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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 * interface_cli.c: interface CLI
18 * Copyright (c) 2008 Eliot Dresselhaus
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:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
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.
45 #include <vnet/vnet.h>
46 #include <vnet/ip/ip.h>
47 #include <vppinfra/bitmap.h>
48 #include <vnet/fib/ip4_fib.h>
49 #include <vnet/fib/ip6_fib.h>
50 #include <vnet/l2/l2_output.h>
51 #include <vnet/l2/l2_input.h>
54 compare_interface_names (void *a1, void *a2)
59 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
63 show_or_clear_hw_interfaces (vlib_main_t * vm,
64 unformat_input_t * input,
65 vlib_cli_command_t * cmd)
67 clib_error_t *error = 0;
68 vnet_main_t *vnm = vnet_get_main ();
69 vnet_interface_main_t *im = &vnm->interface_main;
70 vnet_hw_interface_t *hi;
71 u32 hw_if_index, *hw_if_indices = 0;
72 int i, verbose = -1, is_show, show_bond = 0;
74 is_show = strstr (cmd->path, "show") != 0;
75 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
77 /* See if user wants to show a specific interface. */
79 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
80 vec_add1 (hw_if_indices, hw_if_index);
82 /* See if user wants to show an interface with a specific hw_if_index. */
83 else if (unformat (input, "%u", &hw_if_index))
84 vec_add1 (hw_if_indices, hw_if_index);
86 else if (unformat (input, "verbose"))
87 verbose = 1; /* this is also the default */
89 else if (unformat (input, "detail"))
92 else if (unformat (input, "brief"))
95 else if (unformat (input, "bond"))
99 verbose = 0; /* default to brief for link bonding */
104 error = clib_error_return (0, "unknown input `%U'",
105 format_unformat_error, input);
110 /* Gather interfaces. */
111 if (vec_len (hw_if_indices) == 0)
112 pool_foreach (hi, im->hw_interfaces,
113 vec_add1 (hw_if_indices, hi - im->hw_interfaces));
116 verbose = 1; /* default to verbose (except bond) */
121 vec_sort_with_function (hw_if_indices, compare_interface_names);
123 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
124 for (i = 0; i < vec_len (hw_if_indices); i++)
126 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
127 if (show_bond == 0) /* show all interfaces */
128 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
130 else if ((hi->bond_info) &&
131 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
132 { /* show only bonded interface and all its slave interfaces */
134 vnet_hw_interface_t *shi;
135 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
139 clib_bitmap_foreach (hw_idx, hi->bond_info,
141 shi = vnet_get_hw_interface(vnm, hw_idx);
142 vlib_cli_output (vm, "%U\n",
143 format_vnet_hw_interface, vnm, shi, verbose);
151 for (i = 0; i < vec_len (hw_if_indices); i++)
153 vnet_device_class_t *dc;
155 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
156 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
158 if (dc->clear_counters)
159 dc->clear_counters (hi->dev_instance);
164 vec_free (hw_if_indices);
170 * Displays various information about the state of the current terminal
174 * @cliexstart{show hardware}
176 * GigabitEthernet2/0/0 up GigabitEthernet2/0/0
177 * Ethernet address 00:50:56:b7:7c:83
178 * Intel 82545em_copper
179 * link up, media 1000T full-duplex, master,
180 * 0 unprocessed, 384 total buffers on rx queue 0 ring
181 * 237 buffers in driver rx cache
182 * rx total packets 1816
183 * rx total bytes 181084
184 * rx good packets 1816
185 * rx good bytes 181084
186 * rx 65 127 byte packets 1586
187 * rx 256 511 byte packets 230
188 * tx total packets 346
189 * tx total bytes 90224
190 * tx good packets 346
191 * tx good bytes 88840
192 * tx 64 byte packets 1
193 * tx 65 127 byte packets 115
194 * tx 256 511 byte packets 230
197 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
198 .path = "show hardware-interfaces",
199 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] [<if-name1> <if-name2> ...]",
200 .function = show_or_clear_hw_interfaces,
205 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
206 .path = "clear hardware-interfaces",
207 .short_help = "Clear hardware interfaces statistics",
208 .function = show_or_clear_hw_interfaces,
213 sw_interface_name_compare (void *a1, void *a2)
215 vnet_sw_interface_t *si1 = a1;
216 vnet_sw_interface_t *si2 = a2;
218 return vnet_sw_interface_compare (vnet_get_main (),
219 si1->sw_if_index, si2->sw_if_index);
222 static clib_error_t *
223 show_sw_interfaces (vlib_main_t * vm,
224 unformat_input_t * input, vlib_cli_command_t * cmd)
226 clib_error_t *error = 0;
227 vnet_main_t *vnm = vnet_get_main ();
228 vnet_interface_main_t *im = &vnm->interface_main;
229 vnet_sw_interface_t *si, *sorted_sis = 0;
230 u32 sw_if_index = ~(u32) 0;
231 u8 show_addresses = 0;
232 u8 show_features = 0;
235 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
237 /* See if user wants to show specific interface */
239 (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
241 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
242 vec_add1 (sorted_sis, si[0]);
244 else if (unformat (input, "address") || unformat (input, "addr"))
246 else if (unformat (input, "features") || unformat (input, "feat"))
248 else if (unformat (input, "tag"))
252 error = clib_error_return (0, "unknown input `%U'",
253 format_unformat_error, input);
258 if (show_features || show_tag)
260 if (sw_if_index == ~(u32) 0)
261 return clib_error_return (0, "Interface not specified...");
266 vnet_interface_features_show (vm, sw_if_index);
268 l2_input_config_t *l2_input = l2input_intf_config (sw_if_index);
269 u32 fb = l2_input->feature_bitmap;
270 /* intf input features are masked by bridge domain */
271 if (l2_input->bridge)
272 fb &= l2input_bd_config (l2_input->bd_index)->feature_bitmap;
273 vlib_cli_output (vm, "\nl2-input:\n%U", format_l2_input_features, fb);
275 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
276 vlib_cli_output (vm, "\nl2-output:");
277 if (l2_output->out_vtr_flag)
278 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
279 vlib_cli_output (vm, "%U", format_l2_output_features,
280 l2_output->feature_bitmap);
286 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
287 vlib_cli_output (vm, "%U: %s",
288 format_vnet_sw_if_index_name, vnm, sw_if_index,
289 tag ? (char *) tag : "(none)");
294 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
296 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
298 /* Gather interfaces. */
300 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
301 _vec_len (sorted_sis) = 0;
302 pool_foreach (si, im->sw_interfaces, (
305 vnet_swif_is_api_visible (si);
307 vec_add1 (sorted_sis, si[0]);}
311 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
316 vec_foreach (si, sorted_sis)
318 ip4_main_t *im4 = &ip4_main;
319 ip6_main_t *im6 = &ip6_main;
320 ip_lookup_main_t *lm4 = &im4->lookup_main;
321 ip_lookup_main_t *lm6 = &im6->lookup_main;
322 ip_interface_address_t *ia = 0;
325 u32 fib_index4 = 0, fib_index6 = 0;
329 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
330 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
333 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
334 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
337 fib4 = ip4_fib_get (fib_index4);
338 fib6 = ip6_fib_get (fib_index6);
340 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
342 (vm, "%U (%s): \n unnumbered, use %U",
343 format_vnet_sw_if_index_name,
344 vnm, si->sw_if_index,
345 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
346 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
350 vlib_cli_output (vm, "%U (%s):",
351 format_vnet_sw_if_index_name,
352 vnm, si->sw_if_index,
353 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
357 /* Display any L2 info */
358 l2_input_config_t *l2_input = l2input_intf_config (si->sw_if_index);
359 if (l2_input->bridge)
361 u32 bd_id = l2input_main.bd_configs[l2_input->bd_index].bd_id;
362 vlib_cli_output (vm, " l2 bridge bd_id %d%s%d", bd_id,
363 l2_input->bvi ? " bvi shg " : " shg ",
366 else if (l2_input->xconnect)
368 vlib_cli_output (vm, " l2 xconnect %U",
369 format_vnet_sw_if_index_name,
370 vnm, l2_input->output_sw_if_index);
373 /* Display any IP4 addressing info */
375 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
376 1 /* honor unnumbered */,
378 r4 = ip_interface_address_get_address (lm4, ia);
381 vlib_cli_output (vm, " %U/%d table %d",
382 format_ip4_address, r4,
388 vlib_cli_output (vm, " %U/%d",
389 format_ip4_address, r4,
395 /* Display any IP6 addressing info */
397 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
398 1 /* honor unnumbered */,
400 r6 = ip_interface_address_get_address (lm6, ia);
403 vlib_cli_output (vm, " %U/%d table %d",
404 format_ip6_address, r6,
410 vlib_cli_output (vm, " %U/%d",
411 format_ip6_address, r6,
420 vec_foreach (si, sorted_sis)
422 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
427 vec_free (sorted_sis);
432 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
433 .path = "show interface",
434 .short_help = "show interface [address|addr|features|feat] [<if-name1> <if-name2> ...]",
435 .function = show_sw_interfaces,
439 /* Root of all interface commands. */
441 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
443 .short_help = "Interface commands",
448 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
449 .path = "set interface",
450 .short_help = "Interface commands",
454 static clib_error_t *
455 clear_interface_counters (vlib_main_t * vm,
456 unformat_input_t * input, vlib_cli_command_t * cmd)
458 vnet_main_t *vnm = vnet_get_main ();
459 vnet_interface_main_t *im = &vnm->interface_main;
460 vlib_simple_counter_main_t *sm;
461 vlib_combined_counter_main_t *cm;
462 static vnet_main_t **my_vnet_mains;
463 int i, j, n_counters;
465 vec_reset_length (my_vnet_mains);
467 for (i = 0; i < vec_len (vnet_mains); i++)
470 vec_add1 (my_vnet_mains, vnet_mains[i]);
473 if (vec_len (vnet_mains) == 0)
474 vec_add1 (my_vnet_mains, vnm);
476 n_counters = vec_len (im->combined_sw_if_counters);
478 for (j = 0; j < n_counters; j++)
480 for (i = 0; i < vec_len (my_vnet_mains); i++)
482 im = &my_vnet_mains[i]->interface_main;
483 cm = im->combined_sw_if_counters + j;
484 vlib_clear_combined_counters (cm);
488 n_counters = vec_len (im->sw_if_counters);
490 for (j = 0; j < n_counters; j++)
492 for (i = 0; i < vec_len (my_vnet_mains); i++)
494 im = &my_vnet_mains[i]->interface_main;
495 sm = im->sw_if_counters + j;
496 vlib_clear_simple_counters (sm);
504 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
505 .path = "clear interfaces",
506 .short_help = "Clear interfaces statistics",
507 .function = clear_interface_counters,
512 * Parse subinterface names.
514 * The following subinterface syntax is supported. The first two are for
515 * backwards compatability:
518 * - a subinterface with the name <intf-name>.<id>. The subinterface
519 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
521 * <intf-name> <min_id>-<max_id>
522 * - a set of the above subinterfaces, repeating for each id
523 * in the range <min_id> to <max_id>
525 * In the following, exact-match semantics (i.e. the number of vlan tags on the
526 * packet must match the number of tags in the configuration) are used only if
527 * the keyword exact-match is present. Non-exact match is the default.
529 * <intf-name> <id> dot1q <outer_id> [exact-match]
530 * - a subinterface with the name <intf-name>.<id>. The subinterface
531 * is a single dot1q vlan with vlan id <outer_id>.
533 * <intf-name> <id> dot1q any [exact-match]
534 * - a subinterface with the name <intf-name>.<id>. The subinterface
535 * is a single dot1q vlan with any vlan id.
537 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
538 * - a subinterface with the name <intf-name>.<id>. The subinterface
539 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
542 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
543 * - a subinterface with the name <intf-name>.<id>. The subinterface
544 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
546 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
548 * - a subinterface with the name <intf-name>.<id>. The subinterface
549 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
551 * For each of the above CLI, there is a duplicate that uses the keyword
552 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
553 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
554 * tagged packets the inner ethertype is always 0x8100. Also note that
555 * the dot1q and dot1ad naming spaces are independent, so it is legal to
556 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
558 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
559 * - a subinterface with the name <intf-name>.<id>. The subinterface
560 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
563 * <intf-name> <id> untagged
564 * - a subinterface with the name <intf-name>.<id>. The subinterface
565 * has no vlan tags. Only one can be specified per interface.
567 * <intf-name> <id> default
568 * - a subinterface with the name <intf-name>.<id>. This is associated
569 * with a packet that did not match any other configured subinterface
570 * on this interface. Only one can be specified per interface.
573 static clib_error_t *
574 parse_vlan_sub_interfaces (unformat_input_t * input,
575 vnet_sw_interface_t * template)
577 clib_error_t *error = 0;
578 u32 inner_vlan, outer_vlan;
580 if (unformat (input, "any inner-dot1q any"))
582 template->sub.eth.flags.two_tags = 1;
583 template->sub.eth.flags.outer_vlan_id_any = 1;
584 template->sub.eth.flags.inner_vlan_id_any = 1;
586 else if (unformat (input, "any"))
588 template->sub.eth.flags.one_tag = 1;
589 template->sub.eth.flags.outer_vlan_id_any = 1;
591 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
593 template->sub.eth.flags.two_tags = 1;
594 template->sub.eth.flags.inner_vlan_id_any = 1;
595 template->sub.eth.outer_vlan_id = outer_vlan;
597 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
599 template->sub.eth.flags.two_tags = 1;
600 template->sub.eth.outer_vlan_id = outer_vlan;
601 template->sub.eth.inner_vlan_id = inner_vlan;
603 else if (unformat (input, "%d", &outer_vlan))
605 template->sub.eth.flags.one_tag = 1;
606 template->sub.eth.outer_vlan_id = outer_vlan;
610 error = clib_error_return (0, "expected dot1q config, got `%U'",
611 format_unformat_error, input);
615 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
617 if (unformat (input, "exact-match"))
619 template->sub.eth.flags.exact_match = 1;
627 static clib_error_t *
628 create_sub_interfaces (vlib_main_t * vm,
629 unformat_input_t * input, vlib_cli_command_t * cmd)
631 vnet_main_t *vnm = vnet_get_main ();
632 clib_error_t *error = 0;
633 u32 hw_if_index, sw_if_index;
634 vnet_hw_interface_t *hi;
635 u32 id, id_min, id_max;
636 vnet_sw_interface_t template;
639 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
641 error = clib_error_return (0, "unknown interface `%U'",
642 format_unformat_error, input);
646 memset (&template, 0, sizeof (template));
647 template.sub.eth.raw_flags = 0;
649 if (unformat (input, "%d default", &id_min))
652 template.sub.eth.flags.default_sub = 1;
654 else if (unformat (input, "%d untagged", &id_min))
657 template.sub.eth.flags.no_tags = 1;
658 template.sub.eth.flags.exact_match = 1;
660 else if (unformat (input, "%d dot1q", &id_min))
662 /* parse dot1q config */
664 error = parse_vlan_sub_interfaces (input, &template);
668 else if (unformat (input, "%d dot1ad", &id_min))
670 /* parse dot1ad config */
672 template.sub.eth.flags.dot1ad = 1;
673 error = parse_vlan_sub_interfaces (input, &template);
677 else if (unformat (input, "%d-%d", &id_min, &id_max))
679 template.sub.eth.flags.one_tag = 1;
680 template.sub.eth.flags.exact_match = 1;
684 else if (unformat (input, "%d", &id_min))
687 template.sub.eth.flags.one_tag = 1;
688 template.sub.eth.outer_vlan_id = id_min;
689 template.sub.eth.flags.exact_match = 1;
694 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
695 format_unformat_error, input);
699 hi = vnet_get_hw_interface (vnm, hw_if_index);
701 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
704 clib_error_return (0,
705 "not allowed as %v belong to a BondEthernet interface",
710 for (id = id_min; id <= id_max; id++)
713 vnet_interface_main_t *im = &vnm->interface_main;
714 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
717 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
721 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
722 hi->sw_if_index, id);
726 kp = clib_mem_alloc (sizeof (*kp));
727 *kp = sup_and_sub_key;
729 template.type = VNET_SW_INTERFACE_TYPE_SUB;
730 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
731 template.sup_sw_if_index = hi->sw_if_index;
732 template.sub.id = id;
734 template.sub.eth.outer_vlan_id = id;
736 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
740 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
741 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
742 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
743 vnet_get_main (), sw_if_index);
752 * Create vlan subinterfaces
755 * @cliexstart{create sub-interfaces}
757 * To create a vlan subinterface 11 to process packets on 802.1q VLAN id 11, use:
759 * vpp# create sub GigabitEthernet2/0/0 11
761 * This shorthand is equivalent to:
762 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 11 exact-match
764 * You can specify a subinterface number that is different from the vlan id:
765 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100
767 * You can create qinq and q-in-any interfaces:
768 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200
769 * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any
771 * You can also create dot1ad interfaces:
772 * vpp# create sub GigabitEthernet2/0/0 11 dot1ad 11
773 * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q 200
775 * Subinterfaces can be configured as either exact-match or non-exact match.
776 * Non-exact match is the CLI default. If exact-match is specified,
777 * packets must have the same number of vlan tags as the configuration.
778 * For non-exact-match, packets must at least that number of tags.
779 * L3 (routed) interfaces must be configured as exact-match.
780 * L2 interfaces are typically configured as non-exact-match.
782 * For example, a packet with outer vlan 100 and inner 200 would match this interface:
783 * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100
785 * but would not match this interface:
786 * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100 exact-match
788 * There are two special subinterfaces that can be configured. Subinterface untagged has no vlan tags:
789 * vpp# create sub GigabitEthernet2/0/0 5 untagged
791 * The subinterface default matches any packet that does not match any other subinterface:
792 * vpp# create sub GigabitEthernet2/0/0 7 default
795 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
796 .path = "create sub-interfaces",
797 .short_help = "create sub-interfaces <nn>[-<nn>] [dot1q|dot1ad|default|untagged]",
798 .function = create_sub_interfaces,
802 static clib_error_t *
803 set_state (vlib_main_t * vm,
804 unformat_input_t * input, vlib_cli_command_t * cmd)
806 vnet_main_t *vnm = vnet_get_main ();
808 u32 sw_if_index, flags;
811 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
813 error = clib_error_return (0, "unknown interface `%U'",
814 format_unformat_error, input);
818 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
820 error = clib_error_return (0, "unknown flags `%U'",
821 format_unformat_error, input);
825 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
836 * Interface admin up/down
839 * @cliexstart{set interface state}
840 * vpp# set interface state GigabitEthernet2/0/0 up
841 * vpp# set interface state GigabitEthernet2/0/0 down
844 VLIB_CLI_COMMAND (set_state_command, static) = {
845 .path = "set interface state",
846 .short_help = "set interface state <if-name> [up|down|punt|enable]",
847 .function = set_state,
851 static clib_error_t *
852 set_unnumbered (vlib_main_t * vm,
853 unformat_input_t * input, vlib_cli_command_t * cmd)
855 vnet_main_t *vnm = vnet_get_main ();
856 u32 unnumbered_sw_if_index;
857 u32 inherit_from_sw_if_index;
858 vnet_sw_interface_t *si;
863 if (unformat (input, "%U use %U",
864 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
865 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
867 else if (unformat (input, "del %U",
868 unformat_vnet_sw_interface, vnm,
869 &unnumbered_sw_if_index))
872 return clib_error_return (0, "parse error '%U'",
873 format_unformat_error, input);
875 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
876 was_unnum = (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED);
880 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
881 si->unnumbered_sw_if_index = (u32) ~ 0;
883 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
884 [unnumbered_sw_if_index] = ~0;
885 ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
886 [unnumbered_sw_if_index] = ~0;
890 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
891 si->unnumbered_sw_if_index = inherit_from_sw_if_index;
893 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
894 [unnumbered_sw_if_index] =
895 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
896 [inherit_from_sw_if_index];
897 ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
898 [unnumbered_sw_if_index] =
899 ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
900 [inherit_from_sw_if_index];
903 if (was_unnum != (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
905 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, !is_del);
906 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, !is_del);
913 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
914 .path = "set interface unnumbered",
915 .short_help = "set interface unnumbered [<intfc> use <intfc> | del <intfc>]",
916 .function = set_unnumbered,
922 static clib_error_t *
923 set_hw_class (vlib_main_t * vm,
924 unformat_input_t * input, vlib_cli_command_t * cmd)
926 vnet_main_t *vnm = vnet_get_main ();
927 vnet_interface_main_t *im = &vnm->interface_main;
929 u32 hw_if_index, hw_class_index;
932 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
934 error = clib_error_return (0, "unknown hardware interface `%U'",
935 format_unformat_error, input);
939 if (!unformat_user (input, unformat_hash_string,
940 im->hw_interface_class_by_name, &hw_class_index))
942 error = clib_error_return (0, "unknown hardware class `%U'",
943 format_unformat_error, input);
947 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
956 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
957 .path = "set interface hw-class",
958 .short_help = "Set interface hardware class",
959 .function = set_hw_class,
963 static clib_error_t *
964 vnet_interface_cli_init (vlib_main_t * vm)
969 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
971 static clib_error_t *
972 renumber_interface_command_fn (vlib_main_t * vm,
973 unformat_input_t * input,
974 vlib_cli_command_t * cmd)
977 u32 new_dev_instance;
978 vnet_main_t *vnm = vnet_get_main ();
981 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
982 return clib_error_return (0, "unknown hardware interface `%U'",
983 format_unformat_error, input);
985 if (!unformat (input, "%d", &new_dev_instance))
986 return clib_error_return (0, "new dev instance missing");
988 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
996 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
1006 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1007 .path = "renumber interface",
1008 .short_help = "renumber interface <if-name> <new-dev-instance>",
1009 .function = renumber_interface_command_fn,
1013 static clib_error_t *
1014 promiscuous_cmd (vlib_main_t * vm,
1015 unformat_input_t * input, vlib_cli_command_t * cmd)
1017 vnet_main_t *vnm = vnet_get_main ();
1019 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
1020 ethernet_main_t *em = ðernet_main;
1021 ethernet_interface_t *eif;
1023 if (unformat (input, "on %U",
1024 unformat_vnet_hw_interface, vnm, &hw_if_index))
1026 else if (unformat (input, "off %U",
1027 unformat_ethernet_interface, vnm, &hw_if_index))
1030 return clib_error_return (0, "unknown input `%U'",
1031 format_unformat_error, input);
1033 eif = ethernet_get_interface (em, hw_if_index);
1035 return clib_error_return (0, "not supported");
1037 ethernet_set_flags (vnm, hw_if_index, flags);
1042 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1043 .path = "set interface promiscuous",
1044 .short_help = "set interface promiscuous [on | off] <intfc>",
1045 .function = promiscuous_cmd,
1049 static clib_error_t *
1050 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1052 vnet_main_t *vnm = vnet_get_main ();
1053 u32 hw_if_index, mtu;
1054 u32 flags = ETHERNET_INTERFACE_FLAG_MTU;
1055 ethernet_main_t *em = ðernet_main;
1057 if (unformat (input, "%d %U", &mtu,
1058 unformat_vnet_hw_interface, vnm, &hw_if_index))
1060 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1061 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1064 return clib_error_return (0, "not supported");
1066 if (mtu < hi->min_supported_packet_bytes)
1067 return clib_error_return (0, "Invalid mtu (%d): "
1068 "must be >= min pkt bytes (%d)", mtu,
1069 hi->min_supported_packet_bytes);
1071 if (mtu > hi->max_supported_packet_bytes)
1072 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1073 hi->max_supported_packet_bytes);
1075 if (hi->max_packet_bytes != mtu)
1077 hi->max_packet_bytes = mtu;
1078 ethernet_set_flags (vnm, hw_if_index, flags);
1082 return clib_error_return (0, "unknown input `%U'",
1083 format_unformat_error, input);
1088 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1089 .path = "set interface mtu",
1090 .short_help = "set interface mtu <value> <intfc>",
1091 .function = mtu_cmd,
1095 static clib_error_t *
1096 set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1097 vlib_cli_command_t * cmd)
1099 vnet_main_t *vnm = vnet_get_main ();
1100 clib_error_t *error = 0;
1101 u32 sw_if_index = ~0;
1104 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1106 error = clib_error_return (0, "unknown interface `%U'",
1107 format_unformat_error, input);
1110 if (!unformat_user (input, unformat_ethernet_address, &mac))
1112 error = clib_error_return (0, "expected mac address `%U'",
1113 format_unformat_error, input);
1116 error = vnet_hw_interface_change_mac_address (vnm, sw_if_index, mac);
1122 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1123 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1124 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1128 * Example of how to change MAC Address of interface:
1129 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1130 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1131 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1132 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1136 VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1137 .path = "set interface mac address",
1138 .short_help = "set interface mac address <intfc> <mac-address>",
1139 .function = set_interface_mac_address,
1143 static clib_error_t *
1144 set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1146 vnet_main_t *vnm = vnet_get_main ();
1147 u32 sw_if_index = ~0;
1150 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1151 vnm, &sw_if_index, &tag))
1152 return clib_error_return (0, "unknown input `%U'",
1153 format_unformat_error, input);
1155 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1161 VLIB_CLI_COMMAND (set_tag_command, static) = {
1162 .path = "set interface tag",
1163 .short_help = "set interface tag <intfc> <tag>",
1164 .function = set_tag,
1168 static clib_error_t *
1169 clear_tag (vlib_main_t * vm, unformat_input_t * input,
1170 vlib_cli_command_t * cmd)
1172 vnet_main_t *vnm = vnet_get_main ();
1173 u32 sw_if_index = ~0;
1175 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1176 return clib_error_return (0, "unknown input `%U'",
1177 format_unformat_error, input);
1179 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1185 VLIB_CLI_COMMAND (clear_tag_command, static) = {
1186 .path = "clear interface tag",
1187 .short_help = "clear interface tag <intfc>",
1188 .function = clear_tag,
1192 static clib_error_t *
1193 set_hw_interface_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1194 u32 queue_id, vnet_hw_interface_rx_mode mode)
1196 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1197 vnet_device_class_t *dev_class =
1198 vnet_get_device_class (vnm, hw->dev_class_index);
1199 clib_error_t *error;
1200 vnet_hw_interface_rx_mode old_mode;
1203 if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT)
1204 mode = hw->default_rx_mode;
1206 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &old_mode);
1210 if (old_mode == mode)
1211 return 0; /* same rx-mode, no change */
1213 case VNET_API_ERROR_INVALID_INTERFACE:
1214 return clib_error_return (0, "invalid interface");
1216 return clib_error_return (0, "unknown error");
1219 if (dev_class->rx_mode_change_function)
1221 error = dev_class->rx_mode_change_function (vnm, hw_if_index, queue_id,
1227 rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1232 case VNET_API_ERROR_UNSUPPORTED:
1233 return clib_error_return (0, "unsupported");
1234 case VNET_API_ERROR_INVALID_INTERFACE:
1235 return clib_error_return (0, "invalid interface");
1237 return clib_error_return (0, "unknown error");
1243 static clib_error_t *
1244 set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1245 vlib_cli_command_t * cmd)
1247 clib_error_t *error = 0;
1248 unformat_input_t _line_input, *line_input = &_line_input;
1249 vnet_main_t *vnm = vnet_get_main ();
1250 vnet_hw_interface_t *hw;
1251 u32 hw_if_index = (u32) ~ 0;
1252 u32 queue_id = (u32) ~ 0;
1253 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
1256 if (!unformat_user (input, unformat_line_input, line_input))
1259 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1262 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1264 else if (unformat (line_input, "queue %d", &queue_id))
1266 else if (unformat (line_input, "polling"))
1267 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
1268 else if (unformat (line_input, "interrupt"))
1269 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
1270 else if (unformat (line_input, "adaptive"))
1271 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
1274 error = clib_error_return (0, "parse error: '%U'",
1275 format_unformat_error, line_input);
1276 unformat_free (line_input);
1281 unformat_free (line_input);
1283 if (hw_if_index == (u32) ~ 0)
1284 return clib_error_return (0, "please specify valid interface name");
1286 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
1287 return clib_error_return (0, "please specify valid rx-mode");
1289 hw = vnet_get_hw_interface (vnm, hw_if_index);
1293 for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1295 error = set_hw_interface_rx_mode (vnm, hw_if_index, i, mode);
1299 hw->default_rx_mode = mode;
1302 error = set_hw_interface_rx_mode (vnm, hw_if_index, queue_id, mode);
1308 * This command is used to assign a given interface, and optionally a
1309 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1313 * Example of how to display the interface placement:
1314 * @cliexstart{show interface rx-placement}
1315 * Thread 1 (vpp_wk_0):
1316 * GigabitEthernet0/8/0 queue 0
1317 * GigabitEthernet0/9/0 queue 0
1318 * Thread 2 (vpp_wk_1):
1319 * GigabitEthernet0/8/0 queue 1
1320 * GigabitEthernet0/9/0 queue 1
1322 * Example of how to assign a interface and queue to a thread:
1323 * @cliexcmd{set interface placement GigabitEthernet0/8/0 queue 1 thread 1}
1326 VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
1327 .path = "set interface rx-mode",
1328 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1329 .function = set_interface_rx_mode,
1333 static clib_error_t *
1334 show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1335 vlib_cli_command_t * cmd)
1338 vnet_main_t *vnm = vnet_get_main ();
1339 vnet_device_input_runtime_t *rt;
1340 vnet_device_and_queue_t *dq;
1341 vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
1346 foreach_vlib_main (({
1347 clib_bitmap_foreach (si, pn->sibling_bitmap,
1349 rt = vlib_node_get_runtime_data (this_vlib_main, si);
1351 if (vec_len (rt->devices_and_queues))
1352 s = format (s, " node %U:\n", format_vlib_node_name, vm, si);
1354 vec_foreach (dq, rt->devices_and_queues)
1356 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm,
1358 s = format (s, " %U queue %u (%U)\n",
1359 format_vnet_sw_if_index_name, vnm, hi->sw_if_index,
1361 format_vnet_hw_interface_rx_mode, dq->mode);
1364 if (vec_len (s) > 0)
1366 vlib_cli_output(vm, "Thread %u (%v):\n%v", index,
1367 vlib_worker_threads[index].name, s);
1368 vec_reset_length (s);
1379 VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1380 .path = "show interface rx-placement",
1381 .short_help = "show interface rx-placement",
1382 .function = show_interface_rx_placement_fn,
1386 static clib_error_t *
1387 set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input,
1388 vlib_cli_command_t * cmd)
1390 clib_error_t *error = 0;
1391 unformat_input_t _line_input, *line_input = &_line_input;
1392 vnet_main_t *vnm = vnet_get_main ();
1393 vnet_device_main_t *vdm = &vnet_device_main;
1394 vnet_hw_interface_rx_mode mode;
1395 u32 hw_if_index = (u32) ~ 0;
1396 u32 queue_id = (u32) 0;
1397 u32 thread_index = (u32) ~ 0;
1400 if (!unformat_user (input, unformat_line_input, line_input))
1403 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1406 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1408 else if (unformat (line_input, "queue %d", &queue_id))
1410 else if (unformat (line_input, "main", &thread_index))
1412 else if (unformat (line_input, "worker %d", &thread_index))
1413 thread_index += vdm->first_worker_thread_index;
1416 error = clib_error_return (0, "parse error: '%U'",
1417 format_unformat_error, line_input);
1418 unformat_free (line_input);
1423 unformat_free (line_input);
1425 if (hw_if_index == (u32) ~ 0)
1426 return clib_error_return (0, "please specify valid interface name");
1428 if (thread_index > vdm->last_worker_thread_index)
1429 return clib_error_return (0,
1430 "please specify valid worker thread or main");
1432 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode);
1435 return clib_error_return (0, "not found");
1437 rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id);
1440 return clib_error_return (0, "not found");
1442 vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id,
1444 vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1450 * This command is used to assign a given interface, and optionally a
1451 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1455 * Example of how to display the interface placement:
1456 * @cliexstart{show interface placement}
1457 * Thread 1 (vpp_wk_0):
1458 * GigabitEthernet0/8/0 queue 0
1459 * GigabitEthernet0/9/0 queue 0
1460 * Thread 2 (vpp_wk_1):
1461 * GigabitEthernet0/8/0 queue 1
1462 * GigabitEthernet0/9/0 queue 1
1464 * Example of how to assign a interface and queue to a thread:
1465 * @cliexcmd{set interface placement GigabitEthernet0/8/0 queue 1 thread 1}
1468 VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1469 .path = "set interface rx-placement",
1470 .short_help = "set interface rx-placement <hw-interface> [queue <n>] "
1471 "[worker <n> | main]",
1472 .function = set_interface_rx_placement,
1478 * fd.io coding-style-patch-verification: ON
1481 * eval: (c-set-style "gnu")