Skip to contentSkip to conversation

Add support for VXLAN and NVGRE encap as a sample actions

PATCH Superseded Salem Sol 1 participant 8 messages Mar 15, 2021 Network drivers

v1 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Salem Sol

author
#0 lore raw

cover Add support for VXLAN and NVGRE encap as a sample actions

This series adds support for VXLAN and NVGRE encap as a sample actions with the proper documentation, this series depends on [1] for the documentation part.

[1] http://patches.dpdk.org/project/dpdk/patch/[email protected]/

Jiawei Wang (1):
app/testpmd: store VXLAN/NVGRE encap data globally

Salem Sol (6):
net/mlx5: support VXLAN encap action in sample net/mlx5: support NVGRE encap action in sample app/testpmd: support VXLAN encap for sample action app/testpmd: support NVGRE encap for sample action
doc: update sample actions support in testpmd guide
doc: update sample actions support in mlx5 guide

 app/test-pmd/cmdline_flow.c                 | 90 ++++++++++++++-------
 doc/guides/nics/mlx5.rst                    |  4 +-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 21 +++++
 drivers/net/mlx5/mlx5_flow_dv.c             | 13 +++
 4 files changed, 99 insertions(+), 29 deletions(-)
Signature · 1 line
2.21.0
author
#1 lore raw

PATCH 1/7 app/testpmd: store VXLAN/NVGRE encap data globally

From: Jiawei Wang <[email protected]>

With the current code the VXLAN/NVGRE parsing routine stored the configuration of the header on stack, this might lead to overwriting the data on the stack.

This patch stores the external data of vxlan and nvgre encap into global data as a pre-step to supporting vxlan and nvgre encap as a sample actions.

---
 app/test-pmd/cmdline_flow.c | 76 ++++++++++++++++++++++++-------------
 1 file changed, 49 insertions(+), 27 deletions(-)
app/test-pmd/cmdline_flow.c +49 -27
index 49d9f9c043..84676a2e45 100644
@@ -5244,31 +5244,14 @@ parse_vc_action_rss_queue(struct context *ctx, const struct token *token,
 	return len;
 }
 
-/** Parse VXLAN encap action. */
+/** Setup VXLAN encap configuration. */
 static int
-parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
-			    const char *str, unsigned int len,
-			    void *buf, unsigned int size)
+parse_setup_vxlan_encap_data
+		(struct action_vxlan_encap_data *action_vxlan_encap_data)
 {
-	struct buffer *out = buf;
-	struct rte_flow_action *action;
-	struct action_vxlan_encap_data *action_vxlan_encap_data;
-	int ret;
-
-	ret = parse_vc(ctx, token, str, len, buf, size);
-	if (ret < 0)
-		return ret;
-	/* Nothing else to do if there is no buffer. */
-	if (!out)
-		return ret;
-	if (!out->args.vc.actions_n)
+	if (!action_vxlan_encap_data)
 		return -1;
-	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
-	/* Point to selected object. */
-	ctx->object = out->args.vc.data;
-	ctx->objmask = NULL;
 	/* Set up default configuration. */
-	action_vxlan_encap_data = ctx->object;
 	*action_vxlan_encap_data = (struct action_vxlan_encap_data){
 		.conf = (struct rte_flow_action_vxlan_encap){
 			.definition = action_vxlan_encap_data->items,
@@ -5372,19 +5355,18 @@ parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
 	}
 	memcpy(action_vxlan_encap_data->item_vxlan.vni, vxlan_encap_conf.vni,
 	       RTE_DIM(vxlan_encap_conf.vni));
-	action->conf = &action_vxlan_encap_data->conf;
-	return ret;
+	return 0;
 }
 
-/** Parse NVGRE encap action. */
+/** Parse VXLAN encap action. */
 static int
-parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
+parse_vc_action_vxlan_encap(struct context *ctx, const struct token *token,
 			    const char *str, unsigned int len,
 			    void *buf, unsigned int size)
 {
 	struct buffer *out = buf;
 	struct rte_flow_action *action;
-	struct action_nvgre_encap_data *action_nvgre_encap_data;
+	struct action_vxlan_encap_data *action_vxlan_encap_data;
 	int ret;
 
 	ret = parse_vc(ctx, token, str, len, buf, size);
@@ -5399,8 +5381,20 @@ parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
 	/* Point to selected object. */
 	ctx->object = out->args.vc.data;
 	ctx->objmask = NULL;
+	action_vxlan_encap_data = ctx->object;
+	parse_setup_vxlan_encap_data(action_vxlan_encap_data);
+	action->conf = &action_vxlan_encap_data->conf;
+	return ret;
+}
+
+/** Setup NVGRE encap configuration. */
+static int
+parse_setup_nvgre_encap_data
+		(struct action_nvgre_encap_data *action_nvgre_encap_data)
+{
+	if (!action_nvgre_encap_data)
+		return -1;
 	/* Set up default configuration. */
-	action_nvgre_encap_data = ctx->object;
 	*action_nvgre_encap_data = (struct action_nvgre_encap_data){
 		.conf = (struct rte_flow_action_nvgre_encap){
 			.definition = action_nvgre_encap_data->items,
@@ -5463,6 +5457,34 @@ parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
 			RTE_FLOW_ITEM_TYPE_VOID;
 	memcpy(action_nvgre_encap_data->item_nvgre.tni, nvgre_encap_conf.tni,
 	       RTE_DIM(nvgre_encap_conf.tni));
+	return 0;
+}
+
+/** Parse NVGRE encap action. */
+static int
+parse_vc_action_nvgre_encap(struct context *ctx, const struct token *token,
+			    const char *str, unsigned int len,
+			    void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+	struct rte_flow_action *action;
+	struct action_nvgre_encap_data *action_nvgre_encap_data;
+	int ret;
+
+	ret = parse_vc(ctx, token, str, len, buf, size);
+	if (ret < 0)
+		return ret;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return ret;
+	if (!out->args.vc.actions_n)
+		return -1;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	/* Point to selected object. */
+	ctx->object = out->args.vc.data;
+	ctx->objmask = NULL;
+	action_nvgre_encap_data = ctx->object;
+	parse_setup_nvgre_encap_data(action_nvgre_encap_data);
 	action->conf = &action_nvgre_encap_data->conf;
 	return ret;
 }
Signature · 1 line
2.21.0
author
#2 lore raw

PATCH 2/7 net/mlx5: support VXLAN encap action in sample

In reply to Salem Sol

Add support for VXLAN encap as a sample action
and validate it.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +11 -0
index 1a74d5ac2b..4b2db47e39 100644
@@ -5242,6 +5242,16 @@ flow_dv_validate_action_sample(uint64_t *action_flags,
 				return ret;
 			++actions_n;
 			break;
+		case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
+			ret = flow_dv_validate_action_l2_encap(dev,
+							       sub_action_flags,
+							       act, attr,
+							       error);
+			if (ret < 0)
+				return ret;
+			sub_action_flags |= MLX5_FLOW_ACTION_ENCAP;
+			++actions_n;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ACTION,
@@ -10407,6 +10417,7 @@ flow_dv_translate_action_sample(struct rte_eth_dev *dev,
 			action_flags |= MLX5_FLOW_ACTION_PORT_ID;
 			break;
 		}
+		case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
 		case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
 			/* Save the encap resource before sample */
 			pre_rix = dev_flow->handle->dvh.rix_encap_decap;
Signature · 1 line
2.21.0
author
#3 lore raw

PATCH 3/7 net/mlx5: support NVGRE encap action in sample

In reply to Salem Sol

Add support for NVGRE encap as a sample action
and validate it.

---
 drivers/net/mlx5/mlx5_flow_dv.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/mlx5/mlx5_flow_dv.c +2 -0
index 4b2db47e39..590abdc822 100644
@@ -5243,6 +5243,7 @@ flow_dv_validate_action_sample(uint64_t *action_flags,
 			++actions_n;
 			break;
 		case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
+		case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
 			ret = flow_dv_validate_action_l2_encap(dev,
 							       sub_action_flags,
 							       act, attr,
@@ -10418,6 +10419,7 @@ flow_dv_translate_action_sample(struct rte_eth_dev *dev,
 			break;
 		}
 		case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
+		case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
 		case RTE_FLOW_ACTION_TYPE_RAW_ENCAP:
 			/* Save the encap resource before sample */
 			pre_rix = dev_flow->handle->dvh.rix_encap_decap;
Signature · 1 line
2.21.0
author
#4 lore raw

PATCH 4/7 app/testpmd: support VXLAN encap for sample action

In reply to Salem Sol

Add support for rte_flow_action_vxlan_encap as a sample action.

The example of test-pmd command:

1. set vxlan ip-version ... vni ... udp-src ...
set raw_encap 1 eth src.../ ipv4.../...
set sample_actions 2 vxlan_encap / port_id id 0 / end flow create 0 ... pattern eth / end actions
sample ratio 1 index 2 / raw_encap index 1 / port_id id 0...

The flow will result in all the matched egress packets will be encapsulated and sent to wire, and also mirrored the packets using VXLAN encapsulation data and sent to wire.

---
 app/test-pmd/cmdline_flow.c | 7 +++++++
 1 file changed, 7 insertions(+)
app/test-pmd/cmdline_flow.c +7 -0
index 84676a2e45..61dfaab8fd 100644
@@ -582,6 +582,7 @@ struct rte_flow_action_queue sample_queue[RAW_SAMPLE_CONFS_MAX_NUM];
 struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM];
 struct rte_flow_action_port_id sample_port_id[RAW_SAMPLE_CONFS_MAX_NUM];
 struct rte_flow_action_raw_encap sample_encap[RAW_SAMPLE_CONFS_MAX_NUM];
+struct action_vxlan_encap_data sample_vxlan_encap[RAW_SAMPLE_CONFS_MAX_NUM];
 struct action_rss_data sample_rss_data[RAW_SAMPLE_CONFS_MAX_NUM];
 struct rte_flow_action_vf sample_vf[RAW_SAMPLE_CONFS_MAX_NUM];
 
@@ -1615,6 +1616,7 @@ static const enum index next_action_sample[] = {
 	ACTION_COUNT,
 	ACTION_PORT_ID,
 	ACTION_RAW_ENCAP,
+	ACTION_VXLAN_ENCAP,
 	ACTION_NEXT,
 	ZERO,
 };
@@ -7949,6 +7951,11 @@ cmd_set_raw_parsed_sample(const struct buffer *in)
 					(const void *)action->conf, size);
 			action->conf = &sample_vf[idx];
 			break;
+		case RTE_FLOW_ACTION_TYPE_VXLAN_ENCAP:
+			size = sizeof(struct rte_flow_action_vxlan_encap);
+			parse_setup_vxlan_encap_data(&sample_vxlan_encap[idx]);
+			action->conf = &sample_vxlan_encap[idx].conf;
+			break;
 		default:
 			printf("Error - Not supported action\n");
 			return;
Signature · 1 line
2.21.0
author
#5 lore raw

PATCH 5/7 app/testpmd: support NVGRE encap for sample action

In reply to Salem Sol

Add support for rte_flow_action_nvge_encap as a sample action.

The example of test-pmd command:

1. set nvgre ip-version ... tni ... ip-src ... ip-dst ... set raw_encap 1 eth src... / ipv4... /...
set sample_actions 2 nvgre / port_id id 0 / end
flow create 0 ... pattern eth / end actions
sample ratio 1 index 2 / raw_encap index 1 / port_id id 0...

The flow will result in all the matched egress packets will be encapsulated and sent to wire, and also mirrored the packets using NVGRE encapsulation data and sent to wire.

---
 app/test-pmd/cmdline_flow.c | 7 +++++++
 1 file changed, 7 insertions(+)
app/test-pmd/cmdline_flow.c +7 -0
index 61dfaab8fd..0e33410005 100644
@@ -583,6 +583,7 @@ struct rte_flow_action_count sample_count[RAW_SAMPLE_CONFS_MAX_NUM];
 struct rte_flow_action_port_id sample_port_id[RAW_SAMPLE_CONFS_MAX_NUM];
 struct rte_flow_action_raw_encap sample_encap[RAW_SAMPLE_CONFS_MAX_NUM];
 struct action_vxlan_encap_data sample_vxlan_encap[RAW_SAMPLE_CONFS_MAX_NUM];
+struct action_nvgre_encap_data sample_nvgre_encap[RAW_SAMPLE_CONFS_MAX_NUM];
 struct action_rss_data sample_rss_data[RAW_SAMPLE_CONFS_MAX_NUM];
 struct rte_flow_action_vf sample_vf[RAW_SAMPLE_CONFS_MAX_NUM];
 
@@ -1617,6 +1618,7 @@ static const enum index next_action_sample[] = {
 	ACTION_PORT_ID,
 	ACTION_RAW_ENCAP,
 	ACTION_VXLAN_ENCAP,
+	ACTION_NVGRE_ENCAP,
 	ACTION_NEXT,
 	ZERO,
 };
@@ -7956,6 +7958,11 @@ cmd_set_raw_parsed_sample(const struct buffer *in)
 			parse_setup_vxlan_encap_data(&sample_vxlan_encap[idx]);
 			action->conf = &sample_vxlan_encap[idx].conf;
 			break;
+		case RTE_FLOW_ACTION_TYPE_NVGRE_ENCAP:
+			size = sizeof(struct rte_flow_action_nvgre_encap);
+			parse_setup_nvgre_encap_data(&sample_nvgre_encap[idx]);
+			action->conf = &sample_nvgre_encap[idx];
+			break;
 		default:
 			printf("Error - Not supported action\n");
 			return;
Signature · 1 line
2.21.0
author
#6 lore raw

PATCH 6/7 doc: update sample actions support in testpmd guide

In reply to Salem Sol

Update documentation for sample action usage in testpmd utilizing rte_flow_action_vxlan_encap and rte_flow_action_nvgre_encap and show the command line example.

---
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)
doc/guides/testpmd_app_ug/testpmd_funcs.rst +21 -0
index 3a31cc6237..5e40c9bc1c 100644
@@ -4900,6 +4900,27 @@ and also mirrored the packets with encapsulation header and sent to port id 0.
  testpmd> set sample_actions 0 raw_encap / port_id id 0 / end
  testpmd> flow create 0 ingress transfer pattern eth / end actions
         sample ratio 1 index 0  / port_id id 2 / end
+E-Switch Mirroring rule, the matched ingress packets are sent to port id 2,
+and also mirrored the packets with VXLAN encapsulation header and sent to port id 0.
+
+::
+
+ testpmd> set vxlan ip-version ipv4 vni 4 udp-src 4 udp-dst 4 ip-src 127.0.0.1
+        ip-dst 128.0.0.1 eth-src 11:11:11:11:11:11 eth-dst 22:22:22:22:22:22
+ testpmd> set sample_actions 0 vxlan_encap / port_id id 0 / end
+ testpmd> flow create 0 ingress transfer pattern eth / end actions
+        sample ratio 1 index 0  / port_id id 2 / end
+
+E-Switch Mirroring rule, the matched ingress packets are sent to port id 2,
+and also mirrored the packets with NVGRE encapsulation header and sent to port id 0.
+
+::
+
+ testpmd> set nvgre ip-version ipv4 tni 4 ip-src 127.0.0.1 ip-dst 128.0.0.1
+        eth-src 11:11:11:11:11:11 eth-dst 22:22:22:22:22:22
+ testpmd> set sample_actions 0 nvgre_encap / port_id id 0 / end
+ testpmd> flow create 0 ingress transfer pattern eth / end actions
+        sample ratio 1 index 0  / port_id id 2 / end
 
 BPF Functions
 --------------
Signature · 1 line
2.21.0
author
#7 lore raw

PATCH 7/7 doc: update sample actions support in mlx5 guide

In reply to Salem Sol

Updates the documentation with the added support for sample actions VXLAN and NVGRE encap in E-Switch steering flow.

---
 doc/guides/nics/mlx5.rst | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
doc/guides/nics/mlx5.rst +2 -2
index 96fce36e3c..378b7202d9 100644
@@ -376,8 +376,8 @@ Limitations
     encapsulation actions.
   - For NIC Rx flow, supports ``MARK``, ``COUNT``, ``QUEUE``, ``RSS`` in the
     sample actions list.
-  - For E-Switch mirroring flow, supports ``RAW ENCAP``, ``Port ID`` in the
-    sample actions list.
+  - For E-Switch mirroring flow, supports ``RAW ENCAP``, ``Port ID``,
+    ``VXLAN ENCAP``, ``NVGRE ENCAP`` in the sample actions list.
 
 - Modify Field flow:
 
Signature · 1 line
2.21.0