static int parse_policer_action_string(char *p_str, uint32_t action_mask, enum rte_mtr_policer_action actions[]) { char *token; int count = __builtin_popcount(action_mask); int g_color = 0, y_color = 0, action, i; for (i = 0; i < count; i++) { token = strtok_r(p_str, PARSE_DELIMITER, &p_str); if (token == NULL) return -1; action = string_to_policer_action(token); if (action == -1) return -1; if (g_color == 0 && (action_mask & 0x1)) { actions[RTE_MTR_GREEN] = action; g_color = 1; } else if (y_color == 0 && (action_mask & 0x2)) { actions[RTE_MTR_YELLOW] = action; y_color = 1; } else actions[RTE_MTR_RED] = action; } return 0; }
static void cmd_fa_policer_config_parsed( void *parsed_result, __rte_unused struct cmdline *cl, void *data) { struct cmd_fa_policer_config_result *params = parsed_result; struct app_params *app = data; struct pipeline_fa_flow_params flow_params; int status; if (params->policer_id >= PIPELINE_FA_N_TC_MAX) { printf("Command failed\n"); return; } status = 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 = 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 = 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 = app_pipeline_fa_flow_config(app, params->pipeline_id, params->flow_id, 0, 1 << params->policer_id, 0, &flow_params); if (status != 0) printf("Command failed\n"); }
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 = parsed_result; struct app_params *app = data; struct pipeline_fa_flow_params flow_template, *flow_params; uint32_t *flow_id, i; int status; if ((params->n_flows == 0) || (params->policer_id >= PIPELINE_FA_N_TC_MAX)) { printf("Invalid arguments\n"); return; } flow_id = (uint32_t *) rte_malloc(NULL, N_FLOWS_BULK * sizeof(uint32_t), RTE_CACHE_LINE_SIZE); if (flow_id == NULL) { printf("Memory allocation failed\n"); return; } flow_params = (struct pipeline_fa_flow_params *) rte_malloc(NULL, N_FLOWS_BULK * sizeof(struct pipeline_fa_flow_params), RTE_CACHE_LINE_SIZE); if (flow_params == NULL) { rte_free(flow_id); printf("Memory allocation failed\n"); return; } memset(&flow_template, 0, sizeof(flow_template)); status = 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 = 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 = 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 = 0; i < params->n_flows; i++) { uint32_t pos = i % N_FLOWS_BULK; flow_id[pos] = i; memcpy(&flow_params[pos], &flow_template, sizeof(flow_template)); if ((pos == N_FLOWS_BULK - 1) || (i == params->n_flows - 1)) { int status; status = app_pipeline_fa_flow_config_bulk(app, params->pipeline_id, flow_id, pos + 1, 0, 1 << params->policer_id, 0, flow_params); if (status != 0) { printf("Command failed\n"); break; } } } rte_free(flow_params); rte_free(flow_id); }