DPDK patches and discussions
 help / color / mirror / Atom feed
* [dpdk-dev] [PATCH 0/3] ethdev: add generic TTL rewrite actions
@ 2018-09-25 13:47 Xiaoyu Min
  2018-09-25 13:47 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
                   ` (3 more replies)
  0 siblings, 4 replies; 40+ messages in thread
From: Xiaoyu Min @ 2018-09-25 13:47 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: dev

This patch series is for RFC[1]

Patch 1 adds generic TTL rewrite actions to flow API
Patch 2 adds corresponding testpmd commands
Patch 3 implements the offloading logic of E-Switch rules on Mellanox MLX5

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

Xiaoyu Min (3):
  ethdev: add generic TTL rewrite actions
  app/testpmd: add commands of modify TTL
  net/mlx5: eswitch-modify TTL actions

 app/test-pmd/cmdline_flow.c                 | 34 ++++++++++
 app/test-pmd/config.c                       |  3 +
 doc/guides/prog_guide/rte_flow.rst          | 30 +++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 ++
 drivers/net/mlx5/mlx5_flow.h                |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c            | 74 ++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c                |  2 +
 lib/librte_ethdev/rte_flow.h                | 31 +++++++++
 8 files changed, 179 insertions(+), 2 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH 1/3] ethdev: add generic TTL rewrite actions
  2018-09-25 13:47 [dpdk-dev] [PATCH 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
@ 2018-09-25 13:47 ` Xiaoyu Min
  2018-09-25 13:47 ` [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify TTL Xiaoyu Min
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 40+ messages in thread
From: Xiaoyu Min @ 2018-09-25 13:47 UTC (permalink / raw)
  To: ferruh.yigit, Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Andrew Rybchenko
  Cc: dev

rewrite TTL by decrease or just set it directly
it's not necessary to check if the final result
is zero or not

This is slightly different from the one defined
by openflow and more generic

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
 doc/guides/prog_guide/rte_flow.rst | 30 +++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  2 ++
 lib/librte_ethdev/rte_flow.h       | 31 ++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)

diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 4faf8cb40..3aec0834b 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2166,6 +2166,36 @@ Set a new TCP/UDP destination port number.
    | ``port`` | new TCP/UDP destination port |
    +---------------+-------------------------+
 
+Action: ``DEC_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Decrease TTL value.
+
+.. _table_rte_flow_action_dec_ttl:
+
+.. table:: DEC_TTL
+
+   +---------------+
+   | Field         |
+   +===============+
+   | no properties |
+   +---------------+
+
+Action: ``SET_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Assigns a new TTL value.
+
+.. _table_rte_flow_action_set_ttl:
+
+.. table:: SET_TTL
+
+   +---------------+--------------------+
+   | Field         | Value              |
+   +===============+====================+
+   | ``ttl_value`` | new TTL value      |
+   +---------------+--------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index 409c79741..631f80efd 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -121,6 +121,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(SET_TP_DST,
 		       sizeof(struct rte_flow_action_set_tp)),
+	MK_FLOW_ACTION(DEC_TTL, 0),
+	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
 };
 
 static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index c80771b25..b41e37a31 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1547,6 +1547,26 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_set_tp.
 	 */
 	RTE_FLOW_ACTION_TYPE_SET_TP_DST,
+
+	/**
+	 * Decrease TTL value directly
+	 *
+	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
+	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 */
+	RTE_FLOW_ACTION_TYPE_DEC_TTL,
+
+	/**
+	 * Set TTL value
+	 *
+	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
+	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_ttl
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_TTL,
 };
 
 /**
@@ -1955,6 +1975,17 @@ struct rte_flow_action_set_tp {
 	uint16_t port;
 };
 
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_TTL
+ *
+ * Set the TTL value directly for IPv4 or IPv6
+ * The RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
+ * must be present in pattern
+ */
+struct rte_flow_action_set_ttl {
+	uint8_t ttl_value;
+};
+
 /*
  * Definition of a single action.
  *
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify TTL
  2018-09-25 13:47 [dpdk-dev] [PATCH 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
  2018-09-25 13:47 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
@ 2018-09-25 13:47 ` Xiaoyu Min
  2018-09-25 13:47 ` [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify TTL actions Xiaoyu Min
  2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
  3 siblings, 0 replies; 40+ messages in thread
From: Xiaoyu Min @ 2018-09-25 13:47 UTC (permalink / raw)
  To: ferruh.yigit, Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu,
	Bernard Iremonger, John McNamara, Marko Kovacevic
  Cc: dev

add commands which supports following TTL actions:
- RTE_FLOW_ACTION_TYPE_DEC_TTL
- RTE_FLOW_ACTION_TYPE_SET_TTL

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
 app/test-pmd/cmdline_flow.c                 | 34 +++++++++++++++++++++
 app/test-pmd/config.c                       |  3 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 +++
 3 files changed, 42 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 3935539cb..fae825462 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -255,6 +255,9 @@ enum index {
 	ACTION_SET_TP_SRC_TP_SRC,
 	ACTION_SET_TP_DST,
 	ACTION_SET_TP_DST_TP_DST,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
+	ACTION_SET_TTL_TTL,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -834,6 +837,8 @@ static const enum index next_action[] = {
 	ACTION_SET_IPV6_DST,
 	ACTION_SET_TP_SRC,
 	ACTION_SET_TP_DST,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
 	ZERO,
 };
 
@@ -972,6 +977,12 @@ static const enum index action_set_tp_dst[] = {
 	ZERO,
 };
 
+static const enum index action_set_ttl[] = {
+	ACTION_SET_TTL_TTL,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_jump[] = {
 	ACTION_JUMP_GROUP,
 	ACTION_NEXT,
@@ -2620,6 +2631,29 @@ static const struct token token_list[] = {
 			     (struct rte_flow_action_set_tp, port)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_DEC_TTL] = {
+		.name = "dec_ttl",
+		.help = "decrease network TTL if available",
+		.priv = PRIV_ACTION(DEC_TTL, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL] = {
+		.name = "set_ttl",
+		.help = "set ttl value",
+		.priv = PRIV_ACTION(SET_TTL,
+			sizeof(struct rte_flow_action_set_ttl)),
+		.next = NEXT(action_set_ttl),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL_TTL] = {
+		.name = "ttl_value",
+		.help = "new ttl value to set",
+		.next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_ttl, ttl_value)),
+		.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 d1028d03e..d28b6ed14 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1174,6 +1174,9 @@ static const struct {
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(SET_TP_DST,
 		       sizeof(struct rte_flow_action_set_tp)),
+	MK_FLOW_ACTION(DEC_TTL, 0),
+	MK_FLOW_ACTION(SET_TTL,
+		       sizeof(struct rte_flow_action_set_ttl)),
 };
 
 /** Compute storage space needed by action configuration and copy it. */
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index f60be0862..e2674292b 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3721,6 +3721,11 @@ This section lists supported actions and their attributes, if any.
 
   - ``port``: New TCP/UDP destination port number.
 
+- ``dec_ttl``: Performs a decrease TTL vaule action
+
+- ``set_ttl``: Set TTL value with specificed value
+  - ``ttl_value {unsigned}``: The new TTL value to be set
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify TTL actions
  2018-09-25 13:47 [dpdk-dev] [PATCH 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
  2018-09-25 13:47 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
  2018-09-25 13:47 ` [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify TTL Xiaoyu Min
@ 2018-09-25 13:47 ` Xiaoyu Min
  2018-10-03 20:07   ` Yongseok Koh
  2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
  3 siblings, 1 reply; 40+ messages in thread
From: Xiaoyu Min @ 2018-09-25 13:47 UTC (permalink / raw)
  To: ferruh.yigit, Shahaf Shuler, Yongseok Koh; +Cc: dev

Offload following modify TTL actions to E-Swtich via
TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_TTL
- RTE_FLOW_ACTION_TYPE_DEC_TTL

The corresponding IP protocol rte_flow_item_ipv[4|6]
must be present in rte_flow pattern otherwith PMD
return error

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow.h     |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c | 74 +++++++++++++++++++++++++++++++-
 2 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index be182a643..5237e31dd 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -93,6 +93,8 @@
 #define MLX5_ACTION_SET_IPV6_DST (1u << 14)
 #define MLX5_ACTION_SET_TP_SRC (1u << 15)
 #define MLX5_ACTION_SET_TP_DST (1u << 16)
+#define MLX5_ACTION_SET_TTL (1u << 17)
+#define MLX5_ACTION_DEC_TTL (1u << 18)
 
 /* possible L3 layers protocols filtering. */
 #define MLX5_IP_PROTOCOL_TCP 6
diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
index 85c92f369..af88c4a0d 100644
--- a/drivers/net/mlx5/mlx5_flow_tcf.c
+++ b/drivers/net/mlx5/mlx5_flow_tcf.c
@@ -217,6 +217,10 @@ struct tc_pedit_sel {
 #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
 #endif
 
+#ifndef TTL_LEN
+#define TTL_LEN 1
+#endif
+
 /** Empty masks for known item types. */
 static const union {
 	struct rte_flow_item_port_id port_id;
@@ -297,7 +301,9 @@ struct flow_tcf_ptoi {
 		(act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC  || \
 		(act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_DST  || \
 		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC    || \
-		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST) ?    \
+		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST    || \
+		(act) == RTE_FLOW_ACTION_TYPE_SET_TTL       || \
+		(act) == RTE_FLOW_ACTION_TYPE_DEC_TTL) ?       \
 		1 : 0; })
 #define MAX_PEDIT_KEYS (128)
 #define SZ_PEDIT_KEY_VAL (4)
@@ -321,6 +327,34 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
 	return keys;
 }
 
+static void
+flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
+				struct pedit_parser *p_parser,
+				uint64_t item_flags)
+{
+	int idx = p_parser->sel.nkeys;
+
+	p_parser->keys[idx].mask = 0xFFFFFF00;
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
+		p_parser->keys[idx].off = 8; /* IPv4 TTL Offset */
+	}
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
+		p_parser->keys[idx].off = 7; /* IPv6 HopLimit Offset */
+	}
+	if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
+		p_parser->keys[idx].val = 0xFF;
+	} else {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+		p_parser->keys[idx].val =
+			((const struct rte_flow_action_set_ttl *)
+			 actions->conf)->ttl_value;
+	}
+	p_parser->sel.nkeys = (++idx);
+}
+
 static void
 flow_tcf_pedit_key_set_tp_port(const struct rte_flow_action *actions,
 				struct pedit_parser *p_parser,
@@ -408,6 +442,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
 			flow_tcf_pedit_key_set_tp_port(*actions,
 							&p_parser, item_flags);
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			flow_tcf_pedit_key_set_dec_ttl(*actions,
+							&p_parser, item_flags);
+			break;
 		default:
 			goto pedit_mnl_msg_done;
 		}
@@ -488,6 +527,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
 			keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN);
 			flags |= MLX5_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
+			flags |= MLX5_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
+			flags |= MLX5_ACTION_DEC_TTL;
+			break;
 		default:
 			goto get_pedit_action_size_done;
 		}
@@ -988,13 +1035,20 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
 			action_flags |= MLX5_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			action_flags |= MLX5_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			action_flags |= MLX5_ACTION_DEC_TTL;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ACTION,
 						  actions,
 						  "action not supported");
 		}
