diff options
Diffstat (limited to 'src/vpp/stats/stat_segment.c')
-rw-r--r-- | src/vpp/stats/stat_segment.c | 60 |
1 files changed, 59 insertions, 1 deletions
diff --git a/src/vpp/stats/stat_segment.c b/src/vpp/stats/stat_segment.c index ca78a103522..aa32aede3a5 100644 --- a/src/vpp/stats/stat_segment.c +++ b/src/vpp/stats/stat_segment.c @@ -268,7 +268,7 @@ vlib_map_stat_segment_init (void) /* Scalar stats and node counters */ vec_validate (sm->directory_vector, STAT_COUNTERS - 1); #define _(E,t,n,p) \ - strcpy(sm->directory_vector[STAT_COUNTER_##E].name, "/sys" #p "/" #n); \ + strcpy(sm->directory_vector[STAT_COUNTER_##E].name, #p "/" #n); \ sm->directory_vector[STAT_COUNTER_##E].type = STAT_DIR_TYPE_##t; foreach_stat_segment_counter_name #undef _ @@ -686,8 +686,66 @@ statseg_config (vlib_main_t * vm, unformat_input_t * input) return 0; } +static clib_error_t * +statseg_sw_interface_add_del (vnet_main_t * vnm, u32 sw_if_index, u32 is_add) +{ + stat_segment_main_t *sm = &stat_segment_main; + stat_segment_shared_header_t *shared_header = sm->shared_header; + + void *oldheap = vlib_stats_push_heap (); + vlib_stat_segment_lock (); + + vec_validate (sm->interfaces, sw_if_index); + if (is_add) + { + vnet_sw_interface_t *si = vnet_get_sw_interface (vnm, sw_if_index); + vnet_sw_interface_t *si_sup = + vnet_get_sup_sw_interface (vnm, si->sw_if_index); + vnet_hw_interface_t *hi_sup; + + ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE); + hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index); + + u8 *s = 0; + s = format (s, "%v", hi_sup->name); + if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) + s = format (s, ".%d", si->sub.id); + s = format (s, "%c", 0); + sm->interfaces[sw_if_index] = s; + } + else + { + vec_free (sm->interfaces[sw_if_index]); + sm->interfaces[sw_if_index] = 0; + } + + stat_segment_directory_entry_t *ep; + ep = &sm->directory_vector[STAT_COUNTER_INTERFACE_NAMES]; + ep->offset = stat_segment_offset (shared_header, sm->interfaces); + + int i; + u64 *offset_vector = + ep->offset_vector ? stat_segment_pointer (shared_header, + ep->offset_vector) : 0; + + vec_validate (offset_vector, vec_len (sm->interfaces) - 1); + for (i = 0; i < vec_len (sm->interfaces); i++) + { + offset_vector[i] = + sm->interfaces[i] ? stat_segment_offset (shared_header, + sm->interfaces[i]) : 0; + } + ep->offset_vector = stat_segment_offset (shared_header, offset_vector); + + vlib_stat_segment_unlock (); + clib_mem_set_heap (oldheap); + + return 0; +} + VLIB_INIT_FUNCTION (statseg_init); VLIB_EARLY_CONFIG_FUNCTION (statseg_config, "statseg"); +VNET_SW_INTERFACE_ADD_DEL_FUNCTION (statseg_sw_interface_add_del); /* *INDENT-OFF* */ VLIB_REGISTER_NODE (stat_segment_collector, static) = |