Add testpmd command line to match on a meter color:
        flow create 0 ingress group 0 pattern meter color is green / end

Signed-off-by: Alexander Kozyrev <akozy...@nvidia.com>
---
 app/test-pmd/cmdline_flow.c                 | 83 +++++++++++++++++++++
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |  4 +
 2 files changed, 87 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index e3269e278d..c66da76f25 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -458,6 +458,9 @@ enum index {
        ITEM_PPP_ADDR,
        ITEM_PPP_CTRL,
        ITEM_PPP_PROTO_ID,
+       ITEM_METER,
+       ITEM_METER_COLOR,
+       ITEM_METER_COLOR_NAME,
 
        /* Validate/create actions. */
        ACTIONS,
@@ -798,6 +801,10 @@ static const char *const modify_field_ids[] = {
        "tag", "mark", "meta", "pointer", "value", NULL
 };
 
+static const char *const meter_colors[] = {
+       "green", "yellow", "red", "all", NULL
+};
+
 /** Maximum number of subsequent tokens and arguments on the stack. */
 #define CTX_STACK_SIZE 16
 
@@ -1331,6 +1338,7 @@ static const enum index next_item[] = {
        ITEM_FLEX,
        ITEM_L2TPV2,
        ITEM_PPP,
+       ITEM_METER,
        END_SET,
        ZERO,
 };
@@ -1803,6 +1811,12 @@ static const enum index item_ppp[] = {
        ZERO,
 };
 
+static const enum index item_meter[] = {
+       ITEM_METER_COLOR,
+       ITEM_NEXT,
+       ZERO,
+};
+
 static const enum index next_action[] = {
        ACTION_END,
        ACTION_VOID,
@@ -2371,6 +2385,9 @@ static int parse_ia_id2ptr(struct context *ctx, const 
struct token *token,
 static int parse_mp(struct context *, const struct token *,
                    const char *, unsigned int,
                    void *, unsigned int);
+static int parse_meter_color(struct context *ctx, const struct token *token,
+                            const char *str, unsigned int len, void *buf,
+                            unsigned int size);
 static int comp_none(struct context *, const struct token *,
                     unsigned int, char *, unsigned int);
 static int comp_boolean(struct context *, const struct token *,
@@ -2401,6 +2418,8 @@ static int comp_table_id(struct context *, const struct 
token *,
                         unsigned int, char *, unsigned int);
 static int comp_queue_id(struct context *, const struct token *,
                         unsigned int, char *, unsigned int);
+static int comp_meter_color(struct context *, const struct token *,
+                           unsigned int, char *, unsigned int);
 
 /** Token definitions. */
 static const struct token token_list[] = {
@@ -5063,6 +5082,29 @@ static const struct token token_list[] = {
                .args = ARGS(ARGS_ENTRY(struct rte_flow_item_ppp,
                                        hdr.proto_id)),
        },
+       [ITEM_METER] = {
+               .name = "meter",
+               .help = "match meter color",
+               .priv = PRIV_ITEM(METER_COLOR,
+                                 sizeof(struct rte_flow_item_meter_color)),
+               .next = NEXT(item_meter),
+               .call = parse_vc,
+       },
+       [ITEM_METER_COLOR] = {
+               .name = "color",
+               .help = "meter color",
+               .next = NEXT(item_meter,
+                            NEXT_ENTRY(ITEM_METER_COLOR_NAME),
+                            item_param),
+               .args = ARGS(ARGS_ENTRY(struct rte_flow_item_meter_color,
+                                       color)),
+       },
+       [ITEM_METER_COLOR_NAME] = {
+               .name = "color_name",
+               .help = "meter color name",
+               .call = parse_meter_color,
+               .comp = comp_meter_color,
+       },
        /* Validate/create actions. */
        [ACTIONS] = {
                .name = "actions",
@@ -9866,6 +9908,30 @@ parse_flex_handle(struct context *ctx, const struct 
token *token,
        return ret;
 }
 
+/** Parse Meter color name */
+static int
+parse_meter_color(struct context *ctx, const struct token *token,
+                 const char *str, unsigned int len, void *buf,
+                 unsigned int size)
+{
+       struct rte_flow_item_meter_color *meter_color;
+       unsigned int i;
+
+       (void)token;
+       (void)buf;
+       (void)size;
+       for (i = 0; meter_colors[i]; ++i)
+               if (!strcmp_partial(meter_colors[i], str, len))
+                       break;
+       if (!meter_colors[i])
+               return -1;
+       if (!ctx->object)
+               return len;
+       meter_color = ctx->object;
+       meter_color->color = (enum rte_color)i;
+       return len;
+}
+
 /** No completion. */
 static int
 comp_none(struct context *ctx, const struct token *token,
@@ -10157,6 +10223,20 @@ comp_queue_id(struct context *ctx, const struct token 
*token,
        return i;
 }
 
+/** Complete available Meter colors. */
+static int
+comp_meter_color(struct context *ctx, const struct token *token,
+                unsigned int ent, char *buf, unsigned int size)
+{
+       RTE_SET_USED(ctx);
+       RTE_SET_USED(token);
+       if (!buf)
+               return RTE_DIM(meter_colors);
+       if (ent < RTE_DIM(meter_colors) - 1)
+               return strlcpy(buf, meter_colors[ent], size);
+       return -1;
+}
+
 /** Internal context. */
 static struct context cmd_flow_context;
 
@@ -10772,6 +10852,9 @@ flow_item_default_mask(const struct rte_flow_item *item)
        case RTE_FLOW_ITEM_TYPE_PPP:
                mask = &rte_flow_item_ppp_mask;
                break;
+       case RTE_FLOW_ITEM_TYPE_METER_COLOR:
+               mask = &rte_flow_item_meter_color_mask;
+               break;
        default:
                break;
        }
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst 
b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 1083c6d538..5e2f5ffb40 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -4164,6 +4164,10 @@ This section lists supported pattern items and their 
attributes, if any.
   - ``ctrl {unsigned}``: PPP control.
   - ``proto_id {unsigned}``: PPP protocol identifier.
 
+- ``meter``: match Meter color.
+
+  - ``color {value}``: Meter color value(green/yellow/red).
+
 Actions list
 ^^^^^^^^^^^^
 
-- 
2.18.2

Reply via email to