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) 80 while (__sync_lock_test_and_set (&l->
lock, 1))
117 u32 items_this_message = 0;
135 vec_len (cm->
maxi) - i);
138 (
sizeof (*mp) + items_this_message *
sizeof (v));
139 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COUNTERS);
150 if (mp->
count == items_this_message)
152 mp->
count = htonl (items_this_message);
172 u32 items_this_message = 0;
186 vec_len (cm->
maxi) - i);
189 (
sizeof (*mp) + items_this_message *
sizeof (v));
190 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COUNTERS);
199 = clib_host_to_net_u64 (v.
packets);
203 if (mp->
count == items_this_message)
205 mp->
count = htonl (items_this_message);
220 u32 address_length: 6;
227 struct timespec _req, *req = &_req;
228 struct timespec _rem, *rem = &_rem;
234 if (nanosleep (req, rem) == 0)
251 static ip4_route_t *routes;
255 static uword *results;
257 u32 items_this_message;
259 u32 start_at_fib_index = 0;
266 while ((fib - im4->
fibs) < start_at_fib_index)
275 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
298 x.address_length =
i;
303 x.address.data_u32 = p->
key;
306 x.index = vec_len (results);
307 vec_add (results, p->value, lm->fib_result_n_words);
310 x.index = p->
value[0];
315 start_at_fib_index = fib - im4->fibs;
317 ip46_fib_stats_delay (sm, 0 ,
318 STATS_RELEASE_DELAY_NS);
320 ctrp = (vl_api_ip4_fib_counter_t *)mp->c;
330 uword i, j, n_left, n_nhs, adj_index, *result = 0;
334 adj_index = r->index;
338 adj_index = result[0];
361 for (i = j = 0; i < adj->
n_adj; i++)
371 if (n_left == 0 && sum.
packets > 0)
375 ctrp->
address = r->address.as_u32;
378 ctrp->
bytes = clib_host_to_net_u64 (sum.
bytes);
382 if (mp->
count == items_this_message)
384 mp->
count = htonl (items_this_message);
397 ip46_fib_stats_delay (sm, 0 ,
408 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
424 start_at_fib_index = fib - im4->
fibs;
479 r->
index = kvp->value;
494 static uword *results;
496 u32 items_this_message;
498 u32 start_at_fib_index = 0;
499 BVT (clib_bihash) * h = &im6->ip6_lookup_table;
506 while ((fib - im6->
fibs) < start_at_fib_index)
515 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
532 start_at_fib_index = fib - im6->
fibs;
538 ip46_fib_stats_delay (sm, 0 ,
548 uword i, j, n_left, n_nhs, adj_index, *result = 0;
552 adj_index = r->
index;
556 adj_index = result[0];
579 for (i = j = 0; i < adj->
n_adj; i++)
585 if (n_left == 0 && sum.
packets > 0)
593 ctrp->
bytes = clib_host_to_net_u64 (sum.
bytes);
597 if (mp->
count == items_this_message)
599 mp->
count = htonl (items_this_message);
612 ip46_fib_stats_delay (sm, 0 ,
623 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
639 start_at_fib_index = fib - im6->
fibs;
674 pthread_sigmask (SIG_SETMASK, &s, 0);
686 ip46_fib_stats_delay (sm, 10 , 0 );
709 u32 count, sw_if_index;
713 mp_size =
sizeof (*mp) + (ntohl (mp->
count) *
720 q = vl_api_client_index_to_input_queue (reg->client_index);
723 if (q_prev && (q_prev->cursize < q_prev->maxsize))
725 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
726 clib_memcpy(mp_copy, mp, mp_size);
727 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
736 count = ntohl (mp->count);
737 sw_if_index = ntohl (mp->first_sw_if_index);
738 if (mp->is_combined == 0)
741 vp = (
u64 *) mp->data;
743 switch (mp->vnet_counter_type)
746 counter_name =
"drop";
749 counter_name =
"punt";
752 counter_name =
"ip4";
755 counter_name =
"ip6";
758 counter_name =
"rx-no-buff";
761 , counter_name =
"rx-miss";
764 , counter_name =
"rx-error (fifo-full)";
767 , counter_name =
"tx-error (fifo-full)";
770 counter_name =
"bogus";
773 for (
i = 0;
i < count;
i++)
776 v = clib_net_to_host_u64 (v);
779 sm->
vnet_main, sw_if_index, counter_name, v);
789 switch (mp->vnet_counter_type)
798 counter_name =
"bogus";
801 for (
i = 0;
i < count;
i++)
804 packets = clib_net_to_host_u64 (packets);
806 bytes = clib_net_to_host_u64 (bytes);
808 fformat (stdout,
"%U.%s.packets %lld\n",
810 sm->
vnet_main, sw_if_index, counter_name, packets);
811 fformat (stdout,
"%U.%s.bytes %lld\n",
813 sm->
vnet_main, sw_if_index, counter_name, bytes);
818 if (q_prev && (q_prev->cursize < q_prev->maxsize))
837 mp_size =
sizeof (*mp_copy) +
843 q = vl_api_client_index_to_input_queue (reg->client_index);
846 if (q_prev && (q_prev->cursize < q_prev->maxsize))
848 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
849 clib_memcpy(mp_copy, mp, mp_size);
850 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
857 if (q_prev && (q_prev->cursize < q_prev->maxsize))
876 mp_size =
sizeof (*mp_copy) +
882 q = vl_api_client_index_to_input_queue (reg->client_index);
885 if (q_prev && (q_prev->cursize < q_prev->maxsize))
887 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
888 clib_memcpy(mp_copy, mp, mp_size);
889 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
896 if (q_prev && (q_prev->cursize < q_prev->maxsize))
963 rmp->_vl_msg_id = ntohs (VL_API_WANT_STATS_REPLY);
988 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler 989 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler 990 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler 991 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler 1011 vl_msg_api_set_handlers(VL_API_##N, #n, \ 1012 vl_api_##n##_t_handler, \ 1014 vl_api_##n##_t_endian, \ 1015 vl_api_##n##_t_print, \ 1016 sizeof(vl_api_##n##_t), 0 ); 1036 .no_data_structure_clone = 1,
static void stats_thread_fn(void *arg)
Want Stats, register for stats updates.
u64 packets
packet counter
#define hash_set(h, key, value)
sll srl srl sll sra u16x4 i
u64 * maxi
Shared wide counters.
#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)
u16 n_adj
Number of adjecencies in block.
vnet_interface_main_t interface_main
Reply for Want Stats request.
unix_shared_memory_queue_t * vl_input_queue
vlib_counter_t * maxi
Shared wide counter pairs.
#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)
Combined counter to hold both packets and byte differences.
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
VLIB_REGISTER_THREAD(stats_thread_reg, static)
ip_lookup_main_t lookup_main
void clib_longjmp(clib_longjmp_t *save, uword return_value)
static void vlib_counter_zero(vlib_counter_t *a)
Clear a combined counter.
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
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
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)
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
#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
#define clib_warning(format, args...)
struct vl_shmem_hdr_ * shmem_hdr
A collection of simple counters.
static void vlib_counter_add(vlib_counter_t *a, vlib_counter_t *b)
Add two combined counters, results in the first counter.
void vlib_set_thread_name(char *name)
#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
void dsunlock(stats_main_t *sm)
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
static void do_ip6_fibs(stats_main_t *sm)
uword os_get_cpu_number(void)
#define pool_put(P, E)
Free an object E in pool P.
static void vlib_get_combined_counter(vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of mini co...
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)
struct ip_multipath_adjacency_t::@148 normalized_next_hops
void clib_bihash_foreach_key_value_pair(clib_bihash *h, void *callback, void *arg)
Visit active (key,value) pairs in a bi-hash table.
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
static vlib_thread_main_t * vlib_get_thread_main()
static void * clib_mem_set_heap(void *heap)
#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)
vl_api_ip6_fib_counter_t c[count]
typedef CLIB_PACKED(struct{ip4_address_t address;u32 address_length:6;u32 index:26;})
vlib_combined_counter_main_t adjacency_counters
Adjacency packet/byte counters indexed by adjacency index.
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
ip4_fib_t * fibs
Vector of FIBs.
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
void dslock(stats_main_t *sm, int release_hint, int tag)
vl_api_ip4_fib_counter_t c[count]
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)
u32 heap_handle
Handle for this adjacency in adjacency heap.
Want stats counters structure.
A collection of combined counters.
#define clib_mem_unaligned(pointer, type)
static u64 vlib_get_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Get the value of a simple counter Scrapes the entire set of mini counters.
static void do_ip4_fibs(stats_main_t *sm)
static void * clib_mem_alloc_aligned(uword size, uword align)
ip_multipath_next_hop_t * next_hop_heap
Heap of (next hop, weight) blocks.
ip_multipath_adjacency_t * multipath_adjacencies
Indexed by heap_handle from ip_adjacency_t.
ip4_main_t ip4_main
Global ip4 main structure.
#define vec_foreach(var, vec)
Vector iterator.
void vl_msg_api_send_shmem_nolock(unix_shared_memory_queue_t *q, u8 *elem)
void * vlib_worker_thread_bootstrap_fn(void *arg)
#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
static void vl_api_vnet_interface_counters_t_handler(vl_api_vnet_interface_counters_t *mp)
static ip_adjacency_t * ip_get_adjacency(ip_lookup_main_t *lm, u32 adj_index)
struct _unix_shared_memory_queue unix_shared_memory_queue_t
static uword pool_elts(void *v)
Number of active elements in a pool.