-		if (IS_MODIFY_ACTION(actions->type)) {
+		if (IS_MODIFY_ACTION(actions->type) &&
+		    actions->type != RTE_FLOW_ACTION_TYPE_DEC_TTL) {
 			if (!actions->conf)
 				return rte_flow_error_set(error, ENOTSUP,
 						RTE_FLOW_ERROR_TYPE_ACTION_CONF,
@@ -1029,6 +1083,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 						"no TCP/UDP item found in"
 						" pattern");
 	}
+	if (action_flags &
+	   (MLX5_ACTION_SET_TTL | MLX5_ACTION_DEC_TTL)) {
+		if (!(item_flags &
+		     (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
+		      MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
+			return rte_flow_error_set(error, ENOTSUP,
+						  RTE_FLOW_ERROR_TYPE_ACTION,
+						  actions,
+						  "no IP found in pattern");
+	}
 	return 0;
 }
 
@@ -1178,6 +1242,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			size += flow_tcf_get_pedit_actions_size(&actions,
 								&flags);
 			break;
@@ -1451,6 +1517,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 						  RTE_BE16(0x0fff)));
 			break;
 		case RTE_FLOW_ITEM_TYPE_IPV4:
+			item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
 			mask.ipv4 = flow_tcf_item_mask
 				(items, &rte_flow_item_ipv4_mask,
 				 &flow_tcf_mask_supported.ipv4,
@@ -1490,6 +1557,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 			}
 			break;
 		case RTE_FLOW_ITEM_TYPE_IPV6:
+			item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
 			mask.ipv6 = flow_tcf_item_mask
 				(items, &rte_flow_item_ipv6_mask,
 				 &flow_tcf_mask_supported.ipv6,
@@ -1718,6 +1786,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			na_act_index =
 				mnl_attr_nest_start(nlh, na_act_index_cur++);
 			flow_tcf_create_pedit_mnl_msg(nlh,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions
  2018-09-25 13:47 [dpdk-dev] [PATCH 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
                   ` (2 preceding siblings ...)
  2018-09-25 13:47 ` [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify TTL actions Xiaoyu Min
@ 2018-09-25 14:37 ` Xiaoyu Min
  2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 1/3] " Xiaoyu Min
                     ` (5 more replies)
  3 siblings, 6 replies; 40+ messages in thread
From: Xiaoyu Min @ 2018-09-25 14:37 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: dev

This patch series is for RFC[1]

Patch 1 adds generic TTL rewrite actions to flow API
Patch 2 adds corresponding testpmd commands
Patch 3 implements the offloading logic of E-Switch rules on Mellanox MLX5

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

V2:
 * fix misspelled issues reported by checkpatch

Xiaoyu Min (3):
  ethdev: add generic TTL rewrite actions
  app/testpmd: add commands of modify TTL
  net/mlx5: eswitch-modify TTL actions

 app/test-pmd/cmdline_flow.c                 | 34 ++++++++++
 app/test-pmd/config.c                       |  3 +
 doc/guides/prog_guide/rte_flow.rst          | 30 +++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 ++
 drivers/net/mlx5/mlx5_flow.h                |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c            | 74 ++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c                |  2 +
 lib/librte_ethdev/rte_flow.h                | 31 +++++++++
 8 files changed, 179 insertions(+), 2 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v2 1/3] ethdev: add generic TTL rewrite actions
  2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
@ 2018-09-25 14:37   ` Xiaoyu Min
  2018-10-03 19:50     ` Yongseok Koh
  2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify TTL Xiaoyu Min
                     ` (4 subsequent siblings)
  5 siblings, 1 reply; 40+ messages in thread
From: Xiaoyu Min @ 2018-09-25 14:37 UTC (permalink / raw)
  To: ferruh.yigit, Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Andrew Rybchenko
  Cc: dev

rewrite TTL by decrease or just set it directly
it's not necessary to check if the final result
is zero or not

This is slightly different from the one defined
by openflow and more generic

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
 doc/guides/prog_guide/rte_flow.rst | 30 +++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  2 ++
 lib/librte_ethdev/rte_flow.h       | 31 ++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)

diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 4faf8cb40..3aec0834b 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2166,6 +2166,36 @@ Set a new TCP/UDP destination port number.
    | ``port`` | new TCP/UDP destination port |
    +---------------+-------------------------+
 
+Action: ``DEC_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Decrease TTL value.
+
+.. _table_rte_flow_action_dec_ttl:
+
+.. table:: DEC_TTL
+
+   +---------------+
+   | Field         |
+   +===============+
+   | no properties |
+   +---------------+
+
+Action: ``SET_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Assigns a new TTL value.
+
+.. _table_rte_flow_action_set_ttl:
+
+.. table:: SET_TTL
+
+   +---------------+--------------------+
+   | Field         | Value              |
+   +===============+====================+
+   | ``ttl_value`` | new TTL value      |
+   +---------------+--------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index 409c79741..631f80efd 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -121,6 +121,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(SET_TP_DST,
 		       sizeof(struct rte_flow_action_set_tp)),
+	MK_FLOW_ACTION(DEC_TTL, 0),
+	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
 };
 
 static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index c80771b25..b41e37a31 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1547,6 +1547,26 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_set_tp.
 	 */
 	RTE_FLOW_ACTION_TYPE_SET_TP_DST,
+
+	/**
+	 * Decrease TTL value directly
+	 *
+	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
+	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 */
+	RTE_FLOW_ACTION_TYPE_DEC_TTL,
+
+	/**
+	 * Set TTL value
+	 *
+	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
+	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_ttl
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_TTL,
 };
 
 /**
@@ -1955,6 +1975,17 @@ struct rte_flow_action_set_tp {
 	uint16_t port;
 };
 
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_TTL
+ *
+ * Set the TTL value directly for IPv4 or IPv6
+ * The RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
+ * must be present in pattern
+ */
+struct rte_flow_action_set_ttl {
+	uint8_t ttl_value;
+};
+
 /*
  * Definition of a single action.
  *
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify TTL
  2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
  2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 1/3] " Xiaoyu Min
@ 2018-09-25 14:37   ` Xiaoyu Min
  2018-10-03 19:51     ` Yongseok Koh
  2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: eswitch-modify TTL actions Xiaoyu Min
                     ` (3 subsequent siblings)
  5 siblings, 1 reply; 40+ messages in thread
From: Xiaoyu Min @ 2018-09-25 14:37 UTC (permalink / raw)
  To: ferruh.yigit, Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu,
	Bernard Iremonger, John McNamara, Marko Kovacevic
  Cc: dev

add commands which supports following TTL actions:
- RTE_FLOW_ACTION_TYPE_DEC_TTL
- RTE_FLOW_ACTION_TYPE_SET_TTL

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
 app/test-pmd/cmdline_flow.c                 | 34 +++++++++++++++++++++
 app/test-pmd/config.c                       |  3 ++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 +++
 3 files changed, 42 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 3935539cb..fae825462 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -255,6 +255,9 @@ enum index {
 	ACTION_SET_TP_SRC_TP_SRC,
 	ACTION_SET_TP_DST,
 	ACTION_SET_TP_DST_TP_DST,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
+	ACTION_SET_TTL_TTL,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -834,6 +837,8 @@ static const enum index next_action[] = {
 	ACTION_SET_IPV6_DST,
 	ACTION_SET_TP_SRC,
 	ACTION_SET_TP_DST,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
 	ZERO,
 };
 
@@ -972,6 +977,12 @@ static const enum index action_set_tp_dst[] = {
 	ZERO,
 };
 
+static const enum index action_set_ttl[] = {
+	ACTION_SET_TTL_TTL,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_jump[] = {
 	ACTION_JUMP_GROUP,
 	ACTION_NEXT,
@@ -2620,6 +2631,29 @@ static const struct token token_list[] = {
 			     (struct rte_flow_action_set_tp, port)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_DEC_TTL] = {
+		.name = "dec_ttl",
+		.help = "decrease network TTL if available",
+		.priv = PRIV_ACTION(DEC_TTL, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL] = {
+		.name = "set_ttl",
+		.help = "set ttl value",
+		.priv = PRIV_ACTION(SET_TTL,
+			sizeof(struct rte_flow_action_set_ttl)),
+		.next = NEXT(action_set_ttl),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL_TTL] = {
+		.name = "ttl_value",
+		.help = "new ttl value to set",
+		.next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_ttl, ttl_value)),
+		.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 d1028d03e..d28b6ed14 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -1174,6 +1174,9 @@ static const struct {
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(SET_TP_DST,
 		       sizeof(struct rte_flow_action_set_tp)),
+	MK_FLOW_ACTION(DEC_TTL, 0),
+	MK_FLOW_ACTION(SET_TTL,
+		       sizeof(struct rte_flow_action_set_ttl)),
 };
 
 /** Compute storage space needed by action configuration and copy it. */
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index f60be0862..db68c4346 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3721,6 +3721,11 @@ This section lists supported actions and their attributes, if any.
 
   - ``port``: New TCP/UDP destination port number.
 
+- ``dec_ttl``: Performs a decrease TTL value action
+
+- ``set_ttl``: Set TTL value with specificed value
+  - ``ttl_value {unsigned}``: The new TTL value to be set
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v2 3/3] net/mlx5: eswitch-modify TTL actions
  2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
  2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 1/3] " Xiaoyu Min
  2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify TTL Xiaoyu Min
@ 2018-09-25 14:37   ` Xiaoyu Min
  2018-10-05 12:48     ` Ferruh Yigit
  2018-10-03 20:35   ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Thomas Monjalon
                     ` (2 subsequent siblings)
  5 siblings, 1 reply; 40+ messages in thread
From: Xiaoyu Min @ 2018-09-25 14:37 UTC (permalink / raw)
  To: ferruh.yigit, Shahaf Shuler, Yongseok Koh; +Cc: dev

Offload following modify TTL actions to E-Switch via
TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_TTL
- RTE_FLOW_ACTION_TYPE_DEC_TTL

The corresponding IP protocol rte_flow_item_ipv[4|6]
must be present in rte_flow pattern otherwith PMD
return error

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow.h     |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c | 74 +++++++++++++++++++++++++++++++-
 2 files changed, 74 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index be182a643..5237e31dd 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -93,6 +93,8 @@
 #define MLX5_ACTION_SET_IPV6_DST (1u << 14)
 #define MLX5_ACTION_SET_TP_SRC (1u << 15)
 #define MLX5_ACTION_SET_TP_DST (1u << 16)
+#define MLX5_ACTION_SET_TTL (1u << 17)
+#define MLX5_ACTION_DEC_TTL (1u << 18)
 
 /* possible L3 layers protocols filtering. */
 #define MLX5_IP_PROTOCOL_TCP 6
diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
index 85c92f369..af88c4a0d 100644
--- a/drivers/net/mlx5/mlx5_flow_tcf.c
+++ b/drivers/net/mlx5/mlx5_flow_tcf.c
@@ -217,6 +217,10 @@ struct tc_pedit_sel {
 #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
 #endif
 
+#ifndef TTL_LEN
+#define TTL_LEN 1
+#endif
+
 /** Empty masks for known item types. */
 static const union {
 	struct rte_flow_item_port_id port_id;
@@ -297,7 +301,9 @@ struct flow_tcf_ptoi {
 		(act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC  || \
 		(act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_DST  || \
 		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC    || \
-		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST) ?    \
+		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST    || \
+		(act) == RTE_FLOW_ACTION_TYPE_SET_TTL       || \
+		(act) == RTE_FLOW_ACTION_TYPE_DEC_TTL) ?       \
 		1 : 0; })
 #define MAX_PEDIT_KEYS (128)
 #define SZ_PEDIT_KEY_VAL (4)
@@ -321,6 +327,34 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
 	return keys;
 }
 
+static void
+flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
+				struct pedit_parser *p_parser,
+				uint64_t item_flags)
+{
+	int idx = p_parser->sel.nkeys;
+
+	p_parser->keys[idx].mask = 0xFFFFFF00;
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
+		p_parser->keys[idx].off = 8; /* IPv4 TTL Offset */
+	}
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
+		p_parser->keys[idx].off = 7; /* IPv6 HopLimit Offset */
+	}
+	if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
+		p_parser->keys[idx].val = 0xFF;
+	} else {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+		p_parser->keys[idx].val =
+			((const struct rte_flow_action_set_ttl *)
+			 actions->conf)->ttl_value;
+	}
+	p_parser->sel.nkeys = (++idx);
+}
+
 static void
 flow_tcf_pedit_key_set_tp_port(const struct rte_flow_action *actions,
 				struct pedit_parser *p_parser,
@@ -408,6 +442,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
 			flow_tcf_pedit_key_set_tp_port(*actions,
 							&p_parser, item_flags);
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			flow_tcf_pedit_key_set_dec_ttl(*actions,
+							&p_parser, item_flags);
+			break;
 		default:
 			goto pedit_mnl_msg_done;
 		}
@@ -488,6 +527,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
 			keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN);
 			flags |= MLX5_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
+			flags |= MLX5_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
+			flags |= MLX5_ACTION_DEC_TTL;
+			break;
 		default:
 			goto get_pedit_action_size_done;
 		}
@@ -988,13 +1035,20 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
 			action_flags |= MLX5_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			action_flags |= MLX5_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			action_flags |= MLX5_ACTION_DEC_TTL;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ACTION,
 						  actions,
 						  "action not supported");
 		}
-		if (IS_MODIFY_ACTION(actions->type)) {
+		if (IS_MODIFY_ACTION(actions->type) &&
+		    actions->type != RTE_FLOW_ACTION_TYPE_DEC_TTL) {
 			if (!actions->conf)
 				return rte_flow_error_set(error, ENOTSUP,
 						RTE_FLOW_ERROR_TYPE_ACTION_CONF,
@@ -1029,6 +1083,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 						"no TCP/UDP item found in"
 						" pattern");
 	}
+	if (action_flags &
+	   (MLX5_ACTION_SET_TTL | MLX5_ACTION_DEC_TTL)) {
+		if (!(item_flags &
+		     (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
+		      MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
+			return rte_flow_error_set(error, ENOTSUP,
+						  RTE_FLOW_ERROR_TYPE_ACTION,
+						  actions,
+						  "no IP found in pattern");
+	}
 	return 0;
 }
 
@@ -1178,6 +1242,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			size += flow_tcf_get_pedit_actions_size(&actions,
 								&flags);
 			break;
@@ -1451,6 +1517,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 						  RTE_BE16(0x0fff)));
 			break;
 		case RTE_FLOW_ITEM_TYPE_IPV4:
+			item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
 			mask.ipv4 = flow_tcf_item_mask
 				(items, &rte_flow_item_ipv4_mask,
 				 &flow_tcf_mask_supported.ipv4,
@@ -1490,6 +1557,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 			}
 			break;
 		case RTE_FLOW_ITEM_TYPE_IPV6:
+			item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
 			mask.ipv6 = flow_tcf_item_mask
 				(items, &rte_flow_item_ipv6_mask,
 				 &flow_tcf_mask_supported.ipv6,
@@ -1718,6 +1786,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			na_act_index =
 				mnl_attr_nest_start(nlh, na_act_index_cur++);
 			flow_tcf_create_pedit_mnl_msg(nlh,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v2 1/3] ethdev: add generic TTL rewrite actions
  2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 1/3] " Xiaoyu Min
@ 2018-10-03 19:50     ` Yongseok Koh
  0 siblings, 0 replies; 40+ messages in thread
From: Yongseok Koh @ 2018-10-03 19:50 UTC (permalink / raw)
  To: Jack Min
  Cc: ferruh.yigit, Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Andrew Rybchenko, dev

On Tue, Sep 25, 2018 at 10:37:17PM +0800, Xiaoyu Min wrote:
> rewrite TTL by decrease or just set it directly
> it's not necessary to check if the final result
> is zero or not
> 
> This is slightly different from the one defined
> by openflow and more generic
> 
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---

Acked-by: Yongseok Koh <yskoh@mellanox.com>

Thanks

>  doc/guides/prog_guide/rte_flow.rst | 30 +++++++++++++++++++++++++++++
>  lib/librte_ethdev/rte_flow.c       |  2 ++
>  lib/librte_ethdev/rte_flow.h       | 31 ++++++++++++++++++++++++++++++
>  3 files changed, 63 insertions(+)
> 
> diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
> index 4faf8cb40..3aec0834b 100644
> --- a/doc/guides/prog_guide/rte_flow.rst
> +++ b/doc/guides/prog_guide/rte_flow.rst
> @@ -2166,6 +2166,36 @@ Set a new TCP/UDP destination port number.
>     | ``port`` | new TCP/UDP destination port |
>     +---------------+-------------------------+
>  
> +Action: ``DEC_TTL``
> +^^^^^^^^^^^^^^^^^^^
> +
> +Decrease TTL value.
> +
> +.. _table_rte_flow_action_dec_ttl:
> +
> +.. table:: DEC_TTL
> +
> +   +---------------+
> +   | Field         |
> +   +===============+
> +   | no properties |
> +   +---------------+
> +
> +Action: ``SET_TTL``
> +^^^^^^^^^^^^^^^^^^^
> +
> +Assigns a new TTL value.
> +
> +.. _table_rte_flow_action_set_ttl:
> +
> +.. table:: SET_TTL
> +
> +   +---------------+--------------------+
> +   | Field         | Value              |
> +   +===============+====================+
> +   | ``ttl_value`` | new TTL value      |
> +   +---------------+--------------------+
> +
>  Negative types
>  ~~~~~~~~~~~~~~
>  
> diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
> index 409c79741..631f80efd 100644
> --- a/lib/librte_ethdev/rte_flow.c
> +++ b/lib/librte_ethdev/rte_flow.c
> @@ -121,6 +121,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
>  		       sizeof(struct rte_flow_action_set_tp)),
>  	MK_FLOW_ACTION(SET_TP_DST,
>  		       sizeof(struct rte_flow_action_set_tp)),
> +	MK_FLOW_ACTION(DEC_TTL, 0),
> +	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
>  };
>  
>  static int
> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> index c80771b25..b41e37a31 100644
> --- a/lib/librte_ethdev/rte_flow.h
> +++ b/lib/librte_ethdev/rte_flow.h
> @@ -1547,6 +1547,26 @@ enum rte_flow_action_type {
>  	 * See struct rte_flow_action_set_tp.
>  	 */
>  	RTE_FLOW_ACTION_TYPE_SET_TP_DST,
> +
> +	/**
> +	 * Decrease TTL value directly
> +	 *
> +	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
> +	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
> +	 * RTE_FLOW_ERROR_TYPE_ACTION error.
> +	 */
> +	RTE_FLOW_ACTION_TYPE_DEC_TTL,
> +
> +	/**
> +	 * Set TTL value
> +	 *
> +	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
> +	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
> +	 * RTE_FLOW_ERROR_TYPE_ACTION error.
> +	 *
> +	 * See struct rte_flow_action_set_ttl
> +	 */
> +	RTE_FLOW_ACTION_TYPE_SET_TTL,
>  };
>  
>  /**
> @@ -1955,6 +1975,17 @@ struct rte_flow_action_set_tp {
>  	uint16_t port;
>  };
>  
> +/**
> + * RTE_FLOW_ACTION_TYPE_SET_TTL
> + *
> + * Set the TTL value directly for IPv4 or IPv6
> + * The RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
> + * must be present in pattern
> + */
> +struct rte_flow_action_set_ttl {
> +	uint8_t ttl_value;
> +};
> +
>  /*
>   * Definition of a single action.
>   *
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify TTL
  2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify TTL Xiaoyu Min
@ 2018-10-03 19:51     ` Yongseok Koh
  0 siblings, 0 replies; 40+ messages in thread
From: Yongseok Koh @ 2018-10-03 19:51 UTC (permalink / raw)
  To: Jack Min
  Cc: ferruh.yigit, Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu,
	Bernard Iremonger, John McNamara, Marko Kovacevic, dev

On Tue, Sep 25, 2018 at 10:37:18PM +0800, Xiaoyu Min wrote:
> add commands which supports following TTL actions:
> - RTE_FLOW_ACTION_TYPE_DEC_TTL
> - RTE_FLOW_ACTION_TYPE_SET_TTL
> 
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>

Acked-by: Yongseok Koh <yskoh@mellanox.com>

Thanks

> ---
>  app/test-pmd/cmdline_flow.c                 | 34 +++++++++++++++++++++
>  app/test-pmd/config.c                       |  3 ++
>  doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 +++
>  3 files changed, 42 insertions(+)
> 
> diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
> index 3935539cb..fae825462 100644
> --- a/app/test-pmd/cmdline_flow.c
> +++ b/app/test-pmd/cmdline_flow.c
> @@ -255,6 +255,9 @@ enum index {
>  	ACTION_SET_TP_SRC_TP_SRC,
>  	ACTION_SET_TP_DST,
>  	ACTION_SET_TP_DST_TP_DST,
> +	ACTION_DEC_TTL,
> +	ACTION_SET_TTL,
> +	ACTION_SET_TTL_TTL,
>  };
>  
>  /** Maximum size for pattern in struct rte_flow_item_raw. */
> @@ -834,6 +837,8 @@ static const enum index next_action[] = {
>  	ACTION_SET_IPV6_DST,
>  	ACTION_SET_TP_SRC,
>  	ACTION_SET_TP_DST,
> +	ACTION_DEC_TTL,
> +	ACTION_SET_TTL,
>  	ZERO,
>  };
>  
> @@ -972,6 +977,12 @@ static const enum index action_set_tp_dst[] = {
>  	ZERO,
>  };
>  
> +static const enum index action_set_ttl[] = {
> +	ACTION_SET_TTL_TTL,
> +	ACTION_NEXT,
> +	ZERO,
> +};
> +
>  static const enum index action_jump[] = {
>  	ACTION_JUMP_GROUP,
>  	ACTION_NEXT,
> @@ -2620,6 +2631,29 @@ static const struct token token_list[] = {
>  			     (struct rte_flow_action_set_tp, port)),
>  		.call = parse_vc_conf,
>  	},
> +	[ACTION_DEC_TTL] = {
> +		.name = "dec_ttl",
> +		.help = "decrease network TTL if available",
> +		.priv = PRIV_ACTION(DEC_TTL, 0),
> +		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
> +		.call = parse_vc,
> +	},
> +	[ACTION_SET_TTL] = {
> +		.name = "set_ttl",
> +		.help = "set ttl value",
> +		.priv = PRIV_ACTION(SET_TTL,
> +			sizeof(struct rte_flow_action_set_ttl)),
> +		.next = NEXT(action_set_ttl),
> +		.call = parse_vc,
> +	},
> +	[ACTION_SET_TTL_TTL] = {
> +		.name = "ttl_value",
> +		.help = "new ttl value to set",
> +		.next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
> +		.args = ARGS(ARGS_ENTRY_HTON
> +			     (struct rte_flow_action_set_ttl, ttl_value)),
> +		.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 d1028d03e..d28b6ed14 100644
> --- a/app/test-pmd/config.c
> +++ b/app/test-pmd/config.c
> @@ -1174,6 +1174,9 @@ static const struct {
>  		       sizeof(struct rte_flow_action_set_tp)),
>  	MK_FLOW_ACTION(SET_TP_DST,
>  		       sizeof(struct rte_flow_action_set_tp)),
> +	MK_FLOW_ACTION(DEC_TTL, 0),
> +	MK_FLOW_ACTION(SET_TTL,
> +		       sizeof(struct rte_flow_action_set_ttl)),
>  };
>  
>  /** Compute storage space needed by action configuration and copy it. */
> diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> index f60be0862..db68c4346 100644
> --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
> @@ -3721,6 +3721,11 @@ This section lists supported actions and their attributes, if any.
>  
>    - ``port``: New TCP/UDP destination port number.
>  
> +- ``dec_ttl``: Performs a decrease TTL value action
> +
> +- ``set_ttl``: Set TTL value with specificed value
> +  - ``ttl_value {unsigned}``: The new TTL value to be set
> +
>  Destroying flow rules
>  ~~~~~~~~~~~~~~~~~~~~~
>  
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify TTL actions
  2018-09-25 13:47 ` [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify TTL actions Xiaoyu Min
@ 2018-10-03 20:07   ` Yongseok Koh
  2018-10-08  6:57     ` Xiaoyu Min
  0 siblings, 1 reply; 40+ messages in thread
From: Yongseok Koh @ 2018-10-03 20:07 UTC (permalink / raw)
  To: Jack Min; +Cc: ferruh.yigit, Shahaf Shuler, dev

On Tue, Sep 25, 2018 at 09:47:18PM +0800, Xiaoyu Min wrote:
> Offload following modify TTL actions to E-Swtich via
> TC-Flower driver
> 
> - RTE_FLOW_ACTION_TYPE_SET_TTL
> - RTE_FLOW_ACTION_TYPE_DEC_TTL
> 
> The corresponding IP protocol rte_flow_item_ipv[4|6]
> must be present in rte_flow pattern otherwith PMD
> return error
> 
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---

As it is quite similar to the other patch of IP addr and UDP/TCP port, I have
the same comments on this patch too.

Two more things.

1) commit title.
'eswitch' isn't allowed. Like you mentioned in the commit message, it is
officially E-Switch. And I'm curious why '-' is needed for the title.

2) MLX5_ACTION_*
As there are a few more pending patches which add new actions - encap/decap and
multi-table, we may have to have final rebasing in order at the last moment.


Thanks,
Yongseok

>  drivers/net/mlx5/mlx5_flow.h     |  2 +
>  drivers/net/mlx5/mlx5_flow_tcf.c | 74 +++++++++++++++++++++++++++++++-
>  2 files changed, 74 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
> index be182a643..5237e31dd 100644
> --- a/drivers/net/mlx5/mlx5_flow.h
> +++ b/drivers/net/mlx5/mlx5_flow.h
> @@ -93,6 +93,8 @@
>  #define MLX5_ACTION_SET_IPV6_DST (1u << 14)
>  #define MLX5_ACTION_SET_TP_SRC (1u << 15)
>  #define MLX5_ACTION_SET_TP_DST (1u << 16)
> +#define MLX5_ACTION_SET_TTL (1u << 17)
> +#define MLX5_ACTION_DEC_TTL (1u << 18)
>  
>  /* possible L3 layers protocols filtering. */
>  #define MLX5_IP_PROTOCOL_TCP 6
> diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
> index 85c92f369..af88c4a0d 100644
> --- a/drivers/net/mlx5/mlx5_flow_tcf.c
> +++ b/drivers/net/mlx5/mlx5_flow_tcf.c
> @@ -217,6 +217,10 @@ struct tc_pedit_sel {
>  #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
>  #endif
>  
> +#ifndef TTL_LEN
> +#define TTL_LEN 1
> +#endif
> +
>  /** Empty masks for known item types. */
>  static const union {
>  	struct rte_flow_item_port_id port_id;
> @@ -297,7 +301,9 @@ struct flow_tcf_ptoi {
>  		(act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC  || \
>  		(act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_DST  || \
>  		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC    || \
> -		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST) ?    \
> +		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST    || \
> +		(act) == RTE_FLOW_ACTION_TYPE_SET_TTL       || \
> +		(act) == RTE_FLOW_ACTION_TYPE_DEC_TTL) ?       \
>  		1 : 0; })
>  #define MAX_PEDIT_KEYS (128)
>  #define SZ_PEDIT_KEY_VAL (4)
> @@ -321,6 +327,34 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
>  	return keys;
>  }
>  
> +static void
> +flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
> +				struct pedit_parser *p_parser,
> +				uint64_t item_flags)
> +{
> +	int idx = p_parser->sel.nkeys;
> +
> +	p_parser->keys[idx].mask = 0xFFFFFF00;
> +	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
> +		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
> +		p_parser->keys[idx].off = 8; /* IPv4 TTL Offset */
> +	}
> +	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
> +		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
> +		p_parser->keys[idx].off = 7; /* IPv6 HopLimit Offset */
> +	}
> +	if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
> +		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
> +		p_parser->keys[idx].val = 0xFF;
> +	} else {
> +		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
> +		p_parser->keys[idx].val =
> +			((const struct rte_flow_action_set_ttl *)
> +			 actions->conf)->ttl_value;
> +	}
> +	p_parser->sel.nkeys = (++idx);
> +}
> +
>  static void
>  flow_tcf_pedit_key_set_tp_port(const struct rte_flow_action *actions,
>  				struct pedit_parser *p_parser,
> @@ -408,6 +442,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
>  			flow_tcf_pedit_key_set_tp_port(*actions,
>  							&p_parser, item_flags);
>  			break;
> +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> +			flow_tcf_pedit_key_set_dec_ttl(*actions,
> +							&p_parser, item_flags);
> +			break;
>  		default:
>  			goto pedit_mnl_msg_done;
>  		}
> @@ -488,6 +527,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
>  			keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN);
>  			flags |= MLX5_ACTION_SET_TP_DST;
>  			break;
> +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> +			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> +			flags |= MLX5_ACTION_SET_TTL;
> +			break;
> +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> +			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> +			flags |= MLX5_ACTION_DEC_TTL;
> +			break;
>  		default:
>  			goto get_pedit_action_size_done;
>  		}
> @@ -988,13 +1035,20 @@ flow_tcf_validate(struct rte_eth_dev *dev,
>  		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
>  			action_flags |= MLX5_ACTION_SET_TP_DST;
>  			break;
> +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> +			action_flags |= MLX5_ACTION_SET_TTL;
> +			break;
> +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> +			action_flags |= MLX5_ACTION_DEC_TTL;
> +			break;
>  		default:
>  			return rte_flow_error_set(error, ENOTSUP,
>  						  RTE_FLOW_ERROR_TYPE_ACTION,
>  						  actions,
>  						  "action not supported");
>  		}
> -		if (IS_MODIFY_ACTION(actions->type)) {
> +		if (IS_MODIFY_ACTION(actions->type) &&
> +		    actions->type != RTE_FLOW_ACTION_TYPE_DEC_TTL) {
>  			if (!actions->conf)
>  				return rte_flow_error_set(error, ENOTSUP,
>  						RTE_FLOW_ERROR_TYPE_ACTION_CONF,
> @@ -1029,6 +1083,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
>  						"no TCP/UDP item found in"
>  						" pattern");
>  	}
> +	if (action_flags &
> +	   (MLX5_ACTION_SET_TTL | MLX5_ACTION_DEC_TTL)) {
> +		if (!(item_flags &
> +		     (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
> +		      MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
> +			return rte_flow_error_set(error, ENOTSUP,
> +						  RTE_FLOW_ERROR_TYPE_ACTION,
> +						  actions,
> +						  "no IP found in pattern");
> +	}
>  	return 0;
>  }
>  
> @@ -1178,6 +1242,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
>  		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
>  		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
>  		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
>  			size += flow_tcf_get_pedit_actions_size(&actions,
>  								&flags);
>  			break;
> @@ -1451,6 +1517,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
>  						  RTE_BE16(0x0fff)));
>  			break;
>  		case RTE_FLOW_ITEM_TYPE_IPV4:
> +			item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
>  			mask.ipv4 = flow_tcf_item_mask
>  				(items, &rte_flow_item_ipv4_mask,
>  				 &flow_tcf_mask_supported.ipv4,
> @@ -1490,6 +1557,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
>  			}
>  			break;
>  		case RTE_FLOW_ITEM_TYPE_IPV6:
> +			item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
>  			mask.ipv6 = flow_tcf_item_mask
>  				(items, &rte_flow_item_ipv6_mask,
>  				 &flow_tcf_mask_supported.ipv6,
> @@ -1718,6 +1786,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
>  		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
>  		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
>  		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
>  			na_act_index =
>  				mnl_attr_nest_start(nlh, na_act_index_cur++);
>  			flow_tcf_create_pedit_mnl_msg(nlh,
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions
  2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
                     ` (2 preceding siblings ...)
  2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: eswitch-modify TTL actions Xiaoyu Min
@ 2018-10-03 20:35   ` Thomas Monjalon
  2018-10-05 12:52   ` Ferruh Yigit
  2018-10-10 13:05   ` [dpdk-dev] [PATCH v3 " Jack Min
  5 siblings, 0 replies; 40+ messages in thread
From: Thomas Monjalon @ 2018-10-03 20:35 UTC (permalink / raw)
  To: ferruh.yigit; +Cc: dev, Xiaoyu Min, arybchenko, adrien.mazarguil

25/09/2018 16:37, Xiaoyu Min:
> Xiaoyu Min (3):
>   ethdev: add generic TTL rewrite actions
>   app/testpmd: add commands of modify TTL
>   net/mlx5: eswitch-modify TTL actions

If no more comment, I think we should accept this series.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v2 3/3] net/mlx5: eswitch-modify TTL actions
  2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: eswitch-modify TTL actions Xiaoyu Min
@ 2018-10-05 12:48     ` Ferruh Yigit
  2018-10-05 18:17       ` Yongseok Koh
  0 siblings, 1 reply; 40+ messages in thread
From: Ferruh Yigit @ 2018-10-05 12:48 UTC (permalink / raw)
  To: Xiaoyu Min, Shahaf Shuler, Yongseok Koh; +Cc: dev

On 9/25/2018 3:37 PM, Xiaoyu Min wrote:
> Offload following modify TTL actions to E-Switch via
> TC-Flower driver
> 
> - RTE_FLOW_ACTION_TYPE_SET_TTL
> - RTE_FLOW_ACTION_TYPE_DEC_TTL
> 
> The corresponding IP protocol rte_flow_item_ipv[4|6]
> must be present in rte_flow pattern otherwith PMD
> return error
> 
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>

Any comment on this?

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions
  2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
                     ` (3 preceding siblings ...)
  2018-10-03 20:35   ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Thomas Monjalon
@ 2018-10-05 12:52   ` Ferruh Yigit
  2018-10-08  2:30     ` Xiaoyu Min
  2018-10-10 13:05   ` [dpdk-dev] [PATCH v3 " Jack Min
  5 siblings, 1 reply; 40+ messages in thread
From: Ferruh Yigit @ 2018-10-05 12:52 UTC (permalink / raw)
  To: Xiaoyu Min; +Cc: dev

On 9/25/2018 3:37 PM, Xiaoyu Min wrote:
> This patch series is for RFC[1]
> 
> Patch 1 adds generic TTL rewrite actions to flow API
> Patch 2 adds corresponding testpmd commands
> Patch 3 implements the offloading logic of E-Switch rules on Mellanox MLX5
> 
> [1]: https://patches.dpdk.org/patch/43617/
> 
> V2:
>  * fix misspelled issues reported by checkpatch
> 
> Xiaoyu Min (3):
>   ethdev: add generic TTL rewrite actions
>   app/testpmd: add commands of modify TTL
>   net/mlx5: eswitch-modify TTL actions

Can you please rebase on top of latest next-net? I guess Adrien's "flow API
object converter" causing conflict with existing rte_flow patches.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v2 3/3] net/mlx5: eswitch-modify TTL actions
  2018-10-05 12:48     ` Ferruh Yigit
@ 2018-10-05 18:17       ` Yongseok Koh
  0 siblings, 0 replies; 40+ messages in thread
From: Yongseok Koh @ 2018-10-05 18:17 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: Jack Min, Shahaf Shuler, dev


> On Oct 5, 2018, at 5:48 AM, Ferruh Yigit <ferruh.yigit@intel.com> wrote:
> 
> On 9/25/2018 3:37 PM, Xiaoyu Min wrote:
>> Offload following modify TTL actions to E-Switch via
>> TC-Flower driver
>> 
>> - RTE_FLOW_ACTION_TYPE_SET_TTL
>> - RTE_FLOW_ACTION_TYPE_DEC_TTL
>> 
>> The corresponding IP protocol rte_flow_item_ipv[4|6]
>> must be present in rte_flow pattern otherwith PMD
>> return error
>> 
>> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> 
> Any comment on this?

I mistakenly put comments on the v1 [1].
Xiaoyu, please refer to that.

Ferruh, he is on vacation. He'll response once he returns.

[1] http://patches.dpdk.org/patch/45323/

Thanks,
Yongseok

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions
  2018-10-05 12:52   ` Ferruh Yigit
@ 2018-10-08  2:30     ` Xiaoyu Min
  0 siblings, 0 replies; 40+ messages in thread
From: Xiaoyu Min @ 2018-10-08  2:30 UTC (permalink / raw)
  To: Ferruh Yigit; +Cc: dev

On 18-10-05 13:52:03, Ferruh Yigit wrote:
> On 9/25/2018 3:37 PM, Xiaoyu Min wrote:
> > This patch series is for RFC[1]
> > 
> > Patch 1 adds generic TTL rewrite actions to flow API
> > Patch 2 adds corresponding testpmd commands
> > Patch 3 implements the offloading logic of E-Switch rules on Mellanox MLX5
> > 
> > [1]: https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatches.dpdk.org%2Fpatch%2F43617%2F&amp;data=02%7C01%7Cjackmin%40mellanox.com%7Cf0b174a17cc549c8c6a108d62ac15e73%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C636743407334308856&amp;sdata=WQy0UYGPK2uZOJ7hhDsMHjNhj05vx9BVpvzCwKlYjWE%3D&amp;reserved=0
> > 
> > V2:
> >  * fix misspelled issues reported by checkpatch
> > 
> > Xiaoyu Min (3):
> >   ethdev: add generic TTL rewrite actions
> >   app/testpmd: add commands of modify TTL
> >   net/mlx5: eswitch-modify TTL actions
> 
> Can you please rebase on top of latest next-net? I guess Adrien's "flow API
> object converter" causing conflict with existing rte_flow patches.
Sure, I'll rebase on latest next-net and address change requests in next version

-Jack

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify TTL actions
  2018-10-03 20:07   ` Yongseok Koh
@ 2018-10-08  6:57     ` Xiaoyu Min
  0 siblings, 0 replies; 40+ messages in thread
From: Xiaoyu Min @ 2018-10-08  6:57 UTC (permalink / raw)
  To: Yongseok Koh; +Cc: ferruh.yigit, Shahaf Shuler, dev

On 18-10-04 04:07:02, Yongseok Koh wrote:
> On Tue, Sep 25, 2018 at 09:47:18PM +0800, Xiaoyu Min wrote:
> > Offload following modify TTL actions to E-Swtich via
> > TC-Flower driver
> > 
> > - RTE_FLOW_ACTION_TYPE_SET_TTL
> > - RTE_FLOW_ACTION_TYPE_DEC_TTL
> > 
> > The corresponding IP protocol rte_flow_item_ipv[4|6]
> > must be present in rte_flow pattern otherwith PMD
> > return error
> > 
> > Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> > ---
> 
> As it is quite similar to the other patch of IP addr and UDP/TCP port, I have
> the same comments on this patch too.
> 
> Two more things.
> 
> 1) commit title.
> 'eswitch' isn't allowed. Like you mentioned in the commit message, it is
> officially E-Switch. And I'm curious why '-' is needed for the title.
> 
Yes you are right I should use officially one.
'-' is wrongly used, I will remove it.
> 2) MLX5_ACTION_*
> As there are a few more pending patches which add new actions - encap/decap and
> multi-table, we may have to have final rebasing in order at the last moment.
> 
Definitely we need.
> 
> Thanks,
> Yongseok
> 
> >  drivers/net/mlx5/mlx5_flow.h     |  2 +
> >  drivers/net/mlx5/mlx5_flow_tcf.c | 74 +++++++++++++++++++++++++++++++-
> >  2 files changed, 74 insertions(+), 2 deletions(-)
> > 
> > diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
> > index be182a643..5237e31dd 100644
> > --- a/drivers/net/mlx5/mlx5_flow.h
> > +++ b/drivers/net/mlx5/mlx5_flow.h
> > @@ -93,6 +93,8 @@
> >  #define MLX5_ACTION_SET_IPV6_DST (1u << 14)
> >  #define MLX5_ACTION_SET_TP_SRC (1u << 15)
> >  #define MLX5_ACTION_SET_TP_DST (1u << 16)
> > +#define MLX5_ACTION_SET_TTL (1u << 17)
> > +#define MLX5_ACTION_DEC_TTL (1u << 18)
> >  
> >  /* possible L3 layers protocols filtering. */
> >  #define MLX5_IP_PROTOCOL_TCP 6
> > diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
> > index 85c92f369..af88c4a0d 100644
> > --- a/drivers/net/mlx5/mlx5_flow_tcf.c
> > +++ b/drivers/net/mlx5/mlx5_flow_tcf.c
> > @@ -217,6 +217,10 @@ struct tc_pedit_sel {
> >  #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
> >  #endif
> >  
> > +#ifndef TTL_LEN
> > +#define TTL_LEN 1
> > +#endif
> > +
> >  /** Empty masks for known item types. */
> >  static const union {
> >  	struct rte_flow_item_port_id port_id;
> > @@ -297,7 +301,9 @@ struct flow_tcf_ptoi {
> >  		(act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_SRC  || \
> >  		(act) == RTE_FLOW_ACTION_TYPE_SET_IPV6_DST  || \
> >  		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_SRC    || \
> > -		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST) ?    \
> > +		(act) == RTE_FLOW_ACTION_TYPE_SET_TP_DST    || \
> > +		(act) == RTE_FLOW_ACTION_TYPE_SET_TTL       || \
> > +		(act) == RTE_FLOW_ACTION_TYPE_DEC_TTL) ?       \
> >  		1 : 0; })
> >  #define MAX_PEDIT_KEYS (128)
> >  #define SZ_PEDIT_KEY_VAL (4)
> > @@ -321,6 +327,34 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
> >  	return keys;
> >  }
> >  
> > +static void
> > +flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
> > +				struct pedit_parser *p_parser,
> > +				uint64_t item_flags)
> > +{
> > +	int idx = p_parser->sel.nkeys;
> > +
> > +	p_parser->keys[idx].mask = 0xFFFFFF00;
> > +	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
> > +		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
> > +		p_parser->keys[idx].off = 8; /* IPv4 TTL Offset */
> > +	}
> > +	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
> > +		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
> > +		p_parser->keys[idx].off = 7; /* IPv6 HopLimit Offset */
> > +	}
> > +	if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
> > +		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
> > +		p_parser->keys[idx].val = 0xFF;
> > +	} else {
> > +		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
> > +		p_parser->keys[idx].val =
> > +			((const struct rte_flow_action_set_ttl *)
> > +			 actions->conf)->ttl_value;
> > +	}
> > +	p_parser->sel.nkeys = (++idx);
> > +}
> > +
> >  static void
> >  flow_tcf_pedit_key_set_tp_port(const struct rte_flow_action *actions,
> >  				struct pedit_parser *p_parser,
> > @@ -408,6 +442,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
> >  			flow_tcf_pedit_key_set_tp_port(*actions,
> >  							&p_parser, item_flags);
> >  			break;
> > +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> > +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> > +			flow_tcf_pedit_key_set_dec_ttl(*actions,
> > +							&p_parser, item_flags);
> > +			break;
> >  		default:
> >  			goto pedit_mnl_msg_done;
> >  		}
> > @@ -488,6 +527,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
> >  			keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN);
> >  			flags |= MLX5_ACTION_SET_TP_DST;
> >  			break;
> > +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> > +			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> > +			flags |= MLX5_ACTION_SET_TTL;
> > +			break;
> > +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> > +			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> > +			flags |= MLX5_ACTION_DEC_TTL;
> > +			break;
> >  		default:
> >  			goto get_pedit_action_size_done;
> >  		}
> > @@ -988,13 +1035,20 @@ flow_tcf_validate(struct rte_eth_dev *dev,
> >  		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> >  			action_flags |= MLX5_ACTION_SET_TP_DST;
> >  			break;
> > +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> > +			action_flags |= MLX5_ACTION_SET_TTL;
> > +			break;
> > +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> > +			action_flags |= MLX5_ACTION_DEC_TTL;
> > +			break;
> >  		default:
> >  			return rte_flow_error_set(error, ENOTSUP,
> >  						  RTE_FLOW_ERROR_TYPE_ACTION,
> >  						  actions,
> >  						  "action not supported");
> >  		}
> > -		if (IS_MODIFY_ACTION(actions->type)) {
> > +		if (IS_MODIFY_ACTION(actions->type) &&
> > +		    actions->type != RTE_FLOW_ACTION_TYPE_DEC_TTL) {
> >  			if (!actions->conf)
> >  				return rte_flow_error_set(error, ENOTSUP,
> >  						RTE_FLOW_ERROR_TYPE_ACTION_CONF,
> > @@ -1029,6 +1083,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
> >  						"no TCP/UDP item found in"
> >  						" pattern");
> >  	}
> > +	if (action_flags &
> > +	   (MLX5_ACTION_SET_TTL | MLX5_ACTION_DEC_TTL)) {
> > +		if (!(item_flags &
> > +		     (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
> > +		      MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
> > +			return rte_flow_error_set(error, ENOTSUP,
> > +						  RTE_FLOW_ERROR_TYPE_ACTION,
> > +						  actions,
> > +						  "no IP found in pattern");
> > +	}
> >  	return 0;
> >  }
> >  
> > @@ -1178,6 +1242,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
> >  		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
> >  		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
> >  		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> > +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> > +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> >  			size += flow_tcf_get_pedit_actions_size(&actions,
> >  								&flags);
> >  			break;
> > @@ -1451,6 +1517,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> >  						  RTE_BE16(0x0fff)));
> >  			break;
> >  		case RTE_FLOW_ITEM_TYPE_IPV4:
> > +			item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV4;
> >  			mask.ipv4 = flow_tcf_item_mask
> >  				(items, &rte_flow_item_ipv4_mask,
> >  				 &flow_tcf_mask_supported.ipv4,
> > @@ -1490,6 +1557,7 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> >  			}
> >  			break;
> >  		case RTE_FLOW_ITEM_TYPE_IPV6:
> > +			item_flags |= MLX5_FLOW_LAYER_OUTER_L3_IPV6;
> >  			mask.ipv6 = flow_tcf_item_mask
> >  				(items, &rte_flow_item_ipv6_mask,
> >  				 &flow_tcf_mask_supported.ipv6,
> > @@ -1718,6 +1786,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
> >  		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
> >  		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
> >  		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> > +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> > +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> >  			na_act_index =
> >  				mnl_attr_nest_start(nlh, na_act_index_cur++);
> >  			flow_tcf_create_pedit_mnl_msg(nlh,
> > -- 
> > 2.17.1
> > 

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v3 0/3] ethdev: add generic TTL rewrite actions
  2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
                     ` (4 preceding siblings ...)
  2018-10-05 12:52   ` Ferruh Yigit
@ 2018-10-10 13:05   ` Jack Min
  2018-10-10 13:05     ` [dpdk-dev] [PATCH v3 1/3] " Jack Min
                       ` (3 more replies)
  5 siblings, 4 replies; 40+ messages in thread
From: Jack Min @ 2018-10-10 13:05 UTC (permalink / raw)
  Cc: dev

This patch series is for RFC[1] and depends on patch[2]

Patch 1 adds generic TTL rewrite actions to flow API
Patch 2 adds corresponding testpmd commands
Patch 3 implements the offloading logic of E-Switch rules on Mellanox MLX5

[1]: https://patches.dpdk.org/patch/43617/
[2]: https://patches.dpdk.org/patch/46490/

v2:
 * fix misspelled issues reported by checkpatch
v3:
 * rebased
 * changed commit title of patch 3
 * added example testpmd command in commit log
 * changes in validation

Xiaoyu Min (3):
  ethdev: add generic TTL rewrite actions
  app/testpmd: add commands of modify TTL
  net/mlx5: rewrite TTL by E-Switch

 app/test-pmd/cmdline_flow.c                 | 34 +++++++++
 doc/guides/prog_guide/rte_flow.rst          | 30 ++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 ++
 drivers/net/mlx5/mlx5_flow.h                |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c            | 84 ++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c                |  2 +
 lib/librte_ethdev/rte_flow.h                | 31 ++++++++
 7 files changed, 186 insertions(+), 2 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v3 1/3] ethdev: add generic TTL rewrite actions
  2018-10-10 13:05   ` [dpdk-dev] [PATCH v3 " Jack Min
@ 2018-10-10 13:05     ` Jack Min
  2018-10-10 13:05     ` [dpdk-dev] [PATCH v3 2/3] app/testpmd: add commands of modify TTL Jack Min
                       ` (2 subsequent siblings)
  3 siblings, 0 replies; 40+ messages in thread
From: Jack Min @ 2018-10-10 13:05 UTC (permalink / raw)
  To: Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko
  Cc: dev

rewrite TTL by decrease or just set it directly
it's not necessary to check if the final result
is zero or not

This is slightly different from the one defined
by openflow and more generic

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 doc/guides/prog_guide/rte_flow.rst | 30 +++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  2 ++
 lib/librte_ethdev/rte_flow.h       | 31 ++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)

diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index 93daceca2..e8df1e488 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2166,6 +2166,36 @@ Set a new TCP/UDP destination port number.
    | ``port`` | new TCP/UDP destination port |
    +---------------+-------------------------+
 
+Action: ``DEC_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Decrease TTL value.
+
+.. _table_rte_flow_action_dec_ttl:
+
+.. table:: DEC_TTL
+
+   +---------------+
+   | Field         |
+   +===============+
+   | no properties |
+   +---------------+
+
+Action: ``SET_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Assigns a new TTL value.
+
+.. _table_rte_flow_action_set_ttl:
+
+.. table:: SET_TTL
+
+   +---------------+--------------------+
+   | Field         | Value              |
+   +===============+====================+
+   | ``ttl_value`` | new TTL value      |
+   +---------------+--------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index 4eeb392b6..458a05994 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -135,6 +135,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(SET_TP_DST,
 		       sizeof(struct rte_flow_action_set_tp)),
+	MK_FLOW_ACTION(DEC_TTL, 0),
+	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
 };
 
 static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index fe7e2434f..bb07eba9d 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1548,6 +1548,26 @@ enum rte_flow_action_type {
 	 * See struct rte_flow_action_set_tp.
 	 */
 	RTE_FLOW_ACTION_TYPE_SET_TP_DST,
+
+	/**
+	 * Decrease TTL value directly
+	 *
+	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
+	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 */
+	RTE_FLOW_ACTION_TYPE_DEC_TTL,
+
+	/**
+	 * Set TTL value
+	 *
+	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
+	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_ttl
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_TTL,
 };
 
 /**
@@ -1956,6 +1976,17 @@ struct rte_flow_action_set_tp {
 	uint16_t port;
 };
 
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_TTL
+ *
+ * Set the TTL value directly for IPv4 or IPv6
+ * The RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
+ * must be present in pattern
+ */
+struct rte_flow_action_set_ttl {
+	uint8_t ttl_value;
+};
+
 /*
  * Definition of a single action.
  *
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v3 2/3] app/testpmd: add commands of modify TTL
  2018-10-10 13:05   ` [dpdk-dev] [PATCH v3 " Jack Min
  2018-10-10 13:05     ` [dpdk-dev] [PATCH v3 1/3] " Jack Min
@ 2018-10-10 13:05     ` Jack Min
  2018-10-10 13:06     ` [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
  2018-10-11 13:27     ` [dpdk-dev] [PATCH v4 0/3] ethdev: add generic TTL rewrite actions Jack Min
  3 siblings, 0 replies; 40+ messages in thread
From: Jack Min @ 2018-10-10 13:05 UTC (permalink / raw)
  To: Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu, Bernard Iremonger,
	John McNamara, Marko Kovacevic
  Cc: dev

add commands which supports following TTL actions:
- RTE_FLOW_ACTION_TYPE_DEC_TTL
- RTE_FLOW_ACTION_TYPE_SET_TTL

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 app/test-pmd/cmdline_flow.c                 | 34 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 +++
 2 files changed, 39 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 3935539cb..fae825462 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -255,6 +255,9 @@ enum index {
 	ACTION_SET_TP_SRC_TP_SRC,
 	ACTION_SET_TP_DST,
 	ACTION_SET_TP_DST_TP_DST,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
+	ACTION_SET_TTL_TTL,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -834,6 +837,8 @@ static const enum index next_action[] = {
 	ACTION_SET_IPV6_DST,
 	ACTION_SET_TP_SRC,
 	ACTION_SET_TP_DST,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
 	ZERO,
 };
 
@@ -972,6 +977,12 @@ static const enum index action_set_tp_dst[] = {
 	ZERO,
 };
 
+static const enum index action_set_ttl[] = {
+	ACTION_SET_TTL_TTL,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_jump[] = {
 	ACTION_JUMP_GROUP,
 	ACTION_NEXT,
@@ -2620,6 +2631,29 @@ static const struct token token_list[] = {
 			     (struct rte_flow_action_set_tp, port)),
 		.call = parse_vc_conf,
 	},
+	[ACTION_DEC_TTL] = {
+		.name = "dec_ttl",
+		.help = "decrease network TTL if available",
+		.priv = PRIV_ACTION(DEC_TTL, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL] = {
+		.name = "set_ttl",
+		.help = "set ttl value",
+		.priv = PRIV_ACTION(SET_TTL,
+			sizeof(struct rte_flow_action_set_ttl)),
+		.next = NEXT(action_set_ttl),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL_TTL] = {
+		.name = "ttl_value",
+		.help = "new ttl value to set",
+		.next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_ttl, ttl_value)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 86efed4bf..16cd4468e 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3728,6 +3728,11 @@ This section lists supported actions and their attributes, if any.
 
   - ``port``: New TCP/UDP destination port number.
 
+- ``dec_ttl``: Performs a decrease TTL value action
+
+- ``set_ttl``: Set TTL value with specificed value
+  - ``ttl_value {unsigned}``: The new TTL value to be set
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite TTL by E-Switch
  2018-10-10 13:05   ` [dpdk-dev] [PATCH v3 " Jack Min
  2018-10-10 13:05     ` [dpdk-dev] [PATCH v3 1/3] " Jack Min
  2018-10-10 13:05     ` [dpdk-dev] [PATCH v3 2/3] app/testpmd: add commands of modify TTL Jack Min
@ 2018-10-10 13:06     ` Jack Min
  2018-10-11  5:47       ` Yongseok Koh
  2018-10-11 13:27     ` [dpdk-dev] [PATCH v4 0/3] ethdev: add generic TTL rewrite actions Jack Min
  3 siblings, 1 reply; 40+ messages in thread
From: Jack Min @ 2018-10-10 13:06 UTC (permalink / raw)
  To: Shahaf Shuler, Yongseok Koh; +Cc: dev

Offload following modify TTL actions to E-Switch via
TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_TTL
- RTE_FLOW_ACTION_TYPE_DEC_TTL

The corresponding IP protocol rte_flow_item_ipv[4|6]
must be present in rte_flow pattern otherwith PMD
return error

The example testpmd commands are:

    flow create 0 transfer ingress
         pattern eth / ipv4 / udp dst is 7000 / end
	 actions dec_ttl /
	 port_id id 1 / end

    flow create 0 transfer ingress
         pattern eth / ipv4 / udp dst is 7001 / end
	 actions set_ttl ttl_value 10 /
	 port_id id 1 / end

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow.h     |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c | 84 +++++++++++++++++++++++++++++++-
 2 files changed, 84 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index cbb8c56c8..0ad8c12ea 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -84,6 +84,8 @@
 #define MLX5_FLOW_ACTION_SET_IPV6_DST (1u << 14)
 #define MLX5_FLOW_ACTION_SET_TP_SRC (1u << 15)
 #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
+#define MLX5_FLOW_ACTION_SET_TTL (1u << 17)
+#define MLX5_FLOW_ACTION_DEC_TTL (1u << 18)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)
diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
index 65e8a4b3f..af8a68529 100644
--- a/drivers/net/mlx5/mlx5_flow_tcf.c
+++ b/drivers/net/mlx5/mlx5_flow_tcf.c
@@ -217,6 +217,10 @@ struct tc_pedit_sel {
 #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
 #endif
 
+#ifndef TTL_LEN
+#define TTL_LEN 1
+#endif
+
 /** Empty masks for known item types. */
 static const union {
 	struct rte_flow_item_port_id port_id;
@@ -299,13 +303,16 @@ struct flow_tcf_ptoi {
 				MLX5_FLOW_ACTION_SET_IPV6_SRC | \
 				MLX5_FLOW_ACTION_SET_IPV6_DST | \
 				MLX5_FLOW_ACTION_SET_TP_SRC   | \
-				MLX5_FLOW_ACTION_SET_TP_DST)
+				MLX5_FLOW_ACTION_SET_TP_DST   | \
+				MLX5_FLOW_ACTION_SET_TTL      | \
+				MLX5_FLOW_ACTION_DEC_TTL)
 
 #define MLX5_TCF_CONFIG_ACTIONS (MLX5_FLOW_ACTION_PORT_ID | \
 				 MLX5_FLOW_ACTION_OF_PUSH_VLAN | \
 				 MLX5_FLOW_ACTION_OF_SET_VLAN_VID | \
 				 MLX5_FLOW_ACTION_OF_SET_VLAN_PCP | \
-				 MLX5_TCF_PEDIT_ACTIONS)
+				 (MLX5_TCF_PEDIT_ACTIONS & \
+				  ~MLX5_FLOW_ACTION_DEC_TTL))
 
 #define MAX_PEDIT_KEYS (128)
 #define SZ_PEDIT_KEY_VAL (4)
