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 rte_eth_macaddr_get(link->port_id, &mac_addr);
257 ret = rte_eth_link_get(link->port_id, ð_link);
259 snprintf(out, out_size, "\n%s: link get failed: %s",
260 link->name, rte_strerror(-ret));
264 rte_eth_dev_get_mtu(link->port_id, &mtu);
266 snprintf(out, out_size,
268 "%s: flags=<%s> mtu %u\n"
269 "\tether %02X:%02X:%02X:%02X:%02X:%02X rxqueues %u txqueues %u\n"
270 "\tport# %u speed %u Mbps\n"
271 "\tRX packets %" PRIu64" bytes %" PRIu64"\n"
272 "\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n"
273 "\tTX packets %" PRIu64" bytes %" PRIu64"\n"
274 "\tTX errors %" PRIu64"\n",
276 eth_link.link_status == 0 ? "DOWN" : "UP",
278 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
279 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
280 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5],
296 * link show [<link_name>]
299 cmd_link_show(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
304 if (n_tokens != 2 && n_tokens != 3) {
305 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
310 link = link_next(NULL);
312 while (link != NULL) {
313 out_size = out_size - strlen(out);
314 out = &out[strlen(out)];
316 print_link_info(link, out, out_size);
317 link = link_next(link);
320 out_size = out_size - strlen(out);
321 out = &out[strlen(out)];
323 link_name = tokens[2];
324 link = link_find(link_name);
327 snprintf(out, out_size, MSG_ARG_INVALID,
328 "Link does not exist");
331 print_link_info(link, out, out_size);
335 static const char cmd_swq_help[] =
341 cmd_swq(char **tokens,
351 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
357 if (strcmp(tokens[2], "size") != 0) {
358 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
362 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
363 snprintf(out, out_size, MSG_ARG_INVALID, "size");
367 if (strcmp(tokens[4], "cpu") != 0) {
368 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
372 if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
373 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
377 swq = swq_create(name, &p);
379 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
384 static const char cmd_tmgr_subport_profile_help[] =
385 "tmgr subport profile\n"
386 " <tb_rate> <tb_size>\n"
387 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
388 " <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
389 " <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
393 cmd_tmgr_subport_profile(char **tokens,
398 struct rte_sched_subport_params p;
401 if (n_tokens != 19) {
402 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
406 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
407 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
411 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
412 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
416 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
417 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
418 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
422 if (parser_read_uint32(&p.tc_period, tokens[18]) != 0) {
423 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
427 status = tmgr_subport_profile_add(&p);
429 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
434 static const char cmd_tmgr_pipe_profile_help[] =
435 "tmgr pipe profile\n"
436 " <tb_rate> <tb_size>\n"
437 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
438 " <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
439 " <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
442 " <wrr_weight0..3>\n";
445 cmd_tmgr_pipe_profile(char **tokens,
450 struct rte_sched_pipe_params p;
453 if (n_tokens != 24) {
454 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
458 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
459 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
463 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
464 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
468 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
469 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
470 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
474 if (parser_read_uint32(&p.tc_period, tokens[18]) != 0) {
475 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
479 if (parser_read_uint8(&p.tc_ov_weight, tokens[19]) != 0) {
480 snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
484 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++)
485 if (parser_read_uint8(&p.wrr_weights[i], tokens[20 + i]) != 0) {
486 snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
490 status = tmgr_pipe_profile_add(&p);
492 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
497 static const char cmd_tmgr_help[] =
500 " spp <n_subports_per_port>\n"
501 " pps <n_pipes_per_subport>\n"
502 " qsize <qsize_tc0> <qsize_tc1> <qsize_tc2>"
503 " <qsize_tc3> <qsize_tc4> <qsize_tc5> <qsize_tc6>"
504 " <qsize_tc7> <qsize_tc8> <qsize_tc9> <qsize_tc10>"
505 " <qsize_tc11> <qsize_tc12>\n"
506 " fo <frame_overhead>\n"
511 cmd_tmgr(char **tokens,
516 struct tmgr_port_params p;
518 struct tmgr_port *tmgr_port;
521 if (n_tokens != 28) {
522 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
528 if (strcmp(tokens[2], "rate") != 0) {
529 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
533 if (parser_read_uint32(&p.rate, tokens[3]) != 0) {
534 snprintf(out, out_size, MSG_ARG_INVALID, "rate");
538 if (strcmp(tokens[4], "spp") != 0) {
539 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
543 if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
544 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
548 if (strcmp(tokens[6], "pps") != 0) {
549 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
553 if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
554 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
558 if (strcmp(tokens[8], "qsize") != 0) {
559 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "qsize");
563 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
564 if (parser_read_uint16(&p.qsize[i], tokens[9 + i]) != 0) {
565 snprintf(out, out_size, MSG_ARG_INVALID, "qsize");
569 if (strcmp(tokens[22], "fo") != 0) {
570 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
574 if (parser_read_uint32(&p.frame_overhead, tokens[23]) != 0) {
575 snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
579 if (strcmp(tokens[24], "mtu") != 0) {
580 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
584 if (parser_read_uint32(&p.mtu, tokens[25]) != 0) {
585 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
589 if (strcmp(tokens[26], "cpu") != 0) {
590 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
594 if (parser_read_uint32(&p.cpu_id, tokens[27]) != 0) {
595 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
599 tmgr_port = tmgr_port_create(name, &p);
600 if (tmgr_port == NULL) {
601 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
606 static const char cmd_tmgr_subport_help[] =
607 "tmgr <tmgr_name> subport <subport_id>\n"
608 " profile <subport_profile_id>\n";
611 cmd_tmgr_subport(char **tokens,
616 uint32_t subport_id, subport_profile_id;
621 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
627 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
628 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
632 if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
633 snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
637 status = tmgr_subport_config(name, subport_id, subport_profile_id);
639 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
645 static const char cmd_tmgr_subport_pipe_help[] =
646 "tmgr <tmgr_name> subport <subport_id> pipe\n"
647 " from <pipe_id_first> to <pipe_id_last>\n"
648 " profile <pipe_profile_id>\n";
651 cmd_tmgr_subport_pipe(char **tokens,
656 uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
660 if (n_tokens != 11) {
661 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
667 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
668 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
672 if (strcmp(tokens[4], "pipe") != 0) {
673 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
677 if (strcmp(tokens[5], "from") != 0) {
678 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
682 if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
683 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
687 if (strcmp(tokens[7], "to") != 0) {
688 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
692 if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
693 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
697 if (strcmp(tokens[9], "profile") != 0) {
698 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
702 if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
703 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
707 status = tmgr_pipe_config(name, subport_id, pipe_id_first,
708 pipe_id_last, pipe_profile_id);
710 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
716 static const char cmd_tap_help[] =
720 cmd_tap(char **tokens,
729 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
735 tap = tap_create(name);
737 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
742 static const char cmd_kni_help[] =
744 " link <link_name>\n"
745 " mempool <mempool_name>\n"
746 " [thread <thread_id>]\n";
749 cmd_kni(char **tokens,
758 memset(&p, 0, sizeof(p));
759 if ((n_tokens != 6) && (n_tokens != 8)) {
760 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
766 if (strcmp(tokens[2], "link") != 0) {
767 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
771 p.link_name = tokens[3];
773 if (strcmp(tokens[4], "mempool") != 0) {
774 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
778 p.mempool_name = tokens[5];
781 if (strcmp(tokens[6], "thread") != 0) {
782 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
786 if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
787 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
795 kni = kni_create(name, &p);
797 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
802 static const char cmd_cryptodev_help[] =
803 "cryptodev <cryptodev_name>\n"
804 " dev <device_name> | dev_id <device_id>\n"
805 " queue <n_queues> <queue_size>\n"
806 " max_sessions <n_sessions>";
809 cmd_cryptodev(char **tokens,
814 struct cryptodev_params params;
817 memset(¶ms, 0, sizeof(params));
819 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
825 if (strcmp(tokens[2], "dev") == 0)
826 params.dev_name = tokens[3];
827 else if (strcmp(tokens[2], "dev_id") == 0) {
828 if (parser_read_uint32(¶ms.dev_id, tokens[3]) < 0) {
829 snprintf(out, out_size, MSG_ARG_INVALID,
834 snprintf(out, out_size, MSG_ARG_INVALID,
839 if (strcmp(tokens[4], "queue")) {
840 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
845 if (parser_read_uint32(¶ms.n_queues, tokens[5]) < 0) {
846 snprintf(out, out_size, MSG_ARG_INVALID,
851 if (parser_read_uint32(¶ms.queue_size, tokens[6]) < 0) {
852 snprintf(out, out_size, MSG_ARG_INVALID,
857 if (strcmp(tokens[7], "max_sessions")) {
858 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
863 if (parser_read_uint32(¶ms.session_pool_size, tokens[8]) < 0) {
864 snprintf(out, out_size, MSG_ARG_INVALID,
869 if (cryptodev_create(name, ¶ms) == NULL) {
870 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
875 static const char cmd_port_in_action_profile_help[] =
876 "port in action profile <profile_name>\n"
877 " [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]\n"
878 " [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]\n";
881 cmd_port_in_action_profile(char **tokens,
886 struct port_in_action_profile_params p;
887 struct port_in_action_profile *ap;
891 memset(&p, 0, sizeof(p));
894 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
898 if (strcmp(tokens[1], "in") != 0) {
899 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
903 if (strcmp(tokens[2], "action") != 0) {
904 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
908 if (strcmp(tokens[3], "profile") != 0) {
909 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
917 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
920 if (n_tokens < t0 + 10) {
921 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
925 if (strcmp(tokens[t0 + 1], "match") == 0)
926 p.fltr.filter_on_match = 1;
927 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
928 p.fltr.filter_on_match = 0;
930 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
934 if (strcmp(tokens[t0 + 2], "offset") != 0) {
935 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
939 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
940 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
944 if (strcmp(tokens[t0 + 4], "mask") != 0) {
945 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
949 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
950 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
951 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
952 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
956 if (strcmp(tokens[t0 + 6], "key") != 0) {
957 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
961 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
962 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
963 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
964 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
968 if (strcmp(tokens[t0 + 8], "port") != 0) {
969 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
973 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
974 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
978 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
982 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
985 if (n_tokens < t0 + 22) {
986 snprintf(out, out_size, MSG_ARG_MISMATCH,
987 "port in action profile balance");
991 if (strcmp(tokens[t0 + 1], "offset") != 0) {
992 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
996 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
997 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1001 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1002 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1006 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1007 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1008 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1012 if (strcmp(tokens[t0 + 5], "port") != 0) {
1013 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1017 for (i = 0; i < 16; i++)
1018 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
1019 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1023 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
1027 if (t0 < n_tokens) {
1028 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1032 ap = port_in_action_profile_create(name, &p);
1034 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1040 static const char cmd_table_action_profile_help[] =
1041 "table action profile <profile_name>\n"
1043 " offset <ip_offset>\n"
1045 " [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]\n"
1046 " [meter srtcm | trtcm\n"
1048 " stats none | pkts | bytes | both]\n"
1049 " [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]\n"
1050 " [encap ether | vlan | qinq | mpls | pppoe | qinq_pppoe \n"
1051 " vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]\n"
1053 " proto udp | tcp]\n"
1054 " [ttl drop | fwd\n"
1055 " stats none | pkts]\n"
1056 " [stats pkts | bytes | both]\n"
1058 " [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
1063 cmd_table_action_profile(char **tokens,
1068 struct table_action_profile_params p;
1069 struct table_action_profile *ap;
1073 memset(&p, 0, sizeof(p));
1076 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1080 if (strcmp(tokens[1], "action") != 0) {
1081 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1085 if (strcmp(tokens[2], "profile") != 0) {
1086 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1092 if (strcmp(tokens[4], "ipv4") == 0)
1093 p.common.ip_version = 1;
1094 else if (strcmp(tokens[4], "ipv6") == 0)
1095 p.common.ip_version = 0;
1097 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1101 if (strcmp(tokens[5], "offset") != 0) {
1102 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1106 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
1107 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1111 if (strcmp(tokens[7], "fwd") != 0) {
1112 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1116 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1119 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
1120 if (n_tokens < t0 + 7) {
1121 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1125 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1126 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1130 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1131 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1135 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1136 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1140 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1141 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1142 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1146 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1147 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1151 if (parser_read_uint32(&p.lb.out_offset, tokens[t0 + 6]) != 0) {
1152 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1156 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1160 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
1161 if (n_tokens < t0 + 6) {
1162 snprintf(out, out_size, MSG_ARG_MISMATCH,
1163 "table action profile meter");
1167 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
1168 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1169 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
1170 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1172 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1177 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1178 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1182 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
1183 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1187 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1188 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1192 if (strcmp(tokens[t0 + 5], "none") == 0) {
1193 p.mtr.n_packets_enabled = 0;
1194 p.mtr.n_bytes_enabled = 0;
1195 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1196 p.mtr.n_packets_enabled = 1;
1197 p.mtr.n_bytes_enabled = 0;
1198 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1199 p.mtr.n_packets_enabled = 0;
1200 p.mtr.n_bytes_enabled = 1;
1201 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1202 p.mtr.n_packets_enabled = 1;
1203 p.mtr.n_bytes_enabled = 1;
1205 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1206 "none or pkts or bytes or both");
1210 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1214 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
1215 if (n_tokens < t0 + 5) {
1216 snprintf(out, out_size, MSG_ARG_MISMATCH,
1217 "table action profile tm");
1221 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1222 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1226 if (parser_read_uint32(&p.tm.n_subports_per_port,
1227 tokens[t0 + 2]) != 0) {
1228 snprintf(out, out_size, MSG_ARG_INVALID,
1229 "n_subports_per_port");
1233 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1234 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1238 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1239 tokens[t0 + 4]) != 0) {
1240 snprintf(out, out_size, MSG_ARG_INVALID,
1241 "n_pipes_per_subport");
1245 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1249 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1250 uint32_t n_extra_tokens = 0;
1252 if (n_tokens < t0 + 2) {
1253 snprintf(out, out_size, MSG_ARG_MISMATCH,
1254 "action profile encap");
1258 if (strcmp(tokens[t0 + 1], "ether") == 0)
1259 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1260 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1261 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1262 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1263 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1264 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1265 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1266 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1267 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1268 else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1269 if (n_tokens < t0 + 2 + 5) {
1270 snprintf(out, out_size, MSG_ARG_MISMATCH,
1271 "action profile encap vxlan");
1275 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1276 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1281 if (parser_read_uint32(&p.encap.vxlan.data_offset,
1282 tokens[t0 + 2 + 1]) != 0) {
1283 snprintf(out, out_size, MSG_ARG_INVALID,
1284 "vxlan: ether_offset");
1288 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1289 p.encap.vxlan.ip_version = 1;
1290 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1291 p.encap.vxlan.ip_version = 0;
1293 snprintf(out, out_size, MSG_ARG_INVALID,
1294 "vxlan: ipv4 or ipv6");
1298 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1299 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1304 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
1305 p.encap.vxlan.vlan = 1;
1306 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
1307 p.encap.vxlan.vlan = 0;
1309 snprintf(out, out_size, MSG_ARG_INVALID,
1310 "vxlan: on or off");
1314 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
1316 } else if (strcmp(tokens[t0 + 1], "qinq_pppoe") == 0)
1317 p.encap.encap_mask =
1318 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
1320 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1324 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1325 t0 += 2 + n_extra_tokens;
1328 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1329 if (n_tokens < t0 + 4) {
1330 snprintf(out, out_size, MSG_ARG_MISMATCH,
1331 "table action profile nat");
1335 if (strcmp(tokens[t0 + 1], "src") == 0)
1336 p.nat.source_nat = 1;
1337 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1338 p.nat.source_nat = 0;
1340 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1345 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1346 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1350 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1352 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1355 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1360 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1364 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1365 if (n_tokens < t0 + 4) {
1366 snprintf(out, out_size, MSG_ARG_MISMATCH,
1367 "table action profile ttl");
1371 if (strcmp(tokens[t0 + 1], "drop") == 0)
1373 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1376 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1381 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1382 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1386 if (strcmp(tokens[t0 + 3], "none") == 0)
1387 p.ttl.n_packets_enabled = 0;
1388 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1389 p.ttl.n_packets_enabled = 1;
1391 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1396 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1400 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1401 if (n_tokens < t0 + 2) {
1402 snprintf(out, out_size, MSG_ARG_MISMATCH,
1403 "table action profile stats");
1407 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1408 p.stats.n_packets_enabled = 1;
1409 p.stats.n_bytes_enabled = 0;
1410 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1411 p.stats.n_packets_enabled = 0;
1412 p.stats.n_bytes_enabled = 1;
1413 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1414 p.stats.n_packets_enabled = 1;
1415 p.stats.n_bytes_enabled = 1;
1417 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1418 "pkts or bytes or both");
1422 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1426 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1427 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1431 if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
1432 struct cryptodev *cryptodev;
1434 if (n_tokens < t0 + 5 ||
1435 strcmp(tokens[t0 + 1], "dev") ||
1436 strcmp(tokens[t0 + 3], "offset")) {
1437 snprintf(out, out_size, MSG_ARG_MISMATCH,
1438 "table action profile sym_crypto");
1442 cryptodev = cryptodev_find(tokens[t0 + 2]);
1443 if (cryptodev == NULL) {
1444 snprintf(out, out_size, MSG_ARG_INVALID,
1445 "table action profile sym_crypto");
1449 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
1451 if (parser_read_uint32(&p.sym_crypto.op_offset,
1452 tokens[t0 + 4]) != 0) {
1453 snprintf(out, out_size, MSG_ARG_INVALID,
1454 "table action profile sym_crypto");
1458 p.sym_crypto.mp_create = cryptodev->mp_create;
1459 p.sym_crypto.mp_init = cryptodev->mp_init;
1461 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
1466 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {
1467 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
1471 if ((t0 < n_tokens) && (strcmp(tokens[t0], "decap") == 0)) {
1472 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1476 if (t0 < n_tokens) {
1477 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1481 ap = table_action_profile_create(name, &p);
1483 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1488 static const char cmd_pipeline_help[] =
1489 "pipeline <pipeline_name>\n"
1490 " period <timer_period_ms>\n"
1491 " offset_port_id <offset_port_id>\n"
1495 cmd_pipeline(char **tokens,
1500 struct pipeline_params p;
1502 struct pipeline *pipeline;
1504 if (n_tokens != 8) {
1505 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1511 if (strcmp(tokens[2], "period") != 0) {
1512 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1516 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1517 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1521 if (strcmp(tokens[4], "offset_port_id") != 0) {
1522 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1526 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1527 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1531 if (strcmp(tokens[6], "cpu") != 0) {
1532 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1536 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1537 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1541 pipeline = pipeline_create(name, &p);
1542 if (pipeline == NULL) {
1543 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1548 static const char cmd_pipeline_port_in_help[] =
1549 "pipeline <pipeline_name> port in\n"
1550 " bsz <burst_size>\n"
1551 " link <link_name> rxq <queue_id>\n"
1552 " | swq <swq_name>\n"
1553 " | tmgr <tmgr_name>\n"
1554 " | tap <tap_name> mempool <mempool_name> mtu <mtu>\n"
1555 " | kni <kni_name>\n"
1556 " | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>\n"
1557 " | cryptodev <cryptodev_name> rxq <queue_id>\n"
1558 " [action <port_in_action_profile_name>]\n"
1562 cmd_pipeline_port_in(char **tokens,
1567 struct port_in_params p;
1568 char *pipeline_name;
1570 int enabled, status;
1573 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1577 pipeline_name = tokens[1];
1579 if (strcmp(tokens[2], "port") != 0) {
1580 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1584 if (strcmp(tokens[3], "in") != 0) {
1585 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1589 if (strcmp(tokens[4], "bsz") != 0) {
1590 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1594 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1595 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1601 if (strcmp(tokens[t0], "link") == 0) {
1602 if (n_tokens < t0 + 4) {
1603 snprintf(out, out_size, MSG_ARG_MISMATCH,
1604 "pipeline port in link");
1608 p.type = PORT_IN_RXQ;
1610 p.dev_name = tokens[t0 + 1];
1612 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1613 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1617 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1618 snprintf(out, out_size, MSG_ARG_INVALID,
1623 } else if (strcmp(tokens[t0], "swq") == 0) {
1624 if (n_tokens < t0 + 2) {
1625 snprintf(out, out_size, MSG_ARG_MISMATCH,
1626 "pipeline port in swq");
1630 p.type = PORT_IN_SWQ;
1632 p.dev_name = tokens[t0 + 1];
1635 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1636 if (n_tokens < t0 + 2) {
1637 snprintf(out, out_size, MSG_ARG_MISMATCH,
1638 "pipeline port in tmgr");
1642 p.type = PORT_IN_TMGR;
1644 p.dev_name = tokens[t0 + 1];
1647 } else if (strcmp(tokens[t0], "tap") == 0) {
1648 if (n_tokens < t0 + 6) {
1649 snprintf(out, out_size, MSG_ARG_MISMATCH,
1650 "pipeline port in tap");
1654 p.type = PORT_IN_TAP;
1656 p.dev_name = tokens[t0 + 1];
1658 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1659 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1664 p.tap.mempool_name = tokens[t0 + 3];
1666 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1667 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1672 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1673 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1678 } else if (strcmp(tokens[t0], "kni") == 0) {
1679 if (n_tokens < t0 + 2) {
1680 snprintf(out, out_size, MSG_ARG_MISMATCH,
1681 "pipeline port in kni");
1685 p.type = PORT_IN_KNI;
1687 p.dev_name = tokens[t0 + 1];
1690 } else if (strcmp(tokens[t0], "source") == 0) {
1691 if (n_tokens < t0 + 6) {
1692 snprintf(out, out_size, MSG_ARG_MISMATCH,
1693 "pipeline port in source");
1697 p.type = PORT_IN_SOURCE;
1701 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1702 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1707 p.source.mempool_name = tokens[t0 + 2];
1709 if (strcmp(tokens[t0 + 3], "file") != 0) {
1710 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1715 p.source.file_name = tokens[t0 + 4];
1717 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1718 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1723 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1724 snprintf(out, out_size, MSG_ARG_INVALID,
1730 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
1731 if (n_tokens < t0 + 3) {
1732 snprintf(out, out_size, MSG_ARG_MISMATCH,
1733 "pipeline port in cryptodev");
1737 p.type = PORT_IN_CRYPTODEV;
1739 p.dev_name = tokens[t0 + 1];
1740 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1741 snprintf(out, out_size, MSG_ARG_INVALID,
1746 p.cryptodev.arg_callback = NULL;
1747 p.cryptodev.f_callback = NULL;
1751 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1755 p.action_profile_name = NULL;
1756 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1757 if (n_tokens < t0 + 2) {
1758 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1762 p.action_profile_name = tokens[t0 + 1];
1768 if ((n_tokens > t0) &&
1769 (strcmp(tokens[t0], "disabled") == 0)) {
1775 if (n_tokens != t0) {
1776 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1780 status = pipeline_port_in_create(pipeline_name,
1783 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1788 static const char cmd_pipeline_port_out_help[] =
1789 "pipeline <pipeline_name> port out\n"
1790 " bsz <burst_size>\n"
1791 " link <link_name> txq <txq_id>\n"
1792 " | swq <swq_name>\n"
1793 " | tmgr <tmgr_name>\n"
1794 " | tap <tap_name>\n"
1795 " | kni <kni_name>\n"
1796 " | sink [file <file_name> pkts <max_n_pkts>]\n"
1797 " | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>\n";
1800 cmd_pipeline_port_out(char **tokens,
1805 struct port_out_params p;
1806 char *pipeline_name;
1809 memset(&p, 0, sizeof(p));
1812 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1816 pipeline_name = tokens[1];
1818 if (strcmp(tokens[2], "port") != 0) {
1819 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1823 if (strcmp(tokens[3], "out") != 0) {
1824 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1828 if (strcmp(tokens[4], "bsz") != 0) {
1829 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1833 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1834 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1838 if (strcmp(tokens[6], "link") == 0) {
1839 if (n_tokens != 10) {
1840 snprintf(out, out_size, MSG_ARG_MISMATCH,
1841 "pipeline port out link");
1845 p.type = PORT_OUT_TXQ;
1847 p.dev_name = tokens[7];
1849 if (strcmp(tokens[8], "txq") != 0) {
1850 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1854 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1855 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1858 } else if (strcmp(tokens[6], "swq") == 0) {
1859 if (n_tokens != 8) {
1860 snprintf(out, out_size, MSG_ARG_MISMATCH,
1861 "pipeline port out swq");
1865 p.type = PORT_OUT_SWQ;
1867 p.dev_name = tokens[7];
1868 } else if (strcmp(tokens[6], "tmgr") == 0) {
1869 if (n_tokens != 8) {
1870 snprintf(out, out_size, MSG_ARG_MISMATCH,
1871 "pipeline port out tmgr");
1875 p.type = PORT_OUT_TMGR;
1877 p.dev_name = tokens[7];
1878 } else if (strcmp(tokens[6], "tap") == 0) {
1879 if (n_tokens != 8) {
1880 snprintf(out, out_size, MSG_ARG_MISMATCH,
1881 "pipeline port out tap");
1885 p.type = PORT_OUT_TAP;
1887 p.dev_name = tokens[7];
1888 } else if (strcmp(tokens[6], "kni") == 0) {
1889 if (n_tokens != 8) {
1890 snprintf(out, out_size, MSG_ARG_MISMATCH,
1891 "pipeline port out kni");
1895 p.type = PORT_OUT_KNI;
1897 p.dev_name = tokens[7];
1898 } else if (strcmp(tokens[6], "sink") == 0) {
1899 if ((n_tokens != 7) && (n_tokens != 11)) {
1900 snprintf(out, out_size, MSG_ARG_MISMATCH,
1901 "pipeline port out sink");
1905 p.type = PORT_OUT_SINK;
1909 if (n_tokens == 7) {
1910 p.sink.file_name = NULL;
1911 p.sink.max_n_pkts = 0;
1913 if (strcmp(tokens[7], "file") != 0) {
1914 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1919 p.sink.file_name = tokens[8];
1921 if (strcmp(tokens[9], "pkts") != 0) {
1922 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1926 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1927 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1932 } else if (strcmp(tokens[6], "cryptodev") == 0) {
1933 if (n_tokens != 12) {
1934 snprintf(out, out_size, MSG_ARG_MISMATCH,
1935 "pipeline port out cryptodev");
1939 p.type = PORT_OUT_CRYPTODEV;
1941 p.dev_name = tokens[7];
1943 if (strcmp(tokens[8], "txq")) {
1944 snprintf(out, out_size, MSG_ARG_MISMATCH,
1945 "pipeline port out cryptodev");
1949 if (parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
1951 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1955 if (strcmp(tokens[10], "offset")) {
1956 snprintf(out, out_size, MSG_ARG_MISMATCH,
1957 "pipeline port out cryptodev");
1961 if (parser_read_uint32(&p.cryptodev.op_offset, tokens[11])
1963 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1967 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1971 status = pipeline_port_out_create(pipeline_name, &p);
1973 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1978 static const char cmd_pipeline_table_help[] =
1979 "pipeline <pipeline_name> table\n"
1983 " offset <ip_header_offset>\n"
1986 " offset <key_offset>\n"
1991 " mask <key_mask>\n"
1992 " offset <key_offset>\n"
1993 " buckets <n_buckets>\n"
1997 " offset <ip_header_offset>\n"
2000 " [action <table_action_profile_name>]\n";
2003 cmd_pipeline_table(char **tokens,
2008 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
2009 struct table_params p;
2010 char *pipeline_name;
2015 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2019 pipeline_name = tokens[1];
2021 if (strcmp(tokens[2], "table") != 0) {
2022 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2026 if (strcmp(tokens[3], "match") != 0) {
2027 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2032 if (strcmp(tokens[t0], "acl") == 0) {
2033 if (n_tokens < t0 + 6) {
2034 snprintf(out, out_size, MSG_ARG_MISMATCH,
2035 "pipeline table acl");
2039 p.match_type = TABLE_ACL;
2041 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2042 p.match.acl.ip_version = 1;
2043 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2044 p.match.acl.ip_version = 0;
2046 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2051 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2052 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2056 if (parser_read_uint32(&p.match.acl.ip_header_offset,
2057 tokens[t0 + 3]) != 0) {
2058 snprintf(out, out_size, MSG_ARG_INVALID,
2059 "ip_header_offset");
2063 if (strcmp(tokens[t0 + 4], "size") != 0) {
2064 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2068 if (parser_read_uint32(&p.match.acl.n_rules,
2069 tokens[t0 + 5]) != 0) {
2070 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2075 } else if (strcmp(tokens[t0], "array") == 0) {
2076 if (n_tokens < t0 + 5) {
2077 snprintf(out, out_size, MSG_ARG_MISMATCH,
2078 "pipeline table array");
2082 p.match_type = TABLE_ARRAY;
2084 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2085 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2089 if (parser_read_uint32(&p.match.array.key_offset,
2090 tokens[t0 + 2]) != 0) {
2091 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2095 if (strcmp(tokens[t0 + 3], "size") != 0) {
2096 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2100 if (parser_read_uint32(&p.match.array.n_keys,
2101 tokens[t0 + 4]) != 0) {
2102 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2107 } else if (strcmp(tokens[t0], "hash") == 0) {
2108 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2110 if (n_tokens < t0 + 12) {
2111 snprintf(out, out_size, MSG_ARG_MISMATCH,
2112 "pipeline table hash");
2116 p.match_type = TABLE_HASH;
2118 if (strcmp(tokens[t0 + 1], "ext") == 0)
2119 p.match.hash.extendable_bucket = 1;
2120 else if (strcmp(tokens[t0 + 1], "lru") == 0)
2121 p.match.hash.extendable_bucket = 0;
2123 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2128 if (strcmp(tokens[t0 + 2], "key") != 0) {
2129 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2133 if ((parser_read_uint32(&p.match.hash.key_size,
2134 tokens[t0 + 3]) != 0) ||
2135 (p.match.hash.key_size == 0) ||
2136 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
2137 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2141 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2142 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2146 if ((parse_hex_string(tokens[t0 + 5],
2147 key_mask, &key_mask_size) != 0) ||
2148 (key_mask_size != p.match.hash.key_size)) {
2149 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2152 p.match.hash.key_mask = key_mask;
2154 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2155 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2159 if (parser_read_uint32(&p.match.hash.key_offset,
2160 tokens[t0 + 7]) != 0) {
2161 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2165 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2166 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2170 if (parser_read_uint32(&p.match.hash.n_buckets,
2171 tokens[t0 + 9]) != 0) {
2172 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2176 if (strcmp(tokens[t0 + 10], "size") != 0) {
2177 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2181 if (parser_read_uint32(&p.match.hash.n_keys,
2182 tokens[t0 + 11]) != 0) {
2183 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2188 } else if (strcmp(tokens[t0], "lpm") == 0) {
2189 if (n_tokens < t0 + 6) {
2190 snprintf(out, out_size, MSG_ARG_MISMATCH,
2191 "pipeline table lpm");
2195 p.match_type = TABLE_LPM;
2197 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2198 p.match.lpm.key_size = 4;
2199 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2200 p.match.lpm.key_size = 16;
2202 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2207 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2208 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2212 if (parser_read_uint32(&p.match.lpm.key_offset,
2213 tokens[t0 + 3]) != 0) {
2214 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2218 if (strcmp(tokens[t0 + 4], "size") != 0) {
2219 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2223 if (parser_read_uint32(&p.match.lpm.n_rules,
2224 tokens[t0 + 5]) != 0) {
2225 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2230 } else if (strcmp(tokens[t0], "stub") == 0) {
2231 p.match_type = TABLE_STUB;
2235 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2239 p.action_profile_name = NULL;
2240 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
2241 if (n_tokens < t0 + 2) {
2242 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2246 p.action_profile_name = tokens[t0 + 1];
2251 if (n_tokens > t0) {
2252 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2256 status = pipeline_table_create(pipeline_name, &p);
2258 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2263 static const char cmd_pipeline_port_in_table_help[] =
2264 "pipeline <pipeline_name> port in <port_id> table <table_id>\n";
2267 cmd_pipeline_port_in_table(char **tokens,
2272 char *pipeline_name;
2273 uint32_t port_id, table_id;
2276 if (n_tokens != 7) {
2277 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2281 pipeline_name = tokens[1];
2283 if (strcmp(tokens[2], "port") != 0) {
2284 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2288 if (strcmp(tokens[3], "in") != 0) {
2289 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2293 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2294 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2298 if (strcmp(tokens[5], "table") != 0) {
2299 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2303 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
2304 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2308 status = pipeline_port_in_connect_to_table(pipeline_name,
2312 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2318 static const char cmd_pipeline_port_in_stats_help[] =
2319 "pipeline <pipeline_name> port in <port_id> stats read [clear]\n";
2321 #define MSG_PIPELINE_PORT_IN_STATS \
2322 "Pkts in: %" PRIu64 "\n" \
2323 "Pkts dropped by AH: %" PRIu64 "\n" \
2324 "Pkts dropped by other: %" PRIu64 "\n"
2327 cmd_pipeline_port_in_stats(char **tokens,
2332 struct rte_pipeline_port_in_stats stats;
2333 char *pipeline_name;
2337 if ((n_tokens != 7) && (n_tokens != 8)) {
2338 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2342 pipeline_name = tokens[1];
2344 if (strcmp(tokens[2], "port") != 0) {
2345 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2349 if (strcmp(tokens[3], "in") != 0) {
2350 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2354 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2355 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2359 if (strcmp(tokens[5], "stats") != 0) {
2360 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2364 if (strcmp(tokens[6], "read") != 0) {
2365 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2370 if (n_tokens == 8) {
2371 if (strcmp(tokens[7], "clear") != 0) {
2372 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2379 status = pipeline_port_in_stats_read(pipeline_name,
2384 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2388 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2389 stats.stats.n_pkts_in,
2390 stats.n_pkts_dropped_by_ah,
2391 stats.stats.n_pkts_drop);
2395 static const char cmd_pipeline_port_in_enable_help[] =
2396 "pipeline <pipeline_name> port in <port_id> enable\n";
2399 cmd_pipeline_port_in_enable(char **tokens,
2404 char *pipeline_name;
2408 if (n_tokens != 6) {
2409 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2413 pipeline_name = tokens[1];
2415 if (strcmp(tokens[2], "port") != 0) {
2416 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2420 if (strcmp(tokens[3], "in") != 0) {
2421 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2425 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2426 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2430 if (strcmp(tokens[5], "enable") != 0) {
2431 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2435 status = pipeline_port_in_enable(pipeline_name, port_id);
2437 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2443 static const char cmd_pipeline_port_in_disable_help[] =
2444 "pipeline <pipeline_name> port in <port_id> disable\n";
2447 cmd_pipeline_port_in_disable(char **tokens,
2452 char *pipeline_name;
2456 if (n_tokens != 6) {
2457 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2461 pipeline_name = tokens[1];
2463 if (strcmp(tokens[2], "port") != 0) {
2464 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2468 if (strcmp(tokens[3], "in") != 0) {
2469 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2473 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2474 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2478 if (strcmp(tokens[5], "disable") != 0) {
2479 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2483 status = pipeline_port_in_disable(pipeline_name, port_id);
2485 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2491 static const char cmd_pipeline_port_out_stats_help[] =
2492 "pipeline <pipeline_name> port out <port_id> stats read [clear]\n";
2494 #define MSG_PIPELINE_PORT_OUT_STATS \
2495 "Pkts in: %" PRIu64 "\n" \
2496 "Pkts dropped by AH: %" PRIu64 "\n" \
2497 "Pkts dropped by other: %" PRIu64 "\n"
2500 cmd_pipeline_port_out_stats(char **tokens,
2505 struct rte_pipeline_port_out_stats stats;
2506 char *pipeline_name;
2510 if ((n_tokens != 7) && (n_tokens != 8)) {
2511 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2515 pipeline_name = tokens[1];
2517 if (strcmp(tokens[2], "port") != 0) {
2518 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2522 if (strcmp(tokens[3], "out") != 0) {
2523 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2527 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2528 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2532 if (strcmp(tokens[5], "stats") != 0) {
2533 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2537 if (strcmp(tokens[6], "read") != 0) {
2538 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2543 if (n_tokens == 8) {
2544 if (strcmp(tokens[7], "clear") != 0) {
2545 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2552 status = pipeline_port_out_stats_read(pipeline_name,
2557 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2561 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2562 stats.stats.n_pkts_in,
2563 stats.n_pkts_dropped_by_ah,
2564 stats.stats.n_pkts_drop);
2568 static const char cmd_pipeline_table_stats_help[] =
2569 "pipeline <pipeline_name> table <table_id> stats read [clear]\n";
2571 #define MSG_PIPELINE_TABLE_STATS \
2572 "Pkts in: %" PRIu64 "\n" \
2573 "Pkts in with lookup miss: %" PRIu64 "\n" \
2574 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2575 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2576 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2577 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2580 cmd_pipeline_table_stats(char **tokens,
2585 struct rte_pipeline_table_stats stats;
2586 char *pipeline_name;
2590 if ((n_tokens != 6) && (n_tokens != 7)) {
2591 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2595 pipeline_name = tokens[1];
2597 if (strcmp(tokens[2], "table") != 0) {
2598 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2602 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2603 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2607 if (strcmp(tokens[4], "stats") != 0) {
2608 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2612 if (strcmp(tokens[5], "read") != 0) {
2613 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2618 if (n_tokens == 7) {
2619 if (strcmp(tokens[6], "clear") != 0) {
2620 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2627 status = pipeline_table_stats_read(pipeline_name,
2632 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2636 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2637 stats.stats.n_pkts_in,
2638 stats.stats.n_pkts_lookup_miss,
2639 stats.n_pkts_dropped_by_lkp_hit_ah,
2640 stats.n_pkts_dropped_lkp_hit,
2641 stats.n_pkts_dropped_by_lkp_miss_ah,
2642 stats.n_pkts_dropped_lkp_miss);
2650 * priority <priority>
2651 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2652 * <sp0> <sp1> <dp0> <dp1> <proto>
2656 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2657 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2658 * | ipv4_addr <addr>
2659 * | ipv6_addr <addr>
2660 * | qinq <svlan> <cvlan>
2662 * ipv4 | ipv6 <addr> <depth>
2664 struct pkt_key_qinq {
2665 uint16_t ethertype_svlan;
2667 uint16_t ethertype_cvlan;
2669 } __attribute__((__packed__));
2671 struct pkt_key_ipv4_5tuple {
2672 uint8_t time_to_live;
2674 uint16_t hdr_checksum;
2679 } __attribute__((__packed__));
2681 struct pkt_key_ipv6_5tuple {
2682 uint16_t payload_length;
2689 } __attribute__((__packed__));
2691 struct pkt_key_ipv4_addr {
2693 } __attribute__((__packed__));
2695 struct pkt_key_ipv6_addr {
2697 } __attribute__((__packed__));
2700 parse_match(char **tokens,
2704 struct table_rule_match *m)
2706 memset(m, 0, sizeof(*m));
2711 if (strcmp(tokens[0], "match") != 0) {
2712 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2716 if (strcmp(tokens[1], "acl") == 0) {
2717 if (n_tokens < 14) {
2718 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2722 m->match_type = TABLE_ACL;
2724 if (strcmp(tokens[2], "priority") != 0) {
2725 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2729 if (parser_read_uint32(&m->match.acl.priority,
2731 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2735 if (strcmp(tokens[4], "ipv4") == 0) {
2736 struct in_addr saddr, daddr;
2738 m->match.acl.ip_version = 1;
2740 if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2741 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2744 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2746 if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2747 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2750 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2751 } else if (strcmp(tokens[4], "ipv6") == 0) {
2752 struct in6_addr saddr, daddr;
2754 m->match.acl.ip_version = 0;
2756 if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2757 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2760 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2762 if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2763 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2766 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2768 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2773 if (parser_read_uint32(&m->match.acl.sa_depth,
2775 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2779 if (parser_read_uint32(&m->match.acl.da_depth,
2781 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2785 if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2786 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2790 if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2791 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2795 if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2796 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2800 if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2801 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2805 if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2806 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2810 m->match.acl.proto_mask = 0xff;
2815 if (strcmp(tokens[1], "array") == 0) {
2817 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2821 m->match_type = TABLE_ARRAY;
2823 if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2824 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2831 if (strcmp(tokens[1], "hash") == 0) {
2833 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2837 m->match_type = TABLE_HASH;
2839 if (strcmp(tokens[2], "raw") == 0) {
2840 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2843 snprintf(out, out_size, MSG_ARG_MISMATCH,
2848 if (parse_hex_string(tokens[3],
2849 m->match.hash.key, &key_size) != 0) {
2850 snprintf(out, out_size, MSG_ARG_INVALID, "key");
2857 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2858 struct pkt_key_ipv4_5tuple *ipv4 =
2859 (struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2860 struct in_addr saddr, daddr;
2865 snprintf(out, out_size, MSG_ARG_MISMATCH,
2870 if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2871 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2875 if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2876 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2880 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2881 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2885 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2886 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2890 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2891 snprintf(out, out_size, MSG_ARG_INVALID,
2896 ipv4->sa = saddr.s_addr;
2897 ipv4->da = daddr.s_addr;
2898 ipv4->sp = rte_cpu_to_be_16(sp);
2899 ipv4->dp = rte_cpu_to_be_16(dp);
2900 ipv4->proto = proto;
2903 } /* hash ipv4_5tuple */
2905 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2906 struct pkt_key_ipv6_5tuple *ipv6 =
2907 (struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2908 struct in6_addr saddr, daddr;
2913 snprintf(out, out_size, MSG_ARG_MISMATCH,
2918 if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2919 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2923 if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2924 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2928 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2929 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2933 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2934 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2938 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2939 snprintf(out, out_size, MSG_ARG_INVALID,
2944 memcpy(ipv6->sa, saddr.s6_addr, 16);
2945 memcpy(ipv6->da, daddr.s6_addr, 16);
2946 ipv6->sp = rte_cpu_to_be_16(sp);
2947 ipv6->dp = rte_cpu_to_be_16(dp);
2948 ipv6->proto = proto;
2951 } /* hash ipv6_5tuple */
2953 if (strcmp(tokens[2], "ipv4_addr") == 0) {
2954 struct pkt_key_ipv4_addr *ipv4_addr =
2955 (struct pkt_key_ipv4_addr *) m->match.hash.key;
2956 struct in_addr addr;
2959 snprintf(out, out_size, MSG_ARG_MISMATCH,
2964 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2965 snprintf(out, out_size, MSG_ARG_INVALID,
2970 ipv4_addr->addr = addr.s_addr;
2973 } /* hash ipv4_addr */
2975 if (strcmp(tokens[2], "ipv6_addr") == 0) {
2976 struct pkt_key_ipv6_addr *ipv6_addr =
2977 (struct pkt_key_ipv6_addr *) m->match.hash.key;
2978 struct in6_addr addr;
2981 snprintf(out, out_size, MSG_ARG_MISMATCH,
2986 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2987 snprintf(out, out_size, MSG_ARG_INVALID,
2992 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
2995 } /* hash ipv6_5tuple */
2997 if (strcmp(tokens[2], "qinq") == 0) {
2998 struct pkt_key_qinq *qinq =
2999 (struct pkt_key_qinq *) m->match.hash.key;
3000 uint16_t svlan, cvlan;
3003 snprintf(out, out_size, MSG_ARG_MISMATCH,
3008 if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
3010 snprintf(out, out_size, MSG_ARG_INVALID,
3015 if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3017 snprintf(out, out_size, MSG_ARG_INVALID,
3022 qinq->svlan = rte_cpu_to_be_16(svlan);
3023 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3028 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3032 if (strcmp(tokens[1], "lpm") == 0) {
3034 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3038 m->match_type = TABLE_LPM;
3040 if (strcmp(tokens[2], "ipv4") == 0) {
3041 struct in_addr addr;
3043 m->match.lpm.ip_version = 1;
3045 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
3046 snprintf(out, out_size, MSG_ARG_INVALID,
3051 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3052 } else if (strcmp(tokens[2], "ipv6") == 0) {
3053 struct in6_addr addr;
3055 m->match.lpm.ip_version = 0;
3057 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
3058 snprintf(out, out_size, MSG_ARG_INVALID,
3063 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3065 snprintf(out, out_size, MSG_ARG_MISMATCH,
3070 if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3071 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3078 snprintf(out, out_size, MSG_ARG_MISMATCH,
3079 "acl or array or hash or lpm");
3091 * | table <table_id>
3092 * [balance <out0> ... <out7>]
3094 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3095 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3096 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3097 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3098 * [tm subport <subport_id> pipe <pipe_id>]
3101 * | vlan <da> <sa> <pcp> <dei> <vid>
3102 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3103 * | qinq_pppoe <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid> <session_id>
3104 * | mpls unicast | multicast
3106 * label0 <label> <tc> <ttl>
3107 * [label1 <label> <tc> <ttl>
3108 * [label2 <label> <tc> <ttl>
3109 * [label3 <label> <tc> <ttl>]]]
3110 * | pppoe <da> <sa> <session_id>
3111 * | vxlan ether <da> <sa>
3112 * [vlan <pcp> <dei> <vid>]
3113 * ipv4 <sa> <da> <dscp> <ttl>
3114 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3117 * [nat ipv4 | ipv6 <addr> <port>]
3125 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3127 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3128 * auth_algo <algo> auth_key <key> digest_size <size>
3130 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3131 * digest_size <size>
3132 * data_offset <data_offset>]
3137 * <pa> ::= g | y | r | drop
3140 parse_table_action_fwd(char **tokens,
3142 struct table_rule_action *a)
3144 if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
3150 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3151 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3152 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3156 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3159 if ((n_tokens < 2) ||
3160 parser_read_uint32(&id, tokens[1]))
3163 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3165 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3169 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3170 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3171 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3175 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3178 if ((n_tokens < 2) ||
3179 parser_read_uint32(&id, tokens[1]))
3182 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3184 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3192 parse_table_action_balance(char **tokens,
3194 struct table_rule_action *a)
3198 if ((n_tokens == 0) || (strcmp(tokens[0], "balance") != 0))
3204 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3207 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3208 if (parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3211 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3212 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3217 parse_policer_action(char *token, enum rte_table_action_policer *a)
3219 if (strcmp(token, "g") == 0) {
3220 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3224 if (strcmp(token, "y") == 0) {
3225 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3229 if (strcmp(token, "r") == 0) {
3230 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3234 if (strcmp(token, "drop") == 0) {
3235 *a = RTE_TABLE_ACTION_POLICER_DROP;
3243 parse_table_action_meter_tc(char **tokens,
3245 struct rte_table_action_mtr_tc_params *mtr)
3247 if ((n_tokens < 9) ||
3248 strcmp(tokens[0], "meter") ||
3249 parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3250 strcmp(tokens[2], "policer") ||
3251 strcmp(tokens[3], "g") ||
3252 parse_policer_action(tokens[4], &mtr->policer[RTE_COLOR_GREEN]) ||
3253 strcmp(tokens[5], "y") ||
3254 parse_policer_action(tokens[6], &mtr->policer[RTE_COLOR_YELLOW]) ||
3255 strcmp(tokens[7], "r") ||
3256 parse_policer_action(tokens[8], &mtr->policer[RTE_COLOR_RED]))
3263 parse_table_action_meter(char **tokens,
3265 struct table_rule_action *a)
3267 if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
3273 if ((n_tokens < 10) ||
3274 strcmp(tokens[0], "tc0") ||
3275 (parse_table_action_meter_tc(tokens + 1,
3277 &a->mtr.mtr[0]) == 0))
3283 if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
3285 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3289 if ((n_tokens < 30) ||
3290 (parse_table_action_meter_tc(tokens + 1,
3291 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3292 strcmp(tokens[10], "tc2") ||
3293 (parse_table_action_meter_tc(tokens + 11,
3294 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3295 strcmp(tokens[20], "tc3") ||
3296 (parse_table_action_meter_tc(tokens + 21,
3297 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3300 a->mtr.tc_mask = 0xF;
3301 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3302 return 1 + 10 + 3 * 10;
3306 parse_table_action_tm(char **tokens,
3308 struct table_rule_action *a)
3310 uint32_t subport_id, pipe_id;
3312 if ((n_tokens < 5) ||
3313 strcmp(tokens[0], "tm") ||
3314 strcmp(tokens[1], "subport") ||
3315 parser_read_uint32(&subport_id, tokens[2]) ||
3316 strcmp(tokens[3], "pipe") ||
3317 parser_read_uint32(&pipe_id, tokens[4]))
3320 a->tm.subport_id = subport_id;
3321 a->tm.pipe_id = pipe_id;
3322 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3327 parse_table_action_encap(char **tokens,
3329 struct table_rule_action *a)
3331 if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
3338 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3339 if ((n_tokens < 3) ||
3340 parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3341 parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3344 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3345 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3350 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3351 uint32_t pcp, dei, vid;
3353 if ((n_tokens < 6) ||
3354 parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3355 parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3356 parser_read_uint32(&pcp, tokens[3]) ||
3358 parser_read_uint32(&dei, tokens[4]) ||
3360 parser_read_uint32(&vid, tokens[5]) ||
3364 a->encap.vlan.vlan.pcp = pcp & 0x7;
3365 a->encap.vlan.vlan.dei = dei & 0x1;
3366 a->encap.vlan.vlan.vid = vid & 0xFFF;
3367 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3368 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3373 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3374 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3375 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3377 if ((n_tokens < 9) ||
3378 parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3379 parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3380 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3381 (svlan_pcp > 0x7) ||
3382 parser_read_uint32(&svlan_dei, tokens[4]) ||
3383 (svlan_dei > 0x1) ||
3384 parser_read_uint32(&svlan_vid, tokens[5]) ||
3385 (svlan_vid > 0xFFF) ||
3386 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3387 (cvlan_pcp > 0x7) ||
3388 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3389 (cvlan_dei > 0x1) ||
3390 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3391 (cvlan_vid > 0xFFF))
3394 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3395 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3396 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3397 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3398 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3399 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3400 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3401 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3406 if (n_tokens && (strcmp(tokens[0], "qinq_pppoe") == 0)) {
3407 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3408 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3410 if ((n_tokens < 10) ||
3411 parse_mac_addr(tokens[1],
3412 &a->encap.qinq_pppoe.ether.da) ||
3413 parse_mac_addr(tokens[2],
3414 &a->encap.qinq_pppoe.ether.sa) ||
3415 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3416 (svlan_pcp > 0x7) ||
3417 parser_read_uint32(&svlan_dei, tokens[4]) ||
3418 (svlan_dei > 0x1) ||
3419 parser_read_uint32(&svlan_vid, tokens[5]) ||
3420 (svlan_vid > 0xFFF) ||
3421 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3422 (cvlan_pcp > 0x7) ||
3423 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3424 (cvlan_dei > 0x1) ||
3425 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3426 (cvlan_vid > 0xFFF) ||
3427 parser_read_uint16(&a->encap.qinq_pppoe.pppoe.session_id,
3431 a->encap.qinq_pppoe.svlan.pcp = svlan_pcp & 0x7;
3432 a->encap.qinq_pppoe.svlan.dei = svlan_dei & 0x1;
3433 a->encap.qinq_pppoe.svlan.vid = svlan_vid & 0xFFF;
3434 a->encap.qinq_pppoe.cvlan.pcp = cvlan_pcp & 0x7;
3435 a->encap.qinq_pppoe.cvlan.dei = cvlan_dei & 0x1;
3436 a->encap.qinq_pppoe.cvlan.vid = cvlan_vid & 0xFFF;
3437 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
3438 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3444 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3445 uint32_t label, tc, ttl;
3450 if (strcmp(tokens[1], "unicast") == 0)
3451 a->encap.mpls.unicast = 1;
3452 else if (strcmp(tokens[1], "multicast") == 0)
3453 a->encap.mpls.unicast = 0;
3457 if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3458 parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3459 strcmp(tokens[4], "label0") ||
3460 parser_read_uint32(&label, tokens[5]) ||
3461 (label > 0xFFFFF) ||
3462 parser_read_uint32(&tc, tokens[6]) ||
3464 parser_read_uint32(&ttl, tokens[7]) ||
3468 a->encap.mpls.mpls[0].label = label;
3469 a->encap.mpls.mpls[0].tc = tc;
3470 a->encap.mpls.mpls[0].ttl = ttl;
3475 if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3476 a->encap.mpls.mpls_count = 1;
3477 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3478 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3482 if ((n_tokens < 4) ||
3483 parser_read_uint32(&label, tokens[1]) ||
3484 (label > 0xFFFFF) ||
3485 parser_read_uint32(&tc, tokens[2]) ||
3487 parser_read_uint32(&ttl, tokens[3]) ||
3491 a->encap.mpls.mpls[1].label = label;
3492 a->encap.mpls.mpls[1].tc = tc;
3493 a->encap.mpls.mpls[1].ttl = ttl;
3498 if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3499 a->encap.mpls.mpls_count = 2;
3500 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3501 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3505 if ((n_tokens < 4) ||
3506 parser_read_uint32(&label, tokens[1]) ||
3507 (label > 0xFFFFF) ||
3508 parser_read_uint32(&tc, tokens[2]) ||
3510 parser_read_uint32(&ttl, tokens[3]) ||
3514 a->encap.mpls.mpls[2].label = label;
3515 a->encap.mpls.mpls[2].tc = tc;
3516 a->encap.mpls.mpls[2].ttl = ttl;
3521 if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3522 a->encap.mpls.mpls_count = 3;
3523 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3524 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3525 return 1 + 8 + 4 + 4;
3528 if ((n_tokens < 4) ||
3529 parser_read_uint32(&label, tokens[1]) ||
3530 (label > 0xFFFFF) ||
3531 parser_read_uint32(&tc, tokens[2]) ||
3533 parser_read_uint32(&ttl, tokens[3]) ||
3537 a->encap.mpls.mpls[3].label = label;
3538 a->encap.mpls.mpls[3].tc = tc;
3539 a->encap.mpls.mpls[3].ttl = ttl;
3541 a->encap.mpls.mpls_count = 4;
3542 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3543 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3544 return 1 + 8 + 4 + 4 + 4;
3548 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3549 if ((n_tokens < 4) ||
3550 parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3551 parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3552 parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3556 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3557 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3562 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3569 /* ether <da> <sa> */
3570 if ((n_tokens < 3) ||
3571 strcmp(tokens[0], "ether") ||
3572 parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3573 parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3580 /* [vlan <pcp> <dei> <vid>] */
3581 if (strcmp(tokens[0], "vlan") == 0) {
3582 uint32_t pcp, dei, vid;
3584 if ((n_tokens < 4) ||
3585 parser_read_uint32(&pcp, tokens[1]) ||
3587 parser_read_uint32(&dei, tokens[2]) ||
3589 parser_read_uint32(&vid, tokens[3]) ||
3593 a->encap.vxlan.vlan.pcp = pcp;
3594 a->encap.vxlan.vlan.dei = dei;
3595 a->encap.vxlan.vlan.vid = vid;
3602 /* ipv4 <sa> <da> <dscp> <ttl>
3603 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3604 if (strcmp(tokens[0], "ipv4") == 0) {
3605 struct in_addr sa, da;
3608 if ((n_tokens < 5) ||
3609 parse_ipv4_addr(tokens[1], &sa) ||
3610 parse_ipv4_addr(tokens[2], &da) ||
3611 parser_read_uint8(&dscp, tokens[3]) ||
3613 parser_read_uint8(&ttl, tokens[4]))
3616 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3617 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3618 a->encap.vxlan.ipv4.dscp = dscp;
3619 a->encap.vxlan.ipv4.ttl = ttl;
3624 } else if (strcmp(tokens[0], "ipv6") == 0) {
3625 struct in6_addr sa, da;
3626 uint32_t flow_label;
3627 uint8_t dscp, hop_limit;
3629 if ((n_tokens < 6) ||
3630 parse_ipv6_addr(tokens[1], &sa) ||
3631 parse_ipv6_addr(tokens[2], &da) ||
3632 parser_read_uint32(&flow_label, tokens[3]) ||
3633 parser_read_uint8(&dscp, tokens[4]) ||
3635 parser_read_uint8(&hop_limit, tokens[5]))
3638 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3639 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3640 a->encap.vxlan.ipv6.flow_label = flow_label;
3641 a->encap.vxlan.ipv6.dscp = dscp;
3642 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3651 if ((n_tokens < 3) ||
3652 strcmp(tokens[0], "udp") ||
3653 parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3654 parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3662 if ((n_tokens < 2) ||
3663 strcmp(tokens[0], "vxlan") ||
3664 parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3665 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3672 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3673 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3681 parse_table_action_nat(char **tokens,
3683 struct table_rule_action *a)
3685 if ((n_tokens < 4) ||
3686 strcmp(tokens[0], "nat"))
3689 if (strcmp(tokens[1], "ipv4") == 0) {
3690 struct in_addr addr;
3693 if (parse_ipv4_addr(tokens[2], &addr) ||
3694 parser_read_uint16(&port, tokens[3]))
3697 a->nat.ip_version = 1;
3698 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3700 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3704 if (strcmp(tokens[1], "ipv6") == 0) {
3705 struct in6_addr addr;
3708 if (parse_ipv6_addr(tokens[2], &addr) ||
3709 parser_read_uint16(&port, tokens[3]))
3712 a->nat.ip_version = 0;
3713 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3715 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3723 parse_table_action_ttl(char **tokens,
3725 struct table_rule_action *a)
3727 if ((n_tokens < 2) ||
3728 strcmp(tokens[0], "ttl"))
3731 if (strcmp(tokens[1], "dec") == 0)
3732 a->ttl.decrement = 1;
3733 else if (strcmp(tokens[1], "keep") == 0)
3734 a->ttl.decrement = 0;
3738 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3743 parse_table_action_stats(char **tokens,
3745 struct table_rule_action *a)
3747 if ((n_tokens < 1) ||
3748 strcmp(tokens[0], "stats"))
3751 a->stats.n_packets = 0;
3752 a->stats.n_bytes = 0;
3753 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3758 parse_table_action_time(char **tokens,
3760 struct table_rule_action *a)
3762 if ((n_tokens < 1) ||
3763 strcmp(tokens[0], "time"))
3766 a->time.time = rte_rdtsc();
3767 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3772 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
3774 struct rte_crypto_sym_xform *xform[2] = {NULL};
3777 xform[0] = p->xform;
3779 xform[1] = xform[0]->next;
3781 for (i = 0; i < 2; i++) {
3782 if (xform[i] == NULL)
3785 switch (xform[i]->type) {
3786 case RTE_CRYPTO_SYM_XFORM_CIPHER:
3787 if (p->cipher_auth.cipher_iv.val)
3788 free(p->cipher_auth.cipher_iv.val);
3789 if (p->cipher_auth.cipher_iv_update.val)
3790 free(p->cipher_auth.cipher_iv_update.val);
3792 case RTE_CRYPTO_SYM_XFORM_AUTH:
3793 if (p->cipher_auth.auth_iv.val)
3794 free(p->cipher_auth.cipher_iv.val);
3795 if (p->cipher_auth.auth_iv_update.val)
3796 free(p->cipher_auth.cipher_iv_update.val);
3798 case RTE_CRYPTO_SYM_XFORM_AEAD:
3800 free(p->aead.iv.val);
3801 if (p->aead.aad.val)
3802 free(p->aead.aad.val);
3811 static struct rte_crypto_sym_xform *
3812 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3813 uint8_t *key, uint32_t max_key_len, char **tokens,
3814 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3816 struct rte_crypto_sym_xform *xform_cipher;
3820 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
3821 strcmp(tokens[3], "cipher_key") ||
3822 strcmp(tokens[5], "cipher_iv"))
3825 xform_cipher = calloc(1, sizeof(*xform_cipher));
3826 if (xform_cipher == NULL)
3829 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3830 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
3831 RTE_CRYPTO_CIPHER_OP_DECRYPT;
3834 status = rte_cryptodev_get_cipher_algo_enum(
3835 &xform_cipher->cipher.algo, tokens[2]);
3840 len = strlen(tokens[4]);
3841 if (len / 2 > max_key_len) {
3846 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
3850 xform_cipher->cipher.key.data = key;
3851 xform_cipher->cipher.key.length = (uint16_t)len;
3854 len = strlen(tokens[6]);
3856 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
3857 if (p->cipher_auth.cipher_iv.val == NULL)
3860 status = parse_hex_string(tokens[6],
3861 p->cipher_auth.cipher_iv.val,
3866 xform_cipher->cipher.iv.length = (uint16_t)len;
3867 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3868 p->cipher_auth.cipher_iv.length = (uint32_t)len;
3871 return xform_cipher;
3874 if (p->cipher_auth.cipher_iv.val) {
3875 free(p->cipher_auth.cipher_iv.val);
3876 p->cipher_auth.cipher_iv.val = NULL;
3884 static struct rte_crypto_sym_xform *
3885 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3886 uint8_t *key, uint32_t max_key_len, char **tokens,
3887 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3889 struct rte_crypto_sym_xform *xform_cipher;
3890 struct rte_crypto_sym_xform *xform_auth;
3894 if (n_tokens < 13 ||
3895 strcmp(tokens[7], "auth_algo") ||
3896 strcmp(tokens[9], "auth_key") ||
3897 strcmp(tokens[11], "digest_size"))
3900 xform_auth = calloc(1, sizeof(*xform_auth));
3901 if (xform_auth == NULL)
3904 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
3905 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
3906 RTE_CRYPTO_AUTH_OP_VERIFY;
3909 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
3915 len = strlen(tokens[10]);
3916 if (len / 2 > max_key_len) {
3921 status = parse_hex_string(tokens[10], key, (uint32_t *)&len);
3925 xform_auth->auth.key.data = key;
3926 xform_auth->auth.key.length = (uint16_t)len;
3928 key += xform_auth->auth.key.length;
3929 max_key_len -= xform_auth->auth.key.length;
3931 if (strcmp(tokens[11], "digest_size"))
3934 status = parser_read_uint16(&xform_auth->auth.digest_length,
3939 xform_cipher = parse_table_action_cipher(p, key, max_key_len, tokens,
3940 7, encrypt, used_n_tokens);
3941 if (xform_cipher == NULL)
3944 *used_n_tokens += 6;
3947 xform_cipher->next = xform_auth;
3948 return xform_cipher;
3950 xform_auth->next = xform_cipher;
3955 if (p->cipher_auth.auth_iv.val) {
3956 free(p->cipher_auth.auth_iv.val);
3957 p->cipher_auth.auth_iv.val = 0;
3965 static struct rte_crypto_sym_xform *
3966 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3967 uint8_t *key, uint32_t max_key_len, char **tokens,
3968 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3970 struct rte_crypto_sym_xform *xform_aead;
3974 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
3975 strcmp(tokens[3], "aead_key") ||
3976 strcmp(tokens[5], "aead_iv") ||
3977 strcmp(tokens[7], "aead_aad") ||
3978 strcmp(tokens[9], "digest_size"))
3981 xform_aead = calloc(1, sizeof(*xform_aead));
3982 if (xform_aead == NULL)
3985 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
3986 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
3987 RTE_CRYPTO_AEAD_OP_DECRYPT;
3990 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
3996 len = strlen(tokens[4]);
3997 if (len / 2 > max_key_len) {
4002 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
4006 xform_aead->aead.key.data = key;
4007 xform_aead->aead.key.length = (uint16_t)len;
4010 len = strlen(tokens[6]);
4011 p->aead.iv.val = calloc(1, len / 2 + 1);
4012 if (p->aead.iv.val == NULL)
4015 status = parse_hex_string(tokens[6], p->aead.iv.val,
4020 xform_aead->aead.iv.length = (uint16_t)len;
4021 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4022 p->aead.iv.length = (uint32_t)len;
4025 len = strlen(tokens[8]);
4026 p->aead.aad.val = calloc(1, len / 2 + 1);
4027 if (p->aead.aad.val == NULL)
4030 status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
4034 xform_aead->aead.aad_length = (uint16_t)len;
4035 p->aead.aad.length = (uint32_t)len;
4038 status = parser_read_uint16(&xform_aead->aead.digest_length,
4043 *used_n_tokens = 11;
4048 if (p->aead.iv.val) {
4049 free(p->aead.iv.val);
4050 p->aead.iv.val = NULL;
4052 if (p->aead.aad.val) {
4053 free(p->aead.aad.val);
4054 p->aead.aad.val = NULL;
4064 parse_table_action_sym_crypto(char **tokens,
4066 struct table_rule_action *a)
4068 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4069 struct rte_crypto_sym_xform *xform = NULL;
4070 uint8_t *key = a->sym_crypto_key;
4071 uint32_t max_key_len = SYM_CRYPTO_MAX_KEY_SIZE;
4072 uint32_t used_n_tokens;
4076 if ((n_tokens < 12) ||
4077 strcmp(tokens[0], "sym_crypto") ||
4078 strcmp(tokens[2], "type"))
4081 memset(p, 0, sizeof(*p));
4083 if (strcmp(tokens[1], "encrypt") == 0)
4088 status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4092 if (strcmp(tokens[3], "cipher") == 0) {
4096 xform = parse_table_action_cipher(p, key, max_key_len, tokens,
4097 n_tokens, encrypt, &used_n_tokens);
4098 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4102 xform = parse_table_action_cipher_auth(p, key, max_key_len,
4103 tokens, n_tokens, encrypt, &used_n_tokens);
4104 } else if (strcmp(tokens[3], "aead") == 0) {
4108 xform = parse_table_action_aead(p, key, max_key_len, tokens,
4109 n_tokens, encrypt, &used_n_tokens);
4117 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4118 parse_free_sym_crypto_param_data(p);
4122 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4124 return used_n_tokens + 5;
4128 parse_table_action_tag(char **tokens,
4130 struct table_rule_action *a)
4132 if ((n_tokens < 2) ||
4133 strcmp(tokens[0], "tag"))
4136 if (parser_read_uint32(&a->tag.tag, tokens[1]))
4139 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4144 parse_table_action_decap(char **tokens,
4146 struct table_rule_action *a)
4148 if ((n_tokens < 2) ||
4149 strcmp(tokens[0], "decap"))
4152 if (parser_read_uint16(&a->decap.n, tokens[1]))
4155 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4160 parse_table_action(char **tokens,
4164 struct table_rule_action *a)
4166 uint32_t n_tokens0 = n_tokens;
4168 memset(a, 0, sizeof(*a));
4170 if ((n_tokens < 2) ||
4171 strcmp(tokens[0], "action"))
4177 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4180 n = parse_table_action_fwd(tokens, n_tokens, a);
4182 snprintf(out, out_size, MSG_ARG_INVALID,
4191 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4194 n = parse_table_action_balance(tokens, n_tokens, a);
4196 snprintf(out, out_size, MSG_ARG_INVALID,
4205 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4208 n = parse_table_action_meter(tokens, n_tokens, a);
4210 snprintf(out, out_size, MSG_ARG_INVALID,
4219 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4222 n = parse_table_action_tm(tokens, n_tokens, a);
4224 snprintf(out, out_size, MSG_ARG_INVALID,
4233 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4236 n = parse_table_action_encap(tokens, n_tokens, a);
4238 snprintf(out, out_size, MSG_ARG_INVALID,
4247 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4250 n = parse_table_action_nat(tokens, n_tokens, a);
4252 snprintf(out, out_size, MSG_ARG_INVALID,
4261 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4264 n = parse_table_action_ttl(tokens, n_tokens, a);
4266 snprintf(out, out_size, MSG_ARG_INVALID,
4275 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4278 n = parse_table_action_stats(tokens, n_tokens, a);
4280 snprintf(out, out_size, MSG_ARG_INVALID,
4289 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4292 n = parse_table_action_time(tokens, n_tokens, a);
4294 snprintf(out, out_size, MSG_ARG_INVALID,
4303 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4306 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4308 snprintf(out, out_size, MSG_ARG_INVALID,
4309 "action sym_crypto");
4316 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4319 n = parse_table_action_tag(tokens, n_tokens, a);
4321 snprintf(out, out_size, MSG_ARG_INVALID,
4330 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4333 n = parse_table_action_decap(tokens, n_tokens, a);
4335 snprintf(out, out_size, MSG_ARG_INVALID,
4344 if (n_tokens0 - n_tokens == 1) {
4345 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4349 return n_tokens0 - n_tokens;
4353 static const char cmd_pipeline_table_rule_add_help[] =
4354 "pipeline <pipeline_name> table <table_id> rule add\n"
4356 " action <table_action>\n";
4359 cmd_pipeline_table_rule_add(char **tokens,
4364 struct table_rule_match m;
4365 struct table_rule_action a;
4366 char *pipeline_name;
4367 uint32_t table_id, t0, n_tokens_parsed;
4371 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4375 pipeline_name = tokens[1];
4377 if (strcmp(tokens[2], "table") != 0) {
4378 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4382 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4383 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4387 if (strcmp(tokens[4], "rule") != 0) {
4388 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4392 if (strcmp(tokens[5], "add") != 0) {
4393 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4400 n_tokens_parsed = parse_match(tokens + t0,
4405 if (n_tokens_parsed == 0)
4407 t0 += n_tokens_parsed;
4410 n_tokens_parsed = parse_table_action(tokens + t0,
4415 if (n_tokens_parsed == 0)
4417 t0 += n_tokens_parsed;
4419 if (t0 != n_tokens) {
4420 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4424 status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
4426 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4430 if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
4431 parse_free_sym_crypto_param_data(&a.sym_crypto);
4435 static const char cmd_pipeline_table_rule_add_default_help[] =
4436 "pipeline <pipeline_name> table <table_id> rule add\n"
4442 " | port <port_id>\n"
4444 " | table <table_id>\n";
4447 cmd_pipeline_table_rule_add_default(char **tokens,
4452 struct table_rule_action action;
4453 char *pipeline_name;
4457 if ((n_tokens != 11) && (n_tokens != 12)) {
4458 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4462 pipeline_name = tokens[1];
4464 if (strcmp(tokens[2], "table") != 0) {
4465 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4469 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4470 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4474 if (strcmp(tokens[4], "rule") != 0) {
4475 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4479 if (strcmp(tokens[5], "add") != 0) {
4480 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4484 if (strcmp(tokens[6], "match") != 0) {
4485 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4489 if (strcmp(tokens[7], "default") != 0) {
4490 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4494 if (strcmp(tokens[8], "action") != 0) {
4495 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4499 if (strcmp(tokens[9], "fwd") != 0) {
4500 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4504 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4506 if (strcmp(tokens[10], "drop") == 0) {
4507 if (n_tokens != 11) {
4508 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4512 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4513 } else if (strcmp(tokens[10], "port") == 0) {
4516 if (n_tokens != 12) {
4517 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4521 if (parser_read_uint32(&id, tokens[11]) != 0) {
4522 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4526 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4528 } else if (strcmp(tokens[10], "meta") == 0) {
4529 if (n_tokens != 11) {
4530 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4534 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4535 } else if (strcmp(tokens[10], "table") == 0) {
4538 if (n_tokens != 12) {
4539 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4543 if (parser_read_uint32(&id, tokens[11]) != 0) {
4544 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4548 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4551 snprintf(out, out_size, MSG_ARG_INVALID,
4552 "drop or port or meta or table");
4556 status = pipeline_table_rule_add_default(pipeline_name,
4560 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4566 static const char cmd_pipeline_table_rule_add_bulk_help[] =
4567 "pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\n"
4569 " File <file_name>:\n"
4570 " - line format: match <match> action <action>\n";
4573 cli_rule_file_process(const char *file_name,
4574 size_t line_len_max,
4575 struct table_rule_list **rule_list,
4577 uint32_t *line_number,
4582 cmd_pipeline_table_rule_add_bulk(char **tokens,
4587 struct table_rule_list *list = NULL;
4588 char *pipeline_name, *file_name;
4589 uint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;
4592 if (n_tokens != 8) {
4593 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4597 pipeline_name = tokens[1];
4599 if (strcmp(tokens[2], "table") != 0) {
4600 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4604 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4605 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4609 if (strcmp(tokens[4], "rule") != 0) {
4610 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4614 if (strcmp(tokens[5], "add") != 0) {
4615 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4619 if (strcmp(tokens[6], "bulk") != 0) {
4620 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4624 file_name = tokens[7];
4626 /* Load rules from file. */
4627 status = cli_rule_file_process(file_name,
4635 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4640 status = pipeline_table_rule_add_bulk(pipeline_name,
4644 &n_rules_not_added);
4646 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4650 snprintf(out, out_size, "Added %u rules out of %u.\n",
4656 static const char cmd_pipeline_table_rule_delete_help[] =
4657 "pipeline <pipeline_name> table <table_id> rule delete\n"
4661 cmd_pipeline_table_rule_delete(char **tokens,
4666 struct table_rule_match m;
4667 char *pipeline_name;
4668 uint32_t table_id, n_tokens_parsed, t0;
4672 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4676 pipeline_name = tokens[1];
4678 if (strcmp(tokens[2], "table") != 0) {
4679 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4683 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4684 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4688 if (strcmp(tokens[4], "rule") != 0) {
4689 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4693 if (strcmp(tokens[5], "delete") != 0) {
4694 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4701 n_tokens_parsed = parse_match(tokens + t0,
4706 if (n_tokens_parsed == 0)
4708 t0 += n_tokens_parsed;
4710 if (n_tokens != t0) {
4711 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4715 status = pipeline_table_rule_delete(pipeline_name,
4719 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4725 static const char cmd_pipeline_table_rule_delete_default_help[] =
4726 "pipeline <pipeline_name> table <table_id> rule delete\n"
4731 cmd_pipeline_table_rule_delete_default(char **tokens,
4736 char *pipeline_name;
4740 if (n_tokens != 8) {
4741 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4745 pipeline_name = tokens[1];
4747 if (strcmp(tokens[2], "table") != 0) {
4748 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4752 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4753 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4757 if (strcmp(tokens[4], "rule") != 0) {
4758 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4762 if (strcmp(tokens[5], "delete") != 0) {
4763 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4767 if (strcmp(tokens[6], "match") != 0) {
4768 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4772 if (strcmp(tokens[7], "default") != 0) {
4773 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4777 status = pipeline_table_rule_delete_default(pipeline_name,
4780 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4786 ether_addr_show(FILE *f, struct rte_ether_addr *addr)
4788 fprintf(f, "%02x:%02x:%02x:%02x:%02x:%02x",
4789 (uint32_t)addr->addr_bytes[0], (uint32_t)addr->addr_bytes[1],
4790 (uint32_t)addr->addr_bytes[2], (uint32_t)addr->addr_bytes[3],
4791 (uint32_t)addr->addr_bytes[4], (uint32_t)addr->addr_bytes[5]);
4795 ipv4_addr_show(FILE *f, uint32_t addr)
4797 fprintf(f, "%u.%u.%u.%u",
4799 (addr >> 16) & 0xFF,
4805 ipv6_addr_show(FILE *f, uint8_t *addr)
4807 fprintf(f, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
4808 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:",
4809 (uint32_t)addr[0], (uint32_t)addr[1],
4810 (uint32_t)addr[2], (uint32_t)addr[3],
4811 (uint32_t)addr[4], (uint32_t)addr[5],
4812 (uint32_t)addr[6], (uint32_t)addr[7],
4813 (uint32_t)addr[8], (uint32_t)addr[9],
4814 (uint32_t)addr[10], (uint32_t)addr[11],
4815 (uint32_t)addr[12], (uint32_t)addr[13],
4816 (uint32_t)addr[14], (uint32_t)addr[15]);
4820 policer_action_string(enum rte_table_action_policer action) {
4822 case RTE_TABLE_ACTION_POLICER_COLOR_GREEN: return "G";
4823 case RTE_TABLE_ACTION_POLICER_COLOR_YELLOW: return "Y";
4824 case RTE_TABLE_ACTION_POLICER_COLOR_RED: return "R";
4825 case RTE_TABLE_ACTION_POLICER_DROP: return "D";
4826 default: return "?";
4831 table_rule_show(const char *pipeline_name,
4833 const char *file_name)
4836 struct table *table;
4837 struct table_rule *rule;
4841 /* Check input params. */
4842 if ((pipeline_name == NULL) ||
4843 (file_name == NULL))
4846 p = pipeline_find(pipeline_name);
4848 (table_id >= p->n_tables))
4851 table = &p->table[table_id];
4854 f = fopen(file_name, "w");
4858 /* Write table rules to file. */
4859 TAILQ_FOREACH(rule, &table->rules, node) {
4860 struct table_rule_match *m = &rule->match;
4861 struct table_rule_action *a = &rule->action;
4863 fprintf(f, "match ");
4864 switch (m->match_type) {
4866 fprintf(f, "acl priority %u ",
4867 m->match.acl.priority);
4869 fprintf(f, m->match.acl.ip_version ? "ipv4 " : "ipv6 ");
4871 if (m->match.acl.ip_version)
4872 ipv4_addr_show(f, m->match.acl.ipv4.sa);
4874 ipv6_addr_show(f, m->match.acl.ipv6.sa);
4876 fprintf(f, "%u", m->match.acl.sa_depth);
4878 if (m->match.acl.ip_version)
4879 ipv4_addr_show(f, m->match.acl.ipv4.da);
4881 ipv6_addr_show(f, m->match.acl.ipv6.da);
4883 fprintf(f, "%u", m->match.acl.da_depth);
4885 fprintf(f, "%u %u %u %u %u ",
4886 (uint32_t)m->match.acl.sp0,
4887 (uint32_t)m->match.acl.sp1,
4888 (uint32_t)m->match.acl.dp0,
4889 (uint32_t)m->match.acl.dp1,
4890 (uint32_t)m->match.acl.proto);
4894 fprintf(f, "array %u ",
4895 m->match.array.pos);
4899 fprintf(f, "hash raw ");
4900 for (i = 0; i < table->params.match.hash.key_size; i++)
4901 fprintf(f, "%02x", m->match.hash.key[i]);
4908 fprintf(f, m->match.lpm.ip_version ? "ipv4 " : "ipv6 ");
4910 if (m->match.acl.ip_version)
4911 ipv4_addr_show(f, m->match.lpm.ipv4);
4913 ipv6_addr_show(f, m->match.lpm.ipv6);
4916 (uint32_t)m->match.lpm.depth);
4920 fprintf(f, "unknown ");
4923 fprintf(f, "action ");
4924 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
4926 switch (a->fwd.action) {
4927 case RTE_PIPELINE_ACTION_DROP:
4928 fprintf(f, "drop ");
4931 case RTE_PIPELINE_ACTION_PORT:
4932 fprintf(f, "port %u ", a->fwd.id);
4935 case RTE_PIPELINE_ACTION_PORT_META:
4936 fprintf(f, "meta ");
4939 case RTE_PIPELINE_ACTION_TABLE:
4941 fprintf(f, "table %u ", a->fwd.id);
4945 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
4946 fprintf(f, "balance ");
4947 for (i = 0; i < RTE_DIM(a->lb.out); i++)
4948 fprintf(f, "%u ", a->lb.out[i]);
4951 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
4953 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++)
4954 if (a->mtr.tc_mask & (1 << i)) {
4955 struct rte_table_action_mtr_tc_params *p =
4957 enum rte_table_action_policer ga =
4958 p->policer[RTE_COLOR_GREEN];
4959 enum rte_table_action_policer ya =
4960 p->policer[RTE_COLOR_YELLOW];
4961 enum rte_table_action_policer ra =
4962 p->policer[RTE_COLOR_RED];
4964 fprintf(f, "tc%u meter %u policer g %s y %s r %s ",
4966 a->mtr.mtr[i].meter_profile_id,
4967 policer_action_string(ga),
4968 policer_action_string(ya),
4969 policer_action_string(ra));
4973 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TM))
4974 fprintf(f, "tm subport %u pipe %u ",
4978 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
4979 fprintf(f, "encap ");
4980 switch (a->encap.type) {
4981 case RTE_TABLE_ACTION_ENCAP_ETHER:
4982 fprintf(f, "ether ");
4983 ether_addr_show(f, &a->encap.ether.ether.da);
4985 ether_addr_show(f, &a->encap.ether.ether.sa);
4989 case RTE_TABLE_ACTION_ENCAP_VLAN:
4990 fprintf(f, "vlan ");
4991 ether_addr_show(f, &a->encap.vlan.ether.da);
4993 ether_addr_show(f, &a->encap.vlan.ether.sa);
4994 fprintf(f, " pcp %u dei %u vid %u ",
4995 a->encap.vlan.vlan.pcp,
4996 a->encap.vlan.vlan.dei,
4997 a->encap.vlan.vlan.vid);
5000 case RTE_TABLE_ACTION_ENCAP_QINQ:
5001 fprintf(f, "qinq ");
5002 ether_addr_show(f, &a->encap.qinq.ether.da);
5004 ether_addr_show(f, &a->encap.qinq.ether.sa);
5005 fprintf(f, " pcp %u dei %u vid %u pcp %u dei %u vid %u ",
5006 a->encap.qinq.svlan.pcp,
5007 a->encap.qinq.svlan.dei,
5008 a->encap.qinq.svlan.vid,
5009 a->encap.qinq.cvlan.pcp,
5010 a->encap.qinq.cvlan.dei,
5011 a->encap.qinq.cvlan.vid);
5014 case RTE_TABLE_ACTION_ENCAP_MPLS:
5015 fprintf(f, "mpls %s ", (a->encap.mpls.unicast) ?
5016 "unicast " : "multicast ");
5017 ether_addr_show(f, &a->encap.mpls.ether.da);
5019 ether_addr_show(f, &a->encap.mpls.ether.sa);
5021 for (i = 0; i < a->encap.mpls.mpls_count; i++) {
5022 struct rte_table_action_mpls_hdr *l =
5023 &a->encap.mpls.mpls[i];
5025 fprintf(f, "label%u %u %u %u ",
5033 case RTE_TABLE_ACTION_ENCAP_PPPOE:
5034 fprintf(f, "pppoe ");
5035 ether_addr_show(f, &a->encap.pppoe.ether.da);
5037 ether_addr_show(f, &a->encap.pppoe.ether.sa);
5038 fprintf(f, " %u ", a->encap.pppoe.pppoe.session_id);
5041 case RTE_TABLE_ACTION_ENCAP_VXLAN:
5042 fprintf(f, "vxlan ether ");
5043 ether_addr_show(f, &a->encap.vxlan.ether.da);
5045 ether_addr_show(f, &a->encap.vxlan.ether.sa);
5046 if (table->ap->params.encap.vxlan.vlan)
5047 fprintf(f, " vlan pcp %u dei %u vid %u ",
5048 a->encap.vxlan.vlan.pcp,
5049 a->encap.vxlan.vlan.dei,
5050 a->encap.vxlan.vlan.vid);
5051 if (table->ap->params.encap.vxlan.ip_version) {
5052 fprintf(f, " ipv4 ");
5053 ipv4_addr_show(f, a->encap.vxlan.ipv4.sa);
5055 ipv4_addr_show(f, a->encap.vxlan.ipv4.da);
5056 fprintf(f, " %u %u ",
5057 (uint32_t)a->encap.vxlan.ipv4.dscp,
5058 (uint32_t)a->encap.vxlan.ipv4.ttl);
5060 fprintf(f, " ipv6 ");
5061 ipv6_addr_show(f, a->encap.vxlan.ipv6.sa);
5063 ipv6_addr_show(f, a->encap.vxlan.ipv6.da);
5064 fprintf(f, " %u %u %u ",
5065 a->encap.vxlan.ipv6.flow_label,
5066 (uint32_t)a->encap.vxlan.ipv6.dscp,
5067 (uint32_t)a->encap.vxlan.ipv6.hop_limit);
5068 fprintf(f, " udp %u %u vxlan %u ",
5069 a->encap.vxlan.udp.sp,
5070 a->encap.vxlan.udp.dp,
5071 a->encap.vxlan.vxlan.vni);
5076 fprintf(f, "unknown ");
5080 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
5081 fprintf(f, "nat %s ", (a->nat.ip_version) ? "ipv4 " : "ipv6 ");
5082 if (a->nat.ip_version)
5083 ipv4_addr_show(f, a->nat.addr.ipv4);
5085 ipv6_addr_show(f, a->nat.addr.ipv6);
5086 fprintf(f, " %u ", (uint32_t)(a->nat.port));
5089 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TTL))
5090 fprintf(f, "ttl %s ", (a->ttl.decrement) ? "dec" : "keep");
5092 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_STATS))
5093 fprintf(f, "stats ");
5095 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TIME))
5096 fprintf(f, "time ");
5098 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO))
5099 fprintf(f, "sym_crypto ");
5101 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TAG))
5102 fprintf(f, "tag %u ", a->tag.tag);
5104 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
5105 fprintf(f, "decap %u ", a->decap.n);
5111 /* Write table default rule to file. */
5112 if (table->rule_default) {
5113 struct table_rule_action *a = &table->rule_default->action;
5115 fprintf(f, "# match default action fwd ");
5117 switch (a->fwd.action) {
5118 case RTE_PIPELINE_ACTION_DROP:
5119 fprintf(f, "drop ");
5122 case RTE_PIPELINE_ACTION_PORT:
5123 fprintf(f, "port %u ", a->fwd.id);
5126 case RTE_PIPELINE_ACTION_PORT_META:
5127 fprintf(f, "meta ");
5130 case RTE_PIPELINE_ACTION_TABLE:
5132 fprintf(f, "table %u ", a->fwd.id);
5135 fprintf(f, "# match default action fwd drop ");
5145 static const char cmd_pipeline_table_rule_show_help[] =
5146 "pipeline <pipeline_name> table <table_id> rule show\n"
5147 " file <file_name>\n";
5150 cmd_pipeline_table_rule_show(char **tokens,
5155 char *file_name = NULL, *pipeline_name;
5159 if (n_tokens != 8) {
5160 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5164 pipeline_name = tokens[1];
5166 if (strcmp(tokens[2], "table") != 0) {
5167 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5171 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5172 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5176 if (strcmp(tokens[4], "rule") != 0) {
5177 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5181 if (strcmp(tokens[5], "show") != 0) {
5182 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "show");
5186 if (strcmp(tokens[6], "file") != 0) {
5187 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "file");
5191 file_name = tokens[7];
5193 status = table_rule_show(pipeline_name, table_id, file_name);
5195 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5200 static const char cmd_pipeline_table_rule_stats_read_help[] =
5201 "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n"
5205 cmd_pipeline_table_rule_stats_read(char **tokens,
5210 struct table_rule_match m;
5211 struct rte_table_action_stats_counters stats;
5212 char *pipeline_name;
5213 uint32_t table_id, n_tokens_parsed;
5214 int clear = 0, status;
5217 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5221 pipeline_name = tokens[1];
5223 if (strcmp(tokens[2], "table") != 0) {
5224 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5228 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5229 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5233 if (strcmp(tokens[4], "rule") != 0) {
5234 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5238 if (strcmp(tokens[5], "read") != 0) {
5239 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5243 if (strcmp(tokens[6], "stats") != 0) {
5244 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
5252 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5260 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5261 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5265 n_tokens_parsed = parse_match(tokens,
5270 if (n_tokens_parsed == 0)
5272 n_tokens -= n_tokens_parsed;
5273 tokens += n_tokens_parsed;
5277 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5281 /* Read table rule stats. */
5282 status = pipeline_table_rule_stats_read(pipeline_name,
5288 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5293 if (stats.n_packets_valid && stats.n_bytes_valid)
5294 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: %" PRIu64 "\n",
5298 if (stats.n_packets_valid && !stats.n_bytes_valid)
5299 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: N/A\n",
5302 if (!stats.n_packets_valid && stats.n_bytes_valid)
5303 snprintf(out, out_size, "Packets: N/A; Bytes: %" PRIu64 "\n",
5306 if (!stats.n_packets_valid && !stats.n_bytes_valid)
5307 snprintf(out, out_size, "Packets: N/A ; Bytes: N/A\n");
5310 static const char cmd_pipeline_table_meter_profile_add_help[] =
5311 "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
5312 " add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
5313 " | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
5316 cmd_pipeline_table_meter_profile_add(char **tokens,
5321 struct rte_table_action_meter_profile p;
5322 char *pipeline_name;
5323 uint32_t table_id, meter_profile_id;
5327 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5331 pipeline_name = tokens[1];
5333 if (strcmp(tokens[2], "table") != 0) {
5334 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5338 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5339 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5343 if (strcmp(tokens[4], "meter") != 0) {
5344 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5348 if (strcmp(tokens[5], "profile") != 0) {
5349 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5353 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5354 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5358 if (strcmp(tokens[7], "add") != 0) {
5359 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5363 if (strcmp(tokens[8], "srtcm") == 0) {
5364 if (n_tokens != 15) {
5365 snprintf(out, out_size, MSG_ARG_MISMATCH,
5370 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5372 if (strcmp(tokens[9], "cir") != 0) {
5373 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5377 if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5378 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5382 if (strcmp(tokens[11], "cbs") != 0) {
5383 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5387 if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5388 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5392 if (strcmp(tokens[13], "ebs") != 0) {
5393 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5397 if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5398 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5401 } else if (strcmp(tokens[8], "trtcm") == 0) {
5402 if (n_tokens != 17) {
5403 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5407 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5409 if (strcmp(tokens[9], "cir") != 0) {
5410 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5414 if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5415 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5419 if (strcmp(tokens[11], "pir") != 0) {
5420 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5424 if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5425 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5428 if (strcmp(tokens[13], "cbs") != 0) {
5429 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5433 if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5434 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5438 if (strcmp(tokens[15], "pbs") != 0) {
5439 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5443 if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5444 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5448 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5452 status = pipeline_table_mtr_profile_add(pipeline_name,
5457 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5463 static const char cmd_pipeline_table_meter_profile_delete_help[] =
5464 "pipeline <pipeline_name> table <table_id>\n"
5465 " meter profile <meter_profile_id> delete\n";
5468 cmd_pipeline_table_meter_profile_delete(char **tokens,
5473 char *pipeline_name;
5474 uint32_t table_id, meter_profile_id;
5477 if (n_tokens != 8) {
5478 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5482 pipeline_name = tokens[1];
5484 if (strcmp(tokens[2], "table") != 0) {
5485 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5489 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5490 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5494 if (strcmp(tokens[4], "meter") != 0) {
5495 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5499 if (strcmp(tokens[5], "profile") != 0) {
5500 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5504 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5505 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5509 if (strcmp(tokens[7], "delete") != 0) {
5510 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5514 status = pipeline_table_mtr_profile_delete(pipeline_name,
5518 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5524 static const char cmd_pipeline_table_rule_meter_read_help[] =
5525 "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n"
5529 cmd_pipeline_table_rule_meter_read(char **tokens,
5534 struct table_rule_match m;
5535 struct rte_table_action_mtr_counters stats;
5536 char *pipeline_name;
5537 uint32_t table_id, n_tokens_parsed;
5538 int clear = 0, status;
5541 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5545 pipeline_name = tokens[1];
5547 if (strcmp(tokens[2], "table") != 0) {
5548 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5552 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5553 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5557 if (strcmp(tokens[4], "rule") != 0) {
5558 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5562 if (strcmp(tokens[5], "read") != 0) {
5563 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5567 if (strcmp(tokens[6], "meter") != 0) {
5568 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5576 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5584 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5585 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5589 n_tokens_parsed = parse_match(tokens,
5594 if (n_tokens_parsed == 0)
5596 n_tokens -= n_tokens_parsed;
5597 tokens += n_tokens_parsed;
5601 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5605 /* Read table rule meter stats. */
5606 status = pipeline_table_rule_mtr_read(pipeline_name,
5612 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5620 static const char cmd_pipeline_table_dscp_help[] =
5621 "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
5623 " File <file_name>:\n"
5624 " - exactly 64 lines\n"
5625 " - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
5628 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5629 const char *file_name,
5630 uint32_t *line_number)
5635 /* Check input arguments */
5636 if ((dscp_table == NULL) ||
5637 (file_name == NULL) ||
5638 (line_number == NULL)) {
5644 /* Open input file */
5645 f = fopen(file_name, "r");
5652 for (dscp = 0, l = 1; ; l++) {
5655 enum rte_color color;
5656 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5658 if (fgets(line, sizeof(line), f) == NULL)
5661 if (is_comment(line))
5664 if (parse_tokenize_string(line, tokens, &n_tokens)) {
5673 if ((dscp >= RTE_DIM(dscp_table->entry)) ||
5674 (n_tokens != RTE_DIM(tokens)) ||
5675 parser_read_uint32(&tc_id, tokens[0]) ||
5676 (tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
5677 parser_read_uint32(&tc_queue_id, tokens[1]) ||
5678 (tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
5679 (strlen(tokens[2]) != 1)) {
5685 switch (tokens[2][0]) {
5688 color = RTE_COLOR_GREEN;
5693 color = RTE_COLOR_YELLOW;
5698 color = RTE_COLOR_RED;
5707 dscp_table->entry[dscp].tc_id = tc_id;
5708 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5709 dscp_table->entry[dscp].color = color;
5719 cmd_pipeline_table_dscp(char **tokens,
5724 struct rte_table_action_dscp_table dscp_table;
5725 char *pipeline_name, *file_name;
5726 uint32_t table_id, line_number;
5729 if (n_tokens != 6) {
5730 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5734 pipeline_name = tokens[1];
5736 if (strcmp(tokens[2], "table") != 0) {
5737 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5741 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5742 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5746 if (strcmp(tokens[4], "dscp") != 0) {
5747 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5751 file_name = tokens[5];
5753 status = load_dscp_table(&dscp_table, file_name, &line_number);
5755 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5759 status = pipeline_table_dscp_table_update(pipeline_name,
5764 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5770 static const char cmd_pipeline_table_rule_ttl_read_help[] =
5771 "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n"
5775 cmd_pipeline_table_rule_ttl_read(char **tokens,
5780 struct table_rule_match m;
5781 struct rte_table_action_ttl_counters stats;
5782 char *pipeline_name;
5783 uint32_t table_id, n_tokens_parsed;
5784 int clear = 0, status;
5787 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5791 pipeline_name = tokens[1];
5793 if (strcmp(tokens[2], "table") != 0) {
5794 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5798 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5799 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5803 if (strcmp(tokens[4], "rule") != 0) {
5804 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5808 if (strcmp(tokens[5], "read") != 0) {
5809 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5813 if (strcmp(tokens[6], "ttl") != 0) {
5814 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ttl");
5822 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5830 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5831 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5835 n_tokens_parsed = parse_match(tokens,
5840 if (n_tokens_parsed == 0)
5842 n_tokens -= n_tokens_parsed;
5843 tokens += n_tokens_parsed;
5847 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5851 /* Read table rule TTL stats. */
5852 status = pipeline_table_rule_ttl_read(pipeline_name,
5858 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5863 snprintf(out, out_size, "Packets: %" PRIu64 "\n",
5867 static const char cmd_pipeline_table_rule_time_read_help[] =
5868 "pipeline <pipeline_name> table <table_id> rule read time\n"
5872 cmd_pipeline_table_rule_time_read(char **tokens,
5877 struct table_rule_match m;
5878 char *pipeline_name;
5880 uint32_t table_id, n_tokens_parsed;
5884 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5888 pipeline_name = tokens[1];
5890 if (strcmp(tokens[2], "table") != 0) {
5891 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5895 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5896 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5900 if (strcmp(tokens[4], "rule") != 0) {
5901 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5905 if (strcmp(tokens[5], "read") != 0) {
5906 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5910 if (strcmp(tokens[6], "time") != 0) {
5911 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "time");
5919 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5920 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5924 n_tokens_parsed = parse_match(tokens,
5929 if (n_tokens_parsed == 0)
5931 n_tokens -= n_tokens_parsed;
5932 tokens += n_tokens_parsed;
5936 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5940 /* Read table rule timestamp. */
5941 status = pipeline_table_rule_time_read(pipeline_name,
5946 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5951 snprintf(out, out_size, "Packets: %" PRIu64 "\n", timestamp);
5954 static const char cmd_thread_pipeline_enable_help[] =
5955 "thread <thread_id> pipeline <pipeline_name> enable\n";
5958 cmd_thread_pipeline_enable(char **tokens,
5963 char *pipeline_name;
5967 if (n_tokens != 5) {
5968 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5972 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5973 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5977 if (strcmp(tokens[2], "pipeline") != 0) {
5978 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5982 pipeline_name = tokens[3];
5984 if (strcmp(tokens[4], "enable") != 0) {
5985 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5989 status = thread_pipeline_enable(thread_id, pipeline_name);
5991 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5997 static const char cmd_thread_pipeline_disable_help[] =
5998 "thread <thread_id> pipeline <pipeline_name> disable\n";
6001 cmd_thread_pipeline_disable(char **tokens,
6006 char *pipeline_name;
6010 if (n_tokens != 5) {
6011 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
6015 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
6016 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
6020 if (strcmp(tokens[2], "pipeline") != 0) {
6021 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
6025 pipeline_name = tokens[3];
6027 if (strcmp(tokens[4], "disable") != 0) {
6028 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
6032 status = thread_pipeline_disable(thread_id, pipeline_name);
6034 snprintf(out, out_size, MSG_CMD_FAIL,
6035 "thread pipeline disable");
6041 cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
6046 if (n_tokens == 0) {
6047 snprintf(out, out_size,
6048 "Type 'help <command>' for details on each command.\n\n"
6049 "List of commands:\n"
6053 "\ttmgr subport profile\n"
6054 "\ttmgr pipe profile\n"
6057 "\ttmgr subport pipe\n"
6060 "\tport in action profile\n"
6061 "\ttable action profile\n"
6063 "\tpipeline port in\n"
6064 "\tpipeline port out\n"
6065 "\tpipeline table\n"
6066 "\tpipeline port in table\n"
6067 "\tpipeline port in stats\n"
6068 "\tpipeline port in enable\n"
6069 "\tpipeline port in disable\n"
6070 "\tpipeline port out stats\n"
6071 "\tpipeline table stats\n"
6072 "\tpipeline table rule add\n"
6073 "\tpipeline table rule add default\n"
6074 "\tpipeline table rule add bulk\n"
6075 "\tpipeline table rule delete\n"
6076 "\tpipeline table rule delete default\n"
6077 "\tpipeline table rule show\n"
6078 "\tpipeline table rule stats read\n"
6079 "\tpipeline table meter profile add\n"
6080 "\tpipeline table meter profile delete\n"
6081 "\tpipeline table rule meter read\n"
6082 "\tpipeline table dscp\n"
6083 "\tpipeline table rule ttl read\n"
6084 "\tpipeline table rule time read\n"
6085 "\tthread pipeline enable\n"
6086 "\tthread pipeline disable\n\n");
6090 if (strcmp(tokens[0], "mempool") == 0) {
6091 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
6095 if (strcmp(tokens[0], "link") == 0) {
6096 snprintf(out, out_size, "\n%s\n", cmd_link_help);
6100 if (strcmp(tokens[0], "swq") == 0) {
6101 snprintf(out, out_size, "\n%s\n", cmd_swq_help);
6105 if (strcmp(tokens[0], "tmgr") == 0) {
6106 if (n_tokens == 1) {
6107 snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
6111 if ((n_tokens == 2) &&
6112 (strcmp(tokens[1], "subport")) == 0) {
6113 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
6117 if ((n_tokens == 3) &&
6118 (strcmp(tokens[1], "subport") == 0) &&
6119 (strcmp(tokens[2], "profile") == 0)) {
6120 snprintf(out, out_size, "\n%s\n",
6121 cmd_tmgr_subport_profile_help);
6125 if ((n_tokens == 3) &&
6126 (strcmp(tokens[1], "subport") == 0) &&
6127 (strcmp(tokens[2], "pipe") == 0)) {
6128 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
6132 if ((n_tokens == 3) &&
6133 (strcmp(tokens[1], "pipe") == 0) &&
6134 (strcmp(tokens[2], "profile") == 0)) {
6135 snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
6140 if (strcmp(tokens[0], "tap") == 0) {
6141 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
6145 if (strcmp(tokens[0], "kni") == 0) {
6146 snprintf(out, out_size, "\n%s\n", cmd_kni_help);
6150 if (strcmp(tokens[0], "cryptodev") == 0) {
6151 snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
6155 if ((n_tokens == 4) &&
6156 (strcmp(tokens[0], "port") == 0) &&
6157 (strcmp(tokens[1], "in") == 0) &&
6158 (strcmp(tokens[2], "action") == 0) &&
6159 (strcmp(tokens[3], "profile") == 0)) {
6160 snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
6164 if ((n_tokens == 3) &&
6165 (strcmp(tokens[0], "table") == 0) &&
6166 (strcmp(tokens[1], "action") == 0) &&
6167 (strcmp(tokens[2], "profile") == 0)) {
6168 snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
6172 if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
6173 snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
6177 if ((strcmp(tokens[0], "pipeline") == 0) &&
6178 (strcmp(tokens[1], "port") == 0)) {
6179 if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
6180 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
6184 if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
6185 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
6189 if ((n_tokens == 4) &&
6190 (strcmp(tokens[2], "in") == 0) &&
6191 (strcmp(tokens[3], "table") == 0)) {
6192 snprintf(out, out_size, "\n%s\n",
6193 cmd_pipeline_port_in_table_help);
6197 if ((n_tokens == 4) &&
6198 (strcmp(tokens[2], "in") == 0) &&
6199 (strcmp(tokens[3], "stats") == 0)) {
6200 snprintf(out, out_size, "\n%s\n",
6201 cmd_pipeline_port_in_stats_help);
6205 if ((n_tokens == 4) &&
6206 (strcmp(tokens[2], "in") == 0) &&
6207 (strcmp(tokens[3], "enable") == 0)) {
6208 snprintf(out, out_size, "\n%s\n",
6209 cmd_pipeline_port_in_enable_help);
6213 if ((n_tokens == 4) &&
6214 (strcmp(tokens[2], "in") == 0) &&
6215 (strcmp(tokens[3], "disable") == 0)) {
6216 snprintf(out, out_size, "\n%s\n",
6217 cmd_pipeline_port_in_disable_help);
6221 if ((n_tokens == 4) &&
6222 (strcmp(tokens[2], "out") == 0) &&
6223 (strcmp(tokens[3], "stats") == 0)) {
6224 snprintf(out, out_size, "\n%s\n",
6225 cmd_pipeline_port_out_stats_help);
6230 if ((strcmp(tokens[0], "pipeline") == 0) &&
6231 (strcmp(tokens[1], "table") == 0)) {
6232 if (n_tokens == 2) {
6233 snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
6237 if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
6238 snprintf(out, out_size, "\n%s\n",
6239 cmd_pipeline_table_stats_help);
6243 if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
6244 snprintf(out, out_size, "\n%s\n",
6245 cmd_pipeline_table_dscp_help);
6249 if ((n_tokens == 4) &&
6250 (strcmp(tokens[2], "rule") == 0) &&
6251 (strcmp(tokens[3], "add") == 0)) {
6252 snprintf(out, out_size, "\n%s\n",
6253 cmd_pipeline_table_rule_add_help);
6257 if ((n_tokens == 5) &&
6258 (strcmp(tokens[2], "rule") == 0) &&
6259 (strcmp(tokens[3], "add") == 0) &&
6260 (strcmp(tokens[4], "default") == 0)) {
6261 snprintf(out, out_size, "\n%s\n",
6262 cmd_pipeline_table_rule_add_default_help);
6266 if ((n_tokens == 5) &&
6267 (strcmp(tokens[2], "rule") == 0) &&
6268 (strcmp(tokens[3], "add") == 0) &&
6269 (strcmp(tokens[4], "bulk") == 0)) {
6270 snprintf(out, out_size, "\n%s\n",
6271 cmd_pipeline_table_rule_add_bulk_help);
6275 if ((n_tokens == 4) &&
6276 (strcmp(tokens[2], "rule") == 0) &&
6277 (strcmp(tokens[3], "delete") == 0)) {
6278 snprintf(out, out_size, "\n%s\n",
6279 cmd_pipeline_table_rule_delete_help);
6283 if ((n_tokens == 5) &&
6284 (strcmp(tokens[2], "rule") == 0) &&
6285 (strcmp(tokens[3], "delete") == 0) &&
6286 (strcmp(tokens[4], "default") == 0)) {
6287 snprintf(out, out_size, "\n%s\n",
6288 cmd_pipeline_table_rule_delete_default_help);
6292 if ((n_tokens == 4) &&
6293 (strcmp(tokens[2], "rule") == 0) &&
6294 (strcmp(tokens[3], "show") == 0)) {
6295 snprintf(out, out_size, "\n%s\n",
6296 cmd_pipeline_table_rule_show_help);
6300 if ((n_tokens == 5) &&
6301 (strcmp(tokens[2], "rule") == 0) &&
6302 (strcmp(tokens[3], "stats") == 0) &&
6303 (strcmp(tokens[4], "read") == 0)) {
6304 snprintf(out, out_size, "\n%s\n",
6305 cmd_pipeline_table_rule_stats_read_help);
6309 if ((n_tokens == 5) &&
6310 (strcmp(tokens[2], "meter") == 0) &&
6311 (strcmp(tokens[3], "profile") == 0) &&
6312 (strcmp(tokens[4], "add") == 0)) {
6313 snprintf(out, out_size, "\n%s\n",
6314 cmd_pipeline_table_meter_profile_add_help);
6318 if ((n_tokens == 5) &&
6319 (strcmp(tokens[2], "meter") == 0) &&
6320 (strcmp(tokens[3], "profile") == 0) &&
6321 (strcmp(tokens[4], "delete") == 0)) {
6322 snprintf(out, out_size, "\n%s\n",
6323 cmd_pipeline_table_meter_profile_delete_help);
6327 if ((n_tokens == 5) &&
6328 (strcmp(tokens[2], "rule") == 0) &&
6329 (strcmp(tokens[3], "meter") == 0) &&
6330 (strcmp(tokens[4], "read") == 0)) {
6331 snprintf(out, out_size, "\n%s\n",
6332 cmd_pipeline_table_rule_meter_read_help);
6336 if ((n_tokens == 5) &&
6337 (strcmp(tokens[2], "rule") == 0) &&
6338 (strcmp(tokens[3], "ttl") == 0) &&
6339 (strcmp(tokens[4], "read") == 0)) {
6340 snprintf(out, out_size, "\n%s\n",
6341 cmd_pipeline_table_rule_ttl_read_help);
6345 if ((n_tokens == 5) &&
6346 (strcmp(tokens[2], "rule") == 0) &&
6347 (strcmp(tokens[3], "time") == 0) &&
6348 (strcmp(tokens[4], "read") == 0)) {
6349 snprintf(out, out_size, "\n%s\n",
6350 cmd_pipeline_table_rule_time_read_help);
6355 if ((n_tokens == 3) &&
6356 (strcmp(tokens[0], "thread") == 0) &&
6357 (strcmp(tokens[1], "pipeline") == 0)) {
6358 if (strcmp(tokens[2], "enable") == 0) {
6359 snprintf(out, out_size, "\n%s\n",
6360 cmd_thread_pipeline_enable_help);
6364 if (strcmp(tokens[2], "disable") == 0) {
6365 snprintf(out, out_size, "\n%s\n",
6366 cmd_thread_pipeline_disable_help);
6371 snprintf(out, out_size, "Invalid command\n");
6375 cli_process(char *in, char *out, size_t out_size)
6377 char *tokens[CMD_MAX_TOKENS];
6378 uint32_t n_tokens = RTE_DIM(tokens);
6384 status = parse_tokenize_string(in, tokens, &n_tokens);
6386 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
6393 if (strcmp(tokens[0], "help") == 0) {
6394 cmd_help(tokens, n_tokens, out, out_size);
6398 if (strcmp(tokens[0], "mempool") == 0) {
6399 cmd_mempool(tokens, n_tokens, out, out_size);
6403 if (strcmp(tokens[0], "link") == 0) {
6404 if (strcmp(tokens[1], "show") == 0) {
6405 cmd_link_show(tokens, n_tokens, out, out_size);
6409 cmd_link(tokens, n_tokens, out, out_size);
6413 if (strcmp(tokens[0], "swq") == 0) {
6414 cmd_swq(tokens, n_tokens, out, out_size);
6418 if (strcmp(tokens[0], "tmgr") == 0) {
6419 if ((n_tokens >= 3) &&
6420 (strcmp(tokens[1], "subport") == 0) &&
6421 (strcmp(tokens[2], "profile") == 0)) {
6422 cmd_tmgr_subport_profile(tokens, n_tokens,
6427 if ((n_tokens >= 3) &&
6428 (strcmp(tokens[1], "pipe") == 0) &&
6429 (strcmp(tokens[2], "profile") == 0)) {
6430 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
6434 if ((n_tokens >= 5) &&
6435 (strcmp(tokens[2], "subport") == 0) &&
6436 (strcmp(tokens[4], "profile") == 0)) {
6437 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
6441 if ((n_tokens >= 5) &&
6442 (strcmp(tokens[2], "subport") == 0) &&
6443 (strcmp(tokens[4], "pipe") == 0)) {
6444 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
6448 cmd_tmgr(tokens, n_tokens, out, out_size);
6452 if (strcmp(tokens[0], "tap") == 0) {
6453 cmd_tap(tokens, n_tokens, out, out_size);
6457 if (strcmp(tokens[0], "kni") == 0) {
6458 cmd_kni(tokens, n_tokens, out, out_size);
6462 if (strcmp(tokens[0], "cryptodev") == 0) {
6463 cmd_cryptodev(tokens, n_tokens, out, out_size);
6467 if (strcmp(tokens[0], "port") == 0) {
6468 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
6472 if (strcmp(tokens[0], "table") == 0) {
6473 cmd_table_action_profile(tokens, n_tokens, out, out_size);
6477 if (strcmp(tokens[0], "pipeline") == 0) {
6478 if ((n_tokens >= 3) &&
6479 (strcmp(tokens[2], "period") == 0)) {
6480 cmd_pipeline(tokens, n_tokens, out, out_size);
6484 if ((n_tokens >= 5) &&
6485 (strcmp(tokens[2], "port") == 0) &&
6486 (strcmp(tokens[3], "in") == 0) &&
6487 (strcmp(tokens[4], "bsz") == 0)) {
6488 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
6492 if ((n_tokens >= 5) &&
6493 (strcmp(tokens[2], "port") == 0) &&
6494 (strcmp(tokens[3], "out") == 0) &&
6495 (strcmp(tokens[4], "bsz") == 0)) {
6496 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
6500 if ((n_tokens >= 4) &&
6501 (strcmp(tokens[2], "table") == 0) &&
6502 (strcmp(tokens[3], "match") == 0)) {
6503 cmd_pipeline_table(tokens, n_tokens, out, out_size);
6507 if ((n_tokens >= 6) &&
6508 (strcmp(tokens[2], "port") == 0) &&
6509 (strcmp(tokens[3], "in") == 0) &&
6510 (strcmp(tokens[5], "table") == 0)) {
6511 cmd_pipeline_port_in_table(tokens, n_tokens,
6516 if ((n_tokens >= 6) &&
6517 (strcmp(tokens[2], "port") == 0) &&
6518 (strcmp(tokens[3], "in") == 0) &&
6519 (strcmp(tokens[5], "stats") == 0)) {
6520 cmd_pipeline_port_in_stats(tokens, n_tokens,
6525 if ((n_tokens >= 6) &&
6526 (strcmp(tokens[2], "port") == 0) &&
6527 (strcmp(tokens[3], "in") == 0) &&
6528 (strcmp(tokens[5], "enable") == 0)) {
6529 cmd_pipeline_port_in_enable(tokens, n_tokens,
6534 if ((n_tokens >= 6) &&
6535 (strcmp(tokens[2], "port") == 0) &&
6536 (strcmp(tokens[3], "in") == 0) &&
6537 (strcmp(tokens[5], "disable") == 0)) {
6538 cmd_pipeline_port_in_disable(tokens, n_tokens,
6543 if ((n_tokens >= 6) &&
6544 (strcmp(tokens[2], "port") == 0) &&
6545 (strcmp(tokens[3], "out") == 0) &&
6546 (strcmp(tokens[5], "stats") == 0)) {
6547 cmd_pipeline_port_out_stats(tokens, n_tokens,
6552 if ((n_tokens >= 5) &&
6553 (strcmp(tokens[2], "table") == 0) &&
6554 (strcmp(tokens[4], "stats") == 0)) {
6555 cmd_pipeline_table_stats(tokens, n_tokens,
6560 if ((n_tokens >= 7) &&
6561 (strcmp(tokens[2], "table") == 0) &&
6562 (strcmp(tokens[4], "rule") == 0) &&
6563 (strcmp(tokens[5], "add") == 0) &&
6564 (strcmp(tokens[6], "match") == 0)) {
6565 if ((n_tokens >= 8) &&
6566 (strcmp(tokens[7], "default") == 0)) {
6567 cmd_pipeline_table_rule_add_default(tokens,
6568 n_tokens, out, out_size);
6572 cmd_pipeline_table_rule_add(tokens, n_tokens,
6577 if ((n_tokens >= 7) &&
6578 (strcmp(tokens[2], "table") == 0) &&
6579 (strcmp(tokens[4], "rule") == 0) &&
6580 (strcmp(tokens[5], "add") == 0) &&
6581 (strcmp(tokens[6], "bulk") == 0)) {
6582 cmd_pipeline_table_rule_add_bulk(tokens,
6583 n_tokens, out, out_size);
6587 if ((n_tokens >= 7) &&
6588 (strcmp(tokens[2], "table") == 0) &&
6589 (strcmp(tokens[4], "rule") == 0) &&
6590 (strcmp(tokens[5], "delete") == 0) &&
6591 (strcmp(tokens[6], "match") == 0)) {
6592 if ((n_tokens >= 8) &&
6593 (strcmp(tokens[7], "default") == 0)) {
6594 cmd_pipeline_table_rule_delete_default(tokens,
6595 n_tokens, out, out_size);
6599 cmd_pipeline_table_rule_delete(tokens, n_tokens,
6604 if ((n_tokens >= 6) &&
6605 (strcmp(tokens[2], "table") == 0) &&
6606 (strcmp(tokens[4], "rule") == 0) &&
6607 (strcmp(tokens[5], "show") == 0)) {
6608 cmd_pipeline_table_rule_show(tokens, n_tokens,
6613 if ((n_tokens >= 7) &&
6614 (strcmp(tokens[2], "table") == 0) &&
6615 (strcmp(tokens[4], "rule") == 0) &&
6616 (strcmp(tokens[5], "read") == 0) &&
6617 (strcmp(tokens[6], "stats") == 0)) {
6618 cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
6623 if ((n_tokens >= 8) &&
6624 (strcmp(tokens[2], "table") == 0) &&
6625 (strcmp(tokens[4], "meter") == 0) &&
6626 (strcmp(tokens[5], "profile") == 0) &&
6627 (strcmp(tokens[7], "add") == 0)) {
6628 cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
6633 if ((n_tokens >= 8) &&
6634 (strcmp(tokens[2], "table") == 0) &&
6635 (strcmp(tokens[4], "meter") == 0) &&
6636 (strcmp(tokens[5], "profile") == 0) &&
6637 (strcmp(tokens[7], "delete") == 0)) {
6638 cmd_pipeline_table_meter_profile_delete(tokens,
6639 n_tokens, out, out_size);
6643 if ((n_tokens >= 7) &&
6644 (strcmp(tokens[2], "table") == 0) &&
6645 (strcmp(tokens[4], "rule") == 0) &&
6646 (strcmp(tokens[5], "read") == 0) &&
6647 (strcmp(tokens[6], "meter") == 0)) {
6648 cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
6653 if ((n_tokens >= 5) &&
6654 (strcmp(tokens[2], "table") == 0) &&
6655 (strcmp(tokens[4], "dscp") == 0)) {
6656 cmd_pipeline_table_dscp(tokens, n_tokens,
6661 if ((n_tokens >= 7) &&
6662 (strcmp(tokens[2], "table") == 0) &&
6663 (strcmp(tokens[4], "rule") == 0) &&
6664 (strcmp(tokens[5], "read") == 0) &&
6665 (strcmp(tokens[6], "ttl") == 0)) {
6666 cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
6671 if ((n_tokens >= 7) &&
6672 (strcmp(tokens[2], "table") == 0) &&
6673 (strcmp(tokens[4], "rule") == 0) &&
6674 (strcmp(tokens[5], "read") == 0) &&
6675 (strcmp(tokens[6], "time") == 0)) {
6676 cmd_pipeline_table_rule_time_read(tokens, n_tokens,
6682 if (strcmp(tokens[0], "thread") == 0) {
6683 if ((n_tokens >= 5) &&
6684 (strcmp(tokens[4], "enable") == 0)) {
6685 cmd_thread_pipeline_enable(tokens, n_tokens,
6690 if ((n_tokens >= 5) &&
6691 (strcmp(tokens[4], "disable") == 0)) {
6692 cmd_thread_pipeline_disable(tokens, n_tokens,
6698 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
6702 cli_script_process(const char *file_name,
6703 size_t msg_in_len_max,
6704 size_t msg_out_len_max)
6706 char *msg_in = NULL, *msg_out = NULL;
6709 /* Check input arguments */
6710 if ((file_name == NULL) ||
6711 (strlen(file_name) == 0) ||
6712 (msg_in_len_max == 0) ||
6713 (msg_out_len_max == 0))
6716 msg_in = malloc(msg_in_len_max + 1);
6717 msg_out = malloc(msg_out_len_max + 1);
6718 if ((msg_in == NULL) ||
6719 (msg_out == NULL)) {
6725 /* Open input file */
6726 f = fopen(file_name, "r");
6735 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6738 printf("%s", msg_in);
6745 if (strlen(msg_out))
6746 printf("%s", msg_out);
6757 cli_rule_file_process(const char *file_name,
6758 size_t line_len_max,
6759 struct table_rule_list **rule_list,
6761 uint32_t *line_number,
6765 struct table_rule_list *list = NULL;
6768 uint32_t rule_id = 0, line_id = 0;
6771 /* Check input arguments */
6772 if ((file_name == NULL) ||
6773 (strlen(file_name) == 0) ||
6774 (line_len_max == 0) ||
6775 (rule_list == NULL) ||
6776 (n_rules == NULL) ||
6777 (line_number == NULL) ||
6780 goto cli_rule_file_process_free;
6783 /* Memory allocation */
6784 list = malloc(sizeof(struct table_rule_list));
6787 goto cli_rule_file_process_free;
6792 line = malloc(line_len_max + 1);
6795 goto cli_rule_file_process_free;
6799 f = fopen(file_name, "r");
6802 goto cli_rule_file_process_free;
6806 for (line_id = 1, rule_id = 0; ; line_id++) {
6807 char *tokens[CMD_MAX_TOKENS];
6808 struct table_rule *rule = NULL;
6809 uint32_t n_tokens, n_tokens_parsed, t0;
6811 /* Read next line from file. */
6812 if (fgets(line, line_len_max + 1, f) == NULL)
6816 if (is_comment(line))
6820 n_tokens = RTE_DIM(tokens);
6821 status = parse_tokenize_string(line, tokens, &n_tokens);
6824 goto cli_rule_file_process_free;
6832 /* Rule alloc and insert. */
6833 rule = calloc(1, sizeof(struct table_rule));
6836 goto cli_rule_file_process_free;
6839 TAILQ_INSERT_TAIL(list, rule, node);
6842 n_tokens_parsed = parse_match(tokens + t0,
6847 if (n_tokens_parsed == 0) {
6849 goto cli_rule_file_process_free;
6851 t0 += n_tokens_parsed;
6854 n_tokens_parsed = parse_table_action(tokens + t0,
6859 if (n_tokens_parsed == 0) {
6861 goto cli_rule_file_process_free;
6863 t0 += n_tokens_parsed;
6865 /* Line completed. */
6866 if (t0 < n_tokens) {
6868 goto cli_rule_file_process_free;
6871 /* Increment rule count */
6883 *line_number = line_id;
6886 cli_rule_file_process_free:
6887 if (rule_list != NULL)
6890 if (n_rules != NULL)
6893 if (line_number != NULL)
6894 *line_number = line_id;
6898 struct table_rule *rule;
6900 rule = TAILQ_FIRST(list);
6904 TAILQ_REMOVE(list, rule, node);