X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=VNFs%2FDPPD-PROX%2Fcmd_parser.c;h=0506fc522542bdc413638cf00ffcbbb76ca836af;hb=442501d625b6d05f38267d442fd4e42f6cebef7d;hp=95688477471ac4b90d991ebec4fb831d0c53e9c0;hpb=a0eb3c45ca8a89220caaefa43665a7a1eb6c1933;p=samplevnf.git diff --git a/VNFs/DPPD-PROX/cmd_parser.c b/VNFs/DPPD-PROX/cmd_parser.c index 95688477..0506fc52 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) { @@ -235,6 +236,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); } } @@ -308,18 +325,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) @@ -346,7 +370,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 { @@ -375,11 +399,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; @@ -399,11 +424,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; @@ -423,11 +449,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; @@ -484,13 +511,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; @@ -516,11 +542,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]; @@ -550,11 +576,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 +602,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 +623,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); @@ -618,7 +644,7 @@ static int parse_cmd_reset_values(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 { @@ -649,7 +675,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) { @@ -690,7 +716,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) { @@ -832,14 +858,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; @@ -860,12 +887,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); } @@ -1592,7 +1623,7 @@ static int parse_cmd_lat_stats(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, "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 { @@ -1644,7 +1675,7 @@ static int parse_cmd_irq(const char *str, struct input *input) 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]); @@ -1692,7 +1723,7 @@ static int parse_cmd_lat_packets(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, "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 { @@ -1714,7 +1745,7 @@ static int parse_cmd_cgnat_public_hash(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, "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 { @@ -1738,7 +1769,7 @@ static int parse_cmd_cgnat_private_hash(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, "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 { @@ -1766,7 +1797,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 {