28 #define f64_print(a,b) 39 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 44 #define foreach_stats_msg \ 45 _(WANT_STATS, want_stats) \ 46 _(WANT_STATS_REPLY, want_stats_reply) \ 47 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \ 48 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \ 49 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) 52 #define SIMPLE_COUNTER_BATCH_SIZE 126 53 #define COMBINED_COUNTER_BATCH_SIZE 63 54 #define IP4_FIB_COUNTER_BATCH_SIZE 48 55 #define IP6_FIB_COUNTER_BATCH_SIZE 30 58 #define STATS_RELEASE_DELAY_NS (1000 * 1000 * 5) 78 while (__sync_lock_test_and_set (&l->
lock, 1))
112 u32 items_this_message = 0;
127 vec_len (cm->
maxi) - i);
130 (
sizeof (*mp) + items_this_message *
sizeof (v));
131 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COUNTERS);
142 if (mp->
count == items_this_message) {
143 mp->
count = htonl (items_this_message);
162 u32 items_this_message = 0;
173 vec_len (cm->
maxi) - i);
176 (
sizeof (*mp) + items_this_message *
sizeof (v));
177 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COUNTERS);
186 = clib_host_to_net_u64 (v.
packets);
188 = clib_host_to_net_u64 (v.
bytes);
191 if (mp->
count == items_this_message) {
192 mp->
count = htonl (items_this_message);
207 u32 address_length : 6;
214 struct timespec _req, *req = &_req;
215 struct timespec _rem, *rem = &_rem;
220 if (nanosleep (req, rem) == 0)
236 static ip4_route_t * routes;
240 static uword * results;
242 u32 items_this_message;
244 u32 start_at_fib_index = 0;
250 while ((fib - im4->
fibs) < start_at_fib_index)
258 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
278 x.address_length =
i;
282 x.address.data_u32 = p->
key;
284 x.index = vec_len (results);
285 vec_add (results, p->value, lm->fib_result_n_words);
288 x.index = p->
value[0];
292 start_at_fib_index = fib - im4->fibs;
294 ip46_fib_stats_delay (sm, 0 ,
295 STATS_RELEASE_DELAY_NS);
297 ctrp = (vl_api_ip4_fib_counter_t *)mp->c;
305 uword i, j, n_left, n_nhs, adj_index, * result = 0;
309 adj_index = r->index;
312 adj_index = result[0];
316 if (adj->
n_adj == 1) {
333 for (i = j = 0; i < adj->
n_adj; i++) {
342 if (n_left == 0 && sum.
packets > 0) {
345 ctrp->
address = r->address.as_u32;
348 ctrp->
bytes = clib_host_to_net_u64(sum.
bytes);
352 if (mp->
count == items_this_message) {
353 mp->
count = htonl (items_this_message);
365 ip46_fib_stats_delay (sm, 0 ,
377 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
391 start_at_fib_index = fib - im4->
fibs;
442 r->
index = kvp->value;
456 static uword * results;
458 u32 items_this_message;
460 u32 start_at_fib_index = 0;
461 BVT(clib_bihash) * h = &im6->ip6_lookup_table;
467 while ((fib - im6->
fibs) < start_at_fib_index)
475 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
492 start_at_fib_index = fib - im6->
fibs;
498 ip46_fib_stats_delay (sm, 0 ,
507 uword i, j, n_left, n_nhs, adj_index, * result = 0;
511 adj_index = r->
index;
514 adj_index = result[0];
518 if (adj->
n_adj == 1) {
535 for (i = j = 0; i < adj->
n_adj; i++) {
540 if (n_left == 0 && sum.
packets > 0) {
547 ctrp->
bytes = clib_host_to_net_u64(sum.
bytes);
551 if (mp->
count == items_this_message) {
552 mp->
count = htonl (items_this_message);
564 ip46_fib_stats_delay (sm, 0 ,
576 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
590 start_at_fib_index = fib - im6->
fibs;
623 pthread_sigmask (SIG_SETMASK, &s, 0);
634 ip46_fib_stats_delay (sm, 10 , 0 );
656 u32 count, sw_if_index;
660 mp_size =
sizeof (*mp) + (ntohl(mp->
count) *
665 q = vl_api_client_index_to_input_queue (reg->client_index);
667 if (q_prev && (q_prev->cursize < q_prev->maxsize)) {
668 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
669 clib_memcpy(mp_copy, mp, mp_size);
670 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
678 count = ntohl (mp->count);
679 sw_if_index = ntohl (mp->first_sw_if_index);
680 if (mp->is_combined == 0) {
682 vp = (
u64 *) mp->data;
684 switch (mp->vnet_counter_type) {
686 counter_name =
"drop";
689 counter_name =
"punt";
692 counter_name =
"ip4";
695 counter_name =
"ip6";
698 counter_name =
"rx-no-buff";
701 counter_name =
"rx-miss";
704 counter_name =
"rx-error (fifo-full)";
707 counter_name =
"tx-error (fifo-full)";
710 counter_name =
"bogus";
713 for (
i = 0;
i < count;
i++) {
715 v = clib_net_to_host_u64 (v);
718 sm->
vnet_main, sw_if_index, counter_name, v);
726 switch (mp->vnet_counter_type) {
734 counter_name =
"bogus";
737 for (
i = 0;
i < count;
i++) {
739 packets = clib_net_to_host_u64 (packets);
741 bytes = clib_net_to_host_u64 (bytes);
743 fformat (stdout,
"%U.%s.packets %lld\n",
745 sm->
vnet_main, sw_if_index, counter_name, packets);
746 fformat (stdout,
"%U.%s.bytes %lld\n",
748 sm->
vnet_main, sw_if_index, counter_name, bytes);
754 (q_prev->cursize < q_prev->maxsize)) {
770 mp_size =
sizeof(*mp_copy) +
775 q = vl_api_client_index_to_input_queue (reg->client_index);
777 if (q_prev && (q_prev->cursize < q_prev->maxsize)) {
778 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
779 clib_memcpy(mp_copy, mp, mp_size);
780 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
787 (q_prev->cursize < q_prev->maxsize)) {
803 mp_size =
sizeof(*mp_copy) +
808 q = vl_api_client_index_to_input_queue (reg->client_index);
810 if (q_prev && (q_prev->cursize < q_prev->maxsize)) {
811 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
812 clib_memcpy(mp_copy, mp, mp_size);
813 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
820 (q_prev->cursize < q_prev->maxsize)) {
876 rmp->_vl_msg_id = ntohs(VL_API_WANT_STATS_REPLY);
899 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler 900 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler 901 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler 902 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler 921 vl_msg_api_set_handlers(VL_API_##N, #n, \ 922 vl_api_##n##_t_handler, \ 924 vl_api_##n##_t_endian, \ 925 vl_api_##n##_t_print, \ 926 sizeof(vl_api_##n##_t), 0 ); 945 .no_data_structure_clone = 1,
static void stats_thread_fn(void *arg)
void * vlib_worker_thread_bootstrap_fn(void *arg)
Want Stats, register for stats updates.
#define hash_set(h, key, value)
always_inline vlib_thread_main_t * vlib_get_thread_main()
sll srl srl sll sra u16x4 i
#define hash_unset(h, key)
int unix_shared_memory_queue_is_full(unix_shared_memory_queue_t *q)
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
vnet_interface_main_t interface_main
Reply for Want Stats request.
unix_shared_memory_queue_t * vl_input_queue
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define heap_elt_at_index(v, index)
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
always_inline u64 vlib_get_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
VLIB_REGISTER_THREAD(stats_thread_reg, static)
ip_lookup_main_t lookup_main
void clib_longjmp(clib_longjmp_t *save, uword return_value)
uword clib_setjmp(clib_longjmp_t *save, uword return_value_not_taken)
static void vl_api_vnet_ip4_fib_counters_t_handler(vl_api_vnet_ip4_fib_counters_t *mp)
static clib_error_t * stats_init(vlib_main_t *vm)
format_function_t format_vnet_sw_if_index_name
vl_api_ip6_fib_counter_t c[0]
uword * stats_registration_hash
vpe_client_registration_t * stats_registrations
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
volatile u32 release_hint
vnet_main_t * vnet_get_main(void)
always_inline void vlib_counter_add(vlib_counter_t *a, vlib_counter_t *b)
void BV() clib_bihash_foreach_key_value_pair(BVT(clib_bihash)*h, void *callback, void *arg)
#define pool_foreach(VAR, POOL, BODY)
#define VLIB_INIT_FUNCTION(x)
void vl_msg_api_free(void *)
vlib_combined_counter_main_t * combined_sw_if_counters
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define IP6_FIB_COUNTER_BATCH_SIZE
always_inline uword pool_elts(void *v)
#define clib_warning(format, args...)
struct vl_shmem_hdr_ * shmem_hdr
#define foreach_stats_msg
static void vl_api_want_stats_reply_t_handler(vl_api_want_stats_reply_t *mp)
vl_shmem_hdr_t * shmem_hdr
always_inline void * clib_mem_alloc_aligned(uword size, uword align)
void dsunlock(stats_main_t *sm)
#define pool_elt_at_index(p, i)
static void do_ip6_fibs(stats_main_t *sm)
always_inline void vlib_counter_zero(vlib_counter_t *a)
uword os_get_cpu_number(void)
static void vlib_get_combined_counter(vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
always_inline void * clib_mem_set_heap(void *heap)
vlib_simple_counter_main_t * sw_if_counters
#define SIMPLE_COUNTER_BATCH_SIZE
void unix_shared_memory_queue_lock(unix_shared_memory_queue_t *q)
#define COMBINED_COUNTER_BATCH_SIZE
static void do_simple_interface_counters(stats_main_t *sm)
static void add_routes_in_fib(BVT(clib_bihash_kv)*kvp, void *arg)
void * vl_msg_api_alloc(int nbytes)
#define IP4_FIB_COUNTER_BATCH_SIZE
#define clib_unix_warning(format, args...)
static void vnet_interface_counter_unlock(vnet_interface_main_t *im)
static void vl_api_vnet_ip6_fib_counters_t_handler(vl_api_vnet_ip6_fib_counters_t *mp)
struct ip_multipath_adjacency_t::@117 normalized_next_hops
typedef CLIB_PACKED(struct{ip4_address_t address;u32 address_length:6;u32 index:26;})
vlib_combined_counter_main_t adjacency_counters
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
ip_lookup_main_t lookup_main
#define STATS_RELEASE_DELAY_NS
int stats_memclnt_delete_callback(u32 client_index)
static void do_combined_interface_counters(stats_main_t *sm)
u32 stats_poll_interval_in_seconds
always_inline ip_adjacency_t * ip_get_adjacency(ip_lookup_main_t *lm, u32 adj_index)
void dslock(stats_main_t *sm, int release_hint, int tag)
data_structure_lock_t * data_structure_lock
void unix_shared_memory_queue_unlock(unix_shared_memory_queue_t *q)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vnet_interface_main_t * interface_main
static void vl_api_want_stats_t_handler(vl_api_want_stats_t *mp)
#define hash_foreach_pair(p, v, body)
Want stats counters structure.
#define clib_mem_unaligned(pointer, type)
static void do_ip4_fibs(stats_main_t *sm)
ip_multipath_next_hop_t * next_hop_heap
ip_multipath_adjacency_t * multipath_adjacencies
#define vec_foreach(var, vec)
Vector iterator.
void vl_msg_api_send_shmem_nolock(unix_shared_memory_queue_t *q, u8 *elem)
#define CLIB_MEMORY_BARRIER()
uword * adj_index_by_dst_address[33]
void * vl_msg_api_alloc_as_if_client(int nbytes)
#define CLIB_CACHE_LINE_BYTES
void vlib_set_thread_name(char *name)
static void vl_api_vnet_interface_counters_t_handler(vl_api_vnet_interface_counters_t *mp)
vl_api_ip4_fib_counter_t c[0]
struct _unix_shared_memory_queue unix_shared_memory_queue_t