61 for (i = 0; i < n_alloc; i++)
67 new_data_len = (
u16) ((
i16) mb->data_len + delta);
68 new_pkt_len = (
u16) ((
i16) mb->pkt_len + delta);
70 mb->data_len = new_data_len;
71 mb->pkt_len = new_pkt_len;
79 u32 data_offset,
u32 n_bytes)
92 for (i = 0; i < n_bytes; i++)
93 if ((bd[i] & pm[i]) != pd[
i])
117 ASSERT (v0 >= v_min && v0 <= v_max);
124 if (is_net_byte_order)
125 v0 = clib_host_to_net_u16 (v0);
130 if (is_net_byte_order)
131 v0 = clib_host_to_net_u32 (v0);
136 if (is_net_byte_order)
137 v0 = clib_host_to_net_u64 (v0);
146 u32 n_bits,
u32 is_net_byte_order,
u32 is_increment)
148 ASSERT (v0 >= v_min && v0 <= v_max);
149 ASSERT (v1 >= v_min && v1 <= (v_max + is_increment));
157 if (is_net_byte_order)
159 v0 = clib_host_to_net_u16 (v0);
160 v1 = clib_host_to_net_u16 (v1);
167 if (is_net_byte_order)
169 v0 = clib_host_to_net_u32 (v0);
170 v1 = clib_host_to_net_u32 (v1);
177 if (is_net_byte_order)
179 v0 = clib_host_to_net_u64 (v0);
180 v1 = clib_host_to_net_u64 (v1);
193 u32 byte_offset,
u32 is_net_byte_order,
u64 v_min,
u64 v_max)
197 while (n_buffers >= 4)
209 a0 = (
void *) b0 + byte_offset;
210 a1 = (
void *) b1 + byte_offset;
211 CLIB_PREFETCH ((
void *) b2 + byte_offset,
sizeof (v_min), WRITE);
212 CLIB_PREFETCH ((
void *) b3 + byte_offset,
sizeof (v_min), WRITE);
214 set_2 (a0, a1, v_min, v_min, v_min, v_max, n_bits, is_net_byte_order,
221 while (n_buffers > 0)
230 a0 = (
void *) b0 + byte_offset;
232 set_1 (a0, v_min, v_min, v_max, n_bits, is_net_byte_order);
245 u32 is_net_byte_order,
251 ASSERT (v >= v_min && v <= v_max);
253 while (n_buffers >= 4)
266 a0 = (
void *) b0 + byte_offset;
267 a1 = (
void *) b1 + byte_offset;
268 CLIB_PREFETCH ((
void *) b2 + byte_offset,
sizeof (v_min), WRITE);
269 CLIB_PREFETCH ((
void *) b3 + byte_offset,
sizeof (v_min), WRITE);
273 v = v > v_max ? v_min : v;
275 v_old + 0, v_old + 1, v_min, v_max, n_bits, is_net_byte_order,
279 sum += 2 * v_old + 1;
284 sum -= 2 * v_old + 1;
287 set_1 (a0, v + 0, v_min, v_max, n_bits, is_net_byte_order);
292 v = v > v_max ? v_min : v;
293 set_1 (a1, v + 0, v_min, v_max, n_bits, is_net_byte_order);
303 while (n_buffers > 0)
313 a0 = (
void *) b0 + byte_offset;
319 v = v > v_max ? v_min : v;
321 ASSERT (v_old >= v_min && v_old <= v_max);
322 set_1 (a0, v_old, v_min, v_max, n_bits, is_net_byte_order);
340 u32 is_net_byte_order,
344 u64 v_diff = v_max - v_min + 1;
355 while (n_buffers >= 4)
368 a0 = (
void *) b0 + byte_offset;
369 a1 = (
void *) b1 + byte_offset;
370 CLIB_PREFETCH ((
void *) b2 + byte_offset,
sizeof (v_min), WRITE);
371 CLIB_PREFETCH ((
void *) b3 + byte_offset,
sizeof (v_min), WRITE);
378 u##n * r = random_data; \ 381 random_data = r + 2; \ 398 v0 = v0 > v_max ? v0 - v_diff : v0;
399 v1 = v1 > v_max ? v1 - v_diff : v1;
400 v0 = v0 > v_max ? v0 - v_diff : v0;
401 v1 = v1 > v_max ? v1 - v_diff : v1;
406 set_2 (a0, a1, v0, v1, v_min, v_max, n_bits, is_net_byte_order,
413 while (n_buffers > 0)
423 a0 = (
void *) b0 + byte_offset;
430 u##n * r = random_data; \ 432 random_data = r + 1; \ 448 v0 = v0 > v_max ? v0 - v_diff : v0;
449 v0 = v0 > v_max ? v0 - v_diff : v0;
454 set_1 (a0, v0, v_min, v_max, n_bits, is_net_byte_order);
464 clib_mem_unaligned (a##i, t) = \ 465 clib_host_to_net_##t ((clib_net_to_host_mem_##t (a##i) &~ mask) \ 474 ASSERT (v0 >= v_min && v0 <= v_max);
475 if (max_bits ==
BITS (
u8))
476 ((
u8 *) a0)[0] = (((
u8 *) a0)[0] & ~mask) | (v0 << shift);
478 else if (max_bits ==
BITS (
u16))
482 else if (max_bits ==
BITS (
u32))
486 else if (max_bits ==
BITS (
u64))
498 ASSERT (v0 >= v_min && v0 <= v_max);
499 ASSERT (v1 >= v_min && v1 <= v_max + is_increment);
500 if (max_bits ==
BITS (
u8))
502 ((
u8 *) a0)[0] = (((
u8 *) a0)[0] & ~mask) | (v0 << shift);
503 ((
u8 *) a1)[0] = (((
u8 *) a1)[0] & ~mask) | (v1 << shift);
506 else if (max_bits ==
BITS (
u16))
511 else if (max_bits ==
BITS (
u32))
516 else if (max_bits ==
BITS (
u64))
536 while (n_buffers >= 4)
548 a0 = (
void *) b0 + byte_offset;
549 a1 = (
void *) b1 + byte_offset;
550 CLIB_PREFETCH ((
void *) b2 + byte_offset,
sizeof (v_min), WRITE);
551 CLIB_PREFETCH ((
void *) b3 + byte_offset,
sizeof (v_min), WRITE);
554 v_min, v_min, v_min, v_max, max_bits, n_bits, mask, shift,
561 while (n_buffers > 0)
570 a0 = (
void *) b0 + byte_offset;
572 setbits_1 (a0, v_min, v_min, v_max, max_bits, n_bits, mask, shift);
589 ASSERT (v >= v_min && v <= v_max);
591 while (n_buffers >= 4)
604 a0 = (
void *) b0 + byte_offset;
605 a1 = (
void *) b1 + byte_offset;
606 CLIB_PREFETCH ((
void *) b2 + byte_offset,
sizeof (v_min), WRITE);
607 CLIB_PREFETCH ((
void *) b3 + byte_offset,
sizeof (v_min), WRITE);
611 v = v > v_max ? v_min : v;
613 v_old + 0, v_old + 1,
614 v_min, v_max, max_bits, n_bits, mask, shift,
620 setbits_1 (a0, v + 0, v_min, v_max, max_bits, n_bits, mask, shift);
623 v = v > v_max ? v_min : v;
624 setbits_1 (a1, v + 0, v_min, v_max, max_bits, n_bits, mask, shift);
631 while (n_buffers > 0)
641 a0 = (
void *) b0 + byte_offset;
645 v = v > v_max ? v_min : v;
647 ASSERT (v_old >= v_min && v_old <= v_max);
648 setbits_1 (a0, v_old, v_min, v_max, max_bits, n_bits, mask, shift);
666 u64 v_diff = v_max - v_min + 1;
675 while (n_buffers >= 4)
688 a0 = (
void *) b0 + byte_offset;
689 a1 = (
void *) b1 + byte_offset;
690 CLIB_PREFETCH ((
void *) b2 + byte_offset,
sizeof (v_min), WRITE);
691 CLIB_PREFETCH ((
void *) b3 + byte_offset,
sizeof (v_min), WRITE);
698 u##n * r = random_data; \ 701 random_data = r + 2; \ 718 v0 = v0 > v_max ? v0 - v_diff : v0;
719 v1 = v1 > v_max ? v1 - v_diff : v1;
720 v0 = v0 > v_max ? v0 - v_diff : v0;
721 v1 = v1 > v_max ? v1 - v_diff : v1;
723 setbits_2 (a0, a1, v0, v1, v_min, v_max, max_bits, n_bits, mask, shift,
730 while (n_buffers > 0)
740 a0 = (
void *) b0 + byte_offset;
747 u##n * r = random_data; \ 749 random_data = r + 1; \ 765 v0 = v0 > v_max ? v0 - v_diff : v0;
766 v0 = v0 > v_max ? v0 - v_diff : v0;
768 setbits_1 (a0, v0, v_min, v_max, max_bits, n_bits, mask, shift);
782 u32 max_bits, l0, l1, h1, start_bit;
791 start_bit = l0 *
BITS (
u8);
793 max_bits = hi_bit - start_bit;
798 if (edit_type == PG_EDIT_INCREMENT) \ 799 v = do_set_increment (pg, s, buffers, n_buffers, \ 806 else if (edit_type == PG_EDIT_RANDOM) \ 807 do_set_random (pg, s, buffers, n_buffers, \ 814 do_set_fixed (pg, s, buffers, n_buffers, \ 821 if (l1 == 0 && h1 == 0)
837 u32 n_bits = max_bits;
841 mask = ((
u64) 1 << (
u64) n_bits) - 1;
842 mask &= ~(((
u64) 1 << (
u64) shift) - 1);
844 mask <<= max_bits - n_bits;
845 shift += max_bits - n_bits;
851 if (edit_type == PG_EDIT_INCREMENT) \ 852 v = do_setbits_increment (pg, s, buffers, n_buffers, \ 853 BITS (u##n), n_bits, \ 854 l0, v_min, v_max, v, \ 856 else if (edit_type == PG_EDIT_RANDOM) \ 857 do_setbits_random (pg, s, buffers, n_buffers, \ 858 BITS (u##n), n_bits, \ 862 do_setbits_fixed (pg, s, buffers, n_buffers, \ 863 BITS (u##n), n_bits, \ 885 u64 v_min, v_max, length_sum;
916 length_sum = v_min * n_buffers;
937 u32 * buffers,
u32 n_buffers)
942 static u32 *unused_buffers = 0;
944 while (n_buffers > 0)
962 if (n_bytes_left > 0)
978 ASSERT (n_bytes_left == 0);
984 if (
vec_len (unused_buffers) > 0)
987 _vec_len (unused_buffers) = 0;
1012 lo_bit = hi_bit - e->
n_bits;
1015 =
do_it (pg, s, buffers, n_buffers, lo_bit, hi_bit, v_min, v_max,
1045 u32 * buffers,
u32 * next_buffers,
u32 n_buffers)
1049 while (n_buffers >= 4)
1056 ni0 = next_buffers[0];
1057 ni1 = next_buffers[1];
1072 while (n_buffers > 0)
1078 ni0 = next_buffers[0];
1092 u32 n_buffers,
u32 data_offset,
u32 n_data)
1094 u32 n_left, *b,
i, l;
1120 if (data_offset + n_data >=
vec_len (d0))
1121 n0 =
vec_len (d0) > data_offset ?
vec_len (d0) - data_offset : 0;
1126 i = i + 1 == l ? 0 : i + 1;
1134 u32 n_buffers,
u32 data_offset,
u32 n_data,
u32 set_data)
1236 u32 * buffers,
u32 * next_buffers,
u32 n_alloc)
1255 if (is_start_of_packet)
1263 if (n_allocated == 0)
1270 n_alloc = n_allocated;
1273 if (DPDK == 0 || CLIB_DEBUG > 0
1284 ASSERT (next_buffers == 0);
1288 if (is_start_of_packet)
1298 for (i = 0; i < n_alloc; i++)
1325 word i, n_in_fifo, n_alloc, n_free, n_added;
1326 u32 *tail, *start, *end, *last_tail, *last_start;
1331 if (n_in_fifo >= n_buffers)
1334 n_alloc = n_buffers - n_in_fifo;
1360 last_tail = last_start = 0;
1368 if (n_free < n_alloc)
1375 if (tail + n_alloc <= end)
1385 if (n_added == n && n_alloc > n_added)
1388 (pg, s, bi, start, last_start, n_alloc - n_added);
1408 struct rte_mbuf *mb;
1410 b = vlib_get_buffer(vm, bi0[0]);
1411 mb = rte_mbuf_from_vlib_buffer(b);
1412 ASSERT(rte_mbuf_refcnt_read(mb) == 1);
1419 return n_in_fifo + n_added;
1479 u32 *b, n_left, stream_index, next_index;
1483 stream_index = s - pg->
streams;
1550 u32 *to_next, n_this_frame, n_left, n_trace, n_packets_in_fifo;
1551 uword n_packets_generated;
1556 n_packets_in_fifo =
pg_stream_fill (pg, s, n_packets_to_generate);
1557 n_packets_to_generate =
clib_min (n_packets_in_fifo, n_packets_to_generate);
1558 n_packets_generated = 0;
1560 while (n_packets_to_generate > 0)
1562 u32 *head, *start, *end;
1566 n_this_frame = n_packets_to_generate;
1567 if (n_this_frame > n_left)
1568 n_this_frame = n_left;
1574 if (head + n_this_frame <= end)
1593 n_packets_to_generate -= n_this_frame;
1594 n_packets_generated += n_this_frame;
1595 n_left -= n_this_frame;
1599 return n_packets_generated;
1655 uword n_packets = 0;
1659 n_packets += pg_input_stream (node, pg, vec_elt_at_index (pg->streams, i));
1675 .state = VLIB_NODE_STATE_DISABLED,
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
sll srl srl sll sra u16x4 i
#define clib_fifo_head(v)
#define rte_mbuf_from_vlib_buffer(x)
static u32 vlib_get_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt)
static vlib_main_t * vlib_get_main(void)
static uword clib_fifo_elts(void *v)
vnet_interface_main_t interface_main
format_function_t format_vlib_buffer
pg_edit_group_t * edit_groups
#define clib_fifo_advance_tail(f, n_elts)
u32 vlib_buffer_alloc_from_free_list(vlib_main_t *vm, u32 *buffers, u32 n_buffers, u32 free_list_index)
Allocate buffers from specific freelist into supplied array.
static f64 vlib_time_now(vlib_main_t *vm)
#define clib_fifo_resize(f, n_elts)
static void * clib_random_buffer_get_data(clib_random_buffer_t *b, uword n_bytes)
vlib_buffer_t buffer_init_template
void(* edit_function)(struct pg_main_t *pg, struct pg_stream_t *s, struct pg_edit_group_t *g, u32 *buffers, u32 n_buffers)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define STRUCT_OFFSET_OF(t, f)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
pg_buffer_index_t * buffer_indices
pg_edit_type_t packet_size_edit_type
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
u8 * fixed_packet_data_mask
static void vlib_trace_buffer(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, vlib_buffer_t *b, int follow_chain)
vnet_main_t * vnet_get_main(void)
i16 current_data
signed offset in data[], pre_data[] that we are currently processing.
#define static_always_inline
void(* buffer_init_function)(struct vlib_main_t *vm, struct vlib_buffer_free_list_t *fl, u32 *buffers, u32 n_buffers)
#define vlib_prefetch_buffer_with_index(vm, bi, type)
Prefetch buffer metadata by buffer index The first 64 bytes of buffer contains most header informatio...
u32 local_interface_sw_if_index
static uword pow2_mask(uword x)
vlib_combined_counter_main_t * combined_sw_if_counters
static uword clib_fifo_free_elts(void *v)
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
#define clib_warning(format, args...)
#define vec_end(v)
End (last data address) of vector.
static void vlib_copy_buffers(u32 *dst, u32 *src, u32 n)
#define VLIB_BUFFER_NEXT_PRESENT
u32 last_increment_packet_size
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
u16 current_length
Nbytes between current data and the end of this buffer.
u32 current_replay_packet_index
static u64 pg_edit_get_value(pg_edit_t *e, int hi_or_lo)
uword os_get_cpu_number(void)
#define PG_STREAM_FLAGS_DISABLE_BUFFER_RECYCLE
format_function_t * format_buffer
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
#define clib_fifo_foreach(v, f, body)
#define CLIB_PREFETCH(addr, size, type)
#define clib_memcpy(a, b, c)
static uword max_pow2(uword x)
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
pg_edit_t * non_fixed_edits
u8 ** replay_packet_templates
static uword clib_fifo_advance_head(void *v, uword n_elts)
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 cpu_index, u32 index, u32 packet_increment, u32 byte_increment)
Increment a combined counter.
u32 next_buffer
Next buffer for this linked-list of buffers.
void pg_stream_enable_disable(pg_main_t *pg, pg_stream_t *s, int is_enable)
static uword vlib_buffer_index_length_in_chain(vlib_main_t *vm, u32 bi)
Get length in bytes of the buffer index buffer chain.
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
#define vec_elt(v, i)
Get vector value at index i.
u32 sw_if_index[VLIB_N_RX_TX]
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
#define clib_mem_unaligned(pointer, type)
f64 rate_packets_per_second
#define VLIB_REGISTER_NODE(x,...)
#define STRUCT_SIZE_OF(t, f)
static vlib_node_t * vlib_get_node(vlib_main_t *vm, u32 i)
Get vlib node by index.
#define vec_foreach(var, vec)
Vector iterator.
uword buffer_init_function_opaque
static vlib_buffer_free_list_t * vlib_buffer_get_free_list(vlib_main_t *vm, u32 free_list_index)
void vlib_buffer_free_no_next(vlib_main_t *vm, u32 *buffers, u32 n_buffers)
Free buffers, does not free the buffer chain for each buffer.
static void vlib_set_trace_count(vlib_main_t *vm, vlib_node_runtime_t *rt, u32 count)
u32 flags
buffer flags: VLIB_BUFFER_IS_TRACED: trace this buffer.
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
clib_random_buffer_t random_buffer