Skip to contentSkip to conversation

ethdev: add group set miss actions API

PATCH In review Tomer Shmilovich 2 participants 4 messages Sep 20, 2023 – Sep 29, 2023

lore
Share & tools
lore
#0 lore raw

cover ethdev: add group set miss actions API

Introduce new group set miss actions API:
rte_flow_group_set_miss_actions().

A group's miss actions are a set of actions to be performed in case of a miss on a group, i.e. when a packet didn't hit any flow rules in the group.

Currently, the expected behavior in this case is undefined. In order to achieve such functionality, a user can add a flow rule that matches on all traffic with the lowest priority in the group - this is not explicit however, and can be overridden by another flow rule with a lower priority.

This new API function allows a user to set a group's miss actions in an explicit way.

RFC discussion: http://patches.dpdk.org/project/dpdk/patch/[email protected]/

Tomer Shmilovich (2):
ethdev: add group set miss actions API app/testpmd: add group set miss actions CLI commands

 .mailmap                               |   1 +
 app/test-pmd/cmdline_flow.c            | 112 +++++++++++++++++++++++++
 app/test-pmd/config.c                  |  27 ++++++
 app/test-pmd/testpmd.h                 |   2 +
 doc/guides/prog_guide/rte_flow.rst     |  30 +++++++
 doc/guides/rel_notes/release_23_11.rst |   5 ++
 lib/ethdev/rte_flow.c                  |  22 +++++
 lib/ethdev/rte_flow.h                  |  35 ++++++++
 lib/ethdev/rte_flow_driver.h           |   7 ++
 lib/ethdev/version.map                 |   3 +
 10 files changed, 244 insertions(+)
Signature · 1 line
2.34.1
#1 lore raw

PATCH 1/2 ethdev: add group set miss actions API

Introduce new group set miss actions API:
rte_flow_group_set_miss_actions().

A group's miss actions are a set of actions to be performed in case of a miss on a group, meaning a packet didn't hit any rules in the group. This API function allows a user to set a group's miss actions.

---
 .mailmap                               |  1 +
 doc/guides/prog_guide/rte_flow.rst     | 30 ++++++++++++++++++++++
 doc/guides/rel_notes/release_23_11.rst |  5 ++++
 lib/ethdev/rte_flow.c                  | 22 ++++++++++++++++
 lib/ethdev/rte_flow.h                  | 35 ++++++++++++++++++++++++++
 lib/ethdev/rte_flow_driver.h           |  7 ++++++
 lib/ethdev/version.map                 |  3 +++
 7 files changed, 103 insertions(+)
.mailmap +1 -0
index 864d33ee46..0cd6be849e 100644
@@ -1411,6 +1411,7 @@ Tom Barbette <[email protected]> <[email protected]>
 Tom Crugnale <[email protected]>
 Tom Millington <[email protected]>
 Tom Rix <[email protected]>
+Tomer Shmilovich <[email protected]>
 Tone Zhang <[email protected]>
 Tonghao Zhang <[email protected]> <[email protected]>
 Tony Nguyen <[email protected]>
doc/guides/prog_guide/rte_flow.rst +30 -0
index 5bc998a433..590d2a770e 100644
@@ -3758,6 +3758,36 @@ Information about the number of available resources can be retrieved via
                      struct rte_flow_queue_info *queue_info,
                      struct rte_flow_error *error);
 
+Group Miss Actions
+~~~~~~~~~~~~~~~~~~
+
+In an application, many flow rules share common group attributes, meaning they can be grouped and
+classified together. A user can explicitly specify a set of actions performed on a packet when it
+did not match any flows rules in a group using the following API:
+
+.. code-block:: c
+
+      int
+      rte_flow_group_set_miss_actions(uint16_t port_id,
+                                      uint32_t group_id,
+                                      const struct rte_flow_group_attr *attr,
+                                      const struct rte_flow_action actions[],
+                                      struct rte_flow_error *error);
+
+For example, to configure a RTE_FLOW_TYPE_JUMP action as a miss action for ingress group 1:
+
+.. code-block:: c
+
+      struct rte_flow_group_attr attr = {.ingress = 1};
+      struct rte_flow_action act[] = {
+      /* Setting miss actions to jump to group 3 */
+          [0] = {.type = RTE_FLOW_ACTION_TYPE_JUMP,
+                 .conf = &(struct rte_flow_action_jump){.group = 3}},
+          [1] = {.type = RTE_FLOW_ACTION_TYPE_END},
+      };
+      struct rte_flow_error err;
+      rte_flow_group_set_miss_actions(port, 1, &attr, act, &err);
+
 Flow templates
 ~~~~~~~~~~~~~~
 
