1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include <rte_common.h>
21 #ifndef CMD_MAX_TOKENS
22 #define CMD_MAX_TOKENS 256
25 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
26 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
27 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
28 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
29 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
30 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
31 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
32 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
33 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
34 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
39 if ((strlen(in) && index("!#%;", in[0])) ||
40 (strncmp(in, "//", 2) == 0) ||
41 (strncmp(in, "--", 2) == 0))
48 * mempool <mempool_name>
49 * buffer <buffer_size>
55 cmd_mempool(char **tokens,
60 struct mempool_params p;
62 struct mempool *mempool;
65 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
71 if (strcmp(tokens[2], "buffer") != 0) {
72 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
76 if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
77 snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
81 if (strcmp(tokens[4], "pool") != 0) {
82 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
86 if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
87 snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
91 if (strcmp(tokens[6], "cache") != 0) {
92 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
96 if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
97 snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
101 if (strcmp(tokens[8], "cpu") != 0) {
102 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
106 if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
107 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
111 mempool = mempool_create(name, &p);
112 if (mempool == NULL) {
113 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
120 * dev <device_name> | port <port_id>
121 * rxq <n_queues> <queue_size> <mempool_name>
122 * txq <n_queues> <queue_size>
123 * promiscuous on | off
124 * [rss <qid_0> ... <qid_n>]
127 cmd_link(char **tokens,
132 struct link_params p;
133 struct link_params_rss rss;
137 if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
138 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
143 if (strcmp(tokens[2], "dev") == 0)
144 p.dev_name = tokens[3];
145 else if (strcmp(tokens[2], "port") == 0) {
148 if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
149 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
153 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
157 if (strcmp(tokens[4], "rxq") != 0) {
158 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
162 if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
163 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
166 if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
167 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
171 p.rx.mempool_name = tokens[7];
173 if (strcmp(tokens[8], "txq") != 0) {
174 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
178 if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
179 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
183 if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
184 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
188 if (strcmp(tokens[11], "promiscuous") != 0) {
189 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
193 if (strcmp(tokens[12], "on") == 0)
195 else if (strcmp(tokens[12], "off") == 0)
198 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
205 uint32_t queue_id, i;
207 if (strcmp(tokens[13], "rss") != 0) {
208 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
215 for (i = 14; i < n_tokens; i++) {
216 if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
217 snprintf(out, out_size, MSG_ARG_INVALID,
222 rss.queue_id[rss.n_queues] = queue_id;
227 link = link_create(name, &p);
229 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
240 cmd_swq(char **tokens,
250 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
256 if (strcmp(tokens[2], "size") != 0) {
257 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
261 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
262 snprintf(out, out_size, MSG_ARG_INVALID, "size");
266 if (strcmp(tokens[4], "cpu") != 0) {
267 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
271 if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
272 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
276 swq = swq_create(name, &p);
278 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
284 * tmgr subport profile
285 * <tb_rate> <tb_size>
286 * <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>
290 cmd_tmgr_subport_profile(char **tokens,
295 struct rte_sched_subport_params p;
298 if (n_tokens != 10) {
299 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
303 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
304 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
308 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
309 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
313 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
314 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
315 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
319 if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) {
320 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
324 status = tmgr_subport_profile_add(&p);
326 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
333 * <tb_rate> <tb_size>
334 * <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>
340 cmd_tmgr_pipe_profile(char **tokens,
345 struct rte_sched_pipe_params p;
348 if (n_tokens != 27) {
349 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
353 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
354 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
358 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
359 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
363 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
364 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
365 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
369 if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) {
370 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
374 #ifdef RTE_SCHED_SUBPORT_TC_OV
375 if (parser_read_uint8(&p.tc_ov_weight, tokens[10]) != 0) {
376 snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
381 for (i = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++)
382 if (parser_read_uint8(&p.wrr_weights[i], tokens[11 + i]) != 0) {
383 snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
387 status = tmgr_pipe_profile_add(&p);
389 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
397 * spp <n_subports_per_port>
398 * pps <n_pipes_per_subport>
399 * qsize <qsize_tc0> <qsize_tc1> <qsize_tc2> <qsize_tc3>
400 * fo <frame_overhead>
405 cmd_tmgr(char **tokens,
410 struct tmgr_port_params p;
412 struct tmgr_port *tmgr_port;
415 if (n_tokens != 19) {
416 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
422 if (strcmp(tokens[2], "rate") != 0) {
423 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
427 if (parser_read_uint32(&p.rate, tokens[3]) != 0) {
428 snprintf(out, out_size, MSG_ARG_INVALID, "rate");
432 if (strcmp(tokens[4], "spp") != 0) {
433 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
437 if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
438 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
442 if (strcmp(tokens[6], "pps") != 0) {
443 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
447 if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
448 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
452 if (strcmp(tokens[8], "qsize") != 0) {
453 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "qsize");
457 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
458 if (parser_read_uint16(&p.qsize[i], tokens[9 + i]) != 0) {
459 snprintf(out, out_size, MSG_ARG_INVALID, "qsize");
463 if (strcmp(tokens[13], "fo") != 0) {
464 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
468 if (parser_read_uint32(&p.frame_overhead, tokens[14]) != 0) {
469 snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
473 if (strcmp(tokens[15], "mtu") != 0) {
474 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
478 if (parser_read_uint32(&p.mtu, tokens[16]) != 0) {
479 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
483 if (strcmp(tokens[17], "cpu") != 0) {
484 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
488 if (parser_read_uint32(&p.cpu_id, tokens[18]) != 0) {
489 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
493 tmgr_port = tmgr_port_create(name, &p);
494 if (tmgr_port == NULL) {
495 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
501 * tmgr <tmgr_name> subport <subport_id>
502 * profile <subport_profile_id>
505 cmd_tmgr_subport(char **tokens,
510 uint32_t subport_id, subport_profile_id;
515 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
521 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
522 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
526 if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
527 snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
531 status = tmgr_subport_config(name, subport_id, subport_profile_id);
533 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
539 * tmgr <tmgr_name> subport <subport_id> pipe
540 * from <pipe_id_first> to <pipe_id_last>
541 * profile <pipe_profile_id>
544 cmd_tmgr_subport_pipe(char **tokens,
549 uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
553 if (n_tokens != 11) {
554 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
560 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
561 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
565 if (strcmp(tokens[4], "pipe") != 0) {
566 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
570 if (strcmp(tokens[5], "from") != 0) {
571 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
575 if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
576 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
580 if (strcmp(tokens[7], "to") != 0) {
581 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
585 if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
586 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
590 if (strcmp(tokens[9], "profile") != 0) {
591 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
595 if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
596 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
600 status = tmgr_pipe_config(name, subport_id, pipe_id_first,
601 pipe_id_last, pipe_profile_id);
603 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
612 cmd_tap(char **tokens,
621 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
627 tap = tap_create(name);
629 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
637 * mempool <mempool_name>
638 * [thread <thread_id>]
641 cmd_kni(char **tokens,
650 if ((n_tokens != 6) && (n_tokens != 8)) {
651 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
657 if (strcmp(tokens[2], "link") != 0) {
658 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
662 p.link_name = tokens[3];
664 if (strcmp(tokens[4], "mempool") != 0) {
665 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
669 p.mempool_name = tokens[5];
672 if (strcmp(tokens[6], "thread") != 0) {
673 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
677 if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
678 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
686 kni = kni_create(name, &p);
688 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
694 * port in action profile <profile_name>
695 * [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]
696 * [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]
699 cmd_port_in_action_profile(char **tokens,
704 struct port_in_action_profile_params p;
705 struct port_in_action_profile *ap;
709 memset(&p, 0, sizeof(p));
712 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
716 if (strcmp(tokens[1], "in") != 0) {
717 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
721 if (strcmp(tokens[2], "action") != 0) {
722 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
726 if (strcmp(tokens[3], "profile") != 0) {
727 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
735 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
738 if (n_tokens < t0 + 10) {
739 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
743 if (strcmp(tokens[t0 + 1], "match") == 0)
744 p.fltr.filter_on_match = 1;
745 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
746 p.fltr.filter_on_match = 0;
748 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
752 if (strcmp(tokens[t0 + 2], "offset") != 0) {
753 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
757 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
758 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
762 if (strcmp(tokens[t0 + 4], "mask") != 0) {
763 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
767 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
768 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
769 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
770 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
774 if (strcmp(tokens[t0 + 6], "key") != 0) {
775 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
779 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
780 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
781 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
782 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
786 if (strcmp(tokens[t0 + 8], "port") != 0) {
787 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
791 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
792 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
796 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
800 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
803 if (n_tokens < t0 + 22) {
804 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile balance");
808 if (strcmp(tokens[t0 + 1], "offset") != 0) {
809 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
813 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
814 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
818 if (strcmp(tokens[t0 + 3], "mask") != 0) {
819 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
823 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
824 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
825 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
829 if (strcmp(tokens[t0 + 5], "port") != 0) {
830 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
834 for (i = 0; i < 16; i++)
835 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
836 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
840 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
845 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
849 ap = port_in_action_profile_create(name, &p);
851 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
857 * table action profile <profile_name>
861 * [meter srtcm | trtcm
863 * stats none | pkts | bytes | both]
864 * [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]
865 * [encap ether | vlan | qinq | mpls | pppoe]
870 * [stats pkts | bytes | both]
874 cmd_table_action_profile(char **tokens,
879 struct table_action_profile_params p;
880 struct table_action_profile *ap;
884 memset(&p, 0, sizeof(p));
887 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
891 if (strcmp(tokens[1], "action") != 0) {
892 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
896 if (strcmp(tokens[2], "profile") != 0) {
897 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
903 if (strcmp(tokens[4], "ipv4") == 0)
904 p.common.ip_version = 1;
905 else if (strcmp(tokens[4], "ipv6") == 0)
906 p.common.ip_version = 0;
908 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
912 if (strcmp(tokens[5], "offset") != 0) {
913 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
917 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
918 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
922 if (strcmp(tokens[7], "fwd") != 0) {
923 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
927 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
930 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
931 if (n_tokens < t0 + 6) {
932 snprintf(out, out_size, MSG_ARG_MISMATCH,
933 "table action profile meter");
937 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
938 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
939 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
940 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
942 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
947 if (strcmp(tokens[t0 + 2], "tc") != 0) {
948 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
952 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
953 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
957 if (strcmp(tokens[t0 + 4], "stats") != 0) {
958 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
962 if (strcmp(tokens[t0 + 5], "none") == 0) {
963 p.mtr.n_packets_enabled = 0;
964 p.mtr.n_bytes_enabled = 0;
965 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
966 p.mtr.n_packets_enabled = 1;
967 p.mtr.n_bytes_enabled = 0;
968 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
969 p.mtr.n_packets_enabled = 0;
970 p.mtr.n_bytes_enabled = 1;
971 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
972 p.mtr.n_packets_enabled = 1;
973 p.mtr.n_bytes_enabled = 1;
975 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
976 "none or pkts or bytes or both");
980 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
984 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
985 if (n_tokens < t0 + 5) {
986 snprintf(out, out_size, MSG_ARG_MISMATCH,
987 "table action profile tm");
991 if (strcmp(tokens[t0 + 1], "spp") != 0) {
992 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
996 if (parser_read_uint32(&p.tm.n_subports_per_port,
997 tokens[t0 + 2]) != 0) {
998 snprintf(out, out_size, MSG_ARG_INVALID,
999 "n_subports_per_port");
1003 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1004 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1008 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1009 tokens[t0 + 4]) != 0) {
1010 snprintf(out, out_size, MSG_ARG_INVALID,
1011 "n_pipes_per_subport");
1015 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1019 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1020 if (n_tokens < t0 + 2) {
1021 snprintf(out, out_size, MSG_ARG_MISMATCH,
1022 "action profile encap");
1026 if (strcmp(tokens[t0 + 1], "ether") == 0)
1027 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1028 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1029 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1030 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1031 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1032 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1033 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1034 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1035 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1037 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1041 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1045 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1046 if (n_tokens < t0 + 4) {
1047 snprintf(out, out_size, MSG_ARG_MISMATCH,
1048 "table action profile nat");
1052 if (strcmp(tokens[t0 + 1], "src") == 0)
1053 p.nat.source_nat = 1;
1054 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1055 p.nat.source_nat = 0;
1057 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1062 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1063 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1067 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1069 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1072 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1077 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1081 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1082 if (n_tokens < t0 + 4) {
1083 snprintf(out, out_size, MSG_ARG_MISMATCH,
1084 "table action profile ttl");
1088 if (strcmp(tokens[t0 + 1], "drop") == 0)
1090 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1093 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1098 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1099 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1103 if (strcmp(tokens[t0 + 3], "none") == 0)
1104 p.ttl.n_packets_enabled = 0;
1105 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1106 p.ttl.n_packets_enabled = 1;
1108 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1113 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1117 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1118 if (n_tokens < t0 + 2) {
1119 snprintf(out, out_size, MSG_ARG_MISMATCH,
1120 "table action profile stats");
1124 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1125 p.stats.n_packets_enabled = 1;
1126 p.stats.n_bytes_enabled = 0;
1127 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1128 p.stats.n_packets_enabled = 0;
1129 p.stats.n_bytes_enabled = 1;
1130 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1131 p.stats.n_packets_enabled = 1;
1132 p.stats.n_bytes_enabled = 1;
1134 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1135 "pkts or bytes or both");
1139 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1143 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1144 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1148 if (t0 < n_tokens) {
1149 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1153 ap = table_action_profile_create(name, &p);
1155 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1161 cli_process(char *in, char *out, size_t out_size)
1163 char *tokens[CMD_MAX_TOKENS];
1164 uint32_t n_tokens = RTE_DIM(tokens);
1170 status = parse_tokenize_string(in, tokens, &n_tokens);
1172 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
1179 if (strcmp(tokens[0], "mempool") == 0) {
1180 cmd_mempool(tokens, n_tokens, out, out_size);
1184 if (strcmp(tokens[0], "link") == 0) {
1185 cmd_link(tokens, n_tokens, out, out_size);
1189 if (strcmp(tokens[0], "swq") == 0) {
1190 cmd_swq(tokens, n_tokens, out, out_size);
1194 if (strcmp(tokens[0], "tmgr") == 0) {
1195 if ((n_tokens >= 3) &&
1196 (strcmp(tokens[1], "subport") == 0) &&
1197 (strcmp(tokens[2], "profile") == 0)) {
1198 cmd_tmgr_subport_profile(tokens, n_tokens,
1203 if ((n_tokens >= 3) &&
1204 (strcmp(tokens[1], "pipe") == 0) &&
1205 (strcmp(tokens[2], "profile") == 0)) {
1206 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
1210 if ((n_tokens >= 5) &&
1211 (strcmp(tokens[2], "subport") == 0) &&
1212 (strcmp(tokens[4], "profile") == 0)) {
1213 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
1217 if ((n_tokens >= 5) &&
1218 (strcmp(tokens[2], "subport") == 0) &&
1219 (strcmp(tokens[4], "pipe") == 0)) {
1220 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
1224 cmd_tmgr(tokens, n_tokens, out, out_size);
1228 if (strcmp(tokens[0], "tap") == 0) {
1229 cmd_tap(tokens, n_tokens, out, out_size);
1233 if (strcmp(tokens[0], "kni") == 0) {
1234 cmd_kni(tokens, n_tokens, out, out_size);
1238 if (strcmp(tokens[0], "port") == 0) {
1239 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
1243 if (strcmp(tokens[0], "table") == 0) {
1244 cmd_table_action_profile(tokens, n_tokens, out, out_size);
1248 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
1252 cli_script_process(const char *file_name,
1253 size_t msg_in_len_max,
1254 size_t msg_out_len_max)
1256 char *msg_in = NULL, *msg_out = NULL;
1259 /* Check input arguments */
1260 if ((file_name == NULL) ||
1261 (strlen(file_name) == 0) ||
1262 (msg_in_len_max == 0) ||
1263 (msg_out_len_max == 0))
1266 msg_in = malloc(msg_in_len_max + 1);
1267 msg_out = malloc(msg_out_len_max + 1);
1268 if ((msg_in == NULL) ||
1269 (msg_out == NULL)) {
1275 /* Open input file */
1276 f = fopen(file_name, "r");
1285 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
1288 printf("%s", msg_in);
1295 if (strlen(msg_out))
1296 printf("%s", msg_out);