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 _(VNET_INTERFACE_COUNTERS, vnet_interface_counters) \ 50 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \ 51 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \ 52 _(VNET_IP4_NBR_COUNTERS, vnet_ip4_nbr_counters) \ 53 _(VNET_IP6_NBR_COUNTERS, vnet_ip6_nbr_counters) 56 #define SIMPLE_COUNTER_BATCH_SIZE 126 57 #define COMBINED_COUNTER_BATCH_SIZE 63 58 #define IP4_FIB_COUNTER_BATCH_SIZE 48 59 #define IP6_FIB_COUNTER_BATCH_SIZE 30 62 #define STATS_RELEASE_DELAY_NS (1000 * 1000 * 5) 84 while (__sync_lock_test_and_set (&l->
lock, 1))
135 u32 items_this_message = 0;
148 for (i = 0; i < n_counts; i++)
156 (
sizeof (*mp) + items_this_message *
sizeof (v));
157 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COUNTERS);
168 if (mp->
count == items_this_message)
170 mp->
count = htonl (items_this_message);
190 u32 items_this_message = 0;
199 for (i = 0; i < n_counts; i++)
207 (
sizeof (*mp) + items_this_message *
sizeof (v));
208 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COUNTERS);
217 = clib_host_to_net_u64 (v.
packets);
221 if (mp->
count == items_this_message)
223 mp->
count = htonl (items_this_message);
238 u32 address_length: 6;
245 struct timespec _req, *req = &_req;
246 struct timespec _rem, *rem = &_rem;
252 if (nanosleep (req, rem) == 0)
295 vl_counter->
bytes = clib_host_to_net_u64 (adj_counter.
bytes);
302 #define MIN(x,y) (((x)<(y))?(x):(y)) 329 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_NBR_COUNTERS);
330 mp->
count = ntohl (n_items);
357 ip46_fib_stats_delay (sm, 0 ,
380 ctx.sw_if_index = si->sw_if_index;
386 ASSERT(ctx.counters == NULL);
396 adj_nbr_walk (si->sw_if_index,
406 if (NULL != ctx.counters)
408 ip4_nbr_ship(sm, &ctx);
448 vl_counter->
bytes = clib_host_to_net_u64(adj_counter.
bytes);
456 #define MIN(x,y) (((x)<(y))?(x):(y)) 484 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_NBR_COUNTERS);
485 mp->
count = ntohl (n_items);
512 ip46_fib_stats_delay (sm, 0 ,
535 ctx.sw_if_index = si->sw_if_index;
541 ASSERT(ctx.counters == NULL);
551 adj_nbr_walk (si->sw_if_index,
561 if (NULL != ctx.counters)
563 ip6_nbr_ship(sm, &ctx);
576 static ip4_route_t *routes;
580 static uword *results;
582 u32 items_this_message;
584 u32 start_at_fib_index = 0;
592 while ((fib - im4->fibs) < start_at_fib_index)
597 items_this_message = IP4_FIB_COUNTER_BATCH_SIZE;
598 mp = vl_msg_api_alloc_as_if_client
600 items_this_message * sizeof (vl_api_ip4_fib_counter_t));
601 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
603 mp->vrf_id = ntohl (fib->ft_table_id);
604 ctrp = (vl_api_ip4_fib_counter_t *) mp->c;
609 ASSERT (mp->count == 0);
610 mp->vrf_id = ntohl (fib->ft_table_id);
624 x.address_length =
i;
628 x.address.data_u32 = p->
key;
629 x.index = p->
value[0];
634 start_at_fib_index = fib - im4->
fibs;
636 ip46_fib_stats_delay (sm, 0 ,
659 ctrp->
address = r->address.as_u32;
666 if (mp->
count == items_this_message)
668 mp->
count = htonl (items_this_message);
681 ip46_fib_stats_delay (sm, 0 ,
692 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
700 start_at_fib_index = fib - im4->
fibs;
757 r->
index = kvp->value;
771 static uword *results;
773 u32 items_this_message;
775 u32 start_at_fib_index = 0;
784 while ((fib - im6->fibs) < start_at_fib_index)
789 items_this_message = IP6_FIB_COUNTER_BATCH_SIZE;
790 mp = vl_msg_api_alloc_as_if_client
792 items_this_message * sizeof (vl_api_ip6_fib_counter_t));
793 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
795 mp->vrf_id = ntohl (fib->ft_table_id);
796 ctrp = (vl_api_ip6_fib_counter_t *) mp->c;
810 start_at_fib_index = fib - im6->
fibs;
816 ip46_fib_stats_delay (sm, 0 ,
844 if (mp->
count == items_this_message)
846 mp->
count = htonl (items_this_message);
859 ip46_fib_stats_delay (sm, 0 ,
870 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
879 start_at_fib_index = fib - im6->
fibs;
916 pthread_sigmask (SIG_SETMASK, &s, 0);
928 ip46_fib_stats_delay (sm, 10 , 0 );
957 mp_size =
sizeof (*mp) + (ntohl (mp->
count) *
964 q = vl_api_client_index_to_input_queue (reg->client_index);
967 if (q_prev && (q_prev->cursize < q_prev->maxsize))
969 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
970 clib_memcpy(mp_copy, mp, mp_size);
971 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
980 count = ntohl (mp->count);
982 if (mp->is_combined == 0)
985 vp = (
u64 *) mp->data;
987 switch (mp->vnet_counter_type)
990 counter_name =
"drop";
993 counter_name =
"punt";
996 counter_name =
"ip4";
999 counter_name =
"ip6";
1002 counter_name =
"rx-no-buff";
1005 , counter_name =
"rx-miss";
1008 , counter_name =
"rx-error (fifo-full)";
1011 , counter_name =
"tx-error (fifo-full)";
1014 counter_name =
"bogus";
1017 for (
i = 0;
i < count;
i++)
1020 v = clib_net_to_host_u64 (v);
1033 switch (mp->vnet_counter_type)
1036 counter_name =
"rx";
1039 counter_name =
"tx";
1042 counter_name =
"bogus";
1045 for (
i = 0;
i < count;
i++)
1048 packets = clib_net_to_host_u64 (packets);
1050 bytes = clib_net_to_host_u64 (bytes);
1052 fformat (stdout,
"%U.%s.packets %lld\n",
1054 sm->vnet_main,
sw_if_index, counter_name, packets);
1055 fformat (stdout,
"%U.%s.bytes %lld\n",
1062 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1081 mp_size =
sizeof (*mp_copy) +
1087 q = vl_api_client_index_to_input_queue (reg->client_index);
1090 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1092 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
1093 clib_memcpy(mp_copy, mp, mp_size);
1094 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
1101 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1120 mp_size =
sizeof (*mp_copy) +
1126 q = vl_api_client_index_to_input_queue (reg->client_index);
1129 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1131 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
1132 clib_memcpy(mp_copy, mp, mp_size);
1133 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
1140 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1159 mp_size =
sizeof (*mp_copy) +
1165 q = vl_api_client_index_to_input_queue (reg->client_index);
1168 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1170 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
1171 clib_memcpy(mp_copy, mp, mp_size);
1172 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
1179 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1198 mp_size =
sizeof (*mp_copy) +
1204 q = vl_api_client_index_to_input_queue (reg->client_index);
1207 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1209 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
1210 clib_memcpy(mp_copy, mp, mp_size);
1211 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
1218 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1279 rmp->_vl_msg_id = ntohs (VL_API_WANT_STATS_REPLY);
1304 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler 1305 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler 1306 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler 1307 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler 1308 #define vl_api_vnet_ip4_nbr_counters_t_endian vl_noop_handler 1309 #define vl_api_vnet_ip4_nbr_counters_t_print vl_noop_handler 1310 #define vl_api_vnet_ip6_nbr_counters_t_endian vl_noop_handler 1311 #define vl_api_vnet_ip6_nbr_counters_t_print vl_noop_handler 1331 vl_msg_api_set_handlers(VL_API_##N, #n, \ 1332 vl_api_##n##_t_handler, \ 1334 vl_api_##n##_t_endian, \ 1335 vl_api_##n##_t_print, \ 1336 sizeof(vl_api_##n##_t), 0 ); 1358 .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
#define hash_set(h, key, value)
u32 vlib_simple_counter_n_counters(const vlib_simple_counter_main_t *cm)
The number of counters (not the number of per-thread counters)
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)
static adj_walk_rc_t ip6_nbr_stats_cb(adj_index_t ai, void *arg)
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
vnet_main_t * vnet_get_main(void)
struct ip_adjacency_t_::@138::@139 nbr
IP_LOOKUP_NEXT_ARP/IP_LOOKUP_NEXT_REWRITE.
vnet_interface_main_t interface_main
Reply for Want Stats request.
unix_shared_memory_queue_t * vl_input_queue
u32 sw_if_index
The SW IF index all these adjs belong to.
#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.
vl_api_ip4_nbr_counter_t c[count]
VLIB_REGISTER_THREAD(stats_thread_reg, static)
ip_lookup_main_t lookup_main
void clib_longjmp(clib_longjmp_t *save, uword return_value)
union ip_adjacency_t_::@138 sub_type
#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.
static void vl_api_vnet_ip4_nbr_counters_t_handler(vl_api_vnet_ip4_nbr_counters_t *mp)
volatile u32 release_hint
static counter_t vlib_get_simple_counter(vlib_simple_counter_main_t *cm, u32 index)
Get the value of a simple counter Scrapes the entire set of per-thread counters.
static ip_adjacency_t * adj_get(adj_index_t adj_index)
Get a pointer to an adjacency object from its index.
#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
enum adj_walk_rc_t_ adj_walk_rc_t
return codes from a adjacency walker callback function
#define IP6_FIB_COUNTER_BATCH_SIZE
struct vl_shmem_hdr_ * shmem_hdr
static void do_ip4_nbrs(stats_main_t *sm)
A collection of simple counters.
static adj_walk_rc_t ip4_nbr_stats_cb(adj_index_t ai, void *arg)
void vlib_set_thread_name(char *name)
#define foreach_stats_msg
vl_shmem_hdr_t * shmem_hdr
static heap_elt_t * first(heap_header_t *h)
void dsunlock(stats_main_t *sm)
struct ip4_nbr_stats_ctx_t_ ip4_nbr_stats_ctx_t
The context passed when collecting adjacency counters.
vl_api_ip4_nbr_counter_t * counters
A vector of ip4 nbr counters.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
uword * fib_entry_by_dst_address[33]
counter_t packets
packet counter
static void do_ip6_fibs(stats_main_t *sm)
u32 vlib_combined_counter_n_counters(const vlib_combined_counter_main_t *cm)
The number of counters (not the number of per-thread counters)
uword os_get_cpu_number(void)
#define pool_put(P, E)
Free an object E in pool P.
vlib_simple_counter_main_t * sw_if_counters
load_balance_main_t load_balance_main
The one instance of load-balance main.
static void ip4_nbr_ship(stats_main_t *sm, ip4_nbr_stats_ctx_t *ctx)
#define SIMPLE_COUNTER_BATCH_SIZE
void unix_shared_memory_queue_lock(unix_shared_memory_queue_t *q)
#define COMBINED_COUNTER_BATCH_SIZE
vl_api_ip6_nbr_counter_t * counters
A vector of ip6 nbr counters.
vlib_combined_counter_main_t adjacency_counters
Adjacency packet counters.
static void do_simple_interface_counters(stats_main_t *sm)
The context passed when collecting adjacency counters.
void clib_bihash_foreach_key_value_pair(clib_bihash *h, void *callback, void *arg)
Visit active (key,value) pairs in a bi-hash table.
u32 sw_if_index
The SW IF index all these adjs belong to.
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.
static void vlib_get_combined_counter(const 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 per-thr...
#define IP4_FIB_COUNTER_BATCH_SIZE
static void * clib_mem_set_heap(void *heap)
#define clib_warning(format, args...)
This table stores the routes that are used to forward traffic.
#define clib_memcpy(a, b, c)
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)
u32 adj_index_t
An index for adjacencies.
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)
struct ip6_nbr_stats_ctx_t_ ip6_nbr_stats_ctx_t
The context passed when collecting adjacency counters.
static void do_ip6_nbrs(stats_main_t *sm)
void stats_dslock_with_hint(int hint, int tag)
static void ip6_nbr_ship(stats_main_t *sm, ip6_nbr_stats_ctx_t *ctx)
#define STATS_RELEASE_DELAY_NS
The context passed when collecting adjacency counters.
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]
counter_t bytes
byte counter
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.
vnet_sw_interface_t * sw_interfaces
#define clib_unix_warning(format, args...)
Stats counters structure.
A collection of combined counters.
#define clib_mem_unaligned(pointer, type)
static void do_ip4_fibs(stats_main_t *sm)
static void vl_api_vnet_ip6_nbr_counters_t_handler(vl_api_vnet_ip6_nbr_counters_t *mp)
static void * clib_mem_alloc_aligned(uword size, uword align)
ip4_main_t ip4_main
Global ip4 main structure.
static vlib_thread_main_t * vlib_get_thread_main()
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)
vl_api_ip6_nbr_counter_t c[count]
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.