doc/guides/rel_notes/release_23_11.rst +5 -0
index 333e1d95a2..da0ddc2078 100644
@@ -41,6 +41,11 @@ DPDK Release 23.11
 New Features
 ------------
 
+* **Added flow group set miss actions.**
+   Introduced ``rte_flow_group_set_miss_actions()`` API to explicitly set a group's miss actions,
+   which are the actions to be performed on packets that didn't match any of the flow rules
+   in the group.
+
 .. This section should contain new features added in this release.
    Sample format:
 
lib/ethdev/rte_flow.c +22 -0
index 271d854f78..a98d87265f 100644
@@ -1973,6 +1973,28 @@ rte_flow_template_table_destroy(uint16_t port_id,
 				  NULL, rte_strerror(ENOTSUP));
 }
 
+int
+rte_flow_group_set_miss_actions(uint16_t port_id,
+				uint32_t group_id,
+				const struct rte_flow_group_attr *attr,
+				const struct rte_flow_action actions[],
+				struct rte_flow_error *error)
+{
+	struct rte_eth_dev *dev = &rte_eth_devices[port_id];
+	const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+	if (unlikely(!ops))
+		return -rte_errno;
+	if (likely(!!ops->group_set_miss_actions)) {
+		return flow_err(port_id,
+				ops->group_set_miss_actions(dev, group_id, attr, actions, error),
+				error);
+	}
+	return rte_flow_error_set(error, ENOTSUP,
+				  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+				  NULL, rte_strerror(ENOTSUP));
+}
+
 struct rte_flow *
 rte_flow_async_create(uint16_t port_id,
 		      uint32_t queue_id,
lib/ethdev/rte_flow.h +35 -0
index 2ebb76dbc0..82548a8b93 100644
@@ -129,6 +129,12 @@ struct rte_flow_attr {
 	uint32_t reserved:29; /**< Reserved, must be zero. */
 };
 
+struct rte_flow_group_attr {
+	uint32_t ingress:1;
+	uint32_t egress:1;
+	uint32_t transfer:1;
+};
+
 /**
  * Matching pattern item types.
  *
@@ -5828,6 +5834,35 @@ rte_flow_template_table_destroy(uint16_t port_id,
 		struct rte_flow_template_table *template_table,
 		struct rte_flow_error *error);
 
+/**
+ * @warning
+ * @b EXPERIMENTAL: this API may change without prior notice.
+ *
+ * Set group miss actions.
+ *
+ * @param port_id
+ *   Port identifier of Ethernet device.
+ * @param group_id
+ *   Identifier of a group to set miss actions for.
+ * @param attr
+ *   Group attributes.
+ * @param actions
+ *   List of group miss actions.
+ * @param[out] error
+ *   Perform verbose error reporting if not NULL.
+ *   PMDs initialize this structure in case of error only.
+ *
+ * @return
+ *   0 on success, a negative errno value otherwise and rte_errno is set.
+ */
+__rte_experimental
+int
+rte_flow_group_set_miss_actions(uint16_t port_id,
+				uint32_t group_id,
+				const struct rte_flow_group_attr *attr,
+				const struct rte_flow_action actions[],
+				struct rte_flow_error *error);
+
 /**
  * @warning
  * @b EXPERIMENTAL: this API may change without prior notice.
lib/ethdev/rte_flow_driver.h +7 -0
index f9fb01b8a2..3ced086c47 100644
@@ -227,6 +227,13 @@ struct rte_flow_ops {
 		(struct rte_eth_dev *dev,
 		 struct rte_flow_template_table *template_table,
 		 struct rte_flow_error *err);
+	/** See rte_flow_group_set_miss_actions() */
+	int (*group_set_miss_actions)
+		(struct rte_eth_dev *dev,
+		 uint32_t group_id,
+		 const struct rte_flow_group_attr *attr,
+		 const struct rte_flow_action actions[],
+		 struct rte_flow_error *err);
 	/** See rte_flow_async_create() */
 	struct rte_flow *(*async_create)
 		(struct rte_eth_dev *dev,
lib/ethdev/version.map +3 -0
index b965d6aa52..ff9b92f21e 100644
@@ -312,6 +312,9 @@ EXPERIMENTAL {
 	rte_flow_async_action_list_handle_query_update;
 	rte_flow_async_actions_update;
 	rte_flow_restore_info_dynflag;
+
+	# added in 23.11
+	rte_flow_group_set_miss_actions;
 };
 
 INTERNAL {
Signature · 1 line
2.34.1
#2 lore raw

PATCH 2/2 app/testpmd: add group set miss actions CLI commands

In reply to Tomer Shmilovich

Add testpmd CLI interface for the group set miss actions API:

flow group 0 group_id 1 ingress set_miss_actions jump group 3 / end flow group 0 group_id 1 ingress set_miss_actions end

---
 app/test-pmd/cmdline_flow.c | 112 ++++++++++++++++++++++++++++++++++++
 app/test-pmd/config.c       |  27 +++++++++
 app/test-pmd/testpmd.h      |   2 +
 3 files changed, 141 insertions(+)
app/test-pmd/cmdline_flow.c +112 -0
index 94827bcc4a..b3b8893e37 100644
@@ -86,6 +86,7 @@ enum index {
 	PATTERN_TEMPLATE,
 	ACTIONS_TEMPLATE,
 	TABLE,
+	FLOW_GROUP,
 	INDIRECT_ACTION,
 	VALIDATE,
 	CREATE,
@@ -206,6 +207,13 @@ enum index {
 	TABLE_PATTERN_TEMPLATE,
 	TABLE_ACTIONS_TEMPLATE,
 
+	/* Group arguments */
+	GROUP_ID,
+	GROUP_INGRESS,
+	GROUP_EGRESS,
+	GROUP_TRANSFER,
+	GROUP_SET_MISS_ACTIONS,
+
 	/* Tunnel arguments. */
 	TUNNEL_CREATE,
 	TUNNEL_CREATE_TYPE,
@@ -1293,6 +1301,14 @@ static const enum index next_at_destroy_attr[] = {
 	ZERO,
 };
 
+static const enum index next_group_attr[] = {
+	GROUP_INGRESS,
+	GROUP_EGRESS,
+	GROUP_TRANSFER,
+	GROUP_SET_MISS_ACTIONS,
+	ZERO,
+};
+
 static const enum index next_table_subcmd[] = {
 	TABLE_CREATE,
 	TABLE_DESTROY,
@@ -2678,6 +2694,9 @@ static int parse_push(struct context *, const struct token *,
 static int parse_pull(struct context *, const struct token *,
 		      const char *, unsigned int,
 		      void *, unsigned int);
+static int parse_group(struct context *, const struct token *,
+		       const char *, unsigned int,
+		       void *, unsigned int);
 static int parse_tunnel(struct context *, const struct token *,
 			const char *, unsigned int,
 			void *, unsigned int);
@@ -3021,6 +3040,7 @@ static const struct token token_list[] = {
 			      PATTERN_TEMPLATE,
 			      ACTIONS_TEMPLATE,
 			      TABLE,
+			      FLOW_GROUP,
 			      INDIRECT_ACTION,
 			      VALIDATE,
 			      CREATE,
@@ -3411,6 +3431,46 @@ static const struct token token_list[] = {
 		.call = parse_table,
 	},
 	/* Top-level command. */
+	[FLOW_GROUP] = {
+		.name = "group",
+		.help = "manage flow groups",
+		.next = NEXT(NEXT_ENTRY(GROUP_ID), NEXT_ENTRY(COMMON_PORT_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, port)),
+		.call = parse_group,
+	},
+	/* Sub-level commands. */
+	[GROUP_SET_MISS_ACTIONS] = {
+		.name = "set_miss_actions",
+		.help = "set group miss actions",
+		.next = NEXT(next_action),
+		.call = parse_group,
+	},
+	/* Group arguments */
+	[GROUP_ID]	= {
+		.name = "group_id",
+		.help = "group id",
+		.next = NEXT(next_group_attr, NEXT_ENTRY(COMMON_GROUP_ID)),
+		.args = ARGS(ARGS_ENTRY(struct buffer, args.vc.attr.group)),
+	},
+	[GROUP_INGRESS] = {
+		.name = "ingress",
+		.help = "group ingress attr",
+		.next = NEXT(next_group_attr),
+		.call = parse_group,
+	},
+	[GROUP_EGRESS] = {
+		.name = "egress",
+		.help = "group egress attr",
+		.next = NEXT(next_group_attr),
+		.call = parse_group,
+	},
+	[GROUP_TRANSFER] = {
+		.name = "transfer",
+		.help = "group transfer attr",
+		.next = NEXT(next_group_attr),
+		.call = parse_group,
+	},
+	/* Top-level command. */
 	[QUEUE] = {
 		.name = "queue",
 		.help = "queue a flow rule operation",
@@ -10449,6 +10509,54 @@ parse_pull(struct context *ctx, const struct token *token,
 	return len;
 }
 
+static int
+parse_group(struct context *ctx, const struct token *token,
+	    const char *str, unsigned int len,
+	    void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+
+	/* Token name must match. */
+	if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+		return -1;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return len;
+	if (!out->command) {
+		if (ctx->curr != FLOW_GROUP)
+			return -1;
+		if (sizeof(*out) > size)
+			return -1;
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.vc.data = (uint8_t *)out + size;
+		return len;
+	}
+	switch (ctx->curr) {
+	case GROUP_INGRESS:
+		out->args.vc.attr.ingress = 1;
+		return len;
+	case GROUP_EGRESS:
+		out->args.vc.attr.egress = 1;
+		return len;
+	case GROUP_TRANSFER:
+		out->args.vc.attr.transfer = 1;
+		return len;
+	case GROUP_SET_MISS_ACTIONS:
+		out->command = ctx->curr;
+		ctx->objdata = 0;
+		ctx->object = out;
+		ctx->objmask = NULL;
+		out->args.vc.actions = (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1),
+							       sizeof(double));
+		return len;
+	default:
+		return -1;
+	}
+}
+
 static int
 parse_flex(struct context *ctx, const struct token *token,
 	     const char *str, unsigned int len,
@@ -12329,6 +12437,10 @@ cmd_flow_parsed(const struct buffer *in)
 					in->args.table_destroy.table_id_n,
 					in->args.table_destroy.table_id);
 		break;
+	case GROUP_SET_MISS_ACTIONS:
+		port_queue_group_set_miss_actions(in->port, &in->args.vc.attr,
+						  in->args.vc.actions);
+		break;
 	case QUEUE_CREATE:
 		port_queue_flow_create(in->port, in->queue, in->postpone,
 			in->args.vc.table_id, in->args.vc.rule_id,
app/test-pmd/config.c +27 -0
index 3d1da99307..709864bb44 100644
@@ -3514,6 +3514,33 @@ port_queue_flow_pull(portid_t port_id, queueid_t queue_id)
 	return ret;
 }
 
+/* Set group miss actions */
+int
+port_queue_group_set_miss_actions(portid_t port_id, const struct rte_flow_attr *attr,
+				  const struct rte_flow_action *actions)
+{
+	struct rte_flow_group_attr gattr = {
+		.ingress = attr->ingress,
+		.egress = attr->egress,
+		.transfer = attr->transfer,
+	};
+	struct rte_flow_error error;
+	int ret = 0;
+
+	if (port_id_is_invalid(port_id, ENABLED_WARN) ||
+	    port_id == (portid_t)RTE_PORT_ALL)
+		return -EINVAL;
+
+	memset(&error, 0x66, sizeof(error));
+	ret = rte_flow_group_set_miss_actions(port_id, attr->group, &gattr, actions, &error);
+
+	if (ret < 0)
+		return port_flow_complain(&error);
+
+	printf("Group #%u set miss actions succeeded\n", attr->group);
+	return ret;
+}
+
 /** Create flow rule. */
 int
 port_flow_create(portid_t port_id,
app/test-pmd/testpmd.h +2 -0
index f1df6a8faf..e69b76f380 100644
@@ -979,6 +979,8 @@ int port_flow_template_table_create(portid_t port_id, uint32_t id,
 int port_flow_template_table_destroy(portid_t port_id,
 			    uint32_t n, const uint32_t *table);
 int port_flow_template_table_flush(portid_t port_id);
+int port_queue_group_set_miss_actions(portid_t port_id, const struct rte_flow_attr *attr,
+				      const struct rte_flow_action *actions);
 int port_queue_flow_create(portid_t port_id, queueid_t queue_id,
 			   bool postpone, uint32_t table_id, uint32_t rule_idx,
 			   uint32_t pattern_idx, uint32_t actions_idx,
Signature · 1 line
2.34.1
#3 lore raw
In reply to Tomer Shmilovich
Quoted 13 lines · Tomer Shmilovich

Introduce new group set miss actions API:
rte_flow_group_set_miss_actions().

A group's miss actions are a set of actions to be performed in case of a miss on a group, i.e. when a packet didn't hit any flow rules in the group.

Currently, the expected behavior in this case is undefined. In order to achieve such functionality, a user can add a flow rule that matches on all traffic with the lowest priority in the group - this is not explicit however, and can be overridden by another flow rule with a lower priority.

Quoted 9 lines

This new API function allows a user to set a group's miss actions in an explicit way.

RFC discussion: http://patches.dpdk.org/project/dpdk/patch/[email protected]/

Tomer Shmilovich (2):
ethdev: add group set miss actions API app/testpmd: add group set miss actions CLI commands

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