xref: /dpdk/examples/ip_pipeline/cli.c (revision 06c047b6)
14bbf8e30SJasvinder Singh /* SPDX-License-Identifier: BSD-3-Clause
24bbf8e30SJasvinder Singh  * Copyright(c) 2010-2018 Intel Corporation
34bbf8e30SJasvinder Singh  */
44bbf8e30SJasvinder Singh 
54bbf8e30SJasvinder Singh #include <stdio.h>
64bbf8e30SJasvinder Singh #include <stdint.h>
74bbf8e30SJasvinder Singh #include <stdlib.h>
84bbf8e30SJasvinder Singh #include <string.h>
94bbf8e30SJasvinder Singh 
104bbf8e30SJasvinder Singh #include <rte_common.h>
11a3a95b7dSJasvinder Singh #include <rte_cycles.h>
12ecfc2b1cSKevin Laatz #include <rte_ethdev.h>
134bbf8e30SJasvinder Singh 
144bbf8e30SJasvinder Singh #include "cli.h"
151edccebcSFan Zhang 
161edccebcSFan Zhang #include "cryptodev.h"
179a408cc8SJasvinder Singh #include "kni.h"
18133c2c65SJasvinder Singh #include "link.h"
196bfe74f8SJasvinder Singh #include "mempool.h"
206bfe74f8SJasvinder Singh #include "parser.h"
21d75c371eSJasvinder Singh #include "pipeline.h"
228245472cSJasvinder Singh #include "swq.h"
232f74ae28SJasvinder Singh #include "tap.h"
2432e5d9b1SJasvinder Singh #include "thread.h"
2525961ff3SJasvinder Singh #include "tmgr.h"
266bfe74f8SJasvinder Singh 
276bfe74f8SJasvinder Singh #ifndef CMD_MAX_TOKENS
286bfe74f8SJasvinder Singh #define CMD_MAX_TOKENS     256
296bfe74f8SJasvinder Singh #endif
306bfe74f8SJasvinder Singh 
316bfe74f8SJasvinder Singh #define MSG_OUT_OF_MEMORY   "Not enough memory.\n"
326bfe74f8SJasvinder Singh #define MSG_CMD_UNKNOWN     "Unknown command \"%s\".\n"
336bfe74f8SJasvinder Singh #define MSG_CMD_UNIMPLEM    "Command \"%s\" not implemented.\n"
346bfe74f8SJasvinder Singh #define MSG_ARG_NOT_ENOUGH  "Not enough arguments for command \"%s\".\n"
356bfe74f8SJasvinder Singh #define MSG_ARG_TOO_MANY    "Too many arguments for command \"%s\".\n"
366bfe74f8SJasvinder Singh #define MSG_ARG_MISMATCH    "Wrong number of arguments for command \"%s\".\n"
376bfe74f8SJasvinder Singh #define MSG_ARG_NOT_FOUND   "Argument \"%s\" not found.\n"
386bfe74f8SJasvinder Singh #define MSG_ARG_INVALID     "Invalid value for argument \"%s\".\n"
396bfe74f8SJasvinder Singh #define MSG_FILE_ERR        "Error in file \"%s\" at line %u.\n"
403186282fSJasvinder Singh #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
416bfe74f8SJasvinder Singh #define MSG_CMD_FAIL        "Command \"%s\" failed.\n"
424bbf8e30SJasvinder Singh 
434bbf8e30SJasvinder Singh static int
is_comment(char * in)444bbf8e30SJasvinder Singh is_comment(char *in)
454bbf8e30SJasvinder Singh {
464bbf8e30SJasvinder Singh 	if ((strlen(in) && index("!#%;", in[0])) ||
474bbf8e30SJasvinder Singh 		(strncmp(in, "//", 2) == 0) ||
484bbf8e30SJasvinder Singh 		(strncmp(in, "--", 2) == 0))
494bbf8e30SJasvinder Singh 		return 1;
504bbf8e30SJasvinder Singh 
514bbf8e30SJasvinder Singh 	return 0;
524bbf8e30SJasvinder Singh }
534bbf8e30SJasvinder Singh 
5426b3effeSKevin Laatz static const char cmd_mempool_help[] =
5526b3effeSKevin Laatz "mempool <mempool_name>\n"
5626b3effeSKevin Laatz "   buffer <buffer_size>\n"
5726b3effeSKevin Laatz "   pool <pool_size>\n"
5826b3effeSKevin Laatz "   cache <cache_size>\n"
5926b3effeSKevin Laatz "   cpu <cpu_id>\n";
6026b3effeSKevin Laatz 
616bfe74f8SJasvinder Singh static void
cmd_mempool(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)626bfe74f8SJasvinder Singh cmd_mempool(char **tokens,
636bfe74f8SJasvinder Singh 	uint32_t n_tokens,
646bfe74f8SJasvinder Singh 	char *out,
656bfe74f8SJasvinder Singh 	size_t out_size)
664bbf8e30SJasvinder Singh {
676bfe74f8SJasvinder Singh 	struct mempool_params p;
686bfe74f8SJasvinder Singh 	char *name;
696bfe74f8SJasvinder Singh 	struct mempool *mempool;
706bfe74f8SJasvinder Singh 
716bfe74f8SJasvinder Singh 	if (n_tokens != 10) {
726bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
736bfe74f8SJasvinder Singh 		return;
746bfe74f8SJasvinder Singh 	}
756bfe74f8SJasvinder Singh 
766bfe74f8SJasvinder Singh 	name = tokens[1];
776bfe74f8SJasvinder Singh 
786bfe74f8SJasvinder Singh 	if (strcmp(tokens[2], "buffer") != 0) {
796bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
806bfe74f8SJasvinder Singh 		return;
816bfe74f8SJasvinder Singh 	}
826bfe74f8SJasvinder Singh 
836bfe74f8SJasvinder Singh 	if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
846bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
856bfe74f8SJasvinder Singh 		return;
866bfe74f8SJasvinder Singh 	}
876bfe74f8SJasvinder Singh 
886bfe74f8SJasvinder Singh 	if (strcmp(tokens[4], "pool") != 0) {
896bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
906bfe74f8SJasvinder Singh 		return;
916bfe74f8SJasvinder Singh 	}
926bfe74f8SJasvinder Singh 
936bfe74f8SJasvinder Singh 	if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
946bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
956bfe74f8SJasvinder Singh 		return;
966bfe74f8SJasvinder Singh 	}
976bfe74f8SJasvinder Singh 
986bfe74f8SJasvinder Singh 	if (strcmp(tokens[6], "cache") != 0) {
996bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
1006bfe74f8SJasvinder Singh 		return;
1016bfe74f8SJasvinder Singh 	}
1026bfe74f8SJasvinder Singh 
1036bfe74f8SJasvinder Singh 	if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
1046bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
1056bfe74f8SJasvinder Singh 		return;
1066bfe74f8SJasvinder Singh 	}
1076bfe74f8SJasvinder Singh 
1086bfe74f8SJasvinder Singh 	if (strcmp(tokens[8], "cpu") != 0) {
1096bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1106bfe74f8SJasvinder Singh 		return;
1116bfe74f8SJasvinder Singh 	}
1126bfe74f8SJasvinder Singh 
1136bfe74f8SJasvinder Singh 	if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
1146bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1156bfe74f8SJasvinder Singh 		return;
1166bfe74f8SJasvinder Singh 	}
1176bfe74f8SJasvinder Singh 
1186bfe74f8SJasvinder Singh 	mempool = mempool_create(name, &p);
1196bfe74f8SJasvinder Singh 	if (mempool == NULL) {
1206bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1216bfe74f8SJasvinder Singh 		return;
1226bfe74f8SJasvinder Singh 	}
1236bfe74f8SJasvinder Singh }
1246bfe74f8SJasvinder Singh 
12526b3effeSKevin Laatz static const char cmd_link_help[] =
12626b3effeSKevin Laatz "link <link_name>\n"
12726b3effeSKevin Laatz "   dev <device_name> | port <port_id>\n"
12826b3effeSKevin Laatz "   rxq <n_queues> <queue_size> <mempool_name>\n"
12926b3effeSKevin Laatz "   txq <n_queues> <queue_size>\n"
13026b3effeSKevin Laatz "   promiscuous on | off\n"
13126b3effeSKevin Laatz "   [rss <qid_0> ... <qid_n>]\n";
13226b3effeSKevin Laatz 
133133c2c65SJasvinder Singh static void
cmd_link(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)134133c2c65SJasvinder Singh cmd_link(char **tokens,
135133c2c65SJasvinder Singh 	uint32_t n_tokens,
136133c2c65SJasvinder Singh 	char *out,
137133c2c65SJasvinder Singh 	size_t out_size)
138133c2c65SJasvinder Singh {
139133c2c65SJasvinder Singh 	struct link_params p;
140133c2c65SJasvinder Singh 	struct link_params_rss rss;
141133c2c65SJasvinder Singh 	struct link *link;
142133c2c65SJasvinder Singh 	char *name;
143133c2c65SJasvinder Singh 
14484a27d89SFan Zhang 	memset(&p, 0, sizeof(p));
14584a27d89SFan Zhang 
146133c2c65SJasvinder Singh 	if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
147133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
148133c2c65SJasvinder Singh 		return;
149133c2c65SJasvinder Singh 	}
150133c2c65SJasvinder Singh 	name = tokens[1];
151133c2c65SJasvinder Singh 
152133c2c65SJasvinder Singh 	if (strcmp(tokens[2], "dev") == 0)
153133c2c65SJasvinder Singh 		p.dev_name = tokens[3];
154133c2c65SJasvinder Singh 	else if (strcmp(tokens[2], "port") == 0) {
155133c2c65SJasvinder Singh 		p.dev_name = NULL;
156133c2c65SJasvinder Singh 
157133c2c65SJasvinder Singh 		if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
158133c2c65SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
159133c2c65SJasvinder Singh 			return;
160133c2c65SJasvinder Singh 		}
161133c2c65SJasvinder Singh 	} else {
162133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
163133c2c65SJasvinder Singh 		return;
164133c2c65SJasvinder Singh 	}
165133c2c65SJasvinder Singh 
166133c2c65SJasvinder Singh 	if (strcmp(tokens[4], "rxq") != 0) {
167133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
168133c2c65SJasvinder Singh 		return;
169133c2c65SJasvinder Singh 	}
170133c2c65SJasvinder Singh 
171133c2c65SJasvinder Singh 	if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
172133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
173133c2c65SJasvinder Singh 		return;
174133c2c65SJasvinder Singh 	}
175133c2c65SJasvinder Singh 	if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
176133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
177133c2c65SJasvinder Singh 		return;
178133c2c65SJasvinder Singh 	}
179133c2c65SJasvinder Singh 
180133c2c65SJasvinder Singh 	p.rx.mempool_name = tokens[7];
181133c2c65SJasvinder Singh 
182133c2c65SJasvinder Singh 	if (strcmp(tokens[8], "txq") != 0) {
183133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
184133c2c65SJasvinder Singh 		return;
185133c2c65SJasvinder Singh 	}
186133c2c65SJasvinder Singh 
187133c2c65SJasvinder Singh 	if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
188133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
189133c2c65SJasvinder Singh 		return;
190133c2c65SJasvinder Singh 	}
191133c2c65SJasvinder Singh 
192133c2c65SJasvinder Singh 	if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
193133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
194133c2c65SJasvinder Singh 		return;
195133c2c65SJasvinder Singh 	}
196133c2c65SJasvinder Singh 
197133c2c65SJasvinder Singh 	if (strcmp(tokens[11], "promiscuous") != 0) {
198133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
199133c2c65SJasvinder Singh 		return;
200133c2c65SJasvinder Singh 	}
201133c2c65SJasvinder Singh 
202133c2c65SJasvinder Singh 	if (strcmp(tokens[12], "on") == 0)
203133c2c65SJasvinder Singh 		p.promiscuous = 1;
204133c2c65SJasvinder Singh 	else if (strcmp(tokens[12], "off") == 0)
205133c2c65SJasvinder Singh 		p.promiscuous = 0;
206133c2c65SJasvinder Singh 	else {
207133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
208133c2c65SJasvinder Singh 		return;
209133c2c65SJasvinder Singh 	}
210133c2c65SJasvinder Singh 
211133c2c65SJasvinder Singh 	/* RSS */
212133c2c65SJasvinder Singh 	p.rx.rss = NULL;
213133c2c65SJasvinder Singh 	if (n_tokens > 13) {
214133c2c65SJasvinder Singh 		uint32_t queue_id, i;
215133c2c65SJasvinder Singh 
216133c2c65SJasvinder Singh 		if (strcmp(tokens[13], "rss") != 0) {
217133c2c65SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
218133c2c65SJasvinder Singh 			return;
219133c2c65SJasvinder Singh 		}
220133c2c65SJasvinder Singh 
221133c2c65SJasvinder Singh 		p.rx.rss = &rss;
222133c2c65SJasvinder Singh 
223133c2c65SJasvinder Singh 		rss.n_queues = 0;
224133c2c65SJasvinder Singh 		for (i = 14; i < n_tokens; i++) {
225133c2c65SJasvinder Singh 			if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
226133c2c65SJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
227133c2c65SJasvinder Singh 					"queue_id");
228133c2c65SJasvinder Singh 				return;
229133c2c65SJasvinder Singh 			}
230133c2c65SJasvinder Singh 
231133c2c65SJasvinder Singh 			rss.queue_id[rss.n_queues] = queue_id;
232133c2c65SJasvinder Singh 			rss.n_queues++;
233133c2c65SJasvinder Singh 		}
234133c2c65SJasvinder Singh 	}
235133c2c65SJasvinder Singh 
236133c2c65SJasvinder Singh 	link = link_create(name, &p);
237133c2c65SJasvinder Singh 	if (link == NULL) {
238133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
239133c2c65SJasvinder Singh 		return;
240133c2c65SJasvinder Singh 	}
241133c2c65SJasvinder Singh }
242133c2c65SJasvinder Singh 
243ecfc2b1cSKevin Laatz /* Print the link stats and info */
244ecfc2b1cSKevin Laatz static void
print_link_info(struct link * link,char * out,size_t out_size)245ecfc2b1cSKevin Laatz print_link_info(struct link *link, char *out, size_t out_size)
246ecfc2b1cSKevin Laatz {
247ecfc2b1cSKevin Laatz 	struct rte_eth_stats stats;
2486d13ea8eSOlivier Matz 	struct rte_ether_addr mac_addr;
249ecfc2b1cSKevin Laatz 	struct rte_eth_link eth_link;
250ecfc2b1cSKevin Laatz 	uint16_t mtu;
25122e5c73bSIgor Romanov 	int ret;
252ecfc2b1cSKevin Laatz 
253ecfc2b1cSKevin Laatz 	memset(&stats, 0, sizeof(stats));
254ecfc2b1cSKevin Laatz 	rte_eth_stats_get(link->port_id, &stats);
255ecfc2b1cSKevin Laatz 
25670febdcfSIgor Romanov 	ret = rte_eth_macaddr_get(link->port_id, &mac_addr);
25770febdcfSIgor Romanov 	if (ret != 0) {
25870febdcfSIgor Romanov 		snprintf(out, out_size, "\n%s: MAC address get failed: %s",
25970febdcfSIgor Romanov 			 link->name, rte_strerror(-ret));
26070febdcfSIgor Romanov 		return;
26170febdcfSIgor Romanov 	}
26270febdcfSIgor Romanov 
26322e5c73bSIgor Romanov 	ret = rte_eth_link_get(link->port_id, &eth_link);
26422e5c73bSIgor Romanov 	if (ret < 0) {
26522e5c73bSIgor Romanov 		snprintf(out, out_size, "\n%s: link get failed: %s",
26622e5c73bSIgor Romanov 			 link->name, rte_strerror(-ret));
26722e5c73bSIgor Romanov 		return;
26822e5c73bSIgor Romanov 	}
26922e5c73bSIgor Romanov 
270ecfc2b1cSKevin Laatz 	rte_eth_dev_get_mtu(link->port_id, &mtu);
271ecfc2b1cSKevin Laatz 
272ecfc2b1cSKevin Laatz 	snprintf(out, out_size,
273ecfc2b1cSKevin Laatz 		"\n"
274ecfc2b1cSKevin Laatz 		"%s: flags=<%s> mtu %u\n"
275c2c4f87bSAman Deep Singh 		"\tether " RTE_ETHER_ADDR_PRT_FMT " rxqueues %u txqueues %u\n"
276db4e8135SIvan Dyukov 		"\tport# %u  speed %s\n"
277ecfc2b1cSKevin Laatz 		"\tRX packets %" PRIu64"  bytes %" PRIu64"\n"
278ecfc2b1cSKevin Laatz 		"\tRX errors %" PRIu64"  missed %" PRIu64"  no-mbuf %" PRIu64"\n"
279ecfc2b1cSKevin Laatz 		"\tTX packets %" PRIu64"  bytes %" PRIu64"\n"
280ecfc2b1cSKevin Laatz 		"\tTX errors %" PRIu64"\n",
281ecfc2b1cSKevin Laatz 		link->name,
282ecfc2b1cSKevin Laatz 		eth_link.link_status == 0 ? "DOWN" : "UP",
283ecfc2b1cSKevin Laatz 		mtu,
284*a7db3afcSAman Deep Singh 		RTE_ETHER_ADDR_BYTES(&mac_addr),
285ecfc2b1cSKevin Laatz 		link->n_rxq,
286ecfc2b1cSKevin Laatz 		link->n_txq,
287ecfc2b1cSKevin Laatz 		link->port_id,
288db4e8135SIvan Dyukov 		rte_eth_link_speed_to_str(eth_link.link_speed),
289ecfc2b1cSKevin Laatz 		stats.ipackets,
290ecfc2b1cSKevin Laatz 		stats.ibytes,
291ecfc2b1cSKevin Laatz 		stats.ierrors,
292ecfc2b1cSKevin Laatz 		stats.imissed,
293ecfc2b1cSKevin Laatz 		stats.rx_nombuf,
294ecfc2b1cSKevin Laatz 		stats.opackets,
295ecfc2b1cSKevin Laatz 		stats.obytes,
296ecfc2b1cSKevin Laatz 		stats.oerrors);
297ecfc2b1cSKevin Laatz }
298ecfc2b1cSKevin Laatz 
299ecfc2b1cSKevin Laatz /*
300ecfc2b1cSKevin Laatz  * link show [<link_name>]
301ecfc2b1cSKevin Laatz  */
302ecfc2b1cSKevin Laatz static void
cmd_link_show(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)303ecfc2b1cSKevin Laatz cmd_link_show(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
304ecfc2b1cSKevin Laatz {
305ecfc2b1cSKevin Laatz 	struct link *link;
306ecfc2b1cSKevin Laatz 	char *link_name;
307ecfc2b1cSKevin Laatz 
308ecfc2b1cSKevin Laatz 	if (n_tokens != 2 && n_tokens != 3) {
309ecfc2b1cSKevin Laatz 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
310ecfc2b1cSKevin Laatz 		return;
311ecfc2b1cSKevin Laatz 	}
312ecfc2b1cSKevin Laatz 
313ecfc2b1cSKevin Laatz 	if (n_tokens == 2) {
314ecfc2b1cSKevin Laatz 		link = link_next(NULL);
315ecfc2b1cSKevin Laatz 
316ecfc2b1cSKevin Laatz 		while (link != NULL) {
317ecfc2b1cSKevin Laatz 			out_size = out_size - strlen(out);
318ecfc2b1cSKevin Laatz 			out = &out[strlen(out)];
319ecfc2b1cSKevin Laatz 
320ecfc2b1cSKevin Laatz 			print_link_info(link, out, out_size);
321ecfc2b1cSKevin Laatz 			link = link_next(link);
322ecfc2b1cSKevin Laatz 		}
323ecfc2b1cSKevin Laatz 	} else {
324ecfc2b1cSKevin Laatz 		out_size = out_size - strlen(out);
325ecfc2b1cSKevin Laatz 		out = &out[strlen(out)];
326ecfc2b1cSKevin Laatz 
327ecfc2b1cSKevin Laatz 		link_name = tokens[2];
328ecfc2b1cSKevin Laatz 		link = link_find(link_name);
329ecfc2b1cSKevin Laatz 
330ecfc2b1cSKevin Laatz 		if (link == NULL) {
331ecfc2b1cSKevin Laatz 			snprintf(out, out_size, MSG_ARG_INVALID,
332ecfc2b1cSKevin Laatz 					"Link does not exist");
333ecfc2b1cSKevin Laatz 			return;
334ecfc2b1cSKevin Laatz 		}
335ecfc2b1cSKevin Laatz 		print_link_info(link, out, out_size);
336ecfc2b1cSKevin Laatz 	}
337ecfc2b1cSKevin Laatz }
338ecfc2b1cSKevin Laatz 
33926b3effeSKevin Laatz static const char cmd_swq_help[] =
34026b3effeSKevin Laatz "swq <swq_name>\n"
34126b3effeSKevin Laatz "   size <size>\n"
34226b3effeSKevin Laatz "   cpu <cpu_id>\n";
34326b3effeSKevin Laatz 
3448245472cSJasvinder Singh static void
cmd_swq(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)3458245472cSJasvinder Singh cmd_swq(char **tokens,
3468245472cSJasvinder Singh 	uint32_t n_tokens,
3478245472cSJasvinder Singh 	char *out,
3488245472cSJasvinder Singh 	size_t out_size)
3498245472cSJasvinder Singh {
3508245472cSJasvinder Singh 	struct swq_params p;
3518245472cSJasvinder Singh 	char *name;
3528245472cSJasvinder Singh 	struct swq *swq;
3538245472cSJasvinder Singh 
3548245472cSJasvinder Singh 	if (n_tokens != 6) {
3558245472cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3568245472cSJasvinder Singh 		return;
3578245472cSJasvinder Singh 	}
3588245472cSJasvinder Singh 
3598245472cSJasvinder Singh 	name = tokens[1];
3608245472cSJasvinder Singh 
3618245472cSJasvinder Singh 	if (strcmp(tokens[2], "size") != 0) {
3628245472cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
3638245472cSJasvinder Singh 		return;
3648245472cSJasvinder Singh 	}
3658245472cSJasvinder Singh 
3668245472cSJasvinder Singh 	if (parser_read_uint32(&p.size, tokens[3]) != 0) {
3678245472cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "size");
3688245472cSJasvinder Singh 		return;
3698245472cSJasvinder Singh 	}
3708245472cSJasvinder Singh 
3718245472cSJasvinder Singh 	if (strcmp(tokens[4], "cpu") != 0) {
3728245472cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
3738245472cSJasvinder Singh 		return;
3748245472cSJasvinder Singh 	}
3758245472cSJasvinder Singh 
3768245472cSJasvinder Singh 	if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
3778245472cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
3788245472cSJasvinder Singh 		return;
3798245472cSJasvinder Singh 	}
3808245472cSJasvinder Singh 
3818245472cSJasvinder Singh 	swq = swq_create(name, &p);
3828245472cSJasvinder Singh 	if (swq == NULL) {
3838245472cSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3848245472cSJasvinder Singh 		return;
3858245472cSJasvinder Singh 	}
3868245472cSJasvinder Singh }
3878245472cSJasvinder Singh 
38826b3effeSKevin Laatz static const char cmd_tmgr_subport_profile_help[] =
38926b3effeSKevin Laatz "tmgr subport profile\n"
39026b3effeSKevin Laatz "   <tb_rate> <tb_size>\n"
3913f2eaa4cSJasvinder Singh "   <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
3923f2eaa4cSJasvinder Singh "        <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
3933f2eaa4cSJasvinder Singh "        <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
39454a298e5SSavinay Dharmappa "   <tc_period>\n";
39526b3effeSKevin Laatz 
39625961ff3SJasvinder Singh static void
cmd_tmgr_subport_profile(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)39725961ff3SJasvinder Singh cmd_tmgr_subport_profile(char **tokens,
39825961ff3SJasvinder Singh 	uint32_t n_tokens,
39925961ff3SJasvinder Singh 	char *out,
40025961ff3SJasvinder Singh 	size_t out_size)
40125961ff3SJasvinder Singh {
40254a298e5SSavinay Dharmappa 	struct rte_sched_subport_profile_params subport_profile;
40325961ff3SJasvinder Singh 	int status, i;
40425961ff3SJasvinder Singh 
40554a298e5SSavinay Dharmappa 	if (n_tokens != 19) {
40625961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
40725961ff3SJasvinder Singh 		return;
40825961ff3SJasvinder Singh 	}
40925961ff3SJasvinder Singh 
41054a298e5SSavinay Dharmappa 	if (parser_read_uint64(&subport_profile.tb_rate, tokens[3]) != 0) {
41125961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
41225961ff3SJasvinder Singh 		return;
41325961ff3SJasvinder Singh 	}
41425961ff3SJasvinder Singh 
41554a298e5SSavinay Dharmappa 	if (parser_read_uint64(&subport_profile.tb_size, tokens[4]) != 0) {
41625961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
41725961ff3SJasvinder Singh 		return;
41825961ff3SJasvinder Singh 	}
41925961ff3SJasvinder Singh 
42025961ff3SJasvinder Singh 	for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
42154a298e5SSavinay Dharmappa 		if (parser_read_uint64(&subport_profile.tc_rate[i],
42254a298e5SSavinay Dharmappa 				tokens[5 + i]) != 0) {
42325961ff3SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
42425961ff3SJasvinder Singh 			return;
42525961ff3SJasvinder Singh 		}
42625961ff3SJasvinder Singh 
42754a298e5SSavinay Dharmappa 	if (parser_read_uint64(&subport_profile.tc_period, tokens[18]) != 0) {
42825961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
42925961ff3SJasvinder Singh 		return;
43025961ff3SJasvinder Singh 	}
43125961ff3SJasvinder Singh 
43254a298e5SSavinay Dharmappa 	status = tmgr_subport_profile_add(&subport_profile);
43325961ff3SJasvinder Singh 	if (status != 0) {
43425961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
43525961ff3SJasvinder Singh 		return;
43625961ff3SJasvinder Singh 	}
43725961ff3SJasvinder Singh }
43825961ff3SJasvinder Singh 
43926b3effeSKevin Laatz static const char cmd_tmgr_pipe_profile_help[] =
44026b3effeSKevin Laatz "tmgr pipe profile\n"
44126b3effeSKevin Laatz "   <tb_rate> <tb_size>\n"
4423f2eaa4cSJasvinder Singh "   <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
4433f2eaa4cSJasvinder Singh "     <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
4443f2eaa4cSJasvinder Singh "     <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
44526b3effeSKevin Laatz "   <tc_period>\n"
44626b3effeSKevin Laatz "   <tc_ov_weight>\n"
4473f2eaa4cSJasvinder Singh "   <wrr_weight0..3>\n";
44826b3effeSKevin Laatz 
44925961ff3SJasvinder Singh static void
cmd_tmgr_pipe_profile(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)45025961ff3SJasvinder Singh cmd_tmgr_pipe_profile(char **tokens,
45125961ff3SJasvinder Singh 	uint32_t n_tokens,
45225961ff3SJasvinder Singh 	char *out,
45325961ff3SJasvinder Singh 	size_t out_size)
45425961ff3SJasvinder Singh {
45525961ff3SJasvinder Singh 	struct rte_sched_pipe_params p;
45625961ff3SJasvinder Singh 	int status, i;
45725961ff3SJasvinder Singh 
4583f2eaa4cSJasvinder Singh 	if (n_tokens != 24) {
45925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
46025961ff3SJasvinder Singh 		return;
46125961ff3SJasvinder Singh 	}
46225961ff3SJasvinder Singh 
4630edf18eeSJasvinder Singh 	if (parser_read_uint64(&p.tb_rate, tokens[3]) != 0) {
46425961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
46525961ff3SJasvinder Singh 		return;
46625961ff3SJasvinder Singh 	}
46725961ff3SJasvinder Singh 
4680edf18eeSJasvinder Singh 	if (parser_read_uint64(&p.tb_size, tokens[4]) != 0) {
46925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
47025961ff3SJasvinder Singh 		return;
47125961ff3SJasvinder Singh 	}
47225961ff3SJasvinder Singh 
47325961ff3SJasvinder Singh 	for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
4740edf18eeSJasvinder Singh 		if (parser_read_uint64(&p.tc_rate[i], tokens[5 + i]) != 0) {
47525961ff3SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
47625961ff3SJasvinder Singh 			return;
47725961ff3SJasvinder Singh 		}
47825961ff3SJasvinder Singh 
4790edf18eeSJasvinder Singh 	if (parser_read_uint64(&p.tc_period, tokens[18]) != 0) {
48025961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
48125961ff3SJasvinder Singh 		return;
48225961ff3SJasvinder Singh 	}
48325961ff3SJasvinder Singh 
4843f2eaa4cSJasvinder Singh 	if (parser_read_uint8(&p.tc_ov_weight, tokens[19]) != 0) {
48525961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
48625961ff3SJasvinder Singh 		return;
48725961ff3SJasvinder Singh 	}
48825961ff3SJasvinder Singh 
4893f2eaa4cSJasvinder Singh 	for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++)
4903f2eaa4cSJasvinder Singh 		if (parser_read_uint8(&p.wrr_weights[i], tokens[20 + i]) != 0) {
49125961ff3SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
49225961ff3SJasvinder Singh 			return;
49325961ff3SJasvinder Singh 		}
49425961ff3SJasvinder Singh 
49525961ff3SJasvinder Singh 	status = tmgr_pipe_profile_add(&p);
49625961ff3SJasvinder Singh 	if (status != 0) {
49725961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
49825961ff3SJasvinder Singh 		return;
49925961ff3SJasvinder Singh 	}
50025961ff3SJasvinder Singh }
50125961ff3SJasvinder Singh 
50226b3effeSKevin Laatz static const char cmd_tmgr_help[] =
50326b3effeSKevin Laatz "tmgr <tmgr_name>\n"
50426b3effeSKevin Laatz "   rate <rate>\n"
50526b3effeSKevin Laatz "   spp <n_subports_per_port>\n"
50654a298e5SSavinay Dharmappa "   pps <n_pipes_per_subport>\n"
50726b3effeSKevin Laatz "   fo <frame_overhead>\n"
50826b3effeSKevin Laatz "   mtu <mtu>\n"
50926b3effeSKevin Laatz "   cpu <cpu_id>\n";
51026b3effeSKevin Laatz 
51125961ff3SJasvinder Singh static void
cmd_tmgr(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)51225961ff3SJasvinder Singh cmd_tmgr(char **tokens,
51325961ff3SJasvinder Singh 	uint32_t n_tokens,
51425961ff3SJasvinder Singh 	char *out,
51525961ff3SJasvinder Singh 	size_t out_size)
51625961ff3SJasvinder Singh {
51725961ff3SJasvinder Singh 	struct tmgr_port_params p;
51825961ff3SJasvinder Singh 	char *name;
51925961ff3SJasvinder Singh 	struct tmgr_port *tmgr_port;
52025961ff3SJasvinder Singh 
52154a298e5SSavinay Dharmappa 	if (n_tokens != 14) {
52225961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
52325961ff3SJasvinder Singh 		return;
52425961ff3SJasvinder Singh 	}
52525961ff3SJasvinder Singh 
52625961ff3SJasvinder Singh 	name = tokens[1];
52725961ff3SJasvinder Singh 
52825961ff3SJasvinder Singh 	if (strcmp(tokens[2], "rate") != 0) {
52925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
53025961ff3SJasvinder Singh 		return;
53125961ff3SJasvinder Singh 	}
53225961ff3SJasvinder Singh 
5330edf18eeSJasvinder Singh 	if (parser_read_uint64(&p.rate, tokens[3]) != 0) {
53425961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "rate");
53525961ff3SJasvinder Singh 		return;
53625961ff3SJasvinder Singh 	}
53725961ff3SJasvinder Singh 
53825961ff3SJasvinder Singh 	if (strcmp(tokens[4], "spp") != 0) {
53925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
54025961ff3SJasvinder Singh 		return;
54125961ff3SJasvinder Singh 	}
54225961ff3SJasvinder Singh 
54325961ff3SJasvinder Singh 	if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
54425961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
54525961ff3SJasvinder Singh 		return;
54625961ff3SJasvinder Singh 	}
54725961ff3SJasvinder Singh 
54854a298e5SSavinay Dharmappa 	if (strcmp(tokens[6], "pps") != 0) {
54954a298e5SSavinay Dharmappa 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
55054a298e5SSavinay Dharmappa 		return;
55154a298e5SSavinay Dharmappa 	}
55254a298e5SSavinay Dharmappa 
55354a298e5SSavinay Dharmappa 	if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
55454a298e5SSavinay Dharmappa 		snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
55554a298e5SSavinay Dharmappa 		return;
55654a298e5SSavinay Dharmappa 	}
55754a298e5SSavinay Dharmappa 
55854a298e5SSavinay Dharmappa 	if (strcmp(tokens[8], "fo") != 0) {
55925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
56025961ff3SJasvinder Singh 		return;
56125961ff3SJasvinder Singh 	}
56225961ff3SJasvinder Singh 
56354a298e5SSavinay Dharmappa 	if (parser_read_uint32(&p.frame_overhead, tokens[9]) != 0) {
56425961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
56525961ff3SJasvinder Singh 		return;
56625961ff3SJasvinder Singh 	}
56725961ff3SJasvinder Singh 
56854a298e5SSavinay Dharmappa 	if (strcmp(tokens[10], "mtu") != 0) {
56925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
57025961ff3SJasvinder Singh 		return;
57125961ff3SJasvinder Singh 	}
57225961ff3SJasvinder Singh 
57354a298e5SSavinay Dharmappa 	if (parser_read_uint32(&p.mtu, tokens[11]) != 0) {
57425961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
57525961ff3SJasvinder Singh 		return;
57625961ff3SJasvinder Singh 	}
57725961ff3SJasvinder Singh 
57854a298e5SSavinay Dharmappa 	if (strcmp(tokens[12], "cpu") != 0) {
57925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
58025961ff3SJasvinder Singh 		return;
58125961ff3SJasvinder Singh 	}
58225961ff3SJasvinder Singh 
58354a298e5SSavinay Dharmappa 	if (parser_read_uint32(&p.cpu_id, tokens[13]) != 0) {
58425961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
58525961ff3SJasvinder Singh 		return;
58625961ff3SJasvinder Singh 	}
58725961ff3SJasvinder Singh 
58825961ff3SJasvinder Singh 	tmgr_port = tmgr_port_create(name, &p);
58925961ff3SJasvinder Singh 	if (tmgr_port == NULL) {
59025961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
59125961ff3SJasvinder Singh 		return;
59225961ff3SJasvinder Singh 	}
59325961ff3SJasvinder Singh }
59425961ff3SJasvinder Singh 
59526b3effeSKevin Laatz static const char cmd_tmgr_subport_help[] =
59626b3effeSKevin Laatz "tmgr <tmgr_name> subport <subport_id>\n"
59726b3effeSKevin Laatz "   profile <subport_profile_id>\n";
59826b3effeSKevin Laatz 
59925961ff3SJasvinder Singh static void
cmd_tmgr_subport(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)60025961ff3SJasvinder Singh cmd_tmgr_subport(char **tokens,
60125961ff3SJasvinder Singh 	uint32_t n_tokens,
60225961ff3SJasvinder Singh 	char *out,
60325961ff3SJasvinder Singh 	size_t out_size)
60425961ff3SJasvinder Singh {
60525961ff3SJasvinder Singh 	uint32_t subport_id, subport_profile_id;
60625961ff3SJasvinder Singh 	int status;
60725961ff3SJasvinder Singh 	char *name;
60825961ff3SJasvinder Singh 
60925961ff3SJasvinder Singh 	if (n_tokens != 6) {
61025961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
61125961ff3SJasvinder Singh 		return;
61225961ff3SJasvinder Singh 	}
61325961ff3SJasvinder Singh 
61425961ff3SJasvinder Singh 	name = tokens[1];
61525961ff3SJasvinder Singh 
61625961ff3SJasvinder Singh 	if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
61725961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
61825961ff3SJasvinder Singh 		return;
61925961ff3SJasvinder Singh 	}
62025961ff3SJasvinder Singh 
62125961ff3SJasvinder Singh 	if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
62225961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
62325961ff3SJasvinder Singh 		return;
62425961ff3SJasvinder Singh 	}
62525961ff3SJasvinder Singh 
62625961ff3SJasvinder Singh 	status = tmgr_subport_config(name, subport_id, subport_profile_id);
62725961ff3SJasvinder Singh 	if (status) {
62825961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
62925961ff3SJasvinder Singh 		return;
63025961ff3SJasvinder Singh 	}
63125961ff3SJasvinder Singh }
63225961ff3SJasvinder Singh 
63326b3effeSKevin Laatz 
63426b3effeSKevin Laatz static const char cmd_tmgr_subport_pipe_help[] =
63526b3effeSKevin Laatz "tmgr <tmgr_name> subport <subport_id> pipe\n"
63626b3effeSKevin Laatz "   from <pipe_id_first> to <pipe_id_last>\n"
63726b3effeSKevin Laatz "   profile <pipe_profile_id>\n";
63826b3effeSKevin Laatz 
63925961ff3SJasvinder Singh static void
cmd_tmgr_subport_pipe(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)64025961ff3SJasvinder Singh cmd_tmgr_subport_pipe(char **tokens,
64125961ff3SJasvinder Singh 	uint32_t n_tokens,
64225961ff3SJasvinder Singh 	char *out,
64325961ff3SJasvinder Singh 	size_t out_size)
64425961ff3SJasvinder Singh {
64525961ff3SJasvinder Singh 	uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
64625961ff3SJasvinder Singh 	int status;
64725961ff3SJasvinder Singh 	char *name;
64825961ff3SJasvinder Singh 
64925961ff3SJasvinder Singh 	if (n_tokens != 11) {
65025961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
65125961ff3SJasvinder Singh 		return;
65225961ff3SJasvinder Singh 	}
65325961ff3SJasvinder Singh 
65425961ff3SJasvinder Singh 	name = tokens[1];
65525961ff3SJasvinder Singh 
65625961ff3SJasvinder Singh 	if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
65725961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
65825961ff3SJasvinder Singh 		return;
65925961ff3SJasvinder Singh 	}
66025961ff3SJasvinder Singh 
66125961ff3SJasvinder Singh 	if (strcmp(tokens[4], "pipe") != 0) {
66225961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
66325961ff3SJasvinder Singh 		return;
66425961ff3SJasvinder Singh 	}
66525961ff3SJasvinder Singh 
66625961ff3SJasvinder Singh 	if (strcmp(tokens[5], "from") != 0) {
66725961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
66825961ff3SJasvinder Singh 		return;
66925961ff3SJasvinder Singh 	}
67025961ff3SJasvinder Singh 
67125961ff3SJasvinder Singh 	if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
67225961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
67325961ff3SJasvinder Singh 		return;
67425961ff3SJasvinder Singh 	}
67525961ff3SJasvinder Singh 
67625961ff3SJasvinder Singh 	if (strcmp(tokens[7], "to") != 0) {
67725961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
67825961ff3SJasvinder Singh 		return;
67925961ff3SJasvinder Singh 	}
68025961ff3SJasvinder Singh 
68125961ff3SJasvinder Singh 	if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
68225961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
68325961ff3SJasvinder Singh 		return;
68425961ff3SJasvinder Singh 	}
68525961ff3SJasvinder Singh 
68625961ff3SJasvinder Singh 	if (strcmp(tokens[9], "profile") != 0) {
68725961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
68825961ff3SJasvinder Singh 		return;
68925961ff3SJasvinder Singh 	}
69025961ff3SJasvinder Singh 
69125961ff3SJasvinder Singh 	if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
69225961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
69325961ff3SJasvinder Singh 		return;
69425961ff3SJasvinder Singh 	}
69525961ff3SJasvinder Singh 
69625961ff3SJasvinder Singh 	status = tmgr_pipe_config(name, subport_id, pipe_id_first,
69725961ff3SJasvinder Singh 			pipe_id_last, pipe_profile_id);
69825961ff3SJasvinder Singh 	if (status) {
69925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
70025961ff3SJasvinder Singh 		return;
70125961ff3SJasvinder Singh 	}
70225961ff3SJasvinder Singh }
70325961ff3SJasvinder Singh 
70426b3effeSKevin Laatz 
70526b3effeSKevin Laatz static const char cmd_tap_help[] =
70626b3effeSKevin Laatz "tap <tap_name>\n";
70726b3effeSKevin Laatz 
7082f74ae28SJasvinder Singh static void
cmd_tap(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)7092f74ae28SJasvinder Singh cmd_tap(char **tokens,
7102f74ae28SJasvinder Singh 	uint32_t n_tokens,
7112f74ae28SJasvinder Singh 	char *out,
7122f74ae28SJasvinder Singh 	size_t out_size)
7132f74ae28SJasvinder Singh {
7142f74ae28SJasvinder Singh 	char *name;
7152f74ae28SJasvinder Singh 	struct tap *tap;
7162f74ae28SJasvinder Singh 
7172f74ae28SJasvinder Singh 	if (n_tokens != 2) {
7182f74ae28SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
7192f74ae28SJasvinder Singh 		return;
7202f74ae28SJasvinder Singh 	}
7212f74ae28SJasvinder Singh 
7222f74ae28SJasvinder Singh 	name = tokens[1];
7232f74ae28SJasvinder Singh 
7242f74ae28SJasvinder Singh 	tap = tap_create(name);
7252f74ae28SJasvinder Singh 	if (tap == NULL) {
7262f74ae28SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
7272f74ae28SJasvinder Singh 		return;
7282f74ae28SJasvinder Singh 	}
7292f74ae28SJasvinder Singh }
7302f74ae28SJasvinder Singh 
73126b3effeSKevin Laatz static const char cmd_kni_help[] =
73226b3effeSKevin Laatz "kni <kni_name>\n"
73326b3effeSKevin Laatz "   link <link_name>\n"
73426b3effeSKevin Laatz "   mempool <mempool_name>\n"
73526b3effeSKevin Laatz "   [thread <thread_id>]\n";
73626b3effeSKevin Laatz 
7379a408cc8SJasvinder Singh static void
cmd_kni(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)7389a408cc8SJasvinder Singh cmd_kni(char **tokens,
7399a408cc8SJasvinder Singh 	uint32_t n_tokens,
7409a408cc8SJasvinder Singh 	char *out,
7419a408cc8SJasvinder Singh 	size_t out_size)
7429a408cc8SJasvinder Singh {
7439a408cc8SJasvinder Singh 	struct kni_params p;
7449a408cc8SJasvinder Singh 	char *name;
7459a408cc8SJasvinder Singh 	struct kni *kni;
7469a408cc8SJasvinder Singh 
7471d27b0f2SReshma Pattan 	memset(&p, 0, sizeof(p));
7489a408cc8SJasvinder Singh 	if ((n_tokens != 6) && (n_tokens != 8)) {
7499a408cc8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
7509a408cc8SJasvinder Singh 		return;
7519a408cc8SJasvinder Singh 	}
7529a408cc8SJasvinder Singh 
7539a408cc8SJasvinder Singh 	name = tokens[1];
7549a408cc8SJasvinder Singh 
7559a408cc8SJasvinder Singh 	if (strcmp(tokens[2], "link") != 0) {
7569a408cc8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "link");
7579a408cc8SJasvinder Singh 		return;
7589a408cc8SJasvinder Singh 	}
7599a408cc8SJasvinder Singh 
7609a408cc8SJasvinder Singh 	p.link_name = tokens[3];
7619a408cc8SJasvinder Singh 
7629a408cc8SJasvinder Singh 	if (strcmp(tokens[4], "mempool") != 0) {
7639a408cc8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mempool");
7649a408cc8SJasvinder Singh 		return;
7659a408cc8SJasvinder Singh 	}
7669a408cc8SJasvinder Singh 
7679a408cc8SJasvinder Singh 	p.mempool_name = tokens[5];
7689a408cc8SJasvinder Singh 
7699a408cc8SJasvinder Singh 	if (n_tokens == 8) {
7709a408cc8SJasvinder Singh 		if (strcmp(tokens[6], "thread") != 0) {
7719a408cc8SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "thread");
7729a408cc8SJasvinder Singh 			return;
7739a408cc8SJasvinder Singh 		}
7749a408cc8SJasvinder Singh 
7759a408cc8SJasvinder Singh 		if (parser_read_uint32(&p.thread_id, tokens[7]) != 0) {
7769a408cc8SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
7779a408cc8SJasvinder Singh 			return;
7789a408cc8SJasvinder Singh 		}
7799a408cc8SJasvinder Singh 
7809a408cc8SJasvinder Singh 		p.force_bind = 1;
7819a408cc8SJasvinder Singh 	} else
7829a408cc8SJasvinder Singh 		p.force_bind = 0;
7839a408cc8SJasvinder Singh 
7849a408cc8SJasvinder Singh 	kni = kni_create(name, &p);
7859a408cc8SJasvinder Singh 	if (kni == NULL) {
7869a408cc8SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
7879a408cc8SJasvinder Singh 		return;
7889a408cc8SJasvinder Singh 	}
7899a408cc8SJasvinder Singh }
7909a408cc8SJasvinder Singh 
7911edccebcSFan Zhang static const char cmd_cryptodev_help[] =
7921edccebcSFan Zhang "cryptodev <cryptodev_name>\n"
7931edccebcSFan Zhang "   dev <device_name> | dev_id <device_id>\n"
794261bbff7SFan Zhang "   queue <n_queues> <queue_size>\n"
795261bbff7SFan Zhang "   max_sessions <n_sessions>";
7961edccebcSFan Zhang 
7971edccebcSFan Zhang static void
cmd_cryptodev(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)7981edccebcSFan Zhang cmd_cryptodev(char **tokens,
7991edccebcSFan Zhang 	uint32_t n_tokens,
8001edccebcSFan Zhang 	char *out,
8011edccebcSFan Zhang 	size_t out_size)
8021edccebcSFan Zhang {
8031edccebcSFan Zhang 	struct cryptodev_params params;
8041edccebcSFan Zhang 	char *name;
8051edccebcSFan Zhang 
8061edccebcSFan Zhang 	memset(&params, 0, sizeof(params));
807261bbff7SFan Zhang 	if (n_tokens != 9) {
8081edccebcSFan Zhang 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
8091edccebcSFan Zhang 		return;
8101edccebcSFan Zhang 	}
8111edccebcSFan Zhang 
8121edccebcSFan Zhang 	name = tokens[1];
8131edccebcSFan Zhang 
8141edccebcSFan Zhang 	if (strcmp(tokens[2], "dev") == 0)
8151edccebcSFan Zhang 		params.dev_name = tokens[3];
8161edccebcSFan Zhang 	else if (strcmp(tokens[2], "dev_id") == 0) {
8171edccebcSFan Zhang 		if (parser_read_uint32(&params.dev_id, tokens[3]) < 0) {
8181edccebcSFan Zhang 			snprintf(out, out_size,	MSG_ARG_INVALID,
8191edccebcSFan Zhang 				"dev_id");
8201edccebcSFan Zhang 			return;
8211edccebcSFan Zhang 		}
8221edccebcSFan Zhang 	} else {
8231edccebcSFan Zhang 		snprintf(out, out_size,	MSG_ARG_INVALID,
8241edccebcSFan Zhang 			"cryptodev");
8251edccebcSFan Zhang 		return;
8261edccebcSFan Zhang 	}
8271edccebcSFan Zhang 
8281edccebcSFan Zhang 	if (strcmp(tokens[4], "queue")) {
8291edccebcSFan Zhang 		snprintf(out, out_size,	MSG_ARG_NOT_FOUND,
830261bbff7SFan Zhang 			"queue");
8311edccebcSFan Zhang 		return;
8321edccebcSFan Zhang 	}
8331edccebcSFan Zhang 
8341edccebcSFan Zhang 	if (parser_read_uint32(&params.n_queues, tokens[5]) < 0) {
8351edccebcSFan Zhang 		snprintf(out, out_size,	MSG_ARG_INVALID,
8361edccebcSFan Zhang 			"q");
8371edccebcSFan Zhang 		return;
8381edccebcSFan Zhang 	}
8391edccebcSFan Zhang 
8401edccebcSFan Zhang 	if (parser_read_uint32(&params.queue_size, tokens[6]) < 0) {
8411edccebcSFan Zhang 		snprintf(out, out_size,	MSG_ARG_INVALID,
8421edccebcSFan Zhang 			"queue_size");
8431edccebcSFan Zhang 		return;
8441edccebcSFan Zhang 	}
8451edccebcSFan Zhang 
846261bbff7SFan Zhang 	if (strcmp(tokens[7], "max_sessions")) {
847261bbff7SFan Zhang 		snprintf(out, out_size,	MSG_ARG_NOT_FOUND,
848261bbff7SFan Zhang 			"max_sessions");
849261bbff7SFan Zhang 		return;
850261bbff7SFan Zhang 	}
851261bbff7SFan Zhang 
852261bbff7SFan Zhang 	if (parser_read_uint32(&params.session_pool_size, tokens[8]) < 0) {
853261bbff7SFan Zhang 		snprintf(out, out_size,	MSG_ARG_INVALID,
854261bbff7SFan Zhang 			"queue_size");
855261bbff7SFan Zhang 		return;
856261bbff7SFan Zhang 	}
857261bbff7SFan Zhang 
8581edccebcSFan Zhang 	if (cryptodev_create(name, &params) == NULL) {
8591edccebcSFan Zhang 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
8601edccebcSFan Zhang 		return;
8611edccebcSFan Zhang 	}
8621edccebcSFan Zhang }
86326b3effeSKevin Laatz 
86426b3effeSKevin Laatz static const char cmd_port_in_action_profile_help[] =
86526b3effeSKevin Laatz "port in action profile <profile_name>\n"
86626b3effeSKevin Laatz "   [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]\n"
86726b3effeSKevin Laatz "   [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]\n";
86826b3effeSKevin Laatz 
86971937434SJasvinder Singh static void
cmd_port_in_action_profile(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)87071937434SJasvinder Singh cmd_port_in_action_profile(char **tokens,
87171937434SJasvinder Singh 	uint32_t n_tokens,
87271937434SJasvinder Singh 	char *out,
87371937434SJasvinder Singh 	size_t out_size)
87471937434SJasvinder Singh {
87571937434SJasvinder Singh 	struct port_in_action_profile_params p;
87671937434SJasvinder Singh 	struct port_in_action_profile *ap;
87771937434SJasvinder Singh 	char *name;
87871937434SJasvinder Singh 	uint32_t t0;
87971937434SJasvinder Singh 
88071937434SJasvinder Singh 	memset(&p, 0, sizeof(p));
88171937434SJasvinder Singh 
88271937434SJasvinder Singh 	if (n_tokens < 5) {
88371937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
88471937434SJasvinder Singh 		return;
88571937434SJasvinder Singh 	}
88671937434SJasvinder Singh 
88771937434SJasvinder Singh 	if (strcmp(tokens[1], "in") != 0) {
88871937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
88971937434SJasvinder Singh 		return;
89071937434SJasvinder Singh 	}
89171937434SJasvinder Singh 
89271937434SJasvinder Singh 	if (strcmp(tokens[2], "action") != 0) {
89371937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
89471937434SJasvinder Singh 		return;
89571937434SJasvinder Singh 	}
89671937434SJasvinder Singh 
89771937434SJasvinder Singh 	if (strcmp(tokens[3], "profile") != 0) {
89871937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
89971937434SJasvinder Singh 		return;
90071937434SJasvinder Singh 	}
90171937434SJasvinder Singh 
90271937434SJasvinder Singh 	name = tokens[4];
90371937434SJasvinder Singh 
90471937434SJasvinder Singh 	t0 = 5;
90571937434SJasvinder Singh 
90671937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
90771937434SJasvinder Singh 		uint32_t size;
90871937434SJasvinder Singh 
90971937434SJasvinder Singh 		if (n_tokens < t0 + 10) {
91071937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
91171937434SJasvinder Singh 			return;
91271937434SJasvinder Singh 		}
91371937434SJasvinder Singh 
91471937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "match") == 0)
91571937434SJasvinder Singh 			p.fltr.filter_on_match = 1;
91671937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
91771937434SJasvinder Singh 			p.fltr.filter_on_match = 0;
91871937434SJasvinder Singh 		else {
91971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
92071937434SJasvinder Singh 			return;
92171937434SJasvinder Singh 		}
92271937434SJasvinder Singh 
92371937434SJasvinder Singh 		if (strcmp(tokens[t0 + 2], "offset") != 0) {
92471937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
92571937434SJasvinder Singh 			return;
92671937434SJasvinder Singh 		}
92771937434SJasvinder Singh 
92871937434SJasvinder Singh 		if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
92971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
93071937434SJasvinder Singh 			return;
93171937434SJasvinder Singh 		}
93271937434SJasvinder Singh 
93371937434SJasvinder Singh 		if (strcmp(tokens[t0 + 4], "mask") != 0) {
93471937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
93571937434SJasvinder Singh 			return;
93671937434SJasvinder Singh 		}
93771937434SJasvinder Singh 
93871937434SJasvinder Singh 		size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
93971937434SJasvinder Singh 		if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
94071937434SJasvinder Singh 			(size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
94171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
94271937434SJasvinder Singh 			return;
94371937434SJasvinder Singh 		}
94471937434SJasvinder Singh 
94571937434SJasvinder Singh 		if (strcmp(tokens[t0 + 6], "key") != 0) {
94671937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
94771937434SJasvinder Singh 			return;
94871937434SJasvinder Singh 		}
94971937434SJasvinder Singh 
95071937434SJasvinder Singh 		size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
95171937434SJasvinder Singh 		if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
95271937434SJasvinder Singh 			(size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
95371937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
95471937434SJasvinder Singh 			return;
95571937434SJasvinder Singh 		}
95671937434SJasvinder Singh 
95771937434SJasvinder Singh 		if (strcmp(tokens[t0 + 8], "port") != 0) {
95871937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
95971937434SJasvinder Singh 			return;
96071937434SJasvinder Singh 		}
96171937434SJasvinder Singh 
96271937434SJasvinder Singh 		if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
96371937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
96471937434SJasvinder Singh 			return;
96571937434SJasvinder Singh 		}
96671937434SJasvinder Singh 
96771937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
96871937434SJasvinder Singh 		t0 += 10;
96971937434SJasvinder Singh 	} /* filter */
97071937434SJasvinder Singh 
97171937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
97271937434SJasvinder Singh 		uint32_t i;
97371937434SJasvinder Singh 
97471937434SJasvinder Singh 		if (n_tokens < t0 + 22) {
975802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
976802755dcSJasvinder Singh 				"port in action profile balance");
97771937434SJasvinder Singh 			return;
97871937434SJasvinder Singh 		}
97971937434SJasvinder Singh 
98071937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "offset") != 0) {
98171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
98271937434SJasvinder Singh 			return;
98371937434SJasvinder Singh 		}
98471937434SJasvinder Singh 
98571937434SJasvinder Singh 		if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
98671937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
98771937434SJasvinder Singh 			return;
98871937434SJasvinder Singh 		}
98971937434SJasvinder Singh 
99071937434SJasvinder Singh 		if (strcmp(tokens[t0 + 3], "mask") != 0) {
99171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
99271937434SJasvinder Singh 			return;
99371937434SJasvinder Singh 		}
99471937434SJasvinder Singh 
99571937434SJasvinder Singh 		p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
99671937434SJasvinder Singh 		if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
99771937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
99871937434SJasvinder Singh 			return;
99971937434SJasvinder Singh 		}
100071937434SJasvinder Singh 
100171937434SJasvinder Singh 		if (strcmp(tokens[t0 + 5], "port") != 0) {
100271937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
100371937434SJasvinder Singh 			return;
100471937434SJasvinder Singh 		}
100571937434SJasvinder Singh 
100671937434SJasvinder Singh 		for (i = 0; i < 16; i++)
100771937434SJasvinder Singh 			if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
100871937434SJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
100971937434SJasvinder Singh 				return;
101071937434SJasvinder Singh 			}
101171937434SJasvinder Singh 
101271937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
101371937434SJasvinder Singh 		t0 += 22;
101471937434SJasvinder Singh 	} /* balance */
101571937434SJasvinder Singh 
101671937434SJasvinder Singh 	if (t0 < n_tokens) {
101771937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
101871937434SJasvinder Singh 		return;
101971937434SJasvinder Singh 	}
102071937434SJasvinder Singh 
102171937434SJasvinder Singh 	ap = port_in_action_profile_create(name, &p);
102271937434SJasvinder Singh 	if (ap == NULL) {
102371937434SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
102471937434SJasvinder Singh 		return;
102571937434SJasvinder Singh 	}
102671937434SJasvinder Singh }
102771937434SJasvinder Singh 
102826b3effeSKevin Laatz 
102926b3effeSKevin Laatz static const char cmd_table_action_profile_help[] =
103026b3effeSKevin Laatz "table action profile <profile_name>\n"
103126b3effeSKevin Laatz "   ipv4 | ipv6\n"
103226b3effeSKevin Laatz "   offset <ip_offset>\n"
103326b3effeSKevin Laatz "   fwd\n"
103426b3effeSKevin Laatz "   [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]\n"
103526b3effeSKevin Laatz "   [meter srtcm | trtcm\n"
103626b3effeSKevin Laatz "       tc <n_tc>\n"
103726b3effeSKevin Laatz "       stats none | pkts | bytes | both]\n"
103826b3effeSKevin Laatz "   [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]\n"
103933e7afe6SNemanja Marjanovic "   [encap ether | vlan | qinq | mpls | pppoe | qinq_pppoe \n"
104044cad685SCristian Dumitrescu "       vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]\n"
104126b3effeSKevin Laatz "   [nat src | dst\n"
104226b3effeSKevin Laatz "       proto udp | tcp]\n"
104326b3effeSKevin Laatz "   [ttl drop | fwd\n"
104426b3effeSKevin Laatz "       stats none | pkts]\n"
104526b3effeSKevin Laatz "   [stats pkts | bytes | both]\n"
10461edccebcSFan Zhang "   [time]\n"
1047261bbff7SFan Zhang "   [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
1048d5ed626fSCristian Dumitrescu "   [tag]\n"
1049d5ed626fSCristian Dumitrescu "   [decap]\n";
105026b3effeSKevin Laatz 
105171937434SJasvinder Singh static void
cmd_table_action_profile(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)105271937434SJasvinder Singh cmd_table_action_profile(char **tokens,
105371937434SJasvinder Singh 	uint32_t n_tokens,
105471937434SJasvinder Singh 	char *out,
105571937434SJasvinder Singh 	size_t out_size)
105671937434SJasvinder Singh {
105771937434SJasvinder Singh 	struct table_action_profile_params p;
105871937434SJasvinder Singh 	struct table_action_profile *ap;
105971937434SJasvinder Singh 	char *name;
106071937434SJasvinder Singh 	uint32_t t0;
106171937434SJasvinder Singh 
106271937434SJasvinder Singh 	memset(&p, 0, sizeof(p));
106371937434SJasvinder Singh 
106471937434SJasvinder Singh 	if (n_tokens < 8) {
106571937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
106671937434SJasvinder Singh 		return;
106771937434SJasvinder Singh 	}
106871937434SJasvinder Singh 
106971937434SJasvinder Singh 	if (strcmp(tokens[1], "action") != 0) {
107071937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
107171937434SJasvinder Singh 		return;
107271937434SJasvinder Singh 	}
107371937434SJasvinder Singh 
107471937434SJasvinder Singh 	if (strcmp(tokens[2], "profile") != 0) {
107571937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
107671937434SJasvinder Singh 		return;
107771937434SJasvinder Singh 	}
107871937434SJasvinder Singh 
107971937434SJasvinder Singh 	name = tokens[3];
108071937434SJasvinder Singh 
108171937434SJasvinder Singh 	if (strcmp(tokens[4], "ipv4") == 0)
108271937434SJasvinder Singh 		p.common.ip_version = 1;
108371937434SJasvinder Singh 	else if (strcmp(tokens[4], "ipv6") == 0)
108471937434SJasvinder Singh 		p.common.ip_version = 0;
108571937434SJasvinder Singh 	else {
108671937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
108771937434SJasvinder Singh 		return;
108871937434SJasvinder Singh 	}
108971937434SJasvinder Singh 
109071937434SJasvinder Singh 	if (strcmp(tokens[5], "offset") != 0) {
109171937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
109271937434SJasvinder Singh 		return;
109371937434SJasvinder Singh 	}
109471937434SJasvinder Singh 
109571937434SJasvinder Singh 	if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
109671937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
109771937434SJasvinder Singh 		return;
109871937434SJasvinder Singh 	}
109971937434SJasvinder Singh 
110071937434SJasvinder Singh 	if (strcmp(tokens[7], "fwd") != 0) {
110171937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
110271937434SJasvinder Singh 		return;
110371937434SJasvinder Singh 	}
110471937434SJasvinder Singh 
110571937434SJasvinder Singh 	p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
110671937434SJasvinder Singh 
110771937434SJasvinder Singh 	t0 = 8;
1108802755dcSJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
1109802755dcSJasvinder Singh 		if (n_tokens < t0 + 7) {
1110802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1111802755dcSJasvinder Singh 			return;
1112802755dcSJasvinder Singh 		}
1113802755dcSJasvinder Singh 
1114802755dcSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "offset") != 0) {
1115802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1116802755dcSJasvinder Singh 			return;
1117802755dcSJasvinder Singh 		}
1118802755dcSJasvinder Singh 
1119802755dcSJasvinder Singh 		if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1120802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1121802755dcSJasvinder Singh 			return;
1122802755dcSJasvinder Singh 		}
1123802755dcSJasvinder Singh 
1124802755dcSJasvinder Singh 		if (strcmp(tokens[t0 + 3], "mask") != 0) {
1125802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1126802755dcSJasvinder Singh 			return;
1127802755dcSJasvinder Singh 		}
1128802755dcSJasvinder Singh 
1129802755dcSJasvinder Singh 		p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1130802755dcSJasvinder Singh 		if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1131802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1132802755dcSJasvinder Singh 			return;
1133802755dcSJasvinder Singh 		}
1134802755dcSJasvinder Singh 
1135802755dcSJasvinder Singh 		if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1136802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1137802755dcSJasvinder Singh 			return;
1138802755dcSJasvinder Singh 		}
1139802755dcSJasvinder Singh 
1140802755dcSJasvinder Singh 		if (parser_read_uint32(&p.lb.out_offset, tokens[t0 + 6]) != 0) {
1141802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1142802755dcSJasvinder Singh 			return;
1143802755dcSJasvinder Singh 		}
1144802755dcSJasvinder Singh 
1145802755dcSJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1146802755dcSJasvinder Singh 		t0 += 7;
1147802755dcSJasvinder Singh 	} /* balance */
1148802755dcSJasvinder Singh 
114971937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
115071937434SJasvinder Singh 		if (n_tokens < t0 + 6) {
115171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
115271937434SJasvinder Singh 				"table action profile meter");
115371937434SJasvinder Singh 			return;
115471937434SJasvinder Singh 		}
115571937434SJasvinder Singh 
115671937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "srtcm") == 0)
115771937434SJasvinder Singh 			p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
115871937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
115971937434SJasvinder Singh 			p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
116071937434SJasvinder Singh 		else {
116171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
116271937434SJasvinder Singh 				"srtcm or trtcm");
116371937434SJasvinder Singh 			return;
116471937434SJasvinder Singh 		}
116571937434SJasvinder Singh 
116671937434SJasvinder Singh 		if (strcmp(tokens[t0 + 2], "tc") != 0) {
116771937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
116871937434SJasvinder Singh 			return;
116971937434SJasvinder Singh 		}
117071937434SJasvinder Singh 
117171937434SJasvinder Singh 		if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
117271937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
117371937434SJasvinder Singh 			return;
117471937434SJasvinder Singh 		}
117571937434SJasvinder Singh 
117671937434SJasvinder Singh 		if (strcmp(tokens[t0 + 4], "stats") != 0) {
117771937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
117871937434SJasvinder Singh 			return;
117971937434SJasvinder Singh 		}
118071937434SJasvinder Singh 
118171937434SJasvinder Singh 		if (strcmp(tokens[t0 + 5], "none") == 0) {
118271937434SJasvinder Singh 			p.mtr.n_packets_enabled = 0;
118371937434SJasvinder Singh 			p.mtr.n_bytes_enabled = 0;
118471937434SJasvinder Singh 		} else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
118571937434SJasvinder Singh 			p.mtr.n_packets_enabled = 1;
118671937434SJasvinder Singh 			p.mtr.n_bytes_enabled = 0;
118771937434SJasvinder Singh 		} else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
118871937434SJasvinder Singh 			p.mtr.n_packets_enabled = 0;
118971937434SJasvinder Singh 			p.mtr.n_bytes_enabled = 1;
119071937434SJasvinder Singh 		} else if (strcmp(tokens[t0 + 5], "both") == 0) {
119171937434SJasvinder Singh 			p.mtr.n_packets_enabled = 1;
119271937434SJasvinder Singh 			p.mtr.n_bytes_enabled = 1;
119371937434SJasvinder Singh 		} else {
119471937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
119571937434SJasvinder Singh 				"none or pkts or bytes or both");
119671937434SJasvinder Singh 			return;
119771937434SJasvinder Singh 		}
119871937434SJasvinder Singh 
119971937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
120071937434SJasvinder Singh 		t0 += 6;
120171937434SJasvinder Singh 	} /* meter */
120271937434SJasvinder Singh 
120371937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
120471937434SJasvinder Singh 		if (n_tokens < t0 + 5) {
120571937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
120671937434SJasvinder Singh 				"table action profile tm");
120771937434SJasvinder Singh 			return;
120871937434SJasvinder Singh 		}
120971937434SJasvinder Singh 
121071937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "spp") != 0) {
121171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
121271937434SJasvinder Singh 			return;
121371937434SJasvinder Singh 		}
121471937434SJasvinder Singh 
121571937434SJasvinder Singh 		if (parser_read_uint32(&p.tm.n_subports_per_port,
121671937434SJasvinder Singh 			tokens[t0 + 2]) != 0) {
121771937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
121871937434SJasvinder Singh 				"n_subports_per_port");
121971937434SJasvinder Singh 			return;
122071937434SJasvinder Singh 		}
122171937434SJasvinder Singh 
122271937434SJasvinder Singh 		if (strcmp(tokens[t0 + 3], "pps") != 0) {
122371937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
122471937434SJasvinder Singh 			return;
122571937434SJasvinder Singh 		}
122671937434SJasvinder Singh 
122771937434SJasvinder Singh 		if (parser_read_uint32(&p.tm.n_pipes_per_subport,
122871937434SJasvinder Singh 			tokens[t0 + 4]) != 0) {
122971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
123071937434SJasvinder Singh 				"n_pipes_per_subport");
123171937434SJasvinder Singh 			return;
123271937434SJasvinder Singh 		}
123371937434SJasvinder Singh 
123471937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
123571937434SJasvinder Singh 		t0 += 5;
123671937434SJasvinder Singh 	} /* tm */
123771937434SJasvinder Singh 
123871937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
123944cad685SCristian Dumitrescu 		uint32_t n_extra_tokens = 0;
124044cad685SCristian Dumitrescu 
124171937434SJasvinder Singh 		if (n_tokens < t0 + 2) {
124271937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
124371937434SJasvinder Singh 				"action profile encap");
124471937434SJasvinder Singh 			return;
124571937434SJasvinder Singh 		}
124671937434SJasvinder Singh 
124771937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "ether") == 0)
124871937434SJasvinder Singh 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
124971937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "vlan") == 0)
125071937434SJasvinder Singh 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
125171937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "qinq") == 0)
125271937434SJasvinder Singh 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
125371937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "mpls") == 0)
125471937434SJasvinder Singh 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
125571937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
125671937434SJasvinder Singh 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
125744cad685SCristian Dumitrescu 		else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
125844cad685SCristian Dumitrescu 			if (n_tokens < t0 + 2 + 5) {
125944cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_MISMATCH,
126044cad685SCristian Dumitrescu 					"action profile encap vxlan");
126144cad685SCristian Dumitrescu 				return;
126244cad685SCristian Dumitrescu 			}
126344cad685SCristian Dumitrescu 
126444cad685SCristian Dumitrescu 			if (strcmp(tokens[t0 + 2], "offset") != 0) {
126544cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_NOT_FOUND,
126644cad685SCristian Dumitrescu 					"vxlan: offset");
126744cad685SCristian Dumitrescu 				return;
126844cad685SCristian Dumitrescu 			}
126944cad685SCristian Dumitrescu 
127044cad685SCristian Dumitrescu 			if (parser_read_uint32(&p.encap.vxlan.data_offset,
127144cad685SCristian Dumitrescu 				tokens[t0 + 2 + 1]) != 0) {
127244cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_INVALID,
127344cad685SCristian Dumitrescu 					"vxlan: ether_offset");
127444cad685SCristian Dumitrescu 				return;
127544cad685SCristian Dumitrescu 			}
127644cad685SCristian Dumitrescu 
127744cad685SCristian Dumitrescu 			if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
127844cad685SCristian Dumitrescu 				p.encap.vxlan.ip_version = 1;
127944cad685SCristian Dumitrescu 			else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
128044cad685SCristian Dumitrescu 				p.encap.vxlan.ip_version = 0;
128171937434SJasvinder Singh 			else {
128244cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_INVALID,
128344cad685SCristian Dumitrescu 					"vxlan: ipv4 or ipv6");
128444cad685SCristian Dumitrescu 				return;
128544cad685SCristian Dumitrescu 			}
128644cad685SCristian Dumitrescu 
128744cad685SCristian Dumitrescu 			if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
128844cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_NOT_FOUND,
128944cad685SCristian Dumitrescu 					"vxlan: vlan");
129044cad685SCristian Dumitrescu 				return;
129144cad685SCristian Dumitrescu 			}
129244cad685SCristian Dumitrescu 
129344cad685SCristian Dumitrescu 			if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
129444cad685SCristian Dumitrescu 				p.encap.vxlan.vlan = 1;
129544cad685SCristian Dumitrescu 			else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
129644cad685SCristian Dumitrescu 				p.encap.vxlan.vlan = 0;
129744cad685SCristian Dumitrescu 			else {
129844cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_INVALID,
129944cad685SCristian Dumitrescu 					"vxlan: on or off");
130044cad685SCristian Dumitrescu 				return;
130144cad685SCristian Dumitrescu 			}
130244cad685SCristian Dumitrescu 
130344cad685SCristian Dumitrescu 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
130444cad685SCristian Dumitrescu 			n_extra_tokens = 5;
130533e7afe6SNemanja Marjanovic 		} else if (strcmp(tokens[t0 + 1], "qinq_pppoe") == 0)
130633e7afe6SNemanja Marjanovic 			p.encap.encap_mask =
130733e7afe6SNemanja Marjanovic 				1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
130833e7afe6SNemanja Marjanovic 		else {
130971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
131071937434SJasvinder Singh 			return;
131171937434SJasvinder Singh 		}
131271937434SJasvinder Singh 
131371937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
131444cad685SCristian Dumitrescu 		t0 += 2 + n_extra_tokens;
131571937434SJasvinder Singh 	} /* encap */
131671937434SJasvinder Singh 
131771937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
131871937434SJasvinder Singh 		if (n_tokens < t0 + 4) {
131971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
132071937434SJasvinder Singh 				"table action profile nat");
132171937434SJasvinder Singh 			return;
132271937434SJasvinder Singh 		}
132371937434SJasvinder Singh 
132471937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "src") == 0)
132571937434SJasvinder Singh 			p.nat.source_nat = 1;
132671937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "dst") == 0)
132771937434SJasvinder Singh 			p.nat.source_nat = 0;
132871937434SJasvinder Singh 		else {
132971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
133071937434SJasvinder Singh 				"src or dst");
133171937434SJasvinder Singh 			return;
133271937434SJasvinder Singh 		}
133371937434SJasvinder Singh 
133471937434SJasvinder Singh 		if (strcmp(tokens[t0 + 2], "proto") != 0) {
133571937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
133671937434SJasvinder Singh 			return;
133771937434SJasvinder Singh 		}
133871937434SJasvinder Singh 
133971937434SJasvinder Singh 		if (strcmp(tokens[t0 + 3], "tcp") == 0)
134071937434SJasvinder Singh 			p.nat.proto = 0x06;
134171937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 3], "udp") == 0)
134271937434SJasvinder Singh 			p.nat.proto = 0x11;
134371937434SJasvinder Singh 		else {
134471937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
134571937434SJasvinder Singh 				"tcp or udp");
134671937434SJasvinder Singh 			return;
134771937434SJasvinder Singh 		}
134871937434SJasvinder Singh 
134971937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
135071937434SJasvinder Singh 		t0 += 4;
135171937434SJasvinder Singh 	} /* nat */
135271937434SJasvinder Singh 
135371937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
135471937434SJasvinder Singh 		if (n_tokens < t0 + 4) {
135571937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
135671937434SJasvinder Singh 				"table action profile ttl");
135771937434SJasvinder Singh 			return;
135871937434SJasvinder Singh 		}
135971937434SJasvinder Singh 
136071937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "drop") == 0)
136171937434SJasvinder Singh 			p.ttl.drop = 1;
136271937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "fwd") == 0)
136371937434SJasvinder Singh 			p.ttl.drop = 0;
136471937434SJasvinder Singh 		else {
136571937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
136671937434SJasvinder Singh 				"drop or fwd");
136771937434SJasvinder Singh 			return;
136871937434SJasvinder Singh 		}
136971937434SJasvinder Singh 
137071937434SJasvinder Singh 		if (strcmp(tokens[t0 + 2], "stats") != 0) {
137171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
137271937434SJasvinder Singh 			return;
137371937434SJasvinder Singh 		}
137471937434SJasvinder Singh 
137571937434SJasvinder Singh 		if (strcmp(tokens[t0 + 3], "none") == 0)
137671937434SJasvinder Singh 			p.ttl.n_packets_enabled = 0;
137771937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 3], "pkts") == 0)
137871937434SJasvinder Singh 			p.ttl.n_packets_enabled = 1;
137971937434SJasvinder Singh 		else {
138071937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
138171937434SJasvinder Singh 				"none or pkts");
138271937434SJasvinder Singh 			return;
138371937434SJasvinder Singh 		}
138471937434SJasvinder Singh 
138571937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
138671937434SJasvinder Singh 		t0 += 4;
138771937434SJasvinder Singh 	} /* ttl */
138871937434SJasvinder Singh 
138971937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
139071937434SJasvinder Singh 		if (n_tokens < t0 + 2) {
139171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
139271937434SJasvinder Singh 				"table action profile stats");
139371937434SJasvinder Singh 			return;
139471937434SJasvinder Singh 		}
139571937434SJasvinder Singh 
139671937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "pkts") == 0) {
139771937434SJasvinder Singh 			p.stats.n_packets_enabled = 1;
139871937434SJasvinder Singh 			p.stats.n_bytes_enabled = 0;
139971937434SJasvinder Singh 		} else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
140071937434SJasvinder Singh 			p.stats.n_packets_enabled = 0;
140171937434SJasvinder Singh 			p.stats.n_bytes_enabled = 1;
140271937434SJasvinder Singh 		} else if (strcmp(tokens[t0 + 1], "both") == 0) {
140371937434SJasvinder Singh 			p.stats.n_packets_enabled = 1;
140471937434SJasvinder Singh 			p.stats.n_bytes_enabled = 1;
140571937434SJasvinder Singh 		} else {
140671937434SJasvinder Singh 			snprintf(out, out_size,	MSG_ARG_NOT_FOUND,
140771937434SJasvinder Singh 				"pkts or bytes or both");
140871937434SJasvinder Singh 			return;
140971937434SJasvinder Singh 		}
141071937434SJasvinder Singh 
141171937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
141271937434SJasvinder Singh 		t0 += 2;
141371937434SJasvinder Singh 	} /* stats */
141471937434SJasvinder Singh 
141571937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
141671937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
141771937434SJasvinder Singh 		t0 += 1;
141871937434SJasvinder Singh 	} /* time */
141971937434SJasvinder Singh 
14201edccebcSFan Zhang 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
14211edccebcSFan Zhang 		struct cryptodev *cryptodev;
14221edccebcSFan Zhang 
1423261bbff7SFan Zhang 		if (n_tokens < t0 + 5 ||
14241edccebcSFan Zhang 				strcmp(tokens[t0 + 1], "dev") ||
1425261bbff7SFan Zhang 				strcmp(tokens[t0 + 3], "offset")) {
14261edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_MISMATCH,
14271edccebcSFan Zhang 				"table action profile sym_crypto");
14281edccebcSFan Zhang 			return;
14291edccebcSFan Zhang 		}
14301edccebcSFan Zhang 
14311edccebcSFan Zhang 		cryptodev = cryptodev_find(tokens[t0 + 2]);
14321edccebcSFan Zhang 		if (cryptodev == NULL) {
14331edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID,
14341edccebcSFan Zhang 				"table action profile sym_crypto");
14351edccebcSFan Zhang 			return;
14361edccebcSFan Zhang 		}
14371edccebcSFan Zhang 
14381edccebcSFan Zhang 		p.sym_crypto.cryptodev_id = cryptodev->dev_id;
14391edccebcSFan Zhang 
14401edccebcSFan Zhang 		if (parser_read_uint32(&p.sym_crypto.op_offset,
14411edccebcSFan Zhang 				tokens[t0 + 4]) != 0) {
14421edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID,
14431edccebcSFan Zhang 					"table action profile sym_crypto");
14441edccebcSFan Zhang 			return;
14451edccebcSFan Zhang 		}
14461edccebcSFan Zhang 
1447261bbff7SFan Zhang 		p.sym_crypto.mp_create = cryptodev->mp_create;
1448261bbff7SFan Zhang 		p.sym_crypto.mp_init = cryptodev->mp_init;
14491edccebcSFan Zhang 
14501edccebcSFan Zhang 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
14511edccebcSFan Zhang 
1452261bbff7SFan Zhang 		t0 += 5;
14531edccebcSFan Zhang 	} /* sym_crypto */
14541edccebcSFan Zhang 
14551bdf2632SCristian Dumitrescu 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {
14561bdf2632SCristian Dumitrescu 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
14571bdf2632SCristian Dumitrescu 		t0 += 1;
14581bdf2632SCristian Dumitrescu 	} /* tag */
14591bdf2632SCristian Dumitrescu 
1460d5ed626fSCristian Dumitrescu 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "decap") == 0)) {
1461d5ed626fSCristian Dumitrescu 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1462d5ed626fSCristian Dumitrescu 		t0 += 1;
1463d5ed626fSCristian Dumitrescu 	} /* decap */
1464d5ed626fSCristian Dumitrescu 
146571937434SJasvinder Singh 	if (t0 < n_tokens) {
146671937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
146771937434SJasvinder Singh 		return;
146871937434SJasvinder Singh 	}
146971937434SJasvinder Singh 
147071937434SJasvinder Singh 	ap = table_action_profile_create(name, &p);
147171937434SJasvinder Singh 	if (ap == NULL) {
147271937434SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
147371937434SJasvinder Singh 		return;
147471937434SJasvinder Singh 	}
147571937434SJasvinder Singh }
147671937434SJasvinder Singh 
147726b3effeSKevin Laatz static const char cmd_pipeline_help[] =
147826b3effeSKevin Laatz "pipeline <pipeline_name>\n"
147926b3effeSKevin Laatz "   period <timer_period_ms>\n"
148026b3effeSKevin Laatz "   offset_port_id <offset_port_id>\n"
148126b3effeSKevin Laatz "   cpu <cpu_id>\n";
148226b3effeSKevin Laatz 
1483d75c371eSJasvinder Singh static void
cmd_pipeline(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)1484d75c371eSJasvinder Singh cmd_pipeline(char **tokens,
1485d75c371eSJasvinder Singh 	uint32_t n_tokens,
1486d75c371eSJasvinder Singh 	char *out,
1487d75c371eSJasvinder Singh 	size_t out_size)
1488d75c371eSJasvinder Singh {
1489d75c371eSJasvinder Singh 	struct pipeline_params p;
1490d75c371eSJasvinder Singh 	char *name;
1491d75c371eSJasvinder Singh 	struct pipeline *pipeline;
1492d75c371eSJasvinder Singh 
1493d75c371eSJasvinder Singh 	if (n_tokens != 8) {
1494d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1495d75c371eSJasvinder Singh 		return;
1496d75c371eSJasvinder Singh 	}
1497d75c371eSJasvinder Singh 
1498d75c371eSJasvinder Singh 	name = tokens[1];
1499d75c371eSJasvinder Singh 
1500d75c371eSJasvinder Singh 	if (strcmp(tokens[2], "period") != 0) {
1501d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1502d75c371eSJasvinder Singh 		return;
1503d75c371eSJasvinder Singh 	}
1504d75c371eSJasvinder Singh 
1505d75c371eSJasvinder Singh 	if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1506d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1507d75c371eSJasvinder Singh 		return;
1508d75c371eSJasvinder Singh 	}
1509d75c371eSJasvinder Singh 
1510d75c371eSJasvinder Singh 	if (strcmp(tokens[4], "offset_port_id") != 0) {
1511d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1512d75c371eSJasvinder Singh 		return;
1513d75c371eSJasvinder Singh 	}
1514d75c371eSJasvinder Singh 
1515d75c371eSJasvinder Singh 	if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1516d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1517d75c371eSJasvinder Singh 		return;
1518d75c371eSJasvinder Singh 	}
1519d75c371eSJasvinder Singh 
1520d75c371eSJasvinder Singh 	if (strcmp(tokens[6], "cpu") != 0) {
1521d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1522d75c371eSJasvinder Singh 		return;
1523d75c371eSJasvinder Singh 	}
1524d75c371eSJasvinder Singh 
1525d75c371eSJasvinder Singh 	if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1526d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1527d75c371eSJasvinder Singh 		return;
1528d75c371eSJasvinder Singh 	}
1529d75c371eSJasvinder Singh 
1530d75c371eSJasvinder Singh 	pipeline = pipeline_create(name, &p);
1531d75c371eSJasvinder Singh 	if (pipeline == NULL) {
1532d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1533d75c371eSJasvinder Singh 		return;
1534d75c371eSJasvinder Singh 	}
1535d75c371eSJasvinder Singh }
1536d75c371eSJasvinder Singh 
153726b3effeSKevin Laatz static const char cmd_pipeline_port_in_help[] =
153826b3effeSKevin Laatz "pipeline <pipeline_name> port in\n"
153926b3effeSKevin Laatz "   bsz <burst_size>\n"
154026b3effeSKevin Laatz "   link <link_name> rxq <queue_id>\n"
154126b3effeSKevin Laatz "   | swq <swq_name>\n"
154226b3effeSKevin Laatz "   | tmgr <tmgr_name>\n"
154326b3effeSKevin Laatz "   | tap <tap_name> mempool <mempool_name> mtu <mtu>\n"
154426b3effeSKevin Laatz "   | kni <kni_name>\n"
154526b3effeSKevin Laatz "   | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>\n"
15461edccebcSFan Zhang "   | cryptodev <cryptodev_name> rxq <queue_id>\n"
154726b3effeSKevin Laatz "   [action <port_in_action_profile_name>]\n"
154826b3effeSKevin Laatz "   [disabled]\n";
154926b3effeSKevin Laatz 
1550d75c371eSJasvinder Singh static void
cmd_pipeline_port_in(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)1551d75c371eSJasvinder Singh cmd_pipeline_port_in(char **tokens,
1552d75c371eSJasvinder Singh 	uint32_t n_tokens,
1553d75c371eSJasvinder Singh 	char *out,
1554d75c371eSJasvinder Singh 	size_t out_size)
1555d75c371eSJasvinder Singh {
1556d75c371eSJasvinder Singh 	struct port_in_params p;
1557d75c371eSJasvinder Singh 	char *pipeline_name;
1558d75c371eSJasvinder Singh 	uint32_t t0;
1559d75c371eSJasvinder Singh 	int enabled, status;
1560d75c371eSJasvinder Singh 
1561d75c371eSJasvinder Singh 	if (n_tokens < 7) {
1562d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1563d75c371eSJasvinder Singh 		return;
1564d75c371eSJasvinder Singh 	}
1565d75c371eSJasvinder Singh 
1566d75c371eSJasvinder Singh 	pipeline_name = tokens[1];
1567d75c371eSJasvinder Singh 
1568d75c371eSJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
1569d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1570d75c371eSJasvinder Singh 		return;
1571d75c371eSJasvinder Singh 	}
1572d75c371eSJasvinder Singh 
1573d75c371eSJasvinder Singh 	if (strcmp(tokens[3], "in") != 0) {
1574d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1575d75c371eSJasvinder Singh 		return;
1576d75c371eSJasvinder Singh 	}
1577d75c371eSJasvinder Singh 
1578d75c371eSJasvinder Singh 	if (strcmp(tokens[4], "bsz") != 0) {
1579d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1580d75c371eSJasvinder Singh 		return;
1581d75c371eSJasvinder Singh 	}
1582d75c371eSJasvinder Singh 
1583d75c371eSJasvinder Singh 	if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1584d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1585d75c371eSJasvinder Singh 		return;
1586d75c371eSJasvinder Singh 	}
1587d75c371eSJasvinder Singh 
1588d75c371eSJasvinder Singh 	t0 = 6;
1589d75c371eSJasvinder Singh 
1590d75c371eSJasvinder Singh 	if (strcmp(tokens[t0], "link") == 0) {
1591d75c371eSJasvinder Singh 		if (n_tokens < t0 + 4) {
1592d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1593d75c371eSJasvinder Singh 				"pipeline port in link");
1594d75c371eSJasvinder Singh 			return;
1595d75c371eSJasvinder Singh 		}
1596d75c371eSJasvinder Singh 
1597d75c371eSJasvinder Singh 		p.type = PORT_IN_RXQ;
1598d75c371eSJasvinder Singh 
1599d75c371eSJasvinder Singh 		p.dev_name = tokens[t0 + 1];
1600d75c371eSJasvinder Singh 
1601d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1602d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1603d75c371eSJasvinder Singh 			return;
1604d75c371eSJasvinder Singh 		}
1605d75c371eSJasvinder Singh 
1606d75c371eSJasvinder Singh 		if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1607d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
1608d75c371eSJasvinder Singh 				"queue_id");
1609d75c371eSJasvinder Singh 			return;
1610d75c371eSJasvinder Singh 		}
1611d75c371eSJasvinder Singh 		t0 += 4;
1612d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "swq") == 0) {
1613d75c371eSJasvinder Singh 		if (n_tokens < t0 + 2) {
1614d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1615d75c371eSJasvinder Singh 				"pipeline port in swq");
1616d75c371eSJasvinder Singh 			return;
1617d75c371eSJasvinder Singh 		}
1618d75c371eSJasvinder Singh 
1619d75c371eSJasvinder Singh 		p.type = PORT_IN_SWQ;
1620d75c371eSJasvinder Singh 
1621d75c371eSJasvinder Singh 		p.dev_name = tokens[t0 + 1];
1622d75c371eSJasvinder Singh 
1623d75c371eSJasvinder Singh 		t0 += 2;
1624d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "tmgr") == 0) {
1625d75c371eSJasvinder Singh 		if (n_tokens < t0 + 2) {
1626d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1627d75c371eSJasvinder Singh 				"pipeline port in tmgr");
1628d75c371eSJasvinder Singh 			return;
1629d75c371eSJasvinder Singh 		}
1630d75c371eSJasvinder Singh 
1631d75c371eSJasvinder Singh 		p.type = PORT_IN_TMGR;
1632d75c371eSJasvinder Singh 
1633d75c371eSJasvinder Singh 		p.dev_name = tokens[t0 + 1];
1634d75c371eSJasvinder Singh 
1635d75c371eSJasvinder Singh 		t0 += 2;
1636d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "tap") == 0) {
1637d75c371eSJasvinder Singh 		if (n_tokens < t0 + 6) {
1638d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1639d75c371eSJasvinder Singh 				"pipeline port in tap");
1640d75c371eSJasvinder Singh 			return;
1641d75c371eSJasvinder Singh 		}
1642d75c371eSJasvinder Singh 
1643d75c371eSJasvinder Singh 		p.type = PORT_IN_TAP;
1644d75c371eSJasvinder Singh 
1645d75c371eSJasvinder Singh 		p.dev_name = tokens[t0 + 1];
1646d75c371eSJasvinder Singh 
1647d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1648d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1649d75c371eSJasvinder Singh 				"mempool");
1650d75c371eSJasvinder Singh 			return;
1651d75c371eSJasvinder Singh 		}
1652d75c371eSJasvinder Singh 
1653d75c371eSJasvinder Singh 		p.tap.mempool_name = tokens[t0 + 3];
1654d75c371eSJasvinder Singh 
1655d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1656d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1657d75c371eSJasvinder Singh 				"mtu");
1658d75c371eSJasvinder Singh 			return;
1659d75c371eSJasvinder Singh 		}
1660d75c371eSJasvinder Singh 
1661d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1662d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1663d75c371eSJasvinder Singh 			return;
1664d75c371eSJasvinder Singh 		}
1665d75c371eSJasvinder Singh 
1666d75c371eSJasvinder Singh 		t0 += 6;
1667d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "kni") == 0) {
1668d75c371eSJasvinder Singh 		if (n_tokens < t0 + 2) {
1669d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1670d75c371eSJasvinder Singh 				"pipeline port in kni");
1671d75c371eSJasvinder Singh 			return;
1672d75c371eSJasvinder Singh 		}
1673d75c371eSJasvinder Singh 
1674d75c371eSJasvinder Singh 		p.type = PORT_IN_KNI;
1675d75c371eSJasvinder Singh 
1676d75c371eSJasvinder Singh 		p.dev_name = tokens[t0 + 1];
1677d75c371eSJasvinder Singh 
1678d75c371eSJasvinder Singh 		t0 += 2;
1679d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "source") == 0) {
1680d75c371eSJasvinder Singh 		if (n_tokens < t0 + 6) {
1681d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1682d75c371eSJasvinder Singh 				"pipeline port in source");
1683d75c371eSJasvinder Singh 			return;
1684d75c371eSJasvinder Singh 		}
1685d75c371eSJasvinder Singh 
1686d75c371eSJasvinder Singh 		p.type = PORT_IN_SOURCE;
1687d75c371eSJasvinder Singh 
1688d75c371eSJasvinder Singh 		p.dev_name = NULL;
1689d75c371eSJasvinder Singh 
1690d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1691d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1692d75c371eSJasvinder Singh 				"mempool");
1693d75c371eSJasvinder Singh 			return;
1694d75c371eSJasvinder Singh 		}
1695d75c371eSJasvinder Singh 
1696d75c371eSJasvinder Singh 		p.source.mempool_name = tokens[t0 + 2];
1697d75c371eSJasvinder Singh 
1698d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 3], "file") != 0) {
1699d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1700d75c371eSJasvinder Singh 				"file");
1701d75c371eSJasvinder Singh 			return;
1702d75c371eSJasvinder Singh 		}
1703d75c371eSJasvinder Singh 
1704d75c371eSJasvinder Singh 		p.source.file_name = tokens[t0 + 4];
1705d75c371eSJasvinder Singh 
1706d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1707d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1708d75c371eSJasvinder Singh 				"bpp");
1709d75c371eSJasvinder Singh 			return;
1710d75c371eSJasvinder Singh 		}
1711d75c371eSJasvinder Singh 
1712d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1713d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
1714d75c371eSJasvinder Singh 				"n_bytes_per_pkt");
1715d75c371eSJasvinder Singh 			return;
1716d75c371eSJasvinder Singh 		}
1717d75c371eSJasvinder Singh 
1718d75c371eSJasvinder Singh 		t0 += 7;
17191edccebcSFan Zhang 	} else if (strcmp(tokens[t0], "cryptodev") == 0) {
17201edccebcSFan Zhang 		if (n_tokens < t0 + 3) {
17211edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_MISMATCH,
17221edccebcSFan Zhang 				"pipeline port in cryptodev");
17231edccebcSFan Zhang 			return;
17241edccebcSFan Zhang 		}
17251edccebcSFan Zhang 
17261edccebcSFan Zhang 		p.type = PORT_IN_CRYPTODEV;
17271edccebcSFan Zhang 
17281edccebcSFan Zhang 		p.dev_name = tokens[t0 + 1];
17291edccebcSFan Zhang 		if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
17301edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID,
17311edccebcSFan Zhang 				"rxq");
17321edccebcSFan Zhang 			return;
17331edccebcSFan Zhang 		}
17341edccebcSFan Zhang 
17351edccebcSFan Zhang 		p.cryptodev.arg_callback = NULL;
17361edccebcSFan Zhang 		p.cryptodev.f_callback = NULL;
17371edccebcSFan Zhang 
17381edccebcSFan Zhang 		t0 += 4;
1739d75c371eSJasvinder Singh 	} else {
1740d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1741d75c371eSJasvinder Singh 		return;
1742d75c371eSJasvinder Singh 	}
1743d75c371eSJasvinder Singh 
1744d75c371eSJasvinder Singh 	p.action_profile_name = NULL;
1745d75c371eSJasvinder Singh 	if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1746d75c371eSJasvinder Singh 		if (n_tokens < t0 + 2) {
1747d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1748d75c371eSJasvinder Singh 			return;
1749d75c371eSJasvinder Singh 		}
1750d75c371eSJasvinder Singh 
1751d75c371eSJasvinder Singh 		p.action_profile_name = tokens[t0 + 1];
1752d75c371eSJasvinder Singh 
1753d75c371eSJasvinder Singh 		t0 += 2;
1754d75c371eSJasvinder Singh 	}
1755d75c371eSJasvinder Singh 
1756d75c371eSJasvinder Singh 	enabled = 1;
1757d75c371eSJasvinder Singh 	if ((n_tokens > t0) &&
1758d75c371eSJasvinder Singh 		(strcmp(tokens[t0], "disabled") == 0)) {
1759d75c371eSJasvinder Singh 		enabled = 0;
1760d75c371eSJasvinder Singh 
1761d75c371eSJasvinder Singh 		t0 += 1;
1762d75c371eSJasvinder Singh 	}
1763d75c371eSJasvinder Singh 
1764d75c371eSJasvinder Singh 	if (n_tokens != t0) {
1765d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1766d75c371eSJasvinder Singh 		return;
1767d75c371eSJasvinder Singh 	}
1768d75c371eSJasvinder Singh 
1769d75c371eSJasvinder Singh 	status = pipeline_port_in_create(pipeline_name,
1770d75c371eSJasvinder Singh 		&p, enabled);
1771d75c371eSJasvinder Singh 	if (status) {
1772d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1773d75c371eSJasvinder Singh 		return;
1774d75c371eSJasvinder Singh 	}
1775d75c371eSJasvinder Singh }
1776d75c371eSJasvinder Singh 
177726b3effeSKevin Laatz static const char cmd_pipeline_port_out_help[] =
177826b3effeSKevin Laatz "pipeline <pipeline_name> port out\n"
177926b3effeSKevin Laatz "   bsz <burst_size>\n"
178026b3effeSKevin Laatz "   link <link_name> txq <txq_id>\n"
178126b3effeSKevin Laatz "   | swq <swq_name>\n"
178226b3effeSKevin Laatz "   | tmgr <tmgr_name>\n"
178326b3effeSKevin Laatz "   | tap <tap_name>\n"
178426b3effeSKevin Laatz "   | kni <kni_name>\n"
17851edccebcSFan Zhang "   | sink [file <file_name> pkts <max_n_pkts>]\n"
17861edccebcSFan Zhang "   | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>\n";
178726b3effeSKevin Laatz 
1788d75c371eSJasvinder Singh static void
cmd_pipeline_port_out(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)1789d75c371eSJasvinder Singh cmd_pipeline_port_out(char **tokens,
1790d75c371eSJasvinder Singh 	uint32_t n_tokens,
1791d75c371eSJasvinder Singh 	char *out,
1792d75c371eSJasvinder Singh 	size_t out_size)
1793d75c371eSJasvinder Singh {
1794d75c371eSJasvinder Singh 	struct port_out_params p;
1795d75c371eSJasvinder Singh 	char *pipeline_name;
1796d75c371eSJasvinder Singh 	int status;
1797d75c371eSJasvinder Singh 
1798d75c371eSJasvinder Singh 	memset(&p, 0, sizeof(p));
1799d75c371eSJasvinder Singh 
1800d75c371eSJasvinder Singh 	if (n_tokens < 7) {
1801d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1802d75c371eSJasvinder Singh 		return;
1803d75c371eSJasvinder Singh 	}
1804d75c371eSJasvinder Singh 
1805d75c371eSJasvinder Singh 	pipeline_name = tokens[1];
1806d75c371eSJasvinder Singh 
1807d75c371eSJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
1808d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1809d75c371eSJasvinder Singh 		return;
1810d75c371eSJasvinder Singh 	}
1811d75c371eSJasvinder Singh 
1812d75c371eSJasvinder Singh 	if (strcmp(tokens[3], "out") != 0) {
1813d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1814d75c371eSJasvinder Singh 		return;
1815d75c371eSJasvinder Singh 	}
1816d75c371eSJasvinder Singh 
1817d75c371eSJasvinder Singh 	if (strcmp(tokens[4], "bsz") != 0) {
1818d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1819d75c371eSJasvinder Singh 		return;
1820d75c371eSJasvinder Singh 	}
1821d75c371eSJasvinder Singh 
1822d75c371eSJasvinder Singh 	if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1823d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1824d75c371eSJasvinder Singh 		return;
1825d75c371eSJasvinder Singh 	}
1826d75c371eSJasvinder Singh 
1827d75c371eSJasvinder Singh 	if (strcmp(tokens[6], "link") == 0) {
1828d75c371eSJasvinder Singh 		if (n_tokens != 10) {
1829d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1830d75c371eSJasvinder Singh 				"pipeline port out link");
1831d75c371eSJasvinder Singh 			return;
1832d75c371eSJasvinder Singh 		}
1833d75c371eSJasvinder Singh 
1834d75c371eSJasvinder Singh 		p.type = PORT_OUT_TXQ;
1835d75c371eSJasvinder Singh 
1836d75c371eSJasvinder Singh 		p.dev_name = tokens[7];
1837d75c371eSJasvinder Singh 
1838d75c371eSJasvinder Singh 		if (strcmp(tokens[8], "txq") != 0) {
1839d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1840d75c371eSJasvinder Singh 			return;
1841d75c371eSJasvinder Singh 		}
1842d75c371eSJasvinder Singh 
1843d75c371eSJasvinder Singh 		if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1844d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1845d75c371eSJasvinder Singh 			return;
1846d75c371eSJasvinder Singh 		}
1847d75c371eSJasvinder Singh 	} else if (strcmp(tokens[6], "swq") == 0) {
1848d75c371eSJasvinder Singh 		if (n_tokens != 8) {
1849d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1850d75c371eSJasvinder Singh 				"pipeline port out swq");
1851d75c371eSJasvinder Singh 			return;
1852d75c371eSJasvinder Singh 		}
1853d75c371eSJasvinder Singh 
1854d75c371eSJasvinder Singh 		p.type = PORT_OUT_SWQ;
1855d75c371eSJasvinder Singh 
1856d75c371eSJasvinder Singh 		p.dev_name = tokens[7];
1857d75c371eSJasvinder Singh 	} else if (strcmp(tokens[6], "tmgr") == 0) {
1858d75c371eSJasvinder Singh 		if (n_tokens != 8) {
1859d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1860d75c371eSJasvinder Singh 				"pipeline port out tmgr");
1861d75c371eSJasvinder Singh 			return;
1862d75c371eSJasvinder Singh 		}
1863d75c371eSJasvinder Singh 
1864d75c371eSJasvinder Singh 		p.type = PORT_OUT_TMGR;
1865d75c371eSJasvinder Singh 
1866d75c371eSJasvinder Singh 		p.dev_name = tokens[7];
1867d75c371eSJasvinder Singh 	} else if (strcmp(tokens[6], "tap") == 0) {
1868d75c371eSJasvinder Singh 		if (n_tokens != 8) {
1869d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1870d75c371eSJasvinder Singh 				"pipeline port out tap");
1871d75c371eSJasvinder Singh 			return;
1872d75c371eSJasvinder Singh 		}
1873d75c371eSJasvinder Singh 
1874d75c371eSJasvinder Singh 		p.type = PORT_OUT_TAP;
1875d75c371eSJasvinder Singh 
1876d75c371eSJasvinder Singh 		p.dev_name = tokens[7];
1877d75c371eSJasvinder Singh 	} else if (strcmp(tokens[6], "kni") == 0) {
1878d75c371eSJasvinder Singh 		if (n_tokens != 8) {
1879d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1880d75c371eSJasvinder Singh 				"pipeline port out kni");
1881d75c371eSJasvinder Singh 			return;
1882d75c371eSJasvinder Singh 		}
1883d75c371eSJasvinder Singh 
1884d75c371eSJasvinder Singh 		p.type = PORT_OUT_KNI;
1885d75c371eSJasvinder Singh 
1886d75c371eSJasvinder Singh 		p.dev_name = tokens[7];
1887d75c371eSJasvinder Singh 	} else if (strcmp(tokens[6], "sink") == 0) {
1888d75c371eSJasvinder Singh 		if ((n_tokens != 7) && (n_tokens != 11)) {
1889d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1890d75c371eSJasvinder Singh 				"pipeline port out sink");
1891d75c371eSJasvinder Singh 			return;
1892d75c371eSJasvinder Singh 		}
1893d75c371eSJasvinder Singh 
1894d75c371eSJasvinder Singh 		p.type = PORT_OUT_SINK;
1895d75c371eSJasvinder Singh 
1896d75c371eSJasvinder Singh 		p.dev_name = NULL;
1897d75c371eSJasvinder Singh 
1898d75c371eSJasvinder Singh 		if (n_tokens == 7) {
1899d75c371eSJasvinder Singh 			p.sink.file_name = NULL;
1900d75c371eSJasvinder Singh 			p.sink.max_n_pkts = 0;
1901d75c371eSJasvinder Singh 		} else {
1902d75c371eSJasvinder Singh 			if (strcmp(tokens[7], "file") != 0) {
1903d75c371eSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1904d75c371eSJasvinder Singh 					"file");
1905d75c371eSJasvinder Singh 				return;
1906d75c371eSJasvinder Singh 			}
1907d75c371eSJasvinder Singh 
1908d75c371eSJasvinder Singh 			p.sink.file_name = tokens[8];
1909d75c371eSJasvinder Singh 
1910d75c371eSJasvinder Singh 			if (strcmp(tokens[9], "pkts") != 0) {
1911d75c371eSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1912d75c371eSJasvinder Singh 				return;
1913d75c371eSJasvinder Singh 			}
1914d75c371eSJasvinder Singh 
1915d75c371eSJasvinder Singh 			if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1916d75c371eSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1917d75c371eSJasvinder Singh 				return;
1918d75c371eSJasvinder Singh 			}
1919d75c371eSJasvinder Singh 		}
19201edccebcSFan Zhang 
19211edccebcSFan Zhang 	} else if (strcmp(tokens[6], "cryptodev") == 0) {
19221edccebcSFan Zhang 		if (n_tokens != 12) {
19231edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_MISMATCH,
19241edccebcSFan Zhang 				"pipeline port out cryptodev");
19251edccebcSFan Zhang 			return;
19261edccebcSFan Zhang 		}
19271edccebcSFan Zhang 
19281edccebcSFan Zhang 		p.type = PORT_OUT_CRYPTODEV;
19291edccebcSFan Zhang 
19301edccebcSFan Zhang 		p.dev_name = tokens[7];
19311edccebcSFan Zhang 
19321edccebcSFan Zhang 		if (strcmp(tokens[8], "txq")) {
19331edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_MISMATCH,
19341edccebcSFan Zhang 				"pipeline port out cryptodev");
19351edccebcSFan Zhang 			return;
19361edccebcSFan Zhang 		}
19371edccebcSFan Zhang 
19381edccebcSFan Zhang 		if (parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
19391edccebcSFan Zhang 				!= 0) {
19401edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
19411edccebcSFan Zhang 			return;
19421edccebcSFan Zhang 		}
19431edccebcSFan Zhang 
19441edccebcSFan Zhang 		if (strcmp(tokens[10], "offset")) {
19451edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_MISMATCH,
19461edccebcSFan Zhang 				"pipeline port out cryptodev");
19471edccebcSFan Zhang 			return;
19481edccebcSFan Zhang 		}
19491edccebcSFan Zhang 
19501edccebcSFan Zhang 		if (parser_read_uint32(&p.cryptodev.op_offset, tokens[11])
19511edccebcSFan Zhang 				!= 0) {
19521edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
19531edccebcSFan Zhang 			return;
19541edccebcSFan Zhang 		}
1955d75c371eSJasvinder Singh 	} else {
1956d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1957d75c371eSJasvinder Singh 		return;
1958d75c371eSJasvinder Singh 	}
1959d75c371eSJasvinder Singh 
1960d75c371eSJasvinder Singh 	status = pipeline_port_out_create(pipeline_name, &p);
1961d75c371eSJasvinder Singh 	if (status) {
1962d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1963d75c371eSJasvinder Singh 		return;
1964d75c371eSJasvinder Singh 	}
1965d75c371eSJasvinder Singh }
1966d75c371eSJasvinder Singh 
196726b3effeSKevin Laatz static const char cmd_pipeline_table_help[] =
196826b3effeSKevin Laatz "pipeline <pipeline_name> table\n"
196926b3effeSKevin Laatz "       match\n"
197026b3effeSKevin Laatz "       acl\n"
197126b3effeSKevin Laatz "           ipv4 | ipv6\n"
197226b3effeSKevin Laatz "           offset <ip_header_offset>\n"
197326b3effeSKevin Laatz "           size <n_rules>\n"
197426b3effeSKevin Laatz "       | array\n"
197526b3effeSKevin Laatz "           offset <key_offset>\n"
197626b3effeSKevin Laatz "           size <n_keys>\n"
197726b3effeSKevin Laatz "       | hash\n"
197826b3effeSKevin Laatz "           ext | lru\n"
197926b3effeSKevin Laatz "           key <key_size>\n"
198026b3effeSKevin Laatz "           mask <key_mask>\n"
198126b3effeSKevin Laatz "           offset <key_offset>\n"
198226b3effeSKevin Laatz "           buckets <n_buckets>\n"
198326b3effeSKevin Laatz "           size <n_keys>\n"
198426b3effeSKevin Laatz "       | lpm\n"
198526b3effeSKevin Laatz "           ipv4 | ipv6\n"
198626b3effeSKevin Laatz "           offset <ip_header_offset>\n"
198726b3effeSKevin Laatz "           size <n_rules>\n"
198826b3effeSKevin Laatz "       | stub\n"
198926b3effeSKevin Laatz "   [action <table_action_profile_name>]\n";
199026b3effeSKevin Laatz 
1991d75c371eSJasvinder Singh static void
cmd_pipeline_table(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)1992d75c371eSJasvinder Singh cmd_pipeline_table(char **tokens,
1993d75c371eSJasvinder Singh 	uint32_t n_tokens,
1994d75c371eSJasvinder Singh 	char *out,
1995d75c371eSJasvinder Singh 	size_t out_size)
1996d75c371eSJasvinder Singh {
1997d75c371eSJasvinder Singh 	uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
1998d75c371eSJasvinder Singh 	struct table_params p;
1999d75c371eSJasvinder Singh 	char *pipeline_name;
2000d75c371eSJasvinder Singh 	uint32_t t0;
2001d75c371eSJasvinder Singh 	int status;
2002d75c371eSJasvinder Singh 
2003d75c371eSJasvinder Singh 	if (n_tokens < 5) {
2004d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2005d75c371eSJasvinder Singh 		return;
2006d75c371eSJasvinder Singh 	}
2007d75c371eSJasvinder Singh 
2008d75c371eSJasvinder Singh 	pipeline_name = tokens[1];
2009d75c371eSJasvinder Singh 
2010d75c371eSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
2011d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2012d75c371eSJasvinder Singh 		return;
2013d75c371eSJasvinder Singh 	}
2014d75c371eSJasvinder Singh 
2015d75c371eSJasvinder Singh 	if (strcmp(tokens[3], "match") != 0) {
2016d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2017d75c371eSJasvinder Singh 		return;
2018d75c371eSJasvinder Singh 	}
2019d75c371eSJasvinder Singh 
2020d75c371eSJasvinder Singh 	t0 = 4;
2021d75c371eSJasvinder Singh 	if (strcmp(tokens[t0], "acl") == 0) {
2022d75c371eSJasvinder Singh 		if (n_tokens < t0 + 6) {
2023d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
2024d75c371eSJasvinder Singh 				"pipeline table acl");
2025d75c371eSJasvinder Singh 			return;
2026d75c371eSJasvinder Singh 		}
2027d75c371eSJasvinder Singh 
2028d75c371eSJasvinder Singh 		p.match_type = TABLE_ACL;
2029d75c371eSJasvinder Singh 
2030d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2031d75c371eSJasvinder Singh 			p.match.acl.ip_version = 1;
2032d75c371eSJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2033d75c371eSJasvinder Singh 			p.match.acl.ip_version = 0;
2034d75c371eSJasvinder Singh 		else {
2035d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2036d75c371eSJasvinder Singh 				"ipv4 or ipv6");
2037d75c371eSJasvinder Singh 			return;
2038d75c371eSJasvinder Singh 		}
2039d75c371eSJasvinder Singh 
2040d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 2], "offset") != 0) {
2041d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2042d75c371eSJasvinder Singh 			return;
2043d75c371eSJasvinder Singh 		}
2044d75c371eSJasvinder Singh 
2045d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.acl.ip_header_offset,
2046d75c371eSJasvinder Singh 			tokens[t0 + 3]) != 0) {
2047d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
2048d75c371eSJasvinder Singh 				"ip_header_offset");
2049d75c371eSJasvinder Singh 			return;
2050d75c371eSJasvinder Singh 		}
2051d75c371eSJasvinder Singh 
2052d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 4], "size") != 0) {
2053d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2054d75c371eSJasvinder Singh 			return;
2055d75c371eSJasvinder Singh 		}
2056d75c371eSJasvinder Singh 
2057d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.acl.n_rules,
2058d75c371eSJasvinder Singh 			tokens[t0 + 5]) != 0) {
2059d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2060d75c371eSJasvinder Singh 			return;
2061d75c371eSJasvinder Singh 		}
2062d75c371eSJasvinder Singh 
2063d75c371eSJasvinder Singh 		t0 += 6;
2064d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "array") == 0) {
2065d75c371eSJasvinder Singh 		if (n_tokens < t0 + 5) {
2066d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
2067d75c371eSJasvinder Singh 				"pipeline table array");
2068d75c371eSJasvinder Singh 			return;
2069d75c371eSJasvinder Singh 		}
2070d75c371eSJasvinder Singh 
2071d75c371eSJasvinder Singh 		p.match_type = TABLE_ARRAY;
2072d75c371eSJasvinder Singh 
2073d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "offset") != 0) {
2074d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2075d75c371eSJasvinder Singh 			return;
2076d75c371eSJasvinder Singh 		}
2077d75c371eSJasvinder Singh 
2078d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.array.key_offset,
2079d75c371eSJasvinder Singh 			tokens[t0 + 2]) != 0) {
2080d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2081d75c371eSJasvinder Singh 			return;
2082d75c371eSJasvinder Singh 		}
2083d75c371eSJasvinder Singh 
2084d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 3], "size") != 0) {
2085d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2086d75c371eSJasvinder Singh 			return;
2087d75c371eSJasvinder Singh 		}
2088d75c371eSJasvinder Singh 
2089d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.array.n_keys,
2090d75c371eSJasvinder Singh 			tokens[t0 + 4]) != 0) {
2091d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2092d75c371eSJasvinder Singh 			return;
2093d75c371eSJasvinder Singh 		}
2094d75c371eSJasvinder Singh 
2095d75c371eSJasvinder Singh 		t0 += 5;
2096d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "hash") == 0) {
2097d75c371eSJasvinder Singh 		uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2098d75c371eSJasvinder Singh 
2099d75c371eSJasvinder Singh 		if (n_tokens < t0 + 12) {
2100d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
2101d75c371eSJasvinder Singh 				"pipeline table hash");
2102d75c371eSJasvinder Singh 			return;
2103d75c371eSJasvinder Singh 		}
2104d75c371eSJasvinder Singh 
2105d75c371eSJasvinder Singh 		p.match_type = TABLE_HASH;
2106d75c371eSJasvinder Singh 
2107d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "ext") == 0)
2108d75c371eSJasvinder Singh 			p.match.hash.extendable_bucket = 1;
2109d75c371eSJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "lru") == 0)
2110d75c371eSJasvinder Singh 			p.match.hash.extendable_bucket = 0;
2111d75c371eSJasvinder Singh 		else {
2112d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2113d75c371eSJasvinder Singh 				"ext or lru");
2114d75c371eSJasvinder Singh 			return;
2115d75c371eSJasvinder Singh 		}
2116d75c371eSJasvinder Singh 
2117d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 2], "key") != 0) {
2118d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2119d75c371eSJasvinder Singh 			return;
2120d75c371eSJasvinder Singh 		}
2121d75c371eSJasvinder Singh 
2122d75c371eSJasvinder Singh 		if ((parser_read_uint32(&p.match.hash.key_size,
2123d75c371eSJasvinder Singh 			tokens[t0 + 3]) != 0) ||
2124d75c371eSJasvinder Singh 			(p.match.hash.key_size == 0) ||
2125d75c371eSJasvinder Singh 			(p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
2126d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2127d75c371eSJasvinder Singh 			return;
2128d75c371eSJasvinder Singh 		}
2129d75c371eSJasvinder Singh 
2130d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 4], "mask") != 0) {
2131d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2132d75c371eSJasvinder Singh 			return;
2133d75c371eSJasvinder Singh 		}
2134d75c371eSJasvinder Singh 
2135d75c371eSJasvinder Singh 		if ((parse_hex_string(tokens[t0 + 5],
2136d75c371eSJasvinder Singh 			key_mask, &key_mask_size) != 0) ||
2137d75c371eSJasvinder Singh 			(key_mask_size != p.match.hash.key_size)) {
2138d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2139d75c371eSJasvinder Singh 			return;
2140d75c371eSJasvinder Singh 		}
2141d75c371eSJasvinder Singh 		p.match.hash.key_mask = key_mask;
2142d75c371eSJasvinder Singh 
2143d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 6], "offset") != 0) {
2144d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2145d75c371eSJasvinder Singh 			return;
2146d75c371eSJasvinder Singh 		}
2147d75c371eSJasvinder Singh 
2148d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.hash.key_offset,
2149d75c371eSJasvinder Singh 			tokens[t0 + 7]) != 0) {
2150d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2151d75c371eSJasvinder Singh 			return;
2152d75c371eSJasvinder Singh 		}
2153d75c371eSJasvinder Singh 
2154d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2155d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2156d75c371eSJasvinder Singh 			return;
2157d75c371eSJasvinder Singh 		}
2158d75c371eSJasvinder Singh 
2159d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.hash.n_buckets,
2160d75c371eSJasvinder Singh 			tokens[t0 + 9]) != 0) {
2161d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2162d75c371eSJasvinder Singh 			return;
2163d75c371eSJasvinder Singh 		}
2164d75c371eSJasvinder Singh 
2165d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 10], "size") != 0) {
2166d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2167d75c371eSJasvinder Singh 			return;
2168d75c371eSJasvinder Singh 		}
2169d75c371eSJasvinder Singh 
2170d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.hash.n_keys,
2171d75c371eSJasvinder Singh 			tokens[t0 + 11]) != 0) {
2172d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2173d75c371eSJasvinder Singh 			return;
2174d75c371eSJasvinder Singh 		}
2175d75c371eSJasvinder Singh 
2176d75c371eSJasvinder Singh 		t0 += 12;
2177d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "lpm") == 0) {
2178d75c371eSJasvinder Singh 		if (n_tokens < t0 + 6) {
2179d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
2180d75c371eSJasvinder Singh 				"pipeline table lpm");
2181d75c371eSJasvinder Singh 			return;
2182d75c371eSJasvinder Singh 		}
2183d75c371eSJasvinder Singh 
2184d75c371eSJasvinder Singh 		p.match_type = TABLE_LPM;
2185d75c371eSJasvinder Singh 
2186d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2187d75c371eSJasvinder Singh 			p.match.lpm.key_size = 4;
2188d75c371eSJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2189d75c371eSJasvinder Singh 			p.match.lpm.key_size = 16;
2190d75c371eSJasvinder Singh 		else {
2191d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2192d75c371eSJasvinder Singh 				"ipv4 or ipv6");
2193d75c371eSJasvinder Singh 			return;
2194d75c371eSJasvinder Singh 		}
2195d75c371eSJasvinder Singh 
2196d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 2], "offset") != 0) {
2197d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2198d75c371eSJasvinder Singh 			return;
2199d75c371eSJasvinder Singh 		}
2200d75c371eSJasvinder Singh 
2201d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.lpm.key_offset,
2202d75c371eSJasvinder Singh 			tokens[t0 + 3]) != 0) {
2203d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2204d75c371eSJasvinder Singh 			return;
2205d75c371eSJasvinder Singh 		}
2206d75c371eSJasvinder Singh 
2207d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 4], "size") != 0) {
2208d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2209d75c371eSJasvinder Singh 			return;
2210d75c371eSJasvinder Singh 		}
2211d75c371eSJasvinder Singh 
2212d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.lpm.n_rules,
2213d75c371eSJasvinder Singh 			tokens[t0 + 5]) != 0) {
2214d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2215d75c371eSJasvinder Singh 			return;
2216d75c371eSJasvinder Singh 		}
2217d75c371eSJasvinder Singh 
2218d75c371eSJasvinder Singh 		t0 += 6;
2219d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "stub") == 0) {
2220d75c371eSJasvinder Singh 		p.match_type = TABLE_STUB;
2221d75c371eSJasvinder Singh 
2222d75c371eSJasvinder Singh 		t0 += 1;
2223d75c371eSJasvinder Singh 	} else {
2224d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2225d75c371eSJasvinder Singh 		return;
2226d75c371eSJasvinder Singh 	}
2227d75c371eSJasvinder Singh 
2228d75c371eSJasvinder Singh 	p.action_profile_name = NULL;
2229d75c371eSJasvinder Singh 	if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
2230d75c371eSJasvinder Singh 		if (n_tokens < t0 + 2) {
2231d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2232d75c371eSJasvinder Singh 			return;
2233d75c371eSJasvinder Singh 		}
2234d75c371eSJasvinder Singh 
2235d75c371eSJasvinder Singh 		p.action_profile_name = tokens[t0 + 1];
2236d75c371eSJasvinder Singh 
2237d75c371eSJasvinder Singh 		t0 += 2;
2238d75c371eSJasvinder Singh 	}
2239d75c371eSJasvinder Singh 
2240d75c371eSJasvinder Singh 	if (n_tokens > t0) {
2241d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2242d75c371eSJasvinder Singh 		return;
2243d75c371eSJasvinder Singh 	}
2244d75c371eSJasvinder Singh 
2245d75c371eSJasvinder Singh 	status = pipeline_table_create(pipeline_name, &p);
2246d75c371eSJasvinder Singh 	if (status) {
2247d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2248d75c371eSJasvinder Singh 		return;
2249d75c371eSJasvinder Singh 	}
2250d75c371eSJasvinder Singh }
2251d75c371eSJasvinder Singh 
225226b3effeSKevin Laatz static const char cmd_pipeline_port_in_table_help[] =
225326b3effeSKevin Laatz "pipeline <pipeline_name> port in <port_id> table <table_id>\n";
225426b3effeSKevin Laatz 
2255d75c371eSJasvinder Singh static void
cmd_pipeline_port_in_table(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)2256d75c371eSJasvinder Singh cmd_pipeline_port_in_table(char **tokens,
2257d75c371eSJasvinder Singh 	uint32_t n_tokens,
2258d75c371eSJasvinder Singh 	char *out,
2259d75c371eSJasvinder Singh 	size_t out_size)
2260d75c371eSJasvinder Singh {
2261d75c371eSJasvinder Singh 	char *pipeline_name;
2262d75c371eSJasvinder Singh 	uint32_t port_id, table_id;
2263d75c371eSJasvinder Singh 	int status;
2264d75c371eSJasvinder Singh 
2265d75c371eSJasvinder Singh 	if (n_tokens != 7) {
2266d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2267d75c371eSJasvinder Singh 		return;
2268d75c371eSJasvinder Singh 	}
2269d75c371eSJasvinder Singh 
2270d75c371eSJasvinder Singh 	pipeline_name = tokens[1];
2271d75c371eSJasvinder Singh 
2272d75c371eSJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
2273d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2274d75c371eSJasvinder Singh 		return;
2275d75c371eSJasvinder Singh 	}
2276d75c371eSJasvinder Singh 
2277d75c371eSJasvinder Singh 	if (strcmp(tokens[3], "in") != 0) {
2278d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2279d75c371eSJasvinder Singh 		return;
2280d75c371eSJasvinder Singh 	}
2281d75c371eSJasvinder Singh 
2282d75c371eSJasvinder Singh 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2283d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2284d75c371eSJasvinder Singh 		return;
2285d75c371eSJasvinder Singh 	}
2286d75c371eSJasvinder Singh 
2287d75c371eSJasvinder Singh 	if (strcmp(tokens[5], "table") != 0) {
2288d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2289d75c371eSJasvinder Singh 		return;
2290d75c371eSJasvinder Singh 	}
2291d75c371eSJasvinder Singh 
2292d75c371eSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[6]) != 0) {
2293d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2294d75c371eSJasvinder Singh 		return;
2295d75c371eSJasvinder Singh 	}
2296d75c371eSJasvinder Singh 
2297d75c371eSJasvinder Singh 	status = pipeline_port_in_connect_to_table(pipeline_name,
2298d75c371eSJasvinder Singh 		port_id,
2299d75c371eSJasvinder Singh 		table_id);
2300d75c371eSJasvinder Singh 	if (status) {
2301d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2302d75c371eSJasvinder Singh 		return;
2303d75c371eSJasvinder Singh 	}
2304d75c371eSJasvinder Singh }
2305d75c371eSJasvinder Singh 
230626b3effeSKevin Laatz 
230726b3effeSKevin Laatz static const char cmd_pipeline_port_in_stats_help[] =
230826b3effeSKevin Laatz "pipeline <pipeline_name> port in <port_id> stats read [clear]\n";
230950e73d05SJasvinder Singh 
231050e73d05SJasvinder Singh #define MSG_PIPELINE_PORT_IN_STATS                         \
231150e73d05SJasvinder Singh 	"Pkts in: %" PRIu64 "\n"                           \
231250e73d05SJasvinder Singh 	"Pkts dropped by AH: %" PRIu64 "\n"                \
231350e73d05SJasvinder Singh 	"Pkts dropped by other: %" PRIu64 "\n"
231450e73d05SJasvinder Singh 
231550e73d05SJasvinder Singh static void
cmd_pipeline_port_in_stats(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)231650e73d05SJasvinder Singh cmd_pipeline_port_in_stats(char **tokens,
231750e73d05SJasvinder Singh 	uint32_t n_tokens,
231850e73d05SJasvinder Singh 	char *out,
231950e73d05SJasvinder Singh 	size_t out_size)
232050e73d05SJasvinder Singh {
232150e73d05SJasvinder Singh 	struct rte_pipeline_port_in_stats stats;
232250e73d05SJasvinder Singh 	char *pipeline_name;
232350e73d05SJasvinder Singh 	uint32_t port_id;
232450e73d05SJasvinder Singh 	int clear, status;
232550e73d05SJasvinder Singh 
232650e73d05SJasvinder Singh 	if ((n_tokens != 7) && (n_tokens != 8)) {
232750e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
232850e73d05SJasvinder Singh 		return;
232950e73d05SJasvinder Singh 	}
233050e73d05SJasvinder Singh 
233150e73d05SJasvinder Singh 	pipeline_name = tokens[1];
233250e73d05SJasvinder Singh 
233350e73d05SJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
233450e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
233550e73d05SJasvinder Singh 		return;
233650e73d05SJasvinder Singh 	}
233750e73d05SJasvinder Singh 
233850e73d05SJasvinder Singh 	if (strcmp(tokens[3], "in") != 0) {
233950e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
234050e73d05SJasvinder Singh 		return;
234150e73d05SJasvinder Singh 	}
234250e73d05SJasvinder Singh 
234350e73d05SJasvinder Singh 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
234450e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
234550e73d05SJasvinder Singh 		return;
234650e73d05SJasvinder Singh 	}
234750e73d05SJasvinder Singh 
234850e73d05SJasvinder Singh 	if (strcmp(tokens[5], "stats") != 0) {
234950e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
235050e73d05SJasvinder Singh 		return;
235150e73d05SJasvinder Singh 	}
235250e73d05SJasvinder Singh 
235350e73d05SJasvinder Singh 	if (strcmp(tokens[6], "read") != 0) {
235450e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
235550e73d05SJasvinder Singh 		return;
235650e73d05SJasvinder Singh 	}
235750e73d05SJasvinder Singh 
235850e73d05SJasvinder Singh 	clear = 0;
235950e73d05SJasvinder Singh 	if (n_tokens == 8) {
236050e73d05SJasvinder Singh 		if (strcmp(tokens[7], "clear") != 0) {
236150e73d05SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "clear");
236250e73d05SJasvinder Singh 			return;
236350e73d05SJasvinder Singh 		}
236450e73d05SJasvinder Singh 
236550e73d05SJasvinder Singh 		clear = 1;
236650e73d05SJasvinder Singh 	}
236750e73d05SJasvinder Singh 
236850e73d05SJasvinder Singh 	status = pipeline_port_in_stats_read(pipeline_name,
236950e73d05SJasvinder Singh 		port_id,
237050e73d05SJasvinder Singh 		&stats,
237150e73d05SJasvinder Singh 		clear);
237250e73d05SJasvinder Singh 	if (status) {
237350e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
237450e73d05SJasvinder Singh 		return;
237550e73d05SJasvinder Singh 	}
237650e73d05SJasvinder Singh 
237750e73d05SJasvinder Singh 	snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
237850e73d05SJasvinder Singh 		stats.stats.n_pkts_in,
237950e73d05SJasvinder Singh 		stats.n_pkts_dropped_by_ah,
238050e73d05SJasvinder Singh 		stats.stats.n_pkts_drop);
238150e73d05SJasvinder Singh }
238250e73d05SJasvinder Singh 
238326b3effeSKevin Laatz 
238426b3effeSKevin Laatz static const char cmd_pipeline_port_in_enable_help[] =
238526b3effeSKevin Laatz "pipeline <pipeline_name> port in <port_id> enable\n";
238626b3effeSKevin Laatz 
23876b1b3c3cSJasvinder Singh static void
cmd_pipeline_port_in_enable(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)23886b1b3c3cSJasvinder Singh cmd_pipeline_port_in_enable(char **tokens,
23896b1b3c3cSJasvinder Singh 	uint32_t n_tokens,
23906b1b3c3cSJasvinder Singh 	char *out,
23916b1b3c3cSJasvinder Singh 	size_t out_size)
23926b1b3c3cSJasvinder Singh {
23936b1b3c3cSJasvinder Singh 	char *pipeline_name;
23946b1b3c3cSJasvinder Singh 	uint32_t port_id;
23956b1b3c3cSJasvinder Singh 	int status;
23966b1b3c3cSJasvinder Singh 
23976b1b3c3cSJasvinder Singh 	if (n_tokens != 6) {
23986b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
23996b1b3c3cSJasvinder Singh 		return;
24006b1b3c3cSJasvinder Singh 	}
24016b1b3c3cSJasvinder Singh 
24026b1b3c3cSJasvinder Singh 	pipeline_name = tokens[1];
24036b1b3c3cSJasvinder Singh 
24046b1b3c3cSJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
24056b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
24066b1b3c3cSJasvinder Singh 		return;
24076b1b3c3cSJasvinder Singh 	}
24086b1b3c3cSJasvinder Singh 
24096b1b3c3cSJasvinder Singh 	if (strcmp(tokens[3], "in") != 0) {
24106b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
24116b1b3c3cSJasvinder Singh 		return;
24126b1b3c3cSJasvinder Singh 	}
24136b1b3c3cSJasvinder Singh 
24146b1b3c3cSJasvinder Singh 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
24156b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
24166b1b3c3cSJasvinder Singh 		return;
24176b1b3c3cSJasvinder Singh 	}
24186b1b3c3cSJasvinder Singh 
24196b1b3c3cSJasvinder Singh 	if (strcmp(tokens[5], "enable") != 0) {
24206b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
24216b1b3c3cSJasvinder Singh 		return;
24226b1b3c3cSJasvinder Singh 	}
24236b1b3c3cSJasvinder Singh 
24246b1b3c3cSJasvinder Singh 	status = pipeline_port_in_enable(pipeline_name, port_id);
24256b1b3c3cSJasvinder Singh 	if (status) {
24266b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
24276b1b3c3cSJasvinder Singh 		return;
24286b1b3c3cSJasvinder Singh 	}
24296b1b3c3cSJasvinder Singh }
24306b1b3c3cSJasvinder Singh 
243126b3effeSKevin Laatz 
243226b3effeSKevin Laatz static const char cmd_pipeline_port_in_disable_help[] =
243326b3effeSKevin Laatz "pipeline <pipeline_name> port in <port_id> disable\n";
243426b3effeSKevin Laatz 
24356b1b3c3cSJasvinder Singh static void
cmd_pipeline_port_in_disable(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)24366b1b3c3cSJasvinder Singh cmd_pipeline_port_in_disable(char **tokens,
24376b1b3c3cSJasvinder Singh 	uint32_t n_tokens,
24386b1b3c3cSJasvinder Singh 	char *out,
24396b1b3c3cSJasvinder Singh 	size_t out_size)
24406b1b3c3cSJasvinder Singh {
24416b1b3c3cSJasvinder Singh 	char *pipeline_name;
24426b1b3c3cSJasvinder Singh 	uint32_t port_id;
24436b1b3c3cSJasvinder Singh 	int status;
24446b1b3c3cSJasvinder Singh 
24456b1b3c3cSJasvinder Singh 	if (n_tokens != 6) {
24466b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
24476b1b3c3cSJasvinder Singh 		return;
24486b1b3c3cSJasvinder Singh 	}
24496b1b3c3cSJasvinder Singh 
24506b1b3c3cSJasvinder Singh 	pipeline_name = tokens[1];
24516b1b3c3cSJasvinder Singh 
24526b1b3c3cSJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
24536b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
24546b1b3c3cSJasvinder Singh 		return;
24556b1b3c3cSJasvinder Singh 	}
24566b1b3c3cSJasvinder Singh 
24576b1b3c3cSJasvinder Singh 	if (strcmp(tokens[3], "in") != 0) {
24586b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
24596b1b3c3cSJasvinder Singh 		return;
24606b1b3c3cSJasvinder Singh 	}
24616b1b3c3cSJasvinder Singh 
24626b1b3c3cSJasvinder Singh 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
24636b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
24646b1b3c3cSJasvinder Singh 		return;
24656b1b3c3cSJasvinder Singh 	}
24666b1b3c3cSJasvinder Singh 
24676b1b3c3cSJasvinder Singh 	if (strcmp(tokens[5], "disable") != 0) {
24686b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
24696b1b3c3cSJasvinder Singh 		return;
24706b1b3c3cSJasvinder Singh 	}
24716b1b3c3cSJasvinder Singh 
24726b1b3c3cSJasvinder Singh 	status = pipeline_port_in_disable(pipeline_name, port_id);
24736b1b3c3cSJasvinder Singh 	if (status) {
24746b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
24756b1b3c3cSJasvinder Singh 		return;
24766b1b3c3cSJasvinder Singh 	}
24776b1b3c3cSJasvinder Singh }
24786b1b3c3cSJasvinder Singh 
247926b3effeSKevin Laatz 
248026b3effeSKevin Laatz static const char cmd_pipeline_port_out_stats_help[] =
248126b3effeSKevin Laatz "pipeline <pipeline_name> port out <port_id> stats read [clear]\n";
248226b3effeSKevin Laatz 
248350e73d05SJasvinder Singh #define MSG_PIPELINE_PORT_OUT_STATS                        \
248450e73d05SJasvinder Singh 	"Pkts in: %" PRIu64 "\n"                           \
248550e73d05SJasvinder Singh 	"Pkts dropped by AH: %" PRIu64 "\n"                \
248650e73d05SJasvinder Singh 	"Pkts dropped by other: %" PRIu64 "\n"
248750e73d05SJasvinder Singh 
248850e73d05SJasvinder Singh static void
cmd_pipeline_port_out_stats(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)248950e73d05SJasvinder Singh cmd_pipeline_port_out_stats(char **tokens,
249050e73d05SJasvinder Singh 	uint32_t n_tokens,
249150e73d05SJasvinder Singh 	char *out,
249250e73d05SJasvinder Singh 	size_t out_size)
249350e73d05SJasvinder Singh {
249450e73d05SJasvinder Singh 	struct rte_pipeline_port_out_stats stats;
249550e73d05SJasvinder Singh 	char *pipeline_name;
249650e73d05SJasvinder Singh 	uint32_t port_id;
249750e73d05SJasvinder Singh 	int clear, status;
249850e73d05SJasvinder Singh 
249950e73d05SJasvinder Singh 	if ((n_tokens != 7) && (n_tokens != 8)) {
250050e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
250150e73d05SJasvinder Singh 		return;
250250e73d05SJasvinder Singh 	}
250350e73d05SJasvinder Singh 
250450e73d05SJasvinder Singh 	pipeline_name = tokens[1];
250550e73d05SJasvinder Singh 
250650e73d05SJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
250750e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
250850e73d05SJasvinder Singh 		return;
250950e73d05SJasvinder Singh 	}
251050e73d05SJasvinder Singh 
251150e73d05SJasvinder Singh 	if (strcmp(tokens[3], "out") != 0) {
251250e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
251350e73d05SJasvinder Singh 		return;
251450e73d05SJasvinder Singh 	}
251550e73d05SJasvinder Singh 
251650e73d05SJasvinder Singh 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
251750e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
251850e73d05SJasvinder Singh 		return;
251950e73d05SJasvinder Singh 	}
252050e73d05SJasvinder Singh 
252150e73d05SJasvinder Singh 	if (strcmp(tokens[5], "stats") != 0) {
252250e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
252350e73d05SJasvinder Singh 		return;
252450e73d05SJasvinder Singh 	}
252550e73d05SJasvinder Singh 
252650e73d05SJasvinder Singh 	if (strcmp(tokens[6], "read") != 0) {
252750e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
252850e73d05SJasvinder Singh 		return;
252950e73d05SJasvinder Singh 	}
253050e73d05SJasvinder Singh 
253150e73d05SJasvinder Singh 	clear = 0;
253250e73d05SJasvinder Singh 	if (n_tokens == 8) {
253350e73d05SJasvinder Singh 		if (strcmp(tokens[7], "clear") != 0) {
253450e73d05SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "clear");
253550e73d05SJasvinder Singh 			return;
253650e73d05SJasvinder Singh 		}
253750e73d05SJasvinder Singh 
253850e73d05SJasvinder Singh 		clear = 1;
253950e73d05SJasvinder Singh 	}
254050e73d05SJasvinder Singh 
254150e73d05SJasvinder Singh 	status = pipeline_port_out_stats_read(pipeline_name,
254250e73d05SJasvinder Singh 		port_id,
254350e73d05SJasvinder Singh 		&stats,
254450e73d05SJasvinder Singh 		clear);
254550e73d05SJasvinder Singh 	if (status) {
254650e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
254750e73d05SJasvinder Singh 		return;
254850e73d05SJasvinder Singh 	}
254950e73d05SJasvinder Singh 
255050e73d05SJasvinder Singh 	snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
255150e73d05SJasvinder Singh 		stats.stats.n_pkts_in,
255250e73d05SJasvinder Singh 		stats.n_pkts_dropped_by_ah,
255350e73d05SJasvinder Singh 		stats.stats.n_pkts_drop);
255450e73d05SJasvinder Singh }
255550e73d05SJasvinder Singh 
255626b3effeSKevin Laatz 
255726b3effeSKevin Laatz static const char cmd_pipeline_table_stats_help[] =
255826b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> stats read [clear]\n";
255926b3effeSKevin Laatz 
256050e73d05SJasvinder Singh #define MSG_PIPELINE_TABLE_STATS                                     \
256150e73d05SJasvinder Singh 	"Pkts in: %" PRIu64 "\n"                                     \
256250e73d05SJasvinder Singh 	"Pkts in with lookup miss: %" PRIu64 "\n"                    \
256350e73d05SJasvinder Singh 	"Pkts in with lookup hit dropped by AH: %" PRIu64 "\n"       \
256450e73d05SJasvinder Singh 	"Pkts in with lookup hit dropped by others: %" PRIu64 "\n"   \
256550e73d05SJasvinder Singh 	"Pkts in with lookup miss dropped by AH: %" PRIu64 "\n"      \
256650e73d05SJasvinder Singh 	"Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
256750e73d05SJasvinder Singh 
256850e73d05SJasvinder Singh static void
cmd_pipeline_table_stats(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)256950e73d05SJasvinder Singh cmd_pipeline_table_stats(char **tokens,
257050e73d05SJasvinder Singh 	uint32_t n_tokens,
257150e73d05SJasvinder Singh 	char *out,
257250e73d05SJasvinder Singh 	size_t out_size)
257350e73d05SJasvinder Singh {
257450e73d05SJasvinder Singh 	struct rte_pipeline_table_stats stats;
257550e73d05SJasvinder Singh 	char *pipeline_name;
257650e73d05SJasvinder Singh 	uint32_t table_id;
257750e73d05SJasvinder Singh 	int clear, status;
257850e73d05SJasvinder Singh 
257950e73d05SJasvinder Singh 	if ((n_tokens != 6) && (n_tokens != 7)) {
258050e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
258150e73d05SJasvinder Singh 		return;
258250e73d05SJasvinder Singh 	}
258350e73d05SJasvinder Singh 
258450e73d05SJasvinder Singh 	pipeline_name = tokens[1];
258550e73d05SJasvinder Singh 
258650e73d05SJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
258750e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
258850e73d05SJasvinder Singh 		return;
258950e73d05SJasvinder Singh 	}
259050e73d05SJasvinder Singh 
259150e73d05SJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
259250e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
259350e73d05SJasvinder Singh 		return;
259450e73d05SJasvinder Singh 	}
259550e73d05SJasvinder Singh 
259650e73d05SJasvinder Singh 	if (strcmp(tokens[4], "stats") != 0) {
259750e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
259850e73d05SJasvinder Singh 		return;
259950e73d05SJasvinder Singh 	}
260050e73d05SJasvinder Singh 
260150e73d05SJasvinder Singh 	if (strcmp(tokens[5], "read") != 0) {
260250e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
260350e73d05SJasvinder Singh 		return;
260450e73d05SJasvinder Singh 	}
260550e73d05SJasvinder Singh 
260650e73d05SJasvinder Singh 	clear = 0;
260750e73d05SJasvinder Singh 	if (n_tokens == 7) {
260850e73d05SJasvinder Singh 		if (strcmp(tokens[6], "clear") != 0) {
260950e73d05SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "clear");
261050e73d05SJasvinder Singh 			return;
261150e73d05SJasvinder Singh 		}
261250e73d05SJasvinder Singh 
261350e73d05SJasvinder Singh 		clear = 1;
261450e73d05SJasvinder Singh 	}
261550e73d05SJasvinder Singh 
261650e73d05SJasvinder Singh 	status = pipeline_table_stats_read(pipeline_name,
261750e73d05SJasvinder Singh 		table_id,
261850e73d05SJasvinder Singh 		&stats,
261950e73d05SJasvinder Singh 		clear);
262050e73d05SJasvinder Singh 	if (status) {
262150e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
262250e73d05SJasvinder Singh 		return;
262350e73d05SJasvinder Singh 	}
262450e73d05SJasvinder Singh 
262550e73d05SJasvinder Singh 	snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
262650e73d05SJasvinder Singh 		stats.stats.n_pkts_in,
262750e73d05SJasvinder Singh 		stats.stats.n_pkts_lookup_miss,
262850e73d05SJasvinder Singh 		stats.n_pkts_dropped_by_lkp_hit_ah,
262950e73d05SJasvinder Singh 		stats.n_pkts_dropped_lkp_hit,
263050e73d05SJasvinder Singh 		stats.n_pkts_dropped_by_lkp_miss_ah,
263150e73d05SJasvinder Singh 		stats.n_pkts_dropped_lkp_miss);
263250e73d05SJasvinder Singh }
263350e73d05SJasvinder Singh 
263450e73d05SJasvinder Singh /**
2635a3a95b7dSJasvinder Singh  * <match> ::=
2636a3a95b7dSJasvinder Singh  *
2637a3a95b7dSJasvinder Singh  * match
2638a3a95b7dSJasvinder Singh  *    acl
2639a3a95b7dSJasvinder Singh  *       priority <priority>
2640a3a95b7dSJasvinder Singh  *       ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2641a3a95b7dSJasvinder Singh  *       <sp0> <sp1> <dp0> <dp1> <proto>
2642085c3d8cSJasvinder Singh  *    | array <pos>
2643a3a95b7dSJasvinder Singh  *    | hash
2644a3a95b7dSJasvinder Singh  *       raw <key>
2645a3a95b7dSJasvinder Singh  *       | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2646a3a95b7dSJasvinder Singh  *       | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2647a3a95b7dSJasvinder Singh  *       | ipv4_addr <addr>
2648a3a95b7dSJasvinder Singh  *       | ipv6_addr <addr>
2649a3a95b7dSJasvinder Singh  *       | qinq <svlan> <cvlan>
2650a3a95b7dSJasvinder Singh  *    | lpm
2651a3a95b7dSJasvinder Singh  *       ipv4 | ipv6 <addr> <depth>
2652a3a95b7dSJasvinder Singh  */
2653a3a95b7dSJasvinder Singh struct pkt_key_qinq {
2654a3a95b7dSJasvinder Singh 	uint16_t ethertype_svlan;
2655a3a95b7dSJasvinder Singh 	uint16_t svlan;
2656a3a95b7dSJasvinder Singh 	uint16_t ethertype_cvlan;
2657a3a95b7dSJasvinder Singh 	uint16_t cvlan;
2658ef5baf34SThomas Monjalon } __rte_packed;
2659a3a95b7dSJasvinder Singh 
2660a3a95b7dSJasvinder Singh struct pkt_key_ipv4_5tuple {
2661a3a95b7dSJasvinder Singh 	uint8_t time_to_live;
2662a3a95b7dSJasvinder Singh 	uint8_t proto;
2663a3a95b7dSJasvinder Singh 	uint16_t hdr_checksum;
2664a3a95b7dSJasvinder Singh 	uint32_t sa;
2665a3a95b7dSJasvinder Singh 	uint32_t da;
2666a3a95b7dSJasvinder Singh 	uint16_t sp;
2667a3a95b7dSJasvinder Singh 	uint16_t dp;
2668ef5baf34SThomas Monjalon } __rte_packed;
2669a3a95b7dSJasvinder Singh 
2670a3a95b7dSJasvinder Singh struct pkt_key_ipv6_5tuple {
2671a3a95b7dSJasvinder Singh 	uint16_t payload_length;
2672a3a95b7dSJasvinder Singh 	uint8_t proto;
2673a3a95b7dSJasvinder Singh 	uint8_t hop_limit;
2674a3a95b7dSJasvinder Singh 	uint8_t sa[16];
2675a3a95b7dSJasvinder Singh 	uint8_t da[16];
2676a3a95b7dSJasvinder Singh 	uint16_t sp;
2677a3a95b7dSJasvinder Singh 	uint16_t dp;
2678ef5baf34SThomas Monjalon } __rte_packed;
2679a3a95b7dSJasvinder Singh 
2680a3a95b7dSJasvinder Singh struct pkt_key_ipv4_addr {
2681a3a95b7dSJasvinder Singh 	uint32_t addr;
2682ef5baf34SThomas Monjalon } __rte_packed;
2683a3a95b7dSJasvinder Singh 
2684a3a95b7dSJasvinder Singh struct pkt_key_ipv6_addr {
2685a3a95b7dSJasvinder Singh 	uint8_t addr[16];
2686ef5baf34SThomas Monjalon } __rte_packed;
2687a3a95b7dSJasvinder Singh 
2688a3a95b7dSJasvinder Singh static uint32_t
parse_match(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,struct table_rule_match * m)2689a3a95b7dSJasvinder Singh parse_match(char **tokens,
2690a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
2691a3a95b7dSJasvinder Singh 	char *out,
2692a3a95b7dSJasvinder Singh 	size_t out_size,
2693a3a95b7dSJasvinder Singh 	struct table_rule_match *m)
2694a3a95b7dSJasvinder Singh {
2695a3a95b7dSJasvinder Singh 	memset(m, 0, sizeof(*m));
2696a3a95b7dSJasvinder Singh 
2697a3a95b7dSJasvinder Singh 	if (n_tokens < 2)
2698a3a95b7dSJasvinder Singh 		return 0;
2699a3a95b7dSJasvinder Singh 
2700a3a95b7dSJasvinder Singh 	if (strcmp(tokens[0], "match") != 0) {
2701a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2702a3a95b7dSJasvinder Singh 		return 0;
2703a3a95b7dSJasvinder Singh 	}
2704a3a95b7dSJasvinder Singh 
2705a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "acl") == 0) {
2706a3a95b7dSJasvinder Singh 		if (n_tokens < 14) {
2707a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2708a3a95b7dSJasvinder Singh 			return 0;
2709a3a95b7dSJasvinder Singh 		}
2710a3a95b7dSJasvinder Singh 
2711a3a95b7dSJasvinder Singh 		m->match_type = TABLE_ACL;
2712a3a95b7dSJasvinder Singh 
2713a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "priority") != 0) {
2714a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2715a3a95b7dSJasvinder Singh 			return 0;
2716a3a95b7dSJasvinder Singh 		}
2717a3a95b7dSJasvinder Singh 
2718a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&m->match.acl.priority,
2719a3a95b7dSJasvinder Singh 			tokens[3]) != 0) {
2720a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2721a3a95b7dSJasvinder Singh 			return 0;
2722a3a95b7dSJasvinder Singh 		}
2723a3a95b7dSJasvinder Singh 
2724a3a95b7dSJasvinder Singh 		if (strcmp(tokens[4], "ipv4") == 0) {
2725a3a95b7dSJasvinder Singh 			struct in_addr saddr, daddr;
2726a3a95b7dSJasvinder Singh 
2727a3a95b7dSJasvinder Singh 			m->match.acl.ip_version = 1;
2728a3a95b7dSJasvinder Singh 
2729a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2730a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2731a3a95b7dSJasvinder Singh 				return 0;
2732a3a95b7dSJasvinder Singh 			}
2733a3a95b7dSJasvinder Singh 			m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2734a3a95b7dSJasvinder Singh 
2735a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2736a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "da");
2737a3a95b7dSJasvinder Singh 				return 0;
2738a3a95b7dSJasvinder Singh 			}
2739a3a95b7dSJasvinder Singh 			m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2740a3a95b7dSJasvinder Singh 		} else if (strcmp(tokens[4], "ipv6") == 0) {
2741a3a95b7dSJasvinder Singh 			struct in6_addr saddr, daddr;
2742a3a95b7dSJasvinder Singh 
2743a3a95b7dSJasvinder Singh 			m->match.acl.ip_version = 0;
2744a3a95b7dSJasvinder Singh 
2745a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2746a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2747a3a95b7dSJasvinder Singh 				return 0;
2748a3a95b7dSJasvinder Singh 			}
2749a3a95b7dSJasvinder Singh 			memcpy(m->match.acl.ipv6.sa, saddr.s6_addr, 16);
2750a3a95b7dSJasvinder Singh 
2751a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2752a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "da");
2753a3a95b7dSJasvinder Singh 				return 0;
2754a3a95b7dSJasvinder Singh 			}
2755a3a95b7dSJasvinder Singh 			memcpy(m->match.acl.ipv6.da, daddr.s6_addr, 16);
2756a3a95b7dSJasvinder Singh 		} else {
2757a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2758a3a95b7dSJasvinder Singh 				"ipv4 or ipv6");
2759a3a95b7dSJasvinder Singh 			return 0;
2760a3a95b7dSJasvinder Singh 		}
2761a3a95b7dSJasvinder Singh 
2762a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&m->match.acl.sa_depth,
2763a3a95b7dSJasvinder Singh 			tokens[6]) != 0) {
2764a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2765a3a95b7dSJasvinder Singh 			return 0;
2766a3a95b7dSJasvinder Singh 		}
2767a3a95b7dSJasvinder Singh 
2768a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&m->match.acl.da_depth,
2769a3a95b7dSJasvinder Singh 			tokens[8]) != 0) {
2770a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2771a3a95b7dSJasvinder Singh 			return 0;
2772a3a95b7dSJasvinder Singh 		}
2773a3a95b7dSJasvinder Singh 
2774a3a95b7dSJasvinder Singh 		if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2775a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2776a3a95b7dSJasvinder Singh 			return 0;
2777a3a95b7dSJasvinder Singh 		}
2778a3a95b7dSJasvinder Singh 
2779a3a95b7dSJasvinder Singh 		if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2780a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2781a3a95b7dSJasvinder Singh 			return 0;
2782a3a95b7dSJasvinder Singh 		}
2783a3a95b7dSJasvinder Singh 
2784a3a95b7dSJasvinder Singh 		if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2785a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2786a3a95b7dSJasvinder Singh 			return 0;
2787a3a95b7dSJasvinder Singh 		}
2788a3a95b7dSJasvinder Singh 
2789a3a95b7dSJasvinder Singh 		if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2790a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2791a3a95b7dSJasvinder Singh 			return 0;
2792a3a95b7dSJasvinder Singh 		}
2793a3a95b7dSJasvinder Singh 
2794a3a95b7dSJasvinder Singh 		if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2795a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2796a3a95b7dSJasvinder Singh 			return 0;
2797a3a95b7dSJasvinder Singh 		}
2798a3a95b7dSJasvinder Singh 
2799a3a95b7dSJasvinder Singh 		m->match.acl.proto_mask = 0xff;
2800a3a95b7dSJasvinder Singh 
2801a3a95b7dSJasvinder Singh 		return 14;
2802a3a95b7dSJasvinder Singh 	} /* acl */
2803a3a95b7dSJasvinder Singh 
2804a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "array") == 0) {
2805a3a95b7dSJasvinder Singh 		if (n_tokens < 3) {
2806a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2807a3a95b7dSJasvinder Singh 			return 0;
2808a3a95b7dSJasvinder Singh 		}
2809a3a95b7dSJasvinder Singh 
2810a3a95b7dSJasvinder Singh 		m->match_type = TABLE_ARRAY;
2811a3a95b7dSJasvinder Singh 
2812a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2813a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2814a3a95b7dSJasvinder Singh 			return 0;
2815a3a95b7dSJasvinder Singh 		}
2816a3a95b7dSJasvinder Singh 
2817a3a95b7dSJasvinder Singh 		return 3;
2818a3a95b7dSJasvinder Singh 	} /* array */
2819a3a95b7dSJasvinder Singh 
2820a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "hash") == 0) {
2821a3a95b7dSJasvinder Singh 		if (n_tokens < 3) {
2822a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2823a3a95b7dSJasvinder Singh 			return 0;
2824a3a95b7dSJasvinder Singh 		}
2825a3a95b7dSJasvinder Singh 
2826a3a95b7dSJasvinder Singh 		m->match_type = TABLE_HASH;
2827a3a95b7dSJasvinder Singh 
2828a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "raw") == 0) {
2829a3a95b7dSJasvinder Singh 			uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2830a3a95b7dSJasvinder Singh 
2831a3a95b7dSJasvinder Singh 			if (n_tokens < 4) {
2832a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2833a3a95b7dSJasvinder Singh 					tokens[0]);
2834a3a95b7dSJasvinder Singh 				return 0;
2835a3a95b7dSJasvinder Singh 			}
2836a3a95b7dSJasvinder Singh 
2837a3a95b7dSJasvinder Singh 			if (parse_hex_string(tokens[3],
2838a3a95b7dSJasvinder Singh 				m->match.hash.key, &key_size) != 0) {
2839a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "key");
2840a3a95b7dSJasvinder Singh 				return 0;
2841a3a95b7dSJasvinder Singh 			}
2842a3a95b7dSJasvinder Singh 
2843a3a95b7dSJasvinder Singh 			return 4;
2844a3a95b7dSJasvinder Singh 		} /* hash raw */
2845a3a95b7dSJasvinder Singh 
2846a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2847a3a95b7dSJasvinder Singh 			struct pkt_key_ipv4_5tuple *ipv4 =
2848a3a95b7dSJasvinder Singh 				(struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2849a3a95b7dSJasvinder Singh 			struct in_addr saddr, daddr;
2850a3a95b7dSJasvinder Singh 			uint16_t sp, dp;
2851a3a95b7dSJasvinder Singh 			uint8_t proto;
2852a3a95b7dSJasvinder Singh 
2853a3a95b7dSJasvinder Singh 			if (n_tokens < 8) {
2854a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2855a3a95b7dSJasvinder Singh 					tokens[0]);
2856a3a95b7dSJasvinder Singh 				return 0;
2857a3a95b7dSJasvinder Singh 			}
2858a3a95b7dSJasvinder Singh 
2859a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2860a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2861a3a95b7dSJasvinder Singh 				return 0;
2862a3a95b7dSJasvinder Singh 			}
2863a3a95b7dSJasvinder Singh 
2864a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2865a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "da");
2866a3a95b7dSJasvinder Singh 				return 0;
2867a3a95b7dSJasvinder Singh 			}
2868a3a95b7dSJasvinder Singh 
2869a3a95b7dSJasvinder Singh 			if (parser_read_uint16(&sp, tokens[5]) != 0) {
2870a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2871a3a95b7dSJasvinder Singh 				return 0;
2872a3a95b7dSJasvinder Singh 			}
2873a3a95b7dSJasvinder Singh 
2874a3a95b7dSJasvinder Singh 			if (parser_read_uint16(&dp, tokens[6]) != 0) {
2875a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2876a3a95b7dSJasvinder Singh 				return 0;
2877a3a95b7dSJasvinder Singh 			}
2878a3a95b7dSJasvinder Singh 
2879a3a95b7dSJasvinder Singh 			if (parser_read_uint8(&proto, tokens[7]) != 0) {
2880a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2881a3a95b7dSJasvinder Singh 					"proto");
2882a3a95b7dSJasvinder Singh 				return 0;
2883a3a95b7dSJasvinder Singh 			}
2884a3a95b7dSJasvinder Singh 
2885a3a95b7dSJasvinder Singh 			ipv4->sa = saddr.s_addr;
2886a3a95b7dSJasvinder Singh 			ipv4->da = daddr.s_addr;
2887a3a95b7dSJasvinder Singh 			ipv4->sp = rte_cpu_to_be_16(sp);
2888a3a95b7dSJasvinder Singh 			ipv4->dp = rte_cpu_to_be_16(dp);
2889a3a95b7dSJasvinder Singh 			ipv4->proto = proto;
2890a3a95b7dSJasvinder Singh 
2891a3a95b7dSJasvinder Singh 			return 8;
2892a3a95b7dSJasvinder Singh 		} /* hash ipv4_5tuple */
2893a3a95b7dSJasvinder Singh 
2894a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2895a3a95b7dSJasvinder Singh 			struct pkt_key_ipv6_5tuple *ipv6 =
2896a3a95b7dSJasvinder Singh 				(struct pkt_key_ipv6_5tuple *) m->match.hash.key;
2897a3a95b7dSJasvinder Singh 			struct in6_addr saddr, daddr;
2898a3a95b7dSJasvinder Singh 			uint16_t sp, dp;
2899a3a95b7dSJasvinder Singh 			uint8_t proto;
2900a3a95b7dSJasvinder Singh 
2901a3a95b7dSJasvinder Singh 			if (n_tokens < 8) {
2902a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2903a3a95b7dSJasvinder Singh 					tokens[0]);
2904a3a95b7dSJasvinder Singh 				return 0;
2905a3a95b7dSJasvinder Singh 			}
2906a3a95b7dSJasvinder Singh 
2907a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2908a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2909a3a95b7dSJasvinder Singh 				return 0;
2910a3a95b7dSJasvinder Singh 			}
2911a3a95b7dSJasvinder Singh 
2912a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2913a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "da");
2914a3a95b7dSJasvinder Singh 				return 0;
2915a3a95b7dSJasvinder Singh 			}
2916a3a95b7dSJasvinder Singh 
2917a3a95b7dSJasvinder Singh 			if (parser_read_uint16(&sp, tokens[5]) != 0) {
2918a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2919a3a95b7dSJasvinder Singh 				return 0;
2920a3a95b7dSJasvinder Singh 			}
2921a3a95b7dSJasvinder Singh 
2922a3a95b7dSJasvinder Singh 			if (parser_read_uint16(&dp, tokens[6]) != 0) {
2923a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2924a3a95b7dSJasvinder Singh 				return 0;
2925a3a95b7dSJasvinder Singh 			}
2926a3a95b7dSJasvinder Singh 
2927a3a95b7dSJasvinder Singh 			if (parser_read_uint8(&proto, tokens[7]) != 0) {
2928a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2929a3a95b7dSJasvinder Singh 					"proto");
2930a3a95b7dSJasvinder Singh 				return 0;
2931a3a95b7dSJasvinder Singh 			}
2932a3a95b7dSJasvinder Singh 
2933a3a95b7dSJasvinder Singh 			memcpy(ipv6->sa, saddr.s6_addr, 16);
2934a3a95b7dSJasvinder Singh 			memcpy(ipv6->da, daddr.s6_addr, 16);
2935a3a95b7dSJasvinder Singh 			ipv6->sp = rte_cpu_to_be_16(sp);
2936a3a95b7dSJasvinder Singh 			ipv6->dp = rte_cpu_to_be_16(dp);
2937a3a95b7dSJasvinder Singh 			ipv6->proto = proto;
2938a3a95b7dSJasvinder Singh 
2939a3a95b7dSJasvinder Singh 			return 8;
2940a3a95b7dSJasvinder Singh 		} /* hash ipv6_5tuple */
2941a3a95b7dSJasvinder Singh 
2942a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "ipv4_addr") == 0) {
2943a3a95b7dSJasvinder Singh 			struct pkt_key_ipv4_addr *ipv4_addr =
2944a3a95b7dSJasvinder Singh 				(struct pkt_key_ipv4_addr *) m->match.hash.key;
2945a3a95b7dSJasvinder Singh 			struct in_addr addr;
2946a3a95b7dSJasvinder Singh 
2947a3a95b7dSJasvinder Singh 			if (n_tokens < 4) {
2948a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2949a3a95b7dSJasvinder Singh 					tokens[0]);
2950a3a95b7dSJasvinder Singh 				return 0;
2951a3a95b7dSJasvinder Singh 			}
2952a3a95b7dSJasvinder Singh 
2953a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2954a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2955a3a95b7dSJasvinder Singh 					"addr");
2956a3a95b7dSJasvinder Singh 				return 0;
2957a3a95b7dSJasvinder Singh 			}
2958a3a95b7dSJasvinder Singh 
2959a3a95b7dSJasvinder Singh 			ipv4_addr->addr = addr.s_addr;
2960a3a95b7dSJasvinder Singh 
2961a3a95b7dSJasvinder Singh 			return 4;
2962a3a95b7dSJasvinder Singh 		} /* hash ipv4_addr */
2963a3a95b7dSJasvinder Singh 
2964a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "ipv6_addr") == 0) {
2965a3a95b7dSJasvinder Singh 			struct pkt_key_ipv6_addr *ipv6_addr =
2966a3a95b7dSJasvinder Singh 				(struct pkt_key_ipv6_addr *) m->match.hash.key;
2967a3a95b7dSJasvinder Singh 			struct in6_addr addr;
2968a3a95b7dSJasvinder Singh 
2969a3a95b7dSJasvinder Singh 			if (n_tokens < 4) {
2970a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2971a3a95b7dSJasvinder Singh 					tokens[0]);
2972a3a95b7dSJasvinder Singh 				return 0;
2973a3a95b7dSJasvinder Singh 			}
2974a3a95b7dSJasvinder Singh 
2975a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2976a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2977a3a95b7dSJasvinder Singh 					"addr");
2978a3a95b7dSJasvinder Singh 				return 0;
2979a3a95b7dSJasvinder Singh 			}
2980a3a95b7dSJasvinder Singh 
2981a3a95b7dSJasvinder Singh 			memcpy(ipv6_addr->addr, addr.s6_addr, 16);
2982a3a95b7dSJasvinder Singh 
2983a3a95b7dSJasvinder Singh 			return 4;
2984a3a95b7dSJasvinder Singh 		} /* hash ipv6_5tuple */
2985a3a95b7dSJasvinder Singh 
2986a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "qinq") == 0) {
2987a3a95b7dSJasvinder Singh 			struct pkt_key_qinq *qinq =
2988a3a95b7dSJasvinder Singh 				(struct pkt_key_qinq *) m->match.hash.key;
2989a3a95b7dSJasvinder Singh 			uint16_t svlan, cvlan;
2990a3a95b7dSJasvinder Singh 
2991a3a95b7dSJasvinder Singh 			if (n_tokens < 5) {
2992a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2993a3a95b7dSJasvinder Singh 					tokens[0]);
2994a3a95b7dSJasvinder Singh 				return 0;
2995a3a95b7dSJasvinder Singh 			}
2996a3a95b7dSJasvinder Singh 
2997a3a95b7dSJasvinder Singh 			if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
2998a3a95b7dSJasvinder Singh 				(svlan > 0xFFF)) {
2999a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
3000a3a95b7dSJasvinder Singh 					"svlan");
3001a3a95b7dSJasvinder Singh 				return 0;
3002a3a95b7dSJasvinder Singh 			}
3003a3a95b7dSJasvinder Singh 
3004a3a95b7dSJasvinder Singh 			if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
3005a3a95b7dSJasvinder Singh 				(cvlan > 0xFFF)) {
3006a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
3007a3a95b7dSJasvinder Singh 					"cvlan");
3008a3a95b7dSJasvinder Singh 				return 0;
3009a3a95b7dSJasvinder Singh 			}
3010a3a95b7dSJasvinder Singh 
3011a3a95b7dSJasvinder Singh 			qinq->svlan = rte_cpu_to_be_16(svlan);
3012a3a95b7dSJasvinder Singh 			qinq->cvlan = rte_cpu_to_be_16(cvlan);
3013a3a95b7dSJasvinder Singh 
3014a3a95b7dSJasvinder Singh 			return 5;
3015a3a95b7dSJasvinder Singh 		} /* hash qinq */
3016a3a95b7dSJasvinder Singh 
3017a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3018a3a95b7dSJasvinder Singh 		return 0;
3019a3a95b7dSJasvinder Singh 	} /* hash */
3020a3a95b7dSJasvinder Singh 
3021a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "lpm") == 0) {
3022a3a95b7dSJasvinder Singh 		if (n_tokens < 5) {
3023a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3024a3a95b7dSJasvinder Singh 			return 0;
3025a3a95b7dSJasvinder Singh 		}
3026a3a95b7dSJasvinder Singh 
3027a3a95b7dSJasvinder Singh 		m->match_type = TABLE_LPM;
3028a3a95b7dSJasvinder Singh 
3029a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "ipv4") == 0) {
3030a3a95b7dSJasvinder Singh 			struct in_addr addr;
3031a3a95b7dSJasvinder Singh 
3032a3a95b7dSJasvinder Singh 			m->match.lpm.ip_version = 1;
3033a3a95b7dSJasvinder Singh 
3034a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[3], &addr) != 0) {
3035a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
3036a3a95b7dSJasvinder Singh 					"addr");
3037a3a95b7dSJasvinder Singh 				return 0;
3038a3a95b7dSJasvinder Singh 			}
3039a3a95b7dSJasvinder Singh 
3040a3a95b7dSJasvinder Singh 			m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3041a3a95b7dSJasvinder Singh 		} else if (strcmp(tokens[2], "ipv6") == 0) {
3042a3a95b7dSJasvinder Singh 			struct in6_addr addr;
3043a3a95b7dSJasvinder Singh 
3044a3a95b7dSJasvinder Singh 			m->match.lpm.ip_version = 0;
3045a3a95b7dSJasvinder Singh 
3046a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[3], &addr) != 0) {
3047a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
3048a3a95b7dSJasvinder Singh 					"addr");
3049a3a95b7dSJasvinder Singh 				return 0;
3050a3a95b7dSJasvinder Singh 			}
3051a3a95b7dSJasvinder Singh 
3052a3a95b7dSJasvinder Singh 			memcpy(m->match.lpm.ipv6, addr.s6_addr, 16);
3053a3a95b7dSJasvinder Singh 		} else {
3054a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
3055a3a95b7dSJasvinder Singh 				"ipv4 or ipv6");
3056a3a95b7dSJasvinder Singh 			return 0;
3057a3a95b7dSJasvinder Singh 		}
3058a3a95b7dSJasvinder Singh 
3059a3a95b7dSJasvinder Singh 		if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
3060a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "depth");
3061a3a95b7dSJasvinder Singh 			return 0;
3062a3a95b7dSJasvinder Singh 		}
3063a3a95b7dSJasvinder Singh 
3064a3a95b7dSJasvinder Singh 		return 5;
3065a3a95b7dSJasvinder Singh 	} /* lpm */
3066a3a95b7dSJasvinder Singh 
3067a3a95b7dSJasvinder Singh 	snprintf(out, out_size, MSG_ARG_MISMATCH,
3068a3a95b7dSJasvinder Singh 		"acl or array or hash or lpm");
3069a3a95b7dSJasvinder Singh 	return 0;
3070a3a95b7dSJasvinder Singh }
3071a3a95b7dSJasvinder Singh 
3072a3a95b7dSJasvinder Singh /**
3073a3a95b7dSJasvinder Singh  * table_action ::=
3074a3a95b7dSJasvinder Singh  *
3075a3a95b7dSJasvinder Singh  * action
3076a3a95b7dSJasvinder Singh  *    fwd
3077a3a95b7dSJasvinder Singh  *       drop
3078a3a95b7dSJasvinder Singh  *       | port <port_id>
3079a3a95b7dSJasvinder Singh  *       | meta
3080a3a95b7dSJasvinder Singh  *       | table <table_id>
3081a3a95b7dSJasvinder Singh  *    [balance <out0> ... <out7>]
3082a3a95b7dSJasvinder Singh  *    [meter
3083a3a95b7dSJasvinder Singh  *       tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3084a3a95b7dSJasvinder Singh  *       [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3085a3a95b7dSJasvinder Singh  *       tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3086a3a95b7dSJasvinder Singh  *       tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3087a3a95b7dSJasvinder Singh  *    [tm subport <subport_id> pipe <pipe_id>]
3088a3a95b7dSJasvinder Singh  *    [encap
3089a3a95b7dSJasvinder Singh  *       ether <da> <sa>
3090a3a95b7dSJasvinder Singh  *       | vlan <da> <sa> <pcp> <dei> <vid>
3091a3a95b7dSJasvinder Singh  *       | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
309233e7afe6SNemanja Marjanovic  *       | qinq_pppoe <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid> <session_id>
3093a3a95b7dSJasvinder Singh  *       | mpls unicast | multicast
3094a3a95b7dSJasvinder Singh  *          <da> <sa>
3095a3a95b7dSJasvinder Singh  *          label0 <label> <tc> <ttl>
3096a3a95b7dSJasvinder Singh  *          [label1 <label> <tc> <ttl>
3097a3a95b7dSJasvinder Singh  *          [label2 <label> <tc> <ttl>
3098a3a95b7dSJasvinder Singh  *          [label3 <label> <tc> <ttl>]]]
309944cad685SCristian Dumitrescu  *       | pppoe <da> <sa> <session_id>
310044cad685SCristian Dumitrescu  *       | vxlan ether <da> <sa>
310144cad685SCristian Dumitrescu  *          [vlan <pcp> <dei> <vid>]
310244cad685SCristian Dumitrescu  *          ipv4 <sa> <da> <dscp> <ttl>
310344cad685SCristian Dumitrescu  *          | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
310444cad685SCristian Dumitrescu  *          udp <sp> <dp>
310544cad685SCristian Dumitrescu  *          vxlan <vni>]
3106a3a95b7dSJasvinder Singh  *    [nat ipv4 | ipv6 <addr> <port>]
3107a3a95b7dSJasvinder Singh  *    [ttl dec | keep]
3108a3a95b7dSJasvinder Singh  *    [stats]
3109a3a95b7dSJasvinder Singh  *    [time]
31101edccebcSFan Zhang  *    [sym_crypto
31111edccebcSFan Zhang  *       encrypt | decrypt
31121edccebcSFan Zhang  *       type
31131edccebcSFan Zhang  *       | cipher
31141edccebcSFan Zhang  *          cipher_algo <algo> cipher_key <key> cipher_iv <iv>
31151edccebcSFan Zhang  *       | cipher_auth
31161edccebcSFan Zhang  *          cipher_algo <algo> cipher_key <key> cipher_iv <iv>
31171edccebcSFan Zhang  *          auth_algo <algo> auth_key <key> digest_size <size>
31181edccebcSFan Zhang  *       | aead
31191edccebcSFan Zhang  *          aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
31201edccebcSFan Zhang  *          digest_size <size>
31211edccebcSFan Zhang  *       data_offset <data_offset>]
31221bdf2632SCristian Dumitrescu  *    [tag <tag>]
3123d5ed626fSCristian Dumitrescu  *    [decap <n>]
3124a3a95b7dSJasvinder Singh  *
3125a3a95b7dSJasvinder Singh  * where:
3126a3a95b7dSJasvinder Singh  *    <pa> ::= g | y | r | drop
3127a3a95b7dSJasvinder Singh  */
3128a3a95b7dSJasvinder Singh static uint32_t
parse_table_action_fwd(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)3129a3a95b7dSJasvinder Singh parse_table_action_fwd(char **tokens,
3130a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3131a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3132a3a95b7dSJasvinder Singh {
3133a3a95b7dSJasvinder Singh 	if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
3134a3a95b7dSJasvinder Singh 		return 0;
3135a3a95b7dSJasvinder Singh 
3136a3a95b7dSJasvinder Singh 	tokens++;
3137a3a95b7dSJasvinder Singh 	n_tokens--;
3138a3a95b7dSJasvinder Singh 
3139a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3140a3a95b7dSJasvinder Singh 		a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3141a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3142a3a95b7dSJasvinder Singh 		return 1 + 1;
3143a3a95b7dSJasvinder Singh 	}
3144a3a95b7dSJasvinder Singh 
3145a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3146a3a95b7dSJasvinder Singh 		uint32_t id;
3147a3a95b7dSJasvinder Singh 
3148a3a95b7dSJasvinder Singh 		if ((n_tokens < 2) ||
3149a3a95b7dSJasvinder Singh 			parser_read_uint32(&id, tokens[1]))
3150a3a95b7dSJasvinder Singh 			return 0;
3151a3a95b7dSJasvinder Singh 
3152a3a95b7dSJasvinder Singh 		a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3153a3a95b7dSJasvinder Singh 		a->fwd.id = id;
3154a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3155a3a95b7dSJasvinder Singh 		return 1 + 2;
3156a3a95b7dSJasvinder Singh 	}
3157a3a95b7dSJasvinder Singh 
3158a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3159a3a95b7dSJasvinder Singh 		a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3160a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3161a3a95b7dSJasvinder Singh 		return 1 + 1;
3162a3a95b7dSJasvinder Singh 	}
3163a3a95b7dSJasvinder Singh 
3164a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3165a3a95b7dSJasvinder Singh 		uint32_t id;
3166a3a95b7dSJasvinder Singh 
3167a3a95b7dSJasvinder Singh 		if ((n_tokens < 2) ||
3168a3a95b7dSJasvinder Singh 			parser_read_uint32(&id, tokens[1]))
3169a3a95b7dSJasvinder Singh 			return 0;
3170a3a95b7dSJasvinder Singh 
3171a3a95b7dSJasvinder Singh 		a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3172a3a95b7dSJasvinder Singh 		a->fwd.id = id;
3173a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3174a3a95b7dSJasvinder Singh 		return 1 + 2;
3175a3a95b7dSJasvinder Singh 	}
3176a3a95b7dSJasvinder Singh 
3177a3a95b7dSJasvinder Singh 	return 0;
3178a3a95b7dSJasvinder Singh }
3179a3a95b7dSJasvinder Singh 
3180802755dcSJasvinder Singh static uint32_t
parse_table_action_balance(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)3181802755dcSJasvinder Singh parse_table_action_balance(char **tokens,
3182802755dcSJasvinder Singh 	uint32_t n_tokens,
3183802755dcSJasvinder Singh 	struct table_rule_action *a)
3184802755dcSJasvinder Singh {
3185802755dcSJasvinder Singh 	uint32_t i;
3186802755dcSJasvinder Singh 
3187802755dcSJasvinder Singh 	if ((n_tokens == 0) || (strcmp(tokens[0], "balance") != 0))
3188802755dcSJasvinder Singh 		return 0;
3189802755dcSJasvinder Singh 
3190802755dcSJasvinder Singh 	tokens++;
3191802755dcSJasvinder Singh 	n_tokens--;
3192802755dcSJasvinder Singh 
3193085c3d8cSJasvinder Singh 	if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3194802755dcSJasvinder Singh 		return 0;
3195802755dcSJasvinder Singh 
3196085c3d8cSJasvinder Singh 	for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3197802755dcSJasvinder Singh 		if (parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3198802755dcSJasvinder Singh 			return 0;
3199802755dcSJasvinder Singh 
3200802755dcSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3201085c3d8cSJasvinder Singh 	return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3202802755dcSJasvinder Singh 
3203802755dcSJasvinder Singh }
3204802755dcSJasvinder Singh 
3205a3a95b7dSJasvinder Singh static int
parse_policer_action(char * token,enum rte_table_action_policer * a)3206a3a95b7dSJasvinder Singh parse_policer_action(char *token, enum rte_table_action_policer *a)
3207a3a95b7dSJasvinder Singh {
3208a3a95b7dSJasvinder Singh 	if (strcmp(token, "g") == 0) {
3209a3a95b7dSJasvinder Singh 		*a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3210a3a95b7dSJasvinder Singh 		return 0;
3211a3a95b7dSJasvinder Singh 	}
3212a3a95b7dSJasvinder Singh 
3213a3a95b7dSJasvinder Singh 	if (strcmp(token, "y") == 0) {
3214a3a95b7dSJasvinder Singh 		*a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3215a3a95b7dSJasvinder Singh 		return 0;
3216a3a95b7dSJasvinder Singh 	}
3217a3a95b7dSJasvinder Singh 
3218a3a95b7dSJasvinder Singh 	if (strcmp(token, "r") == 0) {
3219a3a95b7dSJasvinder Singh 		*a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3220a3a95b7dSJasvinder Singh 		return 0;
3221a3a95b7dSJasvinder Singh 	}
3222a3a95b7dSJasvinder Singh 
3223a3a95b7dSJasvinder Singh 	if (strcmp(token, "drop") == 0) {
3224a3a95b7dSJasvinder Singh 		*a = RTE_TABLE_ACTION_POLICER_DROP;
3225a3a95b7dSJasvinder Singh 		return 0;
3226a3a95b7dSJasvinder Singh 	}
3227a3a95b7dSJasvinder Singh 
3228a3a95b7dSJasvinder Singh 	return -1;
3229a3a95b7dSJasvinder Singh }
3230a3a95b7dSJasvinder Singh 
3231a3a95b7dSJasvinder Singh static uint32_t
parse_table_action_meter_tc(char ** tokens,uint32_t n_tokens,struct rte_table_action_mtr_tc_params * mtr)3232a3a95b7dSJasvinder Singh parse_table_action_meter_tc(char **tokens,
3233a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3234a3a95b7dSJasvinder Singh 	struct rte_table_action_mtr_tc_params *mtr)
3235a3a95b7dSJasvinder Singh {
3236a3a95b7dSJasvinder Singh 	if ((n_tokens < 9) ||
3237a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "meter") ||
3238a3a95b7dSJasvinder Singh 		parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3239a3a95b7dSJasvinder Singh 		strcmp(tokens[2], "policer") ||
3240a3a95b7dSJasvinder Singh 		strcmp(tokens[3], "g") ||
3241c1656328SJasvinder Singh 		parse_policer_action(tokens[4], &mtr->policer[RTE_COLOR_GREEN]) ||
3242a3a95b7dSJasvinder Singh 		strcmp(tokens[5], "y") ||
3243c1656328SJasvinder Singh 		parse_policer_action(tokens[6], &mtr->policer[RTE_COLOR_YELLOW]) ||
3244a3a95b7dSJasvinder Singh 		strcmp(tokens[7], "r") ||
3245c1656328SJasvinder Singh 		parse_policer_action(tokens[8], &mtr->policer[RTE_COLOR_RED]))
3246a3a95b7dSJasvinder Singh 		return 0;
3247a3a95b7dSJasvinder Singh 
3248a3a95b7dSJasvinder Singh 	return 9;
3249a3a95b7dSJasvinder Singh }
3250a3a95b7dSJasvinder Singh 
3251a3a95b7dSJasvinder Singh static uint32_t
parse_table_action_meter(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)3252a3a95b7dSJasvinder Singh parse_table_action_meter(char **tokens,
3253a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3254a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3255a3a95b7dSJasvinder Singh {
3256a3a95b7dSJasvinder Singh 	if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
3257a3a95b7dSJasvinder Singh 		return 0;
3258a3a95b7dSJasvinder Singh 
3259a3a95b7dSJasvinder Singh 	tokens++;
3260a3a95b7dSJasvinder Singh 	n_tokens--;
3261a3a95b7dSJasvinder Singh 
3262a3a95b7dSJasvinder Singh 	if ((n_tokens < 10) ||
3263a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "tc0") ||
3264a3a95b7dSJasvinder Singh 		(parse_table_action_meter_tc(tokens + 1,
3265a3a95b7dSJasvinder Singh 			n_tokens - 1,
3266a3a95b7dSJasvinder Singh 			&a->mtr.mtr[0]) == 0))
3267a3a95b7dSJasvinder Singh 		return 0;
3268a3a95b7dSJasvinder Singh 
3269a3a95b7dSJasvinder Singh 	tokens += 10;
3270a3a95b7dSJasvinder Singh 	n_tokens -= 10;
3271a3a95b7dSJasvinder Singh 
3272a3a95b7dSJasvinder Singh 	if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
3273a3a95b7dSJasvinder Singh 		a->mtr.tc_mask = 1;
3274a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3275a3a95b7dSJasvinder Singh 		return 1 + 10;
3276a3a95b7dSJasvinder Singh 	}
3277a3a95b7dSJasvinder Singh 
3278a3a95b7dSJasvinder Singh 	if ((n_tokens < 30) ||
3279a3a95b7dSJasvinder Singh 		(parse_table_action_meter_tc(tokens + 1,
3280a3a95b7dSJasvinder Singh 			n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3281a3a95b7dSJasvinder Singh 		strcmp(tokens[10], "tc2") ||
3282a3a95b7dSJasvinder Singh 		(parse_table_action_meter_tc(tokens + 11,
3283a3a95b7dSJasvinder Singh 			n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3284a3a95b7dSJasvinder Singh 		strcmp(tokens[20], "tc3") ||
3285a3a95b7dSJasvinder Singh 		(parse_table_action_meter_tc(tokens + 21,
3286a3a95b7dSJasvinder Singh 			n_tokens - 21, &a->mtr.mtr[3]) == 0))
3287a3a95b7dSJasvinder Singh 		return 0;
3288a3a95b7dSJasvinder Singh 
3289a3a95b7dSJasvinder Singh 	a->mtr.tc_mask = 0xF;
3290a3a95b7dSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3291a3a95b7dSJasvinder Singh 	return 1 + 10 + 3 * 10;
3292a3a95b7dSJasvinder Singh }
3293a3a95b7dSJasvinder Singh 
3294a3a95b7dSJasvinder Singh static uint32_t
parse_table_action_tm(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)3295a3a95b7dSJasvinder Singh parse_table_action_tm(char **tokens,
3296a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3297a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3298a3a95b7dSJasvinder Singh {
3299a3a95b7dSJasvinder Singh 	uint32_t subport_id, pipe_id;
3300a3a95b7dSJasvinder Singh 
3301a3a95b7dSJasvinder Singh 	if ((n_tokens < 5) ||
3302a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "tm") ||
3303a3a95b7dSJasvinder Singh 		strcmp(tokens[1], "subport") ||
3304a3a95b7dSJasvinder Singh 		parser_read_uint32(&subport_id, tokens[2]) ||
3305a3a95b7dSJasvinder Singh 		strcmp(tokens[3], "pipe") ||
3306a3a95b7dSJasvinder Singh 		parser_read_uint32(&pipe_id, tokens[4]))
3307a3a95b7dSJasvinder Singh 		return 0;
3308a3a95b7dSJasvinder Singh 
3309a3a95b7dSJasvinder Singh 	a->tm.subport_id = subport_id;
3310a3a95b7dSJasvinder Singh 	a->tm.pipe_id = pipe_id;
3311a3a95b7dSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3312a3a95b7dSJasvinder Singh 	return 5;
3313a3a95b7dSJasvinder Singh }
3314a3a95b7dSJasvinder Singh 
3315a3a95b7dSJasvinder Singh static uint32_t
parse_table_action_encap(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)3316a3a95b7dSJasvinder Singh parse_table_action_encap(char **tokens,
3317a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3318a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3319a3a95b7dSJasvinder Singh {
3320a3a95b7dSJasvinder Singh 	if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
3321a3a95b7dSJasvinder Singh 		return 0;
3322a3a95b7dSJasvinder Singh 
3323a3a95b7dSJasvinder Singh 	tokens++;
3324a3a95b7dSJasvinder Singh 	n_tokens--;
3325a3a95b7dSJasvinder Singh 
3326a3a95b7dSJasvinder Singh 	/* ether */
3327a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3328a3a95b7dSJasvinder Singh 		if ((n_tokens < 3) ||
3329a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3330a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3331a3a95b7dSJasvinder Singh 			return 0;
3332a3a95b7dSJasvinder Singh 
3333a3a95b7dSJasvinder Singh 		a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3334a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3335a3a95b7dSJasvinder Singh 		return 1 + 3;
3336a3a95b7dSJasvinder Singh 	}
3337a3a95b7dSJasvinder Singh 
3338a3a95b7dSJasvinder Singh 	/* vlan */
3339a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3340a3a95b7dSJasvinder Singh 		uint32_t pcp, dei, vid;
3341a3a95b7dSJasvinder Singh 
3342a3a95b7dSJasvinder Singh 		if ((n_tokens < 6) ||
3343a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3344a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3345a3a95b7dSJasvinder Singh 			parser_read_uint32(&pcp, tokens[3]) ||
3346a3a95b7dSJasvinder Singh 			(pcp > 0x7) ||
3347a3a95b7dSJasvinder Singh 			parser_read_uint32(&dei, tokens[4]) ||
3348a3a95b7dSJasvinder Singh 			(dei > 0x1) ||
3349a3a95b7dSJasvinder Singh 			parser_read_uint32(&vid, tokens[5]) ||
3350a3a95b7dSJasvinder Singh 			(vid > 0xFFF))
3351a3a95b7dSJasvinder Singh 			return 0;
3352a3a95b7dSJasvinder Singh 
3353a3a95b7dSJasvinder Singh 		a->encap.vlan.vlan.pcp = pcp & 0x7;
3354a3a95b7dSJasvinder Singh 		a->encap.vlan.vlan.dei = dei & 0x1;
3355a3a95b7dSJasvinder Singh 		a->encap.vlan.vlan.vid = vid & 0xFFF;
3356a3a95b7dSJasvinder Singh 		a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3357a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3358a3a95b7dSJasvinder Singh 		return 1 + 6;
3359a3a95b7dSJasvinder Singh 	}
3360a3a95b7dSJasvinder Singh 
3361a3a95b7dSJasvinder Singh 	/* qinq */
3362a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3363a3a95b7dSJasvinder Singh 		uint32_t svlan_pcp, svlan_dei, svlan_vid;
3364a3a95b7dSJasvinder Singh 		uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3365a3a95b7dSJasvinder Singh 
3366a3a95b7dSJasvinder Singh 		if ((n_tokens < 9) ||
3367a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3368a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3369a3a95b7dSJasvinder Singh 			parser_read_uint32(&svlan_pcp, tokens[3]) ||
3370a3a95b7dSJasvinder Singh 			(svlan_pcp > 0x7) ||
3371a3a95b7dSJasvinder Singh 			parser_read_uint32(&svlan_dei, tokens[4]) ||
3372a3a95b7dSJasvinder Singh 			(svlan_dei > 0x1) ||
3373a3a95b7dSJasvinder Singh 			parser_read_uint32(&svlan_vid, tokens[5]) ||
3374a3a95b7dSJasvinder Singh 			(svlan_vid > 0xFFF) ||
3375a3a95b7dSJasvinder Singh 			parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3376a3a95b7dSJasvinder Singh 			(cvlan_pcp > 0x7) ||
3377a3a95b7dSJasvinder Singh 			parser_read_uint32(&cvlan_dei, tokens[7]) ||
3378a3a95b7dSJasvinder Singh 			(cvlan_dei > 0x1) ||
3379a3a95b7dSJasvinder Singh 			parser_read_uint32(&cvlan_vid, tokens[8]) ||
3380a3a95b7dSJasvinder Singh 			(cvlan_vid > 0xFFF))
3381a3a95b7dSJasvinder Singh 			return 0;
3382a3a95b7dSJasvinder Singh 
3383a3a95b7dSJasvinder Singh 		a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3384a3a95b7dSJasvinder Singh 		a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3385a3a95b7dSJasvinder Singh 		a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3386a3a95b7dSJasvinder Singh 		a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3387a3a95b7dSJasvinder Singh 		a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3388a3a95b7dSJasvinder Singh 		a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3389a3a95b7dSJasvinder Singh 		a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3390a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3391a3a95b7dSJasvinder Singh 		return 1 + 9;
3392a3a95b7dSJasvinder Singh 	}
3393a3a95b7dSJasvinder Singh 
339433e7afe6SNemanja Marjanovic 	/* qinq_pppoe */
339533e7afe6SNemanja Marjanovic 	if (n_tokens && (strcmp(tokens[0], "qinq_pppoe") == 0)) {
339633e7afe6SNemanja Marjanovic 		uint32_t svlan_pcp, svlan_dei, svlan_vid;
339733e7afe6SNemanja Marjanovic 		uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
339833e7afe6SNemanja Marjanovic 
339933e7afe6SNemanja Marjanovic 		if ((n_tokens < 10) ||
340033e7afe6SNemanja Marjanovic 			parse_mac_addr(tokens[1],
340133e7afe6SNemanja Marjanovic 				&a->encap.qinq_pppoe.ether.da) ||
340233e7afe6SNemanja Marjanovic 			parse_mac_addr(tokens[2],
340333e7afe6SNemanja Marjanovic 				&a->encap.qinq_pppoe.ether.sa) ||
340433e7afe6SNemanja Marjanovic 			parser_read_uint32(&svlan_pcp, tokens[3]) ||
340533e7afe6SNemanja Marjanovic 			(svlan_pcp > 0x7) ||
340633e7afe6SNemanja Marjanovic 			parser_read_uint32(&svlan_dei, tokens[4]) ||
340733e7afe6SNemanja Marjanovic 			(svlan_dei > 0x1) ||
340833e7afe6SNemanja Marjanovic 			parser_read_uint32(&svlan_vid, tokens[5]) ||
340933e7afe6SNemanja Marjanovic 			(svlan_vid > 0xFFF) ||
341033e7afe6SNemanja Marjanovic 			parser_read_uint32(&cvlan_pcp, tokens[6]) ||
341133e7afe6SNemanja Marjanovic 			(cvlan_pcp > 0x7) ||
341233e7afe6SNemanja Marjanovic 			parser_read_uint32(&cvlan_dei, tokens[7]) ||
341333e7afe6SNemanja Marjanovic 			(cvlan_dei > 0x1) ||
341433e7afe6SNemanja Marjanovic 			parser_read_uint32(&cvlan_vid, tokens[8]) ||
341533e7afe6SNemanja Marjanovic 			(cvlan_vid > 0xFFF) ||
341633e7afe6SNemanja Marjanovic 			parser_read_uint16(&a->encap.qinq_pppoe.pppoe.session_id,
341733e7afe6SNemanja Marjanovic 				tokens[9]))
341833e7afe6SNemanja Marjanovic 			return 0;
341933e7afe6SNemanja Marjanovic 
342033e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.svlan.pcp = svlan_pcp & 0x7;
342133e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.svlan.dei = svlan_dei & 0x1;
342233e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.svlan.vid = svlan_vid & 0xFFF;
342333e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.cvlan.pcp = cvlan_pcp & 0x7;
342433e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.cvlan.dei = cvlan_dei & 0x1;
342533e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.cvlan.vid = cvlan_vid & 0xFFF;
342633e7afe6SNemanja Marjanovic 		a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
342733e7afe6SNemanja Marjanovic 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
342833e7afe6SNemanja Marjanovic 		return 1 + 10;
342933e7afe6SNemanja Marjanovic 
343033e7afe6SNemanja Marjanovic 	}
343133e7afe6SNemanja Marjanovic 
3432a3a95b7dSJasvinder Singh 	/* mpls */
3433a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3434a3a95b7dSJasvinder Singh 		uint32_t label, tc, ttl;
3435a3a95b7dSJasvinder Singh 
3436a3a95b7dSJasvinder Singh 		if (n_tokens < 8)
3437a3a95b7dSJasvinder Singh 			return 0;
3438a3a95b7dSJasvinder Singh 
3439a3a95b7dSJasvinder Singh 		if (strcmp(tokens[1], "unicast") == 0)
3440a3a95b7dSJasvinder Singh 			a->encap.mpls.unicast = 1;
3441a3a95b7dSJasvinder Singh 		else if (strcmp(tokens[1], "multicast") == 0)
3442a3a95b7dSJasvinder Singh 			a->encap.mpls.unicast = 0;
3443a3a95b7dSJasvinder Singh 		else
3444a3a95b7dSJasvinder Singh 			return 0;
3445a3a95b7dSJasvinder Singh 
3446a3a95b7dSJasvinder Singh 		if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3447a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3448a3a95b7dSJasvinder Singh 			strcmp(tokens[4], "label0") ||
3449a3a95b7dSJasvinder Singh 			parser_read_uint32(&label, tokens[5]) ||
3450a3a95b7dSJasvinder Singh 			(label > 0xFFFFF) ||
3451a3a95b7dSJasvinder Singh 			parser_read_uint32(&tc, tokens[6]) ||
3452a3a95b7dSJasvinder Singh 			(tc > 0x7) ||
3453a3a95b7dSJasvinder Singh 			parser_read_uint32(&ttl, tokens[7]) ||
3454a3a95b7dSJasvinder Singh 			(ttl > 0x3F))
3455a3a95b7dSJasvinder Singh 			return 0;
3456a3a95b7dSJasvinder Singh 
3457a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[0].label = label;
3458a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[0].tc = tc;
3459a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[0].ttl = ttl;
3460a3a95b7dSJasvinder Singh 
3461a3a95b7dSJasvinder Singh 		tokens += 8;
3462a3a95b7dSJasvinder Singh 		n_tokens -= 8;
3463a3a95b7dSJasvinder Singh 
3464a3a95b7dSJasvinder Singh 		if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3465a3a95b7dSJasvinder Singh 			a->encap.mpls.mpls_count = 1;
3466a3a95b7dSJasvinder Singh 			a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3467a3a95b7dSJasvinder Singh 			a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3468a3a95b7dSJasvinder Singh 			return 1 + 8;
3469a3a95b7dSJasvinder Singh 		}
3470a3a95b7dSJasvinder Singh 
3471a3a95b7dSJasvinder Singh 		if ((n_tokens < 4) ||
3472a3a95b7dSJasvinder Singh 			parser_read_uint32(&label, tokens[1]) ||
3473a3a95b7dSJasvinder Singh 			(label > 0xFFFFF) ||
3474a3a95b7dSJasvinder Singh 			parser_read_uint32(&tc, tokens[2]) ||
3475a3a95b7dSJasvinder Singh 			(tc > 0x7) ||
3476a3a95b7dSJasvinder Singh 			parser_read_uint32(&ttl, tokens[3]) ||
3477a3a95b7dSJasvinder Singh 			(ttl > 0x3F))
3478a3a95b7dSJasvinder Singh 			return 0;
3479a3a95b7dSJasvinder Singh 
3480a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[1].label = label;
3481a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[1].tc = tc;
3482a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[1].ttl = ttl;
3483a3a95b7dSJasvinder Singh 
3484a3a95b7dSJasvinder Singh 		tokens += 4;
3485a3a95b7dSJasvinder Singh 		n_tokens -= 4;
3486a3a95b7dSJasvinder Singh 
3487a3a95b7dSJasvinder Singh 		if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3488a3a95b7dSJasvinder Singh 			a->encap.mpls.mpls_count = 2;
3489a3a95b7dSJasvinder Singh 			a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3490a3a95b7dSJasvinder Singh 			a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3491a3a95b7dSJasvinder Singh 			return 1 + 8 + 4;
3492a3a95b7dSJasvinder Singh 		}
3493a3a95b7dSJasvinder Singh 
3494a3a95b7dSJasvinder Singh 		if ((n_tokens < 4) ||
3495a3a95b7dSJasvinder Singh 			parser_read_uint32(&label, tokens[1]) ||
3496a3a95b7dSJasvinder Singh 			(label > 0xFFFFF) ||
3497a3a95b7dSJasvinder Singh 			parser_read_uint32(&tc, tokens[2]) ||
3498a3a95b7dSJasvinder Singh 			(tc > 0x7) ||
3499a3a95b7dSJasvinder Singh 			parser_read_uint32(&ttl, tokens[3]) ||
3500a3a95b7dSJasvinder Singh 			(ttl > 0x3F))
3501a3a95b7dSJasvinder Singh 			return 0;
3502a3a95b7dSJasvinder Singh 
3503a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[2].label = label;
3504a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[2].tc = tc;
3505a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[2].ttl = ttl;
3506a3a95b7dSJasvinder Singh 
3507a3a95b7dSJasvinder Singh 		tokens += 4;
3508a3a95b7dSJasvinder Singh 		n_tokens -= 4;
3509a3a95b7dSJasvinder Singh 
3510a3a95b7dSJasvinder Singh 		if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3511a3a95b7dSJasvinder Singh 			a->encap.mpls.mpls_count = 3;
3512a3a95b7dSJasvinder Singh 			a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3513a3a95b7dSJasvinder Singh 			a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3514a3a95b7dSJasvinder Singh 			return 1 + 8 + 4 + 4;
3515a3a95b7dSJasvinder Singh 		}
3516a3a95b7dSJasvinder Singh 
3517a3a95b7dSJasvinder Singh 		if ((n_tokens < 4) ||
3518a3a95b7dSJasvinder Singh 			parser_read_uint32(&label, tokens[1]) ||
3519a3a95b7dSJasvinder Singh 			(label > 0xFFFFF) ||
3520a3a95b7dSJasvinder Singh 			parser_read_uint32(&tc, tokens[2]) ||
3521a3a95b7dSJasvinder Singh 			(tc > 0x7) ||
3522a3a95b7dSJasvinder Singh 			parser_read_uint32(&ttl, tokens[3]) ||
3523a3a95b7dSJasvinder Singh 			(ttl > 0x3F))
3524a3a95b7dSJasvinder Singh 			return 0;
3525a3a95b7dSJasvinder Singh 
3526a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[3].label = label;
3527a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[3].tc = tc;
3528a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[3].ttl = ttl;
3529a3a95b7dSJasvinder Singh 
3530a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls_count = 4;
3531a3a95b7dSJasvinder Singh 		a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3532a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3533a3a95b7dSJasvinder Singh 		return 1 + 8 + 4 + 4 + 4;
3534a3a95b7dSJasvinder Singh 	}
3535a3a95b7dSJasvinder Singh 
3536a3a95b7dSJasvinder Singh 	/* pppoe */
3537a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3538a3a95b7dSJasvinder Singh 		if ((n_tokens < 4) ||
3539a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3540a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3541a3a95b7dSJasvinder Singh 			parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3542a3a95b7dSJasvinder Singh 				tokens[3]))
3543a3a95b7dSJasvinder Singh 			return 0;
3544a3a95b7dSJasvinder Singh 
3545a3a95b7dSJasvinder Singh 		a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3546a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3547a3a95b7dSJasvinder Singh 		return 1 + 4;
3548a3a95b7dSJasvinder Singh 	}
3549a3a95b7dSJasvinder Singh 
355044cad685SCristian Dumitrescu 	/* vxlan */
355144cad685SCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
355244cad685SCristian Dumitrescu 		uint32_t n = 0;
355344cad685SCristian Dumitrescu 
355444cad685SCristian Dumitrescu 		n_tokens--;
355544cad685SCristian Dumitrescu 		tokens++;
355644cad685SCristian Dumitrescu 		n++;
355744cad685SCristian Dumitrescu 
355844cad685SCristian Dumitrescu 		/* ether <da> <sa> */
355944cad685SCristian Dumitrescu 		if ((n_tokens < 3) ||
356044cad685SCristian Dumitrescu 			strcmp(tokens[0], "ether") ||
356144cad685SCristian Dumitrescu 			parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
356244cad685SCristian Dumitrescu 			parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
356344cad685SCristian Dumitrescu 			return 0;
356444cad685SCristian Dumitrescu 
356544cad685SCristian Dumitrescu 		n_tokens -= 3;
356644cad685SCristian Dumitrescu 		tokens += 3;
356744cad685SCristian Dumitrescu 		n += 3;
356844cad685SCristian Dumitrescu 
356944cad685SCristian Dumitrescu 		/* [vlan <pcp> <dei> <vid>] */
357044cad685SCristian Dumitrescu 		if (strcmp(tokens[0], "vlan") == 0) {
357144cad685SCristian Dumitrescu 			uint32_t pcp, dei, vid;
357244cad685SCristian Dumitrescu 
357344cad685SCristian Dumitrescu 			if ((n_tokens < 4) ||
357444cad685SCristian Dumitrescu 				parser_read_uint32(&pcp, tokens[1]) ||
357544cad685SCristian Dumitrescu 				(pcp > 7) ||
357644cad685SCristian Dumitrescu 				parser_read_uint32(&dei, tokens[2]) ||
357744cad685SCristian Dumitrescu 				(dei > 1) ||
357844cad685SCristian Dumitrescu 				parser_read_uint32(&vid, tokens[3]) ||
357944cad685SCristian Dumitrescu 				(vid > 0xFFF))
358044cad685SCristian Dumitrescu 				return 0;
358144cad685SCristian Dumitrescu 
358244cad685SCristian Dumitrescu 			a->encap.vxlan.vlan.pcp = pcp;
358344cad685SCristian Dumitrescu 			a->encap.vxlan.vlan.dei = dei;
358444cad685SCristian Dumitrescu 			a->encap.vxlan.vlan.vid = vid;
358544cad685SCristian Dumitrescu 
358644cad685SCristian Dumitrescu 			n_tokens -= 4;
358744cad685SCristian Dumitrescu 			tokens += 4;
358844cad685SCristian Dumitrescu 			n += 4;
358944cad685SCristian Dumitrescu 		}
359044cad685SCristian Dumitrescu 
359144cad685SCristian Dumitrescu 		/* ipv4 <sa> <da> <dscp> <ttl>
359244cad685SCristian Dumitrescu 		   | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
359344cad685SCristian Dumitrescu 		if (strcmp(tokens[0], "ipv4") == 0) {
359444cad685SCristian Dumitrescu 			struct in_addr sa, da;
359544cad685SCristian Dumitrescu 			uint8_t dscp, ttl;
359644cad685SCristian Dumitrescu 
359744cad685SCristian Dumitrescu 			if ((n_tokens < 5) ||
359844cad685SCristian Dumitrescu 				parse_ipv4_addr(tokens[1], &sa) ||
359944cad685SCristian Dumitrescu 				parse_ipv4_addr(tokens[2], &da) ||
360044cad685SCristian Dumitrescu 				parser_read_uint8(&dscp, tokens[3]) ||
360144cad685SCristian Dumitrescu 				(dscp > 64) ||
360244cad685SCristian Dumitrescu 				parser_read_uint8(&ttl, tokens[4]))
360344cad685SCristian Dumitrescu 				return 0;
360444cad685SCristian Dumitrescu 
360544cad685SCristian Dumitrescu 			a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
360644cad685SCristian Dumitrescu 			a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
360744cad685SCristian Dumitrescu 			a->encap.vxlan.ipv4.dscp = dscp;
360844cad685SCristian Dumitrescu 			a->encap.vxlan.ipv4.ttl = ttl;
360944cad685SCristian Dumitrescu 
361044cad685SCristian Dumitrescu 			n_tokens -= 5;
361144cad685SCristian Dumitrescu 			tokens += 5;
361244cad685SCristian Dumitrescu 			n += 5;
361344cad685SCristian Dumitrescu 		} else if (strcmp(tokens[0], "ipv6") == 0) {
361444cad685SCristian Dumitrescu 			struct in6_addr sa, da;
361544cad685SCristian Dumitrescu 			uint32_t flow_label;
361644cad685SCristian Dumitrescu 			uint8_t dscp, hop_limit;
361744cad685SCristian Dumitrescu 
361844cad685SCristian Dumitrescu 			if ((n_tokens < 6) ||
361944cad685SCristian Dumitrescu 				parse_ipv6_addr(tokens[1], &sa) ||
362044cad685SCristian Dumitrescu 				parse_ipv6_addr(tokens[2], &da) ||
362144cad685SCristian Dumitrescu 				parser_read_uint32(&flow_label, tokens[3]) ||
362244cad685SCristian Dumitrescu 				parser_read_uint8(&dscp, tokens[4]) ||
362344cad685SCristian Dumitrescu 				(dscp > 64) ||
362444cad685SCristian Dumitrescu 				parser_read_uint8(&hop_limit, tokens[5]))
362544cad685SCristian Dumitrescu 				return 0;
362644cad685SCristian Dumitrescu 
362744cad685SCristian Dumitrescu 			memcpy(a->encap.vxlan.ipv6.sa, sa.s6_addr, 16);
362844cad685SCristian Dumitrescu 			memcpy(a->encap.vxlan.ipv6.da, da.s6_addr, 16);
362944cad685SCristian Dumitrescu 			a->encap.vxlan.ipv6.flow_label = flow_label;
363044cad685SCristian Dumitrescu 			a->encap.vxlan.ipv6.dscp = dscp;
363144cad685SCristian Dumitrescu 			a->encap.vxlan.ipv6.hop_limit = hop_limit;
363244cad685SCristian Dumitrescu 
363344cad685SCristian Dumitrescu 			n_tokens -= 6;
363444cad685SCristian Dumitrescu 			tokens += 6;
363544cad685SCristian Dumitrescu 			n += 6;
363644cad685SCristian Dumitrescu 		} else
363744cad685SCristian Dumitrescu 			return 0;
363844cad685SCristian Dumitrescu 
363944cad685SCristian Dumitrescu 		/* udp <sp> <dp> */
364044cad685SCristian Dumitrescu 		if ((n_tokens < 3) ||
364144cad685SCristian Dumitrescu 			strcmp(tokens[0], "udp") ||
364244cad685SCristian Dumitrescu 			parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
364344cad685SCristian Dumitrescu 			parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
364444cad685SCristian Dumitrescu 			return 0;
364544cad685SCristian Dumitrescu 
364644cad685SCristian Dumitrescu 		n_tokens -= 3;
364744cad685SCristian Dumitrescu 		tokens += 3;
364844cad685SCristian Dumitrescu 		n += 3;
364944cad685SCristian Dumitrescu 
365044cad685SCristian Dumitrescu 		/* vxlan <vni> */
365144cad685SCristian Dumitrescu 		if ((n_tokens < 2) ||
365244cad685SCristian Dumitrescu 			strcmp(tokens[0], "vxlan") ||
365344cad685SCristian Dumitrescu 			parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
365444cad685SCristian Dumitrescu 			(a->encap.vxlan.vxlan.vni > 0xFFFFFF))
365544cad685SCristian Dumitrescu 			return 0;
365644cad685SCristian Dumitrescu 
365744cad685SCristian Dumitrescu 		n_tokens -= 2;
365844cad685SCristian Dumitrescu 		tokens += 2;
365944cad685SCristian Dumitrescu 		n += 2;
366044cad685SCristian Dumitrescu 
366144cad685SCristian Dumitrescu 		a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
366244cad685SCristian Dumitrescu 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
366344cad685SCristian Dumitrescu 		return 1 + n;
366444cad685SCristian Dumitrescu 	}
366544cad685SCristian Dumitrescu 
3666a3a95b7dSJasvinder Singh 	return 0;
3667a3a95b7dSJasvinder Singh }
3668a3a95b7dSJasvinder Singh 
3669a3a95b7dSJasvinder Singh static uint32_t
parse_table_action_nat(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)3670a3a95b7dSJasvinder Singh parse_table_action_nat(char **tokens,
3671a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3672a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3673a3a95b7dSJasvinder Singh {
3674a3a95b7dSJasvinder Singh 	if ((n_tokens < 4) ||
3675a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "nat"))
3676a3a95b7dSJasvinder Singh 		return 0;
3677a3a95b7dSJasvinder Singh 
3678a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "ipv4") == 0) {
3679a3a95b7dSJasvinder Singh 		struct in_addr addr;
3680a3a95b7dSJasvinder Singh 		uint16_t port;
3681a3a95b7dSJasvinder Singh 
3682a3a95b7dSJasvinder Singh 		if (parse_ipv4_addr(tokens[2], &addr) ||
3683a3a95b7dSJasvinder Singh 			parser_read_uint16(&port, tokens[3]))
3684a3a95b7dSJasvinder Singh 			return 0;
3685a3a95b7dSJasvinder Singh 
3686a3a95b7dSJasvinder Singh 		a->nat.ip_version = 1;
3687a3a95b7dSJasvinder Singh 		a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3688a3a95b7dSJasvinder Singh 		a->nat.port = port;
3689a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3690a3a95b7dSJasvinder Singh 		return 4;
3691a3a95b7dSJasvinder Singh 	}
3692a3a95b7dSJasvinder Singh 
3693a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "ipv6") == 0) {
3694a3a95b7dSJasvinder Singh 		struct in6_addr addr;
3695a3a95b7dSJasvinder Singh 		uint16_t port;
3696a3a95b7dSJasvinder Singh 
3697a3a95b7dSJasvinder Singh 		if (parse_ipv6_addr(tokens[2], &addr) ||
3698a3a95b7dSJasvinder Singh 			parser_read_uint16(&port, tokens[3]))
3699a3a95b7dSJasvinder Singh 			return 0;
3700a3a95b7dSJasvinder Singh 
3701a3a95b7dSJasvinder Singh 		a->nat.ip_version = 0;
3702a3a95b7dSJasvinder Singh 		memcpy(a->nat.addr.ipv6, addr.s6_addr, 16);
3703a3a95b7dSJasvinder Singh 		a->nat.port = port;
3704a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3705a3a95b7dSJasvinder Singh 		return 4;
3706a3a95b7dSJasvinder Singh 	}
3707a3a95b7dSJasvinder Singh 
3708a3a95b7dSJasvinder Singh 	return 0;
3709a3a95b7dSJasvinder Singh }
3710a3a95b7dSJasvinder Singh 
3711a3a95b7dSJasvinder Singh static uint32_t
parse_table_action_ttl(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)3712a3a95b7dSJasvinder Singh parse_table_action_ttl(char **tokens,
3713a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3714a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3715a3a95b7dSJasvinder Singh {
3716a3a95b7dSJasvinder Singh 	if ((n_tokens < 2) ||
3717a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "ttl"))
3718a3a95b7dSJasvinder Singh 		return 0;
3719a3a95b7dSJasvinder Singh 
3720a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "dec") == 0)
3721a3a95b7dSJasvinder Singh 		a->ttl.decrement = 1;
3722a3a95b7dSJasvinder Singh 	else if (strcmp(tokens[1], "keep") == 0)
3723a3a95b7dSJasvinder Singh 		a->ttl.decrement = 0;
3724a3a95b7dSJasvinder Singh 	else
3725a3a95b7dSJasvinder Singh 		return 0;
3726a3a95b7dSJasvinder Singh 
3727a3a95b7dSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3728a3a95b7dSJasvinder Singh 	return 2;
3729a3a95b7dSJasvinder Singh }
3730a3a95b7dSJasvinder Singh 
3731a3a95b7dSJasvinder Singh static uint32_t
parse_table_action_stats(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)3732a3a95b7dSJasvinder Singh parse_table_action_stats(char **tokens,
3733a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3734a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3735a3a95b7dSJasvinder Singh {
3736a3a95b7dSJasvinder Singh 	if ((n_tokens < 1) ||
3737a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "stats"))
3738a3a95b7dSJasvinder Singh 		return 0;
3739a3a95b7dSJasvinder Singh 
3740a3a95b7dSJasvinder Singh 	a->stats.n_packets = 0;
3741a3a95b7dSJasvinder Singh 	a->stats.n_bytes = 0;
3742a3a95b7dSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3743a3a95b7dSJasvinder Singh 	return 1;
3744a3a95b7dSJasvinder Singh }
3745a3a95b7dSJasvinder Singh 
3746a3a95b7dSJasvinder Singh static uint32_t
parse_table_action_time(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)3747a3a95b7dSJasvinder Singh parse_table_action_time(char **tokens,
3748a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3749a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3750a3a95b7dSJasvinder Singh {
3751a3a95b7dSJasvinder Singh 	if ((n_tokens < 1) ||
3752a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "time"))
3753a3a95b7dSJasvinder Singh 		return 0;
3754a3a95b7dSJasvinder Singh 
3755a3a95b7dSJasvinder Singh 	a->time.time = rte_rdtsc();
3756a3a95b7dSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3757a3a95b7dSJasvinder Singh 	return 1;
3758a3a95b7dSJasvinder Singh }
3759a3a95b7dSJasvinder Singh 
37601edccebcSFan Zhang static void
parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params * p)37611edccebcSFan Zhang parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
37621edccebcSFan Zhang {
37631edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform[2] = {NULL};
37641edccebcSFan Zhang 	uint32_t i;
37651edccebcSFan Zhang 
37661edccebcSFan Zhang 	xform[0] = p->xform;
37671edccebcSFan Zhang 	if (xform[0])
37681edccebcSFan Zhang 		xform[1] = xform[0]->next;
37691edccebcSFan Zhang 
37701edccebcSFan Zhang 	for (i = 0; i < 2; i++) {
37711edccebcSFan Zhang 		if (xform[i] == NULL)
37721edccebcSFan Zhang 			continue;
37731edccebcSFan Zhang 
37741edccebcSFan Zhang 		switch (xform[i]->type) {
37751edccebcSFan Zhang 		case RTE_CRYPTO_SYM_XFORM_CIPHER:
37761edccebcSFan Zhang 			free(p->cipher_auth.cipher_iv.val);
37771edccebcSFan Zhang 			free(p->cipher_auth.cipher_iv_update.val);
37781edccebcSFan Zhang 			break;
37791edccebcSFan Zhang 		case RTE_CRYPTO_SYM_XFORM_AUTH:
37801edccebcSFan Zhang 			if (p->cipher_auth.auth_iv.val)
37811edccebcSFan Zhang 				free(p->cipher_auth.cipher_iv.val);
37821edccebcSFan Zhang 			if (p->cipher_auth.auth_iv_update.val)
37831edccebcSFan Zhang 				free(p->cipher_auth.cipher_iv_update.val);
37841edccebcSFan Zhang 			break;
37851edccebcSFan Zhang 		case RTE_CRYPTO_SYM_XFORM_AEAD:
37861edccebcSFan Zhang 			free(p->aead.iv.val);
37871edccebcSFan Zhang 			free(p->aead.aad.val);
37881edccebcSFan Zhang 			break;
37891edccebcSFan Zhang 		default:
37901edccebcSFan Zhang 			continue;
37911edccebcSFan Zhang 		}
37921edccebcSFan Zhang 	}
37931edccebcSFan Zhang 
37941edccebcSFan Zhang }
37951edccebcSFan Zhang 
37961edccebcSFan Zhang static struct rte_crypto_sym_xform *
parse_table_action_cipher(struct rte_table_action_sym_crypto_params * p,uint8_t * key,uint32_t max_key_len,char ** tokens,uint32_t n_tokens,uint32_t encrypt,uint32_t * used_n_tokens)37971edccebcSFan Zhang parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3798186b14d6SFan Zhang 		uint8_t *key, uint32_t max_key_len, char **tokens,
3799186b14d6SFan Zhang 		uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
38001edccebcSFan Zhang {
38011edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform_cipher;
38021edccebcSFan Zhang 	int status;
38031edccebcSFan Zhang 	size_t len;
38041edccebcSFan Zhang 
38051edccebcSFan Zhang 	if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
38061edccebcSFan Zhang 			strcmp(tokens[3], "cipher_key") ||
38071edccebcSFan Zhang 			strcmp(tokens[5], "cipher_iv"))
38081edccebcSFan Zhang 		return NULL;
38091edccebcSFan Zhang 
38101edccebcSFan Zhang 	xform_cipher = calloc(1, sizeof(*xform_cipher));
38111edccebcSFan Zhang 	if (xform_cipher == NULL)
38121edccebcSFan Zhang 		return NULL;
38131edccebcSFan Zhang 
38141edccebcSFan Zhang 	xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
38151edccebcSFan Zhang 	xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
38161edccebcSFan Zhang 			RTE_CRYPTO_CIPHER_OP_DECRYPT;
38171edccebcSFan Zhang 
38181edccebcSFan Zhang 	/* cipher_algo */
38191edccebcSFan Zhang 	status = rte_cryptodev_get_cipher_algo_enum(
38201edccebcSFan Zhang 			&xform_cipher->cipher.algo, tokens[2]);
38211edccebcSFan Zhang 	if (status < 0)
38221edccebcSFan Zhang 		goto error_exit;
38231edccebcSFan Zhang 
38241edccebcSFan Zhang 	/* cipher_key */
38251edccebcSFan Zhang 	len = strlen(tokens[4]);
3826186b14d6SFan Zhang 	if (len / 2 > max_key_len) {
3827186b14d6SFan Zhang 		status = -ENOMEM;
38281edccebcSFan Zhang 		goto error_exit;
3829186b14d6SFan Zhang 	}
38301edccebcSFan Zhang 
3831186b14d6SFan Zhang 	status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
38321edccebcSFan Zhang 	if (status < 0)
38331edccebcSFan Zhang 		goto error_exit;
38341edccebcSFan Zhang 
3835186b14d6SFan Zhang 	xform_cipher->cipher.key.data = key;
38361edccebcSFan Zhang 	xform_cipher->cipher.key.length = (uint16_t)len;
38371edccebcSFan Zhang 
38381edccebcSFan Zhang 	/* cipher_iv */
38391edccebcSFan Zhang 	len = strlen(tokens[6]);
38401edccebcSFan Zhang 
38411edccebcSFan Zhang 	p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
38421edccebcSFan Zhang 	if (p->cipher_auth.cipher_iv.val == NULL)
38431edccebcSFan Zhang 		goto error_exit;
38441edccebcSFan Zhang 
38451edccebcSFan Zhang 	status = parse_hex_string(tokens[6],
38461edccebcSFan Zhang 			p->cipher_auth.cipher_iv.val,
38471edccebcSFan Zhang 			(uint32_t *)&len);
38481edccebcSFan Zhang 	if (status < 0)
38491edccebcSFan Zhang 		goto error_exit;
38501edccebcSFan Zhang 
38511edccebcSFan Zhang 	xform_cipher->cipher.iv.length = (uint16_t)len;
38521edccebcSFan Zhang 	xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
38531edccebcSFan Zhang 	p->cipher_auth.cipher_iv.length = (uint32_t)len;
38541edccebcSFan Zhang 	*used_n_tokens = 7;
38551edccebcSFan Zhang 
38561edccebcSFan Zhang 	return xform_cipher;
38571edccebcSFan Zhang 
38581edccebcSFan Zhang error_exit:
38591edccebcSFan Zhang 	if (p->cipher_auth.cipher_iv.val) {
38601edccebcSFan Zhang 		free(p->cipher_auth.cipher_iv.val);
38611edccebcSFan Zhang 		p->cipher_auth.cipher_iv.val = NULL;
38621edccebcSFan Zhang 	}
38631edccebcSFan Zhang 
38641edccebcSFan Zhang 	free(xform_cipher);
38651edccebcSFan Zhang 
38661edccebcSFan Zhang 	return NULL;
38671edccebcSFan Zhang }
38681edccebcSFan Zhang 
38691edccebcSFan Zhang static struct rte_crypto_sym_xform *
parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params * p,uint8_t * key,uint32_t max_key_len,char ** tokens,uint32_t n_tokens,uint32_t encrypt,uint32_t * used_n_tokens)38701edccebcSFan Zhang parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3871186b14d6SFan Zhang 		uint8_t *key, uint32_t max_key_len, char **tokens,
3872186b14d6SFan Zhang 		uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
38731edccebcSFan Zhang {
38741edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform_cipher;
38751edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform_auth;
38761edccebcSFan Zhang 	int status;
38771edccebcSFan Zhang 	size_t len;
38781edccebcSFan Zhang 
38791edccebcSFan Zhang 	if (n_tokens < 13 ||
38801edccebcSFan Zhang 			strcmp(tokens[7], "auth_algo") ||
38811edccebcSFan Zhang 			strcmp(tokens[9], "auth_key") ||
38821edccebcSFan Zhang 			strcmp(tokens[11], "digest_size"))
38831edccebcSFan Zhang 		return NULL;
38841edccebcSFan Zhang 
38851edccebcSFan Zhang 	xform_auth = calloc(1, sizeof(*xform_auth));
38861edccebcSFan Zhang 	if (xform_auth == NULL)
38871edccebcSFan Zhang 		return NULL;
38881edccebcSFan Zhang 
38891edccebcSFan Zhang 	xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
38901edccebcSFan Zhang 	xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
38911edccebcSFan Zhang 			RTE_CRYPTO_AUTH_OP_VERIFY;
38921edccebcSFan Zhang 
38931edccebcSFan Zhang 	/* auth_algo */
38941edccebcSFan Zhang 	status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
38951edccebcSFan Zhang 			tokens[8]);
38961edccebcSFan Zhang 	if (status < 0)
38971edccebcSFan Zhang 		goto error_exit;
38981edccebcSFan Zhang 
38991edccebcSFan Zhang 	/* auth_key */
39001edccebcSFan Zhang 	len = strlen(tokens[10]);
3901186b14d6SFan Zhang 	if (len / 2 > max_key_len) {
3902186b14d6SFan Zhang 		status = -ENOMEM;
39031edccebcSFan Zhang 		goto error_exit;
3904186b14d6SFan Zhang 	}
39051edccebcSFan Zhang 
3906186b14d6SFan Zhang 	status = parse_hex_string(tokens[10], key, (uint32_t *)&len);
39071edccebcSFan Zhang 	if (status < 0)
39081edccebcSFan Zhang 		goto error_exit;
39091edccebcSFan Zhang 
3910186b14d6SFan Zhang 	xform_auth->auth.key.data = key;
39111edccebcSFan Zhang 	xform_auth->auth.key.length = (uint16_t)len;
39121edccebcSFan Zhang 
3913186b14d6SFan Zhang 	key += xform_auth->auth.key.length;
3914186b14d6SFan Zhang 	max_key_len -= xform_auth->auth.key.length;
3915186b14d6SFan Zhang 
39161edccebcSFan Zhang 	if (strcmp(tokens[11], "digest_size"))
39171edccebcSFan Zhang 		goto error_exit;
39181edccebcSFan Zhang 
39191edccebcSFan Zhang 	status = parser_read_uint16(&xform_auth->auth.digest_length,
39201edccebcSFan Zhang 			tokens[12]);
39211edccebcSFan Zhang 	if (status < 0)
39221edccebcSFan Zhang 		goto error_exit;
39231edccebcSFan Zhang 
3924186b14d6SFan Zhang 	xform_cipher = parse_table_action_cipher(p, key, max_key_len, tokens,
3925186b14d6SFan Zhang 			7, encrypt, used_n_tokens);
39261edccebcSFan Zhang 	if (xform_cipher == NULL)
39271edccebcSFan Zhang 		goto error_exit;
39281edccebcSFan Zhang 
39291edccebcSFan Zhang 	*used_n_tokens += 6;
39301edccebcSFan Zhang 
39311edccebcSFan Zhang 	if (encrypt) {
39321edccebcSFan Zhang 		xform_cipher->next = xform_auth;
39331edccebcSFan Zhang 		return xform_cipher;
39341edccebcSFan Zhang 	} else {
39351edccebcSFan Zhang 		xform_auth->next = xform_cipher;
39361edccebcSFan Zhang 		return xform_auth;
39371edccebcSFan Zhang 	}
39381edccebcSFan Zhang 
39391edccebcSFan Zhang error_exit:
39401edccebcSFan Zhang 	if (p->cipher_auth.auth_iv.val) {
39411edccebcSFan Zhang 		free(p->cipher_auth.auth_iv.val);
39421edccebcSFan Zhang 		p->cipher_auth.auth_iv.val = 0;
39431edccebcSFan Zhang 	}
39441edccebcSFan Zhang 
39451edccebcSFan Zhang 	free(xform_auth);
39461edccebcSFan Zhang 
39471edccebcSFan Zhang 	return NULL;
39481edccebcSFan Zhang }
39491edccebcSFan Zhang 
39501edccebcSFan Zhang static struct rte_crypto_sym_xform *
parse_table_action_aead(struct rte_table_action_sym_crypto_params * p,uint8_t * key,uint32_t max_key_len,char ** tokens,uint32_t n_tokens,uint32_t encrypt,uint32_t * used_n_tokens)39511edccebcSFan Zhang parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3952186b14d6SFan Zhang 		uint8_t *key, uint32_t max_key_len, char **tokens,
3953186b14d6SFan Zhang 		uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
39541edccebcSFan Zhang {
39551edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform_aead;
39561edccebcSFan Zhang 	int status;
39571edccebcSFan Zhang 	size_t len;
39581edccebcSFan Zhang 
39591edccebcSFan Zhang 	if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
39601edccebcSFan Zhang 			strcmp(tokens[3], "aead_key") ||
39611edccebcSFan Zhang 			strcmp(tokens[5], "aead_iv") ||
39621edccebcSFan Zhang 			strcmp(tokens[7], "aead_aad") ||
39631edccebcSFan Zhang 			strcmp(tokens[9], "digest_size"))
39641edccebcSFan Zhang 		return NULL;
39651edccebcSFan Zhang 
39661edccebcSFan Zhang 	xform_aead = calloc(1, sizeof(*xform_aead));
39671edccebcSFan Zhang 	if (xform_aead == NULL)
39681edccebcSFan Zhang 		return NULL;
39691edccebcSFan Zhang 
39701edccebcSFan Zhang 	xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
39711edccebcSFan Zhang 	xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
39721edccebcSFan Zhang 			RTE_CRYPTO_AEAD_OP_DECRYPT;
39731edccebcSFan Zhang 
39741edccebcSFan Zhang 	/* aead_algo */
39751edccebcSFan Zhang 	status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
39761edccebcSFan Zhang 			tokens[2]);
39771edccebcSFan Zhang 	if (status < 0)
39781edccebcSFan Zhang 		goto error_exit;
39791edccebcSFan Zhang 
39801edccebcSFan Zhang 	/* aead_key */
39811edccebcSFan Zhang 	len = strlen(tokens[4]);
3982186b14d6SFan Zhang 	if (len / 2 > max_key_len) {
3983186b14d6SFan Zhang 		status = -ENOMEM;
39841edccebcSFan Zhang 		goto error_exit;
3985186b14d6SFan Zhang 	}
39861edccebcSFan Zhang 
3987186b14d6SFan Zhang 	status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
39881edccebcSFan Zhang 	if (status < 0)
39891edccebcSFan Zhang 		goto error_exit;
39901edccebcSFan Zhang 
3991186b14d6SFan Zhang 	xform_aead->aead.key.data = key;
39921edccebcSFan Zhang 	xform_aead->aead.key.length = (uint16_t)len;
39931edccebcSFan Zhang 
39941edccebcSFan Zhang 	/* aead_iv */
39951edccebcSFan Zhang 	len = strlen(tokens[6]);
39961edccebcSFan Zhang 	p->aead.iv.val = calloc(1, len / 2 + 1);
39971edccebcSFan Zhang 	if (p->aead.iv.val == NULL)
39981edccebcSFan Zhang 		goto error_exit;
39991edccebcSFan Zhang 
40001edccebcSFan Zhang 	status = parse_hex_string(tokens[6], p->aead.iv.val,
40011edccebcSFan Zhang 			(uint32_t *)&len);
40021edccebcSFan Zhang 	if (status < 0)
40031edccebcSFan Zhang 		goto error_exit;
40041edccebcSFan Zhang 
40051edccebcSFan Zhang 	xform_aead->aead.iv.length = (uint16_t)len;
40061edccebcSFan Zhang 	xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
40071edccebcSFan Zhang 	p->aead.iv.length = (uint32_t)len;
40081edccebcSFan Zhang 
40091edccebcSFan Zhang 	/* aead_aad */
40101edccebcSFan Zhang 	len = strlen(tokens[8]);
40111edccebcSFan Zhang 	p->aead.aad.val = calloc(1, len / 2 + 1);
40121edccebcSFan Zhang 	if (p->aead.aad.val == NULL)
40131edccebcSFan Zhang 		goto error_exit;
40141edccebcSFan Zhang 
40151edccebcSFan Zhang 	status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
40161edccebcSFan Zhang 	if (status < 0)
40171edccebcSFan Zhang 		goto error_exit;
40181edccebcSFan Zhang 
40191edccebcSFan Zhang 	xform_aead->aead.aad_length = (uint16_t)len;
40201edccebcSFan Zhang 	p->aead.aad.length = (uint32_t)len;
40211edccebcSFan Zhang 
40221edccebcSFan Zhang 	/* digest_size */
40231edccebcSFan Zhang 	status = parser_read_uint16(&xform_aead->aead.digest_length,
40241edccebcSFan Zhang 			tokens[10]);
40251edccebcSFan Zhang 	if (status < 0)
40261edccebcSFan Zhang 		goto error_exit;
40271edccebcSFan Zhang 
40281edccebcSFan Zhang 	*used_n_tokens = 11;
40291edccebcSFan Zhang 
40301edccebcSFan Zhang 	return xform_aead;
40311edccebcSFan Zhang 
40321edccebcSFan Zhang error_exit:
40331edccebcSFan Zhang 	if (p->aead.iv.val) {
40341edccebcSFan Zhang 		free(p->aead.iv.val);
40351edccebcSFan Zhang 		p->aead.iv.val = NULL;
40361edccebcSFan Zhang 	}
40371edccebcSFan Zhang 	if (p->aead.aad.val) {
40381edccebcSFan Zhang 		free(p->aead.aad.val);
40391edccebcSFan Zhang 		p->aead.aad.val = NULL;
40401edccebcSFan Zhang 	}
40411edccebcSFan Zhang 
40421edccebcSFan Zhang 	free(xform_aead);
40431edccebcSFan Zhang 
40441edccebcSFan Zhang 	return NULL;
40451edccebcSFan Zhang }
40461edccebcSFan Zhang 
40471edccebcSFan Zhang 
40481edccebcSFan Zhang static uint32_t
parse_table_action_sym_crypto(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)40491edccebcSFan Zhang parse_table_action_sym_crypto(char **tokens,
40501edccebcSFan Zhang 	uint32_t n_tokens,
40511edccebcSFan Zhang 	struct table_rule_action *a)
40521edccebcSFan Zhang {
40531edccebcSFan Zhang 	struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
40541edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform = NULL;
4055186b14d6SFan Zhang 	uint8_t *key = a->sym_crypto_key;
4056186b14d6SFan Zhang 	uint32_t max_key_len = SYM_CRYPTO_MAX_KEY_SIZE;
40571edccebcSFan Zhang 	uint32_t used_n_tokens;
40581edccebcSFan Zhang 	uint32_t encrypt;
40591edccebcSFan Zhang 	int status;
40601edccebcSFan Zhang 
40611edccebcSFan Zhang 	if ((n_tokens < 12) ||
40621edccebcSFan Zhang 		strcmp(tokens[0], "sym_crypto") ||
40631edccebcSFan Zhang 		strcmp(tokens[2], "type"))
40641edccebcSFan Zhang 		return 0;
40651edccebcSFan Zhang 
40661edccebcSFan Zhang 	memset(p, 0, sizeof(*p));
40671edccebcSFan Zhang 
40681edccebcSFan Zhang 	if (strcmp(tokens[1], "encrypt") == 0)
40691edccebcSFan Zhang 		encrypt = 1;
40701edccebcSFan Zhang 	else
40711edccebcSFan Zhang 		encrypt = 0;
40721edccebcSFan Zhang 
40731edccebcSFan Zhang 	status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
40741edccebcSFan Zhang 	if (status < 0)
40751edccebcSFan Zhang 		return 0;
40761edccebcSFan Zhang 
40771edccebcSFan Zhang 	if (strcmp(tokens[3], "cipher") == 0) {
40781edccebcSFan Zhang 		tokens += 3;
40791edccebcSFan Zhang 		n_tokens -= 3;
40801edccebcSFan Zhang 
4081186b14d6SFan Zhang 		xform = parse_table_action_cipher(p, key, max_key_len, tokens,
4082186b14d6SFan Zhang 				n_tokens, encrypt, &used_n_tokens);
40831edccebcSFan Zhang 	} else if (strcmp(tokens[3], "cipher_auth") == 0) {
40841edccebcSFan Zhang 		tokens += 3;
40851edccebcSFan Zhang 		n_tokens -= 3;
40861edccebcSFan Zhang 
4087186b14d6SFan Zhang 		xform = parse_table_action_cipher_auth(p, key, max_key_len,
4088186b14d6SFan Zhang 				tokens, n_tokens, encrypt, &used_n_tokens);
40891edccebcSFan Zhang 	} else if (strcmp(tokens[3], "aead") == 0) {
40901edccebcSFan Zhang 		tokens += 3;
40911edccebcSFan Zhang 		n_tokens -= 3;
40921edccebcSFan Zhang 
4093186b14d6SFan Zhang 		xform = parse_table_action_aead(p, key, max_key_len, tokens,
4094186b14d6SFan Zhang 				n_tokens, encrypt, &used_n_tokens);
40951edccebcSFan Zhang 	}
40961edccebcSFan Zhang 
40971edccebcSFan Zhang 	if (xform == NULL)
40981edccebcSFan Zhang 		return 0;
40991edccebcSFan Zhang 
41001edccebcSFan Zhang 	p->xform = xform;
41011edccebcSFan Zhang 
41021edccebcSFan Zhang 	if (strcmp(tokens[used_n_tokens], "data_offset")) {
41031edccebcSFan Zhang 		parse_free_sym_crypto_param_data(p);
41041edccebcSFan Zhang 		return 0;
41051edccebcSFan Zhang 	}
41061edccebcSFan Zhang 
41071edccebcSFan Zhang 	a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
41081edccebcSFan Zhang 
41091edccebcSFan Zhang 	return used_n_tokens + 5;
41101edccebcSFan Zhang }
41111edccebcSFan Zhang 
4112a3a95b7dSJasvinder Singh static uint32_t
parse_table_action_tag(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)41131bdf2632SCristian Dumitrescu parse_table_action_tag(char **tokens,
41141bdf2632SCristian Dumitrescu 	uint32_t n_tokens,
41151bdf2632SCristian Dumitrescu 	struct table_rule_action *a)
41161bdf2632SCristian Dumitrescu {
41171bdf2632SCristian Dumitrescu 	if ((n_tokens < 2) ||
41181bdf2632SCristian Dumitrescu 		strcmp(tokens[0], "tag"))
41191bdf2632SCristian Dumitrescu 		return 0;
41201bdf2632SCristian Dumitrescu 
41211bdf2632SCristian Dumitrescu 	if (parser_read_uint32(&a->tag.tag, tokens[1]))
41221bdf2632SCristian Dumitrescu 		return 0;
41231bdf2632SCristian Dumitrescu 
41241bdf2632SCristian Dumitrescu 	a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
41251bdf2632SCristian Dumitrescu 	return 2;
41261bdf2632SCristian Dumitrescu }
41271bdf2632SCristian Dumitrescu 
41281bdf2632SCristian Dumitrescu static uint32_t
parse_table_action_decap(char ** tokens,uint32_t n_tokens,struct table_rule_action * a)4129d5ed626fSCristian Dumitrescu parse_table_action_decap(char **tokens,
4130d5ed626fSCristian Dumitrescu 	uint32_t n_tokens,
4131d5ed626fSCristian Dumitrescu 	struct table_rule_action *a)
4132d5ed626fSCristian Dumitrescu {
4133d5ed626fSCristian Dumitrescu 	if ((n_tokens < 2) ||
4134d5ed626fSCristian Dumitrescu 		strcmp(tokens[0], "decap"))
4135d5ed626fSCristian Dumitrescu 		return 0;
4136d5ed626fSCristian Dumitrescu 
4137d5ed626fSCristian Dumitrescu 	if (parser_read_uint16(&a->decap.n, tokens[1]))
4138d5ed626fSCristian Dumitrescu 		return 0;
4139d5ed626fSCristian Dumitrescu 
4140d5ed626fSCristian Dumitrescu 	a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4141d5ed626fSCristian Dumitrescu 	return 2;
4142d5ed626fSCristian Dumitrescu }
4143d5ed626fSCristian Dumitrescu 
4144d5ed626fSCristian Dumitrescu static uint32_t
parse_table_action(char ** tokens,uint32_t n_tokens,char * out,size_t out_size,struct table_rule_action * a)4145a3a95b7dSJasvinder Singh parse_table_action(char **tokens,
4146a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
4147a3a95b7dSJasvinder Singh 	char *out,
4148a3a95b7dSJasvinder Singh 	size_t out_size,
4149a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
4150a3a95b7dSJasvinder Singh {
4151a3a95b7dSJasvinder Singh 	uint32_t n_tokens0 = n_tokens;
4152a3a95b7dSJasvinder Singh 
4153a3a95b7dSJasvinder Singh 	memset(a, 0, sizeof(*a));
4154a3a95b7dSJasvinder Singh 
4155a3a95b7dSJasvinder Singh 	if ((n_tokens < 2) ||
4156a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "action"))
4157a3a95b7dSJasvinder Singh 		return 0;
4158a3a95b7dSJasvinder Singh 
4159a3a95b7dSJasvinder Singh 	tokens++;
4160a3a95b7dSJasvinder Singh 	n_tokens--;
4161a3a95b7dSJasvinder Singh 
4162a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4163a3a95b7dSJasvinder Singh 		uint32_t n;
4164a3a95b7dSJasvinder Singh 
4165a3a95b7dSJasvinder Singh 		n = parse_table_action_fwd(tokens, n_tokens, a);
4166a3a95b7dSJasvinder Singh 		if (n == 0) {
4167a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4168a3a95b7dSJasvinder Singh 				"action fwd");
4169a3a95b7dSJasvinder Singh 			return 0;
4170a3a95b7dSJasvinder Singh 		}
4171a3a95b7dSJasvinder Singh 
4172a3a95b7dSJasvinder Singh 		tokens += n;
4173a3a95b7dSJasvinder Singh 		n_tokens -= n;
4174a3a95b7dSJasvinder Singh 	}
4175a3a95b7dSJasvinder Singh 
4176802755dcSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4177802755dcSJasvinder Singh 		uint32_t n;
4178802755dcSJasvinder Singh 
4179802755dcSJasvinder Singh 		n = parse_table_action_balance(tokens, n_tokens, a);
4180802755dcSJasvinder Singh 		if (n == 0) {
4181802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4182802755dcSJasvinder Singh 				"action balance");
4183802755dcSJasvinder Singh 			return 0;
4184802755dcSJasvinder Singh 		}
4185802755dcSJasvinder Singh 
4186802755dcSJasvinder Singh 		tokens += n;
4187802755dcSJasvinder Singh 		n_tokens -= n;
4188802755dcSJasvinder Singh 	}
4189802755dcSJasvinder Singh 
4190a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4191a3a95b7dSJasvinder Singh 		uint32_t n;
4192a3a95b7dSJasvinder Singh 
4193a3a95b7dSJasvinder Singh 		n = parse_table_action_meter(tokens, n_tokens, a);
4194a3a95b7dSJasvinder Singh 		if (n == 0) {
4195a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4196a3a95b7dSJasvinder Singh 				"action meter");
4197a3a95b7dSJasvinder Singh 			return 0;
4198a3a95b7dSJasvinder Singh 		}
4199a3a95b7dSJasvinder Singh 
4200a3a95b7dSJasvinder Singh 		tokens += n;
4201a3a95b7dSJasvinder Singh 		n_tokens -= n;
4202a3a95b7dSJasvinder Singh 	}
4203a3a95b7dSJasvinder Singh 
4204a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4205a3a95b7dSJasvinder Singh 		uint32_t n;
4206a3a95b7dSJasvinder Singh 
4207a3a95b7dSJasvinder Singh 		n = parse_table_action_tm(tokens, n_tokens, a);
4208a3a95b7dSJasvinder Singh 		if (n == 0) {
4209a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4210a3a95b7dSJasvinder Singh 				"action tm");
4211a3a95b7dSJasvinder Singh 			return 0;
4212a3a95b7dSJasvinder Singh 		}
4213a3a95b7dSJasvinder Singh 
4214a3a95b7dSJasvinder Singh 		tokens += n;
4215a3a95b7dSJasvinder Singh 		n_tokens -= n;
4216a3a95b7dSJasvinder Singh 	}
4217a3a95b7dSJasvinder Singh 
4218a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4219a3a95b7dSJasvinder Singh 		uint32_t n;
4220a3a95b7dSJasvinder Singh 
4221a3a95b7dSJasvinder Singh 		n = parse_table_action_encap(tokens, n_tokens, a);
4222a3a95b7dSJasvinder Singh 		if (n == 0) {
4223a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4224a3a95b7dSJasvinder Singh 				"action encap");
4225a3a95b7dSJasvinder Singh 			return 0;
4226a3a95b7dSJasvinder Singh 		}
4227a3a95b7dSJasvinder Singh 
4228a3a95b7dSJasvinder Singh 		tokens += n;
4229a3a95b7dSJasvinder Singh 		n_tokens -= n;
4230a3a95b7dSJasvinder Singh 	}
4231a3a95b7dSJasvinder Singh 
4232a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4233a3a95b7dSJasvinder Singh 		uint32_t n;
4234a3a95b7dSJasvinder Singh 
4235a3a95b7dSJasvinder Singh 		n = parse_table_action_nat(tokens, n_tokens, a);
4236a3a95b7dSJasvinder Singh 		if (n == 0) {
4237a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4238a3a95b7dSJasvinder Singh 				"action nat");
4239a3a95b7dSJasvinder Singh 			return 0;
4240a3a95b7dSJasvinder Singh 		}
4241a3a95b7dSJasvinder Singh 
4242a3a95b7dSJasvinder Singh 		tokens += n;
4243a3a95b7dSJasvinder Singh 		n_tokens -= n;
4244a3a95b7dSJasvinder Singh 	}
4245a3a95b7dSJasvinder Singh 
4246a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4247a3a95b7dSJasvinder Singh 		uint32_t n;
4248a3a95b7dSJasvinder Singh 
4249a3a95b7dSJasvinder Singh 		n = parse_table_action_ttl(tokens, n_tokens, a);
4250a3a95b7dSJasvinder Singh 		if (n == 0) {
4251a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4252a3a95b7dSJasvinder Singh 				"action ttl");
4253a3a95b7dSJasvinder Singh 			return 0;
4254a3a95b7dSJasvinder Singh 		}
4255a3a95b7dSJasvinder Singh 
4256a3a95b7dSJasvinder Singh 		tokens += n;
4257a3a95b7dSJasvinder Singh 		n_tokens -= n;
4258a3a95b7dSJasvinder Singh 	}
4259a3a95b7dSJasvinder Singh 
4260a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4261a3a95b7dSJasvinder Singh 		uint32_t n;
4262a3a95b7dSJasvinder Singh 
4263a3a95b7dSJasvinder Singh 		n = parse_table_action_stats(tokens, n_tokens, a);
4264a3a95b7dSJasvinder Singh 		if (n == 0) {
4265a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4266a3a95b7dSJasvinder Singh 				"action stats");
4267a3a95b7dSJasvinder Singh 			return 0;
4268a3a95b7dSJasvinder Singh 		}
4269a3a95b7dSJasvinder Singh 
4270a3a95b7dSJasvinder Singh 		tokens += n;
4271a3a95b7dSJasvinder Singh 		n_tokens -= n;
4272a3a95b7dSJasvinder Singh 	}
4273a3a95b7dSJasvinder Singh 
4274a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4275a3a95b7dSJasvinder Singh 		uint32_t n;
4276a3a95b7dSJasvinder Singh 
4277a3a95b7dSJasvinder Singh 		n = parse_table_action_time(tokens, n_tokens, a);
4278a3a95b7dSJasvinder Singh 		if (n == 0) {
4279a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4280a3a95b7dSJasvinder Singh 				"action time");
4281a3a95b7dSJasvinder Singh 			return 0;
4282a3a95b7dSJasvinder Singh 		}
4283a3a95b7dSJasvinder Singh 
4284a3a95b7dSJasvinder Singh 		tokens += n;
4285a3a95b7dSJasvinder Singh 		n_tokens -= n;
4286a3a95b7dSJasvinder Singh 	}
4287a3a95b7dSJasvinder Singh 
42881edccebcSFan Zhang 	if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
42891edccebcSFan Zhang 		uint32_t n;
42901edccebcSFan Zhang 
42911edccebcSFan Zhang 		n = parse_table_action_sym_crypto(tokens, n_tokens, a);
42921edccebcSFan Zhang 		if (n == 0) {
42931edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID,
42941edccebcSFan Zhang 				"action sym_crypto");
42951bdf2632SCristian Dumitrescu 		}
42961bdf2632SCristian Dumitrescu 
42971bdf2632SCristian Dumitrescu 		tokens += n;
42981bdf2632SCristian Dumitrescu 		n_tokens -= n;
42991bdf2632SCristian Dumitrescu 	}
43001bdf2632SCristian Dumitrescu 
43011bdf2632SCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
43021bdf2632SCristian Dumitrescu 		uint32_t n;
43031bdf2632SCristian Dumitrescu 
43041bdf2632SCristian Dumitrescu 		n = parse_table_action_tag(tokens, n_tokens, a);
43051bdf2632SCristian Dumitrescu 		if (n == 0) {
43061bdf2632SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
43071bdf2632SCristian Dumitrescu 				"action tag");
43081edccebcSFan Zhang 			return 0;
43091edccebcSFan Zhang 		}
43101edccebcSFan Zhang 
43111edccebcSFan Zhang 		tokens += n;
43121edccebcSFan Zhang 		n_tokens -= n;
43131edccebcSFan Zhang 	}
43141edccebcSFan Zhang 
4315d5ed626fSCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4316d5ed626fSCristian Dumitrescu 		uint32_t n;
4317d5ed626fSCristian Dumitrescu 
4318d5ed626fSCristian Dumitrescu 		n = parse_table_action_decap(tokens, n_tokens, a);
4319d5ed626fSCristian Dumitrescu 		if (n == 0) {
4320d5ed626fSCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
4321d5ed626fSCristian Dumitrescu 				"action decap");
4322d5ed626fSCristian Dumitrescu 			return 0;
4323d5ed626fSCristian Dumitrescu 		}
4324d5ed626fSCristian Dumitrescu 
4325d5ed626fSCristian Dumitrescu 		tokens += n;
4326d5ed626fSCristian Dumitrescu 		n_tokens -= n;
4327d5ed626fSCristian Dumitrescu 	}
4328d5ed626fSCristian Dumitrescu 
4329a3a95b7dSJasvinder Singh 	if (n_tokens0 - n_tokens == 1) {
4330a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "action");
4331a3a95b7dSJasvinder Singh 		return 0;
4332a3a95b7dSJasvinder Singh 	}
4333a3a95b7dSJasvinder Singh 
4334a3a95b7dSJasvinder Singh 	return n_tokens0 - n_tokens;
4335a3a95b7dSJasvinder Singh }
4336a3a95b7dSJasvinder Singh 
433726b3effeSKevin Laatz 
433826b3effeSKevin Laatz static const char cmd_pipeline_table_rule_add_help[] =
433926b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> rule add\n"
434026b3effeSKevin Laatz "     match <match>\n"
434126b3effeSKevin Laatz "     action <table_action>\n";
434226b3effeSKevin Laatz 
4343a3a95b7dSJasvinder Singh static void
cmd_pipeline_table_rule_add(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)4344a3a95b7dSJasvinder Singh cmd_pipeline_table_rule_add(char **tokens,
4345a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
4346a3a95b7dSJasvinder Singh 	char *out,
4347a3a95b7dSJasvinder Singh 	size_t out_size)
4348a3a95b7dSJasvinder Singh {
4349a3a95b7dSJasvinder Singh 	struct table_rule_match m;
4350a3a95b7dSJasvinder Singh 	struct table_rule_action a;
4351a3a95b7dSJasvinder Singh 	char *pipeline_name;
4352a3a95b7dSJasvinder Singh 	uint32_t table_id, t0, n_tokens_parsed;
4353a3a95b7dSJasvinder Singh 	int status;
4354a3a95b7dSJasvinder Singh 
4355a3a95b7dSJasvinder Singh 	if (n_tokens < 8) {
4356a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4357a3a95b7dSJasvinder Singh 		return;
4358a3a95b7dSJasvinder Singh 	}
4359a3a95b7dSJasvinder Singh 
4360a3a95b7dSJasvinder Singh 	pipeline_name = tokens[1];
4361a3a95b7dSJasvinder Singh 
4362a3a95b7dSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
4363a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4364a3a95b7dSJasvinder Singh 		return;
4365a3a95b7dSJasvinder Singh 	}
4366a3a95b7dSJasvinder Singh 
4367a3a95b7dSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4368a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4369a3a95b7dSJasvinder Singh 		return;
4370a3a95b7dSJasvinder Singh 	}
4371a3a95b7dSJasvinder Singh 
4372a3a95b7dSJasvinder Singh 	if (strcmp(tokens[4], "rule") != 0) {
4373a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4374a3a95b7dSJasvinder Singh 		return;
4375a3a95b7dSJasvinder Singh 	}
4376a3a95b7dSJasvinder Singh 
4377a3a95b7dSJasvinder Singh 	if (strcmp(tokens[5], "add") != 0) {
4378a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4379a3a95b7dSJasvinder Singh 		return;
4380a3a95b7dSJasvinder Singh 	}
4381a3a95b7dSJasvinder Singh 
4382a3a95b7dSJasvinder Singh 	t0 = 6;
4383a3a95b7dSJasvinder Singh 
4384a3a95b7dSJasvinder Singh 	/* match */
4385a3a95b7dSJasvinder Singh 	n_tokens_parsed = parse_match(tokens + t0,
4386a3a95b7dSJasvinder Singh 		n_tokens - t0,
4387a3a95b7dSJasvinder Singh 		out,
4388a3a95b7dSJasvinder Singh 		out_size,
4389a3a95b7dSJasvinder Singh 		&m);
4390a3a95b7dSJasvinder Singh 	if (n_tokens_parsed == 0)
4391a3a95b7dSJasvinder Singh 		return;
4392a3a95b7dSJasvinder Singh 	t0 += n_tokens_parsed;
4393a3a95b7dSJasvinder Singh 
4394a3a95b7dSJasvinder Singh 	/* action */
4395a3a95b7dSJasvinder Singh 	n_tokens_parsed = parse_table_action(tokens + t0,
4396a3a95b7dSJasvinder Singh 		n_tokens - t0,
4397a3a95b7dSJasvinder Singh 		out,
4398a3a95b7dSJasvinder Singh 		out_size,
4399a3a95b7dSJasvinder Singh 		&a);
4400a3a95b7dSJasvinder Singh 	if (n_tokens_parsed == 0)
4401a3a95b7dSJasvinder Singh 		return;
4402a3a95b7dSJasvinder Singh 	t0 += n_tokens_parsed;
4403a3a95b7dSJasvinder Singh 
4404a3a95b7dSJasvinder Singh 	if (t0 != n_tokens) {
4405a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4406a3a95b7dSJasvinder Singh 		return;
4407a3a95b7dSJasvinder Singh 	}
4408a3a95b7dSJasvinder Singh 
44094c65163eSCristian Dumitrescu 	status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
4410a3a95b7dSJasvinder Singh 	if (status) {
4411a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4412a3a95b7dSJasvinder Singh 		return;
4413a3a95b7dSJasvinder Singh 	}
44141edccebcSFan Zhang 
44151edccebcSFan Zhang 	if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
44161edccebcSFan Zhang 		parse_free_sym_crypto_param_data(&a.sym_crypto);
4417a3a95b7dSJasvinder Singh }
4418a3a95b7dSJasvinder Singh 
441926b3effeSKevin Laatz 
442026b3effeSKevin Laatz static const char cmd_pipeline_table_rule_add_default_help[] =
442126b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> rule add\n"
442226b3effeSKevin Laatz "     match\n"
442326b3effeSKevin Laatz "        default\n"
442426b3effeSKevin Laatz "     action\n"
442526b3effeSKevin Laatz "        fwd\n"
442626b3effeSKevin Laatz "           drop\n"
442726b3effeSKevin Laatz "           | port <port_id>\n"
442826b3effeSKevin Laatz "           | meta\n"
442926b3effeSKevin Laatz "           | table <table_id>\n";
443026b3effeSKevin Laatz 
4431a3a95b7dSJasvinder Singh static void
cmd_pipeline_table_rule_add_default(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)4432a3a95b7dSJasvinder Singh cmd_pipeline_table_rule_add_default(char **tokens,
4433a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
4434a3a95b7dSJasvinder Singh 	char *out,
4435a3a95b7dSJasvinder Singh 	size_t out_size)
4436a3a95b7dSJasvinder Singh {
4437a3a95b7dSJasvinder Singh 	struct table_rule_action action;
4438a3a95b7dSJasvinder Singh 	char *pipeline_name;
4439a3a95b7dSJasvinder Singh 	uint32_t table_id;
4440a3a95b7dSJasvinder Singh 	int status;
4441a3a95b7dSJasvinder Singh 
4442a3a95b7dSJasvinder Singh 	if ((n_tokens != 11) && (n_tokens != 12)) {
4443a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4444a3a95b7dSJasvinder Singh 		return;
4445a3a95b7dSJasvinder Singh 	}
4446a3a95b7dSJasvinder Singh 
4447a3a95b7dSJasvinder Singh 	pipeline_name = tokens[1];
4448a3a95b7dSJasvinder Singh 
4449a3a95b7dSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
4450a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4451a3a95b7dSJasvinder Singh 		return;
4452a3a95b7dSJasvinder Singh 	}
4453a3a95b7dSJasvinder Singh 
4454a3a95b7dSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4455a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4456a3a95b7dSJasvinder Singh 		return;
4457a3a95b7dSJasvinder Singh 	}
4458a3a95b7dSJasvinder Singh 
4459a3a95b7dSJasvinder Singh 	if (strcmp(tokens[4], "rule") != 0) {
4460a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4461a3a95b7dSJasvinder Singh 		return;
4462a3a95b7dSJasvinder Singh 	}
4463a3a95b7dSJasvinder Singh 
4464a3a95b7dSJasvinder Singh 	if (strcmp(tokens[5], "add") != 0) {
4465a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4466a3a95b7dSJasvinder Singh 		return;
4467a3a95b7dSJasvinder Singh 	}
4468a3a95b7dSJasvinder Singh 
4469a3a95b7dSJasvinder Singh 	if (strcmp(tokens[6], "match") != 0) {
4470a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "match");
4471a3a95b7dSJasvinder Singh 		return;
4472a3a95b7dSJasvinder Singh 	}
4473a3a95b7dSJasvinder Singh 
4474a3a95b7dSJasvinder Singh 	if (strcmp(tokens[7], "default") != 0) {
4475a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "default");
4476a3a95b7dSJasvinder Singh 		return;
4477a3a95b7dSJasvinder Singh 	}
4478a3a95b7dSJasvinder Singh 
4479a3a95b7dSJasvinder Singh 	if (strcmp(tokens[8], "action") != 0) {
4480a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "action");
4481a3a95b7dSJasvinder Singh 		return;
4482a3a95b7dSJasvinder Singh 	}
4483a3a95b7dSJasvinder Singh 
4484a3a95b7dSJasvinder Singh 	if (strcmp(tokens[9], "fwd") != 0) {
4485a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4486a3a95b7dSJasvinder Singh 		return;
4487a3a95b7dSJasvinder Singh 	}
4488a3a95b7dSJasvinder Singh 
4489a3a95b7dSJasvinder Singh 	action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4490a3a95b7dSJasvinder Singh 
4491a3a95b7dSJasvinder Singh 	if (strcmp(tokens[10], "drop") == 0) {
4492a3a95b7dSJasvinder Singh 		if (n_tokens != 11) {
4493a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4494a3a95b7dSJasvinder Singh 			return;
4495a3a95b7dSJasvinder Singh 		}
4496a3a95b7dSJasvinder Singh 
4497a3a95b7dSJasvinder Singh 		action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4498a3a95b7dSJasvinder Singh 	} else if (strcmp(tokens[10], "port") == 0) {
4499a3a95b7dSJasvinder Singh 		uint32_t id;
4500a3a95b7dSJasvinder Singh 
4501a3a95b7dSJasvinder Singh 		if (n_tokens != 12) {
4502a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4503a3a95b7dSJasvinder Singh 			return;
4504a3a95b7dSJasvinder Singh 		}
4505a3a95b7dSJasvinder Singh 
4506a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&id, tokens[11]) != 0) {
4507a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4508a3a95b7dSJasvinder Singh 			return;
4509a3a95b7dSJasvinder Singh 		}
4510a3a95b7dSJasvinder Singh 
4511a3a95b7dSJasvinder Singh 		action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4512a3a95b7dSJasvinder Singh 		action.fwd.id = id;
4513a3a95b7dSJasvinder Singh 	} else if (strcmp(tokens[10], "meta") == 0) {
4514a3a95b7dSJasvinder Singh 		if (n_tokens != 11) {
4515a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4516a3a95b7dSJasvinder Singh 			return;
4517a3a95b7dSJasvinder Singh 		}
4518a3a95b7dSJasvinder Singh 
4519a3a95b7dSJasvinder Singh 		action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4520a3a95b7dSJasvinder Singh 	} else if (strcmp(tokens[10], "table") == 0) {
4521a3a95b7dSJasvinder Singh 		uint32_t id;
4522a3a95b7dSJasvinder Singh 
4523a3a95b7dSJasvinder Singh 		if (n_tokens != 12) {
4524a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4525a3a95b7dSJasvinder Singh 			return;
4526a3a95b7dSJasvinder Singh 		}
4527a3a95b7dSJasvinder Singh 
4528a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&id, tokens[11]) != 0) {
4529a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4530a3a95b7dSJasvinder Singh 			return;
4531a3a95b7dSJasvinder Singh 		}
4532a3a95b7dSJasvinder Singh 
4533a3a95b7dSJasvinder Singh 		action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4534a3a95b7dSJasvinder Singh 		action.fwd.id = id;
4535a3a95b7dSJasvinder Singh 	} else {
4536a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID,
4537a3a95b7dSJasvinder Singh 			"drop or port or meta or table");
4538a3a95b7dSJasvinder Singh 		return;
4539a3a95b7dSJasvinder Singh 	}
4540a3a95b7dSJasvinder Singh 
4541a3a95b7dSJasvinder Singh 	status = pipeline_table_rule_add_default(pipeline_name,
4542a3a95b7dSJasvinder Singh 		table_id,
4543c348ec05SCristian Dumitrescu 		&action);
4544a3a95b7dSJasvinder Singh 	if (status) {
4545a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4546a3a95b7dSJasvinder Singh 		return;
4547a3a95b7dSJasvinder Singh 	}
4548a3a95b7dSJasvinder Singh }
4549a3a95b7dSJasvinder Singh 
455026b3effeSKevin Laatz 
455126b3effeSKevin Laatz static const char cmd_pipeline_table_rule_add_bulk_help[] =
455227b333b2SCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\n"
455326b3effeSKevin Laatz "\n"
455426b3effeSKevin Laatz "  File <file_name>:\n"
455526b3effeSKevin Laatz "  - line format: match <match> action <action>\n";
455626b3effeSKevin Laatz 
45573186282fSJasvinder Singh static int
45583186282fSJasvinder Singh cli_rule_file_process(const char *file_name,
45593186282fSJasvinder Singh 	size_t line_len_max,
456027b333b2SCristian Dumitrescu 	struct table_rule_list **rule_list,
45613186282fSJasvinder Singh 	uint32_t *n_rules,
45623186282fSJasvinder Singh 	uint32_t *line_number,
45633186282fSJasvinder Singh 	char *out,
45643186282fSJasvinder Singh 	size_t out_size);
45653186282fSJasvinder Singh 
45663186282fSJasvinder Singh static void
cmd_pipeline_table_rule_add_bulk(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)45673186282fSJasvinder Singh cmd_pipeline_table_rule_add_bulk(char **tokens,
45683186282fSJasvinder Singh 	uint32_t n_tokens,
45693186282fSJasvinder Singh 	char *out,
45703186282fSJasvinder Singh 	size_t out_size)
45713186282fSJasvinder Singh {
457227b333b2SCristian Dumitrescu 	struct table_rule_list *list = NULL;
45733186282fSJasvinder Singh 	char *pipeline_name, *file_name;
457427b333b2SCristian Dumitrescu 	uint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;
45753186282fSJasvinder Singh 	int status;
45763186282fSJasvinder Singh 
457727b333b2SCristian Dumitrescu 	if (n_tokens != 8) {
45783186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
45793186282fSJasvinder Singh 		return;
45803186282fSJasvinder Singh 	}
45813186282fSJasvinder Singh 
45823186282fSJasvinder Singh 	pipeline_name = tokens[1];
45833186282fSJasvinder Singh 
45843186282fSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
45853186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
45863186282fSJasvinder Singh 		return;
45873186282fSJasvinder Singh 	}
45883186282fSJasvinder Singh 
45893186282fSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
45903186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
45913186282fSJasvinder Singh 		return;
45923186282fSJasvinder Singh 	}
45933186282fSJasvinder Singh 
45943186282fSJasvinder Singh 	if (strcmp(tokens[4], "rule") != 0) {
45953186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
45963186282fSJasvinder Singh 		return;
45973186282fSJasvinder Singh 	}
45983186282fSJasvinder Singh 
45993186282fSJasvinder Singh 	if (strcmp(tokens[5], "add") != 0) {
46003186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
46013186282fSJasvinder Singh 		return;
46023186282fSJasvinder Singh 	}
46033186282fSJasvinder Singh 
46043186282fSJasvinder Singh 	if (strcmp(tokens[6], "bulk") != 0) {
46053186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
46063186282fSJasvinder Singh 		return;
46073186282fSJasvinder Singh 	}
46083186282fSJasvinder Singh 
46093186282fSJasvinder Singh 	file_name = tokens[7];
46103186282fSJasvinder Singh 
461127b333b2SCristian Dumitrescu 	/* Load rules from file. */
46123186282fSJasvinder Singh 	status = cli_rule_file_process(file_name,
46133186282fSJasvinder Singh 		1024,
461427b333b2SCristian Dumitrescu 		&list,
461527b333b2SCristian Dumitrescu 		&n_rules,
46163186282fSJasvinder Singh 		&line_number,
46173186282fSJasvinder Singh 		out,
46183186282fSJasvinder Singh 		out_size);
46193186282fSJasvinder Singh 	if (status) {
46203186282fSJasvinder Singh 		snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
46213186282fSJasvinder Singh 		return;
46223186282fSJasvinder Singh 	}
46233186282fSJasvinder Singh 
46243186282fSJasvinder Singh 	/* Rule bulk add */
46253186282fSJasvinder Singh 	status = pipeline_table_rule_add_bulk(pipeline_name,
46263186282fSJasvinder Singh 		table_id,
462727b333b2SCristian Dumitrescu 		list,
462827b333b2SCristian Dumitrescu 		&n_rules_added,
462927b333b2SCristian Dumitrescu 		&n_rules_not_added);
46303186282fSJasvinder Singh 	if (status) {
46313186282fSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
46323186282fSJasvinder Singh 		return;
46333186282fSJasvinder Singh 	}
46343186282fSJasvinder Singh 
463527b333b2SCristian Dumitrescu 	snprintf(out, out_size, "Added %u rules out of %u.\n",
463627b333b2SCristian Dumitrescu 		n_rules_added,
463727b333b2SCristian Dumitrescu 		n_rules);
46383186282fSJasvinder Singh }
46393186282fSJasvinder Singh 
464026b3effeSKevin Laatz 
464126b3effeSKevin Laatz static const char cmd_pipeline_table_rule_delete_help[] =
464226b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> rule delete\n"
464326b3effeSKevin Laatz "     match <match>\n";
464426b3effeSKevin Laatz 
4645f634e4c5SJasvinder Singh static void
cmd_pipeline_table_rule_delete(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)4646f634e4c5SJasvinder Singh cmd_pipeline_table_rule_delete(char **tokens,
4647f634e4c5SJasvinder Singh 	uint32_t n_tokens,
4648f634e4c5SJasvinder Singh 	char *out,
4649f634e4c5SJasvinder Singh 	size_t out_size)
4650f634e4c5SJasvinder Singh {
4651f634e4c5SJasvinder Singh 	struct table_rule_match m;
4652f634e4c5SJasvinder Singh 	char *pipeline_name;
4653f634e4c5SJasvinder Singh 	uint32_t table_id, n_tokens_parsed, t0;
4654f634e4c5SJasvinder Singh 	int status;
4655f634e4c5SJasvinder Singh 
4656f634e4c5SJasvinder Singh 	if (n_tokens < 8) {
4657f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4658f634e4c5SJasvinder Singh 		return;
4659f634e4c5SJasvinder Singh 	}
4660f634e4c5SJasvinder Singh 
4661f634e4c5SJasvinder Singh 	pipeline_name = tokens[1];
4662f634e4c5SJasvinder Singh 
4663f634e4c5SJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
4664f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4665f634e4c5SJasvinder Singh 		return;
4666f634e4c5SJasvinder Singh 	}
4667f634e4c5SJasvinder Singh 
4668f634e4c5SJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4669f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4670f634e4c5SJasvinder Singh 		return;
4671f634e4c5SJasvinder Singh 	}
4672f634e4c5SJasvinder Singh 
4673f634e4c5SJasvinder Singh 	if (strcmp(tokens[4], "rule") != 0) {
4674f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4675f634e4c5SJasvinder Singh 		return;
4676f634e4c5SJasvinder Singh 	}
4677f634e4c5SJasvinder Singh 
4678f634e4c5SJasvinder Singh 	if (strcmp(tokens[5], "delete") != 0) {
4679f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4680f634e4c5SJasvinder Singh 		return;
4681f634e4c5SJasvinder Singh 	}
4682f634e4c5SJasvinder Singh 
4683f634e4c5SJasvinder Singh 	t0 = 6;
4684f634e4c5SJasvinder Singh 
4685f634e4c5SJasvinder Singh 	/* match */
4686f634e4c5SJasvinder Singh 	n_tokens_parsed = parse_match(tokens + t0,
4687f634e4c5SJasvinder Singh 		n_tokens - t0,
4688f634e4c5SJasvinder Singh 		out,
4689f634e4c5SJasvinder Singh 		out_size,
4690f634e4c5SJasvinder Singh 		&m);
4691f634e4c5SJasvinder Singh 	if (n_tokens_parsed == 0)
4692f634e4c5SJasvinder Singh 		return;
4693f634e4c5SJasvinder Singh 	t0 += n_tokens_parsed;
4694f634e4c5SJasvinder Singh 
4695f634e4c5SJasvinder Singh 	if (n_tokens != t0) {
4696f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4697f634e4c5SJasvinder Singh 		return;
4698f634e4c5SJasvinder Singh 	}
4699f634e4c5SJasvinder Singh 
4700f634e4c5SJasvinder Singh 	status = pipeline_table_rule_delete(pipeline_name,
4701f634e4c5SJasvinder Singh 		table_id,
4702f634e4c5SJasvinder Singh 		&m);
4703f634e4c5SJasvinder Singh 	if (status) {
4704f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4705f634e4c5SJasvinder Singh 		return;
4706f634e4c5SJasvinder Singh 	}
4707f634e4c5SJasvinder Singh }
4708f634e4c5SJasvinder Singh 
470926b3effeSKevin Laatz 
471026b3effeSKevin Laatz static const char cmd_pipeline_table_rule_delete_default_help[] =
471126b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> rule delete\n"
471226b3effeSKevin Laatz "     match\n"
471326b3effeSKevin Laatz "        default\n";
471426b3effeSKevin Laatz 
4715f634e4c5SJasvinder Singh static void
cmd_pipeline_table_rule_delete_default(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)4716f634e4c5SJasvinder Singh cmd_pipeline_table_rule_delete_default(char **tokens,
4717f634e4c5SJasvinder Singh 	uint32_t n_tokens,
4718f634e4c5SJasvinder Singh 	char *out,
4719f634e4c5SJasvinder Singh 	size_t out_size)
4720f634e4c5SJasvinder Singh {
4721f634e4c5SJasvinder Singh 	char *pipeline_name;
4722f634e4c5SJasvinder Singh 	uint32_t table_id;
4723f634e4c5SJasvinder Singh 	int status;
4724f634e4c5SJasvinder Singh 
4725f634e4c5SJasvinder Singh 	if (n_tokens != 8) {
4726f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4727f634e4c5SJasvinder Singh 		return;
4728f634e4c5SJasvinder Singh 	}
4729f634e4c5SJasvinder Singh 
4730f634e4c5SJasvinder Singh 	pipeline_name = tokens[1];
4731f634e4c5SJasvinder Singh 
4732f634e4c5SJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
4733f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4734f634e4c5SJasvinder Singh 		return;
4735f634e4c5SJasvinder Singh 	}
4736f634e4c5SJasvinder Singh 
4737f634e4c5SJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4738f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4739f634e4c5SJasvinder Singh 		return;
4740f634e4c5SJasvinder Singh 	}
4741f634e4c5SJasvinder Singh 
4742f634e4c5SJasvinder Singh 	if (strcmp(tokens[4], "rule") != 0) {
4743f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4744f634e4c5SJasvinder Singh 		return;
4745f634e4c5SJasvinder Singh 	}
4746f634e4c5SJasvinder Singh 
4747f634e4c5SJasvinder Singh 	if (strcmp(tokens[5], "delete") != 0) {
4748f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4749f634e4c5SJasvinder Singh 		return;
4750f634e4c5SJasvinder Singh 	}
4751f634e4c5SJasvinder Singh 
4752f634e4c5SJasvinder Singh 	if (strcmp(tokens[6], "match") != 0) {
4753f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "match");
4754f634e4c5SJasvinder Singh 		return;
4755f634e4c5SJasvinder Singh 	}
4756f634e4c5SJasvinder Singh 
4757f634e4c5SJasvinder Singh 	if (strcmp(tokens[7], "default") != 0) {
4758f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "default");
4759f634e4c5SJasvinder Singh 		return;
4760f634e4c5SJasvinder Singh 	}
4761f634e4c5SJasvinder Singh 
4762f634e4c5SJasvinder Singh 	status = pipeline_table_rule_delete_default(pipeline_name,
4763f634e4c5SJasvinder Singh 		table_id);
4764f634e4c5SJasvinder Singh 	if (status) {
4765f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4766f634e4c5SJasvinder Singh 		return;
4767f634e4c5SJasvinder Singh 	}
4768f634e4c5SJasvinder Singh }
4769f634e4c5SJasvinder Singh 
47702fbdf834SCristian Dumitrescu static void
ether_addr_show(FILE * f,struct rte_ether_addr * addr)47716d13ea8eSOlivier Matz ether_addr_show(FILE *f, struct rte_ether_addr *addr)
47722fbdf834SCristian Dumitrescu {
4773*a7db3afcSAman Deep Singh 	fprintf(f, RTE_ETHER_ADDR_PRT_FMT, RTE_ETHER_ADDR_BYTES(addr));
47742fbdf834SCristian Dumitrescu }
47752fbdf834SCristian Dumitrescu 
47762fbdf834SCristian Dumitrescu static void
ipv4_addr_show(FILE * f,uint32_t addr)47772fbdf834SCristian Dumitrescu ipv4_addr_show(FILE *f, uint32_t addr)
47782fbdf834SCristian Dumitrescu {
47792fbdf834SCristian Dumitrescu 	fprintf(f, "%u.%u.%u.%u",
47802fbdf834SCristian Dumitrescu 		addr >> 24,
47812fbdf834SCristian Dumitrescu 		(addr >> 16) & 0xFF,
47822fbdf834SCristian Dumitrescu 		(addr >> 8) & 0xFF,
47832fbdf834SCristian Dumitrescu 		addr & 0xFF);
47842fbdf834SCristian Dumitrescu }
47852fbdf834SCristian Dumitrescu 
47862fbdf834SCristian Dumitrescu static void
ipv6_addr_show(FILE * f,uint8_t * addr)47872fbdf834SCristian Dumitrescu ipv6_addr_show(FILE *f, uint8_t *addr)
47882fbdf834SCristian Dumitrescu {
47892fbdf834SCristian Dumitrescu 	fprintf(f, "%02x%02x:%02x%02x:%02x%02x:%02x%02x:"
47902fbdf834SCristian Dumitrescu 		"%02x%02x:%02x%02x:%02x%02x:%02x%02x:",
47912fbdf834SCristian Dumitrescu 		(uint32_t)addr[0], (uint32_t)addr[1],
47922fbdf834SCristian Dumitrescu 		(uint32_t)addr[2], (uint32_t)addr[3],
47932fbdf834SCristian Dumitrescu 		(uint32_t)addr[4], (uint32_t)addr[5],
47942fbdf834SCristian Dumitrescu 		(uint32_t)addr[6], (uint32_t)addr[7],
47952fbdf834SCristian Dumitrescu 		(uint32_t)addr[8], (uint32_t)addr[9],
47962fbdf834SCristian Dumitrescu 		(uint32_t)addr[10], (uint32_t)addr[11],
47972fbdf834SCristian Dumitrescu 		(uint32_t)addr[12], (uint32_t)addr[13],
47982fbdf834SCristian Dumitrescu 		(uint32_t)addr[14], (uint32_t)addr[15]);
47992fbdf834SCristian Dumitrescu }
48002fbdf834SCristian Dumitrescu 
48012fbdf834SCristian Dumitrescu static const char *
policer_action_string(enum rte_table_action_policer action)48022fbdf834SCristian Dumitrescu policer_action_string(enum rte_table_action_policer action) {
48032fbdf834SCristian Dumitrescu 	switch (action) {
48042fbdf834SCristian Dumitrescu 		case RTE_TABLE_ACTION_POLICER_COLOR_GREEN: return "G";
48052fbdf834SCristian Dumitrescu 		case RTE_TABLE_ACTION_POLICER_COLOR_YELLOW: return "Y";
48062fbdf834SCristian Dumitrescu 		case RTE_TABLE_ACTION_POLICER_COLOR_RED: return "R";
48072fbdf834SCristian Dumitrescu 		case RTE_TABLE_ACTION_POLICER_DROP: return "D";
48082fbdf834SCristian Dumitrescu 		default: return "?";
48092fbdf834SCristian Dumitrescu 	}
48102fbdf834SCristian Dumitrescu }
48112fbdf834SCristian Dumitrescu 
48122fbdf834SCristian Dumitrescu static int
table_rule_show(const char * pipeline_name,uint32_t table_id,const char * file_name)48132fbdf834SCristian Dumitrescu table_rule_show(const char *pipeline_name,
48142fbdf834SCristian Dumitrescu 	uint32_t table_id,
48152fbdf834SCristian Dumitrescu 	const char *file_name)
48162fbdf834SCristian Dumitrescu {
48172fbdf834SCristian Dumitrescu 	struct pipeline *p;
48182fbdf834SCristian Dumitrescu 	struct table *table;
48192fbdf834SCristian Dumitrescu 	struct table_rule *rule;
48202fbdf834SCristian Dumitrescu 	FILE *f = NULL;
48212fbdf834SCristian Dumitrescu 	uint32_t i;
48222fbdf834SCristian Dumitrescu 
48232fbdf834SCristian Dumitrescu 	/* Check input params. */
48242fbdf834SCristian Dumitrescu 	if ((pipeline_name == NULL) ||
48252fbdf834SCristian Dumitrescu 		(file_name == NULL))
48262fbdf834SCristian Dumitrescu 		return -1;
48272fbdf834SCristian Dumitrescu 
48282fbdf834SCristian Dumitrescu 	p = pipeline_find(pipeline_name);
48292fbdf834SCristian Dumitrescu 	if ((p == NULL) ||
48302fbdf834SCristian Dumitrescu 		(table_id >= p->n_tables))
48312fbdf834SCristian Dumitrescu 		return -1;
48322fbdf834SCristian Dumitrescu 
48332fbdf834SCristian Dumitrescu 	table = &p->table[table_id];
48342fbdf834SCristian Dumitrescu 
48352fbdf834SCristian Dumitrescu 	/* Open file. */
48362fbdf834SCristian Dumitrescu 	f = fopen(file_name, "w");
48372fbdf834SCristian Dumitrescu 	if (f == NULL)
48382fbdf834SCristian Dumitrescu 		return -1;
48392fbdf834SCristian Dumitrescu 
48402fbdf834SCristian Dumitrescu 	/* Write table rules to file. */
48412fbdf834SCristian Dumitrescu 	TAILQ_FOREACH(rule, &table->rules, node) {
48422fbdf834SCristian Dumitrescu 		struct table_rule_match *m = &rule->match;
48432fbdf834SCristian Dumitrescu 		struct table_rule_action *a = &rule->action;
48442fbdf834SCristian Dumitrescu 
48452fbdf834SCristian Dumitrescu 		fprintf(f, "match ");
48462fbdf834SCristian Dumitrescu 		switch (m->match_type) {
48472fbdf834SCristian Dumitrescu 		case TABLE_ACL:
48482fbdf834SCristian Dumitrescu 			fprintf(f, "acl priority %u ",
48492fbdf834SCristian Dumitrescu 				m->match.acl.priority);
48502fbdf834SCristian Dumitrescu 
48512fbdf834SCristian Dumitrescu 			fprintf(f, m->match.acl.ip_version ? "ipv4 " : "ipv6 ");
48522fbdf834SCristian Dumitrescu 
48532fbdf834SCristian Dumitrescu 			if (m->match.acl.ip_version)
48542fbdf834SCristian Dumitrescu 				ipv4_addr_show(f, m->match.acl.ipv4.sa);
48552fbdf834SCristian Dumitrescu 			else
48562fbdf834SCristian Dumitrescu 				ipv6_addr_show(f, m->match.acl.ipv6.sa);
48572fbdf834SCristian Dumitrescu 
48582fbdf834SCristian Dumitrescu 			fprintf(f, "%u",	m->match.acl.sa_depth);
48592fbdf834SCristian Dumitrescu 
48602fbdf834SCristian Dumitrescu 			if (m->match.acl.ip_version)
48612fbdf834SCristian Dumitrescu 				ipv4_addr_show(f, m->match.acl.ipv4.da);
48622fbdf834SCristian Dumitrescu 			else
48632fbdf834SCristian Dumitrescu 				ipv6_addr_show(f, m->match.acl.ipv6.da);
48642fbdf834SCristian Dumitrescu 
48652fbdf834SCristian Dumitrescu 			fprintf(f, "%u",	m->match.acl.da_depth);
48662fbdf834SCristian Dumitrescu 
48672fbdf834SCristian Dumitrescu 			fprintf(f, "%u %u %u %u %u ",
48682fbdf834SCristian Dumitrescu 				(uint32_t)m->match.acl.sp0,
48692fbdf834SCristian Dumitrescu 				(uint32_t)m->match.acl.sp1,
48702fbdf834SCristian Dumitrescu 				(uint32_t)m->match.acl.dp0,
48712fbdf834SCristian Dumitrescu 				(uint32_t)m->match.acl.dp1,
48722fbdf834SCristian Dumitrescu 				(uint32_t)m->match.acl.proto);
48732fbdf834SCristian Dumitrescu 			break;
48742fbdf834SCristian Dumitrescu 
48752fbdf834SCristian Dumitrescu 		case TABLE_ARRAY:
48762fbdf834SCristian Dumitrescu 			fprintf(f, "array %u ",
48772fbdf834SCristian Dumitrescu 				m->match.array.pos);
48782fbdf834SCristian Dumitrescu 			break;
48792fbdf834SCristian Dumitrescu 
48802fbdf834SCristian Dumitrescu 		case TABLE_HASH:
48812fbdf834SCristian Dumitrescu 			fprintf(f, "hash raw ");
48822fbdf834SCristian Dumitrescu 			for (i = 0; i < table->params.match.hash.key_size; i++)
48832fbdf834SCristian Dumitrescu 				fprintf(f, "%02x", m->match.hash.key[i]);
48842fbdf834SCristian Dumitrescu 			fprintf(f, " ");
48852fbdf834SCristian Dumitrescu 			break;
48862fbdf834SCristian Dumitrescu 
48872fbdf834SCristian Dumitrescu 		case TABLE_LPM:
48882fbdf834SCristian Dumitrescu 			fprintf(f, "lpm ");
48892fbdf834SCristian Dumitrescu 
48902fbdf834SCristian Dumitrescu 			fprintf(f, m->match.lpm.ip_version ? "ipv4 " : "ipv6 ");
48912fbdf834SCristian Dumitrescu 
48922fbdf834SCristian Dumitrescu 			if (m->match.acl.ip_version)
48932fbdf834SCristian Dumitrescu 				ipv4_addr_show(f, m->match.lpm.ipv4);
48942fbdf834SCristian Dumitrescu 			else
48952fbdf834SCristian Dumitrescu 				ipv6_addr_show(f, m->match.lpm.ipv6);
48962fbdf834SCristian Dumitrescu 
48972fbdf834SCristian Dumitrescu 			fprintf(f, "%u ",
48982fbdf834SCristian Dumitrescu 				(uint32_t)m->match.lpm.depth);
48992fbdf834SCristian Dumitrescu 			break;
49002fbdf834SCristian Dumitrescu 
49012fbdf834SCristian Dumitrescu 		default:
49022fbdf834SCristian Dumitrescu 			fprintf(f, "unknown ");
49032fbdf834SCristian Dumitrescu 		}
49042fbdf834SCristian Dumitrescu 
49052fbdf834SCristian Dumitrescu 		fprintf(f, "action ");
49062fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
49072fbdf834SCristian Dumitrescu 			fprintf(f, "fwd ");
49082fbdf834SCristian Dumitrescu 			switch (a->fwd.action) {
49092fbdf834SCristian Dumitrescu 			case RTE_PIPELINE_ACTION_DROP:
49102fbdf834SCristian Dumitrescu 				fprintf(f, "drop ");
49112fbdf834SCristian Dumitrescu 				break;
49122fbdf834SCristian Dumitrescu 
49132fbdf834SCristian Dumitrescu 			case RTE_PIPELINE_ACTION_PORT:
49142fbdf834SCristian Dumitrescu 				fprintf(f, "port %u ", a->fwd.id);
49152fbdf834SCristian Dumitrescu 				break;
49162fbdf834SCristian Dumitrescu 
49172fbdf834SCristian Dumitrescu 			case RTE_PIPELINE_ACTION_PORT_META:
49182fbdf834SCristian Dumitrescu 				fprintf(f, "meta ");
49192fbdf834SCristian Dumitrescu 				break;
49202fbdf834SCristian Dumitrescu 
49212fbdf834SCristian Dumitrescu 			case RTE_PIPELINE_ACTION_TABLE:
49222fbdf834SCristian Dumitrescu 			default:
49232fbdf834SCristian Dumitrescu 				fprintf(f, "table %u ", a->fwd.id);
49242fbdf834SCristian Dumitrescu 			}
49252fbdf834SCristian Dumitrescu 		}
49262fbdf834SCristian Dumitrescu 
49272fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
49282fbdf834SCristian Dumitrescu 			fprintf(f, "balance ");
49292fbdf834SCristian Dumitrescu 			for (i = 0; i < RTE_DIM(a->lb.out); i++)
49302fbdf834SCristian Dumitrescu 				fprintf(f, "%u ", a->lb.out[i]);
49312fbdf834SCristian Dumitrescu 		}
49322fbdf834SCristian Dumitrescu 
49332fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
49342fbdf834SCristian Dumitrescu 			fprintf(f, "mtr ");
49352fbdf834SCristian Dumitrescu 			for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++)
49362fbdf834SCristian Dumitrescu 				if (a->mtr.tc_mask & (1 << i)) {
49372fbdf834SCristian Dumitrescu 					struct rte_table_action_mtr_tc_params *p =
49382fbdf834SCristian Dumitrescu 						&a->mtr.mtr[i];
49392fbdf834SCristian Dumitrescu 					enum rte_table_action_policer ga =
4940c1656328SJasvinder Singh 						p->policer[RTE_COLOR_GREEN];
49412fbdf834SCristian Dumitrescu 					enum rte_table_action_policer ya =
4942c1656328SJasvinder Singh 						p->policer[RTE_COLOR_YELLOW];
49432fbdf834SCristian Dumitrescu 					enum rte_table_action_policer ra =
4944c1656328SJasvinder Singh 						p->policer[RTE_COLOR_RED];
49452fbdf834SCristian Dumitrescu 
49462fbdf834SCristian Dumitrescu 					fprintf(f, "tc%u meter %u policer g %s y %s r %s ",
49472fbdf834SCristian Dumitrescu 						i,
49482fbdf834SCristian Dumitrescu 						a->mtr.mtr[i].meter_profile_id,
49492fbdf834SCristian Dumitrescu 						policer_action_string(ga),
49502fbdf834SCristian Dumitrescu 						policer_action_string(ya),
49512fbdf834SCristian Dumitrescu 						policer_action_string(ra));
49522fbdf834SCristian Dumitrescu 				}
49532fbdf834SCristian Dumitrescu 		}
49542fbdf834SCristian Dumitrescu 
49552fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TM))
49562fbdf834SCristian Dumitrescu 			fprintf(f, "tm subport %u pipe %u ",
49572fbdf834SCristian Dumitrescu 				a->tm.subport_id,
49582fbdf834SCristian Dumitrescu 				a->tm.pipe_id);
49592fbdf834SCristian Dumitrescu 
49602fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
49612fbdf834SCristian Dumitrescu 			fprintf(f, "encap ");
49622fbdf834SCristian Dumitrescu 			switch (a->encap.type) {
49632fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_ETHER:
49642fbdf834SCristian Dumitrescu 				fprintf(f, "ether ");
49652fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.ether.ether.da);
49662fbdf834SCristian Dumitrescu 				fprintf(f, " ");
49672fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.ether.ether.sa);
49682fbdf834SCristian Dumitrescu 				fprintf(f, " ");
49692fbdf834SCristian Dumitrescu 				break;
49702fbdf834SCristian Dumitrescu 
49712fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_VLAN:
49722fbdf834SCristian Dumitrescu 				fprintf(f, "vlan ");
49732fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.vlan.ether.da);
49742fbdf834SCristian Dumitrescu 				fprintf(f, " ");
49752fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.vlan.ether.sa);
49762fbdf834SCristian Dumitrescu 				fprintf(f, " pcp %u dei %u vid %u ",
49772fbdf834SCristian Dumitrescu 					a->encap.vlan.vlan.pcp,
49782fbdf834SCristian Dumitrescu 					a->encap.vlan.vlan.dei,
49792fbdf834SCristian Dumitrescu 					a->encap.vlan.vlan.vid);
49802fbdf834SCristian Dumitrescu 				break;
49812fbdf834SCristian Dumitrescu 
49822fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_QINQ:
49832fbdf834SCristian Dumitrescu 				fprintf(f, "qinq ");
49842fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.qinq.ether.da);
49852fbdf834SCristian Dumitrescu 				fprintf(f, " ");
49862fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.qinq.ether.sa);
49872fbdf834SCristian Dumitrescu 				fprintf(f, " pcp %u dei %u vid %u pcp %u dei %u vid %u ",
49882fbdf834SCristian Dumitrescu 					a->encap.qinq.svlan.pcp,
49892fbdf834SCristian Dumitrescu 					a->encap.qinq.svlan.dei,
49902fbdf834SCristian Dumitrescu 					a->encap.qinq.svlan.vid,
49912fbdf834SCristian Dumitrescu 					a->encap.qinq.cvlan.pcp,
49922fbdf834SCristian Dumitrescu 					a->encap.qinq.cvlan.dei,
49932fbdf834SCristian Dumitrescu 					a->encap.qinq.cvlan.vid);
49942fbdf834SCristian Dumitrescu 				break;
49952fbdf834SCristian Dumitrescu 
49962fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_MPLS:
49972fbdf834SCristian Dumitrescu 				fprintf(f, "mpls %s ", (a->encap.mpls.unicast) ?
49982fbdf834SCristian Dumitrescu 					"unicast " : "multicast ");
49992fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.mpls.ether.da);
50002fbdf834SCristian Dumitrescu 				fprintf(f, " ");
50012fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.mpls.ether.sa);
50022fbdf834SCristian Dumitrescu 				fprintf(f, " ");
50032fbdf834SCristian Dumitrescu 				for (i = 0; i < a->encap.mpls.mpls_count; i++) {
50042fbdf834SCristian Dumitrescu 					struct rte_table_action_mpls_hdr *l =
50052fbdf834SCristian Dumitrescu 						&a->encap.mpls.mpls[i];
50062fbdf834SCristian Dumitrescu 
50072fbdf834SCristian Dumitrescu 					fprintf(f, "label%u %u %u %u ",
50082fbdf834SCristian Dumitrescu 						i,
50092fbdf834SCristian Dumitrescu 						l->label,
50102fbdf834SCristian Dumitrescu 						l->tc,
50112fbdf834SCristian Dumitrescu 						l->ttl);
50122fbdf834SCristian Dumitrescu 				}
50132fbdf834SCristian Dumitrescu 				break;
50142fbdf834SCristian Dumitrescu 
50152fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_PPPOE:
50162fbdf834SCristian Dumitrescu 				fprintf(f, "pppoe ");
50172fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.pppoe.ether.da);
50182fbdf834SCristian Dumitrescu 				fprintf(f, " ");
50192fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.pppoe.ether.sa);
50202fbdf834SCristian Dumitrescu 				fprintf(f, " %u ", a->encap.pppoe.pppoe.session_id);
50212fbdf834SCristian Dumitrescu 				break;
50222fbdf834SCristian Dumitrescu 
50232fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_VXLAN:
50242fbdf834SCristian Dumitrescu 				fprintf(f, "vxlan ether ");
50252fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.vxlan.ether.da);
50262fbdf834SCristian Dumitrescu 				fprintf(f, " ");
50272fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.vxlan.ether.sa);
50282fbdf834SCristian Dumitrescu 				if (table->ap->params.encap.vxlan.vlan)
50292fbdf834SCristian Dumitrescu 					fprintf(f, " vlan pcp %u dei %u vid %u ",
50302fbdf834SCristian Dumitrescu 						a->encap.vxlan.vlan.pcp,
50312fbdf834SCristian Dumitrescu 						a->encap.vxlan.vlan.dei,
50322fbdf834SCristian Dumitrescu 						a->encap.vxlan.vlan.vid);
50332fbdf834SCristian Dumitrescu 				if (table->ap->params.encap.vxlan.ip_version) {
50342fbdf834SCristian Dumitrescu 					fprintf(f, " ipv4 ");
50352fbdf834SCristian Dumitrescu 					ipv4_addr_show(f, a->encap.vxlan.ipv4.sa);
50362fbdf834SCristian Dumitrescu 					fprintf(f, " ");
50372fbdf834SCristian Dumitrescu 					ipv4_addr_show(f, a->encap.vxlan.ipv4.da);
50382fbdf834SCristian Dumitrescu 					fprintf(f, " %u %u ",
50392fbdf834SCristian Dumitrescu 						(uint32_t)a->encap.vxlan.ipv4.dscp,
50402fbdf834SCristian Dumitrescu 						(uint32_t)a->encap.vxlan.ipv4.ttl);
50412fbdf834SCristian Dumitrescu 				} else {
50422fbdf834SCristian Dumitrescu 					fprintf(f, " ipv6 ");
50432fbdf834SCristian Dumitrescu 					ipv6_addr_show(f, a->encap.vxlan.ipv6.sa);
50442fbdf834SCristian Dumitrescu 					fprintf(f, " ");
50452fbdf834SCristian Dumitrescu 					ipv6_addr_show(f, a->encap.vxlan.ipv6.da);
50462fbdf834SCristian Dumitrescu 					fprintf(f, " %u %u %u ",
50472fbdf834SCristian Dumitrescu 						a->encap.vxlan.ipv6.flow_label,
50482fbdf834SCristian Dumitrescu 						(uint32_t)a->encap.vxlan.ipv6.dscp,
50492fbdf834SCristian Dumitrescu 						(uint32_t)a->encap.vxlan.ipv6.hop_limit);
50502fbdf834SCristian Dumitrescu 					fprintf(f, " udp %u %u vxlan %u ",
50512fbdf834SCristian Dumitrescu 						a->encap.vxlan.udp.sp,
50522fbdf834SCristian Dumitrescu 						a->encap.vxlan.udp.dp,
50532fbdf834SCristian Dumitrescu 						a->encap.vxlan.vxlan.vni);
50542fbdf834SCristian Dumitrescu 				}
50552fbdf834SCristian Dumitrescu 				break;
50562fbdf834SCristian Dumitrescu 
50572fbdf834SCristian Dumitrescu 			default:
50582fbdf834SCristian Dumitrescu 				fprintf(f, "unknown ");
50592fbdf834SCristian Dumitrescu 			}
50602fbdf834SCristian Dumitrescu 		}
50612fbdf834SCristian Dumitrescu 
50622fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
50632fbdf834SCristian Dumitrescu 			fprintf(f, "nat %s ", (a->nat.ip_version) ? "ipv4 " : "ipv6 ");
50642fbdf834SCristian Dumitrescu 			if (a->nat.ip_version)
50652fbdf834SCristian Dumitrescu 				ipv4_addr_show(f, a->nat.addr.ipv4);
50662fbdf834SCristian Dumitrescu 			else
50672fbdf834SCristian Dumitrescu 				ipv6_addr_show(f, a->nat.addr.ipv6);
50682fbdf834SCristian Dumitrescu 			fprintf(f, " %u ", (uint32_t)(a->nat.port));
50692fbdf834SCristian Dumitrescu 		}
50702fbdf834SCristian Dumitrescu 
50712fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TTL))
50722fbdf834SCristian Dumitrescu 			fprintf(f, "ttl %s ", (a->ttl.decrement) ? "dec" : "keep");
50732fbdf834SCristian Dumitrescu 
50742fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_STATS))
50752fbdf834SCristian Dumitrescu 			fprintf(f, "stats ");
50762fbdf834SCristian Dumitrescu 
50772fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TIME))
50782fbdf834SCristian Dumitrescu 			fprintf(f, "time ");
50792fbdf834SCristian Dumitrescu 
50802fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO))
50812fbdf834SCristian Dumitrescu 			fprintf(f, "sym_crypto ");
50822fbdf834SCristian Dumitrescu 
50832fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TAG))
50842fbdf834SCristian Dumitrescu 			fprintf(f, "tag %u ", a->tag.tag);
50852fbdf834SCristian Dumitrescu 
50862fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
50872fbdf834SCristian Dumitrescu 			fprintf(f, "decap %u ", a->decap.n);
50882fbdf834SCristian Dumitrescu 
50892fbdf834SCristian Dumitrescu 		/* end */
50902fbdf834SCristian Dumitrescu 		fprintf(f, "\n");
50912fbdf834SCristian Dumitrescu 	}
50922fbdf834SCristian Dumitrescu 
50932fbdf834SCristian Dumitrescu 	/* Write table default rule to file. */
50942fbdf834SCristian Dumitrescu 	if (table->rule_default) {
50952fbdf834SCristian Dumitrescu 		struct table_rule_action *a = &table->rule_default->action;
50962fbdf834SCristian Dumitrescu 
50972fbdf834SCristian Dumitrescu 		fprintf(f, "# match default action fwd ");
50982fbdf834SCristian Dumitrescu 
50992fbdf834SCristian Dumitrescu 		switch (a->fwd.action) {
51002fbdf834SCristian Dumitrescu 		case RTE_PIPELINE_ACTION_DROP:
51012fbdf834SCristian Dumitrescu 			fprintf(f, "drop ");
51022fbdf834SCristian Dumitrescu 			break;
51032fbdf834SCristian Dumitrescu 
51042fbdf834SCristian Dumitrescu 		case RTE_PIPELINE_ACTION_PORT:
51052fbdf834SCristian Dumitrescu 			fprintf(f, "port %u ", a->fwd.id);
51062fbdf834SCristian Dumitrescu 			break;
51072fbdf834SCristian Dumitrescu 
51082fbdf834SCristian Dumitrescu 		case RTE_PIPELINE_ACTION_PORT_META:
51092fbdf834SCristian Dumitrescu 			fprintf(f, "meta ");
51102fbdf834SCristian Dumitrescu 			break;
51112fbdf834SCristian Dumitrescu 
51122fbdf834SCristian Dumitrescu 		case RTE_PIPELINE_ACTION_TABLE:
51132fbdf834SCristian Dumitrescu 		default:
51142fbdf834SCristian Dumitrescu 			fprintf(f, "table %u ", a->fwd.id);
51152fbdf834SCristian Dumitrescu 		}
51162fbdf834SCristian Dumitrescu 	} else
51172fbdf834SCristian Dumitrescu 		fprintf(f, "# match default action fwd drop ");
51182fbdf834SCristian Dumitrescu 
51192fbdf834SCristian Dumitrescu 	fprintf(f, "\n");
51202fbdf834SCristian Dumitrescu 
51212fbdf834SCristian Dumitrescu 	/* Close file. */
51222fbdf834SCristian Dumitrescu 	fclose(f);
51232fbdf834SCristian Dumitrescu 
51242fbdf834SCristian Dumitrescu 	return 0;
51252fbdf834SCristian Dumitrescu }
51262fbdf834SCristian Dumitrescu 
51272fbdf834SCristian Dumitrescu static const char cmd_pipeline_table_rule_show_help[] =
51282fbdf834SCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule show\n"
51292fbdf834SCristian Dumitrescu "     file <file_name>\n";
51302fbdf834SCristian Dumitrescu 
51312fbdf834SCristian Dumitrescu static void
cmd_pipeline_table_rule_show(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)51322fbdf834SCristian Dumitrescu cmd_pipeline_table_rule_show(char **tokens,
51332fbdf834SCristian Dumitrescu 	uint32_t n_tokens,
51342fbdf834SCristian Dumitrescu 	char *out,
51352fbdf834SCristian Dumitrescu 	size_t out_size)
51362fbdf834SCristian Dumitrescu {
51372fbdf834SCristian Dumitrescu 	char *file_name = NULL, *pipeline_name;
51382fbdf834SCristian Dumitrescu 	uint32_t table_id;
51392fbdf834SCristian Dumitrescu 	int status;
51402fbdf834SCristian Dumitrescu 
51412fbdf834SCristian Dumitrescu 	if (n_tokens != 8) {
51422fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
51432fbdf834SCristian Dumitrescu 		return;
51442fbdf834SCristian Dumitrescu 	}
51452fbdf834SCristian Dumitrescu 
51462fbdf834SCristian Dumitrescu 	pipeline_name = tokens[1];
51472fbdf834SCristian Dumitrescu 
51482fbdf834SCristian Dumitrescu 	if (strcmp(tokens[2], "table") != 0) {
51492fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
51502fbdf834SCristian Dumitrescu 		return;
51512fbdf834SCristian Dumitrescu 	}
51522fbdf834SCristian Dumitrescu 
51532fbdf834SCristian Dumitrescu 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
51542fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
51552fbdf834SCristian Dumitrescu 		return;
51562fbdf834SCristian Dumitrescu 	}
51572fbdf834SCristian Dumitrescu 
51582fbdf834SCristian Dumitrescu 	if (strcmp(tokens[4], "rule") != 0) {
51592fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
51602fbdf834SCristian Dumitrescu 		return;
51612fbdf834SCristian Dumitrescu 	}
51622fbdf834SCristian Dumitrescu 
51632fbdf834SCristian Dumitrescu 	if (strcmp(tokens[5], "show") != 0) {
51642fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "show");
51652fbdf834SCristian Dumitrescu 		return;
51662fbdf834SCristian Dumitrescu 	}
51672fbdf834SCristian Dumitrescu 
51682fbdf834SCristian Dumitrescu 	if (strcmp(tokens[6], "file") != 0) {
51692fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "file");
51702fbdf834SCristian Dumitrescu 		return;
51712fbdf834SCristian Dumitrescu 	}
51722fbdf834SCristian Dumitrescu 
51732fbdf834SCristian Dumitrescu 	file_name = tokens[7];
51742fbdf834SCristian Dumitrescu 
51752fbdf834SCristian Dumitrescu 	status = table_rule_show(pipeline_name, table_id, file_name);
51762fbdf834SCristian Dumitrescu 	if (status) {
51772fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
51782fbdf834SCristian Dumitrescu 		return;
51792fbdf834SCristian Dumitrescu 	}
51802fbdf834SCristian Dumitrescu }
518126b3effeSKevin Laatz 
518226b3effeSKevin Laatz static const char cmd_pipeline_table_rule_stats_read_help[] =
518387b36dcdSCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n"
518487b36dcdSCristian Dumitrescu "     match <match>\n";
518526b3effeSKevin Laatz 
5186c64b9121SJasvinder Singh static void
cmd_pipeline_table_rule_stats_read(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)5187c64b9121SJasvinder Singh cmd_pipeline_table_rule_stats_read(char **tokens,
518887b36dcdSCristian Dumitrescu 	uint32_t n_tokens,
5189c64b9121SJasvinder Singh 	char *out,
5190c64b9121SJasvinder Singh 	size_t out_size)
5191c64b9121SJasvinder Singh {
519287b36dcdSCristian Dumitrescu 	struct table_rule_match m;
519387b36dcdSCristian Dumitrescu 	struct rte_table_action_stats_counters stats;
519487b36dcdSCristian Dumitrescu 	char *pipeline_name;
519587b36dcdSCristian Dumitrescu 	uint32_t table_id, n_tokens_parsed;
519687b36dcdSCristian Dumitrescu 	int clear = 0, status;
519787b36dcdSCristian Dumitrescu 
519887b36dcdSCristian Dumitrescu 	if (n_tokens < 7) {
519987b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
520087b36dcdSCristian Dumitrescu 		return;
5201c64b9121SJasvinder Singh 	}
5202c64b9121SJasvinder Singh 
520387b36dcdSCristian Dumitrescu 	pipeline_name = tokens[1];
520487b36dcdSCristian Dumitrescu 
520587b36dcdSCristian Dumitrescu 	if (strcmp(tokens[2], "table") != 0) {
520687b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
520787b36dcdSCristian Dumitrescu 		return;
520887b36dcdSCristian Dumitrescu 	}
520987b36dcdSCristian Dumitrescu 
521087b36dcdSCristian Dumitrescu 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
521187b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
521287b36dcdSCristian Dumitrescu 		return;
521387b36dcdSCristian Dumitrescu 	}
521487b36dcdSCristian Dumitrescu 
521587b36dcdSCristian Dumitrescu 	if (strcmp(tokens[4], "rule") != 0) {
521687b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
521787b36dcdSCristian Dumitrescu 		return;
521887b36dcdSCristian Dumitrescu 	}
521987b36dcdSCristian Dumitrescu 
522087b36dcdSCristian Dumitrescu 	if (strcmp(tokens[5], "read") != 0) {
522187b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
522287b36dcdSCristian Dumitrescu 		return;
522387b36dcdSCristian Dumitrescu 	}
522487b36dcdSCristian Dumitrescu 
522587b36dcdSCristian Dumitrescu 	if (strcmp(tokens[6], "stats") != 0) {
522687b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
522787b36dcdSCristian Dumitrescu 		return;
522887b36dcdSCristian Dumitrescu 	}
522987b36dcdSCristian Dumitrescu 
523087b36dcdSCristian Dumitrescu 	n_tokens -= 7;
523187b36dcdSCristian Dumitrescu 	tokens += 7;
523287b36dcdSCristian Dumitrescu 
523387b36dcdSCristian Dumitrescu 	/* clear */
523487b36dcdSCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
523587b36dcdSCristian Dumitrescu 		clear = 1;
523687b36dcdSCristian Dumitrescu 
523787b36dcdSCristian Dumitrescu 		n_tokens--;
523887b36dcdSCristian Dumitrescu 		tokens++;
523987b36dcdSCristian Dumitrescu 	}
524087b36dcdSCristian Dumitrescu 
524187b36dcdSCristian Dumitrescu 	/* match */
524287b36dcdSCristian Dumitrescu 	if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
524387b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
524487b36dcdSCristian Dumitrescu 		return;
524587b36dcdSCristian Dumitrescu 	}
524687b36dcdSCristian Dumitrescu 
524787b36dcdSCristian Dumitrescu 	n_tokens_parsed = parse_match(tokens,
524887b36dcdSCristian Dumitrescu 		n_tokens,
524987b36dcdSCristian Dumitrescu 		out,
525087b36dcdSCristian Dumitrescu 		out_size,
525187b36dcdSCristian Dumitrescu 		&m);
525287b36dcdSCristian Dumitrescu 	if (n_tokens_parsed == 0)
525387b36dcdSCristian Dumitrescu 		return;
525487b36dcdSCristian Dumitrescu 	n_tokens -= n_tokens_parsed;
525587b36dcdSCristian Dumitrescu 	tokens += n_tokens_parsed;
525687b36dcdSCristian Dumitrescu 
525787b36dcdSCristian Dumitrescu 	/* end */
525887b36dcdSCristian Dumitrescu 	if (n_tokens) {
525987b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
526087b36dcdSCristian Dumitrescu 		return;
526187b36dcdSCristian Dumitrescu 	}
526287b36dcdSCristian Dumitrescu 
526387b36dcdSCristian Dumitrescu 	/* Read table rule stats. */
526487b36dcdSCristian Dumitrescu 	status = pipeline_table_rule_stats_read(pipeline_name,
526587b36dcdSCristian Dumitrescu 		table_id,
526687b36dcdSCristian Dumitrescu 		&m,
526787b36dcdSCristian Dumitrescu 		&stats,
526887b36dcdSCristian Dumitrescu 		clear);
526987b36dcdSCristian Dumitrescu 	if (status) {
527087b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
527187b36dcdSCristian Dumitrescu 		return;
527287b36dcdSCristian Dumitrescu 	}
527387b36dcdSCristian Dumitrescu 
527487b36dcdSCristian Dumitrescu 	/* Print stats. */
527587b36dcdSCristian Dumitrescu 	if (stats.n_packets_valid && stats.n_bytes_valid)
527687b36dcdSCristian Dumitrescu 		snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: %" PRIu64 "\n",
527787b36dcdSCristian Dumitrescu 			stats.n_packets,
527887b36dcdSCristian Dumitrescu 			stats.n_bytes);
527987b36dcdSCristian Dumitrescu 
528087b36dcdSCristian Dumitrescu 	if (stats.n_packets_valid && !stats.n_bytes_valid)
528187b36dcdSCristian Dumitrescu 		snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: N/A\n",
528287b36dcdSCristian Dumitrescu 			stats.n_packets);
528387b36dcdSCristian Dumitrescu 
528487b36dcdSCristian Dumitrescu 	if (!stats.n_packets_valid && stats.n_bytes_valid)
528587b36dcdSCristian Dumitrescu 		snprintf(out, out_size, "Packets: N/A; Bytes: %" PRIu64 "\n",
528687b36dcdSCristian Dumitrescu 			stats.n_bytes);
528787b36dcdSCristian Dumitrescu 
528887b36dcdSCristian Dumitrescu 	if (!stats.n_packets_valid && !stats.n_bytes_valid)
528987b36dcdSCristian Dumitrescu 		snprintf(out, out_size, "Packets: N/A ; Bytes: N/A\n");
529087b36dcdSCristian Dumitrescu }
529126b3effeSKevin Laatz 
529226b3effeSKevin Laatz static const char cmd_pipeline_table_meter_profile_add_help[] =
529326b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
529426b3effeSKevin Laatz "   add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
529526b3effeSKevin Laatz "   | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
529626b3effeSKevin Laatz 
52977e11393eSJasvinder Singh static void
cmd_pipeline_table_meter_profile_add(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)52987e11393eSJasvinder Singh cmd_pipeline_table_meter_profile_add(char **tokens,
52997e11393eSJasvinder Singh 	uint32_t n_tokens,
53007e11393eSJasvinder Singh 	char *out,
53017e11393eSJasvinder Singh 	size_t out_size)
53027e11393eSJasvinder Singh {
53037e11393eSJasvinder Singh 	struct rte_table_action_meter_profile p;
53047e11393eSJasvinder Singh 	char *pipeline_name;
53057e11393eSJasvinder Singh 	uint32_t table_id, meter_profile_id;
53067e11393eSJasvinder Singh 	int status;
53077e11393eSJasvinder Singh 
53087e11393eSJasvinder Singh 	if (n_tokens < 9) {
53097e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
53107e11393eSJasvinder Singh 		return;
53117e11393eSJasvinder Singh 	}
53127e11393eSJasvinder Singh 
53137e11393eSJasvinder Singh 	pipeline_name = tokens[1];
53147e11393eSJasvinder Singh 
53157e11393eSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
53167e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
53177e11393eSJasvinder Singh 		return;
53187e11393eSJasvinder Singh 	}
53197e11393eSJasvinder Singh 
53207e11393eSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
53217e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
53227e11393eSJasvinder Singh 		return;
53237e11393eSJasvinder Singh 	}
53247e11393eSJasvinder Singh 
53257e11393eSJasvinder Singh 	if (strcmp(tokens[4], "meter") != 0) {
53267e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
53277e11393eSJasvinder Singh 		return;
53287e11393eSJasvinder Singh 	}
53297e11393eSJasvinder Singh 
53307e11393eSJasvinder Singh 	if (strcmp(tokens[5], "profile") != 0) {
53317e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
53327e11393eSJasvinder Singh 		return;
53337e11393eSJasvinder Singh 	}
53347e11393eSJasvinder Singh 
53357e11393eSJasvinder Singh 	if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
53367e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
53377e11393eSJasvinder Singh 		return;
53387e11393eSJasvinder Singh 	}
53397e11393eSJasvinder Singh 
53407e11393eSJasvinder Singh 	if (strcmp(tokens[7], "add") != 0) {
53417e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
53427e11393eSJasvinder Singh 		return;
53437e11393eSJasvinder Singh 	}
53447e11393eSJasvinder Singh 
53457e11393eSJasvinder Singh 	if (strcmp(tokens[8], "srtcm") == 0) {
53467e11393eSJasvinder Singh 		if (n_tokens != 15) {
53477e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
53487e11393eSJasvinder Singh 				tokens[0]);
53497e11393eSJasvinder Singh 			return;
53507e11393eSJasvinder Singh 		}
53517e11393eSJasvinder Singh 
53527e11393eSJasvinder Singh 		p.alg = RTE_TABLE_ACTION_METER_SRTCM;
53537e11393eSJasvinder Singh 
53547e11393eSJasvinder Singh 		if (strcmp(tokens[9], "cir") != 0) {
53557e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
53567e11393eSJasvinder Singh 			return;
53577e11393eSJasvinder Singh 		}
53587e11393eSJasvinder Singh 
53597e11393eSJasvinder Singh 		if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
53607e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "cir");
53617e11393eSJasvinder Singh 			return;
53627e11393eSJasvinder Singh 		}
53637e11393eSJasvinder Singh 
53647e11393eSJasvinder Singh 		if (strcmp(tokens[11], "cbs") != 0) {
53657e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
53667e11393eSJasvinder Singh 			return;
53677e11393eSJasvinder Singh 		}
53687e11393eSJasvinder Singh 
53697e11393eSJasvinder Singh 		if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
53707e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
53717e11393eSJasvinder Singh 			return;
53727e11393eSJasvinder Singh 		}
53737e11393eSJasvinder Singh 
53747e11393eSJasvinder Singh 		if (strcmp(tokens[13], "ebs") != 0) {
53757e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
53767e11393eSJasvinder Singh 			return;
53777e11393eSJasvinder Singh 		}
53787e11393eSJasvinder Singh 
53797e11393eSJasvinder Singh 		if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
53807e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
53817e11393eSJasvinder Singh 			return;
53827e11393eSJasvinder Singh 		}
53837e11393eSJasvinder Singh 	} else if (strcmp(tokens[8], "trtcm") == 0) {
53847e11393eSJasvinder Singh 		if (n_tokens != 17) {
53857e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
53867e11393eSJasvinder Singh 			return;
53877e11393eSJasvinder Singh 		}
53887e11393eSJasvinder Singh 
53897e11393eSJasvinder Singh 		p.alg = RTE_TABLE_ACTION_METER_TRTCM;
53907e11393eSJasvinder Singh 
53917e11393eSJasvinder Singh 		if (strcmp(tokens[9], "cir") != 0) {
53927e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
53937e11393eSJasvinder Singh 			return;
53947e11393eSJasvinder Singh 		}
53957e11393eSJasvinder Singh 
53967e11393eSJasvinder Singh 		if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
53977e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "cir");
53987e11393eSJasvinder Singh 			return;
53997e11393eSJasvinder Singh 		}
54007e11393eSJasvinder Singh 
54017e11393eSJasvinder Singh 		if (strcmp(tokens[11], "pir") != 0) {
54027e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
54037e11393eSJasvinder Singh 			return;
54047e11393eSJasvinder Singh 		}
54057e11393eSJasvinder Singh 
54067e11393eSJasvinder Singh 		if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
54077e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "pir");
54087e11393eSJasvinder Singh 			return;
54097e11393eSJasvinder Singh 		}
54107e11393eSJasvinder Singh 		if (strcmp(tokens[13], "cbs") != 0) {
54117e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
54127e11393eSJasvinder Singh 			return;
54137e11393eSJasvinder Singh 		}
54147e11393eSJasvinder Singh 
54157e11393eSJasvinder Singh 		if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
54167e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
54177e11393eSJasvinder Singh 			return;
54187e11393eSJasvinder Singh 		}
54197e11393eSJasvinder Singh 
54207e11393eSJasvinder Singh 		if (strcmp(tokens[15], "pbs") != 0) {
54217e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
54227e11393eSJasvinder Singh 			return;
54237e11393eSJasvinder Singh 		}
54247e11393eSJasvinder Singh 
54257e11393eSJasvinder Singh 		if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
54267e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
54277e11393eSJasvinder Singh 			return;
54287e11393eSJasvinder Singh 		}
54297e11393eSJasvinder Singh 	} else {
54307e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
54317e11393eSJasvinder Singh 		return;
54327e11393eSJasvinder Singh 	}
54337e11393eSJasvinder Singh 
54347e11393eSJasvinder Singh 	status = pipeline_table_mtr_profile_add(pipeline_name,
54357e11393eSJasvinder Singh 		table_id,
54367e11393eSJasvinder Singh 		meter_profile_id,
54377e11393eSJasvinder Singh 		&p);
54387e11393eSJasvinder Singh 	if (status) {
54397e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
54407e11393eSJasvinder Singh 		return;
54417e11393eSJasvinder Singh 	}
54427e11393eSJasvinder Singh }
54437e11393eSJasvinder Singh 
544426b3effeSKevin Laatz 
544526b3effeSKevin Laatz static const char cmd_pipeline_table_meter_profile_delete_help[] =
544626b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id>\n"
544726b3effeSKevin Laatz "   meter profile <meter_profile_id> delete\n";
544826b3effeSKevin Laatz 
54497e11393eSJasvinder Singh static void
cmd_pipeline_table_meter_profile_delete(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)54507e11393eSJasvinder Singh cmd_pipeline_table_meter_profile_delete(char **tokens,
54517e11393eSJasvinder Singh 	uint32_t n_tokens,
54527e11393eSJasvinder Singh 	char *out,
54537e11393eSJasvinder Singh 	size_t out_size)
54547e11393eSJasvinder Singh {
54557e11393eSJasvinder Singh 	char *pipeline_name;
54567e11393eSJasvinder Singh 	uint32_t table_id, meter_profile_id;
54577e11393eSJasvinder Singh 	int status;
54587e11393eSJasvinder Singh 
54597e11393eSJasvinder Singh 	if (n_tokens != 8) {
54607e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
54617e11393eSJasvinder Singh 		return;
54627e11393eSJasvinder Singh 	}
54637e11393eSJasvinder Singh 
54647e11393eSJasvinder Singh 	pipeline_name = tokens[1];
54657e11393eSJasvinder Singh 
54667e11393eSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
54677e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
54687e11393eSJasvinder Singh 		return;
54697e11393eSJasvinder Singh 	}
54707e11393eSJasvinder Singh 
54717e11393eSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
54727e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
54737e11393eSJasvinder Singh 		return;
54747e11393eSJasvinder Singh 	}
54757e11393eSJasvinder Singh 
54767e11393eSJasvinder Singh 	if (strcmp(tokens[4], "meter") != 0) {
54777e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
54787e11393eSJasvinder Singh 		return;
54797e11393eSJasvinder Singh 	}
54807e11393eSJasvinder Singh 
54817e11393eSJasvinder Singh 	if (strcmp(tokens[5], "profile") != 0) {
54827e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
54837e11393eSJasvinder Singh 		return;
54847e11393eSJasvinder Singh 	}
54857e11393eSJasvinder Singh 
54867e11393eSJasvinder Singh 	if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
54877e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
54887e11393eSJasvinder Singh 		return;
54897e11393eSJasvinder Singh 	}
54907e11393eSJasvinder Singh 
54917e11393eSJasvinder Singh 	if (strcmp(tokens[7], "delete") != 0) {
54927e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
54937e11393eSJasvinder Singh 		return;
54947e11393eSJasvinder Singh 	}
54957e11393eSJasvinder Singh 
54967e11393eSJasvinder Singh 	status = pipeline_table_mtr_profile_delete(pipeline_name,
54977e11393eSJasvinder Singh 		table_id,
54987e11393eSJasvinder Singh 		meter_profile_id);
54997e11393eSJasvinder Singh 	if (status) {
55007e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
55017e11393eSJasvinder Singh 		return;
55027e11393eSJasvinder Singh 	}
55037e11393eSJasvinder Singh }
55047e11393eSJasvinder Singh 
550526b3effeSKevin Laatz 
550626b3effeSKevin Laatz static const char cmd_pipeline_table_rule_meter_read_help[] =
55078c6dc647SCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n"
55088c6dc647SCristian Dumitrescu "     match <match>\n";
550926b3effeSKevin Laatz 
5510e92058d6SJasvinder Singh static void
cmd_pipeline_table_rule_meter_read(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)5511e92058d6SJasvinder Singh cmd_pipeline_table_rule_meter_read(char **tokens,
55128c6dc647SCristian Dumitrescu 	uint32_t n_tokens,
5513e92058d6SJasvinder Singh 	char *out,
5514e92058d6SJasvinder Singh 	size_t out_size)
5515e92058d6SJasvinder Singh {
55168c6dc647SCristian Dumitrescu 	struct table_rule_match m;
55178c6dc647SCristian Dumitrescu 	struct rte_table_action_mtr_counters stats;
55188c6dc647SCristian Dumitrescu 	char *pipeline_name;
55198c6dc647SCristian Dumitrescu 	uint32_t table_id, n_tokens_parsed;
55208c6dc647SCristian Dumitrescu 	int clear = 0, status;
55218c6dc647SCristian Dumitrescu 
55228c6dc647SCristian Dumitrescu 	if (n_tokens < 7) {
55238c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
55248c6dc647SCristian Dumitrescu 		return;
55258c6dc647SCristian Dumitrescu 	}
55268c6dc647SCristian Dumitrescu 
55278c6dc647SCristian Dumitrescu 	pipeline_name = tokens[1];
55288c6dc647SCristian Dumitrescu 
55298c6dc647SCristian Dumitrescu 	if (strcmp(tokens[2], "table") != 0) {
55308c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
55318c6dc647SCristian Dumitrescu 		return;
55328c6dc647SCristian Dumitrescu 	}
55338c6dc647SCristian Dumitrescu 
55348c6dc647SCristian Dumitrescu 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
55358c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
55368c6dc647SCristian Dumitrescu 		return;
55378c6dc647SCristian Dumitrescu 	}
55388c6dc647SCristian Dumitrescu 
55398c6dc647SCristian Dumitrescu 	if (strcmp(tokens[4], "rule") != 0) {
55408c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
55418c6dc647SCristian Dumitrescu 		return;
55428c6dc647SCristian Dumitrescu 	}
55438c6dc647SCristian Dumitrescu 
55448c6dc647SCristian Dumitrescu 	if (strcmp(tokens[5], "read") != 0) {
55458c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
55468c6dc647SCristian Dumitrescu 		return;
55478c6dc647SCristian Dumitrescu 	}
55488c6dc647SCristian Dumitrescu 
55498c6dc647SCristian Dumitrescu 	if (strcmp(tokens[6], "meter") != 0) {
55508c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
55518c6dc647SCristian Dumitrescu 		return;
55528c6dc647SCristian Dumitrescu 	}
55538c6dc647SCristian Dumitrescu 
55548c6dc647SCristian Dumitrescu 	n_tokens -= 7;
55558c6dc647SCristian Dumitrescu 	tokens += 7;
55568c6dc647SCristian Dumitrescu 
55578c6dc647SCristian Dumitrescu 	/* clear */
55588c6dc647SCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
55598c6dc647SCristian Dumitrescu 		clear = 1;
55608c6dc647SCristian Dumitrescu 
55618c6dc647SCristian Dumitrescu 		n_tokens--;
55628c6dc647SCristian Dumitrescu 		tokens++;
55638c6dc647SCristian Dumitrescu 	}
55648c6dc647SCristian Dumitrescu 
55658c6dc647SCristian Dumitrescu 	/* match */
55668c6dc647SCristian Dumitrescu 	if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
55678c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
55688c6dc647SCristian Dumitrescu 		return;
55698c6dc647SCristian Dumitrescu 	}
55708c6dc647SCristian Dumitrescu 
55718c6dc647SCristian Dumitrescu 	n_tokens_parsed = parse_match(tokens,
55728c6dc647SCristian Dumitrescu 		n_tokens,
55738c6dc647SCristian Dumitrescu 		out,
55748c6dc647SCristian Dumitrescu 		out_size,
55758c6dc647SCristian Dumitrescu 		&m);
55768c6dc647SCristian Dumitrescu 	if (n_tokens_parsed == 0)
55778c6dc647SCristian Dumitrescu 		return;
55788c6dc647SCristian Dumitrescu 	n_tokens -= n_tokens_parsed;
55798c6dc647SCristian Dumitrescu 	tokens += n_tokens_parsed;
55808c6dc647SCristian Dumitrescu 
55818c6dc647SCristian Dumitrescu 	/* end */
55828c6dc647SCristian Dumitrescu 	if (n_tokens) {
55838c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
55848c6dc647SCristian Dumitrescu 		return;
55858c6dc647SCristian Dumitrescu 	}
55868c6dc647SCristian Dumitrescu 
55878c6dc647SCristian Dumitrescu 	/* Read table rule meter stats. */
55888c6dc647SCristian Dumitrescu 	status = pipeline_table_rule_mtr_read(pipeline_name,
55898c6dc647SCristian Dumitrescu 		table_id,
55908c6dc647SCristian Dumitrescu 		&m,
55918c6dc647SCristian Dumitrescu 		&stats,
55928c6dc647SCristian Dumitrescu 		clear);
55938c6dc647SCristian Dumitrescu 	if (status) {
55948c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
55958c6dc647SCristian Dumitrescu 		return;
55968c6dc647SCristian Dumitrescu 	}
55978c6dc647SCristian Dumitrescu 
55988c6dc647SCristian Dumitrescu 	/* Print stats. */
5599e92058d6SJasvinder Singh }
5600e92058d6SJasvinder Singh 
560126b3effeSKevin Laatz 
560226b3effeSKevin Laatz static const char cmd_pipeline_table_dscp_help[] =
560326b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
560426b3effeSKevin Laatz "\n"
560526b3effeSKevin Laatz " File <file_name>:\n"
560626b3effeSKevin Laatz "   - exactly 64 lines\n"
560726b3effeSKevin Laatz "   - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
560826b3effeSKevin Laatz 
56092b82ef48SJasvinder Singh static int
load_dscp_table(struct rte_table_action_dscp_table * dscp_table,const char * file_name,uint32_t * line_number)56102b82ef48SJasvinder Singh load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
56112b82ef48SJasvinder Singh 	const char *file_name,
56122b82ef48SJasvinder Singh 	uint32_t *line_number)
56132b82ef48SJasvinder Singh {
56142b82ef48SJasvinder Singh 	FILE *f = NULL;
56152b82ef48SJasvinder Singh 	uint32_t dscp, l;
56162b82ef48SJasvinder Singh 
56172b82ef48SJasvinder Singh 	/* Check input arguments */
56182b82ef48SJasvinder Singh 	if ((dscp_table == NULL) ||
56192b82ef48SJasvinder Singh 		(file_name == NULL) ||
56202b82ef48SJasvinder Singh 		(line_number == NULL)) {
56212b82ef48SJasvinder Singh 		if (line_number)
56222b82ef48SJasvinder Singh 			*line_number = 0;
56232b82ef48SJasvinder Singh 		return -EINVAL;
56242b82ef48SJasvinder Singh 	}
56252b82ef48SJasvinder Singh 
56262b82ef48SJasvinder Singh 	/* Open input file */
56272b82ef48SJasvinder Singh 	f = fopen(file_name, "r");
56282b82ef48SJasvinder Singh 	if (f == NULL) {
56292b82ef48SJasvinder Singh 		*line_number = 0;
56302b82ef48SJasvinder Singh 		return -EINVAL;
56312b82ef48SJasvinder Singh 	}
56322b82ef48SJasvinder Singh 
56332b82ef48SJasvinder Singh 	/* Read file */
56342b82ef48SJasvinder Singh 	for (dscp = 0, l = 1; ; l++) {
56352b82ef48SJasvinder Singh 		char line[64];
56362b82ef48SJasvinder Singh 		char *tokens[3];
5637c1656328SJasvinder Singh 		enum rte_color color;
56382b82ef48SJasvinder Singh 		uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
56392b82ef48SJasvinder Singh 
56402b82ef48SJasvinder Singh 		if (fgets(line, sizeof(line), f) == NULL)
56412b82ef48SJasvinder Singh 			break;
56422b82ef48SJasvinder Singh 
56432b82ef48SJasvinder Singh 		if (is_comment(line))
56442b82ef48SJasvinder Singh 			continue;
56452b82ef48SJasvinder Singh 
56462b82ef48SJasvinder Singh 		if (parse_tokenize_string(line, tokens, &n_tokens)) {
56472b82ef48SJasvinder Singh 			*line_number = l;
56489b607951SJasvinder Singh 			fclose(f);
56492b82ef48SJasvinder Singh 			return -EINVAL;
56502b82ef48SJasvinder Singh 		}
56512b82ef48SJasvinder Singh 
56522b82ef48SJasvinder Singh 		if (n_tokens == 0)
56532b82ef48SJasvinder Singh 			continue;
56542b82ef48SJasvinder Singh 
56552b82ef48SJasvinder Singh 		if ((dscp >= RTE_DIM(dscp_table->entry)) ||
56562b82ef48SJasvinder Singh 			(n_tokens != RTE_DIM(tokens)) ||
56572b82ef48SJasvinder Singh 			parser_read_uint32(&tc_id, tokens[0]) ||
56582b82ef48SJasvinder Singh 			(tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
56592b82ef48SJasvinder Singh 			parser_read_uint32(&tc_queue_id, tokens[1]) ||
56602b82ef48SJasvinder Singh 			(tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
56612b82ef48SJasvinder Singh 			(strlen(tokens[2]) != 1)) {
56622b82ef48SJasvinder Singh 			*line_number = l;
56639b607951SJasvinder Singh 			fclose(f);
56642b82ef48SJasvinder Singh 			return -EINVAL;
56652b82ef48SJasvinder Singh 		}
56662b82ef48SJasvinder Singh 
56672b82ef48SJasvinder Singh 		switch (tokens[2][0]) {
56682b82ef48SJasvinder Singh 		case 'g':
56692b82ef48SJasvinder Singh 		case 'G':
5670c1656328SJasvinder Singh 			color = RTE_COLOR_GREEN;
56712b82ef48SJasvinder Singh 			break;
56722b82ef48SJasvinder Singh 
56732b82ef48SJasvinder Singh 		case 'y':
56742b82ef48SJasvinder Singh 		case 'Y':
5675c1656328SJasvinder Singh 			color = RTE_COLOR_YELLOW;
56762b82ef48SJasvinder Singh 			break;
56772b82ef48SJasvinder Singh 
56782b82ef48SJasvinder Singh 		case 'r':
56792b82ef48SJasvinder Singh 		case 'R':
5680c1656328SJasvinder Singh 			color = RTE_COLOR_RED;
56812b82ef48SJasvinder Singh 			break;
56822b82ef48SJasvinder Singh 
56832b82ef48SJasvinder Singh 		default:
56842b82ef48SJasvinder Singh 			*line_number = l;
56859b607951SJasvinder Singh 			fclose(f);
56862b82ef48SJasvinder Singh 			return -EINVAL;
56872b82ef48SJasvinder Singh 		}
56882b82ef48SJasvinder Singh 
56892b82ef48SJasvinder Singh 		dscp_table->entry[dscp].tc_id = tc_id;
56902b82ef48SJasvinder Singh 		dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
56912b82ef48SJasvinder Singh 		dscp_table->entry[dscp].color = color;
56922b82ef48SJasvinder Singh 		dscp++;
56932b82ef48SJasvinder Singh 	}
56942b82ef48SJasvinder Singh 
56952b82ef48SJasvinder Singh 	/* Close file */
56962b82ef48SJasvinder Singh 	fclose(f);
56972b82ef48SJasvinder Singh 	return 0;
56982b82ef48SJasvinder Singh }
56992b82ef48SJasvinder Singh 
57002b82ef48SJasvinder Singh static void
cmd_pipeline_table_dscp(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)57012b82ef48SJasvinder Singh cmd_pipeline_table_dscp(char **tokens,
57022b82ef48SJasvinder Singh 	uint32_t n_tokens,
57032b82ef48SJasvinder Singh 	char *out,
57042b82ef48SJasvinder Singh 	size_t out_size)
57052b82ef48SJasvinder Singh {
57062b82ef48SJasvinder Singh 	struct rte_table_action_dscp_table dscp_table;
57072b82ef48SJasvinder Singh 	char *pipeline_name, *file_name;
57082b82ef48SJasvinder Singh 	uint32_t table_id, line_number;
57092b82ef48SJasvinder Singh 	int status;
57102b82ef48SJasvinder Singh 
57112b82ef48SJasvinder Singh 	if (n_tokens != 6) {
57122b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
57132b82ef48SJasvinder Singh 		return;
57142b82ef48SJasvinder Singh 	}
57152b82ef48SJasvinder Singh 
57162b82ef48SJasvinder Singh 	pipeline_name = tokens[1];
57172b82ef48SJasvinder Singh 
57182b82ef48SJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
57192b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
57202b82ef48SJasvinder Singh 		return;
57212b82ef48SJasvinder Singh 	}
57222b82ef48SJasvinder Singh 
57232b82ef48SJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
57242b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
57252b82ef48SJasvinder Singh 		return;
57262b82ef48SJasvinder Singh 	}
57272b82ef48SJasvinder Singh 
57282b82ef48SJasvinder Singh 	if (strcmp(tokens[4], "dscp") != 0) {
57292b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
57302b82ef48SJasvinder Singh 		return;
57312b82ef48SJasvinder Singh 	}
57322b82ef48SJasvinder Singh 
57332b82ef48SJasvinder Singh 	file_name = tokens[5];
57342b82ef48SJasvinder Singh 
57352b82ef48SJasvinder Singh 	status = load_dscp_table(&dscp_table, file_name, &line_number);
57362b82ef48SJasvinder Singh 	if (status) {
57372b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
57382b82ef48SJasvinder Singh 		return;
57392b82ef48SJasvinder Singh 	}
57402b82ef48SJasvinder Singh 
57412b82ef48SJasvinder Singh 	status = pipeline_table_dscp_table_update(pipeline_name,
57422b82ef48SJasvinder Singh 		table_id,
57432b82ef48SJasvinder Singh 		UINT64_MAX,
57442b82ef48SJasvinder Singh 		&dscp_table);
57452b82ef48SJasvinder Singh 	if (status) {
57462b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
57472b82ef48SJasvinder Singh 		return;
57482b82ef48SJasvinder Singh 	}
57492b82ef48SJasvinder Singh }
57502b82ef48SJasvinder Singh 
575126b3effeSKevin Laatz 
575226b3effeSKevin Laatz static const char cmd_pipeline_table_rule_ttl_read_help[] =
57538bfe22acSCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n"
57548bfe22acSCristian Dumitrescu "     match <match>\n";
575526b3effeSKevin Laatz 
5756d0d306c7SJasvinder Singh static void
cmd_pipeline_table_rule_ttl_read(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)5757d0d306c7SJasvinder Singh cmd_pipeline_table_rule_ttl_read(char **tokens,
57588bfe22acSCristian Dumitrescu 	uint32_t n_tokens,
5759d0d306c7SJasvinder Singh 	char *out,
5760d0d306c7SJasvinder Singh 	size_t out_size)
5761d0d306c7SJasvinder Singh {
57628bfe22acSCristian Dumitrescu 	struct table_rule_match m;
57638bfe22acSCristian Dumitrescu 	struct rte_table_action_ttl_counters stats;
57648bfe22acSCristian Dumitrescu 	char *pipeline_name;
57658bfe22acSCristian Dumitrescu 	uint32_t table_id, n_tokens_parsed;
57668bfe22acSCristian Dumitrescu 	int clear = 0, status;
57678bfe22acSCristian Dumitrescu 
57688bfe22acSCristian Dumitrescu 	if (n_tokens < 7) {
57698bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
57708bfe22acSCristian Dumitrescu 		return;
57718bfe22acSCristian Dumitrescu 	}
57728bfe22acSCristian Dumitrescu 
57738bfe22acSCristian Dumitrescu 	pipeline_name = tokens[1];
57748bfe22acSCristian Dumitrescu 
57758bfe22acSCristian Dumitrescu 	if (strcmp(tokens[2], "table") != 0) {
57768bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
57778bfe22acSCristian Dumitrescu 		return;
57788bfe22acSCristian Dumitrescu 	}
57798bfe22acSCristian Dumitrescu 
57808bfe22acSCristian Dumitrescu 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
57818bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
57828bfe22acSCristian Dumitrescu 		return;
57838bfe22acSCristian Dumitrescu 	}
57848bfe22acSCristian Dumitrescu 
57858bfe22acSCristian Dumitrescu 	if (strcmp(tokens[4], "rule") != 0) {
57868bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
57878bfe22acSCristian Dumitrescu 		return;
57888bfe22acSCristian Dumitrescu 	}
57898bfe22acSCristian Dumitrescu 
57908bfe22acSCristian Dumitrescu 	if (strcmp(tokens[5], "read") != 0) {
57918bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
57928bfe22acSCristian Dumitrescu 		return;
57938bfe22acSCristian Dumitrescu 	}
57948bfe22acSCristian Dumitrescu 
57958bfe22acSCristian Dumitrescu 	if (strcmp(tokens[6], "ttl") != 0) {
57968bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ttl");
57978bfe22acSCristian Dumitrescu 		return;
57988bfe22acSCristian Dumitrescu 	}
57998bfe22acSCristian Dumitrescu 
58008bfe22acSCristian Dumitrescu 	n_tokens -= 7;
58018bfe22acSCristian Dumitrescu 	tokens += 7;
58028bfe22acSCristian Dumitrescu 
58038bfe22acSCristian Dumitrescu 	/* clear */
58048bfe22acSCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
58058bfe22acSCristian Dumitrescu 		clear = 1;
58068bfe22acSCristian Dumitrescu 
58078bfe22acSCristian Dumitrescu 		n_tokens--;
58088bfe22acSCristian Dumitrescu 		tokens++;
58098bfe22acSCristian Dumitrescu 	}
58108bfe22acSCristian Dumitrescu 
58118bfe22acSCristian Dumitrescu 	/* match */
58128bfe22acSCristian Dumitrescu 	if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
58138bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
58148bfe22acSCristian Dumitrescu 		return;
58158bfe22acSCristian Dumitrescu 	}
58168bfe22acSCristian Dumitrescu 
58178bfe22acSCristian Dumitrescu 	n_tokens_parsed = parse_match(tokens,
58188bfe22acSCristian Dumitrescu 		n_tokens,
58198bfe22acSCristian Dumitrescu 		out,
58208bfe22acSCristian Dumitrescu 		out_size,
58218bfe22acSCristian Dumitrescu 		&m);
58228bfe22acSCristian Dumitrescu 	if (n_tokens_parsed == 0)
58238bfe22acSCristian Dumitrescu 		return;
58248bfe22acSCristian Dumitrescu 	n_tokens -= n_tokens_parsed;
58258bfe22acSCristian Dumitrescu 	tokens += n_tokens_parsed;
58268bfe22acSCristian Dumitrescu 
58278bfe22acSCristian Dumitrescu 	/* end */
58288bfe22acSCristian Dumitrescu 	if (n_tokens) {
58298bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
58308bfe22acSCristian Dumitrescu 		return;
58318bfe22acSCristian Dumitrescu 	}
58328bfe22acSCristian Dumitrescu 
58338bfe22acSCristian Dumitrescu 	/* Read table rule TTL stats. */
58348bfe22acSCristian Dumitrescu 	status = pipeline_table_rule_ttl_read(pipeline_name,
58358bfe22acSCristian Dumitrescu 		table_id,
58368bfe22acSCristian Dumitrescu 		&m,
58378bfe22acSCristian Dumitrescu 		&stats,
58388bfe22acSCristian Dumitrescu 		clear);
58398bfe22acSCristian Dumitrescu 	if (status) {
58408bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
58418bfe22acSCristian Dumitrescu 		return;
58428bfe22acSCristian Dumitrescu 	}
58438bfe22acSCristian Dumitrescu 
58448bfe22acSCristian Dumitrescu 	/* Print stats. */
58458bfe22acSCristian Dumitrescu 	snprintf(out, out_size, "Packets: %" PRIu64 "\n",
58468bfe22acSCristian Dumitrescu 		stats.n_packets);
5847d0d306c7SJasvinder Singh }
5848d0d306c7SJasvinder Singh 
5849a3169ee5SCristian Dumitrescu static const char cmd_pipeline_table_rule_time_read_help[] =
5850a3169ee5SCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule read time\n"
5851a3169ee5SCristian Dumitrescu "     match <match>\n";
5852a3169ee5SCristian Dumitrescu 
5853a3169ee5SCristian Dumitrescu static void
cmd_pipeline_table_rule_time_read(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)5854a3169ee5SCristian Dumitrescu cmd_pipeline_table_rule_time_read(char **tokens,
5855a3169ee5SCristian Dumitrescu 	uint32_t n_tokens,
5856a3169ee5SCristian Dumitrescu 	char *out,
5857a3169ee5SCristian Dumitrescu 	size_t out_size)
5858a3169ee5SCristian Dumitrescu {
5859a3169ee5SCristian Dumitrescu 	struct table_rule_match m;
5860a3169ee5SCristian Dumitrescu 	char *pipeline_name;
5861a3169ee5SCristian Dumitrescu 	uint64_t timestamp;
5862a3169ee5SCristian Dumitrescu 	uint32_t table_id, n_tokens_parsed;
5863a3169ee5SCristian Dumitrescu 	int status;
5864a3169ee5SCristian Dumitrescu 
5865a3169ee5SCristian Dumitrescu 	if (n_tokens < 7) {
5866a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5867a3169ee5SCristian Dumitrescu 		return;
5868a3169ee5SCristian Dumitrescu 	}
5869a3169ee5SCristian Dumitrescu 
5870a3169ee5SCristian Dumitrescu 	pipeline_name = tokens[1];
5871a3169ee5SCristian Dumitrescu 
5872a3169ee5SCristian Dumitrescu 	if (strcmp(tokens[2], "table") != 0) {
5873a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5874a3169ee5SCristian Dumitrescu 		return;
5875a3169ee5SCristian Dumitrescu 	}
5876a3169ee5SCristian Dumitrescu 
5877a3169ee5SCristian Dumitrescu 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5878a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5879a3169ee5SCristian Dumitrescu 		return;
5880a3169ee5SCristian Dumitrescu 	}
5881a3169ee5SCristian Dumitrescu 
5882a3169ee5SCristian Dumitrescu 	if (strcmp(tokens[4], "rule") != 0) {
5883a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5884a3169ee5SCristian Dumitrescu 		return;
5885a3169ee5SCristian Dumitrescu 	}
5886a3169ee5SCristian Dumitrescu 
5887a3169ee5SCristian Dumitrescu 	if (strcmp(tokens[5], "read") != 0) {
5888a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5889a3169ee5SCristian Dumitrescu 		return;
5890a3169ee5SCristian Dumitrescu 	}
5891a3169ee5SCristian Dumitrescu 
5892a3169ee5SCristian Dumitrescu 	if (strcmp(tokens[6], "time") != 0) {
5893a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "time");
5894a3169ee5SCristian Dumitrescu 		return;
5895a3169ee5SCristian Dumitrescu 	}
5896a3169ee5SCristian Dumitrescu 
5897a3169ee5SCristian Dumitrescu 	n_tokens -= 7;
5898a3169ee5SCristian Dumitrescu 	tokens += 7;
5899a3169ee5SCristian Dumitrescu 
5900a3169ee5SCristian Dumitrescu 	/* match */
5901a3169ee5SCristian Dumitrescu 	if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5902a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5903a3169ee5SCristian Dumitrescu 		return;
5904a3169ee5SCristian Dumitrescu 	}
5905a3169ee5SCristian Dumitrescu 
5906a3169ee5SCristian Dumitrescu 	n_tokens_parsed = parse_match(tokens,
5907a3169ee5SCristian Dumitrescu 		n_tokens,
5908a3169ee5SCristian Dumitrescu 		out,
5909a3169ee5SCristian Dumitrescu 		out_size,
5910a3169ee5SCristian Dumitrescu 		&m);
5911a3169ee5SCristian Dumitrescu 	if (n_tokens_parsed == 0)
5912a3169ee5SCristian Dumitrescu 		return;
5913a3169ee5SCristian Dumitrescu 	n_tokens -= n_tokens_parsed;
5914a3169ee5SCristian Dumitrescu 	tokens += n_tokens_parsed;
5915a3169ee5SCristian Dumitrescu 
5916a3169ee5SCristian Dumitrescu 	/* end */
5917a3169ee5SCristian Dumitrescu 	if (n_tokens) {
5918a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5919a3169ee5SCristian Dumitrescu 		return;
5920a3169ee5SCristian Dumitrescu 	}
5921a3169ee5SCristian Dumitrescu 
5922a3169ee5SCristian Dumitrescu 	/* Read table rule timestamp. */
5923a3169ee5SCristian Dumitrescu 	status = pipeline_table_rule_time_read(pipeline_name,
5924a3169ee5SCristian Dumitrescu 		table_id,
5925a3169ee5SCristian Dumitrescu 		&m,
5926a3169ee5SCristian Dumitrescu 		&timestamp);
5927a3169ee5SCristian Dumitrescu 	if (status) {
5928a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5929a3169ee5SCristian Dumitrescu 		return;
5930a3169ee5SCristian Dumitrescu 	}
5931a3169ee5SCristian Dumitrescu 
5932a3169ee5SCristian Dumitrescu 	/* Print stats. */
5933a3169ee5SCristian Dumitrescu 	snprintf(out, out_size, "Packets: %" PRIu64 "\n", timestamp);
5934a3169ee5SCristian Dumitrescu }
593526b3effeSKevin Laatz 
593626b3effeSKevin Laatz static const char cmd_thread_pipeline_enable_help[] =
593726b3effeSKevin Laatz "thread <thread_id> pipeline <pipeline_name> enable\n";
593826b3effeSKevin Laatz 
593932e5d9b1SJasvinder Singh static void
cmd_thread_pipeline_enable(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)594032e5d9b1SJasvinder Singh cmd_thread_pipeline_enable(char **tokens,
594132e5d9b1SJasvinder Singh 	uint32_t n_tokens,
594232e5d9b1SJasvinder Singh 	char *out,
594332e5d9b1SJasvinder Singh 	size_t out_size)
594432e5d9b1SJasvinder Singh {
594532e5d9b1SJasvinder Singh 	char *pipeline_name;
594632e5d9b1SJasvinder Singh 	uint32_t thread_id;
594732e5d9b1SJasvinder Singh 	int status;
594832e5d9b1SJasvinder Singh 
594932e5d9b1SJasvinder Singh 	if (n_tokens != 5) {
595032e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
595132e5d9b1SJasvinder Singh 		return;
595232e5d9b1SJasvinder Singh 	}
595332e5d9b1SJasvinder Singh 
595432e5d9b1SJasvinder Singh 	if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
595532e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
595632e5d9b1SJasvinder Singh 		return;
595732e5d9b1SJasvinder Singh 	}
595832e5d9b1SJasvinder Singh 
595932e5d9b1SJasvinder Singh 	if (strcmp(tokens[2], "pipeline") != 0) {
596032e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
596132e5d9b1SJasvinder Singh 		return;
596232e5d9b1SJasvinder Singh 	}
596332e5d9b1SJasvinder Singh 
596432e5d9b1SJasvinder Singh 	pipeline_name = tokens[3];
596532e5d9b1SJasvinder Singh 
596632e5d9b1SJasvinder Singh 	if (strcmp(tokens[4], "enable") != 0) {
596732e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
596832e5d9b1SJasvinder Singh 		return;
596932e5d9b1SJasvinder Singh 	}
597032e5d9b1SJasvinder Singh 
597132e5d9b1SJasvinder Singh 	status = thread_pipeline_enable(thread_id, pipeline_name);
597232e5d9b1SJasvinder Singh 	if (status) {
597332e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
597432e5d9b1SJasvinder Singh 		return;
597532e5d9b1SJasvinder Singh 	}
597632e5d9b1SJasvinder Singh }
597732e5d9b1SJasvinder Singh 
597826b3effeSKevin Laatz 
597926b3effeSKevin Laatz static const char cmd_thread_pipeline_disable_help[] =
598026b3effeSKevin Laatz "thread <thread_id> pipeline <pipeline_name> disable\n";
598126b3effeSKevin Laatz 
598232e5d9b1SJasvinder Singh static void
cmd_thread_pipeline_disable(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)598332e5d9b1SJasvinder Singh cmd_thread_pipeline_disable(char **tokens,
598432e5d9b1SJasvinder Singh 	uint32_t n_tokens,
598532e5d9b1SJasvinder Singh 	char *out,
598632e5d9b1SJasvinder Singh 	size_t out_size)
598732e5d9b1SJasvinder Singh {
598832e5d9b1SJasvinder Singh 	char *pipeline_name;
598932e5d9b1SJasvinder Singh 	uint32_t thread_id;
599032e5d9b1SJasvinder Singh 	int status;
599132e5d9b1SJasvinder Singh 
599232e5d9b1SJasvinder Singh 	if (n_tokens != 5) {
599332e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
599432e5d9b1SJasvinder Singh 		return;
599532e5d9b1SJasvinder Singh 	}
599632e5d9b1SJasvinder Singh 
599732e5d9b1SJasvinder Singh 	if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
599832e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
599932e5d9b1SJasvinder Singh 		return;
600032e5d9b1SJasvinder Singh 	}
600132e5d9b1SJasvinder Singh 
600232e5d9b1SJasvinder Singh 	if (strcmp(tokens[2], "pipeline") != 0) {
600332e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
600432e5d9b1SJasvinder Singh 		return;
600532e5d9b1SJasvinder Singh 	}
600632e5d9b1SJasvinder Singh 
600732e5d9b1SJasvinder Singh 	pipeline_name = tokens[3];
600832e5d9b1SJasvinder Singh 
600932e5d9b1SJasvinder Singh 	if (strcmp(tokens[4], "disable") != 0) {
601032e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
601132e5d9b1SJasvinder Singh 		return;
601232e5d9b1SJasvinder Singh 	}
601332e5d9b1SJasvinder Singh 
601432e5d9b1SJasvinder Singh 	status = thread_pipeline_disable(thread_id, pipeline_name);
601532e5d9b1SJasvinder Singh 	if (status) {
601632e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL,
601732e5d9b1SJasvinder Singh 			"thread pipeline disable");
601832e5d9b1SJasvinder Singh 		return;
601932e5d9b1SJasvinder Singh 	}
602032e5d9b1SJasvinder Singh }
602132e5d9b1SJasvinder Singh 
602226b3effeSKevin Laatz static void
cmd_help(char ** tokens,uint32_t n_tokens,char * out,size_t out_size)602326b3effeSKevin Laatz cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
602426b3effeSKevin Laatz {
602526b3effeSKevin Laatz 	tokens++;
602626b3effeSKevin Laatz 	n_tokens--;
602726b3effeSKevin Laatz 
602826b3effeSKevin Laatz 	if (n_tokens == 0) {
602926b3effeSKevin Laatz 		snprintf(out, out_size,
603026b3effeSKevin Laatz 			"Type 'help <command>' for details on each command.\n\n"
603126b3effeSKevin Laatz 			"List of commands:\n"
603226b3effeSKevin Laatz 			"\tmempool\n"
603326b3effeSKevin Laatz 			"\tlink\n"
603426b3effeSKevin Laatz 			"\tswq\n"
603526b3effeSKevin Laatz 			"\ttmgr subport profile\n"
603626b3effeSKevin Laatz 			"\ttmgr pipe profile\n"
603726b3effeSKevin Laatz 			"\ttmgr\n"
603826b3effeSKevin Laatz 			"\ttmgr subport\n"
603926b3effeSKevin Laatz 			"\ttmgr subport pipe\n"
604026b3effeSKevin Laatz 			"\ttap\n"
604126b3effeSKevin Laatz 			"\tkni\n"
604226b3effeSKevin Laatz 			"\tport in action profile\n"
604326b3effeSKevin Laatz 			"\ttable action profile\n"
604426b3effeSKevin Laatz 			"\tpipeline\n"
604526b3effeSKevin Laatz 			"\tpipeline port in\n"
604626b3effeSKevin Laatz 			"\tpipeline port out\n"
604726b3effeSKevin Laatz 			"\tpipeline table\n"
604826b3effeSKevin Laatz 			"\tpipeline port in table\n"
604926b3effeSKevin Laatz 			"\tpipeline port in stats\n"
605026b3effeSKevin Laatz 			"\tpipeline port in enable\n"
605126b3effeSKevin Laatz 			"\tpipeline port in disable\n"
605226b3effeSKevin Laatz 			"\tpipeline port out stats\n"
605326b3effeSKevin Laatz 			"\tpipeline table stats\n"
605426b3effeSKevin Laatz 			"\tpipeline table rule add\n"
605526b3effeSKevin Laatz 			"\tpipeline table rule add default\n"
605626b3effeSKevin Laatz 			"\tpipeline table rule add bulk\n"
605726b3effeSKevin Laatz 			"\tpipeline table rule delete\n"
605826b3effeSKevin Laatz 			"\tpipeline table rule delete default\n"
60592fbdf834SCristian Dumitrescu 			"\tpipeline table rule show\n"
606026b3effeSKevin Laatz 			"\tpipeline table rule stats read\n"
606126b3effeSKevin Laatz 			"\tpipeline table meter profile add\n"
606226b3effeSKevin Laatz 			"\tpipeline table meter profile delete\n"
606326b3effeSKevin Laatz 			"\tpipeline table rule meter read\n"
606426b3effeSKevin Laatz 			"\tpipeline table dscp\n"
606526b3effeSKevin Laatz 			"\tpipeline table rule ttl read\n"
6066a3169ee5SCristian Dumitrescu 			"\tpipeline table rule time read\n"
606726b3effeSKevin Laatz 			"\tthread pipeline enable\n"
606826b3effeSKevin Laatz 			"\tthread pipeline disable\n\n");
606926b3effeSKevin Laatz 		return;
607026b3effeSKevin Laatz 	}
607126b3effeSKevin Laatz 
607226b3effeSKevin Laatz 	if (strcmp(tokens[0], "mempool") == 0) {
607326b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
607426b3effeSKevin Laatz 		return;
607526b3effeSKevin Laatz 	}
607626b3effeSKevin Laatz 
607726b3effeSKevin Laatz 	if (strcmp(tokens[0], "link") == 0) {
607826b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_link_help);
607926b3effeSKevin Laatz 		return;
608026b3effeSKevin Laatz 	}
608126b3effeSKevin Laatz 
608226b3effeSKevin Laatz 	if (strcmp(tokens[0], "swq") == 0) {
608326b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_swq_help);
608426b3effeSKevin Laatz 		return;
608526b3effeSKevin Laatz 	}
608626b3effeSKevin Laatz 
608726b3effeSKevin Laatz 	if (strcmp(tokens[0], "tmgr") == 0) {
608826b3effeSKevin Laatz 		if (n_tokens == 1) {
608926b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
609026b3effeSKevin Laatz 			return;
609126b3effeSKevin Laatz 		}
609226b3effeSKevin Laatz 
609326b3effeSKevin Laatz 		if ((n_tokens == 2) &&
609426b3effeSKevin Laatz 			(strcmp(tokens[1], "subport")) == 0) {
609526b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
609626b3effeSKevin Laatz 			return;
609726b3effeSKevin Laatz 		}
609826b3effeSKevin Laatz 
609926b3effeSKevin Laatz 		if ((n_tokens == 3) &&
610026b3effeSKevin Laatz 			(strcmp(tokens[1], "subport") == 0) &&
610126b3effeSKevin Laatz 			(strcmp(tokens[2], "profile") == 0)) {
610226b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
610326b3effeSKevin Laatz 				cmd_tmgr_subport_profile_help);
610426b3effeSKevin Laatz 			return;
610526b3effeSKevin Laatz 		}
610626b3effeSKevin Laatz 
610726b3effeSKevin Laatz 		if ((n_tokens == 3) &&
610826b3effeSKevin Laatz 			(strcmp(tokens[1], "subport") == 0) &&
610926b3effeSKevin Laatz 			(strcmp(tokens[2], "pipe") == 0)) {
611026b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
611126b3effeSKevin Laatz 			return;
611226b3effeSKevin Laatz 		}
611326b3effeSKevin Laatz 
611426b3effeSKevin Laatz 		if ((n_tokens == 3) &&
611526b3effeSKevin Laatz 			(strcmp(tokens[1], "pipe") == 0) &&
611626b3effeSKevin Laatz 			(strcmp(tokens[2], "profile") == 0)) {
611726b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
611826b3effeSKevin Laatz 			return;
611926b3effeSKevin Laatz 		}
612026b3effeSKevin Laatz 	}
612126b3effeSKevin Laatz 
612226b3effeSKevin Laatz 	if (strcmp(tokens[0], "tap") == 0) {
612326b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_tap_help);
612426b3effeSKevin Laatz 		return;
612526b3effeSKevin Laatz 	}
612626b3effeSKevin Laatz 
612726b3effeSKevin Laatz 	if (strcmp(tokens[0], "kni") == 0) {
612826b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_kni_help);
612926b3effeSKevin Laatz 		return;
613026b3effeSKevin Laatz 	}
613126b3effeSKevin Laatz 
61321edccebcSFan Zhang 	if (strcmp(tokens[0], "cryptodev") == 0) {
61331edccebcSFan Zhang 		snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
61341edccebcSFan Zhang 		return;
61351edccebcSFan Zhang 	}
61361edccebcSFan Zhang 
613726b3effeSKevin Laatz 	if ((n_tokens == 4) &&
613826b3effeSKevin Laatz 		(strcmp(tokens[0], "port") == 0) &&
613926b3effeSKevin Laatz 		(strcmp(tokens[1], "in") == 0) &&
614026b3effeSKevin Laatz 		(strcmp(tokens[2], "action") == 0) &&
614126b3effeSKevin Laatz 		(strcmp(tokens[3], "profile") == 0)) {
614226b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
614326b3effeSKevin Laatz 		return;
614426b3effeSKevin Laatz 	}
614526b3effeSKevin Laatz 
614626b3effeSKevin Laatz 	if ((n_tokens == 3) &&
614726b3effeSKevin Laatz 		(strcmp(tokens[0], "table") == 0) &&
614826b3effeSKevin Laatz 		(strcmp(tokens[1], "action") == 0) &&
614926b3effeSKevin Laatz 		(strcmp(tokens[2], "profile") == 0)) {
615026b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
615126b3effeSKevin Laatz 		return;
615226b3effeSKevin Laatz 	}
615326b3effeSKevin Laatz 
615426b3effeSKevin Laatz 	if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
615526b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
615626b3effeSKevin Laatz 		return;
615726b3effeSKevin Laatz 	}
615826b3effeSKevin Laatz 
615926b3effeSKevin Laatz 	if ((strcmp(tokens[0], "pipeline") == 0) &&
616026b3effeSKevin Laatz 		(strcmp(tokens[1], "port") == 0)) {
616126b3effeSKevin Laatz 		if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
616226b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
616326b3effeSKevin Laatz 			return;
616426b3effeSKevin Laatz 		}
616526b3effeSKevin Laatz 
616626b3effeSKevin Laatz 		if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
616726b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
616826b3effeSKevin Laatz 			return;
616926b3effeSKevin Laatz 		}
617026b3effeSKevin Laatz 
617126b3effeSKevin Laatz 		if ((n_tokens == 4) &&
617226b3effeSKevin Laatz 			(strcmp(tokens[2], "in") == 0) &&
617326b3effeSKevin Laatz 			(strcmp(tokens[3], "table") == 0)) {
617426b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
617526b3effeSKevin Laatz 				cmd_pipeline_port_in_table_help);
617626b3effeSKevin Laatz 			return;
617726b3effeSKevin Laatz 		}
617826b3effeSKevin Laatz 
617926b3effeSKevin Laatz 		if ((n_tokens == 4) &&
618026b3effeSKevin Laatz 			(strcmp(tokens[2], "in") == 0) &&
618126b3effeSKevin Laatz 			(strcmp(tokens[3], "stats") == 0)) {
618226b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
618326b3effeSKevin Laatz 				cmd_pipeline_port_in_stats_help);
618426b3effeSKevin Laatz 			return;
618526b3effeSKevin Laatz 		}
618626b3effeSKevin Laatz 
618726b3effeSKevin Laatz 		if ((n_tokens == 4) &&
618826b3effeSKevin Laatz 			(strcmp(tokens[2], "in") == 0) &&
618926b3effeSKevin Laatz 			(strcmp(tokens[3], "enable") == 0)) {
619026b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
619126b3effeSKevin Laatz 				cmd_pipeline_port_in_enable_help);
619226b3effeSKevin Laatz 			return;
619326b3effeSKevin Laatz 		}
619426b3effeSKevin Laatz 
619526b3effeSKevin Laatz 		if ((n_tokens == 4) &&
619626b3effeSKevin Laatz 			(strcmp(tokens[2], "in") == 0) &&
619726b3effeSKevin Laatz 			(strcmp(tokens[3], "disable") == 0)) {
619826b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
619926b3effeSKevin Laatz 				cmd_pipeline_port_in_disable_help);
620026b3effeSKevin Laatz 			return;
620126b3effeSKevin Laatz 		}
620226b3effeSKevin Laatz 
620326b3effeSKevin Laatz 		if ((n_tokens == 4) &&
620426b3effeSKevin Laatz 			(strcmp(tokens[2], "out") == 0) &&
620526b3effeSKevin Laatz 			(strcmp(tokens[3], "stats") == 0)) {
620626b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
620726b3effeSKevin Laatz 				cmd_pipeline_port_out_stats_help);
620826b3effeSKevin Laatz 			return;
620926b3effeSKevin Laatz 		}
621026b3effeSKevin Laatz 	}
621126b3effeSKevin Laatz 
621226b3effeSKevin Laatz 	if ((strcmp(tokens[0], "pipeline") == 0) &&
621326b3effeSKevin Laatz 		(strcmp(tokens[1], "table") == 0)) {
621426b3effeSKevin Laatz 		if (n_tokens == 2) {
621526b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
621626b3effeSKevin Laatz 			return;
621726b3effeSKevin Laatz 		}
621826b3effeSKevin Laatz 
621926b3effeSKevin Laatz 		if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
622026b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
622126b3effeSKevin Laatz 				cmd_pipeline_table_stats_help);
622226b3effeSKevin Laatz 			return;
622326b3effeSKevin Laatz 		}
622426b3effeSKevin Laatz 
622526b3effeSKevin Laatz 		if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
622626b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
622726b3effeSKevin Laatz 				cmd_pipeline_table_dscp_help);
622826b3effeSKevin Laatz 			return;
622926b3effeSKevin Laatz 		}
623026b3effeSKevin Laatz 
623126b3effeSKevin Laatz 		if ((n_tokens == 4) &&
623226b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
623326b3effeSKevin Laatz 			(strcmp(tokens[3], "add") == 0)) {
623426b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
623526b3effeSKevin Laatz 				cmd_pipeline_table_rule_add_help);
623626b3effeSKevin Laatz 			return;
623726b3effeSKevin Laatz 		}
623826b3effeSKevin Laatz 
623926b3effeSKevin Laatz 		if ((n_tokens == 5) &&
624026b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
624126b3effeSKevin Laatz 			(strcmp(tokens[3], "add") == 0) &&
624226b3effeSKevin Laatz 			(strcmp(tokens[4], "default") == 0)) {
624326b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
624426b3effeSKevin Laatz 				cmd_pipeline_table_rule_add_default_help);
624526b3effeSKevin Laatz 			return;
624626b3effeSKevin Laatz 		}
624726b3effeSKevin Laatz 
624826b3effeSKevin Laatz 		if ((n_tokens == 5) &&
624926b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
625026b3effeSKevin Laatz 			(strcmp(tokens[3], "add") == 0) &&
625126b3effeSKevin Laatz 			(strcmp(tokens[4], "bulk") == 0)) {
625226b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
625326b3effeSKevin Laatz 				cmd_pipeline_table_rule_add_bulk_help);
625426b3effeSKevin Laatz 			return;
625526b3effeSKevin Laatz 		}
625626b3effeSKevin Laatz 
625726b3effeSKevin Laatz 		if ((n_tokens == 4) &&
625826b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
625926b3effeSKevin Laatz 			(strcmp(tokens[3], "delete") == 0)) {
626026b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
626126b3effeSKevin Laatz 				cmd_pipeline_table_rule_delete_help);
626226b3effeSKevin Laatz 			return;
626326b3effeSKevin Laatz 		}
626426b3effeSKevin Laatz 
626526b3effeSKevin Laatz 		if ((n_tokens == 5) &&
626626b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
626726b3effeSKevin Laatz 			(strcmp(tokens[3], "delete") == 0) &&
626826b3effeSKevin Laatz 			(strcmp(tokens[4], "default") == 0)) {
626926b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
627026b3effeSKevin Laatz 				cmd_pipeline_table_rule_delete_default_help);
627126b3effeSKevin Laatz 			return;
627226b3effeSKevin Laatz 		}
627326b3effeSKevin Laatz 
62742fbdf834SCristian Dumitrescu 		if ((n_tokens == 4) &&
62752fbdf834SCristian Dumitrescu 			(strcmp(tokens[2], "rule") == 0) &&
62762fbdf834SCristian Dumitrescu 			(strcmp(tokens[3], "show") == 0)) {
62772fbdf834SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
62782fbdf834SCristian Dumitrescu 				cmd_pipeline_table_rule_show_help);
62792fbdf834SCristian Dumitrescu 			return;
62802fbdf834SCristian Dumitrescu 		}
62812fbdf834SCristian Dumitrescu 
628226b3effeSKevin Laatz 		if ((n_tokens == 5) &&
628326b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
628426b3effeSKevin Laatz 			(strcmp(tokens[3], "stats") == 0) &&
628526b3effeSKevin Laatz 			(strcmp(tokens[4], "read") == 0)) {
628626b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
628726b3effeSKevin Laatz 				cmd_pipeline_table_rule_stats_read_help);
628826b3effeSKevin Laatz 			return;
628926b3effeSKevin Laatz 		}
629026b3effeSKevin Laatz 
629126b3effeSKevin Laatz 		if ((n_tokens == 5) &&
629226b3effeSKevin Laatz 			(strcmp(tokens[2], "meter") == 0) &&
629326b3effeSKevin Laatz 			(strcmp(tokens[3], "profile") == 0) &&
629426b3effeSKevin Laatz 			(strcmp(tokens[4], "add") == 0)) {
629526b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
629626b3effeSKevin Laatz 				cmd_pipeline_table_meter_profile_add_help);
629726b3effeSKevin Laatz 			return;
629826b3effeSKevin Laatz 		}
629926b3effeSKevin Laatz 
630026b3effeSKevin Laatz 		if ((n_tokens == 5) &&
630126b3effeSKevin Laatz 			(strcmp(tokens[2], "meter") == 0) &&
630226b3effeSKevin Laatz 			(strcmp(tokens[3], "profile") == 0) &&
630326b3effeSKevin Laatz 			(strcmp(tokens[4], "delete") == 0)) {
630426b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
630526b3effeSKevin Laatz 				cmd_pipeline_table_meter_profile_delete_help);
630626b3effeSKevin Laatz 			return;
630726b3effeSKevin Laatz 		}
630826b3effeSKevin Laatz 
630926b3effeSKevin Laatz 		if ((n_tokens == 5) &&
631026b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
631126b3effeSKevin Laatz 			(strcmp(tokens[3], "meter") == 0) &&
631226b3effeSKevin Laatz 			(strcmp(tokens[4], "read") == 0)) {
631326b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
631426b3effeSKevin Laatz 				cmd_pipeline_table_rule_meter_read_help);
631526b3effeSKevin Laatz 			return;
631626b3effeSKevin Laatz 		}
631726b3effeSKevin Laatz 
631826b3effeSKevin Laatz 		if ((n_tokens == 5) &&
631926b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
632026b3effeSKevin Laatz 			(strcmp(tokens[3], "ttl") == 0) &&
632126b3effeSKevin Laatz 			(strcmp(tokens[4], "read") == 0)) {
632226b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
632326b3effeSKevin Laatz 				cmd_pipeline_table_rule_ttl_read_help);
632426b3effeSKevin Laatz 			return;
632526b3effeSKevin Laatz 		}
6326a3169ee5SCristian Dumitrescu 
6327a3169ee5SCristian Dumitrescu 		if ((n_tokens == 5) &&
6328a3169ee5SCristian Dumitrescu 			(strcmp(tokens[2], "rule") == 0) &&
6329a3169ee5SCristian Dumitrescu 			(strcmp(tokens[3], "time") == 0) &&
6330a3169ee5SCristian Dumitrescu 			(strcmp(tokens[4], "read") == 0)) {
6331a3169ee5SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
6332a3169ee5SCristian Dumitrescu 				cmd_pipeline_table_rule_time_read_help);
6333a3169ee5SCristian Dumitrescu 			return;
6334a3169ee5SCristian Dumitrescu 		}
633526b3effeSKevin Laatz 	}
633626b3effeSKevin Laatz 
633726b3effeSKevin Laatz 	if ((n_tokens == 3) &&
633826b3effeSKevin Laatz 		(strcmp(tokens[0], "thread") == 0) &&
633926b3effeSKevin Laatz 		(strcmp(tokens[1], "pipeline") == 0)) {
634026b3effeSKevin Laatz 		if (strcmp(tokens[2], "enable") == 0) {
634126b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
634226b3effeSKevin Laatz 				cmd_thread_pipeline_enable_help);
634326b3effeSKevin Laatz 			return;
634426b3effeSKevin Laatz 		}
634526b3effeSKevin Laatz 
634626b3effeSKevin Laatz 		if (strcmp(tokens[2], "disable") == 0) {
634726b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
634826b3effeSKevin Laatz 				cmd_thread_pipeline_disable_help);
634926b3effeSKevin Laatz 			return;
635026b3effeSKevin Laatz 		}
635126b3effeSKevin Laatz 	}
635226b3effeSKevin Laatz 
635326b3effeSKevin Laatz 	snprintf(out, out_size, "Invalid command\n");
635426b3effeSKevin Laatz }
635526b3effeSKevin Laatz 
63566bfe74f8SJasvinder Singh void
cli_process(char * in,char * out,size_t out_size)63576bfe74f8SJasvinder Singh cli_process(char *in, char *out, size_t out_size)
63586bfe74f8SJasvinder Singh {
63596bfe74f8SJasvinder Singh 	char *tokens[CMD_MAX_TOKENS];
63606bfe74f8SJasvinder Singh 	uint32_t n_tokens = RTE_DIM(tokens);
63616bfe74f8SJasvinder Singh 	int status;
63626bfe74f8SJasvinder Singh 
63634bbf8e30SJasvinder Singh 	if (is_comment(in))
63644bbf8e30SJasvinder Singh 		return;
63654bbf8e30SJasvinder Singh 
63666bfe74f8SJasvinder Singh 	status = parse_tokenize_string(in, tokens, &n_tokens);
63676bfe74f8SJasvinder Singh 	if (status) {
63686bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
63696bfe74f8SJasvinder Singh 		return;
63706bfe74f8SJasvinder Singh 	}
63716bfe74f8SJasvinder Singh 
63726bfe74f8SJasvinder Singh 	if (n_tokens == 0)
63736bfe74f8SJasvinder Singh 		return;
63746bfe74f8SJasvinder Singh 
637526b3effeSKevin Laatz 	if (strcmp(tokens[0], "help") == 0) {
637626b3effeSKevin Laatz 		cmd_help(tokens, n_tokens, out, out_size);
637726b3effeSKevin Laatz 		return;
637826b3effeSKevin Laatz 	}
637926b3effeSKevin Laatz 
63806bfe74f8SJasvinder Singh 	if (strcmp(tokens[0], "mempool") == 0) {
63816bfe74f8SJasvinder Singh 		cmd_mempool(tokens, n_tokens, out, out_size);
63826bfe74f8SJasvinder Singh 		return;
63836bfe74f8SJasvinder Singh 	}
63846bfe74f8SJasvinder Singh 
6385133c2c65SJasvinder Singh 	if (strcmp(tokens[0], "link") == 0) {
6386ecfc2b1cSKevin Laatz 		if (strcmp(tokens[1], "show") == 0) {
6387ecfc2b1cSKevin Laatz 			cmd_link_show(tokens, n_tokens, out, out_size);
6388ecfc2b1cSKevin Laatz 			return;
6389ecfc2b1cSKevin Laatz 		}
6390ecfc2b1cSKevin Laatz 
6391133c2c65SJasvinder Singh 		cmd_link(tokens, n_tokens, out, out_size);
6392133c2c65SJasvinder Singh 		return;
6393133c2c65SJasvinder Singh 	}
6394133c2c65SJasvinder Singh 
63958245472cSJasvinder Singh 	if (strcmp(tokens[0], "swq") == 0) {
63968245472cSJasvinder Singh 		cmd_swq(tokens, n_tokens, out, out_size);
63978245472cSJasvinder Singh 		return;
63988245472cSJasvinder Singh 	}
63998245472cSJasvinder Singh 
640025961ff3SJasvinder Singh 	if (strcmp(tokens[0], "tmgr") == 0) {
640125961ff3SJasvinder Singh 		if ((n_tokens >= 3) &&
640225961ff3SJasvinder Singh 			(strcmp(tokens[1], "subport") == 0) &&
640325961ff3SJasvinder Singh 			(strcmp(tokens[2], "profile") == 0)) {
640425961ff3SJasvinder Singh 			cmd_tmgr_subport_profile(tokens, n_tokens,
640525961ff3SJasvinder Singh 				out, out_size);
640625961ff3SJasvinder Singh 			return;
640725961ff3SJasvinder Singh 		}
640825961ff3SJasvinder Singh 
640925961ff3SJasvinder Singh 		if ((n_tokens >= 3) &&
641025961ff3SJasvinder Singh 			(strcmp(tokens[1], "pipe") == 0) &&
641125961ff3SJasvinder Singh 			(strcmp(tokens[2], "profile") == 0)) {
641225961ff3SJasvinder Singh 			cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
641325961ff3SJasvinder Singh 			return;
641425961ff3SJasvinder Singh 		}
641525961ff3SJasvinder Singh 
641625961ff3SJasvinder Singh 		if ((n_tokens >= 5) &&
641725961ff3SJasvinder Singh 			(strcmp(tokens[2], "subport") == 0) &&
641825961ff3SJasvinder Singh 			(strcmp(tokens[4], "profile") == 0)) {
641925961ff3SJasvinder Singh 			cmd_tmgr_subport(tokens, n_tokens, out, out_size);
642025961ff3SJasvinder Singh 			return;
642125961ff3SJasvinder Singh 		}
642225961ff3SJasvinder Singh 
642325961ff3SJasvinder Singh 		if ((n_tokens >= 5) &&
642425961ff3SJasvinder Singh 			(strcmp(tokens[2], "subport") == 0) &&
642525961ff3SJasvinder Singh 			(strcmp(tokens[4], "pipe") == 0)) {
642625961ff3SJasvinder Singh 			cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
642725961ff3SJasvinder Singh 			return;
642825961ff3SJasvinder Singh 		}
642925961ff3SJasvinder Singh 
643025961ff3SJasvinder Singh 		cmd_tmgr(tokens, n_tokens, out, out_size);
643125961ff3SJasvinder Singh 		return;
643225961ff3SJasvinder Singh 	}
643325961ff3SJasvinder Singh 
64342f74ae28SJasvinder Singh 	if (strcmp(tokens[0], "tap") == 0) {
64352f74ae28SJasvinder Singh 		cmd_tap(tokens, n_tokens, out, out_size);
64362f74ae28SJasvinder Singh 		return;
64372f74ae28SJasvinder Singh 	}
64382f74ae28SJasvinder Singh 
64399a408cc8SJasvinder Singh 	if (strcmp(tokens[0], "kni") == 0) {
64409a408cc8SJasvinder Singh 		cmd_kni(tokens, n_tokens, out, out_size);
64419a408cc8SJasvinder Singh 		return;
64429a408cc8SJasvinder Singh 	}
64439a408cc8SJasvinder Singh 
64441edccebcSFan Zhang 	if (strcmp(tokens[0], "cryptodev") == 0) {
64451edccebcSFan Zhang 		cmd_cryptodev(tokens, n_tokens, out, out_size);
64461edccebcSFan Zhang 		return;
64471edccebcSFan Zhang 	}
64481edccebcSFan Zhang 
644971937434SJasvinder Singh 	if (strcmp(tokens[0], "port") == 0) {
645071937434SJasvinder Singh 		cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
645171937434SJasvinder Singh 		return;
645271937434SJasvinder Singh 	}
645371937434SJasvinder Singh 
645471937434SJasvinder Singh 	if (strcmp(tokens[0], "table") == 0) {
645571937434SJasvinder Singh 		cmd_table_action_profile(tokens, n_tokens, out, out_size);
645671937434SJasvinder Singh 		return;
645771937434SJasvinder Singh 	}
645871937434SJasvinder Singh 
6459d75c371eSJasvinder Singh 	if (strcmp(tokens[0], "pipeline") == 0) {
6460d75c371eSJasvinder Singh 		if ((n_tokens >= 3) &&
6461d75c371eSJasvinder Singh 			(strcmp(tokens[2], "period") == 0)) {
6462d75c371eSJasvinder Singh 			cmd_pipeline(tokens, n_tokens, out, out_size);
6463d75c371eSJasvinder Singh 			return;
6464d75c371eSJasvinder Singh 		}
6465d75c371eSJasvinder Singh 
6466d75c371eSJasvinder Singh 		if ((n_tokens >= 5) &&
6467d75c371eSJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
6468d75c371eSJasvinder Singh 			(strcmp(tokens[3], "in") == 0) &&
6469d75c371eSJasvinder Singh 			(strcmp(tokens[4], "bsz") == 0)) {
6470d75c371eSJasvinder Singh 			cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
6471d75c371eSJasvinder Singh 			return;
6472d75c371eSJasvinder Singh 		}
6473d75c371eSJasvinder Singh 
6474d75c371eSJasvinder Singh 		if ((n_tokens >= 5) &&
6475d75c371eSJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
6476d75c371eSJasvinder Singh 			(strcmp(tokens[3], "out") == 0) &&
6477d75c371eSJasvinder Singh 			(strcmp(tokens[4], "bsz") == 0)) {
6478d75c371eSJasvinder Singh 			cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
6479d75c371eSJasvinder Singh 			return;
6480d75c371eSJasvinder Singh 		}
6481d75c371eSJasvinder Singh 
6482d75c371eSJasvinder Singh 		if ((n_tokens >= 4) &&
6483d75c371eSJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6484d75c371eSJasvinder Singh 			(strcmp(tokens[3], "match") == 0)) {
6485d75c371eSJasvinder Singh 			cmd_pipeline_table(tokens, n_tokens, out, out_size);
6486d75c371eSJasvinder Singh 			return;
6487d75c371eSJasvinder Singh 		}
6488d75c371eSJasvinder Singh 
6489d75c371eSJasvinder Singh 		if ((n_tokens >= 6) &&
6490d75c371eSJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
6491d75c371eSJasvinder Singh 			(strcmp(tokens[3], "in") == 0) &&
6492d75c371eSJasvinder Singh 			(strcmp(tokens[5], "table") == 0)) {
6493d75c371eSJasvinder Singh 			cmd_pipeline_port_in_table(tokens, n_tokens,
6494d75c371eSJasvinder Singh 				out, out_size);
6495d75c371eSJasvinder Singh 			return;
6496d75c371eSJasvinder Singh 		}
64976b1b3c3cSJasvinder Singh 
64986b1b3c3cSJasvinder Singh 		if ((n_tokens >= 6) &&
64996b1b3c3cSJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
65006b1b3c3cSJasvinder Singh 			(strcmp(tokens[3], "in") == 0) &&
650150e73d05SJasvinder Singh 			(strcmp(tokens[5], "stats") == 0)) {
650250e73d05SJasvinder Singh 			cmd_pipeline_port_in_stats(tokens, n_tokens,
650350e73d05SJasvinder Singh 				out, out_size);
650450e73d05SJasvinder Singh 			return;
650550e73d05SJasvinder Singh 		}
650650e73d05SJasvinder Singh 
650750e73d05SJasvinder Singh 		if ((n_tokens >= 6) &&
650850e73d05SJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
650950e73d05SJasvinder Singh 			(strcmp(tokens[3], "in") == 0) &&
65106b1b3c3cSJasvinder Singh 			(strcmp(tokens[5], "enable") == 0)) {
65116b1b3c3cSJasvinder Singh 			cmd_pipeline_port_in_enable(tokens, n_tokens,
65126b1b3c3cSJasvinder Singh 				out, out_size);
65136b1b3c3cSJasvinder Singh 			return;
65146b1b3c3cSJasvinder Singh 		}
65156b1b3c3cSJasvinder Singh 
65166b1b3c3cSJasvinder Singh 		if ((n_tokens >= 6) &&
65176b1b3c3cSJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
65186b1b3c3cSJasvinder Singh 			(strcmp(tokens[3], "in") == 0) &&
65196b1b3c3cSJasvinder Singh 			(strcmp(tokens[5], "disable") == 0)) {
65206b1b3c3cSJasvinder Singh 			cmd_pipeline_port_in_disable(tokens, n_tokens,
65216b1b3c3cSJasvinder Singh 				out, out_size);
65226b1b3c3cSJasvinder Singh 			return;
65236b1b3c3cSJasvinder Singh 		}
652450e73d05SJasvinder Singh 
652550e73d05SJasvinder Singh 		if ((n_tokens >= 6) &&
652650e73d05SJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
652750e73d05SJasvinder Singh 			(strcmp(tokens[3], "out") == 0) &&
652850e73d05SJasvinder Singh 			(strcmp(tokens[5], "stats") == 0)) {
652950e73d05SJasvinder Singh 			cmd_pipeline_port_out_stats(tokens, n_tokens,
653050e73d05SJasvinder Singh 				out, out_size);
653150e73d05SJasvinder Singh 			return;
653250e73d05SJasvinder Singh 		}
653350e73d05SJasvinder Singh 
653450e73d05SJasvinder Singh 		if ((n_tokens >= 5) &&
653550e73d05SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
653650e73d05SJasvinder Singh 			(strcmp(tokens[4], "stats") == 0)) {
653750e73d05SJasvinder Singh 			cmd_pipeline_table_stats(tokens, n_tokens,
653850e73d05SJasvinder Singh 				out, out_size);
653950e73d05SJasvinder Singh 			return;
654050e73d05SJasvinder Singh 		}
6541a3a95b7dSJasvinder Singh 
6542a3a95b7dSJasvinder Singh 		if ((n_tokens >= 7) &&
6543a3a95b7dSJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6544a3a95b7dSJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
6545a3a95b7dSJasvinder Singh 			(strcmp(tokens[5], "add") == 0) &&
6546a3a95b7dSJasvinder Singh 			(strcmp(tokens[6], "match") == 0)) {
6547a3a95b7dSJasvinder Singh 			if ((n_tokens >= 8) &&
6548a3a95b7dSJasvinder Singh 				(strcmp(tokens[7], "default") == 0)) {
6549a3a95b7dSJasvinder Singh 				cmd_pipeline_table_rule_add_default(tokens,
6550a3a95b7dSJasvinder Singh 					n_tokens, out, out_size);
6551a3a95b7dSJasvinder Singh 				return;
6552a3a95b7dSJasvinder Singh 			}
6553a3a95b7dSJasvinder Singh 
6554a3a95b7dSJasvinder Singh 			cmd_pipeline_table_rule_add(tokens, n_tokens,
6555a3a95b7dSJasvinder Singh 				out, out_size);
6556a3a95b7dSJasvinder Singh 			return;
6557a3a95b7dSJasvinder Singh 		}
6558f634e4c5SJasvinder Singh 
6559f634e4c5SJasvinder Singh 		if ((n_tokens >= 7) &&
6560f634e4c5SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6561f634e4c5SJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
65623186282fSJasvinder Singh 			(strcmp(tokens[5], "add") == 0) &&
65633186282fSJasvinder Singh 			(strcmp(tokens[6], "bulk") == 0)) {
65643186282fSJasvinder Singh 			cmd_pipeline_table_rule_add_bulk(tokens,
65653186282fSJasvinder Singh 				n_tokens, out, out_size);
65663186282fSJasvinder Singh 			return;
65673186282fSJasvinder Singh 		}
65683186282fSJasvinder Singh 
65693186282fSJasvinder Singh 		if ((n_tokens >= 7) &&
65703186282fSJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
65713186282fSJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
6572f634e4c5SJasvinder Singh 			(strcmp(tokens[5], "delete") == 0) &&
6573f634e4c5SJasvinder Singh 			(strcmp(tokens[6], "match") == 0)) {
6574f634e4c5SJasvinder Singh 			if ((n_tokens >= 8) &&
6575f634e4c5SJasvinder Singh 				(strcmp(tokens[7], "default") == 0)) {
6576f634e4c5SJasvinder Singh 				cmd_pipeline_table_rule_delete_default(tokens,
6577f634e4c5SJasvinder Singh 					n_tokens, out, out_size);
6578f634e4c5SJasvinder Singh 				return;
6579f634e4c5SJasvinder Singh 				}
6580f634e4c5SJasvinder Singh 
6581f634e4c5SJasvinder Singh 			cmd_pipeline_table_rule_delete(tokens, n_tokens,
6582f634e4c5SJasvinder Singh 				out, out_size);
6583f634e4c5SJasvinder Singh 			return;
6584f634e4c5SJasvinder Singh 		}
6585c64b9121SJasvinder Singh 
65862fbdf834SCristian Dumitrescu 		if ((n_tokens >= 6) &&
65872fbdf834SCristian Dumitrescu 			(strcmp(tokens[2], "table") == 0) &&
65882fbdf834SCristian Dumitrescu 			(strcmp(tokens[4], "rule") == 0) &&
65892fbdf834SCristian Dumitrescu 			(strcmp(tokens[5], "show") == 0)) {
65902fbdf834SCristian Dumitrescu 			cmd_pipeline_table_rule_show(tokens, n_tokens,
65912fbdf834SCristian Dumitrescu 				out, out_size);
65922fbdf834SCristian Dumitrescu 			return;
65932fbdf834SCristian Dumitrescu 		}
65942fbdf834SCristian Dumitrescu 
6595c64b9121SJasvinder Singh 		if ((n_tokens >= 7) &&
6596c64b9121SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6597c64b9121SJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
6598c64b9121SJasvinder Singh 			(strcmp(tokens[5], "read") == 0) &&
6599c64b9121SJasvinder Singh 			(strcmp(tokens[6], "stats") == 0)) {
6600c64b9121SJasvinder Singh 			cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
6601c64b9121SJasvinder Singh 				out, out_size);
6602c64b9121SJasvinder Singh 			return;
6603c64b9121SJasvinder Singh 		}
66047e11393eSJasvinder Singh 
66057e11393eSJasvinder Singh 		if ((n_tokens >= 8) &&
66067e11393eSJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
66077e11393eSJasvinder Singh 			(strcmp(tokens[4], "meter") == 0) &&
66087e11393eSJasvinder Singh 			(strcmp(tokens[5], "profile") == 0) &&
66097e11393eSJasvinder Singh 			(strcmp(tokens[7], "add") == 0)) {
66107e11393eSJasvinder Singh 			cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
66117e11393eSJasvinder Singh 				out, out_size);
66127e11393eSJasvinder Singh 			return;
66137e11393eSJasvinder Singh 		}
66147e11393eSJasvinder Singh 
66157e11393eSJasvinder Singh 		if ((n_tokens >= 8) &&
66167e11393eSJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
66177e11393eSJasvinder Singh 			(strcmp(tokens[4], "meter") == 0) &&
66187e11393eSJasvinder Singh 			(strcmp(tokens[5], "profile") == 0) &&
66197e11393eSJasvinder Singh 			(strcmp(tokens[7], "delete") == 0)) {
66207e11393eSJasvinder Singh 			cmd_pipeline_table_meter_profile_delete(tokens,
66217e11393eSJasvinder Singh 				n_tokens, out, out_size);
66227e11393eSJasvinder Singh 			return;
66237e11393eSJasvinder Singh 		}
6624e92058d6SJasvinder Singh 
6625e92058d6SJasvinder Singh 		if ((n_tokens >= 7) &&
6626e92058d6SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6627e92058d6SJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
6628e92058d6SJasvinder Singh 			(strcmp(tokens[5], "read") == 0) &&
6629e92058d6SJasvinder Singh 			(strcmp(tokens[6], "meter") == 0)) {
6630e92058d6SJasvinder Singh 			cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
6631e92058d6SJasvinder Singh 				out, out_size);
6632e92058d6SJasvinder Singh 			return;
6633e92058d6SJasvinder Singh 		}
66342b82ef48SJasvinder Singh 
66352b82ef48SJasvinder Singh 		if ((n_tokens >= 5) &&
66362b82ef48SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
66372b82ef48SJasvinder Singh 			(strcmp(tokens[4], "dscp") == 0)) {
66382b82ef48SJasvinder Singh 			cmd_pipeline_table_dscp(tokens, n_tokens,
66392b82ef48SJasvinder Singh 				out, out_size);
66402b82ef48SJasvinder Singh 			return;
66412b82ef48SJasvinder Singh 		}
6642d0d306c7SJasvinder Singh 
6643d0d306c7SJasvinder Singh 		if ((n_tokens >= 7) &&
6644d0d306c7SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6645d0d306c7SJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
6646d0d306c7SJasvinder Singh 			(strcmp(tokens[5], "read") == 0) &&
6647d0d306c7SJasvinder Singh 			(strcmp(tokens[6], "ttl") == 0)) {
6648d0d306c7SJasvinder Singh 			cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
6649d0d306c7SJasvinder Singh 				out, out_size);
6650d0d306c7SJasvinder Singh 			return;
6651d0d306c7SJasvinder Singh 		}
6652a3169ee5SCristian Dumitrescu 
6653a3169ee5SCristian Dumitrescu 		if ((n_tokens >= 7) &&
6654a3169ee5SCristian Dumitrescu 			(strcmp(tokens[2], "table") == 0) &&
6655a3169ee5SCristian Dumitrescu 			(strcmp(tokens[4], "rule") == 0) &&
6656a3169ee5SCristian Dumitrescu 			(strcmp(tokens[5], "read") == 0) &&
6657a3169ee5SCristian Dumitrescu 			(strcmp(tokens[6], "time") == 0)) {
6658a3169ee5SCristian Dumitrescu 			cmd_pipeline_table_rule_time_read(tokens, n_tokens,
6659a3169ee5SCristian Dumitrescu 				out, out_size);
6660a3169ee5SCristian Dumitrescu 			return;
6661a3169ee5SCristian Dumitrescu 		}
6662d75c371eSJasvinder Singh 	}
6663d75c371eSJasvinder Singh 
666432e5d9b1SJasvinder Singh 	if (strcmp(tokens[0], "thread") == 0) {
666532e5d9b1SJasvinder Singh 		if ((n_tokens >= 5) &&
666632e5d9b1SJasvinder Singh 			(strcmp(tokens[4], "enable") == 0)) {
666732e5d9b1SJasvinder Singh 			cmd_thread_pipeline_enable(tokens, n_tokens,
666832e5d9b1SJasvinder Singh 				out, out_size);
666932e5d9b1SJasvinder Singh 			return;
667032e5d9b1SJasvinder Singh 		}
667132e5d9b1SJasvinder Singh 
667232e5d9b1SJasvinder Singh 		if ((n_tokens >= 5) &&
667332e5d9b1SJasvinder Singh 			(strcmp(tokens[4], "disable") == 0)) {
667432e5d9b1SJasvinder Singh 			cmd_thread_pipeline_disable(tokens, n_tokens,
667532e5d9b1SJasvinder Singh 				out, out_size);
667632e5d9b1SJasvinder Singh 			return;
667732e5d9b1SJasvinder Singh 		}
667832e5d9b1SJasvinder Singh 	}
667932e5d9b1SJasvinder Singh 
66806bfe74f8SJasvinder Singh 	snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
66814bbf8e30SJasvinder Singh }
66824bbf8e30SJasvinder Singh 
66834bbf8e30SJasvinder Singh int
cli_script_process(const char * file_name,size_t msg_in_len_max,size_t msg_out_len_max)66844bbf8e30SJasvinder Singh cli_script_process(const char *file_name,
66854bbf8e30SJasvinder Singh 	size_t msg_in_len_max,
66864bbf8e30SJasvinder Singh 	size_t msg_out_len_max)
66874bbf8e30SJasvinder Singh {
66884bbf8e30SJasvinder Singh 	char *msg_in = NULL, *msg_out = NULL;
66894bbf8e30SJasvinder Singh 	FILE *f = NULL;
66904bbf8e30SJasvinder Singh 
66914bbf8e30SJasvinder Singh 	/* Check input arguments */
66924bbf8e30SJasvinder Singh 	if ((file_name == NULL) ||
66934bbf8e30SJasvinder Singh 		(strlen(file_name) == 0) ||
66944bbf8e30SJasvinder Singh 		(msg_in_len_max == 0) ||
66954bbf8e30SJasvinder Singh 		(msg_out_len_max == 0))
66964bbf8e30SJasvinder Singh 		return -EINVAL;
66974bbf8e30SJasvinder Singh 
66984bbf8e30SJasvinder Singh 	msg_in = malloc(msg_in_len_max + 1);
66994bbf8e30SJasvinder Singh 	msg_out = malloc(msg_out_len_max + 1);
67004bbf8e30SJasvinder Singh 	if ((msg_in == NULL) ||
67014bbf8e30SJasvinder Singh 		(msg_out == NULL)) {
67024bbf8e30SJasvinder Singh 		free(msg_out);
67034bbf8e30SJasvinder Singh 		free(msg_in);
67044bbf8e30SJasvinder Singh 		return -ENOMEM;
67054bbf8e30SJasvinder Singh 	}
67064bbf8e30SJasvinder Singh 
67074bbf8e30SJasvinder Singh 	/* Open input file */
67084bbf8e30SJasvinder Singh 	f = fopen(file_name, "r");
67094bbf8e30SJasvinder Singh 	if (f == NULL) {
67104bbf8e30SJasvinder Singh 		free(msg_out);
67114bbf8e30SJasvinder Singh 		free(msg_in);
67124bbf8e30SJasvinder Singh 		return -EIO;
67134bbf8e30SJasvinder Singh 	}
67144bbf8e30SJasvinder Singh 
67154bbf8e30SJasvinder Singh 	/* Read file */
67164bbf8e30SJasvinder Singh 	for ( ; ; ) {
67174bbf8e30SJasvinder Singh 		if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
67184bbf8e30SJasvinder Singh 			break;
67194bbf8e30SJasvinder Singh 
67204bbf8e30SJasvinder Singh 		printf("%s", msg_in);
67214bbf8e30SJasvinder Singh 		msg_out[0] = 0;
67224bbf8e30SJasvinder Singh 
67234bbf8e30SJasvinder Singh 		cli_process(msg_in,
67244bbf8e30SJasvinder Singh 			msg_out,
67254bbf8e30SJasvinder Singh 			msg_out_len_max);
67264bbf8e30SJasvinder Singh 
67274bbf8e30SJasvinder Singh 		if (strlen(msg_out))
67284bbf8e30SJasvinder Singh 			printf("%s", msg_out);
67294bbf8e30SJasvinder Singh 	}
67304bbf8e30SJasvinder Singh 
67314bbf8e30SJasvinder Singh 	/* Close file */
67324bbf8e30SJasvinder Singh 	fclose(f);
67334bbf8e30SJasvinder Singh 	free(msg_out);
67344bbf8e30SJasvinder Singh 	free(msg_in);
67354bbf8e30SJasvinder Singh 	return 0;
67364bbf8e30SJasvinder Singh }
67373186282fSJasvinder Singh 
67383186282fSJasvinder Singh static int
cli_rule_file_process(const char * file_name,size_t line_len_max,struct table_rule_list ** rule_list,uint32_t * n_rules,uint32_t * line_number,char * out,size_t out_size)67393186282fSJasvinder Singh cli_rule_file_process(const char *file_name,
67403186282fSJasvinder Singh 	size_t line_len_max,
674127b333b2SCristian Dumitrescu 	struct table_rule_list **rule_list,
67423186282fSJasvinder Singh 	uint32_t *n_rules,
67433186282fSJasvinder Singh 	uint32_t *line_number,
67443186282fSJasvinder Singh 	char *out,
67453186282fSJasvinder Singh 	size_t out_size)
67463186282fSJasvinder Singh {
674727b333b2SCristian Dumitrescu 	struct table_rule_list *list = NULL;
67483186282fSJasvinder Singh 	char *line = NULL;
674927b333b2SCristian Dumitrescu 	FILE *f = NULL;
675027b333b2SCristian Dumitrescu 	uint32_t rule_id = 0, line_id = 0;
67513186282fSJasvinder Singh 	int status = 0;
67523186282fSJasvinder Singh 
67533186282fSJasvinder Singh 	/* Check input arguments */
67543186282fSJasvinder Singh 	if ((file_name == NULL) ||
67553186282fSJasvinder Singh 		(strlen(file_name) == 0) ||
675627b333b2SCristian Dumitrescu 		(line_len_max == 0) ||
675727b333b2SCristian Dumitrescu 		(rule_list == NULL) ||
675827b333b2SCristian Dumitrescu 		(n_rules == NULL) ||
675927b333b2SCristian Dumitrescu 		(line_number == NULL) ||
676027b333b2SCristian Dumitrescu 		(out == NULL)) {
676127b333b2SCristian Dumitrescu 		status = -EINVAL;
676227b333b2SCristian Dumitrescu 		goto cli_rule_file_process_free;
67633186282fSJasvinder Singh 	}
67643186282fSJasvinder Singh 
67653186282fSJasvinder Singh 	/* Memory allocation */
676627b333b2SCristian Dumitrescu 	list = malloc(sizeof(struct table_rule_list));
676727b333b2SCristian Dumitrescu 	if (list == NULL) {
676827b333b2SCristian Dumitrescu 		status = -ENOMEM;
676927b333b2SCristian Dumitrescu 		goto cli_rule_file_process_free;
677027b333b2SCristian Dumitrescu 	}
677127b333b2SCristian Dumitrescu 
677227b333b2SCristian Dumitrescu 	TAILQ_INIT(list);
677327b333b2SCristian Dumitrescu 
67743186282fSJasvinder Singh 	line = malloc(line_len_max + 1);
67753186282fSJasvinder Singh 	if (line == NULL) {
677627b333b2SCristian Dumitrescu 		status = -ENOMEM;
677727b333b2SCristian Dumitrescu 		goto cli_rule_file_process_free;
67783186282fSJasvinder Singh 	}
67793186282fSJasvinder Singh 
67803186282fSJasvinder Singh 	/* Open file */
67813186282fSJasvinder Singh 	f = fopen(file_name, "r");
67823186282fSJasvinder Singh 	if (f == NULL) {
678327b333b2SCristian Dumitrescu 		status = -EIO;
678427b333b2SCristian Dumitrescu 		goto cli_rule_file_process_free;
67853186282fSJasvinder Singh 	}
67863186282fSJasvinder Singh 
67873186282fSJasvinder Singh 	/* Read file */
678827b333b2SCristian Dumitrescu 	for (line_id = 1, rule_id = 0; ; line_id++) {
67893186282fSJasvinder Singh 		char *tokens[CMD_MAX_TOKENS];
679027b333b2SCristian Dumitrescu 		struct table_rule *rule = NULL;
67913186282fSJasvinder Singh 		uint32_t n_tokens, n_tokens_parsed, t0;
67923186282fSJasvinder Singh 
67933186282fSJasvinder Singh 		/* Read next line from file. */
67943186282fSJasvinder Singh 		if (fgets(line, line_len_max + 1, f) == NULL)
67953186282fSJasvinder Singh 			break;
67963186282fSJasvinder Singh 
67973186282fSJasvinder Singh 		/* Comment. */
67983186282fSJasvinder Singh 		if (is_comment(line))
67993186282fSJasvinder Singh 			continue;
68003186282fSJasvinder Singh 
68013186282fSJasvinder Singh 		/* Parse line. */
68023186282fSJasvinder Singh 		n_tokens = RTE_DIM(tokens);
68033186282fSJasvinder Singh 		status = parse_tokenize_string(line, tokens, &n_tokens);
68043186282fSJasvinder Singh 		if (status) {
68053186282fSJasvinder Singh 			status = -EINVAL;
680627b333b2SCristian Dumitrescu 			goto cli_rule_file_process_free;
68073186282fSJasvinder Singh 		}
68083186282fSJasvinder Singh 
68093186282fSJasvinder Singh 		/* Empty line. */
68103186282fSJasvinder Singh 		if (n_tokens == 0)
68113186282fSJasvinder Singh 			continue;
68123186282fSJasvinder Singh 		t0 = 0;
68133186282fSJasvinder Singh 
681427b333b2SCristian Dumitrescu 		/* Rule alloc and insert. */
681527b333b2SCristian Dumitrescu 		rule = calloc(1, sizeof(struct table_rule));
681627b333b2SCristian Dumitrescu 		if (rule == NULL) {
681727b333b2SCristian Dumitrescu 			status = -ENOMEM;
681827b333b2SCristian Dumitrescu 			goto cli_rule_file_process_free;
681927b333b2SCristian Dumitrescu 		}
682027b333b2SCristian Dumitrescu 
682127b333b2SCristian Dumitrescu 		TAILQ_INSERT_TAIL(list, rule, node);
682227b333b2SCristian Dumitrescu 
68233186282fSJasvinder Singh 		/* Rule match. */
68243186282fSJasvinder Singh 		n_tokens_parsed = parse_match(tokens + t0,
68253186282fSJasvinder Singh 			n_tokens - t0,
68263186282fSJasvinder Singh 			out,
68273186282fSJasvinder Singh 			out_size,
682827b333b2SCristian Dumitrescu 			&rule->match);
68293186282fSJasvinder Singh 		if (n_tokens_parsed == 0) {
68303186282fSJasvinder Singh 			status = -EINVAL;
683127b333b2SCristian Dumitrescu 			goto cli_rule_file_process_free;
68323186282fSJasvinder Singh 		}
68333186282fSJasvinder Singh 		t0 += n_tokens_parsed;
68343186282fSJasvinder Singh 
68353186282fSJasvinder Singh 		/* Rule action. */
68363186282fSJasvinder Singh 		n_tokens_parsed = parse_table_action(tokens + t0,
68373186282fSJasvinder Singh 			n_tokens - t0,
68383186282fSJasvinder Singh 			out,
68393186282fSJasvinder Singh 			out_size,
684027b333b2SCristian Dumitrescu 			&rule->action);
68413186282fSJasvinder Singh 		if (n_tokens_parsed == 0) {
68423186282fSJasvinder Singh 			status = -EINVAL;
684327b333b2SCristian Dumitrescu 			goto cli_rule_file_process_free;
68443186282fSJasvinder Singh 		}
68453186282fSJasvinder Singh 		t0 += n_tokens_parsed;
68463186282fSJasvinder Singh 
68473186282fSJasvinder Singh 		/* Line completed. */
68483186282fSJasvinder Singh 		if (t0 < n_tokens) {
68493186282fSJasvinder Singh 			status = -EINVAL;
685027b333b2SCristian Dumitrescu 			goto cli_rule_file_process_free;
68513186282fSJasvinder Singh 		}
68523186282fSJasvinder Singh 
68533186282fSJasvinder Singh 		/* Increment rule count */
68543186282fSJasvinder Singh 		rule_id++;
68553186282fSJasvinder Singh 	}
68563186282fSJasvinder Singh 
68573186282fSJasvinder Singh 	/* Close file */
68583186282fSJasvinder Singh 	fclose(f);
68593186282fSJasvinder Singh 
68603186282fSJasvinder Singh 	/* Memory free */
68613186282fSJasvinder Singh 	free(line);
68623186282fSJasvinder Singh 
686327b333b2SCristian Dumitrescu 	*rule_list = list;
68643186282fSJasvinder Singh 	*n_rules = rule_id;
68653186282fSJasvinder Singh 	*line_number = line_id;
686627b333b2SCristian Dumitrescu 	return 0;
686727b333b2SCristian Dumitrescu 
686827b333b2SCristian Dumitrescu cli_rule_file_process_free:
6869c44ae27aSJasvinder Singh 	if (rule_list != NULL)
687027b333b2SCristian Dumitrescu 		*rule_list = NULL;
6871c44ae27aSJasvinder Singh 
6872c44ae27aSJasvinder Singh 	if (n_rules != NULL)
687327b333b2SCristian Dumitrescu 		*n_rules = rule_id;
6874c44ae27aSJasvinder Singh 
6875c44ae27aSJasvinder Singh 	if (line_number != NULL)
687627b333b2SCristian Dumitrescu 		*line_number = line_id;
687727b333b2SCristian Dumitrescu 
6878c44ae27aSJasvinder Singh 	if (list != NULL)
687927b333b2SCristian Dumitrescu 		for ( ; ; ) {
688027b333b2SCristian Dumitrescu 			struct table_rule *rule;
688127b333b2SCristian Dumitrescu 
688227b333b2SCristian Dumitrescu 			rule = TAILQ_FIRST(list);
688327b333b2SCristian Dumitrescu 			if (rule == NULL)
688427b333b2SCristian Dumitrescu 				break;
688527b333b2SCristian Dumitrescu 
688627b333b2SCristian Dumitrescu 			TAILQ_REMOVE(list, rule, node);
688727b333b2SCristian Dumitrescu 			free(rule);
688827b333b2SCristian Dumitrescu 		}
688927b333b2SCristian Dumitrescu 
689027b333b2SCristian Dumitrescu 	if (f)
689127b333b2SCristian Dumitrescu 		fclose(f);
689227b333b2SCristian Dumitrescu 	free(line);
689327b333b2SCristian Dumitrescu 	free(list);
689427b333b2SCristian Dumitrescu 
68953186282fSJasvinder Singh 	return status;
68963186282fSJasvinder Singh }
6897