[dpdk-dev] [RFC 2/3] ethdev: add flow api actions to modify TCP/UDP port numbers

Rahul Lakkireddy rahul.lakkireddy at chelsio.com
Fri Jun 22 11:56:04 CEST 2018


From: Shagun Agrawal <shaguna at chelsio.com>

Add actions:
- OF_SET_TP_SRC - set a new TCP/UDP source port number.
- OF_SET_TP_DST - set a new TCP/UDP destination port number.

Based on OFPAT_SET_TP_SRC and OFPAT_SET_TP_DST actions from OpenFlow
Specification.

Signed-off-by: Shagun Agrawal <shaguna at chelsio.com>
Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy at chelsio.com>
---
 app/test-pmd/cmdline_flow.c                 | 50 +++++++++++++++++++++++++++++
 app/test-pmd/config.c                       |  4 +++
 doc/guides/prog_guide/rte_flow.rst          | 34 ++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  8 +++++
 lib/librte_ethdev/rte_flow.c                |  4 +++
 lib/librte_ethdev/rte_flow.h                | 30 +++++++++++++++++
 6 files changed, 130 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 4550491ec..87745ada9 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -245,6 +245,10 @@ enum index {
 	ACTION_OF_SET_NW_IPV6_SRC_NW_IPV6_SRC,
 	ACTION_OF_SET_NW_IPV6_DST,
 	ACTION_OF_SET_NW_IPV6_DST_NW_IPV6_DST,
+	ACTION_OF_SET_TP_SRC,
+	ACTION_OF_SET_TP_SRC_TP_SRC,
+	ACTION_OF_SET_TP_DST,
+	ACTION_OF_SET_TP_DST_TP_DST,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -785,6 +789,8 @@ static const enum index next_action[] = {
 	ACTION_OF_SET_NW_IPV4_DST,
 	ACTION_OF_SET_NW_IPV6_SRC,
 	ACTION_OF_SET_NW_IPV6_DST,
+	ACTION_OF_SET_TP_SRC,
+	ACTION_OF_SET_TP_DST,
 	ZERO,
 };
 
@@ -904,6 +910,18 @@ static const enum index action_of_set_nw_ipv6_dst[] = {
 	ZERO,
 };
 
+static const enum index action_of_set_tp_src[] = {
+	ACTION_OF_SET_TP_SRC_TP_SRC,
+	ACTION_NEXT,
+	ZERO,
+};
+
+static const enum index action_of_set_tp_dst[] = {
+	ACTION_OF_SET_TP_DST_TP_DST,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_jump[] = {
 	ACTION_JUMP_GROUP,
 	ACTION_NEXT,
@@ -2462,6 +2480,38 @@ static const struct token token_list[] = {
 			(struct rte_flow_action_of_set_nw_ipv6, ipv6_addr)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_OF_SET_TP_SRC] = {
+		.name = "of_set_tp_src",
+		.help = "set tcp/udp source port number",
+		.priv = PRIV_ACTION(OF_SET_TP_SRC,
+			sizeof(struct rte_flow_action_of_set_tp)),
+		.next = NEXT(action_of_set_tp_src),
+		.call = parse_vc,
+	},
+	[ACTION_OF_SET_TP_SRC_TP_SRC] = {
+		.name = "port",
+		.help = "new source port number to set",
+		.next = NEXT(action_of_set_tp_src, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_of_set_tp, port)),
+		.call = parse_vc_conf,
+	},
+	[ACTION_OF_SET_TP_DST] = {
+		.name = "of_set_tp_dst",
+		.help = "set tcp/udp destination port number",
+		.priv = PRIV_ACTION(OF_SET_TP_DST,
+			sizeof(struct rte_flow_action_of_set_tp)),
+		.next = NEXT(action_of_set_tp_dst),
+		.call = parse_vc,
+	},
+	[ACTION_OF_SET_TP_DST_TP_DST] = {
+		.name = "port",
+		.help = "new destination port number to set",
+		.next = NEXT(action_of_set_tp_dst, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_of_set_tp, port)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 83cb0354d..1faf0071e 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1161,6 +1161,10 @@ static const struct {
 		       sizeof(struct rte_flow_action_of_set_nw_ipv6)),
 	MK_FLOW_ACTION(OF_SET_NW_IPV6_DST,
 		       sizeof(struct rte_flow_action_of_set_nw_ipv6)),
+	MK_FLOW_ACTION(OF_SET_TP_SRC,
+		       sizeof(struct rte_flow_action_of_set_tp)),
+	MK_FLOW_ACTION(OF_SET_TP_DST,
+		       sizeof(struct rte_flow_action_of_set_tp)),
 };
 
 /** Compute storage space needed by action configuration and copy it. */
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 3f56cc2d1..76c25a606 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2144,6 +2144,40 @@ Set a new IPv6 destination address. It is based on ``OFPAT_SET_NW_DST``
    | ``ipv6_addr`` | new IPv6 destination address |
    +---------------+------------------------------+
 
+Action: ``OF_SET_TP_SRC``
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Set a new TCP/UDP source port number. It is based on ``OFPAT_SET_TP_SRC``
+("set the transport source address") as defined by the
+`OpenFlow Switch Specification`_.
+
+.. _table_rte_flow_action_of_set_tp_src:
+
+.. table:: OF_SET_TP_SRC
+
+   +----------+-------------------------+
+   | Field    | Value                   |
+   +==========+=========================+
+   | ``port`` | new TCP/UDP source port |
+   +---------------+--------------------+
+
+Action: ``OF_SET_TP_DST``
+^^^^^^^^^^^^^^^^^^^^^^^^^
+
+Set a new TCP/UDP destination port number. It is based on ``OFPAT_SET_TP_DST``
+("set the transport destination address") as defined by the
+`OpenFlow Switch Specification`_.
+
+.. _table_rte_flow_action_of_set_tp_dst:
+
+.. table:: OF_SET_TP_DST
+
+   +----------+------------------------------+
+   | Field    | Value                        |
+   +==========+==============================+
+   | ``port`` | new TCP/UDP destination port |
+   +---------------+-------------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 56e3d6326..488b84de8 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3666,6 +3666,14 @@ This section lists supported actions and their attributes, if any.
 
   - ``ipv6_addr``: New IPv6 destination address.
 
+- ``of_set_tp_src``: Set a new TCP/UDP source port number.
+
+  - ``port``: New TCP/UDP source port number.
+
+- ``of_set_tp_dst``: Set a new TCP/UDP destination port number.
+
+  - ``port``: New TCP/UDP destination port number.
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index 29f846783..c1ec26276 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -117,6 +117,10 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_of_set_nw_ipv6)),
 	MK_FLOW_ACTION(OF_SET_NW_IPV6_DST,
 		       sizeof(struct rte_flow_action_of_set_nw_ipv6)),
