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