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> stats read [clear]
1944 #define MSG_PIPELINE_PORT_IN_STATS \
1945 "Pkts in: %" PRIu64 "\n" \
1946 "Pkts dropped by AH: %" PRIu64 "\n" \
1947 "Pkts dropped by other: %" PRIu64 "\n"
1950 cmd_pipeline_port_in_stats(char **tokens,
1955 struct rte_pipeline_port_in_stats stats;
1956 char *pipeline_name;
1960 if ((n_tokens != 7) && (n_tokens != 8)) {
1961 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1965 pipeline_name = tokens[1];
1967 if (strcmp(tokens[2], "port") != 0) {
1968 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1972 if (strcmp(tokens[3], "in") != 0) {
1973 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1977 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
1978 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1982 if (strcmp(tokens[5], "stats") != 0) {
1983 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1987 if (strcmp(tokens[6], "read") != 0) {
1988 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
1993 if (n_tokens == 8) {
1994 if (strcmp(tokens[7], "clear") != 0) {
1995 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2002 status = pipeline_port_in_stats_read(pipeline_name,
2007 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2011 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2012 stats.stats.n_pkts_in,
2013 stats.n_pkts_dropped_by_ah,
2014 stats.stats.n_pkts_drop);
2018 * pipeline <pipeline_name> port in <port_id> enable
2021 cmd_pipeline_port_in_enable(char **tokens,
2026 char *pipeline_name;
2030 if (n_tokens != 6) {
2031 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2035 pipeline_name = tokens[1];
2037 if (strcmp(tokens[2], "port") != 0) {
2038 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2042 if (strcmp(tokens[3], "in") != 0) {
2043 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2047 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2048 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2052 if (strcmp(tokens[5], "enable") != 0) {
2053 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2057 status = pipeline_port_in_enable(pipeline_name, port_id);
2059 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2065 * pipeline <pipeline_name> port in <port_id> disable
2068 cmd_pipeline_port_in_disable(char **tokens,
2073 char *pipeline_name;
2077 if (n_tokens != 6) {
2078 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2082 pipeline_name = tokens[1];
2084 if (strcmp(tokens[2], "port") != 0) {
2085 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2089 if (strcmp(tokens[3], "in") != 0) {
2090 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2094 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2095 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2099 if (strcmp(tokens[5], "disable") != 0) {
2100 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2104 status = pipeline_port_in_disable(pipeline_name, port_id);
2106 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2112 * pipeline <pipeline_name> port out <port_id> stats read [clear]
2114 #define MSG_PIPELINE_PORT_OUT_STATS \
2115 "Pkts in: %" PRIu64 "\n" \
2116 "Pkts dropped by AH: %" PRIu64 "\n" \
2117 "Pkts dropped by other: %" PRIu64 "\n"
2120 cmd_pipeline_port_out_stats(char **tokens,
2125 struct rte_pipeline_port_out_stats stats;
2126 char *pipeline_name;
2130 if ((n_tokens != 7) && (n_tokens != 8)) {
2131 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2135 pipeline_name = tokens[1];
2137 if (strcmp(tokens[2], "port") != 0) {
2138 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2142 if (strcmp(tokens[3], "out") != 0) {
2143 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2147 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2148 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2152 if (strcmp(tokens[5], "stats") != 0) {
2153 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2157 if (strcmp(tokens[6], "read") != 0) {
2158 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2163 if (n_tokens == 8) {
2164 if (strcmp(tokens[7], "clear") != 0) {
2165 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2172 status = pipeline_port_out_stats_read(pipeline_name,
2177 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2181 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2182 stats.stats.n_pkts_in,
2183 stats.n_pkts_dropped_by_ah,
2184 stats.stats.n_pkts_drop);
2188 * pipeline <pipeline_name> table <table_id> stats read [clear]
2190 #define MSG_PIPELINE_TABLE_STATS \
2191 "Pkts in: %" PRIu64 "\n" \
2192 "Pkts in with lookup miss: %" PRIu64 "\n" \
2193 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2194 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2195 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2196 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2199 cmd_pipeline_table_stats(char **tokens,
2204 struct rte_pipeline_table_stats stats;
2205 char *pipeline_name;
2209 if ((n_tokens != 6) && (n_tokens != 7)) {
2210 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2214 pipeline_name = tokens[1];
2216 if (strcmp(tokens[2], "table") != 0) {
2217 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2221 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2222 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2226 if (strcmp(tokens[4], "stats") != 0) {
2227 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2231 if (strcmp(tokens[5], "read") != 0) {
2232 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2237 if (n_tokens == 7) {
2238 if (strcmp(tokens[6], "clear") != 0) {
2239 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2246 status = pipeline_table_stats_read(pipeline_name,
2251 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2255 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2256 stats.stats.n_pkts_in,
2257 stats.stats.n_pkts_lookup_miss,
2258 stats.n_pkts_dropped_by_lkp_hit_ah,
2259 stats.n_pkts_dropped_lkp_hit,
2260 stats.n_pkts_dropped_by_lkp_miss_ah,
2261 stats.n_pkts_dropped_lkp_miss);
2265 * thread <thread_id> pipeline <pipeline_name> enable
2268 cmd_thread_pipeline_enable(char **tokens,
2273 char *pipeline_name;
2277 if (n_tokens != 5) {
2278 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2282 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
2283 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
2287 if (strcmp(tokens[2], "pipeline") != 0) {
2288 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
2292 pipeline_name = tokens[3];
2294 if (strcmp(tokens[4], "enable") != 0) {
2295 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2299 status = thread_pipeline_enable(thread_id, pipeline_name);
2301 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
2307 * thread <thread_id> pipeline <pipeline_name> disable
2310 cmd_thread_pipeline_disable(char **tokens,
2315 char *pipeline_name;
2319 if (n_tokens != 5) {
2320 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2324 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
2325 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
2329 if (strcmp(tokens[2], "pipeline") != 0) {
2330 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
2334 pipeline_name = tokens[3];
2336 if (strcmp(tokens[4], "disable") != 0) {
2337 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2341 status = thread_pipeline_disable(thread_id, pipeline_name);
2343 snprintf(out, out_size, MSG_CMD_FAIL,
2344 "thread pipeline disable");
2350 cli_process(char *in, char *out, size_t out_size)
2352 char *tokens[CMD_MAX_TOKENS];
2353 uint32_t n_tokens = RTE_DIM(tokens);
2359 status = parse_tokenize_string(in, tokens, &n_tokens);
2361 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
2368 if (strcmp(tokens[0], "mempool") == 0) {
2369 cmd_mempool(tokens, n_tokens, out, out_size);
2373 if (strcmp(tokens[0], "link") == 0) {
2374 cmd_link(tokens, n_tokens, out, out_size);
2378 if (strcmp(tokens[0], "swq") == 0) {
2379 cmd_swq(tokens, n_tokens, out, out_size);
2383 if (strcmp(tokens[0], "tmgr") == 0) {
2384 if ((n_tokens >= 3) &&
2385 (strcmp(tokens[1], "subport") == 0) &&
2386 (strcmp(tokens[2], "profile") == 0)) {
2387 cmd_tmgr_subport_profile(tokens, n_tokens,
2392 if ((n_tokens >= 3) &&
2393 (strcmp(tokens[1], "pipe") == 0) &&
2394 (strcmp(tokens[2], "profile") == 0)) {
2395 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
2399 if ((n_tokens >= 5) &&
2400 (strcmp(tokens[2], "subport") == 0) &&
2401 (strcmp(tokens[4], "profile") == 0)) {
2402 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
2406 if ((n_tokens >= 5) &&
2407 (strcmp(tokens[2], "subport") == 0) &&
2408 (strcmp(tokens[4], "pipe") == 0)) {
2409 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
2413 cmd_tmgr(tokens, n_tokens, out, out_size);
2417 if (strcmp(tokens[0], "tap") == 0) {
2418 cmd_tap(tokens, n_tokens, out, out_size);
2422 if (strcmp(tokens[0], "kni") == 0) {
2423 cmd_kni(tokens, n_tokens, out, out_size);
2427 if (strcmp(tokens[0], "port") == 0) {
2428 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
2432 if (strcmp(tokens[0], "table") == 0) {
2433 cmd_table_action_profile(tokens, n_tokens, out, out_size);
2437 if (strcmp(tokens[0], "pipeline") == 0) {
2438 if ((n_tokens >= 3) &&
2439 (strcmp(tokens[2], "period") == 0)) {
2440 cmd_pipeline(tokens, n_tokens, out, out_size);
2444 if ((n_tokens >= 5) &&
2445 (strcmp(tokens[2], "port") == 0) &&
2446 (strcmp(tokens[3], "in") == 0) &&
2447 (strcmp(tokens[4], "bsz") == 0)) {
2448 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
2452 if ((n_tokens >= 5) &&
2453 (strcmp(tokens[2], "port") == 0) &&
2454 (strcmp(tokens[3], "out") == 0) &&
2455 (strcmp(tokens[4], "bsz") == 0)) {
2456 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
2460 if ((n_tokens >= 4) &&
2461 (strcmp(tokens[2], "table") == 0) &&
2462 (strcmp(tokens[3], "match") == 0)) {
2463 cmd_pipeline_table(tokens, n_tokens, out, out_size);
2467 if ((n_tokens >= 6) &&
2468 (strcmp(tokens[2], "port") == 0) &&
2469 (strcmp(tokens[3], "in") == 0) &&
2470 (strcmp(tokens[5], "table") == 0)) {
2471 cmd_pipeline_port_in_table(tokens, n_tokens,
2476 if ((n_tokens >= 6) &&
2477 (strcmp(tokens[2], "port") == 0) &&
2478 (strcmp(tokens[3], "in") == 0) &&
2479 (strcmp(tokens[5], "stats") == 0)) {
2480 cmd_pipeline_port_in_stats(tokens, n_tokens,
2485 if ((n_tokens >= 6) &&
2486 (strcmp(tokens[2], "port") == 0) &&
2487 (strcmp(tokens[3], "in") == 0) &&
2488 (strcmp(tokens[5], "enable") == 0)) {
2489 cmd_pipeline_port_in_enable(tokens, n_tokens,
2494 if ((n_tokens >= 6) &&
2495 (strcmp(tokens[2], "port") == 0) &&
2496 (strcmp(tokens[3], "in") == 0) &&
2497 (strcmp(tokens[5], "disable") == 0)) {
2498 cmd_pipeline_port_in_disable(tokens, n_tokens,
2503 if ((n_tokens >= 6) &&
2504 (strcmp(tokens[2], "port") == 0) &&
2505 (strcmp(tokens[3], "out") == 0) &&
2506 (strcmp(tokens[5], "stats") == 0)) {
2507 cmd_pipeline_port_out_stats(tokens, n_tokens,
2512 if ((n_tokens >= 5) &&
2513 (strcmp(tokens[2], "table") == 0) &&
2514 (strcmp(tokens[4], "stats") == 0)) {
2515 cmd_pipeline_table_stats(tokens, n_tokens,
2521 if (strcmp(tokens[0], "thread") == 0) {
2522 if ((n_tokens >= 5) &&
2523 (strcmp(tokens[4], "enable") == 0)) {
2524 cmd_thread_pipeline_enable(tokens, n_tokens,
2529 if ((n_tokens >= 5) &&
2530 (strcmp(tokens[4], "disable") == 0)) {
2531 cmd_thread_pipeline_disable(tokens, n_tokens,
2537 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
2541 cli_script_process(const char *file_name,
2542 size_t msg_in_len_max,
2543 size_t msg_out_len_max)
2545 char *msg_in = NULL, *msg_out = NULL;
2548 /* Check input arguments */
2549 if ((file_name == NULL) ||
2550 (strlen(file_name) == 0) ||
2551 (msg_in_len_max == 0) ||
2552 (msg_out_len_max == 0))
2555 msg_in = malloc(msg_in_len_max + 1);
2556 msg_out = malloc(msg_out_len_max + 1);
2557 if ((msg_in == NULL) ||
2558 (msg_out == NULL)) {
2564 /* Open input file */
2565 f = fopen(file_name, "r");
2574 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
2577 printf("%s", msg_in);
2584 if (strlen(msg_out))
2585 printf("%s", msg_out);