X-Git-Url: https://gerrit.fd.io/r/gitweb?a=blobdiff_plain;f=src%2Fvpp%2Fstats%2Fstats.c;h=bf0bc50cafc46e2371f8e8bd4d7b62d7ccd693fc;hb=048a4e5a000017d0d632ebf02dcc23d9bf9ccf72;hp=ac364e88efda20b9bb2c3f0fc23af7c67462c57e;hpb=831fb59f2eba1abbd1e49fc7dce58172f0842258;p=vpp.git diff --git a/src/vpp/stats/stats.c b/src/vpp/stats/stats.c index ac364e88efd..bf0bc50cafc 100644 --- a/src/vpp/stats/stats.c +++ b/src/vpp/stats/stats.c @@ -16,7 +16,9 @@ #include #include #include +#include #include +#include #define STATS_DEBUG 0 @@ -46,21 +48,25 @@ stats_main_t stats_main; #define foreach_stats_msg \ _(WANT_STATS, want_stats) \ _(VNET_INTERFACE_SIMPLE_COUNTERS, vnet_interface_simple_counters) \ -_(WANT_INTERFACE_SIMPLE_STATS, want_interface_simple_stats) \ +_(WANT_INTERFACE_SIMPLE_STATS, want_interface_simple_stats) \ _(VNET_INTERFACE_COMBINED_COUNTERS, vnet_interface_combined_counters) \ -_(WANT_INTERFACE_COMBINED_STATS, want_interface_combined_stats) \ +_(WANT_INTERFACE_COMBINED_STATS, want_interface_combined_stats) \ _(WANT_PER_INTERFACE_COMBINED_STATS, want_per_interface_combined_stats) \ -_(WANT_PER_INTERFACE_SIMPLE_STATS, want_per_interface_simple_stats) \ +_(WANT_PER_INTERFACE_SIMPLE_STATS, want_per_interface_simple_stats) \ _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \ -_(WANT_IP4_FIB_STATS, want_ip4_fib_stats) \ +_(WANT_IP4_FIB_STATS, want_ip4_fib_stats) \ _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \ -_(WANT_IP6_FIB_STATS, want_ip6_fib_stats) \ +_(WANT_IP6_FIB_STATS, want_ip6_fib_stats) \ +_(WANT_IP4_MFIB_STATS, want_ip4_mfib_stats) \ +_(WANT_IP6_MFIB_STATS, want_ip6_mfib_stats) \ _(VNET_IP4_NBR_COUNTERS, vnet_ip4_nbr_counters) \ -_(WANT_IP4_NBR_STATS, want_ip4_nbr_stats) \ -_(VNET_IP6_NBR_COUNTERS, vnet_ip6_nbr_counters) \ -_(WANT_IP6_NBR_STATS, want_ip6_nbr_stats) \ -_(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) - +_(WANT_IP4_NBR_STATS, want_ip4_nbr_stats) \ +_(VNET_IP6_NBR_COUNTERS, vnet_ip6_nbr_counters) \ +_(WANT_IP6_NBR_STATS, want_ip6_nbr_stats) \ +_(VNET_GET_SUMMARY_STATS, vnet_get_summary_stats) \ +_(STATS_GET_POLLER_DELAY, stats_get_poller_delay) \ +_(WANT_UDP_ENCAP_STATS, want_udp_encap_stats) \ +_(MAP_STATS_SEGMENT, map_stats_segment) #define vl_msg_name_crc_list #include @@ -80,6 +86,9 @@ setup_message_id_table (api_main_t * am) #define COMBINED_COUNTER_BATCH_SIZE 63 #define IP4_FIB_COUNTER_BATCH_SIZE 48 #define IP6_FIB_COUNTER_BATCH_SIZE 30 +#define IP4_MFIB_COUNTER_BATCH_SIZE 24 +#define IP6_MFIB_COUNTER_BATCH_SIZE 15 +#define UDP_ENCAP_COUNTER_BATCH_SIZE (1024 / sizeof(vl_api_udp_encap_counter_t)) /* 5ms */ #define STATS_RELEASE_DELAY_NS (1000 * 1000 * 5) @@ -189,7 +198,7 @@ format_vnet_interface_simple_counters (u8 * s, va_list * args) return s; } -void +static void dslock (stats_main_t * sm, int release_hint, int tag) { u32 thread_index; @@ -222,7 +231,7 @@ stats_dslock_with_hint (int hint, int tag) dslock (sm, hint, tag); } -void +static void dsunlock (stats_main_t * sm) { u32 thread_index; @@ -355,6 +364,9 @@ exit: return elts; } +/* + * Return a copy of the clients list. + */ vpe_client_registration_t * get_clients_for_stat (u32 reg, u32 item) { @@ -373,10 +385,13 @@ get_clients_for_stat (u32 reg, u32 item) registration = pool_elt_at_index (sm->stats_registrations[reg], p[0]); vec_reset_length (clients); - pool_foreach (client, registration->clients, ( - { - vec_add1 (clients, *client);} - )); + + /* *INDENT-OFF* */ + pool_foreach (client, registration->clients, + ({ + vec_add1 (clients, *client);} + )); + /* *INDENT-ON* */ return clients; } @@ -443,7 +458,7 @@ do_simple_interface_counters (stats_main_t * sm) vnet_interface_main_t *im = sm->interface_main; api_main_t *am = sm->api_main; vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; - unix_shared_memory_queue_t *q = shmem_hdr->vl_input_queue; + svm_queue_t *q = shmem_hdr->vl_input_queue; vlib_simple_counter_main_t *cm; u32 items_this_message = 0; u64 v, *vp = 0; @@ -539,7 +554,7 @@ static void vl_api_want_interface_combined_stats_reply_t *rmp; uword *p; i32 retval = 0; - unix_shared_memory_queue_t *q; + vl_api_registration_t *reg; u32 swif; swif = ~0; //Using same mechanism as _per_interface_ @@ -550,9 +565,8 @@ static void mp->enable_disable); reply: - q = vl_api_client_index_to_input_queue (mp->client_index); - - if (!q) + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) { sm->enable_poller = clear_client_for_stat (IDX_PER_INTERFACE_COMBINED_COUNTERS, swif, @@ -565,7 +579,7 @@ reply: rmp->context = mp->context; rmp->retval = retval; - vl_msg_api_send_shmem (q, (u8 *) & rmp); + vl_api_send_msg (reg, (u8 *) rmp); } static void @@ -574,7 +588,7 @@ static void { vpe_client_registration_t *clients, client; stats_main_t *sm = &stats_main; - unix_shared_memory_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_interface_combined_counters_t *mp_copy = NULL; u32 mp_size; int i; @@ -588,26 +602,27 @@ static void for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } } + vec_free (clients); #if STATS_DEBUG > 0 fformat (stdout, "%U\n", format_vnet_combined_counters, mp); #endif - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -622,7 +637,7 @@ do_combined_interface_counters (stats_main_t * sm) vnet_interface_main_t *im = sm->interface_main; api_main_t *am = sm->api_main; vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; - unix_shared_memory_queue_t *q = shmem_hdr->vl_input_queue; + svm_queue_t *q = shmem_hdr->vl_input_queue; vlib_combined_counter_main_t *cm; u32 items_this_message = 0; vlib_counter_t v, *vp = 0; @@ -682,16 +697,21 @@ static void vlib_combined_counter_main_t *cm; uword *p; i32 retval = 0; - unix_shared_memory_queue_t *q; - int i; - u32 swif; + vl_api_registration_t *reg; + u32 i, swif, num = 0; + + num = ntohl (mp->num); - // Validate we have good sw_if_indexes before registering - for (i = 0; i < mp->num; i++) + /* + * Validate sw_if_indexes before registering + */ + for (i = 0; i < num; i++) { - swif = mp->sw_ifs[i]; + swif = ntohl (mp->sw_ifs[i]); - /* Check its a real sw_if_index that the client is allowed to see */ + /* + * Check its a real sw_if_index that the client is allowed to see + */ if (swif != ~0) { if (pool_is_free_index (sm->interface_main->sw_interfaces, swif)) @@ -702,24 +722,24 @@ static void } } - for (i = 0; i < mp->num; i++) + for (i = 0; i < num; i++) { - swif = mp->sw_ifs[i]; + swif = ntohl (mp->sw_ifs[i]); rp.client_index = mp->client_index; rp.client_pid = mp->pid; handle_client_registration (&rp, IDX_PER_INTERFACE_COMBINED_COUNTERS, - swif, mp->enable_disable); + swif, ntohl (mp->enable_disable)); } reply: - q = vl_api_client_index_to_input_queue (mp->client_index); - - if (!q) + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) { - for (i = 0; i < mp->num; i++) + for (i = 0; i < num; i++) { - swif = mp->sw_ifs[i]; + swif = ntohl (mp->sw_ifs[i]); + sm->enable_poller = clear_client_for_stat (IDX_PER_INTERFACE_COMBINED_COUNTERS, swif, mp->client_index); @@ -732,7 +752,7 @@ reply: rmp->context = mp->context; rmp->retval = retval; - vl_msg_api_send_shmem (q, (u8 *) & rmp); + vl_api_send_msg (reg, (u8 *) rmp); } /* Per Interface Combined distribution to client */ @@ -743,53 +763,24 @@ do_combined_per_interface_counters (stats_main_t * sm) vnet_interface_main_t *im = sm->interface_main; api_main_t *am = sm->api_main; vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; - unix_shared_memory_queue_t *q = NULL; + vl_api_registration_t *vl_reg; vlib_combined_counter_main_t *cm; - /* - * items_this_message will eventually be used to optimise the batching - * of per client messages for each stat. For now setting this to 1 then - * iterate. This will not affect API. - * - * FIXME instead of enqueueing here, this should be sent to a batch - * storer for per-client transmission. Each "mp" sent would be a single entry - * and if a client is listening to other sw_if_indexes for same, it would be - * appended to that *mp - */ - u32 items_this_message = 1; - vnet_combined_counter_t *vp = 0; + vl_api_vnet_combined_counter_t *vp = 0; vlib_counter_t v; - int i, j; - u32 timestamp; + u32 i, j; vpe_client_stats_registration_t *reg; vpe_client_registration_t *client; u32 *sw_if_index = 0; - /* - FIXME(s): - - capturing the timestamp of the counters "when VPP knew them" is important. - Less so is that the timing of the delivery to the control plane be in the same - timescale. - - i.e. As long as the control plane can delta messages from VPP and work out - velocity etc based on the timestamp, it can do so in a more "batch mode". - - It would be beneficial to keep a "per-client" message queue, and then - batch all the stat messages for a client into one message, with - discrete timestamps. - - Given this particular API is for "per interface" one assumes that the scale - is less than the ~0 case, which the prior API is suited for. - */ vnet_interface_counter_lock (im); - timestamp = vlib_time_now (sm->vlib_main); - vec_reset_length (sm->regs_tmp); + + /* *INDENT-OFF* */ pool_foreach (reg, - sm->stats_registrations[IDX_PER_INTERFACE_COMBINED_COUNTERS], - ( - { - vec_add1 (sm->regs_tmp, reg);})); + sm->stats_registrations[IDX_PER_INTERFACE_COMBINED_COUNTERS], + ({ vec_add1 (sm->regs_tmp, reg); })); + /* *INDENT-ON* */ for (i = 0; i < vec_len (sm->regs_tmp); i++) { @@ -802,60 +793,91 @@ do_combined_per_interface_counters (stats_main_t * sm) continue; } vec_reset_length (sm->clients_tmp); - pool_foreach (client, reg->clients, ( - { - vec_add1 (sm->clients_tmp, - client);} - )); - - //FIXME - should be doing non-variant part of mp here and managing - // any alloc per client in that vec_foreach + + /* *INDENT-OFF* */ + pool_foreach (client, reg->clients, ({ vec_add1 (sm->clients_tmp, + client);})); + /* *INDENT-ON* */ + for (j = 0; j < vec_len (sm->clients_tmp); j++) { client = sm->clients_tmp[j]; - q = vl_api_client_index_to_input_queue (client->client_index); + + vl_reg = vl_api_client_index_to_registration (client->client_index); //Client may have disconnected abrubtly, clean up so we don't poll nothing. - if (!q) + if (!vl_reg) { sm->enable_poller = clear_client_for_stat (IDX_PER_INTERFACE_COMBINED_COUNTERS, reg->item, client->client_index); continue; } + mp = vl_msg_api_alloc_as_if_client (sizeof (*mp) + sizeof (*vp)); + memset (mp, 0, sizeof (*mp)); - mp = vl_msg_api_alloc (sizeof (*mp) + - (items_this_message * - (sizeof (*vp) /* rx */ ))); - - // FIXME when optimising for items_this_message > 1 need to include a - // SIMPLE_INTERFACE_BATCH_SIZE check. mp->_vl_msg_id = ntohs (VL_API_VNET_PER_INTERFACE_COMBINED_COUNTERS); - mp->count = items_this_message; - mp->timestamp = timestamp; - vp = (vnet_combined_counter_t *) mp->data; - + /* + * count will eventually be used to optimise the batching + * of per client messages for each stat. For now setting this to 1 then + * iterate. This will not affect API. + * + * FIXME instead of enqueueing here, this should be sent to a batch + * storer for per-client transmission. Each "mp" sent would be a single entry + * and if a client is listening to other sw_if_indexes for same, it would be + * appended to that *mp + * + * + * FIXME(s): + * - capturing the timestamp of the counters "when VPP knew them" is important. + * Less so is that the timing of the delivery to the control plane be in the same + * timescale. + + * i.e. As long as the control plane can delta messages from VPP and work out + * velocity etc based on the timestamp, it can do so in a more "batch mode". + + * It would be beneficial to keep a "per-client" message queue, and then + * batch all the stat messages for a client into one message, with + * discrete timestamps. + + * Given this particular API is for "per interface" one assumes that the scale + * is less than the ~0 case, which the prior API is suited for. + */ + + /* + * 1 message per api call for now + */ + mp->count = htonl (1); + mp->timestamp = htonl (vlib_time_now (sm->vlib_main)); + + vp = (vl_api_vnet_combined_counter_t *) mp->data; vp->sw_if_index = htonl (reg->item); - cm = im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX; - vlib_get_combined_counter (cm, reg->item, &v); - clib_mem_unaligned (&vp->rx_packets, u64) - = clib_host_to_net_u64 (v.packets); - clib_mem_unaligned (&vp->rx_bytes, u64) = - clib_host_to_net_u64 (v.bytes); + im = &vnet_get_main ()->interface_main; +#define _(X, x) \ + cm = im->combined_sw_if_counters + X; \ + vlib_get_combined_counter (cm, reg->item, &v); \ + clib_mem_unaligned (&vp->x##_packets, u64) = \ + clib_host_to_net_u64 (v.packets); \ + clib_mem_unaligned (&vp->x##_bytes, u64) = \ + clib_host_to_net_u64 (v.bytes); - /* TX vlib_counter_t packets/bytes */ - cm = im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_TX; - vlib_get_combined_counter (cm, reg->item, &v); - clib_mem_unaligned (&vp->tx_packets, u64) - = clib_host_to_net_u64 (v.packets); - clib_mem_unaligned (&vp->tx_bytes, u64) = - clib_host_to_net_u64 (v.bytes); - vl_msg_api_send_shmem (q, (u8 *) & mp); + _(VNET_INTERFACE_COUNTER_RX, rx); + _(VNET_INTERFACE_COUNTER_TX, tx); + _(VNET_INTERFACE_COUNTER_RX_UNICAST, rx_unicast); + _(VNET_INTERFACE_COUNTER_TX_UNICAST, tx_unicast); + _(VNET_INTERFACE_COUNTER_RX_MULTICAST, rx_multicast); + _(VNET_INTERFACE_COUNTER_TX_MULTICAST, tx_multicast); + _(VNET_INTERFACE_COUNTER_RX_BROADCAST, rx_broadcast); + _(VNET_INTERFACE_COUNTER_TX_BROADCAST, tx_broadcast); + +#undef _ + + vl_api_send_msg (vl_reg, (u8 *) mp); } } @@ -877,13 +899,14 @@ static void vlib_simple_counter_main_t *cm; uword *p; i32 retval = 0; - unix_shared_memory_queue_t *q; - int i; - u32 swif; + vl_api_registration_t *reg; + u32 i, swif, num = 0; - for (i = 0; i < mp->num; i++) + num = ntohl (mp->num); + + for (i = 0; i < num; i++) { - swif = mp->sw_ifs[i]; + swif = ntohl (mp->sw_ifs[i]); /* Check its a real sw_if_index that the client is allowed to see */ if (swif != ~0) @@ -896,25 +919,25 @@ static void } } - for (i = 0; i < mp->num; i++) + for (i = 0; i < num; i++) { - swif = mp->sw_ifs[i]; + swif = ntohl (mp->sw_ifs[i]); rp.client_index = mp->client_index; rp.client_pid = mp->pid; handle_client_registration (&rp, IDX_PER_INTERFACE_SIMPLE_COUNTERS, - swif, mp->enable_disable); + swif, ntohl (mp->enable_disable)); } reply: - q = vl_api_client_index_to_input_queue (mp->client_index); + reg = vl_api_client_index_to_registration (mp->client_index); - //Client may have disconnected abrubtly, clean up so we don't poll nothing. - if (!q) + /* Client may have disconnected abruptly, clean up */ + if (!reg) { - for (i = 0; i < mp->num; i++) + for (i = 0; i < num; i++) { - swif = mp->sw_ifs[i]; + swif = ntohl (mp->sw_ifs[i]); sm->enable_poller = clear_client_for_stat (IDX_PER_INTERFACE_SIMPLE_COUNTERS, swif, mp->client_index); @@ -929,7 +952,7 @@ reply: rmp->context = mp->context; rmp->retval = retval; - vl_msg_api_send_shmem (q, (u8 *) & rmp); + vl_api_send_msg (reg, (u8 *) rmp); } /* Per Interface Simple distribution to client */ @@ -940,54 +963,24 @@ do_simple_per_interface_counters (stats_main_t * sm) vnet_interface_main_t *im = sm->interface_main; api_main_t *am = sm->api_main; vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; - unix_shared_memory_queue_t *q = NULL; + vl_api_registration_t *vl_reg; vlib_simple_counter_main_t *cm; - /* - * items_this_message will eventually be used to optimise the batching - * of per client messages for each stat. For now setting this to 1 then - * iterate. This will not affect API. - * - * FIXME instead of enqueueing here, this should be sent to a batch - * storer for per-client transmission. Each "mp" sent would be a single entry - * and if a client is listening to other sw_if_indexes for same, it would be - * appended to that *mp - */ - u32 items_this_message = 1; - int i, j, size; + u32 i, j, size; vpe_client_stats_registration_t *reg; vpe_client_registration_t *client; - u32 timestamp; - u32 count; - vnet_simple_counter_t *vp = 0; + u32 timestamp, count; + vl_api_vnet_simple_counter_t *vp = 0; counter_t v; - /* - FIXME(s): - - capturing the timestamp of the counters "when VPP knew them" is important. - Less so is that the timing of the delivery to the control plane be in the same - timescale. - - i.e. As long as the control plane can delta messages from VPP and work out - velocity etc based on the timestamp, it can do so in a more "batch mode". - - It would be beneficial to keep a "per-client" message queue, and then - batch all the stat messages for a client into one message, with - discrete timestamps. - - Given this particular API is for "per interface" one assumes that the scale - is less than the ~0 case, which the prior API is suited for. - */ vnet_interface_counter_lock (im); - timestamp = vlib_time_now (sm->vlib_main); - vec_reset_length (sm->regs_tmp); + + /* *INDENT-OFF* */ pool_foreach (reg, - sm->stats_registrations[IDX_PER_INTERFACE_SIMPLE_COUNTERS], ( - { - vec_add1 - (sm->regs_tmp, - reg);})); + sm->stats_registrations[IDX_PER_INTERFACE_SIMPLE_COUNTERS], + ({ vec_add1 (sm->regs_tmp, reg); })); + /* *INDENT-ON* */ for (i = 0; i < vec_len (sm->regs_tmp); i++) { @@ -1000,21 +993,19 @@ do_simple_per_interface_counters (stats_main_t * sm) continue; } vec_reset_length (sm->clients_tmp); - pool_foreach (client, reg->clients, ( - { - vec_add1 (sm->clients_tmp, - client);} - )); - - //FIXME - should be doing non-variant part of mp here and managing - // any alloc per client in that vec_foreach + + /* *INDENT-OFF* */ + pool_foreach (client, reg->clients, ({ vec_add1 (sm->clients_tmp, + client);})); + /* *INDENT-ON* */ + for (j = 0; j < vec_len (sm->clients_tmp); j++) { client = sm->clients_tmp[j]; - q = vl_api_client_index_to_input_queue (client->client_index); + vl_reg = vl_api_client_index_to_registration (client->client_index); - //Client may have disconnected abrubtly, clean up so we don't poll nothing. - if (!q) + /* Client may have disconnected abrubtly, clean up */ + if (!vl_reg) { sm->enable_poller = clear_client_for_stat (IDX_PER_INTERFACE_SIMPLE_COUNTERS, @@ -1022,19 +1013,46 @@ do_simple_per_interface_counters (stats_main_t * sm) continue; } - size = (sizeof (*mp) + (items_this_message * (sizeof (u64) * 10))); - mp = vl_msg_api_alloc (size); - // FIXME when optimising for items_this_message > 1 need to include a - // SIMPLE_INTERFACE_BATCH_SIZE check. + mp = vl_msg_api_alloc_as_if_client (sizeof (*mp) + sizeof (*vp)); + memset (mp, 0, sizeof (*mp)); mp->_vl_msg_id = ntohs (VL_API_VNET_PER_INTERFACE_SIMPLE_COUNTERS); - mp->count = items_this_message; - mp->timestamp = timestamp; - vp = (vnet_simple_counter_t *) mp->data; + /* + * count will eventually be used to optimise the batching + * of per client messages for each stat. For now setting this to 1 then + * iterate. This will not affect API. + * + * FIXME instead of enqueueing here, this should be sent to a batch + * storer for per-client transmission. Each "mp" sent would be a single entry + * and if a client is listening to other sw_if_indexes for same, it would be + * appended to that *mp + * + * + * FIXME(s): + * - capturing the timestamp of the counters "when VPP knew them" is important. + * Less so is that the timing of the delivery to the control plane be in the same + * timescale. + + * i.e. As long as the control plane can delta messages from VPP and work out + * velocity etc based on the timestamp, it can do so in a more "batch mode". + + * It would be beneficial to keep a "per-client" message queue, and then + * batch all the stat messages for a client into one message, with + * discrete timestamps. + + * Given this particular API is for "per interface" one assumes that the scale + * is less than the ~0 case, which the prior API is suited for. + */ + + /* + * 1 message per api call for now + */ + mp->count = htonl (1); + mp->timestamp = htonl (vlib_time_now (sm->vlib_main)); + vp = (vl_api_vnet_simple_counter_t *) mp->data; vp->sw_if_index = htonl (reg->item); - //FIXME will be simpler with a preprocessor macro // VNET_INTERFACE_COUNTER_DROP cm = im->sw_if_counters + VNET_INTERFACE_COUNTER_DROP; v = vlib_get_simple_counter (cm, reg->item); @@ -1081,7 +1099,7 @@ do_simple_per_interface_counters (stats_main_t * sm) v = vlib_get_simple_counter (cm, reg->item); clib_mem_unaligned (&vp->rx_mpls, u64) = clib_host_to_net_u64 (v); - vl_msg_api_send_shmem (q, (u8 *) & mp); + vl_api_send_msg (vl_reg, (u8 *) mp); } } @@ -1159,7 +1177,7 @@ ip4_nbr_ship (stats_main_t * sm, ip4_nbr_stats_ctx_t * ctx) { api_main_t *am = sm->api_main; vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; - unix_shared_memory_queue_t *q = shmem_hdr->vl_input_queue; + svm_queue_t *q = shmem_hdr->vl_input_queue; vl_api_vnet_ip4_nbr_counters_t *mp = 0; int first = 0; @@ -1199,11 +1217,11 @@ ip4_nbr_ship (stats_main_t * sm, ip4_nbr_stats_ctx_t * ctx) /* * send to the shm q */ - unix_shared_memory_queue_lock (q); - pause = unix_shared_memory_queue_is_full (q); + svm_queue_lock (q); + pause = svm_queue_is_full (q); vl_msg_api_send_shmem_nolock (q, (u8 *) & mp); - unix_shared_memory_queue_unlock (q); + svm_queue_unlock (q); dsunlock (sm); if (pause) @@ -1314,7 +1332,7 @@ ip6_nbr_ship (stats_main_t * sm, { api_main_t *am = sm->api_main; vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; - unix_shared_memory_queue_t *q = shmem_hdr->vl_input_queue; + svm_queue_t *q = shmem_hdr->vl_input_queue; vl_api_vnet_ip6_nbr_counters_t *mp = 0; int first = 0; @@ -1354,11 +1372,11 @@ ip6_nbr_ship (stats_main_t * sm, /* * send to the shm q */ - unix_shared_memory_queue_lock (q); - pause = unix_shared_memory_queue_is_full (q); + svm_queue_lock (q); + pause = svm_queue_is_full (q); vl_msg_api_send_shmem_nolock (q, (u8 *) & mp); - unix_shared_memory_queue_unlock (q); + svm_queue_unlock (q); dsunlock (sm); if (pause) @@ -1425,7 +1443,7 @@ do_ip4_fib_counters (stats_main_t * sm) ip4_main_t *im4 = &ip4_main; api_main_t *am = sm->api_main; vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; - unix_shared_memory_queue_t *q = shmem_hdr->vl_input_queue; + svm_queue_t *q = shmem_hdr->vl_input_queue; ip4_route_t *r; fib_table_t *fib; ip4_fib_t *v4_fib; @@ -1546,19 +1564,19 @@ again: * drop the data structure lock (which the main thread * may want), and take a pause. */ - unix_shared_memory_queue_lock (q); - if (unix_shared_memory_queue_is_full (q)) + svm_queue_lock (q); + if (svm_queue_is_full (q)) { dsunlock (sm); vl_msg_api_send_shmem_nolock (q, (u8 *) & mp); - unix_shared_memory_queue_unlock (q); + svm_queue_unlock (q); mp = 0; ip46_fib_stats_delay (sm, 0 /* sec */ , STATS_RELEASE_DELAY_NS); goto again; } vl_msg_api_send_shmem_nolock (q, (u8 *) & mp); - unix_shared_memory_queue_unlock (q); + svm_queue_unlock (q); items_this_message = IP4_FIB_COUNTER_BATCH_SIZE; mp = vl_msg_api_alloc_as_if_client @@ -1597,6 +1615,299 @@ again: vl_msg_api_free (mp); } +static int +mfib_table_stats_walk_cb (fib_node_index_t fei, void *ctx) +{ + stats_main_t *sm = ctx; + do_ip46_fibs_t *do_fibs; + mfib_entry_t *entry; + + do_fibs = &sm->do_ip46_fibs; + entry = mfib_entry_get (fei); + + vec_add1 (do_fibs->mroutes, entry->mfe_prefix); + + return (1); +} + +static void +do_ip4_mfib_counters (stats_main_t * sm) +{ + ip4_main_t *im4 = &ip4_main; + api_main_t *am = sm->api_main; + vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; + svm_queue_t *q = shmem_hdr->vl_input_queue; + mfib_prefix_t *pfx; + mfib_table_t *mfib; + do_ip46_fibs_t *do_fibs; + vl_api_vnet_ip4_mfib_counters_t *mp = 0; + u32 items_this_message; + vl_api_ip4_mfib_counter_t *ctrp = 0; + u32 start_at_mfib_index = 0; + int i, j, k; + + do_fibs = &sm->do_ip46_fibs; + + vec_reset_length (do_fibs->mfibs); + /* *INDENT-OFF* */ + pool_foreach (mfib, im4->mfibs, ({vec_add1(do_fibs->mfibs, mfib);})); + /* *INDENT-ON* */ + + for (j = 0; j < vec_len (do_fibs->mfibs); j++) + { + mfib = do_fibs->mfibs[j]; + /* We may have bailed out due to control-plane activity */ + while ((mfib - im4->mfibs) < start_at_mfib_index) + continue; + + if (mp == 0) + { + items_this_message = IP4_MFIB_COUNTER_BATCH_SIZE; + mp = vl_msg_api_alloc_as_if_client + (sizeof (*mp) + + items_this_message * sizeof (vl_api_ip4_mfib_counter_t)); + mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_MFIB_COUNTERS); + mp->count = 0; + mp->vrf_id = ntohl (mfib->mft_table_id); + ctrp = (vl_api_ip4_mfib_counter_t *) mp->c; + } + else + { + /* happens if the last MFIB was empty... */ + ASSERT (mp->count == 0); + mp->vrf_id = ntohl (mfib->mft_table_id); + } + + vec_reset_length (do_fibs->mroutes); + + /* + * walk the table with table updates blocked + */ + dslock (sm, 0 /* release hint */ , 1 /* tag */ ); + + mfib_table_walk (mfib->mft_index, + FIB_PROTOCOL_IP4, mfib_table_stats_walk_cb, sm); + dsunlock (sm); + + vec_foreach (pfx, do_fibs->mroutes) + { + const dpo_id_t *dpo_id; + fib_node_index_t mfei; + vlib_counter_t c; + u32 index; + + /* + * re-lookup the entry, since we suspend during the collection + */ + mfei = mfib_table_lookup (mfib->mft_index, pfx); + + if (FIB_NODE_INDEX_INVALID == mfei) + continue; + + dpo_id = mfib_entry_contribute_ip_forwarding (mfei); + index = (u32) dpo_id->dpoi_index; + + vlib_get_combined_counter (&replicate_main.repm_counters, + dpo_id->dpoi_index, &c); + /* + * If it has seen at least one packet, send it. + */ + if (c.packets > 0) + { + /* already in net byte order */ + memcpy (ctrp->group, &pfx->fp_grp_addr.ip4, 4); + memcpy (ctrp->source, &pfx->fp_src_addr.ip4, 4); + ctrp->group_length = pfx->fp_len; + ctrp->packets = clib_host_to_net_u64 (c.packets); + ctrp->bytes = clib_host_to_net_u64 (c.bytes); + mp->count++; + ctrp++; + + if (mp->count == items_this_message) + { + mp->count = htonl (items_this_message); + /* + * If the main thread's input queue is stuffed, + * drop the data structure lock (which the main thread + * may want), and take a pause. + */ + svm_queue_lock (q); + + while (svm_queue_is_full (q)) + { + svm_queue_unlock (q); + ip46_fib_stats_delay (sm, 0 /* sec */ , + STATS_RELEASE_DELAY_NS); + svm_queue_lock (q); + } + vl_msg_api_send_shmem_nolock (q, (u8 *) & mp); + svm_queue_unlock (q); + + items_this_message = IP4_MFIB_COUNTER_BATCH_SIZE; + mp = vl_msg_api_alloc_as_if_client + (sizeof (*mp) + + items_this_message * sizeof (vl_api_ip4_mfib_counter_t)); + mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_MFIB_COUNTERS); + mp->count = 0; + mp->vrf_id = ntohl (mfib->mft_table_id); + ctrp = (vl_api_ip4_mfib_counter_t *) mp->c; + } + } + } + + /* Flush any data from this mfib */ + if (mp->count) + { + mp->count = htonl (mp->count); + vl_msg_api_send_shmem (q, (u8 *) & mp); + mp = 0; + } + } + + /* If e.g. the last FIB had no reportable routes, free the buffer */ + if (mp) + vl_msg_api_free (mp); +} + +static void +do_ip6_mfib_counters (stats_main_t * sm) +{ + ip6_main_t *im6 = &ip6_main; + api_main_t *am = sm->api_main; + vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; + svm_queue_t *q = shmem_hdr->vl_input_queue; + mfib_prefix_t *pfx; + mfib_table_t *mfib; + do_ip46_fibs_t *do_fibs; + vl_api_vnet_ip6_mfib_counters_t *mp = 0; + u32 items_this_message; + vl_api_ip6_mfib_counter_t *ctrp = 0; + u32 start_at_mfib_index = 0; + int i, j, k; + + do_fibs = &sm->do_ip46_fibs; + + vec_reset_length (do_fibs->mfibs); + /* *INDENT-OFF* */ + pool_foreach (mfib, im6->mfibs, ({vec_add1(do_fibs->mfibs, mfib);})); + /* *INDENT-ON* */ + + for (j = 0; j < vec_len (do_fibs->mfibs); j++) + { + mfib = do_fibs->mfibs[j]; + /* We may have bailed out due to control-plane activity */ + while ((mfib - im6->mfibs) < start_at_mfib_index) + continue; + + if (mp == 0) + { + items_this_message = IP6_MFIB_COUNTER_BATCH_SIZE; + mp = vl_msg_api_alloc_as_if_client + (sizeof (*mp) + + items_this_message * sizeof (vl_api_ip6_mfib_counter_t)); + mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_MFIB_COUNTERS); + mp->count = 0; + mp->vrf_id = ntohl (mfib->mft_table_id); + ctrp = (vl_api_ip6_mfib_counter_t *) mp->c; + } + else + { + /* happens if the last MFIB was empty... */ + ASSERT (mp->count == 0); + mp->vrf_id = ntohl (mfib->mft_table_id); + } + + vec_reset_length (do_fibs->mroutes); + + /* + * walk the table with table updates blocked + */ + dslock (sm, 0 /* release hint */ , 1 /* tag */ ); + + mfib_table_walk (mfib->mft_index, + FIB_PROTOCOL_IP6, mfib_table_stats_walk_cb, sm); + dsunlock (sm); + + vec_foreach (pfx, do_fibs->mroutes) + { + const dpo_id_t *dpo_id; + fib_node_index_t mfei; + vlib_counter_t c; + u32 index; + + /* + * re-lookup the entry, since we suspend during the collection + */ + mfei = mfib_table_lookup (mfib->mft_index, pfx); + + if (FIB_NODE_INDEX_INVALID == mfei) + continue; + + dpo_id = mfib_entry_contribute_ip_forwarding (mfei); + index = (u32) dpo_id->dpoi_index; + + vlib_get_combined_counter (&replicate_main.repm_counters, + dpo_id->dpoi_index, &c); + /* + * If it has seen at least one packet, send it. + */ + if (c.packets > 0) + { + /* already in net byte order */ + memcpy (ctrp->group, &pfx->fp_grp_addr.ip6, 16); + memcpy (ctrp->source, &pfx->fp_src_addr.ip6, 16); + ctrp->group_length = pfx->fp_len; + ctrp->packets = clib_host_to_net_u64 (c.packets); + ctrp->bytes = clib_host_to_net_u64 (c.bytes); + mp->count++; + ctrp++; + + if (mp->count == items_this_message) + { + mp->count = htonl (items_this_message); + /* + * If the main thread's input queue is stuffed, + * drop the data structure lock (which the main thread + * may want), and take a pause. + */ + svm_queue_lock (q); + + while (svm_queue_is_full (q)) + { + svm_queue_unlock (q); + ip46_fib_stats_delay (sm, 0 /* sec */ , + STATS_RELEASE_DELAY_NS); + svm_queue_lock (q); + } + vl_msg_api_send_shmem_nolock (q, (u8 *) & mp); + svm_queue_unlock (q); + + items_this_message = IP6_MFIB_COUNTER_BATCH_SIZE; + mp = vl_msg_api_alloc_as_if_client + (sizeof (*mp) + + items_this_message * sizeof (vl_api_ip6_mfib_counter_t)); + mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_MFIB_COUNTERS); + mp->count = 0; + mp->vrf_id = ntohl (mfib->mft_table_id); + ctrp = (vl_api_ip6_mfib_counter_t *) mp->c; + } + } + } + + /* Flush any data from this mfib */ + if (mp->count) + { + mp->count = htonl (mp->count); + vl_msg_api_send_shmem (q, (u8 *) & mp); + mp = 0; + } + } + + /* If e.g. the last FIB had no reportable routes, free the buffer */ + if (mp) + vl_msg_api_free (mp); +} + typedef struct { u32 fib_index; @@ -1631,7 +1942,7 @@ do_ip6_fib_counters (stats_main_t * sm) ip6_main_t *im6 = &ip6_main; api_main_t *am = sm->api_main; vl_shmem_hdr_t *shmem_hdr = am->shmem_hdr; - unix_shared_memory_queue_t *q = shmem_hdr->vl_input_queue; + svm_queue_t *q = shmem_hdr->vl_input_queue; ip6_route_t *r; fib_table_t *fib; do_ip46_fibs_t *do_fibs; @@ -1724,19 +2035,19 @@ again: * drop the data structure lock (which the main thread * may want), and take a pause. */ - unix_shared_memory_queue_lock (q); - if (unix_shared_memory_queue_is_full (q)) + svm_queue_lock (q); + if (svm_queue_is_full (q)) { dsunlock (sm); vl_msg_api_send_shmem_nolock (q, (u8 *) & mp); - unix_shared_memory_queue_unlock (q); + svm_queue_unlock (q); mp = 0; ip46_fib_stats_delay (sm, 0 /* sec */ , STATS_RELEASE_DELAY_NS); goto again; } vl_msg_api_send_shmem_nolock (q, (u8 *) & mp); - unix_shared_memory_queue_unlock (q); + svm_queue_unlock (q); items_this_message = IP6_FIB_COUNTER_BATCH_SIZE; mp = vl_msg_api_alloc_as_if_client @@ -1776,6 +2087,182 @@ again: vl_msg_api_free (mp); } +typedef struct udp_encap_stat_t_ +{ + u32 ue_id; + u64 stats[2]; +} udp_encap_stat_t; + +typedef struct udp_encap_stats_walk_t_ +{ + udp_encap_stat_t *stats; +} udp_encap_stats_walk_t; + +static int +udp_encap_stats_walk_cb (index_t uei, void *arg) +{ + udp_encap_stats_walk_t *ctx = arg; + udp_encap_stat_t *stat; + udp_encap_t *ue; + + ue = udp_encap_get (uei); + vec_add2 (ctx->stats, stat, 1); + + stat->ue_id = uei; + udp_encap_get_stats (ue->ue_id, &stat->stats[0], &stat->stats[1]); + + return (1); +} + +static void +udp_encap_ship (udp_encap_stats_walk_t * ctx) +{ + vl_api_vnet_udp_encap_counters_t *mp; + vl_shmem_hdr_t *shmem_hdr; + stats_main_t *sm; + api_main_t *am; + svm_queue_t *q; + + mp = NULL; + sm = &stats_main; + am = sm->api_main; + shmem_hdr = am->shmem_hdr; + q = shmem_hdr->vl_input_queue; + + /* + * If the walk context has counters, which may be left over from the last + * suspend, then we continue from there. + */ + while (0 != vec_len (ctx->stats)) + { + u32 n_items = MIN (vec_len (ctx->stats), + UDP_ENCAP_COUNTER_BATCH_SIZE); + u8 pause = 0; + + dslock (sm, 0 /* release hint */ , 1 /* tag */ ); + + mp = vl_msg_api_alloc_as_if_client (sizeof (*mp) + + (n_items * + sizeof + (vl_api_udp_encap_counter_t))); + mp->_vl_msg_id = ntohs (VL_API_VNET_UDP_ENCAP_COUNTERS); + mp->count = ntohl (n_items); + + /* + * copy the counters from the back of the context, then we can easily + * 'erase' them by resetting the vector length. + * The order we push the stats to the caller is not important. + */ + clib_memcpy (mp->c, + &ctx->stats[vec_len (ctx->stats) - n_items], + n_items * sizeof (*ctx->stats)); + + _vec_len (ctx->stats) = vec_len (ctx->stats) - n_items; + + /* + * send to the shm q + */ + svm_queue_lock (q); + pause = svm_queue_is_full (q); + + vl_msg_api_send_shmem_nolock (q, (u8 *) & mp); + svm_queue_unlock (q); + dsunlock (sm); + + if (pause) + ip46_fib_stats_delay (sm, 0 /* sec */ , + STATS_RELEASE_DELAY_NS); + } +} + +static void +do_udp_encap_counters (stats_main_t * sm) +{ + udp_encap_stat_t *stat; + + udp_encap_stats_walk_t ctx = { + .stats = NULL, + }; + + dslock (sm, 0 /* release hint */ , 1 /* tag */ ); + udp_encap_walk (udp_encap_stats_walk_cb, &ctx); + dsunlock (sm); + + udp_encap_ship (&ctx); +} + +int +stats_set_poller_delay (u32 poller_delay_sec) +{ + stats_main_t *sm = &stats_main; + if (!poller_delay_sec) + { + return VNET_API_ERROR_INVALID_ARGUMENT; + } + else + { + sm->stats_poll_interval_in_seconds = poller_delay_sec; + return 0; + } +} + +static clib_error_t * +stats_config (vlib_main_t * vm, unformat_input_t * input) +{ + u32 sec; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) + { + if (unformat (input, "interval %u", &sec)) + { + int rv = stats_set_poller_delay (sec); + if (rv) + { + return clib_error_return (0, + "`stats_set_poller_delay' API call failed, rv=%d:%U", + (int) rv, format_vnet_api_errno, rv); + } + return 0; + } + else + { + return clib_error_return (0, "unknown input '%U'", + format_unformat_error, input); + } + } + return 0; +} + +/* stats { ... } configuration. */ +/*? + * + * @cfgcmd{interval, <seconds>} + * Configure stats poller delay to be @c seconds. + * +?*/ +VLIB_CONFIG_FUNCTION (stats_config, "stats"); + +static void + vl_api_stats_get_poller_delay_t_handler + (vl_api_stats_get_poller_delay_t * mp) +{ + stats_main_t *sm = &stats_main; + vl_api_registration_t *reg; + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; + vl_api_stats_get_poller_delay_reply_t *rmp; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_WANT_PER_INTERFACE_SIMPLE_STATS_REPLY); + rmp->context = mp->context; + rmp->retval = 0; + rmp->delay = clib_host_to_net_u32 (sm->stats_poll_interval_in_seconds); + + vl_api_send_msg (reg, (u8 *) rmp); + +} + static void stats_thread_fn (void *arg) { @@ -1798,8 +2285,8 @@ stats_thread_fn (void *arg) while (1) { - /* 10 second poll interval */ - ip46_fib_stats_delay (sm, 10 /* secs */ , 0 /* nsec */ ); + ip46_fib_stats_delay (sm, sm->stats_poll_interval_in_seconds, + 0 /* nsec */ ); if (!(sm->enable_poller)) { @@ -1819,11 +2306,20 @@ stats_thread_fn (void *arg) if (pool_elts (sm->stats_registrations[IDX_IP6_FIB_COUNTERS])) do_ip6_fib_counters (sm); + if (pool_elts (sm->stats_registrations[IDX_IP4_MFIB_COUNTERS])) + do_ip4_mfib_counters (sm); + + if (pool_elts (sm->stats_registrations[IDX_IP6_MFIB_COUNTERS])) + do_ip6_mfib_counters (sm); + if (pool_elts (sm->stats_registrations[IDX_IP4_NBR_COUNTERS])) do_ip4_nbr_counters (sm); if (pool_elts (sm->stats_registrations[IDX_IP6_NBR_COUNTERS])) do_ip6_nbr_counters (sm); + + if (pool_elts (sm->stats_registrations[IDX_UDP_ENCAP_COUNTERS])) + do_udp_encap_counters (sm); } } @@ -1833,7 +2329,7 @@ static void { vpe_client_registration_t *clients, client; stats_main_t *sm = &stats_main; - unix_shared_memory_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_interface_simple_counters_t *mp_copy = NULL; u32 mp_size; int i; @@ -1847,17 +2343,17 @@ static void for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } else { @@ -1867,14 +2363,15 @@ static void continue; } } + vec_free (clients); #if STATS_DEBUG > 0 fformat (stdout, "%U\n", format_vnet_simple_counters, mp); #endif - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -1882,15 +2379,11 @@ static void } } - - - - static void vl_api_vnet_ip4_fib_counters_t_handler (vl_api_vnet_ip4_fib_counters_t * mp) { stats_main_t *sm = &stats_main; - unix_shared_memory_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_ip4_fib_counters_t *mp_copy = NULL; u32 mp_size; vpe_client_registration_t *clients, client; @@ -1905,17 +2398,17 @@ vl_api_vnet_ip4_fib_counters_t_handler (vl_api_vnet_ip4_fib_counters_t * mp) for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } else { @@ -1924,10 +2417,11 @@ vl_api_vnet_ip4_fib_counters_t_handler (vl_api_vnet_ip4_fib_counters_t * mp) continue; } } + vec_free (clients); - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -1939,7 +2433,7 @@ static void vl_api_vnet_ip4_nbr_counters_t_handler (vl_api_vnet_ip4_nbr_counters_t * mp) { stats_main_t *sm = &stats_main; - unix_shared_memory_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_ip4_nbr_counters_t *mp_copy = NULL; u32 mp_size; vpe_client_registration_t *clients, client; @@ -1954,17 +2448,17 @@ vl_api_vnet_ip4_nbr_counters_t_handler (vl_api_vnet_ip4_nbr_counters_t * mp) for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } else { @@ -1973,11 +2467,12 @@ vl_api_vnet_ip4_nbr_counters_t_handler (vl_api_vnet_ip4_nbr_counters_t * mp) continue; } } + vec_free (clients); /* *INDENT-ON* */ - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -1989,7 +2484,7 @@ static void vl_api_vnet_ip6_fib_counters_t_handler (vl_api_vnet_ip6_fib_counters_t * mp) { stats_main_t *sm = &stats_main; - unix_shared_memory_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_ip6_fib_counters_t *mp_copy = NULL; u32 mp_size; vpe_client_registration_t *clients, client; @@ -2004,17 +2499,17 @@ vl_api_vnet_ip6_fib_counters_t_handler (vl_api_vnet_ip6_fib_counters_t * mp) for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } else { @@ -2023,10 +2518,12 @@ vl_api_vnet_ip6_fib_counters_t_handler (vl_api_vnet_ip6_fib_counters_t * mp) continue; } } + vec_free (clients); + /* *INDENT-ON* */ - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -2038,7 +2535,7 @@ static void vl_api_vnet_ip6_nbr_counters_t_handler (vl_api_vnet_ip6_nbr_counters_t * mp) { stats_main_t *sm = &stats_main; - unix_shared_memory_queue_t *q, *q_prev = NULL; + vl_api_registration_t *reg, *reg_prev = NULL; vl_api_vnet_ip6_nbr_counters_t *mp_copy = NULL; u32 mp_size; vpe_client_registration_t *clients, client; @@ -2053,17 +2550,17 @@ vl_api_vnet_ip6_nbr_counters_t_handler (vl_api_vnet_ip6_nbr_counters_t * mp) for (i = 0; i < vec_len (clients); i++) { client = clients[i]; - q = vl_api_client_index_to_input_queue (client.client_index); - if (q) + reg = vl_api_client_index_to_registration (client.client_index); + if (reg) { - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { mp_copy = vl_msg_api_alloc_as_if_client (mp_size); clib_memcpy (mp_copy, mp, mp_size); - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); mp = mp_copy; } - q_prev = q; + reg_prev = reg; } else { @@ -2072,10 +2569,12 @@ vl_api_vnet_ip6_nbr_counters_t_handler (vl_api_vnet_ip6_nbr_counters_t * mp) continue; } } + vec_free (clients); + /* *INDENT-ON* */ - if (q_prev && (q_prev->cursize < q_prev->maxsize)) + if (reg_prev && vl_api_can_send_msg (reg_prev)) { - vl_msg_api_send_shmem (q_prev, (u8 *) & mp); + vl_api_send_msg (reg_prev, (u8 *) mp); } else { @@ -2083,6 +2582,41 @@ vl_api_vnet_ip6_nbr_counters_t_handler (vl_api_vnet_ip6_nbr_counters_t * mp) } } +static void +vl_api_want_udp_encap_stats_t_handler (vl_api_want_udp_encap_stats_t * mp) +{ + stats_main_t *sm = &stats_main; + vpe_client_registration_t rp; + vl_api_want_udp_encap_stats_reply_t *rmp; + uword *p; + i32 retval = 0; + vl_api_registration_t *reg; + u32 fib; + + fib = ~0; //Using same mechanism as _per_interface_ + rp.client_index = mp->client_index; + rp.client_pid = mp->pid; + + handle_client_registration (&rp, IDX_UDP_ENCAP_COUNTERS, fib, mp->enable); + +reply: + reg = vl_api_client_index_to_registration (mp->client_index); + + if (!reg) + { + sm->enable_poller = clear_client_for_stat (IDX_UDP_ENCAP_COUNTERS, + fib, mp->client_index); + return; + } + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_WANT_UDP_ENCAP_STATS_REPLY); + rmp->context = mp->context; + rmp->retval = retval; + + vl_api_send_msg (reg, (u8 *) rmp); +} + static void vl_api_want_stats_t_handler (vl_api_want_stats_t * mp) { @@ -2092,7 +2626,7 @@ vl_api_want_stats_t_handler (vl_api_want_stats_t * mp) uword *p; i32 retval = 0; u32 item; - unix_shared_memory_queue_t *q; + vl_api_registration_t *reg; item = ~0; //"ALL THE THINGS IN THE THINGS rp.client_index = mp->client_index; @@ -2117,9 +2651,8 @@ vl_api_want_stats_t_handler (vl_api_want_stats_t * mp) item, mp->enable_disable); reply: - q = vl_api_client_index_to_input_queue (mp->client_index); - - if (!q) + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) return; rmp = vl_msg_api_alloc (sizeof (*rmp)); @@ -2127,7 +2660,7 @@ reply: rmp->context = mp->context; rmp->retval = retval; - vl_msg_api_send_shmem (q, (u8 *) & rmp); + vl_api_send_msg (reg, (u8 *) rmp); } static void @@ -2140,7 +2673,7 @@ static void uword *p; i32 retval = 0; u32 swif; - unix_shared_memory_queue_t *q; + vl_api_registration_t *reg; swif = ~0; //Using same mechanism as _per_interface_ rp.client_index = mp->client_index; @@ -2150,9 +2683,9 @@ static void mp->enable_disable); reply: - q = vl_api_client_index_to_input_queue (mp->client_index); + reg = vl_api_client_index_to_registration (mp->client_index); - if (!q) + if (!reg) { sm->enable_poller = clear_client_for_stat (IDX_PER_INTERFACE_SIMPLE_COUNTERS, swif, @@ -2165,7 +2698,7 @@ reply: rmp->context = mp->context; rmp->retval = retval; - vl_msg_api_send_shmem (q, (u8 *) & rmp); + vl_api_send_msg (reg, (u8 *) rmp); } @@ -2177,7 +2710,7 @@ vl_api_want_ip4_fib_stats_t_handler (vl_api_want_ip4_fib_stats_t * mp) vl_api_want_ip4_fib_stats_reply_t *rmp; uword *p; i32 retval = 0; - unix_shared_memory_queue_t *q; + vl_api_registration_t *reg; u32 fib; fib = ~0; //Using same mechanism as _per_interface_ @@ -2188,9 +2721,9 @@ vl_api_want_ip4_fib_stats_t_handler (vl_api_want_ip4_fib_stats_t * mp) mp->enable_disable); reply: - q = vl_api_client_index_to_input_queue (mp->client_index); + reg = vl_api_client_index_to_registration (mp->client_index); - if (!q) + if (!reg) { sm->enable_poller = clear_client_for_stat (IDX_IP4_FIB_COUNTERS, fib, mp->client_index); @@ -2202,7 +2735,42 @@ reply: rmp->context = mp->context; rmp->retval = retval; - vl_msg_api_send_shmem (q, (u8 *) & rmp); + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_want_ip4_mfib_stats_t_handler (vl_api_want_ip4_mfib_stats_t * mp) +{ + stats_main_t *sm = &stats_main; + vpe_client_registration_t rp; + vl_api_want_ip4_mfib_stats_reply_t *rmp; + uword *p; + i32 retval = 0; + vl_api_registration_t *reg; + u32 mfib; + + mfib = ~0; //Using same mechanism as _per_interface_ + rp.client_index = mp->client_index; + rp.client_pid = mp->pid; + + handle_client_registration (&rp, IDX_IP4_MFIB_COUNTERS, mfib, + mp->enable_disable); + +reply: + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + { + sm->enable_poller = clear_client_for_stat (IDX_IP4_MFIB_COUNTERS, + mfib, mp->client_index); + return; + } + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_WANT_IP4_MFIB_STATS_REPLY); + rmp->context = mp->context; + rmp->retval = retval; + + vl_api_send_msg (reg, (u8 *) rmp); } static void @@ -2213,7 +2781,7 @@ vl_api_want_ip6_fib_stats_t_handler (vl_api_want_ip6_fib_stats_t * mp) vl_api_want_ip4_fib_stats_reply_t *rmp; uword *p; i32 retval = 0; - unix_shared_memory_queue_t *q; + vl_api_registration_t *reg; u32 fib; fib = ~0; //Using same mechanism as _per_interface_ @@ -2224,9 +2792,8 @@ vl_api_want_ip6_fib_stats_t_handler (vl_api_want_ip6_fib_stats_t * mp) mp->enable_disable); reply: - q = vl_api_client_index_to_input_queue (mp->client_index); - - if (!q) + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) { sm->enable_poller = clear_client_for_stat (IDX_IP6_FIB_COUNTERS, fib, mp->client_index); @@ -2238,7 +2805,42 @@ reply: rmp->context = mp->context; rmp->retval = retval; - vl_msg_api_send_shmem (q, (u8 *) & rmp); + vl_api_send_msg (reg, (u8 *) rmp); +} + +static void +vl_api_want_ip6_mfib_stats_t_handler (vl_api_want_ip6_mfib_stats_t * mp) +{ + stats_main_t *sm = &stats_main; + vpe_client_registration_t rp; + vl_api_want_ip4_mfib_stats_reply_t *rmp; + uword *p; + i32 retval = 0; + vl_api_registration_t *reg; + u32 mfib; + + mfib = ~0; //Using same mechanism as _per_interface_ + rp.client_index = mp->client_index; + rp.client_pid = mp->pid; + + handle_client_registration (&rp, IDX_IP6_MFIB_COUNTERS, mfib, + mp->enable_disable); + +reply: + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + { + sm->enable_poller = clear_client_for_stat (IDX_IP6_MFIB_COUNTERS, + mfib, mp->client_index); + return; + } + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + rmp->_vl_msg_id = ntohs (VL_API_WANT_IP6_MFIB_STATS_REPLY); + rmp->context = mp->context; + rmp->retval = retval; + + vl_api_send_msg (reg, (u8 *) rmp); } /* FIXME - NBR stats broken - this will be fixed in subsequent patch */ @@ -2263,14 +2865,11 @@ vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp) int i, which; u64 total_pkts[VLIB_N_RX_TX]; u64 total_bytes[VLIB_N_RX_TX]; + vl_api_registration_t *reg; - unix_shared_memory_queue_t *q = - vl_api_client_index_to_input_queue (mp->client_index); - - if (!q) - { - return; - } + reg = vl_api_client_index_to_registration (mp->client_index); + if (!reg) + return; rmp = vl_msg_api_alloc (sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_VNET_GET_SUMMARY_STATS_REPLY); @@ -2302,7 +2901,7 @@ vl_api_vnet_get_summary_stats_t_handler (vl_api_vnet_get_summary_stats_t * mp) rmp->vector_rate = clib_host_to_net_u64 (vlib_last_vector_length_per_node (sm->vlib_main)); - vl_msg_api_send_shmem (q, (u8 *) & rmp); + vl_api_send_msg (reg, (u8 *) rmp); } int @@ -2336,6 +2935,50 @@ stats_memclnt_delete_callback (u32 client_index) #define vl_api_vnet_ip4_nbr_counters_t_print vl_noop_handler #define vl_api_vnet_ip6_nbr_counters_t_endian vl_noop_handler #define vl_api_vnet_ip6_nbr_counters_t_print vl_noop_handler +#define vl_api_map_stats_segment_t_print vl_noop_handler + +static void +vl_api_map_stats_segment_t_handler (vl_api_map_stats_segment_t * mp) +{ + vl_api_map_stats_segment_reply_t *rmp; + stats_main_t *sm = &stats_main; + ssvm_private_t *ssvmp = &sm->stat_segment; + vl_api_registration_t *regp; + api_main_t *am = &api_main; + clib_file_t *cf; + vl_api_shm_elem_config_t *config = 0; + vl_shmem_hdr_t *shmem_hdr; + int rv = 0; + + regp = vl_api_client_index_to_registration (mp->client_index); + if (regp == 0) + { + clib_warning ("API client disconnected"); + return; + } + if (regp->registration_type != REGISTRATION_TYPE_SOCKET_SERVER) + rv = VNET_API_ERROR_INVALID_REGISTRATION; + + rmp = vl_msg_api_alloc (sizeof (*rmp)); + rmp->_vl_msg_id = htons (VL_API_MAP_STATS_SEGMENT_REPLY); + rmp->context = mp->context; + rmp->retval = htonl (rv); + + vl_api_send_msg (regp, (u8 *) rmp); + + if (rv != 0) + return; + + /* + * We need the reply message to make it out the back door + * before we send the magic fd message so force a flush + */ + cf = vl_api_registration_file (regp); + cf->write_function (cf); + + /* Send the magic "here's your sign (aka fd)" socket message */ + vl_sock_api_send_fd_msg (cf->file_descriptor, ssvmp->fd); +} static clib_error_t * stats_init (vlib_main_t * vm)