From 8b25d1ad5d2264bdfc2818c7bda74ee2697df6db Mon Sep 17 00:00:00 2001 From: Christian Ehrhardt Date: Wed, 6 Jul 2016 09:22:35 +0200 Subject: Imported Upstream version 16.07-rc1 Change-Id: I40a523e52f12e8496fdd69e902824b0226c303de Signed-off-by: Christian Ehrhardt --- examples/ip_pipeline/pipeline/pipeline_common_fe.c | 640 +++--- examples/ip_pipeline/pipeline/pipeline_common_fe.h | 26 + examples/ip_pipeline/pipeline/pipeline_firewall.c | 1463 +++++--------- examples/ip_pipeline/pipeline/pipeline_firewall.h | 12 + .../ip_pipeline/pipeline/pipeline_firewall_be.c | 28 +- .../ip_pipeline/pipeline/pipeline_flow_actions.c | 1507 +++++--------- .../ip_pipeline/pipeline/pipeline_flow_actions.h | 11 + .../pipeline/pipeline_flow_actions_be.c | 22 - .../pipeline/pipeline_flow_classification.c | 2084 +++++++++----------- .../pipeline/pipeline_flow_classification.h | 28 + .../pipeline/pipeline_flow_classification_be.c | 22 - examples/ip_pipeline/pipeline/pipeline_master.c | 2 + examples/ip_pipeline/pipeline/pipeline_master_be.c | 22 +- .../ip_pipeline/pipeline/pipeline_passthrough.c | 27 + .../ip_pipeline/pipeline/pipeline_passthrough_be.c | 39 +- examples/ip_pipeline/pipeline/pipeline_routing.c | 1867 ++++++------------ examples/ip_pipeline/pipeline/pipeline_routing.h | 7 + .../ip_pipeline/pipeline/pipeline_routing_be.c | 102 +- .../ip_pipeline/pipeline/pipeline_routing_be.h | 16 + 19 files changed, 3177 insertions(+), 4748 deletions(-) (limited to 'examples/ip_pipeline/pipeline') diff --git a/examples/ip_pipeline/pipeline/pipeline_common_fe.c b/examples/ip_pipeline/pipeline/pipeline_common_fe.c index a691d422..cd1d082a 100644 --- a/examples/ip_pipeline/pipeline/pipeline_common_fe.c +++ b/examples/ip_pipeline/pipeline/pipeline_common_fe.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -42,12 +42,146 @@ #include #include #include -#include -#include -#include #include #include "pipeline_common_fe.h" +#include "parser.h" + +struct app_link_params * +app_pipeline_track_pktq_out_to_link(struct app_params *app, + uint32_t pipeline_id, + uint32_t pktq_out_id) +{ + struct app_pipeline_params *p; + + /* Check input arguments */ + if (app == NULL) + return NULL; + + APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p); + if (p == NULL) + return NULL; + + for ( ; ; ) { + struct app_pktq_out_params *pktq_out = + &p->pktq_out[pktq_out_id]; + + switch (pktq_out->type) { + case APP_PKTQ_OUT_HWQ: + { + struct app_pktq_hwq_out_params *hwq_out; + + hwq_out = &app->hwq_out_params[pktq_out->id]; + + return app_get_link_for_txq(app, hwq_out); + } + + case APP_PKTQ_OUT_SWQ: + { + struct pipeline_params pp; + struct pipeline_type *ptype; + struct app_pktq_swq_params *swq; + uint32_t pktq_in_id; + int status; + + swq = &app->swq_params[pktq_out->id]; + p = app_swq_get_reader(app, swq, &pktq_in_id); + if (p == NULL) + return NULL; + + ptype = app_pipeline_type_find(app, p->type); + if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL)) + return NULL; + + app_pipeline_params_get(app, p, &pp); + status = ptype->fe_ops->f_track(&pp, + pktq_in_id, + &pktq_out_id); + if (status) + return NULL; + + break; + } + + case APP_PKTQ_OUT_TM: + { + struct pipeline_params pp; + struct pipeline_type *ptype; + struct app_pktq_tm_params *tm; + uint32_t pktq_in_id; + int status; + + tm = &app->tm_params[pktq_out->id]; + p = app_tm_get_reader(app, tm, &pktq_in_id); + if (p == NULL) + return NULL; + + ptype = app_pipeline_type_find(app, p->type); + if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL)) + return NULL; + + app_pipeline_params_get(app, p, &pp); + status = ptype->fe_ops->f_track(&pp, + pktq_in_id, + &pktq_out_id); + if (status) + return NULL; + + break; + } + + case APP_PKTQ_OUT_KNI: + { + struct pipeline_params pp; + struct pipeline_type *ptype; + struct app_pktq_kni_params *kni; + uint32_t pktq_in_id; + int status; + + kni = &app->kni_params[pktq_out->id]; + p = app_kni_get_reader(app, kni, &pktq_in_id); + if (p == NULL) + return NULL; + + ptype = app_pipeline_type_find(app, p->type); + if ((ptype == NULL) || (ptype->fe_ops->f_track == NULL)) + return NULL; + + app_pipeline_params_get(app, p, &pp); + status = ptype->fe_ops->f_track(&pp, + pktq_in_id, + &pktq_out_id); + if (status) + return NULL; + + break; + } + + case APP_PKTQ_OUT_SINK: + default: + return NULL; + } + } +} + +int +app_pipeline_track_default(struct pipeline_params *p, + uint32_t port_in, + uint32_t *port_out) +{ + /* Check input arguments */ + if ((p == NULL) || + (port_in >= p->n_ports_in) || + (port_out == NULL)) + return -1; + + if (p->n_ports_out == 1) { + *port_out = 0; + return 0; + } + + return -1; +} int app_pipeline_ping(struct app_params *app, @@ -311,6 +445,40 @@ app_pipeline_port_in_disable(struct app_params *app, return status; } +int +app_link_set_op(struct app_params *app, + uint32_t link_id, + uint32_t pipeline_id, + app_link_op op, + void *arg) +{ + struct app_pipeline_params *pp; + struct app_link_params *lp; + struct app_link_data *ld; + uint32_t ppos, lpos; + + /* Check input arguments */ + if ((app == NULL) || + (op == NULL)) + return -1; + + APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, lp); + if (lp == NULL) + return -1; + lpos = lp - app->link_params; + ld = &app->link_data[lpos]; + + APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, pp); + if (pp == NULL) + return -1; + ppos = pp - app->pipeline_params; + + ld->f_link[ppos] = op; + ld->arg[ppos] = arg; + + return 0; +} + int app_link_config(struct app_params *app, uint32_t link_id, @@ -382,6 +550,8 @@ app_link_up(struct app_params *app, uint32_t link_id) { struct app_link_params *p; + struct app_link_data *d; + int i; /* Check input arguments */ if (app == NULL) @@ -394,6 +564,8 @@ app_link_up(struct app_params *app, return -1; } + d = &app->link_data[p - app->link_params]; + /* Check link state */ if (p->state) { APP_LOG(app, HIGH, "%s is already UP", p->name); @@ -408,6 +580,11 @@ app_link_up(struct app_params *app, app_link_up_internal(app, p); + /* Callbacks */ + for (i = 0; i < APP_MAX_PIPELINES; i++) + if (d->f_link[i]) + d->f_link[i](app, link_id, 1, d->arg[i]); + return 0; } @@ -416,6 +593,8 @@ app_link_down(struct app_params *app, uint32_t link_id) { struct app_link_params *p; + struct app_link_data *d; + uint32_t i; /* Check input arguments */ if (app == NULL) @@ -428,6 +607,8 @@ app_link_down(struct app_params *app, return -1; } + d = &app->link_data[p - app->link_params]; + /* Check link state */ if (p->state == 0) { APP_LOG(app, HIGH, "%s is already DOWN", p->name); @@ -436,6 +617,11 @@ app_link_down(struct app_params *app, app_link_down_internal(app, p); + /* Callbacks */ + for (i = 0; i < APP_MAX_PIPELINES; i++) + if (d->f_link[i]) + d->f_link[i](app, link_id, 0, d->arg[i]); + return 0; } @@ -464,16 +650,16 @@ cmd_ping_parsed( printf("Command failed\n"); } -cmdline_parse_token_string_t cmd_ping_p_string = +static cmdline_parse_token_string_t cmd_ping_p_string = TOKEN_STRING_INITIALIZER(struct cmd_ping_result, p_string, "p"); -cmdline_parse_token_num_t cmd_ping_pipeline_id = +static cmdline_parse_token_num_t cmd_ping_pipeline_id = TOKEN_NUM_INITIALIZER(struct cmd_ping_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_ping_ping_string = +static cmdline_parse_token_string_t cmd_ping_ping_string = TOKEN_STRING_INITIALIZER(struct cmd_ping_result, ping_string, "ping"); -cmdline_parse_inst_t cmd_ping = { +static cmdline_parse_inst_t cmd_ping = { .f = cmd_ping_parsed, .data = NULL, .help_str = "Pipeline ping", @@ -498,6 +684,7 @@ struct cmd_stats_port_in_result { uint32_t port_in_id; }; + static void cmd_stats_port_in_parsed( void *parsed_result, @@ -531,23 +718,23 @@ cmd_stats_port_in_parsed( stats.stats.n_pkts_drop); } -cmdline_parse_token_string_t cmd_stats_port_in_p_string = +static cmdline_parse_token_string_t cmd_stats_port_in_p_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, p_string, "p"); -cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id = +static cmdline_parse_token_num_t cmd_stats_port_in_pipeline_id = TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_stats_port_in_stats_string = +static cmdline_parse_token_string_t cmd_stats_port_in_stats_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, stats_string, "stats"); -cmdline_parse_token_string_t cmd_stats_port_in_port_string = +static cmdline_parse_token_string_t cmd_stats_port_in_port_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, port_string, "port"); -cmdline_parse_token_string_t cmd_stats_port_in_in_string = +static cmdline_parse_token_string_t cmd_stats_port_in_in_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_port_in_result, in_string, "in"); @@ -555,7 +742,7 @@ cmdline_parse_token_string_t cmd_stats_port_in_in_string = TOKEN_NUM_INITIALIZER(struct cmd_stats_port_in_result, port_in_id, UINT32); -cmdline_parse_inst_t cmd_stats_port_in = { +static cmdline_parse_inst_t cmd_stats_port_in = { .f = cmd_stats_port_in_parsed, .data = NULL, .help_str = "Pipeline input port stats", @@ -617,31 +804,31 @@ cmd_stats_port_out_parsed( stats.stats.n_pkts_drop); } -cmdline_parse_token_string_t cmd_stats_port_out_p_string = +static cmdline_parse_token_string_t cmd_stats_port_out_p_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, p_string, "p"); -cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id = +static cmdline_parse_token_num_t cmd_stats_port_out_pipeline_id = TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_stats_port_out_stats_string = +static cmdline_parse_token_string_t cmd_stats_port_out_stats_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, stats_string, "stats"); -cmdline_parse_token_string_t cmd_stats_port_out_port_string = +static cmdline_parse_token_string_t cmd_stats_port_out_port_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, port_string, "port"); -cmdline_parse_token_string_t cmd_stats_port_out_out_string = +static cmdline_parse_token_string_t cmd_stats_port_out_out_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_port_out_result, out_string, "out"); -cmdline_parse_token_num_t cmd_stats_port_out_port_out_id = +static cmdline_parse_token_num_t cmd_stats_port_out_port_out_id = TOKEN_NUM_INITIALIZER(struct cmd_stats_port_out_result, port_out_id, UINT32); -cmdline_parse_inst_t cmd_stats_port_out = { +static cmdline_parse_inst_t cmd_stats_port_out = { .f = cmd_stats_port_out_parsed, .data = NULL, .help_str = "Pipeline output port stats", @@ -707,26 +894,26 @@ cmd_stats_table_parsed( stats.n_pkts_dropped_lkp_miss); } -cmdline_parse_token_string_t cmd_stats_table_p_string = +static cmdline_parse_token_string_t cmd_stats_table_p_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, p_string, "p"); -cmdline_parse_token_num_t cmd_stats_table_pipeline_id = +static cmdline_parse_token_num_t cmd_stats_table_pipeline_id = TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_stats_table_stats_string = +static cmdline_parse_token_string_t cmd_stats_table_stats_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, stats_string, "stats"); -cmdline_parse_token_string_t cmd_stats_table_table_string = +static cmdline_parse_token_string_t cmd_stats_table_table_string = TOKEN_STRING_INITIALIZER(struct cmd_stats_table_result, table_string, "table"); -cmdline_parse_token_num_t cmd_stats_table_table_id = +static cmdline_parse_token_num_t cmd_stats_table_table_id = TOKEN_NUM_INITIALIZER(struct cmd_stats_table_result, table_id, UINT32); -cmdline_parse_inst_t cmd_stats_table = { +static cmdline_parse_inst_t cmd_stats_table = { .f = cmd_stats_table_parsed, .data = NULL, .help_str = "Pipeline table stats", @@ -771,31 +958,31 @@ cmd_port_in_enable_parsed( printf("Command failed\n"); } -cmdline_parse_token_string_t cmd_port_in_enable_p_string = +static cmdline_parse_token_string_t cmd_port_in_enable_p_string = TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, p_string, "p"); -cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id = +static cmdline_parse_token_num_t cmd_port_in_enable_pipeline_id = TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_port_in_enable_port_string = +static cmdline_parse_token_string_t cmd_port_in_enable_port_string = TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, port_string, "port"); -cmdline_parse_token_string_t cmd_port_in_enable_in_string = +static cmdline_parse_token_string_t cmd_port_in_enable_in_string = TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, in_string, "in"); -cmdline_parse_token_num_t cmd_port_in_enable_port_in_id = +static cmdline_parse_token_num_t cmd_port_in_enable_port_in_id = TOKEN_NUM_INITIALIZER(struct cmd_port_in_enable_result, port_in_id, UINT32); -cmdline_parse_token_string_t cmd_port_in_enable_enable_string = +static cmdline_parse_token_string_t cmd_port_in_enable_enable_string = TOKEN_STRING_INITIALIZER(struct cmd_port_in_enable_result, enable_string, "enable"); -cmdline_parse_inst_t cmd_port_in_enable = { +static cmdline_parse_inst_t cmd_port_in_enable = { .f = cmd_port_in_enable_parsed, .data = NULL, .help_str = "Pipeline input port enable", @@ -841,31 +1028,31 @@ cmd_port_in_disable_parsed( printf("Command failed\n"); } -cmdline_parse_token_string_t cmd_port_in_disable_p_string = +static cmdline_parse_token_string_t cmd_port_in_disable_p_string = TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, p_string, "p"); -cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id = +static cmdline_parse_token_num_t cmd_port_in_disable_pipeline_id = TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_port_in_disable_port_string = +static cmdline_parse_token_string_t cmd_port_in_disable_port_string = TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, port_string, "port"); -cmdline_parse_token_string_t cmd_port_in_disable_in_string = +static cmdline_parse_token_string_t cmd_port_in_disable_in_string = TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, in_string, "in"); -cmdline_parse_token_num_t cmd_port_in_disable_port_in_id = +static cmdline_parse_token_num_t cmd_port_in_disable_port_in_id = TOKEN_NUM_INITIALIZER(struct cmd_port_in_disable_result, port_in_id, UINT32); -cmdline_parse_token_string_t cmd_port_in_disable_disable_string = +static cmdline_parse_token_string_t cmd_port_in_disable_disable_string = TOKEN_STRING_INITIALIZER(struct cmd_port_in_disable_result, disable_string, "disable"); -cmdline_parse_inst_t cmd_port_in_disable = { +static cmdline_parse_inst_t cmd_port_in_disable = { .f = cmd_port_in_disable_parsed, .data = NULL, .help_str = "Pipeline input port disable", @@ -963,219 +1150,144 @@ print_link_info(struct app_link_params *p) printf("\n"); } -struct cmd_link_config_result { - cmdline_fixed_string_t link_string; - uint32_t link_id; - cmdline_fixed_string_t config_string; - cmdline_ipaddr_t ip; - uint32_t depth; -}; - -static void -cmd_link_config_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct cmd_link_config_result *params = parsed_result; - struct app_params *app = data; - int status; - - uint32_t link_id = params->link_id; - uint32_t ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr); - uint32_t depth = params->depth; - - status = app_link_config(app, link_id, ip, depth); - if (status) - printf("Command failed\n"); - else { - struct app_link_params *p; - - APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p); - print_link_info(p); - } -} - -cmdline_parse_token_string_t cmd_link_config_link_string = - TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, link_string, - "link"); - -cmdline_parse_token_num_t cmd_link_config_link_id = - TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, link_id, UINT32); - -cmdline_parse_token_string_t cmd_link_config_config_string = - TOKEN_STRING_INITIALIZER(struct cmd_link_config_result, config_string, - "config"); - -cmdline_parse_token_ipaddr_t cmd_link_config_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_link_config_result, ip); - -cmdline_parse_token_num_t cmd_link_config_depth = - TOKEN_NUM_INITIALIZER(struct cmd_link_config_result, depth, UINT32); - -cmdline_parse_inst_t cmd_link_config = { - .f = cmd_link_config_parsed, - .data = NULL, - .help_str = "Link configuration", - .tokens = { - (void *)&cmd_link_config_link_string, - (void *)&cmd_link_config_link_id, - (void *)&cmd_link_config_config_string, - (void *)&cmd_link_config_ip, - (void *)&cmd_link_config_depth, - NULL, - }, -}; - /* - * link up + * link + * + * link config: + * link config + * + * link up: + * link up + * + * link down: + * link down + * + * link ls: + * link ls */ -struct cmd_link_up_result { +struct cmd_link_result { cmdline_fixed_string_t link_string; - uint32_t link_id; - cmdline_fixed_string_t up_string; + cmdline_multi_string_t multi_string; }; static void -cmd_link_up_parsed( +cmd_link_parsed( void *parsed_result, __attribute__((unused)) struct cmdline *cl, - void *data) + void *data) { - struct cmd_link_up_result *params = parsed_result; + struct cmd_link_result *params = parsed_result; struct app_params *app = data; + + char *tokens[16]; + uint32_t n_tokens = RTE_DIM(tokens); int status; - status = app_link_up(app, params->link_id); - if (status != 0) - printf("Command failed\n"); - else { - struct app_link_params *p; + uint32_t link_id; - APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id, - p); - print_link_info(p); + status = parse_tokenize_string(params->multi_string, tokens, &n_tokens); + if (status != 0) { + printf(CMD_MSG_TOO_MANY_ARGS, "link"); + return; } -} - -cmdline_parse_token_string_t cmd_link_up_link_string = - TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, link_string, - "link"); -cmdline_parse_token_num_t cmd_link_up_link_id = - TOKEN_NUM_INITIALIZER(struct cmd_link_up_result, link_id, UINT32); + /* link ls */ + if ((n_tokens == 1) && (strcmp(tokens[0], "ls") == 0)) { + for (link_id = 0; link_id < app->n_links; link_id++) { + struct app_link_params *p; -cmdline_parse_token_string_t cmd_link_up_up_string = - TOKEN_STRING_INITIALIZER(struct cmd_link_up_result, up_string, "up"); + APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p); + print_link_info(p); + } + return; + } /* link ls */ -cmdline_parse_inst_t cmd_link_up = { - .f = cmd_link_up_parsed, - .data = NULL, - .help_str = "Link UP", - .tokens = { - (void *)&cmd_link_up_link_string, - (void *)&cmd_link_up_link_id, - (void *)&cmd_link_up_up_string, - NULL, - }, -}; + if (n_tokens < 2) { + printf(CMD_MSG_MISMATCH_ARGS, "link"); + return; + } -/* - * link down - */ + if (parser_read_uint32(&link_id, tokens[0])) { + printf(CMD_MSG_INVALID_ARG, "linkid"); + return; + } -struct cmd_link_down_result { - cmdline_fixed_string_t link_string; - uint32_t link_id; - cmdline_fixed_string_t down_string; -}; + /* link config */ + if (strcmp(tokens[1], "config") == 0) { + struct in_addr ipaddr_ipv4; + uint32_t depth; -static void -cmd_link_down_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct cmd_link_down_result *params = parsed_result; - struct app_params *app = data; - int status; + if (n_tokens != 4) { + printf(CMD_MSG_MISMATCH_ARGS, "link config"); + return; + } - status = app_link_down(app, params->link_id); - if (status != 0) - printf("Command failed\n"); - else { - struct app_link_params *p; + if (parse_ipv4_addr(tokens[2], &ipaddr_ipv4)) { + printf(CMD_MSG_INVALID_ARG, "ipaddr"); + return; + } - APP_PARAM_FIND_BY_ID(app->link_params, "LINK", params->link_id, - p); - print_link_info(p); - } -} + if (parser_read_uint32(&depth, tokens[3])) { + printf(CMD_MSG_INVALID_ARG, "depth"); + return; + } -cmdline_parse_token_string_t cmd_link_down_link_string = - TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, link_string, - "link"); + status = app_link_config(app, + link_id, + rte_be_to_cpu_32(ipaddr_ipv4.s_addr), + depth); + if (status) + printf(CMD_MSG_FAIL, "link config"); -cmdline_parse_token_num_t cmd_link_down_link_id = - TOKEN_NUM_INITIALIZER(struct cmd_link_down_result, link_id, UINT32); + return; + } /* link config */ -cmdline_parse_token_string_t cmd_link_down_down_string = - TOKEN_STRING_INITIALIZER(struct cmd_link_down_result, down_string, - "down"); + /* link up */ + if (strcmp(tokens[1], "up") == 0) { + if (n_tokens != 2) { + printf(CMD_MSG_MISMATCH_ARGS, "link up"); + return; + } -cmdline_parse_inst_t cmd_link_down = { - .f = cmd_link_down_parsed, - .data = NULL, - .help_str = "Link DOWN", - .tokens = { - (void *) &cmd_link_down_link_string, - (void *) &cmd_link_down_link_id, - (void *) &cmd_link_down_down_string, - NULL, - }, -}; + status = app_link_up(app, link_id); + if (status) + printf(CMD_MSG_FAIL, "link up"); -/* - * link ls - */ + return; + } /* link up */ -struct cmd_link_ls_result { - cmdline_fixed_string_t link_string; - cmdline_fixed_string_t ls_string; -}; + /* link down */ + if (strcmp(tokens[1], "down") == 0) { + if (n_tokens != 2) { + printf(CMD_MSG_MISMATCH_ARGS, "link down"); + return; + } -static void -cmd_link_ls_parsed( - __attribute__((unused)) void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct app_params *app = data; - uint32_t link_id; + status = app_link_down(app, link_id); + if (status) + printf(CMD_MSG_FAIL, "link down"); - for (link_id = 0; link_id < app->n_links; link_id++) { - struct app_link_params *p; + return; + } /* link down */ - APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, p); - print_link_info(p); - } + printf(CMD_MSG_MISMATCH_ARGS, "link"); } -cmdline_parse_token_string_t cmd_link_ls_link_string = - TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, link_string, - "link"); +static cmdline_parse_token_string_t cmd_link_link_string = + TOKEN_STRING_INITIALIZER(struct cmd_link_result, link_string, "link"); -cmdline_parse_token_string_t cmd_link_ls_ls_string = - TOKEN_STRING_INITIALIZER(struct cmd_link_ls_result, ls_string, "ls"); +static cmdline_parse_token_string_t cmd_link_multi_string = + TOKEN_STRING_INITIALIZER(struct cmd_link_result, multi_string, + TOKEN_STRING_MULTI); -cmdline_parse_inst_t cmd_link_ls = { - .f = cmd_link_ls_parsed, +static cmdline_parse_inst_t cmd_link = { + .f = cmd_link_parsed, .data = NULL, - .help_str = "Link list", + .help_str = "link config / up / down / ls", .tokens = { - (void *)&cmd_link_ls_link_string, - (void *)&cmd_link_ls_ls_string, + (void *) &cmd_link_link_string, + (void *) &cmd_link_multi_string, NULL, }, }; @@ -1212,6 +1324,11 @@ static cmdline_parse_inst_t cmd_quit = { /* * run + * + * run + * run [ []] + default is 1 + * is measured in milliseconds, default is 1 second */ static void @@ -1233,9 +1350,9 @@ app_run_file( close(fd); } -struct cmd_run_file_result { +struct cmd_run_result { cmdline_fixed_string_t run_string; - char file_name[APP_FILE_NAME_SIZE]; + cmdline_multi_string_t multi_string; }; static void @@ -1244,25 +1361,87 @@ cmd_run_parsed( struct cmdline *cl, __attribute__((unused)) void *data) { - struct cmd_run_file_result *params = parsed_result; + struct cmd_run_result *params = parsed_result; + + char *tokens[16]; + uint32_t n_tokens = RTE_DIM(tokens); + int status; + + char *file_name; + uint32_t count, interval, i; - app_run_file(cl->ctx, params->file_name); + status = parse_tokenize_string(params->multi_string, tokens, &n_tokens); + if (status) { + printf(CMD_MSG_TOO_MANY_ARGS, "run"); + return; + } + + switch (n_tokens) { + case 0: + printf(CMD_MSG_NOT_ENOUGH_ARGS, "run"); + return; + + case 1: + file_name = tokens[0]; + count = 1; + interval = 1000; + break; + + case 2: + file_name = tokens[0]; + + if (parser_read_uint32(&count, tokens[1]) || + (count == 0)) { + printf(CMD_MSG_INVALID_ARG, "count"); + return; + } + + interval = 1000; + break; + + case 3: + file_name = tokens[0]; + + if (parser_read_uint32(&count, tokens[1]) || + (count == 0)) { + printf(CMD_MSG_INVALID_ARG, "count"); + return; + } + + if (parser_read_uint32(&interval, tokens[2]) || + (interval == 0)) { + printf(CMD_MSG_INVALID_ARG, "interval"); + return; + } + break; + + default: + printf(CMD_MSG_MISMATCH_ARGS, "run"); + return; + } + + for (i = 0; i < count; i++) { + app_run_file(cl->ctx, file_name); + if (interval) + usleep(interval * 1000); + } } -cmdline_parse_token_string_t cmd_run_run_string = - TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, run_string, - "run"); +static cmdline_parse_token_string_t cmd_run_run_string = + TOKEN_STRING_INITIALIZER(struct cmd_run_result, run_string, "run"); + +static cmdline_parse_token_string_t cmd_run_multi_string = + TOKEN_STRING_INITIALIZER(struct cmd_run_result, multi_string, + TOKEN_STRING_MULTI); -cmdline_parse_token_string_t cmd_run_file_name = - TOKEN_STRING_INITIALIZER(struct cmd_run_file_result, file_name, NULL); -cmdline_parse_inst_t cmd_run = { +static cmdline_parse_inst_t cmd_run = { .f = cmd_run_parsed, .data = NULL, .help_str = "Run CLI script file", .tokens = { (void *) &cmd_run_run_string, - (void *) &cmd_run_file_name, + (void *) &cmd_run_multi_string, NULL, }, }; @@ -1270,12 +1449,7 @@ cmdline_parse_inst_t cmd_run = { static cmdline_parse_ctx_t pipeline_common_cmds[] = { (cmdline_parse_inst_t *) &cmd_quit, (cmdline_parse_inst_t *) &cmd_run, - - (cmdline_parse_inst_t *) &cmd_link_config, - (cmdline_parse_inst_t *) &cmd_link_up, - (cmdline_parse_inst_t *) &cmd_link_down, - (cmdline_parse_inst_t *) &cmd_link_ls, - + (cmdline_parse_inst_t *) &cmd_link, (cmdline_parse_inst_t *) &cmd_ping, (cmdline_parse_inst_t *) &cmd_stats_port_in, (cmdline_parse_inst_t *) &cmd_stats_port_out, diff --git a/examples/ip_pipeline/pipeline/pipeline_common_fe.h b/examples/ip_pipeline/pipeline/pipeline_common_fe.h index cfad963d..ce0bf13e 100644 --- a/examples/ip_pipeline/pipeline/pipeline_common_fe.h +++ b/examples/ip_pipeline/pipeline/pipeline_common_fe.h @@ -182,6 +182,16 @@ app_msg_send_recv(struct app_params *app, return msg_recv; } +struct app_link_params * +app_pipeline_track_pktq_out_to_link(struct app_params *app, + uint32_t pipeline_id, + uint32_t pktq_out_id); + +int +app_pipeline_track_default(struct pipeline_params *params, + uint32_t port_in, + uint32_t *port_out); + int app_pipeline_ping(struct app_params *app, uint32_t pipeline_id); @@ -214,6 +224,13 @@ app_pipeline_port_in_disable(struct app_params *app, uint32_t pipeline_id, uint32_t port_id); +int +app_link_set_op(struct app_params *app, + uint32_t link_id, + uint32_t pipeline_id, + app_link_op op, + void *arg); + int app_link_config(struct app_params *app, uint32_t link_id, @@ -231,4 +248,13 @@ app_link_down(struct app_params *app, int app_pipeline_common_cmd_push(struct app_params *app); +#define CMD_MSG_OUT_OF_MEMORY "Not enough memory\n" +#define CMD_MSG_NOT_ENOUGH_ARGS "Not enough arguments for command \"%s\"\n" +#define CMD_MSG_TOO_MANY_ARGS "Too many arguments for command \"%s\"\n" +#define CMD_MSG_MISMATCH_ARGS "Incorrect set of arguments for command \"%s\"\n" +#define CMD_MSG_INVALID_ARG "Invalid value for argument \"%s\"\n" +#define CMD_MSG_ARG_NOT_FOUND "Syntax error: \"%s\" not found\n" +#define CMD_MSG_FILE_ERR "Error in file \"%s\" at line %u\n" +#define CMD_MSG_FAIL "Command \"%s\" failed\n" + #endif diff --git a/examples/ip_pipeline/pipeline/pipeline_firewall.c b/examples/ip_pipeline/pipeline/pipeline_firewall.c index fd897d5c..a82e552d 100644 --- a/examples/ip_pipeline/pipeline/pipeline_firewall.c +++ b/examples/ip_pipeline/pipeline/pipeline_firewall.c @@ -30,9 +30,11 @@ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - +#include #include #include +#include +#include #include #include @@ -43,15 +45,11 @@ #include #include #include -#include -#include -#include #include "app.h" #include "pipeline_common_fe.h" #include "pipeline_firewall.h" - -#define BUF_SIZE 1024 +#include "parser.h" struct app_pipeline_firewall_rule { struct pipeline_firewall_key key; @@ -75,18 +73,6 @@ struct app_pipeline_firewall { void *default_rule_entry_ptr; }; -struct app_pipeline_add_bulk_params { - struct pipeline_firewall_key *keys; - uint32_t n_keys; - uint32_t *priorities; - uint32_t *port_ids; -}; - -struct app_pipeline_del_bulk_params { - struct pipeline_firewall_key *keys; - uint32_t n_keys; -}; - static void print_firewall_ipv4_rule(struct app_pipeline_firewall_rule *rule) { @@ -272,356 +258,118 @@ app_pipeline_firewall_key_check_and_normalize(struct pipeline_firewall_key *key) } } -static int -app_pipeline_add_bulk_parse_file(char *filename, - struct app_pipeline_add_bulk_params *params) +int +app_pipeline_firewall_load_file(char *filename, + struct pipeline_firewall_key *keys, + uint32_t *priorities, + uint32_t *port_ids, + uint32_t *n_keys, + uint32_t *line) { - FILE *f; - char file_buf[BUF_SIZE]; - uint32_t i; - int status = 0; + FILE *f = NULL; + char file_buf[1024]; + uint32_t i, l; - f = fopen(filename, "r"); - if (f == NULL) + /* Check input arguments */ + if ((filename == NULL) || + (keys == NULL) || + (priorities == NULL) || + (port_ids == NULL) || + (n_keys == NULL) || + (*n_keys == 0) || + (line == NULL)) { + if (line) + *line = 0; return -1; - - params->n_keys = 0; - while (fgets(file_buf, BUF_SIZE, f) != NULL) - params->n_keys++; - rewind(f); - - if (params->n_keys == 0) { - status = -1; - goto end; - } - - params->keys = rte_malloc(NULL, - params->n_keys * sizeof(struct pipeline_firewall_key), - RTE_CACHE_LINE_SIZE); - if (params->keys == NULL) { - status = -1; - goto end; - } - - params->priorities = rte_malloc(NULL, - params->n_keys * sizeof(uint32_t), - RTE_CACHE_LINE_SIZE); - if (params->priorities == NULL) { - status = -1; - goto end; - } - - params->port_ids = rte_malloc(NULL, - params->n_keys * sizeof(uint32_t), - RTE_CACHE_LINE_SIZE); - if (params->port_ids == NULL) { - status = -1; - goto end; - } - - i = 0; - while (fgets(file_buf, BUF_SIZE, f) != NULL) { - char *str; - - str = strtok(file_buf, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->priorities[i] = atoi(str); - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_ip = atoi(str)<<24; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_ip |= atoi(str)<<16; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_ip |= atoi(str)<<8; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_ip |= atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; } - params->keys[i].key.ipv4_5tuple.src_ip_mask = atoi(str); - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_ip = atoi(str)<<24; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_ip |= atoi(str)<<16; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_ip |= atoi(str)<<8; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_ip |= atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_ip_mask = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_port_from = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_port_to = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_port_from = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_port_to = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.proto = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - /* Need to add 2 to str to skip leading 0x */ - params->keys[i].key.ipv4_5tuple.proto_mask = strtol(str+2, NULL, 16); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->port_ids[i] = atoi(str); - params->keys[i].type = PIPELINE_FIREWALL_IPV4_5TUPLE; - - i++; - } - -end: - fclose(f); - return status; -} - -static int -app_pipeline_del_bulk_parse_file(char *filename, - struct app_pipeline_del_bulk_params *params) -{ - FILE *f; - char file_buf[BUF_SIZE]; - uint32_t i; - int status = 0; + /* Open input file */ f = fopen(filename, "r"); - if (f == NULL) + if (f == NULL) { + *line = 0; return -1; - - params->n_keys = 0; - while (fgets(file_buf, BUF_SIZE, f) != NULL) - params->n_keys++; - rewind(f); - - if (params->n_keys == 0) { - status = -1; - goto end; - } - - params->keys = rte_malloc(NULL, - params->n_keys * sizeof(struct pipeline_firewall_key), - RTE_CACHE_LINE_SIZE); - if (params->keys == NULL) { - status = -1; - goto end; } - i = 0; - while (fgets(file_buf, BUF_SIZE, f) != NULL) { - char *str; - - str = strtok(file_buf, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_ip = atoi(str)<<24; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_ip |= atoi(str)<<16; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_ip |= atoi(str)<<8; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_ip |= atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_ip_mask = atoi(str); - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_ip = atoi(str)<<24; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_ip |= atoi(str)<<16; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_ip |= atoi(str)<<8; - - str = strtok(NULL, " ."); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_ip |= atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_ip_mask = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_port_from = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.src_port_to = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_port_from = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.dst_port_to = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - params->keys[i].key.ipv4_5tuple.proto = atoi(str); - - str = strtok(NULL, " "); - if (str == NULL) { - status = -1; - goto end; - } - /* Need to add 2 to str to skip leading 0x */ - params->keys[i].key.ipv4_5tuple.proto_mask = strtol(str+2, NULL, 16); - - params->keys[i].type = PIPELINE_FIREWALL_IPV4_5TUPLE; + /* Read file */ + for (i = 0, l = 1; i < *n_keys; l++) { + char *tokens[32]; + uint32_t n_tokens = RTE_DIM(tokens); + + uint32_t priority = 0; + struct in_addr sipaddr; + uint32_t sipdepth = 0; + struct in_addr dipaddr; + uint32_t dipdepth = 0; + uint16_t sport0 = 0; + uint16_t sport1 = 0; + uint16_t dport0 = 0; + uint16_t dport1 = 0; + uint8_t proto = 0; + uint8_t protomask = 0; + uint32_t port_id = 0; + + int status; + + if (fgets(file_buf, sizeof(file_buf), f) == NULL) + break; + + status = parse_tokenize_string(file_buf, tokens, &n_tokens); + if (status) + goto error1; + + if ((n_tokens == 0) || (tokens[0][0] == '#')) + continue; + + if ((n_tokens != 15) || + strcmp(tokens[0], "priority") || + parser_read_uint32(&priority, tokens[1]) || + strcmp(tokens[2], "ipv4") || + parse_ipv4_addr(tokens[3], &sipaddr) || + parser_read_uint32(&sipdepth, tokens[4]) || + parse_ipv4_addr(tokens[5], &dipaddr) || + parser_read_uint32(&dipdepth, tokens[6]) || + parser_read_uint16(&sport0, tokens[7]) || + parser_read_uint16(&sport1, tokens[8]) || + parser_read_uint16(&dport0, tokens[9]) || + parser_read_uint16(&dport1, tokens[10]) || + parser_read_uint8(&proto, tokens[11]) || + parser_read_uint8_hex(&protomask, tokens[12]) || + strcmp(tokens[13], "port") || + parser_read_uint32(&port_id, tokens[14])) + goto error1; + + keys[i].type = PIPELINE_FIREWALL_IPV4_5TUPLE; + keys[i].key.ipv4_5tuple.src_ip = + rte_be_to_cpu_32(sipaddr.s_addr); + keys[i].key.ipv4_5tuple.src_ip_mask = sipdepth; + keys[i].key.ipv4_5tuple.dst_ip = + rte_be_to_cpu_32(dipaddr.s_addr); + keys[i].key.ipv4_5tuple.dst_ip_mask = dipdepth; + keys[i].key.ipv4_5tuple.src_port_from = sport0; + keys[i].key.ipv4_5tuple.src_port_to = sport1; + keys[i].key.ipv4_5tuple.dst_port_from = dport0; + keys[i].key.ipv4_5tuple.dst_port_to = dport1; + keys[i].key.ipv4_5tuple.proto = proto; + keys[i].key.ipv4_5tuple.proto_mask = protomask; + + port_ids[i] = port_id; + priorities[i] = priority; + + if (app_pipeline_firewall_key_check_and_normalize(&keys[i])) + goto error1; i++; } - for (i = 0; i < params->n_keys; i++) { - if (app_pipeline_firewall_key_check_and_normalize(¶ms->keys[i]) != 0) { - status = -1; - goto end; - } - } + /* Close file */ + *n_keys = i; + fclose(f); + return 0; -end: +error1: + *line = l; fclose(f); - return status; + return -1; } int @@ -804,14 +552,14 @@ app_pipeline_firewall_add_bulk(struct app_params *app, return -1; rules = rte_malloc(NULL, - n_keys * sizeof(struct app_pipeline_firewall_rule *), - RTE_CACHE_LINE_SIZE); + n_keys * sizeof(struct app_pipeline_firewall_rule *), + RTE_CACHE_LINE_SIZE); if (rules == NULL) return -1; new_rules = rte_malloc(NULL, - n_keys * sizeof(int), - RTE_CACHE_LINE_SIZE); + n_keys * sizeof(int), + RTE_CACHE_LINE_SIZE); if (new_rules == NULL) { rte_free(rules); return -1; @@ -834,8 +582,9 @@ app_pipeline_firewall_add_bulk(struct app_params *app, rules[i] = app_pipeline_firewall_rule_find(p, &keys[i]); new_rules[i] = (rules[i] == NULL); if (rules[i] == NULL) { - rules[i] = rte_malloc(NULL, sizeof(*rules[i]), - RTE_CACHE_LINE_SIZE); + rules[i] = rte_malloc(NULL, + sizeof(*rules[i]), + RTE_CACHE_LINE_SIZE); if (rules[i] == NULL) { uint32_t j; @@ -852,8 +601,8 @@ app_pipeline_firewall_add_bulk(struct app_params *app, } keys_found = rte_malloc(NULL, - n_keys * sizeof(int), - RTE_CACHE_LINE_SIZE); + n_keys * sizeof(int), + RTE_CACHE_LINE_SIZE); if (keys_found == NULL) { uint32_t j; @@ -867,8 +616,8 @@ app_pipeline_firewall_add_bulk(struct app_params *app, } entries_ptr = rte_malloc(NULL, - n_keys * sizeof(struct rte_pipeline_table_entry *), - RTE_CACHE_LINE_SIZE); + n_keys * sizeof(struct rte_pipeline_table_entry *), + RTE_CACHE_LINE_SIZE); if (entries_ptr == NULL) { uint32_t j; @@ -883,8 +632,8 @@ app_pipeline_firewall_add_bulk(struct app_params *app, } for (i = 0; i < n_keys; i++) { entries_ptr[i] = rte_malloc(NULL, - sizeof(struct rte_pipeline_table_entry), - RTE_CACHE_LINE_SIZE); + sizeof(struct rte_pipeline_table_entry), + RTE_CACHE_LINE_SIZE); if (entries_ptr[i] == NULL) { uint32_t j; @@ -1030,8 +779,8 @@ app_pipeline_firewall_delete_bulk(struct app_params *app, return -1; rules = rte_malloc(NULL, - n_keys * sizeof(struct app_pipeline_firewall_rule *), - RTE_CACHE_LINE_SIZE); + n_keys * sizeof(struct app_pipeline_firewall_rule *), + RTE_CACHE_LINE_SIZE); if (rules == NULL) return -1; @@ -1044,8 +793,8 @@ app_pipeline_firewall_delete_bulk(struct app_params *app, } keys_found = rte_malloc(NULL, - n_keys * sizeof(int), - RTE_CACHE_LINE_SIZE); + n_keys * sizeof(int), + RTE_CACHE_LINE_SIZE); if (keys_found == NULL) { rte_free(rules); return -1; @@ -1197,668 +946,500 @@ app_pipeline_firewall_delete_default_rule(struct app_params *app, } /* - * p firewall add ipv4 + * firewall + * + * firewall add: + * p firewall add priority + * ipv4 + * + * port + * Note: is a hex value + * + * p firewall add bulk + * + * firewall add default: + * p firewall add default + * + * firewall del: + * p firewall del + * ipv4 + * + * + * p firewall del bulk + * + * firewall del default: + * p firewall del default + * + * firewall ls: + * p firewall ls */ -struct cmd_firewall_add_ipv4_result { +struct cmd_firewall_result { cmdline_fixed_string_t p_string; uint32_t pipeline_id; cmdline_fixed_string_t firewall_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t ipv4_string; - int32_t priority; - cmdline_ipaddr_t src_ip; - uint32_t src_ip_mask; - cmdline_ipaddr_t dst_ip; - uint32_t dst_ip_mask; - uint16_t src_port_from; - uint16_t src_port_to; - uint16_t dst_port_from; - uint16_t dst_port_to; - uint8_t proto; - uint8_t proto_mask; - uint8_t port_id; + cmdline_multi_string_t multi_string; }; -static void -cmd_firewall_add_ipv4_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, +static void cmd_firewall_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, void *data) { - struct cmd_firewall_add_ipv4_result *params = parsed_result; + struct cmd_firewall_result *params = parsed_result; struct app_params *app = data; - struct pipeline_firewall_key key; int status; - key.type = PIPELINE_FIREWALL_IPV4_5TUPLE; - key.key.ipv4_5tuple.src_ip = rte_bswap32( - (uint32_t) params->src_ip.addr.ipv4.s_addr); - key.key.ipv4_5tuple.src_ip_mask = params->src_ip_mask; - key.key.ipv4_5tuple.dst_ip = rte_bswap32( - (uint32_t) params->dst_ip.addr.ipv4.s_addr); - key.key.ipv4_5tuple.dst_ip_mask = params->dst_ip_mask; - key.key.ipv4_5tuple.src_port_from = params->src_port_from; - key.key.ipv4_5tuple.src_port_to = params->src_port_to; - key.key.ipv4_5tuple.dst_port_from = params->dst_port_from; - key.key.ipv4_5tuple.dst_port_to = params->dst_port_to; - key.key.ipv4_5tuple.proto = params->proto; - key.key.ipv4_5tuple.proto_mask = params->proto_mask; - - status = app_pipeline_firewall_add_rule(app, - params->pipeline_id, - &key, - params->priority, - params->port_id); - - if (status != 0) { - printf("Command failed\n"); - return; - } -} - -cmdline_parse_token_string_t cmd_firewall_add_ipv4_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_ipv4_result, p_string, - "p"); - -cmdline_parse_token_num_t cmd_firewall_add_ipv4_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, pipeline_id, - UINT32); - -cmdline_parse_token_string_t cmd_firewall_add_ipv4_firewall_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_ipv4_result, - firewall_string, "firewall"); - -cmdline_parse_token_string_t cmd_firewall_add_ipv4_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_ipv4_result, - add_string, "add"); - -cmdline_parse_token_string_t cmd_firewall_add_ipv4_ipv4_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_ipv4_result, - ipv4_string, "ipv4"); - -cmdline_parse_token_num_t cmd_firewall_add_ipv4_priority = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, priority, - INT32); - -cmdline_parse_token_ipaddr_t cmd_firewall_add_ipv4_src_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_firewall_add_ipv4_result, src_ip); + char *tokens[17]; + uint32_t n_tokens = RTE_DIM(tokens); -cmdline_parse_token_num_t cmd_firewall_add_ipv4_src_ip_mask = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, src_ip_mask, - UINT32); - -cmdline_parse_token_ipaddr_t cmd_firewall_add_ipv4_dst_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_firewall_add_ipv4_result, dst_ip); - -cmdline_parse_token_num_t cmd_firewall_add_ipv4_dst_ip_mask = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, dst_ip_mask, - UINT32); - -cmdline_parse_token_num_t cmd_firewall_add_ipv4_src_port_from = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, - src_port_from, UINT16); - -cmdline_parse_token_num_t cmd_firewall_add_ipv4_src_port_to = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, - src_port_to, UINT16); - -cmdline_parse_token_num_t cmd_firewall_add_ipv4_dst_port_from = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, - dst_port_from, UINT16); - -cmdline_parse_token_num_t cmd_firewall_add_ipv4_dst_port_to = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, - dst_port_to, UINT16); - -cmdline_parse_token_num_t cmd_firewall_add_ipv4_proto = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, - proto, UINT8); - -cmdline_parse_token_num_t cmd_firewall_add_ipv4_proto_mask = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, - proto_mask, UINT8); - -cmdline_parse_token_num_t cmd_firewall_add_ipv4_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_ipv4_result, - port_id, UINT8); - -cmdline_parse_inst_t cmd_firewall_add_ipv4 = { - .f = cmd_firewall_add_ipv4_parsed, - .data = NULL, - .help_str = "Firewall rule add", - .tokens = { - (void *) &cmd_firewall_add_ipv4_p_string, - (void *) &cmd_firewall_add_ipv4_pipeline_id, - (void *) &cmd_firewall_add_ipv4_firewall_string, - (void *) &cmd_firewall_add_ipv4_add_string, - (void *) &cmd_firewall_add_ipv4_ipv4_string, - (void *) &cmd_firewall_add_ipv4_priority, - (void *) &cmd_firewall_add_ipv4_src_ip, - (void *) &cmd_firewall_add_ipv4_src_ip_mask, - (void *) &cmd_firewall_add_ipv4_dst_ip, - (void *) &cmd_firewall_add_ipv4_dst_ip_mask, - (void *) &cmd_firewall_add_ipv4_src_port_from, - (void *) &cmd_firewall_add_ipv4_src_port_to, - (void *) &cmd_firewall_add_ipv4_dst_port_from, - (void *) &cmd_firewall_add_ipv4_dst_port_to, - (void *) &cmd_firewall_add_ipv4_proto, - (void *) &cmd_firewall_add_ipv4_proto_mask, - (void *) &cmd_firewall_add_ipv4_port_id, - NULL, - }, -}; - -/* - * p firewall del ipv4 - */ - -struct cmd_firewall_del_ipv4_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t firewall_string; - cmdline_fixed_string_t del_string; - cmdline_fixed_string_t ipv4_string; - cmdline_ipaddr_t src_ip; - uint32_t src_ip_mask; - cmdline_ipaddr_t dst_ip; - uint32_t dst_ip_mask; - uint16_t src_port_from; - uint16_t src_port_to; - uint16_t dst_port_from; - uint16_t dst_port_to; - uint8_t proto; - uint8_t proto_mask; -}; - -static void -cmd_firewall_del_ipv4_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct cmd_firewall_del_ipv4_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_firewall_key key; - int status; - - key.type = PIPELINE_FIREWALL_IPV4_5TUPLE; - key.key.ipv4_5tuple.src_ip = rte_bswap32( - (uint32_t) params->src_ip.addr.ipv4.s_addr); - key.key.ipv4_5tuple.src_ip_mask = params->src_ip_mask; - key.key.ipv4_5tuple.dst_ip = rte_bswap32( - (uint32_t) params->dst_ip.addr.ipv4.s_addr); - key.key.ipv4_5tuple.dst_ip_mask = params->dst_ip_mask; - key.key.ipv4_5tuple.src_port_from = params->src_port_from; - key.key.ipv4_5tuple.src_port_to = params->src_port_to; - key.key.ipv4_5tuple.dst_port_from = params->dst_port_from; - key.key.ipv4_5tuple.dst_port_to = params->dst_port_to; - key.key.ipv4_5tuple.proto = params->proto; - key.key.ipv4_5tuple.proto_mask = params->proto_mask; - - status = app_pipeline_firewall_delete_rule(app, - params->pipeline_id, - &key); - - if (status != 0) { - printf("Command failed\n"); + status = parse_tokenize_string(params->multi_string, tokens, &n_tokens); + if (status) { + printf(CMD_MSG_TOO_MANY_ARGS, "firewall"); return; } -} - -cmdline_parse_token_string_t cmd_firewall_del_ipv4_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_ipv4_result, p_string, - "p"); - -cmdline_parse_token_num_t cmd_firewall_del_ipv4_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_ipv4_result, pipeline_id, - UINT32); - -cmdline_parse_token_string_t cmd_firewall_del_ipv4_firewall_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_ipv4_result, - firewall_string, "firewall"); - -cmdline_parse_token_string_t cmd_firewall_del_ipv4_del_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_ipv4_result, - del_string, "del"); -cmdline_parse_token_string_t cmd_firewall_del_ipv4_ipv4_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_ipv4_result, - ipv4_string, "ipv4"); - -cmdline_parse_token_ipaddr_t cmd_firewall_del_ipv4_src_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_firewall_del_ipv4_result, src_ip); - -cmdline_parse_token_num_t cmd_firewall_del_ipv4_src_ip_mask = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_ipv4_result, src_ip_mask, - UINT32); - -cmdline_parse_token_ipaddr_t cmd_firewall_del_ipv4_dst_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_firewall_del_ipv4_result, dst_ip); - -cmdline_parse_token_num_t cmd_firewall_del_ipv4_dst_ip_mask = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_ipv4_result, dst_ip_mask, - UINT32); + /* firewall add */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "priority") == 0)) { + struct pipeline_firewall_key key; + uint32_t priority; + struct in_addr sipaddr; + uint32_t sipdepth; + struct in_addr dipaddr; + uint32_t dipdepth; + uint16_t sport0; + uint16_t sport1; + uint16_t dport0; + uint16_t dport1; + uint8_t proto; + uint8_t protomask; + uint32_t port_id; + + memset(&key, 0, sizeof(key)); + + if (n_tokens != 16) { + printf(CMD_MSG_MISMATCH_ARGS, "firewall add"); + return; + } -cmdline_parse_token_num_t cmd_firewall_del_ipv4_src_port_from = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_ipv4_result, - src_port_from, UINT16); + if (parser_read_uint32(&priority, tokens[2])) { + printf(CMD_MSG_INVALID_ARG, "priority"); + return; + } -cmdline_parse_token_num_t cmd_firewall_del_ipv4_src_port_to = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_ipv4_result, src_port_to, - UINT16); + if (strcmp(tokens[3], "ipv4")) { + printf(CMD_MSG_ARG_NOT_FOUND, "ipv4"); + return; + } -cmdline_parse_token_num_t cmd_firewall_del_ipv4_dst_port_from = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_ipv4_result, - dst_port_from, UINT16); + if (parse_ipv4_addr(tokens[4], &sipaddr)) { + printf(CMD_MSG_INVALID_ARG, "sipaddr"); + return; + } -cmdline_parse_token_num_t cmd_firewall_del_ipv4_dst_port_to = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_ipv4_result, - dst_port_to, UINT16); + if (parser_read_uint32(&sipdepth, tokens[5])) { + printf(CMD_MSG_INVALID_ARG, "sipdepth"); + return; + } -cmdline_parse_token_num_t cmd_firewall_del_ipv4_proto = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_ipv4_result, - proto, UINT8); + if (parse_ipv4_addr(tokens[6], &dipaddr)) { + printf(CMD_MSG_INVALID_ARG, "dipaddr"); + return; + } -cmdline_parse_token_num_t cmd_firewall_del_ipv4_proto_mask = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_ipv4_result, proto_mask, - UINT8); + if (parser_read_uint32(&dipdepth, tokens[7])) { + printf(CMD_MSG_INVALID_ARG, "dipdepth"); + return; + } -cmdline_parse_inst_t cmd_firewall_del_ipv4 = { - .f = cmd_firewall_del_ipv4_parsed, - .data = NULL, - .help_str = "Firewall rule delete", - .tokens = { - (void *) &cmd_firewall_del_ipv4_p_string, - (void *) &cmd_firewall_del_ipv4_pipeline_id, - (void *) &cmd_firewall_del_ipv4_firewall_string, - (void *) &cmd_firewall_del_ipv4_del_string, - (void *) &cmd_firewall_del_ipv4_ipv4_string, - (void *) &cmd_firewall_del_ipv4_src_ip, - (void *) &cmd_firewall_del_ipv4_src_ip_mask, - (void *) &cmd_firewall_del_ipv4_dst_ip, - (void *) &cmd_firewall_del_ipv4_dst_ip_mask, - (void *) &cmd_firewall_del_ipv4_src_port_from, - (void *) &cmd_firewall_del_ipv4_src_port_to, - (void *) &cmd_firewall_del_ipv4_dst_port_from, - (void *) &cmd_firewall_del_ipv4_dst_port_to, - (void *) &cmd_firewall_del_ipv4_proto, - (void *) &cmd_firewall_del_ipv4_proto_mask, - NULL, - }, -}; + if (parser_read_uint16(&sport0, tokens[8])) { + printf(CMD_MSG_INVALID_ARG, "sport0"); + return; + } -/* - * p firewall add bulk - */ + if (parser_read_uint16(&sport1, tokens[9])) { + printf(CMD_MSG_INVALID_ARG, "sport1"); + return; + } -struct cmd_firewall_add_bulk_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t firewall_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t bulk_string; - cmdline_fixed_string_t file_path; -}; + if (parser_read_uint16(&dport0, tokens[10])) { + printf(CMD_MSG_INVALID_ARG, "dport0"); + return; + } -static void -cmd_firewall_add_bulk_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct cmd_firewall_add_bulk_result *params = parsed_result; - struct app_params *app = data; - int status; + if (parser_read_uint16(&dport1, tokens[11])) { + printf(CMD_MSG_INVALID_ARG, "dport1"); + return; + } - struct app_pipeline_add_bulk_params add_bulk_params; + if (parser_read_uint8(&proto, tokens[12])) { + printf(CMD_MSG_INVALID_ARG, "proto"); + return; + } - status = app_pipeline_add_bulk_parse_file(params->file_path, &add_bulk_params); - if (status != 0) { - printf("Command failed\n"); - goto end; - } + if (parser_read_uint8_hex(&protomask, tokens[13])) { + printf(CMD_MSG_INVALID_ARG, "protomask"); + return; + } - status = app_pipeline_firewall_add_bulk(app, params->pipeline_id, add_bulk_params.keys, - add_bulk_params.n_keys, add_bulk_params.priorities, add_bulk_params.port_ids); - if (status != 0) { - printf("Command failed\n"); - goto end; - } + if (strcmp(tokens[14], "port")) { + printf(CMD_MSG_ARG_NOT_FOUND, "port"); + return; + } -end: - rte_free(add_bulk_params.keys); - rte_free(add_bulk_params.priorities); - rte_free(add_bulk_params.port_ids); -} + if (parser_read_uint32(&port_id, tokens[15])) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } -cmdline_parse_token_string_t cmd_firewall_add_bulk_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_bulk_result, p_string, - "p"); + key.type = PIPELINE_FIREWALL_IPV4_5TUPLE; + key.key.ipv4_5tuple.src_ip = rte_be_to_cpu_32(sipaddr.s_addr); + key.key.ipv4_5tuple.src_ip_mask = sipdepth; + key.key.ipv4_5tuple.dst_ip = rte_be_to_cpu_32(dipaddr.s_addr); + key.key.ipv4_5tuple.dst_ip_mask = dipdepth; + key.key.ipv4_5tuple.src_port_from = sport0; + key.key.ipv4_5tuple.src_port_to = sport1; + key.key.ipv4_5tuple.dst_port_from = dport0; + key.key.ipv4_5tuple.dst_port_to = dport1; + key.key.ipv4_5tuple.proto = proto; + key.key.ipv4_5tuple.proto_mask = protomask; + + status = app_pipeline_firewall_add_rule(app, + params->pipeline_id, + &key, + priority, + port_id); + if (status) + printf(CMD_MSG_FAIL, "firewall add"); -cmdline_parse_token_num_t cmd_firewall_add_bulk_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_bulk_result, pipeline_id, - UINT32); + return; + } /* firewall add */ + + /* firewall add bulk */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "bulk") == 0)) { + struct pipeline_firewall_key *keys; + uint32_t *priorities, *port_ids, n_keys, line; + char *filename; + + if (n_tokens != 3) { + printf(CMD_MSG_MISMATCH_ARGS, "firewall add bulk"); + return; + } -cmdline_parse_token_string_t cmd_firewall_add_bulk_firewall_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_bulk_result, - firewall_string, "firewall"); + filename = tokens[2]; -cmdline_parse_token_string_t cmd_firewall_add_bulk_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_bulk_result, - add_string, "add"); + n_keys = APP_PIPELINE_FIREWALL_MAX_RULES_IN_FILE; + keys = malloc(n_keys * sizeof(struct pipeline_firewall_key)); + if (keys == NULL) { + printf(CMD_MSG_OUT_OF_MEMORY); + return; + } + memset(keys, 0, n_keys * sizeof(struct pipeline_firewall_key)); -cmdline_parse_token_string_t cmd_firewall_add_bulk_bulk_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_bulk_result, - bulk_string, "bulk"); + priorities = malloc(n_keys * sizeof(uint32_t)); + if (priorities == NULL) { + printf(CMD_MSG_OUT_OF_MEMORY); + free(keys); + return; + } -cmdline_parse_token_string_t cmd_firewall_add_bulk_file_path_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_bulk_result, - file_path, NULL); + port_ids = malloc(n_keys * sizeof(uint32_t)); + if (port_ids == NULL) { + printf(CMD_MSG_OUT_OF_MEMORY); + free(priorities); + free(keys); + return; + } -cmdline_parse_inst_t cmd_firewall_add_bulk = { - .f = cmd_firewall_add_bulk_parsed, - .data = NULL, - .help_str = "Firewall rule add bulk", - .tokens = { - (void *) &cmd_firewall_add_bulk_p_string, - (void *) &cmd_firewall_add_bulk_pipeline_id, - (void *) &cmd_firewall_add_bulk_firewall_string, - (void *) &cmd_firewall_add_bulk_add_string, - (void *) &cmd_firewall_add_bulk_bulk_string, - (void *) &cmd_firewall_add_bulk_file_path_string, - NULL, - }, -}; + status = app_pipeline_firewall_load_file(filename, + keys, + priorities, + port_ids, + &n_keys, + &line); + if (status != 0) { + printf(CMD_MSG_FILE_ERR, filename, line); + free(port_ids); + free(priorities); + free(keys); + return; + } -/* - * p firewall del bulk - */ + status = app_pipeline_firewall_add_bulk(app, + params->pipeline_id, + keys, + n_keys, + priorities, + port_ids); + if (status) + printf(CMD_MSG_FAIL, "firewall add bulk"); + + free(keys); + free(priorities); + free(port_ids); + return; + } /* firewall add bulk */ -struct cmd_firewall_del_bulk_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t firewall_string; - cmdline_fixed_string_t del_string; - cmdline_fixed_string_t bulk_string; - cmdline_fixed_string_t file_path; -}; + /* firewall add default */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "default") == 0)) { + uint32_t port_id; -static void -cmd_firewall_del_bulk_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct cmd_firewall_del_bulk_result *params = parsed_result; - struct app_params *app = data; - int status; + if (n_tokens != 3) { + printf(CMD_MSG_MISMATCH_ARGS, "firewall add default"); + return; + } - struct app_pipeline_del_bulk_params del_bulk_params; + if (parser_read_uint32(&port_id, tokens[2])) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } - status = app_pipeline_del_bulk_parse_file(params->file_path, &del_bulk_params); - if (status != 0) { - printf("Command failed\n"); - goto end; - } + status = app_pipeline_firewall_add_default_rule(app, + params->pipeline_id, + port_id); + if (status) + printf(CMD_MSG_FAIL, "firewall add default"); - status = app_pipeline_firewall_delete_bulk(app, params->pipeline_id, - del_bulk_params.keys, del_bulk_params.n_keys); - if (status != 0) { - printf("Command failed\n"); - goto end; - } + return; + } /* firewall add default */ + + /* firewall del */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + (strcmp(tokens[1], "ipv4") == 0)) { + struct pipeline_firewall_key key; + struct in_addr sipaddr; + uint32_t sipdepth; + struct in_addr dipaddr; + uint32_t dipdepth; + uint16_t sport0; + uint16_t sport1; + uint16_t dport0; + uint16_t dport1; + uint8_t proto; + uint8_t protomask; + + memset(&key, 0, sizeof(key)); + + if (n_tokens != 12) { + printf(CMD_MSG_MISMATCH_ARGS, "firewall del"); + return; + } -end: - rte_free(del_bulk_params.keys); -} + if (parse_ipv4_addr(tokens[2], &sipaddr)) { + printf(CMD_MSG_INVALID_ARG, "sipaddr"); + return; + } -cmdline_parse_token_string_t cmd_firewall_del_bulk_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_bulk_result, p_string, - "p"); + if (parser_read_uint32(&sipdepth, tokens[3])) { + printf(CMD_MSG_INVALID_ARG, "sipdepth"); + return; + } -cmdline_parse_token_num_t cmd_firewall_del_bulk_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_bulk_result, pipeline_id, - UINT32); + if (parse_ipv4_addr(tokens[4], &dipaddr)) { + printf(CMD_MSG_INVALID_ARG, "dipaddr"); + return; + } -cmdline_parse_token_string_t cmd_firewall_del_bulk_firewall_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_bulk_result, - firewall_string, "firewall"); + if (parser_read_uint32(&dipdepth, tokens[5])) { + printf(CMD_MSG_INVALID_ARG, "dipdepth"); + return; + } -cmdline_parse_token_string_t cmd_firewall_del_bulk_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_bulk_result, - del_string, "del"); + if (parser_read_uint16(&sport0, tokens[6])) { + printf(CMD_MSG_INVALID_ARG, "sport0"); + return; + } -cmdline_parse_token_string_t cmd_firewall_del_bulk_bulk_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_bulk_result, - bulk_string, "bulk"); + if (parser_read_uint16(&sport1, tokens[7])) { + printf(CMD_MSG_INVALID_ARG, "sport1"); + return; + } -cmdline_parse_token_string_t cmd_firewall_del_bulk_file_path_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_bulk_result, - file_path, NULL); + if (parser_read_uint16(&dport0, tokens[8])) { + printf(CMD_MSG_INVALID_ARG, "dport0"); + return; + } -cmdline_parse_inst_t cmd_firewall_del_bulk = { - .f = cmd_firewall_del_bulk_parsed, - .data = NULL, - .help_str = "Firewall rule del bulk", - .tokens = { - (void *) &cmd_firewall_del_bulk_p_string, - (void *) &cmd_firewall_del_bulk_pipeline_id, - (void *) &cmd_firewall_del_bulk_firewall_string, - (void *) &cmd_firewall_del_bulk_add_string, - (void *) &cmd_firewall_del_bulk_bulk_string, - (void *) &cmd_firewall_del_bulk_file_path_string, - NULL, - }, -}; + if (parser_read_uint16(&dport1, tokens[9])) { + printf(CMD_MSG_INVALID_ARG, "dport1"); + return; + } -/* - * p firewall add default - */ -struct cmd_firewall_add_default_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t firewall_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t default_string; - uint8_t port_id; -}; + if (parser_read_uint8(&proto, tokens[10])) { + printf(CMD_MSG_INVALID_ARG, "proto"); + return; + } -static void -cmd_firewall_add_default_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct cmd_firewall_add_default_result *params = parsed_result; - struct app_params *app = data; - int status; + if (parser_read_uint8_hex(&protomask, tokens[11])) { + printf(CMD_MSG_INVALID_ARG, "protomask"); + return; + } - status = app_pipeline_firewall_add_default_rule(app, - params->pipeline_id, - params->port_id); + key.type = PIPELINE_FIREWALL_IPV4_5TUPLE; + key.key.ipv4_5tuple.src_ip = rte_be_to_cpu_32(sipaddr.s_addr); + key.key.ipv4_5tuple.src_ip_mask = sipdepth; + key.key.ipv4_5tuple.dst_ip = rte_be_to_cpu_32(dipaddr.s_addr); + key.key.ipv4_5tuple.dst_ip_mask = dipdepth; + key.key.ipv4_5tuple.src_port_from = sport0; + key.key.ipv4_5tuple.src_port_to = sport1; + key.key.ipv4_5tuple.dst_port_from = dport0; + key.key.ipv4_5tuple.dst_port_to = dport1; + key.key.ipv4_5tuple.proto = proto; + key.key.ipv4_5tuple.proto_mask = protomask; + + status = app_pipeline_firewall_delete_rule(app, + params->pipeline_id, + &key); + if (status) + printf(CMD_MSG_FAIL, "firewall del"); - if (status != 0) { - printf("Command failed\n"); return; - } -} - -cmdline_parse_token_string_t cmd_firewall_add_default_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_default_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_firewall_add_default_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_default_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_firewall_add_default_firewall_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_default_result, - firewall_string, "firewall"); - -cmdline_parse_token_string_t cmd_firewall_add_default_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_default_result, - add_string, "add"); + } /* firewall del */ + + /* firewall del bulk */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + (strcmp(tokens[1], "bulk") == 0)) { + struct pipeline_firewall_key *keys; + uint32_t *priorities, *port_ids, n_keys, line; + char *filename; + + if (n_tokens != 3) { + printf(CMD_MSG_MISMATCH_ARGS, "firewall del bulk"); + return; + } -cmdline_parse_token_string_t cmd_firewall_add_default_default_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_add_default_result, - default_string, "default"); + filename = tokens[2]; -cmdline_parse_token_num_t cmd_firewall_add_default_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_add_default_result, port_id, - UINT8); + n_keys = APP_PIPELINE_FIREWALL_MAX_RULES_IN_FILE; + keys = malloc(n_keys * sizeof(struct pipeline_firewall_key)); + if (keys == NULL) { + printf(CMD_MSG_OUT_OF_MEMORY); + return; + } + memset(keys, 0, n_keys * sizeof(struct pipeline_firewall_key)); -cmdline_parse_inst_t cmd_firewall_add_default = { - .f = cmd_firewall_add_default_parsed, - .data = NULL, - .help_str = "Firewall default rule add", - .tokens = { - (void *) &cmd_firewall_add_default_p_string, - (void *) &cmd_firewall_add_default_pipeline_id, - (void *) &cmd_firewall_add_default_firewall_string, - (void *) &cmd_firewall_add_default_add_string, - (void *) &cmd_firewall_add_default_default_string, - (void *) &cmd_firewall_add_default_port_id, - NULL, - }, -}; + priorities = malloc(n_keys * sizeof(uint32_t)); + if (priorities == NULL) { + printf(CMD_MSG_OUT_OF_MEMORY); + free(keys); + return; + } -/* - * p firewall del default - */ -struct cmd_firewall_del_default_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t firewall_string; - cmdline_fixed_string_t del_string; - cmdline_fixed_string_t default_string; -}; + port_ids = malloc(n_keys * sizeof(uint32_t)); + if (port_ids == NULL) { + printf(CMD_MSG_OUT_OF_MEMORY); + free(priorities); + free(keys); + return; + } -static void -cmd_firewall_del_default_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct cmd_firewall_del_default_result *params = parsed_result; - struct app_params *app = data; - int status; + status = app_pipeline_firewall_load_file(filename, + keys, + priorities, + port_ids, + &n_keys, + &line); + if (status != 0) { + printf(CMD_MSG_FILE_ERR, filename, line); + free(port_ids); + free(priorities); + free(keys); + return; + } - status = app_pipeline_firewall_delete_default_rule(app, - params->pipeline_id); + status = app_pipeline_firewall_delete_bulk(app, + params->pipeline_id, + keys, + n_keys); + if (status) + printf(CMD_MSG_FAIL, "firewall del bulk"); - if (status != 0) { - printf("Command failed\n"); + free(port_ids); + free(priorities); + free(keys); return; - } -} - -cmdline_parse_token_string_t cmd_firewall_del_default_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_default_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_firewall_del_default_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_del_default_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_firewall_del_default_firewall_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_default_result, - firewall_string, "firewall"); - -cmdline_parse_token_string_t cmd_firewall_del_default_del_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_default_result, - del_string, "del"); + } /* firewall del bulk */ + + /* firewall del default */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + (strcmp(tokens[1], "default") == 0)) { + if (n_tokens != 2) { + printf(CMD_MSG_MISMATCH_ARGS, "firewall del default"); + return; + } -cmdline_parse_token_string_t cmd_firewall_del_default_default_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_del_default_result, - default_string, "default"); + status = app_pipeline_firewall_delete_default_rule(app, + params->pipeline_id); + if (status) + printf(CMD_MSG_FAIL, "firewall del default"); -cmdline_parse_inst_t cmd_firewall_del_default = { - .f = cmd_firewall_del_default_parsed, - .data = NULL, - .help_str = "Firewall default rule delete", - .tokens = { - (void *) &cmd_firewall_del_default_p_string, - (void *) &cmd_firewall_del_default_pipeline_id, - (void *) &cmd_firewall_del_default_firewall_string, - (void *) &cmd_firewall_del_default_del_string, - (void *) &cmd_firewall_del_default_default_string, - NULL, - }, -}; + return; -/* - * p firewall ls - */ + } /* firewall del default */ -struct cmd_firewall_ls_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t firewall_string; - cmdline_fixed_string_t ls_string; -}; - -static void -cmd_firewall_ls_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct cmd_firewall_ls_result *params = parsed_result; - struct app_params *app = data; - int status; + /* firewall ls */ + if ((n_tokens >= 1) && (strcmp(tokens[0], "ls") == 0)) { + if (n_tokens != 1) { + printf(CMD_MSG_MISMATCH_ARGS, "firewall ls"); + return; + } - status = app_pipeline_firewall_ls(app, params->pipeline_id); + status = app_pipeline_firewall_ls(app, params->pipeline_id); + if (status) + printf(CMD_MSG_FAIL, "firewall ls"); - if (status != 0) { - printf("Command failed\n"); return; - } + } /* firewall ls */ + + printf(CMD_MSG_MISMATCH_ARGS, "firewall"); } -cmdline_parse_token_string_t cmd_firewall_ls_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_ls_result, p_string, - "p"); +static cmdline_parse_token_string_t cmd_firewall_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_firewall_result, p_string, "p"); -cmdline_parse_token_num_t cmd_firewall_ls_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_firewall_ls_result, pipeline_id, - UINT32); +static cmdline_parse_token_num_t cmd_firewall_pipeline_id = + TOKEN_NUM_INITIALIZER(struct cmd_firewall_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_firewall_ls_firewall_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_ls_result, - firewall_string, "firewall"); +static cmdline_parse_token_string_t cmd_firewall_firewall_string = + TOKEN_STRING_INITIALIZER(struct cmd_firewall_result, firewall_string, + "firewall"); -cmdline_parse_token_string_t cmd_firewall_ls_ls_string = - TOKEN_STRING_INITIALIZER(struct cmd_firewall_ls_result, ls_string, - "ls"); +static cmdline_parse_token_string_t cmd_firewall_multi_string = + TOKEN_STRING_INITIALIZER(struct cmd_firewall_result, multi_string, + TOKEN_STRING_MULTI); -cmdline_parse_inst_t cmd_firewall_ls = { - .f = cmd_firewall_ls_parsed, +static cmdline_parse_inst_t cmd_firewall = { + .f = cmd_firewall_parsed, .data = NULL, - .help_str = "Firewall rule list", + .help_str = "firewall add / add bulk / add default / del / del bulk" + " / del default / ls", .tokens = { - (void *) &cmd_firewall_ls_p_string, - (void *) &cmd_firewall_ls_pipeline_id, - (void *) &cmd_firewall_ls_firewall_string, - (void *) &cmd_firewall_ls_ls_string, + (void *) &cmd_firewall_p_string, + (void *) &cmd_firewall_pipeline_id, + (void *) &cmd_firewall_firewall_string, + (void *) &cmd_firewall_multi_string, NULL, }, }; static cmdline_parse_ctx_t pipeline_cmds[] = { - (cmdline_parse_inst_t *) &cmd_firewall_add_ipv4, - (cmdline_parse_inst_t *) &cmd_firewall_del_ipv4, - (cmdline_parse_inst_t *) &cmd_firewall_add_bulk, - (cmdline_parse_inst_t *) &cmd_firewall_del_bulk, - (cmdline_parse_inst_t *) &cmd_firewall_add_default, - (cmdline_parse_inst_t *) &cmd_firewall_del_default, - (cmdline_parse_inst_t *) &cmd_firewall_ls, + (cmdline_parse_inst_t *) &cmd_firewall, NULL, }; static struct pipeline_fe_ops pipeline_firewall_fe_ops = { .f_init = app_pipeline_firewall_init, + .f_post_init = NULL, .f_free = app_pipeline_firewall_free, + .f_track = app_pipeline_track_default, .cmds = pipeline_cmds, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_firewall.h b/examples/ip_pipeline/pipeline/pipeline_firewall.h index ccc4e64b..aa79a2a0 100644 --- a/examples/ip_pipeline/pipeline/pipeline_firewall.h +++ b/examples/ip_pipeline/pipeline/pipeline_firewall.h @@ -72,6 +72,18 @@ int app_pipeline_firewall_delete_default_rule(struct app_params *app, uint32_t pipeline_id); +#ifndef APP_PIPELINE_FIREWALL_MAX_RULES_IN_FILE +#define APP_PIPELINE_FIREWALL_MAX_RULES_IN_FILE 65536 +#endif + +int +app_pipeline_firewall_load_file(char *filename, + struct pipeline_firewall_key *keys, + uint32_t *priorities, + uint32_t *port_ids, + uint32_t *n_keys, + uint32_t *line); + extern struct pipeline_type pipeline_firewall; #endif diff --git a/examples/ip_pipeline/pipeline/pipeline_firewall_be.c b/examples/ip_pipeline/pipeline/pipeline_firewall_be.c index e7a8a4c5..b61f3034 100644 --- a/examples/ip_pipeline/pipeline/pipeline_firewall_be.c +++ b/examples/ip_pipeline/pipeline/pipeline_firewall_be.c @@ -564,27 +564,6 @@ pipeline_firewall_free(void *pipeline) return 0; } -static int -pipeline_firewall_track(void *pipeline, - __rte_unused uint32_t port_in, - uint32_t *port_out) -{ - struct pipeline *p = (struct pipeline *) pipeline; - - /* Check input arguments */ - if ((p == NULL) || - (port_in >= p->n_ports_in) || - (port_out == NULL)) - return -1; - - if (p->n_ports_in == 1) { - *port_out = 0; - return 0; - } - - return -1; -} - static int pipeline_firewall_timer(void *pipeline) { @@ -732,7 +711,7 @@ pipeline_firewall_msg_req_add_bulk_handler(struct pipeline *p, void *msg) n_keys = req->n_keys; for (i = 0; i < n_keys; i++) { - entries[i] = rte_malloc(NULL, + entries[i] = rte_zmalloc(NULL, sizeof(struct firewall_table_entry), RTE_CACHE_LINE_SIZE); if (entries[i] == NULL) { @@ -740,7 +719,7 @@ pipeline_firewall_msg_req_add_bulk_handler(struct pipeline *p, void *msg) return rsp; } - params[i] = rte_malloc(NULL, + params[i] = rte_zmalloc(NULL, sizeof(struct rte_table_acl_rule_add_params), RTE_CACHE_LINE_SIZE); if (params[i] == NULL) { @@ -814,7 +793,7 @@ pipeline_firewall_msg_req_del_bulk_handler(struct pipeline *p, void *msg) n_keys = req->n_keys; for (i = 0; i < n_keys; i++) { - params[i] = rte_malloc(NULL, + params[i] = rte_zmalloc(NULL, sizeof(struct rte_table_acl_rule_delete_params), RTE_CACHE_LINE_SIZE); if (params[i] == NULL) { @@ -903,5 +882,4 @@ struct pipeline_be_ops pipeline_firewall_be_ops = { .f_free = pipeline_firewall_free, .f_run = NULL, .f_timer = pipeline_firewall_timer, - .f_track = pipeline_firewall_track, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_flow_actions.c b/examples/ip_pipeline/pipeline/pipeline_flow_actions.c index 4012121f..bf12fd7b 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 #include #include @@ -43,13 +44,12 @@ #include #include #include -#include -#include #include "app.h" #include "pipeline_common_fe.h" #include "pipeline_flow_actions.h" #include "hash_func.h" +#include "parser.h" /* * Flow actions pipeline @@ -689,1121 +689,620 @@ app_pipeline_fa_dscp_ls(struct app_params *app, return 0; } -/* - * Flow meter configuration (single flow) - * - * p flow meter trtcm - */ - -struct cmd_fa_meter_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 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_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_meter_config_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fa_flow_params flow_params; - int status; - - if (params->meter_id >= PIPELINE_FA_N_TC_MAX) { - printf("Command failed\n"); - return; - } - - flow_params.m[params->meter_id].cir = params->cir; - flow_params.m[params->meter_id].pir = params->pir; - flow_params.m[params->meter_id].cbs = params->cbs; - flow_params.m[params->meter_id].pbs = params->pbs; - - status = app_pipeline_fa_flow_config(app, - params->pipeline_id, - params->flow_id, - 1 << params->meter_id, - 0, - 0, - &flow_params); - - if (status != 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fa_meter_config_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_meter_config_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_meter_config_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_result, - flow_string, "flow"); - -cmdline_parse_token_num_t cmd_fa_meter_config_flow_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, - flow_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_meter_config_meter_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_result, - meter_string, "meter"); - -cmdline_parse_token_num_t cmd_fa_meter_config_meter_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, - meter_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_meter_config_trtcm_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_result, - trtcm_string, "trtcm"); - -cmdline_parse_token_num_t cmd_fa_meter_config_cir = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, cir, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_pir = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, pir, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_cbs = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, cbs, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_pbs = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_result, pbs, UINT64); - -cmdline_parse_inst_t cmd_fa_meter_config = { - .f = cmd_fa_meter_config_parsed, - .data = NULL, - .help_str = "Flow meter configuration (single flow) ", - .tokens = { - (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) +int +app_pipeline_fa_load_file(char *filename, + uint32_t *flow_ids, + struct pipeline_fa_flow_params *p, + uint32_t *n_flows, + uint32_t *line) { - struct cmd_fa_meter_config_bulk_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fa_flow_params flow_template, *flow_params; - uint32_t *flow_id; - uint32_t i; + FILE *f = NULL; + char file_buf[1024]; + uint32_t i, l; - if ((params->n_flows == 0) || - (params->meter_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; - } + /* Check input arguments */ + if ((filename == NULL) || + (flow_ids == NULL) || + (p == NULL) || + (n_flows == NULL) || + (*n_flows == 0) || + (line == NULL)) { + if (line) + *line = 0; + return -1; + } - 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; + /* Open input file */ + f = fopen(filename, "r"); + if (f == NULL) { + *line = 0; + return -1; } - memset(&flow_template, 0, sizeof(flow_template)); - flow_template.m[params->meter_id].cir = params->cir; - flow_template.m[params->meter_id].pir = params->pir; - flow_template.m[params->meter_id].cbs = params->cbs; - flow_template.m[params->meter_id].pbs = params->pbs; + /* Read file */ + for (i = 0, l = 1; i < *n_flows; l++) { + char *tokens[64]; + uint32_t n_tokens = RTE_DIM(tokens); - for (i = 0; i < params->n_flows; i++) { - uint32_t pos = i % N_FLOWS_BULK; + int status; - flow_id[pos] = i; - memcpy(&flow_params[pos], - &flow_template, - sizeof(flow_template)); + if (fgets(file_buf, sizeof(file_buf), f) == NULL) + break; - if ((pos == N_FLOWS_BULK - 1) || - (i == params->n_flows - 1)) { - int status; + status = parse_tokenize_string(file_buf, tokens, &n_tokens); + if (status) + goto error1; - status = app_pipeline_fa_flow_config_bulk(app, - params->pipeline_id, - flow_id, - pos + 1, - 1 << params->meter_id, - 0, - 0, - flow_params); + if ((n_tokens == 0) || (tokens[0][0] == '#')) + continue; - if (status != 0) { - printf("Command failed\n"); - break; - } - } + if ((n_tokens != 64) || + /* flow */ + strcmp(tokens[0], "flow") || + parser_read_uint32(&flow_ids[i], tokens[1]) || + + /* meter & policer 0 */ + strcmp(tokens[2], "meter") || + strcmp(tokens[3], "0") || + strcmp(tokens[4], "trtcm") || + parser_read_uint64(&p[i].m[0].cir, tokens[5]) || + parser_read_uint64(&p[i].m[0].pir, tokens[6]) || + parser_read_uint64(&p[i].m[0].cbs, tokens[7]) || + parser_read_uint64(&p[i].m[0].pbs, tokens[8]) || + strcmp(tokens[9], "policer") || + strcmp(tokens[10], "0") || + strcmp(tokens[11], "g") || + string_to_policer_action(tokens[12], + &p[i].p[0].action[e_RTE_METER_GREEN]) || + strcmp(tokens[13], "y") || + string_to_policer_action(tokens[14], + &p[i].p[0].action[e_RTE_METER_YELLOW]) || + strcmp(tokens[15], "r") || + string_to_policer_action(tokens[16], + &p[i].p[0].action[e_RTE_METER_RED]) || + + /* meter & policer 1 */ + strcmp(tokens[17], "meter") || + strcmp(tokens[18], "1") || + strcmp(tokens[19], "trtcm") || + parser_read_uint64(&p[i].m[1].cir, tokens[20]) || + parser_read_uint64(&p[i].m[1].pir, tokens[21]) || + parser_read_uint64(&p[i].m[1].cbs, tokens[22]) || + parser_read_uint64(&p[i].m[1].pbs, tokens[23]) || + strcmp(tokens[24], "policer") || + strcmp(tokens[25], "1") || + strcmp(tokens[26], "g") || + string_to_policer_action(tokens[27], + &p[i].p[1].action[e_RTE_METER_GREEN]) || + strcmp(tokens[28], "y") || + string_to_policer_action(tokens[29], + &p[i].p[1].action[e_RTE_METER_YELLOW]) || + strcmp(tokens[30], "r") || + string_to_policer_action(tokens[31], + &p[i].p[1].action[e_RTE_METER_RED]) || + + /* meter & policer 2 */ + strcmp(tokens[32], "meter") || + strcmp(tokens[33], "2") || + strcmp(tokens[34], "trtcm") || + parser_read_uint64(&p[i].m[2].cir, tokens[35]) || + parser_read_uint64(&p[i].m[2].pir, tokens[36]) || + parser_read_uint64(&p[i].m[2].cbs, tokens[37]) || + parser_read_uint64(&p[i].m[2].pbs, tokens[38]) || + strcmp(tokens[39], "policer") || + strcmp(tokens[40], "2") || + strcmp(tokens[41], "g") || + string_to_policer_action(tokens[42], + &p[i].p[2].action[e_RTE_METER_GREEN]) || + strcmp(tokens[43], "y") || + string_to_policer_action(tokens[44], + &p[i].p[2].action[e_RTE_METER_YELLOW]) || + strcmp(tokens[45], "r") || + string_to_policer_action(tokens[46], + &p[i].p[2].action[e_RTE_METER_RED]) || + + /* meter & policer 3 */ + strcmp(tokens[47], "meter") || + strcmp(tokens[48], "3") || + strcmp(tokens[49], "trtcm") || + parser_read_uint64(&p[i].m[3].cir, tokens[50]) || + parser_read_uint64(&p[i].m[3].pir, tokens[51]) || + parser_read_uint64(&p[i].m[3].cbs, tokens[52]) || + parser_read_uint64(&p[i].m[3].pbs, tokens[53]) || + strcmp(tokens[54], "policer") || + strcmp(tokens[55], "3") || + strcmp(tokens[56], "g") || + string_to_policer_action(tokens[57], + &p[i].p[3].action[e_RTE_METER_GREEN]) || + strcmp(tokens[58], "y") || + string_to_policer_action(tokens[59], + &p[i].p[3].action[e_RTE_METER_YELLOW]) || + strcmp(tokens[60], "r") || + string_to_policer_action(tokens[61], + &p[i].p[3].action[e_RTE_METER_RED]) || + + /* port */ + strcmp(tokens[62], "port") || + parser_read_uint32(&p[i].port_id, tokens[63])) + goto error1; + + i++; } - rte_free(flow_params); - rte_free(flow_id); + /* Close file */ + *n_flows = i; + fclose(f); + return 0; +error1: + *line = l; + fclose(f); + return -1; } -cmdline_parse_token_string_t cmd_fa_meter_config_bulk_p_string = - 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 = - 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 = - 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 = - 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 = - 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 = - 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 = - TOKEN_STRING_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - trtcm_string, "trtcm"); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_cir = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - cir, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_pir = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - pir, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_cbs = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - cbs, UINT64); - -cmdline_parse_token_num_t cmd_fa_meter_config_bulk_pbs = - TOKEN_NUM_INITIALIZER(struct cmd_fa_meter_config_bulk_result, - pbs, UINT64); - -cmdline_parse_inst_t cmd_fa_meter_config_bulk = { - .f = cmd_fa_meter_config_bulk_parsed, - .data = NULL, - .help_str = "Flow meter configuration (multiple flows)", - .tokens = { - (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) + * action * - * p flow policer - * G Y R + * flow meter, policer and output port configuration: + * p action flow meter trtcm * - * = 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 = 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"); - -} - -cmdline_parse_token_string_t cmd_fa_policer_config_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_policer_config_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_config_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_config_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - flow_string, "flow"); - -cmdline_parse_token_num_t cmd_fa_policer_config_flow_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_config_result, - flow_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_config_policer_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - policer_string, "policer"); - -cmdline_parse_token_num_t cmd_fa_policer_config_policer_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_config_result, - policer_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_config_green_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - green_string, "G"); - -cmdline_parse_token_string_t cmd_fa_policer_config_g_action = - 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 = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - yellow_string, "Y"); - -cmdline_parse_token_string_t cmd_fa_policer_config_y_action = - 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 = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - red_string, "R"); - -cmdline_parse_token_string_t cmd_fa_policer_config_r_action = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_result, - r_action, "R#Y#G#D"); - -cmdline_parse_inst_t cmd_fa_policer_config = { - .f = cmd_fa_policer_config_parsed, - .data = NULL, - .help_str = "Flow policer configuration (single flow)", - .tokens = { - (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 action flow policer g y r + * is one of the following: + * G = recolor to green + * Y = recolor as yellow + * R = recolor as red + * D = drop * - * p flows policer - * G Y R + * p action flow port * - * = G (green) | Y (yellow) | R (red) | D (drop) - */ + * p action flow bulk + * + * flow policer stats read: + * p action flow stats + * + * flow ls: + * p action flow ls + * + * dscp table configuration: + * p action dscp class color + * + * dscp table ls: + * p action dscp ls +**/ -struct cmd_fa_policer_config_bulk_result { +struct cmd_action_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; + cmdline_fixed_string_t action_string; + cmdline_multi_string_t multi_string; }; static void -cmd_fa_policer_config_bulk_parsed( +cmd_action_parsed( void *parsed_result, __rte_unused struct cmdline *cl, void *data) { - struct cmd_fa_policer_config_bulk_result *params = parsed_result; + struct cmd_action_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; - } + char *tokens[16]; + uint32_t n_tokens = RTE_DIM(tokens); + int status; - 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"); + status = parse_tokenize_string(params->multi_string, tokens, &n_tokens); + if (status != 0) { + printf(CMD_MSG_TOO_MANY_ARGS, "action"); 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; - } + /* action flow meter */ + if ((n_tokens >= 3) && + (strcmp(tokens[0], "flow") == 0) && + strcmp(tokens[1], "bulk") && + strcmp(tokens[1], "ls") && + (strcmp(tokens[2], "meter") == 0)) { + struct pipeline_fa_flow_params flow_params; + uint32_t flow_id, meter_id; + + if (n_tokens != 9) { + printf(CMD_MSG_MISMATCH_ARGS, "action flow meter"); + return; } - } - - rte_free(flow_params); - rte_free(flow_id); - -} - -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_p_string = - 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 = - 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 = - 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 = - 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 = - 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 = - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - policer_id, UINT32); + memset(&flow_params, 0, sizeof(flow_params)); -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_green_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - green_string, "G"); + if (parser_read_uint32(&flow_id, tokens[1])) { + printf(CMD_MSG_INVALID_ARG, "flowid"); + return; + } -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_g_action = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - g_action, "R#Y#G#D"); + if (parser_read_uint32(&meter_id, tokens[3]) || + (meter_id >= PIPELINE_FA_N_TC_MAX)) { + printf(CMD_MSG_INVALID_ARG, "meterid"); + return; + } -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_yellow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - yellow_string, "Y"); + if (strcmp(tokens[4], "trtcm")) { + printf(CMD_MSG_ARG_NOT_FOUND, "trtcm"); + return; + } -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_y_action = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - y_action, "R#Y#G#D"); + if (parser_read_uint64(&flow_params.m[meter_id].cir, tokens[5])) { + printf(CMD_MSG_INVALID_ARG, "cir"); + return; + } -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_red_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - red_string, "R"); + if (parser_read_uint64(&flow_params.m[meter_id].pir, tokens[6])) { + printf(CMD_MSG_INVALID_ARG, "pir"); + return; + } -cmdline_parse_token_string_t cmd_fa_policer_config_bulk_r_action = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_config_bulk_result, - r_action, "R#Y#G#D"); + if (parser_read_uint64(&flow_params.m[meter_id].cbs, tokens[7])) { + printf(CMD_MSG_INVALID_ARG, "cbs"); + return; + } -cmdline_parse_inst_t cmd_fa_policer_config_bulk = { - .f = cmd_fa_policer_config_bulk_parsed, - .data = NULL, - .help_str = "Flow policer configuration (multiple flows)", - .tokens = { - (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, - }, -}; + if (parser_read_uint64(&flow_params.m[meter_id].pbs, tokens[8])) { + printf(CMD_MSG_INVALID_ARG, "pbs"); + return; + } -/* - * Flow output port configuration (single flow) - * - * p flow port - */ + status = app_pipeline_fa_flow_config(app, + params->pipeline_id, + flow_id, + 1 << meter_id, + 0, + 0, + &flow_params); + if (status) + printf(CMD_MSG_FAIL, "action flow meter"); -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; -}; + return; + } /* action flow meter */ + + /* action flow policer */ + if ((n_tokens >= 3) && + (strcmp(tokens[0], "flow") == 0) && + strcmp(tokens[1], "bulk") && + strcmp(tokens[1], "ls") && + (strcmp(tokens[2], "policer") == 0)) { + struct pipeline_fa_flow_params flow_params; + uint32_t flow_id, policer_id; + + if (n_tokens != 10) { + printf(CMD_MSG_MISMATCH_ARGS, "action flow policer"); + return; + } -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 = parsed_result; - struct app_params *app = data; - struct pipeline_fa_flow_params flow_params; - int status; + memset(&flow_params, 0, sizeof(flow_params)); - flow_params.port_id = params->port_id; + if (parser_read_uint32(&flow_id, tokens[1])) { + printf(CMD_MSG_INVALID_ARG, "flowid"); + return; + } - status = app_pipeline_fa_flow_config(app, - params->pipeline_id, - params->flow_id, - 0, - 0, - 1, - &flow_params); + if (parser_read_uint32(&policer_id, tokens[3]) || + (policer_id >= PIPELINE_FA_N_TC_MAX)) { + printf(CMD_MSG_INVALID_ARG, "policerid"); + return; + } - if (status != 0) - printf("Command failed\n"); -} + if (strcmp(tokens[4], "g")) { + printf(CMD_MSG_ARG_NOT_FOUND, "g"); + return; + } -cmdline_parse_token_string_t cmd_fa_output_port_config_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_output_port_config_result, - p_string, "p"); + if (string_to_policer_action(tokens[5], + &flow_params.p[policer_id].action[e_RTE_METER_GREEN])) { + printf(CMD_MSG_INVALID_ARG, "gaction"); + return; + } -cmdline_parse_token_num_t cmd_fa_output_port_config_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_output_port_config_result, - pipeline_id, UINT32); + if (strcmp(tokens[6], "y")) { + printf(CMD_MSG_ARG_NOT_FOUND, "y"); + return; + } -cmdline_parse_token_string_t cmd_fa_output_port_config_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_output_port_config_result, - flow_string, "flow"); + if (string_to_policer_action(tokens[7], + &flow_params.p[policer_id].action[e_RTE_METER_YELLOW])) { + printf(CMD_MSG_INVALID_ARG, "yaction"); + return; + } -cmdline_parse_token_num_t cmd_fa_output_port_config_flow_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_output_port_config_result, - flow_id, UINT32); + if (strcmp(tokens[8], "r")) { + printf(CMD_MSG_ARG_NOT_FOUND, "r"); + return; + } -cmdline_parse_token_string_t cmd_fa_output_port_config_port_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_output_port_config_result, - port_string, "port"); + if (string_to_policer_action(tokens[9], + &flow_params.p[policer_id].action[e_RTE_METER_RED])) { + printf(CMD_MSG_INVALID_ARG, "raction"); + return; + } -cmdline_parse_token_num_t cmd_fa_output_port_config_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_output_port_config_result, - port_id, UINT32); + status = app_pipeline_fa_flow_config(app, + params->pipeline_id, + flow_id, + 0, + 1 << policer_id, + 0, + &flow_params); + if (status != 0) + printf(CMD_MSG_FAIL, "action flow policer"); -cmdline_parse_inst_t cmd_fa_output_port_config = { - .f = cmd_fa_output_port_config_parsed, - .data = NULL, - .help_str = "Flow output port configuration (single flow)", - .tokens = { - (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, - }, -}; + return; + } /* action flow policer */ + + /* action flow port */ + if ((n_tokens >= 3) && + (strcmp(tokens[0], "flow") == 0) && + strcmp(tokens[1], "bulk") && + strcmp(tokens[1], "ls") && + (strcmp(tokens[2], "port") == 0)) { + struct pipeline_fa_flow_params flow_params; + uint32_t flow_id, port_id; + + if (n_tokens != 4) { + printf(CMD_MSG_MISMATCH_ARGS, "action flow port"); + return; + } -/* - * Flow output port configuration (multiple flows) - * - * p flows ports - */ + memset(&flow_params, 0, sizeof(flow_params)); -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; -}; + if (parser_read_uint32(&flow_id, tokens[1])) { + printf(CMD_MSG_INVALID_ARG, "flowid"); + return; + } -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 = parsed_result; - struct app_params *app = data; - struct pipeline_fa_flow_params *flow_params; - uint32_t *flow_id; - uint32_t i; + if (parser_read_uint32(&port_id, tokens[3])) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } - if (params->n_flows == 0) { - printf("Invalid arguments\n"); - return; - } + flow_params.port_id = port_id; - 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; - } + status = app_pipeline_fa_flow_config(app, + params->pipeline_id, + flow_id, + 0, + 0, + 1, + &flow_params); + if (status) + printf(CMD_MSG_FAIL, "action flow port"); - 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; - } - - for (i = 0; i < params->n_flows; i++) { - uint32_t pos = i % N_FLOWS_BULK; - uint32_t port_id = i % params->n_ports; - - flow_id[pos] = i; - - memset(&flow_params[pos], 0, sizeof(flow_params[pos])); - flow_params[pos].port_id = port_id; + } /* action flow port */ + + /* action flow stats */ + if ((n_tokens >= 3) && + (strcmp(tokens[0], "flow") == 0) && + strcmp(tokens[1], "bulk") && + strcmp(tokens[1], "ls") && + (strcmp(tokens[2], "stats") == 0)) { + struct pipeline_fa_policer_stats stats; + uint32_t flow_id, policer_id; + + if (n_tokens != 3) { + printf(CMD_MSG_MISMATCH_ARGS, "action flow stats"); + return; + } - if ((pos == N_FLOWS_BULK - 1) || - (i == params->n_flows - 1)) { - int status; + if (parser_read_uint32(&flow_id, tokens[1])) { + printf(CMD_MSG_INVALID_ARG, "flowid"); + return; + } - status = app_pipeline_fa_flow_config_bulk(app, + for (policer_id = 0; + policer_id < PIPELINE_FA_N_TC_MAX; + policer_id++) { + status = app_pipeline_fa_flow_policer_stats_read(app, params->pipeline_id, flow_id, - pos + 1, - 0, - 0, + policer_id, 1, - flow_params); - + &stats); if (status != 0) { - printf("Command failed\n"); - - break; + printf(CMD_MSG_FAIL, "action flow stats"); + return; } - } - } - - rte_free(flow_params); - rte_free(flow_id); - -} - -cmdline_parse_token_string_t cmd_fa_output_port_config_bulk_p_string = - 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 = - 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 = - 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 = - 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 = - 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 = - TOKEN_NUM_INITIALIZER(struct cmd_fa_output_port_config_bulk_result, - n_ports, UINT32); - -cmdline_parse_inst_t cmd_fa_output_port_config_bulk = { - .f = cmd_fa_output_port_config_bulk_parsed, - .data = NULL, - .help_str = "Flow output port configuration (multiple flows)", - .tokens = { - (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 - * - * = 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 = parsed_result; - struct app_params *app = data; - enum rte_meter_color color; - int status; + /* 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); + } - status = string_to_color(params->color, &color); - if (status) { - printf("Invalid color\n"); return; - } - - status = app_pipeline_fa_dscp_config(app, - params->pipeline_id, - params->dscp_id, - params->traffic_class_id, - color); - - if (status != 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fa_dscp_config_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_config_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_dscp_config_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_dscp_config_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_dscp_config_dscp_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_config_result, - dscp_string, "dscp"); - -cmdline_parse_token_num_t cmd_fa_dscp_config_dscp_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_dscp_config_result, - dscp_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_dscp_config_class_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_config_result, - class_string, "class"); - -cmdline_parse_token_num_t cmd_fa_dscp_config_traffic_class_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_dscp_config_result, - traffic_class_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_dscp_config_color_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_config_result, - color_string, "color"); - -cmdline_parse_token_string_t cmd_fa_dscp_config_color = - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_config_result, - color, "G#Y#R"); + } /* action flow stats */ + + /* action flow bulk */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "flow") == 0) && + (strcmp(tokens[1], "bulk") == 0)) { + struct pipeline_fa_flow_params *flow_params; + uint32_t *flow_ids, n_flows, line; + char *filename; + + if (n_tokens != 3) { + printf(CMD_MSG_MISMATCH_ARGS, "action flow bulk"); + return; + } -cmdline_parse_inst_t cmd_fa_dscp_config = { - .f = cmd_fa_dscp_config_parsed, - .data = NULL, - .help_str = "Flow DSCP translation table configuration", - .tokens = { - (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, - }, -}; + filename = tokens[2]; -/* - * Flow policer stats read - * - * p flow policer stats - */ + n_flows = APP_PIPELINE_FA_MAX_RECORDS_IN_FILE; + flow_ids = malloc(n_flows * sizeof(uint32_t)); + if (flow_ids == NULL) { + printf(CMD_MSG_OUT_OF_MEMORY); + return; + } -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; -}; + flow_params = malloc(n_flows * sizeof(struct pipeline_fa_flow_params)); + if (flow_params == NULL) { + printf(CMD_MSG_OUT_OF_MEMORY); + free(flow_ids); + return; + } -static void -cmd_fa_policer_stats_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_policer_stats_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fa_policer_stats stats; - int status; + status = app_pipeline_fa_load_file(filename, + flow_ids, + flow_params, + &n_flows, + &line); + if (status) { + printf(CMD_MSG_FILE_ERR, filename, line); + free(flow_params); + free(flow_ids); + return; + } - status = app_pipeline_fa_flow_policer_stats_read(app, - params->pipeline_id, - params->flow_id, - params->policer_id, - 1, - &stats); - if (status != 0) { - printf("Command failed\n"); + status = app_pipeline_fa_flow_config_bulk(app, + params->pipeline_id, + flow_ids, + n_flows, + 0xF, + 0xF, + 1, + flow_params); + if (status) + printf(CMD_MSG_FAIL, "action flow bulk"); + + free(flow_params); + free(flow_ids); return; - } - - /* 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); -} - -cmdline_parse_token_string_t cmd_fa_policer_stats_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_stats_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fa_policer_stats_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_stats_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_stats_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_stats_result, - flow_string, "flow"); - -cmdline_parse_token_num_t cmd_fa_policer_stats_flow_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_stats_result, - flow_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_stats_policer_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_stats_result, - policer_string, "policer"); - -cmdline_parse_token_num_t cmd_fa_policer_stats_policer_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_policer_stats_result, - policer_id, UINT32); - -cmdline_parse_token_string_t cmd_fa_policer_stats_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_policer_stats_result, - stats_string, "stats"); - -cmdline_parse_inst_t cmd_fa_policer_stats = { - .f = cmd_fa_policer_stats_parsed, - .data = NULL, - .help_str = "Flow policer stats read", - .tokens = { - (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 - */ + } /* action flow bulk */ + + /* action flow ls */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "flow") == 0) && + (strcmp(tokens[1], "ls") == 0)) { + if (n_tokens != 2) { + printf(CMD_MSG_MISMATCH_ARGS, "action flow ls"); + return; + } -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; -}; + status = app_pipeline_fa_flow_ls(app, + params->pipeline_id); + if (status) + printf(CMD_MSG_FAIL, "action flow ls"); -static void -cmd_fa_flow_ls_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_flow_ls_result *params = parsed_result; - struct app_params *app = data; - int status; - - status = app_pipeline_fa_flow_ls(app, params->pipeline_id); - if (status != 0) - printf("Command failed\n"); -} + return; + } /* action flow ls */ + + /* action dscp */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "dscp") == 0) && + strcmp(tokens[1], "ls")) { + uint32_t dscp_id, tc_id; + enum rte_meter_color color; + + if (n_tokens != 6) { + printf(CMD_MSG_MISMATCH_ARGS, "action dscp"); + return; + } -cmdline_parse_token_string_t cmd_fa_flow_ls_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_flow_ls_result, - p_string, "p"); + if (parser_read_uint32(&dscp_id, tokens[1])) { + printf(CMD_MSG_INVALID_ARG, "dscpid"); + return; + } -cmdline_parse_token_num_t cmd_fa_flow_ls_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_flow_ls_result, - pipeline_id, UINT32); + if (strcmp(tokens[2], "class")) { + printf(CMD_MSG_ARG_NOT_FOUND, "class"); + return; + } -cmdline_parse_token_string_t cmd_fa_flow_ls_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_flow_ls_result, - flow_string, "flow"); + if (parser_read_uint32(&tc_id, tokens[3])) { + printf(CMD_MSG_INVALID_ARG, "classid"); + return; + } -cmdline_parse_token_string_t cmd_fa_flow_ls_actions_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_flow_ls_result, - actions_string, "actions"); + if (strcmp(tokens[4], "color")) { + printf(CMD_MSG_ARG_NOT_FOUND, "color"); + return; + } -cmdline_parse_token_string_t cmd_fa_flow_ls_ls_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_flow_ls_result, - ls_string, "ls"); + if (string_to_color(tokens[5], &color)) { + printf(CMD_MSG_INVALID_ARG, "colorid"); + return; + } -cmdline_parse_inst_t cmd_fa_flow_ls = { - .f = cmd_fa_flow_ls_parsed, - .data = NULL, - .help_str = "Flow actions list", - .tokens = { - (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, - }, -}; + status = app_pipeline_fa_dscp_config(app, + params->pipeline_id, + dscp_id, + tc_id, + color); + if (status != 0) + printf(CMD_MSG_FAIL, "action dscp"); -/* - * Flow DiffServ Code Point (DSCP) translation table list - * - * p dscp ls - */ + return; + } /* action dscp */ + + /* action dscp ls */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "dscp") == 0) && + (strcmp(tokens[1], "ls") == 0)) { + if (n_tokens != 2) { + printf(CMD_MSG_MISMATCH_ARGS, "action dscp ls"); + return; + } -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; -}; + status = app_pipeline_fa_dscp_ls(app, + params->pipeline_id); + if (status) + printf(CMD_MSG_FAIL, "action dscp ls"); -static void -cmd_fa_dscp_ls_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fa_dscp_ls_result *params = parsed_result; - struct app_params *app = data; - int status; + return; + } /* action dscp ls */ - status = app_pipeline_fa_dscp_ls(app, params->pipeline_id); - if (status != 0) - printf("Command failed\n"); + printf(CMD_MSG_FAIL, "action"); } -cmdline_parse_token_string_t cmd_fa_dscp_ls_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_ls_result, - p_string, "p"); +static cmdline_parse_token_string_t cmd_action_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_action_result, p_string, "p"); -cmdline_parse_token_num_t cmd_fa_dscp_ls_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fa_dscp_ls_result, - pipeline_id, UINT32); +static cmdline_parse_token_num_t cmd_action_pipeline_id = + TOKEN_NUM_INITIALIZER(struct cmd_action_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_fa_dscp_ls_dscp_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_ls_result, - dscp_string, "dscp"); +static cmdline_parse_token_string_t cmd_action_action_string = + TOKEN_STRING_INITIALIZER(struct cmd_action_result, action_string, "action"); -cmdline_parse_token_string_t cmd_fa_dscp_ls_string = - TOKEN_STRING_INITIALIZER(struct cmd_fa_dscp_ls_result, ls_string, - "ls"); +static cmdline_parse_token_string_t cmd_action_multi_string = + TOKEN_STRING_INITIALIZER(struct cmd_action_result, multi_string, + TOKEN_STRING_MULTI); -cmdline_parse_inst_t cmd_fa_dscp_ls = { - .f = cmd_fa_dscp_ls_parsed, +cmdline_parse_inst_t cmd_action = { + .f = cmd_action_parsed, .data = NULL, - .help_str = "Flow DSCP translaton table list", + .help_str = "flow actions (meter, policer, policer stats, dscp table)", .tokens = { - (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, }, }; static cmdline_parse_ctx_t pipeline_cmds[] = { - (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, }; static struct pipeline_fe_ops pipeline_flow_actions_fe_ops = { .f_init = app_pipeline_fa_init, + .f_post_init = NULL, .f_free = app_pipeline_fa_free, + .f_track = app_pipeline_track_default, .cmds = pipeline_cmds, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_flow_actions.h b/examples/ip_pipeline/pipeline/pipeline_flow_actions.h index f2cd0cbb..9c609741 100644 --- a/examples/ip_pipeline/pipeline/pipeline_flow_actions.h +++ b/examples/ip_pipeline/pipeline/pipeline_flow_actions.h @@ -73,6 +73,17 @@ app_pipeline_fa_flow_policer_stats_read(struct app_params *app, int clear, struct pipeline_fa_policer_stats *stats); +#ifndef APP_PIPELINE_FA_MAX_RECORDS_IN_FILE +#define APP_PIPELINE_FA_MAX_RECORDS_IN_FILE 65536 +#endif + +int +app_pipeline_fa_load_file(char *filename, + uint32_t *flow_ids, + struct pipeline_fa_flow_params *p, + uint32_t *n_flows, + uint32_t *line); + extern struct pipeline_type pipeline_flow_actions; #endif diff --git a/examples/ip_pipeline/pipeline/pipeline_flow_actions_be.c b/examples/ip_pipeline/pipeline/pipeline_flow_actions_be.c index 3ad3ee63..11fcbb76 100644 --- a/examples/ip_pipeline/pipeline/pipeline_flow_actions_be.c +++ b/examples/ip_pipeline/pipeline/pipeline_flow_actions_be.c @@ -759,27 +759,6 @@ pipeline_fa_free(void *pipeline) return 0; } -static int -pipeline_fa_track(void *pipeline, - __rte_unused uint32_t port_in, - uint32_t *port_out) -{ - struct pipeline *p = (struct pipeline *) pipeline; - - /* Check input arguments */ - if ((p == NULL) || - (port_in >= p->n_ports_in) || - (port_out == NULL)) - return -1; - - if (p->n_ports_in == 1) { - *port_out = 0; - return 0; - } - - return -1; -} - static int pipeline_fa_timer(void *pipeline) { @@ -1007,5 +986,4 @@ struct pipeline_be_ops pipeline_flow_actions_be_ops = { .f_free = pipeline_fa_free, .f_run = NULL, .f_timer = pipeline_fa_timer, - .f_track = pipeline_fa_track, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_flow_classification.c b/examples/ip_pipeline/pipeline/pipeline_flow_classification.c index 19215748..9ef50cc9 100644 --- a/examples/ip_pipeline/pipeline/pipeline_flow_classification.c +++ b/examples/ip_pipeline/pipeline/pipeline_flow_classification.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -43,13 +44,12 @@ #include #include #include -#include -#include #include "app.h" #include "pipeline_common_fe.h" #include "pipeline_flow_classification.h" #include "hash_func.h" +#include "parser.h" /* * Key conversion @@ -96,9 +96,9 @@ app_pipeline_fc_key_convert(struct pipeline_fc_key *key_in, struct pkt_key_qinq *qinq = key_buffer; qinq->ethertype_svlan = 0; - qinq->svlan = rte_bswap16(key_in->key.qinq.svlan); + qinq->svlan = rte_cpu_to_be_16(key_in->key.qinq.svlan); qinq->ethertype_cvlan = 0; - qinq->cvlan = rte_bswap16(key_in->key.qinq.cvlan); + qinq->cvlan = rte_cpu_to_be_16(key_in->key.qinq.cvlan); if (signature) *signature = (uint32_t) hash_default_key8(qinq, 8, 0); @@ -112,10 +112,10 @@ app_pipeline_fc_key_convert(struct pipeline_fc_key *key_in, ipv4->ttl = 0; ipv4->proto = key_in->key.ipv4_5tuple.proto; ipv4->checksum = 0; - ipv4->ip_src = rte_bswap32(key_in->key.ipv4_5tuple.ip_src); - ipv4->ip_dst = rte_bswap32(key_in->key.ipv4_5tuple.ip_dst); - ipv4->port_src = rte_bswap16(key_in->key.ipv4_5tuple.port_src); - ipv4->port_dst = rte_bswap16(key_in->key.ipv4_5tuple.port_dst); + ipv4->ip_src = rte_cpu_to_be_32(key_in->key.ipv4_5tuple.ip_src); + ipv4->ip_dst = rte_cpu_to_be_32(key_in->key.ipv4_5tuple.ip_dst); + ipv4->port_src = rte_cpu_to_be_16(key_in->key.ipv4_5tuple.port_src); + ipv4->port_dst = rte_cpu_to_be_16(key_in->key.ipv4_5tuple.port_dst); if (signature) *signature = (uint32_t) hash_default_key16(ipv4, 16, 0); @@ -132,8 +132,8 @@ app_pipeline_fc_key_convert(struct pipeline_fc_key *key_in, ipv6->hop_limit = 0; memcpy(&ipv6->ip_src, &key_in->key.ipv6_5tuple.ip_src, 16); memcpy(&ipv6->ip_dst, &key_in->key.ipv6_5tuple.ip_dst, 16); - ipv6->port_src = rte_bswap16(key_in->key.ipv6_5tuple.port_src); - ipv6->port_dst = rte_bswap16(key_in->key.ipv6_5tuple.port_dst); + ipv6->port_src = rte_cpu_to_be_16(key_in->key.ipv6_5tuple.port_src); + ipv6->port_dst = rte_cpu_to_be_16(key_in->key.ipv6_5tuple.port_dst); if (signature) *signature = (uint32_t) hash_default_key64(ipv6, 64, 0); @@ -277,6 +277,283 @@ app_pipeline_fc_key_check(struct pipeline_fc_key *key) } } +int +app_pipeline_fc_load_file_qinq(char *filename, + struct pipeline_fc_key *keys, + uint32_t *port_ids, + uint32_t *flow_ids, + uint32_t *n_keys, + uint32_t *line) +{ + FILE *f = NULL; + char file_buf[1024]; + uint32_t i, l; + + /* Check input arguments */ + if ((filename == NULL) || + (keys == NULL) || + (port_ids == NULL) || + (flow_ids == NULL) || + (n_keys == NULL) || + (*n_keys == 0) || + (line == NULL)) { + if (line) + *line = 0; + return -1; + } + + /* Open input file */ + f = fopen(filename, "r"); + if (f == NULL) { + *line = 0; + return -1; + } + + /* Read file */ + for (i = 0, l = 1; i < *n_keys; l++) { + char *tokens[32]; + uint32_t n_tokens = RTE_DIM(tokens); + + uint16_t svlan, cvlan; + uint32_t portid, flowid; + int status; + + if (fgets(file_buf, sizeof(file_buf), f) == NULL) + break; + + status = parse_tokenize_string(file_buf, tokens, &n_tokens); + if (status) + goto error1; + + if ((n_tokens == 0) || (tokens[0][0] == '#')) + continue; + + if ((n_tokens != 7) || + strcmp(tokens[0], "qinq") || + parser_read_uint16(&svlan, tokens[1]) || + parser_read_uint16(&cvlan, tokens[2]) || + strcmp(tokens[3], "port") || + parser_read_uint32(&portid, tokens[4]) || + strcmp(tokens[5], "id") || + parser_read_uint32(&flowid, tokens[6])) + goto error1; + + keys[i].type = FLOW_KEY_QINQ; + keys[i].key.qinq.svlan = svlan; + keys[i].key.qinq.cvlan = cvlan; + + port_ids[i] = portid; + flow_ids[i] = flowid; + + if (app_pipeline_fc_key_check(&keys[i])) + goto error1; + + i++; + } + + /* Close file */ + *n_keys = i; + fclose(f); + return 0; + +error1: + *line = l; + fclose(f); + return -1; +} + +int +app_pipeline_fc_load_file_ipv4(char *filename, + struct pipeline_fc_key *keys, + uint32_t *port_ids, + uint32_t *flow_ids, + uint32_t *n_keys, + uint32_t *line) +{ + FILE *f = NULL; + char file_buf[1024]; + uint32_t i, l; + + /* Check input arguments */ + if ((filename == NULL) || + (keys == NULL) || + (port_ids == NULL) || + (flow_ids == NULL) || + (n_keys == NULL) || + (*n_keys == 0) || + (line == NULL)) { + if (line) + *line = 0; + return -1; + } + + /* Open input file */ + f = fopen(filename, "r"); + if (f == NULL) { + *line = 0; + return -1; + } + + /* Read file */ + for (i = 0, l = 1; i < *n_keys; l++) { + char *tokens[32]; + uint32_t n_tokens = RTE_DIM(tokens); + + struct in_addr sipaddr, dipaddr; + uint16_t sport, dport; + uint8_t proto; + uint32_t portid, flowid; + int status; + + if (fgets(file_buf, sizeof(file_buf), f) == NULL) + break; + + status = parse_tokenize_string(file_buf, tokens, &n_tokens); + if (status) + goto error2; + + if ((n_tokens == 0) || (tokens[0][0] == '#')) + continue; + + if ((n_tokens != 10) || + strcmp(tokens[0], "ipv4") || + parse_ipv4_addr(tokens[1], &sipaddr) || + parse_ipv4_addr(tokens[2], &dipaddr) || + parser_read_uint16(&sport, tokens[3]) || + parser_read_uint16(&dport, tokens[4]) || + parser_read_uint8(&proto, tokens[5]) || + strcmp(tokens[6], "port") || + parser_read_uint32(&portid, tokens[7]) || + strcmp(tokens[8], "id") || + parser_read_uint32(&flowid, tokens[9])) + goto error2; + + keys[i].type = FLOW_KEY_IPV4_5TUPLE; + keys[i].key.ipv4_5tuple.ip_src = rte_be_to_cpu_32(sipaddr.s_addr); + keys[i].key.ipv4_5tuple.ip_dst = rte_be_to_cpu_32(dipaddr.s_addr); + keys[i].key.ipv4_5tuple.port_src = sport; + keys[i].key.ipv4_5tuple.port_dst = dport; + keys[i].key.ipv4_5tuple.proto = proto; + + port_ids[i] = portid; + flow_ids[i] = flowid; + + if (app_pipeline_fc_key_check(&keys[i])) + goto error2; + + i++; + } + + /* Close file */ + *n_keys = i; + fclose(f); + return 0; + +error2: + *line = l; + fclose(f); + return -1; +} + +int +app_pipeline_fc_load_file_ipv6(char *filename, + struct pipeline_fc_key *keys, + uint32_t *port_ids, + uint32_t *flow_ids, + uint32_t *n_keys, + uint32_t *line) +{ + FILE *f = NULL; + char file_buf[1024]; + uint32_t i, l; + + /* Check input arguments */ + if ((filename == NULL) || + (keys == NULL) || + (port_ids == NULL) || + (flow_ids == NULL) || + (n_keys == NULL) || + (*n_keys == 0) || + (line == NULL)) { + if (line) + *line = 0; + return -1; + } + + /* Open input file */ + f = fopen(filename, "r"); + if (f == NULL) { + *line = 0; + return -1; + } + + /* Read file */ + for (i = 0, l = 1; i < *n_keys; l++) { + char *tokens[32]; + uint32_t n_tokens = RTE_DIM(tokens); + + struct in6_addr sipaddr, dipaddr; + uint16_t sport, dport; + uint8_t proto; + uint32_t portid, flowid; + int status; + + if (fgets(file_buf, sizeof(file_buf), f) == NULL) + break; + + status = parse_tokenize_string(file_buf, tokens, &n_tokens); + if (status) + goto error3; + + if ((n_tokens == 0) || (tokens[0][0] == '#')) + continue; + + if ((n_tokens != 10) || + strcmp(tokens[0], "ipv6") || + parse_ipv6_addr(tokens[1], &sipaddr) || + parse_ipv6_addr(tokens[2], &dipaddr) || + parser_read_uint16(&sport, tokens[3]) || + parser_read_uint16(&dport, tokens[4]) || + parser_read_uint8(&proto, tokens[5]) || + strcmp(tokens[6], "port") || + parser_read_uint32(&portid, tokens[7]) || + strcmp(tokens[8], "id") || + parser_read_uint32(&flowid, tokens[9])) + goto error3; + + keys[i].type = FLOW_KEY_IPV6_5TUPLE; + memcpy(keys[i].key.ipv6_5tuple.ip_src, + sipaddr.s6_addr, + sizeof(sipaddr.s6_addr)); + memcpy(keys[i].key.ipv6_5tuple.ip_dst, + dipaddr.s6_addr, + sizeof(dipaddr.s6_addr)); + keys[i].key.ipv6_5tuple.port_src = sport; + keys[i].key.ipv6_5tuple.port_dst = dport; + keys[i].key.ipv6_5tuple.proto = proto; + + port_ids[i] = portid; + flow_ids[i] = flowid; + + if (app_pipeline_fc_key_check(&keys[i])) + goto error3; + + i++; + } + + /* Close file */ + *n_keys = i; + fclose(f); + return 0; + +error3: + *line = l; + fclose(f); + return -1; +} + + + int app_pipeline_fc_add(struct app_params *app, uint32_t pipeline_id, @@ -896,1315 +1173,728 @@ app_pipeline_fc_ls(struct app_params *app, return 0; } - /* - * flow add qinq - */ - -struct cmd_fc_add_qinq_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t qinq_string; - uint16_t svlan; - uint16_t cvlan; - cmdline_fixed_string_t port_string; - uint32_t port; - cmdline_fixed_string_t flowid_string; - uint32_t flow_id; -}; - -static void -cmd_fc_add_qinq_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fc_add_qinq_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fc_key key; - int status; - - memset(&key, 0, sizeof(key)); - key.type = FLOW_KEY_QINQ; - key.key.qinq.svlan = params->svlan; - key.key.qinq.cvlan = params->cvlan; - - status = app_pipeline_fc_add(app, - params->pipeline_id, - &key, - params->port, - params->flow_id); - if (status != 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fc_add_qinq_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_result, p_string, "p"); - -cmdline_parse_token_num_t cmd_fc_add_qinq_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_qinq_result, pipeline_id, - UINT32); - -cmdline_parse_token_string_t cmd_fc_add_qinq_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_result, flow_string, - "flow"); - -cmdline_parse_token_string_t cmd_fc_add_qinq_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_result, add_string, - "add"); - -cmdline_parse_token_string_t cmd_fc_add_qinq_qinq_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_result, qinq_string, - "qinq"); - -cmdline_parse_token_num_t cmd_fc_add_qinq_svlan = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_qinq_result, svlan, UINT16); - -cmdline_parse_token_num_t cmd_fc_add_qinq_cvlan = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_qinq_result, cvlan, UINT16); - -cmdline_parse_token_string_t cmd_fc_add_qinq_port_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_result, port_string, - "port"); - -cmdline_parse_token_num_t cmd_fc_add_qinq_port = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_qinq_result, port, UINT32); - -cmdline_parse_token_string_t cmd_fc_add_qinq_flowid_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_result, flowid_string, - "flowid"); - -cmdline_parse_token_num_t cmd_fc_add_qinq_flow_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_qinq_result, flow_id, UINT32); - -cmdline_parse_inst_t cmd_fc_add_qinq = { - .f = cmd_fc_add_qinq_parsed, - .data = NULL, - .help_str = "Flow add (Q-in-Q)", - .tokens = { - (void *) &cmd_fc_add_qinq_p_string, - (void *) &cmd_fc_add_qinq_pipeline_id, - (void *) &cmd_fc_add_qinq_flow_string, - (void *) &cmd_fc_add_qinq_add_string, - (void *) &cmd_fc_add_qinq_qinq_string, - (void *) &cmd_fc_add_qinq_svlan, - (void *) &cmd_fc_add_qinq_cvlan, - (void *) &cmd_fc_add_qinq_port_string, - (void *) &cmd_fc_add_qinq_port, - (void *) &cmd_fc_add_qinq_flowid_string, - (void *) &cmd_fc_add_qinq_flow_id, - NULL, - }, -}; - -/* - * flow add qinq all + * flow + * + * flow add: + * p flow add qinq port id + * p flow add qinq bulk + * p flow add ipv4 port id + * p flow add ipv4 bulk + * p flow add ipv6 port id + * p flow add ipv6 bulk + * + * flow add default: + * p flow add default + * + * flow del: + * p flow del qinq + * p flow del ipv4 + * p flow del ipv6 + * + * flow del default: + * p flow del default + * + * flow ls: + * p flow ls */ -struct cmd_fc_add_qinq_all_result { +struct cmd_flow_result { cmdline_fixed_string_t p_string; uint32_t pipeline_id; cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t qinq_string; - cmdline_fixed_string_t all_string; - uint32_t n_flows; - uint32_t n_ports; + cmdline_multi_string_t multi_string; }; -#ifndef N_FLOWS_BULK -#define N_FLOWS_BULK 4096 -#endif - static void -cmd_fc_add_qinq_all_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, +cmd_flow_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, void *data) { - struct cmd_fc_add_qinq_all_result *params = parsed_result; + struct cmd_flow_result *results = parsed_result; struct app_params *app = data; - struct pipeline_fc_key *key; - uint32_t *port_id; - uint32_t *flow_id; - uint32_t id; - - /* Check input arguments */ - if (params->n_flows == 0) { - printf("Invalid number of flows\n"); - return; - } - if (params->n_ports == 0) { - printf("Invalid number of output ports\n"); - return; - } - - /* Memory allocation */ - key = rte_zmalloc(NULL, - N_FLOWS_BULK * sizeof(*key), - RTE_CACHE_LINE_SIZE); - if (key == NULL) { - printf("Memory allocation failed\n"); - return; - } - - port_id = rte_malloc(NULL, - N_FLOWS_BULK * sizeof(*port_id), - RTE_CACHE_LINE_SIZE); - if (port_id == NULL) { - rte_free(key); - printf("Memory allocation failed\n"); - return; - } + char *tokens[16]; + uint32_t n_tokens = RTE_DIM(tokens); + int status; - flow_id = rte_malloc(NULL, - N_FLOWS_BULK * sizeof(*flow_id), - RTE_CACHE_LINE_SIZE); - if (flow_id == NULL) { - rte_free(port_id); - rte_free(key); - printf("Memory allocation failed\n"); + status = parse_tokenize_string(results->multi_string, tokens, &n_tokens); + if (status) { + printf(CMD_MSG_TOO_MANY_ARGS, "flow"); return; } - /* Flow add */ - for (id = 0; id < params->n_flows; id++) { - uint32_t pos = id & (N_FLOWS_BULK - 1); - - key[pos].type = FLOW_KEY_QINQ; - key[pos].key.qinq.svlan = id >> 12; - key[pos].key.qinq.cvlan = id & 0xFFF; - - port_id[pos] = id % params->n_ports; - flow_id[pos] = id; - - if ((pos == N_FLOWS_BULK - 1) || - (id == params->n_flows - 1)) { - int status; - - status = app_pipeline_fc_add_bulk(app, - params->pipeline_id, - key, - port_id, - flow_id, - pos + 1); - - if (status != 0) { - printf("Command failed\n"); - - break; - } + /* flow add qinq */ + if ((n_tokens >= 3) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "qinq") == 0) && + strcmp(tokens[2], "bulk")) { + struct pipeline_fc_key key; + uint32_t svlan; + uint32_t cvlan; + uint32_t port_id; + uint32_t flow_id; + + memset(&key, 0, sizeof(key)); + + if (n_tokens != 8) { + printf(CMD_MSG_MISMATCH_ARGS, "flow add qinq"); + return; } - } - - /* Memory free */ - rte_free(flow_id); - rte_free(port_id); - rte_free(key); -} -cmdline_parse_token_string_t cmd_fc_add_qinq_all_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_all_result, p_string, - "p"); + if (parser_read_uint32(&svlan, tokens[2]) != 0) { + printf(CMD_MSG_INVALID_ARG, "svlan"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_qinq_all_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_qinq_all_result, pipeline_id, - UINT32); + if (parser_read_uint32(&cvlan, tokens[3]) != 0) { + printf(CMD_MSG_INVALID_ARG, "cvlan"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_qinq_all_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_all_result, flow_string, - "flow"); + if (strcmp(tokens[4], "port") != 0) { + printf(CMD_MSG_ARG_NOT_FOUND, "port"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_qinq_all_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_all_result, add_string, - "add"); + if (parser_read_uint32(&port_id, tokens[5]) != 0) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_qinq_all_qinq_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_all_result, qinq_string, - "qinq"); + if (strcmp(tokens[6], "id") != 0) { + printf(CMD_MSG_ARG_NOT_FOUND, "id"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_qinq_all_all_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_qinq_all_result, all_string, - "all"); + if (parser_read_uint32(&flow_id, tokens[7]) != 0) { + printf(CMD_MSG_INVALID_ARG, "flowid"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_qinq_all_n_flows = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_qinq_all_result, n_flows, - UINT32); + key.type = FLOW_KEY_QINQ; + key.key.qinq.svlan = svlan; + key.key.qinq.cvlan = cvlan; -cmdline_parse_token_num_t cmd_fc_add_qinq_all_n_ports = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_qinq_all_result, n_ports, - UINT32); + status = app_pipeline_fc_add(app, + results->pipeline_id, + &key, + port_id, + flow_id); + if (status) + printf(CMD_MSG_FAIL, "flow add qinq"); -cmdline_parse_inst_t cmd_fc_add_qinq_all = { - .f = cmd_fc_add_qinq_all_parsed, - .data = NULL, - .help_str = "Flow add all (Q-in-Q)", - .tokens = { - (void *) &cmd_fc_add_qinq_all_p_string, - (void *) &cmd_fc_add_qinq_all_pipeline_id, - (void *) &cmd_fc_add_qinq_all_flow_string, - (void *) &cmd_fc_add_qinq_all_add_string, - (void *) &cmd_fc_add_qinq_all_qinq_string, - (void *) &cmd_fc_add_qinq_all_all_string, - (void *) &cmd_fc_add_qinq_all_n_flows, - (void *) &cmd_fc_add_qinq_all_n_ports, - NULL, - }, -}; + return; + } /* flow add qinq */ + + /* flow add ipv4 */ + if ((n_tokens >= 3) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "ipv4") == 0) && + strcmp(tokens[2], "bulk")) { + struct pipeline_fc_key key; + struct in_addr sipaddr; + struct in_addr dipaddr; + uint32_t sport; + uint32_t dport; + uint32_t proto; + uint32_t port_id; + uint32_t flow_id; + + memset(&key, 0, sizeof(key)); + + if (n_tokens != 11) { + printf(CMD_MSG_MISMATCH_ARGS, "flow add ipv4"); + return; + } -/* - * flow add ipv4_5tuple - */ + if (parse_ipv4_addr(tokens[2], &sipaddr) != 0) { + printf(CMD_MSG_INVALID_ARG, "sipv4addr"); + return; + } + if (parse_ipv4_addr(tokens[3], &dipaddr) != 0) { + printf(CMD_MSG_INVALID_ARG, "dipv4addr"); + return; + } -struct cmd_fc_add_ipv4_5tuple_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t ipv4_5tuple_string; - cmdline_ipaddr_t ip_src; - cmdline_ipaddr_t ip_dst; - uint16_t port_src; - uint16_t port_dst; - uint32_t proto; - cmdline_fixed_string_t port_string; - uint32_t port; - cmdline_fixed_string_t flowid_string; - uint32_t flow_id; -}; + if (parser_read_uint32(&sport, tokens[4]) != 0) { + printf(CMD_MSG_INVALID_ARG, "sport"); + return; + } -static void -cmd_fc_add_ipv4_5tuple_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fc_add_ipv4_5tuple_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fc_key key; - int status; + if (parser_read_uint32(&dport, tokens[5]) != 0) { + printf(CMD_MSG_INVALID_ARG, "dport"); + return; + } - memset(&key, 0, sizeof(key)); - key.type = FLOW_KEY_IPV4_5TUPLE; - key.key.ipv4_5tuple.ip_src = rte_bswap32( - params->ip_src.addr.ipv4.s_addr); - key.key.ipv4_5tuple.ip_dst = rte_bswap32( - params->ip_dst.addr.ipv4.s_addr); - key.key.ipv4_5tuple.port_src = params->port_src; - key.key.ipv4_5tuple.port_dst = params->port_dst; - key.key.ipv4_5tuple.proto = params->proto; - - status = app_pipeline_fc_add(app, - params->pipeline_id, - &key, - params->port, - params->flow_id); - if (status != 0) - printf("Command failed\n"); -} + if (parser_read_uint32(&proto, tokens[6]) != 0) { + printf(CMD_MSG_INVALID_ARG, "proto"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, p_string, - "p"); + if (strcmp(tokens[7], "port") != 0) { + printf(CMD_MSG_ARG_NOT_FOUND, "port"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv4_5tuple_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, pipeline_id, - UINT32); + if (parser_read_uint32(&port_id, tokens[8]) != 0) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, - flow_string, "flow"); + if (strcmp(tokens[9], "id") != 0) { + printf(CMD_MSG_ARG_NOT_FOUND, "id"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, - add_string, "add"); + if (parser_read_uint32(&flow_id, tokens[10]) != 0) { + printf(CMD_MSG_INVALID_ARG, "flowid"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_ipv4_5tuple_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, - ipv4_5tuple_string, "ipv4_5tuple"); + key.type = FLOW_KEY_IPV4_5TUPLE; + key.key.ipv4_5tuple.ip_src = rte_be_to_cpu_32(sipaddr.s_addr); + key.key.ipv4_5tuple.ip_dst = rte_be_to_cpu_32(dipaddr.s_addr); + key.key.ipv4_5tuple.port_src = sport; + key.key.ipv4_5tuple.port_dst = dport; + key.key.ipv4_5tuple.proto = proto; + + status = app_pipeline_fc_add(app, + results->pipeline_id, + &key, + port_id, + flow_id); + if (status) + printf(CMD_MSG_FAIL, "flow add ipv4"); -cmdline_parse_token_ipaddr_t cmd_fc_add_ipv4_5tuple_ip_src = - TOKEN_IPV4_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, ip_src); + return; + } /* flow add ipv4 */ + + /* flow add ipv6 */ + if ((n_tokens >= 3) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "ipv6") == 0) && + strcmp(tokens[2], "bulk")) { + struct pipeline_fc_key key; + struct in6_addr sipaddr; + struct in6_addr dipaddr; + uint32_t sport; + uint32_t dport; + uint32_t proto; + uint32_t port_id; + uint32_t flow_id; + + memset(&key, 0, sizeof(key)); + + if (n_tokens != 11) { + printf(CMD_MSG_MISMATCH_ARGS, "flow add ipv6"); + return; + } -cmdline_parse_token_ipaddr_t cmd_fc_add_ipv4_5tuple_ip_dst = - TOKEN_IPV4_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, ip_dst); + if (parse_ipv6_addr(tokens[2], &sipaddr) != 0) { + printf(CMD_MSG_INVALID_ARG, "sipv6addr"); + return; + } + if (parse_ipv6_addr(tokens[3], &dipaddr) != 0) { + printf(CMD_MSG_INVALID_ARG, "dipv6addr"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv4_5tuple_port_src = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, port_src, - UINT16); + if (parser_read_uint32(&sport, tokens[4]) != 0) { + printf(CMD_MSG_INVALID_ARG, "sport"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv4_5tuple_port_dst = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, port_dst, - UINT16); + if (parser_read_uint32(&dport, tokens[5]) != 0) { + printf(CMD_MSG_INVALID_ARG, "dport"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv4_5tuple_proto = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, proto, - UINT32); + if (parser_read_uint32(&proto, tokens[6]) != 0) { + printf(CMD_MSG_INVALID_ARG, "proto"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_port_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, port_string, - "port"); + if (strcmp(tokens[7], "port") != 0) { + printf(CMD_MSG_ARG_NOT_FOUND, "port"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv4_5tuple_port = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, port, - UINT32); + if (parser_read_uint32(&port_id, tokens[8]) != 0) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_flowid_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, - flowid_string, "flowid"); + if (strcmp(tokens[9], "id") != 0) { + printf(CMD_MSG_ARG_NOT_FOUND, "id"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv4_5tuple_flow_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_result, flow_id, - UINT32); + if (parser_read_uint32(&flow_id, tokens[10]) != 0) { + printf(CMD_MSG_INVALID_ARG, "flowid"); + return; + } -cmdline_parse_inst_t cmd_fc_add_ipv4_5tuple = { - .f = cmd_fc_add_ipv4_5tuple_parsed, - .data = NULL, - .help_str = "Flow add (IPv4 5-tuple)", - .tokens = { - (void *) &cmd_fc_add_ipv4_5tuple_p_string, - (void *) &cmd_fc_add_ipv4_5tuple_pipeline_id, - (void *) &cmd_fc_add_ipv4_5tuple_flow_string, - (void *) &cmd_fc_add_ipv4_5tuple_add_string, - (void *) &cmd_fc_add_ipv4_5tuple_ipv4_5tuple_string, - (void *) &cmd_fc_add_ipv4_5tuple_ip_src, - (void *) &cmd_fc_add_ipv4_5tuple_ip_dst, - (void *) &cmd_fc_add_ipv4_5tuple_port_src, - (void *) &cmd_fc_add_ipv4_5tuple_port_dst, - (void *) &cmd_fc_add_ipv4_5tuple_proto, - (void *) &cmd_fc_add_ipv4_5tuple_port_string, - (void *) &cmd_fc_add_ipv4_5tuple_port, - (void *) &cmd_fc_add_ipv4_5tuple_flowid_string, - (void *) &cmd_fc_add_ipv4_5tuple_flow_id, - NULL, - }, -}; + key.type = FLOW_KEY_IPV6_5TUPLE; + memcpy(key.key.ipv6_5tuple.ip_src, (void *)&sipaddr, 16); + memcpy(key.key.ipv6_5tuple.ip_dst, (void *)&dipaddr, 16); + key.key.ipv6_5tuple.port_src = sport; + key.key.ipv6_5tuple.port_dst = dport; + key.key.ipv6_5tuple.proto = proto; + + status = app_pipeline_fc_add(app, + results->pipeline_id, + &key, + port_id, + flow_id); + if (status) + printf(CMD_MSG_FAIL, "flow add ipv6"); -/* - * flow add ipv4_5tuple all - */ + return; + } /* flow add ipv6 */ + + /* flow add qinq bulk */ + if ((n_tokens >= 3) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "qinq") == 0) && + (strcmp(tokens[2], "bulk") == 0)) { + struct pipeline_fc_key *keys; + uint32_t *port_ids, *flow_ids, n_keys, line; + char *filename; + + if (n_tokens != 4) { + printf(CMD_MSG_MISMATCH_ARGS, "flow add qinq bulk"); + return; + } -struct cmd_fc_add_ipv4_5tuple_all_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t ipv4_5tuple_string; - cmdline_fixed_string_t all_string; - uint32_t n_flows; - uint32_t n_ports; -}; + filename = tokens[3]; -static void -cmd_fc_add_ipv4_5tuple_all_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fc_add_ipv4_5tuple_all_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fc_key *key; - uint32_t *port_id; - uint32_t *flow_id; - uint32_t id; - - /* Check input parameters */ - if (params->n_flows == 0) { - printf("Invalid number of flows\n"); - return; - } + n_keys = APP_PIPELINE_FC_MAX_FLOWS_IN_FILE; + keys = malloc(n_keys * sizeof(struct pipeline_fc_key)); + if (keys == NULL) + return; + memset(keys, 0, n_keys * sizeof(struct pipeline_fc_key)); - if (params->n_ports == 0) { - printf("Invalid number of ports\n"); - return; - } + port_ids = malloc(n_keys * sizeof(uint32_t)); + if (port_ids == NULL) { + free(keys); + return; + } - /* Memory allocation */ - key = rte_zmalloc(NULL, - N_FLOWS_BULK * sizeof(*key), - RTE_CACHE_LINE_SIZE); - if (key == NULL) { - printf("Memory allocation failed\n"); - return; - } + flow_ids = malloc(n_keys * sizeof(uint32_t)); + if (flow_ids == NULL) { + free(port_ids); + free(keys); + return; + } - port_id = rte_malloc(NULL, - N_FLOWS_BULK * sizeof(*port_id), - RTE_CACHE_LINE_SIZE); - if (port_id == NULL) { - rte_free(key); - printf("Memory allocation failed\n"); - return; - } + status = app_pipeline_fc_load_file_qinq(filename, + keys, + port_ids, + flow_ids, + &n_keys, + &line); + if (status != 0) { + printf(CMD_MSG_FILE_ERR, filename, line); + free(flow_ids); + free(port_ids); + free(keys); + return; + } - flow_id = rte_malloc(NULL, - N_FLOWS_BULK * sizeof(*flow_id), - RTE_CACHE_LINE_SIZE); - if (flow_id == NULL) { - rte_free(port_id); - rte_free(key); - printf("Memory allocation failed\n"); + status = app_pipeline_fc_add_bulk(app, + results->pipeline_id, + keys, + port_ids, + flow_ids, + n_keys); + if (status) + printf(CMD_MSG_FAIL, "flow add qinq bulk"); + + free(flow_ids); + free(port_ids); + free(keys); return; - } - - /* Flow add */ - for (id = 0; id < params->n_flows; id++) { - uint32_t pos = id & (N_FLOWS_BULK - 1); + } /* flow add qinq bulk */ + + /* flow add ipv4 bulk */ + if ((n_tokens >= 3) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "ipv4") == 0) && + (strcmp(tokens[2], "bulk") == 0)) { + struct pipeline_fc_key *keys; + uint32_t *port_ids, *flow_ids, n_keys, line; + char *filename; + + if (n_tokens != 4) { + printf(CMD_MSG_MISMATCH_ARGS, "flow add ipv4 bulk"); + return; + } - key[pos].type = FLOW_KEY_IPV4_5TUPLE; - key[pos].key.ipv4_5tuple.ip_src = 0; - key[pos].key.ipv4_5tuple.ip_dst = id; - key[pos].key.ipv4_5tuple.port_src = 0; - key[pos].key.ipv4_5tuple.port_dst = 0; - key[pos].key.ipv4_5tuple.proto = 6; + filename = tokens[3]; - port_id[pos] = id % params->n_ports; - flow_id[pos] = id; + n_keys = APP_PIPELINE_FC_MAX_FLOWS_IN_FILE; + keys = malloc(n_keys * sizeof(struct pipeline_fc_key)); + if (keys == NULL) + return; + memset(keys, 0, n_keys * sizeof(struct pipeline_fc_key)); - if ((pos == N_FLOWS_BULK - 1) || - (id == params->n_flows - 1)) { - int status; + port_ids = malloc(n_keys * sizeof(uint32_t)); + if (port_ids == NULL) { + free(keys); + return; + } - status = app_pipeline_fc_add_bulk(app, - params->pipeline_id, - key, - port_id, - flow_id, - pos + 1); + flow_ids = malloc(n_keys * sizeof(uint32_t)); + if (flow_ids == NULL) { + free(port_ids); + free(keys); + return; + } - if (status != 0) { - printf("Command failed\n"); + status = app_pipeline_fc_load_file_ipv4(filename, + keys, + port_ids, + flow_ids, + &n_keys, + &line); + if (status != 0) { + printf(CMD_MSG_FILE_ERR, filename, line); + free(flow_ids); + free(port_ids); + free(keys); + return; + } - break; - } + status = app_pipeline_fc_add_bulk(app, + results->pipeline_id, + keys, + port_ids, + flow_ids, + n_keys); + if (status) + printf(CMD_MSG_FAIL, "flow add ipv4 bulk"); + + free(flow_ids); + free(port_ids); + free(keys); + return; + } /* flow add ipv4 bulk */ + + /* flow add ipv6 bulk */ + if ((n_tokens >= 3) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "ipv6") == 0) && + (strcmp(tokens[2], "bulk") == 0)) { + struct pipeline_fc_key *keys; + uint32_t *port_ids, *flow_ids, n_keys, line; + char *filename; + + if (n_tokens != 4) { + printf(CMD_MSG_MISMATCH_ARGS, "flow add ipv6 bulk"); + return; } - } - /* Memory free */ - rte_free(flow_id); - rte_free(port_id); - rte_free(key); -} + filename = tokens[3]; -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_all_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_all_result, - p_string, "p"); + n_keys = APP_PIPELINE_FC_MAX_FLOWS_IN_FILE; + keys = malloc(n_keys * sizeof(struct pipeline_fc_key)); + if (keys == NULL) + return; + memset(keys, 0, n_keys * sizeof(struct pipeline_fc_key)); -cmdline_parse_token_num_t cmd_fc_add_ipv4_5tuple_all_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_all_result, - pipeline_id, UINT32); + port_ids = malloc(n_keys * sizeof(uint32_t)); + if (port_ids == NULL) { + free(keys); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_all_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_all_result, - flow_string, "flow"); + flow_ids = malloc(n_keys * sizeof(uint32_t)); + if (flow_ids == NULL) { + free(port_ids); + free(keys); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_all_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_all_result, - add_string, "add"); + status = app_pipeline_fc_load_file_ipv6(filename, + keys, + port_ids, + flow_ids, + &n_keys, + &line); + if (status != 0) { + printf(CMD_MSG_FILE_ERR, filename, line); + free(flow_ids); + free(port_ids); + free(keys); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_all_ipv4_5tuple_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_all_result, - ipv4_5tuple_string, "ipv4_5tuple"); + status = app_pipeline_fc_add_bulk(app, + results->pipeline_id, + keys, + port_ids, + flow_ids, + n_keys); + if (status) + printf(CMD_MSG_FAIL, "flow add ipv6 bulk"); + + free(flow_ids); + free(port_ids); + free(keys); + return; + } /* flow add ipv6 bulk */ -cmdline_parse_token_string_t cmd_fc_add_ipv4_5tuple_all_all_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_all_result, - all_string, "all"); + /* flow add default*/ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "default") == 0)) { + uint32_t port_id; -cmdline_parse_token_num_t cmd_fc_add_ipv4_5tuple_all_n_flows = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_all_result, - n_flows, UINT32); + if (n_tokens != 3) { + printf(CMD_MSG_MISMATCH_ARGS, "flow add default"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv4_5tuple_all_n_ports = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv4_5tuple_all_result, - n_ports, UINT32); + if (parser_read_uint32(&port_id, tokens[2]) != 0) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } -cmdline_parse_inst_t cmd_fc_add_ipv4_5tuple_all = { - .f = cmd_fc_add_ipv4_5tuple_all_parsed, - .data = NULL, - .help_str = "Flow add all (IPv4 5-tuple)", - .tokens = { - (void *) &cmd_fc_add_ipv4_5tuple_all_p_string, - (void *) &cmd_fc_add_ipv4_5tuple_all_pipeline_id, - (void *) &cmd_fc_add_ipv4_5tuple_all_flow_string, - (void *) &cmd_fc_add_ipv4_5tuple_all_add_string, - (void *) &cmd_fc_add_ipv4_5tuple_all_ipv4_5tuple_string, - (void *) &cmd_fc_add_ipv4_5tuple_all_all_string, - (void *) &cmd_fc_add_ipv4_5tuple_all_n_flows, - (void *) &cmd_fc_add_ipv4_5tuple_all_n_ports, - NULL, - }, -}; + status = app_pipeline_fc_add_default(app, + results->pipeline_id, + port_id); + if (status) + printf(CMD_MSG_FAIL, "flow add default"); -/* - * flow add ipv6_5tuple - */ + return; + } /* flow add default */ -struct cmd_fc_add_ipv6_5tuple_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t ipv6_5tuple_string; - cmdline_ipaddr_t ip_src; - cmdline_ipaddr_t ip_dst; - uint16_t port_src; - uint16_t port_dst; - uint32_t proto; - cmdline_fixed_string_t port_string; - uint32_t port; - cmdline_fixed_string_t flowid_string; - uint32_t flow_id; -}; + /* flow del qinq */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + (strcmp(tokens[1], "qinq") == 0)) { + struct pipeline_fc_key key; + uint32_t svlan; + uint32_t cvlan; -static void -cmd_fc_add_ipv6_5tuple_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fc_add_ipv6_5tuple_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fc_key key; - int status; + memset(&key, 0, sizeof(key)); - memset(&key, 0, sizeof(key)); - key.type = FLOW_KEY_IPV6_5TUPLE; - memcpy(key.key.ipv6_5tuple.ip_src, - params->ip_src.addr.ipv6.s6_addr, - 16); - memcpy(key.key.ipv6_5tuple.ip_dst, - params->ip_dst.addr.ipv6.s6_addr, - 16); - key.key.ipv6_5tuple.port_src = params->port_src; - key.key.ipv6_5tuple.port_dst = params->port_dst; - key.key.ipv6_5tuple.proto = params->proto; - - status = app_pipeline_fc_add(app, - params->pipeline_id, - &key, - params->port, - params->flow_id); - if (status != 0) - printf("Command failed\n"); -} + if (n_tokens != 4) { + printf(CMD_MSG_MISMATCH_ARGS, "flow del qinq"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, - p_string, "p"); + if (parser_read_uint32(&svlan, tokens[2]) != 0) { + printf(CMD_MSG_INVALID_ARG, "svlan"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv6_5tuple_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, pipeline_id, - UINT32); + if (parser_read_uint32(&cvlan, tokens[3]) != 0) { + printf(CMD_MSG_INVALID_ARG, "cvlan"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, - flow_string, "flow"); + key.type = FLOW_KEY_QINQ; + key.key.qinq.svlan = svlan; + key.key.qinq.cvlan = cvlan; -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, - add_string, "add"); + status = app_pipeline_fc_del(app, + results->pipeline_id, + &key); + if (status) + printf(CMD_MSG_FAIL, "flow del qinq"); -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_ipv6_5tuple_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, - ipv6_5tuple_string, "ipv6_5tuple"); + return; + } /* flow del qinq */ + + /* flow del ipv4 */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + (strcmp(tokens[1], "ipv4") == 0)) { + struct pipeline_fc_key key; + struct in_addr sipaddr; + struct in_addr dipaddr; + uint32_t sport; + uint32_t dport; + uint32_t proto; + + memset(&key, 0, sizeof(key)); + + if (n_tokens != 7) { + printf(CMD_MSG_MISMATCH_ARGS, "flow del ipv4"); + return; + } -cmdline_parse_token_ipaddr_t cmd_fc_add_ipv6_5tuple_ip_src = - TOKEN_IPV6_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, ip_src); + if (parse_ipv4_addr(tokens[2], &sipaddr) != 0) { + printf(CMD_MSG_INVALID_ARG, "sipv4addr"); + return; + } + if (parse_ipv4_addr(tokens[3], &dipaddr) != 0) { + printf(CMD_MSG_INVALID_ARG, "dipv4addr"); + return; + } -cmdline_parse_token_ipaddr_t cmd_fc_add_ipv6_5tuple_ip_dst = - TOKEN_IPV6_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, ip_dst); + if (parser_read_uint32(&sport, tokens[4]) != 0) { + printf(CMD_MSG_INVALID_ARG, "sport"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv6_5tuple_port_src = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, port_src, - UINT16); + if (parser_read_uint32(&dport, tokens[5]) != 0) { + printf(CMD_MSG_INVALID_ARG, "dport"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv6_5tuple_port_dst = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, port_dst, - UINT16); + if (parser_read_uint32(&proto, tokens[6]) != 0) { + printf(CMD_MSG_INVALID_ARG, "proto"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv6_5tuple_proto = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, proto, - UINT32); + key.type = FLOW_KEY_IPV4_5TUPLE; + key.key.ipv4_5tuple.ip_src = rte_be_to_cpu_32(sipaddr.s_addr); + key.key.ipv4_5tuple.ip_dst = rte_be_to_cpu_32(dipaddr.s_addr); + key.key.ipv4_5tuple.port_src = sport; + key.key.ipv4_5tuple.port_dst = dport; + key.key.ipv4_5tuple.proto = proto; -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_port_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, - port_string, "port"); + status = app_pipeline_fc_del(app, + results->pipeline_id, + &key); + if (status) + printf(CMD_MSG_FAIL, "flow del ipv4"); -cmdline_parse_token_num_t cmd_fc_add_ipv6_5tuple_port = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, port, - UINT32); + return; + } /* flow del ipv4 */ + + /* flow del ipv6 */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + (strcmp(tokens[1], "ipv6") == 0)) { + struct pipeline_fc_key key; + struct in6_addr sipaddr; + struct in6_addr dipaddr; + uint32_t sport; + uint32_t dport; + uint32_t proto; + + memset(&key, 0, sizeof(key)); + + if (n_tokens != 7) { + printf(CMD_MSG_MISMATCH_ARGS, "flow del ipv6"); + return; + } -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_flowid_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, - flowid_string, "flowid"); + if (parse_ipv6_addr(tokens[2], &sipaddr) != 0) { + printf(CMD_MSG_INVALID_ARG, "sipv6addr"); + return; + } -cmdline_parse_token_num_t cmd_fc_add_ipv6_5tuple_flow_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_result, flow_id, - UINT32); + if (parse_ipv6_addr(tokens[3], &dipaddr) != 0) { + printf(CMD_MSG_INVALID_ARG, "dipv6addr"); + return; + } -cmdline_parse_inst_t cmd_fc_add_ipv6_5tuple = { - .f = cmd_fc_add_ipv6_5tuple_parsed, - .data = NULL, - .help_str = "Flow add (IPv6 5-tuple)", - .tokens = { - (void *) &cmd_fc_add_ipv6_5tuple_p_string, - (void *) &cmd_fc_add_ipv6_5tuple_pipeline_id, - (void *) &cmd_fc_add_ipv6_5tuple_flow_string, - (void *) &cmd_fc_add_ipv6_5tuple_add_string, - (void *) &cmd_fc_add_ipv6_5tuple_ipv6_5tuple_string, - (void *) &cmd_fc_add_ipv6_5tuple_ip_src, - (void *) &cmd_fc_add_ipv6_5tuple_ip_dst, - (void *) &cmd_fc_add_ipv6_5tuple_port_src, - (void *) &cmd_fc_add_ipv6_5tuple_port_dst, - (void *) &cmd_fc_add_ipv6_5tuple_proto, - (void *) &cmd_fc_add_ipv6_5tuple_port_string, - (void *) &cmd_fc_add_ipv6_5tuple_port, - (void *) &cmd_fc_add_ipv6_5tuple_flowid_string, - (void *) &cmd_fc_add_ipv6_5tuple_flow_id, - NULL, - }, -}; + if (parser_read_uint32(&sport, tokens[4]) != 0) { + printf(CMD_MSG_INVALID_ARG, "sport"); + return; + } -/* - * flow add ipv6_5tuple all - */ + if (parser_read_uint32(&dport, tokens[5]) != 0) { + printf(CMD_MSG_INVALID_ARG, "dport"); + return; + } -struct cmd_fc_add_ipv6_5tuple_all_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t ipv6_5tuple_string; - cmdline_fixed_string_t all_string; - uint32_t n_flows; - uint32_t n_ports; -}; + if (parser_read_uint32(&proto, tokens[6]) != 0) { + printf(CMD_MSG_INVALID_ARG, "proto"); + return; + } -static void -cmd_fc_add_ipv6_5tuple_all_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fc_add_ipv6_5tuple_all_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fc_key *key; - uint32_t *port_id; - uint32_t *flow_id; - uint32_t id; - - /* Check input parameters */ - if (params->n_flows == 0) { - printf("Invalid number of flows\n"); - return; - } + key.type = FLOW_KEY_IPV6_5TUPLE; + memcpy(key.key.ipv6_5tuple.ip_src, &sipaddr, 16); + memcpy(key.key.ipv6_5tuple.ip_dst, &dipaddr, 16); + key.key.ipv6_5tuple.port_src = sport; + key.key.ipv6_5tuple.port_dst = dport; + key.key.ipv6_5tuple.proto = proto; - if (params->n_ports == 0) { - printf("Invalid number of ports\n"); - return; - } + status = app_pipeline_fc_del(app, + results->pipeline_id, + &key); + if (status) + printf(CMD_MSG_FAIL, "flow del ipv6"); - /* Memory allocation */ - key = rte_zmalloc(NULL, - N_FLOWS_BULK * sizeof(*key), - RTE_CACHE_LINE_SIZE); - if (key == NULL) { - printf("Memory allocation failed\n"); return; - } + } /* flow del ipv6 */ + + /* flow del default*/ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + (strcmp(tokens[1], "default") == 0)) { + if (n_tokens != 2) { + printf(CMD_MSG_MISMATCH_ARGS, "flow del default"); + return; + } - port_id = rte_malloc(NULL, - N_FLOWS_BULK * sizeof(*port_id), - RTE_CACHE_LINE_SIZE); - if (port_id == NULL) { - rte_free(key); - printf("Memory allocation failed\n"); - return; - } + status = app_pipeline_fc_del_default(app, + results->pipeline_id); + if (status) + printf(CMD_MSG_FAIL, "flow del default"); - flow_id = rte_malloc(NULL, - N_FLOWS_BULK * sizeof(*flow_id), - RTE_CACHE_LINE_SIZE); - if (flow_id == NULL) { - rte_free(port_id); - rte_free(key); - printf("Memory allocation failed\n"); return; - } - - /* Flow add */ - for (id = 0; id < params->n_flows; id++) { - uint32_t pos = id & (N_FLOWS_BULK - 1); - uint32_t *x; - - key[pos].type = FLOW_KEY_IPV6_5TUPLE; - x = (uint32_t *) key[pos].key.ipv6_5tuple.ip_dst; - *x = rte_bswap32(id); - key[pos].key.ipv6_5tuple.proto = 6; - - port_id[pos] = id % params->n_ports; - flow_id[pos] = id; + } /* flow del default */ - if ((pos == N_FLOWS_BULK - 1) || - (id == params->n_flows - 1)) { - int status; - - status = app_pipeline_fc_add_bulk(app, - params->pipeline_id, - key, - port_id, - flow_id, - pos + 1); - - if (status != 0) { - printf("Command failed\n"); - - break; - } + /* flow ls */ + if ((n_tokens >= 1) && (strcmp(tokens[0], "ls") == 0)) { + if (n_tokens != 1) { + printf(CMD_MSG_MISMATCH_ARGS, "flow ls"); + return; } - } - - /* Memory free */ - rte_free(flow_id); - rte_free(port_id); - rte_free(key); -} - -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_all_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_all_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fc_add_ipv6_5tuple_all_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_all_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_all_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_all_result, - flow_string, "flow"); - -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_all_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_all_result, - add_string, "add"); - -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_all_ipv6_5tuple_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_all_result, - ipv6_5tuple_string, "ipv6_5tuple"); - -cmdline_parse_token_string_t cmd_fc_add_ipv6_5tuple_all_all_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_all_result, - all_string, "all"); - -cmdline_parse_token_num_t cmd_fc_add_ipv6_5tuple_all_n_flows = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_all_result, - n_flows, UINT32); - -cmdline_parse_token_num_t cmd_fc_add_ipv6_5tuple_all_n_ports = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_ipv6_5tuple_all_result, - n_ports, UINT32); - -cmdline_parse_inst_t cmd_fc_add_ipv6_5tuple_all = { - .f = cmd_fc_add_ipv6_5tuple_all_parsed, - .data = NULL, - .help_str = "Flow add all (ipv6 5-tuple)", - .tokens = { - (void *) &cmd_fc_add_ipv6_5tuple_all_p_string, - (void *) &cmd_fc_add_ipv6_5tuple_all_pipeline_id, - (void *) &cmd_fc_add_ipv6_5tuple_all_flow_string, - (void *) &cmd_fc_add_ipv6_5tuple_all_add_string, - (void *) &cmd_fc_add_ipv6_5tuple_all_ipv6_5tuple_string, - (void *) &cmd_fc_add_ipv6_5tuple_all_all_string, - (void *) &cmd_fc_add_ipv6_5tuple_all_n_flows, - (void *) &cmd_fc_add_ipv6_5tuple_all_n_ports, - NULL, - }, -}; - -/* - * flow del qinq - */ -struct cmd_fc_del_qinq_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t del_string; - cmdline_fixed_string_t qinq_string; - uint16_t svlan; - uint16_t cvlan; -}; - -static void -cmd_fc_del_qinq_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fc_del_qinq_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fc_key key; - int status; - - memset(&key, 0, sizeof(key)); - key.type = FLOW_KEY_QINQ; - key.key.qinq.svlan = params->svlan; - key.key.qinq.cvlan = params->cvlan; - status = app_pipeline_fc_del(app, params->pipeline_id, &key); - - if (status != 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fc_del_qinq_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_qinq_result, p_string, "p"); - -cmdline_parse_token_num_t cmd_fc_del_qinq_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_qinq_result, pipeline_id, - UINT32); - -cmdline_parse_token_string_t cmd_fc_del_qinq_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_qinq_result, flow_string, - "flow"); - -cmdline_parse_token_string_t cmd_fc_del_qinq_del_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_qinq_result, del_string, - "del"); - -cmdline_parse_token_string_t cmd_fc_del_qinq_qinq_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_qinq_result, qinq_string, - "qinq"); - -cmdline_parse_token_num_t cmd_fc_del_qinq_svlan = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_qinq_result, svlan, UINT16); - -cmdline_parse_token_num_t cmd_fc_del_qinq_cvlan = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_qinq_result, cvlan, UINT16); - -cmdline_parse_inst_t cmd_fc_del_qinq = { - .f = cmd_fc_del_qinq_parsed, - .data = NULL, - .help_str = "Flow delete (Q-in-Q)", - .tokens = { - (void *) &cmd_fc_del_qinq_p_string, - (void *) &cmd_fc_del_qinq_pipeline_id, - (void *) &cmd_fc_del_qinq_flow_string, - (void *) &cmd_fc_del_qinq_del_string, - (void *) &cmd_fc_del_qinq_qinq_string, - (void *) &cmd_fc_del_qinq_svlan, - (void *) &cmd_fc_del_qinq_cvlan, - NULL, - }, -}; - -/* - * flow del ipv4_5tuple - */ - -struct cmd_fc_del_ipv4_5tuple_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t del_string; - cmdline_fixed_string_t ipv4_5tuple_string; - cmdline_ipaddr_t ip_src; - cmdline_ipaddr_t ip_dst; - uint16_t port_src; - uint16_t port_dst; - uint32_t proto; -}; - -static void -cmd_fc_del_ipv4_5tuple_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fc_del_ipv4_5tuple_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fc_key key; - int status; - - memset(&key, 0, sizeof(key)); - key.type = FLOW_KEY_IPV4_5TUPLE; - key.key.ipv4_5tuple.ip_src = rte_bswap32( - params->ip_src.addr.ipv4.s_addr); - key.key.ipv4_5tuple.ip_dst = rte_bswap32( - params->ip_dst.addr.ipv4.s_addr); - key.key.ipv4_5tuple.port_src = params->port_src; - key.key.ipv4_5tuple.port_dst = params->port_dst; - key.key.ipv4_5tuple.proto = params->proto; - - status = app_pipeline_fc_del(app, params->pipeline_id, &key); - if (status != 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fc_del_ipv4_5tuple_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_ipv4_5tuple_result, - p_string, "p"); -cmdline_parse_token_num_t cmd_fc_del_ipv4_5tuple_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_ipv4_5tuple_result, - pipeline_id, UINT32); + status = app_pipeline_fc_ls(app, results->pipeline_id); + if (status) + printf(CMD_MSG_FAIL, "flow ls"); -cmdline_parse_token_string_t cmd_fc_del_ipv4_5tuple_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_ipv4_5tuple_result, - flow_string, "flow"); - -cmdline_parse_token_string_t cmd_fc_del_ipv4_5tuple_del_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_ipv4_5tuple_result, - del_string, "del"); - -cmdline_parse_token_string_t cmd_fc_del_ipv4_5tuple_ipv4_5tuple_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_ipv4_5tuple_result, - ipv4_5tuple_string, "ipv4_5tuple"); - -cmdline_parse_token_ipaddr_t cmd_fc_del_ipv4_5tuple_ip_src = - TOKEN_IPV4_INITIALIZER(struct cmd_fc_del_ipv4_5tuple_result, - ip_src); - -cmdline_parse_token_ipaddr_t cmd_fc_del_ipv4_5tuple_ip_dst = - TOKEN_IPV4_INITIALIZER(struct cmd_fc_del_ipv4_5tuple_result, ip_dst); - -cmdline_parse_token_num_t cmd_fc_del_ipv4_5tuple_port_src = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_ipv4_5tuple_result, - port_src, UINT16); - -cmdline_parse_token_num_t cmd_fc_del_ipv4_5tuple_port_dst = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_ipv4_5tuple_result, - port_dst, UINT16); - -cmdline_parse_token_num_t cmd_fc_del_ipv4_5tuple_proto = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_ipv4_5tuple_result, - proto, UINT32); - -cmdline_parse_inst_t cmd_fc_del_ipv4_5tuple = { - .f = cmd_fc_del_ipv4_5tuple_parsed, - .data = NULL, - .help_str = "Flow delete (IPv4 5-tuple)", - .tokens = { - (void *) &cmd_fc_del_ipv4_5tuple_p_string, - (void *) &cmd_fc_del_ipv4_5tuple_pipeline_id, - (void *) &cmd_fc_del_ipv4_5tuple_flow_string, - (void *) &cmd_fc_del_ipv4_5tuple_del_string, - (void *) &cmd_fc_del_ipv4_5tuple_ipv4_5tuple_string, - (void *) &cmd_fc_del_ipv4_5tuple_ip_src, - (void *) &cmd_fc_del_ipv4_5tuple_ip_dst, - (void *) &cmd_fc_del_ipv4_5tuple_port_src, - (void *) &cmd_fc_del_ipv4_5tuple_port_dst, - (void *) &cmd_fc_del_ipv4_5tuple_proto, - NULL, - }, -}; - -/* - * flow del ipv6_5tuple - */ - -struct cmd_fc_del_ipv6_5tuple_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t del_string; - cmdline_fixed_string_t ipv6_5tuple_string; - cmdline_ipaddr_t ip_src; - cmdline_ipaddr_t ip_dst; - uint16_t port_src; - uint16_t port_dst; - uint32_t proto; -}; - -static void -cmd_fc_del_ipv6_5tuple_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fc_del_ipv6_5tuple_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_fc_key key; - int status; - - memset(&key, 0, sizeof(key)); - key.type = FLOW_KEY_IPV6_5TUPLE; - memcpy(key.key.ipv6_5tuple.ip_src, - params->ip_src.addr.ipv6.s6_addr, - 16); - memcpy(key.key.ipv6_5tuple.ip_dst, - params->ip_dst.addr.ipv6.s6_addr, - 16); - key.key.ipv6_5tuple.port_src = params->port_src; - key.key.ipv6_5tuple.port_dst = params->port_dst; - key.key.ipv6_5tuple.proto = params->proto; - - status = app_pipeline_fc_del(app, params->pipeline_id, &key); - if (status != 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fc_del_ipv6_5tuple_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_ipv6_5tuple_result, - p_string, "p"); - -cmdline_parse_token_num_t cmd_fc_del_ipv6_5tuple_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_ipv6_5tuple_result, - pipeline_id, UINT32); - -cmdline_parse_token_string_t cmd_fc_del_ipv6_5tuple_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_ipv6_5tuple_result, - flow_string, "flow"); - -cmdline_parse_token_string_t cmd_fc_del_ipv6_5tuple_del_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_ipv6_5tuple_result, - del_string, "del"); - -cmdline_parse_token_string_t cmd_fc_del_ipv6_5tuple_ipv6_5tuple_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_ipv6_5tuple_result, - ipv6_5tuple_string, "ipv6_5tuple"); - -cmdline_parse_token_ipaddr_t cmd_fc_del_ipv6_5tuple_ip_src = - TOKEN_IPV6_INITIALIZER(struct cmd_fc_del_ipv6_5tuple_result, ip_src); - -cmdline_parse_token_ipaddr_t cmd_fc_del_ipv6_5tuple_ip_dst = - TOKEN_IPV6_INITIALIZER(struct cmd_fc_del_ipv6_5tuple_result, ip_dst); - -cmdline_parse_token_num_t cmd_fc_del_ipv6_5tuple_port_src = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_ipv6_5tuple_result, port_src, - UINT16); - -cmdline_parse_token_num_t cmd_fc_del_ipv6_5tuple_port_dst = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_ipv6_5tuple_result, port_dst, - UINT16); - -cmdline_parse_token_num_t cmd_fc_del_ipv6_5tuple_proto = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_ipv6_5tuple_result, proto, - UINT32); - -cmdline_parse_inst_t cmd_fc_del_ipv6_5tuple = { - .f = cmd_fc_del_ipv6_5tuple_parsed, - .data = NULL, - .help_str = "Flow delete (IPv6 5-tuple)", - .tokens = { - (void *) &cmd_fc_del_ipv6_5tuple_p_string, - (void *) &cmd_fc_del_ipv6_5tuple_pipeline_id, - (void *) &cmd_fc_del_ipv6_5tuple_flow_string, - (void *) &cmd_fc_del_ipv6_5tuple_del_string, - (void *) &cmd_fc_del_ipv6_5tuple_ipv6_5tuple_string, - (void *) &cmd_fc_del_ipv6_5tuple_ip_src, - (void *) &cmd_fc_del_ipv6_5tuple_ip_dst, - (void *) &cmd_fc_del_ipv6_5tuple_port_src, - (void *) &cmd_fc_del_ipv6_5tuple_port_dst, - (void *) &cmd_fc_del_ipv6_5tuple_proto, - NULL, - }, -}; - -/* - * flow add default - */ - -struct cmd_fc_add_default_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t default_string; - uint32_t port; -}; - -static void -cmd_fc_add_default_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fc_add_default_result *params = parsed_result; - struct app_params *app = data; - int status; - - status = app_pipeline_fc_add_default(app, params->pipeline_id, - params->port); - - if (status != 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fc_add_default_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_default_result, p_string, - "p"); - -cmdline_parse_token_num_t cmd_fc_add_default_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_default_result, pipeline_id, - UINT32); - -cmdline_parse_token_string_t cmd_fc_add_default_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_default_result, flow_string, - "flow"); - -cmdline_parse_token_string_t cmd_fc_add_default_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_default_result, add_string, - "add"); - -cmdline_parse_token_string_t cmd_fc_add_default_default_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_add_default_result, - default_string, "default"); - -cmdline_parse_token_num_t cmd_fc_add_default_port = - TOKEN_NUM_INITIALIZER(struct cmd_fc_add_default_result, port, UINT32); - -cmdline_parse_inst_t cmd_fc_add_default = { - .f = cmd_fc_add_default_parsed, - .data = NULL, - .help_str = "Flow add default", - .tokens = { - (void *) &cmd_fc_add_default_p_string, - (void *) &cmd_fc_add_default_pipeline_id, - (void *) &cmd_fc_add_default_flow_string, - (void *) &cmd_fc_add_default_add_string, - (void *) &cmd_fc_add_default_default_string, - (void *) &cmd_fc_add_default_port, - NULL, - }, -}; - -/* - * flow del default - */ - -struct cmd_fc_del_default_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t del_string; - cmdline_fixed_string_t default_string; -}; - -static void -cmd_fc_del_default_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_fc_del_default_result *params = parsed_result; - struct app_params *app = data; - int status; - - status = app_pipeline_fc_del_default(app, params->pipeline_id); - if (status != 0) - printf("Command failed\n"); -} - -cmdline_parse_token_string_t cmd_fc_del_default_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_default_result, p_string, - "p"); - -cmdline_parse_token_num_t cmd_fc_del_default_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_del_default_result, pipeline_id, - UINT32); - -cmdline_parse_token_string_t cmd_fc_del_default_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_default_result, flow_string, - "flow"); - -cmdline_parse_token_string_t cmd_fc_del_default_del_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_default_result, del_string, - "del"); - -cmdline_parse_token_string_t cmd_fc_del_default_default_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_del_default_result, - default_string, "default"); - -cmdline_parse_inst_t cmd_fc_del_default = { - .f = cmd_fc_del_default_parsed, - .data = NULL, - .help_str = "Flow delete default", - .tokens = { - (void *) &cmd_fc_del_default_p_string, - (void *) &cmd_fc_del_default_pipeline_id, - (void *) &cmd_fc_del_default_flow_string, - (void *) &cmd_fc_del_default_del_string, - (void *) &cmd_fc_del_default_default_string, - NULL, - }, -}; - -/* - * flow ls - */ - -struct cmd_fc_ls_result { - cmdline_fixed_string_t p_string; - uint32_t pipeline_id; - cmdline_fixed_string_t flow_string; - cmdline_fixed_string_t ls_string; -}; - -static void -cmd_fc_ls_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct cmd_fc_ls_result *params = parsed_result; - struct app_params *app = data; - int status; + return; + } /* flow ls */ - status = app_pipeline_fc_ls(app, params->pipeline_id); - if (status != 0) - printf("Command failed\n"); + printf(CMD_MSG_MISMATCH_ARGS, "flow"); } -cmdline_parse_token_string_t cmd_fc_ls_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_ls_result, p_string, "p"); +static cmdline_parse_token_string_t cmd_flow_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_flow_result, p_string, "p"); -cmdline_parse_token_num_t cmd_fc_ls_pipeline_id = - TOKEN_NUM_INITIALIZER(struct cmd_fc_ls_result, pipeline_id, UINT32); +static cmdline_parse_token_num_t cmd_flow_pipeline_id = + TOKEN_NUM_INITIALIZER(struct cmd_flow_result, pipeline_id, UINT32); -cmdline_parse_token_string_t cmd_fc_ls_flow_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_ls_result, - flow_string, "flow"); +static cmdline_parse_token_string_t cmd_flow_flow_string = + TOKEN_STRING_INITIALIZER(struct cmd_flow_result, flow_string, "flow"); -cmdline_parse_token_string_t cmd_fc_ls_ls_string = - TOKEN_STRING_INITIALIZER(struct cmd_fc_ls_result, ls_string, - "ls"); +static cmdline_parse_token_string_t cmd_flow_multi_string = + TOKEN_STRING_INITIALIZER(struct cmd_flow_result, multi_string, + TOKEN_STRING_MULTI); -cmdline_parse_inst_t cmd_fc_ls = { - .f = cmd_fc_ls_parsed, +static cmdline_parse_inst_t cmd_flow = { + .f = cmd_flow_parsed, .data = NULL, - .help_str = "Flow list", + .help_str = "flow add / add bulk / add default / del / del default / ls", .tokens = { - (void *) &cmd_fc_ls_p_string, - (void *) &cmd_fc_ls_pipeline_id, - (void *) &cmd_fc_ls_flow_string, - (void *) &cmd_fc_ls_ls_string, + (void *) &cmd_flow_p_string, + (void *) &cmd_flow_pipeline_id, + (void *) &cmd_flow_flow_string, + (void *) &cmd_flow_multi_string, NULL, }, }; static cmdline_parse_ctx_t pipeline_cmds[] = { - (cmdline_parse_inst_t *) &cmd_fc_add_qinq, - (cmdline_parse_inst_t *) &cmd_fc_add_ipv4_5tuple, - (cmdline_parse_inst_t *) &cmd_fc_add_ipv6_5tuple, - - (cmdline_parse_inst_t *) &cmd_fc_del_qinq, - (cmdline_parse_inst_t *) &cmd_fc_del_ipv4_5tuple, - (cmdline_parse_inst_t *) &cmd_fc_del_ipv6_5tuple, - - (cmdline_parse_inst_t *) &cmd_fc_add_default, - (cmdline_parse_inst_t *) &cmd_fc_del_default, - - (cmdline_parse_inst_t *) &cmd_fc_add_qinq_all, - (cmdline_parse_inst_t *) &cmd_fc_add_ipv4_5tuple_all, - (cmdline_parse_inst_t *) &cmd_fc_add_ipv6_5tuple_all, - - (cmdline_parse_inst_t *) &cmd_fc_ls, + (cmdline_parse_inst_t *) &cmd_flow, NULL, }; static struct pipeline_fe_ops pipeline_flow_classification_fe_ops = { .f_init = app_pipeline_fc_init, + .f_post_init = NULL, .f_free = app_pipeline_fc_free, + .f_track = app_pipeline_track_default, .cmds = pipeline_cmds, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_flow_classification.h b/examples/ip_pipeline/pipeline/pipeline_flow_classification.h index 9c775006..6c5ed384 100644 --- a/examples/ip_pipeline/pipeline/pipeline_flow_classification.h +++ b/examples/ip_pipeline/pipeline/pipeline_flow_classification.h @@ -102,6 +102,34 @@ int app_pipeline_fc_del_default(struct app_params *app, uint32_t pipeline_id); +#ifndef APP_PIPELINE_FC_MAX_FLOWS_IN_FILE +#define APP_PIPELINE_FC_MAX_FLOWS_IN_FILE (16 * 1024 * 1024) +#endif + +int +app_pipeline_fc_load_file_qinq(char *filename, + struct pipeline_fc_key *keys, + uint32_t *port_ids, + uint32_t *flow_ids, + uint32_t *n_keys, + uint32_t *line); + +int +app_pipeline_fc_load_file_ipv4(char *filename, + struct pipeline_fc_key *keys, + uint32_t *port_ids, + uint32_t *flow_ids, + uint32_t *n_keys, + uint32_t *line); + +int +app_pipeline_fc_load_file_ipv6(char *filename, + struct pipeline_fc_key *keys, + uint32_t *port_ids, + uint32_t *flow_ids, + uint32_t *n_keys, + uint32_t *line); + extern struct pipeline_type pipeline_flow_classification; #endif diff --git a/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c b/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c index 70d976d5..8a762bc7 100644 --- a/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c +++ b/examples/ip_pipeline/pipeline/pipeline_flow_classification_be.c @@ -642,27 +642,6 @@ pipeline_fc_free(void *pipeline) return 0; } -static int -pipeline_fc_track(void *pipeline, - __rte_unused uint32_t port_in, - uint32_t *port_out) -{ - struct pipeline *p = (struct pipeline *) pipeline; - - /* Check input arguments */ - if ((p == NULL) || - (port_in >= p->n_ports_in) || - (port_out == NULL)) - return -1; - - if (p->n_ports_in == 1) { - *port_out = 0; - return 0; - } - - return -1; -} - static int pipeline_fc_timer(void *pipeline) { @@ -807,5 +786,4 @@ struct pipeline_be_ops pipeline_flow_classification_be_ops = { .f_free = pipeline_fc_free, .f_run = NULL, .f_timer = pipeline_fc_timer, - .f_track = pipeline_fc_track, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_master.c b/examples/ip_pipeline/pipeline/pipeline_master.c index 1ccdad14..aab58a27 100644 --- a/examples/ip_pipeline/pipeline/pipeline_master.c +++ b/examples/ip_pipeline/pipeline/pipeline_master.c @@ -36,7 +36,9 @@ static struct pipeline_fe_ops pipeline_master_fe_ops = { .f_init = NULL, + .f_post_init = NULL, .f_free = NULL, + .f_track = NULL, .cmds = NULL, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_master_be.c b/examples/ip_pipeline/pipeline/pipeline_master_be.c index ac0cbbc5..9a7c8c13 100644 --- a/examples/ip_pipeline/pipeline/pipeline_master_be.c +++ b/examples/ip_pipeline/pipeline/pipeline_master_be.c @@ -48,6 +48,7 @@ struct pipeline_master { struct app_params *app; struct cmdline *cl; + int post_init_done; int script_file_done; } __rte_cache_aligned; @@ -77,6 +78,7 @@ pipeline_init(__rte_unused struct pipeline_params *params, void *arg) return NULL; } + p->post_init_done = 0; p->script_file_done = 0; if (app->script_file == NULL) p->script_file_done = 1; @@ -102,8 +104,20 @@ static int pipeline_run(void *pipeline) { struct pipeline_master *p = (struct pipeline_master *) pipeline; + struct app_params *app = p->app; int status; +#ifdef RTE_LIBRTE_KNI + uint32_t i; +#endif /* RTE_LIBRTE_KNI */ + /* Application post-init phase */ + if (p->post_init_done == 0) { + app_post_init(app); + + p->post_init_done = 1; + } + + /* Run startup script file */ if (p->script_file_done == 0) { struct app_params *app = p->app; int fd = open(app->script_file, O_RDONLY); @@ -124,6 +138,7 @@ pipeline_run(void *pipeline) p->script_file_done = 1; } + /* Command Line Interface (CLI) */ status = cmdline_poll(p->cl); if (status < 0) rte_panic("CLI poll error (%" PRId32 ")\n", status); @@ -132,6 +147,12 @@ pipeline_run(void *pipeline) rte_exit(0, "Bye!\n"); } +#ifdef RTE_LIBRTE_KNI + /* Handle KNI requests from Linux kernel */ + for (i = 0; i < app->n_pktq_kni; i++) + rte_kni_handle_request(app->kni[i]); +#endif /* RTE_LIBRTE_KNI */ + return 0; } @@ -146,5 +167,4 @@ struct pipeline_be_ops pipeline_master_be_ops = { .f_free = pipeline_free, .f_run = pipeline_run, .f_timer = pipeline_timer, - .f_track = NULL, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_passthrough.c b/examples/ip_pipeline/pipeline/pipeline_passthrough.c index fc2cae5e..63ce1472 100644 --- a/examples/ip_pipeline/pipeline/pipeline_passthrough.c +++ b/examples/ip_pipeline/pipeline/pipeline_passthrough.c @@ -34,9 +34,36 @@ #include "pipeline_passthrough.h" #include "pipeline_passthrough_be.h" +static int +app_pipeline_passthrough_track(struct pipeline_params *p, + uint32_t port_in, + uint32_t *port_out) +{ + struct pipeline_passthrough_params pp; + int status; + + /* Check input arguments */ + if ((p == NULL) || + (port_in >= p->n_ports_in) || + (port_out == NULL)) + return -1; + + status = pipeline_passthrough_parse_args(&pp, p); + if (status) + return -1; + + if (pp.lb_hash_enabled) + return -1; + + *port_out = port_in / (p->n_ports_in / p->n_ports_out); + return 0; +} + static struct pipeline_fe_ops pipeline_passthrough_fe_ops = { .f_init = NULL, + .f_post_init = NULL, .f_free = NULL, + .f_track = app_pipeline_passthrough_track, .cmds = NULL, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_passthrough_be.c b/examples/ip_pipeline/pipeline/pipeline_passthrough_be.c index a0d11aea..6146a28f 100644 --- a/examples/ip_pipeline/pipeline/pipeline_passthrough_be.c +++ b/examples/ip_pipeline/pipeline/pipeline_passthrough_be.c @@ -547,6 +547,18 @@ pipeline_passthrough_parse_args(struct pipeline_passthrough_params *p, "dma_src_mask", dma_mask_str); } + if (p->lb_hash_enabled) + PIPELINE_ARG_CHECK((params->n_ports_out > 1), + "Parse error in section \"%s\": entry \"lb\" not " + "allowed for single output port pipeline", + params->name); + else + PIPELINE_ARG_CHECK(((params->n_ports_in >= params->n_ports_out) + && ((params->n_ports_in % params->n_ports_out) == 0)), + "Parse error in section \"%s\": n_ports_in needs to be " + "a multiple of n_ports_out (lb mode disabled)", + params->name); + return 0; } @@ -579,9 +591,7 @@ pipeline_passthrough_init(struct pipeline_params *params, /* Check input arguments */ if ((params == NULL) || (params->n_ports_in == 0) || - (params->n_ports_out == 0) || - (params->n_ports_in < params->n_ports_out) || - (params->n_ports_in % params->n_ports_out)) + (params->n_ports_out == 0)) return NULL; /* Memory allocation */ @@ -702,10 +712,13 @@ pipeline_passthrough_init(struct pipeline_params *params, /* Add entries to tables */ for (i = 0; i < p->n_ports_in; i++) { + uint32_t port_out_id = (p_pt->params.lb_hash_enabled == 0) ? + (i / (p->n_ports_in / p->n_ports_out)) : + 0; + struct rte_pipeline_table_entry default_entry = { .action = RTE_PIPELINE_ACTION_PORT, - {.port_id = p->port_out_id[ - i / (p->n_ports_in / p->n_ports_out)]}, + {.port_id = p->port_out_id[port_out_id]}, }; struct rte_pipeline_table_entry *default_entry_ptr; @@ -780,25 +793,9 @@ pipeline_passthrough_timer(void *pipeline) return 0; } -static int -pipeline_passthrough_track(void *pipeline, uint32_t port_in, uint32_t *port_out) -{ - struct pipeline *p = (struct pipeline *) pipeline; - - /* Check input arguments */ - if ((p == NULL) || - (port_in >= p->n_ports_in) || - (port_out == NULL)) - return -1; - - *port_out = port_in / p->n_ports_in; - return 0; -} - struct pipeline_be_ops pipeline_passthrough_be_ops = { .f_init = pipeline_passthrough_init, .f_free = pipeline_passthrough_free, .f_run = NULL, .f_timer = pipeline_passthrough_timer, - .f_track = pipeline_passthrough_track, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_routing.c b/examples/ip_pipeline/pipeline/pipeline_routing.c index eab89f2e..3aadbf91 100644 --- a/examples/ip_pipeline/pipeline/pipeline_routing.c +++ b/examples/ip_pipeline/pipeline/pipeline_routing.c @@ -1,7 +1,7 @@ /*- * BSD LICENSE * - * Copyright(c) 2010-2015 Intel Corporation. All rights reserved. + * Copyright(c) 2010-2016 Intel Corporation. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -34,12 +34,11 @@ #include #include #include -#include -#include #include "app.h" #include "pipeline_common_fe.h" #include "pipeline_routing.h" +#include "parser.h" struct app_pipeline_routing_route { struct pipeline_routing_route_key key; @@ -59,8 +58,14 @@ struct app_pipeline_routing_arp_entry { struct pipeline_routing { /* Parameters */ + struct app_params *app; + uint32_t pipeline_id; uint32_t n_ports_in; uint32_t n_ports_out; + struct pipeline_routing_params rp; + + /* Links */ + uint32_t link_id[PIPELINE_MAX_PORT_OUT]; /* Routes */ TAILQ_HEAD(, app_pipeline_routing_route) routes; @@ -79,12 +84,151 @@ struct pipeline_routing { void *default_arp_entry_ptr; }; +static int +app_pipeline_routing_find_link(struct pipeline_routing *p, + uint32_t link_id, + uint32_t *port_id) +{ + uint32_t i; + + for (i = 0; i < p->n_ports_out; i++) + if (p->link_id[i] == link_id) { + *port_id = i; + return 0; + } + + return -1; +} + +static void +app_pipeline_routing_link_op(__rte_unused struct app_params *app, + uint32_t link_id, + uint32_t up, + void *arg) +{ + struct pipeline_routing_route_key key0, key1; + struct pipeline_routing *p = arg; + struct app_link_params *lp; + uint32_t port_id, netmask; + int status; + + if (app == NULL) + return; + + APP_PARAM_FIND_BY_ID(app->link_params, "LINK", link_id, lp); + if (lp == NULL) + return; + + status = app_pipeline_routing_find_link(p, + link_id, + &port_id); + if (status) + return; + + netmask = (~0U) << (32 - lp->depth); + + /* Local network (directly attached network) */ + key0.type = PIPELINE_ROUTING_ROUTE_IPV4; + key0.key.ipv4.ip = lp->ip & netmask; + key0.key.ipv4.depth = lp->depth; + + /* Local termination */ + key1.type = PIPELINE_ROUTING_ROUTE_IPV4; + key1.key.ipv4.ip = lp->ip; + key1.key.ipv4.depth = 32; + + if (up) { + struct pipeline_routing_route_data data0, data1; + + /* Local network (directly attached network) */ + memset(&data0, 0, sizeof(data0)); + data0.flags = PIPELINE_ROUTING_ROUTE_LOCAL | + PIPELINE_ROUTING_ROUTE_ARP; + if (p->rp.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_QINQ) + data0.flags |= PIPELINE_ROUTING_ROUTE_QINQ; + if (p->rp.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_MPLS) { + data0.flags |= PIPELINE_ROUTING_ROUTE_MPLS; + data0.l2.mpls.n_labels = 1; + } + data0.port_id = port_id; + + if (p->rp.n_arp_entries) + app_pipeline_routing_add_route(app, + p->pipeline_id, + &key0, + &data0); + + /* Local termination */ + memset(&data1, 0, sizeof(data1)); + data1.flags = PIPELINE_ROUTING_ROUTE_LOCAL | + PIPELINE_ROUTING_ROUTE_ARP; + if (p->rp.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_QINQ) + data1.flags |= PIPELINE_ROUTING_ROUTE_QINQ; + if (p->rp.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_MPLS) { + data1.flags |= PIPELINE_ROUTING_ROUTE_MPLS; + data1.l2.mpls.n_labels = 1; + } + data1.port_id = p->rp.port_local_dest; + + app_pipeline_routing_add_route(app, + p->pipeline_id, + &key1, + &data1); + } else { + /* Local network (directly attached network) */ + if (p->rp.n_arp_entries) + app_pipeline_routing_delete_route(app, + p->pipeline_id, + &key0); + + /* Local termination */ + app_pipeline_routing_delete_route(app, + p->pipeline_id, + &key1); + } +} + +static int +app_pipeline_routing_set_link_op( + struct app_params *app, + struct pipeline_routing *p) +{ + uint32_t port_id; + + for (port_id = 0; port_id < p->n_ports_out; port_id++) { + struct app_link_params *link; + uint32_t link_id; + int status; + + link = app_pipeline_track_pktq_out_to_link(app, + p->pipeline_id, + port_id); + if (link == NULL) + continue; + + link_id = link - app->link_params; + p->link_id[port_id] = link_id; + + status = app_link_set_op(app, + link_id, + p->pipeline_id, + app_pipeline_routing_link_op, + (void *) p); + if (status) + return status; + } + + return 0; +} + static void * -pipeline_routing_init(struct pipeline_params *params, - __rte_unused void *arg) +app_pipeline_routing_init(struct pipeline_params *params, + void *arg) { + struct app_params *app = (struct app_params *) arg; struct pipeline_routing *p; - uint32_t size; + uint32_t pipeline_id, size; + int status; /* Check input arguments */ if ((params == NULL) || @@ -92,6 +236,8 @@ pipeline_routing_init(struct pipeline_params *params, (params->n_ports_out == 0)) return NULL; + APP_PARAM_GET_ID(params, "PIPELINE", pipeline_id); + /* Memory allocation */ size = RTE_CACHE_LINE_ROUNDUP(sizeof(struct pipeline_routing)); p = rte_zmalloc(NULL, size, RTE_CACHE_LINE_SIZE); @@ -99,18 +245,39 @@ pipeline_routing_init(struct pipeline_params *params, return NULL; /* Initialization */ + p->app = app; + p->pipeline_id = pipeline_id; p->n_ports_in = params->n_ports_in; p->n_ports_out = params->n_ports_out; + status = pipeline_routing_parse_args(&p->rp, params); + if (status) { + rte_free(p); + return NULL; + } TAILQ_INIT(&p->routes); p->n_routes = 0; TAILQ_INIT(&p->arp_entries); p->n_arp_entries = 0; + app_pipeline_routing_set_link_op(app, p); + return p; } +static int +app_pipeline_routing_post_init(void *pipeline) +{ + struct pipeline_routing *p = pipeline; + + /* Check input arguments */ + if (p == NULL) + return -1; + + return app_pipeline_routing_set_macaddr(p->app, p->pipeline_id); +} + static int app_pipeline_routing_free(void *pipeline) { @@ -198,7 +365,9 @@ print_route(const struct app_pipeline_routing_route *route) key->depth, route->data.port_id); - if (route->data.flags & PIPELINE_ROUTING_ROUTE_ARP) + if (route->data.flags & PIPELINE_ROUTING_ROUTE_LOCAL) + printf(", Local"); + else if (route->data.flags & PIPELINE_ROUTING_ROUTE_ARP) printf( ", Next Hop IP = %" PRIu32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32, @@ -383,8 +552,6 @@ app_pipeline_routing_add_route(struct app_params *app, p->n_routes++; } - print_route(entry); - /* Message buffer free */ app_msg_free(app, rsp); return 0; @@ -677,8 +844,6 @@ app_pipeline_routing_add_arp_entry(struct app_params *app, uint32_t pipeline_id, p->n_arp_entries++; } - print_arp_entry(entry); - /* Message buffer free */ app_msg_free(app, rsp); return 0; @@ -853,1382 +1018,600 @@ app_pipeline_routing_delete_default_arp_entry(struct app_params *app, return 0; } -static int -parse_labels(char *string, uint32_t *labels, uint32_t *n_labels) +int +app_pipeline_routing_set_macaddr(struct app_params *app, + uint32_t pipeline_id) { - uint32_t n_max_labels = *n_labels, count = 0; + struct app_pipeline_params *p; + struct pipeline_routing_set_macaddr_msg_req *req; + struct pipeline_routing_set_macaddr_msg_rsp *rsp; + uint32_t port_id; - /* Check for void list of labels */ - if (strcmp(string, "") == 0) { - *n_labels = 0; - return 0; - } + /* Check input arguments */ + if (app == NULL) + return -EINVAL; - /* At least one label should be present */ - for ( ; (*string != '\0'); ) { - char *next; - int value; + APP_PARAM_FIND_BY_ID(app->pipeline_params, "PIPELINE", pipeline_id, p); + if (p == NULL) + return -EINVAL; - if (count >= n_max_labels) - return -1; + /* Allocate and write request */ + req = app_msg_alloc(app); + if (req == NULL) + return -ENOMEM; - if (count > 0) { - if (string[0] != ':') - return -1; + req->type = PIPELINE_MSG_REQ_CUSTOM; + req->subtype = PIPELINE_ROUTING_MSG_REQ_SET_MACADDR; - string++; - } + memset(req->macaddr, 0, sizeof(req->macaddr)); + for (port_id = 0; port_id < p->n_pktq_out; port_id++) { + struct app_link_params *link; - value = strtol(string, &next, 10); - if (next == string) - return -1; - string = next; + link = app_pipeline_track_pktq_out_to_link(app, + pipeline_id, + port_id); + if (link) + req->macaddr[port_id] = link->mac_addr; + } - labels[count++] = (uint32_t) value; + /* Send request and wait for response */ + rsp = app_msg_send_recv(app, pipeline_id, req, MSG_TIMEOUT_DEFAULT); + if (rsp == NULL) + return -ETIMEDOUT; + + /* Read response and write entry */ + if (rsp->status) { + app_msg_free(app, rsp); + return rsp->status; } - *n_labels = count; + /* Free response */ + app_msg_free(app, rsp); + return 0; } /* - * route add (mpls = no, qinq = no, arp = no) + * route + * + * route add (ARP = ON/OFF, MPLS = ON/OFF, QINQ = ON/OFF): + * p route add port ether + * p route add port ether + * p route add port ether qinq + * p route add port ether qinq + * p route add port ether mpls + * p route add port ether mpls + * + * route add default: + * p route add default + * + * route del: + * p route del + * + * route del default: + * p route del default + * + * route ls: + * p route ls */ -struct cmd_route_add1_result { +struct cmd_route_result { cmdline_fixed_string_t p_string; uint32_t p; cmdline_fixed_string_t route_string; - cmdline_fixed_string_t add_string; - cmdline_ipaddr_t ip; - uint32_t depth; - cmdline_fixed_string_t port_string; - uint32_t port; - cmdline_fixed_string_t ether_string; - struct ether_addr macaddr; + cmdline_multi_string_t multi_string; }; static void -cmd_route_add1_parsed( +cmd_route_parsed( void *parsed_result, __rte_unused struct cmdline *cl, void *data) { - struct cmd_route_add1_result *params = parsed_result; + struct cmd_route_result *params = parsed_result; struct app_params *app = data; - struct pipeline_routing_route_key key; - struct pipeline_routing_route_data route_data; - int status; - /* Create route */ - key.type = PIPELINE_ROUTING_ROUTE_IPV4; - key.key.ipv4.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr); - key.key.ipv4.depth = params->depth; - - route_data.flags = 0; - route_data.port_id = params->port; - route_data.ethernet.macaddr = params->macaddr; - - status = app_pipeline_routing_add_route(app, - params->p, - &key, - &route_data); + char *tokens[16]; + uint32_t n_tokens = RTE_DIM(tokens); + int status; + status = parse_tokenize_string(params->multi_string, tokens, &n_tokens); if (status != 0) { - printf("Command failed\n"); + printf(CMD_MSG_TOO_MANY_ARGS, "route"); return; } -} -static cmdline_parse_token_string_t cmd_route_add1_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add1_result, p_string, - "p"); + /* route add */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "add") == 0) && + strcmp(tokens[1], "default")) { + struct pipeline_routing_route_key key; + struct pipeline_routing_route_data route_data; + struct in_addr ipv4, nh_ipv4; + struct ether_addr mac_addr; + uint32_t depth, port_id, svlan, cvlan, i; + uint32_t mpls_labels[PIPELINE_ROUTING_MPLS_LABELS_MAX]; + uint32_t n_labels = RTE_DIM(mpls_labels); + + memset(&key, 0, sizeof(key)); + memset(&route_data, 0, sizeof(route_data)); + + if (n_tokens < 7) { + printf(CMD_MSG_NOT_ENOUGH_ARGS, "route add"); + return; + } -static cmdline_parse_token_num_t cmd_route_add1_p = - TOKEN_NUM_INITIALIZER(struct cmd_route_add1_result, p, UINT32); + if (parse_ipv4_addr(tokens[1], &ipv4)) { + printf(CMD_MSG_INVALID_ARG, "ipaddr"); + return; + } -static cmdline_parse_token_string_t cmd_route_add1_route_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add1_result, route_string, - "route"); + if (parser_read_uint32(&depth, tokens[2])) { + printf(CMD_MSG_INVALID_ARG, "depth"); + return; + } -static cmdline_parse_token_string_t cmd_route_add1_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add1_result, add_string, - "add"); + if (strcmp(tokens[3], "port")) { + printf(CMD_MSG_ARG_NOT_FOUND, "port"); + return; + } -static cmdline_parse_token_ipaddr_t cmd_route_add1_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_route_add1_result, ip); + if (parser_read_uint32(&port_id, tokens[4])) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } -static cmdline_parse_token_num_t cmd_route_add1_depth = - TOKEN_NUM_INITIALIZER(struct cmd_route_add1_result, depth, UINT32); + if (strcmp(tokens[5], "ether")) { + printf(CMD_MSG_ARG_NOT_FOUND, "ether"); + return; + } -static cmdline_parse_token_string_t cmd_route_add1_port_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add1_result, port_string, - "port"); + if (parse_mac_addr(tokens[6], &mac_addr)) { + if (parse_ipv4_addr(tokens[6], &nh_ipv4)) { + printf(CMD_MSG_INVALID_ARG, "nhmacaddr or nhipaddr"); + return; + } -static cmdline_parse_token_num_t cmd_route_add1_port = - TOKEN_NUM_INITIALIZER(struct cmd_route_add1_result, port, UINT32); + route_data.flags |= PIPELINE_ROUTING_ROUTE_ARP; + } -static cmdline_parse_token_string_t cmd_route_add1_ether_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add1_result, ether_string, - "ether"); + if (n_tokens > 7) { + if (strcmp(tokens[7], "mpls") == 0) { + if (n_tokens != 9) { + printf(CMD_MSG_MISMATCH_ARGS, "route add mpls"); + return; + } + + if (parse_mpls_labels(tokens[8], mpls_labels, &n_labels)) { + printf(CMD_MSG_INVALID_ARG, "mpls labels"); + return; + } + + route_data.flags |= PIPELINE_ROUTING_ROUTE_MPLS; + } else if (strcmp(tokens[7], "qinq") == 0) { + if (n_tokens != 10) { + printf(CMD_MSG_MISMATCH_ARGS, "route add qinq"); + return; + } + + if (parser_read_uint32(&svlan, tokens[8])) { + printf(CMD_MSG_INVALID_ARG, "svlan"); + return; + } + if (parser_read_uint32(&cvlan, tokens[9])) { + printf(CMD_MSG_INVALID_ARG, "cvlan"); + return; + } + + route_data.flags |= PIPELINE_ROUTING_ROUTE_QINQ; + } else { + printf(CMD_MSG_ARG_NOT_FOUND, "mpls or qinq"); + return; + } + } -static cmdline_parse_token_etheraddr_t cmd_route_add1_macaddr = - TOKEN_ETHERADDR_INITIALIZER(struct cmd_route_add1_result, macaddr); + switch (route_data.flags) { + case 0: + route_data.port_id = port_id; + route_data.ethernet.macaddr = mac_addr; + break; -static cmdline_parse_inst_t cmd_route_add1 = { - .f = cmd_route_add1_parsed, - .data = NULL, - .help_str = "Route add (mpls = no, qinq = no, arp = no)", - .tokens = { - (void *)&cmd_route_add1_p_string, - (void *)&cmd_route_add1_p, - (void *)&cmd_route_add1_route_string, - (void *)&cmd_route_add1_add_string, - (void *)&cmd_route_add1_ip, - (void *)&cmd_route_add1_depth, - (void *)&cmd_route_add1_port_string, - (void *)&cmd_route_add1_port, - (void *)&cmd_route_add1_ether_string, - (void *)&cmd_route_add1_macaddr, - NULL, - }, -}; + case PIPELINE_ROUTING_ROUTE_ARP: + route_data.port_id = port_id; + route_data.ethernet.ip = rte_be_to_cpu_32(nh_ipv4.s_addr); + break; -/* - * route add (mpls = no, qinq = no, arp = yes) - */ + case PIPELINE_ROUTING_ROUTE_MPLS: + route_data.port_id = port_id; + route_data.ethernet.macaddr = mac_addr; + for (i = 0; i < n_labels; i++) + route_data.l2.mpls.labels[i] = mpls_labels[i]; + route_data.l2.mpls.n_labels = n_labels; + break; -struct cmd_route_add2_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t route_string; - cmdline_fixed_string_t add_string; - cmdline_ipaddr_t ip; - uint32_t depth; - cmdline_fixed_string_t port_string; - uint32_t port; - cmdline_fixed_string_t ether_string; - cmdline_ipaddr_t nh_ip; -}; + case PIPELINE_ROUTING_ROUTE_MPLS | PIPELINE_ROUTING_ROUTE_ARP: + route_data.port_id = port_id; + route_data.ethernet.ip = rte_be_to_cpu_32(nh_ipv4.s_addr); + for (i = 0; i < n_labels; i++) + route_data.l2.mpls.labels[i] = mpls_labels[i]; + route_data.l2.mpls.n_labels = n_labels; + break; -static void -cmd_route_add2_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_route_add2_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_routing_route_key key; - struct pipeline_routing_route_data route_data; - int status; + case PIPELINE_ROUTING_ROUTE_QINQ: + route_data.port_id = port_id; + route_data.ethernet.macaddr = mac_addr; + route_data.l2.qinq.svlan = svlan; + route_data.l2.qinq.cvlan = cvlan; + break; - /* Create route */ - key.type = PIPELINE_ROUTING_ROUTE_IPV4; - key.key.ipv4.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr); - key.key.ipv4.depth = params->depth; + case PIPELINE_ROUTING_ROUTE_QINQ | PIPELINE_ROUTING_ROUTE_ARP: + default: + route_data.port_id = port_id; + route_data.ethernet.ip = rte_be_to_cpu_32(nh_ipv4.s_addr); + route_data.l2.qinq.svlan = svlan; + route_data.l2.qinq.cvlan = cvlan; + break; + } - route_data.flags = PIPELINE_ROUTING_ROUTE_ARP; - route_data.port_id = params->port; - route_data.ethernet.ip = - rte_bswap32((uint32_t) params->nh_ip.addr.ipv4.s_addr); + key.type = PIPELINE_ROUTING_ROUTE_IPV4; + key.key.ipv4.ip = rte_be_to_cpu_32(ipv4.s_addr); + key.key.ipv4.depth = depth; - status = app_pipeline_routing_add_route(app, - params->p, - &key, - &route_data); + status = app_pipeline_routing_add_route(app, + params->p, + &key, + &route_data); + if (status != 0) + printf(CMD_MSG_FAIL, "route add"); - if (status != 0) { - printf("Command failed\n"); return; - } -} - -static cmdline_parse_token_string_t cmd_route_add2_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add2_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_route_add2_p = - TOKEN_NUM_INITIALIZER(struct cmd_route_add2_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_route_add2_route_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add2_result, route_string, - "route"); + } /* route add */ -static cmdline_parse_token_string_t cmd_route_add2_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add2_result, add_string, - "add"); + /* route add default */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "default") == 0)) { + uint32_t port_id; -static cmdline_parse_token_ipaddr_t cmd_route_add2_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_route_add2_result, ip); - -static cmdline_parse_token_num_t cmd_route_add2_depth = - TOKEN_NUM_INITIALIZER(struct cmd_route_add2_result, depth, UINT32); - -static cmdline_parse_token_string_t cmd_route_add2_port_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add2_result, port_string, - "port"); + if (n_tokens != 3) { + printf(CMD_MSG_MISMATCH_ARGS, "route add default"); + return; + } -static cmdline_parse_token_num_t cmd_route_add2_port = - TOKEN_NUM_INITIALIZER(struct cmd_route_add2_result, port, UINT32); + if (parser_read_uint32(&port_id, tokens[2])) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } -static cmdline_parse_token_string_t cmd_route_add2_ether_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add2_result, ether_string, - "ether"); + status = app_pipeline_routing_add_default_route(app, + params->p, + port_id); + if (status != 0) + printf(CMD_MSG_FAIL, "route add default"); -static cmdline_parse_token_ipaddr_t cmd_route_add2_nh_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_route_add2_result, nh_ip); + return; + } /* route add default */ -static cmdline_parse_inst_t cmd_route_add2 = { - .f = cmd_route_add2_parsed, - .data = NULL, - .help_str = "Route add (mpls = no, qinq = no, arp = yes)", - .tokens = { - (void *)&cmd_route_add2_p_string, - (void *)&cmd_route_add2_p, - (void *)&cmd_route_add2_route_string, - (void *)&cmd_route_add2_add_string, - (void *)&cmd_route_add2_ip, - (void *)&cmd_route_add2_depth, - (void *)&cmd_route_add2_port_string, - (void *)&cmd_route_add2_port, - (void *)&cmd_route_add2_ether_string, - (void *)&cmd_route_add2_nh_ip, - NULL, - }, -}; + /* route del*/ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + strcmp(tokens[1], "default")) { + struct pipeline_routing_route_key key; + struct in_addr ipv4; + uint32_t depth; -/* - * route add (mpls = no, qinq = yes, arp = no) - */ + memset(&key, 0, sizeof(key)); -struct cmd_route_add3_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t route_string; - cmdline_fixed_string_t add_string; - cmdline_ipaddr_t ip; - uint32_t depth; - cmdline_fixed_string_t port_string; - uint32_t port; - cmdline_fixed_string_t ether_string; - struct ether_addr macaddr; - cmdline_fixed_string_t qinq_string; - uint32_t svlan; - uint32_t cvlan; -}; + if (n_tokens != 3) { + printf(CMD_MSG_MISMATCH_ARGS, "route del"); + return; + } -static void -cmd_route_add3_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_route_add3_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_routing_route_key key; - struct pipeline_routing_route_data route_data; - int status; + if (parse_ipv4_addr(tokens[1], &ipv4)) { + printf(CMD_MSG_INVALID_ARG, "ipaddr"); + return; + } - /* Create route */ - key.type = PIPELINE_ROUTING_ROUTE_IPV4; - key.key.ipv4.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr); - key.key.ipv4.depth = params->depth; + if (parser_read_uint32(&depth, tokens[2])) { + printf(CMD_MSG_INVALID_ARG, "depth"); + return; + } - route_data.flags = PIPELINE_ROUTING_ROUTE_QINQ; - route_data.port_id = params->port; - route_data.ethernet.macaddr = params->macaddr; - route_data.l2.qinq.svlan = params->svlan; - route_data.l2.qinq.cvlan = params->cvlan; + key.type = PIPELINE_ROUTING_ROUTE_IPV4; + key.key.ipv4.ip = rte_be_to_cpu_32(ipv4.s_addr); + key.key.ipv4.depth = depth; - status = app_pipeline_routing_add_route(app, - params->p, - &key, - &route_data); + status = app_pipeline_routing_delete_route(app, params->p, &key); + if (status != 0) + printf(CMD_MSG_FAIL, "route del"); - if (status != 0) { - printf("Command failed\n"); return; - } -} - -static cmdline_parse_token_string_t cmd_route_add3_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add3_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_route_add3_p = - TOKEN_NUM_INITIALIZER(struct cmd_route_add3_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_route_add3_route_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add3_result, route_string, - "route"); + } /* route del */ + + /* route del default */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + (strcmp(tokens[1], "default") == 0)) { + if (n_tokens != 2) { + printf(CMD_MSG_MISMATCH_ARGS, "route del default"); + return; + } -static cmdline_parse_token_string_t cmd_route_add3_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add3_result, add_string, - "add"); + status = app_pipeline_routing_delete_default_route(app, + params->p); + if (status != 0) + printf(CMD_MSG_FAIL, "route del default"); -static cmdline_parse_token_ipaddr_t cmd_route_add3_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_route_add3_result, ip); + return; + } /* route del default */ -static cmdline_parse_token_num_t cmd_route_add3_depth = - TOKEN_NUM_INITIALIZER(struct cmd_route_add3_result, depth, UINT32); + /* route ls */ + if ((n_tokens >= 1) && (strcmp(tokens[0], "ls") == 0)) { + if (n_tokens != 1) { + printf(CMD_MSG_MISMATCH_ARGS, "route ls"); + return; + } -static cmdline_parse_token_string_t cmd_route_add3_port_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add3_result, port_string, - "port"); + status = app_pipeline_routing_route_ls(app, params->p); + if (status != 0) + printf(CMD_MSG_FAIL, "route ls"); -static cmdline_parse_token_num_t cmd_route_add3_port = - TOKEN_NUM_INITIALIZER(struct cmd_route_add3_result, port, UINT32); + return; + } /* route ls */ -static cmdline_parse_token_string_t cmd_route_add3_ether_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add3_result, ether_string, - "ether"); + printf(CMD_MSG_MISMATCH_ARGS, "route"); +} -static cmdline_parse_token_etheraddr_t cmd_route_add3_macaddr = - TOKEN_ETHERADDR_INITIALIZER(struct cmd_route_add3_result, macaddr); +static cmdline_parse_token_string_t cmd_route_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_result, p_string, "p"); -static cmdline_parse_token_string_t cmd_route_add3_qinq_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add3_result, qinq_string, - "qinq"); +static cmdline_parse_token_num_t cmd_route_p = + TOKEN_NUM_INITIALIZER(struct cmd_route_result, p, UINT32); -static cmdline_parse_token_num_t cmd_route_add3_svlan = - TOKEN_NUM_INITIALIZER(struct cmd_route_add3_result, svlan, UINT32); +static cmdline_parse_token_string_t cmd_route_route_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_result, route_string, "route"); -static cmdline_parse_token_num_t cmd_route_add3_cvlan = - TOKEN_NUM_INITIALIZER(struct cmd_route_add3_result, cvlan, UINT32); +static cmdline_parse_token_string_t cmd_route_multi_string = + TOKEN_STRING_INITIALIZER(struct cmd_route_result, multi_string, + TOKEN_STRING_MULTI); -static cmdline_parse_inst_t cmd_route_add3 = { - .f = cmd_route_add3_parsed, +static cmdline_parse_inst_t cmd_route = { + .f = cmd_route_parsed, .data = NULL, - .help_str = "Route add (qinq = yes, arp = no)", + .help_str = "route add / add default / del / del default / ls", .tokens = { - (void *)&cmd_route_add3_p_string, - (void *)&cmd_route_add3_p, - (void *)&cmd_route_add3_route_string, - (void *)&cmd_route_add3_add_string, - (void *)&cmd_route_add3_ip, - (void *)&cmd_route_add3_depth, - (void *)&cmd_route_add3_port_string, - (void *)&cmd_route_add3_port, - (void *)&cmd_route_add3_ether_string, - (void *)&cmd_route_add3_macaddr, - (void *)&cmd_route_add3_qinq_string, - (void *)&cmd_route_add3_svlan, - (void *)&cmd_route_add3_cvlan, + (void *)&cmd_route_p_string, + (void *)&cmd_route_p, + (void *)&cmd_route_route_string, + (void *)&cmd_route_multi_string, NULL, }, }; /* - * route add (mpls = no, qinq = yes, arp = yes) + * arp + * + * arp add: + * p arp add + * + * arp add default: + * p arp add default + * + * arp del: + * p arp del + * + * arp del default: + * p arp del default + * + * arp ls: + * p arp ls */ -struct cmd_route_add4_result { +struct cmd_arp_result { cmdline_fixed_string_t p_string; uint32_t p; - cmdline_fixed_string_t route_string; - cmdline_fixed_string_t add_string; - cmdline_ipaddr_t ip; - uint32_t depth; - cmdline_fixed_string_t port_string; - uint32_t port; - cmdline_fixed_string_t ether_string; - cmdline_ipaddr_t nh_ip; - cmdline_fixed_string_t qinq_string; - uint32_t svlan; - uint32_t cvlan; + cmdline_fixed_string_t arp_string; + cmdline_multi_string_t multi_string; }; static void -cmd_route_add4_parsed( +cmd_arp_parsed( void *parsed_result, __rte_unused struct cmdline *cl, void *data) { - struct cmd_route_add4_result *params = parsed_result; + struct cmd_arp_result *params = parsed_result; struct app_params *app = data; - struct pipeline_routing_route_key key; - struct pipeline_routing_route_data route_data; - int status; - /* Create route */ - key.type = PIPELINE_ROUTING_ROUTE_IPV4; - key.key.ipv4.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr); - key.key.ipv4.depth = params->depth; - - route_data.flags = PIPELINE_ROUTING_ROUTE_QINQ | - PIPELINE_ROUTING_ROUTE_ARP; - route_data.port_id = params->port; - route_data.ethernet.ip = - rte_bswap32((uint32_t) params->nh_ip.addr.ipv4.s_addr); - route_data.l2.qinq.svlan = params->svlan; - route_data.l2.qinq.cvlan = params->cvlan; - - status = app_pipeline_routing_add_route(app, - params->p, - &key, - &route_data); + char *tokens[16]; + uint32_t n_tokens = RTE_DIM(tokens); + int status; + status = parse_tokenize_string(params->multi_string, tokens, &n_tokens); if (status != 0) { - printf("Command failed\n"); + printf(CMD_MSG_TOO_MANY_ARGS, "arp"); return; } -} - -static cmdline_parse_token_string_t cmd_route_add4_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add4_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_route_add4_p = - TOKEN_NUM_INITIALIZER(struct cmd_route_add4_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_route_add4_route_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add4_result, route_string, - "route"); - -static cmdline_parse_token_string_t cmd_route_add4_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add4_result, add_string, - "add"); -static cmdline_parse_token_ipaddr_t cmd_route_add4_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_route_add4_result, ip); + /* arp add */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "add") == 0) && + strcmp(tokens[1], "default")) { + struct pipeline_routing_arp_key key; + struct in_addr ipv4; + struct ether_addr mac_addr; + uint32_t port_id; -static cmdline_parse_token_num_t cmd_route_add4_depth = - TOKEN_NUM_INITIALIZER(struct cmd_route_add4_result, depth, UINT32); + memset(&key, 0, sizeof(key)); -static cmdline_parse_token_string_t cmd_route_add4_port_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add4_result, port_string, - "port"); - -static cmdline_parse_token_num_t cmd_route_add4_port = - TOKEN_NUM_INITIALIZER(struct cmd_route_add4_result, port, UINT32); - -static cmdline_parse_token_string_t cmd_route_add4_ether_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add4_result, ether_string, - "ether"); - -static cmdline_parse_token_ipaddr_t cmd_route_add4_nh_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_route_add4_result, nh_ip); - -static cmdline_parse_token_string_t cmd_route_add4_qinq_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add4_result, qinq_string, - "qinq"); - -static cmdline_parse_token_num_t cmd_route_add4_svlan = - TOKEN_NUM_INITIALIZER(struct cmd_route_add4_result, svlan, UINT32); - -static cmdline_parse_token_num_t cmd_route_add4_cvlan = - TOKEN_NUM_INITIALIZER(struct cmd_route_add4_result, cvlan, UINT32); - -static cmdline_parse_inst_t cmd_route_add4 = { - .f = cmd_route_add4_parsed, - .data = NULL, - .help_str = "Route add (qinq = yes, arp = yes)", - .tokens = { - (void *)&cmd_route_add4_p_string, - (void *)&cmd_route_add4_p, - (void *)&cmd_route_add4_route_string, - (void *)&cmd_route_add4_add_string, - (void *)&cmd_route_add4_ip, - (void *)&cmd_route_add4_depth, - (void *)&cmd_route_add4_port_string, - (void *)&cmd_route_add4_port, - (void *)&cmd_route_add4_ether_string, - (void *)&cmd_route_add4_nh_ip, - (void *)&cmd_route_add4_qinq_string, - (void *)&cmd_route_add4_svlan, - (void *)&cmd_route_add4_cvlan, - NULL, - }, -}; - -/* - * route add (mpls = yes, qinq = no, arp = no) - */ - -struct cmd_route_add5_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t route_string; - cmdline_fixed_string_t add_string; - cmdline_ipaddr_t ip; - uint32_t depth; - cmdline_fixed_string_t port_string; - uint32_t port; - cmdline_fixed_string_t ether_string; - struct ether_addr macaddr; - cmdline_fixed_string_t mpls_string; - cmdline_fixed_string_t mpls_labels; -}; + if (n_tokens != 4) { + printf(CMD_MSG_MISMATCH_ARGS, "arp add"); + return; + } -static void -cmd_route_add5_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_route_add5_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_routing_route_key key; - struct pipeline_routing_route_data route_data; - uint32_t mpls_labels[PIPELINE_ROUTING_MPLS_LABELS_MAX]; - uint32_t n_labels = RTE_DIM(mpls_labels); - uint32_t i; - int status; + if (parser_read_uint32(&port_id, tokens[1])) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } - /* Parse MPLS labels */ - status = parse_labels(params->mpls_labels, mpls_labels, &n_labels); - if (status) { - printf("MPLS labels parse error\n"); - return; - } + if (parse_ipv4_addr(tokens[2], &ipv4)) { + printf(CMD_MSG_INVALID_ARG, "ipaddr"); + return; + } - /* Create route */ - key.type = PIPELINE_ROUTING_ROUTE_IPV4; - key.key.ipv4.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr); - key.key.ipv4.depth = params->depth; + if (parse_mac_addr(tokens[3], &mac_addr)) { + printf(CMD_MSG_INVALID_ARG, "macaddr"); + return; + } - route_data.flags = PIPELINE_ROUTING_ROUTE_MPLS; - route_data.port_id = params->port; - route_data.ethernet.macaddr = params->macaddr; - for (i = 0; i < n_labels; i++) - route_data.l2.mpls.labels[i] = mpls_labels[i]; - route_data.l2.mpls.n_labels = n_labels; + key.type = PIPELINE_ROUTING_ARP_IPV4; + key.key.ipv4.port_id = port_id; + key.key.ipv4.ip = rte_be_to_cpu_32(ipv4.s_addr); - status = app_pipeline_routing_add_route(app, - params->p, - &key, - &route_data); + status = app_pipeline_routing_add_arp_entry(app, + params->p, + &key, + &mac_addr); + if (status != 0) + printf(CMD_MSG_FAIL, "arp add"); - if (status != 0) { - printf("Command failed\n"); return; - } -} + } /* arp add */ -static cmdline_parse_token_string_t cmd_route_add5_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add5_result, p_string, - "p"); + /* arp add default */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "add") == 0) && + (strcmp(tokens[1], "default") == 0)) { + uint32_t port_id; -static cmdline_parse_token_num_t cmd_route_add5_p = - TOKEN_NUM_INITIALIZER(struct cmd_route_add5_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_route_add5_route_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add5_result, route_string, - "route"); + if (n_tokens != 3) { + printf(CMD_MSG_MISMATCH_ARGS, "arp add default"); + return; + } -static cmdline_parse_token_string_t cmd_route_add5_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add5_result, add_string, - "add"); + if (parser_read_uint32(&port_id, tokens[2])) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } -static cmdline_parse_token_ipaddr_t cmd_route_add5_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_route_add5_result, ip); + status = app_pipeline_routing_add_default_arp_entry(app, + params->p, + port_id); + if (status != 0) + printf(CMD_MSG_FAIL, "arp add default"); -static cmdline_parse_token_num_t cmd_route_add5_depth = - TOKEN_NUM_INITIALIZER(struct cmd_route_add5_result, depth, UINT32); + return; + } /* arp add default */ -static cmdline_parse_token_string_t cmd_route_add5_port_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add5_result, port_string, - "port"); + /* arp del*/ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + strcmp(tokens[1], "default")) { + struct pipeline_routing_arp_key key; + struct in_addr ipv4; + uint32_t port_id; -static cmdline_parse_token_num_t cmd_route_add5_port = - TOKEN_NUM_INITIALIZER(struct cmd_route_add5_result, port, UINT32); + memset(&key, 0, sizeof(key)); -static cmdline_parse_token_string_t cmd_route_add5_ether_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add5_result, ether_string, - "ether"); + if (n_tokens != 3) { + printf(CMD_MSG_MISMATCH_ARGS, "arp del"); + return; + } -static cmdline_parse_token_etheraddr_t cmd_route_add5_macaddr = - TOKEN_ETHERADDR_INITIALIZER(struct cmd_route_add5_result, macaddr); + if (parser_read_uint32(&port_id, tokens[1])) { + printf(CMD_MSG_INVALID_ARG, "portid"); + return; + } -static cmdline_parse_token_string_t cmd_route_add5_mpls_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add5_result, mpls_string, - "mpls"); + if (parse_ipv4_addr(tokens[2], &ipv4)) { + printf(CMD_MSG_INVALID_ARG, "ipaddr"); + return; + } -static cmdline_parse_token_string_t cmd_route_add5_mpls_labels = - TOKEN_STRING_INITIALIZER(struct cmd_route_add5_result, mpls_labels, - NULL); + key.type = PIPELINE_ROUTING_ARP_IPV4; + key.key.ipv4.ip = rte_be_to_cpu_32(ipv4.s_addr); + key.key.ipv4.port_id = port_id; -static cmdline_parse_inst_t cmd_route_add5 = { - .f = cmd_route_add5_parsed, - .data = NULL, - .help_str = "Route add (mpls = yes, arp = no)", - .tokens = { - (void *)&cmd_route_add5_p_string, - (void *)&cmd_route_add5_p, - (void *)&cmd_route_add5_route_string, - (void *)&cmd_route_add5_add_string, - (void *)&cmd_route_add5_ip, - (void *)&cmd_route_add5_depth, - (void *)&cmd_route_add5_port_string, - (void *)&cmd_route_add5_port, - (void *)&cmd_route_add5_ether_string, - (void *)&cmd_route_add5_macaddr, - (void *)&cmd_route_add5_mpls_string, - (void *)&cmd_route_add5_mpls_labels, - NULL, - }, -}; + status = app_pipeline_routing_delete_arp_entry(app, + params->p, + &key); + if (status != 0) + printf(CMD_MSG_FAIL, "arp del"); -/* - * route add (mpls = yes, qinq = no, arp = yes) - */ + return; + } /* arp del */ + + /* arp del default */ + if ((n_tokens >= 2) && + (strcmp(tokens[0], "del") == 0) && + (strcmp(tokens[1], "default") == 0)) { + if (n_tokens != 2) { + printf(CMD_MSG_MISMATCH_ARGS, "arp del default"); + return; + } + + status = app_pipeline_routing_delete_default_arp_entry(app, + params->p); + if (status != 0) + printf(CMD_MSG_FAIL, "arp del default"); + + return; + } /* arp del default */ + + /* arp ls */ + if ((n_tokens >= 1) && (strcmp(tokens[0], "ls") == 0)) { + if (n_tokens != 1) { + printf(CMD_MSG_MISMATCH_ARGS, "arp ls"); + return; + } -struct cmd_route_add6_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t route_string; - cmdline_fixed_string_t add_string; - cmdline_ipaddr_t ip; - uint32_t depth; - cmdline_fixed_string_t port_string; - uint32_t port; - cmdline_fixed_string_t ether_string; - cmdline_ipaddr_t nh_ip; - cmdline_fixed_string_t mpls_string; - cmdline_fixed_string_t mpls_labels; -}; + status = app_pipeline_routing_arp_ls(app, params->p); + if (status != 0) + printf(CMD_MSG_FAIL, "arp ls"); -static void -cmd_route_add6_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_route_add6_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_routing_route_key key; - struct pipeline_routing_route_data route_data; - uint32_t mpls_labels[PIPELINE_ROUTING_MPLS_LABELS_MAX]; - uint32_t n_labels = RTE_DIM(mpls_labels); - uint32_t i; - int status; - - /* Parse MPLS labels */ - status = parse_labels(params->mpls_labels, mpls_labels, &n_labels); - if (status) { - printf("MPLS labels parse error\n"); - return; - } - - /* Create route */ - key.type = PIPELINE_ROUTING_ROUTE_IPV4; - key.key.ipv4.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr); - key.key.ipv4.depth = params->depth; - - route_data.flags = PIPELINE_ROUTING_ROUTE_MPLS | - PIPELINE_ROUTING_ROUTE_ARP; - route_data.port_id = params->port; - route_data.ethernet.ip = - rte_bswap32((uint32_t) params->nh_ip.addr.ipv4.s_addr); - for (i = 0; i < n_labels; i++) - route_data.l2.mpls.labels[i] = mpls_labels[i]; - route_data.l2.mpls.n_labels = n_labels; - - status = app_pipeline_routing_add_route(app, - params->p, - &key, - &route_data); - - if (status != 0) { - printf("Command failed\n"); - return; - } -} - -static cmdline_parse_token_string_t cmd_route_add6_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add6_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_route_add6_p = - TOKEN_NUM_INITIALIZER(struct cmd_route_add6_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_route_add6_route_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add6_result, route_string, - "route"); - -static cmdline_parse_token_string_t cmd_route_add6_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add6_result, add_string, - "add"); - -static cmdline_parse_token_ipaddr_t cmd_route_add6_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_route_add6_result, ip); - -static cmdline_parse_token_num_t cmd_route_add6_depth = - TOKEN_NUM_INITIALIZER(struct cmd_route_add6_result, depth, UINT32); - -static cmdline_parse_token_string_t cmd_route_add6_port_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add6_result, port_string, - "port"); - -static cmdline_parse_token_num_t cmd_route_add6_port = - TOKEN_NUM_INITIALIZER(struct cmd_route_add6_result, port, UINT32); - -static cmdline_parse_token_string_t cmd_route_add6_ether_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add6_result, ether_string, - "ether"); - -static cmdline_parse_token_ipaddr_t cmd_route_add6_nh_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_route_add6_result, nh_ip); - -static cmdline_parse_token_string_t cmd_route_add6_mpls_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add6_result, mpls_string, - "mpls"); - -static cmdline_parse_token_string_t cmd_route_add6_mpls_labels = - TOKEN_STRING_INITIALIZER(struct cmd_route_add6_result, mpls_labels, - NULL); - -static cmdline_parse_inst_t cmd_route_add6 = { - .f = cmd_route_add6_parsed, - .data = NULL, - .help_str = "Route add (mpls = yes, arp = yes)", - .tokens = { - (void *)&cmd_route_add6_p_string, - (void *)&cmd_route_add6_p, - (void *)&cmd_route_add6_route_string, - (void *)&cmd_route_add6_add_string, - (void *)&cmd_route_add6_ip, - (void *)&cmd_route_add6_depth, - (void *)&cmd_route_add6_port_string, - (void *)&cmd_route_add6_port, - (void *)&cmd_route_add6_ether_string, - (void *)&cmd_route_add6_nh_ip, - (void *)&cmd_route_add6_mpls_string, - (void *)&cmd_route_add6_mpls_labels, - NULL, - }, -}; - -/* - * route del - */ - -struct cmd_route_del_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t route_string; - cmdline_fixed_string_t del_string; - cmdline_ipaddr_t ip; - uint32_t depth; -}; - -static void -cmd_route_del_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_route_del_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_routing_route_key key; - - int status; - - /* Create route */ - key.type = PIPELINE_ROUTING_ROUTE_IPV4; - key.key.ipv4.ip = rte_bswap32((uint32_t) params->ip.addr.ipv4.s_addr); - key.key.ipv4.depth = params->depth; - - status = app_pipeline_routing_delete_route(app, params->p, &key); - - if (status != 0) { - printf("Command failed\n"); - return; - } -} - -static cmdline_parse_token_string_t cmd_route_del_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_del_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_route_del_p = - TOKEN_NUM_INITIALIZER(struct cmd_route_del_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_route_del_route_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_del_result, route_string, - "route"); - -static cmdline_parse_token_string_t cmd_route_del_del_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_del_result, del_string, - "del"); - -static cmdline_parse_token_ipaddr_t cmd_route_del_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_route_del_result, ip); - -static cmdline_parse_token_num_t cmd_route_del_depth = - TOKEN_NUM_INITIALIZER(struct cmd_route_del_result, depth, UINT32); - -static cmdline_parse_inst_t cmd_route_del = { - .f = cmd_route_del_parsed, - .data = NULL, - .help_str = "Route delete", - .tokens = { - (void *)&cmd_route_del_p_string, - (void *)&cmd_route_del_p, - (void *)&cmd_route_del_route_string, - (void *)&cmd_route_del_del_string, - (void *)&cmd_route_del_ip, - (void *)&cmd_route_del_depth, - NULL, - }, -}; - -/* - * route add default - */ - -struct cmd_route_add_default_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t route_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t default_string; - uint32_t port; -}; - -static void -cmd_route_add_default_parsed( - void *parsed_result, - __attribute__((unused)) struct cmdline *cl, - void *data) -{ - struct cmd_route_add_default_result *params = parsed_result; - struct app_params *app = data; - int status; - - status = app_pipeline_routing_add_default_route(app, params->p, - params->port); - - if (status != 0) { - printf("Command failed\n"); - return; - } -} - -static cmdline_parse_token_string_t cmd_route_add_default_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add_default_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_route_add_default_p = - TOKEN_NUM_INITIALIZER(struct cmd_route_add_default_result, p, UINT32); - -cmdline_parse_token_string_t cmd_route_add_default_route_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add_default_result, - route_string, "route"); - -cmdline_parse_token_string_t cmd_route_add_default_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add_default_result, - add_string, "add"); - -cmdline_parse_token_string_t cmd_route_add_default_default_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_add_default_result, - default_string, "default"); - -cmdline_parse_token_num_t cmd_route_add_default_port = - TOKEN_NUM_INITIALIZER(struct cmd_route_add_default_result, - port, UINT32); - -cmdline_parse_inst_t cmd_route_add_default = { - .f = cmd_route_add_default_parsed, - .data = NULL, - .help_str = "Route default set", - .tokens = { - (void *)&cmd_route_add_default_p_string, - (void *)&cmd_route_add_default_p, - (void *)&cmd_route_add_default_route_string, - (void *)&cmd_route_add_default_add_string, - (void *)&cmd_route_add_default_default_string, - (void *)&cmd_route_add_default_port, - NULL, - }, -}; - -/* - * route del default - */ - -struct cmd_route_del_default_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t route_string; - cmdline_fixed_string_t del_string; - cmdline_fixed_string_t default_string; -}; - -static void -cmd_route_del_default_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_route_del_default_result *params = parsed_result; - struct app_params *app = data; - int status; - - status = app_pipeline_routing_delete_default_route(app, params->p); - - if (status != 0) { - printf("Command failed\n"); - return; - } -} - -static cmdline_parse_token_string_t cmd_route_del_default_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_del_default_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_route_del_default_p = - TOKEN_NUM_INITIALIZER(struct cmd_route_del_default_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_route_del_default_route_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_del_default_result, - route_string, "route"); - -static cmdline_parse_token_string_t cmd_route_del_default_del_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_del_default_result, - del_string, "del"); - -static cmdline_parse_token_string_t cmd_route_del_default_default_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_del_default_result, - default_string, "default"); - - -static cmdline_parse_inst_t cmd_route_del_default = { - .f = cmd_route_del_default_parsed, - .data = NULL, - .help_str = "Route default clear", - .tokens = { - (void *)&cmd_route_del_default_p_string, - (void *)&cmd_route_del_default_p, - (void *)&cmd_route_del_default_route_string, - (void *)&cmd_route_del_default_del_string, - (void *)&cmd_route_del_default_default_string, - NULL, - }, -}; - -/* - * route ls - */ - -struct cmd_route_ls_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t route_string; - cmdline_fixed_string_t ls_string; -}; - -static void -cmd_route_ls_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_route_ls_result *params = parsed_result; - struct app_params *app = data; - int status; - - status = app_pipeline_routing_route_ls(app, params->p); - - if (status != 0) { - printf("Command failed\n"); - return; - } -} - -static cmdline_parse_token_string_t cmd_route_ls_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_ls_result, p_string, "p"); - -static cmdline_parse_token_num_t cmd_route_ls_p = - TOKEN_NUM_INITIALIZER(struct cmd_route_ls_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_route_ls_route_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_ls_result, - route_string, "route"); - -static cmdline_parse_token_string_t cmd_route_ls_ls_string = - TOKEN_STRING_INITIALIZER(struct cmd_route_ls_result, ls_string, - "ls"); - -static cmdline_parse_inst_t cmd_route_ls = { - .f = cmd_route_ls_parsed, - .data = NULL, - .help_str = "Route list", - .tokens = { - (void *)&cmd_route_ls_p_string, - (void *)&cmd_route_ls_p, - (void *)&cmd_route_ls_route_string, - (void *)&cmd_route_ls_ls_string, - NULL, - }, -}; - -/* - * arp add - */ - -struct cmd_arp_add_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t arp_string; - cmdline_fixed_string_t add_string; - uint32_t port_id; - cmdline_ipaddr_t ip; - struct ether_addr macaddr; - -}; - -static void -cmd_arp_add_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_arp_add_result *params = parsed_result; - struct app_params *app = data; - - struct pipeline_routing_arp_key key; - int status; - - key.type = PIPELINE_ROUTING_ARP_IPV4; - key.key.ipv4.port_id = params->port_id; - key.key.ipv4.ip = rte_cpu_to_be_32(params->ip.addr.ipv4.s_addr); - - status = app_pipeline_routing_add_arp_entry(app, - params->p, - &key, - ¶ms->macaddr); - - if (status != 0) { - printf("Command failed\n"); - return; - } -} - -static cmdline_parse_token_string_t cmd_arp_add_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_add_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_arp_add_p = - TOKEN_NUM_INITIALIZER(struct cmd_arp_add_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_arp_add_arp_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_add_result, arp_string, "arp"); - -static cmdline_parse_token_string_t cmd_arp_add_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_add_result, add_string, "add"); - -static cmdline_parse_token_num_t cmd_arp_add_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_arp_add_result, port_id, UINT32); - -static cmdline_parse_token_ipaddr_t cmd_arp_add_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_arp_add_result, ip); - -static cmdline_parse_token_etheraddr_t cmd_arp_add_macaddr = - TOKEN_ETHERADDR_INITIALIZER(struct cmd_arp_add_result, macaddr); - -static cmdline_parse_inst_t cmd_arp_add = { - .f = cmd_arp_add_parsed, - .data = NULL, - .help_str = "ARP add", - .tokens = { - (void *)&cmd_arp_add_p_string, - (void *)&cmd_arp_add_p, - (void *)&cmd_arp_add_arp_string, - (void *)&cmd_arp_add_add_string, - (void *)&cmd_arp_add_port_id, - (void *)&cmd_arp_add_ip, - (void *)&cmd_arp_add_macaddr, - NULL, - }, -}; - -/* - * arp del - */ - -struct cmd_arp_del_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t arp_string; - cmdline_fixed_string_t del_string; - uint32_t port_id; - cmdline_ipaddr_t ip; -}; - -static void -cmd_arp_del_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_arp_del_result *params = parsed_result; - struct app_params *app = data; - - struct pipeline_routing_arp_key key; - int status; - - key.type = PIPELINE_ROUTING_ARP_IPV4; - key.key.ipv4.ip = rte_cpu_to_be_32(params->ip.addr.ipv4.s_addr); - key.key.ipv4.port_id = params->port_id; - - status = app_pipeline_routing_delete_arp_entry(app, params->p, &key); - - if (status != 0) { - printf("Command failed\n"); - return; - } -} - -static cmdline_parse_token_string_t cmd_arp_del_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_del_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_arp_del_p = - TOKEN_NUM_INITIALIZER(struct cmd_arp_del_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_arp_del_arp_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_del_result, arp_string, "arp"); - -static cmdline_parse_token_string_t cmd_arp_del_del_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_del_result, del_string, "del"); - -static cmdline_parse_token_num_t cmd_arp_del_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_arp_del_result, port_id, UINT32); - -static cmdline_parse_token_ipaddr_t cmd_arp_del_ip = - TOKEN_IPV4_INITIALIZER(struct cmd_arp_del_result, ip); - -static cmdline_parse_inst_t cmd_arp_del = { - .f = cmd_arp_del_parsed, - .data = NULL, - .help_str = "ARP delete", - .tokens = { - (void *)&cmd_arp_del_p_string, - (void *)&cmd_arp_del_p, - (void *)&cmd_arp_del_arp_string, - (void *)&cmd_arp_del_del_string, - (void *)&cmd_arp_del_port_id, - (void *)&cmd_arp_del_ip, - NULL, - }, -}; - -/* - * arp add default - */ - -struct cmd_arp_add_default_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t arp_string; - cmdline_fixed_string_t add_string; - cmdline_fixed_string_t default_string; - uint32_t port_id; -}; - -static void -cmd_arp_add_default_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_arp_add_default_result *params = parsed_result; - struct app_params *app = data; - - int status; - - status = app_pipeline_routing_add_default_arp_entry(app, - params->p, - params->port_id); - - if (status != 0) { - printf("Command failed\n"); - return; - } -} - -static cmdline_parse_token_string_t cmd_arp_add_default_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_add_default_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_arp_add_default_p = - TOKEN_NUM_INITIALIZER(struct cmd_arp_add_default_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_arp_add_default_arp_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_add_default_result, arp_string, - "arp"); - -static cmdline_parse_token_string_t cmd_arp_add_default_add_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_add_default_result, add_string, - "add"); - -static cmdline_parse_token_string_t cmd_arp_add_default_default_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_add_default_result, - default_string, "default"); - -static cmdline_parse_token_num_t cmd_arp_add_default_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_arp_add_default_result, port_id, - UINT32); - -static cmdline_parse_inst_t cmd_arp_add_default = { - .f = cmd_arp_add_default_parsed, - .data = NULL, - .help_str = "ARP add default", - .tokens = { - (void *)&cmd_arp_add_default_p_string, - (void *)&cmd_arp_add_default_p, - (void *)&cmd_arp_add_default_arp_string, - (void *)&cmd_arp_add_default_add_string, - (void *)&cmd_arp_add_default_default_string, - (void *)&cmd_arp_add_default_port_id, - NULL, - }, -}; - -/* - * arp del default - */ - -struct cmd_arp_del_default_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t arp_string; - cmdline_fixed_string_t del_string; - cmdline_fixed_string_t default_string; -}; - -static void -cmd_arp_del_default_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_arp_del_default_result *params = parsed_result; - struct app_params *app = data; - - int status; - - status = app_pipeline_routing_delete_default_arp_entry(app, params->p); - - if (status != 0) { - printf("Command failed\n"); - return; - } -} - -static cmdline_parse_token_string_t cmd_arp_del_default_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_del_default_result, p_string, - "p"); - -static cmdline_parse_token_num_t cmd_arp_del_default_p = - TOKEN_NUM_INITIALIZER(struct cmd_arp_del_default_result, p, UINT32); - -static cmdline_parse_token_string_t cmd_arp_del_default_arp_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_del_default_result, arp_string, - "arp"); - -static cmdline_parse_token_string_t cmd_arp_del_default_del_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_del_default_result, del_string, - "del"); - -static cmdline_parse_token_string_t cmd_arp_del_default_default_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_del_default_result, - default_string, "default"); - -static cmdline_parse_inst_t cmd_arp_del_default = { - .f = cmd_arp_del_default_parsed, - .data = NULL, - .help_str = "ARP delete default", - .tokens = { - (void *)&cmd_arp_del_default_p_string, - (void *)&cmd_arp_del_default_p, - (void *)&cmd_arp_del_default_arp_string, - (void *)&cmd_arp_del_default_del_string, - (void *)&cmd_arp_del_default_default_string, - NULL, - }, -}; - -/* - * arp ls - */ - -struct cmd_arp_ls_result { - cmdline_fixed_string_t p_string; - uint32_t p; - cmdline_fixed_string_t arp_string; - cmdline_fixed_string_t ls_string; -}; - -static void -cmd_arp_ls_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - void *data) -{ - struct cmd_arp_ls_result *params = parsed_result; - struct app_params *app = data; - struct pipeline_routing *p; - - p = app_pipeline_data_fe(app, params->p, &pipeline_routing); - if (p == NULL) return; + } /* arp ls */ - app_pipeline_routing_arp_ls(app, params->p); + printf(CMD_MSG_FAIL, "arp"); } -static cmdline_parse_token_string_t cmd_arp_ls_p_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, p_string, - "p"); +static cmdline_parse_token_string_t cmd_arp_p_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_result, p_string, "p"); -static cmdline_parse_token_num_t cmd_arp_ls_p = - TOKEN_NUM_INITIALIZER(struct cmd_arp_ls_result, p, UINT32); +static cmdline_parse_token_num_t cmd_arp_p = + TOKEN_NUM_INITIALIZER(struct cmd_arp_result, p, UINT32); -static cmdline_parse_token_string_t cmd_arp_ls_arp_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, arp_string, - "arp"); +static cmdline_parse_token_string_t cmd_arp_arp_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_result, arp_string, "arp"); -static cmdline_parse_token_string_t cmd_arp_ls_ls_string = - TOKEN_STRING_INITIALIZER(struct cmd_arp_ls_result, ls_string, - "ls"); +static cmdline_parse_token_string_t cmd_arp_multi_string = + TOKEN_STRING_INITIALIZER(struct cmd_arp_result, multi_string, + TOKEN_STRING_MULTI); -static cmdline_parse_inst_t cmd_arp_ls = { - .f = cmd_arp_ls_parsed, +static cmdline_parse_inst_t cmd_arp = { + .f = cmd_arp_parsed, .data = NULL, - .help_str = "ARP list", + .help_str = "arp add / add default / del / del default / ls", .tokens = { - (void *)&cmd_arp_ls_p_string, - (void *)&cmd_arp_ls_p, - (void *)&cmd_arp_ls_arp_string, - (void *)&cmd_arp_ls_ls_string, + (void *)&cmd_arp_p_string, + (void *)&cmd_arp_p, + (void *)&cmd_arp_arp_string, + (void *)&cmd_arp_multi_string, NULL, }, }; static cmdline_parse_ctx_t pipeline_cmds[] = { - (cmdline_parse_inst_t *)&cmd_route_add1, - (cmdline_parse_inst_t *)&cmd_route_add2, - (cmdline_parse_inst_t *)&cmd_route_add3, - (cmdline_parse_inst_t *)&cmd_route_add4, - (cmdline_parse_inst_t *)&cmd_route_add5, - (cmdline_parse_inst_t *)&cmd_route_add6, - (cmdline_parse_inst_t *)&cmd_route_del, - (cmdline_parse_inst_t *)&cmd_route_add_default, - (cmdline_parse_inst_t *)&cmd_route_del_default, - (cmdline_parse_inst_t *)&cmd_route_ls, - (cmdline_parse_inst_t *)&cmd_arp_add, - (cmdline_parse_inst_t *)&cmd_arp_del, - (cmdline_parse_inst_t *)&cmd_arp_add_default, - (cmdline_parse_inst_t *)&cmd_arp_del_default, - (cmdline_parse_inst_t *)&cmd_arp_ls, + (cmdline_parse_inst_t *)&cmd_route, + (cmdline_parse_inst_t *)&cmd_arp, NULL, }; static struct pipeline_fe_ops pipeline_routing_fe_ops = { - .f_init = pipeline_routing_init, + .f_init = app_pipeline_routing_init, + .f_post_init = app_pipeline_routing_post_init, .f_free = app_pipeline_routing_free, + .f_track = app_pipeline_track_default, .cmds = pipeline_cmds, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_routing.h b/examples/ip_pipeline/pipeline/pipeline_routing.h index fa41642b..0197449b 100644 --- a/examples/ip_pipeline/pipeline/pipeline_routing.h +++ b/examples/ip_pipeline/pipeline/pipeline_routing.h @@ -85,6 +85,13 @@ int app_pipeline_routing_delete_default_arp_entry(struct app_params *app, uint32_t pipeline_id); +/* + * SETTINGS + */ +int +app_pipeline_routing_set_macaddr(struct app_params *app, + uint32_t pipeline_id); + /* * Pipeline type */ diff --git a/examples/ip_pipeline/pipeline/pipeline_routing_be.c b/examples/ip_pipeline/pipeline/pipeline_routing_be.c index bc5bf7a5..21ac7888 100644 --- a/examples/ip_pipeline/pipeline/pipeline_routing_be.c +++ b/examples/ip_pipeline/pipeline/pipeline_routing_be.c @@ -65,7 +65,9 @@ ((((uint64_t) (pipe)) & 0xFFFFFFFF) << 32)) -#define MAC_SRC_DEFAULT 0x112233445566ULL +/* Network Byte Order (NBO) */ +#define SLAB_NBO_MACADDRSRC_ETHERTYPE(macaddr, ethertype) \ + (((uint64_t) macaddr) | (((uint64_t) rte_cpu_to_be_16(ethertype)) << 48)) #ifndef PIPELINE_ROUTING_LPM_TABLE_NUMBER_TABLE8s #define PIPELINE_ROUTING_LPM_TABLE_NUMBER_TABLE8s 256 @@ -75,6 +77,7 @@ struct pipeline_routing { struct pipeline p; struct pipeline_routing_params params; pipeline_msg_req_handler custom_handlers[PIPELINE_ROUTING_MSG_REQS]; + uint64_t macaddr[PIPELINE_MAX_PORT_OUT]; } __rte_cache_aligned; /* @@ -132,6 +135,10 @@ static void * pipeline_routing_msg_req_arp_del_default_handler(struct pipeline *p, void *msg); +static void * +pipeline_routing_msg_req_set_macaddr_handler(struct pipeline *p, + void *msg); + static pipeline_msg_req_handler custom_handlers[] = { [PIPELINE_ROUTING_MSG_REQ_ROUTE_ADD] = pipeline_routing_msg_req_route_add_handler, @@ -149,6 +156,8 @@ static pipeline_msg_req_handler custom_handlers[] = { pipeline_routing_msg_req_arp_add_default_handler, [PIPELINE_ROUTING_MSG_REQ_ARP_DEL_DEFAULT] = pipeline_routing_msg_req_arp_del_default_handler, + [PIPELINE_ROUTING_MSG_REQ_SET_MACADDR] = + pipeline_routing_msg_req_set_macaddr_handler, }; /* @@ -921,6 +930,7 @@ pipeline_routing_parse_args(struct pipeline_routing_params *p, struct pipeline_params *params) { uint32_t n_routes_present = 0; + uint32_t port_local_dest_present = 0; uint32_t encap_present = 0; uint32_t qinq_sched_present = 0; uint32_t mpls_color_mark_present = 0; @@ -933,6 +943,7 @@ pipeline_routing_parse_args(struct pipeline_routing_params *p, /* default values */ p->n_routes = PIPELINE_ROUTING_N_ROUTES_DEFAULT; + p->port_local_dest = params->n_ports_out - 1; p->encap = PIPELINE_ROUTING_ENCAP_ETHERNET; p->qinq_sched = 0; p->mpls_color_mark = 0; @@ -962,6 +973,23 @@ pipeline_routing_parse_args(struct pipeline_routing_params *p, continue; } + /* port_local_dest */ + if (strcmp(arg_name, "port_local_dest") == 0) { + int status; + + PIPELINE_PARSE_ERR_DUPLICATE( + port_local_dest_present == 0, params->name, + arg_name); + port_local_dest_present = 1; + + status = parser_read_uint32(&p->port_local_dest, + arg_value); + PIPELINE_PARSE_ERR_INV_VAL(((status == 0) && + (p->port_local_dest < params->n_ports_out)), + params->name, arg_name, arg_value); + + continue; + } /* encap */ if (strcmp(arg_name, "encap") == 0) { @@ -1418,27 +1446,6 @@ pipeline_routing_free(void *pipeline) return 0; } -static int -pipeline_routing_track(void *pipeline, - __rte_unused uint32_t port_in, - uint32_t *port_out) -{ - struct pipeline *p = (struct pipeline *) pipeline; - - /* Check input arguments */ - if ((p == NULL) || - (port_in >= p->n_ports_in) || - (port_out == NULL)) - return -1; - - if (p->n_ports_in == 1) { - *port_out = 0; - return 0; - } - - return -1; -} - static int pipeline_routing_timer(void *pipeline) { @@ -1534,7 +1541,7 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) /* Ether - ARP off */ if ((p_rt->params.encap == PIPELINE_ROUTING_ENCAP_ETHERNET) && (p_rt->params.n_arp_entries == 0)) { - uint64_t macaddr_src = MAC_SRC_DEFAULT; + uint64_t macaddr_src = p_rt->macaddr[req->data.port_id]; uint64_t macaddr_dst; uint64_t ethertype = ETHER_TYPE_IPv4; @@ -1542,7 +1549,7 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) macaddr_dst = rte_bswap64(macaddr_dst << 16); entry_arp0.slab[0] = - rte_bswap64((macaddr_src << 16) | ethertype); + SLAB_NBO_MACADDRSRC_ETHERTYPE(macaddr_src, ethertype); entry_arp0.slab_offset[0] = p_rt->params.ip_hdr_offset - 8; entry_arp0.slab[1] = rte_bswap64(macaddr_dst); @@ -1556,11 +1563,11 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) /* Ether - ARP on */ if ((p_rt->params.encap == PIPELINE_ROUTING_ENCAP_ETHERNET) && p_rt->params.n_arp_entries) { - uint64_t macaddr_src = MAC_SRC_DEFAULT; + uint64_t macaddr_src = p_rt->macaddr[req->data.port_id]; uint64_t ethertype = ETHER_TYPE_IPv4; - entry_arp1.slab[0] = rte_bswap64((macaddr_src << 16) | - ethertype); + entry_arp1.slab[0] = + SLAB_NBO_MACADDRSRC_ETHERTYPE(macaddr_src, ethertype); entry_arp1.slab_offset[0] = p_rt->params.ip_hdr_offset - 8; entry_arp1.data_offset = entry_arp1.slab_offset[0] - 6 @@ -1571,7 +1578,7 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) /* Ether QinQ - ARP off */ if ((p_rt->params.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_QINQ) && (p_rt->params.n_arp_entries == 0)) { - uint64_t macaddr_src = MAC_SRC_DEFAULT; + uint64_t macaddr_src = p_rt->macaddr[req->data.port_id]; uint64_t macaddr_dst; uint64_t ethertype_ipv4 = ETHER_TYPE_IPv4; uint64_t ethertype_vlan = 0x8100; @@ -1588,8 +1595,8 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) ethertype_ipv4); entry_arp0.slab_offset[0] = p_rt->params.ip_hdr_offset - 8; - entry_arp0.slab[1] = rte_bswap64((macaddr_src << 16) | - ethertype_qinq); + entry_arp0.slab[1] = + SLAB_NBO_MACADDRSRC_ETHERTYPE(macaddr_src, ethertype_qinq); entry_arp0.slab_offset[1] = p_rt->params.ip_hdr_offset - 2 * 8; entry_arp0.slab[2] = rte_bswap64(macaddr_dst); @@ -1603,7 +1610,7 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) /* Ether QinQ - ARP on */ if ((p_rt->params.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_QINQ) && p_rt->params.n_arp_entries) { - uint64_t macaddr_src = MAC_SRC_DEFAULT; + uint64_t macaddr_src = p_rt->macaddr[req->data.port_id]; uint64_t ethertype_ipv4 = ETHER_TYPE_IPv4; uint64_t ethertype_vlan = 0x8100; uint64_t ethertype_qinq = 0x9100; @@ -1616,8 +1623,8 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) ethertype_ipv4); entry_arp1.slab_offset[0] = p_rt->params.ip_hdr_offset - 8; - entry_arp1.slab[1] = rte_bswap64((macaddr_src << 16) | - ethertype_qinq); + entry_arp1.slab[1] = + SLAB_NBO_MACADDRSRC_ETHERTYPE(macaddr_src, ethertype_qinq); entry_arp1.slab_offset[1] = p_rt->params.ip_hdr_offset - 2 * 8; entry_arp1.data_offset = entry_arp1.slab_offset[1] - 6 @@ -1628,7 +1635,7 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) /* Ether MPLS - ARP off */ if ((p_rt->params.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_MPLS) && (p_rt->params.n_arp_entries == 0)) { - uint64_t macaddr_src = MAC_SRC_DEFAULT; + uint64_t macaddr_src = p_rt->macaddr[req->data.port_id]; uint64_t macaddr_dst; uint64_t ethertype_mpls = 0x8847; @@ -1697,8 +1704,8 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) return rsp; } - entry_arp0.slab[2] = rte_bswap64((macaddr_src << 16) | - ethertype_mpls); + entry_arp0.slab[2] = + SLAB_NBO_MACADDRSRC_ETHERTYPE(macaddr_src, ethertype_mpls); entry_arp0.slab_offset[2] = p_rt->params.ip_hdr_offset - (n_labels * 4 + 8); @@ -1714,7 +1721,7 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) /* Ether MPLS - ARP on */ if ((p_rt->params.encap == PIPELINE_ROUTING_ENCAP_ETHERNET_MPLS) && p_rt->params.n_arp_entries) { - uint64_t macaddr_src = MAC_SRC_DEFAULT; + uint64_t macaddr_src = p_rt->macaddr[req->data.port_id]; uint64_t ethertype_mpls = 0x8847; uint64_t label0 = req->data.l2.mpls.labels[0]; @@ -1779,8 +1786,8 @@ pipeline_routing_msg_req_route_add_handler(struct pipeline *p, void *msg) return rsp; } - entry_arp1.slab[2] = rte_bswap64((macaddr_src << 16) | - ethertype_mpls); + entry_arp1.slab[2] = + SLAB_NBO_MACADDRSRC_ETHERTYPE(macaddr_src, ethertype_mpls); entry_arp1.slab_offset[2] = p_rt->params.ip_hdr_offset - (n_labels * 4 + 8); @@ -1961,10 +1968,25 @@ pipeline_routing_msg_req_arp_del_default_handler(struct pipeline *p, void *msg) return rsp; } +void * +pipeline_routing_msg_req_set_macaddr_handler(struct pipeline *p, void *msg) +{ + struct pipeline_routing *p_rt = (struct pipeline_routing *) p; + struct pipeline_routing_set_macaddr_msg_req *req = msg; + struct pipeline_routing_set_macaddr_msg_rsp *rsp = msg; + uint32_t port_id; + + for (port_id = 0; port_id < p->n_ports_out; port_id++) + p_rt->macaddr[port_id] = req->macaddr[port_id]; + + rsp->status = 0; + + return rsp; +} + struct pipeline_be_ops pipeline_routing_be_ops = { .f_init = pipeline_routing_init, .f_free = pipeline_routing_free, .f_run = NULL, .f_timer = pipeline_routing_timer, - .f_track = pipeline_routing_track, }; diff --git a/examples/ip_pipeline/pipeline/pipeline_routing_be.h b/examples/ip_pipeline/pipeline/pipeline_routing_be.h index ec767b24..12763427 100644 --- a/examples/ip_pipeline/pipeline/pipeline_routing_be.h +++ b/examples/ip_pipeline/pipeline/pipeline_routing_be.h @@ -54,6 +54,7 @@ enum pipeline_routing_encap { struct pipeline_routing_params { /* routing */ uint32_t n_routes; + uint32_t port_local_dest; /* routing packet encapsulation */ enum pipeline_routing_encap encap; @@ -160,6 +161,7 @@ enum pipeline_routing_msg_req_type { PIPELINE_ROUTING_MSG_REQ_ARP_DEL, PIPELINE_ROUTING_MSG_REQ_ARP_ADD_DEFAULT, PIPELINE_ROUTING_MSG_REQ_ARP_DEL_DEFAULT, + PIPELINE_ROUTING_MSG_REQ_SET_MACADDR, PIPELINE_ROUTING_MSG_REQS }; @@ -291,6 +293,20 @@ struct pipeline_routing_arp_delete_default_msg_rsp { int status; }; +/* + * MSG SET MACADDR + */ +struct pipeline_routing_set_macaddr_msg_req { + enum pipeline_msg_req_type type; + enum pipeline_routing_msg_req_type subtype; + + uint64_t macaddr[PIPELINE_MAX_PORT_OUT]; +}; + +struct pipeline_routing_set_macaddr_msg_rsp { + int status; +}; + extern struct pipeline_be_ops pipeline_routing_be_ops; #endif -- cgit 1.2.3-korg