1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation
10 #include <rte_common.h>
11 #include <rte_ethdev.h>
12 #include <rte_swx_port_ethdev.h>
13 #include <rte_swx_port_ring.h>
14 #include <rte_swx_port_source_sink.h>
15 #include <rte_swx_port_fd.h>
16 #include <rte_swx_pipeline.h>
17 #include <rte_swx_ctl.h>
24 #ifndef CMD_MAX_TOKENS
25 #define CMD_MAX_TOKENS 256
28 #define MSG_OUT_OF_MEMORY "Not enough memory.\n"
29 #define MSG_CMD_UNKNOWN "Unknown command \"%s\".\n"
30 #define MSG_CMD_UNIMPLEM "Command \"%s\" not implemented.\n"
31 #define MSG_ARG_NOT_ENOUGH "Not enough arguments for command \"%s\".\n"
32 #define MSG_ARG_TOO_MANY "Too many arguments for command \"%s\".\n"
33 #define MSG_ARG_MISMATCH "Wrong number of arguments for command \"%s\".\n"
34 #define MSG_ARG_NOT_FOUND "Argument \"%s\" not found.\n"
35 #define MSG_ARG_INVALID "Invalid value for argument \"%s\".\n"
36 #define MSG_FILE_ERR "Error in file \"%s\" at line %u.\n"
37 #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
38 #define MSG_CMD_FAIL "Command \"%s\" failed.\n"
40 #define skip_white_spaces(pos) \
42 __typeof__(pos) _p = (pos); \
43 for ( ; isspace(*_p); _p++) \
49 parser_read_uint64(uint64_t *value, const char *p)
54 p = skip_white_spaces(p);
58 val = strtoul(p, &next, 0);
80 p = skip_white_spaces(p);
89 parser_read_uint32(uint32_t *value, const char *p)
92 int ret = parser_read_uint64(&val, p);
105 parser_read_uint16(uint16_t *value, const char *p)
108 int ret = parser_read_uint64(&val, p);
113 if (val > UINT16_MAX)
120 #define PARSE_DELIMITER " \f\n\r\t\v"
123 parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens)
127 if ((string == NULL) ||
132 for (i = 0; i < *n_tokens; i++) {
133 tokens[i] = strtok_r(string, PARSE_DELIMITER, &string);
134 if (tokens[i] == NULL)
138 if ((i == *n_tokens) && strtok_r(string, PARSE_DELIMITER, &string))
148 if ((strlen(in) && index("!#%;", in[0])) ||
149 (strncmp(in, "//", 2) == 0) ||
150 (strncmp(in, "--", 2) == 0))
156 static const char cmd_mempool_help[] =
157 "mempool <mempool_name>\n"
158 " buffer <buffer_size>\n"
159 " pool <pool_size>\n"
160 " cache <cache_size>\n"
164 cmd_mempool(char **tokens,
170 struct mempool_params p;
172 struct mempool *mempool;
174 if (n_tokens != 10) {
175 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
181 if (strcmp(tokens[2], "buffer") != 0) {
182 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
186 if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
187 snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
191 if (strcmp(tokens[4], "pool") != 0) {
192 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
196 if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
197 snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
201 if (strcmp(tokens[6], "cache") != 0) {
202 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
206 if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
207 snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
211 if (strcmp(tokens[8], "cpu") != 0) {
212 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
216 if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
217 snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
221 mempool = mempool_create(obj, name, &p);
222 if (mempool == NULL) {
223 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
228 static const char cmd_link_help[] =
230 " dev <device_name> | port <port_id>\n"
231 " rxq <n_queues> <queue_size> <mempool_name>\n"
232 " txq <n_queues> <queue_size>\n"
233 " promiscuous on | off\n"
234 " [rss <qid_0> ... <qid_n>]\n";
237 cmd_link(char **tokens,
243 struct link_params p;
244 struct link_params_rss rss;
248 memset(&p, 0, sizeof(p));
250 if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
251 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
256 if (strcmp(tokens[2], "dev") == 0)
257 p.dev_name = tokens[3];
258 else if (strcmp(tokens[2], "port") == 0) {
261 if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
262 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
266 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
270 if (strcmp(tokens[4], "rxq") != 0) {
271 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
275 if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
276 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
279 if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
280 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
284 p.rx.mempool_name = tokens[7];
286 if (strcmp(tokens[8], "txq") != 0) {
287 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
291 if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
292 snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
296 if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
297 snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
301 if (strcmp(tokens[11], "promiscuous") != 0) {
302 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
306 if (strcmp(tokens[12], "on") == 0)
308 else if (strcmp(tokens[12], "off") == 0)
311 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
318 uint32_t queue_id, i;
320 if (strcmp(tokens[13], "rss") != 0) {
321 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
328 for (i = 14; i < n_tokens; i++) {
329 if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
330 snprintf(out, out_size, MSG_ARG_INVALID,
335 rss.queue_id[rss.n_queues] = queue_id;
340 link = link_create(obj, name, &p);
342 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
347 /* Print the link stats and info */
349 print_link_info(struct link *link, char *out, size_t out_size)
351 struct rte_eth_stats stats;
352 struct rte_ether_addr mac_addr;
353 struct rte_eth_link eth_link;
357 memset(&stats, 0, sizeof(stats));
358 rte_eth_stats_get(link->port_id, &stats);
360 ret = rte_eth_macaddr_get(link->port_id, &mac_addr);
362 snprintf(out, out_size, "\n%s: MAC address get failed: %s",
363 link->name, rte_strerror(-ret));
367 ret = rte_eth_link_get(link->port_id, ð_link);
369 snprintf(out, out_size, "\n%s: link get failed: %s",
370 link->name, rte_strerror(-ret));
374 rte_eth_dev_get_mtu(link->port_id, &mtu);
376 snprintf(out, out_size,
378 "%s: flags=<%s> mtu %u\n"
379 "\tether %02X:%02X:%02X:%02X:%02X:%02X rxqueues %u txqueues %u\n"
380 "\tport# %u speed %s\n"
381 "\tRX packets %" PRIu64" bytes %" PRIu64"\n"
382 "\tRX errors %" PRIu64" missed %" PRIu64" no-mbuf %" PRIu64"\n"
383 "\tTX packets %" PRIu64" bytes %" PRIu64"\n"
384 "\tTX errors %" PRIu64"\n",
386 eth_link.link_status == 0 ? "DOWN" : "UP",
388 mac_addr.addr_bytes[0], mac_addr.addr_bytes[1],
389 mac_addr.addr_bytes[2], mac_addr.addr_bytes[3],
390 mac_addr.addr_bytes[4], mac_addr.addr_bytes[5],
394 rte_eth_link_speed_to_str(eth_link.link_speed),
406 * link show [<link_name>]
409 cmd_link_show(char **tokens,
418 if (n_tokens != 2 && n_tokens != 3) {
419 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
424 link = link_next(obj, NULL);
426 while (link != NULL) {
427 out_size = out_size - strlen(out);
428 out = &out[strlen(out)];
430 print_link_info(link, out, out_size);
431 link = link_next(obj, link);
434 out_size = out_size - strlen(out);
435 out = &out[strlen(out)];
437 link_name = tokens[2];
438 link = link_find(obj, link_name);
441 snprintf(out, out_size, MSG_ARG_INVALID,
442 "Link does not exist");
445 print_link_info(link, out, out_size);
449 static const char cmd_ring_help[] =
450 "ring <ring_name> size <size> numa <numa_node>\n";
453 cmd_ring(char **tokens,
459 struct ring_params p;
464 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
470 if (strcmp(tokens[2], "size") != 0) {
471 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
475 if (parser_read_uint32(&p.size, tokens[3]) != 0) {
476 snprintf(out, out_size, MSG_ARG_INVALID, "size");
480 if (strcmp(tokens[4], "numa") != 0) {
481 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa");
485 if (parser_read_uint32(&p.numa_node, tokens[5]) != 0) {
486 snprintf(out, out_size, MSG_ARG_INVALID, "numa_node");
490 ring = ring_create(obj, name, &p);
492 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
497 static const char cmd_tap_help[] =
501 cmd_tap(char **tokens,
511 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
516 tap = tap_create(obj, name);
518 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
523 static const char cmd_pipeline_create_help[] =
524 "pipeline <pipeline_name> create <numa_node>\n";
527 cmd_pipeline_create(char **tokens,
538 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
544 if (parser_read_uint32(&numa_node, tokens[3]) != 0) {
545 snprintf(out, out_size, MSG_ARG_INVALID, "numa_node");
549 p = pipeline_create(obj, name, (int)numa_node);
551 snprintf(out, out_size, "pipeline create error.");
556 static const char cmd_pipeline_port_in_help[] =
557 "pipeline <pipeline_name> port in <port_id>\n"
558 " link <link_name> rxq <queue_id> bsz <burst_size>\n"
559 " ring <ring_name> bsz <burst_size>\n"
560 " | source <mempool_name> <file_name>\n"
561 " | tap <tap_name> mempool <mempool_name> mtu <mtu> bsz <burst_size>\n";
564 cmd_pipeline_port_in(char **tokens,
572 uint32_t port_id = 0, t0;
575 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
579 p = pipeline_find(obj, tokens[1]);
581 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
585 if (strcmp(tokens[2], "port") != 0) {
586 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
590 if (strcmp(tokens[3], "in") != 0) {
591 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
595 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
596 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
602 if (strcmp(tokens[t0], "link") == 0) {
603 struct rte_swx_port_ethdev_reader_params params;
606 if (n_tokens < t0 + 6) {
607 snprintf(out, out_size, MSG_ARG_MISMATCH,
608 "pipeline port in link");
612 link = link_find(obj, tokens[t0 + 1]);
614 snprintf(out, out_size, MSG_ARG_INVALID,
618 params.dev_name = link->dev_name;
620 if (strcmp(tokens[t0 + 2], "rxq") != 0) {
621 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
625 if (parser_read_uint16(¶ms.queue_id, tokens[t0 + 3]) != 0) {
626 snprintf(out, out_size, MSG_ARG_INVALID,
631 if (strcmp(tokens[t0 + 4], "bsz") != 0) {
632 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
636 if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 5])) {
637 snprintf(out, out_size, MSG_ARG_INVALID,
644 status = rte_swx_pipeline_port_in_config(p->p,
648 } else if (strcmp(tokens[t0], "ring") == 0) {
649 struct rte_swx_port_ring_reader_params params;
652 if (n_tokens < t0 + 4) {
653 snprintf(out, out_size, MSG_ARG_MISMATCH,
654 "pipeline port in ring");
658 ring = ring_find(obj, tokens[t0 + 1]);
660 snprintf(out, out_size, MSG_ARG_INVALID,
664 params.name = ring->name;
666 if (strcmp(tokens[t0 + 2], "bsz") != 0) {
667 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
671 if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) {
672 snprintf(out, out_size, MSG_ARG_INVALID,
679 status = rte_swx_pipeline_port_in_config(p->p,
683 } else if (strcmp(tokens[t0], "source") == 0) {
684 struct rte_swx_port_source_params params;
687 if (n_tokens < t0 + 3) {
688 snprintf(out, out_size, MSG_ARG_MISMATCH,
689 "pipeline port in source");
693 mp = mempool_find(obj, tokens[t0 + 1]);
695 snprintf(out, out_size, MSG_ARG_INVALID,
701 params.file_name = tokens[t0 + 2];
705 status = rte_swx_pipeline_port_in_config(p->p,
709 } else if (strcmp(tokens[t0], "tap") == 0) {
710 struct rte_swx_port_fd_reader_params params;
714 if (n_tokens < t0 + 8) {
715 snprintf(out, out_size, MSG_ARG_MISMATCH,
716 "pipeline port in tap");
720 tap = tap_find(obj, tokens[t0 + 1]);
722 snprintf(out, out_size, MSG_ARG_INVALID,
728 if (strcmp(tokens[t0 + 2], "mempool") != 0) {
729 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
734 mp = mempool_find(obj, tokens[t0 + 3]);
736 snprintf(out, out_size, MSG_ARG_INVALID,
740 params.mempool = mp->m;
742 if (strcmp(tokens[t0 + 4], "mtu") != 0) {
743 snprintf(out, out_size, MSG_ARG_NOT_FOUND,
748 if (parser_read_uint32(¶ms.mtu, tokens[t0 + 5]) != 0) {
749 snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
753 if (strcmp(tokens[t0 + 6], "bsz") != 0) {
754 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
758 if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 7])) {
759 snprintf(out, out_size, MSG_ARG_INVALID,
766 status = rte_swx_pipeline_port_in_config(p->p,
772 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
777 snprintf(out, out_size, "port in error.");
781 if (n_tokens != t0) {
782 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
787 static const char cmd_pipeline_port_out_help[] =
788 "pipeline <pipeline_name> port out <port_id>\n"
789 " link <link_name> txq <txq_id> bsz <burst_size>\n"
790 " ring <ring_name> bsz <burst_size>\n"
791 " | sink <file_name> | none\n"
792 " | tap <tap_name> bsz <burst_size>\n";
795 cmd_pipeline_port_out(char **tokens,
803 uint32_t port_id = 0, t0;
806 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
810 p = pipeline_find(obj, tokens[1]);
812 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
816 if (strcmp(tokens[2], "port") != 0) {
817 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
821 if (strcmp(tokens[3], "out") != 0) {
822 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
826 if (parser_read_uint32(&port_id, tokens[4]) != 0) {
827 snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
833 if (strcmp(tokens[t0], "link") == 0) {
834 struct rte_swx_port_ethdev_writer_params params;
837 if (n_tokens < t0 + 6) {
838 snprintf(out, out_size, MSG_ARG_MISMATCH,
839 "pipeline port out link");
843 link = link_find(obj, tokens[t0 + 1]);
845 snprintf(out, out_size, MSG_ARG_INVALID,
849 params.dev_name = link->dev_name;
851 if (strcmp(tokens[t0 + 2], "txq") != 0) {
852 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
856 if (parser_read_uint16(¶ms.queue_id, tokens[t0 + 3]) != 0) {
857 snprintf(out, out_size, MSG_ARG_INVALID,
862 if (strcmp(tokens[t0 + 4], "bsz") != 0) {
863 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
867 if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 5])) {
868 snprintf(out, out_size, MSG_ARG_INVALID,
875 status = rte_swx_pipeline_port_out_config(p->p,
879 } else if (strcmp(tokens[t0], "ring") == 0) {
880 struct rte_swx_port_ring_writer_params params;
883 if (n_tokens < t0 + 4) {
884 snprintf(out, out_size, MSG_ARG_MISMATCH,
885 "pipeline port out link");
889 ring = ring_find(obj, tokens[t0 + 1]);
891 snprintf(out, out_size, MSG_ARG_INVALID,
895 params.name = ring->name;
897 if (strcmp(tokens[t0 + 2], "bsz") != 0) {
898 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
902 if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) {
903 snprintf(out, out_size, MSG_ARG_INVALID,
910 status = rte_swx_pipeline_port_out_config(p->p,
914 } else if (strcmp(tokens[t0], "sink") == 0) {
915 struct rte_swx_port_sink_params params;
917 params.file_name = strcmp(tokens[t0 + 1], "none") ?
918 tokens[t0 + 1] : NULL;
922 status = rte_swx_pipeline_port_out_config(p->p,
926 } else if (strcmp(tokens[t0], "tap") == 0) {
927 struct rte_swx_port_fd_writer_params params;
930 if (n_tokens < t0 + 4) {
931 snprintf(out, out_size, MSG_ARG_MISMATCH,
932 "pipeline port out tap");
936 tap = tap_find(obj, tokens[t0 + 1]);
938 snprintf(out, out_size, MSG_ARG_INVALID,
944 if (strcmp(tokens[t0 + 2], "bsz") != 0) {
945 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
949 if (parser_read_uint32(¶ms.burst_size, tokens[t0 + 3])) {
950 snprintf(out, out_size, MSG_ARG_INVALID,
957 status = rte_swx_pipeline_port_out_config(p->p,
962 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
967 snprintf(out, out_size, "port out error.");
971 if (n_tokens != t0) {
972 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
977 static const char cmd_pipeline_build_help[] =
978 "pipeline <pipeline_name> build <spec_file>\n";
981 cmd_pipeline_build(char **tokens,
987 struct pipeline *p = NULL;
994 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
998 p = pipeline_find(obj, tokens[1]);
1000 snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1004 spec = fopen(tokens[3], "r");
1006 snprintf(out, out_size, "Cannot open file %s.\n", tokens[3]);
1010 status = rte_swx_pipeline_build_from_spec(p->p,
1016 snprintf(out, out_size, "Error %d at line %u: %s\n.",
1017 status, err_line, err_msg);
1021 p->ctl = rte_swx_ctl_pipeline_create(p->p);
1023 snprintf(out, out_size, "Pipeline control create failed.");
1024 rte_swx_pipeline_free(p->p);
1030 table_entry_free(struct rte_swx_table_entry *entry)
1036 free(entry->key_mask);
1037 free(entry->action_data);
1041 static const char cmd_pipeline_table_update_help[] =
1042 "pipeline <pipeline_name> table <table_name> update <file_name_add> "
1043 "<file_name_delete> <file_name_default>";
1046 cmd_pipeline_table_update(char **tokens,
1053 char *pipeline_name, *table_name, *line = NULL;
1054 char *file_name_add, *file_name_delete, *file_name_default;
1055 FILE *file_add = NULL, *file_delete = NULL, *file_default = NULL;
1059 if (n_tokens != 8) {
1060 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1064 pipeline_name = tokens[1];
1065 p = pipeline_find(obj, pipeline_name);
1066 if (!p || !p->ctl) {
1067 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1071 if (strcmp(tokens[2], "table") != 0) {
1072 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
1076 table_name = tokens[3];
1078 if (strcmp(tokens[4], "update") != 0) {
1079 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "update");
1083 file_name_add = tokens[5];
1084 file_name_delete = tokens[6];
1085 file_name_default = tokens[7];
1088 if (strcmp(file_name_add, "none")) {
1089 file_add = fopen(file_name_add, "r");
1091 snprintf(out, out_size, "Cannot open file %s",
1097 if (strcmp(file_name_delete, "none")) {
1098 file_delete = fopen(file_name_delete, "r");
1100 snprintf(out, out_size, "Cannot open file %s",
1106 if (strcmp(file_name_default, "none")) {
1107 file_default = fopen(file_name_default, "r");
1108 if (!file_default) {
1109 snprintf(out, out_size, "Cannot open file %s",
1115 if (!file_add && !file_delete && !file_default) {
1116 snprintf(out, out_size, "Nothing to be done.");
1120 /* Buffer allocation. */
1121 line = malloc(2048);
1123 snprintf(out, out_size, MSG_OUT_OF_MEMORY);
1129 for (line_id = 1; ; line_id++) {
1130 struct rte_swx_table_entry *entry;
1131 int is_blank_or_comment;
1133 if (fgets(line, 2048, file_add) == NULL)
1136 entry = rte_swx_ctl_pipeline_table_entry_read(p->ctl,
1139 &is_blank_or_comment);
1141 if (is_blank_or_comment)
1144 snprintf(out, out_size, MSG_FILE_ERR,
1145 file_name_add, line_id);
1149 status = rte_swx_ctl_pipeline_table_entry_add(p->ctl,
1152 table_entry_free(entry);
1154 snprintf(out, out_size,
1155 "Invalid entry in file %s at line %u",
1156 file_name_add, line_id);
1164 for (line_id = 1; ; line_id++) {
1165 struct rte_swx_table_entry *entry;
1166 int is_blank_or_comment;
1168 if (fgets(line, 2048, file_delete) == NULL)
1171 entry = rte_swx_ctl_pipeline_table_entry_read(p->ctl,
1174 &is_blank_or_comment);
1176 if (is_blank_or_comment)
1179 snprintf(out, out_size, MSG_FILE_ERR,
1180 file_name_delete, line_id);
1184 status = rte_swx_ctl_pipeline_table_entry_delete(p->ctl,
1187 table_entry_free(entry);
1189 snprintf(out, out_size,
1190 "Invalid entry in file %s at line %u",
1191 file_name_delete, line_id);
1198 for (line_id = 1; ; line_id++) {
1199 struct rte_swx_table_entry *entry;
1200 int is_blank_or_comment;
1202 if (fgets(line, 2048, file_default) == NULL)
1205 entry = rte_swx_ctl_pipeline_table_entry_read(p->ctl,
1208 &is_blank_or_comment);
1210 if (is_blank_or_comment)
1213 snprintf(out, out_size, MSG_FILE_ERR,
1214 file_name_default, line_id);
1218 status = rte_swx_ctl_pipeline_table_default_entry_add(p->ctl,
1221 table_entry_free(entry);
1223 snprintf(out, out_size,
1224 "Invalid entry in file %s at line %u",
1225 file_name_default, line_id);
1230 status = rte_swx_ctl_pipeline_commit(p->ctl, 1);
1232 snprintf(out, out_size, "Commit failed.");
1237 rte_swx_ctl_pipeline_table_fprintf(stdout, p->ctl, table_name);
1243 fclose(file_delete);
1245 fclose(file_default);
1249 rte_swx_ctl_pipeline_abort(p->ctl);
1254 fclose(file_delete);
1256 fclose(file_default);
1259 static const char cmd_pipeline_regrd_help[] =
1260 "pipeline <pipeline_name> regrd <register_array_name> <index>\n";
1263 cmd_pipeline_regrd(char **tokens,
1275 if (n_tokens != 5) {
1276 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1280 p = pipeline_find(obj, tokens[1]);
1281 if (!p || !p->ctl) {
1282 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1286 if (strcmp(tokens[2], "regrd")) {
1287 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd");
1293 if (parser_read_uint32(&idx, tokens[4])) {
1294 snprintf(out, out_size, MSG_ARG_INVALID, "index");
1298 status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value);
1300 snprintf(out, out_size, "Command failed.\n");
1304 snprintf(out, out_size, "0x%" PRIx64 "\n", value);
1307 static const char cmd_pipeline_regwr_help[] =
1308 "pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
1311 cmd_pipeline_regwr(char **tokens,
1323 if (n_tokens != 6) {
1324 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1328 p = pipeline_find(obj, tokens[1]);
1329 if (!p || !p->ctl) {
1330 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1334 if (strcmp(tokens[2], "regwr")) {
1335 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr");
1341 if (parser_read_uint32(&idx, tokens[4])) {
1342 snprintf(out, out_size, MSG_ARG_INVALID, "index");
1346 if (parser_read_uint64(&value, tokens[5])) {
1347 snprintf(out, out_size, MSG_ARG_INVALID, "value");
1351 status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value);
1353 snprintf(out, out_size, "Command failed.\n");
1358 static const char cmd_pipeline_meter_profile_add_help[] =
1359 "pipeline <pipeline_name> meter profile <profile_name> add "
1360 "cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
1363 cmd_pipeline_meter_profile_add(char **tokens,
1369 struct rte_meter_trtcm_params params;
1371 const char *profile_name;
1374 if (n_tokens != 14) {
1375 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1379 p = pipeline_find(obj, tokens[1]);
1380 if (!p || !p->ctl) {
1381 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1385 if (strcmp(tokens[2], "meter")) {
1386 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
1390 if (strcmp(tokens[3], "profile")) {
1391 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1395 profile_name = tokens[4];
1397 if (strcmp(tokens[5], "add")) {
1398 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
1402 if (strcmp(tokens[6], "cir")) {
1403 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
1407 if (parser_read_uint64(¶ms.cir, tokens[7])) {
1408 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
1412 if (strcmp(tokens[8], "pir")) {
1413 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
1417 if (parser_read_uint64(¶ms.pir, tokens[9])) {
1418 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
1422 if (strcmp(tokens[10], "cbs")) {
1423 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
1427 if (parser_read_uint64(¶ms.cbs, tokens[11])) {
1428 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
1432 if (strcmp(tokens[12], "pbs")) {
1433 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
1437 if (parser_read_uint64(¶ms.pbs, tokens[13])) {
1438 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
1442 status = rte_swx_ctl_meter_profile_add(p->p, profile_name, ¶ms);
1444 snprintf(out, out_size, "Command failed.\n");
1449 static const char cmd_pipeline_meter_profile_delete_help[] =
1450 "pipeline <pipeline_name> meter profile <profile_name> delete\n";
1453 cmd_pipeline_meter_profile_delete(char **tokens,
1460 const char *profile_name;
1463 if (n_tokens != 6) {
1464 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1468 p = pipeline_find(obj, tokens[1]);
1469 if (!p || !p->ctl) {
1470 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1474 if (strcmp(tokens[2], "meter")) {
1475 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
1479 if (strcmp(tokens[3], "profile")) {
1480 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1484 profile_name = tokens[4];
1486 if (strcmp(tokens[5], "delete")) {
1487 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
1491 status = rte_swx_ctl_meter_profile_delete(p->p, profile_name);
1493 snprintf(out, out_size, "Command failed.\n");
1498 static const char cmd_pipeline_meter_reset_help[] =
1499 "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
1503 cmd_pipeline_meter_reset(char **tokens,
1511 uint32_t idx0, idx1;
1513 if (n_tokens != 9) {
1514 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1518 p = pipeline_find(obj, tokens[1]);
1519 if (!p || !p->ctl) {
1520 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1524 if (strcmp(tokens[2], "meter")) {
1525 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
1531 if (strcmp(tokens[4], "from")) {
1532 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
1536 if (parser_read_uint32(&idx0, tokens[5])) {
1537 snprintf(out, out_size, MSG_ARG_INVALID, "index0");
1541 if (strcmp(tokens[6], "to")) {
1542 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
1546 if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
1547 snprintf(out, out_size, MSG_ARG_INVALID, "index1");
1551 if (strcmp(tokens[8], "reset")) {
1552 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
1556 for ( ; idx0 <= idx1; idx0++) {
1559 status = rte_swx_ctl_meter_reset(p->p, name, idx0);
1561 snprintf(out, out_size, "Command failed for index %u.\n", idx0);
1567 static const char cmd_pipeline_meter_set_help[] =
1568 "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
1569 "set profile <profile_name>\n";
1572 cmd_pipeline_meter_set(char **tokens,
1579 const char *name, *profile_name;
1580 uint32_t idx0, idx1;
1582 if (n_tokens != 11) {
1583 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1587 p = pipeline_find(obj, tokens[1]);
1588 if (!p || !p->ctl) {
1589 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1593 if (strcmp(tokens[2], "meter")) {
1594 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
1600 if (strcmp(tokens[4], "from")) {
1601 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
1605 if (parser_read_uint32(&idx0, tokens[5])) {
1606 snprintf(out, out_size, MSG_ARG_INVALID, "index0");
1610 if (strcmp(tokens[6], "to")) {
1611 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
1615 if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
1616 snprintf(out, out_size, MSG_ARG_INVALID, "index1");
1620 if (strcmp(tokens[8], "set")) {
1621 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
1625 if (strcmp(tokens[9], "profile")) {
1626 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
1630 profile_name = tokens[10];
1632 for ( ; idx0 <= idx1; idx0++) {
1635 status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name);
1637 snprintf(out, out_size, "Command failed for index %u.\n", idx0);
1643 static const char cmd_pipeline_meter_stats_help[] =
1644 "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
1648 cmd_pipeline_meter_stats(char **tokens,
1654 struct rte_swx_ctl_meter_stats stats;
1657 uint32_t idx0, idx1;
1659 if (n_tokens != 9) {
1660 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1664 p = pipeline_find(obj, tokens[1]);
1665 if (!p || !p->ctl) {
1666 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1670 if (strcmp(tokens[2], "meter")) {
1671 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
1677 if (strcmp(tokens[4], "from")) {
1678 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
1682 if (parser_read_uint32(&idx0, tokens[5])) {
1683 snprintf(out, out_size, MSG_ARG_INVALID, "index0");
1687 if (strcmp(tokens[6], "to")) {
1688 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
1692 if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
1693 snprintf(out, out_size, MSG_ARG_INVALID, "index1");
1697 if (strcmp(tokens[8], "stats")) {
1698 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1703 snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
1705 "----------------", "----------------", "----------------",
1706 "----------------", "----------------", "----------------");
1707 out_size -= strlen(out);
1710 snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n",
1712 "GREEN (packets)", "YELLOW (packets)", "RED (packets)",
1713 "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)");
1714 out_size -= strlen(out);
1717 snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
1719 "----------------", "----------------", "----------------",
1720 "----------------", "----------------", "----------------");
1721 out_size -= strlen(out);
1725 for ( ; idx0 <= idx1; idx0++) {
1728 status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats);
1730 snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
1731 out_size -= strlen(out);
1736 snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
1737 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
1739 stats.n_pkts[RTE_COLOR_GREEN],
1740 stats.n_pkts[RTE_COLOR_YELLOW],
1741 stats.n_pkts[RTE_COLOR_RED],
1742 stats.n_bytes[RTE_COLOR_GREEN],
1743 stats.n_bytes[RTE_COLOR_YELLOW],
1744 stats.n_bytes[RTE_COLOR_RED]);
1745 out_size -= strlen(out);
1750 static const char cmd_pipeline_stats_help[] =
1751 "pipeline <pipeline_name> stats\n";
1754 cmd_pipeline_stats(char **tokens,
1760 struct rte_swx_ctl_pipeline_info info;
1765 if (n_tokens != 3) {
1766 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1770 p = pipeline_find(obj, tokens[1]);
1771 if (!p || !p->ctl) {
1772 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1776 if (strcmp(tokens[2], "stats")) {
1777 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
1781 status = rte_swx_ctl_pipeline_info_get(p->p, &info);
1783 snprintf(out, out_size, "Pipeline info get error.");
1787 snprintf(out, out_size, "Input ports:\n");
1788 out_size -= strlen(out);
1791 for (i = 0; i < info.n_ports_in; i++) {
1792 struct rte_swx_port_in_stats stats;
1794 rte_swx_ctl_pipeline_port_in_stats_read(p->p, i, &stats);
1796 snprintf(out, out_size, "\tPort %u:"
1799 " empty %" PRIu64 "\n",
1800 i, stats.n_pkts, stats.n_bytes, stats.n_empty);
1801 out_size -= strlen(out);
1805 snprintf(out, out_size, "Output ports:\n");
1806 out_size -= strlen(out);
1809 for (i = 0; i < info.n_ports_out; i++) {
1810 struct rte_swx_port_out_stats stats;
1812 rte_swx_ctl_pipeline_port_out_stats_read(p->p, i, &stats);
1814 snprintf(out, out_size, "\tPort %u:"
1816 " bytes %" PRIu64 "\n",
1817 i, stats.n_pkts, stats.n_bytes);
1818 out_size -= strlen(out);
1823 static const char cmd_thread_pipeline_enable_help[] =
1824 "thread <thread_id> pipeline <pipeline_name> enable\n";
1827 cmd_thread_pipeline_enable(char **tokens,
1833 char *pipeline_name;
1838 if (n_tokens != 5) {
1839 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1843 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
1844 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
1848 if (strcmp(tokens[2], "pipeline") != 0) {
1849 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
1853 pipeline_name = tokens[3];
1854 p = pipeline_find(obj, pipeline_name);
1855 if (!p || !p->ctl) {
1856 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1860 if (strcmp(tokens[4], "enable") != 0) {
1861 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
1865 status = thread_pipeline_enable(thread_id, obj, pipeline_name);
1867 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
1872 static const char cmd_thread_pipeline_disable_help[] =
1873 "thread <thread_id> pipeline <pipeline_name> disable\n";
1876 cmd_thread_pipeline_disable(char **tokens,
1883 char *pipeline_name;
1887 if (n_tokens != 5) {
1888 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1892 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
1893 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
1897 if (strcmp(tokens[2], "pipeline") != 0) {
1898 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
1902 pipeline_name = tokens[3];
1903 p = pipeline_find(obj, pipeline_name);
1904 if (!p || !p->ctl) {
1905 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1909 if (strcmp(tokens[4], "disable") != 0) {
1910 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
1914 status = thread_pipeline_disable(thread_id, obj, pipeline_name);
1916 snprintf(out, out_size, MSG_CMD_FAIL,
1917 "thread pipeline disable");
1923 cmd_help(char **tokens,
1927 void *arg __rte_unused)
1932 if (n_tokens == 0) {
1933 snprintf(out, out_size,
1934 "Type 'help <command>' for command details.\n\n"
1935 "List of commands:\n"
1939 "\tpipeline create\n"
1940 "\tpipeline port in\n"
1941 "\tpipeline port out\n"
1942 "\tpipeline build\n"
1943 "\tpipeline table update\n"
1944 "\tpipeline regrd\n"
1945 "\tpipeline regwr\n"
1946 "\tpipeline meter profile add\n"
1947 "\tpipeline meter profile delete\n"
1948 "\tpipeline meter reset\n"
1949 "\tpipeline meter set\n"
1950 "\tpipeline meter stats\n"
1951 "\tpipeline stats\n"
1952 "\tthread pipeline enable\n"
1953 "\tthread pipeline disable\n\n");
1957 if (strcmp(tokens[0], "mempool") == 0) {
1958 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
1962 if (strcmp(tokens[0], "link") == 0) {
1963 snprintf(out, out_size, "\n%s\n", cmd_link_help);
1967 if (strcmp(tokens[0], "ring") == 0) {
1968 snprintf(out, out_size, "\n%s\n", cmd_ring_help);
1972 if (strcmp(tokens[0], "tap") == 0) {
1973 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
1977 if ((strcmp(tokens[0], "pipeline") == 0) &&
1978 (n_tokens == 2) && (strcmp(tokens[1], "create") == 0)) {
1979 snprintf(out, out_size, "\n%s\n", cmd_pipeline_create_help);
1983 if ((strcmp(tokens[0], "pipeline") == 0) &&
1984 (n_tokens == 3) && (strcmp(tokens[1], "port") == 0)) {
1985 if (strcmp(tokens[2], "in") == 0) {
1986 snprintf(out, out_size, "\n%s\n",
1987 cmd_pipeline_port_in_help);
1991 if (strcmp(tokens[2], "out") == 0) {
1992 snprintf(out, out_size, "\n%s\n",
1993 cmd_pipeline_port_out_help);
1998 if ((strcmp(tokens[0], "pipeline") == 0) &&
1999 (n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) {
2000 snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help);
2004 if ((strcmp(tokens[0], "pipeline") == 0) &&
2006 (strcmp(tokens[1], "table") == 0) &&
2007 (strcmp(tokens[2], "update") == 0)) {
2008 snprintf(out, out_size, "\n%s\n",
2009 cmd_pipeline_table_update_help);
2013 if ((strcmp(tokens[0], "pipeline") == 0) &&
2014 (n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) {
2015 snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help);
2019 if ((strcmp(tokens[0], "pipeline") == 0) &&
2020 (n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) {
2021 snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help);
2025 if (!strcmp(tokens[0], "pipeline") &&
2026 (n_tokens == 4) && !strcmp(tokens[1], "meter")
2027 && !strcmp(tokens[2], "profile")
2028 && !strcmp(tokens[3], "add")) {
2029 snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help);
2033 if (!strcmp(tokens[0], "pipeline") &&
2034 (n_tokens == 4) && !strcmp(tokens[1], "meter")
2035 && !strcmp(tokens[2], "profile")
2036 && !strcmp(tokens[3], "delete")) {
2037 snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help);
2041 if (!strcmp(tokens[0], "pipeline") &&
2042 (n_tokens == 3) && !strcmp(tokens[1], "meter")
2043 && !strcmp(tokens[2], "reset")) {
2044 snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help);
2048 if (!strcmp(tokens[0], "pipeline") &&
2049 (n_tokens == 3) && !strcmp(tokens[1], "meter")
2050 && !strcmp(tokens[2], "set")) {
2051 snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help);
2055 if (!strcmp(tokens[0], "pipeline") &&
2056 (n_tokens == 3) && !strcmp(tokens[1], "meter")
2057 && !strcmp(tokens[2], "stats")) {
2058 snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help);
2062 if ((strcmp(tokens[0], "pipeline") == 0) &&
2063 (n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) {
2064 snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help);
2068 if ((n_tokens == 3) &&
2069 (strcmp(tokens[0], "thread") == 0) &&
2070 (strcmp(tokens[1], "pipeline") == 0)) {
2071 if (strcmp(tokens[2], "enable") == 0) {
2072 snprintf(out, out_size, "\n%s\n",
2073 cmd_thread_pipeline_enable_help);
2077 if (strcmp(tokens[2], "disable") == 0) {
2078 snprintf(out, out_size, "\n%s\n",
2079 cmd_thread_pipeline_disable_help);
2084 snprintf(out, out_size, "Invalid command\n");
2088 cli_process(char *in, char *out, size_t out_size, void *obj)
2090 char *tokens[CMD_MAX_TOKENS];
2091 uint32_t n_tokens = RTE_DIM(tokens);
2097 status = parse_tokenize_string(in, tokens, &n_tokens);
2099 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
2106 if (strcmp(tokens[0], "help") == 0) {
2107 cmd_help(tokens, n_tokens, out, out_size, obj);
2111 if (strcmp(tokens[0], "mempool") == 0) {
2112 cmd_mempool(tokens, n_tokens, out, out_size, obj);
2116 if (strcmp(tokens[0], "link") == 0) {
2117 if ((n_tokens >= 2) && (strcmp(tokens[1], "show") == 0)) {
2118 cmd_link_show(tokens, n_tokens, out, out_size, obj);
2122 cmd_link(tokens, n_tokens, out, out_size, obj);
2126 if (strcmp(tokens[0], "ring") == 0) {
2127 cmd_ring(tokens, n_tokens, out, out_size, obj);
2131 if (strcmp(tokens[0], "tap") == 0) {
2132 cmd_tap(tokens, n_tokens, out, out_size, obj);
2136 if (strcmp(tokens[0], "pipeline") == 0) {
2137 if ((n_tokens >= 3) &&
2138 (strcmp(tokens[2], "create") == 0)) {
2139 cmd_pipeline_create(tokens, n_tokens, out, out_size,
2144 if ((n_tokens >= 4) &&
2145 (strcmp(tokens[2], "port") == 0) &&
2146 (strcmp(tokens[3], "in") == 0)) {
2147 cmd_pipeline_port_in(tokens, n_tokens, out, out_size,
2152 if ((n_tokens >= 4) &&
2153 (strcmp(tokens[2], "port") == 0) &&
2154 (strcmp(tokens[3], "out") == 0)) {
2155 cmd_pipeline_port_out(tokens, n_tokens, out, out_size,
2160 if ((n_tokens >= 3) &&
2161 (strcmp(tokens[2], "build") == 0)) {
2162 cmd_pipeline_build(tokens, n_tokens, out, out_size,
2167 if ((n_tokens >= 3) &&
2168 (strcmp(tokens[2], "table") == 0)) {
2169 cmd_pipeline_table_update(tokens, n_tokens, out,
2174 if ((n_tokens >= 3) &&
2175 (strcmp(tokens[2], "regrd") == 0)) {
2176 cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj);
2180 if ((n_tokens >= 3) &&
2181 (strcmp(tokens[2], "regwr") == 0)) {
2182 cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj);
2186 if ((n_tokens >= 6) &&
2187 (strcmp(tokens[2], "meter") == 0) &&
2188 (strcmp(tokens[3], "profile") == 0) &&
2189 (strcmp(tokens[5], "add") == 0)) {
2190 cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj);
2194 if ((n_tokens >= 6) &&
2195 (strcmp(tokens[2], "meter") == 0) &&
2196 (strcmp(tokens[3], "profile") == 0) &&
2197 (strcmp(tokens[5], "delete") == 0)) {
2198 cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj);
2202 if ((n_tokens >= 9) &&
2203 (strcmp(tokens[2], "meter") == 0) &&
2204 (strcmp(tokens[8], "reset") == 0)) {
2205 cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj);
2209 if ((n_tokens >= 9) &&
2210 (strcmp(tokens[2], "meter") == 0) &&
2211 (strcmp(tokens[8], "set") == 0)) {
2212 cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj);
2216 if ((n_tokens >= 9) &&
2217 (strcmp(tokens[2], "meter") == 0) &&
2218 (strcmp(tokens[8], "stats") == 0)) {
2219 cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj);
2223 if ((n_tokens >= 3) &&
2224 (strcmp(tokens[2], "stats") == 0)) {
2225 cmd_pipeline_stats(tokens, n_tokens, out, out_size,
2231 if (strcmp(tokens[0], "thread") == 0) {
2232 if ((n_tokens >= 5) &&
2233 (strcmp(tokens[4], "enable") == 0)) {
2234 cmd_thread_pipeline_enable(tokens, n_tokens,
2235 out, out_size, obj);
2239 if ((n_tokens >= 5) &&
2240 (strcmp(tokens[4], "disable") == 0)) {
2241 cmd_thread_pipeline_disable(tokens, n_tokens,
2242 out, out_size, obj);
2247 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
2251 cli_script_process(const char *file_name,
2252 size_t msg_in_len_max,
2253 size_t msg_out_len_max,
2256 char *msg_in = NULL, *msg_out = NULL;
2259 /* Check input arguments */
2260 if ((file_name == NULL) ||
2261 (strlen(file_name) == 0) ||
2262 (msg_in_len_max == 0) ||
2263 (msg_out_len_max == 0))
2266 msg_in = malloc(msg_in_len_max + 1);
2267 msg_out = malloc(msg_out_len_max + 1);
2268 if ((msg_in == NULL) ||
2269 (msg_out == NULL)) {
2275 /* Open input file */
2276 f = fopen(file_name, "r");
2285 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
2288 printf("%s", msg_in);
2296 if (strlen(msg_out))
2297 printf("%s", msg_out);