1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include <rte_common.h>
23 #ifndef CMD_MAX_TOKENS
24 #define CMD_MAX_TOKENS 256
27 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
28 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
29 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
30 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
31 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
32 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
33 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
34 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
35 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
36 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
41 if ((strlen(in) && index("!#%;", in[0])) ||
42 (strncmp(in, "//", 2) == 0) ||
43 (strncmp(in, "--", 2) == 0))
50 * mempool <mempool_name>
51 * buffer <buffer_size>
57 cmd_mempool(char **tokens,
62 struct mempool_params p;
64 struct mempool *mempool;
67 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
73 if (strcmp(tokens[2], "buffer") != 0) {
74 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
78 if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
79 snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
83 if (strcmp(tokens[4], "pool") != 0) {
84 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
88 if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
89 snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
93 if (strcmp(tokens[6], "cache") != 0) {
94 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
98 if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
99 snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
103 if (strcmp(tokens[8], "cpu") != 0) {
104 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
108 if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
109 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
113 mempool = mempool_create(name, &p);
114 if (mempool == NULL) {
115 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
122 * dev <device_name> | port <port_id>
123 * rxq <n_queues> <queue_size> <mempool_name>
124 * txq <n_queues> <queue_size>
125 * promiscuous on | off
126 * [rss <qid_0> ... <qid_n>]
129 cmd_link(char **tokens,
134 struct link_params p;
135 struct link_params_rss rss;
139 if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
140 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
145 if (strcmp(tokens[2], "dev") == 0)
146 p.dev_name = tokens[3];
147 else if (strcmp(tokens[2], "port") == 0) {
150 if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
151 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
155 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
159 if (strcmp(tokens[4], "rxq") != 0) {
160 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
164 if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
165 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
168 if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
169 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
173 p.rx.mempool_name = tokens[7];
175 if (strcmp(tokens[8], "txq") != 0) {
176 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
180 if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
181 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
185 if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
186 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
190 if (strcmp(tokens[11], "promiscuous") != 0) {
191 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
195 if (strcmp(tokens[12], "on") == 0)
197 else if (strcmp(tokens[12], "off") == 0)
200 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
207 uint32_t queue_id, i;
209 if (strcmp(tokens[13], "rss") != 0) {
210 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
217 for (i = 14; i < n_tokens; i++) {
218 if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
219 snprintf(out, out_size, MSG_ARG_INVALID,
224 rss.queue_id[rss.n_queues] = queue_id;
229 link = link_create(name, &p);
231 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
242 cmd_swq(char **tokens,
252 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
258 if (strcmp(tokens[2], "size") != 0) {
259 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
263 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
264 snprintf(out, out_size, MSG_ARG_INVALID, "size");
268 if (strcmp(tokens[4], "cpu") != 0) {
269 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
273 if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
274 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
278 swq = swq_create(name, &p);
280 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
286 * tmgr subport profile
287 * <tb_rate> <tb_size>
288 * <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>
292 cmd_tmgr_subport_profile(char **tokens,
297 struct rte_sched_subport_params p;
300 if (n_tokens != 10) {
301 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
305 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
306 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
310 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
311 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
315 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
316 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
317 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
321 if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) {
322 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
326 status = tmgr_subport_profile_add(&p);
328 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
335 * <tb_rate> <tb_size>
336 * <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>
342 cmd_tmgr_pipe_profile(char **tokens,
347 struct rte_sched_pipe_params p;
350 if (n_tokens != 27) {
351 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
355 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
356 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
360 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
361 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
365 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
366 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
367 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
371 if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) {
372 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
376 #ifdef RTE_SCHED_SUBPORT_TC_OV
377 if (parser_read_uint8(&p.tc_ov_weight, tokens[10]) != 0) {
378 snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
383 for (i = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++)
384 if (parser_read_uint8(&p.wrr_weights[i], tokens[11 + i]) != 0) {
385 snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
389 status = tmgr_pipe_profile_add(&p);
391 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
399 * spp <n_subports_per_port>
400 * pps <n_pipes_per_subport>
401 * qsize <qsize_tc0> <qsize_tc1> <qsize_tc2> <qsize_tc3>
402 * fo <frame_overhead>
407 cmd_tmgr(char **tokens,
412 struct tmgr_port_params p;
414 struct tmgr_port *tmgr_port;
417 if (n_tokens != 19) {
418 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
424 if (strcmp(tokens[2], "rate") != 0) {
425 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
429 if (parser_read_uint32(&p.rate, tokens[3]) != 0) {
430 snprintf(out, out_size, MSG_ARG_INVALID, "rate");
434 if (strcmp(tokens[4], "spp") != 0) {
435 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
439 if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
440 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
444 if (strcmp(tokens[6], "pps") != 0) {
445 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
449 if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
450 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
454 if (strcmp(tokens[8], "qsize") != 0) {
455 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "qsize");
459 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
460 if (parser_read_uint16(&p.qsize[i], tokens[9 + i]) != 0) {
461 snprintf(out, out_size, MSG_ARG_INVALID, "qsize");
465 if (strcmp(tokens[13], "fo") != 0) {
466 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
470 if (parser_read_uint32(&p.frame_overhead, tokens[14]) != 0) {
471 snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
475 if (strcmp(tokens[15], "mtu") != 0) {
476 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
480 if (parser_read_uint32(&p.mtu, tokens[16]) != 0) {
481 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
485 if (strcmp(tokens[17], "cpu") != 0) {
486 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
490 if (parser_read_uint32(&p.cpu_id, tokens[18]) != 0) {
491 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
495 tmgr_port = tmgr_port_create(name, &p);
496 if (tmgr_port == NULL) {
497 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
503 * tmgr <tmgr_name> subport <subport_id>
504 * profile <subport_profile_id>
507 cmd_tmgr_subport(char **tokens,
512 uint32_t subport_id, subport_profile_id;
517 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
523 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
524 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
528 if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
529 snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
533 status = tmgr_subport_config(name, subport_id, subport_profile_id);
535 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
541 * tmgr <tmgr_name> subport <subport_id> pipe
542 * from <pipe_id_first> to <pipe_id_last>
543 * profile <pipe_profile_id>
546 cmd_tmgr_subport_pipe(char **tokens,
551 uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
555 if (n_tokens != 11) {
556 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
562 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
563 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
567 if (strcmp(tokens[4], "pipe") != 0) {
568 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
572 if (strcmp(tokens[5], "from") != 0) {
573 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
577 if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
578 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
582 if (strcmp(tokens[7], "to") != 0) {
583 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
587 if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
588 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
592 if (strcmp(tokens[9], "profile") != 0) {
593 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
597 if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
598 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
602 status = tmgr_pipe_config(name, subport_id, pipe_id_first,
603 pipe_id_last, pipe_profile_id);
605 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
614 cmd_tap(char **tokens,
623 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
629 tap = tap_create(name);
631 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
639 * mempool <mempool_name>
640 * [thread <thread_id>]
643 cmd_kni(char **tokens,
652 if ((n_tokens != 6) && (n_tokens != 8)) {
653 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
659 if (strcmp(tokens[2], "link") != 0) {
660 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
664 p.link_name = tokens[3];
666 if (strcmp(tokens[4], "mempool") != 0) {
667 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
671 p.mempool_name = tokens[5];
674 if (strcmp(tokens[6], "thread") != 0) {
675 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
679 if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
680 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
688 kni = kni_create(name, &p);
690 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
696 * port in action profile <profile_name>
697 * [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]
698 * [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]
701 cmd_port_in_action_profile(char **tokens,
706 struct port_in_action_profile_params p;
707 struct port_in_action_profile *ap;
711 memset(&p, 0, sizeof(p));
714 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
718 if (strcmp(tokens[1], "in") != 0) {
719 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
723 if (strcmp(tokens[2], "action") != 0) {
724 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
728 if (strcmp(tokens[3], "profile") != 0) {
729 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
737 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
740 if (n_tokens < t0 + 10) {
741 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
745 if (strcmp(tokens[t0 + 1], "match") == 0)
746 p.fltr.filter_on_match = 1;
747 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
748 p.fltr.filter_on_match = 0;
750 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
754 if (strcmp(tokens[t0 + 2], "offset") != 0) {
755 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
759 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
760 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
764 if (strcmp(tokens[t0 + 4], "mask") != 0) {
765 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
769 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
770 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
771 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
772 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
776 if (strcmp(tokens[t0 + 6], "key") != 0) {
777 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
781 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
782 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
783 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
784 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
788 if (strcmp(tokens[t0 + 8], "port") != 0) {
789 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
793 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
794 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
798 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
802 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
805 if (n_tokens < t0 + 22) {
806 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile balance");
810 if (strcmp(tokens[t0 + 1], "offset") != 0) {
811 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
815 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
816 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
820 if (strcmp(tokens[t0 + 3], "mask") != 0) {
821 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
825 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
826 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
827 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
831 if (strcmp(tokens[t0 + 5], "port") != 0) {
832 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
836 for (i = 0; i < 16; i++)
837 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
838 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
842 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
847 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
851 ap = port_in_action_profile_create(name, &p);
853 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
859 * table action profile <profile_name>
863 * [meter srtcm | trtcm
865 * stats none | pkts | bytes | both]
866 * [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]
867 * [encap ether | vlan | qinq | mpls | pppoe]
872 * [stats pkts | bytes | both]
876 cmd_table_action_profile(char **tokens,
881 struct table_action_profile_params p;
882 struct table_action_profile *ap;
886 memset(&p, 0, sizeof(p));
889 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
893 if (strcmp(tokens[1], "action") != 0) {
894 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
898 if (strcmp(tokens[2], "profile") != 0) {
899 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
905 if (strcmp(tokens[4], "ipv4") == 0)
906 p.common.ip_version = 1;
907 else if (strcmp(tokens[4], "ipv6") == 0)
908 p.common.ip_version = 0;
910 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
914 if (strcmp(tokens[5], "offset") != 0) {
915 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
919 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
920 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
924 if (strcmp(tokens[7], "fwd") != 0) {
925 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
929 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
932 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
933 if (n_tokens < t0 + 6) {
934 snprintf(out, out_size, MSG_ARG_MISMATCH,
935 "table action profile meter");
939 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
940 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
941 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
942 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
944 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
949 if (strcmp(tokens[t0 + 2], "tc") != 0) {
950 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
954 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
955 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
959 if (strcmp(tokens[t0 + 4], "stats") != 0) {
960 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
964 if (strcmp(tokens[t0 + 5], "none") == 0) {
965 p.mtr.n_packets_enabled = 0;
966 p.mtr.n_bytes_enabled = 0;
967 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
968 p.mtr.n_packets_enabled = 1;
969 p.mtr.n_bytes_enabled = 0;
970 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
971 p.mtr.n_packets_enabled = 0;
972 p.mtr.n_bytes_enabled = 1;
973 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
974 p.mtr.n_packets_enabled = 1;
975 p.mtr.n_bytes_enabled = 1;
977 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
978 "none or pkts or bytes or both");
982 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
986 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
987 if (n_tokens < t0 + 5) {
988 snprintf(out, out_size, MSG_ARG_MISMATCH,
989 "table action profile tm");
993 if (strcmp(tokens[t0 + 1], "spp") != 0) {
994 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
998 if (parser_read_uint32(&p.tm.n_subports_per_port,
999 tokens[t0 + 2]) != 0) {
1000 snprintf(out, out_size, MSG_ARG_INVALID,
1001 "n_subports_per_port");
1005 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1006 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1010 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1011 tokens[t0 + 4]) != 0) {
1012 snprintf(out, out_size, MSG_ARG_INVALID,
1013 "n_pipes_per_subport");
1017 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1021 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1022 if (n_tokens < t0 + 2) {
1023 snprintf(out, out_size, MSG_ARG_MISMATCH,
1024 "action profile encap");
1028 if (strcmp(tokens[t0 + 1], "ether") == 0)
1029 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1030 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1031 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1032 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1033 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1034 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1035 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1036 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1037 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1039 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1043 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1047 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1048 if (n_tokens < t0 + 4) {
1049 snprintf(out, out_size, MSG_ARG_MISMATCH,
1050 "table action profile nat");
1054 if (strcmp(tokens[t0 + 1], "src") == 0)
1055 p.nat.source_nat = 1;
1056 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1057 p.nat.source_nat = 0;
1059 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1064 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1065 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1069 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1071 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1074 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1079 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1083 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1084 if (n_tokens < t0 + 4) {
1085 snprintf(out, out_size, MSG_ARG_MISMATCH,
1086 "table action profile ttl");
1090 if (strcmp(tokens[t0 + 1], "drop") == 0)
1092 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1095 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1100 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1101 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1105 if (strcmp(tokens[t0 + 3], "none") == 0)
1106 p.ttl.n_packets_enabled = 0;
1107 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1108 p.ttl.n_packets_enabled = 1;
1110 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1115 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1119 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1120 if (n_tokens < t0 + 2) {
1121 snprintf(out, out_size, MSG_ARG_MISMATCH,
1122 "table action profile stats");
1126 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1127 p.stats.n_packets_enabled = 1;
1128 p.stats.n_bytes_enabled = 0;
1129 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1130 p.stats.n_packets_enabled = 0;
1131 p.stats.n_bytes_enabled = 1;
1132 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1133 p.stats.n_packets_enabled = 1;
1134 p.stats.n_bytes_enabled = 1;
1136 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1137 "pkts or bytes or both");
1141 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1145 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1146 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1150 if (t0 < n_tokens) {
1151 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1155 ap = table_action_profile_create(name, &p);
1157 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1163 * pipeline <pipeline_name>
1164 * period <timer_period_ms>
1165 * offset_port_id <offset_port_id>
1169 cmd_pipeline(char **tokens,
1174 struct pipeline_params p;
1176 struct pipeline *pipeline;
1178 if (n_tokens != 8) {
1179 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1185 if (strcmp(tokens[2], "period") != 0) {
1186 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1190 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1191 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1195 if (strcmp(tokens[4], "offset_port_id") != 0) {
1196 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1200 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1201 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1205 if (strcmp(tokens[6], "cpu") != 0) {
1206 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1210 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1211 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1215 pipeline = pipeline_create(name, &p);
1216 if (pipeline == NULL) {
1217 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1223 * pipeline <pipeline_name> port in
1225 * link <link_name> rxq <queue_id>
1227 * | tmgr <tmgr_name>
1228 * | tap <tap_name> mempool <mempool_name> mtu <mtu>
1230 * | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>
1231 * [action <port_in_action_profile_name>]
1235 cmd_pipeline_port_in(char **tokens,
1240 struct port_in_params p;
1241 char *pipeline_name;
1243 int enabled, status;
1246 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1250 pipeline_name = tokens[1];
1252 if (strcmp(tokens[2], "port") != 0) {
1253 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1257 if (strcmp(tokens[3], "in") != 0) {
1258 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1262 if (strcmp(tokens[4], "bsz") != 0) {
1263 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1267 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1268 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1274 if (strcmp(tokens[t0], "link") == 0) {
1275 if (n_tokens < t0 + 4) {
1276 snprintf(out, out_size, MSG_ARG_MISMATCH,
1277 "pipeline port in link");
1281 p.type = PORT_IN_RXQ;
1283 p.dev_name = tokens[t0 + 1];
1285 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1286 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1290 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1291 snprintf(out, out_size, MSG_ARG_INVALID,
1296 } else if (strcmp(tokens[t0], "swq") == 0) {
1297 if (n_tokens < t0 + 2) {
1298 snprintf(out, out_size, MSG_ARG_MISMATCH,
1299 "pipeline port in swq");
1303 p.type = PORT_IN_SWQ;
1305 p.dev_name = tokens[t0 + 1];
1308 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1309 if (n_tokens < t0 + 2) {
1310 snprintf(out, out_size, MSG_ARG_MISMATCH,
1311 "pipeline port in tmgr");
1315 p.type = PORT_IN_TMGR;
1317 p.dev_name = tokens[t0 + 1];
1320 } else if (strcmp(tokens[t0], "tap") == 0) {
1321 if (n_tokens < t0 + 6) {
1322 snprintf(out, out_size, MSG_ARG_MISMATCH,
1323 "pipeline port in tap");
1327 p.type = PORT_IN_TAP;
1329 p.dev_name = tokens[t0 + 1];
1331 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1332 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1337 p.tap.mempool_name = tokens[t0 + 3];
1339 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1340 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1345 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1346 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1351 } else if (strcmp(tokens[t0], "kni") == 0) {
1352 if (n_tokens < t0 + 2) {
1353 snprintf(out, out_size, MSG_ARG_MISMATCH,
1354 "pipeline port in kni");
1358 p.type = PORT_IN_KNI;
1360 p.dev_name = tokens[t0 + 1];
1363 } else if (strcmp(tokens[t0], "source") == 0) {
1364 if (n_tokens < t0 + 6) {
1365 snprintf(out, out_size, MSG_ARG_MISMATCH,
1366 "pipeline port in source");
1370 p.type = PORT_IN_SOURCE;
1374 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1375 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1380 p.source.mempool_name = tokens[t0 + 2];
1382 if (strcmp(tokens[t0 + 3], "file") != 0) {
1383 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1388 p.source.file_name = tokens[t0 + 4];
1390 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1391 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1396 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1397 snprintf(out, out_size, MSG_ARG_INVALID,
1404 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1408 p.action_profile_name = NULL;
1409 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1410 if (n_tokens < t0 + 2) {
1411 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1415 p.action_profile_name = tokens[t0 + 1];
1421 if ((n_tokens > t0) &&
1422 (strcmp(tokens[t0], "disabled") == 0)) {
1428 if (n_tokens != t0) {
1429 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1433 status = pipeline_port_in_create(pipeline_name,
1436 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1442 * pipeline <pipeline_name> port out
1444 * link <link_name> txq <txq_id>
1446 * | tmgr <tmgr_name>
1449 * | sink [file <file_name> pkts <max_n_pkts>]
1452 cmd_pipeline_port_out(char **tokens,
1457 struct port_out_params p;
1458 char *pipeline_name;
1461 memset(&p, 0, sizeof(p));
1464 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1468 pipeline_name = tokens[1];
1470 if (strcmp(tokens[2], "port") != 0) {
1471 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1475 if (strcmp(tokens[3], "out") != 0) {
1476 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1480 if (strcmp(tokens[4], "bsz") != 0) {
1481 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1485 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1486 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1490 if (strcmp(tokens[6], "link") == 0) {
1491 if (n_tokens != 10) {
1492 snprintf(out, out_size, MSG_ARG_MISMATCH,
1493 "pipeline port out link");
1497 p.type = PORT_OUT_TXQ;
1499 p.dev_name = tokens[7];
1501 if (strcmp(tokens[8], "txq") != 0) {
1502 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1506 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1507 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1510 } else if (strcmp(tokens[6], "swq") == 0) {
1511 if (n_tokens != 8) {
1512 snprintf(out, out_size, MSG_ARG_MISMATCH,
1513 "pipeline port out swq");
1517 p.type = PORT_OUT_SWQ;
1519 p.dev_name = tokens[7];
1520 } else if (strcmp(tokens[6], "tmgr") == 0) {
1521 if (n_tokens != 8) {
1522 snprintf(out, out_size, MSG_ARG_MISMATCH,
1523 "pipeline port out tmgr");
1527 p.type = PORT_OUT_TMGR;
1529 p.dev_name = tokens[7];
1530 } else if (strcmp(tokens[6], "tap") == 0) {
1531 if (n_tokens != 8) {
1532 snprintf(out, out_size, MSG_ARG_MISMATCH,
1533 "pipeline port out tap");
1537 p.type = PORT_OUT_TAP;
1539 p.dev_name = tokens[7];
1540 } else if (strcmp(tokens[6], "kni") == 0) {
1541 if (n_tokens != 8) {
1542 snprintf(out, out_size, MSG_ARG_MISMATCH,
1543 "pipeline port out kni");
1547 p.type = PORT_OUT_KNI;
1549 p.dev_name = tokens[7];
1550 } else if (strcmp(tokens[6], "sink") == 0) {
1551 if ((n_tokens != 7) && (n_tokens != 11)) {
1552 snprintf(out, out_size, MSG_ARG_MISMATCH,
1553 "pipeline port out sink");
1557 p.type = PORT_OUT_SINK;
1561 if (n_tokens == 7) {
1562 p.sink.file_name = NULL;
1563 p.sink.max_n_pkts = 0;
1565 if (strcmp(tokens[7], "file") != 0) {
1566 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1571 p.sink.file_name = tokens[8];
1573 if (strcmp(tokens[9], "pkts") != 0) {
1574 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1578 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1579 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1584 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1588 status = pipeline_port_out_create(pipeline_name, &p);
1590 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1596 * pipeline <pipeline_name> table
1600 * offset <ip_header_offset>
1603 * offset <key_offset>
1609 * offset <key_offset>
1610 * buckets <n_buckets>
1614 * offset <ip_header_offset>
1617 * [action <table_action_profile_name>]
1620 cmd_pipeline_table(char **tokens,
1625 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
1626 struct table_params p;
1627 char *pipeline_name;
1632 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1636 pipeline_name = tokens[1];
1638 if (strcmp(tokens[2], "table") != 0) {
1639 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
1643 if (strcmp(tokens[3], "match") != 0) {
1644 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
1649 if (strcmp(tokens[t0], "acl") == 0) {
1650 if (n_tokens < t0 + 6) {
1651 snprintf(out, out_size, MSG_ARG_MISMATCH,
1652 "pipeline table acl");
1656 p.match_type = TABLE_ACL;
1658 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
1659 p.match.acl.ip_version = 1;
1660 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
1661 p.match.acl.ip_version = 0;
1663 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1668 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1669 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1673 if (parser_read_uint32(&p.match.acl.ip_header_offset,
1674 tokens[t0 + 3]) != 0) {
1675 snprintf(out, out_size, MSG_ARG_INVALID,
1676 "ip_header_offset");
1680 if (strcmp(tokens[t0 + 4], "size") != 0) {
1681 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1685 if (parser_read_uint32(&p.match.acl.n_rules,
1686 tokens[t0 + 5]) != 0) {
1687 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
1692 } else if (strcmp(tokens[t0], "array") == 0) {
1693 if (n_tokens < t0 + 5) {
1694 snprintf(out, out_size, MSG_ARG_MISMATCH,
1695 "pipeline table array");
1699 p.match_type = TABLE_ARRAY;
1701 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1702 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1706 if (parser_read_uint32(&p.match.array.key_offset,
1707 tokens[t0 + 2]) != 0) {
1708 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1712 if (strcmp(tokens[t0 + 3], "size") != 0) {
1713 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1717 if (parser_read_uint32(&p.match.array.n_keys,
1718 tokens[t0 + 4]) != 0) {
1719 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
1724 } else if (strcmp(tokens[t0], "hash") == 0) {
1725 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
1727 if (n_tokens < t0 + 12) {
1728 snprintf(out, out_size, MSG_ARG_MISMATCH,
1729 "pipeline table hash");
1733 p.match_type = TABLE_HASH;
1735 if (strcmp(tokens[t0 + 1], "ext") == 0)
1736 p.match.hash.extendable_bucket = 1;
1737 else if (strcmp(tokens[t0 + 1], "lru") == 0)
1738 p.match.hash.extendable_bucket = 0;
1740 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1745 if (strcmp(tokens[t0 + 2], "key") != 0) {
1746 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
1750 if ((parser_read_uint32(&p.match.hash.key_size,
1751 tokens[t0 + 3]) != 0) ||
1752 (p.match.hash.key_size == 0) ||
1753 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
1754 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
1758 if (strcmp(tokens[t0 + 4], "mask") != 0) {
1759 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1763 if ((parse_hex_string(tokens[t0 + 5],
1764 key_mask, &key_mask_size) != 0) ||
1765 (key_mask_size != p.match.hash.key_size)) {
1766 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1769 p.match.hash.key_mask = key_mask;
1771 if (strcmp(tokens[t0 + 6], "offset") != 0) {
1772 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1776 if (parser_read_uint32(&p.match.hash.key_offset,
1777 tokens[t0 + 7]) != 0) {
1778 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1782 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
1783 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
1787 if (parser_read_uint32(&p.match.hash.n_buckets,
1788 tokens[t0 + 9]) != 0) {
1789 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
1793 if (strcmp(tokens[t0 + 10], "size") != 0) {
1794 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1798 if (parser_read_uint32(&p.match.hash.n_keys,
1799 tokens[t0 + 11]) != 0) {
1800 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
1805 } else if (strcmp(tokens[t0], "lpm") == 0) {
1806 if (n_tokens < t0 + 6) {
1807 snprintf(out, out_size, MSG_ARG_MISMATCH,
1808 "pipeline table lpm");
1812 p.match_type = TABLE_LPM;
1814 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
1815 p.match.lpm.key_size = 4;
1816 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
1817 p.match.lpm.key_size = 16;
1819 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1824 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1825 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1829 if (parser_read_uint32(&p.match.lpm.key_offset,
1830 tokens[t0 + 3]) != 0) {
1831 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1835 if (strcmp(tokens[t0 + 4], "size") != 0) {
1836 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1840 if (parser_read_uint32(&p.match.lpm.n_rules,
1841 tokens[t0 + 5]) != 0) {
1842 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
1847 } else if (strcmp(tokens[t0], "stub") == 0) {
1848 if (n_tokens < t0 + 1) {
1849 snprintf(out, out_size, MSG_ARG_MISMATCH,
1850 "pipeline table stub");
1854 p.match_type = TABLE_STUB;
1858 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1862 p.action_profile_name = NULL;
1863 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1864 if (n_tokens < t0 + 2) {
1865 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1869 p.action_profile_name = tokens[t0 + 1];
1874 if (n_tokens > t0) {
1875 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1879 status = pipeline_table_create(pipeline_name, &p);
1881 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1887 * pipeline <pipeline_name> port in <port_id> table <table_id>
1890 cmd_pipeline_port_in_table(char **tokens,
1895 char *pipeline_name;
1896 uint32_t port_id, table_id;
1899 if (n_tokens != 7) {
1900 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1904 pipeline_name = tokens[1];
1906 if (strcmp(tokens[2], "port") != 0) {
1907 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1911 if (strcmp(tokens[3], "in") != 0) {
1912 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1916 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
1917 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1921 if (strcmp(tokens[5], "table") != 0) {
1922 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
1926 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
1927 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
1931 status = pipeline_port_in_connect_to_table(pipeline_name,
1935 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1941 * pipeline <pipeline_name> port in <port_id> enable
1944 cmd_pipeline_port_in_enable(char **tokens,
1949 char *pipeline_name;
1953 if (n_tokens != 6) {
1954 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1958 pipeline_name = tokens[1];
1960 if (strcmp(tokens[2], "port") != 0) {
1961 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1965 if (strcmp(tokens[3], "in") != 0) {
1966 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1970 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
1971 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1975 if (strcmp(tokens[5], "enable") != 0) {
1976 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
1980 status = pipeline_port_in_enable(pipeline_name, port_id);
1982 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1988 * pipeline <pipeline_name> port in <port_id> disable
1991 cmd_pipeline_port_in_disable(char **tokens,
1996 char *pipeline_name;
2000 if (n_tokens != 6) {
2001 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2005 pipeline_name = tokens[1];
2007 if (strcmp(tokens[2], "port") != 0) {
2008 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2012 if (strcmp(tokens[3], "in") != 0) {
2013 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2017 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2018 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2022 if (strcmp(tokens[5], "disable") != 0) {
2023 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2027 status = pipeline_port_in_disable(pipeline_name, port_id);
2029 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2035 * thread <thread_id> pipeline <pipeline_name> enable
2038 cmd_thread_pipeline_enable(char **tokens,
2043 char *pipeline_name;
2047 if (n_tokens != 5) {
2048 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2052 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
2053 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
2057 if (strcmp(tokens[2], "pipeline") != 0) {
2058 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
2062 pipeline_name = tokens[3];
2064 if (strcmp(tokens[4], "enable") != 0) {
2065 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2069 status = thread_pipeline_enable(thread_id, pipeline_name);
2071 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
2077 * thread <thread_id> pipeline <pipeline_name> disable
2080 cmd_thread_pipeline_disable(char **tokens,
2085 char *pipeline_name;
2089 if (n_tokens != 5) {
2090 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2094 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
2095 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
2099 if (strcmp(tokens[2], "pipeline") != 0) {
2100 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
2104 pipeline_name = tokens[3];
2106 if (strcmp(tokens[4], "disable") != 0) {
2107 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2111 status = thread_pipeline_disable(thread_id, pipeline_name);
2113 snprintf(out, out_size, MSG_CMD_FAIL,
2114 "thread pipeline disable");
2120 cli_process(char *in, char *out, size_t out_size)
2122 char *tokens[CMD_MAX_TOKENS];
2123 uint32_t n_tokens = RTE_DIM(tokens);
2129 status = parse_tokenize_string(in, tokens, &n_tokens);
2131 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
2138 if (strcmp(tokens[0], "mempool") == 0) {
2139 cmd_mempool(tokens, n_tokens, out, out_size);
2143 if (strcmp(tokens[0], "link") == 0) {
2144 cmd_link(tokens, n_tokens, out, out_size);
2148 if (strcmp(tokens[0], "swq") == 0) {
2149 cmd_swq(tokens, n_tokens, out, out_size);
2153 if (strcmp(tokens[0], "tmgr") == 0) {
2154 if ((n_tokens >= 3) &&
2155 (strcmp(tokens[1], "subport") == 0) &&
2156 (strcmp(tokens[2], "profile") == 0)) {
2157 cmd_tmgr_subport_profile(tokens, n_tokens,
2162 if ((n_tokens >= 3) &&
2163 (strcmp(tokens[1], "pipe") == 0) &&
2164 (strcmp(tokens[2], "profile") == 0)) {
2165 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
2169 if ((n_tokens >= 5) &&
2170 (strcmp(tokens[2], "subport") == 0) &&
2171 (strcmp(tokens[4], "profile") == 0)) {
2172 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
2176 if ((n_tokens >= 5) &&
2177 (strcmp(tokens[2], "subport") == 0) &&
2178 (strcmp(tokens[4], "pipe") == 0)) {
2179 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
2183 cmd_tmgr(tokens, n_tokens, out, out_size);
2187 if (strcmp(tokens[0], "tap") == 0) {
2188 cmd_tap(tokens, n_tokens, out, out_size);
2192 if (strcmp(tokens[0], "kni") == 0) {
2193 cmd_kni(tokens, n_tokens, out, out_size);
2197 if (strcmp(tokens[0], "port") == 0) {
2198 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
2202 if (strcmp(tokens[0], "table") == 0) {
2203 cmd_table_action_profile(tokens, n_tokens, out, out_size);
2207 if (strcmp(tokens[0], "pipeline") == 0) {
2208 if ((n_tokens >= 3) &&
2209 (strcmp(tokens[2], "period") == 0)) {
2210 cmd_pipeline(tokens, n_tokens, out, out_size);
2214 if ((n_tokens >= 5) &&
2215 (strcmp(tokens[2], "port") == 0) &&
2216 (strcmp(tokens[3], "in") == 0) &&
2217 (strcmp(tokens[4], "bsz") == 0)) {
2218 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
2222 if ((n_tokens >= 5) &&
2223 (strcmp(tokens[2], "port") == 0) &&
2224 (strcmp(tokens[3], "out") == 0) &&
2225 (strcmp(tokens[4], "bsz") == 0)) {
2226 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
2230 if ((n_tokens >= 4) &&
2231 (strcmp(tokens[2], "table") == 0) &&
2232 (strcmp(tokens[3], "match") == 0)) {
2233 cmd_pipeline_table(tokens, n_tokens, out, out_size);
2237 if ((n_tokens >= 6) &&
2238 (strcmp(tokens[2], "port") == 0) &&
2239 (strcmp(tokens[3], "in") == 0) &&
2240 (strcmp(tokens[5], "table") == 0)) {
2241 cmd_pipeline_port_in_table(tokens, n_tokens,
2246 if ((n_tokens >= 6) &&
2247 (strcmp(tokens[2], "port") == 0) &&
2248 (strcmp(tokens[3], "in") == 0) &&
2249 (strcmp(tokens[5], "enable") == 0)) {
2250 cmd_pipeline_port_in_enable(tokens, n_tokens,
2255 if ((n_tokens >= 6) &&
2256 (strcmp(tokens[2], "port") == 0) &&
2257 (strcmp(tokens[3], "in") == 0) &&
2258 (strcmp(tokens[5], "disable") == 0)) {
2259 cmd_pipeline_port_in_disable(tokens, n_tokens,
2265 if (strcmp(tokens[0], "thread") == 0) {
2266 if ((n_tokens >= 5) &&
2267 (strcmp(tokens[4], "enable") == 0)) {
2268 cmd_thread_pipeline_enable(tokens, n_tokens,
2273 if ((n_tokens >= 5) &&
2274 (strcmp(tokens[4], "disable") == 0)) {
2275 cmd_thread_pipeline_disable(tokens, n_tokens,
2281 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
2285 cli_script_process(const char *file_name,
2286 size_t msg_in_len_max,
2287 size_t msg_out_len_max)
2289 char *msg_in = NULL, *msg_out = NULL;
2292 /* Check input arguments */
2293 if ((file_name == NULL) ||
2294 (strlen(file_name) == 0) ||
2295 (msg_in_len_max == 0) ||
2296 (msg_out_len_max == 0))
2299 msg_in = malloc(msg_in_len_max + 1);
2300 msg_out = malloc(msg_out_len_max + 1);
2301 if ((msg_in == NULL) ||
2302 (msg_out == NULL)) {
2308 /* Open input file */
2309 f = fopen(file_name, "r");
2318 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
2321 printf("%s", msg_in);
2328 if (strlen(msg_out))
2329 printf("%s", msg_out);