FD.io VPP  v19.08-27-gf4dcae4
Vector Packet Processing
cli.c
Go to the documentation of this file.
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
26 {
27  bond_main_t *bm = &bond_main;
28  bond_if_t *bif;
29  int i;
30  uword p;
31  vnet_main_t *vnm = vnet_get_main ();
33  u8 switching_active = 0;
34 
38  {
39  p = *vec_elt_at_index (bif->active_slaves, i);
40  if (p == sif->sw_if_index)
41  {
42  if (sif->sw_if_index == bif->sw_if_index_working)
43  {
44  switching_active = 1;
45  if (bif->mode == BOND_MODE_ACTIVE_BACKUP)
46  bif->is_local_numa = 0;
47  }
48  vec_del1 (bif->active_slaves, i);
50  if (sif->lacp_enabled && bif->numa_only)
51  {
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)
56  {
57  bif->n_numa_slaves--;
58  ASSERT (bif->n_numa_slaves >= 0);
59  }
60  }
61  break;
62  }
63  }
64 
65  /* We get a new slave just becoming active */
66  if ((bif->mode == BOND_MODE_ACTIVE_BACKUP) && switching_active)
67  {
68  if ((vec_len (bif->active_slaves) >= 1))
69  {
70  /* scan all slaves and try to find the first slave with local numa node. */
72  {
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)
76  {
77  bif->sw_if_index_working = p;
78  bif->is_local_numa = 1;
80  bond_process_node.index,
82  bif->hw_if_index);
83  break;
84  }
85  }
86  }
87 
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))
90  {
91  p = *vec_elt_at_index (bif->active_slaves, 0);
92  bif->sw_if_index_working = p;
95  }
96  }
98 
99  return;
100 }
101 
102 void
104 {
105  bond_if_t *bif;
106  bond_main_t *bm = &bond_main;
107  vnet_main_t *vnm = vnet_get_main ();
109  int i;
110  uword p;
111 
115  {
117  sif->sw_if_index);
118 
119  if ((sif->lacp_enabled && bif->numa_only)
120  && (vm->numa_node == hw->numa_node))
121  {
122  vec_insert_elts (bif->active_slaves, &sif->sw_if_index, 1,
123  bif->n_numa_slaves);
124  bif->n_numa_slaves++;
125  }
126  else
127  {
128  vec_add1 (bif->active_slaves, sif->sw_if_index);
129  }
130 
131  /* First slave becomes active? */
132  if ((vec_len (bif->active_slaves) == 1) &&
133  (bif->mode == BOND_MODE_ACTIVE_BACKUP))
134  {
135  bif->sw_if_index_working = sif->sw_if_index;
136  bif->is_local_numa = (vm->numa_node == hw->numa_node) ? 1 : 0;
139  }
140  else if ((vec_len (bif->active_slaves) > 1)
141  && (bif->mode == BOND_MODE_ACTIVE_BACKUP)
142  && bif->is_local_numa == 0)
143  {
144  if (vm->numa_node == hw->numa_node)
145  {
147  {
148  p = *vec_elt_at_index (bif->active_slaves, 0);
149  if (p == sif->sw_if_index)
150  break;
151 
152  vec_del1 (bif->active_slaves, 0);
154  vec_add1 (bif->active_slaves, p);
156  }
157  bif->sw_if_index_working = sif->sw_if_index;
158  bif->is_local_numa = 1;
160  bond_process_node.index,
162 
163  }
164  }
165  }
167 
168  return;
169 }
170 
171 int
173 {
174  vnet_main_t *vnm = vnet_get_main ();
175  bond_main_t *bm = &bond_main;
176  bond_if_t *bif;
178  bond_interface_details_t *r_bondifs = NULL;
179  bond_interface_details_t *bondif = NULL;
180 
181  /* *INDENT-OFF* */
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);
196  );
197  /* *INDENT-ON* */
198 
199  *out_bondifs = r_bondifs;
200 
201  return 0;
202 }
203 
204 int
206  u32 bond_sw_if_index)
207 {
208  vnet_main_t *vnm = vnet_get_main ();
209  bond_if_t *bif;
212  slave_interface_details_t *r_slaveifs = NULL;
213  slave_interface_details_t *slaveif = NULL;
214  u32 *sw_if_index = NULL;
215  slave_if_t *sif;
216 
217  bif = bond_get_master_by_sw_if_index (bond_sw_if_index);
218  if (!bif)
219  return 1;
220 
221  vec_foreach (sw_if_index, bif->slaves)
222  {
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);
226  if (sif)
227  {
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;
236  }
237  }
238  *out_slaveifs = r_slaveifs;
239 
240  return 0;
241 }
242 
243 static void
245 {
246  bond_main_t *bm = &bond_main;
247  vnet_main_t *vnm = vnet_get_main ();
248  int i;
249  vnet_hw_interface_t *sif_hw;
250 
251  sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
252 
253  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)
260  {
261  uword p = *vec_elt_at_index (bif->slaves, i);
262  if (p == sif->sw_if_index)
263  {
264  vec_del1 (bif->slaves, i);
265  break;
266  }
267  }
268 
270 
271  vnet_feature_enable_disable ("device-input", "bond-input",
272  sif_hw->hw_if_index, 0, 0, 0);
273 
274  /* Put back the old mac */
276  sif->persistent_hw_address);
277 
278  if ((bif->mode == BOND_MODE_LACP) && bm->lacp_enable_disable)
279  (*bm->lacp_enable_disable) (vm, bif, sif, 0);
280 
281  pool_put (bm->neighbors, sif);
282 }
283 
284 int
286 {
287  bond_main_t *bm = &bond_main;
288  vnet_main_t *vnm = vnet_get_main ();
289  bond_if_t *bif;
290  slave_if_t *sif;
292  u32 *sif_sw_if_index;
293  u32 **s_list = 0;
294  u32 i;
295 
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;
299 
301 
302  vec_foreach (sif_sw_if_index, bif->slaves)
303  {
304  vec_add1 (s_list, sif_sw_if_index);
305  }
306 
307  for (i = 0; i < vec_len (s_list); i++)
308  {
309  sif_sw_if_index = s_list[i];
310  sif = bond_get_slave_by_sw_if_index (*sif_sw_if_index);
311  if (sif)
312  bond_delete_neighbor (vm, bif, sif);
313  }
314 
315  if (s_list)
316  vec_free (s_list);
317 
318  /* bring down the interface */
321 
323 
326  hash_unset (bm->id_used, bif->id);
327  clib_memset (bif, 0, sizeof (*bif));
328  pool_put (bm->interfaces, bif);
329 
330  return 0;
331 }
332 
333 void
335 {
336  bond_main_t *bm = &bond_main;
337  vnet_main_t *vnm = vnet_get_main ();
339  bond_if_t *bif;
340 
341  if ((args->mode == BOND_MODE_LACP) && bm->lacp_plugin_loaded == 0)
342  {
343  args->rv = VNET_API_ERROR_FEATURE_DISABLED;
344  args->error = clib_error_return (0, "LACP plugin is not loaded");
345  return;
346  }
347  if (args->mode > BOND_MODE_LACP || args->mode < BOND_MODE_ROUND_ROBIN)
348  {
349  args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
350  args->error = clib_error_return (0, "Invalid mode");
351  return;
352  }
353  if (args->lb > BOND_LB_L23)
354  {
355  args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
356  args->error = clib_error_return (0, "Invalid load-balance");
357  return;
358  }
359  pool_get (bm->interfaces, bif);
360  clib_memset (bif, 0, sizeof (*bif));
361  bif->dev_instance = bif - bm->interfaces;
362  bif->id = args->id;
363  bif->lb = args->lb;
364  bif->mode = args->mode;
365 
366  // Adjust requested interface id
367  if (bif->id == ~0)
368  bif->id = bif->dev_instance;
369  if (hash_get (bm->id_used, bif->id))
370  {
371  args->rv = VNET_API_ERROR_INSTANCE_IN_USE;
372  pool_put (bm->interfaces, bif);
373  return;
374  }
375  hash_set (bm->id_used, bif->id, 1);
376 
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;
384 
385  bif->use_custom_mac = args->hw_addr_set;
386  if (!args->hw_addr_set)
387  {
388  f64 now = vlib_time_now (vm);
389  u32 rnd;
390  rnd = (u32) (now * 1e6);
391  rnd = random_u32 (&rnd);
392 
393  memcpy (args->hw_addr + 2, &rnd, sizeof (rnd));
394  args->hw_addr[0] = 2;
395  args->hw_addr[1] = 0xfe;
396  }
397  memcpy (bif->hw_address, args->hw_addr, 6);
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 */ );
402 
403  if (args->error)
404  {
405  args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
406  hash_unset (bm->id_used, bif->id);
407  pool_put (bm->interfaces, bif);
408  return;
409  }
410 
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);
417 
420 
422 
423  // for return
424  args->sw_if_index = bif->sw_if_index;
425  args->rv = 0;
426 }
427 
428 static clib_error_t *
430  vlib_cli_command_t * cmd)
431 {
432  unformat_input_t _line_input, *line_input = &_line_input;
433  bond_create_if_args_t args = { 0 };
434  u8 mode_is_set = 0;
435 
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.");
439 
440  args.id = ~0;
441  args.mode = -1;
442  args.lb = BOND_LB_L2;
443  args.rv = -1;
444  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
445  {
446  if (unformat (line_input, "mode %U", unformat_bond_mode, &args.mode))
447  mode_is_set = 1;
448  else if (((args.mode == BOND_MODE_LACP) || (args.mode == BOND_MODE_XOR))
449  && unformat (line_input, "load-balance %U",
451  ;
452  else if (unformat (line_input, "hw-addr %U",
454  args.hw_addr_set = 1;
455  else if (unformat (line_input, "id %u", &args.id))
456  ;
457  else if (unformat (line_input, "numa-only"))
458  {
459  if (args.mode == BOND_MODE_LACP)
460  args.numa_only = 1;
461  else
462  return clib_error_return (0,
463  "Only lacp mode supports numa-only so far!");
464  }
465  else
466  return clib_error_return (0, "unknown input `%U'",
467  format_unformat_error, input);
468  }
469  unformat_free (line_input);
470 
471  if (mode_is_set == 0)
472  return clib_error_return (0, "Missing bond mode");
473 
474  bond_create_if (vm, &args);
475 
476  if (!args.rv)
478  vnet_get_main (), args.sw_if_index);
479 
480  return args.error;
481 }
482 
483 /* *INDENT-OFF* */
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>] "
488  "[id <if-id>]",
489  .function = bond_create_command_fn,
490 };
491 /* *INDENT-ON* */
492 
493 static clib_error_t *
495  vlib_cli_command_t * cmd)
496 {
497  unformat_input_t _line_input, *line_input = &_line_input;
498  u32 sw_if_index = ~0;
499  vnet_main_t *vnm = vnet_get_main ();
500  int rv;
501 
502  /* Get a line of input. */
503  if (!unformat_user (input, unformat_line_input, line_input))
504  return clib_error_return (0, "Missing <interface>");
505 
506  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
507  {
508  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
509  ;
510  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
511  vnm, &sw_if_index))
512  ;
513  else
514  return clib_error_return (0, "unknown input `%U'",
515  format_unformat_error, input);
516  }
517  unformat_free (line_input);
518 
519  if (sw_if_index == ~0)
520  return clib_error_return (0,
521  "please specify interface name or sw_if_index");
522 
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");
526  else if (rv != 0)
527  return clib_error_return (0, "error on deleting bond interface");
528 
529  return 0;
530 }
531 
532 /* *INDENT-OFF* */
533 VLIB_CLI_COMMAND (bond_delete__command, static) =
534 {
535  .path = "delete bond",
536  .short_help = "delete bond {<interface> | sw_if_index <sw_idx>}",
537  .function = bond_delete_command_fn,
538 };
539 /* *INDENT-ON* */
540 
541 void
543 {
544  bond_main_t *bm = &bond_main;
545  vnet_main_t *vnm = vnet_get_main ();
546  bond_if_t *bif;
547  slave_if_t *sif;
549  vnet_hw_interface_t *bif_hw, *sif_hw;
551  u32 thread_index;
552  u32 sif_if_index;
553 
555  if (!bif)
556  {
557  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
558  args->error = clib_error_return (0, "bond interface not found");
559  return;
560  }
561  // make sure the interface is not already enslaved
563  {
564  args->rv = VNET_API_ERROR_VALUE_EXIST;
565  args->error = clib_error_return (0, "interface was already enslaved");
566  return;
567  }
568  sif_hw = vnet_get_sup_hw_interface (vnm, args->slave);
569  if (sif_hw->dev_class_index == bond_dev_class.index)
570  {
571  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
572  args->error =
573  clib_error_return (0, "bond interface cannot be enslaved");
574  return;
575  }
576  pool_get (bm->neighbors, sif);
577  clib_memset (sif, 0, sizeof (*sif));
578  sw = pool_elt_at_index (im->sw_interfaces, args->slave);
580  sif->sw_if_index = sw->sw_if_index;
581  sif->hw_if_index = sw->hw_if_index;
582  sif->packet_template_index = (u8) ~ 0;
583  sif->is_passive = args->is_passive;
584  sif->group = args->group;
585  sif->bif_dev_instance = bif->dev_instance;
586  sif->mode = bif->mode;
587 
588  sif->is_long_timeout = args->is_long_timeout;
589  if (args->is_long_timeout)
591  else
593 
596  /*
597  * sif - bm->neighbors may be 0
598  * Left shift it by 1 bit to distinguish the valid entry that we actually
599  * store from the null entries
600  */
602  (uword) (((sif - bm->neighbors) << 1) | 1);
603  vec_add1 (bif->slaves, sif->sw_if_index);
604 
605  sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
606 
607  /* Save the old mac */
608  memcpy (sif->persistent_hw_address, sif_hw->hw_address, 6);
609  bif_hw = vnet_get_sup_hw_interface (vnm, bif->sw_if_index);
610  if (bif->use_custom_mac)
611  {
613  bif->hw_address);
614  }
615  else
616  {
617  // bond interface gets the mac address from the first slave
618  if (vec_len (bif->slaves) == 1)
619  {
620  memcpy (bif->hw_address, sif_hw->hw_address, 6);
622  sif_hw->hw_address);
623  }
624  else
625  {
626  // subsequent slaves gets the mac address of the bond interface
628  bif->hw_address);
629  }
630  }
631 
632  if (bif_hw->l2_if_count)
633  {
634  ethernet_set_flags (vnm, sif_hw->hw_if_index,
636  /* ensure all packets go to ethernet-input */
637  ethernet_set_rx_redirect (vnm, sif_hw, 1);
638  }
639 
640  if (bif->mode == BOND_MODE_LACP)
641  {
642  if (bm->lacp_enable_disable)
643  (*bm->lacp_enable_disable) (vm, bif, sif, 1);
644  }
645  else if (sif->port_enabled &&
647  {
649  }
650 
651  vec_foreach_index (thread_index, bm->per_thread_data)
652  {
654  thread_index);
655 
658 
659  vec_foreach_index (sif_if_index, ptd->per_port_queue)
660  {
661  ptd->per_port_queue[sif_if_index].n_buffers = 0;
662  }
663  }
664 
665  args->rv = vnet_feature_enable_disable ("device-input", "bond-input",
666  sif_hw->hw_if_index, 1, 0, 0);
667 
668  if (args->rv)
669  {
670  args->error =
672  "Error encountered on input feature arc enable");
673  }
674 }
675 
676 static clib_error_t *
678  vlib_cli_command_t * cmd)
679 {
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 ();
683 
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.");
687 
688  args.slave = ~0;
689  args.group = ~0;
690  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
691  {
692  if (unformat (line_input, "%U %U",
693  unformat_vnet_sw_interface, vnm, &args.group,
694  unformat_vnet_sw_interface, vnm, &args.slave))
695  ;
696  else if (unformat (line_input, "passive"))
697  args.is_passive = 1;
698  else if (unformat (line_input, "long-timeout"))
699  args.is_long_timeout = 1;
700  else
701  {
702  args.error = clib_error_return (0, "unknown input `%U'",
703  format_unformat_error, input);
704  break;
705  }
706  }
707  unformat_free (line_input);
708 
709  if (args.error)
710  return args.error;
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");
715 
716  bond_enslave (vm, &args);
717 
718  return args.error;
719 }
720 
721 /* *INDENT-OFF* */
722 VLIB_CLI_COMMAND (enslave_interface_command, static) = {
723  .path = "bond add",
724  .short_help = "bond add <BondEthernetx> <slave-interface> "
725  "[passive] [long-timeout]",
726  .function = enslave_interface_command_fn,
727 };
728 /* *INDENT-ON* */
729 
730 void
732 {
733  bond_if_t *bif;
734  slave_if_t *sif;
735 
736  sif = bond_get_slave_by_sw_if_index (args->slave);
737  if (!sif)
738  {
739  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
740  args->error = clib_error_return (0, "interface was not enslaved");
741  return;
742  }
744  bond_delete_neighbor (vm, bif, sif);
745 }
746 
747 static clib_error_t *
749  vlib_cli_command_t * cmd)
750 {
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 ();
754 
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.");
758 
759  args.slave = ~0;
760  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
761  {
762  if (unformat (line_input, "%U",
763  unformat_vnet_sw_interface, vnm, &args.slave))
764  ;
765  else
766  {
767  args.error = clib_error_return (0, "unknown input `%U'",
768  format_unformat_error, input);
769  break;
770  }
771  }
772  unformat_free (line_input);
773 
774  if (args.error)
775  return args.error;
776  if (args.slave == ~0)
777  return clib_error_return (0, "please specify valid slave interface name");
778 
779  bond_detach_slave (vm, &args);
780 
781  return args.error;
782 }
783 
784 /* *INDENT-OFF* */
785 VLIB_CLI_COMMAND (detach_interface_command, static) = {
786  .path = "bond del",
787  .short_help = "bond del <slave-interface>",
788  .function = detach_interface_command_fn,
789 };
790 /* *INDENT-ON* */
791 
792 static void
794 {
795  bond_main_t *bm = &bond_main;
796  bond_if_t *bif;
797 
798  vlib_cli_output (vm, "%-16s %-12s %-13s %-13s %-14s %s",
799  "interface name", "sw_if_index", "mode",
800  "load balance", "active slaves", "slaves");
801 
802  /* *INDENT-OFF* */
803  pool_foreach (bif, bm->interfaces,
804  ({
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));
810  }));
811  /* *INDENT-ON* */
812 }
813 
814 static void
816 {
817  bond_main_t *bm = &bond_main;
818  bond_if_t *bif;
819  u32 *sw_if_index;
820 
821  /* *INDENT-OFF* */
822  pool_foreach (bif, bm->interfaces,
823  ({
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)
835  {
836  vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
837  vnet_get_main (), *sw_if_index);
838  }
839  vlib_cli_output (vm, " number of slaves: %d", vec_len (bif->slaves));
840  vec_foreach (sw_if_index, bif->slaves)
841  {
842  vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
843  vnet_get_main (), *sw_if_index);
844  }
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);
849  }));
850  /* *INDENT-ON* */
851 }
852 
853 static clib_error_t *
855  vlib_cli_command_t * cmd)
856 {
857  u8 details = 0;
858 
860  {
861  if (unformat (input, "details"))
862  details = 1;
863  else
864  {
865  return clib_error_return (0, "unknown input `%U'",
866  format_unformat_error, input);
867  }
868  }
869 
870  if (details)
871  show_bond_details (vm);
872  else
873  show_bond (vm);
874 
875  return 0;
876 }
877 
878 /* *INDENT-OFF* */
879 VLIB_CLI_COMMAND (show_bond_command, static) = {
880  .path = "show bond",
881  .short_help = "show bond [details]",
882  .function = show_bond_fn,
883 };
884 /* *INDENT-ON* */
885 
886 clib_error_t *
888 {
889  bond_main_t *bm = &bond_main;
890 
891  bm->vlib_main = vm;
892  bm->vnet_main = vnet_get_main ();
895  vlib_get_thread_main ()->n_vlib_mains - 1,
897 
898  return 0;
899 }
900 
902 
903 /*
904  * fd.io coding-style-patch-verification: ON
905  *
906  * Local Variables:
907  * eval: (c-set-style "gnu")
908  * End:
909  */
vnet_main_t * vnet_main
Definition: node.h:360
vmrglw vmrglh hi
u32 dev_instance
Definition: node.h:171
u32 group
Definition: node.h:200
#define vec_foreach_index(var, v)
Iterate over vector indices.
u32 hw_if_index
Definition: node.h:176
static uword unformat_bond_mode(unformat_input_t *input, va_list *args)
Definition: node.h:408
#define hash_set(h, key, value)
Definition: hash.h:255
static void bond_delete_neighbor(vlib_main_t *vm, bond_if_t *bif, slave_if_t *sif)
Definition: cli.c:244
static void show_bond_details(vlib_main_t *vm)
Definition: cli.c:815
vlib_node_registration_t bond_process_node
(constructor) VLIB_REGISTER_NODE (bond_process_node)
Definition: device.c:790
int bond_delete_if(vlib_main_t *vm, u32 sw_if_index)
Definition: cli.c:285
#define hash_unset(h, key)
Definition: hash.h:261
void ethernet_delete_interface(vnet_main_t *vnm, u32 hw_if_index)
Definition: interface.c:324
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
u8 lb
Definition: node.h:160
static clib_error_t * detach_interface_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:748
vnet_interface_main_t interface_main
Definition: vnet.h:56
clib_error_t * error
Definition: node.h:89
uword * id_used
Definition: node.h:350
int bond_dump_ifs(bond_interface_details_t **out_bondifs)
Definition: cli.c:172
static bond_if_t * bond_get_master_by_sw_if_index(u32 sw_if_index)
Definition: node.h:481
#define NULL
Definition: clib.h:58
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:258
u8 is_long_timeout
Definition: node.h:99
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:108
u8 * last_marker_pkt
Definition: node.h:237
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:522
#define vec_add2(V, P, N)
Add N elements to end of vector V, return pointer to new elements in P.
Definition: vec.h:560
int i
bond_main_t bond_main
Definition: node.c:25
static uword * clib_bitmap_set(uword *ai, uword i, uword value)
Sets the ith bit of a bitmap to new_value Removes trailing zeros from the bitmap. ...
Definition: bitmap.h:167
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:989
clib_memset(h->entries, 0, sizeof(h->entries[0])*entries)
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
lacp_enable_disable_func lacp_enable_disable
Definition: node.h:365
unformat_function_t unformat_vnet_sw_interface
u32 numa_node
Definition: main.h:199
static clib_error_t * enslave_interface_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:677
#define vec_validate_aligned(V, I, A)
Make sure vector is long enough for given index (no header, specified alignment)
Definition: vec.h:450
u32 id
Definition: node.h:174
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
u8 mode
Definition: node.h:320
void bond_enable_collecting_distributing(vlib_main_t *vm, slave_if_t *sif)
Definition: cli.c:103
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
bond_per_thread_data_t * per_thread_data
Definition: node.h:369
double f64
Definition: types.h:142
static vnet_sw_interface_t * vnet_get_hw_sw_interface(vnet_main_t *vnm, u32 hw_if_index)
#define clib_memcpy(d, s, n)
Definition: string.h:180
static clib_error_t * show_bond_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:854
f32 ttl_in_seconds
Definition: node.h:216
u8 numa_only
Definition: node.h:195
u8 is_local_numa
Definition: node.h:164
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
u8 use_custom_mac
Definition: node.h:202
u32 sw_if_index
Definition: node.h:177
uword * active_slave_by_sw_if_index
Definition: node.h:186
vnet_hw_interface_flags_t flags
Definition: interface.h:505
void bond_enslave(vlib_main_t *vm, bond_enslave_args_t *args)
Definition: cli.c:542
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_error_return(e, args...)
Definition: error.h:99
vlib_main_t * vlib_main
Definition: node.h:359
unsigned int u32
Definition: types.h:88
#define MIN(x, y)
Definition: node.h:31
unformat_function_t unformat_line_input
Definition: format.h:283
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:61
u8 * last_rx_pkt
Definition: node.h:234
void ethernet_set_rx_redirect(vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 enable)
Definition: node.c:1939
static clib_error_t * bond_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:429
#define LACP_LONG_TIMOUT_TIME
Definition: node.h:28
#define hash_get(h, key)
Definition: hash.h:249
vnet_device_class_t bond_dev_class
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:934
struct _unformat_input_t unformat_input_t
static uword unformat_bond_load_balance(unformat_input_t *input, va_list *args)
Definition: node.h:440
u8 persistent_hw_address[6]
Definition: node.h:210
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
vnet_sw_interface_flags_t flags
Definition: interface.h:699
#define vec_del1(v, i)
Delete the element at index I.
Definition: vec.h:804
#define LACP_SHORT_TIMOUT_TIME
Definition: node.h:26
static clib_error_t * bond_delete_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:494
bond_if_t * interfaces
Definition: node.h:347
u8 is_long_timeout
Definition: node.h:219
void bond_detach_slave(vlib_main_t *vm, bond_detach_slave_args_t *args)
Definition: cli.c:731
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
u32 * slaves
Definition: node.h:180
u8 is_passive
Definition: node.h:243
u8 mode
Definition: node.h:159
word n_numa_slaves
Definition: node.h:198
u32 sw_if_index
Definition: node.h:213
vlib_main_t * vm
Definition: buffer.c:312
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
uword * bond_by_sw_if_index
Definition: node.h:356
u32 group
Definition: node.h:311
void bond_disable_collecting_distributing(vlib_main_t *vm, slave_if_t *sif)
Definition: cli.c:25
clib_spinlock_t lockp
Definition: node.h:205
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL
Definition: ethernet.h:141
#define ARRAY_LEN(x)
Definition: clib.h:62
static void show_bond(vlib_main_t *vm)
Definition: cli.c:793
BOND interface details struct.
Definition: node.h:114
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
uword * slave_by_sw_if_index
Definition: node.h:367
u32 sw_if_index_working
Definition: node.h:166
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
Definition: format.c:233
#define ASSERT(truth)
void bond_create_if(vlib_main_t *vm, bond_create_if_args_t *args)
Definition: cli.c:334
u8 lacp_plugin_loaded
Definition: node.h:363
static bond_if_t * bond_get_master_by_dev_instance(u32 dev_instance)
Definition: node.h:495
#define vec_insert_elts(V, E, N, M)
Insert N vector elements starting at element M, insert given elements (no header, unspecified alignme...
Definition: vec.h:763
u32 bif_dev_instance
Definition: node.h:315
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
u32 * active_slaves
Definition: node.h:183
clib_error_t * error
Definition: node.h:102
clib_error_t * error
Definition: node.h:110
u8 lacp_enabled
Definition: node.h:263
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
clib_error_t * ethernet_register_interface(vnet_main_t *vnm, u32 dev_class_index, u32 dev_instance, const u8 *address, u32 *hw_if_index_return, ethernet_flag_change_function_t flag_change)
Definition: interface.c:278
clib_error_t * vnet_hw_interface_set_flags(vnet_main_t *vnm, u32 hw_if_index, vnet_hw_interface_flags_t flags)
Definition: interface.c:501
uword * port_number_bitmap
Definition: node.h:201
u64 uword
Definition: types.h:112
static void unformat_free(unformat_input_t *i)
Definition: format.h:163
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:833
int bond_dump_slave_ifs(slave_interface_details_t **out_slaveifs, u32 bond_sw_if_index)
Definition: cli.c:205
slave interface details struct
Definition: node.h:127
static u32 random_u32(u32 *seed)
32-bit random number generator
Definition: random.h:69
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
slave_if_t * neighbors
Definition: node.h:353
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, vnet_sw_interface_flags_t flags)
Definition: interface.c:510
static vlib_thread_main_t * vlib_get_thread_main()
Definition: global_funcs.h:32
#define vec_foreach(var, vec)
Vector iterator.
u8 hw_address[6]
Definition: node.h:203
clib_error_t * vnet_hw_interface_change_mac_address(vnet_main_t *vnm, u32 hw_if_index, const u8 *mac_address)
Definition: interface.c:1485
u8 port_enabled
Definition: node.h:257
static slave_if_t * bond_get_slave_by_sw_if_index(u32 sw_if_index)
Definition: node.h:503
lacp_port_info_t actor_admin
Definition: node.h:251
clib_error_t * bond_cli_init(vlib_main_t *vm)
Definition: cli.c:887
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
u8 packet_template_index
Definition: node.h:225
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:768
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:93
u32 hw_if_index
Definition: node.h:240
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
int vnet_feature_enable_disable(const char *arc_name, const char *node_name, u32 sw_if_index, int enable_disable, void *feature_config, u32 n_feature_config_bytes)
Definition: feature.c:274
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
bond_per_port_queue_t * per_port_queue
Definition: node.h:153
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:372