diff options
Diffstat (limited to 'vnet')
-rw-r--r-- | vnet/vnet/pg/cli.c | 221 | ||||
-rw-r--r-- | vnet/vnet/pg/edit.c | 46 | ||||
-rw-r--r-- | vnet/vnet/pg/edit.h | 22 | ||||
-rw-r--r-- | vnet/vnet/pg/init.c | 17 | ||||
-rw-r--r-- | vnet/vnet/pg/input.c | 630 | ||||
-rw-r--r-- | vnet/vnet/pg/output.c | 23 | ||||
-rw-r--r-- | vnet/vnet/pg/pg.h | 147 | ||||
-rw-r--r-- | vnet/vnet/pg/stream.c | 219 |
8 files changed, 682 insertions, 643 deletions
diff --git a/vnet/vnet/pg/cli.c b/vnet/vnet/pg/cli.c index 96c20b70144..e6bd11e09ce 100644 --- a/vnet/vnet/pg/cli.c +++ b/vnet/vnet/pg/cli.c @@ -47,63 +47,69 @@ #endif /* Root of all packet generator cli commands. */ +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (vlib_cli_pg_command, static) = { .path = "packet-generator", .short_help = "Packet generator commands", }; +/* *INDENT-ON* */ -void pg_enable_disable (u32 stream_index, int is_enable) +void +pg_enable_disable (u32 stream_index, int is_enable) { - pg_main_t * pg = &pg_main; - pg_stream_t * s; + pg_main_t *pg = &pg_main; + pg_stream_t *s; - if (stream_index == ~0) { - /* No stream specified: enable/disable all streams. */ + if (stream_index == ~0) + { + /* No stream specified: enable/disable all streams. */ + /* *INDENT-OFF* */ pool_foreach (s, pg->streams, ({ pg_stream_enable_disable (pg, s, is_enable); })); + /* *INDENT-ON* */ } - else + else { - /* enable/disable specified stream. */ - s = pool_elt_at_index (pg->streams, stream_index); - pg_stream_enable_disable (pg, s, is_enable); + /* enable/disable specified stream. */ + s = pool_elt_at_index (pg->streams, stream_index); + pg_stream_enable_disable (pg, s, is_enable); } } -clib_error_t * pg_capture (pg_capture_args_t *a) +clib_error_t * +pg_capture (pg_capture_args_t * a) { - pg_main_t * pg = &pg_main; - pg_interface_t * pi; + pg_main_t *pg = &pg_main; + pg_interface_t *pi; - if (a->is_enabled == 1) + if (a->is_enabled == 1) { - struct stat sb; - if (stat ((char *) a->pcap_file_name, &sb) != -1) - return clib_error_return (0, "Cannot create pcap file"); + struct stat sb; + if (stat ((char *) a->pcap_file_name, &sb) != -1) + return clib_error_return (0, "Cannot create pcap file"); } - pi = pool_elt_at_index (pg->interfaces, a->dev_instance); - vec_free (pi->pcap_file_name); - memset (&pi->pcap_main, 0, sizeof (pi->pcap_main)); + pi = pool_elt_at_index (pg->interfaces, a->dev_instance); + vec_free (pi->pcap_file_name); + memset (&pi->pcap_main, 0, sizeof (pi->pcap_main)); - if (a->is_enabled == 0) - return 0; + if (a->is_enabled == 0) + return 0; - pi->pcap_file_name = a->pcap_file_name; - pi->pcap_main.file_name = (char *) pi->pcap_file_name; - pi->pcap_main.n_packets_to_capture = a->count; - pi->pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet; + pi->pcap_file_name = a->pcap_file_name; + pi->pcap_main.file_name = (char *) pi->pcap_file_name; + pi->pcap_main.n_packets_to_capture = a->count; + pi->pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet; - return 0; + return 0; } static clib_error_t * enable_disable_stream (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) + unformat_input_t * input, vlib_cli_command_t * cmd) { - pg_main_t * pg = &pg_main; + pg_main_t *pg = &pg_main; int is_enable = cmd->function_arg != 0; u32 stream_index = ~0; @@ -121,26 +127,31 @@ enable_disable_stream (vlib_main_t * vm, return 0; } +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (enable_streams_cli, static) = { .path = "packet-generator enable-stream", .short_help = "Enable packet generator streams", .function = enable_disable_stream, .function_arg = 1, /* is_enable */ }; +/* *INDENT-ON* */ +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (disable_streams_cli, static) = { .path = "packet-generator disable-stream", .short_help = "Disable packet generator streams", .function = enable_disable_stream, .function_arg = 0, /* is_enable */ }; +/* *INDENT-ON* */ -static u8 * format_pg_stream (u8 * s, va_list * va) +static u8 * +format_pg_stream (u8 * s, va_list * va) { - pg_stream_t * t = va_arg (*va, pg_stream_t *); - u8 * v; + pg_stream_t *t = va_arg (*va, pg_stream_t *); + u8 *v; - if (! t) + if (!t) return format (s, "%=16s%=12s%=16s%s", "Name", "Enabled", "Count", "Parameters"); @@ -173,11 +184,10 @@ static u8 * format_pg_stream (u8 * s, va_list * va) static clib_error_t * show_streams (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) + unformat_input_t * input, vlib_cli_command_t * cmd) { - pg_main_t * pg = &pg_main; - pg_stream_t * s; + pg_main_t *pg = &pg_main; + pg_stream_t *s; if (pool_elts (pg->streams) == 0) { @@ -186,28 +196,32 @@ show_streams (vlib_main_t * vm, } vlib_cli_output (vm, "%U", format_pg_stream, 0); + /* *INDENT-OFF* */ pool_foreach (s, pg->streams, ({ vlib_cli_output (vm, "%U", format_pg_stream, s); })); + /* *INDENT-ON* */ - done: +done: return 0; } +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (show_streams_cli, static) = { .path = "show packet-generator", .short_help = "Show packet generator streams", .function = show_streams, }; +/* *INDENT-ON* */ static clib_error_t * -pg_pcap_read (pg_stream_t * s, char * file_name) +pg_pcap_read (pg_stream_t * s, char *file_name) { #ifndef CLIB_UNIX return clib_error_return (0, "no pcap support"); #else pcap_main_t pm; - clib_error_t * error; + clib_error_t *error; memset (&pm, 0, sizeof (pm)); pm.file_name = file_name; error = pcap_read (&pm); @@ -228,7 +242,7 @@ pg_pcap_read (pg_stream_t * s, char * file_name) static uword unformat_pg_stream_parameter (unformat_input_t * input, va_list * args) { - pg_stream_t * s = va_arg (*args, pg_stream_t *); + pg_stream_t *s = va_arg (*args, pg_stream_t *); f64 x; if (unformat (input, "limit %f", &x)) @@ -261,8 +275,9 @@ validate_stream (pg_stream_t * s) return clib_error_create ("max-size < min-size"); if (s->buffer_bytes >= 4096 || s->buffer_bytes == 0) - return clib_error_create ("buffer-size must be positive and < 4096, given %d", - s->buffer_bytes); + return + clib_error_create ("buffer-size must be positive and < 4096, given %d", + s->buffer_bytes); if (s->rate_packets_per_second < 0) return clib_error_create ("negative rate"); @@ -272,19 +287,18 @@ validate_stream (pg_stream_t * s) static clib_error_t * new_stream (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) + unformat_input_t * input, vlib_cli_command_t * cmd) { - clib_error_t * error = 0; - u8 * tmp = 0; + clib_error_t *error = 0; + u8 *tmp = 0; u32 hw_if_index; - unformat_input_t sub_input = {0}; + unformat_input_t sub_input = { 0 }; int sub_input_given = 0; - vnet_main_t * vnm = vnet_get_main(); - pg_main_t * pg = &pg_main; - pg_stream_t s = {0}; - char * pcap_file_name; - + vnet_main_t *vnm = vnet_get_main (); + pg_main_t *pg = &pg_main; + pg_stream_t s = { 0 }; + char *pcap_file_name; + s.sw_if_index[VLIB_RX] = s.sw_if_index[VLIB_TX] = ~0; s.node_index = ~0; s.max_packet_bytes = s.min_packet_bytes = 64; @@ -303,30 +317,31 @@ new_stream (vlib_main_t * vm, else if (unformat (input, "node %U", unformat_vnet_hw_interface, vnm, &hw_if_index)) { - vnet_hw_interface_t * hi = vnet_get_hw_interface (vnm, hw_if_index); + vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); s.node_index = hi->output_node_index; s.sw_if_index[VLIB_TX] = hi->sw_if_index; } - else if (unformat (input, "source pg%u",&s.if_id)) + else if (unformat (input, "source pg%u", &s.if_id)) ; else if (unformat (input, "node %U", unformat_vlib_node, vm, &s.node_index)) ; - + else if (unformat (input, "interface %U", - unformat_vnet_sw_interface, vnm, &s.sw_if_index[VLIB_RX])) + unformat_vnet_sw_interface, vnm, + &s.sw_if_index[VLIB_RX])) ; else if (unformat (input, "pcap %s", &pcap_file_name)) ; - else if (! sub_input_given + else if (!sub_input_given && unformat (input, "data %U", unformat_input, &sub_input)) sub_input_given++; - + else if (unformat_user (input, unformat_pg_stream_parameter, &s)) ; @@ -345,7 +360,7 @@ new_stream (vlib_main_t * vm, if (error) return error; - if (! sub_input_given && ! pcap_file_name) + if (!sub_input_given && !pcap_file_name) { error = clib_error_create ("no packet data given"); goto done; @@ -355,7 +370,8 @@ new_stream (vlib_main_t * vm, { if (pcap_file_name != 0) { - vlib_node_t * n = vlib_get_node_by_name(vm, (u8 *) "ethernet-input"); + vlib_node_t *n = + vlib_get_node_by_name (vm, (u8 *) "ethernet-input"); s.node_index = n->index; } else @@ -366,7 +382,7 @@ new_stream (vlib_main_t * vm, } { - pg_node_t * n; + pg_node_t *n; if (s.node_index < vec_len (pg->nodes)) n = pg->nodes + s.node_index; @@ -382,10 +398,10 @@ new_stream (vlib_main_t * vm, } else if (n && n->unformat_edit - && unformat_user (&sub_input, n->unformat_edit, &s)) + && unformat_user (&sub_input, n->unformat_edit, &s)) ; - else if (! unformat_user (&sub_input, unformat_pg_payload, &s)) + else if (!unformat_user (&sub_input, unformat_pg_payload, &s)) { error = clib_error_create ("failed to parse packet data from `%U'", @@ -397,12 +413,13 @@ new_stream (vlib_main_t * vm, pg_stream_add (pg, &s); return 0; - done: +done: pg_stream_free (&s); unformat_free (&sub_input); return error; } +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (new_stream_cli, static) = { .path = "packet-generator new", .function = new_stream, @@ -418,17 +435,17 @@ VLIB_CLI_COMMAND (new_stream_cli, static) = { "data STRING specifies packet data\n" "pcap FILENAME read packet data from pcap file\n", }; +/* *INDENT-ON* */ static clib_error_t * del_stream (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) + unformat_input_t * input, vlib_cli_command_t * cmd) { - pg_main_t * pg = &pg_main; + pg_main_t *pg = &pg_main; u32 i; - - if (! unformat (input, "%U", - &unformat_hash_vec_string, pg->stream_index_by_name, &i)) + + if (!unformat (input, "%U", + &unformat_hash_vec_string, pg->stream_index_by_name, &i)) return clib_error_create ("expected stream name `%U'", format_unformat_error, input); @@ -436,21 +453,22 @@ del_stream (vlib_main_t * vm, return 0; } +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (del_stream_cli, static) = { .path = "packet-generator delete", .function = del_stream, .short_help = "Delete stream with given name", }; +/* *INDENT-ON* */ static clib_error_t * change_stream_parameters (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) + unformat_input_t * input, vlib_cli_command_t * cmd) { - pg_main_t * pg = &pg_main; - pg_stream_t * s, s_new; + pg_main_t *pg = &pg_main; + pg_stream_t *s, s_new; u32 stream_index = ~0; - clib_error_t * error; + clib_error_t *error; if (unformat (input, "%U", unformat_hash_vec_string, pg->stream_index_by_name, &stream_index)) @@ -473,39 +491,40 @@ change_stream_parameters (vlib_main_t * vm, } error = validate_stream (&s_new); - if (! error) + if (!error) s[0] = s_new; return error; } +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (change_stream_parameters_cli, static) = { .path = "packet-generator configure", .short_help = "Change packet generator stream parameters", .function = change_stream_parameters, }; +/* *INDENT-ON* */ static clib_error_t * pg_capture_cmd_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) + unformat_input_t * input, vlib_cli_command_t * cmd) { - clib_error_t * error = 0; - vnet_main_t * vnm = vnet_get_main(); - unformat_input_t _line_input, * line_input = &_line_input; - vnet_hw_interface_t * hi = 0; - u8 * pcap_file_name = 0; + clib_error_t *error = 0; + vnet_main_t *vnm = vnet_get_main (); + unformat_input_t _line_input, *line_input = &_line_input; + vnet_hw_interface_t *hi = 0; + u8 *pcap_file_name = 0; u32 hw_if_index; u32 is_disable = 0; u32 count = ~0; - if (! unformat_user (input, unformat_line_input, line_input)) + if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) { if (unformat (line_input, "%U", - unformat_vnet_hw_interface, vnm, &hw_if_index)) + unformat_vnet_hw_interface, vnm, &hw_if_index)) { hi = vnet_get_hw_interface (vnm, hw_if_index); } @@ -536,7 +555,7 @@ pg_capture_cmd_fn (vlib_main_t * vm, unformat_free (line_input); - pg_capture_args_t _a, *a=&_a; + pg_capture_args_t _a, *a = &_a; a->hw_if_index = hw_if_index; a->dev_instance = hi->dev_instance; @@ -548,22 +567,23 @@ pg_capture_cmd_fn (vlib_main_t * vm, return error; } +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (pg_capture_cmd, static) = { .path = "packet-generator capture", .short_help = "packet-generator capture <interface name> pcap <filename> [count <n>]", .function = pg_capture_cmd_fn, }; +/* *INDENT-ON* */ static clib_error_t * create_pg_if_cmd_fn (vlib_main_t * vm, - unformat_input_t * input, - vlib_cli_command_t * cmd) + unformat_input_t * input, vlib_cli_command_t * cmd) { - pg_main_t * pg = &pg_main; - unformat_input_t _line_input, * line_input = &_line_input; + pg_main_t *pg = &pg_main; + unformat_input_t _line_input, *line_input = &_line_input; u32 if_id; - if (! unformat_user (input, unformat_line_input, line_input)) + if (!unformat_user (input, unformat_line_input, line_input)) return 0; while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) @@ -582,14 +602,27 @@ create_pg_if_cmd_fn (vlib_main_t * vm, return 0; } +/* *INDENT-OFF* */ VLIB_CLI_COMMAND (create_pg_if_cmd, static) = { .path = "create packet-generator", .short_help = "create packet-generator interface <interface name>", .function = create_pg_if_cmd_fn, }; +/* *INDENT-ON* */ /* Dummy init function so that we can be linked in. */ -static clib_error_t * pg_cli_init (vlib_main_t * vm) -{ return 0; } +static clib_error_t * +pg_cli_init (vlib_main_t * vm) +{ + return 0; +} VLIB_INIT_FUNCTION (pg_cli_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/pg/edit.c b/vnet/vnet/pg/edit.c index 9c49cef8903..c6fc3fd124e 100644 --- a/vnet/vnet/pg/edit.c +++ b/vnet/vnet/pg/edit.c @@ -44,7 +44,7 @@ static void pg_edit_set_value_helper (pg_edit_t * e, u64 value, u8 * result) { int i, j, n_bits_left; - u8 * v, tmp[8]; + u8 *v, tmp[8]; v = tmp; @@ -81,21 +81,21 @@ pg_edit_set_value (pg_edit_t * e, int hi_or_lo, u64 value) } /* Parse an int either %d or 0x%x into network byte order. */ -uword unformat_pg_number (unformat_input_t * input, va_list * args) +uword +unformat_pg_number (unformat_input_t * input, va_list * args) { - u8 * result = va_arg (*args, u8 *); - pg_edit_t * e = va_arg (*args, pg_edit_t *); + u8 *result = va_arg (*args, u8 *); + pg_edit_t *e = va_arg (*args, pg_edit_t *); u64 value; ASSERT (BITS (value) >= e->n_bits); - if (! unformat (input, "0x%X", sizeof (value), &value) - && ! unformat (input, "%D", sizeof (value), &value)) + if (!unformat (input, "0x%X", sizeof (value), &value) + && !unformat (input, "%D", sizeof (value), &value)) return 0; /* Number given does not fit into bit field. */ - if (e->n_bits < 64 - && value >= (u64) 1 << (u64) e->n_bits) + if (e->n_bits < 64 && value >= (u64) 1 << (u64) e->n_bits) return 0; pg_edit_set_value_helper (e, value, result); @@ -105,11 +105,11 @@ uword unformat_pg_number (unformat_input_t * input, va_list * args) uword unformat_pg_edit (unformat_input_t * input, va_list * args) { - unformat_function_t * f = va_arg (*args, unformat_function_t *); - pg_edit_t * e = va_arg (*args, pg_edit_t *); + unformat_function_t *f = va_arg (*args, unformat_function_t *); + pg_edit_t *e = va_arg (*args, pg_edit_t *); pg_edit_alloc_value (e, PG_EDIT_LO); - if (! unformat_user (input, f, e->values[PG_EDIT_LO], e)) + if (!unformat_user (input, f, e->values[PG_EDIT_LO], e)) return 0; pg_edit_alloc_value (e, PG_EDIT_HI); @@ -126,13 +126,13 @@ unformat_pg_edit (unformat_input_t * input, va_list * args) uword unformat_pg_payload (unformat_input_t * input, va_list * args) { - pg_stream_t * s = va_arg (*args, pg_stream_t *); - pg_main_t * pg = &pg_main; - vlib_main_t * vm = pg->vlib_main; - pg_edit_t * e; + pg_stream_t *s = va_arg (*args, pg_stream_t *); + pg_main_t *pg = &pg_main; + vlib_main_t *vm = pg->vlib_main; + pg_edit_t *e; u32 i, node_index, len, max_len; - u8 * v; - + u8 *v; + v = 0; if (unformat (input, "incrementing %d", &len)) @@ -146,8 +146,8 @@ unformat_pg_payload (unformat_input_t * input, va_list * args) else if (unformat (input, "%U", unformat_vlib_node, vm, &node_index)) { - pg_node_t * pn = pg_get_node (node_index); - if (! pn->unformat_edit) + pg_node_t *pn = pg_get_node (node_index); + if (!pn->unformat_edit) return 0; return unformat (input, "%U", pn->unformat_edit, s); } @@ -177,3 +177,11 @@ unformat_pg_payload (unformat_input_t * input, va_list * args) return 1; } + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/pg/edit.h b/vnet/vnet/pg/edit.h index 07c14a2a203..3bfdad575f5 100644 --- a/vnet/vnet/pg/edit.h +++ b/vnet/vnet/pg/edit.h @@ -43,7 +43,8 @@ #include <vppinfra/format.h> #include <vppinfra/vec.h> -typedef enum { +typedef enum +{ /* Invalid type used to poison edits. */ PG_EDIT_INVALID_TYPE, @@ -60,7 +61,8 @@ typedef enum { PG_EDIT_UNSPECIFIED, } pg_edit_type_t; -typedef struct { +typedef struct +{ pg_edit_type_t type; /* Bit offset within packet where value is to be written. @@ -77,7 +79,7 @@ typedef struct { u32 n_bits; /* Low and high values for this edit. Network byte order. */ - u8 * values[2]; + u8 *values[2]; #define PG_EDIT_LO 0 #define PG_EDIT_HI 1 @@ -141,7 +143,9 @@ pg_edit_n_alloc_bytes (pg_edit_t * e) static inline void pg_edit_alloc_value (pg_edit_t * e, int i) -{ vec_validate (e->values[i], e->lsb_bit_offset / BITS (u8)); } +{ + vec_validate (e->values[i], e->lsb_bit_offset / BITS (u8)); +} extern void pg_edit_set_value (pg_edit_t * e, int hi_or_lo, u64 value); @@ -170,7 +174,7 @@ pg_edit_get_value (pg_edit_t * e, int hi_or_lo) { u64 r = 0; int i, n; - u8 * v = e->values[hi_or_lo]; + u8 *v = e->values[hi_or_lo]; n = round_pow2 (e->n_bits, BITS (u8)) / BITS (u8); @@ -196,3 +200,11 @@ uword unformat_pg_number (unformat_input_t * input, va_list * args); uword unformat_pg_interface (unformat_input_t * input, va_list * args); #endif /* included_packet_generator_pg_edit_h */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/pg/init.c b/vnet/vnet/pg/init.c index 5cbb6db09b2..d939a31e1d0 100644 --- a/vnet/vnet/pg/init.c +++ b/vnet/vnet/pg/init.c @@ -43,10 +43,11 @@ /* Global main structure. */ pg_main_t pg_main; -static clib_error_t * pg_init (vlib_main_t * vm) +static clib_error_t * +pg_init (vlib_main_t * vm) { - clib_error_t * error; - pg_main_t * pg = &pg_main; + clib_error_t *error; + pg_main_t *pg = &pg_main; pg->vlib_main = vm; pg->if_index_by_if_id = hash_create (0, sizeof (uword)); @@ -57,8 +58,16 @@ static clib_error_t * pg_init (vlib_main_t * vm) if ((error = vlib_call_init_function (vm, pg_cli_init))) goto done; - done: +done: return error; } VLIB_INIT_FUNCTION (pg_init); + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/pg/input.c b/vnet/vnet/pg/input.c index e3bd9f2631a..c3a54ad6e44 100644 --- a/vnet/vnet/pg/input.c +++ b/vnet/vnet/pg/input.c @@ -45,13 +45,13 @@ #include <vnet/devices/dpdk/dpdk.h> #endif -static inline void +static inline void pg_set_mbuf_metadata (pg_main_t * pg, u32 * buffers, u32 n_alloc) { #if DPDK == 1 - vlib_main_t * vm = vlib_get_main(); - vlib_buffer_t * b; - struct rte_mbuf * mb; + vlib_main_t *vm = vlib_get_main (); + vlib_buffer_t *b; + struct rte_mbuf *mb; i16 delta; u16 new_data_len; u16 new_pkt_len; @@ -61,24 +61,24 @@ pg_set_mbuf_metadata (pg_main_t * pg, u32 * buffers, u32 n_alloc) for (i = 0; i < n_alloc; i++) { b = vlib_get_buffer (vm, buffers[i]); - mb = rte_mbuf_from_vlib_buffer(b); + mb = rte_mbuf_from_vlib_buffer (b); delta = vlib_buffer_length_in_chain (vm, b) - (i16) mb->pkt_len; - new_data_len = (u16)((i16) mb->data_len + delta); - new_pkt_len = (u16)((i16) mb->pkt_len + delta); + new_data_len = (u16) ((i16) mb->data_len + delta); + new_pkt_len = (u16) ((i16) mb->pkt_len + delta); mb->data_len = new_data_len; mb->pkt_len = new_pkt_len; - mb->data_off = (u16)((RTE_PKTMBUF_HEADROOM) + b->current_data); + mb->data_off = (u16) ((RTE_PKTMBUF_HEADROOM) + b->current_data); } -#endif +#endif } static int validate_buffer_data2 (vlib_buffer_t * b, pg_stream_t * s, u32 data_offset, u32 n_bytes) { - u8 * bd, * pd, * pm; + u8 *bd, *pd, *pm; u32 i; bd = b->data; @@ -87,8 +87,7 @@ validate_buffer_data2 (vlib_buffer_t * b, pg_stream_t * s, if (pd + n_bytes >= vec_end (s->fixed_packet_data)) n_bytes = (pd < vec_end (s->fixed_packet_data) - ? vec_end (s->fixed_packet_data) - pd - : 0); + ? vec_end (s->fixed_packet_data) - pd : 0); for (i = 0; i < n_bytes; i++) if ((bd[i] & pm[i]) != pd[i]) @@ -107,14 +106,13 @@ validate_buffer_data2 (vlib_buffer_t * b, pg_stream_t * s, static int validate_buffer_data (vlib_buffer_t * b, pg_stream_t * s) -{ return validate_buffer_data2 (b, s, 0, s->buffer_bytes); } +{ + return validate_buffer_data2 (b, s, 0, s->buffer_bytes); +} always_inline void -set_1 (void * a0, - u64 v0, - u64 v_min, u64 v_max, - u32 n_bits, - u32 is_net_byte_order) +set_1 (void *a0, + u64 v0, u64 v_min, u64 v_max, u32 n_bits, u32 is_net_byte_order) { ASSERT (v0 >= v_min && v0 <= v_max); if (n_bits == BITS (u8)) @@ -142,12 +140,10 @@ set_1 (void * a0, } always_inline void -set_2 (void * a0, void * a1, +set_2 (void *a0, void *a1, u64 v0, u64 v1, u64 v_min, u64 v_max, - u32 n_bits, - u32 is_net_byte_order, - u32 is_increment) + u32 n_bits, u32 is_net_byte_order, u32 is_increment) { ASSERT (v0 >= v_min && v0 <= v_max); ASSERT (v1 >= v_min && v1 <= (v_max + is_increment)); @@ -194,17 +190,14 @@ do_set_fixed (pg_main_t * pg, u32 * buffers, u32 n_buffers, u32 n_bits, - u32 byte_offset, - u32 is_net_byte_order, - u64 v_min, u64 v_max) - + u32 byte_offset, u32 is_net_byte_order, u64 v_min, u64 v_max) { - vlib_main_t * vm = pg->vlib_main; + vlib_main_t *vm = pg->vlib_main; while (n_buffers >= 4) { - vlib_buffer_t * b0, * b1, * b2, * b3; - void * a0, * a1; + vlib_buffer_t *b0, *b1, *b2, *b3; + void *a0, *a1; b0 = vlib_get_buffer (vm, buffers[0]); b1 = vlib_get_buffer (vm, buffers[1]); @@ -218,9 +211,7 @@ do_set_fixed (pg_main_t * pg, CLIB_PREFETCH ((void *) b2 + byte_offset, sizeof (v_min), WRITE); CLIB_PREFETCH ((void *) b3 + byte_offset, sizeof (v_min), WRITE); - set_2 (a0, a1, v_min, v_min, - v_min, v_max, - n_bits, is_net_byte_order, + set_2 (a0, a1, v_min, v_min, v_min, v_max, n_bits, is_net_byte_order, /* is_increment */ 0); ASSERT (validate_buffer_data (b0, s)); @@ -229,8 +220,8 @@ do_set_fixed (pg_main_t * pg, while (n_buffers > 0) { - vlib_buffer_t * b0; - void * a0; + vlib_buffer_t *b0; + void *a0; b0 = vlib_get_buffer (vm, buffers[0]); buffers += 1; @@ -238,9 +229,7 @@ do_set_fixed (pg_main_t * pg, a0 = (void *) b0 + byte_offset; - set_1 (a0, v_min, - v_min, v_max, - n_bits, is_net_byte_order); + set_1 (a0, v_min, v_min, v_max, n_bits, is_net_byte_order); ASSERT (validate_buffer_data (b0, s)); } @@ -254,20 +243,17 @@ do_set_increment (pg_main_t * pg, u32 n_bits, u32 byte_offset, u32 is_net_byte_order, - u32 want_sum, - u64 * sum_result, - u64 v_min, u64 v_max, - u64 v) + u32 want_sum, u64 * sum_result, u64 v_min, u64 v_max, u64 v) { - vlib_main_t * vm = pg->vlib_main; + vlib_main_t *vm = pg->vlib_main; u64 sum = 0; ASSERT (v >= v_min && v <= v_max); while (n_buffers >= 4) { - vlib_buffer_t * b0, * b1, * b2, * b3; - void * a0, * a1; + vlib_buffer_t *b0, *b1, *b2, *b3; + void *a0, *a1; u64 v_old; b0 = vlib_get_buffer (vm, buffers[0]); @@ -286,18 +272,16 @@ do_set_increment (pg_main_t * pg, v = v_old + 2; v = v > v_max ? v_min : v; set_2 (a0, a1, - v_old + 0, v_old + 1, - v_min, v_max, - n_bits, is_net_byte_order, + v_old + 0, v_old + 1, v_min, v_max, n_bits, is_net_byte_order, /* is_increment */ 1); if (want_sum) - sum += 2*v_old + 1; + sum += 2 * v_old + 1; if (PREDICT_FALSE (v_old + 1 > v_max)) { if (want_sum) - sum -= 2*v_old + 1; + sum -= 2 * v_old + 1; v = v_old; set_1 (a0, v + 0, v_min, v_max, n_bits, is_net_byte_order); @@ -318,8 +302,8 @@ do_set_increment (pg_main_t * pg, while (n_buffers > 0) { - vlib_buffer_t * b0; - void * a0; + vlib_buffer_t *b0; + void *a0; u64 v_old; b0 = vlib_get_buffer (vm, buffers[0]); @@ -354,17 +338,14 @@ do_set_random (pg_main_t * pg, u32 n_bits, u32 byte_offset, u32 is_net_byte_order, - u32 want_sum, - u64 * sum_result, - u64 v_min, u64 v_max) - + u32 want_sum, u64 * sum_result, u64 v_min, u64 v_max) { - vlib_main_t * vm = pg->vlib_main; + vlib_main_t *vm = pg->vlib_main; u64 v_diff = v_max - v_min + 1; u64 r_mask = max_pow2 (v_diff) - 1; u64 v0, v1; u64 sum = 0; - void * random_data; + void *random_data; random_data = clib_random_buffer_get_data (&vm->random_buffer, n_buffers * n_bits / BITS (u8)); @@ -373,9 +354,9 @@ do_set_random (pg_main_t * pg, while (n_buffers >= 4) { - vlib_buffer_t * b0, * b1, * b2, * b3; - void * a0, * a1; - u64 r0=0, r1=0; /* warnings be gone */ + vlib_buffer_t *b0, *b1, *b2, *b3; + void *a0, *a1; + u64 r0 = 0, r1 = 0; /* warnings be gone */ b0 = vlib_get_buffer (vm, buffers[0]); b1 = vlib_get_buffer (vm, buffers[1]); @@ -401,10 +382,10 @@ do_set_random (pg_main_t * pg, } \ break; - _ (8); - _ (16); - _ (32); - _ (64); + _(8); + _(16); + _(32); + _(64); #undef _ } @@ -422,10 +403,7 @@ do_set_random (pg_main_t * pg, if (want_sum) sum += v0 + v1; - set_2 (a0, a1, - v0, v1, - v_min, v_max, - n_bits, is_net_byte_order, + set_2 (a0, a1, v0, v1, v_min, v_max, n_bits, is_net_byte_order, /* is_increment */ 0); ASSERT (validate_buffer_data (b0, s)); @@ -434,9 +412,9 @@ do_set_random (pg_main_t * pg, while (n_buffers > 0) { - vlib_buffer_t * b0; - void * a0; - u64 r0 = 0; /* warnings be gone */ + vlib_buffer_t *b0; + void *a0; + u64 r0 = 0; /* warnings be gone */ b0 = vlib_get_buffer (vm, buffers[0]); buffers += 1; @@ -455,10 +433,10 @@ do_set_random (pg_main_t * pg, } \ break; - _ (8); - _ (16); - _ (32); - _ (64); + _(8); + _(16); + _(32); + _(64); #undef _ } @@ -486,66 +464,59 @@ do_set_random (pg_main_t * pg, clib_mem_unaligned (a##i, t) = \ clib_host_to_net_##t ((clib_net_to_host_mem_##t (a##i) &~ mask) \ | (v##i << shift)) - + always_inline void -setbits_1 (void * a0, +setbits_1 (void *a0, u64 v0, u64 v_min, u64 v_max, - u32 max_bits, - u32 n_bits, - u64 mask, - u32 shift) + u32 max_bits, u32 n_bits, u64 mask, u32 shift) { ASSERT (v0 >= v_min && v0 <= v_max); if (max_bits == BITS (u8)) - ((u8 *) a0)[0] = (((u8 *) a0)[0] &~ mask) | (v0 << shift); + ((u8 *) a0)[0] = (((u8 *) a0)[0] & ~mask) | (v0 << shift); else if (max_bits == BITS (u16)) { - _ (0, u16); + _(0, u16); } else if (max_bits == BITS (u32)) { - _ (0, u32); + _(0, u32); } else if (max_bits == BITS (u64)) { - _ (0, u64); + _(0, u64); } } always_inline void -setbits_2 (void * a0, void * a1, +setbits_2 (void *a0, void *a1, u64 v0, u64 v1, u64 v_min, u64 v_max, - u32 max_bits, - u32 n_bits, - u64 mask, - u32 shift, - u32 is_increment) + u32 max_bits, u32 n_bits, u64 mask, u32 shift, u32 is_increment) { ASSERT (v0 >= v_min && v0 <= v_max); ASSERT (v1 >= v_min && v1 <= v_max + is_increment); if (max_bits == BITS (u8)) { - ((u8 *) a0)[0] = (((u8 *) a0)[0] &~ mask) | (v0 << shift); - ((u8 *) a1)[0] = (((u8 *) a1)[0] &~ mask) | (v1 << shift); + ((u8 *) a0)[0] = (((u8 *) a0)[0] & ~mask) | (v0 << shift); + ((u8 *) a1)[0] = (((u8 *) a1)[0] & ~mask) | (v1 << shift); } else if (max_bits == BITS (u16)) { - _ (0, u16); - _ (1, u16); + _(0, u16); + _(1, u16); } else if (max_bits == BITS (u32)) { - _ (0, u32); - _ (1, u32); + _(0, u32); + _(1, u32); } else if (max_bits == BITS (u64)) { - _ (0, u64); - _ (1, u64); + _(0, u64); + _(1, u64); } } @@ -558,18 +529,14 @@ do_setbits_fixed (pg_main_t * pg, u32 n_buffers, u32 max_bits, u32 n_bits, - u32 byte_offset, - u64 v_min, u64 v_max, - u64 mask, - u32 shift) - + u32 byte_offset, u64 v_min, u64 v_max, u64 mask, u32 shift) { - vlib_main_t * vm = pg->vlib_main; + vlib_main_t *vm = pg->vlib_main; while (n_buffers >= 4) { - vlib_buffer_t * b0, * b1, * b2, * b3; - void * a0, * a1; + vlib_buffer_t *b0, *b1, *b2, *b3; + void *a0, *a1; b0 = vlib_get_buffer (vm, buffers[0]); b1 = vlib_get_buffer (vm, buffers[1]); @@ -584,9 +551,7 @@ do_setbits_fixed (pg_main_t * pg, CLIB_PREFETCH ((void *) b3 + byte_offset, sizeof (v_min), WRITE); setbits_2 (a0, a1, - v_min, v_min, - v_min, v_max, - max_bits, n_bits, mask, shift, + v_min, v_min, v_min, v_max, max_bits, n_bits, mask, shift, /* is_increment */ 0); ASSERT (validate_buffer_data (b0, s)); @@ -595,8 +560,8 @@ do_setbits_fixed (pg_main_t * pg, while (n_buffers > 0) { - vlib_buffer_t * b0; - void * a0; + vlib_buffer_t *b0; + void *a0; b0 = vlib_get_buffer (vm, buffers[0]); buffers += 1; @@ -617,19 +582,16 @@ do_setbits_increment (pg_main_t * pg, u32 max_bits, u32 n_bits, u32 byte_offset, - u64 v_min, u64 v_max, - u64 v, - u64 mask, - u32 shift) + u64 v_min, u64 v_max, u64 v, u64 mask, u32 shift) { - vlib_main_t * vm = pg->vlib_main; + vlib_main_t *vm = pg->vlib_main; ASSERT (v >= v_min && v <= v_max); while (n_buffers >= 4) { - vlib_buffer_t * b0, * b1, * b2, * b3; - void * a0, * a1; + vlib_buffer_t *b0, *b1, *b2, *b3; + void *a0, *a1; u64 v_old; b0 = vlib_get_buffer (vm, buffers[0]); @@ -649,8 +611,7 @@ do_setbits_increment (pg_main_t * pg, v = v > v_max ? v_min : v; setbits_2 (a0, a1, v_old + 0, v_old + 1, - v_min, v_max, - max_bits, n_bits, mask, shift, + v_min, v_max, max_bits, n_bits, mask, shift, /* is_increment */ 1); if (PREDICT_FALSE (v_old + 1 > v_max)) @@ -669,8 +630,8 @@ do_setbits_increment (pg_main_t * pg, while (n_buffers > 0) { - vlib_buffer_t * b0; - void * a0; + vlib_buffer_t *b0; + void *a0; u64 v_old; b0 = vlib_get_buffer (vm, buffers[0]); @@ -699,16 +660,13 @@ do_setbits_random (pg_main_t * pg, u32 n_buffers, u32 max_bits, u32 n_bits, - u32 byte_offset, - u64 v_min, u64 v_max, - u64 mask, - u32 shift) + u32 byte_offset, u64 v_min, u64 v_max, u64 mask, u32 shift) { - vlib_main_t * vm = pg->vlib_main; + vlib_main_t *vm = pg->vlib_main; u64 v_diff = v_max - v_min + 1; u64 r_mask = max_pow2 (v_diff) - 1; u64 v0, v1; - void * random_data; + void *random_data; random_data = clib_random_buffer_get_data (&vm->random_buffer, n_buffers * max_bits / BITS (u8)); @@ -716,9 +674,9 @@ do_setbits_random (pg_main_t * pg, while (n_buffers >= 4) { - vlib_buffer_t * b0, * b1, * b2, * b3; - void * a0, * a1; - u64 r0=0, r1=0; /* warnings be gone */ + vlib_buffer_t *b0, *b1, *b2, *b3; + void *a0, *a1; + u64 r0 = 0, r1 = 0; /* warnings be gone */ b0 = vlib_get_buffer (vm, buffers[0]); b1 = vlib_get_buffer (vm, buffers[1]); @@ -744,10 +702,10 @@ do_setbits_random (pg_main_t * pg, } \ break; - _ (8); - _ (16); - _ (32); - _ (64); + _(8); + _(16); + _(32); + _(64); #undef _ } @@ -762,10 +720,7 @@ do_setbits_random (pg_main_t * pg, v0 = v0 > v_max ? v0 - v_diff : v0; v1 = v1 > v_max ? v1 - v_diff : v1; - setbits_2 (a0, a1, - v0, v1, - v_min, v_max, - max_bits, n_bits, mask, shift, + setbits_2 (a0, a1, v0, v1, v_min, v_max, max_bits, n_bits, mask, shift, /* is_increment */ 0); ASSERT (validate_buffer_data (b0, s)); @@ -774,9 +729,9 @@ do_setbits_random (pg_main_t * pg, while (n_buffers > 0) { - vlib_buffer_t * b0; - void * a0; - u64 r0 = 0; /* warnings be gone */ + vlib_buffer_t *b0; + void *a0; + u64 r0 = 0; /* warnings be gone */ b0 = vlib_get_buffer (vm, buffers[0]); buffers += 1; @@ -795,10 +750,10 @@ do_setbits_random (pg_main_t * pg, } \ break; - _ (8); - _ (16); - _ (32); - _ (64); + _(8); + _(16); + _(32); + _(64); #undef _ } @@ -816,14 +771,13 @@ do_setbits_random (pg_main_t * pg, } } -static u64 do_it (pg_main_t * pg, - pg_stream_t * s, - u32 * buffers, - u32 n_buffers, - u32 lo_bit, u32 hi_bit, - u64 v_min, u64 v_max, - u64 v, - pg_edit_type_t edit_type) +static u64 +do_it (pg_main_t * pg, + pg_stream_t * s, + u32 * buffers, + u32 n_buffers, + u32 lo_bit, u32 hi_bit, + u64 v_min, u64 v_max, u64 v, pg_edit_type_t edit_type) { u32 max_bits, l0, l1, h1, start_bit; @@ -868,10 +822,10 @@ static u64 do_it (pg_main_t * pg, { switch (max_bits) { - _ (8); - _ (16); - _ (32); - _ (64); + _(8); + _(16); + _(32); + _(64); } } @@ -880,7 +834,7 @@ static u64 do_it (pg_main_t * pg, { u64 mask; u32 shift = l1; - u32 n_bits = max_bits; + u32 n_bits = max_bits; max_bits = clib_max (max_pow2 (n_bits), 8); @@ -911,24 +865,22 @@ static u64 do_it (pg_main_t * pg, mask, shift); \ goto done; - _ (8); - _ (16); - _ (32); - _ (64); + _(8); + _(16); + _(32); + _(64); #undef _ } } - done: +done: return v; } static void pg_generate_set_lengths (pg_main_t * pg, - pg_stream_t * s, - u32 * buffers, - u32 n_buffers) + pg_stream_t * s, u32 * buffers, u32 n_buffers) { u64 v_min, v_max, length_sum; pg_edit_type_t edit_type; @@ -944,8 +896,7 @@ pg_generate_set_lengths (pg_main_t * pg, STRUCT_OFFSET_OF (vlib_buffer_t, current_length), /* is_net_byte_order */ 0, /* want sum */ 1, &length_sum, - v_min, v_max, - s->last_increment_packet_size); + v_min, v_max, s->last_increment_packet_size); else if (edit_type == PG_EDIT_RANDOM) do_set_random (pg, s, buffers, n_buffers, @@ -955,7 +906,7 @@ pg_generate_set_lengths (pg_main_t * pg, /* want sum */ 1, &length_sum, v_min, v_max); - else /* edit_type == PG_EDIT_FIXED */ + else /* edit_type == PG_EDIT_FIXED */ { do_set_fixed (pg, s, buffers, n_buffers, 8 * STRUCT_SIZE_OF (vlib_buffer_t, current_length), @@ -966,16 +917,15 @@ pg_generate_set_lengths (pg_main_t * pg, } { - vnet_main_t * vnm = vnet_get_main(); - vnet_interface_main_t * im = &vnm->interface_main; - vnet_sw_interface_t * si = vnet_get_sw_interface (vnm, s->sw_if_index[VLIB_RX]); + vnet_main_t *vnm = vnet_get_main (); + vnet_interface_main_t *im = &vnm->interface_main; + vnet_sw_interface_t *si = + vnet_get_sw_interface (vnm, s->sw_if_index[VLIB_RX]); vlib_increment_combined_counter (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX, - os_get_cpu_number(), - si->sw_if_index, - n_buffers, - length_sum); + os_get_cpu_number (), + si->sw_if_index, n_buffers, length_sum); } pg_set_mbuf_metadata (pg, buffers, n_buffers); @@ -984,17 +934,16 @@ pg_generate_set_lengths (pg_main_t * pg, static void pg_generate_fix_multi_buffer_lengths (pg_main_t * pg, pg_stream_t * s, - u32 * buffers, - u32 n_buffers) + u32 * buffers, u32 n_buffers) { - vlib_main_t * vm = pg->vlib_main; - pg_buffer_index_t * pbi; + vlib_main_t *vm = pg->vlib_main; + pg_buffer_index_t *pbi; uword n_bytes_left; - static u32 * unused_buffers = 0; + static u32 *unused_buffers = 0; while (n_buffers > 0) { - vlib_buffer_t * b; + vlib_buffer_t *b; u32 bi; bi = buffers[0]; @@ -1034,61 +983,56 @@ pg_generate_fix_multi_buffer_lengths (pg_main_t * pg, if (vec_len (unused_buffers) > 0) { - vlib_buffer_free_no_next (vm, unused_buffers, - vec_len (unused_buffers)); + vlib_buffer_free_no_next (vm, unused_buffers, vec_len (unused_buffers)); _vec_len (unused_buffers) = 0; } } static void pg_generate_edit (pg_main_t * pg, - pg_stream_t * s, - u32 * buffers, - u32 n_buffers) + pg_stream_t * s, u32 * buffers, u32 n_buffers) { - pg_edit_t * e; + pg_edit_t *e; vec_foreach (e, s->non_fixed_edits) - { - switch (e->type) + { + switch (e->type) + { + case PG_EDIT_RANDOM: + case PG_EDIT_INCREMENT: { - case PG_EDIT_RANDOM: - case PG_EDIT_INCREMENT: - { - u32 lo_bit, hi_bit; - u64 v_min, v_max; - - v_min = pg_edit_get_value (e, PG_EDIT_LO); - v_max = pg_edit_get_value (e, PG_EDIT_HI); - - hi_bit = (BITS (u8) * STRUCT_OFFSET_OF (vlib_buffer_t, data) - + BITS (u8) - + e->lsb_bit_offset); - lo_bit = hi_bit - e->n_bits; - - e->last_increment_value - = do_it (pg, s, buffers, n_buffers, lo_bit, hi_bit, v_min, v_max, - e->last_increment_value, - e->type); - } - break; + u32 lo_bit, hi_bit; + u64 v_min, v_max; - case PG_EDIT_UNSPECIFIED: - break; + v_min = pg_edit_get_value (e, PG_EDIT_LO); + v_max = pg_edit_get_value (e, PG_EDIT_HI); - default: - /* Should not be any fixed edits left. */ - ASSERT (0); - break; + hi_bit = (BITS (u8) * STRUCT_OFFSET_OF (vlib_buffer_t, data) + + BITS (u8) + e->lsb_bit_offset); + lo_bit = hi_bit - e->n_bits; + + e->last_increment_value + = do_it (pg, s, buffers, n_buffers, lo_bit, hi_bit, v_min, v_max, + e->last_increment_value, e->type); } - } + break; + + case PG_EDIT_UNSPECIFIED: + break; + + default: + /* Should not be any fixed edits left. */ + ASSERT (0); + break; + } + } /* Call any edit functions to e.g. completely IP lengths, checksums, ... */ { int i; for (i = vec_len (s->edit_groups) - 1; i >= 0; i--) { - pg_edit_group_t * g = s->edit_groups + i; + pg_edit_group_t *g = s->edit_groups + i; if (g->edit_function) g->edit_function (pg, s, g, buffers, n_buffers); } @@ -1098,16 +1042,14 @@ pg_generate_edit (pg_main_t * pg, static void pg_set_next_buffer_pointers (pg_main_t * pg, pg_stream_t * s, - u32 * buffers, - u32 * next_buffers, - u32 n_buffers) + u32 * buffers, u32 * next_buffers, u32 n_buffers) { - vlib_main_t * vm = pg->vlib_main; + vlib_main_t *vm = pg->vlib_main; while (n_buffers >= 4) { u32 ni0, ni1; - vlib_buffer_t * b0, * b1; + vlib_buffer_t *b0, *b1; b0 = vlib_get_buffer (vm, buffers[0]); b1 = vlib_get_buffer (vm, buffers[1]); @@ -1130,7 +1072,7 @@ pg_set_next_buffer_pointers (pg_main_t * pg, while (n_buffers > 0) { u32 ni0; - vlib_buffer_t * b0; + vlib_buffer_t *b0; b0 = vlib_get_buffer (vm, buffers[0]); ni0 = next_buffers[0]; @@ -1147,11 +1089,9 @@ static_always_inline void init_replay_buffers_inline (vlib_main_t * vm, pg_stream_t * s, u32 * buffers, - u32 n_buffers, - u32 data_offset, - u32 n_data) + u32 n_buffers, u32 data_offset, u32 n_data) { - u32 n_left, * b, i, l; + u32 n_left, *b, i, l; n_left = n_buffers; b = buffers; @@ -1161,8 +1101,8 @@ init_replay_buffers_inline (vlib_main_t * vm, while (n_left >= 1) { u32 bi0, n0; - vlib_buffer_t * b0; - u8 * d0; + vlib_buffer_t *b0; + u8 *d0; bi0 = b[0]; b += 1; @@ -1172,7 +1112,7 @@ init_replay_buffers_inline (vlib_main_t * vm, vnet_buffer (b0)->sw_if_index[VLIB_RX] = s->sw_if_index[VLIB_RX]; /* was s->sw_if_index[VLIB_TX]; */ - vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32)~0; + vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0; d0 = vec_elt (s->replay_packet_templates, i); @@ -1191,23 +1131,20 @@ static_always_inline void init_buffers_inline (vlib_main_t * vm, pg_stream_t * s, u32 * buffers, - u32 n_buffers, - u32 data_offset, - u32 n_data, - u32 set_data) + u32 n_buffers, u32 data_offset, u32 n_data, u32 set_data) { - u32 n_left, * b; - u8 * data, * mask; + u32 n_left, *b; + u8 *data, *mask; if (vec_len (s->replay_packet_templates) > 0) - return init_replay_buffers_inline (vm, s, buffers, n_buffers, data_offset, n_data); + return init_replay_buffers_inline (vm, s, buffers, n_buffers, data_offset, + n_data); data = s->fixed_packet_data + data_offset; mask = s->fixed_packet_data_mask + data_offset; if (data + n_data >= vec_end (s->fixed_packet_data)) n_data = (data < vec_end (s->fixed_packet_data) - ? vec_end (s->fixed_packet_data) - data - : 0); + ? vec_end (s->fixed_packet_data) - data : 0); if (n_data > 0) { ASSERT (data + n_data <= vec_end (s->fixed_packet_data)); @@ -1220,7 +1157,7 @@ init_buffers_inline (vlib_main_t * vm, while (n_left >= 4) { u32 bi0, bi1; - vlib_buffer_t * b0, * b1; + vlib_buffer_t *b0, *b1; /* Prefetch next iteration. */ vlib_prefetch_buffer_with_index (vm, b[2], STORE); @@ -1238,7 +1175,7 @@ init_buffers_inline (vlib_main_t * vm, vnet_buffer (b1)->sw_if_index[VLIB_RX] = s->sw_if_index[VLIB_RX]; vnet_buffer (b0)->sw_if_index[VLIB_TX] = - vnet_buffer (b1)->sw_if_index[VLIB_TX] = (u32)~0; + vnet_buffer (b1)->sw_if_index[VLIB_TX] = (u32) ~ 0; if (set_data) { @@ -1255,7 +1192,7 @@ init_buffers_inline (vlib_main_t * vm, while (n_left >= 1) { u32 bi0; - vlib_buffer_t * b0; + vlib_buffer_t *b0; bi0 = b[0]; b += 1; @@ -1264,7 +1201,7 @@ init_buffers_inline (vlib_main_t * vm, b0 = vlib_get_buffer (vm, bi0); vnet_buffer (b0)->sw_if_index[VLIB_RX] = s->sw_if_index[VLIB_RX]; /* s->sw_if_index[VLIB_TX]; */ - vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32)~0; + vnet_buffer (b0)->sw_if_index[VLIB_TX] = (u32) ~ 0; if (set_data) clib_memcpy (b0->data, data, n_data); @@ -1273,13 +1210,12 @@ init_buffers_inline (vlib_main_t * vm, } } -static void pg_buffer_init (vlib_main_t * vm, - vlib_buffer_free_list_t * fl, - u32 * buffers, - u32 n_buffers) +static void +pg_buffer_init (vlib_main_t * vm, + vlib_buffer_free_list_t * fl, u32 * buffers, u32 n_buffers) { - pg_main_t * pg = &pg_main; - pg_stream_t * s; + pg_main_t *pg = &pg_main; + pg_stream_t *s; uword bi, si; si = fl->buffer_init_function_opaque & pow2_mask (24); @@ -1297,58 +1233,55 @@ static u32 pg_stream_fill_helper (pg_main_t * pg, pg_stream_t * s, pg_buffer_index_t * bi, - u32 * buffers, - u32 * next_buffers, - u32 n_alloc) + u32 * buffers, u32 * next_buffers, u32 n_alloc) { - vlib_main_t * vm = pg->vlib_main; - vlib_buffer_free_list_t * f; + vlib_main_t *vm = pg->vlib_main; + vlib_buffer_free_list_t *f; uword is_start_of_packet = bi == s->buffer_indices; u32 n_allocated; f = vlib_buffer_get_free_list (vm, bi->free_list_index); - /* + /* * Historically, the pg maintained its own free lists and * device drivers tx paths would return pkts. With the DPDK, * that doesn't happen. */ - if (DPDK == 0 && ! (s->flags & PG_STREAM_FLAGS_DISABLE_BUFFER_RECYCLE)) + if (DPDK == 0 && !(s->flags & PG_STREAM_FLAGS_DISABLE_BUFFER_RECYCLE)) f->buffer_init_function = pg_buffer_init; - f->buffer_init_function_opaque = + f->buffer_init_function_opaque = (s - pg->streams) | ((bi - s->buffer_indices) << 24); if (is_start_of_packet) - vnet_buffer (&f->buffer_init_template)->sw_if_index[VLIB_RX] + vnet_buffer (&f->buffer_init_template)->sw_if_index[VLIB_RX] = vnet_main.local_interface_sw_if_index; n_allocated = vlib_buffer_alloc_from_free_list (vm, - buffers, - n_alloc, - bi->free_list_index); + buffers, + n_alloc, + bi->free_list_index); if (n_allocated == 0) return 0; - /* - * We can't assume we got all the buffers we asked for... + /* + * We can't assume we got all the buffers we asked for... * This never worked until recently. */ n_alloc = n_allocated; /* Reinitialize buffers */ - if (DPDK == 0 || CLIB_DEBUG > 0 + if (DPDK == 0 || CLIB_DEBUG > 0 || (s->flags & PG_STREAM_FLAGS_DISABLE_BUFFER_RECYCLE)) init_buffers_inline (vm, s, buffers, - n_alloc, - (bi - s->buffer_indices) * s->buffer_bytes /* data offset */, + n_alloc, (bi - s->buffer_indices) * s->buffer_bytes /* data offset */ , s->buffer_bytes, /* set_data */ DPDK == 1 || (s->flags & PG_STREAM_FLAGS_DISABLE_BUFFER_RECYCLE) != 0); - + /* $$$ this doesn't work at the moment */ - ASSERT(next_buffers == 0); + ASSERT (next_buffers == 0); if (next_buffers) pg_set_next_buffer_pointers (pg, s, buffers, next_buffers, n_alloc); @@ -1356,23 +1289,21 @@ pg_stream_fill_helper (pg_main_t * pg, { if (vec_len (s->replay_packet_templates) > 0) { - vnet_main_t * vnm = vnet_get_main(); - vnet_interface_main_t * im = &vnm->interface_main; - vnet_sw_interface_t * si = - vnet_get_sw_interface (vnm, s->sw_if_index[VLIB_RX]); + vnet_main_t *vnm = vnet_get_main (); + vnet_interface_main_t *im = &vnm->interface_main; + vnet_sw_interface_t *si = + vnet_get_sw_interface (vnm, s->sw_if_index[VLIB_RX]); u32 l = 0; u32 i; for (i = 0; i < n_alloc; i++) l += vlib_buffer_index_length_in_chain (vm, buffers[i]); vlib_increment_combined_counter (im->combined_sw_if_counters + VNET_INTERFACE_COUNTER_RX, - os_get_cpu_number(), - si->sw_if_index, - n_alloc, - l); + os_get_cpu_number (), + si->sw_if_index, n_alloc, l); s->current_replay_packet_index += n_alloc; - s->current_replay_packet_index %= - vec_len (s->replay_packet_templates); + s->current_replay_packet_index %= + vec_len (s->replay_packet_templates); } else { @@ -1390,9 +1321,9 @@ pg_stream_fill_helper (pg_main_t * pg, static u32 pg_stream_fill (pg_main_t * pg, pg_stream_t * s, u32 n_buffers) { - pg_buffer_index_t * bi; + pg_buffer_index_t *bi; word i, n_in_fifo, n_alloc, n_free, n_added; - u32 * tail, * start, * end, * last_tail, * last_start; + u32 *tail, *start, *end, *last_tail, *last_start; bi = s->buffer_indices; @@ -1418,12 +1349,12 @@ pg_stream_fill (pg_main_t * pg, pg_stream_t * s, u32 n_buffers) { uword l = ~0, e; vec_foreach (bi, s->buffer_indices) - { - e = clib_fifo_elts (bi->buffer_fifo); - if (bi == s->buffer_indices) - l = e; - ASSERT (l == e); - } + { + e = clib_fifo_elts (bi->buffer_fifo); + if (bi == s->buffer_indices) + l = e; + ASSERT (l == e); + } } last_tail = last_start = 0; @@ -1442,19 +1373,20 @@ pg_stream_fill (pg_main_t * pg, pg_stream_t * s, u32 n_buffers) end = clib_fifo_end (bi->buffer_fifo); if (tail + n_alloc <= end) - { - n_added = pg_stream_fill_helper (pg, s, bi, tail, last_tail, n_alloc); - } + { + n_added = + pg_stream_fill_helper (pg, s, bi, tail, last_tail, n_alloc); + } else { u32 n = clib_min (end - tail, n_alloc); n_added = pg_stream_fill_helper (pg, s, bi, tail, last_tail, n); if (n_added == n && n_alloc > n_added) - { - n_added += pg_stream_fill_helper - (pg, s, bi, start, last_start, n_alloc - n_added); - } + { + n_added += pg_stream_fill_helper + (pg, s, bi, start, last_start, n_alloc - n_added); + } } if (PREDICT_FALSE (n_added < n_alloc)) @@ -1466,10 +1398,11 @@ pg_stream_fill (pg_main_t * pg, pg_stream_t * s, u32 n_buffers) /* Verify that pkts in the fifo are properly allocated */ #if DPDK == 1 if (CLIB_DEBUG > 0) - { - u32 *bi0; - vlib_main_t * vm = vlib_get_main(); - clib_fifo_foreach (bi0, bi->buffer_fifo, + { + u32 *bi0; + vlib_main_t *vm = vlib_get_main (); + /* *INDENT-OFF* */ + clib_fifo_foreach (bi0, bi->buffer_fifo, ({ vlib_buffer_t * b; struct rte_mbuf *mb; @@ -1478,14 +1411,16 @@ pg_stream_fill (pg_main_t * pg, pg_stream_t * s, u32 n_buffers) mb = rte_mbuf_from_vlib_buffer(b); ASSERT(rte_mbuf_refcnt_read(mb) == 1); })); - } + /* *INDENT-ON* */ + } #endif } - + return n_in_fifo + n_added; } -typedef struct { +typedef struct +{ u32 stream_index; u32 packet_length; @@ -1494,18 +1429,19 @@ typedef struct { vlib_buffer_t buffer; } pg_input_trace_t; -static u8 * format_pg_input_trace (u8 * s, va_list * va) +static u8 * +format_pg_input_trace (u8 * s, va_list * va) { - vlib_main_t * vm = va_arg (*va, vlib_main_t *); + vlib_main_t *vm = va_arg (*va, vlib_main_t *); CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *); - pg_input_trace_t * t = va_arg (*va, pg_input_trace_t *); - pg_main_t * pg = &pg_main; - pg_stream_t * stream; - vlib_node_t * n; + pg_input_trace_t *t = va_arg (*va, pg_input_trace_t *); + pg_main_t *pg = &pg_main; + pg_stream_t *stream; + vlib_node_t *n; uword indent = format_get_indent (s); stream = 0; - if (! pool_is_free_index (pg->streams, t->stream_index)) + if (!pool_is_free_index (pg->streams, t->stream_index)) stream = pool_elt_at_index (pg->streams, t->stream_index); if (stream) @@ -1516,11 +1452,9 @@ static u8 * format_pg_input_trace (u8 * s, va_list * va) s = format (s, ", %d bytes", t->packet_length); s = format (s, "\n%U%U", - format_white_space, indent, - format_vlib_buffer, &t->buffer); + format_white_space, indent, format_vlib_buffer, &t->buffer); - s = format (s, "\n%U", - format_white_space, indent); + s = format (s, "\n%U", format_white_space, indent); n = 0; if (stream) @@ -1528,10 +1462,9 @@ static u8 * format_pg_input_trace (u8 * s, va_list * va) if (n && n->format_buffer) s = format (s, "%U", n->format_buffer, - t->buffer.pre_data, - sizeof (t->buffer.pre_data)); + t->buffer.pre_data, sizeof (t->buffer.pre_data)); else - s = format (s, "%U", + s = format (s, "%U", format_hex_bytes, t->buffer.pre_data, ARRAY_LEN (t->buffer.pre_data)); return s; @@ -1540,12 +1473,10 @@ static u8 * format_pg_input_trace (u8 * s, va_list * va) static void pg_input_trace (pg_main_t * pg, vlib_node_runtime_t * node, - pg_stream_t * s, - u32 * buffers, - u32 n_buffers) + pg_stream_t * s, u32 * buffers, u32 n_buffers) { - vlib_main_t * vm = pg->vlib_main; - u32 * b, n_left, stream_index, next_index; + vlib_main_t *vm = pg->vlib_main; + u32 *b, n_left, stream_index, next_index; n_left = n_buffers; b = buffers; @@ -1555,8 +1486,8 @@ pg_input_trace (pg_main_t * pg, while (n_left >= 2) { u32 bi0, bi1; - vlib_buffer_t * b0, * b1; - pg_input_trace_t * t0, * t1; + vlib_buffer_t *b0, *b1; + pg_input_trace_t *t0, *t1; bi0 = b[0]; bi1 = b[1]; @@ -1581,15 +1512,17 @@ pg_input_trace (pg_main_t * pg, clib_memcpy (&t0->buffer, b0, sizeof (b0[0]) - sizeof (b0->pre_data)); clib_memcpy (&t1->buffer, b1, sizeof (b1[0]) - sizeof (b1->pre_data)); - clib_memcpy (t0->buffer.pre_data, b0->data, sizeof (t0->buffer.pre_data)); - clib_memcpy (t1->buffer.pre_data, b1->data, sizeof (t1->buffer.pre_data)); + clib_memcpy (t0->buffer.pre_data, b0->data, + sizeof (t0->buffer.pre_data)); + clib_memcpy (t1->buffer.pre_data, b1->data, + sizeof (t1->buffer.pre_data)); } while (n_left >= 1) { u32 bi0; - vlib_buffer_t * b0; - pg_input_trace_t * t0; + vlib_buffer_t *b0; + pg_input_trace_t *t0; bi0 = b[0]; b += 1; @@ -1603,20 +1536,20 @@ pg_input_trace (pg_main_t * pg, t0->stream_index = stream_index; t0->packet_length = vlib_buffer_length_in_chain (vm, b0); clib_memcpy (&t0->buffer, b0, sizeof (b0[0]) - sizeof (b0->pre_data)); - clib_memcpy (t0->buffer.pre_data, b0->data, sizeof (t0->buffer.pre_data)); + clib_memcpy (t0->buffer.pre_data, b0->data, + sizeof (t0->buffer.pre_data)); } } static uword pg_generate_packets (vlib_node_runtime_t * node, pg_main_t * pg, - pg_stream_t * s, - uword n_packets_to_generate) + pg_stream_t * s, uword n_packets_to_generate) { - vlib_main_t * vm = pg->vlib_main; - u32 * to_next, n_this_frame, n_left, n_trace, n_packets_in_fifo; + vlib_main_t *vm = pg->vlib_main; + u32 *to_next, n_this_frame, n_left, n_trace, n_packets_in_fifo; uword n_packets_generated; - pg_buffer_index_t * bi, * bi0; + pg_buffer_index_t *bi, *bi0; bi0 = s->buffer_indices; @@ -1626,7 +1559,7 @@ pg_generate_packets (vlib_node_runtime_t * node, while (n_packets_to_generate > 0) { - u32 * head, * start, * end; + u32 *head, *start, *end; vlib_get_next_frame (vm, node, s->next_index, to_next, n_left); @@ -1667,16 +1600,13 @@ pg_generate_packets (vlib_node_runtime_t * node, } static uword -pg_input_stream (vlib_node_runtime_t * node, - pg_main_t * pg, - pg_stream_t * s) +pg_input_stream (vlib_node_runtime_t * node, pg_main_t * pg, pg_stream_t * s) { - vlib_main_t * vm = pg->vlib_main; + vlib_main_t *vm = pg->vlib_main; uword n_packets; f64 time_now, dt; - if (s->n_packets_limit > 0 - && s->n_packets_generated >= s->n_packets_limit) + if (s->n_packets_limit > 0 && s->n_packets_generated >= s->n_packets_limit) { pg_stream_enable_disable (pg, s, /* want_enabled */ 0); return 0; @@ -1718,21 +1648,22 @@ pg_input_stream (vlib_node_runtime_t * node, } uword -pg_input (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) +pg_input (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { uword i; - pg_main_t * pg = &pg_main; + pg_main_t *pg = &pg_main; uword n_packets = 0; + /* *INDENT-OFF* */ clib_bitmap_foreach (i, pg->enabled_streams, ({ n_packets += pg_input_stream (node, pg, vec_elt_at_index (pg->streams, i)); })); + /* *INDENT-ON* */ return n_packets; } +/* *INDENT-OFF* */ VLIB_REGISTER_NODE (pg_input_node) = { .function = pg_input, .name = "pg-input", @@ -1743,3 +1674,12 @@ VLIB_REGISTER_NODE (pg_input_node) = { /* Input node will be left disabled until a stream is active. */ .state = VLIB_NODE_STATE_DISABLED, }; +/* *INDENT-ON* */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/pg/output.c b/vnet/vnet/pg/output.c index 5ce3f903508..2de06acaea5 100644 --- a/vnet/vnet/pg/output.c +++ b/vnet/vnet/pg/output.c @@ -43,16 +43,14 @@ #include <vnet/ethernet/ethernet.h> uword -pg_output (vlib_main_t * vm, - vlib_node_runtime_t * node, - vlib_frame_t * frame) +pg_output (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) { - pg_main_t * pg = &pg_main; - u32 * buffers = vlib_frame_args (frame); + pg_main_t *pg = &pg_main; + u32 *buffers = vlib_frame_args (frame); uword n_buffers = frame->n_vectors; uword n_left = n_buffers; - vnet_interface_output_runtime_t * rd = (void *) node->runtime_data; - pg_interface_t * pif = pool_elt_at_index (pg->interfaces, rd->dev_instance); + vnet_interface_output_runtime_t *rd = (void *) node->runtime_data; + pg_interface_t *pif = pool_elt_at_index (pg->interfaces, rd->dev_instance); if (pif->pcap_file_name != 0) { @@ -62,7 +60,8 @@ pg_output (vlib_main_t * vm, u32 bi0 = buffers[0]; buffers++; - pcap_add_buffer (&pif->pcap_main, vm, bi0, ETHERNET_MAX_PACKET_BYTES); + pcap_add_buffer (&pif->pcap_main, vm, bi0, + ETHERNET_MAX_PACKET_BYTES); } pcap_write (&pif->pcap_main); } @@ -70,3 +69,11 @@ pg_output (vlib_main_t * vm, vlib_buffer_free_no_next (vm, vlib_frame_args (frame), n_buffers); return n_buffers; } + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/pg/pg.h b/vnet/vnet/pg/pg.h index 54c270ff0a8..067172da174 100644 --- a/vnet/vnet/pg/pg.h +++ b/vnet/vnet/pg/pg.h @@ -42,7 +42,7 @@ #include <vlib/vlib.h> /* for VLIB_N_RX_TX */ #include <vnet/pg/edit.h> -#include <vppinfra/fifo.h> /* for buffer_fifo */ +#include <vppinfra/fifo.h> /* for buffer_fifo */ #include <vnet/unix/pcap.h> #include <vnet/interface.h> @@ -51,16 +51,17 @@ extern vnet_device_class_t pg_dev_class; struct pg_main_t; struct pg_stream_t; -typedef struct pg_edit_group_t { +typedef struct pg_edit_group_t +{ /* Edits in this group. */ - pg_edit_t * edits; + pg_edit_t *edits; /* Vector of non-fixed edits for this group. */ - pg_edit_t * non_fixed_edits; + pg_edit_t *non_fixed_edits; /* Fixed edits for this group. */ - u8 * fixed_packet_data; - u8 * fixed_packet_data_mask; + u8 *fixed_packet_data; + u8 *fixed_packet_data_mask; /* Byte offset where packet data begins. */ u32 start_byte_offset; @@ -69,11 +70,10 @@ typedef struct pg_edit_group_t { u32 n_packet_bytes; /* Function to perform miscellaneous edits (e.g. set IP checksum, ...). */ - void (* edit_function) (struct pg_main_t * pg, - struct pg_stream_t * s, - struct pg_edit_group_t * g, - u32 * buffers, - u32 n_buffers); + void (*edit_function) (struct pg_main_t * pg, + struct pg_stream_t * s, + struct pg_edit_group_t * g, + u32 * buffers, u32 n_buffers); /* Opaque data for edit function's use. */ uword edit_function_opaque; @@ -81,20 +81,22 @@ typedef struct pg_edit_group_t { /* Packets are made of multiple buffers chained together. This struct keeps track of data per-chain index. */ -typedef struct { +typedef struct +{ /* Vector of buffer edits for this stream and buffer index. */ - pg_edit_t * edits; + pg_edit_t *edits; /* Buffers pre-initialized with fixed buffer data for this stream. */ - u32 * buffer_fifo; + u32 *buffer_fifo; /* Buffer free list for this buffer index in stream. */ u32 free_list_index; } pg_buffer_index_t; -typedef struct pg_stream_t { +typedef struct pg_stream_t +{ /* Stream name. */ - u8 * name; + u8 *name; u32 flags; @@ -104,7 +106,7 @@ typedef struct pg_stream_t { /* Edit groups are created by each protocol level (e.g. ethernet, ip4, tcp, ...). */ - pg_edit_group_t * edit_groups; + pg_edit_group_t *edit_groups; pg_edit_type_t packet_size_edit_type; @@ -113,12 +115,12 @@ typedef struct pg_stream_t { /* Vector of non-fixed edits for this stream. All fixed edits are performed and placed into fixed_packet_data. */ - pg_edit_t * non_fixed_edits; + pg_edit_t *non_fixed_edits; /* Packet data with all fixed edits performed. All packets in stream are initialized according with this data. Mask specifies which bits of packet data are covered by fixed edits. */ - u8 * fixed_packet_data, * fixed_packet_data_mask; + u8 *fixed_packet_data, *fixed_packet_data_mask; /* Size to use for buffers. 0 means use buffers big enough for max_packet_bytes. */ @@ -161,9 +163,9 @@ typedef struct pg_stream_t { f64 packet_accumulator; - pg_buffer_index_t * buffer_indices; + pg_buffer_index_t *buffer_indices; - u8 ** replay_packet_templates; + u8 **replay_packet_templates; u32 current_replay_packet_index; } pg_stream_t; @@ -177,9 +179,8 @@ pg_buffer_index_free (pg_buffer_index_t * bi) always_inline void pg_edit_group_free (pg_edit_group_t * g) { - pg_edit_t * e; - vec_foreach (e, g->edits) - pg_edit_free (e); + pg_edit_t *e; + vec_foreach (e, g->edits) pg_edit_free (e); vec_free (g->edits); vec_free (g->fixed_packet_data); vec_free (g->fixed_packet_data_mask); @@ -188,41 +189,40 @@ pg_edit_group_free (pg_edit_group_t * g) always_inline void pg_stream_free (pg_stream_t * s) { - pg_edit_group_t * g; - pg_edit_t * e; - vec_foreach (e, s->non_fixed_edits) - pg_edit_free (e); + pg_edit_group_t *g; + pg_edit_t *e; + vec_foreach (e, s->non_fixed_edits) pg_edit_free (e); vec_free (s->non_fixed_edits); - vec_foreach (g, s->edit_groups) - pg_edit_group_free (g); + vec_foreach (g, s->edit_groups) pg_edit_group_free (g); vec_free (s->edit_groups); vec_free (s->fixed_packet_data); vec_free (s->fixed_packet_data_mask); vec_free (s->name); { - pg_buffer_index_t * bi; - vec_foreach (bi, s->buffer_indices) - pg_buffer_index_free (bi); + pg_buffer_index_t *bi; + vec_foreach (bi, s->buffer_indices) pg_buffer_index_free (bi); vec_free (s->buffer_indices); } } always_inline int pg_stream_is_enabled (pg_stream_t * s) -{ return (s->flags & PG_STREAM_FLAGS_IS_ENABLED) != 0; } +{ + return (s->flags & PG_STREAM_FLAGS_IS_ENABLED) != 0; +} always_inline pg_edit_group_t * pg_stream_get_group (pg_stream_t * s, u32 group_index) -{ return vec_elt_at_index (s->edit_groups, group_index); } +{ + return vec_elt_at_index (s->edit_groups, group_index); +} always_inline void * pg_create_edit_group (pg_stream_t * s, - int n_edit_bytes, - int n_packet_bytes, - u32 * group_index) + int n_edit_bytes, int n_packet_bytes, u32 * group_index) { - pg_edit_group_t * g; + pg_edit_group_t *g; int n_edits; vec_add2 (s->edit_groups, g, 1); @@ -242,8 +242,8 @@ always_inline void * pg_add_edits (pg_stream_t * s, int n_edit_bytes, int n_packet_bytes, u32 group_index) { - pg_edit_group_t * g = pg_stream_get_group (s, group_index); - pg_edit_t * e; + pg_edit_group_t *g = pg_stream_get_group (s, group_index); + pg_edit_t *e; int n_edits; ASSERT (n_edit_bytes % sizeof (pg_edit_t) == 0); n_edits = n_edit_bytes / sizeof (pg_edit_t); @@ -255,7 +255,7 @@ pg_add_edits (pg_stream_t * s, int n_edit_bytes, int n_packet_bytes, always_inline void * pg_get_edit_group (pg_stream_t * s, u32 group_index) { - pg_edit_group_t * g = pg_stream_get_group (s, group_index); + pg_edit_group_t *g = pg_stream_get_group (s, group_index); return g->edits; } @@ -263,7 +263,7 @@ pg_get_edit_group (pg_stream_t * s, u32 group_index) always_inline uword pg_edit_group_n_bytes (pg_stream_t * s, u32 group_index) { - pg_edit_group_t * g; + pg_edit_group_t *g; uword n_bytes = 0; for (g = s->edit_groups + group_index; g < vec_end (s->edit_groups); g++) @@ -275,14 +275,15 @@ always_inline void pg_free_edit_group (pg_stream_t * s) { uword i = vec_len (s->edit_groups) - 1; - pg_edit_group_t * g = pg_stream_get_group (s, i); + pg_edit_group_t *g = pg_stream_get_group (s, i); pg_edit_group_free (g); memset (g, 0, sizeof (g[0])); _vec_len (s->edit_groups) = i; } -typedef struct { +typedef struct +{ /* VLIB interface indices. */ u32 hw_if_index, sw_if_index; @@ -290,34 +291,36 @@ typedef struct { u32 id; pcap_main_t pcap_main; - u8 * pcap_file_name; + u8 *pcap_file_name; } pg_interface_t; /* Per VLIB node data. */ -typedef struct { +typedef struct +{ /* Parser function indexed by node index. */ - unformat_function_t * unformat_edit; + unformat_function_t *unformat_edit; } pg_node_t; -typedef struct pg_main_t { +typedef struct pg_main_t +{ /* Back pointer to main structure. */ - vlib_main_t * vlib_main; + vlib_main_t *vlib_main; /* Pool of streams. */ - pg_stream_t * streams; + pg_stream_t *streams; /* Bitmap indicating which streams are currently enabled. */ - uword * enabled_streams; + uword *enabled_streams; /* Hash mapping name -> stream index. */ - uword * stream_index_by_name; + uword *stream_index_by_name; /* Pool of interfaces. */ - pg_interface_t * interfaces; - uword * if_index_by_if_id; + pg_interface_t *interfaces; + uword *if_index_by_if_id; /* Per VLIB node information. */ - pg_node_t * nodes; + pg_node_t *nodes; } pg_main_t; /* Global main structure. */ @@ -334,7 +337,8 @@ void pg_stream_del (pg_main_t * pg, uword index); void pg_stream_add (pg_main_t * pg, pg_stream_t * s_init); /* Enable/disable stream. */ -void pg_stream_enable_disable (pg_main_t * pg, pg_stream_t * s, int is_enable); +void pg_stream_enable_disable (pg_main_t * pg, pg_stream_t * s, + int is_enable); /* Find/create free packet-generator interface index. */ u32 pg_interface_add_or_get (pg_main_t * pg, uword stream_index); @@ -342,26 +346,35 @@ u32 pg_interface_add_or_get (pg_main_t * pg, uword stream_index); always_inline pg_node_t * pg_get_node (uword node_index) { - pg_main_t * pg = &pg_main; + pg_main_t *pg = &pg_main; vec_validate (pg->nodes, node_index); return pg->nodes + node_index; } void pg_edit_group_get_fixed_packet_data (pg_stream_t * s, u32 group_index, - void * fixed_packet_data, - void * fixed_packet_data_mask); + void *fixed_packet_data, + void *fixed_packet_data_mask); void pg_enable_disable (u32 stream_index, int is_enable); -typedef struct { - u32 hw_if_index; - u32 dev_instance; - u8 is_enabled; - u8 * pcap_file_name; - u32 count; +typedef struct +{ + u32 hw_if_index; + u32 dev_instance; + u8 is_enabled; + u8 *pcap_file_name; + u32 count; } pg_capture_args_t; -clib_error_t * pg_capture (pg_capture_args_t *a); +clib_error_t *pg_capture (pg_capture_args_t * a); #endif /* included_vlib_pg_h */ + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ diff --git a/vnet/vnet/pg/stream.c b/vnet/vnet/pg/stream.c index 769fce1a70c..9f7e9e8df05 100644 --- a/vnet/vnet/pg/stream.c +++ b/vnet/vnet/pg/stream.c @@ -42,24 +42,25 @@ #include <vnet/ethernet/ethernet.h> /* Mark stream active or inactive. */ -void pg_stream_enable_disable (pg_main_t * pg, pg_stream_t * s, int want_enabled) +void +pg_stream_enable_disable (pg_main_t * pg, pg_stream_t * s, int want_enabled) { - vnet_main_t * vnm = vnet_get_main(); - pg_interface_t * pi = pool_elt_at_index (pg->interfaces, s->pg_if_index); + vnet_main_t *vnm = vnet_get_main (); + pg_interface_t *pi = pool_elt_at_index (pg->interfaces, s->pg_if_index); want_enabled = want_enabled != 0; if (pg_stream_is_enabled (s) == want_enabled) /* No change necessary. */ return; - + if (want_enabled) s->n_packets_generated = 0; /* Toggle enabled flag. */ s->flags ^= PG_STREAM_FLAGS_IS_ENABLED; - ASSERT (! pool_is_free (pg->streams, s)); + ASSERT (!pool_is_free (pg->streams, s)); pg->enabled_streams = clib_bitmap_set (pg->enabled_streams, s - pg->streams, want_enabled); @@ -67,12 +68,12 @@ void pg_stream_enable_disable (pg_main_t * pg, pg_stream_t * s, int want_enabled if (want_enabled) { vnet_hw_interface_set_flags (vnm, pi->hw_if_index, - VNET_HW_INTERFACE_FLAG_LINK_UP); + VNET_HW_INTERFACE_FLAG_LINK_UP); vnet_sw_interface_set_flags (vnm, pi->sw_if_index, - VNET_SW_INTERFACE_FLAG_ADMIN_UP); + VNET_SW_INTERFACE_FLAG_ADMIN_UP); } - + vlib_node_set_state (pg->vlib_main, pg_input_node.index, (clib_bitmap_is_zero (pg->enabled_streams) @@ -83,11 +84,12 @@ void pg_stream_enable_disable (pg_main_t * pg, pg_stream_t * s, int want_enabled s->time_last_generate = 0; } -static u8 * format_pg_interface_name (u8 * s, va_list * args) +static u8 * +format_pg_interface_name (u8 * s, va_list * args) { - pg_main_t * pg = &pg_main; + pg_main_t *pg = &pg_main; u32 if_index = va_arg (*args, u32); - pg_interface_t * pi; + pg_interface_t *pi; pi = pool_elt_at_index (pg->interfaces, if_index); s = format (s, "pg%d", pi->id); @@ -103,26 +105,27 @@ pg_interface_admin_up_down (vnet_main_t * vnm, u32 hw_if_index, u32 flags) if (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) hw_flags = VNET_HW_INTERFACE_FLAG_LINK_UP; - vnet_hw_interface_set_flags(vnm, hw_if_index, hw_flags); + vnet_hw_interface_set_flags (vnm, hw_if_index, hw_flags); return 0; } +/* *INDENT-OFF* */ VNET_DEVICE_CLASS (pg_dev_class) = { .name = "pg", .tx_function = pg_output, .format_device_name = format_pg_interface_name, .admin_up_down_function = pg_interface_admin_up_down, }; +/* *INDENT-ON* */ -static uword pg_set_rewrite (vnet_main_t * vnm, - u32 sw_if_index, - u32 l3_type, - void * dst_address, - void * rewrite, - uword max_rewrite_bytes) +static uword +pg_set_rewrite (vnet_main_t * vnm, + u32 sw_if_index, + u32 l3_type, + void *dst_address, void *rewrite, uword max_rewrite_bytes) { - u16 * h = rewrite; + u16 *h = rewrite; if (max_rewrite_bytes < sizeof (h[0])) return 0; @@ -131,10 +134,12 @@ static uword pg_set_rewrite (vnet_main_t * vnm, return sizeof (h[0]); } +/* *INDENT-OFF* */ VNET_HW_INTERFACE_CLASS (pg_interface_class,static) = { .name = "Packet generator", .set_rewrite = pg_set_rewrite, }; +/* *INDENT-ON* */ static u32 pg_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags) @@ -143,12 +148,13 @@ pg_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags) return 0; } -u32 pg_interface_add_or_get (pg_main_t * pg, uword if_id) +u32 +pg_interface_add_or_get (pg_main_t * pg, uword if_id) { - vnet_main_t * vnm = vnet_get_main(); - vlib_main_t * vm = vlib_get_main(); - pg_interface_t * pi; - vnet_hw_interface_t * hi; + vnet_main_t *vnm = vnet_get_main (); + vlib_main_t *vm = vlib_get_main (); + pg_interface_t *pi; + vnet_hw_interface_t *hi; uword *p; u32 i; @@ -161,7 +167,7 @@ u32 pg_interface_add_or_get (pg_main_t * pg, uword if_id) else { u8 hw_addr[6]; - f64 now = vlib_time_now(vm); + f64 now = vlib_time_now (vm); u32 rnd; pool_get (pg->interfaces, pi); @@ -169,7 +175,7 @@ u32 pg_interface_add_or_get (pg_main_t * pg, uword if_id) rnd = (u32) (now * 1e6); rnd = random_u32 (&rnd); - clib_memcpy (hw_addr+2, &rnd, sizeof(rnd)); + clib_memcpy (hw_addr + 2, &rnd, sizeof (rnd)); hw_addr[0] = 2; hw_addr[1] = 0xfe; @@ -185,13 +191,12 @@ u32 pg_interface_add_or_get (pg_main_t * pg, uword if_id) return i; } -static void do_edit (pg_stream_t * stream, - pg_edit_group_t * g, - pg_edit_t * e, - uword want_commit) +static void +do_edit (pg_stream_t * stream, + pg_edit_group_t * g, pg_edit_t * e, uword want_commit) { u32 i, i0, i1, mask, n_bits_left; - u8 * v, * s, * m; + u8 *v, *s, *m; i0 = e->lsb_bit_offset / BITS (u8); @@ -212,11 +217,11 @@ static void do_edit (pg_stream_t * stream, break; } - if (want_commit) - { - ASSERT(e->type != PG_EDIT_INVALID_TYPE); - vec_add1 (g->non_fixed_edits, e[0]); - } + if (want_commit) + { + ASSERT (e->type != PG_EDIT_INVALID_TYPE); + vec_add1 (g->non_fixed_edits, e[0]); + } return; } @@ -239,7 +244,7 @@ static void do_edit (pg_stream_t * stream, ASSERT (i0 < vec_len (s)); ASSERT (i < vec_len (v)); - ASSERT ((v[i] &~ mask) == 0); + ASSERT ((v[i] & ~mask) == 0); s[i0] |= v[i] & mask; m[i0] |= mask; @@ -270,7 +275,7 @@ static void do_edit (pg_stream_t * stream, ASSERT (i0 < vec_len (s)); ASSERT (i < vec_len (v)); - ASSERT ((v[i] &~ mask) == 0); + ASSERT ((v[i] & ~mask) == 0); s[i0] |= v[i] & mask; m[i0] |= mask; @@ -280,73 +285,73 @@ static void do_edit (pg_stream_t * stream, pg_edit_free (e); } -void pg_edit_group_get_fixed_packet_data (pg_stream_t * s, - u32 group_index, - void * packet_data, - void * packet_data_mask) +void +pg_edit_group_get_fixed_packet_data (pg_stream_t * s, + u32 group_index, + void *packet_data, + void *packet_data_mask) { - pg_edit_group_t * g = pg_stream_get_group (s, group_index); - pg_edit_t * e; + pg_edit_group_t *g = pg_stream_get_group (s, group_index); + pg_edit_t *e; - vec_foreach (e, g->edits) - do_edit (s, g, e, /* want_commit */ 0); + vec_foreach (e, g->edits) do_edit (s, g, e, /* want_commit */ 0); - clib_memcpy (packet_data, g->fixed_packet_data, vec_len (g->fixed_packet_data)); - clib_memcpy (packet_data_mask, g->fixed_packet_data_mask, vec_len (g->fixed_packet_data_mask)); + clib_memcpy (packet_data, g->fixed_packet_data, + vec_len (g->fixed_packet_data)); + clib_memcpy (packet_data_mask, g->fixed_packet_data_mask, + vec_len (g->fixed_packet_data_mask)); } -static void perform_fixed_edits (pg_stream_t * s) +static void +perform_fixed_edits (pg_stream_t * s) { - pg_edit_group_t * g; - pg_edit_t * e; + pg_edit_group_t *g; + pg_edit_t *e; word i; for (i = vec_len (s->edit_groups) - 1; i >= 0; i--) { g = vec_elt_at_index (s->edit_groups, i); - vec_foreach (e, g->edits) - do_edit (s, g, e, /* want_commit */ 1); + vec_foreach (e, g->edits) do_edit (s, g, e, /* want_commit */ 1); /* All edits have either been performed or added to - g->non_fixed_edits. So, we can delete the vector. */ + g->non_fixed_edits. So, we can delete the vector. */ vec_free (g->edits); } vec_free (s->fixed_packet_data_mask); vec_free (s->fixed_packet_data); vec_foreach (g, s->edit_groups) - { - int i; - g->start_byte_offset = vec_len (s->fixed_packet_data); - - /* Relocate and copy non-fixed edits from group to stream. */ - vec_foreach (e, g->non_fixed_edits) - e->lsb_bit_offset += g->start_byte_offset * BITS (u8); - - for (i = 0; i < vec_len (g->non_fixed_edits); i++) - ASSERT(g->non_fixed_edits[i].type != PG_EDIT_INVALID_TYPE); - - vec_add (s->non_fixed_edits, - g->non_fixed_edits, - vec_len (g->non_fixed_edits)); - vec_free (g->non_fixed_edits); - - vec_add (s->fixed_packet_data, - g->fixed_packet_data, - vec_len (g->fixed_packet_data)); - vec_add (s->fixed_packet_data_mask, - g->fixed_packet_data_mask, - vec_len (g->fixed_packet_data_mask)); - } + { + int i; + g->start_byte_offset = vec_len (s->fixed_packet_data); + + /* Relocate and copy non-fixed edits from group to stream. */ + vec_foreach (e, g->non_fixed_edits) + e->lsb_bit_offset += g->start_byte_offset * BITS (u8); + + for (i = 0; i < vec_len (g->non_fixed_edits); i++) + ASSERT (g->non_fixed_edits[i].type != PG_EDIT_INVALID_TYPE); + + vec_add (s->non_fixed_edits, + g->non_fixed_edits, vec_len (g->non_fixed_edits)); + vec_free (g->non_fixed_edits); + + vec_add (s->fixed_packet_data, + g->fixed_packet_data, vec_len (g->fixed_packet_data)); + vec_add (s->fixed_packet_data_mask, + g->fixed_packet_data_mask, vec_len (g->fixed_packet_data_mask)); + } } -void pg_stream_add (pg_main_t * pg, pg_stream_t * s_init) +void +pg_stream_add (pg_main_t * pg, pg_stream_t * s_init) { - vlib_main_t * vm = pg->vlib_main; - pg_stream_t * s; - uword * p; + vlib_main_t *vm = pg->vlib_main; + pg_stream_t *s; + uword *p; - if (! pg->stream_index_by_name) + if (!pg->stream_index_by_name) pg->stream_index_by_name = hash_create_vec (0, sizeof (s->name[0]), sizeof (uword)); @@ -361,7 +366,7 @@ void pg_stream_add (pg_main_t * pg, pg_stream_t * s_init) s[0] = s_init[0]; /* Give it a name. */ - if (! s->name) + if (!s->name) s->name = format (0, "stream%d", s - pg->streams); else s->name = vec_dup (s->name); @@ -384,18 +389,19 @@ void pg_stream_add (pg_main_t * pg, pg_stream_t * s_init) default: /* Get packet size from fixed edits. */ s->packet_size_edit_type = PG_EDIT_FIXED; - if (! s->replay_packet_templates) - s->min_packet_bytes = s->max_packet_bytes = vec_len (s->fixed_packet_data); + if (!s->replay_packet_templates) + s->min_packet_bytes = s->max_packet_bytes = + vec_len (s->fixed_packet_data); break; } s->last_increment_packet_size = s->min_packet_bytes; { - pg_buffer_index_t * bi; + pg_buffer_index_t *bi; int n; - if (! s->buffer_bytes) + if (!s->buffer_bytes) s->buffer_bytes = s->max_packet_bytes; s->buffer_bytes = vlib_buffer_round_size (s->buffer_bytes); @@ -409,32 +415,35 @@ void pg_stream_add (pg_main_t * pg, pg_stream_t * s_init) bi->free_list_index = vlib_buffer_create_free_list (vm, s->buffer_bytes, "pg stream %d buffer #%d", s - pg->streams, - 1 + (bi - s->buffer_indices)); + 1 + (bi - + s-> + buffer_indices)); } /* Find an interface to use. */ s->pg_if_index = pg_interface_add_or_get (pg, s->if_id); { - pg_interface_t * pi = pool_elt_at_index (pg->interfaces, s->pg_if_index); + pg_interface_t *pi = pool_elt_at_index (pg->interfaces, s->pg_if_index); vlib_rx_or_tx_t rx_or_tx; vlib_foreach_rx_tx (rx_or_tx) - { - if (s->sw_if_index[rx_or_tx] == ~0) - s->sw_if_index[rx_or_tx] = pi->sw_if_index; - } + { + if (s->sw_if_index[rx_or_tx] == ~0) + s->sw_if_index[rx_or_tx] = pi->sw_if_index; + } } /* Connect the graph. */ s->next_index = vlib_node_add_next (vm, pg_input_node.index, s->node_index); } -void pg_stream_del (pg_main_t * pg, uword index) +void +pg_stream_del (pg_main_t * pg, uword index) { - vlib_main_t * vm = pg->vlib_main; - pg_stream_t * s; - pg_buffer_index_t * bi; + vlib_main_t *vm = pg->vlib_main; + pg_stream_t *s; + pg_buffer_index_t *bi; s = pool_elt_at_index (pg->streams, index); @@ -442,12 +451,20 @@ void pg_stream_del (pg_main_t * pg, uword index) hash_unset_mem (pg->stream_index_by_name, s->name); vec_foreach (bi, s->buffer_indices) - { - vlib_buffer_delete_free_list (vm, bi->free_list_index); - clib_fifo_free (bi->buffer_fifo); - } + { + vlib_buffer_delete_free_list (vm, bi->free_list_index); + clib_fifo_free (bi->buffer_fifo); + } pg_stream_free (s); pool_put (pg->streams, s); } + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ |