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";
796 cmd_cryptodev(char **tokens,
801 struct cryptodev_params params;
804 memset(¶ms, 0, sizeof(params));
806 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
812 if (strcmp(tokens[2], "dev") == 0)
813 params.dev_name = tokens[3];
814 else if (strcmp(tokens[2], "dev_id") == 0) {
815 if (parser_read_uint32(¶ms.dev_id, tokens[3]) < 0) {
816 snprintf(out, out_size, MSG_ARG_INVALID,
821 snprintf(out, out_size, MSG_ARG_INVALID,
826 if (strcmp(tokens[4], "queue")) {
827 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
832 if (parser_read_uint32(¶ms.n_queues, tokens[5]) < 0) {
833 snprintf(out, out_size, MSG_ARG_INVALID,
838 if (parser_read_uint32(¶ms.queue_size, tokens[6]) < 0) {
839 snprintf(out, out_size, MSG_ARG_INVALID,
844 if (cryptodev_create(name, ¶ms) == NULL) {
845 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
850 static const char cmd_port_in_action_profile_help[] =
851 "port in action profile <profile_name>\n"
852 " [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]\n"
853 " [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]\n";
856 cmd_port_in_action_profile(char **tokens,
861 struct port_in_action_profile_params p;
862 struct port_in_action_profile *ap;
866 memset(&p, 0, sizeof(p));
869 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
873 if (strcmp(tokens[1], "in") != 0) {
874 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
878 if (strcmp(tokens[2], "action") != 0) {
879 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
883 if (strcmp(tokens[3], "profile") != 0) {
884 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
892 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
895 if (n_tokens < t0 + 10) {
896 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
900 if (strcmp(tokens[t0 + 1], "match") == 0)
901 p.fltr.filter_on_match = 1;
902 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
903 p.fltr.filter_on_match = 0;
905 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
909 if (strcmp(tokens[t0 + 2], "offset") != 0) {
910 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
914 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
915 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
919 if (strcmp(tokens[t0 + 4], "mask") != 0) {
920 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
924 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
925 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
926 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
927 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
931 if (strcmp(tokens[t0 + 6], "key") != 0) {
932 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
936 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
937 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
938 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
939 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
943 if (strcmp(tokens[t0 + 8], "port") != 0) {
944 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
948 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
949 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
953 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
957 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
960 if (n_tokens < t0 + 22) {
961 snprintf(out, out_size, MSG_ARG_MISMATCH,
962 "port in action profile balance");
966 if (strcmp(tokens[t0 + 1], "offset") != 0) {
967 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
971 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
972 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
976 if (strcmp(tokens[t0 + 3], "mask") != 0) {
977 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
981 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
982 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
983 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
987 if (strcmp(tokens[t0 + 5], "port") != 0) {
988 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
992 for (i = 0; i < 16; i++)
993 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
994 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
998 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
1002 if (t0 < n_tokens) {
1003 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1007 ap = port_in_action_profile_create(name, &p);
1009 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1015 static const char cmd_table_action_profile_help[] =
1016 "table action profile <profile_name>\n"
1018 " offset <ip_offset>\n"
1020 " [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]\n"
1021 " [meter srtcm | trtcm\n"
1023 " stats none | pkts | bytes | both]\n"
1024 " [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]\n"
1025 " [encap ether | vlan | qinq | mpls | pppoe |\n"
1026 " vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]\n"
1028 " proto udp | tcp]\n"
1029 " [ttl drop | fwd\n"
1030 " stats none | pkts]\n"
1031 " [stats pkts | bytes | both]\n"
1033 " [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset> "
1034 " mempool_create <mempool_name>\n"
1035 " mempool_init <mempool_name>]\n";
1038 cmd_table_action_profile(char **tokens,
1043 struct table_action_profile_params p;
1044 struct table_action_profile *ap;
1048 memset(&p, 0, sizeof(p));
1051 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1055 if (strcmp(tokens[1], "action") != 0) {
1056 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1060 if (strcmp(tokens[2], "profile") != 0) {
1061 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1067 if (strcmp(tokens[4], "ipv4") == 0)
1068 p.common.ip_version = 1;
1069 else if (strcmp(tokens[4], "ipv6") == 0)
1070 p.common.ip_version = 0;
1072 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1076 if (strcmp(tokens[5], "offset") != 0) {
1077 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1081 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
1082 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1086 if (strcmp(tokens[7], "fwd") != 0) {
1087 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1091 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1094 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
1095 if (n_tokens < t0 + 7) {
1096 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1100 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1101 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1105 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1106 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1110 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1111 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1115 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1116 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1117 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1121 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1122 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1126 if (parser_read_uint32(&p.lb.out_offset, tokens[t0 + 6]) != 0) {
1127 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1131 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1135 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
1136 if (n_tokens < t0 + 6) {
1137 snprintf(out, out_size, MSG_ARG_MISMATCH,
1138 "table action profile meter");
1142 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
1143 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1144 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
1145 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1147 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1152 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1153 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1157 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
1158 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1162 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1163 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1167 if (strcmp(tokens[t0 + 5], "none") == 0) {
1168 p.mtr.n_packets_enabled = 0;
1169 p.mtr.n_bytes_enabled = 0;
1170 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1171 p.mtr.n_packets_enabled = 1;
1172 p.mtr.n_bytes_enabled = 0;
1173 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1174 p.mtr.n_packets_enabled = 0;
1175 p.mtr.n_bytes_enabled = 1;
1176 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1177 p.mtr.n_packets_enabled = 1;
1178 p.mtr.n_bytes_enabled = 1;
1180 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1181 "none or pkts or bytes or both");
1185 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1189 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
1190 if (n_tokens < t0 + 5) {
1191 snprintf(out, out_size, MSG_ARG_MISMATCH,
1192 "table action profile tm");
1196 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1197 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1201 if (parser_read_uint32(&p.tm.n_subports_per_port,
1202 tokens[t0 + 2]) != 0) {
1203 snprintf(out, out_size, MSG_ARG_INVALID,
1204 "n_subports_per_port");
1208 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1209 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1213 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1214 tokens[t0 + 4]) != 0) {
1215 snprintf(out, out_size, MSG_ARG_INVALID,
1216 "n_pipes_per_subport");
1220 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1224 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1225 uint32_t n_extra_tokens = 0;
1227 if (n_tokens < t0 + 2) {
1228 snprintf(out, out_size, MSG_ARG_MISMATCH,
1229 "action profile encap");
1233 if (strcmp(tokens[t0 + 1], "ether") == 0)
1234 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1235 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1236 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1237 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1238 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1239 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1240 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1241 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1242 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1243 else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1244 if (n_tokens < t0 + 2 + 5) {
1245 snprintf(out, out_size, MSG_ARG_MISMATCH,
1246 "action profile encap vxlan");
1250 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1251 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1256 if (parser_read_uint32(&p.encap.vxlan.data_offset,
1257 tokens[t0 + 2 + 1]) != 0) {
1258 snprintf(out, out_size, MSG_ARG_INVALID,
1259 "vxlan: ether_offset");
1263 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1264 p.encap.vxlan.ip_version = 1;
1265 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1266 p.encap.vxlan.ip_version = 0;
1268 snprintf(out, out_size, MSG_ARG_INVALID,
1269 "vxlan: ipv4 or ipv6");
1273 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1274 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1279 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
1280 p.encap.vxlan.vlan = 1;
1281 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
1282 p.encap.vxlan.vlan = 0;
1284 snprintf(out, out_size, MSG_ARG_INVALID,
1285 "vxlan: on or off");
1289 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
1292 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1296 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1297 t0 += 2 + n_extra_tokens;
1300 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1301 if (n_tokens < t0 + 4) {
1302 snprintf(out, out_size, MSG_ARG_MISMATCH,
1303 "table action profile nat");
1307 if (strcmp(tokens[t0 + 1], "src") == 0)
1308 p.nat.source_nat = 1;
1309 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1310 p.nat.source_nat = 0;
1312 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1317 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1318 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1322 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1324 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1327 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1332 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1336 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1337 if (n_tokens < t0 + 4) {
1338 snprintf(out, out_size, MSG_ARG_MISMATCH,
1339 "table action profile ttl");
1343 if (strcmp(tokens[t0 + 1], "drop") == 0)
1345 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1348 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1353 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1354 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1358 if (strcmp(tokens[t0 + 3], "none") == 0)
1359 p.ttl.n_packets_enabled = 0;
1360 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1361 p.ttl.n_packets_enabled = 1;
1363 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1368 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1372 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1373 if (n_tokens < t0 + 2) {
1374 snprintf(out, out_size, MSG_ARG_MISMATCH,
1375 "table action profile stats");
1379 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1380 p.stats.n_packets_enabled = 1;
1381 p.stats.n_bytes_enabled = 0;
1382 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1383 p.stats.n_packets_enabled = 0;
1384 p.stats.n_bytes_enabled = 1;
1385 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1386 p.stats.n_packets_enabled = 1;
1387 p.stats.n_bytes_enabled = 1;
1389 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1390 "pkts or bytes or both");
1394 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1398 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1399 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1403 if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
1404 struct cryptodev *cryptodev;
1405 struct mempool *mempool;
1407 if (n_tokens < t0 + 9 ||
1408 strcmp(tokens[t0 + 1], "dev") ||
1409 strcmp(tokens[t0 + 3], "offset") ||
1410 strcmp(tokens[t0 + 5], "mempool_create") ||
1411 strcmp(tokens[t0 + 7], "mempool_init")) {
1412 snprintf(out, out_size, MSG_ARG_MISMATCH,
1413 "table action profile sym_crypto");
1417 cryptodev = cryptodev_find(tokens[t0 + 2]);
1418 if (cryptodev == NULL) {
1419 snprintf(out, out_size, MSG_ARG_INVALID,
1420 "table action profile sym_crypto");
1424 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
1426 if (parser_read_uint32(&p.sym_crypto.op_offset,
1427 tokens[t0 + 4]) != 0) {
1428 snprintf(out, out_size, MSG_ARG_INVALID,
1429 "table action profile sym_crypto");
1433 mempool = mempool_find(tokens[t0 + 6]);
1434 if (mempool == NULL) {
1435 snprintf(out, out_size, MSG_ARG_INVALID,
1436 "table action profile sym_crypto");
1439 p.sym_crypto.mp_create = mempool->m;
1441 mempool = mempool_find(tokens[t0 + 8]);
1442 if (mempool == NULL) {
1443 snprintf(out, out_size, MSG_ARG_INVALID,
1444 "table action profile sym_crypto");
1447 p.sym_crypto.mp_init = mempool->m;
1449 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
1454 if (t0 < n_tokens) {
1455 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1459 ap = table_action_profile_create(name, &p);
1461 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1466 static const char cmd_pipeline_help[] =
1467 "pipeline <pipeline_name>\n"
1468 " period <timer_period_ms>\n"
1469 " offset_port_id <offset_port_id>\n"
1473 cmd_pipeline(char **tokens,
1478 struct pipeline_params p;
1480 struct pipeline *pipeline;
1482 if (n_tokens != 8) {
1483 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1489 if (strcmp(tokens[2], "period") != 0) {
1490 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1494 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1495 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1499 if (strcmp(tokens[4], "offset_port_id") != 0) {
1500 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1504 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1505 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1509 if (strcmp(tokens[6], "cpu") != 0) {
1510 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1514 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1515 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1519 pipeline = pipeline_create(name, &p);
1520 if (pipeline == NULL) {
1521 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1526 static const char cmd_pipeline_port_in_help[] =
1527 "pipeline <pipeline_name> port in\n"
1528 " bsz <burst_size>\n"
1529 " link <link_name> rxq <queue_id>\n"
1530 " | swq <swq_name>\n"
1531 " | tmgr <tmgr_name>\n"
1532 " | tap <tap_name> mempool <mempool_name> mtu <mtu>\n"
1533 " | kni <kni_name>\n"
1534 " | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>\n"
1535 " | cryptodev <cryptodev_name> rxq <queue_id>\n"
1536 " [action <port_in_action_profile_name>]\n"
1540 cmd_pipeline_port_in(char **tokens,
1545 struct port_in_params p;
1546 char *pipeline_name;
1548 int enabled, status;
1551 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1555 pipeline_name = tokens[1];
1557 if (strcmp(tokens[2], "port") != 0) {
1558 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1562 if (strcmp(tokens[3], "in") != 0) {
1563 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1567 if (strcmp(tokens[4], "bsz") != 0) {
1568 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1572 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1573 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1579 if (strcmp(tokens[t0], "link") == 0) {
1580 if (n_tokens < t0 + 4) {
1581 snprintf(out, out_size, MSG_ARG_MISMATCH,
1582 "pipeline port in link");
1586 p.type = PORT_IN_RXQ;
1588 p.dev_name = tokens[t0 + 1];
1590 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1591 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1595 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1596 snprintf(out, out_size, MSG_ARG_INVALID,
1601 } else if (strcmp(tokens[t0], "swq") == 0) {
1602 if (n_tokens < t0 + 2) {
1603 snprintf(out, out_size, MSG_ARG_MISMATCH,
1604 "pipeline port in swq");
1608 p.type = PORT_IN_SWQ;
1610 p.dev_name = tokens[t0 + 1];
1613 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1614 if (n_tokens < t0 + 2) {
1615 snprintf(out, out_size, MSG_ARG_MISMATCH,
1616 "pipeline port in tmgr");
1620 p.type = PORT_IN_TMGR;
1622 p.dev_name = tokens[t0 + 1];
1625 } else if (strcmp(tokens[t0], "tap") == 0) {
1626 if (n_tokens < t0 + 6) {
1627 snprintf(out, out_size, MSG_ARG_MISMATCH,
1628 "pipeline port in tap");
1632 p.type = PORT_IN_TAP;
1634 p.dev_name = tokens[t0 + 1];
1636 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1637 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1642 p.tap.mempool_name = tokens[t0 + 3];
1644 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1645 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1650 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1651 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1656 } else if (strcmp(tokens[t0], "kni") == 0) {
1657 if (n_tokens < t0 + 2) {
1658 snprintf(out, out_size, MSG_ARG_MISMATCH,
1659 "pipeline port in kni");
1663 p.type = PORT_IN_KNI;
1665 p.dev_name = tokens[t0 + 1];
1668 } else if (strcmp(tokens[t0], "source") == 0) {
1669 if (n_tokens < t0 + 6) {
1670 snprintf(out, out_size, MSG_ARG_MISMATCH,
1671 "pipeline port in source");
1675 p.type = PORT_IN_SOURCE;
1679 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1680 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1685 p.source.mempool_name = tokens[t0 + 2];
1687 if (strcmp(tokens[t0 + 3], "file") != 0) {
1688 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1693 p.source.file_name = tokens[t0 + 4];
1695 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1696 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1701 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1702 snprintf(out, out_size, MSG_ARG_INVALID,
1708 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
1709 if (n_tokens < t0 + 3) {
1710 snprintf(out, out_size, MSG_ARG_MISMATCH,
1711 "pipeline port in cryptodev");
1715 p.type = PORT_IN_CRYPTODEV;
1717 p.dev_name = tokens[t0 + 1];
1718 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1719 snprintf(out, out_size, MSG_ARG_INVALID,
1724 p.cryptodev.arg_callback = NULL;
1725 p.cryptodev.f_callback = NULL;
1729 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1733 p.action_profile_name = NULL;
1734 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1735 if (n_tokens < t0 + 2) {
1736 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1740 p.action_profile_name = tokens[t0 + 1];
1746 if ((n_tokens > t0) &&
1747 (strcmp(tokens[t0], "disabled") == 0)) {
1753 if (n_tokens != t0) {
1754 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1758 status = pipeline_port_in_create(pipeline_name,
1761 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1766 static const char cmd_pipeline_port_out_help[] =
1767 "pipeline <pipeline_name> port out\n"
1768 " bsz <burst_size>\n"
1769 " link <link_name> txq <txq_id>\n"
1770 " | swq <swq_name>\n"
1771 " | tmgr <tmgr_name>\n"
1772 " | tap <tap_name>\n"
1773 " | kni <kni_name>\n"
1774 " | sink [file <file_name> pkts <max_n_pkts>]\n"
1775 " | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>\n";
1778 cmd_pipeline_port_out(char **tokens,
1783 struct port_out_params p;
1784 char *pipeline_name;
1787 memset(&p, 0, sizeof(p));
1790 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1794 pipeline_name = tokens[1];
1796 if (strcmp(tokens[2], "port") != 0) {
1797 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1801 if (strcmp(tokens[3], "out") != 0) {
1802 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1806 if (strcmp(tokens[4], "bsz") != 0) {
1807 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1811 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1812 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1816 if (strcmp(tokens[6], "link") == 0) {
1817 if (n_tokens != 10) {
1818 snprintf(out, out_size, MSG_ARG_MISMATCH,
1819 "pipeline port out link");
1823 p.type = PORT_OUT_TXQ;
1825 p.dev_name = tokens[7];
1827 if (strcmp(tokens[8], "txq") != 0) {
1828 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1832 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1833 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1836 } else if (strcmp(tokens[6], "swq") == 0) {
1837 if (n_tokens != 8) {
1838 snprintf(out, out_size, MSG_ARG_MISMATCH,
1839 "pipeline port out swq");
1843 p.type = PORT_OUT_SWQ;
1845 p.dev_name = tokens[7];
1846 } else if (strcmp(tokens[6], "tmgr") == 0) {
1847 if (n_tokens != 8) {
1848 snprintf(out, out_size, MSG_ARG_MISMATCH,
1849 "pipeline port out tmgr");
1853 p.type = PORT_OUT_TMGR;
1855 p.dev_name = tokens[7];
1856 } else if (strcmp(tokens[6], "tap") == 0) {
1857 if (n_tokens != 8) {
1858 snprintf(out, out_size, MSG_ARG_MISMATCH,
1859 "pipeline port out tap");
1863 p.type = PORT_OUT_TAP;
1865 p.dev_name = tokens[7];
1866 } else if (strcmp(tokens[6], "kni") == 0) {
1867 if (n_tokens != 8) {
1868 snprintf(out, out_size, MSG_ARG_MISMATCH,
1869 "pipeline port out kni");
1873 p.type = PORT_OUT_KNI;
1875 p.dev_name = tokens[7];
1876 } else if (strcmp(tokens[6], "sink") == 0) {
1877 if ((n_tokens != 7) && (n_tokens != 11)) {
1878 snprintf(out, out_size, MSG_ARG_MISMATCH,
1879 "pipeline port out sink");
1883 p.type = PORT_OUT_SINK;
1887 if (n_tokens == 7) {
1888 p.sink.file_name = NULL;
1889 p.sink.max_n_pkts = 0;
1891 if (strcmp(tokens[7], "file") != 0) {
1892 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1897 p.sink.file_name = tokens[8];
1899 if (strcmp(tokens[9], "pkts") != 0) {
1900 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1904 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1905 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1910 } else if (strcmp(tokens[6], "cryptodev") == 0) {
1911 if (n_tokens != 12) {
1912 snprintf(out, out_size, MSG_ARG_MISMATCH,
1913 "pipeline port out cryptodev");
1917 p.type = PORT_OUT_CRYPTODEV;
1919 p.dev_name = tokens[7];
1921 if (strcmp(tokens[8], "txq")) {
1922 snprintf(out, out_size, MSG_ARG_MISMATCH,
1923 "pipeline port out cryptodev");
1927 if (parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
1929 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1933 if (strcmp(tokens[10], "offset")) {
1934 snprintf(out, out_size, MSG_ARG_MISMATCH,
1935 "pipeline port out cryptodev");
1939 if (parser_read_uint32(&p.cryptodev.op_offset, tokens[11])
1941 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1945 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1949 status = pipeline_port_out_create(pipeline_name, &p);
1951 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1956 static const char cmd_pipeline_table_help[] =
1957 "pipeline <pipeline_name> table\n"
1961 " offset <ip_header_offset>\n"
1964 " offset <key_offset>\n"
1969 " mask <key_mask>\n"
1970 " offset <key_offset>\n"
1971 " buckets <n_buckets>\n"
1975 " offset <ip_header_offset>\n"
1978 " [action <table_action_profile_name>]\n";
1981 cmd_pipeline_table(char **tokens,
1986 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
1987 struct table_params p;
1988 char *pipeline_name;
1993 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1997 pipeline_name = tokens[1];
1999 if (strcmp(tokens[2], "table") != 0) {
2000 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2004 if (strcmp(tokens[3], "match") != 0) {
2005 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2010 if (strcmp(tokens[t0], "acl") == 0) {
2011 if (n_tokens < t0 + 6) {
2012 snprintf(out, out_size, MSG_ARG_MISMATCH,
2013 "pipeline table acl");
2017 p.match_type = TABLE_ACL;
2019 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2020 p.match.acl.ip_version = 1;
2021 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2022 p.match.acl.ip_version = 0;
2024 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2029 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2030 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2034 if (parser_read_uint32(&p.match.acl.ip_header_offset,
2035 tokens[t0 + 3]) != 0) {
2036 snprintf(out, out_size, MSG_ARG_INVALID,
2037 "ip_header_offset");
2041 if (strcmp(tokens[t0 + 4], "size") != 0) {
2042 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2046 if (parser_read_uint32(&p.match.acl.n_rules,
2047 tokens[t0 + 5]) != 0) {
2048 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2053 } else if (strcmp(tokens[t0], "array") == 0) {
2054 if (n_tokens < t0 + 5) {
2055 snprintf(out, out_size, MSG_ARG_MISMATCH,
2056 "pipeline table array");
2060 p.match_type = TABLE_ARRAY;
2062 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2063 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2067 if (parser_read_uint32(&p.match.array.key_offset,
2068 tokens[t0 + 2]) != 0) {
2069 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2073 if (strcmp(tokens[t0 + 3], "size") != 0) {
2074 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2078 if (parser_read_uint32(&p.match.array.n_keys,
2079 tokens[t0 + 4]) != 0) {
2080 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2085 } else if (strcmp(tokens[t0], "hash") == 0) {
2086 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2088 if (n_tokens < t0 + 12) {
2089 snprintf(out, out_size, MSG_ARG_MISMATCH,
2090 "pipeline table hash");
2094 p.match_type = TABLE_HASH;
2096 if (strcmp(tokens[t0 + 1], "ext") == 0)
2097 p.match.hash.extendable_bucket = 1;
2098 else if (strcmp(tokens[t0 + 1], "lru") == 0)
2099 p.match.hash.extendable_bucket = 0;
2101 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2106 if (strcmp(tokens[t0 + 2], "key") != 0) {
2107 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2111 if ((parser_read_uint32(&p.match.hash.key_size,
2112 tokens[t0 + 3]) != 0) ||
2113 (p.match.hash.key_size == 0) ||
2114 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
2115 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2119 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2120 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2124 if ((parse_hex_string(tokens[t0 + 5],
2125 key_mask, &key_mask_size) != 0) ||
2126 (key_mask_size != p.match.hash.key_size)) {
2127 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2130 p.match.hash.key_mask = key_mask;
2132 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2133 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2137 if (parser_read_uint32(&p.match.hash.key_offset,
2138 tokens[t0 + 7]) != 0) {
2139 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2143 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2144 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2148 if (parser_read_uint32(&p.match.hash.n_buckets,
2149 tokens[t0 + 9]) != 0) {
2150 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2154 if (strcmp(tokens[t0 + 10], "size") != 0) {
2155 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2159 if (parser_read_uint32(&p.match.hash.n_keys,
2160 tokens[t0 + 11]) != 0) {
2161 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2166 } else if (strcmp(tokens[t0], "lpm") == 0) {
2167 if (n_tokens < t0 + 6) {
2168 snprintf(out, out_size, MSG_ARG_MISMATCH,
2169 "pipeline table lpm");
2173 p.match_type = TABLE_LPM;
2175 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2176 p.match.lpm.key_size = 4;
2177 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2178 p.match.lpm.key_size = 16;
2180 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2185 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2186 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2190 if (parser_read_uint32(&p.match.lpm.key_offset,
2191 tokens[t0 + 3]) != 0) {
2192 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2196 if (strcmp(tokens[t0 + 4], "size") != 0) {
2197 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2201 if (parser_read_uint32(&p.match.lpm.n_rules,
2202 tokens[t0 + 5]) != 0) {
2203 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2208 } else if (strcmp(tokens[t0], "stub") == 0) {
2209 p.match_type = TABLE_STUB;
2213 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2217 p.action_profile_name = NULL;
2218 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
2219 if (n_tokens < t0 + 2) {
2220 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2224 p.action_profile_name = tokens[t0 + 1];
2229 if (n_tokens > t0) {
2230 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2234 status = pipeline_table_create(pipeline_name, &p);
2236 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2241 static const char cmd_pipeline_port_in_table_help[] =
2242 "pipeline <pipeline_name> port in <port_id> table <table_id>\n";
2245 cmd_pipeline_port_in_table(char **tokens,
2250 char *pipeline_name;
2251 uint32_t port_id, table_id;
2254 if (n_tokens != 7) {
2255 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2259 pipeline_name = tokens[1];
2261 if (strcmp(tokens[2], "port") != 0) {
2262 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2266 if (strcmp(tokens[3], "in") != 0) {
2267 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2271 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2272 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2276 if (strcmp(tokens[5], "table") != 0) {
2277 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2281 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
2282 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2286 status = pipeline_port_in_connect_to_table(pipeline_name,
2290 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2296 static const char cmd_pipeline_port_in_stats_help[] =
2297 "pipeline <pipeline_name> port in <port_id> stats read [clear]\n";
2299 #define MSG_PIPELINE_PORT_IN_STATS \
2300 "Pkts in: %" PRIu64 "\n" \
2301 "Pkts dropped by AH: %" PRIu64 "\n" \
2302 "Pkts dropped by other: %" PRIu64 "\n"
2305 cmd_pipeline_port_in_stats(char **tokens,
2310 struct rte_pipeline_port_in_stats stats;
2311 char *pipeline_name;
2315 if ((n_tokens != 7) && (n_tokens != 8)) {
2316 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2320 pipeline_name = tokens[1];
2322 if (strcmp(tokens[2], "port") != 0) {
2323 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2327 if (strcmp(tokens[3], "in") != 0) {
2328 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2332 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2333 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2337 if (strcmp(tokens[5], "stats") != 0) {
2338 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2342 if (strcmp(tokens[6], "read") != 0) {
2343 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2348 if (n_tokens == 8) {
2349 if (strcmp(tokens[7], "clear") != 0) {
2350 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2357 status = pipeline_port_in_stats_read(pipeline_name,
2362 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2366 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2367 stats.stats.n_pkts_in,
2368 stats.n_pkts_dropped_by_ah,
2369 stats.stats.n_pkts_drop);
2373 static const char cmd_pipeline_port_in_enable_help[] =
2374 "pipeline <pipeline_name> port in <port_id> enable\n";
2377 cmd_pipeline_port_in_enable(char **tokens,
2382 char *pipeline_name;
2386 if (n_tokens != 6) {
2387 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2391 pipeline_name = tokens[1];
2393 if (strcmp(tokens[2], "port") != 0) {
2394 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2398 if (strcmp(tokens[3], "in") != 0) {
2399 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2403 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2404 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2408 if (strcmp(tokens[5], "enable") != 0) {
2409 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2413 status = pipeline_port_in_enable(pipeline_name, port_id);
2415 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2421 static const char cmd_pipeline_port_in_disable_help[] =
2422 "pipeline <pipeline_name> port in <port_id> disable\n";
2425 cmd_pipeline_port_in_disable(char **tokens,
2430 char *pipeline_name;
2434 if (n_tokens != 6) {
2435 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2439 pipeline_name = tokens[1];
2441 if (strcmp(tokens[2], "port") != 0) {
2442 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2446 if (strcmp(tokens[3], "in") != 0) {
2447 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2451 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2452 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2456 if (strcmp(tokens[5], "disable") != 0) {
2457 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2461 status = pipeline_port_in_disable(pipeline_name, port_id);
2463 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2469 static const char cmd_pipeline_port_out_stats_help[] =
2470 "pipeline <pipeline_name> port out <port_id> stats read [clear]\n";
2472 #define MSG_PIPELINE_PORT_OUT_STATS \
2473 "Pkts in: %" PRIu64 "\n" \
2474 "Pkts dropped by AH: %" PRIu64 "\n" \
2475 "Pkts dropped by other: %" PRIu64 "\n"
2478 cmd_pipeline_port_out_stats(char **tokens,
2483 struct rte_pipeline_port_out_stats stats;
2484 char *pipeline_name;
2488 if ((n_tokens != 7) && (n_tokens != 8)) {
2489 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2493 pipeline_name = tokens[1];
2495 if (strcmp(tokens[2], "port") != 0) {
2496 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2500 if (strcmp(tokens[3], "out") != 0) {
2501 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2505 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2506 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2510 if (strcmp(tokens[5], "stats") != 0) {
2511 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2515 if (strcmp(tokens[6], "read") != 0) {
2516 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2521 if (n_tokens == 8) {
2522 if (strcmp(tokens[7], "clear") != 0) {
2523 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2530 status = pipeline_port_out_stats_read(pipeline_name,
2535 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2539 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2540 stats.stats.n_pkts_in,
2541 stats.n_pkts_dropped_by_ah,
2542 stats.stats.n_pkts_drop);
2546 static const char cmd_pipeline_table_stats_help[] =
2547 "pipeline <pipeline_name> table <table_id> stats read [clear]\n";
2549 #define MSG_PIPELINE_TABLE_STATS \
2550 "Pkts in: %" PRIu64 "\n" \
2551 "Pkts in with lookup miss: %" PRIu64 "\n" \
2552 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2553 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2554 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2555 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2558 cmd_pipeline_table_stats(char **tokens,
2563 struct rte_pipeline_table_stats stats;
2564 char *pipeline_name;
2568 if ((n_tokens != 6) && (n_tokens != 7)) {
2569 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2573 pipeline_name = tokens[1];
2575 if (strcmp(tokens[2], "table") != 0) {
2576 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2580 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2581 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2585 if (strcmp(tokens[4], "stats") != 0) {
2586 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2590 if (strcmp(tokens[5], "read") != 0) {
2591 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2596 if (n_tokens == 7) {
2597 if (strcmp(tokens[6], "clear") != 0) {
2598 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2605 status = pipeline_table_stats_read(pipeline_name,
2610 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2614 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2615 stats.stats.n_pkts_in,
2616 stats.stats.n_pkts_lookup_miss,
2617 stats.n_pkts_dropped_by_lkp_hit_ah,
2618 stats.n_pkts_dropped_lkp_hit,
2619 stats.n_pkts_dropped_by_lkp_miss_ah,
2620 stats.n_pkts_dropped_lkp_miss);
2628 * priority <priority>
2629 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2630 * <sp0> <sp1> <dp0> <dp1> <proto>
2634 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2635 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2636 * | ipv4_addr <addr>
2637 * | ipv6_addr <addr>
2638 * | qinq <svlan> <cvlan>
2640 * ipv4 | ipv6 <addr> <depth>
2642 struct pkt_key_qinq {
2643 uint16_t ethertype_svlan;
2645 uint16_t ethertype_cvlan;
2647 } __attribute__((__packed__));
2649 struct pkt_key_ipv4_5tuple {
2650 uint8_t time_to_live;
2652 uint16_t hdr_checksum;
2657 } __attribute__((__packed__));
2659 struct pkt_key_ipv6_5tuple {
2660 uint16_t payload_length;
2667 } __attribute__((__packed__));
2669 struct pkt_key_ipv4_addr {
2671 } __attribute__((__packed__));
2673 struct pkt_key_ipv6_addr {
2675 } __attribute__((__packed__));
2678 parse_match(char **tokens,
2682 struct table_rule_match *m)
2684 memset(m, 0, sizeof(*m));
2689 if (strcmp(tokens[0], "match") != 0) {
2690 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2694 if (strcmp(tokens[1], "acl") == 0) {
2695 if (n_tokens < 14) {
2696 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2700 m->match_type = TABLE_ACL;
2702 if (strcmp(tokens[2], "priority") != 0) {
2703 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2707 if (parser_read_uint32(&m->match.acl.priority,
2709 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2713 if (strcmp(tokens[4], "ipv4") == 0) {
2714 struct in_addr saddr, daddr;
2716 m->match.acl.ip_version = 1;
2718 if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2719 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2722 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2724 if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2725 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2728 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2729 } else if (strcmp(tokens[4], "ipv6") == 0) {
2730 struct in6_addr saddr, daddr;
2732 m->match.acl.ip_version = 0;
2734 if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2735 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2738 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2740 if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2741 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2744 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2746 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2751 if (parser_read_uint32(&m->match.acl.sa_depth,
2753 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2757 if (parser_read_uint32(&m->match.acl.da_depth,
2759 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2763 if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2764 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2768 if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2769 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2773 if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2774 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2778 if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2779 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2783 if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2784 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2788 m->match.acl.proto_mask = 0xff;
2793 if (strcmp(tokens[1], "array") == 0) {
2795 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2799 m->match_type = TABLE_ARRAY;
2801 if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2802 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2809 if (strcmp(tokens[1], "hash") == 0) {
2811 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2815 m->match_type = TABLE_HASH;
2817 if (strcmp(tokens[2], "raw") == 0) {
2818 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2821 snprintf(out, out_size, MSG_ARG_MISMATCH,
2826 if (parse_hex_string(tokens[3],
2827 m->match.hash.key, &key_size) != 0) {
2828 snprintf(out, out_size, MSG_ARG_INVALID, "key");
2835 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2836 struct pkt_key_ipv4_5tuple *ipv4 =
2837 (struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2838 struct in_addr saddr, daddr;
2843 snprintf(out, out_size, MSG_ARG_MISMATCH,
2848 if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2849 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2853 if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2854 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2858 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2859 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2863 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2864 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2868 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2869 snprintf(out, out_size, MSG_ARG_INVALID,
2874 ipv4->sa = saddr.s_addr;
2875 ipv4->da = daddr.s_addr;
2876 ipv4->sp = rte_cpu_to_be_16(sp);
2877 ipv4->dp = rte_cpu_to_be_16(dp);
2878 ipv4->proto = proto;
2881 } /* hash ipv4_5tuple */
2883 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2884 struct pkt_key_ipv6_5tuple *ipv6 =
2885 (struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2886 struct in6_addr saddr, daddr;
2891 snprintf(out, out_size, MSG_ARG_MISMATCH,
2896 if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2897 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2901 if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2902 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2906 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2907 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2911 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2912 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2916 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2917 snprintf(out, out_size, MSG_ARG_INVALID,
2922 memcpy(ipv6->sa, saddr.s6_addr, 16);
2923 memcpy(ipv6->da, daddr.s6_addr, 16);
2924 ipv6->sp = rte_cpu_to_be_16(sp);
2925 ipv6->dp = rte_cpu_to_be_16(dp);
2926 ipv6->proto = proto;
2929 } /* hash ipv6_5tuple */
2931 if (strcmp(tokens[2], "ipv4_addr") == 0) {
2932 struct pkt_key_ipv4_addr *ipv4_addr =
2933 (struct pkt_key_ipv4_addr *) m->match.hash.key;
2934 struct in_addr addr;
2937 snprintf(out, out_size, MSG_ARG_MISMATCH,
2942 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2943 snprintf(out, out_size, MSG_ARG_INVALID,
2948 ipv4_addr->addr = addr.s_addr;
2951 } /* hash ipv4_addr */
2953 if (strcmp(tokens[2], "ipv6_addr") == 0) {
2954 struct pkt_key_ipv6_addr *ipv6_addr =
2955 (struct pkt_key_ipv6_addr *) m->match.hash.key;
2956 struct in6_addr addr;
2959 snprintf(out, out_size, MSG_ARG_MISMATCH,
2964 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2965 snprintf(out, out_size, MSG_ARG_INVALID,
2970 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
2973 } /* hash ipv6_5tuple */
2975 if (strcmp(tokens[2], "qinq") == 0) {
2976 struct pkt_key_qinq *qinq =
2977 (struct pkt_key_qinq *) m->match.hash.key;
2978 uint16_t svlan, cvlan;
2981 snprintf(out, out_size, MSG_ARG_MISMATCH,
2986 if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
2988 snprintf(out, out_size, MSG_ARG_INVALID,
2993 if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
2995 snprintf(out, out_size, MSG_ARG_INVALID,
3000 qinq->svlan = rte_cpu_to_be_16(svlan);
3001 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3006 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3010 if (strcmp(tokens[1], "lpm") == 0) {
3012 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3016 m->match_type = TABLE_LPM;
3018 if (strcmp(tokens[2], "ipv4") == 0) {
3019 struct in_addr addr;
3021 m->match.lpm.ip_version = 1;
3023 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
3024 snprintf(out, out_size, MSG_ARG_INVALID,
3029 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3030 } else if (strcmp(tokens[2], "ipv6") == 0) {
3031 struct in6_addr addr;
3033 m->match.lpm.ip_version = 0;
3035 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
3036 snprintf(out, out_size, MSG_ARG_INVALID,
3041 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3043 snprintf(out, out_size, MSG_ARG_MISMATCH,
3048 if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3049 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3056 snprintf(out, out_size, MSG_ARG_MISMATCH,
3057 "acl or array or hash or lpm");
3069 * | table <table_id>
3070 * [balance <out0> ... <out7>]
3072 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3073 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3074 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3075 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3076 * [tm subport <subport_id> pipe <pipe_id>]
3079 * | vlan <da> <sa> <pcp> <dei> <vid>
3080 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3081 * | mpls unicast | multicast
3083 * label0 <label> <tc> <ttl>
3084 * [label1 <label> <tc> <ttl>
3085 * [label2 <label> <tc> <ttl>
3086 * [label3 <label> <tc> <ttl>]]]
3087 * | pppoe <da> <sa> <session_id>
3088 * | vxlan ether <da> <sa>
3089 * [vlan <pcp> <dei> <vid>]
3090 * ipv4 <sa> <da> <dscp> <ttl>
3091 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3094 * [nat ipv4 | ipv6 <addr> <port>]
3102 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3104 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3105 * auth_algo <algo> auth_key <key> digest_size <size>
3107 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3108 * digest_size <size>
3109 * data_offset <data_offset>]
3112 * <pa> ::= g | y | r | drop
3115 parse_table_action_fwd(char **tokens,
3117 struct table_rule_action *a)
3119 if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
3125 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3126 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3127 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3131 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3134 if ((n_tokens < 2) ||
3135 parser_read_uint32(&id, tokens[1]))
3138 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3140 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3144 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3145 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3146 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3150 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3153 if ((n_tokens < 2) ||
3154 parser_read_uint32(&id, tokens[1]))
3157 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3159 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3167 parse_table_action_balance(char **tokens,
3169 struct table_rule_action *a)
3173 if ((n_tokens == 0) || (strcmp(tokens[0], "balance") != 0))
3179 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3182 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3183 if (parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3186 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3187 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3192 parse_policer_action(char *token, enum rte_table_action_policer *a)
3194 if (strcmp(token, "g") == 0) {
3195 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3199 if (strcmp(token, "y") == 0) {
3200 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3204 if (strcmp(token, "r") == 0) {
3205 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3209 if (strcmp(token, "drop") == 0) {
3210 *a = RTE_TABLE_ACTION_POLICER_DROP;
3218 parse_table_action_meter_tc(char **tokens,
3220 struct rte_table_action_mtr_tc_params *mtr)
3222 if ((n_tokens < 9) ||
3223 strcmp(tokens[0], "meter") ||
3224 parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3225 strcmp(tokens[2], "policer") ||
3226 strcmp(tokens[3], "g") ||
3227 parse_policer_action(tokens[4], &mtr->policer[e_RTE_METER_GREEN]) ||
3228 strcmp(tokens[5], "y") ||
3229 parse_policer_action(tokens[6], &mtr->policer[e_RTE_METER_YELLOW]) ||
3230 strcmp(tokens[7], "r") ||
3231 parse_policer_action(tokens[8], &mtr->policer[e_RTE_METER_RED]))
3238 parse_table_action_meter(char **tokens,
3240 struct table_rule_action *a)
3242 if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
3248 if ((n_tokens < 10) ||
3249 strcmp(tokens[0], "tc0") ||
3250 (parse_table_action_meter_tc(tokens + 1,
3252 &a->mtr.mtr[0]) == 0))
3258 if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
3260 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3264 if ((n_tokens < 30) ||
3265 (parse_table_action_meter_tc(tokens + 1,
3266 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3267 strcmp(tokens[10], "tc2") ||
3268 (parse_table_action_meter_tc(tokens + 11,
3269 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3270 strcmp(tokens[20], "tc3") ||
3271 (parse_table_action_meter_tc(tokens + 21,
3272 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3275 a->mtr.tc_mask = 0xF;
3276 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3277 return 1 + 10 + 3 * 10;
3281 parse_table_action_tm(char **tokens,
3283 struct table_rule_action *a)
3285 uint32_t subport_id, pipe_id;
3287 if ((n_tokens < 5) ||
3288 strcmp(tokens[0], "tm") ||
3289 strcmp(tokens[1], "subport") ||
3290 parser_read_uint32(&subport_id, tokens[2]) ||
3291 strcmp(tokens[3], "pipe") ||
3292 parser_read_uint32(&pipe_id, tokens[4]))
3295 a->tm.subport_id = subport_id;
3296 a->tm.pipe_id = pipe_id;
3297 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3302 parse_table_action_encap(char **tokens,
3304 struct table_rule_action *a)
3306 if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
3313 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3314 if ((n_tokens < 3) ||
3315 parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3316 parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3319 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3320 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3325 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3326 uint32_t pcp, dei, vid;
3328 if ((n_tokens < 6) ||
3329 parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3330 parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3331 parser_read_uint32(&pcp, tokens[3]) ||
3333 parser_read_uint32(&dei, tokens[4]) ||
3335 parser_read_uint32(&vid, tokens[5]) ||
3339 a->encap.vlan.vlan.pcp = pcp & 0x7;
3340 a->encap.vlan.vlan.dei = dei & 0x1;
3341 a->encap.vlan.vlan.vid = vid & 0xFFF;
3342 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3343 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3348 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3349 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3350 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3352 if ((n_tokens < 9) ||
3353 parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3354 parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3355 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3356 (svlan_pcp > 0x7) ||
3357 parser_read_uint32(&svlan_dei, tokens[4]) ||
3358 (svlan_dei > 0x1) ||
3359 parser_read_uint32(&svlan_vid, tokens[5]) ||
3360 (svlan_vid > 0xFFF) ||
3361 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3362 (cvlan_pcp > 0x7) ||
3363 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3364 (cvlan_dei > 0x1) ||
3365 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3366 (cvlan_vid > 0xFFF))
3369 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3370 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3371 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3372 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3373 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3374 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3375 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3376 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3381 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3382 uint32_t label, tc, ttl;
3387 if (strcmp(tokens[1], "unicast") == 0)
3388 a->encap.mpls.unicast = 1;
3389 else if (strcmp(tokens[1], "multicast") == 0)
3390 a->encap.mpls.unicast = 0;
3394 if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3395 parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3396 strcmp(tokens[4], "label0") ||
3397 parser_read_uint32(&label, tokens[5]) ||
3398 (label > 0xFFFFF) ||
3399 parser_read_uint32(&tc, tokens[6]) ||
3401 parser_read_uint32(&ttl, tokens[7]) ||
3405 a->encap.mpls.mpls[0].label = label;
3406 a->encap.mpls.mpls[0].tc = tc;
3407 a->encap.mpls.mpls[0].ttl = ttl;
3412 if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3413 a->encap.mpls.mpls_count = 1;
3414 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3415 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3419 if ((n_tokens < 4) ||
3420 parser_read_uint32(&label, tokens[1]) ||
3421 (label > 0xFFFFF) ||
3422 parser_read_uint32(&tc, tokens[2]) ||
3424 parser_read_uint32(&ttl, tokens[3]) ||
3428 a->encap.mpls.mpls[1].label = label;
3429 a->encap.mpls.mpls[1].tc = tc;
3430 a->encap.mpls.mpls[1].ttl = ttl;
3435 if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3436 a->encap.mpls.mpls_count = 2;
3437 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3438 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3442 if ((n_tokens < 4) ||
3443 parser_read_uint32(&label, tokens[1]) ||
3444 (label > 0xFFFFF) ||
3445 parser_read_uint32(&tc, tokens[2]) ||
3447 parser_read_uint32(&ttl, tokens[3]) ||
3451 a->encap.mpls.mpls[2].label = label;
3452 a->encap.mpls.mpls[2].tc = tc;
3453 a->encap.mpls.mpls[2].ttl = ttl;
3458 if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3459 a->encap.mpls.mpls_count = 3;
3460 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3461 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3462 return 1 + 8 + 4 + 4;
3465 if ((n_tokens < 4) ||
3466 parser_read_uint32(&label, tokens[1]) ||
3467 (label > 0xFFFFF) ||
3468 parser_read_uint32(&tc, tokens[2]) ||
3470 parser_read_uint32(&ttl, tokens[3]) ||
3474 a->encap.mpls.mpls[3].label = label;
3475 a->encap.mpls.mpls[3].tc = tc;
3476 a->encap.mpls.mpls[3].ttl = ttl;
3478 a->encap.mpls.mpls_count = 4;
3479 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3480 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3481 return 1 + 8 + 4 + 4 + 4;
3485 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3486 if ((n_tokens < 4) ||
3487 parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3488 parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3489 parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3493 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3494 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3499 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3506 /* ether <da> <sa> */
3507 if ((n_tokens < 3) ||
3508 strcmp(tokens[0], "ether") ||
3509 parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3510 parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3517 /* [vlan <pcp> <dei> <vid>] */
3518 if (strcmp(tokens[0], "vlan") == 0) {
3519 uint32_t pcp, dei, vid;
3521 if ((n_tokens < 4) ||
3522 parser_read_uint32(&pcp, tokens[1]) ||
3524 parser_read_uint32(&dei, tokens[2]) ||
3526 parser_read_uint32(&vid, tokens[3]) ||
3530 a->encap.vxlan.vlan.pcp = pcp;
3531 a->encap.vxlan.vlan.dei = dei;
3532 a->encap.vxlan.vlan.vid = vid;
3539 /* ipv4 <sa> <da> <dscp> <ttl>
3540 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3541 if (strcmp(tokens[0], "ipv4") == 0) {
3542 struct in_addr sa, da;
3545 if ((n_tokens < 5) ||
3546 parse_ipv4_addr(tokens[1], &sa) ||
3547 parse_ipv4_addr(tokens[2], &da) ||
3548 parser_read_uint8(&dscp, tokens[3]) ||
3550 parser_read_uint8(&ttl, tokens[4]))
3553 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3554 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3555 a->encap.vxlan.ipv4.dscp = dscp;
3556 a->encap.vxlan.ipv4.ttl = ttl;
3561 } else if (strcmp(tokens[0], "ipv6") == 0) {
3562 struct in6_addr sa, da;
3563 uint32_t flow_label;
3564 uint8_t dscp, hop_limit;
3566 if ((n_tokens < 6) ||
3567 parse_ipv6_addr(tokens[1], &sa) ||
3568 parse_ipv6_addr(tokens[2], &da) ||
3569 parser_read_uint32(&flow_label, tokens[3]) ||
3570 parser_read_uint8(&dscp, tokens[4]) ||
3572 parser_read_uint8(&hop_limit, tokens[5]))
3575 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3576 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3577 a->encap.vxlan.ipv6.flow_label = flow_label;
3578 a->encap.vxlan.ipv6.dscp = dscp;
3579 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3588 if ((n_tokens < 3) ||
3589 strcmp(tokens[0], "udp") ||
3590 parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3591 parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3599 if ((n_tokens < 2) ||
3600 strcmp(tokens[0], "vxlan") ||
3601 parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3602 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3609 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3610 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3618 parse_table_action_nat(char **tokens,
3620 struct table_rule_action *a)
3622 if ((n_tokens < 4) ||
3623 strcmp(tokens[0], "nat"))
3626 if (strcmp(tokens[1], "ipv4") == 0) {
3627 struct in_addr addr;
3630 if (parse_ipv4_addr(tokens[2], &addr) ||
3631 parser_read_uint16(&port, tokens[3]))
3634 a->nat.ip_version = 1;
3635 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3637 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3641 if (strcmp(tokens[1], "ipv6") == 0) {
3642 struct in6_addr addr;
3645 if (parse_ipv6_addr(tokens[2], &addr) ||
3646 parser_read_uint16(&port, tokens[3]))
3649 a->nat.ip_version = 0;
3650 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3652 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3660 parse_table_action_ttl(char **tokens,
3662 struct table_rule_action *a)
3664 if ((n_tokens < 2) ||
3665 strcmp(tokens[0], "ttl"))
3668 if (strcmp(tokens[1], "dec") == 0)
3669 a->ttl.decrement = 1;
3670 else if (strcmp(tokens[1], "keep") == 0)
3671 a->ttl.decrement = 0;
3675 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3680 parse_table_action_stats(char **tokens,
3682 struct table_rule_action *a)
3684 if ((n_tokens < 1) ||
3685 strcmp(tokens[0], "stats"))
3688 a->stats.n_packets = 0;
3689 a->stats.n_bytes = 0;
3690 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3695 parse_table_action_time(char **tokens,
3697 struct table_rule_action *a)
3699 if ((n_tokens < 1) ||
3700 strcmp(tokens[0], "time"))
3703 a->time.time = rte_rdtsc();
3704 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3709 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
3711 struct rte_crypto_sym_xform *xform[2] = {NULL};
3714 xform[0] = p->xform;
3716 xform[1] = xform[0]->next;
3718 for (i = 0; i < 2; i++) {
3719 if (xform[i] == NULL)
3722 switch (xform[i]->type) {
3723 case RTE_CRYPTO_SYM_XFORM_CIPHER:
3724 if (xform[i]->cipher.key.data)
3725 free(xform[i]->cipher.key.data);
3726 if (p->cipher_auth.cipher_iv.val)
3727 free(p->cipher_auth.cipher_iv.val);
3728 if (p->cipher_auth.cipher_iv_update.val)
3729 free(p->cipher_auth.cipher_iv_update.val);
3731 case RTE_CRYPTO_SYM_XFORM_AUTH:
3732 if (xform[i]->auth.key.data)
3733 free(xform[i]->cipher.key.data);
3734 if (p->cipher_auth.auth_iv.val)
3735 free(p->cipher_auth.cipher_iv.val);
3736 if (p->cipher_auth.auth_iv_update.val)
3737 free(p->cipher_auth.cipher_iv_update.val);
3739 case RTE_CRYPTO_SYM_XFORM_AEAD:
3740 if (xform[i]->aead.key.data)
3741 free(xform[i]->cipher.key.data);
3743 free(p->aead.iv.val);
3744 if (p->aead.aad.val)
3745 free(p->aead.aad.val);
3754 static struct rte_crypto_sym_xform *
3755 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3756 char **tokens, uint32_t n_tokens, uint32_t encrypt,
3757 uint32_t *used_n_tokens)
3759 struct rte_crypto_sym_xform *xform_cipher;
3763 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
3764 strcmp(tokens[3], "cipher_key") ||
3765 strcmp(tokens[5], "cipher_iv"))
3768 xform_cipher = calloc(1, sizeof(*xform_cipher));
3769 if (xform_cipher == NULL)
3772 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3773 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
3774 RTE_CRYPTO_CIPHER_OP_DECRYPT;
3777 status = rte_cryptodev_get_cipher_algo_enum(
3778 &xform_cipher->cipher.algo, tokens[2]);
3783 len = strlen(tokens[4]);
3784 xform_cipher->cipher.key.data = calloc(1, len / 2 + 1);
3785 if (xform_cipher->cipher.key.data == NULL)
3788 status = parse_hex_string(tokens[4],
3789 xform_cipher->cipher.key.data,
3794 xform_cipher->cipher.key.length = (uint16_t)len;
3797 len = strlen(tokens[6]);
3799 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
3800 if (p->cipher_auth.cipher_iv.val == NULL)
3803 status = parse_hex_string(tokens[6],
3804 p->cipher_auth.cipher_iv.val,
3809 xform_cipher->cipher.iv.length = (uint16_t)len;
3810 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3811 p->cipher_auth.cipher_iv.length = (uint32_t)len;
3814 return xform_cipher;
3817 if (xform_cipher->cipher.key.data)
3818 free(xform_cipher->cipher.key.data);
3820 if (p->cipher_auth.cipher_iv.val) {
3821 free(p->cipher_auth.cipher_iv.val);
3822 p->cipher_auth.cipher_iv.val = NULL;
3830 static struct rte_crypto_sym_xform *
3831 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3832 char **tokens, uint32_t n_tokens, uint32_t encrypt,
3833 uint32_t *used_n_tokens)
3835 struct rte_crypto_sym_xform *xform_cipher;
3836 struct rte_crypto_sym_xform *xform_auth;
3840 if (n_tokens < 13 ||
3841 strcmp(tokens[7], "auth_algo") ||
3842 strcmp(tokens[9], "auth_key") ||
3843 strcmp(tokens[11], "digest_size"))
3846 xform_auth = calloc(1, sizeof(*xform_auth));
3847 if (xform_auth == NULL)
3850 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
3851 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
3852 RTE_CRYPTO_AUTH_OP_VERIFY;
3855 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
3861 len = strlen(tokens[10]);
3862 xform_auth->auth.key.data = calloc(1, len / 2 + 1);
3863 if (xform_auth->auth.key.data == NULL)
3866 status = parse_hex_string(tokens[10],
3867 xform_auth->auth.key.data, (uint32_t *)&len);
3871 xform_auth->auth.key.length = (uint16_t)len;
3873 if (strcmp(tokens[11], "digest_size"))
3876 status = parser_read_uint16(&xform_auth->auth.digest_length,
3881 xform_cipher = parse_table_action_cipher(p, tokens, 7, encrypt,
3883 if (xform_cipher == NULL)
3886 *used_n_tokens += 6;
3889 xform_cipher->next = xform_auth;
3890 return xform_cipher;
3892 xform_auth->next = xform_cipher;
3897 if (xform_auth->auth.key.data)
3898 free(xform_auth->auth.key.data);
3899 if (p->cipher_auth.auth_iv.val) {
3900 free(p->cipher_auth.auth_iv.val);
3901 p->cipher_auth.auth_iv.val = 0;
3909 static struct rte_crypto_sym_xform *
3910 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3911 char **tokens, uint32_t n_tokens, uint32_t encrypt,
3912 uint32_t *used_n_tokens)
3914 struct rte_crypto_sym_xform *xform_aead;
3918 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
3919 strcmp(tokens[3], "aead_key") ||
3920 strcmp(tokens[5], "aead_iv") ||
3921 strcmp(tokens[7], "aead_aad") ||
3922 strcmp(tokens[9], "digest_size"))
3925 xform_aead = calloc(1, sizeof(*xform_aead));
3926 if (xform_aead == NULL)
3929 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
3930 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
3931 RTE_CRYPTO_AEAD_OP_DECRYPT;
3934 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
3940 len = strlen(tokens[4]);
3941 xform_aead->aead.key.data = calloc(1, len / 2 + 1);
3942 if (xform_aead->aead.key.data == NULL)
3945 status = parse_hex_string(tokens[4], xform_aead->aead.key.data,
3950 xform_aead->aead.key.length = (uint16_t)len;
3953 len = strlen(tokens[6]);
3954 p->aead.iv.val = calloc(1, len / 2 + 1);
3955 if (p->aead.iv.val == NULL)
3958 status = parse_hex_string(tokens[6], p->aead.iv.val,
3963 xform_aead->aead.iv.length = (uint16_t)len;
3964 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3965 p->aead.iv.length = (uint32_t)len;
3968 len = strlen(tokens[8]);
3969 p->aead.aad.val = calloc(1, len / 2 + 1);
3970 if (p->aead.aad.val == NULL)
3973 status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
3977 xform_aead->aead.aad_length = (uint16_t)len;
3978 p->aead.aad.length = (uint32_t)len;
3981 status = parser_read_uint16(&xform_aead->aead.digest_length,
3986 *used_n_tokens = 11;
3991 if (xform_aead->aead.key.data)
3992 free(xform_aead->aead.key.data);
3993 if (p->aead.iv.val) {
3994 free(p->aead.iv.val);
3995 p->aead.iv.val = NULL;
3997 if (p->aead.aad.val) {
3998 free(p->aead.aad.val);
3999 p->aead.aad.val = NULL;
4009 parse_table_action_sym_crypto(char **tokens,
4011 struct table_rule_action *a)
4013 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4014 struct rte_crypto_sym_xform *xform = NULL;
4015 uint32_t used_n_tokens;
4019 if ((n_tokens < 12) ||
4020 strcmp(tokens[0], "sym_crypto") ||
4021 strcmp(tokens[2], "type"))
4024 memset(p, 0, sizeof(*p));
4026 if (strcmp(tokens[1], "encrypt") == 0)
4031 status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4035 if (strcmp(tokens[3], "cipher") == 0) {
4039 xform = parse_table_action_cipher(p, tokens, n_tokens, encrypt,
4041 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4045 xform = parse_table_action_cipher_auth(p, tokens, n_tokens,
4046 encrypt, &used_n_tokens);
4047 } else if (strcmp(tokens[3], "aead") == 0) {
4051 xform = parse_table_action_aead(p, tokens, n_tokens, encrypt,
4060 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4061 parse_free_sym_crypto_param_data(p);
4065 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4067 return used_n_tokens + 5;
4071 parse_table_action(char **tokens,
4075 struct table_rule_action *a)
4077 uint32_t n_tokens0 = n_tokens;
4079 memset(a, 0, sizeof(*a));
4081 if ((n_tokens < 2) ||
4082 strcmp(tokens[0], "action"))
4088 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4091 n = parse_table_action_fwd(tokens, n_tokens, a);
4093 snprintf(out, out_size, MSG_ARG_INVALID,
4102 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4105 n = parse_table_action_balance(tokens, n_tokens, a);
4107 snprintf(out, out_size, MSG_ARG_INVALID,
4116 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4119 n = parse_table_action_meter(tokens, n_tokens, a);
4121 snprintf(out, out_size, MSG_ARG_INVALID,
4130 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4133 n = parse_table_action_tm(tokens, n_tokens, a);
4135 snprintf(out, out_size, MSG_ARG_INVALID,
4144 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4147 n = parse_table_action_encap(tokens, n_tokens, a);
4149 snprintf(out, out_size, MSG_ARG_INVALID,
4158 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4161 n = parse_table_action_nat(tokens, n_tokens, a);
4163 snprintf(out, out_size, MSG_ARG_INVALID,
4172 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4175 n = parse_table_action_ttl(tokens, n_tokens, a);
4177 snprintf(out, out_size, MSG_ARG_INVALID,
4186 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4189 n = parse_table_action_stats(tokens, n_tokens, a);
4191 snprintf(out, out_size, MSG_ARG_INVALID,
4200 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4203 n = parse_table_action_time(tokens, n_tokens, a);
4205 snprintf(out, out_size, MSG_ARG_INVALID,
4214 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4217 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4219 snprintf(out, out_size, MSG_ARG_INVALID,
4220 "action sym_crypto");
4228 if (n_tokens0 - n_tokens == 1) {
4229 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4233 return n_tokens0 - n_tokens;
4237 static const char cmd_pipeline_table_rule_add_help[] =
4238 "pipeline <pipeline_name> table <table_id> rule add\n"
4240 " action <table_action>\n";
4243 cmd_pipeline_table_rule_add(char **tokens,
4248 struct table_rule_match m;
4249 struct table_rule_action a;
4250 char *pipeline_name;
4252 uint32_t table_id, t0, n_tokens_parsed;
4256 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4260 pipeline_name = tokens[1];
4262 if (strcmp(tokens[2], "table") != 0) {
4263 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4267 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4268 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4272 if (strcmp(tokens[4], "rule") != 0) {
4273 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4277 if (strcmp(tokens[5], "add") != 0) {
4278 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4285 n_tokens_parsed = parse_match(tokens + t0,
4290 if (n_tokens_parsed == 0)
4292 t0 += n_tokens_parsed;
4295 n_tokens_parsed = parse_table_action(tokens + t0,
4300 if (n_tokens_parsed == 0)
4302 t0 += n_tokens_parsed;
4304 if (t0 != n_tokens) {
4305 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4309 status = pipeline_table_rule_add(pipeline_name, table_id,
4312 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4316 if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
4317 parse_free_sym_crypto_param_data(&a.sym_crypto);
4321 static const char cmd_pipeline_table_rule_add_default_help[] =
4322 "pipeline <pipeline_name> table <table_id> rule add\n"
4328 " | port <port_id>\n"
4330 " | table <table_id>\n";
4333 cmd_pipeline_table_rule_add_default(char **tokens,
4338 struct table_rule_action action;
4340 char *pipeline_name;
4344 if ((n_tokens != 11) && (n_tokens != 12)) {
4345 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4349 pipeline_name = tokens[1];
4351 if (strcmp(tokens[2], "table") != 0) {
4352 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4356 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4357 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4361 if (strcmp(tokens[4], "rule") != 0) {
4362 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4366 if (strcmp(tokens[5], "add") != 0) {
4367 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4371 if (strcmp(tokens[6], "match") != 0) {
4372 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4376 if (strcmp(tokens[7], "default") != 0) {
4377 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4381 if (strcmp(tokens[8], "action") != 0) {
4382 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4386 if (strcmp(tokens[9], "fwd") != 0) {
4387 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4391 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4393 if (strcmp(tokens[10], "drop") == 0) {
4394 if (n_tokens != 11) {
4395 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4399 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4400 } else if (strcmp(tokens[10], "port") == 0) {
4403 if (n_tokens != 12) {
4404 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4408 if (parser_read_uint32(&id, tokens[11]) != 0) {
4409 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4413 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4415 } else if (strcmp(tokens[10], "meta") == 0) {
4416 if (n_tokens != 11) {
4417 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4421 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4422 } else if (strcmp(tokens[10], "table") == 0) {
4425 if (n_tokens != 12) {
4426 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4430 if (parser_read_uint32(&id, tokens[11]) != 0) {
4431 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4435 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4438 snprintf(out, out_size, MSG_ARG_INVALID,
4439 "drop or port or meta or table");
4443 status = pipeline_table_rule_add_default(pipeline_name,
4448 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4454 static const char cmd_pipeline_table_rule_add_bulk_help[] =
4455 "pipeline <pipeline_name> table <table_id> rule add bulk <file_name> <n_rules>\n"
4457 " File <file_name>:\n"
4458 " - line format: match <match> action <action>\n";
4461 cli_rule_file_process(const char *file_name,
4462 size_t line_len_max,
4463 struct table_rule_match *m,
4464 struct table_rule_action *a,
4466 uint32_t *line_number,
4471 cmd_pipeline_table_rule_add_bulk(char **tokens,
4476 struct table_rule_match *match;
4477 struct table_rule_action *action;
4479 char *pipeline_name, *file_name;
4480 uint32_t table_id, n_rules, n_rules_parsed, line_number;
4483 if (n_tokens != 9) {
4484 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4488 pipeline_name = tokens[1];
4490 if (strcmp(tokens[2], "table") != 0) {
4491 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4495 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4496 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4500 if (strcmp(tokens[4], "rule") != 0) {
4501 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4505 if (strcmp(tokens[5], "add") != 0) {
4506 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4510 if (strcmp(tokens[6], "bulk") != 0) {
4511 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4515 file_name = tokens[7];
4517 if ((parser_read_uint32(&n_rules, tokens[8]) != 0) ||
4519 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
4523 /* Memory allocation. */
4524 match = calloc(n_rules, sizeof(struct table_rule_match));
4525 action = calloc(n_rules, sizeof(struct table_rule_action));
4526 data = calloc(n_rules, sizeof(void *));
4527 if ((match == NULL) || (action == NULL) || (data == NULL)) {
4528 snprintf(out, out_size, MSG_OUT_OF_MEMORY);
4535 /* Load rule file */
4536 n_rules_parsed = n_rules;
4537 status = cli_rule_file_process(file_name,
4546 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4552 if (n_rules_parsed != n_rules) {
4553 snprintf(out, out_size, MSG_FILE_NOT_ENOUGH, file_name);
4561 status = pipeline_table_rule_add_bulk(pipeline_name,
4568 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4582 static const char cmd_pipeline_table_rule_delete_help[] =
4583 "pipeline <pipeline_name> table <table_id> rule delete\n"
4587 cmd_pipeline_table_rule_delete(char **tokens,
4592 struct table_rule_match m;
4593 char *pipeline_name;
4594 uint32_t table_id, n_tokens_parsed, t0;
4598 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4602 pipeline_name = tokens[1];
4604 if (strcmp(tokens[2], "table") != 0) {
4605 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4609 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4610 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4614 if (strcmp(tokens[4], "rule") != 0) {
4615 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4619 if (strcmp(tokens[5], "delete") != 0) {
4620 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4627 n_tokens_parsed = parse_match(tokens + t0,
4632 if (n_tokens_parsed == 0)
4634 t0 += n_tokens_parsed;
4636 if (n_tokens != t0) {
4637 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4641 status = pipeline_table_rule_delete(pipeline_name,
4645 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4651 static const char cmd_pipeline_table_rule_delete_default_help[] =
4652 "pipeline <pipeline_name> table <table_id> rule delete\n"
4657 cmd_pipeline_table_rule_delete_default(char **tokens,
4662 char *pipeline_name;
4666 if (n_tokens != 8) {
4667 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4671 pipeline_name = tokens[1];
4673 if (strcmp(tokens[2], "table") != 0) {
4674 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4678 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4679 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4683 if (strcmp(tokens[4], "rule") != 0) {
4684 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4688 if (strcmp(tokens[5], "delete") != 0) {
4689 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4693 if (strcmp(tokens[6], "match") != 0) {
4694 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4698 if (strcmp(tokens[7], "default") != 0) {
4699 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4703 status = pipeline_table_rule_delete_default(pipeline_name,
4706 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4712 static const char cmd_pipeline_table_rule_stats_read_help[] =
4713 "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n";
4716 cmd_pipeline_table_rule_stats_read(char **tokens,
4717 uint32_t n_tokens __rte_unused,
4721 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
4725 static const char cmd_pipeline_table_meter_profile_add_help[] =
4726 "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
4727 " add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
4728 " | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
4731 cmd_pipeline_table_meter_profile_add(char **tokens,
4736 struct rte_table_action_meter_profile p;
4737 char *pipeline_name;
4738 uint32_t table_id, meter_profile_id;
4742 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4746 pipeline_name = tokens[1];
4748 if (strcmp(tokens[2], "table") != 0) {
4749 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
4753 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4754 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4758 if (strcmp(tokens[4], "meter") != 0) {
4759 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
4763 if (strcmp(tokens[5], "profile") != 0) {
4764 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
4768 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
4769 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
4773 if (strcmp(tokens[7], "add") != 0) {
4774 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4778 if (strcmp(tokens[8], "srtcm") == 0) {
4779 if (n_tokens != 15) {
4780 snprintf(out, out_size, MSG_ARG_MISMATCH,
4785 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
4787 if (strcmp(tokens[9], "cir") != 0) {
4788 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
4792 if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
4793 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
4797 if (strcmp(tokens[11], "cbs") != 0) {
4798 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
4802 if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
4803 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
4807 if (strcmp(tokens[13], "ebs") != 0) {
4808 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
4812 if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
4813 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
4816 } else if (strcmp(tokens[8], "trtcm") == 0) {
4817 if (n_tokens != 17) {
4818 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4822 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
4824 if (strcmp(tokens[9], "cir") != 0) {
4825 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
4829 if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
4830 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
4834 if (strcmp(tokens[11], "pir") != 0) {
4835 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
4839 if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
4840 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
4843 if (strcmp(tokens[13], "cbs") != 0) {
4844 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
4848 if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
4849 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
4853 if (strcmp(tokens[15], "pbs") != 0) {
4854 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
4858 if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
4859 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
4863 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4867 status = pipeline_table_mtr_profile_add(pipeline_name,
4872 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4878 static const char cmd_pipeline_table_meter_profile_delete_help[] =
4879 "pipeline <pipeline_name> table <table_id>\n"
4880 " meter profile <meter_profile_id> delete\n";
4883 cmd_pipeline_table_meter_profile_delete(char **tokens,
4888 char *pipeline_name;
4889 uint32_t table_id, meter_profile_id;
4892 if (n_tokens != 8) {
4893 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4897 pipeline_name = tokens[1];
4899 if (strcmp(tokens[2], "table") != 0) {
4900 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
4904 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4905 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4909 if (strcmp(tokens[4], "meter") != 0) {
4910 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
4914 if (strcmp(tokens[5], "profile") != 0) {
4915 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
4919 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
4920 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
4924 if (strcmp(tokens[7], "delete") != 0) {
4925 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4929 status = pipeline_table_mtr_profile_delete(pipeline_name,
4933 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4939 static const char cmd_pipeline_table_rule_meter_read_help[] =
4940 "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n";
4943 cmd_pipeline_table_rule_meter_read(char **tokens,
4944 uint32_t n_tokens __rte_unused,
4948 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
4952 static const char cmd_pipeline_table_dscp_help[] =
4953 "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
4955 " File <file_name>:\n"
4956 " - exactly 64 lines\n"
4957 " - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
4960 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
4961 const char *file_name,
4962 uint32_t *line_number)
4967 /* Check input arguments */
4968 if ((dscp_table == NULL) ||
4969 (file_name == NULL) ||
4970 (line_number == NULL)) {
4976 /* Open input file */
4977 f = fopen(file_name, "r");
4984 for (dscp = 0, l = 1; ; l++) {
4987 enum rte_meter_color color;
4988 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
4990 if (fgets(line, sizeof(line), f) == NULL)
4993 if (is_comment(line))
4996 if (parse_tokenize_string(line, tokens, &n_tokens)) {
5005 if ((dscp >= RTE_DIM(dscp_table->entry)) ||
5006 (n_tokens != RTE_DIM(tokens)) ||
5007 parser_read_uint32(&tc_id, tokens[0]) ||
5008 (tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
5009 parser_read_uint32(&tc_queue_id, tokens[1]) ||
5010 (tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
5011 (strlen(tokens[2]) != 1)) {
5017 switch (tokens[2][0]) {
5020 color = e_RTE_METER_GREEN;
5025 color = e_RTE_METER_YELLOW;
5030 color = e_RTE_METER_RED;
5039 dscp_table->entry[dscp].tc_id = tc_id;
5040 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5041 dscp_table->entry[dscp].color = color;
5051 cmd_pipeline_table_dscp(char **tokens,
5056 struct rte_table_action_dscp_table dscp_table;
5057 char *pipeline_name, *file_name;
5058 uint32_t table_id, line_number;
5061 if (n_tokens != 6) {
5062 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5066 pipeline_name = tokens[1];
5068 if (strcmp(tokens[2], "table") != 0) {
5069 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5073 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5074 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5078 if (strcmp(tokens[4], "dscp") != 0) {
5079 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5083 file_name = tokens[5];
5085 status = load_dscp_table(&dscp_table, file_name, &line_number);
5087 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5091 status = pipeline_table_dscp_table_update(pipeline_name,
5096 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5102 static const char cmd_pipeline_table_rule_ttl_read_help[] =
5103 "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n";
5106 cmd_pipeline_table_rule_ttl_read(char **tokens,
5107 uint32_t n_tokens __rte_unused,
5111 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5115 static const char cmd_thread_pipeline_enable_help[] =
5116 "thread <thread_id> pipeline <pipeline_name> enable\n";
5119 cmd_thread_pipeline_enable(char **tokens,
5124 char *pipeline_name;
5128 if (n_tokens != 5) {
5129 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5133 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5134 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5138 if (strcmp(tokens[2], "pipeline") != 0) {
5139 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5143 pipeline_name = tokens[3];
5145 if (strcmp(tokens[4], "enable") != 0) {
5146 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5150 status = thread_pipeline_enable(thread_id, pipeline_name);
5152 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5158 static const char cmd_thread_pipeline_disable_help[] =
5159 "thread <thread_id> pipeline <pipeline_name> disable\n";
5162 cmd_thread_pipeline_disable(char **tokens,
5167 char *pipeline_name;
5171 if (n_tokens != 5) {
5172 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5176 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5177 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5181 if (strcmp(tokens[2], "pipeline") != 0) {
5182 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5186 pipeline_name = tokens[3];
5188 if (strcmp(tokens[4], "disable") != 0) {
5189 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
5193 status = thread_pipeline_disable(thread_id, pipeline_name);
5195 snprintf(out, out_size, MSG_CMD_FAIL,
5196 "thread pipeline disable");
5202 cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
5207 if (n_tokens == 0) {
5208 snprintf(out, out_size,
5209 "Type 'help <command>' for details on each command.\n\n"
5210 "List of commands:\n"
5214 "\ttmgr subport profile\n"
5215 "\ttmgr pipe profile\n"
5218 "\ttmgr subport pipe\n"
5221 "\tport in action profile\n"
5222 "\ttable action profile\n"
5224 "\tpipeline port in\n"
5225 "\tpipeline port out\n"
5226 "\tpipeline table\n"
5227 "\tpipeline port in table\n"
5228 "\tpipeline port in stats\n"
5229 "\tpipeline port in enable\n"
5230 "\tpipeline port in disable\n"
5231 "\tpipeline port out stats\n"
5232 "\tpipeline table stats\n"
5233 "\tpipeline table rule add\n"
5234 "\tpipeline table rule add default\n"
5235 "\tpipeline table rule add bulk\n"
5236 "\tpipeline table rule delete\n"
5237 "\tpipeline table rule delete default\n"
5238 "\tpipeline table rule stats read\n"
5239 "\tpipeline table meter profile add\n"
5240 "\tpipeline table meter profile delete\n"
5241 "\tpipeline table rule meter read\n"
5242 "\tpipeline table dscp\n"
5243 "\tpipeline table rule ttl read\n"
5244 "\tthread pipeline enable\n"
5245 "\tthread pipeline disable\n\n");
5249 if (strcmp(tokens[0], "mempool") == 0) {
5250 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
5254 if (strcmp(tokens[0], "link") == 0) {
5255 snprintf(out, out_size, "\n%s\n", cmd_link_help);
5259 if (strcmp(tokens[0], "swq") == 0) {
5260 snprintf(out, out_size, "\n%s\n", cmd_swq_help);
5264 if (strcmp(tokens[0], "tmgr") == 0) {
5265 if (n_tokens == 1) {
5266 snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
5270 if ((n_tokens == 2) &&
5271 (strcmp(tokens[1], "subport")) == 0) {
5272 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
5276 if ((n_tokens == 3) &&
5277 (strcmp(tokens[1], "subport") == 0) &&
5278 (strcmp(tokens[2], "profile") == 0)) {
5279 snprintf(out, out_size, "\n%s\n",
5280 cmd_tmgr_subport_profile_help);
5284 if ((n_tokens == 3) &&
5285 (strcmp(tokens[1], "subport") == 0) &&
5286 (strcmp(tokens[2], "pipe") == 0)) {
5287 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
5291 if ((n_tokens == 3) &&
5292 (strcmp(tokens[1], "pipe") == 0) &&
5293 (strcmp(tokens[2], "profile") == 0)) {
5294 snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
5299 if (strcmp(tokens[0], "tap") == 0) {
5300 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
5304 if (strcmp(tokens[0], "kni") == 0) {
5305 snprintf(out, out_size, "\n%s\n", cmd_kni_help);
5309 if (strcmp(tokens[0], "cryptodev") == 0) {
5310 snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
5314 if ((n_tokens == 4) &&
5315 (strcmp(tokens[0], "port") == 0) &&
5316 (strcmp(tokens[1], "in") == 0) &&
5317 (strcmp(tokens[2], "action") == 0) &&
5318 (strcmp(tokens[3], "profile") == 0)) {
5319 snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
5323 if ((n_tokens == 3) &&
5324 (strcmp(tokens[0], "table") == 0) &&
5325 (strcmp(tokens[1], "action") == 0) &&
5326 (strcmp(tokens[2], "profile") == 0)) {
5327 snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
5331 if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
5332 snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
5336 if ((strcmp(tokens[0], "pipeline") == 0) &&
5337 (strcmp(tokens[1], "port") == 0)) {
5338 if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
5339 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
5343 if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
5344 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
5348 if ((n_tokens == 4) &&
5349 (strcmp(tokens[2], "in") == 0) &&
5350 (strcmp(tokens[3], "table") == 0)) {
5351 snprintf(out, out_size, "\n%s\n",
5352 cmd_pipeline_port_in_table_help);
5356 if ((n_tokens == 4) &&
5357 (strcmp(tokens[2], "in") == 0) &&
5358 (strcmp(tokens[3], "stats") == 0)) {
5359 snprintf(out, out_size, "\n%s\n",
5360 cmd_pipeline_port_in_stats_help);
5364 if ((n_tokens == 4) &&
5365 (strcmp(tokens[2], "in") == 0) &&
5366 (strcmp(tokens[3], "enable") == 0)) {
5367 snprintf(out, out_size, "\n%s\n",
5368 cmd_pipeline_port_in_enable_help);
5372 if ((n_tokens == 4) &&
5373 (strcmp(tokens[2], "in") == 0) &&
5374 (strcmp(tokens[3], "disable") == 0)) {
5375 snprintf(out, out_size, "\n%s\n",
5376 cmd_pipeline_port_in_disable_help);
5380 if ((n_tokens == 4) &&
5381 (strcmp(tokens[2], "out") == 0) &&
5382 (strcmp(tokens[3], "stats") == 0)) {
5383 snprintf(out, out_size, "\n%s\n",
5384 cmd_pipeline_port_out_stats_help);
5389 if ((strcmp(tokens[0], "pipeline") == 0) &&
5390 (strcmp(tokens[1], "table") == 0)) {
5391 if (n_tokens == 2) {
5392 snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
5396 if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
5397 snprintf(out, out_size, "\n%s\n",
5398 cmd_pipeline_table_stats_help);
5402 if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
5403 snprintf(out, out_size, "\n%s\n",
5404 cmd_pipeline_table_dscp_help);
5408 if ((n_tokens == 4) &&
5409 (strcmp(tokens[2], "rule") == 0) &&
5410 (strcmp(tokens[3], "add") == 0)) {
5411 snprintf(out, out_size, "\n%s\n",
5412 cmd_pipeline_table_rule_add_help);
5416 if ((n_tokens == 5) &&
5417 (strcmp(tokens[2], "rule") == 0) &&
5418 (strcmp(tokens[3], "add") == 0) &&
5419 (strcmp(tokens[4], "default") == 0)) {
5420 snprintf(out, out_size, "\n%s\n",
5421 cmd_pipeline_table_rule_add_default_help);
5425 if ((n_tokens == 5) &&
5426 (strcmp(tokens[2], "rule") == 0) &&
5427 (strcmp(tokens[3], "add") == 0) &&
5428 (strcmp(tokens[4], "bulk") == 0)) {
5429 snprintf(out, out_size, "\n%s\n",
5430 cmd_pipeline_table_rule_add_bulk_help);
5434 if ((n_tokens == 4) &&
5435 (strcmp(tokens[2], "rule") == 0) &&
5436 (strcmp(tokens[3], "delete") == 0)) {
5437 snprintf(out, out_size, "\n%s\n",
5438 cmd_pipeline_table_rule_delete_help);
5442 if ((n_tokens == 5) &&
5443 (strcmp(tokens[2], "rule") == 0) &&
5444 (strcmp(tokens[3], "delete") == 0) &&
5445 (strcmp(tokens[4], "default") == 0)) {
5446 snprintf(out, out_size, "\n%s\n",
5447 cmd_pipeline_table_rule_delete_default_help);
5451 if ((n_tokens == 5) &&
5452 (strcmp(tokens[2], "rule") == 0) &&
5453 (strcmp(tokens[3], "stats") == 0) &&
5454 (strcmp(tokens[4], "read") == 0)) {
5455 snprintf(out, out_size, "\n%s\n",
5456 cmd_pipeline_table_rule_stats_read_help);
5460 if ((n_tokens == 5) &&
5461 (strcmp(tokens[2], "meter") == 0) &&
5462 (strcmp(tokens[3], "profile") == 0) &&
5463 (strcmp(tokens[4], "add") == 0)) {
5464 snprintf(out, out_size, "\n%s\n",
5465 cmd_pipeline_table_meter_profile_add_help);
5469 if ((n_tokens == 5) &&
5470 (strcmp(tokens[2], "meter") == 0) &&
5471 (strcmp(tokens[3], "profile") == 0) &&
5472 (strcmp(tokens[4], "delete") == 0)) {
5473 snprintf(out, out_size, "\n%s\n",
5474 cmd_pipeline_table_meter_profile_delete_help);
5478 if ((n_tokens == 5) &&
5479 (strcmp(tokens[2], "rule") == 0) &&
5480 (strcmp(tokens[3], "meter") == 0) &&
5481 (strcmp(tokens[4], "read") == 0)) {
5482 snprintf(out, out_size, "\n%s\n",
5483 cmd_pipeline_table_rule_meter_read_help);
5487 if ((n_tokens == 5) &&
5488 (strcmp(tokens[2], "rule") == 0) &&
5489 (strcmp(tokens[3], "ttl") == 0) &&
5490 (strcmp(tokens[4], "read") == 0)) {
5491 snprintf(out, out_size, "\n%s\n",
5492 cmd_pipeline_table_rule_ttl_read_help);
5497 if ((n_tokens == 3) &&
5498 (strcmp(tokens[0], "thread") == 0) &&
5499 (strcmp(tokens[1], "pipeline") == 0)) {
5500 if (strcmp(tokens[2], "enable") == 0) {
5501 snprintf(out, out_size, "\n%s\n",
5502 cmd_thread_pipeline_enable_help);
5506 if (strcmp(tokens[2], "disable") == 0) {
5507 snprintf(out, out_size, "\n%s\n",
5508 cmd_thread_pipeline_disable_help);
5513 snprintf(out, out_size, "Invalid command\n");
5517 cli_process(char *in, char *out, size_t out_size)
5519 char *tokens[CMD_MAX_TOKENS];
5520 uint32_t n_tokens = RTE_DIM(tokens);
5526 status = parse_tokenize_string(in, tokens, &n_tokens);
5528 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
5535 if (strcmp(tokens[0], "help") == 0) {
5536 cmd_help(tokens, n_tokens, out, out_size);
5540 if (strcmp(tokens[0], "mempool") == 0) {
5541 cmd_mempool(tokens, n_tokens, out, out_size);
5545 if (strcmp(tokens[0], "link") == 0) {
5546 if (strcmp(tokens[1], "show") == 0) {
5547 cmd_link_show(tokens, n_tokens, out, out_size);
5551 cmd_link(tokens, n_tokens, out, out_size);
5555 if (strcmp(tokens[0], "swq") == 0) {
5556 cmd_swq(tokens, n_tokens, out, out_size);
5560 if (strcmp(tokens[0], "tmgr") == 0) {
5561 if ((n_tokens >= 3) &&
5562 (strcmp(tokens[1], "subport") == 0) &&
5563 (strcmp(tokens[2], "profile") == 0)) {
5564 cmd_tmgr_subport_profile(tokens, n_tokens,
5569 if ((n_tokens >= 3) &&
5570 (strcmp(tokens[1], "pipe") == 0) &&
5571 (strcmp(tokens[2], "profile") == 0)) {
5572 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
5576 if ((n_tokens >= 5) &&
5577 (strcmp(tokens[2], "subport") == 0) &&
5578 (strcmp(tokens[4], "profile") == 0)) {
5579 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
5583 if ((n_tokens >= 5) &&
5584 (strcmp(tokens[2], "subport") == 0) &&
5585 (strcmp(tokens[4], "pipe") == 0)) {
5586 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
5590 cmd_tmgr(tokens, n_tokens, out, out_size);
5594 if (strcmp(tokens[0], "tap") == 0) {
5595 cmd_tap(tokens, n_tokens, out, out_size);
5599 if (strcmp(tokens[0], "kni") == 0) {
5600 cmd_kni(tokens, n_tokens, out, out_size);
5604 if (strcmp(tokens[0], "cryptodev") == 0) {
5605 cmd_cryptodev(tokens, n_tokens, out, out_size);
5609 if (strcmp(tokens[0], "port") == 0) {
5610 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
5614 if (strcmp(tokens[0], "table") == 0) {
5615 cmd_table_action_profile(tokens, n_tokens, out, out_size);
5619 if (strcmp(tokens[0], "pipeline") == 0) {
5620 if ((n_tokens >= 3) &&
5621 (strcmp(tokens[2], "period") == 0)) {
5622 cmd_pipeline(tokens, n_tokens, out, out_size);
5626 if ((n_tokens >= 5) &&
5627 (strcmp(tokens[2], "port") == 0) &&
5628 (strcmp(tokens[3], "in") == 0) &&
5629 (strcmp(tokens[4], "bsz") == 0)) {
5630 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
5634 if ((n_tokens >= 5) &&
5635 (strcmp(tokens[2], "port") == 0) &&
5636 (strcmp(tokens[3], "out") == 0) &&
5637 (strcmp(tokens[4], "bsz") == 0)) {
5638 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
5642 if ((n_tokens >= 4) &&
5643 (strcmp(tokens[2], "table") == 0) &&
5644 (strcmp(tokens[3], "match") == 0)) {
5645 cmd_pipeline_table(tokens, n_tokens, out, out_size);
5649 if ((n_tokens >= 6) &&
5650 (strcmp(tokens[2], "port") == 0) &&
5651 (strcmp(tokens[3], "in") == 0) &&
5652 (strcmp(tokens[5], "table") == 0)) {
5653 cmd_pipeline_port_in_table(tokens, n_tokens,
5658 if ((n_tokens >= 6) &&
5659 (strcmp(tokens[2], "port") == 0) &&
5660 (strcmp(tokens[3], "in") == 0) &&
5661 (strcmp(tokens[5], "stats") == 0)) {
5662 cmd_pipeline_port_in_stats(tokens, n_tokens,
5667 if ((n_tokens >= 6) &&
5668 (strcmp(tokens[2], "port") == 0) &&
5669 (strcmp(tokens[3], "in") == 0) &&
5670 (strcmp(tokens[5], "enable") == 0)) {
5671 cmd_pipeline_port_in_enable(tokens, n_tokens,
5676 if ((n_tokens >= 6) &&
5677 (strcmp(tokens[2], "port") == 0) &&
5678 (strcmp(tokens[3], "in") == 0) &&
5679 (strcmp(tokens[5], "disable") == 0)) {
5680 cmd_pipeline_port_in_disable(tokens, n_tokens,
5685 if ((n_tokens >= 6) &&
5686 (strcmp(tokens[2], "port") == 0) &&
5687 (strcmp(tokens[3], "out") == 0) &&
5688 (strcmp(tokens[5], "stats") == 0)) {
5689 cmd_pipeline_port_out_stats(tokens, n_tokens,
5694 if ((n_tokens >= 5) &&
5695 (strcmp(tokens[2], "table") == 0) &&
5696 (strcmp(tokens[4], "stats") == 0)) {
5697 cmd_pipeline_table_stats(tokens, n_tokens,
5702 if ((n_tokens >= 7) &&
5703 (strcmp(tokens[2], "table") == 0) &&
5704 (strcmp(tokens[4], "rule") == 0) &&
5705 (strcmp(tokens[5], "add") == 0) &&
5706 (strcmp(tokens[6], "match") == 0)) {
5707 if ((n_tokens >= 8) &&
5708 (strcmp(tokens[7], "default") == 0)) {
5709 cmd_pipeline_table_rule_add_default(tokens,
5710 n_tokens, out, out_size);
5714 cmd_pipeline_table_rule_add(tokens, n_tokens,
5719 if ((n_tokens >= 7) &&
5720 (strcmp(tokens[2], "table") == 0) &&
5721 (strcmp(tokens[4], "rule") == 0) &&
5722 (strcmp(tokens[5], "add") == 0) &&
5723 (strcmp(tokens[6], "bulk") == 0)) {
5724 cmd_pipeline_table_rule_add_bulk(tokens,
5725 n_tokens, out, out_size);
5729 if ((n_tokens >= 7) &&
5730 (strcmp(tokens[2], "table") == 0) &&
5731 (strcmp(tokens[4], "rule") == 0) &&
5732 (strcmp(tokens[5], "delete") == 0) &&
5733 (strcmp(tokens[6], "match") == 0)) {
5734 if ((n_tokens >= 8) &&
5735 (strcmp(tokens[7], "default") == 0)) {
5736 cmd_pipeline_table_rule_delete_default(tokens,
5737 n_tokens, out, out_size);
5741 cmd_pipeline_table_rule_delete(tokens, n_tokens,
5746 if ((n_tokens >= 7) &&
5747 (strcmp(tokens[2], "table") == 0) &&
5748 (strcmp(tokens[4], "rule") == 0) &&
5749 (strcmp(tokens[5], "read") == 0) &&
5750 (strcmp(tokens[6], "stats") == 0)) {
5751 cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
5756 if ((n_tokens >= 8) &&
5757 (strcmp(tokens[2], "table") == 0) &&
5758 (strcmp(tokens[4], "meter") == 0) &&
5759 (strcmp(tokens[5], "profile") == 0) &&
5760 (strcmp(tokens[7], "add") == 0)) {
5761 cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
5766 if ((n_tokens >= 8) &&
5767 (strcmp(tokens[2], "table") == 0) &&
5768 (strcmp(tokens[4], "meter") == 0) &&
5769 (strcmp(tokens[5], "profile") == 0) &&
5770 (strcmp(tokens[7], "delete") == 0)) {
5771 cmd_pipeline_table_meter_profile_delete(tokens,
5772 n_tokens, out, out_size);
5776 if ((n_tokens >= 7) &&
5777 (strcmp(tokens[2], "table") == 0) &&
5778 (strcmp(tokens[4], "rule") == 0) &&
5779 (strcmp(tokens[5], "read") == 0) &&
5780 (strcmp(tokens[6], "meter") == 0)) {
5781 cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
5786 if ((n_tokens >= 5) &&
5787 (strcmp(tokens[2], "table") == 0) &&
5788 (strcmp(tokens[4], "dscp") == 0)) {
5789 cmd_pipeline_table_dscp(tokens, n_tokens,
5794 if ((n_tokens >= 7) &&
5795 (strcmp(tokens[2], "table") == 0) &&
5796 (strcmp(tokens[4], "rule") == 0) &&
5797 (strcmp(tokens[5], "read") == 0) &&
5798 (strcmp(tokens[6], "ttl") == 0)) {
5799 cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
5805 if (strcmp(tokens[0], "thread") == 0) {
5806 if ((n_tokens >= 5) &&
5807 (strcmp(tokens[4], "enable") == 0)) {
5808 cmd_thread_pipeline_enable(tokens, n_tokens,
5813 if ((n_tokens >= 5) &&
5814 (strcmp(tokens[4], "disable") == 0)) {
5815 cmd_thread_pipeline_disable(tokens, n_tokens,
5821 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
5825 cli_script_process(const char *file_name,
5826 size_t msg_in_len_max,
5827 size_t msg_out_len_max)
5829 char *msg_in = NULL, *msg_out = NULL;
5832 /* Check input arguments */
5833 if ((file_name == NULL) ||
5834 (strlen(file_name) == 0) ||
5835 (msg_in_len_max == 0) ||
5836 (msg_out_len_max == 0))
5839 msg_in = malloc(msg_in_len_max + 1);
5840 msg_out = malloc(msg_out_len_max + 1);
5841 if ((msg_in == NULL) ||
5842 (msg_out == NULL)) {
5848 /* Open input file */
5849 f = fopen(file_name, "r");
5858 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
5861 printf("%s", msg_in);
5868 if (strlen(msg_out))
5869 printf("%s", msg_out);
5880 cli_rule_file_process(const char *file_name,
5881 size_t line_len_max,
5882 struct table_rule_match *m,
5883 struct table_rule_action *a,
5885 uint32_t *line_number,
5891 uint32_t rule_id, line_id;
5894 /* Check input arguments */
5895 if ((file_name == NULL) ||
5896 (strlen(file_name) == 0) ||
5897 (line_len_max == 0)) {
5902 /* Memory allocation */
5903 line = malloc(line_len_max + 1);
5910 f = fopen(file_name, "r");
5918 for (line_id = 1, rule_id = 0; rule_id < *n_rules; line_id++) {
5919 char *tokens[CMD_MAX_TOKENS];
5920 uint32_t n_tokens, n_tokens_parsed, t0;
5922 /* Read next line from file. */
5923 if (fgets(line, line_len_max + 1, f) == NULL)
5927 if (is_comment(line))
5931 n_tokens = RTE_DIM(tokens);
5932 status = parse_tokenize_string(line, tokens, &n_tokens);
5944 n_tokens_parsed = parse_match(tokens + t0,
5949 if (n_tokens_parsed == 0) {
5953 t0 += n_tokens_parsed;
5956 n_tokens_parsed = parse_table_action(tokens + t0,
5961 if (n_tokens_parsed == 0) {
5965 t0 += n_tokens_parsed;
5967 /* Line completed. */
5968 if (t0 < n_tokens) {
5973 /* Increment rule count */
5984 *line_number = line_id;