Add testpmd command line to match for METER_MARK action:
        flow create ... actions meter_mark mtr_profile 20 / end

Signed-off-by: Alexander Kozyrev <akozy...@nvidia.com>
---
 app/test-pmd/cmdline_flow.c                 | 127 ++++++++++++++++++++
 app/test-pmd/config.c                       |  26 ++++
 app/test-pmd/testpmd.h                      |   4 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |   5 +
 4 files changed, 162 insertions(+)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 401922fc34..7261d6f52e 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -53,6 +53,7 @@ enum index {
        COMMON_GROUP_ID,
        COMMON_PRIORITY_LEVEL,
        COMMON_INDIRECT_ACTION_ID,
+       COMMON_PROFILE_ID,
        COMMON_POLICY_ID,
        COMMON_FLEX_HANDLE,
        COMMON_FLEX_TOKEN,
@@ -508,6 +509,11 @@ enum index {
        ACTION_METER_COLOR_YELLOW,
        ACTION_METER_COLOR_RED,
        ACTION_METER_ID,
+       ACTION_METER_MARK,
+       ACTION_METER_PROFILE,
+       ACTION_METER_PROFILE_ID2PTR,
+       ACTION_METER_POLICY,
+       ACTION_METER_POLICY_ID2PTR,
        ACTION_OF_SET_MPLS_TTL,
        ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
        ACTION_OF_DEC_MPLS_TTL,
@@ -1835,6 +1841,7 @@ static const enum index next_action[] = {
        ACTION_PORT_ID,
        ACTION_METER,
        ACTION_METER_COLOR,
+       ACTION_METER_MARK,
        ACTION_OF_SET_MPLS_TTL,
        ACTION_OF_DEC_MPLS_TTL,
        ACTION_OF_SET_NW_TTL,
@@ -1951,6 +1958,13 @@ static const enum index action_meter_color[] = {
        ZERO,
 };
 
+static const enum index action_meter_mark[] = {
+       ACTION_METER_PROFILE,
+       ACTION_METER_POLICY,
+       ACTION_NEXT,
+       ZERO,
+};
+
 static const enum index action_of_set_mpls_ttl[] = {
        ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
        ACTION_NEXT,
@@ -2389,6 +2403,14 @@ static int parse_mp(struct context *, const struct token 
*,
 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 parse_meter_profile_id2ptr(struct context *ctx,
+                                     const struct token *token,
+                                     const char *str, unsigned int len,
+                                     void *buf, unsigned int size);
+static int parse_meter_policy_id2ptr(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 *,
@@ -2550,6 +2572,13 @@ static const struct token token_list[] = {
                .call = parse_int,
                .comp = comp_none,
        },
+       [COMMON_PROFILE_ID] = {
+               .name = "{profile_id}",
+               .type = "PROFILE_ID",
+               .help = "profile id",
+               .call = parse_int,
+               .comp = comp_none,
+       },
        [COMMON_POLICY_ID] = {
                .name = "{policy_id}",
                .type = "POLICY_ID",
@@ -5428,6 +5457,42 @@ static const struct token token_list[] = {
                .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)),
                .call = parse_vc_conf,
        },
+       [ACTION_METER_MARK] = {
+               .name = "meter_mark",
+               .help = "meter the directed packets using profile and policy",
+               .priv = PRIV_ACTION(METER_MARK,
+                                   sizeof(struct rte_flow_action_meter_mark)),
+               .next = NEXT(action_meter_mark),
+               .call = parse_vc,
+       },
+       [ACTION_METER_PROFILE] = {
+               .name = "mtr_profile",
+               .help = "meter profile id to use",
+               .next = NEXT(NEXT_ENTRY(ACTION_METER_PROFILE_ID2PTR)),
+               .args = ARGS(ARGS_ENTRY_ARB(0, sizeof(uint32_t))),
+       },
+       [ACTION_METER_PROFILE_ID2PTR] = {
+               .name = "{mtr_profile_id}",
+               .type = "PROFILE_ID",
+               .help = "meter profile id",
+               .next = NEXT(action_meter_mark),
+               .call = parse_meter_profile_id2ptr,
+               .comp = comp_none,
+       },
+       [ACTION_METER_POLICY] = {
+               .name = "mtr_policy",
+               .help = "meter policy id to use",
+               .next = NEXT(NEXT_ENTRY(ACTION_METER_POLICY_ID2PTR)),
+               ARGS(ARGS_ENTRY_ARB(0, sizeof(uint32_t))),
+       },
+       [ACTION_METER_POLICY_ID2PTR] = {
+               .name = "{mtr_policy_id}",
+               .type = "POLICY_ID",
+               .help = "meter policy id",
+               .next = NEXT(action_meter_mark),
+               .call = parse_meter_policy_id2ptr,
+               .comp = comp_none,
+       },
        [ACTION_OF_SET_MPLS_TTL] = {
                .name = "of_set_mpls_ttl",
                .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
@@ -9747,6 +9812,68 @@ parse_ia_id2ptr(struct context *ctx, const struct token 
*token,
        return ret;
 }
 
+static int
+parse_meter_profile_id2ptr(struct context *ctx, const struct token *token,
+                          const char *str, unsigned int len,
+                          void *buf, unsigned int size)
+{
+       struct rte_flow_action *action = ctx->object;
+       struct rte_flow_action_meter_mark *meter;
+       struct rte_flow_meter_profile *profile = NULL;
+       uint32_t id;
+       int ret;
+
+       (void)buf;
+       (void)size;
+       ctx->objdata = 0;
+       ctx->object = &id;
+       ctx->objmask = NULL;
+       ret = parse_int(ctx, token, str, len, ctx->object, sizeof(id));
+       ctx->object = action;
+       if (ret != (int)len)
+               return ret;
+       /* set meter profile */
+       if (action) {
+               meter = (struct rte_flow_action_meter_mark *)
+                               (uintptr_t)(action->conf);
+               profile = port_meter_profile_get_by_id(ctx->port, id);
+               meter->profile = profile;
+               ret = (profile) ? ret : -1;
+       }
+       return ret;
+}
+
+static int
+parse_meter_policy_id2ptr(struct context *ctx, const struct token *token,
+                         const char *str, unsigned int len,
+                         void *buf, unsigned int size)
+{
+       struct rte_flow_action *action = ctx->object;
+       struct rte_flow_action_meter_mark *meter;
+       struct rte_flow_meter_policy *policy = NULL;
+       uint32_t id;
+       int ret;
+
+       (void)buf;
+       (void)size;
+       ctx->objdata = 0;
+       ctx->object = &id;
+       ctx->objmask = NULL;
+       ret = parse_int(ctx, token, str, len, ctx->object, sizeof(id));
+       ctx->object = action;
+       if (ret != (int)len)
+               return ret;
+       /* set meter policy */
+       if (action) {
+               meter = (struct rte_flow_action_meter_mark *)
+                               (uintptr_t)(action->conf);
+               policy = port_meter_policy_get_by_id(ctx->port, id);
+               meter->policy = policy;
+               ret = (policy) ? ret : -1;
+       }
+       return ret;
+}
+
 /** Parse set command, initialize output buffer for subsequent tokens. */
 static int
 parse_set_raw_encap_decap(struct context *ctx, const struct token *token,
diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c
index 1b1e738f83..413dcb6e9d 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -2184,6 +2184,32 @@ port_meter_policy_add(portid_t port_id, uint32_t 
policy_id,
        return ret;
 }
 
+/** Get port meter profile */
+struct rte_flow_meter_profile *
+port_meter_profile_get_by_id(portid_t port_id, uint32_t id)
+{
+       struct rte_mtr_error error;
+       struct rte_flow_meter_profile *profile;
+
+       profile = rte_mtr_meter_profile_get(port_id, id, &error);
+       if (!profile)
+               print_mtr_err_msg(&error);
+       return profile;
+}
+
+/** Get port meter policy */
+struct rte_flow_meter_policy *
+port_meter_policy_get_by_id(portid_t port_id, uint32_t id)
+{
+       struct rte_mtr_error error;
+       struct rte_flow_meter_policy *policy;
+
+       policy = rte_mtr_meter_policy_get(port_id, id, &error);
+       if (!policy)
+               print_mtr_err_msg(&error);
+       return policy;
+}
+
 /** Validate flow rule. */
 int
 port_flow_validate(portid_t port_id,
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index f04a9a11b4..5fed46ae17 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -985,6 +985,10 @@ void port_flow_tunnel_create(portid_t port_id, const 
struct tunnel_ops *ops);
 int port_flow_isolate(portid_t port_id, int set);
 int port_meter_policy_add(portid_t port_id, uint32_t policy_id,
                const struct rte_flow_action *actions);
+struct rte_flow_meter_profile *port_meter_profile_get_by_id(portid_t port_id,
+                                                           uint32_t id);
+struct rte_flow_meter_policy *port_meter_policy_get_by_id(portid_t port_id,
+                                                         uint32_t id);
 
 void rx_ring_desc_display(portid_t port_id, queueid_t rxq_id, uint16_t rxd_id);
 void tx_ring_desc_display(portid_t port_id, queueid_t txq_id, uint16_t txd_id);
diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst 
b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
index 5e2f5ffb40..fd5a05dbad 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -4453,6 +4453,11 @@ This section lists supported actions and their 
attributes, if any.
 
   - ``ethdev_port_id {unsigned}``: ethdev port ID
 
+- ``meter_mark``:  meter the directed packets using profile and policy
+
+  - ``mtr_profile {unsigned}``: meter profile id to use
+  - ``mtr_policy {unsigned}``: meter policy id to use
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
-- 
2.18.2

Reply via email to