[dpdk-dev] [PATCH v3 3/4] ethdev: add TTL change actions in flow API

Qi Zhang qi.z.zhang at intel.com
Mon Apr 16 07:16:38 CEST 2018


Add couple OpenFlow frienldy TTL change actions.

RTE_FLOW_ACTION_MLPS_TTL_DEC - decrement MPLS TTL.
RTE_FLOW_ACTION_IP_TTL_DEC - decrement IP TTL.
RTE_FLOW_ACTION_TTL_COPY_OUT - copy TTL outwards.
RTE_FLOW_ACTION_TTL_COPY_IN - copy TTL inwards.

Signed-off-by: Qi Zhang <qi.z.zhang at intel.com>
---
 app/test-pmd/cmdline_flow.c                 | 64 +++++++++++++++++++++++
 doc/guides/prog_guide/rte_flow.rst          | 80 +++++++++++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 12 +++++
 lib/librte_ether/rte_flow.h                 | 77 +++++++++++++++++++++++++++
 4 files changed, 233 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index a5e21c1fe..fa35ecc6d 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -190,6 +190,12 @@ enum index {
 	ACTION_VF_ID,
 	ACTION_METER,
 	ACTION_METER_ID,
+	ACTION_MPLS_TTL_DEC,
+	ACTION_MPLS_TTL_DEC_LVL,
+	ACTION_IP_TTL_DEC,
+	ACTION_IP_TTL_DEC_LVL,
+	ACTION_TTL_COPY_OUT,
+	ACTION_TTL_COPY_IN,
 };
 
 /** Size of pattern[] field in struct rte_flow_item_raw. */
@@ -654,6 +660,10 @@ static const enum index next_action[] = {
 	ACTION_PF,
 	ACTION_VF,
 	ACTION_METER,
+	ACTION_MPLS_TTL_DEC,
+	ACTION_IP_TTL_DEC,
+	ACTION_TTL_COPY_OUT,
+	ACTION_TTL_COPY_IN,
 	ZERO,
 };
 
@@ -694,6 +704,16 @@ static const enum index action_meter[] = {
 	ZERO,
 };
 
