xref: /dpdk/examples/ip_pipeline/cli.c (revision 37e33391ee75767310b5ac388278082104caefe7)
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"
17133c2c65SJasvinder Singh #include "link.h"
186bfe74f8SJasvinder Singh #include "mempool.h"
196bfe74f8SJasvinder Singh #include "parser.h"
20d75c371eSJasvinder Singh #include "pipeline.h"
218245472cSJasvinder Singh #include "swq.h"
222f74ae28SJasvinder Singh #include "tap.h"
2332e5d9b1SJasvinder Singh #include "thread.h"
2425961ff3SJasvinder Singh #include "tmgr.h"
256bfe74f8SJasvinder Singh 
266bfe74f8SJasvinder Singh #ifndef CMD_MAX_TOKENS
276bfe74f8SJasvinder Singh #define CMD_MAX_TOKENS     256
286bfe74f8SJasvinder Singh #endif
296bfe74f8SJasvinder Singh 
306bfe74f8SJasvinder Singh #define MSG_OUT_OF_MEMORY   "Not enough memory.\n"
316bfe74f8SJasvinder Singh #define MSG_CMD_UNKNOWN     "Unknown command \"%s\".\n"
326bfe74f8SJasvinder Singh #define MSG_CMD_UNIMPLEM    "Command \"%s\" not implemented.\n"
336bfe74f8SJasvinder Singh #define MSG_ARG_NOT_ENOUGH  "Not enough arguments for command \"%s\".\n"
346bfe74f8SJasvinder Singh #define MSG_ARG_TOO_MANY    "Too many arguments for command \"%s\".\n"
356bfe74f8SJasvinder Singh #define MSG_ARG_MISMATCH    "Wrong number of arguments for command \"%s\".\n"
366bfe74f8SJasvinder Singh #define MSG_ARG_NOT_FOUND   "Argument \"%s\" not found.\n"
376bfe74f8SJasvinder Singh #define MSG_ARG_INVALID     "Invalid value for argument \"%s\".\n"
386bfe74f8SJasvinder Singh #define MSG_FILE_ERR        "Error in file \"%s\" at line %u.\n"
393186282fSJasvinder Singh #define MSG_FILE_NOT_ENOUGH "Not enough rules in file \"%s\".\n"
406bfe74f8SJasvinder Singh #define MSG_CMD_FAIL        "Command \"%s\" failed.\n"
414bbf8e30SJasvinder Singh 
424bbf8e30SJasvinder Singh static int
434bbf8e30SJasvinder Singh is_comment(char *in)
444bbf8e30SJasvinder Singh {
454bbf8e30SJasvinder Singh 	if ((strlen(in) && index("!#%;", in[0])) ||
464bbf8e30SJasvinder Singh 		(strncmp(in, "//", 2) == 0) ||
474bbf8e30SJasvinder Singh 		(strncmp(in, "--", 2) == 0))
484bbf8e30SJasvinder Singh 		return 1;
494bbf8e30SJasvinder Singh 
504bbf8e30SJasvinder Singh 	return 0;
514bbf8e30SJasvinder Singh }
524bbf8e30SJasvinder Singh 
5326b3effeSKevin Laatz static const char cmd_mempool_help[] =
5426b3effeSKevin Laatz "mempool <mempool_name>\n"
5526b3effeSKevin Laatz "   buffer <buffer_size>\n"
5626b3effeSKevin Laatz "   pool <pool_size>\n"
5726b3effeSKevin Laatz "   cache <cache_size>\n"
5826b3effeSKevin Laatz "   cpu <cpu_id>\n";
5926b3effeSKevin Laatz 
606bfe74f8SJasvinder Singh static void
616bfe74f8SJasvinder Singh cmd_mempool(char **tokens,
626bfe74f8SJasvinder Singh 	uint32_t n_tokens,
636bfe74f8SJasvinder Singh 	char *out,
646bfe74f8SJasvinder Singh 	size_t out_size)
654bbf8e30SJasvinder Singh {
666bfe74f8SJasvinder Singh 	struct mempool_params p;
676bfe74f8SJasvinder Singh 	char *name;
686bfe74f8SJasvinder Singh 	struct mempool *mempool;
696bfe74f8SJasvinder Singh 
706bfe74f8SJasvinder Singh 	if (n_tokens != 10) {
716bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
726bfe74f8SJasvinder Singh 		return;
736bfe74f8SJasvinder Singh 	}
746bfe74f8SJasvinder Singh 
756bfe74f8SJasvinder Singh 	name = tokens[1];
766bfe74f8SJasvinder Singh 
776bfe74f8SJasvinder Singh 	if (strcmp(tokens[2], "buffer") != 0) {
786bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buffer");
796bfe74f8SJasvinder Singh 		return;
806bfe74f8SJasvinder Singh 	}
816bfe74f8SJasvinder Singh 
826bfe74f8SJasvinder Singh 	if (parser_read_uint32(&p.buffer_size, tokens[3]) != 0) {
836bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "buffer_size");
846bfe74f8SJasvinder Singh 		return;
856bfe74f8SJasvinder Singh 	}
866bfe74f8SJasvinder Singh 
876bfe74f8SJasvinder Singh 	if (strcmp(tokens[4], "pool") != 0) {
886bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pool");
896bfe74f8SJasvinder Singh 		return;
906bfe74f8SJasvinder Singh 	}
916bfe74f8SJasvinder Singh 
926bfe74f8SJasvinder Singh 	if (parser_read_uint32(&p.pool_size, tokens[5]) != 0) {
936bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "pool_size");
946bfe74f8SJasvinder Singh 		return;
956bfe74f8SJasvinder Singh 	}
966bfe74f8SJasvinder Singh 
976bfe74f8SJasvinder Singh 	if (strcmp(tokens[6], "cache") != 0) {
986bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cache");
996bfe74f8SJasvinder Singh 		return;
1006bfe74f8SJasvinder Singh 	}
1016bfe74f8SJasvinder Singh 
1026bfe74f8SJasvinder Singh 	if (parser_read_uint32(&p.cache_size, tokens[7]) != 0) {
1036bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "cache_size");
1046bfe74f8SJasvinder Singh 		return;
1056bfe74f8SJasvinder Singh 	}
1066bfe74f8SJasvinder Singh 
1076bfe74f8SJasvinder Singh 	if (strcmp(tokens[8], "cpu") != 0) {
1086bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1096bfe74f8SJasvinder Singh 		return;
1106bfe74f8SJasvinder Singh 	}
1116bfe74f8SJasvinder Singh 
1126bfe74f8SJasvinder Singh 	if (parser_read_uint32(&p.cpu_id, tokens[9]) != 0) {
1136bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1146bfe74f8SJasvinder Singh 		return;
1156bfe74f8SJasvinder Singh 	}
1166bfe74f8SJasvinder Singh 
1176bfe74f8SJasvinder Singh 	mempool = mempool_create(name, &p);
1186bfe74f8SJasvinder Singh 	if (mempool == NULL) {
1196bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1206bfe74f8SJasvinder Singh 		return;
1216bfe74f8SJasvinder Singh 	}
1226bfe74f8SJasvinder Singh }
1236bfe74f8SJasvinder Singh 
12426b3effeSKevin Laatz static const char cmd_link_help[] =
12526b3effeSKevin Laatz "link <link_name>\n"
12626b3effeSKevin Laatz "   dev <device_name> | port <port_id>\n"
12726b3effeSKevin Laatz "   rxq <n_queues> <queue_size> <mempool_name>\n"
12826b3effeSKevin Laatz "   txq <n_queues> <queue_size>\n"
12926b3effeSKevin Laatz "   promiscuous on | off\n"
13026b3effeSKevin Laatz "   [rss <qid_0> ... <qid_n>]\n";
13126b3effeSKevin Laatz 
132133c2c65SJasvinder Singh static void
133133c2c65SJasvinder Singh cmd_link(char **tokens,
134133c2c65SJasvinder Singh 	uint32_t n_tokens,
135133c2c65SJasvinder Singh 	char *out,
136133c2c65SJasvinder Singh 	size_t out_size)
137133c2c65SJasvinder Singh {
138133c2c65SJasvinder Singh 	struct link_params p;
139133c2c65SJasvinder Singh 	struct link_params_rss rss;
140133c2c65SJasvinder Singh 	struct link *link;
141133c2c65SJasvinder Singh 	char *name;
142133c2c65SJasvinder Singh 
14384a27d89SFan Zhang 	memset(&p, 0, sizeof(p));
14484a27d89SFan Zhang 
145133c2c65SJasvinder Singh 	if ((n_tokens < 13) || (n_tokens > 14 + LINK_RXQ_RSS_MAX)) {
146133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
147133c2c65SJasvinder Singh 		return;
148133c2c65SJasvinder Singh 	}
149133c2c65SJasvinder Singh 	name = tokens[1];
150133c2c65SJasvinder Singh 
151133c2c65SJasvinder Singh 	if (strcmp(tokens[2], "dev") == 0)
152133c2c65SJasvinder Singh 		p.dev_name = tokens[3];
153133c2c65SJasvinder Singh 	else if (strcmp(tokens[2], "port") == 0) {
154133c2c65SJasvinder Singh 		p.dev_name = NULL;
155133c2c65SJasvinder Singh 
156133c2c65SJasvinder Singh 		if (parser_read_uint16(&p.port_id, tokens[3]) != 0) {
157133c2c65SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
158133c2c65SJasvinder Singh 			return;
159133c2c65SJasvinder Singh 		}
160133c2c65SJasvinder Singh 	} else {
161133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dev or port");
162133c2c65SJasvinder Singh 		return;
163133c2c65SJasvinder Singh 	}
164133c2c65SJasvinder Singh 
165133c2c65SJasvinder Singh 	if (strcmp(tokens[4], "rxq") != 0) {
166133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
167133c2c65SJasvinder Singh 		return;
168133c2c65SJasvinder Singh 	}
169133c2c65SJasvinder Singh 
170133c2c65SJasvinder Singh 	if (parser_read_uint32(&p.rx.n_queues, tokens[5]) != 0) {
171133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
172133c2c65SJasvinder Singh 		return;
173133c2c65SJasvinder Singh 	}
174133c2c65SJasvinder Singh 	if (parser_read_uint32(&p.rx.queue_size, tokens[6]) != 0) {
175133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
176133c2c65SJasvinder Singh 		return;
177133c2c65SJasvinder Singh 	}
178133c2c65SJasvinder Singh 
179133c2c65SJasvinder Singh 	p.rx.mempool_name = tokens[7];
180133c2c65SJasvinder Singh 
181133c2c65SJasvinder Singh 	if (strcmp(tokens[8], "txq") != 0) {
182133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
183133c2c65SJasvinder Singh 		return;
184133c2c65SJasvinder Singh 	}
185133c2c65SJasvinder Singh 
186133c2c65SJasvinder Singh 	if (parser_read_uint32(&p.tx.n_queues, tokens[9]) != 0) {
187133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "n_queues");
188133c2c65SJasvinder Singh 		return;
189133c2c65SJasvinder Singh 	}
190133c2c65SJasvinder Singh 
191133c2c65SJasvinder Singh 	if (parser_read_uint32(&p.tx.queue_size, tokens[10]) != 0) {
192133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "queue_size");
193133c2c65SJasvinder Singh 		return;
194133c2c65SJasvinder Singh 	}
195133c2c65SJasvinder Singh 
196133c2c65SJasvinder Singh 	if (strcmp(tokens[11], "promiscuous") != 0) {
197133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "promiscuous");
198133c2c65SJasvinder Singh 		return;
199133c2c65SJasvinder Singh 	}
200133c2c65SJasvinder Singh 
201133c2c65SJasvinder Singh 	if (strcmp(tokens[12], "on") == 0)
202133c2c65SJasvinder Singh 		p.promiscuous = 1;
203133c2c65SJasvinder Singh 	else if (strcmp(tokens[12], "off") == 0)
204133c2c65SJasvinder Singh 		p.promiscuous = 0;
205133c2c65SJasvinder Singh 	else {
206133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "on or off");
207133c2c65SJasvinder Singh 		return;
208133c2c65SJasvinder Singh 	}
209133c2c65SJasvinder Singh 
210133c2c65SJasvinder Singh 	/* RSS */
211133c2c65SJasvinder Singh 	p.rx.rss = NULL;
212133c2c65SJasvinder Singh 	if (n_tokens > 13) {
213133c2c65SJasvinder Singh 		uint32_t queue_id, i;
214133c2c65SJasvinder Singh 
215133c2c65SJasvinder Singh 		if (strcmp(tokens[13], "rss") != 0) {
216133c2c65SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rss");
217133c2c65SJasvinder Singh 			return;
218133c2c65SJasvinder Singh 		}
219133c2c65SJasvinder Singh 
220133c2c65SJasvinder Singh 		p.rx.rss = &rss;
221133c2c65SJasvinder Singh 
222133c2c65SJasvinder Singh 		rss.n_queues = 0;
223133c2c65SJasvinder Singh 		for (i = 14; i < n_tokens; i++) {
224133c2c65SJasvinder Singh 			if (parser_read_uint32(&queue_id, tokens[i]) != 0) {
225133c2c65SJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
226133c2c65SJasvinder Singh 					"queue_id");
227133c2c65SJasvinder Singh 				return;
228133c2c65SJasvinder Singh 			}
229133c2c65SJasvinder Singh 
230133c2c65SJasvinder Singh 			rss.queue_id[rss.n_queues] = queue_id;
231133c2c65SJasvinder Singh 			rss.n_queues++;
232133c2c65SJasvinder Singh 		}
233133c2c65SJasvinder Singh 	}
234133c2c65SJasvinder Singh 
235133c2c65SJasvinder Singh 	link = link_create(name, &p);
236133c2c65SJasvinder Singh 	if (link == NULL) {
237133c2c65SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
238133c2c65SJasvinder Singh 		return;
239133c2c65SJasvinder Singh 	}
240133c2c65SJasvinder Singh }
241133c2c65SJasvinder Singh 
242ecfc2b1cSKevin Laatz /* Print the link stats and info */
243ecfc2b1cSKevin Laatz static void
244ecfc2b1cSKevin Laatz print_link_info(struct link *link, char *out, size_t out_size)
245ecfc2b1cSKevin Laatz {
246ecfc2b1cSKevin Laatz 	struct rte_eth_stats stats;
2476d13ea8eSOlivier Matz 	struct rte_ether_addr mac_addr;
248ecfc2b1cSKevin Laatz 	struct rte_eth_link eth_link;
249ecfc2b1cSKevin Laatz 	uint16_t mtu;
25022e5c73bSIgor Romanov 	int ret;
251ecfc2b1cSKevin Laatz 
252ecfc2b1cSKevin Laatz 	memset(&stats, 0, sizeof(stats));
253ecfc2b1cSKevin Laatz 	rte_eth_stats_get(link->port_id, &stats);
254ecfc2b1cSKevin Laatz 
25570febdcfSIgor Romanov 	ret = rte_eth_macaddr_get(link->port_id, &mac_addr);
25670febdcfSIgor Romanov 	if (ret != 0) {
25770febdcfSIgor Romanov 		snprintf(out, out_size, "\n%s: MAC address get failed: %s",
25870febdcfSIgor Romanov 			 link->name, rte_strerror(-ret));
25970febdcfSIgor Romanov 		return;
26070febdcfSIgor Romanov 	}
26170febdcfSIgor Romanov 
26222e5c73bSIgor Romanov 	ret = rte_eth_link_get(link->port_id, &eth_link);
26322e5c73bSIgor Romanov 	if (ret < 0) {
26422e5c73bSIgor Romanov 		snprintf(out, out_size, "\n%s: link get failed: %s",
26522e5c73bSIgor Romanov 			 link->name, rte_strerror(-ret));
26622e5c73bSIgor Romanov 		return;
26722e5c73bSIgor Romanov 	}
26822e5c73bSIgor Romanov 
269ecfc2b1cSKevin Laatz 	rte_eth_dev_get_mtu(link->port_id, &mtu);
270ecfc2b1cSKevin Laatz 
271ecfc2b1cSKevin Laatz 	snprintf(out, out_size,
272ecfc2b1cSKevin Laatz 		"\n"
273ecfc2b1cSKevin Laatz 		"%s: flags=<%s> mtu %u\n"
274c2c4f87bSAman Deep Singh 		"\tether " RTE_ETHER_ADDR_PRT_FMT " rxqueues %u txqueues %u\n"
275db4e8135SIvan Dyukov 		"\tport# %u  speed %s\n"
276ecfc2b1cSKevin Laatz 		"\tRX packets %" PRIu64"  bytes %" PRIu64"\n"
277ecfc2b1cSKevin Laatz 		"\tRX errors %" PRIu64"  missed %" PRIu64"  no-mbuf %" PRIu64"\n"
278ecfc2b1cSKevin Laatz 		"\tTX packets %" PRIu64"  bytes %" PRIu64"\n"
279ecfc2b1cSKevin Laatz 		"\tTX errors %" PRIu64"\n",
280ecfc2b1cSKevin Laatz 		link->name,
281ecfc2b1cSKevin Laatz 		eth_link.link_status == 0 ? "DOWN" : "UP",
282ecfc2b1cSKevin Laatz 		mtu,
283a7db3afcSAman Deep Singh 		RTE_ETHER_ADDR_BYTES(&mac_addr),
284ecfc2b1cSKevin Laatz 		link->n_rxq,
285ecfc2b1cSKevin Laatz 		link->n_txq,
286ecfc2b1cSKevin Laatz 		link->port_id,
287db4e8135SIvan Dyukov 		rte_eth_link_speed_to_str(eth_link.link_speed),
288ecfc2b1cSKevin Laatz 		stats.ipackets,
289ecfc2b1cSKevin Laatz 		stats.ibytes,
290ecfc2b1cSKevin Laatz 		stats.ierrors,
291ecfc2b1cSKevin Laatz 		stats.imissed,
292ecfc2b1cSKevin Laatz 		stats.rx_nombuf,
293ecfc2b1cSKevin Laatz 		stats.opackets,
294ecfc2b1cSKevin Laatz 		stats.obytes,
295ecfc2b1cSKevin Laatz 		stats.oerrors);
296ecfc2b1cSKevin Laatz }
297ecfc2b1cSKevin Laatz 
298ecfc2b1cSKevin Laatz /*
299ecfc2b1cSKevin Laatz  * link show [<link_name>]
300ecfc2b1cSKevin Laatz  */
301ecfc2b1cSKevin Laatz static void
302ecfc2b1cSKevin Laatz cmd_link_show(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
303ecfc2b1cSKevin Laatz {
304ecfc2b1cSKevin Laatz 	struct link *link;
305ecfc2b1cSKevin Laatz 	char *link_name;
306ecfc2b1cSKevin Laatz 
307ecfc2b1cSKevin Laatz 	if (n_tokens != 2 && n_tokens != 3) {
308ecfc2b1cSKevin Laatz 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
309ecfc2b1cSKevin Laatz 		return;
310ecfc2b1cSKevin Laatz 	}
311ecfc2b1cSKevin Laatz 
312ecfc2b1cSKevin Laatz 	if (n_tokens == 2) {
313ecfc2b1cSKevin Laatz 		link = link_next(NULL);
314ecfc2b1cSKevin Laatz 
315ecfc2b1cSKevin Laatz 		while (link != NULL) {
316ecfc2b1cSKevin Laatz 			out_size = out_size - strlen(out);
317ecfc2b1cSKevin Laatz 			out = &out[strlen(out)];
318ecfc2b1cSKevin Laatz 
319ecfc2b1cSKevin Laatz 			print_link_info(link, out, out_size);
320ecfc2b1cSKevin Laatz 			link = link_next(link);
321ecfc2b1cSKevin Laatz 		}
322ecfc2b1cSKevin Laatz 	} else {
323ecfc2b1cSKevin Laatz 		out_size = out_size - strlen(out);
324ecfc2b1cSKevin Laatz 		out = &out[strlen(out)];
325ecfc2b1cSKevin Laatz 
326ecfc2b1cSKevin Laatz 		link_name = tokens[2];
327ecfc2b1cSKevin Laatz 		link = link_find(link_name);
328ecfc2b1cSKevin Laatz 
329ecfc2b1cSKevin Laatz 		if (link == NULL) {
330ecfc2b1cSKevin Laatz 			snprintf(out, out_size, MSG_ARG_INVALID,
331ecfc2b1cSKevin Laatz 					"Link does not exist");
332ecfc2b1cSKevin Laatz 			return;
333ecfc2b1cSKevin Laatz 		}
334ecfc2b1cSKevin Laatz 		print_link_info(link, out, out_size);
335ecfc2b1cSKevin Laatz 	}
336ecfc2b1cSKevin Laatz }
337ecfc2b1cSKevin Laatz 
33826b3effeSKevin Laatz static const char cmd_swq_help[] =
33926b3effeSKevin Laatz "swq <swq_name>\n"
34026b3effeSKevin Laatz "   size <size>\n"
34126b3effeSKevin Laatz "   cpu <cpu_id>\n";
34226b3effeSKevin Laatz 
3438245472cSJasvinder Singh static void
3448245472cSJasvinder Singh cmd_swq(char **tokens,
3458245472cSJasvinder Singh 	uint32_t n_tokens,
3468245472cSJasvinder Singh 	char *out,
3478245472cSJasvinder Singh 	size_t out_size)
3488245472cSJasvinder Singh {
3498245472cSJasvinder Singh 	struct swq_params p;
3508245472cSJasvinder Singh 	char *name;
3518245472cSJasvinder Singh 	struct swq *swq;
3528245472cSJasvinder Singh 
3538245472cSJasvinder Singh 	if (n_tokens != 6) {
3548245472cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
3558245472cSJasvinder Singh 		return;
3568245472cSJasvinder Singh 	}
3578245472cSJasvinder Singh 
3588245472cSJasvinder Singh 	name = tokens[1];
3598245472cSJasvinder Singh 
3608245472cSJasvinder Singh 	if (strcmp(tokens[2], "size") != 0) {
3618245472cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
3628245472cSJasvinder Singh 		return;
3638245472cSJasvinder Singh 	}
3648245472cSJasvinder Singh 
3658245472cSJasvinder Singh 	if (parser_read_uint32(&p.size, tokens[3]) != 0) {
3668245472cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "size");
3678245472cSJasvinder Singh 		return;
3688245472cSJasvinder Singh 	}
3698245472cSJasvinder Singh 
3708245472cSJasvinder Singh 	if (strcmp(tokens[4], "cpu") != 0) {
3718245472cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
3728245472cSJasvinder Singh 		return;
3738245472cSJasvinder Singh 	}
3748245472cSJasvinder Singh 
3758245472cSJasvinder Singh 	if (parser_read_uint32(&p.cpu_id, tokens[5]) != 0) {
3768245472cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
3778245472cSJasvinder Singh 		return;
3788245472cSJasvinder Singh 	}
3798245472cSJasvinder Singh 
3808245472cSJasvinder Singh 	swq = swq_create(name, &p);
3818245472cSJasvinder Singh 	if (swq == NULL) {
3828245472cSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
3838245472cSJasvinder Singh 		return;
3848245472cSJasvinder Singh 	}
3858245472cSJasvinder Singh }
3868245472cSJasvinder Singh 
38726b3effeSKevin Laatz static const char cmd_tmgr_subport_profile_help[] =
38826b3effeSKevin Laatz "tmgr subport profile\n"
38926b3effeSKevin Laatz "   <tb_rate> <tb_size>\n"
3903f2eaa4cSJasvinder Singh "   <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
3913f2eaa4cSJasvinder Singh "        <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
3923f2eaa4cSJasvinder Singh "        <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
39354a298e5SSavinay Dharmappa "   <tc_period>\n";
39426b3effeSKevin Laatz 
39525961ff3SJasvinder Singh static void
39625961ff3SJasvinder Singh cmd_tmgr_subport_profile(char **tokens,
39725961ff3SJasvinder Singh 	uint32_t n_tokens,
39825961ff3SJasvinder Singh 	char *out,
39925961ff3SJasvinder Singh 	size_t out_size)
40025961ff3SJasvinder Singh {
40154a298e5SSavinay Dharmappa 	struct rte_sched_subport_profile_params subport_profile;
40225961ff3SJasvinder Singh 	int status, i;
40325961ff3SJasvinder Singh 
40454a298e5SSavinay Dharmappa 	if (n_tokens != 19) {
40525961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
40625961ff3SJasvinder Singh 		return;
40725961ff3SJasvinder Singh 	}
40825961ff3SJasvinder Singh 
40954a298e5SSavinay Dharmappa 	if (parser_read_uint64(&subport_profile.tb_rate, tokens[3]) != 0) {
41025961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
41125961ff3SJasvinder Singh 		return;
41225961ff3SJasvinder Singh 	}
41325961ff3SJasvinder Singh 
41454a298e5SSavinay Dharmappa 	if (parser_read_uint64(&subport_profile.tb_size, tokens[4]) != 0) {
41525961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
41625961ff3SJasvinder Singh 		return;
41725961ff3SJasvinder Singh 	}
41825961ff3SJasvinder Singh 
41925961ff3SJasvinder Singh 	for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
42054a298e5SSavinay Dharmappa 		if (parser_read_uint64(&subport_profile.tc_rate[i],
42154a298e5SSavinay Dharmappa 				tokens[5 + i]) != 0) {
42225961ff3SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
42325961ff3SJasvinder Singh 			return;
42425961ff3SJasvinder Singh 		}
42525961ff3SJasvinder Singh 
42654a298e5SSavinay Dharmappa 	if (parser_read_uint64(&subport_profile.tc_period, tokens[18]) != 0) {
42725961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
42825961ff3SJasvinder Singh 		return;
42925961ff3SJasvinder Singh 	}
43025961ff3SJasvinder Singh 
43154a298e5SSavinay Dharmappa 	status = tmgr_subport_profile_add(&subport_profile);
43225961ff3SJasvinder Singh 	if (status != 0) {
43325961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
43425961ff3SJasvinder Singh 		return;
43525961ff3SJasvinder Singh 	}
43625961ff3SJasvinder Singh }
43725961ff3SJasvinder Singh 
43826b3effeSKevin Laatz static const char cmd_tmgr_pipe_profile_help[] =
43926b3effeSKevin Laatz "tmgr pipe profile\n"
44026b3effeSKevin Laatz "   <tb_rate> <tb_size>\n"
4413f2eaa4cSJasvinder Singh "   <tc0_rate> <tc1_rate> <tc2_rate> <tc3_rate> <tc4_rate>"
4423f2eaa4cSJasvinder Singh "     <tc5_rate> <tc6_rate> <tc7_rate> <tc8_rate>"
4433f2eaa4cSJasvinder Singh "     <tc9_rate> <tc10_rate> <tc11_rate> <tc12_rate>\n"
44426b3effeSKevin Laatz "   <tc_period>\n"
44526b3effeSKevin Laatz "   <tc_ov_weight>\n"
4463f2eaa4cSJasvinder Singh "   <wrr_weight0..3>\n";
44726b3effeSKevin Laatz 
44825961ff3SJasvinder Singh static void
44925961ff3SJasvinder Singh cmd_tmgr_pipe_profile(char **tokens,
45025961ff3SJasvinder Singh 	uint32_t n_tokens,
45125961ff3SJasvinder Singh 	char *out,
45225961ff3SJasvinder Singh 	size_t out_size)
45325961ff3SJasvinder Singh {
45425961ff3SJasvinder Singh 	struct rte_sched_pipe_params p;
45525961ff3SJasvinder Singh 	int status, i;
45625961ff3SJasvinder Singh 
4573f2eaa4cSJasvinder Singh 	if (n_tokens != 24) {
45825961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
45925961ff3SJasvinder Singh 		return;
46025961ff3SJasvinder Singh 	}
46125961ff3SJasvinder Singh 
4620edf18eeSJasvinder Singh 	if (parser_read_uint64(&p.tb_rate, tokens[3]) != 0) {
46325961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tb_rate");
46425961ff3SJasvinder Singh 		return;
46525961ff3SJasvinder Singh 	}
46625961ff3SJasvinder Singh 
4670edf18eeSJasvinder Singh 	if (parser_read_uint64(&p.tb_size, tokens[4]) != 0) {
46825961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tb_size");
46925961ff3SJasvinder Singh 		return;
47025961ff3SJasvinder Singh 	}
47125961ff3SJasvinder Singh 
47225961ff3SJasvinder Singh 	for (i = 0; i < RTE_SCHED_TRAFFIC_CLASSES_PER_PIPE; i++)
4730edf18eeSJasvinder Singh 		if (parser_read_uint64(&p.tc_rate[i], tokens[5 + i]) != 0) {
47425961ff3SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "tc_rate");
47525961ff3SJasvinder Singh 			return;
47625961ff3SJasvinder Singh 		}
47725961ff3SJasvinder Singh 
4780edf18eeSJasvinder Singh 	if (parser_read_uint64(&p.tc_period, tokens[18]) != 0) {
47925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tc_period");
48025961ff3SJasvinder Singh 		return;
48125961ff3SJasvinder Singh 	}
48225961ff3SJasvinder Singh 
4833f2eaa4cSJasvinder Singh 	if (parser_read_uint8(&p.tc_ov_weight, tokens[19]) != 0) {
48425961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "tc_ov_weight");
48525961ff3SJasvinder Singh 		return;
48625961ff3SJasvinder Singh 	}
48725961ff3SJasvinder Singh 
4883f2eaa4cSJasvinder Singh 	for (i = 0; i < RTE_SCHED_BE_QUEUES_PER_PIPE; i++)
4893f2eaa4cSJasvinder Singh 		if (parser_read_uint8(&p.wrr_weights[i], tokens[20 + i]) != 0) {
49025961ff3SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "wrr_weights");
49125961ff3SJasvinder Singh 			return;
49225961ff3SJasvinder Singh 		}
49325961ff3SJasvinder Singh 
49425961ff3SJasvinder Singh 	status = tmgr_pipe_profile_add(&p);
49525961ff3SJasvinder Singh 	if (status != 0) {
49625961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
49725961ff3SJasvinder Singh 		return;
49825961ff3SJasvinder Singh 	}
49925961ff3SJasvinder Singh }
50025961ff3SJasvinder Singh 
50126b3effeSKevin Laatz static const char cmd_tmgr_help[] =
50226b3effeSKevin Laatz "tmgr <tmgr_name>\n"
50326b3effeSKevin Laatz "   rate <rate>\n"
50426b3effeSKevin Laatz "   spp <n_subports_per_port>\n"
50554a298e5SSavinay Dharmappa "   pps <n_pipes_per_subport>\n"
50626b3effeSKevin Laatz "   fo <frame_overhead>\n"
50726b3effeSKevin Laatz "   mtu <mtu>\n"
50826b3effeSKevin Laatz "   cpu <cpu_id>\n";
50926b3effeSKevin Laatz 
51025961ff3SJasvinder Singh static void
51125961ff3SJasvinder Singh cmd_tmgr(char **tokens,
51225961ff3SJasvinder Singh 	uint32_t n_tokens,
51325961ff3SJasvinder Singh 	char *out,
51425961ff3SJasvinder Singh 	size_t out_size)
51525961ff3SJasvinder Singh {
51625961ff3SJasvinder Singh 	struct tmgr_port_params p;
51725961ff3SJasvinder Singh 	char *name;
51825961ff3SJasvinder Singh 	struct tmgr_port *tmgr_port;
51925961ff3SJasvinder Singh 
52054a298e5SSavinay Dharmappa 	if (n_tokens != 14) {
52125961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
52225961ff3SJasvinder Singh 		return;
52325961ff3SJasvinder Singh 	}
52425961ff3SJasvinder Singh 
52525961ff3SJasvinder Singh 	name = tokens[1];
52625961ff3SJasvinder Singh 
52725961ff3SJasvinder Singh 	if (strcmp(tokens[2], "rate") != 0) {
52825961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rate");
52925961ff3SJasvinder Singh 		return;
53025961ff3SJasvinder Singh 	}
53125961ff3SJasvinder Singh 
5320edf18eeSJasvinder Singh 	if (parser_read_uint64(&p.rate, tokens[3]) != 0) {
53325961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "rate");
53425961ff3SJasvinder Singh 		return;
53525961ff3SJasvinder Singh 	}
53625961ff3SJasvinder Singh 
53725961ff3SJasvinder Singh 	if (strcmp(tokens[4], "spp") != 0) {
53825961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
53925961ff3SJasvinder Singh 		return;
54025961ff3SJasvinder Singh 	}
54125961ff3SJasvinder Singh 
54225961ff3SJasvinder Singh 	if (parser_read_uint32(&p.n_subports_per_port, tokens[5]) != 0) {
54325961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "n_subports_per_port");
54425961ff3SJasvinder Singh 		return;
54525961ff3SJasvinder Singh 	}
54625961ff3SJasvinder Singh 
54754a298e5SSavinay Dharmappa 	if (strcmp(tokens[6], "pps") != 0) {
54854a298e5SSavinay Dharmappa 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
54954a298e5SSavinay Dharmappa 		return;
55054a298e5SSavinay Dharmappa 	}
55154a298e5SSavinay Dharmappa 
55254a298e5SSavinay Dharmappa 	if (parser_read_uint32(&p.n_pipes_per_subport, tokens[7]) != 0) {
55354a298e5SSavinay Dharmappa 		snprintf(out, out_size, MSG_ARG_INVALID, "n_pipes_per_subport");
55454a298e5SSavinay Dharmappa 		return;
55554a298e5SSavinay Dharmappa 	}
55654a298e5SSavinay Dharmappa 
55754a298e5SSavinay Dharmappa 	if (strcmp(tokens[8], "fo") != 0) {
55825961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fo");
55925961ff3SJasvinder Singh 		return;
56025961ff3SJasvinder Singh 	}
56125961ff3SJasvinder Singh 
56254a298e5SSavinay Dharmappa 	if (parser_read_uint32(&p.frame_overhead, tokens[9]) != 0) {
56325961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "frame_overhead");
56425961ff3SJasvinder Singh 		return;
56525961ff3SJasvinder Singh 	}
56625961ff3SJasvinder Singh 
56754a298e5SSavinay Dharmappa 	if (strcmp(tokens[10], "mtu") != 0) {
56825961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mtu");
56925961ff3SJasvinder Singh 		return;
57025961ff3SJasvinder Singh 	}
57125961ff3SJasvinder Singh 
57254a298e5SSavinay Dharmappa 	if (parser_read_uint32(&p.mtu, tokens[11]) != 0) {
57325961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
57425961ff3SJasvinder Singh 		return;
57525961ff3SJasvinder Singh 	}
57625961ff3SJasvinder Singh 
57754a298e5SSavinay Dharmappa 	if (strcmp(tokens[12], "cpu") != 0) {
57825961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
57925961ff3SJasvinder Singh 		return;
58025961ff3SJasvinder Singh 	}
58125961ff3SJasvinder Singh 
58254a298e5SSavinay Dharmappa 	if (parser_read_uint32(&p.cpu_id, tokens[13]) != 0) {
58325961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
58425961ff3SJasvinder Singh 		return;
58525961ff3SJasvinder Singh 	}
58625961ff3SJasvinder Singh 
58725961ff3SJasvinder Singh 	tmgr_port = tmgr_port_create(name, &p);
58825961ff3SJasvinder Singh 	if (tmgr_port == NULL) {
58925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
59025961ff3SJasvinder Singh 		return;
59125961ff3SJasvinder Singh 	}
59225961ff3SJasvinder Singh }
59325961ff3SJasvinder Singh 
59426b3effeSKevin Laatz static const char cmd_tmgr_subport_help[] =
59526b3effeSKevin Laatz "tmgr <tmgr_name> subport <subport_id>\n"
59626b3effeSKevin Laatz "   profile <subport_profile_id>\n";
59726b3effeSKevin Laatz 
59825961ff3SJasvinder Singh static void
59925961ff3SJasvinder Singh cmd_tmgr_subport(char **tokens,
60025961ff3SJasvinder Singh 	uint32_t n_tokens,
60125961ff3SJasvinder Singh 	char *out,
60225961ff3SJasvinder Singh 	size_t out_size)
60325961ff3SJasvinder Singh {
60425961ff3SJasvinder Singh 	uint32_t subport_id, subport_profile_id;
60525961ff3SJasvinder Singh 	int status;
60625961ff3SJasvinder Singh 	char *name;
60725961ff3SJasvinder Singh 
60825961ff3SJasvinder Singh 	if (n_tokens != 6) {
60925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
61025961ff3SJasvinder Singh 		return;
61125961ff3SJasvinder Singh 	}
61225961ff3SJasvinder Singh 
61325961ff3SJasvinder Singh 	name = tokens[1];
61425961ff3SJasvinder Singh 
61525961ff3SJasvinder Singh 	if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
61625961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
61725961ff3SJasvinder Singh 		return;
61825961ff3SJasvinder Singh 	}
61925961ff3SJasvinder Singh 
62025961ff3SJasvinder Singh 	if (parser_read_uint32(&subport_profile_id, tokens[5]) != 0) {
62125961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "subport_profile_id");
62225961ff3SJasvinder Singh 		return;
62325961ff3SJasvinder Singh 	}
62425961ff3SJasvinder Singh 
62525961ff3SJasvinder Singh 	status = tmgr_subport_config(name, subport_id, subport_profile_id);
62625961ff3SJasvinder Singh 	if (status) {
62725961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
62825961ff3SJasvinder Singh 		return;
62925961ff3SJasvinder Singh 	}
63025961ff3SJasvinder Singh }
63125961ff3SJasvinder Singh 
63226b3effeSKevin Laatz 
63326b3effeSKevin Laatz static const char cmd_tmgr_subport_pipe_help[] =
63426b3effeSKevin Laatz "tmgr <tmgr_name> subport <subport_id> pipe\n"
63526b3effeSKevin Laatz "   from <pipe_id_first> to <pipe_id_last>\n"
63626b3effeSKevin Laatz "   profile <pipe_profile_id>\n";
63726b3effeSKevin Laatz 
63825961ff3SJasvinder Singh static void
63925961ff3SJasvinder Singh cmd_tmgr_subport_pipe(char **tokens,
64025961ff3SJasvinder Singh 	uint32_t n_tokens,
64125961ff3SJasvinder Singh 	char *out,
64225961ff3SJasvinder Singh 	size_t out_size)
64325961ff3SJasvinder Singh {
64425961ff3SJasvinder Singh 	uint32_t subport_id, pipe_id_first, pipe_id_last, pipe_profile_id;
64525961ff3SJasvinder Singh 	int status;
64625961ff3SJasvinder Singh 	char *name;
64725961ff3SJasvinder Singh 
64825961ff3SJasvinder Singh 	if (n_tokens != 11) {
64925961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
65025961ff3SJasvinder Singh 		return;
65125961ff3SJasvinder Singh 	}
65225961ff3SJasvinder Singh 
65325961ff3SJasvinder Singh 	name = tokens[1];
65425961ff3SJasvinder Singh 
65525961ff3SJasvinder Singh 	if (parser_read_uint32(&subport_id, tokens[3]) != 0) {
65625961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "subport_id");
65725961ff3SJasvinder Singh 		return;
65825961ff3SJasvinder Singh 	}
65925961ff3SJasvinder Singh 
66025961ff3SJasvinder Singh 	if (strcmp(tokens[4], "pipe") != 0) {
66125961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipe");
66225961ff3SJasvinder Singh 		return;
66325961ff3SJasvinder Singh 	}
66425961ff3SJasvinder Singh 
66525961ff3SJasvinder Singh 	if (strcmp(tokens[5], "from") != 0) {
66625961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "from");
66725961ff3SJasvinder Singh 		return;
66825961ff3SJasvinder Singh 	}
66925961ff3SJasvinder Singh 
67025961ff3SJasvinder Singh 	if (parser_read_uint32(&pipe_id_first, tokens[6]) != 0) {
67125961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_first");
67225961ff3SJasvinder Singh 		return;
67325961ff3SJasvinder Singh 	}
67425961ff3SJasvinder Singh 
67525961ff3SJasvinder Singh 	if (strcmp(tokens[7], "to") != 0) {
67625961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "to");
67725961ff3SJasvinder Singh 		return;
67825961ff3SJasvinder Singh 	}
67925961ff3SJasvinder Singh 
68025961ff3SJasvinder Singh 	if (parser_read_uint32(&pipe_id_last, tokens[8]) != 0) {
68125961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "pipe_id_last");
68225961ff3SJasvinder Singh 		return;
68325961ff3SJasvinder Singh 	}
68425961ff3SJasvinder Singh 
68525961ff3SJasvinder Singh 	if (strcmp(tokens[9], "profile") != 0) {
68625961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
68725961ff3SJasvinder Singh 		return;
68825961ff3SJasvinder Singh 	}
68925961ff3SJasvinder Singh 
69025961ff3SJasvinder Singh 	if (parser_read_uint32(&pipe_profile_id, tokens[10]) != 0) {
69125961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "pipe_profile_id");
69225961ff3SJasvinder Singh 		return;
69325961ff3SJasvinder Singh 	}
69425961ff3SJasvinder Singh 
69525961ff3SJasvinder Singh 	status = tmgr_pipe_config(name, subport_id, pipe_id_first,
69625961ff3SJasvinder Singh 			pipe_id_last, pipe_profile_id);
69725961ff3SJasvinder Singh 	if (status) {
69825961ff3SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
69925961ff3SJasvinder Singh 		return;
70025961ff3SJasvinder Singh 	}
70125961ff3SJasvinder Singh }
70225961ff3SJasvinder Singh 
70326b3effeSKevin Laatz 
70426b3effeSKevin Laatz static const char cmd_tap_help[] =
70526b3effeSKevin Laatz "tap <tap_name>\n";
70626b3effeSKevin Laatz 
7072f74ae28SJasvinder Singh static void
7082f74ae28SJasvinder Singh cmd_tap(char **tokens,
7092f74ae28SJasvinder Singh 	uint32_t n_tokens,
7102f74ae28SJasvinder Singh 	char *out,
7112f74ae28SJasvinder Singh 	size_t out_size)
7122f74ae28SJasvinder Singh {
7132f74ae28SJasvinder Singh 	char *name;
7142f74ae28SJasvinder Singh 	struct tap *tap;
7152f74ae28SJasvinder Singh 
7162f74ae28SJasvinder Singh 	if (n_tokens != 2) {
7172f74ae28SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
7182f74ae28SJasvinder Singh 		return;
7192f74ae28SJasvinder Singh 	}
7202f74ae28SJasvinder Singh 
7212f74ae28SJasvinder Singh 	name = tokens[1];
7222f74ae28SJasvinder Singh 
7232f74ae28SJasvinder Singh 	tap = tap_create(name);
7242f74ae28SJasvinder Singh 	if (tap == NULL) {
7252f74ae28SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
7262f74ae28SJasvinder Singh 		return;
7272f74ae28SJasvinder Singh 	}
7282f74ae28SJasvinder Singh }
7292f74ae28SJasvinder Singh 
7309a408cc8SJasvinder Singh 
7311edccebcSFan Zhang static const char cmd_cryptodev_help[] =
7321edccebcSFan Zhang "cryptodev <cryptodev_name>\n"
7331edccebcSFan Zhang "   dev <device_name> | dev_id <device_id>\n"
734261bbff7SFan Zhang "   queue <n_queues> <queue_size>\n"
735261bbff7SFan Zhang "   max_sessions <n_sessions>";
7361edccebcSFan Zhang 
7371edccebcSFan Zhang static void
7381edccebcSFan Zhang cmd_cryptodev(char **tokens,
7391edccebcSFan Zhang 	uint32_t n_tokens,
7401edccebcSFan Zhang 	char *out,
7411edccebcSFan Zhang 	size_t out_size)
7421edccebcSFan Zhang {
7431edccebcSFan Zhang 	struct cryptodev_params params;
7441edccebcSFan Zhang 	char *name;
7451edccebcSFan Zhang 
7461edccebcSFan Zhang 	memset(&params, 0, sizeof(params));
747261bbff7SFan Zhang 	if (n_tokens != 9) {
7481edccebcSFan Zhang 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
7491edccebcSFan Zhang 		return;
7501edccebcSFan Zhang 	}
7511edccebcSFan Zhang 
7521edccebcSFan Zhang 	name = tokens[1];
7531edccebcSFan Zhang 
7541edccebcSFan Zhang 	if (strcmp(tokens[2], "dev") == 0)
7551edccebcSFan Zhang 		params.dev_name = tokens[3];
7561edccebcSFan Zhang 	else if (strcmp(tokens[2], "dev_id") == 0) {
7571edccebcSFan Zhang 		if (parser_read_uint32(&params.dev_id, tokens[3]) < 0) {
7581edccebcSFan Zhang 			snprintf(out, out_size,	MSG_ARG_INVALID,
7591edccebcSFan Zhang 				"dev_id");
7601edccebcSFan Zhang 			return;
7611edccebcSFan Zhang 		}
7621edccebcSFan Zhang 	} else {
7631edccebcSFan Zhang 		snprintf(out, out_size,	MSG_ARG_INVALID,
7641edccebcSFan Zhang 			"cryptodev");
7651edccebcSFan Zhang 		return;
7661edccebcSFan Zhang 	}
7671edccebcSFan Zhang 
7681edccebcSFan Zhang 	if (strcmp(tokens[4], "queue")) {
7691edccebcSFan Zhang 		snprintf(out, out_size,	MSG_ARG_NOT_FOUND,
770261bbff7SFan Zhang 			"queue");
7711edccebcSFan Zhang 		return;
7721edccebcSFan Zhang 	}
7731edccebcSFan Zhang 
7741edccebcSFan Zhang 	if (parser_read_uint32(&params.n_queues, tokens[5]) < 0) {
7751edccebcSFan Zhang 		snprintf(out, out_size,	MSG_ARG_INVALID,
7761edccebcSFan Zhang 			"q");
7771edccebcSFan Zhang 		return;
7781edccebcSFan Zhang 	}
7791edccebcSFan Zhang 
7801edccebcSFan Zhang 	if (parser_read_uint32(&params.queue_size, tokens[6]) < 0) {
7811edccebcSFan Zhang 		snprintf(out, out_size,	MSG_ARG_INVALID,
7821edccebcSFan Zhang 			"queue_size");
7831edccebcSFan Zhang 		return;
7841edccebcSFan Zhang 	}
7851edccebcSFan Zhang 
786261bbff7SFan Zhang 	if (strcmp(tokens[7], "max_sessions")) {
787261bbff7SFan Zhang 		snprintf(out, out_size,	MSG_ARG_NOT_FOUND,
788261bbff7SFan Zhang 			"max_sessions");
789261bbff7SFan Zhang 		return;
790261bbff7SFan Zhang 	}
791261bbff7SFan Zhang 
792261bbff7SFan Zhang 	if (parser_read_uint32(&params.session_pool_size, tokens[8]) < 0) {
793261bbff7SFan Zhang 		snprintf(out, out_size,	MSG_ARG_INVALID,
794261bbff7SFan Zhang 			"queue_size");
795261bbff7SFan Zhang 		return;
796261bbff7SFan Zhang 	}
797261bbff7SFan Zhang 
7981edccebcSFan Zhang 	if (cryptodev_create(name, &params) == NULL) {
7991edccebcSFan Zhang 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
8001edccebcSFan Zhang 		return;
8011edccebcSFan Zhang 	}
8021edccebcSFan Zhang }
80326b3effeSKevin Laatz 
80426b3effeSKevin Laatz static const char cmd_port_in_action_profile_help[] =
80526b3effeSKevin Laatz "port in action profile <profile_name>\n"
80626b3effeSKevin Laatz "   [filter match | mismatch offset <key_offset> mask <key_mask> key <key_value> port <port_id>]\n"
80726b3effeSKevin Laatz "   [balance offset <key_offset> mask <key_mask> port <port_id0> ... <port_id15>]\n";
80826b3effeSKevin Laatz 
80971937434SJasvinder Singh static void
81071937434SJasvinder Singh cmd_port_in_action_profile(char **tokens,
81171937434SJasvinder Singh 	uint32_t n_tokens,
81271937434SJasvinder Singh 	char *out,
81371937434SJasvinder Singh 	size_t out_size)
81471937434SJasvinder Singh {
81571937434SJasvinder Singh 	struct port_in_action_profile_params p;
81671937434SJasvinder Singh 	struct port_in_action_profile *ap;
81771937434SJasvinder Singh 	char *name;
81871937434SJasvinder Singh 	uint32_t t0;
81971937434SJasvinder Singh 
82071937434SJasvinder Singh 	memset(&p, 0, sizeof(p));
82171937434SJasvinder Singh 
82271937434SJasvinder Singh 	if (n_tokens < 5) {
82371937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
82471937434SJasvinder Singh 		return;
82571937434SJasvinder Singh 	}
82671937434SJasvinder Singh 
82771937434SJasvinder Singh 	if (strcmp(tokens[1], "in") != 0) {
82871937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
82971937434SJasvinder Singh 		return;
83071937434SJasvinder Singh 	}
83171937434SJasvinder Singh 
83271937434SJasvinder Singh 	if (strcmp(tokens[2], "action") != 0) {
83371937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
83471937434SJasvinder Singh 		return;
83571937434SJasvinder Singh 	}
83671937434SJasvinder Singh 
83771937434SJasvinder Singh 	if (strcmp(tokens[3], "profile") != 0) {
83871937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
83971937434SJasvinder Singh 		return;
84071937434SJasvinder Singh 	}
84171937434SJasvinder Singh 
84271937434SJasvinder Singh 	name = tokens[4];
84371937434SJasvinder Singh 
84471937434SJasvinder Singh 	t0 = 5;
84571937434SJasvinder Singh 
84671937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "filter") == 0)) {
84771937434SJasvinder Singh 		uint32_t size;
84871937434SJasvinder Singh 
84971937434SJasvinder Singh 		if (n_tokens < t0 + 10) {
85071937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, "port in action profile filter");
85171937434SJasvinder Singh 			return;
85271937434SJasvinder Singh 		}
85371937434SJasvinder Singh 
85471937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "match") == 0)
85571937434SJasvinder Singh 			p.fltr.filter_on_match = 1;
85671937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "mismatch") == 0)
85771937434SJasvinder Singh 			p.fltr.filter_on_match = 0;
85871937434SJasvinder Singh 		else {
85971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "match or mismatch");
86071937434SJasvinder Singh 			return;
86171937434SJasvinder Singh 		}
86271937434SJasvinder Singh 
86371937434SJasvinder Singh 		if (strcmp(tokens[t0 + 2], "offset") != 0) {
86471937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
86571937434SJasvinder Singh 			return;
86671937434SJasvinder Singh 		}
86771937434SJasvinder Singh 
86871937434SJasvinder Singh 		if (parser_read_uint32(&p.fltr.key_offset, tokens[t0 + 3]) != 0) {
86971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
87071937434SJasvinder Singh 			return;
87171937434SJasvinder Singh 		}
87271937434SJasvinder Singh 
87371937434SJasvinder Singh 		if (strcmp(tokens[t0 + 4], "mask") != 0) {
87471937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
87571937434SJasvinder Singh 			return;
87671937434SJasvinder Singh 		}
87771937434SJasvinder Singh 
87871937434SJasvinder Singh 		size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
87971937434SJasvinder Singh 		if ((parse_hex_string(tokens[t0 + 5], p.fltr.key_mask, &size) != 0) ||
88071937434SJasvinder Singh 			(size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
88171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
88271937434SJasvinder Singh 			return;
88371937434SJasvinder Singh 		}
88471937434SJasvinder Singh 
88571937434SJasvinder Singh 		if (strcmp(tokens[t0 + 6], "key") != 0) {
88671937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
88771937434SJasvinder Singh 			return;
88871937434SJasvinder Singh 		}
88971937434SJasvinder Singh 
89071937434SJasvinder Singh 		size = RTE_PORT_IN_ACTION_FLTR_KEY_SIZE;
89171937434SJasvinder Singh 		if ((parse_hex_string(tokens[t0 + 7], p.fltr.key, &size) != 0) ||
89271937434SJasvinder Singh 			(size != RTE_PORT_IN_ACTION_FLTR_KEY_SIZE)) {
89371937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_value");
89471937434SJasvinder Singh 			return;
89571937434SJasvinder Singh 		}
89671937434SJasvinder Singh 
89771937434SJasvinder Singh 		if (strcmp(tokens[t0 + 8], "port") != 0) {
89871937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
89971937434SJasvinder Singh 			return;
90071937434SJasvinder Singh 		}
90171937434SJasvinder Singh 
90271937434SJasvinder Singh 		if (parser_read_uint32(&p.fltr.port_id, tokens[t0 + 9]) != 0) {
90371937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
90471937434SJasvinder Singh 			return;
90571937434SJasvinder Singh 		}
90671937434SJasvinder Singh 
90771937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_FLTR;
90871937434SJasvinder Singh 		t0 += 10;
90971937434SJasvinder Singh 	} /* filter */
91071937434SJasvinder Singh 
91171937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
91271937434SJasvinder Singh 		uint32_t i;
91371937434SJasvinder Singh 
91471937434SJasvinder Singh 		if (n_tokens < t0 + 22) {
915802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
916802755dcSJasvinder Singh 				"port in action profile balance");
91771937434SJasvinder Singh 			return;
91871937434SJasvinder Singh 		}
91971937434SJasvinder Singh 
92071937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "offset") != 0) {
92171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
92271937434SJasvinder Singh 			return;
92371937434SJasvinder Singh 		}
92471937434SJasvinder Singh 
92571937434SJasvinder Singh 		if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
92671937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
92771937434SJasvinder Singh 			return;
92871937434SJasvinder Singh 		}
92971937434SJasvinder Singh 
93071937434SJasvinder Singh 		if (strcmp(tokens[t0 + 3], "mask") != 0) {
93171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
93271937434SJasvinder Singh 			return;
93371937434SJasvinder Singh 		}
93471937434SJasvinder Singh 
93571937434SJasvinder Singh 		p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
93671937434SJasvinder Singh 		if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
93771937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
93871937434SJasvinder Singh 			return;
93971937434SJasvinder Singh 		}
94071937434SJasvinder Singh 
94171937434SJasvinder Singh 		if (strcmp(tokens[t0 + 5], "port") != 0) {
94271937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
94371937434SJasvinder Singh 			return;
94471937434SJasvinder Singh 		}
94571937434SJasvinder Singh 
94671937434SJasvinder Singh 		for (i = 0; i < 16; i++)
94771937434SJasvinder Singh 			if (parser_read_uint32(&p.lb.port_id[i], tokens[t0 + 6 + i]) != 0) {
94871937434SJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
94971937434SJasvinder Singh 				return;
95071937434SJasvinder Singh 			}
95171937434SJasvinder Singh 
95271937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_PORT_IN_ACTION_LB;
95371937434SJasvinder Singh 		t0 += 22;
95471937434SJasvinder Singh 	} /* balance */
95571937434SJasvinder Singh 
95671937434SJasvinder Singh 	if (t0 < n_tokens) {
95771937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
95871937434SJasvinder Singh 		return;
95971937434SJasvinder Singh 	}
96071937434SJasvinder Singh 
96171937434SJasvinder Singh 	ap = port_in_action_profile_create(name, &p);
96271937434SJasvinder Singh 	if (ap == NULL) {
96371937434SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
96471937434SJasvinder Singh 		return;
96571937434SJasvinder Singh 	}
96671937434SJasvinder Singh }
96771937434SJasvinder Singh 
96826b3effeSKevin Laatz 
96926b3effeSKevin Laatz static const char cmd_table_action_profile_help[] =
97026b3effeSKevin Laatz "table action profile <profile_name>\n"
97126b3effeSKevin Laatz "   ipv4 | ipv6\n"
97226b3effeSKevin Laatz "   offset <ip_offset>\n"
97326b3effeSKevin Laatz "   fwd\n"
97426b3effeSKevin Laatz "   [balance offset <key_offset> mask <key_mask> outoffset <out_offset>]\n"
97526b3effeSKevin Laatz "   [meter srtcm | trtcm\n"
97626b3effeSKevin Laatz "       tc <n_tc>\n"
97726b3effeSKevin Laatz "       stats none | pkts | bytes | both]\n"
97826b3effeSKevin Laatz "   [tm spp <n_subports_per_port> pps <n_pipes_per_subport>]\n"
97933e7afe6SNemanja Marjanovic "   [encap ether | vlan | qinq | mpls | pppoe | qinq_pppoe \n"
98044cad685SCristian Dumitrescu "       vxlan offset <ether_offset> ipv4 | ipv6 vlan on | off]\n"
98126b3effeSKevin Laatz "   [nat src | dst\n"
98226b3effeSKevin Laatz "       proto udp | tcp]\n"
98326b3effeSKevin Laatz "   [ttl drop | fwd\n"
98426b3effeSKevin Laatz "       stats none | pkts]\n"
98526b3effeSKevin Laatz "   [stats pkts | bytes | both]\n"
9861edccebcSFan Zhang "   [time]\n"
987261bbff7SFan Zhang "   [sym_crypto dev <CRYPTODEV_NAME> offset <op_offset>]\n"
988d5ed626fSCristian Dumitrescu "   [tag]\n"
989d5ed626fSCristian Dumitrescu "   [decap]\n";
99026b3effeSKevin Laatz 
99171937434SJasvinder Singh static void
99271937434SJasvinder Singh cmd_table_action_profile(char **tokens,
99371937434SJasvinder Singh 	uint32_t n_tokens,
99471937434SJasvinder Singh 	char *out,
99571937434SJasvinder Singh 	size_t out_size)
99671937434SJasvinder Singh {
99771937434SJasvinder Singh 	struct table_action_profile_params p;
99871937434SJasvinder Singh 	struct table_action_profile *ap;
99971937434SJasvinder Singh 	char *name;
100071937434SJasvinder Singh 	uint32_t t0;
100171937434SJasvinder Singh 
100271937434SJasvinder Singh 	memset(&p, 0, sizeof(p));
100371937434SJasvinder Singh 
100471937434SJasvinder Singh 	if (n_tokens < 8) {
100571937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
100671937434SJasvinder Singh 		return;
100771937434SJasvinder Singh 	}
100871937434SJasvinder Singh 
100971937434SJasvinder Singh 	if (strcmp(tokens[1], "action") != 0) {
101071937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "action");
101171937434SJasvinder Singh 		return;
101271937434SJasvinder Singh 	}
101371937434SJasvinder Singh 
101471937434SJasvinder Singh 	if (strcmp(tokens[2], "profile") != 0) {
101571937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
101671937434SJasvinder Singh 		return;
101771937434SJasvinder Singh 	}
101871937434SJasvinder Singh 
101971937434SJasvinder Singh 	name = tokens[3];
102071937434SJasvinder Singh 
102171937434SJasvinder Singh 	if (strcmp(tokens[4], "ipv4") == 0)
102271937434SJasvinder Singh 		p.common.ip_version = 1;
102371937434SJasvinder Singh 	else if (strcmp(tokens[4], "ipv6") == 0)
102471937434SJasvinder Singh 		p.common.ip_version = 0;
102571937434SJasvinder Singh 	else {
102671937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "ipv4 or ipv6");
102771937434SJasvinder Singh 		return;
102871937434SJasvinder Singh 	}
102971937434SJasvinder Singh 
103071937434SJasvinder Singh 	if (strcmp(tokens[5], "offset") != 0) {
103171937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
103271937434SJasvinder Singh 		return;
103371937434SJasvinder Singh 	}
103471937434SJasvinder Singh 
103571937434SJasvinder Singh 	if (parser_read_uint32(&p.common.ip_offset, tokens[6]) != 0) {
103671937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "ip_offset");
103771937434SJasvinder Singh 		return;
103871937434SJasvinder Singh 	}
103971937434SJasvinder Singh 
104071937434SJasvinder Singh 	if (strcmp(tokens[7], "fwd") != 0) {
104171937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "fwd");
104271937434SJasvinder Singh 		return;
104371937434SJasvinder Singh 	}
104471937434SJasvinder Singh 
104571937434SJasvinder Singh 	p.action_mask |= 1LLU << RTE_TABLE_ACTION_FWD;
104671937434SJasvinder Singh 
104771937434SJasvinder Singh 	t0 = 8;
1048802755dcSJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "balance") == 0)) {
1049802755dcSJasvinder Singh 		if (n_tokens < t0 + 7) {
1050802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, "table action profile balance");
1051802755dcSJasvinder Singh 			return;
1052802755dcSJasvinder Singh 		}
1053802755dcSJasvinder Singh 
1054802755dcSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "offset") != 0) {
1055802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1056802755dcSJasvinder Singh 			return;
1057802755dcSJasvinder Singh 		}
1058802755dcSJasvinder Singh 
1059802755dcSJasvinder Singh 		if (parser_read_uint32(&p.lb.key_offset, tokens[t0 + 2]) != 0) {
1060802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1061802755dcSJasvinder Singh 			return;
1062802755dcSJasvinder Singh 		}
1063802755dcSJasvinder Singh 
1064802755dcSJasvinder Singh 		if (strcmp(tokens[t0 + 3], "mask") != 0) {
1065802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
1066802755dcSJasvinder Singh 			return;
1067802755dcSJasvinder Singh 		}
1068802755dcSJasvinder Singh 
1069802755dcSJasvinder Singh 		p.lb.key_size = RTE_PORT_IN_ACTION_LB_KEY_SIZE_MAX;
1070802755dcSJasvinder Singh 		if (parse_hex_string(tokens[t0 + 4], p.lb.key_mask, &p.lb.key_size) != 0) {
1071802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
1072802755dcSJasvinder Singh 			return;
1073802755dcSJasvinder Singh 		}
1074802755dcSJasvinder Singh 
1075802755dcSJasvinder Singh 		if (strcmp(tokens[t0 + 5], "outoffset") != 0) {
1076802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "outoffset");
1077802755dcSJasvinder Singh 			return;
1078802755dcSJasvinder Singh 		}
1079802755dcSJasvinder Singh 
1080802755dcSJasvinder Singh 		if (parser_read_uint32(&p.lb.out_offset, tokens[t0 + 6]) != 0) {
1081802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "out_offset");
1082802755dcSJasvinder Singh 			return;
1083802755dcSJasvinder Singh 		}
1084802755dcSJasvinder Singh 
1085802755dcSJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_LB;
1086802755dcSJasvinder Singh 		t0 += 7;
1087802755dcSJasvinder Singh 	} /* balance */
1088802755dcSJasvinder Singh 
108971937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "meter") == 0)) {
109071937434SJasvinder Singh 		if (n_tokens < t0 + 6) {
109171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
109271937434SJasvinder Singh 				"table action profile meter");
109371937434SJasvinder Singh 			return;
109471937434SJasvinder Singh 		}
109571937434SJasvinder Singh 
109671937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "srtcm") == 0)
109771937434SJasvinder Singh 			p.mtr.alg = RTE_TABLE_ACTION_METER_SRTCM;
109871937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "trtcm") == 0)
109971937434SJasvinder Singh 			p.mtr.alg = RTE_TABLE_ACTION_METER_TRTCM;
110071937434SJasvinder Singh 		else {
110171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
110271937434SJasvinder Singh 				"srtcm or trtcm");
110371937434SJasvinder Singh 			return;
110471937434SJasvinder Singh 		}
110571937434SJasvinder Singh 
110671937434SJasvinder Singh 		if (strcmp(tokens[t0 + 2], "tc") != 0) {
110771937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "tc");
110871937434SJasvinder Singh 			return;
110971937434SJasvinder Singh 		}
111071937434SJasvinder Singh 
111171937434SJasvinder Singh 		if (parser_read_uint32(&p.mtr.n_tc, tokens[t0 + 3]) != 0) {
111271937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_tc");
111371937434SJasvinder Singh 			return;
111471937434SJasvinder Singh 		}
111571937434SJasvinder Singh 
111671937434SJasvinder Singh 		if (strcmp(tokens[t0 + 4], "stats") != 0) {
111771937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
111871937434SJasvinder Singh 			return;
111971937434SJasvinder Singh 		}
112071937434SJasvinder Singh 
112171937434SJasvinder Singh 		if (strcmp(tokens[t0 + 5], "none") == 0) {
112271937434SJasvinder Singh 			p.mtr.n_packets_enabled = 0;
112371937434SJasvinder Singh 			p.mtr.n_bytes_enabled = 0;
112471937434SJasvinder Singh 		} else if (strcmp(tokens[t0 + 5], "pkts") == 0) {
112571937434SJasvinder Singh 			p.mtr.n_packets_enabled = 1;
112671937434SJasvinder Singh 			p.mtr.n_bytes_enabled = 0;
112771937434SJasvinder Singh 		} else if (strcmp(tokens[t0 + 5], "bytes") == 0) {
112871937434SJasvinder Singh 			p.mtr.n_packets_enabled = 0;
112971937434SJasvinder Singh 			p.mtr.n_bytes_enabled = 1;
113071937434SJasvinder Singh 		} else if (strcmp(tokens[t0 + 5], "both") == 0) {
113171937434SJasvinder Singh 			p.mtr.n_packets_enabled = 1;
113271937434SJasvinder Singh 			p.mtr.n_bytes_enabled = 1;
113371937434SJasvinder Singh 		} else {
113471937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
113571937434SJasvinder Singh 				"none or pkts or bytes or both");
113671937434SJasvinder Singh 			return;
113771937434SJasvinder Singh 		}
113871937434SJasvinder Singh 
113971937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_MTR;
114071937434SJasvinder Singh 		t0 += 6;
114171937434SJasvinder Singh 	} /* meter */
114271937434SJasvinder Singh 
114371937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "tm") == 0)) {
114471937434SJasvinder Singh 		if (n_tokens < t0 + 5) {
114571937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
114671937434SJasvinder Singh 				"table action profile tm");
114771937434SJasvinder Singh 			return;
114871937434SJasvinder Singh 		}
114971937434SJasvinder Singh 
115071937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "spp") != 0) {
115171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "spp");
115271937434SJasvinder Singh 			return;
115371937434SJasvinder Singh 		}
115471937434SJasvinder Singh 
115571937434SJasvinder Singh 		if (parser_read_uint32(&p.tm.n_subports_per_port,
115671937434SJasvinder Singh 			tokens[t0 + 2]) != 0) {
115771937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
115871937434SJasvinder Singh 				"n_subports_per_port");
115971937434SJasvinder Singh 			return;
116071937434SJasvinder Singh 		}
116171937434SJasvinder Singh 
116271937434SJasvinder Singh 		if (strcmp(tokens[t0 + 3], "pps") != 0) {
116371937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pps");
116471937434SJasvinder Singh 			return;
116571937434SJasvinder Singh 		}
116671937434SJasvinder Singh 
116771937434SJasvinder Singh 		if (parser_read_uint32(&p.tm.n_pipes_per_subport,
116871937434SJasvinder Singh 			tokens[t0 + 4]) != 0) {
116971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
117071937434SJasvinder Singh 				"n_pipes_per_subport");
117171937434SJasvinder Singh 			return;
117271937434SJasvinder Singh 		}
117371937434SJasvinder Singh 
117471937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_TM;
117571937434SJasvinder Singh 		t0 += 5;
117671937434SJasvinder Singh 	} /* tm */
117771937434SJasvinder Singh 
117871937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "encap") == 0)) {
117944cad685SCristian Dumitrescu 		uint32_t n_extra_tokens = 0;
118044cad685SCristian Dumitrescu 
118171937434SJasvinder Singh 		if (n_tokens < t0 + 2) {
118271937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
118371937434SJasvinder Singh 				"action profile encap");
118471937434SJasvinder Singh 			return;
118571937434SJasvinder Singh 		}
118671937434SJasvinder Singh 
118771937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "ether") == 0)
118871937434SJasvinder Singh 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_ETHER;
118971937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "vlan") == 0)
119071937434SJasvinder Singh 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VLAN;
119171937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "qinq") == 0)
119271937434SJasvinder Singh 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_QINQ;
119371937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "mpls") == 0)
119471937434SJasvinder Singh 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_MPLS;
119571937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "pppoe") == 0)
119671937434SJasvinder Singh 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_PPPOE;
119744cad685SCristian Dumitrescu 		else if (strcmp(tokens[t0 + 1], "vxlan") == 0) {
119844cad685SCristian Dumitrescu 			if (n_tokens < t0 + 2 + 5) {
119944cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_MISMATCH,
120044cad685SCristian Dumitrescu 					"action profile encap vxlan");
120144cad685SCristian Dumitrescu 				return;
120244cad685SCristian Dumitrescu 			}
120344cad685SCristian Dumitrescu 
120444cad685SCristian Dumitrescu 			if (strcmp(tokens[t0 + 2], "offset") != 0) {
120544cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_NOT_FOUND,
120644cad685SCristian Dumitrescu 					"vxlan: offset");
120744cad685SCristian Dumitrescu 				return;
120844cad685SCristian Dumitrescu 			}
120944cad685SCristian Dumitrescu 
121044cad685SCristian Dumitrescu 			if (parser_read_uint32(&p.encap.vxlan.data_offset,
121144cad685SCristian Dumitrescu 				tokens[t0 + 2 + 1]) != 0) {
121244cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_INVALID,
121344cad685SCristian Dumitrescu 					"vxlan: ether_offset");
121444cad685SCristian Dumitrescu 				return;
121544cad685SCristian Dumitrescu 			}
121644cad685SCristian Dumitrescu 
121744cad685SCristian Dumitrescu 			if (strcmp(tokens[t0 + 2 + 2], "ipv4") == 0)
121844cad685SCristian Dumitrescu 				p.encap.vxlan.ip_version = 1;
121944cad685SCristian Dumitrescu 			else if (strcmp(tokens[t0 + 2 + 2], "ipv6") == 0)
122044cad685SCristian Dumitrescu 				p.encap.vxlan.ip_version = 0;
122171937434SJasvinder Singh 			else {
122244cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_INVALID,
122344cad685SCristian Dumitrescu 					"vxlan: ipv4 or ipv6");
122444cad685SCristian Dumitrescu 				return;
122544cad685SCristian Dumitrescu 			}
122644cad685SCristian Dumitrescu 
122744cad685SCristian Dumitrescu 			if (strcmp(tokens[t0 + 2 + 3], "vlan") != 0) {
122844cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_NOT_FOUND,
122944cad685SCristian Dumitrescu 					"vxlan: vlan");
123044cad685SCristian Dumitrescu 				return;
123144cad685SCristian Dumitrescu 			}
123244cad685SCristian Dumitrescu 
123344cad685SCristian Dumitrescu 			if (strcmp(tokens[t0 + 2 + 4], "on") == 0)
123444cad685SCristian Dumitrescu 				p.encap.vxlan.vlan = 1;
123544cad685SCristian Dumitrescu 			else if (strcmp(tokens[t0 + 2 + 4], "off") == 0)
123644cad685SCristian Dumitrescu 				p.encap.vxlan.vlan = 0;
123744cad685SCristian Dumitrescu 			else {
123844cad685SCristian Dumitrescu 				snprintf(out, out_size, MSG_ARG_INVALID,
123944cad685SCristian Dumitrescu 					"vxlan: on or off");
124044cad685SCristian Dumitrescu 				return;
124144cad685SCristian Dumitrescu 			}
124244cad685SCristian Dumitrescu 
124344cad685SCristian Dumitrescu 			p.encap.encap_mask = 1LLU << RTE_TABLE_ACTION_ENCAP_VXLAN;
124444cad685SCristian Dumitrescu 			n_extra_tokens = 5;
124533e7afe6SNemanja Marjanovic 		} else if (strcmp(tokens[t0 + 1], "qinq_pppoe") == 0)
124633e7afe6SNemanja Marjanovic 			p.encap.encap_mask =
124733e7afe6SNemanja Marjanovic 				1LLU << RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
124833e7afe6SNemanja Marjanovic 		else {
124971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, "encap");
125071937434SJasvinder Singh 			return;
125171937434SJasvinder Singh 		}
125271937434SJasvinder Singh 
125371937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_ENCAP;
125444cad685SCristian Dumitrescu 		t0 += 2 + n_extra_tokens;
125571937434SJasvinder Singh 	} /* encap */
125671937434SJasvinder Singh 
125771937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "nat") == 0)) {
125871937434SJasvinder Singh 		if (n_tokens < t0 + 4) {
125971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
126071937434SJasvinder Singh 				"table action profile nat");
126171937434SJasvinder Singh 			return;
126271937434SJasvinder Singh 		}
126371937434SJasvinder Singh 
126471937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "src") == 0)
126571937434SJasvinder Singh 			p.nat.source_nat = 1;
126671937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "dst") == 0)
126771937434SJasvinder Singh 			p.nat.source_nat = 0;
126871937434SJasvinder Singh 		else {
126971937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
127071937434SJasvinder Singh 				"src or dst");
127171937434SJasvinder Singh 			return;
127271937434SJasvinder Singh 		}
127371937434SJasvinder Singh 
127471937434SJasvinder Singh 		if (strcmp(tokens[t0 + 2], "proto") != 0) {
127571937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "proto");
127671937434SJasvinder Singh 			return;
127771937434SJasvinder Singh 		}
127871937434SJasvinder Singh 
127971937434SJasvinder Singh 		if (strcmp(tokens[t0 + 3], "tcp") == 0)
128071937434SJasvinder Singh 			p.nat.proto = 0x06;
128171937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 3], "udp") == 0)
128271937434SJasvinder Singh 			p.nat.proto = 0x11;
128371937434SJasvinder Singh 		else {
128471937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
128571937434SJasvinder Singh 				"tcp or udp");
128671937434SJasvinder Singh 			return;
128771937434SJasvinder Singh 		}
128871937434SJasvinder Singh 
128971937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_NAT;
129071937434SJasvinder Singh 		t0 += 4;
129171937434SJasvinder Singh 	} /* nat */
129271937434SJasvinder Singh 
129371937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "ttl") == 0)) {
129471937434SJasvinder Singh 		if (n_tokens < t0 + 4) {
129571937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
129671937434SJasvinder Singh 				"table action profile ttl");
129771937434SJasvinder Singh 			return;
129871937434SJasvinder Singh 		}
129971937434SJasvinder Singh 
130071937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "drop") == 0)
130171937434SJasvinder Singh 			p.ttl.drop = 1;
130271937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "fwd") == 0)
130371937434SJasvinder Singh 			p.ttl.drop = 0;
130471937434SJasvinder Singh 		else {
130571937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
130671937434SJasvinder Singh 				"drop or fwd");
130771937434SJasvinder Singh 			return;
130871937434SJasvinder Singh 		}
130971937434SJasvinder Singh 
131071937434SJasvinder Singh 		if (strcmp(tokens[t0 + 2], "stats") != 0) {
131171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
131271937434SJasvinder Singh 			return;
131371937434SJasvinder Singh 		}
131471937434SJasvinder Singh 
131571937434SJasvinder Singh 		if (strcmp(tokens[t0 + 3], "none") == 0)
131671937434SJasvinder Singh 			p.ttl.n_packets_enabled = 0;
131771937434SJasvinder Singh 		else if (strcmp(tokens[t0 + 3], "pkts") == 0)
131871937434SJasvinder Singh 			p.ttl.n_packets_enabled = 1;
131971937434SJasvinder Singh 		else {
132071937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
132171937434SJasvinder Singh 				"none or pkts");
132271937434SJasvinder Singh 			return;
132371937434SJasvinder Singh 		}
132471937434SJasvinder Singh 
132571937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_TTL;
132671937434SJasvinder Singh 		t0 += 4;
132771937434SJasvinder Singh 	} /* ttl */
132871937434SJasvinder Singh 
132971937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "stats") == 0)) {
133071937434SJasvinder Singh 		if (n_tokens < t0 + 2) {
133171937434SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
133271937434SJasvinder Singh 				"table action profile stats");
133371937434SJasvinder Singh 			return;
133471937434SJasvinder Singh 		}
133571937434SJasvinder Singh 
133671937434SJasvinder Singh 		if (strcmp(tokens[t0 + 1], "pkts") == 0) {
133771937434SJasvinder Singh 			p.stats.n_packets_enabled = 1;
133871937434SJasvinder Singh 			p.stats.n_bytes_enabled = 0;
133971937434SJasvinder Singh 		} else if (strcmp(tokens[t0 + 1], "bytes") == 0) {
134071937434SJasvinder Singh 			p.stats.n_packets_enabled = 0;
134171937434SJasvinder Singh 			p.stats.n_bytes_enabled = 1;
134271937434SJasvinder Singh 		} else if (strcmp(tokens[t0 + 1], "both") == 0) {
134371937434SJasvinder Singh 			p.stats.n_packets_enabled = 1;
134471937434SJasvinder Singh 			p.stats.n_bytes_enabled = 1;
134571937434SJasvinder Singh 		} else {
134671937434SJasvinder Singh 			snprintf(out, out_size,	MSG_ARG_NOT_FOUND,
134771937434SJasvinder Singh 				"pkts or bytes or both");
134871937434SJasvinder Singh 			return;
134971937434SJasvinder Singh 		}
135071937434SJasvinder Singh 
135171937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_STATS;
135271937434SJasvinder Singh 		t0 += 2;
135371937434SJasvinder Singh 	} /* stats */
135471937434SJasvinder Singh 
135571937434SJasvinder Singh 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "time") == 0)) {
135671937434SJasvinder Singh 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_TIME;
135771937434SJasvinder Singh 		t0 += 1;
135871937434SJasvinder Singh 	} /* time */
135971937434SJasvinder Singh 
13601edccebcSFan Zhang 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "sym_crypto") == 0)) {
13611edccebcSFan Zhang 		struct cryptodev *cryptodev;
13621edccebcSFan Zhang 
1363261bbff7SFan Zhang 		if (n_tokens < t0 + 5 ||
13641edccebcSFan Zhang 				strcmp(tokens[t0 + 1], "dev") ||
1365261bbff7SFan Zhang 				strcmp(tokens[t0 + 3], "offset")) {
13661edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_MISMATCH,
13671edccebcSFan Zhang 				"table action profile sym_crypto");
13681edccebcSFan Zhang 			return;
13691edccebcSFan Zhang 		}
13701edccebcSFan Zhang 
13711edccebcSFan Zhang 		cryptodev = cryptodev_find(tokens[t0 + 2]);
13721edccebcSFan Zhang 		if (cryptodev == NULL) {
13731edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID,
13741edccebcSFan Zhang 				"table action profile sym_crypto");
13751edccebcSFan Zhang 			return;
13761edccebcSFan Zhang 		}
13771edccebcSFan Zhang 
13781edccebcSFan Zhang 		p.sym_crypto.cryptodev_id = cryptodev->dev_id;
13791edccebcSFan Zhang 
13801edccebcSFan Zhang 		if (parser_read_uint32(&p.sym_crypto.op_offset,
13811edccebcSFan Zhang 				tokens[t0 + 4]) != 0) {
13821edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID,
13831edccebcSFan Zhang 					"table action profile sym_crypto");
13841edccebcSFan Zhang 			return;
13851edccebcSFan Zhang 		}
13861edccebcSFan Zhang 
1387261bbff7SFan Zhang 		p.sym_crypto.mp_create = cryptodev->mp_create;
1388261bbff7SFan Zhang 		p.sym_crypto.mp_init = cryptodev->mp_init;
13891edccebcSFan Zhang 
13901edccebcSFan Zhang 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_SYM_CRYPTO;
13911edccebcSFan Zhang 
1392261bbff7SFan Zhang 		t0 += 5;
13931edccebcSFan Zhang 	} /* sym_crypto */
13941edccebcSFan Zhang 
13951bdf2632SCristian Dumitrescu 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "tag") == 0)) {
13961bdf2632SCristian Dumitrescu 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_TAG;
13971bdf2632SCristian Dumitrescu 		t0 += 1;
13981bdf2632SCristian Dumitrescu 	} /* tag */
13991bdf2632SCristian Dumitrescu 
1400d5ed626fSCristian Dumitrescu 	if ((t0 < n_tokens) && (strcmp(tokens[t0], "decap") == 0)) {
1401d5ed626fSCristian Dumitrescu 		p.action_mask |= 1LLU << RTE_TABLE_ACTION_DECAP;
1402d5ed626fSCristian Dumitrescu 		t0 += 1;
1403d5ed626fSCristian Dumitrescu 	} /* decap */
1404d5ed626fSCristian Dumitrescu 
140571937434SJasvinder Singh 	if (t0 < n_tokens) {
140671937434SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
140771937434SJasvinder Singh 		return;
140871937434SJasvinder Singh 	}
140971937434SJasvinder Singh 
141071937434SJasvinder Singh 	ap = table_action_profile_create(name, &p);
141171937434SJasvinder Singh 	if (ap == NULL) {
141271937434SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
141371937434SJasvinder Singh 		return;
141471937434SJasvinder Singh 	}
141571937434SJasvinder Singh }
141671937434SJasvinder Singh 
141726b3effeSKevin Laatz static const char cmd_pipeline_help[] =
141826b3effeSKevin Laatz "pipeline <pipeline_name>\n"
141926b3effeSKevin Laatz "   period <timer_period_ms>\n"
142026b3effeSKevin Laatz "   offset_port_id <offset_port_id>\n"
142126b3effeSKevin Laatz "   cpu <cpu_id>\n";
142226b3effeSKevin Laatz 
1423d75c371eSJasvinder Singh static void
1424d75c371eSJasvinder Singh cmd_pipeline(char **tokens,
1425d75c371eSJasvinder Singh 	uint32_t n_tokens,
1426d75c371eSJasvinder Singh 	char *out,
1427d75c371eSJasvinder Singh 	size_t out_size)
1428d75c371eSJasvinder Singh {
1429d75c371eSJasvinder Singh 	struct pipeline_params p;
1430d75c371eSJasvinder Singh 	char *name;
1431d75c371eSJasvinder Singh 	struct pipeline *pipeline;
1432d75c371eSJasvinder Singh 
1433d75c371eSJasvinder Singh 	if (n_tokens != 8) {
1434d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1435d75c371eSJasvinder Singh 		return;
1436d75c371eSJasvinder Singh 	}
1437d75c371eSJasvinder Singh 
1438d75c371eSJasvinder Singh 	name = tokens[1];
1439d75c371eSJasvinder Singh 
1440d75c371eSJasvinder Singh 	if (strcmp(tokens[2], "period") != 0) {
1441d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "period");
1442d75c371eSJasvinder Singh 		return;
1443d75c371eSJasvinder Singh 	}
1444d75c371eSJasvinder Singh 
1445d75c371eSJasvinder Singh 	if (parser_read_uint32(&p.timer_period_ms, tokens[3]) != 0) {
1446d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "timer_period_ms");
1447d75c371eSJasvinder Singh 		return;
1448d75c371eSJasvinder Singh 	}
1449d75c371eSJasvinder Singh 
1450d75c371eSJasvinder Singh 	if (strcmp(tokens[4], "offset_port_id") != 0) {
1451d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset_port_id");
1452d75c371eSJasvinder Singh 		return;
1453d75c371eSJasvinder Singh 	}
1454d75c371eSJasvinder Singh 
1455d75c371eSJasvinder Singh 	if (parser_read_uint32(&p.offset_port_id, tokens[5]) != 0) {
1456d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "offset_port_id");
1457d75c371eSJasvinder Singh 		return;
1458d75c371eSJasvinder Singh 	}
1459d75c371eSJasvinder Singh 
1460d75c371eSJasvinder Singh 	if (strcmp(tokens[6], "cpu") != 0) {
1461d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cpu");
1462d75c371eSJasvinder Singh 		return;
1463d75c371eSJasvinder Singh 	}
1464d75c371eSJasvinder Singh 
1465d75c371eSJasvinder Singh 	if (parser_read_uint32(&p.cpu_id, tokens[7]) != 0) {
1466d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "cpu_id");
1467d75c371eSJasvinder Singh 		return;
1468d75c371eSJasvinder Singh 	}
1469d75c371eSJasvinder Singh 
1470d75c371eSJasvinder Singh 	pipeline = pipeline_create(name, &p);
1471d75c371eSJasvinder Singh 	if (pipeline == NULL) {
1472d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1473d75c371eSJasvinder Singh 		return;
1474d75c371eSJasvinder Singh 	}
1475d75c371eSJasvinder Singh }
1476d75c371eSJasvinder Singh 
147726b3effeSKevin Laatz static const char cmd_pipeline_port_in_help[] =
147826b3effeSKevin Laatz "pipeline <pipeline_name> port in\n"
147926b3effeSKevin Laatz "   bsz <burst_size>\n"
148026b3effeSKevin Laatz "   link <link_name> rxq <queue_id>\n"
148126b3effeSKevin Laatz "   | swq <swq_name>\n"
148226b3effeSKevin Laatz "   | tmgr <tmgr_name>\n"
148326b3effeSKevin Laatz "   | tap <tap_name> mempool <mempool_name> mtu <mtu>\n"
148426b3effeSKevin Laatz "   | source mempool <mempool_name> file <file_name> bpp <n_bytes_per_pkt>\n"
14851edccebcSFan Zhang "   | cryptodev <cryptodev_name> rxq <queue_id>\n"
148626b3effeSKevin Laatz "   [action <port_in_action_profile_name>]\n"
148726b3effeSKevin Laatz "   [disabled]\n";
148826b3effeSKevin Laatz 
1489d75c371eSJasvinder Singh static void
1490d75c371eSJasvinder Singh cmd_pipeline_port_in(char **tokens,
1491d75c371eSJasvinder Singh 	uint32_t n_tokens,
1492d75c371eSJasvinder Singh 	char *out,
1493d75c371eSJasvinder Singh 	size_t out_size)
1494d75c371eSJasvinder Singh {
1495d75c371eSJasvinder Singh 	struct port_in_params p;
1496d75c371eSJasvinder Singh 	char *pipeline_name;
1497d75c371eSJasvinder Singh 	uint32_t t0;
1498d75c371eSJasvinder Singh 	int enabled, status;
1499d75c371eSJasvinder Singh 
1500d75c371eSJasvinder Singh 	if (n_tokens < 7) {
1501d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1502d75c371eSJasvinder Singh 		return;
1503d75c371eSJasvinder Singh 	}
1504d75c371eSJasvinder Singh 
1505d75c371eSJasvinder Singh 	pipeline_name = tokens[1];
1506d75c371eSJasvinder Singh 
1507d75c371eSJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
1508d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1509d75c371eSJasvinder Singh 		return;
1510d75c371eSJasvinder Singh 	}
1511d75c371eSJasvinder Singh 
1512d75c371eSJasvinder Singh 	if (strcmp(tokens[3], "in") != 0) {
1513d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
1514d75c371eSJasvinder Singh 		return;
1515d75c371eSJasvinder Singh 	}
1516d75c371eSJasvinder Singh 
1517d75c371eSJasvinder Singh 	if (strcmp(tokens[4], "bsz") != 0) {
1518d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1519d75c371eSJasvinder Singh 		return;
1520d75c371eSJasvinder Singh 	}
1521d75c371eSJasvinder Singh 
1522d75c371eSJasvinder Singh 	if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1523d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1524d75c371eSJasvinder Singh 		return;
1525d75c371eSJasvinder Singh 	}
1526d75c371eSJasvinder Singh 
1527d75c371eSJasvinder Singh 	t0 = 6;
1528d75c371eSJasvinder Singh 
1529d75c371eSJasvinder Singh 	if (strcmp(tokens[t0], "link") == 0) {
1530d75c371eSJasvinder Singh 		if (n_tokens < t0 + 4) {
1531d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1532d75c371eSJasvinder Singh 				"pipeline port in link");
1533d75c371eSJasvinder Singh 			return;
1534d75c371eSJasvinder Singh 		}
1535d75c371eSJasvinder Singh 
1536d75c371eSJasvinder Singh 		p.type = PORT_IN_RXQ;
1537d75c371eSJasvinder Singh 
1538d75c371eSJasvinder Singh 		p.dev_name = tokens[t0 + 1];
1539d75c371eSJasvinder Singh 
1540d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 2], "rxq") != 0) {
1541d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rxq");
1542d75c371eSJasvinder Singh 			return;
1543d75c371eSJasvinder Singh 		}
1544d75c371eSJasvinder Singh 
1545d75c371eSJasvinder Singh 		if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
1546d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
1547d75c371eSJasvinder Singh 				"queue_id");
1548d75c371eSJasvinder Singh 			return;
1549d75c371eSJasvinder Singh 		}
1550d75c371eSJasvinder Singh 		t0 += 4;
1551d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "swq") == 0) {
1552d75c371eSJasvinder Singh 		if (n_tokens < t0 + 2) {
1553d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1554d75c371eSJasvinder Singh 				"pipeline port in swq");
1555d75c371eSJasvinder Singh 			return;
1556d75c371eSJasvinder Singh 		}
1557d75c371eSJasvinder Singh 
1558d75c371eSJasvinder Singh 		p.type = PORT_IN_SWQ;
1559d75c371eSJasvinder Singh 
1560d75c371eSJasvinder Singh 		p.dev_name = tokens[t0 + 1];
1561d75c371eSJasvinder Singh 
1562d75c371eSJasvinder Singh 		t0 += 2;
1563d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "tmgr") == 0) {
1564d75c371eSJasvinder Singh 		if (n_tokens < t0 + 2) {
1565d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1566d75c371eSJasvinder Singh 				"pipeline port in tmgr");
1567d75c371eSJasvinder Singh 			return;
1568d75c371eSJasvinder Singh 		}
1569d75c371eSJasvinder Singh 
1570d75c371eSJasvinder Singh 		p.type = PORT_IN_TMGR;
1571d75c371eSJasvinder Singh 
1572d75c371eSJasvinder Singh 		p.dev_name = tokens[t0 + 1];
1573d75c371eSJasvinder Singh 
1574d75c371eSJasvinder Singh 		t0 += 2;
1575d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "tap") == 0) {
1576d75c371eSJasvinder Singh 		if (n_tokens < t0 + 6) {
1577d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1578d75c371eSJasvinder Singh 				"pipeline port in tap");
1579d75c371eSJasvinder Singh 			return;
1580d75c371eSJasvinder Singh 		}
1581d75c371eSJasvinder Singh 
1582d75c371eSJasvinder Singh 		p.type = PORT_IN_TAP;
1583d75c371eSJasvinder Singh 
1584d75c371eSJasvinder Singh 		p.dev_name = tokens[t0 + 1];
1585d75c371eSJasvinder Singh 
1586d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 2], "mempool") != 0) {
1587d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1588d75c371eSJasvinder Singh 				"mempool");
1589d75c371eSJasvinder Singh 			return;
1590d75c371eSJasvinder Singh 		}
1591d75c371eSJasvinder Singh 
1592d75c371eSJasvinder Singh 		p.tap.mempool_name = tokens[t0 + 3];
1593d75c371eSJasvinder Singh 
1594d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 4], "mtu") != 0) {
1595d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1596d75c371eSJasvinder Singh 				"mtu");
1597d75c371eSJasvinder Singh 			return;
1598d75c371eSJasvinder Singh 		}
1599d75c371eSJasvinder Singh 
1600d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.tap.mtu, tokens[t0 + 5]) != 0) {
1601d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "mtu");
1602d75c371eSJasvinder Singh 			return;
1603d75c371eSJasvinder Singh 		}
1604d75c371eSJasvinder Singh 
1605d75c371eSJasvinder Singh 		t0 += 6;
1606d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "source") == 0) {
1607d75c371eSJasvinder Singh 		if (n_tokens < t0 + 6) {
1608d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1609d75c371eSJasvinder Singh 				"pipeline port in source");
1610d75c371eSJasvinder Singh 			return;
1611d75c371eSJasvinder Singh 		}
1612d75c371eSJasvinder Singh 
1613d75c371eSJasvinder Singh 		p.type = PORT_IN_SOURCE;
1614d75c371eSJasvinder Singh 
1615d75c371eSJasvinder Singh 		p.dev_name = NULL;
1616d75c371eSJasvinder Singh 
1617d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "mempool") != 0) {
1618d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1619d75c371eSJasvinder Singh 				"mempool");
1620d75c371eSJasvinder Singh 			return;
1621d75c371eSJasvinder Singh 		}
1622d75c371eSJasvinder Singh 
1623d75c371eSJasvinder Singh 		p.source.mempool_name = tokens[t0 + 2];
1624d75c371eSJasvinder Singh 
1625d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 3], "file") != 0) {
1626d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1627d75c371eSJasvinder Singh 				"file");
1628d75c371eSJasvinder Singh 			return;
1629d75c371eSJasvinder Singh 		}
1630d75c371eSJasvinder Singh 
1631d75c371eSJasvinder Singh 		p.source.file_name = tokens[t0 + 4];
1632d75c371eSJasvinder Singh 
1633d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 5], "bpp") != 0) {
1634d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1635d75c371eSJasvinder Singh 				"bpp");
1636d75c371eSJasvinder Singh 			return;
1637d75c371eSJasvinder Singh 		}
1638d75c371eSJasvinder Singh 
1639d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.source.n_bytes_per_pkt, tokens[t0 + 6]) != 0) {
1640d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
1641d75c371eSJasvinder Singh 				"n_bytes_per_pkt");
1642d75c371eSJasvinder Singh 			return;
1643d75c371eSJasvinder Singh 		}
1644d75c371eSJasvinder Singh 
1645d75c371eSJasvinder Singh 		t0 += 7;
16461edccebcSFan Zhang 	} else if (strcmp(tokens[t0], "cryptodev") == 0) {
16471edccebcSFan Zhang 		if (n_tokens < t0 + 3) {
16481edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_MISMATCH,
16491edccebcSFan Zhang 				"pipeline port in cryptodev");
16501edccebcSFan Zhang 			return;
16511edccebcSFan Zhang 		}
16521edccebcSFan Zhang 
16531edccebcSFan Zhang 		p.type = PORT_IN_CRYPTODEV;
16541edccebcSFan Zhang 
16551edccebcSFan Zhang 		p.dev_name = tokens[t0 + 1];
16561edccebcSFan Zhang 		if (parser_read_uint16(&p.rxq.queue_id, tokens[t0 + 3]) != 0) {
16571edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID,
16581edccebcSFan Zhang 				"rxq");
16591edccebcSFan Zhang 			return;
16601edccebcSFan Zhang 		}
16611edccebcSFan Zhang 
16621edccebcSFan Zhang 		p.cryptodev.arg_callback = NULL;
16631edccebcSFan Zhang 		p.cryptodev.f_callback = NULL;
16641edccebcSFan Zhang 
16651edccebcSFan Zhang 		t0 += 4;
1666d75c371eSJasvinder Singh 	} else {
1667d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1668d75c371eSJasvinder Singh 		return;
1669d75c371eSJasvinder Singh 	}
1670d75c371eSJasvinder Singh 
1671d75c371eSJasvinder Singh 	p.action_profile_name = NULL;
1672d75c371eSJasvinder Singh 	if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
1673d75c371eSJasvinder Singh 		if (n_tokens < t0 + 2) {
1674d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
1675d75c371eSJasvinder Singh 			return;
1676d75c371eSJasvinder Singh 		}
1677d75c371eSJasvinder Singh 
1678d75c371eSJasvinder Singh 		p.action_profile_name = tokens[t0 + 1];
1679d75c371eSJasvinder Singh 
1680d75c371eSJasvinder Singh 		t0 += 2;
1681d75c371eSJasvinder Singh 	}
1682d75c371eSJasvinder Singh 
1683d75c371eSJasvinder Singh 	enabled = 1;
1684d75c371eSJasvinder Singh 	if ((n_tokens > t0) &&
1685d75c371eSJasvinder Singh 		(strcmp(tokens[t0], "disabled") == 0)) {
1686d75c371eSJasvinder Singh 		enabled = 0;
1687d75c371eSJasvinder Singh 
1688d75c371eSJasvinder Singh 		t0 += 1;
1689d75c371eSJasvinder Singh 	}
1690d75c371eSJasvinder Singh 
1691d75c371eSJasvinder Singh 	if (n_tokens != t0) {
1692d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1693d75c371eSJasvinder Singh 		return;
1694d75c371eSJasvinder Singh 	}
1695d75c371eSJasvinder Singh 
1696d75c371eSJasvinder Singh 	status = pipeline_port_in_create(pipeline_name,
1697d75c371eSJasvinder Singh 		&p, enabled);
1698d75c371eSJasvinder Singh 	if (status) {
1699d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1700d75c371eSJasvinder Singh 		return;
1701d75c371eSJasvinder Singh 	}
1702d75c371eSJasvinder Singh }
1703d75c371eSJasvinder Singh 
170426b3effeSKevin Laatz static const char cmd_pipeline_port_out_help[] =
170526b3effeSKevin Laatz "pipeline <pipeline_name> port out\n"
170626b3effeSKevin Laatz "   bsz <burst_size>\n"
170726b3effeSKevin Laatz "   link <link_name> txq <txq_id>\n"
170826b3effeSKevin Laatz "   | swq <swq_name>\n"
170926b3effeSKevin Laatz "   | tmgr <tmgr_name>\n"
171026b3effeSKevin Laatz "   | tap <tap_name>\n"
17111edccebcSFan Zhang "   | sink [file <file_name> pkts <max_n_pkts>]\n"
17121edccebcSFan Zhang "   | cryptodev <cryptodev_name> txq <txq_id> offset <crypto_op_offset>\n";
171326b3effeSKevin Laatz 
1714d75c371eSJasvinder Singh static void
1715d75c371eSJasvinder Singh cmd_pipeline_port_out(char **tokens,
1716d75c371eSJasvinder Singh 	uint32_t n_tokens,
1717d75c371eSJasvinder Singh 	char *out,
1718d75c371eSJasvinder Singh 	size_t out_size)
1719d75c371eSJasvinder Singh {
1720d75c371eSJasvinder Singh 	struct port_out_params p;
1721d75c371eSJasvinder Singh 	char *pipeline_name;
1722d75c371eSJasvinder Singh 	int status;
1723d75c371eSJasvinder Singh 
1724d75c371eSJasvinder Singh 	memset(&p, 0, sizeof(p));
1725d75c371eSJasvinder Singh 
1726d75c371eSJasvinder Singh 	if (n_tokens < 7) {
1727d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1728d75c371eSJasvinder Singh 		return;
1729d75c371eSJasvinder Singh 	}
1730d75c371eSJasvinder Singh 
1731d75c371eSJasvinder Singh 	pipeline_name = tokens[1];
1732d75c371eSJasvinder Singh 
1733d75c371eSJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
1734d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
1735d75c371eSJasvinder Singh 		return;
1736d75c371eSJasvinder Singh 	}
1737d75c371eSJasvinder Singh 
1738d75c371eSJasvinder Singh 	if (strcmp(tokens[3], "out") != 0) {
1739d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
1740d75c371eSJasvinder Singh 		return;
1741d75c371eSJasvinder Singh 	}
1742d75c371eSJasvinder Singh 
1743d75c371eSJasvinder Singh 	if (strcmp(tokens[4], "bsz") != 0) {
1744d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "bsz");
1745d75c371eSJasvinder Singh 		return;
1746d75c371eSJasvinder Singh 	}
1747d75c371eSJasvinder Singh 
1748d75c371eSJasvinder Singh 	if (parser_read_uint32(&p.burst_size, tokens[5]) != 0) {
1749d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "burst_size");
1750d75c371eSJasvinder Singh 		return;
1751d75c371eSJasvinder Singh 	}
1752d75c371eSJasvinder Singh 
1753d75c371eSJasvinder Singh 	if (strcmp(tokens[6], "link") == 0) {
1754d75c371eSJasvinder Singh 		if (n_tokens != 10) {
1755d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1756d75c371eSJasvinder Singh 				"pipeline port out link");
1757d75c371eSJasvinder Singh 			return;
1758d75c371eSJasvinder Singh 		}
1759d75c371eSJasvinder Singh 
1760d75c371eSJasvinder Singh 		p.type = PORT_OUT_TXQ;
1761d75c371eSJasvinder Singh 
1762d75c371eSJasvinder Singh 		p.dev_name = tokens[7];
1763d75c371eSJasvinder Singh 
1764d75c371eSJasvinder Singh 		if (strcmp(tokens[8], "txq") != 0) {
1765d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "txq");
1766d75c371eSJasvinder Singh 			return;
1767d75c371eSJasvinder Singh 		}
1768d75c371eSJasvinder Singh 
1769d75c371eSJasvinder Singh 		if (parser_read_uint16(&p.txq.queue_id, tokens[9]) != 0) {
1770d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
1771d75c371eSJasvinder Singh 			return;
1772d75c371eSJasvinder Singh 		}
1773d75c371eSJasvinder Singh 	} else if (strcmp(tokens[6], "swq") == 0) {
1774d75c371eSJasvinder Singh 		if (n_tokens != 8) {
1775d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1776d75c371eSJasvinder Singh 				"pipeline port out swq");
1777d75c371eSJasvinder Singh 			return;
1778d75c371eSJasvinder Singh 		}
1779d75c371eSJasvinder Singh 
1780d75c371eSJasvinder Singh 		p.type = PORT_OUT_SWQ;
1781d75c371eSJasvinder Singh 
1782d75c371eSJasvinder Singh 		p.dev_name = tokens[7];
1783d75c371eSJasvinder Singh 	} else if (strcmp(tokens[6], "tmgr") == 0) {
1784d75c371eSJasvinder Singh 		if (n_tokens != 8) {
1785d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1786d75c371eSJasvinder Singh 				"pipeline port out tmgr");
1787d75c371eSJasvinder Singh 			return;
1788d75c371eSJasvinder Singh 		}
1789d75c371eSJasvinder Singh 
1790d75c371eSJasvinder Singh 		p.type = PORT_OUT_TMGR;
1791d75c371eSJasvinder Singh 
1792d75c371eSJasvinder Singh 		p.dev_name = tokens[7];
1793d75c371eSJasvinder Singh 	} else if (strcmp(tokens[6], "tap") == 0) {
1794d75c371eSJasvinder Singh 		if (n_tokens != 8) {
1795d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1796d75c371eSJasvinder Singh 				"pipeline port out tap");
1797d75c371eSJasvinder Singh 			return;
1798d75c371eSJasvinder Singh 		}
1799d75c371eSJasvinder Singh 
1800d75c371eSJasvinder Singh 		p.type = PORT_OUT_TAP;
1801d75c371eSJasvinder Singh 
1802d75c371eSJasvinder Singh 		p.dev_name = tokens[7];
1803d75c371eSJasvinder Singh 	} else if (strcmp(tokens[6], "sink") == 0) {
1804d75c371eSJasvinder Singh 		if ((n_tokens != 7) && (n_tokens != 11)) {
1805d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1806d75c371eSJasvinder Singh 				"pipeline port out sink");
1807d75c371eSJasvinder Singh 			return;
1808d75c371eSJasvinder Singh 		}
1809d75c371eSJasvinder Singh 
1810d75c371eSJasvinder Singh 		p.type = PORT_OUT_SINK;
1811d75c371eSJasvinder Singh 
1812d75c371eSJasvinder Singh 		p.dev_name = NULL;
1813d75c371eSJasvinder Singh 
1814d75c371eSJasvinder Singh 		if (n_tokens == 7) {
1815d75c371eSJasvinder Singh 			p.sink.file_name = NULL;
1816d75c371eSJasvinder Singh 			p.sink.max_n_pkts = 0;
1817d75c371eSJasvinder Singh 		} else {
1818d75c371eSJasvinder Singh 			if (strcmp(tokens[7], "file") != 0) {
1819d75c371eSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1820d75c371eSJasvinder Singh 					"file");
1821d75c371eSJasvinder Singh 				return;
1822d75c371eSJasvinder Singh 			}
1823d75c371eSJasvinder Singh 
1824d75c371eSJasvinder Singh 			p.sink.file_name = tokens[8];
1825d75c371eSJasvinder Singh 
1826d75c371eSJasvinder Singh 			if (strcmp(tokens[9], "pkts") != 0) {
1827d75c371eSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pkts");
1828d75c371eSJasvinder Singh 				return;
1829d75c371eSJasvinder Singh 			}
1830d75c371eSJasvinder Singh 
1831d75c371eSJasvinder Singh 			if (parser_read_uint32(&p.sink.max_n_pkts, tokens[10]) != 0) {
1832d75c371eSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "max_n_pkts");
1833d75c371eSJasvinder Singh 				return;
1834d75c371eSJasvinder Singh 			}
1835d75c371eSJasvinder Singh 		}
18361edccebcSFan Zhang 
18371edccebcSFan Zhang 	} else if (strcmp(tokens[6], "cryptodev") == 0) {
18381edccebcSFan Zhang 		if (n_tokens != 12) {
18391edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_MISMATCH,
18401edccebcSFan Zhang 				"pipeline port out cryptodev");
18411edccebcSFan Zhang 			return;
18421edccebcSFan Zhang 		}
18431edccebcSFan Zhang 
18441edccebcSFan Zhang 		p.type = PORT_OUT_CRYPTODEV;
18451edccebcSFan Zhang 
18461edccebcSFan Zhang 		p.dev_name = tokens[7];
18471edccebcSFan Zhang 
18481edccebcSFan Zhang 		if (strcmp(tokens[8], "txq")) {
18491edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_MISMATCH,
18501edccebcSFan Zhang 				"pipeline port out cryptodev");
18511edccebcSFan Zhang 			return;
18521edccebcSFan Zhang 		}
18531edccebcSFan Zhang 
18541edccebcSFan Zhang 		if (parser_read_uint16(&p.cryptodev.queue_id, tokens[9])
18551edccebcSFan Zhang 				!= 0) {
18561edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
18571edccebcSFan Zhang 			return;
18581edccebcSFan Zhang 		}
18591edccebcSFan Zhang 
18601edccebcSFan Zhang 		if (strcmp(tokens[10], "offset")) {
18611edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_MISMATCH,
18621edccebcSFan Zhang 				"pipeline port out cryptodev");
18631edccebcSFan Zhang 			return;
18641edccebcSFan Zhang 		}
18651edccebcSFan Zhang 
18661edccebcSFan Zhang 		if (parser_read_uint32(&p.cryptodev.op_offset, tokens[11])
18671edccebcSFan Zhang 				!= 0) {
18681edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID, "queue_id");
18691edccebcSFan Zhang 			return;
18701edccebcSFan Zhang 		}
1871d75c371eSJasvinder Singh 	} else {
1872d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
1873d75c371eSJasvinder Singh 		return;
1874d75c371eSJasvinder Singh 	}
1875d75c371eSJasvinder Singh 
1876d75c371eSJasvinder Singh 	status = pipeline_port_out_create(pipeline_name, &p);
1877d75c371eSJasvinder Singh 	if (status) {
1878d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
1879d75c371eSJasvinder Singh 		return;
1880d75c371eSJasvinder Singh 	}
1881d75c371eSJasvinder Singh }
1882d75c371eSJasvinder Singh 
188326b3effeSKevin Laatz static const char cmd_pipeline_table_help[] =
188426b3effeSKevin Laatz "pipeline <pipeline_name> table\n"
188526b3effeSKevin Laatz "       match\n"
188626b3effeSKevin Laatz "       acl\n"
188726b3effeSKevin Laatz "           ipv4 | ipv6\n"
188826b3effeSKevin Laatz "           offset <ip_header_offset>\n"
188926b3effeSKevin Laatz "           size <n_rules>\n"
189026b3effeSKevin Laatz "       | array\n"
189126b3effeSKevin Laatz "           offset <key_offset>\n"
189226b3effeSKevin Laatz "           size <n_keys>\n"
189326b3effeSKevin Laatz "       | hash\n"
189426b3effeSKevin Laatz "           ext | lru\n"
189526b3effeSKevin Laatz "           key <key_size>\n"
189626b3effeSKevin Laatz "           mask <key_mask>\n"
189726b3effeSKevin Laatz "           offset <key_offset>\n"
189826b3effeSKevin Laatz "           buckets <n_buckets>\n"
189926b3effeSKevin Laatz "           size <n_keys>\n"
190026b3effeSKevin Laatz "       | lpm\n"
190126b3effeSKevin Laatz "           ipv4 | ipv6\n"
190226b3effeSKevin Laatz "           offset <ip_header_offset>\n"
190326b3effeSKevin Laatz "           size <n_rules>\n"
190426b3effeSKevin Laatz "       | stub\n"
190526b3effeSKevin Laatz "   [action <table_action_profile_name>]\n";
190626b3effeSKevin Laatz 
1907d75c371eSJasvinder Singh static void
1908d75c371eSJasvinder Singh cmd_pipeline_table(char **tokens,
1909d75c371eSJasvinder Singh 	uint32_t n_tokens,
1910d75c371eSJasvinder Singh 	char *out,
1911d75c371eSJasvinder Singh 	size_t out_size)
1912d75c371eSJasvinder Singh {
1913d75c371eSJasvinder Singh 	uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
1914d75c371eSJasvinder Singh 	struct table_params p;
1915d75c371eSJasvinder Singh 	char *pipeline_name;
1916d75c371eSJasvinder Singh 	uint32_t t0;
1917d75c371eSJasvinder Singh 	int status;
1918d75c371eSJasvinder Singh 
1919d75c371eSJasvinder Singh 	if (n_tokens < 5) {
1920d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
1921d75c371eSJasvinder Singh 		return;
1922d75c371eSJasvinder Singh 	}
1923d75c371eSJasvinder Singh 
1924d75c371eSJasvinder Singh 	pipeline_name = tokens[1];
1925d75c371eSJasvinder Singh 
1926d75c371eSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
1927d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
1928d75c371eSJasvinder Singh 		return;
1929d75c371eSJasvinder Singh 	}
1930d75c371eSJasvinder Singh 
1931d75c371eSJasvinder Singh 	if (strcmp(tokens[3], "match") != 0) {
1932d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
1933d75c371eSJasvinder Singh 		return;
1934d75c371eSJasvinder Singh 	}
1935d75c371eSJasvinder Singh 
1936d75c371eSJasvinder Singh 	t0 = 4;
1937d75c371eSJasvinder Singh 	if (strcmp(tokens[t0], "acl") == 0) {
1938d75c371eSJasvinder Singh 		if (n_tokens < t0 + 6) {
1939d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1940d75c371eSJasvinder Singh 				"pipeline table acl");
1941d75c371eSJasvinder Singh 			return;
1942d75c371eSJasvinder Singh 		}
1943d75c371eSJasvinder Singh 
1944d75c371eSJasvinder Singh 		p.match_type = TABLE_ACL;
1945d75c371eSJasvinder Singh 
1946d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "ipv4") == 0)
1947d75c371eSJasvinder Singh 			p.match.acl.ip_version = 1;
1948d75c371eSJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
1949d75c371eSJasvinder Singh 			p.match.acl.ip_version = 0;
1950d75c371eSJasvinder Singh 		else {
1951d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
1952d75c371eSJasvinder Singh 				"ipv4 or ipv6");
1953d75c371eSJasvinder Singh 			return;
1954d75c371eSJasvinder Singh 		}
1955d75c371eSJasvinder Singh 
1956d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 2], "offset") != 0) {
1957d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1958d75c371eSJasvinder Singh 			return;
1959d75c371eSJasvinder Singh 		}
1960d75c371eSJasvinder Singh 
1961d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.acl.ip_header_offset,
1962d75c371eSJasvinder Singh 			tokens[t0 + 3]) != 0) {
1963d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
1964d75c371eSJasvinder Singh 				"ip_header_offset");
1965d75c371eSJasvinder Singh 			return;
1966d75c371eSJasvinder Singh 		}
1967d75c371eSJasvinder Singh 
1968d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 4], "size") != 0) {
1969d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
1970d75c371eSJasvinder Singh 			return;
1971d75c371eSJasvinder Singh 		}
1972d75c371eSJasvinder Singh 
1973d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.acl.n_rules,
1974d75c371eSJasvinder Singh 			tokens[t0 + 5]) != 0) {
1975d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
1976d75c371eSJasvinder Singh 			return;
1977d75c371eSJasvinder Singh 		}
1978d75c371eSJasvinder Singh 
1979d75c371eSJasvinder Singh 		t0 += 6;
1980d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "array") == 0) {
1981d75c371eSJasvinder Singh 		if (n_tokens < t0 + 5) {
1982d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
1983d75c371eSJasvinder Singh 				"pipeline table array");
1984d75c371eSJasvinder Singh 			return;
1985d75c371eSJasvinder Singh 		}
1986d75c371eSJasvinder Singh 
1987d75c371eSJasvinder Singh 		p.match_type = TABLE_ARRAY;
1988d75c371eSJasvinder Singh 
1989d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "offset") != 0) {
1990d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
1991d75c371eSJasvinder Singh 			return;
1992d75c371eSJasvinder Singh 		}
1993d75c371eSJasvinder Singh 
1994d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.array.key_offset,
1995d75c371eSJasvinder Singh 			tokens[t0 + 2]) != 0) {
1996d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
1997d75c371eSJasvinder Singh 			return;
1998d75c371eSJasvinder Singh 		}
1999d75c371eSJasvinder Singh 
2000d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 3], "size") != 0) {
2001d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2002d75c371eSJasvinder Singh 			return;
2003d75c371eSJasvinder Singh 		}
2004d75c371eSJasvinder Singh 
2005d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.array.n_keys,
2006d75c371eSJasvinder Singh 			tokens[t0 + 4]) != 0) {
2007d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2008d75c371eSJasvinder Singh 			return;
2009d75c371eSJasvinder Singh 		}
2010d75c371eSJasvinder Singh 
2011d75c371eSJasvinder Singh 		t0 += 5;
2012d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "hash") == 0) {
2013d75c371eSJasvinder Singh 		uint32_t key_mask_size = TABLE_RULE_MATCH_SIZE_MAX;
2014d75c371eSJasvinder Singh 
2015d75c371eSJasvinder Singh 		if (n_tokens < t0 + 12) {
2016d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
2017d75c371eSJasvinder Singh 				"pipeline table hash");
2018d75c371eSJasvinder Singh 			return;
2019d75c371eSJasvinder Singh 		}
2020d75c371eSJasvinder Singh 
2021d75c371eSJasvinder Singh 		p.match_type = TABLE_HASH;
2022d75c371eSJasvinder Singh 
2023d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "ext") == 0)
2024d75c371eSJasvinder Singh 			p.match.hash.extendable_bucket = 1;
2025d75c371eSJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "lru") == 0)
2026d75c371eSJasvinder Singh 			p.match.hash.extendable_bucket = 0;
2027d75c371eSJasvinder Singh 		else {
2028d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2029d75c371eSJasvinder Singh 				"ext or lru");
2030d75c371eSJasvinder Singh 			return;
2031d75c371eSJasvinder Singh 		}
2032d75c371eSJasvinder Singh 
2033d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 2], "key") != 0) {
2034d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "key");
2035d75c371eSJasvinder Singh 			return;
2036d75c371eSJasvinder Singh 		}
2037d75c371eSJasvinder Singh 
2038d75c371eSJasvinder Singh 		if ((parser_read_uint32(&p.match.hash.key_size,
2039d75c371eSJasvinder Singh 			tokens[t0 + 3]) != 0) ||
2040d75c371eSJasvinder Singh 			(p.match.hash.key_size == 0) ||
2041d75c371eSJasvinder Singh 			(p.match.hash.key_size > TABLE_RULE_MATCH_SIZE_MAX)) {
2042d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_size");
2043d75c371eSJasvinder Singh 			return;
2044d75c371eSJasvinder Singh 		}
2045d75c371eSJasvinder Singh 
2046d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 4], "mask") != 0) {
2047d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "mask");
2048d75c371eSJasvinder Singh 			return;
2049d75c371eSJasvinder Singh 		}
2050d75c371eSJasvinder Singh 
2051d75c371eSJasvinder Singh 		if ((parse_hex_string(tokens[t0 + 5],
2052d75c371eSJasvinder Singh 			key_mask, &key_mask_size) != 0) ||
2053d75c371eSJasvinder Singh 			(key_mask_size != p.match.hash.key_size)) {
2054d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_mask");
2055d75c371eSJasvinder Singh 			return;
2056d75c371eSJasvinder Singh 		}
2057d75c371eSJasvinder Singh 		p.match.hash.key_mask = key_mask;
2058d75c371eSJasvinder Singh 
2059d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 6], "offset") != 0) {
2060d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2061d75c371eSJasvinder Singh 			return;
2062d75c371eSJasvinder Singh 		}
2063d75c371eSJasvinder Singh 
2064d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.hash.key_offset,
2065d75c371eSJasvinder Singh 			tokens[t0 + 7]) != 0) {
2066d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2067d75c371eSJasvinder Singh 			return;
2068d75c371eSJasvinder Singh 		}
2069d75c371eSJasvinder Singh 
2070d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 8], "buckets") != 0) {
2071d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "buckets");
2072d75c371eSJasvinder Singh 			return;
2073d75c371eSJasvinder Singh 		}
2074d75c371eSJasvinder Singh 
2075d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.hash.n_buckets,
2076d75c371eSJasvinder Singh 			tokens[t0 + 9]) != 0) {
2077d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_buckets");
2078d75c371eSJasvinder Singh 			return;
2079d75c371eSJasvinder Singh 		}
2080d75c371eSJasvinder Singh 
2081d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 10], "size") != 0) {
2082d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2083d75c371eSJasvinder Singh 			return;
2084d75c371eSJasvinder Singh 		}
2085d75c371eSJasvinder Singh 
2086d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.hash.n_keys,
2087d75c371eSJasvinder Singh 			tokens[t0 + 11]) != 0) {
2088d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_keys");
2089d75c371eSJasvinder Singh 			return;
2090d75c371eSJasvinder Singh 		}
2091d75c371eSJasvinder Singh 
2092d75c371eSJasvinder Singh 		t0 += 12;
2093d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "lpm") == 0) {
2094d75c371eSJasvinder Singh 		if (n_tokens < t0 + 6) {
2095d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
2096d75c371eSJasvinder Singh 				"pipeline table lpm");
2097d75c371eSJasvinder Singh 			return;
2098d75c371eSJasvinder Singh 		}
2099d75c371eSJasvinder Singh 
2100d75c371eSJasvinder Singh 		p.match_type = TABLE_LPM;
2101d75c371eSJasvinder Singh 
2102d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 1], "ipv4") == 0)
2103d75c371eSJasvinder Singh 			p.match.lpm.key_size = 4;
2104d75c371eSJasvinder Singh 		else if (strcmp(tokens[t0 + 1], "ipv6") == 0)
2105d75c371eSJasvinder Singh 			p.match.lpm.key_size = 16;
2106d75c371eSJasvinder Singh 		else {
2107d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2108d75c371eSJasvinder Singh 				"ipv4 or ipv6");
2109d75c371eSJasvinder Singh 			return;
2110d75c371eSJasvinder Singh 		}
2111d75c371eSJasvinder Singh 
2112d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 2], "offset") != 0) {
2113d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "offset");
2114d75c371eSJasvinder Singh 			return;
2115d75c371eSJasvinder Singh 		}
2116d75c371eSJasvinder Singh 
2117d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.lpm.key_offset,
2118d75c371eSJasvinder Singh 			tokens[t0 + 3]) != 0) {
2119d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "key_offset");
2120d75c371eSJasvinder Singh 			return;
2121d75c371eSJasvinder Singh 		}
2122d75c371eSJasvinder Singh 
2123d75c371eSJasvinder Singh 		if (strcmp(tokens[t0 + 4], "size") != 0) {
2124d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "size");
2125d75c371eSJasvinder Singh 			return;
2126d75c371eSJasvinder Singh 		}
2127d75c371eSJasvinder Singh 
2128d75c371eSJasvinder Singh 		if (parser_read_uint32(&p.match.lpm.n_rules,
2129d75c371eSJasvinder Singh 			tokens[t0 + 5]) != 0) {
2130d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "n_rules");
2131d75c371eSJasvinder Singh 			return;
2132d75c371eSJasvinder Singh 		}
2133d75c371eSJasvinder Singh 
2134d75c371eSJasvinder Singh 		t0 += 6;
2135d75c371eSJasvinder Singh 	} else if (strcmp(tokens[t0], "stub") == 0) {
2136d75c371eSJasvinder Singh 		p.match_type = TABLE_STUB;
2137d75c371eSJasvinder Singh 
2138d75c371eSJasvinder Singh 		t0 += 1;
2139d75c371eSJasvinder Singh 	} else {
2140d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
2141d75c371eSJasvinder Singh 		return;
2142d75c371eSJasvinder Singh 	}
2143d75c371eSJasvinder Singh 
2144d75c371eSJasvinder Singh 	p.action_profile_name = NULL;
2145d75c371eSJasvinder Singh 	if ((n_tokens > t0) && (strcmp(tokens[t0], "action") == 0)) {
2146d75c371eSJasvinder Singh 		if (n_tokens < t0 + 2) {
2147d75c371eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, "action");
2148d75c371eSJasvinder Singh 			return;
2149d75c371eSJasvinder Singh 		}
2150d75c371eSJasvinder Singh 
2151d75c371eSJasvinder Singh 		p.action_profile_name = tokens[t0 + 1];
2152d75c371eSJasvinder Singh 
2153d75c371eSJasvinder Singh 		t0 += 2;
2154d75c371eSJasvinder Singh 	}
2155d75c371eSJasvinder Singh 
2156d75c371eSJasvinder Singh 	if (n_tokens > t0) {
2157d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2158d75c371eSJasvinder Singh 		return;
2159d75c371eSJasvinder Singh 	}
2160d75c371eSJasvinder Singh 
2161d75c371eSJasvinder Singh 	status = pipeline_table_create(pipeline_name, &p);
2162d75c371eSJasvinder Singh 	if (status) {
2163d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2164d75c371eSJasvinder Singh 		return;
2165d75c371eSJasvinder Singh 	}
2166d75c371eSJasvinder Singh }
2167d75c371eSJasvinder Singh 
216826b3effeSKevin Laatz static const char cmd_pipeline_port_in_table_help[] =
216926b3effeSKevin Laatz "pipeline <pipeline_name> port in <port_id> table <table_id>\n";
217026b3effeSKevin Laatz 
2171d75c371eSJasvinder Singh static void
2172d75c371eSJasvinder Singh cmd_pipeline_port_in_table(char **tokens,
2173d75c371eSJasvinder Singh 	uint32_t n_tokens,
2174d75c371eSJasvinder Singh 	char *out,
2175d75c371eSJasvinder Singh 	size_t out_size)
2176d75c371eSJasvinder Singh {
2177d75c371eSJasvinder Singh 	char *pipeline_name;
2178d75c371eSJasvinder Singh 	uint32_t port_id, table_id;
2179d75c371eSJasvinder Singh 	int status;
2180d75c371eSJasvinder Singh 
2181d75c371eSJasvinder Singh 	if (n_tokens != 7) {
2182d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2183d75c371eSJasvinder Singh 		return;
2184d75c371eSJasvinder Singh 	}
2185d75c371eSJasvinder Singh 
2186d75c371eSJasvinder Singh 	pipeline_name = tokens[1];
2187d75c371eSJasvinder Singh 
2188d75c371eSJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
2189d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
2190d75c371eSJasvinder Singh 		return;
2191d75c371eSJasvinder Singh 	}
2192d75c371eSJasvinder Singh 
2193d75c371eSJasvinder Singh 	if (strcmp(tokens[3], "in") != 0) {
2194d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
2195d75c371eSJasvinder Singh 		return;
2196d75c371eSJasvinder Singh 	}
2197d75c371eSJasvinder Singh 
2198d75c371eSJasvinder Singh 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
2199d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
2200d75c371eSJasvinder Singh 		return;
2201d75c371eSJasvinder Singh 	}
2202d75c371eSJasvinder Singh 
2203d75c371eSJasvinder Singh 	if (strcmp(tokens[5], "table") != 0) {
2204d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
2205d75c371eSJasvinder Singh 		return;
2206d75c371eSJasvinder Singh 	}
2207d75c371eSJasvinder Singh 
2208d75c371eSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[6]) != 0) {
2209d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
2210d75c371eSJasvinder Singh 		return;
2211d75c371eSJasvinder Singh 	}
2212d75c371eSJasvinder Singh 
2213d75c371eSJasvinder Singh 	status = pipeline_port_in_connect_to_table(pipeline_name,
2214d75c371eSJasvinder Singh 		port_id,
2215d75c371eSJasvinder Singh 		table_id);
2216d75c371eSJasvinder Singh 	if (status) {
2217d75c371eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
2218d75c371eSJasvinder Singh 		return;
2219d75c371eSJasvinder Singh 	}
2220d75c371eSJasvinder Singh }
2221d75c371eSJasvinder Singh 
222226b3effeSKevin Laatz 
222326b3effeSKevin Laatz static const char cmd_pipeline_port_in_stats_help[] =
222426b3effeSKevin Laatz "pipeline <pipeline_name> port in <port_id> stats read [clear]\n";
222550e73d05SJasvinder Singh 
222650e73d05SJasvinder Singh #define MSG_PIPELINE_PORT_IN_STATS                         \
222750e73d05SJasvinder Singh 	"Pkts in: %" PRIu64 "\n"                           \
222850e73d05SJasvinder Singh 	"Pkts dropped by AH: %" PRIu64 "\n"                \
222950e73d05SJasvinder Singh 	"Pkts dropped by other: %" PRIu64 "\n"
223050e73d05SJasvinder Singh 
223150e73d05SJasvinder Singh static void
223250e73d05SJasvinder Singh cmd_pipeline_port_in_stats(char **tokens,
223350e73d05SJasvinder Singh 	uint32_t n_tokens,
223450e73d05SJasvinder Singh 	char *out,
223550e73d05SJasvinder Singh 	size_t out_size)
223650e73d05SJasvinder Singh {
223750e73d05SJasvinder Singh 	struct rte_pipeline_port_in_stats stats;
223850e73d05SJasvinder Singh 	char *pipeline_name;
223950e73d05SJasvinder Singh 	uint32_t port_id;
224050e73d05SJasvinder Singh 	int clear, status;
224150e73d05SJasvinder Singh 
224250e73d05SJasvinder Singh 	if ((n_tokens != 7) && (n_tokens != 8)) {
224350e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
224450e73d05SJasvinder Singh 		return;
224550e73d05SJasvinder Singh 	}
224650e73d05SJasvinder Singh 
224750e73d05SJasvinder Singh 	pipeline_name = tokens[1];
224850e73d05SJasvinder Singh 
224950e73d05SJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
225050e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
225150e73d05SJasvinder Singh 		return;
225250e73d05SJasvinder Singh 	}
225350e73d05SJasvinder Singh 
225450e73d05SJasvinder Singh 	if (strcmp(tokens[3], "in") != 0) {
225550e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
225650e73d05SJasvinder Singh 		return;
225750e73d05SJasvinder Singh 	}
225850e73d05SJasvinder Singh 
225950e73d05SJasvinder Singh 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
226050e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
226150e73d05SJasvinder Singh 		return;
226250e73d05SJasvinder Singh 	}
226350e73d05SJasvinder Singh 
226450e73d05SJasvinder Singh 	if (strcmp(tokens[5], "stats") != 0) {
226550e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
226650e73d05SJasvinder Singh 		return;
226750e73d05SJasvinder Singh 	}
226850e73d05SJasvinder Singh 
226950e73d05SJasvinder Singh 	if (strcmp(tokens[6], "read") != 0) {
227050e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
227150e73d05SJasvinder Singh 		return;
227250e73d05SJasvinder Singh 	}
227350e73d05SJasvinder Singh 
227450e73d05SJasvinder Singh 	clear = 0;
227550e73d05SJasvinder Singh 	if (n_tokens == 8) {
227650e73d05SJasvinder Singh 		if (strcmp(tokens[7], "clear") != 0) {
227750e73d05SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "clear");
227850e73d05SJasvinder Singh 			return;
227950e73d05SJasvinder Singh 		}
228050e73d05SJasvinder Singh 
228150e73d05SJasvinder Singh 		clear = 1;
228250e73d05SJasvinder Singh 	}
228350e73d05SJasvinder Singh 
228450e73d05SJasvinder Singh 	status = pipeline_port_in_stats_read(pipeline_name,
228550e73d05SJasvinder Singh 		port_id,
228650e73d05SJasvinder Singh 		&stats,
228750e73d05SJasvinder Singh 		clear);
228850e73d05SJasvinder Singh 	if (status) {
228950e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
229050e73d05SJasvinder Singh 		return;
229150e73d05SJasvinder Singh 	}
229250e73d05SJasvinder Singh 
229350e73d05SJasvinder Singh 	snprintf(out, out_size, MSG_PIPELINE_PORT_IN_STATS,
229450e73d05SJasvinder Singh 		stats.stats.n_pkts_in,
229550e73d05SJasvinder Singh 		stats.n_pkts_dropped_by_ah,
229650e73d05SJasvinder Singh 		stats.stats.n_pkts_drop);
229750e73d05SJasvinder Singh }
229850e73d05SJasvinder Singh 
229926b3effeSKevin Laatz 
230026b3effeSKevin Laatz static const char cmd_pipeline_port_in_enable_help[] =
230126b3effeSKevin Laatz "pipeline <pipeline_name> port in <port_id> enable\n";
230226b3effeSKevin Laatz 
23036b1b3c3cSJasvinder Singh static void
23046b1b3c3cSJasvinder Singh cmd_pipeline_port_in_enable(char **tokens,
23056b1b3c3cSJasvinder Singh 	uint32_t n_tokens,
23066b1b3c3cSJasvinder Singh 	char *out,
23076b1b3c3cSJasvinder Singh 	size_t out_size)
23086b1b3c3cSJasvinder Singh {
23096b1b3c3cSJasvinder Singh 	char *pipeline_name;
23106b1b3c3cSJasvinder Singh 	uint32_t port_id;
23116b1b3c3cSJasvinder Singh 	int status;
23126b1b3c3cSJasvinder Singh 
23136b1b3c3cSJasvinder Singh 	if (n_tokens != 6) {
23146b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
23156b1b3c3cSJasvinder Singh 		return;
23166b1b3c3cSJasvinder Singh 	}
23176b1b3c3cSJasvinder Singh 
23186b1b3c3cSJasvinder Singh 	pipeline_name = tokens[1];
23196b1b3c3cSJasvinder Singh 
23206b1b3c3cSJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
23216b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
23226b1b3c3cSJasvinder Singh 		return;
23236b1b3c3cSJasvinder Singh 	}
23246b1b3c3cSJasvinder Singh 
23256b1b3c3cSJasvinder Singh 	if (strcmp(tokens[3], "in") != 0) {
23266b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
23276b1b3c3cSJasvinder Singh 		return;
23286b1b3c3cSJasvinder Singh 	}
23296b1b3c3cSJasvinder Singh 
23306b1b3c3cSJasvinder Singh 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
23316b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
23326b1b3c3cSJasvinder Singh 		return;
23336b1b3c3cSJasvinder Singh 	}
23346b1b3c3cSJasvinder Singh 
23356b1b3c3cSJasvinder Singh 	if (strcmp(tokens[5], "enable") != 0) {
23366b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
23376b1b3c3cSJasvinder Singh 		return;
23386b1b3c3cSJasvinder Singh 	}
23396b1b3c3cSJasvinder Singh 
23406b1b3c3cSJasvinder Singh 	status = pipeline_port_in_enable(pipeline_name, port_id);
23416b1b3c3cSJasvinder Singh 	if (status) {
23426b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
23436b1b3c3cSJasvinder Singh 		return;
23446b1b3c3cSJasvinder Singh 	}
23456b1b3c3cSJasvinder Singh }
23466b1b3c3cSJasvinder Singh 
234726b3effeSKevin Laatz 
234826b3effeSKevin Laatz static const char cmd_pipeline_port_in_disable_help[] =
234926b3effeSKevin Laatz "pipeline <pipeline_name> port in <port_id> disable\n";
235026b3effeSKevin Laatz 
23516b1b3c3cSJasvinder Singh static void
23526b1b3c3cSJasvinder Singh cmd_pipeline_port_in_disable(char **tokens,
23536b1b3c3cSJasvinder Singh 	uint32_t n_tokens,
23546b1b3c3cSJasvinder Singh 	char *out,
23556b1b3c3cSJasvinder Singh 	size_t out_size)
23566b1b3c3cSJasvinder Singh {
23576b1b3c3cSJasvinder Singh 	char *pipeline_name;
23586b1b3c3cSJasvinder Singh 	uint32_t port_id;
23596b1b3c3cSJasvinder Singh 	int status;
23606b1b3c3cSJasvinder Singh 
23616b1b3c3cSJasvinder Singh 	if (n_tokens != 6) {
23626b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
23636b1b3c3cSJasvinder Singh 		return;
23646b1b3c3cSJasvinder Singh 	}
23656b1b3c3cSJasvinder Singh 
23666b1b3c3cSJasvinder Singh 	pipeline_name = tokens[1];
23676b1b3c3cSJasvinder Singh 
23686b1b3c3cSJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
23696b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
23706b1b3c3cSJasvinder Singh 		return;
23716b1b3c3cSJasvinder Singh 	}
23726b1b3c3cSJasvinder Singh 
23736b1b3c3cSJasvinder Singh 	if (strcmp(tokens[3], "in") != 0) {
23746b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "in");
23756b1b3c3cSJasvinder Singh 		return;
23766b1b3c3cSJasvinder Singh 	}
23776b1b3c3cSJasvinder Singh 
23786b1b3c3cSJasvinder Singh 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
23796b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
23806b1b3c3cSJasvinder Singh 		return;
23816b1b3c3cSJasvinder Singh 	}
23826b1b3c3cSJasvinder Singh 
23836b1b3c3cSJasvinder Singh 	if (strcmp(tokens[5], "disable") != 0) {
23846b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
23856b1b3c3cSJasvinder Singh 		return;
23866b1b3c3cSJasvinder Singh 	}
23876b1b3c3cSJasvinder Singh 
23886b1b3c3cSJasvinder Singh 	status = pipeline_port_in_disable(pipeline_name, port_id);
23896b1b3c3cSJasvinder Singh 	if (status) {
23906b1b3c3cSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
23916b1b3c3cSJasvinder Singh 		return;
23926b1b3c3cSJasvinder Singh 	}
23936b1b3c3cSJasvinder Singh }
23946b1b3c3cSJasvinder Singh 
239526b3effeSKevin Laatz 
239626b3effeSKevin Laatz static const char cmd_pipeline_port_out_stats_help[] =
239726b3effeSKevin Laatz "pipeline <pipeline_name> port out <port_id> stats read [clear]\n";
239826b3effeSKevin Laatz 
239950e73d05SJasvinder Singh #define MSG_PIPELINE_PORT_OUT_STATS                        \
240050e73d05SJasvinder Singh 	"Pkts in: %" PRIu64 "\n"                           \
240150e73d05SJasvinder Singh 	"Pkts dropped by AH: %" PRIu64 "\n"                \
240250e73d05SJasvinder Singh 	"Pkts dropped by other: %" PRIu64 "\n"
240350e73d05SJasvinder Singh 
240450e73d05SJasvinder Singh static void
240550e73d05SJasvinder Singh cmd_pipeline_port_out_stats(char **tokens,
240650e73d05SJasvinder Singh 	uint32_t n_tokens,
240750e73d05SJasvinder Singh 	char *out,
240850e73d05SJasvinder Singh 	size_t out_size)
240950e73d05SJasvinder Singh {
241050e73d05SJasvinder Singh 	struct rte_pipeline_port_out_stats stats;
241150e73d05SJasvinder Singh 	char *pipeline_name;
241250e73d05SJasvinder Singh 	uint32_t port_id;
241350e73d05SJasvinder Singh 	int clear, status;
241450e73d05SJasvinder Singh 
241550e73d05SJasvinder Singh 	if ((n_tokens != 7) && (n_tokens != 8)) {
241650e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
241750e73d05SJasvinder Singh 		return;
241850e73d05SJasvinder Singh 	}
241950e73d05SJasvinder Singh 
242050e73d05SJasvinder Singh 	pipeline_name = tokens[1];
242150e73d05SJasvinder Singh 
242250e73d05SJasvinder Singh 	if (strcmp(tokens[2], "port") != 0) {
242350e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
242450e73d05SJasvinder Singh 		return;
242550e73d05SJasvinder Singh 	}
242650e73d05SJasvinder Singh 
242750e73d05SJasvinder Singh 	if (strcmp(tokens[3], "out") != 0) {
242850e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "out");
242950e73d05SJasvinder Singh 		return;
243050e73d05SJasvinder Singh 	}
243150e73d05SJasvinder Singh 
243250e73d05SJasvinder Singh 	if (parser_read_uint32(&port_id, tokens[4]) != 0) {
243350e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
243450e73d05SJasvinder Singh 		return;
243550e73d05SJasvinder Singh 	}
243650e73d05SJasvinder Singh 
243750e73d05SJasvinder Singh 	if (strcmp(tokens[5], "stats") != 0) {
243850e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
243950e73d05SJasvinder Singh 		return;
244050e73d05SJasvinder Singh 	}
244150e73d05SJasvinder Singh 
244250e73d05SJasvinder Singh 	if (strcmp(tokens[6], "read") != 0) {
244350e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
244450e73d05SJasvinder Singh 		return;
244550e73d05SJasvinder Singh 	}
244650e73d05SJasvinder Singh 
244750e73d05SJasvinder Singh 	clear = 0;
244850e73d05SJasvinder Singh 	if (n_tokens == 8) {
244950e73d05SJasvinder Singh 		if (strcmp(tokens[7], "clear") != 0) {
245050e73d05SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "clear");
245150e73d05SJasvinder Singh 			return;
245250e73d05SJasvinder Singh 		}
245350e73d05SJasvinder Singh 
245450e73d05SJasvinder Singh 		clear = 1;
245550e73d05SJasvinder Singh 	}
245650e73d05SJasvinder Singh 
245750e73d05SJasvinder Singh 	status = pipeline_port_out_stats_read(pipeline_name,
245850e73d05SJasvinder Singh 		port_id,
245950e73d05SJasvinder Singh 		&stats,
246050e73d05SJasvinder Singh 		clear);
246150e73d05SJasvinder Singh 	if (status) {
246250e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
246350e73d05SJasvinder Singh 		return;
246450e73d05SJasvinder Singh 	}
246550e73d05SJasvinder Singh 
246650e73d05SJasvinder Singh 	snprintf(out, out_size, MSG_PIPELINE_PORT_OUT_STATS,
246750e73d05SJasvinder Singh 		stats.stats.n_pkts_in,
246850e73d05SJasvinder Singh 		stats.n_pkts_dropped_by_ah,
246950e73d05SJasvinder Singh 		stats.stats.n_pkts_drop);
247050e73d05SJasvinder Singh }
247150e73d05SJasvinder Singh 
247226b3effeSKevin Laatz 
247326b3effeSKevin Laatz static const char cmd_pipeline_table_stats_help[] =
247426b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> stats read [clear]\n";
247526b3effeSKevin Laatz 
247650e73d05SJasvinder Singh #define MSG_PIPELINE_TABLE_STATS                                     \
247750e73d05SJasvinder Singh 	"Pkts in: %" PRIu64 "\n"                                     \
247850e73d05SJasvinder Singh 	"Pkts in with lookup miss: %" PRIu64 "\n"                    \
247950e73d05SJasvinder Singh 	"Pkts in with lookup hit dropped by AH: %" PRIu64 "\n"       \
248050e73d05SJasvinder Singh 	"Pkts in with lookup hit dropped by others: %" PRIu64 "\n"   \
248150e73d05SJasvinder Singh 	"Pkts in with lookup miss dropped by AH: %" PRIu64 "\n"      \
248250e73d05SJasvinder Singh 	"Pkts in with lookup miss dropped by others: %" PRIu64 "\n"
248350e73d05SJasvinder Singh 
248450e73d05SJasvinder Singh static void
248550e73d05SJasvinder Singh cmd_pipeline_table_stats(char **tokens,
248650e73d05SJasvinder Singh 	uint32_t n_tokens,
248750e73d05SJasvinder Singh 	char *out,
248850e73d05SJasvinder Singh 	size_t out_size)
248950e73d05SJasvinder Singh {
249050e73d05SJasvinder Singh 	struct rte_pipeline_table_stats stats;
249150e73d05SJasvinder Singh 	char *pipeline_name;
249250e73d05SJasvinder Singh 	uint32_t table_id;
249350e73d05SJasvinder Singh 	int clear, status;
249450e73d05SJasvinder Singh 
249550e73d05SJasvinder Singh 	if ((n_tokens != 6) && (n_tokens != 7)) {
249650e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
249750e73d05SJasvinder Singh 		return;
249850e73d05SJasvinder Singh 	}
249950e73d05SJasvinder Singh 
250050e73d05SJasvinder Singh 	pipeline_name = tokens[1];
250150e73d05SJasvinder Singh 
250250e73d05SJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
250350e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
250450e73d05SJasvinder Singh 		return;
250550e73d05SJasvinder Singh 	}
250650e73d05SJasvinder Singh 
250750e73d05SJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
250850e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
250950e73d05SJasvinder Singh 		return;
251050e73d05SJasvinder Singh 	}
251150e73d05SJasvinder Singh 
251250e73d05SJasvinder Singh 	if (strcmp(tokens[4], "stats") != 0) {
251350e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
251450e73d05SJasvinder Singh 		return;
251550e73d05SJasvinder Singh 	}
251650e73d05SJasvinder Singh 
251750e73d05SJasvinder Singh 	if (strcmp(tokens[5], "read") != 0) {
251850e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
251950e73d05SJasvinder Singh 		return;
252050e73d05SJasvinder Singh 	}
252150e73d05SJasvinder Singh 
252250e73d05SJasvinder Singh 	clear = 0;
252350e73d05SJasvinder Singh 	if (n_tokens == 7) {
252450e73d05SJasvinder Singh 		if (strcmp(tokens[6], "clear") != 0) {
252550e73d05SJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "clear");
252650e73d05SJasvinder Singh 			return;
252750e73d05SJasvinder Singh 		}
252850e73d05SJasvinder Singh 
252950e73d05SJasvinder Singh 		clear = 1;
253050e73d05SJasvinder Singh 	}
253150e73d05SJasvinder Singh 
253250e73d05SJasvinder Singh 	status = pipeline_table_stats_read(pipeline_name,
253350e73d05SJasvinder Singh 		table_id,
253450e73d05SJasvinder Singh 		&stats,
253550e73d05SJasvinder Singh 		clear);
253650e73d05SJasvinder Singh 	if (status) {
253750e73d05SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
253850e73d05SJasvinder Singh 		return;
253950e73d05SJasvinder Singh 	}
254050e73d05SJasvinder Singh 
254150e73d05SJasvinder Singh 	snprintf(out, out_size, MSG_PIPELINE_TABLE_STATS,
254250e73d05SJasvinder Singh 		stats.stats.n_pkts_in,
254350e73d05SJasvinder Singh 		stats.stats.n_pkts_lookup_miss,
254450e73d05SJasvinder Singh 		stats.n_pkts_dropped_by_lkp_hit_ah,
254550e73d05SJasvinder Singh 		stats.n_pkts_dropped_lkp_hit,
254650e73d05SJasvinder Singh 		stats.n_pkts_dropped_by_lkp_miss_ah,
254750e73d05SJasvinder Singh 		stats.n_pkts_dropped_lkp_miss);
254850e73d05SJasvinder Singh }
254950e73d05SJasvinder Singh 
255050e73d05SJasvinder Singh /**
2551a3a95b7dSJasvinder Singh  * <match> ::=
2552a3a95b7dSJasvinder Singh  *
2553a3a95b7dSJasvinder Singh  * match
2554a3a95b7dSJasvinder Singh  *    acl
2555a3a95b7dSJasvinder Singh  *       priority <priority>
2556a3a95b7dSJasvinder Singh  *       ipv4 | ipv6 <sa> <sa_depth> <da> <da_depth>
2557a3a95b7dSJasvinder Singh  *       <sp0> <sp1> <dp0> <dp1> <proto>
2558085c3d8cSJasvinder Singh  *    | array <pos>
2559a3a95b7dSJasvinder Singh  *    | hash
2560a3a95b7dSJasvinder Singh  *       raw <key>
2561a3a95b7dSJasvinder Singh  *       | ipv4_5tuple <sa> <da> <sp> <dp> <proto>
2562a3a95b7dSJasvinder Singh  *       | ipv6_5tuple <sa> <da> <sp> <dp> <proto>
2563a3a95b7dSJasvinder Singh  *       | ipv4_addr <addr>
2564a3a95b7dSJasvinder Singh  *       | ipv6_addr <addr>
2565a3a95b7dSJasvinder Singh  *       | qinq <svlan> <cvlan>
2566a3a95b7dSJasvinder Singh  *    | lpm
2567a3a95b7dSJasvinder Singh  *       ipv4 | ipv6 <addr> <depth>
2568a3a95b7dSJasvinder Singh  */
2569a3a95b7dSJasvinder Singh struct pkt_key_qinq {
2570a3a95b7dSJasvinder Singh 	uint16_t ethertype_svlan;
2571a3a95b7dSJasvinder Singh 	uint16_t svlan;
2572a3a95b7dSJasvinder Singh 	uint16_t ethertype_cvlan;
2573a3a95b7dSJasvinder Singh 	uint16_t cvlan;
2574*37e33391SAndre Muezerie };
2575a3a95b7dSJasvinder Singh 
2576a3a95b7dSJasvinder Singh struct pkt_key_ipv4_5tuple {
2577a3a95b7dSJasvinder Singh 	uint8_t time_to_live;
2578a3a95b7dSJasvinder Singh 	uint8_t proto;
2579a3a95b7dSJasvinder Singh 	uint16_t hdr_checksum;
2580a3a95b7dSJasvinder Singh 	uint32_t sa;
2581a3a95b7dSJasvinder Singh 	uint32_t da;
2582a3a95b7dSJasvinder Singh 	uint16_t sp;
2583a3a95b7dSJasvinder Singh 	uint16_t dp;
2584*37e33391SAndre Muezerie };
2585a3a95b7dSJasvinder Singh 
2586a3a95b7dSJasvinder Singh struct pkt_key_ipv6_5tuple {
2587a3a95b7dSJasvinder Singh 	uint16_t payload_length;
2588a3a95b7dSJasvinder Singh 	uint8_t proto;
2589a3a95b7dSJasvinder Singh 	uint8_t hop_limit;
25905ac1abddSRobin Jarry 	struct rte_ipv6_addr sa;
25915ac1abddSRobin Jarry 	struct rte_ipv6_addr da;
2592a3a95b7dSJasvinder Singh 	uint16_t sp;
2593a3a95b7dSJasvinder Singh 	uint16_t dp;
2594*37e33391SAndre Muezerie };
2595a3a95b7dSJasvinder Singh 
2596a3a95b7dSJasvinder Singh struct pkt_key_ipv4_addr {
2597a3a95b7dSJasvinder Singh 	uint32_t addr;
2598*37e33391SAndre Muezerie };
2599a3a95b7dSJasvinder Singh 
2600a3a95b7dSJasvinder Singh struct pkt_key_ipv6_addr {
26015ac1abddSRobin Jarry 	struct rte_ipv6_addr addr;
2602*37e33391SAndre Muezerie };
2603a3a95b7dSJasvinder Singh 
2604a3a95b7dSJasvinder Singh static uint32_t
2605a3a95b7dSJasvinder Singh parse_match(char **tokens,
2606a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
2607a3a95b7dSJasvinder Singh 	char *out,
2608a3a95b7dSJasvinder Singh 	size_t out_size,
2609a3a95b7dSJasvinder Singh 	struct table_rule_match *m)
2610a3a95b7dSJasvinder Singh {
2611a3a95b7dSJasvinder Singh 	memset(m, 0, sizeof(*m));
2612a3a95b7dSJasvinder Singh 
2613a3a95b7dSJasvinder Singh 	if (n_tokens < 2)
2614a3a95b7dSJasvinder Singh 		return 0;
2615a3a95b7dSJasvinder Singh 
2616a3a95b7dSJasvinder Singh 	if (strcmp(tokens[0], "match") != 0) {
2617a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
2618a3a95b7dSJasvinder Singh 		return 0;
2619a3a95b7dSJasvinder Singh 	}
2620a3a95b7dSJasvinder Singh 
2621a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "acl") == 0) {
2622a3a95b7dSJasvinder Singh 		if (n_tokens < 14) {
2623a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2624a3a95b7dSJasvinder Singh 			return 0;
2625a3a95b7dSJasvinder Singh 		}
2626a3a95b7dSJasvinder Singh 
2627a3a95b7dSJasvinder Singh 		m->match_type = TABLE_ACL;
2628a3a95b7dSJasvinder Singh 
2629a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "priority") != 0) {
2630a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "priority");
2631a3a95b7dSJasvinder Singh 			return 0;
2632a3a95b7dSJasvinder Singh 		}
2633a3a95b7dSJasvinder Singh 
2634a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&m->match.acl.priority,
2635a3a95b7dSJasvinder Singh 			tokens[3]) != 0) {
2636a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "priority");
2637a3a95b7dSJasvinder Singh 			return 0;
2638a3a95b7dSJasvinder Singh 		}
2639a3a95b7dSJasvinder Singh 
2640a3a95b7dSJasvinder Singh 		if (strcmp(tokens[4], "ipv4") == 0) {
2641a3a95b7dSJasvinder Singh 			struct in_addr saddr, daddr;
2642a3a95b7dSJasvinder Singh 
2643a3a95b7dSJasvinder Singh 			m->match.acl.ip_version = 1;
2644a3a95b7dSJasvinder Singh 
2645a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[5], &saddr) != 0) {
2646a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2647a3a95b7dSJasvinder Singh 				return 0;
2648a3a95b7dSJasvinder Singh 			}
2649a3a95b7dSJasvinder Singh 			m->match.acl.ipv4.sa = rte_be_to_cpu_32(saddr.s_addr);
2650a3a95b7dSJasvinder Singh 
2651a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[7], &daddr) != 0) {
2652a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "da");
2653a3a95b7dSJasvinder Singh 				return 0;
2654a3a95b7dSJasvinder Singh 			}
2655a3a95b7dSJasvinder Singh 			m->match.acl.ipv4.da = rte_be_to_cpu_32(daddr.s_addr);
2656a3a95b7dSJasvinder Singh 		} else if (strcmp(tokens[4], "ipv6") == 0) {
26575ac1abddSRobin Jarry 			struct rte_ipv6_addr saddr, daddr;
2658a3a95b7dSJasvinder Singh 
2659a3a95b7dSJasvinder Singh 			m->match.acl.ip_version = 0;
2660a3a95b7dSJasvinder Singh 
2661a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[5], &saddr) != 0) {
2662a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2663a3a95b7dSJasvinder Singh 				return 0;
2664a3a95b7dSJasvinder Singh 			}
26655ac1abddSRobin Jarry 			m->match.acl.ipv6.sa = saddr;
2666a3a95b7dSJasvinder Singh 
2667a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[7], &daddr) != 0) {
2668a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "da");
2669a3a95b7dSJasvinder Singh 				return 0;
2670a3a95b7dSJasvinder Singh 			}
26715ac1abddSRobin Jarry 			m->match.acl.ipv6.da = daddr;
2672a3a95b7dSJasvinder Singh 		} else {
2673a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND,
2674a3a95b7dSJasvinder Singh 				"ipv4 or ipv6");
2675a3a95b7dSJasvinder Singh 			return 0;
2676a3a95b7dSJasvinder Singh 		}
2677a3a95b7dSJasvinder Singh 
2678a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&m->match.acl.sa_depth,
2679a3a95b7dSJasvinder Singh 			tokens[6]) != 0) {
2680a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "sa_depth");
2681a3a95b7dSJasvinder Singh 			return 0;
2682a3a95b7dSJasvinder Singh 		}
2683a3a95b7dSJasvinder Singh 
2684a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&m->match.acl.da_depth,
2685a3a95b7dSJasvinder Singh 			tokens[8]) != 0) {
2686a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "da_depth");
2687a3a95b7dSJasvinder Singh 			return 0;
2688a3a95b7dSJasvinder Singh 		}
2689a3a95b7dSJasvinder Singh 
2690a3a95b7dSJasvinder Singh 		if (parser_read_uint16(&m->match.acl.sp0, tokens[9]) != 0) {
2691a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "sp0");
2692a3a95b7dSJasvinder Singh 			return 0;
2693a3a95b7dSJasvinder Singh 		}
2694a3a95b7dSJasvinder Singh 
2695a3a95b7dSJasvinder Singh 		if (parser_read_uint16(&m->match.acl.sp1, tokens[10]) != 0) {
2696a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "sp1");
2697a3a95b7dSJasvinder Singh 			return 0;
2698a3a95b7dSJasvinder Singh 		}
2699a3a95b7dSJasvinder Singh 
2700a3a95b7dSJasvinder Singh 		if (parser_read_uint16(&m->match.acl.dp0, tokens[11]) != 0) {
2701a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "dp0");
2702a3a95b7dSJasvinder Singh 			return 0;
2703a3a95b7dSJasvinder Singh 		}
2704a3a95b7dSJasvinder Singh 
2705a3a95b7dSJasvinder Singh 		if (parser_read_uint16(&m->match.acl.dp1, tokens[12]) != 0) {
2706a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "dp1");
2707a3a95b7dSJasvinder Singh 			return 0;
2708a3a95b7dSJasvinder Singh 		}
2709a3a95b7dSJasvinder Singh 
2710a3a95b7dSJasvinder Singh 		if (parser_read_uint8(&m->match.acl.proto, tokens[13]) != 0) {
2711a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "proto");
2712a3a95b7dSJasvinder Singh 			return 0;
2713a3a95b7dSJasvinder Singh 		}
2714a3a95b7dSJasvinder Singh 
2715a3a95b7dSJasvinder Singh 		m->match.acl.proto_mask = 0xff;
2716a3a95b7dSJasvinder Singh 
2717a3a95b7dSJasvinder Singh 		return 14;
2718a3a95b7dSJasvinder Singh 	} /* acl */
2719a3a95b7dSJasvinder Singh 
2720a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "array") == 0) {
2721a3a95b7dSJasvinder Singh 		if (n_tokens < 3) {
2722a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2723a3a95b7dSJasvinder Singh 			return 0;
2724a3a95b7dSJasvinder Singh 		}
2725a3a95b7dSJasvinder Singh 
2726a3a95b7dSJasvinder Singh 		m->match_type = TABLE_ARRAY;
2727a3a95b7dSJasvinder Singh 
2728a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&m->match.array.pos, tokens[2]) != 0) {
2729a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "pos");
2730a3a95b7dSJasvinder Singh 			return 0;
2731a3a95b7dSJasvinder Singh 		}
2732a3a95b7dSJasvinder Singh 
2733a3a95b7dSJasvinder Singh 		return 3;
2734a3a95b7dSJasvinder Singh 	} /* array */
2735a3a95b7dSJasvinder Singh 
2736a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "hash") == 0) {
2737a3a95b7dSJasvinder Singh 		if (n_tokens < 3) {
2738a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2739a3a95b7dSJasvinder Singh 			return 0;
2740a3a95b7dSJasvinder Singh 		}
2741a3a95b7dSJasvinder Singh 
2742a3a95b7dSJasvinder Singh 		m->match_type = TABLE_HASH;
2743a3a95b7dSJasvinder Singh 
2744a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "raw") == 0) {
2745a3a95b7dSJasvinder Singh 			uint32_t key_size = TABLE_RULE_MATCH_SIZE_MAX;
2746a3a95b7dSJasvinder Singh 
2747a3a95b7dSJasvinder Singh 			if (n_tokens < 4) {
2748a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2749a3a95b7dSJasvinder Singh 					tokens[0]);
2750a3a95b7dSJasvinder Singh 				return 0;
2751a3a95b7dSJasvinder Singh 			}
2752a3a95b7dSJasvinder Singh 
2753a3a95b7dSJasvinder Singh 			if (parse_hex_string(tokens[3],
2754a3a95b7dSJasvinder Singh 				m->match.hash.key, &key_size) != 0) {
2755a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "key");
2756a3a95b7dSJasvinder Singh 				return 0;
2757a3a95b7dSJasvinder Singh 			}
2758a3a95b7dSJasvinder Singh 
2759a3a95b7dSJasvinder Singh 			return 4;
2760a3a95b7dSJasvinder Singh 		} /* hash raw */
2761a3a95b7dSJasvinder Singh 
2762a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "ipv4_5tuple") == 0) {
2763a3a95b7dSJasvinder Singh 			struct pkt_key_ipv4_5tuple *ipv4 =
2764a3a95b7dSJasvinder Singh 				(struct pkt_key_ipv4_5tuple *) m->match.hash.key;
2765a3a95b7dSJasvinder Singh 			struct in_addr saddr, daddr;
2766a3a95b7dSJasvinder Singh 			uint16_t sp, dp;
2767a3a95b7dSJasvinder Singh 			uint8_t proto;
2768a3a95b7dSJasvinder Singh 
2769a3a95b7dSJasvinder Singh 			if (n_tokens < 8) {
2770a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2771a3a95b7dSJasvinder Singh 					tokens[0]);
2772a3a95b7dSJasvinder Singh 				return 0;
2773a3a95b7dSJasvinder Singh 			}
2774a3a95b7dSJasvinder Singh 
2775a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[3], &saddr) != 0) {
2776a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2777a3a95b7dSJasvinder Singh 				return 0;
2778a3a95b7dSJasvinder Singh 			}
2779a3a95b7dSJasvinder Singh 
2780a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[4], &daddr) != 0) {
2781a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "da");
2782a3a95b7dSJasvinder Singh 				return 0;
2783a3a95b7dSJasvinder Singh 			}
2784a3a95b7dSJasvinder Singh 
2785a3a95b7dSJasvinder Singh 			if (parser_read_uint16(&sp, tokens[5]) != 0) {
2786a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2787a3a95b7dSJasvinder Singh 				return 0;
2788a3a95b7dSJasvinder Singh 			}
2789a3a95b7dSJasvinder Singh 
2790a3a95b7dSJasvinder Singh 			if (parser_read_uint16(&dp, tokens[6]) != 0) {
2791a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2792a3a95b7dSJasvinder Singh 				return 0;
2793a3a95b7dSJasvinder Singh 			}
2794a3a95b7dSJasvinder Singh 
2795a3a95b7dSJasvinder Singh 			if (parser_read_uint8(&proto, tokens[7]) != 0) {
2796a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2797a3a95b7dSJasvinder Singh 					"proto");
2798a3a95b7dSJasvinder Singh 				return 0;
2799a3a95b7dSJasvinder Singh 			}
2800a3a95b7dSJasvinder Singh 
2801a3a95b7dSJasvinder Singh 			ipv4->sa = saddr.s_addr;
2802a3a95b7dSJasvinder Singh 			ipv4->da = daddr.s_addr;
2803a3a95b7dSJasvinder Singh 			ipv4->sp = rte_cpu_to_be_16(sp);
2804a3a95b7dSJasvinder Singh 			ipv4->dp = rte_cpu_to_be_16(dp);
2805a3a95b7dSJasvinder Singh 			ipv4->proto = proto;
2806a3a95b7dSJasvinder Singh 
2807a3a95b7dSJasvinder Singh 			return 8;
2808a3a95b7dSJasvinder Singh 		} /* hash ipv4_5tuple */
2809a3a95b7dSJasvinder Singh 
2810a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "ipv6_5tuple") == 0) {
2811a3a95b7dSJasvinder Singh 			struct pkt_key_ipv6_5tuple *ipv6 =
2812a3a95b7dSJasvinder Singh 				(struct pkt_key_ipv6_5tuple *) m->match.hash.key;
28135ac1abddSRobin Jarry 			struct rte_ipv6_addr saddr, daddr;
2814a3a95b7dSJasvinder Singh 			uint16_t sp, dp;
2815a3a95b7dSJasvinder Singh 			uint8_t proto;
2816a3a95b7dSJasvinder Singh 
2817a3a95b7dSJasvinder Singh 			if (n_tokens < 8) {
2818a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2819a3a95b7dSJasvinder Singh 					tokens[0]);
2820a3a95b7dSJasvinder Singh 				return 0;
2821a3a95b7dSJasvinder Singh 			}
2822a3a95b7dSJasvinder Singh 
2823a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[3], &saddr) != 0) {
2824a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sa");
2825a3a95b7dSJasvinder Singh 				return 0;
2826a3a95b7dSJasvinder Singh 			}
2827a3a95b7dSJasvinder Singh 
2828a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[4], &daddr) != 0) {
2829a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "da");
2830a3a95b7dSJasvinder Singh 				return 0;
2831a3a95b7dSJasvinder Singh 			}
2832a3a95b7dSJasvinder Singh 
2833a3a95b7dSJasvinder Singh 			if (parser_read_uint16(&sp, tokens[5]) != 0) {
2834a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "sp");
2835a3a95b7dSJasvinder Singh 				return 0;
2836a3a95b7dSJasvinder Singh 			}
2837a3a95b7dSJasvinder Singh 
2838a3a95b7dSJasvinder Singh 			if (parser_read_uint16(&dp, tokens[6]) != 0) {
2839a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID, "dp");
2840a3a95b7dSJasvinder Singh 				return 0;
2841a3a95b7dSJasvinder Singh 			}
2842a3a95b7dSJasvinder Singh 
2843a3a95b7dSJasvinder Singh 			if (parser_read_uint8(&proto, tokens[7]) != 0) {
2844a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2845a3a95b7dSJasvinder Singh 					"proto");
2846a3a95b7dSJasvinder Singh 				return 0;
2847a3a95b7dSJasvinder Singh 			}
2848a3a95b7dSJasvinder Singh 
28495ac1abddSRobin Jarry 			ipv6->sa = saddr;
28505ac1abddSRobin Jarry 			ipv6->da = daddr;
2851a3a95b7dSJasvinder Singh 			ipv6->sp = rte_cpu_to_be_16(sp);
2852a3a95b7dSJasvinder Singh 			ipv6->dp = rte_cpu_to_be_16(dp);
2853a3a95b7dSJasvinder Singh 			ipv6->proto = proto;
2854a3a95b7dSJasvinder Singh 
2855a3a95b7dSJasvinder Singh 			return 8;
2856a3a95b7dSJasvinder Singh 		} /* hash ipv6_5tuple */
2857a3a95b7dSJasvinder Singh 
2858a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "ipv4_addr") == 0) {
2859a3a95b7dSJasvinder Singh 			struct pkt_key_ipv4_addr *ipv4_addr =
2860a3a95b7dSJasvinder Singh 				(struct pkt_key_ipv4_addr *) m->match.hash.key;
2861a3a95b7dSJasvinder Singh 			struct in_addr addr;
2862a3a95b7dSJasvinder Singh 
2863a3a95b7dSJasvinder Singh 			if (n_tokens < 4) {
2864a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2865a3a95b7dSJasvinder Singh 					tokens[0]);
2866a3a95b7dSJasvinder Singh 				return 0;
2867a3a95b7dSJasvinder Singh 			}
2868a3a95b7dSJasvinder Singh 
2869a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2870a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2871a3a95b7dSJasvinder Singh 					"addr");
2872a3a95b7dSJasvinder Singh 				return 0;
2873a3a95b7dSJasvinder Singh 			}
2874a3a95b7dSJasvinder Singh 
2875a3a95b7dSJasvinder Singh 			ipv4_addr->addr = addr.s_addr;
2876a3a95b7dSJasvinder Singh 
2877a3a95b7dSJasvinder Singh 			return 4;
2878a3a95b7dSJasvinder Singh 		} /* hash ipv4_addr */
2879a3a95b7dSJasvinder Singh 
2880a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "ipv6_addr") == 0) {
2881a3a95b7dSJasvinder Singh 			struct pkt_key_ipv6_addr *ipv6_addr =
2882a3a95b7dSJasvinder Singh 				(struct pkt_key_ipv6_addr *) m->match.hash.key;
28835ac1abddSRobin Jarry 			struct rte_ipv6_addr addr;
2884a3a95b7dSJasvinder Singh 
2885a3a95b7dSJasvinder Singh 			if (n_tokens < 4) {
2886a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2887a3a95b7dSJasvinder Singh 					tokens[0]);
2888a3a95b7dSJasvinder Singh 				return 0;
2889a3a95b7dSJasvinder Singh 			}
2890a3a95b7dSJasvinder Singh 
2891a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2892a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2893a3a95b7dSJasvinder Singh 					"addr");
2894a3a95b7dSJasvinder Singh 				return 0;
2895a3a95b7dSJasvinder Singh 			}
2896a3a95b7dSJasvinder Singh 
28975ac1abddSRobin Jarry 			ipv6_addr->addr = addr;
2898a3a95b7dSJasvinder Singh 
2899a3a95b7dSJasvinder Singh 			return 4;
2900a3a95b7dSJasvinder Singh 		} /* hash ipv6_5tuple */
2901a3a95b7dSJasvinder Singh 
2902a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "qinq") == 0) {
2903a3a95b7dSJasvinder Singh 			struct pkt_key_qinq *qinq =
2904a3a95b7dSJasvinder Singh 				(struct pkt_key_qinq *) m->match.hash.key;
2905a3a95b7dSJasvinder Singh 			uint16_t svlan, cvlan;
2906a3a95b7dSJasvinder Singh 
2907a3a95b7dSJasvinder Singh 			if (n_tokens < 5) {
2908a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_MISMATCH,
2909a3a95b7dSJasvinder Singh 					tokens[0]);
2910a3a95b7dSJasvinder Singh 				return 0;
2911a3a95b7dSJasvinder Singh 			}
2912a3a95b7dSJasvinder Singh 
2913a3a95b7dSJasvinder Singh 			if ((parser_read_uint16(&svlan, tokens[3]) != 0) ||
2914a3a95b7dSJasvinder Singh 				(svlan > 0xFFF)) {
2915a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2916a3a95b7dSJasvinder Singh 					"svlan");
2917a3a95b7dSJasvinder Singh 				return 0;
2918a3a95b7dSJasvinder Singh 			}
2919a3a95b7dSJasvinder Singh 
2920a3a95b7dSJasvinder Singh 			if ((parser_read_uint16(&cvlan, tokens[4]) != 0) ||
2921a3a95b7dSJasvinder Singh 				(cvlan > 0xFFF)) {
2922a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2923a3a95b7dSJasvinder Singh 					"cvlan");
2924a3a95b7dSJasvinder Singh 				return 0;
2925a3a95b7dSJasvinder Singh 			}
2926a3a95b7dSJasvinder Singh 
2927a3a95b7dSJasvinder Singh 			qinq->svlan = rte_cpu_to_be_16(svlan);
2928a3a95b7dSJasvinder Singh 			qinq->cvlan = rte_cpu_to_be_16(cvlan);
2929a3a95b7dSJasvinder Singh 
2930a3a95b7dSJasvinder Singh 			return 5;
2931a3a95b7dSJasvinder Singh 		} /* hash qinq */
2932a3a95b7dSJasvinder Singh 
2933a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2934a3a95b7dSJasvinder Singh 		return 0;
2935a3a95b7dSJasvinder Singh 	} /* hash */
2936a3a95b7dSJasvinder Singh 
2937a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "lpm") == 0) {
2938a3a95b7dSJasvinder Singh 		if (n_tokens < 5) {
2939a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
2940a3a95b7dSJasvinder Singh 			return 0;
2941a3a95b7dSJasvinder Singh 		}
2942a3a95b7dSJasvinder Singh 
2943a3a95b7dSJasvinder Singh 		m->match_type = TABLE_LPM;
2944a3a95b7dSJasvinder Singh 
2945a3a95b7dSJasvinder Singh 		if (strcmp(tokens[2], "ipv4") == 0) {
2946a3a95b7dSJasvinder Singh 			struct in_addr addr;
2947a3a95b7dSJasvinder Singh 
2948a3a95b7dSJasvinder Singh 			m->match.lpm.ip_version = 1;
2949a3a95b7dSJasvinder Singh 
2950a3a95b7dSJasvinder Singh 			if (parse_ipv4_addr(tokens[3], &addr) != 0) {
2951a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2952a3a95b7dSJasvinder Singh 					"addr");
2953a3a95b7dSJasvinder Singh 				return 0;
2954a3a95b7dSJasvinder Singh 			}
2955a3a95b7dSJasvinder Singh 
2956a3a95b7dSJasvinder Singh 			m->match.lpm.ipv4 = rte_be_to_cpu_32(addr.s_addr);
2957a3a95b7dSJasvinder Singh 		} else if (strcmp(tokens[2], "ipv6") == 0) {
29585ac1abddSRobin Jarry 			struct rte_ipv6_addr addr;
2959a3a95b7dSJasvinder Singh 
2960a3a95b7dSJasvinder Singh 			m->match.lpm.ip_version = 0;
2961a3a95b7dSJasvinder Singh 
2962a3a95b7dSJasvinder Singh 			if (parse_ipv6_addr(tokens[3], &addr) != 0) {
2963a3a95b7dSJasvinder Singh 				snprintf(out, out_size, MSG_ARG_INVALID,
2964a3a95b7dSJasvinder Singh 					"addr");
2965a3a95b7dSJasvinder Singh 				return 0;
2966a3a95b7dSJasvinder Singh 			}
2967a3a95b7dSJasvinder Singh 
29685ac1abddSRobin Jarry 			m->match.lpm.ipv6 = addr;
2969a3a95b7dSJasvinder Singh 		} else {
2970a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
2971a3a95b7dSJasvinder Singh 				"ipv4 or ipv6");
2972a3a95b7dSJasvinder Singh 			return 0;
2973a3a95b7dSJasvinder Singh 		}
2974a3a95b7dSJasvinder Singh 
2975a3a95b7dSJasvinder Singh 		if (parser_read_uint8(&m->match.lpm.depth, tokens[4]) != 0) {
2976a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "depth");
2977a3a95b7dSJasvinder Singh 			return 0;
2978a3a95b7dSJasvinder Singh 		}
2979a3a95b7dSJasvinder Singh 
2980a3a95b7dSJasvinder Singh 		return 5;
2981a3a95b7dSJasvinder Singh 	} /* lpm */
2982a3a95b7dSJasvinder Singh 
2983a3a95b7dSJasvinder Singh 	snprintf(out, out_size, MSG_ARG_MISMATCH,
2984a3a95b7dSJasvinder Singh 		"acl or array or hash or lpm");
2985a3a95b7dSJasvinder Singh 	return 0;
2986a3a95b7dSJasvinder Singh }
2987a3a95b7dSJasvinder Singh 
2988a3a95b7dSJasvinder Singh /**
2989a3a95b7dSJasvinder Singh  * table_action ::=
2990a3a95b7dSJasvinder Singh  *
2991a3a95b7dSJasvinder Singh  * action
2992a3a95b7dSJasvinder Singh  *    fwd
2993a3a95b7dSJasvinder Singh  *       drop
2994a3a95b7dSJasvinder Singh  *       | port <port_id>
2995a3a95b7dSJasvinder Singh  *       | meta
2996a3a95b7dSJasvinder Singh  *       | table <table_id>
2997a3a95b7dSJasvinder Singh  *    [balance <out0> ... <out7>]
2998a3a95b7dSJasvinder Singh  *    [meter
2999a3a95b7dSJasvinder Singh  *       tc0 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3000a3a95b7dSJasvinder Singh  *       [tc1 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3001a3a95b7dSJasvinder Singh  *       tc2 meter <meter_profile_id> policer g <pa> y <pa> r <pa>
3002a3a95b7dSJasvinder Singh  *       tc3 meter <meter_profile_id> policer g <pa> y <pa> r <pa>]]
3003a3a95b7dSJasvinder Singh  *    [tm subport <subport_id> pipe <pipe_id>]
3004a3a95b7dSJasvinder Singh  *    [encap
3005a3a95b7dSJasvinder Singh  *       ether <da> <sa>
3006a3a95b7dSJasvinder Singh  *       | vlan <da> <sa> <pcp> <dei> <vid>
3007a3a95b7dSJasvinder Singh  *       | qinq <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid>
300833e7afe6SNemanja Marjanovic  *       | qinq_pppoe <da> <sa> <pcp> <dei> <vid> <pcp> <dei> <vid> <session_id>
3009a3a95b7dSJasvinder Singh  *       | mpls unicast | multicast
3010a3a95b7dSJasvinder Singh  *          <da> <sa>
3011a3a95b7dSJasvinder Singh  *          label0 <label> <tc> <ttl>
3012a3a95b7dSJasvinder Singh  *          [label1 <label> <tc> <ttl>
3013a3a95b7dSJasvinder Singh  *          [label2 <label> <tc> <ttl>
3014a3a95b7dSJasvinder Singh  *          [label3 <label> <tc> <ttl>]]]
301544cad685SCristian Dumitrescu  *       | pppoe <da> <sa> <session_id>
301644cad685SCristian Dumitrescu  *       | vxlan ether <da> <sa>
301744cad685SCristian Dumitrescu  *          [vlan <pcp> <dei> <vid>]
301844cad685SCristian Dumitrescu  *          ipv4 <sa> <da> <dscp> <ttl>
301944cad685SCristian Dumitrescu  *          | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit>
302044cad685SCristian Dumitrescu  *          udp <sp> <dp>
302144cad685SCristian Dumitrescu  *          vxlan <vni>]
3022a3a95b7dSJasvinder Singh  *    [nat ipv4 | ipv6 <addr> <port>]
3023a3a95b7dSJasvinder Singh  *    [ttl dec | keep]
3024a3a95b7dSJasvinder Singh  *    [stats]
3025a3a95b7dSJasvinder Singh  *    [time]
30261edccebcSFan Zhang  *    [sym_crypto
30271edccebcSFan Zhang  *       encrypt | decrypt
30281edccebcSFan Zhang  *       type
30291edccebcSFan Zhang  *       | cipher
30301edccebcSFan Zhang  *          cipher_algo <algo> cipher_key <key> cipher_iv <iv>
30311edccebcSFan Zhang  *       | cipher_auth
30321edccebcSFan Zhang  *          cipher_algo <algo> cipher_key <key> cipher_iv <iv>
30331edccebcSFan Zhang  *          auth_algo <algo> auth_key <key> digest_size <size>
30341edccebcSFan Zhang  *       | aead
30351edccebcSFan Zhang  *          aead_algo <algo> aead_key <key> aead_iv <iv> aead_aad <aad>
30361edccebcSFan Zhang  *          digest_size <size>
30371edccebcSFan Zhang  *       data_offset <data_offset>]
30381bdf2632SCristian Dumitrescu  *    [tag <tag>]
3039d5ed626fSCristian Dumitrescu  *    [decap <n>]
3040a3a95b7dSJasvinder Singh  *
3041a3a95b7dSJasvinder Singh  * where:
3042a3a95b7dSJasvinder Singh  *    <pa> ::= g | y | r | drop
3043a3a95b7dSJasvinder Singh  */
3044a3a95b7dSJasvinder Singh static uint32_t
3045a3a95b7dSJasvinder Singh parse_table_action_fwd(char **tokens,
3046a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3047a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3048a3a95b7dSJasvinder Singh {
3049a3a95b7dSJasvinder Singh 	if ((n_tokens == 0) || (strcmp(tokens[0], "fwd") != 0))
3050a3a95b7dSJasvinder Singh 		return 0;
3051a3a95b7dSJasvinder Singh 
3052a3a95b7dSJasvinder Singh 	tokens++;
3053a3a95b7dSJasvinder Singh 	n_tokens--;
3054a3a95b7dSJasvinder Singh 
3055a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "drop") == 0)) {
3056a3a95b7dSJasvinder Singh 		a->fwd.action = RTE_PIPELINE_ACTION_DROP;
3057a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3058a3a95b7dSJasvinder Singh 		return 1 + 1;
3059a3a95b7dSJasvinder Singh 	}
3060a3a95b7dSJasvinder Singh 
3061a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "port") == 0)) {
3062a3a95b7dSJasvinder Singh 		uint32_t id;
3063a3a95b7dSJasvinder Singh 
3064a3a95b7dSJasvinder Singh 		if ((n_tokens < 2) ||
3065a3a95b7dSJasvinder Singh 			parser_read_uint32(&id, tokens[1]))
3066a3a95b7dSJasvinder Singh 			return 0;
3067a3a95b7dSJasvinder Singh 
3068a3a95b7dSJasvinder Singh 		a->fwd.action = RTE_PIPELINE_ACTION_PORT;
3069a3a95b7dSJasvinder Singh 		a->fwd.id = id;
3070a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3071a3a95b7dSJasvinder Singh 		return 1 + 2;
3072a3a95b7dSJasvinder Singh 	}
3073a3a95b7dSJasvinder Singh 
3074a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "meta") == 0)) {
3075a3a95b7dSJasvinder Singh 		a->fwd.action = RTE_PIPELINE_ACTION_PORT_META;
3076a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3077a3a95b7dSJasvinder Singh 		return 1 + 1;
3078a3a95b7dSJasvinder Singh 	}
3079a3a95b7dSJasvinder Singh 
3080a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "table") == 0)) {
3081a3a95b7dSJasvinder Singh 		uint32_t id;
3082a3a95b7dSJasvinder Singh 
3083a3a95b7dSJasvinder Singh 		if ((n_tokens < 2) ||
3084a3a95b7dSJasvinder Singh 			parser_read_uint32(&id, tokens[1]))
3085a3a95b7dSJasvinder Singh 			return 0;
3086a3a95b7dSJasvinder Singh 
3087a3a95b7dSJasvinder Singh 		a->fwd.action = RTE_PIPELINE_ACTION_TABLE;
3088a3a95b7dSJasvinder Singh 		a->fwd.id = id;
3089a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_FWD;
3090a3a95b7dSJasvinder Singh 		return 1 + 2;
3091a3a95b7dSJasvinder Singh 	}
3092a3a95b7dSJasvinder Singh 
3093a3a95b7dSJasvinder Singh 	return 0;
3094a3a95b7dSJasvinder Singh }
3095a3a95b7dSJasvinder Singh 
3096802755dcSJasvinder Singh static uint32_t
3097802755dcSJasvinder Singh parse_table_action_balance(char **tokens,
3098802755dcSJasvinder Singh 	uint32_t n_tokens,
3099802755dcSJasvinder Singh 	struct table_rule_action *a)
3100802755dcSJasvinder Singh {
3101802755dcSJasvinder Singh 	uint32_t i;
3102802755dcSJasvinder Singh 
3103802755dcSJasvinder Singh 	if ((n_tokens == 0) || (strcmp(tokens[0], "balance") != 0))
3104802755dcSJasvinder Singh 		return 0;
3105802755dcSJasvinder Singh 
3106802755dcSJasvinder Singh 	tokens++;
3107802755dcSJasvinder Singh 	n_tokens--;
3108802755dcSJasvinder Singh 
3109085c3d8cSJasvinder Singh 	if (n_tokens < RTE_TABLE_ACTION_LB_TABLE_SIZE)
3110802755dcSJasvinder Singh 		return 0;
3111802755dcSJasvinder Singh 
3112085c3d8cSJasvinder Singh 	for (i = 0; i < RTE_TABLE_ACTION_LB_TABLE_SIZE; i++)
3113802755dcSJasvinder Singh 		if (parser_read_uint32(&a->lb.out[i], tokens[i]) != 0)
3114802755dcSJasvinder Singh 			return 0;
3115802755dcSJasvinder Singh 
3116802755dcSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_LB;
3117085c3d8cSJasvinder Singh 	return 1 + RTE_TABLE_ACTION_LB_TABLE_SIZE;
3118802755dcSJasvinder Singh 
3119802755dcSJasvinder Singh }
3120802755dcSJasvinder Singh 
3121a3a95b7dSJasvinder Singh static int
3122a3a95b7dSJasvinder Singh parse_policer_action(char *token, enum rte_table_action_policer *a)
3123a3a95b7dSJasvinder Singh {
3124a3a95b7dSJasvinder Singh 	if (strcmp(token, "g") == 0) {
3125a3a95b7dSJasvinder Singh 		*a = RTE_TABLE_ACTION_POLICER_COLOR_GREEN;
3126a3a95b7dSJasvinder Singh 		return 0;
3127a3a95b7dSJasvinder Singh 	}
3128a3a95b7dSJasvinder Singh 
3129a3a95b7dSJasvinder Singh 	if (strcmp(token, "y") == 0) {
3130a3a95b7dSJasvinder Singh 		*a = RTE_TABLE_ACTION_POLICER_COLOR_YELLOW;
3131a3a95b7dSJasvinder Singh 		return 0;
3132a3a95b7dSJasvinder Singh 	}
3133a3a95b7dSJasvinder Singh 
3134a3a95b7dSJasvinder Singh 	if (strcmp(token, "r") == 0) {
3135a3a95b7dSJasvinder Singh 		*a = RTE_TABLE_ACTION_POLICER_COLOR_RED;
3136a3a95b7dSJasvinder Singh 		return 0;
3137a3a95b7dSJasvinder Singh 	}
3138a3a95b7dSJasvinder Singh 
3139a3a95b7dSJasvinder Singh 	if (strcmp(token, "drop") == 0) {
3140a3a95b7dSJasvinder Singh 		*a = RTE_TABLE_ACTION_POLICER_DROP;
3141a3a95b7dSJasvinder Singh 		return 0;
3142a3a95b7dSJasvinder Singh 	}
3143a3a95b7dSJasvinder Singh 
3144a3a95b7dSJasvinder Singh 	return -1;
3145a3a95b7dSJasvinder Singh }
3146a3a95b7dSJasvinder Singh 
3147a3a95b7dSJasvinder Singh static uint32_t
3148a3a95b7dSJasvinder Singh parse_table_action_meter_tc(char **tokens,
3149a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3150a3a95b7dSJasvinder Singh 	struct rte_table_action_mtr_tc_params *mtr)
3151a3a95b7dSJasvinder Singh {
3152a3a95b7dSJasvinder Singh 	if ((n_tokens < 9) ||
3153a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "meter") ||
3154a3a95b7dSJasvinder Singh 		parser_read_uint32(&mtr->meter_profile_id, tokens[1]) ||
3155a3a95b7dSJasvinder Singh 		strcmp(tokens[2], "policer") ||
3156a3a95b7dSJasvinder Singh 		strcmp(tokens[3], "g") ||
3157c1656328SJasvinder Singh 		parse_policer_action(tokens[4], &mtr->policer[RTE_COLOR_GREEN]) ||
3158a3a95b7dSJasvinder Singh 		strcmp(tokens[5], "y") ||
3159c1656328SJasvinder Singh 		parse_policer_action(tokens[6], &mtr->policer[RTE_COLOR_YELLOW]) ||
3160a3a95b7dSJasvinder Singh 		strcmp(tokens[7], "r") ||
3161c1656328SJasvinder Singh 		parse_policer_action(tokens[8], &mtr->policer[RTE_COLOR_RED]))
3162a3a95b7dSJasvinder Singh 		return 0;
3163a3a95b7dSJasvinder Singh 
3164a3a95b7dSJasvinder Singh 	return 9;
3165a3a95b7dSJasvinder Singh }
3166a3a95b7dSJasvinder Singh 
3167a3a95b7dSJasvinder Singh static uint32_t
3168a3a95b7dSJasvinder Singh parse_table_action_meter(char **tokens,
3169a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3170a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3171a3a95b7dSJasvinder Singh {
3172a3a95b7dSJasvinder Singh 	if ((n_tokens == 0) || strcmp(tokens[0], "meter"))
3173a3a95b7dSJasvinder Singh 		return 0;
3174a3a95b7dSJasvinder Singh 
3175a3a95b7dSJasvinder Singh 	tokens++;
3176a3a95b7dSJasvinder Singh 	n_tokens--;
3177a3a95b7dSJasvinder Singh 
3178a3a95b7dSJasvinder Singh 	if ((n_tokens < 10) ||
3179a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "tc0") ||
3180a3a95b7dSJasvinder Singh 		(parse_table_action_meter_tc(tokens + 1,
3181a3a95b7dSJasvinder Singh 			n_tokens - 1,
3182a3a95b7dSJasvinder Singh 			&a->mtr.mtr[0]) == 0))
3183a3a95b7dSJasvinder Singh 		return 0;
3184a3a95b7dSJasvinder Singh 
3185a3a95b7dSJasvinder Singh 	tokens += 10;
3186a3a95b7dSJasvinder Singh 	n_tokens -= 10;
3187a3a95b7dSJasvinder Singh 
3188a3a95b7dSJasvinder Singh 	if ((n_tokens == 0) || strcmp(tokens[0], "tc1")) {
3189a3a95b7dSJasvinder Singh 		a->mtr.tc_mask = 1;
3190a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3191a3a95b7dSJasvinder Singh 		return 1 + 10;
3192a3a95b7dSJasvinder Singh 	}
3193a3a95b7dSJasvinder Singh 
3194a3a95b7dSJasvinder Singh 	if ((n_tokens < 30) ||
3195a3a95b7dSJasvinder Singh 		(parse_table_action_meter_tc(tokens + 1,
3196a3a95b7dSJasvinder Singh 			n_tokens - 1, &a->mtr.mtr[1]) == 0) ||
3197a3a95b7dSJasvinder Singh 		strcmp(tokens[10], "tc2") ||
3198a3a95b7dSJasvinder Singh 		(parse_table_action_meter_tc(tokens + 11,
3199a3a95b7dSJasvinder Singh 			n_tokens - 11, &a->mtr.mtr[2]) == 0) ||
3200a3a95b7dSJasvinder Singh 		strcmp(tokens[20], "tc3") ||
3201a3a95b7dSJasvinder Singh 		(parse_table_action_meter_tc(tokens + 21,
3202a3a95b7dSJasvinder Singh 			n_tokens - 21, &a->mtr.mtr[3]) == 0))
3203a3a95b7dSJasvinder Singh 		return 0;
3204a3a95b7dSJasvinder Singh 
3205a3a95b7dSJasvinder Singh 	a->mtr.tc_mask = 0xF;
3206a3a95b7dSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_MTR;
3207a3a95b7dSJasvinder Singh 	return 1 + 10 + 3 * 10;
3208a3a95b7dSJasvinder Singh }
3209a3a95b7dSJasvinder Singh 
3210a3a95b7dSJasvinder Singh static uint32_t
3211a3a95b7dSJasvinder Singh parse_table_action_tm(char **tokens,
3212a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3213a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3214a3a95b7dSJasvinder Singh {
3215a3a95b7dSJasvinder Singh 	uint32_t subport_id, pipe_id;
3216a3a95b7dSJasvinder Singh 
3217a3a95b7dSJasvinder Singh 	if ((n_tokens < 5) ||
3218a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "tm") ||
3219a3a95b7dSJasvinder Singh 		strcmp(tokens[1], "subport") ||
3220a3a95b7dSJasvinder Singh 		parser_read_uint32(&subport_id, tokens[2]) ||
3221a3a95b7dSJasvinder Singh 		strcmp(tokens[3], "pipe") ||
3222a3a95b7dSJasvinder Singh 		parser_read_uint32(&pipe_id, tokens[4]))
3223a3a95b7dSJasvinder Singh 		return 0;
3224a3a95b7dSJasvinder Singh 
3225a3a95b7dSJasvinder Singh 	a->tm.subport_id = subport_id;
3226a3a95b7dSJasvinder Singh 	a->tm.pipe_id = pipe_id;
3227a3a95b7dSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_TM;
3228a3a95b7dSJasvinder Singh 	return 5;
3229a3a95b7dSJasvinder Singh }
3230a3a95b7dSJasvinder Singh 
3231a3a95b7dSJasvinder Singh static uint32_t
3232a3a95b7dSJasvinder Singh parse_table_action_encap(char **tokens,
3233a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3234a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3235a3a95b7dSJasvinder Singh {
3236a3a95b7dSJasvinder Singh 	if ((n_tokens == 0) || strcmp(tokens[0], "encap"))
3237a3a95b7dSJasvinder Singh 		return 0;
3238a3a95b7dSJasvinder Singh 
3239a3a95b7dSJasvinder Singh 	tokens++;
3240a3a95b7dSJasvinder Singh 	n_tokens--;
3241a3a95b7dSJasvinder Singh 
3242a3a95b7dSJasvinder Singh 	/* ether */
3243a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "ether") == 0)) {
3244a3a95b7dSJasvinder Singh 		if ((n_tokens < 3) ||
3245a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[1], &a->encap.ether.ether.da) ||
3246a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[2], &a->encap.ether.ether.sa))
3247a3a95b7dSJasvinder Singh 			return 0;
3248a3a95b7dSJasvinder Singh 
3249a3a95b7dSJasvinder Singh 		a->encap.type = RTE_TABLE_ACTION_ENCAP_ETHER;
3250a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3251a3a95b7dSJasvinder Singh 		return 1 + 3;
3252a3a95b7dSJasvinder Singh 	}
3253a3a95b7dSJasvinder Singh 
3254a3a95b7dSJasvinder Singh 	/* vlan */
3255a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "vlan") == 0)) {
3256a3a95b7dSJasvinder Singh 		uint32_t pcp, dei, vid;
3257a3a95b7dSJasvinder Singh 
3258a3a95b7dSJasvinder Singh 		if ((n_tokens < 6) ||
3259a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[1], &a->encap.vlan.ether.da) ||
3260a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[2], &a->encap.vlan.ether.sa) ||
3261a3a95b7dSJasvinder Singh 			parser_read_uint32(&pcp, tokens[3]) ||
3262a3a95b7dSJasvinder Singh 			(pcp > 0x7) ||
3263a3a95b7dSJasvinder Singh 			parser_read_uint32(&dei, tokens[4]) ||
3264a3a95b7dSJasvinder Singh 			(dei > 0x1) ||
3265a3a95b7dSJasvinder Singh 			parser_read_uint32(&vid, tokens[5]) ||
3266a3a95b7dSJasvinder Singh 			(vid > 0xFFF))
3267a3a95b7dSJasvinder Singh 			return 0;
3268a3a95b7dSJasvinder Singh 
3269a3a95b7dSJasvinder Singh 		a->encap.vlan.vlan.pcp = pcp & 0x7;
3270a3a95b7dSJasvinder Singh 		a->encap.vlan.vlan.dei = dei & 0x1;
3271a3a95b7dSJasvinder Singh 		a->encap.vlan.vlan.vid = vid & 0xFFF;
3272a3a95b7dSJasvinder Singh 		a->encap.type = RTE_TABLE_ACTION_ENCAP_VLAN;
3273a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3274a3a95b7dSJasvinder Singh 		return 1 + 6;
3275a3a95b7dSJasvinder Singh 	}
3276a3a95b7dSJasvinder Singh 
3277a3a95b7dSJasvinder Singh 	/* qinq */
3278a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "qinq") == 0)) {
3279a3a95b7dSJasvinder Singh 		uint32_t svlan_pcp, svlan_dei, svlan_vid;
3280a3a95b7dSJasvinder Singh 		uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
3281a3a95b7dSJasvinder Singh 
3282a3a95b7dSJasvinder Singh 		if ((n_tokens < 9) ||
3283a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[1], &a->encap.qinq.ether.da) ||
3284a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[2], &a->encap.qinq.ether.sa) ||
3285a3a95b7dSJasvinder Singh 			parser_read_uint32(&svlan_pcp, tokens[3]) ||
3286a3a95b7dSJasvinder Singh 			(svlan_pcp > 0x7) ||
3287a3a95b7dSJasvinder Singh 			parser_read_uint32(&svlan_dei, tokens[4]) ||
3288a3a95b7dSJasvinder Singh 			(svlan_dei > 0x1) ||
3289a3a95b7dSJasvinder Singh 			parser_read_uint32(&svlan_vid, tokens[5]) ||
3290a3a95b7dSJasvinder Singh 			(svlan_vid > 0xFFF) ||
3291a3a95b7dSJasvinder Singh 			parser_read_uint32(&cvlan_pcp, tokens[6]) ||
3292a3a95b7dSJasvinder Singh 			(cvlan_pcp > 0x7) ||
3293a3a95b7dSJasvinder Singh 			parser_read_uint32(&cvlan_dei, tokens[7]) ||
3294a3a95b7dSJasvinder Singh 			(cvlan_dei > 0x1) ||
3295a3a95b7dSJasvinder Singh 			parser_read_uint32(&cvlan_vid, tokens[8]) ||
3296a3a95b7dSJasvinder Singh 			(cvlan_vid > 0xFFF))
3297a3a95b7dSJasvinder Singh 			return 0;
3298a3a95b7dSJasvinder Singh 
3299a3a95b7dSJasvinder Singh 		a->encap.qinq.svlan.pcp = svlan_pcp & 0x7;
3300a3a95b7dSJasvinder Singh 		a->encap.qinq.svlan.dei = svlan_dei & 0x1;
3301a3a95b7dSJasvinder Singh 		a->encap.qinq.svlan.vid = svlan_vid & 0xFFF;
3302a3a95b7dSJasvinder Singh 		a->encap.qinq.cvlan.pcp = cvlan_pcp & 0x7;
3303a3a95b7dSJasvinder Singh 		a->encap.qinq.cvlan.dei = cvlan_dei & 0x1;
3304a3a95b7dSJasvinder Singh 		a->encap.qinq.cvlan.vid = cvlan_vid & 0xFFF;
3305a3a95b7dSJasvinder Singh 		a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ;
3306a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3307a3a95b7dSJasvinder Singh 		return 1 + 9;
3308a3a95b7dSJasvinder Singh 	}
3309a3a95b7dSJasvinder Singh 
331033e7afe6SNemanja Marjanovic 	/* qinq_pppoe */
331133e7afe6SNemanja Marjanovic 	if (n_tokens && (strcmp(tokens[0], "qinq_pppoe") == 0)) {
331233e7afe6SNemanja Marjanovic 		uint32_t svlan_pcp, svlan_dei, svlan_vid;
331333e7afe6SNemanja Marjanovic 		uint32_t cvlan_pcp, cvlan_dei, cvlan_vid;
331433e7afe6SNemanja Marjanovic 
331533e7afe6SNemanja Marjanovic 		if ((n_tokens < 10) ||
331633e7afe6SNemanja Marjanovic 			parse_mac_addr(tokens[1],
331733e7afe6SNemanja Marjanovic 				&a->encap.qinq_pppoe.ether.da) ||
331833e7afe6SNemanja Marjanovic 			parse_mac_addr(tokens[2],
331933e7afe6SNemanja Marjanovic 				&a->encap.qinq_pppoe.ether.sa) ||
332033e7afe6SNemanja Marjanovic 			parser_read_uint32(&svlan_pcp, tokens[3]) ||
332133e7afe6SNemanja Marjanovic 			(svlan_pcp > 0x7) ||
332233e7afe6SNemanja Marjanovic 			parser_read_uint32(&svlan_dei, tokens[4]) ||
332333e7afe6SNemanja Marjanovic 			(svlan_dei > 0x1) ||
332433e7afe6SNemanja Marjanovic 			parser_read_uint32(&svlan_vid, tokens[5]) ||
332533e7afe6SNemanja Marjanovic 			(svlan_vid > 0xFFF) ||
332633e7afe6SNemanja Marjanovic 			parser_read_uint32(&cvlan_pcp, tokens[6]) ||
332733e7afe6SNemanja Marjanovic 			(cvlan_pcp > 0x7) ||
332833e7afe6SNemanja Marjanovic 			parser_read_uint32(&cvlan_dei, tokens[7]) ||
332933e7afe6SNemanja Marjanovic 			(cvlan_dei > 0x1) ||
333033e7afe6SNemanja Marjanovic 			parser_read_uint32(&cvlan_vid, tokens[8]) ||
333133e7afe6SNemanja Marjanovic 			(cvlan_vid > 0xFFF) ||
333233e7afe6SNemanja Marjanovic 			parser_read_uint16(&a->encap.qinq_pppoe.pppoe.session_id,
333333e7afe6SNemanja Marjanovic 				tokens[9]))
333433e7afe6SNemanja Marjanovic 			return 0;
333533e7afe6SNemanja Marjanovic 
333633e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.svlan.pcp = svlan_pcp & 0x7;
333733e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.svlan.dei = svlan_dei & 0x1;
333833e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.svlan.vid = svlan_vid & 0xFFF;
333933e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.cvlan.pcp = cvlan_pcp & 0x7;
334033e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.cvlan.dei = cvlan_dei & 0x1;
334133e7afe6SNemanja Marjanovic 		a->encap.qinq_pppoe.cvlan.vid = cvlan_vid & 0xFFF;
334233e7afe6SNemanja Marjanovic 		a->encap.type = RTE_TABLE_ACTION_ENCAP_QINQ_PPPOE;
334333e7afe6SNemanja Marjanovic 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
334433e7afe6SNemanja Marjanovic 		return 1 + 10;
334533e7afe6SNemanja Marjanovic 
334633e7afe6SNemanja Marjanovic 	}
334733e7afe6SNemanja Marjanovic 
3348a3a95b7dSJasvinder Singh 	/* mpls */
3349a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "mpls") == 0)) {
3350a3a95b7dSJasvinder Singh 		uint32_t label, tc, ttl;
3351a3a95b7dSJasvinder Singh 
3352a3a95b7dSJasvinder Singh 		if (n_tokens < 8)
3353a3a95b7dSJasvinder Singh 			return 0;
3354a3a95b7dSJasvinder Singh 
3355a3a95b7dSJasvinder Singh 		if (strcmp(tokens[1], "unicast") == 0)
3356a3a95b7dSJasvinder Singh 			a->encap.mpls.unicast = 1;
3357a3a95b7dSJasvinder Singh 		else if (strcmp(tokens[1], "multicast") == 0)
3358a3a95b7dSJasvinder Singh 			a->encap.mpls.unicast = 0;
3359a3a95b7dSJasvinder Singh 		else
3360a3a95b7dSJasvinder Singh 			return 0;
3361a3a95b7dSJasvinder Singh 
3362a3a95b7dSJasvinder Singh 		if (parse_mac_addr(tokens[2], &a->encap.mpls.ether.da) ||
3363a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[3], &a->encap.mpls.ether.sa) ||
3364a3a95b7dSJasvinder Singh 			strcmp(tokens[4], "label0") ||
3365a3a95b7dSJasvinder Singh 			parser_read_uint32(&label, tokens[5]) ||
3366a3a95b7dSJasvinder Singh 			(label > 0xFFFFF) ||
3367a3a95b7dSJasvinder Singh 			parser_read_uint32(&tc, tokens[6]) ||
3368a3a95b7dSJasvinder Singh 			(tc > 0x7) ||
3369a3a95b7dSJasvinder Singh 			parser_read_uint32(&ttl, tokens[7]) ||
3370a3a95b7dSJasvinder Singh 			(ttl > 0x3F))
3371a3a95b7dSJasvinder Singh 			return 0;
3372a3a95b7dSJasvinder Singh 
3373a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[0].label = label;
3374a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[0].tc = tc;
3375a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[0].ttl = ttl;
3376a3a95b7dSJasvinder Singh 
3377a3a95b7dSJasvinder Singh 		tokens += 8;
3378a3a95b7dSJasvinder Singh 		n_tokens -= 8;
3379a3a95b7dSJasvinder Singh 
3380a3a95b7dSJasvinder Singh 		if ((n_tokens == 0) || strcmp(tokens[0], "label1")) {
3381a3a95b7dSJasvinder Singh 			a->encap.mpls.mpls_count = 1;
3382a3a95b7dSJasvinder Singh 			a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3383a3a95b7dSJasvinder Singh 			a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3384a3a95b7dSJasvinder Singh 			return 1 + 8;
3385a3a95b7dSJasvinder Singh 		}
3386a3a95b7dSJasvinder Singh 
3387a3a95b7dSJasvinder Singh 		if ((n_tokens < 4) ||
3388a3a95b7dSJasvinder Singh 			parser_read_uint32(&label, tokens[1]) ||
3389a3a95b7dSJasvinder Singh 			(label > 0xFFFFF) ||
3390a3a95b7dSJasvinder Singh 			parser_read_uint32(&tc, tokens[2]) ||
3391a3a95b7dSJasvinder Singh 			(tc > 0x7) ||
3392a3a95b7dSJasvinder Singh 			parser_read_uint32(&ttl, tokens[3]) ||
3393a3a95b7dSJasvinder Singh 			(ttl > 0x3F))
3394a3a95b7dSJasvinder Singh 			return 0;
3395a3a95b7dSJasvinder Singh 
3396a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[1].label = label;
3397a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[1].tc = tc;
3398a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[1].ttl = ttl;
3399a3a95b7dSJasvinder Singh 
3400a3a95b7dSJasvinder Singh 		tokens += 4;
3401a3a95b7dSJasvinder Singh 		n_tokens -= 4;
3402a3a95b7dSJasvinder Singh 
3403a3a95b7dSJasvinder Singh 		if ((n_tokens == 0) || strcmp(tokens[0], "label2")) {
3404a3a95b7dSJasvinder Singh 			a->encap.mpls.mpls_count = 2;
3405a3a95b7dSJasvinder Singh 			a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3406a3a95b7dSJasvinder Singh 			a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3407a3a95b7dSJasvinder Singh 			return 1 + 8 + 4;
3408a3a95b7dSJasvinder Singh 		}
3409a3a95b7dSJasvinder Singh 
3410a3a95b7dSJasvinder Singh 		if ((n_tokens < 4) ||
3411a3a95b7dSJasvinder Singh 			parser_read_uint32(&label, tokens[1]) ||
3412a3a95b7dSJasvinder Singh 			(label > 0xFFFFF) ||
3413a3a95b7dSJasvinder Singh 			parser_read_uint32(&tc, tokens[2]) ||
3414a3a95b7dSJasvinder Singh 			(tc > 0x7) ||
3415a3a95b7dSJasvinder Singh 			parser_read_uint32(&ttl, tokens[3]) ||
3416a3a95b7dSJasvinder Singh 			(ttl > 0x3F))
3417a3a95b7dSJasvinder Singh 			return 0;
3418a3a95b7dSJasvinder Singh 
3419a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[2].label = label;
3420a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[2].tc = tc;
3421a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[2].ttl = ttl;
3422a3a95b7dSJasvinder Singh 
3423a3a95b7dSJasvinder Singh 		tokens += 4;
3424a3a95b7dSJasvinder Singh 		n_tokens -= 4;
3425a3a95b7dSJasvinder Singh 
3426a3a95b7dSJasvinder Singh 		if ((n_tokens == 0) || strcmp(tokens[0], "label3")) {
3427a3a95b7dSJasvinder Singh 			a->encap.mpls.mpls_count = 3;
3428a3a95b7dSJasvinder Singh 			a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3429a3a95b7dSJasvinder Singh 			a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3430a3a95b7dSJasvinder Singh 			return 1 + 8 + 4 + 4;
3431a3a95b7dSJasvinder Singh 		}
3432a3a95b7dSJasvinder Singh 
3433a3a95b7dSJasvinder Singh 		if ((n_tokens < 4) ||
3434a3a95b7dSJasvinder Singh 			parser_read_uint32(&label, tokens[1]) ||
3435a3a95b7dSJasvinder Singh 			(label > 0xFFFFF) ||
3436a3a95b7dSJasvinder Singh 			parser_read_uint32(&tc, tokens[2]) ||
3437a3a95b7dSJasvinder Singh 			(tc > 0x7) ||
3438a3a95b7dSJasvinder Singh 			parser_read_uint32(&ttl, tokens[3]) ||
3439a3a95b7dSJasvinder Singh 			(ttl > 0x3F))
3440a3a95b7dSJasvinder Singh 			return 0;
3441a3a95b7dSJasvinder Singh 
3442a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[3].label = label;
3443a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[3].tc = tc;
3444a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls[3].ttl = ttl;
3445a3a95b7dSJasvinder Singh 
3446a3a95b7dSJasvinder Singh 		a->encap.mpls.mpls_count = 4;
3447a3a95b7dSJasvinder Singh 		a->encap.type = RTE_TABLE_ACTION_ENCAP_MPLS;
3448a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3449a3a95b7dSJasvinder Singh 		return 1 + 8 + 4 + 4 + 4;
3450a3a95b7dSJasvinder Singh 	}
3451a3a95b7dSJasvinder Singh 
3452a3a95b7dSJasvinder Singh 	/* pppoe */
3453a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "pppoe") == 0)) {
3454a3a95b7dSJasvinder Singh 		if ((n_tokens < 4) ||
3455a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[1], &a->encap.pppoe.ether.da) ||
3456a3a95b7dSJasvinder Singh 			parse_mac_addr(tokens[2], &a->encap.pppoe.ether.sa) ||
3457a3a95b7dSJasvinder Singh 			parser_read_uint16(&a->encap.pppoe.pppoe.session_id,
3458a3a95b7dSJasvinder Singh 				tokens[3]))
3459a3a95b7dSJasvinder Singh 			return 0;
3460a3a95b7dSJasvinder Singh 
3461a3a95b7dSJasvinder Singh 		a->encap.type = RTE_TABLE_ACTION_ENCAP_PPPOE;
3462a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
3463a3a95b7dSJasvinder Singh 		return 1 + 4;
3464a3a95b7dSJasvinder Singh 	}
3465a3a95b7dSJasvinder Singh 
346644cad685SCristian Dumitrescu 	/* vxlan */
346744cad685SCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "vxlan") == 0)) {
346844cad685SCristian Dumitrescu 		uint32_t n = 0;
346944cad685SCristian Dumitrescu 
347044cad685SCristian Dumitrescu 		n_tokens--;
347144cad685SCristian Dumitrescu 		tokens++;
347244cad685SCristian Dumitrescu 		n++;
347344cad685SCristian Dumitrescu 
347444cad685SCristian Dumitrescu 		/* ether <da> <sa> */
347544cad685SCristian Dumitrescu 		if ((n_tokens < 3) ||
347644cad685SCristian Dumitrescu 			strcmp(tokens[0], "ether") ||
347744cad685SCristian Dumitrescu 			parse_mac_addr(tokens[1], &a->encap.vxlan.ether.da) ||
347844cad685SCristian Dumitrescu 			parse_mac_addr(tokens[2], &a->encap.vxlan.ether.sa))
347944cad685SCristian Dumitrescu 			return 0;
348044cad685SCristian Dumitrescu 
348144cad685SCristian Dumitrescu 		n_tokens -= 3;
348244cad685SCristian Dumitrescu 		tokens += 3;
348344cad685SCristian Dumitrescu 		n += 3;
348444cad685SCristian Dumitrescu 
348544cad685SCristian Dumitrescu 		/* [vlan <pcp> <dei> <vid>] */
348644cad685SCristian Dumitrescu 		if (strcmp(tokens[0], "vlan") == 0) {
348744cad685SCristian Dumitrescu 			uint32_t pcp, dei, vid;
348844cad685SCristian Dumitrescu 
348944cad685SCristian Dumitrescu 			if ((n_tokens < 4) ||
349044cad685SCristian Dumitrescu 				parser_read_uint32(&pcp, tokens[1]) ||
349144cad685SCristian Dumitrescu 				(pcp > 7) ||
349244cad685SCristian Dumitrescu 				parser_read_uint32(&dei, tokens[2]) ||
349344cad685SCristian Dumitrescu 				(dei > 1) ||
349444cad685SCristian Dumitrescu 				parser_read_uint32(&vid, tokens[3]) ||
349544cad685SCristian Dumitrescu 				(vid > 0xFFF))
349644cad685SCristian Dumitrescu 				return 0;
349744cad685SCristian Dumitrescu 
349844cad685SCristian Dumitrescu 			a->encap.vxlan.vlan.pcp = pcp;
349944cad685SCristian Dumitrescu 			a->encap.vxlan.vlan.dei = dei;
350044cad685SCristian Dumitrescu 			a->encap.vxlan.vlan.vid = vid;
350144cad685SCristian Dumitrescu 
350244cad685SCristian Dumitrescu 			n_tokens -= 4;
350344cad685SCristian Dumitrescu 			tokens += 4;
350444cad685SCristian Dumitrescu 			n += 4;
350544cad685SCristian Dumitrescu 		}
350644cad685SCristian Dumitrescu 
350744cad685SCristian Dumitrescu 		/* ipv4 <sa> <da> <dscp> <ttl>
350844cad685SCristian Dumitrescu 		   | ipv6 <sa> <da> <flow_label> <dscp> <hop_limit> */
350944cad685SCristian Dumitrescu 		if (strcmp(tokens[0], "ipv4") == 0) {
351044cad685SCristian Dumitrescu 			struct in_addr sa, da;
351144cad685SCristian Dumitrescu 			uint8_t dscp, ttl;
351244cad685SCristian Dumitrescu 
351344cad685SCristian Dumitrescu 			if ((n_tokens < 5) ||
351444cad685SCristian Dumitrescu 				parse_ipv4_addr(tokens[1], &sa) ||
351544cad685SCristian Dumitrescu 				parse_ipv4_addr(tokens[2], &da) ||
351644cad685SCristian Dumitrescu 				parser_read_uint8(&dscp, tokens[3]) ||
351744cad685SCristian Dumitrescu 				(dscp > 64) ||
351844cad685SCristian Dumitrescu 				parser_read_uint8(&ttl, tokens[4]))
351944cad685SCristian Dumitrescu 				return 0;
352044cad685SCristian Dumitrescu 
352144cad685SCristian Dumitrescu 			a->encap.vxlan.ipv4.sa = rte_be_to_cpu_32(sa.s_addr);
352244cad685SCristian Dumitrescu 			a->encap.vxlan.ipv4.da = rte_be_to_cpu_32(da.s_addr);
352344cad685SCristian Dumitrescu 			a->encap.vxlan.ipv4.dscp = dscp;
352444cad685SCristian Dumitrescu 			a->encap.vxlan.ipv4.ttl = ttl;
352544cad685SCristian Dumitrescu 
352644cad685SCristian Dumitrescu 			n_tokens -= 5;
352744cad685SCristian Dumitrescu 			tokens += 5;
352844cad685SCristian Dumitrescu 			n += 5;
352944cad685SCristian Dumitrescu 		} else if (strcmp(tokens[0], "ipv6") == 0) {
35305ac1abddSRobin Jarry 			struct rte_ipv6_addr sa, da;
353144cad685SCristian Dumitrescu 			uint32_t flow_label;
353244cad685SCristian Dumitrescu 			uint8_t dscp, hop_limit;
353344cad685SCristian Dumitrescu 
353444cad685SCristian Dumitrescu 			if ((n_tokens < 6) ||
353544cad685SCristian Dumitrescu 				parse_ipv6_addr(tokens[1], &sa) ||
353644cad685SCristian Dumitrescu 				parse_ipv6_addr(tokens[2], &da) ||
353744cad685SCristian Dumitrescu 				parser_read_uint32(&flow_label, tokens[3]) ||
353844cad685SCristian Dumitrescu 				parser_read_uint8(&dscp, tokens[4]) ||
353944cad685SCristian Dumitrescu 				(dscp > 64) ||
354044cad685SCristian Dumitrescu 				parser_read_uint8(&hop_limit, tokens[5]))
354144cad685SCristian Dumitrescu 				return 0;
354244cad685SCristian Dumitrescu 
35435ac1abddSRobin Jarry 			a->encap.vxlan.ipv6.sa = sa;
35445ac1abddSRobin Jarry 			a->encap.vxlan.ipv6.da = da;
354544cad685SCristian Dumitrescu 			a->encap.vxlan.ipv6.flow_label = flow_label;
354644cad685SCristian Dumitrescu 			a->encap.vxlan.ipv6.dscp = dscp;
354744cad685SCristian Dumitrescu 			a->encap.vxlan.ipv6.hop_limit = hop_limit;
354844cad685SCristian Dumitrescu 
354944cad685SCristian Dumitrescu 			n_tokens -= 6;
355044cad685SCristian Dumitrescu 			tokens += 6;
355144cad685SCristian Dumitrescu 			n += 6;
355244cad685SCristian Dumitrescu 		} else
355344cad685SCristian Dumitrescu 			return 0;
355444cad685SCristian Dumitrescu 
355544cad685SCristian Dumitrescu 		/* udp <sp> <dp> */
355644cad685SCristian Dumitrescu 		if ((n_tokens < 3) ||
355744cad685SCristian Dumitrescu 			strcmp(tokens[0], "udp") ||
355844cad685SCristian Dumitrescu 			parser_read_uint16(&a->encap.vxlan.udp.sp, tokens[1]) ||
355944cad685SCristian Dumitrescu 			parser_read_uint16(&a->encap.vxlan.udp.dp, tokens[2]))
356044cad685SCristian Dumitrescu 			return 0;
356144cad685SCristian Dumitrescu 
356244cad685SCristian Dumitrescu 		n_tokens -= 3;
356344cad685SCristian Dumitrescu 		tokens += 3;
356444cad685SCristian Dumitrescu 		n += 3;
356544cad685SCristian Dumitrescu 
356644cad685SCristian Dumitrescu 		/* vxlan <vni> */
356744cad685SCristian Dumitrescu 		if ((n_tokens < 2) ||
356844cad685SCristian Dumitrescu 			strcmp(tokens[0], "vxlan") ||
356944cad685SCristian Dumitrescu 			parser_read_uint32(&a->encap.vxlan.vxlan.vni, tokens[1]) ||
357044cad685SCristian Dumitrescu 			(a->encap.vxlan.vxlan.vni > 0xFFFFFF))
357144cad685SCristian Dumitrescu 			return 0;
357244cad685SCristian Dumitrescu 
357344cad685SCristian Dumitrescu 		n_tokens -= 2;
357444cad685SCristian Dumitrescu 		tokens += 2;
357544cad685SCristian Dumitrescu 		n += 2;
357644cad685SCristian Dumitrescu 
357744cad685SCristian Dumitrescu 		a->encap.type = RTE_TABLE_ACTION_ENCAP_VXLAN;
357844cad685SCristian Dumitrescu 		a->action_mask |= 1 << RTE_TABLE_ACTION_ENCAP;
357944cad685SCristian Dumitrescu 		return 1 + n;
358044cad685SCristian Dumitrescu 	}
358144cad685SCristian Dumitrescu 
3582a3a95b7dSJasvinder Singh 	return 0;
3583a3a95b7dSJasvinder Singh }
3584a3a95b7dSJasvinder Singh 
3585a3a95b7dSJasvinder Singh static uint32_t
3586a3a95b7dSJasvinder Singh parse_table_action_nat(char **tokens,
3587a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3588a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3589a3a95b7dSJasvinder Singh {
3590a3a95b7dSJasvinder Singh 	if ((n_tokens < 4) ||
3591a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "nat"))
3592a3a95b7dSJasvinder Singh 		return 0;
3593a3a95b7dSJasvinder Singh 
3594a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "ipv4") == 0) {
3595a3a95b7dSJasvinder Singh 		struct in_addr addr;
3596a3a95b7dSJasvinder Singh 		uint16_t port;
3597a3a95b7dSJasvinder Singh 
3598a3a95b7dSJasvinder Singh 		if (parse_ipv4_addr(tokens[2], &addr) ||
3599a3a95b7dSJasvinder Singh 			parser_read_uint16(&port, tokens[3]))
3600a3a95b7dSJasvinder Singh 			return 0;
3601a3a95b7dSJasvinder Singh 
3602a3a95b7dSJasvinder Singh 		a->nat.ip_version = 1;
3603a3a95b7dSJasvinder Singh 		a->nat.addr.ipv4 = rte_be_to_cpu_32(addr.s_addr);
3604a3a95b7dSJasvinder Singh 		a->nat.port = port;
3605a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3606a3a95b7dSJasvinder Singh 		return 4;
3607a3a95b7dSJasvinder Singh 	}
3608a3a95b7dSJasvinder Singh 
3609a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "ipv6") == 0) {
36105ac1abddSRobin Jarry 		struct rte_ipv6_addr addr;
3611a3a95b7dSJasvinder Singh 		uint16_t port;
3612a3a95b7dSJasvinder Singh 
3613a3a95b7dSJasvinder Singh 		if (parse_ipv6_addr(tokens[2], &addr) ||
3614a3a95b7dSJasvinder Singh 			parser_read_uint16(&port, tokens[3]))
3615a3a95b7dSJasvinder Singh 			return 0;
3616a3a95b7dSJasvinder Singh 
3617a3a95b7dSJasvinder Singh 		a->nat.ip_version = 0;
36185ac1abddSRobin Jarry 		a->nat.addr.ipv6 = addr;
3619a3a95b7dSJasvinder Singh 		a->nat.port = port;
3620a3a95b7dSJasvinder Singh 		a->action_mask |= 1 << RTE_TABLE_ACTION_NAT;
3621a3a95b7dSJasvinder Singh 		return 4;
3622a3a95b7dSJasvinder Singh 	}
3623a3a95b7dSJasvinder Singh 
3624a3a95b7dSJasvinder Singh 	return 0;
3625a3a95b7dSJasvinder Singh }
3626a3a95b7dSJasvinder Singh 
3627a3a95b7dSJasvinder Singh static uint32_t
3628a3a95b7dSJasvinder Singh parse_table_action_ttl(char **tokens,
3629a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3630a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3631a3a95b7dSJasvinder Singh {
3632a3a95b7dSJasvinder Singh 	if ((n_tokens < 2) ||
3633a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "ttl"))
3634a3a95b7dSJasvinder Singh 		return 0;
3635a3a95b7dSJasvinder Singh 
3636a3a95b7dSJasvinder Singh 	if (strcmp(tokens[1], "dec") == 0)
3637a3a95b7dSJasvinder Singh 		a->ttl.decrement = 1;
3638a3a95b7dSJasvinder Singh 	else if (strcmp(tokens[1], "keep") == 0)
3639a3a95b7dSJasvinder Singh 		a->ttl.decrement = 0;
3640a3a95b7dSJasvinder Singh 	else
3641a3a95b7dSJasvinder Singh 		return 0;
3642a3a95b7dSJasvinder Singh 
3643a3a95b7dSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_TTL;
3644a3a95b7dSJasvinder Singh 	return 2;
3645a3a95b7dSJasvinder Singh }
3646a3a95b7dSJasvinder Singh 
3647a3a95b7dSJasvinder Singh static uint32_t
3648a3a95b7dSJasvinder Singh parse_table_action_stats(char **tokens,
3649a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3650a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3651a3a95b7dSJasvinder Singh {
3652a3a95b7dSJasvinder Singh 	if ((n_tokens < 1) ||
3653a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "stats"))
3654a3a95b7dSJasvinder Singh 		return 0;
3655a3a95b7dSJasvinder Singh 
3656a3a95b7dSJasvinder Singh 	a->stats.n_packets = 0;
3657a3a95b7dSJasvinder Singh 	a->stats.n_bytes = 0;
3658a3a95b7dSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_STATS;
3659a3a95b7dSJasvinder Singh 	return 1;
3660a3a95b7dSJasvinder Singh }
3661a3a95b7dSJasvinder Singh 
3662a3a95b7dSJasvinder Singh static uint32_t
3663a3a95b7dSJasvinder Singh parse_table_action_time(char **tokens,
3664a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
3665a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
3666a3a95b7dSJasvinder Singh {
3667a3a95b7dSJasvinder Singh 	if ((n_tokens < 1) ||
3668a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "time"))
3669a3a95b7dSJasvinder Singh 		return 0;
3670a3a95b7dSJasvinder Singh 
3671a3a95b7dSJasvinder Singh 	a->time.time = rte_rdtsc();
3672a3a95b7dSJasvinder Singh 	a->action_mask |= 1 << RTE_TABLE_ACTION_TIME;
3673a3a95b7dSJasvinder Singh 	return 1;
3674a3a95b7dSJasvinder Singh }
3675a3a95b7dSJasvinder Singh 
36761edccebcSFan Zhang static void
36771edccebcSFan Zhang parse_free_sym_crypto_param_data(struct rte_table_action_sym_crypto_params *p)
36781edccebcSFan Zhang {
36791edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform[2] = {NULL};
36801edccebcSFan Zhang 	uint32_t i;
36811edccebcSFan Zhang 
36821edccebcSFan Zhang 	xform[0] = p->xform;
36831edccebcSFan Zhang 	if (xform[0])
36841edccebcSFan Zhang 		xform[1] = xform[0]->next;
36851edccebcSFan Zhang 
36861edccebcSFan Zhang 	for (i = 0; i < 2; i++) {
36871edccebcSFan Zhang 		if (xform[i] == NULL)
36881edccebcSFan Zhang 			continue;
36891edccebcSFan Zhang 
36901edccebcSFan Zhang 		switch (xform[i]->type) {
36911edccebcSFan Zhang 		case RTE_CRYPTO_SYM_XFORM_CIPHER:
36921edccebcSFan Zhang 			free(p->cipher_auth.cipher_iv.val);
36931edccebcSFan Zhang 			free(p->cipher_auth.cipher_iv_update.val);
36941edccebcSFan Zhang 			break;
36951edccebcSFan Zhang 		case RTE_CRYPTO_SYM_XFORM_AUTH:
36961edccebcSFan Zhang 			if (p->cipher_auth.auth_iv.val)
36971edccebcSFan Zhang 				free(p->cipher_auth.cipher_iv.val);
36981edccebcSFan Zhang 			if (p->cipher_auth.auth_iv_update.val)
36991edccebcSFan Zhang 				free(p->cipher_auth.cipher_iv_update.val);
37001edccebcSFan Zhang 			break;
37011edccebcSFan Zhang 		case RTE_CRYPTO_SYM_XFORM_AEAD:
37021edccebcSFan Zhang 			free(p->aead.iv.val);
37031edccebcSFan Zhang 			free(p->aead.aad.val);
37041edccebcSFan Zhang 			break;
37051edccebcSFan Zhang 		default:
37061edccebcSFan Zhang 			continue;
37071edccebcSFan Zhang 		}
37081edccebcSFan Zhang 	}
37091edccebcSFan Zhang 
37101edccebcSFan Zhang }
37111edccebcSFan Zhang 
37121edccebcSFan Zhang static struct rte_crypto_sym_xform *
37131edccebcSFan Zhang parse_table_action_cipher(struct rte_table_action_sym_crypto_params *p,
3714186b14d6SFan Zhang 		uint8_t *key, uint32_t max_key_len, char **tokens,
3715186b14d6SFan Zhang 		uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
37161edccebcSFan Zhang {
37171edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform_cipher;
37181edccebcSFan Zhang 	int status;
37191edccebcSFan Zhang 	size_t len;
37201edccebcSFan Zhang 
37211edccebcSFan Zhang 	if (n_tokens < 7 || strcmp(tokens[1], "cipher_algo") ||
37221edccebcSFan Zhang 			strcmp(tokens[3], "cipher_key") ||
37231edccebcSFan Zhang 			strcmp(tokens[5], "cipher_iv"))
37241edccebcSFan Zhang 		return NULL;
37251edccebcSFan Zhang 
37261edccebcSFan Zhang 	xform_cipher = calloc(1, sizeof(*xform_cipher));
37271edccebcSFan Zhang 	if (xform_cipher == NULL)
37281edccebcSFan Zhang 		return NULL;
37291edccebcSFan Zhang 
37301edccebcSFan Zhang 	xform_cipher->type = RTE_CRYPTO_SYM_XFORM_CIPHER;
37311edccebcSFan Zhang 	xform_cipher->cipher.op = encrypt ? RTE_CRYPTO_CIPHER_OP_ENCRYPT :
37321edccebcSFan Zhang 			RTE_CRYPTO_CIPHER_OP_DECRYPT;
37331edccebcSFan Zhang 
37341edccebcSFan Zhang 	/* cipher_algo */
37351edccebcSFan Zhang 	status = rte_cryptodev_get_cipher_algo_enum(
37361edccebcSFan Zhang 			&xform_cipher->cipher.algo, tokens[2]);
37371edccebcSFan Zhang 	if (status < 0)
37381edccebcSFan Zhang 		goto error_exit;
37391edccebcSFan Zhang 
37401edccebcSFan Zhang 	/* cipher_key */
37411edccebcSFan Zhang 	len = strlen(tokens[4]);
3742186b14d6SFan Zhang 	if (len / 2 > max_key_len) {
3743186b14d6SFan Zhang 		status = -ENOMEM;
37441edccebcSFan Zhang 		goto error_exit;
3745186b14d6SFan Zhang 	}
37461edccebcSFan Zhang 
3747186b14d6SFan Zhang 	status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
37481edccebcSFan Zhang 	if (status < 0)
37491edccebcSFan Zhang 		goto error_exit;
37501edccebcSFan Zhang 
3751186b14d6SFan Zhang 	xform_cipher->cipher.key.data = key;
37521edccebcSFan Zhang 	xform_cipher->cipher.key.length = (uint16_t)len;
37531edccebcSFan Zhang 
37541edccebcSFan Zhang 	/* cipher_iv */
37551edccebcSFan Zhang 	len = strlen(tokens[6]);
37561edccebcSFan Zhang 
37571edccebcSFan Zhang 	p->cipher_auth.cipher_iv.val = calloc(1, len / 2 + 1);
37581edccebcSFan Zhang 	if (p->cipher_auth.cipher_iv.val == NULL)
37591edccebcSFan Zhang 		goto error_exit;
37601edccebcSFan Zhang 
37611edccebcSFan Zhang 	status = parse_hex_string(tokens[6],
37621edccebcSFan Zhang 			p->cipher_auth.cipher_iv.val,
37631edccebcSFan Zhang 			(uint32_t *)&len);
37641edccebcSFan Zhang 	if (status < 0)
37651edccebcSFan Zhang 		goto error_exit;
37661edccebcSFan Zhang 
37671edccebcSFan Zhang 	xform_cipher->cipher.iv.length = (uint16_t)len;
37681edccebcSFan Zhang 	xform_cipher->cipher.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
37691edccebcSFan Zhang 	p->cipher_auth.cipher_iv.length = (uint32_t)len;
37701edccebcSFan Zhang 	*used_n_tokens = 7;
37711edccebcSFan Zhang 
37721edccebcSFan Zhang 	return xform_cipher;
37731edccebcSFan Zhang 
37741edccebcSFan Zhang error_exit:
37751edccebcSFan Zhang 	if (p->cipher_auth.cipher_iv.val) {
37761edccebcSFan Zhang 		free(p->cipher_auth.cipher_iv.val);
37771edccebcSFan Zhang 		p->cipher_auth.cipher_iv.val = NULL;
37781edccebcSFan Zhang 	}
37791edccebcSFan Zhang 
37801edccebcSFan Zhang 	free(xform_cipher);
37811edccebcSFan Zhang 
37821edccebcSFan Zhang 	return NULL;
37831edccebcSFan Zhang }
37841edccebcSFan Zhang 
37851edccebcSFan Zhang static struct rte_crypto_sym_xform *
37861edccebcSFan Zhang parse_table_action_cipher_auth(struct rte_table_action_sym_crypto_params *p,
3787186b14d6SFan Zhang 		uint8_t *key, uint32_t max_key_len, char **tokens,
3788186b14d6SFan Zhang 		uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
37891edccebcSFan Zhang {
37901edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform_cipher;
37911edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform_auth;
37921edccebcSFan Zhang 	int status;
37931edccebcSFan Zhang 	size_t len;
37941edccebcSFan Zhang 
37951edccebcSFan Zhang 	if (n_tokens < 13 ||
37961edccebcSFan Zhang 			strcmp(tokens[7], "auth_algo") ||
37971edccebcSFan Zhang 			strcmp(tokens[9], "auth_key") ||
37981edccebcSFan Zhang 			strcmp(tokens[11], "digest_size"))
37991edccebcSFan Zhang 		return NULL;
38001edccebcSFan Zhang 
38011edccebcSFan Zhang 	xform_auth = calloc(1, sizeof(*xform_auth));
38021edccebcSFan Zhang 	if (xform_auth == NULL)
38031edccebcSFan Zhang 		return NULL;
38041edccebcSFan Zhang 
38051edccebcSFan Zhang 	xform_auth->type = RTE_CRYPTO_SYM_XFORM_AUTH;
38061edccebcSFan Zhang 	xform_auth->auth.op = encrypt ? RTE_CRYPTO_AUTH_OP_GENERATE :
38071edccebcSFan Zhang 			RTE_CRYPTO_AUTH_OP_VERIFY;
38081edccebcSFan Zhang 
38091edccebcSFan Zhang 	/* auth_algo */
38101edccebcSFan Zhang 	status = rte_cryptodev_get_auth_algo_enum(&xform_auth->auth.algo,
38111edccebcSFan Zhang 			tokens[8]);
38121edccebcSFan Zhang 	if (status < 0)
38131edccebcSFan Zhang 		goto error_exit;
38141edccebcSFan Zhang 
38151edccebcSFan Zhang 	/* auth_key */
38161edccebcSFan Zhang 	len = strlen(tokens[10]);
3817186b14d6SFan Zhang 	if (len / 2 > max_key_len) {
3818186b14d6SFan Zhang 		status = -ENOMEM;
38191edccebcSFan Zhang 		goto error_exit;
3820186b14d6SFan Zhang 	}
38211edccebcSFan Zhang 
3822186b14d6SFan Zhang 	status = parse_hex_string(tokens[10], key, (uint32_t *)&len);
38231edccebcSFan Zhang 	if (status < 0)
38241edccebcSFan Zhang 		goto error_exit;
38251edccebcSFan Zhang 
3826186b14d6SFan Zhang 	xform_auth->auth.key.data = key;
38271edccebcSFan Zhang 	xform_auth->auth.key.length = (uint16_t)len;
38281edccebcSFan Zhang 
3829186b14d6SFan Zhang 	key += xform_auth->auth.key.length;
3830186b14d6SFan Zhang 	max_key_len -= xform_auth->auth.key.length;
3831186b14d6SFan Zhang 
38321edccebcSFan Zhang 	if (strcmp(tokens[11], "digest_size"))
38331edccebcSFan Zhang 		goto error_exit;
38341edccebcSFan Zhang 
38351edccebcSFan Zhang 	status = parser_read_uint16(&xform_auth->auth.digest_length,
38361edccebcSFan Zhang 			tokens[12]);
38371edccebcSFan Zhang 	if (status < 0)
38381edccebcSFan Zhang 		goto error_exit;
38391edccebcSFan Zhang 
3840186b14d6SFan Zhang 	xform_cipher = parse_table_action_cipher(p, key, max_key_len, tokens,
3841186b14d6SFan Zhang 			7, encrypt, used_n_tokens);
38421edccebcSFan Zhang 	if (xform_cipher == NULL)
38431edccebcSFan Zhang 		goto error_exit;
38441edccebcSFan Zhang 
38451edccebcSFan Zhang 	*used_n_tokens += 6;
38461edccebcSFan Zhang 
38471edccebcSFan Zhang 	if (encrypt) {
38481edccebcSFan Zhang 		xform_cipher->next = xform_auth;
38491edccebcSFan Zhang 		return xform_cipher;
38501edccebcSFan Zhang 	} else {
38511edccebcSFan Zhang 		xform_auth->next = xform_cipher;
38521edccebcSFan Zhang 		return xform_auth;
38531edccebcSFan Zhang 	}
38541edccebcSFan Zhang 
38551edccebcSFan Zhang error_exit:
38561edccebcSFan Zhang 	if (p->cipher_auth.auth_iv.val) {
38571edccebcSFan Zhang 		free(p->cipher_auth.auth_iv.val);
38581edccebcSFan Zhang 		p->cipher_auth.auth_iv.val = 0;
38591edccebcSFan Zhang 	}
38601edccebcSFan Zhang 
38611edccebcSFan Zhang 	free(xform_auth);
38621edccebcSFan Zhang 
38631edccebcSFan Zhang 	return NULL;
38641edccebcSFan Zhang }
38651edccebcSFan Zhang 
38661edccebcSFan Zhang static struct rte_crypto_sym_xform *
38671edccebcSFan Zhang parse_table_action_aead(struct rte_table_action_sym_crypto_params *p,
3868186b14d6SFan Zhang 		uint8_t *key, uint32_t max_key_len, char **tokens,
3869186b14d6SFan Zhang 		uint32_t n_tokens, uint32_t encrypt, uint32_t *used_n_tokens)
38701edccebcSFan Zhang {
38711edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform_aead;
38721edccebcSFan Zhang 	int status;
38731edccebcSFan Zhang 	size_t len;
38741edccebcSFan Zhang 
38751edccebcSFan Zhang 	if (n_tokens < 11 || strcmp(tokens[1], "aead_algo") ||
38761edccebcSFan Zhang 			strcmp(tokens[3], "aead_key") ||
38771edccebcSFan Zhang 			strcmp(tokens[5], "aead_iv") ||
38781edccebcSFan Zhang 			strcmp(tokens[7], "aead_aad") ||
38791edccebcSFan Zhang 			strcmp(tokens[9], "digest_size"))
38801edccebcSFan Zhang 		return NULL;
38811edccebcSFan Zhang 
38821edccebcSFan Zhang 	xform_aead = calloc(1, sizeof(*xform_aead));
38831edccebcSFan Zhang 	if (xform_aead == NULL)
38841edccebcSFan Zhang 		return NULL;
38851edccebcSFan Zhang 
38861edccebcSFan Zhang 	xform_aead->type = RTE_CRYPTO_SYM_XFORM_AEAD;
38871edccebcSFan Zhang 	xform_aead->aead.op = encrypt ? RTE_CRYPTO_AEAD_OP_ENCRYPT :
38881edccebcSFan Zhang 			RTE_CRYPTO_AEAD_OP_DECRYPT;
38891edccebcSFan Zhang 
38901edccebcSFan Zhang 	/* aead_algo */
38911edccebcSFan Zhang 	status = rte_cryptodev_get_aead_algo_enum(&xform_aead->aead.algo,
38921edccebcSFan Zhang 			tokens[2]);
38931edccebcSFan Zhang 	if (status < 0)
38941edccebcSFan Zhang 		goto error_exit;
38951edccebcSFan Zhang 
38961edccebcSFan Zhang 	/* aead_key */
38971edccebcSFan Zhang 	len = strlen(tokens[4]);
3898186b14d6SFan Zhang 	if (len / 2 > max_key_len) {
3899186b14d6SFan Zhang 		status = -ENOMEM;
39001edccebcSFan Zhang 		goto error_exit;
3901186b14d6SFan Zhang 	}
39021edccebcSFan Zhang 
3903186b14d6SFan Zhang 	status = parse_hex_string(tokens[4], key, (uint32_t *)&len);
39041edccebcSFan Zhang 	if (status < 0)
39051edccebcSFan Zhang 		goto error_exit;
39061edccebcSFan Zhang 
3907186b14d6SFan Zhang 	xform_aead->aead.key.data = key;
39081edccebcSFan Zhang 	xform_aead->aead.key.length = (uint16_t)len;
39091edccebcSFan Zhang 
39101edccebcSFan Zhang 	/* aead_iv */
39111edccebcSFan Zhang 	len = strlen(tokens[6]);
39121edccebcSFan Zhang 	p->aead.iv.val = calloc(1, len / 2 + 1);
39131edccebcSFan Zhang 	if (p->aead.iv.val == NULL)
39141edccebcSFan Zhang 		goto error_exit;
39151edccebcSFan Zhang 
39161edccebcSFan Zhang 	status = parse_hex_string(tokens[6], p->aead.iv.val,
39171edccebcSFan Zhang 			(uint32_t *)&len);
39181edccebcSFan Zhang 	if (status < 0)
39191edccebcSFan Zhang 		goto error_exit;
39201edccebcSFan Zhang 
39211edccebcSFan Zhang 	xform_aead->aead.iv.length = (uint16_t)len;
39221edccebcSFan Zhang 	xform_aead->aead.iv.offset = RTE_TABLE_ACTION_SYM_CRYPTO_IV_OFFSET;
39231edccebcSFan Zhang 	p->aead.iv.length = (uint32_t)len;
39241edccebcSFan Zhang 
39251edccebcSFan Zhang 	/* aead_aad */
39261edccebcSFan Zhang 	len = strlen(tokens[8]);
39271edccebcSFan Zhang 	p->aead.aad.val = calloc(1, len / 2 + 1);
39281edccebcSFan Zhang 	if (p->aead.aad.val == NULL)
39291edccebcSFan Zhang 		goto error_exit;
39301edccebcSFan Zhang 
39311edccebcSFan Zhang 	status = parse_hex_string(tokens[8], p->aead.aad.val, (uint32_t *)&len);
39321edccebcSFan Zhang 	if (status < 0)
39331edccebcSFan Zhang 		goto error_exit;
39341edccebcSFan Zhang 
39351edccebcSFan Zhang 	xform_aead->aead.aad_length = (uint16_t)len;
39361edccebcSFan Zhang 	p->aead.aad.length = (uint32_t)len;
39371edccebcSFan Zhang 
39381edccebcSFan Zhang 	/* digest_size */
39391edccebcSFan Zhang 	status = parser_read_uint16(&xform_aead->aead.digest_length,
39401edccebcSFan Zhang 			tokens[10]);
39411edccebcSFan Zhang 	if (status < 0)
39421edccebcSFan Zhang 		goto error_exit;
39431edccebcSFan Zhang 
39441edccebcSFan Zhang 	*used_n_tokens = 11;
39451edccebcSFan Zhang 
39461edccebcSFan Zhang 	return xform_aead;
39471edccebcSFan Zhang 
39481edccebcSFan Zhang error_exit:
39491edccebcSFan Zhang 	if (p->aead.iv.val) {
39501edccebcSFan Zhang 		free(p->aead.iv.val);
39511edccebcSFan Zhang 		p->aead.iv.val = NULL;
39521edccebcSFan Zhang 	}
39531edccebcSFan Zhang 	if (p->aead.aad.val) {
39541edccebcSFan Zhang 		free(p->aead.aad.val);
39551edccebcSFan Zhang 		p->aead.aad.val = NULL;
39561edccebcSFan Zhang 	}
39571edccebcSFan Zhang 
39581edccebcSFan Zhang 	free(xform_aead);
39591edccebcSFan Zhang 
39601edccebcSFan Zhang 	return NULL;
39611edccebcSFan Zhang }
39621edccebcSFan Zhang 
39631edccebcSFan Zhang 
39641edccebcSFan Zhang static uint32_t
39651edccebcSFan Zhang parse_table_action_sym_crypto(char **tokens,
39661edccebcSFan Zhang 	uint32_t n_tokens,
39671edccebcSFan Zhang 	struct table_rule_action *a)
39681edccebcSFan Zhang {
39691edccebcSFan Zhang 	struct rte_table_action_sym_crypto_params *p = &a->sym_crypto;
39701edccebcSFan Zhang 	struct rte_crypto_sym_xform *xform = NULL;
3971186b14d6SFan Zhang 	uint8_t *key = a->sym_crypto_key;
3972186b14d6SFan Zhang 	uint32_t max_key_len = SYM_CRYPTO_MAX_KEY_SIZE;
39731edccebcSFan Zhang 	uint32_t used_n_tokens;
39741edccebcSFan Zhang 	uint32_t encrypt;
39751edccebcSFan Zhang 	int status;
39761edccebcSFan Zhang 
39771edccebcSFan Zhang 	if ((n_tokens < 12) ||
39781edccebcSFan Zhang 		strcmp(tokens[0], "sym_crypto") ||
39791edccebcSFan Zhang 		strcmp(tokens[2], "type"))
39801edccebcSFan Zhang 		return 0;
39811edccebcSFan Zhang 
39821edccebcSFan Zhang 	memset(p, 0, sizeof(*p));
39831edccebcSFan Zhang 
39841edccebcSFan Zhang 	if (strcmp(tokens[1], "encrypt") == 0)
39851edccebcSFan Zhang 		encrypt = 1;
39861edccebcSFan Zhang 	else
39871edccebcSFan Zhang 		encrypt = 0;
39881edccebcSFan Zhang 
39891edccebcSFan Zhang 	status = parser_read_uint32(&p->data_offset, tokens[n_tokens - 1]);
39901edccebcSFan Zhang 	if (status < 0)
39911edccebcSFan Zhang 		return 0;
39921edccebcSFan Zhang 
39931edccebcSFan Zhang 	if (strcmp(tokens[3], "cipher") == 0) {
39941edccebcSFan Zhang 		tokens += 3;
39951edccebcSFan Zhang 		n_tokens -= 3;
39961edccebcSFan Zhang 
3997186b14d6SFan Zhang 		xform = parse_table_action_cipher(p, key, max_key_len, tokens,
3998186b14d6SFan Zhang 				n_tokens, encrypt, &used_n_tokens);
39991edccebcSFan Zhang 	} else if (strcmp(tokens[3], "cipher_auth") == 0) {
40001edccebcSFan Zhang 		tokens += 3;
40011edccebcSFan Zhang 		n_tokens -= 3;
40021edccebcSFan Zhang 
4003186b14d6SFan Zhang 		xform = parse_table_action_cipher_auth(p, key, max_key_len,
4004186b14d6SFan Zhang 				tokens, n_tokens, encrypt, &used_n_tokens);
40051edccebcSFan Zhang 	} else if (strcmp(tokens[3], "aead") == 0) {
40061edccebcSFan Zhang 		tokens += 3;
40071edccebcSFan Zhang 		n_tokens -= 3;
40081edccebcSFan Zhang 
4009186b14d6SFan Zhang 		xform = parse_table_action_aead(p, key, max_key_len, tokens,
4010186b14d6SFan Zhang 				n_tokens, encrypt, &used_n_tokens);
40111edccebcSFan Zhang 	}
40121edccebcSFan Zhang 
40131edccebcSFan Zhang 	if (xform == NULL)
40141edccebcSFan Zhang 		return 0;
40151edccebcSFan Zhang 
40161edccebcSFan Zhang 	p->xform = xform;
40171edccebcSFan Zhang 
40181edccebcSFan Zhang 	if (strcmp(tokens[used_n_tokens], "data_offset")) {
40191edccebcSFan Zhang 		parse_free_sym_crypto_param_data(p);
40201edccebcSFan Zhang 		return 0;
40211edccebcSFan Zhang 	}
40221edccebcSFan Zhang 
40231edccebcSFan Zhang 	a->action_mask |= 1 << RTE_TABLE_ACTION_SYM_CRYPTO;
40241edccebcSFan Zhang 
40251edccebcSFan Zhang 	return used_n_tokens + 5;
40261edccebcSFan Zhang }
40271edccebcSFan Zhang 
4028a3a95b7dSJasvinder Singh static uint32_t
40291bdf2632SCristian Dumitrescu parse_table_action_tag(char **tokens,
40301bdf2632SCristian Dumitrescu 	uint32_t n_tokens,
40311bdf2632SCristian Dumitrescu 	struct table_rule_action *a)
40321bdf2632SCristian Dumitrescu {
40331bdf2632SCristian Dumitrescu 	if ((n_tokens < 2) ||
40341bdf2632SCristian Dumitrescu 		strcmp(tokens[0], "tag"))
40351bdf2632SCristian Dumitrescu 		return 0;
40361bdf2632SCristian Dumitrescu 
40371bdf2632SCristian Dumitrescu 	if (parser_read_uint32(&a->tag.tag, tokens[1]))
40381bdf2632SCristian Dumitrescu 		return 0;
40391bdf2632SCristian Dumitrescu 
40401bdf2632SCristian Dumitrescu 	a->action_mask |= 1 << RTE_TABLE_ACTION_TAG;
40411bdf2632SCristian Dumitrescu 	return 2;
40421bdf2632SCristian Dumitrescu }
40431bdf2632SCristian Dumitrescu 
40441bdf2632SCristian Dumitrescu static uint32_t
4045d5ed626fSCristian Dumitrescu parse_table_action_decap(char **tokens,
4046d5ed626fSCristian Dumitrescu 	uint32_t n_tokens,
4047d5ed626fSCristian Dumitrescu 	struct table_rule_action *a)
4048d5ed626fSCristian Dumitrescu {
4049d5ed626fSCristian Dumitrescu 	if ((n_tokens < 2) ||
4050d5ed626fSCristian Dumitrescu 		strcmp(tokens[0], "decap"))
4051d5ed626fSCristian Dumitrescu 		return 0;
4052d5ed626fSCristian Dumitrescu 
4053d5ed626fSCristian Dumitrescu 	if (parser_read_uint16(&a->decap.n, tokens[1]))
4054d5ed626fSCristian Dumitrescu 		return 0;
4055d5ed626fSCristian Dumitrescu 
4056d5ed626fSCristian Dumitrescu 	a->action_mask |= 1 << RTE_TABLE_ACTION_DECAP;
4057d5ed626fSCristian Dumitrescu 	return 2;
4058d5ed626fSCristian Dumitrescu }
4059d5ed626fSCristian Dumitrescu 
4060d5ed626fSCristian Dumitrescu static uint32_t
4061a3a95b7dSJasvinder Singh parse_table_action(char **tokens,
4062a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
4063a3a95b7dSJasvinder Singh 	char *out,
4064a3a95b7dSJasvinder Singh 	size_t out_size,
4065a3a95b7dSJasvinder Singh 	struct table_rule_action *a)
4066a3a95b7dSJasvinder Singh {
4067a3a95b7dSJasvinder Singh 	uint32_t n_tokens0 = n_tokens;
4068a3a95b7dSJasvinder Singh 
4069a3a95b7dSJasvinder Singh 	memset(a, 0, sizeof(*a));
4070a3a95b7dSJasvinder Singh 
4071a3a95b7dSJasvinder Singh 	if ((n_tokens < 2) ||
4072a3a95b7dSJasvinder Singh 		strcmp(tokens[0], "action"))
4073a3a95b7dSJasvinder Singh 		return 0;
4074a3a95b7dSJasvinder Singh 
4075a3a95b7dSJasvinder Singh 	tokens++;
4076a3a95b7dSJasvinder Singh 	n_tokens--;
4077a3a95b7dSJasvinder Singh 
4078a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "fwd") == 0)) {
4079a3a95b7dSJasvinder Singh 		uint32_t n;
4080a3a95b7dSJasvinder Singh 
4081a3a95b7dSJasvinder Singh 		n = parse_table_action_fwd(tokens, n_tokens, a);
4082a3a95b7dSJasvinder Singh 		if (n == 0) {
4083a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4084a3a95b7dSJasvinder Singh 				"action fwd");
4085a3a95b7dSJasvinder Singh 			return 0;
4086a3a95b7dSJasvinder Singh 		}
4087a3a95b7dSJasvinder Singh 
4088a3a95b7dSJasvinder Singh 		tokens += n;
4089a3a95b7dSJasvinder Singh 		n_tokens -= n;
4090a3a95b7dSJasvinder Singh 	}
4091a3a95b7dSJasvinder Singh 
4092802755dcSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "balance") == 0)) {
4093802755dcSJasvinder Singh 		uint32_t n;
4094802755dcSJasvinder Singh 
4095802755dcSJasvinder Singh 		n = parse_table_action_balance(tokens, n_tokens, a);
4096802755dcSJasvinder Singh 		if (n == 0) {
4097802755dcSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4098802755dcSJasvinder Singh 				"action balance");
4099802755dcSJasvinder Singh 			return 0;
4100802755dcSJasvinder Singh 		}
4101802755dcSJasvinder Singh 
4102802755dcSJasvinder Singh 		tokens += n;
4103802755dcSJasvinder Singh 		n_tokens -= n;
4104802755dcSJasvinder Singh 	}
4105802755dcSJasvinder Singh 
4106a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "meter") == 0)) {
4107a3a95b7dSJasvinder Singh 		uint32_t n;
4108a3a95b7dSJasvinder Singh 
4109a3a95b7dSJasvinder Singh 		n = parse_table_action_meter(tokens, n_tokens, a);
4110a3a95b7dSJasvinder Singh 		if (n == 0) {
4111a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4112a3a95b7dSJasvinder Singh 				"action meter");
4113a3a95b7dSJasvinder Singh 			return 0;
4114a3a95b7dSJasvinder Singh 		}
4115a3a95b7dSJasvinder Singh 
4116a3a95b7dSJasvinder Singh 		tokens += n;
4117a3a95b7dSJasvinder Singh 		n_tokens -= n;
4118a3a95b7dSJasvinder Singh 	}
4119a3a95b7dSJasvinder Singh 
4120a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "tm") == 0)) {
4121a3a95b7dSJasvinder Singh 		uint32_t n;
4122a3a95b7dSJasvinder Singh 
4123a3a95b7dSJasvinder Singh 		n = parse_table_action_tm(tokens, n_tokens, a);
4124a3a95b7dSJasvinder Singh 		if (n == 0) {
4125a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4126a3a95b7dSJasvinder Singh 				"action tm");
4127a3a95b7dSJasvinder Singh 			return 0;
4128a3a95b7dSJasvinder Singh 		}
4129a3a95b7dSJasvinder Singh 
4130a3a95b7dSJasvinder Singh 		tokens += n;
4131a3a95b7dSJasvinder Singh 		n_tokens -= n;
4132a3a95b7dSJasvinder Singh 	}
4133a3a95b7dSJasvinder Singh 
4134a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "encap") == 0)) {
4135a3a95b7dSJasvinder Singh 		uint32_t n;
4136a3a95b7dSJasvinder Singh 
4137a3a95b7dSJasvinder Singh 		n = parse_table_action_encap(tokens, n_tokens, a);
4138a3a95b7dSJasvinder Singh 		if (n == 0) {
4139a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4140a3a95b7dSJasvinder Singh 				"action encap");
4141a3a95b7dSJasvinder Singh 			return 0;
4142a3a95b7dSJasvinder Singh 		}
4143a3a95b7dSJasvinder Singh 
4144a3a95b7dSJasvinder Singh 		tokens += n;
4145a3a95b7dSJasvinder Singh 		n_tokens -= n;
4146a3a95b7dSJasvinder Singh 	}
4147a3a95b7dSJasvinder Singh 
4148a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "nat") == 0)) {
4149a3a95b7dSJasvinder Singh 		uint32_t n;
4150a3a95b7dSJasvinder Singh 
4151a3a95b7dSJasvinder Singh 		n = parse_table_action_nat(tokens, n_tokens, a);
4152a3a95b7dSJasvinder Singh 		if (n == 0) {
4153a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4154a3a95b7dSJasvinder Singh 				"action nat");
4155a3a95b7dSJasvinder Singh 			return 0;
4156a3a95b7dSJasvinder Singh 		}
4157a3a95b7dSJasvinder Singh 
4158a3a95b7dSJasvinder Singh 		tokens += n;
4159a3a95b7dSJasvinder Singh 		n_tokens -= n;
4160a3a95b7dSJasvinder Singh 	}
4161a3a95b7dSJasvinder Singh 
4162a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "ttl") == 0)) {
4163a3a95b7dSJasvinder Singh 		uint32_t n;
4164a3a95b7dSJasvinder Singh 
4165a3a95b7dSJasvinder Singh 		n = parse_table_action_ttl(tokens, n_tokens, a);
4166a3a95b7dSJasvinder Singh 		if (n == 0) {
4167a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4168a3a95b7dSJasvinder Singh 				"action ttl");
4169a3a95b7dSJasvinder Singh 			return 0;
4170a3a95b7dSJasvinder Singh 		}
4171a3a95b7dSJasvinder Singh 
4172a3a95b7dSJasvinder Singh 		tokens += n;
4173a3a95b7dSJasvinder Singh 		n_tokens -= n;
4174a3a95b7dSJasvinder Singh 	}
4175a3a95b7dSJasvinder Singh 
4176a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "stats") == 0)) {
4177a3a95b7dSJasvinder Singh 		uint32_t n;
4178a3a95b7dSJasvinder Singh 
4179a3a95b7dSJasvinder Singh 		n = parse_table_action_stats(tokens, n_tokens, a);
4180a3a95b7dSJasvinder Singh 		if (n == 0) {
4181a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4182a3a95b7dSJasvinder Singh 				"action stats");
4183a3a95b7dSJasvinder Singh 			return 0;
4184a3a95b7dSJasvinder Singh 		}
4185a3a95b7dSJasvinder Singh 
4186a3a95b7dSJasvinder Singh 		tokens += n;
4187a3a95b7dSJasvinder Singh 		n_tokens -= n;
4188a3a95b7dSJasvinder Singh 	}
4189a3a95b7dSJasvinder Singh 
4190a3a95b7dSJasvinder Singh 	if (n_tokens && (strcmp(tokens[0], "time") == 0)) {
4191a3a95b7dSJasvinder Singh 		uint32_t n;
4192a3a95b7dSJasvinder Singh 
4193a3a95b7dSJasvinder Singh 		n = parse_table_action_time(tokens, n_tokens, a);
4194a3a95b7dSJasvinder Singh 		if (n == 0) {
4195a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID,
4196a3a95b7dSJasvinder Singh 				"action time");
4197a3a95b7dSJasvinder Singh 			return 0;
4198a3a95b7dSJasvinder Singh 		}
4199a3a95b7dSJasvinder Singh 
4200a3a95b7dSJasvinder Singh 		tokens += n;
4201a3a95b7dSJasvinder Singh 		n_tokens -= n;
4202a3a95b7dSJasvinder Singh 	}
4203a3a95b7dSJasvinder Singh 
42041edccebcSFan Zhang 	if (n_tokens && (strcmp(tokens[0], "sym_crypto") == 0)) {
42051edccebcSFan Zhang 		uint32_t n;
42061edccebcSFan Zhang 
42071edccebcSFan Zhang 		n = parse_table_action_sym_crypto(tokens, n_tokens, a);
42081edccebcSFan Zhang 		if (n == 0) {
42091edccebcSFan Zhang 			snprintf(out, out_size, MSG_ARG_INVALID,
42101edccebcSFan Zhang 				"action sym_crypto");
42111bdf2632SCristian Dumitrescu 		}
42121bdf2632SCristian Dumitrescu 
42131bdf2632SCristian Dumitrescu 		tokens += n;
42141bdf2632SCristian Dumitrescu 		n_tokens -= n;
42151bdf2632SCristian Dumitrescu 	}
42161bdf2632SCristian Dumitrescu 
42171bdf2632SCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "tag") == 0)) {
42181bdf2632SCristian Dumitrescu 		uint32_t n;
42191bdf2632SCristian Dumitrescu 
42201bdf2632SCristian Dumitrescu 		n = parse_table_action_tag(tokens, n_tokens, a);
42211bdf2632SCristian Dumitrescu 		if (n == 0) {
42221bdf2632SCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
42231bdf2632SCristian Dumitrescu 				"action tag");
42241edccebcSFan Zhang 			return 0;
42251edccebcSFan Zhang 		}
42261edccebcSFan Zhang 
42271edccebcSFan Zhang 		tokens += n;
42281edccebcSFan Zhang 		n_tokens -= n;
42291edccebcSFan Zhang 	}
42301edccebcSFan Zhang 
4231d5ed626fSCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "decap") == 0)) {
4232d5ed626fSCristian Dumitrescu 		uint32_t n;
4233d5ed626fSCristian Dumitrescu 
4234d5ed626fSCristian Dumitrescu 		n = parse_table_action_decap(tokens, n_tokens, a);
4235d5ed626fSCristian Dumitrescu 		if (n == 0) {
4236d5ed626fSCristian Dumitrescu 			snprintf(out, out_size, MSG_ARG_INVALID,
4237d5ed626fSCristian Dumitrescu 				"action decap");
4238d5ed626fSCristian Dumitrescu 			return 0;
4239d5ed626fSCristian Dumitrescu 		}
4240d5ed626fSCristian Dumitrescu 
4241d5ed626fSCristian Dumitrescu 		tokens += n;
4242d5ed626fSCristian Dumitrescu 		n_tokens -= n;
4243d5ed626fSCristian Dumitrescu 	}
4244d5ed626fSCristian Dumitrescu 
4245a3a95b7dSJasvinder Singh 	if (n_tokens0 - n_tokens == 1) {
4246a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "action");
4247a3a95b7dSJasvinder Singh 		return 0;
4248a3a95b7dSJasvinder Singh 	}
4249a3a95b7dSJasvinder Singh 
4250a3a95b7dSJasvinder Singh 	return n_tokens0 - n_tokens;
4251a3a95b7dSJasvinder Singh }
4252a3a95b7dSJasvinder Singh 
425326b3effeSKevin Laatz 
425426b3effeSKevin Laatz static const char cmd_pipeline_table_rule_add_help[] =
425526b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> rule add\n"
425626b3effeSKevin Laatz "     match <match>\n"
425726b3effeSKevin Laatz "     action <table_action>\n";
425826b3effeSKevin Laatz 
4259a3a95b7dSJasvinder Singh static void
4260a3a95b7dSJasvinder Singh cmd_pipeline_table_rule_add(char **tokens,
4261a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
4262a3a95b7dSJasvinder Singh 	char *out,
4263a3a95b7dSJasvinder Singh 	size_t out_size)
4264a3a95b7dSJasvinder Singh {
4265a3a95b7dSJasvinder Singh 	struct table_rule_match m;
4266a3a95b7dSJasvinder Singh 	struct table_rule_action a;
4267a3a95b7dSJasvinder Singh 	char *pipeline_name;
4268a3a95b7dSJasvinder Singh 	uint32_t table_id, t0, n_tokens_parsed;
4269a3a95b7dSJasvinder Singh 	int status;
4270a3a95b7dSJasvinder Singh 
4271a3a95b7dSJasvinder Singh 	if (n_tokens < 8) {
4272a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4273a3a95b7dSJasvinder Singh 		return;
4274a3a95b7dSJasvinder Singh 	}
4275a3a95b7dSJasvinder Singh 
4276a3a95b7dSJasvinder Singh 	pipeline_name = tokens[1];
4277a3a95b7dSJasvinder Singh 
4278a3a95b7dSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
4279a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4280a3a95b7dSJasvinder Singh 		return;
4281a3a95b7dSJasvinder Singh 	}
4282a3a95b7dSJasvinder Singh 
4283a3a95b7dSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4284a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4285a3a95b7dSJasvinder Singh 		return;
4286a3a95b7dSJasvinder Singh 	}
4287a3a95b7dSJasvinder Singh 
4288a3a95b7dSJasvinder Singh 	if (strcmp(tokens[4], "rule") != 0) {
4289a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4290a3a95b7dSJasvinder Singh 		return;
4291a3a95b7dSJasvinder Singh 	}
4292a3a95b7dSJasvinder Singh 
4293a3a95b7dSJasvinder Singh 	if (strcmp(tokens[5], "add") != 0) {
4294a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4295a3a95b7dSJasvinder Singh 		return;
4296a3a95b7dSJasvinder Singh 	}
4297a3a95b7dSJasvinder Singh 
4298a3a95b7dSJasvinder Singh 	t0 = 6;
4299a3a95b7dSJasvinder Singh 
4300a3a95b7dSJasvinder Singh 	/* match */
4301a3a95b7dSJasvinder Singh 	n_tokens_parsed = parse_match(tokens + t0,
4302a3a95b7dSJasvinder Singh 		n_tokens - t0,
4303a3a95b7dSJasvinder Singh 		out,
4304a3a95b7dSJasvinder Singh 		out_size,
4305a3a95b7dSJasvinder Singh 		&m);
4306a3a95b7dSJasvinder Singh 	if (n_tokens_parsed == 0)
4307a3a95b7dSJasvinder Singh 		return;
4308a3a95b7dSJasvinder Singh 	t0 += n_tokens_parsed;
4309a3a95b7dSJasvinder Singh 
4310a3a95b7dSJasvinder Singh 	/* action */
4311a3a95b7dSJasvinder Singh 	n_tokens_parsed = parse_table_action(tokens + t0,
4312a3a95b7dSJasvinder Singh 		n_tokens - t0,
4313a3a95b7dSJasvinder Singh 		out,
4314a3a95b7dSJasvinder Singh 		out_size,
4315a3a95b7dSJasvinder Singh 		&a);
4316a3a95b7dSJasvinder Singh 	if (n_tokens_parsed == 0)
4317a3a95b7dSJasvinder Singh 		return;
4318a3a95b7dSJasvinder Singh 	t0 += n_tokens_parsed;
4319a3a95b7dSJasvinder Singh 
4320a3a95b7dSJasvinder Singh 	if (t0 != n_tokens) {
4321a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
4322a3a95b7dSJasvinder Singh 		return;
4323a3a95b7dSJasvinder Singh 	}
4324a3a95b7dSJasvinder Singh 
43254c65163eSCristian Dumitrescu 	status = pipeline_table_rule_add(pipeline_name, table_id, &m, &a);
4326a3a95b7dSJasvinder Singh 	if (status) {
4327a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4328a3a95b7dSJasvinder Singh 		return;
4329a3a95b7dSJasvinder Singh 	}
43301edccebcSFan Zhang 
43311edccebcSFan Zhang 	if (a.action_mask & 1 << RTE_TABLE_ACTION_SYM_CRYPTO)
43321edccebcSFan Zhang 		parse_free_sym_crypto_param_data(&a.sym_crypto);
4333a3a95b7dSJasvinder Singh }
4334a3a95b7dSJasvinder Singh 
433526b3effeSKevin Laatz 
433626b3effeSKevin Laatz static const char cmd_pipeline_table_rule_add_default_help[] =
433726b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> rule add\n"
433826b3effeSKevin Laatz "     match\n"
433926b3effeSKevin Laatz "        default\n"
434026b3effeSKevin Laatz "     action\n"
434126b3effeSKevin Laatz "        fwd\n"
434226b3effeSKevin Laatz "           drop\n"
434326b3effeSKevin Laatz "           | port <port_id>\n"
434426b3effeSKevin Laatz "           | meta\n"
434526b3effeSKevin Laatz "           | table <table_id>\n";
434626b3effeSKevin Laatz 
4347a3a95b7dSJasvinder Singh static void
4348a3a95b7dSJasvinder Singh cmd_pipeline_table_rule_add_default(char **tokens,
4349a3a95b7dSJasvinder Singh 	uint32_t n_tokens,
4350a3a95b7dSJasvinder Singh 	char *out,
4351a3a95b7dSJasvinder Singh 	size_t out_size)
4352a3a95b7dSJasvinder Singh {
4353a3a95b7dSJasvinder Singh 	struct table_rule_action action;
4354a3a95b7dSJasvinder Singh 	char *pipeline_name;
4355a3a95b7dSJasvinder Singh 	uint32_t table_id;
4356a3a95b7dSJasvinder Singh 	int status;
4357a3a95b7dSJasvinder Singh 
4358a3a95b7dSJasvinder Singh 	if ((n_tokens != 11) && (n_tokens != 12)) {
4359a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4360a3a95b7dSJasvinder Singh 		return;
4361a3a95b7dSJasvinder Singh 	}
4362a3a95b7dSJasvinder Singh 
4363a3a95b7dSJasvinder Singh 	pipeline_name = tokens[1];
4364a3a95b7dSJasvinder Singh 
4365a3a95b7dSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
4366a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4367a3a95b7dSJasvinder Singh 		return;
4368a3a95b7dSJasvinder Singh 	}
4369a3a95b7dSJasvinder Singh 
4370a3a95b7dSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4371a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4372a3a95b7dSJasvinder Singh 		return;
4373a3a95b7dSJasvinder Singh 	}
4374a3a95b7dSJasvinder Singh 
4375a3a95b7dSJasvinder Singh 	if (strcmp(tokens[4], "rule") != 0) {
4376a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4377a3a95b7dSJasvinder Singh 		return;
4378a3a95b7dSJasvinder Singh 	}
4379a3a95b7dSJasvinder Singh 
4380a3a95b7dSJasvinder Singh 	if (strcmp(tokens[5], "add") != 0) {
4381a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
4382a3a95b7dSJasvinder Singh 		return;
4383a3a95b7dSJasvinder Singh 	}
4384a3a95b7dSJasvinder Singh 
4385a3a95b7dSJasvinder Singh 	if (strcmp(tokens[6], "match") != 0) {
4386a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "match");
4387a3a95b7dSJasvinder Singh 		return;
4388a3a95b7dSJasvinder Singh 	}
4389a3a95b7dSJasvinder Singh 
4390a3a95b7dSJasvinder Singh 	if (strcmp(tokens[7], "default") != 0) {
4391a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "default");
4392a3a95b7dSJasvinder Singh 		return;
4393a3a95b7dSJasvinder Singh 	}
4394a3a95b7dSJasvinder Singh 
4395a3a95b7dSJasvinder Singh 	if (strcmp(tokens[8], "action") != 0) {
4396a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "action");
4397a3a95b7dSJasvinder Singh 		return;
4398a3a95b7dSJasvinder Singh 	}
4399a3a95b7dSJasvinder Singh 
4400a3a95b7dSJasvinder Singh 	if (strcmp(tokens[9], "fwd") != 0) {
4401a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "fwd");
4402a3a95b7dSJasvinder Singh 		return;
4403a3a95b7dSJasvinder Singh 	}
4404a3a95b7dSJasvinder Singh 
4405a3a95b7dSJasvinder Singh 	action.action_mask = 1 << RTE_TABLE_ACTION_FWD;
4406a3a95b7dSJasvinder Singh 
4407a3a95b7dSJasvinder Singh 	if (strcmp(tokens[10], "drop") == 0) {
4408a3a95b7dSJasvinder Singh 		if (n_tokens != 11) {
4409a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4410a3a95b7dSJasvinder Singh 			return;
4411a3a95b7dSJasvinder Singh 		}
4412a3a95b7dSJasvinder Singh 
4413a3a95b7dSJasvinder Singh 		action.fwd.action = RTE_PIPELINE_ACTION_DROP;
4414a3a95b7dSJasvinder Singh 	} else if (strcmp(tokens[10], "port") == 0) {
4415a3a95b7dSJasvinder Singh 		uint32_t id;
4416a3a95b7dSJasvinder Singh 
4417a3a95b7dSJasvinder Singh 		if (n_tokens != 12) {
4418a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4419a3a95b7dSJasvinder Singh 			return;
4420a3a95b7dSJasvinder Singh 		}
4421a3a95b7dSJasvinder Singh 
4422a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&id, tokens[11]) != 0) {
4423a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "port_id");
4424a3a95b7dSJasvinder Singh 			return;
4425a3a95b7dSJasvinder Singh 		}
4426a3a95b7dSJasvinder Singh 
4427a3a95b7dSJasvinder Singh 		action.fwd.action = RTE_PIPELINE_ACTION_PORT;
4428a3a95b7dSJasvinder Singh 		action.fwd.id = id;
4429a3a95b7dSJasvinder Singh 	} else if (strcmp(tokens[10], "meta") == 0) {
4430a3a95b7dSJasvinder Singh 		if (n_tokens != 11) {
4431a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4432a3a95b7dSJasvinder Singh 			return;
4433a3a95b7dSJasvinder Singh 		}
4434a3a95b7dSJasvinder Singh 
4435a3a95b7dSJasvinder Singh 		action.fwd.action = RTE_PIPELINE_ACTION_PORT_META;
4436a3a95b7dSJasvinder Singh 	} else if (strcmp(tokens[10], "table") == 0) {
4437a3a95b7dSJasvinder Singh 		uint32_t id;
4438a3a95b7dSJasvinder Singh 
4439a3a95b7dSJasvinder Singh 		if (n_tokens != 12) {
4440a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4441a3a95b7dSJasvinder Singh 			return;
4442a3a95b7dSJasvinder Singh 		}
4443a3a95b7dSJasvinder Singh 
4444a3a95b7dSJasvinder Singh 		if (parser_read_uint32(&id, tokens[11]) != 0) {
4445a3a95b7dSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4446a3a95b7dSJasvinder Singh 			return;
4447a3a95b7dSJasvinder Singh 		}
4448a3a95b7dSJasvinder Singh 
4449a3a95b7dSJasvinder Singh 		action.fwd.action = RTE_PIPELINE_ACTION_TABLE;
4450a3a95b7dSJasvinder Singh 		action.fwd.id = id;
4451a3a95b7dSJasvinder Singh 	} else {
4452a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID,
4453a3a95b7dSJasvinder Singh 			"drop or port or meta or table");
4454a3a95b7dSJasvinder Singh 		return;
4455a3a95b7dSJasvinder Singh 	}
4456a3a95b7dSJasvinder Singh 
4457a3a95b7dSJasvinder Singh 	status = pipeline_table_rule_add_default(pipeline_name,
4458a3a95b7dSJasvinder Singh 		table_id,
4459c348ec05SCristian Dumitrescu 		&action);
4460a3a95b7dSJasvinder Singh 	if (status) {
4461a3a95b7dSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4462a3a95b7dSJasvinder Singh 		return;
4463a3a95b7dSJasvinder Singh 	}
4464a3a95b7dSJasvinder Singh }
4465a3a95b7dSJasvinder Singh 
446626b3effeSKevin Laatz 
446726b3effeSKevin Laatz static const char cmd_pipeline_table_rule_add_bulk_help[] =
446827b333b2SCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule add bulk <file_name>\n"
446926b3effeSKevin Laatz "\n"
447026b3effeSKevin Laatz "  File <file_name>:\n"
447126b3effeSKevin Laatz "  - line format: match <match> action <action>\n";
447226b3effeSKevin Laatz 
44733186282fSJasvinder Singh static int
44743186282fSJasvinder Singh cli_rule_file_process(const char *file_name,
44753186282fSJasvinder Singh 	size_t line_len_max,
447627b333b2SCristian Dumitrescu 	struct table_rule_list **rule_list,
44773186282fSJasvinder Singh 	uint32_t *n_rules,
44783186282fSJasvinder Singh 	uint32_t *line_number,
44793186282fSJasvinder Singh 	char *out,
44803186282fSJasvinder Singh 	size_t out_size);
44813186282fSJasvinder Singh 
44823186282fSJasvinder Singh static void
44833186282fSJasvinder Singh cmd_pipeline_table_rule_add_bulk(char **tokens,
44843186282fSJasvinder Singh 	uint32_t n_tokens,
44853186282fSJasvinder Singh 	char *out,
44863186282fSJasvinder Singh 	size_t out_size)
44873186282fSJasvinder Singh {
448827b333b2SCristian Dumitrescu 	struct table_rule_list *list = NULL;
44893186282fSJasvinder Singh 	char *pipeline_name, *file_name;
449027b333b2SCristian Dumitrescu 	uint32_t table_id, n_rules, n_rules_added, n_rules_not_added, line_number;
44913186282fSJasvinder Singh 	int status;
44923186282fSJasvinder Singh 
449327b333b2SCristian Dumitrescu 	if (n_tokens != 8) {
44943186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
44953186282fSJasvinder Singh 		return;
44963186282fSJasvinder Singh 	}
44973186282fSJasvinder Singh 
44983186282fSJasvinder Singh 	pipeline_name = tokens[1];
44993186282fSJasvinder Singh 
45003186282fSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
45013186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
45023186282fSJasvinder Singh 		return;
45033186282fSJasvinder Singh 	}
45043186282fSJasvinder Singh 
45053186282fSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
45063186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
45073186282fSJasvinder Singh 		return;
45083186282fSJasvinder Singh 	}
45093186282fSJasvinder Singh 
45103186282fSJasvinder Singh 	if (strcmp(tokens[4], "rule") != 0) {
45113186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
45123186282fSJasvinder Singh 		return;
45133186282fSJasvinder Singh 	}
45143186282fSJasvinder Singh 
45153186282fSJasvinder Singh 	if (strcmp(tokens[5], "add") != 0) {
45163186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
45173186282fSJasvinder Singh 		return;
45183186282fSJasvinder Singh 	}
45193186282fSJasvinder Singh 
45203186282fSJasvinder Singh 	if (strcmp(tokens[6], "bulk") != 0) {
45213186282fSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "bulk");
45223186282fSJasvinder Singh 		return;
45233186282fSJasvinder Singh 	}
45243186282fSJasvinder Singh 
45253186282fSJasvinder Singh 	file_name = tokens[7];
45263186282fSJasvinder Singh 
452727b333b2SCristian Dumitrescu 	/* Load rules from file. */
45283186282fSJasvinder Singh 	status = cli_rule_file_process(file_name,
45293186282fSJasvinder Singh 		1024,
453027b333b2SCristian Dumitrescu 		&list,
453127b333b2SCristian Dumitrescu 		&n_rules,
45323186282fSJasvinder Singh 		&line_number,
45333186282fSJasvinder Singh 		out,
45343186282fSJasvinder Singh 		out_size);
45353186282fSJasvinder Singh 	if (status) {
45363186282fSJasvinder Singh 		snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
45373186282fSJasvinder Singh 		return;
45383186282fSJasvinder Singh 	}
45393186282fSJasvinder Singh 
45403186282fSJasvinder Singh 	/* Rule bulk add */
45413186282fSJasvinder Singh 	status = pipeline_table_rule_add_bulk(pipeline_name,
45423186282fSJasvinder Singh 		table_id,
454327b333b2SCristian Dumitrescu 		list,
454427b333b2SCristian Dumitrescu 		&n_rules_added,
454527b333b2SCristian Dumitrescu 		&n_rules_not_added);
45463186282fSJasvinder Singh 	if (status) {
45473186282fSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
45483186282fSJasvinder Singh 		return;
45493186282fSJasvinder Singh 	}
45503186282fSJasvinder Singh 
455127b333b2SCristian Dumitrescu 	snprintf(out, out_size, "Added %u rules out of %u.\n",
455227b333b2SCristian Dumitrescu 		n_rules_added,
455327b333b2SCristian Dumitrescu 		n_rules);
45543186282fSJasvinder Singh }
45553186282fSJasvinder Singh 
455626b3effeSKevin Laatz 
455726b3effeSKevin Laatz static const char cmd_pipeline_table_rule_delete_help[] =
455826b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> rule delete\n"
455926b3effeSKevin Laatz "     match <match>\n";
456026b3effeSKevin Laatz 
4561f634e4c5SJasvinder Singh static void
4562f634e4c5SJasvinder Singh cmd_pipeline_table_rule_delete(char **tokens,
4563f634e4c5SJasvinder Singh 	uint32_t n_tokens,
4564f634e4c5SJasvinder Singh 	char *out,
4565f634e4c5SJasvinder Singh 	size_t out_size)
4566f634e4c5SJasvinder Singh {
4567f634e4c5SJasvinder Singh 	struct table_rule_match m;
4568f634e4c5SJasvinder Singh 	char *pipeline_name;
4569f634e4c5SJasvinder Singh 	uint32_t table_id, n_tokens_parsed, t0;
4570f634e4c5SJasvinder Singh 	int status;
4571f634e4c5SJasvinder Singh 
4572f634e4c5SJasvinder Singh 	if (n_tokens < 8) {
4573f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4574f634e4c5SJasvinder Singh 		return;
4575f634e4c5SJasvinder Singh 	}
4576f634e4c5SJasvinder Singh 
4577f634e4c5SJasvinder Singh 	pipeline_name = tokens[1];
4578f634e4c5SJasvinder Singh 
4579f634e4c5SJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
4580f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4581f634e4c5SJasvinder Singh 		return;
4582f634e4c5SJasvinder Singh 	}
4583f634e4c5SJasvinder Singh 
4584f634e4c5SJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4585f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4586f634e4c5SJasvinder Singh 		return;
4587f634e4c5SJasvinder Singh 	}
4588f634e4c5SJasvinder Singh 
4589f634e4c5SJasvinder Singh 	if (strcmp(tokens[4], "rule") != 0) {
4590f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4591f634e4c5SJasvinder Singh 		return;
4592f634e4c5SJasvinder Singh 	}
4593f634e4c5SJasvinder Singh 
4594f634e4c5SJasvinder Singh 	if (strcmp(tokens[5], "delete") != 0) {
4595f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4596f634e4c5SJasvinder Singh 		return;
4597f634e4c5SJasvinder Singh 	}
4598f634e4c5SJasvinder Singh 
4599f634e4c5SJasvinder Singh 	t0 = 6;
4600f634e4c5SJasvinder Singh 
4601f634e4c5SJasvinder Singh 	/* match */
4602f634e4c5SJasvinder Singh 	n_tokens_parsed = parse_match(tokens + t0,
4603f634e4c5SJasvinder Singh 		n_tokens - t0,
4604f634e4c5SJasvinder Singh 		out,
4605f634e4c5SJasvinder Singh 		out_size,
4606f634e4c5SJasvinder Singh 		&m);
4607f634e4c5SJasvinder Singh 	if (n_tokens_parsed == 0)
4608f634e4c5SJasvinder Singh 		return;
4609f634e4c5SJasvinder Singh 	t0 += n_tokens_parsed;
4610f634e4c5SJasvinder Singh 
4611f634e4c5SJasvinder Singh 	if (n_tokens != t0) {
4612f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4613f634e4c5SJasvinder Singh 		return;
4614f634e4c5SJasvinder Singh 	}
4615f634e4c5SJasvinder Singh 
4616f634e4c5SJasvinder Singh 	status = pipeline_table_rule_delete(pipeline_name,
4617f634e4c5SJasvinder Singh 		table_id,
4618f634e4c5SJasvinder Singh 		&m);
4619f634e4c5SJasvinder Singh 	if (status) {
4620f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4621f634e4c5SJasvinder Singh 		return;
4622f634e4c5SJasvinder Singh 	}
4623f634e4c5SJasvinder Singh }
4624f634e4c5SJasvinder Singh 
462526b3effeSKevin Laatz 
462626b3effeSKevin Laatz static const char cmd_pipeline_table_rule_delete_default_help[] =
462726b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> rule delete\n"
462826b3effeSKevin Laatz "     match\n"
462926b3effeSKevin Laatz "        default\n";
463026b3effeSKevin Laatz 
4631f634e4c5SJasvinder Singh static void
4632f634e4c5SJasvinder Singh cmd_pipeline_table_rule_delete_default(char **tokens,
4633f634e4c5SJasvinder Singh 	uint32_t n_tokens,
4634f634e4c5SJasvinder Singh 	char *out,
4635f634e4c5SJasvinder Singh 	size_t out_size)
4636f634e4c5SJasvinder Singh {
4637f634e4c5SJasvinder Singh 	char *pipeline_name;
4638f634e4c5SJasvinder Singh 	uint32_t table_id;
4639f634e4c5SJasvinder Singh 	int status;
4640f634e4c5SJasvinder Singh 
4641f634e4c5SJasvinder Singh 	if (n_tokens != 8) {
4642f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
4643f634e4c5SJasvinder Singh 		return;
4644f634e4c5SJasvinder Singh 	}
4645f634e4c5SJasvinder Singh 
4646f634e4c5SJasvinder Singh 	pipeline_name = tokens[1];
4647f634e4c5SJasvinder Singh 
4648f634e4c5SJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
4649f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
4650f634e4c5SJasvinder Singh 		return;
4651f634e4c5SJasvinder Singh 	}
4652f634e4c5SJasvinder Singh 
4653f634e4c5SJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
4654f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
4655f634e4c5SJasvinder Singh 		return;
4656f634e4c5SJasvinder Singh 	}
4657f634e4c5SJasvinder Singh 
4658f634e4c5SJasvinder Singh 	if (strcmp(tokens[4], "rule") != 0) {
4659f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
4660f634e4c5SJasvinder Singh 		return;
4661f634e4c5SJasvinder Singh 	}
4662f634e4c5SJasvinder Singh 
4663f634e4c5SJasvinder Singh 	if (strcmp(tokens[5], "delete") != 0) {
4664f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
4665f634e4c5SJasvinder Singh 		return;
4666f634e4c5SJasvinder Singh 	}
4667f634e4c5SJasvinder Singh 
4668f634e4c5SJasvinder Singh 	if (strcmp(tokens[6], "match") != 0) {
4669f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "match");
4670f634e4c5SJasvinder Singh 		return;
4671f634e4c5SJasvinder Singh 	}
4672f634e4c5SJasvinder Singh 
4673f634e4c5SJasvinder Singh 	if (strcmp(tokens[7], "default") != 0) {
4674f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "default");
4675f634e4c5SJasvinder Singh 		return;
4676f634e4c5SJasvinder Singh 	}
4677f634e4c5SJasvinder Singh 
4678f634e4c5SJasvinder Singh 	status = pipeline_table_rule_delete_default(pipeline_name,
4679f634e4c5SJasvinder Singh 		table_id);
4680f634e4c5SJasvinder Singh 	if (status) {
4681f634e4c5SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
4682f634e4c5SJasvinder Singh 		return;
4683f634e4c5SJasvinder Singh 	}
4684f634e4c5SJasvinder Singh }
4685f634e4c5SJasvinder Singh 
46862fbdf834SCristian Dumitrescu static void
46876d13ea8eSOlivier Matz ether_addr_show(FILE *f, struct rte_ether_addr *addr)
46882fbdf834SCristian Dumitrescu {
4689a7db3afcSAman Deep Singh 	fprintf(f, RTE_ETHER_ADDR_PRT_FMT, RTE_ETHER_ADDR_BYTES(addr));
46902fbdf834SCristian Dumitrescu }
46912fbdf834SCristian Dumitrescu 
46922fbdf834SCristian Dumitrescu static void
46932fbdf834SCristian Dumitrescu ipv4_addr_show(FILE *f, uint32_t addr)
46942fbdf834SCristian Dumitrescu {
46952fbdf834SCristian Dumitrescu 	fprintf(f, "%u.%u.%u.%u",
46962fbdf834SCristian Dumitrescu 		addr >> 24,
46972fbdf834SCristian Dumitrescu 		(addr >> 16) & 0xFF,
46982fbdf834SCristian Dumitrescu 		(addr >> 8) & 0xFF,
46992fbdf834SCristian Dumitrescu 		addr & 0xFF);
47002fbdf834SCristian Dumitrescu }
47012fbdf834SCristian Dumitrescu 
47022fbdf834SCristian Dumitrescu static void
47035ac1abddSRobin Jarry ipv6_addr_show(FILE *f, const struct rte_ipv6_addr *ip)
47042fbdf834SCristian Dumitrescu {
47055ac1abddSRobin Jarry 	fprintf(f, RTE_IPV6_ADDR_FMT ":", RTE_IPV6_ADDR_SPLIT(ip));
47062fbdf834SCristian Dumitrescu }
47072fbdf834SCristian Dumitrescu 
47082fbdf834SCristian Dumitrescu static const char *
47092fbdf834SCristian Dumitrescu policer_action_string(enum rte_table_action_policer action) {
47102fbdf834SCristian Dumitrescu 	switch (action) {
47112fbdf834SCristian Dumitrescu 		case RTE_TABLE_ACTION_POLICER_COLOR_GREEN: return "G";
47122fbdf834SCristian Dumitrescu 		case RTE_TABLE_ACTION_POLICER_COLOR_YELLOW: return "Y";
47132fbdf834SCristian Dumitrescu 		case RTE_TABLE_ACTION_POLICER_COLOR_RED: return "R";
47142fbdf834SCristian Dumitrescu 		case RTE_TABLE_ACTION_POLICER_DROP: return "D";
47152fbdf834SCristian Dumitrescu 		default: return "?";
47162fbdf834SCristian Dumitrescu 	}
47172fbdf834SCristian Dumitrescu }
47182fbdf834SCristian Dumitrescu 
47192fbdf834SCristian Dumitrescu static int
47202fbdf834SCristian Dumitrescu table_rule_show(const char *pipeline_name,
47212fbdf834SCristian Dumitrescu 	uint32_t table_id,
47222fbdf834SCristian Dumitrescu 	const char *file_name)
47232fbdf834SCristian Dumitrescu {
47242fbdf834SCristian Dumitrescu 	struct pipeline *p;
47252fbdf834SCristian Dumitrescu 	struct table *table;
47262fbdf834SCristian Dumitrescu 	struct table_rule *rule;
47272fbdf834SCristian Dumitrescu 	FILE *f = NULL;
47282fbdf834SCristian Dumitrescu 	uint32_t i;
47292fbdf834SCristian Dumitrescu 
47302fbdf834SCristian Dumitrescu 	/* Check input params. */
47312fbdf834SCristian Dumitrescu 	if ((pipeline_name == NULL) ||
47322fbdf834SCristian Dumitrescu 		(file_name == NULL))
47332fbdf834SCristian Dumitrescu 		return -1;
47342fbdf834SCristian Dumitrescu 
47352fbdf834SCristian Dumitrescu 	p = pipeline_find(pipeline_name);
47362fbdf834SCristian Dumitrescu 	if ((p == NULL) ||
47372fbdf834SCristian Dumitrescu 		(table_id >= p->n_tables))
47382fbdf834SCristian Dumitrescu 		return -1;
47392fbdf834SCristian Dumitrescu 
47402fbdf834SCristian Dumitrescu 	table = &p->table[table_id];
47412fbdf834SCristian Dumitrescu 
47422fbdf834SCristian Dumitrescu 	/* Open file. */
47432fbdf834SCristian Dumitrescu 	f = fopen(file_name, "w");
47442fbdf834SCristian Dumitrescu 	if (f == NULL)
47452fbdf834SCristian Dumitrescu 		return -1;
47462fbdf834SCristian Dumitrescu 
47472fbdf834SCristian Dumitrescu 	/* Write table rules to file. */
47482fbdf834SCristian Dumitrescu 	TAILQ_FOREACH(rule, &table->rules, node) {
47492fbdf834SCristian Dumitrescu 		struct table_rule_match *m = &rule->match;
47502fbdf834SCristian Dumitrescu 		struct table_rule_action *a = &rule->action;
47512fbdf834SCristian Dumitrescu 
47522fbdf834SCristian Dumitrescu 		fprintf(f, "match ");
47532fbdf834SCristian Dumitrescu 		switch (m->match_type) {
47542fbdf834SCristian Dumitrescu 		case TABLE_ACL:
47552fbdf834SCristian Dumitrescu 			fprintf(f, "acl priority %u ",
47562fbdf834SCristian Dumitrescu 				m->match.acl.priority);
47572fbdf834SCristian Dumitrescu 
47582fbdf834SCristian Dumitrescu 			fprintf(f, m->match.acl.ip_version ? "ipv4 " : "ipv6 ");
47592fbdf834SCristian Dumitrescu 
47602fbdf834SCristian Dumitrescu 			if (m->match.acl.ip_version)
47612fbdf834SCristian Dumitrescu 				ipv4_addr_show(f, m->match.acl.ipv4.sa);
47622fbdf834SCristian Dumitrescu 			else
47635ac1abddSRobin Jarry 				ipv6_addr_show(f, &m->match.acl.ipv6.sa);
47642fbdf834SCristian Dumitrescu 
47652fbdf834SCristian Dumitrescu 			fprintf(f, "%u",	m->match.acl.sa_depth);
47662fbdf834SCristian Dumitrescu 
47672fbdf834SCristian Dumitrescu 			if (m->match.acl.ip_version)
47682fbdf834SCristian Dumitrescu 				ipv4_addr_show(f, m->match.acl.ipv4.da);
47692fbdf834SCristian Dumitrescu 			else
47705ac1abddSRobin Jarry 				ipv6_addr_show(f, &m->match.acl.ipv6.da);
47712fbdf834SCristian Dumitrescu 
47722fbdf834SCristian Dumitrescu 			fprintf(f, "%u",	m->match.acl.da_depth);
47732fbdf834SCristian Dumitrescu 
47742fbdf834SCristian Dumitrescu 			fprintf(f, "%u %u %u %u %u ",
47752fbdf834SCristian Dumitrescu 				(uint32_t)m->match.acl.sp0,
47762fbdf834SCristian Dumitrescu 				(uint32_t)m->match.acl.sp1,
47772fbdf834SCristian Dumitrescu 				(uint32_t)m->match.acl.dp0,
47782fbdf834SCristian Dumitrescu 				(uint32_t)m->match.acl.dp1,
47792fbdf834SCristian Dumitrescu 				(uint32_t)m->match.acl.proto);
47802fbdf834SCristian Dumitrescu 			break;
47812fbdf834SCristian Dumitrescu 
47822fbdf834SCristian Dumitrescu 		case TABLE_ARRAY:
47832fbdf834SCristian Dumitrescu 			fprintf(f, "array %u ",
47842fbdf834SCristian Dumitrescu 				m->match.array.pos);
47852fbdf834SCristian Dumitrescu 			break;
47862fbdf834SCristian Dumitrescu 
47872fbdf834SCristian Dumitrescu 		case TABLE_HASH:
47882fbdf834SCristian Dumitrescu 			fprintf(f, "hash raw ");
47892fbdf834SCristian Dumitrescu 			for (i = 0; i < table->params.match.hash.key_size; i++)
47902fbdf834SCristian Dumitrescu 				fprintf(f, "%02x", m->match.hash.key[i]);
47912fbdf834SCristian Dumitrescu 			fprintf(f, " ");
47922fbdf834SCristian Dumitrescu 			break;
47932fbdf834SCristian Dumitrescu 
47942fbdf834SCristian Dumitrescu 		case TABLE_LPM:
47952fbdf834SCristian Dumitrescu 			fprintf(f, "lpm ");
47962fbdf834SCristian Dumitrescu 
47972fbdf834SCristian Dumitrescu 			fprintf(f, m->match.lpm.ip_version ? "ipv4 " : "ipv6 ");
47982fbdf834SCristian Dumitrescu 
47992fbdf834SCristian Dumitrescu 			if (m->match.acl.ip_version)
48002fbdf834SCristian Dumitrescu 				ipv4_addr_show(f, m->match.lpm.ipv4);
48012fbdf834SCristian Dumitrescu 			else
48025ac1abddSRobin Jarry 				ipv6_addr_show(f, &m->match.lpm.ipv6);
48032fbdf834SCristian Dumitrescu 
48042fbdf834SCristian Dumitrescu 			fprintf(f, "%u ",
48052fbdf834SCristian Dumitrescu 				(uint32_t)m->match.lpm.depth);
48062fbdf834SCristian Dumitrescu 			break;
48072fbdf834SCristian Dumitrescu 
48082fbdf834SCristian Dumitrescu 		default:
48092fbdf834SCristian Dumitrescu 			fprintf(f, "unknown ");
48102fbdf834SCristian Dumitrescu 		}
48112fbdf834SCristian Dumitrescu 
48122fbdf834SCristian Dumitrescu 		fprintf(f, "action ");
48132fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
48142fbdf834SCristian Dumitrescu 			fprintf(f, "fwd ");
48152fbdf834SCristian Dumitrescu 			switch (a->fwd.action) {
48162fbdf834SCristian Dumitrescu 			case RTE_PIPELINE_ACTION_DROP:
48172fbdf834SCristian Dumitrescu 				fprintf(f, "drop ");
48182fbdf834SCristian Dumitrescu 				break;
48192fbdf834SCristian Dumitrescu 
48202fbdf834SCristian Dumitrescu 			case RTE_PIPELINE_ACTION_PORT:
48212fbdf834SCristian Dumitrescu 				fprintf(f, "port %u ", a->fwd.id);
48222fbdf834SCristian Dumitrescu 				break;
48232fbdf834SCristian Dumitrescu 
48242fbdf834SCristian Dumitrescu 			case RTE_PIPELINE_ACTION_PORT_META:
48252fbdf834SCristian Dumitrescu 				fprintf(f, "meta ");
48262fbdf834SCristian Dumitrescu 				break;
48272fbdf834SCristian Dumitrescu 
48282fbdf834SCristian Dumitrescu 			case RTE_PIPELINE_ACTION_TABLE:
48292fbdf834SCristian Dumitrescu 			default:
48302fbdf834SCristian Dumitrescu 				fprintf(f, "table %u ", a->fwd.id);
48312fbdf834SCristian Dumitrescu 			}
48322fbdf834SCristian Dumitrescu 		}
48332fbdf834SCristian Dumitrescu 
48342fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
48352fbdf834SCristian Dumitrescu 			fprintf(f, "balance ");
48362fbdf834SCristian Dumitrescu 			for (i = 0; i < RTE_DIM(a->lb.out); i++)
48372fbdf834SCristian Dumitrescu 				fprintf(f, "%u ", a->lb.out[i]);
48382fbdf834SCristian Dumitrescu 		}
48392fbdf834SCristian Dumitrescu 
48402fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
48412fbdf834SCristian Dumitrescu 			fprintf(f, "mtr ");
48422fbdf834SCristian Dumitrescu 			for (i = 0; i < RTE_TABLE_ACTION_TC_MAX; i++)
48432fbdf834SCristian Dumitrescu 				if (a->mtr.tc_mask & (1 << i)) {
48442fbdf834SCristian Dumitrescu 					struct rte_table_action_mtr_tc_params *p =
48452fbdf834SCristian Dumitrescu 						&a->mtr.mtr[i];
48462fbdf834SCristian Dumitrescu 					enum rte_table_action_policer ga =
4847c1656328SJasvinder Singh 						p->policer[RTE_COLOR_GREEN];
48482fbdf834SCristian Dumitrescu 					enum rte_table_action_policer ya =
4849c1656328SJasvinder Singh 						p->policer[RTE_COLOR_YELLOW];
48502fbdf834SCristian Dumitrescu 					enum rte_table_action_policer ra =
4851c1656328SJasvinder Singh 						p->policer[RTE_COLOR_RED];
48522fbdf834SCristian Dumitrescu 
48532fbdf834SCristian Dumitrescu 					fprintf(f, "tc%u meter %u policer g %s y %s r %s ",
48542fbdf834SCristian Dumitrescu 						i,
48552fbdf834SCristian Dumitrescu 						a->mtr.mtr[i].meter_profile_id,
48562fbdf834SCristian Dumitrescu 						policer_action_string(ga),
48572fbdf834SCristian Dumitrescu 						policer_action_string(ya),
48582fbdf834SCristian Dumitrescu 						policer_action_string(ra));
48592fbdf834SCristian Dumitrescu 				}
48602fbdf834SCristian Dumitrescu 		}
48612fbdf834SCristian Dumitrescu 
48622fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TM))
48632fbdf834SCristian Dumitrescu 			fprintf(f, "tm subport %u pipe %u ",
48642fbdf834SCristian Dumitrescu 				a->tm.subport_id,
48652fbdf834SCristian Dumitrescu 				a->tm.pipe_id);
48662fbdf834SCristian Dumitrescu 
48672fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
48682fbdf834SCristian Dumitrescu 			fprintf(f, "encap ");
48692fbdf834SCristian Dumitrescu 			switch (a->encap.type) {
48702fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_ETHER:
48712fbdf834SCristian Dumitrescu 				fprintf(f, "ether ");
48722fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.ether.ether.da);
48732fbdf834SCristian Dumitrescu 				fprintf(f, " ");
48742fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.ether.ether.sa);
48752fbdf834SCristian Dumitrescu 				fprintf(f, " ");
48762fbdf834SCristian Dumitrescu 				break;
48772fbdf834SCristian Dumitrescu 
48782fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_VLAN:
48792fbdf834SCristian Dumitrescu 				fprintf(f, "vlan ");
48802fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.vlan.ether.da);
48812fbdf834SCristian Dumitrescu 				fprintf(f, " ");
48822fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.vlan.ether.sa);
48832fbdf834SCristian Dumitrescu 				fprintf(f, " pcp %u dei %u vid %u ",
48842fbdf834SCristian Dumitrescu 					a->encap.vlan.vlan.pcp,
48852fbdf834SCristian Dumitrescu 					a->encap.vlan.vlan.dei,
48862fbdf834SCristian Dumitrescu 					a->encap.vlan.vlan.vid);
48872fbdf834SCristian Dumitrescu 				break;
48882fbdf834SCristian Dumitrescu 
48892fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_QINQ:
48902fbdf834SCristian Dumitrescu 				fprintf(f, "qinq ");
48912fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.qinq.ether.da);
48922fbdf834SCristian Dumitrescu 				fprintf(f, " ");
48932fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.qinq.ether.sa);
48942fbdf834SCristian Dumitrescu 				fprintf(f, " pcp %u dei %u vid %u pcp %u dei %u vid %u ",
48952fbdf834SCristian Dumitrescu 					a->encap.qinq.svlan.pcp,
48962fbdf834SCristian Dumitrescu 					a->encap.qinq.svlan.dei,
48972fbdf834SCristian Dumitrescu 					a->encap.qinq.svlan.vid,
48982fbdf834SCristian Dumitrescu 					a->encap.qinq.cvlan.pcp,
48992fbdf834SCristian Dumitrescu 					a->encap.qinq.cvlan.dei,
49002fbdf834SCristian Dumitrescu 					a->encap.qinq.cvlan.vid);
49012fbdf834SCristian Dumitrescu 				break;
49022fbdf834SCristian Dumitrescu 
49032fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_MPLS:
49042fbdf834SCristian Dumitrescu 				fprintf(f, "mpls %s ", (a->encap.mpls.unicast) ?
49052fbdf834SCristian Dumitrescu 					"unicast " : "multicast ");
49062fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.mpls.ether.da);
49072fbdf834SCristian Dumitrescu 				fprintf(f, " ");
49082fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.mpls.ether.sa);
49092fbdf834SCristian Dumitrescu 				fprintf(f, " ");
49102fbdf834SCristian Dumitrescu 				for (i = 0; i < a->encap.mpls.mpls_count; i++) {
49112fbdf834SCristian Dumitrescu 					struct rte_table_action_mpls_hdr *l =
49122fbdf834SCristian Dumitrescu 						&a->encap.mpls.mpls[i];
49132fbdf834SCristian Dumitrescu 
49142fbdf834SCristian Dumitrescu 					fprintf(f, "label%u %u %u %u ",
49152fbdf834SCristian Dumitrescu 						i,
49162fbdf834SCristian Dumitrescu 						l->label,
49172fbdf834SCristian Dumitrescu 						l->tc,
49182fbdf834SCristian Dumitrescu 						l->ttl);
49192fbdf834SCristian Dumitrescu 				}
49202fbdf834SCristian Dumitrescu 				break;
49212fbdf834SCristian Dumitrescu 
49222fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_PPPOE:
49232fbdf834SCristian Dumitrescu 				fprintf(f, "pppoe ");
49242fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.pppoe.ether.da);
49252fbdf834SCristian Dumitrescu 				fprintf(f, " ");
49262fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.pppoe.ether.sa);
49272fbdf834SCristian Dumitrescu 				fprintf(f, " %u ", a->encap.pppoe.pppoe.session_id);
49282fbdf834SCristian Dumitrescu 				break;
49292fbdf834SCristian Dumitrescu 
49302fbdf834SCristian Dumitrescu 			case RTE_TABLE_ACTION_ENCAP_VXLAN:
49312fbdf834SCristian Dumitrescu 				fprintf(f, "vxlan ether ");
49322fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.vxlan.ether.da);
49332fbdf834SCristian Dumitrescu 				fprintf(f, " ");
49342fbdf834SCristian Dumitrescu 				ether_addr_show(f, &a->encap.vxlan.ether.sa);
49352fbdf834SCristian Dumitrescu 				if (table->ap->params.encap.vxlan.vlan)
49362fbdf834SCristian Dumitrescu 					fprintf(f, " vlan pcp %u dei %u vid %u ",
49372fbdf834SCristian Dumitrescu 						a->encap.vxlan.vlan.pcp,
49382fbdf834SCristian Dumitrescu 						a->encap.vxlan.vlan.dei,
49392fbdf834SCristian Dumitrescu 						a->encap.vxlan.vlan.vid);
49402fbdf834SCristian Dumitrescu 				if (table->ap->params.encap.vxlan.ip_version) {
49412fbdf834SCristian Dumitrescu 					fprintf(f, " ipv4 ");
49422fbdf834SCristian Dumitrescu 					ipv4_addr_show(f, a->encap.vxlan.ipv4.sa);
49432fbdf834SCristian Dumitrescu 					fprintf(f, " ");
49442fbdf834SCristian Dumitrescu 					ipv4_addr_show(f, a->encap.vxlan.ipv4.da);
49452fbdf834SCristian Dumitrescu 					fprintf(f, " %u %u ",
49462fbdf834SCristian Dumitrescu 						(uint32_t)a->encap.vxlan.ipv4.dscp,
49472fbdf834SCristian Dumitrescu 						(uint32_t)a->encap.vxlan.ipv4.ttl);
49482fbdf834SCristian Dumitrescu 				} else {
49492fbdf834SCristian Dumitrescu 					fprintf(f, " ipv6 ");
49505ac1abddSRobin Jarry 					ipv6_addr_show(f, &a->encap.vxlan.ipv6.sa);
49512fbdf834SCristian Dumitrescu 					fprintf(f, " ");
49525ac1abddSRobin Jarry 					ipv6_addr_show(f, &a->encap.vxlan.ipv6.da);
49532fbdf834SCristian Dumitrescu 					fprintf(f, " %u %u %u ",
49542fbdf834SCristian Dumitrescu 						a->encap.vxlan.ipv6.flow_label,
49552fbdf834SCristian Dumitrescu 						(uint32_t)a->encap.vxlan.ipv6.dscp,
49562fbdf834SCristian Dumitrescu 						(uint32_t)a->encap.vxlan.ipv6.hop_limit);
49572fbdf834SCristian Dumitrescu 					fprintf(f, " udp %u %u vxlan %u ",
49582fbdf834SCristian Dumitrescu 						a->encap.vxlan.udp.sp,
49592fbdf834SCristian Dumitrescu 						a->encap.vxlan.udp.dp,
49602fbdf834SCristian Dumitrescu 						a->encap.vxlan.vxlan.vni);
49612fbdf834SCristian Dumitrescu 				}
49622fbdf834SCristian Dumitrescu 				break;
49632fbdf834SCristian Dumitrescu 
49642fbdf834SCristian Dumitrescu 			default:
49652fbdf834SCristian Dumitrescu 				fprintf(f, "unknown ");
49662fbdf834SCristian Dumitrescu 			}
49672fbdf834SCristian Dumitrescu 		}
49682fbdf834SCristian Dumitrescu 
49692fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
49702fbdf834SCristian Dumitrescu 			fprintf(f, "nat %s ", (a->nat.ip_version) ? "ipv4 " : "ipv6 ");
49712fbdf834SCristian Dumitrescu 			if (a->nat.ip_version)
49722fbdf834SCristian Dumitrescu 				ipv4_addr_show(f, a->nat.addr.ipv4);
49732fbdf834SCristian Dumitrescu 			else
49745ac1abddSRobin Jarry 				ipv6_addr_show(f, &a->nat.addr.ipv6);
49752fbdf834SCristian Dumitrescu 			fprintf(f, " %u ", (uint32_t)(a->nat.port));
49762fbdf834SCristian Dumitrescu 		}
49772fbdf834SCristian Dumitrescu 
49782fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TTL))
49792fbdf834SCristian Dumitrescu 			fprintf(f, "ttl %s ", (a->ttl.decrement) ? "dec" : "keep");
49802fbdf834SCristian Dumitrescu 
49812fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_STATS))
49822fbdf834SCristian Dumitrescu 			fprintf(f, "stats ");
49832fbdf834SCristian Dumitrescu 
49842fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TIME))
49852fbdf834SCristian Dumitrescu 			fprintf(f, "time ");
49862fbdf834SCristian Dumitrescu 
49872fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_SYM_CRYPTO))
49882fbdf834SCristian Dumitrescu 			fprintf(f, "sym_crypto ");
49892fbdf834SCristian Dumitrescu 
49902fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_TAG))
49912fbdf834SCristian Dumitrescu 			fprintf(f, "tag %u ", a->tag.tag);
49922fbdf834SCristian Dumitrescu 
49932fbdf834SCristian Dumitrescu 		if (a->action_mask & (1LLU << RTE_TABLE_ACTION_DECAP))
49942fbdf834SCristian Dumitrescu 			fprintf(f, "decap %u ", a->decap.n);
49952fbdf834SCristian Dumitrescu 
49962fbdf834SCristian Dumitrescu 		/* end */
49972fbdf834SCristian Dumitrescu 		fprintf(f, "\n");
49982fbdf834SCristian Dumitrescu 	}
49992fbdf834SCristian Dumitrescu 
50002fbdf834SCristian Dumitrescu 	/* Write table default rule to file. */
50012fbdf834SCristian Dumitrescu 	if (table->rule_default) {
50022fbdf834SCristian Dumitrescu 		struct table_rule_action *a = &table->rule_default->action;
50032fbdf834SCristian Dumitrescu 
50042fbdf834SCristian Dumitrescu 		fprintf(f, "# match default action fwd ");
50052fbdf834SCristian Dumitrescu 
50062fbdf834SCristian Dumitrescu 		switch (a->fwd.action) {
50072fbdf834SCristian Dumitrescu 		case RTE_PIPELINE_ACTION_DROP:
50082fbdf834SCristian Dumitrescu 			fprintf(f, "drop ");
50092fbdf834SCristian Dumitrescu 			break;
50102fbdf834SCristian Dumitrescu 
50112fbdf834SCristian Dumitrescu 		case RTE_PIPELINE_ACTION_PORT:
50122fbdf834SCristian Dumitrescu 			fprintf(f, "port %u ", a->fwd.id);
50132fbdf834SCristian Dumitrescu 			break;
50142fbdf834SCristian Dumitrescu 
50152fbdf834SCristian Dumitrescu 		case RTE_PIPELINE_ACTION_PORT_META:
50162fbdf834SCristian Dumitrescu 			fprintf(f, "meta ");
50172fbdf834SCristian Dumitrescu 			break;
50182fbdf834SCristian Dumitrescu 
50192fbdf834SCristian Dumitrescu 		case RTE_PIPELINE_ACTION_TABLE:
50202fbdf834SCristian Dumitrescu 		default:
50212fbdf834SCristian Dumitrescu 			fprintf(f, "table %u ", a->fwd.id);
50222fbdf834SCristian Dumitrescu 		}
50232fbdf834SCristian Dumitrescu 	} else
50242fbdf834SCristian Dumitrescu 		fprintf(f, "# match default action fwd drop ");
50252fbdf834SCristian Dumitrescu 
50262fbdf834SCristian Dumitrescu 	fprintf(f, "\n");
50272fbdf834SCristian Dumitrescu 
50282fbdf834SCristian Dumitrescu 	/* Close file. */
50292fbdf834SCristian Dumitrescu 	fclose(f);
50302fbdf834SCristian Dumitrescu 
50312fbdf834SCristian Dumitrescu 	return 0;
50322fbdf834SCristian Dumitrescu }
50332fbdf834SCristian Dumitrescu 
50342fbdf834SCristian Dumitrescu static const char cmd_pipeline_table_rule_show_help[] =
50352fbdf834SCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule show\n"
50362fbdf834SCristian Dumitrescu "     file <file_name>\n";
50372fbdf834SCristian Dumitrescu 
50382fbdf834SCristian Dumitrescu static void
50392fbdf834SCristian Dumitrescu cmd_pipeline_table_rule_show(char **tokens,
50402fbdf834SCristian Dumitrescu 	uint32_t n_tokens,
50412fbdf834SCristian Dumitrescu 	char *out,
50422fbdf834SCristian Dumitrescu 	size_t out_size)
50432fbdf834SCristian Dumitrescu {
50442fbdf834SCristian Dumitrescu 	char *file_name = NULL, *pipeline_name;
50452fbdf834SCristian Dumitrescu 	uint32_t table_id;
50462fbdf834SCristian Dumitrescu 	int status;
50472fbdf834SCristian Dumitrescu 
50482fbdf834SCristian Dumitrescu 	if (n_tokens != 8) {
50492fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
50502fbdf834SCristian Dumitrescu 		return;
50512fbdf834SCristian Dumitrescu 	}
50522fbdf834SCristian Dumitrescu 
50532fbdf834SCristian Dumitrescu 	pipeline_name = tokens[1];
50542fbdf834SCristian Dumitrescu 
50552fbdf834SCristian Dumitrescu 	if (strcmp(tokens[2], "table") != 0) {
50562fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
50572fbdf834SCristian Dumitrescu 		return;
50582fbdf834SCristian Dumitrescu 	}
50592fbdf834SCristian Dumitrescu 
50602fbdf834SCristian Dumitrescu 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
50612fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
50622fbdf834SCristian Dumitrescu 		return;
50632fbdf834SCristian Dumitrescu 	}
50642fbdf834SCristian Dumitrescu 
50652fbdf834SCristian Dumitrescu 	if (strcmp(tokens[4], "rule") != 0) {
50662fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
50672fbdf834SCristian Dumitrescu 		return;
50682fbdf834SCristian Dumitrescu 	}
50692fbdf834SCristian Dumitrescu 
50702fbdf834SCristian Dumitrescu 	if (strcmp(tokens[5], "show") != 0) {
50712fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "show");
50722fbdf834SCristian Dumitrescu 		return;
50732fbdf834SCristian Dumitrescu 	}
50742fbdf834SCristian Dumitrescu 
50752fbdf834SCristian Dumitrescu 	if (strcmp(tokens[6], "file") != 0) {
50762fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "file");
50772fbdf834SCristian Dumitrescu 		return;
50782fbdf834SCristian Dumitrescu 	}
50792fbdf834SCristian Dumitrescu 
50802fbdf834SCristian Dumitrescu 	file_name = tokens[7];
50812fbdf834SCristian Dumitrescu 
50822fbdf834SCristian Dumitrescu 	status = table_rule_show(pipeline_name, table_id, file_name);
50832fbdf834SCristian Dumitrescu 	if (status) {
50842fbdf834SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
50852fbdf834SCristian Dumitrescu 		return;
50862fbdf834SCristian Dumitrescu 	}
50872fbdf834SCristian Dumitrescu }
508826b3effeSKevin Laatz 
508926b3effeSKevin Laatz static const char cmd_pipeline_table_rule_stats_read_help[] =
509087b36dcdSCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule read stats [clear]\n"
509187b36dcdSCristian Dumitrescu "     match <match>\n";
509226b3effeSKevin Laatz 
5093c64b9121SJasvinder Singh static void
5094c64b9121SJasvinder Singh cmd_pipeline_table_rule_stats_read(char **tokens,
509587b36dcdSCristian Dumitrescu 	uint32_t n_tokens,
5096c64b9121SJasvinder Singh 	char *out,
5097c64b9121SJasvinder Singh 	size_t out_size)
5098c64b9121SJasvinder Singh {
509987b36dcdSCristian Dumitrescu 	struct table_rule_match m;
510087b36dcdSCristian Dumitrescu 	struct rte_table_action_stats_counters stats;
510187b36dcdSCristian Dumitrescu 	char *pipeline_name;
510287b36dcdSCristian Dumitrescu 	uint32_t table_id, n_tokens_parsed;
510387b36dcdSCristian Dumitrescu 	int clear = 0, status;
510487b36dcdSCristian Dumitrescu 
510587b36dcdSCristian Dumitrescu 	if (n_tokens < 7) {
510687b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
510787b36dcdSCristian Dumitrescu 		return;
5108c64b9121SJasvinder Singh 	}
5109c64b9121SJasvinder Singh 
511087b36dcdSCristian Dumitrescu 	pipeline_name = tokens[1];
511187b36dcdSCristian Dumitrescu 
511287b36dcdSCristian Dumitrescu 	if (strcmp(tokens[2], "table") != 0) {
511387b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
511487b36dcdSCristian Dumitrescu 		return;
511587b36dcdSCristian Dumitrescu 	}
511687b36dcdSCristian Dumitrescu 
511787b36dcdSCristian Dumitrescu 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
511887b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
511987b36dcdSCristian Dumitrescu 		return;
512087b36dcdSCristian Dumitrescu 	}
512187b36dcdSCristian Dumitrescu 
512287b36dcdSCristian Dumitrescu 	if (strcmp(tokens[4], "rule") != 0) {
512387b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
512487b36dcdSCristian Dumitrescu 		return;
512587b36dcdSCristian Dumitrescu 	}
512687b36dcdSCristian Dumitrescu 
512787b36dcdSCristian Dumitrescu 	if (strcmp(tokens[5], "read") != 0) {
512887b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
512987b36dcdSCristian Dumitrescu 		return;
513087b36dcdSCristian Dumitrescu 	}
513187b36dcdSCristian Dumitrescu 
513287b36dcdSCristian Dumitrescu 	if (strcmp(tokens[6], "stats") != 0) {
513387b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "stats");
513487b36dcdSCristian Dumitrescu 		return;
513587b36dcdSCristian Dumitrescu 	}
513687b36dcdSCristian Dumitrescu 
513787b36dcdSCristian Dumitrescu 	n_tokens -= 7;
513887b36dcdSCristian Dumitrescu 	tokens += 7;
513987b36dcdSCristian Dumitrescu 
514087b36dcdSCristian Dumitrescu 	/* clear */
514187b36dcdSCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
514287b36dcdSCristian Dumitrescu 		clear = 1;
514387b36dcdSCristian Dumitrescu 
514487b36dcdSCristian Dumitrescu 		n_tokens--;
514587b36dcdSCristian Dumitrescu 		tokens++;
514687b36dcdSCristian Dumitrescu 	}
514787b36dcdSCristian Dumitrescu 
514887b36dcdSCristian Dumitrescu 	/* match */
514987b36dcdSCristian Dumitrescu 	if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
515087b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
515187b36dcdSCristian Dumitrescu 		return;
515287b36dcdSCristian Dumitrescu 	}
515387b36dcdSCristian Dumitrescu 
515487b36dcdSCristian Dumitrescu 	n_tokens_parsed = parse_match(tokens,
515587b36dcdSCristian Dumitrescu 		n_tokens,
515687b36dcdSCristian Dumitrescu 		out,
515787b36dcdSCristian Dumitrescu 		out_size,
515887b36dcdSCristian Dumitrescu 		&m);
515987b36dcdSCristian Dumitrescu 	if (n_tokens_parsed == 0)
516087b36dcdSCristian Dumitrescu 		return;
516187b36dcdSCristian Dumitrescu 	n_tokens -= n_tokens_parsed;
516287b36dcdSCristian Dumitrescu 	tokens += n_tokens_parsed;
516387b36dcdSCristian Dumitrescu 
516487b36dcdSCristian Dumitrescu 	/* end */
516587b36dcdSCristian Dumitrescu 	if (n_tokens) {
516687b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
516787b36dcdSCristian Dumitrescu 		return;
516887b36dcdSCristian Dumitrescu 	}
516987b36dcdSCristian Dumitrescu 
517087b36dcdSCristian Dumitrescu 	/* Read table rule stats. */
517187b36dcdSCristian Dumitrescu 	status = pipeline_table_rule_stats_read(pipeline_name,
517287b36dcdSCristian Dumitrescu 		table_id,
517387b36dcdSCristian Dumitrescu 		&m,
517487b36dcdSCristian Dumitrescu 		&stats,
517587b36dcdSCristian Dumitrescu 		clear);
517687b36dcdSCristian Dumitrescu 	if (status) {
517787b36dcdSCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
517887b36dcdSCristian Dumitrescu 		return;
517987b36dcdSCristian Dumitrescu 	}
518087b36dcdSCristian Dumitrescu 
518187b36dcdSCristian Dumitrescu 	/* Print stats. */
518287b36dcdSCristian Dumitrescu 	if (stats.n_packets_valid && stats.n_bytes_valid)
518387b36dcdSCristian Dumitrescu 		snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: %" PRIu64 "\n",
518487b36dcdSCristian Dumitrescu 			stats.n_packets,
518587b36dcdSCristian Dumitrescu 			stats.n_bytes);
518687b36dcdSCristian Dumitrescu 
518787b36dcdSCristian Dumitrescu 	if (stats.n_packets_valid && !stats.n_bytes_valid)
518887b36dcdSCristian Dumitrescu 		snprintf(out, out_size, "Packets: %" PRIu64 "; Bytes: N/A\n",
518987b36dcdSCristian Dumitrescu 			stats.n_packets);
519087b36dcdSCristian Dumitrescu 
519187b36dcdSCristian Dumitrescu 	if (!stats.n_packets_valid && stats.n_bytes_valid)
519287b36dcdSCristian Dumitrescu 		snprintf(out, out_size, "Packets: N/A; Bytes: %" PRIu64 "\n",
519387b36dcdSCristian Dumitrescu 			stats.n_bytes);
519487b36dcdSCristian Dumitrescu 
519587b36dcdSCristian Dumitrescu 	if (!stats.n_packets_valid && !stats.n_bytes_valid)
519687b36dcdSCristian Dumitrescu 		snprintf(out, out_size, "Packets: N/A ; Bytes: N/A\n");
519787b36dcdSCristian Dumitrescu }
519826b3effeSKevin Laatz 
519926b3effeSKevin Laatz static const char cmd_pipeline_table_meter_profile_add_help[] =
520026b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> meter profile <meter_profile_id>\n"
520126b3effeSKevin Laatz "   add srtcm cir <cir> cbs <cbs> ebs <ebs>\n"
520226b3effeSKevin Laatz "   | trtcm cir <cir> pir <pir> cbs <cbs> pbs <pbs>\n";
520326b3effeSKevin Laatz 
52047e11393eSJasvinder Singh static void
52057e11393eSJasvinder Singh cmd_pipeline_table_meter_profile_add(char **tokens,
52067e11393eSJasvinder Singh 	uint32_t n_tokens,
52077e11393eSJasvinder Singh 	char *out,
52087e11393eSJasvinder Singh 	size_t out_size)
52097e11393eSJasvinder Singh {
52107e11393eSJasvinder Singh 	struct rte_table_action_meter_profile p;
52117e11393eSJasvinder Singh 	char *pipeline_name;
52127e11393eSJasvinder Singh 	uint32_t table_id, meter_profile_id;
52137e11393eSJasvinder Singh 	int status;
52147e11393eSJasvinder Singh 
52157e11393eSJasvinder Singh 	if (n_tokens < 9) {
52167e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
52177e11393eSJasvinder Singh 		return;
52187e11393eSJasvinder Singh 	}
52197e11393eSJasvinder Singh 
52207e11393eSJasvinder Singh 	pipeline_name = tokens[1];
52217e11393eSJasvinder Singh 
52227e11393eSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
52237e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
52247e11393eSJasvinder Singh 		return;
52257e11393eSJasvinder Singh 	}
52267e11393eSJasvinder Singh 
52277e11393eSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
52287e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
52297e11393eSJasvinder Singh 		return;
52307e11393eSJasvinder Singh 	}
52317e11393eSJasvinder Singh 
52327e11393eSJasvinder Singh 	if (strcmp(tokens[4], "meter") != 0) {
52337e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
52347e11393eSJasvinder Singh 		return;
52357e11393eSJasvinder Singh 	}
52367e11393eSJasvinder Singh 
52377e11393eSJasvinder Singh 	if (strcmp(tokens[5], "profile") != 0) {
52387e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
52397e11393eSJasvinder Singh 		return;
52407e11393eSJasvinder Singh 	}
52417e11393eSJasvinder Singh 
52427e11393eSJasvinder Singh 	if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
52437e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
52447e11393eSJasvinder Singh 		return;
52457e11393eSJasvinder Singh 	}
52467e11393eSJasvinder Singh 
52477e11393eSJasvinder Singh 	if (strcmp(tokens[7], "add") != 0) {
52487e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "add");
52497e11393eSJasvinder Singh 		return;
52507e11393eSJasvinder Singh 	}
52517e11393eSJasvinder Singh 
52527e11393eSJasvinder Singh 	if (strcmp(tokens[8], "srtcm") == 0) {
52537e11393eSJasvinder Singh 		if (n_tokens != 15) {
52547e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH,
52557e11393eSJasvinder Singh 				tokens[0]);
52567e11393eSJasvinder Singh 			return;
52577e11393eSJasvinder Singh 		}
52587e11393eSJasvinder Singh 
52597e11393eSJasvinder Singh 		p.alg = RTE_TABLE_ACTION_METER_SRTCM;
52607e11393eSJasvinder Singh 
52617e11393eSJasvinder Singh 		if (strcmp(tokens[9], "cir") != 0) {
52627e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
52637e11393eSJasvinder Singh 			return;
52647e11393eSJasvinder Singh 		}
52657e11393eSJasvinder Singh 
52667e11393eSJasvinder Singh 		if (parser_read_uint64(&p.srtcm.cir, tokens[10]) != 0) {
52677e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "cir");
52687e11393eSJasvinder Singh 			return;
52697e11393eSJasvinder Singh 		}
52707e11393eSJasvinder Singh 
52717e11393eSJasvinder Singh 		if (strcmp(tokens[11], "cbs") != 0) {
52727e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
52737e11393eSJasvinder Singh 			return;
52747e11393eSJasvinder Singh 		}
52757e11393eSJasvinder Singh 
52767e11393eSJasvinder Singh 		if (parser_read_uint64(&p.srtcm.cbs, tokens[12]) != 0) {
52777e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
52787e11393eSJasvinder Singh 			return;
52797e11393eSJasvinder Singh 		}
52807e11393eSJasvinder Singh 
52817e11393eSJasvinder Singh 		if (strcmp(tokens[13], "ebs") != 0) {
52827e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ebs");
52837e11393eSJasvinder Singh 			return;
52847e11393eSJasvinder Singh 		}
52857e11393eSJasvinder Singh 
52867e11393eSJasvinder Singh 		if (parser_read_uint64(&p.srtcm.ebs, tokens[14]) != 0) {
52877e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "ebs");
52887e11393eSJasvinder Singh 			return;
52897e11393eSJasvinder Singh 		}
52907e11393eSJasvinder Singh 	} else if (strcmp(tokens[8], "trtcm") == 0) {
52917e11393eSJasvinder Singh 		if (n_tokens != 17) {
52927e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
52937e11393eSJasvinder Singh 			return;
52947e11393eSJasvinder Singh 		}
52957e11393eSJasvinder Singh 
52967e11393eSJasvinder Singh 		p.alg = RTE_TABLE_ACTION_METER_TRTCM;
52977e11393eSJasvinder Singh 
52987e11393eSJasvinder Singh 		if (strcmp(tokens[9], "cir") != 0) {
52997e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cir");
53007e11393eSJasvinder Singh 			return;
53017e11393eSJasvinder Singh 		}
53027e11393eSJasvinder Singh 
53037e11393eSJasvinder Singh 		if (parser_read_uint64(&p.trtcm.cir, tokens[10]) != 0) {
53047e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "cir");
53057e11393eSJasvinder Singh 			return;
53067e11393eSJasvinder Singh 		}
53077e11393eSJasvinder Singh 
53087e11393eSJasvinder Singh 		if (strcmp(tokens[11], "pir") != 0) {
53097e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pir");
53107e11393eSJasvinder Singh 			return;
53117e11393eSJasvinder Singh 		}
53127e11393eSJasvinder Singh 
53137e11393eSJasvinder Singh 		if (parser_read_uint64(&p.trtcm.pir, tokens[12]) != 0) {
53147e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "pir");
53157e11393eSJasvinder Singh 			return;
53167e11393eSJasvinder Singh 		}
53177e11393eSJasvinder Singh 		if (strcmp(tokens[13], "cbs") != 0) {
53187e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "cbs");
53197e11393eSJasvinder Singh 			return;
53207e11393eSJasvinder Singh 		}
53217e11393eSJasvinder Singh 
53227e11393eSJasvinder Singh 		if (parser_read_uint64(&p.trtcm.cbs, tokens[14]) != 0) {
53237e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "cbs");
53247e11393eSJasvinder Singh 			return;
53257e11393eSJasvinder Singh 		}
53267e11393eSJasvinder Singh 
53277e11393eSJasvinder Singh 		if (strcmp(tokens[15], "pbs") != 0) {
53287e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pbs");
53297e11393eSJasvinder Singh 			return;
53307e11393eSJasvinder Singh 		}
53317e11393eSJasvinder Singh 
53327e11393eSJasvinder Singh 		if (parser_read_uint64(&p.trtcm.pbs, tokens[16]) != 0) {
53337e11393eSJasvinder Singh 			snprintf(out, out_size, MSG_ARG_INVALID, "pbs");
53347e11393eSJasvinder Singh 			return;
53357e11393eSJasvinder Singh 		}
53367e11393eSJasvinder Singh 	} else {
53377e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
53387e11393eSJasvinder Singh 		return;
53397e11393eSJasvinder Singh 	}
53407e11393eSJasvinder Singh 
53417e11393eSJasvinder Singh 	status = pipeline_table_mtr_profile_add(pipeline_name,
53427e11393eSJasvinder Singh 		table_id,
53437e11393eSJasvinder Singh 		meter_profile_id,
53447e11393eSJasvinder Singh 		&p);
53457e11393eSJasvinder Singh 	if (status) {
53467e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
53477e11393eSJasvinder Singh 		return;
53487e11393eSJasvinder Singh 	}
53497e11393eSJasvinder Singh }
53507e11393eSJasvinder Singh 
535126b3effeSKevin Laatz 
535226b3effeSKevin Laatz static const char cmd_pipeline_table_meter_profile_delete_help[] =
535326b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id>\n"
535426b3effeSKevin Laatz "   meter profile <meter_profile_id> delete\n";
535526b3effeSKevin Laatz 
53567e11393eSJasvinder Singh static void
53577e11393eSJasvinder Singh cmd_pipeline_table_meter_profile_delete(char **tokens,
53587e11393eSJasvinder Singh 	uint32_t n_tokens,
53597e11393eSJasvinder Singh 	char *out,
53607e11393eSJasvinder Singh 	size_t out_size)
53617e11393eSJasvinder Singh {
53627e11393eSJasvinder Singh 	char *pipeline_name;
53637e11393eSJasvinder Singh 	uint32_t table_id, meter_profile_id;
53647e11393eSJasvinder Singh 	int status;
53657e11393eSJasvinder Singh 
53667e11393eSJasvinder Singh 	if (n_tokens != 8) {
53677e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
53687e11393eSJasvinder Singh 		return;
53697e11393eSJasvinder Singh 	}
53707e11393eSJasvinder Singh 
53717e11393eSJasvinder Singh 	pipeline_name = tokens[1];
53727e11393eSJasvinder Singh 
53737e11393eSJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
53747e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
53757e11393eSJasvinder Singh 		return;
53767e11393eSJasvinder Singh 	}
53777e11393eSJasvinder Singh 
53787e11393eSJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
53797e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
53807e11393eSJasvinder Singh 		return;
53817e11393eSJasvinder Singh 	}
53827e11393eSJasvinder Singh 
53837e11393eSJasvinder Singh 	if (strcmp(tokens[4], "meter") != 0) {
53847e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
53857e11393eSJasvinder Singh 		return;
53867e11393eSJasvinder Singh 	}
53877e11393eSJasvinder Singh 
53887e11393eSJasvinder Singh 	if (strcmp(tokens[5], "profile") != 0) {
53897e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "profile");
53907e11393eSJasvinder Singh 		return;
53917e11393eSJasvinder Singh 	}
53927e11393eSJasvinder Singh 
53937e11393eSJasvinder Singh 	if (parser_read_uint32(&meter_profile_id, tokens[6]) != 0) {
53947e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "meter_profile_id");
53957e11393eSJasvinder Singh 		return;
53967e11393eSJasvinder Singh 	}
53977e11393eSJasvinder Singh 
53987e11393eSJasvinder Singh 	if (strcmp(tokens[7], "delete") != 0) {
53997e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "delete");
54007e11393eSJasvinder Singh 		return;
54017e11393eSJasvinder Singh 	}
54027e11393eSJasvinder Singh 
54037e11393eSJasvinder Singh 	status = pipeline_table_mtr_profile_delete(pipeline_name,
54047e11393eSJasvinder Singh 		table_id,
54057e11393eSJasvinder Singh 		meter_profile_id);
54067e11393eSJasvinder Singh 	if (status) {
54077e11393eSJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
54087e11393eSJasvinder Singh 		return;
54097e11393eSJasvinder Singh 	}
54107e11393eSJasvinder Singh }
54117e11393eSJasvinder Singh 
541226b3effeSKevin Laatz 
541326b3effeSKevin Laatz static const char cmd_pipeline_table_rule_meter_read_help[] =
54148c6dc647SCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule read meter [clear]\n"
54158c6dc647SCristian Dumitrescu "     match <match>\n";
541626b3effeSKevin Laatz 
5417e92058d6SJasvinder Singh static void
5418e92058d6SJasvinder Singh cmd_pipeline_table_rule_meter_read(char **tokens,
54198c6dc647SCristian Dumitrescu 	uint32_t n_tokens,
5420e92058d6SJasvinder Singh 	char *out,
5421e92058d6SJasvinder Singh 	size_t out_size)
5422e92058d6SJasvinder Singh {
54238c6dc647SCristian Dumitrescu 	struct table_rule_match m;
54248c6dc647SCristian Dumitrescu 	struct rte_table_action_mtr_counters stats;
54258c6dc647SCristian Dumitrescu 	char *pipeline_name;
54268c6dc647SCristian Dumitrescu 	uint32_t table_id, n_tokens_parsed;
54278c6dc647SCristian Dumitrescu 	int clear = 0, status;
54288c6dc647SCristian Dumitrescu 
54298c6dc647SCristian Dumitrescu 	if (n_tokens < 7) {
54308c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
54318c6dc647SCristian Dumitrescu 		return;
54328c6dc647SCristian Dumitrescu 	}
54338c6dc647SCristian Dumitrescu 
54348c6dc647SCristian Dumitrescu 	pipeline_name = tokens[1];
54358c6dc647SCristian Dumitrescu 
54368c6dc647SCristian Dumitrescu 	if (strcmp(tokens[2], "table") != 0) {
54378c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
54388c6dc647SCristian Dumitrescu 		return;
54398c6dc647SCristian Dumitrescu 	}
54408c6dc647SCristian Dumitrescu 
54418c6dc647SCristian Dumitrescu 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
54428c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
54438c6dc647SCristian Dumitrescu 		return;
54448c6dc647SCristian Dumitrescu 	}
54458c6dc647SCristian Dumitrescu 
54468c6dc647SCristian Dumitrescu 	if (strcmp(tokens[4], "rule") != 0) {
54478c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
54488c6dc647SCristian Dumitrescu 		return;
54498c6dc647SCristian Dumitrescu 	}
54508c6dc647SCristian Dumitrescu 
54518c6dc647SCristian Dumitrescu 	if (strcmp(tokens[5], "read") != 0) {
54528c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
54538c6dc647SCristian Dumitrescu 		return;
54548c6dc647SCristian Dumitrescu 	}
54558c6dc647SCristian Dumitrescu 
54568c6dc647SCristian Dumitrescu 	if (strcmp(tokens[6], "meter") != 0) {
54578c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "meter");
54588c6dc647SCristian Dumitrescu 		return;
54598c6dc647SCristian Dumitrescu 	}
54608c6dc647SCristian Dumitrescu 
54618c6dc647SCristian Dumitrescu 	n_tokens -= 7;
54628c6dc647SCristian Dumitrescu 	tokens += 7;
54638c6dc647SCristian Dumitrescu 
54648c6dc647SCristian Dumitrescu 	/* clear */
54658c6dc647SCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
54668c6dc647SCristian Dumitrescu 		clear = 1;
54678c6dc647SCristian Dumitrescu 
54688c6dc647SCristian Dumitrescu 		n_tokens--;
54698c6dc647SCristian Dumitrescu 		tokens++;
54708c6dc647SCristian Dumitrescu 	}
54718c6dc647SCristian Dumitrescu 
54728c6dc647SCristian Dumitrescu 	/* match */
54738c6dc647SCristian Dumitrescu 	if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
54748c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
54758c6dc647SCristian Dumitrescu 		return;
54768c6dc647SCristian Dumitrescu 	}
54778c6dc647SCristian Dumitrescu 
54788c6dc647SCristian Dumitrescu 	n_tokens_parsed = parse_match(tokens,
54798c6dc647SCristian Dumitrescu 		n_tokens,
54808c6dc647SCristian Dumitrescu 		out,
54818c6dc647SCristian Dumitrescu 		out_size,
54828c6dc647SCristian Dumitrescu 		&m);
54838c6dc647SCristian Dumitrescu 	if (n_tokens_parsed == 0)
54848c6dc647SCristian Dumitrescu 		return;
54858c6dc647SCristian Dumitrescu 	n_tokens -= n_tokens_parsed;
54868c6dc647SCristian Dumitrescu 	tokens += n_tokens_parsed;
54878c6dc647SCristian Dumitrescu 
54888c6dc647SCristian Dumitrescu 	/* end */
54898c6dc647SCristian Dumitrescu 	if (n_tokens) {
54908c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
54918c6dc647SCristian Dumitrescu 		return;
54928c6dc647SCristian Dumitrescu 	}
54938c6dc647SCristian Dumitrescu 
54948c6dc647SCristian Dumitrescu 	/* Read table rule meter stats. */
54958c6dc647SCristian Dumitrescu 	status = pipeline_table_rule_mtr_read(pipeline_name,
54968c6dc647SCristian Dumitrescu 		table_id,
54978c6dc647SCristian Dumitrescu 		&m,
54988c6dc647SCristian Dumitrescu 		&stats,
54998c6dc647SCristian Dumitrescu 		clear);
55008c6dc647SCristian Dumitrescu 	if (status) {
55018c6dc647SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
55028c6dc647SCristian Dumitrescu 		return;
55038c6dc647SCristian Dumitrescu 	}
55048c6dc647SCristian Dumitrescu 
55058c6dc647SCristian Dumitrescu 	/* Print stats. */
5506e92058d6SJasvinder Singh }
5507e92058d6SJasvinder Singh 
550826b3effeSKevin Laatz 
550926b3effeSKevin Laatz static const char cmd_pipeline_table_dscp_help[] =
551026b3effeSKevin Laatz "pipeline <pipeline_name> table <table_id> dscp <file_name>\n"
551126b3effeSKevin Laatz "\n"
551226b3effeSKevin Laatz " File <file_name>:\n"
551326b3effeSKevin Laatz "   - exactly 64 lines\n"
551426b3effeSKevin Laatz "   - line format: <tc_id> <tc_queue_id> <color>, with <color> as: g | y | r\n";
551526b3effeSKevin Laatz 
55162b82ef48SJasvinder Singh static int
55172b82ef48SJasvinder Singh load_dscp_table(struct rte_table_action_dscp_table *dscp_table,
55182b82ef48SJasvinder Singh 	const char *file_name,
55192b82ef48SJasvinder Singh 	uint32_t *line_number)
55202b82ef48SJasvinder Singh {
55212b82ef48SJasvinder Singh 	FILE *f = NULL;
55222b82ef48SJasvinder Singh 	uint32_t dscp, l;
55232b82ef48SJasvinder Singh 
55242b82ef48SJasvinder Singh 	/* Check input arguments */
55252b82ef48SJasvinder Singh 	if ((dscp_table == NULL) ||
55262b82ef48SJasvinder Singh 		(file_name == NULL) ||
55272b82ef48SJasvinder Singh 		(line_number == NULL)) {
55282b82ef48SJasvinder Singh 		if (line_number)
55292b82ef48SJasvinder Singh 			*line_number = 0;
55302b82ef48SJasvinder Singh 		return -EINVAL;
55312b82ef48SJasvinder Singh 	}
55322b82ef48SJasvinder Singh 
55332b82ef48SJasvinder Singh 	/* Open input file */
55342b82ef48SJasvinder Singh 	f = fopen(file_name, "r");
55352b82ef48SJasvinder Singh 	if (f == NULL) {
55362b82ef48SJasvinder Singh 		*line_number = 0;
55372b82ef48SJasvinder Singh 		return -EINVAL;
55382b82ef48SJasvinder Singh 	}
55392b82ef48SJasvinder Singh 
55402b82ef48SJasvinder Singh 	/* Read file */
55412b82ef48SJasvinder Singh 	for (dscp = 0, l = 1; ; l++) {
55422b82ef48SJasvinder Singh 		char line[64];
55432b82ef48SJasvinder Singh 		char *tokens[3];
5544c1656328SJasvinder Singh 		enum rte_color color;
55452b82ef48SJasvinder Singh 		uint32_t tc_id, tc_queue_id, n_tokens = RTE_DIM(tokens);
55462b82ef48SJasvinder Singh 
55472b82ef48SJasvinder Singh 		if (fgets(line, sizeof(line), f) == NULL)
55482b82ef48SJasvinder Singh 			break;
55492b82ef48SJasvinder Singh 
55502b82ef48SJasvinder Singh 		if (is_comment(line))
55512b82ef48SJasvinder Singh 			continue;
55522b82ef48SJasvinder Singh 
55532b82ef48SJasvinder Singh 		if (parse_tokenize_string(line, tokens, &n_tokens)) {
55542b82ef48SJasvinder Singh 			*line_number = l;
55559b607951SJasvinder Singh 			fclose(f);
55562b82ef48SJasvinder Singh 			return -EINVAL;
55572b82ef48SJasvinder Singh 		}
55582b82ef48SJasvinder Singh 
55592b82ef48SJasvinder Singh 		if (n_tokens == 0)
55602b82ef48SJasvinder Singh 			continue;
55612b82ef48SJasvinder Singh 
55622b82ef48SJasvinder Singh 		if ((dscp >= RTE_DIM(dscp_table->entry)) ||
55632b82ef48SJasvinder Singh 			(n_tokens != RTE_DIM(tokens)) ||
55642b82ef48SJasvinder Singh 			parser_read_uint32(&tc_id, tokens[0]) ||
55652b82ef48SJasvinder Singh 			(tc_id >= RTE_TABLE_ACTION_TC_MAX) ||
55662b82ef48SJasvinder Singh 			parser_read_uint32(&tc_queue_id, tokens[1]) ||
55672b82ef48SJasvinder Singh 			(tc_queue_id >= RTE_TABLE_ACTION_TC_QUEUE_MAX) ||
55682b82ef48SJasvinder Singh 			(strlen(tokens[2]) != 1)) {
55692b82ef48SJasvinder Singh 			*line_number = l;
55709b607951SJasvinder Singh 			fclose(f);
55712b82ef48SJasvinder Singh 			return -EINVAL;
55722b82ef48SJasvinder Singh 		}
55732b82ef48SJasvinder Singh 
55742b82ef48SJasvinder Singh 		switch (tokens[2][0]) {
55752b82ef48SJasvinder Singh 		case 'g':
55762b82ef48SJasvinder Singh 		case 'G':
5577c1656328SJasvinder Singh 			color = RTE_COLOR_GREEN;
55782b82ef48SJasvinder Singh 			break;
55792b82ef48SJasvinder Singh 
55802b82ef48SJasvinder Singh 		case 'y':
55812b82ef48SJasvinder Singh 		case 'Y':
5582c1656328SJasvinder Singh 			color = RTE_COLOR_YELLOW;
55832b82ef48SJasvinder Singh 			break;
55842b82ef48SJasvinder Singh 
55852b82ef48SJasvinder Singh 		case 'r':
55862b82ef48SJasvinder Singh 		case 'R':
5587c1656328SJasvinder Singh 			color = RTE_COLOR_RED;
55882b82ef48SJasvinder Singh 			break;
55892b82ef48SJasvinder Singh 
55902b82ef48SJasvinder Singh 		default:
55912b82ef48SJasvinder Singh 			*line_number = l;
55929b607951SJasvinder Singh 			fclose(f);
55932b82ef48SJasvinder Singh 			return -EINVAL;
55942b82ef48SJasvinder Singh 		}
55952b82ef48SJasvinder Singh 
55962b82ef48SJasvinder Singh 		dscp_table->entry[dscp].tc_id = tc_id;
55972b82ef48SJasvinder Singh 		dscp_table->entry[dscp].tc_queue_id = tc_queue_id;
55982b82ef48SJasvinder Singh 		dscp_table->entry[dscp].color = color;
55992b82ef48SJasvinder Singh 		dscp++;
56002b82ef48SJasvinder Singh 	}
56012b82ef48SJasvinder Singh 
56022b82ef48SJasvinder Singh 	/* Close file */
56032b82ef48SJasvinder Singh 	fclose(f);
56042b82ef48SJasvinder Singh 	return 0;
56052b82ef48SJasvinder Singh }
56062b82ef48SJasvinder Singh 
56072b82ef48SJasvinder Singh static void
56082b82ef48SJasvinder Singh cmd_pipeline_table_dscp(char **tokens,
56092b82ef48SJasvinder Singh 	uint32_t n_tokens,
56102b82ef48SJasvinder Singh 	char *out,
56112b82ef48SJasvinder Singh 	size_t out_size)
56122b82ef48SJasvinder Singh {
56132b82ef48SJasvinder Singh 	struct rte_table_action_dscp_table dscp_table;
56142b82ef48SJasvinder Singh 	char *pipeline_name, *file_name;
56152b82ef48SJasvinder Singh 	uint32_t table_id, line_number;
56162b82ef48SJasvinder Singh 	int status;
56172b82ef48SJasvinder Singh 
56182b82ef48SJasvinder Singh 	if (n_tokens != 6) {
56192b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
56202b82ef48SJasvinder Singh 		return;
56212b82ef48SJasvinder Singh 	}
56222b82ef48SJasvinder Singh 
56232b82ef48SJasvinder Singh 	pipeline_name = tokens[1];
56242b82ef48SJasvinder Singh 
56252b82ef48SJasvinder Singh 	if (strcmp(tokens[2], "table") != 0) {
56262b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "port");
56272b82ef48SJasvinder Singh 		return;
56282b82ef48SJasvinder Singh 	}
56292b82ef48SJasvinder Singh 
56302b82ef48SJasvinder Singh 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
56312b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
56322b82ef48SJasvinder Singh 		return;
56332b82ef48SJasvinder Singh 	}
56342b82ef48SJasvinder Singh 
56352b82ef48SJasvinder Singh 	if (strcmp(tokens[4], "dscp") != 0) {
56362b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "dscp");
56372b82ef48SJasvinder Singh 		return;
56382b82ef48SJasvinder Singh 	}
56392b82ef48SJasvinder Singh 
56402b82ef48SJasvinder Singh 	file_name = tokens[5];
56412b82ef48SJasvinder Singh 
56422b82ef48SJasvinder Singh 	status = load_dscp_table(&dscp_table, file_name, &line_number);
56432b82ef48SJasvinder Singh 	if (status) {
56442b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_FILE_ERR, file_name, line_number);
56452b82ef48SJasvinder Singh 		return;
56462b82ef48SJasvinder Singh 	}
56472b82ef48SJasvinder Singh 
56482b82ef48SJasvinder Singh 	status = pipeline_table_dscp_table_update(pipeline_name,
56492b82ef48SJasvinder Singh 		table_id,
56502b82ef48SJasvinder Singh 		UINT64_MAX,
56512b82ef48SJasvinder Singh 		&dscp_table);
56522b82ef48SJasvinder Singh 	if (status) {
56532b82ef48SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
56542b82ef48SJasvinder Singh 		return;
56552b82ef48SJasvinder Singh 	}
56562b82ef48SJasvinder Singh }
56572b82ef48SJasvinder Singh 
565826b3effeSKevin Laatz 
565926b3effeSKevin Laatz static const char cmd_pipeline_table_rule_ttl_read_help[] =
56608bfe22acSCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule read ttl [clear]\n"
56618bfe22acSCristian Dumitrescu "     match <match>\n";
566226b3effeSKevin Laatz 
5663d0d306c7SJasvinder Singh static void
5664d0d306c7SJasvinder Singh cmd_pipeline_table_rule_ttl_read(char **tokens,
56658bfe22acSCristian Dumitrescu 	uint32_t n_tokens,
5666d0d306c7SJasvinder Singh 	char *out,
5667d0d306c7SJasvinder Singh 	size_t out_size)
5668d0d306c7SJasvinder Singh {
56698bfe22acSCristian Dumitrescu 	struct table_rule_match m;
56708bfe22acSCristian Dumitrescu 	struct rte_table_action_ttl_counters stats;
56718bfe22acSCristian Dumitrescu 	char *pipeline_name;
56728bfe22acSCristian Dumitrescu 	uint32_t table_id, n_tokens_parsed;
56738bfe22acSCristian Dumitrescu 	int clear = 0, status;
56748bfe22acSCristian Dumitrescu 
56758bfe22acSCristian Dumitrescu 	if (n_tokens < 7) {
56768bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
56778bfe22acSCristian Dumitrescu 		return;
56788bfe22acSCristian Dumitrescu 	}
56798bfe22acSCristian Dumitrescu 
56808bfe22acSCristian Dumitrescu 	pipeline_name = tokens[1];
56818bfe22acSCristian Dumitrescu 
56828bfe22acSCristian Dumitrescu 	if (strcmp(tokens[2], "table") != 0) {
56838bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
56848bfe22acSCristian Dumitrescu 		return;
56858bfe22acSCristian Dumitrescu 	}
56868bfe22acSCristian Dumitrescu 
56878bfe22acSCristian Dumitrescu 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
56888bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
56898bfe22acSCristian Dumitrescu 		return;
56908bfe22acSCristian Dumitrescu 	}
56918bfe22acSCristian Dumitrescu 
56928bfe22acSCristian Dumitrescu 	if (strcmp(tokens[4], "rule") != 0) {
56938bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
56948bfe22acSCristian Dumitrescu 		return;
56958bfe22acSCristian Dumitrescu 	}
56968bfe22acSCristian Dumitrescu 
56978bfe22acSCristian Dumitrescu 	if (strcmp(tokens[5], "read") != 0) {
56988bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
56998bfe22acSCristian Dumitrescu 		return;
57008bfe22acSCristian Dumitrescu 	}
57018bfe22acSCristian Dumitrescu 
57028bfe22acSCristian Dumitrescu 	if (strcmp(tokens[6], "ttl") != 0) {
57038bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "ttl");
57048bfe22acSCristian Dumitrescu 		return;
57058bfe22acSCristian Dumitrescu 	}
57068bfe22acSCristian Dumitrescu 
57078bfe22acSCristian Dumitrescu 	n_tokens -= 7;
57088bfe22acSCristian Dumitrescu 	tokens += 7;
57098bfe22acSCristian Dumitrescu 
57108bfe22acSCristian Dumitrescu 	/* clear */
57118bfe22acSCristian Dumitrescu 	if (n_tokens && (strcmp(tokens[0], "clear") == 0)) {
57128bfe22acSCristian Dumitrescu 		clear = 1;
57138bfe22acSCristian Dumitrescu 
57148bfe22acSCristian Dumitrescu 		n_tokens--;
57158bfe22acSCristian Dumitrescu 		tokens++;
57168bfe22acSCristian Dumitrescu 	}
57178bfe22acSCristian Dumitrescu 
57188bfe22acSCristian Dumitrescu 	/* match */
57198bfe22acSCristian Dumitrescu 	if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
57208bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
57218bfe22acSCristian Dumitrescu 		return;
57228bfe22acSCristian Dumitrescu 	}
57238bfe22acSCristian Dumitrescu 
57248bfe22acSCristian Dumitrescu 	n_tokens_parsed = parse_match(tokens,
57258bfe22acSCristian Dumitrescu 		n_tokens,
57268bfe22acSCristian Dumitrescu 		out,
57278bfe22acSCristian Dumitrescu 		out_size,
57288bfe22acSCristian Dumitrescu 		&m);
57298bfe22acSCristian Dumitrescu 	if (n_tokens_parsed == 0)
57308bfe22acSCristian Dumitrescu 		return;
57318bfe22acSCristian Dumitrescu 	n_tokens -= n_tokens_parsed;
57328bfe22acSCristian Dumitrescu 	tokens += n_tokens_parsed;
57338bfe22acSCristian Dumitrescu 
57348bfe22acSCristian Dumitrescu 	/* end */
57358bfe22acSCristian Dumitrescu 	if (n_tokens) {
57368bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
57378bfe22acSCristian Dumitrescu 		return;
57388bfe22acSCristian Dumitrescu 	}
57398bfe22acSCristian Dumitrescu 
57408bfe22acSCristian Dumitrescu 	/* Read table rule TTL stats. */
57418bfe22acSCristian Dumitrescu 	status = pipeline_table_rule_ttl_read(pipeline_name,
57428bfe22acSCristian Dumitrescu 		table_id,
57438bfe22acSCristian Dumitrescu 		&m,
57448bfe22acSCristian Dumitrescu 		&stats,
57458bfe22acSCristian Dumitrescu 		clear);
57468bfe22acSCristian Dumitrescu 	if (status) {
57478bfe22acSCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
57488bfe22acSCristian Dumitrescu 		return;
57498bfe22acSCristian Dumitrescu 	}
57508bfe22acSCristian Dumitrescu 
57518bfe22acSCristian Dumitrescu 	/* Print stats. */
57528bfe22acSCristian Dumitrescu 	snprintf(out, out_size, "Packets: %" PRIu64 "\n",
57538bfe22acSCristian Dumitrescu 		stats.n_packets);
5754d0d306c7SJasvinder Singh }
5755d0d306c7SJasvinder Singh 
5756a3169ee5SCristian Dumitrescu static const char cmd_pipeline_table_rule_time_read_help[] =
5757a3169ee5SCristian Dumitrescu "pipeline <pipeline_name> table <table_id> rule read time\n"
5758a3169ee5SCristian Dumitrescu "     match <match>\n";
5759a3169ee5SCristian Dumitrescu 
5760a3169ee5SCristian Dumitrescu static void
5761a3169ee5SCristian Dumitrescu cmd_pipeline_table_rule_time_read(char **tokens,
5762a3169ee5SCristian Dumitrescu 	uint32_t n_tokens,
5763a3169ee5SCristian Dumitrescu 	char *out,
5764a3169ee5SCristian Dumitrescu 	size_t out_size)
5765a3169ee5SCristian Dumitrescu {
5766a3169ee5SCristian Dumitrescu 	struct table_rule_match m;
5767a3169ee5SCristian Dumitrescu 	char *pipeline_name;
5768a3169ee5SCristian Dumitrescu 	uint64_t timestamp;
5769a3169ee5SCristian Dumitrescu 	uint32_t table_id, n_tokens_parsed;
5770a3169ee5SCristian Dumitrescu 	int status;
5771a3169ee5SCristian Dumitrescu 
5772a3169ee5SCristian Dumitrescu 	if (n_tokens < 7) {
5773a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
5774a3169ee5SCristian Dumitrescu 		return;
5775a3169ee5SCristian Dumitrescu 	}
5776a3169ee5SCristian Dumitrescu 
5777a3169ee5SCristian Dumitrescu 	pipeline_name = tokens[1];
5778a3169ee5SCristian Dumitrescu 
5779a3169ee5SCristian Dumitrescu 	if (strcmp(tokens[2], "table") != 0) {
5780a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "table");
5781a3169ee5SCristian Dumitrescu 		return;
5782a3169ee5SCristian Dumitrescu 	}
5783a3169ee5SCristian Dumitrescu 
5784a3169ee5SCristian Dumitrescu 	if (parser_read_uint32(&table_id, tokens[3]) != 0) {
5785a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, "table_id");
5786a3169ee5SCristian Dumitrescu 		return;
5787a3169ee5SCristian Dumitrescu 	}
5788a3169ee5SCristian Dumitrescu 
5789a3169ee5SCristian Dumitrescu 	if (strcmp(tokens[4], "rule") != 0) {
5790a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "rule");
5791a3169ee5SCristian Dumitrescu 		return;
5792a3169ee5SCristian Dumitrescu 	}
5793a3169ee5SCristian Dumitrescu 
5794a3169ee5SCristian Dumitrescu 	if (strcmp(tokens[5], "read") != 0) {
5795a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "read");
5796a3169ee5SCristian Dumitrescu 		return;
5797a3169ee5SCristian Dumitrescu 	}
5798a3169ee5SCristian Dumitrescu 
5799a3169ee5SCristian Dumitrescu 	if (strcmp(tokens[6], "time") != 0) {
5800a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "time");
5801a3169ee5SCristian Dumitrescu 		return;
5802a3169ee5SCristian Dumitrescu 	}
5803a3169ee5SCristian Dumitrescu 
5804a3169ee5SCristian Dumitrescu 	n_tokens -= 7;
5805a3169ee5SCristian Dumitrescu 	tokens += 7;
5806a3169ee5SCristian Dumitrescu 
5807a3169ee5SCristian Dumitrescu 	/* match */
5808a3169ee5SCristian Dumitrescu 	if ((n_tokens == 0) || strcmp(tokens[0], "match")) {
5809a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "match");
5810a3169ee5SCristian Dumitrescu 		return;
5811a3169ee5SCristian Dumitrescu 	}
5812a3169ee5SCristian Dumitrescu 
5813a3169ee5SCristian Dumitrescu 	n_tokens_parsed = parse_match(tokens,
5814a3169ee5SCristian Dumitrescu 		n_tokens,
5815a3169ee5SCristian Dumitrescu 		out,
5816a3169ee5SCristian Dumitrescu 		out_size,
5817a3169ee5SCristian Dumitrescu 		&m);
5818a3169ee5SCristian Dumitrescu 	if (n_tokens_parsed == 0)
5819a3169ee5SCristian Dumitrescu 		return;
5820a3169ee5SCristian Dumitrescu 	n_tokens -= n_tokens_parsed;
5821a3169ee5SCristian Dumitrescu 	tokens += n_tokens_parsed;
5822a3169ee5SCristian Dumitrescu 
5823a3169ee5SCristian Dumitrescu 	/* end */
5824a3169ee5SCristian Dumitrescu 	if (n_tokens) {
5825a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_ARG_INVALID, tokens[0]);
5826a3169ee5SCristian Dumitrescu 		return;
5827a3169ee5SCristian Dumitrescu 	}
5828a3169ee5SCristian Dumitrescu 
5829a3169ee5SCristian Dumitrescu 	/* Read table rule timestamp. */
5830a3169ee5SCristian Dumitrescu 	status = pipeline_table_rule_time_read(pipeline_name,
5831a3169ee5SCristian Dumitrescu 		table_id,
5832a3169ee5SCristian Dumitrescu 		&m,
5833a3169ee5SCristian Dumitrescu 		&timestamp);
5834a3169ee5SCristian Dumitrescu 	if (status) {
5835a3169ee5SCristian Dumitrescu 		snprintf(out, out_size, MSG_CMD_FAIL, tokens[0]);
5836a3169ee5SCristian Dumitrescu 		return;
5837a3169ee5SCristian Dumitrescu 	}
5838a3169ee5SCristian Dumitrescu 
5839a3169ee5SCristian Dumitrescu 	/* Print stats. */
5840a3169ee5SCristian Dumitrescu 	snprintf(out, out_size, "Packets: %" PRIu64 "\n", timestamp);
5841a3169ee5SCristian Dumitrescu }
584226b3effeSKevin Laatz 
584326b3effeSKevin Laatz static const char cmd_thread_pipeline_enable_help[] =
584426b3effeSKevin Laatz "thread <thread_id> pipeline <pipeline_name> enable\n";
584526b3effeSKevin Laatz 
584632e5d9b1SJasvinder Singh static void
584732e5d9b1SJasvinder Singh cmd_thread_pipeline_enable(char **tokens,
584832e5d9b1SJasvinder Singh 	uint32_t n_tokens,
584932e5d9b1SJasvinder Singh 	char *out,
585032e5d9b1SJasvinder Singh 	size_t out_size)
585132e5d9b1SJasvinder Singh {
585232e5d9b1SJasvinder Singh 	char *pipeline_name;
585332e5d9b1SJasvinder Singh 	uint32_t thread_id;
585432e5d9b1SJasvinder Singh 	int status;
585532e5d9b1SJasvinder Singh 
585632e5d9b1SJasvinder Singh 	if (n_tokens != 5) {
585732e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
585832e5d9b1SJasvinder Singh 		return;
585932e5d9b1SJasvinder Singh 	}
586032e5d9b1SJasvinder Singh 
586132e5d9b1SJasvinder Singh 	if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
586232e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
586332e5d9b1SJasvinder Singh 		return;
586432e5d9b1SJasvinder Singh 	}
586532e5d9b1SJasvinder Singh 
586632e5d9b1SJasvinder Singh 	if (strcmp(tokens[2], "pipeline") != 0) {
586732e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
586832e5d9b1SJasvinder Singh 		return;
586932e5d9b1SJasvinder Singh 	}
587032e5d9b1SJasvinder Singh 
587132e5d9b1SJasvinder Singh 	pipeline_name = tokens[3];
587232e5d9b1SJasvinder Singh 
587332e5d9b1SJasvinder Singh 	if (strcmp(tokens[4], "enable") != 0) {
587432e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "enable");
587532e5d9b1SJasvinder Singh 		return;
587632e5d9b1SJasvinder Singh 	}
587732e5d9b1SJasvinder Singh 
587832e5d9b1SJasvinder Singh 	status = thread_pipeline_enable(thread_id, pipeline_name);
587932e5d9b1SJasvinder Singh 	if (status) {
588032e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL, "thread pipeline enable");
588132e5d9b1SJasvinder Singh 		return;
588232e5d9b1SJasvinder Singh 	}
588332e5d9b1SJasvinder Singh }
588432e5d9b1SJasvinder Singh 
588526b3effeSKevin Laatz 
588626b3effeSKevin Laatz static const char cmd_thread_pipeline_disable_help[] =
588726b3effeSKevin Laatz "thread <thread_id> pipeline <pipeline_name> disable\n";
588826b3effeSKevin Laatz 
588932e5d9b1SJasvinder Singh static void
589032e5d9b1SJasvinder Singh cmd_thread_pipeline_disable(char **tokens,
589132e5d9b1SJasvinder Singh 	uint32_t n_tokens,
589232e5d9b1SJasvinder Singh 	char *out,
589332e5d9b1SJasvinder Singh 	size_t out_size)
589432e5d9b1SJasvinder Singh {
589532e5d9b1SJasvinder Singh 	char *pipeline_name;
589632e5d9b1SJasvinder Singh 	uint32_t thread_id;
589732e5d9b1SJasvinder Singh 	int status;
589832e5d9b1SJasvinder Singh 
589932e5d9b1SJasvinder Singh 	if (n_tokens != 5) {
590032e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_MISMATCH, tokens[0]);
590132e5d9b1SJasvinder Singh 		return;
590232e5d9b1SJasvinder Singh 	}
590332e5d9b1SJasvinder Singh 
590432e5d9b1SJasvinder Singh 	if (parser_read_uint32(&thread_id, tokens[1]) != 0) {
590532e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_INVALID, "thread_id");
590632e5d9b1SJasvinder Singh 		return;
590732e5d9b1SJasvinder Singh 	}
590832e5d9b1SJasvinder Singh 
590932e5d9b1SJasvinder Singh 	if (strcmp(tokens[2], "pipeline") != 0) {
591032e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "pipeline");
591132e5d9b1SJasvinder Singh 		return;
591232e5d9b1SJasvinder Singh 	}
591332e5d9b1SJasvinder Singh 
591432e5d9b1SJasvinder Singh 	pipeline_name = tokens[3];
591532e5d9b1SJasvinder Singh 
591632e5d9b1SJasvinder Singh 	if (strcmp(tokens[4], "disable") != 0) {
591732e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_NOT_FOUND, "disable");
591832e5d9b1SJasvinder Singh 		return;
591932e5d9b1SJasvinder Singh 	}
592032e5d9b1SJasvinder Singh 
592132e5d9b1SJasvinder Singh 	status = thread_pipeline_disable(thread_id, pipeline_name);
592232e5d9b1SJasvinder Singh 	if (status) {
592332e5d9b1SJasvinder Singh 		snprintf(out, out_size, MSG_CMD_FAIL,
592432e5d9b1SJasvinder Singh 			"thread pipeline disable");
592532e5d9b1SJasvinder Singh 		return;
592632e5d9b1SJasvinder Singh 	}
592732e5d9b1SJasvinder Singh }
592832e5d9b1SJasvinder Singh 
592926b3effeSKevin Laatz static void
593026b3effeSKevin Laatz cmd_help(char **tokens, uint32_t n_tokens, char *out, size_t out_size)
593126b3effeSKevin Laatz {
593226b3effeSKevin Laatz 	tokens++;
593326b3effeSKevin Laatz 	n_tokens--;
593426b3effeSKevin Laatz 
593526b3effeSKevin Laatz 	if (n_tokens == 0) {
593626b3effeSKevin Laatz 		snprintf(out, out_size,
593726b3effeSKevin Laatz 			"Type 'help <command>' for details on each command.\n\n"
593826b3effeSKevin Laatz 			"List of commands:\n"
593926b3effeSKevin Laatz 			"\tmempool\n"
594026b3effeSKevin Laatz 			"\tlink\n"
594126b3effeSKevin Laatz 			"\tswq\n"
594226b3effeSKevin Laatz 			"\ttmgr subport profile\n"
594326b3effeSKevin Laatz 			"\ttmgr pipe profile\n"
594426b3effeSKevin Laatz 			"\ttmgr\n"
594526b3effeSKevin Laatz 			"\ttmgr subport\n"
594626b3effeSKevin Laatz 			"\ttmgr subport pipe\n"
594726b3effeSKevin Laatz 			"\ttap\n"
594826b3effeSKevin Laatz 			"\tport in action profile\n"
594926b3effeSKevin Laatz 			"\ttable action profile\n"
595026b3effeSKevin Laatz 			"\tpipeline\n"
595126b3effeSKevin Laatz 			"\tpipeline port in\n"
595226b3effeSKevin Laatz 			"\tpipeline port out\n"
595326b3effeSKevin Laatz 			"\tpipeline table\n"
595426b3effeSKevin Laatz 			"\tpipeline port in table\n"
595526b3effeSKevin Laatz 			"\tpipeline port in stats\n"
595626b3effeSKevin Laatz 			"\tpipeline port in enable\n"
595726b3effeSKevin Laatz 			"\tpipeline port in disable\n"
595826b3effeSKevin Laatz 			"\tpipeline port out stats\n"
595926b3effeSKevin Laatz 			"\tpipeline table stats\n"
596026b3effeSKevin Laatz 			"\tpipeline table rule add\n"
596126b3effeSKevin Laatz 			"\tpipeline table rule add default\n"
596226b3effeSKevin Laatz 			"\tpipeline table rule add bulk\n"
596326b3effeSKevin Laatz 			"\tpipeline table rule delete\n"
596426b3effeSKevin Laatz 			"\tpipeline table rule delete default\n"
59652fbdf834SCristian Dumitrescu 			"\tpipeline table rule show\n"
596626b3effeSKevin Laatz 			"\tpipeline table rule stats read\n"
596726b3effeSKevin Laatz 			"\tpipeline table meter profile add\n"
596826b3effeSKevin Laatz 			"\tpipeline table meter profile delete\n"
596926b3effeSKevin Laatz 			"\tpipeline table rule meter read\n"
597026b3effeSKevin Laatz 			"\tpipeline table dscp\n"
597126b3effeSKevin Laatz 			"\tpipeline table rule ttl read\n"
5972a3169ee5SCristian Dumitrescu 			"\tpipeline table rule time read\n"
597326b3effeSKevin Laatz 			"\tthread pipeline enable\n"
597426b3effeSKevin Laatz 			"\tthread pipeline disable\n\n");
597526b3effeSKevin Laatz 		return;
597626b3effeSKevin Laatz 	}
597726b3effeSKevin Laatz 
597826b3effeSKevin Laatz 	if (strcmp(tokens[0], "mempool") == 0) {
597926b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_mempool_help);
598026b3effeSKevin Laatz 		return;
598126b3effeSKevin Laatz 	}
598226b3effeSKevin Laatz 
598326b3effeSKevin Laatz 	if (strcmp(tokens[0], "link") == 0) {
598426b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_link_help);
598526b3effeSKevin Laatz 		return;
598626b3effeSKevin Laatz 	}
598726b3effeSKevin Laatz 
598826b3effeSKevin Laatz 	if (strcmp(tokens[0], "swq") == 0) {
598926b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_swq_help);
599026b3effeSKevin Laatz 		return;
599126b3effeSKevin Laatz 	}
599226b3effeSKevin Laatz 
599326b3effeSKevin Laatz 	if (strcmp(tokens[0], "tmgr") == 0) {
599426b3effeSKevin Laatz 		if (n_tokens == 1) {
599526b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_tmgr_help);
599626b3effeSKevin Laatz 			return;
599726b3effeSKevin Laatz 		}
599826b3effeSKevin Laatz 
599926b3effeSKevin Laatz 		if ((n_tokens == 2) &&
600026b3effeSKevin Laatz 			(strcmp(tokens[1], "subport")) == 0) {
600126b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_help);
600226b3effeSKevin Laatz 			return;
600326b3effeSKevin Laatz 		}
600426b3effeSKevin Laatz 
600526b3effeSKevin Laatz 		if ((n_tokens == 3) &&
600626b3effeSKevin Laatz 			(strcmp(tokens[1], "subport") == 0) &&
600726b3effeSKevin Laatz 			(strcmp(tokens[2], "profile") == 0)) {
600826b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
600926b3effeSKevin Laatz 				cmd_tmgr_subport_profile_help);
601026b3effeSKevin Laatz 			return;
601126b3effeSKevin Laatz 		}
601226b3effeSKevin Laatz 
601326b3effeSKevin Laatz 		if ((n_tokens == 3) &&
601426b3effeSKevin Laatz 			(strcmp(tokens[1], "subport") == 0) &&
601526b3effeSKevin Laatz 			(strcmp(tokens[2], "pipe") == 0)) {
601626b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_tmgr_subport_pipe_help);
601726b3effeSKevin Laatz 			return;
601826b3effeSKevin Laatz 		}
601926b3effeSKevin Laatz 
602026b3effeSKevin Laatz 		if ((n_tokens == 3) &&
602126b3effeSKevin Laatz 			(strcmp(tokens[1], "pipe") == 0) &&
602226b3effeSKevin Laatz 			(strcmp(tokens[2], "profile") == 0)) {
602326b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_tmgr_pipe_profile_help);
602426b3effeSKevin Laatz 			return;
602526b3effeSKevin Laatz 		}
602626b3effeSKevin Laatz 	}
602726b3effeSKevin Laatz 
602826b3effeSKevin Laatz 	if (strcmp(tokens[0], "tap") == 0) {
602926b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_tap_help);
603026b3effeSKevin Laatz 		return;
603126b3effeSKevin Laatz 	}
603226b3effeSKevin Laatz 
60331edccebcSFan Zhang 	if (strcmp(tokens[0], "cryptodev") == 0) {
60341edccebcSFan Zhang 		snprintf(out, out_size, "\n%s\n", cmd_cryptodev_help);
60351edccebcSFan Zhang 		return;
60361edccebcSFan Zhang 	}
60371edccebcSFan Zhang 
603826b3effeSKevin Laatz 	if ((n_tokens == 4) &&
603926b3effeSKevin Laatz 		(strcmp(tokens[0], "port") == 0) &&
604026b3effeSKevin Laatz 		(strcmp(tokens[1], "in") == 0) &&
604126b3effeSKevin Laatz 		(strcmp(tokens[2], "action") == 0) &&
604226b3effeSKevin Laatz 		(strcmp(tokens[3], "profile") == 0)) {
604326b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_port_in_action_profile_help);
604426b3effeSKevin Laatz 		return;
604526b3effeSKevin Laatz 	}
604626b3effeSKevin Laatz 
604726b3effeSKevin Laatz 	if ((n_tokens == 3) &&
604826b3effeSKevin Laatz 		(strcmp(tokens[0], "table") == 0) &&
604926b3effeSKevin Laatz 		(strcmp(tokens[1], "action") == 0) &&
605026b3effeSKevin Laatz 		(strcmp(tokens[2], "profile") == 0)) {
605126b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_table_action_profile_help);
605226b3effeSKevin Laatz 		return;
605326b3effeSKevin Laatz 	}
605426b3effeSKevin Laatz 
605526b3effeSKevin Laatz 	if ((strcmp(tokens[0], "pipeline") == 0) && (n_tokens == 1)) {
605626b3effeSKevin Laatz 		snprintf(out, out_size, "\n%s\n", cmd_pipeline_help);
605726b3effeSKevin Laatz 		return;
605826b3effeSKevin Laatz 	}
605926b3effeSKevin Laatz 
606026b3effeSKevin Laatz 	if ((strcmp(tokens[0], "pipeline") == 0) &&
606126b3effeSKevin Laatz 		(strcmp(tokens[1], "port") == 0)) {
606226b3effeSKevin Laatz 		if ((n_tokens == 3) && (strcmp(tokens[2], "in")) == 0) {
606326b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_in_help);
606426b3effeSKevin Laatz 			return;
606526b3effeSKevin Laatz 		}
606626b3effeSKevin Laatz 
606726b3effeSKevin Laatz 		if ((n_tokens == 3) && (strcmp(tokens[2], "out")) == 0) {
606826b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_pipeline_port_out_help);
606926b3effeSKevin Laatz 			return;
607026b3effeSKevin Laatz 		}
607126b3effeSKevin Laatz 
607226b3effeSKevin Laatz 		if ((n_tokens == 4) &&
607326b3effeSKevin Laatz 			(strcmp(tokens[2], "in") == 0) &&
607426b3effeSKevin Laatz 			(strcmp(tokens[3], "table") == 0)) {
607526b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
607626b3effeSKevin Laatz 				cmd_pipeline_port_in_table_help);
607726b3effeSKevin Laatz 			return;
607826b3effeSKevin Laatz 		}
607926b3effeSKevin Laatz 
608026b3effeSKevin Laatz 		if ((n_tokens == 4) &&
608126b3effeSKevin Laatz 			(strcmp(tokens[2], "in") == 0) &&
608226b3effeSKevin Laatz 			(strcmp(tokens[3], "stats") == 0)) {
608326b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
608426b3effeSKevin Laatz 				cmd_pipeline_port_in_stats_help);
608526b3effeSKevin Laatz 			return;
608626b3effeSKevin Laatz 		}
608726b3effeSKevin Laatz 
608826b3effeSKevin Laatz 		if ((n_tokens == 4) &&
608926b3effeSKevin Laatz 			(strcmp(tokens[2], "in") == 0) &&
609026b3effeSKevin Laatz 			(strcmp(tokens[3], "enable") == 0)) {
609126b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
609226b3effeSKevin Laatz 				cmd_pipeline_port_in_enable_help);
609326b3effeSKevin Laatz 			return;
609426b3effeSKevin Laatz 		}
609526b3effeSKevin Laatz 
609626b3effeSKevin Laatz 		if ((n_tokens == 4) &&
609726b3effeSKevin Laatz 			(strcmp(tokens[2], "in") == 0) &&
609826b3effeSKevin Laatz 			(strcmp(tokens[3], "disable") == 0)) {
609926b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
610026b3effeSKevin Laatz 				cmd_pipeline_port_in_disable_help);
610126b3effeSKevin Laatz 			return;
610226b3effeSKevin Laatz 		}
610326b3effeSKevin Laatz 
610426b3effeSKevin Laatz 		if ((n_tokens == 4) &&
610526b3effeSKevin Laatz 			(strcmp(tokens[2], "out") == 0) &&
610626b3effeSKevin Laatz 			(strcmp(tokens[3], "stats") == 0)) {
610726b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
610826b3effeSKevin Laatz 				cmd_pipeline_port_out_stats_help);
610926b3effeSKevin Laatz 			return;
611026b3effeSKevin Laatz 		}
611126b3effeSKevin Laatz 	}
611226b3effeSKevin Laatz 
611326b3effeSKevin Laatz 	if ((strcmp(tokens[0], "pipeline") == 0) &&
611426b3effeSKevin Laatz 		(strcmp(tokens[1], "table") == 0)) {
611526b3effeSKevin Laatz 		if (n_tokens == 2) {
611626b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n", cmd_pipeline_table_help);
611726b3effeSKevin Laatz 			return;
611826b3effeSKevin Laatz 		}
611926b3effeSKevin Laatz 
612026b3effeSKevin Laatz 		if ((n_tokens == 3) && strcmp(tokens[2], "stats") == 0) {
612126b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
612226b3effeSKevin Laatz 				cmd_pipeline_table_stats_help);
612326b3effeSKevin Laatz 			return;
612426b3effeSKevin Laatz 		}
612526b3effeSKevin Laatz 
612626b3effeSKevin Laatz 		if ((n_tokens == 3) && strcmp(tokens[2], "dscp") == 0) {
612726b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
612826b3effeSKevin Laatz 				cmd_pipeline_table_dscp_help);
612926b3effeSKevin Laatz 			return;
613026b3effeSKevin Laatz 		}
613126b3effeSKevin Laatz 
613226b3effeSKevin Laatz 		if ((n_tokens == 4) &&
613326b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
613426b3effeSKevin Laatz 			(strcmp(tokens[3], "add") == 0)) {
613526b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
613626b3effeSKevin Laatz 				cmd_pipeline_table_rule_add_help);
613726b3effeSKevin Laatz 			return;
613826b3effeSKevin Laatz 		}
613926b3effeSKevin Laatz 
614026b3effeSKevin Laatz 		if ((n_tokens == 5) &&
614126b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
614226b3effeSKevin Laatz 			(strcmp(tokens[3], "add") == 0) &&
614326b3effeSKevin Laatz 			(strcmp(tokens[4], "default") == 0)) {
614426b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
614526b3effeSKevin Laatz 				cmd_pipeline_table_rule_add_default_help);
614626b3effeSKevin Laatz 			return;
614726b3effeSKevin Laatz 		}
614826b3effeSKevin Laatz 
614926b3effeSKevin Laatz 		if ((n_tokens == 5) &&
615026b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
615126b3effeSKevin Laatz 			(strcmp(tokens[3], "add") == 0) &&
615226b3effeSKevin Laatz 			(strcmp(tokens[4], "bulk") == 0)) {
615326b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
615426b3effeSKevin Laatz 				cmd_pipeline_table_rule_add_bulk_help);
615526b3effeSKevin Laatz 			return;
615626b3effeSKevin Laatz 		}
615726b3effeSKevin Laatz 
615826b3effeSKevin Laatz 		if ((n_tokens == 4) &&
615926b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
616026b3effeSKevin Laatz 			(strcmp(tokens[3], "delete") == 0)) {
616126b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
616226b3effeSKevin Laatz 				cmd_pipeline_table_rule_delete_help);
616326b3effeSKevin Laatz 			return;
616426b3effeSKevin Laatz 		}
616526b3effeSKevin Laatz 
616626b3effeSKevin Laatz 		if ((n_tokens == 5) &&
616726b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
616826b3effeSKevin Laatz 			(strcmp(tokens[3], "delete") == 0) &&
616926b3effeSKevin Laatz 			(strcmp(tokens[4], "default") == 0)) {
617026b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
617126b3effeSKevin Laatz 				cmd_pipeline_table_rule_delete_default_help);
617226b3effeSKevin Laatz 			return;
617326b3effeSKevin Laatz 		}
617426b3effeSKevin Laatz 
61752fbdf834SCristian Dumitrescu 		if ((n_tokens == 4) &&
61762fbdf834SCristian Dumitrescu 			(strcmp(tokens[2], "rule") == 0) &&
61772fbdf834SCristian Dumitrescu 			(strcmp(tokens[3], "show") == 0)) {
61782fbdf834SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
61792fbdf834SCristian Dumitrescu 				cmd_pipeline_table_rule_show_help);
61802fbdf834SCristian Dumitrescu 			return;
61812fbdf834SCristian Dumitrescu 		}
61822fbdf834SCristian Dumitrescu 
618326b3effeSKevin Laatz 		if ((n_tokens == 5) &&
618426b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
618526b3effeSKevin Laatz 			(strcmp(tokens[3], "stats") == 0) &&
618626b3effeSKevin Laatz 			(strcmp(tokens[4], "read") == 0)) {
618726b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
618826b3effeSKevin Laatz 				cmd_pipeline_table_rule_stats_read_help);
618926b3effeSKevin Laatz 			return;
619026b3effeSKevin Laatz 		}
619126b3effeSKevin Laatz 
619226b3effeSKevin Laatz 		if ((n_tokens == 5) &&
619326b3effeSKevin Laatz 			(strcmp(tokens[2], "meter") == 0) &&
619426b3effeSKevin Laatz 			(strcmp(tokens[3], "profile") == 0) &&
619526b3effeSKevin Laatz 			(strcmp(tokens[4], "add") == 0)) {
619626b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
619726b3effeSKevin Laatz 				cmd_pipeline_table_meter_profile_add_help);
619826b3effeSKevin Laatz 			return;
619926b3effeSKevin Laatz 		}
620026b3effeSKevin Laatz 
620126b3effeSKevin Laatz 		if ((n_tokens == 5) &&
620226b3effeSKevin Laatz 			(strcmp(tokens[2], "meter") == 0) &&
620326b3effeSKevin Laatz 			(strcmp(tokens[3], "profile") == 0) &&
620426b3effeSKevin Laatz 			(strcmp(tokens[4], "delete") == 0)) {
620526b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
620626b3effeSKevin Laatz 				cmd_pipeline_table_meter_profile_delete_help);
620726b3effeSKevin Laatz 			return;
620826b3effeSKevin Laatz 		}
620926b3effeSKevin Laatz 
621026b3effeSKevin Laatz 		if ((n_tokens == 5) &&
621126b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
621226b3effeSKevin Laatz 			(strcmp(tokens[3], "meter") == 0) &&
621326b3effeSKevin Laatz 			(strcmp(tokens[4], "read") == 0)) {
621426b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
621526b3effeSKevin Laatz 				cmd_pipeline_table_rule_meter_read_help);
621626b3effeSKevin Laatz 			return;
621726b3effeSKevin Laatz 		}
621826b3effeSKevin Laatz 
621926b3effeSKevin Laatz 		if ((n_tokens == 5) &&
622026b3effeSKevin Laatz 			(strcmp(tokens[2], "rule") == 0) &&
622126b3effeSKevin Laatz 			(strcmp(tokens[3], "ttl") == 0) &&
622226b3effeSKevin Laatz 			(strcmp(tokens[4], "read") == 0)) {
622326b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
622426b3effeSKevin Laatz 				cmd_pipeline_table_rule_ttl_read_help);
622526b3effeSKevin Laatz 			return;
622626b3effeSKevin Laatz 		}
6227a3169ee5SCristian Dumitrescu 
6228a3169ee5SCristian Dumitrescu 		if ((n_tokens == 5) &&
6229a3169ee5SCristian Dumitrescu 			(strcmp(tokens[2], "rule") == 0) &&
6230a3169ee5SCristian Dumitrescu 			(strcmp(tokens[3], "time") == 0) &&
6231a3169ee5SCristian Dumitrescu 			(strcmp(tokens[4], "read") == 0)) {
6232a3169ee5SCristian Dumitrescu 			snprintf(out, out_size, "\n%s\n",
6233a3169ee5SCristian Dumitrescu 				cmd_pipeline_table_rule_time_read_help);
6234a3169ee5SCristian Dumitrescu 			return;
6235a3169ee5SCristian Dumitrescu 		}
623626b3effeSKevin Laatz 	}
623726b3effeSKevin Laatz 
623826b3effeSKevin Laatz 	if ((n_tokens == 3) &&
623926b3effeSKevin Laatz 		(strcmp(tokens[0], "thread") == 0) &&
624026b3effeSKevin Laatz 		(strcmp(tokens[1], "pipeline") == 0)) {
624126b3effeSKevin Laatz 		if (strcmp(tokens[2], "enable") == 0) {
624226b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
624326b3effeSKevin Laatz 				cmd_thread_pipeline_enable_help);
624426b3effeSKevin Laatz 			return;
624526b3effeSKevin Laatz 		}
624626b3effeSKevin Laatz 
624726b3effeSKevin Laatz 		if (strcmp(tokens[2], "disable") == 0) {
624826b3effeSKevin Laatz 			snprintf(out, out_size, "\n%s\n",
624926b3effeSKevin Laatz 				cmd_thread_pipeline_disable_help);
625026b3effeSKevin Laatz 			return;
625126b3effeSKevin Laatz 		}
625226b3effeSKevin Laatz 	}
625326b3effeSKevin Laatz 
625426b3effeSKevin Laatz 	snprintf(out, out_size, "Invalid command\n");
625526b3effeSKevin Laatz }
625626b3effeSKevin Laatz 
62576bfe74f8SJasvinder Singh void
62586bfe74f8SJasvinder Singh cli_process(char *in, char *out, size_t out_size)
62596bfe74f8SJasvinder Singh {
62606bfe74f8SJasvinder Singh 	char *tokens[CMD_MAX_TOKENS];
62616bfe74f8SJasvinder Singh 	uint32_t n_tokens = RTE_DIM(tokens);
62626bfe74f8SJasvinder Singh 	int status;
62636bfe74f8SJasvinder Singh 
62644bbf8e30SJasvinder Singh 	if (is_comment(in))
62654bbf8e30SJasvinder Singh 		return;
62664bbf8e30SJasvinder Singh 
62676bfe74f8SJasvinder Singh 	status = parse_tokenize_string(in, tokens, &n_tokens);
62686bfe74f8SJasvinder Singh 	if (status) {
62696bfe74f8SJasvinder Singh 		snprintf(out, out_size, MSG_ARG_TOO_MANY, "");
62706bfe74f8SJasvinder Singh 		return;
62716bfe74f8SJasvinder Singh 	}
62726bfe74f8SJasvinder Singh 
62736bfe74f8SJasvinder Singh 	if (n_tokens == 0)
62746bfe74f8SJasvinder Singh 		return;
62756bfe74f8SJasvinder Singh 
627626b3effeSKevin Laatz 	if (strcmp(tokens[0], "help") == 0) {
627726b3effeSKevin Laatz 		cmd_help(tokens, n_tokens, out, out_size);
627826b3effeSKevin Laatz 		return;
627926b3effeSKevin Laatz 	}
628026b3effeSKevin Laatz 
62816bfe74f8SJasvinder Singh 	if (strcmp(tokens[0], "mempool") == 0) {
62826bfe74f8SJasvinder Singh 		cmd_mempool(tokens, n_tokens, out, out_size);
62836bfe74f8SJasvinder Singh 		return;
62846bfe74f8SJasvinder Singh 	}
62856bfe74f8SJasvinder Singh 
6286133c2c65SJasvinder Singh 	if (strcmp(tokens[0], "link") == 0) {
6287ecfc2b1cSKevin Laatz 		if (strcmp(tokens[1], "show") == 0) {
6288ecfc2b1cSKevin Laatz 			cmd_link_show(tokens, n_tokens, out, out_size);
6289ecfc2b1cSKevin Laatz 			return;
6290ecfc2b1cSKevin Laatz 		}
6291ecfc2b1cSKevin Laatz 
6292133c2c65SJasvinder Singh 		cmd_link(tokens, n_tokens, out, out_size);
6293133c2c65SJasvinder Singh 		return;
6294133c2c65SJasvinder Singh 	}
6295133c2c65SJasvinder Singh 
62968245472cSJasvinder Singh 	if (strcmp(tokens[0], "swq") == 0) {
62978245472cSJasvinder Singh 		cmd_swq(tokens, n_tokens, out, out_size);
62988245472cSJasvinder Singh 		return;
62998245472cSJasvinder Singh 	}
63008245472cSJasvinder Singh 
630125961ff3SJasvinder Singh 	if (strcmp(tokens[0], "tmgr") == 0) {
630225961ff3SJasvinder Singh 		if ((n_tokens >= 3) &&
630325961ff3SJasvinder Singh 			(strcmp(tokens[1], "subport") == 0) &&
630425961ff3SJasvinder Singh 			(strcmp(tokens[2], "profile") == 0)) {
630525961ff3SJasvinder Singh 			cmd_tmgr_subport_profile(tokens, n_tokens,
630625961ff3SJasvinder Singh 				out, out_size);
630725961ff3SJasvinder Singh 			return;
630825961ff3SJasvinder Singh 		}
630925961ff3SJasvinder Singh 
631025961ff3SJasvinder Singh 		if ((n_tokens >= 3) &&
631125961ff3SJasvinder Singh 			(strcmp(tokens[1], "pipe") == 0) &&
631225961ff3SJasvinder Singh 			(strcmp(tokens[2], "profile") == 0)) {
631325961ff3SJasvinder Singh 			cmd_tmgr_pipe_profile(tokens, n_tokens, out, out_size);
631425961ff3SJasvinder Singh 			return;
631525961ff3SJasvinder Singh 		}
631625961ff3SJasvinder Singh 
631725961ff3SJasvinder Singh 		if ((n_tokens >= 5) &&
631825961ff3SJasvinder Singh 			(strcmp(tokens[2], "subport") == 0) &&
631925961ff3SJasvinder Singh 			(strcmp(tokens[4], "profile") == 0)) {
632025961ff3SJasvinder Singh 			cmd_tmgr_subport(tokens, n_tokens, out, out_size);
632125961ff3SJasvinder Singh 			return;
632225961ff3SJasvinder Singh 		}
632325961ff3SJasvinder Singh 
632425961ff3SJasvinder Singh 		if ((n_tokens >= 5) &&
632525961ff3SJasvinder Singh 			(strcmp(tokens[2], "subport") == 0) &&
632625961ff3SJasvinder Singh 			(strcmp(tokens[4], "pipe") == 0)) {
632725961ff3SJasvinder Singh 			cmd_tmgr_subport_pipe(tokens, n_tokens, out, out_size);
632825961ff3SJasvinder Singh 			return;
632925961ff3SJasvinder Singh 		}
633025961ff3SJasvinder Singh 
633125961ff3SJasvinder Singh 		cmd_tmgr(tokens, n_tokens, out, out_size);
633225961ff3SJasvinder Singh 		return;
633325961ff3SJasvinder Singh 	}
633425961ff3SJasvinder Singh 
63352f74ae28SJasvinder Singh 	if (strcmp(tokens[0], "tap") == 0) {
63362f74ae28SJasvinder Singh 		cmd_tap(tokens, n_tokens, out, out_size);
63372f74ae28SJasvinder Singh 		return;
63382f74ae28SJasvinder Singh 	}
63392f74ae28SJasvinder Singh 
63401edccebcSFan Zhang 	if (strcmp(tokens[0], "cryptodev") == 0) {
63411edccebcSFan Zhang 		cmd_cryptodev(tokens, n_tokens, out, out_size);
63421edccebcSFan Zhang 		return;
63431edccebcSFan Zhang 	}
63441edccebcSFan Zhang 
634571937434SJasvinder Singh 	if (strcmp(tokens[0], "port") == 0) {
634671937434SJasvinder Singh 		cmd_port_in_action_profile(tokens, n_tokens, out, out_size);
634771937434SJasvinder Singh 		return;
634871937434SJasvinder Singh 	}
634971937434SJasvinder Singh 
635071937434SJasvinder Singh 	if (strcmp(tokens[0], "table") == 0) {
635171937434SJasvinder Singh 		cmd_table_action_profile(tokens, n_tokens, out, out_size);
635271937434SJasvinder Singh 		return;
635371937434SJasvinder Singh 	}
635471937434SJasvinder Singh 
6355d75c371eSJasvinder Singh 	if (strcmp(tokens[0], "pipeline") == 0) {
6356d75c371eSJasvinder Singh 		if ((n_tokens >= 3) &&
6357d75c371eSJasvinder Singh 			(strcmp(tokens[2], "period") == 0)) {
6358d75c371eSJasvinder Singh 			cmd_pipeline(tokens, n_tokens, out, out_size);
6359d75c371eSJasvinder Singh 			return;
6360d75c371eSJasvinder Singh 		}
6361d75c371eSJasvinder Singh 
6362d75c371eSJasvinder Singh 		if ((n_tokens >= 5) &&
6363d75c371eSJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
6364d75c371eSJasvinder Singh 			(strcmp(tokens[3], "in") == 0) &&
6365d75c371eSJasvinder Singh 			(strcmp(tokens[4], "bsz") == 0)) {
6366d75c371eSJasvinder Singh 			cmd_pipeline_port_in(tokens, n_tokens, out, out_size);
6367d75c371eSJasvinder Singh 			return;
6368d75c371eSJasvinder Singh 		}
6369d75c371eSJasvinder Singh 
6370d75c371eSJasvinder Singh 		if ((n_tokens >= 5) &&
6371d75c371eSJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
6372d75c371eSJasvinder Singh 			(strcmp(tokens[3], "out") == 0) &&
6373d75c371eSJasvinder Singh 			(strcmp(tokens[4], "bsz") == 0)) {
6374d75c371eSJasvinder Singh 			cmd_pipeline_port_out(tokens, n_tokens, out, out_size);
6375d75c371eSJasvinder Singh 			return;
6376d75c371eSJasvinder Singh 		}
6377d75c371eSJasvinder Singh 
6378d75c371eSJasvinder Singh 		if ((n_tokens >= 4) &&
6379d75c371eSJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6380d75c371eSJasvinder Singh 			(strcmp(tokens[3], "match") == 0)) {
6381d75c371eSJasvinder Singh 			cmd_pipeline_table(tokens, n_tokens, out, out_size);
6382d75c371eSJasvinder Singh 			return;
6383d75c371eSJasvinder Singh 		}
6384d75c371eSJasvinder Singh 
6385d75c371eSJasvinder Singh 		if ((n_tokens >= 6) &&
6386d75c371eSJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
6387d75c371eSJasvinder Singh 			(strcmp(tokens[3], "in") == 0) &&
6388d75c371eSJasvinder Singh 			(strcmp(tokens[5], "table") == 0)) {
6389d75c371eSJasvinder Singh 			cmd_pipeline_port_in_table(tokens, n_tokens,
6390d75c371eSJasvinder Singh 				out, out_size);
6391d75c371eSJasvinder Singh 			return;
6392d75c371eSJasvinder Singh 		}
63936b1b3c3cSJasvinder Singh 
63946b1b3c3cSJasvinder Singh 		if ((n_tokens >= 6) &&
63956b1b3c3cSJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
63966b1b3c3cSJasvinder Singh 			(strcmp(tokens[3], "in") == 0) &&
639750e73d05SJasvinder Singh 			(strcmp(tokens[5], "stats") == 0)) {
639850e73d05SJasvinder Singh 			cmd_pipeline_port_in_stats(tokens, n_tokens,
639950e73d05SJasvinder Singh 				out, out_size);
640050e73d05SJasvinder Singh 			return;
640150e73d05SJasvinder Singh 		}
640250e73d05SJasvinder Singh 
640350e73d05SJasvinder Singh 		if ((n_tokens >= 6) &&
640450e73d05SJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
640550e73d05SJasvinder Singh 			(strcmp(tokens[3], "in") == 0) &&
64066b1b3c3cSJasvinder Singh 			(strcmp(tokens[5], "enable") == 0)) {
64076b1b3c3cSJasvinder Singh 			cmd_pipeline_port_in_enable(tokens, n_tokens,
64086b1b3c3cSJasvinder Singh 				out, out_size);
64096b1b3c3cSJasvinder Singh 			return;
64106b1b3c3cSJasvinder Singh 		}
64116b1b3c3cSJasvinder Singh 
64126b1b3c3cSJasvinder Singh 		if ((n_tokens >= 6) &&
64136b1b3c3cSJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
64146b1b3c3cSJasvinder Singh 			(strcmp(tokens[3], "in") == 0) &&
64156b1b3c3cSJasvinder Singh 			(strcmp(tokens[5], "disable") == 0)) {
64166b1b3c3cSJasvinder Singh 			cmd_pipeline_port_in_disable(tokens, n_tokens,
64176b1b3c3cSJasvinder Singh 				out, out_size);
64186b1b3c3cSJasvinder Singh 			return;
64196b1b3c3cSJasvinder Singh 		}
642050e73d05SJasvinder Singh 
642150e73d05SJasvinder Singh 		if ((n_tokens >= 6) &&
642250e73d05SJasvinder Singh 			(strcmp(tokens[2], "port") == 0) &&
642350e73d05SJasvinder Singh 			(strcmp(tokens[3], "out") == 0) &&
642450e73d05SJasvinder Singh 			(strcmp(tokens[5], "stats") == 0)) {
642550e73d05SJasvinder Singh 			cmd_pipeline_port_out_stats(tokens, n_tokens,
642650e73d05SJasvinder Singh 				out, out_size);
642750e73d05SJasvinder Singh 			return;
642850e73d05SJasvinder Singh 		}
642950e73d05SJasvinder Singh 
643050e73d05SJasvinder Singh 		if ((n_tokens >= 5) &&
643150e73d05SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
643250e73d05SJasvinder Singh 			(strcmp(tokens[4], "stats") == 0)) {
643350e73d05SJasvinder Singh 			cmd_pipeline_table_stats(tokens, n_tokens,
643450e73d05SJasvinder Singh 				out, out_size);
643550e73d05SJasvinder Singh 			return;
643650e73d05SJasvinder Singh 		}
6437a3a95b7dSJasvinder Singh 
6438a3a95b7dSJasvinder Singh 		if ((n_tokens >= 7) &&
6439a3a95b7dSJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6440a3a95b7dSJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
6441a3a95b7dSJasvinder Singh 			(strcmp(tokens[5], "add") == 0) &&
6442a3a95b7dSJasvinder Singh 			(strcmp(tokens[6], "match") == 0)) {
6443a3a95b7dSJasvinder Singh 			if ((n_tokens >= 8) &&
6444a3a95b7dSJasvinder Singh 				(strcmp(tokens[7], "default") == 0)) {
6445a3a95b7dSJasvinder Singh 				cmd_pipeline_table_rule_add_default(tokens,
6446a3a95b7dSJasvinder Singh 					n_tokens, out, out_size);
6447a3a95b7dSJasvinder Singh 				return;
6448a3a95b7dSJasvinder Singh 			}
6449a3a95b7dSJasvinder Singh 
6450a3a95b7dSJasvinder Singh 			cmd_pipeline_table_rule_add(tokens, n_tokens,
6451a3a95b7dSJasvinder Singh 				out, out_size);
6452a3a95b7dSJasvinder Singh 			return;
6453a3a95b7dSJasvinder Singh 		}
6454f634e4c5SJasvinder Singh 
6455f634e4c5SJasvinder Singh 		if ((n_tokens >= 7) &&
6456f634e4c5SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6457f634e4c5SJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
64583186282fSJasvinder Singh 			(strcmp(tokens[5], "add") == 0) &&
64593186282fSJasvinder Singh 			(strcmp(tokens[6], "bulk") == 0)) {
64603186282fSJasvinder Singh 			cmd_pipeline_table_rule_add_bulk(tokens,
64613186282fSJasvinder Singh 				n_tokens, out, out_size);
64623186282fSJasvinder Singh 			return;
64633186282fSJasvinder Singh 		}
64643186282fSJasvinder Singh 
64653186282fSJasvinder Singh 		if ((n_tokens >= 7) &&
64663186282fSJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
64673186282fSJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
6468f634e4c5SJasvinder Singh 			(strcmp(tokens[5], "delete") == 0) &&
6469f634e4c5SJasvinder Singh 			(strcmp(tokens[6], "match") == 0)) {
6470f634e4c5SJasvinder Singh 			if ((n_tokens >= 8) &&
6471f634e4c5SJasvinder Singh 				(strcmp(tokens[7], "default") == 0)) {
6472f634e4c5SJasvinder Singh 				cmd_pipeline_table_rule_delete_default(tokens,
6473f634e4c5SJasvinder Singh 					n_tokens, out, out_size);
6474f634e4c5SJasvinder Singh 				return;
6475f634e4c5SJasvinder Singh 				}
6476f634e4c5SJasvinder Singh 
6477f634e4c5SJasvinder Singh 			cmd_pipeline_table_rule_delete(tokens, n_tokens,
6478f634e4c5SJasvinder Singh 				out, out_size);
6479f634e4c5SJasvinder Singh 			return;
6480f634e4c5SJasvinder Singh 		}
6481c64b9121SJasvinder Singh 
64822fbdf834SCristian Dumitrescu 		if ((n_tokens >= 6) &&
64832fbdf834SCristian Dumitrescu 			(strcmp(tokens[2], "table") == 0) &&
64842fbdf834SCristian Dumitrescu 			(strcmp(tokens[4], "rule") == 0) &&
64852fbdf834SCristian Dumitrescu 			(strcmp(tokens[5], "show") == 0)) {
64862fbdf834SCristian Dumitrescu 			cmd_pipeline_table_rule_show(tokens, n_tokens,
64872fbdf834SCristian Dumitrescu 				out, out_size);
64882fbdf834SCristian Dumitrescu 			return;
64892fbdf834SCristian Dumitrescu 		}
64902fbdf834SCristian Dumitrescu 
6491c64b9121SJasvinder Singh 		if ((n_tokens >= 7) &&
6492c64b9121SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6493c64b9121SJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
6494c64b9121SJasvinder Singh 			(strcmp(tokens[5], "read") == 0) &&
6495c64b9121SJasvinder Singh 			(strcmp(tokens[6], "stats") == 0)) {
6496c64b9121SJasvinder Singh 			cmd_pipeline_table_rule_stats_read(tokens, n_tokens,
6497c64b9121SJasvinder Singh 				out, out_size);
6498c64b9121SJasvinder Singh 			return;
6499c64b9121SJasvinder Singh 		}
65007e11393eSJasvinder Singh 
65017e11393eSJasvinder Singh 		if ((n_tokens >= 8) &&
65027e11393eSJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
65037e11393eSJasvinder Singh 			(strcmp(tokens[4], "meter") == 0) &&
65047e11393eSJasvinder Singh 			(strcmp(tokens[5], "profile") == 0) &&
65057e11393eSJasvinder Singh 			(strcmp(tokens[7], "add") == 0)) {
65067e11393eSJasvinder Singh 			cmd_pipeline_table_meter_profile_add(tokens, n_tokens,
65077e11393eSJasvinder Singh 				out, out_size);
65087e11393eSJasvinder Singh 			return;
65097e11393eSJasvinder Singh 		}
65107e11393eSJasvinder Singh 
65117e11393eSJasvinder Singh 		if ((n_tokens >= 8) &&
65127e11393eSJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
65137e11393eSJasvinder Singh 			(strcmp(tokens[4], "meter") == 0) &&
65147e11393eSJasvinder Singh 			(strcmp(tokens[5], "profile") == 0) &&
65157e11393eSJasvinder Singh 			(strcmp(tokens[7], "delete") == 0)) {
65167e11393eSJasvinder Singh 			cmd_pipeline_table_meter_profile_delete(tokens,
65177e11393eSJasvinder Singh 				n_tokens, out, out_size);
65187e11393eSJasvinder Singh 			return;
65197e11393eSJasvinder Singh 		}
6520e92058d6SJasvinder Singh 
6521e92058d6SJasvinder Singh 		if ((n_tokens >= 7) &&
6522e92058d6SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6523e92058d6SJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
6524e92058d6SJasvinder Singh 			(strcmp(tokens[5], "read") == 0) &&
6525e92058d6SJasvinder Singh 			(strcmp(tokens[6], "meter") == 0)) {
6526e92058d6SJasvinder Singh 			cmd_pipeline_table_rule_meter_read(tokens, n_tokens,
6527e92058d6SJasvinder Singh 				out, out_size);
6528e92058d6SJasvinder Singh 			return;
6529e92058d6SJasvinder Singh 		}
65302b82ef48SJasvinder Singh 
65312b82ef48SJasvinder Singh 		if ((n_tokens >= 5) &&
65322b82ef48SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
65332b82ef48SJasvinder Singh 			(strcmp(tokens[4], "dscp") == 0)) {
65342b82ef48SJasvinder Singh 			cmd_pipeline_table_dscp(tokens, n_tokens,
65352b82ef48SJasvinder Singh 				out, out_size);
65362b82ef48SJasvinder Singh 			return;
65372b82ef48SJasvinder Singh 		}
6538d0d306c7SJasvinder Singh 
6539d0d306c7SJasvinder Singh 		if ((n_tokens >= 7) &&
6540d0d306c7SJasvinder Singh 			(strcmp(tokens[2], "table") == 0) &&
6541d0d306c7SJasvinder Singh 			(strcmp(tokens[4], "rule") == 0) &&
6542d0d306c7SJasvinder Singh 			(strcmp(tokens[5], "read") == 0) &&
6543d0d306c7SJasvinder Singh 			(strcmp(tokens[6], "ttl") == 0)) {
6544d0d306c7SJasvinder Singh 			cmd_pipeline_table_rule_ttl_read(tokens, n_tokens,
6545d0d306c7SJasvinder Singh 				out, out_size);
6546d0d306c7SJasvinder Singh 			return;
6547d0d306c7SJasvinder Singh 		}
6548a3169ee5SCristian Dumitrescu 
6549a3169ee5SCristian Dumitrescu 		if ((n_tokens >= 7) &&
6550a3169ee5SCristian Dumitrescu 			(strcmp(tokens[2], "table") == 0) &&
6551a3169ee5SCristian Dumitrescu 			(strcmp(tokens[4], "rule") == 0) &&
6552a3169ee5SCristian Dumitrescu 			(strcmp(tokens[5], "read") == 0) &&
6553a3169ee5SCristian Dumitrescu 			(strcmp(tokens[6], "time") == 0)) {
6554a3169ee5SCristian Dumitrescu 			cmd_pipeline_table_rule_time_read(tokens, n_tokens,
6555a3169ee5SCristian Dumitrescu 				out, out_size);
6556a3169ee5SCristian Dumitrescu 			return;
6557a3169ee5SCristian Dumitrescu 		}
6558d75c371eSJasvinder Singh 	}
6559d75c371eSJasvinder Singh 
656032e5d9b1SJasvinder Singh 	if (strcmp(tokens[0], "thread") == 0) {
656132e5d9b1SJasvinder Singh 		if ((n_tokens >= 5) &&
656232e5d9b1SJasvinder Singh 			(strcmp(tokens[4], "enable") == 0)) {
656332e5d9b1SJasvinder Singh 			cmd_thread_pipeline_enable(tokens, n_tokens,
656432e5d9b1SJasvinder Singh 				out, out_size);
656532e5d9b1SJasvinder Singh 			return;
656632e5d9b1SJasvinder Singh 		}
656732e5d9b1SJasvinder Singh 
656832e5d9b1SJasvinder Singh 		if ((n_tokens >= 5) &&
656932e5d9b1SJasvinder Singh 			(strcmp(tokens[4], "disable") == 0)) {
657032e5d9b1SJasvinder Singh 			cmd_thread_pipeline_disable(tokens, n_tokens,
657132e5d9b1SJasvinder Singh 				out, out_size);
657232e5d9b1SJasvinder Singh 			return;
657332e5d9b1SJasvinder Singh 		}
657432e5d9b1SJasvinder Singh 	}
657532e5d9b1SJasvinder Singh 
65766bfe74f8SJasvinder Singh 	snprintf(out, out_size, MSG_CMD_UNKNOWN, tokens[0]);
65774bbf8e30SJasvinder Singh }
65784bbf8e30SJasvinder Singh 
65794bbf8e30SJasvinder Singh int
65804bbf8e30SJasvinder Singh cli_script_process(const char *file_name,
65814bbf8e30SJasvinder Singh 	size_t msg_in_len_max,
65824bbf8e30SJasvinder Singh 	size_t msg_out_len_max)
65834bbf8e30SJasvinder Singh {
65844bbf8e30SJasvinder Singh 	char *msg_in = NULL, *msg_out = NULL;
65854bbf8e30SJasvinder Singh 	FILE *f = NULL;
65864bbf8e30SJasvinder Singh 
65874bbf8e30SJasvinder Singh 	/* Check input arguments */
65884bbf8e30SJasvinder Singh 	if ((file_name == NULL) ||
65894bbf8e30SJasvinder Singh 		(strlen(file_name) == 0) ||
65904bbf8e30SJasvinder Singh 		(msg_in_len_max == 0) ||
65914bbf8e30SJasvinder Singh 		(msg_out_len_max == 0))
65924bbf8e30SJasvinder Singh 		return -EINVAL;
65934bbf8e30SJasvinder Singh 
65944bbf8e30SJasvinder Singh 	msg_in = malloc(msg_in_len_max + 1);
65954bbf8e30SJasvinder Singh 	msg_out = malloc(msg_out_len_max + 1);
65964bbf8e30SJasvinder Singh 	if ((msg_in == NULL) ||
65974bbf8e30SJasvinder Singh 		(msg_out == NULL)) {
65984bbf8e30SJasvinder Singh 		free(msg_out);
65994bbf8e30SJasvinder Singh 		free(msg_in);
66004bbf8e30SJasvinder Singh 		return -ENOMEM;
66014bbf8e30SJasvinder Singh 	}
66024bbf8e30SJasvinder Singh 
66034bbf8e30SJasvinder Singh 	/* Open input file */
66044bbf8e30SJasvinder Singh 	f = fopen(file_name, "r");
66054bbf8e30SJasvinder Singh 	if (f == NULL) {
66064bbf8e30SJasvinder Singh 		free(msg_out);
66074bbf8e30SJasvinder Singh 		free(msg_in);
66084bbf8e30SJasvinder Singh 		return -EIO;
66094bbf8e30SJasvinder Singh 	}
66104bbf8e30SJasvinder Singh 
66114bbf8e30SJasvinder Singh 	/* Read file */
66124bbf8e30SJasvinder Singh 	for ( ; ; ) {
66134bbf8e30SJasvinder Singh 		if (fgets(msg_in, msg_in_len_max + 1, f) == NULL)
66144bbf8e30SJasvinder Singh 			break;
66154bbf8e30SJasvinder Singh 
66164bbf8e30SJasvinder Singh 		printf("%s", msg_in);
66174bbf8e30SJasvinder Singh 		msg_out[0] = 0;
66184bbf8e30SJasvinder Singh 
66194bbf8e30SJasvinder Singh 		cli_process(msg_in,
66204bbf8e30SJasvinder Singh 			msg_out,
66214bbf8e30SJasvinder Singh 			msg_out_len_max);
66224bbf8e30SJasvinder Singh 
66234bbf8e30SJasvinder Singh 		if (strlen(msg_out))
66244bbf8e30SJasvinder Singh 			printf("%s", msg_out);
66254bbf8e30SJasvinder Singh 	}
66264bbf8e30SJasvinder Singh 
66274bbf8e30SJasvinder Singh 	/* Close file */
66284bbf8e30SJasvinder Singh 	fclose(f);
66294bbf8e30SJasvinder Singh 	free(msg_out);
66304bbf8e30SJasvinder Singh 	free(msg_in);
66314bbf8e30SJasvinder Singh 	return 0;
66324bbf8e30SJasvinder Singh }
66333186282fSJasvinder Singh 
66343186282fSJasvinder Singh static int
66353186282fSJasvinder Singh cli_rule_file_process(const char *file_name,
66363186282fSJasvinder Singh 	size_t line_len_max,
663727b333b2SCristian Dumitrescu 	struct table_rule_list **rule_list,
66383186282fSJasvinder Singh 	uint32_t *n_rules,
66393186282fSJasvinder Singh 	uint32_t *line_number,
66403186282fSJasvinder Singh 	char *out,
66413186282fSJasvinder Singh 	size_t out_size)
66423186282fSJasvinder Singh {
664327b333b2SCristian Dumitrescu 	struct table_rule_list *list = NULL;
66443186282fSJasvinder Singh 	char *line = NULL;
664527b333b2SCristian Dumitrescu 	FILE *f = NULL;
664627b333b2SCristian Dumitrescu 	uint32_t rule_id = 0, line_id = 0;
66473186282fSJasvinder Singh 	int status = 0;
66483186282fSJasvinder Singh 
66493186282fSJasvinder Singh 	/* Check input arguments */
66503186282fSJasvinder Singh 	if ((file_name == NULL) ||
66513186282fSJasvinder Singh 		(strlen(file_name) == 0) ||
665227b333b2SCristian Dumitrescu 		(line_len_max == 0) ||
665327b333b2SCristian Dumitrescu 		(rule_list == NULL) ||
665427b333b2SCristian Dumitrescu 		(n_rules == NULL) ||
665527b333b2SCristian Dumitrescu 		(line_number == NULL) ||
665627b333b2SCristian Dumitrescu 		(out == NULL)) {
665727b333b2SCristian Dumitrescu 		status = -EINVAL;
665827b333b2SCristian Dumitrescu 		goto cli_rule_file_process_free;
66593186282fSJasvinder Singh 	}
66603186282fSJasvinder Singh 
66613186282fSJasvinder Singh 	/* Memory allocation */
666227b333b2SCristian Dumitrescu 	list = malloc(sizeof(struct table_rule_list));
666327b333b2SCristian Dumitrescu 	if (list == NULL) {
666427b333b2SCristian Dumitrescu 		status = -ENOMEM;
666527b333b2SCristian Dumitrescu 		goto cli_rule_file_process_free;
666627b333b2SCristian Dumitrescu 	}
666727b333b2SCristian Dumitrescu 
666827b333b2SCristian Dumitrescu 	TAILQ_INIT(list);
666927b333b2SCristian Dumitrescu 
66703186282fSJasvinder Singh 	line = malloc(line_len_max + 1);
66713186282fSJasvinder Singh 	if (line == NULL) {
667227b333b2SCristian Dumitrescu 		status = -ENOMEM;
667327b333b2SCristian Dumitrescu 		goto cli_rule_file_process_free;
66743186282fSJasvinder Singh 	}
66753186282fSJasvinder Singh 
66763186282fSJasvinder Singh 	/* Open file */
66773186282fSJasvinder Singh 	f = fopen(file_name, "r");
66783186282fSJasvinder Singh 	if (f == NULL) {
667927b333b2SCristian Dumitrescu 		status = -EIO;
668027b333b2SCristian Dumitrescu 		goto cli_rule_file_process_free;
66813186282fSJasvinder Singh 	}
66823186282fSJasvinder Singh 
66833186282fSJasvinder Singh 	/* Read file */
668427b333b2SCristian Dumitrescu 	for (line_id = 1, rule_id = 0; ; line_id++) {
66853186282fSJasvinder Singh 		char *tokens[CMD_MAX_TOKENS];
668627b333b2SCristian Dumitrescu 		struct table_rule *rule = NULL;
66873186282fSJasvinder Singh 		uint32_t n_tokens, n_tokens_parsed, t0;
66883186282fSJasvinder Singh 
66893186282fSJasvinder Singh 		/* Read next line from file. */
66903186282fSJasvinder Singh 		if (fgets(line, line_len_max + 1, f) == NULL)
66913186282fSJasvinder Singh 			break;
66923186282fSJasvinder Singh 
66933186282fSJasvinder Singh 		/* Comment. */
66943186282fSJasvinder Singh 		if (is_comment(line))
66953186282fSJasvinder Singh 			continue;
66963186282fSJasvinder Singh 
66973186282fSJasvinder Singh 		/* Parse line. */
66983186282fSJasvinder Singh 		n_tokens = RTE_DIM(tokens);
66993186282fSJasvinder Singh 		status = parse_tokenize_string(line, tokens, &n_tokens);
67003186282fSJasvinder Singh 		if (status) {
67013186282fSJasvinder Singh 			status = -EINVAL;
670227b333b2SCristian Dumitrescu 			goto cli_rule_file_process_free;
67033186282fSJasvinder Singh 		}
67043186282fSJasvinder Singh 
67053186282fSJasvinder Singh 		/* Empty line. */
67063186282fSJasvinder Singh 		if (n_tokens == 0)
67073186282fSJasvinder Singh 			continue;
67083186282fSJasvinder Singh 		t0 = 0;
67093186282fSJasvinder Singh 
671027b333b2SCristian Dumitrescu 		/* Rule alloc and insert. */
671127b333b2SCristian Dumitrescu 		rule = calloc(1, sizeof(struct table_rule));
671227b333b2SCristian Dumitrescu 		if (rule == NULL) {
671327b333b2SCristian Dumitrescu 			status = -ENOMEM;
671427b333b2SCristian Dumitrescu 			goto cli_rule_file_process_free;
671527b333b2SCristian Dumitrescu 		}
671627b333b2SCristian Dumitrescu 
671727b333b2SCristian Dumitrescu 		TAILQ_INSERT_TAIL(list, rule, node);
671827b333b2SCristian Dumitrescu 
67193186282fSJasvinder Singh 		/* Rule match. */
67203186282fSJasvinder Singh 		n_tokens_parsed = parse_match(tokens + t0,
67213186282fSJasvinder Singh 			n_tokens - t0,
67223186282fSJasvinder Singh 			out,
67233186282fSJasvinder Singh 			out_size,
672427b333b2SCristian Dumitrescu 			&rule->match);
67253186282fSJasvinder Singh 		if (n_tokens_parsed == 0) {
67263186282fSJasvinder Singh 			status = -EINVAL;
672727b333b2SCristian Dumitrescu 			goto cli_rule_file_process_free;
67283186282fSJasvinder Singh 		}
67293186282fSJasvinder Singh 		t0 += n_tokens_parsed;
67303186282fSJasvinder Singh 
67313186282fSJasvinder Singh 		/* Rule action. */
67323186282fSJasvinder Singh 		n_tokens_parsed = parse_table_action(tokens + t0,
67333186282fSJasvinder Singh 			n_tokens - t0,
67343186282fSJasvinder Singh 			out,
67353186282fSJasvinder Singh 			out_size,
673627b333b2SCristian Dumitrescu 			&rule->action);
67373186282fSJasvinder Singh 		if (n_tokens_parsed == 0) {
67383186282fSJasvinder Singh 			status = -EINVAL;
673927b333b2SCristian Dumitrescu 			goto cli_rule_file_process_free;
67403186282fSJasvinder Singh 		}
67413186282fSJasvinder Singh 		t0 += n_tokens_parsed;
67423186282fSJasvinder Singh 
67433186282fSJasvinder Singh 		/* Line completed. */
67443186282fSJasvinder Singh 		if (t0 < n_tokens) {
67453186282fSJasvinder Singh 			status = -EINVAL;
674627b333b2SCristian Dumitrescu 			goto cli_rule_file_process_free;
67473186282fSJasvinder Singh 		}
67483186282fSJasvinder Singh 
67493186282fSJasvinder Singh 		/* Increment rule count */
67503186282fSJasvinder Singh 		rule_id++;
67513186282fSJasvinder Singh 	}
67523186282fSJasvinder Singh 
67533186282fSJasvinder Singh 	/* Close file */
67543186282fSJasvinder Singh 	fclose(f);
67553186282fSJasvinder Singh 
67563186282fSJasvinder Singh 	/* Memory free */
67573186282fSJasvinder Singh 	free(line);
67583186282fSJasvinder Singh 
675927b333b2SCristian Dumitrescu 	*rule_list = list;
67603186282fSJasvinder Singh 	*n_rules = rule_id;
67613186282fSJasvinder Singh 	*line_number = line_id;
676227b333b2SCristian Dumitrescu 	return 0;
676327b333b2SCristian Dumitrescu 
676427b333b2SCristian Dumitrescu cli_rule_file_process_free:
6765c44ae27aSJasvinder Singh 	if (rule_list != NULL)
676627b333b2SCristian Dumitrescu 		*rule_list = NULL;
6767c44ae27aSJasvinder Singh 
6768c44ae27aSJasvinder Singh 	if (n_rules != NULL)
676927b333b2SCristian Dumitrescu 		*n_rules = rule_id;
6770c44ae27aSJasvinder Singh 
6771c44ae27aSJasvinder Singh 	if (line_number != NULL)
677227b333b2SCristian Dumitrescu 		*line_number = line_id;
677327b333b2SCristian Dumitrescu 
6774c44ae27aSJasvinder Singh 	if (list != NULL)
677527b333b2SCristian Dumitrescu 		for ( ; ; ) {
677627b333b2SCristian Dumitrescu 			struct table_rule *rule;
677727b333b2SCristian Dumitrescu 
677827b333b2SCristian Dumitrescu 			rule = TAILQ_FIRST(list);
677927b333b2SCristian Dumitrescu 			if (rule == NULL)
678027b333b2SCristian Dumitrescu 				break;
678127b333b2SCristian Dumitrescu 
678227b333b2SCristian Dumitrescu 			TAILQ_REMOVE(list, rule, node);
678327b333b2SCristian Dumitrescu 			free(rule);
678427b333b2SCristian Dumitrescu 		}
678527b333b2SCristian Dumitrescu 
678627b333b2SCristian Dumitrescu 	if (f)
678727b333b2SCristian Dumitrescu 		fclose(f);
678827b333b2SCristian Dumitrescu 	free(line);
678927b333b2SCristian Dumitrescu 	free(list);
679027b333b2SCristian Dumitrescu 
67913186282fSJasvinder Singh 	return status;
67923186282fSJasvinder Singh }
6793