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                 | 153 ++++++++++++++++++++
 app/test-pmd/config.c                       |  45 +++++-
 app/test-pmd/testpmd.h                      |   4 +
 doc/guides/testpmd_app_ug/testpmd_funcs.rst |   8 +
 4 files changed, 209 insertions(+), 1 deletion(-)

diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c
index 601df52f38..417655eca8 100644
--- a/app/test-pmd/cmdline_flow.c
+++ b/app/test-pmd/cmdline_flow.c
@@ -54,6 +54,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,
@@ -509,6 +510,14 @@ 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_METER_COLOR_MODE,
+       ACTION_METER_INIT_COLOR,
+       ACTION_METER_STATE,
        ACTION_OF_SET_MPLS_TTL,
        ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
        ACTION_OF_DEC_MPLS_TTL,
@@ -1836,6 +1845,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,
@@ -1952,6 +1962,16 @@ static const enum index action_meter_color[] = {
        ZERO,
 };
 
+static const enum index action_meter_mark[] = {
+       ACTION_METER_PROFILE,
+       ACTION_METER_POLICY,
+       ACTION_METER_COLOR_MODE,
+       ACTION_METER_INIT_COLOR,
+       ACTION_METER_STATE,
+       ACTION_NEXT,
+       ZERO,
+};
+
 static const enum index action_of_set_mpls_ttl[] = {
        ACTION_OF_SET_MPLS_TTL_MPLS_TTL,
        ACTION_NEXT,
@@ -2387,6 +2407,14 @@ 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_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 parse_meter_color(struct context *ctx, const struct token *token,
                             const char *str, unsigned int len, void *buf,
                             unsigned int size);
@@ -2551,6 +2579,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",
@@ -5429,6 +5464,62 @@ 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_METER_COLOR_MODE] = {
+               .name = "mtr_color_mode",
+               .help = "meter color awareness mode",
+               .next = NEXT(action_meter_mark, NEXT_ENTRY(COMMON_UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter_mark, 
color_mode)),
+               .call = parse_vc_conf,
+       },
+       [ACTION_METER_INIT_COLOR] = {
+               .name = "mtr_init_color",
+               .help = "meter initial color",
+               .next = NEXT(action_meter_mark, 
NEXT_ENTRY(ITEM_METER_COLOR_NAME)),
+               .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter_mark, 
init_color)),
+       },
+       [ACTION_METER_STATE] = {
+               .name = "mtr_state",
+               .help = "meter state",
+               .next = NEXT(action_meter_mark, NEXT_ENTRY(COMMON_UNSIGNED)),
+               .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter_mark, 
state)),
+               .call = parse_vc_conf,
+       },
        [ACTION_OF_SET_MPLS_TTL] = {
                .name = "of_set_mpls_ttl",
                .help = "OpenFlow's OFPAT_SET_MPLS_TTL",
@@ -9748,6 +9839,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 = 0;
+       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 = 0;
+       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 568b0881d4..06d6dc3546 100644
--- a/app/test-pmd/config.c
+++ b/app/test-pmd/config.c
@@ -2122,6 +2122,29 @@ port_meter_policy_add(portid_t port_id, uint32_t 
policy_id,
        return ret;
 }
 
+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;
+}
+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,
@@ -2709,6 +2732,9 @@ port_queue_action_handle_update(portid_t port_id,
        struct rte_port *port;
        struct rte_flow_error error;
        struct rte_flow_action_handle *action_handle;
+       struct port_indirect_action *pia;
+       struct rte_flow_update_meter_mark mtr_update;
+       const void *update;
 
        action_handle = port_action_handle_get_by_id(port_id, id);
        if (!action_handle)
@@ -2720,8 +2746,25 @@ port_queue_action_handle_update(portid_t port_id,
                return -EINVAL;
        }
 
+       pia = action_get_by_id(port_id, id);
+       if (!pia)
+               return -EINVAL;
+
+       if (pia->type == RTE_FLOW_ACTION_TYPE_METER_MARK) {
+               rte_memcpy(&mtr_update.meter_mark, action->conf,
+                       sizeof(struct rte_flow_action_meter_mark));
+               mtr_update.profile_valid = 1;
+               mtr_update.policy_valid  = 1;
+               mtr_update.color_mode_valid  = 1;
+               mtr_update.init_color_valid  = 1;
+               mtr_update.state_valid  = 1;
+               update = &mtr_update;
+       } else {
+               update = action;
+       }
+
        if (rte_flow_async_action_handle_update(port_id, queue_id, &attr,
-                                   action_handle, action, NULL, &error)) {
+                                       action_handle, update, NULL, &error)) {
                return port_flow_complain(&error);
        }
        printf("Indirect action #%u update queued\n", id);
diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h
index 21c5632aec..e96f563674 100644
--- a/app/test-pmd/testpmd.h
+++ b/app/test-pmd/testpmd.h
@@ -938,6 +938,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 b586e92649..d1f536b6fe 100644
--- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst
+++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst
@@ -3986,6 +3986,14 @@ 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
+  - ``mtr_color_mode {unsigned}``: meter color-awareness mode (blind/aware)
+  - ``mtr_init_color {value}``: initial color value(green/yellow/red)
+  - ``mtr_state {unsigned}``: meter state (disabled/enabled)
+
 Destroying flow rules
 ~~~~~~~~~~~~~~~~~~~~~
 
-- 
2.18.2

Reply via email to