FD.io VPP  v16.09
Vector Packet Processing
interface_cli.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  * interface_cli.c: interface CLI
17  *
18  * Copyright (c) 2008 Eliot Dresselhaus
19  *
20  * Permission is hereby granted, free of charge, to any person obtaining
21  * a copy of this software and associated documentation files (the
22  * "Software"), to deal in the Software without restriction, including
23  * without limitation the rights to use, copy, modify, merge, publish,
24  * distribute, sublicense, and/or sell copies of the Software, and to
25  * permit persons to whom the Software is furnished to do so, subject to
26  * the following conditions:
27  *
28  * The above copyright notice and this permission notice shall be
29  * included in all copies or substantial portions of the Software.
30  *
31  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38  */
39 
40 /**
41  * @file
42  * Interface CLI.
43  */
44 
45 #include <vnet/vnet.h>
46 #include <vnet/ip/ip.h>
47 #include <vppinfra/bitmap.h>
48 
49 static int
50 compare_interface_names (void *a1, void *a2)
51 {
52  u32 *hi1 = a1;
53  u32 *hi2 = a2;
54 
55  return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
56 }
57 
58 static clib_error_t *
60  unformat_input_t * input,
61  vlib_cli_command_t * cmd)
62 {
63  clib_error_t *error = 0;
64  vnet_main_t *vnm = vnet_get_main ();
67  u32 hw_if_index, *hw_if_indices = 0;
68  int i, verbose = -1, is_show, show_bond = 0;
69 
70  is_show = strstr (cmd->path, "show") != 0;
72  {
73  /* See if user wants to show a specific interface. */
74  if (unformat
75  (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
76  vec_add1 (hw_if_indices, hw_if_index);
77 
78  /* See if user wants to show an interface with a specific hw_if_index. */
79  else if (unformat (input, "%u", &hw_if_index))
80  vec_add1 (hw_if_indices, hw_if_index);
81 
82  else if (unformat (input, "verbose"))
83  verbose = 1; /* this is also the default */
84 
85  else if (unformat (input, "detail"))
86  verbose = 2;
87 
88  else if (unformat (input, "brief"))
89  verbose = 0;
90 
91  else if (unformat (input, "bond"))
92  {
93  show_bond = 1;
94  if (verbose < 0)
95  verbose = 0; /* default to brief for link bonding */
96  }
97 
98  else
99  {
100  error = clib_error_return (0, "unknown input `%U'",
101  format_unformat_error, input);
102  goto done;
103  }
104  }
105 
106  /* Gather interfaces. */
107  if (vec_len (hw_if_indices) == 0)
108  pool_foreach (hi, im->hw_interfaces,
109  vec_add1 (hw_if_indices, hi - im->hw_interfaces));
110 
111  if (verbose < 0)
112  verbose = 1; /* default to verbose (except bond) */
113 
114  if (is_show)
115  {
116  /* Sort by name. */
118 
119  vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
120  for (i = 0; i < vec_len (hw_if_indices); i++)
121  {
122  hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
123  if (show_bond == 0) /* show all interfaces */
124  vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
125  hi, verbose);
126  else if ((hi->bond_info) &&
128  { /* show only bonded interface and all its slave interfaces */
129  int hw_idx;
130  vnet_hw_interface_t *shi;
131  vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
132  hi, verbose);
133 
134  /* *INDENT-OFF* */
135  clib_bitmap_foreach (hw_idx, hi->bond_info,
136  ({
137  shi = vnet_get_hw_interface(vnm, hw_idx);
138  vlib_cli_output (vm, "%U\n",
139  format_vnet_hw_interface, vnm, shi, verbose);
140  }));
141  /* *INDENT-ON* */
142  }
143  }
144  }
145  else
146  {
147  for (i = 0; i < vec_len (hw_if_indices); i++)
148  {
150 
151  hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
153 
154  if (dc->clear_counters)
155  dc->clear_counters (hi->dev_instance);
156  }
157  }
158 
159 done:
160  vec_free (hw_if_indices);
161  return error;
162 }
163 
164 /* *INDENT-OFF* */
165 /*?
166  * Displays various information about the state of the current terminal
167  * session.
168  *
169  * @cliexpar
170  * @cliexstart{show hardware}
171  * Name Link Hardware
172  * GigabitEthernet2/0/0 up GigabitEthernet2/0/0
173  * Ethernet address 00:50:56:b7:7c:83
174  * Intel 82545em_copper
175  * link up, media 1000T full-duplex, master,
176  * 0 unprocessed, 384 total buffers on rx queue 0 ring
177  * 237 buffers in driver rx cache
178  * rx total packets 1816
179  * rx total bytes 181084
180  * rx good packets 1816
181  * rx good bytes 181084
182  * rx 65 127 byte packets 1586
183  * rx 256 511 byte packets 230
184  * tx total packets 346
185  * tx total bytes 90224
186  * tx good packets 346
187  * tx good bytes 88840
188  * tx 64 byte packets 1
189  * tx 65 127 byte packets 115
190  * tx 256 511 byte packets 230
191  * @cliexend
192  ?*/
193 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
194  .path = "show hardware-interfaces",
195  .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] [<if-name1> <if-name2> ...]",
196  .function = show_or_clear_hw_interfaces,
197 };
198 /* *INDENT-ON* */
199 
200 /* *INDENT-OFF* */
201 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
202  .path = "clear hardware-interfaces",
203  .short_help = "Clear hardware interfaces statistics",
204  .function = show_or_clear_hw_interfaces,
205 };
206 /* *INDENT-ON* */
207 
208 static int
209 sw_interface_name_compare (void *a1, void *a2)
210 {
211  vnet_sw_interface_t *si1 = a1;
212  vnet_sw_interface_t *si2 = a2;
213 
215  si1->sw_if_index, si2->sw_if_index);
216 }
217 
218 static clib_error_t *
220  unformat_input_t * input, vlib_cli_command_t * cmd)
221 {
222  clib_error_t *error = 0;
223  vnet_main_t *vnm = vnet_get_main ();
225  vnet_sw_interface_t *si, *sorted_sis = 0;
226  u8 show_addresses = 0;
227 
229  {
230  u32 sw_if_index;
231 
232  /* See if user wants to show specific interface */
233  if (unformat
234  (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
235  {
236  si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
237  vec_add1 (sorted_sis, si[0]);
238  }
239  else if (unformat (input, "address") || unformat (input, "addr"))
240  show_addresses = 1;
241  else
242  {
243  error = clib_error_return (0, "unknown input `%U'",
244  format_unformat_error, input);
245  goto done;
246  }
247  }
248 
249  if (!show_addresses)
250  vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
251 
252  if (vec_len (sorted_sis) == 0) /* Get all interfaces */
253  {
254  /* Gather interfaces. */
255  sorted_sis =
257  _vec_len (sorted_sis) = 0;
258  pool_foreach (si, im->sw_interfaces, (
259  {
260  vec_add1 (sorted_sis, si[0]);
261  }
262  ));
263 
264  /* Sort by name. */
266  }
267 
268  if (show_addresses)
269  {
270  vec_foreach (si, sorted_sis)
271  {
273  ip4_main_t *im4 = &ip4_main;
274  ip6_main_t *im6 = &ip6_main;
275  ip_lookup_main_t *lm4 = &im4->lookup_main;
276  ip_lookup_main_t *lm6 = &im6->lookup_main;
277  ip_interface_address_t *ia = 0;
278  ip4_address_t *r4;
279  ip6_address_t *r6;
280  u32 fib_index4 = 0, fib_index6 = 0;
281  ip4_fib_t *fib4;
282  ip6_fib_t *fib6;
283  l2_input_config_t *config;
284 
286  fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
287  si->sw_if_index);
288 
290  fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
291  si->sw_if_index);
292 
293  fib4 = vec_elt_at_index (im4->fibs, fib_index4);
294  fib6 = vec_elt_at_index (im6->fibs, fib_index6);
295 
298  (vm, "%U (%s): \n unnumbered, use %U",
300  vnm, si->sw_if_index,
301  (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
303 
304  else
305  {
306  vlib_cli_output (vm, "%U (%s):",
308  vnm, si->sw_if_index,
310  ? "up" : "dn");
311  }
312 
313  /* Display any L2 addressing info */
314  vec_validate (l2m->configs, si->sw_if_index);
315  config = vec_elt_at_index (l2m->configs, si->sw_if_index);
316  if (config->bridge)
317  {
318  u32 bd_id = l2input_main.bd_configs[config->bd_index].bd_id;
319  vlib_cli_output (vm, " l2 bridge bd_id %d%s%d", bd_id,
320  config->bvi ? " bvi shg " : " shg ",
321  config->shg);
322  }
323  else if (config->xconnect)
324  {
325  vlib_cli_output (vm, " l2 xconnect %U",
327  vnm, config->output_sw_if_index);
328  }
329 
330  /* Display any IP4 addressing info */
331  /* *INDENT-OFF* */
333  1 /* honor unnumbered */,
334  ({
335  r4 = ip_interface_address_get_address (lm4, ia);
336  if (fib4->table_id)
337  {
338  vlib_cli_output (vm, " %U/%d table %d",
339  format_ip4_address, r4,
340  ia->address_length,
341  fib4->table_id);
342  }
343  else
344  {
345  vlib_cli_output (vm, " %U/%d",
346  format_ip4_address, r4,
347  ia->address_length);
348  }
349  }));
350  /* *INDENT-ON* */
351 
352  /* Display any IP6 addressing info */
353  /* *INDENT-OFF* */
355  1 /* honor unnumbered */,
356  ({
357  r6 = ip_interface_address_get_address (lm6, ia);
358  if (fib6->table_id)
359  {
360  vlib_cli_output (vm, " %U/%d table %d",
361  format_ip6_address, r6,
362  ia->address_length,
363  fib6->table_id);
364  }
365  else
366  {
367  vlib_cli_output (vm, " %U/%d",
368  format_ip6_address, r6,
369  ia->address_length);
370  }
371  }));
372  /* *INDENT-ON* */
373  }
374  }
375  else
376  {
377  vec_foreach (si, sorted_sis)
378  {
379  vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
380  }
381  }
382 
383 done:
384  vec_free (sorted_sis);
385  return error;
386 }
387 
388 /* *INDENT-OFF* */
389 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
390  .path = "show interfaces",
391  .short_help = "show interfaces [address|addr] [<if-name1> <if-name2> ...]",
392  .function = show_sw_interfaces,
393 };
394 /* *INDENT-ON* */
395 
396 /* Root of all interface commands. */
397 /* *INDENT-OFF* */
398 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
399  .path = "interface",
400  .short_help = "Interface commands",
401 };
402 /* *INDENT-ON* */
403 
404 /* *INDENT-OFF* */
405 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
406  .path = "set interface",
407  .short_help = "Interface commands",
408 };
409 /* *INDENT-ON* */
410 
411 static clib_error_t *
413  unformat_input_t * input, vlib_cli_command_t * cmd)
414 {
415  vnet_main_t *vnm = vnet_get_main ();
419  static vnet_main_t **my_vnet_mains;
420  int i, j, n_counters;
421 
422  vec_reset_length (my_vnet_mains);
423 
424  for (i = 0; i < vec_len (vnet_mains); i++)
425  {
426  if (vnet_mains[i])
427  vec_add1 (my_vnet_mains, vnet_mains[i]);
428  }
429 
430  if (vec_len (vnet_mains) == 0)
431  vec_add1 (my_vnet_mains, vnm);
432 
433  n_counters = vec_len (im->combined_sw_if_counters);
434 
435  for (j = 0; j < n_counters; j++)
436  {
437  for (i = 0; i < vec_len (my_vnet_mains); i++)
438  {
439  im = &my_vnet_mains[i]->interface_main;
440  cm = im->combined_sw_if_counters + j;
442  }
443  }
444 
445  n_counters = vec_len (im->sw_if_counters);
446 
447  for (j = 0; j < n_counters; j++)
448  {
449  for (i = 0; i < vec_len (my_vnet_mains); i++)
450  {
451  im = &my_vnet_mains[i]->interface_main;
452  sm = im->sw_if_counters + j;
454  }
455  }
456 
457  return 0;
458 }
459 
460 /* *INDENT-OFF* */
461 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
462  .path = "clear interfaces",
463  .short_help = "Clear interfaces statistics",
464  .function = clear_interface_counters,
465 };
466 /* *INDENT-ON* */
467 
468 /**
469  * Parse subinterface names.
470  *
471  * The following subinterface syntax is supported. The first two are for
472  * backwards compatability:
473  *
474  * <intf-name> <id>
475  * - a subinterface with the name <intf-name>.<id>. The subinterface
476  * is a single dot1q vlan with vlan id <id> and exact-match semantics.
477  *
478  * <intf-name> <min_id>-<max_id>
479  * - a set of the above subinterfaces, repeating for each id
480  * in the range <min_id> to <max_id>
481  *
482  * In the following, exact-match semantics (i.e. the number of vlan tags on the
483  * packet must match the number of tags in the configuration) are used only if
484  * the keyword exact-match is present. Non-exact match is the default.
485  *
486  * <intf-name> <id> dot1q <outer_id> [exact-match]
487  * - a subinterface with the name <intf-name>.<id>. The subinterface
488  * is a single dot1q vlan with vlan id <outer_id>.
489  *
490  * <intf-name> <id> dot1q any [exact-match]
491  * - a subinterface with the name <intf-name>.<id>. The subinterface
492  * is a single dot1q vlan with any vlan id.
493  *
494  * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
495  * - a subinterface with the name <intf-name>.<id>. The subinterface
496  * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
497  * <inner_id>.
498  *
499  * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
500  * - a subinterface with the name <intf-name>.<id>. The subinterface
501  * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
502  *
503  * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
504  *
505  * - a subinterface with the name <intf-name>.<id>. The subinterface
506  * is a double dot1q vlan with any outer vlan id and any inner vlan id.
507  *
508  * For each of the above CLI, there is a duplicate that uses the keyword
509  * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
510  * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
511  * tagged packets the inner ethertype is always 0x8100. Also note that
512  * the dot1q and dot1ad naming spaces are independent, so it is legal to
513  * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
514  *
515  * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
516  * - a subinterface with the name <intf-name>.<id>. The subinterface
517  * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
518  * id <inner_id>.
519  *
520  * <intf-name> <id> untagged
521  * - a subinterface with the name <intf-name>.<id>. The subinterface
522  * has no vlan tags. Only one can be specified per interface.
523  *
524  * <intf-name> <id> default
525  * - a subinterface with the name <intf-name>.<id>. This is associated
526  * with a packet that did not match any other configured subinterface
527  * on this interface. Only one can be specified per interface.
528  */
529 
530 static clib_error_t *
532  vnet_sw_interface_t * template)
533 {
534  clib_error_t *error = 0;
535  u32 inner_vlan, outer_vlan;
536 
537  if (unformat (input, "any inner-dot1q any"))
538  {
539  template->sub.eth.flags.two_tags = 1;
540  template->sub.eth.flags.outer_vlan_id_any = 1;
541  template->sub.eth.flags.inner_vlan_id_any = 1;
542  }
543  else if (unformat (input, "any"))
544  {
545  template->sub.eth.flags.one_tag = 1;
546  template->sub.eth.flags.outer_vlan_id_any = 1;
547  }
548  else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
549  {
550  template->sub.eth.flags.two_tags = 1;
551  template->sub.eth.flags.inner_vlan_id_any = 1;
552  template->sub.eth.outer_vlan_id = outer_vlan;
553  }
554  else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
555  {
556  template->sub.eth.flags.two_tags = 1;
557  template->sub.eth.outer_vlan_id = outer_vlan;
558  template->sub.eth.inner_vlan_id = inner_vlan;
559  }
560  else if (unformat (input, "%d", &outer_vlan))
561  {
562  template->sub.eth.flags.one_tag = 1;
563  template->sub.eth.outer_vlan_id = outer_vlan;
564  }
565  else
566  {
567  error = clib_error_return (0, "expected dot1q config, got `%U'",
568  format_unformat_error, input);
569  goto done;
570  }
571 
573  {
574  if (unformat (input, "exact-match"))
575  {
576  template->sub.eth.flags.exact_match = 1;
577  }
578  }
579 
580 done:
581  return error;
582 }
583 
584 static clib_error_t *
586  unformat_input_t * input, vlib_cli_command_t * cmd)
587 {
588  vnet_main_t *vnm = vnet_get_main ();
589  clib_error_t *error = 0;
590  u32 hw_if_index, sw_if_index;
592  u32 id, id_min, id_max;
593  vnet_sw_interface_t template;
594 
595  hw_if_index = ~0;
596  if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
597  {
598  error = clib_error_return (0, "unknown interface `%U'",
599  format_unformat_error, input);
600  goto done;
601  }
602 
603  memset (&template, 0, sizeof (template));
604  template.sub.eth.raw_flags = 0;
605 
606  if (unformat (input, "%d default", &id_min))
607  {
608  id_max = id_min;
609  template.sub.eth.flags.default_sub = 1;
610  }
611  else if (unformat (input, "%d untagged", &id_min))
612  {
613  id_max = id_min;
614  template.sub.eth.flags.no_tags = 1;
615  template.sub.eth.flags.exact_match = 1;
616  }
617  else if (unformat (input, "%d dot1q", &id_min))
618  {
619  /* parse dot1q config */
620  id_max = id_min;
621  error = parse_vlan_sub_interfaces (input, &template);
622  if (error)
623  goto done;
624  }
625  else if (unformat (input, "%d dot1ad", &id_min))
626  {
627  /* parse dot1ad config */
628  id_max = id_min;
629  template.sub.eth.flags.dot1ad = 1;
630  error = parse_vlan_sub_interfaces (input, &template);
631  if (error)
632  goto done;
633  }
634  else if (unformat (input, "%d-%d", &id_min, &id_max))
635  {
636  template.sub.eth.flags.one_tag = 1;
637  template.sub.eth.outer_vlan_id = id_min;
638  template.sub.eth.flags.exact_match = 1;
639  if (id_min > id_max)
640  goto id_error;
641  }
642  else if (unformat (input, "%d", &id_min))
643  {
644  id_max = id_min;
645  template.sub.eth.flags.one_tag = 1;
646  template.sub.eth.outer_vlan_id = id_min;
647  template.sub.eth.flags.exact_match = 1;
648  }
649  else
650  {
651  id_error:
652  error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
653  format_unformat_error, input);
654  goto done;
655  }
656 
657  hi = vnet_get_hw_interface (vnm, hw_if_index);
658 
660  {
661  error =
663  "not allowed as %v belong to a BondEthernet interface",
664  hi->name);
665  goto done;
666  }
667 
668  for (id = id_min; id <= id_max; id++)
669  {
670  uword *p;
672  u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
673  u64 *kp;
674 
675  p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
676  if (p)
677  {
678  if (CLIB_DEBUG > 0)
679  clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
680  hi->sw_if_index, id);
681  continue;
682  }
683 
684  kp = clib_mem_alloc (sizeof (*kp));
685  *kp = sup_and_sub_key;
686 
687  template.type = VNET_SW_INTERFACE_TYPE_SUB;
688  template.sup_sw_if_index = hi->sw_if_index;
689  template.sub.id = id;
690  error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
691  if (error)
692  goto done;
693 
694  hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
695  hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
697  vnet_get_main (), sw_if_index);
698  }
699 
700 done:
701  return error;
702 }
703 
704 /* *INDENT-OFF* */
705 /*?
706  * Create vlan subinterfaces
707  *
708  * @cliexpar
709  * @cliexstart{create sub-interfaces}
710  *
711  * To create a vlan subinterface 11 to process packets on 802.1q VLAN id 11, use:
712  *
713  * vpp# create sub GigabitEthernet2/0/0 11
714  *
715  * This shorthand is equivalent to:
716  * vpp# create sub GigabitEthernet2/0/0 11 dot1q 11 exact-match
717  *
718  * You can specify a subinterface number that is different from the vlan id:
719  * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100
720  *
721  * You can create qinq and q-in-any interfaces:
722  * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200
723  * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any
724  *
725  * You can also create dot1ad interfaces:
726  * vpp# create sub GigabitEthernet2/0/0 11 dot1ad 11
727  * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q 200
728  *
729  * Subinterfaces can be configured as either exact-match or non-exact match.
730  * Non-exact match is the CLI default. If exact-match is specified,
731  * packets must have the same number of vlan tags as the configuration.
732  * For non-exact-match, packets must at least that number of tags.
733  * L3 (routed) interfaces must be configured as exact-match.
734  * L2 interfaces are typically configured as non-exact-match.
735  *
736  * For example, a packet with outer vlan 100 and inner 200 would match this interface:
737  * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100
738  *
739  * but would not match this interface:
740  * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100 exact-match
741  *
742  * There are two special subinterfaces that can be configured. Subinterface untagged has no vlan tags:
743  * vpp# create sub GigabitEthernet2/0/0 5 untagged
744  *
745  * The subinterface default matches any packet that does not match any other subinterface:
746  * vpp# create sub GigabitEthernet2/0/0 7 default
747  * @cliexend
748  ?*/
749 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
750  .path = "create sub-interfaces",
751  .short_help = "create sub-interfaces <nn>[-<nn>] [dot1q|dot1ad|default|untagged]",
752  .function = create_sub_interfaces,
753 };
754 /* *INDENT-ON* */
755 
756 static clib_error_t *
758  unformat_input_t * input, vlib_cli_command_t * cmd)
759 {
760  vnet_main_t *vnm = vnet_get_main ();
761  clib_error_t *error;
762  u32 sw_if_index, flags;
763 
764  sw_if_index = ~0;
765  if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
766  {
767  error = clib_error_return (0, "unknown interface `%U'",
768  format_unformat_error, input);
769  goto done;
770  }
771 
772  if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
773  {
774  error = clib_error_return (0, "unknown flags `%U'",
775  format_unformat_error, input);
776  goto done;
777  }
778 
779  error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
780  if (error)
781  goto done;
782 
783 done:
784  return error;
785 }
786 
787 
788 /* *INDENT-OFF* */
789 /*?
790  * Interface admin up/down
791  *
792  * @cliexpar
793  * @cliexstart{set interface state}
794  * vpp# set interface state GigabitEthernet2/0/0 up
795  * vpp# set interface state GigabitEthernet2/0/0 down
796  * @cliexend
797  ?*/
798 VLIB_CLI_COMMAND (set_state_command, static) = {
799  .path = "set interface state",
800  .short_help = "Set interface state",
801  .function = set_state,
802 };
803 /* *INDENT-ON* */
804 
805 static clib_error_t *
807  unformat_input_t * input, vlib_cli_command_t * cmd)
808 {
809  vnet_main_t *vnm = vnet_get_main ();
810  u32 unnumbered_sw_if_index;
811  u32 inherit_from_sw_if_index;
813  int is_set = 0;
814  int is_del = 0;
815 
817  {
818 
819  if (unformat (input, "%U use %U",
820  unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
822  &inherit_from_sw_if_index))
823  is_set = 1;
824  else if (unformat (input, "del %U",
826  vnm, &unnumbered_sw_if_index))
827  is_del = 1;
828  else
829  {
830  if (is_set || is_del)
831  break;
832  else
833  return clib_error_return
834  (0, "parse error '%U'", format_unformat_error, input);
835  }
836  }
837 
838  si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
839  if (is_del)
840  {
842  si->unnumbered_sw_if_index = (u32) ~ 0;
843  }
844  else
845  {
847  si->unnumbered_sw_if_index = inherit_from_sw_if_index;
848  }
849 
850  return 0;
851 }
852 
853 /* *INDENT-OFF* */
854 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
855  .path = "set interface unnumbered",
856  .short_help = "set interface unnumbered [<intfc> use <intfc>][del <intfc>]",
857  .function = set_unnumbered,
858 };
859 /* *INDENT-ON* */
860 
861 
862 
863 static clib_error_t *
865  unformat_input_t * input, vlib_cli_command_t * cmd)
866 {
867  vnet_main_t *vnm = vnet_get_main ();
869  clib_error_t *error;
870  u32 hw_if_index, hw_class_index;
871 
872  hw_if_index = ~0;
873  if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
874  {
875  error = clib_error_return (0, "unknown hardware interface `%U'",
876  format_unformat_error, input);
877  goto done;
878  }
879 
880  if (!unformat_user (input, unformat_hash_string,
881  im->hw_interface_class_by_name, &hw_class_index))
882  {
883  error = clib_error_return (0, "unknown hardware class `%U'",
884  format_unformat_error, input);
885  goto done;
886  }
887 
888  error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
889  if (error)
890  goto done;
891 
892 done:
893  return error;
894 }
895 
896 /* *INDENT-OFF* */
897 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
898  .path = "set interface hw-class",
899  .short_help = "Set interface hardware class",
900  .function = set_hw_class,
901 };
902 /* *INDENT-ON* */
903 
904 static clib_error_t *
906 {
907  return 0;
908 }
909 
911 
912 static clib_error_t *
914  unformat_input_t * input,
915  vlib_cli_command_t * cmd)
916 {
917  u32 hw_if_index;
918  u32 new_dev_instance;
919  vnet_main_t *vnm = vnet_get_main ();
920  int rv;
921 
922  if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
923  return clib_error_return (0, "unknown hardware interface `%U'",
924  format_unformat_error, input);
925 
926  if (!unformat (input, "%d", &new_dev_instance))
927  return clib_error_return (0, "new dev instance missing");
928 
929  rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
930 
931  switch (rv)
932  {
933  case 0:
934  break;
935 
936  default:
937  return clib_error_return (0, "vnet_interface_name_renumber returned %d",
938  rv);
939 
940  }
941 
942  return 0;
943 }
944 
945 
946 /* *INDENT-OFF* */
947 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
948  .path = "renumber interface",
949  .short_help = "renumber interface <if-name> <new-dev-instance>",
950  .function = renumber_interface_command_fn,
951 };
952 /* *INDENT-ON* */
953 
954 static clib_error_t *
956  unformat_input_t * input, vlib_cli_command_t * cmd)
957 {
958  vnet_main_t *vnm = vnet_get_main ();
959  u32 hw_if_index;
963 
964  if (unformat (input, "on %U",
965  unformat_vnet_hw_interface, vnm, &hw_if_index))
966  ;
967  else if (unformat (input, "off %U",
968  unformat_ethernet_interface, vnm, &hw_if_index))
969  flags = 0;
970  else
971  return clib_error_return (0, "unknown input `%U'",
972  format_unformat_error, input);
973 
974  eif = ethernet_get_interface (em, hw_if_index);
975  if (!eif)
976  return clib_error_return (0, "not supported");
977 
978  ethernet_set_flags (vnm, hw_if_index, flags);
979  return 0;
980 }
981 
982 /* *INDENT-OFF* */
983 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
984  .path = "set interface promiscuous",
985  .short_help = "set interface promiscuous [on | off] <intfc>",
986  .function = promiscuous_cmd,
987 };
988 /* *INDENT-ON* */
989 
990 static clib_error_t *
992 {
993  vnet_main_t *vnm = vnet_get_main ();
994  u32 hw_if_index, mtu;
997 
998  if (unformat (input, "%d %U", &mtu,
999  unformat_vnet_hw_interface, vnm, &hw_if_index))
1000  {
1001  vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1002  ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1003 
1004  if (!eif)
1005  return clib_error_return (0, "not supported");
1006 
1007  if (mtu < hi->min_supported_packet_bytes)
1008  return clib_error_return (0, "Invalid mtu (%d): "
1009  "must be >= min pkt bytes (%d)", mtu,
1011 
1012  if (mtu > hi->max_supported_packet_bytes)
1013  return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1015 
1016  if (hi->max_packet_bytes != mtu)
1017  {
1018  hi->max_packet_bytes = mtu;
1019  ethernet_set_flags (vnm, hw_if_index, flags);
1020  }
1021  }
1022  else
1023  return clib_error_return (0, "unknown input `%U'",
1024  format_unformat_error, input);
1025  return 0;
1026 }
1027 
1028 /* *INDENT-OFF* */
1029 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1030  .path = "set interface mtu",
1031  .short_help = "set interface mtu <value> <intfc>",
1032  .function = mtu_cmd,
1033 };
1034 /* *INDENT-ON* */
1035 
1036 /*
1037  * fd.io coding-style-patch-verification: ON
1038  *
1039  * Local Variables:
1040  * eval: (c-set-style "gnu")
1041  * End:
1042  */
unformat_function_t unformat_vnet_hw_interface
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:396
#define foreach_ip_interface_address(lm, a, sw_if_index, loop, body)
Definition: lookup.h:622
static clib_error_t * clear_interface_counters(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define VNET_SW_INTERFACE_FLAG_UNNUMBERED
Definition: interface.h:422
vmrglw vmrglh hi
format_function_t format_vnet_sw_interface
static clib_error_t * create_sub_interfaces(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define hash_set(h, key, value)
Definition: hash.h:254
l2_input_config_t * configs
Definition: l2_input.h:66
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:343
static clib_error_t * promiscuous_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
static clib_error_t * set_hw_class(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
static int sw_interface_name_compare(void *a1, void *a2)
static clib_error_t * set_state(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
unformat_function_t unformat_hash_string
Definition: hash.h:670
vnet_interface_main_t interface_main
Definition: vnet.h:64
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
vnet_main_t ** vnet_mains
Definition: vnet.h:84
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
Definition: vec.h:482
word vnet_sw_interface_compare(vnet_main_t *vnm, uword sw_if_index0, uword sw_if_index1)
Definition: interface.c:1031
int vnet_interface_name_renumber(u32 sw_if_index, u32 new_show_dev_instance)
Definition: interface.c:1151
static clib_error_t * renumber_interface_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define hash_set_mem(h, key, value)
Definition: hash.h:274
ip_lookup_main_t lookup_main
Definition: ip4.h:115
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
uword * sub_interface_sw_if_index_by_id
Definition: interface.h:348
u32 * fib_index_by_sw_if_index
Table index indexed by software interface.
Definition: ip4.h:123
unformat_function_t unformat_vnet_sw_interface
struct _vnet_device_class vnet_device_class_t
format_function_t format_vnet_sw_if_index_name
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
ethernet_main_t ethernet_main
Definition: ethernet.h:241
vnet_main_t * vnet_get_main(void)
Definition: misc.c:45
format_function_t format_vnet_hw_interface
uword flags
Definition: error.h:83
void vlib_clear_combined_counters(vlib_combined_counter_main_t *cm)
Clear a collection of combined counters.
Definition: counter.c:67
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:348
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
u32 output_sw_if_index
Definition: l2_input.h:35
#define vec_new(T, N)
Create new vector of given type and length (unspecified alignment, no header).
Definition: vec.h:270
vlib_combined_counter_main_t * combined_sw_if_counters
Definition: interface.h:501
static clib_error_t * parse_vlan_sub_interfaces(unformat_input_t *input, vnet_sw_interface_t *template)
Parse subinterface names.
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define clib_warning(format, args...)
Definition: error.h:59
unsigned long u64
Definition: types.h:89
uword unformat_user(unformat_input_t *input, unformat_function_t *func,...)
Definition: unformat.c:977
static clib_error_t * set_unnumbered(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
A collection of simple counters.
Definition: counter.h:59
ip6_fib_t * fibs
Definition: ip6.h:118
static clib_error_t * mtu_cmd(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
u32 max_supported_packet_bytes
Definition: interface.h:331
vnet_hw_interface_t * hw_interfaces
Definition: interface.h:478
#define clib_bitmap_foreach(i, ai, body)
Macro to iterate across set bits in a bitmap.
Definition: bitmap.h:361
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:369
uword * sw_if_index_by_sup_and_sub
Definition: interface.h:495
static clib_error_t * show_sw_interfaces(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
vlib_simple_counter_main_t * sw_if_counters
Definition: interface.h:500
word vnet_hw_interface_compare(vnet_main_t *vnm, uword hw_if_index0, uword hw_if_index1)
Definition: interface.c:1045
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:575
static int compare_interface_names(void *a1, void *a2)
Definition: interface_cli.c:50
uword * hw_interface_class_by_name
Definition: interface.h:488
#define VNET_HW_INTERFACE_BOND_INFO_SLAVE
Definition: interface.h:359
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:300
Definition: ip6.h:64
Definition: ip4.h:48
#define ETHERNET_INTERFACE_FLAG_MTU
Definition: ethernet.h:90
#define ETHERNET_INTERFACE_FLAG_ACCEPT_ALL
Definition: ethernet.h:85
static clib_error_t * show_or_clear_hw_interfaces(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: interface_cli.c:59
#define VNET_SW_INTERFACE_FLAG_ADMIN_UP
Definition: interface.h:415
unsigned int u32
Definition: types.h:88
ip4_fib_t * fibs
Vector of FIBs.
Definition: ip4.h:118
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
ip6_main_t ip6_main
Definition: ip6_forward.c:2955
ip_lookup_main_t lookup_main
Definition: ip6.h:110
IPv4 main type.
Definition: ip4.h:114
Bitmaps built as vectors of machine words.
char * path
Definition: cli.h:95
static void * clib_mem_alloc(uword size)
Definition: mem.h:107
uword unformat_ethernet_interface(unformat_input_t *input, va_list *args)
Definition: interface.c:160
u64 uword
Definition: types.h:112
#define vec_elt(v, i)
Get vector value at index i.
l2input_main_t l2input_main
Definition: l2_input.c:76
VLIB_CLI_COMMAND(set_interface_ip_source_and_port_range_check_command, static)
ethernet_interface_t * ethernet_get_interface(ethernet_main_t *em, u32 hw_if_index)
Definition: interface.c:515
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
unsigned char u8
Definition: types.h:56
unformat_function_t unformat_vnet_sw_interface_flags
static clib_error_t * vnet_interface_cli_init(vlib_main_t *vm)
#define vec_sort_with_function(vec, f)
Sort a vector using the supplied element comparison function.
Definition: vec.h:900
vnet_sw_interface_t * sw_interfaces
Definition: interface.h:492
l2_bridge_domain_t * bd_configs
Definition: l2_input.h:69
A collection of combined counters.
Definition: counter.h:212
#define hash_get_mem(h, key)
Definition: hash.h:268
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
u32 min_supported_packet_bytes
Definition: interface.h:328
void vlib_clear_simple_counters(vlib_simple_counter_main_t *cm)
Clear a collection of simple counters.
Definition: counter.c:43
ip4_main_t ip4_main
Global ip4 main structure.
Definition: ip4_forward.c:1578
#define vec_foreach(var, vec)
Vector iterator.
clib_error_t * vnet_sw_interface_set_flags(vnet_main_t *vnm, u32 sw_if_index, u32 flags)
Definition: interface.c:521
vnet_device_class_t * device_classes
Definition: interface.h:485
#define clib_error_return(e, args...)
Definition: error.h:111
struct _unformat_input_t unformat_input_t
clib_error_t * vnet_create_sw_interface(vnet_main_t *vnm, vnet_sw_interface_t *template, u32 *sw_if_index)
Definition: interface.c:573
u32 flags
Definition: vhost-user.h:76
u32 * fib_index_by_sw_if_index
Definition: ip6.h:123
u32 ethernet_set_flags(vnet_main_t *vnm, u32 hw_if_index, u32 flags)
Definition: interface.c:274
clib_error_t * vnet_hw_interface_set_class(vnet_main_t *vnm, u32 hw_if_index, u32 hw_class_index)
Definition: interface.c:990
static uword pool_elts(void *v)
Number of active elements in a pool.
Definition: pool.h:109