FD.io VPP  v19.08.3-2-gbabecb413
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 #include <vpp/stats/stat_segment.h>
24 
25 void
27 {
28  bond_main_t *bm = &bond_main;
29  bond_if_t *bif;
30  int i;
31  uword p;
32  vnet_main_t *vnm = vnet_get_main ();
34  u8 switching_active = 0;
35 
39  {
40  p = *vec_elt_at_index (bif->active_slaves, i);
41  if (p == sif->sw_if_index)
42  {
43  if (sif->sw_if_index == bif->sw_if_index_working)
44  {
45  switching_active = 1;
46  if (bif->mode == BOND_MODE_ACTIVE_BACKUP)
47  bif->is_local_numa = 0;
48  }
49  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  if (bif->mode == BOND_MODE_LACP)
101  [sif->sw_if_index], sif->actor.state);
102 }
103 
104 void
106 {
107  bond_if_t *bif;
108  bond_main_t *bm = &bond_main;
109  vnet_main_t *vnm = vnet_get_main ();
111  int i;
112  uword p;
113 
117  {
118  p = *vec_elt_at_index (bif->active_slaves, i);
119  if (p == sif->sw_if_index)
120  goto done;
121  }
122 
123  if ((sif->lacp_enabled && bif->numa_only)
124  && (vm->numa_node == hw->numa_node))
125  {
126  vec_insert_elts (bif->active_slaves, &sif->sw_if_index, 1,
127  bif->n_numa_slaves);
128  bif->n_numa_slaves++;
129  }
130  else
131  {
132  vec_add1 (bif->active_slaves, sif->sw_if_index);
133  }
134 
135  /* First slave becomes active? */
136  if ((vec_len (bif->active_slaves) == 1) &&
137  (bif->mode == BOND_MODE_ACTIVE_BACKUP))
138  {
139  bif->sw_if_index_working = sif->sw_if_index;
140  bif->is_local_numa = (vm->numa_node == hw->numa_node) ? 1 : 0;
143  }
144  else if ((vec_len (bif->active_slaves) > 1)
145  && (bif->mode == BOND_MODE_ACTIVE_BACKUP)
146  && bif->is_local_numa == 0)
147  {
148  if (vm->numa_node == hw->numa_node)
149  {
151  {
152  p = *vec_elt_at_index (bif->active_slaves, 0);
153  if (p == sif->sw_if_index)
154  break;
155 
156  vec_del1 (bif->active_slaves, 0);
157  vec_add1 (bif->active_slaves, p);
158  }
159  bif->sw_if_index_working = sif->sw_if_index;
160  bif->is_local_numa = 1;
162  bond_process_node.index,
164  }
165  }
166 done:
168 
169  if (bif->mode == BOND_MODE_LACP)
171  [sif->sw_if_index], sif->actor.state);
172 }
173 
174 int
176 {
177  vnet_main_t *vnm = vnet_get_main ();
178  bond_main_t *bm = &bond_main;
179  bond_if_t *bif;
181  bond_interface_details_t *r_bondifs = NULL;
182  bond_interface_details_t *bondif = NULL;
183 
184  /* *INDENT-OFF* */
185  pool_foreach (bif, bm->interfaces,
186  vec_add2(r_bondifs, bondif, 1);
187  clib_memset (bondif, 0, sizeof (*bondif));
188  bondif->id = bif->id;
189  bondif->sw_if_index = bif->sw_if_index;
190  hi = vnet_get_hw_interface (vnm, bif->hw_if_index);
191  clib_memcpy(bondif->interface_name, hi->name,
192  MIN (ARRAY_LEN (bondif->interface_name) - 1,
193  vec_len ((const char *) hi->name)));
194  /* enforce by memset() above */
195  ASSERT(0 == bondif->interface_name[ARRAY_LEN (bondif->interface_name) - 1]);
196  bondif->mode = bif->mode;
197  bondif->lb = bif->lb;
198  bondif->numa_only = bif->numa_only;
199  bondif->active_slaves = vec_len (bif->active_slaves);
200  bondif->slaves = vec_len (bif->slaves);
201  );
202  /* *INDENT-ON* */
203 
204  *out_bondifs = r_bondifs;
205 
206  return 0;
207 }
208 
209 int
211  u32 bond_sw_if_index)
212 {
213  vnet_main_t *vnm = vnet_get_main ();
214  bond_if_t *bif;
217  slave_interface_details_t *r_slaveifs = NULL;
218  slave_interface_details_t *slaveif = NULL;
219  u32 *sw_if_index = NULL;
220  slave_if_t *sif;
221 
222  bif = bond_get_master_by_sw_if_index (bond_sw_if_index);
223  if (!bif)
224  return 1;
225 
226  vec_foreach (sw_if_index, bif->slaves)
227  {
228  vec_add2 (r_slaveifs, slaveif, 1);
229  clib_memset (slaveif, 0, sizeof (*slaveif));
230  sif = bond_get_slave_by_sw_if_index (*sw_if_index);
231  if (sif)
232  {
233  sw = vnet_get_sw_interface (vnm, sif->sw_if_index);
234  hi = vnet_get_hw_interface (vnm, sw->hw_if_index);
235  clib_memcpy (slaveif->interface_name, hi->name,
236  MIN (ARRAY_LEN (slaveif->interface_name) - 1,
237  vec_len ((const char *) hi->name)));
238  /* enforce by memset() above */
239  ASSERT (0 ==
240  slaveif->interface_name[ARRAY_LEN (slaveif->interface_name) -
241  1]);
242  slaveif->sw_if_index = sif->sw_if_index;
243  slaveif->is_passive = sif->is_passive;
244  slaveif->is_long_timeout = sif->is_long_timeout;
245  }
246  }
247  *out_slaveifs = r_slaveifs;
248 
249  return 0;
250 }
251 
252 static void
254 {
255  bond_main_t *bm = &bond_main;
256  vnet_main_t *vnm = vnet_get_main ();
257  int i;
258  vnet_hw_interface_t *sif_hw;
259 
260  sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
261 
262  bif->port_number_bitmap =
264  ntohs (sif->actor_admin.port_number) - 1, 0);
265  bm->slave_by_sw_if_index[sif->sw_if_index] = 0;
266  vec_free (sif->last_marker_pkt);
267  vec_free (sif->last_rx_pkt);
268  vec_foreach_index (i, bif->slaves)
269  {
270  uword p = *vec_elt_at_index (bif->slaves, i);
271  if (p == sif->sw_if_index)
272  {
273  vec_del1 (bif->slaves, i);
274  break;
275  }
276  }
277 
279 
280  vnet_feature_enable_disable ("device-input", "bond-input",
281  sif->sw_if_index, 0, 0, 0);
282 
283  /* Put back the old mac */
285  sif->persistent_hw_address);
286 
287  if ((bif->mode == BOND_MODE_LACP) && bm->lacp_enable_disable)
288  (*bm->lacp_enable_disable) (vm, bif, sif, 0);
289 
290  if (bif->mode == BOND_MODE_LACP)
292  (bm->stats[bif->sw_if_index][sif->sw_if_index]);
293 
294  pool_put (bm->neighbors, sif);
295 }
296 
297 int
299 {
300  bond_main_t *bm = &bond_main;
301  vnet_main_t *vnm = vnet_get_main ();
302  bond_if_t *bif;
303  slave_if_t *sif;
305  u32 *sif_sw_if_index;
306  u32 *s_list = 0;
307 
308  hw = vnet_get_sup_hw_interface (vnm, sw_if_index);
309  if (hw == NULL || bond_dev_class.index != hw->dev_class_index)
310  return VNET_API_ERROR_INVALID_SW_IF_INDEX;
311 
313 
314  vec_append (s_list, bif->slaves);
315  vec_foreach (sif_sw_if_index, s_list)
316  {
317  sif = bond_get_slave_by_sw_if_index (*sif_sw_if_index);
318  if (sif)
319  bond_delete_neighbor (vm, bif, sif);
320  }
321  vec_free (s_list);
322 
323  /* bring down the interface */
326 
328 
331  hash_unset (bm->id_used, bif->id);
332  clib_memset (bif, 0, sizeof (*bif));
333  pool_put (bm->interfaces, bif);
334 
335  return 0;
336 }
337 
338 void
340 {
341  bond_main_t *bm = &bond_main;
342  vnet_main_t *vnm = vnet_get_main ();
344  bond_if_t *bif;
345 
346  if ((args->mode == BOND_MODE_LACP) && bm->lacp_plugin_loaded == 0)
347  {
348  args->rv = VNET_API_ERROR_FEATURE_DISABLED;
349  args->error = clib_error_return (0, "LACP plugin is not loaded");
350  return;
351  }
352  if (args->mode > BOND_MODE_LACP || args->mode < BOND_MODE_ROUND_ROBIN)
353  {
354  args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
355  args->error = clib_error_return (0, "Invalid mode");
356  return;
357  }
358  if (args->lb > BOND_LB_L23)
359  {
360  args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
361  args->error = clib_error_return (0, "Invalid load-balance");
362  return;
363  }
364  pool_get (bm->interfaces, bif);
365  clib_memset (bif, 0, sizeof (*bif));
366  bif->dev_instance = bif - bm->interfaces;
367  bif->id = args->id;
368  bif->lb = args->lb;
369  bif->mode = args->mode;
370  bif->gso = args->gso;
371 
372  // Adjust requested interface id
373  if (bif->id == ~0)
374  bif->id = bif->dev_instance;
375  if (hash_get (bm->id_used, bif->id))
376  {
377  args->rv = VNET_API_ERROR_INSTANCE_IN_USE;
378  pool_put (bm->interfaces, bif);
379  return;
380  }
381  hash_set (bm->id_used, bif->id, 1);
382 
383  // Special load-balance mode used for rr and bc
384  if (bif->mode == BOND_MODE_ROUND_ROBIN)
385  bif->lb = BOND_LB_RR;
386  else if (bif->mode == BOND_MODE_BROADCAST)
387  bif->lb = BOND_LB_BC;
388  else if (bif->mode == BOND_MODE_ACTIVE_BACKUP)
389  bif->lb = BOND_LB_AB;
390 
391  bif->use_custom_mac = args->hw_addr_set;
392  if (!args->hw_addr_set)
393  {
394  f64 now = vlib_time_now (vm);
395  u32 rnd;
396  rnd = (u32) (now * 1e6);
397  rnd = random_u32 (&rnd);
398 
399  memcpy (args->hw_addr + 2, &rnd, sizeof (rnd));
400  args->hw_addr[0] = 2;
401  args->hw_addr[1] = 0xfe;
402  }
403  memcpy (bif->hw_address, args->hw_addr, 6);
405  (vnm, bond_dev_class.index, bif->dev_instance /* device instance */ ,
406  bif->hw_address /* ethernet address */ ,
407  &bif->hw_if_index, 0 /* flag change */ );
408 
409  if (args->error)
410  {
411  args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
412  hash_unset (bm->id_used, bif->id);
413  pool_put (bm->interfaces, bif);
414  return;
415  }
416 
417  sw = vnet_get_hw_sw_interface (vnm, bif->hw_if_index);
418  bif->sw_if_index = sw->sw_if_index;
419  bif->group = bif->sw_if_index;
420  bif->numa_only = args->numa_only;
421 
422  /*
423  * Add GSO and Checksum offload flags if GSO is enabled on Bond
424  */
425  if (args->gso)
426  {
428 
431  }
433  clib_spinlock_init (&bif->lockp);
434 
437 
439 
440  // for return
441  args->sw_if_index = bif->sw_if_index;
442  args->rv = 0;
443 }
444 
445 static clib_error_t *
447  vlib_cli_command_t * cmd)
448 {
449  unformat_input_t _line_input, *line_input = &_line_input;
450  bond_create_if_args_t args = { 0 };
451  u8 mode_is_set = 0;
452 
453  /* Get a line of input. */
454  if (!unformat_user (input, unformat_line_input, line_input))
455  return clib_error_return (0, "Missing required arguments.");
456 
457  args.id = ~0;
458  args.mode = -1;
459  args.lb = BOND_LB_L2;
460  args.rv = -1;
461  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
462  {
463  if (unformat (line_input, "mode %U", unformat_bond_mode, &args.mode))
464  mode_is_set = 1;
465  else if (((args.mode == BOND_MODE_LACP) || (args.mode == BOND_MODE_XOR))
466  && unformat (line_input, "load-balance %U",
468  ;
469  else if (unformat (line_input, "hw-addr %U",
471  args.hw_addr_set = 1;
472  else if (unformat (line_input, "id %u", &args.id))
473  ;
474  else if (unformat (line_input, "gso"))
475  args.gso = 1;
476  else if (unformat (line_input, "numa-only"))
477  {
478  if (args.mode == BOND_MODE_LACP)
479  args.numa_only = 1;
480  else
481  return clib_error_return (0,
482  "Only lacp mode supports numa-only so far!");
483  }
484  else
485  return clib_error_return (0, "unknown input `%U'",
486  format_unformat_error, input);
487  }
488  unformat_free (line_input);
489 
490  if (mode_is_set == 0)
491  return clib_error_return (0, "Missing bond mode");
492 
493  bond_create_if (vm, &args);
494 
495  if (!args.rv)
497  vnet_get_main (), args.sw_if_index);
498 
499  return args.error;
500 }
501 
502 /* *INDENT-OFF* */
503 VLIB_CLI_COMMAND (bond_create_command, static) = {
504  .path = "create bond",
505  .short_help = "create bond mode {round-robin | active-backup | broadcast | "
506  "{lacp | xor} [load-balance { l2 | l23 | l34 } [numa-only]]} "
507  "[hw-addr <mac-address>] [id <if-id>] [gso]",
508  .function = bond_create_command_fn,
509 };
510 /* *INDENT-ON* */
511 
512 static clib_error_t *
514  vlib_cli_command_t * cmd)
515 {
516  unformat_input_t _line_input, *line_input = &_line_input;
517  u32 sw_if_index = ~0;
518  vnet_main_t *vnm = vnet_get_main ();
519  int rv;
520 
521  /* Get a line of input. */
522  if (!unformat_user (input, unformat_line_input, line_input))
523  return clib_error_return (0, "Missing <interface>");
524 
525  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
526  {
527  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
528  ;
529  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
530  vnm, &sw_if_index))
531  ;
532  else
533  return clib_error_return (0, "unknown input `%U'",
534  format_unformat_error, input);
535  }
536  unformat_free (line_input);
537 
538  if (sw_if_index == ~0)
539  return clib_error_return (0,
540  "please specify interface name or sw_if_index");
541 
542  rv = bond_delete_if (vm, sw_if_index);
543  if (rv == VNET_API_ERROR_INVALID_SW_IF_INDEX)
544  return clib_error_return (0, "not a bond interface");
545  else if (rv != 0)
546  return clib_error_return (0, "error on deleting bond interface");
547 
548  return 0;
549 }
550 
551 /* *INDENT-OFF* */
552 VLIB_CLI_COMMAND (bond_delete__command, static) =
553 {
554  .path = "delete bond",
555  .short_help = "delete bond {<interface> | sw_if_index <sw_idx>}",
556  .function = bond_delete_command_fn,
557 };
558 /* *INDENT-ON* */
559 
560 void
562 {
563  bond_main_t *bm = &bond_main;
564  vnet_main_t *vnm = vnet_get_main ();
565  bond_if_t *bif;
566  slave_if_t *sif;
568  vnet_hw_interface_t *bif_hw, *sif_hw;
570  u32 thread_index;
571  u32 sif_if_index;
572 
574  if (!bif)
575  {
576  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
577  args->error = clib_error_return (0, "bond interface not found");
578  return;
579  }
580  // make sure the interface is not already enslaved
582  {
583  args->rv = VNET_API_ERROR_VALUE_EXIST;
584  args->error = clib_error_return (0, "interface was already enslaved");
585  return;
586  }
587  sif_hw = vnet_get_sup_hw_interface (vnm, args->slave);
588  if (sif_hw->dev_class_index == bond_dev_class.index)
589  {
590  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
591  args->error =
592  clib_error_return (0, "bond interface cannot be enslaved");
593  return;
594  }
595  if (bif->gso && !(sif_hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO))
596  {
597  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
598  args->error =
599  clib_error_return (0, "slave interface is not gso capable");
600  return;
601  }
602  if (bif->mode == BOND_MODE_LACP)
603  {
604  u8 *name = format (0, "/if/lacp/%u/%u/state%c", bif->sw_if_index,
605  args->slave, 0);
606 
607  vec_validate (bm->stats, bif->sw_if_index);
608  vec_validate (bm->stats[bif->sw_if_index], args->slave);
609 
611  (name, &bm->stats[bif->sw_if_index][args->slave]);
612  vec_free (name);
613  if (args->error != 0)
614  {
615  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
616  return;
617  }
618  }
619 
620  pool_get (bm->neighbors, sif);
621  clib_memset (sif, 0, sizeof (*sif));
622  sw = pool_elt_at_index (im->sw_interfaces, args->slave);
623  /* port_enabled is both admin up and hw link up */
625  sif->sw_if_index = sw->sw_if_index;
626  sif->hw_if_index = sw->hw_if_index;
627  sif->packet_template_index = (u8) ~ 0;
628  sif->is_passive = args->is_passive;
629  sif->group = args->group;
630  sif->bif_dev_instance = bif->dev_instance;
631  sif->mode = bif->mode;
632 
633  sif->is_long_timeout = args->is_long_timeout;
634  if (args->is_long_timeout)
636  else
638 
641  /*
642  * sif - bm->neighbors may be 0
643  * Left shift it by 1 bit to distinguish the valid entry that we actually
644  * store from the null entries
645  */
647  (uword) (((sif - bm->neighbors) << 1) | 1);
648  vec_add1 (bif->slaves, sif->sw_if_index);
649 
650  sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
651 
652  /* Save the old mac */
653  memcpy (sif->persistent_hw_address, sif_hw->hw_address, 6);
654  bif_hw = vnet_get_sup_hw_interface (vnm, bif->sw_if_index);
655  if (bif->use_custom_mac)
656  {
658  bif->hw_address);
659  }
660  else
661  {
662  // bond interface gets the mac address from the first slave
663  if (vec_len (bif->slaves) == 1)
664  {
665  memcpy (bif->hw_address, sif_hw->hw_address, 6);
667  sif_hw->hw_address);
668  }
669  else
670  {
671  // subsequent slaves gets the mac address of the bond interface
673  bif->hw_address);
674  }
675  }
676 
677  if (bif_hw->l2_if_count)
678  ethernet_set_flags (vnm, sif_hw->hw_if_index,
680  else
681  ethernet_set_flags (vnm, sif_hw->hw_if_index,
682  /*ETHERNET_INTERFACE_FLAG_DEFAULT_L3 */ 0);
683 
684  if (bif->mode == BOND_MODE_LACP)
685  {
686  if (bm->lacp_enable_disable)
687  (*bm->lacp_enable_disable) (vm, bif, sif, 1);
688  }
689  else if (sif->port_enabled)
690  {
692  }
693 
694  vec_foreach_index (thread_index, bm->per_thread_data)
695  {
697  thread_index);
698 
701 
702  vec_foreach_index (sif_if_index, ptd->per_port_queue)
703  {
704  ptd->per_port_queue[sif_if_index].n_buffers = 0;
705  }
706  }
707 
708  args->rv = vnet_feature_enable_disable ("device-input", "bond-input",
709  sif->sw_if_index, 1, 0, 0);
710 
711  if (args->rv)
712  {
713  args->error =
715  "Error encountered on input feature arc enable");
716  }
717 }
718 
719 static clib_error_t *
721  vlib_cli_command_t * cmd)
722 {
723  bond_enslave_args_t args = { 0 };
724  unformat_input_t _line_input, *line_input = &_line_input;
725  vnet_main_t *vnm = vnet_get_main ();
726 
727  /* Get a line of input. */
728  if (!unformat_user (input, unformat_line_input, line_input))
729  return clib_error_return (0, "Missing required arguments.");
730 
731  args.slave = ~0;
732  args.group = ~0;
733  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
734  {
735  if (unformat (line_input, "%U %U",
736  unformat_vnet_sw_interface, vnm, &args.group,
737  unformat_vnet_sw_interface, vnm, &args.slave))
738  ;
739  else if (unformat (line_input, "passive"))
740  args.is_passive = 1;
741  else if (unformat (line_input, "long-timeout"))
742  args.is_long_timeout = 1;
743  else
744  {
745  args.error = clib_error_return (0, "unknown input `%U'",
746  format_unformat_error, input);
747  break;
748  }
749  }
750  unformat_free (line_input);
751 
752  if (args.error)
753  return args.error;
754  if (args.group == ~0)
755  return clib_error_return (0, "Missing bond interface");
756  if (args.slave == ~0)
757  return clib_error_return (0, "please specify valid slave interface name");
758 
759  bond_enslave (vm, &args);
760 
761  return args.error;
762 }
763 
764 /* *INDENT-OFF* */
765 VLIB_CLI_COMMAND (enslave_interface_command, static) = {
766  .path = "bond add",
767  .short_help = "bond add <BondEthernetx> <slave-interface> "
768  "[passive] [long-timeout]",
769  .function = enslave_interface_command_fn,
770 };
771 /* *INDENT-ON* */
772 
773 void
775 {
776  bond_if_t *bif;
777  slave_if_t *sif;
778 
779  sif = bond_get_slave_by_sw_if_index (args->slave);
780  if (!sif)
781  {
782  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
783  args->error = clib_error_return (0, "interface was not enslaved");
784  return;
785  }
787  bond_delete_neighbor (vm, bif, sif);
788 }
789 
790 static clib_error_t *
792  vlib_cli_command_t * cmd)
793 {
794  bond_detach_slave_args_t args = { 0 };
795  unformat_input_t _line_input, *line_input = &_line_input;
796  vnet_main_t *vnm = vnet_get_main ();
797 
798  /* Get a line of input. */
799  if (!unformat_user (input, unformat_line_input, line_input))
800  return clib_error_return (0, "Missing required arguments.");
801 
802  args.slave = ~0;
803  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
804  {
805  if (unformat (line_input, "%U",
806  unformat_vnet_sw_interface, vnm, &args.slave))
807  ;
808  else
809  {
810  args.error = clib_error_return (0, "unknown input `%U'",
811  format_unformat_error, input);
812  break;
813  }
814  }
815  unformat_free (line_input);
816 
817  if (args.error)
818  return args.error;
819  if (args.slave == ~0)
820  return clib_error_return (0, "please specify valid slave interface name");
821 
822  bond_detach_slave (vm, &args);
823 
824  return args.error;
825 }
826 
827 /* *INDENT-OFF* */
828 VLIB_CLI_COMMAND (detach_interface_command, static) = {
829  .path = "bond del",
830  .short_help = "bond del <slave-interface>",
831  .function = detach_interface_command_fn,
832 };
833 /* *INDENT-ON* */
834 
835 static void
837 {
838  bond_main_t *bm = &bond_main;
839  bond_if_t *bif;
840 
841  vlib_cli_output (vm, "%-16s %-12s %-13s %-13s %-14s %s",
842  "interface name", "sw_if_index", "mode",
843  "load balance", "active slaves", "slaves");
844 
845  /* *INDENT-OFF* */
846  pool_foreach (bif, bm->interfaces,
847  ({
848  vlib_cli_output (vm, "%-16U %-12d %-13U %-13U %-14u %u",
849  format_bond_interface_name, bif->dev_instance,
850  bif->sw_if_index, format_bond_mode, bif->mode,
851  format_bond_load_balance, bif->lb,
852  vec_len (bif->active_slaves), vec_len (bif->slaves));
853  }));
854  /* *INDENT-ON* */
855 }
856 
857 static void
859 {
860  bond_main_t *bm = &bond_main;
861  bond_if_t *bif;
862  u32 *sw_if_index;
863 
864  /* *INDENT-OFF* */
865  pool_foreach (bif, bm->interfaces,
866  ({
867  vlib_cli_output (vm, "%U", format_bond_interface_name, bif->dev_instance);
868  vlib_cli_output (vm, " mode: %U",
869  format_bond_mode, bif->mode);
870  vlib_cli_output (vm, " load balance: %U",
871  format_bond_load_balance, bif->lb);
872  if (bif->gso)
873  vlib_cli_output (vm, " gso enable");
874  if (bif->mode == BOND_MODE_ROUND_ROBIN)
875  vlib_cli_output (vm, " last xmit slave index: %u",
876  bif->lb_rr_last_index);
877  vlib_cli_output (vm, " number of active slaves: %d",
878  vec_len (bif->active_slaves));
879  vec_foreach (sw_if_index, bif->active_slaves)
880  {
881  vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
882  vnet_get_main (), *sw_if_index);
883  }
884  vlib_cli_output (vm, " number of slaves: %d", vec_len (bif->slaves));
885  vec_foreach (sw_if_index, bif->slaves)
886  {
887  vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
888  vnet_get_main (), *sw_if_index);
889  }
890  vlib_cli_output (vm, " device instance: %d", bif->dev_instance);
891  vlib_cli_output (vm, " interface id: %d", bif->id);
892  vlib_cli_output (vm, " sw_if_index: %d", bif->sw_if_index);
893  vlib_cli_output (vm, " hw_if_index: %d", bif->hw_if_index);
894  }));
895  /* *INDENT-ON* */
896 }
897 
898 static clib_error_t *
900  vlib_cli_command_t * cmd)
901 {
902  u8 details = 0;
903 
905  {
906  if (unformat (input, "details"))
907  details = 1;
908  else
909  {
910  return clib_error_return (0, "unknown input `%U'",
911  format_unformat_error, input);
912  }
913  }
914 
915  if (details)
916  show_bond_details (vm);
917  else
918  show_bond (vm);
919 
920  return 0;
921 }
922 
923 /* *INDENT-OFF* */
924 VLIB_CLI_COMMAND (show_bond_command, static) = {
925  .path = "show bond",
926  .short_help = "show bond [details]",
927  .function = show_bond_fn,
928 };
929 /* *INDENT-ON* */
930 
931 clib_error_t *
933 {
934  bond_main_t *bm = &bond_main;
935 
936  bm->vlib_main = vm;
937  bm->vnet_main = vnet_get_main ();
940  vlib_get_thread_main ()->n_vlib_mains - 1,
942 
943  return 0;
944 }
945 
947 
948 /*
949  * fd.io coding-style-patch-verification: ON
950  *
951  * Local Variables:
952  * eval: (c-set-style "gnu")
953  * End:
954  */
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:439
vnet_main_t * vnet_main
Definition: node.h:359
static uword vnet_sw_interface_is_up(vnet_main_t *vnm, u32 sw_if_index)
vmrglw vmrglh hi
u8 gso
Definition: node.h:194
u32 dev_instance
Definition: node.h:172
u32 group
Definition: node.h:199
#define vec_foreach_index(var, v)
Iterate over vector indices.
u32 hw_if_index
Definition: node.h:177
static uword unformat_bond_mode(unformat_input_t *input, va_list *args)
Definition: node.h:409
#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:253
static void show_bond_details(vlib_main_t *vm)
Definition: cli.c:858
vlib_node_registration_t bond_process_node
(constructor) VLIB_REGISTER_NODE (bond_process_node)
Definition: device.c:788
int bond_delete_if(vlib_main_t *vm, u32 sw_if_index)
Definition: cli.c:298
#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:161
static clib_error_t * detach_interface_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:791
vnet_interface_main_t interface_main
Definition: vnet.h:56
clib_error_t * error
Definition: node.h:90
uword * id_used
Definition: node.h:349
int bond_dump_ifs(bond_interface_details_t **out_bondifs)
Definition: cli.c:175
static bond_if_t * bond_get_master_by_sw_if_index(u32 sw_if_index)
Definition: node.h:482
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:279
static_always_inline void clib_spinlock_unlock_if_init(clib_spinlock_t *p)
Definition: lock.h:110
u8 * last_marker_pkt
Definition: node.h:236
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
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
lacp_enable_disable_func lacp_enable_disable
Definition: node.h:364
unformat_function_t unformat_vnet_sw_interface
u32 numa_node
Definition: main.h:220
static clib_error_t * enslave_interface_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:720
#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:175
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
u8 mode
Definition: node.h:319
void bond_enable_collecting_distributing(vlib_main_t *vm, slave_if_t *sif)
Definition: cli.c:105
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:368
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:899
f32 ttl_in_seconds
Definition: node.h:215
u8 numa_only
Definition: node.h:193
u8 is_local_numa
Definition: node.h:165
#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:201
u32 sw_if_index
Definition: node.h:178
lacp_port_info_t actor
Definition: node.h:246
vnet_hw_interface_flags_t flags
Definition: interface.h:506
void bond_enslave(vlib_main_t *vm, bond_enslave_args_t *args)
Definition: cli.c:561
#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:358
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:63
u8 * last_rx_pkt
Definition: node.h:233
static clib_error_t * bond_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:446
#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:441
u8 persistent_hw_address[6]
Definition: node.h:209
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
#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:513
bond_if_t * interfaces
Definition: node.h:346
u8 name[64]
Definition: memclnt.api:152
u8 is_long_timeout
Definition: node.h:218
void bond_detach_slave(vlib_main_t *vm, bond_detach_slave_args_t *args)
Definition: cli.c:774
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
u32 * slaves
Definition: node.h:181
u8 is_passive
Definition: node.h:242
u8 mode
Definition: node.h:160
word n_numa_slaves
Definition: node.h:197
u32 sw_if_index
Definition: node.h:212
vlib_main_t * vm
Definition: buffer.c:323
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
uword * bond_by_sw_if_index
Definition: node.h:355
u32 group
Definition: node.h:310
void bond_disable_collecting_distributing(vlib_main_t *vm, slave_if_t *sif)
Definition: cli.c:26
clib_spinlock_t lockp
Definition: node.h:204
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL
Definition: ethernet.h:141
#define ARRAY_LEN(x)
Definition: clib.h:63
static void show_bond(vlib_main_t *vm)
Definition: cli.c:836
BOND interface details struct.
Definition: node.h:115
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:161
uword * slave_by_sw_if_index
Definition: node.h:366
clib_error_t * stat_segment_deregister_state_counter(u32 index)
Definition: stat_segment.c:941
u32 sw_if_index_working
Definition: node.h:167
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:339
u8 lacp_plugin_loaded
Definition: node.h:362
static bond_if_t * bond_get_master_by_dev_instance(u32 dev_instance)
Definition: node.h:496
#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:314
#define vec_append(v1, v2)
Append v2 after v1.
Definition: vec.h:818
#define clib_bitmap_free(v)
Free a bitmap.
Definition: bitmap.h:92
u32 * active_slaves
Definition: node.h:184
clib_error_t * error
Definition: node.h:103
clib_error_t * error
Definition: node.h:111
u8 lacp_enabled
Definition: node.h:262
#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:492
uword * port_number_bitmap
Definition: node.h:200
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:837
int bond_dump_slave_ifs(slave_interface_details_t **out_slaveifs, u32 bond_sw_if_index)
Definition: cli.c:210
slave interface details struct
Definition: node.h:128
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:352
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:501
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:202
u32 ** stats
Definition: node.h:370
clib_error_t * vnet_hw_interface_change_mac_address(vnet_main_t *vnm, u32 hw_if_index, const u8 *mac_address)
Definition: interface.c:1487
u8 port_enabled
Definition: node.h:256
static slave_if_t * bond_get_slave_by_sw_if_index(u32 sw_if_index)
Definition: node.h:504
lacp_port_info_t actor_admin
Definition: node.h:250
clib_error_t * bond_cli_init(vlib_main_t *vm)
Definition: cli.c:932
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
u8 packet_template_index
Definition: node.h:224
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:772
static_always_inline void clib_spinlock_lock_if_init(clib_spinlock_t *p)
Definition: lock.h:95
u32 hw_if_index
Definition: node.h:239
clib_error_t * stat_segment_register_state_counter(u8 *name, u32 *index)
Definition: stat_segment.c:906
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
void stat_segment_set_state_counter(u32 index, u64 value)
Definition: stat_segment.c:969
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:275
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
bond_per_port_queue_t * per_port_queue
Definition: node.h:154
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:372