From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 58067A0548; Fri, 2 Apr 2021 12:36:35 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2C544140F25; Fri, 2 Apr 2021 12:36:33 +0200 (CEST) Received: from mellanox.co.il (mail-il-dmz.mellanox.com [193.47.165.129]) by mails.dpdk.org (Postfix) with ESMTP id 34090140F25 for ; Fri, 2 Apr 2021 12:36:32 +0200 (CEST) Received: from Internal Mail-Server by MTLPINE1 (envelope-from lizh@nvidia.com) with SMTP; 2 Apr 2021 13:36:27 +0300 Received: from nvidia.com (c-235-17-1-009.mtl.labs.mlnx [10.235.17.9]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id 132AaQof022284; Fri, 2 Apr 2021 13:36:27 +0300 From: Li Zhang To: dekelp@nvidia.com, orika@nvidia.com, viacheslavo@nvidia.com, matan@nvidia.com, shahafs@nvidia.com, cristian.dumitrescu@intel.com, lironh@marvell.com, Xiaoyun Li Cc: dev@dpdk.org, thomas@monjalon.net, rasland@nvidia.com, roniba@nvidia.com, Haifei Luo Date: Fri, 2 Apr 2021 13:36:23 +0300 Message-Id: <20210402103623.1524254-3-lizh@nvidia.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20210402103623.1524254-1-lizh@nvidia.com> References: <20210401065448.1480127-1-lizh@nvidia.com> <20210402103623.1524254-1-lizh@nvidia.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 2/2] app/testpmd: support policy actions per color X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" From: Haifei Luo add the new create meter with policy API to support it. Signed-off-by: Haifei Luo --- app/test-pmd/cmdline.c | 6 +- app/test-pmd/cmdline_flow.c | 118 +++++++++++++++++++++++++++++++++++- app/test-pmd/cmdline_mtr.c | 85 ++++++++++++++++++++++++-- app/test-pmd/cmdline_mtr.h | 3 + app/test-pmd/config.c | 34 +++++++++++ app/test-pmd/testpmd.h | 2 + 6 files changed, 240 insertions(+), 8 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index dcb5f9c871..029cb38786 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -705,7 +705,7 @@ static void cmd_help_long_parsed(void *parsed_result, "del port meter profile (port_id) (profile_id)\n" " meter profile delete\n\n" - "create port meter (port_id) (mtr_id) (profile_id) (meter_enable)\n" + "create port meter (port_id) [mtr_id] (profile_id) [policy (policy_id)] (meter_enable)\n" "(g_action) (y_action) (r_action) (stats_mask) (shared)\n" "(use_pre_meter_color) [(dscp_tbl_entry0) (dscp_tbl_entry1)...\n" "(dscp_tbl_entry63)]\n" @@ -720,6 +720,9 @@ static void cmd_help_long_parsed(void *parsed_result, "del port meter (port_id) (mtr_id)\n" " meter delete\n\n" + "del port meter policy (port_id) (policy_id)\n" + " meter policy delete\n\n" + "set port meter profile (port_id) (mtr_id) (profile_id)\n" " meter update meter profile\n\n" @@ -17067,6 +17070,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_enable_port_meter, (cmdline_parse_inst_t *)&cmd_disable_port_meter, (cmdline_parse_inst_t *)&cmd_del_port_meter, + (cmdline_parse_inst_t *)&cmd_del_port_meter_policy, (cmdline_parse_inst_t *)&cmd_set_port_meter_profile, (cmdline_parse_inst_t *)&cmd_set_port_meter_dscp_table, (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask, diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index 2c40c6996e..050290990a 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -55,6 +55,10 @@ enum index { GROUP_ID, PRIORITY_LEVEL, SHARED_ACTION_ID, + POLICY_ID, + + /* TOP-level command. */ + ADD, /* Top-level command. */ SET, @@ -289,6 +293,9 @@ enum index { ITEM_GENEVE_OPT_TYPE, ITEM_GENEVE_OPT_LENGTH, ITEM_GENEVE_OPT_DATA, + ITEM_POL_PORT, + ITEM_POL_METER, + ITEM_POL_POLICY, /* Validate/create actions. */ ACTIONS, @@ -427,6 +434,9 @@ enum index { ACTION_MODIFY_FIELD_SRC_OFFSET, ACTION_MODIFY_FIELD_SRC_VALUE, ACTION_MODIFY_FIELD_WIDTH, + ACTION_POL_G, + ACTION_POL_Y, + ACTION_POL_R, }; /** Maximum size for pattern in struct rte_flow_item_raw. */ @@ -806,6 +816,9 @@ struct buffer { struct { int destroy; } aged; /**< Aged arguments. */ + struct { + uint32_t policy_id; + } policy;/**< Policy arguments. */ } args; /**< Command arguments. */ }; @@ -1781,6 +1794,9 @@ static int parse_ipv6_addr(struct context *, const struct token *, static int parse_port(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); +static int parse_mp(struct context *, const struct token *, + const char *, unsigned int, + void *, unsigned int); static int parse_sa(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -1819,7 +1835,7 @@ static const struct token token_list[] = { [ZERO] = { .name = "ZERO", .help = "null entry, abused as the entry point", - .next = NEXT(NEXT_ENTRY(FLOW)), + .next = NEXT(NEXT_ENTRY(FLOW, ADD)), }, [END] = { .name = "", @@ -1941,6 +1957,13 @@ static const struct token token_list[] = { .call = parse_int, .comp = comp_none, }, + [POLICY_ID] = { + .name = "{policy_id}", + .type = "POLCIY_ID", + .help = "policy id", + .call = parse_int, + .comp = comp_none, + }, /* Top-level command. */ [FLOW] = { .name = "flow", @@ -4524,6 +4547,54 @@ static const struct token token_list[] = { .help = "specify action to share", .next = NEXT(next_action), }, + [ACTION_POL_G] = { + .name = "g_actions", + .help = "submit a list of associated actions for green", + .next = NEXT(next_action), + .call = parse_mp, + }, + [ACTION_POL_Y] = { + .name = "y_actions", + .help = "submit a list of associated actions for yellow", + .next = NEXT(next_action), + }, + [ACTION_POL_R] = { + .name = "r_actions", + .help = "submit a list of associated actions for red", + .next = NEXT(next_action), + }, + + /* Top-level command. */ + [ADD] = { + .name = "add", + .type = "port meter policy {port_id} {arg}", + .help = "add port meter policy", + .next = NEXT(NEXT_ENTRY(ITEM_POL_PORT)), + .call = parse_init, + }, + /* Sub-level commands. */ + [ITEM_POL_PORT] = { + .name = "port", + .help = "add port meter policy", + .next = NEXT(NEXT_ENTRY(ITEM_POL_METER)), + }, + [ITEM_POL_METER] = { + .name = "meter", + .help = "add port meter policy", + .next = NEXT(NEXT_ENTRY(ITEM_POL_POLICY)), + }, + [ITEM_POL_POLICY] = { + .name = "policy", + .help = "add port meter policy", + .next = NEXT(NEXT_ENTRY(ACTION_POL_R), + NEXT_ENTRY(ACTION_POL_Y), + NEXT_ENTRY(ACTION_POL_G), + NEXT_ENTRY(POLICY_ID), + NEXT_ENTRY(PORT_ID)), + .args = ARGS(ARGS_ENTRY(struct buffer, args.policy.policy_id), + ARGS_ENTRY(struct buffer, port)), + .call = parse_mp, + }, }; /** Remove and return last entry from argument stack. */ @@ -4708,6 +4779,47 @@ parse_init(struct context *ctx, const struct token *token, return len; } +/** Parse tokens for meter policy action commands. */ +static int +parse_mp(struct context *ctx, const struct token *token, + const char *str, unsigned int len, + void *buf, unsigned int size) +{ + struct buffer *out = buf; + + /* Token name must match. */ + if (parse_default(ctx, token, str, len, NULL, 0) < 0) + return -1; + /* Nothing else to do if there is no buffer. */ + if (!out) + return len; + if (!out->command) { + if (ctx->curr != ITEM_POL_POLICY) + return -1; + if (sizeof(*out) > size) + return -1; + out->command = ctx->curr; + ctx->objdata = 0; + ctx->object = out; + ctx->objmask = NULL; + out->args.vc.data = (uint8_t *)out + size; + return len; + } + switch (ctx->curr) { + case ACTION_POL_G: + out->args.vc.actions = + (void *)RTE_ALIGN_CEIL((uintptr_t)(out + 1), + sizeof(double)); + out->command = ctx->curr; + ctx->objdata = 0; + ctx->object = out; + ctx->objmask = NULL; + return len; + default: + return -1; + } +} + /** Parse tokens for shared action commands. */ static int parse_sa(struct context *ctx, const struct token *token, @@ -7665,6 +7777,10 @@ cmd_flow_parsed(const struct buffer *in) case TUNNEL_LIST: port_flow_tunnel_list(in->port); break; + case ACTION_POL_G: + port_meter_policy_add(in->port, in->args.policy.policy_id, + in->args.vc.actions); + break; default: break; } diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c index 44394e3ea1..bdc9ae8bfe 100644 --- a/app/test-pmd/cmdline_mtr.c +++ b/app/test-pmd/cmdline_mtr.c @@ -37,6 +37,8 @@ print_err_msg(struct rte_mtr_error *error) [RTE_MTR_ERROR_TYPE_STATS] = "stats", [RTE_MTR_ERROR_TYPE_SHARED] = "shared meter", + [RTE_MTR_ERROR_TYPE_METER_POLICY_ID] = "meter policy id", + [RTE_MTR_ERROR_TYPE_METER_POLICY] = "meter policy null", }; const char *errstr; @@ -56,6 +58,12 @@ print_err_msg(struct rte_mtr_error *error) error->type); } +void +print_mtr_err_msg(struct rte_mtr_error *error) +{ + print_err_msg(error); +} + static int parse_uint(uint64_t *value, const char *str) { @@ -671,6 +679,7 @@ struct cmd_create_port_meter_result { uint16_t port_id; uint32_t mtr_id; uint32_t profile_id; + uint32_t policy_id; cmdline_fixed_string_t meter_enable; cmdline_fixed_string_t g_action; cmdline_fixed_string_t y_action; @@ -698,6 +707,9 @@ cmdline_parse_token_num_t cmd_create_port_meter_mtr_id = cmdline_parse_token_num_t cmd_create_port_meter_profile_id = TOKEN_NUM_INITIALIZER( struct cmd_create_port_meter_result, profile_id, RTE_UINT32); +cmdline_parse_token_num_t cmd_create_port_meter_policy_id = + TOKEN_NUM_INITIALIZER( + struct cmd_create_port_meter_result, policy_id, RTE_UINT32); cmdline_parse_token_string_t cmd_create_port_meter_meter_enable = TOKEN_STRING_INITIALIZER(struct cmd_create_port_meter_result, meter_enable, "yes#no"); @@ -741,7 +753,7 @@ static void cmd_create_port_meter_parsed(void *parsed_result, /* Meter params */ memset(¶ms, 0, sizeof(struct rte_mtr_params)); params.meter_profile_id = res->profile_id; - + params.meter_policy_id = res->policy_id; /* Parse meter input color string params */ ret = parse_meter_color_str(c_str, &use_prev_meter_color, &dscp_table); if (ret) { @@ -756,7 +768,6 @@ static void cmd_create_port_meter_parsed(void *parsed_result, params.meter_enable = 1; else params.meter_enable = 0; - params.stats_mask = res->statistics_mask; ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error); @@ -771,7 +782,6 @@ cmdline_parse_inst_t cmd_create_port_meter = { .f = cmd_create_port_meter_parsed, .data = NULL, .help_str = "create port meter (yes|no) " - "(R|Y|G|D) (R|Y|G|D) (R|Y|G|D) " " " "[ ...]", .tokens = { @@ -781,10 +791,8 @@ cmdline_parse_inst_t cmd_create_port_meter = { (void *)&cmd_create_port_meter_port_id, (void *)&cmd_create_port_meter_mtr_id, (void *)&cmd_create_port_meter_profile_id, + (void *)&cmd_create_port_meter_policy_id, (void *)&cmd_create_port_meter_meter_enable, - (void *)&cmd_create_port_meter_g_action, - (void *)&cmd_create_port_meter_y_action, - (void *)&cmd_create_port_meter_r_action, (void *)&cmd_create_port_meter_statistics_mask, (void *)&cmd_create_port_meter_shared, (void *)&cmd_create_port_meter_input_color, @@ -914,6 +922,71 @@ cmdline_parse_inst_t cmd_disable_port_meter = { }, }; +/* *** Delete Port Meter Policy Object *** */ +struct cmd_del_port_meter_policy_result { + cmdline_fixed_string_t del; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + cmdline_fixed_string_t policy; + uint16_t port_id; + uint32_t policy_id; +}; + +cmdline_parse_token_string_t cmd_del_port_meter_policy_del = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_policy_result, del, "del"); +cmdline_parse_token_string_t cmd_del_port_meter_policy_port = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_policy_result, port, "port"); +cmdline_parse_token_string_t cmd_del_port_meter_policy_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_policy_result, meter, "meter"); +cmdline_parse_token_string_t cmd_del_port_meter_policy_policy = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_policy_result, policy, "policy"); +cmdline_parse_token_num_t cmd_del_port_meter_policy_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_meter_policy_result, port_id, RTE_UINT16); +cmdline_parse_token_num_t cmd_del_port_meter_policy_policy_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_meter_policy_result, policy_id, RTE_UINT32); + +static void cmd_del_port_meter_policy_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_del_port_meter_policy_result *res = parsed_result; + struct rte_mtr_error error; + uint32_t policy_id = res->policy_id; + uint16_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Delete Meter Policy*/ + ret = rte_mtr_meter_policy_delete(port_id, policy_id, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_del_port_meter_policy = { + .f = cmd_del_port_meter_policy_parsed, + .data = NULL, + .help_str = "Delete port meter policy", + .tokens = { + (void *)&cmd_del_port_meter_policy_del, + (void *)&cmd_del_port_meter_policy_port, + (void *)&cmd_del_port_meter_policy_meter, + (void *)&cmd_del_port_meter_policy_policy, + (void *)&cmd_del_port_meter_policy_port_id, + (void *)&cmd_del_port_meter_policy_policy_id, + NULL, + }, +}; + /* *** Delete Port Meter Object *** */ struct cmd_del_port_meter_result { cmdline_fixed_string_t del; diff --git a/app/test-pmd/cmdline_mtr.h b/app/test-pmd/cmdline_mtr.h index 7e2713cea3..2415fc16c3 100644 --- a/app/test-pmd/cmdline_mtr.h +++ b/app/test-pmd/cmdline_mtr.h @@ -4,6 +4,7 @@ #ifndef _CMDLINE_MTR_H_ #define _CMDLINE_MTR_H_ +#include /* Traffic Metering and Policing */ extern cmdline_parse_inst_t cmd_show_port_meter_cap; @@ -15,9 +16,11 @@ extern cmdline_parse_inst_t cmd_create_port_meter; extern cmdline_parse_inst_t cmd_enable_port_meter; extern cmdline_parse_inst_t cmd_disable_port_meter; extern cmdline_parse_inst_t cmd_del_port_meter; +extern cmdline_parse_inst_t cmd_del_port_meter_policy; extern cmdline_parse_inst_t cmd_set_port_meter_profile; extern cmdline_parse_inst_t cmd_set_port_meter_dscp_table; extern cmdline_parse_inst_t cmd_set_port_meter_stats_mask; extern cmdline_parse_inst_t cmd_show_port_meter_stats; +void print_mtr_err_msg(struct rte_mtr_error *error); #endif /* _CMDLINE_MTR_H_ */ diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index ef0b9784d0..336b9b500e 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -38,6 +38,7 @@ #include #include #include +#include #include #ifdef RTE_NET_IXGBE #include @@ -52,6 +53,7 @@ #include #include "testpmd.h" +#include "cmdline_mtr.h" #define ETHDEV_FWVERS_LEN 32 @@ -1464,6 +1466,38 @@ action_alloc(portid_t port_id, uint32_t id, return 0; } +/** Add port meter policy */ +int +port_meter_policy_add(portid_t port_id, uint32_t policy_id, + const struct rte_flow_action *actions) +{ + struct rte_mtr_error error; + const struct rte_flow_action *acts[RTE_COLORS]; + const struct rte_flow_action *act = actions; + const struct rte_flow_action *start; + uint32_t i = 0, act_n; + int ret; + + for (i = 0; i < RTE_COLORS; i++) { + for (act_n = 0, start = act; + act->type != RTE_FLOW_ACTION_TYPE_END; act++) + act_n++; + if (act_n && act->type == RTE_FLOW_ACTION_TYPE_END) + acts[i] = start; + else + acts[i] = NULL; + act++; + } + ret = rte_mtr_meter_policy_create(port_id, + policy_id, + acts, &error); + if (ret) { + print_mtr_err_msg(&error); + return -1; + } + return policy_id; +} + /** Create shared action */ int port_shared_action_create(portid_t port_id, uint32_t id, diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index a87ccb0f0f..bc7cb7e9b9 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -837,6 +837,8 @@ void port_flow_tunnel_list(portid_t port_id); void port_flow_tunnel_destroy(portid_t port_id, uint32_t tunnel_id); 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); 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); -- 2.27.0