bond: performance enhancement
[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, "interface %U",
509                     unformat_vnet_sw_interface, vnm, &args.slave))
510         ;
511       else if (unformat (line_input, "to %U", unformat_vnet_sw_interface, vnm,
512                          &args.group))
513         ;
514       else if (unformat (line_input, "passive"))
515         args.is_passive = 1;
516       else if (unformat (line_input, "long-timeout"))
517         args.is_long_timeout = 1;
518       else
519         {
520           args.error = clib_error_return (0, "unknown input `%U'",
521                                           format_unformat_error, input);
522           break;
523         }
524     }
525   unformat_free (line_input);
526
527   if (args.error)
528     return args.error;
529   if (args.group == ~0)
530     return clib_error_return (0, "Missing bond interface");
531   if (args.slave == ~0)
532     return clib_error_return (0, "please specify valid interface name");
533
534   bond_enslave (vm, &args);
535
536   return args.error;
537 }
538
539 /* *INDENT-OFF* */
540 VLIB_CLI_COMMAND (enslave_interface_command, static) = {
541   .path = "enslave",
542   .short_help = "enslave interface <interface> to <BondEthernetx> [passive] [long-timeout]",
543   .function = enslave_interface_command_fn,
544 };
545 /* *INDENT-ON* */
546
547 void
548 bond_detach_slave (vlib_main_t * vm, bond_detach_slave_args_t * args)
549 {
550   bond_if_t *bif;
551   slave_if_t *sif;
552
553   sif = bond_get_slave_by_sw_if_index (args->slave);
554   if (!sif)
555     {
556       args->rv = VNET_API_ERROR_INVALID_INTERFACE;
557       args->error = clib_error_return (0, "interface was not enslaved");
558       return;
559     }
560   bif = bond_get_master_by_dev_instance (sif->bif_dev_instance);
561   bond_delete_neighbor (vm, bif, sif);
562 }
563
564 static clib_error_t *
565 detach_interface_command_fn (vlib_main_t * vm, unformat_input_t * input,
566                              vlib_cli_command_t * cmd)
567 {
568   bond_detach_slave_args_t args = { 0 };
569   unformat_input_t _line_input, *line_input = &_line_input;
570   vnet_main_t *vnm = vnet_get_main ();
571
572   /* Get a line of input. */
573   if (!unformat_user (input, unformat_line_input, line_input))
574     return clib_error_return (0, "Missing required arguments.");
575
576   args.slave = ~0;
577   while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
578     {
579       if (unformat (line_input, "interface %U",
580                     unformat_vnet_sw_interface, vnm, &args.slave))
581         ;
582       else
583         {
584           args.error = clib_error_return (0, "unknown input `%U'",
585                                           format_unformat_error, input);
586           break;
587         }
588     }
589   unformat_free (line_input);
590
591   if (args.error)
592     return args.error;
593   if (args.slave == ~0)
594     return clib_error_return (0, "please specify valid interface name");
595
596   bond_detach_slave (vm, &args);
597
598   return args.error;
599 }
600
601 /* *INDENT-OFF* */
602 VLIB_CLI_COMMAND (detach_interface_command, static) = {
603   .path = "detach",
604   .short_help = "detach interface <interface>",
605   .function = detach_interface_command_fn,
606 };
607 /* *INDENT-ON* */
608
609 static void
610 show_bond (vlib_main_t * vm)
611 {
612   bond_main_t *bm = &bond_main;
613   bond_if_t *bif;
614
615   vlib_cli_output (vm, "%-16s %-12s %-12s %-13s %-14s %s",
616                    "interface name", "sw_if_index", "mode",
617                    "load balance", "active slaves", "slaves");
618
619   /* *INDENT-OFF* */
620   pool_foreach (bif, bm->interfaces,
621   ({
622     vlib_cli_output (vm, "%-16U %-12d %-12U %-13U %-14u %u",
623                      format_bond_interface_name, bif->dev_instance,
624                      bif->sw_if_index, format_bond_mode, bif->mode,
625                      format_bond_load_balance, bif->lb,
626                      vec_len (bif->active_slaves), vec_len (bif->slaves));
627   }));
628   /* *INDENT-ON* */
629 }
630
631 static void
632 show_bond_details (vlib_main_t * vm)
633 {
634   bond_main_t *bm = &bond_main;
635   bond_if_t *bif;
636   u32 *sw_if_index;
637
638   /* *INDENT-OFF* */
639   pool_foreach (bif, bm->interfaces,
640   ({
641     vlib_cli_output (vm, "%U", format_bond_interface_name, bif->dev_instance);
642     vlib_cli_output (vm, "  mode: %U",
643                      format_bond_mode, bif->mode);
644     vlib_cli_output (vm, "  load balance: %U",
645                      format_bond_load_balance, bif->lb);
646     if (bif->mode == BOND_MODE_ROUND_ROBIN)
647       vlib_cli_output (vm, "  last xmit slave index: %u",
648                        bif->lb_rr_last_index);
649     vlib_cli_output (vm, "  number of active slaves: %d",
650                      vec_len (bif->active_slaves));
651     vec_foreach (sw_if_index, bif->active_slaves)
652       {
653         vlib_cli_output (vm, "    %U", format_vnet_sw_if_index_name,
654                          vnet_get_main (), *sw_if_index);
655       }
656     vlib_cli_output (vm, "  number of slaves: %d", vec_len (bif->slaves));
657     vec_foreach (sw_if_index, bif->slaves)
658       {
659         vlib_cli_output (vm, "    %U", format_vnet_sw_if_index_name,
660                          vnet_get_main (), *sw_if_index);
661       }
662     vlib_cli_output (vm, "  device instance: %d", bif->dev_instance);
663     vlib_cli_output (vm, "  sw_if_index: %d", bif->sw_if_index);
664     vlib_cli_output (vm, "  hw_if_index: %d", bif->hw_if_index);
665   }));
666   /* *INDENT-ON* */
667 }
668
669 static clib_error_t *
670 show_bond_fn (vlib_main_t * vm, unformat_input_t * input,
671               vlib_cli_command_t * cmd)
672 {
673   u8 details = 0;
674
675   while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
676     {
677       if (unformat (input, "details"))
678         details = 1;
679       else
680         {
681           return clib_error_return (0, "unknown input `%U'",
682                                     format_unformat_error, input);
683         }
684     }
685
686   if (details)
687     show_bond_details (vm);
688   else
689     show_bond (vm);
690
691   return 0;
692 }
693
694 /* *INDENT-OFF* */
695 VLIB_CLI_COMMAND (show_bond_command, static) = {
696   .path = "show bond",
697   .short_help = "show bond [details]",
698   .function = show_bond_fn,
699 };
700 /* *INDENT-ON* */
701
702 clib_error_t *
703 bond_cli_init (vlib_main_t * vm)
704 {
705   bond_main_t *bm = &bond_main;
706
707   bm->vlib_main = vm;
708   bm->vnet_main = vnet_get_main ();
709   bm->neighbor_by_sw_if_index = hash_create (0, sizeof (uword));
710
711   return 0;
712 }
713
714 VLIB_INIT_FUNCTION (bond_cli_init);
715
716 /*
717  * fd.io coding-style-patch-verification: ON
718  *
719  * Local Variables:
720  * eval: (c-set-style "gnu")
721  * End:
722  */