Fix extrapolation used in latency measurements
[samplevnf.git] / VNFs / DPPD-PROX / cmd_parser.c
index 388e362..0506fc5 100644 (file)
@@ -325,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)
@@ -363,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 {
@@ -392,12 +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", "")) && (!task_is_mode(lcore_id, task_id, "impair", "l3"))){
+                       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);
-                               return -1;
+                       } 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;
@@ -417,12 +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", "")) && (!task_is_mode(lcore_id, task_id, "impair", "l3"))){
+                       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);
-                               return -1;
+                       } 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;
@@ -442,12 +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", "")) && (!task_is_mode(lcore_id, task_id, "impair", "l3"))){
+                       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);
-                               return -1;
+                       } 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;
@@ -504,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;
@@ -536,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];
@@ -570,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];
@@ -596,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);
 
@@ -617,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);
@@ -638,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 {
@@ -669,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) {
@@ -710,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) {
@@ -883,7 +889,7 @@ static int parse_cmd_local_ip(const char *str, struct input *input)
                lcore_id = lcores[i];
                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(lcore_id, task_id, "arp", "local")) {
+               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 {
@@ -1617,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 {
@@ -1669,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]);
@@ -1717,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 {
@@ -1739,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 {
@@ -1763,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 {
@@ -1791,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 {