xref: /dpdk/app/test-pmd/cmdline_tm.c (revision 68a03efeed657e6e05f281479b33b51102797e15)
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_PACKET_MODE]
58 			= "packet mode field (shaper profile)",
59 		[RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID] = "shaper profile id",
60 		[RTE_TM_ERROR_TYPE_SHARED_SHAPER_ID] = "shared shaper id",
61 		[RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID] = "parent node id",
62 		[RTE_TM_ERROR_TYPE_NODE_PRIORITY] = "node priority",
63 		[RTE_TM_ERROR_TYPE_NODE_WEIGHT] = "node weight",
64 		[RTE_TM_ERROR_TYPE_NODE_PARAMS] = "node parameter null",
65 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID]
66 			= "shaper profile id field (node params)",
67 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID]
68 			= "shared shaper id field (node params)",
69 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS]
70 			= "num shared shapers field (node params)",
71 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE]
72 			= "wfq weght mode field (node params)",
73 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES]
74 			= "num strict priorities field (node params)",
75 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN]
76 			= "congestion management mode field (node params)",
77 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID] =
78 			"wred profile id field (node params)",
79 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID]
80 			= "shared wred context id field (node params)",
81 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS]
82 			= "num shared wred contexts field (node params)",
83 		[RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS]
84 			= "stats field (node params)",
85 		[RTE_TM_ERROR_TYPE_NODE_ID] = "node id",
86 	};
87 
88 	const char *errstr;
89 	char buf[64];
90 
91 	if ((unsigned int)error->type >= RTE_DIM(errstrlist) ||
92 		!errstrlist[error->type])
93 		errstr = "unknown type";
94 	else
95 		errstr = errstrlist[error->type];
96 
97 	if (error->cause)
98 		snprintf(buf, sizeof(buf), "cause: %p, ", error->cause);
99 
100 	printf("%s: %s%s (error %d)\n", errstr, error->cause ? buf : "",
101 		error->message ? error->message : "(no stated reason)",
102 		error->type);
103 }
104 
105 static int
106 read_uint64(uint64_t *value, const char *p)
107 {
108 	char *next;
109 	uint64_t val;
110 
111 	p = skip_white_spaces(p);
112 	if (!isdigit(*p))
113 		return -EINVAL;
114 
115 	val = strtoul(p, &next, 10);
116 	if (p == next)
117 		return -EINVAL;
118 
119 	p = next;
120 	switch (*p) {
121 	case 'T':
122 		val *= 1024ULL;
123 		/* fall through */
124 	case 'G':
125 		val *= 1024ULL;
126 		/* fall through */
127 	case 'M':
128 		val *= 1024ULL;
129 		/* fall through */
130 	case 'k':
131 	case 'K':
132 		val *= 1024ULL;
133 		p++;
134 		break;
135 	}
136 
137 	p = skip_white_spaces(p);
138 	if (*p != '\0')
139 		return -EINVAL;
140 
141 	*value = val;
142 	return 0;
143 }
144 
145 static int
146 read_uint32(uint32_t *value, const char *p)
147 {
148 	uint64_t val = 0;
149 	int ret = read_uint64(&val, p);
150 
151 	if (ret < 0)
152 		return ret;
153 
154 	if (val > UINT32_MAX)
155 		return -ERANGE;
156 
157 	*value = val;
158 	return 0;
159 }
160 
161 static int
162 parse_multi_ss_id_str(char *s_str, uint32_t *n_ssp, uint32_t shaper_id[])
163 {
164 	uint32_t n_shared_shapers = 0, i = 0;
165 	char *token;
166 
167 	/* First token: num of shared shapers */
168 	token = strtok_r(s_str, PARSE_DELIMITER, &s_str);
169 	if (token ==  NULL)
170 		return -1;
171 
172 	if (read_uint32(&n_shared_shapers, token))
173 		return -1;
174 
175 	/* Check: num of shared shaper */
176 	if (n_shared_shapers >= MAX_NUM_SHARED_SHAPERS) {
177 		printf(" Number of shared shapers exceed the max (error)\n");
178 		return -1;
179 	}
180 
181 	/* Parse shared shaper ids */
182 	while (1) {
183 		token = strtok_r(s_str, PARSE_DELIMITER, &s_str);
184 		if ((token !=  NULL && n_shared_shapers == 0) ||
185 			(token == NULL && i < n_shared_shapers))
186 			return -1;
187 
188 		if (token == NULL)
189 			break;
190 
191 		if (read_uint32(&shaper_id[i], token))
192 			return -1;
193 		i++;
194 	}
195 	*n_ssp = n_shared_shapers;
196 
197 	return 0;
198 }
199 /* *** Port TM Capability *** */
200 struct cmd_show_port_tm_cap_result {
201 	cmdline_fixed_string_t show;
202 	cmdline_fixed_string_t port;
203 	cmdline_fixed_string_t tm;
204 	cmdline_fixed_string_t cap;
205 	uint16_t port_id;
206 };
207 
208 cmdline_parse_token_string_t cmd_show_port_tm_cap_show =
209 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
210 		show, "show");
211 cmdline_parse_token_string_t cmd_show_port_tm_cap_port =
212 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
213 		port, "port");
214 cmdline_parse_token_string_t cmd_show_port_tm_cap_tm =
215 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
216 		tm, "tm");
217 cmdline_parse_token_string_t cmd_show_port_tm_cap_cap =
218 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result,
219 		cap, "cap");
220 cmdline_parse_token_num_t cmd_show_port_tm_cap_port_id =
221 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_cap_result,
222 		 port_id, RTE_UINT16);
223 
224 static void cmd_show_port_tm_cap_parsed(void *parsed_result,
225 	__rte_unused struct cmdline *cl,
226 	__rte_unused void *data)
227 {
228 	struct cmd_show_port_tm_cap_result *res = parsed_result;
229 	struct rte_tm_capabilities cap;
230 	struct rte_tm_error error;
231 	portid_t port_id = res->port_id;
232 	uint32_t i;
233 	int ret;
234 
235 	if (port_id_is_invalid(port_id, ENABLED_WARN))
236 		return;
237 
238 	memset(&cap, 0, sizeof(struct rte_tm_capabilities));
239 	memset(&error, 0, sizeof(struct rte_tm_error));
240 	ret = rte_tm_capabilities_get(port_id, &cap, &error);
241 	if (ret) {
242 		print_err_msg(&error);
243 		return;
244 	}
245 
246 	printf("\n****   Port TM Capabilities ****\n\n");
247 	printf("cap.n_nodes_max %" PRIu32 "\n", cap.n_nodes_max);
248 	printf("cap.n_levels_max %" PRIu32 "\n", cap.n_levels_max);
249 	printf("cap.non_leaf_nodes_identical %" PRId32 "\n",
250 		cap.non_leaf_nodes_identical);
251 	printf("cap.leaf_nodes_identical %" PRId32 "\n",
252 		cap.leaf_nodes_identical);
253 	printf("cap.shaper_n_max %u\n", cap.shaper_n_max);
254 	printf("cap.shaper_private_n_max %" PRIu32 "\n",
255 		cap.shaper_private_n_max);
256 	printf("cap.shaper_private_dual_rate_n_max %" PRId32 "\n",
257 		cap.shaper_private_dual_rate_n_max);
258 	printf("cap.shaper_private_rate_min %" PRIu64 "\n",
259 		cap.shaper_private_rate_min);
260 	printf("cap.shaper_private_rate_max %" PRIu64 "\n",
261 		cap.shaper_private_rate_max);
262 	printf("cap.shaper_private_packet_mode_supported %" PRId32 "\n",
263 		cap.shaper_private_packet_mode_supported);
264 	printf("cap.shaper_private_byte_mode_supported %" PRId32 "\n",
265 		cap.shaper_private_byte_mode_supported);
266 	printf("cap.shaper_shared_n_max %" PRIu32 "\n",
267 		cap.shaper_shared_n_max);
268 	printf("cap.shaper_shared_n_nodes_per_shaper_max %" PRIu32 "\n",
269 		cap.shaper_shared_n_nodes_per_shaper_max);
270 	printf("cap.shaper_shared_n_shapers_per_node_max %" PRIu32 "\n",
271 		cap.shaper_shared_n_shapers_per_node_max);
272 	printf("cap.shaper_shared_dual_rate_n_max %" PRIu32 "\n",
273 		cap.shaper_shared_dual_rate_n_max);
274 	printf("cap.shaper_shared_rate_min %" PRIu64 "\n",
275 		cap.shaper_shared_rate_min);
276 	printf("cap.shaper_shared_rate_max %" PRIu64 "\n",
277 		cap.shaper_shared_rate_max);
278 	printf("cap.shaper_shared_packet_mode_supported %" PRId32 "\n",
279 		cap.shaper_shared_packet_mode_supported);
280 	printf("cap.shaper_shared_byte_mode_supported %" PRId32 "\n",
281 		cap.shaper_shared_byte_mode_supported);
282 	printf("cap.shaper_pkt_length_adjust_min %" PRId32 "\n",
283 		cap.shaper_pkt_length_adjust_min);
284 	printf("cap.shaper_pkt_length_adjust_max %" PRId32 "\n",
285 		cap.shaper_pkt_length_adjust_max);
286 	printf("cap.sched_n_children_max %" PRIu32 "\n",
287 		cap.sched_n_children_max);
288 	printf("cap.sched_sp_n_priorities_max %" PRIu32 "\n",
289 		cap.sched_sp_n_priorities_max);
290 	printf("cap.sched_wfq_n_children_per_group_max %" PRIu32 "\n",
291 		cap.sched_wfq_n_children_per_group_max);
292 	printf("cap.sched_wfq_n_groups_max %" PRIu32 "\n",
293 		cap.sched_wfq_n_groups_max);
294 	printf("cap.sched_wfq_weight_max %" PRIu32 "\n",
295 		cap.sched_wfq_weight_max);
296 	printf("cap.sched_wfq_packet_mode_supported %" PRId32 "\n",
297 		cap.sched_wfq_packet_mode_supported);
298 	printf("cap.sched_wfq_byte_mode_supported %" PRId32 "\n",
299 		cap.sched_wfq_byte_mode_supported);
300 	printf("cap.cman_head_drop_supported %" PRId32 "\n",
301 		cap.cman_head_drop_supported);
302 	printf("cap.cman_wred_context_n_max %" PRIu32 "\n",
303 		cap.cman_wred_context_n_max);
304 	printf("cap.cman_wred_context_private_n_max %" PRIu32 "\n",
305 		cap.cman_wred_context_private_n_max);
306 	printf("cap.cman_wred_context_shared_n_max %" PRIu32 "\n",
307 		cap.cman_wred_context_shared_n_max);
308 	printf("cap.cman_wred_context_shared_n_nodes_per_context_max %" PRIu32
309 		"\n", cap.cman_wred_context_shared_n_nodes_per_context_max);
310 	printf("cap.cman_wred_context_shared_n_contexts_per_node_max %" PRIu32
311 		"\n", cap.cman_wred_context_shared_n_contexts_per_node_max);
312 
313 	for (i = 0; i < RTE_COLORS; i++) {
314 		printf("cap.mark_vlan_dei_supported %" PRId32 "\n",
315 			cap.mark_vlan_dei_supported[i]);
316 		printf("cap.mark_ip_ecn_tcp_supported %" PRId32 "\n",
317 			cap.mark_ip_ecn_tcp_supported[i]);
318 		printf("cap.mark_ip_ecn_sctp_supported %" PRId32 "\n",
319 			cap.mark_ip_ecn_sctp_supported[i]);
320 		printf("cap.mark_ip_dscp_supported %" PRId32 "\n",
321 			cap.mark_ip_dscp_supported[i]);
322 	}
323 
324 	printf("cap.dynamic_update_mask %" PRIx64 "\n",
325 		cap.dynamic_update_mask);
326 	printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask);
327 }
328 
329 cmdline_parse_inst_t cmd_show_port_tm_cap = {
330 	.f = cmd_show_port_tm_cap_parsed,
331 	.data = NULL,
332 	.help_str = "Show Port TM Capabilities",
333 	.tokens = {
334 		(void *)&cmd_show_port_tm_cap_show,
335 		(void *)&cmd_show_port_tm_cap_port,
336 		(void *)&cmd_show_port_tm_cap_tm,
337 		(void *)&cmd_show_port_tm_cap_cap,
338 		(void *)&cmd_show_port_tm_cap_port_id,
339 		NULL,
340 	},
341 };
342 
343 /* *** Port TM Hierarchical Level Capability *** */
344 struct cmd_show_port_tm_level_cap_result {
345 	cmdline_fixed_string_t show;
346 	cmdline_fixed_string_t port;
347 	cmdline_fixed_string_t tm;
348 	cmdline_fixed_string_t level;
349 	cmdline_fixed_string_t cap;
350 	uint16_t port_id;
351 	uint32_t level_id;
352 };
353 
354 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_show =
355 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
356 		show, "show");
357 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_port =
358 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
359 		port, "port");
360 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_tm =
361 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
362 		tm, "tm");
363 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_level =
364 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
365 		level, "level");
366 cmdline_parse_token_string_t cmd_show_port_tm_level_cap_cap =
367 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
368 		cap, "cap");
369 cmdline_parse_token_num_t cmd_show_port_tm_level_cap_port_id =
370 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
371 		 port_id, RTE_UINT16);
372 cmdline_parse_token_num_t cmd_show_port_tm_level_cap_level_id =
373 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result,
374 		 level_id, RTE_UINT32);
375 
376 
377 static void cmd_show_port_tm_level_cap_parsed(void *parsed_result,
378 	__rte_unused struct cmdline *cl,
379 	__rte_unused void *data)
380 {
381 	struct cmd_show_port_tm_level_cap_result *res = parsed_result;
382 	struct rte_tm_level_capabilities lcap;
383 	struct rte_tm_error error;
384 	portid_t port_id = res->port_id;
385 	uint32_t level_id = res->level_id;
386 	int ret;
387 
388 	if (port_id_is_invalid(port_id, ENABLED_WARN))
389 		return;
390 
391 	memset(&lcap, 0, sizeof(struct rte_tm_level_capabilities));
392 	memset(&error, 0, sizeof(struct rte_tm_error));
393 	ret = rte_tm_level_capabilities_get(port_id, level_id, &lcap, &error);
394 	if (ret) {
395 		print_err_msg(&error);
396 		return;
397 	}
398 	printf("\n**   Port TM Hierarchy level %" PRIu32 " Capability **\n\n",
399 		level_id);
400 
401 	printf("cap.n_nodes_max %" PRIu32 "\n", lcap.n_nodes_max);
402 	printf("cap.n_nodes_nonleaf_max %" PRIu32 "\n",
403 		lcap.n_nodes_nonleaf_max);
404 	printf("cap.n_nodes_leaf_max %" PRIu32 "\n", lcap.n_nodes_leaf_max);
405 	printf("cap.non_leaf_nodes_identical %" PRId32 "\n",
406 		lcap.non_leaf_nodes_identical);
407 	printf("cap.leaf_nodes_identical %" PRId32 "\n",
408 		lcap.leaf_nodes_identical);
409 	if (level_id <= 3) {
410 		printf("cap.nonleaf.shaper_private_supported %" PRId32 "\n",
411 			lcap.nonleaf.shaper_private_supported);
412 		printf("cap.nonleaf.shaper_private_dual_rate_supported %" PRId32
413 			"\n", lcap.nonleaf.shaper_private_dual_rate_supported);
414 		printf("cap.nonleaf.shaper_private_rate_min %" PRIu64 "\n",
415 			lcap.nonleaf.shaper_private_rate_min);
416 		printf("cap.nonleaf.shaper_private_rate_max %" PRIu64 "\n",
417 			lcap.nonleaf.shaper_private_rate_max);
418 		printf("cap.nonleaf.shaper_private_packet_mode_supported %"
419 		       PRId32 "\n",
420 			lcap.nonleaf.shaper_private_packet_mode_supported);
421 		printf("cap.nonleaf.shaper_private_byte_mode_supported %" PRId32
422 		       "\n", lcap.nonleaf.shaper_private_byte_mode_supported);
423 		printf("cap.nonleaf.shaper_shared_n_max %" PRIu32 "\n",
424 			lcap.nonleaf.shaper_shared_n_max);
425 		printf("cap.nonleaf.shaper_shared_packet_mode_supported %"
426 		       PRId32 "\n",
427 		       lcap.nonleaf.shaper_shared_packet_mode_supported);
428 		printf("cap.nonleaf.shaper_shared_byte_mode_supported %"
429 		       PRId32 "\n",
430 		       lcap.nonleaf.shaper_shared_byte_mode_supported);
431 		printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n",
432 			lcap.nonleaf.sched_n_children_max);
433 		printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n",
434 			lcap.nonleaf.sched_sp_n_priorities_max);
435 		printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32
436 			"\n", lcap.nonleaf.sched_wfq_n_children_per_group_max);
437 		printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n",
438 			lcap.nonleaf.sched_wfq_n_groups_max);
439 		printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n",
440 			lcap.nonleaf.sched_wfq_weight_max);
441 		printf("cap.nonleaf.sched_wfq_packet_mode_supported %" PRId32 "\n",
442 			lcap.nonleaf.sched_wfq_packet_mode_supported);
443 		printf("cap.nonleaf.sched_wfq_byte_mode_supported %" PRId32
444 		       "\n", lcap.nonleaf.sched_wfq_byte_mode_supported);
445 		printf("cap.nonleaf.stats_mask %" PRIx64 "\n",
446 			lcap.nonleaf.stats_mask);
447 	} else {
448 		printf("cap.leaf.shaper_private_supported %" PRId32 "\n",
449 			lcap.leaf.shaper_private_supported);
450 		printf("cap.leaf.shaper_private_dual_rate_supported %" PRId32
451 			"\n", lcap.leaf.shaper_private_dual_rate_supported);
452 		printf("cap.leaf.shaper_private_rate_min %" PRIu64 "\n",
453 			lcap.leaf.shaper_private_rate_min);
454 		printf("cap.leaf.shaper_private_rate_max %" PRIu64 "\n",
455 			lcap.leaf.shaper_private_rate_max);
456 		printf("cap.leaf.shaper_private_packet_mode_supported %" PRId32
457 		       "\n", lcap.leaf.shaper_private_packet_mode_supported);
458 		printf("cap.leaf.shaper_private_byte_mode_supported %" PRId32 "\n",
459 			lcap.leaf.shaper_private_byte_mode_supported);
460 		printf("cap.leaf.shaper_shared_n_max %" PRIu32 "\n",
461 			lcap.leaf.shaper_shared_n_max);
462 		printf("cap.leaf.shaper_shared_packet_mode_supported %" PRId32 "\n",
463 		       lcap.leaf.shaper_shared_packet_mode_supported);
464 		printf("cap.leaf.shaper_shared_byte_mode_supported %" PRId32 "\n",
465 		       lcap.leaf.shaper_shared_byte_mode_supported);
466 		printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n",
467 			lcap.leaf.cman_head_drop_supported);
468 		printf("cap.leaf.cman_wred_context_private_supported %"	PRId32
469 			"\n", lcap.leaf.cman_wred_context_private_supported);
470 		printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n",
471 			lcap.leaf.cman_wred_context_shared_n_max);
472 		printf("cap.leaf.stats_mask %" PRIx64 "\n",
473 			lcap.leaf.stats_mask);
474 	}
475 }
476 
477 cmdline_parse_inst_t cmd_show_port_tm_level_cap = {
478 	.f = cmd_show_port_tm_level_cap_parsed,
479 	.data = NULL,
480 	.help_str = "Show Port TM Hierarhical level Capabilities",
481 	.tokens = {
482 		(void *)&cmd_show_port_tm_level_cap_show,
483 		(void *)&cmd_show_port_tm_level_cap_port,
484 		(void *)&cmd_show_port_tm_level_cap_tm,
485 		(void *)&cmd_show_port_tm_level_cap_level,
486 		(void *)&cmd_show_port_tm_level_cap_cap,
487 		(void *)&cmd_show_port_tm_level_cap_port_id,
488 		(void *)&cmd_show_port_tm_level_cap_level_id,
489 		NULL,
490 	},
491 };
492 
493 /* *** Port TM Hierarchy Node Capability *** */
494 struct cmd_show_port_tm_node_cap_result {
495 	cmdline_fixed_string_t show;
496 	cmdline_fixed_string_t port;
497 	cmdline_fixed_string_t tm;
498 	cmdline_fixed_string_t node;
499 	cmdline_fixed_string_t cap;
500 	uint16_t port_id;
501 	uint32_t node_id;
502 };
503 
504 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_show =
505 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
506 		show, "show");
507 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_port =
508 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
509 		port, "port");
510 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_tm =
511 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
512 		tm, "tm");
513 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_node =
514 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
515 		node, "node");
516 cmdline_parse_token_string_t cmd_show_port_tm_node_cap_cap =
517 	TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
518 		cap, "cap");
519 cmdline_parse_token_num_t cmd_show_port_tm_node_cap_port_id =
520 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
521 		 port_id, RTE_UINT16);
522 cmdline_parse_token_num_t cmd_show_port_tm_node_cap_node_id =
523 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result,
524 		 node_id, RTE_UINT32);
525 
526 static void cmd_show_port_tm_node_cap_parsed(void *parsed_result,
527 	__rte_unused struct cmdline *cl,
528 	__rte_unused void *data)
529 {
530 	struct cmd_show_port_tm_node_cap_result *res = parsed_result;
531 	struct rte_tm_node_capabilities ncap;
532 	struct rte_tm_error error;
533 	uint32_t node_id = res->node_id;
534 	portid_t port_id = res->port_id;
535 	int ret, is_leaf = 0;
536 
537 	if (port_id_is_invalid(port_id, ENABLED_WARN))
538 		return;
539 
540 	memset(&error, 0, sizeof(struct rte_tm_error));
541 	/* Node id must be valid */
542 	ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error);
543 	if (ret != 0) {
544 		print_err_msg(&error);
545 		return;
546 	}
547 
548 	memset(&ncap, 0, sizeof(struct rte_tm_node_capabilities));
549 	ret = rte_tm_node_capabilities_get(port_id, node_id, &ncap, &error);
550 	if (ret != 0) {
551 		print_err_msg(&error);
552 		return;
553 	}
554 	printf("\n**   Port TM Hierarchy node %" PRIu32 " Capability **\n\n",
555 		node_id);
556 	printf("cap.shaper_private_supported %" PRId32 "\n",
557 		ncap.shaper_private_supported);
558 	printf("cap.shaper_private_dual_rate_supported %" PRId32 "\n",
559 		ncap.shaper_private_dual_rate_supported);
560 	printf("cap.shaper_private_rate_min %" PRIu64 "\n",
561 		ncap.shaper_private_rate_min);
562 	printf("cap.shaper_private_rate_max %" PRIu64 "\n",
563 		ncap.shaper_private_rate_max);
564 	printf("cap.shaper_private_packet_mode_supported %" PRId32 "\n",
565 		ncap.shaper_private_packet_mode_supported);
566 	printf("cap.shaper_private_byte_mode_supported %" PRId32 "\n",
567 		ncap.shaper_private_byte_mode_supported);
568 	printf("cap.shaper_shared_n_max %" PRIu32 "\n",
569 		ncap.shaper_shared_n_max);
570 	printf("cap.shaper_shared_packet_mode_supported %" PRId32 "\n",
571 		ncap.shaper_shared_packet_mode_supported);
572 	printf("cap.shaper_shared_byte_mode_supported %" PRId32 "\n",
573 		ncap.shaper_shared_byte_mode_supported);
574 	if (!is_leaf) {
575 		printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n",
576 			ncap.nonleaf.sched_n_children_max);
577 		printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n",
578 			ncap.nonleaf.sched_sp_n_priorities_max);
579 		printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32
580 			"\n", ncap.nonleaf.sched_wfq_n_children_per_group_max);
581 		printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n",
582 			ncap.nonleaf.sched_wfq_n_groups_max);
583 		printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n",
584 			ncap.nonleaf.sched_wfq_weight_max);
585 		printf("cap.nonleaf.sched_wfq_packet_mode_supported %" PRId32 "\n",
586 			ncap.nonleaf.sched_wfq_packet_mode_supported);
587 		printf("cap.nonleaf.sched_wfq_byte_mode_supported %" PRId32 "\n",
588 			ncap.nonleaf.sched_wfq_byte_mode_supported);
589 	} else {
590 		printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n",
591 			ncap.leaf.cman_head_drop_supported);
592 		printf("cap.leaf.cman_wred_context_private_supported %" PRId32
593 			"\n", ncap.leaf.cman_wred_context_private_supported);
594 		printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n",
595 			ncap.leaf.cman_wred_context_shared_n_max);
596 	}
597 	printf("cap.stats_mask %" PRIx64 "\n", ncap.stats_mask);
598 }
599 
600 cmdline_parse_inst_t cmd_show_port_tm_node_cap = {
601 	.f = cmd_show_port_tm_node_cap_parsed,
602 	.data = NULL,
603 	.help_str = "Show Port TM Hierarchy node capabilities",
604 	.tokens = {
605 		(void *)&cmd_show_port_tm_node_cap_show,
606 		(void *)&cmd_show_port_tm_node_cap_port,
607 		(void *)&cmd_show_port_tm_node_cap_tm,
608 		(void *)&cmd_show_port_tm_node_cap_node,
609 		(void *)&cmd_show_port_tm_node_cap_cap,
610 		(void *)&cmd_show_port_tm_node_cap_port_id,
611 		(void *)&cmd_show_port_tm_node_cap_node_id,
612 		NULL,
613 	},
614 };
615 
616 /* *** Show Port TM Node Statistics *** */
617 struct cmd_show_port_tm_node_stats_result {
618 	cmdline_fixed_string_t show;
619 	cmdline_fixed_string_t port;
620 	cmdline_fixed_string_t tm;
621 	cmdline_fixed_string_t node;
622 	cmdline_fixed_string_t stats;
623 	uint16_t port_id;
624 	uint32_t node_id;
625 	uint32_t clear;
626 };
627 
628 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_show =
629 	TOKEN_STRING_INITIALIZER(
630 		struct cmd_show_port_tm_node_stats_result, show, "show");
631 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_port =
632 	TOKEN_STRING_INITIALIZER(
633 		struct cmd_show_port_tm_node_stats_result, port, "port");
634 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_tm =
635 	TOKEN_STRING_INITIALIZER(
636 		struct cmd_show_port_tm_node_stats_result, tm, "tm");
637 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_node =
638 	TOKEN_STRING_INITIALIZER(
639 		struct cmd_show_port_tm_node_stats_result, node, "node");
640 cmdline_parse_token_string_t cmd_show_port_tm_node_stats_stats =
641 	TOKEN_STRING_INITIALIZER(
642 		struct cmd_show_port_tm_node_stats_result, stats, "stats");
643 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_port_id =
644 	TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_stats_result,
645 			port_id, RTE_UINT16);
646 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_node_id =
647 	TOKEN_NUM_INITIALIZER(
648 		struct cmd_show_port_tm_node_stats_result,
649 			node_id, RTE_UINT32);
650 cmdline_parse_token_num_t cmd_show_port_tm_node_stats_clear =
651 	TOKEN_NUM_INITIALIZER(
652 		struct cmd_show_port_tm_node_stats_result, clear, RTE_UINT32);
653 
654 static void cmd_show_port_tm_node_stats_parsed(void *parsed_result,
655 	__rte_unused struct cmdline *cl,
656 	__rte_unused void *data)
657 {
658 	struct cmd_show_port_tm_node_stats_result *res = parsed_result;
659 	struct rte_tm_node_stats stats;
660 	struct rte_tm_error error;
661 	uint64_t stats_mask = 0;
662 	uint32_t node_id = res->node_id;
663 	uint32_t clear = res->clear;
664 	portid_t port_id = res->port_id;
665 	int ret;
666 
667 	if (port_id_is_invalid(port_id, ENABLED_WARN))
668 		return;
669 
670 	memset(&error, 0, sizeof(struct rte_tm_error));
671 	/* Port status */
672 	if (!port_is_started(port_id)) {
673 		printf(" Port %u not started (error)\n", port_id);
674 		return;
675 	}
676 
677 	memset(&stats, 0, sizeof(struct rte_tm_node_stats));
678 	ret = rte_tm_node_stats_read(port_id, node_id, &stats,
679 			&stats_mask, clear, &error);
680 	if (ret != 0) {
681 		print_err_msg(&error);
682 		return;
683 	}
684 
685 	/* Display stats */
686 	if (stats_mask & RTE_TM_STATS_N_PKTS)
687 		printf("\tPkts scheduled from node: %" PRIu64 "\n",
688 			stats.n_pkts);
689 	if (stats_mask & RTE_TM_STATS_N_BYTES)
690 		printf("\tBytes scheduled from node: %" PRIu64 "\n",
691 			stats.n_bytes);
692 	if (stats_mask & RTE_TM_STATS_N_PKTS_GREEN_DROPPED)
693 		printf("\tPkts dropped (green): %" PRIu64 "\n",
694 			stats.leaf.n_pkts_dropped[RTE_COLOR_GREEN]);
695 	if (stats_mask & RTE_TM_STATS_N_PKTS_YELLOW_DROPPED)
696 		printf("\tPkts dropped (yellow): %" PRIu64 "\n",
697 			stats.leaf.n_pkts_dropped[RTE_COLOR_YELLOW]);
698 	if (stats_mask & RTE_TM_STATS_N_PKTS_RED_DROPPED)
699 		printf("\tPkts dropped (red): %" PRIu64 "\n",
700 			stats.leaf.n_pkts_dropped[RTE_COLOR_RED]);
701 	if (stats_mask & RTE_TM_STATS_N_BYTES_GREEN_DROPPED)
702 		printf("\tBytes dropped (green): %" PRIu64 "\n",
703 			stats.leaf.n_bytes_dropped[RTE_COLOR_GREEN]);
704 	if (stats_mask & RTE_TM_STATS_N_BYTES_YELLOW_DROPPED)
705 		printf("\tBytes dropped (yellow): %" PRIu64 "\n",
706 			stats.leaf.n_bytes_dropped[RTE_COLOR_YELLOW]);
707 	if (stats_mask & RTE_TM_STATS_N_BYTES_RED_DROPPED)
708 		printf("\tBytes dropped (red): %" PRIu64 "\n",
709 			stats.leaf.n_bytes_dropped[RTE_COLOR_RED]);
710 	if (stats_mask & RTE_TM_STATS_N_PKTS_QUEUED)
711 		printf("\tPkts queued: %" PRIu64 "\n",
712 			stats.leaf.n_pkts_queued);
713 	if (stats_mask & RTE_TM_STATS_N_BYTES_QUEUED)
714 		printf("\tBytes queued: %" PRIu64 "\n",
715 			stats.leaf.n_bytes_queued);
716 }
717 
718 cmdline_parse_inst_t cmd_show_port_tm_node_stats = {
719 	.f = cmd_show_port_tm_node_stats_parsed,
720 	.data = NULL,
721 	.help_str = "Show port tm node stats",
722 	.tokens = {
723 		(void *)&cmd_show_port_tm_node_stats_show,
724 		(void *)&cmd_show_port_tm_node_stats_port,
725 		(void *)&cmd_show_port_tm_node_stats_tm,
726 		(void *)&cmd_show_port_tm_node_stats_node,
727 		(void *)&cmd_show_port_tm_node_stats_stats,
728 		(void *)&cmd_show_port_tm_node_stats_port_id,
729 		(void *)&cmd_show_port_tm_node_stats_node_id,
730 		(void *)&cmd_show_port_tm_node_stats_clear,
731 		NULL,
732 	},
733 };
734 
735 /* *** Show Port TM Node Type *** */
736 struct cmd_show_port_tm_node_type_result {
737 	cmdline_fixed_string_t show;
738 	cmdline_fixed_string_t port;
739 	cmdline_fixed_string_t tm;
740 	cmdline_fixed_string_t node;
741 	cmdline_fixed_string_t type;
742 	uint16_t port_id;
743 	uint32_t node_id;
744 };
745 
746 cmdline_parse_token_string_t cmd_show_port_tm_node_type_show =
747 	TOKEN_STRING_INITIALIZER(
748 		struct cmd_show_port_tm_node_type_result, show, "show");
749 cmdline_parse_token_string_t cmd_show_port_tm_node_type_port =
750 	TOKEN_STRING_INITIALIZER(
751 		struct cmd_show_port_tm_node_type_result, port, "port");
752 cmdline_parse_token_string_t cmd_show_port_tm_node_type_tm =
753 	TOKEN_STRING_INITIALIZER(
754 		struct cmd_show_port_tm_node_type_result, tm, "tm");
755 cmdline_parse_token_string_t cmd_show_port_tm_node_type_node =
756 	TOKEN_STRING_INITIALIZER(
757 		struct cmd_show_port_tm_node_type_result, node, "node");
758 cmdline_parse_token_string_t cmd_show_port_tm_node_type_type =
759 	TOKEN_STRING_INITIALIZER(
760 		struct cmd_show_port_tm_node_type_result, type, "type");
761 cmdline_parse_token_num_t cmd_show_port_tm_node_type_port_id =
762 	TOKEN_NUM_INITIALIZER(
763 		struct cmd_show_port_tm_node_type_result,
764 			port_id, RTE_UINT16);
765 cmdline_parse_token_num_t cmd_show_port_tm_node_type_node_id =
766 	TOKEN_NUM_INITIALIZER(
767 		struct cmd_show_port_tm_node_type_result,
768 			node_id, RTE_UINT32);
769 
770 static void cmd_show_port_tm_node_type_parsed(void *parsed_result,
771 	__rte_unused struct cmdline *cl,
772 	__rte_unused void *data)
773 {
774 	struct cmd_show_port_tm_node_type_result *res = parsed_result;
775 	struct rte_tm_error error;
776 	uint32_t node_id = res->node_id;
777 	portid_t port_id = res->port_id;
778 	int ret, is_leaf = 0;
779 
780 	if (port_id_is_invalid(port_id, ENABLED_WARN))
781 		return;
782 
783 	memset(&error, 0, sizeof(struct rte_tm_error));
784 	ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error);
785 	if (ret != 0) {
786 		print_err_msg(&error);
787 		return;
788 	}
789 
790 	if (is_leaf == 1)
791 		printf("leaf node\n");
792 	else
793 		printf("nonleaf node\n");
794 
795 }
796 
797 cmdline_parse_inst_t cmd_show_port_tm_node_type = {
798 	.f = cmd_show_port_tm_node_type_parsed,
799 	.data = NULL,
800 	.help_str = "Show port tm node type",
801 	.tokens = {
802 		(void *)&cmd_show_port_tm_node_type_show,
803 		(void *)&cmd_show_port_tm_node_type_port,
804 		(void *)&cmd_show_port_tm_node_type_tm,
805 		(void *)&cmd_show_port_tm_node_type_node,
806 		(void *)&cmd_show_port_tm_node_type_type,
807 		(void *)&cmd_show_port_tm_node_type_port_id,
808 		(void *)&cmd_show_port_tm_node_type_node_id,
809 		NULL,
810 	},
811 };
812 
813 /* *** Add Port TM Private Shaper Profile *** */
814 struct cmd_add_port_tm_node_shaper_profile_result {
815 	cmdline_fixed_string_t add;
816 	cmdline_fixed_string_t port;
817 	cmdline_fixed_string_t tm;
818 	cmdline_fixed_string_t node;
819 	cmdline_fixed_string_t shaper;
820 	cmdline_fixed_string_t profile;
821 	uint16_t port_id;
822 	uint32_t shaper_id;
823 	uint64_t cmit_tb_rate;
824 	uint64_t cmit_tb_size;
825 	uint64_t peak_tb_rate;
826 	uint64_t peak_tb_size;
827 	uint32_t pktlen_adjust;
828 	int pkt_mode;
829 };
830 
831 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_add =
832 	TOKEN_STRING_INITIALIZER(
833 		struct cmd_add_port_tm_node_shaper_profile_result, add, "add");
834 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_port =
835 	TOKEN_STRING_INITIALIZER(
836 		struct cmd_add_port_tm_node_shaper_profile_result,
837 			port, "port");
838 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_tm =
839 	TOKEN_STRING_INITIALIZER(
840 		struct cmd_add_port_tm_node_shaper_profile_result,
841 			tm, "tm");
842 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_node =
843 	TOKEN_STRING_INITIALIZER(
844 		struct cmd_add_port_tm_node_shaper_profile_result,
845 			node, "node");
846 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_shaper =
847 	TOKEN_STRING_INITIALIZER(
848 		struct cmd_add_port_tm_node_shaper_profile_result,
849 			shaper, "shaper");
850 cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_profile =
851 	TOKEN_STRING_INITIALIZER(
852 		struct cmd_add_port_tm_node_shaper_profile_result,
853 			profile, "profile");
854 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_port_id =
855 	TOKEN_NUM_INITIALIZER(
856 		struct cmd_add_port_tm_node_shaper_profile_result,
857 			port_id, RTE_UINT16);
858 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_shaper_id =
859 	TOKEN_NUM_INITIALIZER(
860 		struct cmd_add_port_tm_node_shaper_profile_result,
861 			shaper_id, RTE_UINT32);
862 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_cmit_tb_rate =
863 	TOKEN_NUM_INITIALIZER(
864 		struct cmd_add_port_tm_node_shaper_profile_result,
865 			cmit_tb_rate, RTE_UINT64);
866 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_cmit_tb_size =
867 	TOKEN_NUM_INITIALIZER(
868 		struct cmd_add_port_tm_node_shaper_profile_result,
869 			cmit_tb_size, RTE_UINT64);
870 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_peak_tb_rate =
871 	TOKEN_NUM_INITIALIZER(
872 		struct cmd_add_port_tm_node_shaper_profile_result,
873 			peak_tb_rate, RTE_UINT64);
874 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_peak_tb_size =
875 	TOKEN_NUM_INITIALIZER(
876 		struct cmd_add_port_tm_node_shaper_profile_result,
877 			peak_tb_size, RTE_UINT64);
878 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_pktlen_adjust =
879 	TOKEN_NUM_INITIALIZER(
880 		struct cmd_add_port_tm_node_shaper_profile_result,
881 			pktlen_adjust, RTE_UINT32);
882 cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_packet_mode =
883 	TOKEN_NUM_INITIALIZER(
884 		struct cmd_add_port_tm_node_shaper_profile_result,
885 			pkt_mode, RTE_UINT32);
886 
887 static void cmd_add_port_tm_node_shaper_profile_parsed(void *parsed_result,
888 	__rte_unused struct cmdline *cl,
889 	__rte_unused void *data)
890 {
891 	struct cmd_add_port_tm_node_shaper_profile_result *res = parsed_result;
892 	struct rte_tm_shaper_params sp;
893 	struct rte_tm_error error;
894 	uint32_t shaper_id = res->shaper_id;
895 	uint32_t pkt_len_adjust = res->pktlen_adjust;
896 	portid_t port_id = res->port_id;
897 	int ret;
898 
899 	if (port_id_is_invalid(port_id, ENABLED_WARN))
900 		return;
901 
902 	/* Private shaper profile params */
903 	memset(&sp, 0, sizeof(struct rte_tm_shaper_params));
904 	memset(&error, 0, sizeof(struct rte_tm_error));
905 	sp.committed.rate = res->cmit_tb_rate;
906 	sp.committed.size = res->cmit_tb_size;
907 	sp.peak.rate = res->peak_tb_rate;
908 	sp.peak.size = res->peak_tb_size;
909 	sp.pkt_length_adjust = pkt_len_adjust;
910 	sp.packet_mode = res->pkt_mode;
911 
912 	ret = rte_tm_shaper_profile_add(port_id, shaper_id, &sp, &error);
913 	if (ret != 0) {
914 		print_err_msg(&error);
915 		return;
916 	}
917 }
918 
919 cmdline_parse_inst_t cmd_add_port_tm_node_shaper_profile = {
920 	.f = cmd_add_port_tm_node_shaper_profile_parsed,
921 	.data = NULL,
922 	.help_str = "Add port tm node private shaper profile",
923 	.tokens = {
924 		(void *)&cmd_add_port_tm_node_shaper_profile_add,
925 		(void *)&cmd_add_port_tm_node_shaper_profile_port,
926 		(void *)&cmd_add_port_tm_node_shaper_profile_tm,
927 		(void *)&cmd_add_port_tm_node_shaper_profile_node,
928 		(void *)&cmd_add_port_tm_node_shaper_profile_shaper,
929 		(void *)&cmd_add_port_tm_node_shaper_profile_profile,
930 		(void *)&cmd_add_port_tm_node_shaper_profile_port_id,
931 		(void *)&cmd_add_port_tm_node_shaper_profile_shaper_id,
932 		(void *)&cmd_add_port_tm_node_shaper_profile_cmit_tb_rate,
933 		(void *)&cmd_add_port_tm_node_shaper_profile_cmit_tb_size,
934 		(void *)&cmd_add_port_tm_node_shaper_profile_peak_tb_rate,
935 		(void *)&cmd_add_port_tm_node_shaper_profile_peak_tb_size,
936 		(void *)&cmd_add_port_tm_node_shaper_profile_pktlen_adjust,
937 		(void *)&cmd_add_port_tm_node_shaper_profile_packet_mode,
938 		NULL,
939 	},
940 };
941 
942 /* *** Delete Port TM Private Shaper Profile *** */
943 struct cmd_del_port_tm_node_shaper_profile_result {
944 	cmdline_fixed_string_t del;
945 	cmdline_fixed_string_t port;
946 	cmdline_fixed_string_t tm;
947 	cmdline_fixed_string_t node;
948 	cmdline_fixed_string_t shaper;
949 	cmdline_fixed_string_t profile;
950 	uint16_t port_id;
951 	uint32_t shaper_id;
952 };
953 
954 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_del =
955 	TOKEN_STRING_INITIALIZER(
956 		struct cmd_del_port_tm_node_shaper_profile_result, del, "del");
957 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_port =
958 	TOKEN_STRING_INITIALIZER(
959 		struct cmd_del_port_tm_node_shaper_profile_result,
960 			port, "port");
961 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_tm =
962 	TOKEN_STRING_INITIALIZER(
963 		struct cmd_del_port_tm_node_shaper_profile_result, tm, "tm");
964 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_node =
965 	TOKEN_STRING_INITIALIZER(
966 		struct cmd_del_port_tm_node_shaper_profile_result,
967 			node, "node");
968 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_shaper =
969 	TOKEN_STRING_INITIALIZER(
970 		struct cmd_del_port_tm_node_shaper_profile_result,
971 			shaper, "shaper");
972 cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_profile =
973 	TOKEN_STRING_INITIALIZER(
974 		struct cmd_del_port_tm_node_shaper_profile_result,
975 			profile, "profile");
976 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_port_id =
977 	TOKEN_NUM_INITIALIZER(
978 		struct cmd_del_port_tm_node_shaper_profile_result,
979 			port_id, RTE_UINT16);
980 cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_shaper_id =
981 	TOKEN_NUM_INITIALIZER(
982 		struct cmd_del_port_tm_node_shaper_profile_result,
983 			shaper_id, RTE_UINT32);
984 
985 static void cmd_del_port_tm_node_shaper_profile_parsed(void *parsed_result,
986 	__rte_unused struct cmdline *cl,
987 	__rte_unused void *data)
988 {
989 	struct cmd_del_port_tm_node_shaper_profile_result *res = parsed_result;
990 	struct rte_tm_error error;
991 	uint32_t shaper_id = res->shaper_id;
992 	portid_t port_id = res->port_id;
993 	int ret;
994 
995 	if (port_id_is_invalid(port_id, ENABLED_WARN))
996 		return;
997 
998 	memset(&error, 0, sizeof(struct rte_tm_error));
999 	ret = rte_tm_shaper_profile_delete(port_id, shaper_id, &error);
1000 	if (ret != 0) {
1001 		print_err_msg(&error);
1002 		return;
1003 	}
1004 }
1005 
1006 cmdline_parse_inst_t cmd_del_port_tm_node_shaper_profile = {
1007 	.f = cmd_del_port_tm_node_shaper_profile_parsed,
1008 	.data = NULL,
1009 	.help_str = "Delete port tm node private shaper profile",
1010 	.tokens = {
1011 		(void *)&cmd_del_port_tm_node_shaper_profile_del,
1012 		(void *)&cmd_del_port_tm_node_shaper_profile_port,
1013 		(void *)&cmd_del_port_tm_node_shaper_profile_tm,
1014 		(void *)&cmd_del_port_tm_node_shaper_profile_node,
1015 		(void *)&cmd_del_port_tm_node_shaper_profile_shaper,
1016 		(void *)&cmd_del_port_tm_node_shaper_profile_profile,
1017 		(void *)&cmd_del_port_tm_node_shaper_profile_port_id,
1018 		(void *)&cmd_del_port_tm_node_shaper_profile_shaper_id,
1019 		NULL,
1020 	},
1021 };
1022 
1023 /* *** Add/Update Port TM shared Shaper *** */
1024 struct cmd_add_port_tm_node_shared_shaper_result {
1025 	cmdline_fixed_string_t cmd_type;
1026 	cmdline_fixed_string_t port;
1027 	cmdline_fixed_string_t tm;
1028 	cmdline_fixed_string_t node;
1029 	cmdline_fixed_string_t shared;
1030 	cmdline_fixed_string_t shaper;
1031 	uint16_t port_id;
1032 	uint32_t shared_shaper_id;
1033 	uint32_t shaper_profile_id;
1034 };
1035 
1036 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_cmd_type =
1037 	TOKEN_STRING_INITIALIZER(
1038 		struct cmd_add_port_tm_node_shared_shaper_result,
1039 			cmd_type, "add#set");
1040 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_port =
1041 	TOKEN_STRING_INITIALIZER(
1042 		struct cmd_add_port_tm_node_shared_shaper_result, port, "port");
1043 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_tm =
1044 	TOKEN_STRING_INITIALIZER(
1045 		struct cmd_add_port_tm_node_shared_shaper_result, tm, "tm");
1046 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_node =
1047 	TOKEN_STRING_INITIALIZER(
1048 		struct cmd_add_port_tm_node_shared_shaper_result, node, "node");
1049 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shared =
1050 	TOKEN_STRING_INITIALIZER(
1051 		struct cmd_add_port_tm_node_shared_shaper_result,
1052 			shared, "shared");
1053 cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shaper =
1054 	TOKEN_STRING_INITIALIZER(
1055 		struct cmd_add_port_tm_node_shared_shaper_result,
1056 			shaper, "shaper");
1057 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_port_id =
1058 	TOKEN_NUM_INITIALIZER(
1059 		struct cmd_add_port_tm_node_shared_shaper_result,
1060 			port_id, RTE_UINT16);
1061 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shared_shaper_id =
1062 	TOKEN_NUM_INITIALIZER(
1063 		struct cmd_add_port_tm_node_shared_shaper_result,
1064 			shared_shaper_id, RTE_UINT32);
1065 cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shaper_profile_id =
1066 	TOKEN_NUM_INITIALIZER(
1067 		struct cmd_add_port_tm_node_shared_shaper_result,
1068 			shaper_profile_id, RTE_UINT32);
1069 
1070 static void cmd_add_port_tm_node_shared_shaper_parsed(void *parsed_result,
1071 	__rte_unused struct cmdline *cl,
1072 	__rte_unused void *data)
1073 {
1074 	struct cmd_add_port_tm_node_shared_shaper_result *res = parsed_result;
1075 	struct rte_tm_error error;
1076 	uint32_t shared_shaper_id = res->shared_shaper_id;
1077 	uint32_t shaper_profile_id = res->shaper_profile_id;
1078 	portid_t port_id = res->port_id;
1079 	int ret;
1080 
1081 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1082 		return;
1083 
1084 	memset(&error, 0, sizeof(struct rte_tm_error));
1085 	/* Command type: add */
1086 	if ((strcmp(res->cmd_type, "add") == 0) &&
1087 		(port_is_started(port_id))) {
1088 		printf(" Port %u not stopped (error)\n", port_id);
1089 		return;
1090 	}
1091 
1092 	/* Command type: set (update) */
1093 	if ((strcmp(res->cmd_type, "set") == 0) &&
1094 		(!port_is_started(port_id))) {
1095 		printf(" Port %u not started (error)\n", port_id);
1096 		return;
1097 	}
1098 
1099 	ret = rte_tm_shared_shaper_add_update(port_id, shared_shaper_id,
1100 		shaper_profile_id, &error);
1101 	if (ret != 0) {
1102 		print_err_msg(&error);
1103 		return;
1104 	}
1105 }
1106 
1107 cmdline_parse_inst_t cmd_add_port_tm_node_shared_shaper = {
1108 	.f = cmd_add_port_tm_node_shared_shaper_parsed,
1109 	.data = NULL,
1110 	.help_str = "add/update port tm node shared shaper",
1111 	.tokens = {
1112 		(void *)&cmd_add_port_tm_node_shared_shaper_cmd_type,
1113 		(void *)&cmd_add_port_tm_node_shared_shaper_port,
1114 		(void *)&cmd_add_port_tm_node_shared_shaper_tm,
1115 		(void *)&cmd_add_port_tm_node_shared_shaper_node,
1116 		(void *)&cmd_add_port_tm_node_shared_shaper_shared,
1117 		(void *)&cmd_add_port_tm_node_shared_shaper_shaper,
1118 		(void *)&cmd_add_port_tm_node_shared_shaper_port_id,
1119 		(void *)&cmd_add_port_tm_node_shared_shaper_shared_shaper_id,
1120 		(void *)&cmd_add_port_tm_node_shared_shaper_shaper_profile_id,
1121 		NULL,
1122 	},
1123 };
1124 
1125 /* *** Delete Port TM shared Shaper *** */
1126 struct cmd_del_port_tm_node_shared_shaper_result {
1127 	cmdline_fixed_string_t del;
1128 	cmdline_fixed_string_t port;
1129 	cmdline_fixed_string_t tm;
1130 	cmdline_fixed_string_t node;
1131 	cmdline_fixed_string_t shared;
1132 	cmdline_fixed_string_t shaper;
1133 	uint16_t port_id;
1134 	uint32_t shared_shaper_id;
1135 };
1136 
1137 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_del =
1138 	TOKEN_STRING_INITIALIZER(
1139 		struct cmd_del_port_tm_node_shared_shaper_result, del, "del");
1140 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_port =
1141 	TOKEN_STRING_INITIALIZER(
1142 		struct cmd_del_port_tm_node_shared_shaper_result, port, "port");
1143 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_tm =
1144 	TOKEN_STRING_INITIALIZER(
1145 		struct cmd_del_port_tm_node_shared_shaper_result, tm, "tm");
1146 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_node =
1147 	TOKEN_STRING_INITIALIZER(
1148 		struct cmd_del_port_tm_node_shared_shaper_result, node, "node");
1149 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shared =
1150 	TOKEN_STRING_INITIALIZER(
1151 		struct cmd_del_port_tm_node_shared_shaper_result,
1152 			shared, "shared");
1153 cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shaper =
1154 	TOKEN_STRING_INITIALIZER(
1155 		struct cmd_del_port_tm_node_shared_shaper_result,
1156 			shaper, "shaper");
1157 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_port_id =
1158 	TOKEN_NUM_INITIALIZER(
1159 		struct cmd_del_port_tm_node_shared_shaper_result,
1160 			port_id, RTE_UINT16);
1161 cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_shared_shaper_id =
1162 	TOKEN_NUM_INITIALIZER(
1163 		struct cmd_del_port_tm_node_shared_shaper_result,
1164 			shared_shaper_id, RTE_UINT32);
1165 
1166 static void cmd_del_port_tm_node_shared_shaper_parsed(void *parsed_result,
1167 	__rte_unused struct cmdline *cl,
1168 	__rte_unused void *data)
1169 {
1170 	struct cmd_del_port_tm_node_shared_shaper_result *res = parsed_result;
1171 	struct rte_tm_error error;
1172 	uint32_t shared_shaper_id = res->shared_shaper_id;
1173 	portid_t port_id = res->port_id;
1174 	int ret;
1175 
1176 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1177 		return;
1178 
1179 	memset(&error, 0, sizeof(struct rte_tm_error));
1180 	ret = rte_tm_shared_shaper_delete(port_id, shared_shaper_id, &error);
1181 	if (ret != 0) {
1182 		print_err_msg(&error);
1183 		return;
1184 	}
1185 }
1186 
1187 cmdline_parse_inst_t cmd_del_port_tm_node_shared_shaper = {
1188 	.f = cmd_del_port_tm_node_shared_shaper_parsed,
1189 	.data = NULL,
1190 	.help_str = "delete port tm node shared shaper",
1191 	.tokens = {
1192 		(void *)&cmd_del_port_tm_node_shared_shaper_del,
1193 		(void *)&cmd_del_port_tm_node_shared_shaper_port,
1194 		(void *)&cmd_del_port_tm_node_shared_shaper_tm,
1195 		(void *)&cmd_del_port_tm_node_shared_shaper_node,
1196 		(void *)&cmd_del_port_tm_node_shared_shaper_shared,
1197 		(void *)&cmd_del_port_tm_node_shared_shaper_shaper,
1198 		(void *)&cmd_del_port_tm_node_shared_shaper_port_id,
1199 		(void *)&cmd_del_port_tm_node_shared_shaper_shared_shaper_id,
1200 		NULL,
1201 	},
1202 };
1203 
1204 /* *** Add Port TM Node WRED Profile *** */
1205 struct cmd_add_port_tm_node_wred_profile_result {
1206 	cmdline_fixed_string_t add;
1207 	cmdline_fixed_string_t port;
1208 	cmdline_fixed_string_t tm;
1209 	cmdline_fixed_string_t node;
1210 	cmdline_fixed_string_t wred;
1211 	cmdline_fixed_string_t profile;
1212 	uint16_t port_id;
1213 	uint32_t wred_profile_id;
1214 	cmdline_fixed_string_t color_g;
1215 	uint64_t min_th_g;
1216 	uint64_t max_th_g;
1217 	uint16_t maxp_inv_g;
1218 	uint16_t wq_log2_g;
1219 	cmdline_fixed_string_t color_y;
1220 	uint64_t min_th_y;
1221 	uint64_t max_th_y;
1222 	uint16_t maxp_inv_y;
1223 	uint16_t wq_log2_y;
1224 	cmdline_fixed_string_t color_r;
1225 	uint64_t min_th_r;
1226 	uint64_t max_th_r;
1227 	uint16_t maxp_inv_r;
1228 	uint16_t wq_log2_r;
1229 };
1230 
1231 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_add =
1232 	TOKEN_STRING_INITIALIZER(
1233 		struct cmd_add_port_tm_node_wred_profile_result, add, "add");
1234 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_port =
1235 	TOKEN_STRING_INITIALIZER(
1236 		struct cmd_add_port_tm_node_wred_profile_result, port, "port");
1237 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_tm =
1238 	TOKEN_STRING_INITIALIZER(
1239 		struct cmd_add_port_tm_node_wred_profile_result, tm, "tm");
1240 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_node =
1241 	TOKEN_STRING_INITIALIZER(
1242 		struct cmd_add_port_tm_node_wred_profile_result, node, "node");
1243 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_wred =
1244 	TOKEN_STRING_INITIALIZER(
1245 		struct cmd_add_port_tm_node_wred_profile_result, wred, "wred");
1246 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_profile =
1247 	TOKEN_STRING_INITIALIZER(
1248 		struct cmd_add_port_tm_node_wred_profile_result,
1249 			profile, "profile");
1250 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_port_id =
1251 	TOKEN_NUM_INITIALIZER(
1252 		struct cmd_add_port_tm_node_wred_profile_result,
1253 			port_id, RTE_UINT16);
1254 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wred_profile_id =
1255 	TOKEN_NUM_INITIALIZER(
1256 		struct cmd_add_port_tm_node_wred_profile_result,
1257 			wred_profile_id, RTE_UINT32);
1258 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_g =
1259 	TOKEN_STRING_INITIALIZER(
1260 		struct cmd_add_port_tm_node_wred_profile_result,
1261 			color_g, "G#g");
1262 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_g =
1263 	TOKEN_NUM_INITIALIZER(
1264 		struct cmd_add_port_tm_node_wred_profile_result,
1265 			min_th_g, RTE_UINT64);
1266 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_g =
1267 	TOKEN_NUM_INITIALIZER(
1268 		struct cmd_add_port_tm_node_wred_profile_result,
1269 			max_th_g, RTE_UINT64);
1270 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_g =
1271 	TOKEN_NUM_INITIALIZER(
1272 		struct cmd_add_port_tm_node_wred_profile_result,
1273 			maxp_inv_g, RTE_UINT16);
1274 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_g =
1275 	TOKEN_NUM_INITIALIZER(
1276 		struct cmd_add_port_tm_node_wred_profile_result,
1277 			wq_log2_g, RTE_UINT16);
1278 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_y =
1279 	TOKEN_STRING_INITIALIZER(
1280 		struct cmd_add_port_tm_node_wred_profile_result,
1281 			color_y, "Y#y");
1282 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_y =
1283 	TOKEN_NUM_INITIALIZER(
1284 		struct cmd_add_port_tm_node_wred_profile_result,
1285 			min_th_y, RTE_UINT64);
1286 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_y =
1287 	TOKEN_NUM_INITIALIZER(
1288 		struct cmd_add_port_tm_node_wred_profile_result,
1289 			max_th_y, RTE_UINT64);
1290 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_y =
1291 	TOKEN_NUM_INITIALIZER(
1292 		struct cmd_add_port_tm_node_wred_profile_result,
1293 			maxp_inv_y, RTE_UINT16);
1294 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_y =
1295 	TOKEN_NUM_INITIALIZER(
1296 		struct cmd_add_port_tm_node_wred_profile_result,
1297 			wq_log2_y, RTE_UINT16);
1298 cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_r =
1299 	TOKEN_STRING_INITIALIZER(
1300 		struct cmd_add_port_tm_node_wred_profile_result,
1301 			color_r, "R#r");
1302 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_r =
1303 	TOKEN_NUM_INITIALIZER(
1304 		struct cmd_add_port_tm_node_wred_profile_result,
1305 			min_th_r, RTE_UINT64);
1306 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_r =
1307 	TOKEN_NUM_INITIALIZER(
1308 		struct cmd_add_port_tm_node_wred_profile_result,
1309 			max_th_r, RTE_UINT64);
1310 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_r =
1311 	TOKEN_NUM_INITIALIZER(
1312 		struct cmd_add_port_tm_node_wred_profile_result,
1313 			maxp_inv_r, RTE_UINT16);
1314 cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_r =
1315 	TOKEN_NUM_INITIALIZER(
1316 		struct cmd_add_port_tm_node_wred_profile_result,
1317 			wq_log2_r, RTE_UINT16);
1318 
1319 
1320 static void cmd_add_port_tm_node_wred_profile_parsed(void *parsed_result,
1321 	__rte_unused struct cmdline *cl,
1322 	__rte_unused void *data)
1323 {
1324 	struct cmd_add_port_tm_node_wred_profile_result *res = parsed_result;
1325 	struct rte_tm_wred_params wp;
1326 	enum rte_color color;
1327 	struct rte_tm_error error;
1328 	uint32_t wred_profile_id = res->wred_profile_id;
1329 	portid_t port_id = res->port_id;
1330 	int ret;
1331 
1332 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1333 		return;
1334 
1335 	memset(&wp, 0, sizeof(struct rte_tm_wred_params));
1336 	memset(&error, 0, sizeof(struct rte_tm_error));
1337 
1338 	/* WRED Params  (Green Color)*/
1339 	color = RTE_COLOR_GREEN;
1340 	wp.red_params[color].min_th = res->min_th_g;
1341 	wp.red_params[color].max_th = res->max_th_g;
1342 	wp.red_params[color].maxp_inv = res->maxp_inv_g;
1343 	wp.red_params[color].wq_log2 = res->wq_log2_g;
1344 
1345 
1346 	/* WRED Params  (Yellow Color)*/
1347 	color = RTE_COLOR_YELLOW;
1348 	wp.red_params[color].min_th = res->min_th_y;
1349 	wp.red_params[color].max_th = res->max_th_y;
1350 	wp.red_params[color].maxp_inv = res->maxp_inv_y;
1351 	wp.red_params[color].wq_log2 = res->wq_log2_y;
1352 
1353 	/* WRED Params  (Red Color)*/
1354 	color = RTE_COLOR_RED;
1355 	wp.red_params[color].min_th = res->min_th_r;
1356 	wp.red_params[color].max_th = res->max_th_r;
1357 	wp.red_params[color].maxp_inv = res->maxp_inv_r;
1358 	wp.red_params[color].wq_log2 = res->wq_log2_r;
1359 
1360 	ret = rte_tm_wred_profile_add(port_id, wred_profile_id, &wp, &error);
1361 	if (ret != 0) {
1362 		print_err_msg(&error);
1363 		return;
1364 	}
1365 }
1366 
1367 cmdline_parse_inst_t cmd_add_port_tm_node_wred_profile = {
1368 	.f = cmd_add_port_tm_node_wred_profile_parsed,
1369 	.data = NULL,
1370 	.help_str = "Add port tm node wred profile",
1371 	.tokens = {
1372 		(void *)&cmd_add_port_tm_node_wred_profile_add,
1373 		(void *)&cmd_add_port_tm_node_wred_profile_port,
1374 		(void *)&cmd_add_port_tm_node_wred_profile_tm,
1375 		(void *)&cmd_add_port_tm_node_wred_profile_node,
1376 		(void *)&cmd_add_port_tm_node_wred_profile_wred,
1377 		(void *)&cmd_add_port_tm_node_wred_profile_profile,
1378 		(void *)&cmd_add_port_tm_node_wred_profile_port_id,
1379 		(void *)&cmd_add_port_tm_node_wred_profile_wred_profile_id,
1380 		(void *)&cmd_add_port_tm_node_wred_profile_color_g,
1381 		(void *)&cmd_add_port_tm_node_wred_profile_min_th_g,
1382 		(void *)&cmd_add_port_tm_node_wred_profile_max_th_g,
1383 		(void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_g,
1384 		(void *)&cmd_add_port_tm_node_wred_profile_wq_log2_g,
1385 		(void *)&cmd_add_port_tm_node_wred_profile_color_y,
1386 		(void *)&cmd_add_port_tm_node_wred_profile_min_th_y,
1387 		(void *)&cmd_add_port_tm_node_wred_profile_max_th_y,
1388 		(void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_y,
1389 		(void *)&cmd_add_port_tm_node_wred_profile_wq_log2_y,
1390 		(void *)&cmd_add_port_tm_node_wred_profile_color_r,
1391 		(void *)&cmd_add_port_tm_node_wred_profile_min_th_r,
1392 		(void *)&cmd_add_port_tm_node_wred_profile_max_th_r,
1393 		(void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_r,
1394 		(void *)&cmd_add_port_tm_node_wred_profile_wq_log2_r,
1395 		NULL,
1396 	},
1397 };
1398 
1399 /* *** Delete Port TM node WRED Profile *** */
1400 struct cmd_del_port_tm_node_wred_profile_result {
1401 	cmdline_fixed_string_t del;
1402 	cmdline_fixed_string_t port;
1403 	cmdline_fixed_string_t tm;
1404 	cmdline_fixed_string_t node;
1405 	cmdline_fixed_string_t wred;
1406 	cmdline_fixed_string_t profile;
1407 	uint16_t port_id;
1408 	uint32_t wred_profile_id;
1409 };
1410 
1411 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_del =
1412 	TOKEN_STRING_INITIALIZER(
1413 		struct cmd_del_port_tm_node_wred_profile_result, del, "del");
1414 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_port =
1415 	TOKEN_STRING_INITIALIZER(
1416 		struct cmd_del_port_tm_node_wred_profile_result, port, "port");
1417 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_tm =
1418 	TOKEN_STRING_INITIALIZER(
1419 		struct cmd_del_port_tm_node_wred_profile_result, tm, "tm");
1420 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_node =
1421 	TOKEN_STRING_INITIALIZER(
1422 		struct cmd_del_port_tm_node_wred_profile_result, node, "node");
1423 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_wred =
1424 	TOKEN_STRING_INITIALIZER(
1425 		struct cmd_del_port_tm_node_wred_profile_result, wred, "wred");
1426 cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_profile =
1427 	TOKEN_STRING_INITIALIZER(
1428 		struct cmd_del_port_tm_node_wred_profile_result,
1429 			profile, "profile");
1430 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_port_id =
1431 	TOKEN_NUM_INITIALIZER(
1432 		struct cmd_del_port_tm_node_wred_profile_result,
1433 			port_id, RTE_UINT16);
1434 cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_wred_profile_id =
1435 	TOKEN_NUM_INITIALIZER(
1436 		struct cmd_del_port_tm_node_wred_profile_result,
1437 			wred_profile_id, RTE_UINT32);
1438 
1439 static void cmd_del_port_tm_node_wred_profile_parsed(void *parsed_result,
1440 	__rte_unused struct cmdline *cl,
1441 	__rte_unused void *data)
1442 {
1443 	struct cmd_del_port_tm_node_wred_profile_result *res = parsed_result;
1444 	struct rte_tm_error error;
1445 	uint32_t wred_profile_id = res->wred_profile_id;
1446 	portid_t port_id = res->port_id;
1447 	int ret;
1448 
1449 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1450 		return;
1451 
1452 	memset(&error, 0, sizeof(struct rte_tm_error));
1453 	ret = rte_tm_wred_profile_delete(port_id, wred_profile_id, &error);
1454 	if (ret != 0) {
1455 		print_err_msg(&error);
1456 		return;
1457 	}
1458 }
1459 
1460 cmdline_parse_inst_t cmd_del_port_tm_node_wred_profile = {
1461 	.f = cmd_del_port_tm_node_wred_profile_parsed,
1462 	.data = NULL,
1463 	.help_str = "Delete port tm node wred profile",
1464 	.tokens = {
1465 		(void *)&cmd_del_port_tm_node_wred_profile_del,
1466 		(void *)&cmd_del_port_tm_node_wred_profile_port,
1467 		(void *)&cmd_del_port_tm_node_wred_profile_tm,
1468 		(void *)&cmd_del_port_tm_node_wred_profile_node,
1469 		(void *)&cmd_del_port_tm_node_wred_profile_wred,
1470 		(void *)&cmd_del_port_tm_node_wred_profile_profile,
1471 		(void *)&cmd_del_port_tm_node_wred_profile_port_id,
1472 		(void *)&cmd_del_port_tm_node_wred_profile_wred_profile_id,
1473 		NULL,
1474 	},
1475 };
1476 
1477 /* *** Update Port TM Node Shaper profile *** */
1478 struct cmd_set_port_tm_node_shaper_profile_result {
1479 	cmdline_fixed_string_t set;
1480 	cmdline_fixed_string_t port;
1481 	cmdline_fixed_string_t tm;
1482 	cmdline_fixed_string_t node;
1483 	cmdline_fixed_string_t shaper;
1484 	cmdline_fixed_string_t profile;
1485 	uint16_t port_id;
1486 	uint32_t node_id;
1487 	uint32_t shaper_profile_id;
1488 };
1489 
1490 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_set =
1491 	TOKEN_STRING_INITIALIZER(
1492 		struct cmd_set_port_tm_node_shaper_profile_result, set, "set");
1493 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_port =
1494 	TOKEN_STRING_INITIALIZER(
1495 		struct cmd_set_port_tm_node_shaper_profile_result,
1496 			port, "port");
1497 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_tm =
1498 	TOKEN_STRING_INITIALIZER(
1499 		struct cmd_set_port_tm_node_shaper_profile_result, tm, "tm");
1500 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_node =
1501 	TOKEN_STRING_INITIALIZER(
1502 		struct cmd_set_port_tm_node_shaper_profile_result,
1503 			node, "node");
1504 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_shaper =
1505 	TOKEN_STRING_INITIALIZER(
1506 		struct cmd_set_port_tm_node_shaper_profile_result,
1507 			shaper, "shaper");
1508 cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_profile =
1509 	TOKEN_STRING_INITIALIZER(
1510 		struct cmd_set_port_tm_node_shaper_profile_result,
1511 			profile, "profile");
1512 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_port_id =
1513 	TOKEN_NUM_INITIALIZER(
1514 		struct cmd_set_port_tm_node_shaper_profile_result,
1515 			port_id, RTE_UINT16);
1516 cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_node_id =
1517 	TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_shaper_profile_result,
1518 		node_id, RTE_UINT32);
1519 cmdline_parse_token_num_t
1520 	cmd_set_port_tm_node_shaper_shaper_profile_profile_id =
1521 		TOKEN_NUM_INITIALIZER(
1522 			struct cmd_set_port_tm_node_shaper_profile_result,
1523 			shaper_profile_id, RTE_UINT32);
1524 
1525 static void cmd_set_port_tm_node_shaper_profile_parsed(void *parsed_result,
1526 	__rte_unused struct cmdline *cl,
1527 	__rte_unused void *data)
1528 {
1529 	struct cmd_set_port_tm_node_shaper_profile_result *res = parsed_result;
1530 	struct rte_tm_error error;
1531 	uint32_t node_id = res->node_id;
1532 	uint32_t shaper_profile_id = res->shaper_profile_id;
1533 	portid_t port_id = res->port_id;
1534 	int ret;
1535 
1536 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1537 		return;
1538 
1539 	memset(&error, 0, sizeof(struct rte_tm_error));
1540 	/* Port status */
1541 	if (!port_is_started(port_id)) {
1542 		printf(" Port %u not started (error)\n", port_id);
1543 		return;
1544 	}
1545 
1546 	ret = rte_tm_node_shaper_update(port_id, node_id,
1547 		shaper_profile_id, &error);
1548 	if (ret != 0) {
1549 		print_err_msg(&error);
1550 		return;
1551 	}
1552 }
1553 
1554 cmdline_parse_inst_t cmd_set_port_tm_node_shaper_profile = {
1555 	.f = cmd_set_port_tm_node_shaper_profile_parsed,
1556 	.data = NULL,
1557 	.help_str = "Set port tm node shaper profile",
1558 	.tokens = {
1559 		(void *)&cmd_set_port_tm_node_shaper_profile_set,
1560 		(void *)&cmd_set_port_tm_node_shaper_profile_port,
1561 		(void *)&cmd_set_port_tm_node_shaper_profile_tm,
1562 		(void *)&cmd_set_port_tm_node_shaper_profile_node,
1563 		(void *)&cmd_set_port_tm_node_shaper_profile_shaper,
1564 		(void *)&cmd_set_port_tm_node_shaper_profile_profile,
1565 		(void *)&cmd_set_port_tm_node_shaper_profile_port_id,
1566 		(void *)&cmd_set_port_tm_node_shaper_profile_node_id,
1567 		(void *)&cmd_set_port_tm_node_shaper_shaper_profile_profile_id,
1568 		NULL,
1569 	},
1570 };
1571 
1572 /* *** Add Port TM nonleaf node *** */
1573 struct cmd_add_port_tm_nonleaf_node_result {
1574 	cmdline_fixed_string_t add;
1575 	cmdline_fixed_string_t port;
1576 	cmdline_fixed_string_t tm;
1577 	cmdline_fixed_string_t nonleaf;
1578 	cmdline_fixed_string_t node;
1579 	uint16_t port_id;
1580 	uint32_t node_id;
1581 	int32_t parent_node_id;
1582 	uint32_t priority;
1583 	uint32_t weight;
1584 	uint32_t level_id;
1585 	int32_t shaper_profile_id;
1586 	uint32_t n_sp_priorities;
1587 	uint64_t stats_mask;
1588 	cmdline_multi_string_t multi_shared_shaper_id;
1589 };
1590 
1591 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_add =
1592 	TOKEN_STRING_INITIALIZER(
1593 		struct cmd_add_port_tm_nonleaf_node_result, add, "add");
1594 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_port =
1595 	TOKEN_STRING_INITIALIZER(
1596 		struct cmd_add_port_tm_nonleaf_node_result, port, "port");
1597 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_tm =
1598 	TOKEN_STRING_INITIALIZER(
1599 		struct cmd_add_port_tm_nonleaf_node_result, tm, "tm");
1600 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_nonleaf =
1601 	TOKEN_STRING_INITIALIZER(
1602 		struct cmd_add_port_tm_nonleaf_node_result, nonleaf, "nonleaf");
1603 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_node =
1604 	TOKEN_STRING_INITIALIZER(
1605 		struct cmd_add_port_tm_nonleaf_node_result, node, "node");
1606 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_port_id =
1607 	TOKEN_NUM_INITIALIZER(
1608 		struct cmd_add_port_tm_nonleaf_node_result,
1609 		 port_id, RTE_UINT16);
1610 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_node_id =
1611 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1612 		 node_id, RTE_UINT32);
1613 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_parent_node_id =
1614 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1615 		 parent_node_id, RTE_INT32);
1616 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_priority =
1617 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1618 		 priority, RTE_UINT32);
1619 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_weight =
1620 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1621 		 weight, RTE_UINT32);
1622 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_level_id =
1623 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1624 		 level_id, RTE_UINT32);
1625 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_shaper_profile_id =
1626 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1627 		 shaper_profile_id, RTE_INT32);
1628 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_n_sp_priorities =
1629 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1630 		 n_sp_priorities, RTE_UINT32);
1631 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_stats_mask =
1632 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1633 		 stats_mask, RTE_UINT64);
1634 cmdline_parse_token_string_t
1635 	cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id =
1636 	TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result,
1637 		 multi_shared_shaper_id, TOKEN_STRING_MULTI);
1638 
1639 static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result,
1640 	__rte_unused struct cmdline *cl,
1641 	__rte_unused void *data)
1642 {
1643 	struct cmd_add_port_tm_nonleaf_node_result *res = parsed_result;
1644 	struct rte_tm_error error;
1645 	struct rte_tm_node_params np;
1646 	uint32_t *shared_shaper_id;
1647 	uint32_t parent_node_id, n_shared_shapers = 0;
1648 	char *s_str = res->multi_shared_shaper_id;
1649 	portid_t port_id = res->port_id;
1650 	int ret;
1651 
1652 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1653 		return;
1654 
1655 	memset(&np, 0, sizeof(struct rte_tm_node_params));
1656 	memset(&error, 0, sizeof(struct rte_tm_error));
1657 
1658 	/* Node parameters */
1659 	if (res->parent_node_id < 0)
1660 		parent_node_id = UINT32_MAX;
1661 	else
1662 		parent_node_id = res->parent_node_id;
1663 
1664 	shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1665 		sizeof(uint32_t));
1666 	if (shared_shaper_id == NULL) {
1667 		printf(" Memory not allocated for shared shapers (error)\n");
1668 		return;
1669 	}
1670 
1671 	/* Parse multi shared shaper id string */
1672 	ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
1673 	if (ret) {
1674 		printf(" Shared shapers params string parse error\n");
1675 		free(shared_shaper_id);
1676 		return;
1677 	}
1678 
1679 	if (res->shaper_profile_id < 0)
1680 		np.shaper_profile_id = UINT32_MAX;
1681 	else
1682 		np.shaper_profile_id = res->shaper_profile_id;
1683 
1684 	np.n_shared_shapers = n_shared_shapers;
1685 	if (np.n_shared_shapers) {
1686 		np.shared_shaper_id = &shared_shaper_id[0];
1687 	} else {
1688 		free(shared_shaper_id);
1689 		shared_shaper_id = NULL;
1690 	}
1691 
1692 	np.nonleaf.n_sp_priorities = res->n_sp_priorities;
1693 	np.stats_mask = res->stats_mask;
1694 	np.nonleaf.wfq_weight_mode = NULL;
1695 
1696 	ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
1697 				res->priority, res->weight, res->level_id,
1698 				&np, &error);
1699 	if (ret != 0) {
1700 		print_err_msg(&error);
1701 		free(shared_shaper_id);
1702 		return;
1703 	}
1704 }
1705 
1706 cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node = {
1707 	.f = cmd_add_port_tm_nonleaf_node_parsed,
1708 	.data = NULL,
1709 	.help_str = "Add port tm nonleaf node",
1710 	.tokens = {
1711 		(void *)&cmd_add_port_tm_nonleaf_node_add,
1712 		(void *)&cmd_add_port_tm_nonleaf_node_port,
1713 		(void *)&cmd_add_port_tm_nonleaf_node_tm,
1714 		(void *)&cmd_add_port_tm_nonleaf_node_nonleaf,
1715 		(void *)&cmd_add_port_tm_nonleaf_node_node,
1716 		(void *)&cmd_add_port_tm_nonleaf_node_port_id,
1717 		(void *)&cmd_add_port_tm_nonleaf_node_node_id,
1718 		(void *)&cmd_add_port_tm_nonleaf_node_parent_node_id,
1719 		(void *)&cmd_add_port_tm_nonleaf_node_priority,
1720 		(void *)&cmd_add_port_tm_nonleaf_node_weight,
1721 		(void *)&cmd_add_port_tm_nonleaf_node_level_id,
1722 		(void *)&cmd_add_port_tm_nonleaf_node_shaper_profile_id,
1723 		(void *)&cmd_add_port_tm_nonleaf_node_n_sp_priorities,
1724 		(void *)&cmd_add_port_tm_nonleaf_node_stats_mask,
1725 		(void *)&cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id,
1726 		NULL,
1727 	},
1728 };
1729 
1730 /* *** Add Port TM nonleaf node pkt mode *** */
1731 struct cmd_add_port_tm_nonleaf_node_pmode_result {
1732 	cmdline_fixed_string_t add;
1733 	cmdline_fixed_string_t port;
1734 	cmdline_fixed_string_t tm;
1735 	cmdline_fixed_string_t nonleaf;
1736 	cmdline_fixed_string_t node;
1737 	uint16_t port_id;
1738 	uint32_t node_id;
1739 	int32_t parent_node_id;
1740 	uint32_t priority;
1741 	uint32_t weight;
1742 	uint32_t level_id;
1743 	int32_t shaper_profile_id;
1744 	uint32_t n_sp_priorities;
1745 	uint64_t stats_mask;
1746 	cmdline_multi_string_t multi_shared_shaper_id;
1747 };
1748 
1749 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_add =
1750 	TOKEN_STRING_INITIALIZER(
1751 		struct cmd_add_port_tm_nonleaf_node_pmode_result, add, "add");
1752 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_port =
1753 	TOKEN_STRING_INITIALIZER(
1754 		struct cmd_add_port_tm_nonleaf_node_pmode_result, port, "port");
1755 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_tm =
1756 	TOKEN_STRING_INITIALIZER(
1757 		struct cmd_add_port_tm_nonleaf_node_pmode_result, tm, "tm");
1758 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_nonleaf =
1759 	TOKEN_STRING_INITIALIZER(
1760 		struct cmd_add_port_tm_nonleaf_node_pmode_result, nonleaf, "nonleaf");
1761 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_node =
1762 	TOKEN_STRING_INITIALIZER(
1763 		struct cmd_add_port_tm_nonleaf_node_pmode_result, node, "node");
1764 cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_pmode_pktmode =
1765 	TOKEN_STRING_INITIALIZER(
1766 		struct cmd_add_port_tm_nonleaf_node_pmode_result, node, "pktmode");
1767 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_port_id =
1768 	TOKEN_NUM_INITIALIZER(
1769 		struct cmd_add_port_tm_nonleaf_node_pmode_result,
1770 		 port_id, RTE_UINT16);
1771 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_node_id =
1772 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result,
1773 		 node_id, RTE_UINT32);
1774 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_parent_node_id =
1775 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result,
1776 		 parent_node_id, RTE_INT32);
1777 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_priority =
1778 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result,
1779 		 priority, RTE_UINT32);
1780 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_weight =
1781 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result,
1782 		 weight, RTE_UINT32);
1783 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_level_id =
1784 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result,
1785 		 level_id, RTE_UINT32);
1786 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_shaper_profile_id =
1787 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result,
1788 		 shaper_profile_id, RTE_INT32);
1789 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_n_sp_priorities =
1790 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result,
1791 		 n_sp_priorities, RTE_UINT32);
1792 cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_pmode_stats_mask =
1793 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_pmode_result,
1794 		 stats_mask, RTE_UINT64);
1795 cmdline_parse_token_string_t
1796 	cmd_add_port_tm_nonleaf_node_pmode_multi_shrd_shpr_id =
1797 	TOKEN_STRING_INITIALIZER(
1798 			struct cmd_add_port_tm_nonleaf_node_pmode_result,
1799 			multi_shared_shaper_id, TOKEN_STRING_MULTI);
1800 
1801 static void cmd_add_port_tm_nonleaf_node_pmode_parsed(void *parsed_result,
1802 	__rte_unused struct cmdline *cl,
1803 	__rte_unused void *data)
1804 {
1805 	struct cmd_add_port_tm_nonleaf_node_pmode_result *res = parsed_result;
1806 	uint32_t parent_node_id, n_shared_shapers = 0;
1807 	char *s_str = res->multi_shared_shaper_id;
1808 	portid_t port_id = res->port_id;
1809 	struct rte_tm_node_params np;
1810 	int *wfq_weight_mode = NULL;
1811 	uint32_t *shared_shaper_id;
1812 	struct rte_tm_error error;
1813 	int ret;
1814 
1815 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1816 		return;
1817 
1818 	memset(&np, 0, sizeof(struct rte_tm_node_params));
1819 	memset(&error, 0, sizeof(struct rte_tm_error));
1820 
1821 	/* Node parameters */
1822 	if (res->parent_node_id < 0)
1823 		parent_node_id = UINT32_MAX;
1824 	else
1825 		parent_node_id = res->parent_node_id;
1826 
1827 	shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1828 		sizeof(uint32_t));
1829 	if (shared_shaper_id == NULL) {
1830 		printf(" Memory not allocated for shared shapers (error)\n");
1831 		return;
1832 	}
1833 
1834 	/* Parse multi shared shaper id string */
1835 	ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
1836 	if (ret) {
1837 		printf(" Shared shapers params string parse error\n");
1838 		free(shared_shaper_id);
1839 		return;
1840 	}
1841 
1842 	if (res->shaper_profile_id < 0)
1843 		np.shaper_profile_id = UINT32_MAX;
1844 	else
1845 		np.shaper_profile_id = res->shaper_profile_id;
1846 
1847 	np.n_shared_shapers = n_shared_shapers;
1848 	if (np.n_shared_shapers) {
1849 		np.shared_shaper_id = &shared_shaper_id[0];
1850 	} else {
1851 		free(shared_shaper_id);
1852 		shared_shaper_id = NULL;
1853 	}
1854 
1855 	if (res->n_sp_priorities)
1856 		wfq_weight_mode = calloc(res->n_sp_priorities, sizeof(int));
1857 	np.nonleaf.n_sp_priorities = res->n_sp_priorities;
1858 	np.stats_mask = res->stats_mask;
1859 	np.nonleaf.wfq_weight_mode = wfq_weight_mode;
1860 
1861 	ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
1862 				res->priority, res->weight, res->level_id,
1863 				&np, &error);
1864 	if (ret != 0) {
1865 		print_err_msg(&error);
1866 		free(shared_shaper_id);
1867 		free(wfq_weight_mode);
1868 		return;
1869 	}
1870 }
1871 
1872 cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node_pmode = {
1873 	.f = cmd_add_port_tm_nonleaf_node_pmode_parsed,
1874 	.data = NULL,
1875 	.help_str = "Add port tm nonleaf node pktmode",
1876 	.tokens = {
1877 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_add,
1878 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_port,
1879 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_tm,
1880 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_nonleaf,
1881 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_node,
1882 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_pktmode,
1883 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_port_id,
1884 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_node_id,
1885 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_parent_node_id,
1886 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_priority,
1887 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_weight,
1888 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_level_id,
1889 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_shaper_profile_id,
1890 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_n_sp_priorities,
1891 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_stats_mask,
1892 		(void *)&cmd_add_port_tm_nonleaf_node_pmode_multi_shrd_shpr_id,
1893 		NULL,
1894 	},
1895 };
1896 /* *** Add Port TM leaf node *** */
1897 struct cmd_add_port_tm_leaf_node_result {
1898 	cmdline_fixed_string_t add;
1899 	cmdline_fixed_string_t port;
1900 	cmdline_fixed_string_t tm;
1901 	cmdline_fixed_string_t leaf;
1902 	cmdline_fixed_string_t node;
1903 	uint16_t port_id;
1904 	uint32_t node_id;
1905 	int32_t parent_node_id;
1906 	uint32_t priority;
1907 	uint32_t weight;
1908 	uint32_t level_id;
1909 	int32_t shaper_profile_id;
1910 	uint32_t cman_mode;
1911 	uint32_t wred_profile_id;
1912 	uint64_t stats_mask;
1913 	cmdline_multi_string_t multi_shared_shaper_id;
1914 };
1915 
1916 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_add =
1917 	TOKEN_STRING_INITIALIZER(
1918 		struct cmd_add_port_tm_leaf_node_result, add, "add");
1919 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_port =
1920 	TOKEN_STRING_INITIALIZER(
1921 		struct cmd_add_port_tm_leaf_node_result, port, "port");
1922 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_tm =
1923 	TOKEN_STRING_INITIALIZER(
1924 		struct cmd_add_port_tm_leaf_node_result, tm, "tm");
1925 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_nonleaf =
1926 	TOKEN_STRING_INITIALIZER(
1927 		struct cmd_add_port_tm_leaf_node_result, leaf, "leaf");
1928 cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_node =
1929 	TOKEN_STRING_INITIALIZER(
1930 		struct cmd_add_port_tm_leaf_node_result, node, "node");
1931 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_port_id =
1932 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1933 		 port_id, RTE_UINT16);
1934 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_node_id =
1935 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1936 		 node_id, RTE_UINT32);
1937 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_parent_node_id =
1938 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1939 		 parent_node_id, RTE_INT32);
1940 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_priority =
1941 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1942 		 priority, RTE_UINT32);
1943 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_weight =
1944 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1945 		 weight, RTE_UINT32);
1946 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_level_id =
1947 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1948 		 level_id, RTE_UINT32);
1949 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_shaper_profile_id =
1950 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1951 		 shaper_profile_id, RTE_INT32);
1952 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_cman_mode =
1953 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1954 		 cman_mode, RTE_UINT32);
1955 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_wred_profile_id =
1956 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1957 		 wred_profile_id, RTE_UINT32);
1958 cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_stats_mask =
1959 	TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1960 		 stats_mask, RTE_UINT64);
1961 cmdline_parse_token_string_t
1962 	cmd_add_port_tm_leaf_node_multi_shared_shaper_id =
1963 	TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_leaf_node_result,
1964 		 multi_shared_shaper_id, TOKEN_STRING_MULTI);
1965 
1966 static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result,
1967 	__rte_unused struct cmdline *cl,
1968 	__rte_unused void *data)
1969 {
1970 	struct cmd_add_port_tm_leaf_node_result *res = parsed_result;
1971 	struct rte_tm_error error;
1972 	struct rte_tm_node_params np;
1973 	uint32_t *shared_shaper_id;
1974 	uint32_t parent_node_id, n_shared_shapers = 0;
1975 	portid_t port_id = res->port_id;
1976 	char *s_str = res->multi_shared_shaper_id;
1977 	int ret;
1978 
1979 	if (port_id_is_invalid(port_id, ENABLED_WARN))
1980 		return;
1981 
1982 	memset(&np, 0, sizeof(struct rte_tm_node_params));
1983 	memset(&error, 0, sizeof(struct rte_tm_error));
1984 
1985 	/* Node parameters */
1986 	if (res->parent_node_id < 0)
1987 		parent_node_id = UINT32_MAX;
1988 	else
1989 		parent_node_id = res->parent_node_id;
1990 
1991 	shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS *
1992 		sizeof(uint32_t));
1993 	if (shared_shaper_id == NULL) {
1994 		printf(" Memory not allocated for shared shapers (error)\n");
1995 		return;
1996 	}
1997 
1998 	/* Parse multi shared shaper id string */
1999 	ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id);
2000 	if (ret) {
2001 		printf(" Shared shapers params string parse error\n");
2002 		free(shared_shaper_id);
2003 		return;
2004 	}
2005 
2006 	if (res->shaper_profile_id < 0)
2007 		np.shaper_profile_id = UINT32_MAX;
2008 	else
2009 		np.shaper_profile_id = res->shaper_profile_id;
2010 
2011 	np.n_shared_shapers = n_shared_shapers;
2012 
2013 	if (np.n_shared_shapers) {
2014 		np.shared_shaper_id = &shared_shaper_id[0];
2015 	} else {
2016 		free(shared_shaper_id);
2017 		shared_shaper_id = NULL;
2018 	}
2019 
2020 	np.leaf.cman = res->cman_mode;
2021 	np.leaf.wred.wred_profile_id = res->wred_profile_id;
2022 	np.stats_mask = res->stats_mask;
2023 
2024 	ret = rte_tm_node_add(port_id, res->node_id, parent_node_id,
2025 				res->priority, res->weight, res->level_id,
2026 				&np, &error);
2027 	if (ret != 0) {
2028 		print_err_msg(&error);
2029 		free(shared_shaper_id);
2030 		return;
2031 	}
2032 }
2033 
2034 cmdline_parse_inst_t cmd_add_port_tm_leaf_node = {
2035 	.f = cmd_add_port_tm_leaf_node_parsed,
2036 	.data = NULL,
2037 	.help_str = "Add port tm leaf node",
2038 	.tokens = {
2039 		(void *)&cmd_add_port_tm_leaf_node_add,
2040 		(void *)&cmd_add_port_tm_leaf_node_port,
2041 		(void *)&cmd_add_port_tm_leaf_node_tm,
2042 		(void *)&cmd_add_port_tm_leaf_node_nonleaf,
2043 		(void *)&cmd_add_port_tm_leaf_node_node,
2044 		(void *)&cmd_add_port_tm_leaf_node_port_id,
2045 		(void *)&cmd_add_port_tm_leaf_node_node_id,
2046 		(void *)&cmd_add_port_tm_leaf_node_parent_node_id,
2047 		(void *)&cmd_add_port_tm_leaf_node_priority,
2048 		(void *)&cmd_add_port_tm_leaf_node_weight,
2049 		(void *)&cmd_add_port_tm_leaf_node_level_id,
2050 		(void *)&cmd_add_port_tm_leaf_node_shaper_profile_id,
2051 		(void *)&cmd_add_port_tm_leaf_node_cman_mode,
2052 		(void *)&cmd_add_port_tm_leaf_node_wred_profile_id,
2053 		(void *)&cmd_add_port_tm_leaf_node_stats_mask,
2054 		(void *)&cmd_add_port_tm_leaf_node_multi_shared_shaper_id,
2055 		NULL,
2056 	},
2057 };
2058 
2059 /* *** Delete Port TM Node *** */
2060 struct cmd_del_port_tm_node_result {
2061 	cmdline_fixed_string_t del;
2062 	cmdline_fixed_string_t port;
2063 	cmdline_fixed_string_t tm;
2064 	cmdline_fixed_string_t node;
2065 	uint16_t port_id;
2066 	uint32_t node_id;
2067 };
2068 
2069 cmdline_parse_token_string_t cmd_del_port_tm_node_del =
2070 	TOKEN_STRING_INITIALIZER(
2071 		struct cmd_del_port_tm_node_result, del, "del");
2072 cmdline_parse_token_string_t cmd_del_port_tm_node_port =
2073 	TOKEN_STRING_INITIALIZER(
2074 		struct cmd_del_port_tm_node_result, port, "port");
2075 cmdline_parse_token_string_t cmd_del_port_tm_node_tm =
2076 	TOKEN_STRING_INITIALIZER(
2077 		struct cmd_del_port_tm_node_result, tm, "tm");
2078 cmdline_parse_token_string_t cmd_del_port_tm_node_node =
2079 	TOKEN_STRING_INITIALIZER(
2080 		struct cmd_del_port_tm_node_result, node, "node");
2081 cmdline_parse_token_num_t cmd_del_port_tm_node_port_id =
2082 	TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result,
2083 		 port_id, RTE_UINT16);
2084 cmdline_parse_token_num_t cmd_del_port_tm_node_node_id =
2085 	TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result,
2086 		node_id, RTE_UINT32);
2087 
2088 static void cmd_del_port_tm_node_parsed(void *parsed_result,
2089 	__rte_unused struct cmdline *cl,
2090 	__rte_unused void *data)
2091 {
2092 	struct cmd_del_port_tm_node_result *res = parsed_result;
2093 	struct rte_tm_error error;
2094 	uint32_t node_id = res->node_id;
2095 	portid_t port_id = res->port_id;
2096 	int ret;
2097 
2098 	if (port_id_is_invalid(port_id, ENABLED_WARN))
2099 		return;
2100 
2101 	memset(&error, 0, sizeof(struct rte_tm_error));
2102 	/* Port status */
2103 	if (port_is_started(port_id)) {
2104 		printf(" Port %u not stopped (error)\n", port_id);
2105 		return;
2106 	}
2107 
2108 	ret = rte_tm_node_delete(port_id, node_id, &error);
2109 	if (ret != 0) {
2110 		print_err_msg(&error);
2111 		return;
2112 	}
2113 }
2114 
2115 cmdline_parse_inst_t cmd_del_port_tm_node = {
2116 	.f = cmd_del_port_tm_node_parsed,
2117 	.data = NULL,
2118 	.help_str = "Delete port tm node",
2119 	.tokens = {
2120 		(void *)&cmd_del_port_tm_node_del,
2121 		(void *)&cmd_del_port_tm_node_port,
2122 		(void *)&cmd_del_port_tm_node_tm,
2123 		(void *)&cmd_del_port_tm_node_node,
2124 		(void *)&cmd_del_port_tm_node_port_id,
2125 		(void *)&cmd_del_port_tm_node_node_id,
2126 		NULL,
2127 	},
2128 };
2129 
2130 /* *** Update Port TM Node Parent *** */
2131 struct cmd_set_port_tm_node_parent_result {
2132 	cmdline_fixed_string_t set;
2133 	cmdline_fixed_string_t port;
2134 	cmdline_fixed_string_t tm;
2135 	cmdline_fixed_string_t node;
2136 	cmdline_fixed_string_t parent;
2137 	uint16_t port_id;
2138 	uint32_t node_id;
2139 	uint32_t parent_id;
2140 	uint32_t priority;
2141 	uint32_t weight;
2142 };
2143 
2144 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_set =
2145 	TOKEN_STRING_INITIALIZER(
2146 		struct cmd_set_port_tm_node_parent_result, set, "set");
2147 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_port =
2148 	TOKEN_STRING_INITIALIZER(
2149 		struct cmd_set_port_tm_node_parent_result, port, "port");
2150 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_tm =
2151 	TOKEN_STRING_INITIALIZER(
2152 		struct cmd_set_port_tm_node_parent_result, tm, "tm");
2153 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_node =
2154 	TOKEN_STRING_INITIALIZER(
2155 		struct cmd_set_port_tm_node_parent_result, node, "node");
2156 cmdline_parse_token_string_t cmd_set_port_tm_node_parent_parent =
2157 	TOKEN_STRING_INITIALIZER(
2158 		struct cmd_set_port_tm_node_parent_result, parent, "parent");
2159 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_port_id =
2160 	TOKEN_NUM_INITIALIZER(
2161 		struct cmd_set_port_tm_node_parent_result, port_id,
2162 		RTE_UINT16);
2163 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_node_id =
2164 	TOKEN_NUM_INITIALIZER(
2165 		struct cmd_set_port_tm_node_parent_result, node_id,
2166 		RTE_UINT32);
2167 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_parent_id =
2168 	TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
2169 		parent_id, RTE_UINT32);
2170 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_priority =
2171 	TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
2172 		priority, RTE_UINT32);
2173 cmdline_parse_token_num_t cmd_set_port_tm_node_parent_weight =
2174 	TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result,
2175 		weight, RTE_UINT32);
2176 
2177 static void cmd_set_port_tm_node_parent_parsed(void *parsed_result,
2178 	__rte_unused struct cmdline *cl,
2179 	__rte_unused void *data)
2180 {
2181 	struct cmd_set_port_tm_node_parent_result *res = parsed_result;
2182 	struct rte_tm_error error;
2183 	uint32_t node_id = res->node_id;
2184 	uint32_t parent_id = res->parent_id;
2185 	uint32_t priority = res->priority;
2186 	uint32_t weight = res->weight;
2187 	portid_t port_id = res->port_id;
2188 	int ret;
2189 
2190 	if (port_id_is_invalid(port_id, ENABLED_WARN))
2191 		return;
2192 
2193 	memset(&error, 0, sizeof(struct rte_tm_error));
2194 	/* Port status */
2195 	if (!port_is_started(port_id)) {
2196 		printf(" Port %u not started (error)\n", port_id);
2197 		return;
2198 	}
2199 
2200 	ret = rte_tm_node_parent_update(port_id, node_id,
2201 		parent_id, priority, weight, &error);
2202 	if (ret != 0) {
2203 		print_err_msg(&error);
2204 		return;
2205 	}
2206 }
2207 
2208 cmdline_parse_inst_t cmd_set_port_tm_node_parent = {
2209 	.f = cmd_set_port_tm_node_parent_parsed,
2210 	.data = NULL,
2211 	.help_str = "Set port tm node parent",
2212 	.tokens = {
2213 		(void *)&cmd_set_port_tm_node_parent_set,
2214 		(void *)&cmd_set_port_tm_node_parent_port,
2215 		(void *)&cmd_set_port_tm_node_parent_tm,
2216 		(void *)&cmd_set_port_tm_node_parent_node,
2217 		(void *)&cmd_set_port_tm_node_parent_parent,
2218 		(void *)&cmd_set_port_tm_node_parent_port_id,
2219 		(void *)&cmd_set_port_tm_node_parent_node_id,
2220 		(void *)&cmd_set_port_tm_node_parent_parent_id,
2221 		(void *)&cmd_set_port_tm_node_parent_priority,
2222 		(void *)&cmd_set_port_tm_node_parent_weight,
2223 		NULL,
2224 	},
2225 };
2226 
2227 /* *** Suspend Port TM Node *** */
2228 struct cmd_suspend_port_tm_node_result {
2229 	cmdline_fixed_string_t suspend;
2230 	cmdline_fixed_string_t port;
2231 	cmdline_fixed_string_t tm;
2232 	cmdline_fixed_string_t node;
2233 	uint16_t port_id;
2234 	uint32_t node_id;
2235 };
2236 
2237 cmdline_parse_token_string_t cmd_suspend_port_tm_node_suspend =
2238 	TOKEN_STRING_INITIALIZER(
2239 		struct cmd_suspend_port_tm_node_result, suspend, "suspend");
2240 cmdline_parse_token_string_t cmd_suspend_port_tm_node_port =
2241 	TOKEN_STRING_INITIALIZER(
2242 		struct cmd_suspend_port_tm_node_result, port, "port");
2243 cmdline_parse_token_string_t cmd_suspend_port_tm_node_tm =
2244 	TOKEN_STRING_INITIALIZER(
2245 		struct cmd_suspend_port_tm_node_result, tm, "tm");
2246 cmdline_parse_token_string_t cmd_suspend_port_tm_node_node =
2247 	TOKEN_STRING_INITIALIZER(
2248 		struct cmd_suspend_port_tm_node_result, node, "node");
2249 cmdline_parse_token_num_t cmd_suspend_port_tm_node_port_id =
2250 	TOKEN_NUM_INITIALIZER(
2251 		struct cmd_suspend_port_tm_node_result, port_id,
2252 		RTE_UINT16);
2253 cmdline_parse_token_num_t cmd_suspend_port_tm_node_node_id =
2254 	TOKEN_NUM_INITIALIZER(
2255 		struct cmd_suspend_port_tm_node_result, node_id,
2256 		RTE_UINT32);
2257 
2258 static void cmd_suspend_port_tm_node_parsed(void *parsed_result,
2259 	__rte_unused struct cmdline *cl,
2260 	__rte_unused void *data)
2261 {
2262 	struct cmd_suspend_port_tm_node_result *res = parsed_result;
2263 	struct rte_tm_error error;
2264 	uint32_t node_id = res->node_id;
2265 	portid_t port_id = res->port_id;
2266 	int ret;
2267 
2268 	if (port_id_is_invalid(port_id, ENABLED_WARN))
2269 		return;
2270 
2271 	memset(&error, 0, sizeof(struct rte_tm_error));
2272 	ret = rte_tm_node_suspend(port_id, node_id, &error);
2273 	if (ret != 0) {
2274 		print_err_msg(&error);
2275 		return;
2276 	}
2277 }
2278 
2279 cmdline_parse_inst_t cmd_suspend_port_tm_node = {
2280 	.f = cmd_suspend_port_tm_node_parsed,
2281 	.data = NULL,
2282 	.help_str = "Suspend port tm node",
2283 	.tokens = {
2284 		(void *)&cmd_suspend_port_tm_node_suspend,
2285 		(void *)&cmd_suspend_port_tm_node_port,
2286 		(void *)&cmd_suspend_port_tm_node_tm,
2287 		(void *)&cmd_suspend_port_tm_node_node,
2288 		(void *)&cmd_suspend_port_tm_node_port_id,
2289 		(void *)&cmd_suspend_port_tm_node_node_id,
2290 		NULL,
2291 	},
2292 };
2293 
2294 /* *** Resume Port TM Node *** */
2295 struct cmd_resume_port_tm_node_result {
2296 	cmdline_fixed_string_t resume;
2297 	cmdline_fixed_string_t port;
2298 	cmdline_fixed_string_t tm;
2299 	cmdline_fixed_string_t node;
2300 	uint16_t port_id;
2301 	uint32_t node_id;
2302 };
2303 
2304 cmdline_parse_token_string_t cmd_resume_port_tm_node_resume =
2305 	TOKEN_STRING_INITIALIZER(
2306 		struct cmd_resume_port_tm_node_result, resume, "resume");
2307 cmdline_parse_token_string_t cmd_resume_port_tm_node_port =
2308 	TOKEN_STRING_INITIALIZER(
2309 		struct cmd_resume_port_tm_node_result, port, "port");
2310 cmdline_parse_token_string_t cmd_resume_port_tm_node_tm =
2311 	TOKEN_STRING_INITIALIZER(
2312 		struct cmd_resume_port_tm_node_result, tm, "tm");
2313 cmdline_parse_token_string_t cmd_resume_port_tm_node_node =
2314 	TOKEN_STRING_INITIALIZER(
2315 		struct cmd_resume_port_tm_node_result, node, "node");
2316 cmdline_parse_token_num_t cmd_resume_port_tm_node_port_id =
2317 	TOKEN_NUM_INITIALIZER(
2318 		struct cmd_resume_port_tm_node_result, port_id, RTE_UINT16);
2319 cmdline_parse_token_num_t cmd_resume_port_tm_node_node_id =
2320 	TOKEN_NUM_INITIALIZER(
2321 		struct cmd_resume_port_tm_node_result, node_id, RTE_UINT32);
2322 
2323 static void cmd_resume_port_tm_node_parsed(void *parsed_result,
2324 	__rte_unused struct cmdline *cl,
2325 	__rte_unused void *data)
2326 {
2327 	struct cmd_resume_port_tm_node_result *res = parsed_result;
2328 	struct rte_tm_error error;
2329 	uint32_t node_id = res->node_id;
2330 	portid_t port_id = res->port_id;
2331 	int ret;
2332 
2333 	if (port_id_is_invalid(port_id, ENABLED_WARN))
2334 		return;
2335 
2336 	memset(&error, 0, sizeof(struct rte_tm_error));
2337 	ret = rte_tm_node_resume(port_id, node_id, &error);
2338 	if (ret != 0) {
2339 		print_err_msg(&error);
2340 		return;
2341 	}
2342 }
2343 
2344 cmdline_parse_inst_t cmd_resume_port_tm_node = {
2345 	.f = cmd_resume_port_tm_node_parsed,
2346 	.data = NULL,
2347 	.help_str = "Resume port tm node",
2348 	.tokens = {
2349 		(void *)&cmd_resume_port_tm_node_resume,
2350 		(void *)&cmd_resume_port_tm_node_port,
2351 		(void *)&cmd_resume_port_tm_node_tm,
2352 		(void *)&cmd_resume_port_tm_node_node,
2353 		(void *)&cmd_resume_port_tm_node_port_id,
2354 		(void *)&cmd_resume_port_tm_node_node_id,
2355 		NULL,
2356 	},
2357 };
2358 
2359 /* *** Port TM Hierarchy Commit *** */
2360 struct cmd_port_tm_hierarchy_commit_result {
2361 	cmdline_fixed_string_t port;
2362 	cmdline_fixed_string_t tm;
2363 	cmdline_fixed_string_t hierarchy;
2364 	cmdline_fixed_string_t commit;
2365 	uint16_t port_id;
2366 	cmdline_fixed_string_t clean_on_fail;
2367 };
2368 
2369 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_port =
2370 	TOKEN_STRING_INITIALIZER(
2371 		struct cmd_port_tm_hierarchy_commit_result, port, "port");
2372 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_tm =
2373 	TOKEN_STRING_INITIALIZER(
2374 		struct cmd_port_tm_hierarchy_commit_result, tm, "tm");
2375 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_hierarchy =
2376 	TOKEN_STRING_INITIALIZER(
2377 		struct cmd_port_tm_hierarchy_commit_result,
2378 			hierarchy, "hierarchy");
2379 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_commit =
2380 	TOKEN_STRING_INITIALIZER(
2381 		struct cmd_port_tm_hierarchy_commit_result, commit, "commit");
2382 cmdline_parse_token_num_t cmd_port_tm_hierarchy_commit_port_id =
2383 	TOKEN_NUM_INITIALIZER(
2384 		struct cmd_port_tm_hierarchy_commit_result,
2385 			port_id, RTE_UINT16);
2386 cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_clean_on_fail =
2387 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_hierarchy_commit_result,
2388 		 clean_on_fail, "yes#no");
2389 
2390 static void cmd_port_tm_hierarchy_commit_parsed(void *parsed_result,
2391 	__rte_unused struct cmdline *cl,
2392 	__rte_unused void *data)
2393 {
2394 	struct cmd_port_tm_hierarchy_commit_result *res = parsed_result;
2395 	struct rte_tm_error error;
2396 	uint32_t clean_on_fail;
2397 	portid_t port_id = res->port_id;
2398 	int ret;
2399 
2400 	if (port_id_is_invalid(port_id, ENABLED_WARN))
2401 		return;
2402 
2403 	if (strcmp(res->clean_on_fail, "yes") == 0)
2404 		clean_on_fail = 1;
2405 	else
2406 		clean_on_fail = 0;
2407 
2408 	memset(&error, 0, sizeof(struct rte_tm_error));
2409 	ret = rte_tm_hierarchy_commit(port_id, clean_on_fail, &error);
2410 	if (ret != 0) {
2411 		print_err_msg(&error);
2412 		return;
2413 	}
2414 }
2415 
2416 cmdline_parse_inst_t cmd_port_tm_hierarchy_commit = {
2417 	.f = cmd_port_tm_hierarchy_commit_parsed,
2418 	.data = NULL,
2419 	.help_str = "Commit port tm hierarchy",
2420 	.tokens = {
2421 		(void *)&cmd_port_tm_hierarchy_commit_port,
2422 		(void *)&cmd_port_tm_hierarchy_commit_tm,
2423 		(void *)&cmd_port_tm_hierarchy_commit_hierarchy,
2424 		(void *)&cmd_port_tm_hierarchy_commit_commit,
2425 		(void *)&cmd_port_tm_hierarchy_commit_port_id,
2426 		(void *)&cmd_port_tm_hierarchy_commit_clean_on_fail,
2427 		NULL,
2428 	},
2429 };
2430 
2431 /* *** Port TM Mark IP ECN *** */
2432 struct cmd_port_tm_mark_ip_ecn_result {
2433 	cmdline_fixed_string_t set;
2434 	cmdline_fixed_string_t port;
2435 	cmdline_fixed_string_t tm;
2436 	cmdline_fixed_string_t mark;
2437 	cmdline_fixed_string_t ip_ecn;
2438 	uint16_t port_id;
2439 	uint16_t green;
2440 	uint16_t yellow;
2441 	uint16_t red;
2442 };
2443 
2444 cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_set =
2445 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2446 				 set, "set");
2447 
2448 cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_port =
2449 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2450 				 port, "port");
2451 
2452 cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_tm =
2453 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result, tm,
2454 				 "tm");
2455 
2456 cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_mark =
2457 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2458 				 mark, "mark");
2459 
2460 cmdline_parse_token_string_t cmd_port_tm_mark_ip_ecn_ip_ecn =
2461 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2462 				 ip_ecn, "ip_ecn");
2463 cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_port_id =
2464 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2465 			      port_id, RTE_UINT16);
2466 
2467 cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_green =
2468 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2469 			      green, RTE_UINT16);
2470 cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_yellow =
2471 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2472 			      yellow, RTE_UINT16);
2473 cmdline_parse_token_num_t cmd_port_tm_mark_ip_ecn_red =
2474 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_ecn_result,
2475 				red, RTE_UINT16);
2476 
2477 static void cmd_port_tm_mark_ip_ecn_parsed(void *parsed_result,
2478 	__rte_unused struct cmdline *cl,
2479 	__rte_unused void *data)
2480 {
2481 	struct cmd_port_tm_mark_ip_ecn_result *res = parsed_result;
2482 	struct rte_tm_error error;
2483 	portid_t port_id = res->port_id;
2484 	int green = res->green;
2485 	int yellow = res->yellow;
2486 	int red = res->red;
2487 	int ret;
2488 	if (port_id_is_invalid(port_id, ENABLED_WARN))
2489 		return;
2490 
2491 	memset(&error, 0, sizeof(struct rte_tm_error));
2492 	ret = rte_tm_mark_ip_ecn(port_id, green, yellow, red, &error);
2493 	if (ret != 0) {
2494 		print_err_msg(&error);
2495 		return;
2496 	}
2497 }
2498 
2499 cmdline_parse_inst_t cmd_port_tm_mark_ip_ecn = {
2500 	.f = cmd_port_tm_mark_ip_ecn_parsed,
2501 	.data = NULL,
2502 	.help_str = "set port tm mark ip_ecn <port> <green> <yellow> <red>",
2503 	.tokens = {
2504 		(void *)&cmd_port_tm_mark_ip_ecn_set,
2505 		(void *)&cmd_port_tm_mark_ip_ecn_port,
2506 		(void *)&cmd_port_tm_mark_ip_ecn_tm,
2507 		(void *)&cmd_port_tm_mark_ip_ecn_mark,
2508 		(void *)&cmd_port_tm_mark_ip_ecn_ip_ecn,
2509 		(void *)&cmd_port_tm_mark_ip_ecn_port_id,
2510 		(void *)&cmd_port_tm_mark_ip_ecn_green,
2511 		(void *)&cmd_port_tm_mark_ip_ecn_yellow,
2512 		(void *)&cmd_port_tm_mark_ip_ecn_red,
2513 		NULL,
2514 	},
2515 };
2516 
2517 
2518 /* *** Port TM Mark IP DSCP *** */
2519 struct cmd_port_tm_mark_ip_dscp_result {
2520 	cmdline_fixed_string_t set;
2521 	cmdline_fixed_string_t port;
2522 	cmdline_fixed_string_t tm;
2523 	cmdline_fixed_string_t mark;
2524 	cmdline_fixed_string_t ip_dscp;
2525 	uint16_t port_id;
2526 	uint16_t green;
2527 	uint16_t yellow;
2528 	uint16_t red;
2529 };
2530 
2531 cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_set =
2532 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2533 				 set, "set");
2534 
2535 cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_port =
2536 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2537 				 port, "port");
2538 
2539 cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_tm =
2540 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result, tm,
2541 				 "tm");
2542 
2543 cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_mark =
2544 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2545 				 mark, "mark");
2546 
2547 cmdline_parse_token_string_t cmd_port_tm_mark_ip_dscp_ip_dscp =
2548 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2549 				 ip_dscp, "ip_dscp");
2550 cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_port_id =
2551 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2552 			      port_id, RTE_UINT16);
2553 
2554 cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_green =
2555 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2556 				green, RTE_UINT16);
2557 cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_yellow =
2558 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2559 				yellow, RTE_UINT16);
2560 cmdline_parse_token_num_t cmd_port_tm_mark_ip_dscp_red =
2561 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_ip_dscp_result,
2562 				red, RTE_UINT16);
2563 
2564 static void cmd_port_tm_mark_ip_dscp_parsed(void *parsed_result,
2565 	__rte_unused struct cmdline *cl,
2566 	__rte_unused void *data)
2567 {
2568 	struct cmd_port_tm_mark_ip_dscp_result *res = parsed_result;
2569 	struct rte_tm_error error;
2570 	portid_t port_id = res->port_id;
2571 	int green = res->green;
2572 	int yellow = res->yellow;
2573 	int red = res->red;
2574 	int ret;
2575 	if (port_id_is_invalid(port_id, ENABLED_WARN))
2576 		return;
2577 
2578 	memset(&error, 0, sizeof(struct rte_tm_error));
2579 	ret = rte_tm_mark_ip_dscp(port_id, green, yellow, red, &error);
2580 	if (ret != 0) {
2581 		print_err_msg(&error);
2582 		return;
2583 	}
2584 }
2585 
2586 cmdline_parse_inst_t cmd_port_tm_mark_ip_dscp = {
2587 	.f = cmd_port_tm_mark_ip_dscp_parsed,
2588 	.data = NULL,
2589 	.help_str = "set port tm mark ip_dscp <port> <green> <yellow> <red>",
2590 	.tokens = {
2591 		(void *)&cmd_port_tm_mark_ip_dscp_set,
2592 		(void *)&cmd_port_tm_mark_ip_dscp_port,
2593 		(void *)&cmd_port_tm_mark_ip_dscp_tm,
2594 		(void *)&cmd_port_tm_mark_ip_dscp_mark,
2595 		(void *)&cmd_port_tm_mark_ip_dscp_ip_dscp,
2596 		(void *)&cmd_port_tm_mark_ip_dscp_port_id,
2597 		(void *)&cmd_port_tm_mark_ip_dscp_green,
2598 		(void *)&cmd_port_tm_mark_ip_dscp_yellow,
2599 		(void *)&cmd_port_tm_mark_ip_dscp_red,
2600 		NULL,
2601 	},
2602 };
2603 
2604 
2605 /* *** Port TM Mark VLAN_DEI *** */
2606 struct cmd_port_tm_mark_vlan_dei_result {
2607 	cmdline_fixed_string_t set;
2608 	cmdline_fixed_string_t port;
2609 	cmdline_fixed_string_t tm;
2610 	cmdline_fixed_string_t mark;
2611 	cmdline_fixed_string_t vlan_dei;
2612 	uint16_t port_id;
2613 	uint16_t green;
2614 	uint16_t yellow;
2615 	uint16_t red;
2616 };
2617 
2618 cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_set =
2619 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2620 				 set, "set");
2621 
2622 cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_port =
2623 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2624 				 port, "port");
2625 
2626 cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_tm =
2627 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result, tm,
2628 				 "tm");
2629 
2630 cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_mark =
2631 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2632 				 mark, "mark");
2633 
2634 cmdline_parse_token_string_t cmd_port_tm_mark_vlan_dei_vlan_dei =
2635 	TOKEN_STRING_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2636 				 vlan_dei, "vlan_dei");
2637 cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_port_id =
2638 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2639 			      port_id, RTE_UINT16);
2640 
2641 cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_green =
2642 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2643 				green, RTE_UINT16);
2644 cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_yellow =
2645 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2646 				yellow, RTE_UINT16);
2647 cmdline_parse_token_num_t cmd_port_tm_mark_vlan_dei_red =
2648 	TOKEN_NUM_INITIALIZER(struct cmd_port_tm_mark_vlan_dei_result,
2649 				red, RTE_UINT16);
2650 
2651 static void cmd_port_tm_mark_vlan_dei_parsed(void *parsed_result,
2652 	__rte_unused struct cmdline *cl,
2653 	__rte_unused void *data)
2654 {
2655 	struct cmd_port_tm_mark_vlan_dei_result *res = parsed_result;
2656 	struct rte_tm_error error;
2657 	portid_t port_id = res->port_id;
2658 	int green = res->green;
2659 	int yellow = res->yellow;
2660 	int red = res->red;
2661 	int ret;
2662 	if (port_id_is_invalid(port_id, ENABLED_WARN))
2663 		return;
2664 
2665 	memset(&error, 0, sizeof(struct rte_tm_error));
2666 	ret = rte_tm_mark_vlan_dei(port_id, green, yellow, red, &error);
2667 	if (ret != 0) {
2668 		print_err_msg(&error);
2669 		return;
2670 	}
2671 }
2672 
2673 cmdline_parse_inst_t cmd_port_tm_mark_vlan_dei = {
2674 	.f = cmd_port_tm_mark_vlan_dei_parsed,
2675 	.data = NULL,
2676 	.help_str = "set port tm mark vlan_dei <port> <green> <yellow> <red>",
2677 	.tokens = {
2678 		(void *)&cmd_port_tm_mark_vlan_dei_set,
2679 		(void *)&cmd_port_tm_mark_vlan_dei_port,
2680 		(void *)&cmd_port_tm_mark_vlan_dei_tm,
2681 		(void *)&cmd_port_tm_mark_vlan_dei_mark,
2682 		(void *)&cmd_port_tm_mark_vlan_dei_vlan_dei,
2683 		(void *)&cmd_port_tm_mark_vlan_dei_port_id,
2684 		(void *)&cmd_port_tm_mark_vlan_dei_green,
2685 		(void *)&cmd_port_tm_mark_vlan_dei_yellow,
2686 		(void *)&cmd_port_tm_mark_vlan_dei_red,
2687 		NULL,
2688 	},
2689 };
2690