@@ -338,6 +345,46 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
 	return keys;
 }
 
+/**
+ * Set pedit key of decrease/set ttl
+ *
+ * @param[in] actions
+ *   pointer to action specification
+ * @param[in,out] p_parser
+ *   pointer to pedit_parser
+ * @param[in] item_flags
+ *   flags of all items presented
+ */
+static void
+flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
+				struct pedit_parser *p_parser,
+				uint64_t item_flags)
+{
+	int idx = p_parser->sel.nkeys;
+
+	p_parser->keys[idx].mask = 0xFFFFFF00;
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
+		p_parser->keys[idx].off =
+			offsetof(struct ipv4_hdr, time_to_live);
+	}
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
+		p_parser->keys[idx].off =
+			offsetof(struct ipv6_hdr, hop_limits);
+	}
+	if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
+		p_parser->keys[idx].val = 0x000000FF;
+	} else {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+		p_parser->keys[idx].val =
+			(__u32)((const struct rte_flow_action_set_ttl *)
+			 actions->conf)->ttl_value;
+	}
+	p_parser->sel.nkeys = (++idx);
+}
+
 /**
  * Set pedit key of transport (TCP/UDP) port value
  *
@@ -477,6 +524,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
 			flow_tcf_pedit_key_set_tp_port(*actions,
 							&p_parser, item_flags);
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			flow_tcf_pedit_key_set_dec_ttl(*actions,
+							&p_parser, item_flags);
+			break;
 		default:
 			goto pedit_mnl_msg_done;
 		}
@@ -557,6 +609,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
 			keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN);
 			flags |= MLX5_FLOW_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
+			flags |= MLX5_FLOW_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
+			flags |= MLX5_FLOW_ACTION_DEC_TTL;
+			break;
 		default:
 			goto get_pedit_action_size_done;
 		}
@@ -1075,6 +1135,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
 			current_action_flag = MLX5_FLOW_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			current_action_flag = MLX5_FLOW_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			current_action_flag = MLX5_FLOW_ACTION_DEC_TTL;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ACTION,
@@ -1169,6 +1235,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		return rte_flow_error_set(error, EINVAL,
 					  RTE_FLOW_ERROR_TYPE_ACTION, actions,
 					  "no fate action is found");
+	if (action_flags &
+	   (MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL)) {
+		if (!(item_flags &
+		     (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
+		      MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
+			return rte_flow_error_set(error, EINVAL,
+						  RTE_FLOW_ERROR_TYPE_ACTION,
+						  actions,
+						  "no IP found in pattern");
+	}
 	return 0;
 }
 
@@ -1318,6 +1394,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			size += flow_tcf_get_pedit_actions_size(&actions,
 								&flags);
 			break;
@@ -1862,6 +1940,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			na_act_index =
 				mnl_attr_nest_start(nlh, na_act_index_cur++);
 			flow_tcf_create_pedit_mnl_msg(nlh,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite TTL by E-Switch
  2018-10-10 13:06     ` [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
@ 2018-10-11  5:47       ` Yongseok Koh
  0 siblings, 0 replies; 40+ messages in thread
From: Yongseok Koh @ 2018-10-11  5:47 UTC (permalink / raw)
  To: Jack Min; +Cc: Shahaf Shuler, dev

On Wed, Oct 10, 2018 at 06:06:00AM -0700, Jack Min wrote:
> Offload following modify TTL actions to E-Switch via
> TC-Flower driver
> 
> - RTE_FLOW_ACTION_TYPE_SET_TTL
> - RTE_FLOW_ACTION_TYPE_DEC_TTL
> 
> The corresponding IP protocol rte_flow_item_ipv[4|6]
> must be present in rte_flow pattern otherwith PMD
> return error
> 
> The example testpmd commands are:
> 
>     flow create 0 transfer ingress
>          pattern eth / ipv4 / udp dst is 7000 / end
> 	 actions dec_ttl /
> 	 port_id id 1 / end
> 
>     flow create 0 transfer ingress
>          pattern eth / ipv4 / udp dst is 7001 / end
> 	 actions set_ttl ttl_value 10 /
> 	 port_id id 1 / end
> 
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> ---

Acked-by: Yongseok Koh <yskoh@mellanox.com>

But you should rebase it on your patch -
	net/mlx5: rewrite IP address UDP/TCP port by E-Switch

Thanks

>  drivers/net/mlx5/mlx5_flow.h     |  2 +
>  drivers/net/mlx5/mlx5_flow_tcf.c | 84 +++++++++++++++++++++++++++++++-
>  2 files changed, 84 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
> index cbb8c56c8..0ad8c12ea 100644
> --- a/drivers/net/mlx5/mlx5_flow.h
> +++ b/drivers/net/mlx5/mlx5_flow.h
> @@ -84,6 +84,8 @@
>  #define MLX5_FLOW_ACTION_SET_IPV6_DST (1u << 14)
>  #define MLX5_FLOW_ACTION_SET_TP_SRC (1u << 15)
>  #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
> +#define MLX5_FLOW_ACTION_SET_TTL (1u << 17)
> +#define MLX5_FLOW_ACTION_DEC_TTL (1u << 18)
>  
>  #define MLX5_FLOW_FATE_ACTIONS \
>  	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)
> diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
> index 65e8a4b3f..af8a68529 100644
> --- a/drivers/net/mlx5/mlx5_flow_tcf.c
> +++ b/drivers/net/mlx5/mlx5_flow_tcf.c
> @@ -217,6 +217,10 @@ struct tc_pedit_sel {
>  #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
>  #endif
>  
> +#ifndef TTL_LEN
> +#define TTL_LEN 1
> +#endif
> +
>  /** Empty masks for known item types. */
>  static const union {
>  	struct rte_flow_item_port_id port_id;
> @@ -299,13 +303,16 @@ struct flow_tcf_ptoi {
>  				MLX5_FLOW_ACTION_SET_IPV6_SRC | \
>  				MLX5_FLOW_ACTION_SET_IPV6_DST | \
>  				MLX5_FLOW_ACTION_SET_TP_SRC   | \
> -				MLX5_FLOW_ACTION_SET_TP_DST)
> +				MLX5_FLOW_ACTION_SET_TP_DST   | \
> +				MLX5_FLOW_ACTION_SET_TTL      | \
> +				MLX5_FLOW_ACTION_DEC_TTL)
>  
>  #define MLX5_TCF_CONFIG_ACTIONS (MLX5_FLOW_ACTION_PORT_ID | \
>  				 MLX5_FLOW_ACTION_OF_PUSH_VLAN | \
>  				 MLX5_FLOW_ACTION_OF_SET_VLAN_VID | \
>  				 MLX5_FLOW_ACTION_OF_SET_VLAN_PCP | \
> -				 MLX5_TCF_PEDIT_ACTIONS)
> +				 (MLX5_TCF_PEDIT_ACTIONS & \
> +				  ~MLX5_FLOW_ACTION_DEC_TTL))
>  
>  #define MAX_PEDIT_KEYS (128)
>  #define SZ_PEDIT_KEY_VAL (4)
> @@ -338,6 +345,46 @@ flow_tcf_calc_pedit_keys(const uint64_t size)
>  	return keys;
>  }
>  
> +/**
> + * Set pedit key of decrease/set ttl
> + *
> + * @param[in] actions
> + *   pointer to action specification
> + * @param[in,out] p_parser
> + *   pointer to pedit_parser
> + * @param[in] item_flags
> + *   flags of all items presented
> + */
> +static void
> +flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
> +				struct pedit_parser *p_parser,
> +				uint64_t item_flags)
> +{
> +	int idx = p_parser->sel.nkeys;
> +
> +	p_parser->keys[idx].mask = 0xFFFFFF00;
> +	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
> +		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
> +		p_parser->keys[idx].off =
> +			offsetof(struct ipv4_hdr, time_to_live);
> +	}
> +	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
> +		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
> +		p_parser->keys[idx].off =
> +			offsetof(struct ipv6_hdr, hop_limits);
> +	}
> +	if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
> +		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
> +		p_parser->keys[idx].val = 0x000000FF;
> +	} else {
> +		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
> +		p_parser->keys[idx].val =
> +			(__u32)((const struct rte_flow_action_set_ttl *)
> +			 actions->conf)->ttl_value;
> +	}
> +	p_parser->sel.nkeys = (++idx);
> +}
> +
>  /**
>   * Set pedit key of transport (TCP/UDP) port value
>   *
> @@ -477,6 +524,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
>  			flow_tcf_pedit_key_set_tp_port(*actions,
>  							&p_parser, item_flags);
>  			break;
> +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> +			flow_tcf_pedit_key_set_dec_ttl(*actions,
> +							&p_parser, item_flags);
> +			break;
>  		default:
>  			goto pedit_mnl_msg_done;
>  		}
> @@ -557,6 +609,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
>  			keys += flow_tcf_calc_pedit_keys(TP_PORT_LEN);
>  			flags |= MLX5_FLOW_ACTION_SET_TP_DST;
>  			break;
> +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> +			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> +			flags |= MLX5_FLOW_ACTION_SET_TTL;
> +			break;
> +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> +			keys += flow_tcf_calc_pedit_keys(TTL_LEN);
> +			flags |= MLX5_FLOW_ACTION_DEC_TTL;
> +			break;
>  		default:
>  			goto get_pedit_action_size_done;
>  		}
> @@ -1075,6 +1135,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
>  		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
>  			current_action_flag = MLX5_FLOW_ACTION_SET_TP_DST;
>  			break;
> +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> +			current_action_flag = MLX5_FLOW_ACTION_SET_TTL;
> +			break;
> +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
> +			current_action_flag = MLX5_FLOW_ACTION_DEC_TTL;
> +			break;
>  		default:
>  			return rte_flow_error_set(error, ENOTSUP,
>  						  RTE_FLOW_ERROR_TYPE_ACTION,
> @@ -1169,6 +1235,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
>  		return rte_flow_error_set(error, EINVAL,
>  					  RTE_FLOW_ERROR_TYPE_ACTION, actions,
>  					  "no fate action is found");
> +	if (action_flags &
> +	   (MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL)) {
> +		if (!(item_flags &
> +		     (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
> +		      MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
> +			return rte_flow_error_set(error, EINVAL,
> +						  RTE_FLOW_ERROR_TYPE_ACTION,
> +						  actions,
> +						  "no IP found in pattern");
> +	}
>  	return 0;
>  }
>  
> @@ -1318,6 +1394,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
>  		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
>  		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
>  		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
>  			size += flow_tcf_get_pedit_actions_size(&actions,
>  								&flags);
>  			break;
> @@ -1862,6 +1940,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
>  		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
>  		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
>  		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
> +		case RTE_FLOW_ACTION_TYPE_SET_TTL:
> +		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
>  			na_act_index =
>  				mnl_attr_nest_start(nlh, na_act_index_cur++);
>  			flow_tcf_create_pedit_mnl_msg(nlh,
> -- 
> 2.17.1
> 

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v4 0/3] ethdev: add generic TTL rewrite actions
  2018-10-10 13:05   ` [dpdk-dev] [PATCH v3 " Jack Min
                       ` (2 preceding siblings ...)
  2018-10-10 13:06     ` [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
@ 2018-10-11 13:27     ` Jack Min
  2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 1/3] " Jack Min
                         ` (3 more replies)
  3 siblings, 4 replies; 40+ messages in thread
From: Jack Min @ 2018-10-11 13:27 UTC (permalink / raw)
  Cc: dev

This patch series is for RFC[1] and depends on patch[2]

Patch 1 adds generic TTL rewrite actions to flow API
Patch 2 adds corresponding testpmd commands
Patch 3 implements the offloading logic of E-Switch rules on Mellanox MLX5

[1]: https://patches.dpdk.org/patch/43617/
[2]: http://patches.dpdk.org/patch/46621/

v2:
 * fix misspelled issues reported by checkpatch
v3:
 * rebased
 * changed commit title of patch 3
 * added example testpmd command in commit log
 * changes in validation
v4:
 * fix some coding style issues
 * use macro of calc pedit keys
 * rebased

Xiaoyu Min (3):
  ethdev: add generic TTL rewrite actions
  app/testpmd: add commands of modify TTL
  net/mlx5: rewrite TTL by E-Switch

 app/test-pmd/cmdline_flow.c                 | 34 +++++++++
 doc/guides/prog_guide/rte_flow.rst          | 24 ++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 ++
 drivers/net/mlx5/mlx5_flow.h                |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c            | 82 ++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c                |  2 +
 lib/librte_ethdev/rte_flow.h                | 31 ++++++++
 7 files changed, 178 insertions(+), 2 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v4 1/3] ethdev: add generic TTL rewrite actions
  2018-10-11 13:27     ` [dpdk-dev] [PATCH v4 0/3] ethdev: add generic TTL rewrite actions Jack Min
@ 2018-10-11 13:27       ` Jack Min
  2018-10-12 14:12         ` Ferruh Yigit
  2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 2/3] app/testpmd: add commands of modify TTL Jack Min
                         ` (2 subsequent siblings)
  3 siblings, 1 reply; 40+ messages in thread
From: Jack Min @ 2018-10-11 13:27 UTC (permalink / raw)
  To: Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko
  Cc: dev

rewrite TTL by decrease or just set it directly
it's not necessary to check if the final result
is zero or not

This is slightly different from the one defined
by openflow and more generic

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 doc/guides/prog_guide/rte_flow.rst | 24 +++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  2 ++
 lib/librte_ethdev/rte_flow.h       | 31 ++++++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)

diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index a5ec441c9..9fc5b88f2 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2197,12 +2197,36 @@ Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
 
 .. table:: MAC_SWAP
 
+Action: ``DEC_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Decrease TTL value.
+
+.. _table_rte_flow_action_dec_ttl:
+
+.. table:: DEC_TTL
+
    +---------------+
    | Field         |
    +===============+
    | no properties |
    +---------------+
 
+Action: ``SET_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Assigns a new TTL value.
+
+.. _table_rte_flow_action_set_ttl:
+
+.. table:: SET_TTL
+
+   +---------------+--------------------+
+   | Field         | Value              |
+   +===============+====================+
+   | ``ttl_value`` | new TTL value      |
+   +---------------+--------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index bc9e719dc..5040c7667 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -136,6 +136,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 	MK_FLOW_ACTION(SET_TP_DST,
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(MAC_SWAP, 0),
+	MK_FLOW_ACTION(DEC_TTL, 0),
+	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
 };
 
 static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index 68bbf57d0..f102e6939 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1579,6 +1579,26 @@ enum rte_flow_action_type {
 	 * No associated configuration structure.
 	 */
 	RTE_FLOW_ACTION_TYPE_MAC_SWAP,
