1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include <rte_common.h>
11 #include <rte_cycles.h>
24 #ifndef CMD_MAX_TOKENS
25 #define CMD_MAX_TOKENS 256
28 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
29 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
30 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
31 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
32 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
33 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
34 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
35 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
36 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
37 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
42 if ((strlen(in) && index("!#%;", in[0])) ||
43 (strncmp(in, "//", 2) == 0) ||
44 (strncmp(in, "--", 2) == 0))
51 * mempool <mempool_name>
52 * buffer <buffer_size>
58 cmd_mempool(char **tokens,
63 struct mempool_params p;
65 struct mempool *mempool;
68 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
74 if (strcmp(tokens[2], "buffer") != 0) {
75 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
79 if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
80 snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
84 if (strcmp(tokens[4], "pool") != 0) {
85 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
89 if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
90 snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
94 if (strcmp(tokens[6], "cache") != 0) {
95 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
99 if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
100 snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
104 if (strcmp(tokens[8], "cpu") != 0) {
105 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
109 if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
110 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
114 mempool = mempool_create(name, &p);
115 if (mempool == NULL) {
116 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
123 * dev <device_name> | port <port_id>
124 * rxq <n_queues> <queue_size> <mempool_name>
125 * txq <n_queues> <queue_size>
126 * promiscuous on | off
127 * [rss <qid_0> ... <qid_n>]
130 cmd_link(char **tokens,
135 struct link_params p;
136 struct link_params_rss rss;
140 if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
141 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
146 if (strcmp(tokens[2], "dev") == 0)
147 p.dev_name = tokens[3];
148 else if (strcmp(tokens[2], "port") == 0) {
151 if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
152 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
156 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
160 if (strcmp(tokens[4], "rxq") != 0) {
161 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
165 if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
166 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
169 if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
170 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
174 p.rx.mempool_name = tokens[7];
176 if (strcmp(tokens[8], "txq") != 0) {
177 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
181 if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
182 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
186 if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
187 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
191 if (strcmp(tokens[11], "promiscuous") != 0) {
192 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
196 if (strcmp(tokens[12], "on") == 0)
198 else if (strcmp(tokens[12], "off") == 0)
201 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
208 uint32_t queue_id, i;
210 if (strcmp(tokens[13], "rss") != 0) {
211 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
218 for (i = 14; i < n_tokens; i++) {
219 if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
220 snprintf(out, out_size, MSG_ARG_INVALID,
225 rss.queue_id[rss.n_queues] = queue_id;
230 link = link_create(name, &p);
232 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
243 cmd_swq(char **tokens,
253 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
259 if (strcmp(tokens[2], "size") != 0) {
260 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
264 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
265 snprintf(out, out_size, MSG_ARG_INVALID, "size");
269 if (strcmp(tokens[4], "cpu") != 0) {
270 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
274 if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
275 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
279 swq = swq_create(name, &p);
281 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
287 * tmgr subport profile
288 * <tb_rate> <tb_size>
289 * <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>
293 cmd_tmgr_subport_profile(char **tokens,
298 struct rte_sched_subport_params p;
301 if (n_tokens != 10) {
302 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
306 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
307 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
311 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
312 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
316 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
317 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
318 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
322 if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) {
323 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
327 status = tmgr_subport_profile_add(&p);
329 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
336 * <tb_rate> <tb_size>
337 * <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>
343 cmd_tmgr_pipe_profile(char **tokens,
348 struct rte_sched_pipe_params p;
351 if (n_tokens != 27) {
352 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
356 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
357 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
361 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
362 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
366 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
367 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
368 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
372 if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) {
373 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
377 #ifdef RTE_SCHED_SUBPORT_TC_OV
378 if (parser_read_uint8(&p.tc_ov_weight, tokens[10]) != 0) {
379 snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
384 for (i = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++)
385 if (parser_read_uint8(&p.wrr_weights[i], tokens[11 + i]) != 0) {
386 snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
390 status = tmgr_pipe_profile_add(&p);
392 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
400 * spp <n_subports_per_port>
401 * pps <n_pipes_per_subport>
402 * qsize <qsize_tc0> <qsize_tc1> <qsize_tc2> <qsize_tc3>
403 * fo <frame_overhead>
408 cmd_tmgr(char **tokens,
413 struct tmgr_port_params p;
415 struct tmgr_port *tmgr_port;
418 if (n_tokens != 19) {
419 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
425 if (strcmp(tokens[2], "rate") != 0) {
426 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
430 if (parser_read_uint32(&p.rate, tokens[3]) != 0) {
431 snprintf(out, out_size, MSG_ARG_INVALID, "rate");
435 if (strcmp(tokens[4], "spp") != 0) {
436 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
440 if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
441 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
445 if (strcmp(tokens[6], "pps") != 0) {
446 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
450 if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
451 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
455 if (strcmp(tokens[8], "qsize") != 0) {
456 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "qsize");
460 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
461 if (parser_read_uint16(&p.qsize[i], tokens[9 + i]) != 0) {
462 snprintf(out, out_size, MSG_ARG_INVALID, "qsize");
466 if (strcmp(tokens[13], "fo") != 0) {
467 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
471 if (parser_read_uint32(&p.frame_overhead, tokens[14]) != 0) {
472 snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
476 if (strcmp(tokens[15], "mtu") != 0) {
477 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
481 if (parser_read_uint32(&p.mtu, tokens[16]) != 0) {
482 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
486 if (strcmp(tokens[17], "cpu") != 0) {
487 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
491 if (parser_read_uint32(&p.cpu_id, tokens[18]) != 0) {
492 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
496 tmgr_port = tmgr_port_create(name, &p);
497 if (tmgr_port == NULL) {
498 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
504 * tmgr <tmgr_name> subport <subport_id>
505 * profile <subport_profile_id>
508 cmd_tmgr_subport(char **tokens,
513 uint32_t subport_id, subport_profile_id;
518 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
524 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
525 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
529 if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
530 snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
534 status = tmgr_subport_config(name, subport_id, subport_profile_id);
536 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
542 * tmgr <tmgr_name> subport <subport_id> pipe
543 * from <pipe_id_first> to <pipe_id_last>
544 * profile <pipe_profile_id>
547 cmd_tmgr_subport_pipe(char **tokens,
552 uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
556 if (n_tokens != 11) {
557 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
563 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
564 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
568 if (strcmp(tokens[4], "pipe") != 0) {
569 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
573 if (strcmp(tokens[5], "from") != 0) {
574 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
578 if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
579 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
583 if (strcmp(tokens[7], "to") != 0) {
584 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
588 if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
589 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
593 if (strcmp(tokens[9], "profile") != 0) {
594 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
598 if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
599 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
603 status = tmgr_pipe_config(name, subport_id, pipe_id_first,
604 pipe_id_last, pipe_profile_id);
606 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
615 cmd_tap(char **tokens,
624 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
630 tap = tap_create(name);
632 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
640 * mempool <mempool_name>
641 * [thread <thread_id>]
644 cmd_kni(char **tokens,
653 if ((n_tokens != 6) && (n_tokens != 8)) {
654 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
660 if (strcmp(tokens[2], "link") != 0) {
661 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
665 p.link_name = tokens[3];
667 if (strcmp(tokens[4], "mempool") != 0) {
668 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
672 p.mempool_name = tokens[5];
675 if (strcmp(tokens[6], "thread") != 0) {
676 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
680 if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
681 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
689 kni = kni_create(name, &p);
691 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
697 * port in action profile <profile_name>
698 * [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]
699 * [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]
702 cmd_port_in_action_profile(char **tokens,
707 struct port_in_action_profile_params p;
708 struct port_in_action_profile *ap;
712 memset(&p, 0, sizeof(p));
715 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
719 if (strcmp(tokens[1], "in") != 0) {
720 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
724 if (strcmp(tokens[2], "action") != 0) {
725 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
729 if (strcmp(tokens[3], "profile") != 0) {
730 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
738 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
741 if (n_tokens < t0 + 10) {
742 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
746 if (strcmp(tokens[t0 + 1], "match") == 0)
747 p.fltr.filter_on_match = 1;
748 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
749 p.fltr.filter_on_match = 0;
751 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
755 if (strcmp(tokens[t0 + 2], "offset") != 0) {
756 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
760 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
761 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
765 if (strcmp(tokens[t0 + 4], "mask") != 0) {
766 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
770 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
771 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
772 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
773 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
777 if (strcmp(tokens[t0 + 6], "key") != 0) {
778 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
782 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
783 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
784 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
785 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
789 if (strcmp(tokens[t0 + 8], "port") != 0) {
790 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
794 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
795 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
799 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
803 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
806 if (n_tokens < t0 + 22) {
807 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile balance");
811 if (strcmp(tokens[t0 + 1], "offset") != 0) {
812 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
816 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
817 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
821 if (strcmp(tokens[t0 + 3], "mask") != 0) {
822 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
826 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
827 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
828 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
832 if (strcmp(tokens[t0 + 5], "port") != 0) {
833 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
837 for (i = 0; i < 16; i++)
838 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
839 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
843 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
848 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
852 ap = port_in_action_profile_create(name, &p);
854 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
860 * table action profile <profile_name>
864 * [meter srtcm | trtcm
866 * stats none | pkts | bytes | both]
867 * [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]
868 * [encap ether | vlan | qinq | mpls | pppoe]
873 * [stats pkts | bytes | both]
877 cmd_table_action_profile(char **tokens,
882 struct table_action_profile_params p;
883 struct table_action_profile *ap;
887 memset(&p, 0, sizeof(p));
890 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
894 if (strcmp(tokens[1], "action") != 0) {
895 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
899 if (strcmp(tokens[2], "profile") != 0) {
900 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
906 if (strcmp(tokens[4], "ipv4") == 0)
907 p.common.ip_version = 1;
908 else if (strcmp(tokens[4], "ipv6") == 0)
909 p.common.ip_version = 0;
911 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
915 if (strcmp(tokens[5], "offset") != 0) {
916 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
920 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
921 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
925 if (strcmp(tokens[7], "fwd") != 0) {
926 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
930 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
933 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
934 if (n_tokens < t0 + 6) {
935 snprintf(out, out_size, MSG_ARG_MISMATCH,
936 "table action profile meter");
940 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
941 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
942 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
943 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
945 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
950 if (strcmp(tokens[t0 + 2], "tc") != 0) {
951 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
955 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
956 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
960 if (strcmp(tokens[t0 + 4], "stats") != 0) {
961 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
965 if (strcmp(tokens[t0 + 5], "none") == 0) {
966 p.mtr.n_packets_enabled = 0;
967 p.mtr.n_bytes_enabled = 0;
968 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
969 p.mtr.n_packets_enabled = 1;
970 p.mtr.n_bytes_enabled = 0;
971 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
972 p.mtr.n_packets_enabled = 0;
973 p.mtr.n_bytes_enabled = 1;
974 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
975 p.mtr.n_packets_enabled = 1;
976 p.mtr.n_bytes_enabled = 1;
978 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
979 "none or pkts or bytes or both");
983 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
987 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
988 if (n_tokens < t0 + 5) {
989 snprintf(out, out_size, MSG_ARG_MISMATCH,
990 "table action profile tm");
994 if (strcmp(tokens[t0 + 1], "spp") != 0) {
995 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
999 if (parser_read_uint32(&p.tm.n_subports_per_port,
1000 tokens[t0 + 2]) != 0) {
1001 snprintf(out, out_size, MSG_ARG_INVALID,
1002 "n_subports_per_port");
1006 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1007 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1011 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1012 tokens[t0 + 4]) != 0) {
1013 snprintf(out, out_size, MSG_ARG_INVALID,
1014 "n_pipes_per_subport");
1018 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1022 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1023 if (n_tokens < t0 + 2) {
1024 snprintf(out, out_size, MSG_ARG_MISMATCH,
1025 "action profile encap");
1029 if (strcmp(tokens[t0 + 1], "ether") == 0)
1030 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1031 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1032 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1033 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1034 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1035 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1036 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1037 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1038 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1040 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1044 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1048 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1049 if (n_tokens < t0 + 4) {
1050 snprintf(out, out_size, MSG_ARG_MISMATCH,
1051 "table action profile nat");
1055 if (strcmp(tokens[t0 + 1], "src") == 0)
1056 p.nat.source_nat = 1;
1057 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1058 p.nat.source_nat = 0;
1060 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1065 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1066 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1070 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1072 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1075 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1080 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1084 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1085 if (n_tokens < t0 + 4) {
1086 snprintf(out, out_size, MSG_ARG_MISMATCH,
1087 "table action profile ttl");
1091 if (strcmp(tokens[t0 + 1], "drop") == 0)
1093 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1096 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1101 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1102 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1106 if (strcmp(tokens[t0 + 3], "none") == 0)
1107 p.ttl.n_packets_enabled = 0;
1108 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1109 p.ttl.n_packets_enabled = 1;
1111 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1116 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1120 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1121 if (n_tokens < t0 + 2) {
1122 snprintf(out, out_size, MSG_ARG_MISMATCH,
1123 "table action profile stats");
1127 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1128 p.stats.n_packets_enabled = 1;
1129 p.stats.n_bytes_enabled = 0;
1130 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1131 p.stats.n_packets_enabled = 0;
1132 p.stats.n_bytes_enabled = 1;
1133 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1134 p.stats.n_packets_enabled = 1;
1135 p.stats.n_bytes_enabled = 1;
1137 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1138 "pkts or bytes or both");
1142 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1146 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1147 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1151 if (t0 < n_tokens) {
1152 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1156 ap = table_action_profile_create(name, &p);
1158 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1164 * pipeline <pipeline_name>
1165 * period <timer_period_ms>
1166 * offset_port_id <offset_port_id>
1170 cmd_pipeline(char **tokens,
1175 struct pipeline_params p;
1177 struct pipeline *pipeline;
1179 if (n_tokens != 8) {
1180 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1186 if (strcmp(tokens[2], "period") != 0) {
1187 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1191 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1192 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1196 if (strcmp(tokens[4], "offset_port_id") != 0) {
1197 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1201 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1202 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1206 if (strcmp(tokens[6], "cpu") != 0) {
1207 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1211 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1212 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1216 pipeline = pipeline_create(name, &p);
1217 if (pipeline == NULL) {
1218 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1224 * pipeline <pipeline_name> port in
1226 * link <link_name> rxq <queue_id>
1228 * | tmgr <tmgr_name>
1229 * | tap <tap_name> mempool <mempool_name> mtu <mtu>
1231 * | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>
1232 * [action <port_in_action_profile_name>]
1236 cmd_pipeline_port_in(char **tokens,
1241 struct port_in_params p;
1242 char *pipeline_name;
1244 int enabled, status;
1247 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1251 pipeline_name = tokens[1];
1253 if (strcmp(tokens[2], "port") != 0) {
1254 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1258 if (strcmp(tokens[3], "in") != 0) {
1259 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1263 if (strcmp(tokens[4], "bsz") != 0) {
1264 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1268 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1269 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1275 if (strcmp(tokens[t0], "link") == 0) {
1276 if (n_tokens < t0 + 4) {
1277 snprintf(out, out_size, MSG_ARG_MISMATCH,
1278 "pipeline port in link");
1282 p.type = PORT_IN_RXQ;
1284 p.dev_name = tokens[t0 + 1];
1286 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1287 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1291 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1292 snprintf(out, out_size, MSG_ARG_INVALID,
1297 } else if (strcmp(tokens[t0], "swq") == 0) {
1298 if (n_tokens < t0 + 2) {
1299 snprintf(out, out_size, MSG_ARG_MISMATCH,
1300 "pipeline port in swq");
1304 p.type = PORT_IN_SWQ;
1306 p.dev_name = tokens[t0 + 1];
1309 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1310 if (n_tokens < t0 + 2) {
1311 snprintf(out, out_size, MSG_ARG_MISMATCH,
1312 "pipeline port in tmgr");
1316 p.type = PORT_IN_TMGR;
1318 p.dev_name = tokens[t0 + 1];
1321 } else if (strcmp(tokens[t0], "tap") == 0) {
1322 if (n_tokens < t0 + 6) {
1323 snprintf(out, out_size, MSG_ARG_MISMATCH,
1324 "pipeline port in tap");
1328 p.type = PORT_IN_TAP;
1330 p.dev_name = tokens[t0 + 1];
1332 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1333 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1338 p.tap.mempool_name = tokens[t0 + 3];
1340 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1341 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1346 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1347 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1352 } else if (strcmp(tokens[t0], "kni") == 0) {
1353 if (n_tokens < t0 + 2) {
1354 snprintf(out, out_size, MSG_ARG_MISMATCH,
1355 "pipeline port in kni");
1359 p.type = PORT_IN_KNI;
1361 p.dev_name = tokens[t0 + 1];
1364 } else if (strcmp(tokens[t0], "source") == 0) {
1365 if (n_tokens < t0 + 6) {
1366 snprintf(out, out_size, MSG_ARG_MISMATCH,
1367 "pipeline port in source");
1371 p.type = PORT_IN_SOURCE;
1375 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1376 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1381 p.source.mempool_name = tokens[t0 + 2];
1383 if (strcmp(tokens[t0 + 3], "file") != 0) {
1384 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1389 p.source.file_name = tokens[t0 + 4];
1391 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1392 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1397 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1398 snprintf(out, out_size, MSG_ARG_INVALID,
1405 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1409 p.action_profile_name = NULL;
1410 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1411 if (n_tokens < t0 + 2) {
1412 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1416 p.action_profile_name = tokens[t0 + 1];
1422 if ((n_tokens > t0) &&
1423 (strcmp(tokens[t0], "disabled") == 0)) {
1429 if (n_tokens != t0) {
1430 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1434 status = pipeline_port_in_create(pipeline_name,
1437 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1443 * pipeline <pipeline_name> port out
1445 * link <link_name> txq <txq_id>
1447 * | tmgr <tmgr_name>
1450 * | sink [file <file_name> pkts <max_n_pkts>]
1453 cmd_pipeline_port_out(char **tokens,
1458 struct port_out_params p;
1459 char *pipeline_name;
1462 memset(&p, 0, sizeof(p));
1465 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1469 pipeline_name = tokens[1];
1471 if (strcmp(tokens[2], "port") != 0) {
1472 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1476 if (strcmp(tokens[3], "out") != 0) {
1477 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1481 if (strcmp(tokens[4], "bsz") != 0) {
1482 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1486 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1487 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1491 if (strcmp(tokens[6], "link") == 0) {
1492 if (n_tokens != 10) {
1493 snprintf(out, out_size, MSG_ARG_MISMATCH,
1494 "pipeline port out link");
1498 p.type = PORT_OUT_TXQ;
1500 p.dev_name = tokens[7];
1502 if (strcmp(tokens[8], "txq") != 0) {
1503 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1507 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1508 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1511 } else if (strcmp(tokens[6], "swq") == 0) {
1512 if (n_tokens != 8) {
1513 snprintf(out, out_size, MSG_ARG_MISMATCH,
1514 "pipeline port out swq");
1518 p.type = PORT_OUT_SWQ;
1520 p.dev_name = tokens[7];
1521 } else if (strcmp(tokens[6], "tmgr") == 0) {
1522 if (n_tokens != 8) {
1523 snprintf(out, out_size, MSG_ARG_MISMATCH,
1524 "pipeline port out tmgr");
1528 p.type = PORT_OUT_TMGR;
1530 p.dev_name = tokens[7];
1531 } else if (strcmp(tokens[6], "tap") == 0) {
1532 if (n_tokens != 8) {
1533 snprintf(out, out_size, MSG_ARG_MISMATCH,
1534 "pipeline port out tap");
1538 p.type = PORT_OUT_TAP;
1540 p.dev_name = tokens[7];
1541 } else if (strcmp(tokens[6], "kni") == 0) {
1542 if (n_tokens != 8) {
1543 snprintf(out, out_size, MSG_ARG_MISMATCH,
1544 "pipeline port out kni");
1548 p.type = PORT_OUT_KNI;
1550 p.dev_name = tokens[7];
1551 } else if (strcmp(tokens[6], "sink") == 0) {
1552 if ((n_tokens != 7) && (n_tokens != 11)) {
1553 snprintf(out, out_size, MSG_ARG_MISMATCH,
1554 "pipeline port out sink");
1558 p.type = PORT_OUT_SINK;
1562 if (n_tokens == 7) {
1563 p.sink.file_name = NULL;
1564 p.sink.max_n_pkts = 0;
1566 if (strcmp(tokens[7], "file") != 0) {
1567 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1572 p.sink.file_name = tokens[8];
1574 if (strcmp(tokens[9], "pkts") != 0) {
1575 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1579 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1580 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1585 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1589 status = pipeline_port_out_create(pipeline_name, &p);
1591 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1597 * pipeline <pipeline_name> table
1601 * offset <ip_header_offset>
1604 * offset <key_offset>
1610 * offset <key_offset>
1611 * buckets <n_buckets>
1615 * offset <ip_header_offset>
1618 * [action <table_action_profile_name>]
1621 cmd_pipeline_table(char **tokens,
1626 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
1627 struct table_params p;
1628 char *pipeline_name;
1633 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1637 pipeline_name = tokens[1];
1639 if (strcmp(tokens[2], "table") != 0) {
1640 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
1644 if (strcmp(tokens[3], "match") != 0) {
1645 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
1650 if (strcmp(tokens[t0], "acl") == 0) {
1651 if (n_tokens < t0 + 6) {
1652 snprintf(out, out_size, MSG_ARG_MISMATCH,
1653 "pipeline table acl");
1657 p.match_type = TABLE_ACL;
1659 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
1660 p.match.acl.ip_version = 1;
1661 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
1662 p.match.acl.ip_version = 0;
1664 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1669 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1670 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1674 if (parser_read_uint32(&p.match.acl.ip_header_offset,
1675 tokens[t0 + 3]) != 0) {
1676 snprintf(out, out_size, MSG_ARG_INVALID,
1677 "ip_header_offset");
1681 if (strcmp(tokens[t0 + 4], "size") != 0) {
1682 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1686 if (parser_read_uint32(&p.match.acl.n_rules,
1687 tokens[t0 + 5]) != 0) {
1688 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
1693 } else if (strcmp(tokens[t0], "array") == 0) {
1694 if (n_tokens < t0 + 5) {
1695 snprintf(out, out_size, MSG_ARG_MISMATCH,
1696 "pipeline table array");
1700 p.match_type = TABLE_ARRAY;
1702 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1703 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1707 if (parser_read_uint32(&p.match.array.key_offset,
1708 tokens[t0 + 2]) != 0) {
1709 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1713 if (strcmp(tokens[t0 + 3], "size") != 0) {
1714 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1718 if (parser_read_uint32(&p.match.array.n_keys,
1719 tokens[t0 + 4]) != 0) {
1720 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
1725 } else if (strcmp(tokens[t0], "hash") == 0) {
1726 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
1728 if (n_tokens < t0 + 12) {
1729 snprintf(out, out_size, MSG_ARG_MISMATCH,
1730 "pipeline table hash");
1734 p.match_type = TABLE_HASH;
1736 if (strcmp(tokens[t0 + 1], "ext") == 0)
1737 p.match.hash.extendable_bucket = 1;
1738 else if (strcmp(tokens[t0 + 1], "lru") == 0)
1739 p.match.hash.extendable_bucket = 0;
1741 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1746 if (strcmp(tokens[t0 + 2], "key") != 0) {
1747 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
1751 if ((parser_read_uint32(&p.match.hash.key_size,
1752 tokens[t0 + 3]) != 0) ||
1753 (p.match.hash.key_size == 0) ||
1754 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
1755 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
1759 if (strcmp(tokens[t0 + 4], "mask") != 0) {
1760 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1764 if ((parse_hex_string(tokens[t0 + 5],
1765 key_mask, &key_mask_size) != 0) ||
1766 (key_mask_size != p.match.hash.key_size)) {
1767 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1770 p.match.hash.key_mask = key_mask;
1772 if (strcmp(tokens[t0 + 6], "offset") != 0) {
1773 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1777 if (parser_read_uint32(&p.match.hash.key_offset,
1778 tokens[t0 + 7]) != 0) {
1779 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1783 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
1784 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
1788 if (parser_read_uint32(&p.match.hash.n_buckets,
1789 tokens[t0 + 9]) != 0) {
1790 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
1794 if (strcmp(tokens[t0 + 10], "size") != 0) {
1795 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1799 if (parser_read_uint32(&p.match.hash.n_keys,
1800 tokens[t0 + 11]) != 0) {
1801 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
1806 } else if (strcmp(tokens[t0], "lpm") == 0) {
1807 if (n_tokens < t0 + 6) {
1808 snprintf(out, out_size, MSG_ARG_MISMATCH,
1809 "pipeline table lpm");
1813 p.match_type = TABLE_LPM;
1815 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
1816 p.match.lpm.key_size = 4;
1817 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
1818 p.match.lpm.key_size = 16;
1820 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1825 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1826 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1830 if (parser_read_uint32(&p.match.lpm.key_offset,
1831 tokens[t0 + 3]) != 0) {
1832 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1836 if (strcmp(tokens[t0 + 4], "size") != 0) {
1837 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1841 if (parser_read_uint32(&p.match.lpm.n_rules,
1842 tokens[t0 + 5]) != 0) {
1843 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
1848 } else if (strcmp(tokens[t0], "stub") == 0) {
1849 if (n_tokens < t0 + 1) {
1850 snprintf(out, out_size, MSG_ARG_MISMATCH,
1851 "pipeline table stub");
1855 p.match_type = TABLE_STUB;
1859 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1863 p.action_profile_name = NULL;
1864 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1865 if (n_tokens < t0 + 2) {
1866 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1870 p.action_profile_name = tokens[t0 + 1];
1875 if (n_tokens > t0) {
1876 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1880 status = pipeline_table_create(pipeline_name, &p);
1882 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1888 * pipeline <pipeline_name> port in <port_id> table <table_id>
1891 cmd_pipeline_port_in_table(char **tokens,
1896 char *pipeline_name;
1897 uint32_t port_id, table_id;
1900 if (n_tokens != 7) {
1901 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1905 pipeline_name = tokens[1];
1907 if (strcmp(tokens[2], "port") != 0) {
1908 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1912 if (strcmp(tokens[3], "in") != 0) {
1913 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1917 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
1918 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1922 if (strcmp(tokens[5], "table") != 0) {
1923 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
1927 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
1928 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
1932 status = pipeline_port_in_connect_to_table(pipeline_name,
1936 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1942 * pipeline <pipeline_name> port in <port_id> stats read [clear]
1945 #define MSG_PIPELINE_PORT_IN_STATS \
1946 "Pkts in: %" PRIu64 "\n" \
1947 "Pkts dropped by AH: %" PRIu64 "\n" \
1948 "Pkts dropped by other: %" PRIu64 "\n"
1951 cmd_pipeline_port_in_stats(char **tokens,
1956 struct rte_pipeline_port_in_stats stats;
1957 char *pipeline_name;
1961 if ((n_tokens != 7) && (n_tokens != 8)) {
1962 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1966 pipeline_name = tokens[1];
1968 if (strcmp(tokens[2], "port") != 0) {
1969 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1973 if (strcmp(tokens[3], "in") != 0) {
1974 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1978 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
1979 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1983 if (strcmp(tokens[5], "stats") != 0) {
1984 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1988 if (strcmp(tokens[6], "read") != 0) {
1989 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
1994 if (n_tokens == 8) {
1995 if (strcmp(tokens[7], "clear") != 0) {
1996 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2003 status = pipeline_port_in_stats_read(pipeline_name,
2008 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2012 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2013 stats.stats.n_pkts_in,
2014 stats.n_pkts_dropped_by_ah,
2015 stats.stats.n_pkts_drop);
2019 * pipeline <pipeline_name> port in <port_id> enable
2022 cmd_pipeline_port_in_enable(char **tokens,
2027 char *pipeline_name;
2031 if (n_tokens != 6) {
2032 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2036 pipeline_name = tokens[1];
2038 if (strcmp(tokens[2], "port") != 0) {
2039 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2043 if (strcmp(tokens[3], "in") != 0) {
2044 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2048 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2049 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2053 if (strcmp(tokens[5], "enable") != 0) {
2054 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2058 status = pipeline_port_in_enable(pipeline_name, port_id);
2060 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2066 * pipeline <pipeline_name> port in <port_id> disable
2069 cmd_pipeline_port_in_disable(char **tokens,
2074 char *pipeline_name;
2078 if (n_tokens != 6) {
2079 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2083 pipeline_name = tokens[1];
2085 if (strcmp(tokens[2], "port") != 0) {
2086 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2090 if (strcmp(tokens[3], "in") != 0) {
2091 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2095 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2096 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2100 if (strcmp(tokens[5], "disable") != 0) {
2101 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2105 status = pipeline_port_in_disable(pipeline_name, port_id);
2107 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2113 * pipeline <pipeline_name> port out <port_id> stats read [clear]
2115 #define MSG_PIPELINE_PORT_OUT_STATS \
2116 "Pkts in: %" PRIu64 "\n" \
2117 "Pkts dropped by AH: %" PRIu64 "\n" \
2118 "Pkts dropped by other: %" PRIu64 "\n"
2121 cmd_pipeline_port_out_stats(char **tokens,
2126 struct rte_pipeline_port_out_stats stats;
2127 char *pipeline_name;
2131 if ((n_tokens != 7) && (n_tokens != 8)) {
2132 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2136 pipeline_name = tokens[1];
2138 if (strcmp(tokens[2], "port") != 0) {
2139 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2143 if (strcmp(tokens[3], "out") != 0) {
2144 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2148 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2149 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2153 if (strcmp(tokens[5], "stats") != 0) {
2154 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2158 if (strcmp(tokens[6], "read") != 0) {
2159 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2164 if (n_tokens == 8) {
2165 if (strcmp(tokens[7], "clear") != 0) {
2166 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2173 status = pipeline_port_out_stats_read(pipeline_name,
2178 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2182 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2183 stats.stats.n_pkts_in,
2184 stats.n_pkts_dropped_by_ah,
2185 stats.stats.n_pkts_drop);
2189 * pipeline <pipeline_name> table <table_id> stats read [clear]
2191 #define MSG_PIPELINE_TABLE_STATS \
2192 "Pkts in: %" PRIu64 "\n" \
2193 "Pkts in with lookup miss: %" PRIu64 "\n" \
2194 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2195 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2196 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2197 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2200 cmd_pipeline_table_stats(char **tokens,
2205 struct rte_pipeline_table_stats stats;
2206 char *pipeline_name;
2210 if ((n_tokens != 6) && (n_tokens != 7)) {
2211 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2215 pipeline_name = tokens[1];
2217 if (strcmp(tokens[2], "table") != 0) {
2218 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2222 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2223 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2227 if (strcmp(tokens[4], "stats") != 0) {
2228 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2232 if (strcmp(tokens[5], "read") != 0) {
2233 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2238 if (n_tokens == 7) {
2239 if (strcmp(tokens[6], "clear") != 0) {
2240 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2247 status = pipeline_table_stats_read(pipeline_name,
2252 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2256 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2257 stats.stats.n_pkts_in,
2258 stats.stats.n_pkts_lookup_miss,
2259 stats.n_pkts_dropped_by_lkp_hit_ah,
2260 stats.n_pkts_dropped_lkp_hit,
2261 stats.n_pkts_dropped_by_lkp_miss_ah,
2262 stats.n_pkts_dropped_lkp_miss);
2270 * priority <priority>
2271 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2272 * <sp0> <sp1> <dp0> <dp1> <proto>
2277 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2278 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2279 * | ipv4_addr <addr>
2280 * | ipv6_addr <addr>
2281 * | qinq <svlan> <cvlan>
2283 * ipv4 | ipv6 <addr> <depth>
2285 struct pkt_key_qinq {
2286 uint16_t ethertype_svlan;
2288 uint16_t ethertype_cvlan;
2290 } __attribute__((__packed__));
2292 struct pkt_key_ipv4_5tuple {
2293 uint8_t time_to_live;
2295 uint16_t hdr_checksum;
2300 } __attribute__((__packed__));
2302 struct pkt_key_ipv6_5tuple {
2303 uint16_t payload_length;
2310 } __attribute__((__packed__));
2312 struct pkt_key_ipv4_addr {
2314 } __attribute__((__packed__));
2316 struct pkt_key_ipv6_addr {
2318 } __attribute__((__packed__));
2321 parse_match(char **tokens,
2325 struct table_rule_match *m)
2327 memset(m, 0, sizeof(*m));
2332 if (strcmp(tokens[0], "match") != 0) {
2333 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2337 if (strcmp(tokens[1], "acl") == 0) {
2338 if (n_tokens < 14) {
2339 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2343 m->match_type = TABLE_ACL;
2345 if (strcmp(tokens[2], "priority") != 0) {
2346 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2350 if (parser_read_uint32(&m->match.acl.priority,
2352 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2356 if (strcmp(tokens[4], "ipv4") == 0) {
2357 struct in_addr saddr, daddr;
2359 m->match.acl.ip_version = 1;
2361 if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2362 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2365 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2367 if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2368 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2371 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2372 } else if (strcmp(tokens[4], "ipv6") == 0) {
2373 struct in6_addr saddr, daddr;
2375 m->match.acl.ip_version = 0;
2377 if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2378 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2381 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2383 if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2384 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2387 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2389 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2394 if (parser_read_uint32(&m->match.acl.sa_depth,
2396 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2400 if (parser_read_uint32(&m->match.acl.da_depth,
2402 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2406 if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2407 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2411 if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2412 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2416 if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2417 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2421 if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2422 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2426 if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2427 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2431 m->match.acl.proto_mask = 0xff;
2436 if (strcmp(tokens[1], "array") == 0) {
2438 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2442 m->match_type = TABLE_ARRAY;
2444 if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2445 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2452 if (strcmp(tokens[1], "hash") == 0) {
2454 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2458 m->match_type = TABLE_HASH;
2460 if (strcmp(tokens[2], "raw") == 0) {
2461 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2464 snprintf(out, out_size, MSG_ARG_MISMATCH,
2469 if (parse_hex_string(tokens[3],
2470 m->match.hash.key, &key_size) != 0) {
2471 snprintf(out, out_size, MSG_ARG_INVALID, "key");
2478 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2479 struct pkt_key_ipv4_5tuple *ipv4 =
2480 (struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2481 struct in_addr saddr, daddr;
2486 snprintf(out, out_size, MSG_ARG_MISMATCH,
2491 if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2492 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2496 if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2497 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2501 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2502 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2506 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2507 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2511 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2512 snprintf(out, out_size, MSG_ARG_INVALID,
2517 ipv4->sa = saddr.s_addr;
2518 ipv4->da = daddr.s_addr;
2519 ipv4->sp = rte_cpu_to_be_16(sp);
2520 ipv4->dp = rte_cpu_to_be_16(dp);
2521 ipv4->proto = proto;
2524 } /* hash ipv4_5tuple */
2526 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2527 struct pkt_key_ipv6_5tuple *ipv6 =
2528 (struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2529 struct in6_addr saddr, daddr;
2534 snprintf(out, out_size, MSG_ARG_MISMATCH,
2539 if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2540 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2544 if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2545 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2549 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2550 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2554 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2555 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2559 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2560 snprintf(out, out_size, MSG_ARG_INVALID,
2565 memcpy(ipv6->sa, saddr.s6_addr, 16);
2566 memcpy(ipv6->da, daddr.s6_addr, 16);
2567 ipv6->sp = rte_cpu_to_be_16(sp);
2568 ipv6->dp = rte_cpu_to_be_16(dp);
2569 ipv6->proto = proto;
2572 } /* hash ipv6_5tuple */
2574 if (strcmp(tokens[2], "ipv4_addr") == 0) {
2575 struct pkt_key_ipv4_addr *ipv4_addr =
2576 (struct pkt_key_ipv4_addr *) m->match.hash.key;
2577 struct in_addr addr;
2580 snprintf(out, out_size, MSG_ARG_MISMATCH,
2585 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2586 snprintf(out, out_size, MSG_ARG_INVALID,
2591 ipv4_addr->addr = addr.s_addr;
2594 } /* hash ipv4_addr */
2596 if (strcmp(tokens[2], "ipv6_addr") == 0) {
2597 struct pkt_key_ipv6_addr *ipv6_addr =
2598 (struct pkt_key_ipv6_addr *) m->match.hash.key;
2599 struct in6_addr addr;
2602 snprintf(out, out_size, MSG_ARG_MISMATCH,
2607 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2608 snprintf(out, out_size, MSG_ARG_INVALID,
2613 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
2616 } /* hash ipv6_5tuple */
2618 if (strcmp(tokens[2], "qinq") == 0) {
2619 struct pkt_key_qinq *qinq =
2620 (struct pkt_key_qinq *) m->match.hash.key;
2621 uint16_t svlan, cvlan;
2624 snprintf(out, out_size, MSG_ARG_MISMATCH,
2629 if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
2631 snprintf(out, out_size, MSG_ARG_INVALID,
2636 if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
2638 snprintf(out, out_size, MSG_ARG_INVALID,
2643 qinq->svlan = rte_cpu_to_be_16(svlan);
2644 qinq->cvlan = rte_cpu_to_be_16(cvlan);
2649 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2653 if (strcmp(tokens[1], "lpm") == 0) {
2655 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2659 m->match_type = TABLE_LPM;
2661 if (strcmp(tokens[2], "ipv4") == 0) {
2662 struct in_addr addr;
2664 m->match.lpm.ip_version = 1;
2666 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2667 snprintf(out, out_size, MSG_ARG_INVALID,
2672 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
2673 } else if (strcmp(tokens[2], "ipv6") == 0) {
2674 struct in6_addr addr;
2676 m->match.lpm.ip_version = 0;
2678 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2679 snprintf(out, out_size, MSG_ARG_INVALID,
2684 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
2686 snprintf(out, out_size, MSG_ARG_MISMATCH,
2691 if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
2692 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
2699 snprintf(out, out_size, MSG_ARG_MISMATCH,
2700 "acl or array or hash or lpm");
2712 * | table <table_id>
2713 * [balance <out0> ... <out7>]
2715 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
2716 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
2717 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
2718 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
2719 * [tm subport <subport_id> pipe <pipe_id>]
2722 * | vlan <da> <sa> <pcp> <dei> <vid>
2723 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
2724 * | mpls unicast | multicast
2726 * label0 <label> <tc> <ttl>
2727 * [label1 <label> <tc> <ttl>
2728 * [label2 <label> <tc> <ttl>
2729 * [label3 <label> <tc> <ttl>]]]
2730 * | pppoe <da> <sa> <session_id>]
2731 * [nat ipv4 | ipv6 <addr> <port>]
2737 * <pa> ::= g | y | r | drop
2740 parse_table_action_fwd(char **tokens,
2742 struct table_rule_action *a)
2744 if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
2750 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
2751 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
2752 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2756 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
2759 if ((n_tokens < 2) ||
2760 parser_read_uint32(&id, tokens[1]))
2763 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
2765 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2769 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
2770 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
2771 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2775 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
2778 if ((n_tokens < 2) ||
2779 parser_read_uint32(&id, tokens[1]))
2782 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
2784 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
2792 parse_policer_action(char *token, enum rte_table_action_policer *a)
2794 if (strcmp(token, "g") == 0) {
2795 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
2799 if (strcmp(token, "y") == 0) {
2800 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
2804 if (strcmp(token, "r") == 0) {
2805 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
2809 if (strcmp(token, "drop") == 0) {
2810 *a = RTE_TABLE_ACTION_POLICER_DROP;
2818 parse_table_action_meter_tc(char **tokens,
2820 struct rte_table_action_mtr_tc_params *mtr)
2822 if ((n_tokens < 9) ||
2823 strcmp(tokens[0], "meter") ||
2824 parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
2825 strcmp(tokens[2], "policer") ||
2826 strcmp(tokens[3], "g") ||
2827 parse_policer_action(tokens[4], &mtr->policer[e_RTE_METER_GREEN]) ||
2828 strcmp(tokens[5], "y") ||
2829 parse_policer_action(tokens[6], &mtr->policer[e_RTE_METER_YELLOW]) ||
2830 strcmp(tokens[7], "r") ||
2831 parse_policer_action(tokens[8], &mtr->policer[e_RTE_METER_RED]))
2838 parse_table_action_meter(char **tokens,
2840 struct table_rule_action *a)
2842 if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
2848 if ((n_tokens < 10) ||
2849 strcmp(tokens[0], "tc0") ||
2850 (parse_table_action_meter_tc(tokens + 1,
2852 &a->mtr.mtr[0]) == 0))
2858 if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
2860 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
2864 if ((n_tokens < 30) ||
2865 (parse_table_action_meter_tc(tokens + 1,
2866 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
2867 strcmp(tokens[10], "tc2") ||
2868 (parse_table_action_meter_tc(tokens + 11,
2869 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
2870 strcmp(tokens[20], "tc3") ||
2871 (parse_table_action_meter_tc(tokens + 21,
2872 n_tokens - 21, &a->mtr.mtr[3]) == 0))
2875 a->mtr.tc_mask = 0xF;
2876 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
2877 return 1 + 10 + 3 * 10;
2881 parse_table_action_tm(char **tokens,
2883 struct table_rule_action *a)
2885 uint32_t subport_id, pipe_id;
2887 if ((n_tokens < 5) ||
2888 strcmp(tokens[0], "tm") ||
2889 strcmp(tokens[1], "subport") ||
2890 parser_read_uint32(&subport_id, tokens[2]) ||
2891 strcmp(tokens[3], "pipe") ||
2892 parser_read_uint32(&pipe_id, tokens[4]))
2895 a->tm.subport_id = subport_id;
2896 a->tm.pipe_id = pipe_id;
2897 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
2902 parse_table_action_encap(char **tokens,
2904 struct table_rule_action *a)
2906 if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
2913 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
2914 if ((n_tokens < 3) ||
2915 parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
2916 parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
2919 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
2920 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2925 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
2926 uint32_t pcp, dei, vid;
2928 if ((n_tokens < 6) ||
2929 parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
2930 parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
2931 parser_read_uint32(&pcp, tokens[3]) ||
2933 parser_read_uint32(&dei, tokens[4]) ||
2935 parser_read_uint32(&vid, tokens[5]) ||
2939 a->encap.vlan.vlan.pcp = pcp & 0x7;
2940 a->encap.vlan.vlan.dei = dei & 0x1;
2941 a->encap.vlan.vlan.vid = vid & 0xFFF;
2942 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
2943 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2948 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
2949 uint32_t svlan_pcp, svlan_dei, svlan_vid;
2950 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
2952 if ((n_tokens < 9) ||
2953 parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
2954 parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
2955 parser_read_uint32(&svlan_pcp, tokens[3]) ||
2956 (svlan_pcp > 0x7) ||
2957 parser_read_uint32(&svlan_dei, tokens[4]) ||
2958 (svlan_dei > 0x1) ||
2959 parser_read_uint32(&svlan_vid, tokens[5]) ||
2960 (svlan_vid > 0xFFF) ||
2961 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
2962 (cvlan_pcp > 0x7) ||
2963 parser_read_uint32(&cvlan_dei, tokens[7]) ||
2964 (cvlan_dei > 0x1) ||
2965 parser_read_uint32(&cvlan_vid, tokens[8]) ||
2966 (cvlan_vid > 0xFFF))
2969 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
2970 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
2971 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
2972 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
2973 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
2974 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
2975 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
2976 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
2981 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
2982 uint32_t label, tc, ttl;
2987 if (strcmp(tokens[1], "unicast") == 0)
2988 a->encap.mpls.unicast = 1;
2989 else if (strcmp(tokens[1], "multicast") == 0)
2990 a->encap.mpls.unicast = 0;
2994 if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
2995 parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
2996 strcmp(tokens[4], "label0") ||
2997 parser_read_uint32(&label, tokens[5]) ||
2998 (label > 0xFFFFF) ||
2999 parser_read_uint32(&tc, tokens[6]) ||
3001 parser_read_uint32(&ttl, tokens[7]) ||
3005 a->encap.mpls.mpls[0].label = label;
3006 a->encap.mpls.mpls[0].tc = tc;
3007 a->encap.mpls.mpls[0].ttl = ttl;
3012 if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3013 a->encap.mpls.mpls_count = 1;
3014 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3015 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3019 if ((n_tokens < 4) ||
3020 parser_read_uint32(&label, tokens[1]) ||
3021 (label > 0xFFFFF) ||
3022 parser_read_uint32(&tc, tokens[2]) ||
3024 parser_read_uint32(&ttl, tokens[3]) ||
3028 a->encap.mpls.mpls[1].label = label;
3029 a->encap.mpls.mpls[1].tc = tc;
3030 a->encap.mpls.mpls[1].ttl = ttl;
3035 if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3036 a->encap.mpls.mpls_count = 2;
3037 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3038 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3042 if ((n_tokens < 4) ||
3043 parser_read_uint32(&label, tokens[1]) ||
3044 (label > 0xFFFFF) ||
3045 parser_read_uint32(&tc, tokens[2]) ||
3047 parser_read_uint32(&ttl, tokens[3]) ||
3051 a->encap.mpls.mpls[2].label = label;
3052 a->encap.mpls.mpls[2].tc = tc;
3053 a->encap.mpls.mpls[2].ttl = ttl;
3058 if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3059 a->encap.mpls.mpls_count = 3;
3060 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3061 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3062 return 1 + 8 + 4 + 4;
3065 if ((n_tokens < 4) ||
3066 parser_read_uint32(&label, tokens[1]) ||
3067 (label > 0xFFFFF) ||
3068 parser_read_uint32(&tc, tokens[2]) ||
3070 parser_read_uint32(&ttl, tokens[3]) ||
3074 a->encap.mpls.mpls[3].label = label;
3075 a->encap.mpls.mpls[3].tc = tc;
3076 a->encap.mpls.mpls[3].ttl = ttl;
3078 a->encap.mpls.mpls_count = 4;
3079 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3080 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3081 return 1 + 8 + 4 + 4 + 4;
3085 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3086 if ((n_tokens < 4) ||
3087 parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3088 parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3089 parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3093 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3094 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3102 parse_table_action_nat(char **tokens,
3104 struct table_rule_action *a)
3106 if ((n_tokens < 4) ||
3107 strcmp(tokens[0], "nat"))
3110 if (strcmp(tokens[1], "ipv4") == 0) {
3111 struct in_addr addr;
3114 if (parse_ipv4_addr(tokens[2], &addr) ||
3115 parser_read_uint16(&port, tokens[3]))
3118 a->nat.ip_version = 1;
3119 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3121 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3125 if (strcmp(tokens[1], "ipv6") == 0) {
3126 struct in6_addr addr;
3129 if (parse_ipv6_addr(tokens[2], &addr) ||
3130 parser_read_uint16(&port, tokens[3]))
3133 a->nat.ip_version = 0;
3134 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3136 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3144 parse_table_action_ttl(char **tokens,
3146 struct table_rule_action *a)
3148 if ((n_tokens < 2) ||
3149 strcmp(tokens[0], "ttl"))
3152 if (strcmp(tokens[1], "dec") == 0)
3153 a->ttl.decrement = 1;
3154 else if (strcmp(tokens[1], "keep") == 0)
3155 a->ttl.decrement = 0;
3159 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3164 parse_table_action_stats(char **tokens,
3166 struct table_rule_action *a)
3168 if ((n_tokens < 1) ||
3169 strcmp(tokens[0], "stats"))
3172 a->stats.n_packets = 0;
3173 a->stats.n_bytes = 0;
3174 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3179 parse_table_action_time(char **tokens,
3181 struct table_rule_action *a)
3183 if ((n_tokens < 1) ||
3184 strcmp(tokens[0], "time"))
3187 a->time.time = rte_rdtsc();
3188 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3193 parse_table_action(char **tokens,
3197 struct table_rule_action *a)
3199 uint32_t n_tokens0 = n_tokens;
3201 memset(a, 0, sizeof(*a));
3203 if ((n_tokens < 2) ||
3204 strcmp(tokens[0], "action"))
3210 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
3213 n = parse_table_action_fwd(tokens, n_tokens, a);
3215 snprintf(out, out_size, MSG_ARG_INVALID,
3224 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
3227 n = parse_table_action_meter(tokens, n_tokens, a);
3229 snprintf(out, out_size, MSG_ARG_INVALID,
3238 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
3241 n = parse_table_action_tm(tokens, n_tokens, a);
3243 snprintf(out, out_size, MSG_ARG_INVALID,
3252 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
3255 n = parse_table_action_encap(tokens, n_tokens, a);
3257 snprintf(out, out_size, MSG_ARG_INVALID,
3266 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
3269 n = parse_table_action_nat(tokens, n_tokens, a);
3271 snprintf(out, out_size, MSG_ARG_INVALID,
3280 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
3283 n = parse_table_action_ttl(tokens, n_tokens, a);
3285 snprintf(out, out_size, MSG_ARG_INVALID,
3294 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
3297 n = parse_table_action_stats(tokens, n_tokens, a);
3299 snprintf(out, out_size, MSG_ARG_INVALID,
3308 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
3311 n = parse_table_action_time(tokens, n_tokens, a);
3313 snprintf(out, out_size, MSG_ARG_INVALID,
3322 if (n_tokens0 - n_tokens == 1) {
3323 snprintf(out, out_size, MSG_ARG_INVALID, "action");
3327 return n_tokens0 - n_tokens;
3331 * pipeline <pipeline_name> table <table_id> rule add
3333 * action <table_action>
3336 cmd_pipeline_table_rule_add(char **tokens,
3341 struct table_rule_match m;
3342 struct table_rule_action a;
3343 char *pipeline_name;
3345 uint32_t table_id, t0, n_tokens_parsed;
3349 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3353 pipeline_name = tokens[1];
3355 if (strcmp(tokens[2], "table") != 0) {
3356 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
3360 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
3361 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3365 if (strcmp(tokens[4], "rule") != 0) {
3366 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
3370 if (strcmp(tokens[5], "add") != 0) {
3371 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
3378 n_tokens_parsed = parse_match(tokens + t0,
3383 if (n_tokens_parsed == 0)
3385 t0 += n_tokens_parsed;
3388 n_tokens_parsed = parse_table_action(tokens + t0,
3393 if (n_tokens_parsed == 0)
3395 t0 += n_tokens_parsed;
3397 if (t0 != n_tokens) {
3398 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
3402 status = pipeline_table_rule_add(pipeline_name, table_id,
3405 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3411 * pipeline <pipeline_name> table <table_id> rule add
3419 * | table <table_id>
3422 cmd_pipeline_table_rule_add_default(char **tokens,
3427 struct table_rule_action action;
3429 char *pipeline_name;
3433 if ((n_tokens != 11) && (n_tokens != 12)) {
3434 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3438 pipeline_name = tokens[1];
3440 if (strcmp(tokens[2], "table") != 0) {
3441 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
3445 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
3446 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3450 if (strcmp(tokens[4], "rule") != 0) {
3451 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
3455 if (strcmp(tokens[5], "add") != 0) {
3456 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
3460 if (strcmp(tokens[6], "match") != 0) {
3461 snprintf(out, out_size, MSG_ARG_INVALID, "match");
3465 if (strcmp(tokens[7], "default") != 0) {
3466 snprintf(out, out_size, MSG_ARG_INVALID, "default");
3470 if (strcmp(tokens[8], "action") != 0) {
3471 snprintf(out, out_size, MSG_ARG_INVALID, "action");
3475 if (strcmp(tokens[9], "fwd") != 0) {
3476 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
3480 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
3482 if (strcmp(tokens[10], "drop") == 0) {
3483 if (n_tokens != 11) {
3484 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3488 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
3489 } else if (strcmp(tokens[10], "port") == 0) {
3492 if (n_tokens != 12) {
3493 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3497 if (parser_read_uint32(&id, tokens[11]) != 0) {
3498 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
3502 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
3504 } else if (strcmp(tokens[10], "meta") == 0) {
3505 if (n_tokens != 11) {
3506 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3510 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3511 } else if (strcmp(tokens[10], "table") == 0) {
3514 if (n_tokens != 12) {
3515 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3519 if (parser_read_uint32(&id, tokens[11]) != 0) {
3520 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
3524 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
3527 snprintf(out, out_size, MSG_ARG_INVALID,
3528 "drop or port or meta or table");
3532 status = pipeline_table_rule_add_default(pipeline_name,
3537 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3543 * thread <thread_id> pipeline <pipeline_name> enable
3546 cmd_thread_pipeline_enable(char **tokens,
3551 char *pipeline_name;
3555 if (n_tokens != 5) {
3556 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3560 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
3561 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
3565 if (strcmp(tokens[2], "pipeline") != 0) {
3566 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
3570 pipeline_name = tokens[3];
3572 if (strcmp(tokens[4], "enable") != 0) {
3573 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
3577 status = thread_pipeline_enable(thread_id, pipeline_name);
3579 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
3585 * thread <thread_id> pipeline <pipeline_name> disable
3588 cmd_thread_pipeline_disable(char **tokens,
3593 char *pipeline_name;
3597 if (n_tokens != 5) {
3598 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3602 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
3603 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
3607 if (strcmp(tokens[2], "pipeline") != 0) {
3608 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
3612 pipeline_name = tokens[3];
3614 if (strcmp(tokens[4], "disable") != 0) {
3615 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
3619 status = thread_pipeline_disable(thread_id, pipeline_name);
3621 snprintf(out, out_size, MSG_CMD_FAIL,
3622 "thread pipeline disable");
3628 cli_process(char *in, char *out, size_t out_size)
3630 char *tokens[CMD_MAX_TOKENS];
3631 uint32_t n_tokens = RTE_DIM(tokens);
3637 status = parse_tokenize_string(in, tokens, &n_tokens);
3639 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
3646 if (strcmp(tokens[0], "mempool") == 0) {
3647 cmd_mempool(tokens, n_tokens, out, out_size);
3651 if (strcmp(tokens[0], "link") == 0) {
3652 cmd_link(tokens, n_tokens, out, out_size);
3656 if (strcmp(tokens[0], "swq") == 0) {
3657 cmd_swq(tokens, n_tokens, out, out_size);
3661 if (strcmp(tokens[0], "tmgr") == 0) {
3662 if ((n_tokens >= 3) &&
3663 (strcmp(tokens[1], "subport") == 0) &&
3664 (strcmp(tokens[2], "profile") == 0)) {
3665 cmd_tmgr_subport_profile(tokens, n_tokens,
3670 if ((n_tokens >= 3) &&
3671 (strcmp(tokens[1], "pipe") == 0) &&
3672 (strcmp(tokens[2], "profile") == 0)) {
3673 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
3677 if ((n_tokens >= 5) &&
3678 (strcmp(tokens[2], "subport") == 0) &&
3679 (strcmp(tokens[4], "profile") == 0)) {
3680 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
3684 if ((n_tokens >= 5) &&
3685 (strcmp(tokens[2], "subport") == 0) &&
3686 (strcmp(tokens[4], "pipe") == 0)) {
3687 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
3691 cmd_tmgr(tokens, n_tokens, out, out_size);
3695 if (strcmp(tokens[0], "tap") == 0) {
3696 cmd_tap(tokens, n_tokens, out, out_size);
3700 if (strcmp(tokens[0], "kni") == 0) {
3701 cmd_kni(tokens, n_tokens, out, out_size);
3705 if (strcmp(tokens[0], "port") == 0) {
3706 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
3710 if (strcmp(tokens[0], "table") == 0) {
3711 cmd_table_action_profile(tokens, n_tokens, out, out_size);
3715 if (strcmp(tokens[0], "pipeline") == 0) {
3716 if ((n_tokens >= 3) &&
3717 (strcmp(tokens[2], "period") == 0)) {
3718 cmd_pipeline(tokens, n_tokens, out, out_size);
3722 if ((n_tokens >= 5) &&
3723 (strcmp(tokens[2], "port") == 0) &&
3724 (strcmp(tokens[3], "in") == 0) &&
3725 (strcmp(tokens[4], "bsz") == 0)) {
3726 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
3730 if ((n_tokens >= 5) &&
3731 (strcmp(tokens[2], "port") == 0) &&
3732 (strcmp(tokens[3], "out") == 0) &&
3733 (strcmp(tokens[4], "bsz") == 0)) {
3734 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
3738 if ((n_tokens >= 4) &&
3739 (strcmp(tokens[2], "table") == 0) &&
3740 (strcmp(tokens[3], "match") == 0)) {
3741 cmd_pipeline_table(tokens, n_tokens, out, out_size);
3745 if ((n_tokens >= 6) &&
3746 (strcmp(tokens[2], "port") == 0) &&
3747 (strcmp(tokens[3], "in") == 0) &&
3748 (strcmp(tokens[5], "table") == 0)) {
3749 cmd_pipeline_port_in_table(tokens, n_tokens,
3754 if ((n_tokens >= 6) &&
3755 (strcmp(tokens[2], "port") == 0) &&
3756 (strcmp(tokens[3], "in") == 0) &&
3757 (strcmp(tokens[5], "stats") == 0)) {
3758 cmd_pipeline_port_in_stats(tokens, n_tokens,
3763 if ((n_tokens >= 6) &&
3764 (strcmp(tokens[2], "port") == 0) &&
3765 (strcmp(tokens[3], "in") == 0) &&
3766 (strcmp(tokens[5], "enable") == 0)) {
3767 cmd_pipeline_port_in_enable(tokens, n_tokens,
3772 if ((n_tokens >= 6) &&
3773 (strcmp(tokens[2], "port") == 0) &&
3774 (strcmp(tokens[3], "in") == 0) &&
3775 (strcmp(tokens[5], "disable") == 0)) {
3776 cmd_pipeline_port_in_disable(tokens, n_tokens,
3781 if ((n_tokens >= 6) &&
3782 (strcmp(tokens[2], "port") == 0) &&
3783 (strcmp(tokens[3], "out") == 0) &&
3784 (strcmp(tokens[5], "stats") == 0)) {
3785 cmd_pipeline_port_out_stats(tokens, n_tokens,
3790 if ((n_tokens >= 5) &&
3791 (strcmp(tokens[2], "table") == 0) &&
3792 (strcmp(tokens[4], "stats") == 0)) {
3793 cmd_pipeline_table_stats(tokens, n_tokens,
3798 if ((n_tokens >= 7) &&
3799 (strcmp(tokens[2], "table") == 0) &&
3800 (strcmp(tokens[4], "rule") == 0) &&
3801 (strcmp(tokens[5], "add") == 0) &&
3802 (strcmp(tokens[6], "match") == 0)) {
3803 if ((n_tokens >= 8) &&
3804 (strcmp(tokens[7], "default") == 0)) {
3805 cmd_pipeline_table_rule_add_default(tokens,
3806 n_tokens, out, out_size);
3810 cmd_pipeline_table_rule_add(tokens, n_tokens,
3816 if (strcmp(tokens[0], "thread") == 0) {
3817 if ((n_tokens >= 5) &&
3818 (strcmp(tokens[4], "enable") == 0)) {
3819 cmd_thread_pipeline_enable(tokens, n_tokens,
3824 if ((n_tokens >= 5) &&
3825 (strcmp(tokens[4], "disable") == 0)) {
3826 cmd_thread_pipeline_disable(tokens, n_tokens,
3832 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
3836 cli_script_process(const char *file_name,
3837 size_t msg_in_len_max,
3838 size_t msg_out_len_max)
3840 char *msg_in = NULL, *msg_out = NULL;
3843 /* Check input arguments */
3844 if ((file_name == NULL) ||
3845 (strlen(file_name) == 0) ||
3846 (msg_in_len_max == 0) ||
3847 (msg_out_len_max == 0))
3850 msg_in = malloc(msg_in_len_max + 1);
3851 msg_out = malloc(msg_out_len_max + 1);
3852 if ((msg_in == NULL) ||
3853 (msg_out == NULL)) {
3859 /* Open input file */
3860 f = fopen(file_name, "r");
3869 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
3872 printf("%s", msg_in);
3879 if (strlen(msg_out))
3880 printf("%s", msg_out);