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.
42 * @brief Interface CLI.
44 * Source code for several CLI interface commands.
48 #include <vnet/vnet.h>
49 #include <vnet/ip/ip.h>
50 #include <vppinfra/bitmap.h>
51 #include <vnet/fib/ip4_fib.h>
52 #include <vnet/fib/ip6_fib.h>
53 #include <vnet/l2/l2_output.h>
54 #include <vnet/l2/l2_input.h>
57 compare_interface_names (void *a1, void *a2)
62 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
66 show_or_clear_hw_interfaces (vlib_main_t * vm,
67 unformat_input_t * input,
68 vlib_cli_command_t * cmd)
70 clib_error_t *error = 0;
71 vnet_main_t *vnm = vnet_get_main ();
72 vnet_interface_main_t *im = &vnm->interface_main;
73 vnet_hw_interface_t *hi;
74 u32 hw_if_index, *hw_if_indices = 0;
75 int i, verbose = -1, is_show, show_bond = 0;
77 is_show = strstr (cmd->path, "show") != 0;
78 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
80 /* See if user wants to show a specific interface. */
82 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
83 vec_add1 (hw_if_indices, hw_if_index);
85 /* See if user wants to show an interface with a specific hw_if_index. */
86 else if (unformat (input, "%u", &hw_if_index))
87 vec_add1 (hw_if_indices, hw_if_index);
89 else if (unformat (input, "verbose"))
90 verbose = 1; /* this is also the default */
92 else if (unformat (input, "detail"))
95 else if (unformat (input, "brief"))
98 else if (unformat (input, "bond"))
102 verbose = 0; /* default to brief for link bonding */
107 error = clib_error_return (0, "unknown input `%U'",
108 format_unformat_error, input);
113 /* Gather interfaces. */
114 if (vec_len (hw_if_indices) == 0)
115 pool_foreach (hi, im->hw_interfaces,
116 vec_add1 (hw_if_indices, hi - im->hw_interfaces));
119 verbose = 1; /* default to verbose (except bond) */
124 vec_sort_with_function (hw_if_indices, compare_interface_names);
126 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
127 for (i = 0; i < vec_len (hw_if_indices); i++)
129 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
130 if (show_bond == 0) /* show all interfaces */
131 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
133 else if ((hi->bond_info) &&
134 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
135 { /* show only bonded interface and all its slave interfaces */
137 vnet_hw_interface_t *shi;
138 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
142 clib_bitmap_foreach (hw_idx, hi->bond_info,
144 shi = vnet_get_hw_interface(vnm, hw_idx);
145 vlib_cli_output (vm, "%U\n",
146 format_vnet_hw_interface, vnm, shi, verbose);
154 for (i = 0; i < vec_len (hw_if_indices); i++)
156 vnet_device_class_t *dc;
158 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
159 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
161 if (dc->clear_counters)
162 dc->clear_counters (hi->dev_instance);
167 vec_free (hw_if_indices);
172 * Display more detailed information about all or a list of given interfaces.
173 * The verboseness of the output can be controlled by the following optional
175 * - brief: Only show name, index and state (default for bonded interfaces).
176 * - verbose: Also display additional attributes (default for all other interfaces).
177 * - detail: Also display all remaining attributes and extended statistics.
179 * To limit the output of the command to bonded interfaces and their slave
180 * interfaces, use the '<em>bond</em>' optional parameter.
183 * Example of how to display default data for all interfaces:
184 * @cliexstart{show hardware-interfaces}
185 * Name Idx Link Hardware
186 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
187 * Ethernet address ec:f4:bb:c0:bc:fc
189 * carrier up full duplex speed 1000 mtu 9216
190 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
192 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
193 * Ethernet address ec:f4:bb:c0:bc:fd
195 * carrier up full duplex speed 1000 mtu 9216
196 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
198 * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0
199 * Ethernet address 02:fe:a5:a9:8b:8e
200 * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1
201 * Ethernet address 02:fe:c0:4e:3b:b0
202 * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2
203 * Ethernet address 02:fe:1f:73:92:81
204 * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3
205 * Ethernet address 02:fe:f2:25:c4:68
206 * local0 0 down local0
209 * Example of how to display '<em>verbose</em>' data for an interface by name and
210 * software index (where 2 is the software index):
211 * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose}
212 * Name Idx Link Hardware
213 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
214 * Ethernet address ec:f4:bb:c0:bc:fc
216 * carrier up full duplex speed 1000 mtu 9216
217 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
219 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
220 * Ethernet address ec:f4:bb:c0:bc:fd
222 * carrier up full duplex speed 1000 mtu 9216
223 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
228 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
229 .path = "show hardware-interfaces",
230 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
231 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
232 .function = show_or_clear_hw_interfaces,
238 * Clear the extended statistics for all or a list of given interfaces
239 * (statistics associated with the '<em>show hardware-interfaces</em>' command).
242 * Example of how to clear the extended statistics for all interfaces:
243 * @cliexcmd{clear hardware-interfaces}
244 * Example of how to clear the extended statistics for an interface by
245 * name and software index (where 2 is the software index):
246 * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2}
249 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
250 .path = "clear hardware-interfaces",
251 .short_help = "clear hardware-interfaces "
252 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
253 .function = show_or_clear_hw_interfaces,
258 sw_interface_name_compare (void *a1, void *a2)
260 vnet_sw_interface_t *si1 = a1;
261 vnet_sw_interface_t *si2 = a2;
263 return vnet_sw_interface_compare (vnet_get_main (),
264 si1->sw_if_index, si2->sw_if_index);
267 static clib_error_t *
268 show_sw_interfaces (vlib_main_t * vm,
269 unformat_input_t * input, vlib_cli_command_t * cmd)
271 clib_error_t *error = 0;
272 vnet_main_t *vnm = vnet_get_main ();
273 unformat_input_t _linput, *linput = &_linput;
274 vnet_interface_main_t *im = &vnm->interface_main;
275 vnet_sw_interface_t *si, *sorted_sis = 0;
276 u32 sw_if_index = ~(u32) 0;
277 u8 show_addresses = 0;
278 u8 show_features = 0;
283 * Get a line of input. Won't work if the user typed
284 * "show interface" and nothing more.
286 if (unformat_user (input, unformat_line_input, linput))
288 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
290 /* See if user wants to show specific interface */
292 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
294 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
295 vec_add1 (sorted_sis, si[0]);
297 else if (unformat (linput, "address") || unformat (linput, "addr"))
299 else if (unformat (linput, "features") || unformat (linput, "feat"))
301 else if (unformat (linput, "tag"))
303 else if (unformat (linput, "verbose"))
307 error = clib_error_return (0, "unknown input `%U'",
308 format_unformat_error, linput);
312 unformat_free (linput);
314 if (show_features || show_tag)
316 if (sw_if_index == ~(u32) 0)
317 return clib_error_return (0, "Interface not specified...");
322 vnet_interface_features_show (vm, sw_if_index, verbose);
324 l2_input_config_t *l2_input = l2input_intf_config (sw_if_index);
325 u32 fb = l2_input->feature_bitmap;
326 /* intf input features are masked by bridge domain */
327 if (l2_input->bridge)
328 fb &= l2input_bd_config (l2_input->bd_index)->feature_bitmap;
329 vlib_cli_output (vm, "\nl2-input:\n%U", format_l2_input_features, fb,
332 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
333 vlib_cli_output (vm, "\nl2-output:");
334 if (l2_output->out_vtr_flag)
335 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
336 vlib_cli_output (vm, "%U", format_l2_output_features,
337 l2_output->feature_bitmap, 1);
343 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
344 vlib_cli_output (vm, "%U: %s",
345 format_vnet_sw_if_index_name, vnm, sw_if_index,
346 tag ? (char *) tag : "(none)");
351 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
353 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
355 /* Gather interfaces. */
357 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
358 _vec_len (sorted_sis) = 0;
360 pool_foreach (si, im->sw_interfaces,
362 int visible = vnet_swif_is_api_visible (si);
364 vec_add1 (sorted_sis, si[0]);}
368 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
373 vec_foreach (si, sorted_sis)
375 ip4_main_t *im4 = &ip4_main;
376 ip6_main_t *im6 = &ip6_main;
377 ip_lookup_main_t *lm4 = &im4->lookup_main;
378 ip_lookup_main_t *lm6 = &im6->lookup_main;
379 ip_interface_address_t *ia = 0;
380 u32 fib_index4 = 0, fib_index6 = 0;
382 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
383 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
386 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
387 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
390 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
391 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
393 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
395 (vm, "%U (%s): \n unnumbered, use %U",
396 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
397 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
398 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
402 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
403 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
405 /* Display any L2 info */
406 l2_input_config_t *l2_input = l2input_intf_config (si->sw_if_index);
407 if (l2_input->bridge)
409 bd_main_t *bdm = &bd_main;
410 u32 bd_id = l2input_main.bd_configs[l2_input->bd_index].bd_id;
411 vlib_cli_output (vm, " L2 bridge bd-id %d idx %d shg %d %s",
412 bd_id, bd_find_index (bdm, bd_id), l2_input->shg,
413 l2_input->bvi ? "bvi" : " ");
415 else if (l2_input->xconnect)
416 vlib_cli_output (vm, " L2 xconnect %U",
417 format_vnet_sw_if_index_name, vnm,
418 l2_input->output_sw_if_index);
421 /* Display any IP4 addressing info */
422 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
423 1 /* honor unnumbered */,
425 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
427 vlib_cli_output (vm, " L3 %U/%d ip4 table-id %d fib-idx %d",
428 format_ip4_address, r4, ia->address_length,
430 ip4_fib_index_from_table_id (fib4->table_id));
432 vlib_cli_output (vm, " L3 %U/%d",
433 format_ip4_address, r4, ia->address_length);
438 /* Display any IP6 addressing info */
439 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
440 1 /* honor unnumbered */,
442 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
444 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
445 format_ip6_address, r6, ia->address_length,
447 ip6_fib_index_from_table_id (fib6->table_id));
449 vlib_cli_output (vm, " L3 %U/%d",
450 format_ip6_address, r6, ia->address_length);
457 vec_foreach (si, sorted_sis)
459 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
464 vec_free (sorted_sis);
469 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
470 .path = "show interface",
471 .short_help = "show interface [address|addr|features|feat] [<interface> [<interface> [..]]] [verbose]",
472 .function = show_sw_interfaces,
476 /* Root of all interface commands. */
478 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
480 .short_help = "Interface commands",
485 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
486 .path = "set interface",
487 .short_help = "Interface commands",
491 static clib_error_t *
492 clear_interface_counters (vlib_main_t * vm,
493 unformat_input_t * input, vlib_cli_command_t * cmd)
495 vnet_main_t *vnm = vnet_get_main ();
496 vnet_interface_main_t *im = &vnm->interface_main;
497 vlib_simple_counter_main_t *sm;
498 vlib_combined_counter_main_t *cm;
499 static vnet_main_t **my_vnet_mains;
500 int i, j, n_counters;
502 vec_reset_length (my_vnet_mains);
504 for (i = 0; i < vec_len (vnet_mains); i++)
507 vec_add1 (my_vnet_mains, vnet_mains[i]);
510 if (vec_len (vnet_mains) == 0)
511 vec_add1 (my_vnet_mains, vnm);
513 n_counters = vec_len (im->combined_sw_if_counters);
515 for (j = 0; j < n_counters; j++)
517 for (i = 0; i < vec_len (my_vnet_mains); i++)
519 im = &my_vnet_mains[i]->interface_main;
520 cm = im->combined_sw_if_counters + j;
521 vlib_clear_combined_counters (cm);
525 n_counters = vec_len (im->sw_if_counters);
527 for (j = 0; j < n_counters; j++)
529 for (i = 0; i < vec_len (my_vnet_mains); i++)
531 im = &my_vnet_mains[i]->interface_main;
532 sm = im->sw_if_counters + j;
533 vlib_clear_simple_counters (sm);
541 * Clear the statistics for all interfaces (statistics associated with the
542 * '<em>show interface</em>' command).
545 * Example of how to clear the statistics for all interfaces:
546 * @cliexcmd{clear interfaces}
549 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
550 .path = "clear interfaces",
551 .short_help = "clear interfaces",
552 .function = clear_interface_counters,
557 * Parse subinterface names.
559 * The following subinterface syntax is supported. The first two are for
560 * backwards compatability:
563 * - a subinterface with the name <intf-name>.<id>. The subinterface
564 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
566 * <intf-name> <min_id>-<max_id>
567 * - a set of the above subinterfaces, repeating for each id
568 * in the range <min_id> to <max_id>
570 * In the following, exact-match semantics (i.e. the number of vlan tags on the
571 * packet must match the number of tags in the configuration) are used only if
572 * the keyword exact-match is present. Non-exact match is the default.
574 * <intf-name> <id> dot1q <outer_id> [exact-match]
575 * - a subinterface with the name <intf-name>.<id>. The subinterface
576 * is a single dot1q vlan with vlan id <outer_id>.
578 * <intf-name> <id> dot1q any [exact-match]
579 * - a subinterface with the name <intf-name>.<id>. The subinterface
580 * is a single dot1q vlan with any vlan id.
582 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
583 * - a subinterface with the name <intf-name>.<id>. The subinterface
584 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
587 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
588 * - a subinterface with the name <intf-name>.<id>. The subinterface
589 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
591 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
593 * - a subinterface with the name <intf-name>.<id>. The subinterface
594 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
596 * For each of the above CLI, there is a duplicate that uses the keyword
597 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
598 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
599 * tagged packets the inner ethertype is always 0x8100. Also note that
600 * the dot1q and dot1ad naming spaces are independent, so it is legal to
601 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
603 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
604 * - a subinterface with the name <intf-name>.<id>. The subinterface
605 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
608 * <intf-name> <id> untagged
609 * - a subinterface with the name <intf-name>.<id>. The subinterface
610 * has no vlan tags. Only one can be specified per interface.
612 * <intf-name> <id> default
613 * - a subinterface with the name <intf-name>.<id>. This is associated
614 * with a packet that did not match any other configured subinterface
615 * on this interface. Only one can be specified per interface.
618 static clib_error_t *
619 parse_vlan_sub_interfaces (unformat_input_t * input,
620 vnet_sw_interface_t * template)
622 clib_error_t *error = 0;
623 u32 inner_vlan, outer_vlan;
625 if (unformat (input, "any inner-dot1q any"))
627 template->sub.eth.flags.two_tags = 1;
628 template->sub.eth.flags.outer_vlan_id_any = 1;
629 template->sub.eth.flags.inner_vlan_id_any = 1;
631 else if (unformat (input, "any"))
633 template->sub.eth.flags.one_tag = 1;
634 template->sub.eth.flags.outer_vlan_id_any = 1;
636 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
638 template->sub.eth.flags.two_tags = 1;
639 template->sub.eth.flags.inner_vlan_id_any = 1;
640 template->sub.eth.outer_vlan_id = outer_vlan;
642 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
644 template->sub.eth.flags.two_tags = 1;
645 template->sub.eth.outer_vlan_id = outer_vlan;
646 template->sub.eth.inner_vlan_id = inner_vlan;
648 else if (unformat (input, "%d", &outer_vlan))
650 template->sub.eth.flags.one_tag = 1;
651 template->sub.eth.outer_vlan_id = outer_vlan;
655 error = clib_error_return (0, "expected dot1q config, got `%U'",
656 format_unformat_error, input);
660 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
662 if (unformat (input, "exact-match"))
664 template->sub.eth.flags.exact_match = 1;
672 static clib_error_t *
673 create_sub_interfaces (vlib_main_t * vm,
674 unformat_input_t * input, vlib_cli_command_t * cmd)
676 vnet_main_t *vnm = vnet_get_main ();
677 clib_error_t *error = 0;
678 u32 hw_if_index, sw_if_index;
679 vnet_hw_interface_t *hi;
680 u32 id, id_min, id_max;
681 vnet_sw_interface_t template;
684 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
686 error = clib_error_return (0, "unknown interface `%U'",
687 format_unformat_error, input);
691 clib_memset (&template, 0, sizeof (template));
692 template.sub.eth.raw_flags = 0;
694 if (unformat (input, "%d default", &id_min))
697 template.sub.eth.flags.default_sub = 1;
699 else if (unformat (input, "%d untagged", &id_min))
702 template.sub.eth.flags.no_tags = 1;
703 template.sub.eth.flags.exact_match = 1;
705 else if (unformat (input, "%d dot1q", &id_min))
707 /* parse dot1q config */
709 error = parse_vlan_sub_interfaces (input, &template);
713 else if (unformat (input, "%d dot1ad", &id_min))
715 /* parse dot1ad config */
717 template.sub.eth.flags.dot1ad = 1;
718 error = parse_vlan_sub_interfaces (input, &template);
722 else if (unformat (input, "%d-%d", &id_min, &id_max))
724 template.sub.eth.flags.one_tag = 1;
725 template.sub.eth.flags.exact_match = 1;
729 else if (unformat (input, "%d", &id_min))
732 template.sub.eth.flags.one_tag = 1;
733 template.sub.eth.outer_vlan_id = id_min;
734 template.sub.eth.flags.exact_match = 1;
739 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
740 format_unformat_error, input);
744 hi = vnet_get_hw_interface (vnm, hw_if_index);
746 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
749 clib_error_return (0,
750 "not allowed as %v belong to a BondEthernet interface",
755 for (id = id_min; id <= id_max; id++)
758 vnet_interface_main_t *im = &vnm->interface_main;
759 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
762 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
766 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
767 hi->sw_if_index, id);
771 kp = clib_mem_alloc (sizeof (*kp));
772 *kp = sup_and_sub_key;
774 template.type = VNET_SW_INTERFACE_TYPE_SUB;
775 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
776 template.sup_sw_if_index = hi->sw_if_index;
777 template.sub.id = id;
779 template.sub.eth.outer_vlan_id = id;
781 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
785 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
786 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
787 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
788 vnet_get_main (), sw_if_index);
796 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
797 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
798 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
799 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
800 * but this is not recommended.
802 * This command has several variations:
803 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
804 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
806 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
807 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
808 * match any other subinterfaces should be sent to this subinterface.
810 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
811 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
812 * to this subinterface.
814 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
815 * subinterfaces to handle a range of VLAN IDs.
817 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
818 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
819 * VLAN ID different from the '<em>subId</em>'.
821 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
822 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
825 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
826 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
827 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
828 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
829 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
830 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
831 * entered, then the default behavior is exact-match.
833 * Use the '<em>show interface</em>' command to display all subinterfaces.
837 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
838 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
840 * The previous example is shorthand and is equivalent to:
841 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
844 * Example of how to create a subinterface number that is different from the VLAN ID:
845 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
848 * Examples of how to create q-in-q and q-in-any subinterfaces:
849 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
850 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
852 * Examples of how to create dot1ad interfaces:
853 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
854 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
857 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
858 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
859 * is non-exact match:
860 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
862 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
863 * is specified and only one VLAN is configured, but packet contains two VLANs:
864 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
867 * Example of how to created a subinterface to process untagged packets:
868 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
870 * Example of how to created a subinterface to process any packet with a VLAN ID that
871 * does not match any other subinterface:
872 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
874 * When subinterfaces are created, they are in the down state. Example of how to
875 * enable a newly created subinterface:
876 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
880 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
881 .path = "create sub-interfaces",
882 .short_help = "create sub-interfaces <interface> "
883 "{<subId> [default|untagged]} | "
884 "{<subId>-<subId>} | "
885 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
886 .function = create_sub_interfaces,
890 static clib_error_t *
891 set_state (vlib_main_t * vm,
892 unformat_input_t * input, vlib_cli_command_t * cmd)
894 vnet_main_t *vnm = vnet_get_main ();
896 u32 sw_if_index, flags;
899 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
901 error = clib_error_return (0, "unknown interface `%U'",
902 format_unformat_error, input);
906 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
908 error = clib_error_return (0, "unknown flags `%U'",
909 format_unformat_error, input);
913 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
923 * This command is used to change the admin state (up/down) of an interface.
925 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
926 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
927 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
928 * '<em>punt</em>' flag (interface is still down).
931 * Example of how to configure the admin state of an interface to '<em>up</em?':
932 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
933 * Example of how to configure the admin state of an interface to '<em>down</em?':
934 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
937 VLIB_CLI_COMMAND (set_state_command, static) = {
938 .path = "set interface state",
939 .short_help = "set interface state <interface> [up|down|punt|enable]",
940 .function = set_state,
944 static clib_error_t *
945 set_unnumbered (vlib_main_t * vm,
946 unformat_input_t * input, vlib_cli_command_t * cmd)
948 vnet_main_t *vnm = vnet_get_main ();
949 u32 unnumbered_sw_if_index = ~0;
950 u32 inherit_from_sw_if_index = ~0;
953 if (unformat (input, "%U use %U",
954 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
955 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
957 else if (unformat (input, "del %U",
958 unformat_vnet_sw_interface, vnm,
959 &unnumbered_sw_if_index))
962 return clib_error_return (0, "parse error '%U'",
963 format_unformat_error, input);
965 if (~0 == unnumbered_sw_if_index)
966 return clib_error_return (0, "Specify the unnumbered interface");
967 if (enable && ~0 == inherit_from_sw_if_index)
968 return clib_error_return (0, "When enabling unnumbered specify the"
969 " IP enabled interface that it uses");
971 vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
972 inherit_from_sw_if_index, enable);
978 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
979 .path = "set interface unnumbered",
980 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
981 .function = set_unnumbered,
987 static clib_error_t *
988 set_hw_class (vlib_main_t * vm,
989 unformat_input_t * input, vlib_cli_command_t * cmd)
991 vnet_main_t *vnm = vnet_get_main ();
992 vnet_interface_main_t *im = &vnm->interface_main;
994 u32 hw_if_index, hw_class_index;
997 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
999 error = clib_error_return (0, "unknown hardware interface `%U'",
1000 format_unformat_error, input);
1004 if (!unformat_user (input, unformat_hash_string,
1005 im->hw_interface_class_by_name, &hw_class_index))
1007 error = clib_error_return (0, "unknown hardware class `%U'",
1008 format_unformat_error, input);
1012 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1021 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1022 .path = "set interface hw-class",
1023 .short_help = "Set interface hardware class",
1024 .function = set_hw_class,
1028 static clib_error_t *
1029 vnet_interface_cli_init (vlib_main_t * vm)
1034 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1036 static clib_error_t *
1037 renumber_interface_command_fn (vlib_main_t * vm,
1038 unformat_input_t * input,
1039 vlib_cli_command_t * cmd)
1042 u32 new_dev_instance;
1043 vnet_main_t *vnm = vnet_get_main ();
1046 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
1047 return clib_error_return (0, "unknown hardware interface `%U'",
1048 format_unformat_error, input);
1050 if (!unformat (input, "%d", &new_dev_instance))
1051 return clib_error_return (0, "new dev instance missing");
1053 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1061 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
1071 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1072 .path = "renumber interface",
1073 .short_help = "renumber interface <interface> <new-dev-instance>",
1074 .function = renumber_interface_command_fn,
1078 static clib_error_t *
1079 promiscuous_cmd (vlib_main_t * vm,
1080 unformat_input_t * input, vlib_cli_command_t * cmd)
1082 vnet_main_t *vnm = vnet_get_main ();
1084 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
1085 ethernet_main_t *em = ðernet_main;
1086 ethernet_interface_t *eif;
1088 if (unformat (input, "on %U",
1089 unformat_vnet_hw_interface, vnm, &hw_if_index))
1091 else if (unformat (input, "off %U",
1092 unformat_ethernet_interface, vnm, &hw_if_index))
1095 return clib_error_return (0, "unknown input `%U'",
1096 format_unformat_error, input);
1098 eif = ethernet_get_interface (em, hw_if_index);
1100 return clib_error_return (0, "not supported");
1102 ethernet_set_flags (vnm, hw_if_index, flags);
1107 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1108 .path = "set interface promiscuous",
1109 .short_help = "set interface promiscuous [on|off] <interface>",
1110 .function = promiscuous_cmd,
1114 static clib_error_t *
1115 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1117 vnet_main_t *vnm = vnet_get_main ();
1118 u32 hw_if_index, sw_if_index, mtu;
1119 ethernet_main_t *em = ðernet_main;
1120 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
1122 if (unformat (input, "%d %U", &mtu,
1123 unformat_vnet_hw_interface, vnm, &hw_if_index))
1126 * Change physical MTU on interface. Only supported for Ethernet
1129 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1130 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1133 return clib_error_return (0, "not supported");
1135 if (mtu < hi->min_supported_packet_bytes)
1136 return clib_error_return (0, "Invalid mtu (%d): "
1137 "must be >= min pkt bytes (%d)", mtu,
1138 hi->min_supported_packet_bytes);
1140 if (mtu > hi->max_supported_packet_bytes)
1141 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1142 hi->max_supported_packet_bytes);
1144 vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
1147 else if (unformat (input, "packet %d %U", &mtu,
1148 unformat_vnet_sw_interface, vnm, &sw_if_index))
1149 /* Set default packet MTU (including L3 header */
1150 mtus[VNET_MTU_L3] = mtu;
1151 else if (unformat (input, "ip4 %d %U", &mtu,
1152 unformat_vnet_sw_interface, vnm, &sw_if_index))
1153 mtus[VNET_MTU_IP4] = mtu;
1154 else if (unformat (input, "ip6 %d %U", &mtu,
1155 unformat_vnet_sw_interface, vnm, &sw_if_index))
1156 mtus[VNET_MTU_IP6] = mtu;
1157 else if (unformat (input, "mpls %d %U", &mtu,
1158 unformat_vnet_sw_interface, vnm, &sw_if_index))
1159 mtus[VNET_MTU_MPLS] = mtu;
1161 return clib_error_return (0, "unknown input `%U'",
1162 format_unformat_error, input);
1164 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1171 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1172 .path = "set interface mtu",
1173 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
1174 .function = mtu_cmd,
1178 static clib_error_t *
1179 set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1180 vlib_cli_command_t * cmd)
1182 vnet_main_t *vnm = vnet_get_main ();
1183 vnet_sw_interface_t *si = NULL;
1184 clib_error_t *error = 0;
1185 u32 sw_if_index = ~0;
1188 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1190 error = clib_error_return (0, "unknown interface `%U'",
1191 format_unformat_error, input);
1194 if (!unformat_user (input, unformat_ethernet_address, mac))
1196 error = clib_error_return (0, "expected mac address `%U'",
1197 format_unformat_error, input);
1200 si = vnet_get_sw_interface (vnm, sw_if_index);
1201 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
1207 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1208 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1209 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1213 * Example of how to change MAC Address of interface:
1214 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1215 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1216 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1217 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1221 VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1222 .path = "set interface mac address",
1223 .short_help = "set interface mac address <interface> <mac-address>",
1224 .function = set_interface_mac_address,
1228 static clib_error_t *
1229 set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1231 vnet_main_t *vnm = vnet_get_main ();
1232 u32 sw_if_index = ~0;
1235 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1236 vnm, &sw_if_index, &tag))
1237 return clib_error_return (0, "unknown input `%U'",
1238 format_unformat_error, input);
1240 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1246 VLIB_CLI_COMMAND (set_tag_command, static) = {
1247 .path = "set interface tag",
1248 .short_help = "set interface tag <interface> <tag>",
1249 .function = set_tag,
1253 static clib_error_t *
1254 clear_tag (vlib_main_t * vm, unformat_input_t * input,
1255 vlib_cli_command_t * cmd)
1257 vnet_main_t *vnm = vnet_get_main ();
1258 u32 sw_if_index = ~0;
1260 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1261 return clib_error_return (0, "unknown input `%U'",
1262 format_unformat_error, input);
1264 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1270 VLIB_CLI_COMMAND (clear_tag_command, static) = {
1271 .path = "clear interface tag",
1272 .short_help = "clear interface tag <interface>",
1273 .function = clear_tag,
1277 static clib_error_t *
1278 set_ip_directed_broadcast (vlib_main_t * vm,
1279 unformat_input_t * input, vlib_cli_command_t * cmd)
1281 vnet_main_t *vnm = vnet_get_main ();
1282 u32 sw_if_index = ~0;
1285 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1286 else if (unformat (input, "enable"))
1288 else if (unformat (input, "disable"))
1291 return clib_error_return (0, "unknown input: `%U'",
1292 format_unformat_error, input);
1294 if (~0 == sw_if_index)
1295 return clib_error_return (0, "specify an interface: `%U'",
1296 format_unformat_error, input);
1298 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1304 * This command is used to enable/disable IP directed broadcast
1305 * If directed broadcast is enabled a packet sent to the interface's
1306 * subnet broadcast address will be sent L2 broadcast on the interface,
1307 * otherwise it is dropped.
1310 VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1311 .path = "set interface ip directed-broadcast",
1312 .short_help = "set interface enable <interface> <enable|disable>",
1313 .function = set_ip_directed_broadcast,
1317 static clib_error_t *
1318 set_hw_interface_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1319 u32 queue_id, vnet_hw_interface_rx_mode mode)
1321 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1322 vnet_device_class_t *dev_class =
1323 vnet_get_device_class (vnm, hw->dev_class_index);
1324 clib_error_t *error;
1325 vnet_hw_interface_rx_mode old_mode;
1328 if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT)
1329 mode = hw->default_rx_mode;
1331 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &old_mode);
1335 if (old_mode == mode)
1336 return 0; /* same rx-mode, no change */
1338 case VNET_API_ERROR_INVALID_INTERFACE:
1339 return clib_error_return (0, "invalid interface");
1340 case VNET_API_ERROR_INVALID_QUEUE:
1341 return clib_error_return (0, "invalid queue");
1343 return clib_error_return (0, "unknown error");
1346 if (dev_class->rx_mode_change_function)
1348 error = dev_class->rx_mode_change_function (vnm, hw_if_index, queue_id,
1354 rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1359 case VNET_API_ERROR_UNSUPPORTED:
1360 return clib_error_return (0, "unsupported");
1361 case VNET_API_ERROR_INVALID_INTERFACE:
1362 return clib_error_return (0, "invalid interface");
1363 case VNET_API_ERROR_INVALID_QUEUE:
1364 return clib_error_return (0, "invalid queue");
1366 return clib_error_return (0, "unknown error");
1373 set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1374 u8 queue_id_valid, u32 queue_id,
1375 vnet_hw_interface_rx_mode mode)
1377 clib_error_t *error = 0;
1378 vnet_hw_interface_t *hw;
1381 hw = vnet_get_hw_interface (vnm, hw_if_index);
1383 if (queue_id_valid == 0)
1385 for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1387 error = set_hw_interface_rx_mode (vnm, hw_if_index, i, mode);
1391 hw->default_rx_mode = mode;
1394 error = set_hw_interface_rx_mode (vnm, hw_if_index, queue_id, mode);
1399 static clib_error_t *
1400 set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1401 vlib_cli_command_t * cmd)
1403 clib_error_t *error = 0;
1404 unformat_input_t _line_input, *line_input = &_line_input;
1405 vnet_main_t *vnm = vnet_get_main ();
1406 u32 hw_if_index = (u32) ~ 0;
1407 u32 queue_id = (u32) ~ 0;
1408 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
1409 u8 queue_id_valid = 0;
1411 if (!unformat_user (input, unformat_line_input, line_input))
1414 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1417 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1419 else if (unformat (line_input, "queue %d", &queue_id))
1421 else if (unformat (line_input, "polling"))
1422 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
1423 else if (unformat (line_input, "interrupt"))
1424 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
1425 else if (unformat (line_input, "adaptive"))
1426 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
1429 error = clib_error_return (0, "parse error: '%U'",
1430 format_unformat_error, line_input);
1431 unformat_free (line_input);
1436 unformat_free (line_input);
1438 if (hw_if_index == (u32) ~ 0)
1439 return clib_error_return (0, "please specify valid interface name");
1441 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
1442 return clib_error_return (0, "please specify valid rx-mode");
1444 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1451 * This command is used to assign the RX packet processing mode (polling,
1452 * interrupt, adaptive) of the a given interface, and optionally a
1453 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1454 * is applied to all queues of the interface. Not all interfaces support
1455 * all modes. To display the current rx-mode use the command
1456 * '<em>show interface rx-placement</em>'.
1459 * Example of how to assign rx-mode to all queues on an interface:
1460 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1461 * Example of how to assign rx-mode to one queue of an interface:
1462 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1463 * Example of how to display the rx-mode of all interfaces:
1464 * @cliexstart{show interface rx-placement}
1465 * Thread 1 (vpp_wk_0):
1467 * GigabitEthernet7/0/0 queue 0 (polling)
1468 * node vhost-user-input:
1469 * VirtualEthernet0/0/12 queue 0 (interrupt)
1470 * VirtualEthernet0/0/12 queue 2 (polling)
1471 * VirtualEthernet0/0/13 queue 0 (polling)
1472 * VirtualEthernet0/0/13 queue 2 (polling)
1473 * Thread 2 (vpp_wk_1):
1475 * GigabitEthernet7/0/1 queue 0 (polling)
1476 * node vhost-user-input:
1477 * VirtualEthernet0/0/12 queue 1 (polling)
1478 * VirtualEthernet0/0/12 queue 3 (polling)
1479 * VirtualEthernet0/0/13 queue 1 (polling)
1480 * VirtualEthernet0/0/13 queue 3 (polling)
1484 VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
1485 .path = "set interface rx-mode",
1486 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1487 .function = set_interface_rx_mode,
1491 static clib_error_t *
1492 show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1493 vlib_cli_command_t * cmd)
1496 vnet_main_t *vnm = vnet_get_main ();
1497 vnet_device_input_runtime_t *rt;
1498 vnet_device_and_queue_t *dq;
1499 vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
1504 foreach_vlib_main (({
1505 clib_bitmap_foreach (si, pn->sibling_bitmap,
1507 rt = vlib_node_get_runtime_data (this_vlib_main, si);
1509 if (vec_len (rt->devices_and_queues))
1510 s = format (s, " node %U:\n", format_vlib_node_name, vm, si);
1512 vec_foreach (dq, rt->devices_and_queues)
1514 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm,
1516 s = format (s, " %U queue %u (%U)\n",
1517 format_vnet_sw_if_index_name, vnm, hi->sw_if_index,
1519 format_vnet_hw_interface_rx_mode, dq->mode);
1522 if (vec_len (s) > 0)
1524 vlib_cli_output(vm, "Thread %u (%s):\n%v", index,
1525 vlib_worker_threads[index].name, s);
1526 vec_reset_length (s);
1537 * This command is used to display the interface and queue worker
1541 * Example of how to display the interface placement:
1542 * @cliexstart{show interface rx-placement}
1543 * Thread 1 (vpp_wk_0):
1545 * GigabitEthernet7/0/0 queue 0 (polling)
1546 * node vhost-user-input:
1547 * VirtualEthernet0/0/12 queue 0 (polling)
1548 * VirtualEthernet0/0/12 queue 2 (polling)
1549 * VirtualEthernet0/0/13 queue 0 (polling)
1550 * VirtualEthernet0/0/13 queue 2 (polling)
1551 * Thread 2 (vpp_wk_1):
1553 * GigabitEthernet7/0/1 queue 0 (polling)
1554 * node vhost-user-input:
1555 * VirtualEthernet0/0/12 queue 1 (polling)
1556 * VirtualEthernet0/0/12 queue 3 (polling)
1557 * VirtualEthernet0/0/13 queue 1 (polling)
1558 * VirtualEthernet0/0/13 queue 3 (polling)
1562 VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1563 .path = "show interface rx-placement",
1564 .short_help = "show interface rx-placement",
1565 .function = show_interface_rx_placement_fn,
1570 set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1571 u32 thread_index, u8 is_main)
1573 vnet_main_t *vnm = vnet_get_main ();
1574 vnet_device_main_t *vdm = &vnet_device_main;
1575 clib_error_t *error = 0;
1576 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
1582 thread_index += vdm->first_worker_thread_index;
1584 if (thread_index > vdm->last_worker_thread_index)
1585 return clib_error_return (0,
1586 "please specify valid worker thread or main");
1588 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode);
1591 return clib_error_return (0, "not found");
1593 rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id);
1596 return clib_error_return (0, "not found");
1598 vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id,
1600 vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1605 static clib_error_t *
1606 set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input,
1607 vlib_cli_command_t * cmd)
1609 clib_error_t *error = 0;
1610 unformat_input_t _line_input, *line_input = &_line_input;
1611 vnet_main_t *vnm = vnet_get_main ();
1612 u32 hw_if_index = (u32) ~ 0;
1613 u32 queue_id = (u32) 0;
1614 u32 thread_index = (u32) ~ 0;
1617 if (!unformat_user (input, unformat_line_input, line_input))
1620 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1623 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1625 else if (unformat (line_input, "queue %d", &queue_id))
1627 else if (unformat (line_input, "main", &thread_index))
1629 else if (unformat (line_input, "worker %d", &thread_index))
1633 error = clib_error_return (0, "parse error: '%U'",
1634 format_unformat_error, line_input);
1635 unformat_free (line_input);
1640 unformat_free (line_input);
1642 if (hw_if_index == (u32) ~ 0)
1643 return clib_error_return (0, "please specify valid interface name");
1645 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1652 * This command is used to assign a given interface, and optionally a
1653 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1654 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1655 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
1658 * Example of how to display the interface placement:
1659 * @cliexstart{show interface rx-placement}
1660 * Thread 1 (vpp_wk_0):
1662 * GigabitEthernet7/0/0 queue 0 (polling)
1663 * node vhost-user-input:
1664 * VirtualEthernet0/0/12 queue 0 (polling)
1665 * VirtualEthernet0/0/12 queue 2 (polling)
1666 * VirtualEthernet0/0/13 queue 0 (polling)
1667 * VirtualEthernet0/0/13 queue 2 (polling)
1668 * Thread 2 (vpp_wk_1):
1670 * GigabitEthernet7/0/1 queue 0 (polling)
1671 * node vhost-user-input:
1672 * VirtualEthernet0/0/12 queue 1 (polling)
1673 * VirtualEthernet0/0/12 queue 3 (polling)
1674 * VirtualEthernet0/0/13 queue 1 (polling)
1675 * VirtualEthernet0/0/13 queue 3 (polling)
1677 * Example of how to assign a interface and queue to a worker thread:
1678 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1679 * Example of how to display the interface placement:
1680 * @cliexstart{show interface rx-placement}
1681 * Thread 1 (vpp_wk_0):
1683 * GigabitEthernet7/0/0 queue 0 (polling)
1684 * node vhost-user-input:
1685 * VirtualEthernet0/0/12 queue 0 (polling)
1686 * VirtualEthernet0/0/12 queue 1 (polling)
1687 * VirtualEthernet0/0/12 queue 2 (polling)
1688 * VirtualEthernet0/0/13 queue 0 (polling)
1689 * VirtualEthernet0/0/13 queue 2 (polling)
1690 * Thread 2 (vpp_wk_1):
1692 * GigabitEthernet7/0/1 queue 0 (polling)
1693 * node vhost-user-input:
1694 * VirtualEthernet0/0/12 queue 3 (polling)
1695 * VirtualEthernet0/0/13 queue 1 (polling)
1696 * VirtualEthernet0/0/13 queue 3 (polling)
1700 VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1701 .path = "set interface rx-placement",
1702 .short_help = "set interface rx-placement <interface> [queue <n>] "
1703 "[worker <n> | main]",
1704 .function = set_interface_rx_placement,
1709 static inline clib_error_t *
1710 pcap_trace_command_internal (vlib_main_t * vm,
1711 unformat_input_t * input,
1712 vlib_cli_command_t * cmd, int rx_tx)
1714 #define PCAP_DEF_PKT_TO_CAPTURE (1000)
1716 unformat_input_t _line_input, *line_input = &_line_input;
1718 u8 *chroot_filename = 0;
1722 clib_error_t *error = 0;
1723 vnet_main_t *vnm = vnet_get_main ();
1725 /* Get a line of input. */
1726 if (!unformat_user (input, unformat_line_input, line_input))
1729 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1731 if (unformat (line_input, "on"))
1733 if (vm->pcap[rx_tx].pcap_enable == 0)
1739 vlib_cli_output (vm, "pcap %s capture already on...",
1740 (rx_tx == VLIB_RX) ? "rx" : "tx");
1745 else if (unformat (line_input, "off"))
1747 if (vm->pcap[rx_tx].pcap_enable)
1750 (vm, "captured %d pkts...",
1751 vm->pcap[rx_tx].pcap_main.n_packets_captured);
1752 if (vm->pcap[rx_tx].pcap_main.n_packets_captured)
1754 vm->pcap[rx_tx].pcap_main.n_packets_to_capture =
1755 vm->pcap[rx_tx].pcap_main.n_packets_captured;
1756 error = pcap_write (&vm->pcap[rx_tx].pcap_main);
1758 clib_error_report (error);
1760 vlib_cli_output (vm, "saved to %s...",
1761 vm->pcap[rx_tx].pcap_main.file_name);
1764 vm->pcap[rx_tx].pcap_enable = 0;
1768 vlib_cli_output (vm, "pcap %s capture already off...",
1769 (rx_tx == VLIB_RX) ? "rx" : "tx");
1774 else if (unformat (line_input, "max %d", &max))
1776 if (vm->pcap[rx_tx].pcap_enable)
1780 "can't change max value while pcap tx capture active...");
1784 vm->pcap[rx_tx].pcap_main.n_packets_to_capture = max;
1786 else if (unformat (line_input, "intfc %U",
1787 unformat_vnet_sw_interface, vnm,
1788 &vm->pcap[rx_tx].pcap_sw_if_index))
1791 else if (unformat (line_input, "intfc any"))
1793 vm->pcap[rx_tx].pcap_sw_if_index = 0;
1795 else if (unformat (line_input, "file %s", &filename))
1797 if (vm->pcap[rx_tx].pcap_enable)
1800 (vm, "can't change file while pcap tx capture active...");
1805 /* Brain-police user path input */
1806 if (strstr ((char *) filename, "..")
1807 || index ((char *) filename, '/'))
1809 vlib_cli_output (vm, "illegal characters in filename '%s'",
1811 vlib_cli_output (vm, "Hint: .. and / are not allowed.");
1812 vec_free (filename);
1817 chroot_filename = format (0, "/tmp/%s%c", filename, 0);
1818 vec_free (filename);
1820 else if (unformat (line_input, "status"))
1822 if (vm->pcap[rx_tx].pcap_sw_if_index == 0)
1825 (vm, "max is %d for any interface to file %s",
1826 vm->pcap[rx_tx].pcap_main.n_packets_to_capture ?
1827 vm->pcap[rx_tx].pcap_main.n_packets_to_capture
1828 : PCAP_DEF_PKT_TO_CAPTURE,
1829 vm->pcap[rx_tx].pcap_main.file_name ?
1830 (u8 *) vm->pcap[rx_tx].pcap_main.file_name :
1831 (u8 *) "/tmp/vpe.pcap");
1835 vlib_cli_output (vm, "max is %d for interface %U to file %s",
1836 vm->pcap[rx_tx].pcap_main.n_packets_to_capture
1838 pcap_main.n_packets_to_capture :
1839 PCAP_DEF_PKT_TO_CAPTURE,
1840 format_vnet_sw_if_index_name, vnm,
1841 vm->pcap[rx_tx].pcap_sw_if_index,
1843 pcap_main.file_name ? (u8 *) vm->pcap[rx_tx].
1844 pcap_main.file_name : (u8 *) "/tmp/vpe.pcap");
1847 if (vm->pcap[rx_tx].pcap_enable == 0)
1849 vlib_cli_output (vm, "pcap %s capture is off...",
1850 (rx_tx == VLIB_RX) ? "rx" : "tx");
1854 vlib_cli_output (vm, "pcap %s capture is on: %d of %d pkts...",
1855 (rx_tx == VLIB_RX) ? "rx" : "tx",
1856 vm->pcap[rx_tx].pcap_main.n_packets_captured,
1858 pcap_main.n_packets_to_capture);
1865 error = clib_error_return (0, "unknown input `%U'",
1866 format_unformat_error, line_input);
1871 unformat_free (line_input);
1876 /* Since no error, save configured values. */
1877 if (chroot_filename)
1879 if (vm->pcap[rx_tx].pcap_main.file_name)
1880 vec_free (vm->pcap[rx_tx].pcap_main.file_name);
1881 vec_add1 (chroot_filename, 0);
1882 vm->pcap[rx_tx].pcap_main.file_name = (char *) chroot_filename;
1886 vm->pcap[rx_tx].pcap_main.n_packets_to_capture = max;
1890 if (vm->pcap[rx_tx].pcap_main.file_name == 0)
1891 vm->pcap[rx_tx].pcap_main.file_name
1892 = (char *) format (0, "/tmp/vpe.pcap%c", 0);
1894 vm->pcap[rx_tx].pcap_main.n_packets_captured = 0;
1895 vm->pcap[rx_tx].pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet;
1896 if (vm->pcap[rx_tx].pcap_main.lock == 0)
1897 clib_spinlock_init (&(vm->pcap[rx_tx].pcap_main.lock));
1898 vm->pcap[rx_tx].pcap_enable = 1;
1899 vlib_cli_output (vm, "pcap %s capture on...",
1900 rx_tx == VLIB_RX ? "rx" : "tx");
1903 else if (chroot_filename)
1904 vec_free (chroot_filename);
1909 static clib_error_t *
1910 pcap_rx_trace_command_fn (vlib_main_t * vm,
1911 unformat_input_t * input, vlib_cli_command_t * cmd)
1913 return pcap_trace_command_internal (vm, input, cmd, VLIB_RX);
1916 static clib_error_t *
1917 pcap_tx_trace_command_fn (vlib_main_t * vm,
1918 unformat_input_t * input, vlib_cli_command_t * cmd)
1920 return pcap_trace_command_internal (vm, input, cmd, VLIB_TX);
1925 * This command is used to start or stop a packet capture, or show
1926 * the status of packet capture. Note that both "pcap rx trace" and
1927 * "pcap tx trace" are implemented. The command syntax is identical,
1928 * simply substitute rx for tx as needed.
1930 * This command has the following optional parameters:
1932 * - <b>on|off</b> - Used to start or stop a packet capture.
1934 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
1935 * of packets have been received, buffer is flushed to file. Once another
1936 * '<em>nn</em>' number of packets have been received, buffer is flushed
1937 * to file, overwriting previous write. If not entered, value defaults
1938 * to 100. Can only be updated if packet capture is off.
1940 * - <b>intfc <interface>|any</b> - Used to specify a given interface,
1941 * or use '<em>any</em>' to run packet capture on all interfaces.
1942 * '<em>any</em>' is the default if not provided. Settings from a previous
1943 * packet capture are preserved, so '<em>any</em>' can be used to reset
1944 * the interface setting.
1946 * - <b>file <name></b> - Used to specify the output filename. The file will
1947 * be placed in the '<em>/tmp</em>' directory, so only the filename is
1948 * supported. Directory should not be entered. If file already exists, file
1949 * will be overwritten. If no filename is provided, '<em>/tmp/vpe.pcap</em>'
1950 * will be used. Can only be updated if packet capture is off.
1952 * - <b>status</b> - Displays the current status and configured attributes
1953 * associated with a packet capture. If packet capture is in progress,
1954 * '<em>status</em>' also will return the number of packets currently in
1955 * the local buffer. All additional attributes entered on command line
1956 * with '<em>status</em>' will be ignored and not applied.
1959 * Example of how to display the status of a tx packet capture when off:
1960 * @cliexstart{pcap tx trace status}
1961 * max is 100, for any interface to file /tmp/vpe.pcap
1962 * pcap tx capture is off...
1964 * Example of how to start a tx packet capture:
1965 * @cliexstart{pcap tx trace on max 35 intfc GigabitEthernet0/8/0 file vppTest.pcap}
1966 * pcap tx capture on...
1968 * Example of how to display the status of a tx packet capture in progress:
1969 * @cliexstart{pcap tx trace status}
1970 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
1971 * pcap tx capture is on: 20 of 35 pkts...
1973 * Example of how to stop a tx packet capture:
1974 * @cliexstart{vppctl pcap tx trace off}
1975 * captured 21 pkts...
1976 * saved to /tmp/vppTest.pcap...
1981 VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
1982 .path = "pcap tx trace",
1984 "pcap tx trace [on|off] [max <nn>] [intfc <interface>|any] [file <name>] [status]",
1985 .function = pcap_tx_trace_command_fn,
1987 VLIB_CLI_COMMAND (pcap_rx_trace_command, static) = {
1988 .path = "pcap rx trace",
1990 "pcap rx trace [on|off] [max <nn>] [intfc <interface>|any] [file <name>] [status]",
1991 .function = pcap_rx_trace_command_fn,
1997 * fd.io coding-style-patch-verification: ON
2000 * eval: (c-set-style "gnu")