32 #define f64_print(a,b) 43 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) 48 #define foreach_stats_msg \ 49 _(WANT_STATS, want_stats) \ 50 _(VNET_INTERFACE_SIMPLE_COUNTERS, vnet_interface_simple_counters) \ 51 _(VNET_INTERFACE_COMBINED_COUNTERS, vnet_interface_combined_counters) \ 52 _(VNET_IP4_FIB_COUNTERS, vnet_ip4_fib_counters) \ 53 _(VNET_IP6_FIB_COUNTERS, vnet_ip6_fib_counters) \ 54 _(VNET_IP4_NBR_COUNTERS, vnet_ip4_nbr_counters) \ 55 _(VNET_IP6_NBR_COUNTERS, vnet_ip6_nbr_counters) 58 #define SIMPLE_COUNTER_BATCH_SIZE 126 59 #define COMBINED_COUNTER_BATCH_SIZE 63 60 #define IP4_FIB_COUNTER_BATCH_SIZE 48 61 #define IP6_FIB_COUNTER_BATCH_SIZE 30 64 #define STATS_RELEASE_DELAY_NS (1000 * 1000 * 5) 86 while (__sync_lock_test_and_set (&l->
lock, 1))
137 u32 items_this_message = 0;
150 for (i = 0; i < n_counts; i++)
158 (
sizeof (*mp) + items_this_message *
sizeof (v));
159 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_SIMPLE_COUNTERS);
169 if (mp->
count == items_this_message)
171 mp->
count = htonl (items_this_message);
191 u32 items_this_message = 0;
200 for (i = 0; i < n_counts; i++)
208 (
sizeof (*mp) + items_this_message *
sizeof (v));
209 mp->_vl_msg_id = ntohs (VL_API_VNET_INTERFACE_COMBINED_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;
581 static uword *results;
583 u32 items_this_message;
585 u32 start_at_fib_index = 0;
593 while ((fib - im4->fibs) < start_at_fib_index)
596 v4_fib = pool_elt_at_index (im4->v4_fibs, fib->ft_index);
600 items_this_message = IP4_FIB_COUNTER_BATCH_SIZE;
601 mp = vl_msg_api_alloc_as_if_client
603 items_this_message * sizeof (vl_api_ip4_fib_counter_t));
604 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
606 mp->vrf_id = ntohl (fib->ft_table_id);
607 ctrp = (vl_api_ip4_fib_counter_t *) mp->c;
612 ASSERT (mp->count == 0);
613 mp->vrf_id = ntohl (fib->ft_table_id);
627 x.address_length =
i;
631 x.address.data_u32 = p->
key;
632 x.index = p->
value[0];
637 start_at_fib_index = fib - im4->
fibs;
639 ip46_fib_stats_delay (sm, 0 ,
662 ctrp->
address = r->address.as_u32;
669 if (mp->
count == items_this_message)
671 mp->
count = htonl (items_this_message);
684 ip46_fib_stats_delay (sm, 0 ,
695 mp->_vl_msg_id = ntohs (VL_API_VNET_IP4_FIB_COUNTERS);
703 start_at_fib_index = fib - im4->
fibs;
760 r->
index = kvp->value;
774 static uword *results;
776 u32 items_this_message;
778 u32 start_at_fib_index = 0;
787 while ((fib - im6->fibs) < start_at_fib_index)
792 items_this_message = IP6_FIB_COUNTER_BATCH_SIZE;
793 mp = vl_msg_api_alloc_as_if_client
795 items_this_message * sizeof (vl_api_ip6_fib_counter_t));
796 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
798 mp->vrf_id = ntohl (fib->ft_table_id);
799 ctrp = (vl_api_ip6_fib_counter_t *) mp->c;
813 start_at_fib_index = fib - im6->
fibs;
819 ip46_fib_stats_delay (sm, 0 ,
847 if (mp->
count == items_this_message)
849 mp->
count = htonl (items_this_message);
862 ip46_fib_stats_delay (sm, 0 ,
873 mp->_vl_msg_id = ntohs (VL_API_VNET_IP6_FIB_COUNTERS);
882 start_at_fib_index = fib - im6->
fibs;
919 pthread_sigmask (SIG_SETMASK, &s, 0);
931 ip46_fib_stats_delay (sm, 10 , 0 );
960 mp_size =
sizeof (*mp) + (ntohl (mp->
count) *
sizeof (
u64));
965 q = vl_api_client_index_to_input_queue (reg->client_index);
968 if (q_prev && (q_prev->cursize < q_prev->maxsize))
970 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
971 clib_memcpy(mp_copy, mp, mp_size);
972 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
981 count = ntohl (mp->count);
984 vp = (
u64 *) mp->data;
986 switch (mp->vnet_counter_type)
989 counter_name =
"drop";
992 counter_name =
"punt";
995 counter_name =
"ip4";
998 counter_name =
"ip6";
1001 counter_name =
"rx-no-buff";
1004 , counter_name =
"rx-miss";
1007 , counter_name =
"rx-error (fifo-full)";
1010 , counter_name =
"tx-error (fifo-full)";
1013 counter_name =
"bogus";
1016 for (
i = 0;
i < count;
i++)
1019 v = clib_net_to_host_u64 (v);
1026 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1057 q = vl_api_client_index_to_input_queue (reg->client_index);
1060 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1062 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
1063 clib_memcpy(mp_copy, mp, mp_size);
1064 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
1073 count = ntohl (mp->count);
1080 switch (mp->vnet_counter_type)
1083 counter_name =
"rx";
1086 counter_name =
"tx";
1089 counter_name =
"bogus";
1092 for (
i = 0;
i < count;
i++)
1095 packets = clib_net_to_host_u64 (packets);
1097 bytes = clib_net_to_host_u64 (bytes);
1099 fformat (stdout,
"%U.%s.packets %lld\n",
1101 sm->vnet_main,
sw_if_index, counter_name, packets);
1102 fformat (stdout,
"%U.%s.bytes %lld\n",
1109 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1128 mp_size =
sizeof (*mp_copy) +
1134 q = vl_api_client_index_to_input_queue (reg->client_index);
1137 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1139 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
1140 clib_memcpy(mp_copy, mp, mp_size);
1141 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
1148 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1167 mp_size =
sizeof (*mp_copy) +
1173 q = vl_api_client_index_to_input_queue (reg->client_index);
1176 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1178 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
1179 clib_memcpy(mp_copy, mp, mp_size);
1180 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
1187 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1206 mp_size =
sizeof (*mp_copy) +
1212 q = vl_api_client_index_to_input_queue (reg->client_index);
1215 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1217 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
1218 clib_memcpy(mp_copy, mp, mp_size);
1219 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
1226 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1245 mp_size =
sizeof (*mp_copy) +
1251 q = vl_api_client_index_to_input_queue (reg->client_index);
1254 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1256 mp_copy = vl_msg_api_alloc_as_if_client(mp_size);
1257 clib_memcpy(mp_copy, mp, mp_size);
1258 vl_msg_api_send_shmem (q_prev, (u8 *)&mp);
1265 if (q_prev && (q_prev->cursize < q_prev->maxsize))
1280 vl_api_want_stats_reply_t *rmp;
1326 rmp->_vl_msg_id = ntohs (VL_API_WANT_STATS_REPLY);
1328 rmp->retval = retval;
1351 #define vl_api_vnet_interface_simple_counters_t_endian vl_noop_handler 1352 #define vl_api_vnet_interface_simple_counters_t_print vl_noop_handler 1353 #define vl_api_vnet_interface_combined_counters_t_endian vl_noop_handler 1354 #define vl_api_vnet_interface_combined_counters_t_print vl_noop_handler 1355 #define vl_api_vnet_ip4_fib_counters_t_endian vl_noop_handler 1356 #define vl_api_vnet_ip4_fib_counters_t_print vl_noop_handler 1357 #define vl_api_vnet_ip6_fib_counters_t_endian vl_noop_handler 1358 #define vl_api_vnet_ip6_fib_counters_t_print vl_noop_handler 1359 #define vl_api_vnet_ip4_nbr_counters_t_endian vl_noop_handler 1360 #define vl_api_vnet_ip4_nbr_counters_t_print vl_noop_handler 1361 #define vl_api_vnet_ip6_nbr_counters_t_endian vl_noop_handler 1362 #define vl_api_vnet_ip6_nbr_counters_t_print vl_noop_handler 1382 vl_msg_api_set_handlers(VL_API_##N, #n, \ 1383 vl_api_##n##_t_handler, \ 1385 vl_api_##n##_t_endian, \ 1386 vl_api_##n##_t_print, \ 1387 sizeof(vl_api_##n##_t), 0 ); 1410 .no_data_structure_clone = 1,
static void stats_thread_fn(void *arg)
void * vl_msg_api_alloc_as_if_client(int nbytes)
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
vl_api_vlib_counter_t data[count]
#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)
vnet_main_t * vnet_get_main(void)
struct ip_adjacency_t_::@37::@38 nbr
IP_LOOKUP_NEXT_ARP/IP_LOOKUP_NEXT_REWRITE.
vnet_interface_main_t interface_main
static void vl_api_vnet_interface_simple_counters_t_handler(vl_api_vnet_interface_simple_counters_t *mp)
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).
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_::@37 sub_type
Combined stats counters structure.
#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.
vnet_link_t ia_link
link/ether-type 1 bytes
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)
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)
void * vl_msg_api_alloc(int nbytes)
#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.
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)
void vl_msg_api_free(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)
static_always_inline uword vlib_get_thread_index(void)
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)
unix_shared_memory_queue_t * vl_api_client_index_to_input_queue(u32 index)
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.
void vl_msg_api_send_shmem(unix_shared_memory_queue_t *q, u8 *elem)
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)
Simple stats counters structure.
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 vl_msg_api_send_shmem_nolock(unix_shared_memory_queue_t *q, u8 *elem)
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...)
A collection of combined counters.
uword * fib_entry_by_dst_address[33]
#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 * vlib_worker_thread_bootstrap_fn(void *arg)
#define CLIB_MEMORY_BARRIER()
static void vl_api_vnet_interface_combined_counters_t_handler(vl_api_vnet_interface_combined_counters_t *mp)
void stats_dsunlock(int hint, int tag)
#define CLIB_CACHE_LINE_BYTES
struct fib_table_t_ * fibs
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.