31 #define f64_print(a,b) 42 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 47 #define foreach_stats_msg \ 48 _(WANT_STATS, want_stats) \ 49 _(WANT_STATS_REPLY, want_stats_reply) \ 50 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \ 51 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \ 52 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) 55 #define SIMPLE_COUNTER_BATCH_SIZE 126 56 #define COMBINED_COUNTER_BATCH_SIZE 63 57 #define IP4_FIB_COUNTER_BATCH_SIZE 48 58 #define IP6_FIB_COUNTER_BATCH_SIZE 30 61 #define STATS_RELEASE_DELAY_NS (1000 * 1000 * 5) 83 while (__sync_lock_test_and_set (&l->
lock, 1))
120 u32 items_this_message = 0;
138 vec_len (cm->
maxi) - i);
141 (
sizeof (*mp) + items_this_message *
sizeof (v));
142 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COUNTERS);
153 if (mp->
count == items_this_message)
155 mp->
count = htonl (items_this_message);
175 u32 items_this_message = 0;
189 vec_len (cm->
maxi) - i);
192 (
sizeof (*mp) + items_this_message *
sizeof (v));
193 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COUNTERS);
202 = clib_host_to_net_u64 (v.
packets);
206 if (mp->
count == items_this_message)
208 mp->
count = htonl (items_this_message);
223 u32 address_length: 6;
230 struct timespec _req, *req = &_req;
231 struct timespec _rem, *rem = &_rem;
237 if (nanosleep (req, rem) == 0)
254 static ip4_route_t *routes;
258 static uword *results;
260 u32 items_this_message;
262 u32 start_at_fib_index = 0;
270 while ((fib - im4->fibs) < start_at_fib_index)
275 items_this_message = IP4_FIB_COUNTER_BATCH_SIZE;
276 mp = vl_msg_api_alloc_as_if_client
278 items_this_message * sizeof (vl_api_ip4_fib_counter_t));
279 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
281 mp->vrf_id = ntohl (fib->ft_table_id);
282 ctrp = (vl_api_ip4_fib_counter_t *) mp->c;
287 ASSERT (mp->count == 0);
288 mp->vrf_id = ntohl (fib->ft_table_id);
302 x.address_length =
i;
306 x.address.data_u32 = p->
key;
309 x.index = vec_len (results);
310 vec_add (results, p->value, lm->fib_result_n_words);
313 x.index = p->
value[0];
318 start_at_fib_index = fib - im4->fibs;
320 ip46_fib_stats_delay (sm, 0 ,
321 STATS_RELEASE_DELAY_NS);
323 ctrp = (vl_api_ip4_fib_counter_t *)mp->c;
343 ctrp->
address = r->address.as_u32;
350 if (mp->
count == items_this_message)
352 mp->
count = htonl (items_this_message);
365 ip46_fib_stats_delay (sm, 0 ,
376 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
384 start_at_fib_index = fib - im4->
fibs;
441 r->
index = kvp->value;
455 static uword *results;
457 u32 items_this_message;
459 u32 start_at_fib_index = 0;
468 while ((fib - im6->fibs) < start_at_fib_index)
473 items_this_message = IP6_FIB_COUNTER_BATCH_SIZE;
474 mp = vl_msg_api_alloc_as_if_client
476 items_this_message * sizeof (vl_api_ip6_fib_counter_t));
477 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
479 mp->vrf_id = ntohl (fib->ft_table_id);
480 ctrp = (vl_api_ip6_fib_counter_t *) mp->c;
494 start_at_fib_index = fib - im6->
fibs;
500 ip46_fib_stats_delay (sm, 0 ,
528 if (mp->
count == items_this_message)
530 mp->
count = htonl (items_this_message);
543 ip46_fib_stats_delay (sm, 0 ,
554 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
563 start_at_fib_index = fib - im6->
fibs;
600 pthread_sigmask (SIG_SETMASK, &s, 0);
612 ip46_fib_stats_delay (sm, 10 , 0 );
635 u32 count, sw_if_index;
639 mp_size =
sizeof (*mp) + (ntohl (mp->
count) *
646 q = vl_api_client_index_to_input_queue (reg->client_index);
649 if (q_prev && (q_prev->cursize < q_prev->maxsize))
651 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
652 clib_memcpy(mp_copy, mp, mp_size);
653 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
662 count = ntohl (mp->count);
663 sw_if_index = ntohl (mp->first_sw_if_index);
664 if (mp->is_combined == 0)
667 vp = (
u64 *) mp->data;
669 switch (mp->vnet_counter_type)
672 counter_name =
"drop";
675 counter_name =
"punt";
678 counter_name =
"ip4";
681 counter_name =
"ip6";
684 counter_name =
"rx-no-buff";
687 , counter_name =
"rx-miss";
690 , counter_name =
"rx-error (fifo-full)";
693 , counter_name =
"tx-error (fifo-full)";
696 counter_name =
"bogus";
699 for (
i = 0;
i < count;
i++)
702 v = clib_net_to_host_u64 (v);
705 sm->vnet_main, sw_if_index, counter_name, v);
715 switch (mp->vnet_counter_type)
724 counter_name =
"bogus";
727 for (
i = 0;
i < count;
i++)
730 packets = clib_net_to_host_u64 (packets);
732 bytes = clib_net_to_host_u64 (bytes);
734 fformat (stdout,
"%U.%s.packets %lld\n",
736 sm->vnet_main, sw_if_index, counter_name, packets);
737 fformat (stdout,
"%U.%s.bytes %lld\n",
739 sm->vnet_main, sw_if_index, counter_name, bytes);
744 if (q_prev && (q_prev->cursize < q_prev->maxsize))
763 mp_size =
sizeof (*mp_copy) +
769 q = vl_api_client_index_to_input_queue (reg->client_index);
772 if (q_prev && (q_prev->cursize < q_prev->maxsize))
774 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
775 clib_memcpy(mp_copy, mp, mp_size);
776 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
783 if (q_prev && (q_prev->cursize < q_prev->maxsize))
802 mp_size =
sizeof (*mp_copy) +
808 q = vl_api_client_index_to_input_queue (reg->client_index);
811 if (q_prev && (q_prev->cursize < q_prev->maxsize))
813 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
814 clib_memcpy(mp_copy, mp, mp_size);
815 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
822 if (q_prev && (q_prev->cursize < q_prev->maxsize))
889 rmp->_vl_msg_id = ntohs (VL_API_WANT_STATS_REPLY);
914 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler 915 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler 916 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler 917 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler 937 vl_msg_api_set_handlers(VL_API_##N, #n, \ 938 vl_api_##n##_t_handler, \ 940 vl_api_##n##_t_endian, \ 941 vl_api_##n##_t_print, \ 942 sizeof(vl_api_##n##_t), 0 ); 962 .no_data_structure_clone = 1,
static void stats_thread_fn(void *arg)
Want Stats, register for stats updates.
vlib_combined_counter_main_t lbm_to_counters
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)
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).
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)
#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 IP6_FIB_COUNTER_BATCH_SIZE
#define clib_warning(format, args...)
struct vl_shmem_hdr_ * shmem_hdr
A collection of simple counters.
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.
uword * fib_entry_by_dst_address[33]
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
load_balance_main_t load_balance_main
The one instance of load-balance main.
#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)
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)
u32 ft_table_id
Table ID (hash key) for this FIB.
#define IP4_FIB_COUNTER_BATCH_SIZE
static vlib_thread_main_t * vlib_get_thread_main()
static void * clib_mem_set_heap(void *heap)
This table stores the routes that are used to forward traffic.
#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;})
static void vnet_interface_counter_lock(vnet_interface_main_t *im)
#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
ip6_fib_table_instance_t ip6_table[IP6_FIB_NUM_TABLES]
The two FIB tables; fwding and non-fwding.
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)
Iterate over hash pairs.
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)
ip4_main_t ip4_main
Global ip4 main structure.
struct fib_table_t_ * fibs
Vector of FIBs.
#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()
void * vl_msg_api_alloc_as_if_client(int nbytes)
#define CLIB_CACHE_LINE_BYTES
struct fib_table_t_ * fibs
static void vl_api_vnet_interface_counters_t_handler(vl_api_vnet_interface_counters_t *mp)
A protocol Independent FIB table.
struct _unix_shared_memory_queue unix_shared_memory_queue_t
static uword pool_elts(void *v)
Number of active elements in a pool.