1 /* SPDX-License-Identifier: Apache-2.0
2 * Copyright(c) 2022 Cisco Systems, Inc.
6 #include <vlib/unix/unix.h>
7 #include <vlib/stats/stats.h>
9 #include <vnet/devices/devices.h> /* vnet_get_aggregate_rx_packets */
10 #include <vnet/interface.h>
12 vlib_stats_string_vector_t if_names = 0;
13 static u32 **dir_entry_indices = 0;
20 #define _(e, n, p) { .prefix = #p, .name = #n },
21 foreach_simple_interface_counter_name foreach_combined_interface_counter_name
26 statseg_sw_interface_add_del (vnet_main_t *vnm, u32 sw_if_index, u32 is_add)
32 if_names = vlib_stats_add_string_vector ("/if/names");
34 for (int i = 0; i < ARRAY_LEN (if_counters); i++)
35 if_counters[i].index = vlib_stats_find_entry_index (
36 "/%s/%s", if_counters[i].prefix, if_counters[i].name);
39 vec_validate (dir_entry_indices, sw_if_index);
41 vlib_stats_segment_lock ();
45 vnet_sw_interface_t *si, *si_sup;
46 vnet_hw_interface_t *hi_sup;
48 si = vnet_get_sw_interface (vnm, sw_if_index);
49 si_sup = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
50 ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
51 hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);
53 name = format (0, "%v", hi_sup->name);
54 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
55 name = format (name, ".%d", si->sub.id);
57 vlib_stats_set_string_vector (&if_names, sw_if_index, "%v", name);
59 for (u32 index, i = 0; i < ARRAY_LEN (if_counters); i++)
61 name = format (0, "%v", hi_sup->name);
62 index = vlib_stats_add_symlink (
63 if_counters[i].index, sw_if_index, "/interfaces/%U/%s",
64 format_vlib_stats_symlink, name, if_counters[i].name);
66 vec_add1 (dir_entry_indices[sw_if_index], index);
71 name = format (0, "%s", "deleted");
72 vlib_stats_set_string_vector (&if_names, sw_if_index, "%v", name);
73 for (u32 i = 0; i < vec_len (dir_entry_indices[sw_if_index]); i++)
74 vlib_stats_remove_entry (dir_entry_indices[sw_if_index][i]);
75 vec_free (dir_entry_indices[sw_if_index]);
80 vlib_stats_segment_unlock ();
85 VNET_SW_INTERFACE_ADD_DEL_FUNCTION (statseg_sw_interface_add_del);