2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 * interface_cli.c: interface CLI
18 * Copyright (c) 2008 Eliot Dresselhaus
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 * @brief Interface CLI.
44 * Source code for several CLI interface commands.
48 #include <vnet/vnet.h>
49 #include <vnet/ip/ip.h>
50 #include <vppinfra/bitmap.h>
51 #include <vnet/fib/ip4_fib.h>
52 #include <vnet/fib/ip6_fib.h>
53 #include <vnet/l2/l2_output.h>
54 #include <vnet/l2/l2_input.h>
55 #include <vnet/classify/vnet_classify.h>
56 #include <vnet/interface/rx_queue_funcs.h>
59 compare_interface_names (void *a1, void *a2)
64 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
68 show_or_clear_hw_interfaces (vlib_main_t * vm,
69 unformat_input_t * input,
70 vlib_cli_command_t * cmd, int is_show)
72 clib_error_t *error = 0;
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 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
81 /* See if user wants to show a specific interface. */
83 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
84 vec_add1 (hw_if_indices, hw_if_index);
86 /* See if user wants to show an interface with a specific hw_if_index. */
87 else if (unformat (input, "%u", &hw_if_index))
88 vec_add1 (hw_if_indices, hw_if_index);
90 else if (unformat (input, "verbose"))
91 verbose = 1; /* this is also the default */
93 else if (unformat (input, "detail"))
96 else if (unformat (input, "brief"))
99 else if (unformat (input, "bond"))
103 verbose = 0; /* default to brief for link bonding */
108 error = clib_error_return (0, "unknown input `%U'",
109 format_unformat_error, input);
114 /* Gather interfaces. */
115 if (vec_len (hw_if_indices) == 0)
116 pool_foreach (hi, im->hw_interfaces)
117 vec_add1 (hw_if_indices, hi - im->hw_interfaces);
120 verbose = 1; /* default to verbose (except bond) */
125 vec_sort_with_function (hw_if_indices, compare_interface_names);
127 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
128 for (i = 0; i < vec_len (hw_if_indices); i++)
130 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
131 if (show_bond == 0) /* show all interfaces */
132 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
134 else if ((hi->bond_info) &&
135 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
136 { /* show only bonded interface and all its slave interfaces */
138 vnet_hw_interface_t *shi;
139 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
143 clib_bitmap_foreach (hw_idx, hi->bond_info)
145 shi = vnet_get_hw_interface(vnm, hw_idx);
146 vlib_cli_output (vm, "%U\n",
147 format_vnet_hw_interface, vnm, shi, verbose);
155 for (i = 0; i < vec_len (hw_if_indices); i++)
157 vnet_device_class_t *dc;
159 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
160 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
162 if (dc->clear_counters)
163 dc->clear_counters (hi->dev_instance);
168 vec_free (hw_if_indices);
172 static clib_error_t *
173 show_hw_interfaces (vlib_main_t * vm,
174 unformat_input_t * input, vlib_cli_command_t * cmd)
176 return show_or_clear_hw_interfaces (vm, input, cmd, 1 /* is_show */ );
179 static clib_error_t *
180 clear_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, 0 /* is_show */ );
188 * Display more detailed information about all or a list of given interfaces.
189 * The verboseness of the output can be controlled by the following optional
191 * - brief: Only show name, index and state (default for bonded interfaces).
192 * - verbose: Also display additional attributes (default for all other interfaces).
193 * - detail: Also display all remaining attributes and extended statistics.
195 * To limit the output of the command to bonded interfaces and their slave
196 * interfaces, use the '<em>bond</em>' optional parameter.
199 * Example of how to display default data for all interfaces:
200 * @cliexstart{show hardware-interfaces}
201 * Name Idx Link Hardware
202 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
203 * Ethernet address ec:f4:bb:c0:bc:fc
205 * carrier up full duplex speed 1000 mtu 9216
206 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
208 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
209 * Ethernet address ec:f4:bb:c0:bc:fd
211 * carrier up full duplex speed 1000 mtu 9216
212 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
214 * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0
215 * Ethernet address 02:fe:a5:a9:8b:8e
216 * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1
217 * Ethernet address 02:fe:c0:4e:3b:b0
218 * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2
219 * Ethernet address 02:fe:1f:73:92:81
220 * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3
221 * Ethernet address 02:fe:f2:25:c4:68
222 * local0 0 down local0
225 * Example of how to display '<em>verbose</em>' data for an interface by name and
226 * software index (where 2 is the software index):
227 * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose}
228 * Name Idx Link Hardware
229 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
230 * Ethernet address ec:f4:bb:c0:bc:fc
232 * carrier up full duplex speed 1000 mtu 9216
233 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
235 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
236 * Ethernet address ec:f4:bb:c0:bc:fd
238 * carrier up full duplex speed 1000 mtu 9216
239 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
244 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
245 .path = "show hardware-interfaces",
246 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
247 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
248 .function = show_hw_interfaces,
254 * Clear the extended statistics for all or a list of given interfaces
255 * (statistics associated with the '<em>show hardware-interfaces</em>' command).
258 * Example of how to clear the extended statistics for all interfaces:
259 * @cliexcmd{clear hardware-interfaces}
260 * Example of how to clear the extended statistics for an interface by
261 * name and software index (where 2 is the software index):
262 * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2}
265 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
266 .path = "clear hardware-interfaces",
267 .short_help = "clear hardware-interfaces "
268 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
269 .function = clear_hw_interfaces,
274 sw_interface_name_compare (void *a1, void *a2)
276 vnet_sw_interface_t *si1 = a1;
277 vnet_sw_interface_t *si2 = a2;
279 return vnet_sw_interface_compare (vnet_get_main (),
280 si1->sw_if_index, si2->sw_if_index);
283 static clib_error_t *
284 show_sw_interfaces (vlib_main_t * vm,
285 unformat_input_t * input, vlib_cli_command_t * cmd)
287 clib_error_t *error = 0;
288 vnet_main_t *vnm = vnet_get_main ();
289 unformat_input_t _linput, *linput = &_linput;
290 vnet_interface_main_t *im = &vnm->interface_main;
291 vnet_sw_interface_t *si, *sorted_sis = 0;
292 u32 sw_if_index = ~(u32) 0;
293 u8 show_addresses = 0;
294 u8 show_features = 0;
300 * Get a line of input. Won't work if the user typed
301 * "show interface" and nothing more.
303 if (unformat_user (input, unformat_line_input, linput))
305 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
307 /* See if user wants to show specific interface */
309 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
311 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
312 vec_add1 (sorted_sis, si[0]);
314 else if (unformat (linput, "address") || unformat (linput, "addr"))
316 else if (unformat (linput, "features") || unformat (linput, "feat"))
318 else if (unformat (linput, "tag"))
320 else if (unformat (linput, "vtr"))
322 else if (unformat (linput, "verbose"))
326 vec_free (sorted_sis);
327 error = clib_error_return (0, "unknown input `%U'",
328 format_unformat_error, linput);
332 unformat_free (linput);
334 if (show_features || show_tag || show_vtr)
336 if (sw_if_index == ~(u32) 0)
338 vec_free (sorted_sis);
339 return clib_error_return (0, "Interface not specified...");
345 vnet_interface_features_show (vm, sw_if_index, verbose);
346 vlib_cli_output (vm, "%U", format_l2_input_features, sw_if_index, 1);
348 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
349 vlib_cli_output (vm, "\nl2-output:");
350 if (l2_output->out_vtr_flag)
351 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
352 vlib_cli_output (vm, "%U", format_l2_output_features,
353 l2_output->feature_bitmap, 1);
354 vec_free (sorted_sis);
360 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
361 vlib_cli_output (vm, "%U: %s",
362 format_vnet_sw_if_index_name, vnm, sw_if_index,
363 tag ? (char *) tag : "(none)");
364 vec_free (sorted_sis);
369 * Show vlan tag rewrite data for one interface.
373 u32 vtr_op = L2_VTR_DISABLED;
374 u32 push_dot1q = 0, tag1 = 0, tag2 = 0;
376 if (l2vtr_get (vm, vnm, sw_if_index,
377 &vtr_op, &push_dot1q, &tag1, &tag2) != 0)
379 vlib_cli_output (vm, "%U: Problem getting vlan tag-rewrite data",
380 format_vnet_sw_if_index_name, vnm, sw_if_index);
383 vlib_cli_output (vm, "%U: VTR %0U",
384 format_vnet_sw_if_index_name, vnm, sw_if_index,
385 format_vtr, vtr_op, push_dot1q, tag1, tag2);
390 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
392 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
394 /* Gather interfaces. */
396 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
397 _vec_len (sorted_sis) = 0;
399 pool_foreach (si, im->sw_interfaces)
401 int visible = vnet_swif_is_api_visible (si);
403 vec_add1 (sorted_sis, si[0]);
407 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
412 vec_foreach (si, sorted_sis)
414 ip4_main_t *im4 = &ip4_main;
415 ip6_main_t *im6 = &ip6_main;
416 ip_lookup_main_t *lm4 = &im4->lookup_main;
417 ip_lookup_main_t *lm6 = &im6->lookup_main;
418 ip_interface_address_t *ia = 0;
419 u32 fib_index4 = 0, fib_index6 = 0;
421 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
422 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
425 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
426 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
429 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
430 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
432 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
434 (vm, "%U (%s): \n unnumbered, use %U",
435 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
436 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
437 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
441 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
442 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
444 /* Display any L2 info */
445 vlib_cli_output (vm, "%U", format_l2_input, si->sw_if_index);
448 /* Display any IP4 addressing info */
449 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
450 1 /* honor unnumbered */,
452 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
454 vlib_cli_output (vm, " L3 %U/%d ip4 table-id %d fib-idx %d",
455 format_ip4_address, r4, ia->address_length,
457 ip4_fib_index_from_table_id (fib4->table_id));
459 vlib_cli_output (vm, " L3 %U/%d",
460 format_ip4_address, r4, ia->address_length);
465 /* Display any IP6 addressing info */
466 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
467 1 /* honor unnumbered */,
469 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
471 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
472 format_ip6_address, r6, ia->address_length,
474 ip6_fib_index_from_table_id (fib6->table_id));
476 vlib_cli_output (vm, " L3 %U/%d",
477 format_ip6_address, r6, ia->address_length);
484 vec_foreach (si, sorted_sis)
486 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
491 vec_free (sorted_sis);
496 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
497 .path = "show interface",
498 .short_help = "show interface [address|addr|features|feat|vtr] [<interface> [<interface> [..]]] [verbose]",
499 .function = show_sw_interfaces,
504 /* Root of all interface commands. */
506 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
508 .short_help = "Interface commands",
513 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
514 .path = "set interface",
515 .short_help = "Interface commands",
519 static clib_error_t *
520 clear_interface_counters (vlib_main_t * vm,
521 unformat_input_t * input, vlib_cli_command_t * cmd)
523 vnet_main_t *vnm = vnet_get_main ();
524 vnet_interface_main_t *im = &vnm->interface_main;
525 vlib_simple_counter_main_t *sm;
526 vlib_combined_counter_main_t *cm;
529 n_counters = vec_len (im->combined_sw_if_counters);
531 for (j = 0; j < n_counters; j++)
533 im = &vnm->interface_main;
534 cm = im->combined_sw_if_counters + j;
535 vlib_clear_combined_counters (cm);
538 n_counters = vec_len (im->sw_if_counters);
540 for (j = 0; j < n_counters; j++)
542 im = &vnm->interface_main;
543 sm = im->sw_if_counters + j;
544 vlib_clear_simple_counters (sm);
551 * Clear the statistics for all interfaces (statistics associated with the
552 * '<em>show interface</em>' command).
555 * Example of how to clear the statistics for all interfaces:
556 * @cliexcmd{clear interfaces}
559 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
560 .path = "clear interfaces",
561 .short_help = "clear interfaces",
562 .function = clear_interface_counters,
567 * Parse subinterface names.
569 * The following subinterface syntax is supported. The first two are for
570 * backwards compatability:
573 * - a subinterface with the name <intf-name>.<id>. The subinterface
574 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
576 * <intf-name> <min_id>-<max_id>
577 * - a set of the above subinterfaces, repeating for each id
578 * in the range <min_id> to <max_id>
580 * In the following, exact-match semantics (i.e. the number of vlan tags on the
581 * packet must match the number of tags in the configuration) are used only if
582 * the keyword exact-match is present. Non-exact match is the default.
584 * <intf-name> <id> dot1q <outer_id> [exact-match]
585 * - a subinterface with the name <intf-name>.<id>. The subinterface
586 * is a single dot1q vlan with vlan id <outer_id>.
588 * <intf-name> <id> dot1q any [exact-match]
589 * - a subinterface with the name <intf-name>.<id>. The subinterface
590 * is a single dot1q vlan with any vlan id.
592 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
593 * - a subinterface with the name <intf-name>.<id>. The subinterface
594 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
597 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
598 * - a subinterface with the name <intf-name>.<id>. The subinterface
599 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
601 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
603 * - a subinterface with the name <intf-name>.<id>. The subinterface
604 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
606 * For each of the above CLI, there is a duplicate that uses the keyword
607 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
608 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
609 * tagged packets the inner ethertype is always 0x8100. Also note that
610 * the dot1q and dot1ad naming spaces are independent, so it is legal to
611 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
613 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
614 * - a subinterface with the name <intf-name>.<id>. The subinterface
615 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
618 * <intf-name> <id> untagged
619 * - a subinterface with the name <intf-name>.<id>. The subinterface
620 * has no vlan tags. Only one can be specified per interface.
622 * <intf-name> <id> default
623 * - a subinterface with the name <intf-name>.<id>. This is associated
624 * with a packet that did not match any other configured subinterface
625 * on this interface. Only one can be specified per interface.
628 static clib_error_t *
629 parse_vlan_sub_interfaces (unformat_input_t * input,
630 vnet_sw_interface_t * template)
632 clib_error_t *error = 0;
633 u32 inner_vlan, outer_vlan;
635 if (unformat (input, "any inner-dot1q any"))
637 template->sub.eth.flags.two_tags = 1;
638 template->sub.eth.flags.outer_vlan_id_any = 1;
639 template->sub.eth.flags.inner_vlan_id_any = 1;
641 else if (unformat (input, "any"))
643 template->sub.eth.flags.one_tag = 1;
644 template->sub.eth.flags.outer_vlan_id_any = 1;
646 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
648 template->sub.eth.flags.two_tags = 1;
649 template->sub.eth.flags.inner_vlan_id_any = 1;
650 template->sub.eth.outer_vlan_id = outer_vlan;
652 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
654 template->sub.eth.flags.two_tags = 1;
655 template->sub.eth.outer_vlan_id = outer_vlan;
656 template->sub.eth.inner_vlan_id = inner_vlan;
658 else if (unformat (input, "%d", &outer_vlan))
660 template->sub.eth.flags.one_tag = 1;
661 template->sub.eth.outer_vlan_id = outer_vlan;
665 error = clib_error_return (0, "expected dot1q config, got `%U'",
666 format_unformat_error, input);
670 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
672 if (unformat (input, "exact-match"))
674 template->sub.eth.flags.exact_match = 1;
682 static clib_error_t *
683 create_sub_interfaces (vlib_main_t * vm,
684 unformat_input_t * input, vlib_cli_command_t * cmd)
686 vnet_main_t *vnm = vnet_get_main ();
687 clib_error_t *error = 0;
688 u32 hw_if_index, sw_if_index;
689 vnet_hw_interface_t *hi;
690 u32 id, id_min, id_max;
691 vnet_sw_interface_t template;
694 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
696 error = clib_error_return (0, "unknown interface `%U'",
697 format_unformat_error, input);
701 clib_memset (&template, 0, sizeof (template));
702 template.sub.eth.raw_flags = 0;
704 if (unformat (input, "%d default", &id_min))
707 template.sub.eth.flags.default_sub = 1;
709 else if (unformat (input, "%d untagged", &id_min))
712 template.sub.eth.flags.no_tags = 1;
713 template.sub.eth.flags.exact_match = 1;
715 else if (unformat (input, "%d dot1q", &id_min))
717 /* parse dot1q config */
719 error = parse_vlan_sub_interfaces (input, &template);
723 else if (unformat (input, "%d dot1ad", &id_min))
725 /* parse dot1ad config */
727 template.sub.eth.flags.dot1ad = 1;
728 error = parse_vlan_sub_interfaces (input, &template);
732 else if (unformat (input, "%d-%d", &id_min, &id_max))
734 template.sub.eth.flags.one_tag = 1;
735 template.sub.eth.flags.exact_match = 1;
739 else if (unformat (input, "%d", &id_min))
742 template.sub.eth.flags.one_tag = 1;
743 template.sub.eth.outer_vlan_id = id_min;
744 template.sub.eth.flags.exact_match = 1;
749 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
750 format_unformat_error, input);
754 hi = vnet_get_hw_interface (vnm, hw_if_index);
756 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
759 clib_error_return (0,
760 "not allowed as %v belong to a BondEthernet interface",
765 for (id = id_min; id <= id_max; id++)
768 vnet_interface_main_t *im = &vnm->interface_main;
769 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
772 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
776 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
777 hi->sw_if_index, id);
781 template.type = VNET_SW_INTERFACE_TYPE_SUB;
782 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
783 template.sup_sw_if_index = hi->sw_if_index;
784 template.sub.id = id;
786 template.sub.eth.outer_vlan_id = id;
788 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
792 kp = clib_mem_alloc (sizeof (*kp));
793 *kp = sup_and_sub_key;
795 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
796 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
797 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
798 vnet_get_main (), sw_if_index);
806 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
807 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
808 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
809 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
810 * but this is not recommended.
812 * This command has several variations:
813 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
814 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
816 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
817 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
818 * match any other subinterfaces should be sent to this subinterface.
820 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
821 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
822 * to this subinterface.
824 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
825 * subinterfaces to handle a range of VLAN IDs.
827 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
828 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
829 * VLAN ID different from the '<em>subId</em>'.
831 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
832 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
835 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
836 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
837 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
838 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
839 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
840 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
841 * entered, then the default behavior is exact-match.
843 * Use the '<em>show interface</em>' command to display all subinterfaces.
847 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
848 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
850 * The previous example is shorthand and is equivalent to:
851 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
854 * Example of how to create a subinterface number that is different from the VLAN ID:
855 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
858 * Examples of how to create q-in-q and q-in-any subinterfaces:
859 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
860 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
862 * Examples of how to create dot1ad interfaces:
863 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
864 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
867 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
868 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
869 * is non-exact match:
870 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
872 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
873 * is specified and only one VLAN is configured, but packet contains two VLANs:
874 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
877 * Example of how to created a subinterface to process untagged packets:
878 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
880 * Example of how to created a subinterface to process any packet with a VLAN ID that
881 * does not match any other subinterface:
882 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
884 * When subinterfaces are created, they are in the down state. Example of how to
885 * enable a newly created subinterface:
886 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
890 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
891 .path = "create sub-interfaces",
892 .short_help = "create sub-interfaces <interface> "
893 "{<subId> [default|untagged]} | "
894 "{<subId>-<subId>} | "
895 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
896 .function = create_sub_interfaces,
900 static clib_error_t *
901 set_state (vlib_main_t * vm,
902 unformat_input_t * input, vlib_cli_command_t * cmd)
904 vnet_main_t *vnm = vnet_get_main ();
906 u32 sw_if_index, flags;
909 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
911 error = clib_error_return (0, "unknown interface `%U'",
912 format_unformat_error, input);
916 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
918 error = clib_error_return (0, "unknown flags `%U'",
919 format_unformat_error, input);
923 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
933 * This command is used to change the admin state (up/down) of an interface.
935 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
936 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
937 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
938 * '<em>punt</em>' flag (interface is still down).
941 * Example of how to configure the admin state of an interface to '<em>up</em?':
942 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
943 * Example of how to configure the admin state of an interface to '<em>down</em?':
944 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
947 VLIB_CLI_COMMAND (set_state_command, static) = {
948 .path = "set interface state",
949 .short_help = "set interface state <interface> [up|down|punt|enable]",
950 .function = set_state,
954 static clib_error_t *
955 set_unnumbered (vlib_main_t * vm,
956 unformat_input_t * input, vlib_cli_command_t * cmd)
958 vnet_main_t *vnm = vnet_get_main ();
959 u32 unnumbered_sw_if_index = ~0;
960 u32 inherit_from_sw_if_index = ~0;
963 if (unformat (input, "%U use %U",
964 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
965 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
967 else if (unformat (input, "del %U",
968 unformat_vnet_sw_interface, vnm,
969 &unnumbered_sw_if_index))
972 return clib_error_return (0, "parse error '%U'",
973 format_unformat_error, input);
975 if (~0 == unnumbered_sw_if_index)
976 return clib_error_return (0, "Specify the unnumbered interface");
977 if (enable && ~0 == inherit_from_sw_if_index)
978 return clib_error_return (0, "When enabling unnumbered specify the"
979 " IP enabled interface that it uses");
981 vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
982 inherit_from_sw_if_index, enable);
988 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
989 .path = "set interface unnumbered",
990 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
991 .function = set_unnumbered,
997 static clib_error_t *
998 set_hw_class (vlib_main_t * vm,
999 unformat_input_t * input, vlib_cli_command_t * cmd)
1001 vnet_main_t *vnm = vnet_get_main ();
1002 vnet_interface_main_t *im = &vnm->interface_main;
1003 clib_error_t *error;
1004 u32 hw_if_index, hw_class_index;
1007 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
1009 error = clib_error_return (0, "unknown hardware interface `%U'",
1010 format_unformat_error, input);
1014 if (!unformat_user (input, unformat_hash_string,
1015 im->hw_interface_class_by_name, &hw_class_index))
1017 error = clib_error_return (0, "unknown hardware class `%U'",
1018 format_unformat_error, input);
1022 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1031 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1032 .path = "set interface hw-class",
1033 .short_help = "Set interface hardware class",
1034 .function = set_hw_class,
1038 static clib_error_t *
1039 vnet_interface_cli_init (vlib_main_t * vm)
1044 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1046 static clib_error_t *
1047 renumber_interface_command_fn (vlib_main_t * vm,
1048 unformat_input_t * input,
1049 vlib_cli_command_t * cmd)
1052 u32 new_dev_instance;
1053 vnet_main_t *vnm = vnet_get_main ();
1056 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
1057 return clib_error_return (0, "unknown hardware interface `%U'",
1058 format_unformat_error, input);
1060 if (!unformat (input, "%d", &new_dev_instance))
1061 return clib_error_return (0, "new dev instance missing");
1063 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1071 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
1081 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1082 .path = "renumber interface",
1083 .short_help = "renumber interface <interface> <new-dev-instance>",
1084 .function = renumber_interface_command_fn,
1088 static clib_error_t *
1089 promiscuous_cmd (vlib_main_t * vm,
1090 unformat_input_t * input, vlib_cli_command_t * cmd)
1092 vnet_main_t *vnm = vnet_get_main ();
1094 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
1095 ethernet_main_t *em = ðernet_main;
1096 ethernet_interface_t *eif;
1098 if (unformat (input, "on %U",
1099 unformat_vnet_hw_interface, vnm, &hw_if_index))
1101 else if (unformat (input, "off %U",
1102 unformat_ethernet_interface, vnm, &hw_if_index))
1105 return clib_error_return (0, "unknown input `%U'",
1106 format_unformat_error, input);
1108 eif = ethernet_get_interface (em, hw_if_index);
1110 return clib_error_return (0, "not supported");
1112 ethernet_set_flags (vnm, hw_if_index, flags);
1117 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1118 .path = "set interface promiscuous",
1119 .short_help = "set interface promiscuous [on|off] <interface>",
1120 .function = promiscuous_cmd,
1124 static clib_error_t *
1125 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1127 vnet_main_t *vnm = vnet_get_main ();
1128 u32 hw_if_index, sw_if_index, mtu;
1129 ethernet_main_t *em = ðernet_main;
1130 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
1132 if (unformat (input, "%d %U", &mtu,
1133 unformat_vnet_hw_interface, vnm, &hw_if_index))
1136 * Change physical MTU on interface. Only supported for Ethernet
1139 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1140 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1143 return clib_error_return (0, "not supported");
1145 if (mtu < hi->min_supported_packet_bytes)
1146 return clib_error_return (0, "Invalid mtu (%d): "
1147 "must be >= min pkt bytes (%d)", mtu,
1148 hi->min_supported_packet_bytes);
1150 if (mtu > hi->max_supported_packet_bytes)
1151 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1152 hi->max_supported_packet_bytes);
1154 vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
1157 else if (unformat (input, "packet %d %U", &mtu,
1158 unformat_vnet_sw_interface, vnm, &sw_if_index))
1159 /* Set default packet MTU (including L3 header */
1160 mtus[VNET_MTU_L3] = mtu;
1161 else if (unformat (input, "ip4 %d %U", &mtu,
1162 unformat_vnet_sw_interface, vnm, &sw_if_index))
1163 mtus[VNET_MTU_IP4] = mtu;
1164 else if (unformat (input, "ip6 %d %U", &mtu,
1165 unformat_vnet_sw_interface, vnm, &sw_if_index))
1166 mtus[VNET_MTU_IP6] = mtu;
1167 else if (unformat (input, "mpls %d %U", &mtu,
1168 unformat_vnet_sw_interface, vnm, &sw_if_index))
1169 mtus[VNET_MTU_MPLS] = mtu;
1171 return clib_error_return (0, "unknown input `%U'",
1172 format_unformat_error, input);
1174 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1181 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1182 .path = "set interface mtu",
1183 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
1184 .function = mtu_cmd,
1188 static clib_error_t *
1189 show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input,
1190 vlib_cli_command_t * cmd)
1192 vnet_main_t *vnm = vnet_get_main ();
1193 vnet_interface_main_t *im = &vnm->interface_main;
1194 ethernet_main_t *em = ðernet_main;
1195 u32 sw_if_index = ~0;
1196 vnet_sw_interface_t *si, *sorted_sis = 0;
1198 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1200 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1201 vec_add1 (sorted_sis, si[0]);
1204 /* if an interface name was not passed, get all interfaces */
1205 if (vec_len (sorted_sis) == 0)
1208 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
1209 _vec_len (sorted_sis) = 0;
1211 pool_foreach (si, im->sw_interfaces)
1213 int visible = vnet_swif_is_api_visible (si);
1215 vec_add1 (sorted_sis, si[0]);
1219 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
1222 vec_foreach (si, sorted_sis)
1224 vnet_sw_interface_t *sup_si;
1225 ethernet_interface_t *ei;
1227 sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
1228 ei = ethernet_get_interface (em, sup_si->hw_if_index);
1230 vlib_cli_output (vm, "%U (%s):",
1231 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
1232 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
1235 if (ei && ei->secondary_addrs)
1237 ethernet_interface_address_t *sec_addr;
1239 vec_foreach (sec_addr, ei->secondary_addrs)
1241 vlib_cli_output (vm, " %U", format_mac_address_t, &sec_addr->mac);
1246 vec_free (sorted_sis);
1251 * This command is used to display interface secondary mac addresses.
1254 * Example of how to display interface secondary mac addresses:
1255 * @cliexstart{show interface secondary-mac-address}
1259 VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = {
1260 .path = "show interface secondary-mac-address",
1261 .short_help = "show interface secondary-mac-address [<interface>]",
1262 .function = show_interface_sec_mac_addr_fn,
1266 static clib_error_t *
1267 interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input,
1268 vlib_cli_command_t * cmd)
1270 vnet_main_t *vnm = vnet_get_main ();
1271 vnet_sw_interface_t *si = NULL;
1272 clib_error_t *error = 0;
1273 u32 sw_if_index = ~0;
1277 is_add = is_del = 0;
1279 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1281 error = clib_error_return (0, "unknown interface `%U'",
1282 format_unformat_error, input);
1285 if (!unformat_user (input, unformat_ethernet_address, mac))
1287 error = clib_error_return (0, "expected mac address `%U'",
1288 format_unformat_error, input);
1292 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1294 if (unformat (input, "add"))
1296 else if (unformat (input, "del"))
1302 if (is_add == is_del)
1304 error = clib_error_return (0, "must choose one of add or del");
1308 si = vnet_get_sw_interface (vnm, sw_if_index);
1310 vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add);
1317 * The '<em>set interface secondary-mac-address </em>' command allows adding
1318 * or deleting extra MAC addresses on a given interface without changing the
1319 * default MAC address. This could allow packets sent to these MAC addresses
1320 * to be received without setting the interface to promiscuous mode.
1321 * Not all interfaces support this operation. The ones that do are mostly
1322 * hardware NICs, though virtio does also.
1326 * Example of how to add a secondary MAC Address on an interface:
1327 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add}
1328 * Example of how to delete a secondary MAC address from an interface:
1329 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del}
1333 VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = {
1334 .path = "set interface secondary-mac-address",
1335 .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]",
1336 .function = interface_add_del_mac_address,
1340 static clib_error_t *
1341 set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1342 vlib_cli_command_t * cmd)
1344 vnet_main_t *vnm = vnet_get_main ();
1345 vnet_sw_interface_t *si = NULL;
1346 clib_error_t *error = 0;
1347 u32 sw_if_index = ~0;
1350 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1352 error = clib_error_return (0, "unknown interface `%U'",
1353 format_unformat_error, input);
1356 if (!unformat_user (input, unformat_ethernet_address, mac))
1358 error = clib_error_return (0, "expected mac address `%U'",
1359 format_unformat_error, input);
1362 si = vnet_get_sw_interface (vnm, sw_if_index);
1363 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
1369 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1370 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1371 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1375 * Example of how to change MAC Address of interface:
1376 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1377 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1378 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1379 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1383 VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1384 .path = "set interface mac address",
1385 .short_help = "set interface mac address <interface> <mac-address>",
1386 .function = set_interface_mac_address,
1390 static clib_error_t *
1391 set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1393 vnet_main_t *vnm = vnet_get_main ();
1394 u32 sw_if_index = ~0;
1397 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1398 vnm, &sw_if_index, &tag))
1399 return clib_error_return (0, "unknown input `%U'",
1400 format_unformat_error, input);
1402 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1408 VLIB_CLI_COMMAND (set_tag_command, static) = {
1409 .path = "set interface tag",
1410 .short_help = "set interface tag <interface> <tag>",
1411 .function = set_tag,
1415 static clib_error_t *
1416 clear_tag (vlib_main_t * vm, unformat_input_t * input,
1417 vlib_cli_command_t * cmd)
1419 vnet_main_t *vnm = vnet_get_main ();
1420 u32 sw_if_index = ~0;
1422 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1423 return clib_error_return (0, "unknown input `%U'",
1424 format_unformat_error, input);
1426 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1432 VLIB_CLI_COMMAND (clear_tag_command, static) = {
1433 .path = "clear interface tag",
1434 .short_help = "clear interface tag <interface>",
1435 .function = clear_tag,
1439 static clib_error_t *
1440 set_ip_directed_broadcast (vlib_main_t * vm,
1441 unformat_input_t * input, vlib_cli_command_t * cmd)
1443 vnet_main_t *vnm = vnet_get_main ();
1444 u32 sw_if_index = ~0;
1447 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1448 else if (unformat (input, "enable"))
1450 else if (unformat (input, "disable"))
1453 return clib_error_return (0, "unknown input: `%U'",
1454 format_unformat_error, input);
1456 if (~0 == sw_if_index)
1457 return clib_error_return (0, "specify an interface: `%U'",
1458 format_unformat_error, input);
1460 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1466 * This command is used to enable/disable IP directed broadcast
1467 * If directed broadcast is enabled a packet sent to the interface's
1468 * subnet broadcast address will be sent L2 broadcast on the interface,
1469 * otherwise it is dropped.
1472 VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1473 .path = "set interface ip directed-broadcast",
1474 .short_help = "set interface enable <interface> <enable|disable>",
1475 .function = set_ip_directed_broadcast,
1479 static clib_error_t *
1480 set_hw_interface_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1481 u32 queue_id, vnet_hw_if_rx_mode mode)
1483 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1484 vnet_device_class_t *dev_class =
1485 vnet_get_device_class (vnm, hw->dev_class_index);
1486 clib_error_t *error;
1487 vnet_hw_if_rx_mode old_mode;
1490 if (mode == VNET_HW_IF_RX_MODE_DEFAULT)
1491 mode = hw->default_rx_mode;
1493 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &old_mode);
1497 if (old_mode == mode)
1498 return 0; /* same rx-mode, no change */
1500 case VNET_API_ERROR_INVALID_INTERFACE:
1501 return clib_error_return (0, "invalid interface");
1502 case VNET_API_ERROR_INVALID_QUEUE:
1503 return clib_error_return (0, "invalid queue");
1505 return clib_error_return (0, "unknown error");
1508 if (dev_class->rx_mode_change_function)
1510 error = dev_class->rx_mode_change_function (vnm, hw_if_index, queue_id,
1516 rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1521 case VNET_API_ERROR_UNSUPPORTED:
1522 return clib_error_return (0, "unsupported");
1523 case VNET_API_ERROR_INVALID_INTERFACE:
1524 return clib_error_return (0, "invalid interface");
1525 case VNET_API_ERROR_INVALID_QUEUE:
1526 return clib_error_return (0, "invalid queue");
1528 return clib_error_return (0, "unknown error");
1535 set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1536 u8 queue_id_valid, u32 queue_id,
1537 vnet_hw_if_rx_mode mode)
1539 clib_error_t *error = 0;
1540 vnet_hw_interface_t *hw;
1541 u32 *queue_indices = 0;
1544 hw = vnet_get_hw_interface (vnm, hw_if_index);
1546 /* to be deprecated */
1547 if (vec_len (hw->rx_queue_indices) == 0)
1549 if (queue_id_valid == 0)
1551 for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1553 error = set_hw_interface_rx_mode (vnm, hw_if_index, i, mode);
1557 hw->default_rx_mode = mode;
1560 error = set_hw_interface_rx_mode (vnm, hw_if_index, queue_id, mode);
1569 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1570 if (queue_index == ~0)
1571 return clib_error_return (0, "unknown queue %u on interface %s",
1572 queue_id, hw->name);
1573 vec_add1 (queue_indices, queue_index);
1576 queue_indices = hw->rx_queue_indices;
1578 for (int i = 0; i < vec_len (queue_indices); i++)
1580 int rv = vnet_hw_if_set_rx_queue_mode (vnm, queue_indices[i], mode);
1586 if (queue_indices != hw->rx_queue_indices)
1587 vec_free (queue_indices);
1588 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1592 static clib_error_t *
1593 set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1594 vlib_cli_command_t * cmd)
1596 clib_error_t *error = 0;
1597 unformat_input_t _line_input, *line_input = &_line_input;
1598 vnet_main_t *vnm = vnet_get_main ();
1599 u32 hw_if_index = (u32) ~ 0;
1600 u32 queue_id = (u32) ~ 0;
1601 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
1602 u8 queue_id_valid = 0;
1604 if (!unformat_user (input, unformat_line_input, line_input))
1607 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1610 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1612 else if (unformat (line_input, "queue %d", &queue_id))
1614 else if (unformat (line_input, "polling"))
1615 mode = VNET_HW_IF_RX_MODE_POLLING;
1616 else if (unformat (line_input, "interrupt"))
1617 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
1618 else if (unformat (line_input, "adaptive"))
1619 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
1622 error = clib_error_return (0, "parse error: '%U'",
1623 format_unformat_error, line_input);
1624 unformat_free (line_input);
1629 unformat_free (line_input);
1631 if (hw_if_index == (u32) ~ 0)
1632 return clib_error_return (0, "please specify valid interface name");
1634 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
1635 return clib_error_return (0, "please specify valid rx-mode");
1637 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1644 * This command is used to assign the RX packet processing mode (polling,
1645 * interrupt, adaptive) of the a given interface, and optionally a
1646 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1647 * is applied to all queues of the interface. Not all interfaces support
1648 * all modes. To display the current rx-mode use the command
1649 * '<em>show interface rx-placement</em>'.
1652 * Example of how to assign rx-mode to all queues on an interface:
1653 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1654 * Example of how to assign rx-mode to one queue of an interface:
1655 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1656 * Example of how to display the rx-mode of all interfaces:
1657 * @cliexstart{show interface rx-placement}
1658 * Thread 1 (vpp_wk_0):
1660 * GigabitEthernet7/0/0 queue 0 (polling)
1661 * node vhost-user-input:
1662 * VirtualEthernet0/0/12 queue 0 (interrupt)
1663 * VirtualEthernet0/0/12 queue 2 (polling)
1664 * VirtualEthernet0/0/13 queue 0 (polling)
1665 * VirtualEthernet0/0/13 queue 2 (polling)
1666 * Thread 2 (vpp_wk_1):
1668 * GigabitEthernet7/0/1 queue 0 (polling)
1669 * node vhost-user-input:
1670 * VirtualEthernet0/0/12 queue 1 (polling)
1671 * VirtualEthernet0/0/12 queue 3 (polling)
1672 * VirtualEthernet0/0/13 queue 1 (polling)
1673 * VirtualEthernet0/0/13 queue 3 (polling)
1677 VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
1678 .path = "set interface rx-mode",
1679 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1680 .function = set_interface_rx_mode,
1684 static clib_error_t *
1685 show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1686 vlib_cli_command_t * cmd)
1689 vnet_main_t *vnm = vnet_get_main ();
1690 vnet_device_input_runtime_t *rt;
1691 vnet_device_and_queue_t *dq;
1692 vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
1697 foreach_vlib_main (({
1698 clib_bitmap_foreach (si, pn->sibling_bitmap)
1700 rt = vlib_node_get_runtime_data (this_vlib_main, si);
1702 if (vec_len (rt->devices_and_queues))
1703 s = format (s, " node %U:\n", format_vlib_node_name, vm, si);
1705 vec_foreach (dq, rt->devices_and_queues)
1707 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm,
1709 s = format (s, " %U queue %u (%U)\n",
1710 format_vnet_sw_if_index_name, vnm, hi->sw_if_index,
1712 format_vnet_hw_if_rx_mode, dq->mode);
1715 if (vec_len (s) > 0)
1717 vlib_cli_output(vm, "Thread %u (%s):\n%v", index,
1718 vlib_worker_threads[index].name, s);
1719 vec_reset_length (s);
1730 * This command is used to display the interface and queue worker
1734 * Example of how to display the interface placement:
1735 * @cliexstart{show interface rx-placement}
1736 * Thread 1 (vpp_wk_0):
1738 * GigabitEthernet7/0/0 queue 0 (polling)
1739 * node vhost-user-input:
1740 * VirtualEthernet0/0/12 queue 0 (polling)
1741 * VirtualEthernet0/0/12 queue 2 (polling)
1742 * VirtualEthernet0/0/13 queue 0 (polling)
1743 * VirtualEthernet0/0/13 queue 2 (polling)
1744 * Thread 2 (vpp_wk_1):
1746 * GigabitEthernet7/0/1 queue 0 (polling)
1747 * node vhost-user-input:
1748 * VirtualEthernet0/0/12 queue 1 (polling)
1749 * VirtualEthernet0/0/12 queue 3 (polling)
1750 * VirtualEthernet0/0/13 queue 1 (polling)
1751 * VirtualEthernet0/0/13 queue 3 (polling)
1755 VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1756 .path = "show interface rx-placement",
1757 .short_help = "show interface rx-placement",
1758 .function = show_interface_rx_placement_fn,
1763 set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1764 u32 thread_index, u8 is_main)
1766 vnet_main_t *vnm = vnet_get_main ();
1767 vnet_device_main_t *vdm = &vnet_device_main;
1768 vnet_hw_interface_t *hw;
1775 thread_index += vdm->first_worker_thread_index;
1777 if (thread_index > vdm->last_worker_thread_index)
1778 return clib_error_return (0,
1779 "please specify valid worker thread or main");
1781 hw = vnet_get_hw_interface (vnm, hw_if_index);
1783 /* to be deprecated */
1784 if (vec_len (hw->rx_queue_indices) == 0)
1786 clib_error_t *error = 0;
1787 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
1788 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode);
1791 return clib_error_return (0, "not found");
1793 rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id);
1796 return clib_error_return (0, "not found");
1798 vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id,
1800 vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1806 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1807 if (queue_index == ~0)
1808 return clib_error_return (0, "unknown queue %u on interface %s", queue_id,
1810 vnet_hw_if_set_rx_queue_thread_index (vnm, queue_index, thread_index);
1811 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1815 static clib_error_t *
1816 set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input,
1817 vlib_cli_command_t * cmd)
1819 clib_error_t *error = 0;
1820 unformat_input_t _line_input, *line_input = &_line_input;
1821 vnet_main_t *vnm = vnet_get_main ();
1822 u32 hw_if_index = (u32) ~ 0;
1823 u32 queue_id = (u32) 0;
1824 u32 thread_index = (u32) ~ 0;
1827 if (!unformat_user (input, unformat_line_input, line_input))
1830 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1833 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1835 else if (unformat (line_input, "queue %d", &queue_id))
1837 else if (unformat (line_input, "main", &thread_index))
1839 else if (unformat (line_input, "worker %d", &thread_index))
1843 error = clib_error_return (0, "parse error: '%U'",
1844 format_unformat_error, line_input);
1845 unformat_free (line_input);
1850 unformat_free (line_input);
1852 if (hw_if_index == (u32) ~ 0)
1853 return clib_error_return (0, "please specify valid interface name");
1855 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1862 * This command is used to assign a given interface, and optionally a
1863 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1864 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1865 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
1868 * Example of how to display the interface placement:
1869 * @cliexstart{show interface rx-placement}
1870 * Thread 1 (vpp_wk_0):
1872 * GigabitEthernet7/0/0 queue 0 (polling)
1873 * node vhost-user-input:
1874 * VirtualEthernet0/0/12 queue 0 (polling)
1875 * VirtualEthernet0/0/12 queue 2 (polling)
1876 * VirtualEthernet0/0/13 queue 0 (polling)
1877 * VirtualEthernet0/0/13 queue 2 (polling)
1878 * Thread 2 (vpp_wk_1):
1880 * GigabitEthernet7/0/1 queue 0 (polling)
1881 * node vhost-user-input:
1882 * VirtualEthernet0/0/12 queue 1 (polling)
1883 * VirtualEthernet0/0/12 queue 3 (polling)
1884 * VirtualEthernet0/0/13 queue 1 (polling)
1885 * VirtualEthernet0/0/13 queue 3 (polling)
1887 * Example of how to assign a interface and queue to a worker thread:
1888 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1889 * Example of how to display the interface placement:
1890 * @cliexstart{show interface rx-placement}
1891 * Thread 1 (vpp_wk_0):
1893 * GigabitEthernet7/0/0 queue 0 (polling)
1894 * node vhost-user-input:
1895 * VirtualEthernet0/0/12 queue 0 (polling)
1896 * VirtualEthernet0/0/12 queue 1 (polling)
1897 * VirtualEthernet0/0/12 queue 2 (polling)
1898 * VirtualEthernet0/0/13 queue 0 (polling)
1899 * VirtualEthernet0/0/13 queue 2 (polling)
1900 * Thread 2 (vpp_wk_1):
1902 * GigabitEthernet7/0/1 queue 0 (polling)
1903 * node vhost-user-input:
1904 * VirtualEthernet0/0/12 queue 3 (polling)
1905 * VirtualEthernet0/0/13 queue 1 (polling)
1906 * VirtualEthernet0/0/13 queue 3 (polling)
1910 VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1911 .path = "set interface rx-placement",
1912 .short_help = "set interface rx-placement <interface> [queue <n>] "
1913 "[worker <n> | main]",
1914 .function = set_interface_rx_placement,
1920 set_interface_rss_queues (vlib_main_t * vm, u32 hw_if_index,
1921 clib_bitmap_t * bitmap)
1923 vnet_main_t *vnm = vnet_get_main ();
1924 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1926 return vnet_hw_interface_set_rss_queues (vnm, hi, bitmap);
1929 static clib_error_t *
1930 set_interface_rss_queues_fn (vlib_main_t * vm,
1931 unformat_input_t * input,
1932 vlib_cli_command_t * cmd)
1934 clib_error_t *error = 0;
1935 unformat_input_t _line_input, *line_input = &_line_input;
1936 vnet_main_t *vnm = vnet_get_main ();
1937 u32 hw_if_index = (u32) ~ 0;
1938 clib_bitmap_t *bitmap = NULL;
1940 if (!unformat_user (input, unformat_line_input, line_input))
1943 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1946 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1949 if (unformat (line_input, "list %U", unformat_bitmap_list, &bitmap))
1953 error = clib_error_return (0, "parse error: '%U'",
1954 format_unformat_error, line_input);
1955 unformat_free (line_input);
1960 unformat_free (line_input);
1962 if (hw_if_index == (u32) ~ 0)
1964 error = clib_error_return (0, "please specify valid interface name");
1970 error = clib_error_return (0, "please specify the valid rss queues");
1974 error = set_interface_rss_queues (vm, hw_if_index, bitmap);
1978 clib_bitmap_free (bitmap);
1984 * This command is used to set the rss queues of a given interface
1985 * Not all the interfaces support this operation.
1986 * To display the current rss queues, use the command
1987 * '<em>show hardware-interfaces</em>'.
1990 * Example of how to set the rss queues to 0,2-5,7 of an interface:
1991 * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7}
1995 VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = {
1996 .path = "set interface rss queues",
1997 .short_help = "set interface rss queues <interface> <list <queue-list>>",
1998 .function = set_interface_rss_queues_fn,
2003 format_vnet_pcap (u8 * s, va_list * args)
2005 vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *);
2006 int type = va_arg (*args, int);
2011 if (pp->pcap_rx_enable)
2013 s = format (s, "rx");
2016 if (pp->pcap_tx_enable)
2019 s = format (s, " and ");
2020 s = format (s, "tx");
2023 if (pp->pcap_drop_enable)
2026 s = format (s, " and ");
2027 s = format (s, "drop");
2032 s = format (s, "unknown type %d!", type);
2038 vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
2040 vlib_main_t *vm = vlib_get_main ();
2041 vnet_pcap_t *pp = &vm->pcap;
2042 pcap_main_t *pm = &pp->pcap_main;
2043 vnet_classify_main_t *cm = &vnet_classify_main;
2047 if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable)
2050 (vm, "pcap %U dispatch capture enabled: %d of %d pkts...",
2051 format_vnet_pcap, pp, 0 /* print type */ ,
2052 pm->n_packets_captured, pm->n_packets_to_capture);
2053 vlib_cli_output (vm, "capture to file %s", pm->file_name);
2056 vlib_cli_output (vm, "pcap dispatch capture disabled");
2061 /* Consistency checks */
2063 /* Enable w/ capture already enabled not allowed */
2064 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2065 && (a->rx_enable + a->tx_enable + a->drop_enable))
2066 return VNET_API_ERROR_INVALID_VALUE;
2068 /* Disable capture with capture already disabled, not interesting */
2069 if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) == 0)
2070 && ((a->rx_enable + a->tx_enable + a->drop_enable == 0)))
2071 return VNET_API_ERROR_VALUE_EXIST;
2073 /* Change number of packets to capture while capturing */
2074 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2075 && (a->rx_enable + a->tx_enable + a->drop_enable)
2076 && (pm->n_packets_to_capture != a->packets_to_capture))
2077 return VNET_API_ERROR_INVALID_VALUE_2;
2079 /* Classify filter specified, but no classify filter configured */
2080 if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter &&
2081 cm->classify_table_index_by_sw_if_index[0] == ~0)
2082 return VNET_API_ERROR_NO_SUCH_LABEL;
2084 if (a->rx_enable + a->tx_enable + a->drop_enable)
2086 void *save_pcap_data;
2088 /* Sanity check max bytes per pkt */
2089 if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000)
2090 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
2092 /* Clean up from previous run, if any */
2093 vec_reset_length (pm->pcap_data);
2095 /* Throw away the data buffer? */
2097 vec_free (pm->pcap_data);
2099 save_pcap_data = pm->pcap_data;
2101 memset (pm, 0, sizeof (*pm));
2103 pm->pcap_data = save_pcap_data;
2105 vec_validate_aligned (vnet_trace_placeholder, 2048,
2106 CLIB_CACHE_LINE_BYTES);
2108 clib_spinlock_init (&(pm->lock));
2110 if (a->filename == 0)
2115 stem = format (stem, "rx");
2117 stem = format (stem, "tx");
2119 stem = format (stem, "drop");
2120 a->filename = format (0, "/tmp/%v.pcap%c", stem, 0);
2124 pm->file_name = (char *) a->filename;
2125 pm->n_packets_captured = 0;
2126 pm->packet_type = PCAP_PACKET_TYPE_ethernet;
2127 /* Preallocate the data vector? */
2128 if (a->preallocate_data)
2131 (pm->pcap_data, a->packets_to_capture
2132 * ((sizeof (pcap_packet_header_t) + a->max_bytes_per_pkt)));
2133 vec_reset_length (pm->pcap_data);
2135 pm->n_packets_to_capture = a->packets_to_capture;
2136 pp->pcap_sw_if_index = a->sw_if_index;
2138 pp->filter_classify_table_index =
2139 cm->classify_table_index_by_sw_if_index[0];
2141 pp->filter_classify_table_index = ~0;
2142 pp->pcap_rx_enable = a->rx_enable;
2143 pp->pcap_tx_enable = a->tx_enable;
2144 pp->pcap_drop_enable = a->drop_enable;
2145 pp->max_bytes_per_pkt = a->max_bytes_per_pkt;
2149 pp->pcap_rx_enable = 0;
2150 pp->pcap_tx_enable = 0;
2151 pp->pcap_drop_enable = 0;
2152 pp->filter_classify_table_index = ~0;
2153 if (pm->n_packets_captured)
2155 clib_error_t *error;
2156 pm->n_packets_to_capture = pm->n_packets_captured;
2157 vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
2158 pm->n_packets_captured, pm->file_name);
2159 error = pcap_write (pm);
2160 if (pm->flags & PCAP_MAIN_INIT_DONE)
2162 /* Report I/O errors... */
2165 clib_error_report (error);
2166 return VNET_API_ERROR_SYSCALL_ERROR_1;
2168 vec_free (pm->file_name);
2170 vec_free (pm->pcap_data);
2174 return VNET_API_ERROR_NO_SUCH_ENTRY;
2180 static clib_error_t *
2181 pcap_trace_command_fn (vlib_main_t * vm,
2182 unformat_input_t * input, vlib_cli_command_t * cmd)
2184 unformat_input_t _line_input, *line_input = &_line_input;
2185 vnet_pcap_dispatch_trace_args_t _a, *a = &_a;
2186 vnet_main_t *vnm = vnet_get_main ();
2189 u32 max_bytes_per_pkt = 512;
2193 int preallocate_data = 0;
2194 int drop_enable = 0;
2198 u32 sw_if_index = 0; /* default: any interface */
2200 /* Get a line of input. */
2201 if (!unformat_user (input, unformat_line_input, line_input))
2204 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2206 if (unformat (line_input, "rx"))
2208 else if (unformat (line_input, "tx"))
2210 else if (unformat (line_input, "drop"))
2212 else if (unformat (line_input, "off"))
2213 rx_enable = tx_enable = drop_enable = 0;
2214 else if (unformat (line_input, "max-bytes-per-pkt %u",
2215 &max_bytes_per_pkt))
2217 else if (unformat (line_input, "max %d", &max))
2219 else if (unformat (line_input, "packets-to-capture %d", &max))
2221 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
2224 else if (unformat (line_input, "status %=", &status, 1))
2226 else if (unformat (line_input, "intfc %U",
2227 unformat_vnet_sw_interface, vnm, &sw_if_index))
2229 else if (unformat (line_input, "interface %U",
2230 unformat_vnet_sw_interface, vnm, &sw_if_index))
2232 else if (unformat (line_input, "preallocate-data %=",
2233 &preallocate_data, 1))
2235 else if (unformat (line_input, "free-data %=", &free_data, 1))
2237 else if (unformat (line_input, "intfc any")
2238 || unformat (line_input, "interface any"))
2240 else if (unformat (line_input, "filter"))
2244 return clib_error_return (0, "unknown input `%U'",
2245 format_unformat_error, line_input);
2249 unformat_free (line_input);
2251 /* no need for memset (a, 0, sizeof (*a)), set all fields here. */
2252 a->filename = filename;
2253 a->rx_enable = rx_enable;
2254 a->tx_enable = tx_enable;
2255 a->preallocate_data = preallocate_data;
2256 a->free_data = free_data;
2257 a->drop_enable = drop_enable;
2259 a->packets_to_capture = max;
2260 a->sw_if_index = sw_if_index;
2262 a->max_bytes_per_pkt = max_bytes_per_pkt;
2264 rv = vnet_pcap_dispatch_trace_configure (a);
2271 case VNET_API_ERROR_INVALID_VALUE:
2272 return clib_error_return (0, "dispatch trace already enabled...");
2274 case VNET_API_ERROR_VALUE_EXIST:
2275 return clib_error_return (0, "dispatch trace already disabled...");
2277 case VNET_API_ERROR_INVALID_VALUE_2:
2278 return clib_error_return
2279 (0, "can't change number of records to capture while tracing...");
2281 case VNET_API_ERROR_SYSCALL_ERROR_1:
2282 return clib_error_return (0, "I/O writing trace capture...");
2284 case VNET_API_ERROR_NO_SUCH_ENTRY:
2285 return clib_error_return (0, "No packets captured...");
2287 case VNET_API_ERROR_INVALID_MEMORY_SIZE:
2288 return clib_error_return (0,
2289 "Max bytes per pkt must be > 32, < 9000...");
2291 case VNET_API_ERROR_NO_SUCH_LABEL:
2292 return clib_error_return
2293 (0, "No classify filter configured, see 'classify filter...'");
2296 vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
2303 * This command is used to start or stop a packet capture, or show
2304 * the status of packet capture.
2306 * This command has the following optional parameters:
2309 * - <b>rx</b> - Capture received packets
2311 * - <b>tx</b> - Capture transmitted packets
2313 * - <b>drop</b> - Capture dropped packets
2315 * - <b>off</b> - Stop capturing packets, write results to the specified file
2317 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
2318 * of packets have been received, buffer is flushed to file. Once another
2319 * '<em>nn</em>' number of packets have been received, buffer is flushed
2320 * to file, overwriting previous write. If not entered, value defaults
2321 * to 100. Can only be updated if packet capture is off.
2323 * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture
2324 * for each packet. Must be >= 32, <= 9000.
2326 * - <b>preallocate-data</b> - Preallocate the data buffer, to avoid
2327 * vector expansion delays during pcap capture
2329 * - <b>free-data</b> - Free the data buffer. Ordinarily it's a feature
2330 * to retain the data buffer so this option is seldom used.
2332 * - <b>intfc <interface-name>|any</b> - Used to specify a given interface,
2333 * or use '<em>any</em>' to run packet capture on all interfaces.
2334 * '<em>any</em>' is the default if not provided. Settings from a previous
2335 * packet capture are preserved, so '<em>any</em>' can be used to reset
2336 * the interface setting.
2338 * - <b>filter</b> - Use the pcap rx / tx / drop trace filter, which
2339 * must be configured. Use <b>classify filter pcap...</b> to configure the
2340 * filter. The filter will only be executed if the per-interface or
2341 * any-interface tests fail.
2343 * - <b>file <name></b> - Used to specify the output filename. The file will
2344 * be placed in the '<em>/tmp</em>' directory, so only the filename is
2345 * supported. Directory should not be entered. If file already exists, file
2346 * will be overwritten. If no filename is provided, the file will be
2347 * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc.
2348 * Can only be updated if packet capture is off.
2350 * - <b>status</b> - Displays the current status and configured attributes
2351 * associated with a packet capture. If packet capture is in progress,
2352 * '<em>status</em>' also will return the number of packets currently in
2353 * the local buffer. All additional attributes entered on command line
2354 * with '<em>status</em>' will be ignored and not applied.
2357 * Example of how to display the status of a tx packet capture when off:
2358 * @cliexstart{pcap trace status}
2359 * max is 100, for any interface to file /tmp/vpe.pcap
2360 * pcap tx capture is off...
2362 * Example of how to start a tx packet capture:
2363 * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file vppTest.pcap}
2365 * Example of how to display the status of a tx packet capture in progress:
2366 * @cliexstart{pcap trace status}
2367 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
2368 * pcap tx capture is on: 20 of 35 pkts...
2370 * Example of how to stop a tx packet capture:
2371 * @cliexstart{pcap trace off}
2372 * captured 21 pkts...
2373 * saved to /tmp/vppTest.pcap...
2378 VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
2379 .path = "pcap trace",
2381 "pcap trace [rx] [tx] [drop] [off] [max <nn>] [intfc <interface>|any]\n"
2382 " [file <name>] [status] [max-bytes-per-pkt <nnnn>][filter]\n"
2383 " [preallocate-data][free-data]",
2384 .function = pcap_trace_command_fn,
2389 * fd.io coding-style-patch-verification: ON
2392 * eval: (c-set-style "gnu")