|
FD.io VPP
v21.10.1-2-g0a485f517
Vector Packet Processing
|
Go to the documentation of this file.
15 #ifndef __included_ioam_export_h__
16 #define __included_ioam_export_h__
84 #define DEFAULT_EXPORT_SIZE (3 * CLIB_CACHE_LINE_BYTES)
89 #define DEFAULT_EXPORT_RECORDS 7
125 b0->
flags |= VLIB_BUFFER_TOTAL_LENGTH_VALID;
188 for (
i = 0;
i < no_of_threads;
i++)
204 #define IPFIX_IOAM_EXPORT_ID 272
205 #define IPFIX_VXLAN_IOAM_EXPORT_ID 273
256 ip->ip_version_and_header_length = 0x45;
258 ip->protocol = IP_PROTOCOL_UDP;
260 ip->dst_address.as_u32 = collector_address->
as_u32;
261 udp->
src_port = clib_host_to_net_u16 (UDP_DST_PORT_ipfix);
262 udp->
dst_port = clib_host_to_net_u16 (UDP_DST_PORT_ipfix);
270 h->domain_id = clib_host_to_net_u32 (em->
domain_id);
318 h->export_time = clib_host_to_net_u32 ((
u32)
331 (sizeof (*
ip) +
sizeof (*udp) +
357 #define EXPORT_TIMEOUT (20.0)
358 #define THREAD_PERIOD (30.0)
367 uword *event_data = 0;
370 u32 *vec_buffer_indices = 0;
371 u32 *vec_buffer_to_be_sent = 0;
373 u32 new_pool_index = 0;
380 clib_warning (
"bogus kickoff event received, %d", event_type);
419 vec_add (vec_buffer_indices, &new_pool_index, 1);
446 for (
i = 0;
i <
vec_len (vec_buffer_to_be_sent);
i++)
457 for (
i = 0;
i <
vec_len (vec_buffer_indices);
i++)
470 #define ioam_export_node_common(EM, VM, N, F, HTYPE, L, V, NEXT, FIXUP_FUNC) \
472 u32 n_left_from, *from, *to_next; \
473 export_next_t next_index; \
474 u32 pkts_recorded = 0; \
475 ioam_export_buffer_t *my_buf = 0; \
476 vlib_buffer_t *eb0 = 0; \
478 from = vlib_frame_vector_args (F); \
479 n_left_from = (F)->n_vectors; \
480 next_index = (N)->cached_next_index; \
481 clib_spinlock_lock (&(EM)->lockp[(VM)->thread_index]); \
482 my_buf = ioam_export_get_my_buffer (EM, (VM)->thread_index); \
483 my_buf->touched_at = vlib_time_now (VM); \
484 while (n_left_from > 0) \
486 u32 n_left_to_next; \
487 vlib_get_next_frame (VM, N, next_index, to_next, n_left_to_next); \
488 while (n_left_from >= 4 && n_left_to_next >= 2) \
494 vlib_buffer_t *p0, *p1; \
495 u32 ip_len0, ip_len1; \
497 vlib_buffer_t *p2, *p3; \
498 p2 = vlib_get_buffer (VM, from[2]); \
499 p3 = vlib_get_buffer (VM, from[3]); \
500 vlib_prefetch_buffer_header (p2, LOAD); \
501 vlib_prefetch_buffer_header (p3, LOAD); \
502 CLIB_PREFETCH (p2->data, 3 * CLIB_CACHE_LINE_BYTES, LOAD); \
503 CLIB_PREFETCH (p3->data, 3 * CLIB_CACHE_LINE_BYTES, LOAD); \
505 to_next[0] = bi0 = from[0]; \
506 to_next[1] = bi1 = from[1]; \
510 n_left_to_next -= 2; \
511 p0 = vlib_get_buffer (VM, bi0); \
512 p1 = vlib_get_buffer (VM, bi1); \
513 ip0 = vlib_buffer_get_current (p0); \
514 ip1 = vlib_buffer_get_current (p1); \
516 clib_net_to_host_u16 (ip0->L) + sizeof (HTYPE); \
518 clib_net_to_host_u16 (ip1->L) + sizeof (HTYPE); \
519 ebi0 = my_buf->buffer_index; \
520 eb0 = vlib_get_buffer (VM, ebi0); \
521 if (PREDICT_FALSE (eb0 == 0)) \
524 ip_len0 > DEFAULT_EXPORT_SIZE ? DEFAULT_EXPORT_SIZE : ip_len0; \
526 ip_len1 > DEFAULT_EXPORT_SIZE ? DEFAULT_EXPORT_SIZE : ip_len1; \
527 copy3cachelines (eb0->data + eb0->current_length, ip0, ip_len0); \
528 FIXUP_FUNC(eb0, p0); \
529 eb0->current_length += DEFAULT_EXPORT_SIZE; \
530 my_buf->records_in_this_buffer++; \
531 if (my_buf->records_in_this_buffer >= DEFAULT_EXPORT_RECORDS) \
533 ioam_export_send_buffer (EM, VM, my_buf); \
534 ioam_export_init_buffer (EM, VM, my_buf); \
536 ebi0 = my_buf->buffer_index; \
537 eb0 = vlib_get_buffer (VM, ebi0); \
538 if (PREDICT_FALSE (eb0 == 0)) \
540 copy3cachelines (eb0->data + eb0->current_length, ip1, ip_len1); \
541 FIXUP_FUNC(eb0, p1); \
542 eb0->current_length += DEFAULT_EXPORT_SIZE; \
543 my_buf->records_in_this_buffer++; \
544 if (my_buf->records_in_this_buffer >= DEFAULT_EXPORT_RECORDS) \
546 ioam_export_send_buffer (EM, VM, my_buf); \
547 ioam_export_init_buffer (EM, VM, my_buf); \
549 pkts_recorded += 2; \
550 if (PREDICT_FALSE (((node)->flags & VLIB_NODE_FLAG_TRACE))) \
552 if (p0->flags & VLIB_BUFFER_IS_TRACED) \
554 export_trace_t *t = \
555 vlib_add_trace (VM, node, p0, sizeof (*t)); \
557 clib_net_to_host_u32 (ip0->V); \
558 t->next_index = next0; \
560 if (p1->flags & VLIB_BUFFER_IS_TRACED) \
562 export_trace_t *t = \
563 vlib_add_trace (VM, N, p1, sizeof (*t)); \
565 clib_net_to_host_u32 (ip1->V); \
566 t->next_index = next1; \
570 vlib_validate_buffer_enqueue_x2 (VM, N, next_index, \
571 to_next, n_left_to_next, \
572 bi0, bi1, next0, next1); \
574 while (n_left_from > 0 && n_left_to_next > 0) \
586 n_left_to_next -= 1; \
587 p0 = vlib_get_buffer (VM, bi0); \
588 ip0 = vlib_buffer_get_current (p0); \
590 clib_net_to_host_u16 (ip0->L) + sizeof (HTYPE); \
591 ebi0 = my_buf->buffer_index; \
592 eb0 = vlib_get_buffer (VM, ebi0); \
593 if (PREDICT_FALSE (eb0 == 0)) \
596 ip_len0 > DEFAULT_EXPORT_SIZE ? DEFAULT_EXPORT_SIZE : ip_len0; \
597 copy3cachelines (eb0->data + eb0->current_length, ip0, ip_len0); \
598 FIXUP_FUNC(eb0, p0); \
599 eb0->current_length += DEFAULT_EXPORT_SIZE; \
600 my_buf->records_in_this_buffer++; \
601 if (my_buf->records_in_this_buffer >= DEFAULT_EXPORT_RECORDS) \
603 ioam_export_send_buffer (EM, VM, my_buf); \
604 ioam_export_init_buffer (EM, VM, my_buf); \
606 if (PREDICT_FALSE (((N)->flags & VLIB_NODE_FLAG_TRACE) \
607 && (p0->flags & VLIB_BUFFER_IS_TRACED))) \
609 export_trace_t *t = vlib_add_trace (VM, (N), p0, sizeof (*t)); \
611 clib_net_to_host_u32 (ip0->V); \
612 t->next_index = next0; \
614 pkts_recorded += 1; \
616 vlib_validate_buffer_enqueue_x1 (VM, N, next_index, \
617 to_next, n_left_to_next, \
620 vlib_put_next_frame (VM, N, next_index, n_left_to_next); \
622 vlib_node_increment_counter (VM, export_node.index, \
623 EXPORT_ERROR_RECORDED, pkts_recorded); \
624 clib_spinlock_unlock (&(EM)->lockp[(VM)->thread_index]); \
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
static void clib_spinlock_init(clib_spinlock_t *p)
CLIB_CACHE_LINE_ALIGN_MARK(cacheline0)
Required for pool_get_aligned.
static void vlib_buffer_free(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers Frees the entire buffer chain for each buffer.
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
static uword ioam_export_process_common(ioam_export_main_t *em, vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f, u32 index)
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P with alignment A.
static void clib_mem_free(void *p)
struct ioam_export_buffer ioam_export_buffer_t
#define pool_put(P, E)
Free an object E in pool P.
vlib_main_t * vm
X-connect all packets from the HOST to the PHY.
vlib_worker_thread_t * vlib_worker_threads
vlib_frame_t * vlib_get_frame_to_node(vlib_main_t *vm, u32 to_node_index)
static_always_inline void * clib_memcpy_fast(void *restrict dst, const void *restrict src, size_t n)
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type,...
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
void vlib_put_frame_to_node(vlib_main_t *vm, u32 to_node_index, vlib_frame_t *f)
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
static __clib_warn_unused_result u32 vlib_buffer_alloc(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Allocate buffers into supplied array.
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
static_always_inline void clib_spinlock_lock(clib_spinlock_t *p)
Fixed length block allocator. Pools are built from clib vectors and bitmaps. Use pools when repeatedl...
#define DEFAULT_EXPORT_SIZE
#define DEFAULT_EXPORT_RECORDS
static int ioam_export_send_buffer(ioam_export_main_t *em, vlib_main_t *vm, ioam_export_buffer_t *eb)
static int ioam_export_thread_buffer_init(ioam_export_main_t *em, vlib_main_t *vm)
ethernet_main_t * ethernet_main
static u32 version_length(u16 length)
#define CLIB_CACHE_LINE_BYTES
#define vec_pop(V)
Returns last element of a vector and decrements its length.
u16 current_length
Nbytes between current data and the end of this buffer.
u32 export_process_node_index
#define pool_alloc_aligned(P, N, A)
Allocate N more free elements to pool (general version).
#define vec_free(V)
Free vector's memory (no header).
#define CLIB_SPINLOCK_IS_LOCKED(_p)
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
static int ioam_export_buffer_add_header(ioam_export_main_t *em, vlib_buffer_t *b0)
ioam_export_buffer_t * buffer_pool
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
static void ioam_export_reset_next_node(ioam_export_main_t *em)
ipfix_data_packet_t ipfix
static_always_inline void clib_spinlock_unlock(clib_spinlock_t *p)
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
#define ip_csum_update(sum, old, new, type, field)
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
vnet_interface_output_runtime_t * rt
static u16 ip4_header_checksum(ip4_header_t *i)
#define pool_free(p)
Free a pool.
static u32 ipfix_set_id_length(u16 set_id, u16 length)
static int ioam_export_header_create(ioam_export_main_t *em, ip4_address_t *collector_address, ip4_address_t *src_address)
#define clib_warning(format, args...)
static void ioam_export_set_next_node(ioam_export_main_t *em, u8 *next_node_name)
static void ioam_export_header_cleanup(ioam_export_main_t *em, ip4_address_t *collector_address, ip4_address_t *src_address)
static void ioam_export_thread_buffer_free(ioam_export_main_t *em)
static f64 vlib_time_now(vlib_main_t *vm)
ip4_address_t src_address
static ioam_export_buffer_t * ioam_export_get_my_buffer(ioam_export_main_t *em, u32 thread_id)
u8 records_in_this_buffer
vl_api_address_union_t src_address
ip4_address_t ipfix_collector
static u16 ip_csum_fold(ip_csum_t c)
static int ioam_export_init_buffer(ioam_export_main_t *em, vlib_main_t *vm, ioam_export_buffer_t *eb)
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index,...
VLIB buffer representation.