From c5c507100ea58e24f812401c77c66cdb9bceee36 Mon Sep 17 00:00:00 2001 From: Haifei Luo Date: Wed, 12 May 2021 13:49:33 +0300 Subject: [PATCH] app/testpmd: support action meter color Currently action RTE_FLOW_ACTION_TYPE_METER_COLOR is defined. Add the CLI for this action: color type (types) There are three types: green, yellow and red. Example for the new policy meter CLIs: add port meter policy 0 1 g_actions color type green / end y_actions color type yellow / end r_actions color type red / end In the above command, the action type is RTE_FLOW_ACTION_TYPE_METER_COLOR, the meter policy action list: green -> green, yellow -> yellow, red -> red. Signed-off-by: Haifei Luo Acked-by: Ori Kam Acked-by: Cristian Dumitrescu Acked-by: Ferruh Yigit --- app/test-pmd/cmdline_flow.c | 85 +++++++++++++++++++++ doc/guides/rel_notes/release_21_05.rst | 3 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 24 ++++++ 3 files changed, 112 insertions(+) diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 5947341992..1c587bb7b8 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -348,6 +348,11 @@ enum index { ACTION_PORT_ID_ORIGINAL, ACTION_PORT_ID_ID, ACTION_METER, + ACTION_METER_COLOR, + ACTION_METER_COLOR_TYPE, + ACTION_METER_COLOR_GREEN, + ACTION_METER_COLOR_YELLOW, + ACTION_METER_COLOR_RED, ACTION_METER_ID, ACTION_OF_SET_MPLS_TTL, ACTION_OF_SET_MPLS_TTL_MPLS_TTL, @@ -1377,6 +1382,7 @@ static const enum index next_action[] = { ACTION_PHY_PORT, ACTION_PORT_ID, ACTION_METER, + ACTION_METER_COLOR, ACTION_OF_SET_MPLS_TTL, ACTION_OF_DEC_MPLS_TTL, ACTION_OF_SET_NW_TTL, @@ -1486,6 +1492,12 @@ static const enum index action_meter[] = { ZERO, }; +static const enum index action_meter_color[] = { + ACTION_METER_COLOR_TYPE, + ACTION_NEXT, + ZERO, +}; + static const enum index action_of_set_mpls_ttl[] = { ACTION_OF_SET_MPLS_TTL_MPLS_TTL, ACTION_NEXT, @@ -1723,6 +1735,10 @@ static int parse_vc_conf(struct context *, const struct token *, static int parse_vc_item_ecpri_type(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); +static int parse_vc_action_meter_color_type(struct context *, + const struct token *, + const char *, unsigned int, void *, + unsigned int); static int parse_vc_action_rss(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -3801,6 +3817,37 @@ static const struct token token_list[] = { .next = NEXT(action_meter), .call = parse_vc, }, + [ACTION_METER_COLOR] = { + .name = "color", + .help = "meter color for the packets", + .priv = PRIV_ACTION(METER_COLOR, + sizeof(struct rte_flow_action_meter_color)), + .next = NEXT(action_meter_color), + .call = parse_vc, + }, + [ACTION_METER_COLOR_TYPE] = { + .name = "type", + .help = "specific meter color", + .next = NEXT(NEXT_ENTRY(ACTION_NEXT), + NEXT_ENTRY(ACTION_METER_COLOR_GREEN, + ACTION_METER_COLOR_YELLOW, + ACTION_METER_COLOR_RED)), + }, + [ACTION_METER_COLOR_GREEN] = { + .name = "green", + .help = "meter color green", + .call = parse_vc_action_meter_color_type, + }, + [ACTION_METER_COLOR_YELLOW] = { + .name = "yellow", + .help = "meter color yellow", + .call = parse_vc_action_meter_color_type, + }, + [ACTION_METER_COLOR_RED] = { + .name = "red", + .help = "meter color red", + .call = parse_vc_action_meter_color_type, + }, [ACTION_METER_ID] = { .name = "mtr_id", .help = "meter id to use", @@ -5318,6 +5365,44 @@ parse_vc_item_ecpri_type(struct context *ctx, const struct token *token, return len; } +/** Parse meter color action type. */ +static int +parse_vc_action_meter_color_type(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + struct rte_flow_action *action_data; + struct rte_flow_action_meter_color *conf; + enum rte_color color; + + (void)buf; + (void)size; + /* Token name must match. */ + if (parse_default(ctx, token, str, len, NULL, 0) < 0) + return -1; + switch (ctx->curr) { + case ACTION_METER_COLOR_GREEN: + color = RTE_COLOR_GREEN; + break; + case ACTION_METER_COLOR_YELLOW: + color = RTE_COLOR_YELLOW; + break; + case ACTION_METER_COLOR_RED: + color = RTE_COLOR_RED; + break; + default: + return -1; + } + + if (!ctx->object) + return len; + action_data = ctx->object; + conf = (struct rte_flow_action_meter_color *) + (uintptr_t)(action_data->conf); + conf->color = color; + return len; +} + /** Parse RSS action. */ static int parse_vc_action_rss(struct context *ctx, const struct token *token, diff --git a/doc/guides/rel_notes/release_21_05.rst b/doc/guides/rel_notes/release_21_05.rst index 9bc190ab51..bb8fe03b0b 100644 --- a/doc/guides/rel_notes/release_21_05.rst +++ b/doc/guides/rel_notes/release_21_05.rst @@ -277,6 +277,9 @@ New Features * Added commands to construct conntrack context and relevant indirect action handle creation, update for conntrack action as well as conntrack item matching. + * Added commands for action meter color to color the packet to reflect + the meter color result. + ``color type (green|yellow|red)`` * **Added support for the FIB lookup method in the l3fwd example app.** diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 98a669b892..33857acf54 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -4089,6 +4089,10 @@ This section lists supported actions and their attributes, if any. - ``indirect_action_id {unsigned}``: Indirect action ID to use +- ``color``: Color the packet to reflect the meter color result + + - ``type {value}``: Set color type with specified value(green/yellow/red) + Destroying flow rules ~~~~~~~~~~~~~~~~~~~~~ @@ -5010,6 +5014,26 @@ rules like above for the peer port. testpmd> flow indirect_action 0 update 0 action conntrack_update dir / end +Sample meter with policy rules +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Meter with policy rules can be created by the following commands: + +Need to create policy first and actions are set for green/yellow/red colors. +Create meter with policy id. Create flow with meter id. + +Example for policy with meter color action. The purpose is to color the packet +to reflect the meter color result. +The meter policy action list: ``green -> green, yellow -> yellow, red -> red``. + +:: + + testpmd> add port meter profile srtcm_rfc2697 0 13 21504 2688 0 0 + testpmd> add port meter policy 0 1 g_actions color type green / end y_actions color type yellow / end + r_actions color type red / end + testpmd> create port meter 0 1 13 1 yes 0xffff 0 0 + testpmd> flow create 0 priority 0 ingress group 1 pattern eth / end actions meter mtr_id 1 / end + BPF Functions -------------- -- 2.20.1