xref: /dpdk/examples/pipeline/cli.c (revision 80dd28aff8bf2e36d565d699459d41bc39e088ba)
15074e1d5SCristian Dumitrescu /* SPDX-License-Identifier: BSD-3-Clause
25074e1d5SCristian Dumitrescu  * Copyright(c) 2020 Intel Corporation
35074e1d5SCristian Dumitrescu  */
45074e1d5SCristian Dumitrescu 
55074e1d5SCristian Dumitrescu #include <stdio.h>
65074e1d5SCristian Dumitrescu #include <stdint.h>
75074e1d5SCristian Dumitrescu #include <stdlib.h>
85074e1d5SCristian Dumitrescu #include <string.h>
95074e1d5SCristian Dumitrescu 
105074e1d5SCristian Dumitrescu #include <rte_common.h>
115074e1d5SCristian Dumitrescu #include <rte_ethdev.h>
125074e1d5SCristian Dumitrescu #include <rte_swx_port_ethdev.h>
1377a41301SCristian Dumitrescu #include <rte_swx_port_ring.h>
145074e1d5SCristian Dumitrescu #include <rte_swx_port_source_sink.h>
15e2b8dc52SVenkata Suresh Kumar P #include <rte_swx_port_fd.h>
165074e1d5SCristian Dumitrescu #include <rte_swx_pipeline.h>
175074e1d5SCristian Dumitrescu #include <rte_swx_ctl.h>
185074e1d5SCristian Dumitrescu 
195074e1d5SCristian Dumitrescu #include "cli.h"
205074e1d5SCristian Dumitrescu 
215074e1d5SCristian Dumitrescu #include "obj.h"
225074e1d5SCristian Dumitrescu #include "thread.h"
235074e1d5SCristian Dumitrescu 
245074e1d5SCristian Dumitrescu #ifndef CMD_MAX_TOKENS
255074e1d5SCristian Dumitrescu #define CMD_MAX_TOKENS     256
265074e1d5SCristian Dumitrescu #endif
275074e1d5SCristian Dumitrescu 
285074e1d5SCristian Dumitrescu #define MSG_OUT_OF_MEMORY   "Not enough memory.\n"
295074e1d5SCristian Dumitrescu #define MSG_CMD_UNKNOWN     "Unknown command \"%s\".\n"
305074e1d5SCristian Dumitrescu #define MSG_CMD_UNIMPLEM    "Command \"%s\" not implemented.\n"
315074e1d5SCristian Dumitrescu #define MSG_ARG_NOT_ENOUGH  "Not enough arguments for command \"%s\".\n"
325074e1d5SCristian Dumitrescu #define MSG_ARG_TOO_MANY    "Too many arguments for command \"%s\".\n"
335074e1d5SCristian Dumitrescu #define MSG_ARG_MISMATCH    "Wrong number of arguments for command \"%s\".\n"
345074e1d5SCristian Dumitrescu #define MSG_ARG_NOT_FOUND   "Argument \"%s\" not found.\n"
355074e1d5SCristian Dumitrescu #define MSG_ARG_INVALID     "Invalid value for argument \"%s\".\n"
365074e1d5SCristian Dumitrescu #define MSG_FILE_ERR        "Error in file \"%s\" at line %u.\n"
375074e1d5SCristian Dumitrescu #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
385074e1d5SCristian Dumitrescu #define MSG_CMD_FAIL        "Command \"%s\" failed.\n"
395074e1d5SCristian Dumitrescu 
405074e1d5SCristian Dumitrescu #define skip_white_spaces(pos)			\
415074e1d5SCristian Dumitrescu ({						\
425074e1d5SCristian Dumitrescu 	__typeof__(pos) _p = (pos);		\
435074e1d5SCristian Dumitrescu 	for ( ; isspace(*_p); _p++)		\
445074e1d5SCristian Dumitrescu 		;				\
455074e1d5SCristian Dumitrescu 	_p;					\
465074e1d5SCristian Dumitrescu })
475074e1d5SCristian Dumitrescu 
485074e1d5SCristian Dumitrescu static int
495074e1d5SCristian Dumitrescu parser_read_uint64(uint64_t *value, const char *p)
505074e1d5SCristian Dumitrescu {
515074e1d5SCristian Dumitrescu 	char *next;
525074e1d5SCristian Dumitrescu 	uint64_t val;
535074e1d5SCristian Dumitrescu 
545074e1d5SCristian Dumitrescu 	p = skip_white_spaces(p);
555074e1d5SCristian Dumitrescu 	if (!isdigit(*p))
565074e1d5SCristian Dumitrescu 		return -EINVAL;
575074e1d5SCristian Dumitrescu 
580d644eb6SChurchill Khangar 	val = strtoul(p, &next, 0);
595074e1d5SCristian Dumitrescu 	if (p == next)
605074e1d5SCristian Dumitrescu 		return -EINVAL;
615074e1d5SCristian Dumitrescu 
625074e1d5SCristian Dumitrescu 	p = next;
635074e1d5SCristian Dumitrescu 	switch (*p) {
645074e1d5SCristian Dumitrescu 	case 'T':
655074e1d5SCristian Dumitrescu 		val *= 1024ULL;
665074e1d5SCristian Dumitrescu 		/* fall through */
675074e1d5SCristian Dumitrescu 	case 'G':
685074e1d5SCristian Dumitrescu 		val *= 1024ULL;
695074e1d5SCristian Dumitrescu 		/* fall through */
705074e1d5SCristian Dumitrescu 	case 'M':
715074e1d5SCristian Dumitrescu 		val *= 1024ULL;
725074e1d5SCristian Dumitrescu 		/* fall through */
735074e1d5SCristian Dumitrescu 	case 'k':
745074e1d5SCristian Dumitrescu 	case 'K':
755074e1d5SCristian Dumitrescu 		val *= 1024ULL;
765074e1d5SCristian Dumitrescu 		p++;
775074e1d5SCristian Dumitrescu 		break;
785074e1d5SCristian Dumitrescu 	}
795074e1d5SCristian Dumitrescu 
805074e1d5SCristian Dumitrescu 	p = skip_white_spaces(p);
815074e1d5SCristian Dumitrescu 	if (*p != '\0')
825074e1d5SCristian Dumitrescu 		return -EINVAL;
835074e1d5SCristian Dumitrescu 
845074e1d5SCristian Dumitrescu 	*value = val;
855074e1d5SCristian Dumitrescu 	return 0;
865074e1d5SCristian Dumitrescu }
875074e1d5SCristian Dumitrescu 
885074e1d5SCristian Dumitrescu static int
895074e1d5SCristian Dumitrescu parser_read_uint32(uint32_t *value, const char *p)
905074e1d5SCristian Dumitrescu {
915074e1d5SCristian Dumitrescu 	uint64_t val = 0;
925074e1d5SCristian Dumitrescu 	int ret = parser_read_uint64(&val, p);
935074e1d5SCristian Dumitrescu 
945074e1d5SCristian Dumitrescu 	if (ret < 0)
955074e1d5SCristian Dumitrescu 		return ret;
965074e1d5SCristian Dumitrescu 
975074e1d5SCristian Dumitrescu 	if (val > UINT32_MAX)
985074e1d5SCristian Dumitrescu 		return -ERANGE;
995074e1d5SCristian Dumitrescu 
1005074e1d5SCristian Dumitrescu 	*value = val;
1015074e1d5SCristian Dumitrescu 	return 0;
1025074e1d5SCristian Dumitrescu }
1035074e1d5SCristian Dumitrescu 
1045074e1d5SCristian Dumitrescu static int
1055074e1d5SCristian Dumitrescu parser_read_uint16(uint16_t *value, const char *p)
1065074e1d5SCristian Dumitrescu {
1075074e1d5SCristian Dumitrescu 	uint64_t val = 0;
1085074e1d5SCristian Dumitrescu 	int ret = parser_read_uint64(&val, p);
1095074e1d5SCristian Dumitrescu 
1105074e1d5SCristian Dumitrescu 	if (ret < 0)
1115074e1d5SCristian Dumitrescu 		return ret;
1125074e1d5SCristian Dumitrescu 
1135074e1d5SCristian Dumitrescu 	if (val > UINT16_MAX)
1145074e1d5SCristian Dumitrescu 		return -ERANGE;
1155074e1d5SCristian Dumitrescu 
1165074e1d5SCristian Dumitrescu 	*value = val;
1175074e1d5SCristian Dumitrescu 	return 0;
1185074e1d5SCristian Dumitrescu }
1195074e1d5SCristian Dumitrescu 
1205074e1d5SCristian Dumitrescu #define PARSE_DELIMITER " \f\n\r\t\v"
1215074e1d5SCristian Dumitrescu 
1225074e1d5SCristian Dumitrescu static int
1235074e1d5SCristian Dumitrescu parse_tokenize_string(char *string, char *tokens[], uint32_t *n_tokens)
1245074e1d5SCristian Dumitrescu {
1255074e1d5SCristian Dumitrescu 	uint32_t i;
1265074e1d5SCristian Dumitrescu 
1275074e1d5SCristian Dumitrescu 	if ((string == NULL) ||
1285074e1d5SCristian Dumitrescu 		(tokens == NULL) ||
1295074e1d5SCristian Dumitrescu 		(*n_tokens < 1))
1305074e1d5SCristian Dumitrescu 		return -EINVAL;
1315074e1d5SCristian Dumitrescu 
1325074e1d5SCristian Dumitrescu 	for (i = 0; i < *n_tokens; i++) {
1335074e1d5SCristian Dumitrescu 		tokens[i] = strtok_r(string, PARSE_DELIMITER, &string);
1345074e1d5SCristian Dumitrescu 		if (tokens[i] == NULL)
1355074e1d5SCristian Dumitrescu 			break;
1365074e1d5SCristian Dumitrescu 	}
1375074e1d5SCristian Dumitrescu 
1385074e1d5SCristian Dumitrescu 	if ((i == *n_tokens) && strtok_r(string, PARSE_DELIMITER, &string))
1395074e1d5SCristian Dumitrescu 		return -E2BIG;
1405074e1d5SCristian Dumitrescu 
1415074e1d5SCristian Dumitrescu 	*n_tokens = i;
1425074e1d5SCristian Dumitrescu 	return 0;
1435074e1d5SCristian Dumitrescu }
1445074e1d5SCristian Dumitrescu 
1455074e1d5SCristian Dumitrescu static int
1465074e1d5SCristian Dumitrescu is_comment(char *in)
1475074e1d5SCristian Dumitrescu {
1485074e1d5SCristian Dumitrescu 	if ((strlen(in) && index("!#%;", in[0])) ||
1495074e1d5SCristian Dumitrescu 		(strncmp(in, "//", 2) == 0) ||
1505074e1d5SCristian Dumitrescu 		(strncmp(in, "--", 2) == 0))
1515074e1d5SCristian Dumitrescu 		return 1;
1525074e1d5SCristian Dumitrescu 
1535074e1d5SCristian Dumitrescu 	return 0;
1545074e1d5SCristian Dumitrescu }
1555074e1d5SCristian Dumitrescu 
1565074e1d5SCristian Dumitrescu static const char cmd_mempool_help[] =
1575074e1d5SCristian Dumitrescu "mempool <mempool_name>\n"
1585074e1d5SCristian Dumitrescu "   buffer <buffer_size>\n"
1595074e1d5SCristian Dumitrescu "   pool <pool_size>\n"
1605074e1d5SCristian Dumitrescu "   cache <cache_size>\n"
1615074e1d5SCristian Dumitrescu "   cpu <cpu_id>\n";
1625074e1d5SCristian Dumitrescu 
1635074e1d5SCristian Dumitrescu static void
1645074e1d5SCristian Dumitrescu cmd_mempool(char **tokens,
1655074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
1665074e1d5SCristian Dumitrescu 	char *out,
1675074e1d5SCristian Dumitrescu 	size_t out_size,
1685074e1d5SCristian Dumitrescu 	void *obj)
1695074e1d5SCristian Dumitrescu {
1705074e1d5SCristian Dumitrescu 	struct mempool_params p;
1715074e1d5SCristian Dumitrescu 	char *name;
1725074e1d5SCristian Dumitrescu 	struct mempool *mempool;
1735074e1d5SCristian Dumitrescu 
1745074e1d5SCristian Dumitrescu 	if (n_tokens != 10) {
1755074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1765074e1d5SCristian Dumitrescu 		return;
1775074e1d5SCristian Dumitrescu 	}
1785074e1d5SCristian Dumitrescu 
1795074e1d5SCristian Dumitrescu 	name = tokens[1];
1805074e1d5SCristian Dumitrescu 
1815074e1d5SCristian Dumitrescu 	if (strcmp(tokens[2], "buffer") != 0) {
1825074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
1835074e1d5SCristian Dumitrescu 		return;
1845074e1d5SCristian Dumitrescu 	}
1855074e1d5SCristian Dumitrescu 
1865074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
1875074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
1885074e1d5SCristian Dumitrescu 		return;
1895074e1d5SCristian Dumitrescu 	}
1905074e1d5SCristian Dumitrescu 
1915074e1d5SCristian Dumitrescu 	if (strcmp(tokens[4], "pool") != 0) {
1925074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
1935074e1d5SCristian Dumitrescu 		return;
1945074e1d5SCristian Dumitrescu 	}
1955074e1d5SCristian Dumitrescu 
1965074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
1975074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
1985074e1d5SCristian Dumitrescu 		return;
1995074e1d5SCristian Dumitrescu 	}
2005074e1d5SCristian Dumitrescu 
2015074e1d5SCristian Dumitrescu 	if (strcmp(tokens[6], "cache") != 0) {
2025074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
2035074e1d5SCristian Dumitrescu 		return;
2045074e1d5SCristian Dumitrescu 	}
2055074e1d5SCristian Dumitrescu 
2065074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
2075074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
2085074e1d5SCristian Dumitrescu 		return;
2095074e1d5SCristian Dumitrescu 	}
2105074e1d5SCristian Dumitrescu 
2115074e1d5SCristian Dumitrescu 	if (strcmp(tokens[8], "cpu") != 0) {
2125074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
2135074e1d5SCristian Dumitrescu 		return;
2145074e1d5SCristian Dumitrescu 	}
2155074e1d5SCristian Dumitrescu 
2165074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
2175074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
2185074e1d5SCristian Dumitrescu 		return;
2195074e1d5SCristian Dumitrescu 	}
2205074e1d5SCristian Dumitrescu 
2215074e1d5SCristian Dumitrescu 	mempool = mempool_create(obj, name, &p);
2225074e1d5SCristian Dumitrescu 	if (mempool == NULL) {
2235074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2245074e1d5SCristian Dumitrescu 		return;
2255074e1d5SCristian Dumitrescu 	}
2265074e1d5SCristian Dumitrescu }
2275074e1d5SCristian Dumitrescu 
2285074e1d5SCristian Dumitrescu static const char cmd_link_help[] =
2295074e1d5SCristian Dumitrescu "link <link_name>\n"
2305074e1d5SCristian Dumitrescu "   dev <device_name> | port <port_id>\n"
2315074e1d5SCristian Dumitrescu "   rxq <n_queues> <queue_size> <mempool_name>\n"
2325074e1d5SCristian Dumitrescu "   txq <n_queues> <queue_size>\n"
2335074e1d5SCristian Dumitrescu "   promiscuous on | off\n"
2345074e1d5SCristian Dumitrescu "   [rss <qid_0> ... <qid_n>]\n";
2355074e1d5SCristian Dumitrescu 
2365074e1d5SCristian Dumitrescu static void
2375074e1d5SCristian Dumitrescu cmd_link(char **tokens,
2385074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
2395074e1d5SCristian Dumitrescu 	char *out,
2405074e1d5SCristian Dumitrescu 	size_t out_size,
2415074e1d5SCristian Dumitrescu 	void *obj)
2425074e1d5SCristian Dumitrescu {
2435074e1d5SCristian Dumitrescu 	struct link_params p;
2445074e1d5SCristian Dumitrescu 	struct link_params_rss rss;
2455074e1d5SCristian Dumitrescu 	struct link *link;
2465074e1d5SCristian Dumitrescu 	char *name;
2475074e1d5SCristian Dumitrescu 
2485074e1d5SCristian Dumitrescu 	memset(&p, 0, sizeof(p));
2495074e1d5SCristian Dumitrescu 
2505074e1d5SCristian Dumitrescu 	if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
2515074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2525074e1d5SCristian Dumitrescu 		return;
2535074e1d5SCristian Dumitrescu 	}
2545074e1d5SCristian Dumitrescu 	name = tokens[1];
2555074e1d5SCristian Dumitrescu 
2565074e1d5SCristian Dumitrescu 	if (strcmp(tokens[2], "dev") == 0)
2575074e1d5SCristian Dumitrescu 		p.dev_name = tokens[3];
2585074e1d5SCristian Dumitrescu 	else if (strcmp(tokens[2], "port") == 0) {
2595074e1d5SCristian Dumitrescu 		p.dev_name = NULL;
2605074e1d5SCristian Dumitrescu 
2615074e1d5SCristian Dumitrescu 		if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
2625074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2635074e1d5SCristian Dumitrescu 			return;
2645074e1d5SCristian Dumitrescu 		}
2655074e1d5SCristian Dumitrescu 	} else {
2665074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
2675074e1d5SCristian Dumitrescu 		return;
2685074e1d5SCristian Dumitrescu 	}
2695074e1d5SCristian Dumitrescu 
2705074e1d5SCristian Dumitrescu 	if (strcmp(tokens[4], "rxq") != 0) {
2715074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
2725074e1d5SCristian Dumitrescu 		return;
2735074e1d5SCristian Dumitrescu 	}
2745074e1d5SCristian Dumitrescu 
2755074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
2765074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
2775074e1d5SCristian Dumitrescu 		return;
2785074e1d5SCristian Dumitrescu 	}
2795074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
2805074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
2815074e1d5SCristian Dumitrescu 		return;
2825074e1d5SCristian Dumitrescu 	}
2835074e1d5SCristian Dumitrescu 
2845074e1d5SCristian Dumitrescu 	p.rx.mempool_name = tokens[7];
2855074e1d5SCristian Dumitrescu 
2865074e1d5SCristian Dumitrescu 	if (strcmp(tokens[8], "txq") != 0) {
2875074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
2885074e1d5SCristian Dumitrescu 		return;
2895074e1d5SCristian Dumitrescu 	}
2905074e1d5SCristian Dumitrescu 
2915074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
2925074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
2935074e1d5SCristian Dumitrescu 		return;
2945074e1d5SCristian Dumitrescu 	}
2955074e1d5SCristian Dumitrescu 
2965074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
2975074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
2985074e1d5SCristian Dumitrescu 		return;
2995074e1d5SCristian Dumitrescu 	}
3005074e1d5SCristian Dumitrescu 
3015074e1d5SCristian Dumitrescu 	if (strcmp(tokens[11], "promiscuous") != 0) {
3025074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
3035074e1d5SCristian Dumitrescu 		return;
3045074e1d5SCristian Dumitrescu 	}
3055074e1d5SCristian Dumitrescu 
3065074e1d5SCristian Dumitrescu 	if (strcmp(tokens[12], "on") == 0)
3075074e1d5SCristian Dumitrescu 		p.promiscuous = 1;
3085074e1d5SCristian Dumitrescu 	else if (strcmp(tokens[12], "off") == 0)
3095074e1d5SCristian Dumitrescu 		p.promiscuous = 0;
3105074e1d5SCristian Dumitrescu 	else {
3115074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
3125074e1d5SCristian Dumitrescu 		return;
3135074e1d5SCristian Dumitrescu 	}
3145074e1d5SCristian Dumitrescu 
3155074e1d5SCristian Dumitrescu 	/* RSS */
3165074e1d5SCristian Dumitrescu 	p.rx.rss = NULL;
3175074e1d5SCristian Dumitrescu 	if (n_tokens > 13) {
3185074e1d5SCristian Dumitrescu 		uint32_t queue_id, i;
3195074e1d5SCristian Dumitrescu 
3205074e1d5SCristian Dumitrescu 		if (strcmp(tokens[13], "rss") != 0) {
3215074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
3225074e1d5SCristian Dumitrescu 			return;
3235074e1d5SCristian Dumitrescu 		}
3245074e1d5SCristian Dumitrescu 
3255074e1d5SCristian Dumitrescu 		p.rx.rss = &rss;
3265074e1d5SCristian Dumitrescu 
3275074e1d5SCristian Dumitrescu 		rss.n_queues = 0;
3285074e1d5SCristian Dumitrescu 		for (i = 14; i < n_tokens; i++) {
3295074e1d5SCristian Dumitrescu 			if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
3305074e1d5SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_INVALID,
3315074e1d5SCristian Dumitrescu 					"queue_id");
3325074e1d5SCristian Dumitrescu 				return;
3335074e1d5SCristian Dumitrescu 			}
3345074e1d5SCristian Dumitrescu 
3355074e1d5SCristian Dumitrescu 			rss.queue_id[rss.n_queues] = queue_id;
3365074e1d5SCristian Dumitrescu 			rss.n_queues++;
3375074e1d5SCristian Dumitrescu 		}
3385074e1d5SCristian Dumitrescu 	}
3395074e1d5SCristian Dumitrescu 
3405074e1d5SCristian Dumitrescu 	link = link_create(obj, name, &p);
3415074e1d5SCristian Dumitrescu 	if (link == NULL) {
3425074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3435074e1d5SCristian Dumitrescu 		return;
3445074e1d5SCristian Dumitrescu 	}
3455074e1d5SCristian Dumitrescu }
3465074e1d5SCristian Dumitrescu 
3475074e1d5SCristian Dumitrescu /* Print the link stats and info */
3485074e1d5SCristian Dumitrescu static void
3495074e1d5SCristian Dumitrescu print_link_info(struct link *link, char *out, size_t out_size)
3505074e1d5SCristian Dumitrescu {
3515074e1d5SCristian Dumitrescu 	struct rte_eth_stats stats;
3525074e1d5SCristian Dumitrescu 	struct rte_ether_addr mac_addr;
3535074e1d5SCristian Dumitrescu 	struct rte_eth_link eth_link;
3545074e1d5SCristian Dumitrescu 	uint16_t mtu;
3555074e1d5SCristian Dumitrescu 	int ret;
3565074e1d5SCristian Dumitrescu 
3575074e1d5SCristian Dumitrescu 	memset(&stats, 0, sizeof(stats));
3585074e1d5SCristian Dumitrescu 	rte_eth_stats_get(link->port_id, &stats);
3595074e1d5SCristian Dumitrescu 
3605074e1d5SCristian Dumitrescu 	ret = rte_eth_macaddr_get(link->port_id, &mac_addr);
3615074e1d5SCristian Dumitrescu 	if (ret != 0) {
3625074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s: MAC address get failed: %s",
3635074e1d5SCristian Dumitrescu 			 link->name, rte_strerror(-ret));
3645074e1d5SCristian Dumitrescu 		return;
3655074e1d5SCristian Dumitrescu 	}
3665074e1d5SCristian Dumitrescu 
3675074e1d5SCristian Dumitrescu 	ret = rte_eth_link_get(link->port_id, &eth_link);
3685074e1d5SCristian Dumitrescu 	if (ret < 0) {
3695074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s: link get failed: %s",
3705074e1d5SCristian Dumitrescu 			 link->name, rte_strerror(-ret));
3715074e1d5SCristian Dumitrescu 		return;
3725074e1d5SCristian Dumitrescu 	}
3735074e1d5SCristian Dumitrescu 
3745074e1d5SCristian Dumitrescu 	rte_eth_dev_get_mtu(link->port_id, &mtu);
3755074e1d5SCristian Dumitrescu 
3765074e1d5SCristian Dumitrescu 	snprintf(out, out_size,
3775074e1d5SCristian Dumitrescu 		"\n"
3785074e1d5SCristian Dumitrescu 		"%s: flags=<%s> mtu %u\n"
379c2c4f87bSAman Deep Singh 		"\tether " RTE_ETHER_ADDR_PRT_FMT " rxqueues %u txqueues %u\n"
3805074e1d5SCristian Dumitrescu 		"\tport# %u  speed %s\n"
3815074e1d5SCristian Dumitrescu 		"\tRX packets %" PRIu64"  bytes %" PRIu64"\n"
3825074e1d5SCristian Dumitrescu 		"\tRX errors %" PRIu64"  missed %" PRIu64"  no-mbuf %" PRIu64"\n"
3835074e1d5SCristian Dumitrescu 		"\tTX packets %" PRIu64"  bytes %" PRIu64"\n"
3845074e1d5SCristian Dumitrescu 		"\tTX errors %" PRIu64"\n",
3855074e1d5SCristian Dumitrescu 		link->name,
3865074e1d5SCristian Dumitrescu 		eth_link.link_status == 0 ? "DOWN" : "UP",
3875074e1d5SCristian Dumitrescu 		mtu,
388a7db3afcSAman Deep Singh 		RTE_ETHER_ADDR_BYTES(&mac_addr),
3895074e1d5SCristian Dumitrescu 		link->n_rxq,
3905074e1d5SCristian Dumitrescu 		link->n_txq,
3915074e1d5SCristian Dumitrescu 		link->port_id,
3925074e1d5SCristian Dumitrescu 		rte_eth_link_speed_to_str(eth_link.link_speed),
3935074e1d5SCristian Dumitrescu 		stats.ipackets,
3945074e1d5SCristian Dumitrescu 		stats.ibytes,
3955074e1d5SCristian Dumitrescu 		stats.ierrors,
3965074e1d5SCristian Dumitrescu 		stats.imissed,
3975074e1d5SCristian Dumitrescu 		stats.rx_nombuf,
3985074e1d5SCristian Dumitrescu 		stats.opackets,
3995074e1d5SCristian Dumitrescu 		stats.obytes,
4005074e1d5SCristian Dumitrescu 		stats.oerrors);
4015074e1d5SCristian Dumitrescu }
4025074e1d5SCristian Dumitrescu 
4035074e1d5SCristian Dumitrescu /*
4045074e1d5SCristian Dumitrescu  * link show [<link_name>]
4055074e1d5SCristian Dumitrescu  */
4065074e1d5SCristian Dumitrescu static void
4075074e1d5SCristian Dumitrescu cmd_link_show(char **tokens,
4085074e1d5SCristian Dumitrescu 	      uint32_t n_tokens,
4095074e1d5SCristian Dumitrescu 	      char *out,
4105074e1d5SCristian Dumitrescu 	      size_t out_size,
4115074e1d5SCristian Dumitrescu 	      void *obj)
4125074e1d5SCristian Dumitrescu {
4135074e1d5SCristian Dumitrescu 	struct link *link;
4145074e1d5SCristian Dumitrescu 	char *link_name;
4155074e1d5SCristian Dumitrescu 
4165074e1d5SCristian Dumitrescu 	if (n_tokens != 2 && n_tokens != 3) {
4175074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4185074e1d5SCristian Dumitrescu 		return;
4195074e1d5SCristian Dumitrescu 	}
4205074e1d5SCristian Dumitrescu 
4215074e1d5SCristian Dumitrescu 	if (n_tokens == 2) {
4225074e1d5SCristian Dumitrescu 		link = link_next(obj, NULL);
4235074e1d5SCristian Dumitrescu 
4245074e1d5SCristian Dumitrescu 		while (link != NULL) {
4255074e1d5SCristian Dumitrescu 			out_size = out_size - strlen(out);
4265074e1d5SCristian Dumitrescu 			out = &out[strlen(out)];
4275074e1d5SCristian Dumitrescu 
4285074e1d5SCristian Dumitrescu 			print_link_info(link, out, out_size);
4295074e1d5SCristian Dumitrescu 			link = link_next(obj, link);
4305074e1d5SCristian Dumitrescu 		}
4315074e1d5SCristian Dumitrescu 	} else {
4325074e1d5SCristian Dumitrescu 		out_size = out_size - strlen(out);
4335074e1d5SCristian Dumitrescu 		out = &out[strlen(out)];
4345074e1d5SCristian Dumitrescu 
4355074e1d5SCristian Dumitrescu 		link_name = tokens[2];
4365074e1d5SCristian Dumitrescu 		link = link_find(obj, link_name);
4375074e1d5SCristian Dumitrescu 
4385074e1d5SCristian Dumitrescu 		if (link == NULL) {
4395074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
4405074e1d5SCristian Dumitrescu 					"Link does not exist");
4415074e1d5SCristian Dumitrescu 			return;
4425074e1d5SCristian Dumitrescu 		}
4435074e1d5SCristian Dumitrescu 		print_link_info(link, out, out_size);
4445074e1d5SCristian Dumitrescu 	}
4455074e1d5SCristian Dumitrescu }
4465074e1d5SCristian Dumitrescu 
44777a41301SCristian Dumitrescu static const char cmd_ring_help[] =
44877a41301SCristian Dumitrescu "ring <ring_name> size <size> numa <numa_node>\n";
44977a41301SCristian Dumitrescu 
45077a41301SCristian Dumitrescu static void
45177a41301SCristian Dumitrescu cmd_ring(char **tokens,
45277a41301SCristian Dumitrescu 	uint32_t n_tokens,
45377a41301SCristian Dumitrescu 	char *out,
45477a41301SCristian Dumitrescu 	size_t out_size,
45577a41301SCristian Dumitrescu 	void *obj)
45677a41301SCristian Dumitrescu {
45777a41301SCristian Dumitrescu 	struct ring_params p;
45877a41301SCristian Dumitrescu 	char *name;
45977a41301SCristian Dumitrescu 	struct ring *ring;
46077a41301SCristian Dumitrescu 
46177a41301SCristian Dumitrescu 	if (n_tokens != 6) {
46277a41301SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
46377a41301SCristian Dumitrescu 		return;
46477a41301SCristian Dumitrescu 	}
46577a41301SCristian Dumitrescu 
46677a41301SCristian Dumitrescu 	name = tokens[1];
46777a41301SCristian Dumitrescu 
46877a41301SCristian Dumitrescu 	if (strcmp(tokens[2], "size") != 0) {
46977a41301SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
47077a41301SCristian Dumitrescu 		return;
47177a41301SCristian Dumitrescu 	}
47277a41301SCristian Dumitrescu 
47377a41301SCristian Dumitrescu 	if (parser_read_uint32(&p.size, tokens[3]) != 0) {
47477a41301SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "size");
47577a41301SCristian Dumitrescu 		return;
47677a41301SCristian Dumitrescu 	}
47777a41301SCristian Dumitrescu 
47877a41301SCristian Dumitrescu 	if (strcmp(tokens[4], "numa") != 0) {
47977a41301SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "numa");
48077a41301SCristian Dumitrescu 		return;
48177a41301SCristian Dumitrescu 	}
48277a41301SCristian Dumitrescu 
48377a41301SCristian Dumitrescu 	if (parser_read_uint32(&p.numa_node, tokens[5]) != 0) {
48477a41301SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "numa_node");
48577a41301SCristian Dumitrescu 		return;
48677a41301SCristian Dumitrescu 	}
48777a41301SCristian Dumitrescu 
48877a41301SCristian Dumitrescu 	ring = ring_create(obj, name, &p);
48977a41301SCristian Dumitrescu 	if (!ring) {
49077a41301SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
49177a41301SCristian Dumitrescu 		return;
49277a41301SCristian Dumitrescu 	}
49377a41301SCristian Dumitrescu }
49477a41301SCristian Dumitrescu 
495e2b8dc52SVenkata Suresh Kumar P static const char cmd_tap_help[] =
496e2b8dc52SVenkata Suresh Kumar P "tap <tap_name>\n";
497e2b8dc52SVenkata Suresh Kumar P 
498e2b8dc52SVenkata Suresh Kumar P static void
499e2b8dc52SVenkata Suresh Kumar P cmd_tap(char **tokens,
500e2b8dc52SVenkata Suresh Kumar P 	uint32_t n_tokens,
501e2b8dc52SVenkata Suresh Kumar P 	char *out,
502e2b8dc52SVenkata Suresh Kumar P 	size_t out_size,
503e2b8dc52SVenkata Suresh Kumar P 	void *obj)
504e2b8dc52SVenkata Suresh Kumar P {
505e2b8dc52SVenkata Suresh Kumar P 	struct tap *tap;
506e2b8dc52SVenkata Suresh Kumar P 	char *name;
507e2b8dc52SVenkata Suresh Kumar P 
508e2b8dc52SVenkata Suresh Kumar P 	if (n_tokens < 2) {
509e2b8dc52SVenkata Suresh Kumar P 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
510e2b8dc52SVenkata Suresh Kumar P 		return;
511e2b8dc52SVenkata Suresh Kumar P 	}
512e2b8dc52SVenkata Suresh Kumar P 	name = tokens[1];
513e2b8dc52SVenkata Suresh Kumar P 
514e2b8dc52SVenkata Suresh Kumar P 	tap = tap_create(obj, name);
515e2b8dc52SVenkata Suresh Kumar P 	if (tap == NULL) {
516e2b8dc52SVenkata Suresh Kumar P 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
517e2b8dc52SVenkata Suresh Kumar P 		return;
518e2b8dc52SVenkata Suresh Kumar P 	}
519e2b8dc52SVenkata Suresh Kumar P }
520e2b8dc52SVenkata Suresh Kumar P 
5215074e1d5SCristian Dumitrescu static const char cmd_pipeline_create_help[] =
5225074e1d5SCristian Dumitrescu "pipeline <pipeline_name> create <numa_node>\n";
5235074e1d5SCristian Dumitrescu 
5245074e1d5SCristian Dumitrescu static void
5255074e1d5SCristian Dumitrescu cmd_pipeline_create(char **tokens,
5265074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
5275074e1d5SCristian Dumitrescu 	char *out,
5285074e1d5SCristian Dumitrescu 	size_t out_size,
5295074e1d5SCristian Dumitrescu 	void *obj)
5305074e1d5SCristian Dumitrescu {
5315074e1d5SCristian Dumitrescu 	struct pipeline *p;
5325074e1d5SCristian Dumitrescu 	char *name;
5335074e1d5SCristian Dumitrescu 	uint32_t numa_node;
5345074e1d5SCristian Dumitrescu 
5355074e1d5SCristian Dumitrescu 	if (n_tokens != 4) {
5365074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5375074e1d5SCristian Dumitrescu 		return;
5385074e1d5SCristian Dumitrescu 	}
5395074e1d5SCristian Dumitrescu 
5405074e1d5SCristian Dumitrescu 	name = tokens[1];
5415074e1d5SCristian Dumitrescu 
5425074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&numa_node, tokens[3]) != 0) {
5435074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "numa_node");
5445074e1d5SCristian Dumitrescu 		return;
5455074e1d5SCristian Dumitrescu 	}
5465074e1d5SCristian Dumitrescu 
5475074e1d5SCristian Dumitrescu 	p = pipeline_create(obj, name, (int)numa_node);
5485074e1d5SCristian Dumitrescu 	if (!p) {
5495074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "pipeline create error.");
5505074e1d5SCristian Dumitrescu 		return;
5515074e1d5SCristian Dumitrescu 	}
5525074e1d5SCristian Dumitrescu }
5535074e1d5SCristian Dumitrescu 
5545074e1d5SCristian Dumitrescu static const char cmd_pipeline_port_in_help[] =
5555074e1d5SCristian Dumitrescu "pipeline <pipeline_name> port in <port_id>\n"
5565074e1d5SCristian Dumitrescu "   link <link_name> rxq <queue_id> bsz <burst_size>\n"
55777a41301SCristian Dumitrescu "   ring <ring_name> bsz <burst_size>\n"
5580317c452SYogesh Jangra "   | source <mempool_name> <file_name> loop <n_loops>\n"
559e2b8dc52SVenkata Suresh Kumar P "   | tap <tap_name> mempool <mempool_name> mtu <mtu> bsz <burst_size>\n";
5605074e1d5SCristian Dumitrescu 
5615074e1d5SCristian Dumitrescu static void
5625074e1d5SCristian Dumitrescu cmd_pipeline_port_in(char **tokens,
5635074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
5645074e1d5SCristian Dumitrescu 	char *out,
5655074e1d5SCristian Dumitrescu 	size_t out_size,
5665074e1d5SCristian Dumitrescu 	void *obj)
5675074e1d5SCristian Dumitrescu {
5685074e1d5SCristian Dumitrescu 	struct pipeline *p;
5695074e1d5SCristian Dumitrescu 	int status;
5705074e1d5SCristian Dumitrescu 	uint32_t port_id = 0, t0;
5715074e1d5SCristian Dumitrescu 
5725074e1d5SCristian Dumitrescu 	if (n_tokens < 6) {
5735074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5745074e1d5SCristian Dumitrescu 		return;
5755074e1d5SCristian Dumitrescu 	}
5765074e1d5SCristian Dumitrescu 
5775074e1d5SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
5785074e1d5SCristian Dumitrescu 	if (!p || p->ctl) {
5795074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5805074e1d5SCristian Dumitrescu 		return;
5815074e1d5SCristian Dumitrescu 	}
5825074e1d5SCristian Dumitrescu 
5835074e1d5SCristian Dumitrescu 	if (strcmp(tokens[2], "port") != 0) {
5845074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
5855074e1d5SCristian Dumitrescu 		return;
5865074e1d5SCristian Dumitrescu 	}
5875074e1d5SCristian Dumitrescu 
5885074e1d5SCristian Dumitrescu 	if (strcmp(tokens[3], "in") != 0) {
5895074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
5905074e1d5SCristian Dumitrescu 		return;
5915074e1d5SCristian Dumitrescu 	}
5925074e1d5SCristian Dumitrescu 
5935074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
5945074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
5955074e1d5SCristian Dumitrescu 		return;
5965074e1d5SCristian Dumitrescu 	}
5975074e1d5SCristian Dumitrescu 
5985074e1d5SCristian Dumitrescu 	t0 = 5;
5995074e1d5SCristian Dumitrescu 
6005074e1d5SCristian Dumitrescu 	if (strcmp(tokens[t0], "link") == 0) {
6015074e1d5SCristian Dumitrescu 		struct rte_swx_port_ethdev_reader_params params;
6025074e1d5SCristian Dumitrescu 		struct link *link;
6035074e1d5SCristian Dumitrescu 
6045074e1d5SCristian Dumitrescu 		if (n_tokens < t0 + 6) {
6055074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_MISMATCH,
6065074e1d5SCristian Dumitrescu 				"pipeline port in link");
6075074e1d5SCristian Dumitrescu 			return;
6085074e1d5SCristian Dumitrescu 		}
6095074e1d5SCristian Dumitrescu 
6105074e1d5SCristian Dumitrescu 		link = link_find(obj, tokens[t0 + 1]);
6115074e1d5SCristian Dumitrescu 		if (!link) {
6125074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
6135074e1d5SCristian Dumitrescu 				"link_name");
6145074e1d5SCristian Dumitrescu 			return;
6155074e1d5SCristian Dumitrescu 		}
6165074e1d5SCristian Dumitrescu 		params.dev_name = link->dev_name;
6175074e1d5SCristian Dumitrescu 
6185074e1d5SCristian Dumitrescu 		if (strcmp(tokens[t0 + 2], "rxq") != 0) {
6195074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
6205074e1d5SCristian Dumitrescu 			return;
6215074e1d5SCristian Dumitrescu 		}
6225074e1d5SCristian Dumitrescu 
6235074e1d5SCristian Dumitrescu 		if (parser_read_uint16(&params.queue_id, tokens[t0 + 3]) != 0) {
6245074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
6255074e1d5SCristian Dumitrescu 				"queue_id");
6265074e1d5SCristian Dumitrescu 			return;
6275074e1d5SCristian Dumitrescu 		}
6285074e1d5SCristian Dumitrescu 
6295074e1d5SCristian Dumitrescu 		if (strcmp(tokens[t0 + 4], "bsz") != 0) {
6305074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
6315074e1d5SCristian Dumitrescu 			return;
6325074e1d5SCristian Dumitrescu 		}
6335074e1d5SCristian Dumitrescu 
6345074e1d5SCristian Dumitrescu 		if (parser_read_uint32(&params.burst_size, tokens[t0 + 5])) {
6355074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
6365074e1d5SCristian Dumitrescu 				"burst_size");
6375074e1d5SCristian Dumitrescu 			return;
6385074e1d5SCristian Dumitrescu 		}
6395074e1d5SCristian Dumitrescu 
6405074e1d5SCristian Dumitrescu 		t0 += 6;
6415074e1d5SCristian Dumitrescu 
6425074e1d5SCristian Dumitrescu 		status = rte_swx_pipeline_port_in_config(p->p,
6435074e1d5SCristian Dumitrescu 			port_id,
6445074e1d5SCristian Dumitrescu 			"ethdev",
6455074e1d5SCristian Dumitrescu 			&params);
64677a41301SCristian Dumitrescu 	} else if (strcmp(tokens[t0], "ring") == 0) {
64777a41301SCristian Dumitrescu 		struct rte_swx_port_ring_reader_params params;
64877a41301SCristian Dumitrescu 		struct ring *ring;
64977a41301SCristian Dumitrescu 
65077a41301SCristian Dumitrescu 		if (n_tokens < t0 + 4) {
65177a41301SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_MISMATCH,
65277a41301SCristian Dumitrescu 				"pipeline port in ring");
65377a41301SCristian Dumitrescu 			return;
65477a41301SCristian Dumitrescu 		}
65577a41301SCristian Dumitrescu 
65677a41301SCristian Dumitrescu 		ring = ring_find(obj, tokens[t0 + 1]);
65777a41301SCristian Dumitrescu 		if (!ring) {
65877a41301SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
65977a41301SCristian Dumitrescu 				"ring_name");
66077a41301SCristian Dumitrescu 			return;
66177a41301SCristian Dumitrescu 		}
66277a41301SCristian Dumitrescu 		params.name = ring->name;
66377a41301SCristian Dumitrescu 
66477a41301SCristian Dumitrescu 		if (strcmp(tokens[t0 + 2], "bsz") != 0) {
66577a41301SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
66677a41301SCristian Dumitrescu 			return;
66777a41301SCristian Dumitrescu 		}
66877a41301SCristian Dumitrescu 
66977a41301SCristian Dumitrescu 		if (parser_read_uint32(&params.burst_size, tokens[t0 + 3])) {
67077a41301SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
67177a41301SCristian Dumitrescu 				"burst_size");
67277a41301SCristian Dumitrescu 			return;
67377a41301SCristian Dumitrescu 		}
67477a41301SCristian Dumitrescu 
67577a41301SCristian Dumitrescu 		t0 += 4;
67677a41301SCristian Dumitrescu 
67777a41301SCristian Dumitrescu 		status = rte_swx_pipeline_port_in_config(p->p,
67877a41301SCristian Dumitrescu 			port_id,
67977a41301SCristian Dumitrescu 			"ring",
68077a41301SCristian Dumitrescu 			&params);
6815074e1d5SCristian Dumitrescu 	} else if (strcmp(tokens[t0], "source") == 0) {
6825074e1d5SCristian Dumitrescu 		struct rte_swx_port_source_params params;
6835074e1d5SCristian Dumitrescu 		struct mempool *mp;
6845074e1d5SCristian Dumitrescu 
6850317c452SYogesh Jangra 		if (n_tokens < t0 + 5) {
6865074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_MISMATCH,
6875074e1d5SCristian Dumitrescu 				"pipeline port in source");
6885074e1d5SCristian Dumitrescu 			return;
6895074e1d5SCristian Dumitrescu 		}
6905074e1d5SCristian Dumitrescu 
6915074e1d5SCristian Dumitrescu 		mp = mempool_find(obj, tokens[t0 + 1]);
6925074e1d5SCristian Dumitrescu 		if (!mp) {
6935074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
6945074e1d5SCristian Dumitrescu 				"mempool_name");
6955074e1d5SCristian Dumitrescu 			return;
6965074e1d5SCristian Dumitrescu 		}
6975074e1d5SCristian Dumitrescu 		params.pool = mp->m;
6985074e1d5SCristian Dumitrescu 
6995074e1d5SCristian Dumitrescu 		params.file_name = tokens[t0 + 2];
7005074e1d5SCristian Dumitrescu 
7010317c452SYogesh Jangra 		if (strcmp(tokens[t0 + 3], "loop") != 0) {
7020317c452SYogesh Jangra 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "loop");
7030317c452SYogesh Jangra 			return;
7040317c452SYogesh Jangra 		}
7050317c452SYogesh Jangra 
7060317c452SYogesh Jangra 		if (parser_read_uint64(&params.n_loops, tokens[t0 + 4])) {
7070317c452SYogesh Jangra 			snprintf(out, out_size, MSG_ARG_INVALID,
7080317c452SYogesh Jangra 				"n_loops");
7090317c452SYogesh Jangra 			return;
7100317c452SYogesh Jangra 		}
7110317c452SYogesh Jangra 
7120317c452SYogesh Jangra 		t0 += 5;
7135074e1d5SCristian Dumitrescu 
7145074e1d5SCristian Dumitrescu 		status = rte_swx_pipeline_port_in_config(p->p,
7155074e1d5SCristian Dumitrescu 			port_id,
7165074e1d5SCristian Dumitrescu 			"source",
7175074e1d5SCristian Dumitrescu 			&params);
718e2b8dc52SVenkata Suresh Kumar P 	} else if (strcmp(tokens[t0], "tap") == 0) {
719e2b8dc52SVenkata Suresh Kumar P 		struct rte_swx_port_fd_reader_params params;
720e2b8dc52SVenkata Suresh Kumar P 		struct tap *tap;
721e2b8dc52SVenkata Suresh Kumar P 		struct mempool *mp;
722e2b8dc52SVenkata Suresh Kumar P 
723e2b8dc52SVenkata Suresh Kumar P 		if (n_tokens < t0 + 8) {
724e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_MISMATCH,
725e2b8dc52SVenkata Suresh Kumar P 				"pipeline port in tap");
726e2b8dc52SVenkata Suresh Kumar P 			return;
727e2b8dc52SVenkata Suresh Kumar P 		}
728e2b8dc52SVenkata Suresh Kumar P 
729e2b8dc52SVenkata Suresh Kumar P 		tap = tap_find(obj, tokens[t0 + 1]);
730e2b8dc52SVenkata Suresh Kumar P 		if (!tap) {
731e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_INVALID,
732e2b8dc52SVenkata Suresh Kumar P 				"tap_name");
733e2b8dc52SVenkata Suresh Kumar P 			return;
734e2b8dc52SVenkata Suresh Kumar P 		}
735e2b8dc52SVenkata Suresh Kumar P 		params.fd = tap->fd;
736e2b8dc52SVenkata Suresh Kumar P 
737e2b8dc52SVenkata Suresh Kumar P 		if (strcmp(tokens[t0 + 2], "mempool") != 0) {
738e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
739e2b8dc52SVenkata Suresh Kumar P 				"mempool");
740e2b8dc52SVenkata Suresh Kumar P 			return;
741e2b8dc52SVenkata Suresh Kumar P 		}
742e2b8dc52SVenkata Suresh Kumar P 
743e2b8dc52SVenkata Suresh Kumar P 		mp = mempool_find(obj, tokens[t0 + 3]);
744e2b8dc52SVenkata Suresh Kumar P 		if (!mp) {
745e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_INVALID,
746e2b8dc52SVenkata Suresh Kumar P 				"mempool_name");
747e2b8dc52SVenkata Suresh Kumar P 			return;
748e2b8dc52SVenkata Suresh Kumar P 		}
749e2b8dc52SVenkata Suresh Kumar P 		params.mempool = mp->m;
750e2b8dc52SVenkata Suresh Kumar P 
751e2b8dc52SVenkata Suresh Kumar P 		if (strcmp(tokens[t0 + 4], "mtu") != 0) {
752e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
753e2b8dc52SVenkata Suresh Kumar P 				"mtu");
754e2b8dc52SVenkata Suresh Kumar P 			return;
755e2b8dc52SVenkata Suresh Kumar P 		}
756e2b8dc52SVenkata Suresh Kumar P 
757e2b8dc52SVenkata Suresh Kumar P 		if (parser_read_uint32(&params.mtu, tokens[t0 + 5]) != 0) {
758e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
759e2b8dc52SVenkata Suresh Kumar P 			return;
760e2b8dc52SVenkata Suresh Kumar P 		}
761e2b8dc52SVenkata Suresh Kumar P 
762e2b8dc52SVenkata Suresh Kumar P 		if (strcmp(tokens[t0 + 6], "bsz") != 0) {
763e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
764e2b8dc52SVenkata Suresh Kumar P 			return;
765e2b8dc52SVenkata Suresh Kumar P 		}
766e2b8dc52SVenkata Suresh Kumar P 
767e2b8dc52SVenkata Suresh Kumar P 		if (parser_read_uint32(&params.burst_size, tokens[t0 + 7])) {
768e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_INVALID,
769e2b8dc52SVenkata Suresh Kumar P 				"burst_size");
770e2b8dc52SVenkata Suresh Kumar P 			return;
771e2b8dc52SVenkata Suresh Kumar P 		}
772e2b8dc52SVenkata Suresh Kumar P 
773e2b8dc52SVenkata Suresh Kumar P 		t0 += 8;
774e2b8dc52SVenkata Suresh Kumar P 
775e2b8dc52SVenkata Suresh Kumar P 		status = rte_swx_pipeline_port_in_config(p->p,
776e2b8dc52SVenkata Suresh Kumar P 			port_id,
777e2b8dc52SVenkata Suresh Kumar P 			"fd",
778e2b8dc52SVenkata Suresh Kumar P 			&params);
779e2b8dc52SVenkata Suresh Kumar P 
7805074e1d5SCristian Dumitrescu 	} else {
7815074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
7825074e1d5SCristian Dumitrescu 		return;
7835074e1d5SCristian Dumitrescu 	}
7845074e1d5SCristian Dumitrescu 
7855074e1d5SCristian Dumitrescu 	if (status) {
7865074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "port in error.");
7875074e1d5SCristian Dumitrescu 		return;
7885074e1d5SCristian Dumitrescu 	}
7895074e1d5SCristian Dumitrescu 
7905074e1d5SCristian Dumitrescu 	if (n_tokens != t0) {
7915074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
7925074e1d5SCristian Dumitrescu 		return;
7935074e1d5SCristian Dumitrescu 	}
7945074e1d5SCristian Dumitrescu }
7955074e1d5SCristian Dumitrescu 
7965074e1d5SCristian Dumitrescu static const char cmd_pipeline_port_out_help[] =
7975074e1d5SCristian Dumitrescu "pipeline <pipeline_name> port out <port_id>\n"
7985074e1d5SCristian Dumitrescu "   link <link_name> txq <txq_id> bsz <burst_size>\n"
79977a41301SCristian Dumitrescu "   ring <ring_name> bsz <burst_size>\n"
800e2b8dc52SVenkata Suresh Kumar P "   | sink <file_name> | none\n"
801e2b8dc52SVenkata Suresh Kumar P "   | tap <tap_name> bsz <burst_size>\n";
8025074e1d5SCristian Dumitrescu 
8035074e1d5SCristian Dumitrescu static void
8045074e1d5SCristian Dumitrescu cmd_pipeline_port_out(char **tokens,
8055074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
8065074e1d5SCristian Dumitrescu 	char *out,
8075074e1d5SCristian Dumitrescu 	size_t out_size,
8085074e1d5SCristian Dumitrescu 	void *obj)
8095074e1d5SCristian Dumitrescu {
8105074e1d5SCristian Dumitrescu 	struct pipeline *p;
8115074e1d5SCristian Dumitrescu 	int status;
8125074e1d5SCristian Dumitrescu 	uint32_t port_id = 0, t0;
8135074e1d5SCristian Dumitrescu 
8145074e1d5SCristian Dumitrescu 	if (n_tokens < 6) {
8155074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
8165074e1d5SCristian Dumitrescu 		return;
8175074e1d5SCristian Dumitrescu 	}
8185074e1d5SCristian Dumitrescu 
8195074e1d5SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
8205074e1d5SCristian Dumitrescu 	if (!p || p->ctl) {
8215074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
8225074e1d5SCristian Dumitrescu 		return;
8235074e1d5SCristian Dumitrescu 	}
8245074e1d5SCristian Dumitrescu 
8255074e1d5SCristian Dumitrescu 	if (strcmp(tokens[2], "port") != 0) {
8265074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
8275074e1d5SCristian Dumitrescu 		return;
8285074e1d5SCristian Dumitrescu 	}
8295074e1d5SCristian Dumitrescu 
8305074e1d5SCristian Dumitrescu 	if (strcmp(tokens[3], "out") != 0) {
8315074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
8325074e1d5SCristian Dumitrescu 		return;
8335074e1d5SCristian Dumitrescu 	}
8345074e1d5SCristian Dumitrescu 
8355074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
8365074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
8375074e1d5SCristian Dumitrescu 		return;
8385074e1d5SCristian Dumitrescu 	}
8395074e1d5SCristian Dumitrescu 
8405074e1d5SCristian Dumitrescu 	t0 = 5;
8415074e1d5SCristian Dumitrescu 
8425074e1d5SCristian Dumitrescu 	if (strcmp(tokens[t0], "link") == 0) {
8435074e1d5SCristian Dumitrescu 		struct rte_swx_port_ethdev_writer_params params;
8445074e1d5SCristian Dumitrescu 		struct link *link;
8455074e1d5SCristian Dumitrescu 
8465074e1d5SCristian Dumitrescu 		if (n_tokens < t0 + 6) {
8475074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_MISMATCH,
8485074e1d5SCristian Dumitrescu 				"pipeline port out link");
8495074e1d5SCristian Dumitrescu 			return;
8505074e1d5SCristian Dumitrescu 		}
8515074e1d5SCristian Dumitrescu 
8525074e1d5SCristian Dumitrescu 		link = link_find(obj, tokens[t0 + 1]);
8535074e1d5SCristian Dumitrescu 		if (!link) {
8545074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
8555074e1d5SCristian Dumitrescu 				"link_name");
8565074e1d5SCristian Dumitrescu 			return;
8575074e1d5SCristian Dumitrescu 		}
8585074e1d5SCristian Dumitrescu 		params.dev_name = link->dev_name;
8595074e1d5SCristian Dumitrescu 
8605074e1d5SCristian Dumitrescu 		if (strcmp(tokens[t0 + 2], "txq") != 0) {
8615074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
8625074e1d5SCristian Dumitrescu 			return;
8635074e1d5SCristian Dumitrescu 		}
8645074e1d5SCristian Dumitrescu 
8655074e1d5SCristian Dumitrescu 		if (parser_read_uint16(&params.queue_id, tokens[t0 + 3]) != 0) {
8665074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
8675074e1d5SCristian Dumitrescu 				"queue_id");
8685074e1d5SCristian Dumitrescu 			return;
8695074e1d5SCristian Dumitrescu 		}
8705074e1d5SCristian Dumitrescu 
8715074e1d5SCristian Dumitrescu 		if (strcmp(tokens[t0 + 4], "bsz") != 0) {
8725074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
8735074e1d5SCristian Dumitrescu 			return;
8745074e1d5SCristian Dumitrescu 		}
8755074e1d5SCristian Dumitrescu 
8765074e1d5SCristian Dumitrescu 		if (parser_read_uint32(&params.burst_size, tokens[t0 + 5])) {
8775074e1d5SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
8785074e1d5SCristian Dumitrescu 				"burst_size");
8795074e1d5SCristian Dumitrescu 			return;
8805074e1d5SCristian Dumitrescu 		}
8815074e1d5SCristian Dumitrescu 
8825074e1d5SCristian Dumitrescu 		t0 += 6;
8835074e1d5SCristian Dumitrescu 
8845074e1d5SCristian Dumitrescu 		status = rte_swx_pipeline_port_out_config(p->p,
8855074e1d5SCristian Dumitrescu 			port_id,
8865074e1d5SCristian Dumitrescu 			"ethdev",
8875074e1d5SCristian Dumitrescu 			&params);
88877a41301SCristian Dumitrescu 	} else if (strcmp(tokens[t0], "ring") == 0) {
88977a41301SCristian Dumitrescu 		struct rte_swx_port_ring_writer_params params;
89077a41301SCristian Dumitrescu 		struct ring *ring;
89177a41301SCristian Dumitrescu 
89277a41301SCristian Dumitrescu 		if (n_tokens < t0 + 4) {
89377a41301SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_MISMATCH,
89477a41301SCristian Dumitrescu 				"pipeline port out link");
89577a41301SCristian Dumitrescu 			return;
89677a41301SCristian Dumitrescu 		}
89777a41301SCristian Dumitrescu 
89877a41301SCristian Dumitrescu 		ring = ring_find(obj, tokens[t0 + 1]);
89977a41301SCristian Dumitrescu 		if (!ring) {
90077a41301SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
90177a41301SCristian Dumitrescu 				"ring_name");
90277a41301SCristian Dumitrescu 			return;
90377a41301SCristian Dumitrescu 		}
90477a41301SCristian Dumitrescu 		params.name = ring->name;
90577a41301SCristian Dumitrescu 
90677a41301SCristian Dumitrescu 		if (strcmp(tokens[t0 + 2], "bsz") != 0) {
90777a41301SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
90877a41301SCristian Dumitrescu 			return;
90977a41301SCristian Dumitrescu 		}
91077a41301SCristian Dumitrescu 
91177a41301SCristian Dumitrescu 		if (parser_read_uint32(&params.burst_size, tokens[t0 + 3])) {
91277a41301SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
91377a41301SCristian Dumitrescu 				"burst_size");
91477a41301SCristian Dumitrescu 			return;
91577a41301SCristian Dumitrescu 		}
91677a41301SCristian Dumitrescu 
91777a41301SCristian Dumitrescu 		t0 += 4;
91877a41301SCristian Dumitrescu 
91977a41301SCristian Dumitrescu 		status = rte_swx_pipeline_port_out_config(p->p,
92077a41301SCristian Dumitrescu 			port_id,
92177a41301SCristian Dumitrescu 			"ring",
92277a41301SCristian Dumitrescu 			&params);
9235074e1d5SCristian Dumitrescu 	} else if (strcmp(tokens[t0], "sink") == 0) {
9245074e1d5SCristian Dumitrescu 		struct rte_swx_port_sink_params params;
9255074e1d5SCristian Dumitrescu 
9265074e1d5SCristian Dumitrescu 		params.file_name = strcmp(tokens[t0 + 1], "none") ?
9275074e1d5SCristian Dumitrescu 			tokens[t0 + 1] : NULL;
9285074e1d5SCristian Dumitrescu 
9295074e1d5SCristian Dumitrescu 		t0 += 2;
9305074e1d5SCristian Dumitrescu 
9315074e1d5SCristian Dumitrescu 		status = rte_swx_pipeline_port_out_config(p->p,
9325074e1d5SCristian Dumitrescu 			port_id,
9335074e1d5SCristian Dumitrescu 			"sink",
9345074e1d5SCristian Dumitrescu 			&params);
935e2b8dc52SVenkata Suresh Kumar P 	} else if (strcmp(tokens[t0], "tap") == 0) {
936e2b8dc52SVenkata Suresh Kumar P 		struct rte_swx_port_fd_writer_params params;
937e2b8dc52SVenkata Suresh Kumar P 		struct tap *tap;
938e2b8dc52SVenkata Suresh Kumar P 
939e2b8dc52SVenkata Suresh Kumar P 		if (n_tokens < t0 + 4) {
940e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_MISMATCH,
941e2b8dc52SVenkata Suresh Kumar P 				"pipeline port out tap");
942e2b8dc52SVenkata Suresh Kumar P 			return;
943e2b8dc52SVenkata Suresh Kumar P 		}
944e2b8dc52SVenkata Suresh Kumar P 
945e2b8dc52SVenkata Suresh Kumar P 		tap = tap_find(obj, tokens[t0 + 1]);
946e2b8dc52SVenkata Suresh Kumar P 		if (!tap) {
947e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_INVALID,
948e2b8dc52SVenkata Suresh Kumar P 				"tap_name");
949e2b8dc52SVenkata Suresh Kumar P 			return;
950e2b8dc52SVenkata Suresh Kumar P 		}
951e2b8dc52SVenkata Suresh Kumar P 		params.fd = tap->fd;
952e2b8dc52SVenkata Suresh Kumar P 
953e2b8dc52SVenkata Suresh Kumar P 		if (strcmp(tokens[t0 + 2], "bsz") != 0) {
954e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
955e2b8dc52SVenkata Suresh Kumar P 			return;
956e2b8dc52SVenkata Suresh Kumar P 		}
957e2b8dc52SVenkata Suresh Kumar P 
958e2b8dc52SVenkata Suresh Kumar P 		if (parser_read_uint32(&params.burst_size, tokens[t0 + 3])) {
959e2b8dc52SVenkata Suresh Kumar P 			snprintf(out, out_size, MSG_ARG_INVALID,
960e2b8dc52SVenkata Suresh Kumar P 				"burst_size");
961e2b8dc52SVenkata Suresh Kumar P 			return;
962e2b8dc52SVenkata Suresh Kumar P 		}
963e2b8dc52SVenkata Suresh Kumar P 
964e2b8dc52SVenkata Suresh Kumar P 		t0 += 4;
965e2b8dc52SVenkata Suresh Kumar P 
966e2b8dc52SVenkata Suresh Kumar P 		status = rte_swx_pipeline_port_out_config(p->p,
967e2b8dc52SVenkata Suresh Kumar P 			port_id,
968e2b8dc52SVenkata Suresh Kumar P 			"fd",
969e2b8dc52SVenkata Suresh Kumar P 			&params);
9705074e1d5SCristian Dumitrescu 	} else {
9715074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
9725074e1d5SCristian Dumitrescu 		return;
9735074e1d5SCristian Dumitrescu 	}
9745074e1d5SCristian Dumitrescu 
9755074e1d5SCristian Dumitrescu 	if (status) {
9765074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "port out error.");
9775074e1d5SCristian Dumitrescu 		return;
9785074e1d5SCristian Dumitrescu 	}
9795074e1d5SCristian Dumitrescu 
9805074e1d5SCristian Dumitrescu 	if (n_tokens != t0) {
9815074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
9825074e1d5SCristian Dumitrescu 		return;
9835074e1d5SCristian Dumitrescu 	}
9845074e1d5SCristian Dumitrescu }
9855074e1d5SCristian Dumitrescu 
9865074e1d5SCristian Dumitrescu static const char cmd_pipeline_build_help[] =
9875074e1d5SCristian Dumitrescu "pipeline <pipeline_name> build <spec_file>\n";
9885074e1d5SCristian Dumitrescu 
9895074e1d5SCristian Dumitrescu static void
9905074e1d5SCristian Dumitrescu cmd_pipeline_build(char **tokens,
9915074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
9925074e1d5SCristian Dumitrescu 	char *out,
9935074e1d5SCristian Dumitrescu 	size_t out_size,
9945074e1d5SCristian Dumitrescu 	void *obj)
9955074e1d5SCristian Dumitrescu {
9965074e1d5SCristian Dumitrescu 	struct pipeline *p = NULL;
9975074e1d5SCristian Dumitrescu 	FILE *spec = NULL;
9985074e1d5SCristian Dumitrescu 	uint32_t err_line;
9995074e1d5SCristian Dumitrescu 	const char *err_msg;
10005074e1d5SCristian Dumitrescu 	int status;
10015074e1d5SCristian Dumitrescu 
10025074e1d5SCristian Dumitrescu 	if (n_tokens != 4) {
10035074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
10045074e1d5SCristian Dumitrescu 		return;
10055074e1d5SCristian Dumitrescu 	}
10065074e1d5SCristian Dumitrescu 
10075074e1d5SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
10085074e1d5SCristian Dumitrescu 	if (!p || p->ctl) {
10095074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
10105074e1d5SCristian Dumitrescu 		return;
10115074e1d5SCristian Dumitrescu 	}
10125074e1d5SCristian Dumitrescu 
10135074e1d5SCristian Dumitrescu 	spec = fopen(tokens[3], "r");
10145074e1d5SCristian Dumitrescu 	if (!spec) {
10155074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "Cannot open file %s.\n", tokens[3]);
10165074e1d5SCristian Dumitrescu 		return;
10175074e1d5SCristian Dumitrescu 	}
10185074e1d5SCristian Dumitrescu 
10195074e1d5SCristian Dumitrescu 	status = rte_swx_pipeline_build_from_spec(p->p,
10205074e1d5SCristian Dumitrescu 		spec,
10215074e1d5SCristian Dumitrescu 		&err_line,
10225074e1d5SCristian Dumitrescu 		&err_msg);
10235074e1d5SCristian Dumitrescu 	fclose(spec);
10245074e1d5SCristian Dumitrescu 	if (status) {
10255074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "Error %d at line %u: %s\n.",
10265074e1d5SCristian Dumitrescu 			status, err_line, err_msg);
10275074e1d5SCristian Dumitrescu 		return;
10285074e1d5SCristian Dumitrescu 	}
10295074e1d5SCristian Dumitrescu 
10305074e1d5SCristian Dumitrescu 	p->ctl = rte_swx_ctl_pipeline_create(p->p);
10315074e1d5SCristian Dumitrescu 	if (!p->ctl) {
10325074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "Pipeline control create failed.");
10335074e1d5SCristian Dumitrescu 		rte_swx_pipeline_free(p->p);
10345074e1d5SCristian Dumitrescu 		return;
10355074e1d5SCristian Dumitrescu 	}
10365074e1d5SCristian Dumitrescu }
10375074e1d5SCristian Dumitrescu 
1038275ebefeSCristian Dumitrescu static void
1039275ebefeSCristian Dumitrescu table_entry_free(struct rte_swx_table_entry *entry)
1040275ebefeSCristian Dumitrescu {
1041275ebefeSCristian Dumitrescu 	if (!entry)
1042275ebefeSCristian Dumitrescu 		return;
1043275ebefeSCristian Dumitrescu 
1044275ebefeSCristian Dumitrescu 	free(entry->key);
1045275ebefeSCristian Dumitrescu 	free(entry->key_mask);
1046275ebefeSCristian Dumitrescu 	free(entry->action_data);
1047275ebefeSCristian Dumitrescu 	free(entry);
1048275ebefeSCristian Dumitrescu }
1049275ebefeSCristian Dumitrescu 
105075129cebSChurchill Khangar #ifndef MAX_LINE_SIZE
105175129cebSChurchill Khangar #define MAX_LINE_SIZE 2048
105275129cebSChurchill Khangar #endif
105375129cebSChurchill Khangar 
105475129cebSChurchill Khangar static int
105575129cebSChurchill Khangar pipeline_table_entries_add(struct rte_swx_ctl_pipeline *p,
105675129cebSChurchill Khangar 			   const char *table_name,
105775129cebSChurchill Khangar 			   FILE *file,
105875129cebSChurchill Khangar 			   uint32_t *file_line_number)
105975129cebSChurchill Khangar {
106075129cebSChurchill Khangar 	char *line = NULL;
106175129cebSChurchill Khangar 	uint32_t line_id = 0;
106275129cebSChurchill Khangar 	int status = 0;
106375129cebSChurchill Khangar 
106475129cebSChurchill Khangar 	/* Buffer allocation. */
106575129cebSChurchill Khangar 	line = malloc(MAX_LINE_SIZE);
106675129cebSChurchill Khangar 	if (!line)
106775129cebSChurchill Khangar 		return -ENOMEM;
106875129cebSChurchill Khangar 
106975129cebSChurchill Khangar 	/* File read. */
107075129cebSChurchill Khangar 	for (line_id = 1; ; line_id++) {
107175129cebSChurchill Khangar 		struct rte_swx_table_entry *entry;
107275129cebSChurchill Khangar 		int is_blank_or_comment;
107375129cebSChurchill Khangar 
107475129cebSChurchill Khangar 		if (fgets(line, MAX_LINE_SIZE, file) == NULL)
107575129cebSChurchill Khangar 			break;
107675129cebSChurchill Khangar 
107775129cebSChurchill Khangar 		entry = rte_swx_ctl_pipeline_table_entry_read(p,
107875129cebSChurchill Khangar 							      table_name,
107975129cebSChurchill Khangar 							      line,
108075129cebSChurchill Khangar 							      &is_blank_or_comment);
108175129cebSChurchill Khangar 		if (!entry) {
108275129cebSChurchill Khangar 			if (is_blank_or_comment)
108375129cebSChurchill Khangar 				continue;
108475129cebSChurchill Khangar 
108575129cebSChurchill Khangar 			status = -EINVAL;
108675129cebSChurchill Khangar 			goto error;
108775129cebSChurchill Khangar 		}
108875129cebSChurchill Khangar 
108975129cebSChurchill Khangar 		status = rte_swx_ctl_pipeline_table_entry_add(p,
109075129cebSChurchill Khangar 							      table_name,
109175129cebSChurchill Khangar 							      entry);
109275129cebSChurchill Khangar 		table_entry_free(entry);
109375129cebSChurchill Khangar 		if (status)
109475129cebSChurchill Khangar 			goto error;
109575129cebSChurchill Khangar 	}
109675129cebSChurchill Khangar 
109775129cebSChurchill Khangar error:
109875129cebSChurchill Khangar 	free(line);
109975129cebSChurchill Khangar 	*file_line_number = line_id;
110075129cebSChurchill Khangar 	return status;
110175129cebSChurchill Khangar }
110275129cebSChurchill Khangar 
110375129cebSChurchill Khangar static const char cmd_pipeline_table_add_help[] =
110475129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> add <file_name>\n";
11055074e1d5SCristian Dumitrescu 
11065074e1d5SCristian Dumitrescu static void
110775129cebSChurchill Khangar cmd_pipeline_table_add(char **tokens,
11085074e1d5SCristian Dumitrescu 		       uint32_t n_tokens,
11095074e1d5SCristian Dumitrescu 		       char *out,
11105074e1d5SCristian Dumitrescu 		       size_t out_size,
11115074e1d5SCristian Dumitrescu 		       void *obj)
11125074e1d5SCristian Dumitrescu {
11135074e1d5SCristian Dumitrescu 	struct pipeline *p;
111475129cebSChurchill Khangar 	char *pipeline_name, *table_name, *file_name;
111575129cebSChurchill Khangar 	FILE *file = NULL;
111675129cebSChurchill Khangar 	uint32_t file_line_number = 0;
11175074e1d5SCristian Dumitrescu 	int status;
11185074e1d5SCristian Dumitrescu 
111975129cebSChurchill Khangar 	if (n_tokens != 6) {
11205074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
11215074e1d5SCristian Dumitrescu 		return;
11225074e1d5SCristian Dumitrescu 	}
11235074e1d5SCristian Dumitrescu 
11245074e1d5SCristian Dumitrescu 	pipeline_name = tokens[1];
11255074e1d5SCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
11265074e1d5SCristian Dumitrescu 	if (!p || !p->ctl) {
11275074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
11285074e1d5SCristian Dumitrescu 		return;
11295074e1d5SCristian Dumitrescu 	}
11305074e1d5SCristian Dumitrescu 
113175129cebSChurchill Khangar 	table_name = tokens[3];
113275129cebSChurchill Khangar 
113375129cebSChurchill Khangar 	file_name = tokens[5];
113475129cebSChurchill Khangar 	file = fopen(file_name, "r");
113575129cebSChurchill Khangar 	if (!file) {
113675129cebSChurchill Khangar 		snprintf(out, out_size, "Cannot open file %s.\n", file_name);
113775129cebSChurchill Khangar 		return;
113875129cebSChurchill Khangar 	}
113975129cebSChurchill Khangar 
114075129cebSChurchill Khangar 	status = pipeline_table_entries_add(p->ctl,
114175129cebSChurchill Khangar 					    table_name,
114275129cebSChurchill Khangar 					    file,
114375129cebSChurchill Khangar 					    &file_line_number);
114475129cebSChurchill Khangar 	if (status)
114575129cebSChurchill Khangar 		snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
114675129cebSChurchill Khangar 			 file_name,
114775129cebSChurchill Khangar 			 file_line_number);
114875129cebSChurchill Khangar 
114975129cebSChurchill Khangar 	fclose(file);
115075129cebSChurchill Khangar }
115175129cebSChurchill Khangar 
115275129cebSChurchill Khangar static int
115375129cebSChurchill Khangar pipeline_table_entries_delete(struct rte_swx_ctl_pipeline *p,
115475129cebSChurchill Khangar 			      const char *table_name,
115575129cebSChurchill Khangar 			      FILE *file,
115675129cebSChurchill Khangar 			      uint32_t *file_line_number)
115775129cebSChurchill Khangar {
115875129cebSChurchill Khangar 	char *line = NULL;
115975129cebSChurchill Khangar 	uint32_t line_id = 0;
116075129cebSChurchill Khangar 	int status = 0;
116175129cebSChurchill Khangar 
116275129cebSChurchill Khangar 	/* Buffer allocation. */
116375129cebSChurchill Khangar 	line = malloc(MAX_LINE_SIZE);
116475129cebSChurchill Khangar 	if (!line)
116575129cebSChurchill Khangar 		return -ENOMEM;
116675129cebSChurchill Khangar 
116775129cebSChurchill Khangar 	/* File read. */
116875129cebSChurchill Khangar 	for (line_id = 1; ; line_id++) {
116975129cebSChurchill Khangar 		struct rte_swx_table_entry *entry;
117075129cebSChurchill Khangar 		int is_blank_or_comment;
117175129cebSChurchill Khangar 
117275129cebSChurchill Khangar 		if (fgets(line, MAX_LINE_SIZE, file) == NULL)
117375129cebSChurchill Khangar 			break;
117475129cebSChurchill Khangar 
117575129cebSChurchill Khangar 		entry = rte_swx_ctl_pipeline_table_entry_read(p,
117675129cebSChurchill Khangar 							      table_name,
117775129cebSChurchill Khangar 							      line,
117875129cebSChurchill Khangar 							      &is_blank_or_comment);
117975129cebSChurchill Khangar 		if (!entry) {
118075129cebSChurchill Khangar 			if (is_blank_or_comment)
118175129cebSChurchill Khangar 				continue;
118275129cebSChurchill Khangar 
118375129cebSChurchill Khangar 			status = -EINVAL;
118475129cebSChurchill Khangar 			goto error;
118575129cebSChurchill Khangar 		}
118675129cebSChurchill Khangar 
118775129cebSChurchill Khangar 		status = rte_swx_ctl_pipeline_table_entry_delete(p,
118875129cebSChurchill Khangar 								 table_name,
118975129cebSChurchill Khangar 								 entry);
119075129cebSChurchill Khangar 		table_entry_free(entry);
119175129cebSChurchill Khangar 		if (status)
119275129cebSChurchill Khangar 			goto error;
119375129cebSChurchill Khangar 	}
119475129cebSChurchill Khangar 
119575129cebSChurchill Khangar error:
119675129cebSChurchill Khangar 	*file_line_number = line_id;
119775129cebSChurchill Khangar 	free(line);
119875129cebSChurchill Khangar 	return status;
119975129cebSChurchill Khangar }
120075129cebSChurchill Khangar 
120175129cebSChurchill Khangar static const char cmd_pipeline_table_delete_help[] =
120275129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> delete <file_name>\n";
120375129cebSChurchill Khangar 
120475129cebSChurchill Khangar static void
120575129cebSChurchill Khangar cmd_pipeline_table_delete(char **tokens,
120675129cebSChurchill Khangar 			  uint32_t n_tokens,
120775129cebSChurchill Khangar 			  char *out,
120875129cebSChurchill Khangar 			  size_t out_size,
120975129cebSChurchill Khangar 			  void *obj)
121075129cebSChurchill Khangar {
121175129cebSChurchill Khangar 	struct pipeline *p;
121275129cebSChurchill Khangar 	char *pipeline_name, *table_name, *file_name;
121375129cebSChurchill Khangar 	FILE *file = NULL;
121475129cebSChurchill Khangar 	uint32_t file_line_number = 0;
121575129cebSChurchill Khangar 	int status;
121675129cebSChurchill Khangar 
121775129cebSChurchill Khangar 	if (n_tokens != 6) {
121875129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
121975129cebSChurchill Khangar 		return;
122075129cebSChurchill Khangar 	}
122175129cebSChurchill Khangar 
122275129cebSChurchill Khangar 	pipeline_name = tokens[1];
122375129cebSChurchill Khangar 	p = pipeline_find(obj, pipeline_name);
122475129cebSChurchill Khangar 	if (!p || !p->ctl) {
122575129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
12265074e1d5SCristian Dumitrescu 		return;
12275074e1d5SCristian Dumitrescu 	}
12285074e1d5SCristian Dumitrescu 
12295074e1d5SCristian Dumitrescu 	table_name = tokens[3];
12305074e1d5SCristian Dumitrescu 
123175129cebSChurchill Khangar 	file_name = tokens[5];
123275129cebSChurchill Khangar 	file = fopen(file_name, "r");
123375129cebSChurchill Khangar 	if (!file) {
123475129cebSChurchill Khangar 		snprintf(out, out_size, "Cannot open file %s.\n", file_name);
12355074e1d5SCristian Dumitrescu 		return;
12365074e1d5SCristian Dumitrescu 	}
12375074e1d5SCristian Dumitrescu 
123875129cebSChurchill Khangar 	status = pipeline_table_entries_delete(p->ctl,
123975129cebSChurchill Khangar 					       table_name,
124075129cebSChurchill Khangar 					       file,
124175129cebSChurchill Khangar 					       &file_line_number);
124275129cebSChurchill Khangar 	if (status)
124375129cebSChurchill Khangar 		snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
124475129cebSChurchill Khangar 			 file_name,
124575129cebSChurchill Khangar 			 file_line_number);
12465074e1d5SCristian Dumitrescu 
124775129cebSChurchill Khangar 	fclose(file);
12485074e1d5SCristian Dumitrescu }
12495074e1d5SCristian Dumitrescu 
125075129cebSChurchill Khangar static int
125175129cebSChurchill Khangar pipeline_table_default_entry_add(struct rte_swx_ctl_pipeline *p,
125275129cebSChurchill Khangar 				 const char *table_name,
125375129cebSChurchill Khangar 				 FILE *file,
125475129cebSChurchill Khangar 				 uint32_t *file_line_number)
125575129cebSChurchill Khangar {
125675129cebSChurchill Khangar 	char *line = NULL;
125775129cebSChurchill Khangar 	uint32_t line_id = 0;
125875129cebSChurchill Khangar 	int status = 0;
12595074e1d5SCristian Dumitrescu 
12605074e1d5SCristian Dumitrescu 	/* Buffer allocation. */
126175129cebSChurchill Khangar 	line = malloc(MAX_LINE_SIZE);
126275129cebSChurchill Khangar 	if (!line)
126375129cebSChurchill Khangar 		return -ENOMEM;
12645074e1d5SCristian Dumitrescu 
126575129cebSChurchill Khangar 	/* File read. */
12665074e1d5SCristian Dumitrescu 	for (line_id = 1; ; line_id++) {
12675074e1d5SCristian Dumitrescu 		struct rte_swx_table_entry *entry;
1268cff9a717SCristian Dumitrescu 		int is_blank_or_comment;
12695074e1d5SCristian Dumitrescu 
127075129cebSChurchill Khangar 		if (fgets(line, MAX_LINE_SIZE, file) == NULL)
12715074e1d5SCristian Dumitrescu 			break;
12725074e1d5SCristian Dumitrescu 
127375129cebSChurchill Khangar 		entry = rte_swx_ctl_pipeline_table_entry_read(p,
12745074e1d5SCristian Dumitrescu 							      table_name,
1275cff9a717SCristian Dumitrescu 							      line,
1276cff9a717SCristian Dumitrescu 							      &is_blank_or_comment);
12775074e1d5SCristian Dumitrescu 		if (!entry) {
1278cff9a717SCristian Dumitrescu 			if (is_blank_or_comment)
1279cff9a717SCristian Dumitrescu 				continue;
1280cff9a717SCristian Dumitrescu 
128175129cebSChurchill Khangar 			status = -EINVAL;
12825074e1d5SCristian Dumitrescu 			goto error;
12835074e1d5SCristian Dumitrescu 		}
12845074e1d5SCristian Dumitrescu 
128575129cebSChurchill Khangar 		status = rte_swx_ctl_pipeline_table_default_entry_add(p,
12865074e1d5SCristian Dumitrescu 								      table_name,
12875074e1d5SCristian Dumitrescu 								      entry);
1288275ebefeSCristian Dumitrescu 		table_entry_free(entry);
128975129cebSChurchill Khangar 		if (status)
12905074e1d5SCristian Dumitrescu 			goto error;
12915074e1d5SCristian Dumitrescu 	}
129275129cebSChurchill Khangar 
129375129cebSChurchill Khangar error:
129475129cebSChurchill Khangar 	*file_line_number = line_id;
129575129cebSChurchill Khangar 	free(line);
129675129cebSChurchill Khangar 	return status;
12975074e1d5SCristian Dumitrescu }
12985074e1d5SCristian Dumitrescu 
129975129cebSChurchill Khangar static const char cmd_pipeline_table_default_help[] =
130075129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> default <file_name>\n";
13015074e1d5SCristian Dumitrescu 
130275129cebSChurchill Khangar static void
130375129cebSChurchill Khangar cmd_pipeline_table_default(char **tokens,
130475129cebSChurchill Khangar 			   uint32_t n_tokens,
130575129cebSChurchill Khangar 			   char *out,
130675129cebSChurchill Khangar 			   size_t out_size,
130775129cebSChurchill Khangar 			   void *obj)
130875129cebSChurchill Khangar {
130975129cebSChurchill Khangar 	struct pipeline *p;
131075129cebSChurchill Khangar 	char *pipeline_name, *table_name, *file_name;
131175129cebSChurchill Khangar 	FILE *file = NULL;
131275129cebSChurchill Khangar 	uint32_t file_line_number = 0;
131375129cebSChurchill Khangar 	int status;
13145074e1d5SCristian Dumitrescu 
131575129cebSChurchill Khangar 	if (n_tokens != 6) {
131675129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
131775129cebSChurchill Khangar 		return;
131875129cebSChurchill Khangar 	}
13195074e1d5SCristian Dumitrescu 
132075129cebSChurchill Khangar 	pipeline_name = tokens[1];
132175129cebSChurchill Khangar 	p = pipeline_find(obj, pipeline_name);
132275129cebSChurchill Khangar 	if (!p || !p->ctl) {
132375129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
132475129cebSChurchill Khangar 		return;
132575129cebSChurchill Khangar 	}
132675129cebSChurchill Khangar 
132775129cebSChurchill Khangar 	table_name = tokens[3];
132875129cebSChurchill Khangar 
132975129cebSChurchill Khangar 	file_name = tokens[5];
133075129cebSChurchill Khangar 	file = fopen(file_name, "r");
133175129cebSChurchill Khangar 	if (!file) {
133275129cebSChurchill Khangar 		snprintf(out, out_size, "Cannot open file %s.\n", file_name);
133375129cebSChurchill Khangar 		return;
133475129cebSChurchill Khangar 	}
133575129cebSChurchill Khangar 
133675129cebSChurchill Khangar 	status = pipeline_table_default_entry_add(p->ctl,
13375074e1d5SCristian Dumitrescu 						  table_name,
133875129cebSChurchill Khangar 						  file,
133975129cebSChurchill Khangar 						  &file_line_number);
134075129cebSChurchill Khangar 	if (status)
134175129cebSChurchill Khangar 		snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
134275129cebSChurchill Khangar 			 file_name,
134375129cebSChurchill Khangar 			 file_line_number);
1344cff9a717SCristian Dumitrescu 
134575129cebSChurchill Khangar 	fclose(file);
13465074e1d5SCristian Dumitrescu }
13475074e1d5SCristian Dumitrescu 
134875129cebSChurchill Khangar static const char cmd_pipeline_table_show_help[] =
1349a4c1146cSCristian Dumitrescu "pipeline <pipeline_name> table <table_name> show [filename]\n";
135075129cebSChurchill Khangar 
135175129cebSChurchill Khangar static void
135275129cebSChurchill Khangar cmd_pipeline_table_show(char **tokens,
135375129cebSChurchill Khangar 	uint32_t n_tokens,
135475129cebSChurchill Khangar 	char *out,
135575129cebSChurchill Khangar 	size_t out_size,
135675129cebSChurchill Khangar 	void *obj)
135775129cebSChurchill Khangar {
135875129cebSChurchill Khangar 	struct pipeline *p;
135975129cebSChurchill Khangar 	char *pipeline_name, *table_name;
1360a4c1146cSCristian Dumitrescu 	FILE *file = NULL;
136175129cebSChurchill Khangar 	int status;
136275129cebSChurchill Khangar 
1363a4c1146cSCristian Dumitrescu 	if (n_tokens != 5 && n_tokens != 6) {
136475129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
136575129cebSChurchill Khangar 		return;
13665074e1d5SCristian Dumitrescu 	}
13675074e1d5SCristian Dumitrescu 
136875129cebSChurchill Khangar 	pipeline_name = tokens[1];
136975129cebSChurchill Khangar 	p = pipeline_find(obj, pipeline_name);
137075129cebSChurchill Khangar 	if (!p || !p->ctl) {
137175129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
137275129cebSChurchill Khangar 		return;
13735074e1d5SCristian Dumitrescu 	}
13745074e1d5SCristian Dumitrescu 
137575129cebSChurchill Khangar 	table_name = tokens[3];
1376a4c1146cSCristian Dumitrescu 	file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout;
1377a4c1146cSCristian Dumitrescu 	if (!file) {
1378a4c1146cSCristian Dumitrescu 		snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]);
1379a4c1146cSCristian Dumitrescu 		return;
1380a4c1146cSCristian Dumitrescu 	}
1381a4c1146cSCristian Dumitrescu 
1382a4c1146cSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_table_fprintf(file, p->ctl, table_name);
138375129cebSChurchill Khangar 	if (status)
138475129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_INVALID, "table_name");
1385a4c1146cSCristian Dumitrescu 
1386a4c1146cSCristian Dumitrescu 	if (file)
1387a4c1146cSCristian Dumitrescu 		fclose(file);
13885074e1d5SCristian Dumitrescu }
138975129cebSChurchill Khangar 
1390598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_add_help[] =
1391598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group add\n";
1392598fe0ddSCristian Dumitrescu 
1393598fe0ddSCristian Dumitrescu static void
1394598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add(char **tokens,
1395598fe0ddSCristian Dumitrescu 	uint32_t n_tokens,
1396598fe0ddSCristian Dumitrescu 	char *out,
1397598fe0ddSCristian Dumitrescu 	size_t out_size,
1398598fe0ddSCristian Dumitrescu 	void *obj)
1399598fe0ddSCristian Dumitrescu {
1400598fe0ddSCristian Dumitrescu 	struct pipeline *p;
1401598fe0ddSCristian Dumitrescu 	char *pipeline_name, *selector_name;
1402598fe0ddSCristian Dumitrescu 	uint32_t group_id;
1403598fe0ddSCristian Dumitrescu 	int status;
1404598fe0ddSCristian Dumitrescu 
1405598fe0ddSCristian Dumitrescu 	if (n_tokens != 6) {
1406598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1407598fe0ddSCristian Dumitrescu 		return;
1408598fe0ddSCristian Dumitrescu 	}
1409598fe0ddSCristian Dumitrescu 
1410598fe0ddSCristian Dumitrescu 	pipeline_name = tokens[1];
1411598fe0ddSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
1412598fe0ddSCristian Dumitrescu 	if (!p || !p->ctl) {
1413598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1414598fe0ddSCristian Dumitrescu 		return;
1415598fe0ddSCristian Dumitrescu 	}
1416598fe0ddSCristian Dumitrescu 
1417598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[2], "selector") != 0) {
1418598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1419598fe0ddSCristian Dumitrescu 		return;
1420598fe0ddSCristian Dumitrescu 	}
1421598fe0ddSCristian Dumitrescu 
1422598fe0ddSCristian Dumitrescu 	selector_name = tokens[3];
1423598fe0ddSCristian Dumitrescu 
1424598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[4], "group") ||
1425598fe0ddSCristian Dumitrescu 		strcmp(tokens[5], "add")) {
1426598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group add");
1427598fe0ddSCristian Dumitrescu 		return;
1428598fe0ddSCristian Dumitrescu 	}
1429598fe0ddSCristian Dumitrescu 
1430598fe0ddSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_selector_group_add(p->ctl,
1431598fe0ddSCristian Dumitrescu 		selector_name,
1432598fe0ddSCristian Dumitrescu 		&group_id);
1433598fe0ddSCristian Dumitrescu 	if (status)
1434598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1435598fe0ddSCristian Dumitrescu 	else
1436598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "Group ID: %u\n", group_id);
1437598fe0ddSCristian Dumitrescu }
1438598fe0ddSCristian Dumitrescu 
1439598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_delete_help[] =
1440598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group delete <group_id>\n";
1441598fe0ddSCristian Dumitrescu 
1442598fe0ddSCristian Dumitrescu static void
1443598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete(char **tokens,
1444598fe0ddSCristian Dumitrescu 	uint32_t n_tokens,
1445598fe0ddSCristian Dumitrescu 	char *out,
1446598fe0ddSCristian Dumitrescu 	size_t out_size,
1447598fe0ddSCristian Dumitrescu 	void *obj)
1448598fe0ddSCristian Dumitrescu {
1449598fe0ddSCristian Dumitrescu 	struct pipeline *p;
1450598fe0ddSCristian Dumitrescu 	char *pipeline_name, *selector_name;
1451598fe0ddSCristian Dumitrescu 	uint32_t group_id;
1452598fe0ddSCristian Dumitrescu 	int status;
1453598fe0ddSCristian Dumitrescu 
1454598fe0ddSCristian Dumitrescu 	if (n_tokens != 7) {
1455598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1456598fe0ddSCristian Dumitrescu 		return;
1457598fe0ddSCristian Dumitrescu 	}
1458598fe0ddSCristian Dumitrescu 
1459598fe0ddSCristian Dumitrescu 	pipeline_name = tokens[1];
1460598fe0ddSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
1461598fe0ddSCristian Dumitrescu 	if (!p || !p->ctl) {
1462598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1463598fe0ddSCristian Dumitrescu 		return;
1464598fe0ddSCristian Dumitrescu 	}
1465598fe0ddSCristian Dumitrescu 
1466598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[2], "selector") != 0) {
1467598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1468598fe0ddSCristian Dumitrescu 		return;
1469598fe0ddSCristian Dumitrescu 	}
1470598fe0ddSCristian Dumitrescu 
1471598fe0ddSCristian Dumitrescu 	selector_name = tokens[3];
1472598fe0ddSCristian Dumitrescu 
1473598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[4], "group") ||
1474598fe0ddSCristian Dumitrescu 		strcmp(tokens[5], "delete")) {
1475598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group delete");
1476598fe0ddSCristian Dumitrescu 		return;
1477598fe0ddSCristian Dumitrescu 	}
1478598fe0ddSCristian Dumitrescu 
1479598fe0ddSCristian Dumitrescu 	if (parser_read_uint32(&group_id, tokens[6]) != 0) {
1480598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "group_id");
1481598fe0ddSCristian Dumitrescu 		return;
1482598fe0ddSCristian Dumitrescu 	}
1483598fe0ddSCristian Dumitrescu 
1484598fe0ddSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_selector_group_delete(p->ctl,
1485598fe0ddSCristian Dumitrescu 		selector_name,
1486598fe0ddSCristian Dumitrescu 		group_id);
1487598fe0ddSCristian Dumitrescu 	if (status)
1488598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1489598fe0ddSCristian Dumitrescu }
1490598fe0ddSCristian Dumitrescu 
1491598fe0ddSCristian Dumitrescu #define GROUP_MEMBER_INFO_TOKENS_MAX 6
1492598fe0ddSCristian Dumitrescu 
1493598fe0ddSCristian Dumitrescu static int
1494598fe0ddSCristian Dumitrescu token_is_comment(const char *token)
1495598fe0ddSCristian Dumitrescu {
1496598fe0ddSCristian Dumitrescu 	if ((token[0] == '#') ||
1497598fe0ddSCristian Dumitrescu 	    (token[0] == ';') ||
1498598fe0ddSCristian Dumitrescu 	    ((token[0] == '/') && (token[1] == '/')))
1499598fe0ddSCristian Dumitrescu 		return 1; /* TRUE. */
1500598fe0ddSCristian Dumitrescu 
1501598fe0ddSCristian Dumitrescu 	return 0; /* FALSE. */
1502598fe0ddSCristian Dumitrescu }
1503598fe0ddSCristian Dumitrescu 
1504598fe0ddSCristian Dumitrescu static int
1505598fe0ddSCristian Dumitrescu pipeline_selector_group_member_read(const char *string,
1506598fe0ddSCristian Dumitrescu 				      uint32_t *group_id,
1507598fe0ddSCristian Dumitrescu 				      uint32_t *member_id,
1508598fe0ddSCristian Dumitrescu 				      uint32_t *weight,
1509598fe0ddSCristian Dumitrescu 				      int *is_blank_or_comment)
1510598fe0ddSCristian Dumitrescu {
1511598fe0ddSCristian Dumitrescu 	char *token_array[GROUP_MEMBER_INFO_TOKENS_MAX], **tokens;
1512598fe0ddSCristian Dumitrescu 	char *s0 = NULL, *s;
151300b67591SAli Alnubani 	uint32_t n_tokens = 0, group_id_val = 0, member_id_val = 0, weight_val = 0;
1514598fe0ddSCristian Dumitrescu 	int blank_or_comment = 0;
1515598fe0ddSCristian Dumitrescu 
1516598fe0ddSCristian Dumitrescu 	/* Check input arguments. */
1517598fe0ddSCristian Dumitrescu 	if (!string || !string[0])
1518598fe0ddSCristian Dumitrescu 		goto error;
1519598fe0ddSCristian Dumitrescu 
1520598fe0ddSCristian Dumitrescu 	/* Memory allocation. */
1521598fe0ddSCristian Dumitrescu 	s0 = strdup(string);
1522598fe0ddSCristian Dumitrescu 	if (!s0)
1523598fe0ddSCristian Dumitrescu 		goto error;
1524598fe0ddSCristian Dumitrescu 
1525598fe0ddSCristian Dumitrescu 	/* Parse the string into tokens. */
1526598fe0ddSCristian Dumitrescu 	for (s = s0; ; ) {
1527598fe0ddSCristian Dumitrescu 		char *token;
1528598fe0ddSCristian Dumitrescu 
1529598fe0ddSCristian Dumitrescu 		token = strtok_r(s, " \f\n\r\t\v", &s);
1530598fe0ddSCristian Dumitrescu 		if (!token || token_is_comment(token))
1531598fe0ddSCristian Dumitrescu 			break;
1532598fe0ddSCristian Dumitrescu 
1533cfcc7bf8SCristian Dumitrescu 		if (n_tokens >= GROUP_MEMBER_INFO_TOKENS_MAX)
1534598fe0ddSCristian Dumitrescu 			goto error;
1535598fe0ddSCristian Dumitrescu 
1536598fe0ddSCristian Dumitrescu 		token_array[n_tokens] = token;
1537598fe0ddSCristian Dumitrescu 		n_tokens++;
1538598fe0ddSCristian Dumitrescu 	}
1539598fe0ddSCristian Dumitrescu 
1540598fe0ddSCristian Dumitrescu 	if (!n_tokens) {
1541598fe0ddSCristian Dumitrescu 		blank_or_comment = 1;
1542598fe0ddSCristian Dumitrescu 		goto error;
1543598fe0ddSCristian Dumitrescu 	}
1544598fe0ddSCristian Dumitrescu 
1545598fe0ddSCristian Dumitrescu 	tokens = token_array;
1546598fe0ddSCristian Dumitrescu 
1547598fe0ddSCristian Dumitrescu 	if (n_tokens < 4 ||
1548598fe0ddSCristian Dumitrescu 		strcmp(tokens[0], "group") ||
1549598fe0ddSCristian Dumitrescu 		strcmp(tokens[2], "member"))
1550598fe0ddSCristian Dumitrescu 		goto error;
1551598fe0ddSCristian Dumitrescu 
1552598fe0ddSCristian Dumitrescu 	/*
1553598fe0ddSCristian Dumitrescu 	 * Group ID.
1554598fe0ddSCristian Dumitrescu 	 */
1555598fe0ddSCristian Dumitrescu 	if (parser_read_uint32(&group_id_val, tokens[1]) != 0)
1556598fe0ddSCristian Dumitrescu 		goto error;
1557598fe0ddSCristian Dumitrescu 	*group_id = group_id_val;
1558598fe0ddSCristian Dumitrescu 
1559598fe0ddSCristian Dumitrescu 	/*
1560598fe0ddSCristian Dumitrescu 	 * Member ID.
1561598fe0ddSCristian Dumitrescu 	 */
1562598fe0ddSCristian Dumitrescu 	if (parser_read_uint32(&member_id_val, tokens[3]) != 0)
1563598fe0ddSCristian Dumitrescu 		goto error;
1564598fe0ddSCristian Dumitrescu 	*member_id = member_id_val;
1565598fe0ddSCristian Dumitrescu 
1566598fe0ddSCristian Dumitrescu 	tokens += 4;
1567598fe0ddSCristian Dumitrescu 	n_tokens -= 4;
1568598fe0ddSCristian Dumitrescu 
1569598fe0ddSCristian Dumitrescu 	/*
1570598fe0ddSCristian Dumitrescu 	 * Weight.
1571598fe0ddSCristian Dumitrescu 	 */
1572598fe0ddSCristian Dumitrescu 	if (n_tokens && !strcmp(tokens[0], "weight")) {
1573598fe0ddSCristian Dumitrescu 		if (n_tokens < 2)
1574598fe0ddSCristian Dumitrescu 			goto error;
1575598fe0ddSCristian Dumitrescu 
1576598fe0ddSCristian Dumitrescu 		if (parser_read_uint32(&weight_val, tokens[1]) != 0)
1577598fe0ddSCristian Dumitrescu 			goto error;
1578598fe0ddSCristian Dumitrescu 		*weight = weight_val;
1579598fe0ddSCristian Dumitrescu 
1580598fe0ddSCristian Dumitrescu 		tokens += 2;
1581598fe0ddSCristian Dumitrescu 		n_tokens -= 2;
1582598fe0ddSCristian Dumitrescu 	}
1583598fe0ddSCristian Dumitrescu 
1584598fe0ddSCristian Dumitrescu 	if (n_tokens)
1585598fe0ddSCristian Dumitrescu 		goto error;
1586598fe0ddSCristian Dumitrescu 
1587598fe0ddSCristian Dumitrescu 	free(s0);
1588598fe0ddSCristian Dumitrescu 	return 0;
1589598fe0ddSCristian Dumitrescu 
1590598fe0ddSCristian Dumitrescu error:
1591598fe0ddSCristian Dumitrescu 	free(s0);
1592598fe0ddSCristian Dumitrescu 	if (is_blank_or_comment)
1593598fe0ddSCristian Dumitrescu 		*is_blank_or_comment = blank_or_comment;
1594598fe0ddSCristian Dumitrescu 	return -EINVAL;
1595598fe0ddSCristian Dumitrescu }
1596598fe0ddSCristian Dumitrescu 
1597598fe0ddSCristian Dumitrescu static int
1598598fe0ddSCristian Dumitrescu pipeline_selector_group_members_add(struct rte_swx_ctl_pipeline *p,
1599598fe0ddSCristian Dumitrescu 			   const char *selector_name,
1600598fe0ddSCristian Dumitrescu 			   FILE *file,
1601598fe0ddSCristian Dumitrescu 			   uint32_t *file_line_number)
1602598fe0ddSCristian Dumitrescu {
1603598fe0ddSCristian Dumitrescu 	char *line = NULL;
1604598fe0ddSCristian Dumitrescu 	uint32_t line_id = 0;
1605598fe0ddSCristian Dumitrescu 	int status = 0;
1606598fe0ddSCristian Dumitrescu 
1607598fe0ddSCristian Dumitrescu 	/* Buffer allocation. */
1608598fe0ddSCristian Dumitrescu 	line = malloc(MAX_LINE_SIZE);
1609598fe0ddSCristian Dumitrescu 	if (!line)
1610598fe0ddSCristian Dumitrescu 		return -ENOMEM;
1611598fe0ddSCristian Dumitrescu 
1612598fe0ddSCristian Dumitrescu 	/* File read. */
1613598fe0ddSCristian Dumitrescu 	for (line_id = 1; ; line_id++) {
1614598fe0ddSCristian Dumitrescu 		uint32_t group_id, member_id, weight;
1615598fe0ddSCristian Dumitrescu 		int is_blank_or_comment;
1616598fe0ddSCristian Dumitrescu 
1617598fe0ddSCristian Dumitrescu 		if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1618598fe0ddSCristian Dumitrescu 			break;
1619598fe0ddSCristian Dumitrescu 
1620598fe0ddSCristian Dumitrescu 		status = pipeline_selector_group_member_read(line,
1621598fe0ddSCristian Dumitrescu 							      &group_id,
1622598fe0ddSCristian Dumitrescu 							      &member_id,
1623598fe0ddSCristian Dumitrescu 							      &weight,
1624598fe0ddSCristian Dumitrescu 							      &is_blank_or_comment);
1625598fe0ddSCristian Dumitrescu 		if (status) {
1626598fe0ddSCristian Dumitrescu 			if (is_blank_or_comment)
1627598fe0ddSCristian Dumitrescu 				continue;
1628598fe0ddSCristian Dumitrescu 
1629598fe0ddSCristian Dumitrescu 			goto error;
1630598fe0ddSCristian Dumitrescu 		}
1631598fe0ddSCristian Dumitrescu 
1632598fe0ddSCristian Dumitrescu 		status = rte_swx_ctl_pipeline_selector_group_member_add(p,
1633598fe0ddSCristian Dumitrescu 			selector_name,
1634598fe0ddSCristian Dumitrescu 			group_id,
1635598fe0ddSCristian Dumitrescu 			member_id,
1636598fe0ddSCristian Dumitrescu 			weight);
1637598fe0ddSCristian Dumitrescu 		if (status)
1638598fe0ddSCristian Dumitrescu 			goto error;
1639598fe0ddSCristian Dumitrescu 	}
1640598fe0ddSCristian Dumitrescu 
1641598fe0ddSCristian Dumitrescu error:
1642598fe0ddSCristian Dumitrescu 	free(line);
1643598fe0ddSCristian Dumitrescu 	*file_line_number = line_id;
1644598fe0ddSCristian Dumitrescu 	return status;
1645598fe0ddSCristian Dumitrescu }
1646598fe0ddSCristian Dumitrescu 
1647598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_add_help[] =
1648598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member add <file_name>";
1649598fe0ddSCristian Dumitrescu 
1650598fe0ddSCristian Dumitrescu static void
1651598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add(char **tokens,
1652598fe0ddSCristian Dumitrescu 	uint32_t n_tokens,
1653598fe0ddSCristian Dumitrescu 	char *out,
1654598fe0ddSCristian Dumitrescu 	size_t out_size,
1655598fe0ddSCristian Dumitrescu 	void *obj)
1656598fe0ddSCristian Dumitrescu {
1657598fe0ddSCristian Dumitrescu 	struct pipeline *p;
1658598fe0ddSCristian Dumitrescu 	char *pipeline_name, *selector_name, *file_name;
1659598fe0ddSCristian Dumitrescu 	FILE *file = NULL;
1660598fe0ddSCristian Dumitrescu 	uint32_t file_line_number = 0;
1661598fe0ddSCristian Dumitrescu 	int status;
1662598fe0ddSCristian Dumitrescu 
1663598fe0ddSCristian Dumitrescu 	if (n_tokens != 8) {
1664598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1665598fe0ddSCristian Dumitrescu 		return;
1666598fe0ddSCristian Dumitrescu 	}
1667598fe0ddSCristian Dumitrescu 
1668598fe0ddSCristian Dumitrescu 	pipeline_name = tokens[1];
1669598fe0ddSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
1670598fe0ddSCristian Dumitrescu 	if (!p || !p->ctl) {
1671598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1672598fe0ddSCristian Dumitrescu 		return;
1673598fe0ddSCristian Dumitrescu 	}
1674598fe0ddSCristian Dumitrescu 
1675598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[2], "selector") != 0) {
1676598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1677598fe0ddSCristian Dumitrescu 		return;
1678598fe0ddSCristian Dumitrescu 	}
1679598fe0ddSCristian Dumitrescu 
1680598fe0ddSCristian Dumitrescu 	selector_name = tokens[3];
1681598fe0ddSCristian Dumitrescu 
1682598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[4], "group") ||
1683598fe0ddSCristian Dumitrescu 		strcmp(tokens[5], "member") ||
1684598fe0ddSCristian Dumitrescu 		strcmp(tokens[6], "add")) {
1685598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member add");
1686598fe0ddSCristian Dumitrescu 		return;
1687598fe0ddSCristian Dumitrescu 	}
1688598fe0ddSCristian Dumitrescu 
1689598fe0ddSCristian Dumitrescu 	file_name = tokens[7];
1690598fe0ddSCristian Dumitrescu 	file = fopen(file_name, "r");
1691598fe0ddSCristian Dumitrescu 	if (!file) {
1692598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1693598fe0ddSCristian Dumitrescu 		return;
1694598fe0ddSCristian Dumitrescu 	}
1695598fe0ddSCristian Dumitrescu 
1696598fe0ddSCristian Dumitrescu 	status = pipeline_selector_group_members_add(p->ctl,
1697598fe0ddSCristian Dumitrescu 					    selector_name,
1698598fe0ddSCristian Dumitrescu 					    file,
1699598fe0ddSCristian Dumitrescu 					    &file_line_number);
1700598fe0ddSCristian Dumitrescu 	if (status)
1701598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1702598fe0ddSCristian Dumitrescu 			 file_name,
1703598fe0ddSCristian Dumitrescu 			 file_line_number);
1704598fe0ddSCristian Dumitrescu 
1705598fe0ddSCristian Dumitrescu 	fclose(file);
1706598fe0ddSCristian Dumitrescu }
1707598fe0ddSCristian Dumitrescu 
1708598fe0ddSCristian Dumitrescu static int
1709598fe0ddSCristian Dumitrescu pipeline_selector_group_members_delete(struct rte_swx_ctl_pipeline *p,
1710598fe0ddSCristian Dumitrescu 			   const char *selector_name,
1711598fe0ddSCristian Dumitrescu 			   FILE *file,
1712598fe0ddSCristian Dumitrescu 			   uint32_t *file_line_number)
1713598fe0ddSCristian Dumitrescu {
1714598fe0ddSCristian Dumitrescu 	char *line = NULL;
1715598fe0ddSCristian Dumitrescu 	uint32_t line_id = 0;
1716598fe0ddSCristian Dumitrescu 	int status = 0;
1717598fe0ddSCristian Dumitrescu 
1718598fe0ddSCristian Dumitrescu 	/* Buffer allocation. */
1719598fe0ddSCristian Dumitrescu 	line = malloc(MAX_LINE_SIZE);
1720598fe0ddSCristian Dumitrescu 	if (!line)
1721598fe0ddSCristian Dumitrescu 		return -ENOMEM;
1722598fe0ddSCristian Dumitrescu 
1723598fe0ddSCristian Dumitrescu 	/* File read. */
1724598fe0ddSCristian Dumitrescu 	for (line_id = 1; ; line_id++) {
1725598fe0ddSCristian Dumitrescu 		uint32_t group_id, member_id, weight;
1726598fe0ddSCristian Dumitrescu 		int is_blank_or_comment;
1727598fe0ddSCristian Dumitrescu 
1728598fe0ddSCristian Dumitrescu 		if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1729598fe0ddSCristian Dumitrescu 			break;
1730598fe0ddSCristian Dumitrescu 
1731598fe0ddSCristian Dumitrescu 		status = pipeline_selector_group_member_read(line,
1732598fe0ddSCristian Dumitrescu 							      &group_id,
1733598fe0ddSCristian Dumitrescu 							      &member_id,
1734598fe0ddSCristian Dumitrescu 							      &weight,
1735598fe0ddSCristian Dumitrescu 							      &is_blank_or_comment);
1736598fe0ddSCristian Dumitrescu 		if (status) {
1737598fe0ddSCristian Dumitrescu 			if (is_blank_or_comment)
1738598fe0ddSCristian Dumitrescu 				continue;
1739598fe0ddSCristian Dumitrescu 
1740598fe0ddSCristian Dumitrescu 			goto error;
1741598fe0ddSCristian Dumitrescu 		}
1742598fe0ddSCristian Dumitrescu 
1743598fe0ddSCristian Dumitrescu 		status = rte_swx_ctl_pipeline_selector_group_member_delete(p,
1744598fe0ddSCristian Dumitrescu 			selector_name,
1745598fe0ddSCristian Dumitrescu 			group_id,
1746598fe0ddSCristian Dumitrescu 			member_id);
1747598fe0ddSCristian Dumitrescu 		if (status)
1748598fe0ddSCristian Dumitrescu 			goto error;
1749598fe0ddSCristian Dumitrescu 	}
1750598fe0ddSCristian Dumitrescu 
1751598fe0ddSCristian Dumitrescu error:
1752598fe0ddSCristian Dumitrescu 	free(line);
1753598fe0ddSCristian Dumitrescu 	*file_line_number = line_id;
1754598fe0ddSCristian Dumitrescu 	return status;
1755598fe0ddSCristian Dumitrescu }
1756598fe0ddSCristian Dumitrescu 
1757598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_delete_help[] =
1758598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member delete <file_name>";
1759598fe0ddSCristian Dumitrescu 
1760598fe0ddSCristian Dumitrescu static void
1761598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete(char **tokens,
1762598fe0ddSCristian Dumitrescu 	uint32_t n_tokens,
1763598fe0ddSCristian Dumitrescu 	char *out,
1764598fe0ddSCristian Dumitrescu 	size_t out_size,
1765598fe0ddSCristian Dumitrescu 	void *obj)
1766598fe0ddSCristian Dumitrescu {
1767598fe0ddSCristian Dumitrescu 	struct pipeline *p;
1768598fe0ddSCristian Dumitrescu 	char *pipeline_name, *selector_name, *file_name;
1769598fe0ddSCristian Dumitrescu 	FILE *file = NULL;
1770598fe0ddSCristian Dumitrescu 	uint32_t file_line_number = 0;
1771598fe0ddSCristian Dumitrescu 	int status;
1772598fe0ddSCristian Dumitrescu 
1773598fe0ddSCristian Dumitrescu 	if (n_tokens != 8) {
1774598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1775598fe0ddSCristian Dumitrescu 		return;
1776598fe0ddSCristian Dumitrescu 	}
1777598fe0ddSCristian Dumitrescu 
1778598fe0ddSCristian Dumitrescu 	pipeline_name = tokens[1];
1779598fe0ddSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
1780598fe0ddSCristian Dumitrescu 	if (!p || !p->ctl) {
1781598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1782598fe0ddSCristian Dumitrescu 		return;
1783598fe0ddSCristian Dumitrescu 	}
1784598fe0ddSCristian Dumitrescu 
1785598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[2], "selector") != 0) {
1786598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1787598fe0ddSCristian Dumitrescu 		return;
1788598fe0ddSCristian Dumitrescu 	}
1789598fe0ddSCristian Dumitrescu 
1790598fe0ddSCristian Dumitrescu 	selector_name = tokens[3];
1791598fe0ddSCristian Dumitrescu 
1792598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[4], "group") ||
1793598fe0ddSCristian Dumitrescu 		strcmp(tokens[5], "member") ||
1794598fe0ddSCristian Dumitrescu 		strcmp(tokens[6], "delete")) {
1795598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member delete");
1796598fe0ddSCristian Dumitrescu 		return;
1797598fe0ddSCristian Dumitrescu 	}
1798598fe0ddSCristian Dumitrescu 
1799598fe0ddSCristian Dumitrescu 	file_name = tokens[7];
1800598fe0ddSCristian Dumitrescu 	file = fopen(file_name, "r");
1801598fe0ddSCristian Dumitrescu 	if (!file) {
1802598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1803598fe0ddSCristian Dumitrescu 		return;
1804598fe0ddSCristian Dumitrescu 	}
1805598fe0ddSCristian Dumitrescu 
1806598fe0ddSCristian Dumitrescu 	status = pipeline_selector_group_members_delete(p->ctl,
1807598fe0ddSCristian Dumitrescu 					    selector_name,
1808598fe0ddSCristian Dumitrescu 					    file,
1809598fe0ddSCristian Dumitrescu 					    &file_line_number);
1810598fe0ddSCristian Dumitrescu 	if (status)
1811598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1812598fe0ddSCristian Dumitrescu 			 file_name,
1813598fe0ddSCristian Dumitrescu 			 file_line_number);
1814598fe0ddSCristian Dumitrescu 
1815598fe0ddSCristian Dumitrescu 	fclose(file);
1816598fe0ddSCristian Dumitrescu }
1817598fe0ddSCristian Dumitrescu 
1818598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_show_help[] =
1819a4c1146cSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> show [filename]\n";
1820598fe0ddSCristian Dumitrescu 
1821598fe0ddSCristian Dumitrescu static void
1822598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show(char **tokens,
1823598fe0ddSCristian Dumitrescu 	uint32_t n_tokens,
1824598fe0ddSCristian Dumitrescu 	char *out,
1825598fe0ddSCristian Dumitrescu 	size_t out_size,
1826598fe0ddSCristian Dumitrescu 	void *obj)
1827598fe0ddSCristian Dumitrescu {
1828598fe0ddSCristian Dumitrescu 	struct pipeline *p;
1829598fe0ddSCristian Dumitrescu 	char *pipeline_name, *selector_name;
1830a4c1146cSCristian Dumitrescu 	FILE *file = NULL;
1831598fe0ddSCristian Dumitrescu 	int status;
1832598fe0ddSCristian Dumitrescu 
1833a4c1146cSCristian Dumitrescu 	if (n_tokens != 5 && n_tokens != 6) {
1834598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1835598fe0ddSCristian Dumitrescu 		return;
1836598fe0ddSCristian Dumitrescu 	}
1837598fe0ddSCristian Dumitrescu 
1838598fe0ddSCristian Dumitrescu 	pipeline_name = tokens[1];
1839598fe0ddSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
1840598fe0ddSCristian Dumitrescu 	if (!p || !p->ctl) {
1841598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1842598fe0ddSCristian Dumitrescu 		return;
1843598fe0ddSCristian Dumitrescu 	}
1844598fe0ddSCristian Dumitrescu 
1845598fe0ddSCristian Dumitrescu 	selector_name = tokens[3];
1846a4c1146cSCristian Dumitrescu 
1847a4c1146cSCristian Dumitrescu 	file = (n_tokens == 6) ? fopen(tokens[5], "w") : stdout;
1848a4c1146cSCristian Dumitrescu 	if (!file) {
1849a4c1146cSCristian Dumitrescu 		snprintf(out, out_size, "Cannot open file %s.\n", tokens[5]);
1850a4c1146cSCristian Dumitrescu 		return;
1851a4c1146cSCristian Dumitrescu 	}
1852a4c1146cSCristian Dumitrescu 
1853a4c1146cSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_selector_fprintf(file, p->ctl, selector_name);
1854598fe0ddSCristian Dumitrescu 	if (status)
1855598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "selector_name");
1856a4c1146cSCristian Dumitrescu 
1857a4c1146cSCristian Dumitrescu 	if (file)
1858a4c1146cSCristian Dumitrescu 		fclose(file);
1859598fe0ddSCristian Dumitrescu }
1860598fe0ddSCristian Dumitrescu 
18618bd4862fSCristian Dumitrescu static int
18628bd4862fSCristian Dumitrescu pipeline_learner_default_entry_add(struct rte_swx_ctl_pipeline *p,
18638bd4862fSCristian Dumitrescu 				   const char *learner_name,
18648bd4862fSCristian Dumitrescu 				   FILE *file,
18658bd4862fSCristian Dumitrescu 				   uint32_t *file_line_number)
18668bd4862fSCristian Dumitrescu {
18678bd4862fSCristian Dumitrescu 	char *line = NULL;
18688bd4862fSCristian Dumitrescu 	uint32_t line_id = 0;
18698bd4862fSCristian Dumitrescu 	int status = 0;
18708bd4862fSCristian Dumitrescu 
18718bd4862fSCristian Dumitrescu 	/* Buffer allocation. */
18728bd4862fSCristian Dumitrescu 	line = malloc(MAX_LINE_SIZE);
18738bd4862fSCristian Dumitrescu 	if (!line)
18748bd4862fSCristian Dumitrescu 		return -ENOMEM;
18758bd4862fSCristian Dumitrescu 
18768bd4862fSCristian Dumitrescu 	/* File read. */
18778bd4862fSCristian Dumitrescu 	for (line_id = 1; ; line_id++) {
18788bd4862fSCristian Dumitrescu 		struct rte_swx_table_entry *entry;
18798bd4862fSCristian Dumitrescu 		int is_blank_or_comment;
18808bd4862fSCristian Dumitrescu 
18818bd4862fSCristian Dumitrescu 		if (fgets(line, MAX_LINE_SIZE, file) == NULL)
18828bd4862fSCristian Dumitrescu 			break;
18838bd4862fSCristian Dumitrescu 
18848bd4862fSCristian Dumitrescu 		entry = rte_swx_ctl_pipeline_learner_default_entry_read(p,
18858bd4862fSCristian Dumitrescu 									learner_name,
18868bd4862fSCristian Dumitrescu 									line,
18878bd4862fSCristian Dumitrescu 									&is_blank_or_comment);
18888bd4862fSCristian Dumitrescu 		if (!entry) {
18898bd4862fSCristian Dumitrescu 			if (is_blank_or_comment)
18908bd4862fSCristian Dumitrescu 				continue;
18918bd4862fSCristian Dumitrescu 
18928bd4862fSCristian Dumitrescu 			status = -EINVAL;
18938bd4862fSCristian Dumitrescu 			goto error;
18948bd4862fSCristian Dumitrescu 		}
18958bd4862fSCristian Dumitrescu 
18968bd4862fSCristian Dumitrescu 		status = rte_swx_ctl_pipeline_learner_default_entry_add(p,
18978bd4862fSCristian Dumitrescu 									learner_name,
18988bd4862fSCristian Dumitrescu 									entry);
18998bd4862fSCristian Dumitrescu 		table_entry_free(entry);
19008bd4862fSCristian Dumitrescu 		if (status)
19018bd4862fSCristian Dumitrescu 			goto error;
19028bd4862fSCristian Dumitrescu 	}
19038bd4862fSCristian Dumitrescu 
19048bd4862fSCristian Dumitrescu error:
19058bd4862fSCristian Dumitrescu 	*file_line_number = line_id;
19068bd4862fSCristian Dumitrescu 	free(line);
19078bd4862fSCristian Dumitrescu 	return status;
19088bd4862fSCristian Dumitrescu }
19098bd4862fSCristian Dumitrescu 
19108bd4862fSCristian Dumitrescu static const char cmd_pipeline_learner_default_help[] =
19118bd4862fSCristian Dumitrescu "pipeline <pipeline_name> learner <learner_name> default <file_name>\n";
19128bd4862fSCristian Dumitrescu 
19138bd4862fSCristian Dumitrescu static void
19148bd4862fSCristian Dumitrescu cmd_pipeline_learner_default(char **tokens,
19158bd4862fSCristian Dumitrescu 			     uint32_t n_tokens,
19168bd4862fSCristian Dumitrescu 			     char *out,
19178bd4862fSCristian Dumitrescu 			     size_t out_size,
19188bd4862fSCristian Dumitrescu 			     void *obj)
19198bd4862fSCristian Dumitrescu {
19208bd4862fSCristian Dumitrescu 	struct pipeline *p;
19218bd4862fSCristian Dumitrescu 	char *pipeline_name, *learner_name, *file_name;
19228bd4862fSCristian Dumitrescu 	FILE *file = NULL;
19238bd4862fSCristian Dumitrescu 	uint32_t file_line_number = 0;
19248bd4862fSCristian Dumitrescu 	int status;
19258bd4862fSCristian Dumitrescu 
19268bd4862fSCristian Dumitrescu 	if (n_tokens != 6) {
19278bd4862fSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
19288bd4862fSCristian Dumitrescu 		return;
19298bd4862fSCristian Dumitrescu 	}
19308bd4862fSCristian Dumitrescu 
19318bd4862fSCristian Dumitrescu 	pipeline_name = tokens[1];
19328bd4862fSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
19338bd4862fSCristian Dumitrescu 	if (!p || !p->ctl) {
19348bd4862fSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
19358bd4862fSCristian Dumitrescu 		return;
19368bd4862fSCristian Dumitrescu 	}
19378bd4862fSCristian Dumitrescu 
19388bd4862fSCristian Dumitrescu 	learner_name = tokens[3];
19398bd4862fSCristian Dumitrescu 
19408bd4862fSCristian Dumitrescu 	file_name = tokens[5];
19418bd4862fSCristian Dumitrescu 	file = fopen(file_name, "r");
19428bd4862fSCristian Dumitrescu 	if (!file) {
19438bd4862fSCristian Dumitrescu 		snprintf(out, out_size, "Cannot open file %s.\n", file_name);
19448bd4862fSCristian Dumitrescu 		return;
19458bd4862fSCristian Dumitrescu 	}
19468bd4862fSCristian Dumitrescu 
19478bd4862fSCristian Dumitrescu 	status = pipeline_learner_default_entry_add(p->ctl,
19488bd4862fSCristian Dumitrescu 						    learner_name,
19498bd4862fSCristian Dumitrescu 						    file,
19508bd4862fSCristian Dumitrescu 						    &file_line_number);
19518bd4862fSCristian Dumitrescu 	if (status)
19528bd4862fSCristian Dumitrescu 		snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
19538bd4862fSCristian Dumitrescu 			 file_name,
19548bd4862fSCristian Dumitrescu 			 file_line_number);
19558bd4862fSCristian Dumitrescu 
19568bd4862fSCristian Dumitrescu 	fclose(file);
19578bd4862fSCristian Dumitrescu }
19588bd4862fSCristian Dumitrescu 
195975129cebSChurchill Khangar static const char cmd_pipeline_commit_help[] =
196075129cebSChurchill Khangar "pipeline <pipeline_name> commit\n";
196175129cebSChurchill Khangar 
196275129cebSChurchill Khangar static void
196375129cebSChurchill Khangar cmd_pipeline_commit(char **tokens,
196475129cebSChurchill Khangar 	uint32_t n_tokens,
196575129cebSChurchill Khangar 	char *out,
196675129cebSChurchill Khangar 	size_t out_size,
196775129cebSChurchill Khangar 	void *obj)
196875129cebSChurchill Khangar {
196975129cebSChurchill Khangar 	struct pipeline *p;
197075129cebSChurchill Khangar 	char *pipeline_name;
197175129cebSChurchill Khangar 	int status;
197275129cebSChurchill Khangar 
197375129cebSChurchill Khangar 	if (n_tokens != 3) {
197475129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
197575129cebSChurchill Khangar 		return;
197675129cebSChurchill Khangar 	}
197775129cebSChurchill Khangar 
197875129cebSChurchill Khangar 	pipeline_name = tokens[1];
197975129cebSChurchill Khangar 	p = pipeline_find(obj, pipeline_name);
198075129cebSChurchill Khangar 	if (!p || !p->ctl) {
198175129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
198275129cebSChurchill Khangar 		return;
19835074e1d5SCristian Dumitrescu 	}
19845074e1d5SCristian Dumitrescu 
19855074e1d5SCristian Dumitrescu 	status = rte_swx_ctl_pipeline_commit(p->ctl, 1);
198675129cebSChurchill Khangar 	if (status)
198775129cebSChurchill Khangar 		snprintf(out, out_size, "Commit failed. "
198875129cebSChurchill Khangar 			"Use \"commit\" to retry or \"abort\" to discard the pending work.\n");
19895074e1d5SCristian Dumitrescu }
19905074e1d5SCristian Dumitrescu 
199175129cebSChurchill Khangar static const char cmd_pipeline_abort_help[] =
199275129cebSChurchill Khangar "pipeline <pipeline_name> abort\n";
19935074e1d5SCristian Dumitrescu 
199475129cebSChurchill Khangar static void
199575129cebSChurchill Khangar cmd_pipeline_abort(char **tokens,
199675129cebSChurchill Khangar 	uint32_t n_tokens,
199775129cebSChurchill Khangar 	char *out,
199875129cebSChurchill Khangar 	size_t out_size,
199975129cebSChurchill Khangar 	void *obj)
200075129cebSChurchill Khangar {
200175129cebSChurchill Khangar 	struct pipeline *p;
200275129cebSChurchill Khangar 	char *pipeline_name;
20035074e1d5SCristian Dumitrescu 
200475129cebSChurchill Khangar 	if (n_tokens != 3) {
200575129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
20065074e1d5SCristian Dumitrescu 		return;
200775129cebSChurchill Khangar 	}
20085074e1d5SCristian Dumitrescu 
200975129cebSChurchill Khangar 	pipeline_name = tokens[1];
201075129cebSChurchill Khangar 	p = pipeline_find(obj, pipeline_name);
201175129cebSChurchill Khangar 	if (!p || !p->ctl) {
201275129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
201375129cebSChurchill Khangar 		return;
201475129cebSChurchill Khangar 	}
201575129cebSChurchill Khangar 
20165074e1d5SCristian Dumitrescu 	rte_swx_ctl_pipeline_abort(p->ctl);
20175074e1d5SCristian Dumitrescu }
20185074e1d5SCristian Dumitrescu 
201964cfcebdSCristian Dumitrescu static const char cmd_pipeline_regrd_help[] =
202064cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regrd <register_array_name> <index>\n";
202164cfcebdSCristian Dumitrescu 
202264cfcebdSCristian Dumitrescu static void
202364cfcebdSCristian Dumitrescu cmd_pipeline_regrd(char **tokens,
202464cfcebdSCristian Dumitrescu 	uint32_t n_tokens,
202564cfcebdSCristian Dumitrescu 	char *out,
202664cfcebdSCristian Dumitrescu 	size_t out_size,
202764cfcebdSCristian Dumitrescu 	void *obj)
202864cfcebdSCristian Dumitrescu {
202964cfcebdSCristian Dumitrescu 	struct pipeline *p;
203064cfcebdSCristian Dumitrescu 	const char *name;
203164cfcebdSCristian Dumitrescu 	uint64_t value;
203264cfcebdSCristian Dumitrescu 	uint32_t idx;
203364cfcebdSCristian Dumitrescu 	int status;
203464cfcebdSCristian Dumitrescu 
203564cfcebdSCristian Dumitrescu 	if (n_tokens != 5) {
203664cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
203764cfcebdSCristian Dumitrescu 		return;
203864cfcebdSCristian Dumitrescu 	}
203964cfcebdSCristian Dumitrescu 
204064cfcebdSCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
204164cfcebdSCristian Dumitrescu 	if (!p || !p->ctl) {
204264cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
204364cfcebdSCristian Dumitrescu 		return;
204464cfcebdSCristian Dumitrescu 	}
204564cfcebdSCristian Dumitrescu 
204664cfcebdSCristian Dumitrescu 	if (strcmp(tokens[2], "regrd")) {
204764cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd");
204864cfcebdSCristian Dumitrescu 		return;
204964cfcebdSCristian Dumitrescu 	}
205064cfcebdSCristian Dumitrescu 
205164cfcebdSCristian Dumitrescu 	name = tokens[3];
205264cfcebdSCristian Dumitrescu 
205364cfcebdSCristian Dumitrescu 	if (parser_read_uint32(&idx, tokens[4])) {
205464cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index");
205564cfcebdSCristian Dumitrescu 		return;
205664cfcebdSCristian Dumitrescu 	}
205764cfcebdSCristian Dumitrescu 
205864cfcebdSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value);
205964cfcebdSCristian Dumitrescu 	if (status) {
206064cfcebdSCristian Dumitrescu 		snprintf(out, out_size, "Command failed.\n");
206164cfcebdSCristian Dumitrescu 		return;
206264cfcebdSCristian Dumitrescu 	}
206364cfcebdSCristian Dumitrescu 
206464cfcebdSCristian Dumitrescu 	snprintf(out, out_size, "0x%" PRIx64 "\n", value);
206564cfcebdSCristian Dumitrescu }
206664cfcebdSCristian Dumitrescu 
206764cfcebdSCristian Dumitrescu static const char cmd_pipeline_regwr_help[] =
206864cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
206964cfcebdSCristian Dumitrescu 
207064cfcebdSCristian Dumitrescu static void
207164cfcebdSCristian Dumitrescu cmd_pipeline_regwr(char **tokens,
207264cfcebdSCristian Dumitrescu 	uint32_t n_tokens,
207364cfcebdSCristian Dumitrescu 	char *out,
207464cfcebdSCristian Dumitrescu 	size_t out_size,
207564cfcebdSCristian Dumitrescu 	void *obj)
207664cfcebdSCristian Dumitrescu {
207764cfcebdSCristian Dumitrescu 	struct pipeline *p;
207864cfcebdSCristian Dumitrescu 	const char *name;
207964cfcebdSCristian Dumitrescu 	uint64_t value;
208064cfcebdSCristian Dumitrescu 	uint32_t idx;
208164cfcebdSCristian Dumitrescu 	int status;
208264cfcebdSCristian Dumitrescu 
208364cfcebdSCristian Dumitrescu 	if (n_tokens != 6) {
208464cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
208564cfcebdSCristian Dumitrescu 		return;
208664cfcebdSCristian Dumitrescu 	}
208764cfcebdSCristian Dumitrescu 
208864cfcebdSCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
208964cfcebdSCristian Dumitrescu 	if (!p || !p->ctl) {
209064cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
209164cfcebdSCristian Dumitrescu 		return;
209264cfcebdSCristian Dumitrescu 	}
209364cfcebdSCristian Dumitrescu 
209464cfcebdSCristian Dumitrescu 	if (strcmp(tokens[2], "regwr")) {
209564cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr");
209664cfcebdSCristian Dumitrescu 		return;
209764cfcebdSCristian Dumitrescu 	}
209864cfcebdSCristian Dumitrescu 
209964cfcebdSCristian Dumitrescu 	name = tokens[3];
210064cfcebdSCristian Dumitrescu 
210164cfcebdSCristian Dumitrescu 	if (parser_read_uint32(&idx, tokens[4])) {
210264cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index");
210364cfcebdSCristian Dumitrescu 		return;
210464cfcebdSCristian Dumitrescu 	}
210564cfcebdSCristian Dumitrescu 
210664cfcebdSCristian Dumitrescu 	if (parser_read_uint64(&value, tokens[5])) {
210764cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "value");
210864cfcebdSCristian Dumitrescu 		return;
210964cfcebdSCristian Dumitrescu 	}
211064cfcebdSCristian Dumitrescu 
211164cfcebdSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value);
211264cfcebdSCristian Dumitrescu 	if (status) {
211364cfcebdSCristian Dumitrescu 		snprintf(out, out_size, "Command failed.\n");
211464cfcebdSCristian Dumitrescu 		return;
211564cfcebdSCristian Dumitrescu 	}
211664cfcebdSCristian Dumitrescu }
211764cfcebdSCristian Dumitrescu 
2118f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_add_help[] =
2119f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> add "
2120f38913b7SCristian Dumitrescu 	"cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
2121f38913b7SCristian Dumitrescu 
2122f38913b7SCristian Dumitrescu static void
2123f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(char **tokens,
2124f38913b7SCristian Dumitrescu 	uint32_t n_tokens,
2125f38913b7SCristian Dumitrescu 	char *out,
2126f38913b7SCristian Dumitrescu 	size_t out_size,
2127f38913b7SCristian Dumitrescu 	void *obj)
2128f38913b7SCristian Dumitrescu {
2129f38913b7SCristian Dumitrescu 	struct rte_meter_trtcm_params params;
2130f38913b7SCristian Dumitrescu 	struct pipeline *p;
2131f38913b7SCristian Dumitrescu 	const char *profile_name;
2132f38913b7SCristian Dumitrescu 	int status;
2133f38913b7SCristian Dumitrescu 
2134f38913b7SCristian Dumitrescu 	if (n_tokens != 14) {
2135f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2136f38913b7SCristian Dumitrescu 		return;
2137f38913b7SCristian Dumitrescu 	}
2138f38913b7SCristian Dumitrescu 
2139f38913b7SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
2140f38913b7SCristian Dumitrescu 	if (!p || !p->ctl) {
2141f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2142f38913b7SCristian Dumitrescu 		return;
2143f38913b7SCristian Dumitrescu 	}
2144f38913b7SCristian Dumitrescu 
2145f38913b7SCristian Dumitrescu 	if (strcmp(tokens[2], "meter")) {
2146f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2147f38913b7SCristian Dumitrescu 		return;
2148f38913b7SCristian Dumitrescu 	}
2149f38913b7SCristian Dumitrescu 
2150f38913b7SCristian Dumitrescu 	if (strcmp(tokens[3], "profile")) {
2151f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2152f38913b7SCristian Dumitrescu 		return;
2153f38913b7SCristian Dumitrescu 	}
2154f38913b7SCristian Dumitrescu 
2155f38913b7SCristian Dumitrescu 	profile_name = tokens[4];
2156f38913b7SCristian Dumitrescu 
2157f38913b7SCristian Dumitrescu 	if (strcmp(tokens[5], "add")) {
2158f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
2159f38913b7SCristian Dumitrescu 		return;
2160f38913b7SCristian Dumitrescu 	}
2161f38913b7SCristian Dumitrescu 
2162f38913b7SCristian Dumitrescu 	if (strcmp(tokens[6], "cir")) {
2163f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
2164f38913b7SCristian Dumitrescu 		return;
2165f38913b7SCristian Dumitrescu 	}
2166f38913b7SCristian Dumitrescu 
2167f38913b7SCristian Dumitrescu 	if (parser_read_uint64(&params.cir, tokens[7])) {
2168f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "cir");
2169f38913b7SCristian Dumitrescu 		return;
2170f38913b7SCristian Dumitrescu 	}
2171f38913b7SCristian Dumitrescu 
2172f38913b7SCristian Dumitrescu 	if (strcmp(tokens[8], "pir")) {
2173f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
2174f38913b7SCristian Dumitrescu 		return;
2175f38913b7SCristian Dumitrescu 	}
2176f38913b7SCristian Dumitrescu 
2177f38913b7SCristian Dumitrescu 	if (parser_read_uint64(&params.pir, tokens[9])) {
2178f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pir");
2179f38913b7SCristian Dumitrescu 		return;
2180f38913b7SCristian Dumitrescu 	}
2181f38913b7SCristian Dumitrescu 
2182f38913b7SCristian Dumitrescu 	if (strcmp(tokens[10], "cbs")) {
2183f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
2184f38913b7SCristian Dumitrescu 		return;
2185f38913b7SCristian Dumitrescu 	}
2186f38913b7SCristian Dumitrescu 
2187f38913b7SCristian Dumitrescu 	if (parser_read_uint64(&params.cbs, tokens[11])) {
2188f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
2189f38913b7SCristian Dumitrescu 		return;
2190f38913b7SCristian Dumitrescu 	}
2191f38913b7SCristian Dumitrescu 
2192f38913b7SCristian Dumitrescu 	if (strcmp(tokens[12], "pbs")) {
2193f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
2194f38913b7SCristian Dumitrescu 		return;
2195f38913b7SCristian Dumitrescu 	}
2196f38913b7SCristian Dumitrescu 
2197f38913b7SCristian Dumitrescu 	if (parser_read_uint64(&params.pbs, tokens[13])) {
2198f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
2199f38913b7SCristian Dumitrescu 		return;
2200f38913b7SCristian Dumitrescu 	}
2201f38913b7SCristian Dumitrescu 
2202f38913b7SCristian Dumitrescu 	status = rte_swx_ctl_meter_profile_add(p->p, profile_name, &params);
2203f38913b7SCristian Dumitrescu 	if (status) {
2204f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "Command failed.\n");
2205f38913b7SCristian Dumitrescu 		return;
2206f38913b7SCristian Dumitrescu 	}
2207f38913b7SCristian Dumitrescu }
2208f38913b7SCristian Dumitrescu 
2209f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_delete_help[] =
2210f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> delete\n";
2211f38913b7SCristian Dumitrescu 
2212f38913b7SCristian Dumitrescu static void
2213f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(char **tokens,
2214f38913b7SCristian Dumitrescu 	uint32_t n_tokens,
2215f38913b7SCristian Dumitrescu 	char *out,
2216f38913b7SCristian Dumitrescu 	size_t out_size,
2217f38913b7SCristian Dumitrescu 	void *obj)
2218f38913b7SCristian Dumitrescu {
2219f38913b7SCristian Dumitrescu 	struct pipeline *p;
2220f38913b7SCristian Dumitrescu 	const char *profile_name;
2221f38913b7SCristian Dumitrescu 	int status;
2222f38913b7SCristian Dumitrescu 
2223f38913b7SCristian Dumitrescu 	if (n_tokens != 6) {
2224f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2225f38913b7SCristian Dumitrescu 		return;
2226f38913b7SCristian Dumitrescu 	}
2227f38913b7SCristian Dumitrescu 
2228f38913b7SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
2229f38913b7SCristian Dumitrescu 	if (!p || !p->ctl) {
2230f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2231f38913b7SCristian Dumitrescu 		return;
2232f38913b7SCristian Dumitrescu 	}
2233f38913b7SCristian Dumitrescu 
2234f38913b7SCristian Dumitrescu 	if (strcmp(tokens[2], "meter")) {
2235f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2236f38913b7SCristian Dumitrescu 		return;
2237f38913b7SCristian Dumitrescu 	}
2238f38913b7SCristian Dumitrescu 
2239f38913b7SCristian Dumitrescu 	if (strcmp(tokens[3], "profile")) {
2240f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2241f38913b7SCristian Dumitrescu 		return;
2242f38913b7SCristian Dumitrescu 	}
2243f38913b7SCristian Dumitrescu 
2244f38913b7SCristian Dumitrescu 	profile_name = tokens[4];
2245f38913b7SCristian Dumitrescu 
2246f38913b7SCristian Dumitrescu 	if (strcmp(tokens[5], "delete")) {
2247f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
2248f38913b7SCristian Dumitrescu 		return;
2249f38913b7SCristian Dumitrescu 	}
2250f38913b7SCristian Dumitrescu 
2251f38913b7SCristian Dumitrescu 	status = rte_swx_ctl_meter_profile_delete(p->p, profile_name);
2252f38913b7SCristian Dumitrescu 	if (status) {
2253f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "Command failed.\n");
2254f38913b7SCristian Dumitrescu 		return;
2255f38913b7SCristian Dumitrescu 	}
2256f38913b7SCristian Dumitrescu }
2257f38913b7SCristian Dumitrescu 
2258f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_reset_help[] =
2259f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2260f38913b7SCristian Dumitrescu 	"reset\n";
2261f38913b7SCristian Dumitrescu 
2262f38913b7SCristian Dumitrescu static void
2263f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(char **tokens,
2264f38913b7SCristian Dumitrescu 	uint32_t n_tokens,
2265f38913b7SCristian Dumitrescu 	char *out,
2266f38913b7SCristian Dumitrescu 	size_t out_size,
2267f38913b7SCristian Dumitrescu 	void *obj)
2268f38913b7SCristian Dumitrescu {
2269f38913b7SCristian Dumitrescu 	struct pipeline *p;
2270f38913b7SCristian Dumitrescu 	const char *name;
227100b67591SAli Alnubani 	uint32_t idx0 = 0, idx1 = 0;
2272f38913b7SCristian Dumitrescu 
2273f38913b7SCristian Dumitrescu 	if (n_tokens != 9) {
2274f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2275f38913b7SCristian Dumitrescu 		return;
2276f38913b7SCristian Dumitrescu 	}
2277f38913b7SCristian Dumitrescu 
2278f38913b7SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
2279f38913b7SCristian Dumitrescu 	if (!p || !p->ctl) {
2280f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2281f38913b7SCristian Dumitrescu 		return;
2282f38913b7SCristian Dumitrescu 	}
2283f38913b7SCristian Dumitrescu 
2284f38913b7SCristian Dumitrescu 	if (strcmp(tokens[2], "meter")) {
2285f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2286f38913b7SCristian Dumitrescu 		return;
2287f38913b7SCristian Dumitrescu 	}
2288f38913b7SCristian Dumitrescu 
2289f38913b7SCristian Dumitrescu 	name = tokens[3];
2290f38913b7SCristian Dumitrescu 
2291f38913b7SCristian Dumitrescu 	if (strcmp(tokens[4], "from")) {
2292f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2293f38913b7SCristian Dumitrescu 		return;
2294f38913b7SCristian Dumitrescu 	}
2295f38913b7SCristian Dumitrescu 
2296f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx0, tokens[5])) {
2297f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2298f38913b7SCristian Dumitrescu 		return;
2299f38913b7SCristian Dumitrescu 	}
2300f38913b7SCristian Dumitrescu 
2301f38913b7SCristian Dumitrescu 	if (strcmp(tokens[6], "to")) {
2302f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2303f38913b7SCristian Dumitrescu 		return;
2304f38913b7SCristian Dumitrescu 	}
2305f38913b7SCristian Dumitrescu 
2306f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2307f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2308f38913b7SCristian Dumitrescu 		return;
2309f38913b7SCristian Dumitrescu 	}
2310f38913b7SCristian Dumitrescu 
2311f38913b7SCristian Dumitrescu 	if (strcmp(tokens[8], "reset")) {
2312f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
2313f38913b7SCristian Dumitrescu 		return;
2314f38913b7SCristian Dumitrescu 	}
2315f38913b7SCristian Dumitrescu 
2316f38913b7SCristian Dumitrescu 	for ( ; idx0 <= idx1; idx0++) {
2317f38913b7SCristian Dumitrescu 		int status;
2318f38913b7SCristian Dumitrescu 
2319f38913b7SCristian Dumitrescu 		status = rte_swx_ctl_meter_reset(p->p, name, idx0);
2320f38913b7SCristian Dumitrescu 		if (status) {
2321f38913b7SCristian Dumitrescu 			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
2322f38913b7SCristian Dumitrescu 			return;
2323f38913b7SCristian Dumitrescu 		}
2324f38913b7SCristian Dumitrescu 	}
2325f38913b7SCristian Dumitrescu }
2326f38913b7SCristian Dumitrescu 
2327f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_set_help[] =
2328f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2329f38913b7SCristian Dumitrescu 	"set profile <profile_name>\n";
2330f38913b7SCristian Dumitrescu 
2331f38913b7SCristian Dumitrescu static void
2332f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(char **tokens,
2333f38913b7SCristian Dumitrescu 	uint32_t n_tokens,
2334f38913b7SCristian Dumitrescu 	char *out,
2335f38913b7SCristian Dumitrescu 	size_t out_size,
2336f38913b7SCristian Dumitrescu 	void *obj)
2337f38913b7SCristian Dumitrescu {
2338f38913b7SCristian Dumitrescu 	struct pipeline *p;
2339f38913b7SCristian Dumitrescu 	const char *name, *profile_name;
234000b67591SAli Alnubani 	uint32_t idx0 = 0, idx1 = 0;
2341f38913b7SCristian Dumitrescu 
2342f38913b7SCristian Dumitrescu 	if (n_tokens != 11) {
2343f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2344f38913b7SCristian Dumitrescu 		return;
2345f38913b7SCristian Dumitrescu 	}
2346f38913b7SCristian Dumitrescu 
2347f38913b7SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
2348f38913b7SCristian Dumitrescu 	if (!p || !p->ctl) {
2349f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2350f38913b7SCristian Dumitrescu 		return;
2351f38913b7SCristian Dumitrescu 	}
2352f38913b7SCristian Dumitrescu 
2353f38913b7SCristian Dumitrescu 	if (strcmp(tokens[2], "meter")) {
2354f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2355f38913b7SCristian Dumitrescu 		return;
2356f38913b7SCristian Dumitrescu 	}
2357f38913b7SCristian Dumitrescu 
2358f38913b7SCristian Dumitrescu 	name = tokens[3];
2359f38913b7SCristian Dumitrescu 
2360f38913b7SCristian Dumitrescu 	if (strcmp(tokens[4], "from")) {
2361f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2362f38913b7SCristian Dumitrescu 		return;
2363f38913b7SCristian Dumitrescu 	}
2364f38913b7SCristian Dumitrescu 
2365f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx0, tokens[5])) {
2366f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2367f38913b7SCristian Dumitrescu 		return;
2368f38913b7SCristian Dumitrescu 	}
2369f38913b7SCristian Dumitrescu 
2370f38913b7SCristian Dumitrescu 	if (strcmp(tokens[6], "to")) {
2371f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2372f38913b7SCristian Dumitrescu 		return;
2373f38913b7SCristian Dumitrescu 	}
2374f38913b7SCristian Dumitrescu 
2375f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2376f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2377f38913b7SCristian Dumitrescu 		return;
2378f38913b7SCristian Dumitrescu 	}
2379f38913b7SCristian Dumitrescu 
2380f38913b7SCristian Dumitrescu 	if (strcmp(tokens[8], "set")) {
2381f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
2382f38913b7SCristian Dumitrescu 		return;
2383f38913b7SCristian Dumitrescu 	}
2384f38913b7SCristian Dumitrescu 
2385f38913b7SCristian Dumitrescu 	if (strcmp(tokens[9], "profile")) {
2386f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2387f38913b7SCristian Dumitrescu 		return;
2388f38913b7SCristian Dumitrescu 	}
2389f38913b7SCristian Dumitrescu 
2390f38913b7SCristian Dumitrescu 	profile_name = tokens[10];
2391f38913b7SCristian Dumitrescu 
2392f38913b7SCristian Dumitrescu 	for ( ; idx0 <= idx1; idx0++) {
2393f38913b7SCristian Dumitrescu 		int status;
2394f38913b7SCristian Dumitrescu 
2395f38913b7SCristian Dumitrescu 		status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name);
2396f38913b7SCristian Dumitrescu 		if (status) {
2397f38913b7SCristian Dumitrescu 			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
2398f38913b7SCristian Dumitrescu 			return;
2399f38913b7SCristian Dumitrescu 		}
2400f38913b7SCristian Dumitrescu 	}
2401f38913b7SCristian Dumitrescu }
2402f38913b7SCristian Dumitrescu 
2403f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_stats_help[] =
2404f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2405f38913b7SCristian Dumitrescu 	"stats\n";
2406f38913b7SCristian Dumitrescu 
2407f38913b7SCristian Dumitrescu static void
2408f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(char **tokens,
2409f38913b7SCristian Dumitrescu 	uint32_t n_tokens,
2410f38913b7SCristian Dumitrescu 	char *out,
2411f38913b7SCristian Dumitrescu 	size_t out_size,
2412f38913b7SCristian Dumitrescu 	void *obj)
2413f38913b7SCristian Dumitrescu {
2414f38913b7SCristian Dumitrescu 	struct rte_swx_ctl_meter_stats stats;
2415f38913b7SCristian Dumitrescu 	struct pipeline *p;
2416f38913b7SCristian Dumitrescu 	const char *name;
241700b67591SAli Alnubani 	uint32_t idx0 = 0, idx1 = 0;
2418f38913b7SCristian Dumitrescu 
2419f38913b7SCristian Dumitrescu 	if (n_tokens != 9) {
2420f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2421f38913b7SCristian Dumitrescu 		return;
2422f38913b7SCristian Dumitrescu 	}
2423f38913b7SCristian Dumitrescu 
2424f38913b7SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
2425f38913b7SCristian Dumitrescu 	if (!p || !p->ctl) {
2426f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2427f38913b7SCristian Dumitrescu 		return;
2428f38913b7SCristian Dumitrescu 	}
2429f38913b7SCristian Dumitrescu 
2430f38913b7SCristian Dumitrescu 	if (strcmp(tokens[2], "meter")) {
2431f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2432f38913b7SCristian Dumitrescu 		return;
2433f38913b7SCristian Dumitrescu 	}
2434f38913b7SCristian Dumitrescu 
2435f38913b7SCristian Dumitrescu 	name = tokens[3];
2436f38913b7SCristian Dumitrescu 
2437f38913b7SCristian Dumitrescu 	if (strcmp(tokens[4], "from")) {
2438f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2439f38913b7SCristian Dumitrescu 		return;
2440f38913b7SCristian Dumitrescu 	}
2441f38913b7SCristian Dumitrescu 
2442f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx0, tokens[5])) {
2443f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2444f38913b7SCristian Dumitrescu 		return;
2445f38913b7SCristian Dumitrescu 	}
2446f38913b7SCristian Dumitrescu 
2447f38913b7SCristian Dumitrescu 	if (strcmp(tokens[6], "to")) {
2448f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2449f38913b7SCristian Dumitrescu 		return;
2450f38913b7SCristian Dumitrescu 	}
2451f38913b7SCristian Dumitrescu 
2452f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2453f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2454f38913b7SCristian Dumitrescu 		return;
2455f38913b7SCristian Dumitrescu 	}
2456f38913b7SCristian Dumitrescu 
2457f38913b7SCristian Dumitrescu 	if (strcmp(tokens[8], "stats")) {
2458f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2459f38913b7SCristian Dumitrescu 		return;
2460f38913b7SCristian Dumitrescu 	}
2461f38913b7SCristian Dumitrescu 
2462f38913b7SCristian Dumitrescu 	/* Table header. */
2463f38913b7SCristian Dumitrescu 	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
2464f38913b7SCristian Dumitrescu 		 "-------",
2465f38913b7SCristian Dumitrescu 		 "----------------", "----------------", "----------------",
2466f38913b7SCristian Dumitrescu 		 "----------------", "----------------", "----------------");
2467f38913b7SCristian Dumitrescu 	out_size -= strlen(out);
2468f38913b7SCristian Dumitrescu 	out += strlen(out);
2469f38913b7SCristian Dumitrescu 
2470f38913b7SCristian Dumitrescu 	snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n",
2471f38913b7SCristian Dumitrescu 		 "METER #",
2472f38913b7SCristian Dumitrescu 		 "GREEN (packets)", "YELLOW (packets)", "RED (packets)",
2473f38913b7SCristian Dumitrescu 		 "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)");
2474f38913b7SCristian Dumitrescu 	out_size -= strlen(out);
2475f38913b7SCristian Dumitrescu 	out += strlen(out);
2476f38913b7SCristian Dumitrescu 
2477f38913b7SCristian Dumitrescu 	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
2478f38913b7SCristian Dumitrescu 		 "-------",
2479f38913b7SCristian Dumitrescu 		 "----------------", "----------------", "----------------",
2480f38913b7SCristian Dumitrescu 		 "----------------", "----------------", "----------------");
2481f38913b7SCristian Dumitrescu 	out_size -= strlen(out);
2482f38913b7SCristian Dumitrescu 	out += strlen(out);
2483f38913b7SCristian Dumitrescu 
2484f38913b7SCristian Dumitrescu 	/* Table rows. */
2485f38913b7SCristian Dumitrescu 	for ( ; idx0 <= idx1; idx0++) {
2486f38913b7SCristian Dumitrescu 		int status;
2487f38913b7SCristian Dumitrescu 
2488f38913b7SCristian Dumitrescu 		status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats);
2489f38913b7SCristian Dumitrescu 		if (status) {
2490f38913b7SCristian Dumitrescu 			snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
2491f38913b7SCristian Dumitrescu 			out_size -= strlen(out);
2492f38913b7SCristian Dumitrescu 			out += strlen(out);
2493f38913b7SCristian Dumitrescu 			return;
2494f38913b7SCristian Dumitrescu 		}
2495f38913b7SCristian Dumitrescu 
2496f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
2497f38913b7SCristian Dumitrescu 			 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
2498f38913b7SCristian Dumitrescu 			 idx0,
2499f38913b7SCristian Dumitrescu 			 stats.n_pkts[RTE_COLOR_GREEN],
2500f38913b7SCristian Dumitrescu 			 stats.n_pkts[RTE_COLOR_YELLOW],
2501f38913b7SCristian Dumitrescu 			 stats.n_pkts[RTE_COLOR_RED],
2502f38913b7SCristian Dumitrescu 			 stats.n_bytes[RTE_COLOR_GREEN],
2503f38913b7SCristian Dumitrescu 			 stats.n_bytes[RTE_COLOR_YELLOW],
2504f38913b7SCristian Dumitrescu 			 stats.n_bytes[RTE_COLOR_RED]);
2505f38913b7SCristian Dumitrescu 		out_size -= strlen(out);
2506f38913b7SCristian Dumitrescu 		out += strlen(out);
2507f38913b7SCristian Dumitrescu 	}
2508f38913b7SCristian Dumitrescu }
2509f38913b7SCristian Dumitrescu 
25105074e1d5SCristian Dumitrescu static const char cmd_pipeline_stats_help[] =
25115074e1d5SCristian Dumitrescu "pipeline <pipeline_name> stats\n";
25125074e1d5SCristian Dumitrescu 
25135074e1d5SCristian Dumitrescu static void
25145074e1d5SCristian Dumitrescu cmd_pipeline_stats(char **tokens,
25155074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
25165074e1d5SCristian Dumitrescu 	char *out,
25175074e1d5SCristian Dumitrescu 	size_t out_size,
25185074e1d5SCristian Dumitrescu 	void *obj)
25195074e1d5SCristian Dumitrescu {
25205074e1d5SCristian Dumitrescu 	struct rte_swx_ctl_pipeline_info info;
25215074e1d5SCristian Dumitrescu 	struct pipeline *p;
25225074e1d5SCristian Dumitrescu 	uint32_t i;
25235074e1d5SCristian Dumitrescu 	int status;
25245074e1d5SCristian Dumitrescu 
25255074e1d5SCristian Dumitrescu 	if (n_tokens != 3) {
25265074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
25275074e1d5SCristian Dumitrescu 		return;
25285074e1d5SCristian Dumitrescu 	}
25295074e1d5SCristian Dumitrescu 
25305074e1d5SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
25315074e1d5SCristian Dumitrescu 	if (!p || !p->ctl) {
25325074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
25335074e1d5SCristian Dumitrescu 		return;
25345074e1d5SCristian Dumitrescu 	}
25355074e1d5SCristian Dumitrescu 
25365074e1d5SCristian Dumitrescu 	if (strcmp(tokens[2], "stats")) {
25375074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
25385074e1d5SCristian Dumitrescu 		return;
25395074e1d5SCristian Dumitrescu 	}
25405074e1d5SCristian Dumitrescu 
25415074e1d5SCristian Dumitrescu 	status = rte_swx_ctl_pipeline_info_get(p->p, &info);
25425074e1d5SCristian Dumitrescu 	if (status) {
25435074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "Pipeline info get error.");
25445074e1d5SCristian Dumitrescu 		return;
25455074e1d5SCristian Dumitrescu 	}
25465074e1d5SCristian Dumitrescu 
25475074e1d5SCristian Dumitrescu 	snprintf(out, out_size, "Input ports:\n");
25485074e1d5SCristian Dumitrescu 	out_size -= strlen(out);
25495074e1d5SCristian Dumitrescu 	out += strlen(out);
25505074e1d5SCristian Dumitrescu 
25515074e1d5SCristian Dumitrescu 	for (i = 0; i < info.n_ports_in; i++) {
25525074e1d5SCristian Dumitrescu 		struct rte_swx_port_in_stats stats;
25535074e1d5SCristian Dumitrescu 
25545074e1d5SCristian Dumitrescu 		rte_swx_ctl_pipeline_port_in_stats_read(p->p, i, &stats);
25555074e1d5SCristian Dumitrescu 
25565074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\tPort %u:"
25575074e1d5SCristian Dumitrescu 			" packets %" PRIu64
25585074e1d5SCristian Dumitrescu 			" bytes %" PRIu64
25595074e1d5SCristian Dumitrescu 			" empty %" PRIu64 "\n",
25605074e1d5SCristian Dumitrescu 			i, stats.n_pkts, stats.n_bytes, stats.n_empty);
25615074e1d5SCristian Dumitrescu 		out_size -= strlen(out);
25625074e1d5SCristian Dumitrescu 		out += strlen(out);
25635074e1d5SCristian Dumitrescu 	}
25645074e1d5SCristian Dumitrescu 
2565742b0a57SCristian Dumitrescu 	snprintf(out, out_size, "\nOutput ports:\n");
25665074e1d5SCristian Dumitrescu 	out_size -= strlen(out);
25675074e1d5SCristian Dumitrescu 	out += strlen(out);
25685074e1d5SCristian Dumitrescu 
25695074e1d5SCristian Dumitrescu 	for (i = 0; i < info.n_ports_out; i++) {
25705074e1d5SCristian Dumitrescu 		struct rte_swx_port_out_stats stats;
25715074e1d5SCristian Dumitrescu 
25725074e1d5SCristian Dumitrescu 		rte_swx_ctl_pipeline_port_out_stats_read(p->p, i, &stats);
25735074e1d5SCristian Dumitrescu 
257496b37959SCristian Dumitrescu 		if (i != info.n_ports_out - 1)
257517225455SCristian Dumitrescu 			snprintf(out, out_size, "\tPort %u:", i);
257696b37959SCristian Dumitrescu 		else
257717225455SCristian Dumitrescu 			snprintf(out, out_size, "\tDROP:");
257817225455SCristian Dumitrescu 
257917225455SCristian Dumitrescu 		out_size -= strlen(out);
258017225455SCristian Dumitrescu 		out += strlen(out);
258117225455SCristian Dumitrescu 
258217225455SCristian Dumitrescu 		snprintf(out,
258317225455SCristian Dumitrescu 			out_size,
258496b37959SCristian Dumitrescu 			" packets %" PRIu64
258517225455SCristian Dumitrescu 			" bytes %" PRIu64
258617225455SCristian Dumitrescu 			" clone %" PRIu64
258717225455SCristian Dumitrescu 			" clonerr %" PRIu64 "\n",
258817225455SCristian Dumitrescu 			stats.n_pkts,
258917225455SCristian Dumitrescu 			stats.n_bytes,
259017225455SCristian Dumitrescu 			stats.n_pkts_clone,
259117225455SCristian Dumitrescu 			stats.n_pkts_clone_err);
259296b37959SCristian Dumitrescu 
25935074e1d5SCristian Dumitrescu 		out_size -= strlen(out);
25945074e1d5SCristian Dumitrescu 		out += strlen(out);
25955074e1d5SCristian Dumitrescu 	}
2596742b0a57SCristian Dumitrescu 
2597742b0a57SCristian Dumitrescu 	snprintf(out, out_size, "\nTables:\n");
2598742b0a57SCristian Dumitrescu 	out_size -= strlen(out);
2599742b0a57SCristian Dumitrescu 	out += strlen(out);
2600742b0a57SCristian Dumitrescu 
2601742b0a57SCristian Dumitrescu 	for (i = 0; i < info.n_tables; i++) {
2602742b0a57SCristian Dumitrescu 		struct rte_swx_ctl_table_info table_info;
2603742b0a57SCristian Dumitrescu 		uint64_t n_pkts_action[info.n_actions];
2604742b0a57SCristian Dumitrescu 		struct rte_swx_table_stats stats = {
2605742b0a57SCristian Dumitrescu 			.n_pkts_hit = 0,
2606742b0a57SCristian Dumitrescu 			.n_pkts_miss = 0,
2607742b0a57SCristian Dumitrescu 			.n_pkts_action = n_pkts_action,
2608742b0a57SCristian Dumitrescu 		};
2609742b0a57SCristian Dumitrescu 		uint32_t j;
2610742b0a57SCristian Dumitrescu 
2611742b0a57SCristian Dumitrescu 		status = rte_swx_ctl_table_info_get(p->p, i, &table_info);
2612742b0a57SCristian Dumitrescu 		if (status) {
2613742b0a57SCristian Dumitrescu 			snprintf(out, out_size, "Table info get error.");
2614742b0a57SCristian Dumitrescu 			return;
2615742b0a57SCristian Dumitrescu 		}
2616742b0a57SCristian Dumitrescu 
2617742b0a57SCristian Dumitrescu 		status = rte_swx_ctl_pipeline_table_stats_read(p->p, table_info.name, &stats);
2618742b0a57SCristian Dumitrescu 		if (status) {
2619742b0a57SCristian Dumitrescu 			snprintf(out, out_size, "Table stats read error.");
2620742b0a57SCristian Dumitrescu 			return;
2621742b0a57SCristian Dumitrescu 		}
2622742b0a57SCristian Dumitrescu 
2623742b0a57SCristian Dumitrescu 		snprintf(out, out_size, "\tTable %s:\n"
2624742b0a57SCristian Dumitrescu 			"\t\tHit (packets): %" PRIu64 "\n"
2625742b0a57SCristian Dumitrescu 			"\t\tMiss (packets): %" PRIu64 "\n",
2626742b0a57SCristian Dumitrescu 			table_info.name,
2627742b0a57SCristian Dumitrescu 			stats.n_pkts_hit,
2628742b0a57SCristian Dumitrescu 			stats.n_pkts_miss);
2629742b0a57SCristian Dumitrescu 		out_size -= strlen(out);
2630742b0a57SCristian Dumitrescu 		out += strlen(out);
2631742b0a57SCristian Dumitrescu 
2632742b0a57SCristian Dumitrescu 		for (j = 0; j < info.n_actions; j++) {
2633742b0a57SCristian Dumitrescu 			struct rte_swx_ctl_action_info action_info;
2634742b0a57SCristian Dumitrescu 
2635742b0a57SCristian Dumitrescu 			status = rte_swx_ctl_action_info_get(p->p, j, &action_info);
2636742b0a57SCristian Dumitrescu 			if (status) {
2637742b0a57SCristian Dumitrescu 				snprintf(out, out_size, "Action info get error.");
2638742b0a57SCristian Dumitrescu 				return;
2639742b0a57SCristian Dumitrescu 			}
2640742b0a57SCristian Dumitrescu 
2641742b0a57SCristian Dumitrescu 			snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n",
2642742b0a57SCristian Dumitrescu 				action_info.name,
2643742b0a57SCristian Dumitrescu 				stats.n_pkts_action[j]);
2644742b0a57SCristian Dumitrescu 			out_size -= strlen(out);
2645742b0a57SCristian Dumitrescu 			out += strlen(out);
2646742b0a57SCristian Dumitrescu 		}
2647742b0a57SCristian Dumitrescu 	}
26488bd4862fSCristian Dumitrescu 
26498bd4862fSCristian Dumitrescu 	snprintf(out, out_size, "\nLearner tables:\n");
26508bd4862fSCristian Dumitrescu 	out_size -= strlen(out);
26518bd4862fSCristian Dumitrescu 	out += strlen(out);
26528bd4862fSCristian Dumitrescu 
26538bd4862fSCristian Dumitrescu 	for (i = 0; i < info.n_learners; i++) {
26548bd4862fSCristian Dumitrescu 		struct rte_swx_ctl_learner_info learner_info;
26558bd4862fSCristian Dumitrescu 		uint64_t n_pkts_action[info.n_actions];
26568bd4862fSCristian Dumitrescu 		struct rte_swx_learner_stats stats = {
26578bd4862fSCristian Dumitrescu 			.n_pkts_hit = 0,
26588bd4862fSCristian Dumitrescu 			.n_pkts_miss = 0,
26598bd4862fSCristian Dumitrescu 			.n_pkts_action = n_pkts_action,
26608bd4862fSCristian Dumitrescu 		};
26618bd4862fSCristian Dumitrescu 		uint32_t j;
26628bd4862fSCristian Dumitrescu 
26638bd4862fSCristian Dumitrescu 		status = rte_swx_ctl_learner_info_get(p->p, i, &learner_info);
26648bd4862fSCristian Dumitrescu 		if (status) {
26658bd4862fSCristian Dumitrescu 			snprintf(out, out_size, "Learner table info get error.");
26668bd4862fSCristian Dumitrescu 			return;
26678bd4862fSCristian Dumitrescu 		}
26688bd4862fSCristian Dumitrescu 
26698bd4862fSCristian Dumitrescu 		status = rte_swx_ctl_pipeline_learner_stats_read(p->p, learner_info.name, &stats);
26708bd4862fSCristian Dumitrescu 		if (status) {
26718bd4862fSCristian Dumitrescu 			snprintf(out, out_size, "Learner table stats read error.");
26728bd4862fSCristian Dumitrescu 			return;
26738bd4862fSCristian Dumitrescu 		}
26748bd4862fSCristian Dumitrescu 
26758bd4862fSCristian Dumitrescu 		snprintf(out, out_size, "\tLearner table %s:\n"
26768bd4862fSCristian Dumitrescu 			"\t\tHit (packets): %" PRIu64 "\n"
26778bd4862fSCristian Dumitrescu 			"\t\tMiss (packets): %" PRIu64 "\n"
26788bd4862fSCristian Dumitrescu 			"\t\tLearn OK (packets): %" PRIu64 "\n"
26798bd4862fSCristian Dumitrescu 			"\t\tLearn error (packets): %" PRIu64 "\n"
2680*80dd28afSCristian Dumitrescu 			"\t\tRearm (packets): %" PRIu64 "\n"
26818bd4862fSCristian Dumitrescu 			"\t\tForget (packets): %" PRIu64 "\n",
26828bd4862fSCristian Dumitrescu 			learner_info.name,
26838bd4862fSCristian Dumitrescu 			stats.n_pkts_hit,
26848bd4862fSCristian Dumitrescu 			stats.n_pkts_miss,
26858bd4862fSCristian Dumitrescu 			stats.n_pkts_learn_ok,
26868bd4862fSCristian Dumitrescu 			stats.n_pkts_learn_err,
2687*80dd28afSCristian Dumitrescu 			stats.n_pkts_rearm,
26888bd4862fSCristian Dumitrescu 			stats.n_pkts_forget);
26898bd4862fSCristian Dumitrescu 		out_size -= strlen(out);
26908bd4862fSCristian Dumitrescu 		out += strlen(out);
26918bd4862fSCristian Dumitrescu 
26928bd4862fSCristian Dumitrescu 		for (j = 0; j < info.n_actions; j++) {
26938bd4862fSCristian Dumitrescu 			struct rte_swx_ctl_action_info action_info;
26948bd4862fSCristian Dumitrescu 
26958bd4862fSCristian Dumitrescu 			status = rte_swx_ctl_action_info_get(p->p, j, &action_info);
26968bd4862fSCristian Dumitrescu 			if (status) {
26978bd4862fSCristian Dumitrescu 				snprintf(out, out_size, "Action info get error.");
26988bd4862fSCristian Dumitrescu 				return;
26998bd4862fSCristian Dumitrescu 			}
27008bd4862fSCristian Dumitrescu 
27018bd4862fSCristian Dumitrescu 			snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n",
27028bd4862fSCristian Dumitrescu 				action_info.name,
27038bd4862fSCristian Dumitrescu 				stats.n_pkts_action[j]);
27048bd4862fSCristian Dumitrescu 			out_size -= strlen(out);
27058bd4862fSCristian Dumitrescu 			out += strlen(out);
27068bd4862fSCristian Dumitrescu 		}
27078bd4862fSCristian Dumitrescu 	}
27085074e1d5SCristian Dumitrescu }
27095074e1d5SCristian Dumitrescu 
271017225455SCristian Dumitrescu static const char cmd_pipeline_mirror_help[] =
271117225455SCristian Dumitrescu "pipeline <pipeline_name> mirror slots <n_slots> sessions <n_sessions>\n";
271217225455SCristian Dumitrescu 
271317225455SCristian Dumitrescu static void
271417225455SCristian Dumitrescu cmd_pipeline_mirror(char **tokens,
271517225455SCristian Dumitrescu 	uint32_t n_tokens,
271617225455SCristian Dumitrescu 	char *out,
271717225455SCristian Dumitrescu 	size_t out_size,
271817225455SCristian Dumitrescu 	void *obj)
271917225455SCristian Dumitrescu {
272017225455SCristian Dumitrescu 	struct rte_swx_pipeline_mirroring_params params;
272117225455SCristian Dumitrescu 	struct pipeline *p;
272217225455SCristian Dumitrescu 	int status;
272317225455SCristian Dumitrescu 
272417225455SCristian Dumitrescu 	if (n_tokens != 7) {
272517225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
272617225455SCristian Dumitrescu 		return;
272717225455SCristian Dumitrescu 	}
272817225455SCristian Dumitrescu 
272917225455SCristian Dumitrescu 	if (strcmp(tokens[0], "pipeline")) {
273017225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
273117225455SCristian Dumitrescu 		return;
273217225455SCristian Dumitrescu 	}
273317225455SCristian Dumitrescu 
273417225455SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
273517225455SCristian Dumitrescu 	if (!p) {
273617225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
273717225455SCristian Dumitrescu 		return;
273817225455SCristian Dumitrescu 	}
273917225455SCristian Dumitrescu 
274017225455SCristian Dumitrescu 	if (strcmp(tokens[2], "mirror")) {
274117225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mirror");
274217225455SCristian Dumitrescu 		return;
274317225455SCristian Dumitrescu 	}
274417225455SCristian Dumitrescu 
274517225455SCristian Dumitrescu 	if (strcmp(tokens[3], "slots")) {
274617225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "slots");
274717225455SCristian Dumitrescu 		return;
274817225455SCristian Dumitrescu 	}
274917225455SCristian Dumitrescu 
275017225455SCristian Dumitrescu 	if (parser_read_uint32(&params.n_slots, tokens[4])) {
275117225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "n_slots");
275217225455SCristian Dumitrescu 		return;
275317225455SCristian Dumitrescu 	}
275417225455SCristian Dumitrescu 
275517225455SCristian Dumitrescu 	if (strcmp(tokens[5], "sessions")) {
275617225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "sessions");
275717225455SCristian Dumitrescu 		return;
275817225455SCristian Dumitrescu 	}
275917225455SCristian Dumitrescu 
276017225455SCristian Dumitrescu 	if (parser_read_uint32(&params.n_sessions, tokens[6])) {
276117225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "n_sessions");
276217225455SCristian Dumitrescu 		return;
276317225455SCristian Dumitrescu 	}
276417225455SCristian Dumitrescu 
276517225455SCristian Dumitrescu 	status = rte_swx_pipeline_mirroring_config(p->p, &params);
276617225455SCristian Dumitrescu 	if (status) {
276717225455SCristian Dumitrescu 		snprintf(out, out_size, "Command failed!\n");
276817225455SCristian Dumitrescu 		return;
276917225455SCristian Dumitrescu 	}
277017225455SCristian Dumitrescu }
277117225455SCristian Dumitrescu 
277217225455SCristian Dumitrescu static const char cmd_pipeline_mirror_session_help[] =
277317225455SCristian Dumitrescu "pipeline <pipeline_name> mirror session <session_id> port <port_id> clone fast | slow "
277417225455SCristian Dumitrescu "truncate <truncation_length>\n";
277517225455SCristian Dumitrescu 
277617225455SCristian Dumitrescu static void
277717225455SCristian Dumitrescu cmd_pipeline_mirror_session(char **tokens,
277817225455SCristian Dumitrescu 	uint32_t n_tokens,
277917225455SCristian Dumitrescu 	char *out,
278017225455SCristian Dumitrescu 	size_t out_size,
278117225455SCristian Dumitrescu 	void *obj)
278217225455SCristian Dumitrescu {
278317225455SCristian Dumitrescu 	struct rte_swx_pipeline_mirroring_session_params params;
278417225455SCristian Dumitrescu 	struct pipeline *p;
278517225455SCristian Dumitrescu 	uint32_t session_id;
278617225455SCristian Dumitrescu 	int status;
278717225455SCristian Dumitrescu 
278817225455SCristian Dumitrescu 	if (n_tokens != 11) {
278917225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
279017225455SCristian Dumitrescu 		return;
279117225455SCristian Dumitrescu 	}
279217225455SCristian Dumitrescu 
279317225455SCristian Dumitrescu 	if (strcmp(tokens[0], "pipeline")) {
279417225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
279517225455SCristian Dumitrescu 		return;
279617225455SCristian Dumitrescu 	}
279717225455SCristian Dumitrescu 
279817225455SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
279917225455SCristian Dumitrescu 	if (!p || !p->ctl) {
280017225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
280117225455SCristian Dumitrescu 		return;
280217225455SCristian Dumitrescu 	}
280317225455SCristian Dumitrescu 
280417225455SCristian Dumitrescu 	if (strcmp(tokens[2], "mirror")) {
280517225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mirror");
280617225455SCristian Dumitrescu 		return;
280717225455SCristian Dumitrescu 	}
280817225455SCristian Dumitrescu 
280917225455SCristian Dumitrescu 	if (strcmp(tokens[3], "session")) {
281017225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "session");
281117225455SCristian Dumitrescu 		return;
281217225455SCristian Dumitrescu 	}
281317225455SCristian Dumitrescu 
281417225455SCristian Dumitrescu 	if (parser_read_uint32(&session_id, tokens[4])) {
281517225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "session_id");
281617225455SCristian Dumitrescu 		return;
281717225455SCristian Dumitrescu 	}
281817225455SCristian Dumitrescu 
281917225455SCristian Dumitrescu 	if (strcmp(tokens[5], "port")) {
282017225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
282117225455SCristian Dumitrescu 		return;
282217225455SCristian Dumitrescu 	}
282317225455SCristian Dumitrescu 
282417225455SCristian Dumitrescu 	if (parser_read_uint32(&params.port_id, tokens[6])) {
282517225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
282617225455SCristian Dumitrescu 		return;
282717225455SCristian Dumitrescu 	}
282817225455SCristian Dumitrescu 
282917225455SCristian Dumitrescu 	if (strcmp(tokens[7], "clone")) {
283017225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "clone");
283117225455SCristian Dumitrescu 		return;
283217225455SCristian Dumitrescu 	}
283317225455SCristian Dumitrescu 
283417225455SCristian Dumitrescu 	if (!strcmp(tokens[8], "fast"))
283517225455SCristian Dumitrescu 		params.fast_clone = 1;
283617225455SCristian Dumitrescu 	else if (!strcmp(tokens[8], "slow"))
283717225455SCristian Dumitrescu 		params.fast_clone = 0;
283817225455SCristian Dumitrescu 	else {
283917225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "clone");
284017225455SCristian Dumitrescu 		return;
284117225455SCristian Dumitrescu 	}
284217225455SCristian Dumitrescu 
284317225455SCristian Dumitrescu 	if (strcmp(tokens[9], "truncate")) {
284417225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "truncate");
284517225455SCristian Dumitrescu 		return;
284617225455SCristian Dumitrescu 	}
284717225455SCristian Dumitrescu 
284817225455SCristian Dumitrescu 	if (parser_read_uint32(&params.truncation_length, tokens[10])) {
284917225455SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "truncation_length");
285017225455SCristian Dumitrescu 		return;
285117225455SCristian Dumitrescu 	}
285217225455SCristian Dumitrescu 
285317225455SCristian Dumitrescu 	status = rte_swx_ctl_pipeline_mirroring_session_set(p->p, session_id, &params);
285417225455SCristian Dumitrescu 	if (status) {
285517225455SCristian Dumitrescu 		snprintf(out, out_size, "Command failed!\n");
285617225455SCristian Dumitrescu 		return;
285717225455SCristian Dumitrescu 	}
285817225455SCristian Dumitrescu }
285917225455SCristian Dumitrescu 
28605074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_enable_help[] =
28615074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> enable\n";
28625074e1d5SCristian Dumitrescu 
28635074e1d5SCristian Dumitrescu static void
28645074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(char **tokens,
28655074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
28665074e1d5SCristian Dumitrescu 	char *out,
28675074e1d5SCristian Dumitrescu 	size_t out_size,
28685074e1d5SCristian Dumitrescu 	void *obj)
28695074e1d5SCristian Dumitrescu {
28705074e1d5SCristian Dumitrescu 	char *pipeline_name;
28715074e1d5SCristian Dumitrescu 	struct pipeline *p;
28725074e1d5SCristian Dumitrescu 	uint32_t thread_id;
28735074e1d5SCristian Dumitrescu 	int status;
28745074e1d5SCristian Dumitrescu 
28755074e1d5SCristian Dumitrescu 	if (n_tokens != 5) {
28765074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
28775074e1d5SCristian Dumitrescu 		return;
28785074e1d5SCristian Dumitrescu 	}
28795074e1d5SCristian Dumitrescu 
28805074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
28815074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
28825074e1d5SCristian Dumitrescu 		return;
28835074e1d5SCristian Dumitrescu 	}
28845074e1d5SCristian Dumitrescu 
28855074e1d5SCristian Dumitrescu 	if (strcmp(tokens[2], "pipeline") != 0) {
28865074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
28875074e1d5SCristian Dumitrescu 		return;
28885074e1d5SCristian Dumitrescu 	}
28895074e1d5SCristian Dumitrescu 
28905074e1d5SCristian Dumitrescu 	pipeline_name = tokens[3];
28915074e1d5SCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
28925074e1d5SCristian Dumitrescu 	if (!p || !p->ctl) {
28935074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
28945074e1d5SCristian Dumitrescu 		return;
28955074e1d5SCristian Dumitrescu 	}
28965074e1d5SCristian Dumitrescu 
28975074e1d5SCristian Dumitrescu 	if (strcmp(tokens[4], "enable") != 0) {
28985074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
28995074e1d5SCristian Dumitrescu 		return;
29005074e1d5SCristian Dumitrescu 	}
29015074e1d5SCristian Dumitrescu 
29025074e1d5SCristian Dumitrescu 	status = thread_pipeline_enable(thread_id, obj, pipeline_name);
29035074e1d5SCristian Dumitrescu 	if (status) {
29045074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
29055074e1d5SCristian Dumitrescu 		return;
29065074e1d5SCristian Dumitrescu 	}
29075074e1d5SCristian Dumitrescu }
29085074e1d5SCristian Dumitrescu 
29095074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_disable_help[] =
29105074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> disable\n";
29115074e1d5SCristian Dumitrescu 
29125074e1d5SCristian Dumitrescu static void
29135074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(char **tokens,
29145074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
29155074e1d5SCristian Dumitrescu 	char *out,
29165074e1d5SCristian Dumitrescu 	size_t out_size,
29175074e1d5SCristian Dumitrescu 	void *obj)
29185074e1d5SCristian Dumitrescu {
29195074e1d5SCristian Dumitrescu 	struct pipeline *p;
29205074e1d5SCristian Dumitrescu 	char *pipeline_name;
29215074e1d5SCristian Dumitrescu 	uint32_t thread_id;
29225074e1d5SCristian Dumitrescu 	int status;
29235074e1d5SCristian Dumitrescu 
29245074e1d5SCristian Dumitrescu 	if (n_tokens != 5) {
29255074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
29265074e1d5SCristian Dumitrescu 		return;
29275074e1d5SCristian Dumitrescu 	}
29285074e1d5SCristian Dumitrescu 
29295074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
29305074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
29315074e1d5SCristian Dumitrescu 		return;
29325074e1d5SCristian Dumitrescu 	}
29335074e1d5SCristian Dumitrescu 
29345074e1d5SCristian Dumitrescu 	if (strcmp(tokens[2], "pipeline") != 0) {
29355074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
29365074e1d5SCristian Dumitrescu 		return;
29375074e1d5SCristian Dumitrescu 	}
29385074e1d5SCristian Dumitrescu 
29395074e1d5SCristian Dumitrescu 	pipeline_name = tokens[3];
29405074e1d5SCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
29415074e1d5SCristian Dumitrescu 	if (!p || !p->ctl) {
29425074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
29435074e1d5SCristian Dumitrescu 		return;
29445074e1d5SCristian Dumitrescu 	}
29455074e1d5SCristian Dumitrescu 
29465074e1d5SCristian Dumitrescu 	if (strcmp(tokens[4], "disable") != 0) {
29475074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
29485074e1d5SCristian Dumitrescu 		return;
29495074e1d5SCristian Dumitrescu 	}
29505074e1d5SCristian Dumitrescu 
29515074e1d5SCristian Dumitrescu 	status = thread_pipeline_disable(thread_id, obj, pipeline_name);
29525074e1d5SCristian Dumitrescu 	if (status) {
29535074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL,
29545074e1d5SCristian Dumitrescu 			"thread pipeline disable");
29555074e1d5SCristian Dumitrescu 		return;
29565074e1d5SCristian Dumitrescu 	}
29575074e1d5SCristian Dumitrescu }
29585074e1d5SCristian Dumitrescu 
29595074e1d5SCristian Dumitrescu static void
29605074e1d5SCristian Dumitrescu cmd_help(char **tokens,
29615074e1d5SCristian Dumitrescu 	 uint32_t n_tokens,
29625074e1d5SCristian Dumitrescu 	 char *out,
29635074e1d5SCristian Dumitrescu 	 size_t out_size,
29645074e1d5SCristian Dumitrescu 	 void *arg __rte_unused)
29655074e1d5SCristian Dumitrescu {
29665074e1d5SCristian Dumitrescu 	tokens++;
29675074e1d5SCristian Dumitrescu 	n_tokens--;
29685074e1d5SCristian Dumitrescu 
29695074e1d5SCristian Dumitrescu 	if (n_tokens == 0) {
29705074e1d5SCristian Dumitrescu 		snprintf(out, out_size,
29717fef9ef1SYogesh Jangra 			"Type 'help <command>' for command details.\n\n"
29727fef9ef1SYogesh Jangra 			"List of commands:\n"
29737fef9ef1SYogesh Jangra 			"\tmempool\n"
29747fef9ef1SYogesh Jangra 			"\tlink\n"
2975e2b8dc52SVenkata Suresh Kumar P 			"\ttap\n"
29767fef9ef1SYogesh Jangra 			"\tpipeline create\n"
29777fef9ef1SYogesh Jangra 			"\tpipeline port in\n"
29787fef9ef1SYogesh Jangra 			"\tpipeline port out\n"
29797fef9ef1SYogesh Jangra 			"\tpipeline build\n"
298075129cebSChurchill Khangar 			"\tpipeline table add\n"
298175129cebSChurchill Khangar 			"\tpipeline table delete\n"
298275129cebSChurchill Khangar 			"\tpipeline table default\n"
298375129cebSChurchill Khangar 			"\tpipeline table show\n"
2984598fe0ddSCristian Dumitrescu 			"\tpipeline selector group add\n"
2985598fe0ddSCristian Dumitrescu 			"\tpipeline selector group delete\n"
2986598fe0ddSCristian Dumitrescu 			"\tpipeline selector group member add\n"
2987598fe0ddSCristian Dumitrescu 			"\tpipeline selector group member delete\n"
2988598fe0ddSCristian Dumitrescu 			"\tpipeline selector show\n"
29898bd4862fSCristian Dumitrescu 			"\tpipeline learner default\n"
299075129cebSChurchill Khangar 			"\tpipeline commit\n"
299175129cebSChurchill Khangar 			"\tpipeline abort\n"
299264cfcebdSCristian Dumitrescu 			"\tpipeline regrd\n"
299364cfcebdSCristian Dumitrescu 			"\tpipeline regwr\n"
2994f38913b7SCristian Dumitrescu 			"\tpipeline meter profile add\n"
2995f38913b7SCristian Dumitrescu 			"\tpipeline meter profile delete\n"
2996f38913b7SCristian Dumitrescu 			"\tpipeline meter reset\n"
2997f38913b7SCristian Dumitrescu 			"\tpipeline meter set\n"
2998f38913b7SCristian Dumitrescu 			"\tpipeline meter stats\n"
29997fef9ef1SYogesh Jangra 			"\tpipeline stats\n"
300017225455SCristian Dumitrescu 			"\tpipeline mirror\n"
300117225455SCristian Dumitrescu 			"\tpipeline mirror session\n"
30027fef9ef1SYogesh Jangra 			"\tthread pipeline enable\n"
30037fef9ef1SYogesh Jangra 			"\tthread pipeline disable\n\n");
30045074e1d5SCristian Dumitrescu 		return;
30055074e1d5SCristian Dumitrescu 	}
30065074e1d5SCristian Dumitrescu 
30075074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "mempool") == 0) {
30085074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
30095074e1d5SCristian Dumitrescu 		return;
30105074e1d5SCristian Dumitrescu 	}
30115074e1d5SCristian Dumitrescu 
30125074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "link") == 0) {
30135074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_link_help);
30145074e1d5SCristian Dumitrescu 		return;
30155074e1d5SCristian Dumitrescu 	}
30165074e1d5SCristian Dumitrescu 
301777a41301SCristian Dumitrescu 	if (strcmp(tokens[0], "ring") == 0) {
301877a41301SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_ring_help);
301977a41301SCristian Dumitrescu 		return;
302077a41301SCristian Dumitrescu 	}
302177a41301SCristian Dumitrescu 
3022e2b8dc52SVenkata Suresh Kumar P 	if (strcmp(tokens[0], "tap") == 0) {
3023e2b8dc52SVenkata Suresh Kumar P 		snprintf(out, out_size, "\n%s\n", cmd_tap_help);
3024e2b8dc52SVenkata Suresh Kumar P 		return;
3025e2b8dc52SVenkata Suresh Kumar P 	}
3026e2b8dc52SVenkata Suresh Kumar P 
30275074e1d5SCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
30287fef9ef1SYogesh Jangra 		(n_tokens == 2) && (strcmp(tokens[1], "create") == 0)) {
30295074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_create_help);
30305074e1d5SCristian Dumitrescu 		return;
30315074e1d5SCristian Dumitrescu 	}
30325074e1d5SCristian Dumitrescu 
30335074e1d5SCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
30347fef9ef1SYogesh Jangra 		(n_tokens == 3) && (strcmp(tokens[1], "port") == 0)) {
30357fef9ef1SYogesh Jangra 		if (strcmp(tokens[2], "in") == 0) {
30365074e1d5SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
30375074e1d5SCristian Dumitrescu 				cmd_pipeline_port_in_help);
30385074e1d5SCristian Dumitrescu 			return;
30395074e1d5SCristian Dumitrescu 		}
30405074e1d5SCristian Dumitrescu 
30417fef9ef1SYogesh Jangra 		if (strcmp(tokens[2], "out") == 0) {
30425074e1d5SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
30435074e1d5SCristian Dumitrescu 				cmd_pipeline_port_out_help);
30445074e1d5SCristian Dumitrescu 			return;
30455074e1d5SCristian Dumitrescu 		}
30465074e1d5SCristian Dumitrescu 	}
30475074e1d5SCristian Dumitrescu 
30485074e1d5SCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
30497fef9ef1SYogesh Jangra 		(n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) {
30505074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help);
30515074e1d5SCristian Dumitrescu 		return;
30525074e1d5SCristian Dumitrescu 	}
30535074e1d5SCristian Dumitrescu 
30545074e1d5SCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
30557fef9ef1SYogesh Jangra 		(n_tokens == 3) &&
30567fef9ef1SYogesh Jangra 		(strcmp(tokens[1], "table") == 0) &&
305775129cebSChurchill Khangar 		(strcmp(tokens[2], "add") == 0)) {
30585074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
305975129cebSChurchill Khangar 			cmd_pipeline_table_add_help);
306075129cebSChurchill Khangar 		return;
306175129cebSChurchill Khangar 	}
306275129cebSChurchill Khangar 
306375129cebSChurchill Khangar 	if ((strcmp(tokens[0], "pipeline") == 0) &&
306475129cebSChurchill Khangar 		(n_tokens == 3) &&
306575129cebSChurchill Khangar 		(strcmp(tokens[1], "table") == 0) &&
306675129cebSChurchill Khangar 		(strcmp(tokens[2], "delete") == 0)) {
306775129cebSChurchill Khangar 		snprintf(out, out_size, "\n%s\n",
306875129cebSChurchill Khangar 			cmd_pipeline_table_delete_help);
306975129cebSChurchill Khangar 		return;
307075129cebSChurchill Khangar 	}
307175129cebSChurchill Khangar 
307275129cebSChurchill Khangar 	if ((strcmp(tokens[0], "pipeline") == 0) &&
307375129cebSChurchill Khangar 		(n_tokens == 3) &&
307475129cebSChurchill Khangar 		(strcmp(tokens[1], "table") == 0) &&
307575129cebSChurchill Khangar 		(strcmp(tokens[2], "default") == 0)) {
307675129cebSChurchill Khangar 		snprintf(out, out_size, "\n%s\n",
307775129cebSChurchill Khangar 			cmd_pipeline_table_default_help);
307875129cebSChurchill Khangar 		return;
307975129cebSChurchill Khangar 	}
308075129cebSChurchill Khangar 
308175129cebSChurchill Khangar 	if ((strcmp(tokens[0], "pipeline") == 0) &&
308275129cebSChurchill Khangar 		(n_tokens == 3) &&
308375129cebSChurchill Khangar 		(strcmp(tokens[1], "table") == 0) &&
308475129cebSChurchill Khangar 		(strcmp(tokens[2], "show") == 0)) {
308575129cebSChurchill Khangar 		snprintf(out, out_size, "\n%s\n",
308675129cebSChurchill Khangar 			cmd_pipeline_table_show_help);
308775129cebSChurchill Khangar 		return;
308875129cebSChurchill Khangar 	}
308975129cebSChurchill Khangar 
309075129cebSChurchill Khangar 	if ((strcmp(tokens[0], "pipeline") == 0) &&
3091598fe0ddSCristian Dumitrescu 		(n_tokens == 4) &&
3092598fe0ddSCristian Dumitrescu 		(strcmp(tokens[1], "selector") == 0) &&
3093598fe0ddSCristian Dumitrescu 		(strcmp(tokens[2], "group") == 0) &&
3094598fe0ddSCristian Dumitrescu 		(strcmp(tokens[3], "add") == 0)) {
3095598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
3096598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_add_help);
3097598fe0ddSCristian Dumitrescu 		return;
3098598fe0ddSCristian Dumitrescu 	}
3099598fe0ddSCristian Dumitrescu 
3100598fe0ddSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
3101598fe0ddSCristian Dumitrescu 		(n_tokens == 4) &&
3102598fe0ddSCristian Dumitrescu 		(strcmp(tokens[1], "selector") == 0) &&
3103598fe0ddSCristian Dumitrescu 		(strcmp(tokens[2], "group") == 0) &&
3104598fe0ddSCristian Dumitrescu 		(strcmp(tokens[3], "delete") == 0)) {
3105598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
3106598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_delete_help);
3107598fe0ddSCristian Dumitrescu 		return;
3108598fe0ddSCristian Dumitrescu 	}
3109598fe0ddSCristian Dumitrescu 
3110598fe0ddSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
3111598fe0ddSCristian Dumitrescu 		(n_tokens == 5) &&
3112598fe0ddSCristian Dumitrescu 		(strcmp(tokens[1], "selector") == 0) &&
3113598fe0ddSCristian Dumitrescu 		(strcmp(tokens[2], "group") == 0) &&
3114598fe0ddSCristian Dumitrescu 		(strcmp(tokens[3], "member") == 0) &&
3115598fe0ddSCristian Dumitrescu 		(strcmp(tokens[4], "add") == 0)) {
3116598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
3117598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_member_add_help);
3118598fe0ddSCristian Dumitrescu 		return;
3119598fe0ddSCristian Dumitrescu 	}
3120598fe0ddSCristian Dumitrescu 
3121598fe0ddSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
3122598fe0ddSCristian Dumitrescu 		(n_tokens == 5) &&
3123598fe0ddSCristian Dumitrescu 		(strcmp(tokens[1], "selector") == 0) &&
3124598fe0ddSCristian Dumitrescu 		(strcmp(tokens[2], "group") == 0) &&
3125598fe0ddSCristian Dumitrescu 		(strcmp(tokens[3], "member") == 0) &&
3126598fe0ddSCristian Dumitrescu 		(strcmp(tokens[4], "delete") == 0)) {
3127598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
3128598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_member_delete_help);
3129598fe0ddSCristian Dumitrescu 		return;
3130598fe0ddSCristian Dumitrescu 	}
3131598fe0ddSCristian Dumitrescu 
3132598fe0ddSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
3133598fe0ddSCristian Dumitrescu 		(n_tokens == 3) &&
3134598fe0ddSCristian Dumitrescu 		(strcmp(tokens[1], "selector") == 0) &&
3135598fe0ddSCristian Dumitrescu 		(strcmp(tokens[2], "show") == 0)) {
3136598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
3137598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_show_help);
3138598fe0ddSCristian Dumitrescu 		return;
3139598fe0ddSCristian Dumitrescu 	}
3140598fe0ddSCristian Dumitrescu 
3141598fe0ddSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
31428bd4862fSCristian Dumitrescu 		(n_tokens == 3) &&
31438bd4862fSCristian Dumitrescu 		(strcmp(tokens[1], "learner") == 0) &&
31448bd4862fSCristian Dumitrescu 		(strcmp(tokens[2], "default") == 0)) {
31458bd4862fSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
31468bd4862fSCristian Dumitrescu 			cmd_pipeline_learner_default_help);
31478bd4862fSCristian Dumitrescu 		return;
31488bd4862fSCristian Dumitrescu 	}
31498bd4862fSCristian Dumitrescu 
31508bd4862fSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
315175129cebSChurchill Khangar 		(n_tokens == 2) &&
315275129cebSChurchill Khangar 		(strcmp(tokens[1], "commit") == 0)) {
315375129cebSChurchill Khangar 		snprintf(out, out_size, "\n%s\n",
315475129cebSChurchill Khangar 			cmd_pipeline_commit_help);
315575129cebSChurchill Khangar 		return;
315675129cebSChurchill Khangar 	}
315775129cebSChurchill Khangar 
315875129cebSChurchill Khangar 	if ((strcmp(tokens[0], "pipeline") == 0) &&
315975129cebSChurchill Khangar 		(n_tokens == 2) &&
316075129cebSChurchill Khangar 		(strcmp(tokens[1], "abort") == 0)) {
316175129cebSChurchill Khangar 		snprintf(out, out_size, "\n%s\n",
316275129cebSChurchill Khangar 			cmd_pipeline_abort_help);
31635074e1d5SCristian Dumitrescu 		return;
31645074e1d5SCristian Dumitrescu 	}
31655074e1d5SCristian Dumitrescu 
31665074e1d5SCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
316764cfcebdSCristian Dumitrescu 		(n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) {
316864cfcebdSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help);
316964cfcebdSCristian Dumitrescu 		return;
317064cfcebdSCristian Dumitrescu 	}
317164cfcebdSCristian Dumitrescu 
317264cfcebdSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
317364cfcebdSCristian Dumitrescu 		(n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) {
317464cfcebdSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help);
317564cfcebdSCristian Dumitrescu 		return;
317664cfcebdSCristian Dumitrescu 	}
317764cfcebdSCristian Dumitrescu 
3178f38913b7SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
3179f38913b7SCristian Dumitrescu 		(n_tokens == 4) && !strcmp(tokens[1], "meter")
3180f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[2], "profile")
3181f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[3], "add")) {
3182f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help);
3183f38913b7SCristian Dumitrescu 		return;
3184f38913b7SCristian Dumitrescu 	}
3185f38913b7SCristian Dumitrescu 
3186f38913b7SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
3187f38913b7SCristian Dumitrescu 		(n_tokens == 4) && !strcmp(tokens[1], "meter")
3188f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[2], "profile")
3189f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[3], "delete")) {
3190f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help);
3191f38913b7SCristian Dumitrescu 		return;
3192f38913b7SCristian Dumitrescu 	}
3193f38913b7SCristian Dumitrescu 
3194f38913b7SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
3195f38913b7SCristian Dumitrescu 		(n_tokens == 3) && !strcmp(tokens[1], "meter")
3196f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[2], "reset")) {
3197f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help);
3198f38913b7SCristian Dumitrescu 		return;
3199f38913b7SCristian Dumitrescu 	}
3200f38913b7SCristian Dumitrescu 
3201f38913b7SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
3202f38913b7SCristian Dumitrescu 		(n_tokens == 3) && !strcmp(tokens[1], "meter")
3203f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[2], "set")) {
3204f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help);
3205f38913b7SCristian Dumitrescu 		return;
3206f38913b7SCristian Dumitrescu 	}
3207f38913b7SCristian Dumitrescu 
3208f38913b7SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
3209f38913b7SCristian Dumitrescu 		(n_tokens == 3) && !strcmp(tokens[1], "meter")
3210f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[2], "stats")) {
3211f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help);
3212f38913b7SCristian Dumitrescu 		return;
3213f38913b7SCristian Dumitrescu 	}
3214f38913b7SCristian Dumitrescu 
321564cfcebdSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
32167fef9ef1SYogesh Jangra 		(n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) {
32175074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help);
32185074e1d5SCristian Dumitrescu 		return;
32195074e1d5SCristian Dumitrescu 	}
32205074e1d5SCristian Dumitrescu 
322117225455SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
322217225455SCristian Dumitrescu 		(n_tokens == 2) && !strcmp(tokens[1], "mirror")) {
322317225455SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_mirror_help);
322417225455SCristian Dumitrescu 		return;
322517225455SCristian Dumitrescu 	}
322617225455SCristian Dumitrescu 
322717225455SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
322817225455SCristian Dumitrescu 		(n_tokens == 3) && !strcmp(tokens[1], "mirror")
322917225455SCristian Dumitrescu 		&& !strcmp(tokens[2], "session")) {
323017225455SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_mirror_session_help);
323117225455SCristian Dumitrescu 		return;
323217225455SCristian Dumitrescu 	}
323317225455SCristian Dumitrescu 
32345074e1d5SCristian Dumitrescu 	if ((n_tokens == 3) &&
32355074e1d5SCristian Dumitrescu 		(strcmp(tokens[0], "thread") == 0) &&
32365074e1d5SCristian Dumitrescu 		(strcmp(tokens[1], "pipeline") == 0)) {
32375074e1d5SCristian Dumitrescu 		if (strcmp(tokens[2], "enable") == 0) {
32385074e1d5SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
32395074e1d5SCristian Dumitrescu 				cmd_thread_pipeline_enable_help);
32405074e1d5SCristian Dumitrescu 			return;
32415074e1d5SCristian Dumitrescu 		}
32425074e1d5SCristian Dumitrescu 
32435074e1d5SCristian Dumitrescu 		if (strcmp(tokens[2], "disable") == 0) {
32445074e1d5SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
32455074e1d5SCristian Dumitrescu 				cmd_thread_pipeline_disable_help);
32465074e1d5SCristian Dumitrescu 			return;
32475074e1d5SCristian Dumitrescu 		}
32485074e1d5SCristian Dumitrescu 	}
32495074e1d5SCristian Dumitrescu 
32505074e1d5SCristian Dumitrescu 	snprintf(out, out_size, "Invalid command\n");
32515074e1d5SCristian Dumitrescu }
32525074e1d5SCristian Dumitrescu 
32535074e1d5SCristian Dumitrescu void
32545074e1d5SCristian Dumitrescu cli_process(char *in, char *out, size_t out_size, void *obj)
32555074e1d5SCristian Dumitrescu {
32565074e1d5SCristian Dumitrescu 	char *tokens[CMD_MAX_TOKENS];
32575074e1d5SCristian Dumitrescu 	uint32_t n_tokens = RTE_DIM(tokens);
32585074e1d5SCristian Dumitrescu 	int status;
32595074e1d5SCristian Dumitrescu 
32605074e1d5SCristian Dumitrescu 	if (is_comment(in))
32615074e1d5SCristian Dumitrescu 		return;
32625074e1d5SCristian Dumitrescu 
32635074e1d5SCristian Dumitrescu 	status = parse_tokenize_string(in, tokens, &n_tokens);
32645074e1d5SCristian Dumitrescu 	if (status) {
32655074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
32665074e1d5SCristian Dumitrescu 		return;
32675074e1d5SCristian Dumitrescu 	}
32685074e1d5SCristian Dumitrescu 
32695074e1d5SCristian Dumitrescu 	if (n_tokens == 0)
32705074e1d5SCristian Dumitrescu 		return;
32715074e1d5SCristian Dumitrescu 
32725074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "help") == 0) {
32735074e1d5SCristian Dumitrescu 		cmd_help(tokens, n_tokens, out, out_size, obj);
32745074e1d5SCristian Dumitrescu 		return;
32755074e1d5SCristian Dumitrescu 	}
32765074e1d5SCristian Dumitrescu 
32775074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "mempool") == 0) {
32785074e1d5SCristian Dumitrescu 		cmd_mempool(tokens, n_tokens, out, out_size, obj);
32795074e1d5SCristian Dumitrescu 		return;
32805074e1d5SCristian Dumitrescu 	}
32815074e1d5SCristian Dumitrescu 
32825074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "link") == 0) {
3283821848f5SCristian Dumitrescu 		if ((n_tokens >= 2) && (strcmp(tokens[1], "show") == 0)) {
32845074e1d5SCristian Dumitrescu 			cmd_link_show(tokens, n_tokens, out, out_size, obj);
32855074e1d5SCristian Dumitrescu 			return;
32865074e1d5SCristian Dumitrescu 		}
32875074e1d5SCristian Dumitrescu 
32885074e1d5SCristian Dumitrescu 		cmd_link(tokens, n_tokens, out, out_size, obj);
32895074e1d5SCristian Dumitrescu 		return;
32905074e1d5SCristian Dumitrescu 	}
32915074e1d5SCristian Dumitrescu 
329277a41301SCristian Dumitrescu 	if (strcmp(tokens[0], "ring") == 0) {
329377a41301SCristian Dumitrescu 		cmd_ring(tokens, n_tokens, out, out_size, obj);
329477a41301SCristian Dumitrescu 		return;
329577a41301SCristian Dumitrescu 	}
329677a41301SCristian Dumitrescu 
3297e2b8dc52SVenkata Suresh Kumar P 	if (strcmp(tokens[0], "tap") == 0) {
3298e2b8dc52SVenkata Suresh Kumar P 		cmd_tap(tokens, n_tokens, out, out_size, obj);
3299e2b8dc52SVenkata Suresh Kumar P 		return;
3300e2b8dc52SVenkata Suresh Kumar P 	}
3301e2b8dc52SVenkata Suresh Kumar P 
33025074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "pipeline") == 0) {
33035074e1d5SCristian Dumitrescu 		if ((n_tokens >= 3) &&
33045074e1d5SCristian Dumitrescu 			(strcmp(tokens[2], "create") == 0)) {
33055074e1d5SCristian Dumitrescu 			cmd_pipeline_create(tokens, n_tokens, out, out_size,
33065074e1d5SCristian Dumitrescu 				obj);
33075074e1d5SCristian Dumitrescu 			return;
33085074e1d5SCristian Dumitrescu 		}
33095074e1d5SCristian Dumitrescu 
33105074e1d5SCristian Dumitrescu 		if ((n_tokens >= 4) &&
33115074e1d5SCristian Dumitrescu 			(strcmp(tokens[2], "port") == 0) &&
33125074e1d5SCristian Dumitrescu 			(strcmp(tokens[3], "in") == 0)) {
33135074e1d5SCristian Dumitrescu 			cmd_pipeline_port_in(tokens, n_tokens, out, out_size,
33145074e1d5SCristian Dumitrescu 				obj);
33155074e1d5SCristian Dumitrescu 			return;
33165074e1d5SCristian Dumitrescu 		}
33175074e1d5SCristian Dumitrescu 
33185074e1d5SCristian Dumitrescu 		if ((n_tokens >= 4) &&
33195074e1d5SCristian Dumitrescu 			(strcmp(tokens[2], "port") == 0) &&
33205074e1d5SCristian Dumitrescu 			(strcmp(tokens[3], "out") == 0)) {
33215074e1d5SCristian Dumitrescu 			cmd_pipeline_port_out(tokens, n_tokens, out, out_size,
33225074e1d5SCristian Dumitrescu 				obj);
33235074e1d5SCristian Dumitrescu 			return;
33245074e1d5SCristian Dumitrescu 		}
33255074e1d5SCristian Dumitrescu 
33265074e1d5SCristian Dumitrescu 		if ((n_tokens >= 3) &&
33275074e1d5SCristian Dumitrescu 			(strcmp(tokens[2], "build") == 0)) {
33285074e1d5SCristian Dumitrescu 			cmd_pipeline_build(tokens, n_tokens, out, out_size,
33295074e1d5SCristian Dumitrescu 				obj);
33305074e1d5SCristian Dumitrescu 			return;
33315074e1d5SCristian Dumitrescu 		}
33325074e1d5SCristian Dumitrescu 
333375129cebSChurchill Khangar 		if ((n_tokens >= 5) &&
333475129cebSChurchill Khangar 			(strcmp(tokens[2], "table") == 0) &&
333575129cebSChurchill Khangar 			(strcmp(tokens[4], "add") == 0)) {
333675129cebSChurchill Khangar 			cmd_pipeline_table_add(tokens, n_tokens, out,
333775129cebSChurchill Khangar 				out_size, obj);
333875129cebSChurchill Khangar 			return;
333975129cebSChurchill Khangar 		}
334075129cebSChurchill Khangar 
334175129cebSChurchill Khangar 		if ((n_tokens >= 5) &&
334275129cebSChurchill Khangar 			(strcmp(tokens[2], "table") == 0) &&
334375129cebSChurchill Khangar 			(strcmp(tokens[4], "delete") == 0)) {
334475129cebSChurchill Khangar 			cmd_pipeline_table_delete(tokens, n_tokens, out,
334575129cebSChurchill Khangar 				out_size, obj);
334675129cebSChurchill Khangar 			return;
334775129cebSChurchill Khangar 		}
334875129cebSChurchill Khangar 
334975129cebSChurchill Khangar 		if ((n_tokens >= 5) &&
335075129cebSChurchill Khangar 			(strcmp(tokens[2], "table") == 0) &&
335175129cebSChurchill Khangar 			(strcmp(tokens[4], "default") == 0)) {
335275129cebSChurchill Khangar 			cmd_pipeline_table_default(tokens, n_tokens, out,
335375129cebSChurchill Khangar 				out_size, obj);
335475129cebSChurchill Khangar 			return;
335575129cebSChurchill Khangar 		}
335675129cebSChurchill Khangar 
335775129cebSChurchill Khangar 		if ((n_tokens >= 5) &&
335875129cebSChurchill Khangar 			(strcmp(tokens[2], "table") == 0) &&
335975129cebSChurchill Khangar 			(strcmp(tokens[4], "show") == 0)) {
336075129cebSChurchill Khangar 			cmd_pipeline_table_show(tokens, n_tokens, out,
336175129cebSChurchill Khangar 				out_size, obj);
336275129cebSChurchill Khangar 			return;
336375129cebSChurchill Khangar 		}
336475129cebSChurchill Khangar 
3365598fe0ddSCristian Dumitrescu 		if ((n_tokens >= 6) &&
3366598fe0ddSCristian Dumitrescu 			(strcmp(tokens[2], "selector") == 0) &&
3367598fe0ddSCristian Dumitrescu 			(strcmp(tokens[4], "group") == 0) &&
3368598fe0ddSCristian Dumitrescu 			(strcmp(tokens[5], "add") == 0)) {
3369598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_add(tokens, n_tokens, out,
3370598fe0ddSCristian Dumitrescu 				out_size, obj);
3371598fe0ddSCristian Dumitrescu 			return;
3372598fe0ddSCristian Dumitrescu 		}
3373598fe0ddSCristian Dumitrescu 
3374598fe0ddSCristian Dumitrescu 		if ((n_tokens >= 6) &&
3375598fe0ddSCristian Dumitrescu 			(strcmp(tokens[2], "selector") == 0) &&
3376598fe0ddSCristian Dumitrescu 			(strcmp(tokens[4], "group") == 0) &&
3377598fe0ddSCristian Dumitrescu 			(strcmp(tokens[5], "delete") == 0)) {
3378598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_delete(tokens, n_tokens, out,
3379598fe0ddSCristian Dumitrescu 				out_size, obj);
3380598fe0ddSCristian Dumitrescu 			return;
3381598fe0ddSCristian Dumitrescu 		}
3382598fe0ddSCristian Dumitrescu 
3383598fe0ddSCristian Dumitrescu 		if ((n_tokens >= 7) &&
3384598fe0ddSCristian Dumitrescu 			(strcmp(tokens[2], "selector") == 0) &&
3385598fe0ddSCristian Dumitrescu 			(strcmp(tokens[4], "group") == 0) &&
3386598fe0ddSCristian Dumitrescu 			(strcmp(tokens[5], "member") == 0) &&
3387598fe0ddSCristian Dumitrescu 			(strcmp(tokens[6], "add") == 0)) {
3388598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_member_add(tokens, n_tokens, out,
3389598fe0ddSCristian Dumitrescu 				out_size, obj);
3390598fe0ddSCristian Dumitrescu 			return;
3391598fe0ddSCristian Dumitrescu 		}
3392598fe0ddSCristian Dumitrescu 
3393598fe0ddSCristian Dumitrescu 		if ((n_tokens >= 7) &&
3394598fe0ddSCristian Dumitrescu 			(strcmp(tokens[2], "selector") == 0) &&
3395598fe0ddSCristian Dumitrescu 			(strcmp(tokens[4], "group") == 0) &&
3396598fe0ddSCristian Dumitrescu 			(strcmp(tokens[5], "member") == 0) &&
3397598fe0ddSCristian Dumitrescu 			(strcmp(tokens[6], "delete") == 0)) {
3398598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_member_delete(tokens, n_tokens, out,
3399598fe0ddSCristian Dumitrescu 				out_size, obj);
3400598fe0ddSCristian Dumitrescu 			return;
3401598fe0ddSCristian Dumitrescu 		}
3402598fe0ddSCristian Dumitrescu 
3403598fe0ddSCristian Dumitrescu 		if ((n_tokens >= 5) &&
3404598fe0ddSCristian Dumitrescu 			(strcmp(tokens[2], "selector") == 0) &&
3405598fe0ddSCristian Dumitrescu 			(strcmp(tokens[4], "show") == 0)) {
3406598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_show(tokens, n_tokens, out,
3407598fe0ddSCristian Dumitrescu 				out_size, obj);
3408598fe0ddSCristian Dumitrescu 			return;
3409598fe0ddSCristian Dumitrescu 		}
3410598fe0ddSCristian Dumitrescu 
34118bd4862fSCristian Dumitrescu 		if ((n_tokens >= 5) &&
34128bd4862fSCristian Dumitrescu 			(strcmp(tokens[2], "learner") == 0) &&
34138bd4862fSCristian Dumitrescu 			(strcmp(tokens[4], "default") == 0)) {
34148bd4862fSCristian Dumitrescu 			cmd_pipeline_learner_default(tokens, n_tokens, out,
34158bd4862fSCristian Dumitrescu 				out_size, obj);
34168bd4862fSCristian Dumitrescu 			return;
34178bd4862fSCristian Dumitrescu 		}
34188bd4862fSCristian Dumitrescu 
34195074e1d5SCristian Dumitrescu 		if ((n_tokens >= 3) &&
342075129cebSChurchill Khangar 			(strcmp(tokens[2], "commit") == 0)) {
342175129cebSChurchill Khangar 			cmd_pipeline_commit(tokens, n_tokens, out,
342275129cebSChurchill Khangar 				out_size, obj);
342375129cebSChurchill Khangar 			return;
342475129cebSChurchill Khangar 		}
342575129cebSChurchill Khangar 
342675129cebSChurchill Khangar 		if ((n_tokens >= 3) &&
342775129cebSChurchill Khangar 			(strcmp(tokens[2], "abort") == 0)) {
342875129cebSChurchill Khangar 			cmd_pipeline_abort(tokens, n_tokens, out,
34295074e1d5SCristian Dumitrescu 				out_size, obj);
34305074e1d5SCristian Dumitrescu 			return;
34315074e1d5SCristian Dumitrescu 		}
34325074e1d5SCristian Dumitrescu 
34335074e1d5SCristian Dumitrescu 		if ((n_tokens >= 3) &&
343464cfcebdSCristian Dumitrescu 			(strcmp(tokens[2], "regrd") == 0)) {
343564cfcebdSCristian Dumitrescu 			cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj);
343664cfcebdSCristian Dumitrescu 			return;
343764cfcebdSCristian Dumitrescu 		}
343864cfcebdSCristian Dumitrescu 
343964cfcebdSCristian Dumitrescu 		if ((n_tokens >= 3) &&
344064cfcebdSCristian Dumitrescu 			(strcmp(tokens[2], "regwr") == 0)) {
344164cfcebdSCristian Dumitrescu 			cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj);
344264cfcebdSCristian Dumitrescu 			return;
344364cfcebdSCristian Dumitrescu 		}
344464cfcebdSCristian Dumitrescu 
3445f38913b7SCristian Dumitrescu 		if ((n_tokens >= 6) &&
3446f38913b7SCristian Dumitrescu 			(strcmp(tokens[2], "meter") == 0) &&
3447f38913b7SCristian Dumitrescu 			(strcmp(tokens[3], "profile") == 0) &&
3448f38913b7SCristian Dumitrescu 			(strcmp(tokens[5], "add") == 0)) {
3449f38913b7SCristian Dumitrescu 			cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj);
3450f38913b7SCristian Dumitrescu 			return;
3451f38913b7SCristian Dumitrescu 		}
3452f38913b7SCristian Dumitrescu 
3453f38913b7SCristian Dumitrescu 		if ((n_tokens >= 6) &&
3454f38913b7SCristian Dumitrescu 			(strcmp(tokens[2], "meter") == 0) &&
3455f38913b7SCristian Dumitrescu 			(strcmp(tokens[3], "profile") == 0) &&
3456f38913b7SCristian Dumitrescu 			(strcmp(tokens[5], "delete") == 0)) {
3457f38913b7SCristian Dumitrescu 			cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj);
3458f38913b7SCristian Dumitrescu 			return;
3459f38913b7SCristian Dumitrescu 		}
3460f38913b7SCristian Dumitrescu 
3461f38913b7SCristian Dumitrescu 		if ((n_tokens >= 9) &&
3462f38913b7SCristian Dumitrescu 			(strcmp(tokens[2], "meter") == 0) &&
3463f38913b7SCristian Dumitrescu 			(strcmp(tokens[8], "reset") == 0)) {
3464f38913b7SCristian Dumitrescu 			cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj);
3465f38913b7SCristian Dumitrescu 			return;
3466f38913b7SCristian Dumitrescu 		}
3467f38913b7SCristian Dumitrescu 
3468f38913b7SCristian Dumitrescu 		if ((n_tokens >= 9) &&
3469f38913b7SCristian Dumitrescu 			(strcmp(tokens[2], "meter") == 0) &&
3470f38913b7SCristian Dumitrescu 			(strcmp(tokens[8], "set") == 0)) {
3471f38913b7SCristian Dumitrescu 			cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj);
3472f38913b7SCristian Dumitrescu 			return;
3473f38913b7SCristian Dumitrescu 		}
3474f38913b7SCristian Dumitrescu 
3475f38913b7SCristian Dumitrescu 		if ((n_tokens >= 9) &&
3476f38913b7SCristian Dumitrescu 			(strcmp(tokens[2], "meter") == 0) &&
3477f38913b7SCristian Dumitrescu 			(strcmp(tokens[8], "stats") == 0)) {
3478f38913b7SCristian Dumitrescu 			cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj);
3479f38913b7SCristian Dumitrescu 			return;
3480f38913b7SCristian Dumitrescu 		}
3481f38913b7SCristian Dumitrescu 
348264cfcebdSCristian Dumitrescu 		if ((n_tokens >= 3) &&
34835074e1d5SCristian Dumitrescu 			(strcmp(tokens[2], "stats") == 0)) {
34845074e1d5SCristian Dumitrescu 			cmd_pipeline_stats(tokens, n_tokens, out, out_size,
34855074e1d5SCristian Dumitrescu 				obj);
34865074e1d5SCristian Dumitrescu 			return;
34875074e1d5SCristian Dumitrescu 		}
348817225455SCristian Dumitrescu 
348917225455SCristian Dumitrescu 		if ((n_tokens >= 4) &&
349017225455SCristian Dumitrescu 			(strcmp(tokens[2], "mirror") == 0) &&
349117225455SCristian Dumitrescu 			(strcmp(tokens[3], "slots") == 0)) {
349217225455SCristian Dumitrescu 			cmd_pipeline_mirror(tokens, n_tokens, out, out_size, obj);
349317225455SCristian Dumitrescu 			return;
349417225455SCristian Dumitrescu 		}
349517225455SCristian Dumitrescu 
349617225455SCristian Dumitrescu 		if ((n_tokens >= 4) &&
349717225455SCristian Dumitrescu 			(strcmp(tokens[2], "mirror") == 0) &&
349817225455SCristian Dumitrescu 			(strcmp(tokens[3], "session") == 0)) {
349917225455SCristian Dumitrescu 			cmd_pipeline_mirror_session(tokens, n_tokens, out, out_size, obj);
350017225455SCristian Dumitrescu 			return;
350117225455SCristian Dumitrescu 		}
35025074e1d5SCristian Dumitrescu 	}
35035074e1d5SCristian Dumitrescu 
35045074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "thread") == 0) {
35055074e1d5SCristian Dumitrescu 		if ((n_tokens >= 5) &&
35065074e1d5SCristian Dumitrescu 			(strcmp(tokens[4], "enable") == 0)) {
35075074e1d5SCristian Dumitrescu 			cmd_thread_pipeline_enable(tokens, n_tokens,
35085074e1d5SCristian Dumitrescu 				out, out_size, obj);
35095074e1d5SCristian Dumitrescu 			return;
35105074e1d5SCristian Dumitrescu 		}
35115074e1d5SCristian Dumitrescu 
35125074e1d5SCristian Dumitrescu 		if ((n_tokens >= 5) &&
35135074e1d5SCristian Dumitrescu 			(strcmp(tokens[4], "disable") == 0)) {
35145074e1d5SCristian Dumitrescu 			cmd_thread_pipeline_disable(tokens, n_tokens,
35155074e1d5SCristian Dumitrescu 				out, out_size, obj);
35165074e1d5SCristian Dumitrescu 			return;
35175074e1d5SCristian Dumitrescu 		}
35185074e1d5SCristian Dumitrescu 	}
35195074e1d5SCristian Dumitrescu 
35205074e1d5SCristian Dumitrescu 	snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
35215074e1d5SCristian Dumitrescu }
35225074e1d5SCristian Dumitrescu 
35235074e1d5SCristian Dumitrescu int
35245074e1d5SCristian Dumitrescu cli_script_process(const char *file_name,
35255074e1d5SCristian Dumitrescu 	size_t msg_in_len_max,
35265074e1d5SCristian Dumitrescu 	size_t msg_out_len_max,
35275074e1d5SCristian Dumitrescu 	void *obj)
35285074e1d5SCristian Dumitrescu {
35295074e1d5SCristian Dumitrescu 	char *msg_in = NULL, *msg_out = NULL;
35305074e1d5SCristian Dumitrescu 	FILE *f = NULL;
35315074e1d5SCristian Dumitrescu 
35325074e1d5SCristian Dumitrescu 	/* Check input arguments */
35335074e1d5SCristian Dumitrescu 	if ((file_name == NULL) ||
35345074e1d5SCristian Dumitrescu 		(strlen(file_name) == 0) ||
35355074e1d5SCristian Dumitrescu 		(msg_in_len_max == 0) ||
35365074e1d5SCristian Dumitrescu 		(msg_out_len_max == 0))
35375074e1d5SCristian Dumitrescu 		return -EINVAL;
35385074e1d5SCristian Dumitrescu 
35395074e1d5SCristian Dumitrescu 	msg_in = malloc(msg_in_len_max + 1);
35405074e1d5SCristian Dumitrescu 	msg_out = malloc(msg_out_len_max + 1);
35415074e1d5SCristian Dumitrescu 	if ((msg_in == NULL) ||
35425074e1d5SCristian Dumitrescu 		(msg_out == NULL)) {
35435074e1d5SCristian Dumitrescu 		free(msg_out);
35445074e1d5SCristian Dumitrescu 		free(msg_in);
35455074e1d5SCristian Dumitrescu 		return -ENOMEM;
35465074e1d5SCristian Dumitrescu 	}
35475074e1d5SCristian Dumitrescu 
35485074e1d5SCristian Dumitrescu 	/* Open input file */
35495074e1d5SCristian Dumitrescu 	f = fopen(file_name, "r");
35505074e1d5SCristian Dumitrescu 	if (f == NULL) {
35515074e1d5SCristian Dumitrescu 		free(msg_out);
35525074e1d5SCristian Dumitrescu 		free(msg_in);
35535074e1d5SCristian Dumitrescu 		return -EIO;
35545074e1d5SCristian Dumitrescu 	}
35555074e1d5SCristian Dumitrescu 
35565074e1d5SCristian Dumitrescu 	/* Read file */
35575074e1d5SCristian Dumitrescu 	for ( ; ; ) {
35585074e1d5SCristian Dumitrescu 		if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
35595074e1d5SCristian Dumitrescu 			break;
35605074e1d5SCristian Dumitrescu 
35615074e1d5SCristian Dumitrescu 		printf("%s", msg_in);
35625074e1d5SCristian Dumitrescu 		msg_out[0] = 0;
35635074e1d5SCristian Dumitrescu 
35645074e1d5SCristian Dumitrescu 		cli_process(msg_in,
35655074e1d5SCristian Dumitrescu 			msg_out,
35665074e1d5SCristian Dumitrescu 			msg_out_len_max,
35675074e1d5SCristian Dumitrescu 			obj);
35685074e1d5SCristian Dumitrescu 
35695074e1d5SCristian Dumitrescu 		if (strlen(msg_out))
35705074e1d5SCristian Dumitrescu 			printf("%s", msg_out);
35715074e1d5SCristian Dumitrescu 	}
35725074e1d5SCristian Dumitrescu 
35735074e1d5SCristian Dumitrescu 	/* Close file */
35745074e1d5SCristian Dumitrescu 	fclose(f);
35755074e1d5SCristian Dumitrescu 	free(msg_out);
35765074e1d5SCristian Dumitrescu 	free(msg_in);
35775074e1d5SCristian Dumitrescu 	return 0;
35785074e1d5SCristian Dumitrescu }
3579