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"
55 static int core_task_is_valid(int lcore_id, int task_id)
57 if (lcore_id >= RTE_MAX_LCORE) {
58 plog_err("Invalid core id %u (lcore ID above %d)\n", lcore_id, RTE_MAX_LCORE);
61 else if (!prox_core_active(lcore_id, 0)) {
62 plog_err("Invalid core id %u (lcore is not active)\n", lcore_id);
65 else if (task_id >= lcore_cfg[lcore_id].n_tasks_all) {
66 plog_err("Invalid task id (valid task IDs for core %u are below %u)\n",
67 lcore_id, lcore_cfg[lcore_id].n_tasks_all);
73 static int cores_task_are_valid(unsigned int *lcores, int task_id, unsigned int nb_cores)
75 unsigned int lcore_id;
76 for (unsigned int i = 0; i < nb_cores; i++) {
78 if (lcore_id >= RTE_MAX_LCORE) {
79 plog_err("Invalid core id %u (lcore ID above %d)\n", lcore_id, RTE_MAX_LCORE);
82 else if (!prox_core_active(lcore_id, 0)) {
83 plog_err("Invalid core id %u (lcore is not active)\n", lcore_id);
86 else if (task_id >= lcore_cfg[lcore_id].n_tasks_all) {
87 plog_err("Invalid task id (valid task IDs for core %u are below %u)\n",
88 lcore_id, lcore_cfg[lcore_id].n_tasks_all);
95 static int parse_core_task(const char *str, uint32_t *lcore_id, uint32_t *task_id, unsigned int *nb_cores)
97 char str_lcore_id[128];
100 if (2 != sscanf(str, "%s %u", str_lcore_id, task_id))
103 if ((ret = parse_list_set(lcore_id, str_lcore_id, RTE_MAX_LCORE)) <= 0) {
104 plog_err("Invalid core while parsing command (%s)\n", get_parse_err());
112 static const char *strchr_skip_twice(const char *str, int chr)
114 str = strchr(str, chr);
119 str = strchr(str, chr);
125 static int parse_cmd_quit(const char *str, struct input *input)
127 if (strcmp(str, "") != 0) {
135 static int parse_cmd_quit_force(const char *str, struct input *input)
137 if (strcmp(str, "") != 0) {
144 static int parse_cmd_history(const char *str, struct input *input)
146 if (strcmp(str, "") != 0) {
150 if (input->history) {
151 input->history(input);
154 plog_err("Invalid history comand ");
158 static int parse_cmd_echo(const char *str, struct input *input)
160 if (strcmp(str, "") == 0) {
166 if (parse_vars(resolved, sizeof(resolved), str)) {
171 if (strlen(resolved) + 2 < sizeof(resolved)) {
172 resolved[strlen(resolved) + 1] = 0;
173 resolved[strlen(resolved)] = '\n';
178 input->reply(input, resolved, strlen(resolved));
180 plog_info("%s\n", resolved);
185 static int parse_cmd_reset_stats(const char *str, struct input *input)
187 if (strcmp(str, "") != 0) {
195 static int parse_cmd_reset_lat_stats(const char *str, struct input *input)
197 if (strcmp(str, "") != 0) {
201 stats_latency_reset();
205 static int parse_cmd_trace(const char *str, struct input *input)
207 unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores;
209 if (parse_core_task(str, lcores, &task_id, &nb_cores))
211 if (!(str = strchr_skip_twice(str, ' ')))
213 if (sscanf(str, "%u", &nb_packets) != 1)
216 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
217 for (unsigned int i = 0; i < nb_cores; i++) {
218 cmd_trace(lcores[i], task_id, nb_packets);
224 static int parse_cmd_dump_rx(const char *str, struct input *input)
226 unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores;
228 if (parse_core_task(str, lcores, &task_id, &nb_cores))
230 if (!(str = strchr_skip_twice(str, ' ')))
232 if (sscanf(str, "%u", &nb_packets) != 1) {
236 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
237 for (unsigned int i = 0; i < nb_cores; i++) {
238 cmd_dump(lcores[i], task_id, nb_packets, input, 1, 0);
244 static int parse_cmd_pps_unit(const char *str, struct input *input)
248 if (sscanf(str, "%u", &val) != 1) {
251 display_set_pps_unit(val);
255 static int parse_cmd_dump_tx(const char *str, struct input *input)
257 unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores;
259 if (parse_core_task(str, lcores, &task_id, &nb_cores))
261 if (!(str = strchr_skip_twice(str, ' ')))
263 if (sscanf(str, "%u", &nb_packets) != 1) {
267 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
268 for (unsigned int i = 0; i < nb_cores; i++) {
269 cmd_dump(lcores[i], task_id, nb_packets, input, 0, 1);
275 static int parse_cmd_rate(const char *str, struct input *input)
277 unsigned queue, port, rate;
279 if (sscanf(str, "%u %u %u", &queue, &port, &rate) != 3) {
283 if (port > PROX_MAX_PORTS) {
284 plog_err("Max port id allowed is %u (specified %u)\n", PROX_MAX_PORTS, port);
286 else if (!prox_port_cfg[port].active) {
287 plog_err("Port %u not active\n", port);
289 else if (queue >= prox_port_cfg[port].n_txq) {
290 plog_err("Number of active queues is %u\n",
291 prox_port_cfg[port].n_txq);
293 else if (rate > prox_port_cfg[port].link_speed) {
294 plog_err("Max rate allowed on port %u queue %u is %u Mbps\n",
295 port, queue, prox_port_cfg[port].link_speed);
299 plog_info("Disabling rate limiting on port %u queue %u\n",
303 plog_info("Setting rate limiting to %u Mbps on port %u queue %u\n",
306 rte_eth_set_queue_rate_limit(port, queue, rate);
311 int task_is_mode(uint32_t lcore_id, uint32_t task_id, const char *mode, const char *sub_mode)
313 struct task_init *t = lcore_cfg[lcore_id].targs[task_id].task_init;
315 return !strcmp(t->mode_str, mode) && !strcmp(t->sub_mode_str, sub_mode);
318 int task_is_sub_mode(uint32_t lcore_id, uint32_t task_id, const char *sub_mode)
320 struct task_init *t = lcore_cfg[lcore_id].targs[task_id].task_init;
322 return !strcmp(t->sub_mode_str, sub_mode);
325 static void log_pkt_count(uint32_t count, uint32_t lcore_id, uint32_t task_id)
327 if (count == UINT32_MAX)
328 plog_info("Core %u task %u will keep sending packets\n", lcore_id, task_id);
330 plog_info("Core %u task %u waits for next count command\n", lcore_id, task_id);
332 plog_info("Core %u task %u stopping after %u packets\n", lcore_id, task_id, count);
335 static int parse_cmd_count(const char *str, struct input *input)
337 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, count, nb_cores;
339 if (parse_core_task(str, lcores, &task_id, &nb_cores))
341 if (!(str = strchr_skip_twice(str, ' ')))
343 if (sscanf(str, "%u", &count) != 1)
346 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
347 for (unsigned int i = 0; i < nb_cores; i++) {
348 lcore_id = lcores[i];
349 if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) {
350 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
353 struct task_base *task = lcore_cfg[lcore_id].tasks_all[task_id];
355 log_pkt_count(count, lcore_id, task_id);
356 task_gen_set_pkt_count(task, count);
363 static int parse_cmd_set_probability(const char *str, struct input *input)
365 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
368 if (parse_core_task(str, lcores, &task_id, &nb_cores))
370 if (!(str = strchr_skip_twice(str, ' ')))
372 if (sscanf(str, "%f", &probability) != 1)
375 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
376 for (unsigned int i = 0; i < nb_cores; i++) {
377 lcore_id = lcores[i];
378 if (!task_is_mode(lcore_id, task_id, "impair", "")) {
379 plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id);
381 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
382 task_impair_set_proba(tbase, probability);
388 static int parse_cmd_delay_us(const char *str, struct input *input)
390 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, delay_us, nb_cores;
392 if (parse_core_task(str, lcores, &task_id, &nb_cores))
394 if (!(str = strchr_skip_twice(str, ' ')))
396 if (sscanf(str, "%d", &delay_us) != 1)
399 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
400 for (unsigned int i = 0; i < nb_cores; i++) {
401 lcore_id = lcores[i];
402 if (!task_is_mode(lcore_id, task_id, "impair", "")) {
403 plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id);
405 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
406 task_impair_set_delay_us(tbase, delay_us, 0);
412 static int parse_cmd_random_delay_us(const char *str, struct input *input)
414 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, delay_us, nb_cores;
416 if (parse_core_task(str, lcores, &task_id, &nb_cores))
418 if (!(str = strchr_skip_twice(str, ' ')))
420 if (sscanf(str, "%d", &delay_us) != 1)
423 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
424 for (unsigned int i = 0; i < nb_cores; i++) {
425 lcore_id = lcores[i];
426 if (!task_is_mode(lcore_id, task_id, "impair", "")) {
427 plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id);
429 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
430 task_impair_set_delay_us(tbase, 0, delay_us);
436 static int parse_cmd_bypass(const char *str, struct input *input)
438 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores;
440 if (parse_core_task(str, lcores, &task_id, &nb_cores))
442 if ((prox_cfg.flags & DSF_ENABLE_BYPASS) == 0) {
443 plog_err("enable bypass not set => command not supported\n");
447 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
448 for (unsigned int i = 0; i < nb_cores; i++) {
449 lcore_id = lcores[i];
450 if (bypass_task(lcore_id, task_id) != 0)
457 static int parse_cmd_reconnect(const char *str, struct input *input)
459 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores;
461 if (parse_core_task(str, lcores, &task_id, &nb_cores))
463 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
464 for (unsigned int i = 0; i < nb_cores; i++) {
465 lcore_id = lcores[i];
466 if (reconnect_task(lcore_id, task_id) != 0)
473 static int parse_cmd_pkt_size(const char *str, struct input *input)
475 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores;
477 if (parse_core_task(str, lcores, &task_id, &nb_cores))
479 if (!(str = strchr_skip_twice(str, ' ')))
481 if (sscanf(str, "%d", &pkt_size) != 1)
484 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
485 for (unsigned int i = 0; i < nb_cores; i++) {
486 lcore_id = lcores[i];
487 if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) {
488 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
490 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
492 if (task_gen_set_pkt_size(tbase, pkt_size) != 0)
499 static int parse_cmd_speed(const char *str, struct input *input)
501 unsigned lcores[RTE_MAX_LCORE], task_id, lcore_id, nb_cores;
505 if (parse_core_task(str, lcores, &task_id, &nb_cores))
507 if (!(str = strchr_skip_twice(str, ' ')))
509 if (sscanf(str, "%f", &speed) != 1) {
513 if (!cores_task_are_valid(lcores, task_id, nb_cores)) {
517 for (i = 0; i < nb_cores; i++) {
518 lcore_id = lcores[i];
519 if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) {
520 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
522 else if (speed > 400.0f || speed < 0.0f) {
523 plog_err("Speed out of range (must be betweeen 0%% and 100%%)\n");
526 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
527 uint64_t bps = speed * 12500000;
529 plog_info("Setting rate to %"PRIu64" Bps\n", bps);
531 task_gen_set_rate(tbase, bps);
537 static int parse_cmd_speed_byte(const char *str, struct input *input)
539 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
542 if (parse_core_task(str, lcores, &task_id, &nb_cores))
544 if (!(str = strchr_skip_twice(str, ' ')))
546 if (sscanf(str, "%"PRIu64"", &bps) != 1)
549 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
550 for (unsigned int i = 0; i < nb_cores; i++) {
551 lcore_id = lcores[i];
553 if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) {
554 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
556 else if (bps > 1250000000) {
557 plog_err("Speed out of range (must be <= 1250000000)\n");
560 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
562 plog_info("Setting rate to %"PRIu64" Bps\n", bps);
563 task_gen_set_rate(tbase, bps);
570 static int parse_cmd_reset_randoms_all(const char *str, struct input *input)
572 if (strcmp(str, "") != 0) {
576 unsigned task_id, lcore_id = -1;
577 while (prox_core_next(&lcore_id, 0) == 0) {
578 for (task_id = 0; task_id < lcore_cfg[lcore_id].n_tasks_all; task_id++) {
579 if ((task_is_mode(lcore_id, task_id, "gen", "")) || (task_is_mode(lcore_id, task_id, "gen", "l3"))) {
580 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
581 uint32_t n_rands = task_gen_get_n_randoms(tbase);
583 plog_info("Resetting randoms on core %d task %d from %d randoms\n", lcore_id, task_id, n_rands);
584 task_gen_reset_randoms(tbase);
591 static int parse_cmd_reset_values_all(const char *str, struct input *input)
593 if (strcmp(str, "") != 0) {
597 unsigned task_id, lcore_id = -1;
598 while (prox_core_next(&lcore_id, 0) == 0) {
599 for (task_id = 0; task_id < lcore_cfg[lcore_id].n_tasks_all; task_id++) {
600 if ((task_is_mode(lcore_id, task_id, "gen", "")) || (task_is_mode(lcore_id, task_id, "gen", "l3"))) {
601 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
603 plog_info("Resetting values on core %d task %d\n", lcore_id, task_id);
604 task_gen_reset_values(tbase);
611 static int parse_cmd_reset_values(const char *str, struct input *input)
613 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
615 if (parse_core_task(str, lcores, &task_id, &nb_cores))
618 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
619 for (unsigned int i = 0; i < nb_cores; i++) {
620 lcore_id = lcores[i];
621 if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) {
622 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
625 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
627 plog_info("Resetting values on core %d task %d\n", lcore_id, task_id);
628 task_gen_reset_values(tbase);
635 static int parse_cmd_set_value(const char *str, struct input *input)
637 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, value, nb_cores;
638 unsigned short offset;
641 if (parse_core_task(str, lcores, &task_id, &nb_cores))
643 if (!(str = strchr_skip_twice(str, ' ')))
645 if (sscanf(str, "%hu %u %hhu", &offset, &value, &value_len) != 3) {
649 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
650 for (unsigned int i = 0; i < nb_cores; i++) {
651 lcore_id = lcores[i];
652 if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) {
653 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
655 else if (offset > ETHER_MAX_LEN) {
656 plog_err("Offset out of range (must be less then %u)\n", ETHER_MAX_LEN);
658 else if (value_len > 4) {
659 plog_err("Length out of range (must be less then 4)\n");
662 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
664 if (task_gen_set_value(tbase, value, offset, value_len))
665 plog_info("Unable to set Byte %"PRIu16" to %"PRIu8" - too many value set\n", offset, value);
667 plog_info("Setting Byte %"PRIu16" to %"PRIu32"\n", offset, value);
674 static int parse_cmd_set_random(const char *str, struct input *input)
676 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
677 unsigned short offset;
680 int16_t rand_id = -1;
682 if (parse_core_task(str, lcores, &task_id, &nb_cores))
684 if (!(str = strchr_skip_twice(str, ' ')))
686 if (sscanf(str, "%hu %32s %hhu", &offset, rand_str, &value_len) != 3) {
690 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
691 for (unsigned int i = 0; i < nb_cores; i++) {
692 lcore_id = lcores[i];
693 if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) {
694 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
696 else if (offset > ETHER_MAX_LEN) {
697 plog_err("Offset out of range (must be less then %u)\n", ETHER_MAX_LEN);
699 else if (value_len > 4) {
700 plog_err("Length out of range (must be less then 4)\n");
702 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
704 if (task_gen_add_rand(tbase, rand_str, offset, rand_id)) {
705 plog_warn("Random not added on core %u task %u\n", lcore_id, task_id);
713 static int parse_cmd_thread_info(const char *str, struct input *input)
715 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
717 if (parse_core_task(str, lcores, &task_id, &nb_cores))
719 for (unsigned int i = 0; i < nb_cores; i++) {
720 cmd_thread_info(lcores[i], task_id);
725 static int parse_cmd_verbose(const char *str, struct input *input)
729 if (sscanf(str, "%u", &id) != 1) {
733 if (plog_set_lvl(id) != 0) {
734 plog_err("Cannot set log level to %u\n", id);
739 static int parse_cmd_arp_add(const char *str, struct input *input)
742 struct arp_msg *pmsg = &amsg;
743 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
744 struct rte_ring *ring;
746 if (parse_core_task(str, lcores, &task_id, &nb_cores))
748 if (!(str = strchr_skip_twice(str, ' ')))
752 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
753 if (str_to_arp_msg(&amsg, str) == 0) {
754 for (unsigned int i = 0; i < nb_cores; i++) {
755 lcore_id = lcores[i];
756 ring = ctrl_rings[lcore_id*MAX_TASKS_PER_CORE + task_id];
758 plog_err("No ring for control messages to core %u task %u\n", lcore_id, task_id);
761 #if RTE_VERSION < RTE_VERSION_NUM(17,5,0,1)
762 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&pmsg, 1));
764 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&pmsg, 1, NULL) == 0);
766 while (!rte_ring_empty(ring));
775 static int parse_cmd_rule_add(const char *str, struct input *input)
777 struct rte_ring *ring;
778 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
780 if (parse_core_task(str, lcores, &task_id, &nb_cores))
782 if (!(str = strchr_skip_twice(str, ' ')))
788 strncpy(str_cpy, str, 255);
789 // 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
790 int ret = rte_strsplit(str_cpy, 255, fields, 9, ' ');
795 struct acl4_rule rule;
796 struct acl4_rule *prule = &rule;
797 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
798 if (str_to_rule(&rule, fields, -1, 1) == 0) {
799 for (unsigned int i = 0; i < nb_cores; i++) {
800 lcore_id = lcores[i];
801 ring = ctrl_rings[lcore_id*MAX_TASKS_PER_CORE + task_id];
803 plog_err("No ring for control messages to core %u task %u\n", lcore_id, task_id);
806 #if RTE_VERSION < RTE_VERSION_NUM(17,5,0,1)
807 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&prule, 1));
809 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&prule, 1, NULL) == 0);
811 while (!rte_ring_empty(ring));
820 static int parse_cmd_gateway_ip(const char *str, struct input *input)
822 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, ip[4], nb_cores, i;
824 if (parse_core_task(str, lcores, &task_id, &nb_cores))
826 if (!(str = strchr_skip_twice(str, ' ')))
828 if (!strcmp(str, ""))
830 if (sscanf(str, "%u.%u.%u.%u", ip, ip + 1, ip + 2, ip + 3) != 4) {
833 for (i = 0; i < nb_cores; i++) {
834 lcore_id = lcores[i];
835 if ((!task_is_mode(lcore_id, task_id, "gen", "")) && (!task_is_mode(lcore_id, task_id, "gen", "l3"))) {
836 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
839 uint32_t gateway_ip = ((ip[3] & 0xFF) << 24) | ((ip[2] & 0xFF) << 16) | ((ip[1] & 0xFF) << 8) | ((ip[0] & 0xFF) << 0);
840 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
841 plog_info("Setting gateway ip to %s\n", str);
842 task_gen_set_gateway_ip(tbase, gateway_ip);
848 static int parse_cmd_local_ip(const char *str, struct input *input)
850 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, ip[4], nb_cores, i;
852 if (parse_core_task(str, lcores, &task_id, &nb_cores))
854 if (!(str = strchr_skip_twice(str, ' ')))
856 if (!strcmp(str, ""))
858 if (sscanf(str, "%u.%u.%u.%u", ip, ip + 1, ip + 2, ip + 3) != 4) {
861 for (i = 0; i < nb_cores; i++) {
862 lcore_id = lcores[i];
863 if (!task_is_mode(lcore_id, task_id, "arp", "local")) {
864 plog_err("Core %u task %u is not in arp mode\n", lcore_id, task_id);
867 uint32_t local_ip = ((ip[3] & 0xFF) << 24) | ((ip[2] & 0xFF) << 16) | ((ip[1] & 0xFF) << 8) | ((ip[0] & 0xFF) << 0);
868 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
869 plog_info("Setting local ip to %s\n", str);
870 task_arp_set_local_ip(tbase, local_ip);
876 static int parse_cmd_route_add(const char *str, struct input *input)
878 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, prefix, next_hop_idx, ip[4], nb_cores;
880 if (parse_core_task(str, lcores, &task_id, &nb_cores))
882 if (!(str = strchr_skip_twice(str, ' ')))
886 if (sscanf(str, "%u.%u.%u.%u/%u %u", ip, ip + 1, ip + 2, ip + 3,
887 &prefix, &next_hop_idx) != 8) {
890 struct rte_ring *ring;
892 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
893 for (unsigned int i = 0; i < nb_cores; i++) {
894 lcore_id = lcores[i];
895 ring = ctrl_rings[lcore_id*MAX_TASKS_PER_CORE + task_id];
897 plog_err("No ring for control messages to core %u task %u\n", lcore_id, task_id);
900 struct route_msg rmsg;
901 struct route_msg *pmsg = &rmsg;
903 rmsg.ip_bytes[0] = ip[0];
904 rmsg.ip_bytes[1] = ip[1];
905 rmsg.ip_bytes[2] = ip[2];
906 rmsg.ip_bytes[3] = ip[3];
907 rmsg.prefix = prefix;
908 rmsg.nh = next_hop_idx;
909 #if RTE_VERSION < RTE_VERSION_NUM(17,5,0,1)
910 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&pmsg, 1));
912 while (rte_ring_sp_enqueue_bulk(ring, (void *const *)&pmsg, 1, NULL) == 0);
914 while (!rte_ring_empty(ring));
921 static int parse_cmd_start(const char *str, struct input *input)
925 if (strncmp(str, "all", 3) == 0) {
927 sscanf(str, "%d", &task_id);
929 start_core_all(task_id);
934 uint32_t cores[64] = {0};
936 ret = parse_list_set(cores, str, 64);
940 str = strchr(str, ' ');
943 sscanf(str, "%d", &task_id);
945 start_cores(cores, ret, task_id);
950 static int parse_cmd_stop(const char *str, struct input *input)
954 if (strncmp(str, "all", 3) == 0) {
956 sscanf(str, "%d", &task_id);
957 stop_core_all(task_id);
962 uint32_t cores[64] = {0};
964 ret = parse_list_set(cores, str, 64);
968 str = strchr(str, ' ');
971 sscanf(str, "%d", &task_id);
973 stop_cores(cores, ret, task_id);
979 static int parse_cmd_rx_distr_start(const char *str, struct input *input)
981 unsigned lcore_id[RTE_MAX_LCORE];
985 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
991 for (int i = 0; i < nb_cores; ++i)
992 cmd_rx_distr_start(lcore_id[i]);
996 static int parse_cmd_tx_distr_start(const char *str, struct input *input)
998 unsigned lcore_id[RTE_MAX_LCORE];
1002 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1004 if (nb_cores <= 0) {
1008 for (int i = 0; i < nb_cores; ++i)
1009 cmd_tx_distr_start(lcore_id[i]);
1013 static int parse_cmd_rx_distr_stop(const char *str, struct input *input)
1015 unsigned lcore_id[RTE_MAX_LCORE];
1019 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1021 if (nb_cores <= 0) {
1025 for (int i = 0; i < nb_cores; ++i)
1026 cmd_rx_distr_stop(lcore_id[i]);
1030 static int parse_cmd_tx_distr_stop(const char *str, struct input *input)
1032 unsigned lcore_id[RTE_MAX_LCORE];
1036 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1038 if (nb_cores <= 0) {
1042 for (int i = 0; i < nb_cores; ++i)
1043 cmd_tx_distr_stop(lcore_id[i]);
1047 static int parse_cmd_rx_distr_reset(const char *str, struct input *input)
1049 unsigned lcore_id[RTE_MAX_LCORE];
1053 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1055 if (nb_cores <= 0) {
1059 for (int i = 0; i < nb_cores; ++i)
1060 cmd_rx_distr_rst(lcore_id[i]);
1064 static int parse_cmd_tx_distr_reset(const char *str, struct input *input)
1066 unsigned lcore_id[RTE_MAX_LCORE];
1070 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1072 if (nb_cores <= 0) {
1076 for (int i = 0; i < nb_cores; ++i)
1077 cmd_tx_distr_rst(lcore_id[i]);
1081 static int parse_cmd_rx_distr_show(const char *str, struct input *input)
1083 unsigned lcore_id[RTE_MAX_LCORE];
1087 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1089 if (nb_cores <= 0) {
1093 for (int i = 0; i < nb_cores; ++i)
1094 cmd_rx_distr_show(lcore_id[i]);
1098 static int parse_cmd_tx_distr_show(const char *str, struct input *input)
1100 unsigned lcore_id[RTE_MAX_LCORE];
1104 nb_cores = parse_list_set(lcore_id, str, sizeof(lcore_id)/sizeof(lcore_id[0]));
1106 if (nb_cores <= 0) {
1110 for (int i = 0; i < nb_cores; ++i)
1111 cmd_tx_distr_show(lcore_id[i]);
1115 static int parse_cmd_tot_stats(const char *str, struct input *input)
1117 if (strcmp("", str) != 0) {
1121 struct global_stats_sample *gsl = stats_get_global_stats(1);
1122 uint64_t tot_rx = gsl->host_rx_packets;
1123 uint64_t tot_tx = gsl->host_tx_packets;
1124 uint64_t last_tsc = gsl->tsc;
1128 snprintf(buf, sizeof(buf), "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n",
1129 tot_rx, tot_tx, last_tsc, rte_get_tsc_hz());
1130 input->reply(input, buf, strlen(buf));
1133 plog_info("RX: %"PRIu64", TX: %"PRIu64"\n", tot_rx, tot_tx);
1138 static int parse_cmd_update_interval(const char *str, struct input *input)
1142 if (sscanf(str, "%u", &val) != 1) {
1147 plog_err("Minimum update interval is 1 ms\n");
1150 plog_info("Setting update interval to %d ms\n", val);
1151 set_update_interval(val);
1156 static int parse_cmd_mem_info(const char *str, struct input *input)
1158 if (strcmp("", str) != 0) {
1167 static int parse_cmd_tot_ierrors_tot(const char *str, struct input *input)
1169 if (strcmp(str, "") != 0) {
1173 struct global_stats_sample *gsl = stats_get_global_stats(1);
1174 uint64_t tot = gsl->nics_ierrors;
1175 uint64_t last_tsc = gsl->tsc;
1179 snprintf(buf, sizeof(buf),
1180 "%"PRIu64",%"PRIu64",%"PRIu64"\n",
1181 tot, last_tsc, rte_get_tsc_hz());
1182 input->reply(input, buf, strlen(buf));
1185 plog_info("ierrors: %"PRIu64"\n", tot);
1190 static int parse_cmd_tot_imissed_tot(const char *str, struct input *input)
1192 if (strcmp(str, "") != 0) {
1196 struct global_stats_sample *gsl = stats_get_global_stats(1);
1197 uint64_t tot = gsl->nics_imissed;
1198 uint64_t last_tsc = gsl->tsc;
1202 snprintf(buf, sizeof(buf),
1203 "%"PRIu64",%"PRIu64",%"PRIu64"\n",
1204 tot, last_tsc, rte_get_tsc_hz());
1205 input->reply(input, buf, strlen(buf));
1208 plog_info("imissed: %"PRIu64"\n", tot);
1213 static int parse_cmd_reset_port(const char *str, struct input *input)
1217 if (sscanf(str, "%u", &port_id ) != 1) {
1221 cmd_reset_port(port_id);
1225 static int parse_cmd_write_reg(const char *str, struct input *input)
1230 if (sscanf(str, "%u %x %u", &port_id, &id, &val) != 3) {
1234 cmd_write_reg(port_id, id, val);
1238 static int parse_cmd_read_reg(const char *str, struct input *input)
1243 if (sscanf(str, "%u %x", &port_id, &id) != 2) {
1247 cmd_read_reg(port_id, id);
1251 static int parse_cmd_cache_reset(const char *str, struct input *input)
1257 static int parse_cmd_set_cache_class_mask(const char *str, struct input *input)
1263 if (sscanf(str, "%u %u %u", &lcore_id, &set, &val) != 3) {
1267 cmd_set_cache_class_mask(lcore_id, set, val);
1271 static int parse_cmd_set_cache_class(const char *str, struct input *input)
1276 if (sscanf(str, "%u %u", &lcore_id, &set) != 2) {
1280 cmd_set_cache_class(lcore_id, set);
1284 static int parse_cmd_get_cache_class_mask(const char *str, struct input *input)
1290 if (sscanf(str, "%u %u", &lcore_id, &set) != 2) {
1294 cmd_get_cache_class_mask(lcore_id, set, &val);
1297 snprintf(buf, sizeof(buf), "%d, %d, %x\n", lcore_id, set, val);
1298 input->reply(input, buf, strlen(buf));
1300 plog_info("core=%d, set=%d, mask=%x\n", lcore_id, set, val);
1305 static int parse_cmd_get_cache_class(const char *str, struct input *input)
1311 if (sscanf(str, "%u", &lcore_id) != 1) {
1315 cmd_get_cache_class(lcore_id, &set);
1318 snprintf(buf, sizeof(buf), "%d, %d\n", lcore_id, set);
1319 input->reply(input, buf, strlen(buf));
1321 plog_info("core=%d, cos=%d\n", lcore_id, set);
1326 static int parse_cmd_get_cache_mask(const char *str, struct input *input)
1332 if (sscanf(str, "%u", &lcore_id) != 1) {
1336 cmd_get_cache_class(lcore_id, &set);
1337 cmd_get_cache_class_mask(lcore_id, set, &mask);
1340 snprintf(buf, sizeof(buf), "%d, %x\n", lcore_id, mask);
1341 input->reply(input, buf, strlen(buf));
1343 plog_info("core=%d, mask=%x\n", lcore_id, mask);
1348 static int parse_cmd_set_vlan_offload(const char *str, struct input *input)
1353 if (sscanf(str, "%u %u", &port_id, &val) != 2) {
1357 cmd_set_vlan_offload(port_id, val);
1361 static int parse_cmd_set_vlan_filter(const char *str, struct input *input)
1366 if (sscanf(str, "%u %d %u", &port_id, &id, &val) != 3) {
1370 cmd_set_vlan_filter(port_id, id, val);
1374 static int parse_cmd_ring_info_all(const char *str, struct input *input)
1376 if (strcmp(str, "") != 0) {
1383 static int parse_cmd_port_up(const char *str, struct input *input)
1387 if (sscanf(str, "%u", &val) != 1) {
1395 static int parse_cmd_port_down(const char *str, struct input *input)
1399 if (sscanf(str, "%u", &val) != 1) {
1407 static int parse_cmd_port_link_state(const char *str, struct input *input)
1411 if (sscanf(str, "%u", &val) != 1) {
1415 if (!port_is_active(val))
1418 int active = prox_port_cfg[val].link_up;
1419 const char *state = active? "up\n" : "down\n";
1422 input->reply(input, state, strlen(state));
1424 plog_info("%s", state);
1429 static int parse_cmd_xstats(const char *str, struct input *input)
1433 if (sscanf(str, "%u", &val) != 1) {
1441 static int parse_cmd_stats(const char *str, struct input *input)
1443 if (strcmp(str, "") == 0)
1451 strncpy(buf, str, sizeof(buf) - 1);
1455 while ((tok = strchr(str, ','))) {
1457 stat_val = stats_parser_get(str);
1459 ret += sprintf(ret, "%s%"PRIu64"", list? "," :"", stat_val);
1464 stat_val = stats_parser_get(str);
1465 ret += sprintf(ret, "%s%"PRIu64"", list? "," :"", stat_val);
1470 input->reply(input, ret2, strlen(ret2));
1472 plog_info("%s", ret2);
1476 static void replace_char(char *str, char to_replace, char by)
1478 for (size_t i = 0; str[i] != '\0'; ++i) {
1479 if (str[i] == to_replace)
1484 static int parse_cmd_port_info(const char *str, struct input *input)
1488 if (strcmp(str, "all") == 0) {
1491 else if (sscanf(str, "%d", &val) != 1) {
1495 char port_info[2048];
1497 cmd_portinfo(val, port_info, sizeof(port_info));
1500 replace_char(port_info, '\n', ',');
1501 port_info[strlen(port_info) - 1] = '\n';
1502 input->reply(input, port_info, strlen(port_info));
1504 plog_info("%s", port_info);
1509 static int parse_cmd_ring_info(const char *str, struct input *input)
1511 unsigned lcores[RTE_MAX_LCORE], task_id, nb_cores;
1513 if (parse_core_task(str, lcores, &task_id, &nb_cores))
1516 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1517 for (unsigned int i = 0; i < nb_cores; i++) {
1518 cmd_ringinfo(lcores[i], task_id);
1524 static int parse_cmd_port_stats(const char *str, struct input *input)
1528 if (sscanf(str, "%u", &val) != 1) {
1532 struct get_port_stats s;
1533 if (stats_port(val, &s)) {
1534 plog_err("Invalid port %u\n", val);
1538 snprintf(buf, sizeof(buf),
1539 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64","
1540 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64","
1541 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n",
1542 s.no_mbufs_diff, s.ierrors_diff + s.imissed_diff,
1543 s.rx_bytes_diff, s.tx_bytes_diff,
1544 s.rx_pkts_diff, s.tx_pkts_diff,
1546 s.no_mbufs_tot, s.ierrors_tot + s.imissed_tot,
1547 s.last_tsc, s.prev_tsc);
1548 plog_info("%s", buf);
1550 input->reply(input, buf, strlen(buf));
1554 static int parse_cmd_core_stats(const char *str, struct input *input)
1556 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1558 if (parse_core_task(str, lcores, &task_id, &nb_cores))
1561 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1562 for (unsigned int i = 0; i < nb_cores; i++) {
1563 lcore_id = lcores[i];
1564 uint64_t tot_rx = stats_core_task_tot_rx(lcore_id, task_id);
1565 uint64_t tot_tx = stats_core_task_tot_tx(lcore_id, task_id);
1566 uint64_t tot_drop = stats_core_task_tot_drop(lcore_id, task_id);
1567 uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id);
1571 snprintf(buf, sizeof(buf),
1572 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n",
1573 tot_rx, tot_tx, tot_drop, last_tsc, rte_get_tsc_hz());
1574 input->reply(input, buf, strlen(buf));
1577 plog_info("RX: %"PRIu64", TX: %"PRIu64", DROP: %"PRIu64"\n",
1578 tot_rx, tot_tx, tot_drop);
1585 static int parse_cmd_lat_stats(const char *str, struct input *input)
1587 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1589 if (parse_core_task(str, lcores, &task_id, &nb_cores))
1592 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1593 for (unsigned int i = 0; i < nb_cores; i++) {
1594 lcore_id = lcores[i];
1595 if (!task_is_mode(lcore_id, task_id, "lat", "")) {
1596 plog_err("Core %u task %u is not measuring latency\n", lcore_id, task_id);
1599 struct stats_latency *stats = stats_latency_find(lcore_id, task_id);
1600 struct stats_latency *tot = stats_latency_tot_find(lcore_id, task_id);
1602 uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id);
1603 uint64_t lat_min_usec = time_unit_to_usec(&stats->min.time);
1604 uint64_t lat_max_usec = time_unit_to_usec(&stats->max.time);
1605 uint64_t tot_lat_min_usec = time_unit_to_usec(&tot->min.time);
1606 uint64_t tot_lat_max_usec = time_unit_to_usec(&tot->max.time);
1607 uint64_t lat_avg_usec = time_unit_to_usec(&stats->avg.time);
1611 snprintf(buf, sizeof(buf),
1612 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n",
1620 input->reply(input, buf, strlen(buf));
1623 plog_info("min: %"PRIu64", max: %"PRIu64", avg: %"PRIu64", min since reset: %"PRIu64", max since reset: %"PRIu64"\n",
1636 static int parse_cmd_irq(const char *str, struct input *input)
1639 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1641 if (parse_core_task(str, lcores, &task_id, &nb_cores))
1644 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1645 for (c = 0; c < nb_cores; c++) {
1646 lcore_id = lcores[c];
1647 if (!task_is_mode(lcore_id, task_id, "irq", "")) {
1648 plog_err("Core %u task %u is not in irq mode\n", lcore_id, task_id);
1650 struct task_irq *task_irq = (struct task_irq *)(lcore_cfg[lcore_id].tasks_all[task_id]);
1652 task_irq_show_stats(task_irq, input);
1659 static void task_lat_show_latency_histogram(uint8_t lcore_id, uint8_t task_id, struct input *input)
1661 #ifdef LATENCY_HISTOGRAM
1664 stats_core_lat_histogram(lcore_id, task_id, &buckets);
1666 if (buckets == NULL)
1670 char buf[4096] = {0};
1671 for (size_t i = 0; i < 128; i++)
1672 sprintf(buf+strlen(buf), "Bucket [%zu]: %"PRIu64"\n", i, buckets[i]);
1673 input->reply(input, buf, strlen(buf));
1676 for (size_t i = 0; i < 128; i++)
1678 plog_info("Bucket [%zu]: %"PRIu64"\n", i, buckets[i]);
1681 plog_info("LATENCY_DETAILS disabled\n");
1685 static int parse_cmd_lat_packets(const char *str, struct input *input)
1687 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1689 if (parse_core_task(str, lcores, &task_id, &nb_cores))
1692 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1693 for (unsigned int i = 0; i < nb_cores; i++) {
1694 lcore_id = lcores[i];
1695 if (!task_is_mode(lcore_id, task_id, "lat", "")) {
1696 plog_err("Core %u task %u is not measuring latency\n", lcore_id, task_id);
1699 task_lat_show_latency_histogram(lcore_id, task_id, input);
1706 static int parse_cmd_cgnat_public_hash(const char *str, struct input *input)
1708 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1710 if (parse_core_task(str, lcores, &task_id, &nb_cores))
1713 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1714 for (unsigned int i = 0; i < nb_cores; i++) {
1715 lcore_id = lcores[i];
1717 if (!task_is_mode(lcore_id, task_id, "cgnat", "")) {
1718 plog_err("Core %u task %u is not cgnat\n", lcore_id, task_id);
1721 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
1722 task_cgnat_dump_public_hash((struct task_nat *)tbase);
1729 static int parse_cmd_cgnat_private_hash(const char *str, struct input *input)
1731 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1734 if (parse_core_task(str, lcores, &task_id, &nb_cores))
1737 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1738 for (unsigned int i = 0; i < nb_cores; i++) {
1739 lcore_id = lcores[i];
1741 if (!task_is_mode(lcore_id, task_id, "cgnat", "")) {
1742 plog_err("Core %u task %u is not cgnat\n", lcore_id, task_id);
1745 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
1746 task_cgnat_dump_private_hash((struct task_nat *)tbase);
1753 static int parse_cmd_accuracy(const char *str, struct input *input)
1755 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1758 if (parse_core_task(str, lcores, &task_id, &nb_cores))
1760 if (!(str = strchr_skip_twice(str, ' ')))
1762 if (sscanf(str, "%"PRIu32"", &val) != 1)
1765 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1766 for (unsigned int i = 0; i < nb_cores; i++) {
1767 lcore_id = lcores[i];
1769 if (!task_is_mode(lcore_id, task_id, "lat", "")) {
1770 plog_err("Core %u task %u is not measuring latency\n", lcore_id, task_id);
1773 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
1775 task_lat_set_accuracy_limit((struct task_lat *)tbase, val);
1782 static int parse_cmd_rx_tx_info(const char *str, struct input *input)
1784 if (strcmp(str, "") != 0) {
1792 static int parse_cmd_version(const char *str, struct input *input)
1794 if (strcmp(str, "") != 0) {
1800 ((uint64_t)VERSION_MAJOR) << 24 |
1801 ((uint64_t)VERSION_MINOR) << 16 |
1802 ((uint64_t)VERSION_REV) << 8;
1805 snprintf(buf, sizeof(buf), "%"PRIu64",%"PRIu64"\n", version, (uint64_t)RTE_VERSION);
1806 input->reply(input, buf, strlen(buf));
1809 plog_info("prox version: %d.%d, DPDK version: %s\n",
1810 VERSION_MAJOR, VERSION_MINOR,
1811 rte_version() + sizeof(RTE_VER_PREFIX));
1820 int (*parse)(const char *args, struct input *input);
1823 static int parse_cmd_help(const char *str, struct input *input);
1825 static struct cmd_str cmd_strings[] = {
1826 {"history", "", "Print command history", parse_cmd_history},
1827 {"echo", "", "echo parameter, useful to resolving variables", parse_cmd_echo},
1828 {"quit", "", "Stop all cores and quit", parse_cmd_quit},
1829 {"quit_force", "", "Quit without waiting on cores to stop", parse_cmd_quit_force},
1830 {"help", "<substr>", "Show list of commands that have <substr> as a substring. If no substring is provided, all commands are shown.", parse_cmd_help},
1831 {"verbose", "<level>", "Set verbosity level", parse_cmd_verbose},
1832 {"thread info", "<core_id> <task_id>", "", parse_cmd_thread_info},
1833 {"mem info", "", "Show information about system memory (number of huge pages and addresses of these huge pages)", parse_cmd_mem_info},
1834 {"update interval", "<value>", "Update statistics refresh rate, in msec (must be >=10). Default is 1 second", parse_cmd_update_interval},
1835 {"rx tx info", "", "Print connections between tasks on all cores", parse_cmd_rx_tx_info},
1836 {"start", "<core list>|all <task_id>", "Start core <core_id> or all cores", parse_cmd_start},
1837 {"stop", "<core list>|all <task_id>", "Stop core <core id> or all cores", parse_cmd_stop},
1839 {"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},
1840 {"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},
1841 {"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},
1842 {"rx distr start", "", "Start gathering statistical distribution of received packets", parse_cmd_rx_distr_start},
1843 {"rx distr stop", "", "Stop gathering statistical distribution of received packets", parse_cmd_rx_distr_stop},
1844 {"rx distr reset", "", "Reset gathered statistical distribution of received packets", parse_cmd_rx_distr_reset},
1845 {"rx distr show", "", "Display gathered statistical distribution of received packets", parse_cmd_rx_distr_show},
1846 {"tx distr start", "", "Start gathering statistical distribution of xmitted packets", parse_cmd_tx_distr_start},
1847 {"tx distr stop", "", "Stop gathering statistical distribution of xmitted packets", parse_cmd_tx_distr_stop},
1848 {"tx distr reset", "", "Reset gathered statistical distribution of xmitted packets", parse_cmd_tx_distr_reset},
1849 {"tx distr show", "", "Display gathered statistical distribution of xmitted packets", parse_cmd_tx_distr_show},
1851 {"rate", "<port id> <queue id> <rate>", "rate does not include preamble, SFD and IFG", parse_cmd_rate},
1852 {"count","<core id> <task id> <count>", "Generate <count> packets", parse_cmd_count},
1853 {"bypass", "<core_id> <task_id>", "Bypass task", parse_cmd_bypass},
1854 {"reconnect", "<core_id> <task_id>", "Reconnect task", parse_cmd_reconnect},
1855 {"pkt_size", "<core_id> <task_id> <pkt_size>", "Set the packet size to <pkt_size>", parse_cmd_pkt_size},
1856 {"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},
1857 {"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},
1858 {"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},
1859 {"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},
1860 {"reset values all", "", "Undo all \"set value\" commands on all cores/tasks", parse_cmd_reset_values_all},
1861 {"reset randoms all", "", "Undo all \"set random\" commands on all cores/tasks", parse_cmd_reset_randoms_all},
1862 {"reset values", "<core id> <task id>", "Undo all \"set value\" commands on specified core/task", parse_cmd_reset_values},
1864 {"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},
1865 {"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},
1866 {"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},
1867 {"gateway ip", "<core id> <task id> <ip>", "Define/Change IP address of destination gateway on core <core id> <task id>.", parse_cmd_gateway_ip},
1868 {"local ip", "<core id> <task id> <ip>", "Define/Change IP address of destination gateway on core <core id> <task id>.", parse_cmd_local_ip},
1870 {"pps unit", "", "Change core stats pps unit", parse_cmd_pps_unit},
1871 {"reset stats", "", "Reset all statistics", parse_cmd_reset_stats},
1872 {"reset lat stats", "", "Reset all latency statistics", parse_cmd_reset_lat_stats},
1873 {"tot stats", "", "Print total RX and TX packets", parse_cmd_tot_stats},
1874 {"tot ierrors tot", "", "Print total number of ierrors since reset", parse_cmd_tot_ierrors_tot},
1875 {"tot imissed tot", "", "Print total number of imissed since reset", parse_cmd_tot_imissed_tot},
1876 {"lat stats", "<core id> <task id>", "Print min,max,avg latency as measured during last sampling interval", parse_cmd_lat_stats},
1877 {"irq stats", "<core id> <task id>", "Print irq related infos", parse_cmd_irq},
1878 {"lat packets", "<core id> <task id>", "Print the latency for each of the last set of packets", parse_cmd_lat_packets},
1879 {"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},
1880 {"core stats", "<core id> <task id>", "Print rx/tx/drop for task <task id> running on core <core id>", parse_cmd_core_stats},
1881 {"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},
1882 {"read reg", "", "Read register", parse_cmd_read_reg},
1883 {"write reg", "", "Read register", parse_cmd_write_reg},
1884 {"set vlan offload", "", "Set Vlan offload", parse_cmd_set_vlan_offload},
1885 {"set vlan filter", "", "Set Vlan filter", parse_cmd_set_vlan_filter},
1886 {"reset cache", "", "Reset cache", parse_cmd_cache_reset},
1887 {"set cache class mask", "<core id> <class> <mask>", "Set cache class mask for <core id>", parse_cmd_set_cache_class_mask},
1888 {"get cache class mask", "<core id> <class>", "Get cache class mask", parse_cmd_get_cache_class_mask},
1889 {"set cache class", "<core id> <class>", "Set cache class", parse_cmd_set_cache_class},
1890 {"get cache class", "<core id>", "Get cache class", parse_cmd_get_cache_class},
1891 {"get cache mask", "<core id>", "Get cache mask", parse_cmd_get_cache_mask},
1892 {"reset port", "", "Reset port", parse_cmd_reset_port},
1893 {"ring info all", "", "Get information about ring, such as ring size and number of elements in the ring", parse_cmd_ring_info_all},
1894 {"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},
1895 {"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},
1896 {"port up", "<port id>", "Set the port up", parse_cmd_port_up},
1897 {"port down", "<port id>", "Set the port down", parse_cmd_port_down},
1898 {"port link state", "<port id>", "Get link state (up or down) for port", parse_cmd_port_link_state},
1899 {"port xstats", "<port id>", "Get extra statistics for the port", parse_cmd_xstats},
1900 {"stats", "<stats_path>", "Get stats as sepcified by <stats_path>. A comma-separated list of <stats_path> can be supplied", parse_cmd_stats},
1901 {"cgnat dump public hash", "<core id> <task id>", "Dump cgnat public hash table", parse_cmd_cgnat_public_hash},
1902 {"cgnat dump private hash", "<core id> <task id>", "Dump cgnat private hash table", parse_cmd_cgnat_private_hash},
1903 {"delay_us", "<core_id> <task_id> <delay_us>", "Set the delay in usec for the impair mode to <delay_us>", parse_cmd_delay_us},
1904 {"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},
1905 {"probability", "<core_id> <task_id> <probability>", "Set the percent of forwarded packets for the impair mode", parse_cmd_set_probability},
1906 {"version", "", "Show version", parse_cmd_version},
1910 static int parse_cmd_help(const char *str, struct input *input)
1912 /* str contains the arguments, all commands that have str as a
1913 substring will be shown. */
1914 size_t len, len2, longest_cmd = 0;
1915 for (size_t i = 0; i < cmd_parser_n_cmd(); ++i) {
1916 if (longest_cmd <strlen(cmd_strings[i].cmd))
1917 longest_cmd = strlen(cmd_strings[i].cmd);
1919 /* A single call to log will be executed after the help string
1920 has been built. The reason for this is to make use of the
1922 char buf[32768] = {0};
1924 for (size_t i = 0; i < cmd_parser_n_cmd(); ++i) {
1926 const size_t cmd_len = strlen(cmd_strings[i].cmd);
1927 for (size_t j = 0; j < cmd_len; ++j) {
1929 for (size_t k = 0; k < strlen(str); ++k) {
1930 if (str[k] != (cmd_strings[i].cmd + j)[k]) {
1941 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s", cmd_strings[i].cmd);
1942 len = strlen(cmd_strings[i].cmd);
1943 while (len < longest_cmd) {
1945 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " ");
1948 if (strlen(cmd_strings[i].args)) {
1949 char tmp[256] = {0};
1950 strncpy(tmp, cmd_strings[i].args, 128);
1951 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "Arguments: %s\n", tmp);
1953 if (strlen(cmd_strings[i].help)) {
1956 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " ");
1961 if (strlen(cmd_strings[i].help)) {
1963 const char *h = cmd_strings[i].help;
1969 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " ");
1972 char tmp[128] = {0};
1973 const size_t max_len = strlen(h) > 80? 80 : strlen(h);
1974 size_t len3 = max_len;
1976 while (len3 && h[len3] != ' ')
1982 strncpy(tmp, h, len3);
1984 while (h[0] == ' ' && strlen(h))
1987 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s\n", tmp);
1991 if (strlen(cmd_strings[i].help) == 0&& strlen(cmd_strings[i].args) == 0) {
1992 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "\n");
1995 plog_info("%s", buf);
2000 const char *cmd_parser_cmd(size_t i)
2002 i = i < cmd_parser_n_cmd()? i: cmd_parser_n_cmd();
2003 return cmd_strings[i].cmd;
2006 size_t cmd_parser_n_cmd(void)
2008 return sizeof(cmd_strings)/sizeof(cmd_strings[0]) - 1;
2011 void cmd_parser_parse(const char *str, struct input *input)
2015 for (size_t i = 0; i < cmd_parser_n_cmd(); ++i) {
2016 skip = strlen(cmd_strings[i].cmd);
2017 if (strncmp(cmd_strings[i].cmd, str, skip) == 0 &&
2018 (str[skip] == ' ' || str[skip] == 0)) {
2019 while (str[skip] == ' ')
2022 if (cmd_strings[i].parse(str + skip, input) != 0) {
2023 plog_warn("Invalid syntax for command '%s': %s %s\n",
2024 cmd_strings[i].cmd, cmd_strings[i].args, cmd_strings[i].help);
2030 plog_err("Unknown command: '%s'\n", str);