LCOV - code coverage report
Current view: top level - plugins/igmp - igmp_config.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 37 39 94.9 %
Date: 2023-10-26 01:39:38 Functions: 7 7 100.0 %

          Line data    Source code
       1             : /*
       2             :  *------------------------------------------------------------------
       3             :  * Copyright (c) 2018 Cisco and/or its affiliates.
       4             :  * Licensed under the Apache License, Version 2.0 (the "License");
       5             :  * you may not use this file except in compliance with the License.
       6             :  * You may obtain a copy of the License at:
       7             :  *
       8             :  *     http://www.apache.org/licenses/LICENSE-2.0
       9             :  *
      10             :  * Unless required by applicable law or agreed to in writing, software
      11             :  * distributed under the License is distributed on an "AS IS" BASIS,
      12             :  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      13             :  * See the License for the specific language governing permissions and
      14             :  * limitations under the License.
      15             :  *------------------------------------------------------------------
      16             :  */
      17             : 
      18             : #include <igmp/igmp_config.h>
      19             : #include <igmp/igmp.h>
      20             : 
      21             : void
      22          10 : igmp_clear_config (igmp_config_t * config)
      23             : {
      24             :   igmp_group_t *group;
      25             :   u32 ii;
      26             : 
      27          10 :   IGMP_DBG ("clear-config: %U",
      28             :             format_vnet_sw_if_index_name,
      29             :             vnet_get_main (), config->sw_if_index);
      30             : 
      31             :   /* *INDENT-OFF* */
      32         652 :   FOR_EACH_GROUP (group, config,
      33             :     ({
      34             :       igmp_group_clear (&group);
      35             :     }));
      36             :   /* *INDENT-ON* */
      37             : 
      38          30 :   for (ii = 0; ii < IGMP_CONFIG_N_TIMERS; ii++)
      39             :     {
      40          20 :       igmp_timer_retire (&config->timers[ii]);
      41             :     }
      42          10 : }
      43             : 
      44             : igmp_config_t *
      45        6669 : igmp_config_lookup (u32 sw_if_index)
      46             : {
      47             :   igmp_main_t *im;
      48             : 
      49        6669 :   im = &igmp_main;
      50             : 
      51        6669 :   if (vec_len (im->igmp_config_by_sw_if_index) > sw_if_index)
      52             :     {
      53             :       u32 index;
      54             : 
      55         213 :       index = im->igmp_config_by_sw_if_index[sw_if_index];
      56             : 
      57         213 :       if (~0 != index)
      58         166 :         return (vec_elt_at_index (im->configs, index));
      59             :     }
      60        6503 :   return NULL;
      61             : }
      62             : 
      63             : u32
      64          39 : igmp_config_index (const igmp_config_t * c)
      65             : {
      66          39 :   return (c - igmp_main.configs);
      67             : }
      68             : 
      69             : igmp_config_t *
      70          81 : igmp_config_get (u32 index)
      71             : {
      72          81 :   return (pool_elt_at_index (igmp_main.configs, index));
      73             : }
      74             : 
      75             : igmp_group_t *
      76          49 : igmp_group_lookup (igmp_config_t * config, const igmp_key_t * key)
      77             : {
      78             :   uword *p;
      79          49 :   igmp_group_t *group = NULL;
      80          49 :   if (!config)
      81           0 :     return NULL;
      82             : 
      83          49 :   p = hash_get_mem (config->igmp_group_by_key, key);
      84          49 :   if (p)
      85          30 :     group = pool_elt_at_index (igmp_main.groups, p[0]);
      86             : 
      87          49 :   return group;
      88             : }
      89             : 
      90             : u8 *
      91           2 : format_igmp_config_timer_type (u8 * s, va_list * args)
      92             : {
      93           2 :   igmp_config_timer_type_t type = va_arg (*args, igmp_config_timer_type_t);
      94             : 
      95           2 :   switch (type)
      96             :     {
      97             : #define _(v,t) case IGMP_CONFIG_TIMER_##v: return (format (s, "%s", t));
      98           2 :       foreach_igmp_config_timer_type
      99             : #undef _
     100             :     }
     101           0 :   return (s);
     102             : }
     103             : 
     104             : 
     105             : u8 *
     106           1 : format_igmp_config (u8 * s, va_list * args)
     107             : {
     108             :   igmp_config_t *config;
     109             :   igmp_group_t *group;
     110             :   vnet_main_t *vnm;
     111             :   u32 ii;
     112             : 
     113           1 :   config = va_arg (*args, igmp_config_t *);
     114           1 :   vnm = vnet_get_main ();
     115             : 
     116           1 :   s = format (s, "interface: %U mode: %U %U",
     117             :               format_vnet_sw_if_index_name, vnm, config->sw_if_index,
     118           1 :               format_igmp_mode, config->mode,
     119             :               format_igmp_proxy_device_id, config->proxy_device_id);
     120             : 
     121           3 :   for (ii = 0; ii < IGMP_CONFIG_N_TIMERS; ii++)
     122             :     {
     123           2 :       s = format (s, "\n  %U:%U",
     124             :                   format_igmp_config_timer_type, ii,
     125             :                   format_igmp_timer_id, config->timers[ii]);
     126             :     }
     127             : 
     128             :   /* *INDENT-OFF* */
     129          65 :   FOR_EACH_GROUP (group, config,
     130             :     ({
     131             :       s = format (s, "\n%U", format_igmp_group, group, 4);
     132             :     }));
     133             :   /* *INDENT-ON* */
     134             : 
     135           1 :   return (s);
     136             : }
     137             : 
     138             : /*
     139             :  * fd.io coding-style-patch-verification: ON
     140             :  *
     141             :  * Local Variables:
     142             :  * eval: (c-set-style "gnu")
     143             :  * End:
     144             :  */

Generated by: LCOV version 1.14