+
+	/**
+	 * Decrease TTL value directly
+	 *
+	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
+	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 */
+	RTE_FLOW_ACTION_TYPE_DEC_TTL,
+
+	/**
+	 * Set TTL value
+	 *
+	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
+	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_ttl
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_TTL,
 };
 
 /**
@@ -1987,6 +2007,17 @@ struct rte_flow_action_set_tp {
 	rte_be16_t port;
 };
 
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_TTL
+ *
+ * Set the TTL value directly for IPv4 or IPv6
+ * The RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
+ * must be present in pattern
+ */
+struct rte_flow_action_set_ttl {
+	uint8_t ttl_value;
+};
+
 /*
  * Definition of a single action.
  *
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v4 2/3] app/testpmd: add commands of modify TTL
  2018-10-11 13:27     ` [dpdk-dev] [PATCH v4 0/3] ethdev: add generic TTL rewrite actions Jack Min
  2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 1/3] " Jack Min
@ 2018-10-11 13:27       ` Jack Min
  2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
  2018-10-13  3:24       ` [dpdk-dev] [PATCH v5 0/3] ethdev: add generic TTL rewrite actions Jack Min
  3 siblings, 0 replies; 40+ messages in thread
From: Jack Min @ 2018-10-11 13:27 UTC (permalink / raw)
  To: Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu, Bernard Iremonger,
	John McNamara, Marko Kovacevic
  Cc: dev

add commands which supports following TTL actions:
- RTE_FLOW_ACTION_TYPE_DEC_TTL
- RTE_FLOW_ACTION_TYPE_SET_TTL

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 app/test-pmd/cmdline_flow.c                 | 34 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 +++
 2 files changed, 39 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 4a2764270..3efc2d86e 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -256,6 +256,9 @@ enum index {
 	ACTION_SET_TP_DST,
 	ACTION_SET_TP_DST_TP_DST,
 	ACTION_MAC_SWAP,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
+	ACTION_SET_TTL_TTL,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -836,6 +839,8 @@ static const enum index next_action[] = {
 	ACTION_SET_TP_SRC,
 	ACTION_SET_TP_DST,
 	ACTION_MAC_SWAP,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
 	ZERO,
 };
 
@@ -974,6 +979,12 @@ static const enum index action_set_tp_dst[] = {
 	ZERO,
 };
 
+static const enum index action_set_ttl[] = {
+	ACTION_SET_TTL_TTL,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_jump[] = {
 	ACTION_JUMP_GROUP,
 	ACTION_NEXT,
@@ -2636,6 +2647,29 @@ static const struct token token_list[] = {
 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
 		.call = parse_vc,
 	},
+	[ACTION_DEC_TTL] = {
+		.name = "dec_ttl",
+		.help = "decrease network TTL if available",
+		.priv = PRIV_ACTION(DEC_TTL, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL] = {
+		.name = "set_ttl",
+		.help = "set ttl value",
+		.priv = PRIV_ACTION(SET_TTL,
+			sizeof(struct rte_flow_action_set_ttl)),
+		.next = NEXT(action_set_ttl),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL_TTL] = {
+		.name = "ttl_value",
+		.help = "new ttl value to set",
+		.next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_ttl, ttl_value)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 74769cd48..77233987b 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3739,6 +3739,11 @@ This section lists supported actions and their attributes, if any.
 - ``mac_swap``: Swap the source and destination MAC addresses in the outermost
   Ethernet header.
 
+- ``dec_ttl``: Performs a decrease TTL value action
+
+- ``set_ttl``: Set TTL value with specificed value
+  - ``ttl_value {unsigned}``: The new TTL value to be set
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v4 3/3] net/mlx5: rewrite TTL by E-Switch
  2018-10-11 13:27     ` [dpdk-dev] [PATCH v4 0/3] ethdev: add generic TTL rewrite actions Jack Min
  2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 1/3] " Jack Min
  2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 2/3] app/testpmd: add commands of modify TTL Jack Min
@ 2018-10-11 13:27       ` Jack Min
  2018-10-13  3:24       ` [dpdk-dev] [PATCH v5 0/3] ethdev: add generic TTL rewrite actions Jack Min
  3 siblings, 0 replies; 40+ messages in thread
From: Jack Min @ 2018-10-11 13:27 UTC (permalink / raw)
  To: Shahaf Shuler, Yongseok Koh; +Cc: dev

Offload following modify TTL actions to E-Switch via
TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_TTL
- RTE_FLOW_ACTION_TYPE_DEC_TTL

The corresponding IP protocol rte_flow_item_ipv[4|6]
must be present in rte_flow pattern otherwith PMD
return error

The example testpmd commands are:

    flow create 0 transfer ingress
         pattern eth / ipv4 / udp dst is 7000 / end
	 actions dec_ttl /
	 port_id id 1 / end

    flow create 0 transfer ingress
         pattern eth / ipv4 / udp dst is 7001 / end
	 actions set_ttl ttl_value 10 /
	 port_id id 1 / end

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow.h     |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c | 82 +++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index c592828b5..cb07cf652 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -84,6 +84,8 @@
 #define MLX5_FLOW_ACTION_SET_IPV6_DST (1u << 14)
 #define MLX5_FLOW_ACTION_SET_TP_SRC (1u << 15)
 #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
+#define MLX5_FLOW_ACTION_SET_TTL (1u << 17)
+#define MLX5_FLOW_ACTION_DEC_TTL (1u << 18)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)
diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
index 44c899830..a0a3680d5 100644
--- a/drivers/net/mlx5/mlx5_flow_tcf.c
+++ b/drivers/net/mlx5/mlx5_flow_tcf.c
@@ -218,6 +218,10 @@ struct tc_pedit_sel {
 #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
 #endif
 
+#ifndef TTL_LEN
+#define TTL_LEN 1
+#endif
+
 /** Empty masks for known item types. */
 static const union {
 	struct rte_flow_item_port_id port_id;
@@ -298,12 +302,13 @@ struct flow_tcf_ptoi {
 #define MLX5_TCF_PEDIT_ACTIONS \
 	(MLX5_FLOW_ACTION_SET_IPV4_SRC | MLX5_FLOW_ACTION_SET_IPV4_DST | \
 	 MLX5_FLOW_ACTION_SET_IPV6_SRC | MLX5_FLOW_ACTION_SET_IPV6_DST | \
-	 MLX5_FLOW_ACTION_SET_TP_SRC | MLX5_FLOW_ACTION_SET_TP_DST)
+	 MLX5_FLOW_ACTION_SET_TP_SRC | MLX5_FLOW_ACTION_SET_TP_DST | \
+	 MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL)
 
 #define MLX5_TCF_CONFIG_ACTIONS \
 	(MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_OF_PUSH_VLAN | \
 	 MLX5_FLOW_ACTION_OF_SET_VLAN_VID | MLX5_FLOW_ACTION_OF_SET_VLAN_PCP | \
-	 MLX5_TCF_PEDIT_ACTIONS)
+	 (MLX5_TCF_PEDIT_ACTIONS & ~MLX5_FLOW_ACTION_DEC_TTL))
 
 #define MAX_PEDIT_KEYS 128
 #define SZ_PEDIT_KEY_VAL 4
