2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
20 #include <rte_cycles.h>
21 #include <rte_version.h>
24 #include "cmd_parser.h"
30 #include "prox_port_cfg.h"
31 #include "task_base.h"
34 #include "parse_utils.h"
35 #include "stats_parser.h"
36 #include "stats_port.h"
37 #include "stats_latency.h"
38 #include "stats_global.h"
39 #include "stats_prio_task.h"
41 #include "handle_routing.h"
42 #include "handle_qinq_decap4.h"
43 #include "handle_lat.h"
44 #include "handle_arp.h"
45 #include "handle_gen.h"
46 #include "handle_acl.h"
47 #include "handle_irq.h"
51 #include "stats_latency.h"
52 #include "handle_cgnat.h"
53 #include "handle_impair.h"
56 static int core_task_is_valid(int lcore_id, int task_id)
58 if (lcore_id >= RTE_MAX_LCORE) {
59 plog_err("Invalid core id %u (lcore ID above %d)\n", lcore_id, RTE_MAX_LCORE);
62 else if (!prox_core_active(lcore_id, 0)) {
63 plog_err("Invalid core id %u (lcore is not active)\n", lcore_id);
66 else if (task_id >= lcore_cfg[lcore_id].n_tasks_all) {
67 plog_err("Invalid task id (valid task IDs for core %u are below %u)\n",
68 lcore_id, lcore_cfg[lcore_id].n_tasks_all);
74 static int cores_task_are_valid(unsigned int *lcores, int task_id, unsigned int nb_cores)
76 unsigned int lcore_id;
77 for (unsigned int i = 0; i < nb_cores; i++) {
79 if (core_task_is_valid(lcore_id, task_id) == 0)
85 static int parse_cores_task(const char *str, uint32_t *lcore_id, uint32_t *task_id, unsigned *nb_cores)
87 char str_lcore_id[128];
90 if (2 != sscanf(str, "%s %u", str_lcore_id, task_id))
93 if ((ret = parse_list_set(lcore_id, str_lcore_id, RTE_MAX_LCORE)) <= 0) {
94 plog_err("Invalid core while parsing command (%s)\n", get_parse_err());
102 static int parse_cores_tasks(const char *str, uint32_t *lcore_id, uint32_t *task_id, unsigned *nb_cores, unsigned *nb_tasks)
104 char str_lcore_id[128], str_task_id[128];
107 if (2 != sscanf(str, "%s %s", str_lcore_id, str_task_id))
110 if ((ret = parse_list_set(lcore_id, str_lcore_id, RTE_MAX_LCORE)) <= 0) {
111 plog_err("Invalid core while parsing command (%s)\n", get_parse_err());
116 if ((ret = parse_list_set(task_id, str_task_id, MAX_TASKS_PER_CORE)) <= 0) {
117 plog_err("Invalid task while parsing command (%s)\n", get_parse_err());
125 static const char *strchr_skip_twice(const char *str, int chr)
127 str = strchr(str, chr);
132 str = strchr(str, chr);
138 static int parse_cmd_quit(const char *str, struct input *input)
140 if (strcmp(str, "") != 0) {
148 static int parse_cmd_quit_force(const char *str, struct input *input)
150 if (strcmp(str, "") != 0) {
157 static int parse_cmd_history(const char *str, struct input *input)
159 if (strcmp(str, "") != 0) {
163 if (input->history) {
164 input->history(input);
167 plog_err("Invalid history comand ");
171 static int parse_cmd_echo(const char *str, struct input *input)
173 if (strcmp(str, "") == 0) {
179 if (parse_vars(resolved, sizeof(resolved), str)) {
184 if (strlen(resolved) + 2 < sizeof(resolved)) {
185 resolved[strlen(resolved) + 1] = 0;
186 resolved[strlen(resolved)] = '\n';
191 input->reply(input, resolved, strlen(resolved));
193 plog_info("%s\n", resolved);
198 static int parse_cmd_reset_stats(const char *str, struct input *input)
200 if (strcmp(str, "") != 0) {
208 static int parse_cmd_reset_lat_stats(const char *str, struct input *input)
210 if (strcmp(str, "") != 0) {
214 stats_latency_reset();
218 static int parse_cmd_trace(const char *str, struct input *input)
220 unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores;
222 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
224 if (!(str = strchr_skip_twice(str, ' ')))
226 if (sscanf(str, "%u", &nb_packets) != 1)
229 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
230 for (unsigned int i = 0; i < nb_cores; i++) {
231 cmd_trace(lcores[i], task_id, nb_packets);
237 static int parse_cmd_dump_rx(const char *str, struct input *input)
239 unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores;
241 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
243 if (!(str = strchr_skip_twice(str, ' ')))
245 if (sscanf(str, "%u", &nb_packets) != 1) {
249 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
250 for (unsigned int i = 0; i < nb_cores; i++) {
251 if (lcores[i] > RTE_MAX_LCORE) {
252 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
254 } else if (task_id >= lcore_cfg[lcores[i]].n_tasks_all) {
255 plog_warn("task_id too high, should be in [0, %u]\n", lcore_cfg[lcores[i]].n_tasks_all - 1);
258 struct lcore_cfg *lconf = &lcore_cfg[lcores[i]];
259 struct task_base *tbase = lconf->tasks_all[task_id];
260 int prev_count = tbase->aux->rx_prev_count;
261 if (((prev_count) && (tbase->aux->rx_pkt_prev[prev_count - 1] == rx_pkt_dummy))
262 || (tbase->rx_pkt == rx_pkt_dummy)) {
263 plog_warn("Unable to dump_rx as rx_pkt_dummy\n");
267 cmd_dump(lcores[i], task_id, nb_packets, input, 1, 0);
273 static int parse_cmd_pps_unit(const char *str, struct input *input)
277 if (sscanf(str, "%u", &val) != 1) {
280 display_set_pps_unit(val);
284 static int parse_cmd_dump_tx(const char *str, struct input *input)
286 unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores;
288 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
290 if (!(str = strchr_skip_twice(str, ' ')))
292 if (sscanf(str, "%u", &nb_packets) != 1) {
296 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
297 for (unsigned int i = 0; i < nb_cores; i++) {
298 cmd_dump(lcores[i], task_id, nb_packets, input, 0, 1);
304 static int parse_cmd_rate(const char *str, struct input *input)
306 unsigned queue, port, rate;
308 if (sscanf(str, "%u %u %u", &queue, &port, &rate) != 3) {
312 if (port > PROX_MAX_PORTS) {
313 plog_err("Max port id allowed is %u (specified %u)\n", PROX_MAX_PORTS, port);
315 else if (!prox_port_cfg[port].active) {
316 plog_err("Port %u not active\n", port);
318 else if (queue >= prox_port_cfg[port].n_txq) {
319 plog_err("Number of active queues is %u\n",
320 prox_port_cfg[port].n_txq);
322 else if (rate > prox_port_cfg[port].link_speed) {
323 plog_err("Max rate allowed on port %u queue %u is %u Mbps\n",
324 port, queue, prox_port_cfg[port].link_speed);
328 plog_info("Disabling rate limiting on port %u queue %u\n",
332 plog_info("Setting rate limiting to %u Mbps on port %u queue %u\n",
335 rte_eth_set_queue_rate_limit(port, queue, rate);
340 int task_is_mode_and_submode(uint32_t lcore_id, uint32_t task_id, const char *mode, const char *sub_mode)
342 struct task_args *targs = &lcore_cfg[lcore_id].targs[task_id];
344 return !strcmp(targs->task_init->mode_str, mode) && !strcmp(targs->sub_mode_str, sub_mode);
347 int task_is_mode(uint32_t lcore_id, uint32_t task_id, const char *mode)
349 struct task_init *t = lcore_cfg[lcore_id].targs[task_id].task_init;
351 return !strcmp(t->mode_str, mode);
354 int task_is_sub_mode(uint32_t lcore_id, uint32_t task_id, const char *sub_mode)
356 struct task_args *targs = &lcore_cfg[lcore_id].targs[task_id];
358 return !strcmp(targs->sub_mode_str, sub_mode);
361 static void log_pkt_count(uint32_t count, uint32_t lcore_id, uint32_t task_id)
363 if (count == UINT32_MAX)
364 plog_info("Core %u task %u will keep sending packets\n", lcore_id, task_id);
366 plog_info("Core %u task %u waits for next count command\n", lcore_id, task_id);
368 plog_info("Core %u task %u stopping after %u packets\n", lcore_id, task_id, count);
371 static int parse_cmd_count(const char *str, struct input *input)
373 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, count, nb_cores;
375 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
377 if (!(str = strchr_skip_twice(str, ' ')))
379 if (sscanf(str, "%u", &count) != 1)
382 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
383 for (unsigned int i = 0; i < nb_cores; i++) {
384 lcore_id = lcores[i];
385 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
386 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
389 struct task_base *task = lcore_cfg[lcore_id].tasks_all[task_id];
391 log_pkt_count(count, lcore_id, task_id);
392 task_gen_set_pkt_count(task, count);
399 static int parse_cmd_set_probability(const char *str, struct input *input)
401 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
404 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
406 if (!(str = strchr_skip_twice(str, ' ')))
408 if (sscanf(str, "%f", &probability) != 1)
411 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
412 for (unsigned int i = 0; i < nb_cores; i++) {
413 lcore_id = lcores[i];
414 if ((!task_is_mode_and_submode(lcore_id, task_id, "impair", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "impair", "l3"))){
415 plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id);
417 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
418 task_impair_set_proba(tbase, probability);
425 static int parse_cmd_delay_us(const char *str, struct input *input)
427 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, delay_us, nb_cores;
429 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
431 if (!(str = strchr_skip_twice(str, ' ')))
433 if (sscanf(str, "%d", &delay_us) != 1)
436 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
437 for (unsigned int i = 0; i < nb_cores; i++) {
438 lcore_id = lcores[i];
439 if ((!task_is_mode_and_submode(lcore_id, task_id, "impair", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "impair", "l3"))){
440 plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id);
442 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
443 task_impair_set_delay_us(tbase, delay_us, 0);
450 static int parse_cmd_random_delay_us(const char *str, struct input *input)
452 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, delay_us, nb_cores;
454 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
456 if (!(str = strchr_skip_twice(str, ' ')))
458 if (sscanf(str, "%d", &delay_us) != 1)
461 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
462 for (unsigned int i = 0; i < nb_cores; i++) {
463 lcore_id = lcores[i];
464 if ((!task_is_mode_and_submode(lcore_id, task_id, "impair", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "impair", "l3"))){
465 plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id);
467 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
468 task_impair_set_delay_us(tbase, 0, delay_us);
475 static int parse_cmd_bypass(const char *str, struct input *input)
477 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores;
479 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
481 if ((prox_cfg.flags & DSF_ENABLE_BYPASS) == 0) {
482 plog_err("enable bypass not set => command not supported\n");
486 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
487 for (unsigned int i = 0; i < nb_cores; i++) {
488 lcore_id = lcores[i];
489 if (bypass_task(lcore_id, task_id) != 0)
496 static int parse_cmd_reconnect(const char *str, struct input *input)
498 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores;
500 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
502 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
503 for (unsigned int i = 0; i < nb_cores; i++) {
504 lcore_id = lcores[i];
505 if (reconnect_task(lcore_id, task_id) != 0)
512 static int parse_cmd_pkt_size(const char *str, struct input *input)
514 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores;
516 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
518 if (!(str = strchr_skip_twice(str, ' ')))
520 if (sscanf(str, "%d", &pkt_size) != 1)
523 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
524 for (unsigned int i = 0; i < nb_cores; i++) {
525 lcore_id = lcores[i];
526 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
527 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
529 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
530 task_gen_set_pkt_size(tbase, pkt_size); /* error printed within function */
537 static int parse_cmd_speed(const char *str, struct input *input)
539 unsigned lcores[RTE_MAX_LCORE], task_id, lcore_id, nb_cores;
543 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
545 if (!(str = strchr_skip_twice(str, ' ')))
547 if (sscanf(str, "%f", &speed) != 1) {
551 if (!cores_task_are_valid(lcores, task_id, nb_cores)) {
555 for (i = 0; i < nb_cores; i++) {
556 lcore_id = lcores[i];
557 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
558 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
560 else if (speed > 1000.0f || speed < 0.0f) { // Up to 100 Gbps
561 plog_err("Speed out of range (must be betweeen 0%% and 1000%%)\n");
564 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
565 uint64_t bps = speed * 12500000;
567 plog_info("Setting rate to %"PRIu64" Bps\n", bps);
569 task_gen_set_rate(tbase, bps);
575 static int parse_cmd_speed_byte(const char *str, struct input *input)
577 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
580 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
582 if (!(str = strchr_skip_twice(str, ' ')))
584 if (sscanf(str, "%"PRIu64"", &bps) != 1)
587 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
588 for (unsigned int i = 0; i < nb_cores; i++) {
589 lcore_id = lcores[i];
591 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
592 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
594 else if (bps > 12500000000) { // Up to 100Gbps
595 plog_err("Speed out of range (must be <= 12500000000)\n");
598 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
600 plog_info("Setting rate to %"PRIu64" Bps\n", bps);
601 task_gen_set_rate(tbase, bps);
608 static int parse_cmd_reset_randoms_all(const char *str, struct input *input)
610 if (strcmp(str, "") != 0) {
614 unsigned task_id, lcore_id = -1;
615 while (prox_core_next(&lcore_id, 0) == 0) {
616 for (task_id = 0; task_id < lcore_cfg[lcore_id].n_tasks_all; task_id++) {
617 if ((task_is_mode_and_submode(lcore_id, task_id, "gen", "")) || (task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
618 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
619 uint32_t n_rands = task_gen_get_n_randoms(tbase);
621 plog_info("Resetting randoms on core %d task %d from %d randoms\n", lcore_id, task_id, n_rands);
622 task_gen_reset_randoms(tbase);
629 static int parse_cmd_reset_values_all(const char *str, struct input *input)
631 if (strcmp(str, "") != 0) {
635 unsigned task_id, lcore_id = -1;
636 while (prox_core_next(&lcore_id, 0) == 0) {
637 for (task_id = 0; task_id < lcore_cfg[lcore_id].n_tasks_all; task_id++) {
638 if ((task_is_mode_and_submode(lcore_id, task_id, "gen", "")) || (task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
639 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
641 plog_info("Resetting values on core %d task %d\n", lcore_id, task_id);
642 task_gen_reset_values(tbase);
649 static int parse_cmd_reset_values(const char *str, struct input *input)
651 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
653 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
656 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
657 for (unsigned int i = 0; i < nb_cores; i++) {
658 lcore_id = lcores[i];
659 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
660 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
663 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
665 plog_info("Resetting values on core %d task %d\n", lcore_id, task_id);
666 task_gen_reset_values(tbase);
673 static int parse_cmd_set_value(const char *str, struct input *input)
675 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, value, nb_cores;
676 unsigned short offset;
679 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
681 if (!(str = strchr_skip_twice(str, ' ')))
683 if (sscanf(str, "%hu %u %hhu", &offset, &value, &value_len) != 3) {
687 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
688 for (unsigned int i = 0; i < nb_cores; i++) {
689 lcore_id = lcores[i];
690 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
691 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
693 else if (offset > ETHER_MAX_LEN) {
694 plog_err("Offset out of range (must be less then %u)\n", ETHER_MAX_LEN);
696 else if (value_len > 4) {
697 plog_err("Length out of range (must be less then 4)\n");
700 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
702 if (task_gen_set_value(tbase, value, offset, value_len))
703 plog_info("Unable to set Byte %"PRIu16" to %"PRIu8" - too many value set\n", offset, value);
705 plog_info("Setting Byte %"PRIu16" to %"PRIu32"\n", offset, value);
712 static int parse_cmd_set_random(const char *str, struct input *input)
714 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
715 unsigned short offset;
718 int16_t rand_id = -1;
720 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
722 if (!(str = strchr_skip_twice(str, ' ')))
724 if (sscanf(str, "%hu %32s %hhu", &offset, rand_str, &value_len) != 3) {
728 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
729 for (unsigned int i = 0; i < nb_cores; i++) {
730 lcore_id = lcores[i];
731 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
732 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
734 else if (offset > ETHER_MAX_LEN) {
735 plog_err("Offset out of range (must be less then %u)\n", ETHER_MAX_LEN);
737 else if (value_len > 4) {
738 plog_err("Length out of range (must be less then 4)\n");
740 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
742 if (task_gen_add_rand(tbase, rand_str, offset, rand_id)) {
743 plog_warn("Random not added on core %u task %u\n", lcore_id, task_id);
751 static int parse_cmd_thread_info(const char *str, struct input *input)
753 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
755 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
757 for (unsigned int i = 0; i < nb_cores; i++) {
758 cmd_thread_info(lcores[i], task_id);
763 static int parse_cmd_verbose(const char *str, struct input *input)
767 if (sscanf(str, "%u", &id) != 1) {
771 if (plog_set_lvl(id) != 0) {
772 plog_err("Cannot set log level to %u\n", id);
777 static int parse_cmd_arp_add(const char *str, struct input *input)
780 struct arp_msg *pmsg = &amsg;
781 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
782 struct rte_ring *ring;
784 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
786 if (!(str = strchr_skip_twice(str, ' ')))
790 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
791 if (str_to_arp_msg(&amsg, str) == 0) {
792 for (unsigned int i = 0; i < nb_cores; i++) {
793 lcore_id = lcores[i];
794 ring = ctrl_rings[lcore_id*MAX_TASKS_PER_CORE + task_id];
796 plog_err("No ring for control messages to core %u task %u\n", lcore_id, task_id);
799 #if RTE_VERSION < RTE_VERSION_NUM(17,5,0,1)
800 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&pmsg, 1));
802 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&pmsg, 1, NULL) == 0);
804 while (!rte_ring_empty(ring));
813 static int parse_cmd_rule_add(const char *str, struct input *input)
815 struct rte_ring *ring;
816 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
818 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
820 if (!(str = strchr_skip_twice(str, ' ')))
826 strncpy(str_cpy, str, 255);
827 // example add rule command: rule add 15 0 1&0x0fff 1&0x0fff 0&0 128.0.0.0/1 128.0.0.0/1 5000-5000 5000-5000 allow
828 int ret = rte_strsplit(str_cpy, 255, fields, 9, ' ');
833 struct acl4_rule rule;
834 struct acl4_rule *prule = &rule;
835 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
836 if (str_to_rule(&rule, fields, -1, 1) == 0) {
837 for (unsigned int i = 0; i < nb_cores; i++) {
838 lcore_id = lcores[i];
839 ring = ctrl_rings[lcore_id*MAX_TASKS_PER_CORE + task_id];
841 plog_err("No ring for control messages to core %u task %u\n", lcore_id, task_id);
844 #if RTE_VERSION < RTE_VERSION_NUM(17,5,0,1)
845 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&prule, 1));
847 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&prule, 1, NULL) == 0);
849 while (!rte_ring_empty(ring));
858 static int parse_cmd_gateway_ip(const char *str, struct input *input)
860 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, ip[4], nb_cores, i;
862 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
864 if (!(str = strchr_skip_twice(str, ' ')))
866 if (!strcmp(str, ""))
868 if (sscanf(str, "%u.%u.%u.%u", ip, ip + 1, ip + 2, ip + 3) != 4) {
871 for (i = 0; i < nb_cores; i++) {
872 lcore_id = lcores[i];
874 if (!task_is_sub_mode(lcore_id, task_id, "l3")) {
875 plog_err("Core %u task %u is not in l3 mode\n", lcore_id, task_id);
878 uint32_t gateway_ip = ((ip[3] & 0xFF) << 24) | ((ip[2] & 0xFF) << 16) | ((ip[1] & 0xFF) << 8) | ((ip[0] & 0xFF) << 0);
879 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
880 plog_info("Setting gateway ip to %s\n", str);
881 task_set_gateway_ip(tbase, gateway_ip);
887 static int parse_cmd_local_ip(const char *str, struct input *input)
889 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, ip[4], nb_cores, i;
891 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
893 if (!(str = strchr_skip_twice(str, ' ')))
895 if (!strcmp(str, ""))
897 if (sscanf(str, "%u.%u.%u.%u", ip, ip + 1, ip + 2, ip + 3) != 4) {
900 for (i = 0; i < nb_cores; i++) {
901 lcore_id = lcores[i];
902 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
903 uint32_t local_ip = ((ip[3] & 0xFF) << 24) | ((ip[2] & 0xFF) << 16) | ((ip[1] & 0xFF) << 8) | ((ip[0] & 0xFF) << 0);
904 if (!task_is_mode_and_submode(lcore_id, task_id, "arp", "local")) {
905 if (!task_is_sub_mode(lcore_id, task_id, "l3")) {
906 plog_err("Core %u task %u is not in l3 mode\n", lcore_id, task_id);
908 plog_info("Setting local ip to %s\n", str);
909 task_set_local_ip(tbase, local_ip);
912 plog_info("Setting local ip to %s\n", str);
913 task_arp_set_local_ip(tbase, local_ip);
919 static int parse_cmd_route_add(const char *str, struct input *input)
921 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, prefix, next_hop_idx, ip[4], nb_cores;
923 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
925 if (!(str = strchr_skip_twice(str, ' ')))
929 if (sscanf(str, "%u.%u.%u.%u/%u %u", ip, ip + 1, ip + 2, ip + 3,
930 &prefix, &next_hop_idx) != 8) {
933 struct rte_ring *ring;
935 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
936 for (unsigned int i = 0; i < nb_cores; i++) {
937 lcore_id = lcores[i];
938 ring = ctrl_rings[lcore_id*MAX_TASKS_PER_CORE + task_id];
940 plog_err("No ring for control messages to core %u task %u\n", lcore_id, task_id);
943 struct route_msg rmsg;
944 struct route_msg *pmsg = &rmsg;
946 rmsg.ip_bytes[0] = ip[0];
947 rmsg.ip_bytes[1] = ip[1];
948 rmsg.ip_bytes[2] = ip[2];
949 rmsg.ip_bytes[3] = ip[3];
950 rmsg.prefix = prefix;
951 rmsg.nh = next_hop_idx;
952 #if RTE_VERSION < RTE_VERSION_NUM(17,5,0,1)
953 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&pmsg, 1));
955 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&pmsg, 1, NULL) == 0);
957 while (!rte_ring_empty(ring));
964 static int parse_cmd_start(const char *str, struct input *input)
968 if (strncmp(str, "all", 3) == 0) {
970 sscanf(str, "%d", &task_id);
972 start_core_all(task_id);
977 uint32_t cores[64] = {0};
979 ret = parse_list_set(cores, str, 64);
983 str = strchr(str, ' ');
986 sscanf(str, "%d", &task_id);
988 start_cores(cores, ret, task_id);
993 static int parse_cmd_stop(const char *str, struct input *input)
997 if (strncmp(str, "all", 3) == 0) {
999 sscanf(str, "%d", &task_id);
1000 stop_core_all(task_id);
1005 uint32_t cores[64] = {0};
1007 ret = parse_list_set(cores, str, 64);
1011 str = strchr(str, ' ');
1014 sscanf(str, "%d", &task_id);
1016 stop_cores(cores, ret, task_id);
1022 static int parse_cmd_rx_distr_start(const char *str, struct input *input)
1024 unsigned lcore_id[RTE_MAX_LCORE];
1028 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1030 if (nb_cores <= 0) {
1034 for (int i = 0; i < nb_cores; ++i)
1035 cmd_rx_distr_start(lcore_id[i]);
1039 static int parse_cmd_tx_distr_start(const char *str, struct input *input)
1041 unsigned lcore_id[RTE_MAX_LCORE];
1045 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1047 if (nb_cores <= 0) {
1051 for (int i = 0; i < nb_cores; ++i)
1052 cmd_tx_distr_start(lcore_id[i]);
1056 static int parse_cmd_rx_distr_stop(const char *str, struct input *input)
1058 unsigned lcore_id[RTE_MAX_LCORE];
1062 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1064 if (nb_cores <= 0) {
1068 for (int i = 0; i < nb_cores; ++i)
1069 cmd_rx_distr_stop(lcore_id[i]);
1073 static int parse_cmd_tx_distr_stop(const char *str, struct input *input)
1075 unsigned lcore_id[RTE_MAX_LCORE];
1079 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1081 if (nb_cores <= 0) {
1085 for (int i = 0; i < nb_cores; ++i)
1086 cmd_tx_distr_stop(lcore_id[i]);
1090 static int parse_cmd_rx_distr_reset(const char *str, struct input *input)
1092 unsigned lcore_id[RTE_MAX_LCORE];
1096 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1098 if (nb_cores <= 0) {
1102 for (int i = 0; i < nb_cores; ++i)
1103 cmd_rx_distr_rst(lcore_id[i]);
1107 static int parse_cmd_tx_distr_reset(const char *str, struct input *input)
1109 unsigned lcore_id[RTE_MAX_LCORE];
1113 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1115 if (nb_cores <= 0) {
1119 for (int i = 0; i < nb_cores; ++i)
1120 cmd_tx_distr_rst(lcore_id[i]);
1124 static int parse_cmd_rx_distr_show(const char *str, struct input *input)
1126 unsigned lcore_id[RTE_MAX_LCORE];
1130 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1132 if (nb_cores <= 0) {
1136 for (int i = 0; i < nb_cores; ++i)
1137 cmd_rx_distr_show(lcore_id[i]);
1141 static int parse_cmd_tx_distr_show(const char *str, struct input *input)
1143 unsigned lcore_id[RTE_MAX_LCORE];
1147 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1149 if (nb_cores <= 0) {
1153 for (int i = 0; i < nb_cores; ++i)
1154 cmd_tx_distr_show(lcore_id[i]);
1158 static int parse_cmd_tot_stats(const char *str, struct input *input)
1160 if (strcmp("", str) != 0) {
1164 struct global_stats_sample *gsl = stats_get_global_stats(1);
1165 uint64_t tot_rx = gsl->host_rx_packets;
1166 uint64_t tot_tx = gsl->host_tx_packets;
1167 uint64_t last_tsc = gsl->tsc;
1171 snprintf(buf, sizeof(buf), "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n",
1172 tot_rx, tot_tx, last_tsc, rte_get_tsc_hz());
1173 input->reply(input, buf, strlen(buf));
1176 plog_info("RX: %"PRIu64", TX: %"PRIu64"\n", tot_rx, tot_tx);
1181 static int parse_cmd_update_interval(const char *str, struct input *input)
1185 if (sscanf(str, "%u", &val) != 1) {
1190 plog_err("Minimum update interval is 1 ms\n");
1193 plog_info("Setting update interval to %d ms\n", val);
1194 set_update_interval(val);
1199 static int parse_cmd_mem_info(const char *str, struct input *input)
1201 if (strcmp("", str) != 0) {
1210 static int parse_cmd_tot_ierrors_tot(const char *str, struct input *input)
1212 if (strcmp(str, "") != 0) {
1216 struct global_stats_sample *gsl = stats_get_global_stats(1);
1217 uint64_t tot = gsl->nics_ierrors;
1218 uint64_t last_tsc = gsl->tsc;
1222 snprintf(buf, sizeof(buf),
1223 "%"PRIu64",%"PRIu64",%"PRIu64"\n",
1224 tot, last_tsc, rte_get_tsc_hz());
1225 input->reply(input, buf, strlen(buf));
1228 plog_info("ierrors: %"PRIu64"\n", tot);
1233 static int parse_cmd_tot_imissed_tot(const char *str, struct input *input)
1235 if (strcmp(str, "") != 0) {
1239 struct global_stats_sample *gsl = stats_get_global_stats(1);
1240 uint64_t tot = gsl->nics_imissed;
1241 uint64_t last_tsc = gsl->tsc;
1245 snprintf(buf, sizeof(buf),
1246 "%"PRIu64",%"PRIu64",%"PRIu64"\n",
1247 tot, last_tsc, rte_get_tsc_hz());
1248 input->reply(input, buf, strlen(buf));
1251 plog_info("imissed: %"PRIu64"\n", tot);
1256 static int parse_cmd_reset_port(const char *str, struct input *input)
1260 if (sscanf(str, "%u", &port_id ) != 1) {
1264 cmd_reset_port(port_id);
1268 static int parse_cmd_write_reg(const char *str, struct input *input)
1273 if (sscanf(str, "%u %x %u", &port_id, &id, &val) != 3) {
1277 cmd_write_reg(port_id, id, val);
1281 static int parse_cmd_read_reg(const char *str, struct input *input)
1286 if (sscanf(str, "%u %x", &port_id, &id) != 2) {
1290 cmd_read_reg(port_id, id);
1294 static int parse_cmd_cache_reset(const char *str, struct input *input)
1300 static int parse_cmd_set_cache_class_mask(const char *str, struct input *input)
1306 if (sscanf(str, "%u %u %u", &lcore_id, &set, &val) != 3) {
1310 cmd_set_cache_class_mask(lcore_id, set, val);
1314 static int parse_cmd_set_cache_class(const char *str, struct input *input)
1319 if (sscanf(str, "%u %u", &lcore_id, &set) != 2) {
1323 cmd_set_cache_class(lcore_id, set);
1327 static int parse_cmd_get_cache_class_mask(const char *str, struct input *input)
1333 if (sscanf(str, "%u %u", &lcore_id, &set) != 2) {
1337 cmd_get_cache_class_mask(lcore_id, set, &val);
1340 snprintf(buf, sizeof(buf), "%d, %d, %x\n", lcore_id, set, val);
1341 input->reply(input, buf, strlen(buf));
1343 plog_info("core=%d, set=%d, mask=%x\n", lcore_id, set, val);
1348 static int parse_cmd_get_cache_class(const char *str, struct input *input)
1354 if (sscanf(str, "%u", &lcore_id) != 1) {
1358 cmd_get_cache_class(lcore_id, &set);
1361 snprintf(buf, sizeof(buf), "%d, %d\n", lcore_id, set);
1362 input->reply(input, buf, strlen(buf));
1364 plog_info("core=%d, cos=%d\n", lcore_id, set);
1369 static int parse_cmd_get_cache_mask(const char *str, struct input *input)
1375 if (sscanf(str, "%u", &lcore_id) != 1) {
1379 cmd_get_cache_class(lcore_id, &set);
1380 cmd_get_cache_class_mask(lcore_id, set, &mask);
1383 snprintf(buf, sizeof(buf), "%d, %x\n", lcore_id, mask);
1384 input->reply(input, buf, strlen(buf));
1386 plog_info("core=%d, mask=%x\n", lcore_id, mask);
1391 static int parse_cmd_set_vlan_offload(const char *str, struct input *input)
1396 if (sscanf(str, "%u %u", &port_id, &val) != 2) {
1400 cmd_set_vlan_offload(port_id, val);
1404 static int parse_cmd_set_vlan_filter(const char *str, struct input *input)
1409 if (sscanf(str, "%u %d %u", &port_id, &id, &val) != 3) {
1413 cmd_set_vlan_filter(port_id, id, val);
1417 static int parse_cmd_ring_info_all(const char *str, struct input *input)
1419 if (strcmp(str, "") != 0) {
1426 static int parse_cmd_port_up(const char *str, struct input *input)
1430 if (sscanf(str, "%u", &val) != 1) {
1438 static int parse_cmd_port_down(const char *str, struct input *input)
1442 if (sscanf(str, "%u", &val) != 1) {
1450 static int parse_cmd_port_link_state(const char *str, struct input *input)
1454 if (sscanf(str, "%u", &val) != 1) {
1458 if (!port_is_active(val))
1461 int active = prox_port_cfg[val].link_up;
1462 const char *state = active? "up\n" : "down\n";
1465 input->reply(input, state, strlen(state));
1467 plog_info("%s", state);
1472 static int parse_cmd_xstats(const char *str, struct input *input)
1476 if (sscanf(str, "%u", &val) != 1) {
1484 static int parse_cmd_stats(const char *str, struct input *input)
1486 if (strcmp(str, "") == 0)
1494 strncpy(buf, str, sizeof(buf) - 1);
1498 while ((tok = strchr(str, ','))) {
1500 stat_val = stats_parser_get(str);
1502 ret += sprintf(ret, "%s%"PRIu64"", list? "," :"", stat_val);
1507 stat_val = stats_parser_get(str);
1508 ret += sprintf(ret, "%s%"PRIu64"", list? "," :"", stat_val);
1513 input->reply(input, ret2, strlen(ret2));
1515 plog_info("%s", ret2);
1519 static void replace_char(char *str, char to_replace, char by)
1521 for (size_t i = 0; str[i] != '\0'; ++i) {
1522 if (str[i] == to_replace)
1527 static int parse_cmd_port_info(const char *str, struct input *input)
1531 if (strcmp(str, "all") == 0) {
1534 else if (sscanf(str, "%d", &val) != 1) {
1538 char port_info[2048];
1540 cmd_portinfo(val, port_info, sizeof(port_info));
1543 replace_char(port_info, '\n', ',');
1544 port_info[strlen(port_info) - 1] = '\n';
1545 input->reply(input, port_info, strlen(port_info));
1547 plog_info("%s", port_info);
1552 static int parse_cmd_ring_info(const char *str, struct input *input)
1554 unsigned lcores[RTE_MAX_LCORE], task_id, nb_cores;
1556 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1559 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1560 for (unsigned int i = 0; i < nb_cores; i++) {
1561 cmd_ringinfo(lcores[i], task_id);
1567 static int parse_cmd_port_stats(const char *str, struct input *input)
1571 if (sscanf(str, "%u", &val) != 1) {
1575 struct get_port_stats s;
1576 if (stats_port(val, &s)) {
1577 plog_err("Invalid port %u\n", val);
1581 snprintf(buf, sizeof(buf),
1582 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64","
1583 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64","
1584 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n",
1585 s.no_mbufs_diff, s.ierrors_diff + s.imissed_diff,
1586 s.rx_bytes_diff, s.tx_bytes_diff,
1587 s.rx_pkts_diff, s.tx_pkts_diff,
1589 s.no_mbufs_tot, s.ierrors_tot + s.imissed_tot,
1590 s.last_tsc, s.prev_tsc);
1591 plog_info("%s", buf);
1593 input->reply(input, buf, strlen(buf));
1597 static int parse_cmd_multi_port_stats(const char *str, struct input *input)
1599 uint32_t ports[PROX_MAX_PORTS];
1600 int nb_ports = parse_list_set(ports, str, PROX_MAX_PORTS);
1601 if (nb_ports <= 0) {
1605 char buf[PROX_MAX_PORTS * (11+5*21) + 1], *pbuf = buf;
1606 int left = sizeof(buf);
1607 for (int i = 0; i < nb_ports; ++i) {
1608 struct get_port_stats s;
1609 if (stats_port(ports[i], &s)) {
1610 plog_err("Invalid port %u\n", ports[i]);
1614 int len = snprintf(pbuf, left,
1616 "%"PRIu64",%"PRIu64","
1617 "%"PRIu64",%"PRIu64","
1619 //TODO: adjust buf size above when adding fields
1622 s.no_mbufs_tot, s.ierrors_tot + s.imissed_tot,
1624 if ((len < 0) || (len >= left)) {
1625 plog_err("Cannot print stats for port %u\n", ports[i]);
1634 plog_info("%s", buf);
1636 input->reply(input, buf, sizeof(buf) - left);
1640 static int parse_cmd_core_stats(const char *str, struct input *input)
1642 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1644 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1647 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1648 for (unsigned int i = 0; i < nb_cores; i++) {
1649 lcore_id = lcores[i];
1650 uint64_t tot_rx = stats_core_task_tot_rx(lcore_id, task_id);
1651 uint64_t tot_tx = stats_core_task_tot_tx(lcore_id, task_id);
1652 uint64_t tot_drop = stats_core_task_tot_drop(lcore_id, task_id);
1653 uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id);
1657 snprintf(buf, sizeof(buf),
1658 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n",
1659 tot_rx, tot_tx, tot_drop, last_tsc, rte_get_tsc_hz());
1660 input->reply(input, buf, strlen(buf));
1663 plog_info("RX: %"PRIu64", TX: %"PRIu64", DROP: %"PRIu64"\n",
1664 tot_rx, tot_tx, tot_drop);
1671 static int parse_cmd_dp_core_stats(const char *str, struct input *input)
1673 unsigned lcores[RTE_MAX_LCORE], tasks[MAX_TASKS_PER_CORE], lcore_id, task_id, nb_cores, nb_tasks;
1675 // This function either outputs a single line, in case of syntax error on the lists of cores and/or tasks
1676 if (parse_cores_tasks(str, lcores, tasks, &nb_cores, &nb_tasks)) {
1679 snprintf(buf, sizeof(buf), "error: invalid syntax\n");
1680 input->reply(input, buf, strlen(buf));
1685 // or outputs (nb_cores * nb_tasks) lines, one line for each core/task pair:
1686 // - if the core/task pair is invalid, the output line reports an error
1687 // - otherwise, the output line provides the dataplane statistics for the core/task pair
1688 for (unsigned int i = 0; i < nb_cores; i++) {
1689 for (unsigned int j = 0; j < nb_tasks; j++) {
1690 lcore_id = lcores[i];
1692 if (core_task_is_valid(lcore_id, task_id) == 0) {
1695 snprintf(buf, sizeof(buf), "error: invalid core %u, task %u\n", lcore_id, task_id);
1696 input->reply(input, buf, strlen(buf));
1698 plog_info("error: invalid core %u, task %u\n", lcore_id, task_id);
1702 uint64_t tot_rx = stats_core_task_tot_rx(lcore_id, task_id);
1703 uint64_t tot_tx = stats_core_task_tot_tx(lcore_id, task_id);
1704 uint64_t tot_tx_fail = stats_core_task_tot_tx_fail(lcore_id, task_id);
1705 uint64_t tot_rx_non_dp = stats_core_task_tot_rx_non_dp(lcore_id, task_id);
1706 uint64_t tot_tx_non_dp = stats_core_task_tot_tx_non_dp(lcore_id, task_id);
1707 uint64_t tot_drop = stats_core_task_tot_drop(lcore_id, task_id);
1708 uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id);
1712 snprintf(buf, sizeof(buf),
1713 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%u,%u\n",
1714 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);
1715 input->reply(input, buf, strlen(buf));
1718 plog_info("core: %u, task: %u, RX: %"PRIu64", TX: %"PRIu64", RX_NON_DP: %"PRIu64", TX_NON_DP: %"PRIu64", DROP: %"PRIu64", TX_FAIL: %"PRIu64"\n",
1719 lcore_id, task_id, tot_rx, tot_tx, tot_rx_non_dp, tot_tx_non_dp, tot_drop, tot_tx_fail);
1726 static int parse_cmd_lat_stats(const char *str, struct input *input)
1728 unsigned lcores[RTE_MAX_LCORE], tasks[MAX_TASKS_PER_CORE], lcore_id, task_id, nb_cores, nb_tasks;
1730 // This function either outputs a single line, in case of syntax error on the lists of cores and/or tasks
1731 if (parse_cores_tasks(str, lcores, tasks, &nb_cores, &nb_tasks)) {
1734 snprintf(buf, sizeof(buf), "error: invalid syntax\n");
1735 input->reply(input, buf, strlen(buf));
1740 // or outputs (nb_cores * nb_tasks) lines, one line for each core/task pair:
1741 // - if the core/task pair is invalid, the output line reports an error
1742 // - otherwise, the output line provides the latency statistics for the core/task pair
1743 for (unsigned int i = 0; i < nb_cores; i++) {
1744 for (unsigned int j = 0; j < nb_tasks; j++) {
1745 lcore_id = lcores[i];
1747 if (core_task_is_valid(lcore_id, task_id) == 0) {
1750 snprintf(buf, sizeof(buf), "error: invalid core %u, task %u\n", lcore_id, task_id);
1751 input->reply(input, buf, strlen(buf));
1753 plog_info("error: invalid core %u, task %u\n", lcore_id, task_id);
1757 if (!task_is_mode(lcore_id, task_id, "lat")) {
1760 snprintf(buf, sizeof(buf), "error: core %u task %u is not measuring latency\n", lcore_id, task_id);
1761 input->reply(input, buf, strlen(buf));
1763 plog_info("error: core %u task %u is not measuring latency\n", lcore_id, task_id);
1768 struct stats_latency *stats = stats_latency_find(lcore_id, task_id);
1769 struct stats_latency *tot = stats_latency_tot_find(lcore_id, task_id);
1770 if (!stats || !tot) {
1773 snprintf(buf, sizeof(buf),
1774 "error: core %u task %u stats = %p tot = %p\n",
1775 lcore_id, task_id, stats, tot);
1776 input->reply(input, buf, strlen(buf));
1778 plog_info("error: core %u task %u stats = %p tot = %p\n",
1779 lcore_id, task_id, stats, tot);
1784 uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id);
1785 uint64_t lat_min_usec = time_unit_to_usec(&stats->min.time);
1786 uint64_t lat_max_usec = time_unit_to_usec(&stats->max.time);
1787 uint64_t tot_lat_min_usec = time_unit_to_usec(&tot->min.time);
1788 uint64_t tot_lat_max_usec = time_unit_to_usec(&tot->max.time);
1789 uint64_t lat_avg_usec = time_unit_to_usec(&stats->avg.time);
1793 snprintf(buf, sizeof(buf),
1794 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%u,%u\n",
1804 input->reply(input, buf, strlen(buf));
1807 plog_info("core: %u, task: %u, min: %"PRIu64", max: %"PRIu64", avg: %"PRIu64", min since reset: %"PRIu64", max since reset: %"PRIu64"\n",
1821 static int parse_cmd_show_irq_buckets(const char *str, struct input *input)
1823 char buf[4096] = {0};
1825 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1827 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1830 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1831 for (c = 0; c < nb_cores; c++) {
1832 lcore_id = lcores[c];
1833 get_irq_buckets_by_core_task(buf, lcore_id, task_id);
1834 plog_info("%s", buf);
1836 input->reply(input, buf, strlen(buf));
1843 static int parse_cmd_irq(const char *str, struct input *input)
1846 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1848 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1851 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1852 for (c = 0; c < nb_cores; c++) {
1853 lcore_id = lcores[c];
1854 if (!task_is_mode(lcore_id, task_id, "irq")) {
1855 plog_err("Core %u task %u is not in irq mode\n", lcore_id, task_id);
1857 struct task_irq *task_irq = (struct task_irq *)(lcore_cfg[lcore_id].tasks_all[task_id]);
1859 task_irq_show_stats(task_irq, input);
1866 static void task_lat_show_latency_histogram(uint8_t lcore_id, uint8_t task_id, struct input *input)
1868 #ifdef LATENCY_HISTOGRAM
1871 stats_core_lat_histogram(lcore_id, task_id, &buckets);
1873 if (buckets == NULL)
1877 char buf[4096] = {0};
1878 for (size_t i = 0; i < 128; i++)
1879 sprintf(buf+strlen(buf), "Bucket [%zu]: %"PRIu64"\n", i, buckets[i]);
1880 input->reply(input, buf, strlen(buf));
1883 for (size_t i = 0; i < 128; i++)
1885 plog_info("Bucket [%zu]: %"PRIu64"\n", i, buckets[i]);
1888 plog_info("LATENCY_DETAILS disabled\n");
1892 static int parse_cmd_lat_packets(const char *str, struct input *input)
1894 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1896 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1899 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1900 for (unsigned int i = 0; i < nb_cores; i++) {
1901 lcore_id = lcores[i];
1902 if (!task_is_mode(lcore_id, task_id, "lat")) {
1903 plog_err("Core %u task %u is not measuring latency\n", lcore_id, task_id);
1906 task_lat_show_latency_histogram(lcore_id, task_id, input);
1913 static int parse_cmd_cgnat_public_hash(const char *str, struct input *input)
1915 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1917 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1920 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1921 for (unsigned int i = 0; i < nb_cores; i++) {
1922 lcore_id = lcores[i];
1924 if (!task_is_mode(lcore_id, task_id, "cgnat")) {
1925 plog_err("Core %u task %u is not cgnat\n", lcore_id, task_id);
1928 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
1929 task_cgnat_dump_public_hash((struct task_nat *)tbase);
1936 static int parse_cmd_cgnat_private_hash(const char *str, struct input *input)
1938 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1941 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1944 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1945 for (unsigned int i = 0; i < nb_cores; i++) {
1946 lcore_id = lcores[i];
1948 if (!task_is_mode(lcore_id, task_id, "cgnat")) {
1949 plog_err("Core %u task %u is not cgnat\n", lcore_id, task_id);
1952 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
1953 task_cgnat_dump_private_hash((struct task_nat *)tbase);
1960 static int parse_cmd_accuracy(const char *str, struct input *input)
1962 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1965 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1967 if (!(str = strchr_skip_twice(str, ' ')))
1969 if (sscanf(str, "%"PRIu32"", &val) != 1)
1972 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1973 for (unsigned int i = 0; i < nb_cores; i++) {
1974 lcore_id = lcores[i];
1976 if (!task_is_mode(lcore_id, task_id, "lat")) {
1977 plog_err("Core %u task %u is not measuring latency\n", lcore_id, task_id);
1980 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
1982 task_lat_set_accuracy_limit((struct task_lat *)tbase, val);
1989 static int parse_cmd_rx_tx_info(const char *str, struct input *input)
1991 if (strcmp(str, "") != 0) {
1999 static int parse_cmd_version(const char *str, struct input *input)
2001 if (strcmp(str, "") != 0) {
2007 ((uint64_t)VERSION_MAJOR) << 24 |
2008 ((uint64_t)VERSION_MINOR) << 16 |
2009 ((uint64_t)VERSION_REV) << 8;
2012 snprintf(buf, sizeof(buf), "%"PRIu64",%"PRIu64"\n", version, (uint64_t)RTE_VERSION);
2013 input->reply(input, buf, strlen(buf));
2016 plog_info("prox version: %d.%d, DPDK version: %s\n",
2017 VERSION_MAJOR, VERSION_MINOR,
2018 rte_version() + sizeof(RTE_VER_PREFIX));
2027 int (*parse)(const char *args, struct input *input);
2030 static int parse_cmd_help(const char *str, struct input *input);
2032 static struct cmd_str cmd_strings[] = {
2033 {"history", "", "Print command history", parse_cmd_history},
2034 {"echo", "", "echo parameter, useful to resolving variables", parse_cmd_echo},
2035 {"quit", "", "Stop all cores and quit", parse_cmd_quit},
2036 {"quit_force", "", "Quit without waiting on cores to stop", parse_cmd_quit_force},
2037 {"help", "<substr>", "Show list of commands that have <substr> as a substring. If no substring is provided, all commands are shown.", parse_cmd_help},
2038 {"verbose", "<level>", "Set verbosity level", parse_cmd_verbose},
2039 {"thread info", "<core_id> <task_id>", "", parse_cmd_thread_info},
2040 {"mem info", "", "Show information about system memory (number of huge pages and addresses of these huge pages)", parse_cmd_mem_info},
2041 {"update interval", "<value>", "Update statistics refresh rate, in msec (must be >=10). Default is 1 second", parse_cmd_update_interval},
2042 {"rx tx info", "", "Print connections between tasks on all cores", parse_cmd_rx_tx_info},
2043 {"start", "<core list>|all <task_id>", "Start core <core_id> or all cores", parse_cmd_start},
2044 {"stop", "<core list>|all <task_id>", "Stop core <core id> or all cores", parse_cmd_stop},
2046 {"dump", "<core id> <task id> <nb packets>", "Create a hex dump of <nb_packets> from <task_id> on <core_id> showing how packets have changed between RX and TX.", parse_cmd_trace},
2047 {"dump_rx", "<core id> <task id> <nb packets>", "Create a hex dump of <nb_packets> from <task_id> on <core_id> at RX", parse_cmd_dump_rx},
2048 {"dump_tx", "<core id> <task id> <nb packets>", "Create a hex dump of <nb_packets> from <task_id> on <core_id> at TX", parse_cmd_dump_tx},
2049 {"rx distr start", "", "Start gathering statistical distribution of received packets", parse_cmd_rx_distr_start},
2050 {"rx distr stop", "", "Stop gathering statistical distribution of received packets", parse_cmd_rx_distr_stop},
2051 {"rx distr reset", "", "Reset gathered statistical distribution of received packets", parse_cmd_rx_distr_reset},
2052 {"rx distr show", "", "Display gathered statistical distribution of received packets", parse_cmd_rx_distr_show},
2053 {"tx distr start", "", "Start gathering statistical distribution of xmitted packets", parse_cmd_tx_distr_start},
2054 {"tx distr stop", "", "Stop gathering statistical distribution of xmitted packets", parse_cmd_tx_distr_stop},
2055 {"tx distr reset", "", "Reset gathered statistical distribution of xmitted packets", parse_cmd_tx_distr_reset},
2056 {"tx distr show", "", "Display gathered statistical distribution of xmitted packets", parse_cmd_tx_distr_show},
2058 {"rate", "<port id> <queue id> <rate>", "rate does not include preamble, SFD and IFG", parse_cmd_rate},
2059 {"count","<core id> <task id> <count>", "Generate <count> packets", parse_cmd_count},
2060 {"bypass", "<core_id> <task_id>", "Bypass task", parse_cmd_bypass},
2061 {"reconnect", "<core_id> <task_id>", "Reconnect task", parse_cmd_reconnect},
2062 {"pkt_size", "<core_id> <task_id> <pkt_size>", "Set the packet size to <pkt_size>", parse_cmd_pkt_size},
2063 {"speed", "<core_id> <task_id> <speed percentage>", "Change the speed to <speed percentage> at which packets are being generated on core <core_id> in task <task_id>.", parse_cmd_speed},
2064 {"speed_byte", "<core_id> <task_id> <speed>", "Change speed to <speed>. The speed is specified in units of bytes per second.", parse_cmd_speed_byte},
2065 {"set value", "<core_id> <task_id> <offset> <value> <value_len>", "Set <value_len> bytes to <value> at offset <offset> in packets generated on <core_id> <task_id>", parse_cmd_set_value},
2066 {"set random", "<core_id> <task_id> <offset> <random_str> <value_len>", "Set <value_len> bytes to <rand_str> at offset <offset> in packets generated on <core_id> <task_id>", parse_cmd_set_random},
2067 {"reset values all", "", "Undo all \"set value\" commands on all cores/tasks", parse_cmd_reset_values_all},
2068 {"reset randoms all", "", "Undo all \"set random\" commands on all cores/tasks", parse_cmd_reset_randoms_all},
2069 {"reset values", "<core id> <task id>", "Undo all \"set value\" commands on specified core/task", parse_cmd_reset_values},
2071 {"arp add", "<core id> <task id> <port id> <gre id> <svlan> <cvlan> <ip addr> <mac addr> <user>", "Add a single ARP entry into a CPE table on <core id>/<task id>.", parse_cmd_arp_add},
2072 {"rule add", "<core id> <task id> svlan_id&mask cvlan_id&mask ip_proto&mask source_ip/prefix destination_ip/prefix range dport_range action", "Add a rule to the ACL table on <core id>/<task id>", parse_cmd_rule_add},
2073 {"route add", "<core id> <task id> <ip/prefix> <next hop id>", "Add a route to the routing table on core <core id> <task id>. Example: route add 10.0.16.0/24 9", parse_cmd_route_add},
2074 {"gateway ip", "<core id> <task id> <ip>", "Define/Change IP address of destination gateway on core <core id> <task id>.", parse_cmd_gateway_ip},
2075 {"local ip", "<core id> <task id> <ip>", "Define/Change IP address of destination gateway on core <core id> <task id>.", parse_cmd_local_ip},
2077 {"pps unit", "", "Change core stats pps unit", parse_cmd_pps_unit},
2078 {"reset stats", "", "Reset all statistics", parse_cmd_reset_stats},
2079 {"reset lat stats", "", "Reset all latency statistics", parse_cmd_reset_lat_stats},
2080 {"tot stats", "", "Print total RX and TX packets", parse_cmd_tot_stats},
2081 {"tot ierrors tot", "", "Print total number of ierrors since reset", parse_cmd_tot_ierrors_tot},
2082 {"tot imissed tot", "", "Print total number of imissed since reset", parse_cmd_tot_imissed_tot},
2083 {"lat stats", "<core id> <task id>", "Print min,max,avg latency as measured during last sampling interval", parse_cmd_lat_stats},
2084 {"irq stats", "<core id> <task id>", "Print irq related infos", parse_cmd_irq},
2085 {"show irq buckets", "<core id> <task id>", "Print irq buckets", parse_cmd_show_irq_buckets},
2086 {"lat packets", "<core id> <task id>", "Print the latency for each of the last set of packets", parse_cmd_lat_packets},
2087 {"accuracy limit", "<core id> <task id> <nsec>", "Only consider latency of packets that were measured with an error no more than <nsec>", parse_cmd_accuracy},
2088 {"core stats", "<core id> <task id>", "Print rx/tx/drop for task <task id> running on core <core id>", parse_cmd_core_stats},
2089 {"dp core stats", "<core id> <task id>", "Print rx/tx/non_dp_rx/non_dp_tx/drop for task <task id> running on core <core id>", parse_cmd_dp_core_stats},
2090 {"port_stats", "<port id>", "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 <port id>", parse_cmd_port_stats},
2091 {"multi port stats", "<port list>", "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},
2092 {"read reg", "", "Read register", parse_cmd_read_reg},
2093 {"write reg", "", "Read register", parse_cmd_write_reg},
2094 {"set vlan offload", "", "Set Vlan offload", parse_cmd_set_vlan_offload},
2095 {"set vlan filter", "", "Set Vlan filter", parse_cmd_set_vlan_filter},
2096 {"reset cache", "", "Reset cache", parse_cmd_cache_reset},
2097 {"set cache class mask", "<core id> <class> <mask>", "Set cache class mask for <core id>", parse_cmd_set_cache_class_mask},
2098 {"get cache class mask", "<core id> <class>", "Get cache class mask", parse_cmd_get_cache_class_mask},
2099 {"set cache class", "<core id> <class>", "Set cache class", parse_cmd_set_cache_class},
2100 {"get cache class", "<core id>", "Get cache class", parse_cmd_get_cache_class},
2101 {"get cache mask", "<core id>", "Get cache mask", parse_cmd_get_cache_mask},
2102 {"reset port", "", "Reset port", parse_cmd_reset_port},
2103 {"ring info all", "", "Get information about ring, such as ring size and number of elements in the ring", parse_cmd_ring_info_all},
2104 {"ring info", "<core id> <task id>", "Get information about ring on core <core id> in task <task id>, such as ring size and number of elements in the ring", parse_cmd_ring_info},
2105 {"port info", "<port id> [brief?]", "Get port related information, such as MAC address, socket, number of descriptors..., . Adding \"brief\" after command prints short version of output.", parse_cmd_port_info},
2106 {"port up", "<port id>", "Set the port up", parse_cmd_port_up},
2107 {"port down", "<port id>", "Set the port down", parse_cmd_port_down},
2108 {"port link state", "<port id>", "Get link state (up or down) for port", parse_cmd_port_link_state},
2109 {"port xstats", "<port id>", "Get extra statistics for the port", parse_cmd_xstats},
2110 {"stats", "<stats_path>", "Get stats as specified by <stats_path>. A comma-separated list of <stats_path> can be supplied", parse_cmd_stats},
2111 {"cgnat dump public hash", "<core id> <task id>", "Dump cgnat public hash table", parse_cmd_cgnat_public_hash},
2112 {"cgnat dump private hash", "<core id> <task id>", "Dump cgnat private hash table", parse_cmd_cgnat_private_hash},
2113 {"delay_us", "<core_id> <task_id> <delay_us>", "Set the delay in usec for the impair mode to <delay_us>", parse_cmd_delay_us},
2114 {"random delay_us", "<core_id> <task_id> <random delay_us>", "Set the delay in usec for the impair mode to <random delay_us>", parse_cmd_random_delay_us},
2115 {"probability", "<core_id> <task_id> <probability>", "Set the percent of forwarded packets for the impair mode", parse_cmd_set_probability},
2116 {"version", "", "Show version", parse_cmd_version},
2120 static int parse_cmd_help(const char *str, struct input *input)
2122 /* str contains the arguments, all commands that have str as a
2123 substring will be shown. */
2124 size_t len, len2, longest_cmd = 0;
2125 for (size_t i = 0; i < cmd_parser_n_cmd(); ++i) {
2126 if (longest_cmd <strlen(cmd_strings[i].cmd))
2127 longest_cmd = strlen(cmd_strings[i].cmd);
2129 /* A single call to log will be executed after the help string
2130 has been built. The reason for this is to make use of the
2132 char buf[32768] = {0};
2134 for (size_t i = 0; i < cmd_parser_n_cmd(); ++i) {
2136 const size_t cmd_len = strlen(cmd_strings[i].cmd);
2137 for (size_t j = 0; j < cmd_len; ++j) {
2139 for (size_t k = 0; k < strlen(str); ++k) {
2140 if (str[k] != (cmd_strings[i].cmd + j)[k]) {
2151 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s", cmd_strings[i].cmd);
2152 len = strlen(cmd_strings[i].cmd);
2153 while (len < longest_cmd) {
2155 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " ");
2158 if (strlen(cmd_strings[i].args)) {
2159 char tmp[256] = {0};
2160 strncpy(tmp, cmd_strings[i].args, 128);
2161 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "Arguments: %s\n", tmp);
2163 if (strlen(cmd_strings[i].help)) {
2166 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " ");
2171 if (strlen(cmd_strings[i].help)) {
2173 const char *h = cmd_strings[i].help;
2179 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " ");
2182 char tmp[128] = {0};
2183 const size_t max_len = strlen(h) > 80? 80 : strlen(h);
2184 size_t len3 = max_len;
2186 while (len3 && h[len3] != ' ')
2192 strncpy(tmp, h, len3);
2194 while (h[0] == ' ' && strlen(h))
2197 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s\n", tmp);
2201 if (strlen(cmd_strings[i].help) == 0&& strlen(cmd_strings[i].args) == 0) {
2202 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "\n");
2205 plog_info("%s", buf);
2210 const char *cmd_parser_cmd(size_t i)
2212 i = i < cmd_parser_n_cmd()? i: cmd_parser_n_cmd();
2213 return cmd_strings[i].cmd;
2216 size_t cmd_parser_n_cmd(void)
2218 return sizeof(cmd_strings)/sizeof(cmd_strings[0]) - 1;
2221 void cmd_parser_parse(const char *str, struct input *input)
2225 for (size_t i = 0; i < cmd_parser_n_cmd(); ++i) {
2226 skip = strlen(cmd_strings[i].cmd);
2227 if (strncmp(cmd_strings[i].cmd, str, skip) == 0 &&
2228 (str[skip] == ' ' || str[skip] == 0)) {
2229 while (str[skip] == ' ')
2232 if (cmd_strings[i].parse(str + skip, input) != 0) {
2233 plog_warn("Invalid syntax for command '%s': %s %s\n",
2234 cmd_strings[i].cmd, cmd_strings[i].args, cmd_strings[i].help);
2240 plog_err("Unknown command: '%s'\n", str);