xref: /dpdk/examples/pipeline/cli.c (revision 96b37959fb9aa82807a2018017c41c438c7502b2)
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[] =
134975129cebSChurchill Khangar "pipeline <pipeline_name> table <table_name> show\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;
136075129cebSChurchill Khangar 	int status;
136175129cebSChurchill Khangar 
136275129cebSChurchill Khangar 	if (n_tokens != 5) {
136375129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
136475129cebSChurchill Khangar 		return;
13655074e1d5SCristian Dumitrescu 	}
13665074e1d5SCristian Dumitrescu 
136775129cebSChurchill Khangar 	pipeline_name = tokens[1];
136875129cebSChurchill Khangar 	p = pipeline_find(obj, pipeline_name);
136975129cebSChurchill Khangar 	if (!p || !p->ctl) {
137075129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
137175129cebSChurchill Khangar 		return;
13725074e1d5SCristian Dumitrescu 	}
13735074e1d5SCristian Dumitrescu 
137475129cebSChurchill Khangar 	table_name = tokens[3];
137575129cebSChurchill Khangar 	status = rte_swx_ctl_pipeline_table_fprintf(stdout, p->ctl, table_name);
137675129cebSChurchill Khangar 	if (status)
137775129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_INVALID, "table_name");
13785074e1d5SCristian Dumitrescu }
137975129cebSChurchill Khangar 
1380598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_add_help[] =
1381598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group add\n";
1382598fe0ddSCristian Dumitrescu 
1383598fe0ddSCristian Dumitrescu static void
1384598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_add(char **tokens,
1385598fe0ddSCristian Dumitrescu 	uint32_t n_tokens,
1386598fe0ddSCristian Dumitrescu 	char *out,
1387598fe0ddSCristian Dumitrescu 	size_t out_size,
1388598fe0ddSCristian Dumitrescu 	void *obj)
1389598fe0ddSCristian Dumitrescu {
1390598fe0ddSCristian Dumitrescu 	struct pipeline *p;
1391598fe0ddSCristian Dumitrescu 	char *pipeline_name, *selector_name;
1392598fe0ddSCristian Dumitrescu 	uint32_t group_id;
1393598fe0ddSCristian Dumitrescu 	int status;
1394598fe0ddSCristian Dumitrescu 
1395598fe0ddSCristian Dumitrescu 	if (n_tokens != 6) {
1396598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1397598fe0ddSCristian Dumitrescu 		return;
1398598fe0ddSCristian Dumitrescu 	}
1399598fe0ddSCristian Dumitrescu 
1400598fe0ddSCristian Dumitrescu 	pipeline_name = tokens[1];
1401598fe0ddSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
1402598fe0ddSCristian Dumitrescu 	if (!p || !p->ctl) {
1403598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1404598fe0ddSCristian Dumitrescu 		return;
1405598fe0ddSCristian Dumitrescu 	}
1406598fe0ddSCristian Dumitrescu 
1407598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[2], "selector") != 0) {
1408598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1409598fe0ddSCristian Dumitrescu 		return;
1410598fe0ddSCristian Dumitrescu 	}
1411598fe0ddSCristian Dumitrescu 
1412598fe0ddSCristian Dumitrescu 	selector_name = tokens[3];
1413598fe0ddSCristian Dumitrescu 
1414598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[4], "group") ||
1415598fe0ddSCristian Dumitrescu 		strcmp(tokens[5], "add")) {
1416598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group add");
1417598fe0ddSCristian Dumitrescu 		return;
1418598fe0ddSCristian Dumitrescu 	}
1419598fe0ddSCristian Dumitrescu 
1420598fe0ddSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_selector_group_add(p->ctl,
1421598fe0ddSCristian Dumitrescu 		selector_name,
1422598fe0ddSCristian Dumitrescu 		&group_id);
1423598fe0ddSCristian Dumitrescu 	if (status)
1424598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1425598fe0ddSCristian Dumitrescu 	else
1426598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "Group ID: %u\n", group_id);
1427598fe0ddSCristian Dumitrescu }
1428598fe0ddSCristian Dumitrescu 
1429598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_delete_help[] =
1430598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group delete <group_id>\n";
1431598fe0ddSCristian Dumitrescu 
1432598fe0ddSCristian Dumitrescu static void
1433598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_delete(char **tokens,
1434598fe0ddSCristian Dumitrescu 	uint32_t n_tokens,
1435598fe0ddSCristian Dumitrescu 	char *out,
1436598fe0ddSCristian Dumitrescu 	size_t out_size,
1437598fe0ddSCristian Dumitrescu 	void *obj)
1438598fe0ddSCristian Dumitrescu {
1439598fe0ddSCristian Dumitrescu 	struct pipeline *p;
1440598fe0ddSCristian Dumitrescu 	char *pipeline_name, *selector_name;
1441598fe0ddSCristian Dumitrescu 	uint32_t group_id;
1442598fe0ddSCristian Dumitrescu 	int status;
1443598fe0ddSCristian Dumitrescu 
1444598fe0ddSCristian Dumitrescu 	if (n_tokens != 7) {
1445598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1446598fe0ddSCristian Dumitrescu 		return;
1447598fe0ddSCristian Dumitrescu 	}
1448598fe0ddSCristian Dumitrescu 
1449598fe0ddSCristian Dumitrescu 	pipeline_name = tokens[1];
1450598fe0ddSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
1451598fe0ddSCristian Dumitrescu 	if (!p || !p->ctl) {
1452598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1453598fe0ddSCristian Dumitrescu 		return;
1454598fe0ddSCristian Dumitrescu 	}
1455598fe0ddSCristian Dumitrescu 
1456598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[2], "selector") != 0) {
1457598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1458598fe0ddSCristian Dumitrescu 		return;
1459598fe0ddSCristian Dumitrescu 	}
1460598fe0ddSCristian Dumitrescu 
1461598fe0ddSCristian Dumitrescu 	selector_name = tokens[3];
1462598fe0ddSCristian Dumitrescu 
1463598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[4], "group") ||
1464598fe0ddSCristian Dumitrescu 		strcmp(tokens[5], "delete")) {
1465598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group delete");
1466598fe0ddSCristian Dumitrescu 		return;
1467598fe0ddSCristian Dumitrescu 	}
1468598fe0ddSCristian Dumitrescu 
1469598fe0ddSCristian Dumitrescu 	if (parser_read_uint32(&group_id, tokens[6]) != 0) {
1470598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "group_id");
1471598fe0ddSCristian Dumitrescu 		return;
1472598fe0ddSCristian Dumitrescu 	}
1473598fe0ddSCristian Dumitrescu 
1474598fe0ddSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_selector_group_delete(p->ctl,
1475598fe0ddSCristian Dumitrescu 		selector_name,
1476598fe0ddSCristian Dumitrescu 		group_id);
1477598fe0ddSCristian Dumitrescu 	if (status)
1478598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1479598fe0ddSCristian Dumitrescu }
1480598fe0ddSCristian Dumitrescu 
1481598fe0ddSCristian Dumitrescu #define GROUP_MEMBER_INFO_TOKENS_MAX 6
1482598fe0ddSCristian Dumitrescu 
1483598fe0ddSCristian Dumitrescu static int
1484598fe0ddSCristian Dumitrescu token_is_comment(const char *token)
1485598fe0ddSCristian Dumitrescu {
1486598fe0ddSCristian Dumitrescu 	if ((token[0] == '#') ||
1487598fe0ddSCristian Dumitrescu 	    (token[0] == ';') ||
1488598fe0ddSCristian Dumitrescu 	    ((token[0] == '/') && (token[1] == '/')))
1489598fe0ddSCristian Dumitrescu 		return 1; /* TRUE. */
1490598fe0ddSCristian Dumitrescu 
1491598fe0ddSCristian Dumitrescu 	return 0; /* FALSE. */
1492598fe0ddSCristian Dumitrescu }
1493598fe0ddSCristian Dumitrescu 
1494598fe0ddSCristian Dumitrescu static int
1495598fe0ddSCristian Dumitrescu pipeline_selector_group_member_read(const char *string,
1496598fe0ddSCristian Dumitrescu 				      uint32_t *group_id,
1497598fe0ddSCristian Dumitrescu 				      uint32_t *member_id,
1498598fe0ddSCristian Dumitrescu 				      uint32_t *weight,
1499598fe0ddSCristian Dumitrescu 				      int *is_blank_or_comment)
1500598fe0ddSCristian Dumitrescu {
1501598fe0ddSCristian Dumitrescu 	char *token_array[GROUP_MEMBER_INFO_TOKENS_MAX], **tokens;
1502598fe0ddSCristian Dumitrescu 	char *s0 = NULL, *s;
150300b67591SAli Alnubani 	uint32_t n_tokens = 0, group_id_val = 0, member_id_val = 0, weight_val = 0;
1504598fe0ddSCristian Dumitrescu 	int blank_or_comment = 0;
1505598fe0ddSCristian Dumitrescu 
1506598fe0ddSCristian Dumitrescu 	/* Check input arguments. */
1507598fe0ddSCristian Dumitrescu 	if (!string || !string[0])
1508598fe0ddSCristian Dumitrescu 		goto error;
1509598fe0ddSCristian Dumitrescu 
1510598fe0ddSCristian Dumitrescu 	/* Memory allocation. */
1511598fe0ddSCristian Dumitrescu 	s0 = strdup(string);
1512598fe0ddSCristian Dumitrescu 	if (!s0)
1513598fe0ddSCristian Dumitrescu 		goto error;
1514598fe0ddSCristian Dumitrescu 
1515598fe0ddSCristian Dumitrescu 	/* Parse the string into tokens. */
1516598fe0ddSCristian Dumitrescu 	for (s = s0; ; ) {
1517598fe0ddSCristian Dumitrescu 		char *token;
1518598fe0ddSCristian Dumitrescu 
1519598fe0ddSCristian Dumitrescu 		token = strtok_r(s, " \f\n\r\t\v", &s);
1520598fe0ddSCristian Dumitrescu 		if (!token || token_is_comment(token))
1521598fe0ddSCristian Dumitrescu 			break;
1522598fe0ddSCristian Dumitrescu 
1523cfcc7bf8SCristian Dumitrescu 		if (n_tokens >= GROUP_MEMBER_INFO_TOKENS_MAX)
1524598fe0ddSCristian Dumitrescu 			goto error;
1525598fe0ddSCristian Dumitrescu 
1526598fe0ddSCristian Dumitrescu 		token_array[n_tokens] = token;
1527598fe0ddSCristian Dumitrescu 		n_tokens++;
1528598fe0ddSCristian Dumitrescu 	}
1529598fe0ddSCristian Dumitrescu 
1530598fe0ddSCristian Dumitrescu 	if (!n_tokens) {
1531598fe0ddSCristian Dumitrescu 		blank_or_comment = 1;
1532598fe0ddSCristian Dumitrescu 		goto error;
1533598fe0ddSCristian Dumitrescu 	}
1534598fe0ddSCristian Dumitrescu 
1535598fe0ddSCristian Dumitrescu 	tokens = token_array;
1536598fe0ddSCristian Dumitrescu 
1537598fe0ddSCristian Dumitrescu 	if (n_tokens < 4 ||
1538598fe0ddSCristian Dumitrescu 		strcmp(tokens[0], "group") ||
1539598fe0ddSCristian Dumitrescu 		strcmp(tokens[2], "member"))
1540598fe0ddSCristian Dumitrescu 		goto error;
1541598fe0ddSCristian Dumitrescu 
1542598fe0ddSCristian Dumitrescu 	/*
1543598fe0ddSCristian Dumitrescu 	 * Group ID.
1544598fe0ddSCristian Dumitrescu 	 */
1545598fe0ddSCristian Dumitrescu 	if (parser_read_uint32(&group_id_val, tokens[1]) != 0)
1546598fe0ddSCristian Dumitrescu 		goto error;
1547598fe0ddSCristian Dumitrescu 	*group_id = group_id_val;
1548598fe0ddSCristian Dumitrescu 
1549598fe0ddSCristian Dumitrescu 	/*
1550598fe0ddSCristian Dumitrescu 	 * Member ID.
1551598fe0ddSCristian Dumitrescu 	 */
1552598fe0ddSCristian Dumitrescu 	if (parser_read_uint32(&member_id_val, tokens[3]) != 0)
1553598fe0ddSCristian Dumitrescu 		goto error;
1554598fe0ddSCristian Dumitrescu 	*member_id = member_id_val;
1555598fe0ddSCristian Dumitrescu 
1556598fe0ddSCristian Dumitrescu 	tokens += 4;
1557598fe0ddSCristian Dumitrescu 	n_tokens -= 4;
1558598fe0ddSCristian Dumitrescu 
1559598fe0ddSCristian Dumitrescu 	/*
1560598fe0ddSCristian Dumitrescu 	 * Weight.
1561598fe0ddSCristian Dumitrescu 	 */
1562598fe0ddSCristian Dumitrescu 	if (n_tokens && !strcmp(tokens[0], "weight")) {
1563598fe0ddSCristian Dumitrescu 		if (n_tokens < 2)
1564598fe0ddSCristian Dumitrescu 			goto error;
1565598fe0ddSCristian Dumitrescu 
1566598fe0ddSCristian Dumitrescu 		if (parser_read_uint32(&weight_val, tokens[1]) != 0)
1567598fe0ddSCristian Dumitrescu 			goto error;
1568598fe0ddSCristian Dumitrescu 		*weight = weight_val;
1569598fe0ddSCristian Dumitrescu 
1570598fe0ddSCristian Dumitrescu 		tokens += 2;
1571598fe0ddSCristian Dumitrescu 		n_tokens -= 2;
1572598fe0ddSCristian Dumitrescu 	}
1573598fe0ddSCristian Dumitrescu 
1574598fe0ddSCristian Dumitrescu 	if (n_tokens)
1575598fe0ddSCristian Dumitrescu 		goto error;
1576598fe0ddSCristian Dumitrescu 
1577598fe0ddSCristian Dumitrescu 	free(s0);
1578598fe0ddSCristian Dumitrescu 	return 0;
1579598fe0ddSCristian Dumitrescu 
1580598fe0ddSCristian Dumitrescu error:
1581598fe0ddSCristian Dumitrescu 	free(s0);
1582598fe0ddSCristian Dumitrescu 	if (is_blank_or_comment)
1583598fe0ddSCristian Dumitrescu 		*is_blank_or_comment = blank_or_comment;
1584598fe0ddSCristian Dumitrescu 	return -EINVAL;
1585598fe0ddSCristian Dumitrescu }
1586598fe0ddSCristian Dumitrescu 
1587598fe0ddSCristian Dumitrescu static int
1588598fe0ddSCristian Dumitrescu pipeline_selector_group_members_add(struct rte_swx_ctl_pipeline *p,
1589598fe0ddSCristian Dumitrescu 			   const char *selector_name,
1590598fe0ddSCristian Dumitrescu 			   FILE *file,
1591598fe0ddSCristian Dumitrescu 			   uint32_t *file_line_number)
1592598fe0ddSCristian Dumitrescu {
1593598fe0ddSCristian Dumitrescu 	char *line = NULL;
1594598fe0ddSCristian Dumitrescu 	uint32_t line_id = 0;
1595598fe0ddSCristian Dumitrescu 	int status = 0;
1596598fe0ddSCristian Dumitrescu 
1597598fe0ddSCristian Dumitrescu 	/* Buffer allocation. */
1598598fe0ddSCristian Dumitrescu 	line = malloc(MAX_LINE_SIZE);
1599598fe0ddSCristian Dumitrescu 	if (!line)
1600598fe0ddSCristian Dumitrescu 		return -ENOMEM;
1601598fe0ddSCristian Dumitrescu 
1602598fe0ddSCristian Dumitrescu 	/* File read. */
1603598fe0ddSCristian Dumitrescu 	for (line_id = 1; ; line_id++) {
1604598fe0ddSCristian Dumitrescu 		uint32_t group_id, member_id, weight;
1605598fe0ddSCristian Dumitrescu 		int is_blank_or_comment;
1606598fe0ddSCristian Dumitrescu 
1607598fe0ddSCristian Dumitrescu 		if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1608598fe0ddSCristian Dumitrescu 			break;
1609598fe0ddSCristian Dumitrescu 
1610598fe0ddSCristian Dumitrescu 		status = pipeline_selector_group_member_read(line,
1611598fe0ddSCristian Dumitrescu 							      &group_id,
1612598fe0ddSCristian Dumitrescu 							      &member_id,
1613598fe0ddSCristian Dumitrescu 							      &weight,
1614598fe0ddSCristian Dumitrescu 							      &is_blank_or_comment);
1615598fe0ddSCristian Dumitrescu 		if (status) {
1616598fe0ddSCristian Dumitrescu 			if (is_blank_or_comment)
1617598fe0ddSCristian Dumitrescu 				continue;
1618598fe0ddSCristian Dumitrescu 
1619598fe0ddSCristian Dumitrescu 			goto error;
1620598fe0ddSCristian Dumitrescu 		}
1621598fe0ddSCristian Dumitrescu 
1622598fe0ddSCristian Dumitrescu 		status = rte_swx_ctl_pipeline_selector_group_member_add(p,
1623598fe0ddSCristian Dumitrescu 			selector_name,
1624598fe0ddSCristian Dumitrescu 			group_id,
1625598fe0ddSCristian Dumitrescu 			member_id,
1626598fe0ddSCristian Dumitrescu 			weight);
1627598fe0ddSCristian Dumitrescu 		if (status)
1628598fe0ddSCristian Dumitrescu 			goto error;
1629598fe0ddSCristian Dumitrescu 	}
1630598fe0ddSCristian Dumitrescu 
1631598fe0ddSCristian Dumitrescu error:
1632598fe0ddSCristian Dumitrescu 	free(line);
1633598fe0ddSCristian Dumitrescu 	*file_line_number = line_id;
1634598fe0ddSCristian Dumitrescu 	return status;
1635598fe0ddSCristian Dumitrescu }
1636598fe0ddSCristian Dumitrescu 
1637598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_add_help[] =
1638598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member add <file_name>";
1639598fe0ddSCristian Dumitrescu 
1640598fe0ddSCristian Dumitrescu static void
1641598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_add(char **tokens,
1642598fe0ddSCristian Dumitrescu 	uint32_t n_tokens,
1643598fe0ddSCristian Dumitrescu 	char *out,
1644598fe0ddSCristian Dumitrescu 	size_t out_size,
1645598fe0ddSCristian Dumitrescu 	void *obj)
1646598fe0ddSCristian Dumitrescu {
1647598fe0ddSCristian Dumitrescu 	struct pipeline *p;
1648598fe0ddSCristian Dumitrescu 	char *pipeline_name, *selector_name, *file_name;
1649598fe0ddSCristian Dumitrescu 	FILE *file = NULL;
1650598fe0ddSCristian Dumitrescu 	uint32_t file_line_number = 0;
1651598fe0ddSCristian Dumitrescu 	int status;
1652598fe0ddSCristian Dumitrescu 
1653598fe0ddSCristian Dumitrescu 	if (n_tokens != 8) {
1654598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1655598fe0ddSCristian Dumitrescu 		return;
1656598fe0ddSCristian Dumitrescu 	}
1657598fe0ddSCristian Dumitrescu 
1658598fe0ddSCristian Dumitrescu 	pipeline_name = tokens[1];
1659598fe0ddSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
1660598fe0ddSCristian Dumitrescu 	if (!p || !p->ctl) {
1661598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1662598fe0ddSCristian Dumitrescu 		return;
1663598fe0ddSCristian Dumitrescu 	}
1664598fe0ddSCristian Dumitrescu 
1665598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[2], "selector") != 0) {
1666598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1667598fe0ddSCristian Dumitrescu 		return;
1668598fe0ddSCristian Dumitrescu 	}
1669598fe0ddSCristian Dumitrescu 
1670598fe0ddSCristian Dumitrescu 	selector_name = tokens[3];
1671598fe0ddSCristian Dumitrescu 
1672598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[4], "group") ||
1673598fe0ddSCristian Dumitrescu 		strcmp(tokens[5], "member") ||
1674598fe0ddSCristian Dumitrescu 		strcmp(tokens[6], "add")) {
1675598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member add");
1676598fe0ddSCristian Dumitrescu 		return;
1677598fe0ddSCristian Dumitrescu 	}
1678598fe0ddSCristian Dumitrescu 
1679598fe0ddSCristian Dumitrescu 	file_name = tokens[7];
1680598fe0ddSCristian Dumitrescu 	file = fopen(file_name, "r");
1681598fe0ddSCristian Dumitrescu 	if (!file) {
1682598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1683598fe0ddSCristian Dumitrescu 		return;
1684598fe0ddSCristian Dumitrescu 	}
1685598fe0ddSCristian Dumitrescu 
1686598fe0ddSCristian Dumitrescu 	status = pipeline_selector_group_members_add(p->ctl,
1687598fe0ddSCristian Dumitrescu 					    selector_name,
1688598fe0ddSCristian Dumitrescu 					    file,
1689598fe0ddSCristian Dumitrescu 					    &file_line_number);
1690598fe0ddSCristian Dumitrescu 	if (status)
1691598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1692598fe0ddSCristian Dumitrescu 			 file_name,
1693598fe0ddSCristian Dumitrescu 			 file_line_number);
1694598fe0ddSCristian Dumitrescu 
1695598fe0ddSCristian Dumitrescu 	fclose(file);
1696598fe0ddSCristian Dumitrescu }
1697598fe0ddSCristian Dumitrescu 
1698598fe0ddSCristian Dumitrescu static int
1699598fe0ddSCristian Dumitrescu pipeline_selector_group_members_delete(struct rte_swx_ctl_pipeline *p,
1700598fe0ddSCristian Dumitrescu 			   const char *selector_name,
1701598fe0ddSCristian Dumitrescu 			   FILE *file,
1702598fe0ddSCristian Dumitrescu 			   uint32_t *file_line_number)
1703598fe0ddSCristian Dumitrescu {
1704598fe0ddSCristian Dumitrescu 	char *line = NULL;
1705598fe0ddSCristian Dumitrescu 	uint32_t line_id = 0;
1706598fe0ddSCristian Dumitrescu 	int status = 0;
1707598fe0ddSCristian Dumitrescu 
1708598fe0ddSCristian Dumitrescu 	/* Buffer allocation. */
1709598fe0ddSCristian Dumitrescu 	line = malloc(MAX_LINE_SIZE);
1710598fe0ddSCristian Dumitrescu 	if (!line)
1711598fe0ddSCristian Dumitrescu 		return -ENOMEM;
1712598fe0ddSCristian Dumitrescu 
1713598fe0ddSCristian Dumitrescu 	/* File read. */
1714598fe0ddSCristian Dumitrescu 	for (line_id = 1; ; line_id++) {
1715598fe0ddSCristian Dumitrescu 		uint32_t group_id, member_id, weight;
1716598fe0ddSCristian Dumitrescu 		int is_blank_or_comment;
1717598fe0ddSCristian Dumitrescu 
1718598fe0ddSCristian Dumitrescu 		if (fgets(line, MAX_LINE_SIZE, file) == NULL)
1719598fe0ddSCristian Dumitrescu 			break;
1720598fe0ddSCristian Dumitrescu 
1721598fe0ddSCristian Dumitrescu 		status = pipeline_selector_group_member_read(line,
1722598fe0ddSCristian Dumitrescu 							      &group_id,
1723598fe0ddSCristian Dumitrescu 							      &member_id,
1724598fe0ddSCristian Dumitrescu 							      &weight,
1725598fe0ddSCristian Dumitrescu 							      &is_blank_or_comment);
1726598fe0ddSCristian Dumitrescu 		if (status) {
1727598fe0ddSCristian Dumitrescu 			if (is_blank_or_comment)
1728598fe0ddSCristian Dumitrescu 				continue;
1729598fe0ddSCristian Dumitrescu 
1730598fe0ddSCristian Dumitrescu 			goto error;
1731598fe0ddSCristian Dumitrescu 		}
1732598fe0ddSCristian Dumitrescu 
1733598fe0ddSCristian Dumitrescu 		status = rte_swx_ctl_pipeline_selector_group_member_delete(p,
1734598fe0ddSCristian Dumitrescu 			selector_name,
1735598fe0ddSCristian Dumitrescu 			group_id,
1736598fe0ddSCristian Dumitrescu 			member_id);
1737598fe0ddSCristian Dumitrescu 		if (status)
1738598fe0ddSCristian Dumitrescu 			goto error;
1739598fe0ddSCristian Dumitrescu 	}
1740598fe0ddSCristian Dumitrescu 
1741598fe0ddSCristian Dumitrescu error:
1742598fe0ddSCristian Dumitrescu 	free(line);
1743598fe0ddSCristian Dumitrescu 	*file_line_number = line_id;
1744598fe0ddSCristian Dumitrescu 	return status;
1745598fe0ddSCristian Dumitrescu }
1746598fe0ddSCristian Dumitrescu 
1747598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_group_member_delete_help[] =
1748598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> group member delete <file_name>";
1749598fe0ddSCristian Dumitrescu 
1750598fe0ddSCristian Dumitrescu static void
1751598fe0ddSCristian Dumitrescu cmd_pipeline_selector_group_member_delete(char **tokens,
1752598fe0ddSCristian Dumitrescu 	uint32_t n_tokens,
1753598fe0ddSCristian Dumitrescu 	char *out,
1754598fe0ddSCristian Dumitrescu 	size_t out_size,
1755598fe0ddSCristian Dumitrescu 	void *obj)
1756598fe0ddSCristian Dumitrescu {
1757598fe0ddSCristian Dumitrescu 	struct pipeline *p;
1758598fe0ddSCristian Dumitrescu 	char *pipeline_name, *selector_name, *file_name;
1759598fe0ddSCristian Dumitrescu 	FILE *file = NULL;
1760598fe0ddSCristian Dumitrescu 	uint32_t file_line_number = 0;
1761598fe0ddSCristian Dumitrescu 	int status;
1762598fe0ddSCristian Dumitrescu 
1763598fe0ddSCristian Dumitrescu 	if (n_tokens != 8) {
1764598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1765598fe0ddSCristian Dumitrescu 		return;
1766598fe0ddSCristian Dumitrescu 	}
1767598fe0ddSCristian Dumitrescu 
1768598fe0ddSCristian Dumitrescu 	pipeline_name = tokens[1];
1769598fe0ddSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
1770598fe0ddSCristian Dumitrescu 	if (!p || !p->ctl) {
1771598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1772598fe0ddSCristian Dumitrescu 		return;
1773598fe0ddSCristian Dumitrescu 	}
1774598fe0ddSCristian Dumitrescu 
1775598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[2], "selector") != 0) {
1776598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "selector");
1777598fe0ddSCristian Dumitrescu 		return;
1778598fe0ddSCristian Dumitrescu 	}
1779598fe0ddSCristian Dumitrescu 
1780598fe0ddSCristian Dumitrescu 	selector_name = tokens[3];
1781598fe0ddSCristian Dumitrescu 
1782598fe0ddSCristian Dumitrescu 	if (strcmp(tokens[4], "group") ||
1783598fe0ddSCristian Dumitrescu 		strcmp(tokens[5], "member") ||
1784598fe0ddSCristian Dumitrescu 		strcmp(tokens[6], "delete")) {
1785598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "group member delete");
1786598fe0ddSCristian Dumitrescu 		return;
1787598fe0ddSCristian Dumitrescu 	}
1788598fe0ddSCristian Dumitrescu 
1789598fe0ddSCristian Dumitrescu 	file_name = tokens[7];
1790598fe0ddSCristian Dumitrescu 	file = fopen(file_name, "r");
1791598fe0ddSCristian Dumitrescu 	if (!file) {
1792598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "Cannot open file %s.\n", file_name);
1793598fe0ddSCristian Dumitrescu 		return;
1794598fe0ddSCristian Dumitrescu 	}
1795598fe0ddSCristian Dumitrescu 
1796598fe0ddSCristian Dumitrescu 	status = pipeline_selector_group_members_delete(p->ctl,
1797598fe0ddSCristian Dumitrescu 					    selector_name,
1798598fe0ddSCristian Dumitrescu 					    file,
1799598fe0ddSCristian Dumitrescu 					    &file_line_number);
1800598fe0ddSCristian Dumitrescu 	if (status)
1801598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
1802598fe0ddSCristian Dumitrescu 			 file_name,
1803598fe0ddSCristian Dumitrescu 			 file_line_number);
1804598fe0ddSCristian Dumitrescu 
1805598fe0ddSCristian Dumitrescu 	fclose(file);
1806598fe0ddSCristian Dumitrescu }
1807598fe0ddSCristian Dumitrescu 
1808598fe0ddSCristian Dumitrescu static const char cmd_pipeline_selector_show_help[] =
1809598fe0ddSCristian Dumitrescu "pipeline <pipeline_name> selector <selector_name> show\n";
1810598fe0ddSCristian Dumitrescu 
1811598fe0ddSCristian Dumitrescu static void
1812598fe0ddSCristian Dumitrescu cmd_pipeline_selector_show(char **tokens,
1813598fe0ddSCristian Dumitrescu 	uint32_t n_tokens,
1814598fe0ddSCristian Dumitrescu 	char *out,
1815598fe0ddSCristian Dumitrescu 	size_t out_size,
1816598fe0ddSCristian Dumitrescu 	void *obj)
1817598fe0ddSCristian Dumitrescu {
1818598fe0ddSCristian Dumitrescu 	struct pipeline *p;
1819598fe0ddSCristian Dumitrescu 	char *pipeline_name, *selector_name;
1820598fe0ddSCristian Dumitrescu 	int status;
1821598fe0ddSCristian Dumitrescu 
1822598fe0ddSCristian Dumitrescu 	if (n_tokens != 5) {
1823598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1824598fe0ddSCristian Dumitrescu 		return;
1825598fe0ddSCristian Dumitrescu 	}
1826598fe0ddSCristian Dumitrescu 
1827598fe0ddSCristian Dumitrescu 	pipeline_name = tokens[1];
1828598fe0ddSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
1829598fe0ddSCristian Dumitrescu 	if (!p || !p->ctl) {
1830598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
1831598fe0ddSCristian Dumitrescu 		return;
1832598fe0ddSCristian Dumitrescu 	}
1833598fe0ddSCristian Dumitrescu 
1834598fe0ddSCristian Dumitrescu 	selector_name = tokens[3];
1835598fe0ddSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_selector_fprintf(stdout,
1836598fe0ddSCristian Dumitrescu 		p->ctl, selector_name);
1837598fe0ddSCristian Dumitrescu 	if (status)
1838598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "selector_name");
1839598fe0ddSCristian Dumitrescu }
1840598fe0ddSCristian Dumitrescu 
18418bd4862fSCristian Dumitrescu static int
18428bd4862fSCristian Dumitrescu pipeline_learner_default_entry_add(struct rte_swx_ctl_pipeline *p,
18438bd4862fSCristian Dumitrescu 				   const char *learner_name,
18448bd4862fSCristian Dumitrescu 				   FILE *file,
18458bd4862fSCristian Dumitrescu 				   uint32_t *file_line_number)
18468bd4862fSCristian Dumitrescu {
18478bd4862fSCristian Dumitrescu 	char *line = NULL;
18488bd4862fSCristian Dumitrescu 	uint32_t line_id = 0;
18498bd4862fSCristian Dumitrescu 	int status = 0;
18508bd4862fSCristian Dumitrescu 
18518bd4862fSCristian Dumitrescu 	/* Buffer allocation. */
18528bd4862fSCristian Dumitrescu 	line = malloc(MAX_LINE_SIZE);
18538bd4862fSCristian Dumitrescu 	if (!line)
18548bd4862fSCristian Dumitrescu 		return -ENOMEM;
18558bd4862fSCristian Dumitrescu 
18568bd4862fSCristian Dumitrescu 	/* File read. */
18578bd4862fSCristian Dumitrescu 	for (line_id = 1; ; line_id++) {
18588bd4862fSCristian Dumitrescu 		struct rte_swx_table_entry *entry;
18598bd4862fSCristian Dumitrescu 		int is_blank_or_comment;
18608bd4862fSCristian Dumitrescu 
18618bd4862fSCristian Dumitrescu 		if (fgets(line, MAX_LINE_SIZE, file) == NULL)
18628bd4862fSCristian Dumitrescu 			break;
18638bd4862fSCristian Dumitrescu 
18648bd4862fSCristian Dumitrescu 		entry = rte_swx_ctl_pipeline_learner_default_entry_read(p,
18658bd4862fSCristian Dumitrescu 									learner_name,
18668bd4862fSCristian Dumitrescu 									line,
18678bd4862fSCristian Dumitrescu 									&is_blank_or_comment);
18688bd4862fSCristian Dumitrescu 		if (!entry) {
18698bd4862fSCristian Dumitrescu 			if (is_blank_or_comment)
18708bd4862fSCristian Dumitrescu 				continue;
18718bd4862fSCristian Dumitrescu 
18728bd4862fSCristian Dumitrescu 			status = -EINVAL;
18738bd4862fSCristian Dumitrescu 			goto error;
18748bd4862fSCristian Dumitrescu 		}
18758bd4862fSCristian Dumitrescu 
18768bd4862fSCristian Dumitrescu 		status = rte_swx_ctl_pipeline_learner_default_entry_add(p,
18778bd4862fSCristian Dumitrescu 									learner_name,
18788bd4862fSCristian Dumitrescu 									entry);
18798bd4862fSCristian Dumitrescu 		table_entry_free(entry);
18808bd4862fSCristian Dumitrescu 		if (status)
18818bd4862fSCristian Dumitrescu 			goto error;
18828bd4862fSCristian Dumitrescu 	}
18838bd4862fSCristian Dumitrescu 
18848bd4862fSCristian Dumitrescu error:
18858bd4862fSCristian Dumitrescu 	*file_line_number = line_id;
18868bd4862fSCristian Dumitrescu 	free(line);
18878bd4862fSCristian Dumitrescu 	return status;
18888bd4862fSCristian Dumitrescu }
18898bd4862fSCristian Dumitrescu 
18908bd4862fSCristian Dumitrescu static const char cmd_pipeline_learner_default_help[] =
18918bd4862fSCristian Dumitrescu "pipeline <pipeline_name> learner <learner_name> default <file_name>\n";
18928bd4862fSCristian Dumitrescu 
18938bd4862fSCristian Dumitrescu static void
18948bd4862fSCristian Dumitrescu cmd_pipeline_learner_default(char **tokens,
18958bd4862fSCristian Dumitrescu 			     uint32_t n_tokens,
18968bd4862fSCristian Dumitrescu 			     char *out,
18978bd4862fSCristian Dumitrescu 			     size_t out_size,
18988bd4862fSCristian Dumitrescu 			     void *obj)
18998bd4862fSCristian Dumitrescu {
19008bd4862fSCristian Dumitrescu 	struct pipeline *p;
19018bd4862fSCristian Dumitrescu 	char *pipeline_name, *learner_name, *file_name;
19028bd4862fSCristian Dumitrescu 	FILE *file = NULL;
19038bd4862fSCristian Dumitrescu 	uint32_t file_line_number = 0;
19048bd4862fSCristian Dumitrescu 	int status;
19058bd4862fSCristian Dumitrescu 
19068bd4862fSCristian Dumitrescu 	if (n_tokens != 6) {
19078bd4862fSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
19088bd4862fSCristian Dumitrescu 		return;
19098bd4862fSCristian Dumitrescu 	}
19108bd4862fSCristian Dumitrescu 
19118bd4862fSCristian Dumitrescu 	pipeline_name = tokens[1];
19128bd4862fSCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
19138bd4862fSCristian Dumitrescu 	if (!p || !p->ctl) {
19148bd4862fSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
19158bd4862fSCristian Dumitrescu 		return;
19168bd4862fSCristian Dumitrescu 	}
19178bd4862fSCristian Dumitrescu 
19188bd4862fSCristian Dumitrescu 	learner_name = tokens[3];
19198bd4862fSCristian Dumitrescu 
19208bd4862fSCristian Dumitrescu 	file_name = tokens[5];
19218bd4862fSCristian Dumitrescu 	file = fopen(file_name, "r");
19228bd4862fSCristian Dumitrescu 	if (!file) {
19238bd4862fSCristian Dumitrescu 		snprintf(out, out_size, "Cannot open file %s.\n", file_name);
19248bd4862fSCristian Dumitrescu 		return;
19258bd4862fSCristian Dumitrescu 	}
19268bd4862fSCristian Dumitrescu 
19278bd4862fSCristian Dumitrescu 	status = pipeline_learner_default_entry_add(p->ctl,
19288bd4862fSCristian Dumitrescu 						    learner_name,
19298bd4862fSCristian Dumitrescu 						    file,
19308bd4862fSCristian Dumitrescu 						    &file_line_number);
19318bd4862fSCristian Dumitrescu 	if (status)
19328bd4862fSCristian Dumitrescu 		snprintf(out, out_size, "Invalid entry in file %s at line %u\n",
19338bd4862fSCristian Dumitrescu 			 file_name,
19348bd4862fSCristian Dumitrescu 			 file_line_number);
19358bd4862fSCristian Dumitrescu 
19368bd4862fSCristian Dumitrescu 	fclose(file);
19378bd4862fSCristian Dumitrescu }
19388bd4862fSCristian Dumitrescu 
193975129cebSChurchill Khangar static const char cmd_pipeline_commit_help[] =
194075129cebSChurchill Khangar "pipeline <pipeline_name> commit\n";
194175129cebSChurchill Khangar 
194275129cebSChurchill Khangar static void
194375129cebSChurchill Khangar cmd_pipeline_commit(char **tokens,
194475129cebSChurchill Khangar 	uint32_t n_tokens,
194575129cebSChurchill Khangar 	char *out,
194675129cebSChurchill Khangar 	size_t out_size,
194775129cebSChurchill Khangar 	void *obj)
194875129cebSChurchill Khangar {
194975129cebSChurchill Khangar 	struct pipeline *p;
195075129cebSChurchill Khangar 	char *pipeline_name;
195175129cebSChurchill Khangar 	int status;
195275129cebSChurchill Khangar 
195375129cebSChurchill Khangar 	if (n_tokens != 3) {
195475129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
195575129cebSChurchill Khangar 		return;
195675129cebSChurchill Khangar 	}
195775129cebSChurchill Khangar 
195875129cebSChurchill Khangar 	pipeline_name = tokens[1];
195975129cebSChurchill Khangar 	p = pipeline_find(obj, pipeline_name);
196075129cebSChurchill Khangar 	if (!p || !p->ctl) {
196175129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
196275129cebSChurchill Khangar 		return;
19635074e1d5SCristian Dumitrescu 	}
19645074e1d5SCristian Dumitrescu 
19655074e1d5SCristian Dumitrescu 	status = rte_swx_ctl_pipeline_commit(p->ctl, 1);
196675129cebSChurchill Khangar 	if (status)
196775129cebSChurchill Khangar 		snprintf(out, out_size, "Commit failed. "
196875129cebSChurchill Khangar 			"Use \"commit\" to retry or \"abort\" to discard the pending work.\n");
19695074e1d5SCristian Dumitrescu }
19705074e1d5SCristian Dumitrescu 
197175129cebSChurchill Khangar static const char cmd_pipeline_abort_help[] =
197275129cebSChurchill Khangar "pipeline <pipeline_name> abort\n";
19735074e1d5SCristian Dumitrescu 
197475129cebSChurchill Khangar static void
197575129cebSChurchill Khangar cmd_pipeline_abort(char **tokens,
197675129cebSChurchill Khangar 	uint32_t n_tokens,
197775129cebSChurchill Khangar 	char *out,
197875129cebSChurchill Khangar 	size_t out_size,
197975129cebSChurchill Khangar 	void *obj)
198075129cebSChurchill Khangar {
198175129cebSChurchill Khangar 	struct pipeline *p;
198275129cebSChurchill Khangar 	char *pipeline_name;
19835074e1d5SCristian Dumitrescu 
198475129cebSChurchill Khangar 	if (n_tokens != 3) {
198575129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
19865074e1d5SCristian Dumitrescu 		return;
198775129cebSChurchill Khangar 	}
19885074e1d5SCristian Dumitrescu 
198975129cebSChurchill Khangar 	pipeline_name = tokens[1];
199075129cebSChurchill Khangar 	p = pipeline_find(obj, pipeline_name);
199175129cebSChurchill Khangar 	if (!p || !p->ctl) {
199275129cebSChurchill Khangar 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
199375129cebSChurchill Khangar 		return;
199475129cebSChurchill Khangar 	}
199575129cebSChurchill Khangar 
19965074e1d5SCristian Dumitrescu 	rte_swx_ctl_pipeline_abort(p->ctl);
19975074e1d5SCristian Dumitrescu }
19985074e1d5SCristian Dumitrescu 
199964cfcebdSCristian Dumitrescu static const char cmd_pipeline_regrd_help[] =
200064cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regrd <register_array_name> <index>\n";
200164cfcebdSCristian Dumitrescu 
200264cfcebdSCristian Dumitrescu static void
200364cfcebdSCristian Dumitrescu cmd_pipeline_regrd(char **tokens,
200464cfcebdSCristian Dumitrescu 	uint32_t n_tokens,
200564cfcebdSCristian Dumitrescu 	char *out,
200664cfcebdSCristian Dumitrescu 	size_t out_size,
200764cfcebdSCristian Dumitrescu 	void *obj)
200864cfcebdSCristian Dumitrescu {
200964cfcebdSCristian Dumitrescu 	struct pipeline *p;
201064cfcebdSCristian Dumitrescu 	const char *name;
201164cfcebdSCristian Dumitrescu 	uint64_t value;
201264cfcebdSCristian Dumitrescu 	uint32_t idx;
201364cfcebdSCristian Dumitrescu 	int status;
201464cfcebdSCristian Dumitrescu 
201564cfcebdSCristian Dumitrescu 	if (n_tokens != 5) {
201664cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
201764cfcebdSCristian Dumitrescu 		return;
201864cfcebdSCristian Dumitrescu 	}
201964cfcebdSCristian Dumitrescu 
202064cfcebdSCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
202164cfcebdSCristian Dumitrescu 	if (!p || !p->ctl) {
202264cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
202364cfcebdSCristian Dumitrescu 		return;
202464cfcebdSCristian Dumitrescu 	}
202564cfcebdSCristian Dumitrescu 
202664cfcebdSCristian Dumitrescu 	if (strcmp(tokens[2], "regrd")) {
202764cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regrd");
202864cfcebdSCristian Dumitrescu 		return;
202964cfcebdSCristian Dumitrescu 	}
203064cfcebdSCristian Dumitrescu 
203164cfcebdSCristian Dumitrescu 	name = tokens[3];
203264cfcebdSCristian Dumitrescu 
203364cfcebdSCristian Dumitrescu 	if (parser_read_uint32(&idx, tokens[4])) {
203464cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index");
203564cfcebdSCristian Dumitrescu 		return;
203664cfcebdSCristian Dumitrescu 	}
203764cfcebdSCristian Dumitrescu 
203864cfcebdSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_regarray_read(p->p, name, idx, &value);
203964cfcebdSCristian Dumitrescu 	if (status) {
204064cfcebdSCristian Dumitrescu 		snprintf(out, out_size, "Command failed.\n");
204164cfcebdSCristian Dumitrescu 		return;
204264cfcebdSCristian Dumitrescu 	}
204364cfcebdSCristian Dumitrescu 
204464cfcebdSCristian Dumitrescu 	snprintf(out, out_size, "0x%" PRIx64 "\n", value);
204564cfcebdSCristian Dumitrescu }
204664cfcebdSCristian Dumitrescu 
204764cfcebdSCristian Dumitrescu static const char cmd_pipeline_regwr_help[] =
204864cfcebdSCristian Dumitrescu "pipeline <pipeline_name> regwr <register_array_name> <index> <value>\n";
204964cfcebdSCristian Dumitrescu 
205064cfcebdSCristian Dumitrescu static void
205164cfcebdSCristian Dumitrescu cmd_pipeline_regwr(char **tokens,
205264cfcebdSCristian Dumitrescu 	uint32_t n_tokens,
205364cfcebdSCristian Dumitrescu 	char *out,
205464cfcebdSCristian Dumitrescu 	size_t out_size,
205564cfcebdSCristian Dumitrescu 	void *obj)
205664cfcebdSCristian Dumitrescu {
205764cfcebdSCristian Dumitrescu 	struct pipeline *p;
205864cfcebdSCristian Dumitrescu 	const char *name;
205964cfcebdSCristian Dumitrescu 	uint64_t value;
206064cfcebdSCristian Dumitrescu 	uint32_t idx;
206164cfcebdSCristian Dumitrescu 	int status;
206264cfcebdSCristian Dumitrescu 
206364cfcebdSCristian Dumitrescu 	if (n_tokens != 6) {
206464cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
206564cfcebdSCristian Dumitrescu 		return;
206664cfcebdSCristian Dumitrescu 	}
206764cfcebdSCristian Dumitrescu 
206864cfcebdSCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
206964cfcebdSCristian Dumitrescu 	if (!p || !p->ctl) {
207064cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
207164cfcebdSCristian Dumitrescu 		return;
207264cfcebdSCristian Dumitrescu 	}
207364cfcebdSCristian Dumitrescu 
207464cfcebdSCristian Dumitrescu 	if (strcmp(tokens[2], "regwr")) {
207564cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "regwr");
207664cfcebdSCristian Dumitrescu 		return;
207764cfcebdSCristian Dumitrescu 	}
207864cfcebdSCristian Dumitrescu 
207964cfcebdSCristian Dumitrescu 	name = tokens[3];
208064cfcebdSCristian Dumitrescu 
208164cfcebdSCristian Dumitrescu 	if (parser_read_uint32(&idx, tokens[4])) {
208264cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index");
208364cfcebdSCristian Dumitrescu 		return;
208464cfcebdSCristian Dumitrescu 	}
208564cfcebdSCristian Dumitrescu 
208664cfcebdSCristian Dumitrescu 	if (parser_read_uint64(&value, tokens[5])) {
208764cfcebdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "value");
208864cfcebdSCristian Dumitrescu 		return;
208964cfcebdSCristian Dumitrescu 	}
209064cfcebdSCristian Dumitrescu 
209164cfcebdSCristian Dumitrescu 	status = rte_swx_ctl_pipeline_regarray_write(p->p, name, idx, value);
209264cfcebdSCristian Dumitrescu 	if (status) {
209364cfcebdSCristian Dumitrescu 		snprintf(out, out_size, "Command failed.\n");
209464cfcebdSCristian Dumitrescu 		return;
209564cfcebdSCristian Dumitrescu 	}
209664cfcebdSCristian Dumitrescu }
209764cfcebdSCristian Dumitrescu 
2098f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_add_help[] =
2099f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> add "
2100f38913b7SCristian Dumitrescu 	"cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
2101f38913b7SCristian Dumitrescu 
2102f38913b7SCristian Dumitrescu static void
2103f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_add(char **tokens,
2104f38913b7SCristian Dumitrescu 	uint32_t n_tokens,
2105f38913b7SCristian Dumitrescu 	char *out,
2106f38913b7SCristian Dumitrescu 	size_t out_size,
2107f38913b7SCristian Dumitrescu 	void *obj)
2108f38913b7SCristian Dumitrescu {
2109f38913b7SCristian Dumitrescu 	struct rte_meter_trtcm_params params;
2110f38913b7SCristian Dumitrescu 	struct pipeline *p;
2111f38913b7SCristian Dumitrescu 	const char *profile_name;
2112f38913b7SCristian Dumitrescu 	int status;
2113f38913b7SCristian Dumitrescu 
2114f38913b7SCristian Dumitrescu 	if (n_tokens != 14) {
2115f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2116f38913b7SCristian Dumitrescu 		return;
2117f38913b7SCristian Dumitrescu 	}
2118f38913b7SCristian Dumitrescu 
2119f38913b7SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
2120f38913b7SCristian Dumitrescu 	if (!p || !p->ctl) {
2121f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2122f38913b7SCristian Dumitrescu 		return;
2123f38913b7SCristian Dumitrescu 	}
2124f38913b7SCristian Dumitrescu 
2125f38913b7SCristian Dumitrescu 	if (strcmp(tokens[2], "meter")) {
2126f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2127f38913b7SCristian Dumitrescu 		return;
2128f38913b7SCristian Dumitrescu 	}
2129f38913b7SCristian Dumitrescu 
2130f38913b7SCristian Dumitrescu 	if (strcmp(tokens[3], "profile")) {
2131f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2132f38913b7SCristian Dumitrescu 		return;
2133f38913b7SCristian Dumitrescu 	}
2134f38913b7SCristian Dumitrescu 
2135f38913b7SCristian Dumitrescu 	profile_name = tokens[4];
2136f38913b7SCristian Dumitrescu 
2137f38913b7SCristian Dumitrescu 	if (strcmp(tokens[5], "add")) {
2138f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
2139f38913b7SCristian Dumitrescu 		return;
2140f38913b7SCristian Dumitrescu 	}
2141f38913b7SCristian Dumitrescu 
2142f38913b7SCristian Dumitrescu 	if (strcmp(tokens[6], "cir")) {
2143f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
2144f38913b7SCristian Dumitrescu 		return;
2145f38913b7SCristian Dumitrescu 	}
2146f38913b7SCristian Dumitrescu 
2147f38913b7SCristian Dumitrescu 	if (parser_read_uint64(&params.cir, tokens[7])) {
2148f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "cir");
2149f38913b7SCristian Dumitrescu 		return;
2150f38913b7SCristian Dumitrescu 	}
2151f38913b7SCristian Dumitrescu 
2152f38913b7SCristian Dumitrescu 	if (strcmp(tokens[8], "pir")) {
2153f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
2154f38913b7SCristian Dumitrescu 		return;
2155f38913b7SCristian Dumitrescu 	}
2156f38913b7SCristian Dumitrescu 
2157f38913b7SCristian Dumitrescu 	if (parser_read_uint64(&params.pir, tokens[9])) {
2158f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pir");
2159f38913b7SCristian Dumitrescu 		return;
2160f38913b7SCristian Dumitrescu 	}
2161f38913b7SCristian Dumitrescu 
2162f38913b7SCristian Dumitrescu 	if (strcmp(tokens[10], "cbs")) {
2163f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
2164f38913b7SCristian Dumitrescu 		return;
2165f38913b7SCristian Dumitrescu 	}
2166f38913b7SCristian Dumitrescu 
2167f38913b7SCristian Dumitrescu 	if (parser_read_uint64(&params.cbs, tokens[11])) {
2168f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
2169f38913b7SCristian Dumitrescu 		return;
2170f38913b7SCristian Dumitrescu 	}
2171f38913b7SCristian Dumitrescu 
2172f38913b7SCristian Dumitrescu 	if (strcmp(tokens[12], "pbs")) {
2173f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
2174f38913b7SCristian Dumitrescu 		return;
2175f38913b7SCristian Dumitrescu 	}
2176f38913b7SCristian Dumitrescu 
2177f38913b7SCristian Dumitrescu 	if (parser_read_uint64(&params.pbs, tokens[13])) {
2178f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
2179f38913b7SCristian Dumitrescu 		return;
2180f38913b7SCristian Dumitrescu 	}
2181f38913b7SCristian Dumitrescu 
2182f38913b7SCristian Dumitrescu 	status = rte_swx_ctl_meter_profile_add(p->p, profile_name, &params);
2183f38913b7SCristian Dumitrescu 	if (status) {
2184f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "Command failed.\n");
2185f38913b7SCristian Dumitrescu 		return;
2186f38913b7SCristian Dumitrescu 	}
2187f38913b7SCristian Dumitrescu }
2188f38913b7SCristian Dumitrescu 
2189f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_profile_delete_help[] =
2190f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter profile <profile_name> delete\n";
2191f38913b7SCristian Dumitrescu 
2192f38913b7SCristian Dumitrescu static void
2193f38913b7SCristian Dumitrescu cmd_pipeline_meter_profile_delete(char **tokens,
2194f38913b7SCristian Dumitrescu 	uint32_t n_tokens,
2195f38913b7SCristian Dumitrescu 	char *out,
2196f38913b7SCristian Dumitrescu 	size_t out_size,
2197f38913b7SCristian Dumitrescu 	void *obj)
2198f38913b7SCristian Dumitrescu {
2199f38913b7SCristian Dumitrescu 	struct pipeline *p;
2200f38913b7SCristian Dumitrescu 	const char *profile_name;
2201f38913b7SCristian Dumitrescu 	int status;
2202f38913b7SCristian Dumitrescu 
2203f38913b7SCristian Dumitrescu 	if (n_tokens != 6) {
2204f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2205f38913b7SCristian Dumitrescu 		return;
2206f38913b7SCristian Dumitrescu 	}
2207f38913b7SCristian Dumitrescu 
2208f38913b7SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
2209f38913b7SCristian Dumitrescu 	if (!p || !p->ctl) {
2210f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2211f38913b7SCristian Dumitrescu 		return;
2212f38913b7SCristian Dumitrescu 	}
2213f38913b7SCristian Dumitrescu 
2214f38913b7SCristian Dumitrescu 	if (strcmp(tokens[2], "meter")) {
2215f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2216f38913b7SCristian Dumitrescu 		return;
2217f38913b7SCristian Dumitrescu 	}
2218f38913b7SCristian Dumitrescu 
2219f38913b7SCristian Dumitrescu 	if (strcmp(tokens[3], "profile")) {
2220f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2221f38913b7SCristian Dumitrescu 		return;
2222f38913b7SCristian Dumitrescu 	}
2223f38913b7SCristian Dumitrescu 
2224f38913b7SCristian Dumitrescu 	profile_name = tokens[4];
2225f38913b7SCristian Dumitrescu 
2226f38913b7SCristian Dumitrescu 	if (strcmp(tokens[5], "delete")) {
2227f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
2228f38913b7SCristian Dumitrescu 		return;
2229f38913b7SCristian Dumitrescu 	}
2230f38913b7SCristian Dumitrescu 
2231f38913b7SCristian Dumitrescu 	status = rte_swx_ctl_meter_profile_delete(p->p, profile_name);
2232f38913b7SCristian Dumitrescu 	if (status) {
2233f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "Command failed.\n");
2234f38913b7SCristian Dumitrescu 		return;
2235f38913b7SCristian Dumitrescu 	}
2236f38913b7SCristian Dumitrescu }
2237f38913b7SCristian Dumitrescu 
2238f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_reset_help[] =
2239f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2240f38913b7SCristian Dumitrescu 	"reset\n";
2241f38913b7SCristian Dumitrescu 
2242f38913b7SCristian Dumitrescu static void
2243f38913b7SCristian Dumitrescu cmd_pipeline_meter_reset(char **tokens,
2244f38913b7SCristian Dumitrescu 	uint32_t n_tokens,
2245f38913b7SCristian Dumitrescu 	char *out,
2246f38913b7SCristian Dumitrescu 	size_t out_size,
2247f38913b7SCristian Dumitrescu 	void *obj)
2248f38913b7SCristian Dumitrescu {
2249f38913b7SCristian Dumitrescu 	struct pipeline *p;
2250f38913b7SCristian Dumitrescu 	const char *name;
225100b67591SAli Alnubani 	uint32_t idx0 = 0, idx1 = 0;
2252f38913b7SCristian Dumitrescu 
2253f38913b7SCristian Dumitrescu 	if (n_tokens != 9) {
2254f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2255f38913b7SCristian Dumitrescu 		return;
2256f38913b7SCristian Dumitrescu 	}
2257f38913b7SCristian Dumitrescu 
2258f38913b7SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
2259f38913b7SCristian Dumitrescu 	if (!p || !p->ctl) {
2260f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2261f38913b7SCristian Dumitrescu 		return;
2262f38913b7SCristian Dumitrescu 	}
2263f38913b7SCristian Dumitrescu 
2264f38913b7SCristian Dumitrescu 	if (strcmp(tokens[2], "meter")) {
2265f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2266f38913b7SCristian Dumitrescu 		return;
2267f38913b7SCristian Dumitrescu 	}
2268f38913b7SCristian Dumitrescu 
2269f38913b7SCristian Dumitrescu 	name = tokens[3];
2270f38913b7SCristian Dumitrescu 
2271f38913b7SCristian Dumitrescu 	if (strcmp(tokens[4], "from")) {
2272f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2273f38913b7SCristian Dumitrescu 		return;
2274f38913b7SCristian Dumitrescu 	}
2275f38913b7SCristian Dumitrescu 
2276f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx0, tokens[5])) {
2277f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2278f38913b7SCristian Dumitrescu 		return;
2279f38913b7SCristian Dumitrescu 	}
2280f38913b7SCristian Dumitrescu 
2281f38913b7SCristian Dumitrescu 	if (strcmp(tokens[6], "to")) {
2282f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2283f38913b7SCristian Dumitrescu 		return;
2284f38913b7SCristian Dumitrescu 	}
2285f38913b7SCristian Dumitrescu 
2286f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2287f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2288f38913b7SCristian Dumitrescu 		return;
2289f38913b7SCristian Dumitrescu 	}
2290f38913b7SCristian Dumitrescu 
2291f38913b7SCristian Dumitrescu 	if (strcmp(tokens[8], "reset")) {
2292f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "reset");
2293f38913b7SCristian Dumitrescu 		return;
2294f38913b7SCristian Dumitrescu 	}
2295f38913b7SCristian Dumitrescu 
2296f38913b7SCristian Dumitrescu 	for ( ; idx0 <= idx1; idx0++) {
2297f38913b7SCristian Dumitrescu 		int status;
2298f38913b7SCristian Dumitrescu 
2299f38913b7SCristian Dumitrescu 		status = rte_swx_ctl_meter_reset(p->p, name, idx0);
2300f38913b7SCristian Dumitrescu 		if (status) {
2301f38913b7SCristian Dumitrescu 			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
2302f38913b7SCristian Dumitrescu 			return;
2303f38913b7SCristian Dumitrescu 		}
2304f38913b7SCristian Dumitrescu 	}
2305f38913b7SCristian Dumitrescu }
2306f38913b7SCristian Dumitrescu 
2307f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_set_help[] =
2308f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2309f38913b7SCristian Dumitrescu 	"set profile <profile_name>\n";
2310f38913b7SCristian Dumitrescu 
2311f38913b7SCristian Dumitrescu static void
2312f38913b7SCristian Dumitrescu cmd_pipeline_meter_set(char **tokens,
2313f38913b7SCristian Dumitrescu 	uint32_t n_tokens,
2314f38913b7SCristian Dumitrescu 	char *out,
2315f38913b7SCristian Dumitrescu 	size_t out_size,
2316f38913b7SCristian Dumitrescu 	void *obj)
2317f38913b7SCristian Dumitrescu {
2318f38913b7SCristian Dumitrescu 	struct pipeline *p;
2319f38913b7SCristian Dumitrescu 	const char *name, *profile_name;
232000b67591SAli Alnubani 	uint32_t idx0 = 0, idx1 = 0;
2321f38913b7SCristian Dumitrescu 
2322f38913b7SCristian Dumitrescu 	if (n_tokens != 11) {
2323f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2324f38913b7SCristian Dumitrescu 		return;
2325f38913b7SCristian Dumitrescu 	}
2326f38913b7SCristian Dumitrescu 
2327f38913b7SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
2328f38913b7SCristian Dumitrescu 	if (!p || !p->ctl) {
2329f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2330f38913b7SCristian Dumitrescu 		return;
2331f38913b7SCristian Dumitrescu 	}
2332f38913b7SCristian Dumitrescu 
2333f38913b7SCristian Dumitrescu 	if (strcmp(tokens[2], "meter")) {
2334f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2335f38913b7SCristian Dumitrescu 		return;
2336f38913b7SCristian Dumitrescu 	}
2337f38913b7SCristian Dumitrescu 
2338f38913b7SCristian Dumitrescu 	name = tokens[3];
2339f38913b7SCristian Dumitrescu 
2340f38913b7SCristian Dumitrescu 	if (strcmp(tokens[4], "from")) {
2341f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2342f38913b7SCristian Dumitrescu 		return;
2343f38913b7SCristian Dumitrescu 	}
2344f38913b7SCristian Dumitrescu 
2345f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx0, tokens[5])) {
2346f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2347f38913b7SCristian Dumitrescu 		return;
2348f38913b7SCristian Dumitrescu 	}
2349f38913b7SCristian Dumitrescu 
2350f38913b7SCristian Dumitrescu 	if (strcmp(tokens[6], "to")) {
2351f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2352f38913b7SCristian Dumitrescu 		return;
2353f38913b7SCristian Dumitrescu 	}
2354f38913b7SCristian Dumitrescu 
2355f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2356f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2357f38913b7SCristian Dumitrescu 		return;
2358f38913b7SCristian Dumitrescu 	}
2359f38913b7SCristian Dumitrescu 
2360f38913b7SCristian Dumitrescu 	if (strcmp(tokens[8], "set")) {
2361f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "set");
2362f38913b7SCristian Dumitrescu 		return;
2363f38913b7SCristian Dumitrescu 	}
2364f38913b7SCristian Dumitrescu 
2365f38913b7SCristian Dumitrescu 	if (strcmp(tokens[9], "profile")) {
2366f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
2367f38913b7SCristian Dumitrescu 		return;
2368f38913b7SCristian Dumitrescu 	}
2369f38913b7SCristian Dumitrescu 
2370f38913b7SCristian Dumitrescu 	profile_name = tokens[10];
2371f38913b7SCristian Dumitrescu 
2372f38913b7SCristian Dumitrescu 	for ( ; idx0 <= idx1; idx0++) {
2373f38913b7SCristian Dumitrescu 		int status;
2374f38913b7SCristian Dumitrescu 
2375f38913b7SCristian Dumitrescu 		status = rte_swx_ctl_meter_set(p->p, name, idx0, profile_name);
2376f38913b7SCristian Dumitrescu 		if (status) {
2377f38913b7SCristian Dumitrescu 			snprintf(out, out_size, "Command failed for index %u.\n", idx0);
2378f38913b7SCristian Dumitrescu 			return;
2379f38913b7SCristian Dumitrescu 		}
2380f38913b7SCristian Dumitrescu 	}
2381f38913b7SCristian Dumitrescu }
2382f38913b7SCristian Dumitrescu 
2383f38913b7SCristian Dumitrescu static const char cmd_pipeline_meter_stats_help[] =
2384f38913b7SCristian Dumitrescu "pipeline <pipeline_name> meter <meter_array_name> from <index0> to <index1> "
2385f38913b7SCristian Dumitrescu 	"stats\n";
2386f38913b7SCristian Dumitrescu 
2387f38913b7SCristian Dumitrescu static void
2388f38913b7SCristian Dumitrescu cmd_pipeline_meter_stats(char **tokens,
2389f38913b7SCristian Dumitrescu 	uint32_t n_tokens,
2390f38913b7SCristian Dumitrescu 	char *out,
2391f38913b7SCristian Dumitrescu 	size_t out_size,
2392f38913b7SCristian Dumitrescu 	void *obj)
2393f38913b7SCristian Dumitrescu {
2394f38913b7SCristian Dumitrescu 	struct rte_swx_ctl_meter_stats stats;
2395f38913b7SCristian Dumitrescu 	struct pipeline *p;
2396f38913b7SCristian Dumitrescu 	const char *name;
239700b67591SAli Alnubani 	uint32_t idx0 = 0, idx1 = 0;
2398f38913b7SCristian Dumitrescu 
2399f38913b7SCristian Dumitrescu 	if (n_tokens != 9) {
2400f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2401f38913b7SCristian Dumitrescu 		return;
2402f38913b7SCristian Dumitrescu 	}
2403f38913b7SCristian Dumitrescu 
2404f38913b7SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
2405f38913b7SCristian Dumitrescu 	if (!p || !p->ctl) {
2406f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
2407f38913b7SCristian Dumitrescu 		return;
2408f38913b7SCristian Dumitrescu 	}
2409f38913b7SCristian Dumitrescu 
2410f38913b7SCristian Dumitrescu 	if (strcmp(tokens[2], "meter")) {
2411f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
2412f38913b7SCristian Dumitrescu 		return;
2413f38913b7SCristian Dumitrescu 	}
2414f38913b7SCristian Dumitrescu 
2415f38913b7SCristian Dumitrescu 	name = tokens[3];
2416f38913b7SCristian Dumitrescu 
2417f38913b7SCristian Dumitrescu 	if (strcmp(tokens[4], "from")) {
2418f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
2419f38913b7SCristian Dumitrescu 		return;
2420f38913b7SCristian Dumitrescu 	}
2421f38913b7SCristian Dumitrescu 
2422f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx0, tokens[5])) {
2423f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index0");
2424f38913b7SCristian Dumitrescu 		return;
2425f38913b7SCristian Dumitrescu 	}
2426f38913b7SCristian Dumitrescu 
2427f38913b7SCristian Dumitrescu 	if (strcmp(tokens[6], "to")) {
2428f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
2429f38913b7SCristian Dumitrescu 		return;
2430f38913b7SCristian Dumitrescu 	}
2431f38913b7SCristian Dumitrescu 
2432f38913b7SCristian Dumitrescu 	if (parser_read_uint32(&idx1, tokens[7]) || (idx1 < idx0)) {
2433f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "index1");
2434f38913b7SCristian Dumitrescu 		return;
2435f38913b7SCristian Dumitrescu 	}
2436f38913b7SCristian Dumitrescu 
2437f38913b7SCristian Dumitrescu 	if (strcmp(tokens[8], "stats")) {
2438f38913b7SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
2439f38913b7SCristian Dumitrescu 		return;
2440f38913b7SCristian Dumitrescu 	}
2441f38913b7SCristian Dumitrescu 
2442f38913b7SCristian Dumitrescu 	/* Table header. */
2443f38913b7SCristian Dumitrescu 	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
2444f38913b7SCristian Dumitrescu 		 "-------",
2445f38913b7SCristian Dumitrescu 		 "----------------", "----------------", "----------------",
2446f38913b7SCristian Dumitrescu 		 "----------------", "----------------", "----------------");
2447f38913b7SCristian Dumitrescu 	out_size -= strlen(out);
2448f38913b7SCristian Dumitrescu 	out += strlen(out);
2449f38913b7SCristian Dumitrescu 
2450f38913b7SCristian Dumitrescu 	snprintf(out, out_size, "| %4s | %16s | %16s | %16s | %16s | %16s | %16s |\n",
2451f38913b7SCristian Dumitrescu 		 "METER #",
2452f38913b7SCristian Dumitrescu 		 "GREEN (packets)", "YELLOW (packets)", "RED (packets)",
2453f38913b7SCristian Dumitrescu 		 "GREEN (bytes)", "YELLOW (bytes)", "RED (bytes)");
2454f38913b7SCristian Dumitrescu 	out_size -= strlen(out);
2455f38913b7SCristian Dumitrescu 	out += strlen(out);
2456f38913b7SCristian Dumitrescu 
2457f38913b7SCristian Dumitrescu 	snprintf(out, out_size, "+-%7s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+-%16s-+\n",
2458f38913b7SCristian Dumitrescu 		 "-------",
2459f38913b7SCristian Dumitrescu 		 "----------------", "----------------", "----------------",
2460f38913b7SCristian Dumitrescu 		 "----------------", "----------------", "----------------");
2461f38913b7SCristian Dumitrescu 	out_size -= strlen(out);
2462f38913b7SCristian Dumitrescu 	out += strlen(out);
2463f38913b7SCristian Dumitrescu 
2464f38913b7SCristian Dumitrescu 	/* Table rows. */
2465f38913b7SCristian Dumitrescu 	for ( ; idx0 <= idx1; idx0++) {
2466f38913b7SCristian Dumitrescu 		int status;
2467f38913b7SCristian Dumitrescu 
2468f38913b7SCristian Dumitrescu 		status = rte_swx_ctl_meter_stats_read(p->p, name, idx0, &stats);
2469f38913b7SCristian Dumitrescu 		if (status) {
2470f38913b7SCristian Dumitrescu 			snprintf(out, out_size, "Pipeline meter stats error at index %u.\n", idx0);
2471f38913b7SCristian Dumitrescu 			out_size -= strlen(out);
2472f38913b7SCristian Dumitrescu 			out += strlen(out);
2473f38913b7SCristian Dumitrescu 			return;
2474f38913b7SCristian Dumitrescu 		}
2475f38913b7SCristian Dumitrescu 
2476f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "| %7d | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64
2477f38913b7SCristian Dumitrescu 			 " | %16" PRIx64 " | %16" PRIx64 " | %16" PRIx64 " |\n",
2478f38913b7SCristian Dumitrescu 			 idx0,
2479f38913b7SCristian Dumitrescu 			 stats.n_pkts[RTE_COLOR_GREEN],
2480f38913b7SCristian Dumitrescu 			 stats.n_pkts[RTE_COLOR_YELLOW],
2481f38913b7SCristian Dumitrescu 			 stats.n_pkts[RTE_COLOR_RED],
2482f38913b7SCristian Dumitrescu 			 stats.n_bytes[RTE_COLOR_GREEN],
2483f38913b7SCristian Dumitrescu 			 stats.n_bytes[RTE_COLOR_YELLOW],
2484f38913b7SCristian Dumitrescu 			 stats.n_bytes[RTE_COLOR_RED]);
2485f38913b7SCristian Dumitrescu 		out_size -= strlen(out);
2486f38913b7SCristian Dumitrescu 		out += strlen(out);
2487f38913b7SCristian Dumitrescu 	}
2488f38913b7SCristian Dumitrescu }
2489f38913b7SCristian Dumitrescu 
24905074e1d5SCristian Dumitrescu static const char cmd_pipeline_stats_help[] =
24915074e1d5SCristian Dumitrescu "pipeline <pipeline_name> stats\n";
24925074e1d5SCristian Dumitrescu 
24935074e1d5SCristian Dumitrescu static void
24945074e1d5SCristian Dumitrescu cmd_pipeline_stats(char **tokens,
24955074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
24965074e1d5SCristian Dumitrescu 	char *out,
24975074e1d5SCristian Dumitrescu 	size_t out_size,
24985074e1d5SCristian Dumitrescu 	void *obj)
24995074e1d5SCristian Dumitrescu {
25005074e1d5SCristian Dumitrescu 	struct rte_swx_ctl_pipeline_info info;
25015074e1d5SCristian Dumitrescu 	struct pipeline *p;
25025074e1d5SCristian Dumitrescu 	uint32_t i;
25035074e1d5SCristian Dumitrescu 	int status;
25045074e1d5SCristian Dumitrescu 
25055074e1d5SCristian Dumitrescu 	if (n_tokens != 3) {
25065074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
25075074e1d5SCristian Dumitrescu 		return;
25085074e1d5SCristian Dumitrescu 	}
25095074e1d5SCristian Dumitrescu 
25105074e1d5SCristian Dumitrescu 	p = pipeline_find(obj, tokens[1]);
25115074e1d5SCristian Dumitrescu 	if (!p || !p->ctl) {
25125074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
25135074e1d5SCristian Dumitrescu 		return;
25145074e1d5SCristian Dumitrescu 	}
25155074e1d5SCristian Dumitrescu 
25165074e1d5SCristian Dumitrescu 	if (strcmp(tokens[2], "stats")) {
25175074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
25185074e1d5SCristian Dumitrescu 		return;
25195074e1d5SCristian Dumitrescu 	}
25205074e1d5SCristian Dumitrescu 
25215074e1d5SCristian Dumitrescu 	status = rte_swx_ctl_pipeline_info_get(p->p, &info);
25225074e1d5SCristian Dumitrescu 	if (status) {
25235074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "Pipeline info get error.");
25245074e1d5SCristian Dumitrescu 		return;
25255074e1d5SCristian Dumitrescu 	}
25265074e1d5SCristian Dumitrescu 
25275074e1d5SCristian Dumitrescu 	snprintf(out, out_size, "Input ports:\n");
25285074e1d5SCristian Dumitrescu 	out_size -= strlen(out);
25295074e1d5SCristian Dumitrescu 	out += strlen(out);
25305074e1d5SCristian Dumitrescu 
25315074e1d5SCristian Dumitrescu 	for (i = 0; i < info.n_ports_in; i++) {
25325074e1d5SCristian Dumitrescu 		struct rte_swx_port_in_stats stats;
25335074e1d5SCristian Dumitrescu 
25345074e1d5SCristian Dumitrescu 		rte_swx_ctl_pipeline_port_in_stats_read(p->p, i, &stats);
25355074e1d5SCristian Dumitrescu 
25365074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\tPort %u:"
25375074e1d5SCristian Dumitrescu 			" packets %" PRIu64
25385074e1d5SCristian Dumitrescu 			" bytes %" PRIu64
25395074e1d5SCristian Dumitrescu 			" empty %" PRIu64 "\n",
25405074e1d5SCristian Dumitrescu 			i, stats.n_pkts, stats.n_bytes, stats.n_empty);
25415074e1d5SCristian Dumitrescu 		out_size -= strlen(out);
25425074e1d5SCristian Dumitrescu 		out += strlen(out);
25435074e1d5SCristian Dumitrescu 	}
25445074e1d5SCristian Dumitrescu 
2545742b0a57SCristian Dumitrescu 	snprintf(out, out_size, "\nOutput ports:\n");
25465074e1d5SCristian Dumitrescu 	out_size -= strlen(out);
25475074e1d5SCristian Dumitrescu 	out += strlen(out);
25485074e1d5SCristian Dumitrescu 
25495074e1d5SCristian Dumitrescu 	for (i = 0; i < info.n_ports_out; i++) {
25505074e1d5SCristian Dumitrescu 		struct rte_swx_port_out_stats stats;
25515074e1d5SCristian Dumitrescu 
25525074e1d5SCristian Dumitrescu 		rte_swx_ctl_pipeline_port_out_stats_read(p->p, i, &stats);
25535074e1d5SCristian Dumitrescu 
2554*96b37959SCristian Dumitrescu 		if (i != info.n_ports_out - 1)
25555074e1d5SCristian Dumitrescu 			snprintf(out, out_size, "\tPort %u:"
25565074e1d5SCristian Dumitrescu 				" packets %" PRIu64
25575074e1d5SCristian Dumitrescu 				" bytes %" PRIu64 "\n",
25585074e1d5SCristian Dumitrescu 				i, stats.n_pkts, stats.n_bytes);
2559*96b37959SCristian Dumitrescu 		else
2560*96b37959SCristian Dumitrescu 			snprintf(out, out_size, "\tDROP:"
2561*96b37959SCristian Dumitrescu 				" packets %" PRIu64
2562*96b37959SCristian Dumitrescu 				" bytes %" PRIu64 "\n",
2563*96b37959SCristian Dumitrescu 				stats.n_pkts, stats.n_bytes);
2564*96b37959SCristian Dumitrescu 
25655074e1d5SCristian Dumitrescu 		out_size -= strlen(out);
25665074e1d5SCristian Dumitrescu 		out += strlen(out);
25675074e1d5SCristian Dumitrescu 	}
2568742b0a57SCristian Dumitrescu 
2569742b0a57SCristian Dumitrescu 	snprintf(out, out_size, "\nTables:\n");
2570742b0a57SCristian Dumitrescu 	out_size -= strlen(out);
2571742b0a57SCristian Dumitrescu 	out += strlen(out);
2572742b0a57SCristian Dumitrescu 
2573742b0a57SCristian Dumitrescu 	for (i = 0; i < info.n_tables; i++) {
2574742b0a57SCristian Dumitrescu 		struct rte_swx_ctl_table_info table_info;
2575742b0a57SCristian Dumitrescu 		uint64_t n_pkts_action[info.n_actions];
2576742b0a57SCristian Dumitrescu 		struct rte_swx_table_stats stats = {
2577742b0a57SCristian Dumitrescu 			.n_pkts_hit = 0,
2578742b0a57SCristian Dumitrescu 			.n_pkts_miss = 0,
2579742b0a57SCristian Dumitrescu 			.n_pkts_action = n_pkts_action,
2580742b0a57SCristian Dumitrescu 		};
2581742b0a57SCristian Dumitrescu 		uint32_t j;
2582742b0a57SCristian Dumitrescu 
2583742b0a57SCristian Dumitrescu 		status = rte_swx_ctl_table_info_get(p->p, i, &table_info);
2584742b0a57SCristian Dumitrescu 		if (status) {
2585742b0a57SCristian Dumitrescu 			snprintf(out, out_size, "Table info get error.");
2586742b0a57SCristian Dumitrescu 			return;
2587742b0a57SCristian Dumitrescu 		}
2588742b0a57SCristian Dumitrescu 
2589742b0a57SCristian Dumitrescu 		status = rte_swx_ctl_pipeline_table_stats_read(p->p, table_info.name, &stats);
2590742b0a57SCristian Dumitrescu 		if (status) {
2591742b0a57SCristian Dumitrescu 			snprintf(out, out_size, "Table stats read error.");
2592742b0a57SCristian Dumitrescu 			return;
2593742b0a57SCristian Dumitrescu 		}
2594742b0a57SCristian Dumitrescu 
2595742b0a57SCristian Dumitrescu 		snprintf(out, out_size, "\tTable %s:\n"
2596742b0a57SCristian Dumitrescu 			"\t\tHit (packets): %" PRIu64 "\n"
2597742b0a57SCristian Dumitrescu 			"\t\tMiss (packets): %" PRIu64 "\n",
2598742b0a57SCristian Dumitrescu 			table_info.name,
2599742b0a57SCristian Dumitrescu 			stats.n_pkts_hit,
2600742b0a57SCristian Dumitrescu 			stats.n_pkts_miss);
2601742b0a57SCristian Dumitrescu 		out_size -= strlen(out);
2602742b0a57SCristian Dumitrescu 		out += strlen(out);
2603742b0a57SCristian Dumitrescu 
2604742b0a57SCristian Dumitrescu 		for (j = 0; j < info.n_actions; j++) {
2605742b0a57SCristian Dumitrescu 			struct rte_swx_ctl_action_info action_info;
2606742b0a57SCristian Dumitrescu 
2607742b0a57SCristian Dumitrescu 			status = rte_swx_ctl_action_info_get(p->p, j, &action_info);
2608742b0a57SCristian Dumitrescu 			if (status) {
2609742b0a57SCristian Dumitrescu 				snprintf(out, out_size, "Action info get error.");
2610742b0a57SCristian Dumitrescu 				return;
2611742b0a57SCristian Dumitrescu 			}
2612742b0a57SCristian Dumitrescu 
2613742b0a57SCristian Dumitrescu 			snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n",
2614742b0a57SCristian Dumitrescu 				action_info.name,
2615742b0a57SCristian Dumitrescu 				stats.n_pkts_action[j]);
2616742b0a57SCristian Dumitrescu 			out_size -= strlen(out);
2617742b0a57SCristian Dumitrescu 			out += strlen(out);
2618742b0a57SCristian Dumitrescu 		}
2619742b0a57SCristian Dumitrescu 	}
26208bd4862fSCristian Dumitrescu 
26218bd4862fSCristian Dumitrescu 	snprintf(out, out_size, "\nLearner tables:\n");
26228bd4862fSCristian Dumitrescu 	out_size -= strlen(out);
26238bd4862fSCristian Dumitrescu 	out += strlen(out);
26248bd4862fSCristian Dumitrescu 
26258bd4862fSCristian Dumitrescu 	for (i = 0; i < info.n_learners; i++) {
26268bd4862fSCristian Dumitrescu 		struct rte_swx_ctl_learner_info learner_info;
26278bd4862fSCristian Dumitrescu 		uint64_t n_pkts_action[info.n_actions];
26288bd4862fSCristian Dumitrescu 		struct rte_swx_learner_stats stats = {
26298bd4862fSCristian Dumitrescu 			.n_pkts_hit = 0,
26308bd4862fSCristian Dumitrescu 			.n_pkts_miss = 0,
26318bd4862fSCristian Dumitrescu 			.n_pkts_action = n_pkts_action,
26328bd4862fSCristian Dumitrescu 		};
26338bd4862fSCristian Dumitrescu 		uint32_t j;
26348bd4862fSCristian Dumitrescu 
26358bd4862fSCristian Dumitrescu 		status = rte_swx_ctl_learner_info_get(p->p, i, &learner_info);
26368bd4862fSCristian Dumitrescu 		if (status) {
26378bd4862fSCristian Dumitrescu 			snprintf(out, out_size, "Learner table info get error.");
26388bd4862fSCristian Dumitrescu 			return;
26398bd4862fSCristian Dumitrescu 		}
26408bd4862fSCristian Dumitrescu 
26418bd4862fSCristian Dumitrescu 		status = rte_swx_ctl_pipeline_learner_stats_read(p->p, learner_info.name, &stats);
26428bd4862fSCristian Dumitrescu 		if (status) {
26438bd4862fSCristian Dumitrescu 			snprintf(out, out_size, "Learner table stats read error.");
26448bd4862fSCristian Dumitrescu 			return;
26458bd4862fSCristian Dumitrescu 		}
26468bd4862fSCristian Dumitrescu 
26478bd4862fSCristian Dumitrescu 		snprintf(out, out_size, "\tLearner table %s:\n"
26488bd4862fSCristian Dumitrescu 			"\t\tHit (packets): %" PRIu64 "\n"
26498bd4862fSCristian Dumitrescu 			"\t\tMiss (packets): %" PRIu64 "\n"
26508bd4862fSCristian Dumitrescu 			"\t\tLearn OK (packets): %" PRIu64 "\n"
26518bd4862fSCristian Dumitrescu 			"\t\tLearn error (packets): %" PRIu64 "\n"
26528bd4862fSCristian Dumitrescu 			"\t\tForget (packets): %" PRIu64 "\n",
26538bd4862fSCristian Dumitrescu 			learner_info.name,
26548bd4862fSCristian Dumitrescu 			stats.n_pkts_hit,
26558bd4862fSCristian Dumitrescu 			stats.n_pkts_miss,
26568bd4862fSCristian Dumitrescu 			stats.n_pkts_learn_ok,
26578bd4862fSCristian Dumitrescu 			stats.n_pkts_learn_err,
26588bd4862fSCristian Dumitrescu 			stats.n_pkts_forget);
26598bd4862fSCristian Dumitrescu 		out_size -= strlen(out);
26608bd4862fSCristian Dumitrescu 		out += strlen(out);
26618bd4862fSCristian Dumitrescu 
26628bd4862fSCristian Dumitrescu 		for (j = 0; j < info.n_actions; j++) {
26638bd4862fSCristian Dumitrescu 			struct rte_swx_ctl_action_info action_info;
26648bd4862fSCristian Dumitrescu 
26658bd4862fSCristian Dumitrescu 			status = rte_swx_ctl_action_info_get(p->p, j, &action_info);
26668bd4862fSCristian Dumitrescu 			if (status) {
26678bd4862fSCristian Dumitrescu 				snprintf(out, out_size, "Action info get error.");
26688bd4862fSCristian Dumitrescu 				return;
26698bd4862fSCristian Dumitrescu 			}
26708bd4862fSCristian Dumitrescu 
26718bd4862fSCristian Dumitrescu 			snprintf(out, out_size, "\t\tAction %s (packets): %" PRIu64 "\n",
26728bd4862fSCristian Dumitrescu 				action_info.name,
26738bd4862fSCristian Dumitrescu 				stats.n_pkts_action[j]);
26748bd4862fSCristian Dumitrescu 			out_size -= strlen(out);
26758bd4862fSCristian Dumitrescu 			out += strlen(out);
26768bd4862fSCristian Dumitrescu 		}
26778bd4862fSCristian Dumitrescu 	}
26785074e1d5SCristian Dumitrescu }
26795074e1d5SCristian Dumitrescu 
26805074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_enable_help[] =
26815074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> enable\n";
26825074e1d5SCristian Dumitrescu 
26835074e1d5SCristian Dumitrescu static void
26845074e1d5SCristian Dumitrescu cmd_thread_pipeline_enable(char **tokens,
26855074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
26865074e1d5SCristian Dumitrescu 	char *out,
26875074e1d5SCristian Dumitrescu 	size_t out_size,
26885074e1d5SCristian Dumitrescu 	void *obj)
26895074e1d5SCristian Dumitrescu {
26905074e1d5SCristian Dumitrescu 	char *pipeline_name;
26915074e1d5SCristian Dumitrescu 	struct pipeline *p;
26925074e1d5SCristian Dumitrescu 	uint32_t thread_id;
26935074e1d5SCristian Dumitrescu 	int status;
26945074e1d5SCristian Dumitrescu 
26955074e1d5SCristian Dumitrescu 	if (n_tokens != 5) {
26965074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
26975074e1d5SCristian Dumitrescu 		return;
26985074e1d5SCristian Dumitrescu 	}
26995074e1d5SCristian Dumitrescu 
27005074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
27015074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
27025074e1d5SCristian Dumitrescu 		return;
27035074e1d5SCristian Dumitrescu 	}
27045074e1d5SCristian Dumitrescu 
27055074e1d5SCristian Dumitrescu 	if (strcmp(tokens[2], "pipeline") != 0) {
27065074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
27075074e1d5SCristian Dumitrescu 		return;
27085074e1d5SCristian Dumitrescu 	}
27095074e1d5SCristian Dumitrescu 
27105074e1d5SCristian Dumitrescu 	pipeline_name = tokens[3];
27115074e1d5SCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
27125074e1d5SCristian Dumitrescu 	if (!p || !p->ctl) {
27135074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
27145074e1d5SCristian Dumitrescu 		return;
27155074e1d5SCristian Dumitrescu 	}
27165074e1d5SCristian Dumitrescu 
27175074e1d5SCristian Dumitrescu 	if (strcmp(tokens[4], "enable") != 0) {
27185074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
27195074e1d5SCristian Dumitrescu 		return;
27205074e1d5SCristian Dumitrescu 	}
27215074e1d5SCristian Dumitrescu 
27225074e1d5SCristian Dumitrescu 	status = thread_pipeline_enable(thread_id, obj, pipeline_name);
27235074e1d5SCristian Dumitrescu 	if (status) {
27245074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
27255074e1d5SCristian Dumitrescu 		return;
27265074e1d5SCristian Dumitrescu 	}
27275074e1d5SCristian Dumitrescu }
27285074e1d5SCristian Dumitrescu 
27295074e1d5SCristian Dumitrescu static const char cmd_thread_pipeline_disable_help[] =
27305074e1d5SCristian Dumitrescu "thread <thread_id> pipeline <pipeline_name> disable\n";
27315074e1d5SCristian Dumitrescu 
27325074e1d5SCristian Dumitrescu static void
27335074e1d5SCristian Dumitrescu cmd_thread_pipeline_disable(char **tokens,
27345074e1d5SCristian Dumitrescu 	uint32_t n_tokens,
27355074e1d5SCristian Dumitrescu 	char *out,
27365074e1d5SCristian Dumitrescu 	size_t out_size,
27375074e1d5SCristian Dumitrescu 	void *obj)
27385074e1d5SCristian Dumitrescu {
27395074e1d5SCristian Dumitrescu 	struct pipeline *p;
27405074e1d5SCristian Dumitrescu 	char *pipeline_name;
27415074e1d5SCristian Dumitrescu 	uint32_t thread_id;
27425074e1d5SCristian Dumitrescu 	int status;
27435074e1d5SCristian Dumitrescu 
27445074e1d5SCristian Dumitrescu 	if (n_tokens != 5) {
27455074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
27465074e1d5SCristian Dumitrescu 		return;
27475074e1d5SCristian Dumitrescu 	}
27485074e1d5SCristian Dumitrescu 
27495074e1d5SCristian Dumitrescu 	if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
27505074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
27515074e1d5SCristian Dumitrescu 		return;
27525074e1d5SCristian Dumitrescu 	}
27535074e1d5SCristian Dumitrescu 
27545074e1d5SCristian Dumitrescu 	if (strcmp(tokens[2], "pipeline") != 0) {
27555074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
27565074e1d5SCristian Dumitrescu 		return;
27575074e1d5SCristian Dumitrescu 	}
27585074e1d5SCristian Dumitrescu 
27595074e1d5SCristian Dumitrescu 	pipeline_name = tokens[3];
27605074e1d5SCristian Dumitrescu 	p = pipeline_find(obj, pipeline_name);
27615074e1d5SCristian Dumitrescu 	if (!p || !p->ctl) {
27625074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "pipeline_name");
27635074e1d5SCristian Dumitrescu 		return;
27645074e1d5SCristian Dumitrescu 	}
27655074e1d5SCristian Dumitrescu 
27665074e1d5SCristian Dumitrescu 	if (strcmp(tokens[4], "disable") != 0) {
27675074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
27685074e1d5SCristian Dumitrescu 		return;
27695074e1d5SCristian Dumitrescu 	}
27705074e1d5SCristian Dumitrescu 
27715074e1d5SCristian Dumitrescu 	status = thread_pipeline_disable(thread_id, obj, pipeline_name);
27725074e1d5SCristian Dumitrescu 	if (status) {
27735074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL,
27745074e1d5SCristian Dumitrescu 			"thread pipeline disable");
27755074e1d5SCristian Dumitrescu 		return;
27765074e1d5SCristian Dumitrescu 	}
27775074e1d5SCristian Dumitrescu }
27785074e1d5SCristian Dumitrescu 
27795074e1d5SCristian Dumitrescu static void
27805074e1d5SCristian Dumitrescu cmd_help(char **tokens,
27815074e1d5SCristian Dumitrescu 	 uint32_t n_tokens,
27825074e1d5SCristian Dumitrescu 	 char *out,
27835074e1d5SCristian Dumitrescu 	 size_t out_size,
27845074e1d5SCristian Dumitrescu 	 void *arg __rte_unused)
27855074e1d5SCristian Dumitrescu {
27865074e1d5SCristian Dumitrescu 	tokens++;
27875074e1d5SCristian Dumitrescu 	n_tokens--;
27885074e1d5SCristian Dumitrescu 
27895074e1d5SCristian Dumitrescu 	if (n_tokens == 0) {
27905074e1d5SCristian Dumitrescu 		snprintf(out, out_size,
27917fef9ef1SYogesh Jangra 			"Type 'help <command>' for command details.\n\n"
27927fef9ef1SYogesh Jangra 			"List of commands:\n"
27937fef9ef1SYogesh Jangra 			"\tmempool\n"
27947fef9ef1SYogesh Jangra 			"\tlink\n"
2795e2b8dc52SVenkata Suresh Kumar P 			"\ttap\n"
27967fef9ef1SYogesh Jangra 			"\tpipeline create\n"
27977fef9ef1SYogesh Jangra 			"\tpipeline port in\n"
27987fef9ef1SYogesh Jangra 			"\tpipeline port out\n"
27997fef9ef1SYogesh Jangra 			"\tpipeline build\n"
280075129cebSChurchill Khangar 			"\tpipeline table add\n"
280175129cebSChurchill Khangar 			"\tpipeline table delete\n"
280275129cebSChurchill Khangar 			"\tpipeline table default\n"
280375129cebSChurchill Khangar 			"\tpipeline table show\n"
2804598fe0ddSCristian Dumitrescu 			"\tpipeline selector group add\n"
2805598fe0ddSCristian Dumitrescu 			"\tpipeline selector group delete\n"
2806598fe0ddSCristian Dumitrescu 			"\tpipeline selector group member add\n"
2807598fe0ddSCristian Dumitrescu 			"\tpipeline selector group member delete\n"
2808598fe0ddSCristian Dumitrescu 			"\tpipeline selector show\n"
28098bd4862fSCristian Dumitrescu 			"\tpipeline learner default\n"
281075129cebSChurchill Khangar 			"\tpipeline commit\n"
281175129cebSChurchill Khangar 			"\tpipeline abort\n"
281264cfcebdSCristian Dumitrescu 			"\tpipeline regrd\n"
281364cfcebdSCristian Dumitrescu 			"\tpipeline regwr\n"
2814f38913b7SCristian Dumitrescu 			"\tpipeline meter profile add\n"
2815f38913b7SCristian Dumitrescu 			"\tpipeline meter profile delete\n"
2816f38913b7SCristian Dumitrescu 			"\tpipeline meter reset\n"
2817f38913b7SCristian Dumitrescu 			"\tpipeline meter set\n"
2818f38913b7SCristian Dumitrescu 			"\tpipeline meter stats\n"
28197fef9ef1SYogesh Jangra 			"\tpipeline stats\n"
28207fef9ef1SYogesh Jangra 			"\tthread pipeline enable\n"
28217fef9ef1SYogesh Jangra 			"\tthread pipeline disable\n\n");
28225074e1d5SCristian Dumitrescu 		return;
28235074e1d5SCristian Dumitrescu 	}
28245074e1d5SCristian Dumitrescu 
28255074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "mempool") == 0) {
28265074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
28275074e1d5SCristian Dumitrescu 		return;
28285074e1d5SCristian Dumitrescu 	}
28295074e1d5SCristian Dumitrescu 
28305074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "link") == 0) {
28315074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_link_help);
28325074e1d5SCristian Dumitrescu 		return;
28335074e1d5SCristian Dumitrescu 	}
28345074e1d5SCristian Dumitrescu 
283577a41301SCristian Dumitrescu 	if (strcmp(tokens[0], "ring") == 0) {
283677a41301SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_ring_help);
283777a41301SCristian Dumitrescu 		return;
283877a41301SCristian Dumitrescu 	}
283977a41301SCristian Dumitrescu 
2840e2b8dc52SVenkata Suresh Kumar P 	if (strcmp(tokens[0], "tap") == 0) {
2841e2b8dc52SVenkata Suresh Kumar P 		snprintf(out, out_size, "\n%s\n", cmd_tap_help);
2842e2b8dc52SVenkata Suresh Kumar P 		return;
2843e2b8dc52SVenkata Suresh Kumar P 	}
2844e2b8dc52SVenkata Suresh Kumar P 
28455074e1d5SCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
28467fef9ef1SYogesh Jangra 		(n_tokens == 2) && (strcmp(tokens[1], "create") == 0)) {
28475074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_create_help);
28485074e1d5SCristian Dumitrescu 		return;
28495074e1d5SCristian Dumitrescu 	}
28505074e1d5SCristian Dumitrescu 
28515074e1d5SCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
28527fef9ef1SYogesh Jangra 		(n_tokens == 3) && (strcmp(tokens[1], "port") == 0)) {
28537fef9ef1SYogesh Jangra 		if (strcmp(tokens[2], "in") == 0) {
28545074e1d5SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
28555074e1d5SCristian Dumitrescu 				cmd_pipeline_port_in_help);
28565074e1d5SCristian Dumitrescu 			return;
28575074e1d5SCristian Dumitrescu 		}
28585074e1d5SCristian Dumitrescu 
28597fef9ef1SYogesh Jangra 		if (strcmp(tokens[2], "out") == 0) {
28605074e1d5SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
28615074e1d5SCristian Dumitrescu 				cmd_pipeline_port_out_help);
28625074e1d5SCristian Dumitrescu 			return;
28635074e1d5SCristian Dumitrescu 		}
28645074e1d5SCristian Dumitrescu 	}
28655074e1d5SCristian Dumitrescu 
28665074e1d5SCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
28677fef9ef1SYogesh Jangra 		(n_tokens == 2) && (strcmp(tokens[1], "build") == 0)) {
28685074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_build_help);
28695074e1d5SCristian Dumitrescu 		return;
28705074e1d5SCristian Dumitrescu 	}
28715074e1d5SCristian Dumitrescu 
28725074e1d5SCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
28737fef9ef1SYogesh Jangra 		(n_tokens == 3) &&
28747fef9ef1SYogesh Jangra 		(strcmp(tokens[1], "table") == 0) &&
287575129cebSChurchill Khangar 		(strcmp(tokens[2], "add") == 0)) {
28765074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
287775129cebSChurchill Khangar 			cmd_pipeline_table_add_help);
287875129cebSChurchill Khangar 		return;
287975129cebSChurchill Khangar 	}
288075129cebSChurchill Khangar 
288175129cebSChurchill Khangar 	if ((strcmp(tokens[0], "pipeline") == 0) &&
288275129cebSChurchill Khangar 		(n_tokens == 3) &&
288375129cebSChurchill Khangar 		(strcmp(tokens[1], "table") == 0) &&
288475129cebSChurchill Khangar 		(strcmp(tokens[2], "delete") == 0)) {
288575129cebSChurchill Khangar 		snprintf(out, out_size, "\n%s\n",
288675129cebSChurchill Khangar 			cmd_pipeline_table_delete_help);
288775129cebSChurchill Khangar 		return;
288875129cebSChurchill Khangar 	}
288975129cebSChurchill Khangar 
289075129cebSChurchill Khangar 	if ((strcmp(tokens[0], "pipeline") == 0) &&
289175129cebSChurchill Khangar 		(n_tokens == 3) &&
289275129cebSChurchill Khangar 		(strcmp(tokens[1], "table") == 0) &&
289375129cebSChurchill Khangar 		(strcmp(tokens[2], "default") == 0)) {
289475129cebSChurchill Khangar 		snprintf(out, out_size, "\n%s\n",
289575129cebSChurchill Khangar 			cmd_pipeline_table_default_help);
289675129cebSChurchill Khangar 		return;
289775129cebSChurchill Khangar 	}
289875129cebSChurchill Khangar 
289975129cebSChurchill Khangar 	if ((strcmp(tokens[0], "pipeline") == 0) &&
290075129cebSChurchill Khangar 		(n_tokens == 3) &&
290175129cebSChurchill Khangar 		(strcmp(tokens[1], "table") == 0) &&
290275129cebSChurchill Khangar 		(strcmp(tokens[2], "show") == 0)) {
290375129cebSChurchill Khangar 		snprintf(out, out_size, "\n%s\n",
290475129cebSChurchill Khangar 			cmd_pipeline_table_show_help);
290575129cebSChurchill Khangar 		return;
290675129cebSChurchill Khangar 	}
290775129cebSChurchill Khangar 
290875129cebSChurchill Khangar 	if ((strcmp(tokens[0], "pipeline") == 0) &&
2909598fe0ddSCristian Dumitrescu 		(n_tokens == 4) &&
2910598fe0ddSCristian Dumitrescu 		(strcmp(tokens[1], "selector") == 0) &&
2911598fe0ddSCristian Dumitrescu 		(strcmp(tokens[2], "group") == 0) &&
2912598fe0ddSCristian Dumitrescu 		(strcmp(tokens[3], "add") == 0)) {
2913598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
2914598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_add_help);
2915598fe0ddSCristian Dumitrescu 		return;
2916598fe0ddSCristian Dumitrescu 	}
2917598fe0ddSCristian Dumitrescu 
2918598fe0ddSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
2919598fe0ddSCristian Dumitrescu 		(n_tokens == 4) &&
2920598fe0ddSCristian Dumitrescu 		(strcmp(tokens[1], "selector") == 0) &&
2921598fe0ddSCristian Dumitrescu 		(strcmp(tokens[2], "group") == 0) &&
2922598fe0ddSCristian Dumitrescu 		(strcmp(tokens[3], "delete") == 0)) {
2923598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
2924598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_delete_help);
2925598fe0ddSCristian Dumitrescu 		return;
2926598fe0ddSCristian Dumitrescu 	}
2927598fe0ddSCristian Dumitrescu 
2928598fe0ddSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
2929598fe0ddSCristian Dumitrescu 		(n_tokens == 5) &&
2930598fe0ddSCristian Dumitrescu 		(strcmp(tokens[1], "selector") == 0) &&
2931598fe0ddSCristian Dumitrescu 		(strcmp(tokens[2], "group") == 0) &&
2932598fe0ddSCristian Dumitrescu 		(strcmp(tokens[3], "member") == 0) &&
2933598fe0ddSCristian Dumitrescu 		(strcmp(tokens[4], "add") == 0)) {
2934598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
2935598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_member_add_help);
2936598fe0ddSCristian Dumitrescu 		return;
2937598fe0ddSCristian Dumitrescu 	}
2938598fe0ddSCristian Dumitrescu 
2939598fe0ddSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
2940598fe0ddSCristian Dumitrescu 		(n_tokens == 5) &&
2941598fe0ddSCristian Dumitrescu 		(strcmp(tokens[1], "selector") == 0) &&
2942598fe0ddSCristian Dumitrescu 		(strcmp(tokens[2], "group") == 0) &&
2943598fe0ddSCristian Dumitrescu 		(strcmp(tokens[3], "member") == 0) &&
2944598fe0ddSCristian Dumitrescu 		(strcmp(tokens[4], "delete") == 0)) {
2945598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
2946598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_member_delete_help);
2947598fe0ddSCristian Dumitrescu 		return;
2948598fe0ddSCristian Dumitrescu 	}
2949598fe0ddSCristian Dumitrescu 
2950598fe0ddSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
2951598fe0ddSCristian Dumitrescu 		(n_tokens == 3) &&
2952598fe0ddSCristian Dumitrescu 		(strcmp(tokens[1], "selector") == 0) &&
2953598fe0ddSCristian Dumitrescu 		(strcmp(tokens[2], "show") == 0)) {
2954598fe0ddSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
2955598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_show_help);
2956598fe0ddSCristian Dumitrescu 		return;
2957598fe0ddSCristian Dumitrescu 	}
2958598fe0ddSCristian Dumitrescu 
2959598fe0ddSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
29608bd4862fSCristian Dumitrescu 		(n_tokens == 3) &&
29618bd4862fSCristian Dumitrescu 		(strcmp(tokens[1], "learner") == 0) &&
29628bd4862fSCristian Dumitrescu 		(strcmp(tokens[2], "default") == 0)) {
29638bd4862fSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n",
29648bd4862fSCristian Dumitrescu 			cmd_pipeline_learner_default_help);
29658bd4862fSCristian Dumitrescu 		return;
29668bd4862fSCristian Dumitrescu 	}
29678bd4862fSCristian Dumitrescu 
29688bd4862fSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
296975129cebSChurchill Khangar 		(n_tokens == 2) &&
297075129cebSChurchill Khangar 		(strcmp(tokens[1], "commit") == 0)) {
297175129cebSChurchill Khangar 		snprintf(out, out_size, "\n%s\n",
297275129cebSChurchill Khangar 			cmd_pipeline_commit_help);
297375129cebSChurchill Khangar 		return;
297475129cebSChurchill Khangar 	}
297575129cebSChurchill Khangar 
297675129cebSChurchill Khangar 	if ((strcmp(tokens[0], "pipeline") == 0) &&
297775129cebSChurchill Khangar 		(n_tokens == 2) &&
297875129cebSChurchill Khangar 		(strcmp(tokens[1], "abort") == 0)) {
297975129cebSChurchill Khangar 		snprintf(out, out_size, "\n%s\n",
298075129cebSChurchill Khangar 			cmd_pipeline_abort_help);
29815074e1d5SCristian Dumitrescu 		return;
29825074e1d5SCristian Dumitrescu 	}
29835074e1d5SCristian Dumitrescu 
29845074e1d5SCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
298564cfcebdSCristian Dumitrescu 		(n_tokens == 2) && (strcmp(tokens[1], "regrd") == 0)) {
298664cfcebdSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regrd_help);
298764cfcebdSCristian Dumitrescu 		return;
298864cfcebdSCristian Dumitrescu 	}
298964cfcebdSCristian Dumitrescu 
299064cfcebdSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
299164cfcebdSCristian Dumitrescu 		(n_tokens == 2) && (strcmp(tokens[1], "regwr") == 0)) {
299264cfcebdSCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_regwr_help);
299364cfcebdSCristian Dumitrescu 		return;
299464cfcebdSCristian Dumitrescu 	}
299564cfcebdSCristian Dumitrescu 
2996f38913b7SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
2997f38913b7SCristian Dumitrescu 		(n_tokens == 4) && !strcmp(tokens[1], "meter")
2998f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[2], "profile")
2999f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[3], "add")) {
3000f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_add_help);
3001f38913b7SCristian Dumitrescu 		return;
3002f38913b7SCristian Dumitrescu 	}
3003f38913b7SCristian Dumitrescu 
3004f38913b7SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
3005f38913b7SCristian Dumitrescu 		(n_tokens == 4) && !strcmp(tokens[1], "meter")
3006f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[2], "profile")
3007f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[3], "delete")) {
3008f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_profile_delete_help);
3009f38913b7SCristian Dumitrescu 		return;
3010f38913b7SCristian Dumitrescu 	}
3011f38913b7SCristian Dumitrescu 
3012f38913b7SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
3013f38913b7SCristian Dumitrescu 		(n_tokens == 3) && !strcmp(tokens[1], "meter")
3014f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[2], "reset")) {
3015f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_reset_help);
3016f38913b7SCristian Dumitrescu 		return;
3017f38913b7SCristian Dumitrescu 	}
3018f38913b7SCristian Dumitrescu 
3019f38913b7SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
3020f38913b7SCristian Dumitrescu 		(n_tokens == 3) && !strcmp(tokens[1], "meter")
3021f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[2], "set")) {
3022f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_set_help);
3023f38913b7SCristian Dumitrescu 		return;
3024f38913b7SCristian Dumitrescu 	}
3025f38913b7SCristian Dumitrescu 
3026f38913b7SCristian Dumitrescu 	if (!strcmp(tokens[0], "pipeline") &&
3027f38913b7SCristian Dumitrescu 		(n_tokens == 3) && !strcmp(tokens[1], "meter")
3028f38913b7SCristian Dumitrescu 		&& !strcmp(tokens[2], "stats")) {
3029f38913b7SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_meter_stats_help);
3030f38913b7SCristian Dumitrescu 		return;
3031f38913b7SCristian Dumitrescu 	}
3032f38913b7SCristian Dumitrescu 
303364cfcebdSCristian Dumitrescu 	if ((strcmp(tokens[0], "pipeline") == 0) &&
30347fef9ef1SYogesh Jangra 		(n_tokens == 2) && (strcmp(tokens[1], "stats") == 0)) {
30355074e1d5SCristian Dumitrescu 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_stats_help);
30365074e1d5SCristian Dumitrescu 		return;
30375074e1d5SCristian Dumitrescu 	}
30385074e1d5SCristian Dumitrescu 
30395074e1d5SCristian Dumitrescu 	if ((n_tokens == 3) &&
30405074e1d5SCristian Dumitrescu 		(strcmp(tokens[0], "thread") == 0) &&
30415074e1d5SCristian Dumitrescu 		(strcmp(tokens[1], "pipeline") == 0)) {
30425074e1d5SCristian Dumitrescu 		if (strcmp(tokens[2], "enable") == 0) {
30435074e1d5SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
30445074e1d5SCristian Dumitrescu 				cmd_thread_pipeline_enable_help);
30455074e1d5SCristian Dumitrescu 			return;
30465074e1d5SCristian Dumitrescu 		}
30475074e1d5SCristian Dumitrescu 
30485074e1d5SCristian Dumitrescu 		if (strcmp(tokens[2], "disable") == 0) {
30495074e1d5SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
30505074e1d5SCristian Dumitrescu 				cmd_thread_pipeline_disable_help);
30515074e1d5SCristian Dumitrescu 			return;
30525074e1d5SCristian Dumitrescu 		}
30535074e1d5SCristian Dumitrescu 	}
30545074e1d5SCristian Dumitrescu 
30555074e1d5SCristian Dumitrescu 	snprintf(out, out_size, "Invalid command\n");
30565074e1d5SCristian Dumitrescu }
30575074e1d5SCristian Dumitrescu 
30585074e1d5SCristian Dumitrescu void
30595074e1d5SCristian Dumitrescu cli_process(char *in, char *out, size_t out_size, void *obj)
30605074e1d5SCristian Dumitrescu {
30615074e1d5SCristian Dumitrescu 	char *tokens[CMD_MAX_TOKENS];
30625074e1d5SCristian Dumitrescu 	uint32_t n_tokens = RTE_DIM(tokens);
30635074e1d5SCristian Dumitrescu 	int status;
30645074e1d5SCristian Dumitrescu 
30655074e1d5SCristian Dumitrescu 	if (is_comment(in))
30665074e1d5SCristian Dumitrescu 		return;
30675074e1d5SCristian Dumitrescu 
30685074e1d5SCristian Dumitrescu 	status = parse_tokenize_string(in, tokens, &n_tokens);
30695074e1d5SCristian Dumitrescu 	if (status) {
30705074e1d5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
30715074e1d5SCristian Dumitrescu 		return;
30725074e1d5SCristian Dumitrescu 	}
30735074e1d5SCristian Dumitrescu 
30745074e1d5SCristian Dumitrescu 	if (n_tokens == 0)
30755074e1d5SCristian Dumitrescu 		return;
30765074e1d5SCristian Dumitrescu 
30775074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "help") == 0) {
30785074e1d5SCristian Dumitrescu 		cmd_help(tokens, n_tokens, out, out_size, obj);
30795074e1d5SCristian Dumitrescu 		return;
30805074e1d5SCristian Dumitrescu 	}
30815074e1d5SCristian Dumitrescu 
30825074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "mempool") == 0) {
30835074e1d5SCristian Dumitrescu 		cmd_mempool(tokens, n_tokens, out, out_size, obj);
30845074e1d5SCristian Dumitrescu 		return;
30855074e1d5SCristian Dumitrescu 	}
30865074e1d5SCristian Dumitrescu 
30875074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "link") == 0) {
3088821848f5SCristian Dumitrescu 		if ((n_tokens >= 2) && (strcmp(tokens[1], "show") == 0)) {
30895074e1d5SCristian Dumitrescu 			cmd_link_show(tokens, n_tokens, out, out_size, obj);
30905074e1d5SCristian Dumitrescu 			return;
30915074e1d5SCristian Dumitrescu 		}
30925074e1d5SCristian Dumitrescu 
30935074e1d5SCristian Dumitrescu 		cmd_link(tokens, n_tokens, out, out_size, obj);
30945074e1d5SCristian Dumitrescu 		return;
30955074e1d5SCristian Dumitrescu 	}
30965074e1d5SCristian Dumitrescu 
309777a41301SCristian Dumitrescu 	if (strcmp(tokens[0], "ring") == 0) {
309877a41301SCristian Dumitrescu 		cmd_ring(tokens, n_tokens, out, out_size, obj);
309977a41301SCristian Dumitrescu 		return;
310077a41301SCristian Dumitrescu 	}
310177a41301SCristian Dumitrescu 
3102e2b8dc52SVenkata Suresh Kumar P 	if (strcmp(tokens[0], "tap") == 0) {
3103e2b8dc52SVenkata Suresh Kumar P 		cmd_tap(tokens, n_tokens, out, out_size, obj);
3104e2b8dc52SVenkata Suresh Kumar P 		return;
3105e2b8dc52SVenkata Suresh Kumar P 	}
3106e2b8dc52SVenkata Suresh Kumar P 
31075074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "pipeline") == 0) {
31085074e1d5SCristian Dumitrescu 		if ((n_tokens >= 3) &&
31095074e1d5SCristian Dumitrescu 			(strcmp(tokens[2], "create") == 0)) {
31105074e1d5SCristian Dumitrescu 			cmd_pipeline_create(tokens, n_tokens, out, out_size,
31115074e1d5SCristian Dumitrescu 				obj);
31125074e1d5SCristian Dumitrescu 			return;
31135074e1d5SCristian Dumitrescu 		}
31145074e1d5SCristian Dumitrescu 
31155074e1d5SCristian Dumitrescu 		if ((n_tokens >= 4) &&
31165074e1d5SCristian Dumitrescu 			(strcmp(tokens[2], "port") == 0) &&
31175074e1d5SCristian Dumitrescu 			(strcmp(tokens[3], "in") == 0)) {
31185074e1d5SCristian Dumitrescu 			cmd_pipeline_port_in(tokens, n_tokens, out, out_size,
31195074e1d5SCristian Dumitrescu 				obj);
31205074e1d5SCristian Dumitrescu 			return;
31215074e1d5SCristian Dumitrescu 		}
31225074e1d5SCristian Dumitrescu 
31235074e1d5SCristian Dumitrescu 		if ((n_tokens >= 4) &&
31245074e1d5SCristian Dumitrescu 			(strcmp(tokens[2], "port") == 0) &&
31255074e1d5SCristian Dumitrescu 			(strcmp(tokens[3], "out") == 0)) {
31265074e1d5SCristian Dumitrescu 			cmd_pipeline_port_out(tokens, n_tokens, out, out_size,
31275074e1d5SCristian Dumitrescu 				obj);
31285074e1d5SCristian Dumitrescu 			return;
31295074e1d5SCristian Dumitrescu 		}
31305074e1d5SCristian Dumitrescu 
31315074e1d5SCristian Dumitrescu 		if ((n_tokens >= 3) &&
31325074e1d5SCristian Dumitrescu 			(strcmp(tokens[2], "build") == 0)) {
31335074e1d5SCristian Dumitrescu 			cmd_pipeline_build(tokens, n_tokens, out, out_size,
31345074e1d5SCristian Dumitrescu 				obj);
31355074e1d5SCristian Dumitrescu 			return;
31365074e1d5SCristian Dumitrescu 		}
31375074e1d5SCristian Dumitrescu 
313875129cebSChurchill Khangar 		if ((n_tokens >= 5) &&
313975129cebSChurchill Khangar 			(strcmp(tokens[2], "table") == 0) &&
314075129cebSChurchill Khangar 			(strcmp(tokens[4], "add") == 0)) {
314175129cebSChurchill Khangar 			cmd_pipeline_table_add(tokens, n_tokens, out,
314275129cebSChurchill Khangar 				out_size, obj);
314375129cebSChurchill Khangar 			return;
314475129cebSChurchill Khangar 		}
314575129cebSChurchill Khangar 
314675129cebSChurchill Khangar 		if ((n_tokens >= 5) &&
314775129cebSChurchill Khangar 			(strcmp(tokens[2], "table") == 0) &&
314875129cebSChurchill Khangar 			(strcmp(tokens[4], "delete") == 0)) {
314975129cebSChurchill Khangar 			cmd_pipeline_table_delete(tokens, n_tokens, out,
315075129cebSChurchill Khangar 				out_size, obj);
315175129cebSChurchill Khangar 			return;
315275129cebSChurchill Khangar 		}
315375129cebSChurchill Khangar 
315475129cebSChurchill Khangar 		if ((n_tokens >= 5) &&
315575129cebSChurchill Khangar 			(strcmp(tokens[2], "table") == 0) &&
315675129cebSChurchill Khangar 			(strcmp(tokens[4], "default") == 0)) {
315775129cebSChurchill Khangar 			cmd_pipeline_table_default(tokens, n_tokens, out,
315875129cebSChurchill Khangar 				out_size, obj);
315975129cebSChurchill Khangar 			return;
316075129cebSChurchill Khangar 		}
316175129cebSChurchill Khangar 
316275129cebSChurchill Khangar 		if ((n_tokens >= 5) &&
316375129cebSChurchill Khangar 			(strcmp(tokens[2], "table") == 0) &&
316475129cebSChurchill Khangar 			(strcmp(tokens[4], "show") == 0)) {
316575129cebSChurchill Khangar 			cmd_pipeline_table_show(tokens, n_tokens, out,
316675129cebSChurchill Khangar 				out_size, obj);
316775129cebSChurchill Khangar 			return;
316875129cebSChurchill Khangar 		}
316975129cebSChurchill Khangar 
3170598fe0ddSCristian Dumitrescu 		if ((n_tokens >= 6) &&
3171598fe0ddSCristian Dumitrescu 			(strcmp(tokens[2], "selector") == 0) &&
3172598fe0ddSCristian Dumitrescu 			(strcmp(tokens[4], "group") == 0) &&
3173598fe0ddSCristian Dumitrescu 			(strcmp(tokens[5], "add") == 0)) {
3174598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_add(tokens, n_tokens, out,
3175598fe0ddSCristian Dumitrescu 				out_size, obj);
3176598fe0ddSCristian Dumitrescu 			return;
3177598fe0ddSCristian Dumitrescu 		}
3178598fe0ddSCristian Dumitrescu 
3179598fe0ddSCristian Dumitrescu 		if ((n_tokens >= 6) &&
3180598fe0ddSCristian Dumitrescu 			(strcmp(tokens[2], "selector") == 0) &&
3181598fe0ddSCristian Dumitrescu 			(strcmp(tokens[4], "group") == 0) &&
3182598fe0ddSCristian Dumitrescu 			(strcmp(tokens[5], "delete") == 0)) {
3183598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_delete(tokens, n_tokens, out,
3184598fe0ddSCristian Dumitrescu 				out_size, obj);
3185598fe0ddSCristian Dumitrescu 			return;
3186598fe0ddSCristian Dumitrescu 		}
3187598fe0ddSCristian Dumitrescu 
3188598fe0ddSCristian Dumitrescu 		if ((n_tokens >= 7) &&
3189598fe0ddSCristian Dumitrescu 			(strcmp(tokens[2], "selector") == 0) &&
3190598fe0ddSCristian Dumitrescu 			(strcmp(tokens[4], "group") == 0) &&
3191598fe0ddSCristian Dumitrescu 			(strcmp(tokens[5], "member") == 0) &&
3192598fe0ddSCristian Dumitrescu 			(strcmp(tokens[6], "add") == 0)) {
3193598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_member_add(tokens, n_tokens, out,
3194598fe0ddSCristian Dumitrescu 				out_size, obj);
3195598fe0ddSCristian Dumitrescu 			return;
3196598fe0ddSCristian Dumitrescu 		}
3197598fe0ddSCristian Dumitrescu 
3198598fe0ddSCristian Dumitrescu 		if ((n_tokens >= 7) &&
3199598fe0ddSCristian Dumitrescu 			(strcmp(tokens[2], "selector") == 0) &&
3200598fe0ddSCristian Dumitrescu 			(strcmp(tokens[4], "group") == 0) &&
3201598fe0ddSCristian Dumitrescu 			(strcmp(tokens[5], "member") == 0) &&
3202598fe0ddSCristian Dumitrescu 			(strcmp(tokens[6], "delete") == 0)) {
3203598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_group_member_delete(tokens, n_tokens, out,
3204598fe0ddSCristian Dumitrescu 				out_size, obj);
3205598fe0ddSCristian Dumitrescu 			return;
3206598fe0ddSCristian Dumitrescu 		}
3207598fe0ddSCristian Dumitrescu 
3208598fe0ddSCristian Dumitrescu 		if ((n_tokens >= 5) &&
3209598fe0ddSCristian Dumitrescu 			(strcmp(tokens[2], "selector") == 0) &&
3210598fe0ddSCristian Dumitrescu 			(strcmp(tokens[4], "show") == 0)) {
3211598fe0ddSCristian Dumitrescu 			cmd_pipeline_selector_show(tokens, n_tokens, out,
3212598fe0ddSCristian Dumitrescu 				out_size, obj);
3213598fe0ddSCristian Dumitrescu 			return;
3214598fe0ddSCristian Dumitrescu 		}
3215598fe0ddSCristian Dumitrescu 
32168bd4862fSCristian Dumitrescu 		if ((n_tokens >= 5) &&
32178bd4862fSCristian Dumitrescu 			(strcmp(tokens[2], "learner") == 0) &&
32188bd4862fSCristian Dumitrescu 			(strcmp(tokens[4], "default") == 0)) {
32198bd4862fSCristian Dumitrescu 			cmd_pipeline_learner_default(tokens, n_tokens, out,
32208bd4862fSCristian Dumitrescu 				out_size, obj);
32218bd4862fSCristian Dumitrescu 			return;
32228bd4862fSCristian Dumitrescu 		}
32238bd4862fSCristian Dumitrescu 
32245074e1d5SCristian Dumitrescu 		if ((n_tokens >= 3) &&
322575129cebSChurchill Khangar 			(strcmp(tokens[2], "commit") == 0)) {
322675129cebSChurchill Khangar 			cmd_pipeline_commit(tokens, n_tokens, out,
322775129cebSChurchill Khangar 				out_size, obj);
322875129cebSChurchill Khangar 			return;
322975129cebSChurchill Khangar 		}
323075129cebSChurchill Khangar 
323175129cebSChurchill Khangar 		if ((n_tokens >= 3) &&
323275129cebSChurchill Khangar 			(strcmp(tokens[2], "abort") == 0)) {
323375129cebSChurchill Khangar 			cmd_pipeline_abort(tokens, n_tokens, out,
32345074e1d5SCristian Dumitrescu 				out_size, obj);
32355074e1d5SCristian Dumitrescu 			return;
32365074e1d5SCristian Dumitrescu 		}
32375074e1d5SCristian Dumitrescu 
32385074e1d5SCristian Dumitrescu 		if ((n_tokens >= 3) &&
323964cfcebdSCristian Dumitrescu 			(strcmp(tokens[2], "regrd") == 0)) {
324064cfcebdSCristian Dumitrescu 			cmd_pipeline_regrd(tokens, n_tokens, out, out_size, obj);
324164cfcebdSCristian Dumitrescu 			return;
324264cfcebdSCristian Dumitrescu 		}
324364cfcebdSCristian Dumitrescu 
324464cfcebdSCristian Dumitrescu 		if ((n_tokens >= 3) &&
324564cfcebdSCristian Dumitrescu 			(strcmp(tokens[2], "regwr") == 0)) {
324664cfcebdSCristian Dumitrescu 			cmd_pipeline_regwr(tokens, n_tokens, out, out_size, obj);
324764cfcebdSCristian Dumitrescu 			return;
324864cfcebdSCristian Dumitrescu 		}
324964cfcebdSCristian Dumitrescu 
3250f38913b7SCristian Dumitrescu 		if ((n_tokens >= 6) &&
3251f38913b7SCristian Dumitrescu 			(strcmp(tokens[2], "meter") == 0) &&
3252f38913b7SCristian Dumitrescu 			(strcmp(tokens[3], "profile") == 0) &&
3253f38913b7SCristian Dumitrescu 			(strcmp(tokens[5], "add") == 0)) {
3254f38913b7SCristian Dumitrescu 			cmd_pipeline_meter_profile_add(tokens, n_tokens, out, out_size, obj);
3255f38913b7SCristian Dumitrescu 			return;
3256f38913b7SCristian Dumitrescu 		}
3257f38913b7SCristian Dumitrescu 
3258f38913b7SCristian Dumitrescu 		if ((n_tokens >= 6) &&
3259f38913b7SCristian Dumitrescu 			(strcmp(tokens[2], "meter") == 0) &&
3260f38913b7SCristian Dumitrescu 			(strcmp(tokens[3], "profile") == 0) &&
3261f38913b7SCristian Dumitrescu 			(strcmp(tokens[5], "delete") == 0)) {
3262f38913b7SCristian Dumitrescu 			cmd_pipeline_meter_profile_delete(tokens, n_tokens, out, out_size, obj);
3263f38913b7SCristian Dumitrescu 			return;
3264f38913b7SCristian Dumitrescu 		}
3265f38913b7SCristian Dumitrescu 
3266f38913b7SCristian Dumitrescu 		if ((n_tokens >= 9) &&
3267f38913b7SCristian Dumitrescu 			(strcmp(tokens[2], "meter") == 0) &&
3268f38913b7SCristian Dumitrescu 			(strcmp(tokens[8], "reset") == 0)) {
3269f38913b7SCristian Dumitrescu 			cmd_pipeline_meter_reset(tokens, n_tokens, out, out_size, obj);
3270f38913b7SCristian Dumitrescu 			return;
3271f38913b7SCristian Dumitrescu 		}
3272f38913b7SCristian Dumitrescu 
3273f38913b7SCristian Dumitrescu 		if ((n_tokens >= 9) &&
3274f38913b7SCristian Dumitrescu 			(strcmp(tokens[2], "meter") == 0) &&
3275f38913b7SCristian Dumitrescu 			(strcmp(tokens[8], "set") == 0)) {
3276f38913b7SCristian Dumitrescu 			cmd_pipeline_meter_set(tokens, n_tokens, out, out_size, obj);
3277f38913b7SCristian Dumitrescu 			return;
3278f38913b7SCristian Dumitrescu 		}
3279f38913b7SCristian Dumitrescu 
3280f38913b7SCristian Dumitrescu 		if ((n_tokens >= 9) &&
3281f38913b7SCristian Dumitrescu 			(strcmp(tokens[2], "meter") == 0) &&
3282f38913b7SCristian Dumitrescu 			(strcmp(tokens[8], "stats") == 0)) {
3283f38913b7SCristian Dumitrescu 			cmd_pipeline_meter_stats(tokens, n_tokens, out, out_size, obj);
3284f38913b7SCristian Dumitrescu 			return;
3285f38913b7SCristian Dumitrescu 		}
3286f38913b7SCristian Dumitrescu 
328764cfcebdSCristian Dumitrescu 		if ((n_tokens >= 3) &&
32885074e1d5SCristian Dumitrescu 			(strcmp(tokens[2], "stats") == 0)) {
32895074e1d5SCristian Dumitrescu 			cmd_pipeline_stats(tokens, n_tokens, out, out_size,
32905074e1d5SCristian Dumitrescu 				obj);
32915074e1d5SCristian Dumitrescu 			return;
32925074e1d5SCristian Dumitrescu 		}
32935074e1d5SCristian Dumitrescu 	}
32945074e1d5SCristian Dumitrescu 
32955074e1d5SCristian Dumitrescu 	if (strcmp(tokens[0], "thread") == 0) {
32965074e1d5SCristian Dumitrescu 		if ((n_tokens >= 5) &&
32975074e1d5SCristian Dumitrescu 			(strcmp(tokens[4], "enable") == 0)) {
32985074e1d5SCristian Dumitrescu 			cmd_thread_pipeline_enable(tokens, n_tokens,
32995074e1d5SCristian Dumitrescu 				out, out_size, obj);
33005074e1d5SCristian Dumitrescu 			return;
33015074e1d5SCristian Dumitrescu 		}
33025074e1d5SCristian Dumitrescu 
33035074e1d5SCristian Dumitrescu 		if ((n_tokens >= 5) &&
33045074e1d5SCristian Dumitrescu 			(strcmp(tokens[4], "disable") == 0)) {
33055074e1d5SCristian Dumitrescu 			cmd_thread_pipeline_disable(tokens, n_tokens,
33065074e1d5SCristian Dumitrescu 				out, out_size, obj);
33075074e1d5SCristian Dumitrescu 			return;
33085074e1d5SCristian Dumitrescu 		}
33095074e1d5SCristian Dumitrescu 	}
33105074e1d5SCristian Dumitrescu 
33115074e1d5SCristian Dumitrescu 	snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
33125074e1d5SCristian Dumitrescu }
33135074e1d5SCristian Dumitrescu 
33145074e1d5SCristian Dumitrescu int
33155074e1d5SCristian Dumitrescu cli_script_process(const char *file_name,
33165074e1d5SCristian Dumitrescu 	size_t msg_in_len_max,
33175074e1d5SCristian Dumitrescu 	size_t msg_out_len_max,
33185074e1d5SCristian Dumitrescu 	void *obj)
33195074e1d5SCristian Dumitrescu {
33205074e1d5SCristian Dumitrescu 	char *msg_in = NULL, *msg_out = NULL;
33215074e1d5SCristian Dumitrescu 	FILE *f = NULL;
33225074e1d5SCristian Dumitrescu 
33235074e1d5SCristian Dumitrescu 	/* Check input arguments */
33245074e1d5SCristian Dumitrescu 	if ((file_name == NULL) ||
33255074e1d5SCristian Dumitrescu 		(strlen(file_name) == 0) ||
33265074e1d5SCristian Dumitrescu 		(msg_in_len_max == 0) ||
33275074e1d5SCristian Dumitrescu 		(msg_out_len_max == 0))
33285074e1d5SCristian Dumitrescu 		return -EINVAL;
33295074e1d5SCristian Dumitrescu 
33305074e1d5SCristian Dumitrescu 	msg_in = malloc(msg_in_len_max + 1);
33315074e1d5SCristian Dumitrescu 	msg_out = malloc(msg_out_len_max + 1);
33325074e1d5SCristian Dumitrescu 	if ((msg_in == NULL) ||
33335074e1d5SCristian Dumitrescu 		(msg_out == NULL)) {
33345074e1d5SCristian Dumitrescu 		free(msg_out);
33355074e1d5SCristian Dumitrescu 		free(msg_in);
33365074e1d5SCristian Dumitrescu 		return -ENOMEM;
33375074e1d5SCristian Dumitrescu 	}
33385074e1d5SCristian Dumitrescu 
33395074e1d5SCristian Dumitrescu 	/* Open input file */
33405074e1d5SCristian Dumitrescu 	f = fopen(file_name, "r");
33415074e1d5SCristian Dumitrescu 	if (f == NULL) {
33425074e1d5SCristian Dumitrescu 		free(msg_out);
33435074e1d5SCristian Dumitrescu 		free(msg_in);
33445074e1d5SCristian Dumitrescu 		return -EIO;
33455074e1d5SCristian Dumitrescu 	}
33465074e1d5SCristian Dumitrescu 
33475074e1d5SCristian Dumitrescu 	/* Read file */
33485074e1d5SCristian Dumitrescu 	for ( ; ; ) {
33495074e1d5SCristian Dumitrescu 		if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
33505074e1d5SCristian Dumitrescu 			break;
33515074e1d5SCristian Dumitrescu 
33525074e1d5SCristian Dumitrescu 		printf("%s", msg_in);
33535074e1d5SCristian Dumitrescu 		msg_out[0] = 0;
33545074e1d5SCristian Dumitrescu 
33555074e1d5SCristian Dumitrescu 		cli_process(msg_in,
33565074e1d5SCristian Dumitrescu 			msg_out,
33575074e1d5SCristian Dumitrescu 			msg_out_len_max,
33585074e1d5SCristian Dumitrescu 			obj);
33595074e1d5SCristian Dumitrescu 
33605074e1d5SCristian Dumitrescu 		if (strlen(msg_out))
33615074e1d5SCristian Dumitrescu 			printf("%s", msg_out);
33625074e1d5SCristian Dumitrescu 	}
33635074e1d5SCristian Dumitrescu 
33645074e1d5SCristian Dumitrescu 	/* Close file */
33655074e1d5SCristian Dumitrescu 	fclose(f);
33665074e1d5SCristian Dumitrescu 	free(msg_out);
33675074e1d5SCristian Dumitrescu 	free(msg_in);
33685074e1d5SCristian Dumitrescu 	return 0;
33695074e1d5SCristian Dumitrescu }
3370