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 ether_addr mac_addr;
249 struct rte_eth_link eth_link;
252 memset(&stats, 0, sizeof(stats));
253 rte_eth_stats_get(link->port_id, &stats);
255 rte_eth_macaddr_get(link->port_id, &mac_addr);
256 rte_eth_link_get(link->port_id, ð_link);
257 rte_eth_dev_get_mtu(link->port_id, &mtu);
259 snprintf(out, out_size,
261 "%s: flags=<%s> mtu %u\n"
262 "\tether %02X:%02X:%02X:%02X:%02X:%02X rxqueues %u txqueues %u\n"
263 "\tport# %u speed %u Mbps\n"
264 "\tRX packets %" PRIu64" bytes %" PRIu64"\n"
265 "\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n"
266 "\tTX packets %" PRIu64" bytes %" PRIu64"\n"
267 "\tTX errors %" PRIu64"\n",
269 eth_link.link_status == 0 ? "DOWN" : "UP",
271 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
272 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
273 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5],
289 * link show [<link_name>]
292 cmd_link_show(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
297 if (n_tokens != 2 && n_tokens != 3) {
298 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
303 link = link_next(NULL);
305 while (link != NULL) {
306 out_size = out_size - strlen(out);
307 out = &out[strlen(out)];
309 print_link_info(link, out, out_size);
310 link = link_next(link);
313 out_size = out_size - strlen(out);
314 out = &out[strlen(out)];
316 link_name = tokens[2];
317 link = link_find(link_name);
320 snprintf(out, out_size, MSG_ARG_INVALID,
321 "Link does not exist");
324 print_link_info(link, out, out_size);
328 static const char cmd_swq_help[] =
334 cmd_swq(char **tokens,
344 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
350 if (strcmp(tokens[2], "size") != 0) {
351 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
355 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
356 snprintf(out, out_size, MSG_ARG_INVALID, "size");
360 if (strcmp(tokens[4], "cpu") != 0) {
361 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
365 if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
366 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
370 swq = swq_create(name, &p);
372 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
377 static const char cmd_tmgr_subport_profile_help[] =
378 "tmgr subport profile\n"
379 " <tb_rate> <tb_size>\n"
380 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>\n"
384 cmd_tmgr_subport_profile(char **tokens,
389 struct rte_sched_subport_params p;
392 if (n_tokens != 10) {
393 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
397 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
398 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
402 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
403 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
407 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
408 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
409 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
413 if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) {
414 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
418 status = tmgr_subport_profile_add(&p);
420 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
425 static const char cmd_tmgr_pipe_profile_help[] =
426 "tmgr pipe profile\n"
427 " <tb_rate> <tb_size>\n"
428 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate>\n"
431 " <wrr_weight0..15>\n";
434 cmd_tmgr_pipe_profile(char **tokens,
439 struct rte_sched_pipe_params p;
442 if (n_tokens != 27) {
443 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
447 if (parser_read_uint32(&p.tb_rate, tokens[3]) != 0) {
448 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
452 if (parser_read_uint32(&p.tb_size, tokens[4]) != 0) {
453 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
457 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
458 if (parser_read_uint32(&p.tc_rate[i], tokens[5 + i]) != 0) {
459 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
463 if (parser_read_uint32(&p.tc_period, tokens[9]) != 0) {
464 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
468 #ifdef RTE_SCHED_SUBPORT_TC_OV
469 if (parser_read_uint8(&p.tc_ov_weight, tokens[10]) != 0) {
470 snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
475 for (i = 0; i < RTE_SCHED_QUEUES_PER_PIPE; i++)
476 if (parser_read_uint8(&p.wrr_weights[i], tokens[11 + i]) != 0) {
477 snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
481 status = tmgr_pipe_profile_add(&p);
483 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
488 static const char cmd_tmgr_help[] =
491 " spp <n_subports_per_port>\n"
492 " pps <n_pipes_per_subport>\n"
493 " qsize <qsize_tc0> <qsize_tc1> <qsize_tc2> <qsize_tc3>\n"
494 " fo <frame_overhead>\n"
499 cmd_tmgr(char **tokens,
504 struct tmgr_port_params p;
506 struct tmgr_port *tmgr_port;
509 if (n_tokens != 19) {
510 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
516 if (strcmp(tokens[2], "rate") != 0) {
517 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
521 if (parser_read_uint32(&p.rate, tokens[3]) != 0) {
522 snprintf(out, out_size, MSG_ARG_INVALID, "rate");
526 if (strcmp(tokens[4], "spp") != 0) {
527 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
531 if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
532 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
536 if (strcmp(tokens[6], "pps") != 0) {
537 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
541 if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
542 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
546 if (strcmp(tokens[8], "qsize") != 0) {
547 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "qsize");
551 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
552 if (parser_read_uint16(&p.qsize[i], tokens[9 + i]) != 0) {
553 snprintf(out, out_size, MSG_ARG_INVALID, "qsize");
557 if (strcmp(tokens[13], "fo") != 0) {
558 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
562 if (parser_read_uint32(&p.frame_overhead, tokens[14]) != 0) {
563 snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
567 if (strcmp(tokens[15], "mtu") != 0) {
568 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
572 if (parser_read_uint32(&p.mtu, tokens[16]) != 0) {
573 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
577 if (strcmp(tokens[17], "cpu") != 0) {
578 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
582 if (parser_read_uint32(&p.cpu_id, tokens[18]) != 0) {
583 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
587 tmgr_port = tmgr_port_create(name, &p);
588 if (tmgr_port == NULL) {
589 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
594 static const char cmd_tmgr_subport_help[] =
595 "tmgr <tmgr_name> subport <subport_id>\n"
596 " profile <subport_profile_id>\n";
599 cmd_tmgr_subport(char **tokens,
604 uint32_t subport_id, subport_profile_id;
609 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
615 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
616 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
620 if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
621 snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
625 status = tmgr_subport_config(name, subport_id, subport_profile_id);
627 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
633 static const char cmd_tmgr_subport_pipe_help[] =
634 "tmgr <tmgr_name> subport <subport_id> pipe\n"
635 " from <pipe_id_first> to <pipe_id_last>\n"
636 " profile <pipe_profile_id>\n";
639 cmd_tmgr_subport_pipe(char **tokens,
644 uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
648 if (n_tokens != 11) {
649 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
655 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
656 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
660 if (strcmp(tokens[4], "pipe") != 0) {
661 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
665 if (strcmp(tokens[5], "from") != 0) {
666 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
670 if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
671 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
675 if (strcmp(tokens[7], "to") != 0) {
676 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
680 if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
681 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
685 if (strcmp(tokens[9], "profile") != 0) {
686 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
690 if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
691 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
695 status = tmgr_pipe_config(name, subport_id, pipe_id_first,
696 pipe_id_last, pipe_profile_id);
698 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
704 static const char cmd_tap_help[] =
708 cmd_tap(char **tokens,
717 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
723 tap = tap_create(name);
725 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
730 static const char cmd_kni_help[] =
732 " link <link_name>\n"
733 " mempool <mempool_name>\n"
734 " [thread <thread_id>]\n";
737 cmd_kni(char **tokens,
746 memset(&p, 0, sizeof(p));
747 if ((n_tokens != 6) && (n_tokens != 8)) {
748 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
754 if (strcmp(tokens[2], "link") != 0) {
755 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
759 p.link_name = tokens[3];
761 if (strcmp(tokens[4], "mempool") != 0) {
762 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
766 p.mempool_name = tokens[5];
769 if (strcmp(tokens[6], "thread") != 0) {
770 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
774 if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
775 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
783 kni = kni_create(name, &p);
785 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
790 static const char cmd_cryptodev_help[] =
791 "cryptodev <cryptodev_name>\n"
792 " dev <device_name> | dev_id <device_id>\n"
793 " queue <n_queues> <queue_size>\n"
794 " max_sessions <n_sessions>";
797 cmd_cryptodev(char **tokens,
802 struct cryptodev_params params;
805 memset(¶ms, 0, sizeof(params));
807 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
813 if (strcmp(tokens[2], "dev") == 0)
814 params.dev_name = tokens[3];
815 else if (strcmp(tokens[2], "dev_id") == 0) {
816 if (parser_read_uint32(¶ms.dev_id, tokens[3]) < 0) {
817 snprintf(out, out_size, MSG_ARG_INVALID,
822 snprintf(out, out_size, MSG_ARG_INVALID,
827 if (strcmp(tokens[4], "queue")) {
828 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
833 if (parser_read_uint32(¶ms.n_queues, tokens[5]) < 0) {
834 snprintf(out, out_size, MSG_ARG_INVALID,
839 if (parser_read_uint32(¶ms.queue_size, tokens[6]) < 0) {
840 snprintf(out, out_size, MSG_ARG_INVALID,
845 if (strcmp(tokens[7], "max_sessions")) {
846 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
851 if (parser_read_uint32(¶ms.session_pool_size, tokens[8]) < 0) {
852 snprintf(out, out_size, MSG_ARG_INVALID,
857 if (cryptodev_create(name, ¶ms) == NULL) {
858 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
863 static const char cmd_port_in_action_profile_help[] =
864 "port in action profile <profile_name>\n"
865 " [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]\n"
866 " [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]\n";
869 cmd_port_in_action_profile(char **tokens,
874 struct port_in_action_profile_params p;
875 struct port_in_action_profile *ap;
879 memset(&p, 0, sizeof(p));
882 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
886 if (strcmp(tokens[1], "in") != 0) {
887 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
891 if (strcmp(tokens[2], "action") != 0) {
892 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
896 if (strcmp(tokens[3], "profile") != 0) {
897 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
905 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
908 if (n_tokens < t0 + 10) {
909 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
913 if (strcmp(tokens[t0 + 1], "match") == 0)
914 p.fltr.filter_on_match = 1;
915 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
916 p.fltr.filter_on_match = 0;
918 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
922 if (strcmp(tokens[t0 + 2], "offset") != 0) {
923 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
927 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
928 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
932 if (strcmp(tokens[t0 + 4], "mask") != 0) {
933 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
937 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
938 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
939 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
940 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
944 if (strcmp(tokens[t0 + 6], "key") != 0) {
945 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
949 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
950 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
951 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
952 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
956 if (strcmp(tokens[t0 + 8], "port") != 0) {
957 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
961 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
962 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
966 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
970 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
973 if (n_tokens < t0 + 22) {
974 snprintf(out, out_size, MSG_ARG_MISMATCH,
975 "port in action profile balance");
979 if (strcmp(tokens[t0 + 1], "offset") != 0) {
980 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
984 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
985 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
989 if (strcmp(tokens[t0 + 3], "mask") != 0) {
990 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
994 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
995 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
996 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1000 if (strcmp(tokens[t0 + 5], "port") != 0) {
1001 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1005 for (i = 0; i < 16; i++)
1006 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
1007 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1011 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
1015 if (t0 < n_tokens) {
1016 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1020 ap = port_in_action_profile_create(name, &p);
1022 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1028 static const char cmd_table_action_profile_help[] =
1029 "table action profile <profile_name>\n"
1031 " offset <ip_offset>\n"
1033 " [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]\n"
1034 " [meter srtcm | trtcm\n"
1036 " stats none | pkts | bytes | both]\n"
1037 " [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]\n"
1038 " [encap ether | vlan | qinq | mpls | pppoe |\n"
1039 " vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]\n"
1041 " proto udp | tcp]\n"
1042 " [ttl drop | fwd\n"
1043 " stats none | pkts]\n"
1044 " [stats pkts | bytes | both]\n"
1046 " [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
1051 cmd_table_action_profile(char **tokens,
1056 struct table_action_profile_params p;
1057 struct table_action_profile *ap;
1061 memset(&p, 0, sizeof(p));
1064 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1068 if (strcmp(tokens[1], "action") != 0) {
1069 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1073 if (strcmp(tokens[2], "profile") != 0) {
1074 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1080 if (strcmp(tokens[4], "ipv4") == 0)
1081 p.common.ip_version = 1;
1082 else if (strcmp(tokens[4], "ipv6") == 0)
1083 p.common.ip_version = 0;
1085 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1089 if (strcmp(tokens[5], "offset") != 0) {
1090 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1094 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
1095 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1099 if (strcmp(tokens[7], "fwd") != 0) {
1100 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1104 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1107 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
1108 if (n_tokens < t0 + 7) {
1109 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1113 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1114 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1118 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1119 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1123 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1124 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1128 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1129 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1130 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1134 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1135 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1139 if (parser_read_uint32(&p.lb.out_offset, tokens[t0 + 6]) != 0) {
1140 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1144 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1148 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
1149 if (n_tokens < t0 + 6) {
1150 snprintf(out, out_size, MSG_ARG_MISMATCH,
1151 "table action profile meter");
1155 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
1156 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1157 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
1158 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1160 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1165 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1166 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1170 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
1171 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1175 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1176 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1180 if (strcmp(tokens[t0 + 5], "none") == 0) {
1181 p.mtr.n_packets_enabled = 0;
1182 p.mtr.n_bytes_enabled = 0;
1183 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1184 p.mtr.n_packets_enabled = 1;
1185 p.mtr.n_bytes_enabled = 0;
1186 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1187 p.mtr.n_packets_enabled = 0;
1188 p.mtr.n_bytes_enabled = 1;
1189 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1190 p.mtr.n_packets_enabled = 1;
1191 p.mtr.n_bytes_enabled = 1;
1193 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1194 "none or pkts or bytes or both");
1198 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1202 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
1203 if (n_tokens < t0 + 5) {
1204 snprintf(out, out_size, MSG_ARG_MISMATCH,
1205 "table action profile tm");
1209 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1210 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1214 if (parser_read_uint32(&p.tm.n_subports_per_port,
1215 tokens[t0 + 2]) != 0) {
1216 snprintf(out, out_size, MSG_ARG_INVALID,
1217 "n_subports_per_port");
1221 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1222 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1226 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1227 tokens[t0 + 4]) != 0) {
1228 snprintf(out, out_size, MSG_ARG_INVALID,
1229 "n_pipes_per_subport");
1233 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1237 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1238 uint32_t n_extra_tokens = 0;
1240 if (n_tokens < t0 + 2) {
1241 snprintf(out, out_size, MSG_ARG_MISMATCH,
1242 "action profile encap");
1246 if (strcmp(tokens[t0 + 1], "ether") == 0)
1247 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1248 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1249 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1250 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1251 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1252 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1253 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1254 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1255 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1256 else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1257 if (n_tokens < t0 + 2 + 5) {
1258 snprintf(out, out_size, MSG_ARG_MISMATCH,
1259 "action profile encap vxlan");
1263 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1264 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1269 if (parser_read_uint32(&p.encap.vxlan.data_offset,
1270 tokens[t0 + 2 + 1]) != 0) {
1271 snprintf(out, out_size, MSG_ARG_INVALID,
1272 "vxlan: ether_offset");
1276 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1277 p.encap.vxlan.ip_version = 1;
1278 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1279 p.encap.vxlan.ip_version = 0;
1281 snprintf(out, out_size, MSG_ARG_INVALID,
1282 "vxlan: ipv4 or ipv6");
1286 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1287 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1292 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
1293 p.encap.vxlan.vlan = 1;
1294 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
1295 p.encap.vxlan.vlan = 0;
1297 snprintf(out, out_size, MSG_ARG_INVALID,
1298 "vxlan: on or off");
1302 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
1305 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1309 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1310 t0 += 2 + n_extra_tokens;
1313 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1314 if (n_tokens < t0 + 4) {
1315 snprintf(out, out_size, MSG_ARG_MISMATCH,
1316 "table action profile nat");
1320 if (strcmp(tokens[t0 + 1], "src") == 0)
1321 p.nat.source_nat = 1;
1322 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1323 p.nat.source_nat = 0;
1325 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1330 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1331 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1335 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1337 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1340 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1345 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1349 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1350 if (n_tokens < t0 + 4) {
1351 snprintf(out, out_size, MSG_ARG_MISMATCH,
1352 "table action profile ttl");
1356 if (strcmp(tokens[t0 + 1], "drop") == 0)
1358 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1361 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1366 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1367 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1371 if (strcmp(tokens[t0 + 3], "none") == 0)
1372 p.ttl.n_packets_enabled = 0;
1373 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1374 p.ttl.n_packets_enabled = 1;
1376 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1381 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1385 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1386 if (n_tokens < t0 + 2) {
1387 snprintf(out, out_size, MSG_ARG_MISMATCH,
1388 "table action profile stats");
1392 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1393 p.stats.n_packets_enabled = 1;
1394 p.stats.n_bytes_enabled = 0;
1395 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1396 p.stats.n_packets_enabled = 0;
1397 p.stats.n_bytes_enabled = 1;
1398 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1399 p.stats.n_packets_enabled = 1;
1400 p.stats.n_bytes_enabled = 1;
1402 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1403 "pkts or bytes or both");
1407 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1411 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1412 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1416 if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
1417 struct cryptodev *cryptodev;
1419 if (n_tokens < t0 + 5 ||
1420 strcmp(tokens[t0 + 1], "dev") ||
1421 strcmp(tokens[t0 + 3], "offset")) {
1422 snprintf(out, out_size, MSG_ARG_MISMATCH,
1423 "table action profile sym_crypto");
1427 cryptodev = cryptodev_find(tokens[t0 + 2]);
1428 if (cryptodev == NULL) {
1429 snprintf(out, out_size, MSG_ARG_INVALID,
1430 "table action profile sym_crypto");
1434 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
1436 if (parser_read_uint32(&p.sym_crypto.op_offset,
1437 tokens[t0 + 4]) != 0) {
1438 snprintf(out, out_size, MSG_ARG_INVALID,
1439 "table action profile sym_crypto");
1443 p.sym_crypto.mp_create = cryptodev->mp_create;
1444 p.sym_crypto.mp_init = cryptodev->mp_init;
1446 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
1451 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {
1452 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
1456 if ((t0 < n_tokens) && (strcmp(tokens[t0], "decap") == 0)) {
1457 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1461 if (t0 < n_tokens) {
1462 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1466 ap = table_action_profile_create(name, &p);
1468 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1473 static const char cmd_pipeline_help[] =
1474 "pipeline <pipeline_name>\n"
1475 " period <timer_period_ms>\n"
1476 " offset_port_id <offset_port_id>\n"
1480 cmd_pipeline(char **tokens,
1485 struct pipeline_params p;
1487 struct pipeline *pipeline;
1489 if (n_tokens != 8) {
1490 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1496 if (strcmp(tokens[2], "period") != 0) {
1497 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1501 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1502 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1506 if (strcmp(tokens[4], "offset_port_id") != 0) {
1507 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1511 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1512 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1516 if (strcmp(tokens[6], "cpu") != 0) {
1517 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1521 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1522 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1526 pipeline = pipeline_create(name, &p);
1527 if (pipeline == NULL) {
1528 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1533 static const char cmd_pipeline_port_in_help[] =
1534 "pipeline <pipeline_name> port in\n"
1535 " bsz <burst_size>\n"
1536 " link <link_name> rxq <queue_id>\n"
1537 " | swq <swq_name>\n"
1538 " | tmgr <tmgr_name>\n"
1539 " | tap <tap_name> mempool <mempool_name> mtu <mtu>\n"
1540 " | kni <kni_name>\n"
1541 " | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>\n"
1542 " | cryptodev <cryptodev_name> rxq <queue_id>\n"
1543 " [action <port_in_action_profile_name>]\n"
1547 cmd_pipeline_port_in(char **tokens,
1552 struct port_in_params p;
1553 char *pipeline_name;
1555 int enabled, status;
1558 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1562 pipeline_name = tokens[1];
1564 if (strcmp(tokens[2], "port") != 0) {
1565 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1569 if (strcmp(tokens[3], "in") != 0) {
1570 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1574 if (strcmp(tokens[4], "bsz") != 0) {
1575 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1579 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1580 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1586 if (strcmp(tokens[t0], "link") == 0) {
1587 if (n_tokens < t0 + 4) {
1588 snprintf(out, out_size, MSG_ARG_MISMATCH,
1589 "pipeline port in link");
1593 p.type = PORT_IN_RXQ;
1595 p.dev_name = tokens[t0 + 1];
1597 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1598 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1602 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1603 snprintf(out, out_size, MSG_ARG_INVALID,
1608 } else if (strcmp(tokens[t0], "swq") == 0) {
1609 if (n_tokens < t0 + 2) {
1610 snprintf(out, out_size, MSG_ARG_MISMATCH,
1611 "pipeline port in swq");
1615 p.type = PORT_IN_SWQ;
1617 p.dev_name = tokens[t0 + 1];
1620 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1621 if (n_tokens < t0 + 2) {
1622 snprintf(out, out_size, MSG_ARG_MISMATCH,
1623 "pipeline port in tmgr");
1627 p.type = PORT_IN_TMGR;
1629 p.dev_name = tokens[t0 + 1];
1632 } else if (strcmp(tokens[t0], "tap") == 0) {
1633 if (n_tokens < t0 + 6) {
1634 snprintf(out, out_size, MSG_ARG_MISMATCH,
1635 "pipeline port in tap");
1639 p.type = PORT_IN_TAP;
1641 p.dev_name = tokens[t0 + 1];
1643 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1644 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1649 p.tap.mempool_name = tokens[t0 + 3];
1651 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1652 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1657 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1658 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1663 } else if (strcmp(tokens[t0], "kni") == 0) {
1664 if (n_tokens < t0 + 2) {
1665 snprintf(out, out_size, MSG_ARG_MISMATCH,
1666 "pipeline port in kni");
1670 p.type = PORT_IN_KNI;
1672 p.dev_name = tokens[t0 + 1];
1675 } else if (strcmp(tokens[t0], "source") == 0) {
1676 if (n_tokens < t0 + 6) {
1677 snprintf(out, out_size, MSG_ARG_MISMATCH,
1678 "pipeline port in source");
1682 p.type = PORT_IN_SOURCE;
1686 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1687 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1692 p.source.mempool_name = tokens[t0 + 2];
1694 if (strcmp(tokens[t0 + 3], "file") != 0) {
1695 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1700 p.source.file_name = tokens[t0 + 4];
1702 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1703 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1708 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1709 snprintf(out, out_size, MSG_ARG_INVALID,
1715 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
1716 if (n_tokens < t0 + 3) {
1717 snprintf(out, out_size, MSG_ARG_MISMATCH,
1718 "pipeline port in cryptodev");
1722 p.type = PORT_IN_CRYPTODEV;
1724 p.dev_name = tokens[t0 + 1];
1725 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1726 snprintf(out, out_size, MSG_ARG_INVALID,
1731 p.cryptodev.arg_callback = NULL;
1732 p.cryptodev.f_callback = NULL;
1736 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1740 p.action_profile_name = NULL;
1741 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1742 if (n_tokens < t0 + 2) {
1743 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1747 p.action_profile_name = tokens[t0 + 1];
1753 if ((n_tokens > t0) &&
1754 (strcmp(tokens[t0], "disabled") == 0)) {
1760 if (n_tokens != t0) {
1761 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1765 status = pipeline_port_in_create(pipeline_name,
1768 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1773 static const char cmd_pipeline_port_out_help[] =
1774 "pipeline <pipeline_name> port out\n"
1775 " bsz <burst_size>\n"
1776 " link <link_name> txq <txq_id>\n"
1777 " | swq <swq_name>\n"
1778 " | tmgr <tmgr_name>\n"
1779 " | tap <tap_name>\n"
1780 " | kni <kni_name>\n"
1781 " | sink [file <file_name> pkts <max_n_pkts>]\n"
1782 " | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>\n";
1785 cmd_pipeline_port_out(char **tokens,
1790 struct port_out_params p;
1791 char *pipeline_name;
1794 memset(&p, 0, sizeof(p));
1797 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1801 pipeline_name = tokens[1];
1803 if (strcmp(tokens[2], "port") != 0) {
1804 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1808 if (strcmp(tokens[3], "out") != 0) {
1809 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1813 if (strcmp(tokens[4], "bsz") != 0) {
1814 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1818 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1819 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1823 if (strcmp(tokens[6], "link") == 0) {
1824 if (n_tokens != 10) {
1825 snprintf(out, out_size, MSG_ARG_MISMATCH,
1826 "pipeline port out link");
1830 p.type = PORT_OUT_TXQ;
1832 p.dev_name = tokens[7];
1834 if (strcmp(tokens[8], "txq") != 0) {
1835 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1839 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1840 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1843 } else if (strcmp(tokens[6], "swq") == 0) {
1844 if (n_tokens != 8) {
1845 snprintf(out, out_size, MSG_ARG_MISMATCH,
1846 "pipeline port out swq");
1850 p.type = PORT_OUT_SWQ;
1852 p.dev_name = tokens[7];
1853 } else if (strcmp(tokens[6], "tmgr") == 0) {
1854 if (n_tokens != 8) {
1855 snprintf(out, out_size, MSG_ARG_MISMATCH,
1856 "pipeline port out tmgr");
1860 p.type = PORT_OUT_TMGR;
1862 p.dev_name = tokens[7];
1863 } else if (strcmp(tokens[6], "tap") == 0) {
1864 if (n_tokens != 8) {
1865 snprintf(out, out_size, MSG_ARG_MISMATCH,
1866 "pipeline port out tap");
1870 p.type = PORT_OUT_TAP;
1872 p.dev_name = tokens[7];
1873 } else if (strcmp(tokens[6], "kni") == 0) {
1874 if (n_tokens != 8) {
1875 snprintf(out, out_size, MSG_ARG_MISMATCH,
1876 "pipeline port out kni");
1880 p.type = PORT_OUT_KNI;
1882 p.dev_name = tokens[7];
1883 } else if (strcmp(tokens[6], "sink") == 0) {
1884 if ((n_tokens != 7) && (n_tokens != 11)) {
1885 snprintf(out, out_size, MSG_ARG_MISMATCH,
1886 "pipeline port out sink");
1890 p.type = PORT_OUT_SINK;
1894 if (n_tokens == 7) {
1895 p.sink.file_name = NULL;
1896 p.sink.max_n_pkts = 0;
1898 if (strcmp(tokens[7], "file") != 0) {
1899 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1904 p.sink.file_name = tokens[8];
1906 if (strcmp(tokens[9], "pkts") != 0) {
1907 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1911 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1912 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1917 } else if (strcmp(tokens[6], "cryptodev") == 0) {
1918 if (n_tokens != 12) {
1919 snprintf(out, out_size, MSG_ARG_MISMATCH,
1920 "pipeline port out cryptodev");
1924 p.type = PORT_OUT_CRYPTODEV;
1926 p.dev_name = tokens[7];
1928 if (strcmp(tokens[8], "txq")) {
1929 snprintf(out, out_size, MSG_ARG_MISMATCH,
1930 "pipeline port out cryptodev");
1934 if (parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
1936 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1940 if (strcmp(tokens[10], "offset")) {
1941 snprintf(out, out_size, MSG_ARG_MISMATCH,
1942 "pipeline port out cryptodev");
1946 if (parser_read_uint32(&p.cryptodev.op_offset, tokens[11])
1948 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1952 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1956 status = pipeline_port_out_create(pipeline_name, &p);
1958 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1963 static const char cmd_pipeline_table_help[] =
1964 "pipeline <pipeline_name> table\n"
1968 " offset <ip_header_offset>\n"
1971 " offset <key_offset>\n"
1976 " mask <key_mask>\n"
1977 " offset <key_offset>\n"
1978 " buckets <n_buckets>\n"
1982 " offset <ip_header_offset>\n"
1985 " [action <table_action_profile_name>]\n";
1988 cmd_pipeline_table(char **tokens,
1993 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
1994 struct table_params p;
1995 char *pipeline_name;
2000 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2004 pipeline_name = tokens[1];
2006 if (strcmp(tokens[2], "table") != 0) {
2007 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2011 if (strcmp(tokens[3], "match") != 0) {
2012 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2017 if (strcmp(tokens[t0], "acl") == 0) {
2018 if (n_tokens < t0 + 6) {
2019 snprintf(out, out_size, MSG_ARG_MISMATCH,
2020 "pipeline table acl");
2024 p.match_type = TABLE_ACL;
2026 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2027 p.match.acl.ip_version = 1;
2028 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2029 p.match.acl.ip_version = 0;
2031 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2036 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2037 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2041 if (parser_read_uint32(&p.match.acl.ip_header_offset,
2042 tokens[t0 + 3]) != 0) {
2043 snprintf(out, out_size, MSG_ARG_INVALID,
2044 "ip_header_offset");
2048 if (strcmp(tokens[t0 + 4], "size") != 0) {
2049 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2053 if (parser_read_uint32(&p.match.acl.n_rules,
2054 tokens[t0 + 5]) != 0) {
2055 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2060 } else if (strcmp(tokens[t0], "array") == 0) {
2061 if (n_tokens < t0 + 5) {
2062 snprintf(out, out_size, MSG_ARG_MISMATCH,
2063 "pipeline table array");
2067 p.match_type = TABLE_ARRAY;
2069 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2070 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2074 if (parser_read_uint32(&p.match.array.key_offset,
2075 tokens[t0 + 2]) != 0) {
2076 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2080 if (strcmp(tokens[t0 + 3], "size") != 0) {
2081 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2085 if (parser_read_uint32(&p.match.array.n_keys,
2086 tokens[t0 + 4]) != 0) {
2087 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2092 } else if (strcmp(tokens[t0], "hash") == 0) {
2093 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2095 if (n_tokens < t0 + 12) {
2096 snprintf(out, out_size, MSG_ARG_MISMATCH,
2097 "pipeline table hash");
2101 p.match_type = TABLE_HASH;
2103 if (strcmp(tokens[t0 + 1], "ext") == 0)
2104 p.match.hash.extendable_bucket = 1;
2105 else if (strcmp(tokens[t0 + 1], "lru") == 0)
2106 p.match.hash.extendable_bucket = 0;
2108 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2113 if (strcmp(tokens[t0 + 2], "key") != 0) {
2114 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2118 if ((parser_read_uint32(&p.match.hash.key_size,
2119 tokens[t0 + 3]) != 0) ||
2120 (p.match.hash.key_size == 0) ||
2121 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
2122 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2126 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2127 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2131 if ((parse_hex_string(tokens[t0 + 5],
2132 key_mask, &key_mask_size) != 0) ||
2133 (key_mask_size != p.match.hash.key_size)) {
2134 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2137 p.match.hash.key_mask = key_mask;
2139 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2140 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2144 if (parser_read_uint32(&p.match.hash.key_offset,
2145 tokens[t0 + 7]) != 0) {
2146 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2150 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2151 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2155 if (parser_read_uint32(&p.match.hash.n_buckets,
2156 tokens[t0 + 9]) != 0) {
2157 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2161 if (strcmp(tokens[t0 + 10], "size") != 0) {
2162 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2166 if (parser_read_uint32(&p.match.hash.n_keys,
2167 tokens[t0 + 11]) != 0) {
2168 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2173 } else if (strcmp(tokens[t0], "lpm") == 0) {
2174 if (n_tokens < t0 + 6) {
2175 snprintf(out, out_size, MSG_ARG_MISMATCH,
2176 "pipeline table lpm");
2180 p.match_type = TABLE_LPM;
2182 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2183 p.match.lpm.key_size = 4;
2184 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2185 p.match.lpm.key_size = 16;
2187 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2192 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2193 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2197 if (parser_read_uint32(&p.match.lpm.key_offset,
2198 tokens[t0 + 3]) != 0) {
2199 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2203 if (strcmp(tokens[t0 + 4], "size") != 0) {
2204 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2208 if (parser_read_uint32(&p.match.lpm.n_rules,
2209 tokens[t0 + 5]) != 0) {
2210 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2215 } else if (strcmp(tokens[t0], "stub") == 0) {
2216 p.match_type = TABLE_STUB;
2220 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2224 p.action_profile_name = NULL;
2225 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
2226 if (n_tokens < t0 + 2) {
2227 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2231 p.action_profile_name = tokens[t0 + 1];
2236 if (n_tokens > t0) {
2237 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2241 status = pipeline_table_create(pipeline_name, &p);
2243 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2248 static const char cmd_pipeline_port_in_table_help[] =
2249 "pipeline <pipeline_name> port in <port_id> table <table_id>\n";
2252 cmd_pipeline_port_in_table(char **tokens,
2257 char *pipeline_name;
2258 uint32_t port_id, table_id;
2261 if (n_tokens != 7) {
2262 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2266 pipeline_name = tokens[1];
2268 if (strcmp(tokens[2], "port") != 0) {
2269 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2273 if (strcmp(tokens[3], "in") != 0) {
2274 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2278 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2279 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2283 if (strcmp(tokens[5], "table") != 0) {
2284 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2288 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
2289 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2293 status = pipeline_port_in_connect_to_table(pipeline_name,
2297 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2303 static const char cmd_pipeline_port_in_stats_help[] =
2304 "pipeline <pipeline_name> port in <port_id> stats read [clear]\n";
2306 #define MSG_PIPELINE_PORT_IN_STATS \
2307 "Pkts in: %" PRIu64 "\n" \
2308 "Pkts dropped by AH: %" PRIu64 "\n" \
2309 "Pkts dropped by other: %" PRIu64 "\n"
2312 cmd_pipeline_port_in_stats(char **tokens,
2317 struct rte_pipeline_port_in_stats stats;
2318 char *pipeline_name;
2322 if ((n_tokens != 7) && (n_tokens != 8)) {
2323 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2327 pipeline_name = tokens[1];
2329 if (strcmp(tokens[2], "port") != 0) {
2330 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2334 if (strcmp(tokens[3], "in") != 0) {
2335 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2339 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2340 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2344 if (strcmp(tokens[5], "stats") != 0) {
2345 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2349 if (strcmp(tokens[6], "read") != 0) {
2350 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2355 if (n_tokens == 8) {
2356 if (strcmp(tokens[7], "clear") != 0) {
2357 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2364 status = pipeline_port_in_stats_read(pipeline_name,
2369 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2373 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2374 stats.stats.n_pkts_in,
2375 stats.n_pkts_dropped_by_ah,
2376 stats.stats.n_pkts_drop);
2380 static const char cmd_pipeline_port_in_enable_help[] =
2381 "pipeline <pipeline_name> port in <port_id> enable\n";
2384 cmd_pipeline_port_in_enable(char **tokens,
2389 char *pipeline_name;
2393 if (n_tokens != 6) {
2394 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2398 pipeline_name = tokens[1];
2400 if (strcmp(tokens[2], "port") != 0) {
2401 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2405 if (strcmp(tokens[3], "in") != 0) {
2406 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2410 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2411 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2415 if (strcmp(tokens[5], "enable") != 0) {
2416 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2420 status = pipeline_port_in_enable(pipeline_name, port_id);
2422 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2428 static const char cmd_pipeline_port_in_disable_help[] =
2429 "pipeline <pipeline_name> port in <port_id> disable\n";
2432 cmd_pipeline_port_in_disable(char **tokens,
2437 char *pipeline_name;
2441 if (n_tokens != 6) {
2442 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2446 pipeline_name = tokens[1];
2448 if (strcmp(tokens[2], "port") != 0) {
2449 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2453 if (strcmp(tokens[3], "in") != 0) {
2454 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2458 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2459 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2463 if (strcmp(tokens[5], "disable") != 0) {
2464 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2468 status = pipeline_port_in_disable(pipeline_name, port_id);
2470 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2476 static const char cmd_pipeline_port_out_stats_help[] =
2477 "pipeline <pipeline_name> port out <port_id> stats read [clear]\n";
2479 #define MSG_PIPELINE_PORT_OUT_STATS \
2480 "Pkts in: %" PRIu64 "\n" \
2481 "Pkts dropped by AH: %" PRIu64 "\n" \
2482 "Pkts dropped by other: %" PRIu64 "\n"
2485 cmd_pipeline_port_out_stats(char **tokens,
2490 struct rte_pipeline_port_out_stats stats;
2491 char *pipeline_name;
2495 if ((n_tokens != 7) && (n_tokens != 8)) {
2496 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2500 pipeline_name = tokens[1];
2502 if (strcmp(tokens[2], "port") != 0) {
2503 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2507 if (strcmp(tokens[3], "out") != 0) {
2508 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2512 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2513 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2517 if (strcmp(tokens[5], "stats") != 0) {
2518 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2522 if (strcmp(tokens[6], "read") != 0) {
2523 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2528 if (n_tokens == 8) {
2529 if (strcmp(tokens[7], "clear") != 0) {
2530 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2537 status = pipeline_port_out_stats_read(pipeline_name,
2542 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2546 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2547 stats.stats.n_pkts_in,
2548 stats.n_pkts_dropped_by_ah,
2549 stats.stats.n_pkts_drop);
2553 static const char cmd_pipeline_table_stats_help[] =
2554 "pipeline <pipeline_name> table <table_id> stats read [clear]\n";
2556 #define MSG_PIPELINE_TABLE_STATS \
2557 "Pkts in: %" PRIu64 "\n" \
2558 "Pkts in with lookup miss: %" PRIu64 "\n" \
2559 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2560 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2561 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2562 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2565 cmd_pipeline_table_stats(char **tokens,
2570 struct rte_pipeline_table_stats stats;
2571 char *pipeline_name;
2575 if ((n_tokens != 6) && (n_tokens != 7)) {
2576 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2580 pipeline_name = tokens[1];
2582 if (strcmp(tokens[2], "table") != 0) {
2583 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2587 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2588 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2592 if (strcmp(tokens[4], "stats") != 0) {
2593 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2597 if (strcmp(tokens[5], "read") != 0) {
2598 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2603 if (n_tokens == 7) {
2604 if (strcmp(tokens[6], "clear") != 0) {
2605 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2612 status = pipeline_table_stats_read(pipeline_name,
2617 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2621 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2622 stats.stats.n_pkts_in,
2623 stats.stats.n_pkts_lookup_miss,
2624 stats.n_pkts_dropped_by_lkp_hit_ah,
2625 stats.n_pkts_dropped_lkp_hit,
2626 stats.n_pkts_dropped_by_lkp_miss_ah,
2627 stats.n_pkts_dropped_lkp_miss);
2635 * priority <priority>
2636 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2637 * <sp0> <sp1> <dp0> <dp1> <proto>
2641 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2642 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2643 * | ipv4_addr <addr>
2644 * | ipv6_addr <addr>
2645 * | qinq <svlan> <cvlan>
2647 * ipv4 | ipv6 <addr> <depth>
2649 struct pkt_key_qinq {
2650 uint16_t ethertype_svlan;
2652 uint16_t ethertype_cvlan;
2654 } __attribute__((__packed__));
2656 struct pkt_key_ipv4_5tuple {
2657 uint8_t time_to_live;
2659 uint16_t hdr_checksum;
2664 } __attribute__((__packed__));
2666 struct pkt_key_ipv6_5tuple {
2667 uint16_t payload_length;
2674 } __attribute__((__packed__));
2676 struct pkt_key_ipv4_addr {
2678 } __attribute__((__packed__));
2680 struct pkt_key_ipv6_addr {
2682 } __attribute__((__packed__));
2685 parse_match(char **tokens,
2689 struct table_rule_match *m)
2691 memset(m, 0, sizeof(*m));
2696 if (strcmp(tokens[0], "match") != 0) {
2697 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2701 if (strcmp(tokens[1], "acl") == 0) {
2702 if (n_tokens < 14) {
2703 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2707 m->match_type = TABLE_ACL;
2709 if (strcmp(tokens[2], "priority") != 0) {
2710 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2714 if (parser_read_uint32(&m->match.acl.priority,
2716 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2720 if (strcmp(tokens[4], "ipv4") == 0) {
2721 struct in_addr saddr, daddr;
2723 m->match.acl.ip_version = 1;
2725 if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2726 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2729 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2731 if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2732 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2735 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2736 } else if (strcmp(tokens[4], "ipv6") == 0) {
2737 struct in6_addr saddr, daddr;
2739 m->match.acl.ip_version = 0;
2741 if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2742 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2745 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2747 if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2748 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2751 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2753 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2758 if (parser_read_uint32(&m->match.acl.sa_depth,
2760 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2764 if (parser_read_uint32(&m->match.acl.da_depth,
2766 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2770 if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2771 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2775 if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2776 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2780 if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2781 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2785 if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2786 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2790 if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2791 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2795 m->match.acl.proto_mask = 0xff;
2800 if (strcmp(tokens[1], "array") == 0) {
2802 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2806 m->match_type = TABLE_ARRAY;
2808 if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2809 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2816 if (strcmp(tokens[1], "hash") == 0) {
2818 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2822 m->match_type = TABLE_HASH;
2824 if (strcmp(tokens[2], "raw") == 0) {
2825 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2828 snprintf(out, out_size, MSG_ARG_MISMATCH,
2833 if (parse_hex_string(tokens[3],
2834 m->match.hash.key, &key_size) != 0) {
2835 snprintf(out, out_size, MSG_ARG_INVALID, "key");
2842 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2843 struct pkt_key_ipv4_5tuple *ipv4 =
2844 (struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2845 struct in_addr saddr, daddr;
2850 snprintf(out, out_size, MSG_ARG_MISMATCH,
2855 if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2856 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2860 if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2861 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2865 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2866 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2870 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2871 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2875 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2876 snprintf(out, out_size, MSG_ARG_INVALID,
2881 ipv4->sa = saddr.s_addr;
2882 ipv4->da = daddr.s_addr;
2883 ipv4->sp = rte_cpu_to_be_16(sp);
2884 ipv4->dp = rte_cpu_to_be_16(dp);
2885 ipv4->proto = proto;
2888 } /* hash ipv4_5tuple */
2890 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2891 struct pkt_key_ipv6_5tuple *ipv6 =
2892 (struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2893 struct in6_addr saddr, daddr;
2898 snprintf(out, out_size, MSG_ARG_MISMATCH,
2903 if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2904 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2908 if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2909 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2913 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2914 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2918 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2919 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2923 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2924 snprintf(out, out_size, MSG_ARG_INVALID,
2929 memcpy(ipv6->sa, saddr.s6_addr, 16);
2930 memcpy(ipv6->da, daddr.s6_addr, 16);
2931 ipv6->sp = rte_cpu_to_be_16(sp);
2932 ipv6->dp = rte_cpu_to_be_16(dp);
2933 ipv6->proto = proto;
2936 } /* hash ipv6_5tuple */
2938 if (strcmp(tokens[2], "ipv4_addr") == 0) {
2939 struct pkt_key_ipv4_addr *ipv4_addr =
2940 (struct pkt_key_ipv4_addr *) m->match.hash.key;
2941 struct in_addr addr;
2944 snprintf(out, out_size, MSG_ARG_MISMATCH,
2949 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2950 snprintf(out, out_size, MSG_ARG_INVALID,
2955 ipv4_addr->addr = addr.s_addr;
2958 } /* hash ipv4_addr */
2960 if (strcmp(tokens[2], "ipv6_addr") == 0) {
2961 struct pkt_key_ipv6_addr *ipv6_addr =
2962 (struct pkt_key_ipv6_addr *) m->match.hash.key;
2963 struct in6_addr addr;
2966 snprintf(out, out_size, MSG_ARG_MISMATCH,
2971 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2972 snprintf(out, out_size, MSG_ARG_INVALID,
2977 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
2980 } /* hash ipv6_5tuple */
2982 if (strcmp(tokens[2], "qinq") == 0) {
2983 struct pkt_key_qinq *qinq =
2984 (struct pkt_key_qinq *) m->match.hash.key;
2985 uint16_t svlan, cvlan;
2988 snprintf(out, out_size, MSG_ARG_MISMATCH,
2993 if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
2995 snprintf(out, out_size, MSG_ARG_INVALID,
3000 if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3002 snprintf(out, out_size, MSG_ARG_INVALID,
3007 qinq->svlan = rte_cpu_to_be_16(svlan);
3008 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3013 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3017 if (strcmp(tokens[1], "lpm") == 0) {
3019 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3023 m->match_type = TABLE_LPM;
3025 if (strcmp(tokens[2], "ipv4") == 0) {
3026 struct in_addr addr;
3028 m->match.lpm.ip_version = 1;
3030 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
3031 snprintf(out, out_size, MSG_ARG_INVALID,
3036 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3037 } else if (strcmp(tokens[2], "ipv6") == 0) {
3038 struct in6_addr addr;
3040 m->match.lpm.ip_version = 0;
3042 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
3043 snprintf(out, out_size, MSG_ARG_INVALID,
3048 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3050 snprintf(out, out_size, MSG_ARG_MISMATCH,
3055 if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3056 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3063 snprintf(out, out_size, MSG_ARG_MISMATCH,
3064 "acl or array or hash or lpm");
3076 * | table <table_id>
3077 * [balance <out0> ... <out7>]
3079 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3080 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3081 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3082 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3083 * [tm subport <subport_id> pipe <pipe_id>]
3086 * | vlan <da> <sa> <pcp> <dei> <vid>
3087 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3088 * | mpls unicast | multicast
3090 * label0 <label> <tc> <ttl>
3091 * [label1 <label> <tc> <ttl>
3092 * [label2 <label> <tc> <ttl>
3093 * [label3 <label> <tc> <ttl>]]]
3094 * | pppoe <da> <sa> <session_id>
3095 * | vxlan ether <da> <sa>
3096 * [vlan <pcp> <dei> <vid>]
3097 * ipv4 <sa> <da> <dscp> <ttl>
3098 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3101 * [nat ipv4 | ipv6 <addr> <port>]
3109 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3111 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3112 * auth_algo <algo> auth_key <key> digest_size <size>
3114 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3115 * digest_size <size>
3116 * data_offset <data_offset>]
3121 * <pa> ::= g | y | r | drop
3124 parse_table_action_fwd(char **tokens,
3126 struct table_rule_action *a)
3128 if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
3134 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3135 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3136 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3140 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3143 if ((n_tokens < 2) ||
3144 parser_read_uint32(&id, tokens[1]))
3147 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3149 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3153 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3154 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3155 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3159 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3162 if ((n_tokens < 2) ||
3163 parser_read_uint32(&id, tokens[1]))
3166 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3168 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3176 parse_table_action_balance(char **tokens,
3178 struct table_rule_action *a)
3182 if ((n_tokens == 0) || (strcmp(tokens[0], "balance") != 0))
3188 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3191 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3192 if (parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3195 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3196 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3201 parse_policer_action(char *token, enum rte_table_action_policer *a)
3203 if (strcmp(token, "g") == 0) {
3204 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3208 if (strcmp(token, "y") == 0) {
3209 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3213 if (strcmp(token, "r") == 0) {
3214 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3218 if (strcmp(token, "drop") == 0) {
3219 *a = RTE_TABLE_ACTION_POLICER_DROP;
3227 parse_table_action_meter_tc(char **tokens,
3229 struct rte_table_action_mtr_tc_params *mtr)
3231 if ((n_tokens < 9) ||
3232 strcmp(tokens[0], "meter") ||
3233 parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3234 strcmp(tokens[2], "policer") ||
3235 strcmp(tokens[3], "g") ||
3236 parse_policer_action(tokens[4], &mtr->policer[e_RTE_METER_GREEN]) ||
3237 strcmp(tokens[5], "y") ||
3238 parse_policer_action(tokens[6], &mtr->policer[e_RTE_METER_YELLOW]) ||
3239 strcmp(tokens[7], "r") ||
3240 parse_policer_action(tokens[8], &mtr->policer[e_RTE_METER_RED]))
3247 parse_table_action_meter(char **tokens,
3249 struct table_rule_action *a)
3251 if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
3257 if ((n_tokens < 10) ||
3258 strcmp(tokens[0], "tc0") ||
3259 (parse_table_action_meter_tc(tokens + 1,
3261 &a->mtr.mtr[0]) == 0))
3267 if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
3269 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3273 if ((n_tokens < 30) ||
3274 (parse_table_action_meter_tc(tokens + 1,
3275 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3276 strcmp(tokens[10], "tc2") ||
3277 (parse_table_action_meter_tc(tokens + 11,
3278 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3279 strcmp(tokens[20], "tc3") ||
3280 (parse_table_action_meter_tc(tokens + 21,
3281 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3284 a->mtr.tc_mask = 0xF;
3285 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3286 return 1 + 10 + 3 * 10;
3290 parse_table_action_tm(char **tokens,
3292 struct table_rule_action *a)
3294 uint32_t subport_id, pipe_id;
3296 if ((n_tokens < 5) ||
3297 strcmp(tokens[0], "tm") ||
3298 strcmp(tokens[1], "subport") ||
3299 parser_read_uint32(&subport_id, tokens[2]) ||
3300 strcmp(tokens[3], "pipe") ||
3301 parser_read_uint32(&pipe_id, tokens[4]))
3304 a->tm.subport_id = subport_id;
3305 a->tm.pipe_id = pipe_id;
3306 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3311 parse_table_action_encap(char **tokens,
3313 struct table_rule_action *a)
3315 if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
3322 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3323 if ((n_tokens < 3) ||
3324 parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3325 parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3328 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3329 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3334 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3335 uint32_t pcp, dei, vid;
3337 if ((n_tokens < 6) ||
3338 parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3339 parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3340 parser_read_uint32(&pcp, tokens[3]) ||
3342 parser_read_uint32(&dei, tokens[4]) ||
3344 parser_read_uint32(&vid, tokens[5]) ||
3348 a->encap.vlan.vlan.pcp = pcp & 0x7;
3349 a->encap.vlan.vlan.dei = dei & 0x1;
3350 a->encap.vlan.vlan.vid = vid & 0xFFF;
3351 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3352 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3357 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3358 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3359 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3361 if ((n_tokens < 9) ||
3362 parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3363 parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3364 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3365 (svlan_pcp > 0x7) ||
3366 parser_read_uint32(&svlan_dei, tokens[4]) ||
3367 (svlan_dei > 0x1) ||
3368 parser_read_uint32(&svlan_vid, tokens[5]) ||
3369 (svlan_vid > 0xFFF) ||
3370 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3371 (cvlan_pcp > 0x7) ||
3372 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3373 (cvlan_dei > 0x1) ||
3374 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3375 (cvlan_vid > 0xFFF))
3378 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3379 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3380 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3381 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3382 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3383 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3384 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3385 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3390 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3391 uint32_t label, tc, ttl;
3396 if (strcmp(tokens[1], "unicast") == 0)
3397 a->encap.mpls.unicast = 1;
3398 else if (strcmp(tokens[1], "multicast") == 0)
3399 a->encap.mpls.unicast = 0;
3403 if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3404 parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3405 strcmp(tokens[4], "label0") ||
3406 parser_read_uint32(&label, tokens[5]) ||
3407 (label > 0xFFFFF) ||
3408 parser_read_uint32(&tc, tokens[6]) ||
3410 parser_read_uint32(&ttl, tokens[7]) ||
3414 a->encap.mpls.mpls[0].label = label;
3415 a->encap.mpls.mpls[0].tc = tc;
3416 a->encap.mpls.mpls[0].ttl = ttl;
3421 if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3422 a->encap.mpls.mpls_count = 1;
3423 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3424 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3428 if ((n_tokens < 4) ||
3429 parser_read_uint32(&label, tokens[1]) ||
3430 (label > 0xFFFFF) ||
3431 parser_read_uint32(&tc, tokens[2]) ||
3433 parser_read_uint32(&ttl, tokens[3]) ||
3437 a->encap.mpls.mpls[1].label = label;
3438 a->encap.mpls.mpls[1].tc = tc;
3439 a->encap.mpls.mpls[1].ttl = ttl;
3444 if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3445 a->encap.mpls.mpls_count = 2;
3446 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3447 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3451 if ((n_tokens < 4) ||
3452 parser_read_uint32(&label, tokens[1]) ||
3453 (label > 0xFFFFF) ||
3454 parser_read_uint32(&tc, tokens[2]) ||
3456 parser_read_uint32(&ttl, tokens[3]) ||
3460 a->encap.mpls.mpls[2].label = label;
3461 a->encap.mpls.mpls[2].tc = tc;
3462 a->encap.mpls.mpls[2].ttl = ttl;
3467 if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3468 a->encap.mpls.mpls_count = 3;
3469 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3470 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3471 return 1 + 8 + 4 + 4;
3474 if ((n_tokens < 4) ||
3475 parser_read_uint32(&label, tokens[1]) ||
3476 (label > 0xFFFFF) ||
3477 parser_read_uint32(&tc, tokens[2]) ||
3479 parser_read_uint32(&ttl, tokens[3]) ||
3483 a->encap.mpls.mpls[3].label = label;
3484 a->encap.mpls.mpls[3].tc = tc;
3485 a->encap.mpls.mpls[3].ttl = ttl;
3487 a->encap.mpls.mpls_count = 4;
3488 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3489 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3490 return 1 + 8 + 4 + 4 + 4;
3494 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3495 if ((n_tokens < 4) ||
3496 parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3497 parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3498 parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3502 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3503 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3508 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3515 /* ether <da> <sa> */
3516 if ((n_tokens < 3) ||
3517 strcmp(tokens[0], "ether") ||
3518 parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3519 parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3526 /* [vlan <pcp> <dei> <vid>] */
3527 if (strcmp(tokens[0], "vlan") == 0) {
3528 uint32_t pcp, dei, vid;
3530 if ((n_tokens < 4) ||
3531 parser_read_uint32(&pcp, tokens[1]) ||
3533 parser_read_uint32(&dei, tokens[2]) ||
3535 parser_read_uint32(&vid, tokens[3]) ||
3539 a->encap.vxlan.vlan.pcp = pcp;
3540 a->encap.vxlan.vlan.dei = dei;
3541 a->encap.vxlan.vlan.vid = vid;
3548 /* ipv4 <sa> <da> <dscp> <ttl>
3549 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3550 if (strcmp(tokens[0], "ipv4") == 0) {
3551 struct in_addr sa, da;
3554 if ((n_tokens < 5) ||
3555 parse_ipv4_addr(tokens[1], &sa) ||
3556 parse_ipv4_addr(tokens[2], &da) ||
3557 parser_read_uint8(&dscp, tokens[3]) ||
3559 parser_read_uint8(&ttl, tokens[4]))
3562 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3563 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3564 a->encap.vxlan.ipv4.dscp = dscp;
3565 a->encap.vxlan.ipv4.ttl = ttl;
3570 } else if (strcmp(tokens[0], "ipv6") == 0) {
3571 struct in6_addr sa, da;
3572 uint32_t flow_label;
3573 uint8_t dscp, hop_limit;
3575 if ((n_tokens < 6) ||
3576 parse_ipv6_addr(tokens[1], &sa) ||
3577 parse_ipv6_addr(tokens[2], &da) ||
3578 parser_read_uint32(&flow_label, tokens[3]) ||
3579 parser_read_uint8(&dscp, tokens[4]) ||
3581 parser_read_uint8(&hop_limit, tokens[5]))
3584 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3585 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3586 a->encap.vxlan.ipv6.flow_label = flow_label;
3587 a->encap.vxlan.ipv6.dscp = dscp;
3588 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3597 if ((n_tokens < 3) ||
3598 strcmp(tokens[0], "udp") ||
3599 parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3600 parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3608 if ((n_tokens < 2) ||
3609 strcmp(tokens[0], "vxlan") ||
3610 parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3611 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3618 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3619 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3627 parse_table_action_nat(char **tokens,
3629 struct table_rule_action *a)
3631 if ((n_tokens < 4) ||
3632 strcmp(tokens[0], "nat"))
3635 if (strcmp(tokens[1], "ipv4") == 0) {
3636 struct in_addr addr;
3639 if (parse_ipv4_addr(tokens[2], &addr) ||
3640 parser_read_uint16(&port, tokens[3]))
3643 a->nat.ip_version = 1;
3644 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3646 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3650 if (strcmp(tokens[1], "ipv6") == 0) {
3651 struct in6_addr addr;
3654 if (parse_ipv6_addr(tokens[2], &addr) ||
3655 parser_read_uint16(&port, tokens[3]))
3658 a->nat.ip_version = 0;
3659 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3661 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3669 parse_table_action_ttl(char **tokens,
3671 struct table_rule_action *a)
3673 if ((n_tokens < 2) ||
3674 strcmp(tokens[0], "ttl"))
3677 if (strcmp(tokens[1], "dec") == 0)
3678 a->ttl.decrement = 1;
3679 else if (strcmp(tokens[1], "keep") == 0)
3680 a->ttl.decrement = 0;
3684 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3689 parse_table_action_stats(char **tokens,
3691 struct table_rule_action *a)
3693 if ((n_tokens < 1) ||
3694 strcmp(tokens[0], "stats"))
3697 a->stats.n_packets = 0;
3698 a->stats.n_bytes = 0;
3699 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3704 parse_table_action_time(char **tokens,
3706 struct table_rule_action *a)
3708 if ((n_tokens < 1) ||
3709 strcmp(tokens[0], "time"))
3712 a->time.time = rte_rdtsc();
3713 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3718 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
3720 struct rte_crypto_sym_xform *xform[2] = {NULL};
3723 xform[0] = p->xform;
3725 xform[1] = xform[0]->next;
3727 for (i = 0; i < 2; i++) {
3728 if (xform[i] == NULL)
3731 switch (xform[i]->type) {
3732 case RTE_CRYPTO_SYM_XFORM_CIPHER:
3733 if (xform[i]->cipher.key.data)
3734 free(xform[i]->cipher.key.data);
3735 if (p->cipher_auth.cipher_iv.val)
3736 free(p->cipher_auth.cipher_iv.val);
3737 if (p->cipher_auth.cipher_iv_update.val)
3738 free(p->cipher_auth.cipher_iv_update.val);
3740 case RTE_CRYPTO_SYM_XFORM_AUTH:
3741 if (xform[i]->auth.key.data)
3742 free(xform[i]->cipher.key.data);
3743 if (p->cipher_auth.auth_iv.val)
3744 free(p->cipher_auth.cipher_iv.val);
3745 if (p->cipher_auth.auth_iv_update.val)
3746 free(p->cipher_auth.cipher_iv_update.val);
3748 case RTE_CRYPTO_SYM_XFORM_AEAD:
3749 if (xform[i]->aead.key.data)
3750 free(xform[i]->cipher.key.data);
3752 free(p->aead.iv.val);
3753 if (p->aead.aad.val)
3754 free(p->aead.aad.val);
3763 static struct rte_crypto_sym_xform *
3764 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3765 char **tokens, uint32_t n_tokens, uint32_t encrypt,
3766 uint32_t *used_n_tokens)
3768 struct rte_crypto_sym_xform *xform_cipher;
3772 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
3773 strcmp(tokens[3], "cipher_key") ||
3774 strcmp(tokens[5], "cipher_iv"))
3777 xform_cipher = calloc(1, sizeof(*xform_cipher));
3778 if (xform_cipher == NULL)
3781 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3782 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
3783 RTE_CRYPTO_CIPHER_OP_DECRYPT;
3786 status = rte_cryptodev_get_cipher_algo_enum(
3787 &xform_cipher->cipher.algo, tokens[2]);
3792 len = strlen(tokens[4]);
3793 xform_cipher->cipher.key.data = calloc(1, len / 2 + 1);
3794 if (xform_cipher->cipher.key.data == NULL)
3797 status = parse_hex_string(tokens[4],
3798 xform_cipher->cipher.key.data,
3803 xform_cipher->cipher.key.length = (uint16_t)len;
3806 len = strlen(tokens[6]);
3808 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
3809 if (p->cipher_auth.cipher_iv.val == NULL)
3812 status = parse_hex_string(tokens[6],
3813 p->cipher_auth.cipher_iv.val,
3818 xform_cipher->cipher.iv.length = (uint16_t)len;
3819 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3820 p->cipher_auth.cipher_iv.length = (uint32_t)len;
3823 return xform_cipher;
3826 if (xform_cipher->cipher.key.data)
3827 free(xform_cipher->cipher.key.data);
3829 if (p->cipher_auth.cipher_iv.val) {
3830 free(p->cipher_auth.cipher_iv.val);
3831 p->cipher_auth.cipher_iv.val = NULL;
3839 static struct rte_crypto_sym_xform *
3840 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3841 char **tokens, uint32_t n_tokens, uint32_t encrypt,
3842 uint32_t *used_n_tokens)
3844 struct rte_crypto_sym_xform *xform_cipher;
3845 struct rte_crypto_sym_xform *xform_auth;
3849 if (n_tokens < 13 ||
3850 strcmp(tokens[7], "auth_algo") ||
3851 strcmp(tokens[9], "auth_key") ||
3852 strcmp(tokens[11], "digest_size"))
3855 xform_auth = calloc(1, sizeof(*xform_auth));
3856 if (xform_auth == NULL)
3859 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
3860 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
3861 RTE_CRYPTO_AUTH_OP_VERIFY;
3864 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
3870 len = strlen(tokens[10]);
3871 xform_auth->auth.key.data = calloc(1, len / 2 + 1);
3872 if (xform_auth->auth.key.data == NULL)
3875 status = parse_hex_string(tokens[10],
3876 xform_auth->auth.key.data, (uint32_t *)&len);
3880 xform_auth->auth.key.length = (uint16_t)len;
3882 if (strcmp(tokens[11], "digest_size"))
3885 status = parser_read_uint16(&xform_auth->auth.digest_length,
3890 xform_cipher = parse_table_action_cipher(p, tokens, 7, encrypt,
3892 if (xform_cipher == NULL)
3895 *used_n_tokens += 6;
3898 xform_cipher->next = xform_auth;
3899 return xform_cipher;
3901 xform_auth->next = xform_cipher;
3906 if (xform_auth->auth.key.data)
3907 free(xform_auth->auth.key.data);
3908 if (p->cipher_auth.auth_iv.val) {
3909 free(p->cipher_auth.auth_iv.val);
3910 p->cipher_auth.auth_iv.val = 0;
3918 static struct rte_crypto_sym_xform *
3919 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3920 char **tokens, uint32_t n_tokens, uint32_t encrypt,
3921 uint32_t *used_n_tokens)
3923 struct rte_crypto_sym_xform *xform_aead;
3927 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
3928 strcmp(tokens[3], "aead_key") ||
3929 strcmp(tokens[5], "aead_iv") ||
3930 strcmp(tokens[7], "aead_aad") ||
3931 strcmp(tokens[9], "digest_size"))
3934 xform_aead = calloc(1, sizeof(*xform_aead));
3935 if (xform_aead == NULL)
3938 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
3939 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
3940 RTE_CRYPTO_AEAD_OP_DECRYPT;
3943 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
3949 len = strlen(tokens[4]);
3950 xform_aead->aead.key.data = calloc(1, len / 2 + 1);
3951 if (xform_aead->aead.key.data == NULL)
3954 status = parse_hex_string(tokens[4], xform_aead->aead.key.data,
3959 xform_aead->aead.key.length = (uint16_t)len;
3962 len = strlen(tokens[6]);
3963 p->aead.iv.val = calloc(1, len / 2 + 1);
3964 if (p->aead.iv.val == NULL)
3967 status = parse_hex_string(tokens[6], p->aead.iv.val,
3972 xform_aead->aead.iv.length = (uint16_t)len;
3973 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3974 p->aead.iv.length = (uint32_t)len;
3977 len = strlen(tokens[8]);
3978 p->aead.aad.val = calloc(1, len / 2 + 1);
3979 if (p->aead.aad.val == NULL)
3982 status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
3986 xform_aead->aead.aad_length = (uint16_t)len;
3987 p->aead.aad.length = (uint32_t)len;
3990 status = parser_read_uint16(&xform_aead->aead.digest_length,
3995 *used_n_tokens = 11;
4000 if (xform_aead->aead.key.data)
4001 free(xform_aead->aead.key.data);
4002 if (p->aead.iv.val) {
4003 free(p->aead.iv.val);
4004 p->aead.iv.val = NULL;
4006 if (p->aead.aad.val) {
4007 free(p->aead.aad.val);
4008 p->aead.aad.val = NULL;
4018 parse_table_action_sym_crypto(char **tokens,
4020 struct table_rule_action *a)
4022 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4023 struct rte_crypto_sym_xform *xform = NULL;
4024 uint32_t used_n_tokens;
4028 if ((n_tokens < 12) ||
4029 strcmp(tokens[0], "sym_crypto") ||
4030 strcmp(tokens[2], "type"))
4033 memset(p, 0, sizeof(*p));
4035 if (strcmp(tokens[1], "encrypt") == 0)
4040 status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4044 if (strcmp(tokens[3], "cipher") == 0) {
4048 xform = parse_table_action_cipher(p, tokens, n_tokens, encrypt,
4050 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4054 xform = parse_table_action_cipher_auth(p, tokens, n_tokens,
4055 encrypt, &used_n_tokens);
4056 } else if (strcmp(tokens[3], "aead") == 0) {
4060 xform = parse_table_action_aead(p, tokens, n_tokens, encrypt,
4069 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4070 parse_free_sym_crypto_param_data(p);
4074 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4076 return used_n_tokens + 5;
4080 parse_table_action_tag(char **tokens,
4082 struct table_rule_action *a)
4084 if ((n_tokens < 2) ||
4085 strcmp(tokens[0], "tag"))
4088 if (parser_read_uint32(&a->tag.tag, tokens[1]))
4091 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4096 parse_table_action_decap(char **tokens,
4098 struct table_rule_action *a)
4100 if ((n_tokens < 2) ||
4101 strcmp(tokens[0], "decap"))
4104 if (parser_read_uint16(&a->decap.n, tokens[1]))
4107 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4112 parse_table_action(char **tokens,
4116 struct table_rule_action *a)
4118 uint32_t n_tokens0 = n_tokens;
4120 memset(a, 0, sizeof(*a));
4122 if ((n_tokens < 2) ||
4123 strcmp(tokens[0], "action"))
4129 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4132 n = parse_table_action_fwd(tokens, n_tokens, a);
4134 snprintf(out, out_size, MSG_ARG_INVALID,
4143 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4146 n = parse_table_action_balance(tokens, n_tokens, a);
4148 snprintf(out, out_size, MSG_ARG_INVALID,
4157 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4160 n = parse_table_action_meter(tokens, n_tokens, a);
4162 snprintf(out, out_size, MSG_ARG_INVALID,
4171 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4174 n = parse_table_action_tm(tokens, n_tokens, a);
4176 snprintf(out, out_size, MSG_ARG_INVALID,
4185 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4188 n = parse_table_action_encap(tokens, n_tokens, a);
4190 snprintf(out, out_size, MSG_ARG_INVALID,
4199 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4202 n = parse_table_action_nat(tokens, n_tokens, a);
4204 snprintf(out, out_size, MSG_ARG_INVALID,
4213 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4216 n = parse_table_action_ttl(tokens, n_tokens, a);
4218 snprintf(out, out_size, MSG_ARG_INVALID,
4227 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4230 n = parse_table_action_stats(tokens, n_tokens, a);
4232 snprintf(out, out_size, MSG_ARG_INVALID,
4241 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4244 n = parse_table_action_time(tokens, n_tokens, a);
4246 snprintf(out, out_size, MSG_ARG_INVALID,
4255 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4258 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4260 snprintf(out, out_size, MSG_ARG_INVALID,
4261 "action sym_crypto");
4268 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4271 n = parse_table_action_tag(tokens, n_tokens, a);
4273 snprintf(out, out_size, MSG_ARG_INVALID,
4282 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4285 n = parse_table_action_decap(tokens, n_tokens, a);
4287 snprintf(out, out_size, MSG_ARG_INVALID,
4296 if (n_tokens0 - n_tokens == 1) {
4297 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4301 return n_tokens0 - n_tokens;
4305 static const char cmd_pipeline_table_rule_add_help[] =
4306 "pipeline <pipeline_name> table <table_id> rule add\n"
4308 " action <table_action>\n";
4311 cmd_pipeline_table_rule_add(char **tokens,
4316 struct table_rule_match m;
4317 struct table_rule_action a;
4318 char *pipeline_name;
4319 uint32_t table_id, t0, n_tokens_parsed;
4323 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4327 pipeline_name = tokens[1];
4329 if (strcmp(tokens[2], "table") != 0) {
4330 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4334 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4335 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4339 if (strcmp(tokens[4], "rule") != 0) {
4340 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4344 if (strcmp(tokens[5], "add") != 0) {
4345 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4352 n_tokens_parsed = parse_match(tokens + t0,
4357 if (n_tokens_parsed == 0)
4359 t0 += n_tokens_parsed;
4362 n_tokens_parsed = parse_table_action(tokens + t0,
4367 if (n_tokens_parsed == 0)
4369 t0 += n_tokens_parsed;
4371 if (t0 != n_tokens) {
4372 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4376 status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
4378 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4382 if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
4383 parse_free_sym_crypto_param_data(&a.sym_crypto);
4387 static const char cmd_pipeline_table_rule_add_default_help[] =
4388 "pipeline <pipeline_name> table <table_id> rule add\n"
4394 " | port <port_id>\n"
4396 " | table <table_id>\n";
4399 cmd_pipeline_table_rule_add_default(char **tokens,
4404 struct table_rule_action action;
4405 char *pipeline_name;
4409 if ((n_tokens != 11) && (n_tokens != 12)) {
4410 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4414 pipeline_name = tokens[1];
4416 if (strcmp(tokens[2], "table") != 0) {
4417 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4421 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4422 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4426 if (strcmp(tokens[4], "rule") != 0) {
4427 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4431 if (strcmp(tokens[5], "add") != 0) {
4432 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4436 if (strcmp(tokens[6], "match") != 0) {
4437 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4441 if (strcmp(tokens[7], "default") != 0) {
4442 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4446 if (strcmp(tokens[8], "action") != 0) {
4447 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4451 if (strcmp(tokens[9], "fwd") != 0) {
4452 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4456 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4458 if (strcmp(tokens[10], "drop") == 0) {
4459 if (n_tokens != 11) {
4460 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4464 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4465 } else if (strcmp(tokens[10], "port") == 0) {
4468 if (n_tokens != 12) {
4469 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4473 if (parser_read_uint32(&id, tokens[11]) != 0) {
4474 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4478 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4480 } else if (strcmp(tokens[10], "meta") == 0) {
4481 if (n_tokens != 11) {
4482 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4486 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4487 } else if (strcmp(tokens[10], "table") == 0) {
4490 if (n_tokens != 12) {
4491 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4495 if (parser_read_uint32(&id, tokens[11]) != 0) {
4496 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4500 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4503 snprintf(out, out_size, MSG_ARG_INVALID,
4504 "drop or port or meta or table");
4508 status = pipeline_table_rule_add_default(pipeline_name,
4512 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4518 static const char cmd_pipeline_table_rule_add_bulk_help[] =
4519 "pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\n"
4521 " File <file_name>:\n"
4522 " - line format: match <match> action <action>\n";
4525 cli_rule_file_process(const char *file_name,
4526 size_t line_len_max,
4527 struct table_rule_list **rule_list,
4529 uint32_t *line_number,
4534 cmd_pipeline_table_rule_add_bulk(char **tokens,
4539 struct table_rule_list *list = NULL;
4540 char *pipeline_name, *file_name;
4541 uint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;
4544 if (n_tokens != 8) {
4545 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4549 pipeline_name = tokens[1];
4551 if (strcmp(tokens[2], "table") != 0) {
4552 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4556 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4557 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4561 if (strcmp(tokens[4], "rule") != 0) {
4562 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4566 if (strcmp(tokens[5], "add") != 0) {
4567 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4571 if (strcmp(tokens[6], "bulk") != 0) {
4572 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4576 file_name = tokens[7];
4578 /* Load rules from file. */
4579 status = cli_rule_file_process(file_name,
4587 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4592 status = pipeline_table_rule_add_bulk(pipeline_name,
4596 &n_rules_not_added);
4598 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4602 snprintf(out, out_size, "Added %u rules out of %u.\n",
4608 static const char cmd_pipeline_table_rule_delete_help[] =
4609 "pipeline <pipeline_name> table <table_id> rule delete\n"
4613 cmd_pipeline_table_rule_delete(char **tokens,
4618 struct table_rule_match m;
4619 char *pipeline_name;
4620 uint32_t table_id, n_tokens_parsed, t0;
4624 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4628 pipeline_name = tokens[1];
4630 if (strcmp(tokens[2], "table") != 0) {
4631 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4635 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4636 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4640 if (strcmp(tokens[4], "rule") != 0) {
4641 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4645 if (strcmp(tokens[5], "delete") != 0) {
4646 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4653 n_tokens_parsed = parse_match(tokens + t0,
4658 if (n_tokens_parsed == 0)
4660 t0 += n_tokens_parsed;
4662 if (n_tokens != t0) {
4663 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4667 status = pipeline_table_rule_delete(pipeline_name,
4671 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4677 static const char cmd_pipeline_table_rule_delete_default_help[] =
4678 "pipeline <pipeline_name> table <table_id> rule delete\n"
4683 cmd_pipeline_table_rule_delete_default(char **tokens,
4688 char *pipeline_name;
4692 if (n_tokens != 8) {
4693 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4697 pipeline_name = tokens[1];
4699 if (strcmp(tokens[2], "table") != 0) {
4700 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4704 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4705 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4709 if (strcmp(tokens[4], "rule") != 0) {
4710 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4714 if (strcmp(tokens[5], "delete") != 0) {
4715 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4719 if (strcmp(tokens[6], "match") != 0) {
4720 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4724 if (strcmp(tokens[7], "default") != 0) {
4725 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4729 status = pipeline_table_rule_delete_default(pipeline_name,
4732 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4738 ether_addr_show(FILE *f, struct ether_addr *addr)
4740 fprintf(f, "%02x:%02x:%02x:%02x:%02x:%02x",
4741 (uint32_t)addr->addr_bytes[0], (uint32_t)addr->addr_bytes[1],
4742 (uint32_t)addr->addr_bytes[2], (uint32_t)addr->addr_bytes[3],
4743 (uint32_t)addr->addr_bytes[4], (uint32_t)addr->addr_bytes[5]);
4747 ipv4_addr_show(FILE *f, uint32_t addr)
4749 fprintf(f, "%u.%u.%u.%u",
4751 (addr >> 16) & 0xFF,
4757 ipv6_addr_show(FILE *f, uint8_t *addr)
4759 fprintf(f, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
4760 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:",
4761 (uint32_t)addr[0], (uint32_t)addr[1],
4762 (uint32_t)addr[2], (uint32_t)addr[3],
4763 (uint32_t)addr[4], (uint32_t)addr[5],
4764 (uint32_t)addr[6], (uint32_t)addr[7],
4765 (uint32_t)addr[8], (uint32_t)addr[9],
4766 (uint32_t)addr[10], (uint32_t)addr[11],
4767 (uint32_t)addr[12], (uint32_t)addr[13],
4768 (uint32_t)addr[14], (uint32_t)addr[15]);
4772 policer_action_string(enum rte_table_action_policer action) {
4774 case RTE_TABLE_ACTION_POLICER_COLOR_GREEN: return "G";
4775 case RTE_TABLE_ACTION_POLICER_COLOR_YELLOW: return "Y";
4776 case RTE_TABLE_ACTION_POLICER_COLOR_RED: return "R";
4777 case RTE_TABLE_ACTION_POLICER_DROP: return "D";
4778 default: return "?";
4783 table_rule_show(const char *pipeline_name,
4785 const char *file_name)
4788 struct table *table;
4789 struct table_rule *rule;
4793 /* Check input params. */
4794 if ((pipeline_name == NULL) ||
4795 (file_name == NULL))
4798 p = pipeline_find(pipeline_name);
4800 (table_id >= p->n_tables))
4803 table = &p->table[table_id];
4806 f = fopen(file_name, "w");
4810 /* Write table rules to file. */
4811 TAILQ_FOREACH(rule, &table->rules, node) {
4812 struct table_rule_match *m = &rule->match;
4813 struct table_rule_action *a = &rule->action;
4815 fprintf(f, "match ");
4816 switch (m->match_type) {
4818 fprintf(f, "acl priority %u ",
4819 m->match.acl.priority);
4821 fprintf(f, m->match.acl.ip_version ? "ipv4 " : "ipv6 ");
4823 if (m->match.acl.ip_version)
4824 ipv4_addr_show(f, m->match.acl.ipv4.sa);
4826 ipv6_addr_show(f, m->match.acl.ipv6.sa);
4828 fprintf(f, "%u", m->match.acl.sa_depth);
4830 if (m->match.acl.ip_version)
4831 ipv4_addr_show(f, m->match.acl.ipv4.da);
4833 ipv6_addr_show(f, m->match.acl.ipv6.da);
4835 fprintf(f, "%u", m->match.acl.da_depth);
4837 fprintf(f, "%u %u %u %u %u ",
4838 (uint32_t)m->match.acl.sp0,
4839 (uint32_t)m->match.acl.sp1,
4840 (uint32_t)m->match.acl.dp0,
4841 (uint32_t)m->match.acl.dp1,
4842 (uint32_t)m->match.acl.proto);
4846 fprintf(f, "array %u ",
4847 m->match.array.pos);
4851 fprintf(f, "hash raw ");
4852 for (i = 0; i < table->params.match.hash.key_size; i++)
4853 fprintf(f, "%02x", m->match.hash.key[i]);
4860 fprintf(f, m->match.lpm.ip_version ? "ipv4 " : "ipv6 ");
4862 if (m->match.acl.ip_version)
4863 ipv4_addr_show(f, m->match.lpm.ipv4);
4865 ipv6_addr_show(f, m->match.lpm.ipv6);
4868 (uint32_t)m->match.lpm.depth);
4872 fprintf(f, "unknown ");
4875 fprintf(f, "action ");
4876 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
4878 switch (a->fwd.action) {
4879 case RTE_PIPELINE_ACTION_DROP:
4880 fprintf(f, "drop ");
4883 case RTE_PIPELINE_ACTION_PORT:
4884 fprintf(f, "port %u ", a->fwd.id);
4887 case RTE_PIPELINE_ACTION_PORT_META:
4888 fprintf(f, "meta ");
4891 case RTE_PIPELINE_ACTION_TABLE:
4893 fprintf(f, "table %u ", a->fwd.id);
4897 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
4898 fprintf(f, "balance ");
4899 for (i = 0; i < RTE_DIM(a->lb.out); i++)
4900 fprintf(f, "%u ", a->lb.out[i]);
4903 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
4905 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++)
4906 if (a->mtr.tc_mask & (1 << i)) {
4907 struct rte_table_action_mtr_tc_params *p =
4909 enum rte_table_action_policer ga =
4910 p->policer[e_RTE_METER_GREEN];
4911 enum rte_table_action_policer ya =
4912 p->policer[e_RTE_METER_YELLOW];
4913 enum rte_table_action_policer ra =
4914 p->policer[e_RTE_METER_RED];
4916 fprintf(f, "tc%u meter %u policer g %s y %s r %s ",
4918 a->mtr.mtr[i].meter_profile_id,
4919 policer_action_string(ga),
4920 policer_action_string(ya),
4921 policer_action_string(ra));
4925 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TM))
4926 fprintf(f, "tm subport %u pipe %u ",
4930 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
4931 fprintf(f, "encap ");
4932 switch (a->encap.type) {
4933 case RTE_TABLE_ACTION_ENCAP_ETHER:
4934 fprintf(f, "ether ");
4935 ether_addr_show(f, &a->encap.ether.ether.da);
4937 ether_addr_show(f, &a->encap.ether.ether.sa);
4941 case RTE_TABLE_ACTION_ENCAP_VLAN:
4942 fprintf(f, "vlan ");
4943 ether_addr_show(f, &a->encap.vlan.ether.da);
4945 ether_addr_show(f, &a->encap.vlan.ether.sa);
4946 fprintf(f, " pcp %u dei %u vid %u ",
4947 a->encap.vlan.vlan.pcp,
4948 a->encap.vlan.vlan.dei,
4949 a->encap.vlan.vlan.vid);
4952 case RTE_TABLE_ACTION_ENCAP_QINQ:
4953 fprintf(f, "qinq ");
4954 ether_addr_show(f, &a->encap.qinq.ether.da);
4956 ether_addr_show(f, &a->encap.qinq.ether.sa);
4957 fprintf(f, " pcp %u dei %u vid %u pcp %u dei %u vid %u ",
4958 a->encap.qinq.svlan.pcp,
4959 a->encap.qinq.svlan.dei,
4960 a->encap.qinq.svlan.vid,
4961 a->encap.qinq.cvlan.pcp,
4962 a->encap.qinq.cvlan.dei,
4963 a->encap.qinq.cvlan.vid);
4966 case RTE_TABLE_ACTION_ENCAP_MPLS:
4967 fprintf(f, "mpls %s ", (a->encap.mpls.unicast) ?
4968 "unicast " : "multicast ");
4969 ether_addr_show(f, &a->encap.mpls.ether.da);
4971 ether_addr_show(f, &a->encap.mpls.ether.sa);
4973 for (i = 0; i < a->encap.mpls.mpls_count; i++) {
4974 struct rte_table_action_mpls_hdr *l =
4975 &a->encap.mpls.mpls[i];
4977 fprintf(f, "label%u %u %u %u ",
4985 case RTE_TABLE_ACTION_ENCAP_PPPOE:
4986 fprintf(f, "pppoe ");
4987 ether_addr_show(f, &a->encap.pppoe.ether.da);
4989 ether_addr_show(f, &a->encap.pppoe.ether.sa);
4990 fprintf(f, " %u ", a->encap.pppoe.pppoe.session_id);
4993 case RTE_TABLE_ACTION_ENCAP_VXLAN:
4994 fprintf(f, "vxlan ether ");
4995 ether_addr_show(f, &a->encap.vxlan.ether.da);
4997 ether_addr_show(f, &a->encap.vxlan.ether.sa);
4998 if (table->ap->params.encap.vxlan.vlan)
4999 fprintf(f, " vlan pcp %u dei %u vid %u ",
5000 a->encap.vxlan.vlan.pcp,
5001 a->encap.vxlan.vlan.dei,
5002 a->encap.vxlan.vlan.vid);
5003 if (table->ap->params.encap.vxlan.ip_version) {
5004 fprintf(f, " ipv4 ");
5005 ipv4_addr_show(f, a->encap.vxlan.ipv4.sa);
5007 ipv4_addr_show(f, a->encap.vxlan.ipv4.da);
5008 fprintf(f, " %u %u ",
5009 (uint32_t)a->encap.vxlan.ipv4.dscp,
5010 (uint32_t)a->encap.vxlan.ipv4.ttl);
5012 fprintf(f, " ipv6 ");
5013 ipv6_addr_show(f, a->encap.vxlan.ipv6.sa);
5015 ipv6_addr_show(f, a->encap.vxlan.ipv6.da);
5016 fprintf(f, " %u %u %u ",
5017 a->encap.vxlan.ipv6.flow_label,
5018 (uint32_t)a->encap.vxlan.ipv6.dscp,
5019 (uint32_t)a->encap.vxlan.ipv6.hop_limit);
5020 fprintf(f, " udp %u %u vxlan %u ",
5021 a->encap.vxlan.udp.sp,
5022 a->encap.vxlan.udp.dp,
5023 a->encap.vxlan.vxlan.vni);
5028 fprintf(f, "unknown ");
5032 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
5033 fprintf(f, "nat %s ", (a->nat.ip_version) ? "ipv4 " : "ipv6 ");
5034 if (a->nat.ip_version)
5035 ipv4_addr_show(f, a->nat.addr.ipv4);
5037 ipv6_addr_show(f, a->nat.addr.ipv6);
5038 fprintf(f, " %u ", (uint32_t)(a->nat.port));
5041 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TTL))
5042 fprintf(f, "ttl %s ", (a->ttl.decrement) ? "dec" : "keep");
5044 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_STATS))
5045 fprintf(f, "stats ");
5047 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TIME))
5048 fprintf(f, "time ");
5050 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO))
5051 fprintf(f, "sym_crypto ");
5053 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TAG))
5054 fprintf(f, "tag %u ", a->tag.tag);
5056 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
5057 fprintf(f, "decap %u ", a->decap.n);
5063 /* Write table default rule to file. */
5064 if (table->rule_default) {
5065 struct table_rule_action *a = &table->rule_default->action;
5067 fprintf(f, "# match default action fwd ");
5069 switch (a->fwd.action) {
5070 case RTE_PIPELINE_ACTION_DROP:
5071 fprintf(f, "drop ");
5074 case RTE_PIPELINE_ACTION_PORT:
5075 fprintf(f, "port %u ", a->fwd.id);
5078 case RTE_PIPELINE_ACTION_PORT_META:
5079 fprintf(f, "meta ");
5082 case RTE_PIPELINE_ACTION_TABLE:
5084 fprintf(f, "table %u ", a->fwd.id);
5087 fprintf(f, "# match default action fwd drop ");
5097 static const char cmd_pipeline_table_rule_show_help[] =
5098 "pipeline <pipeline_name> table <table_id> rule show\n"
5099 " file <file_name>\n";
5102 cmd_pipeline_table_rule_show(char **tokens,
5107 char *file_name = NULL, *pipeline_name;
5111 if (n_tokens != 8) {
5112 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5116 pipeline_name = tokens[1];
5118 if (strcmp(tokens[2], "table") != 0) {
5119 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5123 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5124 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5128 if (strcmp(tokens[4], "rule") != 0) {
5129 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5133 if (strcmp(tokens[5], "show") != 0) {
5134 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "show");
5138 if (strcmp(tokens[6], "file") != 0) {
5139 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "file");
5143 file_name = tokens[7];
5145 status = table_rule_show(pipeline_name, table_id, file_name);
5147 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5152 static const char cmd_pipeline_table_rule_stats_read_help[] =
5153 "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n"
5157 cmd_pipeline_table_rule_stats_read(char **tokens,
5162 struct table_rule_match m;
5163 struct rte_table_action_stats_counters stats;
5164 char *pipeline_name;
5165 uint32_t table_id, n_tokens_parsed;
5166 int clear = 0, status;
5169 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5173 pipeline_name = tokens[1];
5175 if (strcmp(tokens[2], "table") != 0) {
5176 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5180 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5181 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5185 if (strcmp(tokens[4], "rule") != 0) {
5186 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5190 if (strcmp(tokens[5], "read") != 0) {
5191 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5195 if (strcmp(tokens[6], "stats") != 0) {
5196 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
5204 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5212 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5213 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5217 n_tokens_parsed = parse_match(tokens,
5222 if (n_tokens_parsed == 0)
5224 n_tokens -= n_tokens_parsed;
5225 tokens += n_tokens_parsed;
5229 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5233 /* Read table rule stats. */
5234 status = pipeline_table_rule_stats_read(pipeline_name,
5240 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5245 if (stats.n_packets_valid && stats.n_bytes_valid)
5246 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: %" PRIu64 "\n",
5250 if (stats.n_packets_valid && !stats.n_bytes_valid)
5251 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: N/A\n",
5254 if (!stats.n_packets_valid && stats.n_bytes_valid)
5255 snprintf(out, out_size, "Packets: N/A; Bytes: %" PRIu64 "\n",
5258 if (!stats.n_packets_valid && !stats.n_bytes_valid)
5259 snprintf(out, out_size, "Packets: N/A ; Bytes: N/A\n");
5262 static const char cmd_pipeline_table_meter_profile_add_help[] =
5263 "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
5264 " add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
5265 " | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
5268 cmd_pipeline_table_meter_profile_add(char **tokens,
5273 struct rte_table_action_meter_profile p;
5274 char *pipeline_name;
5275 uint32_t table_id, meter_profile_id;
5279 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5283 pipeline_name = tokens[1];
5285 if (strcmp(tokens[2], "table") != 0) {
5286 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5290 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5291 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5295 if (strcmp(tokens[4], "meter") != 0) {
5296 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5300 if (strcmp(tokens[5], "profile") != 0) {
5301 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5305 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5306 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5310 if (strcmp(tokens[7], "add") != 0) {
5311 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5315 if (strcmp(tokens[8], "srtcm") == 0) {
5316 if (n_tokens != 15) {
5317 snprintf(out, out_size, MSG_ARG_MISMATCH,
5322 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5324 if (strcmp(tokens[9], "cir") != 0) {
5325 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5329 if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5330 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5334 if (strcmp(tokens[11], "cbs") != 0) {
5335 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5339 if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5340 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5344 if (strcmp(tokens[13], "ebs") != 0) {
5345 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5349 if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5350 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5353 } else if (strcmp(tokens[8], "trtcm") == 0) {
5354 if (n_tokens != 17) {
5355 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5359 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5361 if (strcmp(tokens[9], "cir") != 0) {
5362 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5366 if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5367 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5371 if (strcmp(tokens[11], "pir") != 0) {
5372 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5376 if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5377 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5380 if (strcmp(tokens[13], "cbs") != 0) {
5381 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5385 if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5386 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5390 if (strcmp(tokens[15], "pbs") != 0) {
5391 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5395 if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5396 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5400 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5404 status = pipeline_table_mtr_profile_add(pipeline_name,
5409 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5415 static const char cmd_pipeline_table_meter_profile_delete_help[] =
5416 "pipeline <pipeline_name> table <table_id>\n"
5417 " meter profile <meter_profile_id> delete\n";
5420 cmd_pipeline_table_meter_profile_delete(char **tokens,
5425 char *pipeline_name;
5426 uint32_t table_id, meter_profile_id;
5429 if (n_tokens != 8) {
5430 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5434 pipeline_name = tokens[1];
5436 if (strcmp(tokens[2], "table") != 0) {
5437 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5441 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5442 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5446 if (strcmp(tokens[4], "meter") != 0) {
5447 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5451 if (strcmp(tokens[5], "profile") != 0) {
5452 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5456 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5457 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5461 if (strcmp(tokens[7], "delete") != 0) {
5462 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5466 status = pipeline_table_mtr_profile_delete(pipeline_name,
5470 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5476 static const char cmd_pipeline_table_rule_meter_read_help[] =
5477 "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n"
5481 cmd_pipeline_table_rule_meter_read(char **tokens,
5486 struct table_rule_match m;
5487 struct rte_table_action_mtr_counters stats;
5488 char *pipeline_name;
5489 uint32_t table_id, n_tokens_parsed;
5490 int clear = 0, status;
5493 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5497 pipeline_name = tokens[1];
5499 if (strcmp(tokens[2], "table") != 0) {
5500 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5504 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5505 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5509 if (strcmp(tokens[4], "rule") != 0) {
5510 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5514 if (strcmp(tokens[5], "read") != 0) {
5515 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5519 if (strcmp(tokens[6], "meter") != 0) {
5520 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5528 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5536 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5537 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5541 n_tokens_parsed = parse_match(tokens,
5546 if (n_tokens_parsed == 0)
5548 n_tokens -= n_tokens_parsed;
5549 tokens += n_tokens_parsed;
5553 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5557 /* Read table rule meter stats. */
5558 status = pipeline_table_rule_mtr_read(pipeline_name,
5564 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5572 static const char cmd_pipeline_table_dscp_help[] =
5573 "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
5575 " File <file_name>:\n"
5576 " - exactly 64 lines\n"
5577 " - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
5580 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5581 const char *file_name,
5582 uint32_t *line_number)
5587 /* Check input arguments */
5588 if ((dscp_table == NULL) ||
5589 (file_name == NULL) ||
5590 (line_number == NULL)) {
5596 /* Open input file */
5597 f = fopen(file_name, "r");
5604 for (dscp = 0, l = 1; ; l++) {
5607 enum rte_meter_color color;
5608 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5610 if (fgets(line, sizeof(line), f) == NULL)
5613 if (is_comment(line))
5616 if (parse_tokenize_string(line, tokens, &n_tokens)) {
5625 if ((dscp >= RTE_DIM(dscp_table->entry)) ||
5626 (n_tokens != RTE_DIM(tokens)) ||
5627 parser_read_uint32(&tc_id, tokens[0]) ||
5628 (tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
5629 parser_read_uint32(&tc_queue_id, tokens[1]) ||
5630 (tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
5631 (strlen(tokens[2]) != 1)) {
5637 switch (tokens[2][0]) {
5640 color = e_RTE_METER_GREEN;
5645 color = e_RTE_METER_YELLOW;
5650 color = e_RTE_METER_RED;
5659 dscp_table->entry[dscp].tc_id = tc_id;
5660 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5661 dscp_table->entry[dscp].color = color;
5671 cmd_pipeline_table_dscp(char **tokens,
5676 struct rte_table_action_dscp_table dscp_table;
5677 char *pipeline_name, *file_name;
5678 uint32_t table_id, line_number;
5681 if (n_tokens != 6) {
5682 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5686 pipeline_name = tokens[1];
5688 if (strcmp(tokens[2], "table") != 0) {
5689 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5693 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5694 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5698 if (strcmp(tokens[4], "dscp") != 0) {
5699 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5703 file_name = tokens[5];
5705 status = load_dscp_table(&dscp_table, file_name, &line_number);
5707 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5711 status = pipeline_table_dscp_table_update(pipeline_name,
5716 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5722 static const char cmd_pipeline_table_rule_ttl_read_help[] =
5723 "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n"
5727 cmd_pipeline_table_rule_ttl_read(char **tokens,
5732 struct table_rule_match m;
5733 struct rte_table_action_ttl_counters stats;
5734 char *pipeline_name;
5735 uint32_t table_id, n_tokens_parsed;
5736 int clear = 0, status;
5739 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5743 pipeline_name = tokens[1];
5745 if (strcmp(tokens[2], "table") != 0) {
5746 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5750 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5751 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5755 if (strcmp(tokens[4], "rule") != 0) {
5756 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5760 if (strcmp(tokens[5], "read") != 0) {
5761 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5765 if (strcmp(tokens[6], "ttl") != 0) {
5766 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ttl");
5774 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5782 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5783 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5787 n_tokens_parsed = parse_match(tokens,
5792 if (n_tokens_parsed == 0)
5794 n_tokens -= n_tokens_parsed;
5795 tokens += n_tokens_parsed;
5799 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5803 /* Read table rule TTL stats. */
5804 status = pipeline_table_rule_ttl_read(pipeline_name,
5810 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5815 snprintf(out, out_size, "Packets: %" PRIu64 "\n",
5819 static const char cmd_pipeline_table_rule_time_read_help[] =
5820 "pipeline <pipeline_name> table <table_id> rule read time\n"
5824 cmd_pipeline_table_rule_time_read(char **tokens,
5829 struct table_rule_match m;
5830 char *pipeline_name;
5832 uint32_t table_id, n_tokens_parsed;
5836 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5840 pipeline_name = tokens[1];
5842 if (strcmp(tokens[2], "table") != 0) {
5843 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5847 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5848 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5852 if (strcmp(tokens[4], "rule") != 0) {
5853 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5857 if (strcmp(tokens[5], "read") != 0) {
5858 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5862 if (strcmp(tokens[6], "time") != 0) {
5863 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "time");
5871 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5872 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5876 n_tokens_parsed = parse_match(tokens,
5881 if (n_tokens_parsed == 0)
5883 n_tokens -= n_tokens_parsed;
5884 tokens += n_tokens_parsed;
5888 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5892 /* Read table rule timestamp. */
5893 status = pipeline_table_rule_time_read(pipeline_name,
5898 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5903 snprintf(out, out_size, "Packets: %" PRIu64 "\n", timestamp);
5906 static const char cmd_thread_pipeline_enable_help[] =
5907 "thread <thread_id> pipeline <pipeline_name> enable\n";
5910 cmd_thread_pipeline_enable(char **tokens,
5915 char *pipeline_name;
5919 if (n_tokens != 5) {
5920 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5924 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5925 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5929 if (strcmp(tokens[2], "pipeline") != 0) {
5930 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5934 pipeline_name = tokens[3];
5936 if (strcmp(tokens[4], "enable") != 0) {
5937 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5941 status = thread_pipeline_enable(thread_id, pipeline_name);
5943 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5949 static const char cmd_thread_pipeline_disable_help[] =
5950 "thread <thread_id> pipeline <pipeline_name> disable\n";
5953 cmd_thread_pipeline_disable(char **tokens,
5958 char *pipeline_name;
5962 if (n_tokens != 5) {
5963 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5967 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5968 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5972 if (strcmp(tokens[2], "pipeline") != 0) {
5973 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5977 pipeline_name = tokens[3];
5979 if (strcmp(tokens[4], "disable") != 0) {
5980 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
5984 status = thread_pipeline_disable(thread_id, pipeline_name);
5986 snprintf(out, out_size, MSG_CMD_FAIL,
5987 "thread pipeline disable");
5993 cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
5998 if (n_tokens == 0) {
5999 snprintf(out, out_size,
6000 "Type 'help <command>' for details on each command.\n\n"
6001 "List of commands:\n"
6005 "\ttmgr subport profile\n"
6006 "\ttmgr pipe profile\n"
6009 "\ttmgr subport pipe\n"
6012 "\tport in action profile\n"
6013 "\ttable action profile\n"
6015 "\tpipeline port in\n"
6016 "\tpipeline port out\n"
6017 "\tpipeline table\n"
6018 "\tpipeline port in table\n"
6019 "\tpipeline port in stats\n"
6020 "\tpipeline port in enable\n"
6021 "\tpipeline port in disable\n"
6022 "\tpipeline port out stats\n"
6023 "\tpipeline table stats\n"
6024 "\tpipeline table rule add\n"
6025 "\tpipeline table rule add default\n"
6026 "\tpipeline table rule add bulk\n"
6027 "\tpipeline table rule delete\n"
6028 "\tpipeline table rule delete default\n"
6029 "\tpipeline table rule show\n"
6030 "\tpipeline table rule stats read\n"
6031 "\tpipeline table meter profile add\n"
6032 "\tpipeline table meter profile delete\n"
6033 "\tpipeline table rule meter read\n"
6034 "\tpipeline table dscp\n"
6035 "\tpipeline table rule ttl read\n"
6036 "\tpipeline table rule time read\n"
6037 "\tthread pipeline enable\n"
6038 "\tthread pipeline disable\n\n");
6042 if (strcmp(tokens[0], "mempool") == 0) {
6043 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
6047 if (strcmp(tokens[0], "link") == 0) {
6048 snprintf(out, out_size, "\n%s\n", cmd_link_help);
6052 if (strcmp(tokens[0], "swq") == 0) {
6053 snprintf(out, out_size, "\n%s\n", cmd_swq_help);
6057 if (strcmp(tokens[0], "tmgr") == 0) {
6058 if (n_tokens == 1) {
6059 snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
6063 if ((n_tokens == 2) &&
6064 (strcmp(tokens[1], "subport")) == 0) {
6065 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
6069 if ((n_tokens == 3) &&
6070 (strcmp(tokens[1], "subport") == 0) &&
6071 (strcmp(tokens[2], "profile") == 0)) {
6072 snprintf(out, out_size, "\n%s\n",
6073 cmd_tmgr_subport_profile_help);
6077 if ((n_tokens == 3) &&
6078 (strcmp(tokens[1], "subport") == 0) &&
6079 (strcmp(tokens[2], "pipe") == 0)) {
6080 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
6084 if ((n_tokens == 3) &&
6085 (strcmp(tokens[1], "pipe") == 0) &&
6086 (strcmp(tokens[2], "profile") == 0)) {
6087 snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
6092 if (strcmp(tokens[0], "tap") == 0) {
6093 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
6097 if (strcmp(tokens[0], "kni") == 0) {
6098 snprintf(out, out_size, "\n%s\n", cmd_kni_help);
6102 if (strcmp(tokens[0], "cryptodev") == 0) {
6103 snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
6107 if ((n_tokens == 4) &&
6108 (strcmp(tokens[0], "port") == 0) &&
6109 (strcmp(tokens[1], "in") == 0) &&
6110 (strcmp(tokens[2], "action") == 0) &&
6111 (strcmp(tokens[3], "profile") == 0)) {
6112 snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
6116 if ((n_tokens == 3) &&
6117 (strcmp(tokens[0], "table") == 0) &&
6118 (strcmp(tokens[1], "action") == 0) &&
6119 (strcmp(tokens[2], "profile") == 0)) {
6120 snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
6124 if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
6125 snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
6129 if ((strcmp(tokens[0], "pipeline") == 0) &&
6130 (strcmp(tokens[1], "port") == 0)) {
6131 if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
6132 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
6136 if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
6137 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
6141 if ((n_tokens == 4) &&
6142 (strcmp(tokens[2], "in") == 0) &&
6143 (strcmp(tokens[3], "table") == 0)) {
6144 snprintf(out, out_size, "\n%s\n",
6145 cmd_pipeline_port_in_table_help);
6149 if ((n_tokens == 4) &&
6150 (strcmp(tokens[2], "in") == 0) &&
6151 (strcmp(tokens[3], "stats") == 0)) {
6152 snprintf(out, out_size, "\n%s\n",
6153 cmd_pipeline_port_in_stats_help);
6157 if ((n_tokens == 4) &&
6158 (strcmp(tokens[2], "in") == 0) &&
6159 (strcmp(tokens[3], "enable") == 0)) {
6160 snprintf(out, out_size, "\n%s\n",
6161 cmd_pipeline_port_in_enable_help);
6165 if ((n_tokens == 4) &&
6166 (strcmp(tokens[2], "in") == 0) &&
6167 (strcmp(tokens[3], "disable") == 0)) {
6168 snprintf(out, out_size, "\n%s\n",
6169 cmd_pipeline_port_in_disable_help);
6173 if ((n_tokens == 4) &&
6174 (strcmp(tokens[2], "out") == 0) &&
6175 (strcmp(tokens[3], "stats") == 0)) {
6176 snprintf(out, out_size, "\n%s\n",
6177 cmd_pipeline_port_out_stats_help);
6182 if ((strcmp(tokens[0], "pipeline") == 0) &&
6183 (strcmp(tokens[1], "table") == 0)) {
6184 if (n_tokens == 2) {
6185 snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
6189 if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
6190 snprintf(out, out_size, "\n%s\n",
6191 cmd_pipeline_table_stats_help);
6195 if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
6196 snprintf(out, out_size, "\n%s\n",
6197 cmd_pipeline_table_dscp_help);
6201 if ((n_tokens == 4) &&
6202 (strcmp(tokens[2], "rule") == 0) &&
6203 (strcmp(tokens[3], "add") == 0)) {
6204 snprintf(out, out_size, "\n%s\n",
6205 cmd_pipeline_table_rule_add_help);
6209 if ((n_tokens == 5) &&
6210 (strcmp(tokens[2], "rule") == 0) &&
6211 (strcmp(tokens[3], "add") == 0) &&
6212 (strcmp(tokens[4], "default") == 0)) {
6213 snprintf(out, out_size, "\n%s\n",
6214 cmd_pipeline_table_rule_add_default_help);
6218 if ((n_tokens == 5) &&
6219 (strcmp(tokens[2], "rule") == 0) &&
6220 (strcmp(tokens[3], "add") == 0) &&
6221 (strcmp(tokens[4], "bulk") == 0)) {
6222 snprintf(out, out_size, "\n%s\n",
6223 cmd_pipeline_table_rule_add_bulk_help);
6227 if ((n_tokens == 4) &&
6228 (strcmp(tokens[2], "rule") == 0) &&
6229 (strcmp(tokens[3], "delete") == 0)) {
6230 snprintf(out, out_size, "\n%s\n",
6231 cmd_pipeline_table_rule_delete_help);
6235 if ((n_tokens == 5) &&
6236 (strcmp(tokens[2], "rule") == 0) &&
6237 (strcmp(tokens[3], "delete") == 0) &&
6238 (strcmp(tokens[4], "default") == 0)) {
6239 snprintf(out, out_size, "\n%s\n",
6240 cmd_pipeline_table_rule_delete_default_help);
6244 if ((n_tokens == 4) &&
6245 (strcmp(tokens[2], "rule") == 0) &&
6246 (strcmp(tokens[3], "show") == 0)) {
6247 snprintf(out, out_size, "\n%s\n",
6248 cmd_pipeline_table_rule_show_help);
6252 if ((n_tokens == 5) &&
6253 (strcmp(tokens[2], "rule") == 0) &&
6254 (strcmp(tokens[3], "stats") == 0) &&
6255 (strcmp(tokens[4], "read") == 0)) {
6256 snprintf(out, out_size, "\n%s\n",
6257 cmd_pipeline_table_rule_stats_read_help);
6261 if ((n_tokens == 5) &&
6262 (strcmp(tokens[2], "meter") == 0) &&
6263 (strcmp(tokens[3], "profile") == 0) &&
6264 (strcmp(tokens[4], "add") == 0)) {
6265 snprintf(out, out_size, "\n%s\n",
6266 cmd_pipeline_table_meter_profile_add_help);
6270 if ((n_tokens == 5) &&
6271 (strcmp(tokens[2], "meter") == 0) &&
6272 (strcmp(tokens[3], "profile") == 0) &&
6273 (strcmp(tokens[4], "delete") == 0)) {
6274 snprintf(out, out_size, "\n%s\n",
6275 cmd_pipeline_table_meter_profile_delete_help);
6279 if ((n_tokens == 5) &&
6280 (strcmp(tokens[2], "rule") == 0) &&
6281 (strcmp(tokens[3], "meter") == 0) &&
6282 (strcmp(tokens[4], "read") == 0)) {
6283 snprintf(out, out_size, "\n%s\n",
6284 cmd_pipeline_table_rule_meter_read_help);
6288 if ((n_tokens == 5) &&
6289 (strcmp(tokens[2], "rule") == 0) &&
6290 (strcmp(tokens[3], "ttl") == 0) &&
6291 (strcmp(tokens[4], "read") == 0)) {
6292 snprintf(out, out_size, "\n%s\n",
6293 cmd_pipeline_table_rule_ttl_read_help);
6297 if ((n_tokens == 5) &&
6298 (strcmp(tokens[2], "rule") == 0) &&
6299 (strcmp(tokens[3], "time") == 0) &&
6300 (strcmp(tokens[4], "read") == 0)) {
6301 snprintf(out, out_size, "\n%s\n",
6302 cmd_pipeline_table_rule_time_read_help);
6307 if ((n_tokens == 3) &&
6308 (strcmp(tokens[0], "thread") == 0) &&
6309 (strcmp(tokens[1], "pipeline") == 0)) {
6310 if (strcmp(tokens[2], "enable") == 0) {
6311 snprintf(out, out_size, "\n%s\n",
6312 cmd_thread_pipeline_enable_help);
6316 if (strcmp(tokens[2], "disable") == 0) {
6317 snprintf(out, out_size, "\n%s\n",
6318 cmd_thread_pipeline_disable_help);
6323 snprintf(out, out_size, "Invalid command\n");
6327 cli_process(char *in, char *out, size_t out_size)
6329 char *tokens[CMD_MAX_TOKENS];
6330 uint32_t n_tokens = RTE_DIM(tokens);
6336 status = parse_tokenize_string(in, tokens, &n_tokens);
6338 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
6345 if (strcmp(tokens[0], "help") == 0) {
6346 cmd_help(tokens, n_tokens, out, out_size);
6350 if (strcmp(tokens[0], "mempool") == 0) {
6351 cmd_mempool(tokens, n_tokens, out, out_size);
6355 if (strcmp(tokens[0], "link") == 0) {
6356 if (strcmp(tokens[1], "show") == 0) {
6357 cmd_link_show(tokens, n_tokens, out, out_size);
6361 cmd_link(tokens, n_tokens, out, out_size);
6365 if (strcmp(tokens[0], "swq") == 0) {
6366 cmd_swq(tokens, n_tokens, out, out_size);
6370 if (strcmp(tokens[0], "tmgr") == 0) {
6371 if ((n_tokens >= 3) &&
6372 (strcmp(tokens[1], "subport") == 0) &&
6373 (strcmp(tokens[2], "profile") == 0)) {
6374 cmd_tmgr_subport_profile(tokens, n_tokens,
6379 if ((n_tokens >= 3) &&
6380 (strcmp(tokens[1], "pipe") == 0) &&
6381 (strcmp(tokens[2], "profile") == 0)) {
6382 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
6386 if ((n_tokens >= 5) &&
6387 (strcmp(tokens[2], "subport") == 0) &&
6388 (strcmp(tokens[4], "profile") == 0)) {
6389 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
6393 if ((n_tokens >= 5) &&
6394 (strcmp(tokens[2], "subport") == 0) &&
6395 (strcmp(tokens[4], "pipe") == 0)) {
6396 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
6400 cmd_tmgr(tokens, n_tokens, out, out_size);
6404 if (strcmp(tokens[0], "tap") == 0) {
6405 cmd_tap(tokens, n_tokens, out, out_size);
6409 if (strcmp(tokens[0], "kni") == 0) {
6410 cmd_kni(tokens, n_tokens, out, out_size);
6414 if (strcmp(tokens[0], "cryptodev") == 0) {
6415 cmd_cryptodev(tokens, n_tokens, out, out_size);
6419 if (strcmp(tokens[0], "port") == 0) {
6420 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
6424 if (strcmp(tokens[0], "table") == 0) {
6425 cmd_table_action_profile(tokens, n_tokens, out, out_size);
6429 if (strcmp(tokens[0], "pipeline") == 0) {
6430 if ((n_tokens >= 3) &&
6431 (strcmp(tokens[2], "period") == 0)) {
6432 cmd_pipeline(tokens, n_tokens, out, out_size);
6436 if ((n_tokens >= 5) &&
6437 (strcmp(tokens[2], "port") == 0) &&
6438 (strcmp(tokens[3], "in") == 0) &&
6439 (strcmp(tokens[4], "bsz") == 0)) {
6440 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
6444 if ((n_tokens >= 5) &&
6445 (strcmp(tokens[2], "port") == 0) &&
6446 (strcmp(tokens[3], "out") == 0) &&
6447 (strcmp(tokens[4], "bsz") == 0)) {
6448 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
6452 if ((n_tokens >= 4) &&
6453 (strcmp(tokens[2], "table") == 0) &&
6454 (strcmp(tokens[3], "match") == 0)) {
6455 cmd_pipeline_table(tokens, n_tokens, out, out_size);
6459 if ((n_tokens >= 6) &&
6460 (strcmp(tokens[2], "port") == 0) &&
6461 (strcmp(tokens[3], "in") == 0) &&
6462 (strcmp(tokens[5], "table") == 0)) {
6463 cmd_pipeline_port_in_table(tokens, n_tokens,
6468 if ((n_tokens >= 6) &&
6469 (strcmp(tokens[2], "port") == 0) &&
6470 (strcmp(tokens[3], "in") == 0) &&
6471 (strcmp(tokens[5], "stats") == 0)) {
6472 cmd_pipeline_port_in_stats(tokens, n_tokens,
6477 if ((n_tokens >= 6) &&
6478 (strcmp(tokens[2], "port") == 0) &&
6479 (strcmp(tokens[3], "in") == 0) &&
6480 (strcmp(tokens[5], "enable") == 0)) {
6481 cmd_pipeline_port_in_enable(tokens, n_tokens,
6486 if ((n_tokens >= 6) &&
6487 (strcmp(tokens[2], "port") == 0) &&
6488 (strcmp(tokens[3], "in") == 0) &&
6489 (strcmp(tokens[5], "disable") == 0)) {
6490 cmd_pipeline_port_in_disable(tokens, n_tokens,
6495 if ((n_tokens >= 6) &&
6496 (strcmp(tokens[2], "port") == 0) &&
6497 (strcmp(tokens[3], "out") == 0) &&
6498 (strcmp(tokens[5], "stats") == 0)) {
6499 cmd_pipeline_port_out_stats(tokens, n_tokens,
6504 if ((n_tokens >= 5) &&
6505 (strcmp(tokens[2], "table") == 0) &&
6506 (strcmp(tokens[4], "stats") == 0)) {
6507 cmd_pipeline_table_stats(tokens, n_tokens,
6512 if ((n_tokens >= 7) &&
6513 (strcmp(tokens[2], "table") == 0) &&
6514 (strcmp(tokens[4], "rule") == 0) &&
6515 (strcmp(tokens[5], "add") == 0) &&
6516 (strcmp(tokens[6], "match") == 0)) {
6517 if ((n_tokens >= 8) &&
6518 (strcmp(tokens[7], "default") == 0)) {
6519 cmd_pipeline_table_rule_add_default(tokens,
6520 n_tokens, out, out_size);
6524 cmd_pipeline_table_rule_add(tokens, n_tokens,
6529 if ((n_tokens >= 7) &&
6530 (strcmp(tokens[2], "table") == 0) &&
6531 (strcmp(tokens[4], "rule") == 0) &&
6532 (strcmp(tokens[5], "add") == 0) &&
6533 (strcmp(tokens[6], "bulk") == 0)) {
6534 cmd_pipeline_table_rule_add_bulk(tokens,
6535 n_tokens, out, out_size);
6539 if ((n_tokens >= 7) &&
6540 (strcmp(tokens[2], "table") == 0) &&
6541 (strcmp(tokens[4], "rule") == 0) &&
6542 (strcmp(tokens[5], "delete") == 0) &&
6543 (strcmp(tokens[6], "match") == 0)) {
6544 if ((n_tokens >= 8) &&
6545 (strcmp(tokens[7], "default") == 0)) {
6546 cmd_pipeline_table_rule_delete_default(tokens,
6547 n_tokens, out, out_size);
6551 cmd_pipeline_table_rule_delete(tokens, n_tokens,
6556 if ((n_tokens >= 6) &&
6557 (strcmp(tokens[2], "table") == 0) &&
6558 (strcmp(tokens[4], "rule") == 0) &&
6559 (strcmp(tokens[5], "show") == 0)) {
6560 cmd_pipeline_table_rule_show(tokens, n_tokens,
6565 if ((n_tokens >= 7) &&
6566 (strcmp(tokens[2], "table") == 0) &&
6567 (strcmp(tokens[4], "rule") == 0) &&
6568 (strcmp(tokens[5], "read") == 0) &&
6569 (strcmp(tokens[6], "stats") == 0)) {
6570 cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
6575 if ((n_tokens >= 8) &&
6576 (strcmp(tokens[2], "table") == 0) &&
6577 (strcmp(tokens[4], "meter") == 0) &&
6578 (strcmp(tokens[5], "profile") == 0) &&
6579 (strcmp(tokens[7], "add") == 0)) {
6580 cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
6585 if ((n_tokens >= 8) &&
6586 (strcmp(tokens[2], "table") == 0) &&
6587 (strcmp(tokens[4], "meter") == 0) &&
6588 (strcmp(tokens[5], "profile") == 0) &&
6589 (strcmp(tokens[7], "delete") == 0)) {
6590 cmd_pipeline_table_meter_profile_delete(tokens,
6591 n_tokens, out, out_size);
6595 if ((n_tokens >= 7) &&
6596 (strcmp(tokens[2], "table") == 0) &&
6597 (strcmp(tokens[4], "rule") == 0) &&
6598 (strcmp(tokens[5], "read") == 0) &&
6599 (strcmp(tokens[6], "meter") == 0)) {
6600 cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
6605 if ((n_tokens >= 5) &&
6606 (strcmp(tokens[2], "table") == 0) &&
6607 (strcmp(tokens[4], "dscp") == 0)) {
6608 cmd_pipeline_table_dscp(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], "ttl") == 0)) {
6618 cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
6623 if ((n_tokens >= 7) &&
6624 (strcmp(tokens[2], "table") == 0) &&
6625 (strcmp(tokens[4], "rule") == 0) &&
6626 (strcmp(tokens[5], "read") == 0) &&
6627 (strcmp(tokens[6], "time") == 0)) {
6628 cmd_pipeline_table_rule_time_read(tokens, n_tokens,
6634 if (strcmp(tokens[0], "thread") == 0) {
6635 if ((n_tokens >= 5) &&
6636 (strcmp(tokens[4], "enable") == 0)) {
6637 cmd_thread_pipeline_enable(tokens, n_tokens,
6642 if ((n_tokens >= 5) &&
6643 (strcmp(tokens[4], "disable") == 0)) {
6644 cmd_thread_pipeline_disable(tokens, n_tokens,
6650 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
6654 cli_script_process(const char *file_name,
6655 size_t msg_in_len_max,
6656 size_t msg_out_len_max)
6658 char *msg_in = NULL, *msg_out = NULL;
6661 /* Check input arguments */
6662 if ((file_name == NULL) ||
6663 (strlen(file_name) == 0) ||
6664 (msg_in_len_max == 0) ||
6665 (msg_out_len_max == 0))
6668 msg_in = malloc(msg_in_len_max + 1);
6669 msg_out = malloc(msg_out_len_max + 1);
6670 if ((msg_in == NULL) ||
6671 (msg_out == NULL)) {
6677 /* Open input file */
6678 f = fopen(file_name, "r");
6687 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6690 printf("%s", msg_in);
6697 if (strlen(msg_out))
6698 printf("%s", msg_out);
6709 cli_rule_file_process(const char *file_name,
6710 size_t line_len_max,
6711 struct table_rule_list **rule_list,
6713 uint32_t *line_number,
6717 struct table_rule_list *list = NULL;
6720 uint32_t rule_id = 0, line_id = 0;
6723 /* Check input arguments */
6724 if ((file_name == NULL) ||
6725 (strlen(file_name) == 0) ||
6726 (line_len_max == 0) ||
6727 (rule_list == NULL) ||
6728 (n_rules == NULL) ||
6729 (line_number == NULL) ||
6732 goto cli_rule_file_process_free;
6735 /* Memory allocation */
6736 list = malloc(sizeof(struct table_rule_list));
6739 goto cli_rule_file_process_free;
6744 line = malloc(line_len_max + 1);
6747 goto cli_rule_file_process_free;
6751 f = fopen(file_name, "r");
6754 goto cli_rule_file_process_free;
6758 for (line_id = 1, rule_id = 0; ; line_id++) {
6759 char *tokens[CMD_MAX_TOKENS];
6760 struct table_rule *rule = NULL;
6761 uint32_t n_tokens, n_tokens_parsed, t0;
6763 /* Read next line from file. */
6764 if (fgets(line, line_len_max + 1, f) == NULL)
6768 if (is_comment(line))
6772 n_tokens = RTE_DIM(tokens);
6773 status = parse_tokenize_string(line, tokens, &n_tokens);
6776 goto cli_rule_file_process_free;
6784 /* Rule alloc and insert. */
6785 rule = calloc(1, sizeof(struct table_rule));
6788 goto cli_rule_file_process_free;
6791 TAILQ_INSERT_TAIL(list, rule, node);
6794 n_tokens_parsed = parse_match(tokens + t0,
6799 if (n_tokens_parsed == 0) {
6801 goto cli_rule_file_process_free;
6803 t0 += n_tokens_parsed;
6806 n_tokens_parsed = parse_table_action(tokens + t0,
6811 if (n_tokens_parsed == 0) {
6813 goto cli_rule_file_process_free;
6815 t0 += n_tokens_parsed;
6817 /* Line completed. */
6818 if (t0 < n_tokens) {
6820 goto cli_rule_file_process_free;
6823 /* Increment rule count */
6835 *line_number = line_id;
6838 cli_rule_file_process_free:
6839 if (rule_list != NULL)
6842 if (n_rules != NULL)
6845 if (line_number != NULL)
6846 *line_number = line_id;
6850 struct table_rule *rule;
6852 rule = TAILQ_FIRST(list);
6856 TAILQ_REMOVE(list, rule, node);