[4/8] app/testpmd: parse map actions

Message ID 1591194009-4086-5-git-send-email-bernard.iremonger@intel.com (mailing list archive)
State Rejected, archived
Delegated to: Ferruh Yigit
Headers
Series add flow action map |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/checkpatch success coding style OK

Commit Message

Iremonger, Bernard June 3, 2020, 2:20 p.m. UTC
  Parse map, pctype and flowtype on testpmd command line.

In cmdline_flow.c add the following:

ACTION_MAP
ACTION_MAP_PCTYPE
ACTION_MAP_FLOWTYPE
add parse_vc_action_map()

Update testpmd user guide with map action and
sample map action rules.

Signed-off-by: Bernard Iremonger <bernard.iremonger@intel.com>
---
 app/test-pmd/cmdline_flow.c                 | 85 +++++++++++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst | 27 +++++++++
 2 files changed, 112 insertions(+)
  

Patch

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 4e2006c..3b7f775 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -349,6 +349,9 @@  enum index {
 	ACTION_SET_IPV6_DSCP_VALUE,
 	ACTION_AGE,
 	ACTION_AGE_TIMEOUT,
+	ACTION_MAP,
+	ACTION_MAP_PCTYPE,
+	ACTION_MAP_FLOWTYPE,
 };
 
 /** Maximum size for pattern in struct rte_flow_item_raw. */
@@ -368,6 +371,11 @@  struct action_rss_data {
 	uint16_t queue[ACTION_RSS_QUEUE_NUM];
 };
 
+/** Storage for struct rte_flow_action_map including external data. */
+struct action_map_data {
+	struct rte_flow_action_map conf;
+};
+
 /** Maximum data size in struct rte_flow_action_raw_encap. */
 #define ACTION_RAW_ENCAP_MAX_DATA 128
 #define RAW_ENCAP_CONFS_MAX_NUM 8
@@ -1161,6 +1169,7 @@  static const enum index next_action[] = {
 	ACTION_SET_IPV4_DSCP,
 	ACTION_SET_IPV6_DSCP,
 	ACTION_AGE,
+	ACTION_MAP,
 	ZERO,
 };
 
@@ -1194,6 +1203,13 @@  static const enum index action_rss[] = {
 	ZERO,
 };
 
+static const enum index action_map[] = {
+	ACTION_MAP_PCTYPE,
+	ACTION_MAP_FLOWTYPE,
+	ACTION_NEXT,
+	ZERO,
+};
+
 static const enum index action_vf[] = {
 	ACTION_VF_ORIGINAL,
 	ACTION_VF_ID,
@@ -1421,6 +1437,9 @@  static int parse_vc_action_rss_type(struct context *, const struct token *,
 static int parse_vc_action_rss_queue(struct context *, const struct token *,
 				     const char *, unsigned int, void *,
 				     unsigned int);
+static int parse_vc_action_map(struct context *, const struct token *,
+			       const char *, unsigned int, void *,
+			       unsigned int);
 static int parse_vc_action_vxlan_encap(struct context *, const struct token *,
 				       const char *, unsigned int, void *,
 				       unsigned int);
@@ -3609,6 +3628,36 @@  static const struct token token_list[] = {
 		.call = parse_vc_action_raw_decap_index,
 		.comp = comp_set_raw_index,
 	},
+	[ACTION_MAP] = {
+		.name = "map",
+		.help = "map Packet Classification type to flow type",
+		.priv = PRIV_ACTION(MAP, sizeof(struct action_map_data)),
+		.next = NEXT(action_map),
+		.args = ARGS(ARGS_ENTRY(struct rte_flow_action_map, pctype),
+			     ARGS_ENTRY(struct rte_flow_action_map,
+						flowtype)),
+		.call = parse_vc_action_map,
+	},
+	[ACTION_MAP_PCTYPE] = {
+		.name = "pctype",
+		.help = "Packet Classification type ",
+		.next = NEXT(action_map, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_ARB
+			     (offsetof(struct action_map_data, conf) +
+			      offsetof(struct rte_flow_action_map, pctype),
+			      sizeof(((struct rte_flow_action_map *)0)->
+				     pctype))),
+	},
+	[ACTION_MAP_FLOWTYPE] = {
+		.name = "flowtype",
+		.help = "flow type ",
+		.next = NEXT(action_map, NEXT_ENTRY(UNSIGNED)),
+		.args = ARGS(ARGS_ENTRY_ARB
+			     (offsetof(struct action_map_data, conf) +
+			      offsetof(struct rte_flow_action_map, flowtype),
+			      sizeof(((struct rte_flow_action_map *)0)->
+				     flowtype))),
+	},
 	/* Top level command. */
 	[SET] = {
 		.name = "set",
@@ -5207,6 +5256,42 @@  parse_vc_action_set_meta(struct context *ctx, const struct token *token,
 	return len;
 }
 
+/** Parse MAP action. */
+static int
+parse_vc_action_map(struct context *ctx, const struct token *token,
+		    const char *str, unsigned int len,
+		    void *buf, unsigned int size)
+{
+	struct buffer *out = buf;
+	struct rte_flow_action *action;
+	struct action_map_data *action_map_data;
+	int ret;
+
+	ret = parse_vc(ctx, token, str, len, buf, size);
+	if (ret < 0)
+		return ret;
+	/* Nothing else to do if there is no buffer. */
+	if (!out)
+		return ret;
+	if (!out->args.vc.actions_n)
+		return -1;
+	action = &out->args.vc.actions[out->args.vc.actions_n - 1];
+	/* Point to selected object. */
+	ctx->object = out->args.vc.data;
+	ctx->objmask = NULL;
+	/* Set up default configuration. */
+	action_map_data = ctx->object;
+	*action_map_data = (struct action_map_data){
+		.conf = (struct rte_flow_action_map){
+			.flowtype = 0,
+			.pctype = 0
+		},
+	};
+
+	action->conf = &action_map_data->conf;
+	return ret;
+}
+
 /** Parse tokens for destroy command. */
 static int
 parse_destroy(struct context *ctx, const struct token *token,
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index a808b6a..d0c0b09 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -4281,6 +4281,8 @@  This section lists supported actions and their attributes, if any.
 
   - ``dscp_value {unsigned}``: The new DSCP value to be set
 
+- ``map``: map Packet Classification (PC) type to flow type.
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
@@ -4936,6 +4938,31 @@  if seid is set)::
  testpmd> flow create 0 ingress pattern eth / ipv6 / pfcp s_field is 1
         seid is 1 / end actions queue index 3 / end
 
+Sample PCTYPE mapping rules
+~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+The following sequence of commands is required for pctype mapping::
+
+ testpmd> port stop 0
+ testpmd> flow create 0 ingress pattern end actions map pctype 15 flowtype 27 /
+        end
+ testpmd> show port 0 pctype mapping
+ pctype: 15  ->  flowtype: 27
+
+ testpmd> port start 0
+ testpmd> flow create 0 ingress pattern end actions rss types end queues 0 1 2
+        3 end / end
+ testpmd> flow create 0 ingress pattern eth / ipv4 / esp / end actions rss
+        types esp end queues end / end
+
+ testpmd> flow list 0
+ ID Group   Prio    Attr Rule
+ 0  0       0       i--  => MAP
+ 1  0       0       i--  => RSS
+ 2  0       0       i--  ETH IPV4 ESP => RSS
+ testpmd> set verbose 1
+ testpmd> start
+
 BPF Functions
 --------------