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|tag] "
521 "[<interface> [<interface> [..]]] [verbose]",
522 .function = show_sw_interfaces,
527 /* Root of all interface commands. */
529 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
531 .short_help = "Interface commands",
536 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
537 .path = "set interface",
538 .short_help = "Interface commands",
542 static clib_error_t *
543 clear_interface_counters (vlib_main_t * vm,
544 unformat_input_t * input, vlib_cli_command_t * cmd)
546 vnet_main_t *vnm = vnet_get_main ();
547 vnet_interface_main_t *im = &vnm->interface_main;
548 vlib_simple_counter_main_t *sm;
549 vlib_combined_counter_main_t *cm;
552 n_counters = vec_len (im->combined_sw_if_counters);
554 for (j = 0; j < n_counters; j++)
556 im = &vnm->interface_main;
557 cm = im->combined_sw_if_counters + j;
558 vlib_clear_combined_counters (cm);
561 n_counters = vec_len (im->sw_if_counters);
563 for (j = 0; j < n_counters; j++)
565 im = &vnm->interface_main;
566 sm = im->sw_if_counters + j;
567 vlib_clear_simple_counters (sm);
574 * Clear the statistics for all interfaces (statistics associated with the
575 * '<em>show interface</em>' command).
578 * Example of how to clear the statistics for all interfaces:
579 * @cliexcmd{clear interfaces}
582 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
583 .path = "clear interfaces",
584 .short_help = "clear interfaces",
585 .function = clear_interface_counters,
590 * Parse subinterface names.
592 * The following subinterface syntax is supported. The first two are for
593 * backwards compatability:
596 * - a subinterface with the name <intf-name>.<id>. The subinterface
597 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
599 * <intf-name> <min_id>-<max_id>
600 * - a set of the above subinterfaces, repeating for each id
601 * in the range <min_id> to <max_id>
603 * In the following, exact-match semantics (i.e. the number of vlan tags on the
604 * packet must match the number of tags in the configuration) are used only if
605 * the keyword exact-match is present. Non-exact match is the default.
607 * <intf-name> <id> dot1q <outer_id> [exact-match]
608 * - a subinterface with the name <intf-name>.<id>. The subinterface
609 * is a single dot1q vlan with vlan id <outer_id>.
611 * <intf-name> <id> dot1q any [exact-match]
612 * - a subinterface with the name <intf-name>.<id>. The subinterface
613 * is a single dot1q vlan with any vlan id.
615 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
616 * - a subinterface with the name <intf-name>.<id>. The subinterface
617 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
620 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
621 * - a subinterface with the name <intf-name>.<id>. The subinterface
622 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
624 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
626 * - a subinterface with the name <intf-name>.<id>. The subinterface
627 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
629 * For each of the above CLI, there is a duplicate that uses the keyword
630 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
631 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
632 * tagged packets the inner ethertype is always 0x8100. Also note that
633 * the dot1q and dot1ad naming spaces are independent, so it is legal to
634 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
636 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
637 * - a subinterface with the name <intf-name>.<id>. The subinterface
638 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
641 * <intf-name> <id> untagged
642 * - a subinterface with the name <intf-name>.<id>. The subinterface
643 * has no vlan tags. Only one can be specified per interface.
645 * <intf-name> <id> default
646 * - a subinterface with the name <intf-name>.<id>. This is associated
647 * with a packet that did not match any other configured subinterface
648 * on this interface. Only one can be specified per interface.
651 static clib_error_t *
652 parse_vlan_sub_interfaces (unformat_input_t * input,
653 vnet_sw_interface_t * template)
655 clib_error_t *error = 0;
656 u32 inner_vlan, outer_vlan;
658 if (unformat (input, "any inner-dot1q any"))
660 template->sub.eth.flags.two_tags = 1;
661 template->sub.eth.flags.outer_vlan_id_any = 1;
662 template->sub.eth.flags.inner_vlan_id_any = 1;
664 else if (unformat (input, "any"))
666 template->sub.eth.flags.one_tag = 1;
667 template->sub.eth.flags.outer_vlan_id_any = 1;
669 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
671 template->sub.eth.flags.two_tags = 1;
672 template->sub.eth.flags.inner_vlan_id_any = 1;
673 template->sub.eth.outer_vlan_id = outer_vlan;
675 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
677 template->sub.eth.flags.two_tags = 1;
678 template->sub.eth.outer_vlan_id = outer_vlan;
679 template->sub.eth.inner_vlan_id = inner_vlan;
681 else if (unformat (input, "%d", &outer_vlan))
683 template->sub.eth.flags.one_tag = 1;
684 template->sub.eth.outer_vlan_id = outer_vlan;
688 error = clib_error_return (0, "expected dot1q config, got `%U'",
689 format_unformat_error, input);
693 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
695 if (unformat (input, "exact-match"))
697 template->sub.eth.flags.exact_match = 1;
705 static clib_error_t *
706 create_sub_interfaces (vlib_main_t * vm,
707 unformat_input_t * input, vlib_cli_command_t * cmd)
709 vnet_main_t *vnm = vnet_get_main ();
710 clib_error_t *error = 0;
711 u32 hw_if_index, sw_if_index;
712 vnet_hw_interface_t *hi;
713 u32 id, id_min, id_max;
714 vnet_sw_interface_t template;
717 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
719 error = clib_error_return (0, "unknown interface `%U'",
720 format_unformat_error, input);
724 clib_memset (&template, 0, sizeof (template));
725 template.sub.eth.raw_flags = 0;
727 if (unformat (input, "%d default", &id_min))
730 template.sub.eth.flags.default_sub = 1;
732 else if (unformat (input, "%d untagged", &id_min))
735 template.sub.eth.flags.no_tags = 1;
736 template.sub.eth.flags.exact_match = 1;
738 else if (unformat (input, "%d dot1q", &id_min))
740 /* parse dot1q config */
742 error = parse_vlan_sub_interfaces (input, &template);
746 else if (unformat (input, "%d dot1ad", &id_min))
748 /* parse dot1ad config */
750 template.sub.eth.flags.dot1ad = 1;
751 error = parse_vlan_sub_interfaces (input, &template);
755 else if (unformat (input, "%d-%d", &id_min, &id_max))
757 template.sub.eth.flags.one_tag = 1;
758 template.sub.eth.flags.exact_match = 1;
762 else if (unformat (input, "%d", &id_min))
765 template.sub.eth.flags.one_tag = 1;
766 template.sub.eth.outer_vlan_id = id_min;
767 template.sub.eth.flags.exact_match = 1;
772 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
773 format_unformat_error, input);
777 hi = vnet_get_hw_interface (vnm, hw_if_index);
779 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
782 clib_error_return (0,
783 "not allowed as %v belong to a BondEthernet interface",
788 for (id = id_min; id <= id_max; id++)
791 vnet_interface_main_t *im = &vnm->interface_main;
792 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
795 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
799 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
800 hi->sw_if_index, id);
804 template.type = VNET_SW_INTERFACE_TYPE_SUB;
805 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
806 template.sup_sw_if_index = hi->sw_if_index;
807 template.sub.id = id;
809 template.sub.eth.outer_vlan_id = id;
811 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
815 kp = clib_mem_alloc (sizeof (*kp));
816 *kp = sup_and_sub_key;
818 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
819 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
820 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
821 vnet_get_main (), sw_if_index);
829 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
830 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
831 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
832 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
833 * but this is not recommended.
835 * This command has several variations:
836 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
837 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
839 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
840 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
841 * match any other subinterfaces should be sent to this subinterface.
843 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
844 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
845 * to this subinterface.
847 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
848 * subinterfaces to handle a range of VLAN IDs.
850 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
851 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
852 * VLAN ID different from the '<em>subId</em>'.
854 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
855 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
858 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
859 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
860 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
861 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
862 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
863 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
864 * entered, then the default behavior is exact-match.
866 * Use the '<em>show interface</em>' command to display all subinterfaces.
870 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
871 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
873 * The previous example is shorthand and is equivalent to:
874 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
877 * Example of how to create a subinterface number that is different from the VLAN ID:
878 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
881 * Examples of how to create q-in-q and q-in-any subinterfaces:
882 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
883 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
885 * Examples of how to create dot1ad interfaces:
886 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
887 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
890 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
891 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
892 * is non-exact match:
893 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
895 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
896 * is specified and only one VLAN is configured, but packet contains two VLANs:
897 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
900 * Example of how to created a subinterface to process untagged packets:
901 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
903 * Example of how to created a subinterface to process any packet with a VLAN ID that
904 * does not match any other subinterface:
905 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
907 * When subinterfaces are created, they are in the down state. Example of how to
908 * enable a newly created subinterface:
909 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
913 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
914 .path = "create sub-interfaces",
915 .short_help = "create sub-interfaces <interface> "
916 "{<subId> [default|untagged]} | "
917 "{<subId>-<subId>} | "
918 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
919 .function = create_sub_interfaces,
923 static clib_error_t *
924 set_state (vlib_main_t * vm,
925 unformat_input_t * input, vlib_cli_command_t * cmd)
927 vnet_main_t *vnm = vnet_get_main ();
929 u32 sw_if_index, flags;
932 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
934 error = clib_error_return (0, "unknown interface `%U'",
935 format_unformat_error, input);
939 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
941 error = clib_error_return (0, "unknown flags `%U'",
942 format_unformat_error, input);
946 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
955 * This command is used to change the admin state (up/down) of an interface.
957 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
958 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
959 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
960 * '<em>punt</em>' flag (interface is still down).
963 * Example of how to configure the admin state of an interface to
965 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
966 * Example of how to configure the admin state of an interface to
968 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
971 VLIB_CLI_COMMAND (set_state_command, static) = {
972 .path = "set interface state",
973 .short_help = "set interface state <interface> [up|down|punt|enable]",
974 .function = set_state,
978 static clib_error_t *
979 set_unnumbered (vlib_main_t * vm,
980 unformat_input_t * input, vlib_cli_command_t * cmd)
982 vnet_main_t *vnm = vnet_get_main ();
983 u32 unnumbered_sw_if_index = ~0;
984 u32 inherit_from_sw_if_index = ~0;
987 if (unformat (input, "%U use %U",
988 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
989 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
991 else if (unformat (input, "del %U",
992 unformat_vnet_sw_interface, vnm,
993 &unnumbered_sw_if_index))
996 return clib_error_return (0, "parse error '%U'",
997 format_unformat_error, input);
999 if (~0 == unnumbered_sw_if_index)
1000 return clib_error_return (0, "Specify the unnumbered interface");
1001 if (enable && ~0 == inherit_from_sw_if_index)
1002 return clib_error_return (0, "When enabling unnumbered specify the"
1003 " IP enabled interface that it uses");
1005 int rv = vnet_sw_interface_update_unnumbered (
1006 unnumbered_sw_if_index, inherit_from_sw_if_index, enable);
1013 case VNET_API_ERROR_UNEXPECTED_INTF_STATE:
1014 return clib_error_return (
1016 "When enabling unnumbered both interfaces must be in the same tables");
1019 return clib_error_return (
1020 0, "vnet_sw_interface_update_unnumbered returned %d", rv);
1027 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
1028 .path = "set interface unnumbered",
1029 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
1030 .function = set_unnumbered,
1036 static clib_error_t *
1037 set_hw_class (vlib_main_t * vm,
1038 unformat_input_t * input, vlib_cli_command_t * cmd)
1040 vnet_main_t *vnm = vnet_get_main ();
1041 vnet_interface_main_t *im = &vnm->interface_main;
1042 clib_error_t *error;
1043 u32 hw_if_index, hw_class_index;
1046 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
1048 error = clib_error_return (0, "unknown hardware interface `%U'",
1049 format_unformat_error, input);
1053 if (!unformat_user (input, unformat_hash_string,
1054 im->hw_interface_class_by_name, &hw_class_index))
1056 error = clib_error_return (0, "unknown hardware class `%U'",
1057 format_unformat_error, input);
1061 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1070 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1071 .path = "set interface hw-class",
1072 .short_help = "Set interface hardware class",
1073 .function = set_hw_class,
1077 static clib_error_t *
1078 vnet_interface_cli_init (vlib_main_t * vm)
1083 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1085 static clib_error_t *
1086 renumber_interface_command_fn (vlib_main_t * vm,
1087 unformat_input_t * input,
1088 vlib_cli_command_t * cmd)
1091 u32 new_dev_instance;
1092 vnet_main_t *vnm = vnet_get_main ();
1095 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
1096 return clib_error_return (0, "unknown hardware interface `%U'",
1097 format_unformat_error, input);
1099 if (!unformat (input, "%d", &new_dev_instance))
1100 return clib_error_return (0, "new dev instance missing");
1102 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1110 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
1120 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1121 .path = "renumber interface",
1122 .short_help = "renumber interface <interface> <new-dev-instance>",
1123 .function = renumber_interface_command_fn,
1127 static clib_error_t *
1128 promiscuous_cmd (vlib_main_t * vm,
1129 unformat_input_t * input, vlib_cli_command_t * cmd)
1131 vnet_main_t *vnm = vnet_get_main ();
1133 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
1134 ethernet_main_t *em = ðernet_main;
1135 ethernet_interface_t *eif;
1137 if (unformat (input, "on %U",
1138 unformat_vnet_hw_interface, vnm, &hw_if_index))
1140 else if (unformat (input, "off %U",
1141 unformat_ethernet_interface, vnm, &hw_if_index))
1144 return clib_error_return (0, "unknown input `%U'",
1145 format_unformat_error, input);
1147 eif = ethernet_get_interface (em, hw_if_index);
1149 return clib_error_return (0, "not supported");
1151 ethernet_set_flags (vnm, hw_if_index, flags);
1156 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1157 .path = "set interface promiscuous",
1158 .short_help = "set interface promiscuous [on|off] <interface>",
1159 .function = promiscuous_cmd,
1163 static clib_error_t *
1164 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1166 vnet_main_t *vnm = vnet_get_main ();
1167 u32 hw_if_index, sw_if_index, mtu;
1168 ethernet_main_t *em = ðernet_main;
1169 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
1172 if (unformat (input, "%d %U", &mtu,
1173 unformat_vnet_hw_interface, vnm, &hw_if_index))
1176 * Change physical MTU on interface. Only supported for Ethernet
1179 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1182 return clib_error_return (0, "not supported");
1184 err = vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
1189 else if (unformat (input, "packet %d %U", &mtu,
1190 unformat_vnet_sw_interface, vnm, &sw_if_index))
1191 /* Set default packet MTU (including L3 header */
1192 mtus[VNET_MTU_L3] = mtu;
1193 else if (unformat (input, "ip4 %d %U", &mtu,
1194 unformat_vnet_sw_interface, vnm, &sw_if_index))
1195 mtus[VNET_MTU_IP4] = mtu;
1196 else if (unformat (input, "ip6 %d %U", &mtu,
1197 unformat_vnet_sw_interface, vnm, &sw_if_index))
1198 mtus[VNET_MTU_IP6] = mtu;
1199 else if (unformat (input, "mpls %d %U", &mtu,
1200 unformat_vnet_sw_interface, vnm, &sw_if_index))
1201 mtus[VNET_MTU_MPLS] = mtu;
1203 return clib_error_return (0, "unknown input `%U'",
1204 format_unformat_error, input);
1206 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1213 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1214 .path = "set interface mtu",
1215 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
1216 .function = mtu_cmd,
1220 static clib_error_t *
1221 show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input,
1222 vlib_cli_command_t * cmd)
1224 vnet_main_t *vnm = vnet_get_main ();
1225 vnet_interface_main_t *im = &vnm->interface_main;
1226 ethernet_main_t *em = ðernet_main;
1227 u32 sw_if_index = ~0;
1228 vnet_sw_interface_t *si, *sorted_sis = 0;
1230 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1232 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1233 vec_add1 (sorted_sis, si[0]);
1236 /* if an interface name was not passed, get all interfaces */
1237 if (vec_len (sorted_sis) == 0)
1240 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
1241 vec_set_len (sorted_sis, 0);
1243 pool_foreach (si, im->sw_interfaces)
1245 int visible = vnet_swif_is_api_visible (si);
1247 vec_add1 (sorted_sis, si[0]);
1251 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
1254 vec_foreach (si, sorted_sis)
1256 vnet_sw_interface_t *sup_si;
1257 ethernet_interface_t *ei;
1259 sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
1260 ei = ethernet_get_interface (em, sup_si->hw_if_index);
1262 vlib_cli_output (vm, "%U (%s):",
1263 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
1264 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
1267 if (ei && ei->secondary_addrs)
1269 ethernet_interface_address_t *sec_addr;
1271 vec_foreach (sec_addr, ei->secondary_addrs)
1273 vlib_cli_output (vm, " %U", format_mac_address_t, &sec_addr->mac);
1278 vec_free (sorted_sis);
1283 * This command is used to display interface secondary mac addresses.
1286 * Example of how to display interface secondary mac addresses:
1287 * @cliexstart{show interface secondary-mac-address}
1291 VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = {
1292 .path = "show interface secondary-mac-address",
1293 .short_help = "show interface secondary-mac-address [<interface>]",
1294 .function = show_interface_sec_mac_addr_fn,
1298 static clib_error_t *
1299 interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input,
1300 vlib_cli_command_t * cmd)
1302 vnet_main_t *vnm = vnet_get_main ();
1303 vnet_sw_interface_t *si = NULL;
1304 clib_error_t *error = 0;
1305 u32 sw_if_index = ~0;
1309 is_add = is_del = 0;
1311 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1313 error = clib_error_return (0, "unknown interface `%U'",
1314 format_unformat_error, input);
1317 if (!unformat_user (input, unformat_ethernet_address, mac))
1319 error = clib_error_return (0, "expected mac address `%U'",
1320 format_unformat_error, input);
1324 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1326 if (unformat (input, "add"))
1328 else if (unformat (input, "del"))
1334 if (is_add == is_del)
1336 error = clib_error_return (0, "must choose one of add or del");
1340 si = vnet_get_sw_interface (vnm, sw_if_index);
1342 vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add);
1349 * The '<em>set interface secondary-mac-address </em>' command allows adding
1350 * or deleting extra MAC addresses on a given interface without changing the
1351 * default MAC address. This could allow packets sent to these MAC addresses
1352 * to be received without setting the interface to promiscuous mode.
1353 * Not all interfaces support this operation. The ones that do are mostly
1354 * hardware NICs, though virtio does also.
1358 * Example of how to add a secondary MAC Address on an interface:
1359 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add}
1360 * Example of how to delete a secondary MAC address from an interface:
1361 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del}
1365 VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = {
1366 .path = "set interface secondary-mac-address",
1367 .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]",
1368 .function = interface_add_del_mac_address,
1372 static clib_error_t *
1373 set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1374 vlib_cli_command_t * cmd)
1376 vnet_main_t *vnm = vnet_get_main ();
1377 vnet_sw_interface_t *si = NULL;
1378 clib_error_t *error = 0;
1379 u32 sw_if_index = ~0;
1382 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1384 error = clib_error_return (0, "unknown interface `%U'",
1385 format_unformat_error, input);
1388 if (!unformat_user (input, unformat_ethernet_address, mac))
1390 error = clib_error_return (0, "expected mac address `%U'",
1391 format_unformat_error, input);
1394 si = vnet_get_sw_interface (vnm, sw_if_index);
1395 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
1401 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1402 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1403 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1407 * Example of how to change MAC Address of interface:
1408 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1409 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1410 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1411 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1415 VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1416 .path = "set interface mac address",
1417 .short_help = "set interface mac address <interface> <mac-address>",
1418 .function = set_interface_mac_address,
1422 static clib_error_t *
1423 set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1425 vnet_main_t *vnm = vnet_get_main ();
1426 u32 sw_if_index = ~0;
1429 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1430 vnm, &sw_if_index, &tag))
1431 return clib_error_return (0, "unknown input `%U'",
1432 format_unformat_error, input);
1434 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1440 VLIB_CLI_COMMAND (set_tag_command, static) = {
1441 .path = "set interface tag",
1442 .short_help = "set interface tag <interface> <tag>",
1443 .function = set_tag,
1447 static clib_error_t *
1448 clear_tag (vlib_main_t * vm, unformat_input_t * input,
1449 vlib_cli_command_t * cmd)
1451 vnet_main_t *vnm = vnet_get_main ();
1452 u32 sw_if_index = ~0;
1454 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1455 return clib_error_return (0, "unknown input `%U'",
1456 format_unformat_error, input);
1458 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1464 VLIB_CLI_COMMAND (clear_tag_command, static) = {
1465 .path = "clear interface tag",
1466 .short_help = "clear interface tag <interface>",
1467 .function = clear_tag,
1471 static clib_error_t *
1472 set_ip_directed_broadcast (vlib_main_t * vm,
1473 unformat_input_t * input, vlib_cli_command_t * cmd)
1475 vnet_main_t *vnm = vnet_get_main ();
1476 u32 sw_if_index = ~0;
1479 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1480 else if (unformat (input, "enable"))
1482 else if (unformat (input, "disable"))
1485 return clib_error_return (0, "unknown input: `%U'",
1486 format_unformat_error, input);
1488 if (~0 == sw_if_index)
1489 return clib_error_return (0, "specify an interface: `%U'",
1490 format_unformat_error, input);
1492 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1498 * This command is used to enable/disable IP directed broadcast
1499 * If directed broadcast is enabled a packet sent to the interface's
1500 * subnet broadcast address will be sent L2 broadcast on the interface,
1501 * otherwise it is dropped.
1504 VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1505 .path = "set interface ip directed-broadcast",
1506 .short_help = "set interface enable <interface> <enable|disable>",
1507 .function = set_ip_directed_broadcast,
1512 set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1513 u8 queue_id_valid, u32 queue_id,
1514 vnet_hw_if_rx_mode mode)
1516 clib_error_t *error = 0;
1517 vnet_hw_interface_t *hw;
1518 u32 *queue_indices = 0;
1520 hw = vnet_get_hw_interface (vnm, hw_if_index);
1526 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1527 if (queue_index == ~0)
1528 return clib_error_return (0, "unknown queue %u on interface %s",
1529 queue_id, hw->name);
1530 vec_add1 (queue_indices, queue_index);
1533 queue_indices = hw->rx_queue_indices;
1535 for (int i = 0; i < vec_len (queue_indices); i++)
1537 int rv = vnet_hw_if_set_rx_queue_mode (vnm, queue_indices[i], mode);
1540 error = clib_error_return (
1541 0, "unable to set rx-mode on interface %v queue-id %u.\n",
1542 hw->name, queue_id);
1548 if (queue_indices != hw->rx_queue_indices)
1549 vec_free (queue_indices);
1550 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1554 static clib_error_t *
1555 set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1556 vlib_cli_command_t * cmd)
1558 clib_error_t *error = 0;
1559 unformat_input_t _line_input, *line_input = &_line_input;
1560 vnet_main_t *vnm = vnet_get_main ();
1561 u32 hw_if_index = (u32) ~ 0;
1562 u32 queue_id = (u32) ~ 0;
1563 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
1564 u8 queue_id_valid = 0;
1566 if (!unformat_user (input, unformat_line_input, line_input))
1569 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1572 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1574 else if (unformat (line_input, "queue %d", &queue_id))
1576 else if (unformat (line_input, "polling"))
1577 mode = VNET_HW_IF_RX_MODE_POLLING;
1578 else if (unformat (line_input, "interrupt"))
1579 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
1580 else if (unformat (line_input, "adaptive"))
1581 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
1584 error = clib_error_return (0, "parse error: '%U'",
1585 format_unformat_error, line_input);
1586 unformat_free (line_input);
1591 unformat_free (line_input);
1593 if (hw_if_index == (u32) ~ 0)
1594 return clib_error_return (0, "please specify valid interface name");
1596 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
1597 return clib_error_return (0, "please specify valid rx-mode");
1599 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1606 * This command is used to assign the RX packet processing mode (polling,
1607 * interrupt, adaptive) of the a given interface, and optionally a
1608 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1609 * is applied to all queues of the interface. Not all interfaces support
1610 * all modes. To display the current rx-mode use the command
1611 * '<em>show interface rx-placement</em>'.
1614 * Example of how to assign rx-mode to all queues on an interface:
1615 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1616 * Example of how to assign rx-mode to one queue of an interface:
1617 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1618 * Example of how to display the rx-mode of all interfaces:
1619 * @cliexstart{show interface rx-placement}
1620 * Thread 1 (vpp_wk_0):
1622 * GigabitEthernet7/0/0 queue 0 (polling)
1623 * node vhost-user-input:
1624 * VirtualEthernet0/0/12 queue 0 (interrupt)
1625 * VirtualEthernet0/0/12 queue 2 (polling)
1626 * VirtualEthernet0/0/13 queue 0 (polling)
1627 * VirtualEthernet0/0/13 queue 2 (polling)
1628 * Thread 2 (vpp_wk_1):
1630 * GigabitEthernet7/0/1 queue 0 (polling)
1631 * node vhost-user-input:
1632 * VirtualEthernet0/0/12 queue 1 (polling)
1633 * VirtualEthernet0/0/12 queue 3 (polling)
1634 * VirtualEthernet0/0/13 queue 1 (polling)
1635 * VirtualEthernet0/0/13 queue 3 (polling)
1639 VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
1640 .path = "set interface rx-mode",
1641 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1642 .function = set_interface_rx_mode,
1646 static clib_error_t *
1647 show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1648 vlib_cli_command_t * cmd)
1651 vnet_main_t *vnm = vnet_get_main ();
1652 vnet_hw_if_rx_queue_t **all_queues = 0;
1653 vnet_hw_if_rx_queue_t **qptr;
1654 vnet_hw_if_rx_queue_t *q;
1655 pool_foreach (q, vnm->interface_main.hw_if_rx_queues)
1656 vec_add1 (all_queues, q);
1657 vec_sort_with_function (all_queues, vnet_hw_if_rxq_cmp_cli_api);
1660 vec_foreach (qptr, all_queues)
1662 u32 current_thread = qptr[0]->thread_index;
1663 u32 hw_if_index = qptr[0]->hw_if_index;
1664 vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
1665 u32 current_node = hw_if->input_node_index;
1666 if (current_node != prev_node)
1667 s = format (s, " node %U:\n", format_vlib_node_name, vm, current_node);
1668 s = format (s, " %U queue %u (%U)\n", format_vnet_sw_if_index_name,
1669 vnm, hw_if->sw_if_index, qptr[0]->queue_id,
1670 format_vnet_hw_if_rx_mode, qptr[0]->mode);
1671 if (qptr == all_queues + vec_len (all_queues) - 1 ||
1672 current_thread != qptr[1]->thread_index)
1674 vlib_cli_output (vm, "Thread %u (%s):\n%v", current_thread,
1675 vlib_worker_threads[current_thread].name, s);
1676 vec_reset_length (s);
1678 prev_node = current_node;
1681 vec_free (all_queues);
1686 * This command is used to display the interface and queue worker
1690 * Example of how to display the interface placement:
1691 * @cliexstart{show interface rx-placement}
1692 * Thread 1 (vpp_wk_0):
1694 * GigabitEthernet7/0/0 queue 0 (polling)
1695 * node vhost-user-input:
1696 * VirtualEthernet0/0/12 queue 0 (polling)
1697 * VirtualEthernet0/0/12 queue 2 (polling)
1698 * VirtualEthernet0/0/13 queue 0 (polling)
1699 * VirtualEthernet0/0/13 queue 2 (polling)
1700 * Thread 2 (vpp_wk_1):
1702 * GigabitEthernet7/0/1 queue 0 (polling)
1703 * node vhost-user-input:
1704 * VirtualEthernet0/0/12 queue 1 (polling)
1705 * VirtualEthernet0/0/12 queue 3 (polling)
1706 * VirtualEthernet0/0/13 queue 1 (polling)
1707 * VirtualEthernet0/0/13 queue 3 (polling)
1711 VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1712 .path = "show interface rx-placement",
1713 .short_help = "show interface rx-placement",
1714 .function = show_interface_rx_placement_fn,
1718 set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1719 u32 thread_index, u8 is_main)
1721 vnet_main_t *vnm = vnet_get_main ();
1722 vnet_device_main_t *vdm = &vnet_device_main;
1723 vnet_hw_interface_t *hw;
1729 thread_index += vdm->first_worker_thread_index;
1731 if (thread_index > vdm->last_worker_thread_index)
1732 return clib_error_return (0,
1733 "please specify valid worker thread or main");
1735 hw = vnet_get_hw_interface (vnm, hw_if_index);
1738 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1739 if (queue_index == ~0)
1740 return clib_error_return (0, "unknown queue %u on interface %s", queue_id,
1742 vnet_hw_if_set_rx_queue_thread_index (vnm, queue_index, thread_index);
1743 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1747 static clib_error_t *
1748 set_interface_rx_placement (vlib_main_t *vm, unformat_input_t *input,
1749 vlib_cli_command_t *cmd)
1751 clib_error_t *error = 0;
1752 unformat_input_t _line_input, *line_input = &_line_input;
1753 vnet_main_t *vnm = vnet_get_main ();
1754 u32 hw_if_index = (u32) ~ 0;
1755 u32 queue_id = (u32) 0;
1756 u32 thread_index = (u32) ~ 0;
1759 if (!unformat_user (input, unformat_line_input, line_input))
1762 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1765 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1767 else if (unformat (line_input, "queue %d", &queue_id))
1769 else if (unformat (line_input, "main", &thread_index))
1771 else if (unformat (line_input, "worker %d", &thread_index))
1775 error = clib_error_return (0, "parse error: '%U'",
1776 format_unformat_error, line_input);
1777 unformat_free (line_input);
1782 unformat_free (line_input);
1784 if (hw_if_index == (u32) ~ 0)
1785 return clib_error_return (0, "please specify valid interface name");
1787 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1794 * This command is used to assign a given interface, and optionally a
1795 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1796 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1797 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
1800 * Example of how to display the interface placement:
1801 * @cliexstart{show interface rx-placement}
1802 * Thread 1 (vpp_wk_0):
1804 * GigabitEthernet7/0/0 queue 0 (polling)
1805 * node vhost-user-input:
1806 * VirtualEthernet0/0/12 queue 0 (polling)
1807 * VirtualEthernet0/0/12 queue 2 (polling)
1808 * VirtualEthernet0/0/13 queue 0 (polling)
1809 * VirtualEthernet0/0/13 queue 2 (polling)
1810 * Thread 2 (vpp_wk_1):
1812 * GigabitEthernet7/0/1 queue 0 (polling)
1813 * node vhost-user-input:
1814 * VirtualEthernet0/0/12 queue 1 (polling)
1815 * VirtualEthernet0/0/12 queue 3 (polling)
1816 * VirtualEthernet0/0/13 queue 1 (polling)
1817 * VirtualEthernet0/0/13 queue 3 (polling)
1819 * Example of how to assign a interface and queue to a worker thread:
1820 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1821 * Example of how to display the interface placement:
1822 * @cliexstart{show interface rx-placement}
1823 * Thread 1 (vpp_wk_0):
1825 * GigabitEthernet7/0/0 queue 0 (polling)
1826 * node vhost-user-input:
1827 * VirtualEthernet0/0/12 queue 0 (polling)
1828 * VirtualEthernet0/0/12 queue 1 (polling)
1829 * VirtualEthernet0/0/12 queue 2 (polling)
1830 * VirtualEthernet0/0/13 queue 0 (polling)
1831 * VirtualEthernet0/0/13 queue 2 (polling)
1832 * Thread 2 (vpp_wk_1):
1834 * GigabitEthernet7/0/1 queue 0 (polling)
1835 * node vhost-user-input:
1836 * VirtualEthernet0/0/12 queue 3 (polling)
1837 * VirtualEthernet0/0/13 queue 1 (polling)
1838 * VirtualEthernet0/0/13 queue 3 (polling)
1842 VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1843 .path = "set interface rx-placement",
1844 .short_help = "set interface rx-placement <interface> [queue <n>] "
1845 "[worker <n> | main]",
1846 .function = set_interface_rx_placement,
1852 set_hw_interface_tx_queue (u32 hw_if_index, u32 queue_id, uword *bitmap)
1854 vnet_main_t *vnm = vnet_get_main ();
1855 vlib_thread_main_t *vtm = vlib_get_thread_main ();
1856 vnet_hw_if_tx_queue_t *txq;
1860 /* highest set bit in bitmap should not exceed last worker thread index */
1861 thread_index = clib_bitmap_last_set (bitmap);
1862 if ((thread_index != ~0) && (thread_index >= vtm->n_vlib_mains))
1863 return VNET_API_ERROR_INVALID_VALUE;
1866 vnet_hw_if_get_tx_queue_index_by_id (vnm, hw_if_index, queue_id);
1867 if (queue_index == ~0)
1868 return VNET_API_ERROR_INVALID_QUEUE;
1870 txq = vnet_hw_if_get_tx_queue (vnm, queue_index);
1872 // free the existing bitmap
1873 if (clib_bitmap_count_set_bits (txq->threads))
1875 txq->shared_queue = 0;
1876 clib_bitmap_free (txq->threads);
1879 clib_bitmap_foreach (thread_index, bitmap)
1880 vnet_hw_if_tx_queue_assign_thread (vnm, queue_index, thread_index);
1882 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1886 static clib_error_t *
1887 set_interface_tx_queue (vlib_main_t *vm, unformat_input_t *input,
1888 vlib_cli_command_t *cmd)
1890 clib_error_t *error = 0;
1891 unformat_input_t _line_input, *line_input = &_line_input;
1892 vnet_main_t *vnm = vnet_get_main ();
1893 u32 hw_if_index = (u32) ~0;
1894 u32 queue_id = (u32) 0;
1898 if (!unformat_user (input, unformat_line_input, line_input))
1901 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1903 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
1906 else if (unformat (line_input, "queue %d", &queue_id))
1908 else if (unformat (line_input, "threads %U", unformat_bitmap_list,
1913 error = clib_error_return (0, "parse error: '%U'",
1914 format_unformat_error, line_input);
1915 unformat_free (line_input);
1920 unformat_free (line_input);
1922 if (hw_if_index == (u32) ~0)
1924 error = clib_error_return (0, "please specify valid interface name");
1928 rv = set_hw_interface_tx_queue (hw_if_index, queue_id, bitmap);
1932 case VNET_API_ERROR_INVALID_VALUE:
1933 error = clib_error_return (
1934 0, "please specify valid thread(s) - last thread index %u",
1935 clib_bitmap_last_set (bitmap));
1937 case VNET_API_ERROR_INVALID_QUEUE:
1938 error = clib_error_return (
1939 0, "unknown queue %u on interface %s", queue_id,
1940 vnet_get_hw_interface (vnet_get_main (), hw_if_index)->name);
1947 clib_bitmap_free (bitmap);
1951 VLIB_CLI_COMMAND (cmd_set_if_tx_queue, static) = {
1952 .path = "set interface tx-queue",
1953 .short_help = "set interface tx-queue <interface> queue <n> "
1955 .function = set_interface_tx_queue,
1960 set_interface_rss_queues (vlib_main_t * vm, u32 hw_if_index,
1961 clib_bitmap_t * bitmap)
1963 vnet_main_t *vnm = vnet_get_main ();
1964 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1966 return vnet_hw_interface_set_rss_queues (vnm, hi, bitmap);
1969 static clib_error_t *
1970 set_interface_rss_queues_fn (vlib_main_t * vm,
1971 unformat_input_t * input,
1972 vlib_cli_command_t * cmd)
1974 clib_error_t *error = 0;
1975 unformat_input_t _line_input, *line_input = &_line_input;
1976 vnet_main_t *vnm = vnet_get_main ();
1977 u32 hw_if_index = (u32) ~ 0;
1978 clib_bitmap_t *bitmap = NULL;
1980 if (!unformat_user (input, unformat_line_input, line_input))
1983 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1986 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1989 if (unformat (line_input, "list %U", unformat_bitmap_list, &bitmap))
1993 error = clib_error_return (0, "parse error: '%U'",
1994 format_unformat_error, line_input);
1995 unformat_free (line_input);
2000 unformat_free (line_input);
2002 if (hw_if_index == (u32) ~ 0)
2004 error = clib_error_return (0, "please specify valid interface name");
2010 error = clib_error_return (0, "please specify the valid rss queues");
2014 error = set_interface_rss_queues (vm, hw_if_index, bitmap);
2018 clib_bitmap_free (bitmap);
2024 * This command is used to set the rss queues of a given interface
2025 * Not all the interfaces support this operation.
2026 * To display the current rss queues, use the command
2027 * '<em>show hardware-interfaces</em>'.
2030 * Example of how to set the rss queues to 0,2-5,7 of an interface:
2031 * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7}
2035 VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = {
2036 .path = "set interface rss queues",
2037 .short_help = "set interface rss queues <interface> <list <queue-list>>",
2038 .function = set_interface_rss_queues_fn,
2043 format_vnet_pcap (u8 * s, va_list * args)
2045 vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *);
2046 int type = va_arg (*args, int);
2051 if (pp->pcap_rx_enable)
2053 s = format (s, "rx");
2056 if (pp->pcap_tx_enable)
2059 s = format (s, " and ");
2060 s = format (s, "tx");
2063 if (pp->pcap_drop_enable)
2066 s = format (s, " and ");
2067 s = format (s, "drop");
2072 s = format (s, "unknown type %d!", type);
2078 vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
2080 vlib_main_t *vm = vlib_get_main ();
2081 vnet_main_t *vnm = vnet_get_main ();
2082 vnet_pcap_t *pp = &vnm->pcap;
2083 pcap_main_t *pm = &pp->pcap_main;
2084 vnet_classify_main_t *cm = &vnet_classify_main;
2088 if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable)
2091 (vm, "pcap %U dispatch capture enabled: %d of %d pkts...",
2092 format_vnet_pcap, pp, 0 /* print type */ ,
2093 pm->n_packets_captured, pm->n_packets_to_capture);
2094 vlib_cli_output (vm, "capture to file %s", pm->file_name);
2097 vlib_cli_output (vm, "pcap dispatch capture disabled");
2102 /* Consistency checks */
2104 /* Enable w/ capture already enabled not allowed */
2105 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2106 && (a->rx_enable + a->tx_enable + a->drop_enable))
2107 return VNET_API_ERROR_INVALID_VALUE;
2109 /* Disable capture with capture already disabled, not interesting */
2110 if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) ==
2112 ((a->rx_enable + a->tx_enable + a->drop_enable == 0)))
2113 return VNET_API_ERROR_VALUE_EXIST;
2115 /* Change number of packets to capture while capturing */
2116 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2117 && (a->rx_enable + a->tx_enable + a->drop_enable)
2118 && (pm->n_packets_to_capture != a->packets_to_capture))
2119 return VNET_API_ERROR_INVALID_VALUE_2;
2121 /* Classify filter specified, but no classify filter configured */
2122 if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter &&
2123 (!cm->classify_table_index_by_sw_if_index ||
2124 cm->classify_table_index_by_sw_if_index[0] == ~0))
2125 return VNET_API_ERROR_NO_SUCH_LABEL;
2127 if (a->rx_enable + a->tx_enable + a->drop_enable)
2129 void *save_pcap_data;
2131 /* Sanity check max bytes per pkt */
2132 if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000)
2133 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
2135 /* Clean up from previous run, if any */
2136 vec_reset_length (pm->pcap_data);
2138 /* Throw away the data buffer? */
2140 vec_free (pm->pcap_data);
2142 save_pcap_data = pm->pcap_data;
2144 memset (pm, 0, sizeof (*pm));
2146 pm->pcap_data = save_pcap_data;
2148 vec_validate_aligned (vnet_trace_placeholder, 2048,
2149 CLIB_CACHE_LINE_BYTES);
2151 clib_spinlock_init (&(pm->lock));
2153 if (a->filename == 0)
2158 stem = format (stem, "rx");
2160 stem = format (stem, "tx");
2162 stem = format (stem, "drop");
2163 a->filename = format (0, "/tmp/%v.pcap%c", stem, 0);
2167 pm->file_name = (char *) a->filename;
2168 pm->n_packets_captured = 0;
2169 pm->packet_type = PCAP_PACKET_TYPE_ethernet;
2170 /* Preallocate the data vector? */
2171 if (a->preallocate_data)
2174 (pm->pcap_data, a->packets_to_capture
2175 * ((sizeof (pcap_packet_header_t) + a->max_bytes_per_pkt)));
2176 vec_reset_length (pm->pcap_data);
2178 pm->n_packets_to_capture = a->packets_to_capture;
2179 pp->pcap_sw_if_index = a->sw_if_index;
2181 pp->filter_classify_table_index =
2182 cm->classify_table_index_by_sw_if_index[0];
2184 pp->filter_classify_table_index = ~0;
2185 pp->pcap_error_index = a->drop_err;
2186 pp->pcap_rx_enable = a->rx_enable;
2187 pp->pcap_tx_enable = a->tx_enable;
2188 pp->pcap_drop_enable = a->drop_enable;
2189 pp->max_bytes_per_pkt = a->max_bytes_per_pkt;
2193 pp->pcap_rx_enable = 0;
2194 pp->pcap_tx_enable = 0;
2195 pp->pcap_drop_enable = 0;
2196 pp->filter_classify_table_index = ~0;
2197 pp->pcap_error_index = ~0;
2198 if (pm->n_packets_captured)
2200 clib_error_t *error;
2201 pm->n_packets_to_capture = pm->n_packets_captured;
2202 vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
2203 pm->n_packets_captured, pm->file_name);
2204 error = pcap_write (pm);
2205 if (pm->flags & PCAP_MAIN_INIT_DONE)
2207 /* Report I/O errors... */
2210 clib_error_report (error);
2211 return VNET_API_ERROR_SYSCALL_ERROR_1;
2213 vec_free (pm->file_name);
2215 vec_free (pm->pcap_data);
2219 return VNET_API_ERROR_NO_SUCH_ENTRY;
2225 static clib_error_t *
2226 pcap_trace_command_fn (vlib_main_t * vm,
2227 unformat_input_t * input, vlib_cli_command_t * cmd)
2229 unformat_input_t _line_input, *line_input = &_line_input;
2230 vnet_pcap_dispatch_trace_args_t _a, *a = &_a;
2231 vnet_main_t *vnm = vnet_get_main ();
2234 u32 max_bytes_per_pkt = 512;
2238 int preallocate_data = 0;
2239 int drop_enable = 0;
2243 u32 sw_if_index = 0; /* default: any interface */
2244 vlib_error_t drop_err = ~0; /* default: any error */
2246 /* Get a line of input. */
2247 if (!unformat_user (input, unformat_line_input, line_input))
2250 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2252 if (unformat (line_input, "rx"))
2254 else if (unformat (line_input, "tx"))
2256 else if (unformat (line_input, "drop"))
2258 else if (unformat (line_input, "off"))
2259 rx_enable = tx_enable = drop_enable = 0;
2260 else if (unformat (line_input, "max-bytes-per-pkt %u",
2261 &max_bytes_per_pkt))
2263 else if (unformat (line_input, "max %d", &max))
2265 else if (unformat (line_input, "packets-to-capture %d", &max))
2267 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
2270 else if (unformat (line_input, "status %=", &status, 1))
2272 else if (unformat (line_input, "intfc %U",
2273 unformat_vnet_sw_interface, vnm, &sw_if_index))
2275 else if (unformat (line_input, "interface %U",
2276 unformat_vnet_sw_interface, vnm, &sw_if_index))
2278 else if (unformat (line_input, "error %U", unformat_vlib_error, vm,
2281 else if (unformat (line_input, "preallocate-data %=",
2282 &preallocate_data, 1))
2284 else if (unformat (line_input, "free-data %=", &free_data, 1))
2286 else if (unformat (line_input, "intfc any")
2287 || unformat (line_input, "interface any"))
2289 else if (unformat (line_input, "filter"))
2293 return clib_error_return (0, "unknown input `%U'",
2294 format_unformat_error, line_input);
2298 unformat_free (line_input);
2300 /* no need for memset (a, 0, sizeof (*a)), set all fields here. */
2301 a->filename = filename;
2302 a->rx_enable = rx_enable;
2303 a->tx_enable = tx_enable;
2304 a->preallocate_data = preallocate_data;
2305 a->free_data = free_data;
2306 a->drop_enable = drop_enable;
2308 a->packets_to_capture = max;
2309 a->sw_if_index = sw_if_index;
2311 a->max_bytes_per_pkt = max_bytes_per_pkt;
2312 a->drop_err = drop_err;
2314 rv = vnet_pcap_dispatch_trace_configure (a);
2321 case VNET_API_ERROR_INVALID_VALUE:
2322 return clib_error_return (0, "dispatch trace already enabled...");
2324 case VNET_API_ERROR_VALUE_EXIST:
2325 return clib_error_return (0, "dispatch trace already disabled...");
2327 case VNET_API_ERROR_INVALID_VALUE_2:
2328 return clib_error_return
2329 (0, "can't change number of records to capture while tracing...");
2331 case VNET_API_ERROR_SYSCALL_ERROR_1:
2332 return clib_error_return (0, "I/O writing trace capture...");
2334 case VNET_API_ERROR_NO_SUCH_ENTRY:
2335 return clib_error_return (0, "No packets captured...");
2337 case VNET_API_ERROR_INVALID_MEMORY_SIZE:
2338 return clib_error_return (0,
2339 "Max bytes per pkt must be > 32, < 9000...");
2341 case VNET_API_ERROR_NO_SUCH_LABEL:
2342 return clib_error_return
2343 (0, "No classify filter configured, see 'classify filter...'");
2346 vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
2353 * This command is used to start or stop a packet capture, or show
2354 * the status of packet capture.
2356 * This command has the following optional parameters:
2359 * - <b>rx</b> - Capture received packets
2361 * - <b>tx</b> - Capture transmitted packets
2363 * - <b>drop</b> - Capture dropped packets
2365 * - <b>off</b> - Stop capturing packets, write results to the specified file
2367 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
2368 * of packets have been received, buffer is flushed to file. Once another
2369 * '<em>nn</em>' number of packets have been received, buffer is flushed
2370 * to file, overwriting previous write. If not entered, value defaults
2371 * to 100. Can only be updated if packet capture is off.
2373 * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture
2374 * for each packet. Must be >= 32, <= 9000.
2376 * - <b>preallocate-data</b> - Preallocate the data buffer, to avoid
2377 * vector expansion delays during pcap capture
2379 * - <b>free-data</b> - Free the data buffer. Ordinarily it's a feature
2380 * to retain the data buffer so this option is seldom used.
2382 * - <b>intfc <interface-name>|any</b> - Used to specify a given interface,
2383 * or use '<em>any</em>' to run packet capture on all interfaces.
2384 * '<em>any</em>' is the default if not provided. Settings from a previous
2385 * packet capture are preserved, so '<em>any</em>' can be used to reset
2386 * the interface setting.
2388 * - <b>filter</b> - Use the pcap trace rx / tx / drop filter, which
2389 * must be configured. Use <b>classify filter pcap...</b> to configure the
2390 * filter. The filter will only be executed if the per-interface or
2391 * any-interface tests fail.
2393 * - <b>error <node>.<error></b> - filter packets based on a specific error.
2394 * For example: error {ip4-udp-lookup}.{no_listener}
2396 * - <b>file <name></b> - Used to specify the output filename. The file will
2397 * be placed in the '<em>/tmp</em>' directory, so only the filename is
2398 * supported. Directory should not be entered. If file already exists, file
2399 * will be overwritten. If no filename is provided, the file will be
2400 * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc.
2401 * Can only be updated if packet capture is off.
2403 * - <b>status</b> - Displays the current status and configured attributes
2404 * associated with a packet capture. If packet capture is in progress,
2405 * '<em>status</em>' also will return the number of packets currently in
2406 * the local buffer. All additional attributes entered on command line
2407 * with '<em>status</em>' will be ignored and not applied.
2410 * Example of how to display the status of a tx packet capture when off:
2411 * @cliexstart{pcap trace status}
2412 * max is 100, for any interface to file /tmp/vpe.pcap
2413 * pcap tx capture is off...
2415 * Example of how to start a tx packet capture:
2416 * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file
2419 * Example of how to display the status of a tx packet capture in progress:
2420 * @cliexstart{pcap trace status}
2421 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
2422 * pcap tx capture is on: 20 of 35 pkts...
2424 * Example of how to stop a tx packet capture:
2425 * @cliexstart{pcap trace off}
2426 * captured 21 pkts...
2427 * saved to /tmp/vppTest.pcap...
2432 VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
2433 .path = "pcap trace",
2435 "pcap trace [rx] [tx] [drop] [off] [max <nn>] [intfc <interface>|any]\n"
2436 " [file <name>] [status] [max-bytes-per-pkt <nnnn>][filter]\n"
2437 " [preallocate-data][free-data]",
2438 .function = pcap_trace_command_fn,
2442 static clib_error_t *
2443 set_interface_name (vlib_main_t *vm, unformat_input_t *input,
2444 vlib_cli_command_t *cmd)
2446 clib_error_t *error = 0;
2447 unformat_input_t _line_input, *line_input = &_line_input;
2448 vnet_main_t *vnm = vnet_get_main ();
2449 u32 hw_if_index = ~0;
2452 if (!unformat_user (input, unformat_line_input, line_input))
2455 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2457 if (unformat (line_input, "%U %s", unformat_vnet_hw_interface, vnm,
2458 &hw_if_index, &name))
2462 error = clib_error_return (0, "parse error: '%U'",
2463 format_unformat_error, line_input);
2464 unformat_free (line_input);
2470 unformat_free (line_input);
2472 if (hw_if_index == (u32) ~0 || name == 0)
2475 error = clib_error_return (0, "please specify valid interface name");
2479 error = vnet_rename_interface (vnm, hw_if_index, name);
2485 VLIB_CLI_COMMAND (cmd_set_if_name, static) = {
2486 .path = "set interface name",
2487 .short_help = "set interface name <interface-name> <new-interface-name>",
2488 .function = set_interface_name,
2492 static clib_error_t *
2493 set_interface_tx_hash_cmd (vlib_main_t *vm, unformat_input_t *input,
2494 vlib_cli_command_t *cmd)
2496 clib_error_t *error = 0;
2497 unformat_input_t _line_input, *line_input = &_line_input;
2498 vnet_main_t *vnm = vnet_get_main ();
2499 vnet_hw_interface_t *hi;
2501 u32 hw_if_index = (u32) ~0;
2503 vnet_hash_fn_type_t ftype;
2505 if (!unformat_user (input, unformat_line_input, line_input))
2508 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2510 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2513 else if (unformat (line_input, "hash-name %s", &hash_name))
2517 error = clib_error_return (0, "parse error: '%U'",
2518 format_unformat_error, line_input);
2519 unformat_free (line_input);
2524 unformat_free (line_input);
2526 if (hw_if_index == (u32) ~0)
2528 error = clib_error_return (0, "please specify valid interface name");
2534 error = clib_error_return (0, "hash-name is required");
2538 hi = vnet_get_hw_interface (vnm, hw_if_index);
2540 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2541 hf = vnet_hash_function_from_name ((const char *) hash_name, ftype);
2545 error = clib_error_return (0, "please specify valid hash name");
2551 vec_free (hash_name);
2555 VLIB_CLI_COMMAND (cmd_set_if_tx_hash, static) = {
2556 .path = "set interface tx-hash",
2557 .short_help = "set interface tx-hash <interface> hash-name <hash-name>",
2558 .function = set_interface_tx_hash_cmd,
2561 static clib_error_t *
2562 show_tx_hash (vlib_main_t *vm, unformat_input_t *input,
2563 vlib_cli_command_t *cmd)
2565 clib_error_t *error = 0;
2566 unformat_input_t _line_input, *line_input = &_line_input;
2567 vnet_main_t *vnm = vnet_get_main ();
2568 vnet_hw_interface_t *hi;
2569 vnet_hash_function_registration_t *hash;
2570 u32 hw_if_index = (u32) ~0;
2571 vnet_hash_fn_type_t ftype;
2573 if (!unformat_user (input, unformat_line_input, line_input))
2576 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2578 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2583 error = clib_error_return (0, "parse error: '%U'",
2584 format_unformat_error, line_input);
2585 unformat_free (line_input);
2590 unformat_free (line_input);
2592 if (hw_if_index == (u32) ~0)
2594 error = clib_error_return (0, "please specify valid interface name");
2598 hi = vnet_get_hw_interface (vnm, hw_if_index);
2600 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2604 hash = vnet_hash_function_from_func (hi->hf, ftype);
2606 vlib_cli_output (vm, "%U", format_vnet_hash, hash);
2608 vlib_cli_output (vm, "no matching hash function found");
2611 vlib_cli_output (vm, "no hashing function set");
2617 VLIB_CLI_COMMAND (cmd_show_tx_hash, static) = {
2618 .path = "show interface tx-hash",
2619 .short_help = "show interface tx-hash [interface]",
2620 .function = show_tx_hash,
2624 * fd.io coding-style-patch-verification: ON
2627 * eval: (c-set-style "gnu")