@@ -323,6 +328,46 @@ struct pedit_parser {
 };
 
 
+/**
+ * Set pedit key of decrease/set ttl
+ *
+ * @param[in] actions
+ *   pointer to action specification
+ * @param[in,out] p_parser
+ *   pointer to pedit_parser
+ * @param[in] item_flags
+ *   flags of all items presented
+ */
+static void
+flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
+				struct pedit_parser *p_parser,
+				uint64_t item_flags)
+{
+	int idx = p_parser->sel.nkeys;
+
+	p_parser->keys[idx].mask = 0xFFFFFF00;
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
+		p_parser->keys[idx].off =
+			offsetof(struct ipv4_hdr, time_to_live);
+	}
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
+		p_parser->keys[idx].off =
+			offsetof(struct ipv6_hdr, hop_limits);
+	}
+	if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
+		p_parser->keys[idx].val = 0x000000FF;
+	} else {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+		p_parser->keys[idx].val =
+			(__u32)((const struct rte_flow_action_set_ttl *)
+			 actions->conf)->ttl_value;
+	}
+	p_parser->sel.nkeys = (++idx);
+}
+
 /**
  * Set pedit key of transport (TCP/UDP) port value
  *
@@ -458,6 +503,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
 			flow_tcf_pedit_key_set_tp_port(*actions,
 							&p_parser, item_flags);
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			flow_tcf_pedit_key_set_dec_ttl(*actions,
+							&p_parser, item_flags);
+			break;
 		default:
 			goto pedit_mnl_msg_done;
 		}
@@ -538,6 +588,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
 			keys += NUM_OF_PEDIT_KEYS(TP_PORT_LEN);
 			flags |= MLX5_FLOW_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			keys += NUM_OF_PEDIT_KEYS(TTL_LEN);
+			flags |= MLX5_FLOW_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			keys += NUM_OF_PEDIT_KEYS(TTL_LEN);
+			flags |= MLX5_FLOW_ACTION_DEC_TTL;
+			break;
 		default:
 			goto get_pedit_action_size_done;
 		}
@@ -1058,6 +1116,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
 			current_action_flag = MLX5_FLOW_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			current_action_flag = MLX5_FLOW_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			current_action_flag = MLX5_FLOW_ACTION_DEC_TTL;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ACTION,
@@ -1153,6 +1217,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		return rte_flow_error_set(error, EINVAL,
 					  RTE_FLOW_ERROR_TYPE_ACTION, actions,
 					  "no fate action is found");
+	if (action_flags &
+	   (MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL)) {
+		if (!(item_flags &
+		     (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
+		      MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
+			return rte_flow_error_set(error, EINVAL,
+						  RTE_FLOW_ERROR_TYPE_ACTION,
+						  actions,
+						  "no IP found in pattern");
+	}
 	return 0;
 }
 
@@ -1302,6 +1376,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			size += flow_tcf_get_pedit_actions_size(&actions,
 								&flags);
 			break;
@@ -1846,6 +1922,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			na_act_index =
 				mnl_attr_nest_start(nlh, na_act_index_cur++);
 			flow_tcf_create_pedit_mnl_msg(nlh,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v4 1/3] ethdev: add generic TTL rewrite actions
  2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 1/3] " Jack Min
@ 2018-10-12 14:12         ` Ferruh Yigit
  2018-10-13  2:16           ` Jack Min
  0 siblings, 1 reply; 40+ messages in thread
From: Ferruh Yigit @ 2018-10-12 14:12 UTC (permalink / raw)
  To: Jack Min, Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Andrew Rybchenko
  Cc: dev

On 10/11/2018 2:27 PM, Jack Min wrote:
> rewrite TTL by decrease or just set it directly
> it's not necessary to check if the final result
> is zero or not
> 
> This is slightly different from the one defined
> by openflow and more generic
> 
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> Acked-by: Yongseok Koh <yskoh@mellanox.com>
> ---
>  doc/guides/prog_guide/rte_flow.rst | 24 +++++++++++++++++++++++

Getting following documentation warning, can you please check:

rte_flow.rst:2198: WARNING: Content block expected for the "table" directive;
none found.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v4 1/3] ethdev: add generic TTL rewrite actions
  2018-10-12 14:12         ` Ferruh Yigit
@ 2018-10-13  2:16           ` Jack Min
  0 siblings, 0 replies; 40+ messages in thread
From: Jack Min @ 2018-10-13  2:16 UTC (permalink / raw)
  To: Ferruh Yigit
  Cc: Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Andrew Rybchenko, dev

On 18-10-12 15:12:06, Ferruh Yigit wrote:
> On 10/11/2018 2:27 PM, Jack Min wrote:
> > rewrite TTL by decrease or just set it directly
> > it's not necessary to check if the final result
> > is zero or not
> > 
> > This is slightly different from the one defined
> > by openflow and more generic
> > 
> > Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> > Acked-by: Yongseok Koh <yskoh@mellanox.com>
> > ---
> >  doc/guides/prog_guide/rte_flow.rst | 24 +++++++++++++++++++++++
> 
> Getting following documentation warning, can you please check:
> 
> rte_flow.rst:2198: WARNING: Content block expected for the "table" directive;
> none found.
> 
Yes, of course.

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v5 0/3] ethdev: add generic TTL rewrite actions
  2018-10-11 13:27     ` [dpdk-dev] [PATCH v4 0/3] ethdev: add generic TTL rewrite actions Jack Min
                         ` (2 preceding siblings ...)
  2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
@ 2018-10-13  3:24       ` Jack Min
  2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 1/3] " Jack Min
                           ` (3 more replies)
  3 siblings, 4 replies; 40+ messages in thread
From: Jack Min @ 2018-10-13  3:24 UTC (permalink / raw)
  Cc: dev

This patch series is for RFC[1] and depends on patch[2]

Patch 1 adds generic TTL rewrite actions to flow API
Patch 2 adds corresponding testpmd commands
Patch 3 implements the offloading logic of E-Switch rules on Mellanox MLX5

[1]: https://patches.dpdk.org/patch/43617/
[2]: http://patches.dpdk.org/patch/46621/

v2:
 * fix misspelled issues reported by checkpatch
v3:
 * rebased
 * changed commit title of patch 3
 * added example testpmd command in commit log
 * changes in validation
v4:
 * fix some coding style issues
 * use macro of calc pedit keys
 * rebased
v5:
 * fix document warning of rte_flow.rst introduced by v4

Xiaoyu Min (3):
  ethdev: add generic TTL rewrite actions
  app/testpmd: add commands of modify TTL
  net/mlx5: rewrite TTL by E-Switch

 app/test-pmd/cmdline_flow.c                 | 34 +++++++++
 doc/guides/prog_guide/rte_flow.rst          | 30 ++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 ++
 drivers/net/mlx5/mlx5_flow.h                |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c            | 82 ++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c                |  2 +
 lib/librte_ethdev/rte_flow.h                | 31 ++++++++
 7 files changed, 184 insertions(+), 2 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v5 1/3] ethdev: add generic TTL rewrite actions
  2018-10-13  3:24       ` [dpdk-dev] [PATCH v5 0/3] ethdev: add generic TTL rewrite actions Jack Min
@ 2018-10-13  3:24         ` Jack Min
  2018-10-14  7:35           ` Andrew Rybchenko
  2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 2/3] app/testpmd: add commands of modify TTL Jack Min
                           ` (2 subsequent siblings)
  3 siblings, 1 reply; 40+ messages in thread
From: Jack Min @ 2018-10-13  3:24 UTC (permalink / raw)
  To: Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko
  Cc: dev

rewrite TTL by decrease or just set it directly
it's not necessary to check if the final result
is zero or not

This is slightly different from the one defined
by openflow and more generic

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 doc/guides/prog_guide/rte_flow.rst | 30 +++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  2 ++
 lib/librte_ethdev/rte_flow.h       | 31 ++++++++++++++++++++++++++++++
 3 files changed, 63 insertions(+)

diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index a5ec441c9..12f3eb794 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2203,6 +2203,36 @@ Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
    | no properties |
    +---------------+
 
+Action: ``DEC_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Decrease TTL value.
+
+.. _table_rte_flow_action_dec_ttl:
+
+.. table:: DEC_TTL
+
+   +---------------+
+   | Field         |
+   +===============+
+   | no properties |
+   +---------------+
+
+Action: ``SET_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Assigns a new TTL value.
+
+.. _table_rte_flow_action_set_ttl:
+
+.. table:: SET_TTL
+
+   +---------------+--------------------+
+   | Field         | Value              |
+   +===============+====================+
+   | ``ttl_value`` | new TTL value      |
+   +---------------+--------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index bc9e719dc..5040c7667 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -136,6 +136,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 	MK_FLOW_ACTION(SET_TP_DST,
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(MAC_SWAP, 0),
+	MK_FLOW_ACTION(DEC_TTL, 0),
+	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
 };
 
 static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index 68bbf57d0..f102e6939 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1579,6 +1579,26 @@ enum rte_flow_action_type {
 	 * No associated configuration structure.
 	 */
 	RTE_FLOW_ACTION_TYPE_MAC_SWAP,
