2 // Copyright (c) 2010-2019 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 #include "prox_compat.h"
58 static int core_task_is_valid(int lcore_id, int task_id)
60 if (lcore_id >= RTE_MAX_LCORE) {
61 plog_err("Invalid core id %u (lcore ID above %d)\n", lcore_id, RTE_MAX_LCORE);
64 else if (!prox_core_active(lcore_id, 0)) {
65 plog_err("Invalid core id %u (lcore is not active)\n", lcore_id);
68 else if (task_id >= lcore_cfg[lcore_id].n_tasks_all) {
69 plog_err("Invalid task id (valid task IDs for core %u are below %u)\n",
70 lcore_id, lcore_cfg[lcore_id].n_tasks_all);
76 static int cores_task_are_valid(unsigned int *lcores, int task_id, unsigned int nb_cores)
78 unsigned int lcore_id;
79 for (unsigned int i = 0; i < nb_cores; i++) {
81 if (core_task_is_valid(lcore_id, task_id) == 0)
87 static int parse_cores_task(const char *str, uint32_t *lcore_id, uint32_t *task_id, unsigned *nb_cores)
89 char str_lcore_id[128];
92 if (2 != sscanf(str, "%s %u", str_lcore_id, task_id))
95 if ((ret = parse_list_set(lcore_id, str_lcore_id, RTE_MAX_LCORE)) <= 0) {
96 plog_err("Invalid core while parsing command (%s)\n", get_parse_err());
104 static int parse_cores_tasks(const char *str, uint32_t *lcore_id, uint32_t *task_id, unsigned *nb_cores, unsigned *nb_tasks)
106 char str_lcore_id[128], str_task_id[128];
109 if (2 != sscanf(str, "%s %s", str_lcore_id, str_task_id))
112 if ((ret = parse_list_set(lcore_id, str_lcore_id, RTE_MAX_LCORE)) <= 0) {
113 plog_err("Invalid core while parsing command (%s)\n", get_parse_err());
118 if ((ret = parse_list_set(task_id, str_task_id, MAX_TASKS_PER_CORE)) <= 0) {
119 plog_err("Invalid task while parsing command (%s)\n", get_parse_err());
127 static const char *strchr_skip_twice(const char *str, int chr)
129 str = strchr(str, chr);
134 str = strchr(str, chr);
140 static int parse_cmd_quit(const char *str, struct input *input)
142 if (strcmp(str, "") != 0) {
150 static int parse_cmd_quit_force(const char *str, struct input *input)
152 if (strcmp(str, "") != 0) {
159 static int parse_cmd_history(const char *str, struct input *input)
161 if (strcmp(str, "") != 0) {
165 if (input->history) {
166 input->history(input);
169 plog_err("Invalid history comand ");
173 static int parse_cmd_echo(const char *str, struct input *input)
175 if (strcmp(str, "") == 0) {
181 if (parse_vars(resolved, sizeof(resolved), str)) {
186 if (strlen(resolved) + 2 < sizeof(resolved)) {
187 resolved[strlen(resolved) + 1] = 0;
188 resolved[strlen(resolved)] = '\n';
193 input->reply(input, resolved, strlen(resolved));
195 plog_info("%s\n", resolved);
200 static int parse_cmd_reset_stats(const char *str, struct input *input)
202 if (strcmp(str, "") != 0) {
210 static int parse_cmd_reset_lat_stats(const char *str, struct input *input)
212 if (strcmp(str, "") != 0) {
216 stats_latency_reset();
220 static int parse_cmd_trace(const char *str, struct input *input)
222 unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores;
224 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
226 if (!(str = strchr_skip_twice(str, ' ')))
228 if (sscanf(str, "%u", &nb_packets) != 1)
231 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
232 for (unsigned int i = 0; i < nb_cores; i++) {
233 cmd_trace(lcores[i], task_id, nb_packets);
239 static int parse_cmd_dump_rx(const char *str, struct input *input)
241 unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores;
243 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
245 if (!(str = strchr_skip_twice(str, ' ')))
247 if (sscanf(str, "%u", &nb_packets) != 1) {
251 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
252 for (unsigned int i = 0; i < nb_cores; i++) {
253 if (lcores[i] > RTE_MAX_LCORE) {
254 plog_warn("core_id too high, maximum allowed is: %u\n", RTE_MAX_LCORE);
256 } else if (task_id >= lcore_cfg[lcores[i]].n_tasks_all) {
257 plog_warn("task_id too high, should be in [0, %u]\n", lcore_cfg[lcores[i]].n_tasks_all - 1);
260 struct lcore_cfg *lconf = &lcore_cfg[lcores[i]];
261 struct task_base *tbase = lconf->tasks_all[task_id];
262 int prev_count = tbase->aux->rx_prev_count;
263 if (((prev_count) && (tbase->aux->rx_pkt_prev[prev_count - 1] == rx_pkt_dummy))
264 || (tbase->rx_pkt == rx_pkt_dummy)) {
265 plog_warn("Unable to dump_rx as rx_pkt_dummy\n");
269 cmd_dump(lcores[i], task_id, nb_packets, input, 1, 0);
275 static int parse_cmd_pps_unit(const char *str, struct input *input)
279 if (sscanf(str, "%u", &val) != 1) {
282 display_set_pps_unit(val);
286 static int parse_cmd_dump_tx(const char *str, struct input *input)
288 unsigned lcores[RTE_MAX_LCORE], task_id, nb_packets, nb_cores;
290 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
292 if (!(str = strchr_skip_twice(str, ' ')))
294 if (sscanf(str, "%u", &nb_packets) != 1) {
298 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
299 for (unsigned int i = 0; i < nb_cores; i++) {
300 cmd_dump(lcores[i], task_id, nb_packets, input, 0, 1);
306 static int parse_cmd_rate(const char *str, struct input *input)
308 unsigned queue, port, rate;
310 if (sscanf(str, "%u %u %u", &queue, &port, &rate) != 3) {
314 if (port > PROX_MAX_PORTS) {
315 plog_err("Max port id allowed is %u (specified %u)\n", PROX_MAX_PORTS, port);
317 else if (!prox_port_cfg[port].active) {
318 plog_err("Port %u not active\n", port);
320 else if (queue >= prox_port_cfg[port].n_txq) {
321 plog_err("Number of active queues is %u\n",
322 prox_port_cfg[port].n_txq);
324 else if (rate > prox_port_cfg[port].link_speed) {
325 plog_err("Max rate allowed on port %u queue %u is %u Mbps\n",
326 port, queue, prox_port_cfg[port].link_speed);
330 plog_info("Disabling rate limiting on port %u queue %u\n",
334 plog_info("Setting rate limiting to %u Mbps on port %u queue %u\n",
337 rte_eth_set_queue_rate_limit(port, queue, rate);
342 int task_is_mode_and_submode(uint32_t lcore_id, uint32_t task_id, const char *mode, const char *sub_mode)
344 struct task_args *targs = &lcore_cfg[lcore_id].targs[task_id];
346 return !strcmp(targs->task_init->mode_str, mode) && !strcmp(targs->sub_mode_str, sub_mode);
349 int task_is_mode(uint32_t lcore_id, uint32_t task_id, const char *mode)
351 struct task_init *t = lcore_cfg[lcore_id].targs[task_id].task_init;
353 return !strcmp(t->mode_str, mode);
356 int task_is_sub_mode(uint32_t lcore_id, uint32_t task_id, const char *sub_mode)
358 struct task_args *targs = &lcore_cfg[lcore_id].targs[task_id];
360 return !strcmp(targs->sub_mode_str, sub_mode);
363 static void log_pkt_count(uint32_t count, uint32_t lcore_id, uint32_t task_id)
365 if (count == UINT32_MAX)
366 plog_info("Core %u task %u will keep sending packets\n", lcore_id, task_id);
368 plog_info("Core %u task %u waits for next count command\n", lcore_id, task_id);
370 plog_info("Core %u task %u stopping after %u packets\n", lcore_id, task_id, count);
373 static int parse_cmd_count(const char *str, struct input *input)
375 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, count, nb_cores;
377 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
379 if (!(str = strchr_skip_twice(str, ' ')))
381 if (sscanf(str, "%u", &count) != 1)
384 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
385 for (unsigned int i = 0; i < nb_cores; i++) {
386 lcore_id = lcores[i];
387 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
388 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
391 struct task_base *task = lcore_cfg[lcore_id].tasks_all[task_id];
393 log_pkt_count(count, lcore_id, task_id);
394 task_gen_set_pkt_count(task, count);
401 static int parse_cmd_set_probability(const char *str, struct input *input)
403 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
406 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
408 if (!(str = strchr_skip_twice(str, ' ')))
410 if (sscanf(str, "%f", &probability) != 1)
413 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
414 for (unsigned int i = 0; i < nb_cores; i++) {
415 lcore_id = lcores[i];
416 if ((!task_is_mode_and_submode(lcore_id, task_id, "impair", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "impair", "l3"))){
417 plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id);
419 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
420 task_impair_set_proba(tbase, probability);
427 static int parse_cmd_delay_us(const char *str, struct input *input)
429 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, delay_us, nb_cores;
431 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
433 if (!(str = strchr_skip_twice(str, ' ')))
435 if (sscanf(str, "%d", &delay_us) != 1)
438 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
439 for (unsigned int i = 0; i < nb_cores; i++) {
440 lcore_id = lcores[i];
441 if ((!task_is_mode_and_submode(lcore_id, task_id, "impair", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "impair", "l3"))){
442 plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id);
444 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
445 task_impair_set_delay_us(tbase, delay_us, 0);
452 static int parse_cmd_random_delay_us(const char *str, struct input *input)
454 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, delay_us, nb_cores;
456 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
458 if (!(str = strchr_skip_twice(str, ' ')))
460 if (sscanf(str, "%d", &delay_us) != 1)
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 ((!task_is_mode_and_submode(lcore_id, task_id, "impair", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "impair", "l3"))){
467 plog_err("Core %u task %u is not impairing packets\n", lcore_id, task_id);
469 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
470 task_impair_set_delay_us(tbase, 0, delay_us);
477 static int parse_cmd_bypass(const char *str, struct input *input)
479 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores;
481 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
483 if ((prox_cfg.flags & DSF_ENABLE_BYPASS) == 0) {
484 plog_err("enable bypass not set => command not supported\n");
488 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
489 for (unsigned int i = 0; i < nb_cores; i++) {
490 lcore_id = lcores[i];
491 if (bypass_task(lcore_id, task_id) != 0)
498 static int parse_cmd_reconnect(const char *str, struct input *input)
500 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores;
502 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
504 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
505 for (unsigned int i = 0; i < nb_cores; i++) {
506 lcore_id = lcores[i];
507 if (reconnect_task(lcore_id, task_id) != 0)
514 static int parse_cmd_pkt_size(const char *str, struct input *input)
516 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, pkt_size, nb_cores;
518 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
520 if (!(str = strchr_skip_twice(str, ' ')))
522 if (sscanf(str, "%d", &pkt_size) != 1)
525 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
526 for (unsigned int i = 0; i < nb_cores; i++) {
527 lcore_id = lcores[i];
528 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
529 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
531 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
532 task_gen_set_pkt_size(tbase, pkt_size); /* error printed within function */
539 static int parse_cmd_speed(const char *str, struct input *input)
541 unsigned lcores[RTE_MAX_LCORE], task_id, lcore_id, nb_cores;
545 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
547 if (!(str = strchr_skip_twice(str, ' ')))
549 if (sscanf(str, "%f", &speed) != 1) {
553 if (!cores_task_are_valid(lcores, task_id, nb_cores)) {
557 for (i = 0; i < nb_cores; i++) {
558 lcore_id = lcores[i];
559 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
560 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
562 else if (speed > 1000.0f || speed < 0.0f) { // Up to 100 Gbps
563 plog_err("Speed out of range (must be betweeen 0%% and 1000%%)\n");
566 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
567 uint64_t bps = speed * 12500000;
569 plog_info("Setting rate to %"PRIu64" Bps\n", bps);
571 task_gen_set_rate(tbase, bps);
577 static int parse_cmd_speed_byte(const char *str, struct input *input)
579 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
582 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
584 if (!(str = strchr_skip_twice(str, ' ')))
586 if (sscanf(str, "%"PRIu64"", &bps) != 1)
589 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
590 for (unsigned int i = 0; i < nb_cores; i++) {
591 lcore_id = lcores[i];
593 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
594 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
596 else if (bps > 12500000000) { // Up to 100Gbps
597 plog_err("Speed out of range (must be <= 12500000000)\n");
600 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
602 plog_info("Setting rate to %"PRIu64" Bps\n", bps);
603 task_gen_set_rate(tbase, bps);
610 static int parse_cmd_reset_randoms_all(const char *str, struct input *input)
612 if (strcmp(str, "") != 0) {
616 unsigned task_id, lcore_id = -1;
617 while (prox_core_next(&lcore_id, 0) == 0) {
618 for (task_id = 0; task_id < lcore_cfg[lcore_id].n_tasks_all; task_id++) {
619 if ((task_is_mode_and_submode(lcore_id, task_id, "gen", "")) || (task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
620 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
621 uint32_t n_rands = task_gen_get_n_randoms(tbase);
623 plog_info("Resetting randoms on core %d task %d from %d randoms\n", lcore_id, task_id, n_rands);
624 task_gen_reset_randoms(tbase);
631 static int parse_cmd_reset_values_all(const char *str, struct input *input)
633 if (strcmp(str, "") != 0) {
637 unsigned task_id, lcore_id = -1;
638 while (prox_core_next(&lcore_id, 0) == 0) {
639 for (task_id = 0; task_id < lcore_cfg[lcore_id].n_tasks_all; task_id++) {
640 if ((task_is_mode_and_submode(lcore_id, task_id, "gen", "")) || (task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
641 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
643 plog_info("Resetting values on core %d task %d\n", lcore_id, task_id);
644 task_gen_reset_values(tbase);
651 static int parse_cmd_reset_values(const char *str, struct input *input)
653 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
655 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
658 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
659 for (unsigned int i = 0; i < nb_cores; i++) {
660 lcore_id = lcores[i];
661 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
662 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
665 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
667 plog_info("Resetting values on core %d task %d\n", lcore_id, task_id);
668 task_gen_reset_values(tbase);
675 static int parse_cmd_set_value(const char *str, struct input *input)
677 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, value, nb_cores;
678 unsigned short offset;
681 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
683 if (!(str = strchr_skip_twice(str, ' ')))
685 if (sscanf(str, "%hu %u %hhu", &offset, &value, &value_len) != 3) {
689 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
690 for (unsigned int i = 0; i < nb_cores; i++) {
691 lcore_id = lcores[i];
692 if ((!task_is_mode_and_submode(lcore_id, task_id, "gen", "")) && (!task_is_mode_and_submode(lcore_id, task_id, "gen", "l3"))) {
693 plog_err("Core %u task %u is not generating packets\n", lcore_id, task_id);
695 // do not check offset here - gen knows better than us the maximum frame size
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" - invalid offset/len\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 > PROX_RTE_ETHER_MAX_LEN) {
735 plog_err("Offset out of range (must be less then %u)\n", PROX_RTE_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 prox_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_enable_multicast(const char *str, struct input *input)
1259 prox_rte_ether_addr mac;
1261 if (sscanf(str, "%hhu %hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &port_id, mac.addr_bytes, mac.addr_bytes + 1, mac.addr_bytes + 2, mac.addr_bytes + 3, mac.addr_bytes + 4, mac.addr_bytes + 5 ) != 7) {
1264 cmd_multicast(port_id, 1, &mac);
1268 static int parse_cmd_disable_multicast(const char *str, struct input *input)
1271 prox_rte_ether_addr mac;
1273 if (sscanf(str, "%hhu %hhx:%hhx:%hhx:%hhx:%hhx:%hhx", &port_id, mac.addr_bytes, mac.addr_bytes + 1, mac.addr_bytes + 2, mac.addr_bytes + 3, mac.addr_bytes + 4, mac.addr_bytes + 5 ) != 7) {
1277 cmd_multicast(port_id, 0, &mac);
1281 static int parse_cmd_reset_port(const char *str, struct input *input)
1285 if (sscanf(str, "%u", &port_id ) != 1) {
1289 cmd_reset_port(port_id);
1293 static int parse_cmd_write_reg(const char *str, struct input *input)
1298 if (sscanf(str, "%u %x %u", &port_id, &id, &val) != 3) {
1302 cmd_write_reg(port_id, id, val);
1306 static int parse_cmd_read_reg(const char *str, struct input *input)
1311 if (sscanf(str, "%u %x", &port_id, &id) != 2) {
1315 cmd_read_reg(port_id, id);
1319 static int parse_cmd_cache_reset(const char *str, struct input *input)
1325 static int parse_cmd_set_cache_class_mask(const char *str, struct input *input)
1331 if (sscanf(str, "%u %u %u", &lcore_id, &set, &val) != 3) {
1335 cmd_set_cache_class_mask(lcore_id, set, val);
1339 static int parse_cmd_set_cache_class(const char *str, struct input *input)
1344 if (sscanf(str, "%u %u", &lcore_id, &set) != 2) {
1348 cmd_set_cache_class(lcore_id, set);
1352 static int parse_cmd_get_cache_class_mask(const char *str, struct input *input)
1358 if (sscanf(str, "%u %u", &lcore_id, &set) != 2) {
1362 cmd_get_cache_class_mask(lcore_id, set, &val);
1365 snprintf(buf, sizeof(buf), "%d, %d, %x\n", lcore_id, set, val);
1366 input->reply(input, buf, strlen(buf));
1368 plog_info("core=%d, set=%d, mask=%x\n", lcore_id, set, val);
1373 static int parse_cmd_get_cache_class(const char *str, struct input *input)
1379 if (sscanf(str, "%u", &lcore_id) != 1) {
1383 cmd_get_cache_class(lcore_id, &set);
1386 snprintf(buf, sizeof(buf), "%d, %d\n", lcore_id, set);
1387 input->reply(input, buf, strlen(buf));
1389 plog_info("core=%d, cos=%d\n", lcore_id, set);
1394 static int parse_cmd_get_cache_mask(const char *str, struct input *input)
1400 if (sscanf(str, "%u", &lcore_id) != 1) {
1404 cmd_get_cache_class(lcore_id, &set);
1405 cmd_get_cache_class_mask(lcore_id, set, &mask);
1408 snprintf(buf, sizeof(buf), "%d, %x\n", lcore_id, mask);
1409 input->reply(input, buf, strlen(buf));
1411 plog_info("core=%d, mask=%x\n", lcore_id, mask);
1416 static int parse_cmd_set_vlan_offload(const char *str, struct input *input)
1421 if (sscanf(str, "%u %u", &port_id, &val) != 2) {
1425 cmd_set_vlan_offload(port_id, val);
1429 static int parse_cmd_set_vlan_filter(const char *str, struct input *input)
1434 if (sscanf(str, "%u %d %u", &port_id, &id, &val) != 3) {
1438 cmd_set_vlan_filter(port_id, id, val);
1442 static int parse_cmd_ring_info_all(const char *str, struct input *input)
1444 if (strcmp(str, "") != 0) {
1451 static int parse_cmd_port_up(const char *str, struct input *input)
1455 if (sscanf(str, "%u", &val) != 1) {
1463 static int parse_cmd_port_down(const char *str, struct input *input)
1467 if (sscanf(str, "%u", &val) != 1) {
1475 static int parse_cmd_port_link_state(const char *str, struct input *input)
1479 if (sscanf(str, "%u", &val) != 1) {
1483 if (!port_is_active(val))
1486 int active = prox_port_cfg[val].link_up;
1487 const char *state = active? "up\n" : "down\n";
1490 input->reply(input, state, strlen(state));
1492 plog_info("%s", state);
1497 static int parse_cmd_xstats(const char *str, struct input *input)
1501 if (sscanf(str, "%u", &val) != 1) {
1509 static int parse_cmd_stats(const char *str, struct input *input)
1511 if (strcmp(str, "") == 0)
1519 prox_strncpy(buf, str, sizeof(buf) - 1);
1523 while ((tok = strchr(str, ','))) {
1525 stat_val = stats_parser_get(str);
1527 ret += sprintf(ret, "%s%"PRIu64"", list? "," :"", stat_val);
1532 stat_val = stats_parser_get(str);
1533 ret += sprintf(ret, "%s%"PRIu64"", list? "," :"", stat_val);
1538 input->reply(input, ret2, strlen(ret2));
1540 plog_info("%s", ret2);
1544 static void replace_char(char *str, char to_replace, char by)
1546 for (size_t i = 0; str[i] != '\0'; ++i) {
1547 if (str[i] == to_replace)
1552 static int parse_cmd_port_info(const char *str, struct input *input)
1556 if (strcmp(str, "all") == 0) {
1559 else if (sscanf(str, "%d", &val) != 1) {
1563 char port_info[2048];
1565 cmd_portinfo(val, port_info, sizeof(port_info));
1568 replace_char(port_info, '\n', ',');
1569 port_info[strlen(port_info) - 1] = '\n';
1570 input->reply(input, port_info, strlen(port_info));
1572 plog_info("%s", port_info);
1577 static int parse_cmd_ring_info(const char *str, struct input *input)
1579 unsigned lcores[RTE_MAX_LCORE], task_id, nb_cores;
1581 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1584 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1585 for (unsigned int i = 0; i < nb_cores; i++) {
1586 cmd_ringinfo(lcores[i], task_id);
1592 static int parse_cmd_port_stats(const char *str, struct input *input)
1596 if (sscanf(str, "%u", &val) != 1) {
1600 struct get_port_stats s;
1601 if (stats_port(val, &s)) {
1602 plog_err("Invalid port %u\n", val);
1606 snprintf(buf, sizeof(buf),
1607 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64","
1608 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64","
1609 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n",
1610 s.no_mbufs_diff, s.ierrors_diff + s.imissed_diff,
1611 s.rx_bytes_diff, s.tx_bytes_diff,
1612 s.rx_pkts_diff, s.tx_pkts_diff,
1614 s.no_mbufs_tot, s.ierrors_tot + s.imissed_tot,
1615 s.last_tsc, s.prev_tsc);
1616 plog_info("%s", buf);
1618 input->reply(input, buf, strlen(buf));
1622 static int parse_cmd_multi_port_stats(const char *str, struct input *input)
1624 uint32_t ports[PROX_MAX_PORTS];
1625 int nb_ports = parse_list_set(ports, str, PROX_MAX_PORTS);
1626 if (nb_ports <= 0) {
1630 char buf[PROX_MAX_PORTS * (11+5*21) + 1], *pbuf = buf;
1631 int left = sizeof(buf);
1632 for (int i = 0; i < nb_ports; ++i) {
1633 struct get_port_stats s;
1634 if (stats_port(ports[i], &s)) {
1635 plog_err("Invalid port %u\n", ports[i]);
1639 int len = snprintf(pbuf, left,
1641 "%"PRIu64",%"PRIu64","
1642 "%"PRIu64",%"PRIu64","
1644 //TODO: adjust buf size above when adding fields
1647 s.no_mbufs_tot, s.ierrors_tot + s.imissed_tot,
1649 if ((len < 0) || (len >= left)) {
1650 plog_err("Cannot print stats for port %u\n", ports[i]);
1659 plog_info("%s", buf);
1661 input->reply(input, buf, sizeof(buf) - left);
1665 static int parse_cmd_core_stats(const char *str, struct input *input)
1667 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1669 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1672 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1673 for (unsigned int i = 0; i < nb_cores; i++) {
1674 lcore_id = lcores[i];
1675 uint64_t tot_rx = stats_core_task_tot_rx(lcore_id, task_id);
1676 uint64_t tot_tx = stats_core_task_tot_tx(lcore_id, task_id);
1677 uint64_t tot_drop = stats_core_task_tot_drop(lcore_id, task_id);
1678 uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id);
1682 snprintf(buf, sizeof(buf),
1683 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64"\n",
1684 tot_rx, tot_tx, tot_drop, last_tsc, rte_get_tsc_hz());
1685 input->reply(input, buf, strlen(buf));
1688 plog_info("RX: %"PRIu64", TX: %"PRIu64", DROP: %"PRIu64"\n",
1689 tot_rx, tot_tx, tot_drop);
1696 typedef void (*parser_handler)(unsigned, unsigned, struct input *);
1697 static int handle_cores_tasks(const char *str, struct input *input, const char *mode_str, const char *mode_name, parser_handler f)
1699 // This function either outputs a single line, in case of syntax error on the lists of cores and/or tasks
1700 // or outputs (nb_cores * nb_tasks) lines, one line for each core/task pair:
1701 // - if the core/task pair is invalid, the output line reports an error
1702 // - otherwise, the output line provides the latency statistics for the core/task pair
1704 unsigned lcores[RTE_MAX_LCORE], tasks[MAX_TASKS_PER_CORE], lcore_id, task_id, nb_cores, nb_tasks;
1705 if (parse_cores_tasks(str, lcores, tasks, &nb_cores, &nb_tasks)) {
1708 snprintf(buf, sizeof(buf), "error: invalid syntax\n");
1709 input->reply(input, buf, strlen(buf));
1714 for (unsigned int i = 0; i < nb_cores; i++) {
1715 for (unsigned int j = 0; j < nb_tasks; j++) {
1716 lcore_id = lcores[i];
1718 if (core_task_is_valid(lcore_id, task_id) == 0) {
1721 snprintf(buf, sizeof(buf), "error: invalid core %u, task %u\n", lcore_id, task_id);
1722 input->reply(input, buf, strlen(buf));
1724 plog_info("error: invalid core %u, task %u\n", lcore_id, task_id);
1728 if ((mode_str) && (!task_is_mode(lcore_id, task_id, mode_str))) {
1731 snprintf(buf, sizeof(buf), "error: core %u task %u is not measuring %s\n", lcore_id, task_id, mode_name);
1732 input->reply(input, buf, strlen(buf));
1734 plog_info("error: core %u task %u is not measuring %s\n", lcore_id, task_id, mode_name);
1738 f(lcore_id, task_id, input);
1744 static void handle_dp_core_stats(unsigned lcore_id, unsigned task_id, struct input *input)
1746 uint64_t tot_rx = stats_core_task_tot_rx(lcore_id, task_id);
1747 uint64_t tot_tx = stats_core_task_tot_tx(lcore_id, task_id);
1748 uint64_t tot_tx_fail = stats_core_task_tot_tx_fail(lcore_id, task_id);
1749 uint64_t tot_rx_non_dp = stats_core_task_tot_rx_non_dp(lcore_id, task_id);
1750 uint64_t tot_tx_non_dp = stats_core_task_tot_tx_non_dp(lcore_id, task_id);
1751 uint64_t tot_drop = stats_core_task_tot_drop(lcore_id, task_id);
1752 uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id);
1756 snprintf(buf, sizeof(buf),
1757 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%u,%u\n",
1758 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);
1759 input->reply(input, buf, strlen(buf));
1762 plog_info("core: %u, task: %u, RX: %"PRIu64", TX: %"PRIu64", RX_NON_DP: %"PRIu64", TX_NON_DP: %"PRIu64", DROP: %"PRIu64", TX_FAIL: %"PRIu64"\n",
1763 lcore_id, task_id, tot_rx, tot_tx, tot_rx_non_dp, tot_tx_non_dp, tot_drop, tot_tx_fail);
1767 static void handle_lat_stats(unsigned lcore_id, unsigned task_id, struct input *input)
1769 struct stats_latency *stats = stats_latency_find(lcore_id, task_id);
1770 struct stats_latency *tot = stats_latency_tot_find(lcore_id, task_id);
1771 if (!stats || !tot) {
1774 snprintf(buf, sizeof(buf),
1775 "error: core %u task %u stats = %p tot = %p\n",
1776 lcore_id, task_id, stats, tot);
1777 input->reply(input, buf, strlen(buf));
1779 plog_info("error: core %u task %u stats = %p tot = %p\n",
1780 lcore_id, task_id, stats, tot);
1785 uint64_t last_tsc = stats_core_task_last_tsc(lcore_id, task_id);
1786 uint64_t lat_min_usec = time_unit_to_usec(&stats->min.time);
1787 uint64_t lat_max_usec = time_unit_to_usec(&stats->max.time);
1788 uint64_t tot_lat_min_usec = time_unit_to_usec(&tot->min.time);
1789 uint64_t tot_lat_max_usec = time_unit_to_usec(&tot->max.time);
1790 uint64_t lat_avg_usec = time_unit_to_usec(&stats->avg.time);
1794 snprintf(buf, sizeof(buf),
1795 "%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%"PRIu64",%u,%u\n",
1805 input->reply(input, buf, strlen(buf));
1808 plog_info("core: %u, task: %u, min: %"PRIu64", max: %"PRIu64", avg: %"PRIu64", min since reset: %"PRIu64", max since reset: %"PRIu64"\n",
1819 #ifdef LATENCY_HISTOGRAM
1820 static void handle_latency_histogram(unsigned lcore_id, unsigned task_id, struct input *input)
1824 stats_core_lat_histogram(lcore_id, task_id, &buckets);
1826 if (buckets == NULL) {
1829 snprintf(buf, sizeof(buf), "error: unexpected NULL bucket\n");
1830 input->reply(input, buf, strlen(buf));
1836 char buf[4096] = {0};
1837 for (size_t i = 0; i < LAT_BUCKET_COUNT; i++)
1838 sprintf(buf+strlen(buf), "Bucket [%zu]: %"PRIu64"\n", i, buckets[i]);
1839 input->reply(input, buf, strlen(buf));
1842 for (size_t i = 0; i < LAT_BUCKET_COUNT; i++)
1844 plog_info("Bucket [%zu]: %"PRIu64"\n", i, buckets[i]);
1848 static void handle_stats_and_packets(unsigned lcore_id, unsigned task_id, struct input *input)
1850 handle_lat_stats(lcore_id, task_id, input);
1851 handle_latency_histogram(lcore_id, task_id, input);
1855 static int parse_cmd_dp_core_stats(const char *str, struct input *input)
1857 handle_cores_tasks(str, input, NULL, NULL, handle_dp_core_stats);
1861 static int parse_cmd_lat_stats(const char *str, struct input *input)
1863 handle_cores_tasks(str, input, "lat", "latency", handle_lat_stats);
1867 static int parse_cmd_lat_packets(const char *str, struct input *input)
1869 #ifdef LATENCY_HISTOGRAM
1870 handle_cores_tasks(str, input, "lat", "latency", handle_latency_histogram);
1874 snprintf(buf, sizeof(buf), "error: invalid syntax (LATENCY_HISTOGRAM disabled)\n");
1875 input->reply(input, buf, strlen(buf));
1877 plog_info("LATENCY_HISTOGRAMS disabled\n");
1883 static int parse_cmd_lat_stats_and_packets(const char *str, struct input *input)
1885 #ifdef LATENCY_HISTOGRAM
1886 handle_cores_tasks(str, input, "lat", "latency", handle_stats_and_packets);
1890 snprintf(buf, sizeof(buf), "error: invalid syntax (LATENCY_HISTOGRAMS disabled)\n");
1891 input->reply(input, buf, strlen(buf));
1893 plog_info("LATENCY_HISTOGRAMS disabled\n");
1899 static int parse_cmd_show_irq_buckets(const char *str, struct input *input)
1901 char buf[4096] = {0};
1903 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1905 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1908 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1909 for (c = 0; c < nb_cores; c++) {
1910 lcore_id = lcores[c];
1911 get_irq_buckets_by_core_task(buf, lcore_id, task_id);
1912 plog_info("%s", buf);
1914 input->reply(input, buf, strlen(buf));
1921 static int parse_cmd_irq(const char *str, struct input *input)
1924 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1926 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1929 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1930 for (c = 0; c < nb_cores; c++) {
1931 lcore_id = lcores[c];
1932 if (!task_is_mode(lcore_id, task_id, "irq")) {
1933 plog_err("Core %u task %u is not in irq mode\n", lcore_id, task_id);
1935 struct task_irq *task_irq = (struct task_irq *)(lcore_cfg[lcore_id].tasks_all[task_id]);
1937 task_irq_show_stats(task_irq, input);
1944 static int parse_cmd_cgnat_public_hash(const char *str, struct input *input)
1946 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1948 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1951 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1952 for (unsigned int i = 0; i < nb_cores; i++) {
1953 lcore_id = lcores[i];
1955 if (!task_is_mode(lcore_id, task_id, "cgnat")) {
1956 plog_err("Core %u task %u is not cgnat\n", lcore_id, task_id);
1959 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
1960 task_cgnat_dump_public_hash((struct task_nat *)tbase);
1967 static int parse_cmd_cgnat_private_hash(const char *str, struct input *input)
1969 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1972 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1975 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
1976 for (unsigned int i = 0; i < nb_cores; i++) {
1977 lcore_id = lcores[i];
1979 if (!task_is_mode(lcore_id, task_id, "cgnat")) {
1980 plog_err("Core %u task %u is not cgnat\n", lcore_id, task_id);
1983 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
1984 task_cgnat_dump_private_hash((struct task_nat *)tbase);
1991 static int parse_cmd_accuracy(const char *str, struct input *input)
1993 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
1996 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
1998 if (!(str = strchr_skip_twice(str, ' ')))
2000 if (sscanf(str, "%"PRIu32"", &val) != 1)
2003 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
2004 for (unsigned int i = 0; i < nb_cores; i++) {
2005 lcore_id = lcores[i];
2007 if (!task_is_mode(lcore_id, task_id, "lat")) {
2008 plog_err("Core %u task %u is not measuring latency\n", lcore_id, task_id);
2011 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
2013 task_lat_set_accuracy_limit((struct task_lat *)tbase, val);
2020 static int parse_cmd_leave_igmp(const char *str, struct input *input)
2022 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
2024 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
2027 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
2028 for (unsigned int i = 0; i < nb_cores; i++) {
2029 lcore_id = lcores[i];
2031 if (!task_is_mode(lcore_id, task_id, "swap")) {
2032 plog_err("Core %u task %u is not running swap\n", lcore_id, task_id);
2035 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
2036 igmp_leave_group(tbase);
2043 static int parse_cmd_join_igmp(const char *str, struct input *input)
2045 unsigned lcores[RTE_MAX_LCORE], lcore_id, task_id, nb_cores;
2047 uint8_t *igmp_bytes = (uint8_t *)&igmp_ip;
2049 if (parse_cores_task(str, lcores, &task_id, &nb_cores))
2051 if (!(str = strchr_skip_twice(str, ' ')))
2053 if (sscanf(str, "%hhu.%hhu.%hhu.%hhu", igmp_bytes, igmp_bytes + 1, igmp_bytes + 2, igmp_bytes + 3) != 4) {
2056 if (cores_task_are_valid(lcores, task_id, nb_cores)) {
2057 for (unsigned int i = 0; i < nb_cores; i++) {
2058 lcore_id = lcores[i];
2060 if (!task_is_mode(lcore_id, task_id, "swap")) {
2061 plog_err("Core %u task %u is not running swap\n", lcore_id, task_id);
2064 struct task_base *tbase = lcore_cfg[lcore_id].tasks_all[task_id];
2065 igmp_join_group(tbase, igmp_ip);
2072 static int parse_cmd_rx_tx_info(const char *str, struct input *input)
2074 if (strcmp(str, "") != 0) {
2082 static int parse_cmd_version(const char *str, struct input *input)
2084 if (strcmp(str, "") != 0) {
2090 ((uint64_t)VERSION_MAJOR) << 24 |
2091 ((uint64_t)VERSION_MINOR) << 16 |
2092 ((uint64_t)VERSION_REV) << 8;
2095 snprintf(buf, sizeof(buf), "%"PRIu64",%"PRIu64"\n", version, (uint64_t)RTE_VERSION);
2096 input->reply(input, buf, strlen(buf));
2099 plog_info("prox version: %d.%d, DPDK version: %s\n",
2100 VERSION_MAJOR, VERSION_MINOR,
2101 rte_version() + sizeof(RTE_VER_PREFIX));
2110 int (*parse)(const char *args, struct input *input);
2113 static int parse_cmd_help(const char *str, struct input *input);
2115 static struct cmd_str cmd_strings[] = {
2116 {"history", "", "Print command history", parse_cmd_history},
2117 {"echo", "", "echo parameter, useful to resolving variables", parse_cmd_echo},
2118 {"quit", "", "Stop all cores and quit", parse_cmd_quit},
2119 {"quit_force", "", "Quit without waiting on cores to stop", parse_cmd_quit_force},
2120 {"help", "<substr>", "Show list of commands that have <substr> as a substring. If no substring is provided, all commands are shown.", parse_cmd_help},
2121 {"verbose", "<level>", "Set verbosity level", parse_cmd_verbose},
2122 {"thread info", "<core_id> <task_id>", "", parse_cmd_thread_info},
2123 {"mem info", "", "Show information about system memory (number of huge pages and addresses of these huge pages)", parse_cmd_mem_info},
2124 {"update interval", "<value>", "Update statistics refresh rate, in msec (must be >=10). Default is 1 second", parse_cmd_update_interval},
2125 {"rx tx info", "", "Print connections between tasks on all cores", parse_cmd_rx_tx_info},
2126 {"start", "<core list>|all <task_id>", "Start core <core_id> or all cores", parse_cmd_start},
2127 {"stop", "<core list>|all <task_id>", "Stop core <core id> or all cores", parse_cmd_stop},
2129 {"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},
2130 {"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},
2131 {"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},
2132 {"rx distr start", "", "Start gathering statistical distribution of received packets", parse_cmd_rx_distr_start},
2133 {"rx distr stop", "", "Stop gathering statistical distribution of received packets", parse_cmd_rx_distr_stop},
2134 {"rx distr reset", "", "Reset gathered statistical distribution of received packets", parse_cmd_rx_distr_reset},
2135 {"rx distr show", "", "Display gathered statistical distribution of received packets", parse_cmd_rx_distr_show},
2136 {"tx distr start", "", "Start gathering statistical distribution of xmitted packets", parse_cmd_tx_distr_start},
2137 {"tx distr stop", "", "Stop gathering statistical distribution of xmitted packets", parse_cmd_tx_distr_stop},
2138 {"tx distr reset", "", "Reset gathered statistical distribution of xmitted packets", parse_cmd_tx_distr_reset},
2139 {"tx distr show", "", "Display gathered statistical distribution of xmitted packets", parse_cmd_tx_distr_show},
2141 {"rate", "<port id> <queue id> <rate>", "rate does not include preamble, SFD and IFG", parse_cmd_rate},
2142 {"count","<core id> <task id> <count>", "Generate <count> packets", parse_cmd_count},
2143 {"bypass", "<core_id> <task_id>", "Bypass task", parse_cmd_bypass},
2144 {"reconnect", "<core_id> <task_id>", "Reconnect task", parse_cmd_reconnect},
2145 {"pkt_size", "<core_id> <task_id> <pkt_size>", "Set the packet size to <pkt_size>", parse_cmd_pkt_size},
2146 {"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},
2147 {"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},
2148 {"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},
2149 {"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},
2150 {"reset values all", "", "Undo all \"set value\" commands on all cores/tasks", parse_cmd_reset_values_all},
2151 {"reset randoms all", "", "Undo all \"set random\" commands on all cores/tasks", parse_cmd_reset_randoms_all},
2152 {"reset values", "<core id> <task id>", "Undo all \"set value\" commands on specified core/task", parse_cmd_reset_values},
2154 {"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},
2155 {"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},
2156 {"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},
2157 {"gateway ip", "<core id> <task id> <ip>", "Define/Change IP address of destination gateway on core <core id> <task id>.", parse_cmd_gateway_ip},
2158 {"local ip", "<core id> <task id> <ip>", "Define/Change IP address of destination gateway on core <core id> <task id>.", parse_cmd_local_ip},
2160 {"pps unit", "", "Change core stats pps unit", parse_cmd_pps_unit},
2161 {"reset stats", "", "Reset all statistics", parse_cmd_reset_stats},
2162 {"reset lat stats", "", "Reset all latency statistics", parse_cmd_reset_lat_stats},
2163 {"tot stats", "", "Print total RX and TX packets", parse_cmd_tot_stats},
2164 {"tot ierrors tot", "", "Print total number of ierrors since reset", parse_cmd_tot_ierrors_tot},
2165 {"tot imissed tot", "", "Print total number of imissed since reset", parse_cmd_tot_imissed_tot},
2166 {"lat stats", "<core id> <task id>", "Print min,max,avg latency as measured during last sampling interval", parse_cmd_lat_stats},
2167 {"irq stats", "<core id> <task id>", "Print irq related infos", parse_cmd_irq},
2168 {"show irq buckets", "<core id> <task id>", "Print irq buckets", parse_cmd_show_irq_buckets},
2169 {"lat packets", "<core id> <task id>", "Print the latency for each of the last set of packets", parse_cmd_lat_packets},
2170 {"lat all stats", "<core id> <task id>", "Print the latency for each of the last set of packets as well as latency distribution", parse_cmd_lat_stats_and_packets},
2171 {"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},
2172 {"core stats", "<core id> <task id>", "Print rx/tx/drop for task <task id> running on core <core id>", parse_cmd_core_stats},
2173 {"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},
2174 {"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},
2175 {"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},
2176 {"read reg", "", "Read register", parse_cmd_read_reg},
2177 {"write reg", "", "Read register", parse_cmd_write_reg},
2178 {"set vlan offload", "", "Set Vlan offload", parse_cmd_set_vlan_offload},
2179 {"set vlan filter", "", "Set Vlan filter", parse_cmd_set_vlan_filter},
2180 {"reset cache", "", "Reset cache", parse_cmd_cache_reset},
2181 {"set cache class mask", "<core id> <class> <mask>", "Set cache class mask for <core id>", parse_cmd_set_cache_class_mask},
2182 {"get cache class mask", "<core id> <class>", "Get cache class mask", parse_cmd_get_cache_class_mask},
2183 {"set cache class", "<core id> <class>", "Set cache class", parse_cmd_set_cache_class},
2184 {"get cache class", "<core id>", "Get cache class", parse_cmd_get_cache_class},
2185 {"get cache mask", "<core id>", "Get cache mask", parse_cmd_get_cache_mask},
2186 {"reset port", "<port id>", "Reset port", parse_cmd_reset_port},
2187 {"enable multicast", "<port id> <MAC>", "Enable multicast", parse_cmd_enable_multicast},
2188 {"disable multicast", "<port id> <MAC>", "Disable multicast", parse_cmd_disable_multicast},
2189 {"ring info all", "", "Get information about ring, such as ring size and number of elements in the ring", parse_cmd_ring_info_all},
2190 {"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},
2191 {"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},
2192 {"port up", "<port id>", "Set the port up", parse_cmd_port_up},
2193 {"port down", "<port id>", "Set the port down", parse_cmd_port_down},
2194 {"port link state", "<port id>", "Get link state (up or down) for port", parse_cmd_port_link_state},
2195 {"port xstats", "<port id>", "Get extra statistics for the port", parse_cmd_xstats},
2196 {"stats", "<stats_path>", "Get stats as specified by <stats_path>. A comma-separated list of <stats_path> can be supplied", parse_cmd_stats},
2197 {"cgnat dump public hash", "<core id> <task id>", "Dump cgnat public hash table", parse_cmd_cgnat_public_hash},
2198 {"cgnat dump private hash", "<core id> <task id>", "Dump cgnat private hash table", parse_cmd_cgnat_private_hash},
2199 {"delay_us", "<core_id> <task_id> <delay_us>", "Set the delay in usec for the impair mode to <delay_us>", parse_cmd_delay_us},
2200 {"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},
2201 {"probability", "<core_id> <task_id> <probability>", "Set the percent of forwarded packets for the impair mode", parse_cmd_set_probability},
2202 {"version", "", "Show version", parse_cmd_version},
2203 {"join igmp", "<core_id> <task_id> <ip>", "Send igmp membership report for group <ip>", parse_cmd_join_igmp},
2204 {"leave igmp", "<core_id> <task_id>", "Send igmp leave group", parse_cmd_leave_igmp},
2208 static int parse_cmd_help(const char *str, struct input *input)
2210 /* str contains the arguments, all commands that have str as a
2211 substring will be shown. */
2212 size_t len, len2, longest_cmd = 0;
2213 for (size_t i = 0; i < cmd_parser_n_cmd(); ++i) {
2214 if (longest_cmd <strlen(cmd_strings[i].cmd))
2215 longest_cmd = strlen(cmd_strings[i].cmd);
2217 /* A single call to log will be executed after the help string
2218 has been built. The reason for this is to make use of the
2220 char buf[32768] = {0};
2222 for (size_t i = 0; i < cmd_parser_n_cmd(); ++i) {
2224 const size_t cmd_len = strlen(cmd_strings[i].cmd);
2225 for (size_t j = 0; j < cmd_len; ++j) {
2227 for (size_t k = 0; k < strlen(str); ++k) {
2228 if (str[k] != (cmd_strings[i].cmd + j)[k]) {
2239 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s", cmd_strings[i].cmd);
2240 len = strlen(cmd_strings[i].cmd);
2241 while (len < longest_cmd) {
2243 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " ");
2246 if (strlen(cmd_strings[i].args)) {
2247 char tmp[256] = {0};
2248 prox_strncpy(tmp, cmd_strings[i].args, 128);
2249 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "Arguments: %s\n", tmp);
2251 if (strlen(cmd_strings[i].help)) {
2254 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " ");
2259 if (strlen(cmd_strings[i].help)) {
2261 const char *h = cmd_strings[i].help;
2267 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " ");
2270 char tmp[128] = {0};
2271 const size_t max_len = strlen(h) > 80? 80 : strlen(h);
2272 size_t len3 = max_len;
2274 while (len3 && h[len3] != ' ')
2280 // Use strncpy here and not prox_strncpy. The dest (tmp) has been initialized with 0.
2281 // The fact that we are copying 80 characters potentially not null terminated is hence not an issue.
2282 // Using prox_strncpy here might cause a PROX_PANIC
2283 strncpy(tmp, h, len3);
2285 while (h[0] == ' ' && strlen(h))
2288 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "%s\n", tmp);
2292 if (strlen(cmd_strings[i].help) == 0&& strlen(cmd_strings[i].args) == 0) {
2293 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), "\n");
2296 plog_info("%s", buf);
2301 const char *cmd_parser_cmd(size_t i)
2303 i = i < cmd_parser_n_cmd()? i: cmd_parser_n_cmd();
2304 return cmd_strings[i].cmd;
2307 size_t cmd_parser_n_cmd(void)
2309 return sizeof(cmd_strings)/sizeof(cmd_strings[0]) - 1;
2312 void cmd_parser_parse(const char *str, struct input *input)
2316 for (size_t i = 0; i < cmd_parser_n_cmd(); ++i) {
2317 skip = strlen(cmd_strings[i].cmd);
2318 if (strncmp(cmd_strings[i].cmd, str, skip) == 0 &&
2319 (str[skip] == ' ' || str[skip] == 0)) {
2320 while (str[skip] == ' ')
2323 if (cmd_strings[i].parse(str + skip, input) != 0) {
2324 plog_warn("Invalid syntax for command '%s': %s %s\n",
2325 cmd_strings[i].cmd, cmd_strings[i].args, cmd_strings[i].help);
2331 plog_err("Unknown command: '%s'\n", str);