1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include <rte_common.h>
11 #include <rte_cycles.h>
12 #include <rte_ethdev.h>
16 #include "cryptodev.h"
27 #ifndef CMD_MAX_TOKENS
28 #define CMD_MAX_TOKENS 256
31 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
32 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
33 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
34 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
35 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
36 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
37 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
38 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
39 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
40 #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
41 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
46 if ((strlen(in) && index("!#%;", in[0])) ||
47 (strncmp(in, "//", 2) == 0) ||
48 (strncmp(in, "--", 2) == 0))
54 static const char cmd_mempool_help[] =
55 "mempool <mempool_name>\n"
56 " buffer <buffer_size>\n"
58 " cache <cache_size>\n"
62 cmd_mempool(char **tokens,
67 struct mempool_params p;
69 struct mempool *mempool;
72 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
78 if (strcmp(tokens[2], "buffer") != 0) {
79 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
83 if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
84 snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
88 if (strcmp(tokens[4], "pool") != 0) {
89 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
93 if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
94 snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
98 if (strcmp(tokens[6], "cache") != 0) {
99 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
103 if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
104 snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
108 if (strcmp(tokens[8], "cpu") != 0) {
109 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
113 if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
114 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
118 mempool = mempool_create(name, &p);
119 if (mempool == NULL) {
120 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
125 static const char cmd_link_help[] =
127 " dev <device_name> | port <port_id>\n"
128 " rxq <n_queues> <queue_size> <mempool_name>\n"
129 " txq <n_queues> <queue_size>\n"
130 " promiscuous on | off\n"
131 " [rss <qid_0> ... <qid_n>]\n";
134 cmd_link(char **tokens,
139 struct link_params p;
140 struct link_params_rss rss;
144 memset(&p, 0, sizeof(p));
146 if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
147 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
152 if (strcmp(tokens[2], "dev") == 0)
153 p.dev_name = tokens[3];
154 else if (strcmp(tokens[2], "port") == 0) {
157 if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
158 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
162 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
166 if (strcmp(tokens[4], "rxq") != 0) {
167 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
171 if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
172 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
175 if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
176 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
180 p.rx.mempool_name = tokens[7];
182 if (strcmp(tokens[8], "txq") != 0) {
183 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
187 if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
188 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
192 if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
193 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
197 if (strcmp(tokens[11], "promiscuous") != 0) {
198 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
202 if (strcmp(tokens[12], "on") == 0)
204 else if (strcmp(tokens[12], "off") == 0)
207 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
214 uint32_t queue_id, i;
216 if (strcmp(tokens[13], "rss") != 0) {
217 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
224 for (i = 14; i < n_tokens; i++) {
225 if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
226 snprintf(out, out_size, MSG_ARG_INVALID,
231 rss.queue_id[rss.n_queues] = queue_id;
236 link = link_create(name, &p);
238 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
243 /* Print the link stats and info */
245 print_link_info(struct link *link, char *out, size_t out_size)
247 struct rte_eth_stats stats;
248 struct rte_ether_addr mac_addr;
249 struct rte_eth_link eth_link;
253 memset(&stats, 0, sizeof(stats));
254 rte_eth_stats_get(link->port_id, &stats);
256 ret = rte_eth_macaddr_get(link->port_id, &mac_addr);
258 snprintf(out, out_size, "\n%s: MAC address get failed: %s",
259 link->name, rte_strerror(-ret));
263 ret = rte_eth_link_get(link->port_id, ð_link);
265 snprintf(out, out_size, "\n%s: link get failed: %s",
266 link->name, rte_strerror(-ret));
270 rte_eth_dev_get_mtu(link->port_id, &mtu);
272 snprintf(out, out_size,
274 "%s: flags=<%s> mtu %u\n"
275 "\tether %02X:%02X:%02X:%02X:%02X:%02X rxqueues %u txqueues %u\n"
276 "\tport# %u speed %u Mbps\n"
277 "\tRX packets %" PRIu64" bytes %" PRIu64"\n"
278 "\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n"
279 "\tTX packets %" PRIu64" bytes %" PRIu64"\n"
280 "\tTX errors %" PRIu64"\n",
282 eth_link.link_status == 0 ? "DOWN" : "UP",
284 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
285 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
286 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5],
302 * link show [<link_name>]
305 cmd_link_show(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
310 if (n_tokens != 2 && n_tokens != 3) {
311 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
316 link = link_next(NULL);
318 while (link != NULL) {
319 out_size = out_size - strlen(out);
320 out = &out[strlen(out)];
322 print_link_info(link, out, out_size);
323 link = link_next(link);
326 out_size = out_size - strlen(out);
327 out = &out[strlen(out)];
329 link_name = tokens[2];
330 link = link_find(link_name);
333 snprintf(out, out_size, MSG_ARG_INVALID,
334 "Link does not exist");
337 print_link_info(link, out, out_size);
341 static const char cmd_swq_help[] =
347 cmd_swq(char **tokens,
357 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
363 if (strcmp(tokens[2], "size") != 0) {
364 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
368 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
369 snprintf(out, out_size, MSG_ARG_INVALID, "size");
373 if (strcmp(tokens[4], "cpu") != 0) {
374 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
378 if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
379 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
383 swq = swq_create(name, &p);
385 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
390 static const char cmd_tmgr_subport_profile_help[] =
391 "tmgr subport profile\n"
392 " <tb_rate> <tb_size>\n"
393 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
394 " <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
395 " <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
399 cmd_tmgr_subport_profile(char **tokens,
404 struct rte_sched_subport_params p;
407 if (n_tokens != 19) {
408 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
412 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
413 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
417 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
418 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
422 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
423 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
424 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
428 if (parser_read_uint32(&p.tc_period, tokens[18]) != 0) {
429 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
433 status = tmgr_subport_profile_add(&p);
435 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
440 static const char cmd_tmgr_pipe_profile_help[] =
441 "tmgr pipe profile\n"
442 " <tb_rate> <tb_size>\n"
443 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
444 " <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
445 " <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
448 " <wrr_weight0..3>\n";
451 cmd_tmgr_pipe_profile(char **tokens,
456 struct rte_sched_pipe_params p;
459 if (n_tokens != 24) {
460 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
464 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
465 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
469 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
470 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
474 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
475 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
476 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
480 if (parser_read_uint32(&p.tc_period, tokens[18]) != 0) {
481 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
485 if (parser_read_uint8(&p.tc_ov_weight, tokens[19]) != 0) {
486 snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
490 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++)
491 if (parser_read_uint8(&p.wrr_weights[i], tokens[20 + i]) != 0) {
492 snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
496 status = tmgr_pipe_profile_add(&p);
498 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
503 static const char cmd_tmgr_help[] =
506 " spp <n_subports_per_port>\n"
507 " pps <n_pipes_per_subport>\n"
508 " qsize <qsize_tc0> <qsize_tc1> <qsize_tc2>"
509 " <qsize_tc3> <qsize_tc4> <qsize_tc5> <qsize_tc6>"
510 " <qsize_tc7> <qsize_tc8> <qsize_tc9> <qsize_tc10>"
511 " <qsize_tc11> <qsize_tc12>\n"
512 " fo <frame_overhead>\n"
517 cmd_tmgr(char **tokens,
522 struct tmgr_port_params p;
524 struct tmgr_port *tmgr_port;
527 if (n_tokens != 28) {
528 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
534 if (strcmp(tokens[2], "rate") != 0) {
535 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
539 if (parser_read_uint32(&p.rate, tokens[3]) != 0) {
540 snprintf(out, out_size, MSG_ARG_INVALID, "rate");
544 if (strcmp(tokens[4], "spp") != 0) {
545 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
549 if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
550 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
554 if (strcmp(tokens[6], "pps") != 0) {
555 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
559 if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
560 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
564 if (strcmp(tokens[8], "qsize") != 0) {
565 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "qsize");
569 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
570 if (parser_read_uint16(&p.qsize[i], tokens[9 + i]) != 0) {
571 snprintf(out, out_size, MSG_ARG_INVALID, "qsize");
575 if (strcmp(tokens[22], "fo") != 0) {
576 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
580 if (parser_read_uint32(&p.frame_overhead, tokens[23]) != 0) {
581 snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
585 if (strcmp(tokens[24], "mtu") != 0) {
586 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
590 if (parser_read_uint32(&p.mtu, tokens[25]) != 0) {
591 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
595 if (strcmp(tokens[26], "cpu") != 0) {
596 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
600 if (parser_read_uint32(&p.cpu_id, tokens[27]) != 0) {
601 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
605 tmgr_port = tmgr_port_create(name, &p);
606 if (tmgr_port == NULL) {
607 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
612 static const char cmd_tmgr_subport_help[] =
613 "tmgr <tmgr_name> subport <subport_id>\n"
614 " profile <subport_profile_id>\n";
617 cmd_tmgr_subport(char **tokens,
622 uint32_t subport_id, subport_profile_id;
627 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
633 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
634 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
638 if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
639 snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
643 status = tmgr_subport_config(name, subport_id, subport_profile_id);
645 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
651 static const char cmd_tmgr_subport_pipe_help[] =
652 "tmgr <tmgr_name> subport <subport_id> pipe\n"
653 " from <pipe_id_first> to <pipe_id_last>\n"
654 " profile <pipe_profile_id>\n";
657 cmd_tmgr_subport_pipe(char **tokens,
662 uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
666 if (n_tokens != 11) {
667 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
673 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
674 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
678 if (strcmp(tokens[4], "pipe") != 0) {
679 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
683 if (strcmp(tokens[5], "from") != 0) {
684 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
688 if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
689 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
693 if (strcmp(tokens[7], "to") != 0) {
694 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
698 if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
699 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
703 if (strcmp(tokens[9], "profile") != 0) {
704 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
708 if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
709 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
713 status = tmgr_pipe_config(name, subport_id, pipe_id_first,
714 pipe_id_last, pipe_profile_id);
716 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
722 static const char cmd_tap_help[] =
726 cmd_tap(char **tokens,
735 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
741 tap = tap_create(name);
743 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
748 static const char cmd_kni_help[] =
750 " link <link_name>\n"
751 " mempool <mempool_name>\n"
752 " [thread <thread_id>]\n";
755 cmd_kni(char **tokens,
764 memset(&p, 0, sizeof(p));
765 if ((n_tokens != 6) && (n_tokens != 8)) {
766 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
772 if (strcmp(tokens[2], "link") != 0) {
773 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
777 p.link_name = tokens[3];
779 if (strcmp(tokens[4], "mempool") != 0) {
780 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
784 p.mempool_name = tokens[5];
787 if (strcmp(tokens[6], "thread") != 0) {
788 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
792 if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
793 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
801 kni = kni_create(name, &p);
803 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
808 static const char cmd_cryptodev_help[] =
809 "cryptodev <cryptodev_name>\n"
810 " dev <device_name> | dev_id <device_id>\n"
811 " queue <n_queues> <queue_size>\n"
812 " max_sessions <n_sessions>";
815 cmd_cryptodev(char **tokens,
820 struct cryptodev_params params;
823 memset(¶ms, 0, sizeof(params));
825 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
831 if (strcmp(tokens[2], "dev") == 0)
832 params.dev_name = tokens[3];
833 else if (strcmp(tokens[2], "dev_id") == 0) {
834 if (parser_read_uint32(¶ms.dev_id, tokens[3]) < 0) {
835 snprintf(out, out_size, MSG_ARG_INVALID,
840 snprintf(out, out_size, MSG_ARG_INVALID,
845 if (strcmp(tokens[4], "queue")) {
846 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
851 if (parser_read_uint32(¶ms.n_queues, tokens[5]) < 0) {
852 snprintf(out, out_size, MSG_ARG_INVALID,
857 if (parser_read_uint32(¶ms.queue_size, tokens[6]) < 0) {
858 snprintf(out, out_size, MSG_ARG_INVALID,
863 if (strcmp(tokens[7], "max_sessions")) {
864 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
869 if (parser_read_uint32(¶ms.session_pool_size, tokens[8]) < 0) {
870 snprintf(out, out_size, MSG_ARG_INVALID,
875 if (cryptodev_create(name, ¶ms) == NULL) {
876 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
881 static const char cmd_port_in_action_profile_help[] =
882 "port in action profile <profile_name>\n"
883 " [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]\n"
884 " [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]\n";
887 cmd_port_in_action_profile(char **tokens,
892 struct port_in_action_profile_params p;
893 struct port_in_action_profile *ap;
897 memset(&p, 0, sizeof(p));
900 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
904 if (strcmp(tokens[1], "in") != 0) {
905 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
909 if (strcmp(tokens[2], "action") != 0) {
910 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
914 if (strcmp(tokens[3], "profile") != 0) {
915 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
923 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
926 if (n_tokens < t0 + 10) {
927 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
931 if (strcmp(tokens[t0 + 1], "match") == 0)
932 p.fltr.filter_on_match = 1;
933 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
934 p.fltr.filter_on_match = 0;
936 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
940 if (strcmp(tokens[t0 + 2], "offset") != 0) {
941 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
945 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
946 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
950 if (strcmp(tokens[t0 + 4], "mask") != 0) {
951 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
955 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
956 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
957 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
958 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
962 if (strcmp(tokens[t0 + 6], "key") != 0) {
963 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
967 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
968 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
969 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
970 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
974 if (strcmp(tokens[t0 + 8], "port") != 0) {
975 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
979 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
980 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
984 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
988 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
991 if (n_tokens < t0 + 22) {
992 snprintf(out, out_size, MSG_ARG_MISMATCH,
993 "port in action profile balance");
997 if (strcmp(tokens[t0 + 1], "offset") != 0) {
998 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1002 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1003 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1007 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1008 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1012 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1013 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1014 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1018 if (strcmp(tokens[t0 + 5], "port") != 0) {
1019 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1023 for (i = 0; i < 16; i++)
1024 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
1025 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1029 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
1033 if (t0 < n_tokens) {
1034 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1038 ap = port_in_action_profile_create(name, &p);
1040 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1046 static const char cmd_table_action_profile_help[] =
1047 "table action profile <profile_name>\n"
1049 " offset <ip_offset>\n"
1051 " [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]\n"
1052 " [meter srtcm | trtcm\n"
1054 " stats none | pkts | bytes | both]\n"
1055 " [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]\n"
1056 " [encap ether | vlan | qinq | mpls | pppoe | qinq_pppoe \n"
1057 " vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]\n"
1059 " proto udp | tcp]\n"
1060 " [ttl drop | fwd\n"
1061 " stats none | pkts]\n"
1062 " [stats pkts | bytes | both]\n"
1064 " [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
1069 cmd_table_action_profile(char **tokens,
1074 struct table_action_profile_params p;
1075 struct table_action_profile *ap;
1079 memset(&p, 0, sizeof(p));
1082 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1086 if (strcmp(tokens[1], "action") != 0) {
1087 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1091 if (strcmp(tokens[2], "profile") != 0) {
1092 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1098 if (strcmp(tokens[4], "ipv4") == 0)
1099 p.common.ip_version = 1;
1100 else if (strcmp(tokens[4], "ipv6") == 0)
1101 p.common.ip_version = 0;
1103 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1107 if (strcmp(tokens[5], "offset") != 0) {
1108 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1112 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
1113 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1117 if (strcmp(tokens[7], "fwd") != 0) {
1118 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1122 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1125 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
1126 if (n_tokens < t0 + 7) {
1127 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1131 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1132 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1136 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1137 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1141 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1142 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1146 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1147 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1148 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1152 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1153 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1157 if (parser_read_uint32(&p.lb.out_offset, tokens[t0 + 6]) != 0) {
1158 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1162 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1166 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
1167 if (n_tokens < t0 + 6) {
1168 snprintf(out, out_size, MSG_ARG_MISMATCH,
1169 "table action profile meter");
1173 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
1174 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1175 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
1176 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1178 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1183 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1184 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1188 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
1189 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1193 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1194 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1198 if (strcmp(tokens[t0 + 5], "none") == 0) {
1199 p.mtr.n_packets_enabled = 0;
1200 p.mtr.n_bytes_enabled = 0;
1201 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1202 p.mtr.n_packets_enabled = 1;
1203 p.mtr.n_bytes_enabled = 0;
1204 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1205 p.mtr.n_packets_enabled = 0;
1206 p.mtr.n_bytes_enabled = 1;
1207 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1208 p.mtr.n_packets_enabled = 1;
1209 p.mtr.n_bytes_enabled = 1;
1211 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1212 "none or pkts or bytes or both");
1216 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1220 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
1221 if (n_tokens < t0 + 5) {
1222 snprintf(out, out_size, MSG_ARG_MISMATCH,
1223 "table action profile tm");
1227 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1228 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1232 if (parser_read_uint32(&p.tm.n_subports_per_port,
1233 tokens[t0 + 2]) != 0) {
1234 snprintf(out, out_size, MSG_ARG_INVALID,
1235 "n_subports_per_port");
1239 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1240 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1244 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1245 tokens[t0 + 4]) != 0) {
1246 snprintf(out, out_size, MSG_ARG_INVALID,
1247 "n_pipes_per_subport");
1251 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1255 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1256 uint32_t n_extra_tokens = 0;
1258 if (n_tokens < t0 + 2) {
1259 snprintf(out, out_size, MSG_ARG_MISMATCH,
1260 "action profile encap");
1264 if (strcmp(tokens[t0 + 1], "ether") == 0)
1265 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1266 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1267 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1268 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1269 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1270 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1271 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1272 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1273 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1274 else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1275 if (n_tokens < t0 + 2 + 5) {
1276 snprintf(out, out_size, MSG_ARG_MISMATCH,
1277 "action profile encap vxlan");
1281 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1282 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1287 if (parser_read_uint32(&p.encap.vxlan.data_offset,
1288 tokens[t0 + 2 + 1]) != 0) {
1289 snprintf(out, out_size, MSG_ARG_INVALID,
1290 "vxlan: ether_offset");
1294 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1295 p.encap.vxlan.ip_version = 1;
1296 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1297 p.encap.vxlan.ip_version = 0;
1299 snprintf(out, out_size, MSG_ARG_INVALID,
1300 "vxlan: ipv4 or ipv6");
1304 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1305 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1310 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
1311 p.encap.vxlan.vlan = 1;
1312 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
1313 p.encap.vxlan.vlan = 0;
1315 snprintf(out, out_size, MSG_ARG_INVALID,
1316 "vxlan: on or off");
1320 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
1322 } else if (strcmp(tokens[t0 + 1], "qinq_pppoe") == 0)
1323 p.encap.encap_mask =
1324 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
1326 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1330 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1331 t0 += 2 + n_extra_tokens;
1334 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1335 if (n_tokens < t0 + 4) {
1336 snprintf(out, out_size, MSG_ARG_MISMATCH,
1337 "table action profile nat");
1341 if (strcmp(tokens[t0 + 1], "src") == 0)
1342 p.nat.source_nat = 1;
1343 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1344 p.nat.source_nat = 0;
1346 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1351 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1352 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1356 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1358 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1361 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1366 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1370 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1371 if (n_tokens < t0 + 4) {
1372 snprintf(out, out_size, MSG_ARG_MISMATCH,
1373 "table action profile ttl");
1377 if (strcmp(tokens[t0 + 1], "drop") == 0)
1379 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1382 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1387 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1388 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1392 if (strcmp(tokens[t0 + 3], "none") == 0)
1393 p.ttl.n_packets_enabled = 0;
1394 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1395 p.ttl.n_packets_enabled = 1;
1397 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1402 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1406 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1407 if (n_tokens < t0 + 2) {
1408 snprintf(out, out_size, MSG_ARG_MISMATCH,
1409 "table action profile stats");
1413 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1414 p.stats.n_packets_enabled = 1;
1415 p.stats.n_bytes_enabled = 0;
1416 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1417 p.stats.n_packets_enabled = 0;
1418 p.stats.n_bytes_enabled = 1;
1419 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1420 p.stats.n_packets_enabled = 1;
1421 p.stats.n_bytes_enabled = 1;
1423 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1424 "pkts or bytes or both");
1428 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1432 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1433 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1437 if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
1438 struct cryptodev *cryptodev;
1440 if (n_tokens < t0 + 5 ||
1441 strcmp(tokens[t0 + 1], "dev") ||
1442 strcmp(tokens[t0 + 3], "offset")) {
1443 snprintf(out, out_size, MSG_ARG_MISMATCH,
1444 "table action profile sym_crypto");
1448 cryptodev = cryptodev_find(tokens[t0 + 2]);
1449 if (cryptodev == NULL) {
1450 snprintf(out, out_size, MSG_ARG_INVALID,
1451 "table action profile sym_crypto");
1455 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
1457 if (parser_read_uint32(&p.sym_crypto.op_offset,
1458 tokens[t0 + 4]) != 0) {
1459 snprintf(out, out_size, MSG_ARG_INVALID,
1460 "table action profile sym_crypto");
1464 p.sym_crypto.mp_create = cryptodev->mp_create;
1465 p.sym_crypto.mp_init = cryptodev->mp_init;
1467 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
1472 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {
1473 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
1477 if ((t0 < n_tokens) && (strcmp(tokens[t0], "decap") == 0)) {
1478 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1482 if (t0 < n_tokens) {
1483 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1487 ap = table_action_profile_create(name, &p);
1489 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1494 static const char cmd_pipeline_help[] =
1495 "pipeline <pipeline_name>\n"
1496 " period <timer_period_ms>\n"
1497 " offset_port_id <offset_port_id>\n"
1501 cmd_pipeline(char **tokens,
1506 struct pipeline_params p;
1508 struct pipeline *pipeline;
1510 if (n_tokens != 8) {
1511 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1517 if (strcmp(tokens[2], "period") != 0) {
1518 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1522 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1523 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1527 if (strcmp(tokens[4], "offset_port_id") != 0) {
1528 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1532 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1533 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1537 if (strcmp(tokens[6], "cpu") != 0) {
1538 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1542 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1543 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1547 pipeline = pipeline_create(name, &p);
1548 if (pipeline == NULL) {
1549 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1554 static const char cmd_pipeline_port_in_help[] =
1555 "pipeline <pipeline_name> port in\n"
1556 " bsz <burst_size>\n"
1557 " link <link_name> rxq <queue_id>\n"
1558 " | swq <swq_name>\n"
1559 " | tmgr <tmgr_name>\n"
1560 " | tap <tap_name> mempool <mempool_name> mtu <mtu>\n"
1561 " | kni <kni_name>\n"
1562 " | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>\n"
1563 " | cryptodev <cryptodev_name> rxq <queue_id>\n"
1564 " [action <port_in_action_profile_name>]\n"
1568 cmd_pipeline_port_in(char **tokens,
1573 struct port_in_params p;
1574 char *pipeline_name;
1576 int enabled, status;
1579 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1583 pipeline_name = tokens[1];
1585 if (strcmp(tokens[2], "port") != 0) {
1586 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1590 if (strcmp(tokens[3], "in") != 0) {
1591 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1595 if (strcmp(tokens[4], "bsz") != 0) {
1596 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1600 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1601 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1607 if (strcmp(tokens[t0], "link") == 0) {
1608 if (n_tokens < t0 + 4) {
1609 snprintf(out, out_size, MSG_ARG_MISMATCH,
1610 "pipeline port in link");
1614 p.type = PORT_IN_RXQ;
1616 p.dev_name = tokens[t0 + 1];
1618 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1619 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1623 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1624 snprintf(out, out_size, MSG_ARG_INVALID,
1629 } else if (strcmp(tokens[t0], "swq") == 0) {
1630 if (n_tokens < t0 + 2) {
1631 snprintf(out, out_size, MSG_ARG_MISMATCH,
1632 "pipeline port in swq");
1636 p.type = PORT_IN_SWQ;
1638 p.dev_name = tokens[t0 + 1];
1641 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1642 if (n_tokens < t0 + 2) {
1643 snprintf(out, out_size, MSG_ARG_MISMATCH,
1644 "pipeline port in tmgr");
1648 p.type = PORT_IN_TMGR;
1650 p.dev_name = tokens[t0 + 1];
1653 } else if (strcmp(tokens[t0], "tap") == 0) {
1654 if (n_tokens < t0 + 6) {
1655 snprintf(out, out_size, MSG_ARG_MISMATCH,
1656 "pipeline port in tap");
1660 p.type = PORT_IN_TAP;
1662 p.dev_name = tokens[t0 + 1];
1664 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1665 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1670 p.tap.mempool_name = tokens[t0 + 3];
1672 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1673 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1678 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1679 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1684 } else if (strcmp(tokens[t0], "kni") == 0) {
1685 if (n_tokens < t0 + 2) {
1686 snprintf(out, out_size, MSG_ARG_MISMATCH,
1687 "pipeline port in kni");
1691 p.type = PORT_IN_KNI;
1693 p.dev_name = tokens[t0 + 1];
1696 } else if (strcmp(tokens[t0], "source") == 0) {
1697 if (n_tokens < t0 + 6) {
1698 snprintf(out, out_size, MSG_ARG_MISMATCH,
1699 "pipeline port in source");
1703 p.type = PORT_IN_SOURCE;
1707 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1708 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1713 p.source.mempool_name = tokens[t0 + 2];
1715 if (strcmp(tokens[t0 + 3], "file") != 0) {
1716 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1721 p.source.file_name = tokens[t0 + 4];
1723 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1724 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1729 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1730 snprintf(out, out_size, MSG_ARG_INVALID,
1736 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
1737 if (n_tokens < t0 + 3) {
1738 snprintf(out, out_size, MSG_ARG_MISMATCH,
1739 "pipeline port in cryptodev");
1743 p.type = PORT_IN_CRYPTODEV;
1745 p.dev_name = tokens[t0 + 1];
1746 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1747 snprintf(out, out_size, MSG_ARG_INVALID,
1752 p.cryptodev.arg_callback = NULL;
1753 p.cryptodev.f_callback = NULL;
1757 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1761 p.action_profile_name = NULL;
1762 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1763 if (n_tokens < t0 + 2) {
1764 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1768 p.action_profile_name = tokens[t0 + 1];
1774 if ((n_tokens > t0) &&
1775 (strcmp(tokens[t0], "disabled") == 0)) {
1781 if (n_tokens != t0) {
1782 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1786 status = pipeline_port_in_create(pipeline_name,
1789 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1794 static const char cmd_pipeline_port_out_help[] =
1795 "pipeline <pipeline_name> port out\n"
1796 " bsz <burst_size>\n"
1797 " link <link_name> txq <txq_id>\n"
1798 " | swq <swq_name>\n"
1799 " | tmgr <tmgr_name>\n"
1800 " | tap <tap_name>\n"
1801 " | kni <kni_name>\n"
1802 " | sink [file <file_name> pkts <max_n_pkts>]\n"
1803 " | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>\n";
1806 cmd_pipeline_port_out(char **tokens,
1811 struct port_out_params p;
1812 char *pipeline_name;
1815 memset(&p, 0, sizeof(p));
1818 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1822 pipeline_name = tokens[1];
1824 if (strcmp(tokens[2], "port") != 0) {
1825 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1829 if (strcmp(tokens[3], "out") != 0) {
1830 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1834 if (strcmp(tokens[4], "bsz") != 0) {
1835 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1839 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1840 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1844 if (strcmp(tokens[6], "link") == 0) {
1845 if (n_tokens != 10) {
1846 snprintf(out, out_size, MSG_ARG_MISMATCH,
1847 "pipeline port out link");
1851 p.type = PORT_OUT_TXQ;
1853 p.dev_name = tokens[7];
1855 if (strcmp(tokens[8], "txq") != 0) {
1856 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1860 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1861 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1864 } else if (strcmp(tokens[6], "swq") == 0) {
1865 if (n_tokens != 8) {
1866 snprintf(out, out_size, MSG_ARG_MISMATCH,
1867 "pipeline port out swq");
1871 p.type = PORT_OUT_SWQ;
1873 p.dev_name = tokens[7];
1874 } else if (strcmp(tokens[6], "tmgr") == 0) {
1875 if (n_tokens != 8) {
1876 snprintf(out, out_size, MSG_ARG_MISMATCH,
1877 "pipeline port out tmgr");
1881 p.type = PORT_OUT_TMGR;
1883 p.dev_name = tokens[7];
1884 } else if (strcmp(tokens[6], "tap") == 0) {
1885 if (n_tokens != 8) {
1886 snprintf(out, out_size, MSG_ARG_MISMATCH,
1887 "pipeline port out tap");
1891 p.type = PORT_OUT_TAP;
1893 p.dev_name = tokens[7];
1894 } else if (strcmp(tokens[6], "kni") == 0) {
1895 if (n_tokens != 8) {
1896 snprintf(out, out_size, MSG_ARG_MISMATCH,
1897 "pipeline port out kni");
1901 p.type = PORT_OUT_KNI;
1903 p.dev_name = tokens[7];
1904 } else if (strcmp(tokens[6], "sink") == 0) {
1905 if ((n_tokens != 7) && (n_tokens != 11)) {
1906 snprintf(out, out_size, MSG_ARG_MISMATCH,
1907 "pipeline port out sink");
1911 p.type = PORT_OUT_SINK;
1915 if (n_tokens == 7) {
1916 p.sink.file_name = NULL;
1917 p.sink.max_n_pkts = 0;
1919 if (strcmp(tokens[7], "file") != 0) {
1920 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1925 p.sink.file_name = tokens[8];
1927 if (strcmp(tokens[9], "pkts") != 0) {
1928 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1932 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1933 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1938 } else if (strcmp(tokens[6], "cryptodev") == 0) {
1939 if (n_tokens != 12) {
1940 snprintf(out, out_size, MSG_ARG_MISMATCH,
1941 "pipeline port out cryptodev");
1945 p.type = PORT_OUT_CRYPTODEV;
1947 p.dev_name = tokens[7];
1949 if (strcmp(tokens[8], "txq")) {
1950 snprintf(out, out_size, MSG_ARG_MISMATCH,
1951 "pipeline port out cryptodev");
1955 if (parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
1957 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1961 if (strcmp(tokens[10], "offset")) {
1962 snprintf(out, out_size, MSG_ARG_MISMATCH,
1963 "pipeline port out cryptodev");
1967 if (parser_read_uint32(&p.cryptodev.op_offset, tokens[11])
1969 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1973 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1977 status = pipeline_port_out_create(pipeline_name, &p);
1979 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1984 static const char cmd_pipeline_table_help[] =
1985 "pipeline <pipeline_name> table\n"
1989 " offset <ip_header_offset>\n"
1992 " offset <key_offset>\n"
1997 " mask <key_mask>\n"
1998 " offset <key_offset>\n"
1999 " buckets <n_buckets>\n"
2003 " offset <ip_header_offset>\n"
2006 " [action <table_action_profile_name>]\n";
2009 cmd_pipeline_table(char **tokens,
2014 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
2015 struct table_params p;
2016 char *pipeline_name;
2021 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2025 pipeline_name = tokens[1];
2027 if (strcmp(tokens[2], "table") != 0) {
2028 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2032 if (strcmp(tokens[3], "match") != 0) {
2033 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2038 if (strcmp(tokens[t0], "acl") == 0) {
2039 if (n_tokens < t0 + 6) {
2040 snprintf(out, out_size, MSG_ARG_MISMATCH,
2041 "pipeline table acl");
2045 p.match_type = TABLE_ACL;
2047 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2048 p.match.acl.ip_version = 1;
2049 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2050 p.match.acl.ip_version = 0;
2052 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2057 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2058 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2062 if (parser_read_uint32(&p.match.acl.ip_header_offset,
2063 tokens[t0 + 3]) != 0) {
2064 snprintf(out, out_size, MSG_ARG_INVALID,
2065 "ip_header_offset");
2069 if (strcmp(tokens[t0 + 4], "size") != 0) {
2070 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2074 if (parser_read_uint32(&p.match.acl.n_rules,
2075 tokens[t0 + 5]) != 0) {
2076 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2081 } else if (strcmp(tokens[t0], "array") == 0) {
2082 if (n_tokens < t0 + 5) {
2083 snprintf(out, out_size, MSG_ARG_MISMATCH,
2084 "pipeline table array");
2088 p.match_type = TABLE_ARRAY;
2090 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2091 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2095 if (parser_read_uint32(&p.match.array.key_offset,
2096 tokens[t0 + 2]) != 0) {
2097 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2101 if (strcmp(tokens[t0 + 3], "size") != 0) {
2102 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2106 if (parser_read_uint32(&p.match.array.n_keys,
2107 tokens[t0 + 4]) != 0) {
2108 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2113 } else if (strcmp(tokens[t0], "hash") == 0) {
2114 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2116 if (n_tokens < t0 + 12) {
2117 snprintf(out, out_size, MSG_ARG_MISMATCH,
2118 "pipeline table hash");
2122 p.match_type = TABLE_HASH;
2124 if (strcmp(tokens[t0 + 1], "ext") == 0)
2125 p.match.hash.extendable_bucket = 1;
2126 else if (strcmp(tokens[t0 + 1], "lru") == 0)
2127 p.match.hash.extendable_bucket = 0;
2129 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2134 if (strcmp(tokens[t0 + 2], "key") != 0) {
2135 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2139 if ((parser_read_uint32(&p.match.hash.key_size,
2140 tokens[t0 + 3]) != 0) ||
2141 (p.match.hash.key_size == 0) ||
2142 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
2143 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2147 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2148 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2152 if ((parse_hex_string(tokens[t0 + 5],
2153 key_mask, &key_mask_size) != 0) ||
2154 (key_mask_size != p.match.hash.key_size)) {
2155 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2158 p.match.hash.key_mask = key_mask;
2160 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2161 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2165 if (parser_read_uint32(&p.match.hash.key_offset,
2166 tokens[t0 + 7]) != 0) {
2167 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2171 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2172 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2176 if (parser_read_uint32(&p.match.hash.n_buckets,
2177 tokens[t0 + 9]) != 0) {
2178 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2182 if (strcmp(tokens[t0 + 10], "size") != 0) {
2183 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2187 if (parser_read_uint32(&p.match.hash.n_keys,
2188 tokens[t0 + 11]) != 0) {
2189 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2194 } else if (strcmp(tokens[t0], "lpm") == 0) {
2195 if (n_tokens < t0 + 6) {
2196 snprintf(out, out_size, MSG_ARG_MISMATCH,
2197 "pipeline table lpm");
2201 p.match_type = TABLE_LPM;
2203 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2204 p.match.lpm.key_size = 4;
2205 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2206 p.match.lpm.key_size = 16;
2208 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2213 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2214 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2218 if (parser_read_uint32(&p.match.lpm.key_offset,
2219 tokens[t0 + 3]) != 0) {
2220 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2224 if (strcmp(tokens[t0 + 4], "size") != 0) {
2225 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2229 if (parser_read_uint32(&p.match.lpm.n_rules,
2230 tokens[t0 + 5]) != 0) {
2231 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2236 } else if (strcmp(tokens[t0], "stub") == 0) {
2237 p.match_type = TABLE_STUB;
2241 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2245 p.action_profile_name = NULL;
2246 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
2247 if (n_tokens < t0 + 2) {
2248 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2252 p.action_profile_name = tokens[t0 + 1];
2257 if (n_tokens > t0) {
2258 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2262 status = pipeline_table_create(pipeline_name, &p);
2264 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2269 static const char cmd_pipeline_port_in_table_help[] =
2270 "pipeline <pipeline_name> port in <port_id> table <table_id>\n";
2273 cmd_pipeline_port_in_table(char **tokens,
2278 char *pipeline_name;
2279 uint32_t port_id, table_id;
2282 if (n_tokens != 7) {
2283 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2287 pipeline_name = tokens[1];
2289 if (strcmp(tokens[2], "port") != 0) {
2290 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2294 if (strcmp(tokens[3], "in") != 0) {
2295 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2299 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2300 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2304 if (strcmp(tokens[5], "table") != 0) {
2305 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2309 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
2310 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2314 status = pipeline_port_in_connect_to_table(pipeline_name,
2318 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2324 static const char cmd_pipeline_port_in_stats_help[] =
2325 "pipeline <pipeline_name> port in <port_id> stats read [clear]\n";
2327 #define MSG_PIPELINE_PORT_IN_STATS \
2328 "Pkts in: %" PRIu64 "\n" \
2329 "Pkts dropped by AH: %" PRIu64 "\n" \
2330 "Pkts dropped by other: %" PRIu64 "\n"
2333 cmd_pipeline_port_in_stats(char **tokens,
2338 struct rte_pipeline_port_in_stats stats;
2339 char *pipeline_name;
2343 if ((n_tokens != 7) && (n_tokens != 8)) {
2344 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2348 pipeline_name = tokens[1];
2350 if (strcmp(tokens[2], "port") != 0) {
2351 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2355 if (strcmp(tokens[3], "in") != 0) {
2356 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2360 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2361 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2365 if (strcmp(tokens[5], "stats") != 0) {
2366 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2370 if (strcmp(tokens[6], "read") != 0) {
2371 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2376 if (n_tokens == 8) {
2377 if (strcmp(tokens[7], "clear") != 0) {
2378 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2385 status = pipeline_port_in_stats_read(pipeline_name,
2390 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2394 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2395 stats.stats.n_pkts_in,
2396 stats.n_pkts_dropped_by_ah,
2397 stats.stats.n_pkts_drop);
2401 static const char cmd_pipeline_port_in_enable_help[] =
2402 "pipeline <pipeline_name> port in <port_id> enable\n";
2405 cmd_pipeline_port_in_enable(char **tokens,
2410 char *pipeline_name;
2414 if (n_tokens != 6) {
2415 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2419 pipeline_name = tokens[1];
2421 if (strcmp(tokens[2], "port") != 0) {
2422 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2426 if (strcmp(tokens[3], "in") != 0) {
2427 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2431 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2432 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2436 if (strcmp(tokens[5], "enable") != 0) {
2437 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2441 status = pipeline_port_in_enable(pipeline_name, port_id);
2443 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2449 static const char cmd_pipeline_port_in_disable_help[] =
2450 "pipeline <pipeline_name> port in <port_id> disable\n";
2453 cmd_pipeline_port_in_disable(char **tokens,
2458 char *pipeline_name;
2462 if (n_tokens != 6) {
2463 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2467 pipeline_name = tokens[1];
2469 if (strcmp(tokens[2], "port") != 0) {
2470 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2474 if (strcmp(tokens[3], "in") != 0) {
2475 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2479 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2480 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2484 if (strcmp(tokens[5], "disable") != 0) {
2485 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2489 status = pipeline_port_in_disable(pipeline_name, port_id);
2491 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2497 static const char cmd_pipeline_port_out_stats_help[] =
2498 "pipeline <pipeline_name> port out <port_id> stats read [clear]\n";
2500 #define MSG_PIPELINE_PORT_OUT_STATS \
2501 "Pkts in: %" PRIu64 "\n" \
2502 "Pkts dropped by AH: %" PRIu64 "\n" \
2503 "Pkts dropped by other: %" PRIu64 "\n"
2506 cmd_pipeline_port_out_stats(char **tokens,
2511 struct rte_pipeline_port_out_stats stats;
2512 char *pipeline_name;
2516 if ((n_tokens != 7) && (n_tokens != 8)) {
2517 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2521 pipeline_name = tokens[1];
2523 if (strcmp(tokens[2], "port") != 0) {
2524 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2528 if (strcmp(tokens[3], "out") != 0) {
2529 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2533 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2534 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2538 if (strcmp(tokens[5], "stats") != 0) {
2539 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2543 if (strcmp(tokens[6], "read") != 0) {
2544 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2549 if (n_tokens == 8) {
2550 if (strcmp(tokens[7], "clear") != 0) {
2551 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2558 status = pipeline_port_out_stats_read(pipeline_name,
2563 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2567 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2568 stats.stats.n_pkts_in,
2569 stats.n_pkts_dropped_by_ah,
2570 stats.stats.n_pkts_drop);
2574 static const char cmd_pipeline_table_stats_help[] =
2575 "pipeline <pipeline_name> table <table_id> stats read [clear]\n";
2577 #define MSG_PIPELINE_TABLE_STATS \
2578 "Pkts in: %" PRIu64 "\n" \
2579 "Pkts in with lookup miss: %" PRIu64 "\n" \
2580 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2581 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2582 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2583 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2586 cmd_pipeline_table_stats(char **tokens,
2591 struct rte_pipeline_table_stats stats;
2592 char *pipeline_name;
2596 if ((n_tokens != 6) && (n_tokens != 7)) {
2597 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2601 pipeline_name = tokens[1];
2603 if (strcmp(tokens[2], "table") != 0) {
2604 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2608 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2609 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2613 if (strcmp(tokens[4], "stats") != 0) {
2614 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2618 if (strcmp(tokens[5], "read") != 0) {
2619 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2624 if (n_tokens == 7) {
2625 if (strcmp(tokens[6], "clear") != 0) {
2626 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2633 status = pipeline_table_stats_read(pipeline_name,
2638 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2642 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2643 stats.stats.n_pkts_in,
2644 stats.stats.n_pkts_lookup_miss,
2645 stats.n_pkts_dropped_by_lkp_hit_ah,
2646 stats.n_pkts_dropped_lkp_hit,
2647 stats.n_pkts_dropped_by_lkp_miss_ah,
2648 stats.n_pkts_dropped_lkp_miss);
2656 * priority <priority>
2657 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2658 * <sp0> <sp1> <dp0> <dp1> <proto>
2662 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2663 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2664 * | ipv4_addr <addr>
2665 * | ipv6_addr <addr>
2666 * | qinq <svlan> <cvlan>
2668 * ipv4 | ipv6 <addr> <depth>
2670 struct pkt_key_qinq {
2671 uint16_t ethertype_svlan;
2673 uint16_t ethertype_cvlan;
2675 } __attribute__((__packed__));
2677 struct pkt_key_ipv4_5tuple {
2678 uint8_t time_to_live;
2680 uint16_t hdr_checksum;
2685 } __attribute__((__packed__));
2687 struct pkt_key_ipv6_5tuple {
2688 uint16_t payload_length;
2695 } __attribute__((__packed__));
2697 struct pkt_key_ipv4_addr {
2699 } __attribute__((__packed__));
2701 struct pkt_key_ipv6_addr {
2703 } __attribute__((__packed__));
2706 parse_match(char **tokens,
2710 struct table_rule_match *m)
2712 memset(m, 0, sizeof(*m));
2717 if (strcmp(tokens[0], "match") != 0) {
2718 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2722 if (strcmp(tokens[1], "acl") == 0) {
2723 if (n_tokens < 14) {
2724 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2728 m->match_type = TABLE_ACL;
2730 if (strcmp(tokens[2], "priority") != 0) {
2731 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2735 if (parser_read_uint32(&m->match.acl.priority,
2737 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2741 if (strcmp(tokens[4], "ipv4") == 0) {
2742 struct in_addr saddr, daddr;
2744 m->match.acl.ip_version = 1;
2746 if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2747 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2750 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2752 if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2753 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2756 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2757 } else if (strcmp(tokens[4], "ipv6") == 0) {
2758 struct in6_addr saddr, daddr;
2760 m->match.acl.ip_version = 0;
2762 if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2763 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2766 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2768 if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2769 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2772 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2774 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2779 if (parser_read_uint32(&m->match.acl.sa_depth,
2781 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2785 if (parser_read_uint32(&m->match.acl.da_depth,
2787 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2791 if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2792 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2796 if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2797 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2801 if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2802 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2806 if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2807 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2811 if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2812 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2816 m->match.acl.proto_mask = 0xff;
2821 if (strcmp(tokens[1], "array") == 0) {
2823 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2827 m->match_type = TABLE_ARRAY;
2829 if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2830 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2837 if (strcmp(tokens[1], "hash") == 0) {
2839 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2843 m->match_type = TABLE_HASH;
2845 if (strcmp(tokens[2], "raw") == 0) {
2846 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2849 snprintf(out, out_size, MSG_ARG_MISMATCH,
2854 if (parse_hex_string(tokens[3],
2855 m->match.hash.key, &key_size) != 0) {
2856 snprintf(out, out_size, MSG_ARG_INVALID, "key");
2863 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2864 struct pkt_key_ipv4_5tuple *ipv4 =
2865 (struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2866 struct in_addr saddr, daddr;
2871 snprintf(out, out_size, MSG_ARG_MISMATCH,
2876 if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2877 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2881 if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2882 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2886 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2887 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2891 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2892 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2896 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2897 snprintf(out, out_size, MSG_ARG_INVALID,
2902 ipv4->sa = saddr.s_addr;
2903 ipv4->da = daddr.s_addr;
2904 ipv4->sp = rte_cpu_to_be_16(sp);
2905 ipv4->dp = rte_cpu_to_be_16(dp);
2906 ipv4->proto = proto;
2909 } /* hash ipv4_5tuple */
2911 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2912 struct pkt_key_ipv6_5tuple *ipv6 =
2913 (struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2914 struct in6_addr saddr, daddr;
2919 snprintf(out, out_size, MSG_ARG_MISMATCH,
2924 if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2925 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2929 if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2930 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2934 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2935 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2939 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2940 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2944 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2945 snprintf(out, out_size, MSG_ARG_INVALID,
2950 memcpy(ipv6->sa, saddr.s6_addr, 16);
2951 memcpy(ipv6->da, daddr.s6_addr, 16);
2952 ipv6->sp = rte_cpu_to_be_16(sp);
2953 ipv6->dp = rte_cpu_to_be_16(dp);
2954 ipv6->proto = proto;
2957 } /* hash ipv6_5tuple */
2959 if (strcmp(tokens[2], "ipv4_addr") == 0) {
2960 struct pkt_key_ipv4_addr *ipv4_addr =
2961 (struct pkt_key_ipv4_addr *) m->match.hash.key;
2962 struct in_addr addr;
2965 snprintf(out, out_size, MSG_ARG_MISMATCH,
2970 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2971 snprintf(out, out_size, MSG_ARG_INVALID,
2976 ipv4_addr->addr = addr.s_addr;
2979 } /* hash ipv4_addr */
2981 if (strcmp(tokens[2], "ipv6_addr") == 0) {
2982 struct pkt_key_ipv6_addr *ipv6_addr =
2983 (struct pkt_key_ipv6_addr *) m->match.hash.key;
2984 struct in6_addr addr;
2987 snprintf(out, out_size, MSG_ARG_MISMATCH,
2992 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2993 snprintf(out, out_size, MSG_ARG_INVALID,
2998 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
3001 } /* hash ipv6_5tuple */
3003 if (strcmp(tokens[2], "qinq") == 0) {
3004 struct pkt_key_qinq *qinq =
3005 (struct pkt_key_qinq *) m->match.hash.key;
3006 uint16_t svlan, cvlan;
3009 snprintf(out, out_size, MSG_ARG_MISMATCH,
3014 if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
3016 snprintf(out, out_size, MSG_ARG_INVALID,
3021 if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3023 snprintf(out, out_size, MSG_ARG_INVALID,
3028 qinq->svlan = rte_cpu_to_be_16(svlan);
3029 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3034 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3038 if (strcmp(tokens[1], "lpm") == 0) {
3040 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3044 m->match_type = TABLE_LPM;
3046 if (strcmp(tokens[2], "ipv4") == 0) {
3047 struct in_addr addr;
3049 m->match.lpm.ip_version = 1;
3051 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
3052 snprintf(out, out_size, MSG_ARG_INVALID,
3057 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3058 } else if (strcmp(tokens[2], "ipv6") == 0) {
3059 struct in6_addr addr;
3061 m->match.lpm.ip_version = 0;
3063 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
3064 snprintf(out, out_size, MSG_ARG_INVALID,
3069 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3071 snprintf(out, out_size, MSG_ARG_MISMATCH,
3076 if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3077 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3084 snprintf(out, out_size, MSG_ARG_MISMATCH,
3085 "acl or array or hash or lpm");
3097 * | table <table_id>
3098 * [balance <out0> ... <out7>]
3100 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3101 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3102 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3103 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3104 * [tm subport <subport_id> pipe <pipe_id>]
3107 * | vlan <da> <sa> <pcp> <dei> <vid>
3108 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3109 * | qinq_pppoe <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid> <session_id>
3110 * | mpls unicast | multicast
3112 * label0 <label> <tc> <ttl>
3113 * [label1 <label> <tc> <ttl>
3114 * [label2 <label> <tc> <ttl>
3115 * [label3 <label> <tc> <ttl>]]]
3116 * | pppoe <da> <sa> <session_id>
3117 * | vxlan ether <da> <sa>
3118 * [vlan <pcp> <dei> <vid>]
3119 * ipv4 <sa> <da> <dscp> <ttl>
3120 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3123 * [nat ipv4 | ipv6 <addr> <port>]
3131 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3133 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3134 * auth_algo <algo> auth_key <key> digest_size <size>
3136 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3137 * digest_size <size>
3138 * data_offset <data_offset>]
3143 * <pa> ::= g | y | r | drop
3146 parse_table_action_fwd(char **tokens,
3148 struct table_rule_action *a)
3150 if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
3156 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3157 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3158 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3162 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3165 if ((n_tokens < 2) ||
3166 parser_read_uint32(&id, tokens[1]))
3169 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3171 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3175 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3176 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3177 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3181 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3184 if ((n_tokens < 2) ||
3185 parser_read_uint32(&id, tokens[1]))
3188 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3190 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3198 parse_table_action_balance(char **tokens,
3200 struct table_rule_action *a)
3204 if ((n_tokens == 0) || (strcmp(tokens[0], "balance") != 0))
3210 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3213 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3214 if (parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3217 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3218 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3223 parse_policer_action(char *token, enum rte_table_action_policer *a)
3225 if (strcmp(token, "g") == 0) {
3226 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3230 if (strcmp(token, "y") == 0) {
3231 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3235 if (strcmp(token, "r") == 0) {
3236 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3240 if (strcmp(token, "drop") == 0) {
3241 *a = RTE_TABLE_ACTION_POLICER_DROP;
3249 parse_table_action_meter_tc(char **tokens,
3251 struct rte_table_action_mtr_tc_params *mtr)
3253 if ((n_tokens < 9) ||
3254 strcmp(tokens[0], "meter") ||
3255 parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3256 strcmp(tokens[2], "policer") ||
3257 strcmp(tokens[3], "g") ||
3258 parse_policer_action(tokens[4], &mtr->policer[RTE_COLOR_GREEN]) ||
3259 strcmp(tokens[5], "y") ||
3260 parse_policer_action(tokens[6], &mtr->policer[RTE_COLOR_YELLOW]) ||
3261 strcmp(tokens[7], "r") ||
3262 parse_policer_action(tokens[8], &mtr->policer[RTE_COLOR_RED]))
3269 parse_table_action_meter(char **tokens,
3271 struct table_rule_action *a)
3273 if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
3279 if ((n_tokens < 10) ||
3280 strcmp(tokens[0], "tc0") ||
3281 (parse_table_action_meter_tc(tokens + 1,
3283 &a->mtr.mtr[0]) == 0))
3289 if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
3291 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3295 if ((n_tokens < 30) ||
3296 (parse_table_action_meter_tc(tokens + 1,
3297 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3298 strcmp(tokens[10], "tc2") ||
3299 (parse_table_action_meter_tc(tokens + 11,
3300 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3301 strcmp(tokens[20], "tc3") ||
3302 (parse_table_action_meter_tc(tokens + 21,
3303 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3306 a->mtr.tc_mask = 0xF;
3307 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3308 return 1 + 10 + 3 * 10;
3312 parse_table_action_tm(char **tokens,
3314 struct table_rule_action *a)
3316 uint32_t subport_id, pipe_id;
3318 if ((n_tokens < 5) ||
3319 strcmp(tokens[0], "tm") ||
3320 strcmp(tokens[1], "subport") ||
3321 parser_read_uint32(&subport_id, tokens[2]) ||
3322 strcmp(tokens[3], "pipe") ||
3323 parser_read_uint32(&pipe_id, tokens[4]))
3326 a->tm.subport_id = subport_id;
3327 a->tm.pipe_id = pipe_id;
3328 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3333 parse_table_action_encap(char **tokens,
3335 struct table_rule_action *a)
3337 if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
3344 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3345 if ((n_tokens < 3) ||
3346 parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3347 parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3350 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3351 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3356 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3357 uint32_t pcp, dei, vid;
3359 if ((n_tokens < 6) ||
3360 parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3361 parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3362 parser_read_uint32(&pcp, tokens[3]) ||
3364 parser_read_uint32(&dei, tokens[4]) ||
3366 parser_read_uint32(&vid, tokens[5]) ||
3370 a->encap.vlan.vlan.pcp = pcp & 0x7;
3371 a->encap.vlan.vlan.dei = dei & 0x1;
3372 a->encap.vlan.vlan.vid = vid & 0xFFF;
3373 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3374 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3379 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3380 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3381 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3383 if ((n_tokens < 9) ||
3384 parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3385 parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3386 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3387 (svlan_pcp > 0x7) ||
3388 parser_read_uint32(&svlan_dei, tokens[4]) ||
3389 (svlan_dei > 0x1) ||
3390 parser_read_uint32(&svlan_vid, tokens[5]) ||
3391 (svlan_vid > 0xFFF) ||
3392 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3393 (cvlan_pcp > 0x7) ||
3394 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3395 (cvlan_dei > 0x1) ||
3396 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3397 (cvlan_vid > 0xFFF))
3400 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3401 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3402 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3403 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3404 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3405 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3406 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3407 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3412 if (n_tokens && (strcmp(tokens[0], "qinq_pppoe") == 0)) {
3413 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3414 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3416 if ((n_tokens < 10) ||
3417 parse_mac_addr(tokens[1],
3418 &a->encap.qinq_pppoe.ether.da) ||
3419 parse_mac_addr(tokens[2],
3420 &a->encap.qinq_pppoe.ether.sa) ||
3421 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3422 (svlan_pcp > 0x7) ||
3423 parser_read_uint32(&svlan_dei, tokens[4]) ||
3424 (svlan_dei > 0x1) ||
3425 parser_read_uint32(&svlan_vid, tokens[5]) ||
3426 (svlan_vid > 0xFFF) ||
3427 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3428 (cvlan_pcp > 0x7) ||
3429 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3430 (cvlan_dei > 0x1) ||
3431 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3432 (cvlan_vid > 0xFFF) ||
3433 parser_read_uint16(&a->encap.qinq_pppoe.pppoe.session_id,
3437 a->encap.qinq_pppoe.svlan.pcp = svlan_pcp & 0x7;
3438 a->encap.qinq_pppoe.svlan.dei = svlan_dei & 0x1;
3439 a->encap.qinq_pppoe.svlan.vid = svlan_vid & 0xFFF;
3440 a->encap.qinq_pppoe.cvlan.pcp = cvlan_pcp & 0x7;
3441 a->encap.qinq_pppoe.cvlan.dei = cvlan_dei & 0x1;
3442 a->encap.qinq_pppoe.cvlan.vid = cvlan_vid & 0xFFF;
3443 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
3444 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3450 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3451 uint32_t label, tc, ttl;
3456 if (strcmp(tokens[1], "unicast") == 0)
3457 a->encap.mpls.unicast = 1;
3458 else if (strcmp(tokens[1], "multicast") == 0)
3459 a->encap.mpls.unicast = 0;
3463 if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3464 parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3465 strcmp(tokens[4], "label0") ||
3466 parser_read_uint32(&label, tokens[5]) ||
3467 (label > 0xFFFFF) ||
3468 parser_read_uint32(&tc, tokens[6]) ||
3470 parser_read_uint32(&ttl, tokens[7]) ||
3474 a->encap.mpls.mpls[0].label = label;
3475 a->encap.mpls.mpls[0].tc = tc;
3476 a->encap.mpls.mpls[0].ttl = ttl;
3481 if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3482 a->encap.mpls.mpls_count = 1;
3483 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3484 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3488 if ((n_tokens < 4) ||
3489 parser_read_uint32(&label, tokens[1]) ||
3490 (label > 0xFFFFF) ||
3491 parser_read_uint32(&tc, tokens[2]) ||
3493 parser_read_uint32(&ttl, tokens[3]) ||
3497 a->encap.mpls.mpls[1].label = label;
3498 a->encap.mpls.mpls[1].tc = tc;
3499 a->encap.mpls.mpls[1].ttl = ttl;
3504 if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3505 a->encap.mpls.mpls_count = 2;
3506 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3507 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3511 if ((n_tokens < 4) ||
3512 parser_read_uint32(&label, tokens[1]) ||
3513 (label > 0xFFFFF) ||
3514 parser_read_uint32(&tc, tokens[2]) ||
3516 parser_read_uint32(&ttl, tokens[3]) ||
3520 a->encap.mpls.mpls[2].label = label;
3521 a->encap.mpls.mpls[2].tc = tc;
3522 a->encap.mpls.mpls[2].ttl = ttl;
3527 if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3528 a->encap.mpls.mpls_count = 3;
3529 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3530 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3531 return 1 + 8 + 4 + 4;
3534 if ((n_tokens < 4) ||
3535 parser_read_uint32(&label, tokens[1]) ||
3536 (label > 0xFFFFF) ||
3537 parser_read_uint32(&tc, tokens[2]) ||
3539 parser_read_uint32(&ttl, tokens[3]) ||
3543 a->encap.mpls.mpls[3].label = label;
3544 a->encap.mpls.mpls[3].tc = tc;
3545 a->encap.mpls.mpls[3].ttl = ttl;
3547 a->encap.mpls.mpls_count = 4;
3548 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3549 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3550 return 1 + 8 + 4 + 4 + 4;
3554 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3555 if ((n_tokens < 4) ||
3556 parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3557 parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3558 parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3562 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3563 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3568 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3575 /* ether <da> <sa> */
3576 if ((n_tokens < 3) ||
3577 strcmp(tokens[0], "ether") ||
3578 parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3579 parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3586 /* [vlan <pcp> <dei> <vid>] */
3587 if (strcmp(tokens[0], "vlan") == 0) {
3588 uint32_t pcp, dei, vid;
3590 if ((n_tokens < 4) ||
3591 parser_read_uint32(&pcp, tokens[1]) ||
3593 parser_read_uint32(&dei, tokens[2]) ||
3595 parser_read_uint32(&vid, tokens[3]) ||
3599 a->encap.vxlan.vlan.pcp = pcp;
3600 a->encap.vxlan.vlan.dei = dei;
3601 a->encap.vxlan.vlan.vid = vid;
3608 /* ipv4 <sa> <da> <dscp> <ttl>
3609 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3610 if (strcmp(tokens[0], "ipv4") == 0) {
3611 struct in_addr sa, da;
3614 if ((n_tokens < 5) ||
3615 parse_ipv4_addr(tokens[1], &sa) ||
3616 parse_ipv4_addr(tokens[2], &da) ||
3617 parser_read_uint8(&dscp, tokens[3]) ||
3619 parser_read_uint8(&ttl, tokens[4]))
3622 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3623 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3624 a->encap.vxlan.ipv4.dscp = dscp;
3625 a->encap.vxlan.ipv4.ttl = ttl;
3630 } else if (strcmp(tokens[0], "ipv6") == 0) {
3631 struct in6_addr sa, da;
3632 uint32_t flow_label;
3633 uint8_t dscp, hop_limit;
3635 if ((n_tokens < 6) ||
3636 parse_ipv6_addr(tokens[1], &sa) ||
3637 parse_ipv6_addr(tokens[2], &da) ||
3638 parser_read_uint32(&flow_label, tokens[3]) ||
3639 parser_read_uint8(&dscp, tokens[4]) ||
3641 parser_read_uint8(&hop_limit, tokens[5]))
3644 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3645 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3646 a->encap.vxlan.ipv6.flow_label = flow_label;
3647 a->encap.vxlan.ipv6.dscp = dscp;
3648 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3657 if ((n_tokens < 3) ||
3658 strcmp(tokens[0], "udp") ||
3659 parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3660 parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3668 if ((n_tokens < 2) ||
3669 strcmp(tokens[0], "vxlan") ||
3670 parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3671 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3678 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3679 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3687 parse_table_action_nat(char **tokens,
3689 struct table_rule_action *a)
3691 if ((n_tokens < 4) ||
3692 strcmp(tokens[0], "nat"))
3695 if (strcmp(tokens[1], "ipv4") == 0) {
3696 struct in_addr addr;
3699 if (parse_ipv4_addr(tokens[2], &addr) ||
3700 parser_read_uint16(&port, tokens[3]))
3703 a->nat.ip_version = 1;
3704 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3706 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3710 if (strcmp(tokens[1], "ipv6") == 0) {
3711 struct in6_addr addr;
3714 if (parse_ipv6_addr(tokens[2], &addr) ||
3715 parser_read_uint16(&port, tokens[3]))
3718 a->nat.ip_version = 0;
3719 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3721 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3729 parse_table_action_ttl(char **tokens,
3731 struct table_rule_action *a)
3733 if ((n_tokens < 2) ||
3734 strcmp(tokens[0], "ttl"))
3737 if (strcmp(tokens[1], "dec") == 0)
3738 a->ttl.decrement = 1;
3739 else if (strcmp(tokens[1], "keep") == 0)
3740 a->ttl.decrement = 0;
3744 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3749 parse_table_action_stats(char **tokens,
3751 struct table_rule_action *a)
3753 if ((n_tokens < 1) ||
3754 strcmp(tokens[0], "stats"))
3757 a->stats.n_packets = 0;
3758 a->stats.n_bytes = 0;
3759 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3764 parse_table_action_time(char **tokens,
3766 struct table_rule_action *a)
3768 if ((n_tokens < 1) ||
3769 strcmp(tokens[0], "time"))
3772 a->time.time = rte_rdtsc();
3773 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3778 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
3780 struct rte_crypto_sym_xform *xform[2] = {NULL};
3783 xform[0] = p->xform;
3785 xform[1] = xform[0]->next;
3787 for (i = 0; i < 2; i++) {
3788 if (xform[i] == NULL)
3791 switch (xform[i]->type) {
3792 case RTE_CRYPTO_SYM_XFORM_CIPHER:
3793 if (p->cipher_auth.cipher_iv.val)
3794 free(p->cipher_auth.cipher_iv.val);
3795 if (p->cipher_auth.cipher_iv_update.val)
3796 free(p->cipher_auth.cipher_iv_update.val);
3798 case RTE_CRYPTO_SYM_XFORM_AUTH:
3799 if (p->cipher_auth.auth_iv.val)
3800 free(p->cipher_auth.cipher_iv.val);
3801 if (p->cipher_auth.auth_iv_update.val)
3802 free(p->cipher_auth.cipher_iv_update.val);
3804 case RTE_CRYPTO_SYM_XFORM_AEAD:
3806 free(p->aead.iv.val);
3807 if (p->aead.aad.val)
3808 free(p->aead.aad.val);
3817 static struct rte_crypto_sym_xform *
3818 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3819 uint8_t *key, uint32_t max_key_len, char **tokens,
3820 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3822 struct rte_crypto_sym_xform *xform_cipher;
3826 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
3827 strcmp(tokens[3], "cipher_key") ||
3828 strcmp(tokens[5], "cipher_iv"))
3831 xform_cipher = calloc(1, sizeof(*xform_cipher));
3832 if (xform_cipher == NULL)
3835 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3836 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
3837 RTE_CRYPTO_CIPHER_OP_DECRYPT;
3840 status = rte_cryptodev_get_cipher_algo_enum(
3841 &xform_cipher->cipher.algo, tokens[2]);
3846 len = strlen(tokens[4]);
3847 if (len / 2 > max_key_len) {
3852 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
3856 xform_cipher->cipher.key.data = key;
3857 xform_cipher->cipher.key.length = (uint16_t)len;
3860 len = strlen(tokens[6]);
3862 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
3863 if (p->cipher_auth.cipher_iv.val == NULL)
3866 status = parse_hex_string(tokens[6],
3867 p->cipher_auth.cipher_iv.val,
3872 xform_cipher->cipher.iv.length = (uint16_t)len;
3873 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3874 p->cipher_auth.cipher_iv.length = (uint32_t)len;
3877 return xform_cipher;
3880 if (p->cipher_auth.cipher_iv.val) {
3881 free(p->cipher_auth.cipher_iv.val);
3882 p->cipher_auth.cipher_iv.val = NULL;
3890 static struct rte_crypto_sym_xform *
3891 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3892 uint8_t *key, uint32_t max_key_len, char **tokens,
3893 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3895 struct rte_crypto_sym_xform *xform_cipher;
3896 struct rte_crypto_sym_xform *xform_auth;
3900 if (n_tokens < 13 ||
3901 strcmp(tokens[7], "auth_algo") ||
3902 strcmp(tokens[9], "auth_key") ||
3903 strcmp(tokens[11], "digest_size"))
3906 xform_auth = calloc(1, sizeof(*xform_auth));
3907 if (xform_auth == NULL)
3910 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
3911 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
3912 RTE_CRYPTO_AUTH_OP_VERIFY;
3915 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
3921 len = strlen(tokens[10]);
3922 if (len / 2 > max_key_len) {
3927 status = parse_hex_string(tokens[10], key, (uint32_t *)&len);
3931 xform_auth->auth.key.data = key;
3932 xform_auth->auth.key.length = (uint16_t)len;
3934 key += xform_auth->auth.key.length;
3935 max_key_len -= xform_auth->auth.key.length;
3937 if (strcmp(tokens[11], "digest_size"))
3940 status = parser_read_uint16(&xform_auth->auth.digest_length,
3945 xform_cipher = parse_table_action_cipher(p, key, max_key_len, tokens,
3946 7, encrypt, used_n_tokens);
3947 if (xform_cipher == NULL)
3950 *used_n_tokens += 6;
3953 xform_cipher->next = xform_auth;
3954 return xform_cipher;
3956 xform_auth->next = xform_cipher;
3961 if (p->cipher_auth.auth_iv.val) {
3962 free(p->cipher_auth.auth_iv.val);
3963 p->cipher_auth.auth_iv.val = 0;
3971 static struct rte_crypto_sym_xform *
3972 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3973 uint8_t *key, uint32_t max_key_len, char **tokens,
3974 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3976 struct rte_crypto_sym_xform *xform_aead;
3980 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
3981 strcmp(tokens[3], "aead_key") ||
3982 strcmp(tokens[5], "aead_iv") ||
3983 strcmp(tokens[7], "aead_aad") ||
3984 strcmp(tokens[9], "digest_size"))
3987 xform_aead = calloc(1, sizeof(*xform_aead));
3988 if (xform_aead == NULL)
3991 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
3992 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
3993 RTE_CRYPTO_AEAD_OP_DECRYPT;
3996 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
4002 len = strlen(tokens[4]);
4003 if (len / 2 > max_key_len) {
4008 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
4012 xform_aead->aead.key.data = key;
4013 xform_aead->aead.key.length = (uint16_t)len;
4016 len = strlen(tokens[6]);
4017 p->aead.iv.val = calloc(1, len / 2 + 1);
4018 if (p->aead.iv.val == NULL)
4021 status = parse_hex_string(tokens[6], p->aead.iv.val,
4026 xform_aead->aead.iv.length = (uint16_t)len;
4027 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4028 p->aead.iv.length = (uint32_t)len;
4031 len = strlen(tokens[8]);
4032 p->aead.aad.val = calloc(1, len / 2 + 1);
4033 if (p->aead.aad.val == NULL)
4036 status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
4040 xform_aead->aead.aad_length = (uint16_t)len;
4041 p->aead.aad.length = (uint32_t)len;
4044 status = parser_read_uint16(&xform_aead->aead.digest_length,
4049 *used_n_tokens = 11;
4054 if (p->aead.iv.val) {
4055 free(p->aead.iv.val);
4056 p->aead.iv.val = NULL;
4058 if (p->aead.aad.val) {
4059 free(p->aead.aad.val);
4060 p->aead.aad.val = NULL;
4070 parse_table_action_sym_crypto(char **tokens,
4072 struct table_rule_action *a)
4074 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4075 struct rte_crypto_sym_xform *xform = NULL;
4076 uint8_t *key = a->sym_crypto_key;
4077 uint32_t max_key_len = SYM_CRYPTO_MAX_KEY_SIZE;
4078 uint32_t used_n_tokens;
4082 if ((n_tokens < 12) ||
4083 strcmp(tokens[0], "sym_crypto") ||
4084 strcmp(tokens[2], "type"))
4087 memset(p, 0, sizeof(*p));
4089 if (strcmp(tokens[1], "encrypt") == 0)
4094 status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4098 if (strcmp(tokens[3], "cipher") == 0) {
4102 xform = parse_table_action_cipher(p, key, max_key_len, tokens,
4103 n_tokens, encrypt, &used_n_tokens);
4104 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4108 xform = parse_table_action_cipher_auth(p, key, max_key_len,
4109 tokens, n_tokens, encrypt, &used_n_tokens);
4110 } else if (strcmp(tokens[3], "aead") == 0) {
4114 xform = parse_table_action_aead(p, key, max_key_len, tokens,
4115 n_tokens, encrypt, &used_n_tokens);
4123 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4124 parse_free_sym_crypto_param_data(p);
4128 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4130 return used_n_tokens + 5;
4134 parse_table_action_tag(char **tokens,
4136 struct table_rule_action *a)
4138 if ((n_tokens < 2) ||
4139 strcmp(tokens[0], "tag"))
4142 if (parser_read_uint32(&a->tag.tag, tokens[1]))
4145 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4150 parse_table_action_decap(char **tokens,
4152 struct table_rule_action *a)
4154 if ((n_tokens < 2) ||
4155 strcmp(tokens[0], "decap"))
4158 if (parser_read_uint16(&a->decap.n, tokens[1]))
4161 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4166 parse_table_action(char **tokens,
4170 struct table_rule_action *a)
4172 uint32_t n_tokens0 = n_tokens;
4174 memset(a, 0, sizeof(*a));
4176 if ((n_tokens < 2) ||
4177 strcmp(tokens[0], "action"))
4183 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4186 n = parse_table_action_fwd(tokens, n_tokens, a);
4188 snprintf(out, out_size, MSG_ARG_INVALID,
4197 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4200 n = parse_table_action_balance(tokens, n_tokens, a);
4202 snprintf(out, out_size, MSG_ARG_INVALID,
4211 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4214 n = parse_table_action_meter(tokens, n_tokens, a);
4216 snprintf(out, out_size, MSG_ARG_INVALID,
4225 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4228 n = parse_table_action_tm(tokens, n_tokens, a);
4230 snprintf(out, out_size, MSG_ARG_INVALID,
4239 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4242 n = parse_table_action_encap(tokens, n_tokens, a);
4244 snprintf(out, out_size, MSG_ARG_INVALID,
4253 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4256 n = parse_table_action_nat(tokens, n_tokens, a);
4258 snprintf(out, out_size, MSG_ARG_INVALID,
4267 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4270 n = parse_table_action_ttl(tokens, n_tokens, a);
4272 snprintf(out, out_size, MSG_ARG_INVALID,
4281 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4284 n = parse_table_action_stats(tokens, n_tokens, a);
4286 snprintf(out, out_size, MSG_ARG_INVALID,
4295 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4298 n = parse_table_action_time(tokens, n_tokens, a);
4300 snprintf(out, out_size, MSG_ARG_INVALID,
4309 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4312 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4314 snprintf(out, out_size, MSG_ARG_INVALID,
4315 "action sym_crypto");
4322 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4325 n = parse_table_action_tag(tokens, n_tokens, a);
4327 snprintf(out, out_size, MSG_ARG_INVALID,
4336 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4339 n = parse_table_action_decap(tokens, n_tokens, a);
4341 snprintf(out, out_size, MSG_ARG_INVALID,
4350 if (n_tokens0 - n_tokens == 1) {
4351 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4355 return n_tokens0 - n_tokens;
4359 static const char cmd_pipeline_table_rule_add_help[] =
4360 "pipeline <pipeline_name> table <table_id> rule add\n"
4362 " action <table_action>\n";
4365 cmd_pipeline_table_rule_add(char **tokens,
4370 struct table_rule_match m;
4371 struct table_rule_action a;
4372 char *pipeline_name;
4373 uint32_t table_id, t0, n_tokens_parsed;
4377 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4381 pipeline_name = tokens[1];
4383 if (strcmp(tokens[2], "table") != 0) {
4384 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4388 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4389 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4393 if (strcmp(tokens[4], "rule") != 0) {
4394 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4398 if (strcmp(tokens[5], "add") != 0) {
4399 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4406 n_tokens_parsed = parse_match(tokens + t0,
4411 if (n_tokens_parsed == 0)
4413 t0 += n_tokens_parsed;
4416 n_tokens_parsed = parse_table_action(tokens + t0,
4421 if (n_tokens_parsed == 0)
4423 t0 += n_tokens_parsed;
4425 if (t0 != n_tokens) {
4426 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4430 status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
4432 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4436 if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
4437 parse_free_sym_crypto_param_data(&a.sym_crypto);
4441 static const char cmd_pipeline_table_rule_add_default_help[] =
4442 "pipeline <pipeline_name> table <table_id> rule add\n"
4448 " | port <port_id>\n"
4450 " | table <table_id>\n";
4453 cmd_pipeline_table_rule_add_default(char **tokens,
4458 struct table_rule_action action;
4459 char *pipeline_name;
4463 if ((n_tokens != 11) && (n_tokens != 12)) {
4464 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4468 pipeline_name = tokens[1];
4470 if (strcmp(tokens[2], "table") != 0) {
4471 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4475 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4476 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4480 if (strcmp(tokens[4], "rule") != 0) {
4481 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4485 if (strcmp(tokens[5], "add") != 0) {
4486 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4490 if (strcmp(tokens[6], "match") != 0) {
4491 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4495 if (strcmp(tokens[7], "default") != 0) {
4496 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4500 if (strcmp(tokens[8], "action") != 0) {
4501 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4505 if (strcmp(tokens[9], "fwd") != 0) {
4506 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4510 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4512 if (strcmp(tokens[10], "drop") == 0) {
4513 if (n_tokens != 11) {
4514 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4518 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4519 } else if (strcmp(tokens[10], "port") == 0) {
4522 if (n_tokens != 12) {
4523 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4527 if (parser_read_uint32(&id, tokens[11]) != 0) {
4528 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4532 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4534 } else if (strcmp(tokens[10], "meta") == 0) {
4535 if (n_tokens != 11) {
4536 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4540 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4541 } else if (strcmp(tokens[10], "table") == 0) {
4544 if (n_tokens != 12) {
4545 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4549 if (parser_read_uint32(&id, tokens[11]) != 0) {
4550 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4554 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4557 snprintf(out, out_size, MSG_ARG_INVALID,
4558 "drop or port or meta or table");
4562 status = pipeline_table_rule_add_default(pipeline_name,
4566 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4572 static const char cmd_pipeline_table_rule_add_bulk_help[] =
4573 "pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\n"
4575 " File <file_name>:\n"
4576 " - line format: match <match> action <action>\n";
4579 cli_rule_file_process(const char *file_name,
4580 size_t line_len_max,
4581 struct table_rule_list **rule_list,
4583 uint32_t *line_number,
4588 cmd_pipeline_table_rule_add_bulk(char **tokens,
4593 struct table_rule_list *list = NULL;
4594 char *pipeline_name, *file_name;
4595 uint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;
4598 if (n_tokens != 8) {
4599 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4603 pipeline_name = tokens[1];
4605 if (strcmp(tokens[2], "table") != 0) {
4606 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4610 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4611 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4615 if (strcmp(tokens[4], "rule") != 0) {
4616 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4620 if (strcmp(tokens[5], "add") != 0) {
4621 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4625 if (strcmp(tokens[6], "bulk") != 0) {
4626 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4630 file_name = tokens[7];
4632 /* Load rules from file. */
4633 status = cli_rule_file_process(file_name,
4641 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4646 status = pipeline_table_rule_add_bulk(pipeline_name,
4650 &n_rules_not_added);
4652 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4656 snprintf(out, out_size, "Added %u rules out of %u.\n",
4662 static const char cmd_pipeline_table_rule_delete_help[] =
4663 "pipeline <pipeline_name> table <table_id> rule delete\n"
4667 cmd_pipeline_table_rule_delete(char **tokens,
4672 struct table_rule_match m;
4673 char *pipeline_name;
4674 uint32_t table_id, n_tokens_parsed, t0;
4678 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4682 pipeline_name = tokens[1];
4684 if (strcmp(tokens[2], "table") != 0) {
4685 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4689 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4690 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4694 if (strcmp(tokens[4], "rule") != 0) {
4695 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4699 if (strcmp(tokens[5], "delete") != 0) {
4700 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4707 n_tokens_parsed = parse_match(tokens + t0,
4712 if (n_tokens_parsed == 0)
4714 t0 += n_tokens_parsed;
4716 if (n_tokens != t0) {
4717 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4721 status = pipeline_table_rule_delete(pipeline_name,
4725 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4731 static const char cmd_pipeline_table_rule_delete_default_help[] =
4732 "pipeline <pipeline_name> table <table_id> rule delete\n"
4737 cmd_pipeline_table_rule_delete_default(char **tokens,
4742 char *pipeline_name;
4746 if (n_tokens != 8) {
4747 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4751 pipeline_name = tokens[1];
4753 if (strcmp(tokens[2], "table") != 0) {
4754 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4758 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4759 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4763 if (strcmp(tokens[4], "rule") != 0) {
4764 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4768 if (strcmp(tokens[5], "delete") != 0) {
4769 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4773 if (strcmp(tokens[6], "match") != 0) {
4774 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4778 if (strcmp(tokens[7], "default") != 0) {
4779 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4783 status = pipeline_table_rule_delete_default(pipeline_name,
4786 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4792 ether_addr_show(FILE *f, struct rte_ether_addr *addr)
4794 fprintf(f, "%02x:%02x:%02x:%02x:%02x:%02x",
4795 (uint32_t)addr->addr_bytes[0], (uint32_t)addr->addr_bytes[1],
4796 (uint32_t)addr->addr_bytes[2], (uint32_t)addr->addr_bytes[3],
4797 (uint32_t)addr->addr_bytes[4], (uint32_t)addr->addr_bytes[5]);
4801 ipv4_addr_show(FILE *f, uint32_t addr)
4803 fprintf(f, "%u.%u.%u.%u",
4805 (addr >> 16) & 0xFF,
4811 ipv6_addr_show(FILE *f, uint8_t *addr)
4813 fprintf(f, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
4814 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:",
4815 (uint32_t)addr[0], (uint32_t)addr[1],
4816 (uint32_t)addr[2], (uint32_t)addr[3],
4817 (uint32_t)addr[4], (uint32_t)addr[5],
4818 (uint32_t)addr[6], (uint32_t)addr[7],
4819 (uint32_t)addr[8], (uint32_t)addr[9],
4820 (uint32_t)addr[10], (uint32_t)addr[11],
4821 (uint32_t)addr[12], (uint32_t)addr[13],
4822 (uint32_t)addr[14], (uint32_t)addr[15]);
4826 policer_action_string(enum rte_table_action_policer action) {
4828 case RTE_TABLE_ACTION_POLICER_COLOR_GREEN: return "G";
4829 case RTE_TABLE_ACTION_POLICER_COLOR_YELLOW: return "Y";
4830 case RTE_TABLE_ACTION_POLICER_COLOR_RED: return "R";
4831 case RTE_TABLE_ACTION_POLICER_DROP: return "D";
4832 default: return "?";
4837 table_rule_show(const char *pipeline_name,
4839 const char *file_name)
4842 struct table *table;
4843 struct table_rule *rule;
4847 /* Check input params. */
4848 if ((pipeline_name == NULL) ||
4849 (file_name == NULL))
4852 p = pipeline_find(pipeline_name);
4854 (table_id >= p->n_tables))
4857 table = &p->table[table_id];
4860 f = fopen(file_name, "w");
4864 /* Write table rules to file. */
4865 TAILQ_FOREACH(rule, &table->rules, node) {
4866 struct table_rule_match *m = &rule->match;
4867 struct table_rule_action *a = &rule->action;
4869 fprintf(f, "match ");
4870 switch (m->match_type) {
4872 fprintf(f, "acl priority %u ",
4873 m->match.acl.priority);
4875 fprintf(f, m->match.acl.ip_version ? "ipv4 " : "ipv6 ");
4877 if (m->match.acl.ip_version)
4878 ipv4_addr_show(f, m->match.acl.ipv4.sa);
4880 ipv6_addr_show(f, m->match.acl.ipv6.sa);
4882 fprintf(f, "%u", m->match.acl.sa_depth);
4884 if (m->match.acl.ip_version)
4885 ipv4_addr_show(f, m->match.acl.ipv4.da);
4887 ipv6_addr_show(f, m->match.acl.ipv6.da);
4889 fprintf(f, "%u", m->match.acl.da_depth);
4891 fprintf(f, "%u %u %u %u %u ",
4892 (uint32_t)m->match.acl.sp0,
4893 (uint32_t)m->match.acl.sp1,
4894 (uint32_t)m->match.acl.dp0,
4895 (uint32_t)m->match.acl.dp1,
4896 (uint32_t)m->match.acl.proto);
4900 fprintf(f, "array %u ",
4901 m->match.array.pos);
4905 fprintf(f, "hash raw ");
4906 for (i = 0; i < table->params.match.hash.key_size; i++)
4907 fprintf(f, "%02x", m->match.hash.key[i]);
4914 fprintf(f, m->match.lpm.ip_version ? "ipv4 " : "ipv6 ");
4916 if (m->match.acl.ip_version)
4917 ipv4_addr_show(f, m->match.lpm.ipv4);
4919 ipv6_addr_show(f, m->match.lpm.ipv6);
4922 (uint32_t)m->match.lpm.depth);
4926 fprintf(f, "unknown ");
4929 fprintf(f, "action ");
4930 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
4932 switch (a->fwd.action) {
4933 case RTE_PIPELINE_ACTION_DROP:
4934 fprintf(f, "drop ");
4937 case RTE_PIPELINE_ACTION_PORT:
4938 fprintf(f, "port %u ", a->fwd.id);
4941 case RTE_PIPELINE_ACTION_PORT_META:
4942 fprintf(f, "meta ");
4945 case RTE_PIPELINE_ACTION_TABLE:
4947 fprintf(f, "table %u ", a->fwd.id);
4951 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
4952 fprintf(f, "balance ");
4953 for (i = 0; i < RTE_DIM(a->lb.out); i++)
4954 fprintf(f, "%u ", a->lb.out[i]);
4957 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
4959 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++)
4960 if (a->mtr.tc_mask & (1 << i)) {
4961 struct rte_table_action_mtr_tc_params *p =
4963 enum rte_table_action_policer ga =
4964 p->policer[RTE_COLOR_GREEN];
4965 enum rte_table_action_policer ya =
4966 p->policer[RTE_COLOR_YELLOW];
4967 enum rte_table_action_policer ra =
4968 p->policer[RTE_COLOR_RED];
4970 fprintf(f, "tc%u meter %u policer g %s y %s r %s ",
4972 a->mtr.mtr[i].meter_profile_id,
4973 policer_action_string(ga),
4974 policer_action_string(ya),
4975 policer_action_string(ra));
4979 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TM))
4980 fprintf(f, "tm subport %u pipe %u ",
4984 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
4985 fprintf(f, "encap ");
4986 switch (a->encap.type) {
4987 case RTE_TABLE_ACTION_ENCAP_ETHER:
4988 fprintf(f, "ether ");
4989 ether_addr_show(f, &a->encap.ether.ether.da);
4991 ether_addr_show(f, &a->encap.ether.ether.sa);
4995 case RTE_TABLE_ACTION_ENCAP_VLAN:
4996 fprintf(f, "vlan ");
4997 ether_addr_show(f, &a->encap.vlan.ether.da);
4999 ether_addr_show(f, &a->encap.vlan.ether.sa);
5000 fprintf(f, " pcp %u dei %u vid %u ",
5001 a->encap.vlan.vlan.pcp,
5002 a->encap.vlan.vlan.dei,
5003 a->encap.vlan.vlan.vid);
5006 case RTE_TABLE_ACTION_ENCAP_QINQ:
5007 fprintf(f, "qinq ");
5008 ether_addr_show(f, &a->encap.qinq.ether.da);
5010 ether_addr_show(f, &a->encap.qinq.ether.sa);
5011 fprintf(f, " pcp %u dei %u vid %u pcp %u dei %u vid %u ",
5012 a->encap.qinq.svlan.pcp,
5013 a->encap.qinq.svlan.dei,
5014 a->encap.qinq.svlan.vid,
5015 a->encap.qinq.cvlan.pcp,
5016 a->encap.qinq.cvlan.dei,
5017 a->encap.qinq.cvlan.vid);
5020 case RTE_TABLE_ACTION_ENCAP_MPLS:
5021 fprintf(f, "mpls %s ", (a->encap.mpls.unicast) ?
5022 "unicast " : "multicast ");
5023 ether_addr_show(f, &a->encap.mpls.ether.da);
5025 ether_addr_show(f, &a->encap.mpls.ether.sa);
5027 for (i = 0; i < a->encap.mpls.mpls_count; i++) {
5028 struct rte_table_action_mpls_hdr *l =
5029 &a->encap.mpls.mpls[i];
5031 fprintf(f, "label%u %u %u %u ",
5039 case RTE_TABLE_ACTION_ENCAP_PPPOE:
5040 fprintf(f, "pppoe ");
5041 ether_addr_show(f, &a->encap.pppoe.ether.da);
5043 ether_addr_show(f, &a->encap.pppoe.ether.sa);
5044 fprintf(f, " %u ", a->encap.pppoe.pppoe.session_id);
5047 case RTE_TABLE_ACTION_ENCAP_VXLAN:
5048 fprintf(f, "vxlan ether ");
5049 ether_addr_show(f, &a->encap.vxlan.ether.da);
5051 ether_addr_show(f, &a->encap.vxlan.ether.sa);
5052 if (table->ap->params.encap.vxlan.vlan)
5053 fprintf(f, " vlan pcp %u dei %u vid %u ",
5054 a->encap.vxlan.vlan.pcp,
5055 a->encap.vxlan.vlan.dei,
5056 a->encap.vxlan.vlan.vid);
5057 if (table->ap->params.encap.vxlan.ip_version) {
5058 fprintf(f, " ipv4 ");
5059 ipv4_addr_show(f, a->encap.vxlan.ipv4.sa);
5061 ipv4_addr_show(f, a->encap.vxlan.ipv4.da);
5062 fprintf(f, " %u %u ",
5063 (uint32_t)a->encap.vxlan.ipv4.dscp,
5064 (uint32_t)a->encap.vxlan.ipv4.ttl);
5066 fprintf(f, " ipv6 ");
5067 ipv6_addr_show(f, a->encap.vxlan.ipv6.sa);
5069 ipv6_addr_show(f, a->encap.vxlan.ipv6.da);
5070 fprintf(f, " %u %u %u ",
5071 a->encap.vxlan.ipv6.flow_label,
5072 (uint32_t)a->encap.vxlan.ipv6.dscp,
5073 (uint32_t)a->encap.vxlan.ipv6.hop_limit);
5074 fprintf(f, " udp %u %u vxlan %u ",
5075 a->encap.vxlan.udp.sp,
5076 a->encap.vxlan.udp.dp,
5077 a->encap.vxlan.vxlan.vni);
5082 fprintf(f, "unknown ");
5086 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
5087 fprintf(f, "nat %s ", (a->nat.ip_version) ? "ipv4 " : "ipv6 ");
5088 if (a->nat.ip_version)
5089 ipv4_addr_show(f, a->nat.addr.ipv4);
5091 ipv6_addr_show(f, a->nat.addr.ipv6);
5092 fprintf(f, " %u ", (uint32_t)(a->nat.port));
5095 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TTL))
5096 fprintf(f, "ttl %s ", (a->ttl.decrement) ? "dec" : "keep");
5098 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_STATS))
5099 fprintf(f, "stats ");
5101 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TIME))
5102 fprintf(f, "time ");
5104 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO))
5105 fprintf(f, "sym_crypto ");
5107 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TAG))
5108 fprintf(f, "tag %u ", a->tag.tag);
5110 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
5111 fprintf(f, "decap %u ", a->decap.n);
5117 /* Write table default rule to file. */
5118 if (table->rule_default) {
5119 struct table_rule_action *a = &table->rule_default->action;
5121 fprintf(f, "# match default action fwd ");
5123 switch (a->fwd.action) {
5124 case RTE_PIPELINE_ACTION_DROP:
5125 fprintf(f, "drop ");
5128 case RTE_PIPELINE_ACTION_PORT:
5129 fprintf(f, "port %u ", a->fwd.id);
5132 case RTE_PIPELINE_ACTION_PORT_META:
5133 fprintf(f, "meta ");
5136 case RTE_PIPELINE_ACTION_TABLE:
5138 fprintf(f, "table %u ", a->fwd.id);
5141 fprintf(f, "# match default action fwd drop ");
5151 static const char cmd_pipeline_table_rule_show_help[] =
5152 "pipeline <pipeline_name> table <table_id> rule show\n"
5153 " file <file_name>\n";
5156 cmd_pipeline_table_rule_show(char **tokens,
5161 char *file_name = NULL, *pipeline_name;
5165 if (n_tokens != 8) {
5166 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5170 pipeline_name = tokens[1];
5172 if (strcmp(tokens[2], "table") != 0) {
5173 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5177 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5178 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5182 if (strcmp(tokens[4], "rule") != 0) {
5183 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5187 if (strcmp(tokens[5], "show") != 0) {
5188 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "show");
5192 if (strcmp(tokens[6], "file") != 0) {
5193 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "file");
5197 file_name = tokens[7];
5199 status = table_rule_show(pipeline_name, table_id, file_name);
5201 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5206 static const char cmd_pipeline_table_rule_stats_read_help[] =
5207 "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n"
5211 cmd_pipeline_table_rule_stats_read(char **tokens,
5216 struct table_rule_match m;
5217 struct rte_table_action_stats_counters stats;
5218 char *pipeline_name;
5219 uint32_t table_id, n_tokens_parsed;
5220 int clear = 0, status;
5223 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5227 pipeline_name = tokens[1];
5229 if (strcmp(tokens[2], "table") != 0) {
5230 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5234 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5235 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5239 if (strcmp(tokens[4], "rule") != 0) {
5240 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5244 if (strcmp(tokens[5], "read") != 0) {
5245 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5249 if (strcmp(tokens[6], "stats") != 0) {
5250 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
5258 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5266 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5267 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5271 n_tokens_parsed = parse_match(tokens,
5276 if (n_tokens_parsed == 0)
5278 n_tokens -= n_tokens_parsed;
5279 tokens += n_tokens_parsed;
5283 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5287 /* Read table rule stats. */
5288 status = pipeline_table_rule_stats_read(pipeline_name,
5294 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5299 if (stats.n_packets_valid && stats.n_bytes_valid)
5300 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: %" PRIu64 "\n",
5304 if (stats.n_packets_valid && !stats.n_bytes_valid)
5305 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: N/A\n",
5308 if (!stats.n_packets_valid && stats.n_bytes_valid)
5309 snprintf(out, out_size, "Packets: N/A; Bytes: %" PRIu64 "\n",
5312 if (!stats.n_packets_valid && !stats.n_bytes_valid)
5313 snprintf(out, out_size, "Packets: N/A ; Bytes: N/A\n");
5316 static const char cmd_pipeline_table_meter_profile_add_help[] =
5317 "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
5318 " add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
5319 " | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
5322 cmd_pipeline_table_meter_profile_add(char **tokens,
5327 struct rte_table_action_meter_profile p;
5328 char *pipeline_name;
5329 uint32_t table_id, meter_profile_id;
5333 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5337 pipeline_name = tokens[1];
5339 if (strcmp(tokens[2], "table") != 0) {
5340 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5344 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5345 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5349 if (strcmp(tokens[4], "meter") != 0) {
5350 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5354 if (strcmp(tokens[5], "profile") != 0) {
5355 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5359 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5360 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5364 if (strcmp(tokens[7], "add") != 0) {
5365 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5369 if (strcmp(tokens[8], "srtcm") == 0) {
5370 if (n_tokens != 15) {
5371 snprintf(out, out_size, MSG_ARG_MISMATCH,
5376 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5378 if (strcmp(tokens[9], "cir") != 0) {
5379 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5383 if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5384 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5388 if (strcmp(tokens[11], "cbs") != 0) {
5389 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5393 if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5394 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5398 if (strcmp(tokens[13], "ebs") != 0) {
5399 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5403 if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5404 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5407 } else if (strcmp(tokens[8], "trtcm") == 0) {
5408 if (n_tokens != 17) {
5409 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5413 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5415 if (strcmp(tokens[9], "cir") != 0) {
5416 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5420 if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5421 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5425 if (strcmp(tokens[11], "pir") != 0) {
5426 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5430 if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5431 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5434 if (strcmp(tokens[13], "cbs") != 0) {
5435 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5439 if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5440 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5444 if (strcmp(tokens[15], "pbs") != 0) {
5445 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5449 if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5450 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5454 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5458 status = pipeline_table_mtr_profile_add(pipeline_name,
5463 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5469 static const char cmd_pipeline_table_meter_profile_delete_help[] =
5470 "pipeline <pipeline_name> table <table_id>\n"
5471 " meter profile <meter_profile_id> delete\n";
5474 cmd_pipeline_table_meter_profile_delete(char **tokens,
5479 char *pipeline_name;
5480 uint32_t table_id, meter_profile_id;
5483 if (n_tokens != 8) {
5484 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5488 pipeline_name = tokens[1];
5490 if (strcmp(tokens[2], "table") != 0) {
5491 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5495 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5496 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5500 if (strcmp(tokens[4], "meter") != 0) {
5501 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5505 if (strcmp(tokens[5], "profile") != 0) {
5506 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5510 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5511 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5515 if (strcmp(tokens[7], "delete") != 0) {
5516 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5520 status = pipeline_table_mtr_profile_delete(pipeline_name,
5524 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5530 static const char cmd_pipeline_table_rule_meter_read_help[] =
5531 "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n"
5535 cmd_pipeline_table_rule_meter_read(char **tokens,
5540 struct table_rule_match m;
5541 struct rte_table_action_mtr_counters stats;
5542 char *pipeline_name;
5543 uint32_t table_id, n_tokens_parsed;
5544 int clear = 0, status;
5547 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5551 pipeline_name = tokens[1];
5553 if (strcmp(tokens[2], "table") != 0) {
5554 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5558 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5559 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5563 if (strcmp(tokens[4], "rule") != 0) {
5564 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5568 if (strcmp(tokens[5], "read") != 0) {
5569 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5573 if (strcmp(tokens[6], "meter") != 0) {
5574 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5582 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5590 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5591 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5595 n_tokens_parsed = parse_match(tokens,
5600 if (n_tokens_parsed == 0)
5602 n_tokens -= n_tokens_parsed;
5603 tokens += n_tokens_parsed;
5607 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5611 /* Read table rule meter stats. */
5612 status = pipeline_table_rule_mtr_read(pipeline_name,
5618 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5626 static const char cmd_pipeline_table_dscp_help[] =
5627 "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
5629 " File <file_name>:\n"
5630 " - exactly 64 lines\n"
5631 " - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
5634 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5635 const char *file_name,
5636 uint32_t *line_number)
5641 /* Check input arguments */
5642 if ((dscp_table == NULL) ||
5643 (file_name == NULL) ||
5644 (line_number == NULL)) {
5650 /* Open input file */
5651 f = fopen(file_name, "r");
5658 for (dscp = 0, l = 1; ; l++) {
5661 enum rte_color color;
5662 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5664 if (fgets(line, sizeof(line), f) == NULL)
5667 if (is_comment(line))
5670 if (parse_tokenize_string(line, tokens, &n_tokens)) {
5679 if ((dscp >= RTE_DIM(dscp_table->entry)) ||
5680 (n_tokens != RTE_DIM(tokens)) ||
5681 parser_read_uint32(&tc_id, tokens[0]) ||
5682 (tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
5683 parser_read_uint32(&tc_queue_id, tokens[1]) ||
5684 (tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
5685 (strlen(tokens[2]) != 1)) {
5691 switch (tokens[2][0]) {
5694 color = RTE_COLOR_GREEN;
5699 color = RTE_COLOR_YELLOW;
5704 color = RTE_COLOR_RED;
5713 dscp_table->entry[dscp].tc_id = tc_id;
5714 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5715 dscp_table->entry[dscp].color = color;
5725 cmd_pipeline_table_dscp(char **tokens,
5730 struct rte_table_action_dscp_table dscp_table;
5731 char *pipeline_name, *file_name;
5732 uint32_t table_id, line_number;
5735 if (n_tokens != 6) {
5736 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5740 pipeline_name = tokens[1];
5742 if (strcmp(tokens[2], "table") != 0) {
5743 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5747 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5748 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5752 if (strcmp(tokens[4], "dscp") != 0) {
5753 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5757 file_name = tokens[5];
5759 status = load_dscp_table(&dscp_table, file_name, &line_number);
5761 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5765 status = pipeline_table_dscp_table_update(pipeline_name,
5770 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5776 static const char cmd_pipeline_table_rule_ttl_read_help[] =
5777 "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n"
5781 cmd_pipeline_table_rule_ttl_read(char **tokens,
5786 struct table_rule_match m;
5787 struct rte_table_action_ttl_counters stats;
5788 char *pipeline_name;
5789 uint32_t table_id, n_tokens_parsed;
5790 int clear = 0, status;
5793 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5797 pipeline_name = tokens[1];
5799 if (strcmp(tokens[2], "table") != 0) {
5800 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5804 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5805 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5809 if (strcmp(tokens[4], "rule") != 0) {
5810 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5814 if (strcmp(tokens[5], "read") != 0) {
5815 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5819 if (strcmp(tokens[6], "ttl") != 0) {
5820 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ttl");
5828 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5836 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5837 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5841 n_tokens_parsed = parse_match(tokens,
5846 if (n_tokens_parsed == 0)
5848 n_tokens -= n_tokens_parsed;
5849 tokens += n_tokens_parsed;
5853 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5857 /* Read table rule TTL stats. */
5858 status = pipeline_table_rule_ttl_read(pipeline_name,
5864 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5869 snprintf(out, out_size, "Packets: %" PRIu64 "\n",
5873 static const char cmd_pipeline_table_rule_time_read_help[] =
5874 "pipeline <pipeline_name> table <table_id> rule read time\n"
5878 cmd_pipeline_table_rule_time_read(char **tokens,
5883 struct table_rule_match m;
5884 char *pipeline_name;
5886 uint32_t table_id, n_tokens_parsed;
5890 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5894 pipeline_name = tokens[1];
5896 if (strcmp(tokens[2], "table") != 0) {
5897 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5901 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5902 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5906 if (strcmp(tokens[4], "rule") != 0) {
5907 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5911 if (strcmp(tokens[5], "read") != 0) {
5912 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5916 if (strcmp(tokens[6], "time") != 0) {
5917 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "time");
5925 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5926 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5930 n_tokens_parsed = parse_match(tokens,
5935 if (n_tokens_parsed == 0)
5937 n_tokens -= n_tokens_parsed;
5938 tokens += n_tokens_parsed;
5942 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5946 /* Read table rule timestamp. */
5947 status = pipeline_table_rule_time_read(pipeline_name,
5952 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5957 snprintf(out, out_size, "Packets: %" PRIu64 "\n", timestamp);
5960 static const char cmd_thread_pipeline_enable_help[] =
5961 "thread <thread_id> pipeline <pipeline_name> enable\n";
5964 cmd_thread_pipeline_enable(char **tokens,
5969 char *pipeline_name;
5973 if (n_tokens != 5) {
5974 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5978 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5979 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5983 if (strcmp(tokens[2], "pipeline") != 0) {
5984 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5988 pipeline_name = tokens[3];
5990 if (strcmp(tokens[4], "enable") != 0) {
5991 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5995 status = thread_pipeline_enable(thread_id, pipeline_name);
5997 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
6003 static const char cmd_thread_pipeline_disable_help[] =
6004 "thread <thread_id> pipeline <pipeline_name> disable\n";
6007 cmd_thread_pipeline_disable(char **tokens,
6012 char *pipeline_name;
6016 if (n_tokens != 5) {
6017 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
6021 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
6022 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
6026 if (strcmp(tokens[2], "pipeline") != 0) {
6027 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
6031 pipeline_name = tokens[3];
6033 if (strcmp(tokens[4], "disable") != 0) {
6034 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
6038 status = thread_pipeline_disable(thread_id, pipeline_name);
6040 snprintf(out, out_size, MSG_CMD_FAIL,
6041 "thread pipeline disable");
6047 cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
6052 if (n_tokens == 0) {
6053 snprintf(out, out_size,
6054 "Type 'help <command>' for details on each command.\n\n"
6055 "List of commands:\n"
6059 "\ttmgr subport profile\n"
6060 "\ttmgr pipe profile\n"
6063 "\ttmgr subport pipe\n"
6066 "\tport in action profile\n"
6067 "\ttable action profile\n"
6069 "\tpipeline port in\n"
6070 "\tpipeline port out\n"
6071 "\tpipeline table\n"
6072 "\tpipeline port in table\n"
6073 "\tpipeline port in stats\n"
6074 "\tpipeline port in enable\n"
6075 "\tpipeline port in disable\n"
6076 "\tpipeline port out stats\n"
6077 "\tpipeline table stats\n"
6078 "\tpipeline table rule add\n"
6079 "\tpipeline table rule add default\n"
6080 "\tpipeline table rule add bulk\n"
6081 "\tpipeline table rule delete\n"
6082 "\tpipeline table rule delete default\n"
6083 "\tpipeline table rule show\n"
6084 "\tpipeline table rule stats read\n"
6085 "\tpipeline table meter profile add\n"
6086 "\tpipeline table meter profile delete\n"
6087 "\tpipeline table rule meter read\n"
6088 "\tpipeline table dscp\n"
6089 "\tpipeline table rule ttl read\n"
6090 "\tpipeline table rule time read\n"
6091 "\tthread pipeline enable\n"
6092 "\tthread pipeline disable\n\n");
6096 if (strcmp(tokens[0], "mempool") == 0) {
6097 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
6101 if (strcmp(tokens[0], "link") == 0) {
6102 snprintf(out, out_size, "\n%s\n", cmd_link_help);
6106 if (strcmp(tokens[0], "swq") == 0) {
6107 snprintf(out, out_size, "\n%s\n", cmd_swq_help);
6111 if (strcmp(tokens[0], "tmgr") == 0) {
6112 if (n_tokens == 1) {
6113 snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
6117 if ((n_tokens == 2) &&
6118 (strcmp(tokens[1], "subport")) == 0) {
6119 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
6123 if ((n_tokens == 3) &&
6124 (strcmp(tokens[1], "subport") == 0) &&
6125 (strcmp(tokens[2], "profile") == 0)) {
6126 snprintf(out, out_size, "\n%s\n",
6127 cmd_tmgr_subport_profile_help);
6131 if ((n_tokens == 3) &&
6132 (strcmp(tokens[1], "subport") == 0) &&
6133 (strcmp(tokens[2], "pipe") == 0)) {
6134 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
6138 if ((n_tokens == 3) &&
6139 (strcmp(tokens[1], "pipe") == 0) &&
6140 (strcmp(tokens[2], "profile") == 0)) {
6141 snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
6146 if (strcmp(tokens[0], "tap") == 0) {
6147 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
6151 if (strcmp(tokens[0], "kni") == 0) {
6152 snprintf(out, out_size, "\n%s\n", cmd_kni_help);
6156 if (strcmp(tokens[0], "cryptodev") == 0) {
6157 snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
6161 if ((n_tokens == 4) &&
6162 (strcmp(tokens[0], "port") == 0) &&
6163 (strcmp(tokens[1], "in") == 0) &&
6164 (strcmp(tokens[2], "action") == 0) &&
6165 (strcmp(tokens[3], "profile") == 0)) {
6166 snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
6170 if ((n_tokens == 3) &&
6171 (strcmp(tokens[0], "table") == 0) &&
6172 (strcmp(tokens[1], "action") == 0) &&
6173 (strcmp(tokens[2], "profile") == 0)) {
6174 snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
6178 if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
6179 snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
6183 if ((strcmp(tokens[0], "pipeline") == 0) &&
6184 (strcmp(tokens[1], "port") == 0)) {
6185 if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
6186 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
6190 if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
6191 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
6195 if ((n_tokens == 4) &&
6196 (strcmp(tokens[2], "in") == 0) &&
6197 (strcmp(tokens[3], "table") == 0)) {
6198 snprintf(out, out_size, "\n%s\n",
6199 cmd_pipeline_port_in_table_help);
6203 if ((n_tokens == 4) &&
6204 (strcmp(tokens[2], "in") == 0) &&
6205 (strcmp(tokens[3], "stats") == 0)) {
6206 snprintf(out, out_size, "\n%s\n",
6207 cmd_pipeline_port_in_stats_help);
6211 if ((n_tokens == 4) &&
6212 (strcmp(tokens[2], "in") == 0) &&
6213 (strcmp(tokens[3], "enable") == 0)) {
6214 snprintf(out, out_size, "\n%s\n",
6215 cmd_pipeline_port_in_enable_help);
6219 if ((n_tokens == 4) &&
6220 (strcmp(tokens[2], "in") == 0) &&
6221 (strcmp(tokens[3], "disable") == 0)) {
6222 snprintf(out, out_size, "\n%s\n",
6223 cmd_pipeline_port_in_disable_help);
6227 if ((n_tokens == 4) &&
6228 (strcmp(tokens[2], "out") == 0) &&
6229 (strcmp(tokens[3], "stats") == 0)) {
6230 snprintf(out, out_size, "\n%s\n",
6231 cmd_pipeline_port_out_stats_help);
6236 if ((strcmp(tokens[0], "pipeline") == 0) &&
6237 (strcmp(tokens[1], "table") == 0)) {
6238 if (n_tokens == 2) {
6239 snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
6243 if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
6244 snprintf(out, out_size, "\n%s\n",
6245 cmd_pipeline_table_stats_help);
6249 if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
6250 snprintf(out, out_size, "\n%s\n",
6251 cmd_pipeline_table_dscp_help);
6255 if ((n_tokens == 4) &&
6256 (strcmp(tokens[2], "rule") == 0) &&
6257 (strcmp(tokens[3], "add") == 0)) {
6258 snprintf(out, out_size, "\n%s\n",
6259 cmd_pipeline_table_rule_add_help);
6263 if ((n_tokens == 5) &&
6264 (strcmp(tokens[2], "rule") == 0) &&
6265 (strcmp(tokens[3], "add") == 0) &&
6266 (strcmp(tokens[4], "default") == 0)) {
6267 snprintf(out, out_size, "\n%s\n",
6268 cmd_pipeline_table_rule_add_default_help);
6272 if ((n_tokens == 5) &&
6273 (strcmp(tokens[2], "rule") == 0) &&
6274 (strcmp(tokens[3], "add") == 0) &&
6275 (strcmp(tokens[4], "bulk") == 0)) {
6276 snprintf(out, out_size, "\n%s\n",
6277 cmd_pipeline_table_rule_add_bulk_help);
6281 if ((n_tokens == 4) &&
6282 (strcmp(tokens[2], "rule") == 0) &&
6283 (strcmp(tokens[3], "delete") == 0)) {
6284 snprintf(out, out_size, "\n%s\n",
6285 cmd_pipeline_table_rule_delete_help);
6289 if ((n_tokens == 5) &&
6290 (strcmp(tokens[2], "rule") == 0) &&
6291 (strcmp(tokens[3], "delete") == 0) &&
6292 (strcmp(tokens[4], "default") == 0)) {
6293 snprintf(out, out_size, "\n%s\n",
6294 cmd_pipeline_table_rule_delete_default_help);
6298 if ((n_tokens == 4) &&
6299 (strcmp(tokens[2], "rule") == 0) &&
6300 (strcmp(tokens[3], "show") == 0)) {
6301 snprintf(out, out_size, "\n%s\n",
6302 cmd_pipeline_table_rule_show_help);
6306 if ((n_tokens == 5) &&
6307 (strcmp(tokens[2], "rule") == 0) &&
6308 (strcmp(tokens[3], "stats") == 0) &&
6309 (strcmp(tokens[4], "read") == 0)) {
6310 snprintf(out, out_size, "\n%s\n",
6311 cmd_pipeline_table_rule_stats_read_help);
6315 if ((n_tokens == 5) &&
6316 (strcmp(tokens[2], "meter") == 0) &&
6317 (strcmp(tokens[3], "profile") == 0) &&
6318 (strcmp(tokens[4], "add") == 0)) {
6319 snprintf(out, out_size, "\n%s\n",
6320 cmd_pipeline_table_meter_profile_add_help);
6324 if ((n_tokens == 5) &&
6325 (strcmp(tokens[2], "meter") == 0) &&
6326 (strcmp(tokens[3], "profile") == 0) &&
6327 (strcmp(tokens[4], "delete") == 0)) {
6328 snprintf(out, out_size, "\n%s\n",
6329 cmd_pipeline_table_meter_profile_delete_help);
6333 if ((n_tokens == 5) &&
6334 (strcmp(tokens[2], "rule") == 0) &&
6335 (strcmp(tokens[3], "meter") == 0) &&
6336 (strcmp(tokens[4], "read") == 0)) {
6337 snprintf(out, out_size, "\n%s\n",
6338 cmd_pipeline_table_rule_meter_read_help);
6342 if ((n_tokens == 5) &&
6343 (strcmp(tokens[2], "rule") == 0) &&
6344 (strcmp(tokens[3], "ttl") == 0) &&
6345 (strcmp(tokens[4], "read") == 0)) {
6346 snprintf(out, out_size, "\n%s\n",
6347 cmd_pipeline_table_rule_ttl_read_help);
6351 if ((n_tokens == 5) &&
6352 (strcmp(tokens[2], "rule") == 0) &&
6353 (strcmp(tokens[3], "time") == 0) &&
6354 (strcmp(tokens[4], "read") == 0)) {
6355 snprintf(out, out_size, "\n%s\n",
6356 cmd_pipeline_table_rule_time_read_help);
6361 if ((n_tokens == 3) &&
6362 (strcmp(tokens[0], "thread") == 0) &&
6363 (strcmp(tokens[1], "pipeline") == 0)) {
6364 if (strcmp(tokens[2], "enable") == 0) {
6365 snprintf(out, out_size, "\n%s\n",
6366 cmd_thread_pipeline_enable_help);
6370 if (strcmp(tokens[2], "disable") == 0) {
6371 snprintf(out, out_size, "\n%s\n",
6372 cmd_thread_pipeline_disable_help);
6377 snprintf(out, out_size, "Invalid command\n");
6381 cli_process(char *in, char *out, size_t out_size)
6383 char *tokens[CMD_MAX_TOKENS];
6384 uint32_t n_tokens = RTE_DIM(tokens);
6390 status = parse_tokenize_string(in, tokens, &n_tokens);
6392 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
6399 if (strcmp(tokens[0], "help") == 0) {
6400 cmd_help(tokens, n_tokens, out, out_size);
6404 if (strcmp(tokens[0], "mempool") == 0) {
6405 cmd_mempool(tokens, n_tokens, out, out_size);
6409 if (strcmp(tokens[0], "link") == 0) {
6410 if (strcmp(tokens[1], "show") == 0) {
6411 cmd_link_show(tokens, n_tokens, out, out_size);
6415 cmd_link(tokens, n_tokens, out, out_size);
6419 if (strcmp(tokens[0], "swq") == 0) {
6420 cmd_swq(tokens, n_tokens, out, out_size);
6424 if (strcmp(tokens[0], "tmgr") == 0) {
6425 if ((n_tokens >= 3) &&
6426 (strcmp(tokens[1], "subport") == 0) &&
6427 (strcmp(tokens[2], "profile") == 0)) {
6428 cmd_tmgr_subport_profile(tokens, n_tokens,
6433 if ((n_tokens >= 3) &&
6434 (strcmp(tokens[1], "pipe") == 0) &&
6435 (strcmp(tokens[2], "profile") == 0)) {
6436 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
6440 if ((n_tokens >= 5) &&
6441 (strcmp(tokens[2], "subport") == 0) &&
6442 (strcmp(tokens[4], "profile") == 0)) {
6443 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
6447 if ((n_tokens >= 5) &&
6448 (strcmp(tokens[2], "subport") == 0) &&
6449 (strcmp(tokens[4], "pipe") == 0)) {
6450 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
6454 cmd_tmgr(tokens, n_tokens, out, out_size);
6458 if (strcmp(tokens[0], "tap") == 0) {
6459 cmd_tap(tokens, n_tokens, out, out_size);
6463 if (strcmp(tokens[0], "kni") == 0) {
6464 cmd_kni(tokens, n_tokens, out, out_size);
6468 if (strcmp(tokens[0], "cryptodev") == 0) {
6469 cmd_cryptodev(tokens, n_tokens, out, out_size);
6473 if (strcmp(tokens[0], "port") == 0) {
6474 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
6478 if (strcmp(tokens[0], "table") == 0) {
6479 cmd_table_action_profile(tokens, n_tokens, out, out_size);
6483 if (strcmp(tokens[0], "pipeline") == 0) {
6484 if ((n_tokens >= 3) &&
6485 (strcmp(tokens[2], "period") == 0)) {
6486 cmd_pipeline(tokens, n_tokens, out, out_size);
6490 if ((n_tokens >= 5) &&
6491 (strcmp(tokens[2], "port") == 0) &&
6492 (strcmp(tokens[3], "in") == 0) &&
6493 (strcmp(tokens[4], "bsz") == 0)) {
6494 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
6498 if ((n_tokens >= 5) &&
6499 (strcmp(tokens[2], "port") == 0) &&
6500 (strcmp(tokens[3], "out") == 0) &&
6501 (strcmp(tokens[4], "bsz") == 0)) {
6502 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
6506 if ((n_tokens >= 4) &&
6507 (strcmp(tokens[2], "table") == 0) &&
6508 (strcmp(tokens[3], "match") == 0)) {
6509 cmd_pipeline_table(tokens, n_tokens, out, out_size);
6513 if ((n_tokens >= 6) &&
6514 (strcmp(tokens[2], "port") == 0) &&
6515 (strcmp(tokens[3], "in") == 0) &&
6516 (strcmp(tokens[5], "table") == 0)) {
6517 cmd_pipeline_port_in_table(tokens, n_tokens,
6522 if ((n_tokens >= 6) &&
6523 (strcmp(tokens[2], "port") == 0) &&
6524 (strcmp(tokens[3], "in") == 0) &&
6525 (strcmp(tokens[5], "stats") == 0)) {
6526 cmd_pipeline_port_in_stats(tokens, n_tokens,
6531 if ((n_tokens >= 6) &&
6532 (strcmp(tokens[2], "port") == 0) &&
6533 (strcmp(tokens[3], "in") == 0) &&
6534 (strcmp(tokens[5], "enable") == 0)) {
6535 cmd_pipeline_port_in_enable(tokens, n_tokens,
6540 if ((n_tokens >= 6) &&
6541 (strcmp(tokens[2], "port") == 0) &&
6542 (strcmp(tokens[3], "in") == 0) &&
6543 (strcmp(tokens[5], "disable") == 0)) {
6544 cmd_pipeline_port_in_disable(tokens, n_tokens,
6549 if ((n_tokens >= 6) &&
6550 (strcmp(tokens[2], "port") == 0) &&
6551 (strcmp(tokens[3], "out") == 0) &&
6552 (strcmp(tokens[5], "stats") == 0)) {
6553 cmd_pipeline_port_out_stats(tokens, n_tokens,
6558 if ((n_tokens >= 5) &&
6559 (strcmp(tokens[2], "table") == 0) &&
6560 (strcmp(tokens[4], "stats") == 0)) {
6561 cmd_pipeline_table_stats(tokens, n_tokens,
6566 if ((n_tokens >= 7) &&
6567 (strcmp(tokens[2], "table") == 0) &&
6568 (strcmp(tokens[4], "rule") == 0) &&
6569 (strcmp(tokens[5], "add") == 0) &&
6570 (strcmp(tokens[6], "match") == 0)) {
6571 if ((n_tokens >= 8) &&
6572 (strcmp(tokens[7], "default") == 0)) {
6573 cmd_pipeline_table_rule_add_default(tokens,
6574 n_tokens, out, out_size);
6578 cmd_pipeline_table_rule_add(tokens, n_tokens,
6583 if ((n_tokens >= 7) &&
6584 (strcmp(tokens[2], "table") == 0) &&
6585 (strcmp(tokens[4], "rule") == 0) &&
6586 (strcmp(tokens[5], "add") == 0) &&
6587 (strcmp(tokens[6], "bulk") == 0)) {
6588 cmd_pipeline_table_rule_add_bulk(tokens,
6589 n_tokens, out, out_size);
6593 if ((n_tokens >= 7) &&
6594 (strcmp(tokens[2], "table") == 0) &&
6595 (strcmp(tokens[4], "rule") == 0) &&
6596 (strcmp(tokens[5], "delete") == 0) &&
6597 (strcmp(tokens[6], "match") == 0)) {
6598 if ((n_tokens >= 8) &&
6599 (strcmp(tokens[7], "default") == 0)) {
6600 cmd_pipeline_table_rule_delete_default(tokens,
6601 n_tokens, out, out_size);
6605 cmd_pipeline_table_rule_delete(tokens, n_tokens,
6610 if ((n_tokens >= 6) &&
6611 (strcmp(tokens[2], "table") == 0) &&
6612 (strcmp(tokens[4], "rule") == 0) &&
6613 (strcmp(tokens[5], "show") == 0)) {
6614 cmd_pipeline_table_rule_show(tokens, n_tokens,
6619 if ((n_tokens >= 7) &&
6620 (strcmp(tokens[2], "table") == 0) &&
6621 (strcmp(tokens[4], "rule") == 0) &&
6622 (strcmp(tokens[5], "read") == 0) &&
6623 (strcmp(tokens[6], "stats") == 0)) {
6624 cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
6629 if ((n_tokens >= 8) &&
6630 (strcmp(tokens[2], "table") == 0) &&
6631 (strcmp(tokens[4], "meter") == 0) &&
6632 (strcmp(tokens[5], "profile") == 0) &&
6633 (strcmp(tokens[7], "add") == 0)) {
6634 cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
6639 if ((n_tokens >= 8) &&
6640 (strcmp(tokens[2], "table") == 0) &&
6641 (strcmp(tokens[4], "meter") == 0) &&
6642 (strcmp(tokens[5], "profile") == 0) &&
6643 (strcmp(tokens[7], "delete") == 0)) {
6644 cmd_pipeline_table_meter_profile_delete(tokens,
6645 n_tokens, out, out_size);
6649 if ((n_tokens >= 7) &&
6650 (strcmp(tokens[2], "table") == 0) &&
6651 (strcmp(tokens[4], "rule") == 0) &&
6652 (strcmp(tokens[5], "read") == 0) &&
6653 (strcmp(tokens[6], "meter") == 0)) {
6654 cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
6659 if ((n_tokens >= 5) &&
6660 (strcmp(tokens[2], "table") == 0) &&
6661 (strcmp(tokens[4], "dscp") == 0)) {
6662 cmd_pipeline_table_dscp(tokens, n_tokens,
6667 if ((n_tokens >= 7) &&
6668 (strcmp(tokens[2], "table") == 0) &&
6669 (strcmp(tokens[4], "rule") == 0) &&
6670 (strcmp(tokens[5], "read") == 0) &&
6671 (strcmp(tokens[6], "ttl") == 0)) {
6672 cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
6677 if ((n_tokens >= 7) &&
6678 (strcmp(tokens[2], "table") == 0) &&
6679 (strcmp(tokens[4], "rule") == 0) &&
6680 (strcmp(tokens[5], "read") == 0) &&
6681 (strcmp(tokens[6], "time") == 0)) {
6682 cmd_pipeline_table_rule_time_read(tokens, n_tokens,
6688 if (strcmp(tokens[0], "thread") == 0) {
6689 if ((n_tokens >= 5) &&
6690 (strcmp(tokens[4], "enable") == 0)) {
6691 cmd_thread_pipeline_enable(tokens, n_tokens,
6696 if ((n_tokens >= 5) &&
6697 (strcmp(tokens[4], "disable") == 0)) {
6698 cmd_thread_pipeline_disable(tokens, n_tokens,
6704 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
6708 cli_script_process(const char *file_name,
6709 size_t msg_in_len_max,
6710 size_t msg_out_len_max)
6712 char *msg_in = NULL, *msg_out = NULL;
6715 /* Check input arguments */
6716 if ((file_name == NULL) ||
6717 (strlen(file_name) == 0) ||
6718 (msg_in_len_max == 0) ||
6719 (msg_out_len_max == 0))
6722 msg_in = malloc(msg_in_len_max + 1);
6723 msg_out = malloc(msg_out_len_max + 1);
6724 if ((msg_in == NULL) ||
6725 (msg_out == NULL)) {
6731 /* Open input file */
6732 f = fopen(file_name, "r");
6741 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6744 printf("%s", msg_in);
6751 if (strlen(msg_out))
6752 printf("%s", msg_out);
6763 cli_rule_file_process(const char *file_name,
6764 size_t line_len_max,
6765 struct table_rule_list **rule_list,
6767 uint32_t *line_number,
6771 struct table_rule_list *list = NULL;
6774 uint32_t rule_id = 0, line_id = 0;
6777 /* Check input arguments */
6778 if ((file_name == NULL) ||
6779 (strlen(file_name) == 0) ||
6780 (line_len_max == 0) ||
6781 (rule_list == NULL) ||
6782 (n_rules == NULL) ||
6783 (line_number == NULL) ||
6786 goto cli_rule_file_process_free;
6789 /* Memory allocation */
6790 list = malloc(sizeof(struct table_rule_list));
6793 goto cli_rule_file_process_free;
6798 line = malloc(line_len_max + 1);
6801 goto cli_rule_file_process_free;
6805 f = fopen(file_name, "r");
6808 goto cli_rule_file_process_free;
6812 for (line_id = 1, rule_id = 0; ; line_id++) {
6813 char *tokens[CMD_MAX_TOKENS];
6814 struct table_rule *rule = NULL;
6815 uint32_t n_tokens, n_tokens_parsed, t0;
6817 /* Read next line from file. */
6818 if (fgets(line, line_len_max + 1, f) == NULL)
6822 if (is_comment(line))
6826 n_tokens = RTE_DIM(tokens);
6827 status = parse_tokenize_string(line, tokens, &n_tokens);
6830 goto cli_rule_file_process_free;
6838 /* Rule alloc and insert. */
6839 rule = calloc(1, sizeof(struct table_rule));
6842 goto cli_rule_file_process_free;
6845 TAILQ_INSERT_TAIL(list, rule, node);
6848 n_tokens_parsed = parse_match(tokens + t0,
6853 if (n_tokens_parsed == 0) {
6855 goto cli_rule_file_process_free;
6857 t0 += n_tokens_parsed;
6860 n_tokens_parsed = parse_table_action(tokens + t0,
6865 if (n_tokens_parsed == 0) {
6867 goto cli_rule_file_process_free;
6869 t0 += n_tokens_parsed;
6871 /* Line completed. */
6872 if (t0 < n_tokens) {
6874 goto cli_rule_file_process_free;
6877 /* Increment rule count */
6889 *line_number = line_id;
6892 cli_rule_file_process_free:
6893 if (rule_list != NULL)
6896 if (n_rules != NULL)
6899 if (line_number != NULL)
6900 *line_number = line_id;
6904 struct table_rule *rule;
6906 rule = TAILQ_FIRST(list);
6910 TAILQ_REMOVE(list, rule, node);