+
+	/**
+	 * Decrease TTL value directly
+	 *
+	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
+	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 */
+	RTE_FLOW_ACTION_TYPE_DEC_TTL,
+
+	/**
+	 * Set TTL value
+	 *
+	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
+	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
+	 * RTE_FLOW_ERROR_TYPE_ACTION error.
+	 *
+	 * See struct rte_flow_action_set_ttl
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_TTL,
 };
 
 /**
@@ -1987,6 +2007,17 @@ struct rte_flow_action_set_tp {
 	rte_be16_t port;
 };
 
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_TTL
+ *
+ * Set the TTL value directly for IPv4 or IPv6
+ * The RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
+ * must be present in pattern
+ */
+struct rte_flow_action_set_ttl {
+	uint8_t ttl_value;
+};
+
 /*
  * Definition of a single action.
  *
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v5 2/3] app/testpmd: add commands of modify TTL
  2018-10-13  3:24       ` [dpdk-dev] [PATCH v5 0/3] ethdev: add generic TTL rewrite actions Jack Min
  2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 1/3] " Jack Min
@ 2018-10-13  3:24         ` Jack Min
  2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
  2018-10-16  8:14         ` [dpdk-dev] [PATCH v6 0/3] ethdev: add generic TTL rewrite actions Jack Min
  3 siblings, 0 replies; 40+ messages in thread
From: Jack Min @ 2018-10-13  3:24 UTC (permalink / raw)
  To: Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu, Bernard Iremonger,
	John McNamara, Marko Kovacevic
  Cc: dev

add commands which supports following TTL actions:
- RTE_FLOW_ACTION_TYPE_DEC_TTL
- RTE_FLOW_ACTION_TYPE_SET_TTL

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 app/test-pmd/cmdline_flow.c                 | 34 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 +++
 2 files changed, 39 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 4a2764270..3efc2d86e 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -256,6 +256,9 @@ enum index {
 	ACTION_SET_TP_DST,
 	ACTION_SET_TP_DST_TP_DST,
 	ACTION_MAC_SWAP,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
+	ACTION_SET_TTL_TTL,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -836,6 +839,8 @@ static const enum index next_action[] = {
 	ACTION_SET_TP_SRC,
 	ACTION_SET_TP_DST,
 	ACTION_MAC_SWAP,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
 	ZERO,
 };
 
@@ -974,6 +979,12 @@ static const enum index action_set_tp_dst[] = {
 	ZERO,
 };
 
+static const enum index action_set_ttl[] = {
+	ACTION_SET_TTL_TTL,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_jump[] = {
 	ACTION_JUMP_GROUP,
 	ACTION_NEXT,
@@ -2636,6 +2647,29 @@ static const struct token token_list[] = {
 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
 		.call = parse_vc,
 	},
+	[ACTION_DEC_TTL] = {
+		.name = "dec_ttl",
+		.help = "decrease network TTL if available",
+		.priv = PRIV_ACTION(DEC_TTL, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL] = {
+		.name = "set_ttl",
+		.help = "set ttl value",
+		.priv = PRIV_ACTION(SET_TTL,
+			sizeof(struct rte_flow_action_set_ttl)),
+		.next = NEXT(action_set_ttl),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL_TTL] = {
+		.name = "ttl_value",
+		.help = "new ttl value to set",
+		.next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_ttl, ttl_value)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 74769cd48..77233987b 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3739,6 +3739,11 @@ This section lists supported actions and their attributes, if any.
 - ``mac_swap``: Swap the source and destination MAC addresses in the outermost
   Ethernet header.
 
+- ``dec_ttl``: Performs a decrease TTL value action
+
+- ``set_ttl``: Set TTL value with specificed value
+  - ``ttl_value {unsigned}``: The new TTL value to be set
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v5 3/3] net/mlx5: rewrite TTL by E-Switch
  2018-10-13  3:24       ` [dpdk-dev] [PATCH v5 0/3] ethdev: add generic TTL rewrite actions Jack Min
  2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 1/3] " Jack Min
  2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 2/3] app/testpmd: add commands of modify TTL Jack Min
@ 2018-10-13  3:24         ` Jack Min
  2018-10-16  8:14         ` [dpdk-dev] [PATCH v6 0/3] ethdev: add generic TTL rewrite actions Jack Min
  3 siblings, 0 replies; 40+ messages in thread
From: Jack Min @ 2018-10-13  3:24 UTC (permalink / raw)
  To: Shahaf Shuler, Yongseok Koh; +Cc: dev

Offload following modify TTL actions to E-Switch via
TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_TTL
- RTE_FLOW_ACTION_TYPE_DEC_TTL

The corresponding IP protocol rte_flow_item_ipv[4|6]
must be present in rte_flow pattern otherwith PMD
return error

The example testpmd commands are:

    flow create 0 transfer ingress
         pattern eth / ipv4 / udp dst is 7000 / end
	 actions dec_ttl /
	 port_id id 1 / end

    flow create 0 transfer ingress
         pattern eth / ipv4 / udp dst is 7001 / end
	 actions set_ttl ttl_value 10 /
	 port_id id 1 / end

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow.h     |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c | 82 +++++++++++++++++++++++++++++++-
 2 files changed, 82 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index c592828b5..cb07cf652 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -84,6 +84,8 @@
 #define MLX5_FLOW_ACTION_SET_IPV6_DST (1u << 14)
 #define MLX5_FLOW_ACTION_SET_TP_SRC (1u << 15)
 #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
+#define MLX5_FLOW_ACTION_SET_TTL (1u << 17)
+#define MLX5_FLOW_ACTION_DEC_TTL (1u << 18)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)
diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
index 44c899830..a0a3680d5 100644
--- a/drivers/net/mlx5/mlx5_flow_tcf.c
+++ b/drivers/net/mlx5/mlx5_flow_tcf.c
@@ -218,6 +218,10 @@ struct tc_pedit_sel {
 #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
 #endif
 
+#ifndef TTL_LEN
+#define TTL_LEN 1
+#endif
+
 /** Empty masks for known item types. */
 static const union {
 	struct rte_flow_item_port_id port_id;
@@ -298,12 +302,13 @@ struct flow_tcf_ptoi {
 #define MLX5_TCF_PEDIT_ACTIONS \
 	(MLX5_FLOW_ACTION_SET_IPV4_SRC | MLX5_FLOW_ACTION_SET_IPV4_DST | \
 	 MLX5_FLOW_ACTION_SET_IPV6_SRC | MLX5_FLOW_ACTION_SET_IPV6_DST | \
-	 MLX5_FLOW_ACTION_SET_TP_SRC | MLX5_FLOW_ACTION_SET_TP_DST)
+	 MLX5_FLOW_ACTION_SET_TP_SRC | MLX5_FLOW_ACTION_SET_TP_DST | \
+	 MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL)
 
 #define MLX5_TCF_CONFIG_ACTIONS \
 	(MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_OF_PUSH_VLAN | \
 	 MLX5_FLOW_ACTION_OF_SET_VLAN_VID | MLX5_FLOW_ACTION_OF_SET_VLAN_PCP | \
-	 MLX5_TCF_PEDIT_ACTIONS)
+	 (MLX5_TCF_PEDIT_ACTIONS & ~MLX5_FLOW_ACTION_DEC_TTL))
 
 #define MAX_PEDIT_KEYS 128
 #define SZ_PEDIT_KEY_VAL 4
