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>
56 compare_interface_names (void *a1, void *a2)
61 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
65 show_or_clear_hw_interfaces (vlib_main_t * vm,
66 unformat_input_t * input,
67 vlib_cli_command_t * cmd, int is_show)
69 clib_error_t *error = 0;
70 vnet_main_t *vnm = vnet_get_main ();
71 vnet_interface_main_t *im = &vnm->interface_main;
72 vnet_hw_interface_t *hi;
73 u32 hw_if_index, *hw_if_indices = 0;
74 int i, verbose = -1, show_bond = 0;
76 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
78 /* See if user wants to show a specific interface. */
80 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
81 vec_add1 (hw_if_indices, hw_if_index);
83 /* See if user wants to show an interface with a specific hw_if_index. */
84 else if (unformat (input, "%u", &hw_if_index))
85 vec_add1 (hw_if_indices, hw_if_index);
87 else if (unformat (input, "verbose"))
88 verbose = 1; /* this is also the default */
90 else if (unformat (input, "detail"))
93 else if (unformat (input, "brief"))
96 else if (unformat (input, "bond"))
100 verbose = 0; /* default to brief for link bonding */
105 error = clib_error_return (0, "unknown input `%U'",
106 format_unformat_error, input);
111 /* Gather interfaces. */
112 if (vec_len (hw_if_indices) == 0)
113 pool_foreach (hi, im->hw_interfaces)
114 vec_add1 (hw_if_indices, hi - im->hw_interfaces);
117 verbose = 1; /* default to verbose (except bond) */
122 vec_sort_with_function (hw_if_indices, compare_interface_names);
124 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
125 for (i = 0; i < vec_len (hw_if_indices); i++)
127 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
128 if (show_bond == 0) /* show all interfaces */
129 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
131 else if ((hi->bond_info) &&
132 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
133 { /* show only bonded interface and all its slave interfaces */
135 vnet_hw_interface_t *shi;
136 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
140 clib_bitmap_foreach (hw_idx, hi->bond_info)
142 shi = vnet_get_hw_interface(vnm, hw_idx);
143 vlib_cli_output (vm, "%U\n",
144 format_vnet_hw_interface, vnm, shi, verbose);
152 for (i = 0; i < vec_len (hw_if_indices); i++)
154 vnet_device_class_t *dc;
156 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
157 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
159 if (dc->clear_counters)
160 dc->clear_counters (hi->dev_instance);
165 vec_free (hw_if_indices);
169 static clib_error_t *
170 show_hw_interfaces (vlib_main_t * vm,
171 unformat_input_t * input, vlib_cli_command_t * cmd)
173 return show_or_clear_hw_interfaces (vm, input, cmd, 1 /* is_show */ );
176 static clib_error_t *
177 clear_hw_interfaces (vlib_main_t * vm,
178 unformat_input_t * input, vlib_cli_command_t * cmd)
180 return show_or_clear_hw_interfaces (vm, input, cmd, 0 /* is_show */ );
185 * Display more detailed information about all or a list of given interfaces.
186 * The verboseness of the output can be controlled by the following optional
188 * - brief: Only show name, index and state (default for bonded interfaces).
189 * - verbose: Also display additional attributes (default for all other interfaces).
190 * - detail: Also display all remaining attributes and extended statistics.
192 * To limit the output of the command to bonded interfaces and their slave
193 * interfaces, use the '<em>bond</em>' optional parameter.
196 * Example of how to display default data for all interfaces:
197 * @cliexstart{show hardware-interfaces}
198 * Name Idx Link Hardware
199 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
200 * Ethernet address ec:f4:bb:c0:bc:fc
202 * carrier up full duplex speed 1000 mtu 9216
203 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
205 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
206 * Ethernet address ec:f4:bb:c0:bc:fd
208 * carrier up full duplex speed 1000 mtu 9216
209 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
211 * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0
212 * Ethernet address 02:fe:a5:a9:8b:8e
213 * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1
214 * Ethernet address 02:fe:c0:4e:3b:b0
215 * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2
216 * Ethernet address 02:fe:1f:73:92:81
217 * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3
218 * Ethernet address 02:fe:f2:25:c4:68
219 * local0 0 down local0
222 * Example of how to display '<em>verbose</em>' data for an interface by name and
223 * software index (where 2 is the software index):
224 * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose}
225 * Name Idx Link Hardware
226 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
227 * Ethernet address ec:f4:bb:c0:bc:fc
229 * carrier up full duplex speed 1000 mtu 9216
230 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
232 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
233 * Ethernet address ec:f4:bb:c0:bc:fd
235 * carrier up full duplex speed 1000 mtu 9216
236 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
241 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
242 .path = "show hardware-interfaces",
243 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
244 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
245 .function = show_hw_interfaces,
251 * Clear the extended statistics for all or a list of given interfaces
252 * (statistics associated with the '<em>show hardware-interfaces</em>' command).
255 * Example of how to clear the extended statistics for all interfaces:
256 * @cliexcmd{clear hardware-interfaces}
257 * Example of how to clear the extended statistics for an interface by
258 * name and software index (where 2 is the software index):
259 * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2}
262 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
263 .path = "clear hardware-interfaces",
264 .short_help = "clear hardware-interfaces "
265 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
266 .function = clear_hw_interfaces,
271 sw_interface_name_compare (void *a1, void *a2)
273 vnet_sw_interface_t *si1 = a1;
274 vnet_sw_interface_t *si2 = a2;
276 return vnet_sw_interface_compare (vnet_get_main (),
277 si1->sw_if_index, si2->sw_if_index);
280 static clib_error_t *
281 show_sw_interfaces (vlib_main_t * vm,
282 unformat_input_t * input, vlib_cli_command_t * cmd)
284 clib_error_t *error = 0;
285 vnet_main_t *vnm = vnet_get_main ();
286 unformat_input_t _linput, *linput = &_linput;
287 vnet_interface_main_t *im = &vnm->interface_main;
288 vnet_sw_interface_t *si, *sorted_sis = 0;
289 u32 sw_if_index = ~(u32) 0;
290 u8 show_addresses = 0;
291 u8 show_features = 0;
297 * Get a line of input. Won't work if the user typed
298 * "show interface" and nothing more.
300 if (unformat_user (input, unformat_line_input, linput))
302 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
304 /* See if user wants to show specific interface */
306 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
308 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
309 vec_add1 (sorted_sis, si[0]);
311 else if (unformat (linput, "address") || unformat (linput, "addr"))
313 else if (unformat (linput, "features") || unformat (linput, "feat"))
315 else if (unformat (linput, "tag"))
317 else if (unformat (linput, "vtr"))
319 else if (unformat (linput, "verbose"))
323 vec_free (sorted_sis);
324 error = clib_error_return (0, "unknown input `%U'",
325 format_unformat_error, linput);
329 unformat_free (linput);
331 if (show_features || show_tag || show_vtr)
333 if (sw_if_index == ~(u32) 0)
335 vec_free (sorted_sis);
336 return clib_error_return (0, "Interface not specified...");
342 vnet_interface_features_show (vm, sw_if_index, verbose);
343 vlib_cli_output (vm, "%U", format_l2_input_features, sw_if_index, 1);
345 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
346 vlib_cli_output (vm, "\nl2-output:");
347 if (l2_output->out_vtr_flag)
348 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
349 vlib_cli_output (vm, "%U", format_l2_output_features,
350 l2_output->feature_bitmap, 1);
351 vec_free (sorted_sis);
357 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
358 vlib_cli_output (vm, "%U: %s",
359 format_vnet_sw_if_index_name, vnm, sw_if_index,
360 tag ? (char *) tag : "(none)");
361 vec_free (sorted_sis);
366 * Show vlan tag rewrite data for one interface.
370 u32 vtr_op = L2_VTR_DISABLED;
371 u32 push_dot1q = 0, tag1 = 0, tag2 = 0;
373 if (l2vtr_get (vm, vnm, sw_if_index,
374 &vtr_op, &push_dot1q, &tag1, &tag2) != 0)
376 vlib_cli_output (vm, "%U: Problem getting vlan tag-rewrite data",
377 format_vnet_sw_if_index_name, vnm, sw_if_index);
380 vlib_cli_output (vm, "%U: VTR %0U",
381 format_vnet_sw_if_index_name, vnm, sw_if_index,
382 format_vtr, vtr_op, push_dot1q, tag1, tag2);
387 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
389 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
391 /* Gather interfaces. */
393 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
394 _vec_len (sorted_sis) = 0;
396 pool_foreach (si, im->sw_interfaces)
398 int visible = vnet_swif_is_api_visible (si);
400 vec_add1 (sorted_sis, si[0]);
404 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
409 vec_foreach (si, sorted_sis)
411 ip4_main_t *im4 = &ip4_main;
412 ip6_main_t *im6 = &ip6_main;
413 ip_lookup_main_t *lm4 = &im4->lookup_main;
414 ip_lookup_main_t *lm6 = &im6->lookup_main;
415 ip_interface_address_t *ia = 0;
416 u32 fib_index4 = 0, fib_index6 = 0;
418 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
419 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
422 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
423 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
426 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
427 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
429 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
431 (vm, "%U (%s): \n unnumbered, use %U",
432 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
433 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
434 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
438 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
439 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
441 /* Display any L2 info */
442 vlib_cli_output (vm, "%U", format_l2_input, si->sw_if_index);
445 /* Display any IP4 addressing info */
446 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
447 1 /* honor unnumbered */,
449 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
451 vlib_cli_output (vm, " L3 %U/%d ip4 table-id %d fib-idx %d",
452 format_ip4_address, r4, ia->address_length,
454 ip4_fib_index_from_table_id (fib4->table_id));
456 vlib_cli_output (vm, " L3 %U/%d",
457 format_ip4_address, r4, ia->address_length);
462 /* Display any IP6 addressing info */
463 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
464 1 /* honor unnumbered */,
466 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
468 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
469 format_ip6_address, r6, ia->address_length,
471 ip6_fib_index_from_table_id (fib6->table_id));
473 vlib_cli_output (vm, " L3 %U/%d",
474 format_ip6_address, r6, ia->address_length);
481 vec_foreach (si, sorted_sis)
483 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
488 vec_free (sorted_sis);
493 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
494 .path = "show interface",
495 .short_help = "show interface [address|addr|features|feat|vtr] [<interface> [<interface> [..]]] [verbose]",
496 .function = show_sw_interfaces,
501 /* Root of all interface commands. */
503 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
505 .short_help = "Interface commands",
510 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
511 .path = "set interface",
512 .short_help = "Interface commands",
516 static clib_error_t *
517 clear_interface_counters (vlib_main_t * vm,
518 unformat_input_t * input, vlib_cli_command_t * cmd)
520 vnet_main_t *vnm = vnet_get_main ();
521 vnet_interface_main_t *im = &vnm->interface_main;
522 vlib_simple_counter_main_t *sm;
523 vlib_combined_counter_main_t *cm;
526 n_counters = vec_len (im->combined_sw_if_counters);
528 for (j = 0; j < n_counters; j++)
530 im = &vnm->interface_main;
531 cm = im->combined_sw_if_counters + j;
532 vlib_clear_combined_counters (cm);
535 n_counters = vec_len (im->sw_if_counters);
537 for (j = 0; j < n_counters; j++)
539 im = &vnm->interface_main;
540 sm = im->sw_if_counters + j;
541 vlib_clear_simple_counters (sm);
548 * Clear the statistics for all interfaces (statistics associated with the
549 * '<em>show interface</em>' command).
552 * Example of how to clear the statistics for all interfaces:
553 * @cliexcmd{clear interfaces}
556 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
557 .path = "clear interfaces",
558 .short_help = "clear interfaces",
559 .function = clear_interface_counters,
564 * Parse subinterface names.
566 * The following subinterface syntax is supported. The first two are for
567 * backwards compatability:
570 * - a subinterface with the name <intf-name>.<id>. The subinterface
571 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
573 * <intf-name> <min_id>-<max_id>
574 * - a set of the above subinterfaces, repeating for each id
575 * in the range <min_id> to <max_id>
577 * In the following, exact-match semantics (i.e. the number of vlan tags on the
578 * packet must match the number of tags in the configuration) are used only if
579 * the keyword exact-match is present. Non-exact match is the default.
581 * <intf-name> <id> dot1q <outer_id> [exact-match]
582 * - a subinterface with the name <intf-name>.<id>. The subinterface
583 * is a single dot1q vlan with vlan id <outer_id>.
585 * <intf-name> <id> dot1q any [exact-match]
586 * - a subinterface with the name <intf-name>.<id>. The subinterface
587 * is a single dot1q vlan with any vlan id.
589 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
590 * - a subinterface with the name <intf-name>.<id>. The subinterface
591 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
594 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
595 * - a subinterface with the name <intf-name>.<id>. The subinterface
596 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
598 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
600 * - a subinterface with the name <intf-name>.<id>. The subinterface
601 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
603 * For each of the above CLI, there is a duplicate that uses the keyword
604 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
605 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
606 * tagged packets the inner ethertype is always 0x8100. Also note that
607 * the dot1q and dot1ad naming spaces are independent, so it is legal to
608 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
610 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
611 * - a subinterface with the name <intf-name>.<id>. The subinterface
612 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
615 * <intf-name> <id> untagged
616 * - a subinterface with the name <intf-name>.<id>. The subinterface
617 * has no vlan tags. Only one can be specified per interface.
619 * <intf-name> <id> default
620 * - a subinterface with the name <intf-name>.<id>. This is associated
621 * with a packet that did not match any other configured subinterface
622 * on this interface. Only one can be specified per interface.
625 static clib_error_t *
626 parse_vlan_sub_interfaces (unformat_input_t * input,
627 vnet_sw_interface_t * template)
629 clib_error_t *error = 0;
630 u32 inner_vlan, outer_vlan;
632 if (unformat (input, "any inner-dot1q any"))
634 template->sub.eth.flags.two_tags = 1;
635 template->sub.eth.flags.outer_vlan_id_any = 1;
636 template->sub.eth.flags.inner_vlan_id_any = 1;
638 else if (unformat (input, "any"))
640 template->sub.eth.flags.one_tag = 1;
641 template->sub.eth.flags.outer_vlan_id_any = 1;
643 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
645 template->sub.eth.flags.two_tags = 1;
646 template->sub.eth.flags.inner_vlan_id_any = 1;
647 template->sub.eth.outer_vlan_id = outer_vlan;
649 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
651 template->sub.eth.flags.two_tags = 1;
652 template->sub.eth.outer_vlan_id = outer_vlan;
653 template->sub.eth.inner_vlan_id = inner_vlan;
655 else if (unformat (input, "%d", &outer_vlan))
657 template->sub.eth.flags.one_tag = 1;
658 template->sub.eth.outer_vlan_id = outer_vlan;
662 error = clib_error_return (0, "expected dot1q config, got `%U'",
663 format_unformat_error, input);
667 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
669 if (unformat (input, "exact-match"))
671 template->sub.eth.flags.exact_match = 1;
679 static clib_error_t *
680 create_sub_interfaces (vlib_main_t * vm,
681 unformat_input_t * input, vlib_cli_command_t * cmd)
683 vnet_main_t *vnm = vnet_get_main ();
684 clib_error_t *error = 0;
685 u32 hw_if_index, sw_if_index;
686 vnet_hw_interface_t *hi;
687 u32 id, id_min, id_max;
688 vnet_sw_interface_t template;
691 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
693 error = clib_error_return (0, "unknown interface `%U'",
694 format_unformat_error, input);
698 clib_memset (&template, 0, sizeof (template));
699 template.sub.eth.raw_flags = 0;
701 if (unformat (input, "%d default", &id_min))
704 template.sub.eth.flags.default_sub = 1;
706 else if (unformat (input, "%d untagged", &id_min))
709 template.sub.eth.flags.no_tags = 1;
710 template.sub.eth.flags.exact_match = 1;
712 else if (unformat (input, "%d dot1q", &id_min))
714 /* parse dot1q config */
716 error = parse_vlan_sub_interfaces (input, &template);
720 else if (unformat (input, "%d dot1ad", &id_min))
722 /* parse dot1ad config */
724 template.sub.eth.flags.dot1ad = 1;
725 error = parse_vlan_sub_interfaces (input, &template);
729 else if (unformat (input, "%d-%d", &id_min, &id_max))
731 template.sub.eth.flags.one_tag = 1;
732 template.sub.eth.flags.exact_match = 1;
736 else if (unformat (input, "%d", &id_min))
739 template.sub.eth.flags.one_tag = 1;
740 template.sub.eth.outer_vlan_id = id_min;
741 template.sub.eth.flags.exact_match = 1;
746 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
747 format_unformat_error, input);
751 hi = vnet_get_hw_interface (vnm, hw_if_index);
753 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
756 clib_error_return (0,
757 "not allowed as %v belong to a BondEthernet interface",
762 for (id = id_min; id <= id_max; id++)
765 vnet_interface_main_t *im = &vnm->interface_main;
766 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
769 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
773 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
774 hi->sw_if_index, id);
778 template.type = VNET_SW_INTERFACE_TYPE_SUB;
779 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
780 template.sup_sw_if_index = hi->sw_if_index;
781 template.sub.id = id;
783 template.sub.eth.outer_vlan_id = id;
785 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
789 kp = clib_mem_alloc (sizeof (*kp));
790 *kp = sup_and_sub_key;
792 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
793 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
794 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
795 vnet_get_main (), sw_if_index);
803 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
804 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
805 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
806 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
807 * but this is not recommended.
809 * This command has several variations:
810 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
811 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
813 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
814 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
815 * match any other subinterfaces should be sent to this subinterface.
817 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
818 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
819 * to this subinterface.
821 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
822 * subinterfaces to handle a range of VLAN IDs.
824 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
825 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
826 * VLAN ID different from the '<em>subId</em>'.
828 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
829 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
832 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
833 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
834 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
835 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
836 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
837 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
838 * entered, then the default behavior is exact-match.
840 * Use the '<em>show interface</em>' command to display all subinterfaces.
844 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
845 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
847 * The previous example is shorthand and is equivalent to:
848 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
851 * Example of how to create a subinterface number that is different from the VLAN ID:
852 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
855 * Examples of how to create q-in-q and q-in-any subinterfaces:
856 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
857 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
859 * Examples of how to create dot1ad interfaces:
860 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
861 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
864 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
865 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
866 * is non-exact match:
867 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
869 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
870 * is specified and only one VLAN is configured, but packet contains two VLANs:
871 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
874 * Example of how to created a subinterface to process untagged packets:
875 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
877 * Example of how to created a subinterface to process any packet with a VLAN ID that
878 * does not match any other subinterface:
879 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
881 * When subinterfaces are created, they are in the down state. Example of how to
882 * enable a newly created subinterface:
883 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
887 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
888 .path = "create sub-interfaces",
889 .short_help = "create sub-interfaces <interface> "
890 "{<subId> [default|untagged]} | "
891 "{<subId>-<subId>} | "
892 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
893 .function = create_sub_interfaces,
897 static clib_error_t *
898 set_state (vlib_main_t * vm,
899 unformat_input_t * input, vlib_cli_command_t * cmd)
901 vnet_main_t *vnm = vnet_get_main ();
903 u32 sw_if_index, flags;
906 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
908 error = clib_error_return (0, "unknown interface `%U'",
909 format_unformat_error, input);
913 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
915 error = clib_error_return (0, "unknown flags `%U'",
916 format_unformat_error, input);
920 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
930 * This command is used to change the admin state (up/down) of an interface.
932 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
933 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
934 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
935 * '<em>punt</em>' flag (interface is still down).
938 * Example of how to configure the admin state of an interface to '<em>up</em?':
939 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
940 * Example of how to configure the admin state of an interface to '<em>down</em?':
941 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
944 VLIB_CLI_COMMAND (set_state_command, static) = {
945 .path = "set interface state",
946 .short_help = "set interface state <interface> [up|down|punt|enable]",
947 .function = set_state,
951 static clib_error_t *
952 set_unnumbered (vlib_main_t * vm,
953 unformat_input_t * input, vlib_cli_command_t * cmd)
955 vnet_main_t *vnm = vnet_get_main ();
956 u32 unnumbered_sw_if_index = ~0;
957 u32 inherit_from_sw_if_index = ~0;
960 if (unformat (input, "%U use %U",
961 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
962 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
964 else if (unformat (input, "del %U",
965 unformat_vnet_sw_interface, vnm,
966 &unnumbered_sw_if_index))
969 return clib_error_return (0, "parse error '%U'",
970 format_unformat_error, input);
972 if (~0 == unnumbered_sw_if_index)
973 return clib_error_return (0, "Specify the unnumbered interface");
974 if (enable && ~0 == inherit_from_sw_if_index)
975 return clib_error_return (0, "When enabling unnumbered specify the"
976 " IP enabled interface that it uses");
978 vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
979 inherit_from_sw_if_index, enable);
985 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
986 .path = "set interface unnumbered",
987 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
988 .function = set_unnumbered,
994 static clib_error_t *
995 set_hw_class (vlib_main_t * vm,
996 unformat_input_t * input, vlib_cli_command_t * cmd)
998 vnet_main_t *vnm = vnet_get_main ();
999 vnet_interface_main_t *im = &vnm->interface_main;
1000 clib_error_t *error;
1001 u32 hw_if_index, hw_class_index;
1004 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
1006 error = clib_error_return (0, "unknown hardware interface `%U'",
1007 format_unformat_error, input);
1011 if (!unformat_user (input, unformat_hash_string,
1012 im->hw_interface_class_by_name, &hw_class_index))
1014 error = clib_error_return (0, "unknown hardware class `%U'",
1015 format_unformat_error, input);
1019 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1028 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1029 .path = "set interface hw-class",
1030 .short_help = "Set interface hardware class",
1031 .function = set_hw_class,
1035 static clib_error_t *
1036 vnet_interface_cli_init (vlib_main_t * vm)
1041 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1043 static clib_error_t *
1044 renumber_interface_command_fn (vlib_main_t * vm,
1045 unformat_input_t * input,
1046 vlib_cli_command_t * cmd)
1049 u32 new_dev_instance;
1050 vnet_main_t *vnm = vnet_get_main ();
1053 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
1054 return clib_error_return (0, "unknown hardware interface `%U'",
1055 format_unformat_error, input);
1057 if (!unformat (input, "%d", &new_dev_instance))
1058 return clib_error_return (0, "new dev instance missing");
1060 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1068 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
1078 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1079 .path = "renumber interface",
1080 .short_help = "renumber interface <interface> <new-dev-instance>",
1081 .function = renumber_interface_command_fn,
1085 static clib_error_t *
1086 promiscuous_cmd (vlib_main_t * vm,
1087 unformat_input_t * input, vlib_cli_command_t * cmd)
1089 vnet_main_t *vnm = vnet_get_main ();
1091 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
1092 ethernet_main_t *em = ðernet_main;
1093 ethernet_interface_t *eif;
1095 if (unformat (input, "on %U",
1096 unformat_vnet_hw_interface, vnm, &hw_if_index))
1098 else if (unformat (input, "off %U",
1099 unformat_ethernet_interface, vnm, &hw_if_index))
1102 return clib_error_return (0, "unknown input `%U'",
1103 format_unformat_error, input);
1105 eif = ethernet_get_interface (em, hw_if_index);
1107 return clib_error_return (0, "not supported");
1109 ethernet_set_flags (vnm, hw_if_index, flags);
1114 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1115 .path = "set interface promiscuous",
1116 .short_help = "set interface promiscuous [on|off] <interface>",
1117 .function = promiscuous_cmd,
1121 static clib_error_t *
1122 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1124 vnet_main_t *vnm = vnet_get_main ();
1125 u32 hw_if_index, sw_if_index, mtu;
1126 ethernet_main_t *em = ðernet_main;
1127 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
1129 if (unformat (input, "%d %U", &mtu,
1130 unformat_vnet_hw_interface, vnm, &hw_if_index))
1133 * Change physical MTU on interface. Only supported for Ethernet
1136 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1137 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1140 return clib_error_return (0, "not supported");
1142 if (mtu < hi->min_supported_packet_bytes)
1143 return clib_error_return (0, "Invalid mtu (%d): "
1144 "must be >= min pkt bytes (%d)", mtu,
1145 hi->min_supported_packet_bytes);
1147 if (mtu > hi->max_supported_packet_bytes)
1148 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1149 hi->max_supported_packet_bytes);
1151 vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
1154 else if (unformat (input, "packet %d %U", &mtu,
1155 unformat_vnet_sw_interface, vnm, &sw_if_index))
1156 /* Set default packet MTU (including L3 header */
1157 mtus[VNET_MTU_L3] = mtu;
1158 else if (unformat (input, "ip4 %d %U", &mtu,
1159 unformat_vnet_sw_interface, vnm, &sw_if_index))
1160 mtus[VNET_MTU_IP4] = mtu;
1161 else if (unformat (input, "ip6 %d %U", &mtu,
1162 unformat_vnet_sw_interface, vnm, &sw_if_index))
1163 mtus[VNET_MTU_IP6] = mtu;
1164 else if (unformat (input, "mpls %d %U", &mtu,
1165 unformat_vnet_sw_interface, vnm, &sw_if_index))
1166 mtus[VNET_MTU_MPLS] = mtu;
1168 return clib_error_return (0, "unknown input `%U'",
1169 format_unformat_error, input);
1171 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1178 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1179 .path = "set interface mtu",
1180 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
1181 .function = mtu_cmd,
1185 static clib_error_t *
1186 show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input,
1187 vlib_cli_command_t * cmd)
1189 vnet_main_t *vnm = vnet_get_main ();
1190 vnet_interface_main_t *im = &vnm->interface_main;
1191 ethernet_main_t *em = ðernet_main;
1192 u32 sw_if_index = ~0;
1193 vnet_sw_interface_t *si, *sorted_sis = 0;
1195 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1197 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1198 vec_add1 (sorted_sis, si[0]);
1201 /* if an interface name was not passed, get all interfaces */
1202 if (vec_len (sorted_sis) == 0)
1205 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
1206 _vec_len (sorted_sis) = 0;
1208 pool_foreach (si, im->sw_interfaces)
1210 int visible = vnet_swif_is_api_visible (si);
1212 vec_add1 (sorted_sis, si[0]);
1216 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
1219 vec_foreach (si, sorted_sis)
1221 vnet_sw_interface_t *sup_si;
1222 ethernet_interface_t *ei;
1224 sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
1225 ei = ethernet_get_interface (em, sup_si->hw_if_index);
1227 vlib_cli_output (vm, "%U (%s):",
1228 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
1229 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
1232 if (ei && ei->secondary_addrs)
1234 ethernet_interface_address_t *sec_addr;
1236 vec_foreach (sec_addr, ei->secondary_addrs)
1238 vlib_cli_output (vm, " %U", format_mac_address_t, &sec_addr->mac);
1243 vec_free (sorted_sis);
1248 * This command is used to display interface secondary mac addresses.
1251 * Example of how to display interface secondary mac addresses:
1252 * @cliexstart{show interface secondary-mac-address}
1256 VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = {
1257 .path = "show interface secondary-mac-address",
1258 .short_help = "show interface secondary-mac-address [<interface>]",
1259 .function = show_interface_sec_mac_addr_fn,
1263 static clib_error_t *
1264 interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input,
1265 vlib_cli_command_t * cmd)
1267 vnet_main_t *vnm = vnet_get_main ();
1268 vnet_sw_interface_t *si = NULL;
1269 clib_error_t *error = 0;
1270 u32 sw_if_index = ~0;
1274 is_add = is_del = 0;
1276 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1278 error = clib_error_return (0, "unknown interface `%U'",
1279 format_unformat_error, input);
1282 if (!unformat_user (input, unformat_ethernet_address, mac))
1284 error = clib_error_return (0, "expected mac address `%U'",
1285 format_unformat_error, input);
1289 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1291 if (unformat (input, "add"))
1293 else if (unformat (input, "del"))
1299 if (is_add == is_del)
1301 error = clib_error_return (0, "must choose one of add or del");
1305 si = vnet_get_sw_interface (vnm, sw_if_index);
1307 vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add);
1314 * The '<em>set interface secondary-mac-address </em>' command allows adding
1315 * or deleting extra MAC addresses on a given interface without changing the
1316 * default MAC address. This could allow packets sent to these MAC addresses
1317 * to be received without setting the interface to promiscuous mode.
1318 * Not all interfaces support this operation. The ones that do are mostly
1319 * hardware NICs, though virtio does also.
1323 * Example of how to add a secondary MAC Address on an interface:
1324 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add}
1325 * Example of how to delete a secondary MAC address from an interface:
1326 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del}
1330 VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = {
1331 .path = "set interface secondary-mac-address",
1332 .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]",
1333 .function = interface_add_del_mac_address,
1337 static clib_error_t *
1338 set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1339 vlib_cli_command_t * cmd)
1341 vnet_main_t *vnm = vnet_get_main ();
1342 vnet_sw_interface_t *si = NULL;
1343 clib_error_t *error = 0;
1344 u32 sw_if_index = ~0;
1347 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1349 error = clib_error_return (0, "unknown interface `%U'",
1350 format_unformat_error, input);
1353 if (!unformat_user (input, unformat_ethernet_address, mac))
1355 error = clib_error_return (0, "expected mac address `%U'",
1356 format_unformat_error, input);
1359 si = vnet_get_sw_interface (vnm, sw_if_index);
1360 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
1366 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1367 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1368 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1372 * Example of how to change MAC Address of interface:
1373 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1374 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1375 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1376 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1380 VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1381 .path = "set interface mac address",
1382 .short_help = "set interface mac address <interface> <mac-address>",
1383 .function = set_interface_mac_address,
1387 static clib_error_t *
1388 set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1390 vnet_main_t *vnm = vnet_get_main ();
1391 u32 sw_if_index = ~0;
1394 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1395 vnm, &sw_if_index, &tag))
1396 return clib_error_return (0, "unknown input `%U'",
1397 format_unformat_error, input);
1399 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1405 VLIB_CLI_COMMAND (set_tag_command, static) = {
1406 .path = "set interface tag",
1407 .short_help = "set interface tag <interface> <tag>",
1408 .function = set_tag,
1412 static clib_error_t *
1413 clear_tag (vlib_main_t * vm, unformat_input_t * input,
1414 vlib_cli_command_t * cmd)
1416 vnet_main_t *vnm = vnet_get_main ();
1417 u32 sw_if_index = ~0;
1419 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1420 return clib_error_return (0, "unknown input `%U'",
1421 format_unformat_error, input);
1423 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1429 VLIB_CLI_COMMAND (clear_tag_command, static) = {
1430 .path = "clear interface tag",
1431 .short_help = "clear interface tag <interface>",
1432 .function = clear_tag,
1436 static clib_error_t *
1437 set_ip_directed_broadcast (vlib_main_t * vm,
1438 unformat_input_t * input, vlib_cli_command_t * cmd)
1440 vnet_main_t *vnm = vnet_get_main ();
1441 u32 sw_if_index = ~0;
1444 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1445 else if (unformat (input, "enable"))
1447 else if (unformat (input, "disable"))
1450 return clib_error_return (0, "unknown input: `%U'",
1451 format_unformat_error, input);
1453 if (~0 == sw_if_index)
1454 return clib_error_return (0, "specify an interface: `%U'",
1455 format_unformat_error, input);
1457 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1463 * This command is used to enable/disable IP directed broadcast
1464 * If directed broadcast is enabled a packet sent to the interface's
1465 * subnet broadcast address will be sent L2 broadcast on the interface,
1466 * otherwise it is dropped.
1469 VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1470 .path = "set interface ip directed-broadcast",
1471 .short_help = "set interface enable <interface> <enable|disable>",
1472 .function = set_ip_directed_broadcast,
1477 set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1478 u8 queue_id_valid, u32 queue_id,
1479 vnet_hw_if_rx_mode mode)
1481 clib_error_t *error = 0;
1482 vnet_hw_interface_t *hw;
1483 u32 *queue_indices = 0;
1485 hw = vnet_get_hw_interface (vnm, hw_if_index);
1491 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1492 if (queue_index == ~0)
1493 return clib_error_return (0, "unknown queue %u on interface %s",
1494 queue_id, hw->name);
1495 vec_add1 (queue_indices, queue_index);
1498 queue_indices = hw->rx_queue_indices;
1500 for (int i = 0; i < vec_len (queue_indices); i++)
1502 int rv = vnet_hw_if_set_rx_queue_mode (vnm, queue_indices[i], mode);
1508 if (queue_indices != hw->rx_queue_indices)
1509 vec_free (queue_indices);
1510 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1514 static clib_error_t *
1515 set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1516 vlib_cli_command_t * cmd)
1518 clib_error_t *error = 0;
1519 unformat_input_t _line_input, *line_input = &_line_input;
1520 vnet_main_t *vnm = vnet_get_main ();
1521 u32 hw_if_index = (u32) ~ 0;
1522 u32 queue_id = (u32) ~ 0;
1523 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
1524 u8 queue_id_valid = 0;
1526 if (!unformat_user (input, unformat_line_input, line_input))
1529 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1532 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1534 else if (unformat (line_input, "queue %d", &queue_id))
1536 else if (unformat (line_input, "polling"))
1537 mode = VNET_HW_IF_RX_MODE_POLLING;
1538 else if (unformat (line_input, "interrupt"))
1539 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
1540 else if (unformat (line_input, "adaptive"))
1541 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
1544 error = clib_error_return (0, "parse error: '%U'",
1545 format_unformat_error, line_input);
1546 unformat_free (line_input);
1551 unformat_free (line_input);
1553 if (hw_if_index == (u32) ~ 0)
1554 return clib_error_return (0, "please specify valid interface name");
1556 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
1557 return clib_error_return (0, "please specify valid rx-mode");
1559 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1566 * This command is used to assign the RX packet processing mode (polling,
1567 * interrupt, adaptive) of the a given interface, and optionally a
1568 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1569 * is applied to all queues of the interface. Not all interfaces support
1570 * all modes. To display the current rx-mode use the command
1571 * '<em>show interface rx-placement</em>'.
1574 * Example of how to assign rx-mode to all queues on an interface:
1575 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1576 * Example of how to assign rx-mode to one queue of an interface:
1577 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1578 * Example of how to display the rx-mode of all interfaces:
1579 * @cliexstart{show interface rx-placement}
1580 * Thread 1 (vpp_wk_0):
1582 * GigabitEthernet7/0/0 queue 0 (polling)
1583 * node vhost-user-input:
1584 * VirtualEthernet0/0/12 queue 0 (interrupt)
1585 * VirtualEthernet0/0/12 queue 2 (polling)
1586 * VirtualEthernet0/0/13 queue 0 (polling)
1587 * VirtualEthernet0/0/13 queue 2 (polling)
1588 * Thread 2 (vpp_wk_1):
1590 * GigabitEthernet7/0/1 queue 0 (polling)
1591 * node vhost-user-input:
1592 * VirtualEthernet0/0/12 queue 1 (polling)
1593 * VirtualEthernet0/0/12 queue 3 (polling)
1594 * VirtualEthernet0/0/13 queue 1 (polling)
1595 * VirtualEthernet0/0/13 queue 3 (polling)
1599 VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
1600 .path = "set interface rx-mode",
1601 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1602 .function = set_interface_rx_mode,
1606 static clib_error_t *
1607 show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1608 vlib_cli_command_t * cmd)
1611 vnet_main_t *vnm = vnet_get_main ();
1612 vnet_hw_if_rx_queue_t **all_queues = 0;
1613 vnet_hw_if_rx_queue_t **qptr;
1614 vnet_hw_if_rx_queue_t *q;
1615 vec_foreach (q, vnm->interface_main.hw_if_rx_queues)
1616 vec_add1 (all_queues, q);
1617 vec_sort_with_function (all_queues, vnet_hw_if_rxq_cmp_cli_api);
1620 vec_foreach (qptr, all_queues)
1622 u32 current_thread = qptr[0]->thread_index;
1623 u32 hw_if_index = qptr[0]->hw_if_index;
1624 vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
1625 u32 current_node = hw_if->input_node_index;
1626 if (current_node != prev_node)
1627 s = format (s, " node %U:\n", format_vlib_node_name, vm, current_node);
1628 s = format (s, " %U queue %u (%U)\n", format_vnet_sw_if_index_name,
1629 vnm, hw_if->sw_if_index, qptr[0]->queue_id,
1630 format_vnet_hw_if_rx_mode, qptr[0]->mode);
1631 if (qptr == all_queues + vec_len (all_queues) - 1 ||
1632 current_thread != qptr[1]->thread_index)
1634 vlib_cli_output (vm, "Thread %u (%s):\n%v", current_thread,
1635 vlib_worker_threads[current_thread].name, s);
1636 vec_reset_length (s);
1638 prev_node = current_node;
1641 vec_free (all_queues);
1646 * This command is used to display the interface and queue worker
1650 * Example of how to display the interface placement:
1651 * @cliexstart{show interface rx-placement}
1652 * Thread 1 (vpp_wk_0):
1654 * GigabitEthernet7/0/0 queue 0 (polling)
1655 * node vhost-user-input:
1656 * VirtualEthernet0/0/12 queue 0 (polling)
1657 * VirtualEthernet0/0/12 queue 2 (polling)
1658 * VirtualEthernet0/0/13 queue 0 (polling)
1659 * VirtualEthernet0/0/13 queue 2 (polling)
1660 * Thread 2 (vpp_wk_1):
1662 * GigabitEthernet7/0/1 queue 0 (polling)
1663 * node vhost-user-input:
1664 * VirtualEthernet0/0/12 queue 1 (polling)
1665 * VirtualEthernet0/0/12 queue 3 (polling)
1666 * VirtualEthernet0/0/13 queue 1 (polling)
1667 * VirtualEthernet0/0/13 queue 3 (polling)
1671 VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1672 .path = "show interface rx-placement",
1673 .short_help = "show interface rx-placement",
1674 .function = show_interface_rx_placement_fn,
1678 set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1679 u32 thread_index, u8 is_main)
1681 vnet_main_t *vnm = vnet_get_main ();
1682 vnet_device_main_t *vdm = &vnet_device_main;
1683 vnet_hw_interface_t *hw;
1689 thread_index += vdm->first_worker_thread_index;
1691 if (thread_index > vdm->last_worker_thread_index)
1692 return clib_error_return (0,
1693 "please specify valid worker thread or main");
1695 hw = vnet_get_hw_interface (vnm, hw_if_index);
1698 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1699 if (queue_index == ~0)
1700 return clib_error_return (0, "unknown queue %u on interface %s", queue_id,
1702 vnet_hw_if_set_rx_queue_thread_index (vnm, queue_index, thread_index);
1703 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1707 static clib_error_t *
1708 set_interface_rx_placement (vlib_main_t *vm, unformat_input_t *input,
1709 vlib_cli_command_t *cmd)
1711 clib_error_t *error = 0;
1712 unformat_input_t _line_input, *line_input = &_line_input;
1713 vnet_main_t *vnm = vnet_get_main ();
1714 u32 hw_if_index = (u32) ~ 0;
1715 u32 queue_id = (u32) 0;
1716 u32 thread_index = (u32) ~ 0;
1719 if (!unformat_user (input, unformat_line_input, line_input))
1722 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1725 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1727 else if (unformat (line_input, "queue %d", &queue_id))
1729 else if (unformat (line_input, "main", &thread_index))
1731 else if (unformat (line_input, "worker %d", &thread_index))
1735 error = clib_error_return (0, "parse error: '%U'",
1736 format_unformat_error, line_input);
1737 unformat_free (line_input);
1742 unformat_free (line_input);
1744 if (hw_if_index == (u32) ~ 0)
1745 return clib_error_return (0, "please specify valid interface name");
1747 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1754 * This command is used to assign a given interface, and optionally a
1755 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1756 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1757 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
1760 * Example of how to display the interface placement:
1761 * @cliexstart{show interface rx-placement}
1762 * Thread 1 (vpp_wk_0):
1764 * GigabitEthernet7/0/0 queue 0 (polling)
1765 * node vhost-user-input:
1766 * VirtualEthernet0/0/12 queue 0 (polling)
1767 * VirtualEthernet0/0/12 queue 2 (polling)
1768 * VirtualEthernet0/0/13 queue 0 (polling)
1769 * VirtualEthernet0/0/13 queue 2 (polling)
1770 * Thread 2 (vpp_wk_1):
1772 * GigabitEthernet7/0/1 queue 0 (polling)
1773 * node vhost-user-input:
1774 * VirtualEthernet0/0/12 queue 1 (polling)
1775 * VirtualEthernet0/0/12 queue 3 (polling)
1776 * VirtualEthernet0/0/13 queue 1 (polling)
1777 * VirtualEthernet0/0/13 queue 3 (polling)
1779 * Example of how to assign a interface and queue to a worker thread:
1780 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1781 * Example of how to display the interface placement:
1782 * @cliexstart{show interface rx-placement}
1783 * Thread 1 (vpp_wk_0):
1785 * GigabitEthernet7/0/0 queue 0 (polling)
1786 * node vhost-user-input:
1787 * VirtualEthernet0/0/12 queue 0 (polling)
1788 * VirtualEthernet0/0/12 queue 1 (polling)
1789 * VirtualEthernet0/0/12 queue 2 (polling)
1790 * VirtualEthernet0/0/13 queue 0 (polling)
1791 * VirtualEthernet0/0/13 queue 2 (polling)
1792 * Thread 2 (vpp_wk_1):
1794 * GigabitEthernet7/0/1 queue 0 (polling)
1795 * node vhost-user-input:
1796 * VirtualEthernet0/0/12 queue 3 (polling)
1797 * VirtualEthernet0/0/13 queue 1 (polling)
1798 * VirtualEthernet0/0/13 queue 3 (polling)
1802 VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1803 .path = "set interface rx-placement",
1804 .short_help = "set interface rx-placement <interface> [queue <n>] "
1805 "[worker <n> | main]",
1806 .function = set_interface_rx_placement,
1812 set_interface_rss_queues (vlib_main_t * vm, u32 hw_if_index,
1813 clib_bitmap_t * bitmap)
1815 vnet_main_t *vnm = vnet_get_main ();
1816 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1818 return vnet_hw_interface_set_rss_queues (vnm, hi, bitmap);
1821 static clib_error_t *
1822 set_interface_rss_queues_fn (vlib_main_t * vm,
1823 unformat_input_t * input,
1824 vlib_cli_command_t * cmd)
1826 clib_error_t *error = 0;
1827 unformat_input_t _line_input, *line_input = &_line_input;
1828 vnet_main_t *vnm = vnet_get_main ();
1829 u32 hw_if_index = (u32) ~ 0;
1830 clib_bitmap_t *bitmap = NULL;
1832 if (!unformat_user (input, unformat_line_input, line_input))
1835 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1838 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1841 if (unformat (line_input, "list %U", unformat_bitmap_list, &bitmap))
1845 error = clib_error_return (0, "parse error: '%U'",
1846 format_unformat_error, line_input);
1847 unformat_free (line_input);
1852 unformat_free (line_input);
1854 if (hw_if_index == (u32) ~ 0)
1856 error = clib_error_return (0, "please specify valid interface name");
1862 error = clib_error_return (0, "please specify the valid rss queues");
1866 error = set_interface_rss_queues (vm, hw_if_index, bitmap);
1870 clib_bitmap_free (bitmap);
1876 * This command is used to set the rss queues of a given interface
1877 * Not all the interfaces support this operation.
1878 * To display the current rss queues, use the command
1879 * '<em>show hardware-interfaces</em>'.
1882 * Example of how to set the rss queues to 0,2-5,7 of an interface:
1883 * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7}
1887 VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = {
1888 .path = "set interface rss queues",
1889 .short_help = "set interface rss queues <interface> <list <queue-list>>",
1890 .function = set_interface_rss_queues_fn,
1895 format_vnet_pcap (u8 * s, va_list * args)
1897 vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *);
1898 int type = va_arg (*args, int);
1903 if (pp->pcap_rx_enable)
1905 s = format (s, "rx");
1908 if (pp->pcap_tx_enable)
1911 s = format (s, " and ");
1912 s = format (s, "tx");
1915 if (pp->pcap_drop_enable)
1918 s = format (s, " and ");
1919 s = format (s, "drop");
1924 s = format (s, "unknown type %d!", type);
1930 vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
1932 vlib_main_t *vm = vlib_get_main ();
1933 vnet_pcap_t *pp = &vm->pcap;
1934 pcap_main_t *pm = &pp->pcap_main;
1935 vnet_classify_main_t *cm = &vnet_classify_main;
1939 if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable)
1942 (vm, "pcap %U dispatch capture enabled: %d of %d pkts...",
1943 format_vnet_pcap, pp, 0 /* print type */ ,
1944 pm->n_packets_captured, pm->n_packets_to_capture);
1945 vlib_cli_output (vm, "capture to file %s", pm->file_name);
1948 vlib_cli_output (vm, "pcap dispatch capture disabled");
1953 /* Consistency checks */
1955 /* Enable w/ capture already enabled not allowed */
1956 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
1957 && (a->rx_enable + a->tx_enable + a->drop_enable))
1958 return VNET_API_ERROR_INVALID_VALUE;
1960 /* Disable capture with capture already disabled, not interesting */
1961 if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) ==
1963 ((a->rx_enable + a->tx_enable + a->drop_enable == 0)))
1964 return VNET_API_ERROR_VALUE_EXIST;
1966 /* Change number of packets to capture while capturing */
1967 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
1968 && (a->rx_enable + a->tx_enable + a->drop_enable)
1969 && (pm->n_packets_to_capture != a->packets_to_capture))
1970 return VNET_API_ERROR_INVALID_VALUE_2;
1972 /* Classify filter specified, but no classify filter configured */
1973 if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter &&
1974 cm->classify_table_index_by_sw_if_index[0] == ~0)
1975 return VNET_API_ERROR_NO_SUCH_LABEL;
1977 if (a->rx_enable + a->tx_enable + a->drop_enable)
1979 void *save_pcap_data;
1981 /* Sanity check max bytes per pkt */
1982 if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000)
1983 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
1985 /* Clean up from previous run, if any */
1986 vec_reset_length (pm->pcap_data);
1988 /* Throw away the data buffer? */
1990 vec_free (pm->pcap_data);
1992 save_pcap_data = pm->pcap_data;
1994 memset (pm, 0, sizeof (*pm));
1996 pm->pcap_data = save_pcap_data;
1998 vec_validate_aligned (vnet_trace_placeholder, 2048,
1999 CLIB_CACHE_LINE_BYTES);
2001 clib_spinlock_init (&(pm->lock));
2003 if (a->filename == 0)
2008 stem = format (stem, "rx");
2010 stem = format (stem, "tx");
2012 stem = format (stem, "drop");
2013 a->filename = format (0, "/tmp/%v.pcap%c", stem, 0);
2017 pm->file_name = (char *) a->filename;
2018 pm->n_packets_captured = 0;
2019 pm->packet_type = PCAP_PACKET_TYPE_ethernet;
2020 /* Preallocate the data vector? */
2021 if (a->preallocate_data)
2024 (pm->pcap_data, a->packets_to_capture
2025 * ((sizeof (pcap_packet_header_t) + a->max_bytes_per_pkt)));
2026 vec_reset_length (pm->pcap_data);
2028 pm->n_packets_to_capture = a->packets_to_capture;
2029 pp->pcap_sw_if_index = a->sw_if_index;
2031 pp->filter_classify_table_index =
2032 cm->classify_table_index_by_sw_if_index[0];
2034 pp->filter_classify_table_index = ~0;
2035 pp->pcap_rx_enable = a->rx_enable;
2036 pp->pcap_tx_enable = a->tx_enable;
2037 pp->pcap_drop_enable = a->drop_enable;
2038 pp->max_bytes_per_pkt = a->max_bytes_per_pkt;
2042 pp->pcap_rx_enable = 0;
2043 pp->pcap_tx_enable = 0;
2044 pp->pcap_drop_enable = 0;
2045 pp->filter_classify_table_index = ~0;
2046 if (pm->n_packets_captured)
2048 clib_error_t *error;
2049 pm->n_packets_to_capture = pm->n_packets_captured;
2050 vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
2051 pm->n_packets_captured, pm->file_name);
2052 error = pcap_write (pm);
2053 if (pm->flags & PCAP_MAIN_INIT_DONE)
2055 /* Report I/O errors... */
2058 clib_error_report (error);
2059 return VNET_API_ERROR_SYSCALL_ERROR_1;
2061 vec_free (pm->file_name);
2063 vec_free (pm->pcap_data);
2067 return VNET_API_ERROR_NO_SUCH_ENTRY;
2073 static clib_error_t *
2074 pcap_trace_command_fn (vlib_main_t * vm,
2075 unformat_input_t * input, vlib_cli_command_t * cmd)
2077 unformat_input_t _line_input, *line_input = &_line_input;
2078 vnet_pcap_dispatch_trace_args_t _a, *a = &_a;
2079 vnet_main_t *vnm = vnet_get_main ();
2082 u32 max_bytes_per_pkt = 512;
2086 int preallocate_data = 0;
2087 int drop_enable = 0;
2091 u32 sw_if_index = 0; /* default: any interface */
2093 /* Get a line of input. */
2094 if (!unformat_user (input, unformat_line_input, line_input))
2097 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2099 if (unformat (line_input, "rx"))
2101 else if (unformat (line_input, "tx"))
2103 else if (unformat (line_input, "drop"))
2105 else if (unformat (line_input, "off"))
2106 rx_enable = tx_enable = drop_enable = 0;
2107 else if (unformat (line_input, "max-bytes-per-pkt %u",
2108 &max_bytes_per_pkt))
2110 else if (unformat (line_input, "max %d", &max))
2112 else if (unformat (line_input, "packets-to-capture %d", &max))
2114 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
2117 else if (unformat (line_input, "status %=", &status, 1))
2119 else if (unformat (line_input, "intfc %U",
2120 unformat_vnet_sw_interface, vnm, &sw_if_index))
2122 else if (unformat (line_input, "interface %U",
2123 unformat_vnet_sw_interface, vnm, &sw_if_index))
2125 else if (unformat (line_input, "preallocate-data %=",
2126 &preallocate_data, 1))
2128 else if (unformat (line_input, "free-data %=", &free_data, 1))
2130 else if (unformat (line_input, "intfc any")
2131 || unformat (line_input, "interface any"))
2133 else if (unformat (line_input, "filter"))
2137 return clib_error_return (0, "unknown input `%U'",
2138 format_unformat_error, line_input);
2142 unformat_free (line_input);
2144 /* no need for memset (a, 0, sizeof (*a)), set all fields here. */
2145 a->filename = filename;
2146 a->rx_enable = rx_enable;
2147 a->tx_enable = tx_enable;
2148 a->preallocate_data = preallocate_data;
2149 a->free_data = free_data;
2150 a->drop_enable = drop_enable;
2152 a->packets_to_capture = max;
2153 a->sw_if_index = sw_if_index;
2155 a->max_bytes_per_pkt = max_bytes_per_pkt;
2157 rv = vnet_pcap_dispatch_trace_configure (a);
2164 case VNET_API_ERROR_INVALID_VALUE:
2165 return clib_error_return (0, "dispatch trace already enabled...");
2167 case VNET_API_ERROR_VALUE_EXIST:
2168 return clib_error_return (0, "dispatch trace already disabled...");
2170 case VNET_API_ERROR_INVALID_VALUE_2:
2171 return clib_error_return
2172 (0, "can't change number of records to capture while tracing...");
2174 case VNET_API_ERROR_SYSCALL_ERROR_1:
2175 return clib_error_return (0, "I/O writing trace capture...");
2177 case VNET_API_ERROR_NO_SUCH_ENTRY:
2178 return clib_error_return (0, "No packets captured...");
2180 case VNET_API_ERROR_INVALID_MEMORY_SIZE:
2181 return clib_error_return (0,
2182 "Max bytes per pkt must be > 32, < 9000...");
2184 case VNET_API_ERROR_NO_SUCH_LABEL:
2185 return clib_error_return
2186 (0, "No classify filter configured, see 'classify filter...'");
2189 vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
2196 * This command is used to start or stop a packet capture, or show
2197 * the status of packet capture.
2199 * This command has the following optional parameters:
2202 * - <b>rx</b> - Capture received packets
2204 * - <b>tx</b> - Capture transmitted packets
2206 * - <b>drop</b> - Capture dropped packets
2208 * - <b>off</b> - Stop capturing packets, write results to the specified file
2210 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
2211 * of packets have been received, buffer is flushed to file. Once another
2212 * '<em>nn</em>' number of packets have been received, buffer is flushed
2213 * to file, overwriting previous write. If not entered, value defaults
2214 * to 100. Can only be updated if packet capture is off.
2216 * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture
2217 * for each packet. Must be >= 32, <= 9000.
2219 * - <b>preallocate-data</b> - Preallocate the data buffer, to avoid
2220 * vector expansion delays during pcap capture
2222 * - <b>free-data</b> - Free the data buffer. Ordinarily it's a feature
2223 * to retain the data buffer so this option is seldom used.
2225 * - <b>intfc <interface-name>|any</b> - Used to specify a given interface,
2226 * or use '<em>any</em>' to run packet capture on all interfaces.
2227 * '<em>any</em>' is the default if not provided. Settings from a previous
2228 * packet capture are preserved, so '<em>any</em>' can be used to reset
2229 * the interface setting.
2231 * - <b>filter</b> - Use the pcap rx / tx / drop trace filter, which
2232 * must be configured. Use <b>classify filter pcap...</b> to configure the
2233 * filter. The filter will only be executed if the per-interface or
2234 * any-interface tests fail.
2236 * - <b>file <name></b> - Used to specify the output filename. The file will
2237 * be placed in the '<em>/tmp</em>' directory, so only the filename is
2238 * supported. Directory should not be entered. If file already exists, file
2239 * will be overwritten. If no filename is provided, the file will be
2240 * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc.
2241 * Can only be updated if packet capture is off.
2243 * - <b>status</b> - Displays the current status and configured attributes
2244 * associated with a packet capture. If packet capture is in progress,
2245 * '<em>status</em>' also will return the number of packets currently in
2246 * the local buffer. All additional attributes entered on command line
2247 * with '<em>status</em>' will be ignored and not applied.
2250 * Example of how to display the status of a tx packet capture when off:
2251 * @cliexstart{pcap trace status}
2252 * max is 100, for any interface to file /tmp/vpe.pcap
2253 * pcap tx capture is off...
2255 * Example of how to start a tx packet capture:
2256 * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file vppTest.pcap}
2258 * Example of how to display the status of a tx packet capture in progress:
2259 * @cliexstart{pcap trace status}
2260 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
2261 * pcap tx capture is on: 20 of 35 pkts...
2263 * Example of how to stop a tx packet capture:
2264 * @cliexstart{pcap trace off}
2265 * captured 21 pkts...
2266 * saved to /tmp/vppTest.pcap...
2271 VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
2272 .path = "pcap trace",
2274 "pcap trace [rx] [tx] [drop] [off] [max <nn>] [intfc <interface>|any]\n"
2275 " [file <name>] [status] [max-bytes-per-pkt <nnnn>][filter]\n"
2276 " [preallocate-data][free-data]",
2277 .function = pcap_trace_command_fn,
2282 * fd.io coding-style-patch-verification: ON
2285 * eval: (c-set-style "gnu")