From mboxrd@z Thu Jan 1 00:00:00 1970 From: Michal Jastrzebski Subject: [PATCH 6/6] examples/ip_pipeline: modifies flow action pipeline CLI Date: Fri, 6 May 2016 17:57:30 +0200 Message-ID: <1462550250-1256-7-git-send-email-michalx.k.jastrzebski@intel.com> References: <1462550250-1256-1-git-send-email-michalx.k.jastrzebski@intel.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: Marcin Kerlin , Piotr Azarewicz To: dev@dpdk.org Return-path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id EEA762BE6 for ; Fri, 6 May 2016 18:02:11 +0200 (CEST) In-Reply-To: <1462550250-1256-1-git-send-email-michalx.k.jastrzebski@intel.com> List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" All commands merged into one: cmd_action_parsed. modified bulk command: action flow bulk File line format: flow meter 0 meter 1 meter 2 meter 3 policer 0 policer 1 policer 2 policer 3 port at least one meter needs to be provided (can be any meter ID) and at least one policer needs to be provided (can be any policer ID); for any flow, for the metering and policer contexts not specified the default values are applied (file =E2=80=9Cpipeline_flow_actions_be.c=E2=80=9D, fu= nction pipeline_fa_flow_params_set_default()) Signed-off-by: Marcin Kerlin Signed-off-by: Piotr Azarewicz --- .../ip_pipeline/pipeline/pipeline_flow_actions.c | 1826 ++++++++------= ------ 1 file changed, 764 insertions(+), 1062 deletions(-) diff --git a/examples/ip_pipeline/pipeline/pipeline_flow_actions.c b/exam= ples/ip_pipeline/pipeline/pipeline_flow_actions.c index 4012121..f629260 100644 --- a/examples/ip_pipeline/pipeline/pipeline_flow_actions.c +++ b/examples/ip_pipeline/pipeline/pipeline_flow_actions.c @@ -35,6 +35,7 @@ #include #include #include +#include =20 #include #include @@ -50,6 +51,7 @@ #include "pipeline_common_fe.h" #include "pipeline_flow_actions.h" #include "hash_func.h" +#include "parser.h" =20 /* * Flow actions pipeline @@ -58,6 +60,12 @@ #define N_FLOWS_BULK 4096 #endif =20 +#define BUF_SIZE 1024 +#define FA_MAX_NUM_OF_TOKENS 48 +#define FA_MIN_NUM_OF_TOKENS 15 +#define FA_MAX_NUM_OF_RULES 4 +#define FA_MIN_NUM_OF_RULES 1 + struct app_pipeline_fa_flow { struct pipeline_fa_flow_params params; void *entry_ptr; @@ -79,6 +87,12 @@ struct app_pipeline_fa { struct app_pipeline_fa_flow *flows; } __rte_cache_aligned; =20 +struct app_pipeline_add_bulk_params { + struct pipeline_fa_flow_params *keys; + uint32_t n_keys; + uint32_t *flow_ids; +}; + static void* app_pipeline_fa_init(struct pipeline_params *params, __rte_unused void *arg) @@ -601,6 +615,310 @@ string_to_policer_action(char *s, struct pipeline_f= a_policer_action *a) return -1; } =20 +static int +app_pipeline_fa_add_bulk_parse_file(char *filename, + struct app_pipeline_add_bulk_params *params) +{ + FILE *file; + char file_buf[BUF_SIZE]; + char *tokens[FA_MAX_NUM_OF_TOKENS]; + uint32_t i, num_value, ret_tokens, line =3D 0; + uint64_t num_value64; + int status =3D 0; + + file =3D fopen(filename, "r"); + if (file =3D=3D NULL) { + if (getcwd(file_buf, sizeof(file_buf)) !=3D NULL) + printf("not found file %s in the current working dir %s\n", + filename, file_buf); + return -1; + } + + params->n_keys =3D 0; + while (fgets(file_buf, BUF_SIZE, file) !=3D NULL) + if (file_buf[0] !=3D '\0' && file_buf[0] !=3D '\n' && file_buf[0] !=3D= '#') + params->n_keys++; + rewind(file); + + if (params->n_keys =3D=3D 0) { + printf("not found any keys in the file %s\n", filename); + status =3D -1; + goto end; + } + + params->keys =3D rte_malloc(NULL, + params->n_keys * sizeof(struct pipeline_fa_flow_params), + RTE_CACHE_LINE_SIZE); + if (params->keys =3D=3D NULL) { + printf("out of memory\n"); + status =3D -1; + goto end; + } + + params->flow_ids =3D rte_malloc(NULL, + params->n_keys * sizeof(uint32_t), + RTE_CACHE_LINE_SIZE); + if (params->flow_ids =3D=3D NULL) { + printf("out of memory\n"); + status =3D -1; + goto end; + } + + /* set default values for each key */ + for (i =3D 0; i < params->n_keys; i++) { + status =3D pipeline_fa_flow_params_set_default(¶ms->keys[i]); + + if (status !=3D 0) { + printf("there was a problem with the setting default value\n"); + status =3D -1; + goto end; + } + } + + i =3D 0; + while (fgets(file_buf, BUF_SIZE, file) !=3D NULL) { + uint8_t j, pos =3D 0, policer_count =3D 0, meter_count =3D 0, id_mask = =3D 0; + + ret_tokens =3D FA_MAX_NUM_OF_TOKENS; + + status =3D parse_tokenize_string(file_buf, tokens, &ret_tokens); + + if (status !=3D 0) { + if (status =3D=3D -E2BIG) + printf("too many parameters at %d line\n", line + 1); + else + printf("there was a problem with tokenize at %d line\n", + line + 1); + + status =3D -1; + goto end; + + } else if (ret_tokens =3D=3D 0 || tokens[0][0] =3D=3D '#') { + ret_tokens =3D FA_MAX_NUM_OF_TOKENS; + line++; + continue; + + } else if (ret_tokens < FA_MIN_NUM_OF_TOKENS) { + printf("not enough parameters at %d line\n", line + 1); + status =3D -1; + goto end; + } + + status =3D strcmp(tokens[pos++], "flow"); + if (status !=3D 0) { + printf("not found keyword \'flow\' at line %d\n", line + 1); + status =3D -1; + goto end; + } + + status =3D parser_read_uint32(&num_value, tokens[pos]); + if (status !=3D 0) { + printf("conversion error flow id: \'%s\' at line %d\n", + tokens[pos], line + 1); + status =3D -1; + goto end; + } + params->flow_ids[i] =3D num_value; + pos++; + + /* check the number of occurrences of keywords 'policer' and 'meter' *= / + for (j =3D 0; j < ret_tokens; j++) { + if (strcmp(tokens[j], "policer") =3D=3D 0) + policer_count++; + else if (strcmp(tokens[j], "meter") =3D=3D 0) + meter_count++; + } + + /* flow + id + port + id =3D 4 tokens */ + if (ret_tokens !=3D (uint32_t)(4 + (policer_count * 5) + + (meter_count * 6))) { + printf("incorrect amount of parameters at %d line for %d policers " + "and %d meters\n", line + 1, policer_count, meter_count); + status =3D -1; + goto end; + } + + if (policer_count =3D=3D 0) { + printf("the lack of any policers at line %d, required at least 1\n", + line + 1); + status =3D -1; + goto end; + } else if (policer_count > PIPELINE_FA_N_TC_MAX) { + printf("too much instances of policers at line %d\n", line + 1); + status =3D -1; + goto end; + } + + if (meter_count =3D=3D 0) { + printf("the lack of any meters at line %d, required at least 1\n", + line + 1); + status =3D -1; + goto end; + } else if (meter_count > PIPELINE_FA_N_TC_MAX) { + printf("too much instances of meters at line %d\n", line + 1); + status =3D -1; + goto end; + } + + /* set up all meters from the parse file */ + for (j =3D 0; j < meter_count; j++) { + + status =3D strcmp(tokens[pos++], "meter"); + if (status !=3D 0) { + printf("not found keyword \'meter\' at line %d.\n", line + 1); + status =3D -1; + goto end; + } + + status =3D parser_read_uint32(&num_value, tokens[pos]); + if (status !=3D 0) { + printf("conversion error meter id: \'%s\' at line %d\n", + tokens[pos], line + 1); + status =3D -1; + goto end; + } + + if (num_value > PIPELINE_FA_N_TC_MAX - 1) { + printf("meter id %d at line %d is not in the range <0,3>\n", + num_value, line + 1); + status =3D -1; + goto end; + } + + if (id_mask & (1 << num_value)) { + printf("there were 2 the same ID for meters at line %d", + line + 1); + status =3D -1; + goto end; + } + id_mask |=3D 1 << num_value; + pos++; + + struct rte_meter_trtcm_params *m =3D ¶ms->keys[i].m[num_value]; + + status =3D parser_read_uint64(&num_value64, tokens[pos]); + if (status !=3D 0) { + printf("conversion error cir: \'%s\' at line %d\n", + tokens[pos], line + 1); + status =3D -1; + goto end; + } + m->cir =3D num_value64; + pos++; + + status =3D parser_read_uint64(&num_value64, tokens[pos]); + if (status !=3D 0) { + printf("conversion error pir: \'%s\' at line %d\n", + tokens[pos], line + 1); + status =3D -1; + goto end; + } + m->pir =3D num_value64; + pos++; + + status =3D parser_read_uint64(&num_value64, tokens[pos]); + if (status !=3D 0) { + printf("conversion error cbs: \'%s\' at line %d\n", + tokens[pos], line + 1); + status =3D -1; + goto end; + } + m->cbs =3D num_value64; + pos++; + + status =3D parser_read_uint64(&num_value64, tokens[pos]); + if (status !=3D 0) { + printf("conversion error pbs: \'%s\' at line %d\n", + tokens[pos], line + 1); + status =3D -1; + goto end; + } + m->pbs =3D num_value64; + pos++; + } + + id_mask =3D 0; + /* set up all policers from the parse file */ + for (j =3D 0; j < policer_count; j++) { + + status =3D strcmp(tokens[pos++], "policer"); + if (status !=3D 0) { + printf("not found keyword \'policer\' at line %d.\n", line + 1); + status =3D -1; + goto end; + } + + status =3D parser_read_uint32(&num_value, tokens[pos]); + if (status !=3D 0) { + printf("conversion error policer id: \'%s\' at line %d\n", + tokens[pos], line + 1); + status =3D -1; + goto end; + } + + if (num_value > PIPELINE_FA_N_TC_MAX - 1) { + printf("policer id %d at line %d is not in the range <0,3>\n", + num_value, line + 1); + status =3D -1; + goto end; + } + + if (id_mask & (1 << num_value)) { + printf("there were 2 the same ID for policers at line %d", + line + 1); + status =3D -1; + goto end; + } + id_mask |=3D 1 << num_value; + + struct pipeline_fa_policer_params *p =3D + ¶ms->keys[i].p[num_value]; + pos++; + + uint8_t k; + + for (k =3D 0; k < e_RTE_METER_COLORS; k++) { + + struct pipeline_fa_policer_action *a =3D &p->action[k]; + + status =3D string_to_policer_action(tokens[pos], a); + + if (status !=3D 0) { + printf("there was a problem with the set up" + " policer with id %d at line %d with action: %s\n", + num_value, line + 1, tokens[pos]); + status =3D 1; + goto end; + } + pos++; + } + } + + status =3D strcmp(tokens[pos++], "port"); + if (status !=3D 0) { + printf("not found keyword \'port\' at line %d\n", line + 1); + status =3D -1; + goto end; + } + + status =3D parser_read_uint32(&num_value, tokens[pos]); + if (status !=3D 0) { + printf("conversion error port id: \'%s\' at line %d\n", + tokens[pos], line + 1); + status =3D -1; + goto end; + } + params->keys[i].port_id =3D num_value; + + line++; + i++; + } + +end: + fclose(file); + return status; +} + static void print_flow(struct app_pipeline_fa *p, uint32_t flow_id, @@ -690,1114 +1008,498 @@ app_pipeline_fa_dscp_ls(struct app_params *app, } =20 /* - * Flow meter configuration (single flow) - * - * p flow meter trtcm + * action cmd */ =20 -struct cmd_fa_meter_config_result { +struct cmd_action_result { cmdline_fixed_string_t p_string; uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - uint32_t flow_id; - cmdline_fixed_string_t meter_string; - uint32_t meter_id; - cmdline_fixed_string_t trtcm_string; - uint64_t cir; - uint64_t pir; - uint64_t cbs; - uint64_t pbs; + cmdline_fixed_string_t action_string; + cmdline_multi_string_t multi_string; }; =20 static void -cmd_fa_meter_config_parsed( +cmd_action_parsed( void *parsed_result, __rte_unused struct cmdline *cl, void *data) { - struct cmd_fa_meter_config_result *params =3D parsed_result; + struct cmd_action_result *params =3D parsed_result; struct app_params *app =3D data; - struct pipeline_fa_flow_params flow_params; - int status; - - if (params->meter_id >=3D PIPELINE_FA_N_TC_MAX) { - printf("Command failed\n"); - return; - } - - flow_params.m[params->meter_id].cir =3D params->cir; - flow_params.m[params->meter_id].pir =3D params->pir; - flow_params.m[params->meter_id].cbs =3D params->cbs; - flow_params.m[params->meter_id].pbs =3D params->pbs; - - status =3D app_pipeline_fa_flow_config(app, - params->pipeline_id, - params->flow_id, - 1 << params->meter_id, - 0, - 0, - &flow_params); - - if (status !=3D 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fa_meter_config_p_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_meter_config_pipeline_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_meter_config_flow_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_result, - flow_string, "flow"); - -cmdline_parse_token_num_t cmd_fa_meter_config_flow_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, - flow_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_meter_config_meter_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_result, - meter_string, "meter"); - -cmdline_parse_token_num_t cmd_fa_meter_config_meter_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, - meter_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_meter_config_trtcm_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_result, - trtcm_string, "trtcm"); - -cmdline_parse_token_num_t cmd_fa_meter_config_cir =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, cir, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_pir =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, pir, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_cbs =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, cbs, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_pbs =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, pbs, UINT64); - -cmdline_parse_inst_t cmd_fa_meter_config =3D { - .f =3D cmd_fa_meter_config_parsed, - .data =3D NULL, - .help_str =3D "Flow meter configuration (single flow) ", - .tokens =3D { - (void *) &cmd_fa_meter_config_p_string, - (void *) &cmd_fa_meter_config_pipeline_id, - (void *) &cmd_fa_meter_config_flow_string, - (void *) &cmd_fa_meter_config_flow_id, - (void *) &cmd_fa_meter_config_meter_string, - (void *) &cmd_fa_meter_config_meter_id, - (void *) &cmd_fa_meter_config_trtcm_string, - (void *) &cmd_fa_meter_config_cir, - (void *) &cmd_fa_meter_config_pir, - (void *) &cmd_fa_meter_config_cbs, - (void *) &cmd_fa_meter_config_pbs, - NULL, - }, -}; - -/* - * Flow meter configuration (multiple flows) - * - * p flows meter trtcm - */ - -struct cmd_fa_meter_config_bulk_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flows_string; - uint32_t n_flows; - cmdline_fixed_string_t meter_string; - uint32_t meter_id; - cmdline_fixed_string_t trtcm_string; - uint64_t cir; - uint64_t pir; - uint64_t cbs; - uint64_t pbs; -}; - -static void -cmd_fa_meter_config_bulk_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_meter_config_bulk_result *params =3D parsed_result; - struct app_params *app =3D data; - struct pipeline_fa_flow_params flow_template, *flow_params; - uint32_t *flow_id; - uint32_t i; - - if ((params->n_flows =3D=3D 0) || - (params->meter_id >=3D PIPELINE_FA_N_TC_MAX)) { - printf("Invalid arguments\n"); - return; - } - - flow_id =3D (uint32_t *) rte_malloc(NULL, - N_FLOWS_BULK * sizeof(uint32_t), - RTE_CACHE_LINE_SIZE); - if (flow_id =3D=3D NULL) { - printf("Memory allocation failed\n"); - return; - } - - flow_params =3D (struct pipeline_fa_flow_params *) rte_malloc(NULL, - N_FLOWS_BULK * sizeof(struct pipeline_fa_flow_params), - RTE_CACHE_LINE_SIZE); - if (flow_params =3D=3D NULL) { - rte_free(flow_id); - printf("Memory allocation failed\n"); - return; - } - - memset(&flow_template, 0, sizeof(flow_template)); - flow_template.m[params->meter_id].cir =3D params->cir; - flow_template.m[params->meter_id].pir =3D params->pir; - flow_template.m[params->meter_id].cbs =3D params->cbs; - flow_template.m[params->meter_id].pbs =3D params->pbs; - - for (i =3D 0; i < params->n_flows; i++) { - uint32_t pos =3D i % N_FLOWS_BULK; - - flow_id[pos] =3D i; - memcpy(&flow_params[pos], - &flow_template, - sizeof(flow_template)); - - if ((pos =3D=3D N_FLOWS_BULK - 1) || - (i =3D=3D params->n_flows - 1)) { - int status; - - status =3D app_pipeline_fa_flow_config_bulk(app, - params->pipeline_id, - flow_id, - pos + 1, - 1 << params->meter_id, - 0, - 0, - flow_params); - - if (status !=3D 0) { - printf("Command failed\n"); - - break; - } - } - } - - rte_free(flow_params); - rte_free(flow_id); - -} - -cmdline_parse_token_string_t cmd_fa_meter_config_bulk_p_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_pipeline_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_meter_config_bulk_flows_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - flows_string, "flows"); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_n_flows =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - n_flows, UINT32); - -cmdline_parse_token_string_t cmd_fa_meter_config_bulk_meter_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - meter_string, "meter"); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_meter_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - meter_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_meter_config_bulk_trtcm_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - trtcm_string, "trtcm"); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_cir =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - cir, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_pir =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - pir, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_cbs =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - cbs, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_pbs =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - pbs, UINT64); - -cmdline_parse_inst_t cmd_fa_meter_config_bulk =3D { - .f =3D cmd_fa_meter_config_bulk_parsed, - .data =3D NULL, - .help_str =3D "Flow meter configuration (multiple flows)", - .tokens =3D { - (void *) &cmd_fa_meter_config_bulk_p_string, - (void *) &cmd_fa_meter_config_bulk_pipeline_id, - (void *) &cmd_fa_meter_config_bulk_flows_string, - (void *) &cmd_fa_meter_config_bulk_n_flows, - (void *) &cmd_fa_meter_config_bulk_meter_string, - (void *) &cmd_fa_meter_config_bulk_meter_id, - (void *) &cmd_fa_meter_config_bulk_trtcm_string, - (void *) &cmd_fa_meter_config_cir, - (void *) &cmd_fa_meter_config_pir, - (void *) &cmd_fa_meter_config_cbs, - (void *) &cmd_fa_meter_config_pbs, - NULL, - }, -}; - -/* - * Flow policer configuration (single flow) - * - * p flow policer - * G Y R - * - * =3D G (green) | Y (yellow) | R (red) | D (drop) - */ - -struct cmd_fa_policer_config_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - uint32_t flow_id; - cmdline_fixed_string_t policer_string; - uint32_t policer_id; - cmdline_fixed_string_t green_string; - cmdline_fixed_string_t g_action; - cmdline_fixed_string_t yellow_string; - cmdline_fixed_string_t y_action; - cmdline_fixed_string_t red_string; - cmdline_fixed_string_t r_action; -}; - -static void -cmd_fa_policer_config_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_policer_config_result *params =3D parsed_result; - struct app_params *app =3D data; - struct pipeline_fa_flow_params flow_params; - int status; - - if (params->policer_id >=3D PIPELINE_FA_N_TC_MAX) { - printf("Command failed\n"); - return; - } - - status =3D string_to_policer_action(params->g_action, - &flow_params.p[params->policer_id].action[e_RTE_METER_GREEN]); - if (status) - printf("Invalid policer green action\n"); - - status =3D string_to_policer_action(params->y_action, - &flow_params.p[params->policer_id].action[e_RTE_METER_YELLOW]); - if (status) - printf("Invalid policer yellow action\n"); - - status =3D string_to_policer_action(params->r_action, - &flow_params.p[params->policer_id].action[e_RTE_METER_RED]); - if (status) - printf("Invalid policer red action\n"); - - status =3D app_pipeline_fa_flow_config(app, - params->pipeline_id, - params->flow_id, - 0, - 1 << params->policer_id, - 0, - &flow_params); - - if (status !=3D 0) - printf("Command failed\n"); - -} - -cmdline_parse_token_string_t cmd_fa_policer_config_p_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_policer_config_pipeline_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_config_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_config_flow_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - flow_string, "flow"); - -cmdline_parse_token_num_t cmd_fa_policer_config_flow_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_config_result, - flow_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_config_policer_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - policer_string, "policer"); - -cmdline_parse_token_num_t cmd_fa_policer_config_policer_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_config_result, - policer_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_config_green_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - green_string, "G"); - -cmdline_parse_token_string_t cmd_fa_policer_config_g_action =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - g_action, "R#Y#G#D"); - -cmdline_parse_token_string_t cmd_fa_policer_config_yellow_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - yellow_string, "Y"); - -cmdline_parse_token_string_t cmd_fa_policer_config_y_action =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - y_action, "R#Y#G#D"); - -cmdline_parse_token_string_t cmd_fa_policer_config_red_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - red_string, "R"); - -cmdline_parse_token_string_t cmd_fa_policer_config_r_action =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - r_action, "R#Y#G#D"); - -cmdline_parse_inst_t cmd_fa_policer_config =3D { - .f =3D cmd_fa_policer_config_parsed, - .data =3D NULL, - .help_str =3D "Flow policer configuration (single flow)", - .tokens =3D { - (void *) &cmd_fa_policer_config_p_string, - (void *) &cmd_fa_policer_config_pipeline_id, - (void *) &cmd_fa_policer_config_flow_string, - (void *) &cmd_fa_policer_config_flow_id, - (void *) &cmd_fa_policer_config_policer_string, - (void *) &cmd_fa_policer_config_policer_id, - (void *) &cmd_fa_policer_config_green_string, - (void *) &cmd_fa_policer_config_g_action, - (void *) &cmd_fa_policer_config_yellow_string, - (void *) &cmd_fa_policer_config_y_action, - (void *) &cmd_fa_policer_config_red_string, - (void *) &cmd_fa_policer_config_r_action, - NULL, - }, -}; - -/* - * Flow policer configuration (multiple flows) - * - * p flows policer - * G Y R - * - * =3D G (green) | Y (yellow) | R (red) | D (drop) - */ - -struct cmd_fa_policer_config_bulk_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flows_string; - uint32_t n_flows; - cmdline_fixed_string_t policer_string; - uint32_t policer_id; - cmdline_fixed_string_t green_string; - cmdline_fixed_string_t g_action; - cmdline_fixed_string_t yellow_string; - cmdline_fixed_string_t y_action; - cmdline_fixed_string_t red_string; - cmdline_fixed_string_t r_action; -}; - -static void -cmd_fa_policer_config_bulk_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_policer_config_bulk_result *params =3D parsed_result; - struct app_params *app =3D data; - struct pipeline_fa_flow_params flow_template, *flow_params; - uint32_t *flow_id, i; - int status; - - if ((params->n_flows =3D=3D 0) || - (params->policer_id >=3D PIPELINE_FA_N_TC_MAX)) { - printf("Invalid arguments\n"); - return; - } - - flow_id =3D (uint32_t *) rte_malloc(NULL, - N_FLOWS_BULK * sizeof(uint32_t), - RTE_CACHE_LINE_SIZE); - if (flow_id =3D=3D NULL) { - printf("Memory allocation failed\n"); - return; - } - - flow_params =3D (struct pipeline_fa_flow_params *) rte_malloc(NULL, - N_FLOWS_BULK * sizeof(struct pipeline_fa_flow_params), - RTE_CACHE_LINE_SIZE); - if (flow_params =3D=3D NULL) { - rte_free(flow_id); - printf("Memory allocation failed\n"); - return; - } - - memset(&flow_template, 0, sizeof(flow_template)); - - status =3D string_to_policer_action(params->g_action, - &flow_template.p[params->policer_id].action[e_RTE_METER_GREEN]); - if (status) - printf("Invalid policer green action\n"); - - status =3D string_to_policer_action(params->y_action, - &flow_template.p[params->policer_id].action[e_RTE_METER_YELLOW]); - if (status) - printf("Invalid policer yellow action\n"); - - status =3D string_to_policer_action(params->r_action, - &flow_template.p[params->policer_id].action[e_RTE_METER_RED]); - if (status) - printf("Invalid policer red action\n"); - - for (i =3D 0; i < params->n_flows; i++) { - uint32_t pos =3D i % N_FLOWS_BULK; - - flow_id[pos] =3D i; - memcpy(&flow_params[pos], &flow_template, - sizeof(flow_template)); - - if ((pos =3D=3D N_FLOWS_BULK - 1) || - (i =3D=3D params->n_flows - 1)) { - int status; - - status =3D app_pipeline_fa_flow_config_bulk(app, - params->pipeline_id, - flow_id, - pos + 1, - 0, - 1 << params->policer_id, - 0, - flow_params); =20 - if (status !=3D 0) { - printf("Command failed\n"); - - break; - } - } - } - - rte_free(flow_params); - rte_free(flow_id); - -} - -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_p_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_policer_config_bulk_pipeline_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_flows_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - flows_string, "flows"); - -cmdline_parse_token_num_t cmd_fa_policer_config_bulk_n_flows =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - n_flows, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_policer_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - policer_string, "policer"); - -cmdline_parse_token_num_t cmd_fa_policer_config_bulk_policer_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - policer_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_green_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - green_string, "G"); - -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_g_action =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - g_action, "R#Y#G#D"); - -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_yellow_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - yellow_string, "Y"); - -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_y_action =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - y_action, "R#Y#G#D"); - -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_red_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - red_string, "R"); - -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_r_action =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - r_action, "R#Y#G#D"); - -cmdline_parse_inst_t cmd_fa_policer_config_bulk =3D { - .f =3D cmd_fa_policer_config_bulk_parsed, - .data =3D NULL, - .help_str =3D "Flow policer configuration (multiple flows)", - .tokens =3D { - (void *) &cmd_fa_policer_config_bulk_p_string, - (void *) &cmd_fa_policer_config_bulk_pipeline_id, - (void *) &cmd_fa_policer_config_bulk_flows_string, - (void *) &cmd_fa_policer_config_bulk_n_flows, - (void *) &cmd_fa_policer_config_bulk_policer_string, - (void *) &cmd_fa_policer_config_bulk_policer_id, - (void *) &cmd_fa_policer_config_bulk_green_string, - (void *) &cmd_fa_policer_config_bulk_g_action, - (void *) &cmd_fa_policer_config_bulk_yellow_string, - (void *) &cmd_fa_policer_config_bulk_y_action, - (void *) &cmd_fa_policer_config_bulk_red_string, - (void *) &cmd_fa_policer_config_bulk_r_action, - NULL, - }, -}; - -/* - * Flow output port configuration (single flow) - * - * p flow port - */ - -struct cmd_fa_output_port_config_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - uint32_t flow_id; - cmdline_fixed_string_t port_string; - uint32_t port_id; -}; - -static void -cmd_fa_output_port_config_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_output_port_config_result *params =3D parsed_result; - struct app_params *app =3D data; - struct pipeline_fa_flow_params flow_params; - int status; - - flow_params.port_id =3D params->port_id; - - status =3D app_pipeline_fa_flow_config(app, - params->pipeline_id, - params->flow_id, - 0, - 0, - 1, - &flow_params); - - if (status !=3D 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fa_output_port_config_p_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_output_port_config_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_output_port_config_pipeline_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_output_port_config_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_output_port_config_flow_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_output_port_config_result, - flow_string, "flow"); - -cmdline_parse_token_num_t cmd_fa_output_port_config_flow_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_output_port_config_result, - flow_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_output_port_config_port_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_output_port_config_result, - port_string, "port"); - -cmdline_parse_token_num_t cmd_fa_output_port_config_port_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_output_port_config_result, - port_id, UINT32); - -cmdline_parse_inst_t cmd_fa_output_port_config =3D { - .f =3D cmd_fa_output_port_config_parsed, - .data =3D NULL, - .help_str =3D "Flow output port configuration (single flow)", - .tokens =3D { - (void *) &cmd_fa_output_port_config_p_string, - (void *) &cmd_fa_output_port_config_pipeline_id, - (void *) &cmd_fa_output_port_config_flow_string, - (void *) &cmd_fa_output_port_config_flow_id, - (void *) &cmd_fa_output_port_config_port_string, - (void *) &cmd_fa_output_port_config_port_id, - NULL, - }, -}; - -/* - * Flow output port configuration (multiple flows) - * - * p flows ports - */ - -struct cmd_fa_output_port_config_bulk_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flows_string; - uint32_t n_flows; - cmdline_fixed_string_t ports_string; - uint32_t n_ports; -}; - -static void -cmd_fa_output_port_config_bulk_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_output_port_config_bulk_result *params =3D parsed_result; - struct app_params *app =3D data; - struct pipeline_fa_flow_params *flow_params; - uint32_t *flow_id; - uint32_t i; - - if (params->n_flows =3D=3D 0) { - printf("Invalid arguments\n"); - return; - } - - flow_id =3D (uint32_t *) rte_malloc(NULL, - N_FLOWS_BULK * sizeof(uint32_t), - RTE_CACHE_LINE_SIZE); - if (flow_id =3D=3D NULL) { - printf("Memory allocation failed\n"); - return; - } - - flow_params =3D (struct pipeline_fa_flow_params *) rte_malloc(NULL, - N_FLOWS_BULK * sizeof(struct pipeline_fa_flow_params), - RTE_CACHE_LINE_SIZE); - if (flow_params =3D=3D NULL) { - rte_free(flow_id); - printf("Memory allocation failed\n"); - return; - } - - for (i =3D 0; i < params->n_flows; i++) { - uint32_t pos =3D i % N_FLOWS_BULK; - uint32_t port_id =3D i % params->n_ports; - - flow_id[pos] =3D i; - - memset(&flow_params[pos], 0, sizeof(flow_params[pos])); - flow_params[pos].port_id =3D port_id; - - if ((pos =3D=3D N_FLOWS_BULK - 1) || - (i =3D=3D params->n_flows - 1)) { - int status; - - status =3D app_pipeline_fa_flow_config_bulk(app, - params->pipeline_id, - flow_id, - pos + 1, - 0, - 0, - 1, - flow_params); - - if (status !=3D 0) { - printf("Command failed\n"); - - break; - } - } - } - - rte_free(flow_params); - rte_free(flow_id); - -} - -cmdline_parse_token_string_t cmd_fa_output_port_config_bulk_p_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_output_port_config_bulk_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_output_port_config_bulk_pipeline_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_output_port_config_bulk_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_output_port_config_bulk_flows_string= =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_output_port_config_bulk_result, - flows_string, "flows"); - -cmdline_parse_token_num_t cmd_fa_output_port_config_bulk_n_flows =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_output_port_config_bulk_result, - n_flows, UINT32); - -cmdline_parse_token_string_t cmd_fa_output_port_config_bulk_ports_string= =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_output_port_config_bulk_result, - ports_string, "ports"); - -cmdline_parse_token_num_t cmd_fa_output_port_config_bulk_n_ports =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_output_port_config_bulk_result, - n_ports, UINT32); - -cmdline_parse_inst_t cmd_fa_output_port_config_bulk =3D { - .f =3D cmd_fa_output_port_config_bulk_parsed, - .data =3D NULL, - .help_str =3D "Flow output port configuration (multiple flows)", - .tokens =3D { - (void *) &cmd_fa_output_port_config_bulk_p_string, - (void *) &cmd_fa_output_port_config_bulk_pipeline_id, - (void *) &cmd_fa_output_port_config_bulk_flows_string, - (void *) &cmd_fa_output_port_config_bulk_n_flows, - (void *) &cmd_fa_output_port_config_bulk_ports_string, - (void *) &cmd_fa_output_port_config_bulk_n_ports, - NULL, - }, -}; - -/* - * Flow DiffServ Code Point (DSCP) translation table configuration - * - * p dscp class color - * - * =3D G (green) | Y (yellow) | R (red) -*/ - -struct cmd_fa_dscp_config_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t dscp_string; - uint32_t dscp_id; - cmdline_fixed_string_t class_string; - uint32_t traffic_class_id; - cmdline_fixed_string_t color_string; - cmdline_fixed_string_t color; - -}; - -static void -cmd_fa_dscp_config_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_dscp_config_result *params =3D parsed_result; - struct app_params *app =3D data; - enum rte_meter_color color; - int status; - - status =3D string_to_color(params->color, &color); - if (status) { - printf("Invalid color\n"); - return; - } - - status =3D app_pipeline_fa_dscp_config(app, - params->pipeline_id, - params->dscp_id, - params->traffic_class_id, - color); - - if (status !=3D 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fa_dscp_config_p_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_config_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_dscp_config_pipeline_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_dscp_config_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_dscp_config_dscp_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_config_result, - dscp_string, "dscp"); - -cmdline_parse_token_num_t cmd_fa_dscp_config_dscp_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_dscp_config_result, - dscp_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_dscp_config_class_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_config_result, - class_string, "class"); - -cmdline_parse_token_num_t cmd_fa_dscp_config_traffic_class_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_dscp_config_result, - traffic_class_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_dscp_config_color_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_config_result, - color_string, "color"); - -cmdline_parse_token_string_t cmd_fa_dscp_config_color =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_config_result, - color, "G#Y#R"); - -cmdline_parse_inst_t cmd_fa_dscp_config =3D { - .f =3D cmd_fa_dscp_config_parsed, - .data =3D NULL, - .help_str =3D "Flow DSCP translation table configuration", - .tokens =3D { - (void *) &cmd_fa_dscp_config_p_string, - (void *) &cmd_fa_dscp_config_pipeline_id, - (void *) &cmd_fa_dscp_config_dscp_string, - (void *) &cmd_fa_dscp_config_dscp_id, - (void *) &cmd_fa_dscp_config_class_string, - (void *) &cmd_fa_dscp_config_traffic_class_id, - (void *) &cmd_fa_dscp_config_color_string, - (void *) &cmd_fa_dscp_config_color, - NULL, - }, -}; - -/* - * Flow policer stats read - * - * p flow policer stats - */ - -struct cmd_fa_policer_stats_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - uint32_t flow_id; - cmdline_fixed_string_t policer_string; - uint32_t policer_id; - cmdline_fixed_string_t stats_string; -}; - -static void -cmd_fa_policer_stats_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_policer_stats_result *params =3D parsed_result; - struct app_params *app =3D data; - struct pipeline_fa_policer_stats stats; + char *tokens[16]; + uint32_t n_tokens =3D RTE_DIM(tokens); int status; =20 - status =3D app_pipeline_fa_flow_policer_stats_read(app, - params->pipeline_id, - params->flow_id, - params->policer_id, - 1, - &stats); + status =3D parse_tokenize_string(params->multi_string, tokens, &n_token= s); if (status !=3D 0) { - printf("Command failed\n"); + printf("Command \"action\": Too many parameters.\n"); return; } =20 - /* Display stats */ - printf("\tPkts G: %" PRIu64 - "\tPkts Y: %" PRIu64 - "\tPkts R: %" PRIu64 - "\tPkts D: %" PRIu64 "\n", - stats.n_pkts[e_RTE_METER_GREEN], - stats.n_pkts[e_RTE_METER_YELLOW], - stats.n_pkts[e_RTE_METER_RED], - stats.n_pkts_drop); -} + /* "action flow" or "action flow bulk" or "action flow ls" */ + if ((n_tokens > 0) && (0 =3D=3D strcmp(tokens[0], "flow"))) { + struct pipeline_fa_flow_params flow_params; + uint32_t flow_id; =20 -cmdline_parse_token_string_t cmd_fa_policer_stats_p_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_stats_result, - p_string, "p"); + if (n_tokens < 2) { + printf("Not enough parameters for \"action flow\" or" + " \"action flow bulk\" or \"action flow ls\".\n"); + return; + } =20 -cmdline_parse_token_num_t cmd_fa_policer_stats_pipeline_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_stats_result, - pipeline_id, UINT32); + /* action flow */ + if (0 =3D=3D parser_read_uint32(&flow_id, tokens[1])) { + if (n_tokens < 3) { + printf("Not enough parameters for \"action flow\".\n"); + return; + } =20 -cmdline_parse_token_string_t cmd_fa_policer_stats_flow_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_stats_result, - flow_string, "flow"); + /* + * Flow meter configuration (single flow) + * + * p action flow meter + * trtcm + */ + if (0 =3D=3D strcmp(tokens[2], "meter")) { + uint32_t meter_id; =20 -cmdline_parse_token_num_t cmd_fa_policer_stats_flow_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_stats_result, - flow_id, UINT32); + if (n_tokens !=3D 9) { + printf("Incorrect number of parameters for action flow" + " meter configuration.\n"); + return; + } =20 -cmdline_parse_token_string_t cmd_fa_policer_stats_policer_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_stats_result, - policer_string, "policer"); + if (parser_read_uint32(&meter_id, tokens[3])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is meter id.\n", + tokens[3]); + return; + } + if (meter_id >=3D PIPELINE_FA_N_TC_MAX) { + printf("Incorrect parameter: \"%s\"." + " Expected meter id is less than %d.\n", + tokens[3], PIPELINE_FA_N_TC_MAX); + return; + } + if (strcmp(tokens[4], "trtcm")) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is word \"trtcm\".\n", + tokens[4]); + return; + } + if (parser_read_uint64(&flow_params.m[meter_id].cir, + tokens[5])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is cir.\n", + tokens[5]); + return; + } + if (parser_read_uint64(&flow_params.m[meter_id].pir, + tokens[6])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is pir.\n", + tokens[6]); + return; + } + if (parser_read_uint64(&flow_params.m[meter_id].cbs, + tokens[7])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is cbs.\n", + tokens[7]); + return; + } + if (parser_read_uint64(&flow_params.m[meter_id].pbs, + tokens[8])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is pbs.\n", + tokens[8]); + return; + } =20 -cmdline_parse_token_num_t cmd_fa_policer_stats_policer_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_stats_result, - policer_id, UINT32); + status =3D app_pipeline_fa_flow_config(app, + params->pipeline_id, + flow_id, + 1 << meter_id, + 0, + 0, + &flow_params); + if (status !=3D 0) + printf("Command \"action flow meter\" failed.\n"); =20 -cmdline_parse_token_string_t cmd_fa_policer_stats_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_stats_result, - stats_string, "stats"); + return; + } + /* + * Flow policer configuration (single flow) + * + * p action flow policer + * g y r + * + * =3D G (green) | Y (yellow) | R (red) | D (drop) + */ + else if (0 =3D=3D strcmp(tokens[2], "policer")) { + uint32_t policer_id; =20 -cmdline_parse_inst_t cmd_fa_policer_stats =3D { - .f =3D cmd_fa_policer_stats_parsed, - .data =3D NULL, - .help_str =3D "Flow policer stats read", - .tokens =3D { - (void *) &cmd_fa_policer_stats_p_string, - (void *) &cmd_fa_policer_stats_pipeline_id, - (void *) &cmd_fa_policer_stats_flow_string, - (void *) &cmd_fa_policer_stats_flow_id, - (void *) &cmd_fa_policer_stats_policer_string, - (void *) &cmd_fa_policer_stats_policer_id, - (void *) &cmd_fa_policer_stats_string, - NULL, - }, -}; - -/* - * Flow list - * - * p flow ls - */ - -struct cmd_fa_flow_ls_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t actions_string; - cmdline_fixed_string_t ls_string; -}; - -static void -cmd_fa_flow_ls_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_flow_ls_result *params =3D parsed_result; - struct app_params *app =3D data; - int status; - - status =3D app_pipeline_fa_flow_ls(app, params->pipeline_id); - if (status !=3D 0) - printf("Command failed\n"); -} + if (n_tokens !=3D 10) { + printf("Incorrect number of parameters for action flow" + " policer configuration.\n"); + return; + } =20 -cmdline_parse_token_string_t cmd_fa_flow_ls_p_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_flow_ls_result, - p_string, "p"); + if (parser_read_uint32(&policer_id, tokens[3])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is policer id.\n", + tokens[3]); + return; + } + if (policer_id >=3D PIPELINE_FA_N_TC_MAX) { + printf("Incorrect parameter: \"%s\"." + " Expected policer id is less than %d.\n", + tokens[3], PIPELINE_FA_N_TC_MAX); + return; + } + if (strcmp(tokens[4], "g")) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is word \"g\".\n", + tokens[4]); + return; + } + if (string_to_policer_action(tokens[5], + &flow_params.p[policer_id].action[e_RTE_METER_GREEN])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is policer green action.\n", + tokens[5]); + return; + } + if (strcmp(tokens[6], "y")) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is word \"y\".\n", + tokens[6]); + return; + } + if (string_to_policer_action(tokens[7], + &flow_params.p[policer_id].action[e_RTE_METER_YELLOW])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is policer yellow action.\n", + tokens[7]); + return; + } + if (strcmp(tokens[8], "r")) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is word \"r\".\n", + tokens[8]); + return; + } + if (string_to_policer_action(tokens[9], + &flow_params.p[policer_id].action[e_RTE_METER_RED])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is policer red action.\n", + tokens[9]); + return; + } =20 -cmdline_parse_token_num_t cmd_fa_flow_ls_pipeline_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_flow_ls_result, - pipeline_id, UINT32); + status =3D app_pipeline_fa_flow_config(app, + params->pipeline_id, + flow_id, + 0, + 1 << policer_id, + 0, + &flow_params); + if (status !=3D 0) + printf("Command \"action flow policer\" failed.\n"); =20 -cmdline_parse_token_string_t cmd_fa_flow_ls_flow_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_flow_ls_result, - flow_string, "flow"); + return; + } + /* + * Flow output port configuration (single flow) + * + * p action flow port + */ + else if (0 =3D=3D strcmp(tokens[2], "port")) { + if (n_tokens !=3D 4) { + printf("Incorrect number of parameters for action flow" + " output port configuration.\n"); + return; + } =20 -cmdline_parse_token_string_t cmd_fa_flow_ls_actions_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_flow_ls_result, - actions_string, "actions"); + if (parser_read_uint32(&flow_params.port_id, tokens[3])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is port id.\n", + tokens[3]); + return; + } =20 -cmdline_parse_token_string_t cmd_fa_flow_ls_ls_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_flow_ls_result, - ls_string, "ls"); + status =3D app_pipeline_fa_flow_config(app, + params->pipeline_id, + flow_id, + 0, + 0, + 1, + &flow_params); + if (status !=3D 0) + printf("Command \"action flow port\" failed.\n"); =20 -cmdline_parse_inst_t cmd_fa_flow_ls =3D { - .f =3D cmd_fa_flow_ls_parsed, - .data =3D NULL, - .help_str =3D "Flow actions list", - .tokens =3D { - (void *) &cmd_fa_flow_ls_p_string, - (void *) &cmd_fa_flow_ls_pipeline_id, - (void *) &cmd_fa_flow_ls_flow_string, - (void *) &cmd_fa_flow_ls_actions_string, - (void *) &cmd_fa_flow_ls_ls_string, - NULL, - }, -}; - -/* - * Flow DiffServ Code Point (DSCP) translation table list - * - * p dscp ls - */ - -struct cmd_fa_dscp_ls_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t dscp_string; - cmdline_fixed_string_t ls_string; -}; - -static void -cmd_fa_dscp_ls_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_dscp_ls_result *params =3D parsed_result; - struct app_params *app =3D data; - int status; - - status =3D app_pipeline_fa_dscp_ls(app, params->pipeline_id); - if (status !=3D 0) - printf("Command failed\n"); + return; + } + /* + * Flow policer stats read + * + * p action flow stats + */ + else if (0 =3D=3D strcmp(tokens[2], "stats")) { + struct pipeline_fa_policer_stats stats; + uint32_t policer_id; + + if (n_tokens !=3D 3) { + printf("Incorrect number of parameters for action flow" + " policer stats read.\n"); + return; + } + + for (policer_id =3D 0; + policer_id < PIPELINE_FA_N_TC_MAX; + policer_id++) { + status =3D app_pipeline_fa_flow_policer_stats_read(app, + params->pipeline_id, + flow_id, + policer_id, + 1, + &stats); + if (status !=3D 0) { + printf("Command \"action flow stats\" for policer %" + PRIu32 " failed.\n", policer_id); + return; + } + + /* Display stats */ + printf("\tPolicer: %" PRIu32 + "\tPkts G: %" PRIu64 + "\tPkts Y: %" PRIu64 + "\tPkts R: %" PRIu64 + "\tPkts D: %" PRIu64 "\n", + policer_id, + stats.n_pkts[e_RTE_METER_GREEN], + stats.n_pkts[e_RTE_METER_YELLOW], + stats.n_pkts[e_RTE_METER_RED], + stats.n_pkts_drop); + } + + return; + } + else { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is word \"meter\" or \"policer\" or" + " \"port\" or \"stats\".\n", + tokens[2]); + return; + } + } + /* + * Flow meter, policer and output port configuration (multiple flows) + * + * p action flow bulk + */ + else if (0 =3D=3D strcmp(tokens[1], "bulk")) { + struct app_pipeline_add_bulk_params bulk_params; + + if (n_tokens !=3D 3) { + printf( + "Incorrect number of parameters for action flow bulk.\n"); + return; + } + + bulk_params.keys =3D NULL; + bulk_params.flow_ids =3D NULL; + + status =3D app_pipeline_fa_add_bulk_parse_file(tokens[2], + &bulk_params); + if (status !=3D 0) { + printf("Command \"action flow bulk\" failed.\n"); + rte_free(bulk_params.keys); + rte_free(bulk_params.flow_ids); + return; + } + + status =3D app_pipeline_fa_flow_config_bulk(app, + params->pipeline_id, + bulk_params.flow_ids, + bulk_params.n_keys, + 0x0F, + 0x0F, + 1, + bulk_params.keys); + if (status !=3D 0) + printf("Command \"action flow bulk\" failed.\n"); + + rte_free(bulk_params.keys); + rte_free(bulk_params.flow_ids); + return; + } + /* + * Flow list + * + * p action flow ls + */ + else if (0 =3D=3D strcmp(tokens[1], "ls")) { + if (n_tokens !=3D 2) { + printf("Incorrect number of parameters for action flow ls.\n"); + return; + } + + status =3D app_pipeline_fa_flow_ls(app, params->pipeline_id); + if (status !=3D 0) + printf("Command \"action flow ls\" failed.\n"); + + return; + } + else { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is flow id or word \"bulk\" or" + " word \"ls\".\n", + tokens[1]); + return; + } + } + + /* "action dscp" or "action dscp ls" */ + if ((n_tokens > 0) && (0 =3D=3D strcmp(tokens[0], "dscp"))) { + uint32_t dscp_id; + + if (n_tokens < 2) { + printf("Not enough parameters for \"action dscp\" or" + " \"action dscp ls\".\n"); + return; + } + + /* + * Flow DiffServ Code Point (DSCP) translation table configuration + * + * p action dscp class + * color + * + * =3D G (green) | Y (yellow) | R (red) + */ + if (0 =3D=3D parser_read_uint32(&dscp_id, tokens[1])) { + enum rte_meter_color color; + uint32_t traffic_class_id; + + if (n_tokens !=3D 6) { + printf("Incorrect number of parameters for action dscp.\n"); + return; + } + + if (strcmp(tokens[2], "class")) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is word \"class\".\n", + tokens[2]); + return; + } + if (parser_read_uint32(&traffic_class_id, tokens[3])) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is traffic class id.\n", + tokens[3]); + return; + } + if (strcmp(tokens[4], "color")) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is word \"color\".\n", + tokens[4]); + return; + } + if (string_to_color(tokens[5], &color)) { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is color.\n", + tokens[5]); + return; + } + + status =3D app_pipeline_fa_dscp_config(app, + params->pipeline_id, + dscp_id, + traffic_class_id, + color); + if (status !=3D 0) + printf("Command \"action dscp\" failed.\n"); + + return; + } + /* + * Flow DiffServ Code Point (DSCP) translation table list + * + * p action dscp ls + */ + else if (0 =3D=3D strcmp(tokens[1], "ls")) { + if (n_tokens !=3D 2) { + printf("Incorrect number of parameters for action dscp ls.\n"); + return; + } + + status =3D app_pipeline_fa_dscp_ls(app, params->pipeline_id); + if (status !=3D 0) + printf("Command \"action dscp ls\" failed.\n"); + + return; + } + else { + printf("Incorrect parameter: \"%s\"." + " Expected parameter is dscp id or word \"ls\".\n", + tokens[1]); + return; + } + } + + printf("!Command \"action\" failed." + " Expected parameter is \"flow\" or \"dscp\".\n"); + return; } =20 -cmdline_parse_token_string_t cmd_fa_dscp_ls_p_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_ls_result, - p_string, "p"); +static cmdline_parse_token_string_t cmd_action_p_string =3D + TOKEN_STRING_INITIALIZER(struct cmd_action_result, p_string, "p"); =20 -cmdline_parse_token_num_t cmd_fa_dscp_ls_pipeline_id =3D - TOKEN_NUM_INITIALIZER(struct cmd_fa_dscp_ls_result, - pipeline_id, UINT32); +static cmdline_parse_token_num_t cmd_action_pipeline_id =3D + TOKEN_NUM_INITIALIZER(struct cmd_action_result, pipeline_id, UINT32); =20 -cmdline_parse_token_string_t cmd_fa_dscp_ls_dscp_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_ls_result, - dscp_string, "dscp"); +static cmdline_parse_token_string_t cmd_action_action_string =3D + TOKEN_STRING_INITIALIZER(struct cmd_action_result, action_string, "acti= on"); =20 -cmdline_parse_token_string_t cmd_fa_dscp_ls_string =3D - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_ls_result, ls_string, - "ls"); +static cmdline_parse_token_string_t cmd_action_multi_string =3D + TOKEN_STRING_INITIALIZER(struct cmd_action_result, multi_string, + TOKEN_STRING_MULTI); =20 -cmdline_parse_inst_t cmd_fa_dscp_ls =3D { - .f =3D cmd_fa_dscp_ls_parsed, +cmdline_parse_inst_t cmd_action =3D { + .f =3D cmd_action_parsed, .data =3D NULL, - .help_str =3D "Flow DSCP translaton table list", + .help_str =3D + "\n Flow meter configuration (single flow):" + "\n p action flow meter trtcm = " + " " + "\n Flow policer configuration (single flow):" + "\n p action flow policer g" + " y r " + "\n Flow output port configuration (single flow):" + "\n p action flow port " + "\n Flow meter, policer and output port configuration (multiple flows)= :" + "\n p action flow bulk " + "\n Flow policer stats read:" + "\n p action flow stats" + "\n Flow actions list:" + "\n p action flow ls" + "\n Flow DSCP translation table configuration:" + "\n p action dscp class color" + " " + "\n Flow DSCP translaton table list:" + "\n p action dscp ls", .tokens =3D { - (void *) &cmd_fa_dscp_ls_p_string, - (void *) &cmd_fa_dscp_ls_pipeline_id, - (void *) &cmd_fa_dscp_ls_dscp_string, - (void *) &cmd_fa_dscp_ls_string, + (void *) &cmd_action_p_string, + (void *) &cmd_action_pipeline_id, + (void *) &cmd_action_action_string, + (void *) &cmd_action_multi_string, NULL, }, }; =20 static cmdline_parse_ctx_t pipeline_cmds[] =3D { - (cmdline_parse_inst_t *) &cmd_fa_meter_config, - (cmdline_parse_inst_t *) &cmd_fa_meter_config_bulk, - (cmdline_parse_inst_t *) &cmd_fa_policer_config, - (cmdline_parse_inst_t *) &cmd_fa_policer_config_bulk, - (cmdline_parse_inst_t *) &cmd_fa_output_port_config, - (cmdline_parse_inst_t *) &cmd_fa_output_port_config_bulk, - (cmdline_parse_inst_t *) &cmd_fa_dscp_config, - (cmdline_parse_inst_t *) &cmd_fa_policer_stats, - (cmdline_parse_inst_t *) &cmd_fa_flow_ls, - (cmdline_parse_inst_t *) &cmd_fa_dscp_ls, + (cmdline_parse_inst_t *) &cmd_action, NULL, }; =20 --=20 1.9.1