2 *------------------------------------------------------------------
3 * Copyright (c) 2017 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *------------------------------------------------------------------
19 #include <vlib/vlib.h>
20 #include <vlib/unix/unix.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vnet/bonding/node.h>
25 bond_disable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif)
27 bond_main_t *bm = &bond_main;
31 vnet_main_t *vnm = vnet_get_main ();
32 vnet_hw_interface_t *hw;
33 u8 switching_active = 0;
35 bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
36 clib_spinlock_lock_if_init (&bif->lockp);
37 vec_foreach_index (i, bif->active_slaves)
39 p = *vec_elt_at_index (bif->active_slaves, i);
40 if (p == sif->sw_if_index)
42 if (sif->sw_if_index == bif->sw_if_index_working)
45 if (bif->mode == BOND_MODE_ACTIVE_BACKUP)
46 bif->is_local_numa = 0;
48 vec_del1 (bif->active_slaves, i);
49 hash_unset (bif->active_slave_by_sw_if_index, sif->sw_if_index);
50 if (sif->lacp_enabled && bif->numa_only)
52 /* For lacp mode, if we check it is a slave on local numa node,
53 bif->n_numa_slaves should be decreased by 1 becasue the first
54 bif->n_numa_slaves are all slaves on local numa node */
55 if (i < bif->n_numa_slaves)
58 ASSERT (bif->n_numa_slaves >= 0);
65 /* We get a new slave just becoming active */
66 if ((bif->mode == BOND_MODE_ACTIVE_BACKUP) && switching_active)
68 if ((vec_len (bif->active_slaves) >= 1))
70 /* scan all slaves and try to find the first slave with local numa node. */
71 vec_foreach_index (i, bif->active_slaves)
73 p = *vec_elt_at_index (bif->active_slaves, i);
74 hw = vnet_get_sup_hw_interface (vnm, p);
75 if (vm->numa_node == hw->numa_node)
77 bif->sw_if_index_working = p;
78 bif->is_local_numa = 1;
79 vlib_process_signal_event (bm->vlib_main,
80 bond_process_node.index,
88 /* No local numa node is found in the active slave set. Use the first slave */
89 if ((bif->is_local_numa == 0) && (vec_len (bif->active_slaves) >= 1))
91 p = *vec_elt_at_index (bif->active_slaves, 0);
92 bif->sw_if_index_working = p;
93 vlib_process_signal_event (bm->vlib_main, bond_process_node.index,
94 BOND_SEND_GARP_NA, bif->hw_if_index);
97 clib_spinlock_unlock_if_init (&bif->lockp);
103 bond_enable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif)
106 bond_main_t *bm = &bond_main;
107 vnet_main_t *vnm = vnet_get_main ();
108 vnet_hw_interface_t *hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
112 bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
113 clib_spinlock_lock_if_init (&bif->lockp);
114 if (!hash_get (bif->active_slave_by_sw_if_index, sif->sw_if_index))
116 hash_set (bif->active_slave_by_sw_if_index, sif->sw_if_index,
119 if ((sif->lacp_enabled && bif->numa_only)
120 && (vm->numa_node == hw->numa_node))
122 vec_insert_elts (bif->active_slaves, &sif->sw_if_index, 1,
124 bif->n_numa_slaves++;
128 vec_add1 (bif->active_slaves, sif->sw_if_index);
131 /* First slave becomes active? */
132 if ((vec_len (bif->active_slaves) == 1) &&
133 (bif->mode == BOND_MODE_ACTIVE_BACKUP))
135 bif->sw_if_index_working = sif->sw_if_index;
136 bif->is_local_numa = (vm->numa_node == hw->numa_node) ? 1 : 0;
137 vlib_process_signal_event (bm->vlib_main, bond_process_node.index,
138 BOND_SEND_GARP_NA, bif->hw_if_index);
140 else if ((vec_len (bif->active_slaves) > 1)
141 && (bif->mode == BOND_MODE_ACTIVE_BACKUP)
142 && bif->is_local_numa == 0)
144 if (vm->numa_node == hw->numa_node)
146 vec_foreach_index (i, bif->active_slaves)
148 p = *vec_elt_at_index (bif->active_slaves, 0);
149 if (p == sif->sw_if_index)
152 vec_del1 (bif->active_slaves, 0);
153 hash_unset (bif->active_slave_by_sw_if_index, p);
154 vec_add1 (bif->active_slaves, p);
155 hash_set (bif->active_slave_by_sw_if_index, p, p);
157 bif->sw_if_index_working = sif->sw_if_index;
158 bif->is_local_numa = 1;
159 vlib_process_signal_event (bm->vlib_main,
160 bond_process_node.index,
161 BOND_SEND_GARP_NA, bif->hw_if_index);
166 clib_spinlock_unlock_if_init (&bif->lockp);
172 bond_dump_ifs (bond_interface_details_t ** out_bondifs)
174 vnet_main_t *vnm = vnet_get_main ();
175 bond_main_t *bm = &bond_main;
177 vnet_hw_interface_t *hi;
178 bond_interface_details_t *r_bondifs = NULL;
179 bond_interface_details_t *bondif = NULL;
182 pool_foreach (bif, bm->interfaces,
183 vec_add2(r_bondifs, bondif, 1);
184 clib_memset (bondif, 0, sizeof (*bondif));
185 bondif->id = bif->id;
186 bondif->sw_if_index = bif->sw_if_index;
187 hi = vnet_get_hw_interface (vnm, bif->hw_if_index);
188 clib_memcpy(bondif->interface_name, hi->name,
189 MIN (ARRAY_LEN (bondif->interface_name) - 1,
190 strlen ((const char *) hi->name)));
191 bondif->mode = bif->mode;
192 bondif->lb = bif->lb;
193 bondif->numa_only = bif->numa_only;
194 bondif->active_slaves = vec_len (bif->active_slaves);
195 bondif->slaves = vec_len (bif->slaves);
199 *out_bondifs = r_bondifs;
205 bond_dump_slave_ifs (slave_interface_details_t ** out_slaveifs,
206 u32 bond_sw_if_index)
208 vnet_main_t *vnm = vnet_get_main ();
210 vnet_hw_interface_t *hi;
211 vnet_sw_interface_t *sw;
212 slave_interface_details_t *r_slaveifs = NULL;
213 slave_interface_details_t *slaveif = NULL;
214 u32 *sw_if_index = NULL;
217 bif = bond_get_master_by_sw_if_index (bond_sw_if_index);
221 vec_foreach (sw_if_index, bif->slaves)
223 vec_add2 (r_slaveifs, slaveif, 1);
224 clib_memset (slaveif, 0, sizeof (*slaveif));
225 sif = bond_get_slave_by_sw_if_index (*sw_if_index);
228 sw = vnet_get_sw_interface (vnm, sif->sw_if_index);
229 hi = vnet_get_hw_interface (vnm, sw->hw_if_index);
230 clib_memcpy (slaveif->interface_name, hi->name,
231 MIN (ARRAY_LEN (slaveif->interface_name) - 1,
232 strlen ((const char *) hi->name)));
233 slaveif->sw_if_index = sif->sw_if_index;
234 slaveif->is_passive = sif->is_passive;
235 slaveif->is_long_timeout = sif->is_long_timeout;
238 *out_slaveifs = r_slaveifs;
244 bond_delete_neighbor (vlib_main_t * vm, bond_if_t * bif, slave_if_t * sif)
246 bond_main_t *bm = &bond_main;
247 vnet_main_t *vnm = vnet_get_main ();
249 vnet_hw_interface_t *sif_hw;
251 sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
253 bif->port_number_bitmap =
254 clib_bitmap_set (bif->port_number_bitmap,
255 ntohs (sif->actor_admin.port_number) - 1, 0);
256 bm->slave_by_sw_if_index[sif->sw_if_index] = 0;
257 vec_free (sif->last_marker_pkt);
258 vec_free (sif->last_rx_pkt);
259 vec_foreach_index (i, bif->slaves)
261 uword p = *vec_elt_at_index (bif->slaves, i);
262 if (p == sif->sw_if_index)
264 vec_del1 (bif->slaves, i);
269 bond_disable_collecting_distributing (vm, sif);
271 vnet_feature_enable_disable ("device-input", "bond-input",
272 sif_hw->hw_if_index, 0, 0, 0);
274 /* Put back the old mac */
275 vnet_hw_interface_change_mac_address (vnm, sif_hw->hw_if_index,
276 sif->persistent_hw_address);
278 if ((bif->mode == BOND_MODE_LACP) && bm->lacp_enable_disable)
279 (*bm->lacp_enable_disable) (vm, bif, sif, 0);
281 pool_put (bm->neighbors, sif);
285 bond_delete_if (vlib_main_t * vm, u32 sw_if_index)
287 bond_main_t *bm = &bond_main;
288 vnet_main_t *vnm = vnet_get_main ();
291 vnet_hw_interface_t *hw;
292 u32 *sif_sw_if_index;
296 hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
297 if (hw == NULL || bond_dev_class.index != hw->dev_class_index)
298 return VNET_API_ERROR_INVALID_SW_IF_INDEX;
300 bif = bond_get_master_by_dev_instance (hw->dev_instance);
302 vec_foreach (sif_sw_if_index, bif->slaves)
304 vec_add1 (s_list, sif_sw_if_index);
307 for (i = 0; i < vec_len (s_list); i++)
309 sif_sw_if_index = s_list[i];
310 sif = bond_get_slave_by_sw_if_index (*sif_sw_if_index);
312 bond_delete_neighbor (vm, bif, sif);
318 /* bring down the interface */
319 vnet_hw_interface_set_flags (vnm, bif->hw_if_index, 0);
320 vnet_sw_interface_set_flags (vnm, bif->sw_if_index, 0);
322 ethernet_delete_interface (vnm, bif->hw_if_index);
324 clib_bitmap_free (bif->port_number_bitmap);
325 hash_unset (bm->bond_by_sw_if_index, bif->sw_if_index);
326 hash_unset (bm->id_used, bif->id);
327 clib_memset (bif, 0, sizeof (*bif));
328 pool_put (bm->interfaces, bif);
334 bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args)
336 bond_main_t *bm = &bond_main;
337 vnet_main_t *vnm = vnet_get_main ();
338 vnet_sw_interface_t *sw;
341 if ((args->mode == BOND_MODE_LACP) && bm->lacp_plugin_loaded == 0)
343 args->rv = VNET_API_ERROR_FEATURE_DISABLED;
344 args->error = clib_error_return (0, "LACP plugin is not loaded");
347 if (args->mode > BOND_MODE_LACP || args->mode < BOND_MODE_ROUND_ROBIN)
349 args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
350 args->error = clib_error_return (0, "Invalid mode");
353 if (args->lb > BOND_LB_L23)
355 args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
356 args->error = clib_error_return (0, "Invalid load-balance");
359 pool_get (bm->interfaces, bif);
360 clib_memset (bif, 0, sizeof (*bif));
361 bif->dev_instance = bif - bm->interfaces;
364 bif->mode = args->mode;
366 // Adjust requested interface id
368 bif->id = bif->dev_instance;
369 if (hash_get (bm->id_used, bif->id))
371 args->rv = VNET_API_ERROR_INSTANCE_IN_USE;
372 pool_put (bm->interfaces, bif);
375 hash_set (bm->id_used, bif->id, 1);
377 // Special load-balance mode used for rr and bc
378 if (bif->mode == BOND_MODE_ROUND_ROBIN)
379 bif->lb = BOND_LB_RR;
380 else if (bif->mode == BOND_MODE_BROADCAST)
381 bif->lb = BOND_LB_BC;
382 else if (bif->mode == BOND_MODE_ACTIVE_BACKUP)
383 bif->lb = BOND_LB_AB;
385 bif->use_custom_mac = args->hw_addr_set;
386 if (!args->hw_addr_set)
388 f64 now = vlib_time_now (vm);
390 rnd = (u32) (now * 1e6);
391 rnd = random_u32 (&rnd);
393 memcpy (args->hw_addr + 2, &rnd, sizeof (rnd));
394 args->hw_addr[0] = 2;
395 args->hw_addr[1] = 0xfe;
397 memcpy (bif->hw_address, args->hw_addr, 6);
398 args->error = ethernet_register_interface
399 (vnm, bond_dev_class.index, bif->dev_instance /* device instance */ ,
400 bif->hw_address /* ethernet address */ ,
401 &bif->hw_if_index, 0 /* flag change */ );
405 args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
406 hash_unset (bm->id_used, bif->id);
407 pool_put (bm->interfaces, bif);
411 sw = vnet_get_hw_sw_interface (vnm, bif->hw_if_index);
412 bif->sw_if_index = sw->sw_if_index;
413 bif->group = bif->sw_if_index;
414 bif->numa_only = args->numa_only;
415 if (vlib_get_thread_main ()->n_vlib_mains > 1)
416 clib_spinlock_init (&bif->lockp);
418 vnet_hw_interface_set_flags (vnm, bif->hw_if_index,
419 VNET_HW_INTERFACE_FLAG_LINK_UP);
421 hash_set (bm->bond_by_sw_if_index, bif->sw_if_index, bif->dev_instance);
424 args->sw_if_index = bif->sw_if_index;
428 static clib_error_t *
429 bond_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
430 vlib_cli_command_t * cmd)
432 unformat_input_t _line_input, *line_input = &_line_input;
433 bond_create_if_args_t args = { 0 };
436 /* Get a line of input. */
437 if (!unformat_user (input, unformat_line_input, line_input))
438 return clib_error_return (0, "Missing required arguments.");
442 args.lb = BOND_LB_L2;
444 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
446 if (unformat (line_input, "mode %U", unformat_bond_mode, &args.mode))
448 else if (((args.mode == BOND_MODE_LACP) || (args.mode == BOND_MODE_XOR))
449 && unformat (line_input, "load-balance %U",
450 unformat_bond_load_balance, &args.lb))
452 else if (unformat (line_input, "hw-addr %U",
453 unformat_ethernet_address, args.hw_addr))
454 args.hw_addr_set = 1;
455 else if (unformat (line_input, "id %u", &args.id))
457 else if (unformat (line_input, "numa-only"))
459 if (args.mode == BOND_MODE_LACP)
462 return clib_error_return (0,
463 "Only lacp mode supports numa-only so far!");
466 return clib_error_return (0, "unknown input `%U'",
467 format_unformat_error, input);
469 unformat_free (line_input);
471 if (mode_is_set == 0)
472 return clib_error_return (0, "Missing bond mode");
474 bond_create_if (vm, &args);
477 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
478 vnet_get_main (), args.sw_if_index);
484 VLIB_CLI_COMMAND (bond_create_command, static) = {
485 .path = "create bond",
486 .short_help = "create bond mode {round-robin | active-backup | broadcast | "
487 "{lacp | xor} [load-balance { l2 | l23 | l34 } [numa-only]]} [hw-addr <mac-address>] "
489 .function = bond_create_command_fn,
493 static clib_error_t *
494 bond_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
495 vlib_cli_command_t * cmd)
497 unformat_input_t _line_input, *line_input = &_line_input;
498 u32 sw_if_index = ~0;
499 vnet_main_t *vnm = vnet_get_main ();
502 /* Get a line of input. */
503 if (!unformat_user (input, unformat_line_input, line_input))
504 return clib_error_return (0, "Missing <interface>");
506 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
508 if (unformat (line_input, "sw_if_index %d", &sw_if_index))
510 else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
514 return clib_error_return (0, "unknown input `%U'",
515 format_unformat_error, input);
517 unformat_free (line_input);
519 if (sw_if_index == ~0)
520 return clib_error_return (0,
521 "please specify interface name or sw_if_index");
523 rv = bond_delete_if (vm, sw_if_index);
524 if (rv == VNET_API_ERROR_INVALID_SW_IF_INDEX)
525 return clib_error_return (0, "not a bond interface");
527 return clib_error_return (0, "error on deleting bond interface");
533 VLIB_CLI_COMMAND (bond_delete__command, static) =
535 .path = "delete bond",
536 .short_help = "delete bond {<interface> | sw_if_index <sw_idx>}",
537 .function = bond_delete_command_fn,
542 bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args)
544 bond_main_t *bm = &bond_main;
545 vnet_main_t *vnm = vnet_get_main ();
548 vnet_interface_main_t *im = &vnm->interface_main;
549 vnet_hw_interface_t *bif_hw, *sif_hw;
550 vnet_sw_interface_t *sw;
554 bif = bond_get_master_by_sw_if_index (args->group);
557 args->rv = VNET_API_ERROR_INVALID_INTERFACE;
558 args->error = clib_error_return (0, "bond interface not found");
561 // make sure the interface is not already enslaved
562 if (bond_get_slave_by_sw_if_index (args->slave))
564 args->rv = VNET_API_ERROR_VALUE_EXIST;
565 args->error = clib_error_return (0, "interface was already enslaved");
568 sif_hw = vnet_get_sup_hw_interface (vnm, args->slave);
569 if (sif_hw->dev_class_index == bond_dev_class.index)
571 args->rv = VNET_API_ERROR_INVALID_INTERFACE;
573 clib_error_return (0, "bond interface cannot be enslaved");
576 pool_get (bm->neighbors, sif);
577 clib_memset (sif, 0, sizeof (*sif));
578 sw = pool_elt_at_index (im->sw_interfaces, args->slave);
579 /* port_enabled is both admin up and hw link up */
580 sif->port_enabled = vnet_sw_interface_is_up (vnm, sw->sw_if_index);
581 sif->sw_if_index = sw->sw_if_index;
582 sif->hw_if_index = sw->hw_if_index;
583 sif->packet_template_index = (u8) ~ 0;
584 sif->is_passive = args->is_passive;
585 sif->group = args->group;
586 sif->bif_dev_instance = bif->dev_instance;
587 sif->mode = bif->mode;
589 sif->is_long_timeout = args->is_long_timeout;
590 if (args->is_long_timeout)
591 sif->ttl_in_seconds = LACP_LONG_TIMOUT_TIME;
593 sif->ttl_in_seconds = LACP_SHORT_TIMOUT_TIME;
595 vec_validate_aligned (bm->slave_by_sw_if_index, sif->sw_if_index,
596 CLIB_CACHE_LINE_BYTES);
598 * sif - bm->neighbors may be 0
599 * Left shift it by 1 bit to distinguish the valid entry that we actually
600 * store from the null entries
602 bm->slave_by_sw_if_index[sif->sw_if_index] =
603 (uword) (((sif - bm->neighbors) << 1) | 1);
604 vec_add1 (bif->slaves, sif->sw_if_index);
606 sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
608 /* Save the old mac */
609 memcpy (sif->persistent_hw_address, sif_hw->hw_address, 6);
610 bif_hw = vnet_get_sup_hw_interface (vnm, bif->sw_if_index);
611 if (bif->use_custom_mac)
613 vnet_hw_interface_change_mac_address (vnm, sif_hw->hw_if_index,
618 // bond interface gets the mac address from the first slave
619 if (vec_len (bif->slaves) == 1)
621 memcpy (bif->hw_address, sif_hw->hw_address, 6);
622 vnet_hw_interface_change_mac_address (vnm, bif_hw->hw_if_index,
627 // subsequent slaves gets the mac address of the bond interface
628 vnet_hw_interface_change_mac_address (vnm, sif_hw->hw_if_index,
633 if (bif_hw->l2_if_count)
635 ethernet_set_flags (vnm, sif_hw->hw_if_index,
636 ETHERNET_INTERFACE_FLAG_ACCEPT_ALL);
637 /* ensure all packets go to ethernet-input */
638 ethernet_set_rx_redirect (vnm, sif_hw, 1);
641 if (bif->mode == BOND_MODE_LACP)
643 if (bm->lacp_enable_disable)
644 (*bm->lacp_enable_disable) (vm, bif, sif, 1);
646 else if (sif->port_enabled)
648 bond_enable_collecting_distributing (vm, sif);
651 vec_foreach_index (thread_index, bm->per_thread_data)
653 bond_per_thread_data_t *ptd = vec_elt_at_index (bm->per_thread_data,
656 vec_validate_aligned (ptd->per_port_queue, vec_len (bif->slaves) - 1,
657 CLIB_CACHE_LINE_BYTES);
659 vec_foreach_index (sif_if_index, ptd->per_port_queue)
661 ptd->per_port_queue[sif_if_index].n_buffers = 0;
665 args->rv = vnet_feature_enable_disable ("device-input", "bond-input",
666 sif_hw->hw_if_index, 1, 0, 0);
671 clib_error_return (0,
672 "Error encountered on input feature arc enable");
676 static clib_error_t *
677 enslave_interface_command_fn (vlib_main_t * vm, unformat_input_t * input,
678 vlib_cli_command_t * cmd)
680 bond_enslave_args_t args = { 0 };
681 unformat_input_t _line_input, *line_input = &_line_input;
682 vnet_main_t *vnm = vnet_get_main ();
684 /* Get a line of input. */
685 if (!unformat_user (input, unformat_line_input, line_input))
686 return clib_error_return (0, "Missing required arguments.");
690 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
692 if (unformat (line_input, "%U %U",
693 unformat_vnet_sw_interface, vnm, &args.group,
694 unformat_vnet_sw_interface, vnm, &args.slave))
696 else if (unformat (line_input, "passive"))
698 else if (unformat (line_input, "long-timeout"))
699 args.is_long_timeout = 1;
702 args.error = clib_error_return (0, "unknown input `%U'",
703 format_unformat_error, input);
707 unformat_free (line_input);
711 if (args.group == ~0)
712 return clib_error_return (0, "Missing bond interface");
713 if (args.slave == ~0)
714 return clib_error_return (0, "please specify valid slave interface name");
716 bond_enslave (vm, &args);
722 VLIB_CLI_COMMAND (enslave_interface_command, static) = {
724 .short_help = "bond add <BondEthernetx> <slave-interface> "
725 "[passive] [long-timeout]",
726 .function = enslave_interface_command_fn,
731 bond_detach_slave (vlib_main_t * vm, bond_detach_slave_args_t * args)
736 sif = bond_get_slave_by_sw_if_index (args->slave);
739 args->rv = VNET_API_ERROR_INVALID_INTERFACE;
740 args->error = clib_error_return (0, "interface was not enslaved");
743 bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
744 bond_delete_neighbor (vm, bif, sif);
747 static clib_error_t *
748 detach_interface_command_fn (vlib_main_t * vm, unformat_input_t * input,
749 vlib_cli_command_t * cmd)
751 bond_detach_slave_args_t args = { 0 };
752 unformat_input_t _line_input, *line_input = &_line_input;
753 vnet_main_t *vnm = vnet_get_main ();
755 /* Get a line of input. */
756 if (!unformat_user (input, unformat_line_input, line_input))
757 return clib_error_return (0, "Missing required arguments.");
760 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
762 if (unformat (line_input, "%U",
763 unformat_vnet_sw_interface, vnm, &args.slave))
767 args.error = clib_error_return (0, "unknown input `%U'",
768 format_unformat_error, input);
772 unformat_free (line_input);
776 if (args.slave == ~0)
777 return clib_error_return (0, "please specify valid slave interface name");
779 bond_detach_slave (vm, &args);
785 VLIB_CLI_COMMAND (detach_interface_command, static) = {
787 .short_help = "bond del <slave-interface>",
788 .function = detach_interface_command_fn,
793 show_bond (vlib_main_t * vm)
795 bond_main_t *bm = &bond_main;
798 vlib_cli_output (vm, "%-16s %-12s %-13s %-13s %-14s %s",
799 "interface name", "sw_if_index", "mode",
800 "load balance", "active slaves", "slaves");
803 pool_foreach (bif, bm->interfaces,
805 vlib_cli_output (vm, "%-16U %-12d %-13U %-13U %-14u %u",
806 format_bond_interface_name, bif->dev_instance,
807 bif->sw_if_index, format_bond_mode, bif->mode,
808 format_bond_load_balance, bif->lb,
809 vec_len (bif->active_slaves), vec_len (bif->slaves));
815 show_bond_details (vlib_main_t * vm)
817 bond_main_t *bm = &bond_main;
822 pool_foreach (bif, bm->interfaces,
824 vlib_cli_output (vm, "%U", format_bond_interface_name, bif->dev_instance);
825 vlib_cli_output (vm, " mode: %U",
826 format_bond_mode, bif->mode);
827 vlib_cli_output (vm, " load balance: %U",
828 format_bond_load_balance, bif->lb);
829 if (bif->mode == BOND_MODE_ROUND_ROBIN)
830 vlib_cli_output (vm, " last xmit slave index: %u",
831 bif->lb_rr_last_index);
832 vlib_cli_output (vm, " number of active slaves: %d",
833 vec_len (bif->active_slaves));
834 vec_foreach (sw_if_index, bif->active_slaves)
836 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
837 vnet_get_main (), *sw_if_index);
839 vlib_cli_output (vm, " number of slaves: %d", vec_len (bif->slaves));
840 vec_foreach (sw_if_index, bif->slaves)
842 vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
843 vnet_get_main (), *sw_if_index);
845 vlib_cli_output (vm, " device instance: %d", bif->dev_instance);
846 vlib_cli_output (vm, " interface id: %d", bif->id);
847 vlib_cli_output (vm, " sw_if_index: %d", bif->sw_if_index);
848 vlib_cli_output (vm, " hw_if_index: %d", bif->hw_if_index);
853 static clib_error_t *
854 show_bond_fn (vlib_main_t * vm, unformat_input_t * input,
855 vlib_cli_command_t * cmd)
859 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
861 if (unformat (input, "details"))
865 return clib_error_return (0, "unknown input `%U'",
866 format_unformat_error, input);
871 show_bond_details (vm);
879 VLIB_CLI_COMMAND (show_bond_command, static) = {
881 .short_help = "show bond [details]",
882 .function = show_bond_fn,
887 bond_cli_init (vlib_main_t * vm)
889 bond_main_t *bm = &bond_main;
892 bm->vnet_main = vnet_get_main ();
893 vec_validate_aligned (bm->slave_by_sw_if_index, 1, CLIB_CACHE_LINE_BYTES);
894 vec_validate_aligned (bm->per_thread_data,
895 vlib_get_thread_main ()->n_vlib_mains - 1,
896 CLIB_CACHE_LINE_BYTES);
901 VLIB_INIT_FUNCTION (bond_cli_init);
904 * fd.io coding-style-patch-verification: ON
907 * eval: (c-set-style "gnu")