xref: /dpdk/app/test-pmd/cmdline_tm.c (revision c7e9729d)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4 
5 #include <cmdline_parse.h>
6 #include <cmdline_parse_num.h>
7 #include <cmdline_parse_string.h>
8 
9 #include <rte_ethdev.h>
10 #include <rte_flow.h>
11 #include <rte_tm.h>
12 
13 #include "testpmd.h"
14 #include "cmdline_tm.h"
15 
16 #define PARSE_DELIMITER				" \f\n\r\t\v"
17 #define MAX_NUM_SHARED_SHAPERS		256
18 
19 #define skip_white_spaces(pos)			\
20 ({						\
21 	__typeof__(pos) _p = (pos);		\
22 	for ( ; isspace(*_p); _p++)		\
23 		;				\
24 	_p;					\
25 })
26 
27 /** Display TM Error Message */
28 static void
29 print_err_msg(struct rte_tm_error *error)
30 {
31 	static const char *const errstrlist[] = {
32 		[RTE_TM_ERROR_TYPE_NONE] = "no error",
33 		[RTE_TM_ERROR_TYPE_UNSPECIFIED] = "cause unspecified",
34 		[RTE_TM_ERROR_TYPE_CAPABILITIES]
35 			= "capability parameter null",
36 		[RTE_TM_ERROR_TYPE_LEVEL_ID] = "level id",
37 		[RTE_TM_ERROR_TYPE_WRED_PROFILE]
38 			= "wred profile null",
39 		[RTE_TM_ERROR_TYPE_WRED_PROFILE_GREEN] = "wred profile(green)",
40 		[RTE_TM_ERROR_TYPE_WRED_PROFILE_YELLOW]
41 			= "wred profile(yellow)",
42 		[RTE_TM_ERROR_TYPE_WRED_PROFILE_RED] = "wred profile(red)",
43 		[RTE_TM_ERROR_TYPE_WRED_PROFILE_ID] = "wred profile id",
44 		[RTE_TM_ERROR_TYPE_SHARED_WRED_CONTEXT_ID]
45 			= "shared wred context id",
46 		[RTE_TM_ERROR_TYPE_SHAPER_PROFILE] = "shaper profile null",
47 		[RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE]
48 			= "committed rate field (shaper profile)",
49 		[RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE]
50 			= "committed size field (shaper profile)",
51 		[RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_RATE]
52 			= "peak rate field (shaper profile)",
53 		[RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE]
54 			= "peak size field (shaper profile)",
55 		[RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN]
56 			= "packet adjust length field (shaper profile)",
57 		[RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID] = "shaper profile id",
58 		[RTE_TM_ERROR_TYPE_SHARED_SHAPER_ID] = "shared shaper id",
59 		[RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID] = "parent node id",
60 		[RTE_TM_ERROR_TYPE_NODE_PRIORITY] = "node priority",
61 		[RTE_TM_ERROR_TYPE_NODE_WEIGHT] = "node weight",
62 		[RTE_TM_ERROR_TYPE_NODE_PARAMS] = "node parameter null",
63 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID]
64 			= "shaper profile id field (node params)",
65 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID]
66 			= "shared shaper id field (node params)",
67 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS]
68 			= "num shared shapers field (node params)",
69 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE]
70 			= "wfq weght mode field (node params)",
71 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES]
72 			= "num strict priorities field (node params)",
73 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN]
74 			= "congestion management mode field (node params)",
75 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID] =
76 			"wred profile id field (node params)",
77 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID]
78 			= "shared wred context id field (node params)",
79 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS]
80 			= "num shared wred contexts field (node params)",
81 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS]
82 			= "stats field (node params)",
83 		[RTE_TM_ERROR_TYPE_NODE_ID] = "node id",
84 	};
85 
86 	const char *errstr;
87 	char buf[64];
88 
89 	if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
90 		!errstrlist[error->type])
91 		errstr = "unknown type";
92 	else
93 		errstr = errstrlist[error->type];
94 
95 	if (error->cause)
96 		snprintf(buf, sizeof(buf), "cause: %p, ", error->cause);
97 
98 	printf("%s: %s%s (error %d)\n", errstr, error->cause ? buf : "",
99 		error->message ? error->message : "(no stated reason)",
100 		error->type);
101 }
102 
103 static int
104 read_uint64(uint64_t *value, const char *p)
105 {
106 	char *next;
107 	uint64_t val;
108 
109 	p = skip_white_spaces(p);
110 	if (!isdigit(*p))
111 		return -EINVAL;
112 
113 	val = strtoul(p, &next, 10);
114 	if (p == next)
115 		return -EINVAL;
116 
117 	p = next;
118 	switch (*p) {
119 	case 'T':
120 		val *= 1024ULL;
121 		/* fall through */
122 	case 'G':
123 		val *= 1024ULL;
124 		/* fall through */
125 	case 'M':
126 		val *= 1024ULL;
127 		/* fall through */
128 	case 'k':
129 	case 'K':
130 		val *= 1024ULL;
131 		p++;
132 		break;
133 	}
134 
135 	p = skip_white_spaces(p);
136 	if (*p != '\0')
137 		return -EINVAL;
138 
139 	*value = val;
140 	return 0;
141 }
142 
143 static int
144 read_uint32(uint32_t *value, const char *p)
145 {
146 	uint64_t val = 0;
147 	int ret = read_uint64(&val, p);
148 
149 	if (ret < 0)
150 		return ret;
151 
152 	if (val > UINT32_MAX)
153 		return -ERANGE;
154 
155 	*value = val;
156 	return 0;
157 }
158 
159 static int
160 parse_multi_ss_id_str(char *s_str, uint32_t *n_ssp, uint32_t shaper_id[])
161 {
162 	uint32_t n_shared_shapers = 0, i = 0;
163 	char *token;
164 
165 	/* First token: num of shared shapers */
166 	token = strtok_r(s_str, PARSE_DELIMITER, &s_str);
167 	if (token ==  NULL)
168 		return -1;
169 
170 	if (read_uint32(&n_shared_shapers, token))
171 		return -1;
172 
173 	/* Check: num of shared shaper */
174 	if (n_shared_shapers >= MAX_NUM_SHARED_SHAPERS) {
175 		printf(" Number of shared shapers exceed the max (error)\n");
176 		return -1;
177 	}
178 
179 	/* Parse shared shaper ids */
180 	while (1) {
181 		token = strtok_r(s_str, PARSE_DELIMITER, &s_str);
182 		if ((token !=  NULL && n_shared_shapers == 0) ||
183 			(token == NULL && i < n_shared_shapers))
184 			return -1;
185 
186 		if (token == NULL)
187 			break;
188 
189 		if (read_uint32(&shaper_id[i], token))
190 			return -1;
191 		i++;
192 	}
193 	*n_ssp = n_shared_shapers;
194 
195 	return 0;
196 }
197 /* *** Port TM Capability *** */
198 struct cmd_show_port_tm_cap_result {
199 	cmdline_fixed_string_t show;
200 	cmdline_fixed_string_t port;
201 	cmdline_fixed_string_t tm;
202 	cmdline_fixed_string_t cap;
203 	uint16_t port_id;
204 };
205 
206 cmdline_parse_token_string_t cmd_show_port_tm_cap_show =
207 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
208 		show, "show");
209 cmdline_parse_token_string_t cmd_show_port_tm_cap_port =
210 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
211 		port, "port");
212 cmdline_parse_token_string_t cmd_show_port_tm_cap_tm =
213 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
214 		tm, "tm");
215 cmdline_parse_token_string_t cmd_show_port_tm_cap_cap =
216 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
217 		cap, "cap");
218 cmdline_parse_token_num_t cmd_show_port_tm_cap_port_id =
219 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_cap_result,
220 		 port_id, UINT16);
221 
222 static void cmd_show_port_tm_cap_parsed(void *parsed_result,
223 	__attribute__((unused)) struct cmdline *cl,
224 	__attribute__((unused)) void *data)
225 {
226 	struct cmd_show_port_tm_cap_result *res = parsed_result;
227 	struct rte_tm_capabilities cap;
228 	struct rte_tm_error error;
229 	portid_t port_id = res->port_id;
230 	uint32_t i;
231 	int ret;
232 
233 	if (port_id_is_invalid(port_id, ENABLED_WARN))
234 		return;
235 
236 	memset(&cap, 0, sizeof(struct rte_tm_capabilities));
237 	ret = rte_tm_capabilities_get(port_id, &cap, &error);
238 	if (ret) {
239 		print_err_msg(&error);
240 		return;
241 	}
242 
243 	printf("\n****   Port TM Capabilities ****\n\n");
244 	printf("cap.n_nodes_max %" PRIu32 "\n", cap.n_nodes_max);
245 	printf("cap.n_levels_max %" PRIu32 "\n", cap.n_levels_max);
246 	printf("cap.non_leaf_nodes_identical %" PRId32 "\n",
247 		cap.non_leaf_nodes_identical);
248 	printf("cap.leaf_nodes_identical %" PRId32 "\n",
249 		cap.leaf_nodes_identical);
250 	printf("cap.shaper_n_max %u\n", cap.shaper_n_max);
251 	printf("cap.shaper_private_n_max %" PRIu32 "\n",
252 		cap.shaper_private_n_max);
253 	printf("cap.shaper_private_dual_rate_n_max %" PRId32 "\n",
254 		cap.shaper_private_dual_rate_n_max);
255 	printf("cap.shaper_private_rate_min %" PRIu64 "\n",
256 		cap.shaper_private_rate_min);
257 	printf("cap.shaper_private_rate_max %" PRIu64 "\n",
258 		cap.shaper_private_rate_max);
259 	printf("cap.shaper_shared_n_max %" PRIu32 "\n",
260 		cap.shaper_shared_n_max);
261 	printf("cap.shaper_shared_n_nodes_per_shaper_max %" PRIu32 "\n",
262 		cap.shaper_shared_n_nodes_per_shaper_max);
263 	printf("cap.shaper_shared_n_shapers_per_node_max %" PRIu32 "\n",
264 		cap.shaper_shared_n_shapers_per_node_max);
265 	printf("cap.shaper_shared_dual_rate_n_max %" PRIu32 "\n",
266 		cap.shaper_shared_dual_rate_n_max);
267 	printf("cap.shaper_shared_rate_min %" PRIu64 "\n",
268 		cap.shaper_shared_rate_min);
269 	printf("cap.shaper_shared_rate_max %" PRIu64 "\n",
270 		cap.shaper_shared_rate_max);
271 	printf("cap.shaper_pkt_length_adjust_min %" PRId32 "\n",
272 		cap.shaper_pkt_length_adjust_min);
273 	printf("cap.shaper_pkt_length_adjust_max %" PRId32 "\n",
274 		cap.shaper_pkt_length_adjust_max);
275 	printf("cap.sched_n_children_max %" PRIu32 "\n",
276 		cap.sched_n_children_max);
277 	printf("cap.sched_sp_n_priorities_max %" PRIu32 "\n",
278 		cap.sched_sp_n_priorities_max);
279 	printf("cap.sched_wfq_n_children_per_group_max %" PRIu32 "\n",
280 		cap.sched_wfq_n_children_per_group_max);
281 	printf("cap.sched_wfq_n_groups_max %" PRIu32 "\n",
282 		cap.sched_wfq_n_groups_max);
283 	printf("cap.sched_wfq_weight_max %" PRIu32 "\n",
284 		cap.sched_wfq_weight_max);
285 	printf("cap.cman_head_drop_supported %" PRId32 "\n",
286 		cap.cman_head_drop_supported);
287 	printf("cap.cman_wred_context_n_max %" PRIu32 "\n",
288 		cap.cman_wred_context_n_max);
289 	printf("cap.cman_wred_context_private_n_max %" PRIu32 "\n",
290 		cap.cman_wred_context_private_n_max);
291 	printf("cap.cman_wred_context_shared_n_max %" PRIu32 "\n",
292 		cap.cman_wred_context_shared_n_max);
293 	printf("cap.cman_wred_context_shared_n_nodes_per_context_max %" PRIu32
294 		"\n", cap.cman_wred_context_shared_n_nodes_per_context_max);
295 	printf("cap.cman_wred_context_shared_n_contexts_per_node_max %" PRIu32
296 		"\n", cap.cman_wred_context_shared_n_contexts_per_node_max);
297 
298 	for (i = 0; i < RTE_TM_COLORS; i++) {
299 		printf("cap.mark_vlan_dei_supported %" PRId32 "\n",
300 			cap.mark_vlan_dei_supported[i]);
301 		printf("cap.mark_ip_ecn_tcp_supported %" PRId32 "\n",
302 			cap.mark_ip_ecn_tcp_supported[i]);
303 		printf("cap.mark_ip_ecn_sctp_supported %" PRId32 "\n",
304 			cap.mark_ip_ecn_sctp_supported[i]);
305 		printf("cap.mark_ip_dscp_supported %" PRId32 "\n",
306 			cap.mark_ip_dscp_supported[i]);
307 	}
308 
309 	printf("cap.dynamic_update_mask %" PRIx64 "\n",
310 		cap.dynamic_update_mask);
311 	printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
312 }
313 
314 cmdline_parse_inst_t cmd_show_port_tm_cap = {
315 	.f = cmd_show_port_tm_cap_parsed,
316 	.data = NULL,
317 	.help_str = "Show Port TM Capabilities",
318 	.tokens = {
319 		(void *)&cmd_show_port_tm_cap_show,
320 		(void *)&cmd_show_port_tm_cap_port,
321 		(void *)&cmd_show_port_tm_cap_tm,
322 		(void *)&cmd_show_port_tm_cap_cap,
323 		(void *)&cmd_show_port_tm_cap_port_id,
324 		NULL,
325 	},
326 };
327 
328 /* *** Port TM Hierarchical Level Capability *** */
329 struct cmd_show_port_tm_level_cap_result {
330 	cmdline_fixed_string_t show;
331 	cmdline_fixed_string_t port;
332 	cmdline_fixed_string_t tm;
333 	cmdline_fixed_string_t level;
334 	cmdline_fixed_string_t cap;
335 	uint16_t port_id;
336 	uint32_t level_id;
337 };
338 
339 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_show =
340 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
341 		show, "show");
342 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_port =
343 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
344 		port, "port");
345 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_tm =
346 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
347 		tm, "tm");
348 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_level =
349 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
350 		level, "level");
351 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_cap =
352 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
353 		cap, "cap");
354 cmdline_parse_token_num_t cmd_show_port_tm_level_cap_port_id =
355 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
356 		 port_id, UINT16);
357 cmdline_parse_token_num_t cmd_show_port_tm_level_cap_level_id =
358 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
359 		 level_id, UINT32);
360 
361 
362 static void cmd_show_port_tm_level_cap_parsed(void *parsed_result,
363 	__attribute__((unused)) struct cmdline *cl,
364 	__attribute__((unused)) void *data)
365 {
366 	struct cmd_show_port_tm_level_cap_result *res = parsed_result;
367 	struct rte_tm_level_capabilities lcap;
368 	struct rte_tm_error error;
369 	portid_t port_id = res->port_id;
370 	uint32_t level_id = res->level_id;
371 	int ret;
372 
373 	if (port_id_is_invalid(port_id, ENABLED_WARN))
374 		return;
375 
376 	memset(&lcap, 0, sizeof(struct rte_tm_level_capabilities));
377 	ret = rte_tm_level_capabilities_get(port_id, level_id, &lcap, &error);
378 	if (ret) {
379 		print_err_msg(&error);
380 		return;
381 	}
382 	printf("\n**   Port TM Hierarchy level %" PRIu32 " Capability **\n\n",
383 		level_id);
384 
385 	printf("cap.n_nodes_max %" PRIu32 "\n", lcap.n_nodes_max);
386 	printf("cap.n_nodes_nonleaf_max %" PRIu32 "\n",
387 		lcap.n_nodes_nonleaf_max);
388 	printf("cap.n_nodes_leaf_max %" PRIu32 "\n", lcap.n_nodes_leaf_max);
389 	printf("cap.non_leaf_nodes_identical %" PRId32 "\n",
390 		lcap.non_leaf_nodes_identical);
391 	printf("cap.leaf_nodes_identical %" PRId32 "\n",
392 		lcap.leaf_nodes_identical);
393 	if (level_id <= 3) {
394 		printf("cap.nonleaf.shaper_private_supported %" PRId32 "\n",
395 			lcap.nonleaf.shaper_private_supported);
396 		printf("cap.nonleaf.shaper_private_dual_rate_supported %" PRId32
397 			"\n", lcap.nonleaf.shaper_private_dual_rate_supported);
398 		printf("cap.nonleaf.shaper_private_rate_min %" PRIu64 "\n",
399 			lcap.nonleaf.shaper_private_rate_min);
400 		printf("cap.nonleaf.shaper_private_rate_max %" PRIu64 "\n",
401 			lcap.nonleaf.shaper_private_rate_max);
402 		printf("cap.nonleaf.shaper_shared_n_max %" PRIu32 "\n",
403 			lcap.nonleaf.shaper_shared_n_max);
404 		printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n",
405 			lcap.nonleaf.sched_n_children_max);
406 		printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n",
407 			lcap.nonleaf.sched_sp_n_priorities_max);
408 		printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32
409 			"\n", lcap.nonleaf.sched_wfq_n_children_per_group_max);
410 		printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n",
411 			lcap.nonleaf.sched_wfq_n_groups_max);
412 		printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n",
413 			lcap.nonleaf.sched_wfq_weight_max);
414 		printf("cap.nonleaf.stats_mask %" PRIx64 "\n",
415 			lcap.nonleaf.stats_mask);
416 	} else {
417 		printf("cap.leaf.shaper_private_supported %" PRId32 "\n",
418 			lcap.leaf.shaper_private_supported);
419 		printf("cap.leaf.shaper_private_dual_rate_supported %" PRId32
420 			"\n", lcap.leaf.shaper_private_dual_rate_supported);
421 		printf("cap.leaf.shaper_private_rate_min %" PRIu64 "\n",
422 			lcap.leaf.shaper_private_rate_min);
423 		printf("cap.leaf.shaper_private_rate_max %" PRIu64 "\n",
424 			lcap.leaf.shaper_private_rate_max);
425 		printf("cap.leaf.shaper_shared_n_max %" PRIu32 "\n",
426 			lcap.leaf.shaper_shared_n_max);
427 		printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n",
428 			lcap.leaf.cman_head_drop_supported);
429 		printf("cap.leaf.cman_wred_context_private_supported %"	PRId32
430 			"\n", lcap.leaf.cman_wred_context_private_supported);
431 		printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n",
432 			lcap.leaf.cman_wred_context_shared_n_max);
433 		printf("cap.leaf.stats_mask %" PRIx64 "\n",
434 			lcap.leaf.stats_mask);
435 	}
436 }
437 
438 cmdline_parse_inst_t cmd_show_port_tm_level_cap = {
439 	.f = cmd_show_port_tm_level_cap_parsed,
440 	.data = NULL,
441 	.help_str = "Show Port TM Hierarhical level Capabilities",
442 	.tokens = {
443 		(void *)&cmd_show_port_tm_level_cap_show,
444 		(void *)&cmd_show_port_tm_level_cap_port,
445 		(void *)&cmd_show_port_tm_level_cap_tm,
446 		(void *)&cmd_show_port_tm_level_cap_level,
447 		(void *)&cmd_show_port_tm_level_cap_cap,
448 		(void *)&cmd_show_port_tm_level_cap_port_id,
449 		(void *)&cmd_show_port_tm_level_cap_level_id,
450 		NULL,
451 	},
452 };
453 
454 /* *** Port TM Hierarchy Node Capability *** */
455 struct cmd_show_port_tm_node_cap_result {
456 	cmdline_fixed_string_t show;
457 	cmdline_fixed_string_t port;
458 	cmdline_fixed_string_t tm;
459 	cmdline_fixed_string_t node;
460 	cmdline_fixed_string_t cap;
461 	uint16_t port_id;
462 	uint32_t node_id;
463 };
464 
465 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_show =
466 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
467 		show, "show");
468 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_port =
469 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
470 		port, "port");
471 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_tm =
472 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
473 		tm, "tm");
474 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_node =
475 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
476 		node, "node");
477 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_cap =
478 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
479 		cap, "cap");
480 cmdline_parse_token_num_t cmd_show_port_tm_node_cap_port_id =
481 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
482 		 port_id, UINT16);
483 cmdline_parse_token_num_t cmd_show_port_tm_node_cap_node_id =
484 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
485 		 node_id, UINT32);
486 
487 static void cmd_show_port_tm_node_cap_parsed(void *parsed_result,
488 	__attribute__((unused)) struct cmdline *cl,
489 	__attribute__((unused)) void *data)
490 {
491 	struct cmd_show_port_tm_node_cap_result *res = parsed_result;
492 	struct rte_tm_node_capabilities ncap;
493 	struct rte_tm_error error;
494 	uint32_t node_id = res->node_id;
495 	portid_t port_id = res->port_id;
496 	int ret, is_leaf = 0;
497 
498 	if (port_id_is_invalid(port_id, ENABLED_WARN))
499 		return;
500 
501 	/* Node id must be valid */
502 	ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error);
503 	if (ret != 0) {
504 		print_err_msg(&error);
505 		return;
506 	}
507 
508 	memset(&ncap, 0, sizeof(struct rte_tm_node_capabilities));
509 	ret = rte_tm_node_capabilities_get(port_id, node_id, &ncap, &error);
510 	if (ret != 0) {
511 		print_err_msg(&error);
512 		return;
513 	}
514 	printf("\n**   Port TM Hierarchy node %" PRIu32 " Capability **\n\n",
515 		node_id);
516 	printf("cap.shaper_private_supported %" PRId32 "\n",
517 		ncap.shaper_private_supported);
518 	printf("cap.shaper_private_dual_rate_supported %" PRId32 "\n",
519 		ncap.shaper_private_dual_rate_supported);
520 	printf("cap.shaper_private_rate_min %" PRIu64 "\n",
521 		ncap.shaper_private_rate_min);
522 	printf("cap.shaper_private_rate_max %" PRIu64 "\n",
523 		ncap.shaper_private_rate_max);
524 	printf("cap.shaper_shared_n_max %" PRIu32 "\n",
525 		ncap.shaper_shared_n_max);
526 	if (!is_leaf) {
527 		printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n",
528 			ncap.nonleaf.sched_n_children_max);
529 		printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n",
530 			ncap.nonleaf.sched_sp_n_priorities_max);
531 		printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32
532 			"\n", ncap.nonleaf.sched_wfq_n_children_per_group_max);
533 		printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n",
534 			ncap.nonleaf.sched_wfq_n_groups_max);
535 		printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n",
536 			ncap.nonleaf.sched_wfq_weight_max);
537 	} else {
538 		printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n",
539 			ncap.leaf.cman_head_drop_supported);
540 		printf("cap.leaf.cman_wred_context_private_supported %" PRId32
541 			"\n", ncap.leaf.cman_wred_context_private_supported);
542 		printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n",
543 			ncap.leaf.cman_wred_context_shared_n_max);
544 	}
545 	printf("cap.stats_mask %" PRIx64 "\n", ncap.stats_mask);
546 }
547 
548 cmdline_parse_inst_t cmd_show_port_tm_node_cap = {
549 	.f = cmd_show_port_tm_node_cap_parsed,
550 	.data = NULL,
551 	.help_str = "Show Port TM Hierarchy node capabilities",
552 	.tokens = {
553 		(void *)&cmd_show_port_tm_node_cap_show,
554 		(void *)&cmd_show_port_tm_node_cap_port,
555 		(void *)&cmd_show_port_tm_node_cap_tm,
556 		(void *)&cmd_show_port_tm_node_cap_node,
557 		(void *)&cmd_show_port_tm_node_cap_cap,
558 		(void *)&cmd_show_port_tm_node_cap_port_id,
559 		(void *)&cmd_show_port_tm_node_cap_node_id,
560 		NULL,
561 	},
562 };
563 
564 /* *** Show Port TM Node Statistics *** */
565 struct cmd_show_port_tm_node_stats_result {
566 	cmdline_fixed_string_t show;
567 	cmdline_fixed_string_t port;
568 	cmdline_fixed_string_t tm;
569 	cmdline_fixed_string_t node;
570 	cmdline_fixed_string_t stats;
571 	uint16_t port_id;
572 	uint32_t node_id;
573 	uint32_t clear;
574 };
575 
576 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_show =
577 	TOKEN_STRING_INITIALIZER(
578 		struct cmd_show_port_tm_node_stats_result, show, "show");
579 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_port =
580 	TOKEN_STRING_INITIALIZER(
581 		struct cmd_show_port_tm_node_stats_result, port, "port");
582 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_tm =
583 	TOKEN_STRING_INITIALIZER(
584 		struct cmd_show_port_tm_node_stats_result, tm, "tm");
585 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_node =
586 	TOKEN_STRING_INITIALIZER(
587 		struct cmd_show_port_tm_node_stats_result, node, "node");
588 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_stats =
589 	TOKEN_STRING_INITIALIZER(
590 		struct cmd_show_port_tm_node_stats_result, stats, "stats");
591 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_port_id =
592 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_stats_result,
593 			port_id, UINT16);
594 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_node_id =
595 	TOKEN_NUM_INITIALIZER(
596 		struct cmd_show_port_tm_node_stats_result,
597 			node_id, UINT32);
598 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_clear =
599 	TOKEN_NUM_INITIALIZER(
600 		struct cmd_show_port_tm_node_stats_result, clear, UINT32);
601 
602 static void cmd_show_port_tm_node_stats_parsed(void *parsed_result,
603 	__attribute__((unused)) struct cmdline *cl,
604 	__attribute__((unused)) void *data)
605 {
606 	struct cmd_show_port_tm_node_stats_result *res = parsed_result;
607 	struct rte_tm_node_stats stats;
608 	struct rte_tm_error error;
609 	uint64_t stats_mask = 0;
610 	uint32_t node_id = res->node_id;
611 	uint32_t clear = res->clear;
612 	portid_t port_id = res->port_id;
613 	int ret;
614 
615 	if (port_id_is_invalid(port_id, ENABLED_WARN))
616 		return;
617 
618 	/* Port status */
619 	if (!port_is_started(port_id)) {
620 		printf(" Port %u not started (error)\n", port_id);
621 		return;
622 	}
623 
624 	memset(&stats, 0, sizeof(struct rte_tm_node_stats));
625 	ret = rte_tm_node_stats_read(port_id, node_id, &stats,
626 			&stats_mask, clear, &error);
627 	if (ret != 0) {
628 		print_err_msg(&error);
629 		return;
630 	}
631 
632 	/* Display stats */
633 	if (stats_mask & RTE_TM_STATS_N_PKTS)
634 		printf("\tPkts scheduled from node: %" PRIu64 "\n",
635 			stats.n_pkts);
636 	if (stats_mask & RTE_TM_STATS_N_BYTES)
637 		printf("\tBytes scheduled from node: %" PRIu64 "\n",
638 			stats.n_bytes);
639 	if (stats_mask & RTE_TM_STATS_N_PKTS_GREEN_DROPPED)
640 		printf("\tPkts dropped (green): %" PRIu64 "\n",
641 			stats.leaf.n_pkts_dropped[RTE_TM_GREEN]);
642 	if (stats_mask & RTE_TM_STATS_N_PKTS_YELLOW_DROPPED)
643 		printf("\tPkts dropped (yellow): %" PRIu64 "\n",
644 			stats.leaf.n_pkts_dropped[RTE_TM_YELLOW]);
645 	if (stats_mask & RTE_TM_STATS_N_PKTS_RED_DROPPED)
646 		printf("\tPkts dropped (red): %" PRIu64 "\n",
647 			stats.leaf.n_pkts_dropped[RTE_TM_RED]);
648 	if (stats_mask & RTE_TM_STATS_N_BYTES_GREEN_DROPPED)
649 		printf("\tBytes dropped (green): %" PRIu64 "\n",
650 			stats.leaf.n_bytes_dropped[RTE_TM_GREEN]);
651 	if (stats_mask & RTE_TM_STATS_N_BYTES_YELLOW_DROPPED)
652 		printf("\tBytes dropped (yellow): %" PRIu64 "\n",
653 			stats.leaf.n_bytes_dropped[RTE_TM_YELLOW]);
654 	if (stats_mask & RTE_TM_STATS_N_BYTES_RED_DROPPED)
655 		printf("\tBytes dropped (red): %" PRIu64 "\n",
656 			stats.leaf.n_bytes_dropped[RTE_TM_RED]);
657 	if (stats_mask & RTE_TM_STATS_N_PKTS_QUEUED)
658 		printf("\tPkts queued: %" PRIu64 "\n",
659 			stats.leaf.n_pkts_queued);
660 	if (stats_mask & RTE_TM_STATS_N_BYTES_QUEUED)
661 		printf("\tBytes queued: %" PRIu64 "\n",
662 			stats.leaf.n_bytes_queued);
663 }
664 
665 cmdline_parse_inst_t cmd_show_port_tm_node_stats = {
666 	.f = cmd_show_port_tm_node_stats_parsed,
667 	.data = NULL,
668 	.help_str = "Show port tm node stats",
669 	.tokens = {
670 		(void *)&cmd_show_port_tm_node_stats_show,
671 		(void *)&cmd_show_port_tm_node_stats_port,
672 		(void *)&cmd_show_port_tm_node_stats_tm,
673 		(void *)&cmd_show_port_tm_node_stats_node,
674 		(void *)&cmd_show_port_tm_node_stats_stats,
675 		(void *)&cmd_show_port_tm_node_stats_port_id,
676 		(void *)&cmd_show_port_tm_node_stats_node_id,
677 		(void *)&cmd_show_port_tm_node_stats_clear,
678 		NULL,
679 	},
680 };
681 
682 /* *** Show Port TM Node Type *** */
683 struct cmd_show_port_tm_node_type_result {
684 	cmdline_fixed_string_t show;
685 	cmdline_fixed_string_t port;
686 	cmdline_fixed_string_t tm;
687 	cmdline_fixed_string_t node;
688 	cmdline_fixed_string_t type;
689 	uint16_t port_id;
690 	uint32_t node_id;
691 };
692 
693 cmdline_parse_token_string_t cmd_show_port_tm_node_type_show =
694 	TOKEN_STRING_INITIALIZER(
695 		struct cmd_show_port_tm_node_type_result, show, "show");
696 cmdline_parse_token_string_t cmd_show_port_tm_node_type_port =
697 	TOKEN_STRING_INITIALIZER(
698 		struct cmd_show_port_tm_node_type_result, port, "port");
699 cmdline_parse_token_string_t cmd_show_port_tm_node_type_tm =
700 	TOKEN_STRING_INITIALIZER(
701 		struct cmd_show_port_tm_node_type_result, tm, "tm");
702 cmdline_parse_token_string_t cmd_show_port_tm_node_type_node =
703 	TOKEN_STRING_INITIALIZER(
704 		struct cmd_show_port_tm_node_type_result, node, "node");
705 cmdline_parse_token_string_t cmd_show_port_tm_node_type_type =
706 	TOKEN_STRING_INITIALIZER(
707 		struct cmd_show_port_tm_node_type_result, type, "type");
708 cmdline_parse_token_num_t cmd_show_port_tm_node_type_port_id =
709 	TOKEN_NUM_INITIALIZER(
710 		struct cmd_show_port_tm_node_type_result,
711 			port_id, UINT16);
712 cmdline_parse_token_num_t cmd_show_port_tm_node_type_node_id =
713 	TOKEN_NUM_INITIALIZER(
714 		struct cmd_show_port_tm_node_type_result,
715 			node_id, UINT32);
716 
717 static void cmd_show_port_tm_node_type_parsed(void *parsed_result,
718 	__attribute__((unused)) struct cmdline *cl,
719 	__attribute__((unused)) void *data)
720 {
721 	struct cmd_show_port_tm_node_type_result *res = parsed_result;
722 	struct rte_tm_error error;
723 	uint32_t node_id = res->node_id;
724 	portid_t port_id = res->port_id;
725 	int ret, is_leaf = 0;
726 
727 	if (port_id_is_invalid(port_id, ENABLED_WARN))
728 		return;
729 
730 	ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error);
731 	if (ret != 0) {
732 		print_err_msg(&error);
733 		return;
734 	}
735 
736 	if (is_leaf == 1)
737 		printf("leaf node\n");
738 	else
739 		printf("nonleaf node\n");
740 
741 }
742 
743 cmdline_parse_inst_t cmd_show_port_tm_node_type = {
744 	.f = cmd_show_port_tm_node_type_parsed,
745 	.data = NULL,
746 	.help_str = "Show port tm node type",
747 	.tokens = {
748 		(void *)&cmd_show_port_tm_node_type_show,
749 		(void *)&cmd_show_port_tm_node_type_port,
750 		(void *)&cmd_show_port_tm_node_type_tm,
751 		(void *)&cmd_show_port_tm_node_type_node,
752 		(void *)&cmd_show_port_tm_node_type_type,
753 		(void *)&cmd_show_port_tm_node_type_port_id,
754 		(void *)&cmd_show_port_tm_node_type_node_id,
755 		NULL,
756 	},
757 };
758 
759 /* *** Add Port TM Private Shaper Profile *** */
760 struct cmd_add_port_tm_node_shaper_profile_result {
761 	cmdline_fixed_string_t add;
762 	cmdline_fixed_string_t port;
763 	cmdline_fixed_string_t tm;
764 	cmdline_fixed_string_t node;
765 	cmdline_fixed_string_t shaper;
766 	cmdline_fixed_string_t profile;
767 	uint16_t port_id;
768 	uint32_t shaper_id;
769 	uint64_t tb_rate;
770 	uint64_t tb_size;
771 	uint32_t pktlen_adjust;
772 };
773 
774 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_add =
775 	TOKEN_STRING_INITIALIZER(
776 		struct cmd_add_port_tm_node_shaper_profile_result, add, "add");
777 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_port =
778 	TOKEN_STRING_INITIALIZER(
779 		struct cmd_add_port_tm_node_shaper_profile_result,
780 			port, "port");
781 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_tm =
782 	TOKEN_STRING_INITIALIZER(
783 		struct cmd_add_port_tm_node_shaper_profile_result,
784 			tm, "tm");
785 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_node =
786 	TOKEN_STRING_INITIALIZER(
787 		struct cmd_add_port_tm_node_shaper_profile_result,
788 			node, "node");
789 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_shaper =
790 	TOKEN_STRING_INITIALIZER(
791 		struct cmd_add_port_tm_node_shaper_profile_result,
792 			shaper, "shaper");
793 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_profile =
794 	TOKEN_STRING_INITIALIZER(
795 		struct cmd_add_port_tm_node_shaper_profile_result,
796 			profile, "profile");
797 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_port_id =
798 	TOKEN_NUM_INITIALIZER(
799 		struct cmd_add_port_tm_node_shaper_profile_result,
800 			port_id, UINT16);
801 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_shaper_id =
802 	TOKEN_NUM_INITIALIZER(
803 		struct cmd_add_port_tm_node_shaper_profile_result,
804 			shaper_id, UINT32);
805 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_tb_rate =
806 	TOKEN_NUM_INITIALIZER(
807 		struct cmd_add_port_tm_node_shaper_profile_result,
808 			tb_rate, UINT64);
809 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_tb_size =
810 	TOKEN_NUM_INITIALIZER(
811 		struct cmd_add_port_tm_node_shaper_profile_result,
812 			tb_size, UINT64);
813 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_pktlen_adjust =
814 	TOKEN_NUM_INITIALIZER(
815 		struct cmd_add_port_tm_node_shaper_profile_result,
816 			pktlen_adjust, UINT32);
817 
818 static void cmd_add_port_tm_node_shaper_profile_parsed(void *parsed_result,
819 	__attribute__((unused)) struct cmdline *cl,
820 	__attribute__((unused)) void *data)
821 {
822 	struct cmd_add_port_tm_node_shaper_profile_result *res = parsed_result;
823 	struct rte_tm_shaper_params sp;
824 	struct rte_tm_error error;
825 	uint32_t shaper_id = res->shaper_id;
826 	uint32_t pkt_len_adjust = res->pktlen_adjust;
827 	portid_t port_id = res->port_id;
828 	int ret;
829 
830 	if (port_id_is_invalid(port_id, ENABLED_WARN))
831 		return;
832 
833 	/* Private shaper profile params */
834 	memset(&sp, 0, sizeof(struct rte_tm_shaper_params));
835 	sp.peak.rate = res->tb_rate;
836 	sp.peak.size = res->tb_size;
837 	sp.pkt_length_adjust = pkt_len_adjust;
838 
839 	ret = rte_tm_shaper_profile_add(port_id, shaper_id, &sp, &error);
840 	if (ret != 0) {
841 		print_err_msg(&error);
842 		return;
843 	}
844 }
845 
846 cmdline_parse_inst_t cmd_add_port_tm_node_shaper_profile = {
847 	.f = cmd_add_port_tm_node_shaper_profile_parsed,
848 	.data = NULL,
849 	.help_str = "Add port tm node private shaper profile",
850 	.tokens = {
851 		(void *)&cmd_add_port_tm_node_shaper_profile_add,
852 		(void *)&cmd_add_port_tm_node_shaper_profile_port,
853 		(void *)&cmd_add_port_tm_node_shaper_profile_tm,
854 		(void *)&cmd_add_port_tm_node_shaper_profile_node,
855 		(void *)&cmd_add_port_tm_node_shaper_profile_shaper,
856 		(void *)&cmd_add_port_tm_node_shaper_profile_profile,
857 		(void *)&cmd_add_port_tm_node_shaper_profile_port_id,
858 		(void *)&cmd_add_port_tm_node_shaper_profile_shaper_id,
859 		(void *)&cmd_add_port_tm_node_shaper_profile_tb_rate,
860 		(void *)&cmd_add_port_tm_node_shaper_profile_tb_size,
861 		(void *)&cmd_add_port_tm_node_shaper_profile_pktlen_adjust,
862 		NULL,
863 	},
864 };
865 
866 /* *** Delete Port TM Private Shaper Profile *** */
867 struct cmd_del_port_tm_node_shaper_profile_result {
868 	cmdline_fixed_string_t del;
869 	cmdline_fixed_string_t port;
870 	cmdline_fixed_string_t tm;
871 	cmdline_fixed_string_t node;
872 	cmdline_fixed_string_t shaper;
873 	cmdline_fixed_string_t profile;
874 	uint16_t port_id;
875 	uint32_t shaper_id;
876 };
877 
878 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_del =
879 	TOKEN_STRING_INITIALIZER(
880 		struct cmd_del_port_tm_node_shaper_profile_result, del, "del");
881 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_port =
882 	TOKEN_STRING_INITIALIZER(
883 		struct cmd_del_port_tm_node_shaper_profile_result,
884 			port, "port");
885 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_tm =
886 	TOKEN_STRING_INITIALIZER(
887 		struct cmd_del_port_tm_node_shaper_profile_result, tm, "tm");
888 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_node =
889 	TOKEN_STRING_INITIALIZER(
890 		struct cmd_del_port_tm_node_shaper_profile_result,
891 			node, "node");
892 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_shaper =
893 	TOKEN_STRING_INITIALIZER(
894 		struct cmd_del_port_tm_node_shaper_profile_result,
895 			shaper, "shaper");
896 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_profile =
897 	TOKEN_STRING_INITIALIZER(
898 		struct cmd_del_port_tm_node_shaper_profile_result,
899 			profile, "profile");
900 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_port_id =
901 	TOKEN_NUM_INITIALIZER(
902 		struct cmd_del_port_tm_node_shaper_profile_result,
903 			port_id, UINT16);
904 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_shaper_id =
905 	TOKEN_NUM_INITIALIZER(
906 		struct cmd_del_port_tm_node_shaper_profile_result,
907 			shaper_id, UINT32);
908 
909 static void cmd_del_port_tm_node_shaper_profile_parsed(void *parsed_result,
910 	__attribute__((unused)) struct cmdline *cl,
911 	__attribute__((unused)) void *data)
912 {
913 	struct cmd_del_port_tm_node_shaper_profile_result *res = parsed_result;
914 	struct rte_tm_error error;
915 	uint32_t shaper_id = res->shaper_id;
916 	portid_t port_id = res->port_id;
917 	int ret;
918 
919 	if (port_id_is_invalid(port_id, ENABLED_WARN))
920 		return;
921 
922 	ret = rte_tm_shaper_profile_delete(port_id, shaper_id, &error);
923 	if (ret != 0) {
924 		print_err_msg(&error);
925 		return;
926 	}
927 }
928 
929 cmdline_parse_inst_t cmd_del_port_tm_node_shaper_profile = {
930 	.f = cmd_del_port_tm_node_shaper_profile_parsed,
931 	.data = NULL,
932 	.help_str = "Delete port tm node private shaper profile",
933 	.tokens = {
934 		(void *)&cmd_del_port_tm_node_shaper_profile_del,
935 		(void *)&cmd_del_port_tm_node_shaper_profile_port,
936 		(void *)&cmd_del_port_tm_node_shaper_profile_tm,
937 		(void *)&cmd_del_port_tm_node_shaper_profile_node,
938 		(void *)&cmd_del_port_tm_node_shaper_profile_shaper,
939 		(void *)&cmd_del_port_tm_node_shaper_profile_profile,
940 		(void *)&cmd_del_port_tm_node_shaper_profile_port_id,
941 		(void *)&cmd_del_port_tm_node_shaper_profile_shaper_id,
942 		NULL,
943 	},
944 };
945 
946 /* *** Add/Update Port TM shared Shaper *** */
947 struct cmd_add_port_tm_node_shared_shaper_result {
948 	cmdline_fixed_string_t cmd_type;
949 	cmdline_fixed_string_t port;
950 	cmdline_fixed_string_t tm;
951 	cmdline_fixed_string_t node;
952 	cmdline_fixed_string_t shared;
953 	cmdline_fixed_string_t shaper;
954 	uint16_t port_id;
955 	uint32_t shared_shaper_id;
956 	uint32_t shaper_profile_id;
957 };
958 
959 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_cmd_type =
960 	TOKEN_STRING_INITIALIZER(
961 		struct cmd_add_port_tm_node_shared_shaper_result,
962 			cmd_type, "add#set");
963 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_port =
964 	TOKEN_STRING_INITIALIZER(
965 		struct cmd_add_port_tm_node_shared_shaper_result, port, "port");
966 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_tm =
967 	TOKEN_STRING_INITIALIZER(
968 		struct cmd_add_port_tm_node_shared_shaper_result, tm, "tm");
969 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_node =
970 	TOKEN_STRING_INITIALIZER(
971 		struct cmd_add_port_tm_node_shared_shaper_result, node, "node");
972 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shared =
973 	TOKEN_STRING_INITIALIZER(
974 		struct cmd_add_port_tm_node_shared_shaper_result,
975 			shared, "shared");
976 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shaper =
977 	TOKEN_STRING_INITIALIZER(
978 		struct cmd_add_port_tm_node_shared_shaper_result,
979 			shaper, "shaper");
980 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_port_id =
981 	TOKEN_NUM_INITIALIZER(
982 		struct cmd_add_port_tm_node_shared_shaper_result,
983 			port_id, UINT16);
984 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shared_shaper_id =
985 	TOKEN_NUM_INITIALIZER(
986 		struct cmd_add_port_tm_node_shared_shaper_result,
987 			shared_shaper_id, UINT32);
988 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shaper_profile_id =
989 	TOKEN_NUM_INITIALIZER(
990 		struct cmd_add_port_tm_node_shared_shaper_result,
991 			shaper_profile_id, UINT32);
992 
993 static void cmd_add_port_tm_node_shared_shaper_parsed(void *parsed_result,
994 	__attribute__((unused)) struct cmdline *cl,
995 	__attribute__((unused)) void *data)
996 {
997 	struct cmd_add_port_tm_node_shared_shaper_result *res = parsed_result;
998 	struct rte_tm_error error;
999 	uint32_t shared_shaper_id = res->shared_shaper_id;
1000 	uint32_t shaper_profile_id = res->shaper_profile_id;
1001 	portid_t port_id = res->port_id;
1002 	int ret;
1003 
1004 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1005 		return;
1006 
1007 	/* Command type: add */
1008 	if ((strcmp(res->cmd_type, "add") == 0) &&
1009 		(port_is_started(port_id))) {
1010 		printf(" Port %u not stopped (error)\n", port_id);
1011 		return;
1012 	}
1013 
1014 	/* Command type: set (update) */
1015 	if ((strcmp(res->cmd_type, "set") == 0) &&
1016 		(!port_is_started(port_id))) {
1017 		printf(" Port %u not started (error)\n", port_id);
1018 		return;
1019 	}
1020 
1021 	ret = rte_tm_shared_shaper_add_update(port_id, shared_shaper_id,
1022 		shaper_profile_id, &error);
1023 	if (ret != 0) {
1024 		print_err_msg(&error);
1025 		return;
1026 	}
1027 }
1028 
1029 cmdline_parse_inst_t cmd_add_port_tm_node_shared_shaper = {
1030 	.f = cmd_add_port_tm_node_shared_shaper_parsed,
1031 	.data = NULL,
1032 	.help_str = "add/update port tm node shared shaper",
1033 	.tokens = {
1034 		(void *)&cmd_add_port_tm_node_shared_shaper_cmd_type,
1035 		(void *)&cmd_add_port_tm_node_shared_shaper_port,
1036 		(void *)&cmd_add_port_tm_node_shared_shaper_tm,
1037 		(void *)&cmd_add_port_tm_node_shared_shaper_node,
1038 		(void *)&cmd_add_port_tm_node_shared_shaper_shared,
1039 		(void *)&cmd_add_port_tm_node_shared_shaper_shaper,
1040 		(void *)&cmd_add_port_tm_node_shared_shaper_port_id,
1041 		(void *)&cmd_add_port_tm_node_shared_shaper_shared_shaper_id,
1042 		(void *)&cmd_add_port_tm_node_shared_shaper_shaper_profile_id,
1043 		NULL,
1044 	},
1045 };
1046 
1047 /* *** Delete Port TM shared Shaper *** */
1048 struct cmd_del_port_tm_node_shared_shaper_result {
1049 	cmdline_fixed_string_t del;
1050 	cmdline_fixed_string_t port;
1051 	cmdline_fixed_string_t tm;
1052 	cmdline_fixed_string_t node;
1053 	cmdline_fixed_string_t shared;
1054 	cmdline_fixed_string_t shaper;
1055 	uint16_t port_id;
1056 	uint32_t shared_shaper_id;
1057 };
1058 
1059 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_del =
1060 	TOKEN_STRING_INITIALIZER(
1061 		struct cmd_del_port_tm_node_shared_shaper_result, del, "del");
1062 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_port =
1063 	TOKEN_STRING_INITIALIZER(
1064 		struct cmd_del_port_tm_node_shared_shaper_result, port, "port");
1065 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_tm =
1066 	TOKEN_STRING_INITIALIZER(
1067 		struct cmd_del_port_tm_node_shared_shaper_result, tm, "tm");
1068 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_node =
1069 	TOKEN_STRING_INITIALIZER(
1070 		struct cmd_del_port_tm_node_shared_shaper_result, node, "node");
1071 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shared =
1072 	TOKEN_STRING_INITIALIZER(
1073 		struct cmd_del_port_tm_node_shared_shaper_result,
1074 			shared, "shared");
1075 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shaper =
1076 	TOKEN_STRING_INITIALIZER(
1077 		struct cmd_del_port_tm_node_shared_shaper_result,
1078 			shaper, "shaper");
1079 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_port_id =
1080 	TOKEN_NUM_INITIALIZER(
1081 		struct cmd_del_port_tm_node_shared_shaper_result,
1082 			port_id, UINT16);
1083 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_shared_shaper_id =
1084 	TOKEN_NUM_INITIALIZER(
1085 		struct cmd_del_port_tm_node_shared_shaper_result,
1086 			shared_shaper_id, UINT32);
1087 
1088 static void cmd_del_port_tm_node_shared_shaper_parsed(void *parsed_result,
1089 	__attribute__((unused)) struct cmdline *cl,
1090 	__attribute__((unused)) void *data)
1091 {
1092 	struct cmd_del_port_tm_node_shared_shaper_result *res = parsed_result;
1093 	struct rte_tm_error error;
1094 	uint32_t shared_shaper_id = res->shared_shaper_id;
1095 	portid_t port_id = res->port_id;
1096 	int ret;
1097 
1098 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1099 		return;
1100 
1101 	ret = rte_tm_shared_shaper_delete(port_id, shared_shaper_id, &error);
1102 	if (ret != 0) {
1103 		print_err_msg(&error);
1104 		return;
1105 	}
1106 }
1107 
1108 cmdline_parse_inst_t cmd_del_port_tm_node_shared_shaper = {
1109 	.f = cmd_del_port_tm_node_shared_shaper_parsed,
1110 	.data = NULL,
1111 	.help_str = "delete port tm node shared shaper",
1112 	.tokens = {
1113 		(void *)&cmd_del_port_tm_node_shared_shaper_del,
1114 		(void *)&cmd_del_port_tm_node_shared_shaper_port,
1115 		(void *)&cmd_del_port_tm_node_shared_shaper_tm,
1116 		(void *)&cmd_del_port_tm_node_shared_shaper_node,
1117 		(void *)&cmd_del_port_tm_node_shared_shaper_shared,
1118 		(void *)&cmd_del_port_tm_node_shared_shaper_shaper,
1119 		(void *)&cmd_del_port_tm_node_shared_shaper_port_id,
1120 		(void *)&cmd_del_port_tm_node_shared_shaper_shared_shaper_id,
1121 		NULL,
1122 	},
1123 };
1124 
1125 /* *** Add Port TM Node WRED Profile *** */
1126 struct cmd_add_port_tm_node_wred_profile_result {
1127 	cmdline_fixed_string_t add;
1128 	cmdline_fixed_string_t port;
1129 	cmdline_fixed_string_t tm;
1130 	cmdline_fixed_string_t node;
1131 	cmdline_fixed_string_t wred;
1132 	cmdline_fixed_string_t profile;
1133 	uint16_t port_id;
1134 	uint32_t wred_profile_id;
1135 	cmdline_fixed_string_t color_g;
1136 	uint16_t min_th_g;
1137 	uint16_t max_th_g;
1138 	uint16_t maxp_inv_g;
1139 	uint16_t wq_log2_g;
1140 	cmdline_fixed_string_t color_y;
1141 	uint16_t min_th_y;
1142 	uint16_t max_th_y;
1143 	uint16_t maxp_inv_y;
1144 	uint16_t wq_log2_y;
1145 	cmdline_fixed_string_t color_r;
1146 	uint16_t min_th_r;
1147 	uint16_t max_th_r;
1148 	uint16_t maxp_inv_r;
1149 	uint16_t wq_log2_r;
1150 };
1151 
1152 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_add =
1153 	TOKEN_STRING_INITIALIZER(
1154 		struct cmd_add_port_tm_node_wred_profile_result, add, "add");
1155 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_port =
1156 	TOKEN_STRING_INITIALIZER(
1157 		struct cmd_add_port_tm_node_wred_profile_result, port, "port");
1158 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_tm =
1159 	TOKEN_STRING_INITIALIZER(
1160 		struct cmd_add_port_tm_node_wred_profile_result, tm, "tm");
1161 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_node =
1162 	TOKEN_STRING_INITIALIZER(
1163 		struct cmd_add_port_tm_node_wred_profile_result, node, "node");
1164 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_wred =
1165 	TOKEN_STRING_INITIALIZER(
1166 		struct cmd_add_port_tm_node_wred_profile_result, wred, "wred");
1167 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_profile =
1168 	TOKEN_STRING_INITIALIZER(
1169 		struct cmd_add_port_tm_node_wred_profile_result,
1170 			profile, "profile");
1171 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_port_id =
1172 	TOKEN_NUM_INITIALIZER(
1173 		struct cmd_add_port_tm_node_wred_profile_result,
1174 			port_id, UINT16);
1175 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wred_profile_id =
1176 	TOKEN_NUM_INITIALIZER(
1177 		struct cmd_add_port_tm_node_wred_profile_result,
1178 			wred_profile_id, UINT32);
1179 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_g =
1180 	TOKEN_STRING_INITIALIZER(
1181 		struct cmd_add_port_tm_node_wred_profile_result,
1182 			color_g, "G#g");
1183 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_g =
1184 	TOKEN_NUM_INITIALIZER(
1185 		struct cmd_add_port_tm_node_wred_profile_result,
1186 			min_th_g, UINT16);
1187 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_g =
1188 	TOKEN_NUM_INITIALIZER(
1189 		struct cmd_add_port_tm_node_wred_profile_result,
1190 			max_th_g, UINT16);
1191 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_g =
1192 	TOKEN_NUM_INITIALIZER(
1193 		struct cmd_add_port_tm_node_wred_profile_result,
1194 			maxp_inv_g, UINT16);
1195 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_g =
1196 	TOKEN_NUM_INITIALIZER(
1197 		struct cmd_add_port_tm_node_wred_profile_result,
1198 			wq_log2_g, UINT16);
1199 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_y =
1200 	TOKEN_STRING_INITIALIZER(
1201 		struct cmd_add_port_tm_node_wred_profile_result,
1202 			color_y, "Y#y");
1203 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_y =
1204 	TOKEN_NUM_INITIALIZER(
1205 		struct cmd_add_port_tm_node_wred_profile_result,
1206 			min_th_y, UINT16);
1207 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_y =
1208 	TOKEN_NUM_INITIALIZER(
1209 		struct cmd_add_port_tm_node_wred_profile_result,
1210 			max_th_y, UINT16);
1211 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_y =
1212 	TOKEN_NUM_INITIALIZER(
1213 		struct cmd_add_port_tm_node_wred_profile_result,
1214 			maxp_inv_y, UINT16);
1215 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_y =
1216 	TOKEN_NUM_INITIALIZER(
1217 		struct cmd_add_port_tm_node_wred_profile_result,
1218 			wq_log2_y, UINT16);
1219 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_r =
1220 	TOKEN_STRING_INITIALIZER(
1221 		struct cmd_add_port_tm_node_wred_profile_result,
1222 			color_r, "R#r");
1223 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_r =
1224 	TOKEN_NUM_INITIALIZER(
1225 		struct cmd_add_port_tm_node_wred_profile_result,
1226 			min_th_r, UINT16);
1227 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_r =
1228 	TOKEN_NUM_INITIALIZER(
1229 		struct cmd_add_port_tm_node_wred_profile_result,
1230 			max_th_r, UINT16);
1231 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_r =
1232 	TOKEN_NUM_INITIALIZER(
1233 		struct cmd_add_port_tm_node_wred_profile_result,
1234 			maxp_inv_r, UINT16);
1235 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_r =
1236 	TOKEN_NUM_INITIALIZER(
1237 		struct cmd_add_port_tm_node_wred_profile_result,
1238 			wq_log2_r, UINT16);
1239 
1240 
1241 static void cmd_add_port_tm_node_wred_profile_parsed(void *parsed_result,
1242 	__attribute__((unused)) struct cmdline *cl,
1243 	__attribute__((unused)) void *data)
1244 {
1245 	struct cmd_add_port_tm_node_wred_profile_result *res = parsed_result;
1246 	struct rte_tm_wred_params wp;
1247 	enum rte_tm_color color;
1248 	struct rte_tm_error error;
1249 	uint32_t wred_profile_id = res->wred_profile_id;
1250 	portid_t port_id = res->port_id;
1251 	int ret;
1252 
1253 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1254 		return;
1255 
1256 	memset(&wp, 0, sizeof(struct rte_tm_wred_params));
1257 
1258 	/* WRED Params  (Green Color)*/
1259 	color = RTE_TM_GREEN;
1260 	wp.red_params[color].min_th = res->min_th_g;
1261 	wp.red_params[color].max_th = res->max_th_g;
1262 	wp.red_params[color].maxp_inv = res->maxp_inv_g;
1263 	wp.red_params[color].wq_log2 = res->wq_log2_g;
1264 
1265 
1266 	/* WRED Params  (Yellow Color)*/
1267 	color = RTE_TM_YELLOW;
1268 	wp.red_params[color].min_th = res->min_th_y;
1269 	wp.red_params[color].max_th = res->max_th_y;
1270 	wp.red_params[color].maxp_inv = res->maxp_inv_y;
1271 	wp.red_params[color].wq_log2 = res->wq_log2_y;
1272 
1273 	/* WRED Params  (Red Color)*/
1274 	color = RTE_TM_RED;
1275 	wp.red_params[color].min_th = res->min_th_r;
1276 	wp.red_params[color].max_th = res->max_th_r;
1277 	wp.red_params[color].maxp_inv = res->maxp_inv_r;
1278 	wp.red_params[color].wq_log2 = res->wq_log2_r;
1279 
1280 	ret = rte_tm_wred_profile_add(port_id, wred_profile_id, &wp, &error);
1281 	if (ret != 0) {
1282 		print_err_msg(&error);
1283 		return;
1284 	}
1285 }
1286 
1287 cmdline_parse_inst_t cmd_add_port_tm_node_wred_profile = {
1288 	.f = cmd_add_port_tm_node_wred_profile_parsed,
1289 	.data = NULL,
1290 	.help_str = "Add port tm node wred profile",
1291 	.tokens = {
1292 		(void *)&cmd_add_port_tm_node_wred_profile_add,
1293 		(void *)&cmd_add_port_tm_node_wred_profile_port,
1294 		(void *)&cmd_add_port_tm_node_wred_profile_tm,
1295 		(void *)&cmd_add_port_tm_node_wred_profile_node,
1296 		(void *)&cmd_add_port_tm_node_wred_profile_wred,
1297 		(void *)&cmd_add_port_tm_node_wred_profile_profile,
1298 		(void *)&cmd_add_port_tm_node_wred_profile_port_id,
1299 		(void *)&cmd_add_port_tm_node_wred_profile_wred_profile_id,
1300 		(void *)&cmd_add_port_tm_node_wred_profile_color_g,
1301 		(void *)&cmd_add_port_tm_node_wred_profile_min_th_g,
1302 		(void *)&cmd_add_port_tm_node_wred_profile_max_th_g,
1303 		(void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_g,
1304 		(void *)&cmd_add_port_tm_node_wred_profile_wq_log2_g,
1305 		(void *)&cmd_add_port_tm_node_wred_profile_color_y,
1306 		(void *)&cmd_add_port_tm_node_wred_profile_min_th_y,
1307 		(void *)&cmd_add_port_tm_node_wred_profile_max_th_y,
1308 		(void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_y,
1309 		(void *)&cmd_add_port_tm_node_wred_profile_wq_log2_y,
1310 		(void *)&cmd_add_port_tm_node_wred_profile_color_r,
1311 		(void *)&cmd_add_port_tm_node_wred_profile_min_th_r,
1312 		(void *)&cmd_add_port_tm_node_wred_profile_max_th_r,
1313 		(void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_r,
1314 		(void *)&cmd_add_port_tm_node_wred_profile_wq_log2_r,
1315 		NULL,
1316 	},
1317 };
1318 
1319 /* *** Delete Port TM node WRED Profile *** */
1320 struct cmd_del_port_tm_node_wred_profile_result {
1321 	cmdline_fixed_string_t del;
1322 	cmdline_fixed_string_t port;
1323 	cmdline_fixed_string_t tm;
1324 	cmdline_fixed_string_t node;
1325 	cmdline_fixed_string_t wred;
1326 	cmdline_fixed_string_t profile;
1327 	uint16_t port_id;
1328 	uint32_t wred_profile_id;
1329 };
1330 
1331 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_del =
1332 	TOKEN_STRING_INITIALIZER(
1333 		struct cmd_del_port_tm_node_wred_profile_result, del, "del");
1334 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_port =
1335 	TOKEN_STRING_INITIALIZER(
1336 		struct cmd_del_port_tm_node_wred_profile_result, port, "port");
1337 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_tm =
1338 	TOKEN_STRING_INITIALIZER(
1339 		struct cmd_del_port_tm_node_wred_profile_result, tm, "tm");
1340 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_node =
1341 	TOKEN_STRING_INITIALIZER(
1342 		struct cmd_del_port_tm_node_wred_profile_result, node, "node");
1343 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_wred =
1344 	TOKEN_STRING_INITIALIZER(
1345 		struct cmd_del_port_tm_node_wred_profile_result, wred, "wred");
1346 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_profile =
1347 	TOKEN_STRING_INITIALIZER(
1348 		struct cmd_del_port_tm_node_wred_profile_result,
1349 			profile, "profile");
1350 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_port_id =
1351 	TOKEN_NUM_INITIALIZER(
1352 		struct cmd_del_port_tm_node_wred_profile_result,
1353 			port_id, UINT16);
1354 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_wred_profile_id =
1355 	TOKEN_NUM_INITIALIZER(
1356 		struct cmd_del_port_tm_node_wred_profile_result,
1357 			wred_profile_id, UINT32);
1358 
1359 static void cmd_del_port_tm_node_wred_profile_parsed(void *parsed_result,
1360 	__attribute__((unused)) struct cmdline *cl,
1361 	__attribute__((unused)) void *data)
1362 {
1363 	struct cmd_del_port_tm_node_wred_profile_result *res = parsed_result;
1364 	struct rte_tm_error error;
1365 	uint32_t wred_profile_id = res->wred_profile_id;
1366 	portid_t port_id = res->port_id;
1367 	int ret;
1368 
1369 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1370 		return;
1371 
1372 	ret = rte_tm_wred_profile_delete(port_id, wred_profile_id, &error);
1373 	if (ret != 0) {
1374 		print_err_msg(&error);
1375 		return;
1376 	}
1377 }
1378 
1379 cmdline_parse_inst_t cmd_del_port_tm_node_wred_profile = {
1380 	.f = cmd_del_port_tm_node_wred_profile_parsed,
1381 	.data = NULL,
1382 	.help_str = "Delete port tm node wred profile",
1383 	.tokens = {
1384 		(void *)&cmd_del_port_tm_node_wred_profile_del,
1385 		(void *)&cmd_del_port_tm_node_wred_profile_port,
1386 		(void *)&cmd_del_port_tm_node_wred_profile_tm,
1387 		(void *)&cmd_del_port_tm_node_wred_profile_node,
1388 		(void *)&cmd_del_port_tm_node_wred_profile_wred,
1389 		(void *)&cmd_del_port_tm_node_wred_profile_profile,
1390 		(void *)&cmd_del_port_tm_node_wred_profile_port_id,
1391 		(void *)&cmd_del_port_tm_node_wred_profile_wred_profile_id,
1392 		NULL,
1393 	},
1394 };
1395 
1396 /* *** Update Port TM Node Shaper profile *** */
1397 struct cmd_set_port_tm_node_shaper_profile_result {
1398 	cmdline_fixed_string_t set;
1399 	cmdline_fixed_string_t port;
1400 	cmdline_fixed_string_t tm;
1401 	cmdline_fixed_string_t node;
1402 	cmdline_fixed_string_t shaper;
1403 	cmdline_fixed_string_t profile;
1404 	uint16_t port_id;
1405 	uint32_t node_id;
1406 	uint32_t shaper_profile_id;
1407 };
1408 
1409 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_set =
1410 	TOKEN_STRING_INITIALIZER(
1411 		struct cmd_set_port_tm_node_shaper_profile_result, set, "set");
1412 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_port =
1413 	TOKEN_STRING_INITIALIZER(
1414 		struct cmd_set_port_tm_node_shaper_profile_result,
1415 			port, "port");
1416 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_tm =
1417 	TOKEN_STRING_INITIALIZER(
1418 		struct cmd_set_port_tm_node_shaper_profile_result, tm, "tm");
1419 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_node =
1420 	TOKEN_STRING_INITIALIZER(
1421 		struct cmd_set_port_tm_node_shaper_profile_result,
1422 			node, "node");
1423 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_shaper =
1424 	TOKEN_STRING_INITIALIZER(
1425 		struct cmd_set_port_tm_node_shaper_profile_result,
1426 			shaper, "shaper");
1427 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_profile =
1428 	TOKEN_STRING_INITIALIZER(
1429 		struct cmd_set_port_tm_node_shaper_profile_result,
1430 			profile, "profile");
1431 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_port_id =
1432 	TOKEN_NUM_INITIALIZER(
1433 		struct cmd_set_port_tm_node_shaper_profile_result,
1434 			port_id, UINT16);
1435 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_node_id =
1436 	TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_shaper_profile_result,
1437 		node_id, UINT32);
1438 cmdline_parse_token_num_t
1439 	cmd_set_port_tm_node_shaper_shaper_profile_profile_id =
1440 		TOKEN_NUM_INITIALIZER(
1441 			struct cmd_set_port_tm_node_shaper_profile_result,
1442 			shaper_profile_id, UINT32);
1443 
1444 static void cmd_set_port_tm_node_shaper_profile_parsed(void *parsed_result,
1445 	__attribute__((unused)) struct cmdline *cl,
1446 	__attribute__((unused)) void *data)
1447 {
1448 	struct cmd_set_port_tm_node_shaper_profile_result *res = parsed_result;
1449 	struct rte_tm_error error;
1450 	uint32_t node_id = res->node_id;
1451 	uint32_t shaper_profile_id = res->shaper_profile_id;
1452 	portid_t port_id = res->port_id;
1453 	int ret;
1454 
1455 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1456 		return;
1457 
1458 	/* Port status */
1459 	if (!port_is_started(port_id)) {
1460 		printf(" Port %u not started (error)\n", port_id);
1461 		return;
1462 	}
1463 
1464 	ret = rte_tm_node_shaper_update(port_id, node_id,
1465 		shaper_profile_id, &error);
1466 	if (ret != 0) {
1467 		print_err_msg(&error);
1468 		return;
1469 	}
1470 }
1471 
1472 cmdline_parse_inst_t cmd_set_port_tm_node_shaper_profile = {
1473 	.f = cmd_set_port_tm_node_shaper_profile_parsed,
1474 	.data = NULL,
1475 	.help_str = "Set port tm node shaper profile",
1476 	.tokens = {
1477 		(void *)&cmd_set_port_tm_node_shaper_profile_set,
1478 		(void *)&cmd_set_port_tm_node_shaper_profile_port,
1479 		(void *)&cmd_set_port_tm_node_shaper_profile_tm,
1480 		(void *)&cmd_set_port_tm_node_shaper_profile_node,
1481 		(void *)&cmd_set_port_tm_node_shaper_profile_shaper,
1482 		(void *)&cmd_set_port_tm_node_shaper_profile_profile,
1483 		(void *)&cmd_set_port_tm_node_shaper_profile_port_id,
1484 		(void *)&cmd_set_port_tm_node_shaper_profile_node_id,
1485 		(void *)&cmd_set_port_tm_node_shaper_shaper_profile_profile_id,
1486 		NULL,
1487 	},
1488 };
1489 
1490 /* *** Add Port TM nonleaf node *** */
1491 struct cmd_add_port_tm_nonleaf_node_result {
1492 	cmdline_fixed_string_t add;
1493 	cmdline_fixed_string_t port;
1494 	cmdline_fixed_string_t tm;
1495 	cmdline_fixed_string_t nonleaf;
1496 	cmdline_fixed_string_t node;
1497 	uint16_t port_id;
1498 	uint32_t node_id;
1499 	int32_t parent_node_id;
1500 	uint32_t priority;
1501 	uint32_t weight;
1502 	uint32_t level_id;
1503 	uint32_t shaper_profile_id;
1504 	uint32_t n_sp_priorities;
1505 	uint64_t stats_mask;
1506 	cmdline_multi_string_t multi_shared_shaper_id;
1507 };
1508 
1509 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_add =
1510 	TOKEN_STRING_INITIALIZER(
1511 		struct cmd_add_port_tm_nonleaf_node_result, add, "add");
1512 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_port =
1513 	TOKEN_STRING_INITIALIZER(
1514 		struct cmd_add_port_tm_nonleaf_node_result, port, "port");
1515 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_tm =
1516 	TOKEN_STRING_INITIALIZER(
1517 		struct cmd_add_port_tm_nonleaf_node_result, tm, "tm");
1518 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_nonleaf =
1519 	TOKEN_STRING_INITIALIZER(
1520 		struct cmd_add_port_tm_nonleaf_node_result, nonleaf, "nonleaf");
1521 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_node =
1522 	TOKEN_STRING_INITIALIZER(
1523 		struct cmd_add_port_tm_nonleaf_node_result, node, "node");
1524 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_port_id =
1525 	TOKEN_NUM_INITIALIZER(
1526 		struct cmd_add_port_tm_nonleaf_node_result,
1527 		 port_id, UINT16);
1528 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_node_id =
1529 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1530 		 node_id, UINT32);
1531 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_parent_node_id =
1532 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1533 		 parent_node_id, INT32);
1534 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_priority =
1535 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1536 		 priority, UINT32);
1537 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_weight =
1538 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1539 		 weight, UINT32);
1540 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_level_id =
1541 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1542 		 level_id, UINT32);
1543 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_shaper_profile_id =
1544 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1545 		 shaper_profile_id, UINT32);
1546 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_n_sp_priorities =
1547 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1548 		 n_sp_priorities, UINT32);
1549 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_stats_mask =
1550 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1551 		 stats_mask, UINT64);
1552 cmdline_parse_token_string_t
1553 	cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id =
1554 	TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1555 		 multi_shared_shaper_id, TOKEN_STRING_MULTI);
1556 
1557 static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result,
1558 	__attribute__((unused)) struct cmdline *cl,
1559 	__attribute__((unused)) void *data)
1560 {
1561 	struct cmd_add_port_tm_nonleaf_node_result *res = parsed_result;
1562 	struct rte_tm_error error;
1563 	struct rte_tm_node_params np;
1564 	uint32_t *shared_shaper_id;
1565 	uint32_t parent_node_id, n_shared_shapers = 0;
1566 	char *s_str = res->multi_shared_shaper_id;
1567 	portid_t port_id = res->port_id;
1568 	int ret;
1569 
1570 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1571 		return;
1572 
1573 	memset(&np, 0, sizeof(struct rte_tm_node_params));
1574 
1575 	/* Node parameters */
1576 	if (res->parent_node_id < 0)
1577 		parent_node_id = UINT32_MAX;
1578 	else
1579 		parent_node_id = res->parent_node_id;
1580 
1581 	shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1582 		sizeof(uint32_t));
1583 	if (shared_shaper_id == NULL) {
1584 		printf(" Memory not allocated for shared shapers (error)\n");
1585 		return;
1586 	}
1587 
1588 	/* Parse multi shared shaper id string */
1589 	ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
1590 	if (ret) {
1591 		printf(" Shared shapers params string parse error\n");
1592 		free(shared_shaper_id);
1593 		return;
1594 	}
1595 
1596 	np.shaper_profile_id = res->shaper_profile_id;
1597 	np.n_shared_shapers = n_shared_shapers;
1598 	if (np.n_shared_shapers)
1599 		np.shared_shaper_id = &shared_shaper_id[0];
1600 	else
1601 		np.shared_shaper_id = NULL;
1602 
1603 	np.nonleaf.n_sp_priorities = res->n_sp_priorities;
1604 	np.stats_mask = res->stats_mask;
1605 	np.nonleaf.wfq_weight_mode = NULL;
1606 
1607 	ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
1608 				res->priority, res->weight, res->level_id,
1609 				&np, &error);
1610 	if (ret != 0) {
1611 		print_err_msg(&error);
1612 		free(shared_shaper_id);
1613 		return;
1614 	}
1615 }
1616 
1617 cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node = {
1618 	.f = cmd_add_port_tm_nonleaf_node_parsed,
1619 	.data = NULL,
1620 	.help_str = "Add port tm nonleaf node",
1621 	.tokens = {
1622 		(void *)&cmd_add_port_tm_nonleaf_node_add,
1623 		(void *)&cmd_add_port_tm_nonleaf_node_port,
1624 		(void *)&cmd_add_port_tm_nonleaf_node_tm,
1625 		(void *)&cmd_add_port_tm_nonleaf_node_nonleaf,
1626 		(void *)&cmd_add_port_tm_nonleaf_node_node,
1627 		(void *)&cmd_add_port_tm_nonleaf_node_port_id,
1628 		(void *)&cmd_add_port_tm_nonleaf_node_node_id,
1629 		(void *)&cmd_add_port_tm_nonleaf_node_parent_node_id,
1630 		(void *)&cmd_add_port_tm_nonleaf_node_priority,
1631 		(void *)&cmd_add_port_tm_nonleaf_node_weight,
1632 		(void *)&cmd_add_port_tm_nonleaf_node_level_id,
1633 		(void *)&cmd_add_port_tm_nonleaf_node_shaper_profile_id,
1634 		(void *)&cmd_add_port_tm_nonleaf_node_n_sp_priorities,
1635 		(void *)&cmd_add_port_tm_nonleaf_node_stats_mask,
1636 		(void *)&cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id,
1637 		NULL,
1638 	},
1639 };
1640 
1641 /* *** Add Port TM leaf node *** */
1642 struct cmd_add_port_tm_leaf_node_result {
1643 	cmdline_fixed_string_t add;
1644 	cmdline_fixed_string_t port;
1645 	cmdline_fixed_string_t tm;
1646 	cmdline_fixed_string_t leaf;
1647 	cmdline_fixed_string_t node;
1648 	uint16_t port_id;
1649 	uint32_t node_id;
1650 	int32_t parent_node_id;
1651 	uint32_t priority;
1652 	uint32_t weight;
1653 	uint32_t level_id;
1654 	uint32_t shaper_profile_id;
1655 	uint32_t cman_mode;
1656 	uint32_t wred_profile_id;
1657 	uint64_t stats_mask;
1658 	cmdline_multi_string_t multi_shared_shaper_id;
1659 };
1660 
1661 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_add =
1662 	TOKEN_STRING_INITIALIZER(
1663 		struct cmd_add_port_tm_leaf_node_result, add, "add");
1664 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_port =
1665 	TOKEN_STRING_INITIALIZER(
1666 		struct cmd_add_port_tm_leaf_node_result, port, "port");
1667 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_tm =
1668 	TOKEN_STRING_INITIALIZER(
1669 		struct cmd_add_port_tm_leaf_node_result, tm, "tm");
1670 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_nonleaf =
1671 	TOKEN_STRING_INITIALIZER(
1672 		struct cmd_add_port_tm_leaf_node_result, leaf, "leaf");
1673 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_node =
1674 	TOKEN_STRING_INITIALIZER(
1675 		struct cmd_add_port_tm_leaf_node_result, node, "node");
1676 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_port_id =
1677 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1678 		 port_id, UINT16);
1679 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_node_id =
1680 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1681 		 node_id, UINT32);
1682 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_parent_node_id =
1683 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1684 		 parent_node_id, INT32);
1685 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_priority =
1686 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1687 		 priority, UINT32);
1688 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_weight =
1689 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1690 		 weight, UINT32);
1691 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_level_id =
1692 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1693 		 level_id, UINT32);
1694 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_shaper_profile_id =
1695 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1696 		 shaper_profile_id, UINT32);
1697 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_cman_mode =
1698 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1699 		 cman_mode, UINT32);
1700 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_wred_profile_id =
1701 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1702 		 wred_profile_id, UINT32);
1703 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_stats_mask =
1704 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1705 		 stats_mask, UINT64);
1706 cmdline_parse_token_string_t
1707 	cmd_add_port_tm_leaf_node_multi_shared_shaper_id =
1708 	TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1709 		 multi_shared_shaper_id, TOKEN_STRING_MULTI);
1710 
1711 static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result,
1712 	__attribute__((unused)) struct cmdline *cl,
1713 	__attribute__((unused)) void *data)
1714 {
1715 	struct cmd_add_port_tm_leaf_node_result *res = parsed_result;
1716 	struct rte_tm_error error;
1717 	struct rte_tm_node_params np;
1718 	uint32_t *shared_shaper_id;
1719 	uint32_t parent_node_id, n_shared_shapers = 0;
1720 	portid_t port_id = res->port_id;
1721 	char *s_str = res->multi_shared_shaper_id;
1722 	int ret;
1723 
1724 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1725 		return;
1726 
1727 	memset(&np, 0, sizeof(struct rte_tm_node_params));
1728 
1729 	/* Node parameters */
1730 	if (res->parent_node_id < 0)
1731 		parent_node_id = UINT32_MAX;
1732 	else
1733 		parent_node_id = res->parent_node_id;
1734 
1735 	shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1736 		sizeof(uint32_t));
1737 	if (shared_shaper_id == NULL) {
1738 		printf(" Memory not allocated for shared shapers (error)\n");
1739 		return;
1740 	}
1741 
1742 	/* Parse multi shared shaper id string */
1743 	ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
1744 	if (ret) {
1745 		printf(" Shared shapers params string parse error\n");
1746 		free(shared_shaper_id);
1747 		return;
1748 	}
1749 
1750 	np.shaper_profile_id = res->shaper_profile_id;
1751 	np.n_shared_shapers = n_shared_shapers;
1752 
1753 	if (np.n_shared_shapers)
1754 		np.shared_shaper_id = &shared_shaper_id[0];
1755 	else
1756 		np.shared_shaper_id = NULL;
1757 
1758 	np.leaf.cman = res->cman_mode;
1759 	np.leaf.wred.wred_profile_id = res->wred_profile_id;
1760 	np.stats_mask = res->stats_mask;
1761 
1762 	ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
1763 				res->priority, res->weight, res->level_id,
1764 				&np, &error);
1765 	if (ret != 0) {
1766 		print_err_msg(&error);
1767 		free(shared_shaper_id);
1768 		return;
1769 	}
1770 }
1771 
1772 cmdline_parse_inst_t cmd_add_port_tm_leaf_node = {
1773 	.f = cmd_add_port_tm_leaf_node_parsed,
1774 	.data = NULL,
1775 	.help_str = "Add port tm leaf node",
1776 	.tokens = {
1777 		(void *)&cmd_add_port_tm_leaf_node_add,
1778 		(void *)&cmd_add_port_tm_leaf_node_port,
1779 		(void *)&cmd_add_port_tm_leaf_node_tm,
1780 		(void *)&cmd_add_port_tm_leaf_node_nonleaf,
1781 		(void *)&cmd_add_port_tm_leaf_node_node,
1782 		(void *)&cmd_add_port_tm_leaf_node_port_id,
1783 		(void *)&cmd_add_port_tm_leaf_node_node_id,
1784 		(void *)&cmd_add_port_tm_leaf_node_parent_node_id,
1785 		(void *)&cmd_add_port_tm_leaf_node_priority,
1786 		(void *)&cmd_add_port_tm_leaf_node_weight,
1787 		(void *)&cmd_add_port_tm_leaf_node_level_id,
1788 		(void *)&cmd_add_port_tm_leaf_node_shaper_profile_id,
1789 		(void *)&cmd_add_port_tm_leaf_node_cman_mode,
1790 		(void *)&cmd_add_port_tm_leaf_node_wred_profile_id,
1791 		(void *)&cmd_add_port_tm_leaf_node_stats_mask,
1792 		(void *)&cmd_add_port_tm_leaf_node_multi_shared_shaper_id,
1793 		NULL,
1794 	},
1795 };
1796 
1797 /* *** Delete Port TM Node *** */
1798 struct cmd_del_port_tm_node_result {
1799 	cmdline_fixed_string_t del;
1800 	cmdline_fixed_string_t port;
1801 	cmdline_fixed_string_t tm;
1802 	cmdline_fixed_string_t node;
1803 	uint16_t port_id;
1804 	uint32_t node_id;
1805 };
1806 
1807 cmdline_parse_token_string_t cmd_del_port_tm_node_del =
1808 	TOKEN_STRING_INITIALIZER(
1809 		struct cmd_del_port_tm_node_result, del, "del");
1810 cmdline_parse_token_string_t cmd_del_port_tm_node_port =
1811 	TOKEN_STRING_INITIALIZER(
1812 		struct cmd_del_port_tm_node_result, port, "port");
1813 cmdline_parse_token_string_t cmd_del_port_tm_node_tm =
1814 	TOKEN_STRING_INITIALIZER(
1815 		struct cmd_del_port_tm_node_result, tm, "tm");
1816 cmdline_parse_token_string_t cmd_del_port_tm_node_node =
1817 	TOKEN_STRING_INITIALIZER(
1818 		struct cmd_del_port_tm_node_result, node, "node");
1819 cmdline_parse_token_num_t cmd_del_port_tm_node_port_id =
1820 	TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result,
1821 		 port_id, UINT16);
1822 cmdline_parse_token_num_t cmd_del_port_tm_node_node_id =
1823 	TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result,
1824 		node_id, UINT32);
1825 
1826 static void cmd_del_port_tm_node_parsed(void *parsed_result,
1827 	__attribute__((unused)) struct cmdline *cl,
1828 	__attribute__((unused)) void *data)
1829 {
1830 	struct cmd_del_port_tm_node_result *res = parsed_result;
1831 	struct rte_tm_error error;
1832 	uint32_t node_id = res->node_id;
1833 	portid_t port_id = res->port_id;
1834 	int ret;
1835 
1836 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1837 		return;
1838 
1839 	/* Port status */
1840 	if (port_is_started(port_id)) {
1841 		printf(" Port %u not stopped (error)\n", port_id);
1842 		return;
1843 	}
1844 
1845 	ret = rte_tm_node_delete(port_id, node_id, &error);
1846 	if (ret != 0) {
1847 		print_err_msg(&error);
1848 		return;
1849 	}
1850 }
1851 
1852 cmdline_parse_inst_t cmd_del_port_tm_node = {
1853 	.f = cmd_del_port_tm_node_parsed,
1854 	.data = NULL,
1855 	.help_str = "Delete port tm node",
1856 	.tokens = {
1857 		(void *)&cmd_del_port_tm_node_del,
1858 		(void *)&cmd_del_port_tm_node_port,
1859 		(void *)&cmd_del_port_tm_node_tm,
1860 		(void *)&cmd_del_port_tm_node_node,
1861 		(void *)&cmd_del_port_tm_node_port_id,
1862 		(void *)&cmd_del_port_tm_node_node_id,
1863 		NULL,
1864 	},
1865 };
1866 
1867 /* *** Update Port TM Node Parent *** */
1868 struct cmd_set_port_tm_node_parent_result {
1869 	cmdline_fixed_string_t set;
1870 	cmdline_fixed_string_t port;
1871 	cmdline_fixed_string_t tm;
1872 	cmdline_fixed_string_t node;
1873 	cmdline_fixed_string_t parent;
1874 	uint16_t port_id;
1875 	uint32_t node_id;
1876 	uint32_t parent_id;
1877 	uint32_t priority;
1878 	uint32_t weight;
1879 };
1880 
1881 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_set =
1882 	TOKEN_STRING_INITIALIZER(
1883 		struct cmd_set_port_tm_node_parent_result, set, "set");
1884 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_port =
1885 	TOKEN_STRING_INITIALIZER(
1886 		struct cmd_set_port_tm_node_parent_result, port, "port");
1887 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_tm =
1888 	TOKEN_STRING_INITIALIZER(
1889 		struct cmd_set_port_tm_node_parent_result, tm, "tm");
1890 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_node =
1891 	TOKEN_STRING_INITIALIZER(
1892 		struct cmd_set_port_tm_node_parent_result, node, "node");
1893 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_parent =
1894 	TOKEN_STRING_INITIALIZER(
1895 		struct cmd_set_port_tm_node_parent_result, parent, "parent");
1896 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_port_id =
1897 	TOKEN_NUM_INITIALIZER(
1898 		struct cmd_set_port_tm_node_parent_result, port_id, UINT16);
1899 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_node_id =
1900 	TOKEN_NUM_INITIALIZER(
1901 		struct cmd_set_port_tm_node_parent_result, node_id, UINT32);
1902 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_parent_id =
1903 	TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1904 		parent_id, UINT32);
1905 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_priority =
1906 	TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1907 		priority, UINT32);
1908 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_weight =
1909 	TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
1910 		weight, UINT32);
1911 
1912 static void cmd_set_port_tm_node_parent_parsed(void *parsed_result,
1913 	__attribute__((unused)) struct cmdline *cl,
1914 	__attribute__((unused)) void *data)
1915 {
1916 	struct cmd_set_port_tm_node_parent_result *res = parsed_result;
1917 	struct rte_tm_error error;
1918 	uint32_t node_id = res->node_id;
1919 	uint32_t parent_id = res->parent_id;
1920 	uint32_t priority = res->priority;
1921 	uint32_t weight = res->weight;
1922 	portid_t port_id = res->port_id;
1923 	int ret;
1924 
1925 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1926 		return;
1927 
1928 	/* Port status */
1929 	if (!port_is_started(port_id)) {
1930 		printf(" Port %u not started (error)\n", port_id);
1931 		return;
1932 	}
1933 
1934 	ret = rte_tm_node_parent_update(port_id, node_id,
1935 		parent_id, priority, weight, &error);
1936 	if (ret != 0) {
1937 		print_err_msg(&error);
1938 		return;
1939 	}
1940 }
1941 
1942 cmdline_parse_inst_t cmd_set_port_tm_node_parent = {
1943 	.f = cmd_set_port_tm_node_parent_parsed,
1944 	.data = NULL,
1945 	.help_str = "Set port tm node parent",
1946 	.tokens = {
1947 		(void *)&cmd_set_port_tm_node_parent_set,
1948 		(void *)&cmd_set_port_tm_node_parent_port,
1949 		(void *)&cmd_set_port_tm_node_parent_tm,
1950 		(void *)&cmd_set_port_tm_node_parent_node,
1951 		(void *)&cmd_set_port_tm_node_parent_parent,
1952 		(void *)&cmd_set_port_tm_node_parent_port_id,
1953 		(void *)&cmd_set_port_tm_node_parent_node_id,
1954 		(void *)&cmd_set_port_tm_node_parent_parent_id,
1955 		(void *)&cmd_set_port_tm_node_parent_priority,
1956 		(void *)&cmd_set_port_tm_node_parent_weight,
1957 		NULL,
1958 	},
1959 };
1960 
1961 /* *** Port TM Hierarchy Commit *** */
1962 struct cmd_port_tm_hierarchy_commit_result {
1963 	cmdline_fixed_string_t port;
1964 	cmdline_fixed_string_t tm;
1965 	cmdline_fixed_string_t hierarchy;
1966 	cmdline_fixed_string_t commit;
1967 	uint16_t port_id;
1968 	cmdline_fixed_string_t clean_on_fail;
1969 };
1970 
1971 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_port =
1972 	TOKEN_STRING_INITIALIZER(
1973 		struct cmd_port_tm_hierarchy_commit_result, port, "port");
1974 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_tm =
1975 	TOKEN_STRING_INITIALIZER(
1976 		struct cmd_port_tm_hierarchy_commit_result, tm, "tm");
1977 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_hierarchy =
1978 	TOKEN_STRING_INITIALIZER(
1979 		struct cmd_port_tm_hierarchy_commit_result,
1980 			hierarchy, "hierarchy");
1981 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_commit =
1982 	TOKEN_STRING_INITIALIZER(
1983 		struct cmd_port_tm_hierarchy_commit_result, commit, "commit");
1984 cmdline_parse_token_num_t cmd_port_tm_hierarchy_commit_port_id =
1985 	TOKEN_NUM_INITIALIZER(
1986 		struct cmd_port_tm_hierarchy_commit_result,
1987 			port_id, UINT16);
1988 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_clean_on_fail =
1989 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_hierarchy_commit_result,
1990 		 clean_on_fail, "yes#no");
1991 
1992 static void cmd_port_tm_hierarchy_commit_parsed(void *parsed_result,
1993 	__attribute__((unused)) struct cmdline *cl,
1994 	__attribute__((unused)) void *data)
1995 {
1996 	struct cmd_port_tm_hierarchy_commit_result *res = parsed_result;
1997 	struct rte_tm_error error;
1998 	uint32_t clean_on_fail;
1999 	portid_t port_id = res->port_id;
2000 	int ret;
2001 
2002 	if (port_id_is_invalid(port_id, ENABLED_WARN))
2003 		return;
2004 
2005 	if (strcmp(res->clean_on_fail, "yes") == 0)
2006 		clean_on_fail = 1;
2007 	else
2008 		clean_on_fail = 0;
2009 
2010 	ret = rte_tm_hierarchy_commit(port_id, clean_on_fail, &error);
2011 	if (ret != 0) {
2012 		print_err_msg(&error);
2013 		return;
2014 	}
2015 }
2016 
2017 cmdline_parse_inst_t cmd_port_tm_hierarchy_commit = {
2018 	.f = cmd_port_tm_hierarchy_commit_parsed,
2019 	.data = NULL,
2020 	.help_str = "Set port tm node shaper profile",
2021 	.tokens = {
2022 		(void *)&cmd_port_tm_hierarchy_commit_port,
2023 		(void *)&cmd_port_tm_hierarchy_commit_tm,
2024 		(void *)&cmd_port_tm_hierarchy_commit_hierarchy,
2025 		(void *)&cmd_port_tm_hierarchy_commit_commit,
2026 		(void *)&cmd_port_tm_hierarchy_commit_port_id,
2027 		(void *)&cmd_port_tm_hierarchy_commit_clean_on_fail,
2028 		NULL,
2029 	},
2030 };
2031