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 " RTE_ETHER_ADDR_PRT_FMT " 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 RTE_ETHER_ADDR_BYTES(&mac_addr),
288 rte_eth_link_speed_to_str(eth_link.link_speed),
300 * link show [<link_name>]
303 cmd_link_show(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
308 if (n_tokens != 2 && n_tokens != 3) {
309 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
314 link = link_next(NULL);
316 while (link != NULL) {
317 out_size = out_size - strlen(out);
318 out = &out[strlen(out)];
320 print_link_info(link, out, out_size);
321 link = link_next(link);
324 out_size = out_size - strlen(out);
325 out = &out[strlen(out)];
327 link_name = tokens[2];
328 link = link_find(link_name);
331 snprintf(out, out_size, MSG_ARG_INVALID,
332 "Link does not exist");
335 print_link_info(link, out, out_size);
339 static const char cmd_swq_help[] =
345 cmd_swq(char **tokens,
355 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
361 if (strcmp(tokens[2], "size") != 0) {
362 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
366 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
367 snprintf(out, out_size, MSG_ARG_INVALID, "size");
371 if (strcmp(tokens[4], "cpu") != 0) {
372 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
376 if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
377 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
381 swq = swq_create(name, &p);
383 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
388 static const char cmd_tmgr_subport_profile_help[] =
389 "tmgr subport profile\n"
390 " <tb_rate> <tb_size>\n"
391 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
392 " <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
393 " <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
397 cmd_tmgr_subport_profile(char **tokens,
402 struct rte_sched_subport_profile_params subport_profile;
405 if (n_tokens != 19) {
406 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
410 if (parser_read_uint64(&subport_profile.tb_rate, tokens[3]) != 0) {
411 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
415 if (parser_read_uint64(&subport_profile.tb_size, tokens[4]) != 0) {
416 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
420 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
421 if (parser_read_uint64(&subport_profile.tc_rate[i],
422 tokens[5 + i]) != 0) {
423 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
427 if (parser_read_uint64(&subport_profile.tc_period, tokens[18]) != 0) {
428 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
432 status = tmgr_subport_profile_add(&subport_profile);
434 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
439 static const char cmd_tmgr_pipe_profile_help[] =
440 "tmgr pipe profile\n"
441 " <tb_rate> <tb_size>\n"
442 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
443 " <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
444 " <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
447 " <wrr_weight0..3>\n";
450 cmd_tmgr_pipe_profile(char **tokens,
455 struct rte_sched_pipe_params p;
458 if (n_tokens != 24) {
459 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
463 if (parser_read_uint64(&p.tb_rate, tokens[3]) != 0) {
464 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
468 if (parser_read_uint64(&p.tb_size, tokens[4]) != 0) {
469 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
473 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
474 if (parser_read_uint64(&p.tc_rate[i], tokens[5 + i]) != 0) {
475 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
479 if (parser_read_uint64(&p.tc_period, tokens[18]) != 0) {
480 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
484 if (parser_read_uint8(&p.tc_ov_weight, tokens[19]) != 0) {
485 snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
489 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++)
490 if (parser_read_uint8(&p.wrr_weights[i], tokens[20 + i]) != 0) {
491 snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
495 status = tmgr_pipe_profile_add(&p);
497 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
502 static const char cmd_tmgr_help[] =
505 " spp <n_subports_per_port>\n"
506 " pps <n_pipes_per_subport>\n"
507 " fo <frame_overhead>\n"
512 cmd_tmgr(char **tokens,
517 struct tmgr_port_params p;
519 struct tmgr_port *tmgr_port;
521 if (n_tokens != 14) {
522 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
528 if (strcmp(tokens[2], "rate") != 0) {
529 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
533 if (parser_read_uint64(&p.rate, tokens[3]) != 0) {
534 snprintf(out, out_size, MSG_ARG_INVALID, "rate");
538 if (strcmp(tokens[4], "spp") != 0) {
539 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
543 if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
544 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
548 if (strcmp(tokens[6], "pps") != 0) {
549 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
553 if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
554 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
558 if (strcmp(tokens[8], "fo") != 0) {
559 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
563 if (parser_read_uint32(&p.frame_overhead, tokens[9]) != 0) {
564 snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
568 if (strcmp(tokens[10], "mtu") != 0) {
569 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
573 if (parser_read_uint32(&p.mtu, tokens[11]) != 0) {
574 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
578 if (strcmp(tokens[12], "cpu") != 0) {
579 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
583 if (parser_read_uint32(&p.cpu_id, tokens[13]) != 0) {
584 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
588 tmgr_port = tmgr_port_create(name, &p);
589 if (tmgr_port == NULL) {
590 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
595 static const char cmd_tmgr_subport_help[] =
596 "tmgr <tmgr_name> subport <subport_id>\n"
597 " profile <subport_profile_id>\n";
600 cmd_tmgr_subport(char **tokens,
605 uint32_t subport_id, subport_profile_id;
610 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
616 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
617 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
621 if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
622 snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
626 status = tmgr_subport_config(name, subport_id, subport_profile_id);
628 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
634 static const char cmd_tmgr_subport_pipe_help[] =
635 "tmgr <tmgr_name> subport <subport_id> pipe\n"
636 " from <pipe_id_first> to <pipe_id_last>\n"
637 " profile <pipe_profile_id>\n";
640 cmd_tmgr_subport_pipe(char **tokens,
645 uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
649 if (n_tokens != 11) {
650 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
656 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
657 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
661 if (strcmp(tokens[4], "pipe") != 0) {
662 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
666 if (strcmp(tokens[5], "from") != 0) {
667 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
671 if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
672 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
676 if (strcmp(tokens[7], "to") != 0) {
677 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
681 if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
682 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
686 if (strcmp(tokens[9], "profile") != 0) {
687 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
691 if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
692 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
696 status = tmgr_pipe_config(name, subport_id, pipe_id_first,
697 pipe_id_last, pipe_profile_id);
699 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
705 static const char cmd_tap_help[] =
709 cmd_tap(char **tokens,
718 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
724 tap = tap_create(name);
726 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
731 static const char cmd_kni_help[] =
733 " link <link_name>\n"
734 " mempool <mempool_name>\n"
735 " [thread <thread_id>]\n";
738 cmd_kni(char **tokens,
747 memset(&p, 0, sizeof(p));
748 if ((n_tokens != 6) && (n_tokens != 8)) {
749 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
755 if (strcmp(tokens[2], "link") != 0) {
756 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
760 p.link_name = tokens[3];
762 if (strcmp(tokens[4], "mempool") != 0) {
763 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
767 p.mempool_name = tokens[5];
770 if (strcmp(tokens[6], "thread") != 0) {
771 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
775 if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
776 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
784 kni = kni_create(name, &p);
786 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
791 static const char cmd_cryptodev_help[] =
792 "cryptodev <cryptodev_name>\n"
793 " dev <device_name> | dev_id <device_id>\n"
794 " queue <n_queues> <queue_size>\n"
795 " max_sessions <n_sessions>";
798 cmd_cryptodev(char **tokens,
803 struct cryptodev_params params;
806 memset(¶ms, 0, sizeof(params));
808 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
814 if (strcmp(tokens[2], "dev") == 0)
815 params.dev_name = tokens[3];
816 else if (strcmp(tokens[2], "dev_id") == 0) {
817 if (parser_read_uint32(¶ms.dev_id, tokens[3]) < 0) {
818 snprintf(out, out_size, MSG_ARG_INVALID,
823 snprintf(out, out_size, MSG_ARG_INVALID,
828 if (strcmp(tokens[4], "queue")) {
829 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
834 if (parser_read_uint32(¶ms.n_queues, tokens[5]) < 0) {
835 snprintf(out, out_size, MSG_ARG_INVALID,
840 if (parser_read_uint32(¶ms.queue_size, tokens[6]) < 0) {
841 snprintf(out, out_size, MSG_ARG_INVALID,
846 if (strcmp(tokens[7], "max_sessions")) {
847 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
852 if (parser_read_uint32(¶ms.session_pool_size, tokens[8]) < 0) {
853 snprintf(out, out_size, MSG_ARG_INVALID,
858 if (cryptodev_create(name, ¶ms) == NULL) {
859 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
864 static const char cmd_port_in_action_profile_help[] =
865 "port in action profile <profile_name>\n"
866 " [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]\n"
867 " [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]\n";
870 cmd_port_in_action_profile(char **tokens,
875 struct port_in_action_profile_params p;
876 struct port_in_action_profile *ap;
880 memset(&p, 0, sizeof(p));
883 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
887 if (strcmp(tokens[1], "in") != 0) {
888 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
892 if (strcmp(tokens[2], "action") != 0) {
893 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
897 if (strcmp(tokens[3], "profile") != 0) {
898 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
906 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
909 if (n_tokens < t0 + 10) {
910 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
914 if (strcmp(tokens[t0 + 1], "match") == 0)
915 p.fltr.filter_on_match = 1;
916 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
917 p.fltr.filter_on_match = 0;
919 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
923 if (strcmp(tokens[t0 + 2], "offset") != 0) {
924 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
928 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
929 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
933 if (strcmp(tokens[t0 + 4], "mask") != 0) {
934 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
938 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
939 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
940 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
941 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
945 if (strcmp(tokens[t0 + 6], "key") != 0) {
946 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
950 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
951 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
952 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
953 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
957 if (strcmp(tokens[t0 + 8], "port") != 0) {
958 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
962 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
963 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
967 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
971 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
974 if (n_tokens < t0 + 22) {
975 snprintf(out, out_size, MSG_ARG_MISMATCH,
976 "port in action profile balance");
980 if (strcmp(tokens[t0 + 1], "offset") != 0) {
981 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
985 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
986 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
990 if (strcmp(tokens[t0 + 3], "mask") != 0) {
991 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
995 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
996 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
997 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1001 if (strcmp(tokens[t0 + 5], "port") != 0) {
1002 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1006 for (i = 0; i < 16; i++)
1007 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
1008 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1012 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
1016 if (t0 < n_tokens) {
1017 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1021 ap = port_in_action_profile_create(name, &p);
1023 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1029 static const char cmd_table_action_profile_help[] =
1030 "table action profile <profile_name>\n"
1032 " offset <ip_offset>\n"
1034 " [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]\n"
1035 " [meter srtcm | trtcm\n"
1037 " stats none | pkts | bytes | both]\n"
1038 " [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]\n"
1039 " [encap ether | vlan | qinq | mpls | pppoe | qinq_pppoe \n"
1040 " vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]\n"
1042 " proto udp | tcp]\n"
1043 " [ttl drop | fwd\n"
1044 " stats none | pkts]\n"
1045 " [stats pkts | bytes | both]\n"
1047 " [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
1052 cmd_table_action_profile(char **tokens,
1057 struct table_action_profile_params p;
1058 struct table_action_profile *ap;
1062 memset(&p, 0, sizeof(p));
1065 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1069 if (strcmp(tokens[1], "action") != 0) {
1070 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1074 if (strcmp(tokens[2], "profile") != 0) {
1075 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1081 if (strcmp(tokens[4], "ipv4") == 0)
1082 p.common.ip_version = 1;
1083 else if (strcmp(tokens[4], "ipv6") == 0)
1084 p.common.ip_version = 0;
1086 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1090 if (strcmp(tokens[5], "offset") != 0) {
1091 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1095 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
1096 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1100 if (strcmp(tokens[7], "fwd") != 0) {
1101 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1105 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1108 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
1109 if (n_tokens < t0 + 7) {
1110 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1114 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1115 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1119 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1120 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1124 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1125 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1129 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1130 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1131 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1135 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1136 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1140 if (parser_read_uint32(&p.lb.out_offset, tokens[t0 + 6]) != 0) {
1141 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1145 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1149 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
1150 if (n_tokens < t0 + 6) {
1151 snprintf(out, out_size, MSG_ARG_MISMATCH,
1152 "table action profile meter");
1156 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
1157 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1158 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
1159 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1161 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1166 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1167 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1171 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
1172 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1176 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1177 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1181 if (strcmp(tokens[t0 + 5], "none") == 0) {
1182 p.mtr.n_packets_enabled = 0;
1183 p.mtr.n_bytes_enabled = 0;
1184 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1185 p.mtr.n_packets_enabled = 1;
1186 p.mtr.n_bytes_enabled = 0;
1187 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1188 p.mtr.n_packets_enabled = 0;
1189 p.mtr.n_bytes_enabled = 1;
1190 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1191 p.mtr.n_packets_enabled = 1;
1192 p.mtr.n_bytes_enabled = 1;
1194 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1195 "none or pkts or bytes or both");
1199 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1203 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
1204 if (n_tokens < t0 + 5) {
1205 snprintf(out, out_size, MSG_ARG_MISMATCH,
1206 "table action profile tm");
1210 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1211 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1215 if (parser_read_uint32(&p.tm.n_subports_per_port,
1216 tokens[t0 + 2]) != 0) {
1217 snprintf(out, out_size, MSG_ARG_INVALID,
1218 "n_subports_per_port");
1222 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1223 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1227 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1228 tokens[t0 + 4]) != 0) {
1229 snprintf(out, out_size, MSG_ARG_INVALID,
1230 "n_pipes_per_subport");
1234 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1238 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1239 uint32_t n_extra_tokens = 0;
1241 if (n_tokens < t0 + 2) {
1242 snprintf(out, out_size, MSG_ARG_MISMATCH,
1243 "action profile encap");
1247 if (strcmp(tokens[t0 + 1], "ether") == 0)
1248 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1249 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1250 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1251 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1252 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1253 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1254 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1255 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1256 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1257 else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1258 if (n_tokens < t0 + 2 + 5) {
1259 snprintf(out, out_size, MSG_ARG_MISMATCH,
1260 "action profile encap vxlan");
1264 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1265 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1270 if (parser_read_uint32(&p.encap.vxlan.data_offset,
1271 tokens[t0 + 2 + 1]) != 0) {
1272 snprintf(out, out_size, MSG_ARG_INVALID,
1273 "vxlan: ether_offset");
1277 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1278 p.encap.vxlan.ip_version = 1;
1279 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1280 p.encap.vxlan.ip_version = 0;
1282 snprintf(out, out_size, MSG_ARG_INVALID,
1283 "vxlan: ipv4 or ipv6");
1287 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1288 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1293 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
1294 p.encap.vxlan.vlan = 1;
1295 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
1296 p.encap.vxlan.vlan = 0;
1298 snprintf(out, out_size, MSG_ARG_INVALID,
1299 "vxlan: on or off");
1303 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
1305 } else if (strcmp(tokens[t0 + 1], "qinq_pppoe") == 0)
1306 p.encap.encap_mask =
1307 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
1309 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1313 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1314 t0 += 2 + n_extra_tokens;
1317 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1318 if (n_tokens < t0 + 4) {
1319 snprintf(out, out_size, MSG_ARG_MISMATCH,
1320 "table action profile nat");
1324 if (strcmp(tokens[t0 + 1], "src") == 0)
1325 p.nat.source_nat = 1;
1326 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1327 p.nat.source_nat = 0;
1329 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1334 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1335 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1339 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1341 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1344 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1349 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1353 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1354 if (n_tokens < t0 + 4) {
1355 snprintf(out, out_size, MSG_ARG_MISMATCH,
1356 "table action profile ttl");
1360 if (strcmp(tokens[t0 + 1], "drop") == 0)
1362 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1365 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1370 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1371 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1375 if (strcmp(tokens[t0 + 3], "none") == 0)
1376 p.ttl.n_packets_enabled = 0;
1377 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1378 p.ttl.n_packets_enabled = 1;
1380 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1385 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1389 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1390 if (n_tokens < t0 + 2) {
1391 snprintf(out, out_size, MSG_ARG_MISMATCH,
1392 "table action profile stats");
1396 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1397 p.stats.n_packets_enabled = 1;
1398 p.stats.n_bytes_enabled = 0;
1399 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1400 p.stats.n_packets_enabled = 0;
1401 p.stats.n_bytes_enabled = 1;
1402 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1403 p.stats.n_packets_enabled = 1;
1404 p.stats.n_bytes_enabled = 1;
1406 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1407 "pkts or bytes or both");
1411 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1415 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1416 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1420 if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
1421 struct cryptodev *cryptodev;
1423 if (n_tokens < t0 + 5 ||
1424 strcmp(tokens[t0 + 1], "dev") ||
1425 strcmp(tokens[t0 + 3], "offset")) {
1426 snprintf(out, out_size, MSG_ARG_MISMATCH,
1427 "table action profile sym_crypto");
1431 cryptodev = cryptodev_find(tokens[t0 + 2]);
1432 if (cryptodev == NULL) {
1433 snprintf(out, out_size, MSG_ARG_INVALID,
1434 "table action profile sym_crypto");
1438 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
1440 if (parser_read_uint32(&p.sym_crypto.op_offset,
1441 tokens[t0 + 4]) != 0) {
1442 snprintf(out, out_size, MSG_ARG_INVALID,
1443 "table action profile sym_crypto");
1447 p.sym_crypto.mp_create = cryptodev->mp_create;
1448 p.sym_crypto.mp_init = cryptodev->mp_init;
1450 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
1455 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {
1456 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
1460 if ((t0 < n_tokens) && (strcmp(tokens[t0], "decap") == 0)) {
1461 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1465 if (t0 < n_tokens) {
1466 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1470 ap = table_action_profile_create(name, &p);
1472 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1477 static const char cmd_pipeline_help[] =
1478 "pipeline <pipeline_name>\n"
1479 " period <timer_period_ms>\n"
1480 " offset_port_id <offset_port_id>\n"
1484 cmd_pipeline(char **tokens,
1489 struct pipeline_params p;
1491 struct pipeline *pipeline;
1493 if (n_tokens != 8) {
1494 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1500 if (strcmp(tokens[2], "period") != 0) {
1501 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1505 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1506 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1510 if (strcmp(tokens[4], "offset_port_id") != 0) {
1511 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1515 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1516 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1520 if (strcmp(tokens[6], "cpu") != 0) {
1521 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1525 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1526 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1530 pipeline = pipeline_create(name, &p);
1531 if (pipeline == NULL) {
1532 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1537 static const char cmd_pipeline_port_in_help[] =
1538 "pipeline <pipeline_name> port in\n"
1539 " bsz <burst_size>\n"
1540 " link <link_name> rxq <queue_id>\n"
1541 " | swq <swq_name>\n"
1542 " | tmgr <tmgr_name>\n"
1543 " | tap <tap_name> mempool <mempool_name> mtu <mtu>\n"
1544 " | kni <kni_name>\n"
1545 " | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>\n"
1546 " | cryptodev <cryptodev_name> rxq <queue_id>\n"
1547 " [action <port_in_action_profile_name>]\n"
1551 cmd_pipeline_port_in(char **tokens,
1556 struct port_in_params p;
1557 char *pipeline_name;
1559 int enabled, status;
1562 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1566 pipeline_name = tokens[1];
1568 if (strcmp(tokens[2], "port") != 0) {
1569 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1573 if (strcmp(tokens[3], "in") != 0) {
1574 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1578 if (strcmp(tokens[4], "bsz") != 0) {
1579 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1583 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1584 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1590 if (strcmp(tokens[t0], "link") == 0) {
1591 if (n_tokens < t0 + 4) {
1592 snprintf(out, out_size, MSG_ARG_MISMATCH,
1593 "pipeline port in link");
1597 p.type = PORT_IN_RXQ;
1599 p.dev_name = tokens[t0 + 1];
1601 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1602 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1606 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1607 snprintf(out, out_size, MSG_ARG_INVALID,
1612 } else if (strcmp(tokens[t0], "swq") == 0) {
1613 if (n_tokens < t0 + 2) {
1614 snprintf(out, out_size, MSG_ARG_MISMATCH,
1615 "pipeline port in swq");
1619 p.type = PORT_IN_SWQ;
1621 p.dev_name = tokens[t0 + 1];
1624 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1625 if (n_tokens < t0 + 2) {
1626 snprintf(out, out_size, MSG_ARG_MISMATCH,
1627 "pipeline port in tmgr");
1631 p.type = PORT_IN_TMGR;
1633 p.dev_name = tokens[t0 + 1];
1636 } else if (strcmp(tokens[t0], "tap") == 0) {
1637 if (n_tokens < t0 + 6) {
1638 snprintf(out, out_size, MSG_ARG_MISMATCH,
1639 "pipeline port in tap");
1643 p.type = PORT_IN_TAP;
1645 p.dev_name = tokens[t0 + 1];
1647 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1648 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1653 p.tap.mempool_name = tokens[t0 + 3];
1655 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1656 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1661 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1662 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1667 } else if (strcmp(tokens[t0], "kni") == 0) {
1668 if (n_tokens < t0 + 2) {
1669 snprintf(out, out_size, MSG_ARG_MISMATCH,
1670 "pipeline port in kni");
1674 p.type = PORT_IN_KNI;
1676 p.dev_name = tokens[t0 + 1];
1679 } else if (strcmp(tokens[t0], "source") == 0) {
1680 if (n_tokens < t0 + 6) {
1681 snprintf(out, out_size, MSG_ARG_MISMATCH,
1682 "pipeline port in source");
1686 p.type = PORT_IN_SOURCE;
1690 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1691 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1696 p.source.mempool_name = tokens[t0 + 2];
1698 if (strcmp(tokens[t0 + 3], "file") != 0) {
1699 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1704 p.source.file_name = tokens[t0 + 4];
1706 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1707 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1712 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1713 snprintf(out, out_size, MSG_ARG_INVALID,
1719 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
1720 if (n_tokens < t0 + 3) {
1721 snprintf(out, out_size, MSG_ARG_MISMATCH,
1722 "pipeline port in cryptodev");
1726 p.type = PORT_IN_CRYPTODEV;
1728 p.dev_name = tokens[t0 + 1];
1729 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1730 snprintf(out, out_size, MSG_ARG_INVALID,
1735 p.cryptodev.arg_callback = NULL;
1736 p.cryptodev.f_callback = NULL;
1740 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1744 p.action_profile_name = NULL;
1745 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1746 if (n_tokens < t0 + 2) {
1747 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1751 p.action_profile_name = tokens[t0 + 1];
1757 if ((n_tokens > t0) &&
1758 (strcmp(tokens[t0], "disabled") == 0)) {
1764 if (n_tokens != t0) {
1765 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1769 status = pipeline_port_in_create(pipeline_name,
1772 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1777 static const char cmd_pipeline_port_out_help[] =
1778 "pipeline <pipeline_name> port out\n"
1779 " bsz <burst_size>\n"
1780 " link <link_name> txq <txq_id>\n"
1781 " | swq <swq_name>\n"
1782 " | tmgr <tmgr_name>\n"
1783 " | tap <tap_name>\n"
1784 " | kni <kni_name>\n"
1785 " | sink [file <file_name> pkts <max_n_pkts>]\n"
1786 " | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>\n";
1789 cmd_pipeline_port_out(char **tokens,
1794 struct port_out_params p;
1795 char *pipeline_name;
1798 memset(&p, 0, sizeof(p));
1801 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1805 pipeline_name = tokens[1];
1807 if (strcmp(tokens[2], "port") != 0) {
1808 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1812 if (strcmp(tokens[3], "out") != 0) {
1813 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1817 if (strcmp(tokens[4], "bsz") != 0) {
1818 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1822 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1823 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1827 if (strcmp(tokens[6], "link") == 0) {
1828 if (n_tokens != 10) {
1829 snprintf(out, out_size, MSG_ARG_MISMATCH,
1830 "pipeline port out link");
1834 p.type = PORT_OUT_TXQ;
1836 p.dev_name = tokens[7];
1838 if (strcmp(tokens[8], "txq") != 0) {
1839 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1843 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1844 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1847 } else if (strcmp(tokens[6], "swq") == 0) {
1848 if (n_tokens != 8) {
1849 snprintf(out, out_size, MSG_ARG_MISMATCH,
1850 "pipeline port out swq");
1854 p.type = PORT_OUT_SWQ;
1856 p.dev_name = tokens[7];
1857 } else if (strcmp(tokens[6], "tmgr") == 0) {
1858 if (n_tokens != 8) {
1859 snprintf(out, out_size, MSG_ARG_MISMATCH,
1860 "pipeline port out tmgr");
1864 p.type = PORT_OUT_TMGR;
1866 p.dev_name = tokens[7];
1867 } else if (strcmp(tokens[6], "tap") == 0) {
1868 if (n_tokens != 8) {
1869 snprintf(out, out_size, MSG_ARG_MISMATCH,
1870 "pipeline port out tap");
1874 p.type = PORT_OUT_TAP;
1876 p.dev_name = tokens[7];
1877 } else if (strcmp(tokens[6], "kni") == 0) {
1878 if (n_tokens != 8) {
1879 snprintf(out, out_size, MSG_ARG_MISMATCH,
1880 "pipeline port out kni");
1884 p.type = PORT_OUT_KNI;
1886 p.dev_name = tokens[7];
1887 } else if (strcmp(tokens[6], "sink") == 0) {
1888 if ((n_tokens != 7) && (n_tokens != 11)) {
1889 snprintf(out, out_size, MSG_ARG_MISMATCH,
1890 "pipeline port out sink");
1894 p.type = PORT_OUT_SINK;
1898 if (n_tokens == 7) {
1899 p.sink.file_name = NULL;
1900 p.sink.max_n_pkts = 0;
1902 if (strcmp(tokens[7], "file") != 0) {
1903 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1908 p.sink.file_name = tokens[8];
1910 if (strcmp(tokens[9], "pkts") != 0) {
1911 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1915 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1916 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1921 } else if (strcmp(tokens[6], "cryptodev") == 0) {
1922 if (n_tokens != 12) {
1923 snprintf(out, out_size, MSG_ARG_MISMATCH,
1924 "pipeline port out cryptodev");
1928 p.type = PORT_OUT_CRYPTODEV;
1930 p.dev_name = tokens[7];
1932 if (strcmp(tokens[8], "txq")) {
1933 snprintf(out, out_size, MSG_ARG_MISMATCH,
1934 "pipeline port out cryptodev");
1938 if (parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
1940 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1944 if (strcmp(tokens[10], "offset")) {
1945 snprintf(out, out_size, MSG_ARG_MISMATCH,
1946 "pipeline port out cryptodev");
1950 if (parser_read_uint32(&p.cryptodev.op_offset, tokens[11])
1952 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1956 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1960 status = pipeline_port_out_create(pipeline_name, &p);
1962 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1967 static const char cmd_pipeline_table_help[] =
1968 "pipeline <pipeline_name> table\n"
1972 " offset <ip_header_offset>\n"
1975 " offset <key_offset>\n"
1980 " mask <key_mask>\n"
1981 " offset <key_offset>\n"
1982 " buckets <n_buckets>\n"
1986 " offset <ip_header_offset>\n"
1989 " [action <table_action_profile_name>]\n";
1992 cmd_pipeline_table(char **tokens,
1997 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
1998 struct table_params p;
1999 char *pipeline_name;
2004 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2008 pipeline_name = tokens[1];
2010 if (strcmp(tokens[2], "table") != 0) {
2011 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2015 if (strcmp(tokens[3], "match") != 0) {
2016 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2021 if (strcmp(tokens[t0], "acl") == 0) {
2022 if (n_tokens < t0 + 6) {
2023 snprintf(out, out_size, MSG_ARG_MISMATCH,
2024 "pipeline table acl");
2028 p.match_type = TABLE_ACL;
2030 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2031 p.match.acl.ip_version = 1;
2032 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2033 p.match.acl.ip_version = 0;
2035 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2040 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2041 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2045 if (parser_read_uint32(&p.match.acl.ip_header_offset,
2046 tokens[t0 + 3]) != 0) {
2047 snprintf(out, out_size, MSG_ARG_INVALID,
2048 "ip_header_offset");
2052 if (strcmp(tokens[t0 + 4], "size") != 0) {
2053 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2057 if (parser_read_uint32(&p.match.acl.n_rules,
2058 tokens[t0 + 5]) != 0) {
2059 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2064 } else if (strcmp(tokens[t0], "array") == 0) {
2065 if (n_tokens < t0 + 5) {
2066 snprintf(out, out_size, MSG_ARG_MISMATCH,
2067 "pipeline table array");
2071 p.match_type = TABLE_ARRAY;
2073 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2074 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2078 if (parser_read_uint32(&p.match.array.key_offset,
2079 tokens[t0 + 2]) != 0) {
2080 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2084 if (strcmp(tokens[t0 + 3], "size") != 0) {
2085 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2089 if (parser_read_uint32(&p.match.array.n_keys,
2090 tokens[t0 + 4]) != 0) {
2091 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2096 } else if (strcmp(tokens[t0], "hash") == 0) {
2097 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2099 if (n_tokens < t0 + 12) {
2100 snprintf(out, out_size, MSG_ARG_MISMATCH,
2101 "pipeline table hash");
2105 p.match_type = TABLE_HASH;
2107 if (strcmp(tokens[t0 + 1], "ext") == 0)
2108 p.match.hash.extendable_bucket = 1;
2109 else if (strcmp(tokens[t0 + 1], "lru") == 0)
2110 p.match.hash.extendable_bucket = 0;
2112 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2117 if (strcmp(tokens[t0 + 2], "key") != 0) {
2118 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2122 if ((parser_read_uint32(&p.match.hash.key_size,
2123 tokens[t0 + 3]) != 0) ||
2124 (p.match.hash.key_size == 0) ||
2125 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
2126 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2130 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2131 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2135 if ((parse_hex_string(tokens[t0 + 5],
2136 key_mask, &key_mask_size) != 0) ||
2137 (key_mask_size != p.match.hash.key_size)) {
2138 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2141 p.match.hash.key_mask = key_mask;
2143 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2144 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2148 if (parser_read_uint32(&p.match.hash.key_offset,
2149 tokens[t0 + 7]) != 0) {
2150 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2154 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2155 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2159 if (parser_read_uint32(&p.match.hash.n_buckets,
2160 tokens[t0 + 9]) != 0) {
2161 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2165 if (strcmp(tokens[t0 + 10], "size") != 0) {
2166 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2170 if (parser_read_uint32(&p.match.hash.n_keys,
2171 tokens[t0 + 11]) != 0) {
2172 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2177 } else if (strcmp(tokens[t0], "lpm") == 0) {
2178 if (n_tokens < t0 + 6) {
2179 snprintf(out, out_size, MSG_ARG_MISMATCH,
2180 "pipeline table lpm");
2184 p.match_type = TABLE_LPM;
2186 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2187 p.match.lpm.key_size = 4;
2188 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2189 p.match.lpm.key_size = 16;
2191 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2196 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2197 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2201 if (parser_read_uint32(&p.match.lpm.key_offset,
2202 tokens[t0 + 3]) != 0) {
2203 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2207 if (strcmp(tokens[t0 + 4], "size") != 0) {
2208 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2212 if (parser_read_uint32(&p.match.lpm.n_rules,
2213 tokens[t0 + 5]) != 0) {
2214 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2219 } else if (strcmp(tokens[t0], "stub") == 0) {
2220 p.match_type = TABLE_STUB;
2224 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2228 p.action_profile_name = NULL;
2229 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
2230 if (n_tokens < t0 + 2) {
2231 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2235 p.action_profile_name = tokens[t0 + 1];
2240 if (n_tokens > t0) {
2241 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2245 status = pipeline_table_create(pipeline_name, &p);
2247 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2252 static const char cmd_pipeline_port_in_table_help[] =
2253 "pipeline <pipeline_name> port in <port_id> table <table_id>\n";
2256 cmd_pipeline_port_in_table(char **tokens,
2261 char *pipeline_name;
2262 uint32_t port_id, table_id;
2265 if (n_tokens != 7) {
2266 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2270 pipeline_name = tokens[1];
2272 if (strcmp(tokens[2], "port") != 0) {
2273 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2277 if (strcmp(tokens[3], "in") != 0) {
2278 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2282 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2283 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2287 if (strcmp(tokens[5], "table") != 0) {
2288 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2292 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
2293 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2297 status = pipeline_port_in_connect_to_table(pipeline_name,
2301 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2307 static const char cmd_pipeline_port_in_stats_help[] =
2308 "pipeline <pipeline_name> port in <port_id> stats read [clear]\n";
2310 #define MSG_PIPELINE_PORT_IN_STATS \
2311 "Pkts in: %" PRIu64 "\n" \
2312 "Pkts dropped by AH: %" PRIu64 "\n" \
2313 "Pkts dropped by other: %" PRIu64 "\n"
2316 cmd_pipeline_port_in_stats(char **tokens,
2321 struct rte_pipeline_port_in_stats stats;
2322 char *pipeline_name;
2326 if ((n_tokens != 7) && (n_tokens != 8)) {
2327 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2331 pipeline_name = tokens[1];
2333 if (strcmp(tokens[2], "port") != 0) {
2334 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2338 if (strcmp(tokens[3], "in") != 0) {
2339 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2343 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2344 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2348 if (strcmp(tokens[5], "stats") != 0) {
2349 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2353 if (strcmp(tokens[6], "read") != 0) {
2354 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2359 if (n_tokens == 8) {
2360 if (strcmp(tokens[7], "clear") != 0) {
2361 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2368 status = pipeline_port_in_stats_read(pipeline_name,
2373 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2377 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2378 stats.stats.n_pkts_in,
2379 stats.n_pkts_dropped_by_ah,
2380 stats.stats.n_pkts_drop);
2384 static const char cmd_pipeline_port_in_enable_help[] =
2385 "pipeline <pipeline_name> port in <port_id> enable\n";
2388 cmd_pipeline_port_in_enable(char **tokens,
2393 char *pipeline_name;
2397 if (n_tokens != 6) {
2398 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2402 pipeline_name = tokens[1];
2404 if (strcmp(tokens[2], "port") != 0) {
2405 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2409 if (strcmp(tokens[3], "in") != 0) {
2410 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2414 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2415 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2419 if (strcmp(tokens[5], "enable") != 0) {
2420 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2424 status = pipeline_port_in_enable(pipeline_name, port_id);
2426 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2432 static const char cmd_pipeline_port_in_disable_help[] =
2433 "pipeline <pipeline_name> port in <port_id> disable\n";
2436 cmd_pipeline_port_in_disable(char **tokens,
2441 char *pipeline_name;
2445 if (n_tokens != 6) {
2446 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2450 pipeline_name = tokens[1];
2452 if (strcmp(tokens[2], "port") != 0) {
2453 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2457 if (strcmp(tokens[3], "in") != 0) {
2458 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2462 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2463 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2467 if (strcmp(tokens[5], "disable") != 0) {
2468 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2472 status = pipeline_port_in_disable(pipeline_name, port_id);
2474 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2480 static const char cmd_pipeline_port_out_stats_help[] =
2481 "pipeline <pipeline_name> port out <port_id> stats read [clear]\n";
2483 #define MSG_PIPELINE_PORT_OUT_STATS \
2484 "Pkts in: %" PRIu64 "\n" \
2485 "Pkts dropped by AH: %" PRIu64 "\n" \
2486 "Pkts dropped by other: %" PRIu64 "\n"
2489 cmd_pipeline_port_out_stats(char **tokens,
2494 struct rte_pipeline_port_out_stats stats;
2495 char *pipeline_name;
2499 if ((n_tokens != 7) && (n_tokens != 8)) {
2500 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2504 pipeline_name = tokens[1];
2506 if (strcmp(tokens[2], "port") != 0) {
2507 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2511 if (strcmp(tokens[3], "out") != 0) {
2512 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2516 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2517 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2521 if (strcmp(tokens[5], "stats") != 0) {
2522 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2526 if (strcmp(tokens[6], "read") != 0) {
2527 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2532 if (n_tokens == 8) {
2533 if (strcmp(tokens[7], "clear") != 0) {
2534 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2541 status = pipeline_port_out_stats_read(pipeline_name,
2546 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2550 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2551 stats.stats.n_pkts_in,
2552 stats.n_pkts_dropped_by_ah,
2553 stats.stats.n_pkts_drop);
2557 static const char cmd_pipeline_table_stats_help[] =
2558 "pipeline <pipeline_name> table <table_id> stats read [clear]\n";
2560 #define MSG_PIPELINE_TABLE_STATS \
2561 "Pkts in: %" PRIu64 "\n" \
2562 "Pkts in with lookup miss: %" PRIu64 "\n" \
2563 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2564 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2565 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2566 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2569 cmd_pipeline_table_stats(char **tokens,
2574 struct rte_pipeline_table_stats stats;
2575 char *pipeline_name;
2579 if ((n_tokens != 6) && (n_tokens != 7)) {
2580 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2584 pipeline_name = tokens[1];
2586 if (strcmp(tokens[2], "table") != 0) {
2587 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2591 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2592 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2596 if (strcmp(tokens[4], "stats") != 0) {
2597 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2601 if (strcmp(tokens[5], "read") != 0) {
2602 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2607 if (n_tokens == 7) {
2608 if (strcmp(tokens[6], "clear") != 0) {
2609 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2616 status = pipeline_table_stats_read(pipeline_name,
2621 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2625 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2626 stats.stats.n_pkts_in,
2627 stats.stats.n_pkts_lookup_miss,
2628 stats.n_pkts_dropped_by_lkp_hit_ah,
2629 stats.n_pkts_dropped_lkp_hit,
2630 stats.n_pkts_dropped_by_lkp_miss_ah,
2631 stats.n_pkts_dropped_lkp_miss);
2639 * priority <priority>
2640 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2641 * <sp0> <sp1> <dp0> <dp1> <proto>
2645 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2646 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2647 * | ipv4_addr <addr>
2648 * | ipv6_addr <addr>
2649 * | qinq <svlan> <cvlan>
2651 * ipv4 | ipv6 <addr> <depth>
2653 struct pkt_key_qinq {
2654 uint16_t ethertype_svlan;
2656 uint16_t ethertype_cvlan;
2660 struct pkt_key_ipv4_5tuple {
2661 uint8_t time_to_live;
2663 uint16_t hdr_checksum;
2670 struct pkt_key_ipv6_5tuple {
2671 uint16_t payload_length;
2680 struct pkt_key_ipv4_addr {
2684 struct pkt_key_ipv6_addr {
2689 parse_match(char **tokens,
2693 struct table_rule_match *m)
2695 memset(m, 0, sizeof(*m));
2700 if (strcmp(tokens[0], "match") != 0) {
2701 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2705 if (strcmp(tokens[1], "acl") == 0) {
2706 if (n_tokens < 14) {
2707 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2711 m->match_type = TABLE_ACL;
2713 if (strcmp(tokens[2], "priority") != 0) {
2714 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2718 if (parser_read_uint32(&m->match.acl.priority,
2720 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2724 if (strcmp(tokens[4], "ipv4") == 0) {
2725 struct in_addr saddr, daddr;
2727 m->match.acl.ip_version = 1;
2729 if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2730 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2733 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2735 if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2736 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2739 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2740 } else if (strcmp(tokens[4], "ipv6") == 0) {
2741 struct in6_addr saddr, daddr;
2743 m->match.acl.ip_version = 0;
2745 if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2746 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2749 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2751 if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2752 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2755 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2757 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2762 if (parser_read_uint32(&m->match.acl.sa_depth,
2764 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2768 if (parser_read_uint32(&m->match.acl.da_depth,
2770 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2774 if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2775 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2779 if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2780 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2784 if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2785 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2789 if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2790 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2794 if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2795 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2799 m->match.acl.proto_mask = 0xff;
2804 if (strcmp(tokens[1], "array") == 0) {
2806 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2810 m->match_type = TABLE_ARRAY;
2812 if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2813 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2820 if (strcmp(tokens[1], "hash") == 0) {
2822 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2826 m->match_type = TABLE_HASH;
2828 if (strcmp(tokens[2], "raw") == 0) {
2829 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2832 snprintf(out, out_size, MSG_ARG_MISMATCH,
2837 if (parse_hex_string(tokens[3],
2838 m->match.hash.key, &key_size) != 0) {
2839 snprintf(out, out_size, MSG_ARG_INVALID, "key");
2846 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2847 struct pkt_key_ipv4_5tuple *ipv4 =
2848 (struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2849 struct in_addr saddr, daddr;
2854 snprintf(out, out_size, MSG_ARG_MISMATCH,
2859 if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2860 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2864 if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2865 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2869 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2870 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2874 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2875 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2879 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2880 snprintf(out, out_size, MSG_ARG_INVALID,
2885 ipv4->sa = saddr.s_addr;
2886 ipv4->da = daddr.s_addr;
2887 ipv4->sp = rte_cpu_to_be_16(sp);
2888 ipv4->dp = rte_cpu_to_be_16(dp);
2889 ipv4->proto = proto;
2892 } /* hash ipv4_5tuple */
2894 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2895 struct pkt_key_ipv6_5tuple *ipv6 =
2896 (struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2897 struct in6_addr saddr, daddr;
2902 snprintf(out, out_size, MSG_ARG_MISMATCH,
2907 if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2908 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2912 if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2913 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2917 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2918 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2922 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2923 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2927 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2928 snprintf(out, out_size, MSG_ARG_INVALID,
2933 memcpy(ipv6->sa, saddr.s6_addr, 16);
2934 memcpy(ipv6->da, daddr.s6_addr, 16);
2935 ipv6->sp = rte_cpu_to_be_16(sp);
2936 ipv6->dp = rte_cpu_to_be_16(dp);
2937 ipv6->proto = proto;
2940 } /* hash ipv6_5tuple */
2942 if (strcmp(tokens[2], "ipv4_addr") == 0) {
2943 struct pkt_key_ipv4_addr *ipv4_addr =
2944 (struct pkt_key_ipv4_addr *) m->match.hash.key;
2945 struct in_addr addr;
2948 snprintf(out, out_size, MSG_ARG_MISMATCH,
2953 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2954 snprintf(out, out_size, MSG_ARG_INVALID,
2959 ipv4_addr->addr = addr.s_addr;
2962 } /* hash ipv4_addr */
2964 if (strcmp(tokens[2], "ipv6_addr") == 0) {
2965 struct pkt_key_ipv6_addr *ipv6_addr =
2966 (struct pkt_key_ipv6_addr *) m->match.hash.key;
2967 struct in6_addr addr;
2970 snprintf(out, out_size, MSG_ARG_MISMATCH,
2975 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2976 snprintf(out, out_size, MSG_ARG_INVALID,
2981 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
2984 } /* hash ipv6_5tuple */
2986 if (strcmp(tokens[2], "qinq") == 0) {
2987 struct pkt_key_qinq *qinq =
2988 (struct pkt_key_qinq *) m->match.hash.key;
2989 uint16_t svlan, cvlan;
2992 snprintf(out, out_size, MSG_ARG_MISMATCH,
2997 if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
2999 snprintf(out, out_size, MSG_ARG_INVALID,
3004 if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3006 snprintf(out, out_size, MSG_ARG_INVALID,
3011 qinq->svlan = rte_cpu_to_be_16(svlan);
3012 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3017 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3021 if (strcmp(tokens[1], "lpm") == 0) {
3023 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3027 m->match_type = TABLE_LPM;
3029 if (strcmp(tokens[2], "ipv4") == 0) {
3030 struct in_addr addr;
3032 m->match.lpm.ip_version = 1;
3034 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
3035 snprintf(out, out_size, MSG_ARG_INVALID,
3040 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3041 } else if (strcmp(tokens[2], "ipv6") == 0) {
3042 struct in6_addr addr;
3044 m->match.lpm.ip_version = 0;
3046 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
3047 snprintf(out, out_size, MSG_ARG_INVALID,
3052 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3054 snprintf(out, out_size, MSG_ARG_MISMATCH,
3059 if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3060 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3067 snprintf(out, out_size, MSG_ARG_MISMATCH,
3068 "acl or array or hash or lpm");
3080 * | table <table_id>
3081 * [balance <out0> ... <out7>]
3083 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3084 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3085 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3086 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3087 * [tm subport <subport_id> pipe <pipe_id>]
3090 * | vlan <da> <sa> <pcp> <dei> <vid>
3091 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3092 * | qinq_pppoe <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid> <session_id>
3093 * | mpls unicast | multicast
3095 * label0 <label> <tc> <ttl>
3096 * [label1 <label> <tc> <ttl>
3097 * [label2 <label> <tc> <ttl>
3098 * [label3 <label> <tc> <ttl>]]]
3099 * | pppoe <da> <sa> <session_id>
3100 * | vxlan ether <da> <sa>
3101 * [vlan <pcp> <dei> <vid>]
3102 * ipv4 <sa> <da> <dscp> <ttl>
3103 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3106 * [nat ipv4 | ipv6 <addr> <port>]
3114 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3116 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3117 * auth_algo <algo> auth_key <key> digest_size <size>
3119 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3120 * digest_size <size>
3121 * data_offset <data_offset>]
3126 * <pa> ::= g | y | r | drop
3129 parse_table_action_fwd(char **tokens,
3131 struct table_rule_action *a)
3133 if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
3139 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3140 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3141 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3145 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3148 if ((n_tokens < 2) ||
3149 parser_read_uint32(&id, tokens[1]))
3152 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3154 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3158 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3159 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3160 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3164 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3167 if ((n_tokens < 2) ||
3168 parser_read_uint32(&id, tokens[1]))
3171 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3173 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3181 parse_table_action_balance(char **tokens,
3183 struct table_rule_action *a)
3187 if ((n_tokens == 0) || (strcmp(tokens[0], "balance") != 0))
3193 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3196 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3197 if (parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3200 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3201 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3206 parse_policer_action(char *token, enum rte_table_action_policer *a)
3208 if (strcmp(token, "g") == 0) {
3209 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3213 if (strcmp(token, "y") == 0) {
3214 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3218 if (strcmp(token, "r") == 0) {
3219 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3223 if (strcmp(token, "drop") == 0) {
3224 *a = RTE_TABLE_ACTION_POLICER_DROP;
3232 parse_table_action_meter_tc(char **tokens,
3234 struct rte_table_action_mtr_tc_params *mtr)
3236 if ((n_tokens < 9) ||
3237 strcmp(tokens[0], "meter") ||
3238 parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3239 strcmp(tokens[2], "policer") ||
3240 strcmp(tokens[3], "g") ||
3241 parse_policer_action(tokens[4], &mtr->policer[RTE_COLOR_GREEN]) ||
3242 strcmp(tokens[5], "y") ||
3243 parse_policer_action(tokens[6], &mtr->policer[RTE_COLOR_YELLOW]) ||
3244 strcmp(tokens[7], "r") ||
3245 parse_policer_action(tokens[8], &mtr->policer[RTE_COLOR_RED]))
3252 parse_table_action_meter(char **tokens,
3254 struct table_rule_action *a)
3256 if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
3262 if ((n_tokens < 10) ||
3263 strcmp(tokens[0], "tc0") ||
3264 (parse_table_action_meter_tc(tokens + 1,
3266 &a->mtr.mtr[0]) == 0))
3272 if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
3274 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3278 if ((n_tokens < 30) ||
3279 (parse_table_action_meter_tc(tokens + 1,
3280 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3281 strcmp(tokens[10], "tc2") ||
3282 (parse_table_action_meter_tc(tokens + 11,
3283 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3284 strcmp(tokens[20], "tc3") ||
3285 (parse_table_action_meter_tc(tokens + 21,
3286 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3289 a->mtr.tc_mask = 0xF;
3290 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3291 return 1 + 10 + 3 * 10;
3295 parse_table_action_tm(char **tokens,
3297 struct table_rule_action *a)
3299 uint32_t subport_id, pipe_id;
3301 if ((n_tokens < 5) ||
3302 strcmp(tokens[0], "tm") ||
3303 strcmp(tokens[1], "subport") ||
3304 parser_read_uint32(&subport_id, tokens[2]) ||
3305 strcmp(tokens[3], "pipe") ||
3306 parser_read_uint32(&pipe_id, tokens[4]))
3309 a->tm.subport_id = subport_id;
3310 a->tm.pipe_id = pipe_id;
3311 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3316 parse_table_action_encap(char **tokens,
3318 struct table_rule_action *a)
3320 if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
3327 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3328 if ((n_tokens < 3) ||
3329 parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3330 parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3333 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3334 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3339 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3340 uint32_t pcp, dei, vid;
3342 if ((n_tokens < 6) ||
3343 parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3344 parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3345 parser_read_uint32(&pcp, tokens[3]) ||
3347 parser_read_uint32(&dei, tokens[4]) ||
3349 parser_read_uint32(&vid, tokens[5]) ||
3353 a->encap.vlan.vlan.pcp = pcp & 0x7;
3354 a->encap.vlan.vlan.dei = dei & 0x1;
3355 a->encap.vlan.vlan.vid = vid & 0xFFF;
3356 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3357 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3362 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3363 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3364 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3366 if ((n_tokens < 9) ||
3367 parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3368 parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3369 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3370 (svlan_pcp > 0x7) ||
3371 parser_read_uint32(&svlan_dei, tokens[4]) ||
3372 (svlan_dei > 0x1) ||
3373 parser_read_uint32(&svlan_vid, tokens[5]) ||
3374 (svlan_vid > 0xFFF) ||
3375 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3376 (cvlan_pcp > 0x7) ||
3377 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3378 (cvlan_dei > 0x1) ||
3379 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3380 (cvlan_vid > 0xFFF))
3383 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3384 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3385 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3386 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3387 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3388 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3389 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3390 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3395 if (n_tokens && (strcmp(tokens[0], "qinq_pppoe") == 0)) {
3396 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3397 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3399 if ((n_tokens < 10) ||
3400 parse_mac_addr(tokens[1],
3401 &a->encap.qinq_pppoe.ether.da) ||
3402 parse_mac_addr(tokens[2],
3403 &a->encap.qinq_pppoe.ether.sa) ||
3404 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3405 (svlan_pcp > 0x7) ||
3406 parser_read_uint32(&svlan_dei, tokens[4]) ||
3407 (svlan_dei > 0x1) ||
3408 parser_read_uint32(&svlan_vid, tokens[5]) ||
3409 (svlan_vid > 0xFFF) ||
3410 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3411 (cvlan_pcp > 0x7) ||
3412 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3413 (cvlan_dei > 0x1) ||
3414 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3415 (cvlan_vid > 0xFFF) ||
3416 parser_read_uint16(&a->encap.qinq_pppoe.pppoe.session_id,
3420 a->encap.qinq_pppoe.svlan.pcp = svlan_pcp & 0x7;
3421 a->encap.qinq_pppoe.svlan.dei = svlan_dei & 0x1;
3422 a->encap.qinq_pppoe.svlan.vid = svlan_vid & 0xFFF;
3423 a->encap.qinq_pppoe.cvlan.pcp = cvlan_pcp & 0x7;
3424 a->encap.qinq_pppoe.cvlan.dei = cvlan_dei & 0x1;
3425 a->encap.qinq_pppoe.cvlan.vid = cvlan_vid & 0xFFF;
3426 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
3427 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3433 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3434 uint32_t label, tc, ttl;
3439 if (strcmp(tokens[1], "unicast") == 0)
3440 a->encap.mpls.unicast = 1;
3441 else if (strcmp(tokens[1], "multicast") == 0)
3442 a->encap.mpls.unicast = 0;
3446 if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3447 parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3448 strcmp(tokens[4], "label0") ||
3449 parser_read_uint32(&label, tokens[5]) ||
3450 (label > 0xFFFFF) ||
3451 parser_read_uint32(&tc, tokens[6]) ||
3453 parser_read_uint32(&ttl, tokens[7]) ||
3457 a->encap.mpls.mpls[0].label = label;
3458 a->encap.mpls.mpls[0].tc = tc;
3459 a->encap.mpls.mpls[0].ttl = ttl;
3464 if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3465 a->encap.mpls.mpls_count = 1;
3466 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3467 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3471 if ((n_tokens < 4) ||
3472 parser_read_uint32(&label, tokens[1]) ||
3473 (label > 0xFFFFF) ||
3474 parser_read_uint32(&tc, tokens[2]) ||
3476 parser_read_uint32(&ttl, tokens[3]) ||
3480 a->encap.mpls.mpls[1].label = label;
3481 a->encap.mpls.mpls[1].tc = tc;
3482 a->encap.mpls.mpls[1].ttl = ttl;
3487 if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3488 a->encap.mpls.mpls_count = 2;
3489 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3490 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3494 if ((n_tokens < 4) ||
3495 parser_read_uint32(&label, tokens[1]) ||
3496 (label > 0xFFFFF) ||
3497 parser_read_uint32(&tc, tokens[2]) ||
3499 parser_read_uint32(&ttl, tokens[3]) ||
3503 a->encap.mpls.mpls[2].label = label;
3504 a->encap.mpls.mpls[2].tc = tc;
3505 a->encap.mpls.mpls[2].ttl = ttl;
3510 if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3511 a->encap.mpls.mpls_count = 3;
3512 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3513 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3514 return 1 + 8 + 4 + 4;
3517 if ((n_tokens < 4) ||
3518 parser_read_uint32(&label, tokens[1]) ||
3519 (label > 0xFFFFF) ||
3520 parser_read_uint32(&tc, tokens[2]) ||
3522 parser_read_uint32(&ttl, tokens[3]) ||
3526 a->encap.mpls.mpls[3].label = label;
3527 a->encap.mpls.mpls[3].tc = tc;
3528 a->encap.mpls.mpls[3].ttl = ttl;
3530 a->encap.mpls.mpls_count = 4;
3531 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3532 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3533 return 1 + 8 + 4 + 4 + 4;
3537 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3538 if ((n_tokens < 4) ||
3539 parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3540 parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3541 parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3545 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3546 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3551 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3558 /* ether <da> <sa> */
3559 if ((n_tokens < 3) ||
3560 strcmp(tokens[0], "ether") ||
3561 parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3562 parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3569 /* [vlan <pcp> <dei> <vid>] */
3570 if (strcmp(tokens[0], "vlan") == 0) {
3571 uint32_t pcp, dei, vid;
3573 if ((n_tokens < 4) ||
3574 parser_read_uint32(&pcp, tokens[1]) ||
3576 parser_read_uint32(&dei, tokens[2]) ||
3578 parser_read_uint32(&vid, tokens[3]) ||
3582 a->encap.vxlan.vlan.pcp = pcp;
3583 a->encap.vxlan.vlan.dei = dei;
3584 a->encap.vxlan.vlan.vid = vid;
3591 /* ipv4 <sa> <da> <dscp> <ttl>
3592 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3593 if (strcmp(tokens[0], "ipv4") == 0) {
3594 struct in_addr sa, da;
3597 if ((n_tokens < 5) ||
3598 parse_ipv4_addr(tokens[1], &sa) ||
3599 parse_ipv4_addr(tokens[2], &da) ||
3600 parser_read_uint8(&dscp, tokens[3]) ||
3602 parser_read_uint8(&ttl, tokens[4]))
3605 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3606 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3607 a->encap.vxlan.ipv4.dscp = dscp;
3608 a->encap.vxlan.ipv4.ttl = ttl;
3613 } else if (strcmp(tokens[0], "ipv6") == 0) {
3614 struct in6_addr sa, da;
3615 uint32_t flow_label;
3616 uint8_t dscp, hop_limit;
3618 if ((n_tokens < 6) ||
3619 parse_ipv6_addr(tokens[1], &sa) ||
3620 parse_ipv6_addr(tokens[2], &da) ||
3621 parser_read_uint32(&flow_label, tokens[3]) ||
3622 parser_read_uint8(&dscp, tokens[4]) ||
3624 parser_read_uint8(&hop_limit, tokens[5]))
3627 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3628 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3629 a->encap.vxlan.ipv6.flow_label = flow_label;
3630 a->encap.vxlan.ipv6.dscp = dscp;
3631 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3640 if ((n_tokens < 3) ||
3641 strcmp(tokens[0], "udp") ||
3642 parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3643 parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3651 if ((n_tokens < 2) ||
3652 strcmp(tokens[0], "vxlan") ||
3653 parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3654 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3661 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3662 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3670 parse_table_action_nat(char **tokens,
3672 struct table_rule_action *a)
3674 if ((n_tokens < 4) ||
3675 strcmp(tokens[0], "nat"))
3678 if (strcmp(tokens[1], "ipv4") == 0) {
3679 struct in_addr addr;
3682 if (parse_ipv4_addr(tokens[2], &addr) ||
3683 parser_read_uint16(&port, tokens[3]))
3686 a->nat.ip_version = 1;
3687 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3689 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3693 if (strcmp(tokens[1], "ipv6") == 0) {
3694 struct in6_addr addr;
3697 if (parse_ipv6_addr(tokens[2], &addr) ||
3698 parser_read_uint16(&port, tokens[3]))
3701 a->nat.ip_version = 0;
3702 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3704 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3712 parse_table_action_ttl(char **tokens,
3714 struct table_rule_action *a)
3716 if ((n_tokens < 2) ||
3717 strcmp(tokens[0], "ttl"))
3720 if (strcmp(tokens[1], "dec") == 0)
3721 a->ttl.decrement = 1;
3722 else if (strcmp(tokens[1], "keep") == 0)
3723 a->ttl.decrement = 0;
3727 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3732 parse_table_action_stats(char **tokens,
3734 struct table_rule_action *a)
3736 if ((n_tokens < 1) ||
3737 strcmp(tokens[0], "stats"))
3740 a->stats.n_packets = 0;
3741 a->stats.n_bytes = 0;
3742 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3747 parse_table_action_time(char **tokens,
3749 struct table_rule_action *a)
3751 if ((n_tokens < 1) ||
3752 strcmp(tokens[0], "time"))
3755 a->time.time = rte_rdtsc();
3756 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3761 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
3763 struct rte_crypto_sym_xform *xform[2] = {NULL};
3766 xform[0] = p->xform;
3768 xform[1] = xform[0]->next;
3770 for (i = 0; i < 2; i++) {
3771 if (xform[i] == NULL)
3774 switch (xform[i]->type) {
3775 case RTE_CRYPTO_SYM_XFORM_CIPHER:
3776 free(p->cipher_auth.cipher_iv.val);
3777 free(p->cipher_auth.cipher_iv_update.val);
3779 case RTE_CRYPTO_SYM_XFORM_AUTH:
3780 if (p->cipher_auth.auth_iv.val)
3781 free(p->cipher_auth.cipher_iv.val);
3782 if (p->cipher_auth.auth_iv_update.val)
3783 free(p->cipher_auth.cipher_iv_update.val);
3785 case RTE_CRYPTO_SYM_XFORM_AEAD:
3786 free(p->aead.iv.val);
3787 free(p->aead.aad.val);
3796 static struct rte_crypto_sym_xform *
3797 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3798 uint8_t *key, uint32_t max_key_len, char **tokens,
3799 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3801 struct rte_crypto_sym_xform *xform_cipher;
3805 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
3806 strcmp(tokens[3], "cipher_key") ||
3807 strcmp(tokens[5], "cipher_iv"))
3810 xform_cipher = calloc(1, sizeof(*xform_cipher));
3811 if (xform_cipher == NULL)
3814 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3815 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
3816 RTE_CRYPTO_CIPHER_OP_DECRYPT;
3819 status = rte_cryptodev_get_cipher_algo_enum(
3820 &xform_cipher->cipher.algo, tokens[2]);
3825 len = strlen(tokens[4]);
3826 if (len / 2 > max_key_len) {
3831 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
3835 xform_cipher->cipher.key.data = key;
3836 xform_cipher->cipher.key.length = (uint16_t)len;
3839 len = strlen(tokens[6]);
3841 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
3842 if (p->cipher_auth.cipher_iv.val == NULL)
3845 status = parse_hex_string(tokens[6],
3846 p->cipher_auth.cipher_iv.val,
3851 xform_cipher->cipher.iv.length = (uint16_t)len;
3852 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3853 p->cipher_auth.cipher_iv.length = (uint32_t)len;
3856 return xform_cipher;
3859 if (p->cipher_auth.cipher_iv.val) {
3860 free(p->cipher_auth.cipher_iv.val);
3861 p->cipher_auth.cipher_iv.val = NULL;
3869 static struct rte_crypto_sym_xform *
3870 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3871 uint8_t *key, uint32_t max_key_len, char **tokens,
3872 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3874 struct rte_crypto_sym_xform *xform_cipher;
3875 struct rte_crypto_sym_xform *xform_auth;
3879 if (n_tokens < 13 ||
3880 strcmp(tokens[7], "auth_algo") ||
3881 strcmp(tokens[9], "auth_key") ||
3882 strcmp(tokens[11], "digest_size"))
3885 xform_auth = calloc(1, sizeof(*xform_auth));
3886 if (xform_auth == NULL)
3889 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
3890 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
3891 RTE_CRYPTO_AUTH_OP_VERIFY;
3894 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
3900 len = strlen(tokens[10]);
3901 if (len / 2 > max_key_len) {
3906 status = parse_hex_string(tokens[10], key, (uint32_t *)&len);
3910 xform_auth->auth.key.data = key;
3911 xform_auth->auth.key.length = (uint16_t)len;
3913 key += xform_auth->auth.key.length;
3914 max_key_len -= xform_auth->auth.key.length;
3916 if (strcmp(tokens[11], "digest_size"))
3919 status = parser_read_uint16(&xform_auth->auth.digest_length,
3924 xform_cipher = parse_table_action_cipher(p, key, max_key_len, tokens,
3925 7, encrypt, used_n_tokens);
3926 if (xform_cipher == NULL)
3929 *used_n_tokens += 6;
3932 xform_cipher->next = xform_auth;
3933 return xform_cipher;
3935 xform_auth->next = xform_cipher;
3940 if (p->cipher_auth.auth_iv.val) {
3941 free(p->cipher_auth.auth_iv.val);
3942 p->cipher_auth.auth_iv.val = 0;
3950 static struct rte_crypto_sym_xform *
3951 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3952 uint8_t *key, uint32_t max_key_len, char **tokens,
3953 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3955 struct rte_crypto_sym_xform *xform_aead;
3959 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
3960 strcmp(tokens[3], "aead_key") ||
3961 strcmp(tokens[5], "aead_iv") ||
3962 strcmp(tokens[7], "aead_aad") ||
3963 strcmp(tokens[9], "digest_size"))
3966 xform_aead = calloc(1, sizeof(*xform_aead));
3967 if (xform_aead == NULL)
3970 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
3971 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
3972 RTE_CRYPTO_AEAD_OP_DECRYPT;
3975 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
3981 len = strlen(tokens[4]);
3982 if (len / 2 > max_key_len) {
3987 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
3991 xform_aead->aead.key.data = key;
3992 xform_aead->aead.key.length = (uint16_t)len;
3995 len = strlen(tokens[6]);
3996 p->aead.iv.val = calloc(1, len / 2 + 1);
3997 if (p->aead.iv.val == NULL)
4000 status = parse_hex_string(tokens[6], p->aead.iv.val,
4005 xform_aead->aead.iv.length = (uint16_t)len;
4006 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4007 p->aead.iv.length = (uint32_t)len;
4010 len = strlen(tokens[8]);
4011 p->aead.aad.val = calloc(1, len / 2 + 1);
4012 if (p->aead.aad.val == NULL)
4015 status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
4019 xform_aead->aead.aad_length = (uint16_t)len;
4020 p->aead.aad.length = (uint32_t)len;
4023 status = parser_read_uint16(&xform_aead->aead.digest_length,
4028 *used_n_tokens = 11;
4033 if (p->aead.iv.val) {
4034 free(p->aead.iv.val);
4035 p->aead.iv.val = NULL;
4037 if (p->aead.aad.val) {
4038 free(p->aead.aad.val);
4039 p->aead.aad.val = NULL;
4049 parse_table_action_sym_crypto(char **tokens,
4051 struct table_rule_action *a)
4053 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4054 struct rte_crypto_sym_xform *xform = NULL;
4055 uint8_t *key = a->sym_crypto_key;
4056 uint32_t max_key_len = SYM_CRYPTO_MAX_KEY_SIZE;
4057 uint32_t used_n_tokens;
4061 if ((n_tokens < 12) ||
4062 strcmp(tokens[0], "sym_crypto") ||
4063 strcmp(tokens[2], "type"))
4066 memset(p, 0, sizeof(*p));
4068 if (strcmp(tokens[1], "encrypt") == 0)
4073 status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4077 if (strcmp(tokens[3], "cipher") == 0) {
4081 xform = parse_table_action_cipher(p, key, max_key_len, tokens,
4082 n_tokens, encrypt, &used_n_tokens);
4083 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4087 xform = parse_table_action_cipher_auth(p, key, max_key_len,
4088 tokens, n_tokens, encrypt, &used_n_tokens);
4089 } else if (strcmp(tokens[3], "aead") == 0) {
4093 xform = parse_table_action_aead(p, key, max_key_len, tokens,
4094 n_tokens, encrypt, &used_n_tokens);
4102 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4103 parse_free_sym_crypto_param_data(p);
4107 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4109 return used_n_tokens + 5;
4113 parse_table_action_tag(char **tokens,
4115 struct table_rule_action *a)
4117 if ((n_tokens < 2) ||
4118 strcmp(tokens[0], "tag"))
4121 if (parser_read_uint32(&a->tag.tag, tokens[1]))
4124 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4129 parse_table_action_decap(char **tokens,
4131 struct table_rule_action *a)
4133 if ((n_tokens < 2) ||
4134 strcmp(tokens[0], "decap"))
4137 if (parser_read_uint16(&a->decap.n, tokens[1]))
4140 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4145 parse_table_action(char **tokens,
4149 struct table_rule_action *a)
4151 uint32_t n_tokens0 = n_tokens;
4153 memset(a, 0, sizeof(*a));
4155 if ((n_tokens < 2) ||
4156 strcmp(tokens[0], "action"))
4162 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4165 n = parse_table_action_fwd(tokens, n_tokens, a);
4167 snprintf(out, out_size, MSG_ARG_INVALID,
4176 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4179 n = parse_table_action_balance(tokens, n_tokens, a);
4181 snprintf(out, out_size, MSG_ARG_INVALID,
4190 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4193 n = parse_table_action_meter(tokens, n_tokens, a);
4195 snprintf(out, out_size, MSG_ARG_INVALID,
4204 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4207 n = parse_table_action_tm(tokens, n_tokens, a);
4209 snprintf(out, out_size, MSG_ARG_INVALID,
4218 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4221 n = parse_table_action_encap(tokens, n_tokens, a);
4223 snprintf(out, out_size, MSG_ARG_INVALID,
4232 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4235 n = parse_table_action_nat(tokens, n_tokens, a);
4237 snprintf(out, out_size, MSG_ARG_INVALID,
4246 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4249 n = parse_table_action_ttl(tokens, n_tokens, a);
4251 snprintf(out, out_size, MSG_ARG_INVALID,
4260 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4263 n = parse_table_action_stats(tokens, n_tokens, a);
4265 snprintf(out, out_size, MSG_ARG_INVALID,
4274 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4277 n = parse_table_action_time(tokens, n_tokens, a);
4279 snprintf(out, out_size, MSG_ARG_INVALID,
4288 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4291 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4293 snprintf(out, out_size, MSG_ARG_INVALID,
4294 "action sym_crypto");
4301 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4304 n = parse_table_action_tag(tokens, n_tokens, a);
4306 snprintf(out, out_size, MSG_ARG_INVALID,
4315 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4318 n = parse_table_action_decap(tokens, n_tokens, a);
4320 snprintf(out, out_size, MSG_ARG_INVALID,
4329 if (n_tokens0 - n_tokens == 1) {
4330 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4334 return n_tokens0 - n_tokens;
4338 static const char cmd_pipeline_table_rule_add_help[] =
4339 "pipeline <pipeline_name> table <table_id> rule add\n"
4341 " action <table_action>\n";
4344 cmd_pipeline_table_rule_add(char **tokens,
4349 struct table_rule_match m;
4350 struct table_rule_action a;
4351 char *pipeline_name;
4352 uint32_t table_id, t0, n_tokens_parsed;
4356 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4360 pipeline_name = tokens[1];
4362 if (strcmp(tokens[2], "table") != 0) {
4363 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4367 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4368 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4372 if (strcmp(tokens[4], "rule") != 0) {
4373 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4377 if (strcmp(tokens[5], "add") != 0) {
4378 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4385 n_tokens_parsed = parse_match(tokens + t0,
4390 if (n_tokens_parsed == 0)
4392 t0 += n_tokens_parsed;
4395 n_tokens_parsed = parse_table_action(tokens + t0,
4400 if (n_tokens_parsed == 0)
4402 t0 += n_tokens_parsed;
4404 if (t0 != n_tokens) {
4405 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4409 status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
4411 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4415 if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
4416 parse_free_sym_crypto_param_data(&a.sym_crypto);
4420 static const char cmd_pipeline_table_rule_add_default_help[] =
4421 "pipeline <pipeline_name> table <table_id> rule add\n"
4427 " | port <port_id>\n"
4429 " | table <table_id>\n";
4432 cmd_pipeline_table_rule_add_default(char **tokens,
4437 struct table_rule_action action;
4438 char *pipeline_name;
4442 if ((n_tokens != 11) && (n_tokens != 12)) {
4443 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4447 pipeline_name = tokens[1];
4449 if (strcmp(tokens[2], "table") != 0) {
4450 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4454 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4455 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4459 if (strcmp(tokens[4], "rule") != 0) {
4460 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4464 if (strcmp(tokens[5], "add") != 0) {
4465 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4469 if (strcmp(tokens[6], "match") != 0) {
4470 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4474 if (strcmp(tokens[7], "default") != 0) {
4475 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4479 if (strcmp(tokens[8], "action") != 0) {
4480 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4484 if (strcmp(tokens[9], "fwd") != 0) {
4485 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4489 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4491 if (strcmp(tokens[10], "drop") == 0) {
4492 if (n_tokens != 11) {
4493 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4497 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4498 } else if (strcmp(tokens[10], "port") == 0) {
4501 if (n_tokens != 12) {
4502 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4506 if (parser_read_uint32(&id, tokens[11]) != 0) {
4507 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4511 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4513 } else if (strcmp(tokens[10], "meta") == 0) {
4514 if (n_tokens != 11) {
4515 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4519 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4520 } else if (strcmp(tokens[10], "table") == 0) {
4523 if (n_tokens != 12) {
4524 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4528 if (parser_read_uint32(&id, tokens[11]) != 0) {
4529 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4533 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4536 snprintf(out, out_size, MSG_ARG_INVALID,
4537 "drop or port or meta or table");
4541 status = pipeline_table_rule_add_default(pipeline_name,
4545 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4551 static const char cmd_pipeline_table_rule_add_bulk_help[] =
4552 "pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\n"
4554 " File <file_name>:\n"
4555 " - line format: match <match> action <action>\n";
4558 cli_rule_file_process(const char *file_name,
4559 size_t line_len_max,
4560 struct table_rule_list **rule_list,
4562 uint32_t *line_number,
4567 cmd_pipeline_table_rule_add_bulk(char **tokens,
4572 struct table_rule_list *list = NULL;
4573 char *pipeline_name, *file_name;
4574 uint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;
4577 if (n_tokens != 8) {
4578 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4582 pipeline_name = tokens[1];
4584 if (strcmp(tokens[2], "table") != 0) {
4585 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4589 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4590 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4594 if (strcmp(tokens[4], "rule") != 0) {
4595 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4599 if (strcmp(tokens[5], "add") != 0) {
4600 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4604 if (strcmp(tokens[6], "bulk") != 0) {
4605 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4609 file_name = tokens[7];
4611 /* Load rules from file. */
4612 status = cli_rule_file_process(file_name,
4620 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4625 status = pipeline_table_rule_add_bulk(pipeline_name,
4629 &n_rules_not_added);
4631 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4635 snprintf(out, out_size, "Added %u rules out of %u.\n",
4641 static const char cmd_pipeline_table_rule_delete_help[] =
4642 "pipeline <pipeline_name> table <table_id> rule delete\n"
4646 cmd_pipeline_table_rule_delete(char **tokens,
4651 struct table_rule_match m;
4652 char *pipeline_name;
4653 uint32_t table_id, n_tokens_parsed, t0;
4657 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4661 pipeline_name = tokens[1];
4663 if (strcmp(tokens[2], "table") != 0) {
4664 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4668 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4669 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4673 if (strcmp(tokens[4], "rule") != 0) {
4674 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4678 if (strcmp(tokens[5], "delete") != 0) {
4679 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4686 n_tokens_parsed = parse_match(tokens + t0,
4691 if (n_tokens_parsed == 0)
4693 t0 += n_tokens_parsed;
4695 if (n_tokens != t0) {
4696 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4700 status = pipeline_table_rule_delete(pipeline_name,
4704 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4710 static const char cmd_pipeline_table_rule_delete_default_help[] =
4711 "pipeline <pipeline_name> table <table_id> rule delete\n"
4716 cmd_pipeline_table_rule_delete_default(char **tokens,
4721 char *pipeline_name;
4725 if (n_tokens != 8) {
4726 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4730 pipeline_name = tokens[1];
4732 if (strcmp(tokens[2], "table") != 0) {
4733 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4737 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4738 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4742 if (strcmp(tokens[4], "rule") != 0) {
4743 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4747 if (strcmp(tokens[5], "delete") != 0) {
4748 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4752 if (strcmp(tokens[6], "match") != 0) {
4753 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4757 if (strcmp(tokens[7], "default") != 0) {
4758 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4762 status = pipeline_table_rule_delete_default(pipeline_name,
4765 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4771 ether_addr_show(FILE *f, struct rte_ether_addr *addr)
4773 fprintf(f, RTE_ETHER_ADDR_PRT_FMT, RTE_ETHER_ADDR_BYTES(addr));
4777 ipv4_addr_show(FILE *f, uint32_t addr)
4779 fprintf(f, "%u.%u.%u.%u",
4781 (addr >> 16) & 0xFF,
4787 ipv6_addr_show(FILE *f, uint8_t *addr)
4789 fprintf(f, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
4790 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:",
4791 (uint32_t)addr[0], (uint32_t)addr[1],
4792 (uint32_t)addr[2], (uint32_t)addr[3],
4793 (uint32_t)addr[4], (uint32_t)addr[5],
4794 (uint32_t)addr[6], (uint32_t)addr[7],
4795 (uint32_t)addr[8], (uint32_t)addr[9],
4796 (uint32_t)addr[10], (uint32_t)addr[11],
4797 (uint32_t)addr[12], (uint32_t)addr[13],
4798 (uint32_t)addr[14], (uint32_t)addr[15]);
4802 policer_action_string(enum rte_table_action_policer action) {
4804 case RTE_TABLE_ACTION_POLICER_COLOR_GREEN: return "G";
4805 case RTE_TABLE_ACTION_POLICER_COLOR_YELLOW: return "Y";
4806 case RTE_TABLE_ACTION_POLICER_COLOR_RED: return "R";
4807 case RTE_TABLE_ACTION_POLICER_DROP: return "D";
4808 default: return "?";
4813 table_rule_show(const char *pipeline_name,
4815 const char *file_name)
4818 struct table *table;
4819 struct table_rule *rule;
4823 /* Check input params. */
4824 if ((pipeline_name == NULL) ||
4825 (file_name == NULL))
4828 p = pipeline_find(pipeline_name);
4830 (table_id >= p->n_tables))
4833 table = &p->table[table_id];
4836 f = fopen(file_name, "w");
4840 /* Write table rules to file. */
4841 TAILQ_FOREACH(rule, &table->rules, node) {
4842 struct table_rule_match *m = &rule->match;
4843 struct table_rule_action *a = &rule->action;
4845 fprintf(f, "match ");
4846 switch (m->match_type) {
4848 fprintf(f, "acl priority %u ",
4849 m->match.acl.priority);
4851 fprintf(f, m->match.acl.ip_version ? "ipv4 " : "ipv6 ");
4853 if (m->match.acl.ip_version)
4854 ipv4_addr_show(f, m->match.acl.ipv4.sa);
4856 ipv6_addr_show(f, m->match.acl.ipv6.sa);
4858 fprintf(f, "%u", m->match.acl.sa_depth);
4860 if (m->match.acl.ip_version)
4861 ipv4_addr_show(f, m->match.acl.ipv4.da);
4863 ipv6_addr_show(f, m->match.acl.ipv6.da);
4865 fprintf(f, "%u", m->match.acl.da_depth);
4867 fprintf(f, "%u %u %u %u %u ",
4868 (uint32_t)m->match.acl.sp0,
4869 (uint32_t)m->match.acl.sp1,
4870 (uint32_t)m->match.acl.dp0,
4871 (uint32_t)m->match.acl.dp1,
4872 (uint32_t)m->match.acl.proto);
4876 fprintf(f, "array %u ",
4877 m->match.array.pos);
4881 fprintf(f, "hash raw ");
4882 for (i = 0; i < table->params.match.hash.key_size; i++)
4883 fprintf(f, "%02x", m->match.hash.key[i]);
4890 fprintf(f, m->match.lpm.ip_version ? "ipv4 " : "ipv6 ");
4892 if (m->match.acl.ip_version)
4893 ipv4_addr_show(f, m->match.lpm.ipv4);
4895 ipv6_addr_show(f, m->match.lpm.ipv6);
4898 (uint32_t)m->match.lpm.depth);
4902 fprintf(f, "unknown ");
4905 fprintf(f, "action ");
4906 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
4908 switch (a->fwd.action) {
4909 case RTE_PIPELINE_ACTION_DROP:
4910 fprintf(f, "drop ");
4913 case RTE_PIPELINE_ACTION_PORT:
4914 fprintf(f, "port %u ", a->fwd.id);
4917 case RTE_PIPELINE_ACTION_PORT_META:
4918 fprintf(f, "meta ");
4921 case RTE_PIPELINE_ACTION_TABLE:
4923 fprintf(f, "table %u ", a->fwd.id);
4927 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
4928 fprintf(f, "balance ");
4929 for (i = 0; i < RTE_DIM(a->lb.out); i++)
4930 fprintf(f, "%u ", a->lb.out[i]);
4933 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
4935 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++)
4936 if (a->mtr.tc_mask & (1 << i)) {
4937 struct rte_table_action_mtr_tc_params *p =
4939 enum rte_table_action_policer ga =
4940 p->policer[RTE_COLOR_GREEN];
4941 enum rte_table_action_policer ya =
4942 p->policer[RTE_COLOR_YELLOW];
4943 enum rte_table_action_policer ra =
4944 p->policer[RTE_COLOR_RED];
4946 fprintf(f, "tc%u meter %u policer g %s y %s r %s ",
4948 a->mtr.mtr[i].meter_profile_id,
4949 policer_action_string(ga),
4950 policer_action_string(ya),
4951 policer_action_string(ra));
4955 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TM))
4956 fprintf(f, "tm subport %u pipe %u ",
4960 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
4961 fprintf(f, "encap ");
4962 switch (a->encap.type) {
4963 case RTE_TABLE_ACTION_ENCAP_ETHER:
4964 fprintf(f, "ether ");
4965 ether_addr_show(f, &a->encap.ether.ether.da);
4967 ether_addr_show(f, &a->encap.ether.ether.sa);
4971 case RTE_TABLE_ACTION_ENCAP_VLAN:
4972 fprintf(f, "vlan ");
4973 ether_addr_show(f, &a->encap.vlan.ether.da);
4975 ether_addr_show(f, &a->encap.vlan.ether.sa);
4976 fprintf(f, " pcp %u dei %u vid %u ",
4977 a->encap.vlan.vlan.pcp,
4978 a->encap.vlan.vlan.dei,
4979 a->encap.vlan.vlan.vid);
4982 case RTE_TABLE_ACTION_ENCAP_QINQ:
4983 fprintf(f, "qinq ");
4984 ether_addr_show(f, &a->encap.qinq.ether.da);
4986 ether_addr_show(f, &a->encap.qinq.ether.sa);
4987 fprintf(f, " pcp %u dei %u vid %u pcp %u dei %u vid %u ",
4988 a->encap.qinq.svlan.pcp,
4989 a->encap.qinq.svlan.dei,
4990 a->encap.qinq.svlan.vid,
4991 a->encap.qinq.cvlan.pcp,
4992 a->encap.qinq.cvlan.dei,
4993 a->encap.qinq.cvlan.vid);
4996 case RTE_TABLE_ACTION_ENCAP_MPLS:
4997 fprintf(f, "mpls %s ", (a->encap.mpls.unicast) ?
4998 "unicast " : "multicast ");
4999 ether_addr_show(f, &a->encap.mpls.ether.da);
5001 ether_addr_show(f, &a->encap.mpls.ether.sa);
5003 for (i = 0; i < a->encap.mpls.mpls_count; i++) {
5004 struct rte_table_action_mpls_hdr *l =
5005 &a->encap.mpls.mpls[i];
5007 fprintf(f, "label%u %u %u %u ",
5015 case RTE_TABLE_ACTION_ENCAP_PPPOE:
5016 fprintf(f, "pppoe ");
5017 ether_addr_show(f, &a->encap.pppoe.ether.da);
5019 ether_addr_show(f, &a->encap.pppoe.ether.sa);
5020 fprintf(f, " %u ", a->encap.pppoe.pppoe.session_id);
5023 case RTE_TABLE_ACTION_ENCAP_VXLAN:
5024 fprintf(f, "vxlan ether ");
5025 ether_addr_show(f, &a->encap.vxlan.ether.da);
5027 ether_addr_show(f, &a->encap.vxlan.ether.sa);
5028 if (table->ap->params.encap.vxlan.vlan)
5029 fprintf(f, " vlan pcp %u dei %u vid %u ",
5030 a->encap.vxlan.vlan.pcp,
5031 a->encap.vxlan.vlan.dei,
5032 a->encap.vxlan.vlan.vid);
5033 if (table->ap->params.encap.vxlan.ip_version) {
5034 fprintf(f, " ipv4 ");
5035 ipv4_addr_show(f, a->encap.vxlan.ipv4.sa);
5037 ipv4_addr_show(f, a->encap.vxlan.ipv4.da);
5038 fprintf(f, " %u %u ",
5039 (uint32_t)a->encap.vxlan.ipv4.dscp,
5040 (uint32_t)a->encap.vxlan.ipv4.ttl);
5042 fprintf(f, " ipv6 ");
5043 ipv6_addr_show(f, a->encap.vxlan.ipv6.sa);
5045 ipv6_addr_show(f, a->encap.vxlan.ipv6.da);
5046 fprintf(f, " %u %u %u ",
5047 a->encap.vxlan.ipv6.flow_label,
5048 (uint32_t)a->encap.vxlan.ipv6.dscp,
5049 (uint32_t)a->encap.vxlan.ipv6.hop_limit);
5050 fprintf(f, " udp %u %u vxlan %u ",
5051 a->encap.vxlan.udp.sp,
5052 a->encap.vxlan.udp.dp,
5053 a->encap.vxlan.vxlan.vni);
5058 fprintf(f, "unknown ");
5062 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
5063 fprintf(f, "nat %s ", (a->nat.ip_version) ? "ipv4 " : "ipv6 ");
5064 if (a->nat.ip_version)
5065 ipv4_addr_show(f, a->nat.addr.ipv4);
5067 ipv6_addr_show(f, a->nat.addr.ipv6);
5068 fprintf(f, " %u ", (uint32_t)(a->nat.port));
5071 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TTL))
5072 fprintf(f, "ttl %s ", (a->ttl.decrement) ? "dec" : "keep");
5074 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_STATS))
5075 fprintf(f, "stats ");
5077 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TIME))
5078 fprintf(f, "time ");
5080 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO))
5081 fprintf(f, "sym_crypto ");
5083 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TAG))
5084 fprintf(f, "tag %u ", a->tag.tag);
5086 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
5087 fprintf(f, "decap %u ", a->decap.n);
5093 /* Write table default rule to file. */
5094 if (table->rule_default) {
5095 struct table_rule_action *a = &table->rule_default->action;
5097 fprintf(f, "# match default action fwd ");
5099 switch (a->fwd.action) {
5100 case RTE_PIPELINE_ACTION_DROP:
5101 fprintf(f, "drop ");
5104 case RTE_PIPELINE_ACTION_PORT:
5105 fprintf(f, "port %u ", a->fwd.id);
5108 case RTE_PIPELINE_ACTION_PORT_META:
5109 fprintf(f, "meta ");
5112 case RTE_PIPELINE_ACTION_TABLE:
5114 fprintf(f, "table %u ", a->fwd.id);
5117 fprintf(f, "# match default action fwd drop ");
5127 static const char cmd_pipeline_table_rule_show_help[] =
5128 "pipeline <pipeline_name> table <table_id> rule show\n"
5129 " file <file_name>\n";
5132 cmd_pipeline_table_rule_show(char **tokens,
5137 char *file_name = NULL, *pipeline_name;
5141 if (n_tokens != 8) {
5142 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5146 pipeline_name = tokens[1];
5148 if (strcmp(tokens[2], "table") != 0) {
5149 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5153 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5154 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5158 if (strcmp(tokens[4], "rule") != 0) {
5159 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5163 if (strcmp(tokens[5], "show") != 0) {
5164 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "show");
5168 if (strcmp(tokens[6], "file") != 0) {
5169 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "file");
5173 file_name = tokens[7];
5175 status = table_rule_show(pipeline_name, table_id, file_name);
5177 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5182 static const char cmd_pipeline_table_rule_stats_read_help[] =
5183 "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n"
5187 cmd_pipeline_table_rule_stats_read(char **tokens,
5192 struct table_rule_match m;
5193 struct rte_table_action_stats_counters stats;
5194 char *pipeline_name;
5195 uint32_t table_id, n_tokens_parsed;
5196 int clear = 0, status;
5199 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5203 pipeline_name = tokens[1];
5205 if (strcmp(tokens[2], "table") != 0) {
5206 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5210 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5211 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5215 if (strcmp(tokens[4], "rule") != 0) {
5216 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5220 if (strcmp(tokens[5], "read") != 0) {
5221 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5225 if (strcmp(tokens[6], "stats") != 0) {
5226 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
5234 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5242 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5243 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5247 n_tokens_parsed = parse_match(tokens,
5252 if (n_tokens_parsed == 0)
5254 n_tokens -= n_tokens_parsed;
5255 tokens += n_tokens_parsed;
5259 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5263 /* Read table rule stats. */
5264 status = pipeline_table_rule_stats_read(pipeline_name,
5270 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5275 if (stats.n_packets_valid && stats.n_bytes_valid)
5276 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: %" PRIu64 "\n",
5280 if (stats.n_packets_valid && !stats.n_bytes_valid)
5281 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: N/A\n",
5284 if (!stats.n_packets_valid && stats.n_bytes_valid)
5285 snprintf(out, out_size, "Packets: N/A; Bytes: %" PRIu64 "\n",
5288 if (!stats.n_packets_valid && !stats.n_bytes_valid)
5289 snprintf(out, out_size, "Packets: N/A ; Bytes: N/A\n");
5292 static const char cmd_pipeline_table_meter_profile_add_help[] =
5293 "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
5294 " add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
5295 " | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
5298 cmd_pipeline_table_meter_profile_add(char **tokens,
5303 struct rte_table_action_meter_profile p;
5304 char *pipeline_name;
5305 uint32_t table_id, meter_profile_id;
5309 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5313 pipeline_name = tokens[1];
5315 if (strcmp(tokens[2], "table") != 0) {
5316 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5320 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5321 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5325 if (strcmp(tokens[4], "meter") != 0) {
5326 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5330 if (strcmp(tokens[5], "profile") != 0) {
5331 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5335 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5336 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5340 if (strcmp(tokens[7], "add") != 0) {
5341 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5345 if (strcmp(tokens[8], "srtcm") == 0) {
5346 if (n_tokens != 15) {
5347 snprintf(out, out_size, MSG_ARG_MISMATCH,
5352 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5354 if (strcmp(tokens[9], "cir") != 0) {
5355 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5359 if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5360 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5364 if (strcmp(tokens[11], "cbs") != 0) {
5365 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5369 if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5370 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5374 if (strcmp(tokens[13], "ebs") != 0) {
5375 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5379 if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5380 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5383 } else if (strcmp(tokens[8], "trtcm") == 0) {
5384 if (n_tokens != 17) {
5385 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5389 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5391 if (strcmp(tokens[9], "cir") != 0) {
5392 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5396 if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5397 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5401 if (strcmp(tokens[11], "pir") != 0) {
5402 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5406 if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5407 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5410 if (strcmp(tokens[13], "cbs") != 0) {
5411 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5415 if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5416 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5420 if (strcmp(tokens[15], "pbs") != 0) {
5421 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5425 if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5426 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5430 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5434 status = pipeline_table_mtr_profile_add(pipeline_name,
5439 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5445 static const char cmd_pipeline_table_meter_profile_delete_help[] =
5446 "pipeline <pipeline_name> table <table_id>\n"
5447 " meter profile <meter_profile_id> delete\n";
5450 cmd_pipeline_table_meter_profile_delete(char **tokens,
5455 char *pipeline_name;
5456 uint32_t table_id, meter_profile_id;
5459 if (n_tokens != 8) {
5460 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5464 pipeline_name = tokens[1];
5466 if (strcmp(tokens[2], "table") != 0) {
5467 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5471 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5472 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5476 if (strcmp(tokens[4], "meter") != 0) {
5477 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5481 if (strcmp(tokens[5], "profile") != 0) {
5482 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5486 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5487 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5491 if (strcmp(tokens[7], "delete") != 0) {
5492 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5496 status = pipeline_table_mtr_profile_delete(pipeline_name,
5500 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5506 static const char cmd_pipeline_table_rule_meter_read_help[] =
5507 "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n"
5511 cmd_pipeline_table_rule_meter_read(char **tokens,
5516 struct table_rule_match m;
5517 struct rte_table_action_mtr_counters stats;
5518 char *pipeline_name;
5519 uint32_t table_id, n_tokens_parsed;
5520 int clear = 0, status;
5523 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5527 pipeline_name = tokens[1];
5529 if (strcmp(tokens[2], "table") != 0) {
5530 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5534 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5535 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5539 if (strcmp(tokens[4], "rule") != 0) {
5540 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5544 if (strcmp(tokens[5], "read") != 0) {
5545 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5549 if (strcmp(tokens[6], "meter") != 0) {
5550 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5558 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5566 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5567 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5571 n_tokens_parsed = parse_match(tokens,
5576 if (n_tokens_parsed == 0)
5578 n_tokens -= n_tokens_parsed;
5579 tokens += n_tokens_parsed;
5583 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5587 /* Read table rule meter stats. */
5588 status = pipeline_table_rule_mtr_read(pipeline_name,
5594 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5602 static const char cmd_pipeline_table_dscp_help[] =
5603 "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
5605 " File <file_name>:\n"
5606 " - exactly 64 lines\n"
5607 " - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
5610 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5611 const char *file_name,
5612 uint32_t *line_number)
5617 /* Check input arguments */
5618 if ((dscp_table == NULL) ||
5619 (file_name == NULL) ||
5620 (line_number == NULL)) {
5626 /* Open input file */
5627 f = fopen(file_name, "r");
5634 for (dscp = 0, l = 1; ; l++) {
5637 enum rte_color color;
5638 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5640 if (fgets(line, sizeof(line), f) == NULL)
5643 if (is_comment(line))
5646 if (parse_tokenize_string(line, tokens, &n_tokens)) {
5655 if ((dscp >= RTE_DIM(dscp_table->entry)) ||
5656 (n_tokens != RTE_DIM(tokens)) ||
5657 parser_read_uint32(&tc_id, tokens[0]) ||
5658 (tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
5659 parser_read_uint32(&tc_queue_id, tokens[1]) ||
5660 (tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
5661 (strlen(tokens[2]) != 1)) {
5667 switch (tokens[2][0]) {
5670 color = RTE_COLOR_GREEN;
5675 color = RTE_COLOR_YELLOW;
5680 color = RTE_COLOR_RED;
5689 dscp_table->entry[dscp].tc_id = tc_id;
5690 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5691 dscp_table->entry[dscp].color = color;
5701 cmd_pipeline_table_dscp(char **tokens,
5706 struct rte_table_action_dscp_table dscp_table;
5707 char *pipeline_name, *file_name;
5708 uint32_t table_id, line_number;
5711 if (n_tokens != 6) {
5712 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5716 pipeline_name = tokens[1];
5718 if (strcmp(tokens[2], "table") != 0) {
5719 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5723 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5724 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5728 if (strcmp(tokens[4], "dscp") != 0) {
5729 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5733 file_name = tokens[5];
5735 status = load_dscp_table(&dscp_table, file_name, &line_number);
5737 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5741 status = pipeline_table_dscp_table_update(pipeline_name,
5746 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5752 static const char cmd_pipeline_table_rule_ttl_read_help[] =
5753 "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n"
5757 cmd_pipeline_table_rule_ttl_read(char **tokens,
5762 struct table_rule_match m;
5763 struct rte_table_action_ttl_counters stats;
5764 char *pipeline_name;
5765 uint32_t table_id, n_tokens_parsed;
5766 int clear = 0, status;
5769 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5773 pipeline_name = tokens[1];
5775 if (strcmp(tokens[2], "table") != 0) {
5776 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5780 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5781 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5785 if (strcmp(tokens[4], "rule") != 0) {
5786 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5790 if (strcmp(tokens[5], "read") != 0) {
5791 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5795 if (strcmp(tokens[6], "ttl") != 0) {
5796 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ttl");
5804 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5812 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5813 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5817 n_tokens_parsed = parse_match(tokens,
5822 if (n_tokens_parsed == 0)
5824 n_tokens -= n_tokens_parsed;
5825 tokens += n_tokens_parsed;
5829 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5833 /* Read table rule TTL stats. */
5834 status = pipeline_table_rule_ttl_read(pipeline_name,
5840 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5845 snprintf(out, out_size, "Packets: %" PRIu64 "\n",
5849 static const char cmd_pipeline_table_rule_time_read_help[] =
5850 "pipeline <pipeline_name> table <table_id> rule read time\n"
5854 cmd_pipeline_table_rule_time_read(char **tokens,
5859 struct table_rule_match m;
5860 char *pipeline_name;
5862 uint32_t table_id, n_tokens_parsed;
5866 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5870 pipeline_name = tokens[1];
5872 if (strcmp(tokens[2], "table") != 0) {
5873 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5877 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5878 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5882 if (strcmp(tokens[4], "rule") != 0) {
5883 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5887 if (strcmp(tokens[5], "read") != 0) {
5888 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5892 if (strcmp(tokens[6], "time") != 0) {
5893 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "time");
5901 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5902 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5906 n_tokens_parsed = parse_match(tokens,
5911 if (n_tokens_parsed == 0)
5913 n_tokens -= n_tokens_parsed;
5914 tokens += n_tokens_parsed;
5918 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5922 /* Read table rule timestamp. */
5923 status = pipeline_table_rule_time_read(pipeline_name,
5928 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5933 snprintf(out, out_size, "Packets: %" PRIu64 "\n", timestamp);
5936 static const char cmd_thread_pipeline_enable_help[] =
5937 "thread <thread_id> pipeline <pipeline_name> enable\n";
5940 cmd_thread_pipeline_enable(char **tokens,
5945 char *pipeline_name;
5949 if (n_tokens != 5) {
5950 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5954 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5955 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5959 if (strcmp(tokens[2], "pipeline") != 0) {
5960 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5964 pipeline_name = tokens[3];
5966 if (strcmp(tokens[4], "enable") != 0) {
5967 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5971 status = thread_pipeline_enable(thread_id, pipeline_name);
5973 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5979 static const char cmd_thread_pipeline_disable_help[] =
5980 "thread <thread_id> pipeline <pipeline_name> disable\n";
5983 cmd_thread_pipeline_disable(char **tokens,
5988 char *pipeline_name;
5992 if (n_tokens != 5) {
5993 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5997 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5998 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
6002 if (strcmp(tokens[2], "pipeline") != 0) {
6003 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
6007 pipeline_name = tokens[3];
6009 if (strcmp(tokens[4], "disable") != 0) {
6010 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
6014 status = thread_pipeline_disable(thread_id, pipeline_name);
6016 snprintf(out, out_size, MSG_CMD_FAIL,
6017 "thread pipeline disable");
6023 cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
6028 if (n_tokens == 0) {
6029 snprintf(out, out_size,
6030 "Type 'help <command>' for details on each command.\n\n"
6031 "List of commands:\n"
6035 "\ttmgr subport profile\n"
6036 "\ttmgr pipe profile\n"
6039 "\ttmgr subport pipe\n"
6042 "\tport in action profile\n"
6043 "\ttable action profile\n"
6045 "\tpipeline port in\n"
6046 "\tpipeline port out\n"
6047 "\tpipeline table\n"
6048 "\tpipeline port in table\n"
6049 "\tpipeline port in stats\n"
6050 "\tpipeline port in enable\n"
6051 "\tpipeline port in disable\n"
6052 "\tpipeline port out stats\n"
6053 "\tpipeline table stats\n"
6054 "\tpipeline table rule add\n"
6055 "\tpipeline table rule add default\n"
6056 "\tpipeline table rule add bulk\n"
6057 "\tpipeline table rule delete\n"
6058 "\tpipeline table rule delete default\n"
6059 "\tpipeline table rule show\n"
6060 "\tpipeline table rule stats read\n"
6061 "\tpipeline table meter profile add\n"
6062 "\tpipeline table meter profile delete\n"
6063 "\tpipeline table rule meter read\n"
6064 "\tpipeline table dscp\n"
6065 "\tpipeline table rule ttl read\n"
6066 "\tpipeline table rule time read\n"
6067 "\tthread pipeline enable\n"
6068 "\tthread pipeline disable\n\n");
6072 if (strcmp(tokens[0], "mempool") == 0) {
6073 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
6077 if (strcmp(tokens[0], "link") == 0) {
6078 snprintf(out, out_size, "\n%s\n", cmd_link_help);
6082 if (strcmp(tokens[0], "swq") == 0) {
6083 snprintf(out, out_size, "\n%s\n", cmd_swq_help);
6087 if (strcmp(tokens[0], "tmgr") == 0) {
6088 if (n_tokens == 1) {
6089 snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
6093 if ((n_tokens == 2) &&
6094 (strcmp(tokens[1], "subport")) == 0) {
6095 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
6099 if ((n_tokens == 3) &&
6100 (strcmp(tokens[1], "subport") == 0) &&
6101 (strcmp(tokens[2], "profile") == 0)) {
6102 snprintf(out, out_size, "\n%s\n",
6103 cmd_tmgr_subport_profile_help);
6107 if ((n_tokens == 3) &&
6108 (strcmp(tokens[1], "subport") == 0) &&
6109 (strcmp(tokens[2], "pipe") == 0)) {
6110 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
6114 if ((n_tokens == 3) &&
6115 (strcmp(tokens[1], "pipe") == 0) &&
6116 (strcmp(tokens[2], "profile") == 0)) {
6117 snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
6122 if (strcmp(tokens[0], "tap") == 0) {
6123 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
6127 if (strcmp(tokens[0], "kni") == 0) {
6128 snprintf(out, out_size, "\n%s\n", cmd_kni_help);
6132 if (strcmp(tokens[0], "cryptodev") == 0) {
6133 snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
6137 if ((n_tokens == 4) &&
6138 (strcmp(tokens[0], "port") == 0) &&
6139 (strcmp(tokens[1], "in") == 0) &&
6140 (strcmp(tokens[2], "action") == 0) &&
6141 (strcmp(tokens[3], "profile") == 0)) {
6142 snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
6146 if ((n_tokens == 3) &&
6147 (strcmp(tokens[0], "table") == 0) &&
6148 (strcmp(tokens[1], "action") == 0) &&
6149 (strcmp(tokens[2], "profile") == 0)) {
6150 snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
6154 if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
6155 snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
6159 if ((strcmp(tokens[0], "pipeline") == 0) &&
6160 (strcmp(tokens[1], "port") == 0)) {
6161 if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
6162 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
6166 if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
6167 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
6171 if ((n_tokens == 4) &&
6172 (strcmp(tokens[2], "in") == 0) &&
6173 (strcmp(tokens[3], "table") == 0)) {
6174 snprintf(out, out_size, "\n%s\n",
6175 cmd_pipeline_port_in_table_help);
6179 if ((n_tokens == 4) &&
6180 (strcmp(tokens[2], "in") == 0) &&
6181 (strcmp(tokens[3], "stats") == 0)) {
6182 snprintf(out, out_size, "\n%s\n",
6183 cmd_pipeline_port_in_stats_help);
6187 if ((n_tokens == 4) &&
6188 (strcmp(tokens[2], "in") == 0) &&
6189 (strcmp(tokens[3], "enable") == 0)) {
6190 snprintf(out, out_size, "\n%s\n",
6191 cmd_pipeline_port_in_enable_help);
6195 if ((n_tokens == 4) &&
6196 (strcmp(tokens[2], "in") == 0) &&
6197 (strcmp(tokens[3], "disable") == 0)) {
6198 snprintf(out, out_size, "\n%s\n",
6199 cmd_pipeline_port_in_disable_help);
6203 if ((n_tokens == 4) &&
6204 (strcmp(tokens[2], "out") == 0) &&
6205 (strcmp(tokens[3], "stats") == 0)) {
6206 snprintf(out, out_size, "\n%s\n",
6207 cmd_pipeline_port_out_stats_help);
6212 if ((strcmp(tokens[0], "pipeline") == 0) &&
6213 (strcmp(tokens[1], "table") == 0)) {
6214 if (n_tokens == 2) {
6215 snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
6219 if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
6220 snprintf(out, out_size, "\n%s\n",
6221 cmd_pipeline_table_stats_help);
6225 if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
6226 snprintf(out, out_size, "\n%s\n",
6227 cmd_pipeline_table_dscp_help);
6231 if ((n_tokens == 4) &&
6232 (strcmp(tokens[2], "rule") == 0) &&
6233 (strcmp(tokens[3], "add") == 0)) {
6234 snprintf(out, out_size, "\n%s\n",
6235 cmd_pipeline_table_rule_add_help);
6239 if ((n_tokens == 5) &&
6240 (strcmp(tokens[2], "rule") == 0) &&
6241 (strcmp(tokens[3], "add") == 0) &&
6242 (strcmp(tokens[4], "default") == 0)) {
6243 snprintf(out, out_size, "\n%s\n",
6244 cmd_pipeline_table_rule_add_default_help);
6248 if ((n_tokens == 5) &&
6249 (strcmp(tokens[2], "rule") == 0) &&
6250 (strcmp(tokens[3], "add") == 0) &&
6251 (strcmp(tokens[4], "bulk") == 0)) {
6252 snprintf(out, out_size, "\n%s\n",
6253 cmd_pipeline_table_rule_add_bulk_help);
6257 if ((n_tokens == 4) &&
6258 (strcmp(tokens[2], "rule") == 0) &&
6259 (strcmp(tokens[3], "delete") == 0)) {
6260 snprintf(out, out_size, "\n%s\n",
6261 cmd_pipeline_table_rule_delete_help);
6265 if ((n_tokens == 5) &&
6266 (strcmp(tokens[2], "rule") == 0) &&
6267 (strcmp(tokens[3], "delete") == 0) &&
6268 (strcmp(tokens[4], "default") == 0)) {
6269 snprintf(out, out_size, "\n%s\n",
6270 cmd_pipeline_table_rule_delete_default_help);
6274 if ((n_tokens == 4) &&
6275 (strcmp(tokens[2], "rule") == 0) &&
6276 (strcmp(tokens[3], "show") == 0)) {
6277 snprintf(out, out_size, "\n%s\n",
6278 cmd_pipeline_table_rule_show_help);
6282 if ((n_tokens == 5) &&
6283 (strcmp(tokens[2], "rule") == 0) &&
6284 (strcmp(tokens[3], "stats") == 0) &&
6285 (strcmp(tokens[4], "read") == 0)) {
6286 snprintf(out, out_size, "\n%s\n",
6287 cmd_pipeline_table_rule_stats_read_help);
6291 if ((n_tokens == 5) &&
6292 (strcmp(tokens[2], "meter") == 0) &&
6293 (strcmp(tokens[3], "profile") == 0) &&
6294 (strcmp(tokens[4], "add") == 0)) {
6295 snprintf(out, out_size, "\n%s\n",
6296 cmd_pipeline_table_meter_profile_add_help);
6300 if ((n_tokens == 5) &&
6301 (strcmp(tokens[2], "meter") == 0) &&
6302 (strcmp(tokens[3], "profile") == 0) &&
6303 (strcmp(tokens[4], "delete") == 0)) {
6304 snprintf(out, out_size, "\n%s\n",
6305 cmd_pipeline_table_meter_profile_delete_help);
6309 if ((n_tokens == 5) &&
6310 (strcmp(tokens[2], "rule") == 0) &&
6311 (strcmp(tokens[3], "meter") == 0) &&
6312 (strcmp(tokens[4], "read") == 0)) {
6313 snprintf(out, out_size, "\n%s\n",
6314 cmd_pipeline_table_rule_meter_read_help);
6318 if ((n_tokens == 5) &&
6319 (strcmp(tokens[2], "rule") == 0) &&
6320 (strcmp(tokens[3], "ttl") == 0) &&
6321 (strcmp(tokens[4], "read") == 0)) {
6322 snprintf(out, out_size, "\n%s\n",
6323 cmd_pipeline_table_rule_ttl_read_help);
6327 if ((n_tokens == 5) &&
6328 (strcmp(tokens[2], "rule") == 0) &&
6329 (strcmp(tokens[3], "time") == 0) &&
6330 (strcmp(tokens[4], "read") == 0)) {
6331 snprintf(out, out_size, "\n%s\n",
6332 cmd_pipeline_table_rule_time_read_help);
6337 if ((n_tokens == 3) &&
6338 (strcmp(tokens[0], "thread") == 0) &&
6339 (strcmp(tokens[1], "pipeline") == 0)) {
6340 if (strcmp(tokens[2], "enable") == 0) {
6341 snprintf(out, out_size, "\n%s\n",
6342 cmd_thread_pipeline_enable_help);
6346 if (strcmp(tokens[2], "disable") == 0) {
6347 snprintf(out, out_size, "\n%s\n",
6348 cmd_thread_pipeline_disable_help);
6353 snprintf(out, out_size, "Invalid command\n");
6357 cli_process(char *in, char *out, size_t out_size)
6359 char *tokens[CMD_MAX_TOKENS];
6360 uint32_t n_tokens = RTE_DIM(tokens);
6366 status = parse_tokenize_string(in, tokens, &n_tokens);
6368 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
6375 if (strcmp(tokens[0], "help") == 0) {
6376 cmd_help(tokens, n_tokens, out, out_size);
6380 if (strcmp(tokens[0], "mempool") == 0) {
6381 cmd_mempool(tokens, n_tokens, out, out_size);
6385 if (strcmp(tokens[0], "link") == 0) {
6386 if (strcmp(tokens[1], "show") == 0) {
6387 cmd_link_show(tokens, n_tokens, out, out_size);
6391 cmd_link(tokens, n_tokens, out, out_size);
6395 if (strcmp(tokens[0], "swq") == 0) {
6396 cmd_swq(tokens, n_tokens, out, out_size);
6400 if (strcmp(tokens[0], "tmgr") == 0) {
6401 if ((n_tokens >= 3) &&
6402 (strcmp(tokens[1], "subport") == 0) &&
6403 (strcmp(tokens[2], "profile") == 0)) {
6404 cmd_tmgr_subport_profile(tokens, n_tokens,
6409 if ((n_tokens >= 3) &&
6410 (strcmp(tokens[1], "pipe") == 0) &&
6411 (strcmp(tokens[2], "profile") == 0)) {
6412 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
6416 if ((n_tokens >= 5) &&
6417 (strcmp(tokens[2], "subport") == 0) &&
6418 (strcmp(tokens[4], "profile") == 0)) {
6419 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
6423 if ((n_tokens >= 5) &&
6424 (strcmp(tokens[2], "subport") == 0) &&
6425 (strcmp(tokens[4], "pipe") == 0)) {
6426 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
6430 cmd_tmgr(tokens, n_tokens, out, out_size);
6434 if (strcmp(tokens[0], "tap") == 0) {
6435 cmd_tap(tokens, n_tokens, out, out_size);
6439 if (strcmp(tokens[0], "kni") == 0) {
6440 cmd_kni(tokens, n_tokens, out, out_size);
6444 if (strcmp(tokens[0], "cryptodev") == 0) {
6445 cmd_cryptodev(tokens, n_tokens, out, out_size);
6449 if (strcmp(tokens[0], "port") == 0) {
6450 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
6454 if (strcmp(tokens[0], "table") == 0) {
6455 cmd_table_action_profile(tokens, n_tokens, out, out_size);
6459 if (strcmp(tokens[0], "pipeline") == 0) {
6460 if ((n_tokens >= 3) &&
6461 (strcmp(tokens[2], "period") == 0)) {
6462 cmd_pipeline(tokens, n_tokens, out, out_size);
6466 if ((n_tokens >= 5) &&
6467 (strcmp(tokens[2], "port") == 0) &&
6468 (strcmp(tokens[3], "in") == 0) &&
6469 (strcmp(tokens[4], "bsz") == 0)) {
6470 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
6474 if ((n_tokens >= 5) &&
6475 (strcmp(tokens[2], "port") == 0) &&
6476 (strcmp(tokens[3], "out") == 0) &&
6477 (strcmp(tokens[4], "bsz") == 0)) {
6478 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
6482 if ((n_tokens >= 4) &&
6483 (strcmp(tokens[2], "table") == 0) &&
6484 (strcmp(tokens[3], "match") == 0)) {
6485 cmd_pipeline_table(tokens, n_tokens, out, out_size);
6489 if ((n_tokens >= 6) &&
6490 (strcmp(tokens[2], "port") == 0) &&
6491 (strcmp(tokens[3], "in") == 0) &&
6492 (strcmp(tokens[5], "table") == 0)) {
6493 cmd_pipeline_port_in_table(tokens, n_tokens,
6498 if ((n_tokens >= 6) &&
6499 (strcmp(tokens[2], "port") == 0) &&
6500 (strcmp(tokens[3], "in") == 0) &&
6501 (strcmp(tokens[5], "stats") == 0)) {
6502 cmd_pipeline_port_in_stats(tokens, n_tokens,
6507 if ((n_tokens >= 6) &&
6508 (strcmp(tokens[2], "port") == 0) &&
6509 (strcmp(tokens[3], "in") == 0) &&
6510 (strcmp(tokens[5], "enable") == 0)) {
6511 cmd_pipeline_port_in_enable(tokens, n_tokens,
6516 if ((n_tokens >= 6) &&
6517 (strcmp(tokens[2], "port") == 0) &&
6518 (strcmp(tokens[3], "in") == 0) &&
6519 (strcmp(tokens[5], "disable") == 0)) {
6520 cmd_pipeline_port_in_disable(tokens, n_tokens,
6525 if ((n_tokens >= 6) &&
6526 (strcmp(tokens[2], "port") == 0) &&
6527 (strcmp(tokens[3], "out") == 0) &&
6528 (strcmp(tokens[5], "stats") == 0)) {
6529 cmd_pipeline_port_out_stats(tokens, n_tokens,
6534 if ((n_tokens >= 5) &&
6535 (strcmp(tokens[2], "table") == 0) &&
6536 (strcmp(tokens[4], "stats") == 0)) {
6537 cmd_pipeline_table_stats(tokens, n_tokens,
6542 if ((n_tokens >= 7) &&
6543 (strcmp(tokens[2], "table") == 0) &&
6544 (strcmp(tokens[4], "rule") == 0) &&
6545 (strcmp(tokens[5], "add") == 0) &&
6546 (strcmp(tokens[6], "match") == 0)) {
6547 if ((n_tokens >= 8) &&
6548 (strcmp(tokens[7], "default") == 0)) {
6549 cmd_pipeline_table_rule_add_default(tokens,
6550 n_tokens, out, out_size);
6554 cmd_pipeline_table_rule_add(tokens, n_tokens,
6559 if ((n_tokens >= 7) &&
6560 (strcmp(tokens[2], "table") == 0) &&
6561 (strcmp(tokens[4], "rule") == 0) &&
6562 (strcmp(tokens[5], "add") == 0) &&
6563 (strcmp(tokens[6], "bulk") == 0)) {
6564 cmd_pipeline_table_rule_add_bulk(tokens,
6565 n_tokens, out, out_size);
6569 if ((n_tokens >= 7) &&
6570 (strcmp(tokens[2], "table") == 0) &&
6571 (strcmp(tokens[4], "rule") == 0) &&
6572 (strcmp(tokens[5], "delete") == 0) &&
6573 (strcmp(tokens[6], "match") == 0)) {
6574 if ((n_tokens >= 8) &&
6575 (strcmp(tokens[7], "default") == 0)) {
6576 cmd_pipeline_table_rule_delete_default(tokens,
6577 n_tokens, out, out_size);
6581 cmd_pipeline_table_rule_delete(tokens, n_tokens,
6586 if ((n_tokens >= 6) &&
6587 (strcmp(tokens[2], "table") == 0) &&
6588 (strcmp(tokens[4], "rule") == 0) &&
6589 (strcmp(tokens[5], "show") == 0)) {
6590 cmd_pipeline_table_rule_show(tokens, n_tokens,
6595 if ((n_tokens >= 7) &&
6596 (strcmp(tokens[2], "table") == 0) &&
6597 (strcmp(tokens[4], "rule") == 0) &&
6598 (strcmp(tokens[5], "read") == 0) &&
6599 (strcmp(tokens[6], "stats") == 0)) {
6600 cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
6605 if ((n_tokens >= 8) &&
6606 (strcmp(tokens[2], "table") == 0) &&
6607 (strcmp(tokens[4], "meter") == 0) &&
6608 (strcmp(tokens[5], "profile") == 0) &&
6609 (strcmp(tokens[7], "add") == 0)) {
6610 cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
6615 if ((n_tokens >= 8) &&
6616 (strcmp(tokens[2], "table") == 0) &&
6617 (strcmp(tokens[4], "meter") == 0) &&
6618 (strcmp(tokens[5], "profile") == 0) &&
6619 (strcmp(tokens[7], "delete") == 0)) {
6620 cmd_pipeline_table_meter_profile_delete(tokens,
6621 n_tokens, out, out_size);
6625 if ((n_tokens >= 7) &&
6626 (strcmp(tokens[2], "table") == 0) &&
6627 (strcmp(tokens[4], "rule") == 0) &&
6628 (strcmp(tokens[5], "read") == 0) &&
6629 (strcmp(tokens[6], "meter") == 0)) {
6630 cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
6635 if ((n_tokens >= 5) &&
6636 (strcmp(tokens[2], "table") == 0) &&
6637 (strcmp(tokens[4], "dscp") == 0)) {
6638 cmd_pipeline_table_dscp(tokens, n_tokens,
6643 if ((n_tokens >= 7) &&
6644 (strcmp(tokens[2], "table") == 0) &&
6645 (strcmp(tokens[4], "rule") == 0) &&
6646 (strcmp(tokens[5], "read") == 0) &&
6647 (strcmp(tokens[6], "ttl") == 0)) {
6648 cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
6653 if ((n_tokens >= 7) &&
6654 (strcmp(tokens[2], "table") == 0) &&
6655 (strcmp(tokens[4], "rule") == 0) &&
6656 (strcmp(tokens[5], "read") == 0) &&
6657 (strcmp(tokens[6], "time") == 0)) {
6658 cmd_pipeline_table_rule_time_read(tokens, n_tokens,
6664 if (strcmp(tokens[0], "thread") == 0) {
6665 if ((n_tokens >= 5) &&
6666 (strcmp(tokens[4], "enable") == 0)) {
6667 cmd_thread_pipeline_enable(tokens, n_tokens,
6672 if ((n_tokens >= 5) &&
6673 (strcmp(tokens[4], "disable") == 0)) {
6674 cmd_thread_pipeline_disable(tokens, n_tokens,
6680 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
6684 cli_script_process(const char *file_name,
6685 size_t msg_in_len_max,
6686 size_t msg_out_len_max)
6688 char *msg_in = NULL, *msg_out = NULL;
6691 /* Check input arguments */
6692 if ((file_name == NULL) ||
6693 (strlen(file_name) == 0) ||
6694 (msg_in_len_max == 0) ||
6695 (msg_out_len_max == 0))
6698 msg_in = malloc(msg_in_len_max + 1);
6699 msg_out = malloc(msg_out_len_max + 1);
6700 if ((msg_in == NULL) ||
6701 (msg_out == NULL)) {
6707 /* Open input file */
6708 f = fopen(file_name, "r");
6717 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6720 printf("%s", msg_in);
6727 if (strlen(msg_out))
6728 printf("%s", msg_out);
6739 cli_rule_file_process(const char *file_name,
6740 size_t line_len_max,
6741 struct table_rule_list **rule_list,
6743 uint32_t *line_number,
6747 struct table_rule_list *list = NULL;
6750 uint32_t rule_id = 0, line_id = 0;
6753 /* Check input arguments */
6754 if ((file_name == NULL) ||
6755 (strlen(file_name) == 0) ||
6756 (line_len_max == 0) ||
6757 (rule_list == NULL) ||
6758 (n_rules == NULL) ||
6759 (line_number == NULL) ||
6762 goto cli_rule_file_process_free;
6765 /* Memory allocation */
6766 list = malloc(sizeof(struct table_rule_list));
6769 goto cli_rule_file_process_free;
6774 line = malloc(line_len_max + 1);
6777 goto cli_rule_file_process_free;
6781 f = fopen(file_name, "r");
6784 goto cli_rule_file_process_free;
6788 for (line_id = 1, rule_id = 0; ; line_id++) {
6789 char *tokens[CMD_MAX_TOKENS];
6790 struct table_rule *rule = NULL;
6791 uint32_t n_tokens, n_tokens_parsed, t0;
6793 /* Read next line from file. */
6794 if (fgets(line, line_len_max + 1, f) == NULL)
6798 if (is_comment(line))
6802 n_tokens = RTE_DIM(tokens);
6803 status = parse_tokenize_string(line, tokens, &n_tokens);
6806 goto cli_rule_file_process_free;
6814 /* Rule alloc and insert. */
6815 rule = calloc(1, sizeof(struct table_rule));
6818 goto cli_rule_file_process_free;
6821 TAILQ_INSERT_TAIL(list, rule, node);
6824 n_tokens_parsed = parse_match(tokens + t0,
6829 if (n_tokens_parsed == 0) {
6831 goto cli_rule_file_process_free;
6833 t0 += n_tokens_parsed;
6836 n_tokens_parsed = parse_table_action(tokens + t0,
6841 if (n_tokens_parsed == 0) {
6843 goto cli_rule_file_process_free;
6845 t0 += n_tokens_parsed;
6847 /* Line completed. */
6848 if (t0 < n_tokens) {
6850 goto cli_rule_file_process_free;
6853 /* Increment rule count */
6865 *line_number = line_id;
6868 cli_rule_file_process_free:
6869 if (rule_list != NULL)
6872 if (n_rules != NULL)
6875 if (line_number != NULL)
6876 *line_number = line_id;
6880 struct table_rule *rule;
6882 rule = TAILQ_FIRST(list);
6886 TAILQ_REMOVE(list, rule, node);