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.
41 * @brief Interface CLI.
43 * Source code for several CLI interface commands.
46 #include <vnet/vnet.h>
47 #include <vnet/ip/ip.h>
48 #include <vppinfra/bitmap.h>
49 #include <vnet/fib/ip4_fib.h>
50 #include <vnet/fib/ip6_fib.h>
51 #include <vnet/l2/l2_output.h>
52 #include <vnet/l2/l2_input.h>
53 #include <vnet/classify/vnet_classify.h>
54 #include <vnet/interface/rx_queue_funcs.h>
55 #include <vnet/interface/tx_queue_funcs.h>
56 #include <vnet/hash/hash.h>
58 compare_interface_names (void *a1, void *a2)
63 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
67 show_or_clear_hw_interfaces (vlib_main_t * vm,
68 unformat_input_t * input,
69 vlib_cli_command_t * cmd, int is_show)
71 clib_error_t *error = 0;
72 unformat_input_t _line_input, *line_input = &_line_input;
73 vnet_main_t *vnm = vnet_get_main ();
74 vnet_interface_main_t *im = &vnm->interface_main;
75 vnet_hw_interface_t *hi;
76 u32 hw_if_index, *hw_if_indices = 0;
77 int i, verbose = -1, show_bond = 0;
79 if (!unformat_user (input, unformat_line_input, line_input))
82 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
84 /* See if user wants to show a specific interface. */
85 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
87 vec_add1 (hw_if_indices, hw_if_index);
89 /* See if user wants to show an interface with a specific hw_if_index. */
90 else if (unformat (line_input, "%u", &hw_if_index))
91 vec_add1 (hw_if_indices, hw_if_index);
93 else if (unformat (line_input, "verbose"))
94 verbose = 1; /* this is also the default */
96 else if (unformat (line_input, "detail"))
99 else if (unformat (line_input, "brief"))
102 else if (unformat (line_input, "bond"))
106 verbose = 0; /* default to brief for link bonding */
111 error = clib_error_return (0, "unknown input `%U'",
112 format_unformat_error, line_input);
113 unformat_free (line_input);
118 unformat_free (line_input);
121 /* Gather interfaces. */
122 if (vec_len (hw_if_indices) == 0)
123 pool_foreach (hi, im->hw_interfaces)
124 vec_add1 (hw_if_indices, hi - im->hw_interfaces);
127 verbose = 1; /* default to verbose (except bond) */
132 vec_sort_with_function (hw_if_indices, compare_interface_names);
134 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
135 for (i = 0; i < vec_len (hw_if_indices); i++)
137 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
138 if (show_bond == 0) /* show all interfaces */
139 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
141 else if ((hi->bond_info) &&
142 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
143 { /* show only bonded interface and all its slave interfaces */
145 vnet_hw_interface_t *shi;
146 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
150 clib_bitmap_foreach (hw_idx, hi->bond_info)
152 shi = vnet_get_hw_interface(vnm, hw_idx);
153 vlib_cli_output (vm, "%U\n",
154 format_vnet_hw_interface, vnm, shi, verbose);
162 for (i = 0; i < vec_len (hw_if_indices); i++)
164 vnet_device_class_t *dc;
166 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
167 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
169 if (dc->clear_counters)
170 dc->clear_counters (hi->dev_instance);
175 vec_free (hw_if_indices);
179 static clib_error_t *
180 show_hw_interfaces (vlib_main_t * vm,
181 unformat_input_t * input, vlib_cli_command_t * cmd)
183 return show_or_clear_hw_interfaces (vm, input, cmd, 1 /* is_show */ );
186 static clib_error_t *
187 clear_hw_interfaces (vlib_main_t * vm,
188 unformat_input_t * input, vlib_cli_command_t * cmd)
190 return show_or_clear_hw_interfaces (vm, input, cmd, 0 /* is_show */ );
195 * Display more detailed information about all or a list of given interfaces.
196 * The verboseness of the output can be controlled by the following optional
198 * - brief: Only show name, index and state (default for bonded interfaces).
199 * - verbose: Also display additional attributes (default for all other interfaces).
200 * - detail: Also display all remaining attributes and extended statistics.
202 * To limit the output of the command to bonded interfaces and their slave
203 * interfaces, use the '<em>bond</em>' optional parameter.
206 * Example of how to display default data for all interfaces:
207 * @cliexstart{show hardware-interfaces}
208 * Name Idx Link Hardware
209 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
210 * Ethernet address ec:f4:bb:c0:bc:fc
212 * carrier up full duplex speed 1000 mtu 9216
213 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
215 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
216 * Ethernet address ec:f4:bb:c0:bc:fd
218 * carrier up full duplex speed 1000 mtu 9216
219 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
221 * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0
222 * Ethernet address 02:fe:a5:a9:8b:8e
223 * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1
224 * Ethernet address 02:fe:c0:4e:3b:b0
225 * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2
226 * Ethernet address 02:fe:1f:73:92:81
227 * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3
228 * Ethernet address 02:fe:f2:25:c4:68
229 * local0 0 down local0
232 * Example of how to display '<em>verbose</em>' data for an interface by name and
233 * software index (where 2 is the software index):
234 * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose}
235 * Name Idx Link Hardware
236 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
237 * Ethernet address ec:f4:bb:c0:bc:fc
239 * carrier up full duplex speed 1000 mtu 9216
240 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
242 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
243 * Ethernet address ec:f4:bb:c0:bc:fd
245 * carrier up full duplex speed 1000 mtu 9216
246 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
251 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
252 .path = "show hardware-interfaces",
253 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
254 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
255 .function = show_hw_interfaces,
261 * Clear the extended statistics for all or a list of given interfaces
262 * (statistics associated with the '<em>show hardware-interfaces</em>' command).
265 * Example of how to clear the extended statistics for all interfaces:
266 * @cliexcmd{clear hardware-interfaces}
267 * Example of how to clear the extended statistics for an interface by
268 * name and software index (where 2 is the software index):
269 * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2}
272 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
273 .path = "clear hardware-interfaces",
274 .short_help = "clear hardware-interfaces "
275 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
276 .function = clear_hw_interfaces,
281 sw_interface_name_compare (void *a1, void *a2)
283 vnet_sw_interface_t *si1 = a1;
284 vnet_sw_interface_t *si2 = a2;
286 return vnet_sw_interface_compare (vnet_get_main (),
287 si1->sw_if_index, si2->sw_if_index);
290 static clib_error_t *
291 show_sw_interfaces (vlib_main_t * vm,
292 unformat_input_t * input, vlib_cli_command_t * cmd)
294 clib_error_t *error = 0;
295 vnet_main_t *vnm = vnet_get_main ();
296 unformat_input_t _linput, *linput = &_linput;
297 vnet_interface_main_t *im = &vnm->interface_main;
298 vnet_sw_interface_t *si, *sorted_sis = 0;
299 u32 sw_if_index = ~(u32) 0;
300 u8 show_addresses = 0;
301 u8 show_features = 0;
307 * Get a line of input. Won't work if the user typed
308 * "show interface" and nothing more.
310 if (unformat_user (input, unformat_line_input, linput))
312 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
314 /* See if user wants to show specific interface */
316 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
318 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
319 vec_add1 (sorted_sis, si[0]);
321 else if (unformat (linput, "address") || unformat (linput, "addr"))
323 else if (unformat (linput, "features") || unformat (linput, "feat"))
325 else if (unformat (linput, "tag"))
327 else if (unformat (linput, "vtr"))
329 else if (unformat (linput, "verbose"))
331 else if (unformat (linput, "%d", &sw_if_index))
333 if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
335 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
336 vec_add1 (sorted_sis, si[0]);
340 vec_free (sorted_sis);
341 error = clib_error_return (0, "unknown interface index `%d'",
348 vec_free (sorted_sis);
349 error = clib_error_return (0, "unknown input `%U'",
350 format_unformat_error, linput);
354 unformat_free (linput);
356 if (show_features || show_tag || show_vtr)
358 if (sw_if_index == ~(u32) 0)
360 vec_free (sorted_sis);
361 return clib_error_return (0, "Interface not specified...");
367 vnet_interface_features_show (vm, sw_if_index, verbose);
368 vlib_cli_output (vm, "%U", format_l2_input_features, sw_if_index, 1);
370 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
371 vlib_cli_output (vm, "\nl2-output:");
372 if (l2_output->out_vtr_flag)
373 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
374 vlib_cli_output (vm, "%U", format_l2_output_features,
375 l2_output->feature_bitmap, 1);
376 vec_free (sorted_sis);
382 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
383 vlib_cli_output (vm, "%U: %s",
384 format_vnet_sw_if_index_name, vnm, sw_if_index,
385 tag ? (char *) tag : "(none)");
386 vec_free (sorted_sis);
391 * Show vlan tag rewrite data for one interface.
395 u32 vtr_op = L2_VTR_DISABLED;
396 u32 push_dot1q = 0, tag1 = 0, tag2 = 0;
398 if (l2vtr_get (vm, vnm, sw_if_index,
399 &vtr_op, &push_dot1q, &tag1, &tag2) != 0)
401 vlib_cli_output (vm, "%U: Problem getting vlan tag-rewrite data",
402 format_vnet_sw_if_index_name, vnm, sw_if_index);
405 vlib_cli_output (vm, "%U: VTR %0U",
406 format_vnet_sw_if_index_name, vnm, sw_if_index,
407 format_vtr, vtr_op, push_dot1q, tag1, tag2);
412 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
414 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
416 /* Gather interfaces. */
418 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
419 vec_set_len (sorted_sis, 0);
421 pool_foreach (si, im->sw_interfaces)
423 int visible = vnet_swif_is_api_visible (si);
425 vec_add1 (sorted_sis, si[0]);
429 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
434 vec_foreach (si, sorted_sis)
436 ip4_main_t *im4 = &ip4_main;
437 ip6_main_t *im6 = &ip6_main;
438 ip_lookup_main_t *lm4 = &im4->lookup_main;
439 ip_lookup_main_t *lm6 = &im6->lookup_main;
440 ip_interface_address_t *ia = 0;
441 u32 fib_index4 = 0, fib_index6 = 0;
443 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
444 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
447 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
448 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
451 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
452 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
454 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
456 (vm, "%U (%s): \n unnumbered, use %U",
457 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
458 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
459 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
463 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
464 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
466 /* Display any L2 info */
467 vlib_cli_output (vm, "%U", format_l2_input, si->sw_if_index);
470 /* Display any IP4 addressing info */
471 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
472 1 /* honor unnumbered */,
474 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
475 if (fib4->hash.table_id)
477 vm, " L3 %U/%d ip4 table-id %d fib-idx %d", format_ip4_address,
478 r4, ia->address_length, fib4->hash.table_id,
479 ip4_fib_index_from_table_id (fib4->hash.table_id));
481 vlib_cli_output (vm, " L3 %U/%d",
482 format_ip4_address, r4, ia->address_length);
487 /* Display any IP6 addressing info */
488 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
489 1 /* honor unnumbered */,
491 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
493 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
494 format_ip6_address, r6, ia->address_length,
496 ip6_fib_index_from_table_id (fib6->table_id));
498 vlib_cli_output (vm, " L3 %U/%d",
499 format_ip6_address, r6, ia->address_length);
506 vec_foreach (si, sorted_sis)
508 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
513 vec_free (sorted_sis);
518 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
519 .path = "show interface",
520 .short_help = "show interface [address|addr|features|feat|vtr] [<interface> [<interface> [..]]] [verbose]",
521 .function = show_sw_interfaces,
526 /* Root of all interface commands. */
528 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
530 .short_help = "Interface commands",
535 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
536 .path = "set interface",
537 .short_help = "Interface commands",
541 static clib_error_t *
542 clear_interface_counters (vlib_main_t * vm,
543 unformat_input_t * input, vlib_cli_command_t * cmd)
545 vnet_main_t *vnm = vnet_get_main ();
546 vnet_interface_main_t *im = &vnm->interface_main;
547 vlib_simple_counter_main_t *sm;
548 vlib_combined_counter_main_t *cm;
551 n_counters = vec_len (im->combined_sw_if_counters);
553 for (j = 0; j < n_counters; j++)
555 im = &vnm->interface_main;
556 cm = im->combined_sw_if_counters + j;
557 vlib_clear_combined_counters (cm);
560 n_counters = vec_len (im->sw_if_counters);
562 for (j = 0; j < n_counters; j++)
564 im = &vnm->interface_main;
565 sm = im->sw_if_counters + j;
566 vlib_clear_simple_counters (sm);
573 * Clear the statistics for all interfaces (statistics associated with the
574 * '<em>show interface</em>' command).
577 * Example of how to clear the statistics for all interfaces:
578 * @cliexcmd{clear interfaces}
581 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
582 .path = "clear interfaces",
583 .short_help = "clear interfaces",
584 .function = clear_interface_counters,
589 * Parse subinterface names.
591 * The following subinterface syntax is supported. The first two are for
592 * backwards compatability:
595 * - a subinterface with the name <intf-name>.<id>. The subinterface
596 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
598 * <intf-name> <min_id>-<max_id>
599 * - a set of the above subinterfaces, repeating for each id
600 * in the range <min_id> to <max_id>
602 * In the following, exact-match semantics (i.e. the number of vlan tags on the
603 * packet must match the number of tags in the configuration) are used only if
604 * the keyword exact-match is present. Non-exact match is the default.
606 * <intf-name> <id> dot1q <outer_id> [exact-match]
607 * - a subinterface with the name <intf-name>.<id>. The subinterface
608 * is a single dot1q vlan with vlan id <outer_id>.
610 * <intf-name> <id> dot1q any [exact-match]
611 * - a subinterface with the name <intf-name>.<id>. The subinterface
612 * is a single dot1q vlan with any vlan id.
614 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
615 * - a subinterface with the name <intf-name>.<id>. The subinterface
616 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
619 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
620 * - a subinterface with the name <intf-name>.<id>. The subinterface
621 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
623 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
625 * - a subinterface with the name <intf-name>.<id>. The subinterface
626 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
628 * For each of the above CLI, there is a duplicate that uses the keyword
629 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
630 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
631 * tagged packets the inner ethertype is always 0x8100. Also note that
632 * the dot1q and dot1ad naming spaces are independent, so it is legal to
633 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
635 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
636 * - a subinterface with the name <intf-name>.<id>. The subinterface
637 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
640 * <intf-name> <id> untagged
641 * - a subinterface with the name <intf-name>.<id>. The subinterface
642 * has no vlan tags. Only one can be specified per interface.
644 * <intf-name> <id> default
645 * - a subinterface with the name <intf-name>.<id>. This is associated
646 * with a packet that did not match any other configured subinterface
647 * on this interface. Only one can be specified per interface.
650 static clib_error_t *
651 parse_vlan_sub_interfaces (unformat_input_t * input,
652 vnet_sw_interface_t * template)
654 clib_error_t *error = 0;
655 u32 inner_vlan, outer_vlan;
657 if (unformat (input, "any inner-dot1q any"))
659 template->sub.eth.flags.two_tags = 1;
660 template->sub.eth.flags.outer_vlan_id_any = 1;
661 template->sub.eth.flags.inner_vlan_id_any = 1;
663 else if (unformat (input, "any"))
665 template->sub.eth.flags.one_tag = 1;
666 template->sub.eth.flags.outer_vlan_id_any = 1;
668 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
670 template->sub.eth.flags.two_tags = 1;
671 template->sub.eth.flags.inner_vlan_id_any = 1;
672 template->sub.eth.outer_vlan_id = outer_vlan;
674 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
676 template->sub.eth.flags.two_tags = 1;
677 template->sub.eth.outer_vlan_id = outer_vlan;
678 template->sub.eth.inner_vlan_id = inner_vlan;
680 else if (unformat (input, "%d", &outer_vlan))
682 template->sub.eth.flags.one_tag = 1;
683 template->sub.eth.outer_vlan_id = outer_vlan;
687 error = clib_error_return (0, "expected dot1q config, got `%U'",
688 format_unformat_error, input);
692 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
694 if (unformat (input, "exact-match"))
696 template->sub.eth.flags.exact_match = 1;
704 static clib_error_t *
705 create_sub_interfaces (vlib_main_t * vm,
706 unformat_input_t * input, vlib_cli_command_t * cmd)
708 vnet_main_t *vnm = vnet_get_main ();
709 clib_error_t *error = 0;
710 u32 hw_if_index, sw_if_index;
711 vnet_hw_interface_t *hi;
712 u32 id, id_min, id_max;
713 vnet_sw_interface_t template;
716 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
718 error = clib_error_return (0, "unknown interface `%U'",
719 format_unformat_error, input);
723 clib_memset (&template, 0, sizeof (template));
724 template.sub.eth.raw_flags = 0;
726 if (unformat (input, "%d default", &id_min))
729 template.sub.eth.flags.default_sub = 1;
731 else if (unformat (input, "%d untagged", &id_min))
734 template.sub.eth.flags.no_tags = 1;
735 template.sub.eth.flags.exact_match = 1;
737 else if (unformat (input, "%d dot1q", &id_min))
739 /* parse dot1q config */
741 error = parse_vlan_sub_interfaces (input, &template);
745 else if (unformat (input, "%d dot1ad", &id_min))
747 /* parse dot1ad config */
749 template.sub.eth.flags.dot1ad = 1;
750 error = parse_vlan_sub_interfaces (input, &template);
754 else if (unformat (input, "%d-%d", &id_min, &id_max))
756 template.sub.eth.flags.one_tag = 1;
757 template.sub.eth.flags.exact_match = 1;
761 else if (unformat (input, "%d", &id_min))
764 template.sub.eth.flags.one_tag = 1;
765 template.sub.eth.outer_vlan_id = id_min;
766 template.sub.eth.flags.exact_match = 1;
771 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
772 format_unformat_error, input);
776 hi = vnet_get_hw_interface (vnm, hw_if_index);
778 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
781 clib_error_return (0,
782 "not allowed as %v belong to a BondEthernet interface",
787 for (id = id_min; id <= id_max; id++)
790 vnet_interface_main_t *im = &vnm->interface_main;
791 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
794 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
798 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
799 hi->sw_if_index, id);
803 template.type = VNET_SW_INTERFACE_TYPE_SUB;
804 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
805 template.sup_sw_if_index = hi->sw_if_index;
806 template.sub.id = id;
808 template.sub.eth.outer_vlan_id = id;
810 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
814 kp = clib_mem_alloc (sizeof (*kp));
815 *kp = sup_and_sub_key;
817 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
818 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
819 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
820 vnet_get_main (), sw_if_index);
828 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
829 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
830 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
831 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
832 * but this is not recommended.
834 * This command has several variations:
835 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
836 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
838 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
839 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
840 * match any other subinterfaces should be sent to this subinterface.
842 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
843 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
844 * to this subinterface.
846 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
847 * subinterfaces to handle a range of VLAN IDs.
849 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
850 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
851 * VLAN ID different from the '<em>subId</em>'.
853 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
854 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
857 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
858 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
859 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
860 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
861 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
862 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
863 * entered, then the default behavior is exact-match.
865 * Use the '<em>show interface</em>' command to display all subinterfaces.
869 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
870 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
872 * The previous example is shorthand and is equivalent to:
873 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
876 * Example of how to create a subinterface number that is different from the VLAN ID:
877 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
880 * Examples of how to create q-in-q and q-in-any subinterfaces:
881 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
882 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
884 * Examples of how to create dot1ad interfaces:
885 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
886 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
889 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
890 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
891 * is non-exact match:
892 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
894 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
895 * is specified and only one VLAN is configured, but packet contains two VLANs:
896 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
899 * Example of how to created a subinterface to process untagged packets:
900 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
902 * Example of how to created a subinterface to process any packet with a VLAN ID that
903 * does not match any other subinterface:
904 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
906 * When subinterfaces are created, they are in the down state. Example of how to
907 * enable a newly created subinterface:
908 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
912 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
913 .path = "create sub-interfaces",
914 .short_help = "create sub-interfaces <interface> "
915 "{<subId> [default|untagged]} | "
916 "{<subId>-<subId>} | "
917 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
918 .function = create_sub_interfaces,
922 static clib_error_t *
923 set_state (vlib_main_t * vm,
924 unformat_input_t * input, vlib_cli_command_t * cmd)
926 vnet_main_t *vnm = vnet_get_main ();
928 u32 sw_if_index, flags;
931 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
933 error = clib_error_return (0, "unknown interface `%U'",
934 format_unformat_error, input);
938 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
940 error = clib_error_return (0, "unknown flags `%U'",
941 format_unformat_error, input);
945 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
954 * This command is used to change the admin state (up/down) of an interface.
956 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
957 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
958 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
959 * '<em>punt</em>' flag (interface is still down).
962 * Example of how to configure the admin state of an interface to
964 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
965 * Example of how to configure the admin state of an interface to
967 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
970 VLIB_CLI_COMMAND (set_state_command, static) = {
971 .path = "set interface state",
972 .short_help = "set interface state <interface> [up|down|punt|enable]",
973 .function = set_state,
977 static clib_error_t *
978 set_unnumbered (vlib_main_t * vm,
979 unformat_input_t * input, vlib_cli_command_t * cmd)
981 vnet_main_t *vnm = vnet_get_main ();
982 u32 unnumbered_sw_if_index = ~0;
983 u32 inherit_from_sw_if_index = ~0;
986 if (unformat (input, "%U use %U",
987 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
988 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
990 else if (unformat (input, "del %U",
991 unformat_vnet_sw_interface, vnm,
992 &unnumbered_sw_if_index))
995 return clib_error_return (0, "parse error '%U'",
996 format_unformat_error, input);
998 if (~0 == unnumbered_sw_if_index)
999 return clib_error_return (0, "Specify the unnumbered interface");
1000 if (enable && ~0 == inherit_from_sw_if_index)
1001 return clib_error_return (0, "When enabling unnumbered specify the"
1002 " IP enabled interface that it uses");
1004 int rv = vnet_sw_interface_update_unnumbered (
1005 unnumbered_sw_if_index, inherit_from_sw_if_index, enable);
1012 case VNET_API_ERROR_UNEXPECTED_INTF_STATE:
1013 return clib_error_return (
1015 "When enabling unnumbered both interfaces must be in the same tables");
1018 return clib_error_return (
1019 0, "vnet_sw_interface_update_unnumbered returned %d", rv);
1026 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
1027 .path = "set interface unnumbered",
1028 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
1029 .function = set_unnumbered,
1035 static clib_error_t *
1036 set_hw_class (vlib_main_t * vm,
1037 unformat_input_t * input, vlib_cli_command_t * cmd)
1039 vnet_main_t *vnm = vnet_get_main ();
1040 vnet_interface_main_t *im = &vnm->interface_main;
1041 clib_error_t *error;
1042 u32 hw_if_index, hw_class_index;
1045 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
1047 error = clib_error_return (0, "unknown hardware interface `%U'",
1048 format_unformat_error, input);
1052 if (!unformat_user (input, unformat_hash_string,
1053 im->hw_interface_class_by_name, &hw_class_index))
1055 error = clib_error_return (0, "unknown hardware class `%U'",
1056 format_unformat_error, input);
1060 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1069 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1070 .path = "set interface hw-class",
1071 .short_help = "Set interface hardware class",
1072 .function = set_hw_class,
1076 static clib_error_t *
1077 vnet_interface_cli_init (vlib_main_t * vm)
1082 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1084 static clib_error_t *
1085 renumber_interface_command_fn (vlib_main_t * vm,
1086 unformat_input_t * input,
1087 vlib_cli_command_t * cmd)
1090 u32 new_dev_instance;
1091 vnet_main_t *vnm = vnet_get_main ();
1094 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
1095 return clib_error_return (0, "unknown hardware interface `%U'",
1096 format_unformat_error, input);
1098 if (!unformat (input, "%d", &new_dev_instance))
1099 return clib_error_return (0, "new dev instance missing");
1101 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1109 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
1119 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1120 .path = "renumber interface",
1121 .short_help = "renumber interface <interface> <new-dev-instance>",
1122 .function = renumber_interface_command_fn,
1126 static clib_error_t *
1127 promiscuous_cmd (vlib_main_t * vm,
1128 unformat_input_t * input, vlib_cli_command_t * cmd)
1130 vnet_main_t *vnm = vnet_get_main ();
1132 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
1133 ethernet_main_t *em = ðernet_main;
1134 ethernet_interface_t *eif;
1136 if (unformat (input, "on %U",
1137 unformat_vnet_hw_interface, vnm, &hw_if_index))
1139 else if (unformat (input, "off %U",
1140 unformat_ethernet_interface, vnm, &hw_if_index))
1143 return clib_error_return (0, "unknown input `%U'",
1144 format_unformat_error, input);
1146 eif = ethernet_get_interface (em, hw_if_index);
1148 return clib_error_return (0, "not supported");
1150 ethernet_set_flags (vnm, hw_if_index, flags);
1155 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1156 .path = "set interface promiscuous",
1157 .short_help = "set interface promiscuous [on|off] <interface>",
1158 .function = promiscuous_cmd,
1162 static clib_error_t *
1163 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1165 vnet_main_t *vnm = vnet_get_main ();
1166 u32 hw_if_index, sw_if_index, mtu;
1167 ethernet_main_t *em = ðernet_main;
1168 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
1171 if (unformat (input, "%d %U", &mtu,
1172 unformat_vnet_hw_interface, vnm, &hw_if_index))
1175 * Change physical MTU on interface. Only supported for Ethernet
1178 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1181 return clib_error_return (0, "not supported");
1183 err = vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
1188 else if (unformat (input, "packet %d %U", &mtu,
1189 unformat_vnet_sw_interface, vnm, &sw_if_index))
1190 /* Set default packet MTU (including L3 header */
1191 mtus[VNET_MTU_L3] = mtu;
1192 else if (unformat (input, "ip4 %d %U", &mtu,
1193 unformat_vnet_sw_interface, vnm, &sw_if_index))
1194 mtus[VNET_MTU_IP4] = mtu;
1195 else if (unformat (input, "ip6 %d %U", &mtu,
1196 unformat_vnet_sw_interface, vnm, &sw_if_index))
1197 mtus[VNET_MTU_IP6] = mtu;
1198 else if (unformat (input, "mpls %d %U", &mtu,
1199 unformat_vnet_sw_interface, vnm, &sw_if_index))
1200 mtus[VNET_MTU_MPLS] = mtu;
1202 return clib_error_return (0, "unknown input `%U'",
1203 format_unformat_error, input);
1205 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1212 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1213 .path = "set interface mtu",
1214 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
1215 .function = mtu_cmd,
1219 static clib_error_t *
1220 show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input,
1221 vlib_cli_command_t * cmd)
1223 vnet_main_t *vnm = vnet_get_main ();
1224 vnet_interface_main_t *im = &vnm->interface_main;
1225 ethernet_main_t *em = ðernet_main;
1226 u32 sw_if_index = ~0;
1227 vnet_sw_interface_t *si, *sorted_sis = 0;
1229 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1231 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1232 vec_add1 (sorted_sis, si[0]);
1235 /* if an interface name was not passed, get all interfaces */
1236 if (vec_len (sorted_sis) == 0)
1239 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
1240 vec_set_len (sorted_sis, 0);
1242 pool_foreach (si, im->sw_interfaces)
1244 int visible = vnet_swif_is_api_visible (si);
1246 vec_add1 (sorted_sis, si[0]);
1250 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
1253 vec_foreach (si, sorted_sis)
1255 vnet_sw_interface_t *sup_si;
1256 ethernet_interface_t *ei;
1258 sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
1259 ei = ethernet_get_interface (em, sup_si->hw_if_index);
1261 vlib_cli_output (vm, "%U (%s):",
1262 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
1263 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
1266 if (ei && ei->secondary_addrs)
1268 ethernet_interface_address_t *sec_addr;
1270 vec_foreach (sec_addr, ei->secondary_addrs)
1272 vlib_cli_output (vm, " %U", format_mac_address_t, &sec_addr->mac);
1277 vec_free (sorted_sis);
1282 * This command is used to display interface secondary mac addresses.
1285 * Example of how to display interface secondary mac addresses:
1286 * @cliexstart{show interface secondary-mac-address}
1290 VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = {
1291 .path = "show interface secondary-mac-address",
1292 .short_help = "show interface secondary-mac-address [<interface>]",
1293 .function = show_interface_sec_mac_addr_fn,
1297 static clib_error_t *
1298 interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input,
1299 vlib_cli_command_t * cmd)
1301 vnet_main_t *vnm = vnet_get_main ();
1302 vnet_sw_interface_t *si = NULL;
1303 clib_error_t *error = 0;
1304 u32 sw_if_index = ~0;
1308 is_add = is_del = 0;
1310 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1312 error = clib_error_return (0, "unknown interface `%U'",
1313 format_unformat_error, input);
1316 if (!unformat_user (input, unformat_ethernet_address, mac))
1318 error = clib_error_return (0, "expected mac address `%U'",
1319 format_unformat_error, input);
1323 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1325 if (unformat (input, "add"))
1327 else if (unformat (input, "del"))
1333 if (is_add == is_del)
1335 error = clib_error_return (0, "must choose one of add or del");
1339 si = vnet_get_sw_interface (vnm, sw_if_index);
1341 vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add);
1348 * The '<em>set interface secondary-mac-address </em>' command allows adding
1349 * or deleting extra MAC addresses on a given interface without changing the
1350 * default MAC address. This could allow packets sent to these MAC addresses
1351 * to be received without setting the interface to promiscuous mode.
1352 * Not all interfaces support this operation. The ones that do are mostly
1353 * hardware NICs, though virtio does also.
1357 * Example of how to add a secondary MAC Address on an interface:
1358 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add}
1359 * Example of how to delete a secondary MAC address from an interface:
1360 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del}
1364 VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = {
1365 .path = "set interface secondary-mac-address",
1366 .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]",
1367 .function = interface_add_del_mac_address,
1371 static clib_error_t *
1372 set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1373 vlib_cli_command_t * cmd)
1375 vnet_main_t *vnm = vnet_get_main ();
1376 vnet_sw_interface_t *si = NULL;
1377 clib_error_t *error = 0;
1378 u32 sw_if_index = ~0;
1381 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1383 error = clib_error_return (0, "unknown interface `%U'",
1384 format_unformat_error, input);
1387 if (!unformat_user (input, unformat_ethernet_address, mac))
1389 error = clib_error_return (0, "expected mac address `%U'",
1390 format_unformat_error, input);
1393 si = vnet_get_sw_interface (vnm, sw_if_index);
1394 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
1400 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1401 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1402 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1406 * Example of how to change MAC Address of interface:
1407 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1408 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1409 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1410 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1414 VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1415 .path = "set interface mac address",
1416 .short_help = "set interface mac address <interface> <mac-address>",
1417 .function = set_interface_mac_address,
1421 static clib_error_t *
1422 set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1424 vnet_main_t *vnm = vnet_get_main ();
1425 u32 sw_if_index = ~0;
1428 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1429 vnm, &sw_if_index, &tag))
1430 return clib_error_return (0, "unknown input `%U'",
1431 format_unformat_error, input);
1433 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1439 VLIB_CLI_COMMAND (set_tag_command, static) = {
1440 .path = "set interface tag",
1441 .short_help = "set interface tag <interface> <tag>",
1442 .function = set_tag,
1446 static clib_error_t *
1447 clear_tag (vlib_main_t * vm, unformat_input_t * input,
1448 vlib_cli_command_t * cmd)
1450 vnet_main_t *vnm = vnet_get_main ();
1451 u32 sw_if_index = ~0;
1453 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1454 return clib_error_return (0, "unknown input `%U'",
1455 format_unformat_error, input);
1457 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1463 VLIB_CLI_COMMAND (clear_tag_command, static) = {
1464 .path = "clear interface tag",
1465 .short_help = "clear interface tag <interface>",
1466 .function = clear_tag,
1470 static clib_error_t *
1471 set_ip_directed_broadcast (vlib_main_t * vm,
1472 unformat_input_t * input, vlib_cli_command_t * cmd)
1474 vnet_main_t *vnm = vnet_get_main ();
1475 u32 sw_if_index = ~0;
1478 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1479 else if (unformat (input, "enable"))
1481 else if (unformat (input, "disable"))
1484 return clib_error_return (0, "unknown input: `%U'",
1485 format_unformat_error, input);
1487 if (~0 == sw_if_index)
1488 return clib_error_return (0, "specify an interface: `%U'",
1489 format_unformat_error, input);
1491 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1497 * This command is used to enable/disable IP directed broadcast
1498 * If directed broadcast is enabled a packet sent to the interface's
1499 * subnet broadcast address will be sent L2 broadcast on the interface,
1500 * otherwise it is dropped.
1503 VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1504 .path = "set interface ip directed-broadcast",
1505 .short_help = "set interface enable <interface> <enable|disable>",
1506 .function = set_ip_directed_broadcast,
1511 set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1512 u8 queue_id_valid, u32 queue_id,
1513 vnet_hw_if_rx_mode mode)
1515 clib_error_t *error = 0;
1516 vnet_hw_interface_t *hw;
1517 u32 *queue_indices = 0;
1519 hw = vnet_get_hw_interface (vnm, hw_if_index);
1525 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1526 if (queue_index == ~0)
1527 return clib_error_return (0, "unknown queue %u on interface %s",
1528 queue_id, hw->name);
1529 vec_add1 (queue_indices, queue_index);
1532 queue_indices = hw->rx_queue_indices;
1534 for (int i = 0; i < vec_len (queue_indices); i++)
1536 int rv = vnet_hw_if_set_rx_queue_mode (vnm, queue_indices[i], mode);
1539 error = clib_error_return (
1540 0, "unable to set rx-mode on interface %v queue-id %u.\n",
1541 hw->name, queue_id);
1547 if (queue_indices != hw->rx_queue_indices)
1548 vec_free (queue_indices);
1549 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1553 static clib_error_t *
1554 set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1555 vlib_cli_command_t * cmd)
1557 clib_error_t *error = 0;
1558 unformat_input_t _line_input, *line_input = &_line_input;
1559 vnet_main_t *vnm = vnet_get_main ();
1560 u32 hw_if_index = (u32) ~ 0;
1561 u32 queue_id = (u32) ~ 0;
1562 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
1563 u8 queue_id_valid = 0;
1565 if (!unformat_user (input, unformat_line_input, line_input))
1568 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1571 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1573 else if (unformat (line_input, "queue %d", &queue_id))
1575 else if (unformat (line_input, "polling"))
1576 mode = VNET_HW_IF_RX_MODE_POLLING;
1577 else if (unformat (line_input, "interrupt"))
1578 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
1579 else if (unformat (line_input, "adaptive"))
1580 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
1583 error = clib_error_return (0, "parse error: '%U'",
1584 format_unformat_error, line_input);
1585 unformat_free (line_input);
1590 unformat_free (line_input);
1592 if (hw_if_index == (u32) ~ 0)
1593 return clib_error_return (0, "please specify valid interface name");
1595 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
1596 return clib_error_return (0, "please specify valid rx-mode");
1598 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1605 * This command is used to assign the RX packet processing mode (polling,
1606 * interrupt, adaptive) of the a given interface, and optionally a
1607 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1608 * is applied to all queues of the interface. Not all interfaces support
1609 * all modes. To display the current rx-mode use the command
1610 * '<em>show interface rx-placement</em>'.
1613 * Example of how to assign rx-mode to all queues on an interface:
1614 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1615 * Example of how to assign rx-mode to one queue of an interface:
1616 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1617 * Example of how to display the rx-mode of all interfaces:
1618 * @cliexstart{show interface rx-placement}
1619 * Thread 1 (vpp_wk_0):
1621 * GigabitEthernet7/0/0 queue 0 (polling)
1622 * node vhost-user-input:
1623 * VirtualEthernet0/0/12 queue 0 (interrupt)
1624 * VirtualEthernet0/0/12 queue 2 (polling)
1625 * VirtualEthernet0/0/13 queue 0 (polling)
1626 * VirtualEthernet0/0/13 queue 2 (polling)
1627 * Thread 2 (vpp_wk_1):
1629 * GigabitEthernet7/0/1 queue 0 (polling)
1630 * node vhost-user-input:
1631 * VirtualEthernet0/0/12 queue 1 (polling)
1632 * VirtualEthernet0/0/12 queue 3 (polling)
1633 * VirtualEthernet0/0/13 queue 1 (polling)
1634 * VirtualEthernet0/0/13 queue 3 (polling)
1638 VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
1639 .path = "set interface rx-mode",
1640 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1641 .function = set_interface_rx_mode,
1645 static clib_error_t *
1646 show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1647 vlib_cli_command_t * cmd)
1650 vnet_main_t *vnm = vnet_get_main ();
1651 vnet_hw_if_rx_queue_t **all_queues = 0;
1652 vnet_hw_if_rx_queue_t **qptr;
1653 vnet_hw_if_rx_queue_t *q;
1654 pool_foreach (q, vnm->interface_main.hw_if_rx_queues)
1655 vec_add1 (all_queues, q);
1656 vec_sort_with_function (all_queues, vnet_hw_if_rxq_cmp_cli_api);
1659 vec_foreach (qptr, all_queues)
1661 u32 current_thread = qptr[0]->thread_index;
1662 u32 hw_if_index = qptr[0]->hw_if_index;
1663 vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
1664 u32 current_node = hw_if->input_node_index;
1665 if (current_node != prev_node)
1666 s = format (s, " node %U:\n", format_vlib_node_name, vm, current_node);
1667 s = format (s, " %U queue %u (%U)\n", format_vnet_sw_if_index_name,
1668 vnm, hw_if->sw_if_index, qptr[0]->queue_id,
1669 format_vnet_hw_if_rx_mode, qptr[0]->mode);
1670 if (qptr == all_queues + vec_len (all_queues) - 1 ||
1671 current_thread != qptr[1]->thread_index)
1673 vlib_cli_output (vm, "Thread %u (%s):\n%v", current_thread,
1674 vlib_worker_threads[current_thread].name, s);
1675 vec_reset_length (s);
1677 prev_node = current_node;
1680 vec_free (all_queues);
1685 * This command is used to display the interface and queue worker
1689 * Example of how to display the interface placement:
1690 * @cliexstart{show interface rx-placement}
1691 * Thread 1 (vpp_wk_0):
1693 * GigabitEthernet7/0/0 queue 0 (polling)
1694 * node vhost-user-input:
1695 * VirtualEthernet0/0/12 queue 0 (polling)
1696 * VirtualEthernet0/0/12 queue 2 (polling)
1697 * VirtualEthernet0/0/13 queue 0 (polling)
1698 * VirtualEthernet0/0/13 queue 2 (polling)
1699 * Thread 2 (vpp_wk_1):
1701 * GigabitEthernet7/0/1 queue 0 (polling)
1702 * node vhost-user-input:
1703 * VirtualEthernet0/0/12 queue 1 (polling)
1704 * VirtualEthernet0/0/12 queue 3 (polling)
1705 * VirtualEthernet0/0/13 queue 1 (polling)
1706 * VirtualEthernet0/0/13 queue 3 (polling)
1710 VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1711 .path = "show interface rx-placement",
1712 .short_help = "show interface rx-placement",
1713 .function = show_interface_rx_placement_fn,
1717 set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1718 u32 thread_index, u8 is_main)
1720 vnet_main_t *vnm = vnet_get_main ();
1721 vnet_device_main_t *vdm = &vnet_device_main;
1722 vnet_hw_interface_t *hw;
1728 thread_index += vdm->first_worker_thread_index;
1730 if (thread_index > vdm->last_worker_thread_index)
1731 return clib_error_return (0,
1732 "please specify valid worker thread or main");
1734 hw = vnet_get_hw_interface (vnm, hw_if_index);
1737 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1738 if (queue_index == ~0)
1739 return clib_error_return (0, "unknown queue %u on interface %s", queue_id,
1741 vnet_hw_if_set_rx_queue_thread_index (vnm, queue_index, thread_index);
1742 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1746 static clib_error_t *
1747 set_interface_rx_placement (vlib_main_t *vm, unformat_input_t *input,
1748 vlib_cli_command_t *cmd)
1750 clib_error_t *error = 0;
1751 unformat_input_t _line_input, *line_input = &_line_input;
1752 vnet_main_t *vnm = vnet_get_main ();
1753 u32 hw_if_index = (u32) ~ 0;
1754 u32 queue_id = (u32) 0;
1755 u32 thread_index = (u32) ~ 0;
1758 if (!unformat_user (input, unformat_line_input, line_input))
1761 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1764 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1766 else if (unformat (line_input, "queue %d", &queue_id))
1768 else if (unformat (line_input, "main", &thread_index))
1770 else if (unformat (line_input, "worker %d", &thread_index))
1774 error = clib_error_return (0, "parse error: '%U'",
1775 format_unformat_error, line_input);
1776 unformat_free (line_input);
1781 unformat_free (line_input);
1783 if (hw_if_index == (u32) ~ 0)
1784 return clib_error_return (0, "please specify valid interface name");
1786 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1793 * This command is used to assign a given interface, and optionally a
1794 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1795 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1796 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
1799 * Example of how to display the interface placement:
1800 * @cliexstart{show interface rx-placement}
1801 * Thread 1 (vpp_wk_0):
1803 * GigabitEthernet7/0/0 queue 0 (polling)
1804 * node vhost-user-input:
1805 * VirtualEthernet0/0/12 queue 0 (polling)
1806 * VirtualEthernet0/0/12 queue 2 (polling)
1807 * VirtualEthernet0/0/13 queue 0 (polling)
1808 * VirtualEthernet0/0/13 queue 2 (polling)
1809 * Thread 2 (vpp_wk_1):
1811 * GigabitEthernet7/0/1 queue 0 (polling)
1812 * node vhost-user-input:
1813 * VirtualEthernet0/0/12 queue 1 (polling)
1814 * VirtualEthernet0/0/12 queue 3 (polling)
1815 * VirtualEthernet0/0/13 queue 1 (polling)
1816 * VirtualEthernet0/0/13 queue 3 (polling)
1818 * Example of how to assign a interface and queue to a worker thread:
1819 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1820 * Example of how to display the interface placement:
1821 * @cliexstart{show interface rx-placement}
1822 * Thread 1 (vpp_wk_0):
1824 * GigabitEthernet7/0/0 queue 0 (polling)
1825 * node vhost-user-input:
1826 * VirtualEthernet0/0/12 queue 0 (polling)
1827 * VirtualEthernet0/0/12 queue 1 (polling)
1828 * VirtualEthernet0/0/12 queue 2 (polling)
1829 * VirtualEthernet0/0/13 queue 0 (polling)
1830 * VirtualEthernet0/0/13 queue 2 (polling)
1831 * Thread 2 (vpp_wk_1):
1833 * GigabitEthernet7/0/1 queue 0 (polling)
1834 * node vhost-user-input:
1835 * VirtualEthernet0/0/12 queue 3 (polling)
1836 * VirtualEthernet0/0/13 queue 1 (polling)
1837 * VirtualEthernet0/0/13 queue 3 (polling)
1841 VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1842 .path = "set interface rx-placement",
1843 .short_help = "set interface rx-placement <interface> [queue <n>] "
1844 "[worker <n> | main]",
1845 .function = set_interface_rx_placement,
1851 set_hw_interface_tx_queue (u32 hw_if_index, u32 queue_id, uword *bitmap)
1853 vnet_main_t *vnm = vnet_get_main ();
1854 vlib_thread_main_t *vtm = vlib_get_thread_main ();
1855 vnet_hw_if_tx_queue_t *txq;
1859 /* highest set bit in bitmap should not exceed last worker thread index */
1860 thread_index = clib_bitmap_last_set (bitmap);
1861 if ((thread_index != ~0) && (thread_index >= vtm->n_vlib_mains))
1862 return VNET_API_ERROR_INVALID_VALUE;
1865 vnet_hw_if_get_tx_queue_index_by_id (vnm, hw_if_index, queue_id);
1866 if (queue_index == ~0)
1867 return VNET_API_ERROR_INVALID_QUEUE;
1869 txq = vnet_hw_if_get_tx_queue (vnm, queue_index);
1871 // free the existing bitmap
1872 if (clib_bitmap_count_set_bits (txq->threads))
1874 txq->shared_queue = 0;
1875 clib_bitmap_free (txq->threads);
1878 clib_bitmap_foreach (thread_index, bitmap)
1879 vnet_hw_if_tx_queue_assign_thread (vnm, queue_index, thread_index);
1881 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1885 static clib_error_t *
1886 set_interface_tx_queue (vlib_main_t *vm, unformat_input_t *input,
1887 vlib_cli_command_t *cmd)
1889 clib_error_t *error = 0;
1890 unformat_input_t _line_input, *line_input = &_line_input;
1891 vnet_main_t *vnm = vnet_get_main ();
1892 u32 hw_if_index = (u32) ~0;
1893 u32 queue_id = (u32) 0;
1897 if (!unformat_user (input, unformat_line_input, line_input))
1900 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1902 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
1905 else if (unformat (line_input, "queue %d", &queue_id))
1907 else if (unformat (line_input, "threads %U", unformat_bitmap_list,
1912 error = clib_error_return (0, "parse error: '%U'",
1913 format_unformat_error, line_input);
1914 unformat_free (line_input);
1919 unformat_free (line_input);
1921 if (hw_if_index == (u32) ~0)
1923 error = clib_error_return (0, "please specify valid interface name");
1927 rv = set_hw_interface_tx_queue (hw_if_index, queue_id, bitmap);
1931 case VNET_API_ERROR_INVALID_VALUE:
1932 error = clib_error_return (
1933 0, "please specify valid thread(s) - last thread index %u",
1934 clib_bitmap_last_set (bitmap));
1936 case VNET_API_ERROR_INVALID_QUEUE:
1937 error = clib_error_return (
1938 0, "unknown queue %u on interface %s", queue_id,
1939 vnet_get_hw_interface (vnet_get_main (), hw_if_index)->name);
1946 clib_bitmap_free (bitmap);
1950 VLIB_CLI_COMMAND (cmd_set_if_tx_queue, static) = {
1951 .path = "set interface tx-queue",
1952 .short_help = "set interface tx-queue <interface> queue <n> "
1954 .function = set_interface_tx_queue,
1959 set_interface_rss_queues (vlib_main_t * vm, u32 hw_if_index,
1960 clib_bitmap_t * bitmap)
1962 vnet_main_t *vnm = vnet_get_main ();
1963 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1965 return vnet_hw_interface_set_rss_queues (vnm, hi, bitmap);
1968 static clib_error_t *
1969 set_interface_rss_queues_fn (vlib_main_t * vm,
1970 unformat_input_t * input,
1971 vlib_cli_command_t * cmd)
1973 clib_error_t *error = 0;
1974 unformat_input_t _line_input, *line_input = &_line_input;
1975 vnet_main_t *vnm = vnet_get_main ();
1976 u32 hw_if_index = (u32) ~ 0;
1977 clib_bitmap_t *bitmap = NULL;
1979 if (!unformat_user (input, unformat_line_input, line_input))
1982 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1985 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1988 if (unformat (line_input, "list %U", unformat_bitmap_list, &bitmap))
1992 error = clib_error_return (0, "parse error: '%U'",
1993 format_unformat_error, line_input);
1994 unformat_free (line_input);
1999 unformat_free (line_input);
2001 if (hw_if_index == (u32) ~ 0)
2003 error = clib_error_return (0, "please specify valid interface name");
2009 error = clib_error_return (0, "please specify the valid rss queues");
2013 error = set_interface_rss_queues (vm, hw_if_index, bitmap);
2017 clib_bitmap_free (bitmap);
2023 * This command is used to set the rss queues of a given interface
2024 * Not all the interfaces support this operation.
2025 * To display the current rss queues, use the command
2026 * '<em>show hardware-interfaces</em>'.
2029 * Example of how to set the rss queues to 0,2-5,7 of an interface:
2030 * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7}
2034 VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = {
2035 .path = "set interface rss queues",
2036 .short_help = "set interface rss queues <interface> <list <queue-list>>",
2037 .function = set_interface_rss_queues_fn,
2042 format_vnet_pcap (u8 * s, va_list * args)
2044 vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *);
2045 int type = va_arg (*args, int);
2050 if (pp->pcap_rx_enable)
2052 s = format (s, "rx");
2055 if (pp->pcap_tx_enable)
2058 s = format (s, " and ");
2059 s = format (s, "tx");
2062 if (pp->pcap_drop_enable)
2065 s = format (s, " and ");
2066 s = format (s, "drop");
2071 s = format (s, "unknown type %d!", type);
2077 vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
2079 vlib_main_t *vm = vlib_get_main ();
2080 vnet_main_t *vnm = vnet_get_main ();
2081 vnet_pcap_t *pp = &vnm->pcap;
2082 pcap_main_t *pm = &pp->pcap_main;
2083 vnet_classify_main_t *cm = &vnet_classify_main;
2087 if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable)
2090 (vm, "pcap %U dispatch capture enabled: %d of %d pkts...",
2091 format_vnet_pcap, pp, 0 /* print type */ ,
2092 pm->n_packets_captured, pm->n_packets_to_capture);
2093 vlib_cli_output (vm, "capture to file %s", pm->file_name);
2096 vlib_cli_output (vm, "pcap dispatch capture disabled");
2101 /* Consistency checks */
2103 /* Enable w/ capture already enabled not allowed */
2104 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2105 && (a->rx_enable + a->tx_enable + a->drop_enable))
2106 return VNET_API_ERROR_INVALID_VALUE;
2108 /* Disable capture with capture already disabled, not interesting */
2109 if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) ==
2111 ((a->rx_enable + a->tx_enable + a->drop_enable == 0)))
2112 return VNET_API_ERROR_VALUE_EXIST;
2114 /* Change number of packets to capture while capturing */
2115 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2116 && (a->rx_enable + a->tx_enable + a->drop_enable)
2117 && (pm->n_packets_to_capture != a->packets_to_capture))
2118 return VNET_API_ERROR_INVALID_VALUE_2;
2120 /* Classify filter specified, but no classify filter configured */
2121 if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter &&
2122 (!cm->classify_table_index_by_sw_if_index ||
2123 cm->classify_table_index_by_sw_if_index[0] == ~0))
2124 return VNET_API_ERROR_NO_SUCH_LABEL;
2126 if (a->rx_enable + a->tx_enable + a->drop_enable)
2128 void *save_pcap_data;
2130 /* Sanity check max bytes per pkt */
2131 if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000)
2132 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
2134 /* Clean up from previous run, if any */
2135 vec_reset_length (pm->pcap_data);
2137 /* Throw away the data buffer? */
2139 vec_free (pm->pcap_data);
2141 save_pcap_data = pm->pcap_data;
2143 memset (pm, 0, sizeof (*pm));
2145 pm->pcap_data = save_pcap_data;
2147 vec_validate_aligned (vnet_trace_placeholder, 2048,
2148 CLIB_CACHE_LINE_BYTES);
2150 clib_spinlock_init (&(pm->lock));
2152 if (a->filename == 0)
2157 stem = format (stem, "rx");
2159 stem = format (stem, "tx");
2161 stem = format (stem, "drop");
2162 a->filename = format (0, "/tmp/%v.pcap%c", stem, 0);
2166 pm->file_name = (char *) a->filename;
2167 pm->n_packets_captured = 0;
2168 pm->packet_type = PCAP_PACKET_TYPE_ethernet;
2169 /* Preallocate the data vector? */
2170 if (a->preallocate_data)
2173 (pm->pcap_data, a->packets_to_capture
2174 * ((sizeof (pcap_packet_header_t) + a->max_bytes_per_pkt)));
2175 vec_reset_length (pm->pcap_data);
2177 pm->n_packets_to_capture = a->packets_to_capture;
2178 pp->pcap_sw_if_index = a->sw_if_index;
2180 pp->filter_classify_table_index =
2181 cm->classify_table_index_by_sw_if_index[0];
2183 pp->filter_classify_table_index = ~0;
2184 pp->pcap_error_index = a->drop_err;
2185 pp->pcap_rx_enable = a->rx_enable;
2186 pp->pcap_tx_enable = a->tx_enable;
2187 pp->pcap_drop_enable = a->drop_enable;
2188 pp->max_bytes_per_pkt = a->max_bytes_per_pkt;
2192 pp->pcap_rx_enable = 0;
2193 pp->pcap_tx_enable = 0;
2194 pp->pcap_drop_enable = 0;
2195 pp->filter_classify_table_index = ~0;
2196 pp->pcap_error_index = ~0;
2197 if (pm->n_packets_captured)
2199 clib_error_t *error;
2200 pm->n_packets_to_capture = pm->n_packets_captured;
2201 vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
2202 pm->n_packets_captured, pm->file_name);
2203 error = pcap_write (pm);
2204 if (pm->flags & PCAP_MAIN_INIT_DONE)
2206 /* Report I/O errors... */
2209 clib_error_report (error);
2210 return VNET_API_ERROR_SYSCALL_ERROR_1;
2212 vec_free (pm->file_name);
2214 vec_free (pm->pcap_data);
2218 return VNET_API_ERROR_NO_SUCH_ENTRY;
2224 static clib_error_t *
2225 pcap_trace_command_fn (vlib_main_t * vm,
2226 unformat_input_t * input, vlib_cli_command_t * cmd)
2228 unformat_input_t _line_input, *line_input = &_line_input;
2229 vnet_pcap_dispatch_trace_args_t _a, *a = &_a;
2230 vnet_main_t *vnm = vnet_get_main ();
2233 u32 max_bytes_per_pkt = 512;
2237 int preallocate_data = 0;
2238 int drop_enable = 0;
2242 u32 sw_if_index = 0; /* default: any interface */
2243 vlib_error_t drop_err = ~0; /* default: any error */
2245 /* Get a line of input. */
2246 if (!unformat_user (input, unformat_line_input, line_input))
2249 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2251 if (unformat (line_input, "rx"))
2253 else if (unformat (line_input, "tx"))
2255 else if (unformat (line_input, "drop"))
2257 else if (unformat (line_input, "off"))
2258 rx_enable = tx_enable = drop_enable = 0;
2259 else if (unformat (line_input, "max-bytes-per-pkt %u",
2260 &max_bytes_per_pkt))
2262 else if (unformat (line_input, "max %d", &max))
2264 else if (unformat (line_input, "packets-to-capture %d", &max))
2266 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
2269 else if (unformat (line_input, "status %=", &status, 1))
2271 else if (unformat (line_input, "intfc %U",
2272 unformat_vnet_sw_interface, vnm, &sw_if_index))
2274 else if (unformat (line_input, "interface %U",
2275 unformat_vnet_sw_interface, vnm, &sw_if_index))
2277 else if (unformat (line_input, "error %U", unformat_vlib_error, vm,
2280 else if (unformat (line_input, "preallocate-data %=",
2281 &preallocate_data, 1))
2283 else if (unformat (line_input, "free-data %=", &free_data, 1))
2285 else if (unformat (line_input, "intfc any")
2286 || unformat (line_input, "interface any"))
2288 else if (unformat (line_input, "filter"))
2292 return clib_error_return (0, "unknown input `%U'",
2293 format_unformat_error, line_input);
2297 unformat_free (line_input);
2299 /* no need for memset (a, 0, sizeof (*a)), set all fields here. */
2300 a->filename = filename;
2301 a->rx_enable = rx_enable;
2302 a->tx_enable = tx_enable;
2303 a->preallocate_data = preallocate_data;
2304 a->free_data = free_data;
2305 a->drop_enable = drop_enable;
2307 a->packets_to_capture = max;
2308 a->sw_if_index = sw_if_index;
2310 a->max_bytes_per_pkt = max_bytes_per_pkt;
2311 a->drop_err = drop_err;
2313 rv = vnet_pcap_dispatch_trace_configure (a);
2320 case VNET_API_ERROR_INVALID_VALUE:
2321 return clib_error_return (0, "dispatch trace already enabled...");
2323 case VNET_API_ERROR_VALUE_EXIST:
2324 return clib_error_return (0, "dispatch trace already disabled...");
2326 case VNET_API_ERROR_INVALID_VALUE_2:
2327 return clib_error_return
2328 (0, "can't change number of records to capture while tracing...");
2330 case VNET_API_ERROR_SYSCALL_ERROR_1:
2331 return clib_error_return (0, "I/O writing trace capture...");
2333 case VNET_API_ERROR_NO_SUCH_ENTRY:
2334 return clib_error_return (0, "No packets captured...");
2336 case VNET_API_ERROR_INVALID_MEMORY_SIZE:
2337 return clib_error_return (0,
2338 "Max bytes per pkt must be > 32, < 9000...");
2340 case VNET_API_ERROR_NO_SUCH_LABEL:
2341 return clib_error_return
2342 (0, "No classify filter configured, see 'classify filter...'");
2345 vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
2352 * This command is used to start or stop a packet capture, or show
2353 * the status of packet capture.
2355 * This command has the following optional parameters:
2358 * - <b>rx</b> - Capture received packets
2360 * - <b>tx</b> - Capture transmitted packets
2362 * - <b>drop</b> - Capture dropped packets
2364 * - <b>off</b> - Stop capturing packets, write results to the specified file
2366 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
2367 * of packets have been received, buffer is flushed to file. Once another
2368 * '<em>nn</em>' number of packets have been received, buffer is flushed
2369 * to file, overwriting previous write. If not entered, value defaults
2370 * to 100. Can only be updated if packet capture is off.
2372 * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture
2373 * for each packet. Must be >= 32, <= 9000.
2375 * - <b>preallocate-data</b> - Preallocate the data buffer, to avoid
2376 * vector expansion delays during pcap capture
2378 * - <b>free-data</b> - Free the data buffer. Ordinarily it's a feature
2379 * to retain the data buffer so this option is seldom used.
2381 * - <b>intfc <interface-name>|any</b> - Used to specify a given interface,
2382 * or use '<em>any</em>' to run packet capture on all interfaces.
2383 * '<em>any</em>' is the default if not provided. Settings from a previous
2384 * packet capture are preserved, so '<em>any</em>' can be used to reset
2385 * the interface setting.
2387 * - <b>filter</b> - Use the pcap rx / tx / drop trace filter, which
2388 * must be configured. Use <b>classify filter pcap...</b> to configure the
2389 * filter. The filter will only be executed if the per-interface or
2390 * any-interface tests fail.
2392 * - <b>error <node>.<error></b> - filter packets based on a specific error.
2393 * For example: error {ip4-udp-lookup}.{No listener for dst port}
2395 * - <b>file <name></b> - Used to specify the output filename. The file will
2396 * be placed in the '<em>/tmp</em>' directory, so only the filename is
2397 * supported. Directory should not be entered. If file already exists, file
2398 * will be overwritten. If no filename is provided, the file will be
2399 * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc.
2400 * Can only be updated if packet capture is off.
2402 * - <b>status</b> - Displays the current status and configured attributes
2403 * associated with a packet capture. If packet capture is in progress,
2404 * '<em>status</em>' also will return the number of packets currently in
2405 * the local buffer. All additional attributes entered on command line
2406 * with '<em>status</em>' will be ignored and not applied.
2409 * Example of how to display the status of a tx packet capture when off:
2410 * @cliexstart{pcap trace status}
2411 * max is 100, for any interface to file /tmp/vpe.pcap
2412 * pcap tx capture is off...
2414 * Example of how to start a tx packet capture:
2415 * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file
2418 * Example of how to display the status of a tx packet capture in progress:
2419 * @cliexstart{pcap trace status}
2420 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
2421 * pcap tx capture is on: 20 of 35 pkts...
2423 * Example of how to stop a tx packet capture:
2424 * @cliexstart{pcap trace off}
2425 * captured 21 pkts...
2426 * saved to /tmp/vppTest.pcap...
2431 VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
2432 .path = "pcap trace",
2434 "pcap trace [rx] [tx] [drop] [off] [max <nn>] [intfc <interface>|any]\n"
2435 " [file <name>] [status] [max-bytes-per-pkt <nnnn>][filter]\n"
2436 " [preallocate-data][free-data]",
2437 .function = pcap_trace_command_fn,
2441 static clib_error_t *
2442 set_interface_name (vlib_main_t *vm, unformat_input_t *input,
2443 vlib_cli_command_t *cmd)
2445 clib_error_t *error = 0;
2446 unformat_input_t _line_input, *line_input = &_line_input;
2447 vnet_main_t *vnm = vnet_get_main ();
2448 u32 hw_if_index = ~0;
2451 if (!unformat_user (input, unformat_line_input, line_input))
2454 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2456 if (unformat (line_input, "%U %s", unformat_vnet_hw_interface, vnm,
2457 &hw_if_index, &name))
2461 error = clib_error_return (0, "parse error: '%U'",
2462 format_unformat_error, line_input);
2463 unformat_free (line_input);
2469 unformat_free (line_input);
2471 if (hw_if_index == (u32) ~0 || name == 0)
2474 error = clib_error_return (0, "please specify valid interface name");
2478 error = vnet_rename_interface (vnm, hw_if_index, name);
2484 VLIB_CLI_COMMAND (cmd_set_if_name, static) = {
2485 .path = "set interface name",
2486 .short_help = "set interface name <interface-name> <new-interface-name>",
2487 .function = set_interface_name,
2491 static clib_error_t *
2492 set_interface_tx_hash_cmd (vlib_main_t *vm, unformat_input_t *input,
2493 vlib_cli_command_t *cmd)
2495 clib_error_t *error = 0;
2496 unformat_input_t _line_input, *line_input = &_line_input;
2497 vnet_main_t *vnm = vnet_get_main ();
2498 vnet_hw_interface_t *hi;
2500 u32 hw_if_index = (u32) ~0;
2502 vnet_hash_fn_type_t ftype;
2504 if (!unformat_user (input, unformat_line_input, line_input))
2507 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2509 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2512 else if (unformat (line_input, "hash-name %s", &hash_name))
2516 error = clib_error_return (0, "parse error: '%U'",
2517 format_unformat_error, line_input);
2518 unformat_free (line_input);
2523 unformat_free (line_input);
2525 if (hw_if_index == (u32) ~0)
2527 error = clib_error_return (0, "please specify valid interface name");
2533 error = clib_error_return (0, "hash-name is required");
2537 hi = vnet_get_hw_interface (vnm, hw_if_index);
2539 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2540 hf = vnet_hash_function_from_name ((const char *) hash_name, ftype);
2544 error = clib_error_return (0, "please specify valid hash name");
2550 vec_free (hash_name);
2554 VLIB_CLI_COMMAND (cmd_set_if_tx_hash, static) = {
2555 .path = "set interface tx-hash",
2556 .short_help = "set interface tx-hash <interface> hash-name <hash-name>",
2557 .function = set_interface_tx_hash_cmd,
2560 static clib_error_t *
2561 show_tx_hash (vlib_main_t *vm, unformat_input_t *input,
2562 vlib_cli_command_t *cmd)
2564 clib_error_t *error = 0;
2565 unformat_input_t _line_input, *line_input = &_line_input;
2566 vnet_main_t *vnm = vnet_get_main ();
2567 vnet_hw_interface_t *hi;
2568 vnet_hash_function_registration_t *hash;
2569 u32 hw_if_index = (u32) ~0;
2570 vnet_hash_fn_type_t ftype;
2572 if (!unformat_user (input, unformat_line_input, line_input))
2575 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2577 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2582 error = clib_error_return (0, "parse error: '%U'",
2583 format_unformat_error, line_input);
2584 unformat_free (line_input);
2589 unformat_free (line_input);
2591 if (hw_if_index == (u32) ~0)
2593 error = clib_error_return (0, "please specify valid interface name");
2597 hi = vnet_get_hw_interface (vnm, hw_if_index);
2599 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2603 hash = vnet_hash_function_from_func (hi->hf, ftype);
2605 vlib_cli_output (vm, "%U", format_vnet_hash, hash);
2607 vlib_cli_output (vm, "no matching hash function found");
2610 vlib_cli_output (vm, "no hashing function set");
2616 VLIB_CLI_COMMAND (cmd_show_tx_hash, static) = {
2617 .path = "show interface tx-hash",
2618 .short_help = "show interface tx-hash [interface]",
2619 .function = show_tx_hash,
2623 * fd.io coding-style-patch-verification: ON
2626 * eval: (c-set-style "gnu")