+static const enum index action_mpls_ttl_dec[] = {
+	ACTION_MPLS_TTL_DEC_LVL,
+	ZERO,
+};
+
+static const enum index action_ip_ttl_dec[] = {
+	ACTION_IP_TTL_DEC_LVL,
+	ZERO,
+};
+
 static int parse_init(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
@@ -1807,6 +1827,50 @@ static const struct token token_list[] = {
 		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_MPLS_TTL_DEC] = {
+		.name = "mpls_ttl_dec",
+		.help = "decrement MPLS TTL",
+		.priv = PRIV_ACTION(MPLS_TTL_DEC,
+				sizeof(struct rte_flow_action_mpls_ttl_dec)),
+		.next = NEXT(action_mpls_ttl_dec),
+		.call = parse_vc,
+	},
+	[ACTION_MPLS_TTL_DEC_LVL] = {
+		.name = "level",
+		.help = "level of MPLS header",
+		.next = NEXT(action_mpls_ttl_dec, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
+		.call = parse_vc,
+	},
+	[ACTION_IP_TTL_DEC] = {
+		.name = "ip_ttl_dec",
+		.help = "decrement IPv4 TTL or IPv6 Hop Limit",
+		.priv = PRIV_ACTION(MPLS_TTL_DEC,
+				sizeof(struct rte_flow_action_ip_ttl_dec)),
+		.next = NEXT(action_ip_ttl_dec),
+		.call = parse_vc,
+	},
+	[ACTION_IP_TTL_DEC_LVL] = {
+		.name = "level",
+		.help = "level of IPv4 or IPv6 header",
+		.next = NEXT(action_ip_ttl_dec, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_queue, index)),
+		.call = parse_vc,
+	},
+	[ACTION_TTL_COPY_OUT] = {
+		.name = "ttl_copy_out",
+		.help = "copy TTL  outwards",
+		.priv = PRIV_ACTION(DROP, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_TTL_COPY_IN] = {
+		.name = "ttl_copy_in",
+		.help = "copy TTL  inwards",
+		.priv = PRIV_ACTION(DROP, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index ea0e40a52..e81f0e375 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -1588,6 +1588,86 @@ contain respective protocol layer.
    |  ``mask``     | Bit-mask applied to new_val                                       |
    +---------------+-------------------------------------------------------------------+
 
+Action: ``MPLS_TTL_DEC``
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+Decrement MPLS TTL, only applies to packets that contain specific MPLS
+headers.
+
+.. _table_rte_flow_action_mpls_ttl_dec:
+
+.. table:: MPLS_TTL_DEC
+
+   +---------------+---------------------------------------------+
+   | Field         | Value                                       |
+   +===============+=============================================+
+   | ``dir_level`` | Specify the level of MPLS header.           |
+   |               | direction (1b)                              |
+   |               | 0: match start from outermost.              |
+   |               | 1: match start from innermost.              |
+   |               | level: (31b)                                |
+   |               | 0: outermost or innermost MPLS header       |
+   |               | 1: next to outmost or innermost MPLS header |
+   |               | 2: and so on ...                            |
+   +---------------+---------------------------------------------+
+
+Action: ``IP_TTL_DEC``
+^^^^^^^^^^^^^^^^^^^^^^
+
+Decrement IPv4 TTL or IPv6 hop limit field and update the IP checksum,
+only applies to packets that contain specific MPLS headers.
+
+.. _table_rte_flow_action_ip_ttl_dec:
+
+.. table:: IP_TTL_DEC
+
+   +---------------+----------------------------------------------------------+
+   | Field         | Value                                                    |
+   +===============+==========================================================+
+   | ``dir_level`` | Specify the level of IPv4 or IPv6 header.                |
+   |               | direction (1b)                                           |
+   |               | 0: match start from outermost.                           |
+   |               | 1: match start from innermost.                           |
+   |               | level: (31b)                                             |
+   |               | 0: outermost or innermost Ipv4 or IPv6 header            |
+   |               | 1: next to outmost or innermost MPLS IPv4 or IPv6 header |
+   |               | 2: and so on ...                                         |
+   +---------------+----------------------------------------------------------+
+
+Action: ``TTL_COPY_OUT``
+^^^^^^^^^^^^^^^^^^^^^^^^
+
+Copy the TTL from next-to-outermost to outermost header with TTL, copy can
+be IP to IP, MPLS to MPLS or IP to MPLS, only applies packets that contain
+required MPLS or IP headers.
+
+.. _table_rte_flow_action_ttl_copy_out:
+
+.. table:: TTL_COPY_OUT
+
+   +---------------+
+   | Field         |
+   +===============+
+   | no properties |
+   +---------------+
+
+Action: ``TTL_COPY_IN``
+^^^^^^^^^^^^^^^^^^^^^^^
+
+Copy the TTL from outermost to next-to-outermost header with TTL, copy can
+be IP to IP, MPLS to MPLS or MPLS to IP, only applies packets that contain
+required MPLS or IP headers.
+
+.. _table_rte_flow_action_ttl_copy_in:
+
+.. table:: TTL_COPY_IN
+
+   +---------------+
+   | Field         |
+   +===============+
+   | no properties |
+   +---------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 48688600e..4dd86f10e 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3442,6 +3442,18 @@ This section lists supported actions and their attributes, if any.
   - ``original {boolean}``: use original VF ID if possible.
   - ``id {unsigned}``: VF ID to redirect packets to.
 
+- ``mpls_ttl_dec``: decrement MPLS TTL.
+
+  - ``level``: level of MPLS header.
+
+- ``ip_ttl_dec``: decrement IPv4 TTL or IPv6 Hot Limit.
+
+  - ``level``: level of IPv4 or IPv6 header.
+
+- ``ttl_copy_out``: copy TTL outwards.
+
+- ``ttl_copy_in``: copy TTL inwards.
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
diff --git a/lib/librte_ether/rte_flow.h b/lib/librte_ether/rte_flow.h
index 80cf75ff0..96a236945 100644
--- a/lib/librte_ether/rte_flow.h
+++ b/lib/librte_ether/rte_flow.h
@@ -1250,6 +1250,37 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_field_set.
 	 */
 	RTE_FLOW_ACTION_TYPE_FIELD_SET,
+
+	/**
+	 * Decrement MPLS TTL, only applies to packets that contain specific
+	 * MPLS header.
+	 *
+	 * See struct rte_flow_action_mpls_ttl_dec.
+	 */
+	RTE_FLOW_ACTION_TYPE_MPLS_TTL_DEC,
+
+	/**
+	 * Decrement IPv4 TTL or IPv6 Hop limit field and update the IP
+	 * checksum, only applies to packets that contain specific IPv4
+	 * or IPv6 header.
+	 *
+	 * See struct rte_flow_action_ip_ttl_dec.
+	 */
+	RTE_FLOW_ACTION_TYPE_IP_TTL_DEC,
+
+	/**
+	 * Copy the TTL from next-to-outermost to outermost header with TTL,
+	 * copy can be IP to IP, MPLS to MPLS or IP to MPLS, only applies
+	 * packets that contain required protocol headers.
+	 */
+	RTE_FLOW_ACTION_TYPE_TTL_COPY_OUT,
+
+	/**
+	 * Copy the TTL from outermost to next-to-outermost header with TTL,
+	 * copy can be IP to IP, MPLS to MPLS or MPLS to IP, only applies
+	 * packets that contain required protocol headers.
+	 */
+	RTE_FLOW_ACTION_TYPE_TTL_COPY_IN,
 };
 
 /**
@@ -1420,6 +1451,52 @@ struct rte_flow_action_field_set {
 };
 
 /**
+ * RTE_FLOW_ACTION_TYPE_MPLS_TTL_DEC
+ *
+ * Decrement MPLS TTL, only applies to packets that contain specific
+ * MPLS header.
+ */
+struct rte_flow_action_mpls_ttl_dec {
+	/**
+	 * Specify the level of MPLS header.
+	 *
+	 * direction (1b)
+	 * 0: match start from outermost.
+	 * 1: match start from innermost.
+	 *
+	 * level (31b)
+	 * 0: outermost|innermost MPLS header.
+	 * 1: next to outermost|innermost MPLS header.
+	 * 2: and so on ...
+	 */
+	uint32_t dir_level;
+
+};
+
+/**
+ * RTE_FLOW_ACTION_TYPE_IP_TTL_DEC
+ *
+ * Decrement IPv4 TTL or IPv6 hop limit field and update the IP
+ * checksum, only applies to packets that contain specific IPv4
+ * or IPv6 header.
+ */
+struct rte_flow_action_ip_ttl_dec {
+	/**
+	 * Specify the level of IPv4 or IPv6 header.
+	 *
+	 * direction (1b)
+	 * 0: match start from outermost.
+	 * 1: match start from innermost.
+	 *
+	 * level (31b)
+	 * 0: outermost|innermost IPv4 or IPv6 header.
+	 * 1: next to outermost|innermost IPv4 or IPv6 header.
+	 * 2: and so on ...
+	 */
+	uint32_t dir_level;
+};
+
+/**
  * Definition of a single action.
  *
  * A list of actions is terminated by a END action.
-- 
2.13.6



More information about the dev mailing list