bond: cli rename
[vpp.git] / src / vnet / bonding / cli.c
1 /*
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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  *------------------------------------------------------------------
16  */
17
18 #include <stdint.h>
19 #include <vlib/vlib.h>
20 #include <vlib/unix/unix.h>
21 #include <vnet/ethernet/ethernet.h>
22 #include <vnet/bonding/node.h>
23
24 void
25 bond_disable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif)
26 {
27   bond_if_t *bif;
28   int i;
29   uword p;
30
31   bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
32   clib_spinlock_lock_if_init (&bif->lockp);
33   vec_foreach_index (i, bif->active_slaves)
34   {
35     p = *vec_elt_at_index (bif->active_slaves, i);
36     if (p == sif->sw_if_index)
37       {
38         vec_del1 (bif->active_slaves, i);
39         hash_unset (bif->active_slave_by_sw_if_index, sif->sw_if_index);
40         break;
41       }
42   }
43   clib_spinlock_unlock_if_init (&bif->lockp);
44 }
45
46 void
47 bond_enable_collecting_distributing (vlib_main_t * vm, slave_if_t * sif)
48 {
49   bond_if_t *bif;
50
51   bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
52   clib_spinlock_lock_if_init (&bif->lockp);
53   if (!hash_get (bif->active_slave_by_sw_if_index, sif->sw_if_index))
54     {
55       hash_set (bif->active_slave_by_sw_if_index, sif->sw_if_index,
56                 sif->sw_if_index);
57       vec_add1 (bif->active_slaves, sif->sw_if_index);
58     }
59   clib_spinlock_unlock_if_init (&bif->lockp);
60 }
61
62 int
63 bond_dump_ifs (bond_interface_details_t ** out_bondifs)
64 {
65   vnet_main_t *vnm = vnet_get_main ();
66   bond_main_t *bm = &bond_main;
67   bond_if_t *bif;
68   vnet_hw_interface_t *hi;
69   bond_interface_details_t *r_bondifs = NULL;
70   bond_interface_details_t *bondif = NULL;
71
72   /* *INDENT-OFF* */
73   pool_foreach (bif, bm->interfaces,
74     vec_add2(r_bondifs, bondif, 1);
75     memset (bondif, 0, sizeof (*bondif));
76     bondif->sw_if_index = bif->sw_if_index;
77     hi = vnet_get_hw_interface (vnm, bif->hw_if_index);
78     clib_memcpy(bondif->interface_name, hi->name,
79                 MIN (ARRAY_LEN (bondif->interface_name) - 1,
80                      strlen ((const char *) hi->name)));
81     bondif->mode = bif->mode;
82     bondif->lb = bif->lb;
83     bondif->active_slaves = vec_len (bif->active_slaves);
84     bondif->slaves = vec_len (bif->slaves);
85   );
86   /* *INDENT-ON* */
87
88   *out_bondifs = r_bondifs;
89
90   return 0;
91 }
92
93 int
94 bond_dump_slave_ifs (slave_interface_details_t ** out_slaveifs,
95                      u32 bond_sw_if_index)
96 {
97   vnet_main_t *vnm = vnet_get_main ();
98   bond_if_t *bif;
99   vnet_hw_interface_t *hi;
100   vnet_sw_interface_t *sw;
101   slave_interface_details_t *r_slaveifs = NULL;
102   slave_interface_details_t *slaveif = NULL;
103   u32 *sw_if_index = NULL;
104   slave_if_t *sif;
105
106   bif = bond_get_master_by_sw_if_index (bond_sw_if_index);
107   if (!bif)
108     return 1;
109
110   vec_foreach (sw_if_index, bif->slaves)
111   {
112     vec_add2 (r_slaveifs, slaveif, 1);
113     memset (slaveif, 0, sizeof (*slaveif));
114     sif = bond_get_slave_by_sw_if_index (*sw_if_index);
115     if (sif)
116       {
117         sw = vnet_get_sw_interface (vnm, sif->sw_if_index);
118         hi = vnet_get_hw_interface (vnm, sw->hw_if_index);
119         clib_memcpy (slaveif->interface_name, hi->name,
120                      MIN (ARRAY_LEN (slaveif->interface_name) - 1,
121                           strlen ((const char *) hi->name)));
122         slaveif->sw_if_index = sif->sw_if_index;
123         slaveif->is_passive = sif->is_passive;
124         slaveif->is_long_timeout = sif->is_long_timeout;
125       }
126   }
127   *out_slaveifs = r_slaveifs;
128
129   return 0;
130 }
131
132 static void
133 bond_delete_neighbor (vlib_main_t * vm, bond_if_t * bif, slave_if_t * sif)
134 {
135   bond_main_t *bm = &bond_main;
136   vnet_main_t *vnm = vnet_get_main ();
137   int i;
138   vnet_hw_interface_t *hw;
139
140   bif->port_number_bitmap =
141     clib_bitmap_set (bif->port_number_bitmap,
142                      ntohs (sif->actor_admin.port_number) - 1, 0);
143   hash_unset (bm->neighbor_by_sw_if_index, sif->sw_if_index);
144   vec_free (sif->last_marker_pkt);
145   vec_free (sif->last_rx_pkt);
146   vec_foreach_index (i, bif->slaves)
147   {
148     uword p = *vec_elt_at_index (bif->slaves, i);
149     if (p == sif->sw_if_index)
150       {
151         vec_del1 (bif->slaves, i);
152         break;
153       }
154   }
155
156   bond_disable_collecting_distributing (vm, sif);
157
158   /* Put back the old mac */
159   hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
160   vnet_hw_interface_change_mac_address (vnm, hw->hw_if_index,
161                                         sif->persistent_hw_address);
162
163   pool_put (bm->neighbors, sif);
164
165   if ((bif->mode == BOND_MODE_LACP) && bm->lacp_enable_disable)
166     (*bm->lacp_enable_disable) (vm, bif, sif, 0);
167 }
168
169 int
170 bond_delete_if (vlib_main_t * vm, u32 sw_if_index)
171 {
172   bond_main_t *bm = &bond_main;
173   vnet_main_t *vnm = vnet_get_main ();
174   bond_if_t *bif;
175   slave_if_t *sif;
176   vnet_hw_interface_t *hw;
177   u32 *sif_sw_if_index;
178   u32 thread_index;
179
180   hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
181   if (hw == NULL || bond_dev_class.index != hw->dev_class_index)
182     return VNET_API_ERROR_INVALID_SW_IF_INDEX;
183
184   bif = bond_get_master_by_dev_instance (hw->dev_instance);
185
186   vec_foreach (sif_sw_if_index, bif->slaves)
187   {
188     sif = bond_get_slave_by_sw_if_index (*sif_sw_if_index);
189     if (sif)
190       bond_delete_neighbor (vm, bif, sif);
191   }
192
193   /* bring down the interface */
194   vnet_hw_interface_set_flags (vnm, bif->hw_if_index, 0);
195   vnet_sw_interface_set_flags (vnm, bif->sw_if_index, 0);
196
197   ethernet_delete_interface (vnm, bif->hw_if_index);
198
199   clib_bitmap_free (bif->port_number_bitmap);
200   hash_unset (bm->bond_by_sw_if_index, bif->sw_if_index);
201   for (thread_index = 0; thread_index < vlib_get_thread_main ()->n_vlib_mains;
202        thread_index++)
203     {
204       vec_free (bif->per_thread_info[thread_index].frame);
205     }
206   vec_free (bif->per_thread_info);
207   memset (bif, 0, sizeof (*bif));
208   pool_put (bm->interfaces, bif);
209
210   return 0;
211 }
212
213 void
214 bond_create_if (vlib_main_t * vm, bond_create_if_args_t * args)
215 {
216   bond_main_t *bm = &bond_main;
217   vnet_main_t *vnm = vnet_get_main ();
218   vnet_sw_interface_t *sw;
219   bond_if_t *bif;
220
221   if ((args->mode == BOND_MODE_LACP) && bm->lacp_plugin_loaded == 0)
222     {
223       args->rv = VNET_API_ERROR_FEATURE_DISABLED;
224       args->error = clib_error_return (0, "LACP plugin is not loaded");
225       return;
226     }
227   if (args->mode > BOND_MODE_LACP || args->mode < BOND_MODE_ROUND_ROBIN)
228     {
229       args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
230       args->error = clib_error_return (0, "Invalid mode");
231       return;
232     }
233   if (args->lb > BOND_LB_L23)
234     {
235       args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
236       args->error = clib_error_return (0, "Invalid load-balance");
237       return;
238     }
239   pool_get (bm->interfaces, bif);
240   memset (bif, 0, sizeof (*bif));
241   bif->dev_instance = bif - bm->interfaces;
242   bif->lb = args->lb;
243   bif->mode = args->mode;
244
245   // Special load-balance mode used for rr and bc
246   if (bif->mode == BOND_MODE_ROUND_ROBIN)
247     bif->lb = BOND_LB_RR;
248   else if (bif->mode == BOND_MODE_BROADCAST)
249     bif->lb = BOND_LB_BC;
250
251   bif->use_custom_mac = args->hw_addr_set;
252   if (!args->hw_addr_set)
253     {
254       f64 now = vlib_time_now (vm);
255       u32 rnd;
256       rnd = (u32) (now * 1e6);
257       rnd = random_u32 (&rnd);
258
259       memcpy (args->hw_addr + 2, &rnd, sizeof (rnd));
260       args->hw_addr[0] = 2;
261       args->hw_addr[1] = 0xfe;
262     }
263   memcpy (bif->hw_address, args->hw_addr, 6);
264   args->error = ethernet_register_interface
265     (vnm, bond_dev_class.index, bif - bm->interfaces /* device instance */ ,
266      bif->hw_address /* ethernet address */ ,
267      &bif->hw_if_index, 0 /* flag change */ );
268
269   if (args->error)
270     {
271       args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
272       pool_put (bm->interfaces, bif);
273       return;
274     }
275
276   sw = vnet_get_hw_sw_interface (vnm, bif->hw_if_index);
277   bif->sw_if_index = sw->sw_if_index;
278   bif->group = bif->sw_if_index;
279   vec_validate_aligned (bif->per_thread_info,
280                         vlib_get_thread_main ()->n_vlib_mains - 1,
281                         CLIB_CACHE_LINE_BYTES);
282   if (vlib_get_thread_main ()->n_vlib_mains > 1)
283     clib_spinlock_init (&bif->lockp);
284
285   vnet_hw_interface_set_flags (vnm, bif->hw_if_index,
286                                VNET_HW_INTERFACE_FLAG_LINK_UP);
287
288   hash_set (bm->bond_by_sw_if_index, bif->sw_if_index, bif->dev_instance);
289
290   // for return
291   args->sw_if_index = bif->sw_if_index;
292 }
293
294 static clib_error_t *
295 bond_create_command_fn (vlib_main_t * vm, unformat_input_t * input,
296                         vlib_cli_command_t * cmd)
297 {
298   unformat_input_t _line_input, *line_input = &_line_input;
299   bond_create_if_args_t args = { 0 };
300   u8 mode_is_set = 0;
301
302   /* Get a line of input. */
303   if (!unformat_user (input, unformat_line_input, line_input))
304     return clib_error_return (0, "Missing required arguments.");
305
306   args.mode = -1;
307   args.lb = BOND_LB_L2;
308   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
309     {
310       if (unformat (line_input, "mode %U", unformat_bond_mode, &args.mode))
311         mode_is_set = 1;
312       else if (((args.mode == BOND_MODE_LACP) || (args.mode == BOND_MODE_XOR))
313                && unformat (line_input, "load-balance %U",
314                             unformat_bond_load_balance, &args.lb))
315         ;
316       else if (unformat (line_input, "hw-addr %U",
317                          unformat_ethernet_address, args.hw_addr))
318         args.hw_addr_set = 1;
319       else
320         return clib_error_return (0, "unknown input `%U'",
321                                   format_unformat_error, input);
322     }
323   unformat_free (line_input);
324
325   if (mode_is_set == 0)
326     return clib_error_return (0, "Missing bond mode");
327
328   bond_create_if (vm, &args);
329
330   return args.error;
331 }
332
333 /* *INDENT-OFF* */
334 VLIB_CLI_COMMAND (bond_create_command, static) = {
335   .path = "create bond",
336   .short_help = "create bond mode {round-robin | active-backup | broadcast | "
337     "{lacp | xor} [load-balance { l2 | l23 | l34 }]} [hw-addr <mac-address>]",
338   .function = bond_create_command_fn,
339 };
340 /* *INDENT-ON* */
341
342 static clib_error_t *
343 bond_delete_command_fn (vlib_main_t * vm, unformat_input_t * input,
344                         vlib_cli_command_t * cmd)
345 {
346   unformat_input_t _line_input, *line_input = &_line_input;
347   u32 sw_if_index = ~0;
348   vnet_main_t *vnm = vnet_get_main ();
349   int rv;
350
351   /* Get a line of input. */
352   if (!unformat_user (input, unformat_line_input, line_input))
353     return clib_error_return (0, "Missing <interface>");
354
355   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
356     {
357       if (unformat (line_input, "sw_if_index %d", &sw_if_index))
358         ;
359       else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
360                          vnm, &sw_if_index))
361         ;
362       else
363         return clib_error_return (0, "unknown input `%U'",
364                                   format_unformat_error, input);
365     }
366   unformat_free (line_input);
367
368   if (sw_if_index == ~0)
369     return clib_error_return (0,
370                               "please specify interface name or sw_if_index");
371
372   rv = bond_delete_if (vm, sw_if_index);
373   if (rv == VNET_API_ERROR_INVALID_SW_IF_INDEX)
374     return clib_error_return (0, "not a bond interface");
375   else if (rv != 0)
376     return clib_error_return (0, "error on deleting bond interface");
377
378   return 0;
379 }
380
381 /* *INDENT-OFF* */
382 VLIB_CLI_COMMAND (bond_delete__command, static) =
383 {
384   .path = "delete bond",
385   .short_help = "delete bond {<interface> | sw_if_index <sw_idx>}",
386   .function = bond_delete_command_fn,
387 };
388 /* *INDENT-ON* */
389
390 void
391 bond_enslave (vlib_main_t * vm, bond_enslave_args_t * args)
392 {
393   bond_main_t *bm = &bond_main;
394   vnet_main_t *vnm = vnet_get_main ();
395   bond_if_t *bif;
396   slave_if_t *sif;
397   vnet_interface_main_t *im = &vnm->interface_main;
398   vnet_hw_interface_t *hw, *hw2;
399   vnet_sw_interface_t *sw;
400
401   bif = bond_get_master_by_sw_if_index (args->group);
402   if (!bif)
403     {
404       args->rv = VNET_API_ERROR_INVALID_INTERFACE;
405       args->error = clib_error_return (0, "bond interface not found");
406       return;
407     }
408   // make sure the interface is not already enslaved
409   if (bond_get_slave_by_sw_if_index (args->slave))
410     {
411       args->rv = VNET_API_ERROR_VALUE_EXIST;
412       args->error = clib_error_return (0, "interface was already enslaved");
413       return;
414     }
415   hw = vnet_get_sup_hw_interface (vnm, args->slave);
416   if (hw->dev_class_index == bond_dev_class.index)
417     {
418       args->rv = VNET_API_ERROR_INVALID_INTERFACE;
419       args->error =
420         clib_error_return (0, "bond interface cannot be enslaved");
421       return;
422     }
423   pool_get (bm->neighbors, sif);
424   memset (sif, 0, sizeof (*sif));
425   clib_spinlock_init (&sif->lockp);
426   sw = pool_elt_at_index (im->sw_interfaces, args->slave);
427   sif->port_enabled = sw->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP;
428   sif->sw_if_index = sw->sw_if_index;
429   sif->hw_if_index = sw->hw_if_index;
430   sif->packet_template_index = (u8) ~ 0;
431   sif->is_passive = args->is_passive;
432   sif->group = args->group;
433   sif->bif_dev_instance = bif->dev_instance;
434   sif->mode = bif->mode;
435
436   sif->is_long_timeout = args->is_long_timeout;
437   if (args->is_long_timeout)
438     sif->ttl_in_seconds = LACP_LONG_TIMOUT_TIME;
439   else
440     sif->ttl_in_seconds = LACP_SHORT_TIMOUT_TIME;
441
442   hash_set (bm->neighbor_by_sw_if_index, sif->sw_if_index,
443             sif - bm->neighbors);
444   vec_add1 (bif->slaves, sif->sw_if_index);
445
446   hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
447   /* Save the old mac */
448   memcpy (sif->persistent_hw_address, hw->hw_address, 6);
449   if (bif->use_custom_mac)
450     {
451       vnet_hw_interface_change_mac_address (vnm, hw->hw_if_index,
452                                             bif->hw_address);
453     }
454   else
455     {
456       // bond interface gets the mac address from the first slave
457       if (vec_len (bif->slaves) == 1)
458         {
459           memcpy (bif->hw_address, hw->hw_address, 6);
460           hw2 = vnet_get_sup_hw_interface (vnm, bif->sw_if_index);
461           vnet_hw_interface_change_mac_address (vnm, hw2->hw_if_index,
462                                                 hw->hw_address);
463         }
464       else
465         {
466           // subsequent slaves gets the mac address of the bond interface
467           vnet_hw_interface_change_mac_address (vnm, hw->hw_if_index,
468                                                 bif->hw_address);
469         }
470     }
471
472   if ((bif->mode == BOND_MODE_LACP) && bm->lacp_enable_disable)
473     {
474       (*bm->lacp_enable_disable) (vm, bif, sif, 1);
475     }
476   else
477     {
478       bond_enable_collecting_distributing (vm, sif);
479     }
480
481   args->rv = vnet_feature_enable_disable ("device-input", "bond-input",
482                                           hw->hw_if_index, 1, 0, 0);
483
484   if (args->rv)
485     {
486       args->error =
487         clib_error_return (0,
488                            "Error encountered on input feature arc enable");
489     }
490 }
491
492 static clib_error_t *
493 enslave_interface_command_fn (vlib_main_t * vm, unformat_input_t * input,
494                               vlib_cli_command_t * cmd)
495 {
496   bond_enslave_args_t args = { 0 };
497   unformat_input_t _line_input, *line_input = &_line_input;
498   vnet_main_t *vnm = vnet_get_main ();
499
500   /* Get a line of input. */
501   if (!unformat_user (input, unformat_line_input, line_input))
502     return clib_error_return (0, "Missing required arguments.");
503
504   args.slave = ~0;
505   args.group = ~0;
506   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
507     {
508       if (unformat (line_input, "%U %U",
509                     unformat_vnet_sw_interface, vnm, &args.group,
510                     unformat_vnet_sw_interface, vnm, &args.slave))
511         ;
512       else if (unformat (line_input, "passive"))
513         args.is_passive = 1;
514       else if (unformat (line_input, "long-timeout"))
515         args.is_long_timeout = 1;
516       else
517         {
518           args.error = clib_error_return (0, "unknown input `%U'",
519                                           format_unformat_error, input);
520           break;
521         }
522     }
523   unformat_free (line_input);
524
525   if (args.error)
526     return args.error;
527   if (args.group == ~0)
528     return clib_error_return (0, "Missing bond interface");
529   if (args.slave == ~0)
530     return clib_error_return (0, "please specify valid slave interface name");
531
532   bond_enslave (vm, &args);
533
534   return args.error;
535 }
536
537 /* *INDENT-OFF* */
538 VLIB_CLI_COMMAND (enslave_interface_command, static) = {
539   .path = "bond add",
540   .short_help = "bond add <BondEthernetx> <slave-interface> "
541                 "[passive] [long-timeout]",
542   .function = enslave_interface_command_fn,
543 };
544 /* *INDENT-ON* */
545
546 void
547 bond_detach_slave (vlib_main_t * vm, bond_detach_slave_args_t * args)
548 {
549   bond_if_t *bif;
550   slave_if_t *sif;
551
552   sif = bond_get_slave_by_sw_if_index (args->slave);
553   if (!sif)
554     {
555       args->rv = VNET_API_ERROR_INVALID_INTERFACE;
556       args->error = clib_error_return (0, "interface was not enslaved");
557       return;
558     }
559   bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
560   bond_delete_neighbor (vm, bif, sif);
561 }
562
563 static clib_error_t *
564 detach_interface_command_fn (vlib_main_t * vm, unformat_input_t * input,
565                              vlib_cli_command_t * cmd)
566 {
567   bond_detach_slave_args_t args = { 0 };
568   unformat_input_t _line_input, *line_input = &_line_input;
569   vnet_main_t *vnm = vnet_get_main ();
570
571   /* Get a line of input. */
572   if (!unformat_user (input, unformat_line_input, line_input))
573     return clib_error_return (0, "Missing required arguments.");
574
575   args.slave = ~0;
576   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
577     {
578       if (unformat (line_input, "%U",
579                     unformat_vnet_sw_interface, vnm, &args.slave))
580         ;
581       else
582         {
583           args.error = clib_error_return (0, "unknown input `%U'",
584                                           format_unformat_error, input);
585           break;
586         }
587     }
588   unformat_free (line_input);
589
590   if (args.error)
591     return args.error;
592   if (args.slave == ~0)
593     return clib_error_return (0, "please specify valid slave interface name");
594
595   bond_detach_slave (vm, &args);
596
597   return args.error;
598 }
599
600 /* *INDENT-OFF* */
601 VLIB_CLI_COMMAND (detach_interface_command, static) = {
602   .path = "bond del",
603   .short_help = "bond del <slave-interface>",
604   .function = detach_interface_command_fn,
605 };
606 /* *INDENT-ON* */
607
608 static void
609 show_bond (vlib_main_t * vm)
610 {
611   bond_main_t *bm = &bond_main;
612   bond_if_t *bif;
613
614   vlib_cli_output (vm, "%-16s %-12s %-12s %-13s %-14s %s",
615                    "interface name", "sw_if_index", "mode",
616                    "load balance", "active slaves", "slaves");
617
618   /* *INDENT-OFF* */
619   pool_foreach (bif, bm->interfaces,
620   ({
621     vlib_cli_output (vm, "%-16U %-12d %-12U %-13U %-14u %u",
622                      format_bond_interface_name, bif->dev_instance,
623                      bif->sw_if_index, format_bond_mode, bif->mode,
624                      format_bond_load_balance, bif->lb,
625                      vec_len (bif->active_slaves), vec_len (bif->slaves));
626   }));
627   /* *INDENT-ON* */
628 }
629
630 static void
631 show_bond_details (vlib_main_t * vm)
632 {
633   bond_main_t *bm = &bond_main;
634   bond_if_t *bif;
635   u32 *sw_if_index;
636
637   /* *INDENT-OFF* */
638   pool_foreach (bif, bm->interfaces,
639   ({
640     vlib_cli_output (vm, "%U", format_bond_interface_name, bif->dev_instance);
641     vlib_cli_output (vm, "  mode: %U",
642                      format_bond_mode, bif->mode);
643     vlib_cli_output (vm, "  load balance: %U",
644                      format_bond_load_balance, bif->lb);
645     if (bif->mode == BOND_MODE_ROUND_ROBIN)
646       vlib_cli_output (vm, "  last xmit slave index: %u",
647                        bif->lb_rr_last_index);
648     vlib_cli_output (vm, "  number of active slaves: %d",
649                      vec_len (bif->active_slaves));
650     vec_foreach (sw_if_index, bif->active_slaves)
651       {
652         vlib_cli_output (vm, "    %U", format_vnet_sw_if_index_name,
653                          vnet_get_main (), *sw_if_index);
654       }
655     vlib_cli_output (vm, "  number of slaves: %d", vec_len (bif->slaves));
656     vec_foreach (sw_if_index, bif->slaves)
657       {
658         vlib_cli_output (vm, "    %U", format_vnet_sw_if_index_name,
659                          vnet_get_main (), *sw_if_index);
660       }
661     vlib_cli_output (vm, "  device instance: %d", bif->dev_instance);
662     vlib_cli_output (vm, "  sw_if_index: %d", bif->sw_if_index);
663     vlib_cli_output (vm, "  hw_if_index: %d", bif->hw_if_index);
664   }));
665   /* *INDENT-ON* */
666 }
667
668 static clib_error_t *
669 show_bond_fn (vlib_main_t * vm, unformat_input_t * input,
670               vlib_cli_command_t * cmd)
671 {
672   u8 details = 0;
673
674   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
675     {
676       if (unformat (input, "details"))
677         details = 1;
678       else
679         {
680           return clib_error_return (0, "unknown input `%U'",
681                                     format_unformat_error, input);
682         }
683     }
684
685   if (details)
686     show_bond_details (vm);
687   else
688     show_bond (vm);
689
690   return 0;
691 }
692
693 /* *INDENT-OFF* */
694 VLIB_CLI_COMMAND (show_bond_command, static) = {
695   .path = "show bond",
696   .short_help = "show bond [details]",
697   .function = show_bond_fn,
698 };
699 /* *INDENT-ON* */
700
701 clib_error_t *
702 bond_cli_init (vlib_main_t * vm)
703 {
704   bond_main_t *bm = &bond_main;
705
706   bm->vlib_main = vm;
707   bm->vnet_main = vnet_get_main ();
708   bm->neighbor_by_sw_if_index = hash_create (0, sizeof (uword));
709
710   return 0;
711 }
712
713 VLIB_INIT_FUNCTION (bond_cli_init);
714
715 /*
716  * fd.io coding-style-patch-verification: ON
717  *
718  * Local Variables:
719  * eval: (c-set-style "gnu")
720  * End:
721  */