Skip to contentSkip to conversation

ethdev: tunnel offload model

PATCH In review Gregory Etelson 14 participants 95 messages Jun 25, 2020 – Mar 8, 2021 2 messages not in the archive Network drivers Page 1 of 2

lore
Share & tools
lore
#0 lore raw

cover ethdev: tunnel offload model

Hardware vendors implement tunneled traffic offload techniques differently. Although RTE flow API provides tools capable to offload all sorts of network stacks, software application must reference this hardware differences in flow rules compilation. As the result tunneled traffic flow rules that utilize hardware capabilities can be different for the same traffic.

Tunnel port offload proposed in [1] provides software application with unified rules model for tunneled traffic regardless underlying hardware.
- The model introduces a concept of a virtual tunnel port (VTP).
- The model uses VTP to offload ingress tunneled network traffic with RTE flow rules.
- The model is implemented as set of helper functions. Each PMD implements VTP offload according to underlying hardware offload capabilities. Applications must query PMD for VTP flow items / actions before using in creation of a VTP flow rule.

The model components:
- Virtual Tunnel Port (VTP) is a stateless software object that describes tunneled network traffic. VTP object usually contains descriptions of outer headers, tunnel headers and inner headers.
- Tunnel Steering flow Rule (TSR) detects tunneled packets and delegates them to tunnel processing infrastructure, implemented in PMD for optimal hardware utilization, for further processing.
- Tunnel Matching flow Rule (TMR) verifies packet configuration and runs offload actions in case of a match.

Application actions:
1 Initialize VTP object according to tunnel
network parameters.
2 Create TSR flow rule:
2.1 Query PMD for VTP actions: application can query for VTP actions
more than once
int
rte_flow_tunnel_decap_set(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_action **pmd_actions, uint32_t *num_of_pmd_actions, struct rte_flow_error *error);

2.2 Integrate PMD actions into TSR actions list. 2.3 Create TSR flow rule:
flow create <port> group 0
match {tunnel items} / end
actions {PMD actions} / {App actions} / end

3 Create TMR flow rule:
3.1 Query PMD for VTP items: application can query for VTP items
more than once
int
rte_flow_tunnel_match(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_item **pmd_items, uint32_t *num_of_pmd_items, struct rte_flow_error *error);

3.2 Integrate PMD items into TMR items list:
3.3 Create TMR flow rule
flow create <port> group 0
match {PMD items} / {APP items} / end
actions {offload actions} / end

The model provides helper function call to restore packets that miss tunnel TMR rules to its original state:
int
rte_flow_get_restore_info(uint16_t port_id,
struct rte_mbuf *mbuf,
struct rte_flow_restore_info *info, struct rte_flow_error *error);

rte_tunnel object filled by the call inside rte_flow_restore_info *info parameter can be used by the application to create new TMR rule for that tunnel.

The model requirements:
Software application must initialize rte_tunnel object with tunnel parameters before calling rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().

PMD actions array obtained in rte_flow_tunnel_decap_set() must be released by application with rte_flow_action_release() call. Application can release the actionsfter TSR rule was created.

PMD items array obtained with rte_flow_tunnel_match() must be released by application with rte_flow_item_release() call. Application can release the items after rule was created. However, if the application needs to create additional TMR rule for the same tunnel it will need to obtain PMD items again.

Application cannot destroy rte_tunnel object before it releases all PMD actions & PMD items referencing that tunnel.

[1] https://mails.dpdk.org/archives/dev/2020-June/169656.html

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (1):
ethdev: allow negative values in flow rule types

 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 142 +++++++++++++++-
 lib/librte_ethdev/rte_flow.h             | 196 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 5 files changed, 474 insertions(+), 6 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 ethdev: allow negative values in flow rule types

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

---
 lib/librte_ethdev/rte_flow.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
lib/librte_ethdev/rte_flow.c +24 -6
index 1685be5f73..c19d25649f 100644
@@ -563,7 +563,12 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (uint32_t)item->type <= INT_MAX ?
+			rte_flow_desc_item[item->type].size :
+			sizeof(void *);
 		rte_memcpy(buf, data, (size > off ? off : size));
 		break;
 	}
@@ -666,7 +671,12 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_action[action->type].size;
+		/**
+		 * allow PMD private flow action
+		 */
+		off = (uint32_t)action->type <= INT_MAX ?
+			rte_flow_desc_action[action->type].size :
+			sizeof(void *);
 		rte_memcpy(buf, action->conf, (size > off ? off : size));
 		break;
 	}
@@ -708,8 +718,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-		    !rte_flow_desc_item[src->type].name)
+		/**
+		 * allow PMD private flow item
+		 */
+		if (((uint32_t)src->type <= INT_MAX) &&
+			((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+		    !rte_flow_desc_item[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
 				 "cannot convert unknown item type");
@@ -797,8 +811,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-		    !rte_flow_desc_action[src->type].name)
+		/**
+		 * allow PMD private flow action
+		 */
+		if (((uint32_t)src->type <= INT_MAX) &&
+		    ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+		    !rte_flow_desc_action[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
 				 src, "cannot convert unknown action type");
Signature · 1 line
2.25.1
#2 lore raw

Re: [dpdk-dev] [PATCH 1/2] ethdev: allow negative values in flow rule types

Quoted 20 lines · Gregory Etelson

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

---
 lib/librte_ethdev/rte_flow.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
lib/librte_ethdev/rte_flow.c +0 -0
index 1685be5f73..c19d25649f 100644

lib/librte_ethdev/rte_flow.c rte_flow_conv_item_spec(void *buf, const size_t size, · line 571

Quoted 10 lines
lib/librte_ethdev/rte_flow.c +6 -1
@@ -563,7 +563,12 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (uint32_t)item->type <= INT_MAX ?
+			rte_flow_desc_item[item->type].size :
+			sizeof(void *);

May be it is out-of-scope of the patch (strictly speaking), but usage of 'off' variable is very misleading here. It is not used as an offset. It is used as a size to copy.

Also it is absolutely unclear why sizeof(void *) is a right size for PMD private flow items.

#3 lore raw

Re: [dpdk-dev] [PATCH 1/2] ethdev: allow negative values in flow rule types

Quoted 31 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Sunday, July 5, 2020 16:34
To: Gregory Etelson <[email protected]>; [email protected]
Cc: Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Ori Kam <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 1/2] ethdev: allow negative values in flow rule types

lib/librte_ethdev/rte_flow.c rte_flow_conv_item_spec(void *buf, const size_t

Quoted 20 lines · Gregory Etelson

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

---
 lib/librte_ethdev/rte_flow.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.c index 1685be5f73..c19d25649f 100644

lib/librte_ethdev/rte_flow.c +0 -0
@@ -563,7 +563,12 @@ rte_flow_conv_item_spec(void *buf, const size_t

size,

Quoted 15 lines

lib/librte_ethdev/rte_flow.c rte_flow_conv_item_spec(void *buf, const size_t size, · line 571

Quoted 10 lines
lib/librte_ethdev/rte_flow.c +6 -1
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (uint32_t)item->type <= INT_MAX ?
+			rte_flow_desc_item[item->type].size :
+			sizeof(void *);

May be it is out-of-scope of the patch (strictly speaking), but usage of 'off' variable is very misleading here. It is not used as an offset. It is used as a size to copy.

The 'off' variable in that scope refers to object size to copy. I did not change it because it's not related to proposed change.

Quoted 2 lines

Also it is absolutely unclear why sizeof(void *) is a right size for PMD private flow items.

RTE flow library functions cannot work with PMD private items & actions (elements) because RTE flow has no API to query PMD flow object size . In the patch,
PMD flow elements use object pointer. RTE flow library functions handle PMD element object size as size of a pointer. PMD handles its objects internally.

#4 lore raw

PATCH 2/2 ethdev: tunnel offload model

In reply to Gregory Etelson

From: Eli Britstein <[email protected]>

Hardware vendors implement tunneled traffic offload techniques differently. Although RTE flow API provides tools capable to offload all sorts of network stacks, software application must reference this hardware differences in flow rules compilation. As the result tunneled traffic flow rules that utilize hardware capabilities can be different for the same traffic.

Tunnel port offload proposed in [1] provides software application with unified rules model for tunneled traffic regardless underlying hardware.
- The model introduces a concept of a virtual tunnel port (VTP).
- The model uses VTP to offload ingress tunneled network traffic with RTE flow rules.
- The model is implemented as set of helper functions. Each PMD implements VTP offload according to underlying hardware offload capabilities. Applications must query PMD for VTP flow items / actions before using in creation of a VTP flow rule.

The model components:
- Virtual Tunnel Port (VTP) is a stateless software object that describes tunneled network traffic. VTP object usually contains descriptions of outer headers, tunnel headers and inner headers.
- Tunnel Steering flow Rule (TSR) detects tunneled packets and delegates them to tunnel processing infrastructure, implemented in PMD for optimal hardware utilization, for further processing.
- Tunnel Matching flow Rule (TMR) verifies packet configuration and runs offload actions in case of a match.

Application actions:
1 Initialize VTP object according to tunnel
network parameters.
2 Create TSR flow rule:
2.1 Query PMD for VTP actions: application can query for VTP actions
more than once
int
rte_flow_tunnel_decap_set(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_action **pmd_actions, uint32_t *num_of_pmd_actions, struct rte_flow_error *error);

2.2 Integrate PMD actions into TSR actions list. 2.3 Create TSR flow rule:
flow create <port> group 0
match {tunnel items} / end
actions {PMD actions} / {App actions} / end

3 Create TMR flow rule:
3.1 Query PMD for VTP items: application can query for VTP items
more than once
int
rte_flow_tunnel_match(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_item **pmd_items, uint32_t *num_of_pmd_items, struct rte_flow_error *error);

3.2 Integrate PMD items into TMR items list:
3.3 Create TMR flow rule
flow create <port> group 0
match {PMD items} / {APP items} / end
actions {offload actions} / end

The model provides helper function call to restore packets that miss tunnel TMR rules to its original state:
int
rte_flow_get_restore_info(uint16_t port_id,
struct rte_mbuf *mbuf,
struct rte_flow_restore_info *info, struct rte_flow_error *error);

rte_tunnel object filled by the call inside rte_flow_restore_info *info parameter can be used by the application to create new TMR rule for that tunnel.

The model requirements:
Software application must initialize rte_tunnel object with tunnel parameters before calling rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().

PMD actions array obtained in rte_flow_tunnel_decap_set() must be released by application with rte_flow_action_release() call. Application can release the actionsfter TSR rule was created.

PMD items array obtained with rte_flow_tunnel_match() must be released by application with rte_flow_item_release() call. Application can release the items after rule was created. However, if the application needs to create additional TMR rule for the same tunnel it will need to obtain PMD items again.

Application cannot destroy rte_tunnel object before it releases all PMD actions & PMD items referencing that tunnel.

[1] https://mails.dpdk.org/archives/dev/2020-June/169656.html

---
 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 196 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 5 files changed, 450 insertions(+)
doc/guides/prog_guide/rte_flow.rst +105 -0
index d5dd18ce99..cfd98c2e7d 100644
@@ -3010,6 +3010,111 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Provide software application with unified rules model for tunneled traffic
+regardless underlying hardware.
+
+ - The model introduces a concept of a virtual tunnel port (VTP).
+ - The model uses VTP to offload ingress tunneled network traffic 
+   with RTE flow rules.
+ - The model is implemented as set of helper functions. Each PMD
+   implements VTP offload according to underlying hardware offload
+   capabilities.  Applications must query PMD for VTP flow
+   items / actions before using in creation of a VTP flow rule.
+
+The model components:
+
+- Virtual Tunnel Port (VTP) is a stateless software object that
+  describes tunneled network traffic.  VTP object usually contains
+  descriptions of outer headers, tunnel headers and inner headers.
+- Tunnel Steering flow Rule (TSR) detects tunneled packets and
+  delegates them to tunnel processing infrastructure, implemented
+  in PMD for optimal hardware utilization, for further processing.
+- Tunnel Matching flow Rule (TMR) verifies packet configuration and
+  runs offload actions in case of a match.
+
+Application actions:
+
+1 Initialize VTP object according to tunnel network parameters.
+
+2 Create TSR flow rule.
+
+2.1 Query PMD for VTP actions. Application can query for VTP actions more than once.
+
+  .. code-block:: c
+
+    int
+    rte_flow_tunnel_decap_set(uint16_t port_id,
+                              struct rte_flow_tunnel *tunnel,
+                              struct rte_flow_action **pmd_actions,
+                              uint32_t *num_of_pmd_actions,
+                              struct rte_flow_error *error);
+
+2.2 Integrate PMD actions into TSR actions list.
+
+2.3 Create TSR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {tunnel items} / end actions {PMD actions} / {App actions} / end
+
+3 Create TMR flow rule.
+
+3.1 Query PMD for VTP items. Application can query for VTP items more than once.
+
+    .. code-block:: c
+
+      int
+      rte_flow_tunnel_match(uint16_t port_id,
+                            struct rte_flow_tunnel *tunnel,
+                            struct rte_flow_item **pmd_items,
+                            uint32_t *num_of_pmd_items,
+                            struct rte_flow_error *error);
+
+3.2 Integrate PMD items into TMR items list.
+
+3.3 Create TMR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {PMD items} / {APP items} / end actions {offload actions} / end
+
+The model provides helper function call to restore packets that miss
+tunnel TMR rules to its original state:
+
+.. code-block:: c
+
+  int
+  rte_flow_get_restore_info(uint16_t port_id,
+                            struct rte_mbuf *mbuf,
+                            struct rte_flow_restore_info *info,
+                            struct rte_flow_error *error);
+
+rte_tunnel object filled by the call inside
+``rte_flow_restore_info *info parameter`` can be used by the application
+to create new TMR rule for that tunnel.
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+Application can release the actionsfter TSR rule was created.
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release the items after rule was created. However, if the application
+needs to create additional TMR rule for the same tunnel it will need
+to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
 
lib/librte_ethdev/rte_ethdev_version.map +5 -0
index 7155056045..63800811df 100644
@@ -241,4 +241,9 @@ EXPERIMENTAL {
 	__rte_ethdev_trace_rx_burst;
 	__rte_ethdev_trace_tx_burst;
 	rte_flow_get_aged_flows;
+	rte_flow_tunnel_decap_set;
+	rte_flow_tunnel_match;
+	rte_flow_tunnel_get_restore_info;
+	rte_flow_tunnel_action_decap_release;
+	rte_flow_tunnel_item_release;
 };
lib/librte_ethdev/rte_flow.c +112 -0

115 lines not on this page · raw message

lib/librte_ethdev/rte_flow.h +196 -0

202 lines not on this page · raw message

lib/librte_ethdev/rte_flow_driver.h +32 -0
index 881cc469b7..ad1d7a2cdc 100644
@@ -107,6 +107,38 @@ struct rte_flow_ops {
 		 void **context,
 		 uint32_t nb_contexts,
 		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_decap_set() */
+	int (*tunnel_decap_set)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_action **pmd_actions,
+		 uint32_t *num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_match() */
+	int (*tunnel_match)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_item **pmd_items,
+		 uint32_t *num_of_items,
+		 struct rte_flow_error *err);
+	/** See rte_flow_get_rte_flow_restore_info() */
+	int (*get_restore_info)
+		(struct rte_eth_dev *dev,
+		 struct rte_mbuf *m,
+		 struct rte_flow_restore_info *info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_action_tunnel_decap_release() */
+	int (*action_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_action *pmd_actions,
+		 uint32_t num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_item_release() */
+	int (*item_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_item *pmd_items,
+		 uint32_t num_of_items,
+		 struct rte_flow_error *err);
 };
 
 /**
Signature · 1 line
2.25.1

A message that is not in the archive (sent off-list or not yet received): DB8PR05MB6761ED02BCD188771BDCDE64A86F0@DB8PR05MB6761.eurprd05.prod.outlook.com

A message that is not in the archive (sent off-list or not yet received): [email protected]

#7 lore raw
Quoted 410 lines

-----Original Message-----
From: Kinsella, Ray <[email protected]>
Sent: Tuesday, June 30, 2020 14:30
To: Gregory Etelson <[email protected]>
Cc: Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Ori Kam <[email protected]>; John McNamara <[email protected]>; Marko Kovacevic <[email protected]>; Neil Horman <[email protected]>; Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; Ajit Khaparde <[email protected]>; [email protected]; [email protected]; Eli Britstein <[email protected]>; Oz Shlomo <[email protected]>
Subject: Re: [PATCH 2/2] ethdev: tunnel offload model

Quoted 12 lines · Gregory Etelson

+ maintainers

-----Original Message-----
From: Gregory Etelson <[email protected]>
Sent: Thursday, June 25, 2020 19:04
To: [email protected]
Cc: Gregory Etelson <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Eli Britstein <[email protected]>; Ori Kam <[email protected]>
Subject: [PATCH 2/2] ethdev: tunnel offload model

Quoted 3 lines

From: Eli Britstein <[email protected]>

Hardware vendors implement tunneled traffic offload techniques

differently. Although RTE flow API provides tools capable to offload all sorts of network stacks, software application must reference this hardware differences in flow rules compilation. As the result tunneled traffic flow rules that utilize hardware capabilities can be different for the same traffic.

Quoted 2 lines

Tunnel port offload proposed in [1] provides software application with

unified rules model for tunneled traffic regardless underlying hardware.

Quoted 47 lines

- The model introduces a concept of a virtual tunnel port (VTP).
- The model uses VTP to offload ingress tunneled network traffic with RTE flow rules.
- The model is implemented as set of helper functions. Each PMD implements VTP offload according to underlying hardware offload capabilities. Applications must query PMD for VTP flow items / actions before using in creation of a VTP flow rule.

The model components:
- Virtual Tunnel Port (VTP) is a stateless software object that describes tunneled network traffic. VTP object usually contains descriptions of outer headers, tunnel headers and inner headers.
- Tunnel Steering flow Rule (TSR) detects tunneled packets and delegates them to tunnel processing infrastructure, implemented in PMD for optimal hardware utilization, for further processing.
- Tunnel Matching flow Rule (TMR) verifies packet configuration and runs offload actions in case of a match.

Application actions:
1 Initialize VTP object according to tunnel
network parameters.
2 Create TSR flow rule:
2.1 Query PMD for VTP actions: application can query for VTP actions
more than once
int
rte_flow_tunnel_decap_set(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_action **pmd_actions, uint32_t *num_of_pmd_actions, struct rte_flow_error *error);

2.2 Integrate PMD actions into TSR actions list. 2.3 Create TSR flow rule:
flow create <port> group 0
match {tunnel items} / end
actions {PMD actions} / {App actions} / end

3 Create TMR flow rule:
3.1 Query PMD for VTP items: application can query for VTP items
more than once
int
rte_flow_tunnel_match(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_item **pmd_items, uint32_t *num_of_pmd_items, struct rte_flow_error *error);

Quoted 7 lines

3.2 Integrate PMD items into TMR items list:
3.3 Create TMR flow rule
flow create <port> group 0
match {PMD items} / {APP items} / end
actions {offload actions} / end

The model provides helper function call to restore packets that miss tunnel

TMR rules to its original state:

Quoted 7 lines

int
rte_flow_get_restore_info(uint16_t port_id,
struct rte_mbuf *mbuf, struct rte_flow_restore_info *info, struct rte_flow_error *error);

rte_tunnel object filled by the call inside rte_flow_restore_info *info

parameter can be used by the application to create new TMR rule for that tunnel.

Quoted 7 lines

The model requirements:
Software application must initialize rte_tunnel object with tunnel parameters before calling rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().

PMD actions array obtained in rte_flow_tunnel_decap_set() must be

released by application with rte_flow_action_release() call.

Quoted 3 lines

Application can release the actionsfter TSR rule was created.

PMD items array obtained with rte_flow_tunnel_match() must be released

by application with rte_flow_item_release() call. Application can release the items after rule was created. However, if the application needs to create additional TMR rule for the same tunnel it will need to obtain PMD items again.

Quoted 2 lines

Application cannot destroy rte_tunnel object before it releases all PMD

actions & PMD items referencing that tunnel.

Quoted 4 lines

[1]
https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmail
s.dpdk.org%2Farchives%2Fdev%2F2020-

June%2F169656.html&amp;data=02%7C01

Quoted 1 line

%7Cgetelson%40mellanox.com%7C1178dd5eb0214d807d6d08d81ce8e739% 7Ca65297

Quoted 1 line

1c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C637291133935729423&amp;sd ata=G%2B

Quoted 43 lines

GIPy%2Bxz73sgmkem4jojYGKDDsXs8nKVK0Ktdek28c%3D&amp;reserved=0

---
 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 196 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 5 files changed, 450 insertions(+)
doc/guides/prog_guide/rte_flow.rst +22 -0
index d5dd18ce99..cfd98c2e7d 100644
@@ -3010,6 +3010,111 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Provide software application with unified rules model for tunneled
+traffic regardless underlying hardware.
+
+ - The model introduces a concept of a virtual tunnel port (VTP).
+ - The model uses VTP to offload ingress tunneled network traffic
+   with RTE flow rules.
+ - The model is implemented as set of helper functions. Each PMD
+   implements VTP offload according to underlying hardware offload
+   capabilities.  Applications must query PMD for VTP flow
+   items / actions before using in creation of a VTP flow rule.
+
+The model components:
+
+- Virtual Tunnel Port (VTP) is a stateless software object that
+  describes tunneled network traffic.  VTP object usually contains
+  descriptions of outer headers, tunnel headers and inner headers.
+- Tunnel Steering flow Rule (TSR) detects tunneled packets and
+  delegates them to tunnel processing infrastructure, implemented
+  in PMD for optimal hardware utilization, for further processing.

doc/guides/prog_guide/rte_flow.rst operations include: · line 3044

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+- Tunnel Matching flow Rule (TMR) verifies packet configuration and
+  runs offload actions in case of a match.
+
+Application actions:
+
+1 Initialize VTP object according to tunnel network parameters.
+
+2 Create TSR flow rule.
+
+2.1 Query PMD for VTP actions. Application can query for VTP actions

more than once.

Quoted 12 lines
doc/guides/prog_guide/rte_flow.rst +12 -0
+
+  .. code-block:: c
+
+    int
+    rte_flow_tunnel_decap_set(uint16_t port_id,
+                              struct rte_flow_tunnel *tunnel,
+                              struct rte_flow_action **pmd_actions,
+                              uint32_t *num_of_pmd_actions,
+                              struct rte_flow_error *error);
+
+2.2 Integrate PMD actions into TSR actions list.
+

doc/guides/prog_guide/rte_flow.rst operations include:

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+2.3 Create TSR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {tunnel items} / end actions
+ {PMD actions} / {App actions} / end
+
+3 Create TMR flow rule.
+
+3.1 Query PMD for VTP items. Application can query for VTP items more

than once.

lib/librte_ethdev/rte_flow.c rte_flow_get_aged_flows(uint16_t port_id,

Quoted 76 lines
doc/guides/prog_guide/rte_flow.rst +53 -0
+
+    .. code-block:: c
+
+      int
+      rte_flow_tunnel_match(uint16_t port_id,
+                            struct rte_flow_tunnel *tunnel,
+                            struct rte_flow_item **pmd_items,
+                            uint32_t *num_of_pmd_items,
+                            struct rte_flow_error *error);
+
+3.2 Integrate PMD items into TMR items list.
+
+3.3 Create TMR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {PMD items} / {APP items} /
+ end actions {offload actions} / end
+
+The model provides helper function call to restore packets that miss
+tunnel TMR rules to its original state:
+
+.. code-block:: c
+
+  int
+  rte_flow_get_restore_info(uint16_t port_id,
+                            struct rte_mbuf *mbuf,
+                            struct rte_flow_restore_info *info,
+                            struct rte_flow_error *error);
+
+rte_tunnel object filled by the call inside ``rte_flow_restore_info
+*info parameter`` can be used by the application to create new TMR
+rule for that tunnel.
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+Application can release the actionsfter TSR rule was created.
+
+PMD items array obtained with rte_flow_tunnel_match() must be
+released by application with rte_flow_item_release() call.
+Application can release the items after rule was created. However, if
+the application needs to create additional TMR rule for the same
+tunnel it will need to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
lib/librte_ethdev/rte_ethdev_version.map +5 -0
index 7155056045..63800811df 100644
@@ -241,4 +241,9 @@ EXPERIMENTAL {
 	__rte_ethdev_trace_rx_burst;
 	__rte_ethdev_trace_tx_burst;
 	rte_flow_get_aged_flows;
+	rte_flow_tunnel_decap_set;
+	rte_flow_tunnel_match;
+	rte_flow_tunnel_get_restore_info;
+	rte_flow_tunnel_action_decap_release;
+	rte_flow_tunnel_item_release;
 };
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.c index c19d25649f..2dc5bfbb3f 100644

lib/librte_ethdev/rte_flow.c +0 -0
@@ -1268,3 +1268,115 @@ rte_flow_get_aged_flows(uint16_t port_id,

void **contexts,

Quoted 120 lines
lib/librte_ethdev/rte_flow.c +109 -0
 				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
 				  NULL, rte_strerror(ENOTSUP));
 }
+
+int
+rte_flow_tunnel_decap_set(uint16_t port_id,
+			  struct rte_flow_tunnel *tunnel,
+			  struct rte_flow_action **actions,
+			  uint32_t *num_of_actions,
+			  struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->tunnel_decap_set)) {
+		return flow_err(port_id,
+				ops->tunnel_decap_set(dev, tunnel, actions,
+						      num_of_actions, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_tunnel_match(uint16_t port_id,
+		      struct rte_flow_tunnel *tunnel,
+		      struct rte_flow_item **items,
+		      uint32_t *num_of_items,
+		      struct rte_flow_error *error) {
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->tunnel_match)) {
+		return flow_err(port_id,
+				ops->tunnel_match(dev, tunnel, items,
+						  num_of_items, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_tunnel_get_restore_info(uint16_t port_id,
+				 struct rte_mbuf *m,
+				 struct rte_flow_restore_info *restore_info,
+				 struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->get_restore_info)) {
+		return flow_err(port_id,
+				ops->get_restore_info(dev, m, restore_info,
+						      error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_tunnel_action_decap_release(uint16_t port_id,
+				     struct rte_flow_action *actions,
+				     uint32_t num_of_actions,
+				     struct rte_flow_error *error) {
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->action_release)) {
+		return flow_err(port_id,
+				ops->action_release(dev, actions,
+						    num_of_actions, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_tunnel_item_release(uint16_t port_id,
+			     struct rte_flow_item *items,
+			     uint32_t num_of_items,
+			     struct rte_flow_error *error) {
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->item_release)) {
+		return flow_err(port_id,
+				ops->item_release(dev, items,
+						  num_of_items, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.h index b0e4199192..1374b6e5a7 100644

lib/librte_ethdev/rte_flow.h +0 -0
@@ -3324,6 +3324,202 @@ int
 rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
 			uint32_t nb_contexts, struct rte_flow_error *error);
 
Quoted 7 lines

lib/librte_ethdev/rte_flow.h int · line 3328

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+/* Tunnel information. */
+__rte_experimental

__rte_experimental is not required AFAIK on structure definitions, structure definitions are not symbols, just on exported functions and variables.

Did you get a specific warning, that made you add this?

[Gregory Etelson] The attribute is not required in structures definition. It's removed in v2 patch version

Quoted 250 lines

lib/librte_ethdev/rte_flow.h int

Quoted 7 lines
lib/librte_ethdev/rte_flow.h +6 -0
+struct rte_flow_ip_tunnel_key {
+	rte_be64_t tun_id; /**< Tunnel identification. */
+	union {
+		struct {
+			rte_be32_t src_addr; /**< IPv4 source address. */
+			rte_be32_t dst_addr; /**< IPv4 destination address.

*/

lib/librte_ethdev/rte_flow.h int

Quoted 4 lines
lib/librte_ethdev/rte_flow.h +4 -0
+		} ipv4;
+		struct {
+			uint8_t src_addr[16]; /**< IPv6 source address. */
+			uint8_t dst_addr[16]; /**< IPv6 destination address.

*/

Quoted 37 lines
lib/librte_ethdev/rte_flow.h +37 -0
+		} ipv6;
+	} u;
+	bool       is_ipv6; /**< True for valid IPv6 fields. Otherwise IPv4. */
+	rte_be16_t tun_flags; /**< Tunnel flags. */
+	uint8_t    tos; /**< TOS for IPv4, TC for IPv6. */
+	uint8_t    ttl; /**< TTL for IPv4, HL for IPv6. */
+	rte_be32_t label; /**< Flow Label for IPv6. */
+	rte_be16_t tp_src; /**< Tunnel port source. */
+	rte_be16_t tp_dst; /**< Tunnel port destination. */ };
+
+
+/* Tunnel has a type and the key information. */ __rte_experimental
+struct rte_flow_tunnel {
+	/**
+	 * Tunnel type, for example RTE_FLOW_ITEM_TYPE_VXLAN,
+	 * RTE_FLOW_ITEM_TYPE_NVGRE etc.
+	 */
+	enum rte_flow_item_type		type;
+	struct rte_flow_ip_tunnel_key	tun_info; /**< Tunnel key info. */
+};
+
+/**
+ * Indicate that the packet has a tunnel.
+ */
+#define RTE_FLOW_RESTORE_INFO_TUNNEL  (1ULL << 0)
+
+/**
+ * Indicate that the packet has a non decapsulated tunnel header.
+ */
+#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED  (1ULL << 1)
+
+/**
+ * Indicate that the packet has a group_id.
+ */
+#define RTE_FLOW_RESTORE_INFO_GROUP_ID  (1ULL << 2)
+
+/**

lib/librte_ethdev/rte_flow.h int

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ * Restore information structure to communicate the current packet
+processing
+ * state when some of the processing pipeline is done in hardware and
+should
+ * continue in software.
+ */
+__rte_experimental
+struct rte_flow_restore_info {
+	/**
+	 * Bitwise flags (RTE_FLOW_RESTORE_INFO_*) to indicate validation

of

Quoted 62 lines
lib/librte_ethdev/rte_flow.h +62 -0
+	 * other fields in struct rte_flow_restore_info.
+	 */
+	uint64_t flags;
+	uint32_t group_id; /**< Group ID. */
+	struct rte_flow_tunnel tunnel; /**< Tunnel information. */ };
+
+/**
+ * Allocate an array of actions to be used in rte_flow_create, to
+implement
+ * tunnel-decap-set for the given tunnel.
+ * Sample usage:
+ *   actions vxlan_decap / tunnel-decap-set(tunnel properties) /
+ *            jump group 0 / end
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] tunnel
+ *   Tunnel properties.
+ * @param[out] actions
+ *   Array of actions to be allocated by the PMD. This array should be
+ *   concatenated with the actions array provided to rte_flow_create.
+ * @param[out] num_of_actions
+ *   Number of actions allocated.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_decap_set(uint16_t port_id,
+			  struct rte_flow_tunnel *tunnel,
+			  struct rte_flow_action **actions,
+			  uint32_t *num_of_actions,
+			  struct rte_flow_error *error);
+
+/**
+ * Allocate an array of items to be used in rte_flow_create, to
+implement
+ * tunnel-match for the given tunnel.
+ * Sample usage:
+ *   pattern tunnel-match(tunnel properties) / outer-header-matches /
+ *           inner-header-matches / end
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] tunnel
+ *   Tunnel properties.
+ * @param[out] items
+ *   Array of items to be allocated by the PMD. This array should be
+ *   concatenated with the items array provided to rte_flow_create.
+ * @param[out] num_of_items
+ *   Number of items allocated.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */

lib/librte_ethdev/rte_flow.h int

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+__rte_experimental
+int
+rte_flow_tunnel_match(uint16_t port_id,
+		      struct rte_flow_tunnel *tunnel,
+		      struct rte_flow_item **items,
+		      uint32_t *num_of_items,
+		      struct rte_flow_error *error);
+
+/**
+ * Populate the current packet processing state, if exists, for the given

mbuf.

Quoted 116 lines
lib/librte_ethdev/rte_flow.h +66 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] m
+ *   Mbuf struct.
+ * @param[out] info
+ *   Restore information. Upon success contains the HW state.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_get_restore_info(uint16_t port_id,
+				 struct rte_mbuf *m,
+				 struct rte_flow_restore_info *info,
+				 struct rte_flow_error *error);
+
+/**
+ * Release the action array as allocated by rte_flow_tunnel_decap_set.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] actions
+ *   Array of actions to be released.
+ * @param[in] num_of_actions
+ *   Number of elements in actions array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_action_decap_release(uint16_t port_id,
+				     struct rte_flow_action *actions,
+				     uint32_t num_of_actions,
+				     struct rte_flow_error *error);
+
+/**
+ * Release the item array as allocated by rte_flow_tunnel_match.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] items
+ *   Array of items to be released.
+ * @param[in] num_of_items
+ *   Number of elements in item array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_item_release(uint16_t port_id,
+			     struct rte_flow_item *items,
+			     uint32_t num_of_items,
+			     struct rte_flow_error *error);
 #ifdef __cplusplus
 }
 #endif
lib/librte_ethdev/rte_flow_driver.h +32 -1
index 881cc469b7..ad1d7a2cdc 100644
@@ -107,6 +107,38 @@ struct rte_flow_ops {
 		 void **context,
 		 uint32_t nb_contexts,
 		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_decap_set() */
+	int (*tunnel_decap_set)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_action **pmd_actions,
+		 uint32_t *num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_match() */
+	int (*tunnel_match)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_item **pmd_items,
+		 uint32_t *num_of_items,
+		 struct rte_flow_error *err);
+	/** See rte_flow_get_rte_flow_restore_info() */
+	int (*get_restore_info)
+		(struct rte_eth_dev *dev,
+		 struct rte_mbuf *m,
+		 struct rte_flow_restore_info *info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_action_tunnel_decap_release() */
+	int (*action_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_action *pmd_actions,
+		 uint32_t num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_item_release() */
+	int (*item_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_item *pmd_items,
+		 uint32_t num_of_items,
+		 struct rte_flow_error *err);
 };
 
 /**
--

2.25.1

#8 lore raw

01/07/2020 08:52, Gregory Etelson:

Quoted 8 lines

From: Kinsella, Ray <[email protected]>

Quoted 4 lines

__rte_experimental is not required AFAIK on structure definitions, structure definitions are not symbols, just on exported functions and variables.

Did you get a specific warning, that made you add this?

[Gregory Etelson] The attribute is not required in structures definition. It's removed in v2 patch version

Is v2 sent? I don't find it.

#9 lore raw
Quoted 19 lines

-----Original Message-----
From: Thomas Monjalon <[email protected]>
Sent: Monday, July 13, 2020 11:21
To: Gregory Etelson <[email protected]>
Cc: Kinsella, Ray <[email protected]>; [email protected]; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Ori Kam <[email protected]>; John McNamara <[email protected]>; Marko Kovacevic <[email protected]>; Neil Horman <[email protected]>; Ferruh Yigit <[email protected]>; Andrew Rybchenko <[email protected]>; Ajit Khaparde <[email protected]>; [email protected]; [email protected]; Eli Britstein <[email protected]>; Oz Shlomo <[email protected]>; [email protected]
Subject: Re: [dpdk-dev] [PATCH 2/2] ethdev: tunnel offload model

01/07/2020 08:52, Gregory Etelson:

Quoted 3 lines

From: Kinsella, Ray <[email protected]>

Quoted 2 lines

__rte_experimental is not required AFAIK on structure definitions, structure definitions are not symbols, just on exported functions and

Quoted 9 lines

variables.

Quoted 5 lines
Quoted 2 lines

Did you get a specific warning, that made you add this?

[Gregory Etelson] The attribute is not required in structures definition. It's removed in v2 patch version

Is v2 sent? I don't find it.

V2 was not posted yet. it's in progress.

#10 lore raw
In reply to Gregory Etelson

Hi Gregory,

I'm sorry for the review with toooo many questions without any suggestions on how to answer it. Please, see below.

Quoted 112 lines · Gregory Etelson

From: Eli Britstein <[email protected]>

Hardware vendors implement tunneled traffic offload techniques differently. Although RTE flow API provides tools capable to offload all sorts of network stacks, software application must reference this hardware differences in flow rules compilation. As the result tunneled traffic flow rules that utilize hardware capabilities can be different for the same traffic.

Tunnel port offload proposed in [1] provides software application with unified rules model for tunneled traffic regardless underlying hardware.
- The model introduces a concept of a virtual tunnel port (VTP).
- The model uses VTP to offload ingress tunneled network traffic with RTE flow rules.
- The model is implemented as set of helper functions. Each PMD implements VTP offload according to underlying hardware offload capabilities. Applications must query PMD for VTP flow items / actions before using in creation of a VTP flow rule.

The model components:
- Virtual Tunnel Port (VTP) is a stateless software object that describes tunneled network traffic. VTP object usually contains descriptions of outer headers, tunnel headers and inner headers.
- Tunnel Steering flow Rule (TSR) detects tunneled packets and delegates them to tunnel processing infrastructure, implemented in PMD for optimal hardware utilization, for further processing.
- Tunnel Matching flow Rule (TMR) verifies packet configuration and runs offload actions in case of a match.

Application actions:
1 Initialize VTP object according to tunnel
network parameters.
2 Create TSR flow rule:
2.1 Query PMD for VTP actions: application can query for VTP actions
more than once
int
rte_flow_tunnel_decap_set(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_action **pmd_actions, uint32_t *num_of_pmd_actions, struct rte_flow_error *error);

2.2 Integrate PMD actions into TSR actions list. 2.3 Create TSR flow rule:
flow create <port> group 0
match {tunnel items} / end
actions {PMD actions} / {App actions} / end

3 Create TMR flow rule:
3.1 Query PMD for VTP items: application can query for VTP items
more than once
int
rte_flow_tunnel_match(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_item **pmd_items, uint32_t *num_of_pmd_items, struct rte_flow_error *error);

3.2 Integrate PMD items into TMR items list:
3.3 Create TMR flow rule
flow create <port> group 0
match {PMD items} / {APP items} / end
actions {offload actions} / end

The model provides helper function call to restore packets that miss tunnel TMR rules to its original state:
int
rte_flow_get_restore_info(uint16_t port_id,
struct rte_mbuf *mbuf,
struct rte_flow_restore_info *info, struct rte_flow_error *error);

rte_tunnel object filled by the call inside rte_flow_restore_info *info parameter can be used by the application to create new TMR rule for that tunnel.

The model requirements:
Software application must initialize rte_tunnel object with tunnel parameters before calling rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().

PMD actions array obtained in rte_flow_tunnel_decap_set() must be released by application with rte_flow_action_release() call. Application can release the actionsfter TSR rule was created.

PMD items array obtained with rte_flow_tunnel_match() must be released by application with rte_flow_item_release() call. Application can release the items after rule was created. However, if the application needs to create additional TMR rule for the same tunnel it will need to obtain PMD items again.

Application cannot destroy rte_tunnel object before it releases all PMD actions & PMD items referencing that tunnel.

[1] https://mails.dpdk.org/archives/dev/2020-June/169656.html

---
 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 196 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 5 files changed, 450 insertions(+)
doc/guides/prog_guide/rte_flow.rst +0 -0
index d5dd18ce99..cfd98c2e7d 100644

doc/guides/prog_guide/rte_flow.rst operations include: · line 3019

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +7 -0
@@ -3010,6 +3010,111 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Provide software application with unified rules model for tunneled traffic
+regardless underlying hardware.
+
+ - The model introduces a concept of a virtual tunnel port (VTP).

It looks like it is absolutely abstract concept now, since it is not mentioned/referenced in the header file. It makes it hard to put the description and API together.

doc/guides/prog_guide/rte_flow.rst operations include: · line 3025

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+ - The model uses VTP to offload ingress tunneled network traffic 
+   with RTE flow rules.
+ - The model is implemented as set of helper functions. Each PMD
+   implements VTP offload according to underlying hardware offload
+   capabilities.  Applications must query PMD for VTP flow
+   items / actions before using in creation of a VTP flow rule.

For me it looks like "creation of a VTP flow rule" is not covered yet. Flow rules examples mention it in pattern and actions, but there is no corresponding pattern items and actions. May be I simply misunderstand the idea.

doc/guides/prog_guide/rte_flow.rst operations include: · line 3031

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+
+The model components:
+
+- Virtual Tunnel Port (VTP) is a stateless software object that
+  describes tunneled network traffic.  VTP object usually contains
+  descriptions of outer headers, tunnel headers and inner headers.

Are inner headers really a part of the tunnel description?

doc/guides/prog_guide/rte_flow.rst operations include: · line 3036

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+- Tunnel Steering flow Rule (TSR) detects tunneled packets and
+  delegates them to tunnel processing infrastructure, implemented
+  in PMD for optimal hardware utilization, for further processing.
+- Tunnel Matching flow Rule (TMR) verifies packet configuration and
+  runs offload actions in case of a match.

Is it for fully offloaded tunnels with encap/decap or all tunnels (detected, but partially offloaded, e.g. checksumming)?

doc/guides/prog_guide/rte_flow.rst operations include: · line 3040

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+Application actions:
+
+1 Initialize VTP object according to tunnel network parameters.

I.e. fill in 'struct rte_flow_tunnel'. Is it correct?

Quoted 11 lines
doc/guides/prog_guide/rte_flow.rst +11 -0
+
+2 Create TSR flow rule.
+
+2.1 Query PMD for VTP actions. Application can query for VTP actions more than once.
+
+  .. code-block:: c
+
+    int
+    rte_flow_tunnel_decap_set(uint16_t port_id,
+                              struct rte_flow_tunnel *tunnel,
+                              struct rte_flow_action **pmd_actions,

doc/guides/prog_guide/rte_flow.rst operations include: · line 3061

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+                              uint32_t *num_of_pmd_actions,
+                              struct rte_flow_error *error);
+
+2.2 Integrate PMD actions into TSR actions list.
+
+2.3 Create TSR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {tunnel items} / end actions {PMD actions} / {App actions} / end

Are application actions strictly required? If no, it is better to make it clear.
Do tunnel items correlate here somehow with tunnel specification in 'struct rte_flow_tunnel'? Is it obtained using rte_flow_tunnel_match()?

Quoted 26 lines
doc/guides/prog_guide/rte_flow.rst +26 -0
+
+3 Create TMR flow rule.
+
+3.1 Query PMD for VTP items. Application can query for VTP items more than once.
+
+    .. code-block:: c
+
+      int
+      rte_flow_tunnel_match(uint16_t port_id,
+                            struct rte_flow_tunnel *tunnel,
+                            struct rte_flow_item **pmd_items,
+                            uint32_t *num_of_pmd_items,
+                            struct rte_flow_error *error);
+
+3.2 Integrate PMD items into TMR items list.
+
+3.3 Create TMR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {PMD items} / {APP items} / end actions {offload actions} / end
+
+The model provides helper function call to restore packets that miss
+tunnel TMR rules to its original state:
+
+.. code-block:: c

doc/guides/prog_guide/rte_flow.rst operations include: · line 3097

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+
+  int
+  rte_flow_get_restore_info(uint16_t port_id,
+                            struct rte_mbuf *mbuf,
+                            struct rte_flow_restore_info *info,
+                            struct rte_flow_error *error);
+
+rte_tunnel object filled by the call inside
+``rte_flow_restore_info *info parameter`` can be used by the application
+to create new TMR rule for that tunnel.

I think an example, for example, for VXLAN over IPv4 tunnel case with some concrete parameters would be very useful here for understanding. Could it be annotated with a description of the transformations happening with a packet on different stages of the processing (including restore example).

doc/guides/prog_guide/rte_flow.rst operations include: · line 3107

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+Application can release the actionsfter TSR rule was created.

actionsfter ?

Quoted 13 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release the items after rule was created. However, if the application
+needs to create additional TMR rule for the same tunnel it will need
+to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
 

[snip]

lib/librte_ethdev/rte_flow.h int · line 3330

Quoted 12 lines
lib/librte_ethdev/rte_flow.h +4 -0
index b0e4199192..1374b6e5a7 100644
@@ -3324,6 +3324,202 @@ int
 rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
 			uint32_t nb_contexts, struct rte_flow_error *error);
 
+/* Tunnel information. */
+__rte_experimental
+struct rte_flow_ip_tunnel_key {
+	rte_be64_t tun_id; /**< Tunnel identification. */

What is it? Why is it big-endian? Why is it in IP tunnel key? I.e. why is it not in a generic structure?

lib/librte_ethdev/rte_flow.h int · line 3342

Quoted 12 lines
lib/librte_ethdev/rte_flow.h +12 -0
+	union {
+		struct {
+			rte_be32_t src_addr; /**< IPv4 source address. */
+			rte_be32_t dst_addr; /**< IPv4 destination address. */
+		} ipv4;
+		struct {
+			uint8_t src_addr[16]; /**< IPv6 source address. */
+			uint8_t dst_addr[16]; /**< IPv6 destination address. */
+		} ipv6;
+	} u;
+	bool       is_ipv6; /**< True for valid IPv6 fields. Otherwise IPv4. */
+	rte_be16_t tun_flags; /**< Tunnel flags. */

Which flags? Where are these flags defined?
Why is it big-endian?

lib/librte_ethdev/rte_flow.h int · line 3344

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+	uint8_t    tos; /**< TOS for IPv4, TC for IPv6. */
+	uint8_t    ttl; /**< TTL for IPv4, HL for IPv6. */

If combine, I'd stick to IPv6 terminology since it is a bit better (well-thought, especially current tendencies in (re)naming in software).

lib/librte_ethdev/rte_flow.h int · line 3345

Quoted 1 line
lib/librte_ethdev/rte_flow.h +1 -0
+	rte_be32_t label; /**< Flow Label for IPv6. */

What about IPv6 tunnels with extension headers? How to extend?

lib/librte_ethdev/rte_flow.h int · line 3347

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+	rte_be16_t tp_src; /**< Tunnel port source. */
+	rte_be16_t tp_dst; /**< Tunnel port destination. */

What about IP-in-IP tunnels? Is it applicable?

lib/librte_ethdev/rte_flow.h int · line 3359

Quoted 12 lines
lib/librte_ethdev/rte_flow.h +12 -0
+};
+
+
+/* Tunnel has a type and the key information. */
+__rte_experimental
+struct rte_flow_tunnel {
+	/**
+	 * Tunnel type, for example RTE_FLOW_ITEM_TYPE_VXLAN,
+	 * RTE_FLOW_ITEM_TYPE_NVGRE etc.
+	 */
+	enum rte_flow_item_type		type;
+	struct rte_flow_ip_tunnel_key	tun_info; /**< Tunnel key info. */

How to extended for non-IP tunnels? MPLS? Or tunnels with more protocols? E.g. MPLS-over-UDP?

Quoted 20 lines
lib/librte_ethdev/rte_flow.h +20 -0
+};
+
+/**
+ * Indicate that the packet has a tunnel.
+ */
+#define RTE_FLOW_RESTORE_INFO_TUNNEL  (1ULL << 0)
+
+/**
+ * Indicate that the packet has a non decapsulated tunnel header.
+ */
+#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED  (1ULL << 1)
+
+/**
+ * Indicate that the packet has a group_id.
+ */
+#define RTE_FLOW_RESTORE_INFO_GROUP_ID  (1ULL << 2)
+
+/**
+ * Restore information structure to communicate the current packet processing
+ * state when some of the processing pipeline is done in hardware and should

lib/librte_ethdev/rte_flow.h int · line 3389

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ * continue in software.
+ */
+__rte_experimental
+struct rte_flow_restore_info {
+	/**
+	 * Bitwise flags (RTE_FLOW_RESTORE_INFO_*) to indicate validation of
+	 * other fields in struct rte_flow_restore_info.
+	 */
+	uint64_t flags;
+	uint32_t group_id; /**< Group ID. */

What is the group ID here?

lib/librte_ethdev/rte_flow.h int · line 3398

Quoted 9 lines
lib/librte_ethdev/rte_flow.h +9 -0
+	struct rte_flow_tunnel tunnel; /**< Tunnel information. */
+};
+
+/**
+ * Allocate an array of actions to be used in rte_flow_create, to implement
+ * tunnel-decap-set for the given tunnel.
+ * Sample usage:
+ *   actions vxlan_decap / tunnel-decap-set(tunnel properties) /
+ *            jump group 0 / end

Why is jump to group used in example above? Is it mandatory?

lib/librte_ethdev/rte_flow.h int · line 3406

Quoted 8 lines
lib/librte_ethdev/rte_flow.h +8 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] tunnel
+ *   Tunnel properties.
+ * @param[out] actions
+ *   Array of actions to be allocated by the PMD. This array should be
+ *   concatenated with the actions array provided to rte_flow_create.

Please, specify concatenation order explicitly.

Quoted 5 lines
lib/librte_ethdev/rte_flow.h +5 -0
+ * @param[out] num_of_actions
+ *   Number of actions allocated.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.

lib/librte_ethdev/rte_flow.h int · line 3421

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_decap_set(uint16_t port_id,
+			  struct rte_flow_tunnel *tunnel,
+			  struct rte_flow_action **actions,
+			  uint32_t *num_of_actions,

Why does approach to specify actions differ here? I.e. array of specified size vs END-terminated array? Must the actions array be END-terminated here? It must be a strong reason to do it and it should be explained.

Quoted 6 lines
lib/librte_ethdev/rte_flow.h +6 -0
+			  struct rte_flow_error *error);
+
+/**
+ * Allocate an array of items to be used in rte_flow_create, to implement
+ * tunnel-match for the given tunnel.
+ * Sample usage:

lib/librte_ethdev/rte_flow.h int · line 3437

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *   pattern tunnel-match(tunnel properties) / outer-header-matches /
+ *           inner-header-matches / end
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] tunnel
+ *   Tunnel properties.
+ * @param[out] items
+ *   Array of items to be allocated by the PMD. This array should be
+ *   concatenated with the items array provided to rte_flow_create.

Concatenation order/rules should be described. Since it is an output which entity does the concatenation. Is it allowed to refine PMD rules in application rule specification?

Quoted 5 lines
lib/librte_ethdev/rte_flow.h +5 -0
+ * @param[out] num_of_items
+ *   Number of items allocated.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.

lib/librte_ethdev/rte_flow.h int · line 3452

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_match(uint16_t port_id,
+		      struct rte_flow_tunnel *tunnel,
+		      struct rte_flow_item **items,
+		      uint32_t *num_of_items,

Same as above for actions.

Quoted 13 lines
lib/librte_ethdev/rte_flow.h +13 -0
+		      struct rte_flow_error *error);
+
+/**
+ * Populate the current packet processing state, if exists, for the given mbuf.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] m
+ *   Mbuf struct.
+ * @param[out] info
+ *   Restore information. Upon success contains the HW state.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this

lib/librte_ethdev/rte_flow.h int · line 3475

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_get_restore_info(uint16_t port_id,
+				 struct rte_mbuf *m,
+				 struct rte_flow_restore_info *info,

Is it suggesting to make a copy of the restore info for each mbuf? It sounds very expensive. Could you share your thoughts about it.

Quoted 13 lines
lib/librte_ethdev/rte_flow.h +13 -0
+				 struct rte_flow_error *error);
+
+/**
+ * Release the action array as allocated by rte_flow_tunnel_decap_set.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] actions
+ *   Array of actions to be released.
+ * @param[in] num_of_actions
+ *   Number of elements in actions array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this

lib/librte_ethdev/rte_flow.h int · line 3498

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_action_decap_release(uint16_t port_id,
+				     struct rte_flow_action *actions,
+				     uint32_t num_of_actions,

Same question as above for actions and items specification approach.

Quoted 13 lines
lib/librte_ethdev/rte_flow.h +13 -0
+				     struct rte_flow_error *error);
+
+/**
+ * Release the item array as allocated by rte_flow_tunnel_match.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] items
+ *   Array of items to be released.
+ * @param[in] num_of_items
+ *   Number of elements in item array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this

lib/librte_ethdev/rte_flow.h int · line 3521

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_item_release(uint16_t port_id,
+			     struct rte_flow_item *items,
+			     uint32_t num_of_items,

Same question as above for actions and items specification approach.

lib/librte_ethdev/rte_flow.h int · line 3525

Quoted 4 lines
lib/librte_ethdev/rte_flow.h +1 -0
+			     struct rte_flow_error *error);
 #ifdef __cplusplus
 }
 #endif

[snip]

Andrew.

(Right now it is hard to fully imagine how to deal with it. And it looks like a shim to vendor-specific API. May be I'm wrong. Hopefully the next version will have PMD implementation example and it will shed a bit more light on it.)

#11 lore raw

Hello Andrew,

Thank you for detailed review.
Sorry for the late response.
Please see my answers inline.

Regards,
Gregory

Quoted 144 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Sunday, July 5, 2020 17:51
To: Gregory Etelson <[email protected]>; [email protected]
Cc: Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Eli Britstein <[email protected]>; Ori Kam <[email protected]>
Subject: Re: [dpdk-dev] [PATCH 2/2] ethdev: tunnel offload model

Hi Gregory,

I'm sorry for the review with toooo many questions without any suggestions on how to answer it. Please, see below.

Quoted 92 lines · Gregory Etelson

From: Eli Britstein <[email protected]>

Hardware vendors implement tunneled traffic offload techniques differently. Although RTE flow API provides tools capable to offload all sorts of network stacks, software application must reference this hardware differences in flow rules compilation. As the result tunneled traffic flow rules that utilize hardware capabilities can be different for the same traffic.

Tunnel port offload proposed in [1] provides software application with unified rules model for tunneled traffic regardless underlying hardware.
- The model introduces a concept of a virtual tunnel port (VTP).
- The model uses VTP to offload ingress tunneled network traffic with RTE flow rules.
- The model is implemented as set of helper functions. Each PMD implements VTP offload according to underlying hardware offload capabilities. Applications must query PMD for VTP flow items / actions before using in creation of a VTP flow rule.

The model components:
- Virtual Tunnel Port (VTP) is a stateless software object that describes tunneled network traffic. VTP object usually contains descriptions of outer headers, tunnel headers and inner headers.
- Tunnel Steering flow Rule (TSR) detects tunneled packets and delegates them to tunnel processing infrastructure, implemented in PMD for optimal hardware utilization, for further processing.
- Tunnel Matching flow Rule (TMR) verifies packet configuration and runs offload actions in case of a match.

Application actions:
1 Initialize VTP object according to tunnel
network parameters.
2 Create TSR flow rule:
2.1 Query PMD for VTP actions: application can query for VTP actions
more than once
int
rte_flow_tunnel_decap_set(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_action **pmd_actions, uint32_t *num_of_pmd_actions, struct rte_flow_error *error);

2.2 Integrate PMD actions into TSR actions list. 2.3 Create TSR flow rule:
flow create <port> group 0
match {tunnel items} / end
actions {PMD actions} / {App actions} / end

3 Create TMR flow rule:
3.1 Query PMD for VTP items: application can query for VTP items
more than once
int
rte_flow_tunnel_match(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_item **pmd_items, uint32_t *num_of_pmd_items, struct rte_flow_error *error);

3.2 Integrate PMD items into TMR items list:
3.3 Create TMR flow rule
flow create <port> group 0
match {PMD items} / {APP items} / end
actions {offload actions} / end

The model provides helper function call to restore packets that miss tunnel TMR rules to its original state:
int
rte_flow_get_restore_info(uint16_t port_id,
struct rte_mbuf *mbuf,
struct rte_flow_restore_info *info, struct rte_flow_error *error);

rte_tunnel object filled by the call inside rte_flow_restore_info *info parameter can be used by the application to create new TMR rule for that tunnel.

The model requirements:
Software application must initialize rte_tunnel object with tunnel parameters before calling
rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().

PMD actions array obtained in rte_flow_tunnel_decap_set() must be released by application with rte_flow_action_release() call. Application can release the actionsfter TSR rule was created.

PMD items array obtained with rte_flow_tunnel_match() must be released by application with rte_flow_item_release() call. Application can release the items after rule was created. However, if the application needs to create additional TMR rule for the same tunnel it will need to obtain PMD items again.

Quoted 7 lines

Application cannot destroy rte_tunnel object before it releases all PMD actions & PMD items referencing that tunnel.

[1]
https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fma
il
s.dpdk.org%2Farchives%2Fdev%2F2020-

June%2F169656.html&amp;data=02%7C01

Quoted 1 line

%7Cgetelson%40mellanox.com%7Cb1dd5d535357492c727508d820f2d97b%7 Ca65297

Quoted 1 line

1c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C637295574702858871&amp;sd ata=Ej%2

Quoted 1 line

FtMUt2A%2FV3y70iRTXq5NmCRbW8nxCx4PLZQQFwb3o%3D&amp;reserved= 0

Quoted 20 lines
---
 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 196 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 5 files changed, 450 insertions(+)
doc/guides/prog_guide/rte_flow.rst +0 -0
index d5dd18ce99..cfd98c2e7d 100644
@@ -3010,6 +3010,111 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
Quoted 12 lines

doc/guides/prog_guide/rte_flow.rst operations include: · line 3019

Quoted 7 lines
doc/guides/prog_guide/rte_flow.rst +7 -0
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Provide software application with unified rules model for tunneled 
+traffic regardless underlying hardware.
+
+ - The model introduces a concept of a virtual tunnel port (VTP).

It looks like it is absolutely abstract concept now, since it is not mentioned/referenced in the header file. It makes it hard to put the description and API together.

Virtual tunnel is a concept that allows PMD to restore packet outer header after decap. Example below shows how this feature is used.

Quoted 11 lines

doc/guides/prog_guide/rte_flow.rst operations include: · line 3025

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+ - The model uses VTP to offload ingress tunneled network traffic
+   with RTE flow rules.
+ - The model is implemented as set of helper functions. Each PMD
+   implements VTP offload according to underlying hardware offload
+   capabilities.  Applications must query PMD for VTP flow
+   items / actions before using in creation of a VTP flow rule.

For me it looks like "creation of a VTP flow rule" is not covered yet. Flow rules examples mention it in pattern and actions, but there is no corresponding pattern items and actions. May be I simply misunderstand the idea.

This feature does not introduce new RTE items or actions.
The idea is that PMD will use private items and actions to implement internal logic that will allow packet restore after decap. There's a detailed example below. Internal PMD elements referred as pmd_item / pmd_action.

Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst operations include: · line 3031

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+
+The model components:
+
+- Virtual Tunnel Port (VTP) is a stateless software object that
+  describes tunneled network traffic.  VTP object usually contains
+  descriptions of outer headers, tunnel headers and inner headers.

Are inner headers really a part of the tunnel description?

Inner headers are not part of tunnel description.

Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst operations include: · line 3036

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+- Tunnel Steering flow Rule (TSR) detects tunneled packets and
+  delegates them to tunnel processing infrastructure, implemented
+  in PMD for optimal hardware utilization, for further processing.
+- Tunnel Matching flow Rule (TMR) verifies packet configuration and
+  runs offload actions in case of a match.

Is it for fully offloaded tunnels with encap/decap or all tunnels (detected, but partially offloaded, e.g. checksumming)?

Tunnel API is designed for tunnel packets that will go through decap action. Current tunnel API version focuses on VXLAN tunnel.

Quoted 7 lines

doc/guides/prog_guide/rte_flow.rst operations include: · line 3040

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+Application actions:
+
+1 Initialize VTP object according to tunnel network parameters.

I.e. fill in 'struct rte_flow_tunnel'. Is it correct?

Correct. Application initializes rte_flow_tunnel structure

Quoted 22 lines

doc/guides/prog_guide/rte_flow.rst operations include:

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+
+2 Create TSR flow rule.
+
+2.1 Query PMD for VTP actions. Application can query for VTP 
+actions

more than once.

Quoted 16 lines
doc/guides/prog_guide/rte_flow.rst +16 -0
+
+  .. code-block:: c
+
+    int
+    rte_flow_tunnel_decap_set(uint16_t port_id,
+                              struct rte_flow_tunnel *tunnel,
+                              struct rte_flow_action **pmd_actions,
+                              uint32_t *num_of_pmd_actions,
+                              struct rte_flow_error *error);
+
+2.2 Integrate PMD actions into TSR actions list.
+
+2.3 Create TSR flow rule.
+
+    .. code-block:: console
+
Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst operations include: · line 3063

Quoted 2 lines
doc/guides/prog_guide/rte_flow.rst +2 -0
+      flow create <port> group 0 match {tunnel items} / end actions 
+ {PMD actions} / {App actions} / end

Are application actions strictly required?
If no, it is better to make it clear.
Do tunnel items correlate here somehow with tunnel specification in 'struct rte_flow_tunnel'?
Is it obtained using rte_flow_tunnel_match()?

Application actions are not required in steering rule. {tunnel items} refer to rte flow items that identify tunnel. These items correlate to tunnel description in rte_flow_tunnel structure.

Quoted 36 lines

doc/guides/prog_guide/rte_flow.rst operations include:

Quoted 5 lines
doc/guides/prog_guide/rte_flow.rst +5 -0
+
+3 Create TMR flow rule.
+
+3.1 Query PMD for VTP items. Application can query for VTP items 
+more

than once.

Quoted 30 lines
doc/guides/prog_guide/rte_flow.rst +30 -0
+
+    .. code-block:: c
+
+      int
+      rte_flow_tunnel_match(uint16_t port_id,
+                            struct rte_flow_tunnel *tunnel,
+                            struct rte_flow_item **pmd_items,
+                            uint32_t *num_of_pmd_items,
+                            struct rte_flow_error *error);
+
+3.2 Integrate PMD items into TMR items list.
+
+3.3 Create TMR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {PMD items} / {APP items} / 
+ end actions {offload actions} / end
+
+The model provides helper function call to restore packets that 
+miss tunnel TMR rules to its original state:
+
+.. code-block:: c
+
+  int
+  rte_flow_get_restore_info(uint16_t port_id,
+                            struct rte_mbuf *mbuf,
+                            struct rte_flow_restore_info *info,
+                            struct rte_flow_error *error);
+
Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst operations include: · line 3101

Quoted 3 lines
doc/guides/prog_guide/rte_flow.rst +3 -0
+rte_tunnel object filled by the call inside ``rte_flow_restore_info 
+*info parameter`` can be used by the application to create new TMR 
+rule for that tunnel.

I think an example, for example, for VXLAN over IPv4 tunnel case with
some concrete parameters would be very useful here for understanding.
Could it be annotated with a description of the transformations
happening with a packet on different stages of the processing (including restore example).

VXLAN Code example:
Assume application needs to do inner NAT on VXLAN packet. The first rule in group 0:

flow create <port id> ingress group 0 pattern eth / ipv4 / udp dst is 4789 / vxlan / end
actions {pmd actions} / jump group 3 / end

First VXLAN packet that arrives matches the rule in group 0 and jumps to group 3 In group 3 the packet will miss since there is no flow to match and will be uploaded to application.
Application will call rte_flow_get_restore_info() to get the packet outer header. Application will insert a new rule in group 3 to match outer and inner headers:

flow create <port id> ingress group 3 pattern {pmd items} / eth / ipv4 dst is 172.10.10.1 / udp dst 4789 / vxlan vni is 10 /

        ipv4 dst is 184.1.2.3 / end
         actions  set_ipv4_dst  186.1.1.1 / queue index 3 / end

Resulting of rules will be that VXLAN packet with vni=10, outer IPv4 dst =172.10.10.1 and inner IPv4 dst=184.1.2.3 will be received decaped on queue 3 with IPv4 dst=186.1.1.1

Note: Packet in group 3 is considered decaped. All actions in that group will be done on header that was inner before decap. Application may specify outer header to be matched on. It's PMD responsibility to translate these items to outer metadata.

API usage:
/**
* 1. Initiate RTE flow tunnel object
*/
struct rte_flow_tunnel tunnel = {
.type = RTE_FLOW_ITEM_TYPE_VXLAN,

  .tun_info = {
    .tun_id = rte_cpu_to_be_64(10),

}
}

/**
* 2. Obtain PMD tunnel actions
*
* pmd_actions is an intermediate variable application uses to
* compile actions array
*/
struct rte_flow_action **pmd_actions; rte_flow_tunnel_decap_and_set(&tunnel, &pmd_actions,

                              &num_pmd_actions, &error);

/**
* 3. offload the first rule
* matching on VXLAN traffic and jumps to group 3
* (implicitly decaps packet)
*/
app_actions = jump group 3
rule_items = app_items; /* eth / ipv4 / udp / vxlan */ rule_actions = { pmd_actions, app_actions }; attr.group = 0;
flow_1 = rte_flow_create(port_id, &attr,

                                               rule_items, rule_actions, &error);

/**
* 4. after flow creation application does not need to keep tunnel
* action resources.
*/
rte_flow_tunnel_action_release(port_id, pmd_actions,

                                                            num_pmd_actions);

/**
* 5. After partially offloaded packet miss because there was no
* matching rule handle miss on group 3
*/
struct rte_flow_restore_info info; rte_flow_get_restore_info(port_id, mbuf, &info, &error);

/**
* 6. Offload NAT rule:
*/
app_items = eth / ipv4 dst is 172.10.10.1 / udp dst 4789 / vxlan vni is 10 / ipv4 dst is 184.1.2.3 app_actions = set_ipv4_dst 186.1.1.1 / queue index 3

rte_flow_tunnel_match(&info.tunnel, &pmd_items,

                                            &num_pmd_items,  &error); 

rule_items = {pmd_items, app_items};
rule_actions = app_actions;
attr.group = info.group_id;
flow_2 = rte_flow_create(port_id, &attr,

                                               rule_items, rule_actions, &error);							

/**
* 7. Release PMD items after rule creation
*/
rte_flow_tunnel_item_release(port_id, pmd_items, num_pmd_items);

Quoted 4 lines
Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+The model requirements:
+
+Software application must initialize rte_tunnel object with tunnel 
Quoted 9 lines

doc/guides/prog_guide/rte_flow.rst operations include: · line 3107

Quoted 6 lines
doc/guides/prog_guide/rte_flow.rst +6 -0
+parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be 
+released by application with rte_flow_action_release() call.
+Application can release the actionsfter TSR rule was created.

actionsfter ?

Typo. Original text was
"Application can release the actions after TSR rule was created."

Quoted 24 lines
Quoted 13 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+
+PMD items array obtained with rte_flow_tunnel_match() must be 
+released by application with rte_flow_item_release() call.
+Application can release the items after rule was created. However, 
+if the application needs to create additional TMR rule for the same 
+tunnel it will need to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all 
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------

[snip]

Quoted 8 lines
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.h index b0e4199192..1374b6e5a7 100644

lib/librte_ethdev/rte_flow.h +0 -0
@@ -3324,6 +3324,202 @@ int
 rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
 			uint32_t nb_contexts, struct rte_flow_error *error);
 
Quoted 8 lines

lib/librte_ethdev/rte_flow.h int · line 3330

Quoted 4 lines
lib/librte_ethdev/rte_flow.h +4 -0
+/* Tunnel information. */
+__rte_experimental
+struct rte_flow_ip_tunnel_key {
+	rte_be64_t tun_id; /**< Tunnel identification. */

What is it? Why is it big-endian? Why is it in IP tunnel key? I.e. why is it not in a generic structure?

tun_id is tunnel identification key, vni value in VXLAN case. I'll change it to CPU order.
Also, I will merge tunnel_key structure into rte_tunnel in next version.

Quoted 10 lines

lib/librte_ethdev/rte_flow.h int

Quoted 4 lines
lib/librte_ethdev/rte_flow.h +4 -0
+	union {
+		struct {
+			rte_be32_t src_addr; /**< IPv4 source address. */
+			rte_be32_t dst_addr; /**< IPv4 destination address.

*/

lib/librte_ethdev/rte_flow.h int

Quoted 4 lines
lib/librte_ethdev/rte_flow.h +4 -0
+		} ipv4;
+		struct {
+			uint8_t src_addr[16]; /**< IPv6 source address. */
+			uint8_t dst_addr[16]; /**< IPv6 destination address.

*/

Quoted 8 lines

lib/librte_ethdev/rte_flow.h int · line 3342

Quoted 4 lines
lib/librte_ethdev/rte_flow.h +4 -0
+		} ipv6;
+	} u;
+	bool       is_ipv6; /**< True for valid IPv6 fields. Otherwise IPv4. */
+	rte_be16_t tun_flags; /**< Tunnel flags. */

Which flags? Where are these flags defined?
Why is it big-endian?

Tunnel flags value, as it appeared in incoming packet. Since this structure may be used for different tunnel types, exact definitions are different in each type.
I'll change is to CPU order.

Quoted 10 lines

lib/librte_ethdev/rte_flow.h int · line 3344

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+	uint8_t    tos; /**< TOS for IPv4, TC for IPv6. */
+	uint8_t    ttl; /**< TTL for IPv4, HL for IPv6. */

If combine, I'd stick to IPv6 terminology since it is a bit better (well-thought, especially current tendencies in (re)naming in software).

lib/librte_ethdev/rte_flow.h int · line 3345

Quoted 1 line
lib/librte_ethdev/rte_flow.h +1 -0
+	rte_be32_t label; /**< Flow Label for IPv6. */

What about IPv6 tunnels with extension headers? How to extend?

These tunnels are not supported at this point.
Structure can be expended in future.

Quoted 5 lines

lib/librte_ethdev/rte_flow.h int · line 3347

Quoted 2 lines
lib/librte_ethdev/rte_flow.h +2 -0
+	rte_be16_t tp_src; /**< Tunnel port source. */
+	rte_be16_t tp_dst; /**< Tunnel port destination. */

What about IP-in-IP tunnels? Is it applicable?

No support for IP-in-IP tunnels in current version. Future releases can have that feature, based on request.

Quoted 6 lines
Quoted 6 lines
lib/librte_ethdev/rte_flow.h +6 -0
+};
+
+
+/* Tunnel has a type and the key information. */ __rte_experimental 
+struct rte_flow_tunnel {
+	/**
Quoted 9 lines

lib/librte_ethdev/rte_flow.h int · line 3359

Quoted 5 lines
lib/librte_ethdev/rte_flow.h +5 -0
+	 * Tunnel type, for example RTE_FLOW_ITEM_TYPE_VXLAN,
+	 * RTE_FLOW_ITEM_TYPE_NVGRE etc.
+	 */
+	enum rte_flow_item_type		type;
+	struct rte_flow_ip_tunnel_key	tun_info; /**< Tunnel key info. */

How to extended for non-IP tunnels? MPLS? Or tunnels with more protocols? E.g. MPLS-over-UDP?

Regarding extensions to new tunnels
Basically this structure is a software representor. Each tunnel format can add its own fields. In the current implementation we target VXLAN tunnel type.
Additional tunnel types can be added in the future per demand with addition of relevant members to base structure.

Quoted 29 lines
Quoted 18 lines
lib/librte_ethdev/rte_flow.h +18 -0
+};
+
+/**
+ * Indicate that the packet has a tunnel.
+ */
+#define RTE_FLOW_RESTORE_INFO_TUNNEL  (1ULL << 0)
+
+/**
+ * Indicate that the packet has a non decapsulated tunnel header.
+ */
+#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED  (1ULL << 1)
+
+/**
+ * Indicate that the packet has a group_id.
+ */
+#define RTE_FLOW_RESTORE_INFO_GROUP_ID  (1ULL << 2)
+
+/**

lib/librte_ethdev/rte_flow.h int

Quoted 10 lines
lib/librte_ethdev/rte_flow.h +10 -0
+ * Restore information structure to communicate the current packet 
+processing
+ * state when some of the processing pipeline is done in hardware 
+and should
+ * continue in software.
+ */
+__rte_experimental
+struct rte_flow_restore_info {
+	/**
+	 * Bitwise flags (RTE_FLOW_RESTORE_INFO_*) to indicate validation

of

Quoted 7 lines

lib/librte_ethdev/rte_flow.h int · line 3389

Quoted 4 lines
lib/librte_ethdev/rte_flow.h +4 -0
+	 * other fields in struct rte_flow_restore_info.
+	 */
+	uint64_t flags;
+	uint32_t group_id; /**< Group ID. */

What is the group ID here?

Flow group ID where partially offloaded packed missed.

Quoted 12 lines

lib/librte_ethdev/rte_flow.h int · line 3398

Quoted 9 lines
lib/librte_ethdev/rte_flow.h +9 -0
+	struct rte_flow_tunnel tunnel; /**< Tunnel information. */ };
+
+/**
+ * Allocate an array of actions to be used in rte_flow_create, to 
+implement
+ * tunnel-decap-set for the given tunnel.
+ * Sample usage:
+ *   actions vxlan_decap / tunnel-decap-set(tunnel properties) /
+ *            jump group 0 / end

Why is jump to group used in example above? Is it mandatory?

JUMP action is not strictly required. Application may use any terminating action. The most common case however is jump.

Quoted 11 lines

lib/librte_ethdev/rte_flow.h int · line 3406

Quoted 8 lines
lib/librte_ethdev/rte_flow.h +8 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] tunnel
+ *   Tunnel properties.
+ * @param[out] actions
+ *   Array of actions to be allocated by the PMD. This array should be
+ *   concatenated with the actions array provided to rte_flow_create.

Please, specify concatenation order explicitly.

PMD actions precede application actions.
I'll update that spec in next version.

Quoted 12 lines
Quoted 12 lines
lib/librte_ethdev/rte_flow.h +12 -0
+ * @param[out] num_of_actions
+ *   Number of actions allocated.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_decap_set(uint16_t port_id,
Quoted 9 lines

lib/librte_ethdev/rte_flow.h int · line 3422

Quoted 3 lines
lib/librte_ethdev/rte_flow.h +3 -0
+			  struct rte_flow_tunnel *tunnel,
+			  struct rte_flow_action **actions,
+			  uint32_t *num_of_actions,

Why does approach to specify actions differ here? I.e. array of specified size vs END-terminated array? Must the actions array be END-terminated here?
It must be a strong reason to do it and it should be explained.

PMD actions returned in rte_flow_tunnel_decap_set() concatenated with application actions. Actions array produced by concatenation is passed to rte_flow_create() and must be END terminated. PMD actions array is intermediate parameter and does not require END termination.

Quoted 13 lines
Quoted 13 lines
lib/librte_ethdev/rte_flow.h +13 -0
+			  struct rte_flow_error *error);
+
+/**
+ * Allocate an array of items to be used in rte_flow_create, to 
+implement
+ * tunnel-match for the given tunnel.
+ * Sample usage:
+ *   pattern tunnel-match(tunnel properties) / outer-header-matches /
+ *           inner-header-matches / end
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] tunnel
Quoted 9 lines

lib/librte_ethdev/rte_flow.h int · line 3437

Quoted 4 lines
lib/librte_ethdev/rte_flow.h +4 -0
+ *   Tunnel properties.
+ * @param[out] items
+ *   Array of items to be allocated by the PMD. This array should be
+ *   concatenated with the items array provided to rte_flow_create.

Concatenation order/rules should be described.
Since it is an output which entity does the concatenation. Is it allowed to refine PMD rules in application rule specification?

PMD items precede application items.
I'll update this section too.
I'm not sure about the last question about rules refine. Please elaborate.

Quoted 9 lines
Quoted 9 lines
lib/librte_ethdev/rte_flow.h +9 -0
+ * @param[out] num_of_items
+ *   Number of items allocated.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
Quoted 9 lines

lib/librte_ethdev/rte_flow.h int · line 3452

Quoted 6 lines
lib/librte_ethdev/rte_flow.h +6 -0
+__rte_experimental
+int
+rte_flow_tunnel_match(uint16_t port_id,
+		      struct rte_flow_tunnel *tunnel,
+		      struct rte_flow_item **items,
+		      uint32_t *num_of_items,

Same as above for actions.

PMD items returned in rte_flow_tunnel_match () concatenated with application items. Items array produced by concatenation is passed to rte_flow_create() and must be END terminated. PMD items array is intermediate parameter and does not require END termination.

Quoted 20 lines

lib/librte_ethdev/rte_flow.h int

Quoted 5 lines
lib/librte_ethdev/rte_flow.h +5 -0
+		      struct rte_flow_error *error);
+
+/**
+ * Populate the current packet processing state, if exists, for the 
+given

mbuf.

Quoted 14 lines
lib/librte_ethdev/rte_flow.h +14 -0
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] m
+ *   Mbuf struct.
+ * @param[out] info
+ *   Restore information. Upon success contains the HW state.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
Quoted 9 lines

lib/librte_ethdev/rte_flow.h int · line 3475

Quoted 5 lines
lib/librte_ethdev/rte_flow.h +5 -0
+__rte_experimental
+int
+rte_flow_tunnel_get_restore_info(uint16_t port_id,
+				 struct rte_mbuf *m,
+				 struct rte_flow_restore_info *info,

Is it suggesting to make a copy of the restore info for each mbuf? It sounds very expensive. Could you share your thoughts about it.

Restore info may be different for each packet. For example, if application declared tunnel info with tunnel type only, restore info will have outer header data as well.

Quoted 17 lines
Quoted 17 lines
lib/librte_ethdev/rte_flow.h +17 -0
+				 struct rte_flow_error *error);
+
+/**
+ * Release the action array as allocated by rte_flow_tunnel_decap_set.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] actions
+ *   Array of actions to be released.
+ * @param[in] num_of_actions
+ *   Number of elements in actions array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
Quoted 9 lines

lib/librte_ethdev/rte_flow.h int · line 3498

Quoted 6 lines
lib/librte_ethdev/rte_flow.h +6 -0
+ */
+__rte_experimental
+int
+rte_flow_tunnel_action_decap_release(uint16_t port_id,
+				     struct rte_flow_action *actions,
+				     uint32_t num_of_actions,

Same question as above for actions and items specification approach.

PMD items and actions are intermediate parameters used by application to create arguments for rte_flow_create() call.

Quoted 17 lines
Quoted 17 lines
lib/librte_ethdev/rte_flow.h +17 -0
+				     struct rte_flow_error *error);
+
+/**
+ * Release the item array as allocated by rte_flow_tunnel_match.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] items
+ *   Array of items to be released.
+ * @param[in] num_of_items
+ *   Number of elements in item array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
Quoted 9 lines

lib/librte_ethdev/rte_flow.h int · line 3521

Quoted 6 lines
lib/librte_ethdev/rte_flow.h +6 -0
+ */
+__rte_experimental
+int
+rte_flow_tunnel_item_release(uint16_t port_id,
+			     struct rte_flow_item *items,
+			     uint32_t num_of_items,

Same question as above for actions and items specification approach.

PMD items and actions are intermediate parameters used by application to create arguments for rte_flow_create() call.

Quoted 7 lines
Quoted 4 lines
lib/librte_ethdev/rte_flow.h +1 -0
+			     struct rte_flow_error *error);
 #ifdef __cplusplus
 }
 #endif

[snip]

Quoted 6 lines

Andrew.

(Right now it is hard to fully imagine how to deal with it. And it looks like a shim to vendor-specific API. May be I'm wrong. Hopefully the next version will have PMD implementation example and it will shed a bit more light on it.)

The main idea of this API is to hide the internal logic and best practices of specific vendors. For example, one vendor may use internal registers to save outer header while other vendor will only decap packet at the final stage.

I hope that examples above give you better understanding of the API.

PMD implementation is in progress.
However, we are in contact with other vendors that also interested implementing this API. Since we don't want to block their progress it's important to reach conclusion on general API parts. In any case, I'll be more than happy to get your review on PMD.

#12 lore raw
In reply to Gregory Etelson
Quoted 90 lines · Gregory Etelson

Hardware vendors implement tunneled traffic offload techniques differently. Although RTE flow API provides tools capable to offload all sorts of network stacks, software application must reference this hardware differences in flow rules compilation. As the result tunneled traffic flow rules that utilize hardware capabilities can be different for the same traffic.

Tunnel port offload proposed in [1] provides software application with unified rules model for tunneled traffic regardless underlying hardware.
- The model introduces a concept of a virtual tunnel port (VTP).
- The model uses VTP to offload ingress tunneled network traffic with RTE flow rules.
- The model is implemented as set of helper functions. Each PMD implements VTP offload according to underlying hardware offload capabilities. Applications must query PMD for VTP flow items / actions before using in creation of a VTP flow rule.

The model components:
- Virtual Tunnel Port (VTP) is a stateless software object that describes tunneled network traffic. VTP object usually contains descriptions of outer headers, tunnel headers and inner headers.
- Tunnel Steering flow Rule (TSR) detects tunneled packets and delegates them to tunnel processing infrastructure, implemented in PMD for optimal hardware utilization, for further processing.
- Tunnel Matching flow Rule (TMR) verifies packet configuration and runs offload actions in case of a match.

Application actions:
1 Initialize VTP object according to tunnel
network parameters.
2 Create TSR flow rule:
2.1 Query PMD for VTP actions: application can query for VTP actions
more than once
int
rte_flow_tunnel_decap_set(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_action **pmd_actions, uint32_t *num_of_pmd_actions, struct rte_flow_error *error);

2.2 Integrate PMD actions into TSR actions list. 2.3 Create TSR flow rule:
flow create <port> group 0
match {tunnel items} / end
actions {PMD actions} / {App actions} / end

3 Create TMR flow rule:
3.1 Query PMD for VTP items: application can query for VTP items
more than once
int
rte_flow_tunnel_match(uint16_t port_id,
struct rte_flow_tunnel *tunnel, struct rte_flow_item **pmd_items, uint32_t *num_of_pmd_items, struct rte_flow_error *error);

3.2 Integrate PMD items into TMR items list:
3.3 Create TMR flow rule
flow create <port> group 0
match {PMD items} / {APP items} / end
actions {offload actions} / end

The model provides helper function call to restore packets that miss tunnel TMR rules to its original state:
int
rte_flow_get_restore_info(uint16_t port_id,
struct rte_mbuf *mbuf,
struct rte_flow_restore_info *info, struct rte_flow_error *error);

rte_tunnel object filled by the call inside rte_flow_restore_info *info parameter can be used by the application to create new TMR rule for that tunnel.

The model requirements:
Software application must initialize rte_tunnel object with tunnel parameters before calling rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().

PMD actions array obtained in rte_flow_tunnel_decap_set() must be released by application with rte_flow_action_release() call. Application can release the actionsfter TSR rule was created.

PMD items array obtained with rte_flow_tunnel_match() must be released by application with rte_flow_item_release() call. Application can release the items after rule was created. However, if the application needs to create additional TMR rule for the same tunnel it will need to obtain PMD items again.

Quoted 4 lines

Application cannot destroy rte_tunnel object before it releases all PMD actions & PMD items referencing that tunnel.

[1] https://mails.dpdk.org/archives/dev/2020-June/169656.html

Three copies of the above text here, in 2/2 description and 2/2 content in DPDK documentation is too much. IMHO, it should only one place in the documentation with brief summary in patch/series description.

#13 lore raw

v2 cover Tunnel Offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (3):
ethdev: allow negative values in flow rule types net/mlx5: implement tunnel offload API app/testpmd: support tunnel offload API

 app/test-pmd/cmdline_flow.c              | 102 ++++-
 app/test-pmd/config.c                    | 147 +++++++-
 app/test-pmd/testpmd.c                   |   5 +-
 app/test-pmd/testpmd.h                   |  27 +-
 app/test-pmd/util.c                      |  30 +-
 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++
 drivers/net/mlx5/linux/mlx5_os.c         |  14 +
 drivers/net/mlx5/mlx5.c                  |   6 +
 drivers/net/mlx5/mlx5.h                  |   4 +
 drivers/net/mlx5/mlx5_flow.c             | 453 +++++++++++++++++++++++
 drivers/net/mlx5/mlx5_flow.h             |  49 +++
 drivers/net/mlx5/mlx5_flow_dv.c          |  71 +++-
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 142 ++++++-
 lib/librte_ethdev/rte_flow.h             | 195 ++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++
 16 files changed, 1370 insertions(+), 17 deletions(-)
Signature · 1 line
2.25.1
#14 lore raw

PATCH v2 1/4 ethdev: allow negative values in flow rule types

From: Gregory Etelson <[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

RTE flow library functions cannot work with PMD private items and actions (elements) because RTE flow has no API to query PMD flow object size. In the patch, PMD flow elements use object pointer. RTE flow library functions handle PMD element object size as size of a pointer. PMD handles its objects internally.

---
v2:
* Update commit log

---
 lib/librte_ethdev/rte_flow.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
lib/librte_ethdev/rte_flow.c +24 -6
index f8fdd68fe9..9905426bc9 100644
@@ -564,7 +564,12 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (uint32_t)item->type <= INT_MAX ?
+			rte_flow_desc_item[item->type].size :
+			sizeof(void *);
 		rte_memcpy(buf, data, (size > off ? off : size));
 		break;
 	}
@@ -667,7 +672,12 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_action[action->type].size;
+		/**
+		 * allow PMD private flow action
+		 */
+		off = (uint32_t)action->type <= INT_MAX ?
+			rte_flow_desc_action[action->type].size :
+			sizeof(void *);
 		rte_memcpy(buf, action->conf, (size > off ? off : size));
 		break;
 	}
@@ -709,8 +719,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-		    !rte_flow_desc_item[src->type].name)
+		/**
+		 * allow PMD private flow item
+		 */
+		if (((uint32_t)src->type <= INT_MAX) &&
+			((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+		    !rte_flow_desc_item[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
 				 "cannot convert unknown item type");
@@ -798,8 +812,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-		    !rte_flow_desc_action[src->type].name)
+		/**
+		 * allow PMD private flow action
+		 */
+		if (((uint32_t)src->type <= INT_MAX) &&
+		    ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+		    !rte_flow_desc_action[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
 				 src, "cannot convert unknown action type");
Signature · 1 line
2.25.1
#15 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Quoted 11 lines · Gregory Etelson

From: Gregory Etelson <[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

While we are reviewing this, some quick comment/questions..

Doesn't this go against the above "PMD
items & actions usually are not exposed to application and are not used to create RTE flows."?
Why would an application try to use PMD specific private types? Isn't this contrary to having a standard API?

Quoted 87 lines

RTE flow library functions cannot work with PMD private items and actions (elements) because RTE flow has no API to query PMD flow object size. In the patch, PMD flow elements use object pointer. RTE flow library functions handle PMD element object size as size of a pointer. PMD handles its objects internally.

---
v2:
* Update commit log

---
 lib/librte_ethdev/rte_flow.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
lib/librte_ethdev/rte_flow.c +12 -2
index f8fdd68fe9..9905426bc9 100644
@@ -564,7 +564,12 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
                }
                break;
        default:
-               off = rte_flow_desc_item[item->type].size;
+               /**
+                * allow PMD private flow item
+                */
+               off = (uint32_t)item->type <= INT_MAX ?
+                       rte_flow_desc_item[item->type].size :
+                       sizeof(void *);
                rte_memcpy(buf, data, (size > off ? off : size));
                break;
        }
@@ -667,7 +672,12 @@ rte_flow_conv_action_conf(void *buf, const size_t
 size,
                }
                break;
        default:
-               off = rte_flow_desc_action[action->type].size;
+               /**
+                * allow PMD private flow action
+                */
+               off = (uint32_t)action->type <= INT_MAX ?
+                       rte_flow_desc_action[action->type].size :
+                       sizeof(void *);
                rte_memcpy(buf, action->conf, (size > off ? off : size));
                break;
        }
lib/librte_ethdev/rte_flow.c +5 -2
@@ -709,8 +719,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
        unsigned int i;
 
        for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-               if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-                   !rte_flow_desc_item[src->type].name)
+               /**
+                * allow PMD private flow item
+                */
+               if (((uint32_t)src->type <= INT_MAX) &&
+                       ((size_t)src->type >= RTE_DIM(rte_flow_desc_item)
||
+                   !rte_flow_desc_item[src->type].name))
                        return rte_flow_error_set
                                (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM,
src,
                                 "cannot convert unknown item type");
lib/librte_ethdev/rte_flow.c +6 -2
@@ -798,8 +812,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
        unsigned int i;
 
        for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-               if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-                   !rte_flow_desc_action[src->type].name)
+               /**
+                * allow PMD private flow action
+                */
+               if (((uint32_t)src->type <= INT_MAX) &&
+                   ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+                   !rte_flow_desc_action[src->type].name))
                        return rte_flow_error_set
                                (error, ENOTSUP,
 RTE_FLOW_ERROR_TYPE_ACTION,

src, "cannot convert unknown action
type");
--
2.25.1

#16 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Quoted 15 lines · Ajit Khaparde

On Tue, Sep 8, 2020 at 1:16 PM Gregory Etelson <[email protected] <mailto:[email protected]>> wrote:

From: Gregory Etelson <[email protected]
<mailto:[email protected]>>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

Quoted 7 lines

While we are reviewing this, some quick comment/questions..

Doesn't this go against the above "PMD
items & actions usually are not exposed to application and are not used to create RTE flows."?
Why would an application try to use PMD specific private types? Isn't this contrary to having a standard API?

+1

#17 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Subject: Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types On 9/15/20 7:36 AM, Ajit Khaparde wrote:
On Tue, Sep 8, 2020 at 1:16 PM Gregory Etelson <[email protected]<mailto:[email protected]>> wrote:
From: Gregory Etelson <[email protected]<mailto:[email protected]>>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.
While we are reviewing this, some quick comment/questions..

Doesn't this go against the above "PMD
items & actions usually are not exposed to application and are not used to create RTE flows."?
Why would an application try to use PMD specific private types? Isn't this contrary to having a standard API?

+1
PMD items and actions obtained in that patch are not intended to be used by application.
In general, application is not aware about content it receives from PMD. This is a special case when application receives opaque element from PMD and passes it back.

#18 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

From: Gregory Etelson
Sent: Tuesday, September 15, 2020 13:27
To: Andrew Rybchenko <[email protected]>; Ajit Khaparde <[email protected]>
Cc: dpdk-dev <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Ori Kam <[email protected]>; Gregory Etelson <[email protected]>; Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Subject: Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types On 9/15/20 7:36 AM, Ajit Khaparde wrote:
On Tue, Sep 8, 2020 at 1:16 PM Gregory Etelson <mailto:[email protected]> wrote:
From: Gregory Etelson <mailto:[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.
While we are reviewing this, some quick comment/questions..

Doesn't this go against the above "PMD
items & actions usually are not exposed to application and are not used to create RTE flows."?
Why would an application try to use PMD specific private types? Isn't this contrary to having a standard API?

+1

I would like to clarify the purpose and use of private elements patch.
That patch is prerequisite for [PATCH v2 2/4] ethdev: tunnel offload model patch.
The tunnel offload API provides unified hardware independent model to offload tunneled packets, match on packet headers in hardware and to restore outer headers of partially offloaded packets. The model implementation depends on hardware capabilities. For example, if hardware supports inner nat, it can do nat first and postpone decap to the end, while other hardware that cannot do inner nat must decap first and run nat actions afterwards. Such hardware has to save outer header in some hardware context, register or memory, for application to restore a packet later, if needed. Also, in this case the exact solution depends on PMD because of limited number of hardware contexts.
Although application working with DKDK can implement all these requirements with existing flow rules API, it will have to address each hardware specifications separately.
To solve this limitation we selected design where application quires PMD for actions, or items, that are optimal for a hardware that PMD represents. Result can be a mixture of RTE and PMD private elements - it's up to PMD implementation. Application passes these elements back to PMD as a flow rule recipe that's already optimal for underlying hardware.
If PMD has private elements in such rule items or actions, these private elements must not be rejected by RTE layer.

I hope it helps to understand what this model is trying to achieve. Did that clarify your concerns ?

#19 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Quoted 46 lines · Gregory Etelson

From: Gregory Etelson
Sent: Tuesday, September 15, 2020 13:27
To: Andrew Rybchenko <[email protected]>; Ajit Khaparde <[email protected]>
Cc: dpdk-dev <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Ori Kam <[email protected]>; Gregory Etelson <[email protected]>; Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Subject: Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types On 9/15/20 7:36 AM, Ajit Khaparde wrote:
On Tue, Sep 8, 2020 at 1:16 PM Gregory Etelson <mailto:[email protected]> wrote:
From: Gregory Etelson <mailto:[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.
While we are reviewing this, some quick comment/questions..

Doesn't this go against the above "PMD
items & actions usually are not exposed to application and are not used to create RTE flows."?
Why would an application try to use PMD specific private types? Isn't this contrary to having a standard API?

+1

I would like to clarify the purpose and use of private elements patch.
That patch is prerequisite for [PATCH v2 2/4] ethdev: tunnel offload model patch.
The tunnel offload API provides unified hardware independent model to offload tunneled packets, match on packet headers in hardware and to restore outer headers of partially offloaded packets. The model implementation depends on hardware capabilities. For example, if hardware supports inner nat, it can do nat first and postpone decap to the end, while other hardware that cannot do inner nat must decap first and run nat actions afterwards. Such hardware has to save outer header in some hardware context, register or memory, for application to restore a packet later, if needed. Also, in this case the exact solution depends on PMD because of limited number of hardware contexts.
Although application working with DKDK can implement all these requirements with existing flow rules API, it will have to address each hardware specifications separately.
To solve this limitation we selected design where application quires PMD for actions, or items, that are optimal for a hardware that PMD represents. Result can be a mixture of RTE and PMD private elements - it's up to PMD implementation. Application passes these elements back to PMD as a flow rule recipe that's already optimal for underlying hardware.
If PMD has private elements in such rule items or actions, these private elements must not be rejected by RTE layer.

Quoted 2 lines

I hope it helps to understand what this model is trying to achieve. Did that clarify your concerns ?

There is a very simple question which I can't answer after reading it.
Why these PMD specific actions and items do not bind application to a specific vendor. If it binds, it should be clearly stated in the description. If no, I'd like to understand why since opaque actions/items are not really well defined and hardly portable across vendors.

#20 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Hi Andrew,

Quoted 74 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Thursday, September 17, 2020 9:50 AM

Quoted 3 lines · Gregory Etelson

From: Gregory Etelson
Sent: Tuesday, September 15, 2020 13:27
To: Andrew Rybchenko <[email protected]>; Ajit Khaparde

<[email protected]>

Quoted 1 line
Cc dpdk-dev <[email protected]>; Matan Azrad <[email protected]>; Raslan

Darawsheh <[email protected]>; Ori Kam <[email protected]>; Gregory Etelson <[email protected]>; Ori Kam <[email protected]>; NBU- Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>

Quoted 1 line

Subject: RE: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow

rule types

Quoted 2 lines

Subject: Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow

rule types

Quoted 2 lines · Ajit Khaparde

On Tue, Sep 8, 2020 at 1:16 PM Gregory Etelson

Quoted 18 lines · <mailto:[email protected]> wrote:

From: Gregory Etelson <mailto:[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.
While we are reviewing this, some quick comment/questions..

Doesn't this go against the above "PMD
items & actions usually are not exposed to application and are not used to create RTE flows."?
Why would an application try to use PMD specific private types? Isn't this contrary to having a standard API?

Quoted 4 lines

+1

I would like to clarify the purpose and use of private elements patch. That patch is prerequisite for [PATCH v2 2/4] ethdev: tunnel offload model

patch.

Quoted 1 line

The tunnel offload API provides unified hardware independent model to

offload tunneled packets,

Quoted 1 line

match on packet headers in hardware and to restore outer headers of

partially offloaded packets.

Quoted 1 line

The model implementation depends on hardware capabilities. For example,

if hardware supports inner nat,

Quoted 1 line

it can do nat first and postpone decap to the end, while other hardware that

cannot do inner nat must decap first

Quoted 1 line

and run nat actions afterwards. Such hardware has to save outer header in

some hardware context,

Quoted 1 line

register or memory, for application to restore a packet later, if needed. Also,

in this case the exact solution

Quoted 2 lines

depends on PMD because of limited number of hardware contexts. Although application working with DKDK can implement all these

requirements with existing flow rules API,

Quoted 2 lines

it will have to address each hardware specifications separately. To solve this limitation we selected design where application quires PMD for

actions, or items,

Quoted 1 line

that are optimal for a hardware that PMD represents. Result can be a

mixture of RTE and PMD private elements -

Quoted 1 line

it's up to PMD implementation. Application passes these elements back to

PMD as a flow rule recipe

Quoted 2 lines

that's already optimal for underlying hardware.
If PMD has private elements in such rule items or actions, these private

elements must not be rejected by RTE layer.

Quoted 3 lines

I hope it helps to understand what this model is trying to achieve. Did that clarify your concerns ?

Quoted 7 lines

There is a very simple question which I can't answer after reading it.
Why these PMD specific actions and items do not bind application to a specific vendor. If it binds, it should be clearly stated in the description. If no, I'd like to understand why since opaque actions/items are not really well defined and hardly portable across vendors.

You are correct, when looking at this patch as a stand a lone
patch using such action / items does bind the application to specific PMD.
first sometimes it is required, for example one vendor may introduce private action to support some key costumer, or enable feature that is not supported using standard rte flow API.

The main reason for this patch is the tunnel API[1] as stated in the reply
from Gregory, the tunnel API exposes a public function that returns a list of
actions / items. The list is generated by the PMD, so using the API is not binding
since it is generic, but the action / items returned are private but the application is not aware of those actions / items, from it's point of view it called a generic function and got actions that are configured to do the requested job. All the application needs to do is send the actions / item as actions / item when calling flow create.

Does this answer your question?

[1] https://patches.dpdk.org/patch/76931/

#21 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Hi Ori,

Quoted 84 lines · Ori Kam

Hi Andrew,

Quoted 74 lines

-----Original Message-----
From: Andrew Rybchenko <[email protected]>
Sent: Thursday, September 17, 2020 9:50 AM

Quoted 3 lines · Gregory Etelson

From: Gregory Etelson
Sent: Tuesday, September 15, 2020 13:27
To: Andrew Rybchenko <[email protected]>; Ajit Khaparde

<[email protected]>

Quoted 1 line
Cc dpdk-dev <[email protected]>; Matan Azrad <[email protected]>; Raslan

Darawsheh <[email protected]>; Ori Kam <[email protected]>; Gregory Etelson <[email protected]>; Ori Kam <[email protected]>; NBU- Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>

Quoted 1 line

Subject: RE: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow

rule types

Quoted 2 lines

Subject: Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow

rule types

Quoted 2 lines · Ajit Khaparde

On Tue, Sep 8, 2020 at 1:16 PM Gregory Etelson

Quoted 18 lines · <mailto:[email protected]> wrote:

From: Gregory Etelson <mailto:[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.
While we are reviewing this, some quick comment/questions..

Doesn't this go against the above "PMD
items & actions usually are not exposed to application and are not used to create RTE flows."?
Why would an application try to use PMD specific private types? Isn't this contrary to having a standard API?

Quoted 4 lines

+1

I would like to clarify the purpose and use of private elements patch. That patch is prerequisite for [PATCH v2 2/4] ethdev: tunnel offload model

patch.

Quoted 1 line

The tunnel offload API provides unified hardware independent model to

offload tunneled packets,

Quoted 1 line

match on packet headers in hardware and to restore outer headers of

partially offloaded packets.

Quoted 1 line

The model implementation depends on hardware capabilities. For example,

if hardware supports inner nat,

Quoted 1 line

it can do nat first and postpone decap to the end, while other hardware that

cannot do inner nat must decap first

Quoted 1 line

and run nat actions afterwards. Such hardware has to save outer header in

some hardware context,

Quoted 1 line

register or memory, for application to restore a packet later, if needed. Also,

in this case the exact solution

Quoted 2 lines

depends on PMD because of limited number of hardware contexts. Although application working with DKDK can implement all these

requirements with existing flow rules API,

Quoted 2 lines

it will have to address each hardware specifications separately. To solve this limitation we selected design where application quires PMD for

actions, or items,

Quoted 1 line

that are optimal for a hardware that PMD represents. Result can be a

mixture of RTE and PMD private elements -

Quoted 1 line

it's up to PMD implementation. Application passes these elements back to

PMD as a flow rule recipe

Quoted 2 lines

that's already optimal for underlying hardware.
If PMD has private elements in such rule items or actions, these private

elements must not be rejected by RTE layer.

Quoted 3 lines

I hope it helps to understand what this model is trying to achieve. Did that clarify your concerns ?

Quoted 7 lines

There is a very simple question which I can't answer after reading it.
Why these PMD specific actions and items do not bind application to a specific vendor. If it binds, it should be clearly stated in the description. If no, I'd like to understand why since opaque actions/items are not really well defined and hardly portable across vendors.

Quoted 4 lines

You are correct, when looking at this patch as a stand a lone
patch using such action / items does bind the application to specific PMD.
first sometimes it is required, for example one vendor may introduce private action to support some key costumer, or enable feature that is not supported using standard rte flow API.

Good. So I understand it correctly.

Quoted 7 lines

The main reason for this patch is the tunnel API[1] as stated in the reply
from Gregory, the tunnel API exposes a public function that returns a list of
actions / items. The list is generated by the PMD, so using the API is not binding
since it is generic, but the action / items returned are private but the application is not aware of those actions / items, from it's point of view it called a generic function and got actions that are configured to do the requested job. All the application needs to do is send the actions / item as actions / item when calling flow create.

Does this answer your question?

Yes, many thanks. I'm still trying to put the feature design in my head and your explanations helped a lot. May be it is just the same words as before, but in a bit different order and highlights.

Quoted 2 lines

[1] https://patches.dpdk.org/patch/76931/

#22 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

In reply to Andrew Rybchenko
Quoted 60 lines · Gregory Etelson
Quoted 15 lines

From: Gregory Etelson
Sent: Tuesday, September 15, 2020 13:27
To: Andrew Rybchenko <[email protected]>; Ajit Khaparde <[email protected]>
Cc: dpdk-dev <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Ori Kam <[email protected]>; Gregory Etelson <[email protected]>; Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Subject: Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types On 9/15/20 7:36 AM, Ajit Khaparde wrote:
On Tue, Sep 8, 2020 at 1:16 PM Gregory Etelson

Quoted 17 lines · <mailto:[email protected]> wrote:

From: Gregory Etelson <mailto:[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.
While we are reviewing this, some quick comment/questions..

Doesn't this go against the above "PMD items & actions usually are not exposed to application and are not used to create RTE flows."? Why would an application try to use PMD specific private types? Isn't this contrary to having a standard API?

Quoted 4 lines

+1

I would like to clarify the purpose and use of private elements patch. That patch is prerequisite for [PATCH v2 2/4] ethdev: tunnel offload model

patch.

Quoted 2 lines

The tunnel offload API provides unified hardware independent model to offload tunneled packets, match on packet headers in hardware and to

restore outer headers of partially offloaded packets.

Quoted 5 lines

The model implementation depends on hardware capabilities. For example, if hardware supports inner nat, it can do nat first and postpone decap to the end, while other hardware that cannot do inner nat must decap first and run nat actions afterwards. Such hardware has to save outer header in some hardware context, register or memory, for

application to restore a packet later, if needed. Also, in this case the exact solution depends on PMD because of limited number of hardware contexts.

Quoted 2 lines

Although application working with DKDK can implement all these requirements with existing flow rules API, it will have to address each

hardware specifications separately.

Quoted 4 lines

To solve this limitation we selected design where application quires PMD for actions, or items, that are optimal for a hardware that PMD represents. Result can be a mixture of RTE and PMD private elements - it's up to PMD implementation. Application passes these elements back to

PMD as a flow rule recipe that's already optimal for underlying hardware.

Quoted 1 line

If PMD has private elements in such rule items or actions, these private

elements must not be rejected by RTE layer.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

I hope it helps to understand what this model is trying to achieve. Did that clarify your concerns ?

There is a very simple question which I can't answer after reading it. Why these PMD specific actions and items do not bind application to a specific vendor. If it binds, it should be clearly stated in the description. If no, I'd like to understand why since opaque actions/items are not really well defined and hardly portable across vendors.

Tunnel Offload API does not bind application to a vendor.
One of the main goals of that model is to provide application with vendor/hardware independent solution. PMD transfer to application an array of items. Application passes that array back to PMD as opaque data, in rte_flow_create(), without reviewing the array content. Therefore, if there are internal PMD actions in the array, they have no effect on application.
Consider the following application code example:

/* get PMD actions that implement tunnel offload */ rte_tunnel_decap_set(&tunnel, &pmd_actions, pmd_actions_num, error);

/* compile an array of actions to create flow rule */
memcpy(actions, pmd_actions, pmd_actions_num * sizeof(actions[0])); memcpy(actions + pmd_actions_num, app_actions, app_actions_num * sizeof(actions[0]));

/* create flow rule*/
rte_flow_create(port_id, attr, pattern, actions, error);

vendor A provides pmd_actions_A = {va1, va2 …. vaN}
vendor B provides pmd_actions_B = {vb1}
Regardless of pmd_actions content, application code will not change. However, each PMD will receive exact, hardware related, actions for tunnel offload.

#23 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Quoted 83 lines · Gregory Etelson
Quoted 60 lines · Gregory Etelson
Quoted 15 lines

From: Gregory Etelson
Sent: Tuesday, September 15, 2020 13:27
To: Andrew Rybchenko <[email protected]>; Ajit Khaparde <[email protected]>
Cc: dpdk-dev <[email protected]>; Matan Azrad <[email protected]>; Raslan Darawsheh <[email protected]>; Ori Kam <[email protected]>; Gregory Etelson <[email protected]>; Ori Kam <[email protected]>; NBU-Contact-Thomas Monjalon <[email protected]>; Ferruh Yigit <[email protected]>
Subject: RE: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Subject: Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types On 9/15/20 7:36 AM, Ajit Khaparde wrote:
On Tue, Sep 8, 2020 at 1:16 PM Gregory Etelson

Quoted 17 lines · <mailto:[email protected]> wrote:

From: Gregory Etelson <mailto:[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.
While we are reviewing this, some quick comment/questions..

Doesn't this go against the above "PMD items & actions usually are not exposed to application and are not used to create RTE flows."? Why would an application try to use PMD specific private types? Isn't this contrary to having a standard API?

Quoted 4 lines

+1

I would like to clarify the purpose and use of private elements patch. That patch is prerequisite for [PATCH v2 2/4] ethdev: tunnel offload model

patch.

Quoted 2 lines

The tunnel offload API provides unified hardware independent model to offload tunneled packets, match on packet headers in hardware and to

restore outer headers of partially offloaded packets.

Quoted 5 lines

The model implementation depends on hardware capabilities. For example, if hardware supports inner nat, it can do nat first and postpone decap to the end, while other hardware that cannot do inner nat must decap first and run nat actions afterwards. Such hardware has to save outer header in some hardware context, register or memory, for

application to restore a packet later, if needed. Also, in this case the exact solution depends on PMD because of limited number of hardware contexts.

Quoted 2 lines

Although application working with DKDK can implement all these requirements with existing flow rules API, it will have to address each

hardware specifications separately.

Quoted 4 lines

To solve this limitation we selected design where application quires PMD for actions, or items, that are optimal for a hardware that PMD represents. Result can be a mixture of RTE and PMD private elements - it's up to PMD implementation. Application passes these elements back to

PMD as a flow rule recipe that's already optimal for underlying hardware.

Quoted 1 line

If PMD has private elements in such rule items or actions, these private

elements must not be rejected by RTE layer.

Quoted 1 line
Quoted 8 lines
Quoted 2 lines

I hope it helps to understand what this model is trying to achieve. Did that clarify your concerns ?

There is a very simple question which I can't answer after reading it. Why these PMD specific actions and items do not bind application to a specific vendor. If it binds, it should be clearly stated in the description. If no, I'd like to understand why since opaque actions/items are not really well defined and hardly portable across vendors.

Tunnel Offload API does not bind application to a vendor.
One of the main goals of that model is to provide application with vendor/hardware independent solution. PMD transfer to application an array of items. Application passes that array back to PMD as opaque data, in rte_flow_create(), without reviewing the array content. Therefore, if there are internal PMD actions in the array, they have no effect on application.
Consider the following application code example:

/* get PMD actions that implement tunnel offload */ rte_tunnel_decap_set(&tunnel, &pmd_actions, pmd_actions_num, error);

/* compile an array of actions to create flow rule */
memcpy(actions, pmd_actions, pmd_actions_num * sizeof(actions[0])); memcpy(actions + pmd_actions_num, app_actions, app_actions_num * sizeof(actions[0]));

Quoted 8 lines

/* create flow rule*/
rte_flow_create(port_id, attr, pattern, actions, error);

vendor A provides pmd_actions_A = {va1, va2 …. vaN}
vendor B provides pmd_actions_B = {vb1}
Regardless of pmd_actions content, application code will not change. However, each PMD will receive exact, hardware related, actions for tunnel offload.

Many thanks for explanations. I got it. I'll wait for the next version to take a look at code once again.

#24 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

In reply to Gregory Etelson
Quoted 31 lines · Gregory Etelson

From: Gregory Etelson <[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

RTE flow library functions cannot work with PMD private items and actions (elements) because RTE flow has no API to query PMD flow object size. In the patch, PMD flow elements use object pointer. RTE flow library functions handle PMD element object size as size of a pointer. PMD handles its objects internally.

---
v2:
* Update commit log

---
 lib/librte_ethdev/rte_flow.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
lib/librte_ethdev/rte_flow.c +0 -0
index f8fdd68fe9..9905426bc9 100644

lib/librte_ethdev/rte_flow.c rte_flow_conv_item_spec(void *buf, const size_t size, · line 570

Quoted 8 lines
lib/librte_ethdev/rte_flow.c +4 -1
@@ -564,7 +564,12 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (uint32_t)item->type <= INT_MAX ?

It looks inconsistent to cast to uint32_t and compare vs INT_MAX. It should be either cast to 'unsigned int' or compare vs INT32_MAX. I think cast to 'unsigned int' is better for 'enum' values.
But may be it should be 'int' and < 0 in fact to match the description that negative values are vendor-specific.

Quoted 6 lines
lib/librte_ethdev/rte_flow.c +2 -0
+			rte_flow_desc_item[item->type].size :
+			sizeof(void *);
 		rte_memcpy(buf, data, (size > off ? off : size));
 		break;
 	}

lib/librte_ethdev/rte_flow.c rte_flow_conv_action_conf(void *buf, const size_t size, · line 678

Quoted 8 lines
lib/librte_ethdev/rte_flow.c +4 -1
@@ -667,7 +672,12 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_action[action->type].size;
+		/**
+		 * allow PMD private flow action
+		 */
+		off = (uint32_t)action->type <= INT_MAX ?

Same

Quoted 6 lines
lib/librte_ethdev/rte_flow.c +2 -0
+			rte_flow_desc_action[action->type].size :
+			sizeof(void *);
 		rte_memcpy(buf, action->conf, (size > off ? off : size));
 		break;
 	}

lib/librte_ethdev/rte_flow.c rte_flow_conv_pattern(struct rte_flow_item *dst, · line 725

Quoted 9 lines
lib/librte_ethdev/rte_flow.c +4 -2
@@ -709,8 +719,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-		    !rte_flow_desc_item[src->type].name)
+		/**
+		 * allow PMD private flow item
+		 */
+		if (((uint32_t)src->type <= INT_MAX) &&

Same

Quoted 6 lines
lib/librte_ethdev/rte_flow.c +2 -0
+			((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+		    !rte_flow_desc_item[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
 				 "cannot convert unknown item type");

lib/librte_ethdev/rte_flow.c rte_flow_conv_actions(struct rte_flow_action *dst, · line 818

Quoted 9 lines
lib/librte_ethdev/rte_flow.c +4 -2
@@ -798,8 +812,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-		    !rte_flow_desc_action[src->type].name)
+		/**
+		 * allow PMD private flow action
+		 */
+		if (((uint32_t)src->type <= INT_MAX) &&

Same

Quoted 6 lines
lib/librte_ethdev/rte_flow.c +2 -0
+		    ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+		    !rte_flow_desc_action[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
 				 src, "cannot convert unknown action type");
#25 lore raw

Re: [dpdk-dev] [PATCH v2 1/4] ethdev: allow negative values in flow rule types

Quoted 42 lines · Gregory Etelson

lib/librte_ethdev/rte_flow.c rte_flow_conv_item_spec(void *buf, const size_t

Quoted 31 lines

From: Gregory Etelson <[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

RTE flow library functions cannot work with PMD private items and actions (elements) because RTE flow has no API to query PMD flow object size. In the patch, PMD flow elements use object pointer. RTE flow library functions handle PMD element object size as size of a pointer. PMD handles its objects internally.

---
v2:
* Update commit log

---
 lib/librte_ethdev/rte_flow.c | 30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)
(quoted diff) +0 -0

b/lib/librte_ethdev/rte_flow.c index f8fdd68fe9..9905426bc9 100644

lib/librte_ethdev/rte_flow.c +0 -0
@@ -564,7 +564,12 @@ rte_flow_conv_item_spec(void *buf, const size_t

size,

lib/librte_ethdev/rte_flow.c rte_flow_conv_item_spec(void *buf, const size_t size, · line 570

Quoted 8 lines
lib/librte_ethdev/rte_flow.c +4 -1
              }
              break;
      default:
-             off = rte_flow_desc_item[item->type].size;
+             /**
+              * allow PMD private flow item
+              */
+             off = (uint32_t)item->type <= INT_MAX ?
Quoted 6 lines

It looks inconsistent to cast to uint32_t and compare vs INT_MAX. It should be either cast to 'unsigned int' or compare vs INT32_MAX. I think cast to 'unsigned int' is better for 'enum' values.
But may be it should be 'int' and < 0 in fact to match the description that negative values are vendor-specific.

I'll update PMD private item verification to (int) item->type < 0
In the next patch release.
The same applies to PMD private actions verification

Quoted 61 lines

lib/librte_ethdev/rte_flow.c rte_flow_conv_action_conf(void *buf, const size_t

Quoted 6 lines
lib/librte_ethdev/rte_flow.c +2 -0
+                     rte_flow_desc_item[item->type].size :
+                     sizeof(void *);
              rte_memcpy(buf, data, (size > off ? off : size));
              break;
      }
@@ -667,7 +672,12 @@ rte_flow_conv_action_conf(void *buf, const size_t

size,

lib/librte_ethdev/rte_flow.c rte_flow_conv_action_conf(void *buf, const size_t size, · line 678

Quoted 8 lines
lib/librte_ethdev/rte_flow.c +4 -1
              }
              break;
      default:
-             off = rte_flow_desc_action[action->type].size;
+             /**
+              * allow PMD private flow action
+              */
+             off = (uint32_t)action->type <= INT_MAX ?

Same

Quoted 6 lines
lib/librte_ethdev/rte_flow.c +2 -0
+                     rte_flow_desc_action[action->type].size :
+                     sizeof(void *);
              rte_memcpy(buf, action->conf, (size > off ? off : size));
              break;
      }

lib/librte_ethdev/rte_flow.c rte_flow_conv_pattern(struct rte_flow_item *dst, · line 725

Quoted 9 lines
lib/librte_ethdev/rte_flow.c +4 -2
@@ -709,8 +719,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
      unsigned int i;
 
      for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-             if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-                 !rte_flow_desc_item[src->type].name)
+             /**
+              * allow PMD private flow item
+              */
+             if (((uint32_t)src->type <= INT_MAX) &&

Same

Quoted 5 lines
lib/librte_ethdev/rte_flow.c +2 -0
+                     ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+                 !rte_flow_desc_item[src->type].name))
                      return rte_flow_error_set
                              (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
                               "cannot convert unknown item type"); @@

lib/librte_ethdev/rte_flow.c rte_flow_conv_actions(struct rte_flow_action *dst, · line 818

Quoted 10 lines
lib/librte_ethdev/rte_flow.c +4 -3
-798,8 +812,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
      unsigned int i;
 
      for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-             if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-                 !rte_flow_desc_action[src->type].name)
+             /**
+              * allow PMD private flow action
+              */
+             if (((uint32_t)src->type <= INT_MAX) &&

Same

Quoted 7 lines
lib/librte_ethdev/rte_flow.c +2 -0
+                 ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+                 !rte_flow_desc_action[src->type].name))
                      return rte_flow_error_set
                              (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
                               src, "cannot convert unknown action

type");

#26 lore raw

PATCH v2 2/4 ethdev: tunnel offload model

In reply to Gregory Etelson

From: Eli Britstein <[email protected]>

Rte_flow API provides the building blocks for vendor agnostic flow classification offloads. The rte_flow match and action primitives are fine grained, thus enabling DPDK applications the flexibility to offload network stacks and complex pipelines.

Applications wishing to offload complex data structures (e.g. tunnel virtual ports) are required to use the rte_flow primitives, such as group, meta, mark, tag and others to model their high level objects.

The hardware model design for high level software objects is not trivial. Furthermore, an optimal design is often vendor specific.

The goal of this API is to provide applications with the hardware offload model for common high level software objects which is optimal in regards to the underlying hardware.

Tunnel ports are the first of such objects.

Tunnel ports
------------
Ingress processing of tunneled traffic requires the classification of the tunnel type followed by a decap action.

In software, once a packet is decapsulated the in_port field is changed to a virtual port representing the tunnel type. The outer header fields are stored as packet metadata members and may be matched by proceeding flows.

Openvswitch, for example, uses two flows:
1. classification flow - setting the virtual port representing the tunnel type For example: match on udp port 4789 actions=tnl_pop(vxlan_vport)
2. steering flow according to outer and inner header matches match on in_port=vxlan_vport and outer/inner header matches actions=forward to p ort X The benefits of multi-flow tables are described in [1].

Offloading tunnel ports
-----------------------
Tunnel ports introduce a new stateless field that can be matched on. Currently the rte_flow library provides an API to encap, decap and match on tunnel headers. However, there is no rte_flow primitive to set and match tunnel virtual ports.

There are several possible hardware models for offloading virtual tunnel port flows including, but not limited to, the following:
1. Setting the virtual port on a hw register using the rte_flow_action_mark/ rte_flow_action_tag/rte_flow_set_meta objects.
2. Mapping a virtual port to an rte_flow group
3. Avoiding the need to match on transient objects by merging multi-table flows to a single rte_flow rule.

Every approach has its pros and cons. The preferred approach should take into account the entire system architecture and is very often vendor specific.

The proposed rte_flow_tunnel_decap_set helper function (drafted below) is designed to provide a common, vendor agnostic, API for setting the virtual port value. The helper API enables PMD implementations to return vendor specific combination of rte_flow actions realizing the vendor's hardware model for setting a tunnel port. Applications may append the list of actions returned from the helper function when creating an rte_flow rule in hardware.

Similarly, the rte_flow_tunnel_match helper (drafted below) allows for multiple hardware implementations to return a list of fte_flow items.

Miss handling
-------------
Packets going through multiple rte_flow groups are exposed to hw misses due to partial packet processing. In such cases, the software should continue the packet's processing from the point where the hardware missed.

We propose a generic rte_flow_restore structure providing the state that was stored in hardware when the packet missed.

Currently, the structure will provide the tunnel state of the packet that missed, namely:
1. The group id that missed
2. The tunnel port that missed
3. Tunnel information that was stored in memory (due to decap action). In the future, we may add additional fields as more state may be stored in the device memory (e.g. ct_state).

Applications may query the state via a new rte_flow_tunnel_get_restore_info(mbuf) API, thus allowing a vendor specific implementation.

VXLAN Code example:
Assume application needs to do inner NAT on VXLAN packet. The first rule in group 0:

flow create <port id> ingress group 0
pattern eth / ipv4 / udp dst is 4789 / vxlan / end actions {pmd actions} / jump group 3 / end

First VXLAN packet that arrives matches the rule in group 0 and jumps to group 3 In group 3 the packet will miss since there is no flow to match and will be uploaded to application. Application will call rte_flow_get_restore_info() to get the packet outer header. Application will insert a new rule in group 3 to match outer and inner headers:

flow create <port id> ingress group 3
pattern {pmd items} / eth / ipv4 dst is 172.10.10.1 /
udp dst 4789 / vxlan vni is 10 /
ipv4 dst is 184.1.2.3 / end
actions set_ipv4_dst 186.1.1.1 / queue index 3 / end

Resulting of rules will be that VXLAN packet with vni=10, outer IPv4 dst=172.10.10.1 and inner IPv4 dst=184.1.2.3 will be received decaped on queue 3 with IPv4 dst=186.1.1.1

Note: Packet in group 3 is considered decaped. All actions in that group will be done on header that was inner before decap. Application may specify outer header to be matched on. It's PMD responsibility to translate these items to outer metadata.

API usage:
/**
* 1. Initiate RTE flow tunnel object
*/
const struct rte_flow_tunnel tunnel = {
.type = RTE_FLOW_ITEM_TYPE_VXLAN,
.tun_id = 10,
}

/**
* 2. Obtain PMD tunnel actions
*
* pmd_actions is an intermediate variable application uses to
* compile actions array
*/
struct rte_flow_action **pmd_actions; rte_flow_tunnel_decap_and_set(&tunnel, &pmd_actions,

                              &num_pmd_actions, &error);

/**
* 3. offload the first rule
* matching on VXLAN traffic and jumps to group 3
* (implicitly decaps packet)
*/
app_actions = jump group 3
rule_items = app_items; /** eth / ipv4 / udp / vxlan */ rule_actions = { pmd_actions, app_actions }; attr.group = 0;
flow_1 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 4. after flow creation application does not need to keep tunnel
* action resources.
*/
rte_flow_tunnel_action_release(port_id, pmd_actions,

                               num_pmd_actions);

/**
* 5. After partially offloaded packet miss because there was no
* matching rule handle miss on group 3
*/
struct rte_flow_restore_info info; rte_flow_get_restore_info(port_id, mbuf, &info, &error);

/**
* 6. Offload NAT rule:
*/
app_items = { eth / ipv4 dst is 172.10.10.1 / udp dst 4789 /

            vxlan vni is 10 / ipv4 dst is 184.1.2.3 }

app_actions = { set_ipv4_dst 186.1.1.1 / queue index 3 }

rte_flow_tunnel_match(&info.tunnel, &pmd_items,

                      &num_pmd_items,  &error);

rule_items = {pmd_items, app_items};
rule_actions = app_actions;
attr.group = info.group_id;
flow_2 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 7. Release PMD items after rule creation
*/
rte_flow_tunnel_item_release(port_id, pmd_items, num_pmd_items);

References
1. https://mails.dpdk.org/archives/dev/2020-June/index.html

---
v2:
* Update commit log

---
 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++++++++
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 195 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 5 files changed, 449 insertions(+)
doc/guides/prog_guide/rte_flow.rst +105 -0
index 3e5cd1e0d8..827ea0ca76 100644
@@ -3018,6 +3018,111 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Provide software application with unified rules model for tunneled traffic
+regardless underlying hardware.
+
+ - The model introduces a concept of a virtual tunnel port (VTP).
+ - The model uses VTP to offload ingress tunneled network traffic 
+   with RTE flow rules.
+ - The model is implemented as set of helper functions. Each PMD
+   implements VTP offload according to underlying hardware offload
+   capabilities.  Applications must query PMD for VTP flow
+   items / actions before using in creation of a VTP flow rule.
+
+The model components:
+
+- Virtual Tunnel Port (VTP) is a stateless software object that
+  describes tunneled network traffic.  VTP object usually contains
+  descriptions of outer headers, tunnel headers and inner headers.
+- Tunnel Steering flow Rule (TSR) detects tunneled packets and
+  delegates them to tunnel processing infrastructure, implemented
+  in PMD for optimal hardware utilization, for further processing.
+- Tunnel Matching flow Rule (TMR) verifies packet configuration and
+  runs offload actions in case of a match.
+
+Application actions:
+
+1 Initialize VTP object according to tunnel network parameters.
+
+2 Create TSR flow rule.
+
+2.1 Query PMD for VTP actions. Application can query for VTP actions more than once.
+
+  .. code-block:: c
+
+    int
+    rte_flow_tunnel_decap_set(uint16_t port_id,
+                              struct rte_flow_tunnel *tunnel,
+                              struct rte_flow_action **pmd_actions,
+                              uint32_t *num_of_pmd_actions,
+                              struct rte_flow_error *error);
+
+2.2 Integrate PMD actions into TSR actions list.
+
+2.3 Create TSR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {tunnel items} / end actions {PMD actions} / {App actions} / end
+
+3 Create TMR flow rule.
+
+3.1 Query PMD for VTP items. Application can query for VTP items more than once.
+
+    .. code-block:: c
+
+      int
+      rte_flow_tunnel_match(uint16_t port_id,
+                            struct rte_flow_tunnel *tunnel,
+                            struct rte_flow_item **pmd_items,
+                            uint32_t *num_of_pmd_items,
+                            struct rte_flow_error *error);
+
+3.2 Integrate PMD items into TMR items list.
+
+3.3 Create TMR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {PMD items} / {APP items} / end actions {offload actions} / end
+
+The model provides helper function call to restore packets that miss
+tunnel TMR rules to its original state:
+
+.. code-block:: c
+
+  int
+  rte_flow_get_restore_info(uint16_t port_id,
+                            struct rte_mbuf *mbuf,
+                            struct rte_flow_restore_info *info,
+                            struct rte_flow_error *error);
+
+rte_tunnel object filled by the call inside
+``rte_flow_restore_info *info parameter`` can be used by the application
+to create new TMR rule for that tunnel.
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+Application can release the actionsfter TSR rule was created.
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release the items after rule was created. However, if the application
+needs to create additional TMR rule for the same tunnel it will need
+to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
 
lib/librte_ethdev/rte_ethdev_version.map +5 -0
index 1212a17d32..8bb6b99d4a 100644
@@ -241,6 +241,11 @@ EXPERIMENTAL {
 	__rte_ethdev_trace_rx_burst;
 	__rte_ethdev_trace_tx_burst;
 	rte_flow_get_aged_flows;
+	rte_flow_tunnel_decap_set;
+	rte_flow_tunnel_match;
+	rte_flow_tunnel_get_restore_info;
+	rte_flow_tunnel_action_decap_release;
+	rte_flow_tunnel_item_release;
 };
 
 INTERNAL {
lib/librte_ethdev/rte_flow.c +112 -0

115 lines not on this page · raw message

lib/librte_ethdev/rte_flow.h +195 -0

201 lines not on this page · raw message

lib/librte_ethdev/rte_flow_driver.h +32 -0
index 881cc469b7..ad1d7a2cdc 100644
@@ -107,6 +107,38 @@ struct rte_flow_ops {
 		 void **context,
 		 uint32_t nb_contexts,
 		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_decap_set() */
+	int (*tunnel_decap_set)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_action **pmd_actions,
+		 uint32_t *num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_match() */
+	int (*tunnel_match)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_item **pmd_items,
+		 uint32_t *num_of_items,
+		 struct rte_flow_error *err);
+	/** See rte_flow_get_rte_flow_restore_info() */
+	int (*get_restore_info)
+		(struct rte_eth_dev *dev,
+		 struct rte_mbuf *m,
+		 struct rte_flow_restore_info *info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_action_tunnel_decap_release() */
+	int (*action_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_action *pmd_actions,
+		 uint32_t num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_item_release() */
+	int (*item_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_item *pmd_items,
+		 uint32_t num_of_items,
+		 struct rte_flow_error *err);
 };
 
 /**
Signature · 1 line
2.25.1
#27 lore raw

PATCH v2 3/4 net/mlx5: implement tunnel offload API

In reply to Gregory Etelson

From: Gregory Etelson <[email protected]>

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:
* tunnel_offload PMD parameter must be set to 1 to enable the feature.
* application cannot use MARK and META flow actions whith tunnel.
* offload JUMP action is restricted to steering tunnel rule only.

---
v2:
* introduce MLX5 PMD API implementation

---
 drivers/net/mlx5/linux/mlx5_os.c |  14 +
 drivers/net/mlx5/mlx5.c          |   6 +
 drivers/net/mlx5/mlx5.h          |   4 +
 drivers/net/mlx5/mlx5_flow.c     | 453 +++++++++++++++++++++++++++++++
 drivers/net/mlx5/mlx5_flow.h     |  49 ++++
 drivers/net/mlx5/mlx5_flow_dv.c  |  71 ++++-
 6 files changed, 595 insertions(+), 2 deletions(-)
drivers/net/mlx5/linux/mlx5_os.c +14 -0
index 69123e12c3..7193398750 100644
@@ -281,6 +281,12 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
 		sh->esw_drop_action = mlx5_glue->dr_create_flow_action_drop();
 	}
 #endif
+	if (!sh->tunnel_hub)
+		err = mlx5_alloc_tunnel_hub(sh);
+	if (err) {
+		DRV_LOG(ERR, "mlx5_alloc_tunnel_hub failed err=%d", err);
+		goto error;
+	}
 	if (priv->config.reclaim_mode == MLX5_RCM_AGGR) {
 		mlx5_glue->dr_reclaim_domain_memory(sh->rx_domain, 1);
 		mlx5_glue->dr_reclaim_domain_memory(sh->tx_domain, 1);
@@ -319,6 +325,10 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
 		mlx5_hlist_destroy(sh->tag_table, NULL, NULL);
 		sh->tag_table = NULL;
 	}
+	if (sh->tunnel_hub) {
+		mlx5_release_tunnel_hub(sh);
+		sh->tunnel_hub = NULL;
+	}
 	mlx5_free_table_hash_list(priv);
 	return err;
 }
@@ -372,6 +382,10 @@ mlx5_os_free_shared_dr(struct mlx5_priv *priv)
 		mlx5_hlist_destroy(sh->tag_table, NULL, NULL);
 		sh->tag_table = NULL;
 	}
+	if (sh->tunnel_hub) {
+		mlx5_release_tunnel_hub(sh);
+		sh->tunnel_hub = NULL;
+	}
 	mlx5_free_table_hash_list(priv);
 }
 
drivers/net/mlx5/mlx5.c +6 -0
index 1e4c695f84..569070d3db 100644
@@ -177,6 +177,9 @@
 /* Decap will be used or not. */
 #define MLX5_DECAP_EN "decap_en"
 
+/* Configure flow tunnel offload functionality */
+#define MLX5_TUNNEL_OFFLOAD "tunnel_offload"
+
 /* Shared memory between primary and secondary processes. */
 struct mlx5_shared_data *mlx5_shared_data;
 
@@ -1621,6 +1624,8 @@ mlx5_args_check(const char *key, const char *val, void *opaque)
 		config->sys_mem_en = !!tmp;
 	} else if (strcmp(MLX5_DECAP_EN, key) == 0) {
 		config->decap_en = !!tmp;
+	} else if (strcmp(MLX5_TUNNEL_OFFLOAD, key) == 0) {
+		config->tunnel_offload = !!tmp;
 	} else {
 		DRV_LOG(WARNING, "%s: unknown parameter", key);
 		rte_errno = EINVAL;
@@ -1681,6 +1686,7 @@ mlx5_args(struct mlx5_dev_config *config, struct rte_devargs *devargs)
 		MLX5_RECLAIM_MEM,
 		MLX5_SYS_MEM_EN,
 		MLX5_DECAP_EN,
+		MLX5_TUNNEL_OFFLOAD,
 		NULL,
 	};
 	struct rte_kvargs *kvlist;
drivers/net/mlx5/mlx5.h +4 -0
index 78d6eb7281..e450aec029 100644
@@ -208,6 +208,7 @@ struct mlx5_dev_config {
 	unsigned int rt_timestamp:1; /* realtime timestamp format. */
 	unsigned int sys_mem_en:1; /* The default memory allocator. */
 	unsigned int decap_en:1; /* Whether decap will be used or not. */
+	unsigned int tunnel_offload:1; /* Flow tunnel offload functionality */
 	struct {
 		unsigned int enabled:1; /* Whether MPRQ is enabled. */
 		unsigned int stride_num_n; /* Number of strides. */
@@ -605,6 +606,7 @@ struct mlx5_dev_ctx_shared {
 	LIST_ENTRY(mlx5_dev_ctx_shared) next;
 	uint32_t refcnt;
 	uint32_t devx:1; /* Opened with DV. */
+	uint32_t tunnel:1; /* 1 RTE flow tunnel enabled */
 	uint32_t max_port; /* Maximal IB device port index. */
 	void *ctx; /* Verbs/DV/DevX context. */
 	void *pd; /* Protection Domain. */
@@ -634,6 +636,8 @@ struct mlx5_dev_ctx_shared {
 	/* UAR same-page access control required in 32bit implementations. */
 #endif
 	struct mlx5_hlist *flow_tbls;
+	struct rte_hash *flow_tbl_map; /* app group-to-flow table map */
+	struct mlx5_flow_tunnel_hub *tunnel_hub;
 	/* Direct Rules tables for FDB, NIC TX+RX */
 	void *esw_drop_action; /* Pointer to DR E-Switch drop action. */
 	void *pop_vlan_action; /* Pointer to DR pop VLAN action. */
drivers/net/mlx5/mlx5_flow.c +453 -0

516 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +49 -0

89 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_dv.c +69 -2

130 lines not on this page · raw message

Signature · 1 line
2.25.1
#28 lore raw

PATCH v2 4/4 app/testpmd: support tunnel offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:

* Create application tunnel:
flow tunnel <port> type <tunnel type>
On success, the command creates application tunnel object and returns the tunnel descriptor. Tunnel descriptor is used in subsequent flow creation commands to reference the tunnel.

* Create tunnel steering flow rule:
tunnel_set <tunnel descriptor> parameter used with steering rule template.

* Create tunnel matching flow rule:
tunnel_match <tunnel descriptor> used with matching rule template.

* If tunnel steering rule was offloaded, outer header of a partially offloaded packet is restored after miss.

Example:
test packet=
<Ether dst=24:8a:07:8d:ae:d6 src=50:6b:4b:cc:fc:e2 type=IPv4 | <IP version=4 ihl=5 proto=udp src=1.1.1.1 dst=1.1.1.10 | <UDP sport=4789 dport=4789 len=58 chksum=0x7f7b |
<VXLAN NextProtocol=Ethernet vni=0x0 |
<Ether dst=24:aa:aa:aa:aa:d6 src=50:bb:bb:bb:bb:e2 type=IPv4 | <IP version=4 ihl=5 proto=icmp src=2.2.2.2 dst=2.2.2.200 | <ICMP type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>>>>>

Quoted 1 line
Quoted 1 line
Quoted 1 line

len(packet)

92

testpmd> flow flush 0
testpmd> port 0/queue 0: received 1 packets src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 - length=92

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end
Flow rule #0 created
testpmd> port 0/queue 0: received 1 packets
tunnel restore info: - vxlan tunnel - outer header present # <--
src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 -
length=92

testpmd> flow create 0 ingress group 0 tunnel_match 1
pattern eth / ipv4 / udp dst is 4789 / vxlan / eth / ipv4 / end
actions set_mac_dst mac_addr 02:CA:FE:CA:FA:80 / queue index 0 / end
Flow rule #1 created
testpmd> port 0/queue 0: received 1 packets
src=50:BB:BB:BB:BB:E2 - dst=02:CA:FE:CA:FA:80 - type=0x0800 -
length=42

TODO: add tunnel destruction command.

---
v2:
* introduce testpmd support for tunnel offload API

---
 app/test-pmd/cmdline_flow.c | 102 ++++++++++++++++++++++++-
 app/test-pmd/config.c       | 147 +++++++++++++++++++++++++++++++++++-
 app/test-pmd/testpmd.c      |   5 +-
 app/test-pmd/testpmd.h      |  27 ++++++-
 app/test-pmd/util.c         |  30 +++++++-
 5 files changed, 302 insertions(+), 9 deletions(-)
app/test-pmd/cmdline_flow.c +99 -3
index 6263d307ed..f0a7a4a9ea 100644
@@ -69,6 +69,10 @@ enum index {
 	LIST,
 	AGED,
 	ISOLATE,
+	TUNNEL,
+
+	/* Tunnel argumens. */
+	TUNNEL_RULE,
 
 	/* Destroy arguments. */
 	DESTROY_RULE,
@@ -88,6 +92,8 @@ enum index {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 
 	/* Validate/create pattern. */
 	PATTERN,
@@ -653,6 +659,7 @@ struct buffer {
 	union {
 		struct {
 			struct rte_flow_attr attr;
+			struct tunnel_ops tunnel_ops;
 			struct rte_flow_item *pattern;
 			struct rte_flow_action *actions;
 			uint32_t pattern_n;
@@ -713,10 +720,18 @@ static const enum index next_vc_attr[] = {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 	PATTERN,
 	ZERO,
 };
 
+static const enum index next_tunnel_attr[] = {
+	TUNNEL_RULE,
+	END,
+	ZERO,
+};
+
 static const enum index next_destroy_attr[] = {
 	DESTROY_RULE,
 	END,
@@ -1516,6 +1531,9 @@ static int parse_aged(struct context *, const struct token *,
 static int parse_isolate(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
+static int parse_tunnel(struct context *, const struct token *,
+			const char *, unsigned int,
+			void *, unsigned int);
 static int parse_int(struct context *, const struct token *,
 		     const char *, unsigned int,
 		     void *, unsigned int);
@@ -1698,7 +1716,8 @@ static const struct token token_list[] = {
 			      LIST,
 			      AGED,
 			      QUERY,
-			      ISOLATE)),
+			      ISOLATE,
+			      TUNNEL)),
 		.call = parse_init,
 	},
 	/* Sub-level commands. */
@@ -1772,6 +1791,21 @@ static const struct token token_list[] = {
 			     ARGS_ENTRY(struct buffer, port)),
 		.call = parse_isolate,
 	},
+	[TUNNEL] = {
+		.name = "tunnel",
+		.help = "new tunnel API",
+		.next = NEXT(NEXT_ENTRY(TUNNEL_RULE), NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	/* Tunnel arguments. */
+	[TUNNEL_RULE]{
+		.name = "type",
+		.help = "specify tunnel type",
+		.next = NEXT(next_tunnel_attr, NEXT_ENTRY(FILE_PATH)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, type)),
+		.call = parse_tunnel,
+	},
 	/* Destroy arguments. */
 	[DESTROY_RULE] = {
 		.name = "rule",
@@ -1835,6 +1869,20 @@ static const struct token token_list[] = {
 		.next = NEXT(next_vc_attr),
 		.call = parse_vc,
 	},
+	[TUNNEL_SET] = {
+		.name = "tunnel_set",
+		.help = "tunnel steer rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
+	[TUNNEL_MATCH] = {
+		.name = "tunnel_match",
+		.help = "tunnel match rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
 	/* Validate/create pattern. */
 	[PATTERN] = {
 		.name = "pattern",
@@ -4054,12 +4102,28 @@ parse_vc(struct context *ctx, const struct token *token,
 		return len;
 	}
 	ctx->objdata = 0;
-	ctx->object = &out->args.vc.attr;
+	switch (ctx->curr) {
+	default:
+		ctx->object = &out->args.vc.attr;
+		break;
+	case TUNNEL_SET:
+	case TUNNEL_MATCH:
+		ctx->object = &out->args.vc.tunnel_ops;
+		break;
+	}
 	ctx->objmask = NULL;
 	switch (ctx->curr) {
 	case GROUP:
 	case PRIORITY:
 		return len;
+	case TUNNEL_SET:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.actions = 1;
+		return len;
+	case TUNNEL_MATCH:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.items = 1;
+		return len;
 	case INGRESS:
 		out->args.vc.attr.ingress = 1;
 		return len;
@@ -5597,6 +5661,34 @@ parse_isolate(struct context *ctx, const struct token *token,
 	return len;
 }
 
+static int
+parse_tunnel(struct context *ctx, const struct token *token,
+	     const char *str, unsigned int len,
+	     void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != TUNNEL)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+	}
+	if (ctx->curr == TUNNEL_RULE)
+		ctx->object = &out->args.vc.tunnel_ops;
+	return len;
+}
+
 /**
  * Parse signed/unsigned integers 8 to 64-bit long.
  *
@@ -6547,7 +6639,8 @@ cmd_flow_parsed(const struct buffer *in)
 		break;
 	case CREATE:
 		port_flow_create(in->port, &in->args.vc.attr,
-				 in->args.vc.pattern, in->args.vc.actions);
+				 in->args.vc.pattern, in->args.vc.actions,
+				 &in->args.vc.tunnel_ops);
 		break;
 	case DESTROY:
 		port_flow_destroy(in->port, in->args.destroy.rule_n,
@@ -6573,6 +6666,9 @@ cmd_flow_parsed(const struct buffer *in)
 	case AGED:
 		port_flow_aged(in->port, in->args.aged.destroy);
 		break;
+	case TUNNEL:
+		port_flow_add_tunnel(in->port, &in->args.vc.tunnel_ops);
+		break;
 	default:
 		break;
 	}
app/test-pmd/config.c +144 -3

189 lines not on this page · raw message

app/test-pmd/testpmd.c +4 -1
index 7842c3b781..e2330116e1 100644
@@ -3591,6 +3591,8 @@ init_port_dcb_config(portid_t pid,
 static void
 init_port(void)
 {
+	int i;
+
 	/* Configuration of Ethernet ports. */
 	ports = rte_zmalloc("testpmd: ports",
 			    sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
@@ -3600,7 +3602,8 @@ init_port(void)
 				"rte_zmalloc(%d struct rte_port) failed\n",
 				RTE_MAX_ETHPORTS);
 	}
-
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+		LIST_INIT(&ports[i].flow_tunnel_list);
 	/* Initialize ports NUMA structures */
 	memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
 	memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
app/test-pmd/testpmd.h +26 -1
index 25a12b14f2..9c47533c68 100644
@@ -12,6 +12,7 @@
 #include <rte_gro.h>
 #include <rte_gso.h>
 #include <cmdline.h>
+#include <sys/queue.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -148,6 +149,26 @@ struct port_flow {
 	uint8_t data[]; /**< Storage for flow rule description */
 };
 
+struct port_flow_tunnel {
+	LIST_ENTRY(port_flow_tunnel) chain;
+	struct rte_flow_action *pmd_actions;
+	struct rte_flow_item   *pmd_items;
+	uint32_t id;
+	uint32_t num_pmd_actions;
+	uint32_t num_pmd_items;
+	struct rte_flow_tunnel tunnel;
+	struct rte_flow_action *actions;
+	struct rte_flow_item *items;
+};
+
+struct tunnel_ops {
+	uint32_t id;
+	char type[16];
+	uint32_t enabled:1;
+	uint32_t actions:1;
+	uint32_t items:1;
+};
+
 /**
  * The data structure associated with each port.
  */
@@ -178,6 +199,7 @@ struct rte_port {
 	uint32_t                mc_addr_nb; /**< nb. of addr. in mc_addr_pool */
 	uint8_t                 slave_flag; /**< bonding slave port */
 	struct port_flow        *flow_list; /**< Associated flows. */
+	LIST_HEAD(, port_flow_tunnel) flow_tunnel_list;
 	const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	/**< metadata value to insert in Tx packets. */
@@ -729,7 +751,8 @@ int port_flow_validate(portid_t port_id,
 int port_flow_create(portid_t port_id,
 		     const struct rte_flow_attr *attr,
 		     const struct rte_flow_item *pattern,
-		     const struct rte_flow_action *actions);
+		     const struct rte_flow_action *actions,
+		     const struct tunnel_ops *tunnel_ops);
 void update_age_action_context(const struct rte_flow_action *actions,
 		     struct port_flow *pf);
 int port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule);
@@ -739,6 +762,8 @@ int port_flow_query(portid_t port_id, uint32_t rule,
 		    const struct rte_flow_action *action);
 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
 void port_flow_aged(portid_t port_id, uint8_t destroy);
+void port_flow_release_tunnel(struct port_flow_tunnel *flow_tunnel);
+void port_flow_add_tunnel(portid_t port_id, const struct tunnel_ops *ops);
 int port_flow_isolate(portid_t port_id, int set);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
app/test-pmd/util.c +29 -1
index 8488fa1a8f..6757acde9a 100644
@@ -22,6 +22,12 @@ print_ether_addr(const char *what, const struct rte_ether_addr *eth_addr)
 	printf("%s%s", what, buf);
 }
 
+static bool tunnel_missed_packet(struct rte_mbuf  *mb)
+{
+	uint64_t mask = PKT_RX_FDIR | PKT_RX_FDIR_ID;
+	return (mb->ol_flags & mask) == mask;
+}
+
 static inline void
 dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 	      uint16_t nb_pkts, int is_rx)
@@ -51,15 +57,37 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 		mb = pkts[i];
 		eth_hdr = rte_pktmbuf_read(mb, 0, sizeof(_eth_hdr), &_eth_hdr);
 		eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
-		ol_flags = mb->ol_flags;
 		packet_type = mb->packet_type;
 		is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
 
+		if (tunnel_missed_packet(mb)) {
+			int ret;
+			struct rte_flow_error error;
+			struct rte_flow_restore_info info = { 0, };
+
+			ret = rte_flow_tunnel_get_restore_info(port_id, mb,
+							       &info, &error);
+			if (!ret) {
+				printf("tunnel restore info:");
+				if (info.flags & RTE_FLOW_RESTORE_INFO_TUNNEL)
+					if (info.tunnel.type ==
+					    RTE_FLOW_ITEM_TYPE_VXLAN)
+						printf(" - vxlan tunnel");
+				if (info.flags &
+				    RTE_FLOW_RESTORE_INFO_ENCAPSULATED)
+					printf(" - outer header present");
+				if (info.flags & RTE_FLOW_RESTORE_INFO_GROUP_ID)
+					printf(" - miss group %u",
+						info.group_id);
+			}
+			printf("\n");
+		}
 		print_ether_addr("  src=", &eth_hdr->s_addr);
 		print_ether_addr(" - dst=", &eth_hdr->d_addr);
 		printf(" - type=0x%04x - length=%u - nb_segs=%d",
 		       eth_type, (unsigned int) mb->pkt_len,
 		       (int)mb->nb_segs);
+		ol_flags = mb->ol_flags;
 		if (ol_flags & PKT_RX_RSS_HASH) {
 			printf(" - RSS hash=0x%x", (unsigned int) mb->hash.rss);
 			printf(" - RSS queue=0x%x", (unsigned int) queue);
Signature · 1 line
2.25.1
#29 lore raw

Re: [dpdk-dev] [PATCH v2 4/4] app/testpmd: support tunnel offload API

Quoted 14 lines · Gregory Etelson

::::snip::::

app/test-pmd/config.c +9 -0
@@ -1520,6 +1574,75 @@ port_flow_create(portid_t port_id,
                }
                id = port->flow_list->id + 1;
        }
+       if (tunnel_ops->enabled) {
+               int ret;
+               pft = port_flow_locate_tunnel(port, tunnel_ops->id);
+               if (!pft) {
+                       printf("failed to locate port flow tunnel #%u\n",
+                               tunnel_ops->id);
+                       return -ENOENT;
+               }
+               if (tunnel_ops->actions) {

app/test-pmd/config.c port_flow_create(portid_t port_id, · line 1595

Quoted 10 lines
app/test-pmd/config.c +7 -0
+                       uint32_t num_actions;
+                       const struct rte_flow_action *aptr;
+
+                       ret = rte_flow_tunnel_decap_set(port_id,
 &pft->tunnel,
+                                                       &pft->pmd_actions,
+
 &pft->num_pmd_actions,
+                                                       &error);
 

Does tunnel_ops always indicate decap?
Shouldn't there be a check for encap/decap? Or check for direction?

Quoted 7 lines
app/test-pmd/config.c +4 -0
+                       if (ret) {
+                               port_flow_complain(&error);
+                               return -EINVAL;
+                       }

::::snip::::

#30 lore raw

Re: [dpdk-dev] [PATCH v2 4/4] app/testpmd: support tunnel offload API

::::snip::::
@@ -1520,6 +1574,75 @@ port_flow_create(portid_t port_id,
                }
                id = port->flow_list->id + 1;
        }
+       if (tunnel_ops->enabled) {
+               int ret;
+               pft = port_flow_locate_tunnel(port, tunnel_ops->id); +               if (!pft) {
+                       printf("failed to locate port flow tunnel #%u\n", +                               tunnel_ops->id);
+                       return -ENOENT;
+               }
+               if (tunnel_ops->actions) {
+                       uint32_t num_actions;
+                       const struct rte_flow_action *aptr;
+
+                       ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel, +                                                       &pft->pmd_actions, +                                                       &pft->num_pmd_actions, +                                                       &error);

Quoted 2 lines

Does tunnel_ops always indicate decap?
Shouldn't there be a check for encap/decap? Or check for direction?

When tunnel offload API is enabled, application does not need to specify
decap in flow rules - that action is carried out internally by PMD.
If application activated the API, it's expected that it will call rte_flow_tunnel_decap_set() and rte_flow_tunnel_math() and use results obtained by the functions to compile flow rule parameters. tunnel_ops members specify 2 things
1 - tunnel offload API was activated
2 - what function, decap_set or match, should be activated and how to proceed with results
+                       if (ret) {
+                               port_flow_complain(&error);
+                               return -EINVAL;
+                       }
::::snip::::

#31 lore raw

v3 cover Tunnel Offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (3):
ethdev: allow negative values in flow rule types net/mlx5: implement tunnel offload API app/testpmd: add commands for tunnel offload API

 app/test-pmd/cmdline_flow.c                 | 170 ++++-
 app/test-pmd/config.c                       | 253 +++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 +-
 app/test-pmd/util.c                         |  35 +-
 doc/guides/nics/mlx5.rst                    |   3 +
 doc/guides/prog_guide/rte_flow.rst          | 105 +++
 doc/guides/rel_notes/release_20_11.rst      |  10 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++
 drivers/net/mlx5/linux/mlx5_os.c            |  18 +
 drivers/net/mlx5/mlx5.c                     |   8 +-
 drivers/net/mlx5/mlx5.h                     |   3 +
 drivers/net/mlx5/mlx5_defs.h                |   2 +
 drivers/net/mlx5/mlx5_flow.c                | 678 +++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h                | 173 ++++-
 drivers/net/mlx5/mlx5_flow_dv.c             | 241 ++++++-
 lib/librte_ethdev/rte_ethdev_version.map    |   6 +
 lib/librte_ethdev/rte_flow.c                | 140 +++-
 lib/librte_ethdev/rte_flow.h                | 195 ++++++
 lib/librte_ethdev/rte_flow_driver.h         |  32 +
 20 files changed, 2095 insertions(+), 65 deletions(-)
Signature · 1 line
2.25.1
#32 lore raw

PATCH v3 1/4 ethdev: allow negative values in flow rule types

From: Gregory Etelson <[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

RTE flow library functions cannot work with PMD private items and actions (elements) because RTE flow has no API to query PMD flow object size. In the patch, PMD flow elements use object pointer. RTE flow library functions handle PMD element object size as size of a pointer. PMD handles its objects internally.

---
 lib/librte_ethdev/rte_flow.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
lib/librte_ethdev/rte_flow.c +22 -6
index f8fdd68fe9..c8c6d62a8b 100644
@@ -564,7 +564,11 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (int)item->type >= 0 ?
+		      rte_flow_desc_item[item->type].size : sizeof(void *);
 		rte_memcpy(buf, data, (size > off ? off : size));
 		break;
 	}
@@ -667,7 +671,11 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_action[action->type].size;
+		/**
+		 * allow PMD private flow action
+		 */
+		off = (int)action->type >= 0 ?
+		      rte_flow_desc_action[action->type].size : sizeof(void *);
 		rte_memcpy(buf, action->conf, (size > off ? off : size));
 		break;
 	}
@@ -709,8 +717,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-		    !rte_flow_desc_item[src->type].name)
+		/**
+		 * allow PMD private flow item
+		 */
+		if (((int)src->type >= 0) &&
+			((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+		    !rte_flow_desc_item[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
 				 "cannot convert unknown item type");
@@ -798,8 +810,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-		    !rte_flow_desc_action[src->type].name)
+		/**
+		 * allow PMD private flow action
+		 */
+		if (((int)src->type >= 0) &&
+		    ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+		    !rte_flow_desc_action[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
 				 src, "cannot convert unknown action type");
Signature · 1 line
2.25.1
#33 lore raw

Re: [dpdk-dev] [PATCH v3 1/4] ethdev: allow negative values in flow rule types

Gregory,
Please see inline.

Quoted 12 lines · Gregory Etelson

From: Gregory Etelson <[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

Quoted 5 lines

RTE flow library functions cannot work with PMD private items and actions (elements) because RTE flow has no API to query PMD flow object size. In the patch, PMD flow elements use object pointer. RTE flow library functions handle PMD element object size as size of a pointer. PMD handles its objects internally.

This is important information. Apart from the commit log, this should also be added in the rte_flow API documentation. The comment in the code/API could be elaborated with this info as well.

Quoted 71 lines
---
 lib/librte_ethdev/rte_flow.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
lib/librte_ethdev/rte_flow.c +22 -7
index f8fdd68fe9..c8c6d62a8b 100644
@@ -564,7 +564,11 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
                }
                break;
        default:
-               off = rte_flow_desc_item[item->type].size;
+               /**
+                * allow PMD private flow item
+                */
+               off = (int)item->type >= 0 ?
+                     rte_flow_desc_item[item->type].size : sizeof(void *);
                rte_memcpy(buf, data, (size > off ? off : size));
                break;
        }
@@ -667,7 +671,11 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
                }
                break;
        default:
-               off = rte_flow_desc_action[action->type].size;
+               /**
+                * allow PMD private flow action
+                */
+               off = (int)action->type >= 0 ?
+                     rte_flow_desc_action[action->type].size : sizeof(void *);
                rte_memcpy(buf, action->conf, (size > off ? off : size));
                break;
        }
@@ -709,8 +717,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
        unsigned int i;
 
        for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-               if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-                   !rte_flow_desc_item[src->type].name)
+               /**
+                * allow PMD private flow item
+                */
+               if (((int)src->type >= 0) &&
+                       ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+                   !rte_flow_desc_item[src->type].name))
                        return rte_flow_error_set
                                (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
                                 "cannot convert unknown item type");
@@ -798,8 +810,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
        unsigned int i;
 
        for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-               if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-                   !rte_flow_desc_action[src->type].name)
+               /**
+                * allow PMD private flow action
+                */
+               if (((int)src->type >= 0) &&
+                   ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+                   !rte_flow_desc_action[src->type].name))
                        return rte_flow_error_set
                                (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
                                 src, "cannot convert unknown action type");
--

2.25.1

#34 lore raw

Re: [dpdk-dev] [PATCH v3 1/4] ethdev: allow negative values in flow rule types

Hello Ajit,

[snip]

Quoted 10 lines
Quoted 5 lines

RTE flow library functions cannot work with PMD private items and actions (elements) because RTE flow has no API to query PMD flow object size. In the patch, PMD flow elements use object pointer. RTE flow library functions handle PMD element object size as size of a pointer. PMD handles its objects internally.

This is important information. Apart from the commit log, this should also be added in the rte_flow API documentation. The comment in the code/API could be elaborated with this info as well.

I'll update code comments & rte_flow API documentation in the next patch update. The update will be ready this week.

Quoted 74 lines

lib/librte_ethdev/rte_flow.c rte_flow_conv_item_spec(void *buf, const size_t

Quoted 13 lines
---
 lib/librte_ethdev/rte_flow.c | 28 ++++++++++++++++++++++------
 1 file changed, 22 insertions(+), 6 deletions(-)
lib/librte_ethdev/rte_flow.c +0 -0
index f8fdd68fe9..c8c6d62a8b 100644
@@ -564,7 +564,11 @@ rte_flow_conv_item_spec(void *buf, const size_t

size,

lib/librte_ethdev/rte_flow.c rte_flow_conv_action_conf(void *buf, const size_t

Quoted 13 lines
lib/librte_ethdev/rte_flow.c +5 -1
                }
                break;
        default:
-               off = rte_flow_desc_item[item->type].size;
+               /**
+                * allow PMD private flow item
+                */
+               off = (int)item->type >= 0 ?
+                     rte_flow_desc_item[item->type].size : sizeof(void *);
                rte_memcpy(buf, data, (size > off ? off : size));
                break;
        }
@@ -667,7 +671,11 @@ rte_flow_conv_action_conf(void *buf, const size_t

size,

lib/librte_ethdev/rte_flow.c rte_flow_conv_actions(struct rte_flow_action

Quoted 28 lines
lib/librte_ethdev/rte_flow.c +11 -3
                }
                break;
        default:
-               off = rte_flow_desc_action[action->type].size;
+               /**
+                * allow PMD private flow action
+                */
+               off = (int)action->type >= 0 ?
+                     rte_flow_desc_action[action->type].size : sizeof(void *);
                rte_memcpy(buf, action->conf, (size > off ? off : size));
                break;
        }
@@ -709,8 +717,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
        unsigned int i;
 
        for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-               if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-                   !rte_flow_desc_item[src->type].name)
+               /**
+                * allow PMD private flow item
+                */
+               if (((int)src->type >= 0) &&
+                       ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+                   !rte_flow_desc_item[src->type].name))
                        return rte_flow_error_set
                                (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
                                 "cannot convert unknown item type");
@@ -798,8 +810,12 @@ rte_flow_conv_actions(struct rte_flow_action

*dst,

Quoted 17 lines
lib/librte_ethdev/rte_flow.c +6 -3
        unsigned int i;
 
        for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-               if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-                   !rte_flow_desc_action[src->type].name)
+               /**
+                * allow PMD private flow action
+                */
+               if (((int)src->type >= 0) &&
+                   ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+                   !rte_flow_desc_action[src->type].name))
                        return rte_flow_error_set
                                (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
                                 src, "cannot convert unknown action type");
--

2.25.1

#35 lore raw

PATCH v3 2/4 ethdev: tunnel offload model

In reply to Gregory Etelson

From: Eli Britstein <[email protected]>

Rte_flow API provides the building blocks for vendor agnostic flow classification offloads. The rte_flow match and action primitives are fine grained, thus enabling DPDK applications the flexibility to offload network stacks and complex pipelines.

Applications wishing to offload complex data structures (e.g. tunnel virtual ports) are required to use the rte_flow primitives, such as group, meta, mark, tag and others to model their high level objects.

The hardware model design for high level software objects is not trivial. Furthermore, an optimal design is often vendor specific.

The goal of this API is to provide applications with the hardware offload model for common high level software objects which is optimal in regards to the underlying hardware.

Tunnel ports are the first of such objects.

Tunnel ports
------------
Ingress processing of tunneled traffic requires the classification of the tunnel type followed by a decap action.

In software, once a packet is decapsulated the in_port field is changed to a virtual port representing the tunnel type. The outer header fields are stored as packet metadata members and may be matched by proceeding flows.

Openvswitch, for example, uses two flows:
1. classification flow - setting the virtual port representing the tunnel type For example: match on udp port 4789 actions=tnl_pop(vxlan_vport)
2. steering flow according to outer and inner header matches match on in_port=vxlan_vport and outer/inner header matches actions=forward to p ort X The benefits of multi-flow tables are described in [1].

Offloading tunnel ports
-----------------------
Tunnel ports introduce a new stateless field that can be matched on. Currently the rte_flow library provides an API to encap, decap and match on tunnel headers. However, there is no rte_flow primitive to set and match tunnel virtual ports.

There are several possible hardware models for offloading virtual tunnel port flows including, but not limited to, the following:
1. Setting the virtual port on a hw register using the rte_flow_action_mark/ rte_flow_action_tag/rte_flow_set_meta objects.
2. Mapping a virtual port to an rte_flow group
3. Avoiding the need to match on transient objects by merging multi-table flows to a single rte_flow rule.

Every approach has its pros and cons. The preferred approach should take into account the entire system architecture and is very often vendor specific.

The proposed rte_flow_tunnel_decap_set helper function (drafted below) is designed to provide a common, vendor agnostic, API for setting the virtual port value. The helper API enables PMD implementations to return vendor specific combination of rte_flow actions realizing the vendor's hardware model for setting a tunnel port. Applications may append the list of actions returned from the helper function when creating an rte_flow rule in hardware.

Similarly, the rte_flow_tunnel_match helper (drafted below) allows for multiple hardware implementations to return a list of fte_flow items.

Miss handling
-------------
Packets going through multiple rte_flow groups are exposed to hw misses due to partial packet processing. In such cases, the software should continue the packet's processing from the point where the hardware missed.

We propose a generic rte_flow_restore structure providing the state that was stored in hardware when the packet missed.

Currently, the structure will provide the tunnel state of the packet that missed, namely:
1. The group id that missed
2. The tunnel port that missed
3. Tunnel information that was stored in memory (due to decap action). In the future, we may add additional fields as more state may be stored in the device memory (e.g. ct_state).

Applications may query the state via a new rte_flow_tunnel_get_restore_info(mbuf) API, thus allowing a vendor specific implementation.

VXLAN Code example:
Assume application needs to do inner NAT on VXLAN packet. The first rule in group 0:

flow create <port id> ingress group 0
pattern eth / ipv4 / udp dst is 4789 / vxlan / end actions {pmd actions} / jump group 3 / end

First VXLAN packet that arrives matches the rule in group 0 and jumps to group 3 In group 3 the packet will miss since there is no flow to match and will be uploaded to application. Application will call rte_flow_get_restore_info() to get the packet outer header. Application will insert a new rule in group 3 to match outer and inner headers:

flow create <port id> ingress group 3
pattern {pmd items} / eth / ipv4 dst is 172.10.10.1 /
udp dst 4789 / vxlan vni is 10 /
ipv4 dst is 184.1.2.3 / end
actions set_ipv4_dst 186.1.1.1 / queue index 3 / end

Resulting of rules will be that VXLAN packet with vni=10, outer IPv4 dst=172.10.10.1 and inner IPv4 dst=184.1.2.3 will be received decaped on queue 3 with IPv4 dst=186.1.1.1

Note: Packet in group 3 is considered decaped. All actions in that group will be done on header that was inner before decap. Application may specify outer header to be matched on. It's PMD responsibility to translate these items to outer metadata.

API usage:
/**
* 1. Initiate RTE flow tunnel object
*/
const struct rte_flow_tunnel tunnel = {
.type = RTE_FLOW_ITEM_TYPE_VXLAN,
.tun_id = 10,
}

/**
* 2. Obtain PMD tunnel actions
*
* pmd_actions is an intermediate variable application uses to
* compile actions array
*/
struct rte_flow_action **pmd_actions; rte_flow_tunnel_decap_and_set(&tunnel, &pmd_actions,

                              &num_pmd_actions, &error);

/**
* 3. offload the first rule
* matching on VXLAN traffic and jumps to group 3
* (implicitly decaps packet)
*/
app_actions = jump group 3
rule_items = app_items; /** eth / ipv4 / udp / vxlan */ rule_actions = { pmd_actions, app_actions }; attr.group = 0;
flow_1 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 4. after flow creation application does not need to keep tunnel
* action resources.
*/
rte_flow_tunnel_action_release(port_id, pmd_actions,

                               num_pmd_actions);

/**
* 5. After partially offloaded packet miss because there was no
* matching rule handle miss on group 3
*/
struct rte_flow_restore_info info; rte_flow_get_restore_info(port_id, mbuf, &info, &error);

/**
* 6. Offload NAT rule:
*/
app_items = { eth / ipv4 dst is 172.10.10.1 / udp dst 4789 /

            vxlan vni is 10 / ipv4 dst is 184.1.2.3 }

app_actions = { set_ipv4_dst 186.1.1.1 / queue index 3 }

rte_flow_tunnel_match(&info.tunnel, &pmd_items,

                      &num_pmd_items,  &error);

rule_items = {pmd_items, app_items};
rule_actions = app_actions;
attr.group = info.group_id;
flow_2 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 7. Release PMD items after rule creation
*/
rte_flow_tunnel_item_release(port_id, pmd_items, num_pmd_items);

References
1. https://mails.dpdk.org/archives/dev/2020-June/index.html

---
 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++++++++
 doc/guides/rel_notes/release_20_11.rst   |  10 ++
 lib/librte_ethdev/rte_ethdev_version.map |   6 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 195 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 6 files changed, 460 insertions(+)
doc/guides/prog_guide/rte_flow.rst +105 -0
index 119b128739..e62030150e 100644
@@ -3031,6 +3031,111 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Provide software application with unified rules model for tunneled traffic
+regardless underlying hardware.
+
+ - The model introduces a concept of a virtual tunnel port (VTP).
+ - The model uses VTP to offload ingress tunneled network traffic 
+   with RTE flow rules.
+ - The model is implemented as set of helper functions. Each PMD
+   implements VTP offload according to underlying hardware offload
+   capabilities.  Applications must query PMD for VTP flow
+   items / actions before using in creation of a VTP flow rule.
+
+The model components:
+
+- Virtual Tunnel Port (VTP) is a stateless software object that
+  describes tunneled network traffic.  VTP object usually contains
+  descriptions of outer headers, tunnel headers and inner headers.
+- Tunnel Steering flow Rule (TSR) detects tunneled packets and
+  delegates them to tunnel processing infrastructure, implemented
+  in PMD for optimal hardware utilization, for further processing.
+- Tunnel Matching flow Rule (TMR) verifies packet configuration and
+  runs offload actions in case of a match.
+
+Application actions:
+
+1 Initialize VTP object according to tunnel network parameters.
+
+2 Create TSR flow rule.
+
+2.1 Query PMD for VTP actions. Application can query for VTP actions more than once.
+
+  .. code-block:: c
+
+    int
+    rte_flow_tunnel_decap_set(uint16_t port_id,
+                              struct rte_flow_tunnel *tunnel,
+                              struct rte_flow_action **pmd_actions,
+                              uint32_t *num_of_pmd_actions,
+                              struct rte_flow_error *error);
+
+2.2 Integrate PMD actions into TSR actions list.
+
+2.3 Create TSR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {tunnel items} / end actions {PMD actions} / {App actions} / end
+
+3 Create TMR flow rule.
+
+3.1 Query PMD for VTP items. Application can query for VTP items more than once.
+
+    .. code-block:: c
+
+      int
+      rte_flow_tunnel_match(uint16_t port_id,
+                            struct rte_flow_tunnel *tunnel,
+                            struct rte_flow_item **pmd_items,
+                            uint32_t *num_of_pmd_items,
+                            struct rte_flow_error *error);
+
+3.2 Integrate PMD items into TMR items list.
+
+3.3 Create TMR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {PMD items} / {APP items} / end actions {offload actions} / end
+
+The model provides helper function call to restore packets that miss
+tunnel TMR rules to its original state:
+
+.. code-block:: c
+
+  int
+  rte_flow_get_restore_info(uint16_t port_id,
+                            struct rte_mbuf *mbuf,
+                            struct rte_flow_restore_info *info,
+                            struct rte_flow_error *error);
+
+rte_tunnel object filled by the call inside
+``rte_flow_restore_info *info parameter`` can be used by the application
+to create new TMR rule for that tunnel.
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+Application can release the actionsfter TSR rule was created.
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release the items after rule was created. However, if the application
+needs to create additional TMR rule for the same tunnel it will need
+to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
 
doc/guides/rel_notes/release_20_11.rst +10 -0
index c6642f5f94..802d9e74d6 100644
@@ -55,6 +55,16 @@ New Features
      Also, make sure to start the actual text at the margin.
      =======================================================
 
+* **Flow rules allowed to use private PMD items / actions.**
+
+  * Flow rule verification was updated to accept private PMD
+    items and actions.
+
+* **Added generic API to offload tunneled traffic and restore missed packet.**
+
+  * Added a new hardware independent helper API to RTE flow library that
+    offloads tunneled traffic and restores missed packets.
+
 * **Updated Cisco enic driver.**
 
   * Added support for VF representors with single-queue Tx/Rx and flow API
lib/librte_ethdev/rte_ethdev_version.map +6 -0
index c95ef5157a..9832c138a2 100644
@@ -226,6 +226,12 @@ EXPERIMENTAL {
 	rte_tm_wred_profile_add;
 	rte_tm_wred_profile_delete;
 
+	rte_flow_tunnel_decap_set;
+	rte_flow_tunnel_match;
+	rte_flow_get_restore_info;
+	rte_flow_tunnel_action_decap_release;
+	rte_flow_tunnel_item_release;
+
 	# added in 20.11
 	rte_eth_link_speed_to_str;
 	rte_eth_link_to_str;
lib/librte_ethdev/rte_flow.c +112 -0

115 lines not on this page · raw message

lib/librte_ethdev/rte_flow.h +195 -0

201 lines not on this page · raw message

lib/librte_ethdev/rte_flow_driver.h +32 -0
index 3ee871d3eb..9d87407203 100644
@@ -108,6 +108,38 @@ struct rte_flow_ops {
 		 void **context,
 		 uint32_t nb_contexts,
 		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_decap_set() */
+	int (*tunnel_decap_set)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_action **pmd_actions,
+		 uint32_t *num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_match() */
+	int (*tunnel_match)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_item **pmd_items,
+		 uint32_t *num_of_items,
+		 struct rte_flow_error *err);
+	/** See rte_flow_get_rte_flow_restore_info() */
+	int (*get_restore_info)
+		(struct rte_eth_dev *dev,
+		 struct rte_mbuf *m,
+		 struct rte_flow_restore_info *info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_action_tunnel_decap_release() */
+	int (*action_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_action *pmd_actions,
+		 uint32_t num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_item_release() */
+	int (*item_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_item *pmd_items,
+		 uint32_t num_of_items,
+		 struct rte_flow_error *err);
 };
 
 /**
Signature · 1 line
2.25.1
#36 lore raw

PATCH v3 3/4 net/mlx5: implement tunnel offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:
* tunnel_offload PMD parameter must be set to 1 to enable the feature.
* application cannot use MARK and META flow actions whith tunnel.
* offload JUMP action is restricted to steering tunnel rule only.

---
v2:
* introduce MLX5 PMD API implementation
v3:
* bug fixes

---
 doc/guides/nics/mlx5.rst         |   3 +
 drivers/net/mlx5/linux/mlx5_os.c |  18 +
 drivers/net/mlx5/mlx5.c          |   8 +-
 drivers/net/mlx5/mlx5.h          |   3 +
 drivers/net/mlx5/mlx5_defs.h     |   2 +
 drivers/net/mlx5/mlx5_flow.c     | 678 ++++++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h     | 173 +++++++-
 drivers/net/mlx5/mlx5_flow_dv.c  | 241 +++++++++--
 8 files changed, 1080 insertions(+), 46 deletions(-)
doc/guides/nics/mlx5.rst +3 -0
index 211c0c5a6c..287fd23b43 100644
@@ -815,6 +815,9 @@ Driver options
     24 bits. The actual supported width can be retrieved in runtime by
     series of rte_flow_validate() trials.
 
+  - 3, this engages tunnel offload mode. In E-Switch configuration, that
+    mode implicitly activates ``dv_xmeta_en=1``.
+
   +------+-----------+-----------+-------------+-------------+
   | Mode | ``MARK``  | ``META``  | ``META`` Tx | FDB/Through |
   +======+===========+===========+=============+=============+
drivers/net/mlx5/linux/mlx5_os.c +18 -0
index 81a2e99e71..ecf4d2f2a6 100644
@@ -298,6 +298,12 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
 		sh->esw_drop_action = mlx5_glue->dr_create_flow_action_drop();
 	}
 #endif
+	if (!sh->tunnel_hub)
+		err = mlx5_alloc_tunnel_hub(sh);
+	if (err) {
+		DRV_LOG(ERR, "mlx5_alloc_tunnel_hub failed err=%d", err);
+		goto error;
+	}
 	if (priv->config.reclaim_mode == MLX5_RCM_AGGR) {
 		mlx5_glue->dr_reclaim_domain_memory(sh->rx_domain, 1);
 		mlx5_glue->dr_reclaim_domain_memory(sh->tx_domain, 1);
@@ -344,6 +350,10 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
 		mlx5_hlist_destroy(sh->tag_table, NULL, NULL);
 		sh->tag_table = NULL;
 	}
+	if (sh->tunnel_hub) {
+		mlx5_release_tunnel_hub(sh, priv->dev_port);
+		sh->tunnel_hub = NULL;
+	}
 	mlx5_free_table_hash_list(priv);
 	return err;
 }
@@ -405,6 +415,10 @@ mlx5_os_free_shared_dr(struct mlx5_priv *priv)
 		mlx5_hlist_destroy(sh->tag_table, NULL, NULL);
 		sh->tag_table = NULL;
 	}
+	if (sh->tunnel_hub) {
+		mlx5_release_tunnel_hub(sh, priv->dev_port);
+		sh->tunnel_hub = NULL;
+	}
 	mlx5_free_table_hash_list(priv);
 }
 
@@ -658,6 +672,10 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			strerror(rte_errno));
 		goto error;
 	}
+	if (config->dv_miss_info) {
+		if (switch_info->master || switch_info->representor)
+			config->dv_xmeta_en = MLX5_XMETA_MODE_META16;
+	}
 	mlx5_malloc_mem_select(config->sys_mem_en);
 	sh = mlx5_alloc_shared_dev_ctx(spawn, config);
 	if (!sh)
drivers/net/mlx5/mlx5.c +6 -2
index 4a807fb4fd..569a865da8 100644
@@ -1590,13 +1590,17 @@ mlx5_args_check(const char *key, const char *val, void *opaque)
 	} else if (strcmp(MLX5_DV_XMETA_EN, key) == 0) {
 		if (tmp != MLX5_XMETA_MODE_LEGACY &&
 		    tmp != MLX5_XMETA_MODE_META16 &&
-		    tmp != MLX5_XMETA_MODE_META32) {
+		    tmp != MLX5_XMETA_MODE_META32 &&
+		    tmp != MLX5_XMETA_MODE_MISS_INFO) {
 			DRV_LOG(ERR, "invalid extensive "
 				     "metadata parameter");
 			rte_errno = EINVAL;
 			return -rte_errno;
 		}
-		config->dv_xmeta_en = tmp;
+		if (tmp != MLX5_XMETA_MODE_MISS_INFO)
+			config->dv_xmeta_en = tmp;
+		else
+			config->dv_miss_info = 1;
 	} else if (strcmp(MLX5_LACP_BY_USER, key) == 0) {
 		config->lacp_by_user = !!tmp;
 	} else if (strcmp(MLX5_MR_EXT_MEMSEG_EN, key) == 0) {
drivers/net/mlx5/mlx5.h +3 -0
index 0907506755..e12c4cee4b 100644
@@ -206,6 +206,7 @@ struct mlx5_dev_config {
 	unsigned int rt_timestamp:1; /* realtime timestamp format. */
 	unsigned int sys_mem_en:1; /* The default memory allocator. */
 	unsigned int decap_en:1; /* Whether decap will be used or not. */
+	unsigned int dv_miss_info:1; /* restore packet after partial hw miss */
 	struct {
 		unsigned int enabled:1; /* Whether MPRQ is enabled. */
 		unsigned int stride_num_n; /* Number of strides. */
@@ -632,6 +633,8 @@ struct mlx5_dev_ctx_shared {
 	/* UAR same-page access control required in 32bit implementations. */
 #endif
 	struct mlx5_hlist *flow_tbls;
+	struct rte_hash *flow_tbl_map; /* app group-to-flow table map */
+	struct mlx5_flow_tunnel_hub *tunnel_hub;
 	/* Direct Rules tables for FDB, NIC TX+RX */
 	void *esw_drop_action; /* Pointer to DR E-Switch drop action. */
 	void *pop_vlan_action; /* Pointer to DR pop VLAN action. */
drivers/net/mlx5/mlx5_defs.h +2 -0
index 0df47391ee..41a7537d5e 100644
@@ -165,6 +165,8 @@
 #define MLX5_XMETA_MODE_LEGACY 0
 #define MLX5_XMETA_MODE_META16 1
 #define MLX5_XMETA_MODE_META32 2
+/* Provide info on patrial hw miss. Implies MLX5_XMETA_MODE_META16 */
+#define MLX5_XMETA_MODE_MISS_INFO 3
 
 /* MLX5_TX_DB_NC supported values. */
 #define MLX5_TXDB_CACHED 0
drivers/net/mlx5/mlx5_flow.c +660 -18

770 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +170 -3

231 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_dv.c +218 -23

373 lines not on this page · raw message

Signature · 1 line
2.25.1
#37 lore raw

PATCH v3 4/4 app/testpmd: add commands for tunnel offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:

* Create application tunnel:
flow tunnel create <port> type <tunnel type>
On success, the command creates application tunnel object and returns the tunnel descriptor. Tunnel descriptor is used in subsequent flow creation commands to reference the tunnel.

* Create tunnel steering flow rule:
tunnel_set <tunnel descriptor> parameter used with steering rule template.

* Create tunnel matching flow rule:
tunnel_match <tunnel descriptor> used with matching rule template.

* If tunnel steering rule was offloaded, outer header of a partially offloaded packet is restored after miss.

Example:
test packet=
<Ether dst=24:8a:07:8d:ae:d6 src=50:6b:4b:cc:fc:e2 type=IPv4 | <IP version=4 ihl=5 proto=udp src=1.1.1.1 dst=1.1.1.10 | <UDP sport=4789 dport=4789 len=58 chksum=0x7f7b |
<VXLAN NextProtocol=Ethernet vni=0x0 |
<Ether dst=24:aa:aa:aa:aa:d6 src=50:bb:bb:bb:bb:e2 type=IPv4 | <IP version=4 ihl=5 proto=icmp src=2.2.2.2 dst=2.2.2.200 | <ICMP type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>>>>>

Quoted 1 line
Quoted 1 line
Quoted 1 line

len(packet)

92

testpmd> flow flush 0
testpmd> port 0/queue 0: received 1 packets src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 - length=92

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end
Flow rule #0 created
testpmd> port 0/queue 0: received 1 packets
tunnel restore info: - vxlan tunnel - outer header present # <--
src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 -
length=92

testpmd> flow create 0 ingress group 0 tunnel_match 1
pattern eth / ipv4 / udp dst is 4789 / vxlan / eth / ipv4 / end
actions set_mac_dst mac_addr 02:CA:FE:CA:FA:80 / queue index 0 / end
Flow rule #1 created
testpmd> port 0/queue 0: received 1 packets
src=50:BB:BB:BB:BB:E2 - dst=02:CA:FE:CA:FA:80 - type=0x0800 -
length=42

* Destroy flow tunnel
flow tunnel destroy <port> id <tunnel id>

* Show existing flow tunnels
flow tunnel list <port>

---
v2:
* introduce testpmd support for tunnel offload API

v3:
* update flow tunnel commands

---
 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 253 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 6 files changed, 533 insertions(+), 13 deletions(-)
app/test-pmd/cmdline_flow.c +166 -4
index 6263d307ed..0fb61860cd 100644
@@ -69,6 +69,14 @@ enum index {
 	LIST,
 	AGED,
 	ISOLATE,
+	TUNNEL,
+
+	/* Tunnel argumens. */
+	TUNNEL_CREATE,
+	TUNNEL_CREATE_TYPE,
+	TUNNEL_LIST,
+	TUNNEL_DESTROY,
+	TUNNEL_DESTROY_ID,
 
 	/* Destroy arguments. */
 	DESTROY_RULE,
@@ -88,6 +96,8 @@ enum index {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 
 	/* Validate/create pattern. */
 	PATTERN,
@@ -653,6 +663,7 @@ struct buffer {
 	union {
 		struct {
 			struct rte_flow_attr attr;
+			struct tunnel_ops tunnel_ops;
 			struct rte_flow_item *pattern;
 			struct rte_flow_action *actions;
 			uint32_t pattern_n;
@@ -713,10 +724,32 @@ static const enum index next_vc_attr[] = {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 	PATTERN,
 	ZERO,
 };
 
+static const enum index tunnel_create_attr[] = {
+	TUNNEL_CREATE,
+	TUNNEL_CREATE_TYPE,
+	END,
+	ZERO,
+};
+
+static const enum index tunnel_destroy_attr[] = {
+	TUNNEL_DESTROY,
+	TUNNEL_DESTROY_ID,
+	END,
+	ZERO,
+};
+
+static const enum index tunnel_list_attr[] = {
+	TUNNEL_LIST,
+	END,
+	ZERO,
+};
+
 static const enum index next_destroy_attr[] = {
 	DESTROY_RULE,
 	END,
@@ -1516,6 +1549,9 @@ static int parse_aged(struct context *, const struct token *,
 static int parse_isolate(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
+static int parse_tunnel(struct context *, const struct token *,
+			const char *, unsigned int,
+			void *, unsigned int);
 static int parse_int(struct context *, const struct token *,
 		     const char *, unsigned int,
 		     void *, unsigned int);
@@ -1698,7 +1734,8 @@ static const struct token token_list[] = {
 			      LIST,
 			      AGED,
 			      QUERY,
-			      ISOLATE)),
+			      ISOLATE,
+			      TUNNEL)),
 		.call = parse_init,
 	},
 	/* Sub-level commands. */
@@ -1772,6 +1809,49 @@ static const struct token token_list[] = {
 			     ARGS_ENTRY(struct buffer, port)),
 		.call = parse_isolate,
 	},
+	[TUNNEL] = {
+		.name = "tunnel",
+		.help = "new tunnel API",
+		.next = NEXT(NEXT_ENTRY
+			     (TUNNEL_CREATE, TUNNEL_LIST, TUNNEL_DESTROY)),
+		.call = parse_tunnel,
+	},
+	/* Tunnel arguments. */
+	[TUNNEL_CREATE] = {
+		.name = "create",
+		.help = "create new tunnel object",
+		.next = NEXT(tunnel_create_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_CREATE_TYPE] = {
+		.name = "type",
+		.help = "create new tunnel",
+		.next = NEXT(tunnel_create_attr, NEXT_ENTRY(FILE_PATH)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, type)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy tunel",
+		.next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_DESTROY_ID] = {
+		.name = "id",
+		.help = "tunnel identifier to testroy",
+		.next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_LIST] = {
+		.name = "list",
+		.help = "list existing tunnels",
+		.next = NEXT(tunnel_list_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
 	/* Destroy arguments. */
 	[DESTROY_RULE] = {
 		.name = "rule",
@@ -1835,6 +1915,20 @@ static const struct token token_list[] = {
 		.next = NEXT(next_vc_attr),
 		.call = parse_vc,
 	},
+	[TUNNEL_SET] = {
+		.name = "tunnel_set",
+		.help = "tunnel steer rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
+	[TUNNEL_MATCH] = {
+		.name = "tunnel_match",
+		.help = "tunnel match rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
 	/* Validate/create pattern. */
 	[PATTERN] = {
 		.name = "pattern",
@@ -4054,12 +4148,28 @@ parse_vc(struct context *ctx, const struct token *token,
 		return len;
 	}
 	ctx->objdata = 0;
-	ctx->object = &out->args.vc.attr;
+	switch (ctx->curr) {
+	default:
+		ctx->object = &out->args.vc.attr;
+		break;
+	case TUNNEL_SET:
+	case TUNNEL_MATCH:
+		ctx->object = &out->args.vc.tunnel_ops;
+		break;
+	}
 	ctx->objmask = NULL;
 	switch (ctx->curr) {
 	case GROUP:
 	case PRIORITY:
 		return len;
+	case TUNNEL_SET:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.actions = 1;
+		return len;
+	case TUNNEL_MATCH:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.items = 1;
+		return len;
 	case INGRESS:
 		out->args.vc.attr.ingress = 1;
 		return len;
@@ -5597,6 +5707,47 @@ parse_isolate(struct context *ctx, const struct token *token,
 	return len;
 }
 
+static int
+parse_tunnel(struct context *ctx, const struct token *token,
+	     const char *str, unsigned int len,
+	     void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != TUNNEL)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+	} else {
+		switch (ctx->curr) {
+		default:
+			break;
+		case TUNNEL_CREATE:
+		case TUNNEL_DESTROY:
+		case TUNNEL_LIST:
+			out->command = ctx->curr;
+			break;
+		case TUNNEL_CREATE_TYPE:
+		case TUNNEL_DESTROY_ID:
+			ctx->object = &out->args.vc.tunnel_ops;
+			break;
+		}
+	}
+
+	return len;
+}
+
 /**
  * Parse signed/unsigned integers 8 to 64-bit long.
  *
@@ -6543,11 +6694,13 @@ cmd_flow_parsed(const struct buffer *in)
 	switch (in->command) {
 	case VALIDATE:
 		port_flow_validate(in->port, &in->args.vc.attr,
-				   in->args.vc.pattern, in->args.vc.actions);
+				   in->args.vc.pattern, in->args.vc.actions,
+				   &in->args.vc.tunnel_ops);
 		break;
 	case CREATE:
 		port_flow_create(in->port, &in->args.vc.attr,
-				 in->args.vc.pattern, in->args.vc.actions);
+				 in->args.vc.pattern, in->args.vc.actions,
+				 &in->args.vc.tunnel_ops);
 		break;
 	case DESTROY:
 		port_flow_destroy(in->port, in->args.destroy.rule_n,
@@ -6573,6 +6726,15 @@ cmd_flow_parsed(const struct buffer *in)
 	case AGED:
 		port_flow_aged(in->port, in->args.aged.destroy);
 		break;
+	case TUNNEL_CREATE:
+		port_flow_tunnel_create(in->port, &in->args.vc.tunnel_ops);
+		break;
+	case TUNNEL_DESTROY:
+		port_flow_tunnel_destroy(in->port, in->args.vc.tunnel_ops.id);
+		break;
+	case TUNNEL_LIST:
+		port_flow_tunnel_list(in->port);
+		break;
 	default:
 		break;
 	}
app/test-pmd/config.c +249 -4

313 lines not on this page · raw message

app/test-pmd/testpmd.c +4 -1
index fe6450cc0d..e484079147 100644
@@ -3588,6 +3588,8 @@ init_port_dcb_config(portid_t pid,
 static void
 init_port(void)
 {
+	int i;
+
 	/* Configuration of Ethernet ports. */
 	ports = rte_zmalloc("testpmd: ports",
 			    sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
@@ -3597,7 +3599,8 @@ init_port(void)
 				"rte_zmalloc(%d struct rte_port) failed\n",
 				RTE_MAX_ETHPORTS);
 	}
-
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+		LIST_INIT(&ports[i].flow_tunnel_list);
 	/* Initialize ports NUMA structures */
 	memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
 	memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
app/test-pmd/testpmd.h +32 -2
index f139fe7a0a..1dd8cfd3d8 100644
@@ -12,6 +12,7 @@
 #include <rte_gro.h>
 #include <rte_gso.h>
 #include <cmdline.h>
+#include <sys/queue.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -142,6 +143,26 @@ struct port_flow {
 	uint8_t data[]; /**< Storage for flow rule description */
 };
 
+struct port_flow_tunnel {
+	LIST_ENTRY(port_flow_tunnel) chain;
+	struct rte_flow_action *pmd_actions;
+	struct rte_flow_item   *pmd_items;
+	uint32_t id;
+	uint32_t num_pmd_actions;
+	uint32_t num_pmd_items;
+	struct rte_flow_tunnel tunnel;
+	struct rte_flow_action *actions;
+	struct rte_flow_item *items;
+};
+
+struct tunnel_ops {
+	uint32_t id;
+	char type[16];
+	uint32_t enabled:1;
+	uint32_t actions:1;
+	uint32_t items:1;
+};
+
 /**
  * The data structure associated with each port.
  */
@@ -172,6 +193,7 @@ struct rte_port {
 	uint32_t                mc_addr_nb; /**< nb. of addr. in mc_addr_pool */
 	uint8_t                 slave_flag; /**< bonding slave port */
 	struct port_flow        *flow_list; /**< Associated flows. */
+	LIST_HEAD(, port_flow_tunnel) flow_tunnel_list;
 	const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	/**< metadata value to insert in Tx packets. */
@@ -749,11 +771,13 @@ void port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t value);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
-		       const struct rte_flow_action *actions);
+		       const struct rte_flow_action *actions,
+		       const struct tunnel_ops *tunnel_ops);
 int port_flow_create(portid_t port_id,
 		     const struct rte_flow_attr *attr,
 		     const struct rte_flow_item *pattern,
-		     const struct rte_flow_action *actions);
+		     const struct rte_flow_action *actions,
+		     const struct tunnel_ops *tunnel_ops);
 void update_age_action_context(const struct rte_flow_action *actions,
 		     struct port_flow *pf);
 int port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule);
@@ -763,6 +787,12 @@ int port_flow_query(portid_t port_id, uint32_t rule,
 		    const struct rte_flow_action *action);
 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
 void port_flow_aged(portid_t port_id, uint8_t destroy);
+const char *port_flow_tunnel_type(struct rte_flow_tunnel *tunnel);
+struct port_flow_tunnel *
+port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun);
+void port_flow_tunnel_list(portid_t port_id);
+void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
+void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops);
 int port_flow_isolate(portid_t port_id, int set);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
app/test-pmd/util.c +33 -2
index 8488fa1a8f..781a813759 100644
@@ -48,18 +48,49 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 	       is_rx ? "received" : "sent",
 	       (unsigned int) nb_pkts);
 	for (i = 0; i < nb_pkts; i++) {
+		int ret;
+		struct rte_flow_error error;
+		struct rte_flow_restore_info info = { 0, };
+
 		mb = pkts[i];
 		eth_hdr = rte_pktmbuf_read(mb, 0, sizeof(_eth_hdr), &_eth_hdr);
 		eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
-		ol_flags = mb->ol_flags;
 		packet_type = mb->packet_type;
 		is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
-
+		ret = rte_flow_get_restore_info(port_id, mb, &info, &error);
+		if (!ret) {
+			printf("restore info:");
+			if (info.flags & RTE_FLOW_RESTORE_INFO_TUNNEL) {
+				struct port_flow_tunnel *port_tunnel;
+
+				port_tunnel = port_flow_locate_tunnel
+					      (port_id, &info.tunnel);
+				printf(" - tunnel");
+				if (port_tunnel)
+					printf(" #%u", port_tunnel->id);
+				else
+					printf(" %s", "-none-");
+				printf(" type %s",
+					port_flow_tunnel_type(&info.tunnel));
+			} else {
+				printf(" - no tunnel info");
+			}
+			if (info.flags & RTE_FLOW_RESTORE_INFO_ENCAPSULATED)
+				printf(" - outer header present");
+			else
+				printf(" - no outer header");
+			if (info.flags & RTE_FLOW_RESTORE_INFO_GROUP_ID)
+				printf(" - miss group %u", info.group_id);
+			else
+				printf(" - no miss group");
+			printf("\n");
+		}
 		print_ether_addr("  src=", &eth_hdr->s_addr);
 		print_ether_addr(" - dst=", &eth_hdr->d_addr);
 		printf(" - type=0x%04x - length=%u - nb_segs=%d",
 		       eth_type, (unsigned int) mb->pkt_len,
 		       (int)mb->nb_segs);
+		ol_flags = mb->ol_flags;
 		if (ol_flags & PKT_RX_RSS_HASH) {
 			printf(" - RSS hash=0x%x", (unsigned int) mb->hash.rss);
 			printf(" - RSS queue=0x%x", (unsigned int) queue);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +49 -0

73 lines not on this page · raw message

Signature · 1 line
2.25.1
#38 lore raw

Re: [dpdk-dev] [PATCH v3 4/4] app/testpmd: add commands for tunnel offload API

Quoted 43 lines · Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:

* Create application tunnel:
flow tunnel create <port> type <tunnel type>
On success, the command creates application tunnel object and returns the tunnel descriptor. Tunnel descriptor is used in subsequent flow creation commands to reference the tunnel.

* Create tunnel steering flow rule:
tunnel_set <tunnel descriptor> parameter used with steering rule template.

* Create tunnel matching flow rule:
tunnel_match <tunnel descriptor> used with matching rule template.

* If tunnel steering rule was offloaded, outer header of a partially offloaded packet is restored after miss.

Example:
test packet=
<Ether dst=24:8a:07:8d:ae:d6 src=50:6b:4b:cc:fc:e2 type=IPv4 | <IP version=4 ihl=5 proto=udp src=1.1.1.1 dst=1.1.1.10 | <UDP sport=4789 dport=4789 len=58 chksum=0x7f7b |
<VXLAN NextProtocol=Ethernet vni=0x0 |
<Ether dst=24:aa:aa:aa:aa:d6 src=50:bb:bb:bb:bb:e2 type=IPv4 | <IP version=4 ihl=5 proto=icmp src=2.2.2.2 dst=2.2.2.200 | <ICMP type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>>>>>

Quoted 1 line
Quoted 1 line
Quoted 1 line

len(packet)

92

testpmd> flow flush 0
testpmd> port 0/queue 0: received 1 packets src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 - length=92

Quoted 5 lines

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end

I could not get enough time to completely look at this. Can you help understand the sequence a bit.

So when this flow create is issued, it looks like the application issues one of the helper APIs.
In response the PMD returns the vendor specific items/actions.
So what happens to the original match and action criteria provided by the user or applications?

Does the vendor provided actions and items in the tunnel descriptor take precedence over what was used by the application?

And is the criteria provided by the PMD opaque to the application? Such that only the PMD can decipher it when the application calls it for subsequent flow create(s)?

Quoted 871 lines

Flow rule #0 created
testpmd> port 0/queue 0: received 1 packets
tunnel restore info: - vxlan tunnel - outer header present # <--
src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 -
length=92

testpmd> flow create 0 ingress group 0 tunnel_match 1
pattern eth / ipv4 / udp dst is 4789 / vxlan / eth / ipv4 / end
actions set_mac_dst mac_addr 02:CA:FE:CA:FA:80 / queue index 0 / end
Flow rule #1 created
testpmd> port 0/queue 0: received 1 packets
src=50:BB:BB:BB:BB:E2 - dst=02:CA:FE:CA:FA:80 - type=0x0800 -
length=42

* Destroy flow tunnel
flow tunnel destroy <port> id <tunnel id>

* Show existing flow tunnels
flow tunnel list <port>

---
v2:
* introduce testpmd support for tunnel offload API

v3:
* update flow tunnel commands

---
 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 253 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 6 files changed, 533 insertions(+), 13 deletions(-)
app/test-pmd/cmdline_flow.c +166 -4
index 6263d307ed..0fb61860cd 100644
@@ -69,6 +69,14 @@ enum index {
        LIST,
        AGED,
        ISOLATE,
+       TUNNEL,
+
+       /* Tunnel argumens. */
+       TUNNEL_CREATE,
+       TUNNEL_CREATE_TYPE,
+       TUNNEL_LIST,
+       TUNNEL_DESTROY,
+       TUNNEL_DESTROY_ID,
 
        /* Destroy arguments. */
        DESTROY_RULE,
@@ -88,6 +96,8 @@ enum index {
        INGRESS,
        EGRESS,
        TRANSFER,
+       TUNNEL_SET,
+       TUNNEL_MATCH,
 
        /* Validate/create pattern. */
        PATTERN,
@@ -653,6 +663,7 @@ struct buffer {
        union {
                struct {
                        struct rte_flow_attr attr;
+                       struct tunnel_ops tunnel_ops;
                        struct rte_flow_item *pattern;
                        struct rte_flow_action *actions;
                        uint32_t pattern_n;
@@ -713,10 +724,32 @@ static const enum index next_vc_attr[] = {
        INGRESS,
        EGRESS,
        TRANSFER,
+       TUNNEL_SET,
+       TUNNEL_MATCH,
        PATTERN,
        ZERO,
 };
 
+static const enum index tunnel_create_attr[] = {
+       TUNNEL_CREATE,
+       TUNNEL_CREATE_TYPE,
+       END,
+       ZERO,
+};
+
+static const enum index tunnel_destroy_attr[] = {
+       TUNNEL_DESTROY,
+       TUNNEL_DESTROY_ID,
+       END,
+       ZERO,
+};
+
+static const enum index tunnel_list_attr[] = {
+       TUNNEL_LIST,
+       END,
+       ZERO,
+};
+
 static const enum index next_destroy_attr[] = {
        DESTROY_RULE,
        END,
@@ -1516,6 +1549,9 @@ static int parse_aged(struct context *, const struct token *,
 static int parse_isolate(struct context *, const struct token *,
                         const char *, unsigned int,
                         void *, unsigned int);
+static int parse_tunnel(struct context *, const struct token *,
+                       const char *, unsigned int,
+                       void *, unsigned int);
 static int parse_int(struct context *, const struct token *,
                     const char *, unsigned int,
                     void *, unsigned int);
@@ -1698,7 +1734,8 @@ static const struct token token_list[] = {
                              LIST,
                              AGED,
                              QUERY,
-                             ISOLATE)),
+                             ISOLATE,
+                             TUNNEL)),
                .call = parse_init,
        },
        /* Sub-level commands. */
@@ -1772,6 +1809,49 @@ static const struct token token_list[] = {
                             ARGS_ENTRY(struct buffer, port)),
                .call = parse_isolate,
        },
+       [TUNNEL] = {
+               .name = "tunnel",
+               .help = "new tunnel API",
+               .next = NEXT(NEXT_ENTRY
+                            (TUNNEL_CREATE, TUNNEL_LIST, TUNNEL_DESTROY)),
+               .call = parse_tunnel,
+       },
+       /* Tunnel arguments. */
+       [TUNNEL_CREATE] = {
+               .name = "create",
+               .help = "create new tunnel object",
+               .next = NEXT(tunnel_create_attr, NEXT_ENTRY(PORT_ID)),
+               .args = ARGS(ARGS_ENTRY(struct buffer, port)),
+               .call = parse_tunnel,
+       },
+       [TUNNEL_CREATE_TYPE] = {
+               .name = "type",
+               .help = "create new tunnel",
+               .next = NEXT(tunnel_create_attr, NEXT_ENTRY(FILE_PATH)),
+               .args = ARGS(ARGS_ENTRY(struct tunnel_ops, type)),
+               .call = parse_tunnel,
+       },
+       [TUNNEL_DESTROY] = {
+               .name = "destroy",
+               .help = "destroy tunel",
+               .next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(PORT_ID)),
+               .args = ARGS(ARGS_ENTRY(struct buffer, port)),
+               .call = parse_tunnel,
+       },
+       [TUNNEL_DESTROY_ID] = {
+               .name = "id",
+               .help = "tunnel identifier to testroy",
+               .next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+               .call = parse_tunnel,
+       },
+       [TUNNEL_LIST] = {
+               .name = "list",
+               .help = "list existing tunnels",
+               .next = NEXT(tunnel_list_attr, NEXT_ENTRY(PORT_ID)),
+               .args = ARGS(ARGS_ENTRY(struct buffer, port)),
+               .call = parse_tunnel,
+       },
        /* Destroy arguments. */
        [DESTROY_RULE] = {
                .name = "rule",
@@ -1835,6 +1915,20 @@ static const struct token token_list[] = {
                .next = NEXT(next_vc_attr),
                .call = parse_vc,
        },
+       [TUNNEL_SET] = {
+               .name = "tunnel_set",
+               .help = "tunnel steer rule",
+               .next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+               .call = parse_vc,
+       },
+       [TUNNEL_MATCH] = {
+               .name = "tunnel_match",
+               .help = "tunnel match rule",
+               .next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+               .call = parse_vc,
+       },
        /* Validate/create pattern. */
        [PATTERN] = {
                .name = "pattern",
@@ -4054,12 +4148,28 @@ parse_vc(struct context *ctx, const struct token *token,
                return len;
        }
        ctx->objdata = 0;
-       ctx->object = &out->args.vc.attr;
+       switch (ctx->curr) {
+       default:
+               ctx->object = &out->args.vc.attr;
+               break;
+       case TUNNEL_SET:
+       case TUNNEL_MATCH:
+               ctx->object = &out->args.vc.tunnel_ops;
+               break;
+       }
        ctx->objmask = NULL;
        switch (ctx->curr) {
        case GROUP:
        case PRIORITY:
                return len;
+       case TUNNEL_SET:
+               out->args.vc.tunnel_ops.enabled = 1;
+               out->args.vc.tunnel_ops.actions = 1;
+               return len;
+       case TUNNEL_MATCH:
+               out->args.vc.tunnel_ops.enabled = 1;
+               out->args.vc.tunnel_ops.items = 1;
+               return len;
        case INGRESS:
                out->args.vc.attr.ingress = 1;
                return len;
@@ -5597,6 +5707,47 @@ parse_isolate(struct context *ctx, const struct token *token,
        return len;
 }
 
+static int
+parse_tunnel(struct context *ctx, const struct token *token,
+            const char *str, unsigned int len,
+            void *buf, unsigned int size)
+{
+       struct buffer *out = buf;
+
+       /* Token name must match. */
+       if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+               return -1;
+       /* Nothing else to do if there is no buffer. */
+       if (!out)
+               return len;
+       if (!out->command) {
+               if (ctx->curr != TUNNEL)
+                       return -1;
+               if (sizeof(*out) > size)
+                       return -1;
+               out->command = ctx->curr;
+               ctx->objdata = 0;
+               ctx->object = out;
+               ctx->objmask = NULL;
+       } else {
+               switch (ctx->curr) {
+               default:
+                       break;
+               case TUNNEL_CREATE:
+               case TUNNEL_DESTROY:
+               case TUNNEL_LIST:
+                       out->command = ctx->curr;
+                       break;
+               case TUNNEL_CREATE_TYPE:
+               case TUNNEL_DESTROY_ID:
+                       ctx->object = &out->args.vc.tunnel_ops;
+                       break;
+               }
+       }
+
+       return len;
+}
+
 /**
  * Parse signed/unsigned integers 8 to 64-bit long.
  *
@@ -6543,11 +6694,13 @@ cmd_flow_parsed(const struct buffer *in)
        switch (in->command) {
        case VALIDATE:
                port_flow_validate(in->port, &in->args.vc.attr,
-                                  in->args.vc.pattern, in->args.vc.actions);
+                                  in->args.vc.pattern, in->args.vc.actions,
+                                  &in->args.vc.tunnel_ops);
                break;
        case CREATE:
                port_flow_create(in->port, &in->args.vc.attr,
-                                in->args.vc.pattern, in->args.vc.actions);
+                                in->args.vc.pattern, in->args.vc.actions,
+                                &in->args.vc.tunnel_ops);
                break;
        case DESTROY:
                port_flow_destroy(in->port, in->args.destroy.rule_n,
@@ -6573,6 +6726,15 @@ cmd_flow_parsed(const struct buffer *in)
        case AGED:
                port_flow_aged(in->port, in->args.aged.destroy);
                break;
+       case TUNNEL_CREATE:
+               port_flow_tunnel_create(in->port, &in->args.vc.tunnel_ops);
+               break;
+       case TUNNEL_DESTROY:
+               port_flow_tunnel_destroy(in->port, in->args.vc.tunnel_ops.id);
+               break;
+       case TUNNEL_LIST:
+               port_flow_tunnel_list(in->port);
+               break;
        default:
                break;
        }
app/test-pmd/config.c +249 -4
index 2d9a456467..d0f86230d0 100644
@@ -1339,6 +1339,115 @@ port_mtu_set(portid_t port_id, uint16_t mtu)
 
 /* Generic flow management functions. */
 
+static struct port_flow_tunnel *
+port_flow_locate_tunnel_id(struct rte_port *port, uint32_t port_tunnel_id)
+{
+       struct port_flow_tunnel *flow_tunnel;
+
+       LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
+               if (flow_tunnel->id == port_tunnel_id)
+                       goto out;
+       }
+       flow_tunnel = NULL;
+
+out:
+       return flow_tunnel;
+}
+
+const char *
+port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
+{
+       const char *type;
+       switch (tunnel->type) {
+       default:
+               type = "unknown";
+               break;
+       case RTE_FLOW_ITEM_TYPE_VXLAN:
+               type = "vxlan";
+               break;
+       }
+
+       return type;
+}
+
+struct port_flow_tunnel *
+port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
+{
+       struct rte_port *port = &ports[port_id];
+       struct port_flow_tunnel *flow_tunnel;
+
+       LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
+               if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
+                       goto out;
+       }
+       flow_tunnel = NULL;
+
+out:
+       return flow_tunnel;
+}
+
+void port_flow_tunnel_list(portid_t port_id)
+{
+       struct rte_port *port = &ports[port_id];
+       struct port_flow_tunnel *flt;
+
+       LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
+               printf("port %u tunnel #%u type=%s",
+                       port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
+               if (flt->tunnel.tun_id)
+                       printf(" id=%lu", flt->tunnel.tun_id);
+               printf("\n");
+       }
+}
+
+void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
+{
+       struct rte_port *port = &ports[port_id];
+       struct port_flow_tunnel *flt;
+
+       LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
+               if (flt->id == tunnel_id)
+                       break;
+       }
+       if (flt) {
+               LIST_REMOVE(flt, chain);
+               free(flt);
+               printf("port %u: flow tunnel #%u destroyed\n",
+                       port_id, tunnel_id);
+       }
+}
+
+void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops)
+{
+       struct rte_port *port = &ports[port_id];
+       enum rte_flow_item_type type;
+       struct port_flow_tunnel *flt;
+
+       if (!strcmp(ops->type, "vxlan"))
+               type = RTE_FLOW_ITEM_TYPE_VXLAN;
+       else {
+               printf("cannot offload \"%s\" tunnel type\n", ops->type);
+               return;
+       }
+       LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
+               if (flt->tunnel.type == type)
+                       break;
+       }
+       if (!flt) {
+               flt = calloc(1, sizeof(*flt));
+               if (!flt) {
+                       printf("failed to allocate port flt object\n");
+                       return;
+               }
+               flt->tunnel.type = type;
+               flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
+                                 LIST_FIRST(&port->flow_tunnel_list)->id + 1;
+               LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
+       }
+       printf("port %d: flow tunnel #%u type %s\n",
+               port_id, flt->id, ops->type);
+}
+
 /** Generate a port_flow entry from attributes/pattern/actions. */
 static struct port_flow *
 port_flow_new(const struct rte_flow_attr *attr,
@@ -1463,19 +1572,137 @@ rss_config_display(struct rte_flow_action_rss *rss_conf)
        }
 }
 
+static struct port_flow_tunnel *
+port_flow_tunnel_offload_cmd_prep(portid_t port_id,
+                                 const struct rte_flow_item *pattern,
+                                 const struct rte_flow_action *actions,
+                                 const struct tunnel_ops *tunnel_ops)
+{
+       int ret;
+       struct rte_port *port;
+       struct port_flow_tunnel *pft;
+       struct rte_flow_error error;
+
+       port = &ports[port_id];
+       pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
+       if (!pft) {
+               printf("failed to locate port flow tunnel #%u\n",
+                       tunnel_ops->id);
+               return NULL;
+       }
+       if (tunnel_ops->actions) {
+               uint32_t num_actions;
+               const struct rte_flow_action *aptr;
+
+               ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
+                                               &pft->pmd_actions,
+                                               &pft->num_pmd_actions,
+                                               &error);
+               if (ret) {
+                       port_flow_complain(&error);
+                       return NULL;
+               }
+               for (aptr = actions, num_actions = 1;
+                    aptr->type != RTE_FLOW_ACTION_TYPE_END;
+                    aptr++, num_actions++);
+               pft->actions = malloc(
+                               (num_actions +  pft->num_pmd_actions) *
+                               sizeof(actions[0]));
+               if (!pft->actions) {
+                       rte_flow_tunnel_action_decap_release(
+                                       port_id, pft->actions,
+                                       pft->num_pmd_actions, &error);
+                       return NULL;
+               }
+               rte_memcpy(pft->actions, pft->pmd_actions,
+                          pft->num_pmd_actions * sizeof(actions[0]));
+               rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
+                          num_actions * sizeof(actions[0]));
+       }
+       if (tunnel_ops->items) {
+               uint32_t num_items;
+               const struct rte_flow_item *iptr;
+
+               ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
+                                           &pft->pmd_items,
+                                           &pft->num_pmd_items,
+                                           &error);
+               if (ret) {
+                       port_flow_complain(&error);
+                       return NULL;
+               }
+               for (iptr = pattern, num_items = 1;
+                    iptr->type != RTE_FLOW_ITEM_TYPE_END;
+                    iptr++, num_items++);
+               pft->items = malloc((num_items + pft->num_pmd_items) *
+                                   sizeof(pattern[0]));
+               if (!pft->items) {
+                       rte_flow_tunnel_item_release(
+                                       port_id, pft->pmd_items,
+                                       pft->num_pmd_items, &error);
+                       return NULL;
+               }
+               rte_memcpy(pft->items, pft->pmd_items,
+                          pft->num_pmd_items * sizeof(pattern[0]));
+               rte_memcpy(pft->items + pft->num_pmd_items, pattern,
+                          num_items * sizeof(pattern[0]));
+       }
+
+       return pft;
+}
+
+static void
+port_flow_tunnel_offload_cmd_release(portid_t port_id,
+                                    const struct tunnel_ops *tunnel_ops,
+                                    struct port_flow_tunnel *pft)
+{
+       struct rte_flow_error error;
+
+       if (tunnel_ops->actions) {
+               free(pft->actions);
+               rte_flow_tunnel_action_decap_release(
+                       port_id, pft->pmd_actions,
+                       pft->num_pmd_actions, &error);
+               pft->actions = NULL;
+               pft->pmd_actions = NULL;
+       }
+       if (tunnel_ops->items) {
+               free(pft->items);
+               rte_flow_tunnel_item_release(port_id, pft->pmd_items,
+                                            pft->num_pmd_items,
+                                            &error);
+               pft->items = NULL;
+               pft->pmd_items = NULL;
+       }
+}
+
 /** Validate flow rule. */
 int
 port_flow_validate(portid_t port_id,
                   const struct rte_flow_attr *attr,
                   const struct rte_flow_item *pattern,
-                  const struct rte_flow_action *actions)
+                  const struct rte_flow_action *actions,
+                  const struct tunnel_ops *tunnel_ops)
 {
        struct rte_flow_error error;
+       struct port_flow_tunnel *pft = NULL;
 
        /* Poisoning to make sure PMDs update it in case of error. */
        memset(&error, 0x11, sizeof(error));
+       if (tunnel_ops->enabled) {
+               pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
+                                                       actions, tunnel_ops);
+               if (!pft)
+                       return -ENOENT;
+               if (pft->items)
+                       pattern = pft->items;
+               if (pft->actions)
+                       actions = pft->actions;
+       }
        if (rte_flow_validate(port_id, attr, pattern, actions, &error))
                return port_flow_complain(&error);
+       if (tunnel_ops->enabled)
+               port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
        printf("Flow rule validated\n");
        return 0;
 }
@@ -1505,13 +1732,15 @@ int
 port_flow_create(portid_t port_id,
                 const struct rte_flow_attr *attr,
                 const struct rte_flow_item *pattern,
-                const struct rte_flow_action *actions)
+                const struct rte_flow_action *actions,
+                const struct tunnel_ops *tunnel_ops)
 {
        struct rte_flow *flow;
        struct rte_port *port;
        struct port_flow *pf;
        uint32_t id = 0;
        struct rte_flow_error error;
+       struct port_flow_tunnel *pft = NULL;
 
        port = &ports[port_id];
        if (port->flow_list) {
@@ -1522,6 +1751,16 @@ port_flow_create(portid_t port_id,
                }
                id = port->flow_list->id + 1;
        }
+       if (tunnel_ops->enabled) {
+               pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
+                                                       actions, tunnel_ops);
+               if (!pft)
+                       return -ENOENT;
+               if (pft->items)
+                       pattern = pft->items;
+               if (pft->actions)
+                       actions = pft->actions;
+       }
        pf = port_flow_new(attr, pattern, actions, &error);
        if (!pf)
                return port_flow_complain(&error);
@@ -1537,6 +1776,8 @@ port_flow_create(portid_t port_id,
        pf->id = id;
        pf->flow = flow;
        port->flow_list = pf;
+       if (tunnel_ops->enabled)
+               port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
        printf("Flow rule #%u created\n", pf->id);
        return 0;
 }
@@ -1831,7 +2072,9 @@ port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
                       pf->rule.attr->egress ? 'e' : '-',
                       pf->rule.attr->transfer ? 't' : '-');
                while (item->type != RTE_FLOW_ITEM_TYPE_END) {
-                       if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
+                       if ((uint32_t)item->type > INT_MAX)
+                               name = "PMD_INTERNAL";
+                       else if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
                                          &name, sizeof(name),
                                          (void *)(uintptr_t)item->type,
                                          NULL) <= 0)
@@ -1842,7 +2085,9 @@ port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])
                }
                printf("=>");
                while (action->type != RTE_FLOW_ACTION_TYPE_END) {
-                       if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
+                       if ((uint32_t)action->type > INT_MAX)
+                               name = "PMD_INTERNAL";
+                       else if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
                                          &name, sizeof(name),
                                          (void *)(uintptr_t)action->type,
                                          NULL) <= 0)
app/test-pmd/testpmd.c +4 -1
index fe6450cc0d..e484079147 100644
@@ -3588,6 +3588,8 @@ init_port_dcb_config(portid_t pid,
 static void
 init_port(void)
 {
+       int i;
+
        /* Configuration of Ethernet ports. */
        ports = rte_zmalloc("testpmd: ports",
                            sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
@@ -3597,7 +3599,8 @@ init_port(void)
                                "rte_zmalloc(%d struct rte_port) failed\n",
                                RTE_MAX_ETHPORTS);
        }
-
+       for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+               LIST_INIT(&ports[i].flow_tunnel_list);
        /* Initialize ports NUMA structures */
        memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
        memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
app/test-pmd/testpmd.h +32 -2
index f139fe7a0a..1dd8cfd3d8 100644
@@ -12,6 +12,7 @@
 #include <rte_gro.h>
 #include <rte_gso.h>
 #include <cmdline.h>
+#include <sys/queue.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -142,6 +143,26 @@ struct port_flow {
        uint8_t data[]; /**< Storage for flow rule description */
 };
 
+struct port_flow_tunnel {
+       LIST_ENTRY(port_flow_tunnel) chain;
+       struct rte_flow_action *pmd_actions;
+       struct rte_flow_item   *pmd_items;
+       uint32_t id;
+       uint32_t num_pmd_actions;
+       uint32_t num_pmd_items;
+       struct rte_flow_tunnel tunnel;
+       struct rte_flow_action *actions;
+       struct rte_flow_item *items;
+};
+
+struct tunnel_ops {
+       uint32_t id;
+       char type[16];
+       uint32_t enabled:1;
+       uint32_t actions:1;
+       uint32_t items:1;
+};
+
 /**
  * The data structure associated with each port.
  */
@@ -172,6 +193,7 @@ struct rte_port {
        uint32_t                mc_addr_nb; /**< nb. of addr. in mc_addr_pool */
        uint8_t                 slave_flag; /**< bonding slave port */
        struct port_flow        *flow_list; /**< Associated flows. */
+       LIST_HEAD(, port_flow_tunnel) flow_tunnel_list;
        const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
        const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
        /**< metadata value to insert in Tx packets. */
@@ -749,11 +771,13 @@ void port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t value);
 int port_flow_validate(portid_t port_id,
                       const struct rte_flow_attr *attr,
                       const struct rte_flow_item *pattern,
-                      const struct rte_flow_action *actions);
+                      const struct rte_flow_action *actions,
+                      const struct tunnel_ops *tunnel_ops);
 int port_flow_create(portid_t port_id,
                     const struct rte_flow_attr *attr,
                     const struct rte_flow_item *pattern,
-                    const struct rte_flow_action *actions);
+                    const struct rte_flow_action *actions,
+                    const struct tunnel_ops *tunnel_ops);
 void update_age_action_context(const struct rte_flow_action *actions,
                     struct port_flow *pf);
 int port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule);
@@ -763,6 +787,12 @@ int port_flow_query(portid_t port_id, uint32_t rule,
                    const struct rte_flow_action *action);
 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
 void port_flow_aged(portid_t port_id, uint8_t destroy);
+const char *port_flow_tunnel_type(struct rte_flow_tunnel *tunnel);
+struct port_flow_tunnel *
+port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun);
+void port_flow_tunnel_list(portid_t port_id);
+void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
+void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops);
 int port_flow_isolate(portid_t port_id, int set);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
app/test-pmd/util.c +33 -2
index 8488fa1a8f..781a813759 100644
@@ -48,18 +48,49 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
               is_rx ? "received" : "sent",
               (unsigned int) nb_pkts);
        for (i = 0; i < nb_pkts; i++) {
+               int ret;
+               struct rte_flow_error error;
+               struct rte_flow_restore_info info = { 0, };
+
                mb = pkts[i];
                eth_hdr = rte_pktmbuf_read(mb, 0, sizeof(_eth_hdr), &_eth_hdr);
                eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
-               ol_flags = mb->ol_flags;
                packet_type = mb->packet_type;
                is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
-
+               ret = rte_flow_get_restore_info(port_id, mb, &info, &error);
+               if (!ret) {
+                       printf("restore info:");
+                       if (info.flags & RTE_FLOW_RESTORE_INFO_TUNNEL) {
+                               struct port_flow_tunnel *port_tunnel;
+
+                               port_tunnel = port_flow_locate_tunnel
+                                             (port_id, &info.tunnel);
+                               printf(" - tunnel");
+                               if (port_tunnel)
+                                       printf(" #%u", port_tunnel->id);
+                               else
+                                       printf(" %s", "-none-");
+                               printf(" type %s",
+                                       port_flow_tunnel_type(&info.tunnel));
+                       } else {
+                               printf(" - no tunnel info");
+                       }
+                       if (info.flags & RTE_FLOW_RESTORE_INFO_ENCAPSULATED)
+                               printf(" - outer header present");
+                       else
+                               printf(" - no outer header");
+                       if (info.flags & RTE_FLOW_RESTORE_INFO_GROUP_ID)
+                               printf(" - miss group %u", info.group_id);
+                       else
+                               printf(" - no miss group");
+                       printf("\n");
+               }
                print_ether_addr("  src=", &eth_hdr->s_addr);
                print_ether_addr(" - dst=", &eth_hdr->d_addr);
                printf(" - type=0x%04x - length=%u - nb_segs=%d",
                       eth_type, (unsigned int) mb->pkt_len,
                       (int)mb->nb_segs);
+               ol_flags = mb->ol_flags;
                if (ol_flags & PKT_RX_RSS_HASH) {
                        printf(" - RSS hash=0x%x", (unsigned int) mb->hash.rss);
                        printf(" - RSS queue=0x%x", (unsigned int) queue);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +49 -1
index a972ef8951..97fcbfd329 100644
@@ -3720,6 +3720,45 @@ following sections.
 
    flow aged {port_id} [destroy]
 
+- Tunnel offload - create a tunnel stub::
+
+   flow tunnel create {port_id} type {tunnel_type}
+
+- Tunnel offload - destroy a tunnel stub::
+
+   flow tunnel destroy {port_id} id {tunnel_id}
+
+- Tunnel offload - list port tunnel stubs::
+
+   flow tunnel list {port_id}
+
+Creating a tunnel stub for offload
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow tunnel create`` setup a tunnel stub for tunnel offload flow rules::
+
+   flow tunnel create {port_id} type {tunnel_type}
+
+If successful, it will return a tunnel stub ID usable with other commands::
+
+   port [...]: flow tunnel #[...] type [...]
+
+Tunnel stub ID is relative to a port.
+
+Destroying tunnel offload stub
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow tunnel destroy`` destroy port tunnel stub::
+
+   flow tunnel destroy {port_id} id {tunnel_id}
+
+Listing tunnel offload stubs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow tunnel list`` list port tunnel offload stubs::
+
+   flow tunnel list {port_id}
+
 Validating flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
@@ -3766,6 +3805,7 @@ to ``rte_flow_create()``::
 
    flow create {port_id}
       [group {group_id}] [priority {level}] [ingress] [egress] [transfer]
+      [tunnel_set {tunnel_id}] [tunnel_match {tunnel_id}]
       pattern {item} [/ {item} [...]] / end
       actions {action} [/ {action} [...]] / end
 
@@ -3780,6 +3820,7 @@ Otherwise it will show an error message of the form::
 Parameters describe in the following order:
 
 - Attributes (*group*, *priority*, *ingress*, *egress*, *transfer* tokens).
+- Tunnel offload specification (tunnel_set, tunnel_match)
 - A matching pattern, starting with the *pattern* token and terminated by an
   *end* pattern item.
 - Actions, starting with the *actions* token and terminated by an *end*
@@ -3823,6 +3864,14 @@ Most rules affect RX therefore contain the ``ingress`` token::
 
    testpmd> flow create 0 ingress pattern [...]
 
+Tunnel offload
+^^^^^^^^^^^^^^
+
+Indicate tunnel offload rule type
+
+- ``tunnel_set {tunnel_id}``: mark rule as tunnel offload decap_set type.
+- ``tunnel_match {tunnel_id}``:  mark rule as tunel offload match type.
+
 Matching pattern
 ^^^^^^^^^^^^^^^^
 
--

2.25.1

#39 lore raw

Re: [dpdk-dev] [PATCH v3 4/4] app/testpmd: add commands for tunnel offload API

Hello Ajit,

Quoted 62 lines

-----Original Message-----

Quoted 43 lines · Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:

* Create application tunnel:
flow tunnel create <port> type <tunnel type>
On success, the command creates application tunnel object and returns the tunnel descriptor. Tunnel descriptor is used in subsequent flow creation commands to reference the tunnel.

* Create tunnel steering flow rule:
tunnel_set <tunnel descriptor> parameter used with steering rule template.

* Create tunnel matching flow rule:
tunnel_match <tunnel descriptor> used with matching rule template.

* If tunnel steering rule was offloaded, outer header of a partially offloaded packet is restored after miss.

Example:
test packet=
<Ether dst=24:8a:07:8d:ae:d6 src=50:6b:4b:cc:fc:e2 type=IPv4 | <IP version=4 ihl=5 proto=udp src=1.1.1.1 dst=1.1.1.10 | <UDP sport=4789 dport=4789 len=58 chksum=0x7f7b |
<VXLAN NextProtocol=Ethernet vni=0x0 |
<Ether dst=24:aa:aa:aa:aa:d6 src=50:bb:bb:bb:bb:e2 type=IPv4 | <IP version=4 ihl=5 proto=icmp src=2.2.2.2 dst=2.2.2.200 | <ICMP type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>>>>>

Quoted 1 line
Quoted 1 line
Quoted 1 line

len(packet)

92

testpmd> flow flush 0
testpmd> port 0/queue 0: received 1 packets src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 - length=92

Quoted 5 lines

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end

I could not get enough time to completely look at this. Can you help understand the sequence a bit.

So when this flow create is issued, it looks like the application issues one of the helper APIs.
In response the PMD returns the vendor specific items/actions. So what happens to the original match and action criteria provided by the user
or applications?

Quoted 7 lines

Does the vendor provided actions and items in the tunnel descriptor take precedence over what was used by the application?

And is the criteria provided by the PMD opaque to the application? Such that only the PMD can decipher it when the application calls it for subsequent flow create(s)?

Flow rules that implement tunnel offload API are compiled from application and PMD actions and items. Both application and PMD elements are equally important for offload rule creation. Application is "aware" what type of tunnel offload flow rule, decap_set or match, it builds. Therefore, application elements are created according to tunnel offload rule type and the API helper function, that matches selected rule type, is activated to provide PMD elements. PMD elements are opaque. When all elements are present, application concatenates PMD items with application items and PMD actions with application actions. As the result application will have pattern & actions arrays for flow rule creation. For the decap_set rule, the API expects application to provide pattern that describes a tunnel and the JUMP action, although the JUMP is not strictly required. And for the match rule, application pattern should describe packet headers and actions refer to inner parts.

Quoted 892 lines

app/test-pmd/cmdline_flow.c static int parse_aged(struct context *, const

Quoted 108 lines

Flow rule #0 created
testpmd> port 0/queue 0: received 1 packets
tunnel restore info: - vxlan tunnel - outer header present # <--
src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 -
length=92

testpmd> flow create 0 ingress group 0 tunnel_match 1
pattern eth / ipv4 / udp dst is 4789 / vxlan / eth / ipv4 / end
actions set_mac_dst mac_addr 02:CA:FE:CA:FA:80 / queue index 0 / end
Flow rule #1 created
testpmd> port 0/queue 0: received 1 packets
src=50:BB:BB:BB:BB:E2 - dst=02:CA:FE:CA:FA:80 - type=0x0800 -
length=42

* Destroy flow tunnel
flow tunnel destroy <port> id <tunnel id>

* Show existing flow tunnels
flow tunnel list <port>

---
v2:
* introduce testpmd support for tunnel offload API

v3:
* update flow tunnel commands

---
 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 253 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 6 files changed, 533 insertions(+), 13 deletions(-)
app/test-pmd/cmdline_flow.c +33 -0
index 6263d307ed..0fb61860cd 100644
@@ -69,6 +69,14 @@ enum index {
        LIST,
        AGED,
        ISOLATE,
+       TUNNEL,
+
+       /* Tunnel argumens. */
+       TUNNEL_CREATE,
+       TUNNEL_CREATE_TYPE,
+       TUNNEL_LIST,
+       TUNNEL_DESTROY,
+       TUNNEL_DESTROY_ID,
 
        /* Destroy arguments. */
        DESTROY_RULE,
@@ -88,6 +96,8 @@ enum index {
        INGRESS,
        EGRESS,
        TRANSFER,
+       TUNNEL_SET,
+       TUNNEL_MATCH,
 
        /* Validate/create pattern. */
        PATTERN,
@@ -653,6 +663,7 @@ struct buffer {
        union {
                struct {
                        struct rte_flow_attr attr;
+                       struct tunnel_ops tunnel_ops;
                        struct rte_flow_item *pattern;
                        struct rte_flow_action *actions;
                        uint32_t pattern_n;
@@ -713,10 +724,32 @@ static const enum index next_vc_attr[] = {
        INGRESS,
        EGRESS,
        TRANSFER,
+       TUNNEL_SET,
+       TUNNEL_MATCH,
        PATTERN,
        ZERO,
 };
 
+static const enum index tunnel_create_attr[] = {
+       TUNNEL_CREATE,
+       TUNNEL_CREATE_TYPE,
+       END,
+       ZERO,
+};
+
+static const enum index tunnel_destroy_attr[] = {
+       TUNNEL_DESTROY,
+       TUNNEL_DESTROY_ID,
+       END,
+       ZERO,
+};
+
+static const enum index tunnel_list_attr[] = {
+       TUNNEL_LIST,
+       END,
+       ZERO,
+};
+
 static const enum index next_destroy_attr[] = {
        DESTROY_RULE,
        END,
@@ -1516,6 +1549,9 @@ static int parse_aged(struct context *, const

struct token *,

app/test-pmd/cmdline_flow.c parse_vc(struct context *ctx, const struct

Quoted 91 lines
app/test-pmd/cmdline_flow.c +62 -1
 static int parse_isolate(struct context *, const struct token *,
                         const char *, unsigned int,
                         void *, unsigned int);
+static int parse_tunnel(struct context *, const struct token *,
+                       const char *, unsigned int,
+                       void *, unsigned int);
 static int parse_int(struct context *, const struct token *,
                     const char *, unsigned int,
                     void *, unsigned int);
@@ -1698,7 +1734,8 @@ static const struct token token_list[] = {
                              LIST,
                              AGED,
                              QUERY,
-                             ISOLATE)),
+                             ISOLATE,
+                             TUNNEL)),
                .call = parse_init,
        },
        /* Sub-level commands. */
@@ -1772,6 +1809,49 @@ static const struct token token_list[] = {
                             ARGS_ENTRY(struct buffer, port)),
                .call = parse_isolate,
        },
+       [TUNNEL] = {
+               .name = "tunnel",
+               .help = "new tunnel API",
+               .next = NEXT(NEXT_ENTRY
+                            (TUNNEL_CREATE, TUNNEL_LIST, TUNNEL_DESTROY)),
+               .call = parse_tunnel,
+       },
+       /* Tunnel arguments. */
+       [TUNNEL_CREATE] = {
+               .name = "create",
+               .help = "create new tunnel object",
+               .next = NEXT(tunnel_create_attr, NEXT_ENTRY(PORT_ID)),
+               .args = ARGS(ARGS_ENTRY(struct buffer, port)),
+               .call = parse_tunnel,
+       },
+       [TUNNEL_CREATE_TYPE] = {
+               .name = "type",
+               .help = "create new tunnel",
+               .next = NEXT(tunnel_create_attr, NEXT_ENTRY(FILE_PATH)),
+               .args = ARGS(ARGS_ENTRY(struct tunnel_ops, type)),
+               .call = parse_tunnel,
+       },
+       [TUNNEL_DESTROY] = {
+               .name = "destroy",
+               .help = "destroy tunel",
+               .next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(PORT_ID)),
+               .args = ARGS(ARGS_ENTRY(struct buffer, port)),
+               .call = parse_tunnel,
+       },
+       [TUNNEL_DESTROY_ID] = {
+               .name = "id",
+               .help = "tunnel identifier to testroy",
+               .next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+               .call = parse_tunnel,
+       },
+       [TUNNEL_LIST] = {
+               .name = "list",
+               .help = "list existing tunnels",
+               .next = NEXT(tunnel_list_attr, NEXT_ENTRY(PORT_ID)),
+               .args = ARGS(ARGS_ENTRY(struct buffer, port)),
+               .call = parse_tunnel,
+       },
        /* Destroy arguments. */
        [DESTROY_RULE] = {
                .name = "rule",
@@ -1835,6 +1915,20 @@ static const struct token token_list[] = {
                .next = NEXT(next_vc_attr),
                .call = parse_vc,
        },
+       [TUNNEL_SET] = {
+               .name = "tunnel_set",
+               .help = "tunnel steer rule",
+               .next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+               .call = parse_vc,
+       },
+       [TUNNEL_MATCH] = {
+               .name = "tunnel_match",
+               .help = "tunnel match rule",
+               .next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+               .call = parse_vc,
+       },
        /* Validate/create pattern. */
        [PATTERN] = {
                .name = "pattern",
@@ -4054,12 +4148,28 @@ parse_vc(struct context *ctx, const struct

token *token,

app/test-pmd/cmdline_flow.c parse_isolate(struct context *ctx, const struct

Quoted 30 lines
app/test-pmd/cmdline_flow.c +17 -1
                return len;
        }
        ctx->objdata = 0;
-       ctx->object = &out->args.vc.attr;
+       switch (ctx->curr) {
+       default:
+               ctx->object = &out->args.vc.attr;
+               break;
+       case TUNNEL_SET:
+       case TUNNEL_MATCH:
+               ctx->object = &out->args.vc.tunnel_ops;
+               break;
+       }
        ctx->objmask = NULL;
        switch (ctx->curr) {
        case GROUP:
        case PRIORITY:
                return len;
+       case TUNNEL_SET:
+               out->args.vc.tunnel_ops.enabled = 1;
+               out->args.vc.tunnel_ops.actions = 1;
+               return len;
+       case TUNNEL_MATCH:
+               out->args.vc.tunnel_ops.enabled = 1;
+               out->args.vc.tunnel_ops.items = 1;
+               return len;
        case INGRESS:
                out->args.vc.attr.ingress = 1;
                return len;
@@ -5597,6 +5707,47 @@ parse_isolate(struct context *ctx, const struct

token *token,

Quoted 84 lines
app/test-pmd/cmdline_flow.c +54 -2
        return len;
 }
 
+static int
+parse_tunnel(struct context *ctx, const struct token *token,
+            const char *str, unsigned int len,
+            void *buf, unsigned int size)
+{
+       struct buffer *out = buf;
+
+       /* Token name must match. */
+       if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+               return -1;
+       /* Nothing else to do if there is no buffer. */
+       if (!out)
+               return len;
+       if (!out->command) {
+               if (ctx->curr != TUNNEL)
+                       return -1;
+               if (sizeof(*out) > size)
+                       return -1;
+               out->command = ctx->curr;
+               ctx->objdata = 0;
+               ctx->object = out;
+               ctx->objmask = NULL;
+       } else {
+               switch (ctx->curr) {
+               default:
+                       break;
+               case TUNNEL_CREATE:
+               case TUNNEL_DESTROY:
+               case TUNNEL_LIST:
+                       out->command = ctx->curr;
+                       break;
+               case TUNNEL_CREATE_TYPE:
+               case TUNNEL_DESTROY_ID:
+                       ctx->object = &out->args.vc.tunnel_ops;
+                       break;
+               }
+       }
+
+       return len;
+}
+
 /**
  * Parse signed/unsigned integers 8 to 64-bit long.
  *
@@ -6543,11 +6694,13 @@ cmd_flow_parsed(const struct buffer *in)
        switch (in->command) {
        case VALIDATE:
                port_flow_validate(in->port, &in->args.vc.attr,
-                                  in->args.vc.pattern, in->args.vc.actions);
+                                  in->args.vc.pattern, in->args.vc.actions,
+                                  &in->args.vc.tunnel_ops);
                break;
        case CREATE:
                port_flow_create(in->port, &in->args.vc.attr,
-                                in->args.vc.pattern, in->args.vc.actions);
+                                in->args.vc.pattern, in->args.vc.actions,
+                                &in->args.vc.tunnel_ops);
                break;
        case DESTROY:
                port_flow_destroy(in->port, in->args.destroy.rule_n,
@@ -6573,6 +6726,15 @@ cmd_flow_parsed(const struct buffer *in)
        case AGED:
                port_flow_aged(in->port, in->args.aged.destroy);
                break;
+       case TUNNEL_CREATE:
+               port_flow_tunnel_create(in->port, &in->args.vc.tunnel_ops);
+               break;
+       case TUNNEL_DESTROY:
+               port_flow_tunnel_destroy(in->port, in->args.vc.tunnel_ops.id);
+               break;
+       case TUNNEL_LIST:
+               port_flow_tunnel_list(in->port);
+               break;
        default:
                break;
        }
app/test-pmd/config.c +0 -0
index 2d9a456467..d0f86230d0 100644

app/test-pmd/config.c port_mtu_set(portid_t port_id, uint16_t mtu) · line 1343

Quoted 5 lines
app/test-pmd/config.c +2 -0
@@ -1339,6 +1339,115 @@ port_mtu_set(portid_t port_id, uint16_t mtu)
 
 /* Generic flow management functions. */
 
+static struct port_flow_tunnel *
+port_flow_locate_tunnel_id(struct rte_port *port, uint32_t

port_tunnel_id)

Quoted 67 lines
app/test-pmd/config.c +67 -0
+{
+       struct port_flow_tunnel *flow_tunnel;
+
+       LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
+               if (flow_tunnel->id == port_tunnel_id)
+                       goto out;
+       }
+       flow_tunnel = NULL;
+
+out:
+       return flow_tunnel;
+}
+
+const char *
+port_flow_tunnel_type(struct rte_flow_tunnel *tunnel)
+{
+       const char *type;
+       switch (tunnel->type) {
+       default:
+               type = "unknown";
+               break;
+       case RTE_FLOW_ITEM_TYPE_VXLAN:
+               type = "vxlan";
+               break;
+       }
+
+       return type;
+}
+
+struct port_flow_tunnel *
+port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun)
+{
+       struct rte_port *port = &ports[port_id];
+       struct port_flow_tunnel *flow_tunnel;
+
+       LIST_FOREACH(flow_tunnel, &port->flow_tunnel_list, chain) {
+               if (!memcmp(&flow_tunnel->tunnel, tun, sizeof(*tun)))
+                       goto out;
+       }
+       flow_tunnel = NULL;
+
+out:
+       return flow_tunnel;
+}
+
+void port_flow_tunnel_list(portid_t port_id)
+{
+       struct rte_port *port = &ports[port_id];
+       struct port_flow_tunnel *flt;
+
+       LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
+               printf("port %u tunnel #%u type=%s",
+                       port_id, flt->id, port_flow_tunnel_type(&flt->tunnel));
+               if (flt->tunnel.tun_id)
+                       printf(" id=%lu", flt->tunnel.tun_id);
+               printf("\n");
+       }
+}
+
+void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id)
+{
+       struct rte_port *port = &ports[port_id];
+       struct port_flow_tunnel *flt;
+
+       LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
+               if (flt->id == tunnel_id)
+                       break;

app/test-pmd/config.c port_mtu_set(portid_t port_id, uint16_t mtu)

Quoted 10 lines
app/test-pmd/config.c +10 -0
+       }
+       if (flt) {
+               LIST_REMOVE(flt, chain);
+               free(flt);
+               printf("port %u: flow tunnel #%u destroyed\n",
+                       port_id, tunnel_id);
+       }
+}
+
+void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops

*ops)

app/test-pmd/config.c rss_config_display(struct rte_flow_action_rss

Quoted 34 lines
app/test-pmd/config.c +30 -0
+{
+       struct rte_port *port = &ports[port_id];
+       enum rte_flow_item_type type;
+       struct port_flow_tunnel *flt;
+
+       if (!strcmp(ops->type, "vxlan"))
+               type = RTE_FLOW_ITEM_TYPE_VXLAN;
+       else {
+               printf("cannot offload \"%s\" tunnel type\n", ops->type);
+               return;
+       }
+       LIST_FOREACH(flt, &port->flow_tunnel_list, chain) {
+               if (flt->tunnel.type == type)
+                       break;
+       }
+       if (!flt) {
+               flt = calloc(1, sizeof(*flt));
+               if (!flt) {
+                       printf("failed to allocate port flt object\n");
+                       return;
+               }
+               flt->tunnel.type = type;
+               flt->id = LIST_EMPTY(&port->flow_tunnel_list) ? 1 :
+                                 LIST_FIRST(&port->flow_tunnel_list)->id + 1;
+               LIST_INSERT_HEAD(&port->flow_tunnel_list, flt, chain);
+       }
+       printf("port %d: flow tunnel #%u type %s\n",
+               port_id, flt->id, ops->type);
+}
+
 /** Generate a port_flow entry from attributes/pattern/actions. */
 static struct port_flow *
 port_flow_new(const struct rte_flow_attr *attr,
@@ -1463,19 +1572,137 @@ rss_config_display(struct rte_flow_action_rss

*rss_conf)

app/test-pmd/config.c port_flow_list(portid_t port_id, uint32_t n, const

Quoted 182 lines
app/test-pmd/config.c +134 -2
        }
 }
 
+static struct port_flow_tunnel *
+port_flow_tunnel_offload_cmd_prep(portid_t port_id,
+                                 const struct rte_flow_item *pattern,
+                                 const struct rte_flow_action *actions,
+                                 const struct tunnel_ops *tunnel_ops)
+{
+       int ret;
+       struct rte_port *port;
+       struct port_flow_tunnel *pft;
+       struct rte_flow_error error;
+
+       port = &ports[port_id];
+       pft = port_flow_locate_tunnel_id(port, tunnel_ops->id);
+       if (!pft) {
+               printf("failed to locate port flow tunnel #%u\n",
+                       tunnel_ops->id);
+               return NULL;
+       }
+       if (tunnel_ops->actions) {
+               uint32_t num_actions;
+               const struct rte_flow_action *aptr;
+
+               ret = rte_flow_tunnel_decap_set(port_id, &pft->tunnel,
+                                               &pft->pmd_actions,
+                                               &pft->num_pmd_actions,
+                                               &error);
+               if (ret) {
+                       port_flow_complain(&error);
+                       return NULL;
+               }
+               for (aptr = actions, num_actions = 1;
+                    aptr->type != RTE_FLOW_ACTION_TYPE_END;
+                    aptr++, num_actions++);
+               pft->actions = malloc(
+                               (num_actions +  pft->num_pmd_actions) *
+                               sizeof(actions[0]));
+               if (!pft->actions) {
+                       rte_flow_tunnel_action_decap_release(
+                                       port_id, pft->actions,
+                                       pft->num_pmd_actions, &error);
+                       return NULL;
+               }
+               rte_memcpy(pft->actions, pft->pmd_actions,
+                          pft->num_pmd_actions * sizeof(actions[0]));
+               rte_memcpy(pft->actions + pft->num_pmd_actions, actions,
+                          num_actions * sizeof(actions[0]));
+       }
+       if (tunnel_ops->items) {
+               uint32_t num_items;
+               const struct rte_flow_item *iptr;
+
+               ret = rte_flow_tunnel_match(port_id, &pft->tunnel,
+                                           &pft->pmd_items,
+                                           &pft->num_pmd_items,
+                                           &error);
+               if (ret) {
+                       port_flow_complain(&error);
+                       return NULL;
+               }
+               for (iptr = pattern, num_items = 1;
+                    iptr->type != RTE_FLOW_ITEM_TYPE_END;
+                    iptr++, num_items++);
+               pft->items = malloc((num_items + pft->num_pmd_items) *
+                                   sizeof(pattern[0]));
+               if (!pft->items) {
+                       rte_flow_tunnel_item_release(
+                                       port_id, pft->pmd_items,
+                                       pft->num_pmd_items, &error);
+                       return NULL;
+               }
+               rte_memcpy(pft->items, pft->pmd_items,
+                          pft->num_pmd_items * sizeof(pattern[0]));
+               rte_memcpy(pft->items + pft->num_pmd_items, pattern,
+                          num_items * sizeof(pattern[0]));
+       }
+
+       return pft;
+}
+
+static void
+port_flow_tunnel_offload_cmd_release(portid_t port_id,
+                                    const struct tunnel_ops *tunnel_ops,
+                                    struct port_flow_tunnel *pft)
+{
+       struct rte_flow_error error;
+
+       if (tunnel_ops->actions) {
+               free(pft->actions);
+               rte_flow_tunnel_action_decap_release(
+                       port_id, pft->pmd_actions,
+                       pft->num_pmd_actions, &error);
+               pft->actions = NULL;
+               pft->pmd_actions = NULL;
+       }
+       if (tunnel_ops->items) {
+               free(pft->items);
+               rte_flow_tunnel_item_release(port_id, pft->pmd_items,
+                                            pft->num_pmd_items,
+                                            &error);
+               pft->items = NULL;
+               pft->pmd_items = NULL;
+       }
+}
+
 /** Validate flow rule. */
 int
 port_flow_validate(portid_t port_id,
                   const struct rte_flow_attr *attr,
                   const struct rte_flow_item *pattern,
-                  const struct rte_flow_action *actions)
+                  const struct rte_flow_action *actions,
+                  const struct tunnel_ops *tunnel_ops)
 {
        struct rte_flow_error error;
+       struct port_flow_tunnel *pft = NULL;
 
        /* Poisoning to make sure PMDs update it in case of error. */
        memset(&error, 0x11, sizeof(error));
+       if (tunnel_ops->enabled) {
+               pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
+                                                       actions, tunnel_ops);
+               if (!pft)
+                       return -ENOENT;
+               if (pft->items)
+                       pattern = pft->items;
+               if (pft->actions)
+                       actions = pft->actions;
+       }
        if (rte_flow_validate(port_id, attr, pattern, actions, &error))
                return port_flow_complain(&error);
+       if (tunnel_ops->enabled)
+               port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
        printf("Flow rule validated\n");
        return 0;
 }
@@ -1505,13 +1732,15 @@ int
 port_flow_create(portid_t port_id,
                 const struct rte_flow_attr *attr,
                 const struct rte_flow_item *pattern,
-                const struct rte_flow_action *actions)
+                const struct rte_flow_action *actions,
+                const struct tunnel_ops *tunnel_ops)
 {
        struct rte_flow *flow;
        struct rte_port *port;
        struct port_flow *pf;
        uint32_t id = 0;
        struct rte_flow_error error;
+       struct port_flow_tunnel *pft = NULL;
 
        port = &ports[port_id];
        if (port->flow_list) {
@@ -1522,6 +1751,16 @@ port_flow_create(portid_t port_id,
                }
                id = port->flow_list->id + 1;
        }
+       if (tunnel_ops->enabled) {
+               pft = port_flow_tunnel_offload_cmd_prep(port_id, pattern,
+                                                       actions, tunnel_ops);
+               if (!pft)
+                       return -ENOENT;
+               if (pft->items)
+                       pattern = pft->items;
+               if (pft->actions)
+                       actions = pft->actions;
+       }
        pf = port_flow_new(attr, pattern, actions, &error);
        if (!pf)
                return port_flow_complain(&error);
@@ -1537,6 +1776,8 @@ port_flow_create(portid_t port_id,
        pf->id = id;
        pf->flow = flow;
        port->flow_list = pf;
+       if (tunnel_ops->enabled)
+               port_flow_tunnel_offload_cmd_release(port_id, tunnel_ops, pft);
        printf("Flow rule #%u created\n", pf->id);
        return 0;
 }
@@ -1831,7 +2072,9 @@ port_flow_list(portid_t port_id, uint32_t n, const

uint32_t group[n])

app/test-pmd/config.c port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])

Quoted 7 lines
app/test-pmd/config.c +3 -1
                       pf->rule.attr->egress ? 'e' : '-',
                       pf->rule.attr->transfer ? 't' : '-');
                while (item->type != RTE_FLOW_ITEM_TYPE_END) {
-                       if (rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,
+                       if ((uint32_t)item->type > INT_MAX)
+                               name = "PMD_INTERNAL";
+                       else if

(rte_flow_conv(RTE_FLOW_CONV_OP_ITEM_NAME_PTR,

app/test-pmd/config.c port_flow_list(portid_t port_id, uint32_t n, const

Quoted 4 lines
app/test-pmd/config.c +0 -0
                                          &name, sizeof(name),
                                          (void *)(uintptr_t)item->type,
                                          NULL) <= 0)
@@ -1842,7 +2085,9 @@ port_flow_list(portid_t port_id, uint32_t n, const

uint32_t group[n])

app/test-pmd/config.c port_flow_list(portid_t port_id, uint32_t n, const uint32_t group[n])

Quoted 7 lines
app/test-pmd/config.c +3 -1
                }
                printf("=>");
                while (action->type != RTE_FLOW_ACTION_TYPE_END) {
-                       if (rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,
+                       if ((uint32_t)action->type > INT_MAX)
+                               name = "PMD_INTERNAL";
+                       else if

(rte_flow_conv(RTE_FLOW_CONV_OP_ACTION_NAME_PTR,

Quoted 66 lines
app/test-pmd/config.c +0 -0
                                          &name, sizeof(name),
                                          (void *)(uintptr_t)action->type,
                                          NULL) <= 0)
app/test-pmd/testpmd.c +4 -1
index fe6450cc0d..e484079147 100644
@@ -3588,6 +3588,8 @@ init_port_dcb_config(portid_t pid,
 static void
 init_port(void)
 {
+       int i;
+
        /* Configuration of Ethernet ports. */
        ports = rte_zmalloc("testpmd: ports",
                            sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
@@ -3597,7 +3599,8 @@ init_port(void)
                                "rte_zmalloc(%d struct rte_port) failed\n",
                                RTE_MAX_ETHPORTS);
        }
-
+       for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+               LIST_INIT(&ports[i].flow_tunnel_list);
        /* Initialize ports NUMA structures */
        memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
        memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
app/test-pmd/testpmd.h +21 -0
index f139fe7a0a..1dd8cfd3d8 100644
@@ -12,6 +12,7 @@
 #include <rte_gro.h>
 #include <rte_gso.h>
 #include <cmdline.h>
+#include <sys/queue.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -142,6 +143,26 @@ struct port_flow {
        uint8_t data[]; /**< Storage for flow rule description */
 };
 
+struct port_flow_tunnel {
+       LIST_ENTRY(port_flow_tunnel) chain;
+       struct rte_flow_action *pmd_actions;
+       struct rte_flow_item   *pmd_items;
+       uint32_t id;
+       uint32_t num_pmd_actions;
+       uint32_t num_pmd_items;
+       struct rte_flow_tunnel tunnel;
+       struct rte_flow_action *actions;
+       struct rte_flow_item *items;
+};
+
+struct tunnel_ops {
+       uint32_t id;
+       char type[16];
+       uint32_t enabled:1;
+       uint32_t actions:1;
+       uint32_t items:1;
+};
+
 /**
  * The data structure associated with each port.
  */

app/test-pmd/testpmd.h struct rte_port { · line 197

Quoted 5 lines
app/test-pmd/testpmd.h +1 -0
@@ -172,6 +193,7 @@ struct rte_port {
        uint32_t                mc_addr_nb; /**< nb. of addr. in mc_addr_pool */
        uint8_t                 slave_flag; /**< bonding slave port */
        struct port_flow        *flow_list; /**< Associated flows. */
+       LIST_HEAD(, port_flow_tunnel) flow_tunnel_list;
        const struct rte_eth_rxtx_callback

*rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];

app/test-pmd/testpmd.h struct rte_port { · line 198

Quoted 1 line
app/test-pmd/testpmd.h +0 -0
        const struct rte_eth_rxtx_callback

*tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];

app/test-pmd/testpmd.h void port_reg_set(portid_t port_id, uint32_t

Quoted 2 lines
app/test-pmd/testpmd.h +0 -0
        /**< metadata value to insert in Tx packets. */
@@ -749,11 +771,13 @@ void port_reg_set(portid_t port_id, uint32_t

reg_off, uint32_t value);

app/test-pmd/testpmd.h int port_flow_query(portid_t port_id, uint32_t

Quoted 16 lines
app/test-pmd/testpmd.h +4 -2
 int port_flow_validate(portid_t port_id,
                       const struct rte_flow_attr *attr,
                       const struct rte_flow_item *pattern,
-                      const struct rte_flow_action *actions);
+                      const struct rte_flow_action *actions,
+                      const struct tunnel_ops *tunnel_ops);
 int port_flow_create(portid_t port_id,
                     const struct rte_flow_attr *attr,
                     const struct rte_flow_item *pattern,
-                    const struct rte_flow_action *actions);
+                    const struct rte_flow_action *actions,
+                    const struct tunnel_ops *tunnel_ops);
 void update_age_action_context(const struct rte_flow_action *actions,
                     struct port_flow *pf);
 int port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule);
@@ -763,6 +787,12 @@ int port_flow_query(portid_t port_id, uint32_t

rule,

app/test-pmd/testpmd.h int port_flow_query(portid_t port_id, uint32_t rule,

Quoted 9 lines
app/test-pmd/testpmd.h +6 -0
                    const struct rte_flow_action *action);
 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
 void port_flow_aged(portid_t port_id, uint8_t destroy);
+const char *port_flow_tunnel_type(struct rte_flow_tunnel *tunnel);
+struct port_flow_tunnel *
+port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun);
+void port_flow_tunnel_list(portid_t port_id);
+void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
+void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops

*ops);

app/test-pmd/testpmd.h int port_flow_query(portid_t port_id, uint32_t rule,

Quoted 3 lines
app/test-pmd/testpmd.h +0 -0
 int port_flow_isolate(portid_t port_id, int set);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t

rxd_id);

app/test-pmd/util.c dump_pkt_burst(uint16_t port_id, uint16_t queue,

Quoted 5 lines
app/test-pmd/util.c +0 -0
index 8488fa1a8f..781a813759 100644
@@ -48,18 +48,49 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue,

struct rte_mbuf *pkts[],

Review

Quoted 52 lines
app/test-pmd/util.c +33 -2
               is_rx ? "received" : "sent",
               (unsigned int) nb_pkts);
        for (i = 0; i < nb_pkts; i++) {
+               int ret;
+               struct rte_flow_error error;
+               struct rte_flow_restore_info info = { 0, };
+
                mb = pkts[i];
                eth_hdr = rte_pktmbuf_read(mb, 0, sizeof(_eth_hdr), &_eth_hdr);
                eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
-               ol_flags = mb->ol_flags;
                packet_type = mb->packet_type;
                is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
-
+               ret = rte_flow_get_restore_info(port_id, mb, &info, &error);
+               if (!ret) {
+                       printf("restore info:");
+                       if (info.flags & RTE_FLOW_RESTORE_INFO_TUNNEL) {
+                               struct port_flow_tunnel *port_tunnel;
+
+                               port_tunnel = port_flow_locate_tunnel
+                                             (port_id, &info.tunnel);
+                               printf(" - tunnel");
+                               if (port_tunnel)
+                                       printf(" #%u", port_tunnel->id);
+                               else
+                                       printf(" %s", "-none-");
+                               printf(" type %s",
+                                       port_flow_tunnel_type(&info.tunnel));
+                       } else {
+                               printf(" - no tunnel info");
+                       }
+                       if (info.flags & RTE_FLOW_RESTORE_INFO_ENCAPSULATED)
+                               printf(" - outer header present");
+                       else
+                               printf(" - no outer header");
+                       if (info.flags & RTE_FLOW_RESTORE_INFO_GROUP_ID)
+                               printf(" - miss group %u", info.group_id);
+                       else
+                               printf(" - no miss group");
+                       printf("\n");
+               }
                print_ether_addr("  src=", &eth_hdr->s_addr);
                print_ether_addr(" - dst=", &eth_hdr->d_addr);
                printf(" - type=0x%04x - length=%u - nb_segs=%d",
                       eth_type, (unsigned int) mb->pkt_len,
                       (int)mb->nb_segs);
+               ol_flags = mb->ol_flags;
                if (ol_flags & PKT_RX_RSS_HASH) {
                        printf(" - RSS hash=0x%x", (unsigned int) mb->hash.rss);
                        printf(" - RSS queue=0x%x", (unsigned int) queue);
(quoted diff) +0 -0

b/doc/guides/testpmd_app_ug/testpmd_funcs.rst

doc/guides/testpmd_app_ug/testpmd_funcs.rst Otherwise it will show an error message of the

Quoted 58 lines

index a972ef8951..97fcbfd329 100644

doc/guides/testpmd_app_ug/testpmd_funcs.rst +40 -0
@@ -3720,6 +3720,45 @@ following sections.
 
    flow aged {port_id} [destroy]
 
+- Tunnel offload - create a tunnel stub::
+
+   flow tunnel create {port_id} type {tunnel_type}
+
+- Tunnel offload - destroy a tunnel stub::
+
+   flow tunnel destroy {port_id} id {tunnel_id}
+
+- Tunnel offload - list port tunnel stubs::
+
+   flow tunnel list {port_id}
+
+Creating a tunnel stub for offload
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow tunnel create`` setup a tunnel stub for tunnel offload flow rules::
+
+   flow tunnel create {port_id} type {tunnel_type}
+
+If successful, it will return a tunnel stub ID usable with other commands::
+
+   port [...]: flow tunnel #[...] type [...]
+
+Tunnel stub ID is relative to a port.
+
+Destroying tunnel offload stub
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow tunnel destroy`` destroy port tunnel stub::
+
+   flow tunnel destroy {port_id} id {tunnel_id}
+
+Listing tunnel offload stubs
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+``flow tunnel list`` list port tunnel offload stubs::
+
+   flow tunnel list {port_id}
+
 Validating flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
@@ -3766,6 +3805,7 @@ to ``rte_flow_create()``::
 
    flow create {port_id}
       [group {group_id}] [priority {level}] [ingress] [egress] [transfer]
+      [tunnel_set {tunnel_id}] [tunnel_match {tunnel_id}]
       pattern {item} [/ {item} [...]] / end
       actions {action} [/ {action} [...]] / end
 
@@ -3780,6 +3820,7 @@ Otherwise it will show an error message of the

form::

doc/guides/testpmd_app_ug/testpmd_funcs.rst Otherwise it will show an error message of the form::

Quoted 5 lines
doc/guides/testpmd_app_ug/testpmd_funcs.rst +1 -0
 Parameters describe in the following order:
 
 - Attributes (*group*, *priority*, *ingress*, *egress*, *transfer* tokens).
+- Tunnel offload specification (tunnel_set, tunnel_match)
 - A matching pattern, starting with the *pattern* token and terminated by

an

doc/guides/testpmd_app_ug/testpmd_funcs.rst Most rules affect RX therefore contain the

Quoted 3 lines
doc/guides/testpmd_app_ug/testpmd_funcs.rst +0 -0
   *end* pattern item.
 - Actions, starting with the *actions* token and terminated by an *end*
@@ -3823,6 +3864,14 @@ Most rules affect RX therefore contain the

``ingress`` token::

Quoted 17 lines
doc/guides/testpmd_app_ug/testpmd_funcs.rst +8 -1
    testpmd> flow create 0 ingress pattern [...]
 
+Tunnel offload
+^^^^^^^^^^^^^^
+
+Indicate tunnel offload rule type
+
+- ``tunnel_set {tunnel_id}``: mark rule as tunnel offload decap_set type.
+- ``tunnel_match {tunnel_id}``:  mark rule as tunel offload match type.
+
 Matching pattern
 ^^^^^^^^^^^^^^^^
 
--

2.25.1

#40 lore raw

Re: [dpdk-dev] [PATCH v3 4/4] app/testpmd: add commands for tunnel offload API

Gregory,

[snip]

Quoted 24 lines
Quoted 16 lines
Quoted 5 lines

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end

I could not get enough time to completely look at this. Can you help understand the sequence a bit.

So when this flow create is issued, it looks like the application issues one of the helper APIs.
In response the PMD returns the vendor specific items/actions. So what happens to the original match and action criteria provided by the user
or applications?

Quoted 7 lines

Does the vendor provided actions and items in the tunnel descriptor take precedence over what was used by the application?

And is the criteria provided by the PMD opaque to the application? Such that only the PMD can decipher it when the application calls it for subsequent flow create(s)?

Quoted 13 lines

Flow rules that implement tunnel offload API are compiled from application and PMD actions and items. Both application and PMD elements are equally important for offload rule creation. Application is "aware" what type of tunnel offload flow rule, decap_set or match, it builds. Therefore, application elements are created according to tunnel offload rule type and the API helper function, that matches selected rule type, is activated to provide PMD elements. PMD elements are opaque. When all elements are present, application concatenates PMD items with application items and PMD actions with application actions. As the result application will have pattern & actions arrays for flow rule creation. For the decap_set rule, the API expects application to provide pattern that describes a tunnel and the JUMP action, although the JUMP is not strictly required. And for the match rule, application pattern should describe packet headers and actions refer to inner parts.

Since the application concatenates the elements provided by the PMD with that of its own, the PMD is free to validate, parse and use a subset or all of them?

[snip]

#41 lore raw

Re: [dpdk-dev] [PATCH v3 4/4] app/testpmd: add commands for tunnel offload API

Hello Ajit,

Quoted 42 lines

[snip]

Quoted 19 lines
Quoted 19 lines
Quoted 5 lines

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end

I could not get enough time to completely look at this. Can you help understand the sequence a bit.

So when this flow create is issued, it looks like the application issues one of the helper APIs.
In response the PMD returns the vendor specific items/actions. So what happens to the original match and action criteria provided by the user
or applications?

Does the vendor provided actions and items in the tunnel descriptor take precedence over what was used by the application?

Quoted 6 lines
Quoted 4 lines

And is the criteria provided by the PMD opaque to the application? Such that only the PMD can decipher it when the application calls it for subsequent flow create(s)?

Flow rules that implement tunnel offload API are compiled from application

and

Quoted 1 line

PMD actions and items. Both application and PMD elements are equally

important

Quoted 2 lines

for offload rule creation. Application is "aware" what type of tunnel offload flow rule, decap_set or match, it builds. Therefore, application elements

are

Quoted 1 line

created according to tunnel offload rule type and the API helper function,

that

Quoted 2 lines

matches selected rule type, is activated to provide PMD elements. PMD elements are opaque. When all elements are present, application

concatenates

Quoted 1 line

PMD items with application items and PMD actions with application

actions.

Quoted 2 lines

As the result application will have pattern & actions arrays for flow rule creation. For the decap_set rule, the API expects application to provide

pattern

Quoted 9 lines
Quoted 1 line

that describes a tunnel and the JUMP action, although the JUMP is not

strictly

Quoted 1 line

required. And for the match rule, application pattern should describe

packet

Quoted 1 line

headers and actions refer to inner parts.

Since the application concatenates the elements provided by the PMD with that of its own, the PMD is free to validate, parse and use a subset or all of them?

Concatenated array must provide enough information for PMD to build a rule. Application RTE elements describe flow and flow actions while PMD elements are about internal PMD hardware offload and restore after partial miss . PMD uses all application elements, but it may skip internal elements, depending on implementation.

Quoted 1 line

[snip]

#42 lore raw

v4 cover Tunnel Offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

v2:
* documentation updates
* MLX5 PMD implementation for tunnel offload
* testpmd updates for tunnel offload

v3:
* documentation updates
* MLX5 PMD updates
* testpmd updates

v4:
* updated patch: allow negative values in flow rule types

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (3):
ethdev: allow negative values in flow rule types net/mlx5: implement tunnel offload API app/testpmd: add commands for tunnel offload API

 app/test-pmd/cmdline_flow.c                 | 170 ++++-
 app/test-pmd/config.c                       | 253 +++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 +-
 app/test-pmd/util.c                         |  35 +-
 doc/guides/nics/mlx5.rst                    |   3 +
 doc/guides/prog_guide/rte_flow.rst          | 108 ++++
 doc/guides/rel_notes/release_20_11.rst      |   9 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++
 drivers/net/mlx5/linux/mlx5_os.c            |  18 +
 drivers/net/mlx5/mlx5.c                     |   8 +-
 drivers/net/mlx5/mlx5.h                     |   3 +
 drivers/net/mlx5/mlx5_defs.h                |   2 +
 drivers/net/mlx5/mlx5_flow.c                | 678 +++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h                | 173 ++++-
 drivers/net/mlx5/mlx5_flow_dv.c             | 241 ++++++-
 lib/librte_ethdev/rte_ethdev_version.map    |   6 +
 lib/librte_ethdev/rte_flow.c                | 140 +++-
 lib/librte_ethdev/rte_flow.h                | 195 ++++++
 lib/librte_ethdev/rte_flow_driver.h         |  32 +
 20 files changed, 2097 insertions(+), 65 deletions(-)
Signature · 1 line
2.28.0
#43 lore raw

PATCH v4 1/4 ethdev: allow negative values in flow rule types

From: Gregory Etelson <[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

RTE flow item or action coversion library accepts positive known element types with predefined sizes only. Private PMD items and actions do not fit into this scheme becase PMD type values are negative, each PMD has it's own types numeration and element types and their sizes are not visible at RTE level. To resolve these limitations the patch proposes this solution:
1. PMD can to expose elements of pointer size only. RTE flow conversion functions will use pointer size for each configuration object in private PMD element it processes;
2. RTE flow verification will not reject elements with negative type.

---
v4:
* update the 'Negative types' section in the rtre_flow.rst

* update the patch comment

---
 doc/guides/prog_guide/rte_flow.rst |  3 +++
 lib/librte_ethdev/rte_flow.c       | 28 ++++++++++++++++++++++------
 2 files changed, 25 insertions(+), 6 deletions(-)
doc/guides/prog_guide/rte_flow.rst +3 -0
index 119b128739..df71bd2eeb 100644
@@ -2678,6 +2678,9 @@ identifiers they are not aware of.
 
 A method to generate them remains to be defined.
 
+Application may use PMD dynamic items or actions in flow rules. In that case
+size of configuration object in dynamic element must be a pointer size.
+
 Planned types
 ~~~~~~~~~~~~~
 
lib/librte_ethdev/rte_flow.c +22 -6
index f8fdd68fe9..c8c6d62a8b 100644
@@ -564,7 +564,11 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (int)item->type >= 0 ?
+		      rte_flow_desc_item[item->type].size : sizeof(void *);
 		rte_memcpy(buf, data, (size > off ? off : size));
 		break;
 	}
@@ -667,7 +671,11 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_action[action->type].size;
+		/**
+		 * allow PMD private flow action
+		 */
+		off = (int)action->type >= 0 ?
+		      rte_flow_desc_action[action->type].size : sizeof(void *);
 		rte_memcpy(buf, action->conf, (size > off ? off : size));
 		break;
 	}
@@ -709,8 +717,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-		    !rte_flow_desc_item[src->type].name)
+		/**
+		 * allow PMD private flow item
+		 */
+		if (((int)src->type >= 0) &&
+			((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+		    !rte_flow_desc_item[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
 				 "cannot convert unknown item type");
@@ -798,8 +810,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-		    !rte_flow_desc_action[src->type].name)
+		/**
+		 * allow PMD private flow action
+		 */
+		if (((int)src->type >= 0) &&
+		    ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+		    !rte_flow_desc_action[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
 				 src, "cannot convert unknown action type");
Signature · 1 line
2.28.0
#44 lore raw

Re: [dpdk-dev] [PATCH v4 1/4] ethdev: allow negative values in flow rule types

04/10/2020 15:50, Gregory Etelson:

Quoted 7 lines

From: Gregory Etelson <[email protected]>

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

Quoted 5 lines

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

RTE flow item or action coversion library accepts positive known

typo: coversion

Quoted 6 lines

element types with predefined sizes only. Private PMD items and actions do not fit into this scheme becase PMD type values are negative, each PMD has it's own types numeration and element types and their sizes are not visible at RTE level. To resolve these limitations the patch proposes this solution:
1. PMD can to expose elements of pointer size only. RTE flow

typo: "can to"

Quoted 5 lines

conversion functions will use pointer size for each configuration object in private PMD element it processes;
2. RTE flow verification will not reject elements with negative type.

Don't you want to use nvidia email?

Quoted 2 lines

I was not aware of negative PMD types in rte_flow.
Allowing to use these opaque PMD types for magic complex rule looks OK.

#45 lore raw

PATCH v4 2/4 ethdev: tunnel offload model

In reply to Gregory Etelson

From: Eli Britstein <[email protected]>

Rte_flow API provides the building blocks for vendor agnostic flow classification offloads. The rte_flow match and action primitives are fine grained, thus enabling DPDK applications the flexibility to offload network stacks and complex pipelines.

Applications wishing to offload complex data structures (e.g. tunnel virtual ports) are required to use the rte_flow primitives, such as group, meta, mark, tag and others to model their high level objects.

The hardware model design for high level software objects is not trivial. Furthermore, an optimal design is often vendor specific.

The goal of this API is to provide applications with the hardware offload model for common high level software objects which is optimal in regards to the underlying hardware.

Tunnel ports are the first of such objects.

Tunnel ports
------------
Ingress processing of tunneled traffic requires the classification of the tunnel type followed by a decap action.

In software, once a packet is decapsulated the in_port field is changed to a virtual port representing the tunnel type. The outer header fields are stored as packet metadata members and may be matched by proceeding flows.

Openvswitch, for example, uses two flows:
1. classification flow - setting the virtual port representing the tunnel type For example: match on udp port 4789 actions=tnl_pop(vxlan_vport)
2. steering flow according to outer and inner header matches match on in_port=vxlan_vport and outer/inner header matches actions=forward to p ort X The benefits of multi-flow tables are described in [1].

Offloading tunnel ports
-----------------------
Tunnel ports introduce a new stateless field that can be matched on. Currently the rte_flow library provides an API to encap, decap and match on tunnel headers. However, there is no rte_flow primitive to set and match tunnel virtual ports.

There are several possible hardware models for offloading virtual tunnel port flows including, but not limited to, the following:
1. Setting the virtual port on a hw register using the rte_flow_action_mark/ rte_flow_action_tag/rte_flow_set_meta objects.
2. Mapping a virtual port to an rte_flow group
3. Avoiding the need to match on transient objects by merging multi-table flows to a single rte_flow rule.

Every approach has its pros and cons. The preferred approach should take into account the entire system architecture and is very often vendor specific.

The proposed rte_flow_tunnel_decap_set helper function (drafted below) is designed to provide a common, vendor agnostic, API for setting the virtual port value. The helper API enables PMD implementations to return vendor specific combination of rte_flow actions realizing the vendor's hardware model for setting a tunnel port. Applications may append the list of actions returned from the helper function when creating an rte_flow rule in hardware.

Similarly, the rte_flow_tunnel_match helper (drafted below) allows for multiple hardware implementations to return a list of fte_flow items.

Miss handling
-------------
Packets going through multiple rte_flow groups are exposed to hw misses due to partial packet processing. In such cases, the software should continue the packet's processing from the point where the hardware missed.

We propose a generic rte_flow_restore structure providing the state that was stored in hardware when the packet missed.

Currently, the structure will provide the tunnel state of the packet that missed, namely:
1. The group id that missed
2. The tunnel port that missed
3. Tunnel information that was stored in memory (due to decap action). In the future, we may add additional fields as more state may be stored in the device memory (e.g. ct_state).

Applications may query the state via a new rte_flow_tunnel_get_restore_info(mbuf) API, thus allowing a vendor specific implementation.

VXLAN Code example:
Assume application needs to do inner NAT on VXLAN packet. The first rule in group 0:

flow create <port id> ingress group 0
pattern eth / ipv4 / udp dst is 4789 / vxlan / end actions {pmd actions} / jump group 3 / end

First VXLAN packet that arrives matches the rule in group 0 and jumps to group 3 In group 3 the packet will miss since there is no flow to match and will be uploaded to application. Application will call rte_flow_get_restore_info() to get the packet outer header. Application will insert a new rule in group 3 to match outer and inner headers:

flow create <port id> ingress group 3
pattern {pmd items} / eth / ipv4 dst is 172.10.10.1 /
udp dst 4789 / vxlan vni is 10 /
ipv4 dst is 184.1.2.3 / end
actions set_ipv4_dst 186.1.1.1 / queue index 3 / end

Resulting of rules will be that VXLAN packet with vni=10, outer IPv4 dst=172.10.10.1 and inner IPv4 dst=184.1.2.3 will be received decaped on queue 3 with IPv4 dst=186.1.1.1

Note: Packet in group 3 is considered decaped. All actions in that group will be done on header that was inner before decap. Application may specify outer header to be matched on. It's PMD responsibility to translate these items to outer metadata.

API usage:
/**
* 1. Initiate RTE flow tunnel object
*/
const struct rte_flow_tunnel tunnel = {
.type = RTE_FLOW_ITEM_TYPE_VXLAN,
.tun_id = 10,
}

/**
* 2. Obtain PMD tunnel actions
*
* pmd_actions is an intermediate variable application uses to
* compile actions array
*/
struct rte_flow_action **pmd_actions; rte_flow_tunnel_decap_and_set(&tunnel, &pmd_actions,

                              &num_pmd_actions, &error);

/**
* 3. offload the first rule
* matching on VXLAN traffic and jumps to group 3
* (implicitly decaps packet)
*/
app_actions = jump group 3
rule_items = app_items; /** eth / ipv4 / udp / vxlan */ rule_actions = { pmd_actions, app_actions }; attr.group = 0;
flow_1 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 4. after flow creation application does not need to keep tunnel
* action resources.
*/
rte_flow_tunnel_action_release(port_id, pmd_actions,

                               num_pmd_actions);

/**
* 5. After partially offloaded packet miss because there was no
* matching rule handle miss on group 3
*/
struct rte_flow_restore_info info; rte_flow_get_restore_info(port_id, mbuf, &info, &error);

/**
* 6. Offload NAT rule:
*/
app_items = { eth / ipv4 dst is 172.10.10.1 / udp dst 4789 /

            vxlan vni is 10 / ipv4 dst is 184.1.2.3 }

app_actions = { set_ipv4_dst 186.1.1.1 / queue index 3 }

rte_flow_tunnel_match(&info.tunnel, &pmd_items,

                      &num_pmd_items,  &error);

rule_items = {pmd_items, app_items};
rule_actions = app_actions;
attr.group = info.group_id;
flow_2 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 7. Release PMD items after rule creation
*/
rte_flow_tunnel_item_release(port_id, pmd_items, num_pmd_items);

References
1. https://mails.dpdk.org/archives/dev/2020-June/index.html

---
 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++++++++
 doc/guides/rel_notes/release_20_11.rst   |   9 ++
 lib/librte_ethdev/rte_ethdev_version.map |   6 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 195 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 6 files changed, 459 insertions(+)
doc/guides/prog_guide/rte_flow.rst +105 -0
index df71bd2eeb..28f2aca984 100644
@@ -3034,6 +3034,111 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Provide software application with unified rules model for tunneled traffic
+regardless underlying hardware.
+
+ - The model introduces a concept of a virtual tunnel port (VTP).
+ - The model uses VTP to offload ingress tunneled network traffic 
+   with RTE flow rules.
+ - The model is implemented as set of helper functions. Each PMD
+   implements VTP offload according to underlying hardware offload
+   capabilities.  Applications must query PMD for VTP flow
+   items / actions before using in creation of a VTP flow rule.
+
+The model components:
+
+- Virtual Tunnel Port (VTP) is a stateless software object that
+  describes tunneled network traffic.  VTP object usually contains
+  descriptions of outer headers, tunnel headers and inner headers.
+- Tunnel Steering flow Rule (TSR) detects tunneled packets and
+  delegates them to tunnel processing infrastructure, implemented
+  in PMD for optimal hardware utilization, for further processing.
+- Tunnel Matching flow Rule (TMR) verifies packet configuration and
+  runs offload actions in case of a match.
+
+Application actions:
+
+1 Initialize VTP object according to tunnel network parameters.
+
+2 Create TSR flow rule.
+
+2.1 Query PMD for VTP actions. Application can query for VTP actions more than once.
+
+  .. code-block:: c
+
+    int
+    rte_flow_tunnel_decap_set(uint16_t port_id,
+                              struct rte_flow_tunnel *tunnel,
+                              struct rte_flow_action **pmd_actions,
+                              uint32_t *num_of_pmd_actions,
+                              struct rte_flow_error *error);
+
+2.2 Integrate PMD actions into TSR actions list.
+
+2.3 Create TSR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {tunnel items} / end actions {PMD actions} / {App actions} / end
+
+3 Create TMR flow rule.
+
+3.1 Query PMD for VTP items. Application can query for VTP items more than once.
+
+    .. code-block:: c
+
+      int
+      rte_flow_tunnel_match(uint16_t port_id,
+                            struct rte_flow_tunnel *tunnel,
+                            struct rte_flow_item **pmd_items,
+                            uint32_t *num_of_pmd_items,
+                            struct rte_flow_error *error);
+
+3.2 Integrate PMD items into TMR items list.
+
+3.3 Create TMR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {PMD items} / {APP items} / end actions {offload actions} / end
+
+The model provides helper function call to restore packets that miss
+tunnel TMR rules to its original state:
+
+.. code-block:: c
+
+  int
+  rte_flow_get_restore_info(uint16_t port_id,
+                            struct rte_mbuf *mbuf,
+                            struct rte_flow_restore_info *info,
+                            struct rte_flow_error *error);
+
+rte_tunnel object filled by the call inside
+``rte_flow_restore_info *info parameter`` can be used by the application
+to create new TMR rule for that tunnel.
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+Application can release the actionsfter TSR rule was created.
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release the items after rule was created. However, if the application
+needs to create additional TMR rule for the same tunnel it will need
+to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
 
doc/guides/rel_notes/release_20_11.rst +9 -0
index 1a9945f314..9ea8ee3170 100644
@@ -62,6 +62,15 @@ New Features
   * Added support for 200G PAM4 link speed.
   * Added support for RSS hash level selection.
   * Updated HWRM structures to 1.10.1.70 version.
+* **Flow rules allowed to use private PMD items / actions.**
+
+  * Flow rule verification was updated to accept private PMD
+    items and actions.
+
+* **Added generic API to offload tunneled traffic and restore missed packet.**
+
+  * Added a new hardware independent helper API to RTE flow library that
+    offloads tunneled traffic and restores missed packets.
 
 * **Updated Cisco enic driver.**
 
lib/librte_ethdev/rte_ethdev_version.map +6 -0
index c95ef5157a..9832c138a2 100644
@@ -226,6 +226,12 @@ EXPERIMENTAL {
 	rte_tm_wred_profile_add;
 	rte_tm_wred_profile_delete;
 
+	rte_flow_tunnel_decap_set;
+	rte_flow_tunnel_match;
+	rte_flow_get_restore_info;
+	rte_flow_tunnel_action_decap_release;
+	rte_flow_tunnel_item_release;
+
 	# added in 20.11
 	rte_eth_link_speed_to_str;
 	rte_eth_link_to_str;
lib/librte_ethdev/rte_flow.c +112 -0

115 lines not on this page · raw message

lib/librte_ethdev/rte_flow.h +195 -0

201 lines not on this page · raw message

lib/librte_ethdev/rte_flow_driver.h +32 -0
index 3ee871d3eb..9d87407203 100644
@@ -108,6 +108,38 @@ struct rte_flow_ops {
 		 void **context,
 		 uint32_t nb_contexts,
 		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_decap_set() */
+	int (*tunnel_decap_set)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_action **pmd_actions,
+		 uint32_t *num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_match() */
+	int (*tunnel_match)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_item **pmd_items,
+		 uint32_t *num_of_items,
+		 struct rte_flow_error *err);
+	/** See rte_flow_get_rte_flow_restore_info() */
+	int (*get_restore_info)
+		(struct rte_eth_dev *dev,
+		 struct rte_mbuf *m,
+		 struct rte_flow_restore_info *info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_action_tunnel_decap_release() */
+	int (*action_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_action *pmd_actions,
+		 uint32_t num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_item_release() */
+	int (*item_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_item *pmd_items,
+		 uint32_t num_of_items,
+		 struct rte_flow_error *err);
 };
 
 /**
Signature · 1 line
2.28.0
#46 lore raw
Quoted 39 lines · Gregory Etelson

From: Eli Britstein <[email protected]>

Rte_flow API provides the building blocks for vendor agnostic flow classification offloads. The rte_flow match and action primitives are fine grained, thus enabling DPDK applications the flexibility to offload network stacks and complex pipelines.

Applications wishing to offload complex data structures (e.g. tunnel virtual ports) are required to use the rte_flow primitives, such as group, meta, mark, tag and others to model their high level objects.

The hardware model design for high level software objects is not trivial. Furthermore, an optimal design is often vendor specific.

The goal of this API is to provide applications with the hardware offload model for common high level software objects which is optimal in regards to the underlying hardware.

Tunnel ports are the first of such objects.

Tunnel ports
------------
Ingress processing of tunneled traffic requires the classification of the tunnel type followed by a decap action.

In software, once a packet is decapsulated the in_port field is changed to a virtual port representing the tunnel type. The outer header fields are stored as packet metadata members and may be matched by proceeding flows.

Openvswitch, for example, uses two flows:
1. classification flow - setting the virtual port representing the tunnel type For example: match on udp port 4789 actions=tnl_pop(vxlan_vport)
2. steering flow according to outer and inner header matches match on in_port=vxlan_vport and outer/inner header matches actions=forward to p ort X The benefits of multi-flow tables are described in [1].

Quoted 6 lines

Offloading tunnel ports
-----------------------
Tunnel ports introduce a new stateless field that can be matched on. Currently the rte_flow library provides an API to encap, decap and match on tunnel headers. However, there is no rte_flow primitive to set and match tunnel virtual ports.

Tunnel vport is an internal construct used by one specific
application: OVS. So, shouldn't the rte APIs also be application agnostic apart from being vendor agnostic ? For OVS, the match fields in the existing datapath flow rules contain enough information to identify the tunnel type.

Quoted 13 lines

There are several possible hardware models for offloading virtual tunnel port flows including, but not limited to, the following:
1. Setting the virtual port on a hw register using the rte_flow_action_mark/ rte_flow_action_tag/rte_flow_set_meta objects.
2. Mapping a virtual port to an rte_flow group
3. Avoiding the need to match on transient objects by merging multi-table flows to a single rte_flow rule.

Every approach has its pros and cons. The preferred approach should take into account the entire system architecture and is very often vendor specific.

Quoted 7 lines

The proposed rte_flow_tunnel_decap_set helper function (drafted below) is designed to provide a common, vendor agnostic, API for setting the virtual port value. The helper API enables PMD implementations to return vendor specific combination of rte_flow actions realizing the vendor's hardware model for setting a tunnel port. Applications may append the list of actions returned from the helper function when creating an rte_flow rule in hardware.

Wouldn't it be better if the APIs do not refer to vports and avoid percolating it down to the PMD ? My point here is to avoid bringing in the knowledge of an application specific virtual object (vport) to the PMD.

Here's some other issues that I see with the helper APIs and vendor-specific variable actions.
1) The application needs some kind of validation (or understanding) of the actions returned by the PMD. The application can't just blindly use the actions specified by the PMD. That is, the decision to pick the set of actions can't be left entirely to the PMD.
2) The application needs to learn a PMD-specific way of action processing for each vendor. For example, how should the application handle flow-miss, given a different set of actions between two vendors (if one vendor has already popped the tunnel header while the other one hasn't).
3) The end-users/customers won't have a common interface (as in, consistent actions) to perform tunnel decap action. This becomes a manageability/maintenance issue for the application while working with different vendors.

IMO, the API shouldn't expect the PMD to understand the notion of vport. The goal here is to offload a flow rule to decap the tunnel header and forward the packet to a HW endpoint. The problem is that we don't have a way to express the "tnl_pop" datapath action to the HW (decap flow #1, in the context of br-phy in OVS-DPDK) and also we may not want the HW to really pop the tunnel header at that stage. If this cannot be expressed with existing rte action types, maybe we should introduce a new action that clearly defines what is expected to the PMD.

Quoted 11 lines

Similarly, the rte_flow_tunnel_match helper (drafted below) allows for multiple hardware implementations to return a list of fte_flow items.

Miss handling
-------------
Packets going through multiple rte_flow groups are exposed to hw misses due to partial packet processing. In such cases, the software should continue the packet's processing from the point where the hardware missed.

Whether the packet goes through multiple groups or not for tunnel decap processing, should be left to the PMD/HW. These assumptions shouldn't be built into the APIs. The encapsulated packet (i,e with outer headers) should be provided to the application, rather than making SW understand that there was a miss in stage-1, or stage-n in HW. That is, HW either processes it entirely, or punts the whole packet to SW if there's a miss. And the packet should take the normal processing path in SW (no action offload).

Thanks,
-Harsha

Quoted 651 lines

We propose a generic rte_flow_restore structure providing the state that was stored in hardware when the packet missed.

Currently, the structure will provide the tunnel state of the packet that missed, namely:
1. The group id that missed
2. The tunnel port that missed
3. Tunnel information that was stored in memory (due to decap action). In the future, we may add additional fields as more state may be stored in the device memory (e.g. ct_state).

Applications may query the state via a new rte_flow_tunnel_get_restore_info(mbuf) API, thus allowing a vendor specific implementation.

VXLAN Code example:
Assume application needs to do inner NAT on VXLAN packet. The first rule in group 0:

flow create <port id> ingress group 0
pattern eth / ipv4 / udp dst is 4789 / vxlan / end actions {pmd actions} / jump group 3 / end

First VXLAN packet that arrives matches the rule in group 0 and jumps to group 3 In group 3 the packet will miss since there is no flow to match and will be uploaded to application. Application will call rte_flow_get_restore_info() to get the packet outer header. Application will insert a new rule in group 3 to match outer and inner headers:

flow create <port id> ingress group 3
pattern {pmd items} / eth / ipv4 dst is 172.10.10.1 /
udp dst 4789 / vxlan vni is 10 /
ipv4 dst is 184.1.2.3 / end
actions set_ipv4_dst 186.1.1.1 / queue index 3 / end

Resulting of rules will be that VXLAN packet with vni=10, outer IPv4 dst=172.10.10.1 and inner IPv4 dst=184.1.2.3 will be received decaped on queue 3 with IPv4 dst=186.1.1.1

Note: Packet in group 3 is considered decaped. All actions in that group will be done on header that was inner before decap. Application may specify outer header to be matched on. It's PMD responsibility to translate these items to outer metadata.

API usage:
/**
* 1. Initiate RTE flow tunnel object
*/
const struct rte_flow_tunnel tunnel = {
.type = RTE_FLOW_ITEM_TYPE_VXLAN,
.tun_id = 10,
}

/**
* 2. Obtain PMD tunnel actions
*
* pmd_actions is an intermediate variable application uses to
* compile actions array
*/
struct rte_flow_action **pmd_actions; rte_flow_tunnel_decap_and_set(&tunnel, &pmd_actions,

                              &num_pmd_actions, &error);

/**
* 3. offload the first rule
* matching on VXLAN traffic and jumps to group 3
* (implicitly decaps packet)
*/
app_actions = jump group 3
rule_items = app_items; /** eth / ipv4 / udp / vxlan */ rule_actions = { pmd_actions, app_actions }; attr.group = 0;
flow_1 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 4. after flow creation application does not need to keep tunnel
* action resources.
*/
rte_flow_tunnel_action_release(port_id, pmd_actions,

                               num_pmd_actions);

/**
* 5. After partially offloaded packet miss because there was no
* matching rule handle miss on group 3
*/
struct rte_flow_restore_info info; rte_flow_get_restore_info(port_id, mbuf, &info, &error);

/**
* 6. Offload NAT rule:
*/
app_items = { eth / ipv4 dst is 172.10.10.1 / udp dst 4789 /

            vxlan vni is 10 / ipv4 dst is 184.1.2.3 }

app_actions = { set_ipv4_dst 186.1.1.1 / queue index 3 }

rte_flow_tunnel_match(&info.tunnel, &pmd_items,

                      &num_pmd_items,  &error);

rule_items = {pmd_items, app_items};
rule_actions = app_actions;
attr.group = info.group_id;
flow_2 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 7. Release PMD items after rule creation
*/
rte_flow_tunnel_item_release(port_id, pmd_items, num_pmd_items);

References
1. https://mails.dpdk.org/archives/dev/2020-June/index.html

---
 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++++++++
 doc/guides/rel_notes/release_20_11.rst   |   9 ++
 lib/librte_ethdev/rte_ethdev_version.map |   6 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 195 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 6 files changed, 459 insertions(+)
doc/guides/prog_guide/rte_flow.rst +105 -0
index df71bd2eeb..28f2aca984 100644
@@ -3034,6 +3034,111 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Provide software application with unified rules model for tunneled traffic
+regardless underlying hardware.
+
+ - The model introduces a concept of a virtual tunnel port (VTP).
+ - The model uses VTP to offload ingress tunneled network traffic
+   with RTE flow rules.
+ - The model is implemented as set of helper functions. Each PMD
+   implements VTP offload according to underlying hardware offload
+   capabilities.  Applications must query PMD for VTP flow
+   items / actions before using in creation of a VTP flow rule.
+
+The model components:
+
+- Virtual Tunnel Port (VTP) is a stateless software object that
+  describes tunneled network traffic.  VTP object usually contains
+  descriptions of outer headers, tunnel headers and inner headers.
+- Tunnel Steering flow Rule (TSR) detects tunneled packets and
+  delegates them to tunnel processing infrastructure, implemented
+  in PMD for optimal hardware utilization, for further processing.
+- Tunnel Matching flow Rule (TMR) verifies packet configuration and
+  runs offload actions in case of a match.
+
+Application actions:
+
+1 Initialize VTP object according to tunnel network parameters.
+
+2 Create TSR flow rule.
+
+2.1 Query PMD for VTP actions. Application can query for VTP actions more than once.
+
+  .. code-block:: c
+
+    int
+    rte_flow_tunnel_decap_set(uint16_t port_id,
+                              struct rte_flow_tunnel *tunnel,
+                              struct rte_flow_action **pmd_actions,
+                              uint32_t *num_of_pmd_actions,
+                              struct rte_flow_error *error);
+
+2.2 Integrate PMD actions into TSR actions list.
+
+2.3 Create TSR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {tunnel items} / end actions {PMD actions} / {App actions} / end
+
+3 Create TMR flow rule.
+
+3.1 Query PMD for VTP items. Application can query for VTP items more than once.
+
+    .. code-block:: c
+
+      int
+      rte_flow_tunnel_match(uint16_t port_id,
+                            struct rte_flow_tunnel *tunnel,
+                            struct rte_flow_item **pmd_items,
+                            uint32_t *num_of_pmd_items,
+                            struct rte_flow_error *error);
+
+3.2 Integrate PMD items into TMR items list.
+
+3.3 Create TMR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {PMD items} / {APP items} / end actions {offload actions} / end
+
+The model provides helper function call to restore packets that miss
+tunnel TMR rules to its original state:
+
+.. code-block:: c
+
+  int
+  rte_flow_get_restore_info(uint16_t port_id,
+                            struct rte_mbuf *mbuf,
+                            struct rte_flow_restore_info *info,
+                            struct rte_flow_error *error);
+
+rte_tunnel object filled by the call inside
+``rte_flow_restore_info *info parameter`` can be used by the application
+to create new TMR rule for that tunnel.
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+Application can release the actionsfter TSR rule was created.
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release the items after rule was created. However, if the application
+needs to create additional TMR rule for the same tunnel it will need
+to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
 
doc/guides/rel_notes/release_20_11.rst +9 -0
index 1a9945f314..9ea8ee3170 100644
@@ -62,6 +62,15 @@ New Features
   * Added support for 200G PAM4 link speed.
   * Added support for RSS hash level selection.
   * Updated HWRM structures to 1.10.1.70 version.
+* **Flow rules allowed to use private PMD items / actions.**
+
+  * Flow rule verification was updated to accept private PMD
+    items and actions.
+
+* **Added generic API to offload tunneled traffic and restore missed packet.**
+
+  * Added a new hardware independent helper API to RTE flow library that
+    offloads tunneled traffic and restores missed packets.
 
 * **Updated Cisco enic driver.**
 
lib/librte_ethdev/rte_ethdev_version.map +6 -0
index c95ef5157a..9832c138a2 100644
@@ -226,6 +226,12 @@ EXPERIMENTAL {
        rte_tm_wred_profile_add;
        rte_tm_wred_profile_delete;
 
+       rte_flow_tunnel_decap_set;
+       rte_flow_tunnel_match;
+       rte_flow_get_restore_info;
+       rte_flow_tunnel_action_decap_release;
+       rte_flow_tunnel_item_release;
+
        # added in 20.11
        rte_eth_link_speed_to_str;
        rte_eth_link_to_str;
lib/librte_ethdev/rte_flow.c +112 -0
index c8c6d62a8b..181c02792d 100644
@@ -1267,3 +1267,115 @@ rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                  NULL, rte_strerror(ENOTSUP));
 }
+
+int
+rte_flow_tunnel_decap_set(uint16_t port_id,
+                         struct rte_flow_tunnel *tunnel,
+                         struct rte_flow_action **actions,
+                         uint32_t *num_of_actions,
+                         struct rte_flow_error *error)
+{
+       struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+       const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+       if (unlikely(!ops))
+               return -rte_errno;
+       if (likely(!!ops->tunnel_decap_set)) {
+               return flow_err(port_id,
+                               ops->tunnel_decap_set(dev, tunnel, actions,
+                                                     num_of_actions, error),
+                               error);
+       }
+       return rte_flow_error_set(error, ENOTSUP,
+                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                 NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_tunnel_match(uint16_t port_id,
+                     struct rte_flow_tunnel *tunnel,
+                     struct rte_flow_item **items,
+                     uint32_t *num_of_items,
+                     struct rte_flow_error *error)
+{
+       struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+       const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+       if (unlikely(!ops))
+               return -rte_errno;
+       if (likely(!!ops->tunnel_match)) {
+               return flow_err(port_id,
+                               ops->tunnel_match(dev, tunnel, items,
+                                                 num_of_items, error),
+                               error);
+       }
+       return rte_flow_error_set(error, ENOTSUP,
+                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                 NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_get_restore_info(uint16_t port_id,
+                         struct rte_mbuf *m,
+                         struct rte_flow_restore_info *restore_info,
+                         struct rte_flow_error *error)
+{
+       struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+       const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+       if (unlikely(!ops))
+               return -rte_errno;
+       if (likely(!!ops->get_restore_info)) {
+               return flow_err(port_id,
+                               ops->get_restore_info(dev, m, restore_info,
+                                                     error),
+                               error);
+       }
+       return rte_flow_error_set(error, ENOTSUP,
+                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                 NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_tunnel_action_decap_release(uint16_t port_id,
+                                    struct rte_flow_action *actions,
+                                    uint32_t num_of_actions,
+                                    struct rte_flow_error *error)
+{
+       struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+       const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+       if (unlikely(!ops))
+               return -rte_errno;
+       if (likely(!!ops->action_release)) {
+               return flow_err(port_id,
+                               ops->action_release(dev, actions,
+                                                   num_of_actions, error),
+                               error);
+       }
+       return rte_flow_error_set(error, ENOTSUP,
+                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                 NULL, rte_strerror(ENOTSUP));
+}
+
+int
+rte_flow_tunnel_item_release(uint16_t port_id,
+                            struct rte_flow_item *items,
+                            uint32_t num_of_items,
+                            struct rte_flow_error *error)
+{
+       struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+       const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+       if (unlikely(!ops))
+               return -rte_errno;
+       if (likely(!!ops->item_release)) {
+               return flow_err(port_id,
+                               ops->item_release(dev, items,
+                                                 num_of_items, error),
+                               error);
+       }
+       return rte_flow_error_set(error, ENOTSUP,
+                                 RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                 NULL, rte_strerror(ENOTSUP));
+}
lib/librte_ethdev/rte_flow.h +195 -0
index da8bfa5489..2f12d3ea1a 100644
@@ -3357,6 +3357,201 @@ int
 rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
                        uint32_t nb_contexts, struct rte_flow_error *error);
 
+/* Tunnel has a type and the key information. */
+struct rte_flow_tunnel {
+       /**
+        * Tunnel type, for example RTE_FLOW_ITEM_TYPE_VXLAN,
+        * RTE_FLOW_ITEM_TYPE_NVGRE etc.
+        */
+       enum rte_flow_item_type type;
+       uint64_t tun_id; /**< Tunnel identification. */
+
+       RTE_STD_C11
+       union {
+               struct {
+                       rte_be32_t src_addr; /**< IPv4 source address. */
+                       rte_be32_t dst_addr; /**< IPv4 destination address. */
+               } ipv4;
+               struct {
+                       uint8_t src_addr[16]; /**< IPv6 source address. */
+                       uint8_t dst_addr[16]; /**< IPv6 destination address. */
+               } ipv6;
+       };
+       rte_be16_t tp_src; /**< Tunnel port source. */
+       rte_be16_t tp_dst; /**< Tunnel port destination. */
+       uint16_t   tun_flags; /**< Tunnel flags. */
+
+       bool       is_ipv6; /**< True for valid IPv6 fields. Otherwise IPv4. */
+
+       /**
+        * the following members are required to restore packet
+        * after miss
+        */
+       uint8_t    tos; /**< TOS for IPv4, TC for IPv6. */
+       uint8_t    ttl; /**< TTL for IPv4, HL for IPv6. */
+       uint32_t label; /**< Flow Label for IPv6. */
+};
+
+/**
+ * Indicate that the packet has a tunnel.
+ */
+#define RTE_FLOW_RESTORE_INFO_TUNNEL  (1ULL << 0)
+
+/**
+ * Indicate that the packet has a non decapsulated tunnel header.
+ */
+#define RTE_FLOW_RESTORE_INFO_ENCAPSULATED  (1ULL << 1)
+
+/**
+ * Indicate that the packet has a group_id.
+ */
+#define RTE_FLOW_RESTORE_INFO_GROUP_ID  (1ULL << 2)
+
+/**
+ * Restore information structure to communicate the current packet processing
+ * state when some of the processing pipeline is done in hardware and should
+ * continue in software.
+ */
+struct rte_flow_restore_info {
+       /**
+        * Bitwise flags (RTE_FLOW_RESTORE_INFO_*) to indicate validation of
+        * other fields in struct rte_flow_restore_info.
+        */
+       uint64_t flags;
+       uint32_t group_id; /**< Group ID where packed missed */
+       struct rte_flow_tunnel tunnel; /**< Tunnel information. */
+};
+
+/**
+ * Allocate an array of actions to be used in rte_flow_create, to implement
+ * tunnel-decap-set for the given tunnel.
+ * Sample usage:
+ *   actions vxlan_decap / tunnel-decap-set(tunnel properties) /
+ *            jump group 0 / end
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] tunnel
+ *   Tunnel properties.
+ * @param[out] actions
+ *   Array of actions to be allocated by the PMD. This array should be
+ *   concatenated with the actions array provided to rte_flow_create.
+ * @param[out] num_of_actions
+ *   Number of actions allocated.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_decap_set(uint16_t port_id,
+                         struct rte_flow_tunnel *tunnel,
+                         struct rte_flow_action **actions,
+                         uint32_t *num_of_actions,
+                         struct rte_flow_error *error);
+
+/**
+ * Allocate an array of items to be used in rte_flow_create, to implement
+ * tunnel-match for the given tunnel.
+ * Sample usage:
+ *   pattern tunnel-match(tunnel properties) / outer-header-matches /
+ *           inner-header-matches / end
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] tunnel
+ *   Tunnel properties.
+ * @param[out] items
+ *   Array of items to be allocated by the PMD. This array should be
+ *   concatenated with the items array provided to rte_flow_create.
+ * @param[out] num_of_items
+ *   Number of items allocated.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_match(uint16_t port_id,
+                     struct rte_flow_tunnel *tunnel,
+                     struct rte_flow_item **items,
+                     uint32_t *num_of_items,
+                     struct rte_flow_error *error);
+
+/**
+ * Populate the current packet processing state, if exists, for the given mbuf.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] m
+ *   Mbuf struct.
+ * @param[out] info
+ *   Restore information. Upon success contains the HW state.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_get_restore_info(uint16_t port_id,
+                         struct rte_mbuf *m,
+                         struct rte_flow_restore_info *info,
+                         struct rte_flow_error *error);
+
+/**
+ * Release the action array as allocated by rte_flow_tunnel_decap_set.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] actions
+ *   Array of actions to be released.
+ * @param[in] num_of_actions
+ *   Number of elements in actions array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_action_decap_release(uint16_t port_id,
+                                    struct rte_flow_action *actions,
+                                    uint32_t num_of_actions,
+                                    struct rte_flow_error *error);
+
+/**
+ * Release the item array as allocated by rte_flow_tunnel_match.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param[in] items
+ *   Array of items to be released.
+ * @param[in] num_of_items
+ *   Number of elements in item array.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL. PMDs initialize this
+ *   structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_tunnel_item_release(uint16_t port_id,
+                            struct rte_flow_item *items,
+                            uint32_t num_of_items,
+                            struct rte_flow_error *error);
 #ifdef __cplusplus
 }
 #endif
lib/librte_ethdev/rte_flow_driver.h +32 -1
index 3ee871d3eb..9d87407203 100644
@@ -108,6 +108,38 @@ struct rte_flow_ops {
                 void **context,
                 uint32_t nb_contexts,
                 struct rte_flow_error *err);
+       /** See rte_flow_tunnel_decap_set() */
+       int (*tunnel_decap_set)
+               (struct rte_eth_dev *dev,
+                struct rte_flow_tunnel *tunnel,
+                struct rte_flow_action **pmd_actions,
+                uint32_t *num_of_actions,
+                struct rte_flow_error *err);
+       /** See rte_flow_tunnel_match() */
+       int (*tunnel_match)
+               (struct rte_eth_dev *dev,
+                struct rte_flow_tunnel *tunnel,
+                struct rte_flow_item **pmd_items,
+                uint32_t *num_of_items,
+                struct rte_flow_error *err);
+       /** See rte_flow_get_rte_flow_restore_info() */
+       int (*get_restore_info)
+               (struct rte_eth_dev *dev,
+                struct rte_mbuf *m,
+                struct rte_flow_restore_info *info,
+                struct rte_flow_error *err);
+       /** See rte_flow_action_tunnel_decap_release() */
+       int (*action_release)
+               (struct rte_eth_dev *dev,
+                struct rte_flow_action *pmd_actions,
+                uint32_t num_of_actions,
+                struct rte_flow_error *err);
+       /** See rte_flow_item_release() */
+       int (*item_release)
+               (struct rte_eth_dev *dev,
+                struct rte_flow_item *pmd_items,
+                uint32_t num_of_items,
+                struct rte_flow_error *err);
 };
 
 /**
--

2.28.0

#47 lore raw

Hello Harsha,

Quoted 1 line

-----Original Message-----

[snip]

Quoted 6 lines

Tunnel vport is an internal construct used by one specific
application: OVS. So, shouldn't the rte APIs also be application agnostic apart from being vendor agnostic ? For OVS, the match fields in the existing datapath flow rules contain enough information to identify the tunnel type.

Tunnel offload model was inspired by OVS vport, but it is not part of the existing API. It looks like the API documentation should not use that term to avoid confusion.

[snip]

[snip]

Quoted 6 lines

Wouldn't it be better if the APIs do not refer to vports and avoid percolating it down to the PMD ? My point here is to avoid bringing in the knowledge of an application specific virtual object (vport) to the PMD.

As I have mentioned above, the API description should not mention vport. I'll post updated documents.

Quoted 16 lines

Here's some other issues that I see with the helper APIs and vendor-specific variable actions.
1) The application needs some kind of validation (or understanding) of the actions returned by the PMD. The application can't just blindly use the actions specified by the PMD. That is, the decision to pick the set of actions can't be left entirely to the PMD.
2) The application needs to learn a PMD-specific way of action processing for each vendor. For example, how should the application handle flow-miss, given a different set of actions between two vendors (if one vendor has already popped the tunnel header while the other one hasn't).
3) The end-users/customers won't have a common interface (as in, consistent actions) to perform tunnel decap action. This becomes a manageability/maintenance issue for the application while working with different vendors.

Quoted 9 lines

IMO, the API shouldn't expect the PMD to understand the notion of vport. The goal here is to offload a flow rule to decap the tunnel header and forward the packet to a HW endpoint. The problem is that we don't have a way to express the "tnl_pop" datapath action to the HW (decap flow #1, in the context of br-phy in OVS-DPDK) and also we may not want the HW to really pop the tunnel header at that stage. If this cannot be expressed with existing rte action types, maybe we should introduce a new action that clearly defines what is expected to the PMD.

Tunnel Offload API provides a common interface for all HW vendors:
Rule #1: define a tunneled traffic and steer / group traffic related to
that tunnel
Rule #2: within the tunnel selection, run matchers on all packet headers, outer and inner, and perform actions on inner headers in case of a match. For the rule #1 application provides tunnel matchers and traffic selection actions and for rule #2 application provides full header matchers and actions for inner parts. The rest is supplied by PMD according to HW and rule type. Application does not need to understand exact PMD elements implementation.
Helper return value notifies application whether it received requested PMD elements or not. If helper completed successfully, it means that application received required elements and can complete flow rule compilation.
As the result, a packet will be fully offloaded or returned to application with enough information to continue processing in SW.

[snip]

[snip]

Quoted 16 lines
Quoted 6 lines

Miss handling
-------------
Packets going through multiple rte_flow groups are exposed to hw misses due to partial packet processing. In such cases, the software should continue the packet's processing from the point where the hardware missed.

Whether the packet goes through multiple groups or not for tunnel decap processing, should be left to the PMD/HW. These assumptions shouldn't be built into the APIs. The encapsulated packet (i,e with outer headers) should be provided to the application, rather than making SW understand that there was a miss in stage-1, or stage-n in HW. That is, HW either processes it entirely, or punts the whole packet to SW if there's a miss. And the packet should take the normal processing path in SW (no action offload).

Quoted 2 lines

Thanks,
-Harsha

The packet is provided to the application via the standard rte_eth_rx_burst API. Additional information about the HW packet processing state is provided to the application by the suggested rte_flow_get_restore_info API. It is up to the application if to use such provided info, or even if to call this API at all.

[snip]

Regards,
Gregory

#48 lore raw
Quoted 97 lines · Gregory Etelson

Hello Harsha,

Quoted 1 line

-----Original Message-----

[snip]

Quoted 6 lines

Tunnel vport is an internal construct used by one specific
application: OVS. So, shouldn't the rte APIs also be application agnostic apart from being vendor agnostic ? For OVS, the match fields in the existing datapath flow rules contain enough information to identify the tunnel type.

Tunnel offload model was inspired by OVS vport, but it is not part of the existing API. It looks like the API documentation should not use that term to avoid confusion.

[snip]

[snip]

Quoted 6 lines

Wouldn't it be better if the APIs do not refer to vports and avoid percolating it down to the PMD ? My point here is to avoid bringing in the knowledge of an application specific virtual object (vport) to the PMD.

As I have mentioned above, the API description should not mention vport. I'll post updated documents.

Quoted 16 lines

Here's some other issues that I see with the helper APIs and vendor-specific variable actions.
1) The application needs some kind of validation (or understanding) of the actions returned by the PMD. The application can't just blindly use the actions specified by the PMD. That is, the decision to pick the set of actions can't be left entirely to the PMD.
2) The application needs to learn a PMD-specific way of action processing for each vendor. For example, how should the application handle flow-miss, given a different set of actions between two vendors (if one vendor has already popped the tunnel header while the other one hasn't).
3) The end-users/customers won't have a common interface (as in, consistent actions) to perform tunnel decap action. This becomes a manageability/maintenance issue for the application while working with different vendors.

Quoted 9 lines

IMO, the API shouldn't expect the PMD to understand the notion of vport. The goal here is to offload a flow rule to decap the tunnel header and forward the packet to a HW endpoint. The problem is that we don't have a way to express the "tnl_pop" datapath action to the HW (decap flow #1, in the context of br-phy in OVS-DPDK) and also we may not want the HW to really pop the tunnel header at that stage. If this cannot be expressed with existing rte action types, maybe we should introduce a new action that clearly defines what is expected to the PMD.

Tunnel Offload API provides a common interface for all HW vendors:
Rule #1: define a tunneled traffic and steer / group traffic related to
that tunnel
Rule #2: within the tunnel selection, run matchers on all packet headers, outer and inner, and perform actions on inner headers in case of a match. For the rule #1 application provides tunnel matchers and traffic selection actions and for rule #2 application provides full header matchers and actions for inner parts. The rest is supplied by PMD according to HW and rule type. Application does not need to understand exact PMD elements implementation.
Helper return value notifies application whether it received requested PMD elements or not. If helper completed successfully, it means that application received required elements and can complete flow rule compilation.
As the result, a packet will be fully offloaded or returned to application with enough information to continue processing in SW.

[snip]

[snip]

Quoted 16 lines
Quoted 6 lines

Miss handling
-------------
Packets going through multiple rte_flow groups are exposed to hw misses due to partial packet processing. In such cases, the software should continue the packet's processing from the point where the hardware missed.

Whether the packet goes through multiple groups or not for tunnel decap processing, should be left to the PMD/HW. These assumptions shouldn't be built into the APIs. The encapsulated packet (i,e with outer headers) should be provided to the application, rather than making SW understand that there was a miss in stage-1, or stage-n in HW. That is, HW either processes it entirely, or punts the whole packet to SW if there's a miss. And the packet should take the normal processing path in SW (no action offload).

Quoted 2 lines

Thanks,
-Harsha

The packet is provided to the application via the standard rte_eth_rx_burst API. Additional information about the HW packet processing state is provided to the application by the suggested rte_flow_get_restore_info API. It is up to the application if to use such provided info, or even if to call this API at all.

Quoted 5 lines

[snip]

Regards,
Gregory

Hi Gregory, Sriharsha,

Is there any output of the discussion?

#49 lore raw

Hello Feruh,

Quoted 119 lines

Subject: Re: [dpdk-dev] [PATCH v4 2/4] ethdev: tunnel offload model

External email: Use caution opening links or attachments

Quoted 6 lines · Gregory Etelson

Hello Harsha,

Quoted 1 line

-----Original Message-----

[snip]

Quoted 1 line
Quoted 7 lines
Quoted 5 lines

Tunnel vport is an internal construct used by one specific
application: OVS. So, shouldn't the rte APIs also be application agnostic apart from being vendor agnostic ? For OVS, the match fields in the existing datapath flow rules contain enough information to identify the tunnel type.

Tunnel offload model was inspired by OVS vport, but it is not part of

the existing API.

Quoted 1 line

It looks like the API documentation should not use that term to avoid

confusion.

Quoted 40 lines

[snip]

[snip]

Quoted 6 lines

Wouldn't it be better if the APIs do not refer to vports and avoid percolating it down to the PMD ? My point here is to avoid bringing in the knowledge of an application specific virtual object (vport) to the PMD.

As I have mentioned above, the API description should not mention vport. I'll post updated documents.

Quoted 16 lines

Here's some other issues that I see with the helper APIs and vendor-specific variable actions.
1) The application needs some kind of validation (or understanding) of the actions returned by the PMD. The application can't just blindly use the actions specified by the PMD. That is, the decision to pick the set of actions can't be left entirely to the PMD.
2) The application needs to learn a PMD-specific way of action processing for each vendor. For example, how should the application handle flow-miss, given a different set of actions between two vendors (if one vendor has already popped the tunnel header while the other one hasn't).
3) The end-users/customers won't have a common interface (as in, consistent actions) to perform tunnel decap action. This becomes a manageability/maintenance issue for the application while working with different vendors.

Quoted 9 lines

IMO, the API shouldn't expect the PMD to understand the notion of vport. The goal here is to offload a flow rule to decap the tunnel header and forward the packet to a HW endpoint. The problem is that we don't have a way to express the "tnl_pop" datapath action to the HW (decap flow #1, in the context of br-phy in OVS-DPDK) and also we may not want the HW to really pop the tunnel header at that stage. If this cannot be expressed with existing rte action types, maybe we should introduce a new action that clearly defines what is expected to the PMD.

Quoted 4 lines

Tunnel Offload API provides a common interface for all HW vendors:
Rule #1: define a tunneled traffic and steer / group traffic related to that tunnel
Rule #2: within the tunnel selection, run matchers on all packet

headers,

Quoted 1 line

outer and inner, and perform actions on inner headers in case of a

match.

Quoted 1 line

For the rule #1 application provides tunnel matchers and traffic

selection actions

Quoted 1 line

and for rule #2 application provides full header matchers and actions

for inner parts.

Quoted 1 line

The rest is supplied by PMD according to HW and rule type. Application

does not

Quoted 2 lines

need to understand exact PMD elements implementation. Helper return value notifies application whether it received requested

PMD elements or not.

Quoted 1 line

If helper completed successfully, it means that application received

required elements

Quoted 2 lines

and can complete flow rule compilation.
As the result, a packet will be fully offloaded or returned to

application with enough

Quoted 22 lines

information to continue processing in SW.

[snip]

[snip]

Quoted 16 lines
Quoted 6 lines

Miss handling
-------------
Packets going through multiple rte_flow groups are exposed to hw misses due to partial packet processing. In such cases, the software should continue the packet's processing from the point where the hardware missed.

Whether the packet goes through multiple groups or not for tunnel decap processing, should be left to the PMD/HW. These assumptions shouldn't be built into the APIs. The encapsulated packet (i,e with outer headers) should be provided to the application, rather than making SW understand that there was a miss in stage-1, or stage-n in HW. That is, HW either processes it entirely, or punts the whole packet to SW if there's a miss. And the packet should take the normal processing path in SW (no action offload).

Quoted 4 lines
Quoted 2 lines

Thanks,
-Harsha

The packet is provided to the application via the standard

rte_eth_rx_burst API.

Quoted 1 line

Additional information about the HW packet processing state is provided

to

Quoted 1 line

the application by the suggested rte_flow_get_restore_info API. It is up

to the

Quoted 1 line

application if to use such provided info, or even if to call this API at

all.

Quoted 3 lines

[snip]

Quoted 8 lines
Quoted 3 lines

Regards,
Gregory

Hi Gregory, Sriharsha,

Is there any output of the discussion?

Tunnel API documentation was updated in V6.

Regards,
Gregory

#50 lore raw
In reply to Gregory Etelson

Formatting review below (someone has to do it):

04/10/2020 15:50, Gregory Etelson:

doc/guides/prog_guide/rte_flow.rst operations include: · line 3040

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +7 -0
@@ -3034,6 +3034,111 @@ operations include:
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Provide software application with unified rules model for tunneled traffic
+regardless underlying hardware.
+
+ - The model introduces a concept of a virtual tunnel port (VTP).

Given the API does use this terminology, it is confusing to find this wording in the doc.

Quoted 7 lines
doc/guides/prog_guide/rte_flow.rst +7 -0
+ - The model uses VTP to offload ingress tunneled network traffic 
+   with RTE flow rules.
+ - The model is implemented as set of helper functions. Each PMD
+   implements VTP offload according to underlying hardware offload
+   capabilities.  Applications must query PMD for VTP flow
+   items / actions before using in creation of a VTP flow rule.
+

doc/guides/prog_guide/rte_flow.rst operations include: · line 3060

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+The model components:
+
+- Virtual Tunnel Port (VTP) is a stateless software object that
+  describes tunneled network traffic.  VTP object usually contains
+  descriptions of outer headers, tunnel headers and inner headers.
+- Tunnel Steering flow Rule (TSR) detects tunneled packets and
+  delegates them to tunnel processing infrastructure, implemented
+  in PMD for optimal hardware utilization, for further processing.
+- Tunnel Matching flow Rule (TMR) verifies packet configuration and
+  runs offload actions in case of a match.

I'm not a fan of all those acronyms.
It makes reading more difficult in my opinion.

Quoted 15 lines
doc/guides/prog_guide/rte_flow.rst +15 -0
+
+Application actions:
+
+1 Initialize VTP object according to tunnel network parameters.
+
+2 Create TSR flow rule.
+
+2.1 Query PMD for VTP actions. Application can query for VTP actions more than once.
+
+  .. code-block:: c
+
+    int
+    rte_flow_tunnel_decap_set(uint16_t port_id,
+                              struct rte_flow_tunnel *tunnel,
+                              struct rte_flow_action **pmd_actions,

doc/guides/prog_guide/rte_flow.rst operations include: · line 3085

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+                              uint32_t *num_of_pmd_actions,
+                              struct rte_flow_error *error);
+
+2.2 Integrate PMD actions into TSR actions list.
+
+2.3 Create TSR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {tunnel items} / end actions {PMD actions} / {App actions} / end

Not sure about the testpmd syntax here.
Is it bringing a value compared to some text description?

Quoted 28 lines
doc/guides/prog_guide/rte_flow.rst +28 -0
+
+3 Create TMR flow rule.
+
+3.1 Query PMD for VTP items. Application can query for VTP items more than once.
+
+    .. code-block:: c
+
+      int
+      rte_flow_tunnel_match(uint16_t port_id,
+                            struct rte_flow_tunnel *tunnel,
+                            struct rte_flow_item **pmd_items,
+                            uint32_t *num_of_pmd_items,
+                            struct rte_flow_error *error);
+
+3.2 Integrate PMD items into TMR items list.
+
+3.3 Create TMR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {PMD items} / {APP items} / end actions {offload actions} / end
+
+The model provides helper function call to restore packets that miss
+tunnel TMR rules to its original state:
+
+.. code-block:: c
+
+  int

doc/guides/prog_guide/rte_flow.rst operations include: · line 3123

Quoted 10 lines
doc/guides/prog_guide/rte_flow.rst +10 -0
+  rte_flow_get_restore_info(uint16_t port_id,
+                            struct rte_mbuf *mbuf,
+                            struct rte_flow_restore_info *info,
+                            struct rte_flow_error *error);
+
+rte_tunnel object filled by the call inside
+``rte_flow_restore_info *info parameter`` can be used by the application
+to create new TMR rule for that tunnel.
+
+The model requirements:

Should it be a section title?

doc/guides/prog_guide/rte_flow.rst operations include: · line 3127

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().

It is preferred having code symbols between double backquotes.

doc/guides/prog_guide/rte_flow.rst operations include: · line 3131

Quoted 4 lines
doc/guides/prog_guide/rte_flow.rst +4 -0
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+Application can release the actionsfter TSR rule was created.

typo: actionsfter

Quoted 9 lines
doc/guides/prog_guide/rte_flow.rst +9 -0
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release the items after rule was created. However, if the application
+needs to create additional TMR rule for the same tunnel it will need
+to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.

[...]

doc/guides/rel_notes/release_20_11.rst New Features · line 68

Quoted 10 lines
doc/guides/rel_notes/release_20_11.rst +4 -0
@@ -62,6 +62,15 @@ New Features
   * Added support for 200G PAM4 link speed.
   * Added support for RSS hash level selection.
   * Updated HWRM structures to 1.10.1.70 version.
+* **Flow rules allowed to use private PMD items / actions.**
+
+  * Flow rule verification was updated to accept private PMD
+    items and actions.

This should be in the previous patch, but not sure it's worth noting at all.

doc/guides/rel_notes/release_20_11.rst New Features · line 73

Quoted 5 lines
doc/guides/rel_notes/release_20_11.rst +5 -0
+
+* **Added generic API to offload tunneled traffic and restore missed packet.**
+
+  * Added a new hardware independent helper API to RTE flow library that
+    offloads tunneled traffic and restores missed packets.

Here and elsewhere, "hardware independent" is implied for rte_flow API. Please write "flow API" or "rte_flow".
This block should be before driver ones, with other ethdev features.

lib/librte_ethdev/rte_ethdev_version.map EXPERIMENTAL { · line 233

Quoted 11 lines
lib/librte_ethdev/rte_ethdev_version.map +5 -0
@@ -226,6 +226,12 @@ EXPERIMENTAL {
 	rte_tm_wred_profile_add;
 	rte_tm_wred_profile_delete;
 
+	rte_flow_tunnel_decap_set;
+	rte_flow_tunnel_match;
+	rte_flow_get_restore_info;
+	rte_flow_tunnel_action_decap_release;
+	rte_flow_tunnel_item_release;

It is for 20.11 now, so should be placed below.

Quoted 4 lines
lib/librte_ethdev/rte_ethdev_version.map +1 -0
+
 	# added in 20.11
 	rte_eth_link_speed_to_str;
 	rte_eth_link_to_str;
#51 lore raw

PATCH v4 3/4 net/mlx5: implement tunnel offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:
* tunnel_offload PMD parameter must be set to 1 to enable the feature.
* application cannot use MARK and META flow actions whith tunnel.
* offload JUMP action is restricted to steering tunnel rule only.

---
v2:
* introduce MLX5 PMD API implementation
v3:
* bug fixes

---
 doc/guides/nics/mlx5.rst         |   3 +
 drivers/net/mlx5/linux/mlx5_os.c |  18 +
 drivers/net/mlx5/mlx5.c          |   8 +-
 drivers/net/mlx5/mlx5.h          |   3 +
 drivers/net/mlx5/mlx5_defs.h     |   2 +
 drivers/net/mlx5/mlx5_flow.c     | 678 ++++++++++++++++++++++++++++++-
 drivers/net/mlx5/mlx5_flow.h     | 173 +++++++-
 drivers/net/mlx5/mlx5_flow_dv.c  | 241 +++++++++--
 8 files changed, 1080 insertions(+), 46 deletions(-)
doc/guides/nics/mlx5.rst +3 -0
index b0614ae335..03eec3503d 100644
@@ -815,6 +815,9 @@ Driver options
     24 bits. The actual supported width can be retrieved in runtime by
     series of rte_flow_validate() trials.
 
+  - 3, this engages tunnel offload mode. In E-Switch configuration, that
+    mode implicitly activates ``dv_xmeta_en=1``.
+
   +------+-----------+-----------+-------------+-------------+
   | Mode | ``MARK``  | ``META``  | ``META`` Tx | FDB/Through |
   +======+===========+===========+=============+=============+
drivers/net/mlx5/linux/mlx5_os.c +18 -0
index 188a6d4c38..70db822987 100644
@@ -298,6 +298,12 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
 		sh->esw_drop_action = mlx5_glue->dr_create_flow_action_drop();
 	}
 #endif
+	if (!sh->tunnel_hub)
+		err = mlx5_alloc_tunnel_hub(sh);
+	if (err) {
+		DRV_LOG(ERR, "mlx5_alloc_tunnel_hub failed err=%d", err);
+		goto error;
+	}
 	if (priv->config.reclaim_mode == MLX5_RCM_AGGR) {
 		mlx5_glue->dr_reclaim_domain_memory(sh->rx_domain, 1);
 		mlx5_glue->dr_reclaim_domain_memory(sh->tx_domain, 1);
@@ -344,6 +350,10 @@ mlx5_alloc_shared_dr(struct mlx5_priv *priv)
 		mlx5_hlist_destroy(sh->tag_table, NULL, NULL);
 		sh->tag_table = NULL;
 	}
+	if (sh->tunnel_hub) {
+		mlx5_release_tunnel_hub(sh, priv->dev_port);
+		sh->tunnel_hub = NULL;
+	}
 	mlx5_free_table_hash_list(priv);
 	return err;
 }
@@ -405,6 +415,10 @@ mlx5_os_free_shared_dr(struct mlx5_priv *priv)
 		mlx5_hlist_destroy(sh->tag_table, NULL, NULL);
 		sh->tag_table = NULL;
 	}
+	if (sh->tunnel_hub) {
+		mlx5_release_tunnel_hub(sh, priv->dev_port);
+		sh->tunnel_hub = NULL;
+	}
 	mlx5_free_table_hash_list(priv);
 }
 
@@ -658,6 +672,10 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev,
 			strerror(rte_errno));
 		goto error;
 	}
+	if (config->dv_miss_info) {
+		if (switch_info->master || switch_info->representor)
+			config->dv_xmeta_en = MLX5_XMETA_MODE_META16;
+	}
 	mlx5_malloc_mem_select(config->sys_mem_en);
 	sh = mlx5_alloc_shared_dev_ctx(spawn, config);
 	if (!sh)
drivers/net/mlx5/mlx5.c +6 -2
index 01ead6e6af..88d843fc4e 100644
@@ -1591,13 +1591,17 @@ mlx5_args_check(const char *key, const char *val, void *opaque)
 	} else if (strcmp(MLX5_DV_XMETA_EN, key) == 0) {
 		if (tmp != MLX5_XMETA_MODE_LEGACY &&
 		    tmp != MLX5_XMETA_MODE_META16 &&
-		    tmp != MLX5_XMETA_MODE_META32) {
+		    tmp != MLX5_XMETA_MODE_META32 &&
+		    tmp != MLX5_XMETA_MODE_MISS_INFO) {
 			DRV_LOG(ERR, "invalid extensive "
 				     "metadata parameter");
 			rte_errno = EINVAL;
 			return -rte_errno;
 		}
-		config->dv_xmeta_en = tmp;
+		if (tmp != MLX5_XMETA_MODE_MISS_INFO)
+			config->dv_xmeta_en = tmp;
+		else
+			config->dv_miss_info = 1;
 	} else if (strcmp(MLX5_LACP_BY_USER, key) == 0) {
 		config->lacp_by_user = !!tmp;
 	} else if (strcmp(MLX5_MR_EXT_MEMSEG_EN, key) == 0) {
drivers/net/mlx5/mlx5.h +3 -0
index bd91e167e0..b008531736 100644
@@ -206,6 +206,7 @@ struct mlx5_dev_config {
 	unsigned int rt_timestamp:1; /* realtime timestamp format. */
 	unsigned int sys_mem_en:1; /* The default memory allocator. */
 	unsigned int decap_en:1; /* Whether decap will be used or not. */
+	unsigned int dv_miss_info:1; /* restore packet after partial hw miss */
 	struct {
 		unsigned int enabled:1; /* Whether MPRQ is enabled. */
 		unsigned int stride_num_n; /* Number of strides. */
@@ -632,6 +633,8 @@ struct mlx5_dev_ctx_shared {
 	/* UAR same-page access control required in 32bit implementations. */
 #endif
 	struct mlx5_hlist *flow_tbls;
+	struct rte_hash *flow_tbl_map; /* app group-to-flow table map */
+	struct mlx5_flow_tunnel_hub *tunnel_hub;
 	/* Direct Rules tables for FDB, NIC TX+RX */
 	void *esw_drop_action; /* Pointer to DR E-Switch drop action. */
 	void *pop_vlan_action; /* Pointer to DR pop VLAN action. */
drivers/net/mlx5/mlx5_defs.h +2 -0
index 0df47391ee..41a7537d5e 100644
@@ -165,6 +165,8 @@
 #define MLX5_XMETA_MODE_LEGACY 0
 #define MLX5_XMETA_MODE_META16 1
 #define MLX5_XMETA_MODE_META32 2
+/* Provide info on patrial hw miss. Implies MLX5_XMETA_MODE_META16 */
+#define MLX5_XMETA_MODE_MISS_INFO 3
 
 /* MLX5_TX_DB_NC supported values. */
 #define MLX5_TXDB_CACHED 0
drivers/net/mlx5/mlx5_flow.c +660 -18

770 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow.h +170 -3

231 lines not on this page · raw message

drivers/net/mlx5/mlx5_flow_dv.c +218 -23

373 lines not on this page · raw message

Signature · 1 line
2.28.0
#52 lore raw

PATCH v4 4/4 app/testpmd: add commands for tunnel offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:

* Create application tunnel:
flow tunnel create <port> type <tunnel type>
On success, the command creates application tunnel object and returns the tunnel descriptor. Tunnel descriptor is used in subsequent flow creation commands to reference the tunnel.

* Create tunnel steering flow rule:
tunnel_set <tunnel descriptor> parameter used with steering rule template.

* Create tunnel matching flow rule:
tunnel_match <tunnel descriptor> used with matching rule template.

* If tunnel steering rule was offloaded, outer header of a partially offloaded packet is restored after miss.

Example:
test packet=
<Ether dst=24:8a:07:8d:ae:d6 src=50:6b:4b:cc:fc:e2 type=IPv4 | <IP version=4 ihl=5 proto=udp src=1.1.1.1 dst=1.1.1.10 | <UDP sport=4789 dport=4789 len=58 chksum=0x7f7b |
<VXLAN NextProtocol=Ethernet vni=0x0 |
<Ether dst=24:aa:aa:aa:aa:d6 src=50:bb:bb:bb:bb:e2 type=IPv4 | <IP version=4 ihl=5 proto=icmp src=2.2.2.2 dst=2.2.2.200 | <ICMP type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>>>>>

Quoted 1 line
Quoted 1 line
Quoted 1 line

len(packet)

92

testpmd> flow flush 0
testpmd> port 0/queue 0: received 1 packets src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 - length=92

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end
Flow rule #0 created
testpmd> port 0/queue 0: received 1 packets
tunnel restore info: - vxlan tunnel - outer header present # <--
src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 -
length=92

testpmd> flow create 0 ingress group 0 tunnel_match 1
pattern eth / ipv4 / udp dst is 4789 / vxlan / eth / ipv4 / end
actions set_mac_dst mac_addr 02:CA:FE:CA:FA:80 / queue index 0 / end
Flow rule #1 created
testpmd> port 0/queue 0: received 1 packets
src=50:BB:BB:BB:BB:E2 - dst=02:CA:FE:CA:FA:80 - type=0x0800 -
length=42

* Destroy flow tunnel
flow tunnel destroy <port> id <tunnel id>

* Show existing flow tunnels
flow tunnel list <port>

---
v2:
* introduce testpmd support for tunnel offload API

v3:
* update flow tunnel commands

---
 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 253 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 6 files changed, 533 insertions(+), 13 deletions(-)
app/test-pmd/cmdline_flow.c +166 -4
index 6e04d538ea..973dc274c0 100644
@@ -69,6 +69,14 @@ enum index {
 	LIST,
 	AGED,
 	ISOLATE,
+	TUNNEL,
+
+	/* Tunnel argumens. */
+	TUNNEL_CREATE,
+	TUNNEL_CREATE_TYPE,
+	TUNNEL_LIST,
+	TUNNEL_DESTROY,
+	TUNNEL_DESTROY_ID,
 
 	/* Destroy arguments. */
 	DESTROY_RULE,
@@ -88,6 +96,8 @@ enum index {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 
 	/* Validate/create pattern. */
 	PATTERN,
@@ -655,6 +665,7 @@ struct buffer {
 	union {
 		struct {
 			struct rte_flow_attr attr;
+			struct tunnel_ops tunnel_ops;
 			struct rte_flow_item *pattern;
 			struct rte_flow_action *actions;
 			uint32_t pattern_n;
@@ -715,10 +726,32 @@ static const enum index next_vc_attr[] = {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 	PATTERN,
 	ZERO,
 };
 
+static const enum index tunnel_create_attr[] = {
+	TUNNEL_CREATE,
+	TUNNEL_CREATE_TYPE,
+	END,
+	ZERO,
+};
+
+static const enum index tunnel_destroy_attr[] = {
+	TUNNEL_DESTROY,
+	TUNNEL_DESTROY_ID,
+	END,
+	ZERO,
+};
+
+static const enum index tunnel_list_attr[] = {
+	TUNNEL_LIST,
+	END,
+	ZERO,
+};
+
 static const enum index next_destroy_attr[] = {
 	DESTROY_RULE,
 	END,
@@ -1520,6 +1553,9 @@ static int parse_aged(struct context *, const struct token *,
 static int parse_isolate(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
+static int parse_tunnel(struct context *, const struct token *,
+			const char *, unsigned int,
+			void *, unsigned int);
 static int parse_int(struct context *, const struct token *,
 		     const char *, unsigned int,
 		     void *, unsigned int);
@@ -1702,7 +1738,8 @@ static const struct token token_list[] = {
 			      LIST,
 			      AGED,
 			      QUERY,
-			      ISOLATE)),
+			      ISOLATE,
+			      TUNNEL)),
 		.call = parse_init,
 	},
 	/* Sub-level commands. */
@@ -1776,6 +1813,49 @@ static const struct token token_list[] = {
 			     ARGS_ENTRY(struct buffer, port)),
 		.call = parse_isolate,
 	},
+	[TUNNEL] = {
+		.name = "tunnel",
+		.help = "new tunnel API",
+		.next = NEXT(NEXT_ENTRY
+			     (TUNNEL_CREATE, TUNNEL_LIST, TUNNEL_DESTROY)),
+		.call = parse_tunnel,
+	},
+	/* Tunnel arguments. */
+	[TUNNEL_CREATE] = {
+		.name = "create",
+		.help = "create new tunnel object",
+		.next = NEXT(tunnel_create_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_CREATE_TYPE] = {
+		.name = "type",
+		.help = "create new tunnel",
+		.next = NEXT(tunnel_create_attr, NEXT_ENTRY(FILE_PATH)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, type)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy tunel",
+		.next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_DESTROY_ID] = {
+		.name = "id",
+		.help = "tunnel identifier to testroy",
+		.next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_LIST] = {
+		.name = "list",
+		.help = "list existing tunnels",
+		.next = NEXT(tunnel_list_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
 	/* Destroy arguments. */
 	[DESTROY_RULE] = {
 		.name = "rule",
@@ -1839,6 +1919,20 @@ static const struct token token_list[] = {
 		.next = NEXT(next_vc_attr),
 		.call = parse_vc,
 	},
+	[TUNNEL_SET] = {
+		.name = "tunnel_set",
+		.help = "tunnel steer rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
+	[TUNNEL_MATCH] = {
+		.name = "tunnel_match",
+		.help = "tunnel match rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
 	/* Validate/create pattern. */
 	[PATTERN] = {
 		.name = "pattern",
@@ -4072,12 +4166,28 @@ parse_vc(struct context *ctx, const struct token *token,
 		return len;
 	}
 	ctx->objdata = 0;
-	ctx->object = &out->args.vc.attr;
+	switch (ctx->curr) {
+	default:
+		ctx->object = &out->args.vc.attr;
+		break;
+	case TUNNEL_SET:
+	case TUNNEL_MATCH:
+		ctx->object = &out->args.vc.tunnel_ops;
+		break;
+	}
 	ctx->objmask = NULL;
 	switch (ctx->curr) {
 	case GROUP:
 	case PRIORITY:
 		return len;
+	case TUNNEL_SET:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.actions = 1;
+		return len;
+	case TUNNEL_MATCH:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.items = 1;
+		return len;
 	case INGRESS:
 		out->args.vc.attr.ingress = 1;
 		return len;
@@ -5615,6 +5725,47 @@ parse_isolate(struct context *ctx, const struct token *token,
 	return len;
 }
 
+static int
+parse_tunnel(struct context *ctx, const struct token *token,
+	     const char *str, unsigned int len,
+	     void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != TUNNEL)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+	} else {
+		switch (ctx->curr) {
+		default:
+			break;
+		case TUNNEL_CREATE:
+		case TUNNEL_DESTROY:
+		case TUNNEL_LIST:
+			out->command = ctx->curr;
+			break;
+		case TUNNEL_CREATE_TYPE:
+		case TUNNEL_DESTROY_ID:
+			ctx->object = &out->args.vc.tunnel_ops;
+			break;
+		}
+	}
+
+	return len;
+}
+
 /**
  * Parse signed/unsigned integers 8 to 64-bit long.
  *
@@ -6561,11 +6712,13 @@ cmd_flow_parsed(const struct buffer *in)
 	switch (in->command) {
 	case VALIDATE:
 		port_flow_validate(in->port, &in->args.vc.attr,
-				   in->args.vc.pattern, in->args.vc.actions);
+				   in->args.vc.pattern, in->args.vc.actions,
+				   &in->args.vc.tunnel_ops);
 		break;
 	case CREATE:
 		port_flow_create(in->port, &in->args.vc.attr,
-				 in->args.vc.pattern, in->args.vc.actions);
+				 in->args.vc.pattern, in->args.vc.actions,
+				 &in->args.vc.tunnel_ops);
 		break;
 	case DESTROY:
 		port_flow_destroy(in->port, in->args.destroy.rule_n,
@@ -6591,6 +6744,15 @@ cmd_flow_parsed(const struct buffer *in)
 	case AGED:
 		port_flow_aged(in->port, in->args.aged.destroy);
 		break;
+	case TUNNEL_CREATE:
+		port_flow_tunnel_create(in->port, &in->args.vc.tunnel_ops);
+		break;
+	case TUNNEL_DESTROY:
+		port_flow_tunnel_destroy(in->port, in->args.vc.tunnel_ops.id);
+		break;
+	case TUNNEL_LIST:
+		port_flow_tunnel_list(in->port);
+		break;
 	default:
 		break;
 	}
app/test-pmd/config.c +249 -4

313 lines not on this page · raw message

app/test-pmd/testpmd.c +4 -1
index ccba71c076..93b9e4dde1 100644
@@ -3567,6 +3567,8 @@ init_port_dcb_config(portid_t pid,
 static void
 init_port(void)
 {
+	int i;
+
 	/* Configuration of Ethernet ports. */
 	ports = rte_zmalloc("testpmd: ports",
 			    sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
@@ -3576,7 +3578,8 @@ init_port(void)
 				"rte_zmalloc(%d struct rte_port) failed\n",
 				RTE_MAX_ETHPORTS);
 	}
-
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+		LIST_INIT(&ports[i].flow_tunnel_list);
 	/* Initialize ports NUMA structures */
 	memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
 	memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
app/test-pmd/testpmd.h +32 -2
index c7e7e41a97..d3d43b4504 100644
@@ -12,6 +12,7 @@
 #include <rte_gro.h>
 #include <rte_gso.h>
 #include <cmdline.h>
+#include <sys/queue.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -142,6 +143,26 @@ struct port_flow {
 	uint8_t data[]; /**< Storage for flow rule description */
 };
 
+struct port_flow_tunnel {
+	LIST_ENTRY(port_flow_tunnel) chain;
+	struct rte_flow_action *pmd_actions;
+	struct rte_flow_item   *pmd_items;
+	uint32_t id;
+	uint32_t num_pmd_actions;
+	uint32_t num_pmd_items;
+	struct rte_flow_tunnel tunnel;
+	struct rte_flow_action *actions;
+	struct rte_flow_item *items;
+};
+
+struct tunnel_ops {
+	uint32_t id;
+	char type[16];
+	uint32_t enabled:1;
+	uint32_t actions:1;
+	uint32_t items:1;
+};
+
 /**
  * The data structure associated with each port.
  */
@@ -172,6 +193,7 @@ struct rte_port {
 	uint32_t                mc_addr_nb; /**< nb. of addr. in mc_addr_pool */
 	uint8_t                 slave_flag; /**< bonding slave port */
 	struct port_flow        *flow_list; /**< Associated flows. */
+	LIST_HEAD(, port_flow_tunnel) flow_tunnel_list;
 	const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	/**< metadata value to insert in Tx packets. */
@@ -751,11 +773,13 @@ void port_reg_set(portid_t port_id, uint32_t reg_off, uint32_t value);
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
-		       const struct rte_flow_action *actions);
+		       const struct rte_flow_action *actions,
+		       const struct tunnel_ops *tunnel_ops);
 int port_flow_create(portid_t port_id,
 		     const struct rte_flow_attr *attr,
 		     const struct rte_flow_item *pattern,
-		     const struct rte_flow_action *actions);
+		     const struct rte_flow_action *actions,
+		     const struct tunnel_ops *tunnel_ops);
 void update_age_action_context(const struct rte_flow_action *actions,
 		     struct port_flow *pf);
 int port_flow_destroy(portid_t port_id, uint32_t n, const uint32_t *rule);
@@ -765,6 +789,12 @@ int port_flow_query(portid_t port_id, uint32_t rule,
 		    const struct rte_flow_action *action);
 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
 void port_flow_aged(portid_t port_id, uint8_t destroy);
+const char *port_flow_tunnel_type(struct rte_flow_tunnel *tunnel);
+struct port_flow_tunnel *
+port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun);
+void port_flow_tunnel_list(portid_t port_id);
+void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
+void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops);
 int port_flow_isolate(portid_t port_id, int set);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
app/test-pmd/util.c +33 -2
index 8488fa1a8f..781a813759 100644
@@ -48,18 +48,49 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 	       is_rx ? "received" : "sent",
 	       (unsigned int) nb_pkts);
 	for (i = 0; i < nb_pkts; i++) {
+		int ret;
+		struct rte_flow_error error;
+		struct rte_flow_restore_info info = { 0, };
+
 		mb = pkts[i];
 		eth_hdr = rte_pktmbuf_read(mb, 0, sizeof(_eth_hdr), &_eth_hdr);
 		eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
-		ol_flags = mb->ol_flags;
 		packet_type = mb->packet_type;
 		is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
-
+		ret = rte_flow_get_restore_info(port_id, mb, &info, &error);
+		if (!ret) {
+			printf("restore info:");
+			if (info.flags & RTE_FLOW_RESTORE_INFO_TUNNEL) {
+				struct port_flow_tunnel *port_tunnel;
+
+				port_tunnel = port_flow_locate_tunnel
+					      (port_id, &info.tunnel);
+				printf(" - tunnel");
+				if (port_tunnel)
+					printf(" #%u", port_tunnel->id);
+				else
+					printf(" %s", "-none-");
+				printf(" type %s",
+					port_flow_tunnel_type(&info.tunnel));
+			} else {
+				printf(" - no tunnel info");
+			}
+			if (info.flags & RTE_FLOW_RESTORE_INFO_ENCAPSULATED)
+				printf(" - outer header present");
+			else
+				printf(" - no outer header");
+			if (info.flags & RTE_FLOW_RESTORE_INFO_GROUP_ID)
+				printf(" - miss group %u", info.group_id);
+			else
+				printf(" - no miss group");
+			printf("\n");
+		}
 		print_ether_addr("  src=", &eth_hdr->s_addr);
 		print_ether_addr(" - dst=", &eth_hdr->d_addr);
 		printf(" - type=0x%04x - length=%u - nb_segs=%d",
 		       eth_type, (unsigned int) mb->pkt_len,
 		       (int)mb->nb_segs);
+		ol_flags = mb->ol_flags;
 		if (ol_flags & PKT_RX_RSS_HASH) {
 			printf(" - RSS hash=0x%x", (unsigned int) mb->hash.rss);
 			printf(" - RSS queue=0x%x", (unsigned int) queue);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +49 -0

73 lines not on this page · raw message

Signature · 1 line
2.28.0
Acked-by on v4 4/4
#53 lore raw

Re: [dpdk-dev] [PATCH v4 4/4] app/testpmd: add commands for tunnel offload API

Hi

Quoted 74 lines

-----Original Message-----
From: Gregory Etelson <[email protected]>
Sent: Sunday, October 4, 2020 4:51 PM
Subject: [PATCH v4 4/4] app/testpmd: add commands for tunnel offload API

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:

* Create application tunnel:
flow tunnel create <port> type <tunnel type>
On success, the command creates application tunnel object and returns the tunnel descriptor. Tunnel descriptor is used in subsequent flow creation commands to reference the tunnel.

* Create tunnel steering flow rule:
tunnel_set <tunnel descriptor> parameter used with steering rule template.

* Create tunnel matching flow rule:
tunnel_match <tunnel descriptor> used with matching rule template.

* If tunnel steering rule was offloaded, outer header of a partially offloaded packet is restored after miss.

Example:
test packet=
<Ether dst=24:8a:07:8d:ae:d6 src=50:6b:4b:cc:fc:e2 type=IPv4 | <IP version=4 ihl=5 proto=udp src=1.1.1.1 dst=1.1.1.10 | <UDP sport=4789 dport=4789 len=58 chksum=0x7f7b |
<VXLAN NextProtocol=Ethernet vni=0x0 |
<Ether dst=24:aa:aa:aa:aa:d6 src=50:bb:bb:bb:bb:e2 type=IPv4 | <IP version=4 ihl=5 proto=icmp src=2.2.2.2 dst=2.2.2.200 | <ICMP type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>>>>>

Quoted 1 line
Quoted 1 line
Quoted 1 line

len(packet)

92

testpmd> flow flush 0
testpmd> port 0/queue 0: received 1 packets src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 - length=92

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end
Flow rule #0 created
testpmd> port 0/queue 0: received 1 packets
tunnel restore info: - vxlan tunnel - outer header present # <--
src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 -
length=92

testpmd> flow create 0 ingress group 0 tunnel_match 1
pattern eth / ipv4 / udp dst is 4789 / vxlan / eth / ipv4 / end
actions set_mac_dst mac_addr 02:CA:FE:CA:FA:80 / queue index 0 / end
Flow rule #1 created
testpmd> port 0/queue 0: received 1 packets
src=50:BB:BB:BB:BB:E2 - dst=02:CA:FE:CA:FA:80 - type=0x0800 -
length=42

* Destroy flow tunnel
flow tunnel destroy <port> id <tunnel id>

* Show existing flow tunnels
flow tunnel list <port>

Quoted 8 lines

---
v2:
* introduce testpmd support for tunnel offload API

v3:
* update flow tunnel commands
---

Thanks,
Ori

#54 lore raw

Re: [dpdk-dev] [PATCH v4 0/4] Tunnel Offload API

In reply to Gregory Etelson
Quoted 21 lines · Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers

    during entire offload procedure;

- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

v2:
* documentation updates
* MLX5 PMD implementation for tunnel offload
* testpmd updates for tunnel offload

v3:
* documentation updates
* MLX5 PMD updates
* testpmd updates

v4:
* updated patch: allow negative values in flow rule types

Quoted 8 lines

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (3):
ethdev: allow negative values in flow rule types net/mlx5: implement tunnel offload API app/testpmd: add commands for tunnel offload API

Hi Gregory,

If there is no more discussion results you are waiting, can you please rebase your patch on top of latest next-net?

#55 lore raw

v5 cover Tunnel Offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

v2:
* documentation updates
* MLX5 PMD implementation for tunnel offload
* testpmd updates for tunnel offload

v3:
* documentation updates
* MLX5 PMD updates
* testpmd updates

v4:
* updated patch: allow negative values in flow rule types

v5:
* rebase to next-net

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (2):
ethdev: allow negative values in flow rule types app/testpmd: add commands for tunnel offload API

 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 252 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/prog_guide/rte_flow.rst          | 108 +++++++++
 doc/guides/rel_notes/release_20_11.rst      |  10 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 lib/librte_ethdev/rte_ethdev_version.map    |   5 +
 lib/librte_ethdev/rte_flow.c                | 140 ++++++++++-
 lib/librte_ethdev/rte_flow.h                | 195 +++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h         |  32 +++
 12 files changed, 1016 insertions(+), 19 deletions(-)
Signature · 1 line
2.28.0
#56 lore raw

PATCH v5 1/3 ethdev: allow negative values in flow rule types

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

RTE flow item or action conversion library accepts positive known element types with predefined sizes only. Private PMD items and actions do not fit into this scheme becase PMD type values are negative, each PMD has it's own types numeration and element types and their sizes are not visible at RTE level. To resolve these limitations the patch proposes this solution:
1. PMD can expose elements of pointer size only. RTE flow conversion functions will use pointer size for each configuration object in private PMD element it processes;
2. RTE flow verification will not reject elements with negative type.

---
v4:
* update the 'Negative types' section in the rtre_flow.rst

* update the patch comment

v5:
* rebase to next-net

---
 doc/guides/prog_guide/rte_flow.rst     |  3 +++
 doc/guides/rel_notes/release_20_11.rst |  5 +++++
 lib/librte_ethdev/rte_flow.c           | 28 ++++++++++++++++++++------
 3 files changed, 30 insertions(+), 6 deletions(-)
doc/guides/prog_guide/rte_flow.rst +3 -0
index 55497c9033..d0dd7a00f1 100644
@@ -2765,6 +2765,9 @@ identifiers they are not aware of.
 
 A method to generate them remains to be defined.
 
+Application may use PMD dynamic items or actions in flow rules. In that case
+size of configuration object in dynamic element must be a pointer size.
+
 Planned types
 ~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_11.rst +5 -0
index 3181fdb6a7..55bcb5e91f 100644
@@ -92,6 +92,11 @@ New Features
   * Updated HWRM structures to 1.10.1.70 version.
   * Added TRUFLOW support for Stingray devices.
 
+* **Flow rules allowed to use private PMD items / actions.**
+
+  * Flow rule verification was updated to accept private PMD
+    items and actions.
+
 * **Updated Cisco enic driver.**
 
   * Added support for VF representors with single-queue Tx/Rx and flow API
lib/librte_ethdev/rte_flow.c +22 -6
index ee4f3464fe..411da1940e 100644
@@ -480,7 +480,11 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (int)item->type >= 0 ?
+		      rte_flow_desc_item[item->type].size : sizeof(void *);
 		rte_memcpy(buf, data, (size > off ? off : size));
 		break;
 	}
@@ -583,7 +587,11 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_action[action->type].size;
+		/**
+		 * allow PMD private flow action
+		 */
+		off = (int)action->type >= 0 ?
+		      rte_flow_desc_action[action->type].size : sizeof(void *);
 		rte_memcpy(buf, action->conf, (size > off ? off : size));
 		break;
 	}
@@ -625,8 +633,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-		    !rte_flow_desc_item[src->type].name)
+		/**
+		 * allow PMD private flow item
+		 */
+		if (((int)src->type >= 0) &&
+			((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+		    !rte_flow_desc_item[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
 				 "cannot convert unknown item type");
@@ -714,8 +726,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-		    !rte_flow_desc_action[src->type].name)
+		/**
+		 * allow PMD private flow action
+		 */
+		if (((int)src->type >= 0) &&
+		    ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+		    !rte_flow_desc_action[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
 				 src, "cannot convert unknown action type");
Signature · 1 line
2.28.0
#57 lore raw

PATCH v5 2/3 ethdev: tunnel offload model

In reply to Gregory Etelson

From: Eli Britstein <[email protected]>

Rte_flow API provides the building blocks for vendor agnostic flow classification offloads. The rte_flow match and action primitives are fine grained, thus enabling DPDK applications the flexibility to offload network stacks and complex pipelines.

Applications wishing to offload complex data structures (e.g. tunnel virtual ports) are required to use the rte_flow primitives, such as group, meta, mark, tag and others to model their high level objects.

The hardware model design for high level software objects is not trivial. Furthermore, an optimal design is often vendor specific.

The goal of this API is to provide applications with the hardware offload model for common high level software objects which is optimal in regards to the underlying hardware.

Tunnel ports are the first of such objects.

Tunnel ports
------------
Ingress processing of tunneled traffic requires the classification of the tunnel type followed by a decap action.

In software, once a packet is decapsulated the in_port field is changed to a virtual port representing the tunnel type. The outer header fields are stored as packet metadata members and may be matched by proceeding flows.

Openvswitch, for example, uses two flows:
1. classification flow - setting the virtual port representing the tunnel type For example: match on udp port 4789 actions=tnl_pop(vxlan_vport)
2. steering flow according to outer and inner header matches match on in_port=vxlan_vport and outer/inner header matches actions=forward to p ort X The benefits of multi-flow tables are described in [1].

Offloading tunnel ports
-----------------------
Tunnel ports introduce a new stateless field that can be matched on. Currently the rte_flow library provides an API to encap, decap and match on tunnel headers. However, there is no rte_flow primitive to set and match tunnel virtual ports.

There are several possible hardware models for offloading virtual tunnel port flows including, but not limited to, the following:
1. Setting the virtual port on a hw register using the rte_flow_action_mark/ rte_flow_action_tag/rte_flow_set_meta objects.
2. Mapping a virtual port to an rte_flow group
3. Avoiding the need to match on transient objects by merging multi-table flows to a single rte_flow rule.

Every approach has its pros and cons. The preferred approach should take into account the entire system architecture and is very often vendor specific.

The proposed rte_flow_tunnel_decap_set helper function (drafted below) is designed to provide a common, vendor agnostic, API for setting the virtual port value. The helper API enables PMD implementations to return vendor specific combination of rte_flow actions realizing the vendor's hardware model for setting a tunnel port. Applications may append the list of actions returned from the helper function when creating an rte_flow rule in hardware.

Similarly, the rte_flow_tunnel_match helper (drafted below) allows for multiple hardware implementations to return a list of fte_flow items.

Miss handling
-------------
Packets going through multiple rte_flow groups are exposed to hw misses due to partial packet processing. In such cases, the software should continue the packet's processing from the point where the hardware missed.

We propose a generic rte_flow_restore structure providing the state that was stored in hardware when the packet missed.

Currently, the structure will provide the tunnel state of the packet that missed, namely:
1. The group id that missed
2. The tunnel port that missed
3. Tunnel information that was stored in memory (due to decap action). In the future, we may add additional fields as more state may be stored in the device memory (e.g. ct_state).

Applications may query the state via a new rte_flow_tunnel_get_restore_info(mbuf) API, thus allowing a vendor specific implementation.

VXLAN Code example:
Assume application needs to do inner NAT on VXLAN packet. The first rule in group 0:

flow create <port id> ingress group 0
pattern eth / ipv4 / udp dst is 4789 / vxlan / end actions {pmd actions} / jump group 3 / end

First VXLAN packet that arrives matches the rule in group 0 and jumps to group 3 In group 3 the packet will miss since there is no flow to match and will be uploaded to application. Application will call rte_flow_get_restore_info() to get the packet outer header. Application will insert a new rule in group 3 to match outer and inner headers:

flow create <port id> ingress group 3
pattern {pmd items} / eth / ipv4 dst is 172.10.10.1 /
udp dst 4789 / vxlan vni is 10 /
ipv4 dst is 184.1.2.3 / end
actions set_ipv4_dst 186.1.1.1 / queue index 3 / end

Resulting of rules will be that VXLAN packet with vni=10, outer IPv4 dst=172.10.10.1 and inner IPv4 dst=184.1.2.3 will be received decaped on queue 3 with IPv4 dst=186.1.1.1

Note: Packet in group 3 is considered decaped. All actions in that group will be done on header that was inner before decap. Application may specify outer header to be matched on. It's PMD responsibility to translate these items to outer metadata.

API usage:
/**
* 1. Initiate RTE flow tunnel object
*/
const struct rte_flow_tunnel tunnel = {
.type = RTE_FLOW_ITEM_TYPE_VXLAN,
.tun_id = 10,
}

/**
* 2. Obtain PMD tunnel actions
*
* pmd_actions is an intermediate variable application uses to
* compile actions array
*/
struct rte_flow_action **pmd_actions; rte_flow_tunnel_decap_and_set(&tunnel, &pmd_actions,

                              &num_pmd_actions, &error);

/**
* 3. offload the first rule
* matching on VXLAN traffic and jumps to group 3
* (implicitly decaps packet)
*/
app_actions = jump group 3
rule_items = app_items; /** eth / ipv4 / udp / vxlan */ rule_actions = { pmd_actions, app_actions }; attr.group = 0;
flow_1 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 4. after flow creation application does not need to keep tunnel
* action resources.
*/
rte_flow_tunnel_action_release(port_id, pmd_actions,

                               num_pmd_actions);

/**
* 5. After partially offloaded packet miss because there was no
* matching rule handle miss on group 3
*/
struct rte_flow_restore_info info; rte_flow_get_restore_info(port_id, mbuf, &info, &error);

/**
* 6. Offload NAT rule:
*/
app_items = { eth / ipv4 dst is 172.10.10.1 / udp dst 4789 /

            vxlan vni is 10 / ipv4 dst is 184.1.2.3 }

app_actions = { set_ipv4_dst 186.1.1.1 / queue index 3 }

rte_flow_tunnel_match(&info.tunnel, &pmd_items,

                      &num_pmd_items,  &error);

rule_items = {pmd_items, app_items};
rule_actions = app_actions;
attr.group = info.group_id;
flow_2 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 7. Release PMD items after rule creation
*/
rte_flow_tunnel_item_release(port_id, pmd_items, num_pmd_items);

References
1. https://mails.dpdk.org/archives/dev/2020-June/index.html

---
v5:

* rebase to next-net

---
 doc/guides/prog_guide/rte_flow.rst       | 105 ++++++++++++
 doc/guides/rel_notes/release_20_11.rst   |   5 +
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 195 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 6 files changed, 454 insertions(+)
doc/guides/prog_guide/rte_flow.rst +105 -0
index d0dd7a00f1..72ec789c27 100644
@@ -3121,6 +3121,111 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+Provide software application with unified rules model for tunneled traffic
+regardless underlying hardware.
+
+ - The model introduces a concept of a virtual tunnel port (VTP).
+ - The model uses VTP to offload ingress tunneled network traffic 
+   with RTE flow rules.
+ - The model is implemented as set of helper functions. Each PMD
+   implements VTP offload according to underlying hardware offload
+   capabilities.  Applications must query PMD for VTP flow
+   items / actions before using in creation of a VTP flow rule.
+
+The model components:
+
+- Virtual Tunnel Port (VTP) is a stateless software object that
+  describes tunneled network traffic.  VTP object usually contains
+  descriptions of outer headers, tunnel headers and inner headers.
+- Tunnel Steering flow Rule (TSR) detects tunneled packets and
+  delegates them to tunnel processing infrastructure, implemented
+  in PMD for optimal hardware utilization, for further processing.
+- Tunnel Matching flow Rule (TMR) verifies packet configuration and
+  runs offload actions in case of a match.
+
+Application actions:
+
+1 Initialize VTP object according to tunnel network parameters.
+
+2 Create TSR flow rule.
+
+2.1 Query PMD for VTP actions. Application can query for VTP actions more than once.
+
+  .. code-block:: c
+
+    int
+    rte_flow_tunnel_decap_set(uint16_t port_id,
+                              struct rte_flow_tunnel *tunnel,
+                              struct rte_flow_action **pmd_actions,
+                              uint32_t *num_of_pmd_actions,
+                              struct rte_flow_error *error);
+
+2.2 Integrate PMD actions into TSR actions list.
+
+2.3 Create TSR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {tunnel items} / end actions {PMD actions} / {App actions} / end
+
+3 Create TMR flow rule.
+
+3.1 Query PMD for VTP items. Application can query for VTP items more than once.
+
+    .. code-block:: c
+
+      int
+      rte_flow_tunnel_match(uint16_t port_id,
+                            struct rte_flow_tunnel *tunnel,
+                            struct rte_flow_item **pmd_items,
+                            uint32_t *num_of_pmd_items,
+                            struct rte_flow_error *error);
+
+3.2 Integrate PMD items into TMR items list.
+
+3.3 Create TMR flow rule.
+
+    .. code-block:: console
+
+      flow create <port> group 0 match {PMD items} / {APP items} / end actions {offload actions} / end
+
+The model provides helper function call to restore packets that miss
+tunnel TMR rules to its original state:
+
+.. code-block:: c
+
+  int
+  rte_flow_get_restore_info(uint16_t port_id,
+                            struct rte_mbuf *mbuf,
+                            struct rte_flow_restore_info *info,
+                            struct rte_flow_error *error);
+
+rte_tunnel object filled by the call inside
+``rte_flow_restore_info *info parameter`` can be used by the application
+to create new TMR rule for that tunnel.
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+Application can release the actionsfter TSR rule was created.
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release the items after rule was created. However, if the application
+needs to create additional TMR rule for the same tunnel it will need
+to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
 
doc/guides/rel_notes/release_20_11.rst +5 -0
index 55bcb5e91f..a0c6f7264d 100644
@@ -97,6 +97,11 @@ New Features
   * Flow rule verification was updated to accept private PMD
     items and actions.
 
+* **Added generic API to offload tunneled traffic and restore missed packet.**
+
+  * Added a new hardware independent helper API to RTE flow library that
+    offloads tunneled traffic and restores missed packets.
+
 * **Updated Cisco enic driver.**
 
   * Added support for VF representors with single-queue Tx/Rx and flow API
lib/librte_ethdev/rte_ethdev_version.map +5 -0
index 31242dabbf..734657737f 100644
@@ -236,6 +236,11 @@ EXPERIMENTAL {
 	rte_flow_shared_action_destroy;
 	rte_flow_shared_action_query;
 	rte_flow_shared_action_update;
+	rte_flow_tunnel_decap_set;
+	rte_flow_tunnel_match;
+	rte_flow_get_restore_info;
+	rte_flow_tunnel_action_decap_release;
+	rte_flow_tunnel_item_release;
 };
 
 INTERNAL {
lib/librte_ethdev/rte_flow.c +112 -0

115 lines not on this page · raw message

lib/librte_ethdev/rte_flow.h +195 -0

201 lines not on this page · raw message

lib/librte_ethdev/rte_flow_driver.h +32 -0
index 58f56b0262..bd5ffc0bb1 100644
@@ -131,6 +131,38 @@ struct rte_flow_ops {
 		 const struct rte_flow_shared_action *shared_action,
 		 void *data,
 		 struct rte_flow_error *error);
+	/** See rte_flow_tunnel_decap_set() */
+	int (*tunnel_decap_set)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_action **pmd_actions,
+		 uint32_t *num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_match() */
+	int (*tunnel_match)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_item **pmd_items,
+		 uint32_t *num_of_items,
+		 struct rte_flow_error *err);
+	/** See rte_flow_get_rte_flow_restore_info() */
+	int (*get_restore_info)
+		(struct rte_eth_dev *dev,
+		 struct rte_mbuf *m,
+		 struct rte_flow_restore_info *info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_action_tunnel_decap_release() */
+	int (*action_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_action *pmd_actions,
+		 uint32_t num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_item_release() */
+	int (*item_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_item *pmd_items,
+		 uint32_t num_of_items,
+		 struct rte_flow_error *err);
 };
 
 /**
Signature · 1 line
2.28.0
#58 lore raw

PATCH v5 3/3 app/testpmd: add commands for tunnel offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:

* Create application tunnel:
flow tunnel create <port> type <tunnel type>
On success, the command creates application tunnel object and returns the tunnel descriptor. Tunnel descriptor is used in subsequent flow creation commands to reference the tunnel.

* Create tunnel steering flow rule:
tunnel_set <tunnel descriptor> parameter used with steering rule template.

* Create tunnel matching flow rule:
tunnel_match <tunnel descriptor> used with matching rule template.

* If tunnel steering rule was offloaded, outer header of a partially offloaded packet is restored after miss.

Example:
test packet=
<Ether dst=24:8a:07:8d:ae:d6 src=50:6b:4b:cc:fc:e2 type=IPv4 | <IP version=4 ihl=5 proto=udp src=1.1.1.1 dst=1.1.1.10 | <UDP sport=4789 dport=4789 len=58 chksum=0x7f7b |
<VXLAN NextProtocol=Ethernet vni=0x0 |
<Ether dst=24:aa:aa:aa:aa:d6 src=50:bb:bb:bb:bb:e2 type=IPv4 | <IP version=4 ihl=5 proto=icmp src=2.2.2.2 dst=2.2.2.200 | <ICMP type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>>>>>

Quoted 1 line
Quoted 1 line
Quoted 1 line

len(packet)

92

testpmd> flow flush 0
testpmd> port 0/queue 0: received 1 packets src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 - length=92

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end
Flow rule #0 created
testpmd> port 0/queue 0: received 1 packets
tunnel restore info: - vxlan tunnel - outer header present # <--
src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 -
length=92

testpmd> flow create 0 ingress group 0 tunnel_match 1
pattern eth / ipv4 / udp dst is 4789 / vxlan / eth / ipv4 / end
actions set_mac_dst mac_addr 02:CA:FE:CA:FA:80 / queue index 0 / end
Flow rule #1 created
testpmd> port 0/queue 0: received 1 packets
src=50:BB:BB:BB:BB:E2 - dst=02:CA:FE:CA:FA:80 - type=0x0800 -
length=42

* Destroy flow tunnel
flow tunnel destroy <port> id <tunnel id>

* Show existing flow tunnels
flow tunnel list <port>

---
v2:
* introduce testpmd support for tunnel offload API

v3:
* update flow tunnel commands

v5:
* rebase to next-net

---
 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 252 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 6 files changed, 532 insertions(+), 13 deletions(-)
app/test-pmd/cmdline_flow.c +166 -4
index 84bba0f29e..ce7e9fc079 100644
@@ -74,6 +74,14 @@ enum index {
 	LIST,
 	AGED,
 	ISOLATE,
+	TUNNEL,
+
+	/* Tunnel argumens. */
+	TUNNEL_CREATE,
+	TUNNEL_CREATE_TYPE,
+	TUNNEL_LIST,
+	TUNNEL_DESTROY,
+	TUNNEL_DESTROY_ID,
 
 	/* Destroy arguments. */
 	DESTROY_RULE,
@@ -93,6 +101,8 @@ enum index {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 
 	/* Shared action arguments */
 	SHARED_ACTION_CREATE,
@@ -711,6 +721,7 @@ struct buffer {
 		} sa; /* Shared action query arguments */
 		struct {
 			struct rte_flow_attr attr;
+			struct tunnel_ops tunnel_ops;
 			struct rte_flow_item *pattern;
 			struct rte_flow_action *actions;
 			uint32_t pattern_n;
@@ -787,10 +798,32 @@ static const enum index next_vc_attr[] = {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 	PATTERN,
 	ZERO,
 };
 
+static const enum index tunnel_create_attr[] = {
+	TUNNEL_CREATE,
+	TUNNEL_CREATE_TYPE,
+	END,
+	ZERO,
+};
+
+static const enum index tunnel_destroy_attr[] = {
+	TUNNEL_DESTROY,
+	TUNNEL_DESTROY_ID,
+	END,
+	ZERO,
+};
+
+static const enum index tunnel_list_attr[] = {
+	TUNNEL_LIST,
+	END,
+	ZERO,
+};
+
 static const enum index next_destroy_attr[] = {
 	DESTROY_RULE,
 	END,
@@ -1639,6 +1672,9 @@ static int parse_aged(struct context *, const struct token *,
 static int parse_isolate(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
+static int parse_tunnel(struct context *, const struct token *,
+			const char *, unsigned int,
+			void *, unsigned int);
 static int parse_int(struct context *, const struct token *,
 		     const char *, unsigned int,
 		     void *, unsigned int);
@@ -1840,7 +1876,8 @@ static const struct token token_list[] = {
 			      LIST,
 			      AGED,
 			      QUERY,
-			      ISOLATE)),
+			      ISOLATE,
+			      TUNNEL)),
 		.call = parse_init,
 	},
 	/* Top-level command. */
@@ -1951,6 +1988,49 @@ static const struct token token_list[] = {
 			     ARGS_ENTRY(struct buffer, port)),
 		.call = parse_isolate,
 	},
+	[TUNNEL] = {
+		.name = "tunnel",
+		.help = "new tunnel API",
+		.next = NEXT(NEXT_ENTRY
+			     (TUNNEL_CREATE, TUNNEL_LIST, TUNNEL_DESTROY)),
+		.call = parse_tunnel,
+	},
+	/* Tunnel arguments. */
+	[TUNNEL_CREATE] = {
+		.name = "create",
+		.help = "create new tunnel object",
+		.next = NEXT(tunnel_create_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_CREATE_TYPE] = {
+		.name = "type",
+		.help = "create new tunnel",
+		.next = NEXT(tunnel_create_attr, NEXT_ENTRY(FILE_PATH)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, type)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy tunel",
+		.next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_DESTROY_ID] = {
+		.name = "id",
+		.help = "tunnel identifier to testroy",
+		.next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_LIST] = {
+		.name = "list",
+		.help = "list existing tunnels",
+		.next = NEXT(tunnel_list_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
 	/* Destroy arguments. */
 	[DESTROY_RULE] = {
 		.name = "rule",
@@ -2014,6 +2094,20 @@ static const struct token token_list[] = {
 		.next = NEXT(next_vc_attr),
 		.call = parse_vc,
 	},
+	[TUNNEL_SET] = {
+		.name = "tunnel_set",
+		.help = "tunnel steer rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
+	[TUNNEL_MATCH] = {
+		.name = "tunnel_match",
+		.help = "tunnel match rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
 	/* Validate/create pattern. */
 	[PATTERN] = {
 		.name = "pattern",
@@ -4477,12 +4571,28 @@ parse_vc(struct context *ctx, const struct token *token,
 		return len;
 	}
 	ctx->objdata = 0;
-	ctx->object = &out->args.vc.attr;
+	switch (ctx->curr) {
+	default:
+		ctx->object = &out->args.vc.attr;
+		break;
+	case TUNNEL_SET:
+	case TUNNEL_MATCH:
+		ctx->object = &out->args.vc.tunnel_ops;
+		break;
+	}
 	ctx->objmask = NULL;
 	switch (ctx->curr) {
 	case GROUP:
 	case PRIORITY:
 		return len;
+	case TUNNEL_SET:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.actions = 1;
+		return len;
+	case TUNNEL_MATCH:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.items = 1;
+		return len;
 	case INGRESS:
 		out->args.vc.attr.ingress = 1;
 		return len;
@@ -6090,6 +6200,47 @@ parse_isolate(struct context *ctx, const struct token *token,
 	return len;
 }
 
+static int
+parse_tunnel(struct context *ctx, const struct token *token,
+	     const char *str, unsigned int len,
+	     void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != TUNNEL)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+	} else {
+		switch (ctx->curr) {
+		default:
+			break;
+		case TUNNEL_CREATE:
+		case TUNNEL_DESTROY:
+		case TUNNEL_LIST:
+			out->command = ctx->curr;
+			break;
+		case TUNNEL_CREATE_TYPE:
+		case TUNNEL_DESTROY_ID:
+			ctx->object = &out->args.vc.tunnel_ops;
+			break;
+		}
+	}
+
+	return len;
+}
+
 /**
  * Parse signed/unsigned integers 8 to 64-bit long.
  *
@@ -7130,11 +7281,13 @@ cmd_flow_parsed(const struct buffer *in)
 		break;
 	case VALIDATE:
 		port_flow_validate(in->port, &in->args.vc.attr,
-				   in->args.vc.pattern, in->args.vc.actions);
+				   in->args.vc.pattern, in->args.vc.actions,
+				   &in->args.vc.tunnel_ops);
 		break;
 	case CREATE:
 		port_flow_create(in->port, &in->args.vc.attr,
-				 in->args.vc.pattern, in->args.vc.actions);
+				 in->args.vc.pattern, in->args.vc.actions,
+				 &in->args.vc.tunnel_ops);
 		break;
 	case DESTROY:
 		port_flow_destroy(in->port, in->args.destroy.rule_n,
@@ -7160,6 +7313,15 @@ cmd_flow_parsed(const struct buffer *in)
 	case AGED:
 		port_flow_aged(in->port, in->args.aged.destroy);
 		break;
+	case TUNNEL_CREATE:
+		port_flow_tunnel_create(in->port, &in->args.vc.tunnel_ops);
+		break;
+	case TUNNEL_DESTROY:
+		port_flow_tunnel_destroy(in->port, in->args.vc.tunnel_ops.id);
+		break;
+	case TUNNEL_LIST:
+		port_flow_tunnel_list(in->port);
+		break;
 	default:
 		break;
 	}
app/test-pmd/config.c +248 -4

313 lines not on this page · raw message

app/test-pmd/testpmd.c +4 -1
index ccba71c076..93b9e4dde1 100644
@@ -3567,6 +3567,8 @@ init_port_dcb_config(portid_t pid,
 static void
 init_port(void)
 {
+	int i;
+
 	/* Configuration of Ethernet ports. */
 	ports = rte_zmalloc("testpmd: ports",
 			    sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
@@ -3576,7 +3578,8 @@ init_port(void)
 				"rte_zmalloc(%d struct rte_port) failed\n",
 				RTE_MAX_ETHPORTS);
 	}
-
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+		LIST_INIT(&ports[i].flow_tunnel_list);
 	/* Initialize ports NUMA structures */
 	memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
 	memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
app/test-pmd/testpmd.h +32 -2
index a4dfd4fc23..2fc69497f5 100644
@@ -12,6 +12,7 @@
 #include <rte_gro.h>
 #include <rte_gso.h>
 #include <cmdline.h>
+#include <sys/queue.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -150,6 +151,26 @@ struct port_shared_action {
 	struct rte_flow_shared_action *action;	/**< Shared action handle. */
 };
 
+struct port_flow_tunnel {
+	LIST_ENTRY(port_flow_tunnel) chain;
+	struct rte_flow_action *pmd_actions;
+	struct rte_flow_item   *pmd_items;
+	uint32_t id;
+	uint32_t num_pmd_actions;
+	uint32_t num_pmd_items;
+	struct rte_flow_tunnel tunnel;
+	struct rte_flow_action *actions;
+	struct rte_flow_item *items;
+};
+
+struct tunnel_ops {
+	uint32_t id;
+	char type[16];
+	uint32_t enabled:1;
+	uint32_t actions:1;
+	uint32_t items:1;
+};
+
 /**
  * The data structure associated with each port.
  */
@@ -182,6 +203,7 @@ struct rte_port {
 	struct port_flow        *flow_list; /**< Associated flows. */
 	struct port_shared_action *actions_list;
 	/**< Associated shared actions. */
+	LIST_HEAD(, port_flow_tunnel) flow_tunnel_list;
 	const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	/**< metadata value to insert in Tx packets. */
@@ -771,11 +793,13 @@ int port_shared_action_update(portid_t port_id, uint32_t id,
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
-		       const struct rte_flow_action *actions);
+		       const struct rte_flow_action *actions,
+		       const struct tunnel_ops *tunnel_ops);
 int port_flow_create(portid_t port_id,
 		     const struct rte_flow_attr *attr,
 		     const struct rte_flow_item *pattern,
-		     const struct rte_flow_action *actions);
+		     const struct rte_flow_action *actions,
+		     const struct tunnel_ops *tunnel_ops);
 int port_shared_action_query(portid_t port_id, uint32_t id);
 void update_age_action_context(const struct rte_flow_action *actions,
 		     struct port_flow *pf);
@@ -786,6 +810,12 @@ int port_flow_query(portid_t port_id, uint32_t rule,
 		    const struct rte_flow_action *action);
 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
 void port_flow_aged(portid_t port_id, uint8_t destroy);
+const char *port_flow_tunnel_type(struct rte_flow_tunnel *tunnel);
+struct port_flow_tunnel *
+port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun);
+void port_flow_tunnel_list(portid_t port_id);
+void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
+void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops);
 int port_flow_isolate(portid_t port_id, int set);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
app/test-pmd/util.c +33 -2
index 8488fa1a8f..781a813759 100644
@@ -48,18 +48,49 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 	       is_rx ? "received" : "sent",
 	       (unsigned int) nb_pkts);
 	for (i = 0; i < nb_pkts; i++) {
+		int ret;
+		struct rte_flow_error error;
+		struct rte_flow_restore_info info = { 0, };
+
 		mb = pkts[i];
 		eth_hdr = rte_pktmbuf_read(mb, 0, sizeof(_eth_hdr), &_eth_hdr);
 		eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
-		ol_flags = mb->ol_flags;
 		packet_type = mb->packet_type;
 		is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
-
+		ret = rte_flow_get_restore_info(port_id, mb, &info, &error);
+		if (!ret) {
+			printf("restore info:");
+			if (info.flags & RTE_FLOW_RESTORE_INFO_TUNNEL) {
+				struct port_flow_tunnel *port_tunnel;
+
+				port_tunnel = port_flow_locate_tunnel
+					      (port_id, &info.tunnel);
+				printf(" - tunnel");
+				if (port_tunnel)
+					printf(" #%u", port_tunnel->id);
+				else
+					printf(" %s", "-none-");
+				printf(" type %s",
+					port_flow_tunnel_type(&info.tunnel));
+			} else {
+				printf(" - no tunnel info");
+			}
+			if (info.flags & RTE_FLOW_RESTORE_INFO_ENCAPSULATED)
+				printf(" - outer header present");
+			else
+				printf(" - no outer header");
+			if (info.flags & RTE_FLOW_RESTORE_INFO_GROUP_ID)
+				printf(" - miss group %u", info.group_id);
+			else
+				printf(" - no miss group");
+			printf("\n");
+		}
 		print_ether_addr("  src=", &eth_hdr->s_addr);
 		print_ether_addr(" - dst=", &eth_hdr->d_addr);
 		printf(" - type=0x%04x - length=%u - nb_segs=%d",
 		       eth_type, (unsigned int) mb->pkt_len,
 		       (int)mb->nb_segs);
+		ol_flags = mb->ol_flags;
 		if (ol_flags & PKT_RX_RSS_HASH) {
 			printf(" - RSS hash=0x%x", (unsigned int) mb->hash.rss);
 			printf(" - RSS queue=0x%x", (unsigned int) queue);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +49 -0

73 lines not on this page · raw message

Signature · 1 line
2.28.0
#59 lore raw

Re: [dpdk-dev] [PATCH v5 0/3] Tunnel Offload API

In reply to Gregory Etelson
Quoted 23 lines · Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers

    during entire offload procedure;

- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

v2:
* documentation updates
* MLX5 PMD implementation for tunnel offload
* testpmd updates for tunnel offload

v3:
* documentation updates
* MLX5 PMD updates
* testpmd updates

v4:
* updated patch: allow negative values in flow rule types

v5:
* rebase to next-net

Quoted 7 lines

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (2):
ethdev: allow negative values in flow rule types app/testpmd: add commands for tunnel offload API

32 build fails [1], can you please check?

Also there are a few typos [2].

[1]
../app/test-pmd/config.c: In function ‘port_flow_tunnel_list’:
../app/test-pmd/config.c:1580:18: error: format ‘%lu’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘uint64_t’ {aka ‘long long unsigned int’} [-Werror=format=]

1580 |    printf(" id=%lu", flt->tunnel.tun_id);
     |                ~~^   ~~~~~~~~~~~~~~~~~~
     |                  |              |
     |                  |              uint64_t {aka long long unsigned int}
     |                  long unsigned int
     |                %llu

[2]
### ethdev: allow negative values in flow rule types

WARNING:TYPO_SPELLING: 'becase' may be misspelled - perhaps 'because'? #17:
actions do not fit into this scheme becase PMD type values are

total: 0 errors, 1 warnings, 72 lines checked

### app/testpmd: add commands for tunnel offload API

WARNING:TYPO_SPELLING: 'argumens' may be misspelled - perhaps 'arguments'? #87: FILE: app/test-pmd/cmdline_flow.c:79:
+ /* Tunnel argumens. */

#60 lore raw

v6 cover Tunnel Offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

v2:
* documentation updates
* MLX5 PMD implementation for tunnel offload
* testpmd updates for tunnel offload

v3:
* documentation updates
* MLX5 PMD updates
* testpmd updates

v4:
* updated patch: allow negative values in flow rule types

v5:
* rebase to next-net

v6:
* update tunnel offload API documentation

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (2):
ethdev: allow negative values in flow rule types app/testpmd: add commands for tunnel offload API

 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 252 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/prog_guide/rte_flow.rst          |  81 +++++++
 doc/guides/rel_notes/release_20_11.rst      |  10 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 lib/librte_ethdev/rte_ethdev_version.map    |   5 +
 lib/librte_ethdev/rte_flow.c                | 140 ++++++++++-
 lib/librte_ethdev/rte_flow.h                | 195 +++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h         |  32 +++
 12 files changed, 989 insertions(+), 19 deletions(-)
Signature · 1 line
2.28.0
#61 lore raw

PATCH v6 1/3 ethdev: allow negative values in flow rule types

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

RTE flow item or action conversion library accepts positive known element types with predefined sizes only. Private PMD items and actions do not fit into this scheme because PMD type values are negative, each PMD has it's own types numeration and element types and their sizes are not visible at RTE level. To resolve these limitations the patch proposes this solution:
1. PMD can expose elements of pointer size only. RTE flow conversion functions will use pointer size for each configuration object in private PMD element it processes;
2. RTE flow verification will not reject elements with negative type.

---
v4:
* update the 'Negative types' section in the rtre_flow.rst

* update the patch comment

v5:
* rebase to next-net

---
 doc/guides/prog_guide/rte_flow.rst     |  3 +++
 doc/guides/rel_notes/release_20_11.rst |  5 +++++
 lib/librte_ethdev/rte_flow.c           | 28 ++++++++++++++++++++------
 3 files changed, 30 insertions(+), 6 deletions(-)
doc/guides/prog_guide/rte_flow.rst +3 -0
index 6ee0d3a10a..7fb5ec9059 100644
@@ -2775,6 +2775,9 @@ identifiers they are not aware of.
 
 A method to generate them remains to be defined.
 
+Application may use PMD dynamic items or actions in flow rules. In that case
+size of configuration object in dynamic element must be a pointer size.
+
 Planned types
 ~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_11.rst +5 -0
index 79d9ebac4e..9155b468d6 100644
@@ -116,6 +116,11 @@ New Features
   * Updated HWRM structures to 1.10.1.70 version.
   * Added TRUFLOW support for Stingray devices.
 
+* **Flow rules allowed to use private PMD items / actions.**
+
+  * Flow rule verification was updated to accept private PMD
+    items and actions.
+
 * **Updated Cisco enic driver.**
 
   * Added support for VF representors with single-queue Tx/Rx and flow API
lib/librte_ethdev/rte_flow.c +22 -6
index 686fe40eaa..b74ea5593a 100644
@@ -518,7 +518,11 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (int)item->type >= 0 ?
+		      rte_flow_desc_item[item->type].size : sizeof(void *);
 		rte_memcpy(buf, data, (size > off ? off : size));
 		break;
 	}
@@ -621,7 +625,11 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_action[action->type].size;
+		/**
+		 * allow PMD private flow action
+		 */
+		off = (int)action->type >= 0 ?
+		      rte_flow_desc_action[action->type].size : sizeof(void *);
 		rte_memcpy(buf, action->conf, (size > off ? off : size));
 		break;
 	}
@@ -663,8 +671,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-		    !rte_flow_desc_item[src->type].name)
+		/**
+		 * allow PMD private flow item
+		 */
+		if (((int)src->type >= 0) &&
+			((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+		    !rte_flow_desc_item[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
 				 "cannot convert unknown item type");
@@ -752,8 +764,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-		    !rte_flow_desc_action[src->type].name)
+		/**
+		 * allow PMD private flow action
+		 */
+		if (((int)src->type >= 0) &&
+		    ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+		    !rte_flow_desc_action[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
 				 src, "cannot convert unknown action type");
Signature · 1 line
2.28.0
#62 lore raw

PATCH v6 2/3 ethdev: tunnel offload model

In reply to Gregory Etelson

From: Eli Britstein <[email protected]>

rte_flow API provides the building blocks for vendor-agnostic flow classification offloads. The rte_flow "patterns" and "actions" primitives are fine-grained, thus enabling DPDK applications the flexibility to offload network stacks and complex pipelines. Applications wishing to offload tunneled traffic are required to use the rte_flow primitives, such as group, meta, mark, tag, and others to model their high-level objects. The hardware model design for high-level software objects is not trivial. Furthermore, an optimal design is often vendor-specific.

When hardware offloads tunneled traffic in multi-group logic, partially offloaded packets may arrive to the application after they were modified in hardware. In this case, the application may need to restore the original packet headers. Consider the following sequence:
The application decaps a packet in one group and jumps to a second group where it tries to match on a 5-tuple, that will miss and send the packet to the application. In this case, the application does not receive the original packet but a modified one. Also, in this case, the application cannot match on the outer header fields, such as VXLAN vni and 5-tuple.

There are several possible ways to use rte_flow "patterns" and "actions" to resolve the issues above. For example:
1 Mapping headers to a hardware registers using the rte_flow_action_mark/rte_flow_action_tag/rte_flow_set_meta objects. 2 Apply the decap only at the last offload stage after all the "patterns" were matched and the packet will be fully offloaded. Every approach has its pros and cons and is highly dependent on the hardware vendor. For example, some hardware may have a limited number of registers while other hardware could not support inner actions and must decap before accessing inner headers.

The tunnel offload model resolves these issues. The model goals are:
1 Provide a unified application API to offload tunneled traffic that is capable to match on outer headers after decap.
2 Allow the application to restore the outer header of partially offloaded packets.

The tunnel offload model does not introduce new elements to the existing RTE flow model and is implemented as a set of helper functions.

For the application to work with the tunnel offload API it has to adjust flow rules in multi-table tunnel offload in the following way:
1 Remove explicit call to decap action and replace it with PMD actions obtained from rte_flow_tunnel_decap_and_set() helper.
2 Add PMD items obtained from rte_flow_tunnel_match() helper to all other rules in the tunnel offload sequence.

VXLAN Code example:

Assume application needs to do inner NAT on the VXLAN packet. The first rule in group 0:

flow create <port id> ingress group 0
pattern eth / ipv4 / udp dst is 4789 / vxlan / end actions {pmd actions} / jump group 3 / end

The first VXLAN packet that arrives matches the rule in group 0 and jumps to group 3. In group 3 the packet will miss since there is no flow to match and will be sent to the application. Application will call rte_flow_get_restore_info() to get the packet outer header.

Application will insert a new rule in group 3 to match outer and inner headers:

flow create <port id> ingress group 3
pattern {pmd items} / eth / ipv4 dst is 172.10.10.1 /
udp dst 4789 / vxlan vni is 10 /
ipv4 dst is 184.1.2.3 / end
actions set_ipv4_dst 186.1.1.1 / queue index 3 / end

Resulting of the rules will be that VXLAN packet with vni=10, outer IPv4 dst=172.10.10.1 and inner IPv4 dst=184.1.2.3 will be received decapped on queue 3 with IPv4 dst=186.1.1.1

Note: The packet in group 3 is considered decapped. All actions in that group will be done on the header that was inner before decap. The application may specify an outer header to be matched on. It's PMD responsibility to translate these items to outer metadata.

API usage:

/**
* 1. Initiate RTE flow tunnel object
*/
const struct rte_flow_tunnel tunnel = {
.type = RTE_FLOW_ITEM_TYPE_VXLAN,
.tun_id = 10,
}

/**
* 2. Obtain PMD tunnel actions
*
* pmd_actions is an intermediate variable application uses to
* compile actions array
*/
struct rte_flow_action **pmd_actions; rte_flow_tunnel_decap_and_set(&tunnel, &pmd_actions,

                              &num_pmd_actions, &error);

/**
* 3. offload the first rule
* matching on VXLAN traffic and jumps to group 3
* (implicitly decaps packet)
*/
app_actions = jump group 3
rule_items = app_items; /** eth / ipv4 / udp / vxlan */ rule_actions = { pmd_actions, app_actions }; attr.group = 0;
flow_1 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 4. after flow creation application does not need to keep the
* tunnel action resources.
*/
rte_flow_tunnel_action_release(port_id, pmd_actions,

                               num_pmd_actions);

/**
* 5. After partially offloaded packet miss because there was no
* matching rule handle miss on group 3
*/
struct rte_flow_restore_info info; rte_flow_get_restore_info(port_id, mbuf, &info, &error);

/**
* 6. Offload NAT rule:
*/
app_items = { eth / ipv4 dst is 172.10.10.1 / udp dst 4789 /

            vxlan vni is 10 / ipv4 dst is 184.1.2.3 }

app_actions = { set_ipv4_dst 186.1.1.1 / queue index 3 }

rte_flow_tunnel_match(&info.tunnel, &pmd_items,

                      &num_pmd_items,  &error);

rule_items = {pmd_items, app_items};
rule_actions = app_actions;
attr.group = info.group_id;
flow_2 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 7. Release PMD items after rule creation
*/
rte_flow_tunnel_item_release(port_id,

                             pmd_items, num_pmd_items);

References
1. https://mails.dpdk.org/archives/dev/2020-June/index.html

---
v5:
* rebase to next-net

v6:
* update the patch comment
* update tunnel offload section in rte_flow.rst

---
 doc/guides/prog_guide/rte_flow.rst       |  78 +++++++++
 doc/guides/rel_notes/release_20_11.rst   |   5 +
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 195 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 6 files changed, 427 insertions(+)
doc/guides/prog_guide/rte_flow.rst +78 -0
index 7fb5ec9059..8dc048c6f4 100644
@@ -3131,6 +3131,84 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+rte_flow API provides the building blocks for vendor-agnostic flow
+classification offloads. The rte_flow "patterns" and "actions"
+primitives are fine-grained, thus enabling DPDK applications the
+flexibility to offload network stacks and complex pipelines.
+Applications wishing to offload tunneled traffic are required to use
+the rte_flow primitives, such as group, meta, mark, tag, and others to
+model their high-level objects.  The hardware model design for
+high-level software objects is not trivial.  Furthermore, an optimal
+design is often vendor-specific.
+
+When hardware offloads tunneled traffic in multi-group logic,
+partially offloaded packets may arrive to the application after they
+were modified in hardware. In this case, the application may need to
+restore the original packet headers. Consider the following sequence:
+The application decaps a packet in one group and jumps to a second
+group where it tries to match on a 5-tuple, that will miss and send
+the packet to the application. In this case, the application does not
+receive the original packet but a modified one. Also, in this case,
+the application cannot match on the outer header fields, such as VXLAN
+vni and 5-tuple.
+
+There are several possible ways to use rte_flow "patterns" and
+"actions" to resolve the issues above. For example:
+
+1 Mapping headers to a hardware registers using the
+rte_flow_action_mark/rte_flow_action_tag/rte_flow_set_meta objects.
+
+2 Apply the decap only at the last offload stage after all the
+"patterns" were matched and the packet will be fully offloaded.
+
+Every approach has its pros and cons and is highly dependent on the
+hardware vendor.  For example, some hardware may have a limited number
+of registers while other hardware could not support inner actions and
+must decap before accessing inner headers.
+
+The tunnel offload model resolves these issues. The model goals are:
+
+1 Provide a unified application API to offload tunneled traffic that
+is capable to match on outer headers after decap.
+
+2 Allow the application to restore the outer header of partially
+offloaded packets.
+
+The tunnel offload model does not introduce new elements to the
+existing RTE flow model and is implemented as a set of helper
+functions.
+
+For the application to work with the tunnel offload API it
+has to adjust flow rules in multi-table tunnel offload in the
+following way:
+
+1 Remove explicit call to decap action and replace it with PMD actions
+obtained from rte_flow_tunnel_decap_and_set() helper.
+
+2 Add PMD items obtained from rte_flow_tunnel_match() helper to all
+other rules in the tunnel offload sequence.
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release PMD items and actions after rule was created. However, if the
+application needs to create additional rule for the same tunnel it
+will need to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
 
doc/guides/rel_notes/release_20_11.rst +5 -0
index 9155b468d6..f125ce79dd 100644
@@ -121,6 +121,11 @@ New Features
   * Flow rule verification was updated to accept private PMD
     items and actions.
 
+* **Added generic API to offload tunneled traffic and restore missed packet.**
+
+  * Added a new hardware independent helper API to RTE flow library that
+    offloads tunneled traffic and restores missed packets.
+
 * **Updated Cisco enic driver.**
 
   * Added support for VF representors with single-queue Tx/Rx and flow API
lib/librte_ethdev/rte_ethdev_version.map +5 -0
index f64c379ac2..8ddda2547f 100644
@@ -239,6 +239,11 @@ EXPERIMENTAL {
 	rte_flow_shared_action_destroy;
 	rte_flow_shared_action_query;
 	rte_flow_shared_action_update;
+	rte_flow_tunnel_decap_set;
+	rte_flow_tunnel_match;
+	rte_flow_get_restore_info;
+	rte_flow_tunnel_action_decap_release;
+	rte_flow_tunnel_item_release;
 };
 
 INTERNAL {
lib/librte_ethdev/rte_flow.c +112 -0

115 lines not on this page · raw message

lib/librte_ethdev/rte_flow.h +195 -0

201 lines not on this page · raw message

lib/librte_ethdev/rte_flow_driver.h +32 -0
index 58f56b0262..bd5ffc0bb1 100644
@@ -131,6 +131,38 @@ struct rte_flow_ops {
 		 const struct rte_flow_shared_action *shared_action,
 		 void *data,
 		 struct rte_flow_error *error);
+	/** See rte_flow_tunnel_decap_set() */
+	int (*tunnel_decap_set)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_action **pmd_actions,
+		 uint32_t *num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_match() */
+	int (*tunnel_match)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_item **pmd_items,
+		 uint32_t *num_of_items,
+		 struct rte_flow_error *err);
+	/** See rte_flow_get_rte_flow_restore_info() */
+	int (*get_restore_info)
+		(struct rte_eth_dev *dev,
+		 struct rte_mbuf *m,
+		 struct rte_flow_restore_info *info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_action_tunnel_decap_release() */
+	int (*action_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_action *pmd_actions,
+		 uint32_t num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_item_release() */
+	int (*item_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_item *pmd_items,
+		 uint32_t num_of_items,
+		 struct rte_flow_error *err);
 };
 
 /**
Signature · 1 line
2.28.0
#63 lore raw

PATCH v6 3/3 app/testpmd: add commands for tunnel offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:

* Create application tunnel:
flow tunnel create <port> type <tunnel type>
On success, the command creates application tunnel object and returns the tunnel descriptor. Tunnel descriptor is used in subsequent flow creation commands to reference the tunnel.

* Create tunnel steering flow rule:
tunnel_set <tunnel descriptor> parameter used with steering rule template.

* Create tunnel matching flow rule:
tunnel_match <tunnel descriptor> used with matching rule template.

* If tunnel steering rule was offloaded, outer header of a partially offloaded packet is restored after miss.

Example:
test packet=
<Ether dst=24:8a:07:8d:ae:d6 src=50:6b:4b:cc:fc:e2 type=IPv4 | <IP version=4 ihl=5 proto=udp src=1.1.1.1 dst=1.1.1.10 | <UDP sport=4789 dport=4789 len=58 chksum=0x7f7b |
<VXLAN NextProtocol=Ethernet vni=0x0 |
<Ether dst=24:aa:aa:aa:aa:d6 src=50:bb:bb:bb:bb:e2 type=IPv4 | <IP version=4 ihl=5 proto=icmp src=2.2.2.2 dst=2.2.2.200 | <ICMP type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>>>>>

Quoted 1 line
Quoted 1 line
Quoted 1 line

len(packet)

92

testpmd> flow flush 0
testpmd> port 0/queue 0: received 1 packets src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 - length=92

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end
Flow rule #0 created
testpmd> port 0/queue 0: received 1 packets
tunnel restore info: - vxlan tunnel - outer header present # <--
src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 -
length=92

testpmd> flow create 0 ingress group 0 tunnel_match 1
pattern eth / ipv4 / udp dst is 4789 / vxlan / eth / ipv4 / end
actions set_mac_dst mac_addr 02:CA:FE:CA:FA:80 / queue index 0 / end
Flow rule #1 created
testpmd> port 0/queue 0: received 1 packets
src=50:BB:BB:BB:BB:E2 - dst=02:CA:FE:CA:FA:80 - type=0x0800 -
length=42

* Destroy flow tunnel
flow tunnel destroy <port> id <tunnel id>

* Show existing flow tunnels
flow tunnel list <port>

---
v2:
* introduce testpmd support for tunnel offload API

v3:
* update flow tunnel commands

v5:
* rebase to next-net

---
 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 252 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 6 files changed, 532 insertions(+), 13 deletions(-)
app/test-pmd/cmdline_flow.c +166 -4
index 00c70a144a..b9a1f7178a 100644
@@ -74,6 +74,14 @@ enum index {
 	LIST,
 	AGED,
 	ISOLATE,
+	TUNNEL,
+
+	/* Tunnel arguments. */
+	TUNNEL_CREATE,
+	TUNNEL_CREATE_TYPE,
+	TUNNEL_LIST,
+	TUNNEL_DESTROY,
+	TUNNEL_DESTROY_ID,
 
 	/* Destroy arguments. */
 	DESTROY_RULE,
@@ -93,6 +101,8 @@ enum index {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 
 	/* Shared action arguments */
 	SHARED_ACTION_CREATE,
@@ -713,6 +723,7 @@ struct buffer {
 		} sa; /* Shared action query arguments */
 		struct {
 			struct rte_flow_attr attr;
+			struct tunnel_ops tunnel_ops;
 			struct rte_flow_item *pattern;
 			struct rte_flow_action *actions;
 			uint32_t pattern_n;
@@ -789,10 +800,32 @@ static const enum index next_vc_attr[] = {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 	PATTERN,
 	ZERO,
 };
 
+static const enum index tunnel_create_attr[] = {
+	TUNNEL_CREATE,
+	TUNNEL_CREATE_TYPE,
+	END,
+	ZERO,
+};
+
+static const enum index tunnel_destroy_attr[] = {
+	TUNNEL_DESTROY,
+	TUNNEL_DESTROY_ID,
+	END,
+	ZERO,
+};
+
+static const enum index tunnel_list_attr[] = {
+	TUNNEL_LIST,
+	END,
+	ZERO,
+};
+
 static const enum index next_destroy_attr[] = {
 	DESTROY_RULE,
 	END,
@@ -1643,6 +1676,9 @@ static int parse_aged(struct context *, const struct token *,
 static int parse_isolate(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
+static int parse_tunnel(struct context *, const struct token *,
+			const char *, unsigned int,
+			void *, unsigned int);
 static int parse_int(struct context *, const struct token *,
 		     const char *, unsigned int,
 		     void *, unsigned int);
@@ -1844,7 +1880,8 @@ static const struct token token_list[] = {
 			      LIST,
 			      AGED,
 			      QUERY,
-			      ISOLATE)),
+			      ISOLATE,
+			      TUNNEL)),
 		.call = parse_init,
 	},
 	/* Top-level command. */
@@ -1955,6 +1992,49 @@ static const struct token token_list[] = {
 			     ARGS_ENTRY(struct buffer, port)),
 		.call = parse_isolate,
 	},
+	[TUNNEL] = {
+		.name = "tunnel",
+		.help = "new tunnel API",
+		.next = NEXT(NEXT_ENTRY
+			     (TUNNEL_CREATE, TUNNEL_LIST, TUNNEL_DESTROY)),
+		.call = parse_tunnel,
+	},
+	/* Tunnel arguments. */
+	[TUNNEL_CREATE] = {
+		.name = "create",
+		.help = "create new tunnel object",
+		.next = NEXT(tunnel_create_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_CREATE_TYPE] = {
+		.name = "type",
+		.help = "create new tunnel",
+		.next = NEXT(tunnel_create_attr, NEXT_ENTRY(FILE_PATH)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, type)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy tunel",
+		.next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_DESTROY_ID] = {
+		.name = "id",
+		.help = "tunnel identifier to testroy",
+		.next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_LIST] = {
+		.name = "list",
+		.help = "list existing tunnels",
+		.next = NEXT(tunnel_list_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
 	/* Destroy arguments. */
 	[DESTROY_RULE] = {
 		.name = "rule",
@@ -2018,6 +2098,20 @@ static const struct token token_list[] = {
 		.next = NEXT(next_vc_attr),
 		.call = parse_vc,
 	},
+	[TUNNEL_SET] = {
+		.name = "tunnel_set",
+		.help = "tunnel steer rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
+	[TUNNEL_MATCH] = {
+		.name = "tunnel_match",
+		.help = "tunnel match rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
 	/* Validate/create pattern. */
 	[PATTERN] = {
 		.name = "pattern",
@@ -4495,12 +4589,28 @@ parse_vc(struct context *ctx, const struct token *token,
 		return len;
 	}
 	ctx->objdata = 0;
-	ctx->object = &out->args.vc.attr;
+	switch (ctx->curr) {
+	default:
+		ctx->object = &out->args.vc.attr;
+		break;
+	case TUNNEL_SET:
+	case TUNNEL_MATCH:
+		ctx->object = &out->args.vc.tunnel_ops;
+		break;
+	}
 	ctx->objmask = NULL;
 	switch (ctx->curr) {
 	case GROUP:
 	case PRIORITY:
 		return len;
+	case TUNNEL_SET:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.actions = 1;
+		return len;
+	case TUNNEL_MATCH:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.items = 1;
+		return len;
 	case INGRESS:
 		out->args.vc.attr.ingress = 1;
 		return len;
@@ -6108,6 +6218,47 @@ parse_isolate(struct context *ctx, const struct token *token,
 	return len;
 }
 
+static int
+parse_tunnel(struct context *ctx, const struct token *token,
+	     const char *str, unsigned int len,
+	     void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != TUNNEL)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+	} else {
+		switch (ctx->curr) {
+		default:
+			break;
+		case TUNNEL_CREATE:
+		case TUNNEL_DESTROY:
+		case TUNNEL_LIST:
+			out->command = ctx->curr;
+			break;
+		case TUNNEL_CREATE_TYPE:
+		case TUNNEL_DESTROY_ID:
+			ctx->object = &out->args.vc.tunnel_ops;
+			break;
+		}
+	}
+
+	return len;
+}
+
 /**
  * Parse signed/unsigned integers 8 to 64-bit long.
  *
@@ -7148,11 +7299,13 @@ cmd_flow_parsed(const struct buffer *in)
 		break;
 	case VALIDATE:
 		port_flow_validate(in->port, &in->args.vc.attr,
-				   in->args.vc.pattern, in->args.vc.actions);
+				   in->args.vc.pattern, in->args.vc.actions,
+				   &in->args.vc.tunnel_ops);
 		break;
 	case CREATE:
 		port_flow_create(in->port, &in->args.vc.attr,
-				 in->args.vc.pattern, in->args.vc.actions);
+				 in->args.vc.pattern, in->args.vc.actions,
+				 &in->args.vc.tunnel_ops);
 		break;
 	case DESTROY:
 		port_flow_destroy(in->port, in->args.destroy.rule_n,
@@ -7178,6 +7331,15 @@ cmd_flow_parsed(const struct buffer *in)
 	case AGED:
 		port_flow_aged(in->port, in->args.aged.destroy);
 		break;
+	case TUNNEL_CREATE:
+		port_flow_tunnel_create(in->port, &in->args.vc.tunnel_ops);
+		break;
+	case TUNNEL_DESTROY:
+		port_flow_tunnel_destroy(in->port, in->args.vc.tunnel_ops.id);
+		break;
+	case TUNNEL_LIST:
+		port_flow_tunnel_list(in->port);
+		break;
 	default:
 		break;
 	}
app/test-pmd/config.c +248 -4

313 lines not on this page · raw message

app/test-pmd/testpmd.c +4 -1
index 6caba60988..333904d686 100644
@@ -3684,6 +3684,8 @@ init_port_dcb_config(portid_t pid,
 static void
 init_port(void)
 {
+	int i;
+
 	/* Configuration of Ethernet ports. */
 	ports = rte_zmalloc("testpmd: ports",
 			    sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
@@ -3693,7 +3695,8 @@ init_port(void)
 				"rte_zmalloc(%d struct rte_port) failed\n",
 				RTE_MAX_ETHPORTS);
 	}
-
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+		LIST_INIT(&ports[i].flow_tunnel_list);
 	/* Initialize ports NUMA structures */
 	memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
 	memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
app/test-pmd/testpmd.h +32 -2
index f8b0a3517d..5238ac3dd5 100644
@@ -12,6 +12,7 @@
 #include <rte_gro.h>
 #include <rte_gso.h>
 #include <cmdline.h>
+#include <sys/queue.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -150,6 +151,26 @@ struct port_shared_action {
 	struct rte_flow_shared_action *action;	/**< Shared action handle. */
 };
 
+struct port_flow_tunnel {
+	LIST_ENTRY(port_flow_tunnel) chain;
+	struct rte_flow_action *pmd_actions;
+	struct rte_flow_item   *pmd_items;
+	uint32_t id;
+	uint32_t num_pmd_actions;
+	uint32_t num_pmd_items;
+	struct rte_flow_tunnel tunnel;
+	struct rte_flow_action *actions;
+	struct rte_flow_item *items;
+};
+
+struct tunnel_ops {
+	uint32_t id;
+	char type[16];
+	uint32_t enabled:1;
+	uint32_t actions:1;
+	uint32_t items:1;
+};
+
 /**
  * The data structure associated with each port.
  */
@@ -182,6 +203,7 @@ struct rte_port {
 	struct port_flow        *flow_list; /**< Associated flows. */
 	struct port_shared_action *actions_list;
 	/**< Associated shared actions. */
+	LIST_HEAD(, port_flow_tunnel) flow_tunnel_list;
 	const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	/**< metadata value to insert in Tx packets. */
@@ -773,11 +795,13 @@ int port_shared_action_update(portid_t port_id, uint32_t id,
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
-		       const struct rte_flow_action *actions);
+		       const struct rte_flow_action *actions,
+		       const struct tunnel_ops *tunnel_ops);
 int port_flow_create(portid_t port_id,
 		     const struct rte_flow_attr *attr,
 		     const struct rte_flow_item *pattern,
-		     const struct rte_flow_action *actions);
+		     const struct rte_flow_action *actions,
+		     const struct tunnel_ops *tunnel_ops);
 int port_shared_action_query(portid_t port_id, uint32_t id);
 void update_age_action_context(const struct rte_flow_action *actions,
 		     struct port_flow *pf);
@@ -788,6 +812,12 @@ int port_flow_query(portid_t port_id, uint32_t rule,
 		    const struct rte_flow_action *action);
 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
 void port_flow_aged(portid_t port_id, uint8_t destroy);
+const char *port_flow_tunnel_type(struct rte_flow_tunnel *tunnel);
+struct port_flow_tunnel *
+port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun);
+void port_flow_tunnel_list(portid_t port_id);
+void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
+void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops);
 int port_flow_isolate(portid_t port_id, int set);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
app/test-pmd/util.c +33 -2
index 8488fa1a8f..781a813759 100644
@@ -48,18 +48,49 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 	       is_rx ? "received" : "sent",
 	       (unsigned int) nb_pkts);
 	for (i = 0; i < nb_pkts; i++) {
+		int ret;
+		struct rte_flow_error error;
+		struct rte_flow_restore_info info = { 0, };
+
 		mb = pkts[i];
 		eth_hdr = rte_pktmbuf_read(mb, 0, sizeof(_eth_hdr), &_eth_hdr);
 		eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
-		ol_flags = mb->ol_flags;
 		packet_type = mb->packet_type;
 		is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
-
+		ret = rte_flow_get_restore_info(port_id, mb, &info, &error);
+		if (!ret) {
+			printf("restore info:");
+			if (info.flags & RTE_FLOW_RESTORE_INFO_TUNNEL) {
+				struct port_flow_tunnel *port_tunnel;
+
+				port_tunnel = port_flow_locate_tunnel
+					      (port_id, &info.tunnel);
+				printf(" - tunnel");
+				if (port_tunnel)
+					printf(" #%u", port_tunnel->id);
+				else
+					printf(" %s", "-none-");
+				printf(" type %s",
+					port_flow_tunnel_type(&info.tunnel));
+			} else {
+				printf(" - no tunnel info");
+			}
+			if (info.flags & RTE_FLOW_RESTORE_INFO_ENCAPSULATED)
+				printf(" - outer header present");
+			else
+				printf(" - no outer header");
+			if (info.flags & RTE_FLOW_RESTORE_INFO_GROUP_ID)
+				printf(" - miss group %u", info.group_id);
+			else
+				printf(" - no miss group");
+			printf("\n");
+		}
 		print_ether_addr("  src=", &eth_hdr->s_addr);
 		print_ether_addr(" - dst=", &eth_hdr->d_addr);
 		printf(" - type=0x%04x - length=%u - nb_segs=%d",
 		       eth_type, (unsigned int) mb->pkt_len,
 		       (int)mb->nb_segs);
+		ol_flags = mb->ol_flags;
 		if (ol_flags & PKT_RX_RSS_HASH) {
 			printf(" - RSS hash=0x%x", (unsigned int) mb->hash.rss);
 			printf(" - RSS queue=0x%x", (unsigned int) queue);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +49 -0

73 lines not on this page · raw message

Signature · 1 line
2.28.0
#64 lore raw

v7 cover Tunnel Offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

v2:
* documentation updates
* MLX5 PMD implementation for tunnel offload
* testpmd updates for tunnel offload

v3:
* documentation updates
* MLX5 PMD updates
* testpmd updates

v4:
* updated patch: allow negative values in flow rule types

v5:
* rebase to next-net

v6:
* update tunnel offload API documentation

v7:
* testpmd: resolve "%lu" differences in ubuntu 32 & 64

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (2):
ethdev: allow negative values in flow rule types app/testpmd: add commands for tunnel offload API

 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 252 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/prog_guide/rte_flow.rst          |  81 +++++++
 doc/guides/rel_notes/release_20_11.rst      |  10 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 lib/librte_ethdev/rte_ethdev_version.map    |   5 +
 lib/librte_ethdev/rte_flow.c                | 140 ++++++++++-
 lib/librte_ethdev/rte_flow.h                | 195 +++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h         |  32 +++
 12 files changed, 989 insertions(+), 19 deletions(-)
Signature · 1 line
2.28.0
#65 lore raw

PATCH v7 1/3 ethdev: allow negative values in flow rule types

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

RTE flow item or action conversion library accepts positive known element types with predefined sizes only. Private PMD items and actions do not fit into this scheme becase PMD type values are negative, each PMD has it's own types numeration and element types and their sizes are not visible at RTE level. To resolve these limitations the patch proposes this solution:
1. PMD can expose elements of pointer size only. RTE flow conversion functions will use pointer size for each configuration object in private PMD element it processes;
2. RTE flow verification will not reject elements with negative type.

---
v4:
* update the 'Negative types' section in the rtre_flow.rst

* update the patch comment

v5:
* rebase to next-net

---
 doc/guides/prog_guide/rte_flow.rst     |  3 +++
 doc/guides/rel_notes/release_20_11.rst |  5 +++++
 lib/librte_ethdev/rte_flow.c           | 28 ++++++++++++++++++++------
 3 files changed, 30 insertions(+), 6 deletions(-)
doc/guides/prog_guide/rte_flow.rst +3 -0
index 6ee0d3a10a..7fb5ec9059 100644
@@ -2775,6 +2775,9 @@ identifiers they are not aware of.
 
 A method to generate them remains to be defined.
 
+Application may use PMD dynamic items or actions in flow rules. In that case
+size of configuration object in dynamic element must be a pointer size.
+
 Planned types
 ~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_11.rst +5 -0
index 79d9ebac4e..9155b468d6 100644
@@ -116,6 +116,11 @@ New Features
   * Updated HWRM structures to 1.10.1.70 version.
   * Added TRUFLOW support for Stingray devices.
 
+* **Flow rules allowed to use private PMD items / actions.**
+
+  * Flow rule verification was updated to accept private PMD
+    items and actions.
+
 * **Updated Cisco enic driver.**
 
   * Added support for VF representors with single-queue Tx/Rx and flow API
lib/librte_ethdev/rte_flow.c +22 -6
index 686fe40eaa..b74ea5593a 100644
@@ -518,7 +518,11 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (int)item->type >= 0 ?
+		      rte_flow_desc_item[item->type].size : sizeof(void *);
 		rte_memcpy(buf, data, (size > off ? off : size));
 		break;
 	}
@@ -621,7 +625,11 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_action[action->type].size;
+		/**
+		 * allow PMD private flow action
+		 */
+		off = (int)action->type >= 0 ?
+		      rte_flow_desc_action[action->type].size : sizeof(void *);
 		rte_memcpy(buf, action->conf, (size > off ? off : size));
 		break;
 	}
@@ -663,8 +671,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-		    !rte_flow_desc_item[src->type].name)
+		/**
+		 * allow PMD private flow item
+		 */
+		if (((int)src->type >= 0) &&
+			((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+		    !rte_flow_desc_item[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
 				 "cannot convert unknown item type");
@@ -752,8 +764,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-		    !rte_flow_desc_action[src->type].name)
+		/**
+		 * allow PMD private flow action
+		 */
+		if (((int)src->type >= 0) &&
+		    ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+		    !rte_flow_desc_action[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
 				 src, "cannot convert unknown action type");
Signature · 1 line
2.28.0
#66 lore raw

PATCH v7 2/3 ethdev: tunnel offload model

In reply to Gregory Etelson

From: Eli Britstein <[email protected]>

rte_flow API provides the building blocks for vendor-agnostic flow classification offloads. The rte_flow "patterns" and "actions" primitives are fine-grained, thus enabling DPDK applications the flexibility to offload network stacks and complex pipelines. Applications wishing to offload tunneled traffic are required to use the rte_flow primitives, such as group, meta, mark, tag, and others to model their high-level objects. The hardware model design for high-level software objects is not trivial. Furthermore, an optimal design is often vendor-specific.

When hardware offloads tunneled traffic in multi-group logic, partially offloaded packets may arrive to the application after they were modified in hardware. In this case, the application may need to restore the original packet headers. Consider the following sequence:
The application decaps a packet in one group and jumps to a second group where it tries to match on a 5-tuple, that will miss and send the packet to the application. In this case, the application does not receive the original packet but a modified one. Also, in this case, the application cannot match on the outer header fields, such as VXLAN vni and 5-tuple.

There are several possible ways to use rte_flow "patterns" and "actions" to resolve the issues above. For example:
1 Mapping headers to a hardware registers using the rte_flow_action_mark/rte_flow_action_tag/rte_flow_set_meta objects. 2 Apply the decap only at the last offload stage after all the "patterns" were matched and the packet will be fully offloaded. Every approach has its pros and cons and is highly dependent on the hardware vendor. For example, some hardware may have a limited number of registers while other hardware could not support inner actions and must decap before accessing inner headers.

The tunnel offload model resolves these issues. The model goals are:
1 Provide a unified application API to offload tunneled traffic that is capable to match on outer headers after decap.
2 Allow the application to restore the outer header of partially offloaded packets.

The tunnel offload model does not introduce new elements to the existing RTE flow model and is implemented as a set of helper functions.

For the application to work with the tunnel offload API it has to adjust flow rules in multi-table tunnel offload in the following way:
1 Remove explicit call to decap action and replace it with PMD actions obtained from rte_flow_tunnel_decap_and_set() helper.
2 Add PMD items obtained from rte_flow_tunnel_match() helper to all other rules in the tunnel offload sequence.

VXLAN Code example:

Assume application needs to do inner NAT on the VXLAN packet. The first rule in group 0:

flow create <port id> ingress group 0
pattern eth / ipv4 / udp dst is 4789 / vxlan / end actions {pmd actions} / jump group 3 / end

The first VXLAN packet that arrives matches the rule in group 0 and jumps to group 3. In group 3 the packet will miss since there is no flow to match and will be sent to the application. Application will call rte_flow_get_restore_info() to get the packet outer header.

Application will insert a new rule in group 3 to match outer and inner headers:

flow create <port id> ingress group 3
pattern {pmd items} / eth / ipv4 dst is 172.10.10.1 /
udp dst 4789 / vxlan vni is 10 /
ipv4 dst is 184.1.2.3 / end
actions set_ipv4_dst 186.1.1.1 / queue index 3 / end

Resulting of the rules will be that VXLAN packet with vni=10, outer IPv4 dst=172.10.10.1 and inner IPv4 dst=184.1.2.3 will be received decapped on queue 3 with IPv4 dst=186.1.1.1

Note: The packet in group 3 is considered decapped. All actions in that group will be done on the header that was inner before decap. The application may specify an outer header to be matched on. It's PMD responsibility to translate these items to outer metadata.

API usage:

/**
* 1. Initiate RTE flow tunnel object
*/
const struct rte_flow_tunnel tunnel = {
.type = RTE_FLOW_ITEM_TYPE_VXLAN,
.tun_id = 10,
}

/**
* 2. Obtain PMD tunnel actions
*
* pmd_actions is an intermediate variable application uses to
* compile actions array
*/
struct rte_flow_action **pmd_actions; rte_flow_tunnel_decap_and_set(&tunnel, &pmd_actions,

                              &num_pmd_actions, &error);

/**
* 3. offload the first rule
* matching on VXLAN traffic and jumps to group 3
* (implicitly decaps packet)
*/
app_actions = jump group 3
rule_items = app_items; /** eth / ipv4 / udp / vxlan */ rule_actions = { pmd_actions, app_actions }; attr.group = 0;
flow_1 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 4. after flow creation application does not need to keep the
* tunnel action resources.
*/
rte_flow_tunnel_action_release(port_id, pmd_actions,

                               num_pmd_actions);

/**
* 5. After partially offloaded packet miss because there was no
* matching rule handle miss on group 3
*/
struct rte_flow_restore_info info; rte_flow_get_restore_info(port_id, mbuf, &info, &error);

/**
* 6. Offload NAT rule:
*/
app_items = { eth / ipv4 dst is 172.10.10.1 / udp dst 4789 /

            vxlan vni is 10 / ipv4 dst is 184.1.2.3 }

app_actions = { set_ipv4_dst 186.1.1.1 / queue index 3 }

rte_flow_tunnel_match(&info.tunnel, &pmd_items,

                      &num_pmd_items,  &error);

rule_items = {pmd_items, app_items};
rule_actions = app_actions;
attr.group = info.group_id;
flow_2 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 7. Release PMD items after rule creation
*/
rte_flow_tunnel_item_release(port_id,

                             pmd_items, num_pmd_items);

References
1. https://mails.dpdk.org/archives/dev/2020-June/index.html

---
v5:
* rebase to next-net

v6:
* update the patch comment
* update tunnel offload section in rte_flow.rst

---
 doc/guides/prog_guide/rte_flow.rst       |  78 +++++++++
 doc/guides/rel_notes/release_20_11.rst   |   5 +
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 195 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 6 files changed, 427 insertions(+)
doc/guides/prog_guide/rte_flow.rst +78 -0
index 7fb5ec9059..8dc048c6f4 100644
@@ -3131,6 +3131,84 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+rte_flow API provides the building blocks for vendor-agnostic flow
+classification offloads. The rte_flow "patterns" and "actions"
+primitives are fine-grained, thus enabling DPDK applications the
+flexibility to offload network stacks and complex pipelines.
+Applications wishing to offload tunneled traffic are required to use
+the rte_flow primitives, such as group, meta, mark, tag, and others to
+model their high-level objects.  The hardware model design for
+high-level software objects is not trivial.  Furthermore, an optimal
+design is often vendor-specific.
+
+When hardware offloads tunneled traffic in multi-group logic,
+partially offloaded packets may arrive to the application after they
+were modified in hardware. In this case, the application may need to
+restore the original packet headers. Consider the following sequence:
+The application decaps a packet in one group and jumps to a second
+group where it tries to match on a 5-tuple, that will miss and send
+the packet to the application. In this case, the application does not
+receive the original packet but a modified one. Also, in this case,
+the application cannot match on the outer header fields, such as VXLAN
+vni and 5-tuple.
+
+There are several possible ways to use rte_flow "patterns" and
+"actions" to resolve the issues above. For example:
+
+1 Mapping headers to a hardware registers using the
+rte_flow_action_mark/rte_flow_action_tag/rte_flow_set_meta objects.
+
+2 Apply the decap only at the last offload stage after all the
+"patterns" were matched and the packet will be fully offloaded.
+
+Every approach has its pros and cons and is highly dependent on the
+hardware vendor.  For example, some hardware may have a limited number
+of registers while other hardware could not support inner actions and
+must decap before accessing inner headers.
+
+The tunnel offload model resolves these issues. The model goals are:
+
+1 Provide a unified application API to offload tunneled traffic that
+is capable to match on outer headers after decap.
+
+2 Allow the application to restore the outer header of partially
+offloaded packets.
+
+The tunnel offload model does not introduce new elements to the
+existing RTE flow model and is implemented as a set of helper
+functions.
+
+For the application to work with the tunnel offload API it
+has to adjust flow rules in multi-table tunnel offload in the
+following way:
+
+1 Remove explicit call to decap action and replace it with PMD actions
+obtained from rte_flow_tunnel_decap_and_set() helper.
+
+2 Add PMD items obtained from rte_flow_tunnel_match() helper to all
+other rules in the tunnel offload sequence.
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release PMD items and actions after rule was created. However, if the
+application needs to create additional rule for the same tunnel it
+will need to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
 
doc/guides/rel_notes/release_20_11.rst +5 -0
index 9155b468d6..f125ce79dd 100644
@@ -121,6 +121,11 @@ New Features
   * Flow rule verification was updated to accept private PMD
     items and actions.
 
+* **Added generic API to offload tunneled traffic and restore missed packet.**
+
+  * Added a new hardware independent helper API to RTE flow library that
+    offloads tunneled traffic and restores missed packets.
+
 * **Updated Cisco enic driver.**
 
   * Added support for VF representors with single-queue Tx/Rx and flow API
lib/librte_ethdev/rte_ethdev_version.map +5 -0
index f64c379ac2..8ddda2547f 100644
@@ -239,6 +239,11 @@ EXPERIMENTAL {
 	rte_flow_shared_action_destroy;
 	rte_flow_shared_action_query;
 	rte_flow_shared_action_update;
+	rte_flow_tunnel_decap_set;
+	rte_flow_tunnel_match;
+	rte_flow_get_restore_info;
+	rte_flow_tunnel_action_decap_release;
+	rte_flow_tunnel_item_release;
 };
 
 INTERNAL {
lib/librte_ethdev/rte_flow.c +112 -0

115 lines not on this page · raw message

lib/librte_ethdev/rte_flow.h +195 -0

201 lines not on this page · raw message

lib/librte_ethdev/rte_flow_driver.h +32 -0
index 58f56b0262..bd5ffc0bb1 100644
@@ -131,6 +131,38 @@ struct rte_flow_ops {
 		 const struct rte_flow_shared_action *shared_action,
 		 void *data,
 		 struct rte_flow_error *error);
+	/** See rte_flow_tunnel_decap_set() */
+	int (*tunnel_decap_set)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_action **pmd_actions,
+		 uint32_t *num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_match() */
+	int (*tunnel_match)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_item **pmd_items,
+		 uint32_t *num_of_items,
+		 struct rte_flow_error *err);
+	/** See rte_flow_get_rte_flow_restore_info() */
+	int (*get_restore_info)
+		(struct rte_eth_dev *dev,
+		 struct rte_mbuf *m,
+		 struct rte_flow_restore_info *info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_action_tunnel_decap_release() */
+	int (*action_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_action *pmd_actions,
+		 uint32_t num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_item_release() */
+	int (*item_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_item *pmd_items,
+		 uint32_t num_of_items,
+		 struct rte_flow_error *err);
 };
 
 /**
Signature · 1 line
2.28.0
#67 lore raw

PATCH v7 3/3 app/testpmd: add commands for tunnel offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

Implementation details:

* Create application tunnel:
flow tunnel create <port> type <tunnel type>
On success, the command creates application tunnel object and returns the tunnel descriptor. Tunnel descriptor is used in subsequent flow creation commands to reference the tunnel.

* Create tunnel steering flow rule:
tunnel_set <tunnel descriptor> parameter used with steering rule template.

* Create tunnel matching flow rule:
tunnel_match <tunnel descriptor> used with matching rule template.

* If tunnel steering rule was offloaded, outer header of a partially offloaded packet is restored after miss.

Example:
test packet=
<Ether dst=24:8a:07:8d:ae:d6 src=50:6b:4b:cc:fc:e2 type=IPv4 | <IP version=4 ihl=5 proto=udp src=1.1.1.1 dst=1.1.1.10 | <UDP sport=4789 dport=4789 len=58 chksum=0x7f7b |
<VXLAN NextProtocol=Ethernet vni=0x0 |
<Ether dst=24:aa:aa:aa:aa:d6 src=50:bb:bb:bb:bb:e2 type=IPv4 | <IP version=4 ihl=5 proto=icmp src=2.2.2.2 dst=2.2.2.200 | <ICMP type=echo-request code=0 chksum=0xf7ff id=0x0 seq=0x0 |>>>>>>>

Quoted 1 line
Quoted 1 line
Quoted 1 line

len(packet)

92

testpmd> flow flush 0
testpmd> port 0/queue 0: received 1 packets src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 - length=92

testpmd> flow tunnel 0 type vxlan
port 0: flow tunnel #1 type vxlan
testpmd> flow create 0 ingress group 0 tunnel_set 1
pattern eth /ipv4 / udp dst is 4789 / vxlan / end actions jump group 0 / end
Flow rule #0 created
testpmd> port 0/queue 0: received 1 packets
tunnel restore info: - vxlan tunnel - outer header present # <--
src=50:6B:4B:CC:FC:E2 - dst=24:8A:07:8D:AE:D6 - type=0x0800 -
length=92

testpmd> flow create 0 ingress group 0 tunnel_match 1
pattern eth / ipv4 / udp dst is 4789 / vxlan / eth / ipv4 / end
actions set_mac_dst mac_addr 02:CA:FE:CA:FA:80 / queue index 0 / end
Flow rule #1 created
testpmd> port 0/queue 0: received 1 packets
src=50:BB:BB:BB:BB:E2 - dst=02:CA:FE:CA:FA:80 - type=0x0800 -
length=42

* Destroy flow tunnel
flow tunnel destroy <port> id <tunnel id>

* Show existing flow tunnels
flow tunnel list <port>

---
v2:
* introduce testpmd support for tunnel offload API

v3:
* update flow tunnel commands

v5:
* rebase to next-net

v7:
* resolve "%lu" differences in ubuntu 32 & 64

---
 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 252 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 6 files changed, 532 insertions(+), 13 deletions(-)
app/test-pmd/cmdline_flow.c +166 -4
index 00c70a144a..b9a1f7178a 100644
@@ -74,6 +74,14 @@ enum index {
 	LIST,
 	AGED,
 	ISOLATE,
+	TUNNEL,
+
+	/* Tunnel arguments. */
+	TUNNEL_CREATE,
+	TUNNEL_CREATE_TYPE,
+	TUNNEL_LIST,
+	TUNNEL_DESTROY,
+	TUNNEL_DESTROY_ID,
 
 	/* Destroy arguments. */
 	DESTROY_RULE,
@@ -93,6 +101,8 @@ enum index {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 
 	/* Shared action arguments */
 	SHARED_ACTION_CREATE,
@@ -713,6 +723,7 @@ struct buffer {
 		} sa; /* Shared action query arguments */
 		struct {
 			struct rte_flow_attr attr;
+			struct tunnel_ops tunnel_ops;
 			struct rte_flow_item *pattern;
 			struct rte_flow_action *actions;
 			uint32_t pattern_n;
@@ -789,10 +800,32 @@ static const enum index next_vc_attr[] = {
 	INGRESS,
 	EGRESS,
 	TRANSFER,
+	TUNNEL_SET,
+	TUNNEL_MATCH,
 	PATTERN,
 	ZERO,
 };
 
+static const enum index tunnel_create_attr[] = {
+	TUNNEL_CREATE,
+	TUNNEL_CREATE_TYPE,
+	END,
+	ZERO,
+};
+
+static const enum index tunnel_destroy_attr[] = {
+	TUNNEL_DESTROY,
+	TUNNEL_DESTROY_ID,
+	END,
+	ZERO,
+};
+
+static const enum index tunnel_list_attr[] = {
+	TUNNEL_LIST,
+	END,
+	ZERO,
+};
+
 static const enum index next_destroy_attr[] = {
 	DESTROY_RULE,
 	END,
@@ -1643,6 +1676,9 @@ static int parse_aged(struct context *, const struct token *,
 static int parse_isolate(struct context *, const struct token *,
 			 const char *, unsigned int,
 			 void *, unsigned int);
+static int parse_tunnel(struct context *, const struct token *,
+			const char *, unsigned int,
+			void *, unsigned int);
 static int parse_int(struct context *, const struct token *,
 		     const char *, unsigned int,
 		     void *, unsigned int);
@@ -1844,7 +1880,8 @@ static const struct token token_list[] = {
 			      LIST,
 			      AGED,
 			      QUERY,
-			      ISOLATE)),
+			      ISOLATE,
+			      TUNNEL)),
 		.call = parse_init,
 	},
 	/* Top-level command. */
@@ -1955,6 +1992,49 @@ static const struct token token_list[] = {
 			     ARGS_ENTRY(struct buffer, port)),
 		.call = parse_isolate,
 	},
+	[TUNNEL] = {
+		.name = "tunnel",
+		.help = "new tunnel API",
+		.next = NEXT(NEXT_ENTRY
+			     (TUNNEL_CREATE, TUNNEL_LIST, TUNNEL_DESTROY)),
+		.call = parse_tunnel,
+	},
+	/* Tunnel arguments. */
+	[TUNNEL_CREATE] = {
+		.name = "create",
+		.help = "create new tunnel object",
+		.next = NEXT(tunnel_create_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_CREATE_TYPE] = {
+		.name = "type",
+		.help = "create new tunnel",
+		.next = NEXT(tunnel_create_attr, NEXT_ENTRY(FILE_PATH)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, type)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_DESTROY] = {
+		.name = "destroy",
+		.help = "destroy tunel",
+		.next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_DESTROY_ID] = {
+		.name = "id",
+		.help = "tunnel identifier to testroy",
+		.next = NEXT(tunnel_destroy_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_tunnel,
+	},
+	[TUNNEL_LIST] = {
+		.name = "list",
+		.help = "list existing tunnels",
+		.next = NEXT(tunnel_list_attr, NEXT_ENTRY(PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_tunnel,
+	},
 	/* Destroy arguments. */
 	[DESTROY_RULE] = {
 		.name = "rule",
@@ -2018,6 +2098,20 @@ static const struct token token_list[] = {
 		.next = NEXT(next_vc_attr),
 		.call = parse_vc,
 	},
+	[TUNNEL_SET] = {
+		.name = "tunnel_set",
+		.help = "tunnel steer rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
+	[TUNNEL_MATCH] = {
+		.name = "tunnel_match",
+		.help = "tunnel match rule",
+		.next = NEXT(next_vc_attr, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct tunnel_ops, id)),
+		.call = parse_vc,
+	},
 	/* Validate/create pattern. */
 	[PATTERN] = {
 		.name = "pattern",
@@ -4495,12 +4589,28 @@ parse_vc(struct context *ctx, const struct token *token,
 		return len;
 	}
 	ctx->objdata = 0;
-	ctx->object = &out->args.vc.attr;
+	switch (ctx->curr) {
+	default:
+		ctx->object = &out->args.vc.attr;
+		break;
+	case TUNNEL_SET:
+	case TUNNEL_MATCH:
+		ctx->object = &out->args.vc.tunnel_ops;
+		break;
+	}
 	ctx->objmask = NULL;
 	switch (ctx->curr) {
 	case GROUP:
 	case PRIORITY:
 		return len;
+	case TUNNEL_SET:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.actions = 1;
+		return len;
+	case TUNNEL_MATCH:
+		out->args.vc.tunnel_ops.enabled = 1;
+		out->args.vc.tunnel_ops.items = 1;
+		return len;
 	case INGRESS:
 		out->args.vc.attr.ingress = 1;
 		return len;
@@ -6108,6 +6218,47 @@ parse_isolate(struct context *ctx, const struct token *token,
 	return len;
 }
 
+static int
+parse_tunnel(struct context *ctx, const struct token *token,
+	     const char *str, unsigned int len,
+	     void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != TUNNEL)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+	} else {
+		switch (ctx->curr) {
+		default:
+			break;
+		case TUNNEL_CREATE:
+		case TUNNEL_DESTROY:
+		case TUNNEL_LIST:
+			out->command = ctx->curr;
+			break;
+		case TUNNEL_CREATE_TYPE:
+		case TUNNEL_DESTROY_ID:
+			ctx->object = &out->args.vc.tunnel_ops;
+			break;
+		}
+	}
+
+	return len;
+}
+
 /**
  * Parse signed/unsigned integers 8 to 64-bit long.
  *
@@ -7148,11 +7299,13 @@ cmd_flow_parsed(const struct buffer *in)
 		break;
 	case VALIDATE:
 		port_flow_validate(in->port, &in->args.vc.attr,
-				   in->args.vc.pattern, in->args.vc.actions);
+				   in->args.vc.pattern, in->args.vc.actions,
+				   &in->args.vc.tunnel_ops);
 		break;
 	case CREATE:
 		port_flow_create(in->port, &in->args.vc.attr,
-				 in->args.vc.pattern, in->args.vc.actions);
+				 in->args.vc.pattern, in->args.vc.actions,
+				 &in->args.vc.tunnel_ops);
 		break;
 	case DESTROY:
 		port_flow_destroy(in->port, in->args.destroy.rule_n,
@@ -7178,6 +7331,15 @@ cmd_flow_parsed(const struct buffer *in)
 	case AGED:
 		port_flow_aged(in->port, in->args.aged.destroy);
 		break;
+	case TUNNEL_CREATE:
+		port_flow_tunnel_create(in->port, &in->args.vc.tunnel_ops);
+		break;
+	case TUNNEL_DESTROY:
+		port_flow_tunnel_destroy(in->port, in->args.vc.tunnel_ops.id);
+		break;
+	case TUNNEL_LIST:
+		port_flow_tunnel_list(in->port);
+		break;
 	default:
 		break;
 	}
app/test-pmd/config.c +248 -4

313 lines not on this page · raw message

app/test-pmd/testpmd.c +4 -1
index 6caba60988..333904d686 100644
@@ -3684,6 +3684,8 @@ init_port_dcb_config(portid_t pid,
 static void
 init_port(void)
 {
+	int i;
+
 	/* Configuration of Ethernet ports. */
 	ports = rte_zmalloc("testpmd: ports",
 			    sizeof(struct rte_port) * RTE_MAX_ETHPORTS,
@@ -3693,7 +3695,8 @@ init_port(void)
 				"rte_zmalloc(%d struct rte_port) failed\n",
 				RTE_MAX_ETHPORTS);
 	}
-
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++)
+		LIST_INIT(&ports[i].flow_tunnel_list);
 	/* Initialize ports NUMA structures */
 	memset(port_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
 	memset(rxring_numa, NUMA_NO_CONFIG, RTE_MAX_ETHPORTS);
app/test-pmd/testpmd.h +32 -2
index f8b0a3517d..5238ac3dd5 100644
@@ -12,6 +12,7 @@
 #include <rte_gro.h>
 #include <rte_gso.h>
 #include <cmdline.h>
+#include <sys/queue.h>
 
 #define RTE_PORT_ALL            (~(portid_t)0x0)
 
@@ -150,6 +151,26 @@ struct port_shared_action {
 	struct rte_flow_shared_action *action;	/**< Shared action handle. */
 };
 
+struct port_flow_tunnel {
+	LIST_ENTRY(port_flow_tunnel) chain;
+	struct rte_flow_action *pmd_actions;
+	struct rte_flow_item   *pmd_items;
+	uint32_t id;
+	uint32_t num_pmd_actions;
+	uint32_t num_pmd_items;
+	struct rte_flow_tunnel tunnel;
+	struct rte_flow_action *actions;
+	struct rte_flow_item *items;
+};
+
+struct tunnel_ops {
+	uint32_t id;
+	char type[16];
+	uint32_t enabled:1;
+	uint32_t actions:1;
+	uint32_t items:1;
+};
+
 /**
  * The data structure associated with each port.
  */
@@ -182,6 +203,7 @@ struct rte_port {
 	struct port_flow        *flow_list; /**< Associated flows. */
 	struct port_shared_action *actions_list;
 	/**< Associated shared actions. */
+	LIST_HEAD(, port_flow_tunnel) flow_tunnel_list;
 	const struct rte_eth_rxtx_callback *rx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	const struct rte_eth_rxtx_callback *tx_dump_cb[RTE_MAX_QUEUES_PER_PORT+1];
 	/**< metadata value to insert in Tx packets. */
@@ -773,11 +795,13 @@ int port_shared_action_update(portid_t port_id, uint32_t id,
 int port_flow_validate(portid_t port_id,
 		       const struct rte_flow_attr *attr,
 		       const struct rte_flow_item *pattern,
-		       const struct rte_flow_action *actions);
+		       const struct rte_flow_action *actions,
+		       const struct tunnel_ops *tunnel_ops);
 int port_flow_create(portid_t port_id,
 		     const struct rte_flow_attr *attr,
 		     const struct rte_flow_item *pattern,
-		     const struct rte_flow_action *actions);
+		     const struct rte_flow_action *actions,
+		     const struct tunnel_ops *tunnel_ops);
 int port_shared_action_query(portid_t port_id, uint32_t id);
 void update_age_action_context(const struct rte_flow_action *actions,
 		     struct port_flow *pf);
@@ -788,6 +812,12 @@ int port_flow_query(portid_t port_id, uint32_t rule,
 		    const struct rte_flow_action *action);
 void port_flow_list(portid_t port_id, uint32_t n, const uint32_t *group);
 void port_flow_aged(portid_t port_id, uint8_t destroy);
+const char *port_flow_tunnel_type(struct rte_flow_tunnel *tunnel);
+struct port_flow_tunnel *
+port_flow_locate_tunnel(uint16_t port_id, struct rte_flow_tunnel *tun);
+void port_flow_tunnel_list(portid_t port_id);
+void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id);
+void port_flow_tunnel_create(portid_t port_id, const struct tunnel_ops *ops);
 int port_flow_isolate(portid_t port_id, int set);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
app/test-pmd/util.c +33 -2
index 8488fa1a8f..781a813759 100644
@@ -48,18 +48,49 @@ dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
 	       is_rx ? "received" : "sent",
 	       (unsigned int) nb_pkts);
 	for (i = 0; i < nb_pkts; i++) {
+		int ret;
+		struct rte_flow_error error;
+		struct rte_flow_restore_info info = { 0, };
+
 		mb = pkts[i];
 		eth_hdr = rte_pktmbuf_read(mb, 0, sizeof(_eth_hdr), &_eth_hdr);
 		eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
-		ol_flags = mb->ol_flags;
 		packet_type = mb->packet_type;
 		is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
-
+		ret = rte_flow_get_restore_info(port_id, mb, &info, &error);
+		if (!ret) {
+			printf("restore info:");
+			if (info.flags & RTE_FLOW_RESTORE_INFO_TUNNEL) {
+				struct port_flow_tunnel *port_tunnel;
+
+				port_tunnel = port_flow_locate_tunnel
+					      (port_id, &info.tunnel);
+				printf(" - tunnel");
+				if (port_tunnel)
+					printf(" #%u", port_tunnel->id);
+				else
+					printf(" %s", "-none-");
+				printf(" type %s",
+					port_flow_tunnel_type(&info.tunnel));
+			} else {
+				printf(" - no tunnel info");
+			}
+			if (info.flags & RTE_FLOW_RESTORE_INFO_ENCAPSULATED)
+				printf(" - outer header present");
+			else
+				printf(" - no outer header");
+			if (info.flags & RTE_FLOW_RESTORE_INFO_GROUP_ID)
+				printf(" - miss group %u", info.group_id);
+			else
+				printf(" - no miss group");
+			printf("\n");
+		}
 		print_ether_addr("  src=", &eth_hdr->s_addr);
 		print_ether_addr(" - dst=", &eth_hdr->d_addr);
 		printf(" - type=0x%04x - length=%u - nb_segs=%d",
 		       eth_type, (unsigned int) mb->pkt_len,
 		       (int)mb->nb_segs);
+		ol_flags = mb->ol_flags;
 		if (ol_flags & PKT_RX_RSS_HASH) {
 			printf(" - RSS hash=0x%x", (unsigned int) mb->hash.rss);
 			printf(" - RSS queue=0x%x", (unsigned int) queue);
doc/guides/testpmd_app_ug/testpmd_funcs.rst +49 -0

73 lines not on this page · raw message

Signature · 1 line
2.28.0
#68 lore raw

Re: [dpdk-dev] [PATCH v7 0/3] Tunnel Offload API

In reply to Gregory Etelson
Quoted 29 lines · Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers

    during entire offload procedure;

- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

v2:
* documentation updates
* MLX5 PMD implementation for tunnel offload
* testpmd updates for tunnel offload

v3:
* documentation updates
* MLX5 PMD updates
* testpmd updates

v4:
* updated patch: allow negative values in flow rule types

v5:
* rebase to next-net

v6:
* update tunnel offload API documentation

v7:
* testpmd: resolve "%lu" differences in ubuntu 32 & 64

Quoted 6 lines

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (2):
ethdev: allow negative values in flow rule types app/testpmd: add commands for tunnel offload API

Series applied to dpdk-next-net/main, thanks.

#69 lore raw

v8 cover Tunnel Offload API

In reply to Gregory Etelson

Tunnel Offload API provides hardware independent, unified model to offload tunneled traffic. Key model elements are:
- apply matches to both outer and inner packet headers during entire offload procedure;
- restore outer header of partially offloaded packet;
- model is implemented as a set of helper functions.

v2:
* documentation updates
* MLX5 PMD implementation for tunnel offload
* testpmd updates for tunnel offload

v3:
* documentation updates
* MLX5 PMD updates
* testpmd updates

v4:
* updated patch: allow negative values in flow rule types

v5:
* rebase to next-net

v6:
* update tunnel offload API documentation

v7:
* testpmd: resolve "%lu" differences in ubuntu 32 & 64

v8:
* testpmd: use PRIu64 for general cast to uint64_t

Eli Britstein (1):
ethdev: tunnel offload model

Gregory Etelson (2):
ethdev: allow negative values in flow rule types app/testpmd: add commands for tunnel offload API

 app/test-pmd/cmdline_flow.c                 | 170 ++++++++++++-
 app/test-pmd/config.c                       | 252 +++++++++++++++++++-
 app/test-pmd/testpmd.c                      |   5 +-
 app/test-pmd/testpmd.h                      |  34 ++-
 app/test-pmd/util.c                         |  35 ++-
 doc/guides/prog_guide/rte_flow.rst          |  81 +++++++
 doc/guides/rel_notes/release_20_11.rst      |  10 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  49 ++++
 lib/librte_ethdev/rte_ethdev_version.map    |   5 +
 lib/librte_ethdev/rte_flow.c                | 140 ++++++++++-
 lib/librte_ethdev/rte_flow.h                | 195 +++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h         |  32 +++
 12 files changed, 989 insertions(+), 19 deletions(-)
Signature · 1 line
2.28.0
#70 lore raw

PATCH v8 1/3 ethdev: allow negative values in flow rule types

RTE flow items & actions use positive values in item & action type. Negative values are reserved for PMD private types. PMD items & actions usually are not exposed to application and are not used to create RTE flows.

The patch allows applications with access to PMD flow items & actions ability to integrate RTE and PMD items & actions and use them to create flow rule.

RTE flow item or action conversion library accepts positive known element types with predefined sizes only. Private PMD items and actions do not fit into this scheme because PMD type values are negative, each PMD has it's own types numeration and element types and their sizes are not visible at RTE level. To resolve these limitations the patch proposes this solution:
1. PMD can expose elements of pointer size only. RTE flow conversion functions will use pointer size for each configuration object in private PMD element it processes;
2. RTE flow verification will not reject elements with negative type.

---
v4:
* update the 'Negative types' section in the rtre_flow.rst

* update the patch comment

v5:
* rebase to next-net

---
 doc/guides/prog_guide/rte_flow.rst     |  3 +++
 doc/guides/rel_notes/release_20_11.rst |  5 +++++
 lib/librte_ethdev/rte_flow.c           | 28 ++++++++++++++++++++------
 3 files changed, 30 insertions(+), 6 deletions(-)
doc/guides/prog_guide/rte_flow.rst +3 -0
index 6ee0d3a10a..7fb5ec9059 100644
@@ -2775,6 +2775,9 @@ identifiers they are not aware of.
 
 A method to generate them remains to be defined.
 
+Application may use PMD dynamic items or actions in flow rules. In that case
+size of configuration object in dynamic element must be a pointer size.
+
 Planned types
 ~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_20_11.rst +5 -0
index 79d9ebac4e..9155b468d6 100644
@@ -116,6 +116,11 @@ New Features
   * Updated HWRM structures to 1.10.1.70 version.
   * Added TRUFLOW support for Stingray devices.
 
+* **Flow rules allowed to use private PMD items / actions.**
+
+  * Flow rule verification was updated to accept private PMD
+    items and actions.
+
 * **Updated Cisco enic driver.**
 
   * Added support for VF representors with single-queue Tx/Rx and flow API
lib/librte_ethdev/rte_flow.c +22 -6
index 686fe40eaa..b74ea5593a 100644
@@ -518,7 +518,11 @@ rte_flow_conv_item_spec(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_item[item->type].size;
+		/**
+		 * allow PMD private flow item
+		 */
+		off = (int)item->type >= 0 ?
+		      rte_flow_desc_item[item->type].size : sizeof(void *);
 		rte_memcpy(buf, data, (size > off ? off : size));
 		break;
 	}
@@ -621,7 +625,11 @@ rte_flow_conv_action_conf(void *buf, const size_t size,
 		}
 		break;
 	default:
-		off = rte_flow_desc_action[action->type].size;
+		/**
+		 * allow PMD private flow action
+		 */
+		off = (int)action->type >= 0 ?
+		      rte_flow_desc_action[action->type].size : sizeof(void *);
 		rte_memcpy(buf, action->conf, (size > off ? off : size));
 		break;
 	}
@@ -663,8 +671,12 @@ rte_flow_conv_pattern(struct rte_flow_item *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
-		    !rte_flow_desc_item[src->type].name)
+		/**
+		 * allow PMD private flow item
+		 */
+		if (((int)src->type >= 0) &&
+			((size_t)src->type >= RTE_DIM(rte_flow_desc_item) ||
+		    !rte_flow_desc_item[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ITEM, src,
 				 "cannot convert unknown item type");
@@ -752,8 +764,12 @@ rte_flow_conv_actions(struct rte_flow_action *dst,
 	unsigned int i;
 
 	for (i = 0, off = 0; !num || i != num; ++i, ++src, ++dst) {
-		if ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
-		    !rte_flow_desc_action[src->type].name)
+		/**
+		 * allow PMD private flow action
+		 */
+		if (((int)src->type >= 0) &&
+		    ((size_t)src->type >= RTE_DIM(rte_flow_desc_action) ||
+		    !rte_flow_desc_action[src->type].name))
 			return rte_flow_error_set
 				(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION,
 				 src, "cannot convert unknown action type");
Signature · 1 line
2.28.0
#71 lore raw

PATCH v8 2/3 ethdev: tunnel offload model

In reply to Gregory Etelson

From: Eli Britstein <[email protected]>

rte_flow API provides the building blocks for vendor-agnostic flow classification offloads. The rte_flow "patterns" and "actions" primitives are fine-grained, thus enabling DPDK applications the flexibility to offload network stacks and complex pipelines. Applications wishing to offload tunneled traffic are required to use the rte_flow primitives, such as group, meta, mark, tag, and others to model their high-level objects. The hardware model design for high-level software objects is not trivial. Furthermore, an optimal design is often vendor-specific.

When hardware offloads tunneled traffic in multi-group logic, partially offloaded packets may arrive to the application after they were modified in hardware. In this case, the application may need to restore the original packet headers. Consider the following sequence:
The application decaps a packet in one group and jumps to a second group where it tries to match on a 5-tuple, that will miss and send the packet to the application. In this case, the application does not receive the original packet but a modified one. Also, in this case, the application cannot match on the outer header fields, such as VXLAN vni and 5-tuple.

There are several possible ways to use rte_flow "patterns" and "actions" to resolve the issues above. For example:
1 Mapping headers to a hardware registers using the rte_flow_action_mark/rte_flow_action_tag/rte_flow_set_meta objects. 2 Apply the decap only at the last offload stage after all the "patterns" were matched and the packet will be fully offloaded. Every approach has its pros and cons and is highly dependent on the hardware vendor. For example, some hardware may have a limited number of registers while other hardware could not support inner actions and must decap before accessing inner headers.

The tunnel offload model resolves these issues. The model goals are:
1 Provide a unified application API to offload tunneled traffic that is capable to match on outer headers after decap.
2 Allow the application to restore the outer header of partially offloaded packets.

The tunnel offload model does not introduce new elements to the existing RTE flow model and is implemented as a set of helper functions.

For the application to work with the tunnel offload API it has to adjust flow rules in multi-table tunnel offload in the following way:
1 Remove explicit call to decap action and replace it with PMD actions obtained from rte_flow_tunnel_decap_and_set() helper.
2 Add PMD items obtained from rte_flow_tunnel_match() helper to all other rules in the tunnel offload sequence.

VXLAN Code example:

Assume application needs to do inner NAT on the VXLAN packet. The first rule in group 0:

flow create <port id> ingress group 0
pattern eth / ipv4 / udp dst is 4789 / vxlan / end actions {pmd actions} / jump group 3 / end

The first VXLAN packet that arrives matches the rule in group 0 and jumps to group 3. In group 3 the packet will miss since there is no flow to match and will be sent to the application. Application will call rte_flow_get_restore_info() to get the packet outer header.

Application will insert a new rule in group 3 to match outer and inner headers:

flow create <port id> ingress group 3
pattern {pmd items} / eth / ipv4 dst is 172.10.10.1 /
udp dst 4789 / vxlan vni is 10 /
ipv4 dst is 184.1.2.3 / end
actions set_ipv4_dst 186.1.1.1 / queue index 3 / end

Resulting of the rules will be that VXLAN packet with vni=10, outer IPv4 dst=172.10.10.1 and inner IPv4 dst=184.1.2.3 will be received decapped on queue 3 with IPv4 dst=186.1.1.1

Note: The packet in group 3 is considered decapped. All actions in that group will be done on the header that was inner before decap. The application may specify an outer header to be matched on. It's PMD responsibility to translate these items to outer metadata.

API usage:

/**
* 1. Initiate RTE flow tunnel object
*/
const struct rte_flow_tunnel tunnel = {
.type = RTE_FLOW_ITEM_TYPE_VXLAN,
.tun_id = 10,
}

/**
* 2. Obtain PMD tunnel actions
*
* pmd_actions is an intermediate variable application uses to
* compile actions array
*/
struct rte_flow_action **pmd_actions; rte_flow_tunnel_decap_and_set(&tunnel, &pmd_actions,

                              &num_pmd_actions, &error);

/**
* 3. offload the first rule
* matching on VXLAN traffic and jumps to group 3
* (implicitly decaps packet)
*/
app_actions = jump group 3
rule_items = app_items; /** eth / ipv4 / udp / vxlan */ rule_actions = { pmd_actions, app_actions }; attr.group = 0;
flow_1 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 4. after flow creation application does not need to keep the
* tunnel action resources.
*/
rte_flow_tunnel_action_release(port_id, pmd_actions,

                               num_pmd_actions);

/**
* 5. After partially offloaded packet miss because there was no
* matching rule handle miss on group 3
*/
struct rte_flow_restore_info info; rte_flow_get_restore_info(port_id, mbuf, &info, &error);

/**
* 6. Offload NAT rule:
*/
app_items = { eth / ipv4 dst is 172.10.10.1 / udp dst 4789 /

            vxlan vni is 10 / ipv4 dst is 184.1.2.3 }

app_actions = { set_ipv4_dst 186.1.1.1 / queue index 3 }

rte_flow_tunnel_match(&info.tunnel, &pmd_items,

                      &num_pmd_items,  &error);

rule_items = {pmd_items, app_items};
rule_actions = app_actions;
attr.group = info.group_id;
flow_2 = rte_flow_create(port_id, &attr,

                         rule_items, rule_actions, &error);

/**
* 7. Release PMD items after rule creation
*/
rte_flow_tunnel_item_release(port_id,

                             pmd_items, num_pmd_items);

References
1. https://mails.dpdk.org/archives/dev/2020-June/index.html

---
v5:
* rebase to next-net

v6:
* update the patch comment
* update tunnel offload section in rte_flow.rst

---
 doc/guides/prog_guide/rte_flow.rst       |  78 +++++++++
 doc/guides/rel_notes/release_20_11.rst   |   5 +
 lib/librte_ethdev/rte_ethdev_version.map |   5 +
 lib/librte_ethdev/rte_flow.c             | 112 +++++++++++++
 lib/librte_ethdev/rte_flow.h             | 195 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow_driver.h      |  32 ++++
 6 files changed, 427 insertions(+)
doc/guides/prog_guide/rte_flow.rst +78 -0
index 7fb5ec9059..8dc048c6f4 100644
@@ -3131,6 +3131,84 @@ operations include:
 - Duplication of a complete flow rule description.
 - Pattern item or action name retrieval.
 
+Tunneled traffic offload
+~~~~~~~~~~~~~~~~~~~~~~~~
+
+rte_flow API provides the building blocks for vendor-agnostic flow
+classification offloads. The rte_flow "patterns" and "actions"
+primitives are fine-grained, thus enabling DPDK applications the
+flexibility to offload network stacks and complex pipelines.
+Applications wishing to offload tunneled traffic are required to use
+the rte_flow primitives, such as group, meta, mark, tag, and others to
+model their high-level objects.  The hardware model design for
+high-level software objects is not trivial.  Furthermore, an optimal
+design is often vendor-specific.
+
+When hardware offloads tunneled traffic in multi-group logic,
+partially offloaded packets may arrive to the application after they
+were modified in hardware. In this case, the application may need to
+restore the original packet headers. Consider the following sequence:
+The application decaps a packet in one group and jumps to a second
+group where it tries to match on a 5-tuple, that will miss and send
+the packet to the application. In this case, the application does not
+receive the original packet but a modified one. Also, in this case,
+the application cannot match on the outer header fields, such as VXLAN
+vni and 5-tuple.
+
+There are several possible ways to use rte_flow "patterns" and
+"actions" to resolve the issues above. For example:
+
+1 Mapping headers to a hardware registers using the
+rte_flow_action_mark/rte_flow_action_tag/rte_flow_set_meta objects.
+
+2 Apply the decap only at the last offload stage after all the
+"patterns" were matched and the packet will be fully offloaded.
+
+Every approach has its pros and cons and is highly dependent on the
+hardware vendor.  For example, some hardware may have a limited number
+of registers while other hardware could not support inner actions and
+must decap before accessing inner headers.
+
+The tunnel offload model resolves these issues. The model goals are:
+
+1 Provide a unified application API to offload tunneled traffic that
+is capable to match on outer headers after decap.
+
+2 Allow the application to restore the outer header of partially
+offloaded packets.
+
+The tunnel offload model does not introduce new elements to the
+existing RTE flow model and is implemented as a set of helper
+functions.
+
+For the application to work with the tunnel offload API it
+has to adjust flow rules in multi-table tunnel offload in the
+following way:
+
+1 Remove explicit call to decap action and replace it with PMD actions
+obtained from rte_flow_tunnel_decap_and_set() helper.
+
+2 Add PMD items obtained from rte_flow_tunnel_match() helper to all
+other rules in the tunnel offload sequence.
+
+The model requirements:
+
+Software application must initialize
+rte_tunnel object with tunnel parameters before calling
+rte_flow_tunnel_decap_set() & rte_flow_tunnel_match().
+
+PMD actions array obtained in rte_flow_tunnel_decap_set() must be
+released by application with rte_flow_action_release() call.
+
+PMD items array obtained with rte_flow_tunnel_match() must be released
+by application with rte_flow_item_release() call.  Application can
+release PMD items and actions after rule was created. However, if the
+application needs to create additional rule for the same tunnel it
+will need to obtain PMD items again.
+
+Application cannot destroy rte_tunnel object before it releases all
+PMD actions & PMD items referencing that tunnel.
+
 Caveats
 -------
 
doc/guides/rel_notes/release_20_11.rst +5 -0
index 9155b468d6..f125ce79dd 100644
@@ -121,6 +121,11 @@ New Features
   * Flow rule verification was updated to accept private PMD
     items and actions.
 
+* **Added generic API to offload tunneled traffic and restore missed packet.**
+
+  * Added a new hardware independent helper API to RTE flow library that
+    offloads tunneled traffic and restores missed packets.
+
 * **Updated Cisco enic driver.**
 
   * Added support for VF representors with single-queue Tx/Rx and flow API
lib/librte_ethdev/rte_ethdev_version.map +5 -0
index f64c379ac2..8ddda2547f 100644
@@ -239,6 +239,11 @@ EXPERIMENTAL {
 	rte_flow_shared_action_destroy;
 	rte_flow_shared_action_query;
 	rte_flow_shared_action_update;
+	rte_flow_tunnel_decap_set;
+	rte_flow_tunnel_match;
+	rte_flow_get_restore_info;
+	rte_flow_tunnel_action_decap_release;
+	rte_flow_tunnel_item_release;
 };
 
 INTERNAL {
lib/librte_ethdev/rte_flow.c +112 -0

115 lines not on this page · raw message

lib/librte_ethdev/rte_flow.h +195 -0

201 lines not on this page · raw message

lib/librte_ethdev/rte_flow_driver.h +32 -0
index 58f56b0262..bd5ffc0bb1 100644
@@ -131,6 +131,38 @@ struct rte_flow_ops {
 		 const struct rte_flow_shared_action *shared_action,
 		 void *data,
 		 struct rte_flow_error *error);
+	/** See rte_flow_tunnel_decap_set() */
+	int (*tunnel_decap_set)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_action **pmd_actions,
+		 uint32_t *num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_tunnel_match() */
+	int (*tunnel_match)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_tunnel *tunnel,
+		 struct rte_flow_item **pmd_items,
+		 uint32_t *num_of_items,
+		 struct rte_flow_error *err);
+	/** See rte_flow_get_rte_flow_restore_info() */
+	int (*get_restore_info)
+		(struct rte_eth_dev *dev,
+		 struct rte_mbuf *m,
+		 struct rte_flow_restore_info *info,
+		 struct rte_flow_error *err);
+	/** See rte_flow_action_tunnel_decap_release() */
+	int (*action_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_action *pmd_actions,
+		 uint32_t num_of_actions,
+		 struct rte_flow_error *err);
+	/** See rte_flow_item_release() */
+	int (*item_release)
+		(struct rte_eth_dev *dev,
+		 struct rte_flow_item *pmd_items,
+		 uint32_t num_of_items,
+		 struct rte_flow_error *err);
 };
 
 /**
Signature · 1 line
2.28.0