aboutsummaryrefslogtreecommitdiffstats
path: root/src/vnet/pg
diff options
context:
space:
mode:
authorMohsin Kazmi <sykazmi@cisco.com>2019-07-23 11:54:48 +0200
committerNeale Ranns <nranns@cisco.com>2019-07-28 14:20:06 +0000
commit22e9cfd760be613f33a4135e9247729b64619cc6 (patch)
tree81c6c66f0729202b71fa9b7748b405f4489f3f5a /src/vnet/pg
parentbe83704c5b1482dfd2ba38423662a9da5a8d8f81 (diff)
pg: add GSO support
Type: feature Change-Id: I72676495a85fbecc946aa266a75234cce70c3a5e Signed-off-by: Mohsin Kazmi <sykazmi@cisco.com>
Diffstat (limited to 'src/vnet/pg')
-rw-r--r--src/vnet/pg/cli.c18
-rw-r--r--src/vnet/pg/input.c73
-rw-r--r--src/vnet/pg/pg.api6
-rw-r--r--src/vnet/pg/pg.h5
-rw-r--r--src/vnet/pg/pg_api.c4
-rw-r--r--src/vnet/pg/stream.c14
6 files changed, 109 insertions, 11 deletions
diff --git a/src/vnet/pg/cli.c b/src/vnet/pg/cli.c
index 8f82ac1c1f7..a8451d74e1e 100644
--- a/src/vnet/pg/cli.c
+++ b/src/vnet/pg/cli.c
@@ -649,7 +649,7 @@ create_pg_if_cmd_fn (vlib_main_t * vm,
{
pg_main_t *pg = &pg_main;
unformat_input_t _line_input, *line_input = &_line_input;
- u32 if_id;
+ u32 if_id, gso_enabled = 0, gso_size = 0;
clib_error_t *error = NULL;
if (!unformat_user (input, unformat_line_input, line_input))
@@ -659,7 +659,17 @@ create_pg_if_cmd_fn (vlib_main_t * vm,
{
if (unformat (line_input, "interface pg%u", &if_id))
;
-
+ else if (unformat (line_input, "gso-enabled"))
+ {
+ gso_enabled = 1;
+ if (unformat (line_input, "gso-size %u", &gso_size))
+ ;
+ else
+ {
+ error = clib_error_create ("gso enabled but gso size missing");
+ goto done;
+ }
+ }
else
{
error = clib_error_create ("unknown input `%U'",
@@ -668,7 +678,7 @@ create_pg_if_cmd_fn (vlib_main_t * vm,
}
}
- pg_interface_add_or_get (pg, if_id);
+ pg_interface_add_or_get (pg, if_id, gso_enabled, gso_size);
done:
unformat_free (line_input);
@@ -679,7 +689,7 @@ done:
/* *INDENT-OFF* */
VLIB_CLI_COMMAND (create_pg_if_cmd, static) = {
.path = "create packet-generator",
- .short_help = "create packet-generator interface <interface name>",
+ .short_help = "create packet-generator interface <interface name> [gso-enabled gso-size <size>]",
.function = create_pg_if_cmd_fn,
};
/* *INDENT-ON* */
diff --git a/src/vnet/pg/input.c b/src/vnet/pg/input.c
index 2d850e939b0..151624fe00f 100644
--- a/src/vnet/pg/input.c
+++ b/src/vnet/pg/input.c
@@ -50,6 +50,9 @@
#include <vnet/vnet.h>
#include <vnet/ethernet/ethernet.h>
#include <vnet/feature/feature.h>
+#include <vnet/ip/ip4_packet.h>
+#include <vnet/ip/ip6_packet.h>
+#include <vnet/udp/udp_packet.h>
#include <vnet/devices/devices.h>
static int
@@ -1523,6 +1526,70 @@ pg_input_trace (pg_main_t * pg,
}
}
+static_always_inline void
+fill_gso_buffer_flags (vlib_main_t * vm, u32 * buffers, u32 n_buffers,
+ u32 packet_data_size)
+{
+
+ for (int i = 0; i < n_buffers; i++)
+ {
+ vlib_buffer_t *b0 = vlib_get_buffer (vm, buffers[i]);
+ u8 l4_proto = 0;
+ u8 l4_hdr_sz = 0;
+
+ ethernet_header_t *eh = (ethernet_header_t *) b0->data;
+ u16 ethertype = clib_net_to_host_u16 (eh->type);
+ u16 l2hdr_sz = sizeof (ethernet_header_t);
+
+ vnet_buffer (b0)->l2_hdr_offset = 0;
+ vnet_buffer (b0)->l3_hdr_offset = l2hdr_sz;
+ if (PREDICT_TRUE (ethertype == ETHERNET_TYPE_IP4))
+ {
+ ip4_header_t *ip4 = (ip4_header_t *) (b0->data + l2hdr_sz);
+ vnet_buffer (b0)->l4_hdr_offset = l2hdr_sz + ip4_header_bytes (ip4);
+ l4_proto = ip4->protocol;
+ b0->flags |=
+ (VNET_BUFFER_F_IS_IP4 | VNET_BUFFER_F_L2_HDR_OFFSET_VALID
+ | VNET_BUFFER_F_L3_HDR_OFFSET_VALID |
+ VNET_BUFFER_F_L4_HDR_OFFSET_VALID);
+ b0->flags |= VNET_BUFFER_F_OFFLOAD_IP_CKSUM;
+ }
+ else if (PREDICT_TRUE (ethertype == ETHERNET_TYPE_IP6))
+ {
+ ip6_header_t *ip6 = (ip6_header_t *) (b0->data + l2hdr_sz);
+ /* FIXME IPv6 EH traversal */
+ vnet_buffer (b0)->l4_hdr_offset = l2hdr_sz + sizeof (ip6_header_t);
+ l4_proto = ip6->protocol;
+ b0->flags |=
+ (VNET_BUFFER_F_IS_IP6 | VNET_BUFFER_F_L2_HDR_OFFSET_VALID
+ | VNET_BUFFER_F_L3_HDR_OFFSET_VALID |
+ VNET_BUFFER_F_L4_HDR_OFFSET_VALID);
+ b0->flags |= VNET_BUFFER_F_OFFLOAD_IP_CKSUM;
+ }
+ if (l4_proto == IP_PROTOCOL_TCP)
+ {
+ b0->flags |= VNET_BUFFER_F_OFFLOAD_TCP_CKSUM;
+ tcp_header_t *tcp = (tcp_header_t *) (b0->data +
+ vnet_buffer
+ (b0)->l4_hdr_offset);
+ l4_hdr_sz = tcp_header_bytes (tcp);
+ tcp->checksum = 0;
+ vnet_buffer2 (b0)->gso_l4_hdr_sz = l4_hdr_sz;
+ vnet_buffer2 (b0)->gso_size = packet_data_size;
+ b0->flags |= VNET_BUFFER_F_GSO;
+ }
+ else if (l4_proto == IP_PROTOCOL_UDP)
+ {
+ b0->flags |= VNET_BUFFER_F_OFFLOAD_UDP_CKSUM;
+ udp_header_t *udp = (udp_header_t *) (b0->data +
+ vnet_buffer
+ (b0)->l4_hdr_offset);
+ vnet_buffer2 (b0)->gso_l4_hdr_sz = sizeof (*udp);
+ udp->checksum = 0;
+ }
+ }
+}
+
static uword
pg_generate_packets (vlib_node_runtime_t * node,
pg_main_t * pg,
@@ -1538,6 +1605,7 @@ pg_generate_packets (vlib_node_runtime_t * node,
u8 feature_arc_index = fm->device_input_feature_arc_index;
cm = &fm->feature_config_mains[feature_arc_index];
u32 current_config_index = ~(u32) 0;
+ pg_interface_t *pi = pool_elt_at_index (pg->interfaces, s->pg_if_index);
int i;
bi0 = s->buffer_indices;
@@ -1564,14 +1632,12 @@ pg_generate_packets (vlib_node_runtime_t * node,
vlib_next_frame_t *nf;
vlib_frame_t *f;
ethernet_input_frame_t *ef;
- pg_interface_t *pi;
vlib_get_new_next_frame (vm, node, next_index, to_next, n_left);
nf = vlib_node_runtime_get_next_frame (vm, node, next_index);
f = vlib_get_frame (vm, nf->frame);
f->flags = ETH_INPUT_FRAME_F_SINGLE_SW_IF_IDX;
ef = vlib_frame_scalar_args (f);
- pi = pool_elt_at_index (pg->interfaces, s->pg_if_index);
ef->sw_if_index = pi->sw_if_index;
ef->hw_if_index = pi->hw_if_index;
vlib_frame_no_append (f);
@@ -1615,6 +1681,9 @@ pg_generate_packets (vlib_node_runtime_t * node,
vnet_buffer (b)->feature_arc_index = feature_arc_index;
}
+ if (pi->gso_enabled)
+ fill_gso_buffer_flags (vm, to_next, n_this_frame, pi->gso_size);
+
n_trace = vlib_get_trace_count (vm, node);
if (n_trace > 0)
{
diff --git a/src/vnet/pg/pg.api b/src/vnet/pg/pg.api
index 8f986cbc5ed..6a421e45d7d 100644
--- a/src/vnet/pg/pg.api
+++ b/src/vnet/pg/pg.api
@@ -18,18 +18,22 @@
This file defines packet-generator interface APIs.
*/
-option version = "1.0.0";
+option version = "1.1.0";
/** \brief PacketGenerator create interface request
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param interface_id - interface index
+ @param enable_gso - enable gso on this interface
+ @param gso_size - gso size on this interface
*/
define pg_create_interface
{
u32 client_index;
u32 context;
u32 interface_id;
+ u8 gso_enabled;
+ u32 gso_size;
};
/** \brief PacketGenerator create interface response
diff --git a/src/vnet/pg/pg.h b/src/vnet/pg/pg.h
index c0e000fe7b2..aef7a5bbf71 100644
--- a/src/vnet/pg/pg.h
+++ b/src/vnet/pg/pg.h
@@ -299,6 +299,8 @@ typedef struct
/* Identifies stream for this interface. */
u32 id;
+ u8 gso_enabled;
+ u32 gso_size;
pcap_main_t pcap_main;
u8 *pcap_file_name;
} pg_interface_t;
@@ -351,7 +353,8 @@ 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);
+u32 pg_interface_add_or_get (pg_main_t * pg, uword stream_index,
+ u8 gso_enabled, u32 gso_size);
always_inline pg_node_t *
pg_get_node (uword node_index)
diff --git a/src/vnet/pg/pg_api.c b/src/vnet/pg/pg_api.c
index 7775343a6f5..f4b9604bfd4 100644
--- a/src/vnet/pg/pg_api.c
+++ b/src/vnet/pg/pg_api.c
@@ -53,7 +53,9 @@ vl_api_pg_create_interface_t_handler (vl_api_pg_create_interface_t * mp)
int rv = 0;
pg_main_t *pg = &pg_main;
- u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id));
+ u32 pg_if_id = pg_interface_add_or_get (pg, ntohl (mp->interface_id),
+ mp->gso_enabled,
+ ntohl (mp->gso_size));
pg_interface_t *pi = pool_elt_at_index (pg->interfaces, pg_if_id);
/* *INDENT-OFF* */
diff --git a/src/vnet/pg/stream.c b/src/vnet/pg/stream.c
index 64fe7c859ae..c4a57ea702d 100644
--- a/src/vnet/pg/stream.c
+++ b/src/vnet/pg/stream.c
@@ -179,7 +179,8 @@ pg_eth_flag_change (vnet_main_t * vnm, vnet_hw_interface_t * hi, u32 flags)
}
u32
-pg_interface_add_or_get (pg_main_t * pg, uword if_id)
+pg_interface_add_or_get (pg_main_t * pg, uword if_id, u8 gso_enabled,
+ u32 gso_size)
{
vnet_main_t *vnm = vnet_get_main ();
vlib_main_t *vm = vlib_get_main ();
@@ -213,6 +214,13 @@ pg_interface_add_or_get (pg_main_t * pg, uword if_id)
ethernet_register_interface (vnm, pg_dev_class.index, i, hw_addr,
&pi->hw_if_index, pg_eth_flag_change);
hi = vnet_get_hw_interface (vnm, pi->hw_if_index);
+ if (gso_enabled)
+ {
+ hi->flags |= VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO;
+ vnm->interface_main.gso_interface_count++;
+ pi->gso_enabled = 1;
+ pi->gso_size = gso_size;
+ }
pi->sw_if_index = hi->sw_if_index;
hash_set (pg->if_index_by_if_id, if_id, i);
@@ -445,7 +453,9 @@ pg_stream_add (pg_main_t * pg, pg_stream_t * s_init)
}
/* Find an interface to use. */
- s->pg_if_index = pg_interface_add_or_get (pg, s->if_id);
+ s->pg_if_index =
+ pg_interface_add_or_get (pg, s->if_id, 0 /* gso_enabled */ ,
+ 0 /* gso_size */ );
if (s->sw_if_index[VLIB_RX] == ~0)
{