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))
134 u32 items_this_message = 0;
152 vec_len (cm->
maxi) - i);
155 (
sizeof (*mp) + items_this_message *
sizeof (v));
156 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COUNTERS);
167 if (mp->
count == items_this_message)
169 mp->
count = htonl (items_this_message);
189 u32 items_this_message = 0;
203 vec_len (cm->
maxi) - i);
206 (
sizeof (*mp) + items_this_message *
sizeof (v));
207 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COUNTERS);
216 = clib_host_to_net_u64 (v.
packets);
220 if (mp->
count == items_this_message)
222 mp->
count = htonl (items_this_message);
237 u32 address_length: 6;
244 struct timespec _req, *req = &_req;
245 struct timespec _rem, *rem = &_rem;
251 if (nanosleep (req, rem) == 0)
268 static ip4_route_t *routes;
272 static uword *results;
274 u32 items_this_message;
276 u32 start_at_fib_index = 0;
284 while ((fib - im4->fibs) < start_at_fib_index)
289 items_this_message = IP4_FIB_COUNTER_BATCH_SIZE;
290 mp = vl_msg_api_alloc_as_if_client
292 items_this_message * sizeof (vl_api_ip4_fib_counter_t));
293 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
295 mp->vrf_id = ntohl (fib->ft_table_id);
296 ctrp = (vl_api_ip4_fib_counter_t *) mp->c;
301 ASSERT (mp->count == 0);
302 mp->vrf_id = ntohl (fib->ft_table_id);
316 x.address_length =
i;
320 x.address.data_u32 = p->
key;
323 x.index = vec_len (results);
324 vec_add (results, p->value, lm->fib_result_n_words);
327 x.index = p->
value[0];
332 start_at_fib_index = fib - im4->fibs;
334 ip46_fib_stats_delay (sm, 0 ,
335 STATS_RELEASE_DELAY_NS);
337 ctrp = (vl_api_ip4_fib_counter_t *)mp->c;
357 ctrp->
address = r->address.as_u32;
364 if (mp->
count == items_this_message)
366 mp->
count = htonl (items_this_message);
379 ip46_fib_stats_delay (sm, 0 ,
390 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
398 start_at_fib_index = fib - im4->
fibs;
455 r->
index = kvp->value;
469 static uword *results;
471 u32 items_this_message;
473 u32 start_at_fib_index = 0;
482 while ((fib - im6->fibs) < start_at_fib_index)
487 items_this_message = IP6_FIB_COUNTER_BATCH_SIZE;
488 mp = vl_msg_api_alloc_as_if_client
490 items_this_message * sizeof (vl_api_ip6_fib_counter_t));
491 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
493 mp->vrf_id = ntohl (fib->ft_table_id);
494 ctrp = (vl_api_ip6_fib_counter_t *) mp->c;
508 start_at_fib_index = fib - im6->
fibs;
514 ip46_fib_stats_delay (sm, 0 ,
542 if (mp->
count == items_this_message)
544 mp->
count = htonl (items_this_message);
557 ip46_fib_stats_delay (sm, 0 ,
568 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
577 start_at_fib_index = fib - im6->
fibs;
614 pthread_sigmask (SIG_SETMASK, &s, 0);
626 ip46_fib_stats_delay (sm, 10 , 0 );
649 u32 count, sw_if_index;
653 mp_size =
sizeof (*mp) + (ntohl (mp->
count) *
660 q = vl_api_client_index_to_input_queue (reg->client_index);
663 if (q_prev && (q_prev->cursize < q_prev->maxsize))
665 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
666 clib_memcpy(mp_copy, mp, mp_size);
667 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
676 count = ntohl (mp->count);
677 sw_if_index = ntohl (mp->first_sw_if_index);
678 if (mp->is_combined == 0)
681 vp = (
u64 *) mp->data;
683 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++)
716 v = clib_net_to_host_u64 (v);
719 sm->vnet_main, sw_if_index, counter_name, v);
729 switch (mp->vnet_counter_type)
738 counter_name =
"bogus";
741 for (
i = 0;
i < count;
i++)
744 packets = clib_net_to_host_u64 (packets);
746 bytes = clib_net_to_host_u64 (bytes);
748 fformat (stdout,
"%U.%s.packets %lld\n",
750 sm->vnet_main, sw_if_index, counter_name, packets);
751 fformat (stdout,
"%U.%s.bytes %lld\n",
753 sm->vnet_main, sw_if_index, counter_name, bytes);
758 if (q_prev && (q_prev->cursize < q_prev->maxsize))
777 mp_size =
sizeof (*mp_copy) +
783 q = vl_api_client_index_to_input_queue (reg->client_index);
786 if (q_prev && (q_prev->cursize < q_prev->maxsize))
788 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
789 clib_memcpy(mp_copy, mp, mp_size);
790 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
797 if (q_prev && (q_prev->cursize < q_prev->maxsize))
816 mp_size =
sizeof (*mp_copy) +
822 q = vl_api_client_index_to_input_queue (reg->client_index);
825 if (q_prev && (q_prev->cursize < q_prev->maxsize))
827 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
828 clib_memcpy(mp_copy, mp, mp_size);
829 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
836 if (q_prev && (q_prev->cursize < q_prev->maxsize))
903 rmp->_vl_msg_id = ntohs (VL_API_WANT_STATS_REPLY);
928 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler 929 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler 930 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler 931 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler 951 vl_msg_api_set_handlers(VL_API_##N, #n, \ 952 vl_api_##n##_t_handler, \ 954 vl_api_##n##_t_endian, \ 955 vl_api_##n##_t_print, \ 956 sizeof(vl_api_##n##_t), 0 ); 976 .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)
void stats_dslock_with_hint(int hint, int tag)
#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.
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)
void stats_dsunlock(int hint, int tag)
#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.