2 * Copyright (c) 2017 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
17 #include <vnet/bonding/node.h>
18 #include <lacp/node.h>
21 lacp_dump_ifs (lacp_interface_details_t ** out_lacpifs)
23 vnet_main_t *vnm = vnet_get_main ();
24 bond_main_t *bm = &bond_main;
27 vnet_hw_interface_t *hi;
28 lacp_interface_details_t *r_lacpifs = NULL;
29 lacp_interface_details_t *lacpif = NULL;
32 pool_foreach (sif, bm->neighbors,
33 if ((sif->port_enabled == 0) || (sif->lacp_enabled == 0))
35 vec_add2(r_lacpifs, lacpif, 1);
36 memset (lacpif, 0, sizeof (*lacpif));
37 lacpif->sw_if_index = sif->sw_if_index;
38 hi = vnet_get_hw_interface (vnm, sif->hw_if_index);
39 clib_memcpy(lacpif->interface_name, hi->name,
40 MIN (ARRAY_LEN (lacpif->interface_name) - 1,
41 strlen ((const char *) hi->name)));
42 bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
43 hi = vnet_get_hw_interface (vnm, bif->hw_if_index);
44 clib_memcpy(lacpif->bond_interface_name, hi->name,
45 MIN (ARRAY_LEN (lacpif->bond_interface_name) - 1,
46 strlen ((const char *) hi->name)));
47 clib_memcpy (lacpif->actor_system, sif->actor.system, 6);
48 lacpif->actor_system_priority = sif->actor.system_priority;
49 lacpif->actor_key = sif->actor.key;
50 lacpif->actor_port_priority = sif->actor.port_priority;
51 lacpif->actor_port_number = sif->actor.port_number;
52 lacpif->actor_state = sif->actor.state;
53 clib_memcpy (lacpif->partner_system, sif->partner.system, 6);
54 lacpif->partner_system_priority = sif->partner.system_priority;
55 lacpif->partner_key = sif->partner.key;
56 lacpif->partner_port_priority = sif->partner.port_priority;
57 lacpif->partner_port_number = sif->partner.port_number;
58 lacpif->partner_state = sif->partner.state;
59 lacpif->rx_state = sif->rx_state;
60 lacpif->tx_state = sif->tx_state;
61 lacpif->ptx_state = sif->ptx_state;
62 lacpif->mux_state = sif->mux_state;
66 *out_lacpifs = r_lacpifs;
72 show_lacp (vlib_main_t * vm, u32 * sw_if_indices)
81 vlib_cli_output (vm, "%-55s %-32s %-32s", " ", "actor state",
83 vlib_cli_output (vm, "%-25s %-12s %-16s %-31s %-31s", "interface name",
84 "sw_if_index", "bond interface",
85 "exp/def/dis/col/syn/agg/tim/act",
86 "exp/def/dis/col/syn/agg/tim/act");
88 for (i = 0; i < vec_len (sw_if_indices); i++)
90 sif = bond_get_slave_by_sw_if_index (sw_if_indices[i]);
91 if (!sif || (sif->port_enabled == 0) || (sif->lacp_enabled == 0))
93 bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
95 "%-25U %-12d %-16U %3x %3x %3x %3x %3x %3x %3x %3x "
96 "%4x %3x %3x %3x %3x %3x %3x %3x",
97 format_vnet_sw_if_index_name, vnet_get_main (),
98 sif->sw_if_index, sif->sw_if_index,
99 format_vnet_sw_if_index_name, vnet_get_main (),
100 bif->sw_if_index, lacp_bit_test (sif->actor.state, 7),
101 lacp_bit_test (sif->actor.state, 6),
102 lacp_bit_test (sif->actor.state, 5),
103 lacp_bit_test (sif->actor.state, 4),
104 lacp_bit_test (sif->actor.state, 3),
105 lacp_bit_test (sif->actor.state, 2),
106 lacp_bit_test (sif->actor.state, 1),
107 lacp_bit_test (sif->actor.state, 0),
108 lacp_bit_test (sif->partner.state, 7),
109 lacp_bit_test (sif->partner.state, 6),
110 lacp_bit_test (sif->partner.state, 5),
111 lacp_bit_test (sif->partner.state, 4),
112 lacp_bit_test (sif->partner.state, 3),
113 lacp_bit_test (sif->partner.state, 2),
114 lacp_bit_test (sif->partner.state, 1),
115 lacp_bit_test (sif->partner.state, 0));
118 "[(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x), "
119 "(%04x,%02x-%02x-%02x-%02x-%02x-%02x,%04x,%04x,%04x)]",
120 ntohs (sif->actor.system_priority),
121 sif->actor.system[0], sif->actor.system[1],
122 sif->actor.system[2], sif->actor.system[3],
123 sif->actor.system[4], sif->actor.system[5],
124 ntohs (sif->actor.key),
125 ntohs (sif->actor.port_priority),
126 ntohs (sif->actor.port_number),
127 ntohs (sif->partner.system_priority),
128 sif->partner.system[0], sif->partner.system[1],
129 sif->partner.system[2], sif->partner.system[3],
130 sif->partner.system[4], sif->partner.system[5],
131 ntohs (sif->partner.key),
132 ntohs (sif->partner.port_priority),
133 ntohs (sif->partner.port_number));
135 " RX-state: %U, TX-state: %U, "
136 "MUX-state: %U, PTX-state: %U",
137 format_rx_sm_state, sif->rx_state, format_tx_sm_state,
138 sif->tx_state, format_mux_sm_state, sif->mux_state,
139 format_ptx_sm_state, sif->ptx_state);
144 show_lacp_details (vlib_main_t * vm, u32 * sw_if_indices)
147 lacp_state_struct *state_entry;
154 now = vlib_time_now (vm);
155 for (i = 0; i < vec_len (sw_if_indices); i++)
157 sif = bond_get_slave_by_sw_if_index (sw_if_indices[i]);
158 if (!sif || (sif->port_enabled == 0) || (sif->lacp_enabled == 0))
160 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
161 vnet_get_main (), sif->sw_if_index);
162 vlib_cli_output (vm, " debug: %d", sif->debug);
163 vlib_cli_output (vm, " loopback port: %d", sif->loopback_port);
164 vlib_cli_output (vm, " port moved: %d", sif->port_moved);
165 vlib_cli_output (vm, " ready_n: %d", sif->ready_n);
166 vlib_cli_output (vm, " ready: %d", sif->ready);
167 vlib_cli_output (vm, " Actor");
168 vlib_cli_output (vm, " system: %U",
169 format_ethernet_address, sif->actor.system);
170 vlib_cli_output (vm, " system priority: %u",
171 ntohs (sif->actor.system_priority));
172 vlib_cli_output (vm, " key: %u", ntohs (sif->actor.key));
173 vlib_cli_output (vm, " port priority: %u",
174 ntohs (sif->actor.port_priority));
175 vlib_cli_output (vm, " port number: %u",
176 ntohs (sif->actor.port_number));
177 vlib_cli_output (vm, " state: 0x%x", sif->actor.state);
179 state_entry = (lacp_state_struct *) & lacp_state_array;
180 while (state_entry->str)
182 if (sif->actor.state & (1 << state_entry->bit))
183 vlib_cli_output (vm, " %s (%d)", state_entry->str,
188 vlib_cli_output (vm, " Partner");
189 vlib_cli_output (vm, " system: %U",
190 format_ethernet_address, sif->partner.system);
191 vlib_cli_output (vm, " system priority: %u",
192 ntohs (sif->partner.system_priority));
193 vlib_cli_output (vm, " key: %u", ntohs (sif->partner.key));
194 vlib_cli_output (vm, " port priority: %u",
195 ntohs (sif->partner.port_priority));
196 vlib_cli_output (vm, " port number: %u",
197 ntohs (sif->partner.port_number));
198 vlib_cli_output (vm, " state: 0x%x", sif->partner.state);
200 state_entry = (lacp_state_struct *) & lacp_state_array;
201 while (state_entry->str)
203 if (sif->partner.state & (1 << state_entry->bit))
204 vlib_cli_output (vm, " %s (%d)", state_entry->str,
209 if (!lacp_timer_is_running (sif->wait_while_timer))
210 vlib_cli_output (vm, " wait while timer: not running");
212 vlib_cli_output (vm, " wait while timer: %=10.2f seconds",
213 sif->wait_while_timer - now);
214 if (!lacp_timer_is_running (sif->current_while_timer))
215 vlib_cli_output (vm, " current while timer: not running");
217 vlib_cli_output (vm, " current while timer: %=10.2f seconds",
218 sif->current_while_timer - now);
219 if (!lacp_timer_is_running (sif->periodic_timer))
220 vlib_cli_output (vm, " periodic timer: not running");
222 vlib_cli_output (vm, " periodic timer: %=10.2f seconds",
223 sif->periodic_timer - now);
224 vlib_cli_output (vm, " RX-state: %U", format_rx_sm_state,
226 vlib_cli_output (vm, " TX-state: %U", format_tx_sm_state,
228 vlib_cli_output (vm, " MUX-state: %U", format_mux_sm_state,
230 vlib_cli_output (vm, " PTX-state: %U", format_ptx_sm_state,
232 vlib_cli_output (vm, "\n");
236 static clib_error_t *
237 show_lacp_fn (vlib_main_t * vm, unformat_input_t * input,
238 vlib_cli_command_t * cmd)
240 bond_main_t *bm = &bond_main;
241 vnet_main_t *vnm = &vnet_main;
243 clib_error_t *error = 0;
245 u32 hw_if_index, *sw_if_indices = 0;
246 vnet_interface_main_t *im = &vnm->interface_main;
247 vnet_sw_interface_t *sw;
249 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
252 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
254 sw = pool_elt_at_index (im->sw_interfaces, hw_if_index);
255 sif = bond_get_slave_by_sw_if_index (sw->sw_if_index);
258 error = clib_error_return (0, "interface is not enslaved");
261 vec_add1 (sw_if_indices, sif->sw_if_index);
263 else if (unformat (input, "details"))
267 error = clib_error_return (0, "unknown input `%U'",
268 format_unformat_error, input);
273 if (vec_len (sw_if_indices) == 0)
275 pool_foreach (sif, bm->neighbors,
276 vec_add1 (sw_if_indices, sif->sw_if_index);
281 show_lacp_details (vm, sw_if_indices);
283 show_lacp (vm, sw_if_indices);
286 vec_free (sw_if_indices);
291 VLIB_CLI_COMMAND (show_lacp_command, static) = {
293 .short_help = "show lacp [<interface>] [details]",
294 .function = show_lacp_fn,
298 static clib_error_t *
299 debug_lacp_command_fn (vlib_main_t * vm, unformat_input_t * input,
300 vlib_cli_command_t * cmd)
302 unformat_input_t _line_input, *line_input = &_line_input;
303 clib_error_t *error = NULL;
304 lacp_main_t *lm = &lacp_main;
307 u32 hw_if_index = ~0;
309 vnet_main_t *vnm = vnet_get_main ();
310 vnet_interface_main_t *im = &vnm->interface_main;
311 vnet_sw_interface_t *sw;
313 /* Get a line of input. */
314 if (!unformat_user (input, unformat_line_input, line_input))
315 return clib_error_return (0, "missing argument");
317 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
319 if (unformat (line_input, "%U",
320 unformat_vnet_hw_interface, vnm, &hw_if_index))
324 error = clib_error_return (0, "unknown input `%U'",
325 format_unformat_error, line_input);
328 else if (unformat (line_input, "on"))
333 else if (unformat (line_input, "off"))
340 error = clib_error_return (0, "unknown input `%U'",
341 format_unformat_error, line_input);
347 return clib_error_return (0, "must specify on or off");
349 if (hw_if_index != ~0)
351 sw = pool_elt_at_index (im->sw_interfaces, hw_if_index);
352 sif = bond_get_slave_by_sw_if_index (sw->sw_if_index);
354 return (clib_error_return (0, "Please enslave the interface first"));
361 unformat_free (line_input);
367 VLIB_CLI_COMMAND (debug_lacp_command, static) = {
368 .path = "debug lacp",
369 .short_help = "debug lacp <interface> <on | off>",
370 .function = debug_lacp_command_fn,
375 lacp_cli_init (vlib_main_t * vm)
377 lacp_main_t *lm = &lacp_main;
380 lm->vnet_main = vnet_get_main ();
385 VLIB_INIT_FUNCTION (lacp_cli_init);
388 * fd.io coding-style-patch-verification: ON
391 * eval: (c-set-style "gnu")