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 if (p->cipher_auth.cipher_iv.val)
3777 free(p->cipher_auth.cipher_iv.val);
3778 if (p->cipher_auth.cipher_iv_update.val)
3779 free(p->cipher_auth.cipher_iv_update.val);
3781 case RTE_CRYPTO_SYM_XFORM_AUTH:
3782 if (p->cipher_auth.auth_iv.val)
3783 free(p->cipher_auth.cipher_iv.val);
3784 if (p->cipher_auth.auth_iv_update.val)
3785 free(p->cipher_auth.cipher_iv_update.val);
3787 case RTE_CRYPTO_SYM_XFORM_AEAD:
3789 free(p->aead.iv.val);
3790 if (p->aead.aad.val)
3791 free(p->aead.aad.val);
3800 static struct rte_crypto_sym_xform *
3801 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3802 uint8_t *key, uint32_t max_key_len, char **tokens,
3803 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3805 struct rte_crypto_sym_xform *xform_cipher;
3809 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
3810 strcmp(tokens[3], "cipher_key") ||
3811 strcmp(tokens[5], "cipher_iv"))
3814 xform_cipher = calloc(1, sizeof(*xform_cipher));
3815 if (xform_cipher == NULL)
3818 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3819 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
3820 RTE_CRYPTO_CIPHER_OP_DECRYPT;
3823 status = rte_cryptodev_get_cipher_algo_enum(
3824 &xform_cipher->cipher.algo, tokens[2]);
3829 len = strlen(tokens[4]);
3830 if (len / 2 > max_key_len) {
3835 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
3839 xform_cipher->cipher.key.data = key;
3840 xform_cipher->cipher.key.length = (uint16_t)len;
3843 len = strlen(tokens[6]);
3845 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
3846 if (p->cipher_auth.cipher_iv.val == NULL)
3849 status = parse_hex_string(tokens[6],
3850 p->cipher_auth.cipher_iv.val,
3855 xform_cipher->cipher.iv.length = (uint16_t)len;
3856 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3857 p->cipher_auth.cipher_iv.length = (uint32_t)len;
3860 return xform_cipher;
3863 if (p->cipher_auth.cipher_iv.val) {
3864 free(p->cipher_auth.cipher_iv.val);
3865 p->cipher_auth.cipher_iv.val = NULL;
3873 static struct rte_crypto_sym_xform *
3874 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3875 uint8_t *key, uint32_t max_key_len, char **tokens,
3876 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3878 struct rte_crypto_sym_xform *xform_cipher;
3879 struct rte_crypto_sym_xform *xform_auth;
3883 if (n_tokens < 13 ||
3884 strcmp(tokens[7], "auth_algo") ||
3885 strcmp(tokens[9], "auth_key") ||
3886 strcmp(tokens[11], "digest_size"))
3889 xform_auth = calloc(1, sizeof(*xform_auth));
3890 if (xform_auth == NULL)
3893 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
3894 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
3895 RTE_CRYPTO_AUTH_OP_VERIFY;
3898 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
3904 len = strlen(tokens[10]);
3905 if (len / 2 > max_key_len) {
3910 status = parse_hex_string(tokens[10], key, (uint32_t *)&len);
3914 xform_auth->auth.key.data = key;
3915 xform_auth->auth.key.length = (uint16_t)len;
3917 key += xform_auth->auth.key.length;
3918 max_key_len -= xform_auth->auth.key.length;
3920 if (strcmp(tokens[11], "digest_size"))
3923 status = parser_read_uint16(&xform_auth->auth.digest_length,
3928 xform_cipher = parse_table_action_cipher(p, key, max_key_len, tokens,
3929 7, encrypt, used_n_tokens);
3930 if (xform_cipher == NULL)
3933 *used_n_tokens += 6;
3936 xform_cipher->next = xform_auth;
3937 return xform_cipher;
3939 xform_auth->next = xform_cipher;
3944 if (p->cipher_auth.auth_iv.val) {
3945 free(p->cipher_auth.auth_iv.val);
3946 p->cipher_auth.auth_iv.val = 0;
3954 static struct rte_crypto_sym_xform *
3955 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3956 uint8_t *key, uint32_t max_key_len, char **tokens,
3957 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3959 struct rte_crypto_sym_xform *xform_aead;
3963 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
3964 strcmp(tokens[3], "aead_key") ||
3965 strcmp(tokens[5], "aead_iv") ||
3966 strcmp(tokens[7], "aead_aad") ||
3967 strcmp(tokens[9], "digest_size"))
3970 xform_aead = calloc(1, sizeof(*xform_aead));
3971 if (xform_aead == NULL)
3974 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
3975 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
3976 RTE_CRYPTO_AEAD_OP_DECRYPT;
3979 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
3985 len = strlen(tokens[4]);
3986 if (len / 2 > max_key_len) {
3991 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
3995 xform_aead->aead.key.data = key;
3996 xform_aead->aead.key.length = (uint16_t)len;
3999 len = strlen(tokens[6]);
4000 p->aead.iv.val = calloc(1, len / 2 + 1);
4001 if (p->aead.iv.val == NULL)
4004 status = parse_hex_string(tokens[6], p->aead.iv.val,
4009 xform_aead->aead.iv.length = (uint16_t)len;
4010 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4011 p->aead.iv.length = (uint32_t)len;
4014 len = strlen(tokens[8]);
4015 p->aead.aad.val = calloc(1, len / 2 + 1);
4016 if (p->aead.aad.val == NULL)
4019 status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
4023 xform_aead->aead.aad_length = (uint16_t)len;
4024 p->aead.aad.length = (uint32_t)len;
4027 status = parser_read_uint16(&xform_aead->aead.digest_length,
4032 *used_n_tokens = 11;
4037 if (p->aead.iv.val) {
4038 free(p->aead.iv.val);
4039 p->aead.iv.val = NULL;
4041 if (p->aead.aad.val) {
4042 free(p->aead.aad.val);
4043 p->aead.aad.val = NULL;
4053 parse_table_action_sym_crypto(char **tokens,
4055 struct table_rule_action *a)
4057 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4058 struct rte_crypto_sym_xform *xform = NULL;
4059 uint8_t *key = a->sym_crypto_key;
4060 uint32_t max_key_len = SYM_CRYPTO_MAX_KEY_SIZE;
4061 uint32_t used_n_tokens;
4065 if ((n_tokens < 12) ||
4066 strcmp(tokens[0], "sym_crypto") ||
4067 strcmp(tokens[2], "type"))
4070 memset(p, 0, sizeof(*p));
4072 if (strcmp(tokens[1], "encrypt") == 0)
4077 status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4081 if (strcmp(tokens[3], "cipher") == 0) {
4085 xform = parse_table_action_cipher(p, key, max_key_len, tokens,
4086 n_tokens, encrypt, &used_n_tokens);
4087 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4091 xform = parse_table_action_cipher_auth(p, key, max_key_len,
4092 tokens, n_tokens, encrypt, &used_n_tokens);
4093 } else if (strcmp(tokens[3], "aead") == 0) {
4097 xform = parse_table_action_aead(p, key, max_key_len, tokens,
4098 n_tokens, encrypt, &used_n_tokens);
4106 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4107 parse_free_sym_crypto_param_data(p);
4111 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4113 return used_n_tokens + 5;
4117 parse_table_action_tag(char **tokens,
4119 struct table_rule_action *a)
4121 if ((n_tokens < 2) ||
4122 strcmp(tokens[0], "tag"))
4125 if (parser_read_uint32(&a->tag.tag, tokens[1]))
4128 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4133 parse_table_action_decap(char **tokens,
4135 struct table_rule_action *a)
4137 if ((n_tokens < 2) ||
4138 strcmp(tokens[0], "decap"))
4141 if (parser_read_uint16(&a->decap.n, tokens[1]))
4144 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4149 parse_table_action(char **tokens,
4153 struct table_rule_action *a)
4155 uint32_t n_tokens0 = n_tokens;
4157 memset(a, 0, sizeof(*a));
4159 if ((n_tokens < 2) ||
4160 strcmp(tokens[0], "action"))
4166 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4169 n = parse_table_action_fwd(tokens, n_tokens, a);
4171 snprintf(out, out_size, MSG_ARG_INVALID,
4180 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4183 n = parse_table_action_balance(tokens, n_tokens, a);
4185 snprintf(out, out_size, MSG_ARG_INVALID,
4194 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4197 n = parse_table_action_meter(tokens, n_tokens, a);
4199 snprintf(out, out_size, MSG_ARG_INVALID,
4208 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4211 n = parse_table_action_tm(tokens, n_tokens, a);
4213 snprintf(out, out_size, MSG_ARG_INVALID,
4222 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4225 n = parse_table_action_encap(tokens, n_tokens, a);
4227 snprintf(out, out_size, MSG_ARG_INVALID,
4236 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4239 n = parse_table_action_nat(tokens, n_tokens, a);
4241 snprintf(out, out_size, MSG_ARG_INVALID,
4250 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4253 n = parse_table_action_ttl(tokens, n_tokens, a);
4255 snprintf(out, out_size, MSG_ARG_INVALID,
4264 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4267 n = parse_table_action_stats(tokens, n_tokens, a);
4269 snprintf(out, out_size, MSG_ARG_INVALID,
4278 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4281 n = parse_table_action_time(tokens, n_tokens, a);
4283 snprintf(out, out_size, MSG_ARG_INVALID,
4292 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4295 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4297 snprintf(out, out_size, MSG_ARG_INVALID,
4298 "action sym_crypto");
4305 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4308 n = parse_table_action_tag(tokens, n_tokens, a);
4310 snprintf(out, out_size, MSG_ARG_INVALID,
4319 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4322 n = parse_table_action_decap(tokens, n_tokens, a);
4324 snprintf(out, out_size, MSG_ARG_INVALID,
4333 if (n_tokens0 - n_tokens == 1) {
4334 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4338 return n_tokens0 - n_tokens;
4342 static const char cmd_pipeline_table_rule_add_help[] =
4343 "pipeline <pipeline_name> table <table_id> rule add\n"
4345 " action <table_action>\n";
4348 cmd_pipeline_table_rule_add(char **tokens,
4353 struct table_rule_match m;
4354 struct table_rule_action a;
4355 char *pipeline_name;
4356 uint32_t table_id, t0, n_tokens_parsed;
4360 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4364 pipeline_name = tokens[1];
4366 if (strcmp(tokens[2], "table") != 0) {
4367 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4371 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4372 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4376 if (strcmp(tokens[4], "rule") != 0) {
4377 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4381 if (strcmp(tokens[5], "add") != 0) {
4382 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4389 n_tokens_parsed = parse_match(tokens + t0,
4394 if (n_tokens_parsed == 0)
4396 t0 += n_tokens_parsed;
4399 n_tokens_parsed = parse_table_action(tokens + t0,
4404 if (n_tokens_parsed == 0)
4406 t0 += n_tokens_parsed;
4408 if (t0 != n_tokens) {
4409 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4413 status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
4415 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4419 if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
4420 parse_free_sym_crypto_param_data(&a.sym_crypto);
4424 static const char cmd_pipeline_table_rule_add_default_help[] =
4425 "pipeline <pipeline_name> table <table_id> rule add\n"
4431 " | port <port_id>\n"
4433 " | table <table_id>\n";
4436 cmd_pipeline_table_rule_add_default(char **tokens,
4441 struct table_rule_action action;
4442 char *pipeline_name;
4446 if ((n_tokens != 11) && (n_tokens != 12)) {
4447 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4451 pipeline_name = tokens[1];
4453 if (strcmp(tokens[2], "table") != 0) {
4454 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4458 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4459 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4463 if (strcmp(tokens[4], "rule") != 0) {
4464 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4468 if (strcmp(tokens[5], "add") != 0) {
4469 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4473 if (strcmp(tokens[6], "match") != 0) {
4474 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4478 if (strcmp(tokens[7], "default") != 0) {
4479 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4483 if (strcmp(tokens[8], "action") != 0) {
4484 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4488 if (strcmp(tokens[9], "fwd") != 0) {
4489 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4493 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4495 if (strcmp(tokens[10], "drop") == 0) {
4496 if (n_tokens != 11) {
4497 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4501 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4502 } else if (strcmp(tokens[10], "port") == 0) {
4505 if (n_tokens != 12) {
4506 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4510 if (parser_read_uint32(&id, tokens[11]) != 0) {
4511 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4515 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4517 } else if (strcmp(tokens[10], "meta") == 0) {
4518 if (n_tokens != 11) {
4519 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4523 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4524 } else if (strcmp(tokens[10], "table") == 0) {
4527 if (n_tokens != 12) {
4528 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4532 if (parser_read_uint32(&id, tokens[11]) != 0) {
4533 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4537 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4540 snprintf(out, out_size, MSG_ARG_INVALID,
4541 "drop or port or meta or table");
4545 status = pipeline_table_rule_add_default(pipeline_name,
4549 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4555 static const char cmd_pipeline_table_rule_add_bulk_help[] =
4556 "pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\n"
4558 " File <file_name>:\n"
4559 " - line format: match <match> action <action>\n";
4562 cli_rule_file_process(const char *file_name,
4563 size_t line_len_max,
4564 struct table_rule_list **rule_list,
4566 uint32_t *line_number,
4571 cmd_pipeline_table_rule_add_bulk(char **tokens,
4576 struct table_rule_list *list = NULL;
4577 char *pipeline_name, *file_name;
4578 uint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;
4581 if (n_tokens != 8) {
4582 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4586 pipeline_name = tokens[1];
4588 if (strcmp(tokens[2], "table") != 0) {
4589 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4593 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4594 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4598 if (strcmp(tokens[4], "rule") != 0) {
4599 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4603 if (strcmp(tokens[5], "add") != 0) {
4604 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4608 if (strcmp(tokens[6], "bulk") != 0) {
4609 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4613 file_name = tokens[7];
4615 /* Load rules from file. */
4616 status = cli_rule_file_process(file_name,
4624 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4629 status = pipeline_table_rule_add_bulk(pipeline_name,
4633 &n_rules_not_added);
4635 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4639 snprintf(out, out_size, "Added %u rules out of %u.\n",
4645 static const char cmd_pipeline_table_rule_delete_help[] =
4646 "pipeline <pipeline_name> table <table_id> rule delete\n"
4650 cmd_pipeline_table_rule_delete(char **tokens,
4655 struct table_rule_match m;
4656 char *pipeline_name;
4657 uint32_t table_id, n_tokens_parsed, t0;
4661 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4665 pipeline_name = tokens[1];
4667 if (strcmp(tokens[2], "table") != 0) {
4668 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4672 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4673 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4677 if (strcmp(tokens[4], "rule") != 0) {
4678 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4682 if (strcmp(tokens[5], "delete") != 0) {
4683 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4690 n_tokens_parsed = parse_match(tokens + t0,
4695 if (n_tokens_parsed == 0)
4697 t0 += n_tokens_parsed;
4699 if (n_tokens != t0) {
4700 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4704 status = pipeline_table_rule_delete(pipeline_name,
4708 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4714 static const char cmd_pipeline_table_rule_delete_default_help[] =
4715 "pipeline <pipeline_name> table <table_id> rule delete\n"
4720 cmd_pipeline_table_rule_delete_default(char **tokens,
4725 char *pipeline_name;
4729 if (n_tokens != 8) {
4730 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4734 pipeline_name = tokens[1];
4736 if (strcmp(tokens[2], "table") != 0) {
4737 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4741 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4742 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4746 if (strcmp(tokens[4], "rule") != 0) {
4747 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4751 if (strcmp(tokens[5], "delete") != 0) {
4752 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4756 if (strcmp(tokens[6], "match") != 0) {
4757 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4761 if (strcmp(tokens[7], "default") != 0) {
4762 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4766 status = pipeline_table_rule_delete_default(pipeline_name,
4769 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4775 ether_addr_show(FILE *f, struct rte_ether_addr *addr)
4777 fprintf(f, RTE_ETHER_ADDR_PRT_FMT, RTE_ETHER_ADDR_BYTES(addr));
4781 ipv4_addr_show(FILE *f, uint32_t addr)
4783 fprintf(f, "%u.%u.%u.%u",
4785 (addr >> 16) & 0xFF,
4791 ipv6_addr_show(FILE *f, uint8_t *addr)
4793 fprintf(f, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
4794 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:",
4795 (uint32_t)addr[0], (uint32_t)addr[1],
4796 (uint32_t)addr[2], (uint32_t)addr[3],
4797 (uint32_t)addr[4], (uint32_t)addr[5],
4798 (uint32_t)addr[6], (uint32_t)addr[7],
4799 (uint32_t)addr[8], (uint32_t)addr[9],
4800 (uint32_t)addr[10], (uint32_t)addr[11],
4801 (uint32_t)addr[12], (uint32_t)addr[13],
4802 (uint32_t)addr[14], (uint32_t)addr[15]);
4806 policer_action_string(enum rte_table_action_policer action) {
4808 case RTE_TABLE_ACTION_POLICER_COLOR_GREEN: return "G";
4809 case RTE_TABLE_ACTION_POLICER_COLOR_YELLOW: return "Y";
4810 case RTE_TABLE_ACTION_POLICER_COLOR_RED: return "R";
4811 case RTE_TABLE_ACTION_POLICER_DROP: return "D";
4812 default: return "?";
4817 table_rule_show(const char *pipeline_name,
4819 const char *file_name)
4822 struct table *table;
4823 struct table_rule *rule;
4827 /* Check input params. */
4828 if ((pipeline_name == NULL) ||
4829 (file_name == NULL))
4832 p = pipeline_find(pipeline_name);
4834 (table_id >= p->n_tables))
4837 table = &p->table[table_id];
4840 f = fopen(file_name, "w");
4844 /* Write table rules to file. */
4845 TAILQ_FOREACH(rule, &table->rules, node) {
4846 struct table_rule_match *m = &rule->match;
4847 struct table_rule_action *a = &rule->action;
4849 fprintf(f, "match ");
4850 switch (m->match_type) {
4852 fprintf(f, "acl priority %u ",
4853 m->match.acl.priority);
4855 fprintf(f, m->match.acl.ip_version ? "ipv4 " : "ipv6 ");
4857 if (m->match.acl.ip_version)
4858 ipv4_addr_show(f, m->match.acl.ipv4.sa);
4860 ipv6_addr_show(f, m->match.acl.ipv6.sa);
4862 fprintf(f, "%u", m->match.acl.sa_depth);
4864 if (m->match.acl.ip_version)
4865 ipv4_addr_show(f, m->match.acl.ipv4.da);
4867 ipv6_addr_show(f, m->match.acl.ipv6.da);
4869 fprintf(f, "%u", m->match.acl.da_depth);
4871 fprintf(f, "%u %u %u %u %u ",
4872 (uint32_t)m->match.acl.sp0,
4873 (uint32_t)m->match.acl.sp1,
4874 (uint32_t)m->match.acl.dp0,
4875 (uint32_t)m->match.acl.dp1,
4876 (uint32_t)m->match.acl.proto);
4880 fprintf(f, "array %u ",
4881 m->match.array.pos);
4885 fprintf(f, "hash raw ");
4886 for (i = 0; i < table->params.match.hash.key_size; i++)
4887 fprintf(f, "%02x", m->match.hash.key[i]);
4894 fprintf(f, m->match.lpm.ip_version ? "ipv4 " : "ipv6 ");
4896 if (m->match.acl.ip_version)
4897 ipv4_addr_show(f, m->match.lpm.ipv4);
4899 ipv6_addr_show(f, m->match.lpm.ipv6);
4902 (uint32_t)m->match.lpm.depth);
4906 fprintf(f, "unknown ");
4909 fprintf(f, "action ");
4910 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
4912 switch (a->fwd.action) {
4913 case RTE_PIPELINE_ACTION_DROP:
4914 fprintf(f, "drop ");
4917 case RTE_PIPELINE_ACTION_PORT:
4918 fprintf(f, "port %u ", a->fwd.id);
4921 case RTE_PIPELINE_ACTION_PORT_META:
4922 fprintf(f, "meta ");
4925 case RTE_PIPELINE_ACTION_TABLE:
4927 fprintf(f, "table %u ", a->fwd.id);
4931 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
4932 fprintf(f, "balance ");
4933 for (i = 0; i < RTE_DIM(a->lb.out); i++)
4934 fprintf(f, "%u ", a->lb.out[i]);
4937 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
4939 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++)
4940 if (a->mtr.tc_mask & (1 << i)) {
4941 struct rte_table_action_mtr_tc_params *p =
4943 enum rte_table_action_policer ga =
4944 p->policer[RTE_COLOR_GREEN];
4945 enum rte_table_action_policer ya =
4946 p->policer[RTE_COLOR_YELLOW];
4947 enum rte_table_action_policer ra =
4948 p->policer[RTE_COLOR_RED];
4950 fprintf(f, "tc%u meter %u policer g %s y %s r %s ",
4952 a->mtr.mtr[i].meter_profile_id,
4953 policer_action_string(ga),
4954 policer_action_string(ya),
4955 policer_action_string(ra));
4959 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TM))
4960 fprintf(f, "tm subport %u pipe %u ",
4964 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
4965 fprintf(f, "encap ");
4966 switch (a->encap.type) {
4967 case RTE_TABLE_ACTION_ENCAP_ETHER:
4968 fprintf(f, "ether ");
4969 ether_addr_show(f, &a->encap.ether.ether.da);
4971 ether_addr_show(f, &a->encap.ether.ether.sa);
4975 case RTE_TABLE_ACTION_ENCAP_VLAN:
4976 fprintf(f, "vlan ");
4977 ether_addr_show(f, &a->encap.vlan.ether.da);
4979 ether_addr_show(f, &a->encap.vlan.ether.sa);
4980 fprintf(f, " pcp %u dei %u vid %u ",
4981 a->encap.vlan.vlan.pcp,
4982 a->encap.vlan.vlan.dei,
4983 a->encap.vlan.vlan.vid);
4986 case RTE_TABLE_ACTION_ENCAP_QINQ:
4987 fprintf(f, "qinq ");
4988 ether_addr_show(f, &a->encap.qinq.ether.da);
4990 ether_addr_show(f, &a->encap.qinq.ether.sa);
4991 fprintf(f, " pcp %u dei %u vid %u pcp %u dei %u vid %u ",
4992 a->encap.qinq.svlan.pcp,
4993 a->encap.qinq.svlan.dei,
4994 a->encap.qinq.svlan.vid,
4995 a->encap.qinq.cvlan.pcp,
4996 a->encap.qinq.cvlan.dei,
4997 a->encap.qinq.cvlan.vid);
5000 case RTE_TABLE_ACTION_ENCAP_MPLS:
5001 fprintf(f, "mpls %s ", (a->encap.mpls.unicast) ?
5002 "unicast " : "multicast ");
5003 ether_addr_show(f, &a->encap.mpls.ether.da);
5005 ether_addr_show(f, &a->encap.mpls.ether.sa);
5007 for (i = 0; i < a->encap.mpls.mpls_count; i++) {
5008 struct rte_table_action_mpls_hdr *l =
5009 &a->encap.mpls.mpls[i];
5011 fprintf(f, "label%u %u %u %u ",
5019 case RTE_TABLE_ACTION_ENCAP_PPPOE:
5020 fprintf(f, "pppoe ");
5021 ether_addr_show(f, &a->encap.pppoe.ether.da);
5023 ether_addr_show(f, &a->encap.pppoe.ether.sa);
5024 fprintf(f, " %u ", a->encap.pppoe.pppoe.session_id);
5027 case RTE_TABLE_ACTION_ENCAP_VXLAN:
5028 fprintf(f, "vxlan ether ");
5029 ether_addr_show(f, &a->encap.vxlan.ether.da);
5031 ether_addr_show(f, &a->encap.vxlan.ether.sa);
5032 if (table->ap->params.encap.vxlan.vlan)
5033 fprintf(f, " vlan pcp %u dei %u vid %u ",
5034 a->encap.vxlan.vlan.pcp,
5035 a->encap.vxlan.vlan.dei,
5036 a->encap.vxlan.vlan.vid);
5037 if (table->ap->params.encap.vxlan.ip_version) {
5038 fprintf(f, " ipv4 ");
5039 ipv4_addr_show(f, a->encap.vxlan.ipv4.sa);
5041 ipv4_addr_show(f, a->encap.vxlan.ipv4.da);
5042 fprintf(f, " %u %u ",
5043 (uint32_t)a->encap.vxlan.ipv4.dscp,
5044 (uint32_t)a->encap.vxlan.ipv4.ttl);
5046 fprintf(f, " ipv6 ");
5047 ipv6_addr_show(f, a->encap.vxlan.ipv6.sa);
5049 ipv6_addr_show(f, a->encap.vxlan.ipv6.da);
5050 fprintf(f, " %u %u %u ",
5051 a->encap.vxlan.ipv6.flow_label,
5052 (uint32_t)a->encap.vxlan.ipv6.dscp,
5053 (uint32_t)a->encap.vxlan.ipv6.hop_limit);
5054 fprintf(f, " udp %u %u vxlan %u ",
5055 a->encap.vxlan.udp.sp,
5056 a->encap.vxlan.udp.dp,
5057 a->encap.vxlan.vxlan.vni);
5062 fprintf(f, "unknown ");
5066 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
5067 fprintf(f, "nat %s ", (a->nat.ip_version) ? "ipv4 " : "ipv6 ");
5068 if (a->nat.ip_version)
5069 ipv4_addr_show(f, a->nat.addr.ipv4);
5071 ipv6_addr_show(f, a->nat.addr.ipv6);
5072 fprintf(f, " %u ", (uint32_t)(a->nat.port));
5075 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TTL))
5076 fprintf(f, "ttl %s ", (a->ttl.decrement) ? "dec" : "keep");
5078 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_STATS))
5079 fprintf(f, "stats ");
5081 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TIME))
5082 fprintf(f, "time ");
5084 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO))
5085 fprintf(f, "sym_crypto ");
5087 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TAG))
5088 fprintf(f, "tag %u ", a->tag.tag);
5090 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
5091 fprintf(f, "decap %u ", a->decap.n);
5097 /* Write table default rule to file. */
5098 if (table->rule_default) {
5099 struct table_rule_action *a = &table->rule_default->action;
5101 fprintf(f, "# match default action fwd ");
5103 switch (a->fwd.action) {
5104 case RTE_PIPELINE_ACTION_DROP:
5105 fprintf(f, "drop ");
5108 case RTE_PIPELINE_ACTION_PORT:
5109 fprintf(f, "port %u ", a->fwd.id);
5112 case RTE_PIPELINE_ACTION_PORT_META:
5113 fprintf(f, "meta ");
5116 case RTE_PIPELINE_ACTION_TABLE:
5118 fprintf(f, "table %u ", a->fwd.id);
5121 fprintf(f, "# match default action fwd drop ");
5131 static const char cmd_pipeline_table_rule_show_help[] =
5132 "pipeline <pipeline_name> table <table_id> rule show\n"
5133 " file <file_name>\n";
5136 cmd_pipeline_table_rule_show(char **tokens,
5141 char *file_name = NULL, *pipeline_name;
5145 if (n_tokens != 8) {
5146 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5150 pipeline_name = tokens[1];
5152 if (strcmp(tokens[2], "table") != 0) {
5153 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5157 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5158 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5162 if (strcmp(tokens[4], "rule") != 0) {
5163 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5167 if (strcmp(tokens[5], "show") != 0) {
5168 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "show");
5172 if (strcmp(tokens[6], "file") != 0) {
5173 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "file");
5177 file_name = tokens[7];
5179 status = table_rule_show(pipeline_name, table_id, file_name);
5181 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5186 static const char cmd_pipeline_table_rule_stats_read_help[] =
5187 "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n"
5191 cmd_pipeline_table_rule_stats_read(char **tokens,
5196 struct table_rule_match m;
5197 struct rte_table_action_stats_counters stats;
5198 char *pipeline_name;
5199 uint32_t table_id, n_tokens_parsed;
5200 int clear = 0, status;
5203 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5207 pipeline_name = tokens[1];
5209 if (strcmp(tokens[2], "table") != 0) {
5210 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5214 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5215 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5219 if (strcmp(tokens[4], "rule") != 0) {
5220 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5224 if (strcmp(tokens[5], "read") != 0) {
5225 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5229 if (strcmp(tokens[6], "stats") != 0) {
5230 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
5238 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5246 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5247 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5251 n_tokens_parsed = parse_match(tokens,
5256 if (n_tokens_parsed == 0)
5258 n_tokens -= n_tokens_parsed;
5259 tokens += n_tokens_parsed;
5263 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5267 /* Read table rule stats. */
5268 status = pipeline_table_rule_stats_read(pipeline_name,
5274 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5279 if (stats.n_packets_valid && stats.n_bytes_valid)
5280 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: %" PRIu64 "\n",
5284 if (stats.n_packets_valid && !stats.n_bytes_valid)
5285 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: N/A\n",
5288 if (!stats.n_packets_valid && stats.n_bytes_valid)
5289 snprintf(out, out_size, "Packets: N/A; Bytes: %" PRIu64 "\n",
5292 if (!stats.n_packets_valid && !stats.n_bytes_valid)
5293 snprintf(out, out_size, "Packets: N/A ; Bytes: N/A\n");
5296 static const char cmd_pipeline_table_meter_profile_add_help[] =
5297 "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
5298 " add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
5299 " | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
5302 cmd_pipeline_table_meter_profile_add(char **tokens,
5307 struct rte_table_action_meter_profile p;
5308 char *pipeline_name;
5309 uint32_t table_id, meter_profile_id;
5313 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5317 pipeline_name = tokens[1];
5319 if (strcmp(tokens[2], "table") != 0) {
5320 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5324 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5325 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5329 if (strcmp(tokens[4], "meter") != 0) {
5330 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5334 if (strcmp(tokens[5], "profile") != 0) {
5335 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5339 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5340 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5344 if (strcmp(tokens[7], "add") != 0) {
5345 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5349 if (strcmp(tokens[8], "srtcm") == 0) {
5350 if (n_tokens != 15) {
5351 snprintf(out, out_size, MSG_ARG_MISMATCH,
5356 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5358 if (strcmp(tokens[9], "cir") != 0) {
5359 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5363 if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5364 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5368 if (strcmp(tokens[11], "cbs") != 0) {
5369 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5373 if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5374 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5378 if (strcmp(tokens[13], "ebs") != 0) {
5379 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5383 if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5384 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5387 } else if (strcmp(tokens[8], "trtcm") == 0) {
5388 if (n_tokens != 17) {
5389 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5393 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5395 if (strcmp(tokens[9], "cir") != 0) {
5396 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5400 if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5401 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5405 if (strcmp(tokens[11], "pir") != 0) {
5406 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5410 if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5411 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5414 if (strcmp(tokens[13], "cbs") != 0) {
5415 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5419 if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5420 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5424 if (strcmp(tokens[15], "pbs") != 0) {
5425 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5429 if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5430 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5434 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5438 status = pipeline_table_mtr_profile_add(pipeline_name,
5443 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5449 static const char cmd_pipeline_table_meter_profile_delete_help[] =
5450 "pipeline <pipeline_name> table <table_id>\n"
5451 " meter profile <meter_profile_id> delete\n";
5454 cmd_pipeline_table_meter_profile_delete(char **tokens,
5459 char *pipeline_name;
5460 uint32_t table_id, meter_profile_id;
5463 if (n_tokens != 8) {
5464 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5468 pipeline_name = tokens[1];
5470 if (strcmp(tokens[2], "table") != 0) {
5471 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5475 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5476 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5480 if (strcmp(tokens[4], "meter") != 0) {
5481 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5485 if (strcmp(tokens[5], "profile") != 0) {
5486 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5490 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5491 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5495 if (strcmp(tokens[7], "delete") != 0) {
5496 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5500 status = pipeline_table_mtr_profile_delete(pipeline_name,
5504 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5510 static const char cmd_pipeline_table_rule_meter_read_help[] =
5511 "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n"
5515 cmd_pipeline_table_rule_meter_read(char **tokens,
5520 struct table_rule_match m;
5521 struct rte_table_action_mtr_counters stats;
5522 char *pipeline_name;
5523 uint32_t table_id, n_tokens_parsed;
5524 int clear = 0, status;
5527 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5531 pipeline_name = tokens[1];
5533 if (strcmp(tokens[2], "table") != 0) {
5534 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5538 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5539 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5543 if (strcmp(tokens[4], "rule") != 0) {
5544 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5548 if (strcmp(tokens[5], "read") != 0) {
5549 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5553 if (strcmp(tokens[6], "meter") != 0) {
5554 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5562 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5570 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5571 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5575 n_tokens_parsed = parse_match(tokens,
5580 if (n_tokens_parsed == 0)
5582 n_tokens -= n_tokens_parsed;
5583 tokens += n_tokens_parsed;
5587 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5591 /* Read table rule meter stats. */
5592 status = pipeline_table_rule_mtr_read(pipeline_name,
5598 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5606 static const char cmd_pipeline_table_dscp_help[] =
5607 "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
5609 " File <file_name>:\n"
5610 " - exactly 64 lines\n"
5611 " - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
5614 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5615 const char *file_name,
5616 uint32_t *line_number)
5621 /* Check input arguments */
5622 if ((dscp_table == NULL) ||
5623 (file_name == NULL) ||
5624 (line_number == NULL)) {
5630 /* Open input file */
5631 f = fopen(file_name, "r");
5638 for (dscp = 0, l = 1; ; l++) {
5641 enum rte_color color;
5642 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5644 if (fgets(line, sizeof(line), f) == NULL)
5647 if (is_comment(line))
5650 if (parse_tokenize_string(line, tokens, &n_tokens)) {
5659 if ((dscp >= RTE_DIM(dscp_table->entry)) ||
5660 (n_tokens != RTE_DIM(tokens)) ||
5661 parser_read_uint32(&tc_id, tokens[0]) ||
5662 (tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
5663 parser_read_uint32(&tc_queue_id, tokens[1]) ||
5664 (tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
5665 (strlen(tokens[2]) != 1)) {
5671 switch (tokens[2][0]) {
5674 color = RTE_COLOR_GREEN;
5679 color = RTE_COLOR_YELLOW;
5684 color = RTE_COLOR_RED;
5693 dscp_table->entry[dscp].tc_id = tc_id;
5694 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5695 dscp_table->entry[dscp].color = color;
5705 cmd_pipeline_table_dscp(char **tokens,
5710 struct rte_table_action_dscp_table dscp_table;
5711 char *pipeline_name, *file_name;
5712 uint32_t table_id, line_number;
5715 if (n_tokens != 6) {
5716 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5720 pipeline_name = tokens[1];
5722 if (strcmp(tokens[2], "table") != 0) {
5723 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5727 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5728 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5732 if (strcmp(tokens[4], "dscp") != 0) {
5733 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5737 file_name = tokens[5];
5739 status = load_dscp_table(&dscp_table, file_name, &line_number);
5741 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5745 status = pipeline_table_dscp_table_update(pipeline_name,
5750 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5756 static const char cmd_pipeline_table_rule_ttl_read_help[] =
5757 "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n"
5761 cmd_pipeline_table_rule_ttl_read(char **tokens,
5766 struct table_rule_match m;
5767 struct rte_table_action_ttl_counters stats;
5768 char *pipeline_name;
5769 uint32_t table_id, n_tokens_parsed;
5770 int clear = 0, status;
5773 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5777 pipeline_name = tokens[1];
5779 if (strcmp(tokens[2], "table") != 0) {
5780 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5784 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5785 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5789 if (strcmp(tokens[4], "rule") != 0) {
5790 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5794 if (strcmp(tokens[5], "read") != 0) {
5795 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5799 if (strcmp(tokens[6], "ttl") != 0) {
5800 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ttl");
5808 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5816 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5817 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5821 n_tokens_parsed = parse_match(tokens,
5826 if (n_tokens_parsed == 0)
5828 n_tokens -= n_tokens_parsed;
5829 tokens += n_tokens_parsed;
5833 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5837 /* Read table rule TTL stats. */
5838 status = pipeline_table_rule_ttl_read(pipeline_name,
5844 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5849 snprintf(out, out_size, "Packets: %" PRIu64 "\n",
5853 static const char cmd_pipeline_table_rule_time_read_help[] =
5854 "pipeline <pipeline_name> table <table_id> rule read time\n"
5858 cmd_pipeline_table_rule_time_read(char **tokens,
5863 struct table_rule_match m;
5864 char *pipeline_name;
5866 uint32_t table_id, n_tokens_parsed;
5870 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5874 pipeline_name = tokens[1];
5876 if (strcmp(tokens[2], "table") != 0) {
5877 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5881 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5882 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5886 if (strcmp(tokens[4], "rule") != 0) {
5887 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5891 if (strcmp(tokens[5], "read") != 0) {
5892 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5896 if (strcmp(tokens[6], "time") != 0) {
5897 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "time");
5905 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5906 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5910 n_tokens_parsed = parse_match(tokens,
5915 if (n_tokens_parsed == 0)
5917 n_tokens -= n_tokens_parsed;
5918 tokens += n_tokens_parsed;
5922 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5926 /* Read table rule timestamp. */
5927 status = pipeline_table_rule_time_read(pipeline_name,
5932 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5937 snprintf(out, out_size, "Packets: %" PRIu64 "\n", timestamp);
5940 static const char cmd_thread_pipeline_enable_help[] =
5941 "thread <thread_id> pipeline <pipeline_name> enable\n";
5944 cmd_thread_pipeline_enable(char **tokens,
5949 char *pipeline_name;
5953 if (n_tokens != 5) {
5954 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5958 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5959 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5963 if (strcmp(tokens[2], "pipeline") != 0) {
5964 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5968 pipeline_name = tokens[3];
5970 if (strcmp(tokens[4], "enable") != 0) {
5971 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5975 status = thread_pipeline_enable(thread_id, pipeline_name);
5977 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5983 static const char cmd_thread_pipeline_disable_help[] =
5984 "thread <thread_id> pipeline <pipeline_name> disable\n";
5987 cmd_thread_pipeline_disable(char **tokens,
5992 char *pipeline_name;
5996 if (n_tokens != 5) {
5997 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
6001 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
6002 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
6006 if (strcmp(tokens[2], "pipeline") != 0) {
6007 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
6011 pipeline_name = tokens[3];
6013 if (strcmp(tokens[4], "disable") != 0) {
6014 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
6018 status = thread_pipeline_disable(thread_id, pipeline_name);
6020 snprintf(out, out_size, MSG_CMD_FAIL,
6021 "thread pipeline disable");
6027 cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
6032 if (n_tokens == 0) {
6033 snprintf(out, out_size,
6034 "Type 'help <command>' for details on each command.\n\n"
6035 "List of commands:\n"
6039 "\ttmgr subport profile\n"
6040 "\ttmgr pipe profile\n"
6043 "\ttmgr subport pipe\n"
6046 "\tport in action profile\n"
6047 "\ttable action profile\n"
6049 "\tpipeline port in\n"
6050 "\tpipeline port out\n"
6051 "\tpipeline table\n"
6052 "\tpipeline port in table\n"
6053 "\tpipeline port in stats\n"
6054 "\tpipeline port in enable\n"
6055 "\tpipeline port in disable\n"
6056 "\tpipeline port out stats\n"
6057 "\tpipeline table stats\n"
6058 "\tpipeline table rule add\n"
6059 "\tpipeline table rule add default\n"
6060 "\tpipeline table rule add bulk\n"
6061 "\tpipeline table rule delete\n"
6062 "\tpipeline table rule delete default\n"
6063 "\tpipeline table rule show\n"
6064 "\tpipeline table rule stats read\n"
6065 "\tpipeline table meter profile add\n"
6066 "\tpipeline table meter profile delete\n"
6067 "\tpipeline table rule meter read\n"
6068 "\tpipeline table dscp\n"
6069 "\tpipeline table rule ttl read\n"
6070 "\tpipeline table rule time read\n"
6071 "\tthread pipeline enable\n"
6072 "\tthread pipeline disable\n\n");
6076 if (strcmp(tokens[0], "mempool") == 0) {
6077 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
6081 if (strcmp(tokens[0], "link") == 0) {
6082 snprintf(out, out_size, "\n%s\n", cmd_link_help);
6086 if (strcmp(tokens[0], "swq") == 0) {
6087 snprintf(out, out_size, "\n%s\n", cmd_swq_help);
6091 if (strcmp(tokens[0], "tmgr") == 0) {
6092 if (n_tokens == 1) {
6093 snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
6097 if ((n_tokens == 2) &&
6098 (strcmp(tokens[1], "subport")) == 0) {
6099 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
6103 if ((n_tokens == 3) &&
6104 (strcmp(tokens[1], "subport") == 0) &&
6105 (strcmp(tokens[2], "profile") == 0)) {
6106 snprintf(out, out_size, "\n%s\n",
6107 cmd_tmgr_subport_profile_help);
6111 if ((n_tokens == 3) &&
6112 (strcmp(tokens[1], "subport") == 0) &&
6113 (strcmp(tokens[2], "pipe") == 0)) {
6114 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
6118 if ((n_tokens == 3) &&
6119 (strcmp(tokens[1], "pipe") == 0) &&
6120 (strcmp(tokens[2], "profile") == 0)) {
6121 snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
6126 if (strcmp(tokens[0], "tap") == 0) {
6127 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
6131 if (strcmp(tokens[0], "kni") == 0) {
6132 snprintf(out, out_size, "\n%s\n", cmd_kni_help);
6136 if (strcmp(tokens[0], "cryptodev") == 0) {
6137 snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
6141 if ((n_tokens == 4) &&
6142 (strcmp(tokens[0], "port") == 0) &&
6143 (strcmp(tokens[1], "in") == 0) &&
6144 (strcmp(tokens[2], "action") == 0) &&
6145 (strcmp(tokens[3], "profile") == 0)) {
6146 snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
6150 if ((n_tokens == 3) &&
6151 (strcmp(tokens[0], "table") == 0) &&
6152 (strcmp(tokens[1], "action") == 0) &&
6153 (strcmp(tokens[2], "profile") == 0)) {
6154 snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
6158 if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
6159 snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
6163 if ((strcmp(tokens[0], "pipeline") == 0) &&
6164 (strcmp(tokens[1], "port") == 0)) {
6165 if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
6166 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
6170 if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
6171 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
6175 if ((n_tokens == 4) &&
6176 (strcmp(tokens[2], "in") == 0) &&
6177 (strcmp(tokens[3], "table") == 0)) {
6178 snprintf(out, out_size, "\n%s\n",
6179 cmd_pipeline_port_in_table_help);
6183 if ((n_tokens == 4) &&
6184 (strcmp(tokens[2], "in") == 0) &&
6185 (strcmp(tokens[3], "stats") == 0)) {
6186 snprintf(out, out_size, "\n%s\n",
6187 cmd_pipeline_port_in_stats_help);
6191 if ((n_tokens == 4) &&
6192 (strcmp(tokens[2], "in") == 0) &&
6193 (strcmp(tokens[3], "enable") == 0)) {
6194 snprintf(out, out_size, "\n%s\n",
6195 cmd_pipeline_port_in_enable_help);
6199 if ((n_tokens == 4) &&
6200 (strcmp(tokens[2], "in") == 0) &&
6201 (strcmp(tokens[3], "disable") == 0)) {
6202 snprintf(out, out_size, "\n%s\n",
6203 cmd_pipeline_port_in_disable_help);
6207 if ((n_tokens == 4) &&
6208 (strcmp(tokens[2], "out") == 0) &&
6209 (strcmp(tokens[3], "stats") == 0)) {
6210 snprintf(out, out_size, "\n%s\n",
6211 cmd_pipeline_port_out_stats_help);
6216 if ((strcmp(tokens[0], "pipeline") == 0) &&
6217 (strcmp(tokens[1], "table") == 0)) {
6218 if (n_tokens == 2) {
6219 snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
6223 if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
6224 snprintf(out, out_size, "\n%s\n",
6225 cmd_pipeline_table_stats_help);
6229 if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
6230 snprintf(out, out_size, "\n%s\n",
6231 cmd_pipeline_table_dscp_help);
6235 if ((n_tokens == 4) &&
6236 (strcmp(tokens[2], "rule") == 0) &&
6237 (strcmp(tokens[3], "add") == 0)) {
6238 snprintf(out, out_size, "\n%s\n",
6239 cmd_pipeline_table_rule_add_help);
6243 if ((n_tokens == 5) &&
6244 (strcmp(tokens[2], "rule") == 0) &&
6245 (strcmp(tokens[3], "add") == 0) &&
6246 (strcmp(tokens[4], "default") == 0)) {
6247 snprintf(out, out_size, "\n%s\n",
6248 cmd_pipeline_table_rule_add_default_help);
6252 if ((n_tokens == 5) &&
6253 (strcmp(tokens[2], "rule") == 0) &&
6254 (strcmp(tokens[3], "add") == 0) &&
6255 (strcmp(tokens[4], "bulk") == 0)) {
6256 snprintf(out, out_size, "\n%s\n",
6257 cmd_pipeline_table_rule_add_bulk_help);
6261 if ((n_tokens == 4) &&
6262 (strcmp(tokens[2], "rule") == 0) &&
6263 (strcmp(tokens[3], "delete") == 0)) {
6264 snprintf(out, out_size, "\n%s\n",
6265 cmd_pipeline_table_rule_delete_help);
6269 if ((n_tokens == 5) &&
6270 (strcmp(tokens[2], "rule") == 0) &&
6271 (strcmp(tokens[3], "delete") == 0) &&
6272 (strcmp(tokens[4], "default") == 0)) {
6273 snprintf(out, out_size, "\n%s\n",
6274 cmd_pipeline_table_rule_delete_default_help);
6278 if ((n_tokens == 4) &&
6279 (strcmp(tokens[2], "rule") == 0) &&
6280 (strcmp(tokens[3], "show") == 0)) {
6281 snprintf(out, out_size, "\n%s\n",
6282 cmd_pipeline_table_rule_show_help);
6286 if ((n_tokens == 5) &&
6287 (strcmp(tokens[2], "rule") == 0) &&
6288 (strcmp(tokens[3], "stats") == 0) &&
6289 (strcmp(tokens[4], "read") == 0)) {
6290 snprintf(out, out_size, "\n%s\n",
6291 cmd_pipeline_table_rule_stats_read_help);
6295 if ((n_tokens == 5) &&
6296 (strcmp(tokens[2], "meter") == 0) &&
6297 (strcmp(tokens[3], "profile") == 0) &&
6298 (strcmp(tokens[4], "add") == 0)) {
6299 snprintf(out, out_size, "\n%s\n",
6300 cmd_pipeline_table_meter_profile_add_help);
6304 if ((n_tokens == 5) &&
6305 (strcmp(tokens[2], "meter") == 0) &&
6306 (strcmp(tokens[3], "profile") == 0) &&
6307 (strcmp(tokens[4], "delete") == 0)) {
6308 snprintf(out, out_size, "\n%s\n",
6309 cmd_pipeline_table_meter_profile_delete_help);
6313 if ((n_tokens == 5) &&
6314 (strcmp(tokens[2], "rule") == 0) &&
6315 (strcmp(tokens[3], "meter") == 0) &&
6316 (strcmp(tokens[4], "read") == 0)) {
6317 snprintf(out, out_size, "\n%s\n",
6318 cmd_pipeline_table_rule_meter_read_help);
6322 if ((n_tokens == 5) &&
6323 (strcmp(tokens[2], "rule") == 0) &&
6324 (strcmp(tokens[3], "ttl") == 0) &&
6325 (strcmp(tokens[4], "read") == 0)) {
6326 snprintf(out, out_size, "\n%s\n",
6327 cmd_pipeline_table_rule_ttl_read_help);
6331 if ((n_tokens == 5) &&
6332 (strcmp(tokens[2], "rule") == 0) &&
6333 (strcmp(tokens[3], "time") == 0) &&
6334 (strcmp(tokens[4], "read") == 0)) {
6335 snprintf(out, out_size, "\n%s\n",
6336 cmd_pipeline_table_rule_time_read_help);
6341 if ((n_tokens == 3) &&
6342 (strcmp(tokens[0], "thread") == 0) &&
6343 (strcmp(tokens[1], "pipeline") == 0)) {
6344 if (strcmp(tokens[2], "enable") == 0) {
6345 snprintf(out, out_size, "\n%s\n",
6346 cmd_thread_pipeline_enable_help);
6350 if (strcmp(tokens[2], "disable") == 0) {
6351 snprintf(out, out_size, "\n%s\n",
6352 cmd_thread_pipeline_disable_help);
6357 snprintf(out, out_size, "Invalid command\n");
6361 cli_process(char *in, char *out, size_t out_size)
6363 char *tokens[CMD_MAX_TOKENS];
6364 uint32_t n_tokens = RTE_DIM(tokens);
6370 status = parse_tokenize_string(in, tokens, &n_tokens);
6372 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
6379 if (strcmp(tokens[0], "help") == 0) {
6380 cmd_help(tokens, n_tokens, out, out_size);
6384 if (strcmp(tokens[0], "mempool") == 0) {
6385 cmd_mempool(tokens, n_tokens, out, out_size);
6389 if (strcmp(tokens[0], "link") == 0) {
6390 if (strcmp(tokens[1], "show") == 0) {
6391 cmd_link_show(tokens, n_tokens, out, out_size);
6395 cmd_link(tokens, n_tokens, out, out_size);
6399 if (strcmp(tokens[0], "swq") == 0) {
6400 cmd_swq(tokens, n_tokens, out, out_size);
6404 if (strcmp(tokens[0], "tmgr") == 0) {
6405 if ((n_tokens >= 3) &&
6406 (strcmp(tokens[1], "subport") == 0) &&
6407 (strcmp(tokens[2], "profile") == 0)) {
6408 cmd_tmgr_subport_profile(tokens, n_tokens,
6413 if ((n_tokens >= 3) &&
6414 (strcmp(tokens[1], "pipe") == 0) &&
6415 (strcmp(tokens[2], "profile") == 0)) {
6416 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
6420 if ((n_tokens >= 5) &&
6421 (strcmp(tokens[2], "subport") == 0) &&
6422 (strcmp(tokens[4], "profile") == 0)) {
6423 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
6427 if ((n_tokens >= 5) &&
6428 (strcmp(tokens[2], "subport") == 0) &&
6429 (strcmp(tokens[4], "pipe") == 0)) {
6430 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
6434 cmd_tmgr(tokens, n_tokens, out, out_size);
6438 if (strcmp(tokens[0], "tap") == 0) {
6439 cmd_tap(tokens, n_tokens, out, out_size);
6443 if (strcmp(tokens[0], "kni") == 0) {
6444 cmd_kni(tokens, n_tokens, out, out_size);
6448 if (strcmp(tokens[0], "cryptodev") == 0) {
6449 cmd_cryptodev(tokens, n_tokens, out, out_size);
6453 if (strcmp(tokens[0], "port") == 0) {
6454 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
6458 if (strcmp(tokens[0], "table") == 0) {
6459 cmd_table_action_profile(tokens, n_tokens, out, out_size);
6463 if (strcmp(tokens[0], "pipeline") == 0) {
6464 if ((n_tokens >= 3) &&
6465 (strcmp(tokens[2], "period") == 0)) {
6466 cmd_pipeline(tokens, n_tokens, out, out_size);
6470 if ((n_tokens >= 5) &&
6471 (strcmp(tokens[2], "port") == 0) &&
6472 (strcmp(tokens[3], "in") == 0) &&
6473 (strcmp(tokens[4], "bsz") == 0)) {
6474 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
6478 if ((n_tokens >= 5) &&
6479 (strcmp(tokens[2], "port") == 0) &&
6480 (strcmp(tokens[3], "out") == 0) &&
6481 (strcmp(tokens[4], "bsz") == 0)) {
6482 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
6486 if ((n_tokens >= 4) &&
6487 (strcmp(tokens[2], "table") == 0) &&
6488 (strcmp(tokens[3], "match") == 0)) {
6489 cmd_pipeline_table(tokens, n_tokens, out, out_size);
6493 if ((n_tokens >= 6) &&
6494 (strcmp(tokens[2], "port") == 0) &&
6495 (strcmp(tokens[3], "in") == 0) &&
6496 (strcmp(tokens[5], "table") == 0)) {
6497 cmd_pipeline_port_in_table(tokens, n_tokens,
6502 if ((n_tokens >= 6) &&
6503 (strcmp(tokens[2], "port") == 0) &&
6504 (strcmp(tokens[3], "in") == 0) &&
6505 (strcmp(tokens[5], "stats") == 0)) {
6506 cmd_pipeline_port_in_stats(tokens, n_tokens,
6511 if ((n_tokens >= 6) &&
6512 (strcmp(tokens[2], "port") == 0) &&
6513 (strcmp(tokens[3], "in") == 0) &&
6514 (strcmp(tokens[5], "enable") == 0)) {
6515 cmd_pipeline_port_in_enable(tokens, n_tokens,
6520 if ((n_tokens >= 6) &&
6521 (strcmp(tokens[2], "port") == 0) &&
6522 (strcmp(tokens[3], "in") == 0) &&
6523 (strcmp(tokens[5], "disable") == 0)) {
6524 cmd_pipeline_port_in_disable(tokens, n_tokens,
6529 if ((n_tokens >= 6) &&
6530 (strcmp(tokens[2], "port") == 0) &&
6531 (strcmp(tokens[3], "out") == 0) &&
6532 (strcmp(tokens[5], "stats") == 0)) {
6533 cmd_pipeline_port_out_stats(tokens, n_tokens,
6538 if ((n_tokens >= 5) &&
6539 (strcmp(tokens[2], "table") == 0) &&
6540 (strcmp(tokens[4], "stats") == 0)) {
6541 cmd_pipeline_table_stats(tokens, n_tokens,
6546 if ((n_tokens >= 7) &&
6547 (strcmp(tokens[2], "table") == 0) &&
6548 (strcmp(tokens[4], "rule") == 0) &&
6549 (strcmp(tokens[5], "add") == 0) &&
6550 (strcmp(tokens[6], "match") == 0)) {
6551 if ((n_tokens >= 8) &&
6552 (strcmp(tokens[7], "default") == 0)) {
6553 cmd_pipeline_table_rule_add_default(tokens,
6554 n_tokens, out, out_size);
6558 cmd_pipeline_table_rule_add(tokens, n_tokens,
6563 if ((n_tokens >= 7) &&
6564 (strcmp(tokens[2], "table") == 0) &&
6565 (strcmp(tokens[4], "rule") == 0) &&
6566 (strcmp(tokens[5], "add") == 0) &&
6567 (strcmp(tokens[6], "bulk") == 0)) {
6568 cmd_pipeline_table_rule_add_bulk(tokens,
6569 n_tokens, out, out_size);
6573 if ((n_tokens >= 7) &&
6574 (strcmp(tokens[2], "table") == 0) &&
6575 (strcmp(tokens[4], "rule") == 0) &&
6576 (strcmp(tokens[5], "delete") == 0) &&
6577 (strcmp(tokens[6], "match") == 0)) {
6578 if ((n_tokens >= 8) &&
6579 (strcmp(tokens[7], "default") == 0)) {
6580 cmd_pipeline_table_rule_delete_default(tokens,
6581 n_tokens, out, out_size);
6585 cmd_pipeline_table_rule_delete(tokens, n_tokens,
6590 if ((n_tokens >= 6) &&
6591 (strcmp(tokens[2], "table") == 0) &&
6592 (strcmp(tokens[4], "rule") == 0) &&
6593 (strcmp(tokens[5], "show") == 0)) {
6594 cmd_pipeline_table_rule_show(tokens, n_tokens,
6599 if ((n_tokens >= 7) &&
6600 (strcmp(tokens[2], "table") == 0) &&
6601 (strcmp(tokens[4], "rule") == 0) &&
6602 (strcmp(tokens[5], "read") == 0) &&
6603 (strcmp(tokens[6], "stats") == 0)) {
6604 cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
6609 if ((n_tokens >= 8) &&
6610 (strcmp(tokens[2], "table") == 0) &&
6611 (strcmp(tokens[4], "meter") == 0) &&
6612 (strcmp(tokens[5], "profile") == 0) &&
6613 (strcmp(tokens[7], "add") == 0)) {
6614 cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
6619 if ((n_tokens >= 8) &&
6620 (strcmp(tokens[2], "table") == 0) &&
6621 (strcmp(tokens[4], "meter") == 0) &&
6622 (strcmp(tokens[5], "profile") == 0) &&
6623 (strcmp(tokens[7], "delete") == 0)) {
6624 cmd_pipeline_table_meter_profile_delete(tokens,
6625 n_tokens, out, out_size);
6629 if ((n_tokens >= 7) &&
6630 (strcmp(tokens[2], "table") == 0) &&
6631 (strcmp(tokens[4], "rule") == 0) &&
6632 (strcmp(tokens[5], "read") == 0) &&
6633 (strcmp(tokens[6], "meter") == 0)) {
6634 cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
6639 if ((n_tokens >= 5) &&
6640 (strcmp(tokens[2], "table") == 0) &&
6641 (strcmp(tokens[4], "dscp") == 0)) {
6642 cmd_pipeline_table_dscp(tokens, n_tokens,
6647 if ((n_tokens >= 7) &&
6648 (strcmp(tokens[2], "table") == 0) &&
6649 (strcmp(tokens[4], "rule") == 0) &&
6650 (strcmp(tokens[5], "read") == 0) &&
6651 (strcmp(tokens[6], "ttl") == 0)) {
6652 cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
6657 if ((n_tokens >= 7) &&
6658 (strcmp(tokens[2], "table") == 0) &&
6659 (strcmp(tokens[4], "rule") == 0) &&
6660 (strcmp(tokens[5], "read") == 0) &&
6661 (strcmp(tokens[6], "time") == 0)) {
6662 cmd_pipeline_table_rule_time_read(tokens, n_tokens,
6668 if (strcmp(tokens[0], "thread") == 0) {
6669 if ((n_tokens >= 5) &&
6670 (strcmp(tokens[4], "enable") == 0)) {
6671 cmd_thread_pipeline_enable(tokens, n_tokens,
6676 if ((n_tokens >= 5) &&
6677 (strcmp(tokens[4], "disable") == 0)) {
6678 cmd_thread_pipeline_disable(tokens, n_tokens,
6684 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
6688 cli_script_process(const char *file_name,
6689 size_t msg_in_len_max,
6690 size_t msg_out_len_max)
6692 char *msg_in = NULL, *msg_out = NULL;
6695 /* Check input arguments */
6696 if ((file_name == NULL) ||
6697 (strlen(file_name) == 0) ||
6698 (msg_in_len_max == 0) ||
6699 (msg_out_len_max == 0))
6702 msg_in = malloc(msg_in_len_max + 1);
6703 msg_out = malloc(msg_out_len_max + 1);
6704 if ((msg_in == NULL) ||
6705 (msg_out == NULL)) {
6711 /* Open input file */
6712 f = fopen(file_name, "r");
6721 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6724 printf("%s", msg_in);
6731 if (strlen(msg_out))
6732 printf("%s", msg_out);
6743 cli_rule_file_process(const char *file_name,
6744 size_t line_len_max,
6745 struct table_rule_list **rule_list,
6747 uint32_t *line_number,
6751 struct table_rule_list *list = NULL;
6754 uint32_t rule_id = 0, line_id = 0;
6757 /* Check input arguments */
6758 if ((file_name == NULL) ||
6759 (strlen(file_name) == 0) ||
6760 (line_len_max == 0) ||
6761 (rule_list == NULL) ||
6762 (n_rules == NULL) ||
6763 (line_number == NULL) ||
6766 goto cli_rule_file_process_free;
6769 /* Memory allocation */
6770 list = malloc(sizeof(struct table_rule_list));
6773 goto cli_rule_file_process_free;
6778 line = malloc(line_len_max + 1);
6781 goto cli_rule_file_process_free;
6785 f = fopen(file_name, "r");
6788 goto cli_rule_file_process_free;
6792 for (line_id = 1, rule_id = 0; ; line_id++) {
6793 char *tokens[CMD_MAX_TOKENS];
6794 struct table_rule *rule = NULL;
6795 uint32_t n_tokens, n_tokens_parsed, t0;
6797 /* Read next line from file. */
6798 if (fgets(line, line_len_max + 1, f) == NULL)
6802 if (is_comment(line))
6806 n_tokens = RTE_DIM(tokens);
6807 status = parse_tokenize_string(line, tokens, &n_tokens);
6810 goto cli_rule_file_process_free;
6818 /* Rule alloc and insert. */
6819 rule = calloc(1, sizeof(struct table_rule));
6822 goto cli_rule_file_process_free;
6825 TAILQ_INSERT_TAIL(list, rule, node);
6828 n_tokens_parsed = parse_match(tokens + t0,
6833 if (n_tokens_parsed == 0) {
6835 goto cli_rule_file_process_free;
6837 t0 += n_tokens_parsed;
6840 n_tokens_parsed = parse_table_action(tokens + t0,
6845 if (n_tokens_parsed == 0) {
6847 goto cli_rule_file_process_free;
6849 t0 += n_tokens_parsed;
6851 /* Line completed. */
6852 if (t0 < n_tokens) {
6854 goto cli_rule_file_process_free;
6857 /* Increment rule count */
6869 *line_number = line_id;
6872 cli_rule_file_process_free:
6873 if (rule_list != NULL)
6876 if (n_rules != NULL)
6879 if (line_number != NULL)
6880 *line_number = line_id;
6884 struct table_rule *rule;
6886 rule = TAILQ_FIRST(list);
6890 TAILQ_REMOVE(list, rule, node);