LCOV - code coverage report
Current view: top level - vnet/interface - stats.c (source / functions) Hit Total Coverage
Test: coverage-filtered.info Lines: 27 27 100.0 %
Date: 2023-07-05 22:20:52 Functions: 3 3 100.0 %

          Line data    Source code
       1             : /* SPDX-License-Identifier: Apache-2.0
       2             :  * Copyright(c) 2022 Cisco Systems, Inc.
       3             :  */
       4             : 
       5             : #include <vlib/vlib.h>
       6             : #include <vlib/unix/unix.h>
       7             : #include <vlib/stats/stats.h>
       8             : #include <vnet/vnet.h>
       9             : #include <vnet/devices/devices.h> /* vnet_get_aggregate_rx_packets */
      10             : #include <vnet/interface.h>
      11             : 
      12             : vlib_stats_string_vector_t if_names = 0;
      13             : static u32 **dir_entry_indices = 0;
      14             : 
      15             : static struct
      16             : {
      17             :   char *prefix, *name;
      18             :   u32 index;
      19             : } if_counters[] = {
      20             : #define _(e, n, p) { .prefix = #p, .name = #n },
      21             :   foreach_simple_interface_counter_name foreach_combined_interface_counter_name
      22             : #undef _
      23             : };
      24             : 
      25             : static clib_error_t *
      26       11597 : statseg_sw_interface_add_del (vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
      27             : {
      28       11597 :   if (if_names == 0)
      29             :     {
      30         559 :       if_names = vlib_stats_add_string_vector ("/if/names");
      31             : 
      32       10062 :       for (int i = 0; i < ARRAY_LEN (if_counters); i++)
      33        9503 :         if_counters[i].index = vlib_stats_find_entry_index (
      34             :           "/%s/%s", if_counters[i].prefix, if_counters[i].name);
      35             :     }
      36             : 
      37       11597 :   vec_validate (dir_entry_indices, sw_if_index);
      38             : 
      39       11597 :   vlib_stats_segment_lock ();
      40             : 
      41       11597 :   if (is_add)
      42             :     {
      43             :       vnet_sw_interface_t *si, *si_sup;
      44             :       vnet_hw_interface_t *hi_sup;
      45             :       u8 *name;
      46             : 
      47        7418 :       si = vnet_get_sw_interface (vnm, sw_if_index);
      48        7418 :       si_sup = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
      49        7418 :       ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
      50        7418 :       hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);
      51             : 
      52        7418 :       name = format (0, "%v", hi_sup->name);
      53        7418 :       if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
      54        1118 :         name = format (name, ".%d", si->sub.id);
      55             : 
      56        7418 :       vlib_stats_set_string_vector (&if_names, sw_if_index, "%v", name);
      57             : 
      58      133524 :       for (u32 index, i = 0; i < ARRAY_LEN (if_counters); i++)
      59             :         {
      60      126106 :           index = vlib_stats_add_symlink (
      61             :             if_counters[i].index, sw_if_index, "/interfaces/%U/%s",
      62             :             format_vlib_stats_symlink, name, if_counters[i].name);
      63      126106 :           ASSERT (index != ~0);
      64      126106 :           vec_add1 (dir_entry_indices[sw_if_index], index);
      65             :         }
      66             : 
      67        7418 :       vec_free (name);
      68             :     }
      69             :   else
      70             :     {
      71       75222 :       for (u32 i = 0; i < vec_len (dir_entry_indices[sw_if_index]); i++)
      72       71043 :         vlib_stats_remove_entry (dir_entry_indices[sw_if_index][i]);
      73        4179 :       vec_free (dir_entry_indices[sw_if_index]);
      74             :     }
      75             : 
      76       11597 :   vlib_stats_segment_unlock ();
      77             : 
      78       11597 :   return 0;
      79             : }
      80             : 
      81        3363 : VNET_SW_INTERFACE_ADD_DEL_FUNCTION (statseg_sw_interface_add_del);

Generated by: LCOV version 1.14