2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
16 * interface_cli.c: interface CLI
18 * Copyright (c) 2008 Eliot Dresselhaus
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
42 * @brief Interface CLI.
44 * Source code for several CLI interface commands.
48 #include <vnet/vnet.h>
49 #include <vnet/ip/ip.h>
50 #include <vppinfra/bitmap.h>
51 #include <vnet/fib/ip4_fib.h>
52 #include <vnet/fib/ip6_fib.h>
53 #include <vnet/l2/l2_output.h>
54 #include <vnet/l2/l2_input.h>
57 compare_interface_names (void *a1, void *a2)
62 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
66 show_or_clear_hw_interfaces (vlib_main_t * vm,
67 unformat_input_t * input,
68 vlib_cli_command_t * cmd)
70 clib_error_t *error = 0;
71 vnet_main_t *vnm = vnet_get_main ();
72 vnet_interface_main_t *im = &vnm->interface_main;
73 vnet_hw_interface_t *hi;
74 u32 hw_if_index, *hw_if_indices = 0;
75 int i, verbose = -1, is_show, show_bond = 0;
77 is_show = strstr (cmd->path, "show") != 0;
78 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
80 /* See if user wants to show a specific interface. */
82 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
83 vec_add1 (hw_if_indices, hw_if_index);
85 /* See if user wants to show an interface with a specific hw_if_index. */
86 else if (unformat (input, "%u", &hw_if_index))
87 vec_add1 (hw_if_indices, hw_if_index);
89 else if (unformat (input, "verbose"))
90 verbose = 1; /* this is also the default */
92 else if (unformat (input, "detail"))
95 else if (unformat (input, "brief"))
98 else if (unformat (input, "bond"))
102 verbose = 0; /* default to brief for link bonding */
107 error = clib_error_return (0, "unknown input `%U'",
108 format_unformat_error, input);
113 /* Gather interfaces. */
114 if (vec_len (hw_if_indices) == 0)
115 pool_foreach (hi, im->hw_interfaces,
116 vec_add1 (hw_if_indices, hi - im->hw_interfaces));
119 verbose = 1; /* default to verbose (except bond) */
124 vec_sort_with_function (hw_if_indices, compare_interface_names);
126 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
127 for (i = 0; i < vec_len (hw_if_indices); i++)
129 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
130 if (show_bond == 0) /* show all interfaces */
131 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
133 else if ((hi->bond_info) &&
134 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
135 { /* show only bonded interface and all its slave interfaces */
137 vnet_hw_interface_t *shi;
138 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
142 clib_bitmap_foreach (hw_idx, hi->bond_info,
144 shi = vnet_get_hw_interface(vnm, hw_idx);
145 vlib_cli_output (vm, "%U\n",
146 format_vnet_hw_interface, vnm, shi, verbose);
154 for (i = 0; i < vec_len (hw_if_indices); i++)
156 vnet_device_class_t *dc;
158 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
159 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
161 if (dc->clear_counters)
162 dc->clear_counters (hi->dev_instance);
167 vec_free (hw_if_indices);
172 * Display more detailed information about all or a list of given interfaces.
173 * The verboseness of the output can be controlled by the following optional
175 * - brief: Only show name, index and state (default for bonded interfaces).
176 * - verbose: Also display additional attributes (default for all other interfaces).
177 * - detail: Also display all remaining attributes and extended statistics.
179 * To limit the output of the command to bonded interfaces and their slave
180 * interfaces, use the '<em>bond</em>' optional parameter.
183 * Example of how to display default data for all interfaces:
184 * @cliexstart{show hardware-interfaces}
185 * Name Idx Link Hardware
186 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
187 * Ethernet address ec:f4:bb:c0:bc:fc
189 * carrier up full duplex speed 1000 mtu 9216
190 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
192 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
193 * Ethernet address ec:f4:bb:c0:bc:fd
195 * carrier up full duplex speed 1000 mtu 9216
196 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
198 * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0
199 * Ethernet address 02:fe:a5:a9:8b:8e
200 * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1
201 * Ethernet address 02:fe:c0:4e:3b:b0
202 * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2
203 * Ethernet address 02:fe:1f:73:92:81
204 * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3
205 * Ethernet address 02:fe:f2:25:c4:68
206 * local0 0 down local0
209 * Example of how to display '<em>verbose</em>' data for an interface by name and
210 * software index (where 2 is the software index):
211 * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose}
212 * Name Idx Link Hardware
213 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
214 * Ethernet address ec:f4:bb:c0:bc:fc
216 * carrier up full duplex speed 1000 mtu 9216
217 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
219 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
220 * Ethernet address ec:f4:bb:c0:bc:fd
222 * carrier up full duplex speed 1000 mtu 9216
223 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
228 VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
229 .path = "show hardware-interfaces",
230 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
231 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
232 .function = show_or_clear_hw_interfaces,
238 * Clear the extended statistics for all or a list of given interfaces
239 * (statistics associated with the '<em>show hardware-interfaces</em>' command).
242 * Example of how to clear the extended statistics for all interfaces:
243 * @cliexcmd{clear hardware-interfaces}
244 * Example of how to clear the extended statistics for an interface by
245 * name and software index (where 2 is the software index):
246 * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2}
249 VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
250 .path = "clear hardware-interfaces",
251 .short_help = "clear hardware-interfaces "
252 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
253 .function = show_or_clear_hw_interfaces,
258 sw_interface_name_compare (void *a1, void *a2)
260 vnet_sw_interface_t *si1 = a1;
261 vnet_sw_interface_t *si2 = a2;
263 return vnet_sw_interface_compare (vnet_get_main (),
264 si1->sw_if_index, si2->sw_if_index);
267 static clib_error_t *
268 show_sw_interfaces (vlib_main_t * vm,
269 unformat_input_t * input, vlib_cli_command_t * cmd)
271 clib_error_t *error = 0;
272 vnet_main_t *vnm = vnet_get_main ();
273 unformat_input_t _linput, *linput = &_linput;
274 vnet_interface_main_t *im = &vnm->interface_main;
275 vnet_sw_interface_t *si, *sorted_sis = 0;
276 u32 sw_if_index = ~(u32) 0;
277 u8 show_addresses = 0;
278 u8 show_features = 0;
283 * Get a line of input. Won't work if the user typed
284 * "show interface" and nothing more.
286 if (unformat_user (input, unformat_line_input, linput))
288 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
290 /* See if user wants to show specific interface */
292 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
294 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
295 vec_add1 (sorted_sis, si[0]);
297 else if (unformat (linput, "address") || unformat (linput, "addr"))
299 else if (unformat (linput, "features") || unformat (linput, "feat"))
301 else if (unformat (linput, "tag"))
303 else if (unformat (linput, "verbose"))
307 error = clib_error_return (0, "unknown input `%U'",
308 format_unformat_error, linput);
312 unformat_free (linput);
314 if (show_features || show_tag)
316 if (sw_if_index == ~(u32) 0)
317 return clib_error_return (0, "Interface not specified...");
322 vnet_interface_features_show (vm, sw_if_index, verbose);
324 l2_input_config_t *l2_input = l2input_intf_config (sw_if_index);
325 u32 fb = l2_input->feature_bitmap;
326 /* intf input features are masked by bridge domain */
327 if (l2_input->bridge)
328 fb &= l2input_bd_config (l2_input->bd_index)->feature_bitmap;
329 vlib_cli_output (vm, "\nl2-input:\n%U", format_l2_input_features, fb);
331 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
332 vlib_cli_output (vm, "\nl2-output:");
333 if (l2_output->out_vtr_flag)
334 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
335 vlib_cli_output (vm, "%U", format_l2_output_features,
336 l2_output->feature_bitmap);
342 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
343 vlib_cli_output (vm, "%U: %s",
344 format_vnet_sw_if_index_name, vnm, sw_if_index,
345 tag ? (char *) tag : "(none)");
350 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
352 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
354 /* Gather interfaces. */
356 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
357 _vec_len (sorted_sis) = 0;
359 pool_foreach (si, im->sw_interfaces,
361 int visible = vnet_swif_is_api_visible (si);
363 vec_add1 (sorted_sis, si[0]);}
367 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
372 vec_foreach (si, sorted_sis)
374 ip4_main_t *im4 = &ip4_main;
375 ip6_main_t *im6 = &ip6_main;
376 ip_lookup_main_t *lm4 = &im4->lookup_main;
377 ip_lookup_main_t *lm6 = &im6->lookup_main;
378 ip_interface_address_t *ia = 0;
379 u32 fib_index4 = 0, fib_index6 = 0;
381 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
382 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
385 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
386 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
389 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
390 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
392 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
394 (vm, "%U (%s): \n unnumbered, use %U",
395 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
396 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
397 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
401 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
402 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
404 /* Display any L2 info */
405 l2_input_config_t *l2_input = l2input_intf_config (si->sw_if_index);
406 if (l2_input->bridge)
408 bd_main_t *bdm = &bd_main;
409 u32 bd_id = l2input_main.bd_configs[l2_input->bd_index].bd_id;
410 vlib_cli_output (vm, " L2 bridge bd-id %d idx %d shg %d %s",
411 bd_id, bd_find_index (bdm, bd_id), l2_input->shg,
412 l2_input->bvi ? "bvi" : " ");
414 else if (l2_input->xconnect)
415 vlib_cli_output (vm, " L2 xconnect %U",
416 format_vnet_sw_if_index_name, vnm,
417 l2_input->output_sw_if_index);
420 /* Display any IP4 addressing info */
421 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
422 1 /* honor unnumbered */,
424 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
426 vlib_cli_output (vm, " L3 %U/%d ip4 table-id %d fib-idx %d",
427 format_ip4_address, r4, ia->address_length,
429 ip4_fib_index_from_table_id (fib4->table_id));
431 vlib_cli_output (vm, " L3 %U/%d",
432 format_ip4_address, r4, ia->address_length);
437 /* Display any IP6 addressing info */
438 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
439 1 /* honor unnumbered */,
441 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
443 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
444 format_ip6_address, r6, ia->address_length,
446 ip6_fib_index_from_table_id (fib6->table_id));
448 vlib_cli_output (vm, " L3 %U/%d",
449 format_ip6_address, r6, ia->address_length);
456 vec_foreach (si, sorted_sis)
458 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
463 vec_free (sorted_sis);
468 VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
469 .path = "show interface",
470 .short_help = "show interface [address|addr|features|feat] [<interface> [<interface> [..]]] [verbose]",
471 .function = show_sw_interfaces,
475 /* Root of all interface commands. */
477 VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
479 .short_help = "Interface commands",
484 VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
485 .path = "set interface",
486 .short_help = "Interface commands",
490 static clib_error_t *
491 clear_interface_counters (vlib_main_t * vm,
492 unformat_input_t * input, vlib_cli_command_t * cmd)
494 vnet_main_t *vnm = vnet_get_main ();
495 vnet_interface_main_t *im = &vnm->interface_main;
496 vlib_simple_counter_main_t *sm;
497 vlib_combined_counter_main_t *cm;
498 static vnet_main_t **my_vnet_mains;
499 int i, j, n_counters;
501 vec_reset_length (my_vnet_mains);
503 for (i = 0; i < vec_len (vnet_mains); i++)
506 vec_add1 (my_vnet_mains, vnet_mains[i]);
509 if (vec_len (vnet_mains) == 0)
510 vec_add1 (my_vnet_mains, vnm);
512 n_counters = vec_len (im->combined_sw_if_counters);
514 for (j = 0; j < n_counters; j++)
516 for (i = 0; i < vec_len (my_vnet_mains); i++)
518 im = &my_vnet_mains[i]->interface_main;
519 cm = im->combined_sw_if_counters + j;
520 vlib_clear_combined_counters (cm);
524 n_counters = vec_len (im->sw_if_counters);
526 for (j = 0; j < n_counters; j++)
528 for (i = 0; i < vec_len (my_vnet_mains); i++)
530 im = &my_vnet_mains[i]->interface_main;
531 sm = im->sw_if_counters + j;
532 vlib_clear_simple_counters (sm);
540 * Clear the statistics for all interfaces (statistics associated with the
541 * '<em>show interface</em>' command).
544 * Example of how to clear the statistics for all interfaces:
545 * @cliexcmd{clear interfaces}
548 VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
549 .path = "clear interfaces",
550 .short_help = "clear interfaces",
551 .function = clear_interface_counters,
556 * Parse subinterface names.
558 * The following subinterface syntax is supported. The first two are for
559 * backwards compatability:
562 * - a subinterface with the name <intf-name>.<id>. The subinterface
563 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
565 * <intf-name> <min_id>-<max_id>
566 * - a set of the above subinterfaces, repeating for each id
567 * in the range <min_id> to <max_id>
569 * In the following, exact-match semantics (i.e. the number of vlan tags on the
570 * packet must match the number of tags in the configuration) are used only if
571 * the keyword exact-match is present. Non-exact match is the default.
573 * <intf-name> <id> dot1q <outer_id> [exact-match]
574 * - a subinterface with the name <intf-name>.<id>. The subinterface
575 * is a single dot1q vlan with vlan id <outer_id>.
577 * <intf-name> <id> dot1q any [exact-match]
578 * - a subinterface with the name <intf-name>.<id>. The subinterface
579 * is a single dot1q vlan with any vlan id.
581 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
582 * - a subinterface with the name <intf-name>.<id>. The subinterface
583 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
586 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
587 * - a subinterface with the name <intf-name>.<id>. The subinterface
588 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
590 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
592 * - a subinterface with the name <intf-name>.<id>. The subinterface
593 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
595 * For each of the above CLI, there is a duplicate that uses the keyword
596 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
597 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
598 * tagged packets the inner ethertype is always 0x8100. Also note that
599 * the dot1q and dot1ad naming spaces are independent, so it is legal to
600 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
602 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
603 * - a subinterface with the name <intf-name>.<id>. The subinterface
604 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
607 * <intf-name> <id> untagged
608 * - a subinterface with the name <intf-name>.<id>. The subinterface
609 * has no vlan tags. Only one can be specified per interface.
611 * <intf-name> <id> default
612 * - a subinterface with the name <intf-name>.<id>. This is associated
613 * with a packet that did not match any other configured subinterface
614 * on this interface. Only one can be specified per interface.
617 static clib_error_t *
618 parse_vlan_sub_interfaces (unformat_input_t * input,
619 vnet_sw_interface_t * template)
621 clib_error_t *error = 0;
622 u32 inner_vlan, outer_vlan;
624 if (unformat (input, "any inner-dot1q any"))
626 template->sub.eth.flags.two_tags = 1;
627 template->sub.eth.flags.outer_vlan_id_any = 1;
628 template->sub.eth.flags.inner_vlan_id_any = 1;
630 else if (unformat (input, "any"))
632 template->sub.eth.flags.one_tag = 1;
633 template->sub.eth.flags.outer_vlan_id_any = 1;
635 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
637 template->sub.eth.flags.two_tags = 1;
638 template->sub.eth.flags.inner_vlan_id_any = 1;
639 template->sub.eth.outer_vlan_id = outer_vlan;
641 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
643 template->sub.eth.flags.two_tags = 1;
644 template->sub.eth.outer_vlan_id = outer_vlan;
645 template->sub.eth.inner_vlan_id = inner_vlan;
647 else if (unformat (input, "%d", &outer_vlan))
649 template->sub.eth.flags.one_tag = 1;
650 template->sub.eth.outer_vlan_id = outer_vlan;
654 error = clib_error_return (0, "expected dot1q config, got `%U'",
655 format_unformat_error, input);
659 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
661 if (unformat (input, "exact-match"))
663 template->sub.eth.flags.exact_match = 1;
671 static clib_error_t *
672 create_sub_interfaces (vlib_main_t * vm,
673 unformat_input_t * input, vlib_cli_command_t * cmd)
675 vnet_main_t *vnm = vnet_get_main ();
676 clib_error_t *error = 0;
677 u32 hw_if_index, sw_if_index;
678 vnet_hw_interface_t *hi;
679 u32 id, id_min, id_max;
680 vnet_sw_interface_t template;
683 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
685 error = clib_error_return (0, "unknown interface `%U'",
686 format_unformat_error, input);
690 memset (&template, 0, sizeof (template));
691 template.sub.eth.raw_flags = 0;
693 if (unformat (input, "%d default", &id_min))
696 template.sub.eth.flags.default_sub = 1;
698 else if (unformat (input, "%d untagged", &id_min))
701 template.sub.eth.flags.no_tags = 1;
702 template.sub.eth.flags.exact_match = 1;
704 else if (unformat (input, "%d dot1q", &id_min))
706 /* parse dot1q config */
708 error = parse_vlan_sub_interfaces (input, &template);
712 else if (unformat (input, "%d dot1ad", &id_min))
714 /* parse dot1ad config */
716 template.sub.eth.flags.dot1ad = 1;
717 error = parse_vlan_sub_interfaces (input, &template);
721 else if (unformat (input, "%d-%d", &id_min, &id_max))
723 template.sub.eth.flags.one_tag = 1;
724 template.sub.eth.flags.exact_match = 1;
728 else if (unformat (input, "%d", &id_min))
731 template.sub.eth.flags.one_tag = 1;
732 template.sub.eth.outer_vlan_id = id_min;
733 template.sub.eth.flags.exact_match = 1;
738 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
739 format_unformat_error, input);
743 hi = vnet_get_hw_interface (vnm, hw_if_index);
745 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
748 clib_error_return (0,
749 "not allowed as %v belong to a BondEthernet interface",
754 for (id = id_min; id <= id_max; id++)
757 vnet_interface_main_t *im = &vnm->interface_main;
758 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
761 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
765 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
766 hi->sw_if_index, id);
770 kp = clib_mem_alloc (sizeof (*kp));
771 *kp = sup_and_sub_key;
773 template.type = VNET_SW_INTERFACE_TYPE_SUB;
774 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
775 template.sup_sw_if_index = hi->sw_if_index;
776 template.sub.id = id;
778 template.sub.eth.outer_vlan_id = id;
780 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
784 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
785 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
786 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
787 vnet_get_main (), sw_if_index);
795 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
796 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
797 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
798 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
799 * but this is not recommended.
801 * This command has several variations:
802 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
803 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
805 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
806 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
807 * match any other subinterfaces should be sent to this subinterface.
809 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
810 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
811 * to this subinterface.
813 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
814 * subinterfaces to handle a range of VLAN IDs.
816 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
817 * Use this command to specify the outer VLAN ID, to either be explicited or to make the
818 * VLAN ID different from the '<em>subId</em>'.
820 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
821 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
822 * the innner VLAN ID.
824 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explictly entered, subinterfaces
825 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
826 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
827 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
828 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
829 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
830 * entered, then the default behavior is exact-match.
832 * Use the '<em>show interface</em>' command to display all subinterfaces.
836 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
837 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
839 * The previous example is shorthand and is equivalent to:
840 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
843 * Example of how to create a subinterface number that is different from the VLAN ID:
844 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
847 * Examples of how to create q-in-q and q-in-any subinterfaces:
848 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
849 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
851 * Examples of how to create dot1ad interfaces:
852 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
853 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
856 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
857 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
858 * is non-exact match:
859 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
861 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
862 * is specified and only one VLAN is configured, but packet contains two VLANs:
863 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
866 * Example of how to created a subinterface to process untagged packets:
867 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
869 * Example of how to created a subinterface to process any packet with a VLAN ID that
870 * does not match any other subinterface:
871 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
873 * When subinterfaces are created, they are in the down state. Example of how to
874 * enable a newly created subinterface:
875 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
879 VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
880 .path = "create sub-interfaces",
881 .short_help = "create sub-interfaces <interface> "
882 "{<subId> [default|untagged]} | "
883 "{<subId>-<subId>} | "
884 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
885 .function = create_sub_interfaces,
889 static clib_error_t *
890 set_state (vlib_main_t * vm,
891 unformat_input_t * input, vlib_cli_command_t * cmd)
893 vnet_main_t *vnm = vnet_get_main ();
895 u32 sw_if_index, flags;
898 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
900 error = clib_error_return (0, "unknown interface `%U'",
901 format_unformat_error, input);
905 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
907 error = clib_error_return (0, "unknown flags `%U'",
908 format_unformat_error, input);
912 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
922 * This command is used to change the admin state (up/down) of an interface.
924 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
925 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
926 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
927 * '<em>punt</em>' flag (interface is still down).
930 * Example of how to configure the admin state of an interface to '<em>up</em?':
931 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
932 * Example of how to configure the admin state of an interface to '<em>down</em?':
933 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
936 VLIB_CLI_COMMAND (set_state_command, static) = {
937 .path = "set interface state",
938 .short_help = "set interface state <interface> [up|down|punt|enable]",
939 .function = set_state,
943 static clib_error_t *
944 set_unnumbered (vlib_main_t * vm,
945 unformat_input_t * input, vlib_cli_command_t * cmd)
947 vnet_main_t *vnm = vnet_get_main ();
948 u32 unnumbered_sw_if_index = ~0;
949 u32 inherit_from_sw_if_index = ~0;
952 if (unformat (input, "%U use %U",
953 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
954 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
956 else if (unformat (input, "del %U",
957 unformat_vnet_sw_interface, vnm,
958 &unnumbered_sw_if_index))
961 return clib_error_return (0, "parse error '%U'",
962 format_unformat_error, input);
964 if (~0 == unnumbered_sw_if_index)
965 return clib_error_return (0, "Specify the unnumbered interface");
966 if (enable && ~0 == inherit_from_sw_if_index)
967 return clib_error_return (0, "When enabling unnumberered specify the"
968 " IP enabled interface that it uses");
970 vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
971 inherit_from_sw_if_index, enable);
977 VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
978 .path = "set interface unnumbered",
979 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
980 .function = set_unnumbered,
986 static clib_error_t *
987 set_hw_class (vlib_main_t * vm,
988 unformat_input_t * input, vlib_cli_command_t * cmd)
990 vnet_main_t *vnm = vnet_get_main ();
991 vnet_interface_main_t *im = &vnm->interface_main;
993 u32 hw_if_index, hw_class_index;
996 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
998 error = clib_error_return (0, "unknown hardware interface `%U'",
999 format_unformat_error, input);
1003 if (!unformat_user (input, unformat_hash_string,
1004 im->hw_interface_class_by_name, &hw_class_index))
1006 error = clib_error_return (0, "unknown hardware class `%U'",
1007 format_unformat_error, input);
1011 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1020 VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1021 .path = "set interface hw-class",
1022 .short_help = "Set interface hardware class",
1023 .function = set_hw_class,
1027 static clib_error_t *
1028 vnet_interface_cli_init (vlib_main_t * vm)
1033 VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1035 static clib_error_t *
1036 renumber_interface_command_fn (vlib_main_t * vm,
1037 unformat_input_t * input,
1038 vlib_cli_command_t * cmd)
1041 u32 new_dev_instance;
1042 vnet_main_t *vnm = vnet_get_main ();
1045 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
1046 return clib_error_return (0, "unknown hardware interface `%U'",
1047 format_unformat_error, input);
1049 if (!unformat (input, "%d", &new_dev_instance))
1050 return clib_error_return (0, "new dev instance missing");
1052 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1060 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
1070 VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1071 .path = "renumber interface",
1072 .short_help = "renumber interface <interface> <new-dev-instance>",
1073 .function = renumber_interface_command_fn,
1077 static clib_error_t *
1078 promiscuous_cmd (vlib_main_t * vm,
1079 unformat_input_t * input, vlib_cli_command_t * cmd)
1081 vnet_main_t *vnm = vnet_get_main ();
1083 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
1084 ethernet_main_t *em = ðernet_main;
1085 ethernet_interface_t *eif;
1087 if (unformat (input, "on %U",
1088 unformat_vnet_hw_interface, vnm, &hw_if_index))
1090 else if (unformat (input, "off %U",
1091 unformat_ethernet_interface, vnm, &hw_if_index))
1094 return clib_error_return (0, "unknown input `%U'",
1095 format_unformat_error, input);
1097 eif = ethernet_get_interface (em, hw_if_index);
1099 return clib_error_return (0, "not supported");
1101 ethernet_set_flags (vnm, hw_if_index, flags);
1106 VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1107 .path = "set interface promiscuous",
1108 .short_help = "set interface promiscuous [on|off] <interface>",
1109 .function = promiscuous_cmd,
1113 static clib_error_t *
1114 mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1116 vnet_main_t *vnm = vnet_get_main ();
1117 u32 hw_if_index, sw_if_index, mtu;
1118 ethernet_main_t *em = ðernet_main;
1119 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
1121 if (unformat (input, "%d %U", &mtu,
1122 unformat_vnet_hw_interface, vnm, &hw_if_index))
1125 * Change physical MTU on interface. Only supported for Ethernet
1128 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1129 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1132 return clib_error_return (0, "not supported");
1134 if (mtu < hi->min_supported_packet_bytes)
1135 return clib_error_return (0, "Invalid mtu (%d): "
1136 "must be >= min pkt bytes (%d)", mtu,
1137 hi->min_supported_packet_bytes);
1139 if (mtu > hi->max_supported_packet_bytes)
1140 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1141 hi->max_supported_packet_bytes);
1143 vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
1146 else if (unformat (input, "packet %d %U", &mtu,
1147 unformat_vnet_sw_interface, vnm, &sw_if_index))
1148 /* Set default packet MTU (including L3 header */
1149 mtus[VNET_MTU_L3] = mtu;
1150 else if (unformat (input, "ip4 %d %U", &mtu,
1151 unformat_vnet_sw_interface, vnm, &sw_if_index))
1152 mtus[VNET_MTU_IP4] = mtu;
1153 else if (unformat (input, "ip6 %d %U", &mtu,
1154 unformat_vnet_sw_interface, vnm, &sw_if_index))
1155 mtus[VNET_MTU_IP6] = mtu;
1156 else if (unformat (input, "mpls %d %U", &mtu,
1157 unformat_vnet_sw_interface, vnm, &sw_if_index))
1158 mtus[VNET_MTU_MPLS] = mtu;
1160 return clib_error_return (0, "unknown input `%U'",
1161 format_unformat_error, input);
1163 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1170 VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1171 .path = "set interface mtu",
1172 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
1173 .function = mtu_cmd,
1177 static clib_error_t *
1178 set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1179 vlib_cli_command_t * cmd)
1181 vnet_main_t *vnm = vnet_get_main ();
1182 vnet_sw_interface_t *si = NULL;
1183 clib_error_t *error = 0;
1184 u32 sw_if_index = ~0;
1187 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1189 error = clib_error_return (0, "unknown interface `%U'",
1190 format_unformat_error, input);
1193 if (!unformat_user (input, unformat_ethernet_address, mac))
1195 error = clib_error_return (0, "expected mac address `%U'",
1196 format_unformat_error, input);
1199 si = vnet_get_sw_interface (vnm, sw_if_index);
1200 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
1206 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1207 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1208 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1212 * Example of how to change MAC Address of interface:
1213 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1214 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1215 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1216 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1220 VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1221 .path = "set interface mac address",
1222 .short_help = "set interface mac address <interface> <mac-address>",
1223 .function = set_interface_mac_address,
1227 static clib_error_t *
1228 set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1230 vnet_main_t *vnm = vnet_get_main ();
1231 u32 sw_if_index = ~0;
1234 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1235 vnm, &sw_if_index, &tag))
1236 return clib_error_return (0, "unknown input `%U'",
1237 format_unformat_error, input);
1239 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1245 VLIB_CLI_COMMAND (set_tag_command, static) = {
1246 .path = "set interface tag",
1247 .short_help = "set interface tag <interface> <tag>",
1248 .function = set_tag,
1252 static clib_error_t *
1253 clear_tag (vlib_main_t * vm, unformat_input_t * input,
1254 vlib_cli_command_t * cmd)
1256 vnet_main_t *vnm = vnet_get_main ();
1257 u32 sw_if_index = ~0;
1259 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1260 return clib_error_return (0, "unknown input `%U'",
1261 format_unformat_error, input);
1263 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1269 VLIB_CLI_COMMAND (clear_tag_command, static) = {
1270 .path = "clear interface tag",
1271 .short_help = "clear interface tag <interface>",
1272 .function = clear_tag,
1276 static clib_error_t *
1277 set_hw_interface_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1278 u32 queue_id, vnet_hw_interface_rx_mode mode)
1280 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1281 vnet_device_class_t *dev_class =
1282 vnet_get_device_class (vnm, hw->dev_class_index);
1283 clib_error_t *error;
1284 vnet_hw_interface_rx_mode old_mode;
1287 if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT)
1288 mode = hw->default_rx_mode;
1290 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &old_mode);
1294 if (old_mode == mode)
1295 return 0; /* same rx-mode, no change */
1297 case VNET_API_ERROR_INVALID_INTERFACE:
1298 return clib_error_return (0, "invalid interface");
1299 case VNET_API_ERROR_INVALID_QUEUE:
1300 return clib_error_return (0, "invalid queue");
1302 return clib_error_return (0, "unknown error");
1305 if (dev_class->rx_mode_change_function)
1307 error = dev_class->rx_mode_change_function (vnm, hw_if_index, queue_id,
1313 rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1318 case VNET_API_ERROR_UNSUPPORTED:
1319 return clib_error_return (0, "unsupported");
1320 case VNET_API_ERROR_INVALID_INTERFACE:
1321 return clib_error_return (0, "invalid interface");
1322 case VNET_API_ERROR_INVALID_QUEUE:
1323 return clib_error_return (0, "invalid queue");
1325 return clib_error_return (0, "unknown error");
1332 set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1333 u8 queue_id_valid, u32 queue_id,
1334 vnet_hw_interface_rx_mode mode)
1336 clib_error_t *error = 0;
1337 vnet_hw_interface_t *hw;
1340 hw = vnet_get_hw_interface (vnm, hw_if_index);
1342 if (queue_id_valid == 0)
1344 for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1346 error = set_hw_interface_rx_mode (vnm, hw_if_index, i, mode);
1350 hw->default_rx_mode = mode;
1353 error = set_hw_interface_rx_mode (vnm, hw_if_index, queue_id, mode);
1358 static clib_error_t *
1359 set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1360 vlib_cli_command_t * cmd)
1362 clib_error_t *error = 0;
1363 unformat_input_t _line_input, *line_input = &_line_input;
1364 vnet_main_t *vnm = vnet_get_main ();
1365 u32 hw_if_index = (u32) ~ 0;
1366 u32 queue_id = (u32) ~ 0;
1367 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
1368 u8 queue_id_valid = 0;
1370 if (!unformat_user (input, unformat_line_input, line_input))
1373 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1376 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1378 else if (unformat (line_input, "queue %d", &queue_id))
1380 else if (unformat (line_input, "polling"))
1381 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
1382 else if (unformat (line_input, "interrupt"))
1383 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
1384 else if (unformat (line_input, "adaptive"))
1385 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
1388 error = clib_error_return (0, "parse error: '%U'",
1389 format_unformat_error, line_input);
1390 unformat_free (line_input);
1395 unformat_free (line_input);
1397 if (hw_if_index == (u32) ~ 0)
1398 return clib_error_return (0, "please specify valid interface name");
1400 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
1401 return clib_error_return (0, "please specify valid rx-mode");
1403 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1410 * This command is used to assign the RX packet processing mode (polling,
1411 * interrupt, adaptive) of the a given interface, and optionally a
1412 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1413 * is applied to all queues of the interface. Not all interfaces support
1414 * all modes. To display the current rx-mode use the command
1415 * '<em>show interface rx-placement</em>'.
1418 * Example of how to assign rx-mode to all queues on an interface:
1419 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1420 * Example of how to assign rx-mode to one queue of an interface:
1421 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1422 * Example of how to display the rx-mode of all interfaces:
1423 * @cliexstart{show interface rx-placement}
1424 * Thread 1 (vpp_wk_0):
1426 * GigabitEthernet7/0/0 queue 0 (polling)
1427 * node vhost-user-input:
1428 * VirtualEthernet0/0/12 queue 0 (interrupt)
1429 * VirtualEthernet0/0/12 queue 2 (polling)
1430 * VirtualEthernet0/0/13 queue 0 (polling)
1431 * VirtualEthernet0/0/13 queue 2 (polling)
1432 * Thread 2 (vpp_wk_1):
1434 * GigabitEthernet7/0/1 queue 0 (polling)
1435 * node vhost-user-input:
1436 * VirtualEthernet0/0/12 queue 1 (polling)
1437 * VirtualEthernet0/0/12 queue 3 (polling)
1438 * VirtualEthernet0/0/13 queue 1 (polling)
1439 * VirtualEthernet0/0/13 queue 3 (polling)
1443 VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
1444 .path = "set interface rx-mode",
1445 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1446 .function = set_interface_rx_mode,
1450 static clib_error_t *
1451 show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1452 vlib_cli_command_t * cmd)
1455 vnet_main_t *vnm = vnet_get_main ();
1456 vnet_device_input_runtime_t *rt;
1457 vnet_device_and_queue_t *dq;
1458 vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
1463 foreach_vlib_main (({
1464 clib_bitmap_foreach (si, pn->sibling_bitmap,
1466 rt = vlib_node_get_runtime_data (this_vlib_main, si);
1468 if (vec_len (rt->devices_and_queues))
1469 s = format (s, " node %U:\n", format_vlib_node_name, vm, si);
1471 vec_foreach (dq, rt->devices_and_queues)
1473 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm,
1475 s = format (s, " %U queue %u (%U)\n",
1476 format_vnet_sw_if_index_name, vnm, hi->sw_if_index,
1478 format_vnet_hw_interface_rx_mode, dq->mode);
1481 if (vec_len (s) > 0)
1483 vlib_cli_output(vm, "Thread %u (%v):\n%v", index,
1484 vlib_worker_threads[index].name, s);
1485 vec_reset_length (s);
1496 * This command is used to display the interface and queue worker
1500 * Example of how to display the interface placement:
1501 * @cliexstart{show interface rx-placement}
1502 * Thread 1 (vpp_wk_0):
1504 * GigabitEthernet7/0/0 queue 0 (polling)
1505 * node vhost-user-input:
1506 * VirtualEthernet0/0/12 queue 0 (polling)
1507 * VirtualEthernet0/0/12 queue 2 (polling)
1508 * VirtualEthernet0/0/13 queue 0 (polling)
1509 * VirtualEthernet0/0/13 queue 2 (polling)
1510 * Thread 2 (vpp_wk_1):
1512 * GigabitEthernet7/0/1 queue 0 (polling)
1513 * node vhost-user-input:
1514 * VirtualEthernet0/0/12 queue 1 (polling)
1515 * VirtualEthernet0/0/12 queue 3 (polling)
1516 * VirtualEthernet0/0/13 queue 1 (polling)
1517 * VirtualEthernet0/0/13 queue 3 (polling)
1521 VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1522 .path = "show interface rx-placement",
1523 .short_help = "show interface rx-placement",
1524 .function = show_interface_rx_placement_fn,
1528 static clib_error_t *
1529 set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input,
1530 vlib_cli_command_t * cmd)
1532 clib_error_t *error = 0;
1533 unformat_input_t _line_input, *line_input = &_line_input;
1534 vnet_main_t *vnm = vnet_get_main ();
1535 vnet_device_main_t *vdm = &vnet_device_main;
1536 vnet_hw_interface_rx_mode mode;
1537 u32 hw_if_index = (u32) ~ 0;
1538 u32 queue_id = (u32) 0;
1539 u32 thread_index = (u32) ~ 0;
1542 if (!unformat_user (input, unformat_line_input, line_input))
1545 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1548 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1550 else if (unformat (line_input, "queue %d", &queue_id))
1552 else if (unformat (line_input, "main", &thread_index))
1554 else if (unformat (line_input, "worker %d", &thread_index))
1555 thread_index += vdm->first_worker_thread_index;
1558 error = clib_error_return (0, "parse error: '%U'",
1559 format_unformat_error, line_input);
1560 unformat_free (line_input);
1565 unformat_free (line_input);
1567 if (hw_if_index == (u32) ~ 0)
1568 return clib_error_return (0, "please specify valid interface name");
1570 if (thread_index > vdm->last_worker_thread_index)
1571 return clib_error_return (0,
1572 "please specify valid worker thread or main");
1574 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode);
1577 return clib_error_return (0, "not found");
1579 rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id);
1582 return clib_error_return (0, "not found");
1584 vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id,
1586 vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1592 * This command is used to assign a given interface, and optionally a
1593 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1594 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1595 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
1598 * Example of how to display the interface placement:
1599 * @cliexstart{show interface rx-placement}
1600 * Thread 1 (vpp_wk_0):
1602 * GigabitEthernet7/0/0 queue 0 (polling)
1603 * node vhost-user-input:
1604 * VirtualEthernet0/0/12 queue 0 (polling)
1605 * VirtualEthernet0/0/12 queue 2 (polling)
1606 * VirtualEthernet0/0/13 queue 0 (polling)
1607 * VirtualEthernet0/0/13 queue 2 (polling)
1608 * Thread 2 (vpp_wk_1):
1610 * GigabitEthernet7/0/1 queue 0 (polling)
1611 * node vhost-user-input:
1612 * VirtualEthernet0/0/12 queue 1 (polling)
1613 * VirtualEthernet0/0/12 queue 3 (polling)
1614 * VirtualEthernet0/0/13 queue 1 (polling)
1615 * VirtualEthernet0/0/13 queue 3 (polling)
1617 * Example of how to assign a interface and queue to a worker thread:
1618 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1619 * Example of how to display the interface placement:
1620 * @cliexstart{show interface rx-placement}
1621 * Thread 1 (vpp_wk_0):
1623 * GigabitEthernet7/0/0 queue 0 (polling)
1624 * node vhost-user-input:
1625 * VirtualEthernet0/0/12 queue 0 (polling)
1626 * VirtualEthernet0/0/12 queue 1 (polling)
1627 * VirtualEthernet0/0/12 queue 2 (polling)
1628 * VirtualEthernet0/0/13 queue 0 (polling)
1629 * VirtualEthernet0/0/13 queue 2 (polling)
1630 * Thread 2 (vpp_wk_1):
1632 * GigabitEthernet7/0/1 queue 0 (polling)
1633 * node vhost-user-input:
1634 * VirtualEthernet0/0/12 queue 3 (polling)
1635 * VirtualEthernet0/0/13 queue 1 (polling)
1636 * VirtualEthernet0/0/13 queue 3 (polling)
1640 VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1641 .path = "set interface rx-placement",
1642 .short_help = "set interface rx-placement <interface> [queue <n>] "
1643 "[worker <n> | main]",
1644 .function = set_interface_rx_placement,
1649 * fd.io coding-style-patch-verification: ON
1652 * eval: (c-set-style "gnu")