xref: /dpdk/drivers/net/bonding/bonding_testpmd.c (revision 4f84008676739874712cb95f3c3df62198b80dc8)
1703178f8SDavid Marchand /* SPDX-License-Identifier: BSD-3-Clause
2703178f8SDavid Marchand  * Copyright(c) 2010-2016 Intel Corporation.
3703178f8SDavid Marchand  */
4703178f8SDavid Marchand 
5703178f8SDavid Marchand #include <rte_eth_bond.h>
6703178f8SDavid Marchand #include <rte_eth_bond_8023ad.h>
7703178f8SDavid Marchand 
8703178f8SDavid Marchand #include <cmdline_parse.h>
9703178f8SDavid Marchand #include <cmdline_parse_etheraddr.h>
10703178f8SDavid Marchand #include <cmdline_parse_num.h>
11703178f8SDavid Marchand #include <cmdline_parse_string.h>
12703178f8SDavid Marchand 
13703178f8SDavid Marchand #include "testpmd.h"
14703178f8SDavid Marchand 
15703178f8SDavid Marchand /* *** SET BONDING MODE *** */
16703178f8SDavid Marchand struct cmd_set_bonding_mode_result {
17703178f8SDavid Marchand 	cmdline_fixed_string_t set;
18703178f8SDavid Marchand 	cmdline_fixed_string_t bonding;
19703178f8SDavid Marchand 	cmdline_fixed_string_t mode;
20703178f8SDavid Marchand 	uint8_t value;
21703178f8SDavid Marchand 	portid_t port_id;
22703178f8SDavid Marchand };
23703178f8SDavid Marchand 
cmd_set_bonding_mode_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)24703178f8SDavid Marchand static void cmd_set_bonding_mode_parsed(void *parsed_result,
25703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
26703178f8SDavid Marchand {
27703178f8SDavid Marchand 	struct cmd_set_bonding_mode_result *res = parsed_result;
28703178f8SDavid Marchand 	portid_t port_id = res->port_id;
29703178f8SDavid Marchand 	struct rte_port *port = &ports[port_id];
30703178f8SDavid Marchand 
31703178f8SDavid Marchand 	/*
32703178f8SDavid Marchand 	 * Bonding mode changed means resources of device changed, like whether
33703178f8SDavid Marchand 	 * started rte timer or not. Device should be restarted when resources
34703178f8SDavid Marchand 	 * of device changed.
35703178f8SDavid Marchand 	 */
36703178f8SDavid Marchand 	if (port->port_status != RTE_PORT_STOPPED) {
37703178f8SDavid Marchand 		fprintf(stderr,
38703178f8SDavid Marchand 			"\t Error: Can't set bonding mode when port %d is not stopped\n",
39703178f8SDavid Marchand 			port_id);
40703178f8SDavid Marchand 		return;
41703178f8SDavid Marchand 	}
42703178f8SDavid Marchand 
43703178f8SDavid Marchand 	/* Set the bonding mode for the relevant port. */
44703178f8SDavid Marchand 	if (rte_eth_bond_mode_set(port_id, res->value) != 0)
45703178f8SDavid Marchand 		fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n",
46703178f8SDavid Marchand 			port_id);
47703178f8SDavid Marchand }
48703178f8SDavid Marchand 
49703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_mode_set =
50703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
51703178f8SDavid Marchand 		set, "set");
52703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_mode_bonding =
53703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
54703178f8SDavid Marchand 		bonding, "bonding");
55703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_mode_mode =
56703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result,
57703178f8SDavid Marchand 		mode, "mode");
58703178f8SDavid Marchand static cmdline_parse_token_num_t cmd_setbonding_mode_value =
59703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
60703178f8SDavid Marchand 		value, RTE_UINT8);
61703178f8SDavid Marchand static cmdline_parse_token_num_t cmd_setbonding_mode_port =
62703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result,
63703178f8SDavid Marchand 		port_id, RTE_UINT16);
64703178f8SDavid Marchand 
65703178f8SDavid Marchand static cmdline_parse_inst_t cmd_set_bonding_mode = {
66703178f8SDavid Marchand 	.f = cmd_set_bonding_mode_parsed,
67703178f8SDavid Marchand 	.help_str = "set bonding mode <mode_value> <port_id>: "
68703178f8SDavid Marchand 		"Set the bonding mode for port_id",
69703178f8SDavid Marchand 	.data = NULL,
70703178f8SDavid Marchand 	.tokens = {
71703178f8SDavid Marchand 		(void *)&cmd_setbonding_mode_set,
72703178f8SDavid Marchand 		(void *)&cmd_setbonding_mode_bonding,
73703178f8SDavid Marchand 		(void *)&cmd_setbonding_mode_mode,
74703178f8SDavid Marchand 		(void *)&cmd_setbonding_mode_value,
75703178f8SDavid Marchand 		(void *)&cmd_setbonding_mode_port,
76703178f8SDavid Marchand 		NULL
77703178f8SDavid Marchand 	}
78703178f8SDavid Marchand };
79703178f8SDavid Marchand 
80703178f8SDavid Marchand /* *** SET BONDING SLOW_QUEUE SW/HW *** */
81703178f8SDavid Marchand struct cmd_set_bonding_lacp_dedicated_queues_result {
82703178f8SDavid Marchand 	cmdline_fixed_string_t set;
83703178f8SDavid Marchand 	cmdline_fixed_string_t bonding;
84703178f8SDavid Marchand 	cmdline_fixed_string_t lacp;
85703178f8SDavid Marchand 	cmdline_fixed_string_t dedicated_queues;
86703178f8SDavid Marchand 	portid_t port_id;
87703178f8SDavid Marchand 	cmdline_fixed_string_t mode;
88703178f8SDavid Marchand };
89703178f8SDavid Marchand 
cmd_set_bonding_lacp_dedicated_queues_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)90703178f8SDavid Marchand static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result,
91703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
92703178f8SDavid Marchand {
93703178f8SDavid Marchand 	struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result;
94703178f8SDavid Marchand 	portid_t port_id = res->port_id;
95703178f8SDavid Marchand 	struct rte_port *port;
96703178f8SDavid Marchand 
97703178f8SDavid Marchand 	port = &ports[port_id];
98703178f8SDavid Marchand 
99703178f8SDavid Marchand 	/** Check if the port is not started **/
100703178f8SDavid Marchand 	if (port->port_status != RTE_PORT_STOPPED) {
101703178f8SDavid Marchand 		fprintf(stderr, "Please stop port %d first\n", port_id);
102703178f8SDavid Marchand 		return;
103703178f8SDavid Marchand 	}
104703178f8SDavid Marchand 
105703178f8SDavid Marchand 	if (!strcmp(res->mode, "enable")) {
106703178f8SDavid Marchand 		if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0)
107703178f8SDavid Marchand 			printf("Dedicate queues for LACP control packets"
108703178f8SDavid Marchand 					" enabled\n");
109703178f8SDavid Marchand 		else
110703178f8SDavid Marchand 			printf("Enabling dedicate queues for LACP control "
111703178f8SDavid Marchand 					"packets on port %d failed\n", port_id);
112703178f8SDavid Marchand 	} else if (!strcmp(res->mode, "disable")) {
113703178f8SDavid Marchand 		if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0)
114703178f8SDavid Marchand 			printf("Dedicated queues for LACP control packets "
115703178f8SDavid Marchand 					"disabled\n");
116703178f8SDavid Marchand 		else
117703178f8SDavid Marchand 			printf("Disabling dedicated queues for LACP control "
118703178f8SDavid Marchand 					"traffic on port %d failed\n", port_id);
119703178f8SDavid Marchand 	}
120703178f8SDavid Marchand }
121703178f8SDavid Marchand 
122703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set =
123703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
124703178f8SDavid Marchand 		set, "set");
125703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding =
126703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
127703178f8SDavid Marchand 		bonding, "bonding");
128703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp =
129703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
130703178f8SDavid Marchand 		lacp, "lacp");
131703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues =
132703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
133703178f8SDavid Marchand 		dedicated_queues, "dedicated_queues");
134703178f8SDavid Marchand static cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id =
135703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
136703178f8SDavid Marchand 		port_id, RTE_UINT16);
137703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode =
138703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result,
139703178f8SDavid Marchand 		mode, "enable#disable");
140703178f8SDavid Marchand 
141703178f8SDavid Marchand static cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = {
142703178f8SDavid Marchand 	.f = cmd_set_bonding_lacp_dedicated_queues_parsed,
143703178f8SDavid Marchand 	.help_str = "set bonding lacp dedicated_queues <port_id> "
144703178f8SDavid Marchand 		"enable|disable: "
145703178f8SDavid Marchand 		"Enable/disable dedicated queues for LACP control traffic for port_id",
146703178f8SDavid Marchand 	.data = NULL,
147703178f8SDavid Marchand 	.tokens = {
148703178f8SDavid Marchand 		(void *)&cmd_setbonding_lacp_dedicated_queues_set,
149703178f8SDavid Marchand 		(void *)&cmd_setbonding_lacp_dedicated_queues_bonding,
150703178f8SDavid Marchand 		(void *)&cmd_setbonding_lacp_dedicated_queues_lacp,
151703178f8SDavid Marchand 		(void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues,
152703178f8SDavid Marchand 		(void *)&cmd_setbonding_lacp_dedicated_queues_port_id,
153703178f8SDavid Marchand 		(void *)&cmd_setbonding_lacp_dedicated_queues_mode,
154703178f8SDavid Marchand 		NULL
155703178f8SDavid Marchand 	}
156703178f8SDavid Marchand };
157703178f8SDavid Marchand 
158703178f8SDavid Marchand /* *** SET BALANCE XMIT POLICY *** */
159703178f8SDavid Marchand struct cmd_set_bonding_balance_xmit_policy_result {
160703178f8SDavid Marchand 	cmdline_fixed_string_t set;
161703178f8SDavid Marchand 	cmdline_fixed_string_t bonding;
162703178f8SDavid Marchand 	cmdline_fixed_string_t balance_xmit_policy;
163703178f8SDavid Marchand 	portid_t port_id;
164703178f8SDavid Marchand 	cmdline_fixed_string_t policy;
165703178f8SDavid Marchand };
166703178f8SDavid Marchand 
cmd_set_bonding_balance_xmit_policy_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)167703178f8SDavid Marchand static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result,
168703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
169703178f8SDavid Marchand {
170703178f8SDavid Marchand 	struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result;
171703178f8SDavid Marchand 	portid_t port_id = res->port_id;
172703178f8SDavid Marchand 	uint8_t policy;
173703178f8SDavid Marchand 
174703178f8SDavid Marchand 	if (!strcmp(res->policy, "l2")) {
175703178f8SDavid Marchand 		policy = BALANCE_XMIT_POLICY_LAYER2;
176703178f8SDavid Marchand 	} else if (!strcmp(res->policy, "l23")) {
177703178f8SDavid Marchand 		policy = BALANCE_XMIT_POLICY_LAYER23;
178703178f8SDavid Marchand 	} else if (!strcmp(res->policy, "l34")) {
179703178f8SDavid Marchand 		policy = BALANCE_XMIT_POLICY_LAYER34;
180703178f8SDavid Marchand 	} else {
181703178f8SDavid Marchand 		fprintf(stderr, "\t Invalid xmit policy selection");
182703178f8SDavid Marchand 		return;
183703178f8SDavid Marchand 	}
184703178f8SDavid Marchand 
185703178f8SDavid Marchand 	/* Set the bonding mode for the relevant port. */
186703178f8SDavid Marchand 	if (rte_eth_bond_xmit_policy_set(port_id, policy) != 0) {
187703178f8SDavid Marchand 		fprintf(stderr,
188703178f8SDavid Marchand 			"\t Failed to set bonding balance xmit policy for port = %d.\n",
189703178f8SDavid Marchand 			port_id);
190703178f8SDavid Marchand 	}
191703178f8SDavid Marchand }
192703178f8SDavid Marchand 
193703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set =
194703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
195703178f8SDavid Marchand 		set, "set");
196703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding =
197703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
198703178f8SDavid Marchand 		bonding, "bonding");
199703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy =
200703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
201703178f8SDavid Marchand 		balance_xmit_policy, "balance_xmit_policy");
202703178f8SDavid Marchand static cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port =
203703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
204703178f8SDavid Marchand 		port_id, RTE_UINT16);
205703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy =
206703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
207703178f8SDavid Marchand 		policy, "l2#l23#l34");
208703178f8SDavid Marchand 
209703178f8SDavid Marchand static cmdline_parse_inst_t cmd_set_balance_xmit_policy = {
210703178f8SDavid Marchand 	.f = cmd_set_bonding_balance_xmit_policy_parsed,
211703178f8SDavid Marchand 	.help_str = "set bonding balance_xmit_policy <port_id> "
212703178f8SDavid Marchand 		"l2|l23|l34: "
213703178f8SDavid Marchand 		"Set the bonding balance_xmit_policy for port_id",
214703178f8SDavid Marchand 	.data = NULL,
215703178f8SDavid Marchand 	.tokens = {
216703178f8SDavid Marchand 		(void *)&cmd_setbonding_balance_xmit_policy_set,
217703178f8SDavid Marchand 		(void *)&cmd_setbonding_balance_xmit_policy_bonding,
218703178f8SDavid Marchand 		(void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy,
219703178f8SDavid Marchand 		(void *)&cmd_setbonding_balance_xmit_policy_port,
220703178f8SDavid Marchand 		(void *)&cmd_setbonding_balance_xmit_policy_policy,
221703178f8SDavid Marchand 		NULL
222703178f8SDavid Marchand 	}
223703178f8SDavid Marchand };
224703178f8SDavid Marchand 
225703178f8SDavid Marchand /* *** SHOW NIC BONDING CONFIGURATION *** */
226703178f8SDavid Marchand struct cmd_show_bonding_config_result {
227703178f8SDavid Marchand 	cmdline_fixed_string_t show;
228703178f8SDavid Marchand 	cmdline_fixed_string_t bonding;
229703178f8SDavid Marchand 	cmdline_fixed_string_t config;
230703178f8SDavid Marchand 	portid_t port_id;
231703178f8SDavid Marchand };
232703178f8SDavid Marchand 
cmd_show_bonding_config_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)233703178f8SDavid Marchand static void cmd_show_bonding_config_parsed(void *parsed_result,
234703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
235703178f8SDavid Marchand {
236703178f8SDavid Marchand 	struct cmd_show_bonding_config_result *res = parsed_result;
237703178f8SDavid Marchand 	portid_t port_id = res->port_id;
238f3b5f3d3SChengwen Feng 	int bonding_mode;
239703178f8SDavid Marchand 
240703178f8SDavid Marchand 	bonding_mode = rte_eth_bond_mode_get(port_id);
241703178f8SDavid Marchand 	if (bonding_mode < 0) {
242703178f8SDavid Marchand 		fprintf(stderr, "\tFailed to get bonding mode for port = %d\n",
243703178f8SDavid Marchand 			port_id);
244703178f8SDavid Marchand 		return;
245703178f8SDavid Marchand 	}
246703178f8SDavid Marchand 
247f3b5f3d3SChengwen Feng 	(void)rte_eth_dev_priv_dump(port_id, stdout);
248703178f8SDavid Marchand }
249703178f8SDavid Marchand 
250703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_showbonding_config_show =
251703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
252703178f8SDavid Marchand 		show, "show");
253703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_showbonding_config_bonding =
254703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
255703178f8SDavid Marchand 		bonding, "bonding");
256703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_showbonding_config_config =
257703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result,
258703178f8SDavid Marchand 		config, "config");
259703178f8SDavid Marchand static cmdline_parse_token_num_t cmd_showbonding_config_port =
260703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result,
261703178f8SDavid Marchand 		port_id, RTE_UINT16);
262703178f8SDavid Marchand 
263703178f8SDavid Marchand static cmdline_parse_inst_t cmd_show_bonding_config = {
264703178f8SDavid Marchand 	.f = cmd_show_bonding_config_parsed,
265703178f8SDavid Marchand 	.help_str = "show bonding config <port_id>: "
266703178f8SDavid Marchand 		"Show the bonding config for port_id",
267703178f8SDavid Marchand 	.data = NULL,
268703178f8SDavid Marchand 	.tokens = {
269703178f8SDavid Marchand 		(void *)&cmd_showbonding_config_show,
270703178f8SDavid Marchand 		(void *)&cmd_showbonding_config_bonding,
271703178f8SDavid Marchand 		(void *)&cmd_showbonding_config_config,
272703178f8SDavid Marchand 		(void *)&cmd_showbonding_config_port,
273703178f8SDavid Marchand 		NULL
274703178f8SDavid Marchand 	}
275703178f8SDavid Marchand };
276703178f8SDavid Marchand 
277703178f8SDavid Marchand /* *** SET BONDING PRIMARY *** */
278703178f8SDavid Marchand struct cmd_set_bonding_primary_result {
279703178f8SDavid Marchand 	cmdline_fixed_string_t set;
280703178f8SDavid Marchand 	cmdline_fixed_string_t bonding;
281703178f8SDavid Marchand 	cmdline_fixed_string_t primary;
28215e34522SLong Wu 	portid_t member_id;
283703178f8SDavid Marchand 	portid_t port_id;
284703178f8SDavid Marchand };
285703178f8SDavid Marchand 
cmd_set_bonding_primary_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)286703178f8SDavid Marchand static void cmd_set_bonding_primary_parsed(void *parsed_result,
287703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
288703178f8SDavid Marchand {
289703178f8SDavid Marchand 	struct cmd_set_bonding_primary_result *res = parsed_result;
29015e34522SLong Wu 	portid_t main_port_id = res->port_id;
29115e34522SLong Wu 	portid_t member_port_id = res->member_id;
292703178f8SDavid Marchand 
293*4f840086SLong Wu 	/* Set the primary member for a bonding device. */
29415e34522SLong Wu 	if (rte_eth_bond_primary_set(main_port_id, member_port_id) != 0) {
29515e34522SLong Wu 		fprintf(stderr, "\t Failed to set primary member for port = %d.\n",
29615e34522SLong Wu 			main_port_id);
297703178f8SDavid Marchand 		return;
298703178f8SDavid Marchand 	}
299703178f8SDavid Marchand 	init_port_config();
300703178f8SDavid Marchand }
301703178f8SDavid Marchand 
302703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_primary_set =
303703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
304703178f8SDavid Marchand 		set, "set");
305703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_primary_bonding =
306703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
307703178f8SDavid Marchand 		bonding, "bonding");
308703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_setbonding_primary_primary =
309703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result,
310703178f8SDavid Marchand 		primary, "primary");
31115e34522SLong Wu static cmdline_parse_token_num_t cmd_setbonding_primary_member =
312703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
31315e34522SLong Wu 		member_id, RTE_UINT16);
314703178f8SDavid Marchand static cmdline_parse_token_num_t cmd_setbonding_primary_port =
315703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result,
316703178f8SDavid Marchand 		port_id, RTE_UINT16);
317703178f8SDavid Marchand 
318703178f8SDavid Marchand static cmdline_parse_inst_t cmd_set_bonding_primary = {
319703178f8SDavid Marchand 	.f = cmd_set_bonding_primary_parsed,
32015e34522SLong Wu 	.help_str = "set bonding primary <member_id> <port_id>: "
32115e34522SLong Wu 		"Set the primary member for port_id",
322703178f8SDavid Marchand 	.data = NULL,
323703178f8SDavid Marchand 	.tokens = {
324703178f8SDavid Marchand 		(void *)&cmd_setbonding_primary_set,
325703178f8SDavid Marchand 		(void *)&cmd_setbonding_primary_bonding,
326703178f8SDavid Marchand 		(void *)&cmd_setbonding_primary_primary,
32715e34522SLong Wu 		(void *)&cmd_setbonding_primary_member,
328703178f8SDavid Marchand 		(void *)&cmd_setbonding_primary_port,
329703178f8SDavid Marchand 		NULL
330703178f8SDavid Marchand 	}
331703178f8SDavid Marchand };
332703178f8SDavid Marchand 
33315e34522SLong Wu /* *** ADD Member *** */
33415e34522SLong Wu struct cmd_add_bonding_member_result {
335703178f8SDavid Marchand 	cmdline_fixed_string_t add;
336703178f8SDavid Marchand 	cmdline_fixed_string_t bonding;
33715e34522SLong Wu 	cmdline_fixed_string_t member;
33815e34522SLong Wu 	portid_t member_id;
339703178f8SDavid Marchand 	portid_t port_id;
340703178f8SDavid Marchand };
341703178f8SDavid Marchand 
cmd_add_bonding_member_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)34215e34522SLong Wu static void cmd_add_bonding_member_parsed(void *parsed_result,
343703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
344703178f8SDavid Marchand {
34515e34522SLong Wu 	struct cmd_add_bonding_member_result *res = parsed_result;
34615e34522SLong Wu 	portid_t main_port_id = res->port_id;
34715e34522SLong Wu 	portid_t member_port_id = res->member_id;
348703178f8SDavid Marchand 
349*4f840086SLong Wu 	/* add the member for a bonding device. */
35015e34522SLong Wu 	if (rte_eth_bond_member_add(main_port_id, member_port_id) != 0) {
351703178f8SDavid Marchand 		fprintf(stderr,
35215e34522SLong Wu 			"\t Failed to add member %d to main port = %d.\n",
35315e34522SLong Wu 			member_port_id, main_port_id);
354703178f8SDavid Marchand 		return;
355703178f8SDavid Marchand 	}
35615e34522SLong Wu 	ports[main_port_id].update_conf = 1;
357703178f8SDavid Marchand 	init_port_config();
35815e34522SLong Wu 	set_port_member_flag(member_port_id);
359703178f8SDavid Marchand }
360703178f8SDavid Marchand 
36115e34522SLong Wu static cmdline_parse_token_string_t cmd_addbonding_member_add =
36215e34522SLong Wu 	TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_member_result,
363703178f8SDavid Marchand 		add, "add");
36415e34522SLong Wu static cmdline_parse_token_string_t cmd_addbonding_member_bonding =
36515e34522SLong Wu 	TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_member_result,
366703178f8SDavid Marchand 		bonding, "bonding");
36715e34522SLong Wu static cmdline_parse_token_string_t cmd_addbonding_member_member =
36815e34522SLong Wu 	TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_member_result,
36915e34522SLong Wu 		member, "member");
37015e34522SLong Wu static cmdline_parse_token_num_t cmd_addbonding_member_memberid =
37115e34522SLong Wu 	TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_member_result,
37215e34522SLong Wu 		member_id, RTE_UINT16);
37315e34522SLong Wu static cmdline_parse_token_num_t cmd_addbonding_member_port =
37415e34522SLong Wu 	TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_member_result,
375703178f8SDavid Marchand 		port_id, RTE_UINT16);
376703178f8SDavid Marchand 
37715e34522SLong Wu static cmdline_parse_inst_t cmd_add_bonding_member = {
37815e34522SLong Wu 	.f = cmd_add_bonding_member_parsed,
37915e34522SLong Wu 	.help_str = "add bonding member <member_id> <port_id>: "
380*4f840086SLong Wu 		"Add a member device to a bonding device",
381703178f8SDavid Marchand 	.data = NULL,
382703178f8SDavid Marchand 	.tokens = {
38315e34522SLong Wu 		(void *)&cmd_addbonding_member_add,
38415e34522SLong Wu 		(void *)&cmd_addbonding_member_bonding,
38515e34522SLong Wu 		(void *)&cmd_addbonding_member_member,
38615e34522SLong Wu 		(void *)&cmd_addbonding_member_memberid,
38715e34522SLong Wu 		(void *)&cmd_addbonding_member_port,
388703178f8SDavid Marchand 		NULL
389703178f8SDavid Marchand 	}
390703178f8SDavid Marchand };
391703178f8SDavid Marchand 
39215e34522SLong Wu /* *** REMOVE Member *** */
39315e34522SLong Wu struct cmd_remove_bonding_member_result {
394703178f8SDavid Marchand 	cmdline_fixed_string_t remove;
395703178f8SDavid Marchand 	cmdline_fixed_string_t bonding;
39615e34522SLong Wu 	cmdline_fixed_string_t member;
39715e34522SLong Wu 	portid_t member_id;
398703178f8SDavid Marchand 	portid_t port_id;
399703178f8SDavid Marchand };
400703178f8SDavid Marchand 
cmd_remove_bonding_member_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)40115e34522SLong Wu static void cmd_remove_bonding_member_parsed(void *parsed_result,
402703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
403703178f8SDavid Marchand {
40415e34522SLong Wu 	struct cmd_remove_bonding_member_result *res = parsed_result;
40515e34522SLong Wu 	portid_t main_port_id = res->port_id;
40615e34522SLong Wu 	portid_t member_port_id = res->member_id;
407703178f8SDavid Marchand 
408*4f840086SLong Wu 	/* remove the member from a bonding device. */
40915e34522SLong Wu 	if (rte_eth_bond_member_remove(main_port_id, member_port_id) != 0) {
410703178f8SDavid Marchand 		fprintf(stderr,
41115e34522SLong Wu 			"\t Failed to remove member %d from main port = %d.\n",
41215e34522SLong Wu 			member_port_id, main_port_id);
413703178f8SDavid Marchand 		return;
414703178f8SDavid Marchand 	}
415703178f8SDavid Marchand 	init_port_config();
41615e34522SLong Wu 	clear_port_member_flag(member_port_id);
417703178f8SDavid Marchand }
418703178f8SDavid Marchand 
41915e34522SLong Wu static cmdline_parse_token_string_t cmd_removebonding_member_remove =
42015e34522SLong Wu 	TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_member_result,
421703178f8SDavid Marchand 		remove, "remove");
42215e34522SLong Wu static cmdline_parse_token_string_t cmd_removebonding_member_bonding =
42315e34522SLong Wu 	TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_member_result,
424703178f8SDavid Marchand 		bonding, "bonding");
42515e34522SLong Wu static cmdline_parse_token_string_t cmd_removebonding_member_member =
42615e34522SLong Wu 	TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_member_result,
42715e34522SLong Wu 		member, "member");
42815e34522SLong Wu static cmdline_parse_token_num_t cmd_removebonding_member_memberid =
42915e34522SLong Wu 	TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_member_result,
43015e34522SLong Wu 		member_id, RTE_UINT16);
43115e34522SLong Wu static cmdline_parse_token_num_t cmd_removebonding_member_port =
43215e34522SLong Wu 	TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_member_result,
433703178f8SDavid Marchand 		port_id, RTE_UINT16);
434703178f8SDavid Marchand 
43515e34522SLong Wu static cmdline_parse_inst_t cmd_remove_bonding_member = {
43615e34522SLong Wu 	.f = cmd_remove_bonding_member_parsed,
43715e34522SLong Wu 	.help_str = "remove bonding member <member_id> <port_id>: "
438*4f840086SLong Wu 		"Remove a member device from a bonding device",
439703178f8SDavid Marchand 	.data = NULL,
440703178f8SDavid Marchand 	.tokens = {
44115e34522SLong Wu 		(void *)&cmd_removebonding_member_remove,
44215e34522SLong Wu 		(void *)&cmd_removebonding_member_bonding,
44315e34522SLong Wu 		(void *)&cmd_removebonding_member_member,
44415e34522SLong Wu 		(void *)&cmd_removebonding_member_memberid,
44515e34522SLong Wu 		(void *)&cmd_removebonding_member_port,
446703178f8SDavid Marchand 		NULL
447703178f8SDavid Marchand 	}
448703178f8SDavid Marchand };
449703178f8SDavid Marchand 
450*4f840086SLong Wu /* *** CREATE BONDING DEVICE *** */
451*4f840086SLong Wu struct cmd_create_bonding_device_result {
452703178f8SDavid Marchand 	cmdline_fixed_string_t create;
453*4f840086SLong Wu 	cmdline_fixed_string_t bonding;
454703178f8SDavid Marchand 	cmdline_fixed_string_t device;
455703178f8SDavid Marchand 	uint8_t mode;
456703178f8SDavid Marchand 	uint8_t socket;
457703178f8SDavid Marchand };
458703178f8SDavid Marchand 
459703178f8SDavid Marchand static int bond_dev_num;
460703178f8SDavid Marchand 
cmd_create_bonding_device_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)461*4f840086SLong Wu static void cmd_create_bonding_device_parsed(void *parsed_result,
462703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
463703178f8SDavid Marchand {
464*4f840086SLong Wu 	struct cmd_create_bonding_device_result *res = parsed_result;
465703178f8SDavid Marchand 	char ethdev_name[RTE_ETH_NAME_MAX_LEN];
466703178f8SDavid Marchand 	int port_id;
467703178f8SDavid Marchand 	int ret;
468703178f8SDavid Marchand 
469703178f8SDavid Marchand 	if (test_done == 0) {
470703178f8SDavid Marchand 		fprintf(stderr, "Please stop forwarding first\n");
471703178f8SDavid Marchand 		return;
472703178f8SDavid Marchand 	}
473703178f8SDavid Marchand 
474703178f8SDavid Marchand 	snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d",
475703178f8SDavid Marchand 			bond_dev_num++);
476703178f8SDavid Marchand 
477*4f840086SLong Wu 	/* Create a new bonding device. */
478703178f8SDavid Marchand 	port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket);
479703178f8SDavid Marchand 	if (port_id < 0) {
480*4f840086SLong Wu 		fprintf(stderr, "\t Failed to create bonding device.\n");
481703178f8SDavid Marchand 		return;
482703178f8SDavid Marchand 	}
483*4f840086SLong Wu 	printf("Created new bonding device %s on (port %d).\n", ethdev_name,
484703178f8SDavid Marchand 		port_id);
485703178f8SDavid Marchand 
486703178f8SDavid Marchand 	/* Update number of ports */
487703178f8SDavid Marchand 	nb_ports = rte_eth_dev_count_avail();
488703178f8SDavid Marchand 	reconfig(port_id, res->socket);
489703178f8SDavid Marchand 	ret = rte_eth_promiscuous_enable(port_id);
490703178f8SDavid Marchand 	if (ret != 0)
491703178f8SDavid Marchand 		fprintf(stderr, "Failed to enable promiscuous mode for port %u: %s - ignore\n",
492703178f8SDavid Marchand 			port_id, rte_strerror(-ret));
493703178f8SDavid Marchand 
4947c06f1abSHuisong Li 	ports[port_id].update_conf = 1;
495703178f8SDavid Marchand 	ports[port_id].bond_flag = 1;
496703178f8SDavid Marchand 	ports[port_id].need_setup = 0;
497703178f8SDavid Marchand 	ports[port_id].port_status = RTE_PORT_STOPPED;
498703178f8SDavid Marchand }
499703178f8SDavid Marchand 
500*4f840086SLong Wu static cmdline_parse_token_string_t cmd_createbonding_device_create =
501*4f840086SLong Wu 	TOKEN_STRING_INITIALIZER(struct cmd_create_bonding_device_result,
502703178f8SDavid Marchand 		create, "create");
503*4f840086SLong Wu static cmdline_parse_token_string_t cmd_createbonding_device_bonding =
504*4f840086SLong Wu 	TOKEN_STRING_INITIALIZER(struct cmd_create_bonding_device_result,
505*4f840086SLong Wu 		bonding, "bonding");
506*4f840086SLong Wu static cmdline_parse_token_string_t cmd_createbonding_device_device =
507*4f840086SLong Wu 	TOKEN_STRING_INITIALIZER(struct cmd_create_bonding_device_result,
508703178f8SDavid Marchand 		device, "device");
509*4f840086SLong Wu static cmdline_parse_token_num_t cmd_createbonding_device_mode =
510*4f840086SLong Wu 	TOKEN_NUM_INITIALIZER(struct cmd_create_bonding_device_result,
511703178f8SDavid Marchand 		mode, RTE_UINT8);
512*4f840086SLong Wu static cmdline_parse_token_num_t cmd_createbonding_device_socket =
513*4f840086SLong Wu 	TOKEN_NUM_INITIALIZER(struct cmd_create_bonding_device_result,
514703178f8SDavid Marchand 		socket, RTE_UINT8);
515703178f8SDavid Marchand 
516*4f840086SLong Wu static cmdline_parse_inst_t cmd_create_bonding_device = {
517*4f840086SLong Wu 	.f = cmd_create_bonding_device_parsed,
518*4f840086SLong Wu 	.help_str = "create bonding device <mode> <socket>: "
519*4f840086SLong Wu 		"Create a new bonding device with specific bonding mode and socket",
520703178f8SDavid Marchand 	.data = NULL,
521703178f8SDavid Marchand 	.tokens = {
522*4f840086SLong Wu 		(void *)&cmd_createbonding_device_create,
523*4f840086SLong Wu 		(void *)&cmd_createbonding_device_bonding,
524*4f840086SLong Wu 		(void *)&cmd_createbonding_device_device,
525*4f840086SLong Wu 		(void *)&cmd_createbonding_device_mode,
526*4f840086SLong Wu 		(void *)&cmd_createbonding_device_socket,
527703178f8SDavid Marchand 		NULL
528703178f8SDavid Marchand 	}
529703178f8SDavid Marchand };
530703178f8SDavid Marchand 
531*4f840086SLong Wu /* *** SET MAC ADDRESS IN BONDING DEVICE *** */
532703178f8SDavid Marchand struct cmd_set_bond_mac_addr_result {
533703178f8SDavid Marchand 	cmdline_fixed_string_t set;
534703178f8SDavid Marchand 	cmdline_fixed_string_t bonding;
535703178f8SDavid Marchand 	cmdline_fixed_string_t mac_addr;
536703178f8SDavid Marchand 	uint16_t port_num;
537703178f8SDavid Marchand 	struct rte_ether_addr address;
538703178f8SDavid Marchand };
539703178f8SDavid Marchand 
cmd_set_bond_mac_addr_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)540703178f8SDavid Marchand static void cmd_set_bond_mac_addr_parsed(void *parsed_result,
541703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
542703178f8SDavid Marchand {
543703178f8SDavid Marchand 	struct cmd_set_bond_mac_addr_result *res = parsed_result;
544703178f8SDavid Marchand 	int ret;
545703178f8SDavid Marchand 
546703178f8SDavid Marchand 	if (port_id_is_invalid(res->port_num, ENABLED_WARN))
547703178f8SDavid Marchand 		return;
548703178f8SDavid Marchand 
549703178f8SDavid Marchand 	ret = rte_eth_bond_mac_address_set(res->port_num, &res->address);
550703178f8SDavid Marchand 
551703178f8SDavid Marchand 	/* check the return value and print it if is < 0 */
552703178f8SDavid Marchand 	if (ret < 0)
553703178f8SDavid Marchand 		fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
554703178f8SDavid Marchand 			strerror(-ret));
555703178f8SDavid Marchand }
556703178f8SDavid Marchand 
557703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_set_bond_mac_addr_set =
558703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result,
559703178f8SDavid Marchand 		set, "set");
560703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding =
561703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result,
562703178f8SDavid Marchand 		bonding, "bonding");
563703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac =
564703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result,
565703178f8SDavid Marchand 		mac_addr, "mac_addr");
566703178f8SDavid Marchand static cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum =
567703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result,
568703178f8SDavid Marchand 		port_num, RTE_UINT16);
569703178f8SDavid Marchand static cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr =
570703178f8SDavid Marchand 	TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result,
571703178f8SDavid Marchand 		address);
572703178f8SDavid Marchand 
573703178f8SDavid Marchand static cmdline_parse_inst_t cmd_set_bond_mac_addr = {
574703178f8SDavid Marchand 	.f = cmd_set_bond_mac_addr_parsed,
575703178f8SDavid Marchand 	.data = NULL,
576703178f8SDavid Marchand 	.help_str = "set bonding mac_addr <port_id> <mac_addr>",
577703178f8SDavid Marchand 	.tokens = {
578703178f8SDavid Marchand 		(void *)&cmd_set_bond_mac_addr_set,
579703178f8SDavid Marchand 		(void *)&cmd_set_bond_mac_addr_bonding,
580703178f8SDavid Marchand 		(void *)&cmd_set_bond_mac_addr_mac,
581703178f8SDavid Marchand 		(void *)&cmd_set_bond_mac_addr_portnum,
582703178f8SDavid Marchand 		(void *)&cmd_set_bond_mac_addr_addr,
583703178f8SDavid Marchand 		NULL
584703178f8SDavid Marchand 	}
585703178f8SDavid Marchand };
586703178f8SDavid Marchand 
587*4f840086SLong Wu /* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDING DEVICE *** */
588703178f8SDavid Marchand struct cmd_set_bond_mon_period_result {
589703178f8SDavid Marchand 	cmdline_fixed_string_t set;
590703178f8SDavid Marchand 	cmdline_fixed_string_t bonding;
591703178f8SDavid Marchand 	cmdline_fixed_string_t mon_period;
592703178f8SDavid Marchand 	uint16_t port_num;
593703178f8SDavid Marchand 	uint32_t period_ms;
594703178f8SDavid Marchand };
595703178f8SDavid Marchand 
cmd_set_bond_mon_period_parsed(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)596703178f8SDavid Marchand static void cmd_set_bond_mon_period_parsed(void *parsed_result,
597703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
598703178f8SDavid Marchand {
599703178f8SDavid Marchand 	struct cmd_set_bond_mon_period_result *res = parsed_result;
600703178f8SDavid Marchand 	int ret;
601703178f8SDavid Marchand 
602703178f8SDavid Marchand 	ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms);
603703178f8SDavid Marchand 
604703178f8SDavid Marchand 	/* check the return value and print it if is < 0 */
605703178f8SDavid Marchand 	if (ret < 0)
606703178f8SDavid Marchand 		fprintf(stderr, "set_bond_mac_addr error: (%s)\n",
607703178f8SDavid Marchand 			strerror(-ret));
608703178f8SDavid Marchand }
609703178f8SDavid Marchand 
610703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_set_bond_mon_period_set =
611703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
612703178f8SDavid Marchand 		set, "set");
613703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding =
614703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
615703178f8SDavid Marchand 		bonding, "bonding");
616703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period =
617703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result,
618703178f8SDavid Marchand 		mon_period,	"mon_period");
619703178f8SDavid Marchand static cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum =
620703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
621703178f8SDavid Marchand 		port_num, RTE_UINT16);
622703178f8SDavid Marchand static cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms =
623703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result,
624703178f8SDavid Marchand 		period_ms, RTE_UINT32);
625703178f8SDavid Marchand 
626703178f8SDavid Marchand static cmdline_parse_inst_t cmd_set_bond_mon_period = {
627703178f8SDavid Marchand 	.f = cmd_set_bond_mon_period_parsed,
628703178f8SDavid Marchand 	.data = NULL,
629703178f8SDavid Marchand 	.help_str = "set bonding mon_period <port_id> <period_ms>",
630703178f8SDavid Marchand 	.tokens = {
631703178f8SDavid Marchand 		(void *)&cmd_set_bond_mon_period_set,
632703178f8SDavid Marchand 		(void *)&cmd_set_bond_mon_period_bonding,
633703178f8SDavid Marchand 		(void *)&cmd_set_bond_mon_period_mon_period,
634703178f8SDavid Marchand 		(void *)&cmd_set_bond_mon_period_portnum,
635703178f8SDavid Marchand 		(void *)&cmd_set_bond_mon_period_period_ms,
636703178f8SDavid Marchand 		NULL
637703178f8SDavid Marchand 	}
638703178f8SDavid Marchand };
639703178f8SDavid Marchand 
640703178f8SDavid Marchand struct cmd_set_bonding_agg_mode_policy_result {
641703178f8SDavid Marchand 	cmdline_fixed_string_t set;
642703178f8SDavid Marchand 	cmdline_fixed_string_t bonding;
643703178f8SDavid Marchand 	cmdline_fixed_string_t agg_mode;
644703178f8SDavid Marchand 	uint16_t port_num;
645703178f8SDavid Marchand 	cmdline_fixed_string_t policy;
646703178f8SDavid Marchand };
647703178f8SDavid Marchand 
648703178f8SDavid Marchand static void
cmd_set_bonding_agg_mode(void * parsed_result,__rte_unused struct cmdline * cl,__rte_unused void * data)649703178f8SDavid Marchand cmd_set_bonding_agg_mode(void *parsed_result,
650703178f8SDavid Marchand 	__rte_unused struct cmdline *cl, __rte_unused void *data)
651703178f8SDavid Marchand {
652703178f8SDavid Marchand 	struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result;
653703178f8SDavid Marchand 	uint8_t policy = AGG_BANDWIDTH;
654703178f8SDavid Marchand 
655703178f8SDavid Marchand 	if (!strcmp(res->policy, "bandwidth"))
656703178f8SDavid Marchand 		policy = AGG_BANDWIDTH;
657703178f8SDavid Marchand 	else if (!strcmp(res->policy, "stable"))
658703178f8SDavid Marchand 		policy = AGG_STABLE;
659703178f8SDavid Marchand 	else if (!strcmp(res->policy, "count"))
660703178f8SDavid Marchand 		policy = AGG_COUNT;
661703178f8SDavid Marchand 
662703178f8SDavid Marchand 	rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy);
663703178f8SDavid Marchand }
664703178f8SDavid Marchand 
665703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set =
666703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
667703178f8SDavid Marchand 		set, "set");
668703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding =
669703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
670703178f8SDavid Marchand 		bonding, "bonding");
671703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode =
672703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
673703178f8SDavid Marchand 		agg_mode, "agg_mode");
674703178f8SDavid Marchand static cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum =
675703178f8SDavid Marchand 	TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result,
676703178f8SDavid Marchand 		port_num, RTE_UINT16);
677703178f8SDavid Marchand static cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string =
678703178f8SDavid Marchand 	TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result,
679703178f8SDavid Marchand 		policy, "stable#bandwidth#count");
680703178f8SDavid Marchand 
681703178f8SDavid Marchand static cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = {
682703178f8SDavid Marchand 	.f = cmd_set_bonding_agg_mode,
683703178f8SDavid Marchand 	.data = NULL,
684703178f8SDavid Marchand 	.help_str = "set bonding mode IEEE802.3AD aggregator policy <port_id> <agg_name>",
685703178f8SDavid Marchand 	.tokens = {
686703178f8SDavid Marchand 		(void *)&cmd_set_bonding_agg_mode_set,
687703178f8SDavid Marchand 		(void *)&cmd_set_bonding_agg_mode_bonding,
688703178f8SDavid Marchand 		(void *)&cmd_set_bonding_agg_mode_agg_mode,
689703178f8SDavid Marchand 		(void *)&cmd_set_bonding_agg_mode_portnum,
690703178f8SDavid Marchand 		(void *)&cmd_set_bonding_agg_mode_policy_string,
691703178f8SDavid Marchand 		NULL
692703178f8SDavid Marchand 	}
693703178f8SDavid Marchand };
694703178f8SDavid Marchand 
695703178f8SDavid Marchand static struct testpmd_driver_commands bonding_cmds = {
696703178f8SDavid Marchand 	.commands = {
697703178f8SDavid Marchand 	{
698703178f8SDavid Marchand 		&cmd_set_bonding_mode,
699703178f8SDavid Marchand 		"set bonding mode (value) (port_id)\n"
700*4f840086SLong Wu 		"	Set the bonding mode on a bonding device.\n",
701703178f8SDavid Marchand 	},
702703178f8SDavid Marchand 	{
703703178f8SDavid Marchand 		&cmd_show_bonding_config,
704703178f8SDavid Marchand 		"show bonding config (port_id)\n"
705703178f8SDavid Marchand 		"	Show the bonding config for port_id.\n",
706703178f8SDavid Marchand 	},
707703178f8SDavid Marchand 	{
708703178f8SDavid Marchand 		&cmd_set_bonding_primary,
70915e34522SLong Wu 		"set bonding primary (member_id) (port_id)\n"
710*4f840086SLong Wu 		"	Set the primary member for a bonding device.\n",
711703178f8SDavid Marchand 	},
712703178f8SDavid Marchand 	{
71315e34522SLong Wu 		&cmd_add_bonding_member,
71415e34522SLong Wu 		"add bonding member (member_id) (port_id)\n"
715*4f840086SLong Wu 		"	Add a member device to a bonding device.\n",
716703178f8SDavid Marchand 	},
717703178f8SDavid Marchand 	{
71815e34522SLong Wu 		&cmd_remove_bonding_member,
71915e34522SLong Wu 		"remove bonding member (member_id) (port_id)\n"
720*4f840086SLong Wu 		"	Remove a member device from a bonding device.\n",
721703178f8SDavid Marchand 	},
722703178f8SDavid Marchand 	{
723*4f840086SLong Wu 		&cmd_create_bonding_device,
724*4f840086SLong Wu 		"create bonding device (mode) (socket)\n"
725*4f840086SLong Wu 		"	Create a new bonding device with specific bonding mode and socket.\n",
726703178f8SDavid Marchand 	},
727703178f8SDavid Marchand 	{
728703178f8SDavid Marchand 		&cmd_set_bond_mac_addr,
729703178f8SDavid Marchand 		"set bonding mac_addr (port_id) (address)\n"
730*4f840086SLong Wu 		"	Set the MAC address of a bonding device.\n",
731703178f8SDavid Marchand 	},
732703178f8SDavid Marchand 	{
733703178f8SDavid Marchand 		&cmd_set_balance_xmit_policy,
734703178f8SDavid Marchand 		"set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n"
735*4f840086SLong Wu 		"	Set the transmit balance policy for bonding device running in balance mode.\n",
736703178f8SDavid Marchand 	},
737703178f8SDavid Marchand 	{
738703178f8SDavid Marchand 		&cmd_set_bond_mon_period,
739703178f8SDavid Marchand 		"set bonding mon_period (port_id) (value)\n"
740703178f8SDavid Marchand 		"	Set the bonding link status monitoring polling period in ms.\n",
741703178f8SDavid Marchand 	},
742703178f8SDavid Marchand 	{
743703178f8SDavid Marchand 		&cmd_set_lacp_dedicated_queues,
744703178f8SDavid Marchand 		"set bonding lacp dedicated_queues <port_id> (enable|disable)\n"
745703178f8SDavid Marchand 		"	Enable/disable dedicated queues for LACP control traffic.\n",
746703178f8SDavid Marchand 	},
747703178f8SDavid Marchand 	{
748703178f8SDavid Marchand 		&cmd_set_bonding_agg_mode_policy,
749703178f8SDavid Marchand 		"set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)\n"
750703178f8SDavid Marchand 		"	Set Aggregation mode for IEEE802.3AD (mode 4)\n",
751703178f8SDavid Marchand 	},
752703178f8SDavid Marchand 	{ NULL, NULL },
753703178f8SDavid Marchand 	},
754703178f8SDavid Marchand };
755703178f8SDavid Marchand TESTPMD_ADD_DRIVER_COMMANDS(bonding_cmds)
756