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"
1040 cmd_table_action_profile(char **tokens,
1045 struct table_action_profile_params p;
1046 struct table_action_profile *ap;
1050 memset(&p, 0, sizeof(p));
1053 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1057 if (strcmp(tokens[1], "action") != 0) {
1058 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1062 if (strcmp(tokens[2], "profile") != 0) {
1063 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1069 if (strcmp(tokens[4], "ipv4") == 0)
1070 p.common.ip_version = 1;
1071 else if (strcmp(tokens[4], "ipv6") == 0)
1072 p.common.ip_version = 0;
1074 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1078 if (strcmp(tokens[5], "offset") != 0) {
1079 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1083 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
1084 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1088 if (strcmp(tokens[7], "fwd") != 0) {
1089 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1093 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1096 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
1097 if (n_tokens < t0 + 7) {
1098 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1102 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1103 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1107 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1108 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1112 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1113 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1117 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1118 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1119 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1123 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1124 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1128 if (parser_read_uint32(&p.lb.out_offset, tokens[t0 + 6]) != 0) {
1129 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1133 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1137 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
1138 if (n_tokens < t0 + 6) {
1139 snprintf(out, out_size, MSG_ARG_MISMATCH,
1140 "table action profile meter");
1144 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
1145 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1146 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
1147 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1149 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1154 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1155 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1159 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
1160 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1164 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1165 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1169 if (strcmp(tokens[t0 + 5], "none") == 0) {
1170 p.mtr.n_packets_enabled = 0;
1171 p.mtr.n_bytes_enabled = 0;
1172 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1173 p.mtr.n_packets_enabled = 1;
1174 p.mtr.n_bytes_enabled = 0;
1175 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1176 p.mtr.n_packets_enabled = 0;
1177 p.mtr.n_bytes_enabled = 1;
1178 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1179 p.mtr.n_packets_enabled = 1;
1180 p.mtr.n_bytes_enabled = 1;
1182 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1183 "none or pkts or bytes or both");
1187 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1191 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
1192 if (n_tokens < t0 + 5) {
1193 snprintf(out, out_size, MSG_ARG_MISMATCH,
1194 "table action profile tm");
1198 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1199 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1203 if (parser_read_uint32(&p.tm.n_subports_per_port,
1204 tokens[t0 + 2]) != 0) {
1205 snprintf(out, out_size, MSG_ARG_INVALID,
1206 "n_subports_per_port");
1210 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1211 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1215 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1216 tokens[t0 + 4]) != 0) {
1217 snprintf(out, out_size, MSG_ARG_INVALID,
1218 "n_pipes_per_subport");
1222 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1226 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1227 uint32_t n_extra_tokens = 0;
1229 if (n_tokens < t0 + 2) {
1230 snprintf(out, out_size, MSG_ARG_MISMATCH,
1231 "action profile encap");
1235 if (strcmp(tokens[t0 + 1], "ether") == 0)
1236 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1237 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1238 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1239 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1240 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1241 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1242 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1243 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1244 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1245 else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1246 if (n_tokens < t0 + 2 + 5) {
1247 snprintf(out, out_size, MSG_ARG_MISMATCH,
1248 "action profile encap vxlan");
1252 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1253 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1258 if (parser_read_uint32(&p.encap.vxlan.data_offset,
1259 tokens[t0 + 2 + 1]) != 0) {
1260 snprintf(out, out_size, MSG_ARG_INVALID,
1261 "vxlan: ether_offset");
1265 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1266 p.encap.vxlan.ip_version = 1;
1267 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1268 p.encap.vxlan.ip_version = 0;
1270 snprintf(out, out_size, MSG_ARG_INVALID,
1271 "vxlan: ipv4 or ipv6");
1275 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1276 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1281 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
1282 p.encap.vxlan.vlan = 1;
1283 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
1284 p.encap.vxlan.vlan = 0;
1286 snprintf(out, out_size, MSG_ARG_INVALID,
1287 "vxlan: on or off");
1291 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
1294 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1298 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1299 t0 += 2 + n_extra_tokens;
1302 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1303 if (n_tokens < t0 + 4) {
1304 snprintf(out, out_size, MSG_ARG_MISMATCH,
1305 "table action profile nat");
1309 if (strcmp(tokens[t0 + 1], "src") == 0)
1310 p.nat.source_nat = 1;
1311 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1312 p.nat.source_nat = 0;
1314 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1319 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1320 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1324 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1326 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1329 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1334 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1338 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1339 if (n_tokens < t0 + 4) {
1340 snprintf(out, out_size, MSG_ARG_MISMATCH,
1341 "table action profile ttl");
1345 if (strcmp(tokens[t0 + 1], "drop") == 0)
1347 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1350 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1355 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1356 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1360 if (strcmp(tokens[t0 + 3], "none") == 0)
1361 p.ttl.n_packets_enabled = 0;
1362 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1363 p.ttl.n_packets_enabled = 1;
1365 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1370 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1374 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1375 if (n_tokens < t0 + 2) {
1376 snprintf(out, out_size, MSG_ARG_MISMATCH,
1377 "table action profile stats");
1381 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1382 p.stats.n_packets_enabled = 1;
1383 p.stats.n_bytes_enabled = 0;
1384 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1385 p.stats.n_packets_enabled = 0;
1386 p.stats.n_bytes_enabled = 1;
1387 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1388 p.stats.n_packets_enabled = 1;
1389 p.stats.n_bytes_enabled = 1;
1391 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1392 "pkts or bytes or both");
1396 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1400 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1401 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1405 if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
1406 struct cryptodev *cryptodev;
1407 struct mempool *mempool;
1409 if (n_tokens < t0 + 9 ||
1410 strcmp(tokens[t0 + 1], "dev") ||
1411 strcmp(tokens[t0 + 3], "offset") ||
1412 strcmp(tokens[t0 + 5], "mempool_create") ||
1413 strcmp(tokens[t0 + 7], "mempool_init")) {
1414 snprintf(out, out_size, MSG_ARG_MISMATCH,
1415 "table action profile sym_crypto");
1419 cryptodev = cryptodev_find(tokens[t0 + 2]);
1420 if (cryptodev == NULL) {
1421 snprintf(out, out_size, MSG_ARG_INVALID,
1422 "table action profile sym_crypto");
1426 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
1428 if (parser_read_uint32(&p.sym_crypto.op_offset,
1429 tokens[t0 + 4]) != 0) {
1430 snprintf(out, out_size, MSG_ARG_INVALID,
1431 "table action profile sym_crypto");
1435 mempool = mempool_find(tokens[t0 + 6]);
1436 if (mempool == NULL) {
1437 snprintf(out, out_size, MSG_ARG_INVALID,
1438 "table action profile sym_crypto");
1441 p.sym_crypto.mp_create = mempool->m;
1443 mempool = mempool_find(tokens[t0 + 8]);
1444 if (mempool == NULL) {
1445 snprintf(out, out_size, MSG_ARG_INVALID,
1446 "table action profile sym_crypto");
1449 p.sym_crypto.mp_init = mempool->m;
1451 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
1456 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {
1457 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
1461 if ((t0 < n_tokens) && (strcmp(tokens[t0], "decap") == 0)) {
1462 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1466 if (t0 < n_tokens) {
1467 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1471 ap = table_action_profile_create(name, &p);
1473 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1478 static const char cmd_pipeline_help[] =
1479 "pipeline <pipeline_name>\n"
1480 " period <timer_period_ms>\n"
1481 " offset_port_id <offset_port_id>\n"
1485 cmd_pipeline(char **tokens,
1490 struct pipeline_params p;
1492 struct pipeline *pipeline;
1494 if (n_tokens != 8) {
1495 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1501 if (strcmp(tokens[2], "period") != 0) {
1502 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1506 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1507 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1511 if (strcmp(tokens[4], "offset_port_id") != 0) {
1512 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1516 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1517 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1521 if (strcmp(tokens[6], "cpu") != 0) {
1522 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1526 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1527 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1531 pipeline = pipeline_create(name, &p);
1532 if (pipeline == NULL) {
1533 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1538 static const char cmd_pipeline_port_in_help[] =
1539 "pipeline <pipeline_name> port in\n"
1540 " bsz <burst_size>\n"
1541 " link <link_name> rxq <queue_id>\n"
1542 " | swq <swq_name>\n"
1543 " | tmgr <tmgr_name>\n"
1544 " | tap <tap_name> mempool <mempool_name> mtu <mtu>\n"
1545 " | kni <kni_name>\n"
1546 " | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>\n"
1547 " | cryptodev <cryptodev_name> rxq <queue_id>\n"
1548 " [action <port_in_action_profile_name>]\n"
1552 cmd_pipeline_port_in(char **tokens,
1557 struct port_in_params p;
1558 char *pipeline_name;
1560 int enabled, status;
1563 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1567 pipeline_name = tokens[1];
1569 if (strcmp(tokens[2], "port") != 0) {
1570 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1574 if (strcmp(tokens[3], "in") != 0) {
1575 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1579 if (strcmp(tokens[4], "bsz") != 0) {
1580 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1584 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1585 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1591 if (strcmp(tokens[t0], "link") == 0) {
1592 if (n_tokens < t0 + 4) {
1593 snprintf(out, out_size, MSG_ARG_MISMATCH,
1594 "pipeline port in link");
1598 p.type = PORT_IN_RXQ;
1600 p.dev_name = tokens[t0 + 1];
1602 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1603 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1607 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1608 snprintf(out, out_size, MSG_ARG_INVALID,
1613 } else if (strcmp(tokens[t0], "swq") == 0) {
1614 if (n_tokens < t0 + 2) {
1615 snprintf(out, out_size, MSG_ARG_MISMATCH,
1616 "pipeline port in swq");
1620 p.type = PORT_IN_SWQ;
1622 p.dev_name = tokens[t0 + 1];
1625 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1626 if (n_tokens < t0 + 2) {
1627 snprintf(out, out_size, MSG_ARG_MISMATCH,
1628 "pipeline port in tmgr");
1632 p.type = PORT_IN_TMGR;
1634 p.dev_name = tokens[t0 + 1];
1637 } else if (strcmp(tokens[t0], "tap") == 0) {
1638 if (n_tokens < t0 + 6) {
1639 snprintf(out, out_size, MSG_ARG_MISMATCH,
1640 "pipeline port in tap");
1644 p.type = PORT_IN_TAP;
1646 p.dev_name = tokens[t0 + 1];
1648 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1649 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1654 p.tap.mempool_name = tokens[t0 + 3];
1656 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1657 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1662 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1663 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1668 } else if (strcmp(tokens[t0], "kni") == 0) {
1669 if (n_tokens < t0 + 2) {
1670 snprintf(out, out_size, MSG_ARG_MISMATCH,
1671 "pipeline port in kni");
1675 p.type = PORT_IN_KNI;
1677 p.dev_name = tokens[t0 + 1];
1680 } else if (strcmp(tokens[t0], "source") == 0) {
1681 if (n_tokens < t0 + 6) {
1682 snprintf(out, out_size, MSG_ARG_MISMATCH,
1683 "pipeline port in source");
1687 p.type = PORT_IN_SOURCE;
1691 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1692 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1697 p.source.mempool_name = tokens[t0 + 2];
1699 if (strcmp(tokens[t0 + 3], "file") != 0) {
1700 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1705 p.source.file_name = tokens[t0 + 4];
1707 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1708 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1713 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1714 snprintf(out, out_size, MSG_ARG_INVALID,
1720 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
1721 if (n_tokens < t0 + 3) {
1722 snprintf(out, out_size, MSG_ARG_MISMATCH,
1723 "pipeline port in cryptodev");
1727 p.type = PORT_IN_CRYPTODEV;
1729 p.dev_name = tokens[t0 + 1];
1730 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1731 snprintf(out, out_size, MSG_ARG_INVALID,
1736 p.cryptodev.arg_callback = NULL;
1737 p.cryptodev.f_callback = NULL;
1741 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1745 p.action_profile_name = NULL;
1746 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1747 if (n_tokens < t0 + 2) {
1748 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1752 p.action_profile_name = tokens[t0 + 1];
1758 if ((n_tokens > t0) &&
1759 (strcmp(tokens[t0], "disabled") == 0)) {
1765 if (n_tokens != t0) {
1766 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1770 status = pipeline_port_in_create(pipeline_name,
1773 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1778 static const char cmd_pipeline_port_out_help[] =
1779 "pipeline <pipeline_name> port out\n"
1780 " bsz <burst_size>\n"
1781 " link <link_name> txq <txq_id>\n"
1782 " | swq <swq_name>\n"
1783 " | tmgr <tmgr_name>\n"
1784 " | tap <tap_name>\n"
1785 " | kni <kni_name>\n"
1786 " | sink [file <file_name> pkts <max_n_pkts>]\n"
1787 " | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>\n";
1790 cmd_pipeline_port_out(char **tokens,
1795 struct port_out_params p;
1796 char *pipeline_name;
1799 memset(&p, 0, sizeof(p));
1802 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1806 pipeline_name = tokens[1];
1808 if (strcmp(tokens[2], "port") != 0) {
1809 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1813 if (strcmp(tokens[3], "out") != 0) {
1814 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1818 if (strcmp(tokens[4], "bsz") != 0) {
1819 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1823 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1824 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1828 if (strcmp(tokens[6], "link") == 0) {
1829 if (n_tokens != 10) {
1830 snprintf(out, out_size, MSG_ARG_MISMATCH,
1831 "pipeline port out link");
1835 p.type = PORT_OUT_TXQ;
1837 p.dev_name = tokens[7];
1839 if (strcmp(tokens[8], "txq") != 0) {
1840 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1844 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1845 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1848 } else if (strcmp(tokens[6], "swq") == 0) {
1849 if (n_tokens != 8) {
1850 snprintf(out, out_size, MSG_ARG_MISMATCH,
1851 "pipeline port out swq");
1855 p.type = PORT_OUT_SWQ;
1857 p.dev_name = tokens[7];
1858 } else if (strcmp(tokens[6], "tmgr") == 0) {
1859 if (n_tokens != 8) {
1860 snprintf(out, out_size, MSG_ARG_MISMATCH,
1861 "pipeline port out tmgr");
1865 p.type = PORT_OUT_TMGR;
1867 p.dev_name = tokens[7];
1868 } else if (strcmp(tokens[6], "tap") == 0) {
1869 if (n_tokens != 8) {
1870 snprintf(out, out_size, MSG_ARG_MISMATCH,
1871 "pipeline port out tap");
1875 p.type = PORT_OUT_TAP;
1877 p.dev_name = tokens[7];
1878 } else if (strcmp(tokens[6], "kni") == 0) {
1879 if (n_tokens != 8) {
1880 snprintf(out, out_size, MSG_ARG_MISMATCH,
1881 "pipeline port out kni");
1885 p.type = PORT_OUT_KNI;
1887 p.dev_name = tokens[7];
1888 } else if (strcmp(tokens[6], "sink") == 0) {
1889 if ((n_tokens != 7) && (n_tokens != 11)) {
1890 snprintf(out, out_size, MSG_ARG_MISMATCH,
1891 "pipeline port out sink");
1895 p.type = PORT_OUT_SINK;
1899 if (n_tokens == 7) {
1900 p.sink.file_name = NULL;
1901 p.sink.max_n_pkts = 0;
1903 if (strcmp(tokens[7], "file") != 0) {
1904 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1909 p.sink.file_name = tokens[8];
1911 if (strcmp(tokens[9], "pkts") != 0) {
1912 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1916 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1917 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1922 } else if (strcmp(tokens[6], "cryptodev") == 0) {
1923 if (n_tokens != 12) {
1924 snprintf(out, out_size, MSG_ARG_MISMATCH,
1925 "pipeline port out cryptodev");
1929 p.type = PORT_OUT_CRYPTODEV;
1931 p.dev_name = tokens[7];
1933 if (strcmp(tokens[8], "txq")) {
1934 snprintf(out, out_size, MSG_ARG_MISMATCH,
1935 "pipeline port out cryptodev");
1939 if (parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
1941 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1945 if (strcmp(tokens[10], "offset")) {
1946 snprintf(out, out_size, MSG_ARG_MISMATCH,
1947 "pipeline port out cryptodev");
1951 if (parser_read_uint32(&p.cryptodev.op_offset, tokens[11])
1953 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1957 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1961 status = pipeline_port_out_create(pipeline_name, &p);
1963 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1968 static const char cmd_pipeline_table_help[] =
1969 "pipeline <pipeline_name> table\n"
1973 " offset <ip_header_offset>\n"
1976 " offset <key_offset>\n"
1981 " mask <key_mask>\n"
1982 " offset <key_offset>\n"
1983 " buckets <n_buckets>\n"
1987 " offset <ip_header_offset>\n"
1990 " [action <table_action_profile_name>]\n";
1993 cmd_pipeline_table(char **tokens,
1998 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
1999 struct table_params p;
2000 char *pipeline_name;
2005 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2009 pipeline_name = tokens[1];
2011 if (strcmp(tokens[2], "table") != 0) {
2012 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2016 if (strcmp(tokens[3], "match") != 0) {
2017 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2022 if (strcmp(tokens[t0], "acl") == 0) {
2023 if (n_tokens < t0 + 6) {
2024 snprintf(out, out_size, MSG_ARG_MISMATCH,
2025 "pipeline table acl");
2029 p.match_type = TABLE_ACL;
2031 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2032 p.match.acl.ip_version = 1;
2033 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2034 p.match.acl.ip_version = 0;
2036 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2041 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2042 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2046 if (parser_read_uint32(&p.match.acl.ip_header_offset,
2047 tokens[t0 + 3]) != 0) {
2048 snprintf(out, out_size, MSG_ARG_INVALID,
2049 "ip_header_offset");
2053 if (strcmp(tokens[t0 + 4], "size") != 0) {
2054 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2058 if (parser_read_uint32(&p.match.acl.n_rules,
2059 tokens[t0 + 5]) != 0) {
2060 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2065 } else if (strcmp(tokens[t0], "array") == 0) {
2066 if (n_tokens < t0 + 5) {
2067 snprintf(out, out_size, MSG_ARG_MISMATCH,
2068 "pipeline table array");
2072 p.match_type = TABLE_ARRAY;
2074 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2075 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2079 if (parser_read_uint32(&p.match.array.key_offset,
2080 tokens[t0 + 2]) != 0) {
2081 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2085 if (strcmp(tokens[t0 + 3], "size") != 0) {
2086 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2090 if (parser_read_uint32(&p.match.array.n_keys,
2091 tokens[t0 + 4]) != 0) {
2092 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2097 } else if (strcmp(tokens[t0], "hash") == 0) {
2098 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2100 if (n_tokens < t0 + 12) {
2101 snprintf(out, out_size, MSG_ARG_MISMATCH,
2102 "pipeline table hash");
2106 p.match_type = TABLE_HASH;
2108 if (strcmp(tokens[t0 + 1], "ext") == 0)
2109 p.match.hash.extendable_bucket = 1;
2110 else if (strcmp(tokens[t0 + 1], "lru") == 0)
2111 p.match.hash.extendable_bucket = 0;
2113 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2118 if (strcmp(tokens[t0 + 2], "key") != 0) {
2119 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2123 if ((parser_read_uint32(&p.match.hash.key_size,
2124 tokens[t0 + 3]) != 0) ||
2125 (p.match.hash.key_size == 0) ||
2126 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
2127 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2131 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2132 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2136 if ((parse_hex_string(tokens[t0 + 5],
2137 key_mask, &key_mask_size) != 0) ||
2138 (key_mask_size != p.match.hash.key_size)) {
2139 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2142 p.match.hash.key_mask = key_mask;
2144 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2145 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2149 if (parser_read_uint32(&p.match.hash.key_offset,
2150 tokens[t0 + 7]) != 0) {
2151 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2155 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2156 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2160 if (parser_read_uint32(&p.match.hash.n_buckets,
2161 tokens[t0 + 9]) != 0) {
2162 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2166 if (strcmp(tokens[t0 + 10], "size") != 0) {
2167 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2171 if (parser_read_uint32(&p.match.hash.n_keys,
2172 tokens[t0 + 11]) != 0) {
2173 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2178 } else if (strcmp(tokens[t0], "lpm") == 0) {
2179 if (n_tokens < t0 + 6) {
2180 snprintf(out, out_size, MSG_ARG_MISMATCH,
2181 "pipeline table lpm");
2185 p.match_type = TABLE_LPM;
2187 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2188 p.match.lpm.key_size = 4;
2189 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2190 p.match.lpm.key_size = 16;
2192 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2197 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2198 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2202 if (parser_read_uint32(&p.match.lpm.key_offset,
2203 tokens[t0 + 3]) != 0) {
2204 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2208 if (strcmp(tokens[t0 + 4], "size") != 0) {
2209 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2213 if (parser_read_uint32(&p.match.lpm.n_rules,
2214 tokens[t0 + 5]) != 0) {
2215 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2220 } else if (strcmp(tokens[t0], "stub") == 0) {
2221 p.match_type = TABLE_STUB;
2225 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2229 p.action_profile_name = NULL;
2230 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
2231 if (n_tokens < t0 + 2) {
2232 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2236 p.action_profile_name = tokens[t0 + 1];
2241 if (n_tokens > t0) {
2242 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2246 status = pipeline_table_create(pipeline_name, &p);
2248 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2253 static const char cmd_pipeline_port_in_table_help[] =
2254 "pipeline <pipeline_name> port in <port_id> table <table_id>\n";
2257 cmd_pipeline_port_in_table(char **tokens,
2262 char *pipeline_name;
2263 uint32_t port_id, table_id;
2266 if (n_tokens != 7) {
2267 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2271 pipeline_name = tokens[1];
2273 if (strcmp(tokens[2], "port") != 0) {
2274 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2278 if (strcmp(tokens[3], "in") != 0) {
2279 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2283 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2284 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2288 if (strcmp(tokens[5], "table") != 0) {
2289 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2293 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
2294 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2298 status = pipeline_port_in_connect_to_table(pipeline_name,
2302 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2308 static const char cmd_pipeline_port_in_stats_help[] =
2309 "pipeline <pipeline_name> port in <port_id> stats read [clear]\n";
2311 #define MSG_PIPELINE_PORT_IN_STATS \
2312 "Pkts in: %" PRIu64 "\n" \
2313 "Pkts dropped by AH: %" PRIu64 "\n" \
2314 "Pkts dropped by other: %" PRIu64 "\n"
2317 cmd_pipeline_port_in_stats(char **tokens,
2322 struct rte_pipeline_port_in_stats stats;
2323 char *pipeline_name;
2327 if ((n_tokens != 7) && (n_tokens != 8)) {
2328 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2332 pipeline_name = tokens[1];
2334 if (strcmp(tokens[2], "port") != 0) {
2335 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2339 if (strcmp(tokens[3], "in") != 0) {
2340 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2344 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2345 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2349 if (strcmp(tokens[5], "stats") != 0) {
2350 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2354 if (strcmp(tokens[6], "read") != 0) {
2355 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2360 if (n_tokens == 8) {
2361 if (strcmp(tokens[7], "clear") != 0) {
2362 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2369 status = pipeline_port_in_stats_read(pipeline_name,
2374 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2378 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2379 stats.stats.n_pkts_in,
2380 stats.n_pkts_dropped_by_ah,
2381 stats.stats.n_pkts_drop);
2385 static const char cmd_pipeline_port_in_enable_help[] =
2386 "pipeline <pipeline_name> port in <port_id> enable\n";
2389 cmd_pipeline_port_in_enable(char **tokens,
2394 char *pipeline_name;
2398 if (n_tokens != 6) {
2399 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2403 pipeline_name = tokens[1];
2405 if (strcmp(tokens[2], "port") != 0) {
2406 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2410 if (strcmp(tokens[3], "in") != 0) {
2411 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2415 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2416 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2420 if (strcmp(tokens[5], "enable") != 0) {
2421 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2425 status = pipeline_port_in_enable(pipeline_name, port_id);
2427 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2433 static const char cmd_pipeline_port_in_disable_help[] =
2434 "pipeline <pipeline_name> port in <port_id> disable\n";
2437 cmd_pipeline_port_in_disable(char **tokens,
2442 char *pipeline_name;
2446 if (n_tokens != 6) {
2447 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2451 pipeline_name = tokens[1];
2453 if (strcmp(tokens[2], "port") != 0) {
2454 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2458 if (strcmp(tokens[3], "in") != 0) {
2459 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2463 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2464 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2468 if (strcmp(tokens[5], "disable") != 0) {
2469 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2473 status = pipeline_port_in_disable(pipeline_name, port_id);
2475 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2481 static const char cmd_pipeline_port_out_stats_help[] =
2482 "pipeline <pipeline_name> port out <port_id> stats read [clear]\n";
2484 #define MSG_PIPELINE_PORT_OUT_STATS \
2485 "Pkts in: %" PRIu64 "\n" \
2486 "Pkts dropped by AH: %" PRIu64 "\n" \
2487 "Pkts dropped by other: %" PRIu64 "\n"
2490 cmd_pipeline_port_out_stats(char **tokens,
2495 struct rte_pipeline_port_out_stats stats;
2496 char *pipeline_name;
2500 if ((n_tokens != 7) && (n_tokens != 8)) {
2501 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2505 pipeline_name = tokens[1];
2507 if (strcmp(tokens[2], "port") != 0) {
2508 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2512 if (strcmp(tokens[3], "out") != 0) {
2513 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2517 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2518 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2522 if (strcmp(tokens[5], "stats") != 0) {
2523 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2527 if (strcmp(tokens[6], "read") != 0) {
2528 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2533 if (n_tokens == 8) {
2534 if (strcmp(tokens[7], "clear") != 0) {
2535 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2542 status = pipeline_port_out_stats_read(pipeline_name,
2547 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2551 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2552 stats.stats.n_pkts_in,
2553 stats.n_pkts_dropped_by_ah,
2554 stats.stats.n_pkts_drop);
2558 static const char cmd_pipeline_table_stats_help[] =
2559 "pipeline <pipeline_name> table <table_id> stats read [clear]\n";
2561 #define MSG_PIPELINE_TABLE_STATS \
2562 "Pkts in: %" PRIu64 "\n" \
2563 "Pkts in with lookup miss: %" PRIu64 "\n" \
2564 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2565 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2566 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2567 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2570 cmd_pipeline_table_stats(char **tokens,
2575 struct rte_pipeline_table_stats stats;
2576 char *pipeline_name;
2580 if ((n_tokens != 6) && (n_tokens != 7)) {
2581 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2585 pipeline_name = tokens[1];
2587 if (strcmp(tokens[2], "table") != 0) {
2588 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2592 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2593 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2597 if (strcmp(tokens[4], "stats") != 0) {
2598 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2602 if (strcmp(tokens[5], "read") != 0) {
2603 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2608 if (n_tokens == 7) {
2609 if (strcmp(tokens[6], "clear") != 0) {
2610 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2617 status = pipeline_table_stats_read(pipeline_name,
2622 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2626 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2627 stats.stats.n_pkts_in,
2628 stats.stats.n_pkts_lookup_miss,
2629 stats.n_pkts_dropped_by_lkp_hit_ah,
2630 stats.n_pkts_dropped_lkp_hit,
2631 stats.n_pkts_dropped_by_lkp_miss_ah,
2632 stats.n_pkts_dropped_lkp_miss);
2640 * priority <priority>
2641 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2642 * <sp0> <sp1> <dp0> <dp1> <proto>
2646 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2647 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2648 * | ipv4_addr <addr>
2649 * | ipv6_addr <addr>
2650 * | qinq <svlan> <cvlan>
2652 * ipv4 | ipv6 <addr> <depth>
2654 struct pkt_key_qinq {
2655 uint16_t ethertype_svlan;
2657 uint16_t ethertype_cvlan;
2659 } __attribute__((__packed__));
2661 struct pkt_key_ipv4_5tuple {
2662 uint8_t time_to_live;
2664 uint16_t hdr_checksum;
2669 } __attribute__((__packed__));
2671 struct pkt_key_ipv6_5tuple {
2672 uint16_t payload_length;
2679 } __attribute__((__packed__));
2681 struct pkt_key_ipv4_addr {
2683 } __attribute__((__packed__));
2685 struct pkt_key_ipv6_addr {
2687 } __attribute__((__packed__));
2690 parse_match(char **tokens,
2694 struct table_rule_match *m)
2696 memset(m, 0, sizeof(*m));
2701 if (strcmp(tokens[0], "match") != 0) {
2702 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2706 if (strcmp(tokens[1], "acl") == 0) {
2707 if (n_tokens < 14) {
2708 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2712 m->match_type = TABLE_ACL;
2714 if (strcmp(tokens[2], "priority") != 0) {
2715 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2719 if (parser_read_uint32(&m->match.acl.priority,
2721 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2725 if (strcmp(tokens[4], "ipv4") == 0) {
2726 struct in_addr saddr, daddr;
2728 m->match.acl.ip_version = 1;
2730 if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2731 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2734 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2736 if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2737 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2740 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2741 } else if (strcmp(tokens[4], "ipv6") == 0) {
2742 struct in6_addr saddr, daddr;
2744 m->match.acl.ip_version = 0;
2746 if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2747 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2750 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2752 if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2753 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2756 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2758 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2763 if (parser_read_uint32(&m->match.acl.sa_depth,
2765 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2769 if (parser_read_uint32(&m->match.acl.da_depth,
2771 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2775 if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2776 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2780 if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2781 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2785 if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2786 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2790 if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2791 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2795 if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2796 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2800 m->match.acl.proto_mask = 0xff;
2805 if (strcmp(tokens[1], "array") == 0) {
2807 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2811 m->match_type = TABLE_ARRAY;
2813 if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2814 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2821 if (strcmp(tokens[1], "hash") == 0) {
2823 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2827 m->match_type = TABLE_HASH;
2829 if (strcmp(tokens[2], "raw") == 0) {
2830 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2833 snprintf(out, out_size, MSG_ARG_MISMATCH,
2838 if (parse_hex_string(tokens[3],
2839 m->match.hash.key, &key_size) != 0) {
2840 snprintf(out, out_size, MSG_ARG_INVALID, "key");
2847 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2848 struct pkt_key_ipv4_5tuple *ipv4 =
2849 (struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2850 struct in_addr saddr, daddr;
2855 snprintf(out, out_size, MSG_ARG_MISMATCH,
2860 if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2861 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2865 if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2866 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2870 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2871 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2875 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2876 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2880 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2881 snprintf(out, out_size, MSG_ARG_INVALID,
2886 ipv4->sa = saddr.s_addr;
2887 ipv4->da = daddr.s_addr;
2888 ipv4->sp = rte_cpu_to_be_16(sp);
2889 ipv4->dp = rte_cpu_to_be_16(dp);
2890 ipv4->proto = proto;
2893 } /* hash ipv4_5tuple */
2895 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2896 struct pkt_key_ipv6_5tuple *ipv6 =
2897 (struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2898 struct in6_addr saddr, daddr;
2903 snprintf(out, out_size, MSG_ARG_MISMATCH,
2908 if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2909 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2913 if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2914 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2918 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2919 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2923 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2924 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2928 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2929 snprintf(out, out_size, MSG_ARG_INVALID,
2934 memcpy(ipv6->sa, saddr.s6_addr, 16);
2935 memcpy(ipv6->da, daddr.s6_addr, 16);
2936 ipv6->sp = rte_cpu_to_be_16(sp);
2937 ipv6->dp = rte_cpu_to_be_16(dp);
2938 ipv6->proto = proto;
2941 } /* hash ipv6_5tuple */
2943 if (strcmp(tokens[2], "ipv4_addr") == 0) {
2944 struct pkt_key_ipv4_addr *ipv4_addr =
2945 (struct pkt_key_ipv4_addr *) m->match.hash.key;
2946 struct in_addr addr;
2949 snprintf(out, out_size, MSG_ARG_MISMATCH,
2954 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2955 snprintf(out, out_size, MSG_ARG_INVALID,
2960 ipv4_addr->addr = addr.s_addr;
2963 } /* hash ipv4_addr */
2965 if (strcmp(tokens[2], "ipv6_addr") == 0) {
2966 struct pkt_key_ipv6_addr *ipv6_addr =
2967 (struct pkt_key_ipv6_addr *) m->match.hash.key;
2968 struct in6_addr addr;
2971 snprintf(out, out_size, MSG_ARG_MISMATCH,
2976 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2977 snprintf(out, out_size, MSG_ARG_INVALID,
2982 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
2985 } /* hash ipv6_5tuple */
2987 if (strcmp(tokens[2], "qinq") == 0) {
2988 struct pkt_key_qinq *qinq =
2989 (struct pkt_key_qinq *) m->match.hash.key;
2990 uint16_t svlan, cvlan;
2993 snprintf(out, out_size, MSG_ARG_MISMATCH,
2998 if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
3000 snprintf(out, out_size, MSG_ARG_INVALID,
3005 if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3007 snprintf(out, out_size, MSG_ARG_INVALID,
3012 qinq->svlan = rte_cpu_to_be_16(svlan);
3013 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3018 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3022 if (strcmp(tokens[1], "lpm") == 0) {
3024 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3028 m->match_type = TABLE_LPM;
3030 if (strcmp(tokens[2], "ipv4") == 0) {
3031 struct in_addr addr;
3033 m->match.lpm.ip_version = 1;
3035 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
3036 snprintf(out, out_size, MSG_ARG_INVALID,
3041 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3042 } else if (strcmp(tokens[2], "ipv6") == 0) {
3043 struct in6_addr addr;
3045 m->match.lpm.ip_version = 0;
3047 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
3048 snprintf(out, out_size, MSG_ARG_INVALID,
3053 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3055 snprintf(out, out_size, MSG_ARG_MISMATCH,
3060 if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3061 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3068 snprintf(out, out_size, MSG_ARG_MISMATCH,
3069 "acl or array or hash or lpm");
3081 * | table <table_id>
3082 * [balance <out0> ... <out7>]
3084 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3085 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3086 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3087 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3088 * [tm subport <subport_id> pipe <pipe_id>]
3091 * | vlan <da> <sa> <pcp> <dei> <vid>
3092 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3093 * | mpls unicast | multicast
3095 * label0 <label> <tc> <ttl>
3096 * [label1 <label> <tc> <ttl>
3097 * [label2 <label> <tc> <ttl>
3098 * [label3 <label> <tc> <ttl>]]]
3099 * | pppoe <da> <sa> <session_id>
3100 * | vxlan ether <da> <sa>
3101 * [vlan <pcp> <dei> <vid>]
3102 * ipv4 <sa> <da> <dscp> <ttl>
3103 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3106 * [nat ipv4 | ipv6 <addr> <port>]
3114 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3116 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3117 * auth_algo <algo> auth_key <key> digest_size <size>
3119 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3120 * digest_size <size>
3121 * data_offset <data_offset>]
3126 * <pa> ::= g | y | r | drop
3129 parse_table_action_fwd(char **tokens,
3131 struct table_rule_action *a)
3133 if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
3139 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3140 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3141 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3145 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3148 if ((n_tokens < 2) ||
3149 parser_read_uint32(&id, tokens[1]))
3152 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3154 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3158 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3159 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3160 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3164 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3167 if ((n_tokens < 2) ||
3168 parser_read_uint32(&id, tokens[1]))
3171 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3173 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3181 parse_table_action_balance(char **tokens,
3183 struct table_rule_action *a)
3187 if ((n_tokens == 0) || (strcmp(tokens[0], "balance") != 0))
3193 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3196 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3197 if (parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3200 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3201 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3206 parse_policer_action(char *token, enum rte_table_action_policer *a)
3208 if (strcmp(token, "g") == 0) {
3209 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3213 if (strcmp(token, "y") == 0) {
3214 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3218 if (strcmp(token, "r") == 0) {
3219 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3223 if (strcmp(token, "drop") == 0) {
3224 *a = RTE_TABLE_ACTION_POLICER_DROP;
3232 parse_table_action_meter_tc(char **tokens,
3234 struct rte_table_action_mtr_tc_params *mtr)
3236 if ((n_tokens < 9) ||
3237 strcmp(tokens[0], "meter") ||
3238 parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3239 strcmp(tokens[2], "policer") ||
3240 strcmp(tokens[3], "g") ||
3241 parse_policer_action(tokens[4], &mtr->policer[e_RTE_METER_GREEN]) ||
3242 strcmp(tokens[5], "y") ||
3243 parse_policer_action(tokens[6], &mtr->policer[e_RTE_METER_YELLOW]) ||
3244 strcmp(tokens[7], "r") ||
3245 parse_policer_action(tokens[8], &mtr->policer[e_RTE_METER_RED]))
3252 parse_table_action_meter(char **tokens,
3254 struct table_rule_action *a)
3256 if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
3262 if ((n_tokens < 10) ||
3263 strcmp(tokens[0], "tc0") ||
3264 (parse_table_action_meter_tc(tokens + 1,
3266 &a->mtr.mtr[0]) == 0))
3272 if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
3274 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3278 if ((n_tokens < 30) ||
3279 (parse_table_action_meter_tc(tokens + 1,
3280 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3281 strcmp(tokens[10], "tc2") ||
3282 (parse_table_action_meter_tc(tokens + 11,
3283 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3284 strcmp(tokens[20], "tc3") ||
3285 (parse_table_action_meter_tc(tokens + 21,
3286 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3289 a->mtr.tc_mask = 0xF;
3290 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3291 return 1 + 10 + 3 * 10;
3295 parse_table_action_tm(char **tokens,
3297 struct table_rule_action *a)
3299 uint32_t subport_id, pipe_id;
3301 if ((n_tokens < 5) ||
3302 strcmp(tokens[0], "tm") ||
3303 strcmp(tokens[1], "subport") ||
3304 parser_read_uint32(&subport_id, tokens[2]) ||
3305 strcmp(tokens[3], "pipe") ||
3306 parser_read_uint32(&pipe_id, tokens[4]))
3309 a->tm.subport_id = subport_id;
3310 a->tm.pipe_id = pipe_id;
3311 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3316 parse_table_action_encap(char **tokens,
3318 struct table_rule_action *a)
3320 if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
3327 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3328 if ((n_tokens < 3) ||
3329 parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3330 parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3333 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3334 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3339 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3340 uint32_t pcp, dei, vid;
3342 if ((n_tokens < 6) ||
3343 parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3344 parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3345 parser_read_uint32(&pcp, tokens[3]) ||
3347 parser_read_uint32(&dei, tokens[4]) ||
3349 parser_read_uint32(&vid, tokens[5]) ||
3353 a->encap.vlan.vlan.pcp = pcp & 0x7;
3354 a->encap.vlan.vlan.dei = dei & 0x1;
3355 a->encap.vlan.vlan.vid = vid & 0xFFF;
3356 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3357 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3362 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3363 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3364 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3366 if ((n_tokens < 9) ||
3367 parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3368 parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3369 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3370 (svlan_pcp > 0x7) ||
3371 parser_read_uint32(&svlan_dei, tokens[4]) ||
3372 (svlan_dei > 0x1) ||
3373 parser_read_uint32(&svlan_vid, tokens[5]) ||
3374 (svlan_vid > 0xFFF) ||
3375 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3376 (cvlan_pcp > 0x7) ||
3377 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3378 (cvlan_dei > 0x1) ||
3379 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3380 (cvlan_vid > 0xFFF))
3383 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3384 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3385 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3386 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3387 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3388 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3389 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3390 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3395 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3396 uint32_t label, tc, ttl;
3401 if (strcmp(tokens[1], "unicast") == 0)
3402 a->encap.mpls.unicast = 1;
3403 else if (strcmp(tokens[1], "multicast") == 0)
3404 a->encap.mpls.unicast = 0;
3408 if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3409 parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3410 strcmp(tokens[4], "label0") ||
3411 parser_read_uint32(&label, tokens[5]) ||
3412 (label > 0xFFFFF) ||
3413 parser_read_uint32(&tc, tokens[6]) ||
3415 parser_read_uint32(&ttl, tokens[7]) ||
3419 a->encap.mpls.mpls[0].label = label;
3420 a->encap.mpls.mpls[0].tc = tc;
3421 a->encap.mpls.mpls[0].ttl = ttl;
3426 if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3427 a->encap.mpls.mpls_count = 1;
3428 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3429 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3433 if ((n_tokens < 4) ||
3434 parser_read_uint32(&label, tokens[1]) ||
3435 (label > 0xFFFFF) ||
3436 parser_read_uint32(&tc, tokens[2]) ||
3438 parser_read_uint32(&ttl, tokens[3]) ||
3442 a->encap.mpls.mpls[1].label = label;
3443 a->encap.mpls.mpls[1].tc = tc;
3444 a->encap.mpls.mpls[1].ttl = ttl;
3449 if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3450 a->encap.mpls.mpls_count = 2;
3451 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3452 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3456 if ((n_tokens < 4) ||
3457 parser_read_uint32(&label, tokens[1]) ||
3458 (label > 0xFFFFF) ||
3459 parser_read_uint32(&tc, tokens[2]) ||
3461 parser_read_uint32(&ttl, tokens[3]) ||
3465 a->encap.mpls.mpls[2].label = label;
3466 a->encap.mpls.mpls[2].tc = tc;
3467 a->encap.mpls.mpls[2].ttl = ttl;
3472 if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3473 a->encap.mpls.mpls_count = 3;
3474 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3475 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3476 return 1 + 8 + 4 + 4;
3479 if ((n_tokens < 4) ||
3480 parser_read_uint32(&label, tokens[1]) ||
3481 (label > 0xFFFFF) ||
3482 parser_read_uint32(&tc, tokens[2]) ||
3484 parser_read_uint32(&ttl, tokens[3]) ||
3488 a->encap.mpls.mpls[3].label = label;
3489 a->encap.mpls.mpls[3].tc = tc;
3490 a->encap.mpls.mpls[3].ttl = ttl;
3492 a->encap.mpls.mpls_count = 4;
3493 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3494 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3495 return 1 + 8 + 4 + 4 + 4;
3499 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3500 if ((n_tokens < 4) ||
3501 parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3502 parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3503 parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3507 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3508 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3513 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3520 /* ether <da> <sa> */
3521 if ((n_tokens < 3) ||
3522 strcmp(tokens[0], "ether") ||
3523 parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3524 parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3531 /* [vlan <pcp> <dei> <vid>] */
3532 if (strcmp(tokens[0], "vlan") == 0) {
3533 uint32_t pcp, dei, vid;
3535 if ((n_tokens < 4) ||
3536 parser_read_uint32(&pcp, tokens[1]) ||
3538 parser_read_uint32(&dei, tokens[2]) ||
3540 parser_read_uint32(&vid, tokens[3]) ||
3544 a->encap.vxlan.vlan.pcp = pcp;
3545 a->encap.vxlan.vlan.dei = dei;
3546 a->encap.vxlan.vlan.vid = vid;
3553 /* ipv4 <sa> <da> <dscp> <ttl>
3554 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3555 if (strcmp(tokens[0], "ipv4") == 0) {
3556 struct in_addr sa, da;
3559 if ((n_tokens < 5) ||
3560 parse_ipv4_addr(tokens[1], &sa) ||
3561 parse_ipv4_addr(tokens[2], &da) ||
3562 parser_read_uint8(&dscp, tokens[3]) ||
3564 parser_read_uint8(&ttl, tokens[4]))
3567 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3568 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3569 a->encap.vxlan.ipv4.dscp = dscp;
3570 a->encap.vxlan.ipv4.ttl = ttl;
3575 } else if (strcmp(tokens[0], "ipv6") == 0) {
3576 struct in6_addr sa, da;
3577 uint32_t flow_label;
3578 uint8_t dscp, hop_limit;
3580 if ((n_tokens < 6) ||
3581 parse_ipv6_addr(tokens[1], &sa) ||
3582 parse_ipv6_addr(tokens[2], &da) ||
3583 parser_read_uint32(&flow_label, tokens[3]) ||
3584 parser_read_uint8(&dscp, tokens[4]) ||
3586 parser_read_uint8(&hop_limit, tokens[5]))
3589 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3590 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3591 a->encap.vxlan.ipv6.flow_label = flow_label;
3592 a->encap.vxlan.ipv6.dscp = dscp;
3593 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3602 if ((n_tokens < 3) ||
3603 strcmp(tokens[0], "udp") ||
3604 parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3605 parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3613 if ((n_tokens < 2) ||
3614 strcmp(tokens[0], "vxlan") ||
3615 parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3616 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3623 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3624 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3632 parse_table_action_nat(char **tokens,
3634 struct table_rule_action *a)
3636 if ((n_tokens < 4) ||
3637 strcmp(tokens[0], "nat"))
3640 if (strcmp(tokens[1], "ipv4") == 0) {
3641 struct in_addr addr;
3644 if (parse_ipv4_addr(tokens[2], &addr) ||
3645 parser_read_uint16(&port, tokens[3]))
3648 a->nat.ip_version = 1;
3649 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3651 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3655 if (strcmp(tokens[1], "ipv6") == 0) {
3656 struct in6_addr addr;
3659 if (parse_ipv6_addr(tokens[2], &addr) ||
3660 parser_read_uint16(&port, tokens[3]))
3663 a->nat.ip_version = 0;
3664 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3666 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3674 parse_table_action_ttl(char **tokens,
3676 struct table_rule_action *a)
3678 if ((n_tokens < 2) ||
3679 strcmp(tokens[0], "ttl"))
3682 if (strcmp(tokens[1], "dec") == 0)
3683 a->ttl.decrement = 1;
3684 else if (strcmp(tokens[1], "keep") == 0)
3685 a->ttl.decrement = 0;
3689 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3694 parse_table_action_stats(char **tokens,
3696 struct table_rule_action *a)
3698 if ((n_tokens < 1) ||
3699 strcmp(tokens[0], "stats"))
3702 a->stats.n_packets = 0;
3703 a->stats.n_bytes = 0;
3704 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3709 parse_table_action_time(char **tokens,
3711 struct table_rule_action *a)
3713 if ((n_tokens < 1) ||
3714 strcmp(tokens[0], "time"))
3717 a->time.time = rte_rdtsc();
3718 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3723 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
3725 struct rte_crypto_sym_xform *xform[2] = {NULL};
3728 xform[0] = p->xform;
3730 xform[1] = xform[0]->next;
3732 for (i = 0; i < 2; i++) {
3733 if (xform[i] == NULL)
3736 switch (xform[i]->type) {
3737 case RTE_CRYPTO_SYM_XFORM_CIPHER:
3738 if (xform[i]->cipher.key.data)
3739 free(xform[i]->cipher.key.data);
3740 if (p->cipher_auth.cipher_iv.val)
3741 free(p->cipher_auth.cipher_iv.val);
3742 if (p->cipher_auth.cipher_iv_update.val)
3743 free(p->cipher_auth.cipher_iv_update.val);
3745 case RTE_CRYPTO_SYM_XFORM_AUTH:
3746 if (xform[i]->auth.key.data)
3747 free(xform[i]->cipher.key.data);
3748 if (p->cipher_auth.auth_iv.val)
3749 free(p->cipher_auth.cipher_iv.val);
3750 if (p->cipher_auth.auth_iv_update.val)
3751 free(p->cipher_auth.cipher_iv_update.val);
3753 case RTE_CRYPTO_SYM_XFORM_AEAD:
3754 if (xform[i]->aead.key.data)
3755 free(xform[i]->cipher.key.data);
3757 free(p->aead.iv.val);
3758 if (p->aead.aad.val)
3759 free(p->aead.aad.val);
3768 static struct rte_crypto_sym_xform *
3769 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3770 char **tokens, uint32_t n_tokens, uint32_t encrypt,
3771 uint32_t *used_n_tokens)
3773 struct rte_crypto_sym_xform *xform_cipher;
3777 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
3778 strcmp(tokens[3], "cipher_key") ||
3779 strcmp(tokens[5], "cipher_iv"))
3782 xform_cipher = calloc(1, sizeof(*xform_cipher));
3783 if (xform_cipher == NULL)
3786 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3787 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
3788 RTE_CRYPTO_CIPHER_OP_DECRYPT;
3791 status = rte_cryptodev_get_cipher_algo_enum(
3792 &xform_cipher->cipher.algo, tokens[2]);
3797 len = strlen(tokens[4]);
3798 xform_cipher->cipher.key.data = calloc(1, len / 2 + 1);
3799 if (xform_cipher->cipher.key.data == NULL)
3802 status = parse_hex_string(tokens[4],
3803 xform_cipher->cipher.key.data,
3808 xform_cipher->cipher.key.length = (uint16_t)len;
3811 len = strlen(tokens[6]);
3813 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
3814 if (p->cipher_auth.cipher_iv.val == NULL)
3817 status = parse_hex_string(tokens[6],
3818 p->cipher_auth.cipher_iv.val,
3823 xform_cipher->cipher.iv.length = (uint16_t)len;
3824 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3825 p->cipher_auth.cipher_iv.length = (uint32_t)len;
3828 return xform_cipher;
3831 if (xform_cipher->cipher.key.data)
3832 free(xform_cipher->cipher.key.data);
3834 if (p->cipher_auth.cipher_iv.val) {
3835 free(p->cipher_auth.cipher_iv.val);
3836 p->cipher_auth.cipher_iv.val = NULL;
3844 static struct rte_crypto_sym_xform *
3845 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3846 char **tokens, uint32_t n_tokens, uint32_t encrypt,
3847 uint32_t *used_n_tokens)
3849 struct rte_crypto_sym_xform *xform_cipher;
3850 struct rte_crypto_sym_xform *xform_auth;
3854 if (n_tokens < 13 ||
3855 strcmp(tokens[7], "auth_algo") ||
3856 strcmp(tokens[9], "auth_key") ||
3857 strcmp(tokens[11], "digest_size"))
3860 xform_auth = calloc(1, sizeof(*xform_auth));
3861 if (xform_auth == NULL)
3864 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
3865 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
3866 RTE_CRYPTO_AUTH_OP_VERIFY;
3869 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
3875 len = strlen(tokens[10]);
3876 xform_auth->auth.key.data = calloc(1, len / 2 + 1);
3877 if (xform_auth->auth.key.data == NULL)
3880 status = parse_hex_string(tokens[10],
3881 xform_auth->auth.key.data, (uint32_t *)&len);
3885 xform_auth->auth.key.length = (uint16_t)len;
3887 if (strcmp(tokens[11], "digest_size"))
3890 status = parser_read_uint16(&xform_auth->auth.digest_length,
3895 xform_cipher = parse_table_action_cipher(p, tokens, 7, encrypt,
3897 if (xform_cipher == NULL)
3900 *used_n_tokens += 6;
3903 xform_cipher->next = xform_auth;
3904 return xform_cipher;
3906 xform_auth->next = xform_cipher;
3911 if (xform_auth->auth.key.data)
3912 free(xform_auth->auth.key.data);
3913 if (p->cipher_auth.auth_iv.val) {
3914 free(p->cipher_auth.auth_iv.val);
3915 p->cipher_auth.auth_iv.val = 0;
3923 static struct rte_crypto_sym_xform *
3924 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3925 char **tokens, uint32_t n_tokens, uint32_t encrypt,
3926 uint32_t *used_n_tokens)
3928 struct rte_crypto_sym_xform *xform_aead;
3932 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
3933 strcmp(tokens[3], "aead_key") ||
3934 strcmp(tokens[5], "aead_iv") ||
3935 strcmp(tokens[7], "aead_aad") ||
3936 strcmp(tokens[9], "digest_size"))
3939 xform_aead = calloc(1, sizeof(*xform_aead));
3940 if (xform_aead == NULL)
3943 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
3944 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
3945 RTE_CRYPTO_AEAD_OP_DECRYPT;
3948 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
3954 len = strlen(tokens[4]);
3955 xform_aead->aead.key.data = calloc(1, len / 2 + 1);
3956 if (xform_aead->aead.key.data == NULL)
3959 status = parse_hex_string(tokens[4], xform_aead->aead.key.data,
3964 xform_aead->aead.key.length = (uint16_t)len;
3967 len = strlen(tokens[6]);
3968 p->aead.iv.val = calloc(1, len / 2 + 1);
3969 if (p->aead.iv.val == NULL)
3972 status = parse_hex_string(tokens[6], p->aead.iv.val,
3977 xform_aead->aead.iv.length = (uint16_t)len;
3978 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3979 p->aead.iv.length = (uint32_t)len;
3982 len = strlen(tokens[8]);
3983 p->aead.aad.val = calloc(1, len / 2 + 1);
3984 if (p->aead.aad.val == NULL)
3987 status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
3991 xform_aead->aead.aad_length = (uint16_t)len;
3992 p->aead.aad.length = (uint32_t)len;
3995 status = parser_read_uint16(&xform_aead->aead.digest_length,
4000 *used_n_tokens = 11;
4005 if (xform_aead->aead.key.data)
4006 free(xform_aead->aead.key.data);
4007 if (p->aead.iv.val) {
4008 free(p->aead.iv.val);
4009 p->aead.iv.val = NULL;
4011 if (p->aead.aad.val) {
4012 free(p->aead.aad.val);
4013 p->aead.aad.val = NULL;
4023 parse_table_action_sym_crypto(char **tokens,
4025 struct table_rule_action *a)
4027 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4028 struct rte_crypto_sym_xform *xform = NULL;
4029 uint32_t used_n_tokens;
4033 if ((n_tokens < 12) ||
4034 strcmp(tokens[0], "sym_crypto") ||
4035 strcmp(tokens[2], "type"))
4038 memset(p, 0, sizeof(*p));
4040 if (strcmp(tokens[1], "encrypt") == 0)
4045 status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4049 if (strcmp(tokens[3], "cipher") == 0) {
4053 xform = parse_table_action_cipher(p, tokens, n_tokens, encrypt,
4055 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4059 xform = parse_table_action_cipher_auth(p, tokens, n_tokens,
4060 encrypt, &used_n_tokens);
4061 } else if (strcmp(tokens[3], "aead") == 0) {
4065 xform = parse_table_action_aead(p, tokens, n_tokens, encrypt,
4074 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4075 parse_free_sym_crypto_param_data(p);
4079 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4081 return used_n_tokens + 5;
4085 parse_table_action_tag(char **tokens,
4087 struct table_rule_action *a)
4089 if ((n_tokens < 2) ||
4090 strcmp(tokens[0], "tag"))
4093 if (parser_read_uint32(&a->tag.tag, tokens[1]))
4096 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4101 parse_table_action_decap(char **tokens,
4103 struct table_rule_action *a)
4105 if ((n_tokens < 2) ||
4106 strcmp(tokens[0], "decap"))
4109 if (parser_read_uint16(&a->decap.n, tokens[1]))
4112 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4117 parse_table_action(char **tokens,
4121 struct table_rule_action *a)
4123 uint32_t n_tokens0 = n_tokens;
4125 memset(a, 0, sizeof(*a));
4127 if ((n_tokens < 2) ||
4128 strcmp(tokens[0], "action"))
4134 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4137 n = parse_table_action_fwd(tokens, n_tokens, a);
4139 snprintf(out, out_size, MSG_ARG_INVALID,
4148 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4151 n = parse_table_action_balance(tokens, n_tokens, a);
4153 snprintf(out, out_size, MSG_ARG_INVALID,
4162 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4165 n = parse_table_action_meter(tokens, n_tokens, a);
4167 snprintf(out, out_size, MSG_ARG_INVALID,
4176 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4179 n = parse_table_action_tm(tokens, n_tokens, a);
4181 snprintf(out, out_size, MSG_ARG_INVALID,
4190 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4193 n = parse_table_action_encap(tokens, n_tokens, a);
4195 snprintf(out, out_size, MSG_ARG_INVALID,
4204 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4207 n = parse_table_action_nat(tokens, n_tokens, a);
4209 snprintf(out, out_size, MSG_ARG_INVALID,
4218 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4221 n = parse_table_action_ttl(tokens, n_tokens, a);
4223 snprintf(out, out_size, MSG_ARG_INVALID,
4232 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4235 n = parse_table_action_stats(tokens, n_tokens, a);
4237 snprintf(out, out_size, MSG_ARG_INVALID,
4246 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4249 n = parse_table_action_time(tokens, n_tokens, a);
4251 snprintf(out, out_size, MSG_ARG_INVALID,
4260 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4263 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4265 snprintf(out, out_size, MSG_ARG_INVALID,
4266 "action sym_crypto");
4273 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4276 n = parse_table_action_tag(tokens, n_tokens, a);
4278 snprintf(out, out_size, MSG_ARG_INVALID,
4287 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4290 n = parse_table_action_decap(tokens, n_tokens, a);
4292 snprintf(out, out_size, MSG_ARG_INVALID,
4301 if (n_tokens0 - n_tokens == 1) {
4302 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4306 return n_tokens0 - n_tokens;
4310 static const char cmd_pipeline_table_rule_add_help[] =
4311 "pipeline <pipeline_name> table <table_id> rule add\n"
4313 " action <table_action>\n";
4316 cmd_pipeline_table_rule_add(char **tokens,
4321 struct table_rule_match m;
4322 struct table_rule_action a;
4323 char *pipeline_name;
4324 uint32_t table_id, t0, n_tokens_parsed;
4328 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4332 pipeline_name = tokens[1];
4334 if (strcmp(tokens[2], "table") != 0) {
4335 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4339 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4340 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4344 if (strcmp(tokens[4], "rule") != 0) {
4345 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4349 if (strcmp(tokens[5], "add") != 0) {
4350 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4357 n_tokens_parsed = parse_match(tokens + t0,
4362 if (n_tokens_parsed == 0)
4364 t0 += n_tokens_parsed;
4367 n_tokens_parsed = parse_table_action(tokens + t0,
4372 if (n_tokens_parsed == 0)
4374 t0 += n_tokens_parsed;
4376 if (t0 != n_tokens) {
4377 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4381 status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
4383 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4387 if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
4388 parse_free_sym_crypto_param_data(&a.sym_crypto);
4392 static const char cmd_pipeline_table_rule_add_default_help[] =
4393 "pipeline <pipeline_name> table <table_id> rule add\n"
4399 " | port <port_id>\n"
4401 " | table <table_id>\n";
4404 cmd_pipeline_table_rule_add_default(char **tokens,
4409 struct table_rule_action action;
4411 char *pipeline_name;
4415 if ((n_tokens != 11) && (n_tokens != 12)) {
4416 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4420 pipeline_name = tokens[1];
4422 if (strcmp(tokens[2], "table") != 0) {
4423 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4427 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4428 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4432 if (strcmp(tokens[4], "rule") != 0) {
4433 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4437 if (strcmp(tokens[5], "add") != 0) {
4438 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4442 if (strcmp(tokens[6], "match") != 0) {
4443 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4447 if (strcmp(tokens[7], "default") != 0) {
4448 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4452 if (strcmp(tokens[8], "action") != 0) {
4453 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4457 if (strcmp(tokens[9], "fwd") != 0) {
4458 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4462 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4464 if (strcmp(tokens[10], "drop") == 0) {
4465 if (n_tokens != 11) {
4466 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4470 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4471 } else if (strcmp(tokens[10], "port") == 0) {
4474 if (n_tokens != 12) {
4475 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4479 if (parser_read_uint32(&id, tokens[11]) != 0) {
4480 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4484 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4486 } else if (strcmp(tokens[10], "meta") == 0) {
4487 if (n_tokens != 11) {
4488 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4492 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4493 } else if (strcmp(tokens[10], "table") == 0) {
4496 if (n_tokens != 12) {
4497 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4501 if (parser_read_uint32(&id, tokens[11]) != 0) {
4502 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4506 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4509 snprintf(out, out_size, MSG_ARG_INVALID,
4510 "drop or port or meta or table");
4514 status = pipeline_table_rule_add_default(pipeline_name,
4519 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4525 static const char cmd_pipeline_table_rule_add_bulk_help[] =
4526 "pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\n"
4528 " File <file_name>:\n"
4529 " - line format: match <match> action <action>\n";
4532 cli_rule_file_process(const char *file_name,
4533 size_t line_len_max,
4534 struct table_rule_list **rule_list,
4536 uint32_t *line_number,
4541 cmd_pipeline_table_rule_add_bulk(char **tokens,
4546 struct table_rule_list *list = NULL;
4547 char *pipeline_name, *file_name;
4548 uint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;
4551 if (n_tokens != 8) {
4552 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4556 pipeline_name = tokens[1];
4558 if (strcmp(tokens[2], "table") != 0) {
4559 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4563 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4564 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4568 if (strcmp(tokens[4], "rule") != 0) {
4569 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4573 if (strcmp(tokens[5], "add") != 0) {
4574 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4578 if (strcmp(tokens[6], "bulk") != 0) {
4579 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4583 file_name = tokens[7];
4585 /* Load rules from file. */
4586 status = cli_rule_file_process(file_name,
4594 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4599 status = pipeline_table_rule_add_bulk(pipeline_name,
4603 &n_rules_not_added);
4605 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4609 snprintf(out, out_size, "Added %u rules out of %u.\n",
4615 static const char cmd_pipeline_table_rule_delete_help[] =
4616 "pipeline <pipeline_name> table <table_id> rule delete\n"
4620 cmd_pipeline_table_rule_delete(char **tokens,
4625 struct table_rule_match m;
4626 char *pipeline_name;
4627 uint32_t table_id, n_tokens_parsed, t0;
4631 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4635 pipeline_name = tokens[1];
4637 if (strcmp(tokens[2], "table") != 0) {
4638 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4642 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4643 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4647 if (strcmp(tokens[4], "rule") != 0) {
4648 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4652 if (strcmp(tokens[5], "delete") != 0) {
4653 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4660 n_tokens_parsed = parse_match(tokens + t0,
4665 if (n_tokens_parsed == 0)
4667 t0 += n_tokens_parsed;
4669 if (n_tokens != t0) {
4670 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4674 status = pipeline_table_rule_delete(pipeline_name,
4678 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4684 static const char cmd_pipeline_table_rule_delete_default_help[] =
4685 "pipeline <pipeline_name> table <table_id> rule delete\n"
4690 cmd_pipeline_table_rule_delete_default(char **tokens,
4695 char *pipeline_name;
4699 if (n_tokens != 8) {
4700 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4704 pipeline_name = tokens[1];
4706 if (strcmp(tokens[2], "table") != 0) {
4707 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4711 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4712 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4716 if (strcmp(tokens[4], "rule") != 0) {
4717 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4721 if (strcmp(tokens[5], "delete") != 0) {
4722 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4726 if (strcmp(tokens[6], "match") != 0) {
4727 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4731 if (strcmp(tokens[7], "default") != 0) {
4732 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4736 status = pipeline_table_rule_delete_default(pipeline_name,
4739 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4745 static const char cmd_pipeline_table_rule_stats_read_help[] =
4746 "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n";
4749 cmd_pipeline_table_rule_stats_read(char **tokens,
4750 uint32_t n_tokens __rte_unused,
4754 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
4758 static const char cmd_pipeline_table_meter_profile_add_help[] =
4759 "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
4760 " add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
4761 " | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
4764 cmd_pipeline_table_meter_profile_add(char **tokens,
4769 struct rte_table_action_meter_profile p;
4770 char *pipeline_name;
4771 uint32_t table_id, meter_profile_id;
4775 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4779 pipeline_name = tokens[1];
4781 if (strcmp(tokens[2], "table") != 0) {
4782 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
4786 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4787 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4791 if (strcmp(tokens[4], "meter") != 0) {
4792 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
4796 if (strcmp(tokens[5], "profile") != 0) {
4797 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
4801 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
4802 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
4806 if (strcmp(tokens[7], "add") != 0) {
4807 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4811 if (strcmp(tokens[8], "srtcm") == 0) {
4812 if (n_tokens != 15) {
4813 snprintf(out, out_size, MSG_ARG_MISMATCH,
4818 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
4820 if (strcmp(tokens[9], "cir") != 0) {
4821 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
4825 if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
4826 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
4830 if (strcmp(tokens[11], "cbs") != 0) {
4831 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
4835 if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
4836 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
4840 if (strcmp(tokens[13], "ebs") != 0) {
4841 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
4845 if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
4846 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
4849 } else if (strcmp(tokens[8], "trtcm") == 0) {
4850 if (n_tokens != 17) {
4851 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4855 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
4857 if (strcmp(tokens[9], "cir") != 0) {
4858 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
4862 if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
4863 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
4867 if (strcmp(tokens[11], "pir") != 0) {
4868 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
4872 if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
4873 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
4876 if (strcmp(tokens[13], "cbs") != 0) {
4877 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
4881 if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
4882 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
4886 if (strcmp(tokens[15], "pbs") != 0) {
4887 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
4891 if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
4892 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
4896 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4900 status = pipeline_table_mtr_profile_add(pipeline_name,
4905 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4911 static const char cmd_pipeline_table_meter_profile_delete_help[] =
4912 "pipeline <pipeline_name> table <table_id>\n"
4913 " meter profile <meter_profile_id> delete\n";
4916 cmd_pipeline_table_meter_profile_delete(char **tokens,
4921 char *pipeline_name;
4922 uint32_t table_id, meter_profile_id;
4925 if (n_tokens != 8) {
4926 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4930 pipeline_name = tokens[1];
4932 if (strcmp(tokens[2], "table") != 0) {
4933 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
4937 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4938 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4942 if (strcmp(tokens[4], "meter") != 0) {
4943 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
4947 if (strcmp(tokens[5], "profile") != 0) {
4948 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
4952 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
4953 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
4957 if (strcmp(tokens[7], "delete") != 0) {
4958 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4962 status = pipeline_table_mtr_profile_delete(pipeline_name,
4966 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4972 static const char cmd_pipeline_table_rule_meter_read_help[] =
4973 "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n";
4976 cmd_pipeline_table_rule_meter_read(char **tokens,
4977 uint32_t n_tokens __rte_unused,
4981 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
4985 static const char cmd_pipeline_table_dscp_help[] =
4986 "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
4988 " File <file_name>:\n"
4989 " - exactly 64 lines\n"
4990 " - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
4993 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
4994 const char *file_name,
4995 uint32_t *line_number)
5000 /* Check input arguments */
5001 if ((dscp_table == NULL) ||
5002 (file_name == NULL) ||
5003 (line_number == NULL)) {
5009 /* Open input file */
5010 f = fopen(file_name, "r");
5017 for (dscp = 0, l = 1; ; l++) {
5020 enum rte_meter_color color;
5021 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5023 if (fgets(line, sizeof(line), f) == NULL)
5026 if (is_comment(line))
5029 if (parse_tokenize_string(line, tokens, &n_tokens)) {
5038 if ((dscp >= RTE_DIM(dscp_table->entry)) ||
5039 (n_tokens != RTE_DIM(tokens)) ||
5040 parser_read_uint32(&tc_id, tokens[0]) ||
5041 (tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
5042 parser_read_uint32(&tc_queue_id, tokens[1]) ||
5043 (tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
5044 (strlen(tokens[2]) != 1)) {
5050 switch (tokens[2][0]) {
5053 color = e_RTE_METER_GREEN;
5058 color = e_RTE_METER_YELLOW;
5063 color = e_RTE_METER_RED;
5072 dscp_table->entry[dscp].tc_id = tc_id;
5073 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5074 dscp_table->entry[dscp].color = color;
5084 cmd_pipeline_table_dscp(char **tokens,
5089 struct rte_table_action_dscp_table dscp_table;
5090 char *pipeline_name, *file_name;
5091 uint32_t table_id, line_number;
5094 if (n_tokens != 6) {
5095 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5099 pipeline_name = tokens[1];
5101 if (strcmp(tokens[2], "table") != 0) {
5102 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5106 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5107 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5111 if (strcmp(tokens[4], "dscp") != 0) {
5112 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5116 file_name = tokens[5];
5118 status = load_dscp_table(&dscp_table, file_name, &line_number);
5120 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5124 status = pipeline_table_dscp_table_update(pipeline_name,
5129 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5135 static const char cmd_pipeline_table_rule_ttl_read_help[] =
5136 "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n";
5139 cmd_pipeline_table_rule_ttl_read(char **tokens,
5140 uint32_t n_tokens __rte_unused,
5144 snprintf(out, out_size, MSG_CMD_UNIMPLEM, tokens[0]);
5148 static const char cmd_thread_pipeline_enable_help[] =
5149 "thread <thread_id> pipeline <pipeline_name> enable\n";
5152 cmd_thread_pipeline_enable(char **tokens,
5157 char *pipeline_name;
5161 if (n_tokens != 5) {
5162 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5166 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5167 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5171 if (strcmp(tokens[2], "pipeline") != 0) {
5172 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5176 pipeline_name = tokens[3];
5178 if (strcmp(tokens[4], "enable") != 0) {
5179 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5183 status = thread_pipeline_enable(thread_id, pipeline_name);
5185 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5191 static const char cmd_thread_pipeline_disable_help[] =
5192 "thread <thread_id> pipeline <pipeline_name> disable\n";
5195 cmd_thread_pipeline_disable(char **tokens,
5200 char *pipeline_name;
5204 if (n_tokens != 5) {
5205 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5209 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5210 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5214 if (strcmp(tokens[2], "pipeline") != 0) {
5215 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5219 pipeline_name = tokens[3];
5221 if (strcmp(tokens[4], "disable") != 0) {
5222 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
5226 status = thread_pipeline_disable(thread_id, pipeline_name);
5228 snprintf(out, out_size, MSG_CMD_FAIL,
5229 "thread pipeline disable");
5235 cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
5240 if (n_tokens == 0) {
5241 snprintf(out, out_size,
5242 "Type 'help <command>' for details on each command.\n\n"
5243 "List of commands:\n"
5247 "\ttmgr subport profile\n"
5248 "\ttmgr pipe profile\n"
5251 "\ttmgr subport pipe\n"
5254 "\tport in action profile\n"
5255 "\ttable action profile\n"
5257 "\tpipeline port in\n"
5258 "\tpipeline port out\n"
5259 "\tpipeline table\n"
5260 "\tpipeline port in table\n"
5261 "\tpipeline port in stats\n"
5262 "\tpipeline port in enable\n"
5263 "\tpipeline port in disable\n"
5264 "\tpipeline port out stats\n"
5265 "\tpipeline table stats\n"
5266 "\tpipeline table rule add\n"
5267 "\tpipeline table rule add default\n"
5268 "\tpipeline table rule add bulk\n"
5269 "\tpipeline table rule delete\n"
5270 "\tpipeline table rule delete default\n"
5271 "\tpipeline table rule stats read\n"
5272 "\tpipeline table meter profile add\n"
5273 "\tpipeline table meter profile delete\n"
5274 "\tpipeline table rule meter read\n"
5275 "\tpipeline table dscp\n"
5276 "\tpipeline table rule ttl read\n"
5277 "\tthread pipeline enable\n"
5278 "\tthread pipeline disable\n\n");
5282 if (strcmp(tokens[0], "mempool") == 0) {
5283 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
5287 if (strcmp(tokens[0], "link") == 0) {
5288 snprintf(out, out_size, "\n%s\n", cmd_link_help);
5292 if (strcmp(tokens[0], "swq") == 0) {
5293 snprintf(out, out_size, "\n%s\n", cmd_swq_help);
5297 if (strcmp(tokens[0], "tmgr") == 0) {
5298 if (n_tokens == 1) {
5299 snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
5303 if ((n_tokens == 2) &&
5304 (strcmp(tokens[1], "subport")) == 0) {
5305 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
5309 if ((n_tokens == 3) &&
5310 (strcmp(tokens[1], "subport") == 0) &&
5311 (strcmp(tokens[2], "profile") == 0)) {
5312 snprintf(out, out_size, "\n%s\n",
5313 cmd_tmgr_subport_profile_help);
5317 if ((n_tokens == 3) &&
5318 (strcmp(tokens[1], "subport") == 0) &&
5319 (strcmp(tokens[2], "pipe") == 0)) {
5320 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
5324 if ((n_tokens == 3) &&
5325 (strcmp(tokens[1], "pipe") == 0) &&
5326 (strcmp(tokens[2], "profile") == 0)) {
5327 snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
5332 if (strcmp(tokens[0], "tap") == 0) {
5333 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
5337 if (strcmp(tokens[0], "kni") == 0) {
5338 snprintf(out, out_size, "\n%s\n", cmd_kni_help);
5342 if (strcmp(tokens[0], "cryptodev") == 0) {
5343 snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
5347 if ((n_tokens == 4) &&
5348 (strcmp(tokens[0], "port") == 0) &&
5349 (strcmp(tokens[1], "in") == 0) &&
5350 (strcmp(tokens[2], "action") == 0) &&
5351 (strcmp(tokens[3], "profile") == 0)) {
5352 snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
5356 if ((n_tokens == 3) &&
5357 (strcmp(tokens[0], "table") == 0) &&
5358 (strcmp(tokens[1], "action") == 0) &&
5359 (strcmp(tokens[2], "profile") == 0)) {
5360 snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
5364 if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
5365 snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
5369 if ((strcmp(tokens[0], "pipeline") == 0) &&
5370 (strcmp(tokens[1], "port") == 0)) {
5371 if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
5372 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
5376 if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
5377 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
5381 if ((n_tokens == 4) &&
5382 (strcmp(tokens[2], "in") == 0) &&
5383 (strcmp(tokens[3], "table") == 0)) {
5384 snprintf(out, out_size, "\n%s\n",
5385 cmd_pipeline_port_in_table_help);
5389 if ((n_tokens == 4) &&
5390 (strcmp(tokens[2], "in") == 0) &&
5391 (strcmp(tokens[3], "stats") == 0)) {
5392 snprintf(out, out_size, "\n%s\n",
5393 cmd_pipeline_port_in_stats_help);
5397 if ((n_tokens == 4) &&
5398 (strcmp(tokens[2], "in") == 0) &&
5399 (strcmp(tokens[3], "enable") == 0)) {
5400 snprintf(out, out_size, "\n%s\n",
5401 cmd_pipeline_port_in_enable_help);
5405 if ((n_tokens == 4) &&
5406 (strcmp(tokens[2], "in") == 0) &&
5407 (strcmp(tokens[3], "disable") == 0)) {
5408 snprintf(out, out_size, "\n%s\n",
5409 cmd_pipeline_port_in_disable_help);
5413 if ((n_tokens == 4) &&
5414 (strcmp(tokens[2], "out") == 0) &&
5415 (strcmp(tokens[3], "stats") == 0)) {
5416 snprintf(out, out_size, "\n%s\n",
5417 cmd_pipeline_port_out_stats_help);
5422 if ((strcmp(tokens[0], "pipeline") == 0) &&
5423 (strcmp(tokens[1], "table") == 0)) {
5424 if (n_tokens == 2) {
5425 snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
5429 if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
5430 snprintf(out, out_size, "\n%s\n",
5431 cmd_pipeline_table_stats_help);
5435 if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
5436 snprintf(out, out_size, "\n%s\n",
5437 cmd_pipeline_table_dscp_help);
5441 if ((n_tokens == 4) &&
5442 (strcmp(tokens[2], "rule") == 0) &&
5443 (strcmp(tokens[3], "add") == 0)) {
5444 snprintf(out, out_size, "\n%s\n",
5445 cmd_pipeline_table_rule_add_help);
5449 if ((n_tokens == 5) &&
5450 (strcmp(tokens[2], "rule") == 0) &&
5451 (strcmp(tokens[3], "add") == 0) &&
5452 (strcmp(tokens[4], "default") == 0)) {
5453 snprintf(out, out_size, "\n%s\n",
5454 cmd_pipeline_table_rule_add_default_help);
5458 if ((n_tokens == 5) &&
5459 (strcmp(tokens[2], "rule") == 0) &&
5460 (strcmp(tokens[3], "add") == 0) &&
5461 (strcmp(tokens[4], "bulk") == 0)) {
5462 snprintf(out, out_size, "\n%s\n",
5463 cmd_pipeline_table_rule_add_bulk_help);
5467 if ((n_tokens == 4) &&
5468 (strcmp(tokens[2], "rule") == 0) &&
5469 (strcmp(tokens[3], "delete") == 0)) {
5470 snprintf(out, out_size, "\n%s\n",
5471 cmd_pipeline_table_rule_delete_help);
5475 if ((n_tokens == 5) &&
5476 (strcmp(tokens[2], "rule") == 0) &&
5477 (strcmp(tokens[3], "delete") == 0) &&
5478 (strcmp(tokens[4], "default") == 0)) {
5479 snprintf(out, out_size, "\n%s\n",
5480 cmd_pipeline_table_rule_delete_default_help);
5484 if ((n_tokens == 5) &&
5485 (strcmp(tokens[2], "rule") == 0) &&
5486 (strcmp(tokens[3], "stats") == 0) &&
5487 (strcmp(tokens[4], "read") == 0)) {
5488 snprintf(out, out_size, "\n%s\n",
5489 cmd_pipeline_table_rule_stats_read_help);
5493 if ((n_tokens == 5) &&
5494 (strcmp(tokens[2], "meter") == 0) &&
5495 (strcmp(tokens[3], "profile") == 0) &&
5496 (strcmp(tokens[4], "add") == 0)) {
5497 snprintf(out, out_size, "\n%s\n",
5498 cmd_pipeline_table_meter_profile_add_help);
5502 if ((n_tokens == 5) &&
5503 (strcmp(tokens[2], "meter") == 0) &&
5504 (strcmp(tokens[3], "profile") == 0) &&
5505 (strcmp(tokens[4], "delete") == 0)) {
5506 snprintf(out, out_size, "\n%s\n",
5507 cmd_pipeline_table_meter_profile_delete_help);
5511 if ((n_tokens == 5) &&
5512 (strcmp(tokens[2], "rule") == 0) &&
5513 (strcmp(tokens[3], "meter") == 0) &&
5514 (strcmp(tokens[4], "read") == 0)) {
5515 snprintf(out, out_size, "\n%s\n",
5516 cmd_pipeline_table_rule_meter_read_help);
5520 if ((n_tokens == 5) &&
5521 (strcmp(tokens[2], "rule") == 0) &&
5522 (strcmp(tokens[3], "ttl") == 0) &&
5523 (strcmp(tokens[4], "read") == 0)) {
5524 snprintf(out, out_size, "\n%s\n",
5525 cmd_pipeline_table_rule_ttl_read_help);
5530 if ((n_tokens == 3) &&
5531 (strcmp(tokens[0], "thread") == 0) &&
5532 (strcmp(tokens[1], "pipeline") == 0)) {
5533 if (strcmp(tokens[2], "enable") == 0) {
5534 snprintf(out, out_size, "\n%s\n",
5535 cmd_thread_pipeline_enable_help);
5539 if (strcmp(tokens[2], "disable") == 0) {
5540 snprintf(out, out_size, "\n%s\n",
5541 cmd_thread_pipeline_disable_help);
5546 snprintf(out, out_size, "Invalid command\n");
5550 cli_process(char *in, char *out, size_t out_size)
5552 char *tokens[CMD_MAX_TOKENS];
5553 uint32_t n_tokens = RTE_DIM(tokens);
5559 status = parse_tokenize_string(in, tokens, &n_tokens);
5561 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
5568 if (strcmp(tokens[0], "help") == 0) {
5569 cmd_help(tokens, n_tokens, out, out_size);
5573 if (strcmp(tokens[0], "mempool") == 0) {
5574 cmd_mempool(tokens, n_tokens, out, out_size);
5578 if (strcmp(tokens[0], "link") == 0) {
5579 if (strcmp(tokens[1], "show") == 0) {
5580 cmd_link_show(tokens, n_tokens, out, out_size);
5584 cmd_link(tokens, n_tokens, out, out_size);
5588 if (strcmp(tokens[0], "swq") == 0) {
5589 cmd_swq(tokens, n_tokens, out, out_size);
5593 if (strcmp(tokens[0], "tmgr") == 0) {
5594 if ((n_tokens >= 3) &&
5595 (strcmp(tokens[1], "subport") == 0) &&
5596 (strcmp(tokens[2], "profile") == 0)) {
5597 cmd_tmgr_subport_profile(tokens, n_tokens,
5602 if ((n_tokens >= 3) &&
5603 (strcmp(tokens[1], "pipe") == 0) &&
5604 (strcmp(tokens[2], "profile") == 0)) {
5605 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
5609 if ((n_tokens >= 5) &&
5610 (strcmp(tokens[2], "subport") == 0) &&
5611 (strcmp(tokens[4], "profile") == 0)) {
5612 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
5616 if ((n_tokens >= 5) &&
5617 (strcmp(tokens[2], "subport") == 0) &&
5618 (strcmp(tokens[4], "pipe") == 0)) {
5619 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
5623 cmd_tmgr(tokens, n_tokens, out, out_size);
5627 if (strcmp(tokens[0], "tap") == 0) {
5628 cmd_tap(tokens, n_tokens, out, out_size);
5632 if (strcmp(tokens[0], "kni") == 0) {
5633 cmd_kni(tokens, n_tokens, out, out_size);
5637 if (strcmp(tokens[0], "cryptodev") == 0) {
5638 cmd_cryptodev(tokens, n_tokens, out, out_size);
5642 if (strcmp(tokens[0], "port") == 0) {
5643 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
5647 if (strcmp(tokens[0], "table") == 0) {
5648 cmd_table_action_profile(tokens, n_tokens, out, out_size);
5652 if (strcmp(tokens[0], "pipeline") == 0) {
5653 if ((n_tokens >= 3) &&
5654 (strcmp(tokens[2], "period") == 0)) {
5655 cmd_pipeline(tokens, n_tokens, out, out_size);
5659 if ((n_tokens >= 5) &&
5660 (strcmp(tokens[2], "port") == 0) &&
5661 (strcmp(tokens[3], "in") == 0) &&
5662 (strcmp(tokens[4], "bsz") == 0)) {
5663 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
5667 if ((n_tokens >= 5) &&
5668 (strcmp(tokens[2], "port") == 0) &&
5669 (strcmp(tokens[3], "out") == 0) &&
5670 (strcmp(tokens[4], "bsz") == 0)) {
5671 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
5675 if ((n_tokens >= 4) &&
5676 (strcmp(tokens[2], "table") == 0) &&
5677 (strcmp(tokens[3], "match") == 0)) {
5678 cmd_pipeline_table(tokens, n_tokens, out, out_size);
5682 if ((n_tokens >= 6) &&
5683 (strcmp(tokens[2], "port") == 0) &&
5684 (strcmp(tokens[3], "in") == 0) &&
5685 (strcmp(tokens[5], "table") == 0)) {
5686 cmd_pipeline_port_in_table(tokens, n_tokens,
5691 if ((n_tokens >= 6) &&
5692 (strcmp(tokens[2], "port") == 0) &&
5693 (strcmp(tokens[3], "in") == 0) &&
5694 (strcmp(tokens[5], "stats") == 0)) {
5695 cmd_pipeline_port_in_stats(tokens, n_tokens,
5700 if ((n_tokens >= 6) &&
5701 (strcmp(tokens[2], "port") == 0) &&
5702 (strcmp(tokens[3], "in") == 0) &&
5703 (strcmp(tokens[5], "enable") == 0)) {
5704 cmd_pipeline_port_in_enable(tokens, n_tokens,
5709 if ((n_tokens >= 6) &&
5710 (strcmp(tokens[2], "port") == 0) &&
5711 (strcmp(tokens[3], "in") == 0) &&
5712 (strcmp(tokens[5], "disable") == 0)) {
5713 cmd_pipeline_port_in_disable(tokens, n_tokens,
5718 if ((n_tokens >= 6) &&
5719 (strcmp(tokens[2], "port") == 0) &&
5720 (strcmp(tokens[3], "out") == 0) &&
5721 (strcmp(tokens[5], "stats") == 0)) {
5722 cmd_pipeline_port_out_stats(tokens, n_tokens,
5727 if ((n_tokens >= 5) &&
5728 (strcmp(tokens[2], "table") == 0) &&
5729 (strcmp(tokens[4], "stats") == 0)) {
5730 cmd_pipeline_table_stats(tokens, n_tokens,
5735 if ((n_tokens >= 7) &&
5736 (strcmp(tokens[2], "table") == 0) &&
5737 (strcmp(tokens[4], "rule") == 0) &&
5738 (strcmp(tokens[5], "add") == 0) &&
5739 (strcmp(tokens[6], "match") == 0)) {
5740 if ((n_tokens >= 8) &&
5741 (strcmp(tokens[7], "default") == 0)) {
5742 cmd_pipeline_table_rule_add_default(tokens,
5743 n_tokens, out, out_size);
5747 cmd_pipeline_table_rule_add(tokens, n_tokens,
5752 if ((n_tokens >= 7) &&
5753 (strcmp(tokens[2], "table") == 0) &&
5754 (strcmp(tokens[4], "rule") == 0) &&
5755 (strcmp(tokens[5], "add") == 0) &&
5756 (strcmp(tokens[6], "bulk") == 0)) {
5757 cmd_pipeline_table_rule_add_bulk(tokens,
5758 n_tokens, out, out_size);
5762 if ((n_tokens >= 7) &&
5763 (strcmp(tokens[2], "table") == 0) &&
5764 (strcmp(tokens[4], "rule") == 0) &&
5765 (strcmp(tokens[5], "delete") == 0) &&
5766 (strcmp(tokens[6], "match") == 0)) {
5767 if ((n_tokens >= 8) &&
5768 (strcmp(tokens[7], "default") == 0)) {
5769 cmd_pipeline_table_rule_delete_default(tokens,
5770 n_tokens, out, out_size);
5774 cmd_pipeline_table_rule_delete(tokens, n_tokens,
5779 if ((n_tokens >= 7) &&
5780 (strcmp(tokens[2], "table") == 0) &&
5781 (strcmp(tokens[4], "rule") == 0) &&
5782 (strcmp(tokens[5], "read") == 0) &&
5783 (strcmp(tokens[6], "stats") == 0)) {
5784 cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
5789 if ((n_tokens >= 8) &&
5790 (strcmp(tokens[2], "table") == 0) &&
5791 (strcmp(tokens[4], "meter") == 0) &&
5792 (strcmp(tokens[5], "profile") == 0) &&
5793 (strcmp(tokens[7], "add") == 0)) {
5794 cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
5799 if ((n_tokens >= 8) &&
5800 (strcmp(tokens[2], "table") == 0) &&
5801 (strcmp(tokens[4], "meter") == 0) &&
5802 (strcmp(tokens[5], "profile") == 0) &&
5803 (strcmp(tokens[7], "delete") == 0)) {
5804 cmd_pipeline_table_meter_profile_delete(tokens,
5805 n_tokens, out, out_size);
5809 if ((n_tokens >= 7) &&
5810 (strcmp(tokens[2], "table") == 0) &&
5811 (strcmp(tokens[4], "rule") == 0) &&
5812 (strcmp(tokens[5], "read") == 0) &&
5813 (strcmp(tokens[6], "meter") == 0)) {
5814 cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
5819 if ((n_tokens >= 5) &&
5820 (strcmp(tokens[2], "table") == 0) &&
5821 (strcmp(tokens[4], "dscp") == 0)) {
5822 cmd_pipeline_table_dscp(tokens, n_tokens,
5827 if ((n_tokens >= 7) &&
5828 (strcmp(tokens[2], "table") == 0) &&
5829 (strcmp(tokens[4], "rule") == 0) &&
5830 (strcmp(tokens[5], "read") == 0) &&
5831 (strcmp(tokens[6], "ttl") == 0)) {
5832 cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
5838 if (strcmp(tokens[0], "thread") == 0) {
5839 if ((n_tokens >= 5) &&
5840 (strcmp(tokens[4], "enable") == 0)) {
5841 cmd_thread_pipeline_enable(tokens, n_tokens,
5846 if ((n_tokens >= 5) &&
5847 (strcmp(tokens[4], "disable") == 0)) {
5848 cmd_thread_pipeline_disable(tokens, n_tokens,
5854 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
5858 cli_script_process(const char *file_name,
5859 size_t msg_in_len_max,
5860 size_t msg_out_len_max)
5862 char *msg_in = NULL, *msg_out = NULL;
5865 /* Check input arguments */
5866 if ((file_name == NULL) ||
5867 (strlen(file_name) == 0) ||
5868 (msg_in_len_max == 0) ||
5869 (msg_out_len_max == 0))
5872 msg_in = malloc(msg_in_len_max + 1);
5873 msg_out = malloc(msg_out_len_max + 1);
5874 if ((msg_in == NULL) ||
5875 (msg_out == NULL)) {
5881 /* Open input file */
5882 f = fopen(file_name, "r");
5891 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
5894 printf("%s", msg_in);
5901 if (strlen(msg_out))
5902 printf("%s", msg_out);
5913 cli_rule_file_process(const char *file_name,
5914 size_t line_len_max,
5915 struct table_rule_list **rule_list,
5917 uint32_t *line_number,
5921 struct table_rule_list *list = NULL;
5924 uint32_t rule_id = 0, line_id = 0;
5927 /* Check input arguments */
5928 if ((file_name == NULL) ||
5929 (strlen(file_name) == 0) ||
5930 (line_len_max == 0) ||
5931 (rule_list == NULL) ||
5932 (n_rules == NULL) ||
5933 (line_number == NULL) ||
5936 goto cli_rule_file_process_free;
5939 /* Memory allocation */
5940 list = malloc(sizeof(struct table_rule_list));
5943 goto cli_rule_file_process_free;
5948 line = malloc(line_len_max + 1);
5951 goto cli_rule_file_process_free;
5955 f = fopen(file_name, "r");
5958 goto cli_rule_file_process_free;
5962 for (line_id = 1, rule_id = 0; ; line_id++) {
5963 char *tokens[CMD_MAX_TOKENS];
5964 struct table_rule *rule = NULL;
5965 uint32_t n_tokens, n_tokens_parsed, t0;
5967 /* Read next line from file. */
5968 if (fgets(line, line_len_max + 1, f) == NULL)
5972 if (is_comment(line))
5976 n_tokens = RTE_DIM(tokens);
5977 status = parse_tokenize_string(line, tokens, &n_tokens);
5980 goto cli_rule_file_process_free;
5988 /* Rule alloc and insert. */
5989 rule = calloc(1, sizeof(struct table_rule));
5992 goto cli_rule_file_process_free;
5995 TAILQ_INSERT_TAIL(list, rule, node);
5998 n_tokens_parsed = parse_match(tokens + t0,
6003 if (n_tokens_parsed == 0) {
6005 goto cli_rule_file_process_free;
6007 t0 += n_tokens_parsed;
6010 n_tokens_parsed = parse_table_action(tokens + t0,
6015 if (n_tokens_parsed == 0) {
6017 goto cli_rule_file_process_free;
6019 t0 += n_tokens_parsed;
6021 /* Line completed. */
6022 if (t0 < n_tokens) {
6024 goto cli_rule_file_process_free;
6027 /* Increment rule count */
6039 *line_number = line_id;
6042 cli_rule_file_process_free:
6045 *line_number = line_id;
6048 struct table_rule *rule;
6050 rule = TAILQ_FIRST(list);
6054 TAILQ_REMOVE(list, rule, node);