1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
10 #include <rte_common.h>
11 #include <rte_cycles.h>
12 #include <rte_ethdev.h>
16 #include "cryptodev.h"
27 #ifndef CMD_MAX_TOKENS
28 #define CMD_MAX_TOKENS 256
31 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
32 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
33 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
34 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
35 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
36 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
37 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
38 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
39 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
40 #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
41 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
46 if ((strlen(in) && index("!#%;", in[0])) ||
47 (strncmp(in, "//", 2) == 0) ||
48 (strncmp(in, "--", 2) == 0))
54 static const char cmd_mempool_help[] =
55 "mempool <mempool_name>\n"
56 " buffer <buffer_size>\n"
58 " cache <cache_size>\n"
62 cmd_mempool(char **tokens,
67 struct mempool_params p;
69 struct mempool *mempool;
72 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
78 if (strcmp(tokens[2], "buffer") != 0) {
79 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
83 if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
84 snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
88 if (strcmp(tokens[4], "pool") != 0) {
89 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
93 if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
94 snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
98 if (strcmp(tokens[6], "cache") != 0) {
99 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
103 if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
104 snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
108 if (strcmp(tokens[8], "cpu") != 0) {
109 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
113 if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
114 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
118 mempool = mempool_create(name, &p);
119 if (mempool == NULL) {
120 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
125 static const char cmd_link_help[] =
127 " dev <device_name> | port <port_id>\n"
128 " rxq <n_queues> <queue_size> <mempool_name>\n"
129 " txq <n_queues> <queue_size>\n"
130 " promiscuous on | off\n"
131 " [rss <qid_0> ... <qid_n>]\n";
134 cmd_link(char **tokens,
139 struct link_params p;
140 struct link_params_rss rss;
144 memset(&p, 0, sizeof(p));
146 if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
147 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
152 if (strcmp(tokens[2], "dev") == 0)
153 p.dev_name = tokens[3];
154 else if (strcmp(tokens[2], "port") == 0) {
157 if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
158 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
162 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
166 if (strcmp(tokens[4], "rxq") != 0) {
167 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
171 if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
172 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
175 if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
176 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
180 p.rx.mempool_name = tokens[7];
182 if (strcmp(tokens[8], "txq") != 0) {
183 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
187 if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
188 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
192 if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
193 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
197 if (strcmp(tokens[11], "promiscuous") != 0) {
198 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
202 if (strcmp(tokens[12], "on") == 0)
204 else if (strcmp(tokens[12], "off") == 0)
207 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
214 uint32_t queue_id, i;
216 if (strcmp(tokens[13], "rss") != 0) {
217 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
224 for (i = 14; i < n_tokens; i++) {
225 if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
226 snprintf(out, out_size, MSG_ARG_INVALID,
231 rss.queue_id[rss.n_queues] = queue_id;
236 link = link_create(name, &p);
238 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
243 /* Print the link stats and info */
245 print_link_info(struct link *link, char *out, size_t out_size)
247 struct rte_eth_stats stats;
248 struct rte_ether_addr mac_addr;
249 struct rte_eth_link eth_link;
253 memset(&stats, 0, sizeof(stats));
254 rte_eth_stats_get(link->port_id, &stats);
256 ret = rte_eth_macaddr_get(link->port_id, &mac_addr);
258 snprintf(out, out_size, "\n%s: MAC address get failed: %s",
259 link->name, rte_strerror(-ret));
263 ret = rte_eth_link_get(link->port_id, ð_link);
265 snprintf(out, out_size, "\n%s: link get failed: %s",
266 link->name, rte_strerror(-ret));
270 rte_eth_dev_get_mtu(link->port_id, &mtu);
272 snprintf(out, out_size,
274 "%s: flags=<%s> mtu %u\n"
275 "\tether %02X:%02X:%02X:%02X:%02X:%02X rxqueues %u txqueues %u\n"
276 "\tport# %u speed %s\n"
277 "\tRX packets %" PRIu64" bytes %" PRIu64"\n"
278 "\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n"
279 "\tTX packets %" PRIu64" bytes %" PRIu64"\n"
280 "\tTX errors %" PRIu64"\n",
282 eth_link.link_status == 0 ? "DOWN" : "UP",
284 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
285 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
286 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5],
290 rte_eth_link_speed_to_str(eth_link.link_speed),
302 * link show [<link_name>]
305 cmd_link_show(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
310 if (n_tokens != 2 && n_tokens != 3) {
311 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
316 link = link_next(NULL);
318 while (link != NULL) {
319 out_size = out_size - strlen(out);
320 out = &out[strlen(out)];
322 print_link_info(link, out, out_size);
323 link = link_next(link);
326 out_size = out_size - strlen(out);
327 out = &out[strlen(out)];
329 link_name = tokens[2];
330 link = link_find(link_name);
333 snprintf(out, out_size, MSG_ARG_INVALID,
334 "Link does not exist");
337 print_link_info(link, out, out_size);
341 static const char cmd_swq_help[] =
347 cmd_swq(char **tokens,
357 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
363 if (strcmp(tokens[2], "size") != 0) {
364 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
368 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
369 snprintf(out, out_size, MSG_ARG_INVALID, "size");
373 if (strcmp(tokens[4], "cpu") != 0) {
374 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
378 if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
379 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
383 swq = swq_create(name, &p);
385 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
390 static const char cmd_tmgr_subport_profile_help[] =
391 "tmgr subport profile\n"
392 " <tb_rate> <tb_size>\n"
393 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
394 " <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
395 " <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
399 cmd_tmgr_subport_profile(char **tokens,
404 struct rte_sched_subport_profile_params subport_profile;
407 if (n_tokens != 19) {
408 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
412 if (parser_read_uint64(&subport_profile.tb_rate, tokens[3]) != 0) {
413 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
417 if (parser_read_uint64(&subport_profile.tb_size, tokens[4]) != 0) {
418 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
422 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
423 if (parser_read_uint64(&subport_profile.tc_rate[i],
424 tokens[5 + i]) != 0) {
425 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
429 if (parser_read_uint64(&subport_profile.tc_period, tokens[18]) != 0) {
430 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
434 status = tmgr_subport_profile_add(&subport_profile);
436 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
441 static const char cmd_tmgr_pipe_profile_help[] =
442 "tmgr pipe profile\n"
443 " <tb_rate> <tb_size>\n"
444 " <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
445 " <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
446 " <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
449 " <wrr_weight0..3>\n";
452 cmd_tmgr_pipe_profile(char **tokens,
457 struct rte_sched_pipe_params p;
460 if (n_tokens != 24) {
461 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
465 if (parser_read_uint64(&p.tb_rate, tokens[3]) != 0) {
466 snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
470 if (parser_read_uint64(&p.tb_size, tokens[4]) != 0) {
471 snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
475 for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
476 if (parser_read_uint64(&p.tc_rate[i], tokens[5 + i]) != 0) {
477 snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
481 if (parser_read_uint64(&p.tc_period, tokens[18]) != 0) {
482 snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
486 if (parser_read_uint8(&p.tc_ov_weight, tokens[19]) != 0) {
487 snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
491 for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++)
492 if (parser_read_uint8(&p.wrr_weights[i], tokens[20 + i]) != 0) {
493 snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
497 status = tmgr_pipe_profile_add(&p);
499 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
504 static const char cmd_tmgr_help[] =
507 " spp <n_subports_per_port>\n"
508 " pps <n_pipes_per_subport>\n"
509 " fo <frame_overhead>\n"
514 cmd_tmgr(char **tokens,
519 struct tmgr_port_params p;
521 struct tmgr_port *tmgr_port;
523 if (n_tokens != 14) {
524 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
530 if (strcmp(tokens[2], "rate") != 0) {
531 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
535 if (parser_read_uint64(&p.rate, tokens[3]) != 0) {
536 snprintf(out, out_size, MSG_ARG_INVALID, "rate");
540 if (strcmp(tokens[4], "spp") != 0) {
541 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
545 if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
546 snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
550 if (strcmp(tokens[6], "pps") != 0) {
551 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
555 if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
556 snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
560 if (strcmp(tokens[8], "fo") != 0) {
561 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
565 if (parser_read_uint32(&p.frame_overhead, tokens[9]) != 0) {
566 snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
570 if (strcmp(tokens[10], "mtu") != 0) {
571 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
575 if (parser_read_uint32(&p.mtu, tokens[11]) != 0) {
576 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
580 if (strcmp(tokens[12], "cpu") != 0) {
581 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
585 if (parser_read_uint32(&p.cpu_id, tokens[13]) != 0) {
586 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
590 tmgr_port = tmgr_port_create(name, &p);
591 if (tmgr_port == NULL) {
592 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
597 static const char cmd_tmgr_subport_help[] =
598 "tmgr <tmgr_name> subport <subport_id>\n"
599 " profile <subport_profile_id>\n";
602 cmd_tmgr_subport(char **tokens,
607 uint32_t subport_id, subport_profile_id;
612 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
618 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
619 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
623 if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
624 snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
628 status = tmgr_subport_config(name, subport_id, subport_profile_id);
630 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
636 static const char cmd_tmgr_subport_pipe_help[] =
637 "tmgr <tmgr_name> subport <subport_id> pipe\n"
638 " from <pipe_id_first> to <pipe_id_last>\n"
639 " profile <pipe_profile_id>\n";
642 cmd_tmgr_subport_pipe(char **tokens,
647 uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
651 if (n_tokens != 11) {
652 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
658 if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
659 snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
663 if (strcmp(tokens[4], "pipe") != 0) {
664 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
668 if (strcmp(tokens[5], "from") != 0) {
669 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
673 if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
674 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
678 if (strcmp(tokens[7], "to") != 0) {
679 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
683 if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
684 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
688 if (strcmp(tokens[9], "profile") != 0) {
689 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
693 if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
694 snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
698 status = tmgr_pipe_config(name, subport_id, pipe_id_first,
699 pipe_id_last, pipe_profile_id);
701 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
707 static const char cmd_tap_help[] =
711 cmd_tap(char **tokens,
720 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
726 tap = tap_create(name);
728 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
733 static const char cmd_kni_help[] =
735 " link <link_name>\n"
736 " mempool <mempool_name>\n"
737 " [thread <thread_id>]\n";
740 cmd_kni(char **tokens,
749 memset(&p, 0, sizeof(p));
750 if ((n_tokens != 6) && (n_tokens != 8)) {
751 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
757 if (strcmp(tokens[2], "link") != 0) {
758 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
762 p.link_name = tokens[3];
764 if (strcmp(tokens[4], "mempool") != 0) {
765 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
769 p.mempool_name = tokens[5];
772 if (strcmp(tokens[6], "thread") != 0) {
773 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
777 if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
778 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
786 kni = kni_create(name, &p);
788 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
793 static const char cmd_cryptodev_help[] =
794 "cryptodev <cryptodev_name>\n"
795 " dev <device_name> | dev_id <device_id>\n"
796 " queue <n_queues> <queue_size>\n"
797 " max_sessions <n_sessions>";
800 cmd_cryptodev(char **tokens,
805 struct cryptodev_params params;
808 memset(¶ms, 0, sizeof(params));
810 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
816 if (strcmp(tokens[2], "dev") == 0)
817 params.dev_name = tokens[3];
818 else if (strcmp(tokens[2], "dev_id") == 0) {
819 if (parser_read_uint32(¶ms.dev_id, tokens[3]) < 0) {
820 snprintf(out, out_size, MSG_ARG_INVALID,
825 snprintf(out, out_size, MSG_ARG_INVALID,
830 if (strcmp(tokens[4], "queue")) {
831 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
836 if (parser_read_uint32(¶ms.n_queues, tokens[5]) < 0) {
837 snprintf(out, out_size, MSG_ARG_INVALID,
842 if (parser_read_uint32(¶ms.queue_size, tokens[6]) < 0) {
843 snprintf(out, out_size, MSG_ARG_INVALID,
848 if (strcmp(tokens[7], "max_sessions")) {
849 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
854 if (parser_read_uint32(¶ms.session_pool_size, tokens[8]) < 0) {
855 snprintf(out, out_size, MSG_ARG_INVALID,
860 if (cryptodev_create(name, ¶ms) == NULL) {
861 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
866 static const char cmd_port_in_action_profile_help[] =
867 "port in action profile <profile_name>\n"
868 " [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]\n"
869 " [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]\n";
872 cmd_port_in_action_profile(char **tokens,
877 struct port_in_action_profile_params p;
878 struct port_in_action_profile *ap;
882 memset(&p, 0, sizeof(p));
885 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
889 if (strcmp(tokens[1], "in") != 0) {
890 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
894 if (strcmp(tokens[2], "action") != 0) {
895 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
899 if (strcmp(tokens[3], "profile") != 0) {
900 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
908 if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
911 if (n_tokens < t0 + 10) {
912 snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
916 if (strcmp(tokens[t0 + 1], "match") == 0)
917 p.fltr.filter_on_match = 1;
918 else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
919 p.fltr.filter_on_match = 0;
921 snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
925 if (strcmp(tokens[t0 + 2], "offset") != 0) {
926 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
930 if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
931 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
935 if (strcmp(tokens[t0 + 4], "mask") != 0) {
936 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
940 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
941 if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
942 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
943 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
947 if (strcmp(tokens[t0 + 6], "key") != 0) {
948 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
952 size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
953 if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
954 (size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
955 snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
959 if (strcmp(tokens[t0 + 8], "port") != 0) {
960 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
964 if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
965 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
969 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
973 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
976 if (n_tokens < t0 + 22) {
977 snprintf(out, out_size, MSG_ARG_MISMATCH,
978 "port in action profile balance");
982 if (strcmp(tokens[t0 + 1], "offset") != 0) {
983 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
987 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
988 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
992 if (strcmp(tokens[t0 + 3], "mask") != 0) {
993 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
997 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
998 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
999 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1003 if (strcmp(tokens[t0 + 5], "port") != 0) {
1004 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1008 for (i = 0; i < 16; i++)
1009 if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
1010 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
1014 p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
1018 if (t0 < n_tokens) {
1019 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1023 ap = port_in_action_profile_create(name, &p);
1025 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1031 static const char cmd_table_action_profile_help[] =
1032 "table action profile <profile_name>\n"
1034 " offset <ip_offset>\n"
1036 " [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]\n"
1037 " [meter srtcm | trtcm\n"
1039 " stats none | pkts | bytes | both]\n"
1040 " [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]\n"
1041 " [encap ether | vlan | qinq | mpls | pppoe | qinq_pppoe \n"
1042 " vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]\n"
1044 " proto udp | tcp]\n"
1045 " [ttl drop | fwd\n"
1046 " stats none | pkts]\n"
1047 " [stats pkts | bytes | both]\n"
1049 " [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
1054 cmd_table_action_profile(char **tokens,
1059 struct table_action_profile_params p;
1060 struct table_action_profile *ap;
1064 memset(&p, 0, sizeof(p));
1067 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1071 if (strcmp(tokens[1], "action") != 0) {
1072 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
1076 if (strcmp(tokens[2], "profile") != 0) {
1077 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1083 if (strcmp(tokens[4], "ipv4") == 0)
1084 p.common.ip_version = 1;
1085 else if (strcmp(tokens[4], "ipv6") == 0)
1086 p.common.ip_version = 0;
1088 snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
1092 if (strcmp(tokens[5], "offset") != 0) {
1093 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1097 if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
1098 snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
1102 if (strcmp(tokens[7], "fwd") != 0) {
1103 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
1107 p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
1110 if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
1111 if (n_tokens < t0 + 7) {
1112 snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1116 if (strcmp(tokens[t0 + 1], "offset") != 0) {
1117 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1121 if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1122 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1126 if (strcmp(tokens[t0 + 3], "mask") != 0) {
1127 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1131 p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1132 if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1133 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1137 if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1138 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1142 if (parser_read_uint32(&p.lb.out_offset, tokens[t0 + 6]) != 0) {
1143 snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1147 p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1151 if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
1152 if (n_tokens < t0 + 6) {
1153 snprintf(out, out_size, MSG_ARG_MISMATCH,
1154 "table action profile meter");
1158 if (strcmp(tokens[t0 + 1], "srtcm") == 0)
1159 p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
1160 else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
1161 p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
1163 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1168 if (strcmp(tokens[t0 + 2], "tc") != 0) {
1169 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
1173 if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
1174 snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
1178 if (strcmp(tokens[t0 + 4], "stats") != 0) {
1179 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1183 if (strcmp(tokens[t0 + 5], "none") == 0) {
1184 p.mtr.n_packets_enabled = 0;
1185 p.mtr.n_bytes_enabled = 0;
1186 } else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
1187 p.mtr.n_packets_enabled = 1;
1188 p.mtr.n_bytes_enabled = 0;
1189 } else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
1190 p.mtr.n_packets_enabled = 0;
1191 p.mtr.n_bytes_enabled = 1;
1192 } else if (strcmp(tokens[t0 + 5], "both") == 0) {
1193 p.mtr.n_packets_enabled = 1;
1194 p.mtr.n_bytes_enabled = 1;
1196 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1197 "none or pkts or bytes or both");
1201 p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
1205 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
1206 if (n_tokens < t0 + 5) {
1207 snprintf(out, out_size, MSG_ARG_MISMATCH,
1208 "table action profile tm");
1212 if (strcmp(tokens[t0 + 1], "spp") != 0) {
1213 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
1217 if (parser_read_uint32(&p.tm.n_subports_per_port,
1218 tokens[t0 + 2]) != 0) {
1219 snprintf(out, out_size, MSG_ARG_INVALID,
1220 "n_subports_per_port");
1224 if (strcmp(tokens[t0 + 3], "pps") != 0) {
1225 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
1229 if (parser_read_uint32(&p.tm.n_pipes_per_subport,
1230 tokens[t0 + 4]) != 0) {
1231 snprintf(out, out_size, MSG_ARG_INVALID,
1232 "n_pipes_per_subport");
1236 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
1240 if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
1241 uint32_t n_extra_tokens = 0;
1243 if (n_tokens < t0 + 2) {
1244 snprintf(out, out_size, MSG_ARG_MISMATCH,
1245 "action profile encap");
1249 if (strcmp(tokens[t0 + 1], "ether") == 0)
1250 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
1251 else if (strcmp(tokens[t0 + 1], "vlan") == 0)
1252 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
1253 else if (strcmp(tokens[t0 + 1], "qinq") == 0)
1254 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
1255 else if (strcmp(tokens[t0 + 1], "mpls") == 0)
1256 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
1257 else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
1258 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
1259 else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
1260 if (n_tokens < t0 + 2 + 5) {
1261 snprintf(out, out_size, MSG_ARG_MISMATCH,
1262 "action profile encap vxlan");
1266 if (strcmp(tokens[t0 + 2], "offset") != 0) {
1267 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1272 if (parser_read_uint32(&p.encap.vxlan.data_offset,
1273 tokens[t0 + 2 + 1]) != 0) {
1274 snprintf(out, out_size, MSG_ARG_INVALID,
1275 "vxlan: ether_offset");
1279 if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
1280 p.encap.vxlan.ip_version = 1;
1281 else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
1282 p.encap.vxlan.ip_version = 0;
1284 snprintf(out, out_size, MSG_ARG_INVALID,
1285 "vxlan: ipv4 or ipv6");
1289 if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
1290 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1295 if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
1296 p.encap.vxlan.vlan = 1;
1297 else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
1298 p.encap.vxlan.vlan = 0;
1300 snprintf(out, out_size, MSG_ARG_INVALID,
1301 "vxlan: on or off");
1305 p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
1307 } else if (strcmp(tokens[t0 + 1], "qinq_pppoe") == 0)
1308 p.encap.encap_mask =
1309 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
1311 snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
1315 p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
1316 t0 += 2 + n_extra_tokens;
1319 if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
1320 if (n_tokens < t0 + 4) {
1321 snprintf(out, out_size, MSG_ARG_MISMATCH,
1322 "table action profile nat");
1326 if (strcmp(tokens[t0 + 1], "src") == 0)
1327 p.nat.source_nat = 1;
1328 else if (strcmp(tokens[t0 + 1], "dst") == 0)
1329 p.nat.source_nat = 0;
1331 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1336 if (strcmp(tokens[t0 + 2], "proto") != 0) {
1337 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
1341 if (strcmp(tokens[t0 + 3], "tcp") == 0)
1343 else if (strcmp(tokens[t0 + 3], "udp") == 0)
1346 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1351 p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
1355 if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
1356 if (n_tokens < t0 + 4) {
1357 snprintf(out, out_size, MSG_ARG_MISMATCH,
1358 "table action profile ttl");
1362 if (strcmp(tokens[t0 + 1], "drop") == 0)
1364 else if (strcmp(tokens[t0 + 1], "fwd") == 0)
1367 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1372 if (strcmp(tokens[t0 + 2], "stats") != 0) {
1373 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1377 if (strcmp(tokens[t0 + 3], "none") == 0)
1378 p.ttl.n_packets_enabled = 0;
1379 else if (strcmp(tokens[t0 + 3], "pkts") == 0)
1380 p.ttl.n_packets_enabled = 1;
1382 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1387 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
1391 if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
1392 if (n_tokens < t0 + 2) {
1393 snprintf(out, out_size, MSG_ARG_MISMATCH,
1394 "table action profile stats");
1398 if (strcmp(tokens[t0 + 1], "pkts") == 0) {
1399 p.stats.n_packets_enabled = 1;
1400 p.stats.n_bytes_enabled = 0;
1401 } else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
1402 p.stats.n_packets_enabled = 0;
1403 p.stats.n_bytes_enabled = 1;
1404 } else if (strcmp(tokens[t0 + 1], "both") == 0) {
1405 p.stats.n_packets_enabled = 1;
1406 p.stats.n_bytes_enabled = 1;
1408 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1409 "pkts or bytes or both");
1413 p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
1417 if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
1418 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
1422 if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
1423 struct cryptodev *cryptodev;
1425 if (n_tokens < t0 + 5 ||
1426 strcmp(tokens[t0 + 1], "dev") ||
1427 strcmp(tokens[t0 + 3], "offset")) {
1428 snprintf(out, out_size, MSG_ARG_MISMATCH,
1429 "table action profile sym_crypto");
1433 cryptodev = cryptodev_find(tokens[t0 + 2]);
1434 if (cryptodev == NULL) {
1435 snprintf(out, out_size, MSG_ARG_INVALID,
1436 "table action profile sym_crypto");
1440 p.sym_crypto.cryptodev_id = cryptodev->dev_id;
1442 if (parser_read_uint32(&p.sym_crypto.op_offset,
1443 tokens[t0 + 4]) != 0) {
1444 snprintf(out, out_size, MSG_ARG_INVALID,
1445 "table action profile sym_crypto");
1449 p.sym_crypto.mp_create = cryptodev->mp_create;
1450 p.sym_crypto.mp_init = cryptodev->mp_init;
1452 p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
1457 if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {
1458 p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
1462 if ((t0 < n_tokens) && (strcmp(tokens[t0], "decap") == 0)) {
1463 p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1467 if (t0 < n_tokens) {
1468 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1472 ap = table_action_profile_create(name, &p);
1474 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1479 static const char cmd_pipeline_help[] =
1480 "pipeline <pipeline_name>\n"
1481 " period <timer_period_ms>\n"
1482 " offset_port_id <offset_port_id>\n"
1486 cmd_pipeline(char **tokens,
1491 struct pipeline_params p;
1493 struct pipeline *pipeline;
1495 if (n_tokens != 8) {
1496 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1502 if (strcmp(tokens[2], "period") != 0) {
1503 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1507 if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1508 snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1512 if (strcmp(tokens[4], "offset_port_id") != 0) {
1513 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1517 if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1518 snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1522 if (strcmp(tokens[6], "cpu") != 0) {
1523 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1527 if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1528 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1532 pipeline = pipeline_create(name, &p);
1533 if (pipeline == NULL) {
1534 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1539 static const char cmd_pipeline_port_in_help[] =
1540 "pipeline <pipeline_name> port in\n"
1541 " bsz <burst_size>\n"
1542 " link <link_name> rxq <queue_id>\n"
1543 " | swq <swq_name>\n"
1544 " | tmgr <tmgr_name>\n"
1545 " | tap <tap_name> mempool <mempool_name> mtu <mtu>\n"
1546 " | kni <kni_name>\n"
1547 " | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>\n"
1548 " | cryptodev <cryptodev_name> rxq <queue_id>\n"
1549 " [action <port_in_action_profile_name>]\n"
1553 cmd_pipeline_port_in(char **tokens,
1558 struct port_in_params p;
1559 char *pipeline_name;
1561 int enabled, status;
1564 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1568 pipeline_name = tokens[1];
1570 if (strcmp(tokens[2], "port") != 0) {
1571 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1575 if (strcmp(tokens[3], "in") != 0) {
1576 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1580 if (strcmp(tokens[4], "bsz") != 0) {
1581 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1585 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1586 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1592 if (strcmp(tokens[t0], "link") == 0) {
1593 if (n_tokens < t0 + 4) {
1594 snprintf(out, out_size, MSG_ARG_MISMATCH,
1595 "pipeline port in link");
1599 p.type = PORT_IN_RXQ;
1601 p.dev_name = tokens[t0 + 1];
1603 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1604 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1608 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1609 snprintf(out, out_size, MSG_ARG_INVALID,
1614 } else if (strcmp(tokens[t0], "swq") == 0) {
1615 if (n_tokens < t0 + 2) {
1616 snprintf(out, out_size, MSG_ARG_MISMATCH,
1617 "pipeline port in swq");
1621 p.type = PORT_IN_SWQ;
1623 p.dev_name = tokens[t0 + 1];
1626 } else if (strcmp(tokens[t0], "tmgr") == 0) {
1627 if (n_tokens < t0 + 2) {
1628 snprintf(out, out_size, MSG_ARG_MISMATCH,
1629 "pipeline port in tmgr");
1633 p.type = PORT_IN_TMGR;
1635 p.dev_name = tokens[t0 + 1];
1638 } else if (strcmp(tokens[t0], "tap") == 0) {
1639 if (n_tokens < t0 + 6) {
1640 snprintf(out, out_size, MSG_ARG_MISMATCH,
1641 "pipeline port in tap");
1645 p.type = PORT_IN_TAP;
1647 p.dev_name = tokens[t0 + 1];
1649 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1650 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1655 p.tap.mempool_name = tokens[t0 + 3];
1657 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1658 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1663 if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1664 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1669 } else if (strcmp(tokens[t0], "kni") == 0) {
1670 if (n_tokens < t0 + 2) {
1671 snprintf(out, out_size, MSG_ARG_MISMATCH,
1672 "pipeline port in kni");
1676 p.type = PORT_IN_KNI;
1678 p.dev_name = tokens[t0 + 1];
1681 } else if (strcmp(tokens[t0], "source") == 0) {
1682 if (n_tokens < t0 + 6) {
1683 snprintf(out, out_size, MSG_ARG_MISMATCH,
1684 "pipeline port in source");
1688 p.type = PORT_IN_SOURCE;
1692 if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1693 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1698 p.source.mempool_name = tokens[t0 + 2];
1700 if (strcmp(tokens[t0 + 3], "file") != 0) {
1701 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1706 p.source.file_name = tokens[t0 + 4];
1708 if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1709 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1714 if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1715 snprintf(out, out_size, MSG_ARG_INVALID,
1721 } else if (strcmp(tokens[t0], "cryptodev") == 0) {
1722 if (n_tokens < t0 + 3) {
1723 snprintf(out, out_size, MSG_ARG_MISMATCH,
1724 "pipeline port in cryptodev");
1728 p.type = PORT_IN_CRYPTODEV;
1730 p.dev_name = tokens[t0 + 1];
1731 if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1732 snprintf(out, out_size, MSG_ARG_INVALID,
1737 p.cryptodev.arg_callback = NULL;
1738 p.cryptodev.f_callback = NULL;
1742 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1746 p.action_profile_name = NULL;
1747 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1748 if (n_tokens < t0 + 2) {
1749 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1753 p.action_profile_name = tokens[t0 + 1];
1759 if ((n_tokens > t0) &&
1760 (strcmp(tokens[t0], "disabled") == 0)) {
1766 if (n_tokens != t0) {
1767 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1771 status = pipeline_port_in_create(pipeline_name,
1774 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1779 static const char cmd_pipeline_port_out_help[] =
1780 "pipeline <pipeline_name> port out\n"
1781 " bsz <burst_size>\n"
1782 " link <link_name> txq <txq_id>\n"
1783 " | swq <swq_name>\n"
1784 " | tmgr <tmgr_name>\n"
1785 " | tap <tap_name>\n"
1786 " | kni <kni_name>\n"
1787 " | sink [file <file_name> pkts <max_n_pkts>]\n"
1788 " | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>\n";
1791 cmd_pipeline_port_out(char **tokens,
1796 struct port_out_params p;
1797 char *pipeline_name;
1800 memset(&p, 0, sizeof(p));
1803 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1807 pipeline_name = tokens[1];
1809 if (strcmp(tokens[2], "port") != 0) {
1810 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1814 if (strcmp(tokens[3], "out") != 0) {
1815 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1819 if (strcmp(tokens[4], "bsz") != 0) {
1820 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1824 if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1825 snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1829 if (strcmp(tokens[6], "link") == 0) {
1830 if (n_tokens != 10) {
1831 snprintf(out, out_size, MSG_ARG_MISMATCH,
1832 "pipeline port out link");
1836 p.type = PORT_OUT_TXQ;
1838 p.dev_name = tokens[7];
1840 if (strcmp(tokens[8], "txq") != 0) {
1841 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1845 if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1846 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1849 } else if (strcmp(tokens[6], "swq") == 0) {
1850 if (n_tokens != 8) {
1851 snprintf(out, out_size, MSG_ARG_MISMATCH,
1852 "pipeline port out swq");
1856 p.type = PORT_OUT_SWQ;
1858 p.dev_name = tokens[7];
1859 } else if (strcmp(tokens[6], "tmgr") == 0) {
1860 if (n_tokens != 8) {
1861 snprintf(out, out_size, MSG_ARG_MISMATCH,
1862 "pipeline port out tmgr");
1866 p.type = PORT_OUT_TMGR;
1868 p.dev_name = tokens[7];
1869 } else if (strcmp(tokens[6], "tap") == 0) {
1870 if (n_tokens != 8) {
1871 snprintf(out, out_size, MSG_ARG_MISMATCH,
1872 "pipeline port out tap");
1876 p.type = PORT_OUT_TAP;
1878 p.dev_name = tokens[7];
1879 } else if (strcmp(tokens[6], "kni") == 0) {
1880 if (n_tokens != 8) {
1881 snprintf(out, out_size, MSG_ARG_MISMATCH,
1882 "pipeline port out kni");
1886 p.type = PORT_OUT_KNI;
1888 p.dev_name = tokens[7];
1889 } else if (strcmp(tokens[6], "sink") == 0) {
1890 if ((n_tokens != 7) && (n_tokens != 11)) {
1891 snprintf(out, out_size, MSG_ARG_MISMATCH,
1892 "pipeline port out sink");
1896 p.type = PORT_OUT_SINK;
1900 if (n_tokens == 7) {
1901 p.sink.file_name = NULL;
1902 p.sink.max_n_pkts = 0;
1904 if (strcmp(tokens[7], "file") != 0) {
1905 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1910 p.sink.file_name = tokens[8];
1912 if (strcmp(tokens[9], "pkts") != 0) {
1913 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1917 if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1918 snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1923 } else if (strcmp(tokens[6], "cryptodev") == 0) {
1924 if (n_tokens != 12) {
1925 snprintf(out, out_size, MSG_ARG_MISMATCH,
1926 "pipeline port out cryptodev");
1930 p.type = PORT_OUT_CRYPTODEV;
1932 p.dev_name = tokens[7];
1934 if (strcmp(tokens[8], "txq")) {
1935 snprintf(out, out_size, MSG_ARG_MISMATCH,
1936 "pipeline port out cryptodev");
1940 if (parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
1942 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1946 if (strcmp(tokens[10], "offset")) {
1947 snprintf(out, out_size, MSG_ARG_MISMATCH,
1948 "pipeline port out cryptodev");
1952 if (parser_read_uint32(&p.cryptodev.op_offset, tokens[11])
1954 snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1958 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1962 status = pipeline_port_out_create(pipeline_name, &p);
1964 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1969 static const char cmd_pipeline_table_help[] =
1970 "pipeline <pipeline_name> table\n"
1974 " offset <ip_header_offset>\n"
1977 " offset <key_offset>\n"
1982 " mask <key_mask>\n"
1983 " offset <key_offset>\n"
1984 " buckets <n_buckets>\n"
1988 " offset <ip_header_offset>\n"
1991 " [action <table_action_profile_name>]\n";
1994 cmd_pipeline_table(char **tokens,
1999 uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
2000 struct table_params p;
2001 char *pipeline_name;
2006 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2010 pipeline_name = tokens[1];
2012 if (strcmp(tokens[2], "table") != 0) {
2013 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2017 if (strcmp(tokens[3], "match") != 0) {
2018 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2023 if (strcmp(tokens[t0], "acl") == 0) {
2024 if (n_tokens < t0 + 6) {
2025 snprintf(out, out_size, MSG_ARG_MISMATCH,
2026 "pipeline table acl");
2030 p.match_type = TABLE_ACL;
2032 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2033 p.match.acl.ip_version = 1;
2034 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2035 p.match.acl.ip_version = 0;
2037 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2042 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2043 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2047 if (parser_read_uint32(&p.match.acl.ip_header_offset,
2048 tokens[t0 + 3]) != 0) {
2049 snprintf(out, out_size, MSG_ARG_INVALID,
2050 "ip_header_offset");
2054 if (strcmp(tokens[t0 + 4], "size") != 0) {
2055 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2059 if (parser_read_uint32(&p.match.acl.n_rules,
2060 tokens[t0 + 5]) != 0) {
2061 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2066 } else if (strcmp(tokens[t0], "array") == 0) {
2067 if (n_tokens < t0 + 5) {
2068 snprintf(out, out_size, MSG_ARG_MISMATCH,
2069 "pipeline table array");
2073 p.match_type = TABLE_ARRAY;
2075 if (strcmp(tokens[t0 + 1], "offset") != 0) {
2076 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2080 if (parser_read_uint32(&p.match.array.key_offset,
2081 tokens[t0 + 2]) != 0) {
2082 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2086 if (strcmp(tokens[t0 + 3], "size") != 0) {
2087 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2091 if (parser_read_uint32(&p.match.array.n_keys,
2092 tokens[t0 + 4]) != 0) {
2093 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2098 } else if (strcmp(tokens[t0], "hash") == 0) {
2099 uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2101 if (n_tokens < t0 + 12) {
2102 snprintf(out, out_size, MSG_ARG_MISMATCH,
2103 "pipeline table hash");
2107 p.match_type = TABLE_HASH;
2109 if (strcmp(tokens[t0 + 1], "ext") == 0)
2110 p.match.hash.extendable_bucket = 1;
2111 else if (strcmp(tokens[t0 + 1], "lru") == 0)
2112 p.match.hash.extendable_bucket = 0;
2114 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2119 if (strcmp(tokens[t0 + 2], "key") != 0) {
2120 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2124 if ((parser_read_uint32(&p.match.hash.key_size,
2125 tokens[t0 + 3]) != 0) ||
2126 (p.match.hash.key_size == 0) ||
2127 (p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
2128 snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2132 if (strcmp(tokens[t0 + 4], "mask") != 0) {
2133 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2137 if ((parse_hex_string(tokens[t0 + 5],
2138 key_mask, &key_mask_size) != 0) ||
2139 (key_mask_size != p.match.hash.key_size)) {
2140 snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2143 p.match.hash.key_mask = key_mask;
2145 if (strcmp(tokens[t0 + 6], "offset") != 0) {
2146 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2150 if (parser_read_uint32(&p.match.hash.key_offset,
2151 tokens[t0 + 7]) != 0) {
2152 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2156 if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2157 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2161 if (parser_read_uint32(&p.match.hash.n_buckets,
2162 tokens[t0 + 9]) != 0) {
2163 snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2167 if (strcmp(tokens[t0 + 10], "size") != 0) {
2168 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2172 if (parser_read_uint32(&p.match.hash.n_keys,
2173 tokens[t0 + 11]) != 0) {
2174 snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2179 } else if (strcmp(tokens[t0], "lpm") == 0) {
2180 if (n_tokens < t0 + 6) {
2181 snprintf(out, out_size, MSG_ARG_MISMATCH,
2182 "pipeline table lpm");
2186 p.match_type = TABLE_LPM;
2188 if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2189 p.match.lpm.key_size = 4;
2190 else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2191 p.match.lpm.key_size = 16;
2193 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2198 if (strcmp(tokens[t0 + 2], "offset") != 0) {
2199 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2203 if (parser_read_uint32(&p.match.lpm.key_offset,
2204 tokens[t0 + 3]) != 0) {
2205 snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2209 if (strcmp(tokens[t0 + 4], "size") != 0) {
2210 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2214 if (parser_read_uint32(&p.match.lpm.n_rules,
2215 tokens[t0 + 5]) != 0) {
2216 snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2221 } else if (strcmp(tokens[t0], "stub") == 0) {
2222 p.match_type = TABLE_STUB;
2226 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2230 p.action_profile_name = NULL;
2231 if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
2232 if (n_tokens < t0 + 2) {
2233 snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2237 p.action_profile_name = tokens[t0 + 1];
2242 if (n_tokens > t0) {
2243 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2247 status = pipeline_table_create(pipeline_name, &p);
2249 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2254 static const char cmd_pipeline_port_in_table_help[] =
2255 "pipeline <pipeline_name> port in <port_id> table <table_id>\n";
2258 cmd_pipeline_port_in_table(char **tokens,
2263 char *pipeline_name;
2264 uint32_t port_id, table_id;
2267 if (n_tokens != 7) {
2268 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2272 pipeline_name = tokens[1];
2274 if (strcmp(tokens[2], "port") != 0) {
2275 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2279 if (strcmp(tokens[3], "in") != 0) {
2280 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2284 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2285 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2289 if (strcmp(tokens[5], "table") != 0) {
2290 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2294 if (parser_read_uint32(&table_id, tokens[6]) != 0) {
2295 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2299 status = pipeline_port_in_connect_to_table(pipeline_name,
2303 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2309 static const char cmd_pipeline_port_in_stats_help[] =
2310 "pipeline <pipeline_name> port in <port_id> stats read [clear]\n";
2312 #define MSG_PIPELINE_PORT_IN_STATS \
2313 "Pkts in: %" PRIu64 "\n" \
2314 "Pkts dropped by AH: %" PRIu64 "\n" \
2315 "Pkts dropped by other: %" PRIu64 "\n"
2318 cmd_pipeline_port_in_stats(char **tokens,
2323 struct rte_pipeline_port_in_stats stats;
2324 char *pipeline_name;
2328 if ((n_tokens != 7) && (n_tokens != 8)) {
2329 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2333 pipeline_name = tokens[1];
2335 if (strcmp(tokens[2], "port") != 0) {
2336 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2340 if (strcmp(tokens[3], "in") != 0) {
2341 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2345 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2346 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2350 if (strcmp(tokens[5], "stats") != 0) {
2351 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2355 if (strcmp(tokens[6], "read") != 0) {
2356 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2361 if (n_tokens == 8) {
2362 if (strcmp(tokens[7], "clear") != 0) {
2363 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2370 status = pipeline_port_in_stats_read(pipeline_name,
2375 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2379 snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
2380 stats.stats.n_pkts_in,
2381 stats.n_pkts_dropped_by_ah,
2382 stats.stats.n_pkts_drop);
2386 static const char cmd_pipeline_port_in_enable_help[] =
2387 "pipeline <pipeline_name> port in <port_id> enable\n";
2390 cmd_pipeline_port_in_enable(char **tokens,
2395 char *pipeline_name;
2399 if (n_tokens != 6) {
2400 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2404 pipeline_name = tokens[1];
2406 if (strcmp(tokens[2], "port") != 0) {
2407 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2411 if (strcmp(tokens[3], "in") != 0) {
2412 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2416 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2417 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2421 if (strcmp(tokens[5], "enable") != 0) {
2422 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2426 status = pipeline_port_in_enable(pipeline_name, port_id);
2428 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2434 static const char cmd_pipeline_port_in_disable_help[] =
2435 "pipeline <pipeline_name> port in <port_id> disable\n";
2438 cmd_pipeline_port_in_disable(char **tokens,
2443 char *pipeline_name;
2447 if (n_tokens != 6) {
2448 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2452 pipeline_name = tokens[1];
2454 if (strcmp(tokens[2], "port") != 0) {
2455 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2459 if (strcmp(tokens[3], "in") != 0) {
2460 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2464 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2465 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2469 if (strcmp(tokens[5], "disable") != 0) {
2470 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2474 status = pipeline_port_in_disable(pipeline_name, port_id);
2476 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2482 static const char cmd_pipeline_port_out_stats_help[] =
2483 "pipeline <pipeline_name> port out <port_id> stats read [clear]\n";
2485 #define MSG_PIPELINE_PORT_OUT_STATS \
2486 "Pkts in: %" PRIu64 "\n" \
2487 "Pkts dropped by AH: %" PRIu64 "\n" \
2488 "Pkts dropped by other: %" PRIu64 "\n"
2491 cmd_pipeline_port_out_stats(char **tokens,
2496 struct rte_pipeline_port_out_stats stats;
2497 char *pipeline_name;
2501 if ((n_tokens != 7) && (n_tokens != 8)) {
2502 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2506 pipeline_name = tokens[1];
2508 if (strcmp(tokens[2], "port") != 0) {
2509 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2513 if (strcmp(tokens[3], "out") != 0) {
2514 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
2518 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2519 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2523 if (strcmp(tokens[5], "stats") != 0) {
2524 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2528 if (strcmp(tokens[6], "read") != 0) {
2529 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2534 if (n_tokens == 8) {
2535 if (strcmp(tokens[7], "clear") != 0) {
2536 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2543 status = pipeline_port_out_stats_read(pipeline_name,
2548 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2552 snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
2553 stats.stats.n_pkts_in,
2554 stats.n_pkts_dropped_by_ah,
2555 stats.stats.n_pkts_drop);
2559 static const char cmd_pipeline_table_stats_help[] =
2560 "pipeline <pipeline_name> table <table_id> stats read [clear]\n";
2562 #define MSG_PIPELINE_TABLE_STATS \
2563 "Pkts in: %" PRIu64 "\n" \
2564 "Pkts in with lookup miss: %" PRIu64 "\n" \
2565 "Pkts in with lookup hit dropped by AH: %" PRIu64 "\n" \
2566 "Pkts in with lookup hit dropped by others: %" PRIu64 "\n" \
2567 "Pkts in with lookup miss dropped by AH: %" PRIu64 "\n" \
2568 "Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
2571 cmd_pipeline_table_stats(char **tokens,
2576 struct rte_pipeline_table_stats stats;
2577 char *pipeline_name;
2581 if ((n_tokens != 6) && (n_tokens != 7)) {
2582 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2586 pipeline_name = tokens[1];
2588 if (strcmp(tokens[2], "table") != 0) {
2589 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2593 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
2594 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2598 if (strcmp(tokens[4], "stats") != 0) {
2599 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2603 if (strcmp(tokens[5], "read") != 0) {
2604 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
2609 if (n_tokens == 7) {
2610 if (strcmp(tokens[6], "clear") != 0) {
2611 snprintf(out, out_size, MSG_ARG_INVALID, "clear");
2618 status = pipeline_table_stats_read(pipeline_name,
2623 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2627 snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
2628 stats.stats.n_pkts_in,
2629 stats.stats.n_pkts_lookup_miss,
2630 stats.n_pkts_dropped_by_lkp_hit_ah,
2631 stats.n_pkts_dropped_lkp_hit,
2632 stats.n_pkts_dropped_by_lkp_miss_ah,
2633 stats.n_pkts_dropped_lkp_miss);
2641 * priority <priority>
2642 * ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2643 * <sp0> <sp1> <dp0> <dp1> <proto>
2647 * | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2648 * | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2649 * | ipv4_addr <addr>
2650 * | ipv6_addr <addr>
2651 * | qinq <svlan> <cvlan>
2653 * ipv4 | ipv6 <addr> <depth>
2655 struct pkt_key_qinq {
2656 uint16_t ethertype_svlan;
2658 uint16_t ethertype_cvlan;
2662 struct pkt_key_ipv4_5tuple {
2663 uint8_t time_to_live;
2665 uint16_t hdr_checksum;
2672 struct pkt_key_ipv6_5tuple {
2673 uint16_t payload_length;
2682 struct pkt_key_ipv4_addr {
2686 struct pkt_key_ipv6_addr {
2691 parse_match(char **tokens,
2695 struct table_rule_match *m)
2697 memset(m, 0, sizeof(*m));
2702 if (strcmp(tokens[0], "match") != 0) {
2703 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2707 if (strcmp(tokens[1], "acl") == 0) {
2708 if (n_tokens < 14) {
2709 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2713 m->match_type = TABLE_ACL;
2715 if (strcmp(tokens[2], "priority") != 0) {
2716 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2720 if (parser_read_uint32(&m->match.acl.priority,
2722 snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2726 if (strcmp(tokens[4], "ipv4") == 0) {
2727 struct in_addr saddr, daddr;
2729 m->match.acl.ip_version = 1;
2731 if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2732 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2735 m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2737 if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2738 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2741 m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2742 } else if (strcmp(tokens[4], "ipv6") == 0) {
2743 struct in6_addr saddr, daddr;
2745 m->match.acl.ip_version = 0;
2747 if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2748 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2751 memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2753 if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2754 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2757 memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2759 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2764 if (parser_read_uint32(&m->match.acl.sa_depth,
2766 snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2770 if (parser_read_uint32(&m->match.acl.da_depth,
2772 snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2776 if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2777 snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2781 if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2782 snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2786 if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2787 snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2791 if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2792 snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2796 if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2797 snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2801 m->match.acl.proto_mask = 0xff;
2806 if (strcmp(tokens[1], "array") == 0) {
2808 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2812 m->match_type = TABLE_ARRAY;
2814 if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2815 snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2822 if (strcmp(tokens[1], "hash") == 0) {
2824 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2828 m->match_type = TABLE_HASH;
2830 if (strcmp(tokens[2], "raw") == 0) {
2831 uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2834 snprintf(out, out_size, MSG_ARG_MISMATCH,
2839 if (parse_hex_string(tokens[3],
2840 m->match.hash.key, &key_size) != 0) {
2841 snprintf(out, out_size, MSG_ARG_INVALID, "key");
2848 if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2849 struct pkt_key_ipv4_5tuple *ipv4 =
2850 (struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2851 struct in_addr saddr, daddr;
2856 snprintf(out, out_size, MSG_ARG_MISMATCH,
2861 if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2862 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2866 if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2867 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2871 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2872 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2876 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2877 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2881 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2882 snprintf(out, out_size, MSG_ARG_INVALID,
2887 ipv4->sa = saddr.s_addr;
2888 ipv4->da = daddr.s_addr;
2889 ipv4->sp = rte_cpu_to_be_16(sp);
2890 ipv4->dp = rte_cpu_to_be_16(dp);
2891 ipv4->proto = proto;
2894 } /* hash ipv4_5tuple */
2896 if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2897 struct pkt_key_ipv6_5tuple *ipv6 =
2898 (struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2899 struct in6_addr saddr, daddr;
2904 snprintf(out, out_size, MSG_ARG_MISMATCH,
2909 if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2910 snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2914 if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2915 snprintf(out, out_size, MSG_ARG_INVALID, "da");
2919 if (parser_read_uint16(&sp, tokens[5]) != 0) {
2920 snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2924 if (parser_read_uint16(&dp, tokens[6]) != 0) {
2925 snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2929 if (parser_read_uint8(&proto, tokens[7]) != 0) {
2930 snprintf(out, out_size, MSG_ARG_INVALID,
2935 memcpy(ipv6->sa, saddr.s6_addr, 16);
2936 memcpy(ipv6->da, daddr.s6_addr, 16);
2937 ipv6->sp = rte_cpu_to_be_16(sp);
2938 ipv6->dp = rte_cpu_to_be_16(dp);
2939 ipv6->proto = proto;
2942 } /* hash ipv6_5tuple */
2944 if (strcmp(tokens[2], "ipv4_addr") == 0) {
2945 struct pkt_key_ipv4_addr *ipv4_addr =
2946 (struct pkt_key_ipv4_addr *) m->match.hash.key;
2947 struct in_addr addr;
2950 snprintf(out, out_size, MSG_ARG_MISMATCH,
2955 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2956 snprintf(out, out_size, MSG_ARG_INVALID,
2961 ipv4_addr->addr = addr.s_addr;
2964 } /* hash ipv4_addr */
2966 if (strcmp(tokens[2], "ipv6_addr") == 0) {
2967 struct pkt_key_ipv6_addr *ipv6_addr =
2968 (struct pkt_key_ipv6_addr *) m->match.hash.key;
2969 struct in6_addr addr;
2972 snprintf(out, out_size, MSG_ARG_MISMATCH,
2977 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2978 snprintf(out, out_size, MSG_ARG_INVALID,
2983 memcpy(ipv6_addr->addr, addr.s6_addr, 16);
2986 } /* hash ipv6_5tuple */
2988 if (strcmp(tokens[2], "qinq") == 0) {
2989 struct pkt_key_qinq *qinq =
2990 (struct pkt_key_qinq *) m->match.hash.key;
2991 uint16_t svlan, cvlan;
2994 snprintf(out, out_size, MSG_ARG_MISMATCH,
2999 if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
3001 snprintf(out, out_size, MSG_ARG_INVALID,
3006 if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3008 snprintf(out, out_size, MSG_ARG_INVALID,
3013 qinq->svlan = rte_cpu_to_be_16(svlan);
3014 qinq->cvlan = rte_cpu_to_be_16(cvlan);
3019 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3023 if (strcmp(tokens[1], "lpm") == 0) {
3025 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3029 m->match_type = TABLE_LPM;
3031 if (strcmp(tokens[2], "ipv4") == 0) {
3032 struct in_addr addr;
3034 m->match.lpm.ip_version = 1;
3036 if (parse_ipv4_addr(tokens[3], &addr) != 0) {
3037 snprintf(out, out_size, MSG_ARG_INVALID,
3042 m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3043 } else if (strcmp(tokens[2], "ipv6") == 0) {
3044 struct in6_addr addr;
3046 m->match.lpm.ip_version = 0;
3048 if (parse_ipv6_addr(tokens[3], &addr) != 0) {
3049 snprintf(out, out_size, MSG_ARG_INVALID,
3054 memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3056 snprintf(out, out_size, MSG_ARG_MISMATCH,
3061 if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3062 snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3069 snprintf(out, out_size, MSG_ARG_MISMATCH,
3070 "acl or array or hash or lpm");
3082 * | table <table_id>
3083 * [balance <out0> ... <out7>]
3085 * tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3086 * [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3087 * tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3088 * tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3089 * [tm subport <subport_id> pipe <pipe_id>]
3092 * | vlan <da> <sa> <pcp> <dei> <vid>
3093 * | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
3094 * | qinq_pppoe <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid> <session_id>
3095 * | mpls unicast | multicast
3097 * label0 <label> <tc> <ttl>
3098 * [label1 <label> <tc> <ttl>
3099 * [label2 <label> <tc> <ttl>
3100 * [label3 <label> <tc> <ttl>]]]
3101 * | pppoe <da> <sa> <session_id>
3102 * | vxlan ether <da> <sa>
3103 * [vlan <pcp> <dei> <vid>]
3104 * ipv4 <sa> <da> <dscp> <ttl>
3105 * | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
3108 * [nat ipv4 | ipv6 <addr> <port>]
3116 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3118 * cipher_algo <algo> cipher_key <key> cipher_iv <iv>
3119 * auth_algo <algo> auth_key <key> digest_size <size>
3121 * aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
3122 * digest_size <size>
3123 * data_offset <data_offset>]
3128 * <pa> ::= g | y | r | drop
3131 parse_table_action_fwd(char **tokens,
3133 struct table_rule_action *a)
3135 if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
3141 if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3142 a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3143 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3147 if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3150 if ((n_tokens < 2) ||
3151 parser_read_uint32(&id, tokens[1]))
3154 a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3156 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3160 if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3161 a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3162 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3166 if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3169 if ((n_tokens < 2) ||
3170 parser_read_uint32(&id, tokens[1]))
3173 a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3175 a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3183 parse_table_action_balance(char **tokens,
3185 struct table_rule_action *a)
3189 if ((n_tokens == 0) || (strcmp(tokens[0], "balance") != 0))
3195 if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3198 for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3199 if (parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3202 a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3203 return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3208 parse_policer_action(char *token, enum rte_table_action_policer *a)
3210 if (strcmp(token, "g") == 0) {
3211 *a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3215 if (strcmp(token, "y") == 0) {
3216 *a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3220 if (strcmp(token, "r") == 0) {
3221 *a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3225 if (strcmp(token, "drop") == 0) {
3226 *a = RTE_TABLE_ACTION_POLICER_DROP;
3234 parse_table_action_meter_tc(char **tokens,
3236 struct rte_table_action_mtr_tc_params *mtr)
3238 if ((n_tokens < 9) ||
3239 strcmp(tokens[0], "meter") ||
3240 parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3241 strcmp(tokens[2], "policer") ||
3242 strcmp(tokens[3], "g") ||
3243 parse_policer_action(tokens[4], &mtr->policer[RTE_COLOR_GREEN]) ||
3244 strcmp(tokens[5], "y") ||
3245 parse_policer_action(tokens[6], &mtr->policer[RTE_COLOR_YELLOW]) ||
3246 strcmp(tokens[7], "r") ||
3247 parse_policer_action(tokens[8], &mtr->policer[RTE_COLOR_RED]))
3254 parse_table_action_meter(char **tokens,
3256 struct table_rule_action *a)
3258 if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
3264 if ((n_tokens < 10) ||
3265 strcmp(tokens[0], "tc0") ||
3266 (parse_table_action_meter_tc(tokens + 1,
3268 &a->mtr.mtr[0]) == 0))
3274 if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
3276 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3280 if ((n_tokens < 30) ||
3281 (parse_table_action_meter_tc(tokens + 1,
3282 n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3283 strcmp(tokens[10], "tc2") ||
3284 (parse_table_action_meter_tc(tokens + 11,
3285 n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3286 strcmp(tokens[20], "tc3") ||
3287 (parse_table_action_meter_tc(tokens + 21,
3288 n_tokens - 21, &a->mtr.mtr[3]) == 0))
3291 a->mtr.tc_mask = 0xF;
3292 a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3293 return 1 + 10 + 3 * 10;
3297 parse_table_action_tm(char **tokens,
3299 struct table_rule_action *a)
3301 uint32_t subport_id, pipe_id;
3303 if ((n_tokens < 5) ||
3304 strcmp(tokens[0], "tm") ||
3305 strcmp(tokens[1], "subport") ||
3306 parser_read_uint32(&subport_id, tokens[2]) ||
3307 strcmp(tokens[3], "pipe") ||
3308 parser_read_uint32(&pipe_id, tokens[4]))
3311 a->tm.subport_id = subport_id;
3312 a->tm.pipe_id = pipe_id;
3313 a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3318 parse_table_action_encap(char **tokens,
3320 struct table_rule_action *a)
3322 if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
3329 if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3330 if ((n_tokens < 3) ||
3331 parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3332 parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3335 a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3336 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3341 if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3342 uint32_t pcp, dei, vid;
3344 if ((n_tokens < 6) ||
3345 parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3346 parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3347 parser_read_uint32(&pcp, tokens[3]) ||
3349 parser_read_uint32(&dei, tokens[4]) ||
3351 parser_read_uint32(&vid, tokens[5]) ||
3355 a->encap.vlan.vlan.pcp = pcp & 0x7;
3356 a->encap.vlan.vlan.dei = dei & 0x1;
3357 a->encap.vlan.vlan.vid = vid & 0xFFF;
3358 a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3359 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3364 if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3365 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3366 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3368 if ((n_tokens < 9) ||
3369 parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3370 parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3371 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3372 (svlan_pcp > 0x7) ||
3373 parser_read_uint32(&svlan_dei, tokens[4]) ||
3374 (svlan_dei > 0x1) ||
3375 parser_read_uint32(&svlan_vid, tokens[5]) ||
3376 (svlan_vid > 0xFFF) ||
3377 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3378 (cvlan_pcp > 0x7) ||
3379 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3380 (cvlan_dei > 0x1) ||
3381 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3382 (cvlan_vid > 0xFFF))
3385 a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3386 a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3387 a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3388 a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3389 a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3390 a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3391 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3392 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3397 if (n_tokens && (strcmp(tokens[0], "qinq_pppoe") == 0)) {
3398 uint32_t svlan_pcp, svlan_dei, svlan_vid;
3399 uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3401 if ((n_tokens < 10) ||
3402 parse_mac_addr(tokens[1],
3403 &a->encap.qinq_pppoe.ether.da) ||
3404 parse_mac_addr(tokens[2],
3405 &a->encap.qinq_pppoe.ether.sa) ||
3406 parser_read_uint32(&svlan_pcp, tokens[3]) ||
3407 (svlan_pcp > 0x7) ||
3408 parser_read_uint32(&svlan_dei, tokens[4]) ||
3409 (svlan_dei > 0x1) ||
3410 parser_read_uint32(&svlan_vid, tokens[5]) ||
3411 (svlan_vid > 0xFFF) ||
3412 parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3413 (cvlan_pcp > 0x7) ||
3414 parser_read_uint32(&cvlan_dei, tokens[7]) ||
3415 (cvlan_dei > 0x1) ||
3416 parser_read_uint32(&cvlan_vid, tokens[8]) ||
3417 (cvlan_vid > 0xFFF) ||
3418 parser_read_uint16(&a->encap.qinq_pppoe.pppoe.session_id,
3422 a->encap.qinq_pppoe.svlan.pcp = svlan_pcp & 0x7;
3423 a->encap.qinq_pppoe.svlan.dei = svlan_dei & 0x1;
3424 a->encap.qinq_pppoe.svlan.vid = svlan_vid & 0xFFF;
3425 a->encap.qinq_pppoe.cvlan.pcp = cvlan_pcp & 0x7;
3426 a->encap.qinq_pppoe.cvlan.dei = cvlan_dei & 0x1;
3427 a->encap.qinq_pppoe.cvlan.vid = cvlan_vid & 0xFFF;
3428 a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
3429 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3435 if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3436 uint32_t label, tc, ttl;
3441 if (strcmp(tokens[1], "unicast") == 0)
3442 a->encap.mpls.unicast = 1;
3443 else if (strcmp(tokens[1], "multicast") == 0)
3444 a->encap.mpls.unicast = 0;
3448 if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3449 parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3450 strcmp(tokens[4], "label0") ||
3451 parser_read_uint32(&label, tokens[5]) ||
3452 (label > 0xFFFFF) ||
3453 parser_read_uint32(&tc, tokens[6]) ||
3455 parser_read_uint32(&ttl, tokens[7]) ||
3459 a->encap.mpls.mpls[0].label = label;
3460 a->encap.mpls.mpls[0].tc = tc;
3461 a->encap.mpls.mpls[0].ttl = ttl;
3466 if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3467 a->encap.mpls.mpls_count = 1;
3468 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3469 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3473 if ((n_tokens < 4) ||
3474 parser_read_uint32(&label, tokens[1]) ||
3475 (label > 0xFFFFF) ||
3476 parser_read_uint32(&tc, tokens[2]) ||
3478 parser_read_uint32(&ttl, tokens[3]) ||
3482 a->encap.mpls.mpls[1].label = label;
3483 a->encap.mpls.mpls[1].tc = tc;
3484 a->encap.mpls.mpls[1].ttl = ttl;
3489 if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3490 a->encap.mpls.mpls_count = 2;
3491 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3492 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3496 if ((n_tokens < 4) ||
3497 parser_read_uint32(&label, tokens[1]) ||
3498 (label > 0xFFFFF) ||
3499 parser_read_uint32(&tc, tokens[2]) ||
3501 parser_read_uint32(&ttl, tokens[3]) ||
3505 a->encap.mpls.mpls[2].label = label;
3506 a->encap.mpls.mpls[2].tc = tc;
3507 a->encap.mpls.mpls[2].ttl = ttl;
3512 if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3513 a->encap.mpls.mpls_count = 3;
3514 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3515 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3516 return 1 + 8 + 4 + 4;
3519 if ((n_tokens < 4) ||
3520 parser_read_uint32(&label, tokens[1]) ||
3521 (label > 0xFFFFF) ||
3522 parser_read_uint32(&tc, tokens[2]) ||
3524 parser_read_uint32(&ttl, tokens[3]) ||
3528 a->encap.mpls.mpls[3].label = label;
3529 a->encap.mpls.mpls[3].tc = tc;
3530 a->encap.mpls.mpls[3].ttl = ttl;
3532 a->encap.mpls.mpls_count = 4;
3533 a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3534 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3535 return 1 + 8 + 4 + 4 + 4;
3539 if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3540 if ((n_tokens < 4) ||
3541 parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3542 parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3543 parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3547 a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3548 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3553 if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
3560 /* ether <da> <sa> */
3561 if ((n_tokens < 3) ||
3562 strcmp(tokens[0], "ether") ||
3563 parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
3564 parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
3571 /* [vlan <pcp> <dei> <vid>] */
3572 if (strcmp(tokens[0], "vlan") == 0) {
3573 uint32_t pcp, dei, vid;
3575 if ((n_tokens < 4) ||
3576 parser_read_uint32(&pcp, tokens[1]) ||
3578 parser_read_uint32(&dei, tokens[2]) ||
3580 parser_read_uint32(&vid, tokens[3]) ||
3584 a->encap.vxlan.vlan.pcp = pcp;
3585 a->encap.vxlan.vlan.dei = dei;
3586 a->encap.vxlan.vlan.vid = vid;
3593 /* ipv4 <sa> <da> <dscp> <ttl>
3594 | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
3595 if (strcmp(tokens[0], "ipv4") == 0) {
3596 struct in_addr sa, da;
3599 if ((n_tokens < 5) ||
3600 parse_ipv4_addr(tokens[1], &sa) ||
3601 parse_ipv4_addr(tokens[2], &da) ||
3602 parser_read_uint8(&dscp, tokens[3]) ||
3604 parser_read_uint8(&ttl, tokens[4]))
3607 a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
3608 a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
3609 a->encap.vxlan.ipv4.dscp = dscp;
3610 a->encap.vxlan.ipv4.ttl = ttl;
3615 } else if (strcmp(tokens[0], "ipv6") == 0) {
3616 struct in6_addr sa, da;
3617 uint32_t flow_label;
3618 uint8_t dscp, hop_limit;
3620 if ((n_tokens < 6) ||
3621 parse_ipv6_addr(tokens[1], &sa) ||
3622 parse_ipv6_addr(tokens[2], &da) ||
3623 parser_read_uint32(&flow_label, tokens[3]) ||
3624 parser_read_uint8(&dscp, tokens[4]) ||
3626 parser_read_uint8(&hop_limit, tokens[5]))
3629 memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
3630 memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
3631 a->encap.vxlan.ipv6.flow_label = flow_label;
3632 a->encap.vxlan.ipv6.dscp = dscp;
3633 a->encap.vxlan.ipv6.hop_limit = hop_limit;
3642 if ((n_tokens < 3) ||
3643 strcmp(tokens[0], "udp") ||
3644 parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
3645 parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
3653 if ((n_tokens < 2) ||
3654 strcmp(tokens[0], "vxlan") ||
3655 parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
3656 (a->encap.vxlan.vxlan.vni > 0xFFFFFF))
3663 a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
3664 a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3672 parse_table_action_nat(char **tokens,
3674 struct table_rule_action *a)
3676 if ((n_tokens < 4) ||
3677 strcmp(tokens[0], "nat"))
3680 if (strcmp(tokens[1], "ipv4") == 0) {
3681 struct in_addr addr;
3684 if (parse_ipv4_addr(tokens[2], &addr) ||
3685 parser_read_uint16(&port, tokens[3]))
3688 a->nat.ip_version = 1;
3689 a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3691 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3695 if (strcmp(tokens[1], "ipv6") == 0) {
3696 struct in6_addr addr;
3699 if (parse_ipv6_addr(tokens[2], &addr) ||
3700 parser_read_uint16(&port, tokens[3]))
3703 a->nat.ip_version = 0;
3704 memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3706 a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3714 parse_table_action_ttl(char **tokens,
3716 struct table_rule_action *a)
3718 if ((n_tokens < 2) ||
3719 strcmp(tokens[0], "ttl"))
3722 if (strcmp(tokens[1], "dec") == 0)
3723 a->ttl.decrement = 1;
3724 else if (strcmp(tokens[1], "keep") == 0)
3725 a->ttl.decrement = 0;
3729 a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3734 parse_table_action_stats(char **tokens,
3736 struct table_rule_action *a)
3738 if ((n_tokens < 1) ||
3739 strcmp(tokens[0], "stats"))
3742 a->stats.n_packets = 0;
3743 a->stats.n_bytes = 0;
3744 a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3749 parse_table_action_time(char **tokens,
3751 struct table_rule_action *a)
3753 if ((n_tokens < 1) ||
3754 strcmp(tokens[0], "time"))
3757 a->time.time = rte_rdtsc();
3758 a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3763 parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
3765 struct rte_crypto_sym_xform *xform[2] = {NULL};
3768 xform[0] = p->xform;
3770 xform[1] = xform[0]->next;
3772 for (i = 0; i < 2; i++) {
3773 if (xform[i] == NULL)
3776 switch (xform[i]->type) {
3777 case RTE_CRYPTO_SYM_XFORM_CIPHER:
3778 if (p->cipher_auth.cipher_iv.val)
3779 free(p->cipher_auth.cipher_iv.val);
3780 if (p->cipher_auth.cipher_iv_update.val)
3781 free(p->cipher_auth.cipher_iv_update.val);
3783 case RTE_CRYPTO_SYM_XFORM_AUTH:
3784 if (p->cipher_auth.auth_iv.val)
3785 free(p->cipher_auth.cipher_iv.val);
3786 if (p->cipher_auth.auth_iv_update.val)
3787 free(p->cipher_auth.cipher_iv_update.val);
3789 case RTE_CRYPTO_SYM_XFORM_AEAD:
3791 free(p->aead.iv.val);
3792 if (p->aead.aad.val)
3793 free(p->aead.aad.val);
3802 static struct rte_crypto_sym_xform *
3803 parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3804 uint8_t *key, uint32_t max_key_len, char **tokens,
3805 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3807 struct rte_crypto_sym_xform *xform_cipher;
3811 if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
3812 strcmp(tokens[3], "cipher_key") ||
3813 strcmp(tokens[5], "cipher_iv"))
3816 xform_cipher = calloc(1, sizeof(*xform_cipher));
3817 if (xform_cipher == NULL)
3820 xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
3821 xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
3822 RTE_CRYPTO_CIPHER_OP_DECRYPT;
3825 status = rte_cryptodev_get_cipher_algo_enum(
3826 &xform_cipher->cipher.algo, tokens[2]);
3831 len = strlen(tokens[4]);
3832 if (len / 2 > max_key_len) {
3837 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
3841 xform_cipher->cipher.key.data = key;
3842 xform_cipher->cipher.key.length = (uint16_t)len;
3845 len = strlen(tokens[6]);
3847 p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
3848 if (p->cipher_auth.cipher_iv.val == NULL)
3851 status = parse_hex_string(tokens[6],
3852 p->cipher_auth.cipher_iv.val,
3857 xform_cipher->cipher.iv.length = (uint16_t)len;
3858 xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
3859 p->cipher_auth.cipher_iv.length = (uint32_t)len;
3862 return xform_cipher;
3865 if (p->cipher_auth.cipher_iv.val) {
3866 free(p->cipher_auth.cipher_iv.val);
3867 p->cipher_auth.cipher_iv.val = NULL;
3875 static struct rte_crypto_sym_xform *
3876 parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3877 uint8_t *key, uint32_t max_key_len, char **tokens,
3878 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3880 struct rte_crypto_sym_xform *xform_cipher;
3881 struct rte_crypto_sym_xform *xform_auth;
3885 if (n_tokens < 13 ||
3886 strcmp(tokens[7], "auth_algo") ||
3887 strcmp(tokens[9], "auth_key") ||
3888 strcmp(tokens[11], "digest_size"))
3891 xform_auth = calloc(1, sizeof(*xform_auth));
3892 if (xform_auth == NULL)
3895 xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
3896 xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
3897 RTE_CRYPTO_AUTH_OP_VERIFY;
3900 status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
3906 len = strlen(tokens[10]);
3907 if (len / 2 > max_key_len) {
3912 status = parse_hex_string(tokens[10], key, (uint32_t *)&len);
3916 xform_auth->auth.key.data = key;
3917 xform_auth->auth.key.length = (uint16_t)len;
3919 key += xform_auth->auth.key.length;
3920 max_key_len -= xform_auth->auth.key.length;
3922 if (strcmp(tokens[11], "digest_size"))
3925 status = parser_read_uint16(&xform_auth->auth.digest_length,
3930 xform_cipher = parse_table_action_cipher(p, key, max_key_len, tokens,
3931 7, encrypt, used_n_tokens);
3932 if (xform_cipher == NULL)
3935 *used_n_tokens += 6;
3938 xform_cipher->next = xform_auth;
3939 return xform_cipher;
3941 xform_auth->next = xform_cipher;
3946 if (p->cipher_auth.auth_iv.val) {
3947 free(p->cipher_auth.auth_iv.val);
3948 p->cipher_auth.auth_iv.val = 0;
3956 static struct rte_crypto_sym_xform *
3957 parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3958 uint8_t *key, uint32_t max_key_len, char **tokens,
3959 uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
3961 struct rte_crypto_sym_xform *xform_aead;
3965 if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
3966 strcmp(tokens[3], "aead_key") ||
3967 strcmp(tokens[5], "aead_iv") ||
3968 strcmp(tokens[7], "aead_aad") ||
3969 strcmp(tokens[9], "digest_size"))
3972 xform_aead = calloc(1, sizeof(*xform_aead));
3973 if (xform_aead == NULL)
3976 xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
3977 xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
3978 RTE_CRYPTO_AEAD_OP_DECRYPT;
3981 status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
3987 len = strlen(tokens[4]);
3988 if (len / 2 > max_key_len) {
3993 status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
3997 xform_aead->aead.key.data = key;
3998 xform_aead->aead.key.length = (uint16_t)len;
4001 len = strlen(tokens[6]);
4002 p->aead.iv.val = calloc(1, len / 2 + 1);
4003 if (p->aead.iv.val == NULL)
4006 status = parse_hex_string(tokens[6], p->aead.iv.val,
4011 xform_aead->aead.iv.length = (uint16_t)len;
4012 xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
4013 p->aead.iv.length = (uint32_t)len;
4016 len = strlen(tokens[8]);
4017 p->aead.aad.val = calloc(1, len / 2 + 1);
4018 if (p->aead.aad.val == NULL)
4021 status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
4025 xform_aead->aead.aad_length = (uint16_t)len;
4026 p->aead.aad.length = (uint32_t)len;
4029 status = parser_read_uint16(&xform_aead->aead.digest_length,
4034 *used_n_tokens = 11;
4039 if (p->aead.iv.val) {
4040 free(p->aead.iv.val);
4041 p->aead.iv.val = NULL;
4043 if (p->aead.aad.val) {
4044 free(p->aead.aad.val);
4045 p->aead.aad.val = NULL;
4055 parse_table_action_sym_crypto(char **tokens,
4057 struct table_rule_action *a)
4059 struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
4060 struct rte_crypto_sym_xform *xform = NULL;
4061 uint8_t *key = a->sym_crypto_key;
4062 uint32_t max_key_len = SYM_CRYPTO_MAX_KEY_SIZE;
4063 uint32_t used_n_tokens;
4067 if ((n_tokens < 12) ||
4068 strcmp(tokens[0], "sym_crypto") ||
4069 strcmp(tokens[2], "type"))
4072 memset(p, 0, sizeof(*p));
4074 if (strcmp(tokens[1], "encrypt") == 0)
4079 status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
4083 if (strcmp(tokens[3], "cipher") == 0) {
4087 xform = parse_table_action_cipher(p, key, max_key_len, tokens,
4088 n_tokens, encrypt, &used_n_tokens);
4089 } else if (strcmp(tokens[3], "cipher_auth") == 0) {
4093 xform = parse_table_action_cipher_auth(p, key, max_key_len,
4094 tokens, n_tokens, encrypt, &used_n_tokens);
4095 } else if (strcmp(tokens[3], "aead") == 0) {
4099 xform = parse_table_action_aead(p, key, max_key_len, tokens,
4100 n_tokens, encrypt, &used_n_tokens);
4108 if (strcmp(tokens[used_n_tokens], "data_offset")) {
4109 parse_free_sym_crypto_param_data(p);
4113 a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
4115 return used_n_tokens + 5;
4119 parse_table_action_tag(char **tokens,
4121 struct table_rule_action *a)
4123 if ((n_tokens < 2) ||
4124 strcmp(tokens[0], "tag"))
4127 if (parser_read_uint32(&a->tag.tag, tokens[1]))
4130 a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
4135 parse_table_action_decap(char **tokens,
4137 struct table_rule_action *a)
4139 if ((n_tokens < 2) ||
4140 strcmp(tokens[0], "decap"))
4143 if (parser_read_uint16(&a->decap.n, tokens[1]))
4146 a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4151 parse_table_action(char **tokens,
4155 struct table_rule_action *a)
4157 uint32_t n_tokens0 = n_tokens;
4159 memset(a, 0, sizeof(*a));
4161 if ((n_tokens < 2) ||
4162 strcmp(tokens[0], "action"))
4168 if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4171 n = parse_table_action_fwd(tokens, n_tokens, a);
4173 snprintf(out, out_size, MSG_ARG_INVALID,
4182 if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4185 n = parse_table_action_balance(tokens, n_tokens, a);
4187 snprintf(out, out_size, MSG_ARG_INVALID,
4196 if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4199 n = parse_table_action_meter(tokens, n_tokens, a);
4201 snprintf(out, out_size, MSG_ARG_INVALID,
4210 if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4213 n = parse_table_action_tm(tokens, n_tokens, a);
4215 snprintf(out, out_size, MSG_ARG_INVALID,
4224 if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4227 n = parse_table_action_encap(tokens, n_tokens, a);
4229 snprintf(out, out_size, MSG_ARG_INVALID,
4238 if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4241 n = parse_table_action_nat(tokens, n_tokens, a);
4243 snprintf(out, out_size, MSG_ARG_INVALID,
4252 if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4255 n = parse_table_action_ttl(tokens, n_tokens, a);
4257 snprintf(out, out_size, MSG_ARG_INVALID,
4266 if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4269 n = parse_table_action_stats(tokens, n_tokens, a);
4271 snprintf(out, out_size, MSG_ARG_INVALID,
4280 if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4283 n = parse_table_action_time(tokens, n_tokens, a);
4285 snprintf(out, out_size, MSG_ARG_INVALID,
4294 if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
4297 n = parse_table_action_sym_crypto(tokens, n_tokens, a);
4299 snprintf(out, out_size, MSG_ARG_INVALID,
4300 "action sym_crypto");
4307 if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
4310 n = parse_table_action_tag(tokens, n_tokens, a);
4312 snprintf(out, out_size, MSG_ARG_INVALID,
4321 if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4324 n = parse_table_action_decap(tokens, n_tokens, a);
4326 snprintf(out, out_size, MSG_ARG_INVALID,
4335 if (n_tokens0 - n_tokens == 1) {
4336 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4340 return n_tokens0 - n_tokens;
4344 static const char cmd_pipeline_table_rule_add_help[] =
4345 "pipeline <pipeline_name> table <table_id> rule add\n"
4347 " action <table_action>\n";
4350 cmd_pipeline_table_rule_add(char **tokens,
4355 struct table_rule_match m;
4356 struct table_rule_action a;
4357 char *pipeline_name;
4358 uint32_t table_id, t0, n_tokens_parsed;
4362 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4366 pipeline_name = tokens[1];
4368 if (strcmp(tokens[2], "table") != 0) {
4369 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4373 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4374 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4378 if (strcmp(tokens[4], "rule") != 0) {
4379 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4383 if (strcmp(tokens[5], "add") != 0) {
4384 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4391 n_tokens_parsed = parse_match(tokens + t0,
4396 if (n_tokens_parsed == 0)
4398 t0 += n_tokens_parsed;
4401 n_tokens_parsed = parse_table_action(tokens + t0,
4406 if (n_tokens_parsed == 0)
4408 t0 += n_tokens_parsed;
4410 if (t0 != n_tokens) {
4411 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4415 status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
4417 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4421 if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
4422 parse_free_sym_crypto_param_data(&a.sym_crypto);
4426 static const char cmd_pipeline_table_rule_add_default_help[] =
4427 "pipeline <pipeline_name> table <table_id> rule add\n"
4433 " | port <port_id>\n"
4435 " | table <table_id>\n";
4438 cmd_pipeline_table_rule_add_default(char **tokens,
4443 struct table_rule_action action;
4444 char *pipeline_name;
4448 if ((n_tokens != 11) && (n_tokens != 12)) {
4449 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4453 pipeline_name = tokens[1];
4455 if (strcmp(tokens[2], "table") != 0) {
4456 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4460 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4461 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4465 if (strcmp(tokens[4], "rule") != 0) {
4466 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4470 if (strcmp(tokens[5], "add") != 0) {
4471 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4475 if (strcmp(tokens[6], "match") != 0) {
4476 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4480 if (strcmp(tokens[7], "default") != 0) {
4481 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4485 if (strcmp(tokens[8], "action") != 0) {
4486 snprintf(out, out_size, MSG_ARG_INVALID, "action");
4490 if (strcmp(tokens[9], "fwd") != 0) {
4491 snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4495 action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4497 if (strcmp(tokens[10], "drop") == 0) {
4498 if (n_tokens != 11) {
4499 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4503 action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4504 } else if (strcmp(tokens[10], "port") == 0) {
4507 if (n_tokens != 12) {
4508 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4512 if (parser_read_uint32(&id, tokens[11]) != 0) {
4513 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4517 action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4519 } else if (strcmp(tokens[10], "meta") == 0) {
4520 if (n_tokens != 11) {
4521 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4525 action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4526 } else if (strcmp(tokens[10], "table") == 0) {
4529 if (n_tokens != 12) {
4530 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4534 if (parser_read_uint32(&id, tokens[11]) != 0) {
4535 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4539 action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4542 snprintf(out, out_size, MSG_ARG_INVALID,
4543 "drop or port or meta or table");
4547 status = pipeline_table_rule_add_default(pipeline_name,
4551 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4557 static const char cmd_pipeline_table_rule_add_bulk_help[] =
4558 "pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\n"
4560 " File <file_name>:\n"
4561 " - line format: match <match> action <action>\n";
4564 cli_rule_file_process(const char *file_name,
4565 size_t line_len_max,
4566 struct table_rule_list **rule_list,
4568 uint32_t *line_number,
4573 cmd_pipeline_table_rule_add_bulk(char **tokens,
4578 struct table_rule_list *list = NULL;
4579 char *pipeline_name, *file_name;
4580 uint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;
4583 if (n_tokens != 8) {
4584 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4588 pipeline_name = tokens[1];
4590 if (strcmp(tokens[2], "table") != 0) {
4591 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4595 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4596 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4600 if (strcmp(tokens[4], "rule") != 0) {
4601 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4605 if (strcmp(tokens[5], "add") != 0) {
4606 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4610 if (strcmp(tokens[6], "bulk") != 0) {
4611 snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
4615 file_name = tokens[7];
4617 /* Load rules from file. */
4618 status = cli_rule_file_process(file_name,
4626 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
4631 status = pipeline_table_rule_add_bulk(pipeline_name,
4635 &n_rules_not_added);
4637 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4641 snprintf(out, out_size, "Added %u rules out of %u.\n",
4647 static const char cmd_pipeline_table_rule_delete_help[] =
4648 "pipeline <pipeline_name> table <table_id> rule delete\n"
4652 cmd_pipeline_table_rule_delete(char **tokens,
4657 struct table_rule_match m;
4658 char *pipeline_name;
4659 uint32_t table_id, n_tokens_parsed, t0;
4663 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4667 pipeline_name = tokens[1];
4669 if (strcmp(tokens[2], "table") != 0) {
4670 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4674 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4675 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4679 if (strcmp(tokens[4], "rule") != 0) {
4680 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4684 if (strcmp(tokens[5], "delete") != 0) {
4685 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4692 n_tokens_parsed = parse_match(tokens + t0,
4697 if (n_tokens_parsed == 0)
4699 t0 += n_tokens_parsed;
4701 if (n_tokens != t0) {
4702 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4706 status = pipeline_table_rule_delete(pipeline_name,
4710 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4716 static const char cmd_pipeline_table_rule_delete_default_help[] =
4717 "pipeline <pipeline_name> table <table_id> rule delete\n"
4722 cmd_pipeline_table_rule_delete_default(char **tokens,
4727 char *pipeline_name;
4731 if (n_tokens != 8) {
4732 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4736 pipeline_name = tokens[1];
4738 if (strcmp(tokens[2], "table") != 0) {
4739 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4743 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4744 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4748 if (strcmp(tokens[4], "rule") != 0) {
4749 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4753 if (strcmp(tokens[5], "delete") != 0) {
4754 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4758 if (strcmp(tokens[6], "match") != 0) {
4759 snprintf(out, out_size, MSG_ARG_INVALID, "match");
4763 if (strcmp(tokens[7], "default") != 0) {
4764 snprintf(out, out_size, MSG_ARG_INVALID, "default");
4768 status = pipeline_table_rule_delete_default(pipeline_name,
4771 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4777 ether_addr_show(FILE *f, struct rte_ether_addr *addr)
4779 fprintf(f, "%02x:%02x:%02x:%02x:%02x:%02x",
4780 (uint32_t)addr->addr_bytes[0], (uint32_t)addr->addr_bytes[1],
4781 (uint32_t)addr->addr_bytes[2], (uint32_t)addr->addr_bytes[3],
4782 (uint32_t)addr->addr_bytes[4], (uint32_t)addr->addr_bytes[5]);
4786 ipv4_addr_show(FILE *f, uint32_t addr)
4788 fprintf(f, "%u.%u.%u.%u",
4790 (addr >> 16) & 0xFF,
4796 ipv6_addr_show(FILE *f, uint8_t *addr)
4798 fprintf(f, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
4799 "%02x%02x:%02x%02x:%02x%02x:%02x%02x:",
4800 (uint32_t)addr[0], (uint32_t)addr[1],
4801 (uint32_t)addr[2], (uint32_t)addr[3],
4802 (uint32_t)addr[4], (uint32_t)addr[5],
4803 (uint32_t)addr[6], (uint32_t)addr[7],
4804 (uint32_t)addr[8], (uint32_t)addr[9],
4805 (uint32_t)addr[10], (uint32_t)addr[11],
4806 (uint32_t)addr[12], (uint32_t)addr[13],
4807 (uint32_t)addr[14], (uint32_t)addr[15]);
4811 policer_action_string(enum rte_table_action_policer action) {
4813 case RTE_TABLE_ACTION_POLICER_COLOR_GREEN: return "G";
4814 case RTE_TABLE_ACTION_POLICER_COLOR_YELLOW: return "Y";
4815 case RTE_TABLE_ACTION_POLICER_COLOR_RED: return "R";
4816 case RTE_TABLE_ACTION_POLICER_DROP: return "D";
4817 default: return "?";
4822 table_rule_show(const char *pipeline_name,
4824 const char *file_name)
4827 struct table *table;
4828 struct table_rule *rule;
4832 /* Check input params. */
4833 if ((pipeline_name == NULL) ||
4834 (file_name == NULL))
4837 p = pipeline_find(pipeline_name);
4839 (table_id >= p->n_tables))
4842 table = &p->table[table_id];
4845 f = fopen(file_name, "w");
4849 /* Write table rules to file. */
4850 TAILQ_FOREACH(rule, &table->rules, node) {
4851 struct table_rule_match *m = &rule->match;
4852 struct table_rule_action *a = &rule->action;
4854 fprintf(f, "match ");
4855 switch (m->match_type) {
4857 fprintf(f, "acl priority %u ",
4858 m->match.acl.priority);
4860 fprintf(f, m->match.acl.ip_version ? "ipv4 " : "ipv6 ");
4862 if (m->match.acl.ip_version)
4863 ipv4_addr_show(f, m->match.acl.ipv4.sa);
4865 ipv6_addr_show(f, m->match.acl.ipv6.sa);
4867 fprintf(f, "%u", m->match.acl.sa_depth);
4869 if (m->match.acl.ip_version)
4870 ipv4_addr_show(f, m->match.acl.ipv4.da);
4872 ipv6_addr_show(f, m->match.acl.ipv6.da);
4874 fprintf(f, "%u", m->match.acl.da_depth);
4876 fprintf(f, "%u %u %u %u %u ",
4877 (uint32_t)m->match.acl.sp0,
4878 (uint32_t)m->match.acl.sp1,
4879 (uint32_t)m->match.acl.dp0,
4880 (uint32_t)m->match.acl.dp1,
4881 (uint32_t)m->match.acl.proto);
4885 fprintf(f, "array %u ",
4886 m->match.array.pos);
4890 fprintf(f, "hash raw ");
4891 for (i = 0; i < table->params.match.hash.key_size; i++)
4892 fprintf(f, "%02x", m->match.hash.key[i]);
4899 fprintf(f, m->match.lpm.ip_version ? "ipv4 " : "ipv6 ");
4901 if (m->match.acl.ip_version)
4902 ipv4_addr_show(f, m->match.lpm.ipv4);
4904 ipv6_addr_show(f, m->match.lpm.ipv6);
4907 (uint32_t)m->match.lpm.depth);
4911 fprintf(f, "unknown ");
4914 fprintf(f, "action ");
4915 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
4917 switch (a->fwd.action) {
4918 case RTE_PIPELINE_ACTION_DROP:
4919 fprintf(f, "drop ");
4922 case RTE_PIPELINE_ACTION_PORT:
4923 fprintf(f, "port %u ", a->fwd.id);
4926 case RTE_PIPELINE_ACTION_PORT_META:
4927 fprintf(f, "meta ");
4930 case RTE_PIPELINE_ACTION_TABLE:
4932 fprintf(f, "table %u ", a->fwd.id);
4936 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
4937 fprintf(f, "balance ");
4938 for (i = 0; i < RTE_DIM(a->lb.out); i++)
4939 fprintf(f, "%u ", a->lb.out[i]);
4942 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
4944 for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++)
4945 if (a->mtr.tc_mask & (1 << i)) {
4946 struct rte_table_action_mtr_tc_params *p =
4948 enum rte_table_action_policer ga =
4949 p->policer[RTE_COLOR_GREEN];
4950 enum rte_table_action_policer ya =
4951 p->policer[RTE_COLOR_YELLOW];
4952 enum rte_table_action_policer ra =
4953 p->policer[RTE_COLOR_RED];
4955 fprintf(f, "tc%u meter %u policer g %s y %s r %s ",
4957 a->mtr.mtr[i].meter_profile_id,
4958 policer_action_string(ga),
4959 policer_action_string(ya),
4960 policer_action_string(ra));
4964 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TM))
4965 fprintf(f, "tm subport %u pipe %u ",
4969 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
4970 fprintf(f, "encap ");
4971 switch (a->encap.type) {
4972 case RTE_TABLE_ACTION_ENCAP_ETHER:
4973 fprintf(f, "ether ");
4974 ether_addr_show(f, &a->encap.ether.ether.da);
4976 ether_addr_show(f, &a->encap.ether.ether.sa);
4980 case RTE_TABLE_ACTION_ENCAP_VLAN:
4981 fprintf(f, "vlan ");
4982 ether_addr_show(f, &a->encap.vlan.ether.da);
4984 ether_addr_show(f, &a->encap.vlan.ether.sa);
4985 fprintf(f, " pcp %u dei %u vid %u ",
4986 a->encap.vlan.vlan.pcp,
4987 a->encap.vlan.vlan.dei,
4988 a->encap.vlan.vlan.vid);
4991 case RTE_TABLE_ACTION_ENCAP_QINQ:
4992 fprintf(f, "qinq ");
4993 ether_addr_show(f, &a->encap.qinq.ether.da);
4995 ether_addr_show(f, &a->encap.qinq.ether.sa);
4996 fprintf(f, " pcp %u dei %u vid %u pcp %u dei %u vid %u ",
4997 a->encap.qinq.svlan.pcp,
4998 a->encap.qinq.svlan.dei,
4999 a->encap.qinq.svlan.vid,
5000 a->encap.qinq.cvlan.pcp,
5001 a->encap.qinq.cvlan.dei,
5002 a->encap.qinq.cvlan.vid);
5005 case RTE_TABLE_ACTION_ENCAP_MPLS:
5006 fprintf(f, "mpls %s ", (a->encap.mpls.unicast) ?
5007 "unicast " : "multicast ");
5008 ether_addr_show(f, &a->encap.mpls.ether.da);
5010 ether_addr_show(f, &a->encap.mpls.ether.sa);
5012 for (i = 0; i < a->encap.mpls.mpls_count; i++) {
5013 struct rte_table_action_mpls_hdr *l =
5014 &a->encap.mpls.mpls[i];
5016 fprintf(f, "label%u %u %u %u ",
5024 case RTE_TABLE_ACTION_ENCAP_PPPOE:
5025 fprintf(f, "pppoe ");
5026 ether_addr_show(f, &a->encap.pppoe.ether.da);
5028 ether_addr_show(f, &a->encap.pppoe.ether.sa);
5029 fprintf(f, " %u ", a->encap.pppoe.pppoe.session_id);
5032 case RTE_TABLE_ACTION_ENCAP_VXLAN:
5033 fprintf(f, "vxlan ether ");
5034 ether_addr_show(f, &a->encap.vxlan.ether.da);
5036 ether_addr_show(f, &a->encap.vxlan.ether.sa);
5037 if (table->ap->params.encap.vxlan.vlan)
5038 fprintf(f, " vlan pcp %u dei %u vid %u ",
5039 a->encap.vxlan.vlan.pcp,
5040 a->encap.vxlan.vlan.dei,
5041 a->encap.vxlan.vlan.vid);
5042 if (table->ap->params.encap.vxlan.ip_version) {
5043 fprintf(f, " ipv4 ");
5044 ipv4_addr_show(f, a->encap.vxlan.ipv4.sa);
5046 ipv4_addr_show(f, a->encap.vxlan.ipv4.da);
5047 fprintf(f, " %u %u ",
5048 (uint32_t)a->encap.vxlan.ipv4.dscp,
5049 (uint32_t)a->encap.vxlan.ipv4.ttl);
5051 fprintf(f, " ipv6 ");
5052 ipv6_addr_show(f, a->encap.vxlan.ipv6.sa);
5054 ipv6_addr_show(f, a->encap.vxlan.ipv6.da);
5055 fprintf(f, " %u %u %u ",
5056 a->encap.vxlan.ipv6.flow_label,
5057 (uint32_t)a->encap.vxlan.ipv6.dscp,
5058 (uint32_t)a->encap.vxlan.ipv6.hop_limit);
5059 fprintf(f, " udp %u %u vxlan %u ",
5060 a->encap.vxlan.udp.sp,
5061 a->encap.vxlan.udp.dp,
5062 a->encap.vxlan.vxlan.vni);
5067 fprintf(f, "unknown ");
5071 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
5072 fprintf(f, "nat %s ", (a->nat.ip_version) ? "ipv4 " : "ipv6 ");
5073 if (a->nat.ip_version)
5074 ipv4_addr_show(f, a->nat.addr.ipv4);
5076 ipv6_addr_show(f, a->nat.addr.ipv6);
5077 fprintf(f, " %u ", (uint32_t)(a->nat.port));
5080 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TTL))
5081 fprintf(f, "ttl %s ", (a->ttl.decrement) ? "dec" : "keep");
5083 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_STATS))
5084 fprintf(f, "stats ");
5086 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TIME))
5087 fprintf(f, "time ");
5089 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO))
5090 fprintf(f, "sym_crypto ");
5092 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TAG))
5093 fprintf(f, "tag %u ", a->tag.tag);
5095 if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
5096 fprintf(f, "decap %u ", a->decap.n);
5102 /* Write table default rule to file. */
5103 if (table->rule_default) {
5104 struct table_rule_action *a = &table->rule_default->action;
5106 fprintf(f, "# match default action fwd ");
5108 switch (a->fwd.action) {
5109 case RTE_PIPELINE_ACTION_DROP:
5110 fprintf(f, "drop ");
5113 case RTE_PIPELINE_ACTION_PORT:
5114 fprintf(f, "port %u ", a->fwd.id);
5117 case RTE_PIPELINE_ACTION_PORT_META:
5118 fprintf(f, "meta ");
5121 case RTE_PIPELINE_ACTION_TABLE:
5123 fprintf(f, "table %u ", a->fwd.id);
5126 fprintf(f, "# match default action fwd drop ");
5136 static const char cmd_pipeline_table_rule_show_help[] =
5137 "pipeline <pipeline_name> table <table_id> rule show\n"
5138 " file <file_name>\n";
5141 cmd_pipeline_table_rule_show(char **tokens,
5146 char *file_name = NULL, *pipeline_name;
5150 if (n_tokens != 8) {
5151 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5155 pipeline_name = tokens[1];
5157 if (strcmp(tokens[2], "table") != 0) {
5158 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5162 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5163 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5167 if (strcmp(tokens[4], "rule") != 0) {
5168 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5172 if (strcmp(tokens[5], "show") != 0) {
5173 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "show");
5177 if (strcmp(tokens[6], "file") != 0) {
5178 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "file");
5182 file_name = tokens[7];
5184 status = table_rule_show(pipeline_name, table_id, file_name);
5186 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5191 static const char cmd_pipeline_table_rule_stats_read_help[] =
5192 "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n"
5196 cmd_pipeline_table_rule_stats_read(char **tokens,
5201 struct table_rule_match m;
5202 struct rte_table_action_stats_counters stats;
5203 char *pipeline_name;
5204 uint32_t table_id, n_tokens_parsed;
5205 int clear = 0, status;
5208 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5212 pipeline_name = tokens[1];
5214 if (strcmp(tokens[2], "table") != 0) {
5215 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5219 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5220 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5224 if (strcmp(tokens[4], "rule") != 0) {
5225 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5229 if (strcmp(tokens[5], "read") != 0) {
5230 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5234 if (strcmp(tokens[6], "stats") != 0) {
5235 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
5243 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5251 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5252 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5256 n_tokens_parsed = parse_match(tokens,
5261 if (n_tokens_parsed == 0)
5263 n_tokens -= n_tokens_parsed;
5264 tokens += n_tokens_parsed;
5268 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5272 /* Read table rule stats. */
5273 status = pipeline_table_rule_stats_read(pipeline_name,
5279 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5284 if (stats.n_packets_valid && stats.n_bytes_valid)
5285 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: %" PRIu64 "\n",
5289 if (stats.n_packets_valid && !stats.n_bytes_valid)
5290 snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: N/A\n",
5293 if (!stats.n_packets_valid && stats.n_bytes_valid)
5294 snprintf(out, out_size, "Packets: N/A; Bytes: %" PRIu64 "\n",
5297 if (!stats.n_packets_valid && !stats.n_bytes_valid)
5298 snprintf(out, out_size, "Packets: N/A ; Bytes: N/A\n");
5301 static const char cmd_pipeline_table_meter_profile_add_help[] =
5302 "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
5303 " add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
5304 " | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
5307 cmd_pipeline_table_meter_profile_add(char **tokens,
5312 struct rte_table_action_meter_profile p;
5313 char *pipeline_name;
5314 uint32_t table_id, meter_profile_id;
5318 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5322 pipeline_name = tokens[1];
5324 if (strcmp(tokens[2], "table") != 0) {
5325 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5329 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5330 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5334 if (strcmp(tokens[4], "meter") != 0) {
5335 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5339 if (strcmp(tokens[5], "profile") != 0) {
5340 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5344 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5345 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5349 if (strcmp(tokens[7], "add") != 0) {
5350 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
5354 if (strcmp(tokens[8], "srtcm") == 0) {
5355 if (n_tokens != 15) {
5356 snprintf(out, out_size, MSG_ARG_MISMATCH,
5361 p.alg = RTE_TABLE_ACTION_METER_SRTCM;
5363 if (strcmp(tokens[9], "cir") != 0) {
5364 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5368 if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
5369 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5373 if (strcmp(tokens[11], "cbs") != 0) {
5374 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5378 if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
5379 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5383 if (strcmp(tokens[13], "ebs") != 0) {
5384 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
5388 if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
5389 snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
5392 } else if (strcmp(tokens[8], "trtcm") == 0) {
5393 if (n_tokens != 17) {
5394 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5398 p.alg = RTE_TABLE_ACTION_METER_TRTCM;
5400 if (strcmp(tokens[9], "cir") != 0) {
5401 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
5405 if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
5406 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
5410 if (strcmp(tokens[11], "pir") != 0) {
5411 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
5415 if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
5416 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
5419 if (strcmp(tokens[13], "cbs") != 0) {
5420 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
5424 if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
5425 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
5429 if (strcmp(tokens[15], "pbs") != 0) {
5430 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
5434 if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
5435 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
5439 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5443 status = pipeline_table_mtr_profile_add(pipeline_name,
5448 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5454 static const char cmd_pipeline_table_meter_profile_delete_help[] =
5455 "pipeline <pipeline_name> table <table_id>\n"
5456 " meter profile <meter_profile_id> delete\n";
5459 cmd_pipeline_table_meter_profile_delete(char **tokens,
5464 char *pipeline_name;
5465 uint32_t table_id, meter_profile_id;
5468 if (n_tokens != 8) {
5469 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5473 pipeline_name = tokens[1];
5475 if (strcmp(tokens[2], "table") != 0) {
5476 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5480 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5481 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5485 if (strcmp(tokens[4], "meter") != 0) {
5486 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5490 if (strcmp(tokens[5], "profile") != 0) {
5491 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
5495 if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
5496 snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
5500 if (strcmp(tokens[7], "delete") != 0) {
5501 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
5505 status = pipeline_table_mtr_profile_delete(pipeline_name,
5509 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5515 static const char cmd_pipeline_table_rule_meter_read_help[] =
5516 "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n"
5520 cmd_pipeline_table_rule_meter_read(char **tokens,
5525 struct table_rule_match m;
5526 struct rte_table_action_mtr_counters stats;
5527 char *pipeline_name;
5528 uint32_t table_id, n_tokens_parsed;
5529 int clear = 0, status;
5532 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5536 pipeline_name = tokens[1];
5538 if (strcmp(tokens[2], "table") != 0) {
5539 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5543 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5544 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5548 if (strcmp(tokens[4], "rule") != 0) {
5549 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5553 if (strcmp(tokens[5], "read") != 0) {
5554 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5558 if (strcmp(tokens[6], "meter") != 0) {
5559 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
5567 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5575 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5576 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5580 n_tokens_parsed = parse_match(tokens,
5585 if (n_tokens_parsed == 0)
5587 n_tokens -= n_tokens_parsed;
5588 tokens += n_tokens_parsed;
5592 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5596 /* Read table rule meter stats. */
5597 status = pipeline_table_rule_mtr_read(pipeline_name,
5603 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5611 static const char cmd_pipeline_table_dscp_help[] =
5612 "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
5614 " File <file_name>:\n"
5615 " - exactly 64 lines\n"
5616 " - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
5619 load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
5620 const char *file_name,
5621 uint32_t *line_number)
5626 /* Check input arguments */
5627 if ((dscp_table == NULL) ||
5628 (file_name == NULL) ||
5629 (line_number == NULL)) {
5635 /* Open input file */
5636 f = fopen(file_name, "r");
5643 for (dscp = 0, l = 1; ; l++) {
5646 enum rte_color color;
5647 uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
5649 if (fgets(line, sizeof(line), f) == NULL)
5652 if (is_comment(line))
5655 if (parse_tokenize_string(line, tokens, &n_tokens)) {
5664 if ((dscp >= RTE_DIM(dscp_table->entry)) ||
5665 (n_tokens != RTE_DIM(tokens)) ||
5666 parser_read_uint32(&tc_id, tokens[0]) ||
5667 (tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
5668 parser_read_uint32(&tc_queue_id, tokens[1]) ||
5669 (tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
5670 (strlen(tokens[2]) != 1)) {
5676 switch (tokens[2][0]) {
5679 color = RTE_COLOR_GREEN;
5684 color = RTE_COLOR_YELLOW;
5689 color = RTE_COLOR_RED;
5698 dscp_table->entry[dscp].tc_id = tc_id;
5699 dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
5700 dscp_table->entry[dscp].color = color;
5710 cmd_pipeline_table_dscp(char **tokens,
5715 struct rte_table_action_dscp_table dscp_table;
5716 char *pipeline_name, *file_name;
5717 uint32_t table_id, line_number;
5720 if (n_tokens != 6) {
5721 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5725 pipeline_name = tokens[1];
5727 if (strcmp(tokens[2], "table") != 0) {
5728 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5732 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5733 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5737 if (strcmp(tokens[4], "dscp") != 0) {
5738 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
5742 file_name = tokens[5];
5744 status = load_dscp_table(&dscp_table, file_name, &line_number);
5746 snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
5750 status = pipeline_table_dscp_table_update(pipeline_name,
5755 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5761 static const char cmd_pipeline_table_rule_ttl_read_help[] =
5762 "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n"
5766 cmd_pipeline_table_rule_ttl_read(char **tokens,
5771 struct table_rule_match m;
5772 struct rte_table_action_ttl_counters stats;
5773 char *pipeline_name;
5774 uint32_t table_id, n_tokens_parsed;
5775 int clear = 0, status;
5778 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5782 pipeline_name = tokens[1];
5784 if (strcmp(tokens[2], "table") != 0) {
5785 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5789 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5790 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5794 if (strcmp(tokens[4], "rule") != 0) {
5795 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5799 if (strcmp(tokens[5], "read") != 0) {
5800 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5804 if (strcmp(tokens[6], "ttl") != 0) {
5805 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ttl");
5813 if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
5821 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5822 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5826 n_tokens_parsed = parse_match(tokens,
5831 if (n_tokens_parsed == 0)
5833 n_tokens -= n_tokens_parsed;
5834 tokens += n_tokens_parsed;
5838 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5842 /* Read table rule TTL stats. */
5843 status = pipeline_table_rule_ttl_read(pipeline_name,
5849 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5854 snprintf(out, out_size, "Packets: %" PRIu64 "\n",
5858 static const char cmd_pipeline_table_rule_time_read_help[] =
5859 "pipeline <pipeline_name> table <table_id> rule read time\n"
5863 cmd_pipeline_table_rule_time_read(char **tokens,
5868 struct table_rule_match m;
5869 char *pipeline_name;
5871 uint32_t table_id, n_tokens_parsed;
5875 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5879 pipeline_name = tokens[1];
5881 if (strcmp(tokens[2], "table") != 0) {
5882 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5886 if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5887 snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5891 if (strcmp(tokens[4], "rule") != 0) {
5892 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5896 if (strcmp(tokens[5], "read") != 0) {
5897 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5901 if (strcmp(tokens[6], "time") != 0) {
5902 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "time");
5910 if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5911 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5915 n_tokens_parsed = parse_match(tokens,
5920 if (n_tokens_parsed == 0)
5922 n_tokens -= n_tokens_parsed;
5923 tokens += n_tokens_parsed;
5927 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5931 /* Read table rule timestamp. */
5932 status = pipeline_table_rule_time_read(pipeline_name,
5937 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5942 snprintf(out, out_size, "Packets: %" PRIu64 "\n", timestamp);
5945 static const char cmd_thread_pipeline_enable_help[] =
5946 "thread <thread_id> pipeline <pipeline_name> enable\n";
5949 cmd_thread_pipeline_enable(char **tokens,
5954 char *pipeline_name;
5958 if (n_tokens != 5) {
5959 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5963 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
5964 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
5968 if (strcmp(tokens[2], "pipeline") != 0) {
5969 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
5973 pipeline_name = tokens[3];
5975 if (strcmp(tokens[4], "enable") != 0) {
5976 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
5980 status = thread_pipeline_enable(thread_id, pipeline_name);
5982 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
5988 static const char cmd_thread_pipeline_disable_help[] =
5989 "thread <thread_id> pipeline <pipeline_name> disable\n";
5992 cmd_thread_pipeline_disable(char **tokens,
5997 char *pipeline_name;
6001 if (n_tokens != 5) {
6002 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
6006 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
6007 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
6011 if (strcmp(tokens[2], "pipeline") != 0) {
6012 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
6016 pipeline_name = tokens[3];
6018 if (strcmp(tokens[4], "disable") != 0) {
6019 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
6023 status = thread_pipeline_disable(thread_id, pipeline_name);
6025 snprintf(out, out_size, MSG_CMD_FAIL,
6026 "thread pipeline disable");
6032 cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
6037 if (n_tokens == 0) {
6038 snprintf(out, out_size,
6039 "Type 'help <command>' for details on each command.\n\n"
6040 "List of commands:\n"
6044 "\ttmgr subport profile\n"
6045 "\ttmgr pipe profile\n"
6048 "\ttmgr subport pipe\n"
6051 "\tport in action profile\n"
6052 "\ttable action profile\n"
6054 "\tpipeline port in\n"
6055 "\tpipeline port out\n"
6056 "\tpipeline table\n"
6057 "\tpipeline port in table\n"
6058 "\tpipeline port in stats\n"
6059 "\tpipeline port in enable\n"
6060 "\tpipeline port in disable\n"
6061 "\tpipeline port out stats\n"
6062 "\tpipeline table stats\n"
6063 "\tpipeline table rule add\n"
6064 "\tpipeline table rule add default\n"
6065 "\tpipeline table rule add bulk\n"
6066 "\tpipeline table rule delete\n"
6067 "\tpipeline table rule delete default\n"
6068 "\tpipeline table rule show\n"
6069 "\tpipeline table rule stats read\n"
6070 "\tpipeline table meter profile add\n"
6071 "\tpipeline table meter profile delete\n"
6072 "\tpipeline table rule meter read\n"
6073 "\tpipeline table dscp\n"
6074 "\tpipeline table rule ttl read\n"
6075 "\tpipeline table rule time read\n"
6076 "\tthread pipeline enable\n"
6077 "\tthread pipeline disable\n\n");
6081 if (strcmp(tokens[0], "mempool") == 0) {
6082 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
6086 if (strcmp(tokens[0], "link") == 0) {
6087 snprintf(out, out_size, "\n%s\n", cmd_link_help);
6091 if (strcmp(tokens[0], "swq") == 0) {
6092 snprintf(out, out_size, "\n%s\n", cmd_swq_help);
6096 if (strcmp(tokens[0], "tmgr") == 0) {
6097 if (n_tokens == 1) {
6098 snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
6102 if ((n_tokens == 2) &&
6103 (strcmp(tokens[1], "subport")) == 0) {
6104 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
6108 if ((n_tokens == 3) &&
6109 (strcmp(tokens[1], "subport") == 0) &&
6110 (strcmp(tokens[2], "profile") == 0)) {
6111 snprintf(out, out_size, "\n%s\n",
6112 cmd_tmgr_subport_profile_help);
6116 if ((n_tokens == 3) &&
6117 (strcmp(tokens[1], "subport") == 0) &&
6118 (strcmp(tokens[2], "pipe") == 0)) {
6119 snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
6123 if ((n_tokens == 3) &&
6124 (strcmp(tokens[1], "pipe") == 0) &&
6125 (strcmp(tokens[2], "profile") == 0)) {
6126 snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
6131 if (strcmp(tokens[0], "tap") == 0) {
6132 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
6136 if (strcmp(tokens[0], "kni") == 0) {
6137 snprintf(out, out_size, "\n%s\n", cmd_kni_help);
6141 if (strcmp(tokens[0], "cryptodev") == 0) {
6142 snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
6146 if ((n_tokens == 4) &&
6147 (strcmp(tokens[0], "port") == 0) &&
6148 (strcmp(tokens[1], "in") == 0) &&
6149 (strcmp(tokens[2], "action") == 0) &&
6150 (strcmp(tokens[3], "profile") == 0)) {
6151 snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
6155 if ((n_tokens == 3) &&
6156 (strcmp(tokens[0], "table") == 0) &&
6157 (strcmp(tokens[1], "action") == 0) &&
6158 (strcmp(tokens[2], "profile") == 0)) {
6159 snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
6163 if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
6164 snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
6168 if ((strcmp(tokens[0], "pipeline") == 0) &&
6169 (strcmp(tokens[1], "port") == 0)) {
6170 if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
6171 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
6175 if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
6176 snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
6180 if ((n_tokens == 4) &&
6181 (strcmp(tokens[2], "in") == 0) &&
6182 (strcmp(tokens[3], "table") == 0)) {
6183 snprintf(out, out_size, "\n%s\n",
6184 cmd_pipeline_port_in_table_help);
6188 if ((n_tokens == 4) &&
6189 (strcmp(tokens[2], "in") == 0) &&
6190 (strcmp(tokens[3], "stats") == 0)) {
6191 snprintf(out, out_size, "\n%s\n",
6192 cmd_pipeline_port_in_stats_help);
6196 if ((n_tokens == 4) &&
6197 (strcmp(tokens[2], "in") == 0) &&
6198 (strcmp(tokens[3], "enable") == 0)) {
6199 snprintf(out, out_size, "\n%s\n",
6200 cmd_pipeline_port_in_enable_help);
6204 if ((n_tokens == 4) &&
6205 (strcmp(tokens[2], "in") == 0) &&
6206 (strcmp(tokens[3], "disable") == 0)) {
6207 snprintf(out, out_size, "\n%s\n",
6208 cmd_pipeline_port_in_disable_help);
6212 if ((n_tokens == 4) &&
6213 (strcmp(tokens[2], "out") == 0) &&
6214 (strcmp(tokens[3], "stats") == 0)) {
6215 snprintf(out, out_size, "\n%s\n",
6216 cmd_pipeline_port_out_stats_help);
6221 if ((strcmp(tokens[0], "pipeline") == 0) &&
6222 (strcmp(tokens[1], "table") == 0)) {
6223 if (n_tokens == 2) {
6224 snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
6228 if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
6229 snprintf(out, out_size, "\n%s\n",
6230 cmd_pipeline_table_stats_help);
6234 if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
6235 snprintf(out, out_size, "\n%s\n",
6236 cmd_pipeline_table_dscp_help);
6240 if ((n_tokens == 4) &&
6241 (strcmp(tokens[2], "rule") == 0) &&
6242 (strcmp(tokens[3], "add") == 0)) {
6243 snprintf(out, out_size, "\n%s\n",
6244 cmd_pipeline_table_rule_add_help);
6248 if ((n_tokens == 5) &&
6249 (strcmp(tokens[2], "rule") == 0) &&
6250 (strcmp(tokens[3], "add") == 0) &&
6251 (strcmp(tokens[4], "default") == 0)) {
6252 snprintf(out, out_size, "\n%s\n",
6253 cmd_pipeline_table_rule_add_default_help);
6257 if ((n_tokens == 5) &&
6258 (strcmp(tokens[2], "rule") == 0) &&
6259 (strcmp(tokens[3], "add") == 0) &&
6260 (strcmp(tokens[4], "bulk") == 0)) {
6261 snprintf(out, out_size, "\n%s\n",
6262 cmd_pipeline_table_rule_add_bulk_help);
6266 if ((n_tokens == 4) &&
6267 (strcmp(tokens[2], "rule") == 0) &&
6268 (strcmp(tokens[3], "delete") == 0)) {
6269 snprintf(out, out_size, "\n%s\n",
6270 cmd_pipeline_table_rule_delete_help);
6274 if ((n_tokens == 5) &&
6275 (strcmp(tokens[2], "rule") == 0) &&
6276 (strcmp(tokens[3], "delete") == 0) &&
6277 (strcmp(tokens[4], "default") == 0)) {
6278 snprintf(out, out_size, "\n%s\n",
6279 cmd_pipeline_table_rule_delete_default_help);
6283 if ((n_tokens == 4) &&
6284 (strcmp(tokens[2], "rule") == 0) &&
6285 (strcmp(tokens[3], "show") == 0)) {
6286 snprintf(out, out_size, "\n%s\n",
6287 cmd_pipeline_table_rule_show_help);
6291 if ((n_tokens == 5) &&
6292 (strcmp(tokens[2], "rule") == 0) &&
6293 (strcmp(tokens[3], "stats") == 0) &&
6294 (strcmp(tokens[4], "read") == 0)) {
6295 snprintf(out, out_size, "\n%s\n",
6296 cmd_pipeline_table_rule_stats_read_help);
6300 if ((n_tokens == 5) &&
6301 (strcmp(tokens[2], "meter") == 0) &&
6302 (strcmp(tokens[3], "profile") == 0) &&
6303 (strcmp(tokens[4], "add") == 0)) {
6304 snprintf(out, out_size, "\n%s\n",
6305 cmd_pipeline_table_meter_profile_add_help);
6309 if ((n_tokens == 5) &&
6310 (strcmp(tokens[2], "meter") == 0) &&
6311 (strcmp(tokens[3], "profile") == 0) &&
6312 (strcmp(tokens[4], "delete") == 0)) {
6313 snprintf(out, out_size, "\n%s\n",
6314 cmd_pipeline_table_meter_profile_delete_help);
6318 if ((n_tokens == 5) &&
6319 (strcmp(tokens[2], "rule") == 0) &&
6320 (strcmp(tokens[3], "meter") == 0) &&
6321 (strcmp(tokens[4], "read") == 0)) {
6322 snprintf(out, out_size, "\n%s\n",
6323 cmd_pipeline_table_rule_meter_read_help);
6327 if ((n_tokens == 5) &&
6328 (strcmp(tokens[2], "rule") == 0) &&
6329 (strcmp(tokens[3], "ttl") == 0) &&
6330 (strcmp(tokens[4], "read") == 0)) {
6331 snprintf(out, out_size, "\n%s\n",
6332 cmd_pipeline_table_rule_ttl_read_help);
6336 if ((n_tokens == 5) &&
6337 (strcmp(tokens[2], "rule") == 0) &&
6338 (strcmp(tokens[3], "time") == 0) &&
6339 (strcmp(tokens[4], "read") == 0)) {
6340 snprintf(out, out_size, "\n%s\n",
6341 cmd_pipeline_table_rule_time_read_help);
6346 if ((n_tokens == 3) &&
6347 (strcmp(tokens[0], "thread") == 0) &&
6348 (strcmp(tokens[1], "pipeline") == 0)) {
6349 if (strcmp(tokens[2], "enable") == 0) {
6350 snprintf(out, out_size, "\n%s\n",
6351 cmd_thread_pipeline_enable_help);
6355 if (strcmp(tokens[2], "disable") == 0) {
6356 snprintf(out, out_size, "\n%s\n",
6357 cmd_thread_pipeline_disable_help);
6362 snprintf(out, out_size, "Invalid command\n");
6366 cli_process(char *in, char *out, size_t out_size)
6368 char *tokens[CMD_MAX_TOKENS];
6369 uint32_t n_tokens = RTE_DIM(tokens);
6375 status = parse_tokenize_string(in, tokens, &n_tokens);
6377 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
6384 if (strcmp(tokens[0], "help") == 0) {
6385 cmd_help(tokens, n_tokens, out, out_size);
6389 if (strcmp(tokens[0], "mempool") == 0) {
6390 cmd_mempool(tokens, n_tokens, out, out_size);
6394 if (strcmp(tokens[0], "link") == 0) {
6395 if (strcmp(tokens[1], "show") == 0) {
6396 cmd_link_show(tokens, n_tokens, out, out_size);
6400 cmd_link(tokens, n_tokens, out, out_size);
6404 if (strcmp(tokens[0], "swq") == 0) {
6405 cmd_swq(tokens, n_tokens, out, out_size);
6409 if (strcmp(tokens[0], "tmgr") == 0) {
6410 if ((n_tokens >= 3) &&
6411 (strcmp(tokens[1], "subport") == 0) &&
6412 (strcmp(tokens[2], "profile") == 0)) {
6413 cmd_tmgr_subport_profile(tokens, n_tokens,
6418 if ((n_tokens >= 3) &&
6419 (strcmp(tokens[1], "pipe") == 0) &&
6420 (strcmp(tokens[2], "profile") == 0)) {
6421 cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
6425 if ((n_tokens >= 5) &&
6426 (strcmp(tokens[2], "subport") == 0) &&
6427 (strcmp(tokens[4], "profile") == 0)) {
6428 cmd_tmgr_subport(tokens, n_tokens, out, out_size);
6432 if ((n_tokens >= 5) &&
6433 (strcmp(tokens[2], "subport") == 0) &&
6434 (strcmp(tokens[4], "pipe") == 0)) {
6435 cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
6439 cmd_tmgr(tokens, n_tokens, out, out_size);
6443 if (strcmp(tokens[0], "tap") == 0) {
6444 cmd_tap(tokens, n_tokens, out, out_size);
6448 if (strcmp(tokens[0], "kni") == 0) {
6449 cmd_kni(tokens, n_tokens, out, out_size);
6453 if (strcmp(tokens[0], "cryptodev") == 0) {
6454 cmd_cryptodev(tokens, n_tokens, out, out_size);
6458 if (strcmp(tokens[0], "port") == 0) {
6459 cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
6463 if (strcmp(tokens[0], "table") == 0) {
6464 cmd_table_action_profile(tokens, n_tokens, out, out_size);
6468 if (strcmp(tokens[0], "pipeline") == 0) {
6469 if ((n_tokens >= 3) &&
6470 (strcmp(tokens[2], "period") == 0)) {
6471 cmd_pipeline(tokens, n_tokens, out, out_size);
6475 if ((n_tokens >= 5) &&
6476 (strcmp(tokens[2], "port") == 0) &&
6477 (strcmp(tokens[3], "in") == 0) &&
6478 (strcmp(tokens[4], "bsz") == 0)) {
6479 cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
6483 if ((n_tokens >= 5) &&
6484 (strcmp(tokens[2], "port") == 0) &&
6485 (strcmp(tokens[3], "out") == 0) &&
6486 (strcmp(tokens[4], "bsz") == 0)) {
6487 cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
6491 if ((n_tokens >= 4) &&
6492 (strcmp(tokens[2], "table") == 0) &&
6493 (strcmp(tokens[3], "match") == 0)) {
6494 cmd_pipeline_table(tokens, n_tokens, out, out_size);
6498 if ((n_tokens >= 6) &&
6499 (strcmp(tokens[2], "port") == 0) &&
6500 (strcmp(tokens[3], "in") == 0) &&
6501 (strcmp(tokens[5], "table") == 0)) {
6502 cmd_pipeline_port_in_table(tokens, n_tokens,
6507 if ((n_tokens >= 6) &&
6508 (strcmp(tokens[2], "port") == 0) &&
6509 (strcmp(tokens[3], "in") == 0) &&
6510 (strcmp(tokens[5], "stats") == 0)) {
6511 cmd_pipeline_port_in_stats(tokens, n_tokens,
6516 if ((n_tokens >= 6) &&
6517 (strcmp(tokens[2], "port") == 0) &&
6518 (strcmp(tokens[3], "in") == 0) &&
6519 (strcmp(tokens[5], "enable") == 0)) {
6520 cmd_pipeline_port_in_enable(tokens, n_tokens,
6525 if ((n_tokens >= 6) &&
6526 (strcmp(tokens[2], "port") == 0) &&
6527 (strcmp(tokens[3], "in") == 0) &&
6528 (strcmp(tokens[5], "disable") == 0)) {
6529 cmd_pipeline_port_in_disable(tokens, n_tokens,
6534 if ((n_tokens >= 6) &&
6535 (strcmp(tokens[2], "port") == 0) &&
6536 (strcmp(tokens[3], "out") == 0) &&
6537 (strcmp(tokens[5], "stats") == 0)) {
6538 cmd_pipeline_port_out_stats(tokens, n_tokens,
6543 if ((n_tokens >= 5) &&
6544 (strcmp(tokens[2], "table") == 0) &&
6545 (strcmp(tokens[4], "stats") == 0)) {
6546 cmd_pipeline_table_stats(tokens, n_tokens,
6551 if ((n_tokens >= 7) &&
6552 (strcmp(tokens[2], "table") == 0) &&
6553 (strcmp(tokens[4], "rule") == 0) &&
6554 (strcmp(tokens[5], "add") == 0) &&
6555 (strcmp(tokens[6], "match") == 0)) {
6556 if ((n_tokens >= 8) &&
6557 (strcmp(tokens[7], "default") == 0)) {
6558 cmd_pipeline_table_rule_add_default(tokens,
6559 n_tokens, out, out_size);
6563 cmd_pipeline_table_rule_add(tokens, n_tokens,
6568 if ((n_tokens >= 7) &&
6569 (strcmp(tokens[2], "table") == 0) &&
6570 (strcmp(tokens[4], "rule") == 0) &&
6571 (strcmp(tokens[5], "add") == 0) &&
6572 (strcmp(tokens[6], "bulk") == 0)) {
6573 cmd_pipeline_table_rule_add_bulk(tokens,
6574 n_tokens, out, out_size);
6578 if ((n_tokens >= 7) &&
6579 (strcmp(tokens[2], "table") == 0) &&
6580 (strcmp(tokens[4], "rule") == 0) &&
6581 (strcmp(tokens[5], "delete") == 0) &&
6582 (strcmp(tokens[6], "match") == 0)) {
6583 if ((n_tokens >= 8) &&
6584 (strcmp(tokens[7], "default") == 0)) {
6585 cmd_pipeline_table_rule_delete_default(tokens,
6586 n_tokens, out, out_size);
6590 cmd_pipeline_table_rule_delete(tokens, n_tokens,
6595 if ((n_tokens >= 6) &&
6596 (strcmp(tokens[2], "table") == 0) &&
6597 (strcmp(tokens[4], "rule") == 0) &&
6598 (strcmp(tokens[5], "show") == 0)) {
6599 cmd_pipeline_table_rule_show(tokens, n_tokens,
6604 if ((n_tokens >= 7) &&
6605 (strcmp(tokens[2], "table") == 0) &&
6606 (strcmp(tokens[4], "rule") == 0) &&
6607 (strcmp(tokens[5], "read") == 0) &&
6608 (strcmp(tokens[6], "stats") == 0)) {
6609 cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
6614 if ((n_tokens >= 8) &&
6615 (strcmp(tokens[2], "table") == 0) &&
6616 (strcmp(tokens[4], "meter") == 0) &&
6617 (strcmp(tokens[5], "profile") == 0) &&
6618 (strcmp(tokens[7], "add") == 0)) {
6619 cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
6624 if ((n_tokens >= 8) &&
6625 (strcmp(tokens[2], "table") == 0) &&
6626 (strcmp(tokens[4], "meter") == 0) &&
6627 (strcmp(tokens[5], "profile") == 0) &&
6628 (strcmp(tokens[7], "delete") == 0)) {
6629 cmd_pipeline_table_meter_profile_delete(tokens,
6630 n_tokens, out, out_size);
6634 if ((n_tokens >= 7) &&
6635 (strcmp(tokens[2], "table") == 0) &&
6636 (strcmp(tokens[4], "rule") == 0) &&
6637 (strcmp(tokens[5], "read") == 0) &&
6638 (strcmp(tokens[6], "meter") == 0)) {
6639 cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
6644 if ((n_tokens >= 5) &&
6645 (strcmp(tokens[2], "table") == 0) &&
6646 (strcmp(tokens[4], "dscp") == 0)) {
6647 cmd_pipeline_table_dscp(tokens, n_tokens,
6652 if ((n_tokens >= 7) &&
6653 (strcmp(tokens[2], "table") == 0) &&
6654 (strcmp(tokens[4], "rule") == 0) &&
6655 (strcmp(tokens[5], "read") == 0) &&
6656 (strcmp(tokens[6], "ttl") == 0)) {
6657 cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
6662 if ((n_tokens >= 7) &&
6663 (strcmp(tokens[2], "table") == 0) &&
6664 (strcmp(tokens[4], "rule") == 0) &&
6665 (strcmp(tokens[5], "read") == 0) &&
6666 (strcmp(tokens[6], "time") == 0)) {
6667 cmd_pipeline_table_rule_time_read(tokens, n_tokens,
6673 if (strcmp(tokens[0], "thread") == 0) {
6674 if ((n_tokens >= 5) &&
6675 (strcmp(tokens[4], "enable") == 0)) {
6676 cmd_thread_pipeline_enable(tokens, n_tokens,
6681 if ((n_tokens >= 5) &&
6682 (strcmp(tokens[4], "disable") == 0)) {
6683 cmd_thread_pipeline_disable(tokens, n_tokens,
6689 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
6693 cli_script_process(const char *file_name,
6694 size_t msg_in_len_max,
6695 size_t msg_out_len_max)
6697 char *msg_in = NULL, *msg_out = NULL;
6700 /* Check input arguments */
6701 if ((file_name == NULL) ||
6702 (strlen(file_name) == 0) ||
6703 (msg_in_len_max == 0) ||
6704 (msg_out_len_max == 0))
6707 msg_in = malloc(msg_in_len_max + 1);
6708 msg_out = malloc(msg_out_len_max + 1);
6709 if ((msg_in == NULL) ||
6710 (msg_out == NULL)) {
6716 /* Open input file */
6717 f = fopen(file_name, "r");
6726 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
6729 printf("%s", msg_in);
6736 if (strlen(msg_out))
6737 printf("%s", msg_out);
6748 cli_rule_file_process(const char *file_name,
6749 size_t line_len_max,
6750 struct table_rule_list **rule_list,
6752 uint32_t *line_number,
6756 struct table_rule_list *list = NULL;
6759 uint32_t rule_id = 0, line_id = 0;
6762 /* Check input arguments */
6763 if ((file_name == NULL) ||
6764 (strlen(file_name) == 0) ||
6765 (line_len_max == 0) ||
6766 (rule_list == NULL) ||
6767 (n_rules == NULL) ||
6768 (line_number == NULL) ||
6771 goto cli_rule_file_process_free;
6774 /* Memory allocation */
6775 list = malloc(sizeof(struct table_rule_list));
6778 goto cli_rule_file_process_free;
6783 line = malloc(line_len_max + 1);
6786 goto cli_rule_file_process_free;
6790 f = fopen(file_name, "r");
6793 goto cli_rule_file_process_free;
6797 for (line_id = 1, rule_id = 0; ; line_id++) {
6798 char *tokens[CMD_MAX_TOKENS];
6799 struct table_rule *rule = NULL;
6800 uint32_t n_tokens, n_tokens_parsed, t0;
6802 /* Read next line from file. */
6803 if (fgets(line, line_len_max + 1, f) == NULL)
6807 if (is_comment(line))
6811 n_tokens = RTE_DIM(tokens);
6812 status = parse_tokenize_string(line, tokens, &n_tokens);
6815 goto cli_rule_file_process_free;
6823 /* Rule alloc and insert. */
6824 rule = calloc(1, sizeof(struct table_rule));
6827 goto cli_rule_file_process_free;
6830 TAILQ_INSERT_TAIL(list, rule, node);
6833 n_tokens_parsed = parse_match(tokens + t0,
6838 if (n_tokens_parsed == 0) {
6840 goto cli_rule_file_process_free;
6842 t0 += n_tokens_parsed;
6845 n_tokens_parsed = parse_table_action(tokens + t0,
6850 if (n_tokens_parsed == 0) {
6852 goto cli_rule_file_process_free;
6854 t0 += n_tokens_parsed;
6856 /* Line completed. */
6857 if (t0 < n_tokens) {
6859 goto cli_rule_file_process_free;
6862 /* Increment rule count */
6874 *line_number = line_id;
6877 cli_rule_file_process_free:
6878 if (rule_list != NULL)
6881 if (n_rules != NULL)
6884 if (line_number != NULL)
6885 *line_number = line_id;
6889 struct table_rule *rule;
6891 rule = TAILQ_FIRST(list);
6895 TAILQ_REMOVE(list, rule, node);