[v1,04/12] ethdev: add eswitch port action to flow API

Message ID 20211001134716.1608857-5-andrew.rybchenko@oktetlabs.ru (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series ethdev: rework transfer flow API |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Andrew Rybchenko Oct. 1, 2021, 1:47 p.m. UTC
  From: Ivan Malov <ivan.malov@oktetlabs.ru>

For use with "transfer" flows. Supposed to direct matching traffic
at e-switch level to the external world (network, guests) via the
port which is logically connected with the given ethdev.

Signed-off-by: Ivan Malov <ivan.malov@oktetlabs.ru>
Signed-off-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
---
 app/test-pmd/cmdline_flow.c                 | 24 +++++++++++++++++++++
 doc/guides/prog_guide/rte_flow.rst          | 24 +++++++++++++++++++++
 doc/guides/rel_notes/release_21_11.rst      |  2 +-
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  4 ++++
 lib/ethdev/rte_flow.c                       |  1 +
 lib/ethdev/rte_flow.h                       | 10 ++++++++-
 6 files changed, 63 insertions(+), 2 deletions(-)
  

Patch

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index feaa61349e..57c7196866 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -462,6 +462,8 @@  enum index {
 	ACTION_POL_R,
 	ACTION_ETHDEV,
 	ACTION_ETHDEV_ID,
+	ACTION_ESWITCH_PORT,
+	ACTION_ESWITCH_PORT_ETHDEV_ID,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -1455,6 +1457,7 @@  static const enum index next_action[] = {
 	ACTION_CONNTRACK,
 	ACTION_CONNTRACK_UPDATE,
 	ACTION_ETHDEV,
+	ACTION_ESWITCH_PORT,
 	ZERO,
 };
 
@@ -1742,6 +1745,12 @@  static const enum index action_ethdev[] = {
 	ZERO,
 };
 
+static const enum index action_eswitch_port[] = {
+	ACTION_ESWITCH_PORT_ETHDEV_ID,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static int parse_set_raw_encap_decap(struct context *, const struct token *,
 				     const char *, unsigned int,
 				     void *, unsigned int);
@@ -4844,6 +4853,21 @@  static const struct token token_list[] = {
 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_ethdev, id)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_ESWITCH_PORT] = {
+		.name = "eswitch_port",
+		.help = "at e-switch level, direct matching packets to the external port associated with the given ethdev",
+		.priv = PRIV_ACTION(ESWITCH_PORT,
+				sizeof(struct rte_flow_action_ethdev)),
+		.next = NEXT(action_eswitch_port),
+		.call = parse_vc,
+	},
+	[ACTION_ESWITCH_PORT_ETHDEV_ID] = {
+		.name = "ethdev_id",
+		.help = "ethdev ID",
+		.next = NEXT(action_eswitch_port, NEXT_ENTRY(COMMON_UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_ethdev, id)),
+		.call = parse_vc_conf,
+	},
 	/* Indirect action destroy arguments. */
 	[INDIRECT_ACTION_DESTROY_ID] = {
 		.name = "action_id",
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index f633973181..22f7d327d2 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -3087,6 +3087,30 @@  See `Item: ETHDEV`_.
    | ``id`` | ethdev ID |
    +--------+-----------+
 
+Action: ``ESWITCH_PORT``
+^^^^^^^^^^^^^^^^^^^^^^^^
+At e-switch level, directs matching packets to the external port
+associated with the given ethdev, that is, to net. port or guest.
+
+These packets can originate from any of e-switch ports, not
+just the ones associated with the given ethdev. They come
+from the match engine in general, as per some criteria.
+
+::
+
+   *    (Ethdev) ~~~~~~~~~~~~ (Internal Port) ~~~~ [] >>>> (External Port)
+   *    :  SW                 :   Logical                    Net / Guest :
+   *    :                     :                                          :
+   *    | ---- PMD Layer ---- | ------------ E-Switch Layer ------------ |
+   *
+   *    [] shows the effective ("transfer") standpoint, the action engine;
+   *    >> shows the traffic flow in question established by the action;
+   *    ~~ shows logical interconnects between the endpoints.
+
+See `Item: ESWITCH_PORT`_.
+
+This action is meant to use the same structure as `Action: ETHDEV`_.
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/doc/guides/rel_notes/release_21_11.rst b/doc/guides/rel_notes/release_21_11.rst
index d431dc3804..4f4890c7df 100644
--- a/doc/guides/rel_notes/release_21_11.rst
+++ b/doc/guides/rel_notes/release_21_11.rst
@@ -167,7 +167,7 @@  API Changes
    Also, make sure to start the actual text at the margin.
    =======================================================
 
-* ethdev: Added items ``ETHDEV``, ``ESWITCH_PORT`` and action ``ETHDEV`` to flow API.
+* ethdev: Added items and actions ``ETHDEV``, ``ESWITCH_PORT`` to flow API.
 
 * cryptodev: The API rte_cryptodev_pmd_is_valid_dev is modified to
   rte_cryptodev_is_valid_dev as it can be used by the application as
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 79126e2f10..88bd8e743d 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -4107,6 +4107,10 @@  This section lists supported actions and their attributes, if any.
 
   - ``id {unsigned}``: ethdev ID
 
+- ``eswitch_port``: at e-switch level, direct matching packets to the external port associated with the given ethdev
+
+  - ``ethdev_id {unsigned}``: ethdev ID
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/lib/ethdev/rte_flow.c b/lib/ethdev/rte_flow.c
index 3cc84e2b43..647bbf91ce 100644
--- a/lib/ethdev/rte_flow.c
+++ b/lib/ethdev/rte_flow.c
@@ -192,6 +192,7 @@  static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 	MK_FLOW_ACTION(INDIRECT, 0),
 	MK_FLOW_ACTION(CONNTRACK, sizeof(struct rte_flow_action_conntrack)),
 	MK_FLOW_ACTION(ETHDEV, sizeof(struct rte_flow_action_ethdev)),
+	MK_FLOW_ACTION(ESWITCH_PORT, sizeof(struct rte_flow_action_ethdev)),
 };
 
 int
diff --git a/lib/ethdev/rte_flow.h b/lib/ethdev/rte_flow.h
index 3724ebee35..5d46b2350d 100644
--- a/lib/ethdev/rte_flow.h
+++ b/lib/ethdev/rte_flow.h
@@ -2453,6 +2453,14 @@  enum rte_flow_action_type {
 	 * @see struct rte_flow_action_ethdev
 	 */
 	RTE_FLOW_ACTION_TYPE_ETHDEV,
+
+	/**
+	 * At e-switch level, directs matching packets to the external port
+	 * associated with the given ethdev, that is, to net. port or guest.
+	 *
+	 * @see struct rte_flow_action_ethdev
+	 */
+	RTE_FLOW_ACTION_TYPE_ESWITCH_PORT,
 };
 
 /**
@@ -3217,7 +3225,7 @@  struct rte_flow_action_meter_color {
  * @b EXPERIMENTAL: this structure may change without prior notice
  *
  * Provides an ethdev ID for use with actions which are as follows:
- * RTE_FLOW_ACTION_TYPE_ETHDEV.
+ * RTE_FLOW_ACTION_TYPE_ETHDEV, RTE_FLOW_ACTION_TYPE_ESWITCH_PORT.
  */
 struct rte_flow_action_ethdev {
 	uint16_t id; /**< Ethdev ID */