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 #ifndef MAX_LINE_SIZE
1042 #define MAX_LINE_SIZE 2048
1046 pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p,
1047 const char *table_name,
1049 uint32_t *file_line_number)
1052 uint32_t line_id = 0;
1055 /* Buffer allocation. */
1056 line = malloc(MAX_LINE_SIZE);
1061 for (line_id = 1; ; line_id++) {
1062 struct rte_swx_table_entry *entry;
1063 int is_blank_or_comment;
1065 if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1068 entry = rte_swx_ctl_pipeline_table_entry_read(p,
1071 &is_blank_or_comment);
1073 if (is_blank_or_comment)
1080 status = rte_swx_ctl_pipeline_table_entry_add(p,
1083 table_entry_free(entry);
1090 *file_line_number = line_id;
1094 static const char cmd_pipeline_table_add_help[] =
1095 "pipeline <pipeline_name> table <table_name> add <file_name>\n";
1098 cmd_pipeline_table_add(char **tokens,
1105 char *pipeline_name, *table_name, *file_name;
1107 uint32_t file_line_number = 0;
1110 if (n_tokens != 6) {
1111 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1115 pipeline_name = tokens[1];
1116 p = pipeline_find(obj, pipeline_name);
1117 if (!p || !p->ctl) {
1118 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1122 table_name = tokens[3];
1124 file_name = tokens[5];
1125 file = fopen(file_name, "r");
1127 snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1131 status = pipeline_table_entries_add(p->ctl,
1136 snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1144 pipeline_table_entries_delete(struct rte_swx_ctl_pipeline *p,
1145 const char *table_name,
1147 uint32_t *file_line_number)
1150 uint32_t line_id = 0;
1153 /* Buffer allocation. */
1154 line = malloc(MAX_LINE_SIZE);
1159 for (line_id = 1; ; line_id++) {
1160 struct rte_swx_table_entry *entry;
1161 int is_blank_or_comment;
1163 if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1166 entry = rte_swx_ctl_pipeline_table_entry_read(p,
1169 &is_blank_or_comment);
1171 if (is_blank_or_comment)
1178 status = rte_swx_ctl_pipeline_table_entry_delete(p,
1181 table_entry_free(entry);
1187 *file_line_number = line_id;
1192 static const char cmd_pipeline_table_delete_help[] =
1193 "pipeline <pipeline_name> table <table_name> delete <file_name>\n";
1196 cmd_pipeline_table_delete(char **tokens,
1203 char *pipeline_name, *table_name, *file_name;
1205 uint32_t file_line_number = 0;
1208 if (n_tokens != 6) {
1209 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1213 pipeline_name = tokens[1];
1214 p = pipeline_find(obj, pipeline_name);
1215 if (!p || !p->ctl) {
1216 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1220 table_name = tokens[3];
1222 file_name = tokens[5];
1223 file = fopen(file_name, "r");
1225 snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1229 status = pipeline_table_entries_delete(p->ctl,
1234 snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1242 pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *p,
1243 const char *table_name,
1245 uint32_t *file_line_number)
1248 uint32_t line_id = 0;
1251 /* Buffer allocation. */
1252 line = malloc(MAX_LINE_SIZE);
1257 for (line_id = 1; ; line_id++) {
1258 struct rte_swx_table_entry *entry;
1259 int is_blank_or_comment;
1261 if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1264 entry = rte_swx_ctl_pipeline_table_entry_read(p,
1267 &is_blank_or_comment);
1269 if (is_blank_or_comment)
1276 status = rte_swx_ctl_pipeline_table_default_entry_add(p,
1279 table_entry_free(entry);
1285 *file_line_number = line_id;
1290 static const char cmd_pipeline_table_default_help[] =
1291 "pipeline <pipeline_name> table <table_name> default <file_name>\n";
1294 cmd_pipeline_table_default(char **tokens,
1301 char *pipeline_name, *table_name, *file_name;
1303 uint32_t file_line_number = 0;
1306 if (n_tokens != 6) {
1307 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1311 pipeline_name = tokens[1];
1312 p = pipeline_find(obj, pipeline_name);
1313 if (!p || !p->ctl) {
1314 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1318 table_name = tokens[3];
1320 file_name = tokens[5];
1321 file = fopen(file_name, "r");
1323 snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1327 status = pipeline_table_default_entry_add(p->ctl,
1332 snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1339 static const char cmd_pipeline_table_show_help[] =
1340 "pipeline <pipeline_name> table <table_name> show\n";
1343 cmd_pipeline_table_show(char **tokens,
1350 char *pipeline_name, *table_name;
1353 if (n_tokens != 5) {
1354 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1358 pipeline_name = tokens[1];
1359 p = pipeline_find(obj, pipeline_name);
1360 if (!p || !p->ctl) {
1361 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1365 table_name = tokens[3];
1366 status = rte_swx_ctl_pipeline_table_fprintf(stdout, p->ctl, table_name);
1368 snprintf(out, out_size, MSG_ARG_INVALID, "table_name");
1371 static const char cmd_pipeline_selector_group_add_help[] =
1372 "pipeline <pipeline_name> selector <selector_name> group add\n";
1375 cmd_pipeline_selector_group_add(char **tokens,
1382 char *pipeline_name, *selector_name;
1386 if (n_tokens != 6) {
1387 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1391 pipeline_name = tokens[1];
1392 p = pipeline_find(obj, pipeline_name);
1393 if (!p || !p->ctl) {
1394 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1398 if (strcmp(tokens[2], "selector") != 0) {
1399 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1403 selector_name = tokens[3];
1405 if (strcmp(tokens[4], "group") ||
1406 strcmp(tokens[5], "add")) {
1407 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group add");
1411 status = rte_swx_ctl_pipeline_selector_group_add(p->ctl,
1415 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1417 snprintf(out, out_size, "Group ID: %u\n", group_id);
1420 static const char cmd_pipeline_selector_group_delete_help[] =
1421 "pipeline <pipeline_name> selector <selector_name> group delete <group_id>\n";
1424 cmd_pipeline_selector_group_delete(char **tokens,
1431 char *pipeline_name, *selector_name;
1435 if (n_tokens != 7) {
1436 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1440 pipeline_name = tokens[1];
1441 p = pipeline_find(obj, pipeline_name);
1442 if (!p || !p->ctl) {
1443 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1447 if (strcmp(tokens[2], "selector") != 0) {
1448 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1452 selector_name = tokens[3];
1454 if (strcmp(tokens[4], "group") ||
1455 strcmp(tokens[5], "delete")) {
1456 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group delete");
1460 if (parser_read_uint32(&group_id, tokens[6]) != 0) {
1461 snprintf(out, out_size, MSG_ARG_INVALID, "group_id");
1465 status = rte_swx_ctl_pipeline_selector_group_delete(p->ctl,
1469 snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1472 #define GROUP_MEMBER_INFO_TOKENS_MAX 6
1475 token_is_comment(const char *token)
1477 if ((token[0] == '#') ||
1478 (token[0] == ';') ||
1479 ((token[0] == '/') && (token[1] == '/')))
1480 return 1; /* TRUE. */
1482 return 0; /* FALSE. */
1486 pipeline_selector_group_member_read(const char *string,
1488 uint32_t *member_id,
1490 int *is_blank_or_comment)
1492 char *token_array[GROUP_MEMBER_INFO_TOKENS_MAX], **tokens;
1493 char *s0 = NULL, *s;
1494 uint32_t n_tokens = 0, group_id_val = 0, member_id_val = 0, weight_val = 0;
1495 int blank_or_comment = 0;
1497 /* Check input arguments. */
1498 if (!string || !string[0])
1501 /* Memory allocation. */
1502 s0 = strdup(string);
1506 /* Parse the string into tokens. */
1510 token = strtok_r(s, " \f\n\r\t\v", &s);
1511 if (!token || token_is_comment(token))
1514 if (n_tokens >= GROUP_MEMBER_INFO_TOKENS_MAX)
1517 token_array[n_tokens] = token;
1522 blank_or_comment = 1;
1526 tokens = token_array;
1529 strcmp(tokens[0], "group") ||
1530 strcmp(tokens[2], "member"))
1536 if (parser_read_uint32(&group_id_val, tokens[1]) != 0)
1538 *group_id = group_id_val;
1543 if (parser_read_uint32(&member_id_val, tokens[3]) != 0)
1545 *member_id = member_id_val;
1553 if (n_tokens && !strcmp(tokens[0], "weight")) {
1557 if (parser_read_uint32(&weight_val, tokens[1]) != 0)
1559 *weight = weight_val;
1573 if (is_blank_or_comment)
1574 *is_blank_or_comment = blank_or_comment;
1579 pipeline_selector_group_members_add(struct rte_swx_ctl_pipeline *p,
1580 const char *selector_name,
1582 uint32_t *file_line_number)
1585 uint32_t line_id = 0;
1588 /* Buffer allocation. */
1589 line = malloc(MAX_LINE_SIZE);
1594 for (line_id = 1; ; line_id++) {
1595 uint32_t group_id, member_id, weight;
1596 int is_blank_or_comment;
1598 if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1601 status = pipeline_selector_group_member_read(line,
1605 &is_blank_or_comment);
1607 if (is_blank_or_comment)
1613 status = rte_swx_ctl_pipeline_selector_group_member_add(p,
1624 *file_line_number = line_id;
1628 static const char cmd_pipeline_selector_group_member_add_help[] =
1629 "pipeline <pipeline_name> selector <selector_name> group member add <file_name>";
1632 cmd_pipeline_selector_group_member_add(char **tokens,
1639 char *pipeline_name, *selector_name, *file_name;
1641 uint32_t file_line_number = 0;
1644 if (n_tokens != 8) {
1645 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1649 pipeline_name = tokens[1];
1650 p = pipeline_find(obj, pipeline_name);
1651 if (!p || !p->ctl) {
1652 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1656 if (strcmp(tokens[2], "selector") != 0) {
1657 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1661 selector_name = tokens[3];
1663 if (strcmp(tokens[4], "group") ||
1664 strcmp(tokens[5], "member") ||
1665 strcmp(tokens[6], "add")) {
1666 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member add");
1670 file_name = tokens[7];
1671 file = fopen(file_name, "r");
1673 snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1677 status = pipeline_selector_group_members_add(p->ctl,
1682 snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1690 pipeline_selector_group_members_delete(struct rte_swx_ctl_pipeline *p,
1691 const char *selector_name,
1693 uint32_t *file_line_number)
1696 uint32_t line_id = 0;
1699 /* Buffer allocation. */
1700 line = malloc(MAX_LINE_SIZE);
1705 for (line_id = 1; ; line_id++) {
1706 uint32_t group_id, member_id, weight;
1707 int is_blank_or_comment;
1709 if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1712 status = pipeline_selector_group_member_read(line,
1716 &is_blank_or_comment);
1718 if (is_blank_or_comment)
1724 status = rte_swx_ctl_pipeline_selector_group_member_delete(p,
1734 *file_line_number = line_id;
1738 static const char cmd_pipeline_selector_group_member_delete_help[] =
1739 "pipeline <pipeline_name> selector <selector_name> group member delete <file_name>";
1742 cmd_pipeline_selector_group_member_delete(char **tokens,
1749 char *pipeline_name, *selector_name, *file_name;
1751 uint32_t file_line_number = 0;
1754 if (n_tokens != 8) {
1755 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1759 pipeline_name = tokens[1];
1760 p = pipeline_find(obj, pipeline_name);
1761 if (!p || !p->ctl) {
1762 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1766 if (strcmp(tokens[2], "selector") != 0) {
1767 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1771 selector_name = tokens[3];
1773 if (strcmp(tokens[4], "group") ||
1774 strcmp(tokens[5], "member") ||
1775 strcmp(tokens[6], "delete")) {
1776 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member delete");
1780 file_name = tokens[7];
1781 file = fopen(file_name, "r");
1783 snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1787 status = pipeline_selector_group_members_delete(p->ctl,
1792 snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1799 static const char cmd_pipeline_selector_show_help[] =
1800 "pipeline <pipeline_name> selector <selector_name> show\n";
1803 cmd_pipeline_selector_show(char **tokens,
1810 char *pipeline_name, *selector_name;
1813 if (n_tokens != 5) {
1814 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1818 pipeline_name = tokens[1];
1819 p = pipeline_find(obj, pipeline_name);
1820 if (!p || !p->ctl) {
1821 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1825 selector_name = tokens[3];
1826 status = rte_swx_ctl_pipeline_selector_fprintf(stdout,
1827 p->ctl, selector_name);
1829 snprintf(out, out_size, MSG_ARG_INVALID, "selector_name");
1832 static const char cmd_pipeline_commit_help[] =
1833 "pipeline <pipeline_name> commit\n";
1836 cmd_pipeline_commit(char **tokens,
1843 char *pipeline_name;
1846 if (n_tokens != 3) {
1847 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1851 pipeline_name = tokens[1];
1852 p = pipeline_find(obj, pipeline_name);
1853 if (!p || !p->ctl) {
1854 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1858 status = rte_swx_ctl_pipeline_commit(p->ctl, 1);
1860 snprintf(out, out_size, "Commit failed. "
1861 "Use \"commit\" to retry or \"abort\" to discard the pending work.\n");
1864 static const char cmd_pipeline_abort_help[] =
1865 "pipeline <pipeline_name> abort\n";
1868 cmd_pipeline_abort(char **tokens,
1875 char *pipeline_name;
1877 if (n_tokens != 3) {
1878 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1882 pipeline_name = tokens[1];
1883 p = pipeline_find(obj, pipeline_name);
1884 if (!p || !p->ctl) {
1885 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1889 rte_swx_ctl_pipeline_abort(p->ctl);
1892 static const char cmd_pipeline_regrd_help[] =
1893 "pipeline <pipeline_name> regrd <register_array_name> <index>\n";
1896 cmd_pipeline_regrd(char **tokens,
1908 if (n_tokens != 5) {
1909 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1913 p = pipeline_find(obj, tokens[1]);
1914 if (!p || !p->ctl) {
1915 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1919 if (strcmp(tokens[2], "regrd")) {
1920 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd");
1926 if (parser_read_uint32(&idx, tokens[4])) {
1927 snprintf(out, out_size, MSG_ARG_INVALID, "index");
1931 status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value);
1933 snprintf(out, out_size, "Command failed.\n");
1937 snprintf(out, out_size, "0x%" PRIx64 "\n", value);
1940 static const char cmd_pipeline_regwr_help[] =
1941 "pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
1944 cmd_pipeline_regwr(char **tokens,
1956 if (n_tokens != 6) {
1957 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1961 p = pipeline_find(obj, tokens[1]);
1962 if (!p || !p->ctl) {
1963 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1967 if (strcmp(tokens[2], "regwr")) {
1968 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr");
1974 if (parser_read_uint32(&idx, tokens[4])) {
1975 snprintf(out, out_size, MSG_ARG_INVALID, "index");
1979 if (parser_read_uint64(&value, tokens[5])) {
1980 snprintf(out, out_size, MSG_ARG_INVALID, "value");
1984 status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value);
1986 snprintf(out, out_size, "Command failed.\n");
1991 static const char cmd_pipeline_meter_profile_add_help[] =
1992 "pipeline <pipeline_name> meter profile <profile_name> add "
1993 "cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
1996 cmd_pipeline_meter_profile_add(char **tokens,
2002 struct rte_meter_trtcm_params params;
2004 const char *profile_name;
2007 if (n_tokens != 14) {
2008 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2012 p = pipeline_find(obj, tokens[1]);
2013 if (!p || !p->ctl) {
2014 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2018 if (strcmp(tokens[2], "meter")) {
2019 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2023 if (strcmp(tokens[3], "profile")) {
2024 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2028 profile_name = tokens[4];
2030 if (strcmp(tokens[5], "add")) {
2031 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
2035 if (strcmp(tokens[6], "cir")) {
2036 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
2040 if (parser_read_uint64(¶ms.cir, tokens[7])) {
2041 snprintf(out, out_size, MSG_ARG_INVALID, "cir");
2045 if (strcmp(tokens[8], "pir")) {
2046 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
2050 if (parser_read_uint64(¶ms.pir, tokens[9])) {
2051 snprintf(out, out_size, MSG_ARG_INVALID, "pir");
2055 if (strcmp(tokens[10], "cbs")) {
2056 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
2060 if (parser_read_uint64(¶ms.cbs, tokens[11])) {
2061 snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
2065 if (strcmp(tokens[12], "pbs")) {
2066 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
2070 if (parser_read_uint64(¶ms.pbs, tokens[13])) {
2071 snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
2075 status = rte_swx_ctl_meter_profile_add(p->p, profile_name, ¶ms);
2077 snprintf(out, out_size, "Command failed.\n");
2082 static const char cmd_pipeline_meter_profile_delete_help[] =
2083 "pipeline <pipeline_name> meter profile <profile_name> delete\n";
2086 cmd_pipeline_meter_profile_delete(char **tokens,
2093 const char *profile_name;
2096 if (n_tokens != 6) {
2097 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2101 p = pipeline_find(obj, tokens[1]);
2102 if (!p || !p->ctl) {
2103 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2107 if (strcmp(tokens[2], "meter")) {
2108 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2112 if (strcmp(tokens[3], "profile")) {
2113 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2117 profile_name = tokens[4];
2119 if (strcmp(tokens[5], "delete")) {
2120 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
2124 status = rte_swx_ctl_meter_profile_delete(p->p, profile_name);
2126 snprintf(out, out_size, "Command failed.\n");
2131 static const char cmd_pipeline_meter_reset_help[] =
2132 "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2136 cmd_pipeline_meter_reset(char **tokens,
2144 uint32_t idx0 = 0, idx1 = 0;
2146 if (n_tokens != 9) {
2147 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2151 p = pipeline_find(obj, tokens[1]);
2152 if (!p || !p->ctl) {
2153 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2157 if (strcmp(tokens[2], "meter")) {
2158 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2164 if (strcmp(tokens[4], "from")) {
2165 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2169 if (parser_read_uint32(&idx0, tokens[5])) {
2170 snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2174 if (strcmp(tokens[6], "to")) {
2175 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2179 if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2180 snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2184 if (strcmp(tokens[8], "reset")) {
2185 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
2189 for ( ; idx0 <= idx1; idx0++) {
2192 status = rte_swx_ctl_meter_reset(p->p, name, idx0);
2194 snprintf(out, out_size, "Command failed for index %u.\n", idx0);
2200 static const char cmd_pipeline_meter_set_help[] =
2201 "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2202 "set profile <profile_name>\n";
2205 cmd_pipeline_meter_set(char **tokens,
2212 const char *name, *profile_name;
2213 uint32_t idx0 = 0, idx1 = 0;
2215 if (n_tokens != 11) {
2216 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2220 p = pipeline_find(obj, tokens[1]);
2221 if (!p || !p->ctl) {
2222 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2226 if (strcmp(tokens[2], "meter")) {
2227 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2233 if (strcmp(tokens[4], "from")) {
2234 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2238 if (parser_read_uint32(&idx0, tokens[5])) {
2239 snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2243 if (strcmp(tokens[6], "to")) {
2244 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2248 if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2249 snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2253 if (strcmp(tokens[8], "set")) {
2254 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
2258 if (strcmp(tokens[9], "profile")) {
2259 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2263 profile_name = tokens[10];
2265 for ( ; idx0 <= idx1; idx0++) {
2268 status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name);
2270 snprintf(out, out_size, "Command failed for index %u.\n", idx0);
2276 static const char cmd_pipeline_meter_stats_help[] =
2277 "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2281 cmd_pipeline_meter_stats(char **tokens,
2287 struct rte_swx_ctl_meter_stats stats;
2290 uint32_t idx0 = 0, idx1 = 0;
2292 if (n_tokens != 9) {
2293 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2297 p = pipeline_find(obj, tokens[1]);
2298 if (!p || !p->ctl) {
2299 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2303 if (strcmp(tokens[2], "meter")) {
2304 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2310 if (strcmp(tokens[4], "from")) {
2311 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2315 if (parser_read_uint32(&idx0, tokens[5])) {
2316 snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2320 if (strcmp(tokens[6], "to")) {
2321 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2325 if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2326 snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2330 if (strcmp(tokens[8], "stats")) {
2331 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2336 snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
2338 "----------------", "----------------", "----------------",
2339 "----------------", "----------------", "----------------");
2340 out_size -= strlen(out);
2343 snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n",
2345 "GREEN (packets)", "YELLOW (packets)", "RED (packets)",
2346 "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)");
2347 out_size -= strlen(out);
2350 snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
2352 "----------------", "----------------", "----------------",
2353 "----------------", "----------------", "----------------");
2354 out_size -= strlen(out);
2358 for ( ; idx0 <= idx1; idx0++) {
2361 status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats);
2363 snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
2364 out_size -= strlen(out);
2369 snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
2370 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
2372 stats.n_pkts[RTE_COLOR_GREEN],
2373 stats.n_pkts[RTE_COLOR_YELLOW],
2374 stats.n_pkts[RTE_COLOR_RED],
2375 stats.n_bytes[RTE_COLOR_GREEN],
2376 stats.n_bytes[RTE_COLOR_YELLOW],
2377 stats.n_bytes[RTE_COLOR_RED]);
2378 out_size -= strlen(out);
2383 static const char cmd_pipeline_stats_help[] =
2384 "pipeline <pipeline_name> stats\n";
2387 cmd_pipeline_stats(char **tokens,
2393 struct rte_swx_ctl_pipeline_info info;
2398 if (n_tokens != 3) {
2399 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2403 p = pipeline_find(obj, tokens[1]);
2404 if (!p || !p->ctl) {
2405 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2409 if (strcmp(tokens[2], "stats")) {
2410 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2414 status = rte_swx_ctl_pipeline_info_get(p->p, &info);
2416 snprintf(out, out_size, "Pipeline info get error.");
2420 snprintf(out, out_size, "Input ports:\n");
2421 out_size -= strlen(out);
2424 for (i = 0; i < info.n_ports_in; i++) {
2425 struct rte_swx_port_in_stats stats;
2427 rte_swx_ctl_pipeline_port_in_stats_read(p->p, i, &stats);
2429 snprintf(out, out_size, "\tPort %u:"
2432 " empty %" PRIu64 "\n",
2433 i, stats.n_pkts, stats.n_bytes, stats.n_empty);
2434 out_size -= strlen(out);
2438 snprintf(out, out_size, "\nOutput ports:\n");
2439 out_size -= strlen(out);
2442 for (i = 0; i < info.n_ports_out; i++) {
2443 struct rte_swx_port_out_stats stats;
2445 rte_swx_ctl_pipeline_port_out_stats_read(p->p, i, &stats);
2447 snprintf(out, out_size, "\tPort %u:"
2449 " bytes %" PRIu64 "\n",
2450 i, stats.n_pkts, stats.n_bytes);
2451 out_size -= strlen(out);
2455 snprintf(out, out_size, "\nTables:\n");
2456 out_size -= strlen(out);
2459 for (i = 0; i < info.n_tables; i++) {
2460 struct rte_swx_ctl_table_info table_info;
2461 uint64_t n_pkts_action[info.n_actions];
2462 struct rte_swx_table_stats stats = {
2465 .n_pkts_action = n_pkts_action,
2469 status = rte_swx_ctl_table_info_get(p->p, i, &table_info);
2471 snprintf(out, out_size, "Table info get error.");
2475 status = rte_swx_ctl_pipeline_table_stats_read(p->p, table_info.name, &stats);
2477 snprintf(out, out_size, "Table stats read error.");
2481 snprintf(out, out_size, "\tTable %s:\n"
2482 "\t\tHit (packets): %" PRIu64 "\n"
2483 "\t\tMiss (packets): %" PRIu64 "\n",
2487 out_size -= strlen(out);
2490 for (j = 0; j < info.n_actions; j++) {
2491 struct rte_swx_ctl_action_info action_info;
2493 status = rte_swx_ctl_action_info_get(p->p, j, &action_info);
2495 snprintf(out, out_size, "Action info get error.");
2499 snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n",
2501 stats.n_pkts_action[j]);
2502 out_size -= strlen(out);
2508 static const char cmd_thread_pipeline_enable_help[] =
2509 "thread <thread_id> pipeline <pipeline_name> enable\n";
2512 cmd_thread_pipeline_enable(char **tokens,
2518 char *pipeline_name;
2523 if (n_tokens != 5) {
2524 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2528 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
2529 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
2533 if (strcmp(tokens[2], "pipeline") != 0) {
2534 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
2538 pipeline_name = tokens[3];
2539 p = pipeline_find(obj, pipeline_name);
2540 if (!p || !p->ctl) {
2541 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2545 if (strcmp(tokens[4], "enable") != 0) {
2546 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
2550 status = thread_pipeline_enable(thread_id, obj, pipeline_name);
2552 snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
2557 static const char cmd_thread_pipeline_disable_help[] =
2558 "thread <thread_id> pipeline <pipeline_name> disable\n";
2561 cmd_thread_pipeline_disable(char **tokens,
2568 char *pipeline_name;
2572 if (n_tokens != 5) {
2573 snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2577 if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
2578 snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
2582 if (strcmp(tokens[2], "pipeline") != 0) {
2583 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
2587 pipeline_name = tokens[3];
2588 p = pipeline_find(obj, pipeline_name);
2589 if (!p || !p->ctl) {
2590 snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2594 if (strcmp(tokens[4], "disable") != 0) {
2595 snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
2599 status = thread_pipeline_disable(thread_id, obj, pipeline_name);
2601 snprintf(out, out_size, MSG_CMD_FAIL,
2602 "thread pipeline disable");
2608 cmd_help(char **tokens,
2612 void *arg __rte_unused)
2617 if (n_tokens == 0) {
2618 snprintf(out, out_size,
2619 "Type 'help <command>' for command details.\n\n"
2620 "List of commands:\n"
2624 "\tpipeline create\n"
2625 "\tpipeline port in\n"
2626 "\tpipeline port out\n"
2627 "\tpipeline build\n"
2628 "\tpipeline table add\n"
2629 "\tpipeline table delete\n"
2630 "\tpipeline table default\n"
2631 "\tpipeline table show\n"
2632 "\tpipeline selector group add\n"
2633 "\tpipeline selector group delete\n"
2634 "\tpipeline selector group member add\n"
2635 "\tpipeline selector group member delete\n"
2636 "\tpipeline selector show\n"
2637 "\tpipeline commit\n"
2638 "\tpipeline abort\n"
2639 "\tpipeline regrd\n"
2640 "\tpipeline regwr\n"
2641 "\tpipeline meter profile add\n"
2642 "\tpipeline meter profile delete\n"
2643 "\tpipeline meter reset\n"
2644 "\tpipeline meter set\n"
2645 "\tpipeline meter stats\n"
2646 "\tpipeline stats\n"
2647 "\tthread pipeline enable\n"
2648 "\tthread pipeline disable\n\n");
2652 if (strcmp(tokens[0], "mempool") == 0) {
2653 snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
2657 if (strcmp(tokens[0], "link") == 0) {
2658 snprintf(out, out_size, "\n%s\n", cmd_link_help);
2662 if (strcmp(tokens[0], "ring") == 0) {
2663 snprintf(out, out_size, "\n%s\n", cmd_ring_help);
2667 if (strcmp(tokens[0], "tap") == 0) {
2668 snprintf(out, out_size, "\n%s\n", cmd_tap_help);
2672 if ((strcmp(tokens[0], "pipeline") == 0) &&
2673 (n_tokens == 2) && (strcmp(tokens[1], "create") == 0)) {
2674 snprintf(out, out_size, "\n%s\n", cmd_pipeline_create_help);
2678 if ((strcmp(tokens[0], "pipeline") == 0) &&
2679 (n_tokens == 3) && (strcmp(tokens[1], "port") == 0)) {
2680 if (strcmp(tokens[2], "in") == 0) {
2681 snprintf(out, out_size, "\n%s\n",
2682 cmd_pipeline_port_in_help);
2686 if (strcmp(tokens[2], "out") == 0) {
2687 snprintf(out, out_size, "\n%s\n",
2688 cmd_pipeline_port_out_help);
2693 if ((strcmp(tokens[0], "pipeline") == 0) &&
2694 (n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) {
2695 snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help);
2699 if ((strcmp(tokens[0], "pipeline") == 0) &&
2701 (strcmp(tokens[1], "table") == 0) &&
2702 (strcmp(tokens[2], "add") == 0)) {
2703 snprintf(out, out_size, "\n%s\n",
2704 cmd_pipeline_table_add_help);
2708 if ((strcmp(tokens[0], "pipeline") == 0) &&
2710 (strcmp(tokens[1], "table") == 0) &&
2711 (strcmp(tokens[2], "delete") == 0)) {
2712 snprintf(out, out_size, "\n%s\n",
2713 cmd_pipeline_table_delete_help);
2717 if ((strcmp(tokens[0], "pipeline") == 0) &&
2719 (strcmp(tokens[1], "table") == 0) &&
2720 (strcmp(tokens[2], "default") == 0)) {
2721 snprintf(out, out_size, "\n%s\n",
2722 cmd_pipeline_table_default_help);
2726 if ((strcmp(tokens[0], "pipeline") == 0) &&
2728 (strcmp(tokens[1], "table") == 0) &&
2729 (strcmp(tokens[2], "show") == 0)) {
2730 snprintf(out, out_size, "\n%s\n",
2731 cmd_pipeline_table_show_help);
2735 if ((strcmp(tokens[0], "pipeline") == 0) &&
2737 (strcmp(tokens[1], "selector") == 0) &&
2738 (strcmp(tokens[2], "group") == 0) &&
2739 (strcmp(tokens[3], "add") == 0)) {
2740 snprintf(out, out_size, "\n%s\n",
2741 cmd_pipeline_selector_group_add_help);
2745 if ((strcmp(tokens[0], "pipeline") == 0) &&
2747 (strcmp(tokens[1], "selector") == 0) &&
2748 (strcmp(tokens[2], "group") == 0) &&
2749 (strcmp(tokens[3], "delete") == 0)) {
2750 snprintf(out, out_size, "\n%s\n",
2751 cmd_pipeline_selector_group_delete_help);
2755 if ((strcmp(tokens[0], "pipeline") == 0) &&
2757 (strcmp(tokens[1], "selector") == 0) &&
2758 (strcmp(tokens[2], "group") == 0) &&
2759 (strcmp(tokens[3], "member") == 0) &&
2760 (strcmp(tokens[4], "add") == 0)) {
2761 snprintf(out, out_size, "\n%s\n",
2762 cmd_pipeline_selector_group_member_add_help);
2766 if ((strcmp(tokens[0], "pipeline") == 0) &&
2768 (strcmp(tokens[1], "selector") == 0) &&
2769 (strcmp(tokens[2], "group") == 0) &&
2770 (strcmp(tokens[3], "member") == 0) &&
2771 (strcmp(tokens[4], "delete") == 0)) {
2772 snprintf(out, out_size, "\n%s\n",
2773 cmd_pipeline_selector_group_member_delete_help);
2777 if ((strcmp(tokens[0], "pipeline") == 0) &&
2779 (strcmp(tokens[1], "selector") == 0) &&
2780 (strcmp(tokens[2], "show") == 0)) {
2781 snprintf(out, out_size, "\n%s\n",
2782 cmd_pipeline_selector_show_help);
2786 if ((strcmp(tokens[0], "pipeline") == 0) &&
2788 (strcmp(tokens[1], "commit") == 0)) {
2789 snprintf(out, out_size, "\n%s\n",
2790 cmd_pipeline_commit_help);
2794 if ((strcmp(tokens[0], "pipeline") == 0) &&
2796 (strcmp(tokens[1], "abort") == 0)) {
2797 snprintf(out, out_size, "\n%s\n",
2798 cmd_pipeline_abort_help);
2802 if ((strcmp(tokens[0], "pipeline") == 0) &&
2803 (n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) {
2804 snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help);
2808 if ((strcmp(tokens[0], "pipeline") == 0) &&
2809 (n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) {
2810 snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help);
2814 if (!strcmp(tokens[0], "pipeline") &&
2815 (n_tokens == 4) && !strcmp(tokens[1], "meter")
2816 && !strcmp(tokens[2], "profile")
2817 && !strcmp(tokens[3], "add")) {
2818 snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help);
2822 if (!strcmp(tokens[0], "pipeline") &&
2823 (n_tokens == 4) && !strcmp(tokens[1], "meter")
2824 && !strcmp(tokens[2], "profile")
2825 && !strcmp(tokens[3], "delete")) {
2826 snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help);
2830 if (!strcmp(tokens[0], "pipeline") &&
2831 (n_tokens == 3) && !strcmp(tokens[1], "meter")
2832 && !strcmp(tokens[2], "reset")) {
2833 snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help);
2837 if (!strcmp(tokens[0], "pipeline") &&
2838 (n_tokens == 3) && !strcmp(tokens[1], "meter")
2839 && !strcmp(tokens[2], "set")) {
2840 snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help);
2844 if (!strcmp(tokens[0], "pipeline") &&
2845 (n_tokens == 3) && !strcmp(tokens[1], "meter")
2846 && !strcmp(tokens[2], "stats")) {
2847 snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help);
2851 if ((strcmp(tokens[0], "pipeline") == 0) &&
2852 (n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) {
2853 snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help);
2857 if ((n_tokens == 3) &&
2858 (strcmp(tokens[0], "thread") == 0) &&
2859 (strcmp(tokens[1], "pipeline") == 0)) {
2860 if (strcmp(tokens[2], "enable") == 0) {
2861 snprintf(out, out_size, "\n%s\n",
2862 cmd_thread_pipeline_enable_help);
2866 if (strcmp(tokens[2], "disable") == 0) {
2867 snprintf(out, out_size, "\n%s\n",
2868 cmd_thread_pipeline_disable_help);
2873 snprintf(out, out_size, "Invalid command\n");
2877 cli_process(char *in, char *out, size_t out_size, void *obj)
2879 char *tokens[CMD_MAX_TOKENS];
2880 uint32_t n_tokens = RTE_DIM(tokens);
2886 status = parse_tokenize_string(in, tokens, &n_tokens);
2888 snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
2895 if (strcmp(tokens[0], "help") == 0) {
2896 cmd_help(tokens, n_tokens, out, out_size, obj);
2900 if (strcmp(tokens[0], "mempool") == 0) {
2901 cmd_mempool(tokens, n_tokens, out, out_size, obj);
2905 if (strcmp(tokens[0], "link") == 0) {
2906 if ((n_tokens >= 2) && (strcmp(tokens[1], "show") == 0)) {
2907 cmd_link_show(tokens, n_tokens, out, out_size, obj);
2911 cmd_link(tokens, n_tokens, out, out_size, obj);
2915 if (strcmp(tokens[0], "ring") == 0) {
2916 cmd_ring(tokens, n_tokens, out, out_size, obj);
2920 if (strcmp(tokens[0], "tap") == 0) {
2921 cmd_tap(tokens, n_tokens, out, out_size, obj);
2925 if (strcmp(tokens[0], "pipeline") == 0) {
2926 if ((n_tokens >= 3) &&
2927 (strcmp(tokens[2], "create") == 0)) {
2928 cmd_pipeline_create(tokens, n_tokens, out, out_size,
2933 if ((n_tokens >= 4) &&
2934 (strcmp(tokens[2], "port") == 0) &&
2935 (strcmp(tokens[3], "in") == 0)) {
2936 cmd_pipeline_port_in(tokens, n_tokens, out, out_size,
2941 if ((n_tokens >= 4) &&
2942 (strcmp(tokens[2], "port") == 0) &&
2943 (strcmp(tokens[3], "out") == 0)) {
2944 cmd_pipeline_port_out(tokens, n_tokens, out, out_size,
2949 if ((n_tokens >= 3) &&
2950 (strcmp(tokens[2], "build") == 0)) {
2951 cmd_pipeline_build(tokens, n_tokens, out, out_size,
2956 if ((n_tokens >= 5) &&
2957 (strcmp(tokens[2], "table") == 0) &&
2958 (strcmp(tokens[4], "add") == 0)) {
2959 cmd_pipeline_table_add(tokens, n_tokens, out,
2964 if ((n_tokens >= 5) &&
2965 (strcmp(tokens[2], "table") == 0) &&
2966 (strcmp(tokens[4], "delete") == 0)) {
2967 cmd_pipeline_table_delete(tokens, n_tokens, out,
2972 if ((n_tokens >= 5) &&
2973 (strcmp(tokens[2], "table") == 0) &&
2974 (strcmp(tokens[4], "default") == 0)) {
2975 cmd_pipeline_table_default(tokens, n_tokens, out,
2980 if ((n_tokens >= 5) &&
2981 (strcmp(tokens[2], "table") == 0) &&
2982 (strcmp(tokens[4], "show") == 0)) {
2983 cmd_pipeline_table_show(tokens, n_tokens, out,
2988 if ((n_tokens >= 6) &&
2989 (strcmp(tokens[2], "selector") == 0) &&
2990 (strcmp(tokens[4], "group") == 0) &&
2991 (strcmp(tokens[5], "add") == 0)) {
2992 cmd_pipeline_selector_group_add(tokens, n_tokens, out,
2997 if ((n_tokens >= 6) &&
2998 (strcmp(tokens[2], "selector") == 0) &&
2999 (strcmp(tokens[4], "group") == 0) &&
3000 (strcmp(tokens[5], "delete") == 0)) {
3001 cmd_pipeline_selector_group_delete(tokens, n_tokens, out,
3006 if ((n_tokens >= 7) &&
3007 (strcmp(tokens[2], "selector") == 0) &&
3008 (strcmp(tokens[4], "group") == 0) &&
3009 (strcmp(tokens[5], "member") == 0) &&
3010 (strcmp(tokens[6], "add") == 0)) {
3011 cmd_pipeline_selector_group_member_add(tokens, n_tokens, out,
3016 if ((n_tokens >= 7) &&
3017 (strcmp(tokens[2], "selector") == 0) &&
3018 (strcmp(tokens[4], "group") == 0) &&
3019 (strcmp(tokens[5], "member") == 0) &&
3020 (strcmp(tokens[6], "delete") == 0)) {
3021 cmd_pipeline_selector_group_member_delete(tokens, n_tokens, out,
3026 if ((n_tokens >= 5) &&
3027 (strcmp(tokens[2], "selector") == 0) &&
3028 (strcmp(tokens[4], "show") == 0)) {
3029 cmd_pipeline_selector_show(tokens, n_tokens, out,
3034 if ((n_tokens >= 3) &&
3035 (strcmp(tokens[2], "commit") == 0)) {
3036 cmd_pipeline_commit(tokens, n_tokens, out,
3041 if ((n_tokens >= 3) &&
3042 (strcmp(tokens[2], "abort") == 0)) {
3043 cmd_pipeline_abort(tokens, n_tokens, out,
3048 if ((n_tokens >= 3) &&
3049 (strcmp(tokens[2], "regrd") == 0)) {
3050 cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj);
3054 if ((n_tokens >= 3) &&
3055 (strcmp(tokens[2], "regwr") == 0)) {
3056 cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj);
3060 if ((n_tokens >= 6) &&
3061 (strcmp(tokens[2], "meter") == 0) &&
3062 (strcmp(tokens[3], "profile") == 0) &&
3063 (strcmp(tokens[5], "add") == 0)) {
3064 cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj);
3068 if ((n_tokens >= 6) &&
3069 (strcmp(tokens[2], "meter") == 0) &&
3070 (strcmp(tokens[3], "profile") == 0) &&
3071 (strcmp(tokens[5], "delete") == 0)) {
3072 cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj);
3076 if ((n_tokens >= 9) &&
3077 (strcmp(tokens[2], "meter") == 0) &&
3078 (strcmp(tokens[8], "reset") == 0)) {
3079 cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj);
3083 if ((n_tokens >= 9) &&
3084 (strcmp(tokens[2], "meter") == 0) &&
3085 (strcmp(tokens[8], "set") == 0)) {
3086 cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj);
3090 if ((n_tokens >= 9) &&
3091 (strcmp(tokens[2], "meter") == 0) &&
3092 (strcmp(tokens[8], "stats") == 0)) {
3093 cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj);
3097 if ((n_tokens >= 3) &&
3098 (strcmp(tokens[2], "stats") == 0)) {
3099 cmd_pipeline_stats(tokens, n_tokens, out, out_size,
3105 if (strcmp(tokens[0], "thread") == 0) {
3106 if ((n_tokens >= 5) &&
3107 (strcmp(tokens[4], "enable") == 0)) {
3108 cmd_thread_pipeline_enable(tokens, n_tokens,
3109 out, out_size, obj);
3113 if ((n_tokens >= 5) &&
3114 (strcmp(tokens[4], "disable") == 0)) {
3115 cmd_thread_pipeline_disable(tokens, n_tokens,
3116 out, out_size, obj);
3121 snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
3125 cli_script_process(const char *file_name,
3126 size_t msg_in_len_max,
3127 size_t msg_out_len_max,
3130 char *msg_in = NULL, *msg_out = NULL;
3133 /* Check input arguments */
3134 if ((file_name == NULL) ||
3135 (strlen(file_name) == 0) ||
3136 (msg_in_len_max == 0) ||
3137 (msg_out_len_max == 0))
3140 msg_in = malloc(msg_in_len_max + 1);
3141 msg_out = malloc(msg_out_len_max + 1);
3142 if ((msg_in == NULL) ||
3143 (msg_out == NULL)) {
3149 /* Open input file */
3150 f = fopen(file_name, "r");
3159 if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
3162 printf("%s", msg_in);
3170 if (strlen(msg_out))
3171 printf("%s", msg_out);