+	MK_FLOW_ACTION(OF_SET_TP_SRC,
+		       sizeof(struct rte_flow_action_of_set_tp)),
+	MK_FLOW_ACTION(OF_SET_TP_DST,
+		       sizeof(struct rte_flow_action_of_set_tp)),
 };
 
 static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index 76cf652c5..9b58f3894 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1537,6 +1537,22 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_of_set_nw_ipv6.
 	 */
 	RTE_FLOW_ACTION_TYPE_OF_SET_NW_IPV6_DST,
+
+	/**
+	 * Implements OFPAT_SET_TP_SRC (set the source transport port) as
+	 * defined by the OpenFlow Switch Specification for tcp/udp.
+	 *
+	 * See struct rte_flow_action_of_set_tp.
+	 */
+	RTE_FLOW_ACTION_TYPE_OF_SET_TP_SRC,
+
+	/**
+	 * Implements OFPAT_SET_TP_DST (set the destination transport port)
+	 * as defined by the OpenFlow Switch Specification for tcp/udp.
+	 *
+	 * See struct rte_flow_action_of_set_tp.
+	 */
+	RTE_FLOW_ACTION_TYPE_OF_SET_TP_DST,
 };
 
 /**
@@ -1930,6 +1946,20 @@ struct rte_flow_action_of_set_nw_ipv6 {
 	uint8_t ipv6_addr[16];
 };
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this structure may change without prior notice
+ *
+ * RTE_FLOW_ACTION_TYPE_OF_SET_TP_SRC
+ * RTE_FLOW_ACTION_TYPE_OF_SET_TP_DST
+ *
+ * Implements OFPAT_SET_TP_SRC & OFPAT_SET_TP_DST (set the transport port)
+ * as defined by the OpenFlow Switch Specification for tcp/udp.
+ */
+struct rte_flow_action_of_set_tp {
+	uint16_t port;
+};
+
 /*
  * Definition of a single action.
  *
-- 
2.14.1



More information about the dev mailing list