From 2566c33c7147942e422ef52e213cdf0c74969e42 Mon Sep 17 00:00:00 2001 From: Gregory Etelson Date: Wed, 20 Oct 2021 18:14:56 +0300 Subject: [PATCH] app/testpmd: add flow command parsing routine testpmd flow creation is constructed from these procedures: 1. receive string with flow rule description; 2. parse input string and build flow parameters: port_id value, flow attributes, items array, actions array; 3. create a flow rule from flow rule parameters. Flow rule creation procedures are built as a pipeline. A new procedure starts immediately after successful predecessor completion. Due to this we have no dedicated routines providing intermediate results for step 1-3 above. The patch adds `flow_parse()` function call. It parses input string and provides a caller with parsed data. This is a preparation step for introducing flex item command processing. Signed-off-by: Gregory Etelson Reviewed-by: Viacheslav Ovsiienko --- app/test-pmd/cmdline_flow.c | 24 ++++++++++++++++++++++++ app/test-pmd/testpmd.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index a90822b660..cd640b9b7a 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -8076,6 +8076,30 @@ cmd_flow_parse(cmdline_parse_token_hdr_t *hdr, const char *src, void *result, return len; } +int +flow_parse(const char *src, void *result, unsigned int size, + struct rte_flow_attr **attr, + struct rte_flow_item **pattern, struct rte_flow_action **actions) +{ + int ret; + struct context saved_flow_ctx = cmd_flow_context; + + cmd_flow_context_init(&cmd_flow_context); + do { + ret = cmd_flow_parse(NULL, src, result, size); + if (ret > 0) { + src += ret; + while (isspace(*src)) + src++; + } + } while (ret > 0 && strlen(src)); + cmd_flow_context = saved_flow_ctx; + *attr = &((struct buffer *)result)->args.vc.attr; + *pattern = ((struct buffer *)result)->args.vc.pattern; + *actions = ((struct buffer *)result)->args.vc.actions; + return (ret >= 0 && !strlen(src)) ? 0 : -1; +} + /** Return number of completion entries (cmdline API). */ static int cmd_flow_complete_get_nb(cmdline_parse_token_hdr_t *hdr) diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index dd8f27a296..81be754605 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -1047,6 +1047,11 @@ void add_tx_dynf_callback(portid_t portid); void remove_tx_dynf_callback(portid_t portid); int update_mtu_from_frame_size(portid_t portid, uint32_t max_rx_pktlen); +extern int flow_parse(const char *src, void *result, unsigned int size, + struct rte_flow_attr **attr, + struct rte_flow_item **pattern, + struct rte_flow_action **actions); + /* * Work-around of a compilation error with ICC on invocations of the * rte_be_to_cpu_16() function. -- 2.20.1