@@ -323,6 +328,46 @@ struct pedit_parser {
 };
 
 
+/**
+ * Set pedit key of decrease/set ttl
+ *
+ * @param[in] actions
+ *   pointer to action specification
+ * @param[in,out] p_parser
+ *   pointer to pedit_parser
+ * @param[in] item_flags
+ *   flags of all items presented
+ */
+static void
+flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
+				struct pedit_parser *p_parser,
+				uint64_t item_flags)
+{
+	int idx = p_parser->sel.nkeys;
+
+	p_parser->keys[idx].mask = 0xFFFFFF00;
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
+		p_parser->keys[idx].off =
+			offsetof(struct ipv4_hdr, time_to_live);
+	}
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
+		p_parser->keys[idx].off =
+			offsetof(struct ipv6_hdr, hop_limits);
+	}
+	if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
+		p_parser->keys[idx].val = 0x000000FF;
+	} else {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+		p_parser->keys[idx].val =
+			(__u32)((const struct rte_flow_action_set_ttl *)
+			 actions->conf)->ttl_value;
+	}
+	p_parser->sel.nkeys = (++idx);
+}
+
 /**
  * Set pedit key of transport (TCP/UDP) port value
  *
@@ -458,6 +503,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
 			flow_tcf_pedit_key_set_tp_port(*actions,
 							&p_parser, item_flags);
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			flow_tcf_pedit_key_set_dec_ttl(*actions,
+							&p_parser, item_flags);
+			break;
 		default:
 			goto pedit_mnl_msg_done;
 		}
@@ -538,6 +588,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
 			keys += NUM_OF_PEDIT_KEYS(TP_PORT_LEN);
 			flags |= MLX5_FLOW_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			keys += NUM_OF_PEDIT_KEYS(TTL_LEN);
+			flags |= MLX5_FLOW_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			keys += NUM_OF_PEDIT_KEYS(TTL_LEN);
+			flags |= MLX5_FLOW_ACTION_DEC_TTL;
+			break;
 		default:
 			goto get_pedit_action_size_done;
 		}
@@ -1058,6 +1116,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
 			current_action_flag = MLX5_FLOW_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			current_action_flag = MLX5_FLOW_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			current_action_flag = MLX5_FLOW_ACTION_DEC_TTL;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ACTION,
@@ -1153,6 +1217,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		return rte_flow_error_set(error, EINVAL,
 					  RTE_FLOW_ERROR_TYPE_ACTION, actions,
 					  "no fate action is found");
+	if (action_flags &
+	   (MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL)) {
+		if (!(item_flags &
+		     (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
+		      MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
+			return rte_flow_error_set(error, EINVAL,
+						  RTE_FLOW_ERROR_TYPE_ACTION,
+						  actions,
+						  "no IP found in pattern");
+	}
 	return 0;
 }
 
@@ -1302,6 +1376,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			size += flow_tcf_get_pedit_actions_size(&actions,
 								&flags);
 			break;
@@ -1846,6 +1922,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			na_act_index =
 				mnl_attr_nest_start(nlh, na_act_index_cur++);
 			flow_tcf_create_pedit_mnl_msg(nlh,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v5 1/3] ethdev: add generic TTL rewrite actions
  2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 1/3] " Jack Min
@ 2018-10-14  7:35           ` Andrew Rybchenko
  2018-10-16  2:03             ` Jack Min
  0 siblings, 1 reply; 40+ messages in thread
From: Andrew Rybchenko @ 2018-10-14  7:35 UTC (permalink / raw)
  To: Jack Min, Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Ferruh Yigit
  Cc: dev

On 13.10.2018 06:24, Jack Min wrote:
> rewrite TTL by decrease or just set it directly
> it's not necessary to check if the final result
> is zero or not
>
> This is slightly different from the one defined
> by openflow and more generic
>
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> Acked-by: Yongseok Koh <yskoh@mellanox.com>
> ---

[...]

> diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> index 68bbf57d0..f102e6939 100644
> --- a/lib/librte_ethdev/rte_flow.h
> +++ b/lib/librte_ethdev/rte_flow.h
> @@ -1579,6 +1579,26 @@ enum rte_flow_action_type {
>   	 * No associated configuration structure.
>   	 */
>   	RTE_FLOW_ACTION_TYPE_MAC_SWAP,
> +
> +	/**
> +	 * Decrease TTL value directly
> +	 *
> +	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
> +	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
> +	 * RTE_FLOW_ERROR_TYPE_ACTION error.
> +	 */
> +	RTE_FLOW_ACTION_TYPE_DEC_TTL,
> +
> +	/**
> +	 * Set TTL value
> +	 *
> +	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
> +	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
> +	 * RTE_FLOW_ERROR_TYPE_ACTION error.
> +	 *
> +	 * See struct rte_flow_action_set_ttl
> +	 */
> +	RTE_FLOW_ACTION_TYPE_SET_TTL,
>   };
>   
>   /**

As I understand it is one more case where the following note from Adrien
is applicable [1]:

<begin quote>

Another problem is that you must not require actions to rely on specific
pattern content:

  [...]
  *
  * Decapsulate outer most tunnel from matched flow.
  *
  * The flow pattern must have a valid tunnel header
  */
  RTE_FLOW_ACTION_TYPE_TUNNEL_DECAP,

For maximum flexibility, all actions should be usable on their own on empty
pattern. On the other hand, you can document undefined behavior when
performing some action on traffic that doesn't contain something.

Reason is that invalid traffic may have already been removed by other flow
rules (or whatever happens) before such a rule is reached; it's a user's
responsibility to provide such guarantee.

When parsing an action, a PMD is not supposed to look at the pattern. Action
list should contain all the needed info, otherwise it means the API is badly
defined.

I'm aware the above makes it tough to implement something like
RTE_FLOW_ACTION_TYPE_TUNNEL_DECAP as defined in this series, but that's
unfortunately why I think it must not be defined like that.

<end quote>

[1] https://mails.dpdk.org/archives/dev/2018-October/115267.html

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v5 1/3] ethdev: add generic TTL rewrite actions
  2018-10-14  7:35           ` Andrew Rybchenko
@ 2018-10-16  2:03             ` Jack Min
  0 siblings, 0 replies; 40+ messages in thread
From: Jack Min @ 2018-10-16  2:03 UTC (permalink / raw)
  To: Andrew Rybchenko
  Cc: Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Ferruh Yigit, dev

On 18-10-14 10:35:30, Andrew Rybchenko wrote:
> On 13.10.2018 06:24, Jack Min wrote:
> > rewrite TTL by decrease or just set it directly
> > it's not necessary to check if the final result
> > is zero or not
> > 
> > This is slightly different from the one defined
> > by openflow and more generic
> > 
> > Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> > Acked-by: Yongseok Koh <yskoh@mellanox.com>
> > ---
> 
> [...]
> 
> > diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
> > index 68bbf57d0..f102e6939 100644
> > --- a/lib/librte_ethdev/rte_flow.h
> > +++ b/lib/librte_ethdev/rte_flow.h
> > @@ -1579,6 +1579,26 @@ enum rte_flow_action_type {
> >   	 * No associated configuration structure.
> >   	 */
> >   	RTE_FLOW_ACTION_TYPE_MAC_SWAP,
> > +
> > +	/**
> > +	 * Decrease TTL value directly
> > +	 *
> > +	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
> > +	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
> > +	 * RTE_FLOW_ERROR_TYPE_ACTION error.
> > +	 */
> > +	RTE_FLOW_ACTION_TYPE_DEC_TTL,
> > +
> > +	/**
> > +	 * Set TTL value
> > +	 *
> > +	 * If flow pattern doesn't define a valid RTE_FLOW_ITEM_TYPE_IPV4, or
> > +	 * RTE_FLOW_ITEM_TYPE_IPV6, the PMD should return a
> > +	 * RTE_FLOW_ERROR_TYPE_ACTION error.
> > +	 *
> > +	 * See struct rte_flow_action_set_ttl
> > +	 */
> > +	RTE_FLOW_ACTION_TYPE_SET_TTL,
> >   };
> >   /**
> 
> As I understand it is one more case where the following note from Adrien
> is applicable [1]:
> 
> <begin quote>
> 
> Another problem is that you must not require actions to rely on specific
> pattern content:
> 
>  [...]
>  *
>  * Decapsulate outer most tunnel from matched flow.
>  *
>  * The flow pattern must have a valid tunnel header
>  */
>  RTE_FLOW_ACTION_TYPE_TUNNEL_DECAP,
> 
> For maximum flexibility, all actions should be usable on their own on empty
> pattern. On the other hand, you can document undefined behavior when
> performing some action on traffic that doesn't contain something.
> 
> Reason is that invalid traffic may have already been removed by other flow
> rules (or whatever happens) before such a rule is reached; it's a user's
> responsibility to provide such guarantee.
> 
> When parsing an action, a PMD is not supposed to look at the pattern. Action
> list should contain all the needed info, otherwise it means the API is badly
> defined.
> 
> I'm aware the above makes it tough to implement something like
> RTE_FLOW_ACTION_TYPE_TUNNEL_DECAP as defined in this series, but that's
> unfortunately why I think it must not be defined like that.
> 
> <end quote>
> 
> [1] https://emea01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fmails.dpdk.org%2Farchives%2Fdev%2F2018-October%2F115267.html&amp;data=02%7C01%7Cjackmin%40mellanox.com%7C8297d07c910e4aa6b4f508d631a7ab8e%7Ca652971c7d2e4d9ba6a4d149256f461b%7C0%7C0%7C636750993538615097&amp;sdata=q0ywvMqqtRr%2BHp%2FBHLGtMF3x84kwPooZ7eYfdxmHtUs%3D&amp;reserved=0
> 
Alright, I'will document this as PMD's limitation not API's.

-Jack

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v6 0/3] ethdev: add generic TTL rewrite actions
  2018-10-13  3:24       ` [dpdk-dev] [PATCH v5 0/3] ethdev: add generic TTL rewrite actions Jack Min
                           ` (2 preceding siblings ...)
  2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
@ 2018-10-16  8:14         ` Jack Min
  2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 1/3] " Jack Min
                             ` (2 more replies)
  3 siblings, 3 replies; 40+ messages in thread
From: Jack Min @ 2018-10-16  8:14 UTC (permalink / raw)
  Cc: dev

This patch series is for RFC[1]

Patch 1 adds generic TTL rewrite actions to flow API
Patch 2 adds corresponding testpmd commands
Patch 3 implements the offloading logic of E-Switch rules on Mellanox MLX5

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

v2:
 * fix misspelled issues reported by checkpatch
v3:
 * rebased
 * changed commit title of patch 3
 * added example testpmd command in commit log
 * changes in validation
v4:
 * fix some coding style issues
 * use macro of calc pedit keys
 * rebased
v5:
 * fix document warning of rte_flow.rst introduced by v4
v6:
 * updated comments and documents about rte_flow APIs
 * rebased

Xiaoyu Min (3):
  ethdev: add generic TTL rewrite actions
  app/testpmd: add commands of modify TTL
  net/mlx5: rewrite TTL by E-Switch

 app/test-pmd/cmdline_flow.c                 | 34 +++++++++
 doc/guides/prog_guide/rte_flow.rst          | 36 +++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 ++
 drivers/net/mlx5/mlx5_flow.h                |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c            | 83 ++++++++++++++++++++-
 lib/librte_ethdev/rte_flow.c                |  2 +
 lib/librte_ethdev/rte_flow.h                | 23 ++++++
 7 files changed, 183 insertions(+), 2 deletions(-)

-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v6 1/3] ethdev: add generic TTL rewrite actions
  2018-10-16  8:14         ` [dpdk-dev] [PATCH v6 0/3] ethdev: add generic TTL rewrite actions Jack Min
@ 2018-10-16  8:14           ` Jack Min
  2018-10-16  8:25             ` Andrew Rybchenko
  2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 2/3] app/testpmd: add commands of modify TTL Jack Min
  2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
  2 siblings, 1 reply; 40+ messages in thread
From: Jack Min @ 2018-10-16  8:14 UTC (permalink / raw)
  To: Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Ferruh Yigit, Andrew Rybchenko
  Cc: dev

rewrite TTL by decrease or just set it directly
it's not necessary to check if the final result
is zero or not

This is slightly different from the one defined
by openflow and more generic

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 doc/guides/prog_guide/rte_flow.rst | 36 ++++++++++++++++++++++++++++++
 lib/librte_ethdev/rte_flow.c       |  2 ++
 lib/librte_ethdev/rte_flow.h       | 23 +++++++++++++++++++
 3 files changed, 61 insertions(+)

diff --git a/doc/guides/prog_guide/rte_flow.rst b/doc/guides/prog_guide/rte_flow.rst
index a5ec441c9..e76632907 100644
--- a/doc/guides/prog_guide/rte_flow.rst
+++ b/doc/guides/prog_guide/rte_flow.rst
@@ -2203,6 +2203,42 @@ Otherwise, RTE_FLOW_ERROR_TYPE_ACTION error will be returned.
    | no properties |
    +---------------+
 
+Action: ``DEC_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Decrease TTL value.
+
+If there is no valid RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
+in pattern, Some PMDs will reject rule because behaviour will be undefined.
+
+.. _table_rte_flow_action_dec_ttl:
+
+.. table:: DEC_TTL
+
+   +---------------+
+   | Field         |
+   +===============+
+   | no properties |
+   +---------------+
+
+Action: ``SET_TTL``
+^^^^^^^^^^^^^^^^^^^
+
+Assigns a new TTL value.
+
+If there is no valid RTE_FLOW_ITEM_TYPE_IPV4 or RTE_FLOW_ITEM_TYPE_IPV6
+in pattern, Some PMDs will reject rule because behaviour will be undefined.
+
+.. _table_rte_flow_action_set_ttl:
+
+.. table:: SET_TTL
+
+   +---------------+--------------------+
+   | Field         | Value              |
+   +===============+====================+
+   | ``ttl_value`` | new TTL value      |
+   +---------------+--------------------+
+
 Negative types
 ~~~~~~~~~~~~~~
 
diff --git a/lib/librte_ethdev/rte_flow.c b/lib/librte_ethdev/rte_flow.c
index bc9e719dc..5040c7667 100644
--- a/lib/librte_ethdev/rte_flow.c
+++ b/lib/librte_ethdev/rte_flow.c
@@ -136,6 +136,8 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
 	MK_FLOW_ACTION(SET_TP_DST,
 		       sizeof(struct rte_flow_action_set_tp)),
 	MK_FLOW_ACTION(MAC_SWAP, 0),
+	MK_FLOW_ACTION(DEC_TTL, 0),
+	MK_FLOW_ACTION(SET_TTL, sizeof(struct rte_flow_action_set_ttl)),
 };
 
 static int
diff --git a/lib/librte_ethdev/rte_flow.h b/lib/librte_ethdev/rte_flow.h
index 68bbf57d0..79bcb292d 100644
--- a/lib/librte_ethdev/rte_flow.h
+++ b/lib/librte_ethdev/rte_flow.h
@@ -1579,6 +1579,20 @@ enum rte_flow_action_type {
 	 * No associated configuration structure.
 	 */
 	RTE_FLOW_ACTION_TYPE_MAC_SWAP,
+
+	/**
+	 * Decrease TTL value directly
+	 *
+	 * No associated configuration structure.
+	 */
+	RTE_FLOW_ACTION_TYPE_DEC_TTL,
+
+	/**
+	 * Set TTL value
+	 *
+	 * See struct rte_flow_action_set_ttl
+	 */
+	RTE_FLOW_ACTION_TYPE_SET_TTL,
 };
 
 /**
@@ -1987,6 +2001,15 @@ struct rte_flow_action_set_tp {
 	rte_be16_t port;
 };
 
+/**
+ * RTE_FLOW_ACTION_TYPE_SET_TTL
+ *
+ * Set the TTL value directly for IPv4 or IPv6
+ */
+struct rte_flow_action_set_ttl {
+	uint8_t ttl_value;
+};
+
 /*
  * Definition of a single action.
  *
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v6 2/3] app/testpmd: add commands of modify TTL
  2018-10-16  8:14         ` [dpdk-dev] [PATCH v6 0/3] ethdev: add generic TTL rewrite actions Jack Min
  2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 1/3] " Jack Min
