From: Cristian Dumitrescu Date: Wed, 25 Jul 2018 17:10:03 +0000 (+0100) Subject: net/softnic: add command for tmgr shaper profile X-Git-Url: http://git.droids-corp.org/?a=commitdiff_plain;h=552e3f72d49ec91d0cec250cb392b23aaf3757c1;p=dpdk.git net/softnic: add command for tmgr shaper profile Add support to create Traffic Manager (TMGR) shaper profile through firmware CLI script. Signed-off-by: Cristian Dumitrescu Signed-off-by: Jasvinder Singh --- diff --git a/drivers/net/softnic/parser.c b/drivers/net/softnic/parser.c index 7087b87833..a8688a21ea 100644 --- a/drivers/net/softnic/parser.c +++ b/drivers/net/softnic/parser.c @@ -92,6 +92,24 @@ softnic_parser_read_arg_bool(const char *p) return result; } +int +softnic_parser_read_int32(int32_t *value, const char *p) +{ + char *next; + int32_t val; + + p = skip_white_spaces(p); + if (!isdigit(*p)) + return -EINVAL; + + val = strtol(p, &next, 10); + if (p == next) + return -EINVAL; + + *value = val; + return 0; +} + int softnic_parser_read_uint64(uint64_t *value, const char *p) { diff --git a/drivers/net/softnic/parser.h b/drivers/net/softnic/parser.h index 5ab47631d0..1ee3f82a79 100644 --- a/drivers/net/softnic/parser.h +++ b/drivers/net/softnic/parser.h @@ -33,6 +33,8 @@ skip_digits(const char *src) int softnic_parser_read_arg_bool(const char *p); +int softnic_parser_read_int32(int32_t *value, const char *p); + int softnic_parser_read_uint64(uint64_t *value, const char *p); int softnic_parser_read_uint32(uint32_t *value, const char *p); int softnic_parser_read_uint16(uint16_t *value, const char *p); diff --git a/drivers/net/softnic/rte_eth_softnic_cli.c b/drivers/net/softnic/rte_eth_softnic_cli.c index 4a63b94520..0a9ec0169b 100644 --- a/drivers/net/softnic/rte_eth_softnic_cli.c +++ b/drivers/net/softnic/rte_eth_softnic_cli.c @@ -184,6 +184,93 @@ cmd_swq(struct pmd_internals *softnic, } } +/** + * tmgr shaper profile + * id + * rate size + * adj + */ +static void +cmd_tmgr_shaper_profile(struct pmd_internals *softnic, + char **tokens, + uint32_t n_tokens, + char *out, + size_t out_size) +{ + struct rte_tm_shaper_params sp; + struct rte_tm_error error; + uint32_t shaper_profile_id; + uint16_t port_id; + int status; + + memset(&sp, 0, sizeof(struct rte_tm_shaper_params)); + + if (n_tokens != 11) { + snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]); + return; + } + + if (strcmp(tokens[1], "shaper") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "shaper"); + return; + } + + if (strcmp(tokens[2], "profile") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile"); + return; + } + + if (strcmp(tokens[3], "id") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "id"); + return; + } + + if (softnic_parser_read_uint32(&shaper_profile_id, tokens[4]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "profile_id"); + return; + } + + if (strcmp(tokens[5], "rate") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate"); + return; + } + + if (softnic_parser_read_uint64(&sp.peak.rate, tokens[6]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate"); + return; + } + + if (strcmp(tokens[7], "size") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size"); + return; + } + + if (softnic_parser_read_uint64(&sp.peak.size, tokens[8]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "tb_size"); + return; + } + + if (strcmp(tokens[9], "adj") != 0) { + snprintf(out, out_size, MSG_ARG_NOT_FOUND, "adj"); + return; + } + + if (softnic_parser_read_int32(&sp.pkt_length_adjust, tokens[10]) != 0) { + snprintf(out, out_size, MSG_ARG_INVALID, "packet_length_adjust"); + return; + } + + status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id); + if (status) + return; + + status = rte_tm_shaper_profile_add(port_id, shaper_profile_id, &sp, &error); + if (status != 0) { + snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]); + return; + } +} + /** * tmgr */ @@ -3983,8 +4070,17 @@ softnic_cli_process(char *in, char *out, size_t out_size, void *arg) } if (strcmp(tokens[0], "tmgr") == 0) { - cmd_tmgr(softnic, tokens, n_tokens, out, out_size); - return; + if (n_tokens == 2) { + cmd_tmgr(softnic, tokens, n_tokens, out, out_size); + return; + } + + if (n_tokens >= 3 && + (strcmp(tokens[1], "shaper") == 0) && + (strcmp(tokens[2], "profile") == 0)) { + cmd_tmgr_shaper_profile(softnic, tokens, n_tokens, out, out_size); + return; + } } if (strcmp(tokens[0], "tap") == 0) {