blob: a66e1576bde6d1076fcb254effd24d9da93a6939 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
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.
14 */
15/*
16 * interface_cli.c: interface CLI
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
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:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
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.
38 */
39
Chris Luke16bcf7d2016-09-01 14:31:46 -040040/**
41 * @file
Billy McFalle9bac692017-08-11 14:05:11 -040042 * @brief Interface CLI.
43 *
44 * Source code for several CLI interface commands.
45 *
Chris Luke16bcf7d2016-09-01 14:31:46 -040046 */
47
Ed Warnickecb9cada2015-12-08 15:45:58 -070048#include <vnet/vnet.h>
49#include <vnet/ip/ip.h>
John Lobcebbb92016-04-05 15:47:43 -040050#include <vppinfra/bitmap.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010051#include <vnet/fib/ip4_fib.h>
52#include <vnet/fib/ip6_fib.h>
Eyal Bari942402b2017-07-26 11:57:04 +030053#include <vnet/l2/l2_output.h>
54#include <vnet/l2/l2_input.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070055
Dave Barachba868bb2016-08-08 09:51:21 -040056static int
57compare_interface_names (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -070058{
Dave Barachba868bb2016-08-08 09:51:21 -040059 u32 *hi1 = a1;
60 u32 *hi2 = a2;
Ed Warnickecb9cada2015-12-08 15:45:58 -070061
Dave Barachba868bb2016-08-08 09:51:21 -040062 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070063}
64
65static clib_error_t *
66show_or_clear_hw_interfaces (vlib_main_t * vm,
67 unformat_input_t * input,
68 vlib_cli_command_t * cmd)
69{
Dave Barachba868bb2016-08-08 09:51:21 -040070 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;
John Lobcebbb92016-04-05 15:47:43 -040075 int i, verbose = -1, is_show, show_bond = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070076
77 is_show = strstr (cmd->path, "show") != 0;
78 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
79 {
80 /* See if user wants to show a specific interface. */
Dave Barachba868bb2016-08-08 09:51:21 -040081 if (unformat
82 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
83 vec_add1 (hw_if_indices, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -040084
Sean Hope679ea792016-02-22 15:12:01 -050085 /* See if user wants to show an interface with a specific hw_if_index. */
86 else if (unformat (input, "%u", &hw_if_index))
Dave Barachba868bb2016-08-08 09:51:21 -040087 vec_add1 (hw_if_indices, hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070088
89 else if (unformat (input, "verbose"))
Dave Barachba868bb2016-08-08 09:51:21 -040090 verbose = 1; /* this is also the default */
Ed Warnickecb9cada2015-12-08 15:45:58 -070091
92 else if (unformat (input, "detail"))
93 verbose = 2;
94
95 else if (unformat (input, "brief"))
96 verbose = 0;
97
John Lobcebbb92016-04-05 15:47:43 -040098 else if (unformat (input, "bond"))
Dave Barachba868bb2016-08-08 09:51:21 -040099 {
100 show_bond = 1;
101 if (verbose < 0)
102 verbose = 0; /* default to brief for link bonding */
103 }
John Lobcebbb92016-04-05 15:47:43 -0400104
Ed Warnickecb9cada2015-12-08 15:45:58 -0700105 else
106 {
107 error = clib_error_return (0, "unknown input `%U'",
108 format_unformat_error, input);
109 goto done;
110 }
111 }
Dave Barachba868bb2016-08-08 09:51:21 -0400112
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113 /* 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));
117
Dave Barachba868bb2016-08-08 09:51:21 -0400118 if (verbose < 0)
119 verbose = 1; /* default to verbose (except bond) */
John Lobcebbb92016-04-05 15:47:43 -0400120
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121 if (is_show)
122 {
123 /* Sort by name. */
124 vec_sort_with_function (hw_if_indices, compare_interface_names);
125
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++)
128 {
129 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
Dave Barachba868bb2016-08-08 09:51:21 -0400130 if (show_bond == 0) /* show all interfaces */
131 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
132 hi, verbose);
133 else if ((hi->bond_info) &&
John Lobcebbb92016-04-05 15:47:43 -0400134 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
Dave Barachba868bb2016-08-08 09:51:21 -0400135 { /* show only bonded interface and all its slave interfaces */
John Lobcebbb92016-04-05 15:47:43 -0400136 int hw_idx;
Dave Barachba868bb2016-08-08 09:51:21 -0400137 vnet_hw_interface_t *shi;
138 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
John Lobcebbb92016-04-05 15:47:43 -0400139 hi, verbose);
Dave Barachba868bb2016-08-08 09:51:21 -0400140
141 /* *INDENT-OFF* */
John Lobcebbb92016-04-05 15:47:43 -0400142 clib_bitmap_foreach (hw_idx, hi->bond_info,
Dave Barachba868bb2016-08-08 09:51:21 -0400143 ({
144 shi = vnet_get_hw_interface(vnm, hw_idx);
145 vlib_cli_output (vm, "%U\n",
146 format_vnet_hw_interface, vnm, shi, verbose);
147 }));
148 /* *INDENT-ON* */
John Lobcebbb92016-04-05 15:47:43 -0400149 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150 }
151 }
152 else
153 {
154 for (i = 0; i < vec_len (hw_if_indices); i++)
155 {
Dave Barachba868bb2016-08-08 09:51:21 -0400156 vnet_device_class_t *dc;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700157
158 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
159 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400160
Ed Warnickecb9cada2015-12-08 15:45:58 -0700161 if (dc->clear_counters)
162 dc->clear_counters (hi->dev_instance);
163 }
164 }
165
Dave Barachba868bb2016-08-08 09:51:21 -0400166done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700167 vec_free (hw_if_indices);
168 return error;
169}
170
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700171/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400172 * 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
174 * parameters:
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.
178 *
179 * To limit the output of the command to bonded interfaces and their slave
180 * interfaces, use the '<em>bond</em>' optional parameter.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700181 *
182 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400183 * 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
188 * Intel e1000
189 * carrier up full duplex speed 1000 mtu 9216
190 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
191 * cpu socket 0
192 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
193 * Ethernet address ec:f4:bb:c0:bc:fd
194 * Intel e1000
195 * carrier up full duplex speed 1000 mtu 9216
196 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
197 * cpu socket 0
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
207 * local
208 * @cliexend
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
215 * Intel e1000
216 * carrier up full duplex speed 1000 mtu 9216
217 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
218 * cpu socket 0
219 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
220 * Ethernet address ec:f4:bb:c0:bc:fd
221 * Intel e1000
222 * carrier up full duplex speed 1000 mtu 9216
223 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
224 * cpu socket 0
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700225 * @cliexend
226 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400227/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700228VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
229 .path = "show hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400230 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
231 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700232 .function = show_or_clear_hw_interfaces,
233};
Dave Barachba868bb2016-08-08 09:51:21 -0400234/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700235
Billy McFalle9bac692017-08-11 14:05:11 -0400236
237/*?
238 * Clear the extended statistics for all or a list of given interfaces
239 * (statistics associated with the '<em>show hardware-interfaces</em>' command).
240 *
241 * @cliexpar
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}
247 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400248/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700249VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
250 .path = "clear hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400251 .short_help = "clear hardware-interfaces "
252 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700253 .function = show_or_clear_hw_interfaces,
254};
Dave Barachba868bb2016-08-08 09:51:21 -0400255/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256
Dave Barachba868bb2016-08-08 09:51:21 -0400257static int
258sw_interface_name_compare (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700259{
260 vnet_sw_interface_t *si1 = a1;
261 vnet_sw_interface_t *si2 = a2;
262
Dave Barachba868bb2016-08-08 09:51:21 -0400263 return vnet_sw_interface_compare (vnet_get_main (),
264 si1->sw_if_index, si2->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265}
266
267static clib_error_t *
268show_sw_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400269 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700270{
Dave Barachba868bb2016-08-08 09:51:21 -0400271 clib_error_t *error = 0;
272 vnet_main_t *vnm = vnet_get_main ();
Dave Barach525c9d02018-05-26 10:48:55 -0400273 unformat_input_t _linput, *linput = &_linput;
Dave Barachba868bb2016-08-08 09:51:21 -0400274 vnet_interface_main_t *im = &vnm->interface_main;
275 vnet_sw_interface_t *si, *sorted_sis = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200276 u32 sw_if_index = ~(u32) 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700277 u8 show_addresses = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200278 u8 show_features = 0;
Dave Barach7be864a2016-11-28 11:41:35 -0500279 u8 show_tag = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400280 int verbose = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281
Dave Barach525c9d02018-05-26 10:48:55 -0400282 /*
283 * Get a line of input. Won't work if the user typed
284 * "show interface" and nothing more.
285 */
286 if (unformat_user (input, unformat_line_input, linput))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287 {
Dave Barach525c9d02018-05-26 10:48:55 -0400288 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700289 {
Dave Barach525c9d02018-05-26 10:48:55 -0400290 /* See if user wants to show specific interface */
291 if (unformat
292 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
293 {
294 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
295 vec_add1 (sorted_sis, si[0]);
296 }
297 else if (unformat (linput, "address") || unformat (linput, "addr"))
298 show_addresses = 1;
299 else if (unformat (linput, "features") || unformat (linput, "feat"))
300 show_features = 1;
301 else if (unformat (linput, "tag"))
302 show_tag = 1;
303 else if (unformat (linput, "verbose"))
304 verbose = 1;
305 else
306 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400307 vec_free (sorted_sis);
Dave Barach525c9d02018-05-26 10:48:55 -0400308 error = clib_error_return (0, "unknown input `%U'",
309 format_unformat_error, linput);
310 goto done;
311 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700312 }
Dave Barach525c9d02018-05-26 10:48:55 -0400313 unformat_free (linput);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700314 }
Dave Barach7be864a2016-11-28 11:41:35 -0500315 if (show_features || show_tag)
Damjan Marion22311502016-10-28 20:30:15 +0200316 {
317 if (sw_if_index == ~(u32) 0)
Dave Barach8fdde3c2019-05-17 10:46:40 -0400318 {
319 vec_free (sorted_sis);
320 return clib_error_return (0, "Interface not specified...");
321 }
Dave Barach7be864a2016-11-28 11:41:35 -0500322 }
Damjan Marion22311502016-10-28 20:30:15 +0200323
Dave Barach7be864a2016-11-28 11:41:35 -0500324 if (show_features)
325 {
Dave Barach525c9d02018-05-26 10:48:55 -0400326 vnet_interface_features_show (vm, sw_if_index, verbose);
Eyal Bari942402b2017-07-26 11:57:04 +0300327
328 l2_input_config_t *l2_input = l2input_intf_config (sw_if_index);
329 u32 fb = l2_input->feature_bitmap;
330 /* intf input features are masked by bridge domain */
331 if (l2_input->bridge)
332 fb &= l2input_bd_config (l2_input->bd_index)->feature_bitmap;
Neale Ranns5d9df1d2018-11-09 08:19:27 -0800333 vlib_cli_output (vm, "\nl2-input:\n%U", format_l2_input_features, fb,
334 1);
Eyal Bari942402b2017-07-26 11:57:04 +0300335
336 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
337 vlib_cli_output (vm, "\nl2-output:");
338 if (l2_output->out_vtr_flag)
339 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
340 vlib_cli_output (vm, "%U", format_l2_output_features,
Neale Ranns5d9df1d2018-11-09 08:19:27 -0800341 l2_output->feature_bitmap, 1);
Dave Barach8fdde3c2019-05-17 10:46:40 -0400342 vec_free (sorted_sis);
Damjan Marion22311502016-10-28 20:30:15 +0200343 return 0;
344 }
Dave Barach7be864a2016-11-28 11:41:35 -0500345 if (show_tag)
346 {
347 u8 *tag;
348 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
349 vlib_cli_output (vm, "%U: %s",
350 format_vnet_sw_if_index_name, vnm, sw_if_index,
351 tag ? (char *) tag : "(none)");
Dave Barach8fdde3c2019-05-17 10:46:40 -0400352 vec_free (sorted_sis);
Dave Barach7be864a2016-11-28 11:41:35 -0500353 return 0;
354 }
Damjan Marion22311502016-10-28 20:30:15 +0200355
Ed Warnickecb9cada2015-12-08 15:45:58 -0700356 if (!show_addresses)
Dave Barachba868bb2016-08-08 09:51:21 -0400357 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700358
Dave Barachba868bb2016-08-08 09:51:21 -0400359 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700360 {
361 /* Gather interfaces. */
Dave Barachba868bb2016-08-08 09:51:21 -0400362 sorted_sis =
363 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700364 _vec_len (sorted_sis) = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400365 /* *INDENT-OFF* */
366 pool_foreach (si, im->sw_interfaces,
367 ({
368 int visible = vnet_swif_is_api_visible (si);
369 if (visible)
370 vec_add1 (sorted_sis, si[0]);}
371 ));
Ole Troand7231612018-06-07 10:17:57 +0200372 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700373 /* Sort by name. */
374 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
375 }
376
377 if (show_addresses)
378 {
379 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400380 {
Dave Barachba868bb2016-08-08 09:51:21 -0400381 ip4_main_t *im4 = &ip4_main;
382 ip6_main_t *im6 = &ip6_main;
383 ip_lookup_main_t *lm4 = &im4->lookup_main;
384 ip_lookup_main_t *lm6 = &im6->lookup_main;
385 ip_interface_address_t *ia = 0;
Dave Barachba868bb2016-08-08 09:51:21 -0400386 u32 fib_index4 = 0, fib_index6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700387
Dave Barachba868bb2016-08-08 09:51:21 -0400388 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
389 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
390 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700391
Dave Barachba868bb2016-08-08 09:51:21 -0400392 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
393 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
394 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700395
John Lo4478d8e2018-01-12 17:15:25 -0500396 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
397 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700398
Dave Barachba868bb2016-08-08 09:51:21 -0400399 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
400 vlib_cli_output
401 (vm, "%U (%s): \n unnumbered, use %U",
John Lo4478d8e2018-01-12 17:15:25 -0500402 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400403 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
404 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400405 else
John Lo4478d8e2018-01-12 17:15:25 -0500406 vlib_cli_output
407 (vm, "%U (%s):",
408 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
409 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410
Eyal Bari942402b2017-07-26 11:57:04 +0300411 /* Display any L2 info */
412 l2_input_config_t *l2_input = l2input_intf_config (si->sw_if_index);
413 if (l2_input->bridge)
Dave Barachba868bb2016-08-08 09:51:21 -0400414 {
John Lo4478d8e2018-01-12 17:15:25 -0500415 bd_main_t *bdm = &bd_main;
Eyal Bari942402b2017-07-26 11:57:04 +0300416 u32 bd_id = l2input_main.bd_configs[l2_input->bd_index].bd_id;
John Lo4478d8e2018-01-12 17:15:25 -0500417 vlib_cli_output (vm, " L2 bridge bd-id %d idx %d shg %d %s",
418 bd_id, bd_find_index (bdm, bd_id), l2_input->shg,
419 l2_input->bvi ? "bvi" : " ");
Dave Barachba868bb2016-08-08 09:51:21 -0400420 }
Eyal Bari942402b2017-07-26 11:57:04 +0300421 else if (l2_input->xconnect)
John Lo4478d8e2018-01-12 17:15:25 -0500422 vlib_cli_output (vm, " L2 xconnect %U",
423 format_vnet_sw_if_index_name, vnm,
424 l2_input->output_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400425
John Lo4478d8e2018-01-12 17:15:25 -0500426 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400427 /* Display any IP4 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500428 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
429 1 /* honor unnumbered */,
430 ({
431 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
432 if (fib4->table_id)
433 vlib_cli_output (vm, " L3 %U/%d ip4 table-id %d fib-idx %d",
434 format_ip4_address, r4, ia->address_length,
435 fib4->table_id,
436 ip4_fib_index_from_table_id (fib4->table_id));
437 else
438 vlib_cli_output (vm, " L3 %U/%d",
439 format_ip4_address, r4, ia->address_length);
440 }));
441 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700442
John Lo4478d8e2018-01-12 17:15:25 -0500443 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400444 /* Display any IP6 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500445 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
446 1 /* honor unnumbered */,
447 ({
448 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
449 if (fib6->table_id)
450 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
451 format_ip6_address, r6, ia->address_length,
452 fib6->table_id,
453 ip6_fib_index_from_table_id (fib6->table_id));
454 else
455 vlib_cli_output (vm, " L3 %U/%d",
456 format_ip6_address, r6, ia->address_length);
457 }));
458 /* *INDENT-ON* */
Ole Troand7231612018-06-07 10:17:57 +0200459 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700460 }
Ole Troand7231612018-06-07 10:17:57 +0200461 else
462 {
463 vec_foreach (si, sorted_sis)
464 {
465 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
466 }
467 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700468
Dave Barachba868bb2016-08-08 09:51:21 -0400469done:
Ole Troand7231612018-06-07 10:17:57 +0200470 vec_free (sorted_sis);
471 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700472}
473
Dave Barachba868bb2016-08-08 09:51:21 -0400474/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700475VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
Dave Barach13ad1f02017-03-26 19:36:18 -0400476 .path = "show interface",
Dave Barach525c9d02018-05-26 10:48:55 -0400477 .short_help = "show interface [address|addr|features|feat] [<interface> [<interface> [..]]] [verbose]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700478 .function = show_sw_interfaces,
Steven Luongc5fa2b82019-04-25 11:19:49 -0700479 .is_mp_safe = 1,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700480};
Dave Barachba868bb2016-08-08 09:51:21 -0400481/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700482
483/* Root of all interface commands. */
Dave Barachba868bb2016-08-08 09:51:21 -0400484/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700485VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
486 .path = "interface",
487 .short_help = "Interface commands",
488};
Dave Barachba868bb2016-08-08 09:51:21 -0400489/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700490
Dave Barachba868bb2016-08-08 09:51:21 -0400491/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700492VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
493 .path = "set interface",
494 .short_help = "Interface commands",
495};
Dave Barachba868bb2016-08-08 09:51:21 -0400496/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700497
498static clib_error_t *
499clear_interface_counters (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400500 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700501{
Dave Barachba868bb2016-08-08 09:51:21 -0400502 vnet_main_t *vnm = vnet_get_main ();
503 vnet_interface_main_t *im = &vnm->interface_main;
504 vlib_simple_counter_main_t *sm;
505 vlib_combined_counter_main_t *cm;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400506 int j, n_counters;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700507
508 n_counters = vec_len (im->combined_sw_if_counters);
509
510 for (j = 0; j < n_counters; j++)
511 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400512 im = &vnm->interface_main;
513 cm = im->combined_sw_if_counters + j;
514 vlib_clear_combined_counters (cm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700515 }
516
517 n_counters = vec_len (im->sw_if_counters);
518
519 for (j = 0; j < n_counters; j++)
520 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400521 im = &vnm->interface_main;
522 sm = im->sw_if_counters + j;
523 vlib_clear_simple_counters (sm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700524 }
525
526 return 0;
527}
528
Billy McFalle9bac692017-08-11 14:05:11 -0400529/*?
530 * Clear the statistics for all interfaces (statistics associated with the
531 * '<em>show interface</em>' command).
532 *
533 * @cliexpar
534 * Example of how to clear the statistics for all interfaces:
535 * @cliexcmd{clear interfaces}
536 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400537/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700538VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
539 .path = "clear interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400540 .short_help = "clear interfaces",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700541 .function = clear_interface_counters,
542};
Dave Barachba868bb2016-08-08 09:51:21 -0400543/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700544
Chris Luke16bcf7d2016-09-01 14:31:46 -0400545/**
546 * Parse subinterface names.
547 *
Dave Barachba868bb2016-08-08 09:51:21 -0400548 * The following subinterface syntax is supported. The first two are for
549 * backwards compatability:
550 *
551 * <intf-name> <id>
552 * - a subinterface with the name <intf-name>.<id>. The subinterface
553 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
554 *
555 * <intf-name> <min_id>-<max_id>
556 * - a set of the above subinterfaces, repeating for each id
557 * in the range <min_id> to <max_id>
558 *
559 * In the following, exact-match semantics (i.e. the number of vlan tags on the
560 * packet must match the number of tags in the configuration) are used only if
561 * the keyword exact-match is present. Non-exact match is the default.
562 *
563 * <intf-name> <id> dot1q <outer_id> [exact-match]
564 * - a subinterface with the name <intf-name>.<id>. The subinterface
565 * is a single dot1q vlan with vlan id <outer_id>.
566 *
567 * <intf-name> <id> dot1q any [exact-match]
568 * - a subinterface with the name <intf-name>.<id>. The subinterface
569 * is a single dot1q vlan with any vlan id.
570 *
571 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
572 * - a subinterface with the name <intf-name>.<id>. The subinterface
573 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
574 * <inner_id>.
575 *
576 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
577 * - a subinterface with the name <intf-name>.<id>. The subinterface
578 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
579 *
580 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
581 *
582 * - a subinterface with the name <intf-name>.<id>. The subinterface
583 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
584 *
585 * For each of the above CLI, there is a duplicate that uses the keyword
586 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
587 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
588 * tagged packets the inner ethertype is always 0x8100. Also note that
589 * the dot1q and dot1ad naming spaces are independent, so it is legal to
590 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
591 *
592 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
593 * - a subinterface with the name <intf-name>.<id>. The subinterface
594 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
595 * id <inner_id>.
596 *
597 * <intf-name> <id> untagged
598 * - a subinterface with the name <intf-name>.<id>. The subinterface
599 * has no vlan tags. Only one can be specified per interface.
600 *
601 * <intf-name> <id> default
602 * - a subinterface with the name <intf-name>.<id>. This is associated
603 * with a packet that did not match any other configured subinterface
604 * on this interface. Only one can be specified per interface.
605 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700606
607static clib_error_t *
Dave Barachba868bb2016-08-08 09:51:21 -0400608parse_vlan_sub_interfaces (unformat_input_t * input,
609 vnet_sw_interface_t * template)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700610{
Dave Barachba868bb2016-08-08 09:51:21 -0400611 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700612 u32 inner_vlan, outer_vlan;
613
Dave Barachba868bb2016-08-08 09:51:21 -0400614 if (unformat (input, "any inner-dot1q any"))
615 {
616 template->sub.eth.flags.two_tags = 1;
617 template->sub.eth.flags.outer_vlan_id_any = 1;
618 template->sub.eth.flags.inner_vlan_id_any = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700619 }
Dave Barachba868bb2016-08-08 09:51:21 -0400620 else if (unformat (input, "any"))
621 {
622 template->sub.eth.flags.one_tag = 1;
623 template->sub.eth.flags.outer_vlan_id_any = 1;
624 }
625 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
626 {
627 template->sub.eth.flags.two_tags = 1;
628 template->sub.eth.flags.inner_vlan_id_any = 1;
629 template->sub.eth.outer_vlan_id = outer_vlan;
630 }
631 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
632 {
633 template->sub.eth.flags.two_tags = 1;
634 template->sub.eth.outer_vlan_id = outer_vlan;
635 template->sub.eth.inner_vlan_id = inner_vlan;
636 }
637 else if (unformat (input, "%d", &outer_vlan))
638 {
639 template->sub.eth.flags.one_tag = 1;
640 template->sub.eth.outer_vlan_id = outer_vlan;
641 }
642 else
643 {
644 error = clib_error_return (0, "expected dot1q config, got `%U'",
645 format_unformat_error, input);
646 goto done;
647 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700648
Dave Barachba868bb2016-08-08 09:51:21 -0400649 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
650 {
651 if (unformat (input, "exact-match"))
652 {
653 template->sub.eth.flags.exact_match = 1;
654 }
655 }
656
657done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700658 return error;
659}
660
661static clib_error_t *
662create_sub_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400663 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700664{
Dave Barachba868bb2016-08-08 09:51:21 -0400665 vnet_main_t *vnm = vnet_get_main ();
666 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700667 u32 hw_if_index, sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400668 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700669 u32 id, id_min, id_max;
670 vnet_sw_interface_t template;
671
672 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400673 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700674 {
675 error = clib_error_return (0, "unknown interface `%U'",
676 format_unformat_error, input);
677 goto done;
678 }
679
Dave Barachb7b92992018-10-17 10:38:51 -0400680 clib_memset (&template, 0, sizeof (template));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700681 template.sub.eth.raw_flags = 0;
682
Dave Barachba868bb2016-08-08 09:51:21 -0400683 if (unformat (input, "%d default", &id_min))
684 {
685 id_max = id_min;
686 template.sub.eth.flags.default_sub = 1;
687 }
688 else if (unformat (input, "%d untagged", &id_min))
689 {
690 id_max = id_min;
691 template.sub.eth.flags.no_tags = 1;
692 template.sub.eth.flags.exact_match = 1;
693 }
694 else if (unformat (input, "%d dot1q", &id_min))
695 {
696 /* parse dot1q config */
697 id_max = id_min;
698 error = parse_vlan_sub_interfaces (input, &template);
699 if (error)
700 goto done;
701 }
702 else if (unformat (input, "%d dot1ad", &id_min))
703 {
704 /* parse dot1ad config */
705 id_max = id_min;
706 template.sub.eth.flags.dot1ad = 1;
707 error = parse_vlan_sub_interfaces (input, &template);
708 if (error)
709 goto done;
710 }
711 else if (unformat (input, "%d-%d", &id_min, &id_max))
712 {
713 template.sub.eth.flags.one_tag = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400714 template.sub.eth.flags.exact_match = 1;
715 if (id_min > id_max)
716 goto id_error;
717 }
718 else if (unformat (input, "%d", &id_min))
719 {
720 id_max = id_min;
721 template.sub.eth.flags.one_tag = 1;
722 template.sub.eth.outer_vlan_id = id_min;
723 template.sub.eth.flags.exact_match = 1;
724 }
725 else
726 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700727 id_error:
728 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
729 format_unformat_error, input);
730 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400731 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700732
733 hi = vnet_get_hw_interface (vnm, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -0400734
Dave Barachba868bb2016-08-08 09:51:21 -0400735 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
736 {
737 error =
738 clib_error_return (0,
739 "not allowed as %v belong to a BondEthernet interface",
740 hi->name);
741 goto done;
742 }
John Lobcebbb92016-04-05 15:47:43 -0400743
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744 for (id = id_min; id <= id_max; id++)
745 {
Dave Barachba868bb2016-08-08 09:51:21 -0400746 uword *p;
747 vnet_interface_main_t *im = &vnm->interface_main;
748 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
749 u64 *kp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700750
751 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
752 if (p)
Dave Barachba868bb2016-08-08 09:51:21 -0400753 {
754 if (CLIB_DEBUG > 0)
755 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
756 hi->sw_if_index, id);
757 continue;
758 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700759
760 kp = clib_mem_alloc (sizeof (*kp));
761 *kp = sup_and_sub_key;
762
763 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Eyal Baric5b13602016-11-24 19:42:43 +0200764 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700765 template.sup_sw_if_index = hi->sw_if_index;
766 template.sub.id = id;
Eyal Baria4509cf2016-09-26 09:24:09 +0300767 if (id_min < id_max)
768 template.sub.eth.outer_vlan_id = id;
769
Ed Warnickecb9cada2015-12-08 15:45:58 -0700770 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400771 if (error)
772 goto done;
Dave Barach16ad6ae2016-07-28 17:55:30 -0400773
Ed Warnickecb9cada2015-12-08 15:45:58 -0700774 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
775 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400776 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
777 vnet_get_main (), sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700778 }
779
Dave Barachba868bb2016-08-08 09:51:21 -0400780done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700781 return error;
782}
783
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700784/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400785 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
786 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
787 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
788 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
789 * but this is not recommended.
790 *
791 * This command has several variations:
792 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
793 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
794 *
795 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
796 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
797 * match any other subinterfaces should be sent to this subinterface.
798 *
799 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
800 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
801 * to this subinterface.
802 *
803 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
804 * subinterfaces to handle a range of VLAN IDs.
805 *
806 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700807 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
Billy McFalle9bac692017-08-11 14:05:11 -0400808 * VLAN ID different from the '<em>subId</em>'.
809 *
810 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
811 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700812 * the inner VLAN ID.
Billy McFalle9bac692017-08-11 14:05:11 -0400813 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700814 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
Billy McFalle9bac692017-08-11 14:05:11 -0400815 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
816 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
817 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
818 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
819 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
820 * entered, then the default behavior is exact-match.
821 *
822 * Use the '<em>show interface</em>' command to display all subinterfaces.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700823 *
824 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400825 * @parblock
826 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
827 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700828 *
Billy McFalle9bac692017-08-11 14:05:11 -0400829 * The previous example is shorthand and is equivalent to:
830 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700831 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700832 *
Billy McFalle9bac692017-08-11 14:05:11 -0400833 * Example of how to create a subinterface number that is different from the VLAN ID:
834 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700835 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700836 *
Billy McFalle9bac692017-08-11 14:05:11 -0400837 * Examples of how to create q-in-q and q-in-any subinterfaces:
838 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
839 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700840 *
Billy McFalle9bac692017-08-11 14:05:11 -0400841 * Examples of how to create dot1ad interfaces:
842 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
843 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700844 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700845 *
Billy McFalle9bac692017-08-11 14:05:11 -0400846 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
847 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
848 * is non-exact match:
849 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700850 *
Billy McFalle9bac692017-08-11 14:05:11 -0400851 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
852 * is specified and only one VLAN is configured, but packet contains two VLANs:
853 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700854 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700855 *
Billy McFalle9bac692017-08-11 14:05:11 -0400856 * Example of how to created a subinterface to process untagged packets:
857 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
858 *
859 * Example of how to created a subinterface to process any packet with a VLAN ID that
860 * does not match any other subinterface:
861 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
862 *
863 * When subinterfaces are created, they are in the down state. Example of how to
864 * enable a newly created subinterface:
865 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
866 * @endparblock
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700867 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400868/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700869VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700870 .path = "create sub-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400871 .short_help = "create sub-interfaces <interface> "
872 "{<subId> [default|untagged]} | "
873 "{<subId>-<subId>} | "
874 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700875 .function = create_sub_interfaces,
876};
Dave Barachba868bb2016-08-08 09:51:21 -0400877/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700878
879static clib_error_t *
880set_state (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400881 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700882{
Dave Barachba868bb2016-08-08 09:51:21 -0400883 vnet_main_t *vnm = vnet_get_main ();
884 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700885 u32 sw_if_index, flags;
886
887 sw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400888 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700889 {
890 error = clib_error_return (0, "unknown interface `%U'",
891 format_unformat_error, input);
892 goto done;
893 }
894
Dave Barachba868bb2016-08-08 09:51:21 -0400895 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700896 {
897 error = clib_error_return (0, "unknown flags `%U'",
898 format_unformat_error, input);
899 goto done;
900 }
901
902 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
903 if (error)
904 goto done;
905
Dave Barachba868bb2016-08-08 09:51:21 -0400906done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700907 return error;
908}
909
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700910
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700911/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400912 * This command is used to change the admin state (up/down) of an interface.
913 *
914 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
915 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
916 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
917 * '<em>punt</em>' flag (interface is still down).
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700918 *
919 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400920 * Example of how to configure the admin state of an interface to '<em>up</em?':
921 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
922 * Example of how to configure the admin state of an interface to '<em>down</em?':
923 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700924 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400925/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700926VLIB_CLI_COMMAND (set_state_command, static) = {
927 .path = "set interface state",
Billy McFalle9bac692017-08-11 14:05:11 -0400928 .short_help = "set interface state <interface> [up|down|punt|enable]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700929 .function = set_state,
930};
Dave Barachba868bb2016-08-08 09:51:21 -0400931/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700932
933static clib_error_t *
934set_unnumbered (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400935 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700936{
Dave Barachba868bb2016-08-08 09:51:21 -0400937 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700938 u32 unnumbered_sw_if_index = ~0;
939 u32 inherit_from_sw_if_index = ~0;
940 int enable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700941
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700942 if (unformat (input, "%U use %U",
943 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
944 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700945 enable = 1;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700946 else if (unformat (input, "del %U",
947 unformat_vnet_sw_interface, vnm,
948 &unnumbered_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700949 enable = 0;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700950 else
951 return clib_error_return (0, "parse error '%U'",
952 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700953
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700954 if (~0 == unnumbered_sw_if_index)
955 return clib_error_return (0, "Specify the unnumbered interface");
956 if (enable && ~0 == inherit_from_sw_if_index)
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700957 return clib_error_return (0, "When enabling unnumbered specify the"
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700958 " IP enabled interface that it uses");
Neale Ranns898273f2017-03-18 02:57:38 -0700959
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700960 vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
961 inherit_from_sw_if_index, enable);
Neale Ranns898273f2017-03-18 02:57:38 -0700962
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700963 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700964}
965
Dave Barachba868bb2016-08-08 09:51:21 -0400966/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700967VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
968 .path = "set interface unnumbered",
Billy McFalle9bac692017-08-11 14:05:11 -0400969 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700970 .function = set_unnumbered,
971};
Dave Barachba868bb2016-08-08 09:51:21 -0400972/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700973
974
975
976static clib_error_t *
977set_hw_class (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400978 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700979{
Dave Barachba868bb2016-08-08 09:51:21 -0400980 vnet_main_t *vnm = vnet_get_main ();
981 vnet_interface_main_t *im = &vnm->interface_main;
982 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700983 u32 hw_if_index, hw_class_index;
984
985 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400986 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700987 {
988 error = clib_error_return (0, "unknown hardware interface `%U'",
989 format_unformat_error, input);
990 goto done;
991 }
992
Dave Barachba868bb2016-08-08 09:51:21 -0400993 if (!unformat_user (input, unformat_hash_string,
994 im->hw_interface_class_by_name, &hw_class_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700995 {
996 error = clib_error_return (0, "unknown hardware class `%U'",
997 format_unformat_error, input);
998 goto done;
999 }
1000
1001 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1002 if (error)
1003 goto done;
1004
Dave Barachba868bb2016-08-08 09:51:21 -04001005done:
Ed Warnickecb9cada2015-12-08 15:45:58 -07001006 return error;
1007}
1008
Dave Barachba868bb2016-08-08 09:51:21 -04001009/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001010VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1011 .path = "set interface hw-class",
1012 .short_help = "Set interface hardware class",
1013 .function = set_hw_class,
1014};
Dave Barachba868bb2016-08-08 09:51:21 -04001015/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001016
Dave Barachba868bb2016-08-08 09:51:21 -04001017static clib_error_t *
1018vnet_interface_cli_init (vlib_main_t * vm)
1019{
1020 return 0;
1021}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001022
1023VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1024
Dave Barachba868bb2016-08-08 09:51:21 -04001025static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07001026renumber_interface_command_fn (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001027 unformat_input_t * input,
1028 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001029{
1030 u32 hw_if_index;
1031 u32 new_dev_instance;
Dave Barachba868bb2016-08-08 09:51:21 -04001032 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001033 int rv;
1034
Dave Barachba868bb2016-08-08 09:51:21 -04001035 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001036 return clib_error_return (0, "unknown hardware interface `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001037 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001038
Dave Barachba868bb2016-08-08 09:51:21 -04001039 if (!unformat (input, "%d", &new_dev_instance))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001040 return clib_error_return (0, "new dev instance missing");
1041
1042 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1043
1044 switch (rv)
1045 {
1046 case 0:
1047 break;
1048
1049 default:
1050 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
Dave Barachba868bb2016-08-08 09:51:21 -04001051 rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001052
1053 }
1054
1055 return 0;
1056}
1057
1058
Dave Barachba868bb2016-08-08 09:51:21 -04001059/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001060VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1061 .path = "renumber interface",
Billy McFalle9bac692017-08-11 14:05:11 -04001062 .short_help = "renumber interface <interface> <new-dev-instance>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001063 .function = renumber_interface_command_fn,
1064};
Dave Barachba868bb2016-08-08 09:51:21 -04001065/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001066
Damjan Marion8358ff92016-04-15 14:26:00 +02001067static clib_error_t *
1068promiscuous_cmd (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001069 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion8358ff92016-04-15 14:26:00 +02001070{
Dave Barachba868bb2016-08-08 09:51:21 -04001071 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001072 u32 hw_if_index;
1073 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
Dave Barachba868bb2016-08-08 09:51:21 -04001074 ethernet_main_t *em = &ethernet_main;
1075 ethernet_interface_t *eif;
Damjan Marion8358ff92016-04-15 14:26:00 +02001076
1077 if (unformat (input, "on %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001078 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001079 ;
1080 else if (unformat (input, "off %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001081 unformat_ethernet_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001082 flags = 0;
1083 else
1084 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001085 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001086
1087 eif = ethernet_get_interface (em, hw_if_index);
1088 if (!eif)
1089 return clib_error_return (0, "not supported");
1090
1091 ethernet_set_flags (vnm, hw_if_index, flags);
1092 return 0;
1093}
1094
Dave Barachba868bb2016-08-08 09:51:21 -04001095/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001096VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1097 .path = "set interface promiscuous",
Billy McFalle9bac692017-08-11 14:05:11 -04001098 .short_help = "set interface promiscuous [on|off] <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001099 .function = promiscuous_cmd,
1100};
Dave Barachba868bb2016-08-08 09:51:21 -04001101/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001102
1103static clib_error_t *
1104mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1105{
Dave Barachba868bb2016-08-08 09:51:21 -04001106 vnet_main_t *vnm = vnet_get_main ();
Ole Troand7231612018-06-07 10:17:57 +02001107 u32 hw_if_index, sw_if_index, mtu;
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001108 ethernet_main_t *em = &ethernet_main;
Ole Troand7231612018-06-07 10:17:57 +02001109 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
Damjan Marion8358ff92016-04-15 14:26:00 +02001110
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001111 if (unformat (input, "%d %U", &mtu,
1112 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001113 {
Ole Troand7231612018-06-07 10:17:57 +02001114 /*
1115 * Change physical MTU on interface. Only supported for Ethernet
1116 * interfaces
1117 */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001118 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1119 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1120
1121 if (!eif)
1122 return clib_error_return (0, "not supported");
1123
1124 if (mtu < hi->min_supported_packet_bytes)
1125 return clib_error_return (0, "Invalid mtu (%d): "
1126 "must be >= min pkt bytes (%d)", mtu,
1127 hi->min_supported_packet_bytes);
1128
1129 if (mtu > hi->max_supported_packet_bytes)
1130 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1131 hi->max_supported_packet_bytes);
1132
1133 vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
Ole Troand7231612018-06-07 10:17:57 +02001134 goto done;
Damjan Marion8358ff92016-04-15 14:26:00 +02001135 }
Ole Troand7231612018-06-07 10:17:57 +02001136 else if (unformat (input, "packet %d %U", &mtu,
1137 unformat_vnet_sw_interface, vnm, &sw_if_index))
1138 /* Set default packet MTU (including L3 header */
1139 mtus[VNET_MTU_L3] = mtu;
1140 else if (unformat (input, "ip4 %d %U", &mtu,
1141 unformat_vnet_sw_interface, vnm, &sw_if_index))
1142 mtus[VNET_MTU_IP4] = mtu;
1143 else if (unformat (input, "ip6 %d %U", &mtu,
1144 unformat_vnet_sw_interface, vnm, &sw_if_index))
1145 mtus[VNET_MTU_IP6] = mtu;
1146 else if (unformat (input, "mpls %d %U", &mtu,
1147 unformat_vnet_sw_interface, vnm, &sw_if_index))
1148 mtus[VNET_MTU_MPLS] = mtu;
Damjan Marion8358ff92016-04-15 14:26:00 +02001149 else
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001150 return clib_error_return (0, "unknown input `%U'",
1151 format_unformat_error, input);
Ole Troand7231612018-06-07 10:17:57 +02001152
1153 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1154
1155done:
Damjan Marion8358ff92016-04-15 14:26:00 +02001156 return 0;
1157}
1158
Dave Barachba868bb2016-08-08 09:51:21 -04001159/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001160VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1161 .path = "set interface mtu",
Ole Troand7231612018-06-07 10:17:57 +02001162 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001163 .function = mtu_cmd,
1164};
Dave Barachba868bb2016-08-08 09:51:21 -04001165/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001166
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001167static clib_error_t *
Matthew Smithe0792fd2019-07-12 11:48:24 -05001168show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input,
1169 vlib_cli_command_t * cmd)
1170{
1171 vnet_main_t *vnm = vnet_get_main ();
1172 vnet_interface_main_t *im = &vnm->interface_main;
1173 ethernet_main_t *em = &ethernet_main;
1174 u32 sw_if_index = ~0;
1175 vnet_sw_interface_t *si, *sorted_sis = 0;
1176
1177 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1178 {
1179 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1180 vec_add1 (sorted_sis, si[0]);
1181 }
1182
1183 /* if an interface name was not passed, get all interfaces */
1184 if (vec_len (sorted_sis) == 0)
1185 {
1186 sorted_sis =
1187 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
1188 _vec_len (sorted_sis) = 0;
1189 /* *INDENT-OFF* */
1190 pool_foreach (si, im->sw_interfaces,
1191 ({
1192 int visible = vnet_swif_is_api_visible (si);
1193 if (visible)
1194 vec_add1 (sorted_sis, si[0]);}
1195 ));
1196 /* *INDENT-ON* */
1197 /* Sort by name. */
1198 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
1199 }
1200
1201 vec_foreach (si, sorted_sis)
1202 {
1203 vnet_sw_interface_t *sup_si;
1204 ethernet_interface_t *ei;
1205
1206 sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
1207 ei = ethernet_get_interface (em, sup_si->hw_if_index);
1208
1209 vlib_cli_output (vm, "%U (%s):",
1210 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
1211 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
1212 "up" : "dn");
1213
1214 if (ei && ei->secondary_addrs)
1215 {
1216 mac_address_t *sec_addr;
1217
1218 vec_foreach (sec_addr, ei->secondary_addrs)
1219 {
1220 vlib_cli_output (vm, " %U", format_mac_address_t, sec_addr);
1221 }
1222 }
1223 }
1224
1225 vec_free (sorted_sis);
1226 return 0;
1227}
1228
1229/*?
1230 * This command is used to display interface secondary mac addresses.
1231 *
1232 * @cliexpar
1233 * Example of how to display interface secondary mac addresses:
1234 * @cliexstart{show interface secondary-mac-address}
1235 * @cliexend
1236?*/
1237/* *INDENT-OFF* */
1238VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = {
1239 .path = "show interface secondary-mac-address",
1240 .short_help = "show interface secondary-mac-address [<interface>]",
1241 .function = show_interface_sec_mac_addr_fn,
1242};
1243/* *INDENT-ON* */
1244
1245static clib_error_t *
1246interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input,
1247 vlib_cli_command_t * cmd)
1248{
1249 vnet_main_t *vnm = vnet_get_main ();
1250 vnet_sw_interface_t *si = NULL;
1251 clib_error_t *error = 0;
1252 u32 sw_if_index = ~0;
1253 u8 mac[6] = { 0 };
1254 u8 is_add, is_del;
1255
1256 is_add = is_del = 0;
1257
1258 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1259 {
1260 error = clib_error_return (0, "unknown interface `%U'",
1261 format_unformat_error, input);
1262 goto done;
1263 }
1264 if (!unformat_user (input, unformat_ethernet_address, mac))
1265 {
1266 error = clib_error_return (0, "expected mac address `%U'",
1267 format_unformat_error, input);
1268 goto done;
1269 }
1270
1271 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1272 {
1273 if (unformat (input, "add"))
1274 is_add = 1;
1275 else if (unformat (input, "del"))
1276 is_del = 1;
1277 else
1278 break;
1279 }
1280
1281 if (is_add == is_del)
1282 {
1283 error = clib_error_return (0, "must choose one of add or del");
1284 goto done;
1285 }
1286
1287 si = vnet_get_sw_interface (vnm, sw_if_index);
1288 error =
1289 vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add);
1290
1291done:
1292 return error;
1293}
1294
1295/*?
1296 * The '<em>set interface secondary-mac-address </em>' command allows adding
1297 * or deleting extra MAC addresses on a given interface without changing the
1298 * default MAC address. This could allow packets sent to these MAC addresses
1299 * to be received without setting the interface to promiscuous mode.
1300 * Not all interfaces support this operation. The ones that do are mostly
1301 * hardware NICs, though virtio does also.
1302 *
1303 * @cliexpar
1304 * @parblock
1305 * Example of how to add a secondary MAC Address on an interface:
1306 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add}
1307 * Example of how to delete a secondary MAC address from an interface:
1308 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del}
1309 * @endparblock
1310?*/
1311/* *INDENT-OFF* */
1312VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = {
1313 .path = "set interface secondary-mac-address",
1314 .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]",
1315 .function = interface_add_del_mac_address,
1316};
1317/* *INDENT-ON* */
1318
1319static clib_error_t *
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001320set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1321 vlib_cli_command_t * cmd)
1322{
1323 vnet_main_t *vnm = vnet_get_main ();
Neale Rannsd867a7c2017-10-04 02:29:07 -07001324 vnet_sw_interface_t *si = NULL;
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001325 clib_error_t *error = 0;
1326 u32 sw_if_index = ~0;
John Lo62fcc0a2017-10-31 14:31:10 -04001327 u8 mac[6] = { 0 };
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001328
1329 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1330 {
1331 error = clib_error_return (0, "unknown interface `%U'",
1332 format_unformat_error, input);
1333 goto done;
1334 }
John Lo62fcc0a2017-10-31 14:31:10 -04001335 if (!unformat_user (input, unformat_ethernet_address, mac))
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001336 {
1337 error = clib_error_return (0, "expected mac address `%U'",
1338 format_unformat_error, input);
1339 goto done;
1340 }
Neale Rannsd867a7c2017-10-04 02:29:07 -07001341 si = vnet_get_sw_interface (vnm, sw_if_index);
1342 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001343done:
1344 return error;
1345}
1346
1347/*?
1348 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1349 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1350 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1351 *
1352 * @cliexpar
1353 * @parblock
1354 * Example of how to change MAC Address of interface:
1355 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1356 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1357 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1358 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1359 * @endparblock
1360?*/
1361/* *INDENT-OFF* */
1362VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1363 .path = "set interface mac address",
Billy McFalle9bac692017-08-11 14:05:11 -04001364 .short_help = "set interface mac address <interface> <mac-address>",
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001365 .function = set_interface_mac_address,
1366};
1367/* *INDENT-ON* */
1368
Dave Barach7be864a2016-11-28 11:41:35 -05001369static clib_error_t *
1370set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1371{
1372 vnet_main_t *vnm = vnet_get_main ();
1373 u32 sw_if_index = ~0;
1374 u8 *tag = 0;
1375
1376 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1377 vnm, &sw_if_index, &tag))
1378 return clib_error_return (0, "unknown input `%U'",
1379 format_unformat_error, input);
1380
1381 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1382
1383 return 0;
1384}
1385
1386/* *INDENT-OFF* */
1387VLIB_CLI_COMMAND (set_tag_command, static) = {
1388 .path = "set interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001389 .short_help = "set interface tag <interface> <tag>",
Dave Barach7be864a2016-11-28 11:41:35 -05001390 .function = set_tag,
1391};
1392/* *INDENT-ON* */
1393
1394static clib_error_t *
1395clear_tag (vlib_main_t * vm, unformat_input_t * input,
1396 vlib_cli_command_t * cmd)
1397{
1398 vnet_main_t *vnm = vnet_get_main ();
1399 u32 sw_if_index = ~0;
1400
1401 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1402 return clib_error_return (0, "unknown input `%U'",
1403 format_unformat_error, input);
1404
1405 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1406
1407 return 0;
1408}
1409
1410/* *INDENT-OFF* */
1411VLIB_CLI_COMMAND (clear_tag_command, static) = {
1412 .path = "clear interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001413 .short_help = "clear interface tag <interface>",
Dave Barach7be864a2016-11-28 11:41:35 -05001414 .function = clear_tag,
1415};
1416/* *INDENT-ON* */
1417
Damjan Marion44036902017-04-28 12:29:15 +02001418static clib_error_t *
Neale Ranns1855b8e2018-07-11 10:31:26 -07001419set_ip_directed_broadcast (vlib_main_t * vm,
1420 unformat_input_t * input, vlib_cli_command_t * cmd)
1421{
1422 vnet_main_t *vnm = vnet_get_main ();
1423 u32 sw_if_index = ~0;
1424 u8 enable = 0;
1425
1426 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1427 else if (unformat (input, "enable"))
1428 enable = 1;
1429 else if (unformat (input, "disable"))
1430 enable = 0;
1431 else
1432 return clib_error_return (0, "unknown input: `%U'",
1433 format_unformat_error, input);
1434
1435 if (~0 == sw_if_index)
1436 return clib_error_return (0, "specify an interface: `%U'",
1437 format_unformat_error, input);
1438
1439 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1440
1441 return 0;
1442}
1443
1444/*?
1445 * This command is used to enable/disable IP directed broadcast
1446 * If directed broadcast is enabled a packet sent to the interface's
1447 * subnet broadcast address will be sent L2 broadcast on the interface,
1448 * otherwise it is dropped.
1449 ?*/
1450/* *INDENT-OFF* */
1451VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1452 .path = "set interface ip directed-broadcast",
1453 .short_help = "set interface enable <interface> <enable|disable>",
1454 .function = set_ip_directed_broadcast,
1455};
1456/* *INDENT-ON* */
1457
1458static clib_error_t *
Stevene3a395c2017-05-09 16:19:50 -07001459set_hw_interface_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1460 u32 queue_id, vnet_hw_interface_rx_mode mode)
1461{
1462 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1463 vnet_device_class_t *dev_class =
1464 vnet_get_device_class (vnm, hw->dev_class_index);
1465 clib_error_t *error;
1466 vnet_hw_interface_rx_mode old_mode;
1467 int rv;
1468
Damjan Marion4e53a0d2017-06-21 14:29:44 +02001469 if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT)
1470 mode = hw->default_rx_mode;
1471
Stevene3a395c2017-05-09 16:19:50 -07001472 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &old_mode);
1473 switch (rv)
1474 {
1475 case 0:
1476 if (old_mode == mode)
1477 return 0; /* same rx-mode, no change */
1478 break;
1479 case VNET_API_ERROR_INVALID_INTERFACE:
1480 return clib_error_return (0, "invalid interface");
Stevenbd8a6112017-07-30 10:29:26 -07001481 case VNET_API_ERROR_INVALID_QUEUE:
1482 return clib_error_return (0, "invalid queue");
Stevene3a395c2017-05-09 16:19:50 -07001483 default:
1484 return clib_error_return (0, "unknown error");
1485 }
1486
1487 if (dev_class->rx_mode_change_function)
1488 {
1489 error = dev_class->rx_mode_change_function (vnm, hw_if_index, queue_id,
1490 mode);
1491 if (error)
1492 return (error);
1493 }
1494
1495 rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1496 switch (rv)
1497 {
1498 case 0:
1499 break;
1500 case VNET_API_ERROR_UNSUPPORTED:
1501 return clib_error_return (0, "unsupported");
1502 case VNET_API_ERROR_INVALID_INTERFACE:
1503 return clib_error_return (0, "invalid interface");
Stevenbd8a6112017-07-30 10:29:26 -07001504 case VNET_API_ERROR_INVALID_QUEUE:
1505 return clib_error_return (0, "invalid queue");
Stevene3a395c2017-05-09 16:19:50 -07001506 default:
1507 return clib_error_return (0, "unknown error");
1508 }
1509
1510 return 0;
1511}
1512
Stevenad8015b2017-10-29 22:10:46 -07001513clib_error_t *
1514set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1515 u8 queue_id_valid, u32 queue_id,
1516 vnet_hw_interface_rx_mode mode)
1517{
1518 clib_error_t *error = 0;
1519 vnet_hw_interface_t *hw;
1520 int i;
1521
1522 hw = vnet_get_hw_interface (vnm, hw_if_index);
1523
1524 if (queue_id_valid == 0)
1525 {
1526 for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1527 {
1528 error = set_hw_interface_rx_mode (vnm, hw_if_index, i, mode);
1529 if (error)
1530 break;
1531 }
1532 hw->default_rx_mode = mode;
1533 }
1534 else
1535 error = set_hw_interface_rx_mode (vnm, hw_if_index, queue_id, mode);
1536
1537 return (error);
1538}
1539
Stevene3a395c2017-05-09 16:19:50 -07001540static clib_error_t *
Damjan Marion44036902017-04-28 12:29:15 +02001541set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1542 vlib_cli_command_t * cmd)
1543{
1544 clib_error_t *error = 0;
1545 unformat_input_t _line_input, *line_input = &_line_input;
1546 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion44036902017-04-28 12:29:15 +02001547 u32 hw_if_index = (u32) ~ 0;
1548 u32 queue_id = (u32) ~ 0;
1549 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
Stevenad8015b2017-10-29 22:10:46 -07001550 u8 queue_id_valid = 0;
Dave Barach7be864a2016-11-28 11:41:35 -05001551
Damjan Marion44036902017-04-28 12:29:15 +02001552 if (!unformat_user (input, unformat_line_input, line_input))
1553 return 0;
1554
1555 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1556 {
1557 if (unformat
1558 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1559 ;
1560 else if (unformat (line_input, "queue %d", &queue_id))
Stevenad8015b2017-10-29 22:10:46 -07001561 queue_id_valid = 1;
Damjan Marion44036902017-04-28 12:29:15 +02001562 else if (unformat (line_input, "polling"))
1563 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
1564 else if (unformat (line_input, "interrupt"))
1565 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
1566 else if (unformat (line_input, "adaptive"))
1567 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
1568 else
1569 {
1570 error = clib_error_return (0, "parse error: '%U'",
1571 format_unformat_error, line_input);
1572 unformat_free (line_input);
1573 return error;
1574 }
1575 }
1576
1577 unformat_free (line_input);
1578
1579 if (hw_if_index == (u32) ~ 0)
1580 return clib_error_return (0, "please specify valid interface name");
1581
1582 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
1583 return clib_error_return (0, "please specify valid rx-mode");
1584
Stevenad8015b2017-10-29 22:10:46 -07001585 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1586 queue_id, mode);
Damjan Marion44036902017-04-28 12:29:15 +02001587
Stevene3a395c2017-05-09 16:19:50 -07001588 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001589}
1590
1591/*?
Billy McFalle9bac692017-08-11 14:05:11 -04001592 * This command is used to assign the RX packet processing mode (polling,
1593 * interrupt, adaptive) of the a given interface, and optionally a
1594 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1595 * is applied to all queues of the interface. Not all interfaces support
1596 * all modes. To display the current rx-mode use the command
1597 * '<em>show interface rx-placement</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001598 *
1599 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -04001600 * Example of how to assign rx-mode to all queues on an interface:
1601 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1602 * Example of how to assign rx-mode to one queue of an interface:
1603 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1604 * Example of how to display the rx-mode of all interfaces:
Damjan Marion44036902017-04-28 12:29:15 +02001605 * @cliexstart{show interface rx-placement}
1606 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001607 * node dpdk-input:
1608 * GigabitEthernet7/0/0 queue 0 (polling)
1609 * node vhost-user-input:
1610 * VirtualEthernet0/0/12 queue 0 (interrupt)
1611 * VirtualEthernet0/0/12 queue 2 (polling)
1612 * VirtualEthernet0/0/13 queue 0 (polling)
1613 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001614 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001615 * node dpdk-input:
1616 * GigabitEthernet7/0/1 queue 0 (polling)
1617 * node vhost-user-input:
1618 * VirtualEthernet0/0/12 queue 1 (polling)
1619 * VirtualEthernet0/0/12 queue 3 (polling)
1620 * VirtualEthernet0/0/13 queue 1 (polling)
1621 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001622 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001623?*/
1624/* *INDENT-OFF* */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001625VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
Damjan Marion44036902017-04-28 12:29:15 +02001626 .path = "set interface rx-mode",
1627 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1628 .function = set_interface_rx_mode,
1629};
1630/* *INDENT-ON* */
1631
1632static clib_error_t *
1633show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1634 vlib_cli_command_t * cmd)
1635{
1636 u8 *s = 0;
1637 vnet_main_t *vnm = vnet_get_main ();
1638 vnet_device_input_runtime_t *rt;
1639 vnet_device_and_queue_t *dq;
1640 vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
1641 uword si;
1642 int index = 0;
1643
1644 /* *INDENT-OFF* */
1645 foreach_vlib_main (({
1646 clib_bitmap_foreach (si, pn->sibling_bitmap,
1647 ({
1648 rt = vlib_node_get_runtime_data (this_vlib_main, si);
1649
1650 if (vec_len (rt->devices_and_queues))
1651 s = format (s, " node %U:\n", format_vlib_node_name, vm, si);
1652
1653 vec_foreach (dq, rt->devices_and_queues)
1654 {
Steven9d6d9892017-06-30 07:15:02 -07001655 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm,
1656 dq->hw_if_index);
Damjan Marion44036902017-04-28 12:29:15 +02001657 s = format (s, " %U queue %u (%U)\n",
Steven9d6d9892017-06-30 07:15:02 -07001658 format_vnet_sw_if_index_name, vnm, hi->sw_if_index,
Damjan Marion44036902017-04-28 12:29:15 +02001659 dq->queue_id,
1660 format_vnet_hw_interface_rx_mode, dq->mode);
1661 }
1662 }));
1663 if (vec_len (s) > 0)
1664 {
Steven84f36cb2018-09-26 10:44:54 -07001665 vlib_cli_output(vm, "Thread %u (%s):\n%v", index,
Damjan Marion44036902017-04-28 12:29:15 +02001666 vlib_worker_threads[index].name, s);
1667 vec_reset_length (s);
1668 }
1669 index++;
1670 }));
1671 /* *INDENT-ON* */
1672
1673 vec_free (s);
1674 return 0;
1675}
1676
Billy McFalle9bac692017-08-11 14:05:11 -04001677/*?
1678 * This command is used to display the interface and queue worker
1679 * thread placement.
1680 *
1681 * @cliexpar
1682 * Example of how to display the interface placement:
1683 * @cliexstart{show interface rx-placement}
1684 * Thread 1 (vpp_wk_0):
1685 * node dpdk-input:
1686 * GigabitEthernet7/0/0 queue 0 (polling)
1687 * node vhost-user-input:
1688 * VirtualEthernet0/0/12 queue 0 (polling)
1689 * VirtualEthernet0/0/12 queue 2 (polling)
1690 * VirtualEthernet0/0/13 queue 0 (polling)
1691 * VirtualEthernet0/0/13 queue 2 (polling)
1692 * Thread 2 (vpp_wk_1):
1693 * node dpdk-input:
1694 * GigabitEthernet7/0/1 queue 0 (polling)
1695 * node vhost-user-input:
1696 * VirtualEthernet0/0/12 queue 1 (polling)
1697 * VirtualEthernet0/0/12 queue 3 (polling)
1698 * VirtualEthernet0/0/13 queue 1 (polling)
1699 * VirtualEthernet0/0/13 queue 3 (polling)
1700 * @cliexend
1701?*/
Damjan Marion44036902017-04-28 12:29:15 +02001702/* *INDENT-OFF* */
1703VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1704 .path = "show interface rx-placement",
1705 .short_help = "show interface rx-placement",
1706 .function = show_interface_rx_placement_fn,
1707};
1708/* *INDENT-ON* */
1709
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001710clib_error_t *
1711set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1712 u32 thread_index, u8 is_main)
Damjan Marion44036902017-04-28 12:29:15 +02001713{
Damjan Marion44036902017-04-28 12:29:15 +02001714 vnet_main_t *vnm = vnet_get_main ();
1715 vnet_device_main_t *vdm = &vnet_device_main;
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001716 clib_error_t *error = 0;
1717 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
Damjan Marion44036902017-04-28 12:29:15 +02001718 int rv;
1719
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001720 if (is_main)
1721 thread_index = 0;
1722 else
1723 thread_index += vdm->first_worker_thread_index;
Damjan Marion44036902017-04-28 12:29:15 +02001724
1725 if (thread_index > vdm->last_worker_thread_index)
1726 return clib_error_return (0,
1727 "please specify valid worker thread or main");
1728
1729 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode);
1730
1731 if (rv)
1732 return clib_error_return (0, "not found");
1733
1734 rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id);
1735
1736 if (rv)
1737 return clib_error_return (0, "not found");
1738
1739 vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id,
1740 thread_index);
1741 vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1742
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001743 return (error);
1744}
1745
1746static clib_error_t *
1747set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input,
1748 vlib_cli_command_t * cmd)
1749{
1750 clib_error_t *error = 0;
1751 unformat_input_t _line_input, *line_input = &_line_input;
1752 vnet_main_t *vnm = vnet_get_main ();
1753 u32 hw_if_index = (u32) ~ 0;
1754 u32 queue_id = (u32) 0;
1755 u32 thread_index = (u32) ~ 0;
1756 u8 is_main = 0;
1757
1758 if (!unformat_user (input, unformat_line_input, line_input))
1759 return 0;
1760
1761 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1762 {
1763 if (unformat
1764 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1765 ;
1766 else if (unformat (line_input, "queue %d", &queue_id))
1767 ;
1768 else if (unformat (line_input, "main", &thread_index))
1769 is_main = 1;
1770 else if (unformat (line_input, "worker %d", &thread_index))
1771 ;
1772 else
1773 {
1774 error = clib_error_return (0, "parse error: '%U'",
1775 format_unformat_error, line_input);
1776 unformat_free (line_input);
1777 return error;
1778 }
1779 }
1780
1781 unformat_free (line_input);
1782
1783 if (hw_if_index == (u32) ~ 0)
1784 return clib_error_return (0, "please specify valid interface name");
1785
1786 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1787 is_main);
1788
1789 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001790}
1791
1792/*?
1793 * This command is used to assign a given interface, and optionally a
1794 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
Billy McFalle9bac692017-08-11 14:05:11 -04001795 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1796 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001797 *
1798 * @cliexpar
1799 * Example of how to display the interface placement:
Billy McFalle9bac692017-08-11 14:05:11 -04001800 * @cliexstart{show interface rx-placement}
Damjan Marion44036902017-04-28 12:29:15 +02001801 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001802 * node dpdk-input:
1803 * GigabitEthernet7/0/0 queue 0 (polling)
1804 * node vhost-user-input:
1805 * VirtualEthernet0/0/12 queue 0 (polling)
1806 * VirtualEthernet0/0/12 queue 2 (polling)
1807 * VirtualEthernet0/0/13 queue 0 (polling)
1808 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001809 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001810 * node dpdk-input:
1811 * GigabitEthernet7/0/1 queue 0 (polling)
1812 * node vhost-user-input:
1813 * VirtualEthernet0/0/12 queue 1 (polling)
1814 * VirtualEthernet0/0/12 queue 3 (polling)
1815 * VirtualEthernet0/0/13 queue 1 (polling)
1816 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001817 * @cliexend
Billy McFalle9bac692017-08-11 14:05:11 -04001818 * Example of how to assign a interface and queue to a worker thread:
1819 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1820 * Example of how to display the interface placement:
1821 * @cliexstart{show interface rx-placement}
1822 * Thread 1 (vpp_wk_0):
1823 * node dpdk-input:
1824 * GigabitEthernet7/0/0 queue 0 (polling)
1825 * node vhost-user-input:
1826 * VirtualEthernet0/0/12 queue 0 (polling)
1827 * VirtualEthernet0/0/12 queue 1 (polling)
1828 * VirtualEthernet0/0/12 queue 2 (polling)
1829 * VirtualEthernet0/0/13 queue 0 (polling)
1830 * VirtualEthernet0/0/13 queue 2 (polling)
1831 * Thread 2 (vpp_wk_1):
1832 * node dpdk-input:
1833 * GigabitEthernet7/0/1 queue 0 (polling)
1834 * node vhost-user-input:
1835 * VirtualEthernet0/0/12 queue 3 (polling)
1836 * VirtualEthernet0/0/13 queue 1 (polling)
1837 * VirtualEthernet0/0/13 queue 3 (polling)
1838 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001839?*/
1840/* *INDENT-OFF* */
1841VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1842 .path = "set interface rx-placement",
Billy McFalle9bac692017-08-11 14:05:11 -04001843 .short_help = "set interface rx-placement <interface> [queue <n>] "
Damjan Marion6f9ac652017-06-15 19:01:31 +02001844 "[worker <n> | main]",
Damjan Marion44036902017-04-28 12:29:15 +02001845 .function = set_interface_rx_placement,
Damjan Marion6f9ac652017-06-15 19:01:31 +02001846 .is_mp_safe = 1,
Damjan Marion44036902017-04-28 12:29:15 +02001847};
Damjan Marion44036902017-04-28 12:29:15 +02001848/* *INDENT-ON* */
Dave Barach5ecd5a52019-02-25 15:27:28 -05001849
Dave Barach33909772019-09-23 10:27:27 -04001850static u8 *
1851format_vnet_pcap (u8 * s, va_list * args)
1852{
1853 vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *);
1854 int type = va_arg (*args, int);
1855 int printed = 0;
1856
1857 if (type == 0)
1858 {
1859 if (pp->pcap_rx_enable)
1860 {
1861 s = format (s, "rx");
1862 printed = 1;
1863 }
1864 if (pp->pcap_tx_enable)
1865 {
1866 if (printed)
1867 s = format (s, " and ");
1868 s = format (s, "tx");
1869 printed = 1;
1870 }
1871 if (pp->pcap_drop_enable)
1872 {
1873 if (printed)
1874 s = format (s, " and ");
1875 s = format (s, "drop");
1876 printed = 1;
1877 }
1878 return s;
1879 }
1880 s = format (s, "unknown type %d!", type);
1881 return s;
1882}
1883
1884
Dave Barachb97641c2019-09-09 16:38:17 -04001885int
1886vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
1887{
1888 vlib_main_t *vm = vlib_get_main ();
Dave Barach33909772019-09-23 10:27:27 -04001889 vnet_pcap_t *pp = &vm->pcap;
Dave Barachb97641c2019-09-09 16:38:17 -04001890 pcap_main_t *pm = &pp->pcap_main;
Dave Barachf5667c32019-09-25 11:27:46 -04001891 vnet_classify_main_t *cm = &vnet_classify_main;
1892 vnet_classify_filter_set_t *set = 0;
Dave Barachb97641c2019-09-09 16:38:17 -04001893
1894 if (a->status)
1895 {
Dave Barach33909772019-09-23 10:27:27 -04001896 if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04001897 {
1898 vlib_cli_output
Dave Barach33909772019-09-23 10:27:27 -04001899 (vm, "pcap %U dispatch capture enabled: %d of %d pkts...",
1900 format_vnet_pcap, pp, 0 /* print type */ ,
Dave Barachb97641c2019-09-09 16:38:17 -04001901 pm->n_packets_captured, pm->n_packets_to_capture);
1902 vlib_cli_output (vm, "capture to file %s", pm->file_name);
1903 }
1904 else
Dave Barach33909772019-09-23 10:27:27 -04001905 vlib_cli_output (vm, "pcap dispatch capture disabled");
1906
Dave Barachb97641c2019-09-09 16:38:17 -04001907 return 0;
1908 }
1909
1910 /* Consistency checks */
1911
1912 /* Enable w/ capture already enabled not allowed */
Dave Barach33909772019-09-23 10:27:27 -04001913 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
1914 && (a->rx_enable + a->tx_enable + a->drop_enable))
Dave Barachb97641c2019-09-09 16:38:17 -04001915 return VNET_API_ERROR_INVALID_VALUE;
1916
1917 /* Disable capture with capture already disabled, not interesting */
Dave Barach33909772019-09-23 10:27:27 -04001918 if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) == 0)
1919 && ((a->rx_enable + a->tx_enable + a->drop_enable == 0)))
Dave Barachb97641c2019-09-09 16:38:17 -04001920 return VNET_API_ERROR_VALUE_EXIST;
1921
1922 /* Change number of packets to capture while capturing */
Dave Barach33909772019-09-23 10:27:27 -04001923 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
1924 && (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04001925 && (pm->n_packets_to_capture != a->packets_to_capture))
1926 return VNET_API_ERROR_INVALID_VALUE_2;
1927
Dave Barachf5667c32019-09-25 11:27:46 -04001928 set = pool_elt_at_index (cm->filter_sets, cm->filter_set_by_sw_if_index[0]);
1929
Dave Barach33909772019-09-23 10:27:27 -04001930 /* Classify filter specified, but no classify filter configured */
Dave Barachf5667c32019-09-25 11:27:46 -04001931 if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter &&
1932 (set->table_indices[0] == ~0))
Dave Barach9137e542019-09-13 17:47:50 -04001933 return VNET_API_ERROR_NO_SUCH_LABEL;
1934
Dave Barach33909772019-09-23 10:27:27 -04001935 if (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04001936 {
Dave Barach33909772019-09-23 10:27:27 -04001937 /* Sanity check max bytes per pkt */
1938 if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000)
1939 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
1940
Dave Barachb97641c2019-09-09 16:38:17 -04001941 /* Clean up from previous run, if any */
1942 vec_free (pm->file_name);
1943 vec_free (pm->pcap_data);
1944 memset (pm, 0, sizeof (*pm));
1945
1946 vec_validate_aligned (vnet_trace_dummy, 2048, CLIB_CACHE_LINE_BYTES);
1947 if (pm->lock == 0)
1948 clib_spinlock_init (&(pm->lock));
1949
1950 if (a->filename == 0)
Dave Barach33909772019-09-23 10:27:27 -04001951 {
1952 u8 *stem = 0;
1953
1954 if (a->rx_enable)
1955 stem = format (stem, "rx");
1956 if (a->tx_enable)
1957 stem = format (stem, "tx");
1958 if (a->drop_enable)
1959 stem = format (stem, "drop");
1960 a->filename = format (0, "/tmp/%s.pcap%c", stem, 0);
1961 vec_free (stem);
1962 }
Dave Barachb97641c2019-09-09 16:38:17 -04001963
1964 pm->file_name = (char *) a->filename;
1965 pm->n_packets_captured = 0;
1966 pm->packet_type = PCAP_PACKET_TYPE_ethernet;
1967 pm->n_packets_to_capture = a->packets_to_capture;
1968 pp->pcap_sw_if_index = a->sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04001969 if (a->filter)
Dave Barachf5667c32019-09-25 11:27:46 -04001970 pp->filter_classify_table_index = set->table_indices[0];
Dave Barach9137e542019-09-13 17:47:50 -04001971 else
1972 pp->filter_classify_table_index = ~0;
Dave Barach33909772019-09-23 10:27:27 -04001973 pp->pcap_rx_enable = a->rx_enable;
1974 pp->pcap_tx_enable = a->tx_enable;
1975 pp->pcap_drop_enable = a->drop_enable;
1976 pp->max_bytes_per_pkt = a->max_bytes_per_pkt;
Dave Barachb97641c2019-09-09 16:38:17 -04001977 }
1978 else
1979 {
Dave Barach33909772019-09-23 10:27:27 -04001980 pp->pcap_rx_enable = 0;
1981 pp->pcap_tx_enable = 0;
1982 pp->pcap_drop_enable = 0;
Dave Barachf5667c32019-09-25 11:27:46 -04001983 pp->filter_classify_table_index = ~0;
Dave Barachb97641c2019-09-09 16:38:17 -04001984 if (pm->n_packets_captured)
1985 {
1986 clib_error_t *error;
1987 pm->n_packets_to_capture = pm->n_packets_captured;
1988 vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
1989 pm->n_packets_captured, pm->file_name);
1990 error = pcap_write (pm);
Andrew Yourtchenko4da15062019-09-11 14:14:43 +00001991 if (pm->flags & PCAP_MAIN_INIT_DONE)
Dave Barachb97641c2019-09-09 16:38:17 -04001992 pcap_close (pm);
1993 /* Report I/O errors... */
1994 if (error)
1995 {
1996 clib_error_report (error);
1997 return VNET_API_ERROR_SYSCALL_ERROR_1;
1998 }
1999 return 0;
2000 }
2001 else
2002 return VNET_API_ERROR_NO_SUCH_ENTRY;
2003 }
2004
2005 return 0;
2006}
2007
2008static clib_error_t *
Dave Barach33909772019-09-23 10:27:27 -04002009pcap_trace_command_fn (vlib_main_t * vm,
2010 unformat_input_t * input, vlib_cli_command_t * cmd)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002011{
Dave Barach5ecd5a52019-02-25 15:27:28 -05002012 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barachb97641c2019-09-09 16:38:17 -04002013 vnet_pcap_dispatch_trace_args_t _a, *a = &_a;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002014 vnet_main_t *vnm = vnet_get_main ();
Dave Barachb97641c2019-09-09 16:38:17 -04002015 u8 *filename = 0;
2016 u32 max = 1000;
Dave Barach33909772019-09-23 10:27:27 -04002017 u32 max_bytes_per_pkt = 512;
Dave Barachb97641c2019-09-09 16:38:17 -04002018 int rv;
Dave Barach33909772019-09-23 10:27:27 -04002019 int rx_enable = 0;
2020 int tx_enable = 0;
2021 int drop_enable = 0;
Dave Barachb97641c2019-09-09 16:38:17 -04002022 int status = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002023 int filter = 0;
Dave Barachf5667c32019-09-25 11:27:46 -04002024 u32 sw_if_index = ~0;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002025
2026 /* Get a line of input. */
2027 if (!unformat_user (input, unformat_line_input, line_input))
2028 return 0;
2029
2030 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2031 {
Dave Barach33909772019-09-23 10:27:27 -04002032 if (unformat (line_input, "rx"))
2033 rx_enable = 1;
2034 else if (unformat (line_input, "tx"))
2035 tx_enable = 1;
2036 else if (unformat (line_input, "drop"))
2037 drop_enable = 1;
2038 else if (unformat (line_input, "off"))
2039 rx_enable = tx_enable = drop_enable = 0;
2040 else if (unformat (line_input, "max-bytes-per-pkt %u",
2041 &max_bytes_per_pkt))
Dave Barachb97641c2019-09-09 16:38:17 -04002042 ;
2043 else if (unformat (line_input, "max %d", &max))
2044 ;
2045 else if (unformat (line_input, "packets-to-capture %d", &max))
2046 ;
2047 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
2048 &filename))
2049 ;
2050 else if (unformat (line_input, "status %=", &status, 1))
2051 ;
2052 else if (unformat (line_input, "intfc %U",
2053 unformat_vnet_sw_interface, vnm, &sw_if_index))
2054 ;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002055 else if (unformat (line_input, "intfc any"))
Dave Barachb97641c2019-09-09 16:38:17 -04002056 sw_if_index = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002057 else if (unformat (line_input, "filter"))
2058 filter = 1;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002059 else
2060 {
Dave Barachb97641c2019-09-09 16:38:17 -04002061 return clib_error_return (0, "unknown input `%U'",
2062 format_unformat_error, line_input);
Dave Barach5ecd5a52019-02-25 15:27:28 -05002063 }
2064 }
Dave Barachb97641c2019-09-09 16:38:17 -04002065
Dave Barach5ecd5a52019-02-25 15:27:28 -05002066 unformat_free (line_input);
2067
Dave Barachb97641c2019-09-09 16:38:17 -04002068 /* no need for memset (a, 0, sizeof (*a)), set all fields here. */
2069 a->filename = filename;
Dave Barach33909772019-09-23 10:27:27 -04002070 a->rx_enable = rx_enable;
2071 a->tx_enable = tx_enable;
2072 a->drop_enable = drop_enable;
Dave Barachb97641c2019-09-09 16:38:17 -04002073 a->status = status;
2074 a->packets_to_capture = max;
Dave Barachb97641c2019-09-09 16:38:17 -04002075 a->sw_if_index = sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04002076 a->filter = filter;
Dave Barach33909772019-09-23 10:27:27 -04002077 a->max_bytes_per_pkt = max_bytes_per_pkt;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002078
Dave Barachb97641c2019-09-09 16:38:17 -04002079 rv = vnet_pcap_dispatch_trace_configure (a);
2080
2081 switch (rv)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002082 {
Dave Barachb97641c2019-09-09 16:38:17 -04002083 case 0:
2084 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002085
Dave Barachb97641c2019-09-09 16:38:17 -04002086 case VNET_API_ERROR_INVALID_VALUE:
2087 return clib_error_return (0, "dispatch trace already enabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002088
Dave Barachb97641c2019-09-09 16:38:17 -04002089 case VNET_API_ERROR_VALUE_EXIST:
2090 return clib_error_return (0, "dispatch trace already disabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002091
Dave Barachb97641c2019-09-09 16:38:17 -04002092 case VNET_API_ERROR_INVALID_VALUE_2:
2093 return clib_error_return
2094 (0, "can't change number of records to capture while tracing...");
2095
2096 case VNET_API_ERROR_SYSCALL_ERROR_1:
2097 return clib_error_return (0, "I/O writing trace capture...");
2098
2099 case VNET_API_ERROR_NO_SUCH_ENTRY:
2100 return clib_error_return (0, "No packets captured...");
2101
Dave Barach33909772019-09-23 10:27:27 -04002102 case VNET_API_ERROR_INVALID_MEMORY_SIZE:
2103 return clib_error_return (0,
2104 "Max bytes per pkt must be > 32, < 9000...");
2105
Dave Barach9137e542019-09-13 17:47:50 -04002106 case VNET_API_ERROR_NO_SUCH_LABEL:
2107 return clib_error_return
2108 (0, "No classify filter configured, see 'classify filter...'");
2109
Dave Barachb97641c2019-09-09 16:38:17 -04002110 default:
2111 vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
2112 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002113 }
Dave Barachb97641c2019-09-09 16:38:17 -04002114 return 0;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002115}
2116
Dave Barach5ecd5a52019-02-25 15:27:28 -05002117/*?
2118 * This command is used to start or stop a packet capture, or show
Dave Barach33909772019-09-23 10:27:27 -04002119 * the status of packet capture.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002120 *
2121 * This command has the following optional parameters:
2122 *
Dave Barach33909772019-09-23 10:27:27 -04002123 *
2124 * - <b>rx</b> - Capture received packets
2125 *
2126 * - <b>tx</b> - Capture transmitted packets
2127 *
2128 * - <b>drop</b> - Capture dropped packets
2129 *
2130 * - <b>off</b> - Stop capturing packets, write results to the specified file
Dave Barach5ecd5a52019-02-25 15:27:28 -05002131 *
2132 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
2133 * of packets have been received, buffer is flushed to file. Once another
2134 * '<em>nn</em>' number of packets have been received, buffer is flushed
2135 * to file, overwriting previous write. If not entered, value defaults
2136 * to 100. Can only be updated if packet capture is off.
2137 *
Dave Barach33909772019-09-23 10:27:27 -04002138 * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture
2139 * for each packet. Must be >= 32, <= 9000.
2140 *
2141 * - <b>intfc <interface-name>|any</b> - Used to specify a given interface,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002142 * or use '<em>any</em>' to run packet capture on all interfaces.
2143 * '<em>any</em>' is the default if not provided. Settings from a previous
2144 * packet capture are preserved, so '<em>any</em>' can be used to reset
2145 * the interface setting.
2146 *
Dave Barachf5667c32019-09-25 11:27:46 -04002147 * - <b>filter</b> - Use the pcap rx / tx / drop trace filter, which
2148 * must be configured. Use <b>classify filter pcap...</b> to configure the
2149 * filter. The filter will only be executed if the per-interface or
2150 * any-interface tests fail.
2151 *
Dave Barach5ecd5a52019-02-25 15:27:28 -05002152 * - <b>file <name></b> - Used to specify the output filename. The file will
2153 * be placed in the '<em>/tmp</em>' directory, so only the filename is
2154 * supported. Directory should not be entered. If file already exists, file
Dave Barach33909772019-09-23 10:27:27 -04002155 * will be overwritten. If no filename is provided, the file will be
2156 * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc.
2157 * Can only be updated if packet capture is off.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002158 *
2159 * - <b>status</b> - Displays the current status and configured attributes
2160 * associated with a packet capture. If packet capture is in progress,
2161 * '<em>status</em>' also will return the number of packets currently in
2162 * the local buffer. All additional attributes entered on command line
2163 * with '<em>status</em>' will be ignored and not applied.
2164 *
2165 * @cliexpar
2166 * Example of how to display the status of a tx packet capture when off:
Dave Barach33909772019-09-23 10:27:27 -04002167 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002168 * max is 100, for any interface to file /tmp/vpe.pcap
2169 * pcap tx capture is off...
2170 * @cliexend
2171 * Example of how to start a tx packet capture:
Dave Barach33909772019-09-23 10:27:27 -04002172 * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file vppTest.pcap}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002173 * @cliexend
2174 * Example of how to display the status of a tx packet capture in progress:
Dave Barach33909772019-09-23 10:27:27 -04002175 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002176 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
2177 * pcap tx capture is on: 20 of 35 pkts...
2178 * @cliexend
2179 * Example of how to stop a tx packet capture:
Dave Barach33909772019-09-23 10:27:27 -04002180 * @cliexstart{pcap trace off}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002181 * captured 21 pkts...
2182 * saved to /tmp/vppTest.pcap...
2183 * @cliexend
2184?*/
2185/* *INDENT-OFF* */
2186
2187VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
Dave Barach33909772019-09-23 10:27:27 -04002188 .path = "pcap trace",
Dave Barach5ecd5a52019-02-25 15:27:28 -05002189 .short_help =
Dave Barachf5667c32019-09-25 11:27:46 -04002190 "pcap trace rx tx drop off [max <nn>] [intfc <interface>|any] [file <name>] [status] [max-bytes-per-pkt <nnnn>][filter]",
Dave Barach33909772019-09-23 10:27:27 -04002191 .function = pcap_trace_command_fn,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002192};
2193/* *INDENT-ON* */
2194
Dave Barachba868bb2016-08-08 09:51:21 -04002195/*
2196 * fd.io coding-style-patch-verification: ON
2197 *
2198 * Local Variables:
2199 * eval: (c-set-style "gnu")
2200 * End:
2201 */