@ 2018-10-16  8:14           ` Jack Min
  2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
  2 siblings, 0 replies; 40+ messages in thread
From: Jack Min @ 2018-10-16  8:14 UTC (permalink / raw)
  To: Adrien Mazarguil, Wenzhuo Lu, Jingjing Wu, Bernard Iremonger,
	John McNamara, Marko Kovacevic
  Cc: dev

add commands which supports following TTL actions:
- RTE_FLOW_ACTION_TYPE_DEC_TTL
- RTE_FLOW_ACTION_TYPE_SET_TTL

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 app/test-pmd/cmdline_flow.c                 | 34 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  5 +++
 2 files changed, 39 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 4a2764270..3efc2d86e 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -256,6 +256,9 @@ enum index {
 	ACTION_SET_TP_DST,
 	ACTION_SET_TP_DST_TP_DST,
 	ACTION_MAC_SWAP,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
+	ACTION_SET_TTL_TTL,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -836,6 +839,8 @@ static const enum index next_action[] = {
 	ACTION_SET_TP_SRC,
 	ACTION_SET_TP_DST,
 	ACTION_MAC_SWAP,
+	ACTION_DEC_TTL,
+	ACTION_SET_TTL,
 	ZERO,
 };
 
@@ -974,6 +979,12 @@ static const enum index action_set_tp_dst[] = {
 	ZERO,
 };
 
+static const enum index action_set_ttl[] = {
+	ACTION_SET_TTL_TTL,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_jump[] = {
 	ACTION_JUMP_GROUP,
 	ACTION_NEXT,
@@ -2636,6 +2647,29 @@ static const struct token token_list[] = {
 		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
 		.call = parse_vc,
 	},
+	[ACTION_DEC_TTL] = {
+		.name = "dec_ttl",
+		.help = "decrease network TTL if available",
+		.priv = PRIV_ACTION(DEC_TTL, 0),
+		.next = NEXT(NEXT_ENTRY(ACTION_NEXT)),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL] = {
+		.name = "set_ttl",
+		.help = "set ttl value",
+		.priv = PRIV_ACTION(SET_TTL,
+			sizeof(struct rte_flow_action_set_ttl)),
+		.next = NEXT(action_set_ttl),
+		.call = parse_vc,
+	},
+	[ACTION_SET_TTL_TTL] = {
+		.name = "ttl_value",
+		.help = "new ttl value to set",
+		.next = NEXT(action_set_ttl, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_HTON
+			     (struct rte_flow_action_set_ttl, ttl_value)),
+		.call = parse_vc_conf,
+	},
 };
 
 /** Remove and return last entry from argument stack. */
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index ca060e108..02612cc60 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3802,6 +3802,11 @@ This section lists supported actions and their attributes, if any.
 - ``mac_swap``: Swap the source and destination MAC addresses in the outermost
   Ethernet header.
 
+- ``dec_ttl``: Performs a decrease TTL value action
+
+- ``set_ttl``: Set TTL value with specificed value
+  - ``ttl_value {unsigned}``: The new TTL value to be set
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* [dpdk-dev] [PATCH v6 3/3] net/mlx5: rewrite TTL by E-Switch
  2018-10-16  8:14         ` [dpdk-dev] [PATCH v6 0/3] ethdev: add generic TTL rewrite actions Jack Min
  2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 1/3] " Jack Min
  2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 2/3] app/testpmd: add commands of modify TTL Jack Min
@ 2018-10-16  8:14           ` Jack Min
  2 siblings, 0 replies; 40+ messages in thread
From: Jack Min @ 2018-10-16  8:14 UTC (permalink / raw)
  To: Shahaf Shuler, Yongseok Koh; +Cc: dev

Offload following modify TTL actions to E-Switch via
TC-Flower driver

- RTE_FLOW_ACTION_TYPE_SET_TTL
- RTE_FLOW_ACTION_TYPE_DEC_TTL

The corresponding IP protocol rte_flow_item_ipv[4|6]
must be present in rte_flow pattern otherwith PMD
return error

The example testpmd commands are:

    flow create 0 transfer ingress
         pattern eth / ipv4 / udp dst is 7000 / end
	 actions dec_ttl /
	 port_id id 1 / end

    flow create 0 transfer ingress
         pattern eth / ipv4 / udp dst is 7001 / end
	 actions set_ttl ttl_value 10 /
	 port_id id 1 / end

Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
Acked-by: Yongseok Koh <yskoh@mellanox.com>
---
 drivers/net/mlx5/mlx5_flow.h     |  2 +
 drivers/net/mlx5/mlx5_flow_tcf.c | 83 +++++++++++++++++++++++++++++++-
 2 files changed, 83 insertions(+), 2 deletions(-)

diff --git a/drivers/net/mlx5/mlx5_flow.h b/drivers/net/mlx5/mlx5_flow.h
index 094f6668f..cccafe52d 100644
--- a/drivers/net/mlx5/mlx5_flow.h
+++ b/drivers/net/mlx5/mlx5_flow.h
@@ -85,6 +85,8 @@
 #define MLX5_FLOW_ACTION_SET_TP_SRC (1u << 15)
 #define MLX5_FLOW_ACTION_SET_TP_DST (1u << 16)
 #define MLX5_FLOW_ACTION_JUMP (1u << 17)
+#define MLX5_FLOW_ACTION_SET_TTL (1u << 18)
+#define MLX5_FLOW_ACTION_DEC_TTL (1u << 19)
 
 #define MLX5_FLOW_FATE_ACTIONS \
 	(MLX5_FLOW_ACTION_DROP | MLX5_FLOW_ACTION_QUEUE | MLX5_FLOW_ACTION_RSS)
diff --git a/drivers/net/mlx5/mlx5_flow_tcf.c b/drivers/net/mlx5/mlx5_flow_tcf.c
index 4b51a854e..3adcf189e 100644
--- a/drivers/net/mlx5/mlx5_flow_tcf.c
+++ b/drivers/net/mlx5/mlx5_flow_tcf.c
@@ -231,6 +231,10 @@ struct tc_pedit_sel {
 #define TP_PORT_LEN 2 /* Transport Port (UDP/TCP) Length */
 #endif
 
+#ifndef TTL_LEN
+#define TTL_LEN 1
+#endif
+
 /** Empty masks for known item types. */
 static const union {
 	struct rte_flow_item_port_id port_id;
@@ -319,12 +323,14 @@ struct flow_tcf_ptoi {
 #define MLX5_TCF_PEDIT_ACTIONS \
 	(MLX5_FLOW_ACTION_SET_IPV4_SRC | MLX5_FLOW_ACTION_SET_IPV4_DST | \
 	 MLX5_FLOW_ACTION_SET_IPV6_SRC | MLX5_FLOW_ACTION_SET_IPV6_DST | \
-	 MLX5_FLOW_ACTION_SET_TP_SRC | MLX5_FLOW_ACTION_SET_TP_DST)
+	 MLX5_FLOW_ACTION_SET_TP_SRC | MLX5_FLOW_ACTION_SET_TP_DST | \
+	 MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL)
 
 #define MLX5_TCF_CONFIG_ACTIONS \
 	(MLX5_FLOW_ACTION_PORT_ID | MLX5_FLOW_ACTION_JUMP | \
 	 MLX5_FLOW_ACTION_OF_PUSH_VLAN | MLX5_FLOW_ACTION_OF_SET_VLAN_VID | \
-	 MLX5_FLOW_ACTION_OF_SET_VLAN_PCP | MLX5_TCF_PEDIT_ACTIONS)
+	 MLX5_FLOW_ACTION_OF_SET_VLAN_PCP | \
+	 (MLX5_TCF_PEDIT_ACTIONS & ~MLX5_FLOW_ACTION_DEC_TTL))
 
 #define MAX_PEDIT_KEYS 128
 #define SZ_PEDIT_KEY_VAL 4
@@ -344,6 +350,46 @@ struct pedit_parser {
 };
 
 
+/**
+ * Set pedit key of decrease/set ttl
+ *
+ * @param[in] actions
+ *   pointer to action specification
+ * @param[in,out] p_parser
+ *   pointer to pedit_parser
+ * @param[in] item_flags
+ *   flags of all items presented
+ */
+static void
+flow_tcf_pedit_key_set_dec_ttl(const struct rte_flow_action *actions,
+				struct pedit_parser *p_parser,
+				uint64_t item_flags)
+{
+	int idx = p_parser->sel.nkeys;
+
+	p_parser->keys[idx].mask = 0xFFFFFF00;
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV4) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP4;
+		p_parser->keys[idx].off =
+			offsetof(struct ipv4_hdr, time_to_live);
+	}
+	if (item_flags & MLX5_FLOW_LAYER_OUTER_L3_IPV6) {
+		p_parser->keys_ex[idx].htype = TCA_PEDIT_KEY_EX_HDR_TYPE_IP6;
+		p_parser->keys[idx].off =
+			offsetof(struct ipv6_hdr, hop_limits);
+	}
+	if (actions->type == RTE_FLOW_ACTION_TYPE_DEC_TTL) {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_ADD;
+		p_parser->keys[idx].val = 0x000000FF;
+	} else {
+		p_parser->keys_ex[idx].cmd = TCA_PEDIT_KEY_EX_CMD_SET;
+		p_parser->keys[idx].val =
+			(__u32)((const struct rte_flow_action_set_ttl *)
+			 actions->conf)->ttl_value;
+	}
+	p_parser->sel.nkeys = (++idx);
+}
+
 /**
  * Set pedit key of transport (TCP/UDP) port value
  *
@@ -479,6 +525,11 @@ flow_tcf_create_pedit_mnl_msg(struct nlmsghdr *nl,
 			flow_tcf_pedit_key_set_tp_port(*actions,
 							&p_parser, item_flags);
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			flow_tcf_pedit_key_set_dec_ttl(*actions,
+							&p_parser, item_flags);
+			break;
 		default:
 			goto pedit_mnl_msg_done;
 		}
@@ -559,6 +610,14 @@ flow_tcf_get_pedit_actions_size(const struct rte_flow_action **actions,
 			keys += NUM_OF_PEDIT_KEYS(TP_PORT_LEN);
 			flags |= MLX5_FLOW_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			keys += NUM_OF_PEDIT_KEYS(TTL_LEN);
+			flags |= MLX5_FLOW_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			keys += NUM_OF_PEDIT_KEYS(TTL_LEN);
+			flags |= MLX5_FLOW_ACTION_DEC_TTL;
+			break;
 		default:
 			goto get_pedit_action_size_done;
 		}
@@ -1096,6 +1155,12 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
 			current_action_flag = MLX5_FLOW_ACTION_SET_TP_DST;
 			break;
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+			current_action_flag = MLX5_FLOW_ACTION_SET_TTL;
+			break;
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
+			current_action_flag = MLX5_FLOW_ACTION_DEC_TTL;
+			break;
 		default:
 			return rte_flow_error_set(error, ENOTSUP,
 						  RTE_FLOW_ERROR_TYPE_ACTION,
@@ -1198,6 +1263,16 @@ flow_tcf_validate(struct rte_eth_dev *dev,
 		return rte_flow_error_set(error, EINVAL,
 					  RTE_FLOW_ERROR_TYPE_ACTION, actions,
 					  "no fate action is found");
+	if (action_flags &
+	   (MLX5_FLOW_ACTION_SET_TTL | MLX5_FLOW_ACTION_DEC_TTL)) {
+		if (!(item_flags &
+		     (MLX5_FLOW_LAYER_OUTER_L3_IPV4 |
+		      MLX5_FLOW_LAYER_OUTER_L3_IPV6)))
+			return rte_flow_error_set(error, EINVAL,
+						  RTE_FLOW_ERROR_TYPE_ACTION,
+						  actions,
+						  "no IP found in pattern");
+	}
 	return 0;
 }
 
@@ -1357,6 +1432,8 @@ flow_tcf_get_actions_and_size(const struct rte_flow_action actions[],
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			size += flow_tcf_get_pedit_actions_size(&actions,
 								&flags);
 			break;
@@ -1933,6 +2010,8 @@ flow_tcf_translate(struct rte_eth_dev *dev, struct mlx5_flow *dev_flow,
 		case RTE_FLOW_ACTION_TYPE_SET_IPV6_DST:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_SRC:
 		case RTE_FLOW_ACTION_TYPE_SET_TP_DST:
+		case RTE_FLOW_ACTION_TYPE_SET_TTL:
+		case RTE_FLOW_ACTION_TYPE_DEC_TTL:
 			na_act_index =
 				mnl_attr_nest_start(nlh, na_act_index_cur++);
 			flow_tcf_create_pedit_mnl_msg(nlh,
-- 
2.17.1

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v6 1/3] ethdev: add generic TTL rewrite actions
  2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 1/3] " Jack Min
@ 2018-10-16  8:25             ` Andrew Rybchenko
  2018-10-16  8:48               ` Ferruh Yigit
  0 siblings, 1 reply; 40+ messages in thread
From: Andrew Rybchenko @ 2018-10-16  8:25 UTC (permalink / raw)
  To: Jack Min, Adrien Mazarguil, John McNamara, Marko Kovacevic,
	Thomas Monjalon, Ferruh Yigit
  Cc: dev

On 10/16/18 11:14 AM, Jack Min wrote:
> rewrite TTL by decrease or just set it directly
> it's not necessary to check if the final result
> is zero or not
>
> This is slightly different from the one defined
> by openflow and more generic
>
> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
> Acked-by: Yongseok Koh <yskoh@mellanox.com>

Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>

^ permalink raw reply	[flat|nested] 40+ messages in thread

* Re: [dpdk-dev] [PATCH v6 1/3] ethdev: add generic TTL rewrite actions
  2018-10-16  8:25             ` Andrew Rybchenko
@ 2018-10-16  8:48               ` Ferruh Yigit
  0 siblings, 0 replies; 40+ messages in thread
From: Ferruh Yigit @ 2018-10-16  8:48 UTC (permalink / raw)
  To: Andrew Rybchenko, Jack Min, Adrien Mazarguil, John McNamara,
	Marko Kovacevic, Thomas Monjalon
  Cc: dev

On 10/16/2018 9:25 AM, Andrew Rybchenko wrote:
> On 10/16/18 11:14 AM, Jack Min wrote:
>> rewrite TTL by decrease or just set it directly
>> it's not necessary to check if the final result
>> is zero or not
>>
>> This is slightly different from the one defined
>> by openflow and more generic
>>
>> Signed-off-by: Xiaoyu Min <jackmin@mellanox.com>
>> Acked-by: Yongseok Koh <yskoh@mellanox.com>
> 
> Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>

Series applied to dpdk-next-net/master, thanks.

^ permalink raw reply	[flat|nested] 40+ messages in thread

end of thread, other threads:[~2018-10-16  8:48 UTC | newest]

Thread overview: 40+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-09-25 13:47 [dpdk-dev] [PATCH 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
2018-09-25 13:47 ` [dpdk-dev] [PATCH 1/3] " Xiaoyu Min
2018-09-25 13:47 ` [dpdk-dev] [PATCH 2/3] app/testpmd: add commands of modify TTL Xiaoyu Min
2018-09-25 13:47 ` [dpdk-dev] [PATCH 3/3] net/mlx5: eswitch-modify TTL actions Xiaoyu Min
2018-10-03 20:07   ` Yongseok Koh
2018-10-08  6:57     ` Xiaoyu Min
2018-09-25 14:37 ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Xiaoyu Min
2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 1/3] " Xiaoyu Min
2018-10-03 19:50     ` Yongseok Koh
2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 2/3] app/testpmd: add commands of modify TTL Xiaoyu Min
2018-10-03 19:51     ` Yongseok Koh
2018-09-25 14:37   ` [dpdk-dev] [PATCH v2 3/3] net/mlx5: eswitch-modify TTL actions Xiaoyu Min
2018-10-05 12:48     ` Ferruh Yigit
2018-10-05 18:17       ` Yongseok Koh
2018-10-03 20:35   ` [dpdk-dev] [PATCH v2 0/3] ethdev: add generic TTL rewrite actions Thomas Monjalon
2018-10-05 12:52   ` Ferruh Yigit
2018-10-08  2:30     ` Xiaoyu Min
2018-10-10 13:05   ` [dpdk-dev] [PATCH v3 " Jack Min
2018-10-10 13:05     ` [dpdk-dev] [PATCH v3 1/3] " Jack Min
2018-10-10 13:05     ` [dpdk-dev] [PATCH v3 2/3] app/testpmd: add commands of modify TTL Jack Min
2018-10-10 13:06     ` [dpdk-dev] [PATCH v3 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
2018-10-11  5:47       ` Yongseok Koh
2018-10-11 13:27     ` [dpdk-dev] [PATCH v4 0/3] ethdev: add generic TTL rewrite actions Jack Min
2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 1/3] " Jack Min
2018-10-12 14:12         ` Ferruh Yigit
2018-10-13  2:16           ` Jack Min
2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 2/3] app/testpmd: add commands of modify TTL Jack Min
2018-10-11 13:27       ` [dpdk-dev] [PATCH v4 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
2018-10-13  3:24       ` [dpdk-dev] [PATCH v5 0/3] ethdev: add generic TTL rewrite actions Jack Min
2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 1/3] " Jack Min
2018-10-14  7:35           ` Andrew Rybchenko
2018-10-16  2:03             ` Jack Min
2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 2/3] app/testpmd: add commands of modify TTL Jack Min
2018-10-13  3:24         ` [dpdk-dev] [PATCH v5 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min
2018-10-16  8:14         ` [dpdk-dev] [PATCH v6 0/3] ethdev: add generic TTL rewrite actions Jack Min
2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 1/3] " Jack Min
2018-10-16  8:25             ` Andrew Rybchenko
2018-10-16  8:48               ` Ferruh Yigit
2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 2/3] app/testpmd: add commands of modify TTL Jack Min
2018-10-16  8:14           ` [dpdk-dev] [PATCH v6 3/3] net/mlx5: rewrite TTL by E-Switch Jack Min

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).