FD.io VPP  v19.04.4-rc0-5-ge88582fac
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  u8 switching_active = 0;
32 
36  {
37  p = *vec_elt_at_index (bif->active_slaves, i);
38  if (p == sif->sw_if_index)
39  {
40  /* Are we disabling the very 1st slave? */
41  if (sif->sw_if_index == *vec_elt_at_index (bif->active_slaves, 0))
42  switching_active = 1;
43 
44  vec_del1 (bif->active_slaves, i);
45 
46  /* We got a new slave just becoming active? */
47  if ((vec_len (bif->active_slaves) >= 1) &&
48  (bif->mode == BOND_MODE_ACTIVE_BACKUP) && switching_active)
51  break;
52  }
53  }
55 }
56 
57 void
59 {
60  bond_if_t *bif;
61  bond_main_t *bm = &bond_main;
62  int i;
63  uword p;
64 
68  {
69  p = *vec_elt_at_index (bif->active_slaves, i);
70  if (p == sif->sw_if_index)
71  goto done;
72  }
73 
74  vec_add1 (bif->active_slaves, sif->sw_if_index);
75 
76  /* First slave becomes active? */
77  if ((vec_len (bif->active_slaves) == 1) &&
78  (bif->mode == BOND_MODE_ACTIVE_BACKUP))
81 
82 done:
84 }
85 
86 int
88 {
89  vnet_main_t *vnm = vnet_get_main ();
90  bond_main_t *bm = &bond_main;
91  bond_if_t *bif;
93  bond_interface_details_t *r_bondifs = NULL;
95 
96  /* *INDENT-OFF* */
97  pool_foreach (bif, bm->interfaces,
98  vec_add2(r_bondifs, bondif, 1);
99  clib_memset (bondif, 0, sizeof (*bondif));
100  bondif->id = bif->id;
101  bondif->sw_if_index = bif->sw_if_index;
102  hi = vnet_get_hw_interface (vnm, bif->hw_if_index);
103  clib_memcpy(bondif->interface_name, hi->name,
104  MIN (ARRAY_LEN (bondif->interface_name) - 1,
105  strlen ((const char *) hi->name)));
106  bondif->mode = bif->mode;
107  bondif->lb = bif->lb;
108  bondif->active_slaves = vec_len (bif->active_slaves);
109  bondif->slaves = vec_len (bif->slaves);
110  );
111  /* *INDENT-ON* */
112 
113  *out_bondifs = r_bondifs;
114 
115  return 0;
116 }
117 
118 int
120  u32 bond_sw_if_index)
121 {
122  vnet_main_t *vnm = vnet_get_main ();
123  bond_if_t *bif;
126  slave_interface_details_t *r_slaveifs = NULL;
127  slave_interface_details_t *slaveif = NULL;
128  u32 *sw_if_index = NULL;
129  slave_if_t *sif;
130 
131  bif = bond_get_master_by_sw_if_index (bond_sw_if_index);
132  if (!bif)
133  return 1;
134 
135  vec_foreach (sw_if_index, bif->slaves)
136  {
137  vec_add2 (r_slaveifs, slaveif, 1);
138  clib_memset (slaveif, 0, sizeof (*slaveif));
139  sif = bond_get_slave_by_sw_if_index (*sw_if_index);
140  if (sif)
141  {
142  sw = vnet_get_sw_interface (vnm, sif->sw_if_index);
143  hi = vnet_get_hw_interface (vnm, sw->hw_if_index);
144  clib_memcpy (slaveif->interface_name, hi->name,
145  MIN (ARRAY_LEN (slaveif->interface_name) - 1,
146  strlen ((const char *) hi->name)));
147  slaveif->sw_if_index = sif->sw_if_index;
148  slaveif->is_passive = sif->is_passive;
149  slaveif->is_long_timeout = sif->is_long_timeout;
150  }
151  }
152  *out_slaveifs = r_slaveifs;
153 
154  return 0;
155 }
156 
157 static void
159 {
160  bond_main_t *bm = &bond_main;
161  vnet_main_t *vnm = vnet_get_main ();
162  int i;
163  vnet_hw_interface_t *sif_hw;
164 
165  sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
166 
167  bif->port_number_bitmap =
169  ntohs (sif->actor_admin.port_number) - 1, 0);
170  bm->slave_by_sw_if_index[sif->sw_if_index] = 0;
171  vec_free (sif->last_marker_pkt);
172  vec_free (sif->last_rx_pkt);
173  vec_foreach_index (i, bif->slaves)
174  {
175  uword p = *vec_elt_at_index (bif->slaves, i);
176  if (p == sif->sw_if_index)
177  {
178  vec_del1 (bif->slaves, i);
179  break;
180  }
181  }
182 
184 
185  vnet_feature_enable_disable ("device-input", "bond-input",
186  sif_hw->hw_if_index, 0, 0, 0);
187 
188  /* Put back the old mac */
190  sif->persistent_hw_address);
191 
192  if ((bif->mode == BOND_MODE_LACP) && bm->lacp_enable_disable)
193  (*bm->lacp_enable_disable) (vm, bif, sif, 0);
194 
195  pool_put (bm->neighbors, sif);
196 }
197 
198 int
200 {
201  bond_main_t *bm = &bond_main;
202  vnet_main_t *vnm = vnet_get_main ();
203  bond_if_t *bif;
204  slave_if_t *sif;
206  u32 *sif_sw_if_index;
207  u32 **s_list = 0;
208  u32 i;
209 
210  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
211  if (hw == NULL || bond_dev_class.index != hw->dev_class_index)
212  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
213 
215 
216  vec_foreach (sif_sw_if_index, bif->slaves)
217  {
218  vec_add1 (s_list, sif_sw_if_index);
219  }
220 
221  for (i = 0; i < vec_len (s_list); i++)
222  {
223  sif_sw_if_index = s_list[i];
224  sif = bond_get_slave_by_sw_if_index (*sif_sw_if_index);
225  if (sif)
226  bond_delete_neighbor (vm, bif, sif);
227  }
228 
229  if (s_list)
230  vec_free (s_list);
231 
232  /* bring down the interface */
235 
237 
240  hash_unset (bm->id_used, bif->id);
241  clib_memset (bif, 0, sizeof (*bif));
242  pool_put (bm->interfaces, bif);
243 
244  return 0;
245 }
246 
247 void
249 {
250  bond_main_t *bm = &bond_main;
251  vnet_main_t *vnm = vnet_get_main ();
253  bond_if_t *bif;
254 
255  if ((args->mode == BOND_MODE_LACP) && bm->lacp_plugin_loaded == 0)
256  {
257  args->rv = VNET_API_ERROR_FEATURE_DISABLED;
258  args->error = clib_error_return (0, "LACP plugin is not loaded");
259  return;
260  }
261  if (args->mode > BOND_MODE_LACP || args->mode < BOND_MODE_ROUND_ROBIN)
262  {
263  args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
264  args->error = clib_error_return (0, "Invalid mode");
265  return;
266  }
267  if (args->lb > BOND_LB_L23)
268  {
269  args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
270  args->error = clib_error_return (0, "Invalid load-balance");
271  return;
272  }
273  pool_get (bm->interfaces, bif);
274  clib_memset (bif, 0, sizeof (*bif));
275  bif->dev_instance = bif - bm->interfaces;
276  bif->id = args->id;
277  bif->lb = args->lb;
278  bif->mode = args->mode;
279 
280  // Adjust requested interface id
281  if (bif->id == ~0)
282  bif->id = bif->dev_instance;
283  if (hash_get (bm->id_used, bif->id))
284  {
285  args->rv = VNET_API_ERROR_INSTANCE_IN_USE;
286  pool_put (bm->interfaces, bif);
287  return;
288  }
289  hash_set (bm->id_used, bif->id, 1);
290 
291  // Special load-balance mode used for rr and bc
292  if (bif->mode == BOND_MODE_ROUND_ROBIN)
293  bif->lb = BOND_LB_RR;
294  else if (bif->mode == BOND_MODE_BROADCAST)
295  bif->lb = BOND_LB_BC;
296  else if (bif->mode == BOND_MODE_ACTIVE_BACKUP)
297  bif->lb = BOND_LB_AB;
298 
299  bif->use_custom_mac = args->hw_addr_set;
300  if (!args->hw_addr_set)
301  {
302  f64 now = vlib_time_now (vm);
303  u32 rnd;
304  rnd = (u32) (now * 1e6);
305  rnd = random_u32 (&rnd);
306 
307  memcpy (args->hw_addr + 2, &rnd, sizeof (rnd));
308  args->hw_addr[0] = 2;
309  args->hw_addr[1] = 0xfe;
310  }
311  memcpy (bif->hw_address, args->hw_addr, 6);
313  (vnm, bond_dev_class.index, bif->dev_instance /* device instance */ ,
314  bif->hw_address /* ethernet address */ ,
315  &bif->hw_if_index, 0 /* flag change */ );
316 
317  if (args->error)
318  {
319  args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
320  hash_unset (bm->id_used, bif->id);
321  pool_put (bm->interfaces, bif);
322  return;
323  }
324 
325  sw = vnet_get_hw_sw_interface (vnm, bif->hw_if_index);
326  bif->sw_if_index = sw->sw_if_index;
327  bif->group = bif->sw_if_index;
328  if (vlib_get_thread_main ()->n_vlib_mains > 1)
329  clib_spinlock_init (&bif->lockp);
330 
333 
335 
336  // for return
337  args->sw_if_index = bif->sw_if_index;
338 }
339 
340 static clib_error_t *
342  vlib_cli_command_t * cmd)
343 {
344  unformat_input_t _line_input, *line_input = &_line_input;
345  bond_create_if_args_t args = { 0 };
346  u8 mode_is_set = 0;
347 
348  /* Get a line of input. */
349  if (!unformat_user (input, unformat_line_input, line_input))
350  return clib_error_return (0, "Missing required arguments.");
351 
352  args.id = ~0;
353  args.mode = -1;
354  args.lb = BOND_LB_L2;
355  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
356  {
357  if (unformat (line_input, "mode %U", unformat_bond_mode, &args.mode))
358  mode_is_set = 1;
359  else if (((args.mode == BOND_MODE_LACP) || (args.mode == BOND_MODE_XOR))
360  && unformat (line_input, "load-balance %U",
362  ;
363  else if (unformat (line_input, "hw-addr %U",
365  args.hw_addr_set = 1;
366  else if (unformat (line_input, "id %u", &args.id))
367  ;
368  else
369  return clib_error_return (0, "unknown input `%U'",
370  format_unformat_error, input);
371  }
372  unformat_free (line_input);
373 
374  if (mode_is_set == 0)
375  return clib_error_return (0, "Missing bond mode");
376 
377  bond_create_if (vm, &args);
378 
379  return args.error;
380 }
381 
382 /* *INDENT-OFF* */
383 VLIB_CLI_COMMAND (bond_create_command, static) = {
384  .path = "create bond",
385  .short_help = "create bond mode {round-robin | active-backup | broadcast | "
386  "{lacp | xor} [load-balance { l2 | l23 | l34 }]} [hw-addr <mac-address>] "
387  "[id <if-id>]",
388  .function = bond_create_command_fn,
389 };
390 /* *INDENT-ON* */
391 
392 static clib_error_t *
394  vlib_cli_command_t * cmd)
395 {
396  unformat_input_t _line_input, *line_input = &_line_input;
397  u32 sw_if_index = ~0;
398  vnet_main_t *vnm = vnet_get_main ();
399  int rv;
400 
401  /* Get a line of input. */
402  if (!unformat_user (input, unformat_line_input, line_input))
403  return clib_error_return (0, "Missing <interface>");
404 
405  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
406  {
407  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
408  ;
409  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
410  vnm, &sw_if_index))
411  ;
412  else
413  return clib_error_return (0, "unknown input `%U'",
414  format_unformat_error, input);
415  }
416  unformat_free (line_input);
417 
418  if (sw_if_index == ~0)
419  return clib_error_return (0,
420  "please specify interface name or sw_if_index");
421 
422  rv = bond_delete_if (vm, sw_if_index);
423  if (rv == VNET_API_ERROR_INVALID_SW_IF_INDEX)
424  return clib_error_return (0, "not a bond interface");
425  else if (rv != 0)
426  return clib_error_return (0, "error on deleting bond interface");
427 
428  return 0;
429 }
430 
431 /* *INDENT-OFF* */
432 VLIB_CLI_COMMAND (bond_delete__command, static) =
433 {
434  .path = "delete bond",
435  .short_help = "delete bond {<interface> | sw_if_index <sw_idx>}",
436  .function = bond_delete_command_fn,
437 };
438 /* *INDENT-ON* */
439 
440 void
442 {
443  bond_main_t *bm = &bond_main;
444  vnet_main_t *vnm = vnet_get_main ();
445  bond_if_t *bif;
446  slave_if_t *sif;
448  vnet_hw_interface_t *bif_hw, *sif_hw;
450  u32 thread_index;
451  u32 sif_if_index;
452 
454  if (!bif)
455  {
456  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
457  args->error = clib_error_return (0, "bond interface not found");
458  return;
459  }
460  // make sure the interface is not already enslaved
462  {
463  args->rv = VNET_API_ERROR_VALUE_EXIST;
464  args->error = clib_error_return (0, "interface was already enslaved");
465  return;
466  }
467  sif_hw = vnet_get_sup_hw_interface (vnm, args->slave);
468  if (sif_hw->dev_class_index == bond_dev_class.index)
469  {
470  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
471  args->error =
472  clib_error_return (0, "bond interface cannot be enslaved");
473  return;
474  }
475  pool_get (bm->neighbors, sif);
476  clib_memset (sif, 0, sizeof (*sif));
477  sw = pool_elt_at_index (im->sw_interfaces, args->slave);
479  sif->sw_if_index = sw->sw_if_index;
480  sif->hw_if_index = sw->hw_if_index;
481  sif->packet_template_index = (u8) ~ 0;
482  sif->is_passive = args->is_passive;
483  sif->group = args->group;
484  sif->bif_dev_instance = bif->dev_instance;
485  sif->mode = bif->mode;
486 
487  sif->is_long_timeout = args->is_long_timeout;
488  if (args->is_long_timeout)
490  else
492 
495  /*
496  * sif - bm->neighbors may be 0
497  * Left shift it by 1 bit to distinguish the valid entry that we actually
498  * store from the null entries
499  */
501  (uword) (((sif - bm->neighbors) << 1) | 1);
502  vec_add1 (bif->slaves, sif->sw_if_index);
503 
504  sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
505 
506  /* Save the old mac */
507  memcpy (sif->persistent_hw_address, sif_hw->hw_address, 6);
508  bif_hw = vnet_get_sup_hw_interface (vnm, bif->sw_if_index);
509  if (bif->use_custom_mac)
510  {
512  bif->hw_address);
513  }
514  else
515  {
516  // bond interface gets the mac address from the first slave
517  if (vec_len (bif->slaves) == 1)
518  {
519  memcpy (bif->hw_address, sif_hw->hw_address, 6);
521  sif_hw->hw_address);
522  }
523  else
524  {
525  // subsequent slaves gets the mac address of the bond interface
527  bif->hw_address);
528  }
529  }
530 
531  if (bif_hw->l2_if_count)
532  {
533  ethernet_set_flags (vnm, sif_hw->hw_if_index,
535  /* ensure all packets go to ethernet-input */
536  ethernet_set_rx_redirect (vnm, sif_hw, 1);
537  }
538 
539  if (bif->mode == BOND_MODE_LACP)
540  {
541  if (bm->lacp_enable_disable)
542  (*bm->lacp_enable_disable) (vm, bif, sif, 1);
543  }
544  else if (sif->port_enabled &&
546  {
548  }
549 
550  vec_foreach_index (thread_index, bm->per_thread_data)
551  {
553  thread_index);
554 
557 
558  vec_foreach_index (sif_if_index, ptd->per_port_queue)
559  {
560  ptd->per_port_queue[sif_if_index].n_buffers = 0;
561  }
562  }
563 
564  args->rv = vnet_feature_enable_disable ("device-input", "bond-input",
565  sif_hw->hw_if_index, 1, 0, 0);
566 
567  if (args->rv)
568  {
569  args->error =
571  "Error encountered on input feature arc enable");
572  }
573 }
574 
575 static clib_error_t *
577  vlib_cli_command_t * cmd)
578 {
579  bond_enslave_args_t args = { 0 };
580  unformat_input_t _line_input, *line_input = &_line_input;
581  vnet_main_t *vnm = vnet_get_main ();
582 
583  /* Get a line of input. */
584  if (!unformat_user (input, unformat_line_input, line_input))
585  return clib_error_return (0, "Missing required arguments.");
586 
587  args.slave = ~0;
588  args.group = ~0;
589  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
590  {
591  if (unformat (line_input, "%U %U",
592  unformat_vnet_sw_interface, vnm, &args.group,
593  unformat_vnet_sw_interface, vnm, &args.slave))
594  ;
595  else if (unformat (line_input, "passive"))
596  args.is_passive = 1;
597  else if (unformat (line_input, "long-timeout"))
598  args.is_long_timeout = 1;
599  else
600  {
601  args.error = clib_error_return (0, "unknown input `%U'",
602  format_unformat_error, input);
603  break;
604  }
605  }
606  unformat_free (line_input);
607 
608  if (args.error)
609  return args.error;
610  if (args.group == ~0)
611  return clib_error_return (0, "Missing bond interface");
612  if (args.slave == ~0)
613  return clib_error_return (0, "please specify valid slave interface name");
614 
615  bond_enslave (vm, &args);
616 
617  return args.error;
618 }
619 
620 /* *INDENT-OFF* */
621 VLIB_CLI_COMMAND (enslave_interface_command, static) = {
622  .path = "bond add",
623  .short_help = "bond add <BondEthernetx> <slave-interface> "
624  "[passive] [long-timeout]",
625  .function = enslave_interface_command_fn,
626 };
627 /* *INDENT-ON* */
628 
629 void
631 {
632  bond_if_t *bif;
633  slave_if_t *sif;
634 
635  sif = bond_get_slave_by_sw_if_index (args->slave);
636  if (!sif)
637  {
638  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
639  args->error = clib_error_return (0, "interface was not enslaved");
640  return;
641  }
643  bond_delete_neighbor (vm, bif, sif);
644 }
645 
646 static clib_error_t *
648  vlib_cli_command_t * cmd)
649 {
650  bond_detach_slave_args_t args = { 0 };
651  unformat_input_t _line_input, *line_input = &_line_input;
652  vnet_main_t *vnm = vnet_get_main ();
653 
654  /* Get a line of input. */
655  if (!unformat_user (input, unformat_line_input, line_input))
656  return clib_error_return (0, "Missing required arguments.");
657 
658  args.slave = ~0;
659  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
660  {
661  if (unformat (line_input, "%U",
662  unformat_vnet_sw_interface, vnm, &args.slave))
663  ;
664  else
665  {
666  args.error = clib_error_return (0, "unknown input `%U'",
667  format_unformat_error, input);
668  break;
669  }
670  }
671  unformat_free (line_input);
672 
673  if (args.error)
674  return args.error;
675  if (args.slave == ~0)
676  return clib_error_return (0, "please specify valid slave interface name");
677 
678  bond_detach_slave (vm, &args);
679 
680  return args.error;
681 }
682 
683 /* *INDENT-OFF* */
684 VLIB_CLI_COMMAND (detach_interface_command, static) = {
685  .path = "bond del",
686  .short_help = "bond del <slave-interface>",
687  .function = detach_interface_command_fn,
688 };
689 /* *INDENT-ON* */
690 
691 static void
693 {
694  bond_main_t *bm = &bond_main;
695  bond_if_t *bif;
696 
697  vlib_cli_output (vm, "%-16s %-12s %-13s %-13s %-14s %s",
698  "interface name", "sw_if_index", "mode",
699  "load balance", "active slaves", "slaves");
700 
701  /* *INDENT-OFF* */
702  pool_foreach (bif, bm->interfaces,
703  ({
704  vlib_cli_output (vm, "%-16U %-12d %-13U %-13U %-14u %u",
705  format_bond_interface_name, bif->dev_instance,
706  bif->sw_if_index, format_bond_mode, bif->mode,
707  format_bond_load_balance, bif->lb,
708  vec_len (bif->active_slaves), vec_len (bif->slaves));
709  }));
710  /* *INDENT-ON* */
711 }
712 
713 static void
715 {
716  bond_main_t *bm = &bond_main;
717  bond_if_t *bif;
718  u32 *sw_if_index;
719 
720  /* *INDENT-OFF* */
721  pool_foreach (bif, bm->interfaces,
722  ({
723  vlib_cli_output (vm, "%U", format_bond_interface_name, bif->dev_instance);
724  vlib_cli_output (vm, " mode: %U",
725  format_bond_mode, bif->mode);
726  vlib_cli_output (vm, " load balance: %U",
727  format_bond_load_balance, bif->lb);
728  if (bif->mode == BOND_MODE_ROUND_ROBIN)
729  vlib_cli_output (vm, " last xmit slave index: %u",
730  bif->lb_rr_last_index);
731  vlib_cli_output (vm, " number of active slaves: %d",
732  vec_len (bif->active_slaves));
733  vec_foreach (sw_if_index, bif->active_slaves)
734  {
735  vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
736  vnet_get_main (), *sw_if_index);
737  }
738  vlib_cli_output (vm, " number of slaves: %d", vec_len (bif->slaves));
739  vec_foreach (sw_if_index, bif->slaves)
740  {
741  vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
742  vnet_get_main (), *sw_if_index);
743  }
744  vlib_cli_output (vm, " device instance: %d", bif->dev_instance);
745  vlib_cli_output (vm, " interface id: %d", bif->id);
746  vlib_cli_output (vm, " sw_if_index: %d", bif->sw_if_index);
747  vlib_cli_output (vm, " hw_if_index: %d", bif->hw_if_index);
748  }));
749  /* *INDENT-ON* */
750 }
751 
752 static clib_error_t *
754  vlib_cli_command_t * cmd)
755 {
756  u8 details = 0;
757 
759  {
760  if (unformat (input, "details"))
761  details = 1;
762  else
763  {
764  return clib_error_return (0, "unknown input `%U'",
765  format_unformat_error, input);
766  }
767  }
768 
769  if (details)
770  show_bond_details (vm);
771  else
772  show_bond (vm);
773 
774  return 0;
775 }
776 
777 /* *INDENT-OFF* */
778 VLIB_CLI_COMMAND (show_bond_command, static) = {
779  .path = "show bond",
780  .short_help = "show bond [details]",
781  .function = show_bond_fn,
782 };
783 /* *INDENT-ON* */
784 
785 clib_error_t *
787 {
788  bond_main_t *bm = &bond_main;
789 
790  bm->vlib_main = vm;
791  bm->vnet_main = vnet_get_main ();
794  vlib_get_thread_main ()->n_vlib_mains - 1,
796 
797  return 0;
798 }
799 
801 
802 /*
803  * fd.io coding-style-patch-verification: ON
804  *
805  * Local Variables:
806  * eval: (c-set-style "gnu")
807  * End:
808  */
u32 sw_if_index
Definition: ipsec_gre.api:37
vnet_main_t * vnet_main
Definition: node.h:342
vmrglw vmrglh hi
u32 dev_instance
Definition: node.h:164
u32 group
Definition: node.h:182
#define vec_foreach_index(var, v)
Iterate over vector indices.
u32 hw_if_index
Definition: node.h:169
static uword unformat_bond_mode(unformat_input_t *input, va_list *args)
Definition: node.h:390
#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:158
static void show_bond_details(vlib_main_t *vm)
Definition: cli.c:714
vlib_node_registration_t bond_process_node
(constructor) VLIB_REGISTER_NODE (bond_process_node)
Definition: device.c:797
int bond_delete_if(vlib_main_t *vm, u32 sw_if_index)
Definition: cli.c:199
#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:47
static vnet_hw_interface_t * vnet_get_sup_hw_interface(vnet_main_t *vnm, u32 sw_if_index)
u8 lb
Definition: node.h:158
static clib_error_t * detach_interface_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:647
vnet_interface_main_t interface_main
Definition: vnet.h:56
clib_error_t * error
Definition: node.h:88
uword * id_used
Definition: node.h:332
int bond_dump_ifs(bond_interface_details_t **out_bondifs)
Definition: cli.c:87
static bond_if_t * bond_get_master_by_sw_if_index(u32 sw_if_index)
Definition: node.h:463
#define NULL
Definition: clib.h:58
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:255
u8 is_long_timeout
Definition: node.h:98
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:98
u8 * last_marker_pkt
Definition: node.h:219
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:983
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:347
unformat_function_t unformat_vnet_sw_interface
static clib_error_t * enslave_interface_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:576
#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:167
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
u8 mode
Definition: node.h:302
void bond_enable_collecting_distributing(vlib_main_t *vm, slave_if_t *sif)
Definition: cli.c:58
unsigned char u8
Definition: types.h:56
bond_per_thread_data_t * per_thread_data
Definition: node.h:351
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:753
f32 ttl_in_seconds
Definition: node.h:198
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
u8 use_custom_mac
Definition: node.h:184
u32 sw_if_index
Definition: node.h:170
vnet_hw_interface_flags_t flags
Definition: interface.h:494
void bond_enslave(vlib_main_t *vm, bond_enslave_args_t *args)
Definition: cli.c:441
#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:341
unsigned int u32
Definition: types.h:88
#define MIN(x, y)
Definition: node.h:31
unformat_function_t unformat_line_input
Definition: format.h:282
static void clib_spinlock_init(clib_spinlock_t *p)
Definition: lock.h:57
u8 * last_rx_pkt
Definition: node.h:216
void ethernet_set_rx_redirect(vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 enable)
Definition: node.c:1941
static clib_error_t * bond_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:341
#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:422
u8 persistent_hw_address[6]
Definition: node.h:192
#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:684
#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:393
bond_if_t * interfaces
Definition: node.h:329
u8 is_long_timeout
Definition: node.h:201
void bond_detach_slave(vlib_main_t *vm, bond_detach_slave_args_t *args)
Definition: cli.c:630
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
u32 * slaves
Definition: node.h:173
u8 is_passive
Definition: node.h:225
u8 mode
Definition: node.h:157
u32 sw_if_index
Definition: node.h:195
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:338
u32 group
Definition: node.h:293
void bond_disable_collecting_distributing(vlib_main_t *vm, slave_if_t *sif)
Definition: cli.c:25
clib_spinlock_t lockp
Definition: node.h:187
#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:692
BOND interface details struct.
Definition: node.h:113
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:155
uword * slave_by_sw_if_index
Definition: node.h:349
uword unformat_ethernet_address(unformat_input_t *input, va_list *args)
Definition: format.c:233
void bond_create_if(vlib_main_t *vm, bond_create_if_args_t *args)
Definition: cli.c:248
u8 lacp_plugin_loaded
Definition: node.h:345
static bond_if_t * bond_get_master_by_dev_instance(u32 dev_instance)
Definition: node.h:477
u32 bif_dev_instance
Definition: node.h:297
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
u32 * active_slaves
Definition: node.h:176
clib_error_t * error
Definition: node.h:101
clib_error_t * error
Definition: node.h:109
#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:504
uword * port_number_bitmap
Definition: node.h:183
u64 uword
Definition: types.h:112
static void unformat_free(unformat_input_t *i)
Definition: format.h:162
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:815
int bond_dump_slave_ifs(slave_interface_details_t **out_slaveifs, u32 bond_sw_if_index)
Definition: cli.c:119
slave interface details struct
Definition: node.h:125
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:335
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:513
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:185
clib_error_t * vnet_hw_interface_change_mac_address(vnet_main_t *vnm, u32 hw_if_index, const u8 *mac_address)
Definition: interface.c:1466
u8 port_enabled
Definition: node.h:239
static slave_if_t * bond_get_slave_by_sw_if_index(u32 sw_if_index)
Definition: node.h:485
lacp_port_info_t actor_admin
Definition: node.h:233
clib_error_t * bond_cli_init(vlib_main_t *vm)
Definition: cli.c:786
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
u8 packet_template_index
Definition: node.h:207
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:762
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:82
u32 hw_if_index
Definition: node.h:222
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
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:170
bond_per_port_queue_t * per_port_queue
Definition: node.h:151
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:372