1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include <rte_common.h>
11 #include <rte_cycles.h>
12 #include <rte_ethdev.h>
16 #include "cryptodev.h"
27 #ifndef CMD_MAX_TOKENS
28 #define CMD_MAX_TOKENS 256
31 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
32 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
33 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
34 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
35 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
36 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
37 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
38 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
39 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
40 #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
41 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
46 if ((strlen(in) && index("!#%;", in[0])) ||
47 (strncmp(in, "//", 2) == 0) ||
48 (strncmp(in, "--", 2) == 0))
54 static const char cmd_mempool_help[] =
55 "mempool <mempool_name>\n"
56 " buffer <buffer_size>\n"
58 " cache <cache_size>\n"
62 cmd_mempool(char **tokens,
67 struct mempool_params p;
69 struct mempool *mempool;
72 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
78 if (strcmp(tokens[2], "buffer") != 0) {
79 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
83 if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
84 snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
88 if (strcmp(tokens[4], "pool") != 0) {
89 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
93 if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
94 snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
98 if (strcmp(tokens[6], "cache") != 0) {
99 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
103 if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
104 snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
108 if (strcmp(tokens[8], "cpu") != 0) {
109 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
113 if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
114 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
118 mempool = mempool_create(name, &p);
119 if (mempool == NULL) {
120 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
125 static const char cmd_link_help[] =
127 " dev <device_name> | port <port_id>\n"
128 " rxq <n_queues> <queue_size> <mempool_name>\n"
129 " txq <n_queues> <queue_size>\n"
130 " promiscuous on | off\n"
131 " [rss <qid_0> ... <qid_n>]\n";
134 cmd_link(char **tokens,
139 struct link_params p;
140 struct link_params_rss rss;
144 memset(&p, 0, sizeof(p));
146 if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
147 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
152 if (strcmp(tokens[2], "dev") == 0)
153 p.dev_name = tokens[3];
154 else if (strcmp(tokens[2], "port") == 0) {
157 if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
158 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
162 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
166 if (strcmp(tokens[4], "rxq") != 0) {
167 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
171 if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
172 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
175 if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
176 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
180 p.rx.mempool_name = tokens[7];
182 if (strcmp(tokens[8], "txq") != 0) {
183 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
187 if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
188 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
192 if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
193 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
197 if (strcmp(tokens[11], "promiscuous") != 0) {
198 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
202 if (strcmp(tokens[12], "on") == 0)
204 else if (strcmp(tokens[12], "off") == 0)
207 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
214 uint32_t queue_id, i;
216 if (strcmp(tokens[13], "rss") != 0) {
217 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
224 for (i = 14; i < n_tokens; i++) {
225 if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
226 snprintf(out, out_size, MSG_ARG_INVALID,
231 rss.queue_id[rss.n_queues] = queue_id;
236 link = link_create(name, &p);
238 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
243 /* Print the link stats and info */
245 print_link_info(struct link *link, char *out, size_t out_size)
247 struct rte_eth_stats stats;
248 struct rte_ether_addr mac_addr;
249 struct rte_eth_link eth_link;
253 memset(&stats, 0, sizeof(stats));
254 rte_eth_stats_get(link->port_id, &stats);
256 ret = rte_eth_macaddr_get(link->port_id, &mac_addr);
258 snprintf(out, out_size, "\n%s: MAC address get failed: %s",
259 link->name, rte_strerror(-ret));
263 ret = rte_eth_link_get(link->port_id, ð_link);
265 snprintf(out, out_size, "\n%s: link get failed: %s",
266 link->name, rte_strerror(-ret));
270 rte_eth_dev_get_mtu(link->port_id, &mtu);
272 snprintf(out, out_size,
274 "%s: flags=<%s> mtu %u\n"
275 "\tether %02X:%02X:%02X:%02X:%02X:%02X rxqueues %u txqueues %u\n"
276 "\tport# %u speed %s\n"
277 "\tRX packets %" PRIu64" bytes %" PRIu64"\n"
278 "\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n"
279 "\tTX packets %" PRIu64" bytes %" PRIu64"\n"
280 "\tTX errors %" PRIu64"\n",
282 eth_link.link_status == 0 ? "DOWN" : "UP",
284 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
285 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
286 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5],
290 rte_eth_link_speed_to_str(eth_link.link_speed),
302 * link show [<link_name>]
305 cmd_link_show(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
310 if (n_tokens != 2 && n_tokens != 3) {
311 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
316 link = link_next(NULL);
318 while (link != NULL) {
319 out_size = out_size - strlen(out);
320 out = &out[strlen(out)];
322 print_link_info(link, out, out_size);
323 link = link_next(link);
326 out_size = out_size - strlen(out);
327 out = &out[strlen(out)];
329 link_name = tokens[2];
330 link = link_find(link_name);
333 snprintf(out, out_size, MSG_ARG_INVALID,
334 "Link does not exist");
337 print_link_info(link, out, out_size);
341 static const char cmd_swq_help[] =
347 cmd_swq(char **tokens,
357 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
363 if (strcmp(tokens[2], "size") != 0) {
364 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
368 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
369 snprintf(out, out_size, MSG_ARG_INVALID, "size");
373 if (strcmp(tokens[4], "cpu") != 0) {
374 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
378 if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
379 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
383 swq = swq_create(name, &p);
385 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
390 static const char cmd_tmgr_subport_profile_help[] =
391 "tmgr subport profile\n"
392 " <tb_rate> <tb_size>\n"
393 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
394 " <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
395 " <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
397 " pps <n_pipes_per_subport>\n"
398 " qsize <qsize_tc0> <qsize_tc1> <qsize_tc2>"
399 " <qsize_tc3> <qsize_tc4> <qsize_tc5> <qsize_tc6>"
400 " <qsize_tc7> <qsize_tc8> <qsize_tc9> <qsize_tc10>"
401 " <qsize_tc11> <qsize_tc12>";
404 cmd_tmgr_subport_profile(char **tokens,
409 struct rte_sched_subport_params p;
412 if (n_tokens != 35) {
413 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
417 if (parser_read_uint64(&p.tb_rate, tokens[3]) != 0) {
418 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
422 if (parser_read_uint64(&p.tb_size, tokens[4]) != 0) {
423 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
427 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
428 if (parser_read_uint64(&p.tc_rate[i], tokens[5 + i]) != 0) {
429 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
433 if (parser_read_uint64(&p.tc_period, tokens[18]) != 0) {
434 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
438 if (strcmp(tokens[19], "pps") != 0) {
439 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
443 if (parser_read_uint32(&p.n_pipes_per_subport_enabled, tokens[20]) != 0) {
444 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
448 if (strcmp(tokens[21], "qsize") != 0) {
449 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "qsize");
453 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
454 if (parser_read_uint16(&p.qsize[i], tokens[22 + i]) != 0) {
455 snprintf(out, out_size, MSG_ARG_INVALID, "qsize");
459 status = tmgr_subport_profile_add(&p);
461 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
466 static const char cmd_tmgr_pipe_profile_help[] =
467 "tmgr pipe profile\n"
468 " <tb_rate> <tb_size>\n"
469 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
470 " <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
471 " <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
474 " <wrr_weight0..3>\n";
477 cmd_tmgr_pipe_profile(char **tokens,
482 struct rte_sched_pipe_params p;
485 if (n_tokens != 24) {
486 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
490 if (parser_read_uint64(&p.tb_rate, tokens[3]) != 0) {
491 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
495 if (parser_read_uint64(&p.tb_size, tokens[4]) != 0) {
496 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
500 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
501 if (parser_read_uint64(&p.tc_rate[i], tokens[5 + i]) != 0) {
502 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
506 if (parser_read_uint64(&p.tc_period, tokens[18]) != 0) {
507 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
511 if (parser_read_uint8(&p.tc_ov_weight, tokens[19]) != 0) {
512 snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
516 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++)
517 if (parser_read_uint8(&p.wrr_weights[i], tokens[20 + i]) != 0) {
518 snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
522 status = tmgr_pipe_profile_add(&p);
524 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
529 static const char cmd_tmgr_help[] =
532 " spp <n_subports_per_port>\n"
533 " fo <frame_overhead>\n"
538 cmd_tmgr(char **tokens,
543 struct tmgr_port_params p;
545 struct tmgr_port *tmgr_port;
547 if (n_tokens != 12) {
548 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
554 if (strcmp(tokens[2], "rate") != 0) {
555 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
559 if (parser_read_uint64(&p.rate, tokens[3]) != 0) {
560 snprintf(out, out_size, MSG_ARG_INVALID, "rate");
564 if (strcmp(tokens[4], "spp") != 0) {
565 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
569 if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
570 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
574 if (strcmp(tokens[6], "fo") != 0) {
575 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
579 if (parser_read_uint32(&p.frame_overhead, tokens[7]) != 0) {
580 snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
584 if (strcmp(tokens[8], "mtu") != 0) {
585 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
589 if (parser_read_uint32(&p.mtu, tokens[9]) != 0) {
590 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
594 if (strcmp(tokens[10], "cpu") != 0) {
595 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
599 if (parser_read_uint32(&p.cpu_id, tokens[11]) != 0) {
600 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
604 tmgr_port = tmgr_port_create(name, &p);
605 if (tmgr_port == NULL) {
606 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
611 static const char cmd_tmgr_subport_help[] =
612 "tmgr <tmgr_name> subport <subport_id>\n"
613 " profile <subport_profile_id>\n";
616 cmd_tmgr_subport(char **tokens,
621 uint32_t subport_id, subport_profile_id;
626 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
632 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
633 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
637 if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
638 snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
642 status = tmgr_subport_config(name, subport_id, subport_profile_id);
644 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
650 static const char cmd_tmgr_subport_pipe_help[] =
651 "tmgr <tmgr_name> subport <subport_id> pipe\n"
652 " from <pipe_id_first> to <pipe_id_last>\n"
653 " profile <pipe_profile_id>\n";
656 cmd_tmgr_subport_pipe(char **tokens,
661 uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
665 if (n_tokens != 11) {
666 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
672 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
673 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
677 if (strcmp(tokens[4], "pipe") != 0) {
678 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
682 if (strcmp(tokens[5], "from") != 0) {
683 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
687 if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
688 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
692 if (strcmp(tokens[7], "to") != 0) {
693 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
697 if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
698 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
702 if (strcmp(tokens[9], "profile") != 0) {
703 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
707 if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
708 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
712 status = tmgr_pipe_config(name, subport_id, pipe_id_first,
713 pipe_id_last, pipe_profile_id);
715 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
721 static const char cmd_tap_help[] =
725 cmd_tap(char **tokens,
734 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
740 tap = tap_create(name);
742 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
747 static const char cmd_kni_help[] =
749 " link <link_name>\n"
750 " mempool <mempool_name>\n"
751 " [thread <thread_id>]\n";
754 cmd_kni(char **tokens,
763 memset(&p, 0, sizeof(p));
764 if ((n_tokens != 6) && (n_tokens != 8)) {
765 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
771 if (strcmp(tokens[2], "link") != 0) {
772 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
776 p.link_name = tokens[3];
778 if (strcmp(tokens[4], "mempool") != 0) {
779 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
783 p.mempool_name = tokens[5];
786 if (strcmp(tokens[6], "thread") != 0) {
787 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
791 if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
792 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
800 kni = kni_create(name, &p);
802 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
807 static const char cmd_cryptodev_help[] =
808 "cryptodev <cryptodev_name>\n"
809 " dev <device_name> | dev_id <device_id>\n"
810 " queue <n_queues> <queue_size>\n"
811 " max_sessions <n_sessions>";
814 cmd_cryptodev(char **tokens,
819 struct cryptodev_params params;
822 memset(¶ms, 0, sizeof(params));
824 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
830 if (strcmp(tokens[2], "dev") == 0)
831 params.dev_name = tokens[3];
832 else if (strcmp(tokens[2], "dev_id") == 0) {
833 if (parser_read_uint32(¶ms.dev_id, tokens[3]) < 0) {
834 snprintf(out, out_size, MSG_ARG_INVALID,
839 snprintf(out, out_size, MSG_ARG_INVALID,
844 if (strcmp(tokens[4], "queue")) {
845 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
850 if (parser_read_uint32(¶ms.n_queues, tokens[5]) < 0) {
851 snprintf(out, out_size, MSG_ARG_INVALID,
856 if (parser_read_uint32(¶ms.queue_size, tokens[6]) < 0) {
857 snprintf(out, out_size, MSG_ARG_INVALID,
862 if (strcmp(tokens[7], "max_sessions")) {
863 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
868 if (parser_read_uint32(¶ms.session_pool_size, tokens[8]) < 0) {
869 snprintf(out, out_size, MSG_ARG_INVALID,
874 if (cryptodev_create(name, ¶ms) == NULL) {
875 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
880 static const char cmd_port_in_action_profile_help[] =
881 "port in action profile <profile_name>\n"
882 " [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]\n"
883 " [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]\n";
886 cmd_port_in_action_profile(char **tokens,
891 struct port_in_action_profile_params p;
892 struct port_in_action_profile *ap;
896 memset(&p, 0, sizeof(p));
899 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
903 if (strcmp(tokens[1], "in") != 0) {
904 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
908 if (strcmp(tokens[2], "action") != 0) {
909 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
913 if (strcmp(tokens[3], "profile") != 0) {
914 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
922 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
925 if (n_tokens < t0 + 10) {
926 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
930 if (strcmp(tokens[t0 + 1], "match") == 0)
931 p.fltr.filter_on_match = 1;
932 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
933 p.fltr.filter_on_match = 0;
935 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
939 if (strcmp(tokens[t0 + 2], "offset") != 0) {
940 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
944 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
945 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
949 if (strcmp(tokens[t0 + 4], "mask") != 0) {
950 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
954 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
955 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
956 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
957 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
961 if (strcmp(tokens[t0 + 6], "key") != 0) {
962 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
966 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
967 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
968 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
969 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
973 if (strcmp(tokens[t0 + 8], "port") != 0) {
974 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
978 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
979 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
983 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
987 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
990 if (n_tokens < t0 + 22) {
991 snprintf(out, out_size, MSG_ARG_MISMATCH,
992 "port in action profile balance");
996 if (strcmp(tokens[t0 + 1], "offset") != 0) {
997 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1001 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1002 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1006 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1007 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1011 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1012 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1013 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1017 if (strcmp(tokens[t0 + 5], "port") != 0) {
1018 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1022 for (i = 0; i < 16; i++)
1023 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
1024 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1028 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
1032 if (t0 < n_tokens) {
1033 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1037 ap = port_in_action_profile_create(name, &p);
1039 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1045 static const char cmd_table_action_profile_help[] =
1046 "table action profile <profile_name>\n"
1048 " offset <ip_offset>\n"
1050 " [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]\n"
1051 " [meter srtcm | trtcm\n"
1053 " stats none | pkts | bytes | both]\n"
1054 " [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]\n"
1055 " [encap ether | vlan | qinq | mpls | pppoe | qinq_pppoe \n"
1056 " vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]\n"
1058 " proto udp | tcp]\n"
1059 " [ttl drop | fwd\n"
1060 " stats none | pkts]\n"
1061 " [stats pkts | bytes | both]\n"
1063 " [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
1068 cmd_table_action_profile(char **tokens,
1073 struct table_action_profile_params p;
1074 struct table_action_profile *ap;
1078 memset(&p, 0, sizeof(p));
1081 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1085 if (strcmp(tokens[1], "action") != 0) {
1086 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1090 if (strcmp(tokens[2], "profile") != 0) {
1091 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1097 if (strcmp(tokens[4], "ipv4") == 0)
1098 p.common.ip_version = 1;
1099 else if (strcmp(tokens[4], "ipv6") == 0)
1100 p.common.ip_version = 0;
1102 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1106 if (strcmp(tokens[5], "offset") != 0) {
1107 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1111 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
1112 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1116 if (strcmp(tokens[7], "fwd") != 0) {
1117 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1121 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1124 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
1125 if (n_tokens < t0 + 7) {
1126 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1130 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1131 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1135 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1136 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1140 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1141 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1145 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1146 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1147 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1151 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1152 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1156 if (parser_read_uint32(&p.lb.out_offset, tokens[t0 + 6]) != 0) {
1157 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1161 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1165 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
1166 if (n_tokens < t0 + 6) {
1167 snprintf(out, out_size, MSG_ARG_MISMATCH,
1168 "table action profile meter");
1172 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
1173 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1174 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
1175 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1177 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1182 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1183 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1187 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
1188 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1192 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1193 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1197 if (strcmp(tokens[t0 + 5], "none") == 0) {
1198 p.mtr.n_packets_enabled = 0;
1199 p.mtr.n_bytes_enabled = 0;
1200 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1201 p.mtr.n_packets_enabled = 1;
1202 p.mtr.n_bytes_enabled = 0;
1203 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1204 p.mtr.n_packets_enabled = 0;
1205 p.mtr.n_bytes_enabled = 1;
1206 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1207 p.mtr.n_packets_enabled = 1;
1208 p.mtr.n_bytes_enabled = 1;
1210 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1211 "none or pkts or bytes or both");
1215 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1219 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
1220 if (n_tokens < t0 + 5) {
1221 snprintf(out, out_size, MSG_ARG_MISMATCH,
1222 "table action profile tm");
1226 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1227 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1231 if (parser_read_uint32(&p.tm.n_subports_per_port,
1232 tokens[t0 + 2]) != 0) {
1233 snprintf(out, out_size, MSG_ARG_INVALID,
1234 "n_subports_per_port");
1238 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1239 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1243 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1244 tokens[t0 + 4]) != 0) {
1245 snprintf(out, out_size, MSG_ARG_INVALID,
1246 "n_pipes_per_subport");
1250 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1254 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1255 uint32_t n_extra_tokens = 0;
1257 if (n_tokens < t0 + 2) {
1258 snprintf(out, out_size, MSG_ARG_MISMATCH,
1259 "action profile encap");
1263 if (strcmp(tokens[t0 + 1], "ether") == 0)
1264 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1265 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1266 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1267 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1268 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1269 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1270 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1271 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1272 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1273 else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1274 if (n_tokens < t0 + 2 + 5) {
1275 snprintf(out, out_size, MSG_ARG_MISMATCH,
1276 "action profile encap vxlan");
1280 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1281 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1286 if (parser_read_uint32(&p.encap.vxlan.data_offset,
1287 tokens[t0 + 2 + 1]) != 0) {
1288 snprintf(out, out_size, MSG_ARG_INVALID,
1289 "vxlan: ether_offset");
1293 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1294 p.encap.vxlan.ip_version = 1;
1295 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1296 p.encap.vxlan.ip_version = 0;
1298 snprintf(out, out_size, MSG_ARG_INVALID,
1299 "vxlan: ipv4 or ipv6");
1303 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1304 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1309 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
1310 p.encap.vxlan.vlan = 1;
1311 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
1312 p.encap.vxlan.vlan = 0;
1314 snprintf(out, out_size, MSG_ARG_INVALID,
1315 "vxlan: on or off");
1319 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
1321 } else if (strcmp(tokens[t0 + 1], "qinq_pppoe") == 0)
1322 p.encap.encap_mask =
1323 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
1325 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1329 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1330 t0 += 2 + n_extra_tokens;
1333 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1334 if (n_tokens < t0 + 4) {
1335 snprintf(out, out_size, MSG_ARG_MISMATCH,
1336 "table action profile nat");
1340 if (strcmp(tokens[t0 + 1], "src") == 0)
1341 p.nat.source_nat = 1;
1342 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1343 p.nat.source_nat = 0;
1345 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1350 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1351 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1355 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1357 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1360 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1365 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1369 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1370 if (n_tokens < t0 + 4) {
1371 snprintf(out, out_size, MSG_ARG_MISMATCH,
1372 "table action profile ttl");
1376 if (strcmp(tokens[t0 + 1], "drop") == 0)
1378 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1381 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1386 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1387 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1391 if (strcmp(tokens[t0 + 3], "none") == 0)
1392 p.ttl.n_packets_enabled = 0;
1393 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1394 p.ttl.n_packets_enabled = 1;
1396 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1401 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1405 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1406 if (n_tokens < t0 + 2) {
1407 snprintf(out, out_size, MSG_ARG_MISMATCH,
1408 "table action profile stats");
1412 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1413 p.stats.n_packets_enabled = 1;
1414 p.stats.n_bytes_enabled = 0;
1415 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1416 p.stats.n_packets_enabled = 0;
1417 p.stats.n_bytes_enabled = 1;
1418 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1419 p.stats.n_packets_enabled = 1;
1420 p.stats.n_bytes_enabled = 1;
1422 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1423 "pkts or bytes or both");
1427 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1431 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1432 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1436 if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
1437 struct cryptodev *cryptodev;
1439 if (n_tokens < t0 + 5 ||
1440 strcmp(tokens[t0 + 1], "dev") ||
1441 strcmp(tokens[t0 + 3], "offset")) {
1442 snprintf(out, out_size, MSG_ARG_MISMATCH,
1443 "table action profile sym_crypto");
1447 cryptodev = cryptodev_find(tokens[t0 + 2]);
1448 if (cryptodev == NULL) {
1449 snprintf(out, out_size, MSG_ARG_INVALID,
1450 "table action profile sym_crypto");
1454 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
1456 if (parser_read_uint32(&p.sym_crypto.op_offset,
1457 tokens[t0 + 4]) != 0) {
1458 snprintf(out, out_size, MSG_ARG_INVALID,
1459 "table action profile sym_crypto");
1463 p.sym_crypto.mp_create = cryptodev->mp_create;
1464 p.sym_crypto.mp_init = cryptodev->mp_init;
1466 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
1471 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {
1472 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
1476 if ((t0 < n_tokens) && (strcmp(tokens[t0], "decap") == 0)) {
1477 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1481 if (t0 < n_tokens) {
1482 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1486 ap = table_action_profile_create(name, &p);
1488 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1493 static const char cmd_pipeline_help[] =
1494 "pipeline <pipeline_name>\n"
1495 " period <timer_period_ms>\n"
1496 " offset_port_id <offset_port_id>\n"
1500 cmd_pipeline(char **tokens,
1505 struct pipeline_params p;
1507 struct pipeline *pipeline;
1509 if (n_tokens != 8) {
1510 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1516 if (strcmp(tokens[2], "period") != 0) {
1517 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1521 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1522 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1526 if (strcmp(tokens[4], "offset_port_id") != 0) {
1527 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1531 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1532 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1536 if (strcmp(tokens[6], "cpu") != 0) {
1537 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1541 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1542 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1546 pipeline = pipeline_create(name, &p);
1547 if (pipeline == NULL) {
1548 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1553 static const char cmd_pipeline_port_in_help[] =
1554 "pipeline <pipeline_name> port in\n"
1555 " bsz <burst_size>\n"
1556 " link <link_name> rxq <queue_id>\n"
1557 " | swq <swq_name>\n"
1558 " | tmgr <tmgr_name>\n"
1559 " | tap <tap_name> mempool <mempool_name> mtu <mtu>\n"
1560 " | kni <kni_name>\n"
1561 " | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>\n"
1562 " | cryptodev <cryptodev_name> rxq <queue_id>\n"
1563 " [action <port_in_action_profile_name>]\n"
1567 cmd_pipeline_port_in(char **tokens,
1572 struct port_in_params p;
1573 char *pipeline_name;
1575 int enabled, status;
1578 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1582 pipeline_name = tokens[1];
1584 if (strcmp(tokens[2], "port") != 0) {
1585 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1589 if (strcmp(tokens[3], "in") != 0) {
1590 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1594 if (strcmp(tokens[4], "bsz") != 0) {
1595 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1599 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1600 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1606 if (strcmp(tokens[t0], "link") == 0) {
1607 if (n_tokens < t0 + 4) {
1608 snprintf(out, out_size, MSG_ARG_MISMATCH,
1609 "pipeline port in link");
1613 p.type = PORT_IN_RXQ;
1615 p.dev_name = tokens[t0 + 1];
1617 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1618 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1622 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1623 snprintf(out, out_size, MSG_ARG_INVALID,
1628 } else if (strcmp(tokens[t0], "swq") == 0) {
1629 if (n_tokens < t0 + 2) {
1630 snprintf(out, out_size, MSG_ARG_MISMATCH,
1631 "pipeline port in swq");
1635 p.type = PORT_IN_SWQ;
1637 p.dev_name = tokens[t0 + 1];
1640 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1641 if (n_tokens < t0 + 2) {
1642 snprintf(out, out_size, MSG_ARG_MISMATCH,
1643 "pipeline port in tmgr");
1647 p.type = PORT_IN_TMGR;
1649 p.dev_name = tokens[t0 + 1];
1652 } else if (strcmp(tokens[t0], "tap") == 0) {
1653 if (n_tokens < t0 + 6) {
1654 snprintf(out, out_size, MSG_ARG_MISMATCH,
1655 "pipeline port in tap");
1659 p.type = PORT_IN_TAP;
1661 p.dev_name = tokens[t0 + 1];
1663 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1664 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1669 p.tap.mempool_name = tokens[t0 + 3];
1671 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1672 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1677 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1678 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1683 } else if (strcmp(tokens[t0], "kni") == 0) {
1684 if (n_tokens < t0 + 2) {
1685 snprintf(out, out_size, MSG_ARG_MISMATCH,
1686 "pipeline port in kni");
1690 p.type = PORT_IN_KNI;
1692 p.dev_name = tokens[t0 + 1];
1695 } else if (strcmp(tokens[t0], "source") == 0) {
1696 if (n_tokens < t0 + 6) {
1697 snprintf(out, out_size, MSG_ARG_MISMATCH,
1698 "pipeline port in source");
1702 p.type = PORT_IN_SOURCE;
1706 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1707 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1712 p.source.mempool_name = tokens[t0 + 2];
1714 if (strcmp(tokens[t0 + 3], "file") != 0) {
1715 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1720 p.source.file_name = tokens[t0 + 4];
1722 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1723 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1728 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1729 snprintf(out, out_size, MSG_ARG_INVALID,
1735 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
1736 if (n_tokens < t0 + 3) {
1737 snprintf(out, out_size, MSG_ARG_MISMATCH,
1738 "pipeline port in cryptodev");
1742 p.type = PORT_IN_CRYPTODEV;
1744 p.dev_name = tokens[t0 + 1];
1745 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1746 snprintf(out, out_size, MSG_ARG_INVALID,
1751 p.cryptodev.arg_callback = NULL;
1752 p.cryptodev.f_callback = NULL;
1756 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1760 p.action_profile_name = NULL;
1761 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1762 if (n_tokens < t0 + 2) {
1763 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1767 p.action_profile_name = tokens[t0 + 1];
1773 if ((n_tokens > t0) &&
1774 (strcmp(tokens[t0], "disabled") == 0)) {
1780 if (n_tokens != t0) {
1781 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1785 status = pipeline_port_in_create(pipeline_name,
1788 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1793 static const char cmd_pipeline_port_out_help[] =
1794 "pipeline <pipeline_name> port out\n"
1795 " bsz <burst_size>\n"
1796 " link <link_name> txq <txq_id>\n"
1797 " | swq <swq_name>\n"
1798 " | tmgr <tmgr_name>\n"
1799 " | tap <tap_name>\n"
1800 " | kni <kni_name>\n"
1801 " | sink [file <file_name> pkts <max_n_pkts>]\n"
1802 " | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>\n";
1805 cmd_pipeline_port_out(char **tokens,
1810 struct port_out_params p;
1811 char *pipeline_name;
1814 memset(&p, 0, sizeof(p));
1817 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1821 pipeline_name = tokens[1];
1823 if (strcmp(tokens[2], "port") != 0) {
1824 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1828 if (strcmp(tokens[3], "out") != 0) {
1829 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1833 if (strcmp(tokens[4], "bsz") != 0) {
1834 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1838 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1839 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1843 if (strcmp(tokens[6], "link") == 0) {
1844 if (n_tokens != 10) {
1845 snprintf(out, out_size, MSG_ARG_MISMATCH,
1846 "pipeline port out link");
1850 p.type = PORT_OUT_TXQ;
1852 p.dev_name = tokens[7];
1854 if (strcmp(tokens[8], "txq") != 0) {
1855 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1859 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1860 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1863 } else if (strcmp(tokens[6], "swq") == 0) {
1864 if (n_tokens != 8) {
1865 snprintf(out, out_size, MSG_ARG_MISMATCH,
1866 "pipeline port out swq");
1870 p.type = PORT_OUT_SWQ;
1872 p.dev_name = tokens[7];
1873 } else if (strcmp(tokens[6], "tmgr") == 0) {
1874 if (n_tokens != 8) {
1875 snprintf(out, out_size, MSG_ARG_MISMATCH,
1876 "pipeline port out tmgr");
1880 p.type = PORT_OUT_TMGR;
1882 p.dev_name = tokens[7];
1883 } else if (strcmp(tokens[6], "tap") == 0) {
1884 if (n_tokens != 8) {
1885 snprintf(out, out_size, MSG_ARG_MISMATCH,
1886 "pipeline port out tap");
1890 p.type = PORT_OUT_TAP;
1892 p.dev_name = tokens[7];
1893 } else if (strcmp(tokens[6], "kni") == 0) {
1894 if (n_tokens != 8) {
1895 snprintf(out, out_size, MSG_ARG_MISMATCH,
1896 "pipeline port out kni");
1900 p.type = PORT_OUT_KNI;
1902 p.dev_name = tokens[7];
1903 } else if (strcmp(tokens[6], "sink") == 0) {
1904 if ((n_tokens != 7) && (n_tokens != 11)) {
1905 snprintf(out, out_size, MSG_ARG_MISMATCH,
1906 "pipeline port out sink");
1910 p.type = PORT_OUT_SINK;
1914 if (n_tokens == 7) {
1915 p.sink.file_name = NULL;
1916 p.sink.max_n_pkts = 0;
1918 if (strcmp(tokens[7], "file") != 0) {
1919 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1924 p.sink.file_name = tokens[8];
1926 if (strcmp(tokens[9], "pkts") != 0) {
1927 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1931 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1932 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1937 } else if (strcmp(tokens[6], "cryptodev") == 0) {
1938 if (n_tokens != 12) {
1939 snprintf(out, out_size, MSG_ARG_MISMATCH,
1940 "pipeline port out cryptodev");
1944 p.type = PORT_OUT_CRYPTODEV;
1946 p.dev_name = tokens[7];
1948 if (strcmp(tokens[8], "txq")) {
1949 snprintf(out, out_size, MSG_ARG_MISMATCH,
1950 "pipeline port out cryptodev");
1954 if (parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
1956 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1960 if (strcmp(tokens[10], "offset")) {
1961 snprintf(out, out_size, MSG_ARG_MISMATCH,
1962 "pipeline port out cryptodev");
1966 if (parser_read_uint32(&p.cryptodev.op_offset, tokens[11])
1968 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1972 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1976 status = pipeline_port_out_create(pipeline_name, &p);
1978 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1983 static const char cmd_pipeline_table_help[] =
1984 "pipeline <pipeline_name> table\n"
1988 " offset <ip_header_offset>\n"
1991 " offset <key_offset>\n"
1996 " mask <key_mask>\n"
1997 " offset <key_offset>\n"
1998 " buckets <n_buckets>\n"
2002 " offset <ip_header_offset>\n"
2005 " [action <table_action_profile_name>]\n";
2008 cmd_pipeline_table(char **tokens,
2013 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
2014 struct table_params p;
2015 char *pipeline_name;
2020 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2024 pipeline_name = tokens[1];
2026 if (strcmp(tokens[2], "table") != 0) {
2027 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2031 if (strcmp(tokens[3], "match") != 0) {
2032 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2037 if (strcmp(tokens[t0], "acl") == 0) {
2038 if (n_tokens < t0 + 6) {
2039 snprintf(out, out_size, MSG_ARG_MISMATCH,
2040 "pipeline table acl");
2044 p.match_type = TABLE_ACL;
2046 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2047 p.match.acl.ip_version = 1;
2048 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2049 p.match.acl.ip_version = 0;
2051 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2056 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2057 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2061 if (parser_read_uint32(&p.match.acl.ip_header_offset,
2062 tokens[t0 + 3]) != 0) {
2063 snprintf(out, out_size, MSG_ARG_INVALID,
2064 "ip_header_offset");
2068 if (strcmp(tokens[t0 + 4], "size") != 0) {
2069 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2073 if (parser_read_uint32(&p.match.acl.n_rules,
2074 tokens[t0 + 5]) != 0) {
2075 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2080 } else if (strcmp(tokens[t0], "array") == 0) {
2081 if (n_tokens < t0 + 5) {
2082 snprintf(out, out_size, MSG_ARG_MISMATCH,
2083 "pipeline table array");
2087 p.match_type = TABLE_ARRAY;
2089 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2090 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2094 if (parser_read_uint32(&p.match.array.key_offset,
2095 tokens[t0 + 2]) != 0) {
2096 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2100 if (strcmp(tokens[t0 + 3], "size") != 0) {
2101 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2105 if (parser_read_uint32(&p.match.array.n_keys,
2106 tokens[t0 + 4]) != 0) {
2107 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2112 } else if (strcmp(tokens[t0], "hash") == 0) {
2113 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2115 if (n_tokens < t0 + 12) {
2116 snprintf(out, out_size, MSG_ARG_MISMATCH,
2117 "pipeline table hash");
2121 p.match_type = TABLE_HASH;
2123 if (strcmp(tokens[t0 + 1], "ext") == 0)
2124 p.match.hash.extendable_bucket = 1;
2125 else if (strcmp(tokens[t0 + 1], "lru") == 0)
2126 p.match.hash.extendable_bucket = 0;
2128 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2133 if (strcmp(tokens[t0 + 2], "key") != 0) {
2134 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2138 if ((parser_read_uint32(&p.match.hash.key_size,
2139 tokens[t0 + 3]) != 0) ||
2140 (p.match.hash.key_size == 0) ||
2141 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
2142 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2146 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2147 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2151 if ((parse_hex_string(tokens[t0 + 5],
2152 key_mask, &key_mask_size) != 0) ||
2153 (key_mask_size != p.match.hash.key_size)) {
2154 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2157 p.match.hash.key_mask = key_mask;
2159 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2160 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2164 if (parser_read_uint32(&p.match.hash.key_offset,
2165 tokens[t0 + 7]) != 0) {
2166 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2170 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2171 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2175 if (parser_read_uint32(&p.match.hash.n_buckets,
2176 tokens[t0 + 9]) != 0) {
2177 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2181 if (strcmp(tokens[t0 + 10], "size") != 0) {
2182 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2186 if (parser_read_uint32(&p.match.hash.n_keys,
2187 tokens[t0 + 11]) != 0) {
2188 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2193 } else if (strcmp(tokens[t0], "lpm") == 0) {
2194 if (n_tokens < t0 + 6) {
2195 snprintf(out, out_size, MSG_ARG_MISMATCH,
2196 "pipeline table lpm");
2200 p.match_type = TABLE_LPM;
2202 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2203 p.match.lpm.key_size = 4;
2204 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2205 p.match.lpm.key_size = 16;
2207 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2212 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2213 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2217 if (parser_read_uint32(&p.match.lpm.key_offset,
2218 tokens[t0 + 3]) != 0) {
2219 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2223 if (strcmp(tokens[t0 + 4], "size") != 0) {
2224 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2228 if (parser_read_uint32(&p.match.lpm.n_rules,
2229 tokens[t0 + 5]) != 0) {
2230 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2235 } else if (strcmp(tokens[t0], "stub") == 0) {
2236 p.match_type = TABLE_STUB;
2240 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2244 p.action_profile_name = NULL;
2245 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
2246 if (n_tokens < t0 + 2) {
2247 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2251 p.action_profile_name = tokens[t0 + 1];
2256 if (n_tokens > t0) {
2257 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2261 status = pipeline_table_create(pipeline_name, &p);
2263 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2268 static const char cmd_pipeline_port_in_table_help[] =
2269 "pipeline <pipeline_name> port in <port_id> table <table_id>\n";
2272 cmd_pipeline_port_in_table(char **tokens,
2277 char *pipeline_name;
2278 uint32_t port_id, table_id;
2281 if (n_tokens != 7) {
2282 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2286 pipeline_name = tokens[1];
2288 if (strcmp(tokens[2], "port") != 0) {
2289 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2293 if (strcmp(tokens[3], "in") != 0) {
2294 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2298 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2299 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2303 if (strcmp(tokens[5], "table") != 0) {
2304 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2308 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
2309 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2313 status = pipeline_port_in_connect_to_table(pipeline_name,
2317 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2323 static const char cmd_pipeline_port_in_stats_help[] =
2324 "pipeline <pipeline_name> port in <port_id> stats read [clear]\n";
2326 #define MSG_PIPELINE_PORT_IN_STATS \
2327 "Pkts in: %" PRIu64 "\n" \
2328 "Pkts dropped by AH: %" PRIu64 "\n" \
2329 "Pkts dropped by other: %" PRIu64 "\n"
2332 cmd_pipeline_port_in_stats(char **tokens,
2337 struct rte_pipeline_port_in_stats stats;
2338 char *pipeline_name;
2342 if ((n_tokens != 7) && (n_tokens != 8)) {
2343 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2347 pipeline_name = tokens[1];
2349 if (strcmp(tokens[2], "port") != 0) {
2350 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2354 if (strcmp(tokens[3], "in") != 0) {
2355 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2359 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2360 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2364 if (strcmp(tokens[5], "stats") != 0) {
2365 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2369 if (strcmp(tokens[6], "read") != 0) {
2370 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2375 if (n_tokens == 8) {
2376 if (strcmp(tokens[7], "clear") != 0) {
2377 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2384 status = pipeline_port_in_stats_read(pipeline_name,
2389 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2393 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2394 stats.stats.n_pkts_in,
2395 stats.n_pkts_dropped_by_ah,
2396 stats.stats.n_pkts_drop);
2400 static const char cmd_pipeline_port_in_enable_help[] =
2401 "pipeline <pipeline_name> port in <port_id> enable\n";
2404 cmd_pipeline_port_in_enable(char **tokens,
2409 char *pipeline_name;
2413 if (n_tokens != 6) {
2414 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2418 pipeline_name = tokens[1];
2420 if (strcmp(tokens[2], "port") != 0) {
2421 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2425 if (strcmp(tokens[3], "in") != 0) {
2426 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2430 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2431 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2435 if (strcmp(tokens[5], "enable") != 0) {
2436 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2440 status = pipeline_port_in_enable(pipeline_name, port_id);
2442 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2448 static const char cmd_pipeline_port_in_disable_help[] =
2449 "pipeline <pipeline_name> port in <port_id> disable\n";
2452 cmd_pipeline_port_in_disable(char **tokens,
2457 char *pipeline_name;
2461 if (n_tokens != 6) {
2462 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2466 pipeline_name = tokens[1];
2468 if (strcmp(tokens[2], "port") != 0) {
2469 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2473 if (strcmp(tokens[3], "in") != 0) {
2474 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2478 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2479 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2483 if (strcmp(tokens[5], "disable") != 0) {
2484 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2488 status = pipeline_port_in_disable(pipeline_name, port_id);
2490 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2496 static const char cmd_pipeline_port_out_stats_help[] =
2497 "pipeline <pipeline_name> port out <port_id> stats read [clear]\n";
2499 #define MSG_PIPELINE_PORT_OUT_STATS \
2500 "Pkts in: %" PRIu64 "\n" \
2501 "Pkts dropped by AH: %" PRIu64 "\n" \
2502 "Pkts dropped by other: %" PRIu64 "\n"
2505 cmd_pipeline_port_out_stats(char **tokens,
2510 struct rte_pipeline_port_out_stats stats;
2511 char *pipeline_name;
2515 if ((n_tokens != 7) && (n_tokens != 8)) {
2516 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2520 pipeline_name = tokens[1];
2522 if (strcmp(tokens[2], "port") != 0) {
2523 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2527 if (strcmp(tokens[3], "out") != 0) {
2528 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2532 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2533 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2537 if (strcmp(tokens[5], "stats") != 0) {
2538 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2542 if (strcmp(tokens[6], "read") != 0) {
2543 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2548 if (n_tokens == 8) {
2549 if (strcmp(tokens[7], "clear") != 0) {
2550 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2557 status = pipeline_port_out_stats_read(pipeline_name,
2562 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2566 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2567 stats.stats.n_pkts_in,
2568 stats.n_pkts_dropped_by_ah,
2569 stats.stats.n_pkts_drop);
2573 static const char cmd_pipeline_table_stats_help[] =
2574 "pipeline <pipeline_name> table <table_id> stats read [clear]\n";
2576 #define MSG_PIPELINE_TABLE_STATS \
2577 "Pkts in: %" PRIu64 "\n" \
2578 "Pkts in with lookup miss: %" PRIu64 "\n" \
2579 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2580 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2581 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2582 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2585 cmd_pipeline_table_stats(char **tokens,
2590 struct rte_pipeline_table_stats stats;
2591 char *pipeline_name;
2595 if ((n_tokens != 6) && (n_tokens != 7)) {
2596 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2600 pipeline_name = tokens[1];
2602 if (strcmp(tokens[2], "table") != 0) {
2603 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2607 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2608 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2612 if (strcmp(tokens[4], "stats") != 0) {
2613 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2617 if (strcmp(tokens[5], "read") != 0) {
2618 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2623 if (n_tokens == 7) {
2624 if (strcmp(tokens[6], "clear") != 0) {
2625 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2632 status = pipeline_table_stats_read(pipeline_name,
2637 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2641 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2642 stats.stats.n_pkts_in,
2643 stats.stats.n_pkts_lookup_miss,
2644 stats.n_pkts_dropped_by_lkp_hit_ah,
2645 stats.n_pkts_dropped_lkp_hit,
2646 stats.n_pkts_dropped_by_lkp_miss_ah,
2647 stats.n_pkts_dropped_lkp_miss);
2655 * priority <priority>
2656 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2657 * <sp0> <sp1> <dp0> <dp1> <proto>
2661 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2662 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2663 * | ipv4_addr <addr>
2664 * | ipv6_addr <addr>
2665 * | qinq <svlan> <cvlan>
2667 * ipv4 | ipv6 <addr> <depth>
2669 struct pkt_key_qinq {
2670 uint16_t ethertype_svlan;
2672 uint16_t ethertype_cvlan;
2676 struct pkt_key_ipv4_5tuple {
2677 uint8_t time_to_live;
2679 uint16_t hdr_checksum;
2686 struct pkt_key_ipv6_5tuple {
2687 uint16_t payload_length;
2696 struct pkt_key_ipv4_addr {
2700 struct pkt_key_ipv6_addr {
2705 parse_match(char **tokens,
2709 struct table_rule_match *m)
2711 memset(m, 0, sizeof(*m));
2716 if (strcmp(tokens[0], "match") != 0) {
2717 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2721 if (strcmp(tokens[1], "acl") == 0) {
2722 if (n_tokens < 14) {
2723 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2727 m->match_type = TABLE_ACL;
2729 if (strcmp(tokens[2], "priority") != 0) {
2730 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2734 if (parser_read_uint32(&m->match.acl.priority,
2736 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2740 if (strcmp(tokens[4], "ipv4") == 0) {
2741 struct in_addr saddr, daddr;
2743 m->match.acl.ip_version = 1;
2745 if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2746 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2749 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2751 if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2752 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2755 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2756 } else if (strcmp(tokens[4], "ipv6") == 0) {
2757 struct in6_addr saddr, daddr;
2759 m->match.acl.ip_version = 0;
2761 if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2762 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2765 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2767 if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2768 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2771 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2773 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2778 if (parser_read_uint32(&m->match.acl.sa_depth,
2780 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2784 if (parser_read_uint32(&m->match.acl.da_depth,
2786 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2790 if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2791 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2795 if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2796 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2800 if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2801 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2805 if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2806 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2810 if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2811 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2815 m->match.acl.proto_mask = 0xff;
2820 if (strcmp(tokens[1], "array") == 0) {
2822 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2826 m->match_type = TABLE_ARRAY;
2828 if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2829 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2836 if (strcmp(tokens[1], "hash") == 0) {
2838 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2842 m->match_type = TABLE_HASH;
2844 if (strcmp(tokens[2], "raw") == 0) {
2845 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2848 snprintf(out, out_size, MSG_ARG_MISMATCH,
2853 if (parse_hex_string(tokens[3],
2854 m->match.hash.key, &key_size) != 0) {
2855 snprintf(out, out_size, MSG_ARG_INVALID, "key");
2862 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2863 struct pkt_key_ipv4_5tuple *ipv4 =
2864 (struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2865 struct in_addr saddr, daddr;
2870 snprintf(out, out_size, MSG_ARG_MISMATCH,
2875 if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2876 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2880 if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2881 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2885 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2886 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2890 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2891 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2895 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2896 snprintf(out, out_size, MSG_ARG_INVALID,
2901 ipv4->sa = saddr.s_addr;
2902 ipv4->da = daddr.s_addr;
2903 ipv4->sp = rte_cpu_to_be_16(sp);
2904 ipv4->dp = rte_cpu_to_be_16(dp);
2905 ipv4->proto = proto;
2908 } /* hash ipv4_5tuple */
2910 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2911 struct pkt_key_ipv6_5tuple *ipv6 =
2912 (struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2913 struct in6_addr saddr, daddr;
2918 snprintf(out, out_size, MSG_ARG_MISMATCH,
2923 if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2924 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2928 if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2929 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2933 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2934 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2938 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2939 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2943 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2944 snprintf(out, out_size, MSG_ARG_INVALID,
2949 memcpy(ipv6->sa, saddr.s6_addr, 16);
2950 memcpy(ipv6->da, daddr.s6_addr, 16);
2951 ipv6->sp = rte_cpu_to_be_16(sp);
2952 ipv6->dp = rte_cpu_to_be_16(dp);
2953 ipv6->proto = proto;
2956 } /* hash ipv6_5tuple */
2958 if (strcmp(tokens[2], "ipv4_addr") == 0) {
2959 struct pkt_key_ipv4_addr *ipv4_addr =
2960 (struct pkt_key_ipv4_addr *) m->match.hash.key;
2961 struct in_addr addr;
2964 snprintf(out, out_size, MSG_ARG_MISMATCH,
2969 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2970 snprintf(out, out_size, MSG_ARG_INVALID,
2975 ipv4_addr->addr = addr.s_addr;
2978 } /* hash ipv4_addr */
2980 if (strcmp(tokens[2], "ipv6_addr") == 0) {
2981 struct pkt_key_ipv6_addr *ipv6_addr =
2982 (struct pkt_key_ipv6_addr *) m->match.hash.key;
2983 struct in6_addr addr;
2986 snprintf(out, out_size, MSG_ARG_MISMATCH,
2991 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2992 snprintf(out, out_size, MSG_ARG_INVALID,
2997 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
3000 } /* hash ipv6_5tuple */
3002 if (strcmp(tokens[2], "qinq") == 0) {
3003 struct pkt_key_qinq *qinq =
3004 (struct pkt_key_qinq *) m->match.hash.key;
3005 uint16_t svlan, cvlan;
3008 snprintf(out, out_size, MSG_ARG_MISMATCH,
3013 if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
3015 snprintf(out, out_size, MSG_ARG_INVALID,
3020 if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3022 snprintf(out, out_size, MSG_ARG_INVALID,
3027 qinq->svlan = rte_cpu_to_be_16(svlan);
3028 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3033 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3037 if (strcmp(tokens[1], "lpm") == 0) {
3039 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3043 m->match_type = TABLE_LPM;
3045 if (strcmp(tokens[2], "ipv4") == 0) {
3046 struct in_addr addr;
3048 m->match.lpm.ip_version = 1;
3050 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
3051 snprintf(out, out_size, MSG_ARG_INVALID,
3056 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3057 } else if (strcmp(tokens[2], "ipv6") == 0) {
3058 struct in6_addr addr;
3060 m->match.lpm.ip_version = 0;
3062 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
3063 snprintf(out, out_size, MSG_ARG_INVALID,
3068 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3070 snprintf(out, out_size, MSG_ARG_MISMATCH,
3075 if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3076 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3083 snprintf(out, out_size, MSG_ARG_MISMATCH,
3084 "acl or array or hash or lpm");
3096 * | table <table_id>
3097 * [balance <out0> ... <out7>]
3099 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3100 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3101 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3102 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3103 * [tm subport <subport_id> pipe <pipe_id>]
3106 * | vlan <da> <sa> <pcp> <dei> <vid>
3107 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3108 * | qinq_pppoe <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid> <session_id>
3109 * | mpls unicast | multicast
3111 * label0 <label> <tc> <ttl>
3112 * [label1 <label> <tc> <ttl>
3113 * [label2 <label> <tc> <ttl>
3114 * [label3 <label> <tc> <ttl>]]]
3115 * | pppoe <da> <sa> <session_id>
3116 * | vxlan ether <da> <sa>
3117 * [vlan <pcp> <dei> <vid>]
3118 * ipv4 <sa> <da> <dscp> <ttl>
3119 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3122 * [nat ipv4 | ipv6 <addr> <port>]
3130 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3132 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3133 * auth_algo <algo> auth_key <key> digest_size <size>
3135 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3136 * digest_size <size>
3137 * data_offset <data_offset>]
3142 * <pa> ::= g | y | r | drop
3145 parse_table_action_fwd(char **tokens,
3147 struct table_rule_action *a)
3149 if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
3155 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3156 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3157 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3161 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3164 if ((n_tokens < 2) ||
3165 parser_read_uint32(&id, tokens[1]))
3168 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3170 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3174 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3175 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3176 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3180 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3183 if ((n_tokens < 2) ||
3184 parser_read_uint32(&id, tokens[1]))
3187 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3189 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3197 parse_table_action_balance(char **tokens,
3199 struct table_rule_action *a)
3203 if ((n_tokens == 0) || (strcmp(tokens[0], "balance") != 0))
3209 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3212 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3213 if (parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3216 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3217 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3222 parse_policer_action(char *token, enum rte_table_action_policer *a)
3224 if (strcmp(token, "g") == 0) {
3225 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3229 if (strcmp(token, "y") == 0) {
3230 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3234 if (strcmp(token, "r") == 0) {
3235 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3239 if (strcmp(token, "drop") == 0) {
3240 *a = RTE_TABLE_ACTION_POLICER_DROP;
3248 parse_table_action_meter_tc(char **tokens,
3250 struct rte_table_action_mtr_tc_params *mtr)
3252 if ((n_tokens < 9) ||
3253 strcmp(tokens[0], "meter") ||
3254 parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3255 strcmp(tokens[2], "policer") ||
3256 strcmp(tokens[3], "g") ||
3257 parse_policer_action(tokens[4], &mtr->policer[RTE_COLOR_GREEN]) ||
3258 strcmp(tokens[5], "y") ||
3259 parse_policer_action(tokens[6], &mtr->policer[RTE_COLOR_YELLOW]) ||
3260 strcmp(tokens[7], "r") ||
3261 parse_policer_action(tokens[8], &mtr->policer[RTE_COLOR_RED]))
3268 parse_table_action_meter(char **tokens,
3270 struct table_rule_action *a)
3272 if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
3278 if ((n_tokens < 10) ||
3279 strcmp(tokens[0], "tc0") ||
3280 (parse_table_action_meter_tc(tokens + 1,
3282 &a->mtr.mtr[0]) == 0))
3288 if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
3290 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3294 if ((n_tokens < 30) ||
3295 (parse_table_action_meter_tc(tokens + 1,
3296 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3297 strcmp(tokens[10], "tc2") ||
3298 (parse_table_action_meter_tc(tokens + 11,
3299 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3300 strcmp(tokens[20], "tc3") ||
3301 (parse_table_action_meter_tc(tokens + 21,
3302 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3305 a->mtr.tc_mask = 0xF;
3306 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3307 return 1 + 10 + 3 * 10;
3311 parse_table_action_tm(char **tokens,
3313 struct table_rule_action *a)
3315 uint32_t subport_id, pipe_id;
3317 if ((n_tokens < 5) ||
3318 strcmp(tokens[0], "tm") ||
3319 strcmp(tokens[1], "subport") ||
3320 parser_read_uint32(&subport_id, tokens[2]) ||
3321 strcmp(tokens[3], "pipe") ||
3322 parser_read_uint32(&pipe_id, tokens[4]))
3325 a->tm.subport_id = subport_id;
3326 a->tm.pipe_id = pipe_id;
3327 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3332 parse_table_action_encap(char **tokens,
3334 struct table_rule_action *a)
3336 if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
3343 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3344 if ((n_tokens < 3) ||
3345 parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3346 parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3349 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3350 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3355 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3356 uint32_t pcp, dei, vid;
3358 if ((n_tokens < 6) ||
3359 parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3360 parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3361 parser_read_uint32(&pcp, tokens[3]) ||
3363 parser_read_uint32(&dei, tokens[4]) ||
3365 parser_read_uint32(&vid, tokens[5]) ||
3369 a->encap.vlan.vlan.pcp = pcp & 0x7;
3370 a->encap.vlan.vlan.dei = dei & 0x1;
3371 a->encap.vlan.vlan.vid = vid & 0xFFF;
3372 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3373 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3378 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3379 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3380 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3382 if ((n_tokens < 9) ||
3383 parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3384 parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3385 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3386 (svlan_pcp > 0x7) ||
3387 parser_read_uint32(&svlan_dei, tokens[4]) ||
3388 (svlan_dei > 0x1) ||
3389 parser_read_uint32(&svlan_vid, tokens[5]) ||
3390 (svlan_vid > 0xFFF) ||
3391 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3392 (cvlan_pcp > 0x7) ||
3393 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3394 (cvlan_dei > 0x1) ||
3395 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3396 (cvlan_vid > 0xFFF))
3399 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3400 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3401 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3402 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3403 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3404 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3405 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3406 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3411 if (n_tokens && (strcmp(tokens[0], "qinq_pppoe") == 0)) {
3412 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3413 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3415 if ((n_tokens < 10) ||
3416 parse_mac_addr(tokens[1],
3417 &a->encap.qinq_pppoe.ether.da) ||
3418 parse_mac_addr(tokens[2],
3419 &a->encap.qinq_pppoe.ether.sa) ||
3420 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3421 (svlan_pcp > 0x7) ||
3422 parser_read_uint32(&svlan_dei, tokens[4]) ||
3423 (svlan_dei > 0x1) ||
3424 parser_read_uint32(&svlan_vid, tokens[5]) ||
3425 (svlan_vid > 0xFFF) ||
3426 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3427 (cvlan_pcp > 0x7) ||
3428 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3429 (cvlan_dei > 0x1) ||
3430 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3431 (cvlan_vid > 0xFFF) ||
3432 parser_read_uint16(&a->encap.qinq_pppoe.pppoe.session_id,
3436 a->encap.qinq_pppoe.svlan.pcp = svlan_pcp & 0x7;
3437 a->encap.qinq_pppoe.svlan.dei = svlan_dei & 0x1;
3438 a->encap.qinq_pppoe.svlan.vid = svlan_vid & 0xFFF;
3439 a->encap.qinq_pppoe.cvlan.pcp = cvlan_pcp & 0x7;
3440 a->encap.qinq_pppoe.cvlan.dei = cvlan_dei & 0x1;
3441 a->encap.qinq_pppoe.cvlan.vid = cvlan_vid & 0xFFF;
3442 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
3443 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3449 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3450 uint32_t label, tc, ttl;
3455 if (strcmp(tokens[1], "unicast") == 0)
3456 a->encap.mpls.unicast = 1;
3457 else if (strcmp(tokens[1], "multicast") == 0)
3458 a->encap.mpls.unicast = 0;
3462 if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3463 parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3464 strcmp(tokens[4], "label0") ||
3465 parser_read_uint32(&label, tokens[5]) ||
3466 (label > 0xFFFFF) ||
3467 parser_read_uint32(&tc, tokens[6]) ||
3469 parser_read_uint32(&ttl, tokens[7]) ||
3473 a->encap.mpls.mpls[0].label = label;
3474 a->encap.mpls.mpls[0].tc = tc;
3475 a->encap.mpls.mpls[0].ttl = ttl;
3480 if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3481 a->encap.mpls.mpls_count = 1;
3482 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3483 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3487 if ((n_tokens < 4) ||
3488 parser_read_uint32(&label, tokens[1]) ||
3489 (label > 0xFFFFF) ||
3490 parser_read_uint32(&tc, tokens[2]) ||
3492 parser_read_uint32(&ttl, tokens[3]) ||
3496 a->encap.mpls.mpls[1].label = label;
3497 a->encap.mpls.mpls[1].tc = tc;
3498 a->encap.mpls.mpls[1].ttl = ttl;
3503 if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3504 a->encap.mpls.mpls_count = 2;
3505 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3506 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3510 if ((n_tokens < 4) ||
3511 parser_read_uint32(&label, tokens[1]) ||
3512 (label > 0xFFFFF) ||
3513 parser_read_uint32(&tc, tokens[2]) ||
3515 parser_read_uint32(&ttl, tokens[3]) ||
3519 a->encap.mpls.mpls[2].label = label;
3520 a->encap.mpls.mpls[2].tc = tc;
3521 a->encap.mpls.mpls[2].ttl = ttl;
3526 if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3527 a->encap.mpls.mpls_count = 3;
3528 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3529 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3530 return 1 + 8 + 4 + 4;
3533 if ((n_tokens < 4) ||
3534 parser_read_uint32(&label, tokens[1]) ||
3535 (label > 0xFFFFF) ||
3536 parser_read_uint32(&tc, tokens[2]) ||
3538 parser_read_uint32(&ttl, tokens[3]) ||
3542 a->encap.mpls.mpls[3].label = label;
3543 a->encap.mpls.mpls[3].tc = tc;
3544 a->encap.mpls.mpls[3].ttl = ttl;
3546 a->encap.mpls.mpls_count = 4;
3547 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3548 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3549 return 1 + 8 + 4 + 4 + 4;
3553 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3554 if ((n_tokens < 4) ||
3555 parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3556 parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3557 parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3561 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3562 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3567 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3574 /* ether <da> <sa> */
3575 if ((n_tokens < 3) ||
3576 strcmp(tokens[0], "ether") ||
3577 parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3578 parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3585 /* [vlan <pcp> <dei> <vid>] */
3586 if (strcmp(tokens[0], "vlan") == 0) {
3587 uint32_t pcp, dei, vid;
3589 if ((n_tokens < 4) ||
3590 parser_read_uint32(&pcp, tokens[1]) ||
3592 parser_read_uint32(&dei, tokens[2]) ||
3594 parser_read_uint32(&vid, tokens[3]) ||
3598 a->encap.vxlan.vlan.pcp = pcp;
3599 a->encap.vxlan.vlan.dei = dei;
3600 a->encap.vxlan.vlan.vid = vid;
3607 /* ipv4 <sa> <da> <dscp> <ttl>
3608 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3609 if (strcmp(tokens[0], "ipv4") == 0) {
3610 struct in_addr sa, da;
3613 if ((n_tokens < 5) ||
3614 parse_ipv4_addr(tokens[1], &sa) ||
3615 parse_ipv4_addr(tokens[2], &da) ||
3616 parser_read_uint8(&dscp, tokens[3]) ||
3618 parser_read_uint8(&ttl, tokens[4]))
3621 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3622 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3623 a->encap.vxlan.ipv4.dscp = dscp;
3624 a->encap.vxlan.ipv4.ttl = ttl;
3629 } else if (strcmp(tokens[0], "ipv6") == 0) {
3630 struct in6_addr sa, da;
3631 uint32_t flow_label;
3632 uint8_t dscp, hop_limit;
3634 if ((n_tokens < 6) ||
3635 parse_ipv6_addr(tokens[1], &sa) ||
3636 parse_ipv6_addr(tokens[2], &da) ||
3637 parser_read_uint32(&flow_label, tokens[3]) ||
3638 parser_read_uint8(&dscp, tokens[4]) ||
3640 parser_read_uint8(&hop_limit, tokens[5]))
3643 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3644 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3645 a->encap.vxlan.ipv6.flow_label = flow_label;
3646 a->encap.vxlan.ipv6.dscp = dscp;
3647 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3656 if ((n_tokens < 3) ||
3657 strcmp(tokens[0], "udp") ||
3658 parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3659 parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3667 if ((n_tokens < 2) ||
3668 strcmp(tokens[0], "vxlan") ||
3669 parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3670 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3677 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3678 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3686 parse_table_action_nat(char **tokens,
3688 struct table_rule_action *a)
3690 if ((n_tokens < 4) ||
3691 strcmp(tokens[0], "nat"))
3694 if (strcmp(tokens[1], "ipv4") == 0) {
3695 struct in_addr addr;
3698 if (parse_ipv4_addr(tokens[2], &addr) ||
3699 parser_read_uint16(&port, tokens[3]))
3702 a->nat.ip_version = 1;
3703 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3705 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3709 if (strcmp(tokens[1], "ipv6") == 0) {
3710 struct in6_addr addr;
3713 if (parse_ipv6_addr(tokens[2], &addr) ||
3714 parser_read_uint16(&port, tokens[3]))
3717 a->nat.ip_version = 0;
3718 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3720 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3728 parse_table_action_ttl(char **tokens,
3730 struct table_rule_action *a)
3732 if ((n_tokens < 2) ||
3733 strcmp(tokens[0], "ttl"))
3736 if (strcmp(tokens[1], "dec") == 0)
3737 a->ttl.decrement = 1;
3738 else if (strcmp(tokens[1], "keep") == 0)
3739 a->ttl.decrement = 0;
3743 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3748 parse_table_action_stats(char **tokens,
3750 struct table_rule_action *a)
3752 if ((n_tokens < 1) ||
3753 strcmp(tokens[0], "stats"))
3756 a->stats.n_packets = 0;
3757 a->stats.n_bytes = 0;
3758 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3763 parse_table_action_time(char **tokens,
3765 struct table_rule_action *a)
3767 if ((n_tokens < 1) ||
3768 strcmp(tokens[0], "time"))
3771 a->time.time = rte_rdtsc();
3772 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3777 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
3779 struct rte_crypto_sym_xform *xform[2] = {NULL};
3782 xform[0] = p->xform;
3784 xform[1] = xform[0]->next;
3786 for (i = 0; i < 2; i++) {
3787 if (xform[i] == NULL)
3790 switch (xform[i]->type) {
3791 case RTE_CRYPTO_SYM_XFORM_CIPHER:
3792 if (p->cipher_auth.cipher_iv.val)
3793 free(p->cipher_auth.cipher_iv.val);
3794 if (p->cipher_auth.cipher_iv_update.val)
3795 free(p->cipher_auth.cipher_iv_update.val);
3797 case RTE_CRYPTO_SYM_XFORM_AUTH:
3798 if (p->cipher_auth.auth_iv.val)
3799 free(p->cipher_auth.cipher_iv.val);
3800 if (p->cipher_auth.auth_iv_update.val)
3801 free(p->cipher_auth.cipher_iv_update.val);
3803 case RTE_CRYPTO_SYM_XFORM_AEAD:
3805 free(p->aead.iv.val);
3806 if (p->aead.aad.val)
3807 free(p->aead.aad.val);
3816 static struct rte_crypto_sym_xform *
3817 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3818 uint8_t *key, uint32_t max_key_len, char **tokens,
3819 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3821 struct rte_crypto_sym_xform *xform_cipher;
3825 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
3826 strcmp(tokens[3], "cipher_key") ||
3827 strcmp(tokens[5], "cipher_iv"))
3830 xform_cipher = calloc(1, sizeof(*xform_cipher));
3831 if (xform_cipher == NULL)
3834 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3835 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
3836 RTE_CRYPTO_CIPHER_OP_DECRYPT;
3839 status = rte_cryptodev_get_cipher_algo_enum(
3840 &xform_cipher->cipher.algo, tokens[2]);
3845 len = strlen(tokens[4]);
3846 if (len / 2 > max_key_len) {
3851 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
3855 xform_cipher->cipher.key.data = key;
3856 xform_cipher->cipher.key.length = (uint16_t)len;
3859 len = strlen(tokens[6]);
3861 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
3862 if (p->cipher_auth.cipher_iv.val == NULL)
3865 status = parse_hex_string(tokens[6],
3866 p->cipher_auth.cipher_iv.val,
3871 xform_cipher->cipher.iv.length = (uint16_t)len;
3872 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3873 p->cipher_auth.cipher_iv.length = (uint32_t)len;
3876 return xform_cipher;
3879 if (p->cipher_auth.cipher_iv.val) {
3880 free(p->cipher_auth.cipher_iv.val);
3881 p->cipher_auth.cipher_iv.val = NULL;
3889 static struct rte_crypto_sym_xform *
3890 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3891 uint8_t *key, uint32_t max_key_len, char **tokens,
3892 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3894 struct rte_crypto_sym_xform *xform_cipher;
3895 struct rte_crypto_sym_xform *xform_auth;
3899 if (n_tokens < 13 ||
3900 strcmp(tokens[7], "auth_algo") ||
3901 strcmp(tokens[9], "auth_key") ||
3902 strcmp(tokens[11], "digest_size"))
3905 xform_auth = calloc(1, sizeof(*xform_auth));
3906 if (xform_auth == NULL)
3909 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
3910 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
3911 RTE_CRYPTO_AUTH_OP_VERIFY;
3914 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
3920 len = strlen(tokens[10]);
3921 if (len / 2 > max_key_len) {
3926 status = parse_hex_string(tokens[10], key, (uint32_t *)&len);
3930 xform_auth->auth.key.data = key;
3931 xform_auth->auth.key.length = (uint16_t)len;
3933 key += xform_auth->auth.key.length;
3934 max_key_len -= xform_auth->auth.key.length;
3936 if (strcmp(tokens[11], "digest_size"))
3939 status = parser_read_uint16(&xform_auth->auth.digest_length,
3944 xform_cipher = parse_table_action_cipher(p, key, max_key_len, tokens,
3945 7, encrypt, used_n_tokens);
3946 if (xform_cipher == NULL)
3949 *used_n_tokens += 6;
3952 xform_cipher->next = xform_auth;
3953 return xform_cipher;
3955 xform_auth->next = xform_cipher;
3960 if (p->cipher_auth.auth_iv.val) {
3961 free(p->cipher_auth.auth_iv.val);
3962 p->cipher_auth.auth_iv.val = 0;
3970 static struct rte_crypto_sym_xform *
3971 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3972 uint8_t *key, uint32_t max_key_len, char **tokens,
3973 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3975 struct rte_crypto_sym_xform *xform_aead;
3979 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
3980 strcmp(tokens[3], "aead_key") ||
3981 strcmp(tokens[5], "aead_iv") ||
3982 strcmp(tokens[7], "aead_aad") ||
3983 strcmp(tokens[9], "digest_size"))
3986 xform_aead = calloc(1, sizeof(*xform_aead));
3987 if (xform_aead == NULL)
3990 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
3991 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
3992 RTE_CRYPTO_AEAD_OP_DECRYPT;
3995 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
4001 len = strlen(tokens[4]);
4002 if (len / 2 > max_key_len) {
4007 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
4011 xform_aead->aead.key.data = key;
4012 xform_aead->aead.key.length = (uint16_t)len;
4015 len = strlen(tokens[6]);
4016 p->aead.iv.val = calloc(1, len / 2 + 1);
4017 if (p->aead.iv.val == NULL)
4020 status = parse_hex_string(tokens[6], p->aead.iv.val,
4025 xform_aead->aead.iv.length = (uint16_t)len;
4026 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4027 p->aead.iv.length = (uint32_t)len;
4030 len = strlen(tokens[8]);
4031 p->aead.aad.val = calloc(1, len / 2 + 1);
4032 if (p->aead.aad.val == NULL)
4035 status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
4039 xform_aead->aead.aad_length = (uint16_t)len;
4040 p->aead.aad.length = (uint32_t)len;
4043 status = parser_read_uint16(&xform_aead->aead.digest_length,
4048 *used_n_tokens = 11;
4053 if (p->aead.iv.val) {
4054 free(p->aead.iv.val);
4055 p->aead.iv.val = NULL;
4057 if (p->aead.aad.val) {
4058 free(p->aead.aad.val);
4059 p->aead.aad.val = NULL;
4069 parse_table_action_sym_crypto(char **tokens,
4071 struct table_rule_action *a)
4073 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4074 struct rte_crypto_sym_xform *xform = NULL;
4075 uint8_t *key = a->sym_crypto_key;
4076 uint32_t max_key_len = SYM_CRYPTO_MAX_KEY_SIZE;
4077 uint32_t used_n_tokens;
4081 if ((n_tokens < 12) ||
4082 strcmp(tokens[0], "sym_crypto") ||
4083 strcmp(tokens[2], "type"))
4086 memset(p, 0, sizeof(*p));
4088 if (strcmp(tokens[1], "encrypt") == 0)
4093 status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4097 if (strcmp(tokens[3], "cipher") == 0) {
4101 xform = parse_table_action_cipher(p, key, max_key_len, tokens,
4102 n_tokens, encrypt, &used_n_tokens);
4103 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4107 xform = parse_table_action_cipher_auth(p, key, max_key_len,
4108 tokens, n_tokens, encrypt, &used_n_tokens);
4109 } else if (strcmp(tokens[3], "aead") == 0) {
4113 xform = parse_table_action_aead(p, key, max_key_len, tokens,
4114 n_tokens, encrypt, &used_n_tokens);
4122 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4123 parse_free_sym_crypto_param_data(p);
4127 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4129 return used_n_tokens + 5;
4133 parse_table_action_tag(char **tokens,
4135 struct table_rule_action *a)
4137 if ((n_tokens < 2) ||
4138 strcmp(tokens[0], "tag"))
4141 if (parser_read_uint32(&a->tag.tag, tokens[1]))
4144 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4149 parse_table_action_decap(char **tokens,
4151 struct table_rule_action *a)
4153 if ((n_tokens < 2) ||
4154 strcmp(tokens[0], "decap"))
4157 if (parser_read_uint16(&a->decap.n, tokens[1]))
4160 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4165 parse_table_action(char **tokens,
4169 struct table_rule_action *a)
4171 uint32_t n_tokens0 = n_tokens;
4173 memset(a, 0, sizeof(*a));
4175 if ((n_tokens < 2) ||
4176 strcmp(tokens[0], "action"))
4182 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4185 n = parse_table_action_fwd(tokens, n_tokens, a);
4187 snprintf(out, out_size, MSG_ARG_INVALID,
4196 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4199 n = parse_table_action_balance(tokens, n_tokens, a);
4201 snprintf(out, out_size, MSG_ARG_INVALID,
4210 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4213 n = parse_table_action_meter(tokens, n_tokens, a);
4215 snprintf(out, out_size, MSG_ARG_INVALID,
4224 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4227 n = parse_table_action_tm(tokens, n_tokens, a);
4229 snprintf(out, out_size, MSG_ARG_INVALID,
4238 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4241 n = parse_table_action_encap(tokens, n_tokens, a);
4243 snprintf(out, out_size, MSG_ARG_INVALID,
4252 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4255 n = parse_table_action_nat(tokens, n_tokens, a);
4257 snprintf(out, out_size, MSG_ARG_INVALID,
4266 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4269 n = parse_table_action_ttl(tokens, n_tokens, a);
4271 snprintf(out, out_size, MSG_ARG_INVALID,
4280 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4283 n = parse_table_action_stats(tokens, n_tokens, a);
4285 snprintf(out, out_size, MSG_ARG_INVALID,
4294 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4297 n = parse_table_action_time(tokens, n_tokens, a);
4299 snprintf(out, out_size, MSG_ARG_INVALID,
4308 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4311 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4313 snprintf(out, out_size, MSG_ARG_INVALID,
4314 "action sym_crypto");
4321 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4324 n = parse_table_action_tag(tokens, n_tokens, a);
4326 snprintf(out, out_size, MSG_ARG_INVALID,
4335 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4338 n = parse_table_action_decap(tokens, n_tokens, a);
4340 snprintf(out, out_size, MSG_ARG_INVALID,
4349 if (n_tokens0 - n_tokens == 1) {
4350 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4354 return n_tokens0 - n_tokens;
4358 static const char cmd_pipeline_table_rule_add_help[] =
4359 "pipeline <pipeline_name> table <table_id> rule add\n"
4361 " action <table_action>\n";
4364 cmd_pipeline_table_rule_add(char **tokens,
4369 struct table_rule_match m;
4370 struct table_rule_action a;
4371 char *pipeline_name;
4372 uint32_t table_id, t0, n_tokens_parsed;
4376 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4380 pipeline_name = tokens[1];
4382 if (strcmp(tokens[2], "table") != 0) {
4383 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4387 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4388 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4392 if (strcmp(tokens[4], "rule") != 0) {
4393 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4397 if (strcmp(tokens[5], "add") != 0) {
4398 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4405 n_tokens_parsed = parse_match(tokens + t0,
4410 if (n_tokens_parsed == 0)
4412 t0 += n_tokens_parsed;
4415 n_tokens_parsed = parse_table_action(tokens + t0,
4420 if (n_tokens_parsed == 0)
4422 t0 += n_tokens_parsed;
4424 if (t0 != n_tokens) {
4425 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4429 status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
4431 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4435 if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
4436 parse_free_sym_crypto_param_data(&a.sym_crypto);
4440 static const char cmd_pipeline_table_rule_add_default_help[] =
4441 "pipeline <pipeline_name> table <table_id> rule add\n"
4447 " | port <port_id>\n"
4449 " | table <table_id>\n";
4452 cmd_pipeline_table_rule_add_default(char **tokens,
4457 struct table_rule_action action;
4458 char *pipeline_name;
4462 if ((n_tokens != 11) && (n_tokens != 12)) {
4463 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4467 pipeline_name = tokens[1];
4469 if (strcmp(tokens[2], "table") != 0) {
4470 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4474 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4475 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4479 if (strcmp(tokens[4], "rule") != 0) {
4480 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4484 if (strcmp(tokens[5], "add") != 0) {
4485 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4489 if (strcmp(tokens[6], "match") != 0) {
4490 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4494 if (strcmp(tokens[7], "default") != 0) {
4495 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4499 if (strcmp(tokens[8], "action") != 0) {
4500 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4504 if (strcmp(tokens[9], "fwd") != 0) {
4505 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4509 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4511 if (strcmp(tokens[10], "drop") == 0) {
4512 if (n_tokens != 11) {
4513 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4517 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4518 } else if (strcmp(tokens[10], "port") == 0) {
4521 if (n_tokens != 12) {
4522 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4526 if (parser_read_uint32(&id, tokens[11]) != 0) {
4527 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4531 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4533 } else if (strcmp(tokens[10], "meta") == 0) {
4534 if (n_tokens != 11) {
4535 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4539 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4540 } else if (strcmp(tokens[10], "table") == 0) {
4543 if (n_tokens != 12) {
4544 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4548 if (parser_read_uint32(&id, tokens[11]) != 0) {
4549 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4553 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4556 snprintf(out, out_size, MSG_ARG_INVALID,
4557 "drop or port or meta or table");
4561 status = pipeline_table_rule_add_default(pipeline_name,
4565 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4571 static const char cmd_pipeline_table_rule_add_bulk_help[] =
4572 "pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\n"
4574 " File <file_name>:\n"
4575 " - line format: match <match> action <action>\n";
4578 cli_rule_file_process(const char *file_name,
4579 size_t line_len_max,
4580 struct table_rule_list **rule_list,
4582 uint32_t *line_number,
4587 cmd_pipeline_table_rule_add_bulk(char **tokens,
4592 struct table_rule_list *list = NULL;
4593 char *pipeline_name, *file_name;
4594 uint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;
4597 if (n_tokens != 8) {
4598 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4602 pipeline_name = tokens[1];
4604 if (strcmp(tokens[2], "table") != 0) {
4605 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4609 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4610 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4614 if (strcmp(tokens[4], "rule") != 0) {
4615 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4619 if (strcmp(tokens[5], "add") != 0) {
4620 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4624 if (strcmp(tokens[6], "bulk") != 0) {
4625 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4629 file_name = tokens[7];
4631 /* Load rules from file. */
4632 status = cli_rule_file_process(file_name,
4640 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4645 status = pipeline_table_rule_add_bulk(pipeline_name,
4649 &n_rules_not_added);
4651 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4655 snprintf(out, out_size, "Added %u rules out of %u.\n",
4661 static const char cmd_pipeline_table_rule_delete_help[] =
4662 "pipeline <pipeline_name> table <table_id> rule delete\n"
4666 cmd_pipeline_table_rule_delete(char **tokens,
4671 struct table_rule_match m;
4672 char *pipeline_name;
4673 uint32_t table_id, n_tokens_parsed, t0;
4677 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4681 pipeline_name = tokens[1];
4683 if (strcmp(tokens[2], "table") != 0) {
4684 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4688 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4689 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4693 if (strcmp(tokens[4], "rule") != 0) {
4694 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4698 if (strcmp(tokens[5], "delete") != 0) {
4699 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4706 n_tokens_parsed = parse_match(tokens + t0,
4711 if (n_tokens_parsed == 0)
4713 t0 += n_tokens_parsed;
4715 if (n_tokens != t0) {
4716 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4720 status = pipeline_table_rule_delete(pipeline_name,
4724 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4730 static const char cmd_pipeline_table_rule_delete_default_help[] =
4731 "pipeline <pipeline_name> table <table_id> rule delete\n"
4736 cmd_pipeline_table_rule_delete_default(char **tokens,
4741 char *pipeline_name;
4745 if (n_tokens != 8) {
4746 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4750 pipeline_name = tokens[1];
4752 if (strcmp(tokens[2], "table") != 0) {
4753 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4757 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4758 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4762 if (strcmp(tokens[4], "rule") != 0) {
4763 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4767 if (strcmp(tokens[5], "delete") != 0) {
4768 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4772 if (strcmp(tokens[6], "match") != 0) {
4773 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4777 if (strcmp(tokens[7], "default") != 0) {
4778 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4782 status = pipeline_table_rule_delete_default(pipeline_name,
4785 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4791 ether_addr_show(FILE *f, struct rte_ether_addr *addr)
4793 fprintf(f, "%02x:%02x:%02x:%02x:%02x:%02x",
4794 (uint32_t)addr->addr_bytes[0], (uint32_t)addr->addr_bytes[1],
4795 (uint32_t)addr->addr_bytes[2], (uint32_t)addr->addr_bytes[3],
4796 (uint32_t)addr->addr_bytes[4], (uint32_t)addr->addr_bytes[5]);
4800 ipv4_addr_show(FILE *f, uint32_t addr)
4802 fprintf(f, "%u.%u.%u.%u",
4804 (addr >> 16) & 0xFF,
4810 ipv6_addr_show(FILE *f, uint8_t *addr)
4812 fprintf(f, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
4813 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:",
4814 (uint32_t)addr[0], (uint32_t)addr[1],
4815 (uint32_t)addr[2], (uint32_t)addr[3],
4816 (uint32_t)addr[4], (uint32_t)addr[5],
4817 (uint32_t)addr[6], (uint32_t)addr[7],
4818 (uint32_t)addr[8], (uint32_t)addr[9],
4819 (uint32_t)addr[10], (uint32_t)addr[11],
4820 (uint32_t)addr[12], (uint32_t)addr[13],
4821 (uint32_t)addr[14], (uint32_t)addr[15]);
4825 policer_action_string(enum rte_table_action_policer action) {
4827 case RTE_TABLE_ACTION_POLICER_COLOR_GREEN: return "G";
4828 case RTE_TABLE_ACTION_POLICER_COLOR_YELLOW: return "Y";
4829 case RTE_TABLE_ACTION_POLICER_COLOR_RED: return "R";
4830 case RTE_TABLE_ACTION_POLICER_DROP: return "D";
4831 default: return "?";
4836 table_rule_show(const char *pipeline_name,
4838 const char *file_name)
4841 struct table *table;
4842 struct table_rule *rule;
4846 /* Check input params. */
4847 if ((pipeline_name == NULL) ||
4848 (file_name == NULL))
4851 p = pipeline_find(pipeline_name);
4853 (table_id >= p->n_tables))
4856 table = &p->table[table_id];
4859 f = fopen(file_name, "w");
4863 /* Write table rules to file. */
4864 TAILQ_FOREACH(rule, &table->rules, node) {
4865 struct table_rule_match *m = &rule->match;
4866 struct table_rule_action *a = &rule->action;
4868 fprintf(f, "match ");
4869 switch (m->match_type) {
4871 fprintf(f, "acl priority %u ",
4872 m->match.acl.priority);
4874 fprintf(f, m->match.acl.ip_version ? "ipv4 " : "ipv6 ");
4876 if (m->match.acl.ip_version)
4877 ipv4_addr_show(f, m->match.acl.ipv4.sa);
4879 ipv6_addr_show(f, m->match.acl.ipv6.sa);
4881 fprintf(f, "%u", m->match.acl.sa_depth);
4883 if (m->match.acl.ip_version)
4884 ipv4_addr_show(f, m->match.acl.ipv4.da);
4886 ipv6_addr_show(f, m->match.acl.ipv6.da);
4888 fprintf(f, "%u", m->match.acl.da_depth);
4890 fprintf(f, "%u %u %u %u %u ",
4891 (uint32_t)m->match.acl.sp0,
4892 (uint32_t)m->match.acl.sp1,
4893 (uint32_t)m->match.acl.dp0,
4894 (uint32_t)m->match.acl.dp1,
4895 (uint32_t)m->match.acl.proto);
4899 fprintf(f, "array %u ",
4900 m->match.array.pos);
4904 fprintf(f, "hash raw ");
4905 for (i = 0; i < table->params.match.hash.key_size; i++)
4906 fprintf(f, "%02x", m->match.hash.key[i]);
4913 fprintf(f, m->match.lpm.ip_version ? "ipv4 " : "ipv6 ");
4915 if (m->match.acl.ip_version)
4916 ipv4_addr_show(f, m->match.lpm.ipv4);
4918 ipv6_addr_show(f, m->match.lpm.ipv6);
4921 (uint32_t)m->match.lpm.depth);
4925 fprintf(f, "unknown ");
4928 fprintf(f, "action ");
4929 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
4931 switch (a->fwd.action) {
4932 case RTE_PIPELINE_ACTION_DROP:
4933 fprintf(f, "drop ");
4936 case RTE_PIPELINE_ACTION_PORT:
4937 fprintf(f, "port %u ", a->fwd.id);
4940 case RTE_PIPELINE_ACTION_PORT_META:
4941 fprintf(f, "meta ");
4944 case RTE_PIPELINE_ACTION_TABLE:
4946 fprintf(f, "table %u ", a->fwd.id);
4950 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
4951 fprintf(f, "balance ");
4952 for (i = 0; i < RTE_DIM(a->lb.out); i++)
4953 fprintf(f, "%u ", a->lb.out[i]);
4956 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
4958 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++)
4959 if (a->mtr.tc_mask & (1 << i)) {
4960 struct rte_table_action_mtr_tc_params *p =
4962 enum rte_table_action_policer ga =
4963 p->policer[RTE_COLOR_GREEN];
4964 enum rte_table_action_policer ya =
4965 p->policer[RTE_COLOR_YELLOW];
4966 enum rte_table_action_policer ra =
4967 p->policer[RTE_COLOR_RED];
4969 fprintf(f, "tc%u meter %u policer g %s y %s r %s ",
4971 a->mtr.mtr[i].meter_profile_id,
4972 policer_action_string(ga),
4973 policer_action_string(ya),
4974 policer_action_string(ra));
4978 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TM))
4979 fprintf(f, "tm subport %u pipe %u ",
4983 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
4984 fprintf(f, "encap ");
4985 switch (a->encap.type) {
4986 case RTE_TABLE_ACTION_ENCAP_ETHER:
4987 fprintf(f, "ether ");
4988 ether_addr_show(f, &a->encap.ether.ether.da);
4990 ether_addr_show(f, &a->encap.ether.ether.sa);
4994 case RTE_TABLE_ACTION_ENCAP_VLAN:
4995 fprintf(f, "vlan ");
4996 ether_addr_show(f, &a->encap.vlan.ether.da);
4998 ether_addr_show(f, &a->encap.vlan.ether.sa);
4999 fprintf(f, " pcp %u dei %u vid %u ",
5000 a->encap.vlan.vlan.pcp,
5001 a->encap.vlan.vlan.dei,
5002 a->encap.vlan.vlan.vid);
5005 case RTE_TABLE_ACTION_ENCAP_QINQ:
5006 fprintf(f, "qinq ");
5007 ether_addr_show(f, &a->encap.qinq.ether.da);
5009 ether_addr_show(f, &a->encap.qinq.ether.sa);
5010 fprintf(f, " pcp %u dei %u vid %u pcp %u dei %u vid %u ",
5011 a->encap.qinq.svlan.pcp,
5012 a->encap.qinq.svlan.dei,
5013 a->encap.qinq.svlan.vid,
5014 a->encap.qinq.cvlan.pcp,
5015 a->encap.qinq.cvlan.dei,
5016 a->encap.qinq.cvlan.vid);
5019 case RTE_TABLE_ACTION_ENCAP_MPLS:
5020 fprintf(f, "mpls %s ", (a->encap.mpls.unicast) ?
5021 "unicast " : "multicast ");
5022 ether_addr_show(f, &a->encap.mpls.ether.da);
5024 ether_addr_show(f, &a->encap.mpls.ether.sa);
5026 for (i = 0; i < a->encap.mpls.mpls_count; i++) {
5027 struct rte_table_action_mpls_hdr *l =
5028 &a->encap.mpls.mpls[i];
5030 fprintf(f, "label%u %u %u %u ",
5038 case RTE_TABLE_ACTION_ENCAP_PPPOE:
5039 fprintf(f, "pppoe ");
5040 ether_addr_show(f, &a->encap.pppoe.ether.da);
5042 ether_addr_show(f, &a->encap.pppoe.ether.sa);
5043 fprintf(f, " %u ", a->encap.pppoe.pppoe.session_id);
5046 case RTE_TABLE_ACTION_ENCAP_VXLAN:
5047 fprintf(f, "vxlan ether ");
5048 ether_addr_show(f, &a->encap.vxlan.ether.da);
5050 ether_addr_show(f, &a->encap.vxlan.ether.sa);
5051 if (table->ap->params.encap.vxlan.vlan)
5052 fprintf(f, " vlan pcp %u dei %u vid %u ",
5053 a->encap.vxlan.vlan.pcp,
5054 a->encap.vxlan.vlan.dei,
5055 a->encap.vxlan.vlan.vid);
5056 if (table->ap->params.encap.vxlan.ip_version) {
5057 fprintf(f, " ipv4 ");
5058 ipv4_addr_show(f, a->encap.vxlan.ipv4.sa);
5060 ipv4_addr_show(f, a->encap.vxlan.ipv4.da);
5061 fprintf(f, " %u %u ",
5062 (uint32_t)a->encap.vxlan.ipv4.dscp,
5063 (uint32_t)a->encap.vxlan.ipv4.ttl);
5065 fprintf(f, " ipv6 ");
5066 ipv6_addr_show(f, a->encap.vxlan.ipv6.sa);
5068 ipv6_addr_show(f, a->encap.vxlan.ipv6.da);
5069 fprintf(f, " %u %u %u ",
5070 a->encap.vxlan.ipv6.flow_label,
5071 (uint32_t)a->encap.vxlan.ipv6.dscp,
5072 (uint32_t)a->encap.vxlan.ipv6.hop_limit);
5073 fprintf(f, " udp %u %u vxlan %u ",
5074 a->encap.vxlan.udp.sp,
5075 a->encap.vxlan.udp.dp,
5076 a->encap.vxlan.vxlan.vni);
5081 fprintf(f, "unknown ");
5085 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
5086 fprintf(f, "nat %s ", (a->nat.ip_version) ? "ipv4 " : "ipv6 ");
5087 if (a->nat.ip_version)
5088 ipv4_addr_show(f, a->nat.addr.ipv4);
5090 ipv6_addr_show(f, a->nat.addr.ipv6);
5091 fprintf(f, " %u ", (uint32_t)(a->nat.port));
5094 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TTL))
5095 fprintf(f, "ttl %s ", (a->ttl.decrement) ? "dec" : "keep");
5097 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_STATS))
5098 fprintf(f, "stats ");
5100 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TIME))
5101 fprintf(f, "time ");
5103 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO))
5104 fprintf(f, "sym_crypto ");
5106 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TAG))
5107 fprintf(f, "tag %u ", a->tag.tag);
5109 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
5110 fprintf(f, "decap %u ", a->decap.n);
5116 /* Write table default rule to file. */
5117 if (table->rule_default) {
5118 struct table_rule_action *a = &table->rule_default->action;
5120 fprintf(f, "# match default action fwd ");
5122 switch (a->fwd.action) {
5123 case RTE_PIPELINE_ACTION_DROP:
5124 fprintf(f, "drop ");
5127 case RTE_PIPELINE_ACTION_PORT:
5128 fprintf(f, "port %u ", a->fwd.id);
5131 case RTE_PIPELINE_ACTION_PORT_META:
5132 fprintf(f, "meta ");
5135 case RTE_PIPELINE_ACTION_TABLE:
5137 fprintf(f, "table %u ", a->fwd.id);
5140 fprintf(f, "# match default action fwd drop ");
5150 static const char cmd_pipeline_table_rule_show_help[] =
5151 "pipeline <pipeline_name> table <table_id> rule show\n"
5152 " file <file_name>\n";
5155 cmd_pipeline_table_rule_show(char **tokens,
5160 char *file_name = NULL, *pipeline_name;
5164 if (n_tokens != 8) {
5165 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5169 pipeline_name = tokens[1];
5171 if (strcmp(tokens[2], "table") != 0) {
5172 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5176 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5177 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5181 if (strcmp(tokens[4], "rule") != 0) {
5182 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5186 if (strcmp(tokens[5], "show") != 0) {
5187 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "show");
5191 if (strcmp(tokens[6], "file") != 0) {
5192 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "file");
5196 file_name = tokens[7];
5198 status = table_rule_show(pipeline_name, table_id, file_name);
5200 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5205 static const char cmd_pipeline_table_rule_stats_read_help[] =
5206 "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n"
5210 cmd_pipeline_table_rule_stats_read(char **tokens,
5215 struct table_rule_match m;
5216 struct rte_table_action_stats_counters stats;
5217 char *pipeline_name;
5218 uint32_t table_id, n_tokens_parsed;
5219 int clear = 0, status;
5222 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5226 pipeline_name = tokens[1];
5228 if (strcmp(tokens[2], "table") != 0) {
5229 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5233 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5234 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5238 if (strcmp(tokens[4], "rule") != 0) {
5239 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5243 if (strcmp(tokens[5], "read") != 0) {
5244 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5248 if (strcmp(tokens[6], "stats") != 0) {
5249 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
5257 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5265 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5266 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5270 n_tokens_parsed = parse_match(tokens,
5275 if (n_tokens_parsed == 0)
5277 n_tokens -= n_tokens_parsed;
5278 tokens += n_tokens_parsed;
5282 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5286 /* Read table rule stats. */
5287 status = pipeline_table_rule_stats_read(pipeline_name,
5293 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5298 if (stats.n_packets_valid && stats.n_bytes_valid)
5299 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: %" PRIu64 "\n",
5303 if (stats.n_packets_valid && !stats.n_bytes_valid)
5304 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: N/A\n",
5307 if (!stats.n_packets_valid && stats.n_bytes_valid)
5308 snprintf(out, out_size, "Packets: N/A; Bytes: %" PRIu64 "\n",
5311 if (!stats.n_packets_valid && !stats.n_bytes_valid)
5312 snprintf(out, out_size, "Packets: N/A ; Bytes: N/A\n");
5315 static const char cmd_pipeline_table_meter_profile_add_help[] =
5316 "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
5317 " add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
5318 " | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
5321 cmd_pipeline_table_meter_profile_add(char **tokens,
5326 struct rte_table_action_meter_profile p;
5327 char *pipeline_name;
5328 uint32_t table_id, meter_profile_id;
5332 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5336 pipeline_name = tokens[1];
5338 if (strcmp(tokens[2], "table") != 0) {
5339 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5343 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5344 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5348 if (strcmp(tokens[4], "meter") != 0) {
5349 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5353 if (strcmp(tokens[5], "profile") != 0) {
5354 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5358 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5359 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5363 if (strcmp(tokens[7], "add") != 0) {
5364 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5368 if (strcmp(tokens[8], "srtcm") == 0) {
5369 if (n_tokens != 15) {
5370 snprintf(out, out_size, MSG_ARG_MISMATCH,
5375 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5377 if (strcmp(tokens[9], "cir") != 0) {
5378 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5382 if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5383 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5387 if (strcmp(tokens[11], "cbs") != 0) {
5388 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5392 if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5393 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5397 if (strcmp(tokens[13], "ebs") != 0) {
5398 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5402 if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5403 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5406 } else if (strcmp(tokens[8], "trtcm") == 0) {
5407 if (n_tokens != 17) {
5408 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5412 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5414 if (strcmp(tokens[9], "cir") != 0) {
5415 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5419 if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5420 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5424 if (strcmp(tokens[11], "pir") != 0) {
5425 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5429 if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5430 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5433 if (strcmp(tokens[13], "cbs") != 0) {
5434 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5438 if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5439 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5443 if (strcmp(tokens[15], "pbs") != 0) {
5444 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5448 if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5449 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5453 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5457 status = pipeline_table_mtr_profile_add(pipeline_name,
5462 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5468 static const char cmd_pipeline_table_meter_profile_delete_help[] =
5469 "pipeline <pipeline_name> table <table_id>\n"
5470 " meter profile <meter_profile_id> delete\n";
5473 cmd_pipeline_table_meter_profile_delete(char **tokens,
5478 char *pipeline_name;
5479 uint32_t table_id, meter_profile_id;
5482 if (n_tokens != 8) {
5483 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5487 pipeline_name = tokens[1];
5489 if (strcmp(tokens[2], "table") != 0) {
5490 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5494 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5495 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5499 if (strcmp(tokens[4], "meter") != 0) {
5500 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5504 if (strcmp(tokens[5], "profile") != 0) {
5505 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5509 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5510 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5514 if (strcmp(tokens[7], "delete") != 0) {
5515 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5519 status = pipeline_table_mtr_profile_delete(pipeline_name,
5523 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5529 static const char cmd_pipeline_table_rule_meter_read_help[] =
5530 "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n"
5534 cmd_pipeline_table_rule_meter_read(char **tokens,
5539 struct table_rule_match m;
5540 struct rte_table_action_mtr_counters stats;
5541 char *pipeline_name;
5542 uint32_t table_id, n_tokens_parsed;
5543 int clear = 0, status;
5546 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5550 pipeline_name = tokens[1];
5552 if (strcmp(tokens[2], "table") != 0) {
5553 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5557 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5558 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5562 if (strcmp(tokens[4], "rule") != 0) {
5563 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5567 if (strcmp(tokens[5], "read") != 0) {
5568 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5572 if (strcmp(tokens[6], "meter") != 0) {
5573 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5581 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5589 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5590 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5594 n_tokens_parsed = parse_match(tokens,
5599 if (n_tokens_parsed == 0)
5601 n_tokens -= n_tokens_parsed;
5602 tokens += n_tokens_parsed;
5606 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5610 /* Read table rule meter stats. */
5611 status = pipeline_table_rule_mtr_read(pipeline_name,
5617 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5625 static const char cmd_pipeline_table_dscp_help[] =
5626 "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
5628 " File <file_name>:\n"
5629 " - exactly 64 lines\n"
5630 " - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
5633 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5634 const char *file_name,
5635 uint32_t *line_number)
5640 /* Check input arguments */
5641 if ((dscp_table == NULL) ||
5642 (file_name == NULL) ||
5643 (line_number == NULL)) {
5649 /* Open input file */
5650 f = fopen(file_name, "r");
5657 for (dscp = 0, l = 1; ; l++) {
5660 enum rte_color color;
5661 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5663 if (fgets(line, sizeof(line), f) == NULL)
5666 if (is_comment(line))
5669 if (parse_tokenize_string(line, tokens, &n_tokens)) {
5678 if ((dscp >= RTE_DIM(dscp_table->entry)) ||
5679 (n_tokens != RTE_DIM(tokens)) ||
5680 parser_read_uint32(&tc_id, tokens[0]) ||
5681 (tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
5682 parser_read_uint32(&tc_queue_id, tokens[1]) ||
5683 (tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
5684 (strlen(tokens[2]) != 1)) {
5690 switch (tokens[2][0]) {
5693 color = RTE_COLOR_GREEN;
5698 color = RTE_COLOR_YELLOW;
5703 color = RTE_COLOR_RED;
5712 dscp_table->entry[dscp].tc_id = tc_id;
5713 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5714 dscp_table->entry[dscp].color = color;
5724 cmd_pipeline_table_dscp(char **tokens,
5729 struct rte_table_action_dscp_table dscp_table;
5730 char *pipeline_name, *file_name;
5731 uint32_t table_id, line_number;
5734 if (n_tokens != 6) {
5735 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5739 pipeline_name = tokens[1];
5741 if (strcmp(tokens[2], "table") != 0) {
5742 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5746 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5747 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5751 if (strcmp(tokens[4], "dscp") != 0) {
5752 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5756 file_name = tokens[5];
5758 status = load_dscp_table(&dscp_table, file_name, &line_number);
5760 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5764 status = pipeline_table_dscp_table_update(pipeline_name,
5769 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5775 static const char cmd_pipeline_table_rule_ttl_read_help[] =
5776 "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n"
5780 cmd_pipeline_table_rule_ttl_read(char **tokens,
5785 struct table_rule_match m;
5786 struct rte_table_action_ttl_counters stats;
5787 char *pipeline_name;
5788 uint32_t table_id, n_tokens_parsed;
5789 int clear = 0, status;
5792 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5796 pipeline_name = tokens[1];
5798 if (strcmp(tokens[2], "table") != 0) {
5799 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5803 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5804 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5808 if (strcmp(tokens[4], "rule") != 0) {
5809 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5813 if (strcmp(tokens[5], "read") != 0) {
5814 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5818 if (strcmp(tokens[6], "ttl") != 0) {
5819 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ttl");
5827 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5835 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5836 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5840 n_tokens_parsed = parse_match(tokens,
5845 if (n_tokens_parsed == 0)
5847 n_tokens -= n_tokens_parsed;
5848 tokens += n_tokens_parsed;
5852 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5856 /* Read table rule TTL stats. */
5857 status = pipeline_table_rule_ttl_read(pipeline_name,
5863 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5868 snprintf(out, out_size, "Packets: %" PRIu64 "\n",
5872 static const char cmd_pipeline_table_rule_time_read_help[] =
5873 "pipeline <pipeline_name> table <table_id> rule read time\n"
5877 cmd_pipeline_table_rule_time_read(char **tokens,
5882 struct table_rule_match m;
5883 char *pipeline_name;
5885 uint32_t table_id, n_tokens_parsed;
5889 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5893 pipeline_name = tokens[1];
5895 if (strcmp(tokens[2], "table") != 0) {
5896 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5900 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5901 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5905 if (strcmp(tokens[4], "rule") != 0) {
5906 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5910 if (strcmp(tokens[5], "read") != 0) {
5911 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5915 if (strcmp(tokens[6], "time") != 0) {
5916 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "time");
5924 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5925 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5929 n_tokens_parsed = parse_match(tokens,
5934 if (n_tokens_parsed == 0)
5936 n_tokens -= n_tokens_parsed;
5937 tokens += n_tokens_parsed;
5941 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5945 /* Read table rule timestamp. */
5946 status = pipeline_table_rule_time_read(pipeline_name,
5951 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5956 snprintf(out, out_size, "Packets: %" PRIu64 "\n", timestamp);
5959 static const char cmd_thread_pipeline_enable_help[] =
5960 "thread <thread_id> pipeline <pipeline_name> enable\n";
5963 cmd_thread_pipeline_enable(char **tokens,
5968 char *pipeline_name;
5972 if (n_tokens != 5) {
5973 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5977 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5978 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5982 if (strcmp(tokens[2], "pipeline") != 0) {
5983 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5987 pipeline_name = tokens[3];
5989 if (strcmp(tokens[4], "enable") != 0) {
5990 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5994 status = thread_pipeline_enable(thread_id, pipeline_name);
5996 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
6002 static const char cmd_thread_pipeline_disable_help[] =
6003 "thread <thread_id> pipeline <pipeline_name> disable\n";
6006 cmd_thread_pipeline_disable(char **tokens,
6011 char *pipeline_name;
6015 if (n_tokens != 5) {
6016 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
6020 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
6021 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
6025 if (strcmp(tokens[2], "pipeline") != 0) {
6026 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
6030 pipeline_name = tokens[3];
6032 if (strcmp(tokens[4], "disable") != 0) {
6033 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
6037 status = thread_pipeline_disable(thread_id, pipeline_name);
6039 snprintf(out, out_size, MSG_CMD_FAIL,
6040 "thread pipeline disable");
6046 cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
6051 if (n_tokens == 0) {
6052 snprintf(out, out_size,
6053 "Type 'help <command>' for details on each command.\n\n"
6054 "List of commands:\n"
6058 "\ttmgr subport profile\n"
6059 "\ttmgr pipe profile\n"
6062 "\ttmgr subport pipe\n"
6065 "\tport in action profile\n"
6066 "\ttable action profile\n"
6068 "\tpipeline port in\n"
6069 "\tpipeline port out\n"
6070 "\tpipeline table\n"
6071 "\tpipeline port in table\n"
6072 "\tpipeline port in stats\n"
6073 "\tpipeline port in enable\n"
6074 "\tpipeline port in disable\n"
6075 "\tpipeline port out stats\n"
6076 "\tpipeline table stats\n"
6077 "\tpipeline table rule add\n"
6078 "\tpipeline table rule add default\n"
6079 "\tpipeline table rule add bulk\n"
6080 "\tpipeline table rule delete\n"
6081 "\tpipeline table rule delete default\n"
6082 "\tpipeline table rule show\n"
6083 "\tpipeline table rule stats read\n"
6084 "\tpipeline table meter profile add\n"
6085 "\tpipeline table meter profile delete\n"
6086 "\tpipeline table rule meter read\n"
6087 "\tpipeline table dscp\n"
6088 "\tpipeline table rule ttl read\n"
6089 "\tpipeline table rule time read\n"
6090 "\tthread pipeline enable\n"
6091 "\tthread pipeline disable\n\n");
6095 if (strcmp(tokens[0], "mempool") == 0) {
6096 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
6100 if (strcmp(tokens[0], "link") == 0) {
6101 snprintf(out, out_size, "\n%s\n", cmd_link_help);
6105 if (strcmp(tokens[0], "swq") == 0) {
6106 snprintf(out, out_size, "\n%s\n", cmd_swq_help);
6110 if (strcmp(tokens[0], "tmgr") == 0) {
6111 if (n_tokens == 1) {
6112 snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
6116 if ((n_tokens == 2) &&
6117 (strcmp(tokens[1], "subport")) == 0) {
6118 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
6122 if ((n_tokens == 3) &&
6123 (strcmp(tokens[1], "subport") == 0) &&
6124 (strcmp(tokens[2], "profile") == 0)) {
6125 snprintf(out, out_size, "\n%s\n",
6126 cmd_tmgr_subport_profile_help);
6130 if ((n_tokens == 3) &&
6131 (strcmp(tokens[1], "subport") == 0) &&
6132 (strcmp(tokens[2], "pipe") == 0)) {
6133 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
6137 if ((n_tokens == 3) &&
6138 (strcmp(tokens[1], "pipe") == 0) &&
6139 (strcmp(tokens[2], "profile") == 0)) {
6140 snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
6145 if (strcmp(tokens[0], "tap") == 0) {
6146 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
6150 if (strcmp(tokens[0], "kni") == 0) {
6151 snprintf(out, out_size, "\n%s\n", cmd_kni_help);
6155 if (strcmp(tokens[0], "cryptodev") == 0) {
6156 snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
6160 if ((n_tokens == 4) &&
6161 (strcmp(tokens[0], "port") == 0) &&
6162 (strcmp(tokens[1], "in") == 0) &&
6163 (strcmp(tokens[2], "action") == 0) &&
6164 (strcmp(tokens[3], "profile") == 0)) {
6165 snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
6169 if ((n_tokens == 3) &&
6170 (strcmp(tokens[0], "table") == 0) &&
6171 (strcmp(tokens[1], "action") == 0) &&
6172 (strcmp(tokens[2], "profile") == 0)) {
6173 snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
6177 if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
6178 snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
6182 if ((strcmp(tokens[0], "pipeline") == 0) &&
6183 (strcmp(tokens[1], "port") == 0)) {
6184 if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
6185 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
6189 if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
6190 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
6194 if ((n_tokens == 4) &&
6195 (strcmp(tokens[2], "in") == 0) &&
6196 (strcmp(tokens[3], "table") == 0)) {
6197 snprintf(out, out_size, "\n%s\n",
6198 cmd_pipeline_port_in_table_help);
6202 if ((n_tokens == 4) &&
6203 (strcmp(tokens[2], "in") == 0) &&
6204 (strcmp(tokens[3], "stats") == 0)) {
6205 snprintf(out, out_size, "\n%s\n",
6206 cmd_pipeline_port_in_stats_help);
6210 if ((n_tokens == 4) &&
6211 (strcmp(tokens[2], "in") == 0) &&
6212 (strcmp(tokens[3], "enable") == 0)) {
6213 snprintf(out, out_size, "\n%s\n",
6214 cmd_pipeline_port_in_enable_help);
6218 if ((n_tokens == 4) &&
6219 (strcmp(tokens[2], "in") == 0) &&
6220 (strcmp(tokens[3], "disable") == 0)) {
6221 snprintf(out, out_size, "\n%s\n",
6222 cmd_pipeline_port_in_disable_help);
6226 if ((n_tokens == 4) &&
6227 (strcmp(tokens[2], "out") == 0) &&
6228 (strcmp(tokens[3], "stats") == 0)) {
6229 snprintf(out, out_size, "\n%s\n",
6230 cmd_pipeline_port_out_stats_help);
6235 if ((strcmp(tokens[0], "pipeline") == 0) &&
6236 (strcmp(tokens[1], "table") == 0)) {
6237 if (n_tokens == 2) {
6238 snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
6242 if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
6243 snprintf(out, out_size, "\n%s\n",
6244 cmd_pipeline_table_stats_help);
6248 if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
6249 snprintf(out, out_size, "\n%s\n",
6250 cmd_pipeline_table_dscp_help);
6254 if ((n_tokens == 4) &&
6255 (strcmp(tokens[2], "rule") == 0) &&
6256 (strcmp(tokens[3], "add") == 0)) {
6257 snprintf(out, out_size, "\n%s\n",
6258 cmd_pipeline_table_rule_add_help);
6262 if ((n_tokens == 5) &&
6263 (strcmp(tokens[2], "rule") == 0) &&
6264 (strcmp(tokens[3], "add") == 0) &&
6265 (strcmp(tokens[4], "default") == 0)) {
6266 snprintf(out, out_size, "\n%s\n",
6267 cmd_pipeline_table_rule_add_default_help);
6271 if ((n_tokens == 5) &&
6272 (strcmp(tokens[2], "rule") == 0) &&
6273 (strcmp(tokens[3], "add") == 0) &&
6274 (strcmp(tokens[4], "bulk") == 0)) {
6275 snprintf(out, out_size, "\n%s\n",
6276 cmd_pipeline_table_rule_add_bulk_help);
6280 if ((n_tokens == 4) &&
6281 (strcmp(tokens[2], "rule") == 0) &&
6282 (strcmp(tokens[3], "delete") == 0)) {
6283 snprintf(out, out_size, "\n%s\n",
6284 cmd_pipeline_table_rule_delete_help);
6288 if ((n_tokens == 5) &&
6289 (strcmp(tokens[2], "rule") == 0) &&
6290 (strcmp(tokens[3], "delete") == 0) &&
6291 (strcmp(tokens[4], "default") == 0)) {
6292 snprintf(out, out_size, "\n%s\n",
6293 cmd_pipeline_table_rule_delete_default_help);
6297 if ((n_tokens == 4) &&
6298 (strcmp(tokens[2], "rule") == 0) &&
6299 (strcmp(tokens[3], "show") == 0)) {
6300 snprintf(out, out_size, "\n%s\n",
6301 cmd_pipeline_table_rule_show_help);
6305 if ((n_tokens == 5) &&
6306 (strcmp(tokens[2], "rule") == 0) &&
6307 (strcmp(tokens[3], "stats") == 0) &&
6308 (strcmp(tokens[4], "read") == 0)) {
6309 snprintf(out, out_size, "\n%s\n",
6310 cmd_pipeline_table_rule_stats_read_help);
6314 if ((n_tokens == 5) &&
6315 (strcmp(tokens[2], "meter") == 0) &&
6316 (strcmp(tokens[3], "profile") == 0) &&
6317 (strcmp(tokens[4], "add") == 0)) {
6318 snprintf(out, out_size, "\n%s\n",
6319 cmd_pipeline_table_meter_profile_add_help);
6323 if ((n_tokens == 5) &&
6324 (strcmp(tokens[2], "meter") == 0) &&
6325 (strcmp(tokens[3], "profile") == 0) &&
6326 (strcmp(tokens[4], "delete") == 0)) {
6327 snprintf(out, out_size, "\n%s\n",
6328 cmd_pipeline_table_meter_profile_delete_help);
6332 if ((n_tokens == 5) &&
6333 (strcmp(tokens[2], "rule") == 0) &&
6334 (strcmp(tokens[3], "meter") == 0) &&
6335 (strcmp(tokens[4], "read") == 0)) {
6336 snprintf(out, out_size, "\n%s\n",
6337 cmd_pipeline_table_rule_meter_read_help);
6341 if ((n_tokens == 5) &&
6342 (strcmp(tokens[2], "rule") == 0) &&
6343 (strcmp(tokens[3], "ttl") == 0) &&
6344 (strcmp(tokens[4], "read") == 0)) {
6345 snprintf(out, out_size, "\n%s\n",
6346 cmd_pipeline_table_rule_ttl_read_help);
6350 if ((n_tokens == 5) &&
6351 (strcmp(tokens[2], "rule") == 0) &&
6352 (strcmp(tokens[3], "time") == 0) &&
6353 (strcmp(tokens[4], "read") == 0)) {
6354 snprintf(out, out_size, "\n%s\n",
6355 cmd_pipeline_table_rule_time_read_help);
6360 if ((n_tokens == 3) &&
6361 (strcmp(tokens[0], "thread") == 0) &&
6362 (strcmp(tokens[1], "pipeline") == 0)) {
6363 if (strcmp(tokens[2], "enable") == 0) {
6364 snprintf(out, out_size, "\n%s\n",
6365 cmd_thread_pipeline_enable_help);
6369 if (strcmp(tokens[2], "disable") == 0) {
6370 snprintf(out, out_size, "\n%s\n",
6371 cmd_thread_pipeline_disable_help);
6376 snprintf(out, out_size, "Invalid command\n");
6380 cli_process(char *in, char *out, size_t out_size)
6382 char *tokens[CMD_MAX_TOKENS];
6383 uint32_t n_tokens = RTE_DIM(tokens);
6389 status = parse_tokenize_string(in, tokens, &n_tokens);
6391 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
6398 if (strcmp(tokens[0], "help") == 0) {
6399 cmd_help(tokens, n_tokens, out, out_size);
6403 if (strcmp(tokens[0], "mempool") == 0) {
6404 cmd_mempool(tokens, n_tokens, out, out_size);
6408 if (strcmp(tokens[0], "link") == 0) {
6409 if (strcmp(tokens[1], "show") == 0) {
6410 cmd_link_show(tokens, n_tokens, out, out_size);
6414 cmd_link(tokens, n_tokens, out, out_size);
6418 if (strcmp(tokens[0], "swq") == 0) {
6419 cmd_swq(tokens, n_tokens, out, out_size);
6423 if (strcmp(tokens[0], "tmgr") == 0) {
6424 if ((n_tokens >= 3) &&
6425 (strcmp(tokens[1], "subport") == 0) &&
6426 (strcmp(tokens[2], "profile") == 0)) {
6427 cmd_tmgr_subport_profile(tokens, n_tokens,
6432 if ((n_tokens >= 3) &&
6433 (strcmp(tokens[1], "pipe") == 0) &&
6434 (strcmp(tokens[2], "profile") == 0)) {
6435 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
6439 if ((n_tokens >= 5) &&
6440 (strcmp(tokens[2], "subport") == 0) &&
6441 (strcmp(tokens[4], "profile") == 0)) {
6442 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
6446 if ((n_tokens >= 5) &&
6447 (strcmp(tokens[2], "subport") == 0) &&
6448 (strcmp(tokens[4], "pipe") == 0)) {
6449 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
6453 cmd_tmgr(tokens, n_tokens, out, out_size);
6457 if (strcmp(tokens[0], "tap") == 0) {
6458 cmd_tap(tokens, n_tokens, out, out_size);
6462 if (strcmp(tokens[0], "kni") == 0) {
6463 cmd_kni(tokens, n_tokens, out, out_size);
6467 if (strcmp(tokens[0], "cryptodev") == 0) {
6468 cmd_cryptodev(tokens, n_tokens, out, out_size);
6472 if (strcmp(tokens[0], "port") == 0) {
6473 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
6477 if (strcmp(tokens[0], "table") == 0) {
6478 cmd_table_action_profile(tokens, n_tokens, out, out_size);
6482 if (strcmp(tokens[0], "pipeline") == 0) {
6483 if ((n_tokens >= 3) &&
6484 (strcmp(tokens[2], "period") == 0)) {
6485 cmd_pipeline(tokens, n_tokens, out, out_size);
6489 if ((n_tokens >= 5) &&
6490 (strcmp(tokens[2], "port") == 0) &&
6491 (strcmp(tokens[3], "in") == 0) &&
6492 (strcmp(tokens[4], "bsz") == 0)) {
6493 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
6497 if ((n_tokens >= 5) &&
6498 (strcmp(tokens[2], "port") == 0) &&
6499 (strcmp(tokens[3], "out") == 0) &&
6500 (strcmp(tokens[4], "bsz") == 0)) {
6501 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
6505 if ((n_tokens >= 4) &&
6506 (strcmp(tokens[2], "table") == 0) &&
6507 (strcmp(tokens[3], "match") == 0)) {
6508 cmd_pipeline_table(tokens, n_tokens, out, out_size);
6512 if ((n_tokens >= 6) &&
6513 (strcmp(tokens[2], "port") == 0) &&
6514 (strcmp(tokens[3], "in") == 0) &&
6515 (strcmp(tokens[5], "table") == 0)) {
6516 cmd_pipeline_port_in_table(tokens, n_tokens,
6521 if ((n_tokens >= 6) &&
6522 (strcmp(tokens[2], "port") == 0) &&
6523 (strcmp(tokens[3], "in") == 0) &&
6524 (strcmp(tokens[5], "stats") == 0)) {
6525 cmd_pipeline_port_in_stats(tokens, n_tokens,
6530 if ((n_tokens >= 6) &&
6531 (strcmp(tokens[2], "port") == 0) &&
6532 (strcmp(tokens[3], "in") == 0) &&
6533 (strcmp(tokens[5], "enable") == 0)) {
6534 cmd_pipeline_port_in_enable(tokens, n_tokens,
6539 if ((n_tokens >= 6) &&
6540 (strcmp(tokens[2], "port") == 0) &&
6541 (strcmp(tokens[3], "in") == 0) &&
6542 (strcmp(tokens[5], "disable") == 0)) {
6543 cmd_pipeline_port_in_disable(tokens, n_tokens,
6548 if ((n_tokens >= 6) &&
6549 (strcmp(tokens[2], "port") == 0) &&
6550 (strcmp(tokens[3], "out") == 0) &&
6551 (strcmp(tokens[5], "stats") == 0)) {
6552 cmd_pipeline_port_out_stats(tokens, n_tokens,
6557 if ((n_tokens >= 5) &&
6558 (strcmp(tokens[2], "table") == 0) &&
6559 (strcmp(tokens[4], "stats") == 0)) {
6560 cmd_pipeline_table_stats(tokens, n_tokens,
6565 if ((n_tokens >= 7) &&
6566 (strcmp(tokens[2], "table") == 0) &&
6567 (strcmp(tokens[4], "rule") == 0) &&
6568 (strcmp(tokens[5], "add") == 0) &&
6569 (strcmp(tokens[6], "match") == 0)) {
6570 if ((n_tokens >= 8) &&
6571 (strcmp(tokens[7], "default") == 0)) {
6572 cmd_pipeline_table_rule_add_default(tokens,
6573 n_tokens, out, out_size);
6577 cmd_pipeline_table_rule_add(tokens, n_tokens,
6582 if ((n_tokens >= 7) &&
6583 (strcmp(tokens[2], "table") == 0) &&
6584 (strcmp(tokens[4], "rule") == 0) &&
6585 (strcmp(tokens[5], "add") == 0) &&
6586 (strcmp(tokens[6], "bulk") == 0)) {
6587 cmd_pipeline_table_rule_add_bulk(tokens,
6588 n_tokens, out, out_size);
6592 if ((n_tokens >= 7) &&
6593 (strcmp(tokens[2], "table") == 0) &&
6594 (strcmp(tokens[4], "rule") == 0) &&
6595 (strcmp(tokens[5], "delete") == 0) &&
6596 (strcmp(tokens[6], "match") == 0)) {
6597 if ((n_tokens >= 8) &&
6598 (strcmp(tokens[7], "default") == 0)) {
6599 cmd_pipeline_table_rule_delete_default(tokens,
6600 n_tokens, out, out_size);
6604 cmd_pipeline_table_rule_delete(tokens, n_tokens,
6609 if ((n_tokens >= 6) &&
6610 (strcmp(tokens[2], "table") == 0) &&
6611 (strcmp(tokens[4], "rule") == 0) &&
6612 (strcmp(tokens[5], "show") == 0)) {
6613 cmd_pipeline_table_rule_show(tokens, n_tokens,
6618 if ((n_tokens >= 7) &&
6619 (strcmp(tokens[2], "table") == 0) &&
6620 (strcmp(tokens[4], "rule") == 0) &&
6621 (strcmp(tokens[5], "read") == 0) &&
6622 (strcmp(tokens[6], "stats") == 0)) {
6623 cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
6628 if ((n_tokens >= 8) &&
6629 (strcmp(tokens[2], "table") == 0) &&
6630 (strcmp(tokens[4], "meter") == 0) &&
6631 (strcmp(tokens[5], "profile") == 0) &&
6632 (strcmp(tokens[7], "add") == 0)) {
6633 cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
6638 if ((n_tokens >= 8) &&
6639 (strcmp(tokens[2], "table") == 0) &&
6640 (strcmp(tokens[4], "meter") == 0) &&
6641 (strcmp(tokens[5], "profile") == 0) &&
6642 (strcmp(tokens[7], "delete") == 0)) {
6643 cmd_pipeline_table_meter_profile_delete(tokens,
6644 n_tokens, out, out_size);
6648 if ((n_tokens >= 7) &&
6649 (strcmp(tokens[2], "table") == 0) &&
6650 (strcmp(tokens[4], "rule") == 0) &&
6651 (strcmp(tokens[5], "read") == 0) &&
6652 (strcmp(tokens[6], "meter") == 0)) {
6653 cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
6658 if ((n_tokens >= 5) &&
6659 (strcmp(tokens[2], "table") == 0) &&
6660 (strcmp(tokens[4], "dscp") == 0)) {
6661 cmd_pipeline_table_dscp(tokens, n_tokens,
6666 if ((n_tokens >= 7) &&
6667 (strcmp(tokens[2], "table") == 0) &&
6668 (strcmp(tokens[4], "rule") == 0) &&
6669 (strcmp(tokens[5], "read") == 0) &&
6670 (strcmp(tokens[6], "ttl") == 0)) {
6671 cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
6676 if ((n_tokens >= 7) &&
6677 (strcmp(tokens[2], "table") == 0) &&
6678 (strcmp(tokens[4], "rule") == 0) &&
6679 (strcmp(tokens[5], "read") == 0) &&
6680 (strcmp(tokens[6], "time") == 0)) {
6681 cmd_pipeline_table_rule_time_read(tokens, n_tokens,
6687 if (strcmp(tokens[0], "thread") == 0) {
6688 if ((n_tokens >= 5) &&
6689 (strcmp(tokens[4], "enable") == 0)) {
6690 cmd_thread_pipeline_enable(tokens, n_tokens,
6695 if ((n_tokens >= 5) &&
6696 (strcmp(tokens[4], "disable") == 0)) {
6697 cmd_thread_pipeline_disable(tokens, n_tokens,
6703 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
6707 cli_script_process(const char *file_name,
6708 size_t msg_in_len_max,
6709 size_t msg_out_len_max)
6711 char *msg_in = NULL, *msg_out = NULL;
6714 /* Check input arguments */
6715 if ((file_name == NULL) ||
6716 (strlen(file_name) == 0) ||
6717 (msg_in_len_max == 0) ||
6718 (msg_out_len_max == 0))
6721 msg_in = malloc(msg_in_len_max + 1);
6722 msg_out = malloc(msg_out_len_max + 1);
6723 if ((msg_in == NULL) ||
6724 (msg_out == NULL)) {
6730 /* Open input file */
6731 f = fopen(file_name, "r");
6740 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6743 printf("%s", msg_in);
6750 if (strlen(msg_out))
6751 printf("%s", msg_out);
6762 cli_rule_file_process(const char *file_name,
6763 size_t line_len_max,
6764 struct table_rule_list **rule_list,
6766 uint32_t *line_number,
6770 struct table_rule_list *list = NULL;
6773 uint32_t rule_id = 0, line_id = 0;
6776 /* Check input arguments */
6777 if ((file_name == NULL) ||
6778 (strlen(file_name) == 0) ||
6779 (line_len_max == 0) ||
6780 (rule_list == NULL) ||
6781 (n_rules == NULL) ||
6782 (line_number == NULL) ||
6785 goto cli_rule_file_process_free;
6788 /* Memory allocation */
6789 list = malloc(sizeof(struct table_rule_list));
6792 goto cli_rule_file_process_free;
6797 line = malloc(line_len_max + 1);
6800 goto cli_rule_file_process_free;
6804 f = fopen(file_name, "r");
6807 goto cli_rule_file_process_free;
6811 for (line_id = 1, rule_id = 0; ; line_id++) {
6812 char *tokens[CMD_MAX_TOKENS];
6813 struct table_rule *rule = NULL;
6814 uint32_t n_tokens, n_tokens_parsed, t0;
6816 /* Read next line from file. */
6817 if (fgets(line, line_len_max + 1, f) == NULL)
6821 if (is_comment(line))
6825 n_tokens = RTE_DIM(tokens);
6826 status = parse_tokenize_string(line, tokens, &n_tokens);
6829 goto cli_rule_file_process_free;
6837 /* Rule alloc and insert. */
6838 rule = calloc(1, sizeof(struct table_rule));
6841 goto cli_rule_file_process_free;
6844 TAILQ_INSERT_TAIL(list, rule, node);
6847 n_tokens_parsed = parse_match(tokens + t0,
6852 if (n_tokens_parsed == 0) {
6854 goto cli_rule_file_process_free;
6856 t0 += n_tokens_parsed;
6859 n_tokens_parsed = parse_table_action(tokens + t0,
6864 if (n_tokens_parsed == 0) {
6866 goto cli_rule_file_process_free;
6868 t0 += n_tokens_parsed;
6870 /* Line completed. */
6871 if (t0 < n_tokens) {
6873 goto cli_rule_file_process_free;
6876 /* Increment rule count */
6888 *line_number = line_id;
6891 cli_rule_file_process_free:
6892 if (rule_list != NULL)
6895 if (n_rules != NULL)
6898 if (line_number != NULL)
6899 *line_number = line_id;
6903 struct table_rule *rule;
6905 rule = TAILQ_FIRST(list);
6909 TAILQ_REMOVE(list, rule, node);