X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=VNFs%2FDPPD-PROX%2Fcmd_parser.c;h=7df6b1630e72ae779591f09d677ac0d25482d1ea;hb=843ca042cad997b51390bd6156d3200de18294d2;hp=95688477471ac4b90d991ebec4fb831d0c53e9c0;hpb=4eca0440aee462f842567d5ef8b8796c27f4dd1b;p=samplevnf.git diff --git a/VNFs/DPPD-PROX/cmd_parser.c b/VNFs/DPPD-PROX/cmd_parser.c index 95688477..7df6b163 100644 --- a/VNFs/DPPD-PROX/cmd_parser.c +++ b/VNFs/DPPD-PROX/cmd_parser.c @@ -51,6 +51,7 @@ #include "stats_latency.h" #include "handle_cgnat.h" #include "handle_impair.h" +#include "rx_pkt.h" static int core_task_is_valid(int lcore_id, int task_id) { @@ -75,24 +76,13 @@ static int cores_task_are_valid(unsigned int *lcores, int task_id, unsigned int unsigned int lcore_id; for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if (lcore_id >= RTE_MAX_LCORE) { - plog_err("Invalid core id %u (lcore ID above %d)\n", lcore_id, RTE_MAX_LCORE); + if (core_task_is_valid(lcore_id, task_id) == 0) return 0; - } - else if (!prox_core_active(lcore_id, 0)) { - plog_err("Invalid core id %u (lcore is not active)\n", lcore_id); - return 0; - } - else if (task_id >= lcore_cfg[lcore_id].n_tasks_all) { - plog_err("Invalid task id (valid task IDs for core %u are below %u)\n", - lcore_id, lcore_cfg[lcore_id].n_tasks_all); - return 0; - } } return 1; } -static int parse_core_task(const char *str, uint32_t *lcore_id, uint32_t *task_id, unsigned int *nb_cores) +static int parse_cores_task(const char *str, uint32_t *lcore_id, uint32_t *task_id, unsigned *nb_cores) { char str_lcore_id[128]; int ret; @@ -109,6 +99,29 @@ static int parse_core_task(const char *str, uint32_t *lcore_id, uint32_t *task_i return 0; } +static int parse_cores_tasks(const char *str, uint32_t *lcore_id, uint32_t *task_id, unsigned *nb_cores, unsigned *nb_tasks) +{ + char str_lcore_id[128], str_task_id[128]; + int ret; + + if (2 != sscanf(str, "%s %s", str_lcore_id, str_task_id)) + return -1; + + if ((ret = parse_list_set(lcore_id, str_lcore_id, RTE_MAX_LCORE)) <= 0) { + plog_err("Invalid core while parsing command (%s)\n", get_parse_err()); + return -1; + } + *nb_cores = ret; + + if ((ret = parse_list_set(task_id, str_task_id, MAX_TASKS_PER_CORE)) <= 0) { + plog_err("Invalid task while parsing command (%s)\n", get_parse_err()); + return -1; + } + *nb_tasks = ret; + + return 0; +} + static const char *strchr_skip_twice(const char *str, int chr) { str = strchr(str, chr); @@ -206,7 +219,7 @@ static int parse_cmd_trace(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -225,7 +238,7 @@ static int parse_cmd_dump_rx(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -235,6 +248,22 @@ static int parse_cmd_dump_rx(const char *str, struct input *input) if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { + if (lcores[i] > RTE_MAX_LCORE) { + plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE); + return -1; + } else if (task_id >= lcore_cfg[lcores[i]].n_tasks_all) { + plog_warn("task_id too high, should be in [0, %u]\n", lcore_cfg[lcores[i]].n_tasks_all - 1); + return -1; + } else { + struct lcore_cfg *lconf = &lcore_cfg[lcores[i]]; + struct task_base *tbase = lconf->tasks_all[task_id]; + int prev_count = tbase->aux->rx_prev_count; + if (((prev_count) && (tbase->aux->rx_pkt_prev[prev_count - 1] == rx_pkt_dummy)) + || (tbase->rx_pkt == rx_pkt_dummy)) { + plog_warn("Unable to dump_rx as rx_pkt_dummy\n"); + return -1; + } + } cmd_dump(lcores[i], task_id, nb_packets, input, 1, 0); } } @@ -256,7 +285,7 @@ static int parse_cmd_dump_tx(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -308,18 +337,25 @@ static int parse_cmd_rate(const char *str, struct input *input) return 0; } -int task_is_mode(uint32_t lcore_id, uint32_t task_id, const char *mode, const char *sub_mode) +int task_is_mode_and_submode(uint32_t lcore_id, uint32_t task_id, const char *mode, const char *sub_mode) +{ + struct task_args *targs = &lcore_cfg[lcore_id].targs[task_id]; + + return !strcmp(targs->task_init->mode_str, mode) && !strcmp(targs->sub_mode_str, sub_mode); +} + +int task_is_mode(uint32_t lcore_id, uint32_t task_id, const char *mode) { struct task_init *t = lcore_cfg[lcore_id].targs[task_id].task_init; - return !strcmp(t->mode_str, mode) && !strcmp(t->sub_mode_str, sub_mode); + return !strcmp(t->mode_str, mode); } int task_is_sub_mode(uint32_t lcore_id, uint32_t task_id, const char *sub_mode) { - struct task_init *t = lcore_cfg[lcore_id].targs[task_id].task_init; + struct task_args *targs = &lcore_cfg[lcore_id].targs[task_id]; - return !strcmp(t->sub_mode_str, sub_mode); + return !strcmp(targs->sub_mode_str, sub_mode); } static void log_pkt_count(uint32_t count, uint32_t lcore_id, uint32_t task_id) @@ -336,7 +372,7 @@ static int parse_cmd_count(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, count, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -346,7 +382,7 @@ static int parse_cmd_count(const char *str, struct input *input) if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) { + if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) { plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id); } else { @@ -365,7 +401,7 @@ static int parse_cmd_set_probability(const char *str, struct input *input) unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; float probability; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -375,11 +411,12 @@ static int parse_cmd_set_probability(const char *str, struct input *input) if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if (!task_is_mode(lcore_id, task_id, "impair", "")) { + if ((!task_is_mode_and_submode(lcore_id, task_id, "impair", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "impair", "l3"))){ plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id); + } else { + struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; + task_impair_set_proba(tbase, probability); } - struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; - task_impair_set_proba(tbase, probability); } } return 0; @@ -389,7 +426,7 @@ static int parse_cmd_delay_us(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, delay_us, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -399,11 +436,12 @@ static int parse_cmd_delay_us(const char *str, struct input *input) if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if (!task_is_mode(lcore_id, task_id, "impair", "")) { + if ((!task_is_mode_and_submode(lcore_id, task_id, "impair", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "impair", "l3"))){ plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id); + } else { + struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; + task_impair_set_delay_us(tbase, delay_us, 0); } - struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; - task_impair_set_delay_us(tbase, delay_us, 0); } } return 0; @@ -413,7 +451,7 @@ static int parse_cmd_random_delay_us(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, delay_us, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -423,11 +461,12 @@ static int parse_cmd_random_delay_us(const char *str, struct input *input) if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if (!task_is_mode(lcore_id, task_id, "impair", "")) { + if ((!task_is_mode_and_submode(lcore_id, task_id, "impair", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "impair", "l3"))){ plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id); + } else { + struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; + task_impair_set_delay_us(tbase, 0, delay_us); } - struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; - task_impair_set_delay_us(tbase, 0, delay_us); } } return 0; @@ -437,7 +476,7 @@ static int parse_cmd_bypass(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if ((prox_cfg.flags & DSF_ENABLE_BYPASS) == 0) { plog_err("enable bypass not set => command not supported\n"); @@ -458,7 +497,7 @@ static int parse_cmd_reconnect(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { @@ -474,7 +513,7 @@ static int parse_cmd_pkt_size(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -484,13 +523,12 @@ static int parse_cmd_pkt_size(const char *str, struct input *input) if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) { + if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) { plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id); + } else { + struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; + task_gen_set_pkt_size(tbase, pkt_size); /* error printed within function */ } - struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; - - if (task_gen_set_pkt_size(tbase, pkt_size) != 0) - return -1; } } return 0; @@ -502,7 +540,7 @@ static int parse_cmd_speed(const char *str, struct input *input) float speed; unsigned i; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -516,11 +554,11 @@ static int parse_cmd_speed(const char *str, struct input *input) for (i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) { + if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) { plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id); } - else if (speed > 400.0f || speed < 0.0f) { - plog_err("Speed out of range (must be betweeen 0%% and 100%%)\n"); + else if (speed > 1000.0f || speed < 0.0f) { // Up to 100 Gbps + plog_err("Speed out of range (must be betweeen 0%% and 1000%%)\n"); } else { struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; @@ -539,7 +577,7 @@ static int parse_cmd_speed_byte(const char *str, struct input *input) unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; uint64_t bps; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -550,11 +588,11 @@ static int parse_cmd_speed_byte(const char *str, struct input *input) for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) { + if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) { plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id); } - else if (bps > 1250000000) { - plog_err("Speed out of range (must be <= 1250000000)\n"); + else if (bps > 12500000000) { // Up to 100Gbps + plog_err("Speed out of range (must be <= 12500000000)\n"); } else { struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; @@ -576,7 +614,7 @@ static int parse_cmd_reset_randoms_all(const char *str, struct input *input) unsigned task_id, lcore_id = -1; while (prox_core_next(&lcore_id, 0) == 0) { for (task_id = 0; task_id < lcore_cfg[lcore_id].n_tasks_all; task_id++) { - if ((task_is_mode(lcore_id, task_id, "gen", "")) || (task_is_mode(lcore_id, task_id, "gen", "l3"))) { + if ((task_is_mode_and_submode(lcore_id, task_id, "gen", "")) || (task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) { struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; uint32_t n_rands = task_gen_get_n_randoms(tbase); @@ -597,7 +635,7 @@ static int parse_cmd_reset_values_all(const char *str, struct input *input) unsigned task_id, lcore_id = -1; while (prox_core_next(&lcore_id, 0) == 0) { for (task_id = 0; task_id < lcore_cfg[lcore_id].n_tasks_all; task_id++) { - if ((task_is_mode(lcore_id, task_id, "gen", "")) || (task_is_mode(lcore_id, task_id, "gen", "l3"))) { + if ((task_is_mode_and_submode(lcore_id, task_id, "gen", "")) || (task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) { struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; plog_info("Resetting values on core %d task %d\n", lcore_id, task_id); @@ -612,13 +650,13 @@ static int parse_cmd_reset_values(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) { + if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) { plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id); } else { @@ -638,7 +676,7 @@ static int parse_cmd_set_value(const char *str, struct input *input) unsigned short offset; uint8_t value_len; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -649,7 +687,7 @@ static int parse_cmd_set_value(const char *str, struct input *input) if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) { + if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) { plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id); } else if (offset > ETHER_MAX_LEN) { @@ -679,7 +717,7 @@ static int parse_cmd_set_random(const char *str, struct input *input) char rand_str[64]; int16_t rand_id = -1; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -690,7 +728,7 @@ static int parse_cmd_set_random(const char *str, struct input *input) if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) { + if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) { plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id); } else if (offset > ETHER_MAX_LEN) { @@ -714,7 +752,7 @@ static int parse_cmd_thread_info(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; for (unsigned int i = 0; i < nb_cores; i++) { cmd_thread_info(lcores[i], task_id); @@ -743,7 +781,7 @@ static int parse_cmd_arp_add(const char *str, struct input *input) unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; struct rte_ring *ring; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -777,7 +815,7 @@ static int parse_cmd_rule_add(const char *str, struct input *input) struct rte_ring *ring; unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -821,7 +859,7 @@ static int parse_cmd_gateway_ip(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, ip[4], nb_cores, i; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -832,14 +870,15 @@ static int parse_cmd_gateway_ip(const char *str, struct input *input) } for (i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) { - plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id); + + if (!task_is_sub_mode(lcore_id, task_id, "l3")) { + plog_err("Core %u task %u is not in l3 mode\n", lcore_id, task_id); } else { uint32_t gateway_ip = ((ip[3] & 0xFF) << 24) | ((ip[2] & 0xFF) << 16) | ((ip[1] & 0xFF) << 8) | ((ip[0] & 0xFF) << 0); struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; plog_info("Setting gateway ip to %s\n", str); - task_gen_set_gateway_ip(tbase, gateway_ip); + task_set_gateway_ip(tbase, gateway_ip); } } return 0; @@ -849,7 +888,7 @@ static int parse_cmd_local_ip(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, ip[4], nb_cores, i; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -860,12 +899,16 @@ static int parse_cmd_local_ip(const char *str, struct input *input) } for (i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if (!task_is_mode(lcore_id, task_id, "arp", "local")) { - plog_err("Core %u task %u is not in arp mode\n", lcore_id, task_id); - } - else { - uint32_t local_ip = ((ip[3] & 0xFF) << 24) | ((ip[2] & 0xFF) << 16) | ((ip[1] & 0xFF) << 8) | ((ip[0] & 0xFF) << 0); - struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; + struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id]; + uint32_t local_ip = ((ip[3] & 0xFF) << 24) | ((ip[2] & 0xFF) << 16) | ((ip[1] & 0xFF) << 8) | ((ip[0] & 0xFF) << 0); + if (!task_is_mode_and_submode(lcore_id, task_id, "arp", "local")) { + if (!task_is_sub_mode(lcore_id, task_id, "l3")) { + plog_err("Core %u task %u is not in l3 mode\n", lcore_id, task_id); + } else { + plog_info("Setting local ip to %s\n", str); + task_set_local_ip(tbase, local_ip); + } + } else { plog_info("Setting local ip to %s\n", str); task_arp_set_local_ip(tbase, local_ip); } @@ -877,7 +920,7 @@ static int parse_cmd_route_add(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, prefix, next_hop_idx, ip[4], nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -1510,7 +1553,7 @@ static int parse_cmd_ring_info(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], task_id, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (cores_task_are_valid(lcores, task_id, nb_cores)) { @@ -1551,11 +1594,54 @@ static int parse_cmd_port_stats(const char *str, struct input *input) return 0; } +static int parse_cmd_multi_port_stats(const char *str, struct input *input) +{ + uint32_t ports[PROX_MAX_PORTS]; + int nb_ports = parse_list_set(ports, str, PROX_MAX_PORTS); + if (nb_ports <= 0) { + return -1; + } + + char buf[PROX_MAX_PORTS * (11+5*21) + 1], *pbuf = buf; + int left = sizeof(buf); + for (int i = 0; i < nb_ports; ++i) { + struct get_port_stats s; + if (stats_port(ports[i], &s)) { + plog_err("Invalid port %u\n", ports[i]); + return 0; + } + + int len = snprintf(pbuf, left, + "%u," + "%"PRIu64",%"PRIu64"," + "%"PRIu64",%"PRIu64"," + "%"PRIu64";", + //TODO: adjust buf size above when adding fields + ports[i], + s.rx_tot, s.tx_tot, + s.no_mbufs_tot, s.ierrors_tot + s.imissed_tot, + s.last_tsc); + if ((len < 0) || (len >= left)) { + plog_err("Cannot print stats for port %u\n", ports[i]); + return 0; + } + pbuf += len; + left -= len; + } + pbuf--; + *pbuf = '\n'; + + plog_info("%s", buf); + if (input->reply) + input->reply(input, buf, sizeof(buf) - left); + return 0; +} + static int parse_cmd_core_stats(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (cores_task_are_valid(lcores, task_id, nb_cores)) { @@ -1582,22 +1668,115 @@ static int parse_cmd_core_stats(const char *str, struct input *input) return 0; } +static int parse_cmd_dp_core_stats(const char *str, struct input *input) +{ + unsigned lcores[RTE_MAX_LCORE], tasks[MAX_TASKS_PER_CORE], lcore_id, task_id, nb_cores, nb_tasks; + + // This function either outputs a single line, in case of syntax error on the lists of cores and/or tasks + if (parse_cores_tasks(str, lcores, tasks, &nb_cores, &nb_tasks)) { + if (input->reply) { + char buf[128]; + snprintf(buf, sizeof(buf), "error: invalid syntax\n"); + input->reply(input, buf, strlen(buf)); + } + return -1; + } + + // or outputs (nb_cores * nb_tasks) lines, one line for each core/task pair: + // - if the core/task pair is invalid, the output line reports an error + // - otherwise, the output line provides the dataplane statistics for the core/task pair + for (unsigned int i = 0; i < nb_cores; i++) { + for (unsigned int j = 0; j < nb_tasks; j++) { + lcore_id = lcores[i]; + task_id = tasks[j]; + if (core_task_is_valid(lcore_id, task_id) == 0) { + if (input->reply) { + char buf[128]; + snprintf(buf, sizeof(buf), "error: invalid core %u, task %u\n", lcore_id, task_id); + input->reply(input, buf, strlen(buf)); + } else { + plog_info("error: invalid core %u, task %u\n", lcore_id, task_id); + } + continue; + } + uint64_t tot_rx = stats_core_task_tot_rx(lcore_id, task_id); + uint64_t tot_tx = stats_core_task_tot_tx(lcore_id, task_id); + uint64_t tot_tx_fail = stats_core_task_tot_tx_fail(lcore_id, task_id); + uint64_t tot_rx_non_dp = stats_core_task_tot_rx_non_dp(lcore_id, task_id); + uint64_t tot_tx_non_dp = stats_core_task_tot_tx_non_dp(lcore_id, task_id); + uint64_t tot_drop = stats_core_task_tot_drop(lcore_id, task_id); + uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id); + + if (input->reply) { + char buf[128]; + snprintf(buf, sizeof(buf), + "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%u,%u\n", + tot_rx, tot_tx, tot_rx_non_dp, tot_tx_non_dp, tot_drop, tot_tx_fail, last_tsc, rte_get_tsc_hz(), lcore_id, task_id); + input->reply(input, buf, strlen(buf)); + } + else { + plog_info("core: %u, task: %u, RX: %"PRIu64", TX: %"PRIu64", RX_NON_DP: %"PRIu64", TX_NON_DP: %"PRIu64", DROP: %"PRIu64", TX_FAIL: %"PRIu64"\n", + lcore_id, task_id, tot_rx, tot_tx, tot_rx_non_dp, tot_tx_non_dp, tot_drop, tot_tx_fail); + } + } + } + return 0; +} + static int parse_cmd_lat_stats(const char *str, struct input *input) { - unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; + unsigned lcores[RTE_MAX_LCORE], tasks[MAX_TASKS_PER_CORE], lcore_id, task_id, nb_cores, nb_tasks; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + // This function either outputs a single line, in case of syntax error on the lists of cores and/or tasks + if (parse_cores_tasks(str, lcores, tasks, &nb_cores, &nb_tasks)) { + if (input->reply) { + char buf[128]; + snprintf(buf, sizeof(buf), "error: invalid syntax\n"); + input->reply(input, buf, strlen(buf)); + } return -1; + } - if (cores_task_are_valid(lcores, task_id, nb_cores)) { - for (unsigned int i = 0; i < nb_cores; i++) { + // or outputs (nb_cores * nb_tasks) lines, one line for each core/task pair: + // - if the core/task pair is invalid, the output line reports an error + // - otherwise, the output line provides the latency statistics for the core/task pair + for (unsigned int i = 0; i < nb_cores; i++) { + for (unsigned int j = 0; j < nb_tasks; j++) { lcore_id = lcores[i]; - if (!task_is_mode(lcore_id, task_id, "lat", "")) { - plog_err("Core %u task %u is not measuring latency\n", lcore_id, task_id); + task_id = tasks[j]; + if (core_task_is_valid(lcore_id, task_id) == 0) { + if (input->reply) { + char buf[128]; + snprintf(buf, sizeof(buf), "error: invalid core %u, task %u\n", lcore_id, task_id); + input->reply(input, buf, strlen(buf)); + } else { + plog_info("error: invalid core %u, task %u\n", lcore_id, task_id); + } + } else if (!task_is_mode(lcore_id, task_id, "lat")) { + if (input->reply) { + char buf[128]; + snprintf(buf, sizeof(buf), "error: core %u task %u is not measuring latency\n", lcore_id, task_id); + input->reply(input, buf, strlen(buf)); + } else { + plog_info("error: core %u task %u is not measuring latency\n", lcore_id, task_id); + } } else { struct stats_latency *stats = stats_latency_find(lcore_id, task_id); struct stats_latency *tot = stats_latency_tot_find(lcore_id, task_id); + if (!stats || !tot) { + if (input->reply) { + char buf[128]; + snprintf(buf, sizeof(buf), + "error: core %u task %u stats = %p tot = %p\n", + lcore_id, task_id, stats, tot); + input->reply(input, buf, strlen(buf)); + } else { + plog_info("error: core %u task %u stats = %p tot = %p\n", + lcore_id, task_id, stats, tot); + } + continue; + } uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id); uint64_t lat_min_usec = time_unit_to_usec(&stats->min.time); @@ -1609,18 +1788,22 @@ static int parse_cmd_lat_stats(const char *str, struct input *input) if (input->reply) { char buf[128]; snprintf(buf, sizeof(buf), - "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n", + "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%u,%u\n", lat_min_usec, lat_max_usec, lat_avg_usec, tot_lat_min_usec, tot_lat_max_usec, last_tsc, - rte_get_tsc_hz()); + rte_get_tsc_hz(), + lcore_id, + task_id); input->reply(input, buf, strlen(buf)); } else { - plog_info("min: %"PRIu64", max: %"PRIu64", avg: %"PRIu64", min since reset: %"PRIu64", max since reset: %"PRIu64"\n", + plog_info("core: %u, task: %u, min: %"PRIu64", max: %"PRIu64", avg: %"PRIu64", min since reset: %"PRIu64", max since reset: %"PRIu64"\n", + lcore_id, + task_id, lat_min_usec, lat_max_usec, lat_avg_usec, @@ -1633,18 +1816,40 @@ static int parse_cmd_lat_stats(const char *str, struct input *input) return 0; } +static int parse_cmd_show_irq_buckets(const char *str, struct input *input) +{ + char buf[4096] = {0}; + unsigned int i, c; + unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; + + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) + return -1; + + if (cores_task_are_valid(lcores, task_id, nb_cores)) { + for (c = 0; c < nb_cores; c++) { + lcore_id = lcores[c]; + get_irq_buckets_by_core_task(buf, lcore_id, task_id); + plog_info("%s", buf); + if (input->reply) + input->reply(input, buf, strlen(buf)); + buf[0] = 0; + } + } + return 0; +} + static int parse_cmd_irq(const char *str, struct input *input) { unsigned int i, c; unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (c = 0; c < nb_cores; c++) { lcore_id = lcores[c]; - if (!task_is_mode(lcore_id, task_id, "irq", "")) { + if (!task_is_mode(lcore_id, task_id, "irq")) { plog_err("Core %u task %u is not in irq mode\n", lcore_id, task_id); } else { struct task_irq *task_irq = (struct task_irq *)(lcore_cfg[lcore_id].tasks_all[task_id]); @@ -1686,13 +1891,13 @@ static int parse_cmd_lat_packets(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if (!task_is_mode(lcore_id, task_id, "lat", "")) { + if (!task_is_mode(lcore_id, task_id, "lat")) { plog_err("Core %u task %u is not measuring latency\n", lcore_id, task_id); } else { @@ -1707,14 +1912,14 @@ static int parse_cmd_cgnat_public_hash(const char *str, struct input *input) { unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if (!task_is_mode(lcore_id, task_id, "cgnat", "")) { + if (!task_is_mode(lcore_id, task_id, "cgnat")) { plog_err("Core %u task %u is not cgnat\n", lcore_id, task_id); } else { @@ -1731,14 +1936,14 @@ static int parse_cmd_cgnat_private_hash(const char *str, struct input *input) unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; uint32_t val; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (cores_task_are_valid(lcores, task_id, nb_cores)) { for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if (!task_is_mode(lcore_id, task_id, "cgnat", "")) { + if (!task_is_mode(lcore_id, task_id, "cgnat")) { plog_err("Core %u task %u is not cgnat\n", lcore_id, task_id); } else { @@ -1755,7 +1960,7 @@ static int parse_cmd_accuracy(const char *str, struct input *input) unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores; uint32_t val; - if (parse_core_task(str, lcores, &task_id, &nb_cores)) + if (parse_cores_task(str, lcores, &task_id, &nb_cores)) return -1; if (!(str = strchr_skip_twice(str, ' '))) return -1; @@ -1766,7 +1971,7 @@ static int parse_cmd_accuracy(const char *str, struct input *input) for (unsigned int i = 0; i < nb_cores; i++) { lcore_id = lcores[i]; - if (!task_is_mode(lcore_id, task_id, "lat", "")) { + if (!task_is_mode(lcore_id, task_id, "lat")) { plog_err("Core %u task %u is not measuring latency\n", lcore_id, task_id); } else { @@ -1875,10 +2080,13 @@ static struct cmd_str cmd_strings[] = { {"tot imissed tot", "", "Print total number of imissed since reset", parse_cmd_tot_imissed_tot}, {"lat stats", " ", "Print min,max,avg latency as measured during last sampling interval", parse_cmd_lat_stats}, {"irq stats", " ", "Print irq related infos", parse_cmd_irq}, + {"show irq buckets", " ", "Print irq buckets", parse_cmd_show_irq_buckets}, {"lat packets", " ", "Print the latency for each of the last set of packets", parse_cmd_lat_packets}, {"accuracy limit", " ", "Only consider latency of packets that were measured with an error no more than ", parse_cmd_accuracy}, {"core stats", " ", "Print rx/tx/drop for task running on core ", parse_cmd_core_stats}, + {"dp core stats", " ", "Print rx/tx/non_dp_rx/non_dp_tx/drop for task running on core ", parse_cmd_dp_core_stats}, {"port_stats", "", "Print rate for no_mbufs, ierrors + imissed, rx_bytes, tx_bytes, rx_pkts, tx_pkts; totals for RX, TX, no_mbufs, ierrors + imissed for port ", parse_cmd_port_stats}, + {"multi port stats", "", "Get stats for multiple ports, semi-colon separated: port id, total for rx_pkts, tx_pkts, no_mbufs, ierrors + imissed, last_tsc", parse_cmd_multi_port_stats}, {"read reg", "", "Read register", parse_cmd_read_reg}, {"write reg", "", "Read register", parse_cmd_write_reg}, {"set vlan offload", "", "Set Vlan offload", parse_cmd_set_vlan_offload}, @@ -1897,7 +2105,7 @@ static struct cmd_str cmd_strings[] = { {"port down", "", "Set the port down", parse_cmd_port_down}, {"port link state", "", "Get link state (up or down) for port", parse_cmd_port_link_state}, {"port xstats", "", "Get extra statistics for the port", parse_cmd_xstats}, - {"stats", "", "Get stats as sepcified by . A comma-separated list of can be supplied", parse_cmd_stats}, + {"stats", "", "Get stats as specified by . A comma-separated list of can be supplied", parse_cmd_stats}, {"cgnat dump public hash", " ", "Dump cgnat public hash table", parse_cmd_cgnat_public_hash}, {"cgnat dump private hash", " ", "Dump cgnat private hash table", parse_cmd_cgnat_private_hash}, {"delay_us", " ", "Set the delay in usec for the impair mode to ", parse_cmd_delay_us},