FD.io VPP  v19.08.1-401-g8e4ed521a
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;
346 
347  if ((args->mode == BOND_MODE_LACP) && bm->lacp_plugin_loaded == 0)
348  {
349  args->rv = VNET_API_ERROR_FEATURE_DISABLED;
350  args->error = clib_error_return (0, "LACP plugin is not loaded");
351  return;
352  }
353  if (args->mode > BOND_MODE_LACP || args->mode < BOND_MODE_ROUND_ROBIN)
354  {
355  args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
356  args->error = clib_error_return (0, "Invalid mode");
357  return;
358  }
359  if (args->lb > BOND_LB_L23)
360  {
361  args->rv = VNET_API_ERROR_INVALID_ARGUMENT;
362  args->error = clib_error_return (0, "Invalid load-balance");
363  return;
364  }
365  pool_get (bm->interfaces, bif);
366  clib_memset (bif, 0, sizeof (*bif));
367  bif->dev_instance = bif - bm->interfaces;
368  bif->id = args->id;
369  bif->lb = args->lb;
370  bif->mode = args->mode;
371  bif->gso = args->gso;
372 
373  // Adjust requested interface id
374  if (bif->id == ~0)
375  bif->id = bif->dev_instance;
376  if (hash_get (bm->id_used, bif->id))
377  {
378  args->rv = VNET_API_ERROR_INSTANCE_IN_USE;
379  pool_put (bm->interfaces, bif);
380  return;
381  }
382  hash_set (bm->id_used, bif->id, 1);
383 
384  // Special load-balance mode used for rr and bc
385  if (bif->mode == BOND_MODE_ROUND_ROBIN)
386  bif->lb = BOND_LB_RR;
387  else if (bif->mode == BOND_MODE_BROADCAST)
388  bif->lb = BOND_LB_BC;
389  else if (bif->mode == BOND_MODE_ACTIVE_BACKUP)
390  bif->lb = BOND_LB_AB;
391 
392  bif->use_custom_mac = args->hw_addr_set;
393  if (!args->hw_addr_set)
394  {
395  f64 now = vlib_time_now (vm);
396  u32 rnd;
397  rnd = (u32) (now * 1e6);
398  rnd = random_u32 (&rnd);
399 
400  memcpy (args->hw_addr + 2, &rnd, sizeof (rnd));
401  args->hw_addr[0] = 2;
402  args->hw_addr[1] = 0xfe;
403  }
404  memcpy (bif->hw_address, args->hw_addr, 6);
406  (vnm, bond_dev_class.index, bif->dev_instance /* device instance */ ,
407  bif->hw_address /* ethernet address */ ,
408  &bif->hw_if_index, 0 /* flag change */ );
409 
410  if (args->error)
411  {
412  args->rv = VNET_API_ERROR_INVALID_REGISTRATION;
413  hash_unset (bm->id_used, bif->id);
414  pool_put (bm->interfaces, bif);
415  return;
416  }
417 
418  sw = vnet_get_hw_sw_interface (vnm, bif->hw_if_index);
419  bif->sw_if_index = sw->sw_if_index;
420  bif->group = bif->sw_if_index;
421  bif->numa_only = args->numa_only;
422 
423  hw = vnet_get_hw_interface (vnm, bif->hw_if_index);
427  clib_spinlock_init (&bif->lockp);
428 
431 
433 
434  // for return
435  args->sw_if_index = bif->sw_if_index;
436  args->rv = 0;
437 }
438 
439 static clib_error_t *
441  vlib_cli_command_t * cmd)
442 {
443  unformat_input_t _line_input, *line_input = &_line_input;
444  bond_create_if_args_t args = { 0 };
445  u8 mode_is_set = 0;
446 
447  /* Get a line of input. */
448  if (!unformat_user (input, unformat_line_input, line_input))
449  return clib_error_return (0, "Missing required arguments.");
450 
451  args.id = ~0;
452  args.mode = -1;
453  args.lb = BOND_LB_L2;
454  args.rv = -1;
455  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
456  {
457  if (unformat (line_input, "mode %U", unformat_bond_mode, &args.mode))
458  mode_is_set = 1;
459  else if (((args.mode == BOND_MODE_LACP) || (args.mode == BOND_MODE_XOR))
460  && unformat (line_input, "load-balance %U",
462  ;
463  else if (unformat (line_input, "hw-addr %U",
465  args.hw_addr_set = 1;
466  else if (unformat (line_input, "id %u", &args.id))
467  ;
468  else if (unformat (line_input, "gso"))
469  args.gso = 1;
470  else if (unformat (line_input, "numa-only"))
471  {
472  if (args.mode == BOND_MODE_LACP)
473  args.numa_only = 1;
474  else
475  return clib_error_return (0,
476  "Only lacp mode supports numa-only so far!");
477  }
478  else
479  return clib_error_return (0, "unknown input `%U'",
480  format_unformat_error, input);
481  }
482  unformat_free (line_input);
483 
484  if (mode_is_set == 0)
485  return clib_error_return (0, "Missing bond mode");
486 
487  bond_create_if (vm, &args);
488 
489  if (!args.rv)
491  vnet_get_main (), args.sw_if_index);
492 
493  return args.error;
494 }
495 
496 /* *INDENT-OFF* */
497 VLIB_CLI_COMMAND (bond_create_command, static) = {
498  .path = "create bond",
499  .short_help = "create bond mode {round-robin | active-backup | broadcast | "
500  "{lacp | xor} [load-balance { l2 | l23 | l34 } [numa-only]]} "
501  "[hw-addr <mac-address>] [id <if-id>] [gso]",
502  .function = bond_create_command_fn,
503 };
504 /* *INDENT-ON* */
505 
506 static clib_error_t *
508  vlib_cli_command_t * cmd)
509 {
510  unformat_input_t _line_input, *line_input = &_line_input;
511  u32 sw_if_index = ~0;
512  vnet_main_t *vnm = vnet_get_main ();
513  int rv;
514 
515  /* Get a line of input. */
516  if (!unformat_user (input, unformat_line_input, line_input))
517  return clib_error_return (0, "Missing <interface>");
518 
519  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
520  {
521  if (unformat (line_input, "sw_if_index %d", &sw_if_index))
522  ;
523  else if (unformat (line_input, "%U", unformat_vnet_sw_interface,
524  vnm, &sw_if_index))
525  ;
526  else
527  return clib_error_return (0, "unknown input `%U'",
528  format_unformat_error, input);
529  }
530  unformat_free (line_input);
531 
532  if (sw_if_index == ~0)
533  return clib_error_return (0,
534  "please specify interface name or sw_if_index");
535 
536  rv = bond_delete_if (vm, sw_if_index);
537  if (rv == VNET_API_ERROR_INVALID_SW_IF_INDEX)
538  return clib_error_return (0, "not a bond interface");
539  else if (rv != 0)
540  return clib_error_return (0, "error on deleting bond interface");
541 
542  return 0;
543 }
544 
545 /* *INDENT-OFF* */
546 VLIB_CLI_COMMAND (bond_delete__command, static) =
547 {
548  .path = "delete bond",
549  .short_help = "delete bond {<interface> | sw_if_index <sw_idx>}",
550  .function = bond_delete_command_fn,
551 };
552 /* *INDENT-ON* */
553 
554 void
556 {
557  bond_main_t *bm = &bond_main;
558  vnet_main_t *vnm = vnet_get_main ();
559  bond_if_t *bif;
560  slave_if_t *sif;
562  vnet_hw_interface_t *bif_hw, *sif_hw;
564  u32 thread_index;
565  u32 sif_if_index;
566 
568  if (!bif)
569  {
570  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
571  args->error = clib_error_return (0, "bond interface not found");
572  return;
573  }
574  // make sure the interface is not already enslaved
576  {
577  args->rv = VNET_API_ERROR_VALUE_EXIST;
578  args->error = clib_error_return (0, "interface was already enslaved");
579  return;
580  }
581  sif_hw = vnet_get_sup_hw_interface (vnm, args->slave);
582  if (sif_hw->dev_class_index == bond_dev_class.index)
583  {
584  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
585  args->error =
586  clib_error_return (0, "bond interface cannot be enslaved");
587  return;
588  }
589  if (bif->gso && !(sif_hw->flags & VNET_HW_INTERFACE_FLAG_SUPPORTS_GSO))
590  {
591  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
592  args->error =
593  clib_error_return (0, "slave interface is not gso capable");
594  return;
595  }
596  if (bif->mode == BOND_MODE_LACP)
597  {
598  u8 *name = format (0, "/if/lacp/%u/%u/state%c", bif->sw_if_index,
599  args->slave, 0);
600 
601  vec_validate (bm->stats, bif->sw_if_index);
602  vec_validate (bm->stats[bif->sw_if_index], args->slave);
603 
605  (name, &bm->stats[bif->sw_if_index][args->slave]);
606  vec_free (name);
607  if (args->error != 0)
608  {
609  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
610  return;
611  }
612  }
613 
614  pool_get (bm->neighbors, sif);
615  clib_memset (sif, 0, sizeof (*sif));
616  sw = pool_elt_at_index (im->sw_interfaces, args->slave);
617  /* port_enabled is both admin up and hw link up */
619  sif->sw_if_index = sw->sw_if_index;
620  sif->hw_if_index = sw->hw_if_index;
621  sif->packet_template_index = (u8) ~ 0;
622  sif->is_passive = args->is_passive;
623  sif->group = args->group;
624  sif->bif_dev_instance = bif->dev_instance;
625  sif->mode = bif->mode;
626 
627  sif->is_long_timeout = args->is_long_timeout;
628  if (args->is_long_timeout)
630  else
632 
635  /*
636  * sif - bm->neighbors may be 0
637  * Left shift it by 1 bit to distinguish the valid entry that we actually
638  * store from the null entries
639  */
641  (uword) (((sif - bm->neighbors) << 1) | 1);
642  vec_add1 (bif->slaves, sif->sw_if_index);
643 
644  sif_hw = vnet_get_sup_hw_interface (vnm, sif->sw_if_index);
645 
646  /* Save the old mac */
647  memcpy (sif->persistent_hw_address, sif_hw->hw_address, 6);
648  bif_hw = vnet_get_sup_hw_interface (vnm, bif->sw_if_index);
649  if (bif->use_custom_mac)
650  {
652  bif->hw_address);
653  }
654  else
655  {
656  // bond interface gets the mac address from the first slave
657  if (vec_len (bif->slaves) == 1)
658  {
659  memcpy (bif->hw_address, sif_hw->hw_address, 6);
661  sif_hw->hw_address);
662  }
663  else
664  {
665  // subsequent slaves gets the mac address of the bond interface
667  bif->hw_address);
668  }
669  }
670 
671  if (bif_hw->l2_if_count)
672  {
673  ethernet_set_flags (vnm, sif_hw->hw_if_index,
675  /* ensure all packets go to ethernet-input */
676  ethernet_set_rx_redirect (vnm, sif_hw, 1);
677  }
678 
679  if (bif->mode == BOND_MODE_LACP)
680  {
681  if (bm->lacp_enable_disable)
682  (*bm->lacp_enable_disable) (vm, bif, sif, 1);
683  }
684  else if (sif->port_enabled)
685  {
687  }
688 
689  vec_foreach_index (thread_index, bm->per_thread_data)
690  {
692  thread_index);
693 
696 
697  vec_foreach_index (sif_if_index, ptd->per_port_queue)
698  {
699  ptd->per_port_queue[sif_if_index].n_buffers = 0;
700  }
701  }
702 
703  args->rv = vnet_feature_enable_disable ("device-input", "bond-input",
704  sif->sw_if_index, 1, 0, 0);
705 
706  if (args->rv)
707  {
708  args->error =
710  "Error encountered on input feature arc enable");
711  }
712 }
713 
714 static clib_error_t *
716  vlib_cli_command_t * cmd)
717 {
718  bond_enslave_args_t args = { 0 };
719  unformat_input_t _line_input, *line_input = &_line_input;
720  vnet_main_t *vnm = vnet_get_main ();
721 
722  /* Get a line of input. */
723  if (!unformat_user (input, unformat_line_input, line_input))
724  return clib_error_return (0, "Missing required arguments.");
725 
726  args.slave = ~0;
727  args.group = ~0;
728  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
729  {
730  if (unformat (line_input, "%U %U",
731  unformat_vnet_sw_interface, vnm, &args.group,
732  unformat_vnet_sw_interface, vnm, &args.slave))
733  ;
734  else if (unformat (line_input, "passive"))
735  args.is_passive = 1;
736  else if (unformat (line_input, "long-timeout"))
737  args.is_long_timeout = 1;
738  else
739  {
740  args.error = clib_error_return (0, "unknown input `%U'",
741  format_unformat_error, input);
742  break;
743  }
744  }
745  unformat_free (line_input);
746 
747  if (args.error)
748  return args.error;
749  if (args.group == ~0)
750  return clib_error_return (0, "Missing bond interface");
751  if (args.slave == ~0)
752  return clib_error_return (0, "please specify valid slave interface name");
753 
754  bond_enslave (vm, &args);
755 
756  return args.error;
757 }
758 
759 /* *INDENT-OFF* */
760 VLIB_CLI_COMMAND (enslave_interface_command, static) = {
761  .path = "bond add",
762  .short_help = "bond add <BondEthernetx> <slave-interface> "
763  "[passive] [long-timeout]",
764  .function = enslave_interface_command_fn,
765 };
766 /* *INDENT-ON* */
767 
768 void
770 {
771  bond_if_t *bif;
772  slave_if_t *sif;
773 
774  sif = bond_get_slave_by_sw_if_index (args->slave);
775  if (!sif)
776  {
777  args->rv = VNET_API_ERROR_INVALID_INTERFACE;
778  args->error = clib_error_return (0, "interface was not enslaved");
779  return;
780  }
782  bond_delete_neighbor (vm, bif, sif);
783 }
784 
785 static clib_error_t *
787  vlib_cli_command_t * cmd)
788 {
789  bond_detach_slave_args_t args = { 0 };
790  unformat_input_t _line_input, *line_input = &_line_input;
791  vnet_main_t *vnm = vnet_get_main ();
792 
793  /* Get a line of input. */
794  if (!unformat_user (input, unformat_line_input, line_input))
795  return clib_error_return (0, "Missing required arguments.");
796 
797  args.slave = ~0;
798  while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
799  {
800  if (unformat (line_input, "%U",
801  unformat_vnet_sw_interface, vnm, &args.slave))
802  ;
803  else
804  {
805  args.error = clib_error_return (0, "unknown input `%U'",
806  format_unformat_error, input);
807  break;
808  }
809  }
810  unformat_free (line_input);
811 
812  if (args.error)
813  return args.error;
814  if (args.slave == ~0)
815  return clib_error_return (0, "please specify valid slave interface name");
816 
817  bond_detach_slave (vm, &args);
818 
819  return args.error;
820 }
821 
822 /* *INDENT-OFF* */
823 VLIB_CLI_COMMAND (detach_interface_command, static) = {
824  .path = "bond del",
825  .short_help = "bond del <slave-interface>",
826  .function = detach_interface_command_fn,
827 };
828 /* *INDENT-ON* */
829 
830 static void
832 {
833  bond_main_t *bm = &bond_main;
834  bond_if_t *bif;
835 
836  vlib_cli_output (vm, "%-16s %-12s %-13s %-13s %-14s %s",
837  "interface name", "sw_if_index", "mode",
838  "load balance", "active slaves", "slaves");
839 
840  /* *INDENT-OFF* */
841  pool_foreach (bif, bm->interfaces,
842  ({
843  vlib_cli_output (vm, "%-16U %-12d %-13U %-13U %-14u %u",
844  format_bond_interface_name, bif->dev_instance,
845  bif->sw_if_index, format_bond_mode, bif->mode,
846  format_bond_load_balance, bif->lb,
847  vec_len (bif->active_slaves), vec_len (bif->slaves));
848  }));
849  /* *INDENT-ON* */
850 }
851 
852 static void
854 {
855  bond_main_t *bm = &bond_main;
856  bond_if_t *bif;
857  u32 *sw_if_index;
858 
859  /* *INDENT-OFF* */
860  pool_foreach (bif, bm->interfaces,
861  ({
862  vlib_cli_output (vm, "%U", format_bond_interface_name, bif->dev_instance);
863  vlib_cli_output (vm, " mode: %U",
864  format_bond_mode, bif->mode);
865  vlib_cli_output (vm, " load balance: %U",
866  format_bond_load_balance, bif->lb);
867  if (bif->gso)
868  vlib_cli_output (vm, " gso enable");
869  if (bif->mode == BOND_MODE_ROUND_ROBIN)
870  vlib_cli_output (vm, " last xmit slave index: %u",
871  bif->lb_rr_last_index);
872  vlib_cli_output (vm, " number of active slaves: %d",
873  vec_len (bif->active_slaves));
874  vec_foreach (sw_if_index, bif->active_slaves)
875  {
876  vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
877  vnet_get_main (), *sw_if_index);
878  }
879  vlib_cli_output (vm, " number of slaves: %d", vec_len (bif->slaves));
880  vec_foreach (sw_if_index, bif->slaves)
881  {
882  vlib_cli_output (vm, " %U", format_vnet_sw_if_index_name,
883  vnet_get_main (), *sw_if_index);
884  }
885  vlib_cli_output (vm, " device instance: %d", bif->dev_instance);
886  vlib_cli_output (vm, " interface id: %d", bif->id);
887  vlib_cli_output (vm, " sw_if_index: %d", bif->sw_if_index);
888  vlib_cli_output (vm, " hw_if_index: %d", bif->hw_if_index);
889  }));
890  /* *INDENT-ON* */
891 }
892 
893 static clib_error_t *
895  vlib_cli_command_t * cmd)
896 {
897  u8 details = 0;
898 
900  {
901  if (unformat (input, "details"))
902  details = 1;
903  else
904  {
905  return clib_error_return (0, "unknown input `%U'",
906  format_unformat_error, input);
907  }
908  }
909 
910  if (details)
911  show_bond_details (vm);
912  else
913  show_bond (vm);
914 
915  return 0;
916 }
917 
918 /* *INDENT-OFF* */
919 VLIB_CLI_COMMAND (show_bond_command, static) = {
920  .path = "show bond",
921  .short_help = "show bond [details]",
922  .function = show_bond_fn,
923 };
924 /* *INDENT-ON* */
925 
926 clib_error_t *
928 {
929  bond_main_t *bm = &bond_main;
930 
931  bm->vlib_main = vm;
932  bm->vnet_main = vnet_get_main ();
935  vlib_get_thread_main ()->n_vlib_mains - 1,
937 
938  return 0;
939 }
940 
942 
943 /*
944  * fd.io coding-style-patch-verification: ON
945  *
946  * Local Variables:
947  * eval: (c-set-style "gnu")
948  * End:
949  */
#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:853
vlib_node_registration_t bond_process_node
(constructor) VLIB_REGISTER_NODE (bond_process_node)
Definition: device.c:792
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:786
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
#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: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:715
#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:894
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:555
#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
void ethernet_set_rx_redirect(vnet_main_t *vnm, vnet_hw_interface_t *hi, u32 enable)
Definition: node.c:1958
static clib_error_t * bond_create_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: cli.c:440
#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:507
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:769
#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:62
static void show_bond(vlib_main_t *vm)
Definition: cli.c:831
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:833
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:1477
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:927
#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:796
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:854
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