blob: 9de674a10fa13445c9ac2b8b69a9cf4640ab356a [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;
Jon Loeliger9485d992019-11-08 15:05:23 -0600280 u8 show_vtr = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400281 int verbose = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700282
Dave Barach525c9d02018-05-26 10:48:55 -0400283 /*
284 * Get a line of input. Won't work if the user typed
285 * "show interface" and nothing more.
286 */
287 if (unformat_user (input, unformat_line_input, linput))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700288 {
Dave Barach525c9d02018-05-26 10:48:55 -0400289 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700290 {
Dave Barach525c9d02018-05-26 10:48:55 -0400291 /* See if user wants to show specific interface */
292 if (unformat
293 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
294 {
295 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
296 vec_add1 (sorted_sis, si[0]);
297 }
298 else if (unformat (linput, "address") || unformat (linput, "addr"))
299 show_addresses = 1;
300 else if (unformat (linput, "features") || unformat (linput, "feat"))
301 show_features = 1;
302 else if (unformat (linput, "tag"))
303 show_tag = 1;
Jon Loeliger9485d992019-11-08 15:05:23 -0600304 else if (unformat (linput, "vtr"))
305 show_vtr = 1;
Dave Barach525c9d02018-05-26 10:48:55 -0400306 else if (unformat (linput, "verbose"))
307 verbose = 1;
308 else
309 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400310 vec_free (sorted_sis);
Dave Barach525c9d02018-05-26 10:48:55 -0400311 error = clib_error_return (0, "unknown input `%U'",
312 format_unformat_error, linput);
313 goto done;
314 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700315 }
Dave Barach525c9d02018-05-26 10:48:55 -0400316 unformat_free (linput);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700317 }
Jon Loeliger9485d992019-11-08 15:05:23 -0600318 if (show_features || show_tag || show_vtr)
Damjan Marion22311502016-10-28 20:30:15 +0200319 {
320 if (sw_if_index == ~(u32) 0)
Dave Barach8fdde3c2019-05-17 10:46:40 -0400321 {
322 vec_free (sorted_sis);
323 return clib_error_return (0, "Interface not specified...");
324 }
Dave Barach7be864a2016-11-28 11:41:35 -0500325 }
Damjan Marion22311502016-10-28 20:30:15 +0200326
Dave Barach7be864a2016-11-28 11:41:35 -0500327 if (show_features)
328 {
Dave Barach525c9d02018-05-26 10:48:55 -0400329 vnet_interface_features_show (vm, sw_if_index, verbose);
Eyal Bari942402b2017-07-26 11:57:04 +0300330
331 l2_input_config_t *l2_input = l2input_intf_config (sw_if_index);
332 u32 fb = l2_input->feature_bitmap;
333 /* intf input features are masked by bridge domain */
334 if (l2_input->bridge)
335 fb &= l2input_bd_config (l2_input->bd_index)->feature_bitmap;
Neale Ranns5d9df1d2018-11-09 08:19:27 -0800336 vlib_cli_output (vm, "\nl2-input:\n%U", format_l2_input_features, fb,
337 1);
Eyal Bari942402b2017-07-26 11:57:04 +0300338
339 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
340 vlib_cli_output (vm, "\nl2-output:");
341 if (l2_output->out_vtr_flag)
342 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
343 vlib_cli_output (vm, "%U", format_l2_output_features,
Neale Ranns5d9df1d2018-11-09 08:19:27 -0800344 l2_output->feature_bitmap, 1);
Dave Barach8fdde3c2019-05-17 10:46:40 -0400345 vec_free (sorted_sis);
Damjan Marion22311502016-10-28 20:30:15 +0200346 return 0;
347 }
Dave Barach7be864a2016-11-28 11:41:35 -0500348 if (show_tag)
349 {
350 u8 *tag;
351 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
352 vlib_cli_output (vm, "%U: %s",
353 format_vnet_sw_if_index_name, vnm, sw_if_index,
354 tag ? (char *) tag : "(none)");
Dave Barach8fdde3c2019-05-17 10:46:40 -0400355 vec_free (sorted_sis);
Dave Barach7be864a2016-11-28 11:41:35 -0500356 return 0;
357 }
Damjan Marion22311502016-10-28 20:30:15 +0200358
Jon Loeliger9485d992019-11-08 15:05:23 -0600359 /*
360 * Show vlan tag rewrite data for one interface.
361 */
362 if (show_vtr)
363 {
364 u32 vtr_op = L2_VTR_DISABLED;
365 u32 push_dot1q = 0, tag1 = 0, tag2 = 0;
366
367 if (l2vtr_get (vm, vnm, sw_if_index,
368 &vtr_op, &push_dot1q, &tag1, &tag2) != 0)
369 {
370 vlib_cli_output (vm, "%U: Problem getting vlan tag-rewrite data",
371 format_vnet_sw_if_index_name, vnm, sw_if_index);
372 return 0;
373 }
374 vlib_cli_output (vm, "%U: VTR %0U",
375 format_vnet_sw_if_index_name, vnm, sw_if_index,
376 format_vtr, vtr_op, push_dot1q, tag1, tag2);
377 return 0;
378 }
379
Ed Warnickecb9cada2015-12-08 15:45:58 -0700380 if (!show_addresses)
Dave Barachba868bb2016-08-08 09:51:21 -0400381 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700382
Dave Barachba868bb2016-08-08 09:51:21 -0400383 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700384 {
385 /* Gather interfaces. */
Dave Barachba868bb2016-08-08 09:51:21 -0400386 sorted_sis =
387 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700388 _vec_len (sorted_sis) = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400389 /* *INDENT-OFF* */
390 pool_foreach (si, im->sw_interfaces,
391 ({
392 int visible = vnet_swif_is_api_visible (si);
393 if (visible)
394 vec_add1 (sorted_sis, si[0]);}
395 ));
Ole Troand7231612018-06-07 10:17:57 +0200396 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700397 /* Sort by name. */
398 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
399 }
400
401 if (show_addresses)
402 {
403 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400404 {
Dave Barachba868bb2016-08-08 09:51:21 -0400405 ip4_main_t *im4 = &ip4_main;
406 ip6_main_t *im6 = &ip6_main;
407 ip_lookup_main_t *lm4 = &im4->lookup_main;
408 ip_lookup_main_t *lm6 = &im6->lookup_main;
409 ip_interface_address_t *ia = 0;
Dave Barachba868bb2016-08-08 09:51:21 -0400410 u32 fib_index4 = 0, fib_index6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700411
Dave Barachba868bb2016-08-08 09:51:21 -0400412 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
413 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
414 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700415
Dave Barachba868bb2016-08-08 09:51:21 -0400416 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
417 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
418 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700419
John Lo4478d8e2018-01-12 17:15:25 -0500420 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
421 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700422
Dave Barachba868bb2016-08-08 09:51:21 -0400423 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
424 vlib_cli_output
425 (vm, "%U (%s): \n unnumbered, use %U",
John Lo4478d8e2018-01-12 17:15:25 -0500426 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400427 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
428 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400429 else
John Lo4478d8e2018-01-12 17:15:25 -0500430 vlib_cli_output
431 (vm, "%U (%s):",
432 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
433 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700434
Eyal Bari942402b2017-07-26 11:57:04 +0300435 /* Display any L2 info */
436 l2_input_config_t *l2_input = l2input_intf_config (si->sw_if_index);
437 if (l2_input->bridge)
Dave Barachba868bb2016-08-08 09:51:21 -0400438 {
John Lo4478d8e2018-01-12 17:15:25 -0500439 bd_main_t *bdm = &bd_main;
Eyal Bari942402b2017-07-26 11:57:04 +0300440 u32 bd_id = l2input_main.bd_configs[l2_input->bd_index].bd_id;
John Lo4478d8e2018-01-12 17:15:25 -0500441 vlib_cli_output (vm, " L2 bridge bd-id %d idx %d shg %d %s",
442 bd_id, bd_find_index (bdm, bd_id), l2_input->shg,
443 l2_input->bvi ? "bvi" : " ");
Dave Barachba868bb2016-08-08 09:51:21 -0400444 }
Eyal Bari942402b2017-07-26 11:57:04 +0300445 else if (l2_input->xconnect)
John Lo4478d8e2018-01-12 17:15:25 -0500446 vlib_cli_output (vm, " L2 xconnect %U",
447 format_vnet_sw_if_index_name, vnm,
448 l2_input->output_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400449
John Lo4478d8e2018-01-12 17:15:25 -0500450 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400451 /* Display any IP4 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500452 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
453 1 /* honor unnumbered */,
454 ({
455 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
456 if (fib4->table_id)
457 vlib_cli_output (vm, " L3 %U/%d ip4 table-id %d fib-idx %d",
458 format_ip4_address, r4, ia->address_length,
459 fib4->table_id,
460 ip4_fib_index_from_table_id (fib4->table_id));
461 else
462 vlib_cli_output (vm, " L3 %U/%d",
463 format_ip4_address, r4, ia->address_length);
464 }));
465 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700466
John Lo4478d8e2018-01-12 17:15:25 -0500467 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400468 /* Display any IP6 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500469 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
470 1 /* honor unnumbered */,
471 ({
472 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
473 if (fib6->table_id)
474 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
475 format_ip6_address, r6, ia->address_length,
476 fib6->table_id,
477 ip6_fib_index_from_table_id (fib6->table_id));
478 else
479 vlib_cli_output (vm, " L3 %U/%d",
480 format_ip6_address, r6, ia->address_length);
481 }));
482 /* *INDENT-ON* */
Ole Troand7231612018-06-07 10:17:57 +0200483 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700484 }
Ole Troand7231612018-06-07 10:17:57 +0200485 else
486 {
487 vec_foreach (si, sorted_sis)
488 {
489 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
490 }
491 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700492
Dave Barachba868bb2016-08-08 09:51:21 -0400493done:
Ole Troand7231612018-06-07 10:17:57 +0200494 vec_free (sorted_sis);
495 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700496}
497
Dave Barachba868bb2016-08-08 09:51:21 -0400498/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700499VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
Dave Barach13ad1f02017-03-26 19:36:18 -0400500 .path = "show interface",
Jon Loeliger9485d992019-11-08 15:05:23 -0600501 .short_help = "show interface [address|addr|features|feat|vtr] [<interface> [<interface> [..]]] [verbose]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700502 .function = show_sw_interfaces,
Steven Luongc5fa2b82019-04-25 11:19:49 -0700503 .is_mp_safe = 1,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700504};
Dave Barachba868bb2016-08-08 09:51:21 -0400505/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700506
507/* Root of all interface commands. */
Dave Barachba868bb2016-08-08 09:51:21 -0400508/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700509VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
510 .path = "interface",
511 .short_help = "Interface commands",
512};
Dave Barachba868bb2016-08-08 09:51:21 -0400513/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700514
Dave Barachba868bb2016-08-08 09:51:21 -0400515/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700516VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
517 .path = "set interface",
518 .short_help = "Interface commands",
519};
Dave Barachba868bb2016-08-08 09:51:21 -0400520/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700521
522static clib_error_t *
523clear_interface_counters (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400524 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700525{
Dave Barachba868bb2016-08-08 09:51:21 -0400526 vnet_main_t *vnm = vnet_get_main ();
527 vnet_interface_main_t *im = &vnm->interface_main;
528 vlib_simple_counter_main_t *sm;
529 vlib_combined_counter_main_t *cm;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400530 int j, n_counters;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700531
532 n_counters = vec_len (im->combined_sw_if_counters);
533
534 for (j = 0; j < n_counters; j++)
535 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400536 im = &vnm->interface_main;
537 cm = im->combined_sw_if_counters + j;
538 vlib_clear_combined_counters (cm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700539 }
540
541 n_counters = vec_len (im->sw_if_counters);
542
543 for (j = 0; j < n_counters; j++)
544 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400545 im = &vnm->interface_main;
546 sm = im->sw_if_counters + j;
547 vlib_clear_simple_counters (sm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700548 }
549
550 return 0;
551}
552
Billy McFalle9bac692017-08-11 14:05:11 -0400553/*?
554 * Clear the statistics for all interfaces (statistics associated with the
555 * '<em>show interface</em>' command).
556 *
557 * @cliexpar
558 * Example of how to clear the statistics for all interfaces:
559 * @cliexcmd{clear interfaces}
560 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400561/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700562VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
563 .path = "clear interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400564 .short_help = "clear interfaces",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700565 .function = clear_interface_counters,
566};
Dave Barachba868bb2016-08-08 09:51:21 -0400567/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700568
Chris Luke16bcf7d2016-09-01 14:31:46 -0400569/**
570 * Parse subinterface names.
571 *
Dave Barachba868bb2016-08-08 09:51:21 -0400572 * The following subinterface syntax is supported. The first two are for
573 * backwards compatability:
574 *
575 * <intf-name> <id>
576 * - a subinterface with the name <intf-name>.<id>. The subinterface
577 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
578 *
579 * <intf-name> <min_id>-<max_id>
580 * - a set of the above subinterfaces, repeating for each id
581 * in the range <min_id> to <max_id>
582 *
583 * In the following, exact-match semantics (i.e. the number of vlan tags on the
584 * packet must match the number of tags in the configuration) are used only if
585 * the keyword exact-match is present. Non-exact match is the default.
586 *
587 * <intf-name> <id> dot1q <outer_id> [exact-match]
588 * - a subinterface with the name <intf-name>.<id>. The subinterface
589 * is a single dot1q vlan with vlan id <outer_id>.
590 *
591 * <intf-name> <id> dot1q any [exact-match]
592 * - a subinterface with the name <intf-name>.<id>. The subinterface
593 * is a single dot1q vlan with any vlan id.
594 *
595 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
596 * - a subinterface with the name <intf-name>.<id>. The subinterface
597 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
598 * <inner_id>.
599 *
600 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
601 * - a subinterface with the name <intf-name>.<id>. The subinterface
602 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
603 *
604 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
605 *
606 * - a subinterface with the name <intf-name>.<id>. The subinterface
607 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
608 *
609 * For each of the above CLI, there is a duplicate that uses the keyword
610 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
611 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
612 * tagged packets the inner ethertype is always 0x8100. Also note that
613 * the dot1q and dot1ad naming spaces are independent, so it is legal to
614 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
615 *
616 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
617 * - a subinterface with the name <intf-name>.<id>. The subinterface
618 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
619 * id <inner_id>.
620 *
621 * <intf-name> <id> untagged
622 * - a subinterface with the name <intf-name>.<id>. The subinterface
623 * has no vlan tags. Only one can be specified per interface.
624 *
625 * <intf-name> <id> default
626 * - a subinterface with the name <intf-name>.<id>. This is associated
627 * with a packet that did not match any other configured subinterface
628 * on this interface. Only one can be specified per interface.
629 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700630
631static clib_error_t *
Dave Barachba868bb2016-08-08 09:51:21 -0400632parse_vlan_sub_interfaces (unformat_input_t * input,
633 vnet_sw_interface_t * template)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700634{
Dave Barachba868bb2016-08-08 09:51:21 -0400635 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700636 u32 inner_vlan, outer_vlan;
637
Dave Barachba868bb2016-08-08 09:51:21 -0400638 if (unformat (input, "any inner-dot1q any"))
639 {
640 template->sub.eth.flags.two_tags = 1;
641 template->sub.eth.flags.outer_vlan_id_any = 1;
642 template->sub.eth.flags.inner_vlan_id_any = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700643 }
Dave Barachba868bb2016-08-08 09:51:21 -0400644 else if (unformat (input, "any"))
645 {
646 template->sub.eth.flags.one_tag = 1;
647 template->sub.eth.flags.outer_vlan_id_any = 1;
648 }
649 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
650 {
651 template->sub.eth.flags.two_tags = 1;
652 template->sub.eth.flags.inner_vlan_id_any = 1;
653 template->sub.eth.outer_vlan_id = outer_vlan;
654 }
655 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
656 {
657 template->sub.eth.flags.two_tags = 1;
658 template->sub.eth.outer_vlan_id = outer_vlan;
659 template->sub.eth.inner_vlan_id = inner_vlan;
660 }
661 else if (unformat (input, "%d", &outer_vlan))
662 {
663 template->sub.eth.flags.one_tag = 1;
664 template->sub.eth.outer_vlan_id = outer_vlan;
665 }
666 else
667 {
668 error = clib_error_return (0, "expected dot1q config, got `%U'",
669 format_unformat_error, input);
670 goto done;
671 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700672
Dave Barachba868bb2016-08-08 09:51:21 -0400673 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
674 {
675 if (unformat (input, "exact-match"))
676 {
677 template->sub.eth.flags.exact_match = 1;
678 }
679 }
680
681done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700682 return error;
683}
684
685static clib_error_t *
686create_sub_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400687 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700688{
Dave Barachba868bb2016-08-08 09:51:21 -0400689 vnet_main_t *vnm = vnet_get_main ();
690 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700691 u32 hw_if_index, sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400692 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700693 u32 id, id_min, id_max;
694 vnet_sw_interface_t template;
695
696 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400697 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700698 {
699 error = clib_error_return (0, "unknown interface `%U'",
700 format_unformat_error, input);
701 goto done;
702 }
703
Dave Barachb7b92992018-10-17 10:38:51 -0400704 clib_memset (&template, 0, sizeof (template));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700705 template.sub.eth.raw_flags = 0;
706
Dave Barachba868bb2016-08-08 09:51:21 -0400707 if (unformat (input, "%d default", &id_min))
708 {
709 id_max = id_min;
710 template.sub.eth.flags.default_sub = 1;
711 }
712 else if (unformat (input, "%d untagged", &id_min))
713 {
714 id_max = id_min;
715 template.sub.eth.flags.no_tags = 1;
716 template.sub.eth.flags.exact_match = 1;
717 }
718 else if (unformat (input, "%d dot1q", &id_min))
719 {
720 /* parse dot1q config */
721 id_max = id_min;
722 error = parse_vlan_sub_interfaces (input, &template);
723 if (error)
724 goto done;
725 }
726 else if (unformat (input, "%d dot1ad", &id_min))
727 {
728 /* parse dot1ad config */
729 id_max = id_min;
730 template.sub.eth.flags.dot1ad = 1;
731 error = parse_vlan_sub_interfaces (input, &template);
732 if (error)
733 goto done;
734 }
735 else if (unformat (input, "%d-%d", &id_min, &id_max))
736 {
737 template.sub.eth.flags.one_tag = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400738 template.sub.eth.flags.exact_match = 1;
739 if (id_min > id_max)
740 goto id_error;
741 }
742 else if (unformat (input, "%d", &id_min))
743 {
744 id_max = id_min;
745 template.sub.eth.flags.one_tag = 1;
746 template.sub.eth.outer_vlan_id = id_min;
747 template.sub.eth.flags.exact_match = 1;
748 }
749 else
750 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700751 id_error:
752 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
753 format_unformat_error, input);
754 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400755 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700756
757 hi = vnet_get_hw_interface (vnm, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -0400758
Dave Barachba868bb2016-08-08 09:51:21 -0400759 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
760 {
761 error =
762 clib_error_return (0,
763 "not allowed as %v belong to a BondEthernet interface",
764 hi->name);
765 goto done;
766 }
John Lobcebbb92016-04-05 15:47:43 -0400767
Ed Warnickecb9cada2015-12-08 15:45:58 -0700768 for (id = id_min; id <= id_max; id++)
769 {
Dave Barachba868bb2016-08-08 09:51:21 -0400770 uword *p;
771 vnet_interface_main_t *im = &vnm->interface_main;
772 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
773 u64 *kp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700774
775 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
776 if (p)
Dave Barachba868bb2016-08-08 09:51:21 -0400777 {
778 if (CLIB_DEBUG > 0)
779 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
780 hi->sw_if_index, id);
781 continue;
782 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700783
784 kp = clib_mem_alloc (sizeof (*kp));
785 *kp = sup_and_sub_key;
786
787 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Eyal Baric5b13602016-11-24 19:42:43 +0200788 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700789 template.sup_sw_if_index = hi->sw_if_index;
790 template.sub.id = id;
Eyal Baria4509cf2016-09-26 09:24:09 +0300791 if (id_min < id_max)
792 template.sub.eth.outer_vlan_id = id;
793
Ed Warnickecb9cada2015-12-08 15:45:58 -0700794 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400795 if (error)
796 goto done;
Dave Barach16ad6ae2016-07-28 17:55:30 -0400797
Ed Warnickecb9cada2015-12-08 15:45:58 -0700798 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
799 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400800 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
801 vnet_get_main (), sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700802 }
803
Dave Barachba868bb2016-08-08 09:51:21 -0400804done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700805 return error;
806}
807
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700808/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400809 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
810 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
811 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
812 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
813 * but this is not recommended.
814 *
815 * This command has several variations:
816 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
817 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
818 *
819 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
820 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
821 * match any other subinterfaces should be sent to this subinterface.
822 *
823 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
824 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
825 * to this subinterface.
826 *
827 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
828 * subinterfaces to handle a range of VLAN IDs.
829 *
830 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700831 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
Billy McFalle9bac692017-08-11 14:05:11 -0400832 * VLAN ID different from the '<em>subId</em>'.
833 *
834 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
835 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700836 * the inner VLAN ID.
Billy McFalle9bac692017-08-11 14:05:11 -0400837 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700838 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
Billy McFalle9bac692017-08-11 14:05:11 -0400839 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
840 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
841 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
842 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
843 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
844 * entered, then the default behavior is exact-match.
845 *
846 * Use the '<em>show interface</em>' command to display all subinterfaces.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700847 *
848 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400849 * @parblock
850 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
851 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700852 *
Billy McFalle9bac692017-08-11 14:05:11 -0400853 * The previous example is shorthand and is equivalent to:
854 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700855 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700856 *
Billy McFalle9bac692017-08-11 14:05:11 -0400857 * Example of how to create a subinterface number that is different from the VLAN ID:
858 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700859 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700860 *
Billy McFalle9bac692017-08-11 14:05:11 -0400861 * Examples of how to create q-in-q and q-in-any subinterfaces:
862 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
863 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700864 *
Billy McFalle9bac692017-08-11 14:05:11 -0400865 * Examples of how to create dot1ad interfaces:
866 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
867 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700868 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700869 *
Billy McFalle9bac692017-08-11 14:05:11 -0400870 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
871 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
872 * is non-exact match:
873 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700874 *
Billy McFalle9bac692017-08-11 14:05:11 -0400875 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
876 * is specified and only one VLAN is configured, but packet contains two VLANs:
877 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700878 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700879 *
Billy McFalle9bac692017-08-11 14:05:11 -0400880 * Example of how to created a subinterface to process untagged packets:
881 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
882 *
883 * Example of how to created a subinterface to process any packet with a VLAN ID that
884 * does not match any other subinterface:
885 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
886 *
887 * When subinterfaces are created, they are in the down state. Example of how to
888 * enable a newly created subinterface:
889 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
890 * @endparblock
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700891 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400892/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700893VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700894 .path = "create sub-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400895 .short_help = "create sub-interfaces <interface> "
896 "{<subId> [default|untagged]} | "
897 "{<subId>-<subId>} | "
898 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700899 .function = create_sub_interfaces,
900};
Dave Barachba868bb2016-08-08 09:51:21 -0400901/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700902
903static clib_error_t *
904set_state (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400905 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700906{
Dave Barachba868bb2016-08-08 09:51:21 -0400907 vnet_main_t *vnm = vnet_get_main ();
908 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700909 u32 sw_if_index, flags;
910
911 sw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400912 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700913 {
914 error = clib_error_return (0, "unknown interface `%U'",
915 format_unformat_error, input);
916 goto done;
917 }
918
Dave Barachba868bb2016-08-08 09:51:21 -0400919 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700920 {
921 error = clib_error_return (0, "unknown flags `%U'",
922 format_unformat_error, input);
923 goto done;
924 }
925
926 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
927 if (error)
928 goto done;
929
Dave Barachba868bb2016-08-08 09:51:21 -0400930done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700931 return error;
932}
933
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700934
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700935/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400936 * This command is used to change the admin state (up/down) of an interface.
937 *
938 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
939 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
940 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
941 * '<em>punt</em>' flag (interface is still down).
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700942 *
943 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400944 * Example of how to configure the admin state of an interface to '<em>up</em?':
945 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
946 * Example of how to configure the admin state of an interface to '<em>down</em?':
947 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700948 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400949/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700950VLIB_CLI_COMMAND (set_state_command, static) = {
951 .path = "set interface state",
Billy McFalle9bac692017-08-11 14:05:11 -0400952 .short_help = "set interface state <interface> [up|down|punt|enable]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700953 .function = set_state,
954};
Dave Barachba868bb2016-08-08 09:51:21 -0400955/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700956
957static clib_error_t *
958set_unnumbered (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400959 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700960{
Dave Barachba868bb2016-08-08 09:51:21 -0400961 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700962 u32 unnumbered_sw_if_index = ~0;
963 u32 inherit_from_sw_if_index = ~0;
964 int enable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700965
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700966 if (unformat (input, "%U use %U",
967 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
968 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700969 enable = 1;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700970 else if (unformat (input, "del %U",
971 unformat_vnet_sw_interface, vnm,
972 &unnumbered_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700973 enable = 0;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700974 else
975 return clib_error_return (0, "parse error '%U'",
976 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700977
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700978 if (~0 == unnumbered_sw_if_index)
979 return clib_error_return (0, "Specify the unnumbered interface");
980 if (enable && ~0 == inherit_from_sw_if_index)
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700981 return clib_error_return (0, "When enabling unnumbered specify the"
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700982 " IP enabled interface that it uses");
Neale Ranns898273f2017-03-18 02:57:38 -0700983
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700984 vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
985 inherit_from_sw_if_index, enable);
Neale Ranns898273f2017-03-18 02:57:38 -0700986
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700987 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700988}
989
Dave Barachba868bb2016-08-08 09:51:21 -0400990/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700991VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
992 .path = "set interface unnumbered",
Billy McFalle9bac692017-08-11 14:05:11 -0400993 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700994 .function = set_unnumbered,
995};
Dave Barachba868bb2016-08-08 09:51:21 -0400996/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700997
998
999
1000static clib_error_t *
1001set_hw_class (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001002 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001003{
Dave Barachba868bb2016-08-08 09:51:21 -04001004 vnet_main_t *vnm = vnet_get_main ();
1005 vnet_interface_main_t *im = &vnm->interface_main;
1006 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001007 u32 hw_if_index, hw_class_index;
1008
1009 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -04001010 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001011 {
1012 error = clib_error_return (0, "unknown hardware interface `%U'",
1013 format_unformat_error, input);
1014 goto done;
1015 }
1016
Dave Barachba868bb2016-08-08 09:51:21 -04001017 if (!unformat_user (input, unformat_hash_string,
1018 im->hw_interface_class_by_name, &hw_class_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001019 {
1020 error = clib_error_return (0, "unknown hardware class `%U'",
1021 format_unformat_error, input);
1022 goto done;
1023 }
1024
1025 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1026 if (error)
1027 goto done;
1028
Dave Barachba868bb2016-08-08 09:51:21 -04001029done:
Ed Warnickecb9cada2015-12-08 15:45:58 -07001030 return error;
1031}
1032
Dave Barachba868bb2016-08-08 09:51:21 -04001033/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001034VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1035 .path = "set interface hw-class",
1036 .short_help = "Set interface hardware class",
1037 .function = set_hw_class,
1038};
Dave Barachba868bb2016-08-08 09:51:21 -04001039/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001040
Dave Barachba868bb2016-08-08 09:51:21 -04001041static clib_error_t *
1042vnet_interface_cli_init (vlib_main_t * vm)
1043{
1044 return 0;
1045}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001046
1047VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1048
Dave Barachba868bb2016-08-08 09:51:21 -04001049static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07001050renumber_interface_command_fn (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001051 unformat_input_t * input,
1052 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001053{
1054 u32 hw_if_index;
1055 u32 new_dev_instance;
Dave Barachba868bb2016-08-08 09:51:21 -04001056 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001057 int rv;
1058
Dave Barachba868bb2016-08-08 09:51:21 -04001059 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001060 return clib_error_return (0, "unknown hardware interface `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001061 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001062
Dave Barachba868bb2016-08-08 09:51:21 -04001063 if (!unformat (input, "%d", &new_dev_instance))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001064 return clib_error_return (0, "new dev instance missing");
1065
1066 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1067
1068 switch (rv)
1069 {
1070 case 0:
1071 break;
1072
1073 default:
1074 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
Dave Barachba868bb2016-08-08 09:51:21 -04001075 rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001076
1077 }
1078
1079 return 0;
1080}
1081
1082
Dave Barachba868bb2016-08-08 09:51:21 -04001083/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001084VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1085 .path = "renumber interface",
Billy McFalle9bac692017-08-11 14:05:11 -04001086 .short_help = "renumber interface <interface> <new-dev-instance>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001087 .function = renumber_interface_command_fn,
1088};
Dave Barachba868bb2016-08-08 09:51:21 -04001089/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001090
Damjan Marion8358ff92016-04-15 14:26:00 +02001091static clib_error_t *
1092promiscuous_cmd (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001093 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion8358ff92016-04-15 14:26:00 +02001094{
Dave Barachba868bb2016-08-08 09:51:21 -04001095 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001096 u32 hw_if_index;
1097 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
Dave Barachba868bb2016-08-08 09:51:21 -04001098 ethernet_main_t *em = &ethernet_main;
1099 ethernet_interface_t *eif;
Damjan Marion8358ff92016-04-15 14:26:00 +02001100
1101 if (unformat (input, "on %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001102 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001103 ;
1104 else if (unformat (input, "off %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001105 unformat_ethernet_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001106 flags = 0;
1107 else
1108 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001109 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001110
1111 eif = ethernet_get_interface (em, hw_if_index);
1112 if (!eif)
1113 return clib_error_return (0, "not supported");
1114
1115 ethernet_set_flags (vnm, hw_if_index, flags);
1116 return 0;
1117}
1118
Dave Barachba868bb2016-08-08 09:51:21 -04001119/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001120VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1121 .path = "set interface promiscuous",
Billy McFalle9bac692017-08-11 14:05:11 -04001122 .short_help = "set interface promiscuous [on|off] <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001123 .function = promiscuous_cmd,
1124};
Dave Barachba868bb2016-08-08 09:51:21 -04001125/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001126
1127static clib_error_t *
1128mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1129{
Dave Barachba868bb2016-08-08 09:51:21 -04001130 vnet_main_t *vnm = vnet_get_main ();
Ole Troand7231612018-06-07 10:17:57 +02001131 u32 hw_if_index, sw_if_index, mtu;
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001132 ethernet_main_t *em = &ethernet_main;
Ole Troand7231612018-06-07 10:17:57 +02001133 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
Damjan Marion8358ff92016-04-15 14:26:00 +02001134
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001135 if (unformat (input, "%d %U", &mtu,
1136 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001137 {
Ole Troand7231612018-06-07 10:17:57 +02001138 /*
1139 * Change physical MTU on interface. Only supported for Ethernet
1140 * interfaces
1141 */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001142 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1143 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1144
1145 if (!eif)
1146 return clib_error_return (0, "not supported");
1147
1148 if (mtu < hi->min_supported_packet_bytes)
1149 return clib_error_return (0, "Invalid mtu (%d): "
1150 "must be >= min pkt bytes (%d)", mtu,
1151 hi->min_supported_packet_bytes);
1152
1153 if (mtu > hi->max_supported_packet_bytes)
1154 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1155 hi->max_supported_packet_bytes);
1156
1157 vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
Ole Troand7231612018-06-07 10:17:57 +02001158 goto done;
Damjan Marion8358ff92016-04-15 14:26:00 +02001159 }
Ole Troand7231612018-06-07 10:17:57 +02001160 else if (unformat (input, "packet %d %U", &mtu,
1161 unformat_vnet_sw_interface, vnm, &sw_if_index))
1162 /* Set default packet MTU (including L3 header */
1163 mtus[VNET_MTU_L3] = mtu;
1164 else if (unformat (input, "ip4 %d %U", &mtu,
1165 unformat_vnet_sw_interface, vnm, &sw_if_index))
1166 mtus[VNET_MTU_IP4] = mtu;
1167 else if (unformat (input, "ip6 %d %U", &mtu,
1168 unformat_vnet_sw_interface, vnm, &sw_if_index))
1169 mtus[VNET_MTU_IP6] = mtu;
1170 else if (unformat (input, "mpls %d %U", &mtu,
1171 unformat_vnet_sw_interface, vnm, &sw_if_index))
1172 mtus[VNET_MTU_MPLS] = mtu;
Damjan Marion8358ff92016-04-15 14:26:00 +02001173 else
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001174 return clib_error_return (0, "unknown input `%U'",
1175 format_unformat_error, input);
Ole Troand7231612018-06-07 10:17:57 +02001176
1177 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1178
1179done:
Damjan Marion8358ff92016-04-15 14:26:00 +02001180 return 0;
1181}
1182
Dave Barachba868bb2016-08-08 09:51:21 -04001183/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001184VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1185 .path = "set interface mtu",
Ole Troand7231612018-06-07 10:17:57 +02001186 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001187 .function = mtu_cmd,
1188};
Dave Barachba868bb2016-08-08 09:51:21 -04001189/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001190
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001191static clib_error_t *
Matthew Smithe0792fd2019-07-12 11:48:24 -05001192show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input,
1193 vlib_cli_command_t * cmd)
1194{
1195 vnet_main_t *vnm = vnet_get_main ();
1196 vnet_interface_main_t *im = &vnm->interface_main;
1197 ethernet_main_t *em = &ethernet_main;
1198 u32 sw_if_index = ~0;
1199 vnet_sw_interface_t *si, *sorted_sis = 0;
1200
1201 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1202 {
1203 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1204 vec_add1 (sorted_sis, si[0]);
1205 }
1206
1207 /* if an interface name was not passed, get all interfaces */
1208 if (vec_len (sorted_sis) == 0)
1209 {
1210 sorted_sis =
1211 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
1212 _vec_len (sorted_sis) = 0;
1213 /* *INDENT-OFF* */
1214 pool_foreach (si, im->sw_interfaces,
1215 ({
1216 int visible = vnet_swif_is_api_visible (si);
1217 if (visible)
1218 vec_add1 (sorted_sis, si[0]);}
1219 ));
1220 /* *INDENT-ON* */
1221 /* Sort by name. */
1222 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
1223 }
1224
1225 vec_foreach (si, sorted_sis)
1226 {
1227 vnet_sw_interface_t *sup_si;
1228 ethernet_interface_t *ei;
1229
1230 sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
1231 ei = ethernet_get_interface (em, sup_si->hw_if_index);
1232
1233 vlib_cli_output (vm, "%U (%s):",
1234 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
1235 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
1236 "up" : "dn");
1237
1238 if (ei && ei->secondary_addrs)
1239 {
1240 mac_address_t *sec_addr;
1241
1242 vec_foreach (sec_addr, ei->secondary_addrs)
1243 {
1244 vlib_cli_output (vm, " %U", format_mac_address_t, sec_addr);
1245 }
1246 }
1247 }
1248
1249 vec_free (sorted_sis);
1250 return 0;
1251}
1252
1253/*?
1254 * This command is used to display interface secondary mac addresses.
1255 *
1256 * @cliexpar
1257 * Example of how to display interface secondary mac addresses:
1258 * @cliexstart{show interface secondary-mac-address}
1259 * @cliexend
1260?*/
1261/* *INDENT-OFF* */
1262VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = {
1263 .path = "show interface secondary-mac-address",
1264 .short_help = "show interface secondary-mac-address [<interface>]",
1265 .function = show_interface_sec_mac_addr_fn,
1266};
1267/* *INDENT-ON* */
1268
1269static clib_error_t *
1270interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input,
1271 vlib_cli_command_t * cmd)
1272{
1273 vnet_main_t *vnm = vnet_get_main ();
1274 vnet_sw_interface_t *si = NULL;
1275 clib_error_t *error = 0;
1276 u32 sw_if_index = ~0;
1277 u8 mac[6] = { 0 };
1278 u8 is_add, is_del;
1279
1280 is_add = is_del = 0;
1281
1282 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1283 {
1284 error = clib_error_return (0, "unknown interface `%U'",
1285 format_unformat_error, input);
1286 goto done;
1287 }
1288 if (!unformat_user (input, unformat_ethernet_address, mac))
1289 {
1290 error = clib_error_return (0, "expected mac address `%U'",
1291 format_unformat_error, input);
1292 goto done;
1293 }
1294
1295 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1296 {
1297 if (unformat (input, "add"))
1298 is_add = 1;
1299 else if (unformat (input, "del"))
1300 is_del = 1;
1301 else
1302 break;
1303 }
1304
1305 if (is_add == is_del)
1306 {
1307 error = clib_error_return (0, "must choose one of add or del");
1308 goto done;
1309 }
1310
1311 si = vnet_get_sw_interface (vnm, sw_if_index);
1312 error =
1313 vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add);
1314
1315done:
1316 return error;
1317}
1318
1319/*?
1320 * The '<em>set interface secondary-mac-address </em>' command allows adding
1321 * or deleting extra MAC addresses on a given interface without changing the
1322 * default MAC address. This could allow packets sent to these MAC addresses
1323 * to be received without setting the interface to promiscuous mode.
1324 * Not all interfaces support this operation. The ones that do are mostly
1325 * hardware NICs, though virtio does also.
1326 *
1327 * @cliexpar
1328 * @parblock
1329 * Example of how to add a secondary MAC Address on an interface:
1330 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add}
1331 * Example of how to delete a secondary MAC address from an interface:
1332 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del}
1333 * @endparblock
1334?*/
1335/* *INDENT-OFF* */
1336VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = {
1337 .path = "set interface secondary-mac-address",
1338 .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]",
1339 .function = interface_add_del_mac_address,
1340};
1341/* *INDENT-ON* */
1342
1343static clib_error_t *
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001344set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1345 vlib_cli_command_t * cmd)
1346{
1347 vnet_main_t *vnm = vnet_get_main ();
Neale Rannsd867a7c2017-10-04 02:29:07 -07001348 vnet_sw_interface_t *si = NULL;
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001349 clib_error_t *error = 0;
1350 u32 sw_if_index = ~0;
John Lo62fcc0a2017-10-31 14:31:10 -04001351 u8 mac[6] = { 0 };
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001352
1353 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1354 {
1355 error = clib_error_return (0, "unknown interface `%U'",
1356 format_unformat_error, input);
1357 goto done;
1358 }
John Lo62fcc0a2017-10-31 14:31:10 -04001359 if (!unformat_user (input, unformat_ethernet_address, mac))
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001360 {
1361 error = clib_error_return (0, "expected mac address `%U'",
1362 format_unformat_error, input);
1363 goto done;
1364 }
Neale Rannsd867a7c2017-10-04 02:29:07 -07001365 si = vnet_get_sw_interface (vnm, sw_if_index);
1366 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001367done:
1368 return error;
1369}
1370
1371/*?
1372 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1373 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1374 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1375 *
1376 * @cliexpar
1377 * @parblock
1378 * Example of how to change MAC Address of interface:
1379 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1380 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1381 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1382 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1383 * @endparblock
1384?*/
1385/* *INDENT-OFF* */
1386VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1387 .path = "set interface mac address",
Billy McFalle9bac692017-08-11 14:05:11 -04001388 .short_help = "set interface mac address <interface> <mac-address>",
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001389 .function = set_interface_mac_address,
1390};
1391/* *INDENT-ON* */
1392
Dave Barach7be864a2016-11-28 11:41:35 -05001393static clib_error_t *
1394set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1395{
1396 vnet_main_t *vnm = vnet_get_main ();
1397 u32 sw_if_index = ~0;
1398 u8 *tag = 0;
1399
1400 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1401 vnm, &sw_if_index, &tag))
1402 return clib_error_return (0, "unknown input `%U'",
1403 format_unformat_error, input);
1404
1405 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1406
1407 return 0;
1408}
1409
1410/* *INDENT-OFF* */
1411VLIB_CLI_COMMAND (set_tag_command, static) = {
1412 .path = "set interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001413 .short_help = "set interface tag <interface> <tag>",
Dave Barach7be864a2016-11-28 11:41:35 -05001414 .function = set_tag,
1415};
1416/* *INDENT-ON* */
1417
1418static clib_error_t *
1419clear_tag (vlib_main_t * vm, unformat_input_t * input,
1420 vlib_cli_command_t * cmd)
1421{
1422 vnet_main_t *vnm = vnet_get_main ();
1423 u32 sw_if_index = ~0;
1424
1425 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1426 return clib_error_return (0, "unknown input `%U'",
1427 format_unformat_error, input);
1428
1429 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1430
1431 return 0;
1432}
1433
1434/* *INDENT-OFF* */
1435VLIB_CLI_COMMAND (clear_tag_command, static) = {
1436 .path = "clear interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001437 .short_help = "clear interface tag <interface>",
Dave Barach7be864a2016-11-28 11:41:35 -05001438 .function = clear_tag,
1439};
1440/* *INDENT-ON* */
1441
Damjan Marion44036902017-04-28 12:29:15 +02001442static clib_error_t *
Neale Ranns1855b8e2018-07-11 10:31:26 -07001443set_ip_directed_broadcast (vlib_main_t * vm,
1444 unformat_input_t * input, vlib_cli_command_t * cmd)
1445{
1446 vnet_main_t *vnm = vnet_get_main ();
1447 u32 sw_if_index = ~0;
1448 u8 enable = 0;
1449
1450 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1451 else if (unformat (input, "enable"))
1452 enable = 1;
1453 else if (unformat (input, "disable"))
1454 enable = 0;
1455 else
1456 return clib_error_return (0, "unknown input: `%U'",
1457 format_unformat_error, input);
1458
1459 if (~0 == sw_if_index)
1460 return clib_error_return (0, "specify an interface: `%U'",
1461 format_unformat_error, input);
1462
1463 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1464
1465 return 0;
1466}
1467
1468/*?
1469 * This command is used to enable/disable IP directed broadcast
1470 * If directed broadcast is enabled a packet sent to the interface's
1471 * subnet broadcast address will be sent L2 broadcast on the interface,
1472 * otherwise it is dropped.
1473 ?*/
1474/* *INDENT-OFF* */
1475VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1476 .path = "set interface ip directed-broadcast",
1477 .short_help = "set interface enable <interface> <enable|disable>",
1478 .function = set_ip_directed_broadcast,
1479};
1480/* *INDENT-ON* */
1481
1482static clib_error_t *
Stevene3a395c2017-05-09 16:19:50 -07001483set_hw_interface_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1484 u32 queue_id, vnet_hw_interface_rx_mode mode)
1485{
1486 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1487 vnet_device_class_t *dev_class =
1488 vnet_get_device_class (vnm, hw->dev_class_index);
1489 clib_error_t *error;
1490 vnet_hw_interface_rx_mode old_mode;
1491 int rv;
1492
Damjan Marion4e53a0d2017-06-21 14:29:44 +02001493 if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT)
1494 mode = hw->default_rx_mode;
1495
Stevene3a395c2017-05-09 16:19:50 -07001496 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &old_mode);
1497 switch (rv)
1498 {
1499 case 0:
1500 if (old_mode == mode)
1501 return 0; /* same rx-mode, no change */
1502 break;
1503 case VNET_API_ERROR_INVALID_INTERFACE:
1504 return clib_error_return (0, "invalid interface");
Stevenbd8a6112017-07-30 10:29:26 -07001505 case VNET_API_ERROR_INVALID_QUEUE:
1506 return clib_error_return (0, "invalid queue");
Stevene3a395c2017-05-09 16:19:50 -07001507 default:
1508 return clib_error_return (0, "unknown error");
1509 }
1510
1511 if (dev_class->rx_mode_change_function)
1512 {
1513 error = dev_class->rx_mode_change_function (vnm, hw_if_index, queue_id,
1514 mode);
1515 if (error)
1516 return (error);
1517 }
1518
1519 rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1520 switch (rv)
1521 {
1522 case 0:
1523 break;
1524 case VNET_API_ERROR_UNSUPPORTED:
1525 return clib_error_return (0, "unsupported");
1526 case VNET_API_ERROR_INVALID_INTERFACE:
1527 return clib_error_return (0, "invalid interface");
Stevenbd8a6112017-07-30 10:29:26 -07001528 case VNET_API_ERROR_INVALID_QUEUE:
1529 return clib_error_return (0, "invalid queue");
Stevene3a395c2017-05-09 16:19:50 -07001530 default:
1531 return clib_error_return (0, "unknown error");
1532 }
1533
1534 return 0;
1535}
1536
Stevenad8015b2017-10-29 22:10:46 -07001537clib_error_t *
1538set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1539 u8 queue_id_valid, u32 queue_id,
1540 vnet_hw_interface_rx_mode mode)
1541{
1542 clib_error_t *error = 0;
1543 vnet_hw_interface_t *hw;
1544 int i;
1545
1546 hw = vnet_get_hw_interface (vnm, hw_if_index);
1547
1548 if (queue_id_valid == 0)
1549 {
1550 for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1551 {
1552 error = set_hw_interface_rx_mode (vnm, hw_if_index, i, mode);
1553 if (error)
1554 break;
1555 }
1556 hw->default_rx_mode = mode;
1557 }
1558 else
1559 error = set_hw_interface_rx_mode (vnm, hw_if_index, queue_id, mode);
1560
1561 return (error);
1562}
1563
Stevene3a395c2017-05-09 16:19:50 -07001564static clib_error_t *
Damjan Marion44036902017-04-28 12:29:15 +02001565set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1566 vlib_cli_command_t * cmd)
1567{
1568 clib_error_t *error = 0;
1569 unformat_input_t _line_input, *line_input = &_line_input;
1570 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion44036902017-04-28 12:29:15 +02001571 u32 hw_if_index = (u32) ~ 0;
1572 u32 queue_id = (u32) ~ 0;
1573 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
Stevenad8015b2017-10-29 22:10:46 -07001574 u8 queue_id_valid = 0;
Dave Barach7be864a2016-11-28 11:41:35 -05001575
Damjan Marion44036902017-04-28 12:29:15 +02001576 if (!unformat_user (input, unformat_line_input, line_input))
1577 return 0;
1578
1579 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1580 {
1581 if (unformat
1582 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1583 ;
1584 else if (unformat (line_input, "queue %d", &queue_id))
Stevenad8015b2017-10-29 22:10:46 -07001585 queue_id_valid = 1;
Damjan Marion44036902017-04-28 12:29:15 +02001586 else if (unformat (line_input, "polling"))
1587 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
1588 else if (unformat (line_input, "interrupt"))
1589 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
1590 else if (unformat (line_input, "adaptive"))
1591 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
1592 else
1593 {
1594 error = clib_error_return (0, "parse error: '%U'",
1595 format_unformat_error, line_input);
1596 unformat_free (line_input);
1597 return error;
1598 }
1599 }
1600
1601 unformat_free (line_input);
1602
1603 if (hw_if_index == (u32) ~ 0)
1604 return clib_error_return (0, "please specify valid interface name");
1605
1606 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
1607 return clib_error_return (0, "please specify valid rx-mode");
1608
Stevenad8015b2017-10-29 22:10:46 -07001609 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1610 queue_id, mode);
Damjan Marion44036902017-04-28 12:29:15 +02001611
Stevene3a395c2017-05-09 16:19:50 -07001612 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001613}
1614
1615/*?
Billy McFalle9bac692017-08-11 14:05:11 -04001616 * This command is used to assign the RX packet processing mode (polling,
1617 * interrupt, adaptive) of the a given interface, and optionally a
1618 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1619 * is applied to all queues of the interface. Not all interfaces support
1620 * all modes. To display the current rx-mode use the command
1621 * '<em>show interface rx-placement</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001622 *
1623 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -04001624 * Example of how to assign rx-mode to all queues on an interface:
1625 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1626 * Example of how to assign rx-mode to one queue of an interface:
1627 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1628 * Example of how to display the rx-mode of all interfaces:
Damjan Marion44036902017-04-28 12:29:15 +02001629 * @cliexstart{show interface rx-placement}
1630 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001631 * node dpdk-input:
1632 * GigabitEthernet7/0/0 queue 0 (polling)
1633 * node vhost-user-input:
1634 * VirtualEthernet0/0/12 queue 0 (interrupt)
1635 * VirtualEthernet0/0/12 queue 2 (polling)
1636 * VirtualEthernet0/0/13 queue 0 (polling)
1637 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001638 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001639 * node dpdk-input:
1640 * GigabitEthernet7/0/1 queue 0 (polling)
1641 * node vhost-user-input:
1642 * VirtualEthernet0/0/12 queue 1 (polling)
1643 * VirtualEthernet0/0/12 queue 3 (polling)
1644 * VirtualEthernet0/0/13 queue 1 (polling)
1645 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001646 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001647?*/
1648/* *INDENT-OFF* */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001649VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
Damjan Marion44036902017-04-28 12:29:15 +02001650 .path = "set interface rx-mode",
1651 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1652 .function = set_interface_rx_mode,
1653};
1654/* *INDENT-ON* */
1655
1656static clib_error_t *
1657show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1658 vlib_cli_command_t * cmd)
1659{
1660 u8 *s = 0;
1661 vnet_main_t *vnm = vnet_get_main ();
1662 vnet_device_input_runtime_t *rt;
1663 vnet_device_and_queue_t *dq;
1664 vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
1665 uword si;
1666 int index = 0;
1667
1668 /* *INDENT-OFF* */
1669 foreach_vlib_main (({
1670 clib_bitmap_foreach (si, pn->sibling_bitmap,
1671 ({
1672 rt = vlib_node_get_runtime_data (this_vlib_main, si);
1673
1674 if (vec_len (rt->devices_and_queues))
1675 s = format (s, " node %U:\n", format_vlib_node_name, vm, si);
1676
1677 vec_foreach (dq, rt->devices_and_queues)
1678 {
Steven9d6d9892017-06-30 07:15:02 -07001679 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm,
1680 dq->hw_if_index);
Damjan Marion44036902017-04-28 12:29:15 +02001681 s = format (s, " %U queue %u (%U)\n",
Steven9d6d9892017-06-30 07:15:02 -07001682 format_vnet_sw_if_index_name, vnm, hi->sw_if_index,
Damjan Marion44036902017-04-28 12:29:15 +02001683 dq->queue_id,
1684 format_vnet_hw_interface_rx_mode, dq->mode);
1685 }
1686 }));
1687 if (vec_len (s) > 0)
1688 {
Steven84f36cb2018-09-26 10:44:54 -07001689 vlib_cli_output(vm, "Thread %u (%s):\n%v", index,
Damjan Marion44036902017-04-28 12:29:15 +02001690 vlib_worker_threads[index].name, s);
1691 vec_reset_length (s);
1692 }
1693 index++;
1694 }));
1695 /* *INDENT-ON* */
1696
1697 vec_free (s);
1698 return 0;
1699}
1700
Billy McFalle9bac692017-08-11 14:05:11 -04001701/*?
1702 * This command is used to display the interface and queue worker
1703 * thread placement.
1704 *
1705 * @cliexpar
1706 * Example of how to display the interface placement:
1707 * @cliexstart{show interface rx-placement}
1708 * Thread 1 (vpp_wk_0):
1709 * node dpdk-input:
1710 * GigabitEthernet7/0/0 queue 0 (polling)
1711 * node vhost-user-input:
1712 * VirtualEthernet0/0/12 queue 0 (polling)
1713 * VirtualEthernet0/0/12 queue 2 (polling)
1714 * VirtualEthernet0/0/13 queue 0 (polling)
1715 * VirtualEthernet0/0/13 queue 2 (polling)
1716 * Thread 2 (vpp_wk_1):
1717 * node dpdk-input:
1718 * GigabitEthernet7/0/1 queue 0 (polling)
1719 * node vhost-user-input:
1720 * VirtualEthernet0/0/12 queue 1 (polling)
1721 * VirtualEthernet0/0/12 queue 3 (polling)
1722 * VirtualEthernet0/0/13 queue 1 (polling)
1723 * VirtualEthernet0/0/13 queue 3 (polling)
1724 * @cliexend
1725?*/
Damjan Marion44036902017-04-28 12:29:15 +02001726/* *INDENT-OFF* */
1727VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1728 .path = "show interface rx-placement",
1729 .short_help = "show interface rx-placement",
1730 .function = show_interface_rx_placement_fn,
1731};
1732/* *INDENT-ON* */
1733
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001734clib_error_t *
1735set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1736 u32 thread_index, u8 is_main)
Damjan Marion44036902017-04-28 12:29:15 +02001737{
Damjan Marion44036902017-04-28 12:29:15 +02001738 vnet_main_t *vnm = vnet_get_main ();
1739 vnet_device_main_t *vdm = &vnet_device_main;
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001740 clib_error_t *error = 0;
1741 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
Damjan Marion44036902017-04-28 12:29:15 +02001742 int rv;
1743
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001744 if (is_main)
1745 thread_index = 0;
1746 else
1747 thread_index += vdm->first_worker_thread_index;
Damjan Marion44036902017-04-28 12:29:15 +02001748
1749 if (thread_index > vdm->last_worker_thread_index)
1750 return clib_error_return (0,
1751 "please specify valid worker thread or main");
1752
1753 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode);
1754
1755 if (rv)
1756 return clib_error_return (0, "not found");
1757
1758 rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id);
1759
1760 if (rv)
1761 return clib_error_return (0, "not found");
1762
1763 vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id,
1764 thread_index);
1765 vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1766
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001767 return (error);
1768}
1769
1770static clib_error_t *
1771set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input,
1772 vlib_cli_command_t * cmd)
1773{
1774 clib_error_t *error = 0;
1775 unformat_input_t _line_input, *line_input = &_line_input;
1776 vnet_main_t *vnm = vnet_get_main ();
1777 u32 hw_if_index = (u32) ~ 0;
1778 u32 queue_id = (u32) 0;
1779 u32 thread_index = (u32) ~ 0;
1780 u8 is_main = 0;
1781
1782 if (!unformat_user (input, unformat_line_input, line_input))
1783 return 0;
1784
1785 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1786 {
1787 if (unformat
1788 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1789 ;
1790 else if (unformat (line_input, "queue %d", &queue_id))
1791 ;
1792 else if (unformat (line_input, "main", &thread_index))
1793 is_main = 1;
1794 else if (unformat (line_input, "worker %d", &thread_index))
1795 ;
1796 else
1797 {
1798 error = clib_error_return (0, "parse error: '%U'",
1799 format_unformat_error, line_input);
1800 unformat_free (line_input);
1801 return error;
1802 }
1803 }
1804
1805 unformat_free (line_input);
1806
1807 if (hw_if_index == (u32) ~ 0)
1808 return clib_error_return (0, "please specify valid interface name");
1809
1810 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1811 is_main);
1812
1813 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001814}
1815
1816/*?
1817 * This command is used to assign a given interface, and optionally a
1818 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
Billy McFalle9bac692017-08-11 14:05:11 -04001819 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1820 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001821 *
1822 * @cliexpar
1823 * Example of how to display the interface placement:
Billy McFalle9bac692017-08-11 14:05:11 -04001824 * @cliexstart{show interface rx-placement}
Damjan Marion44036902017-04-28 12:29:15 +02001825 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001826 * node dpdk-input:
1827 * GigabitEthernet7/0/0 queue 0 (polling)
1828 * node vhost-user-input:
1829 * VirtualEthernet0/0/12 queue 0 (polling)
1830 * VirtualEthernet0/0/12 queue 2 (polling)
1831 * VirtualEthernet0/0/13 queue 0 (polling)
1832 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001833 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001834 * node dpdk-input:
1835 * GigabitEthernet7/0/1 queue 0 (polling)
1836 * node vhost-user-input:
1837 * VirtualEthernet0/0/12 queue 1 (polling)
1838 * VirtualEthernet0/0/12 queue 3 (polling)
1839 * VirtualEthernet0/0/13 queue 1 (polling)
1840 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001841 * @cliexend
Billy McFalle9bac692017-08-11 14:05:11 -04001842 * Example of how to assign a interface and queue to a worker thread:
1843 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1844 * Example of how to display the interface placement:
1845 * @cliexstart{show interface rx-placement}
1846 * Thread 1 (vpp_wk_0):
1847 * node dpdk-input:
1848 * GigabitEthernet7/0/0 queue 0 (polling)
1849 * node vhost-user-input:
1850 * VirtualEthernet0/0/12 queue 0 (polling)
1851 * VirtualEthernet0/0/12 queue 1 (polling)
1852 * VirtualEthernet0/0/12 queue 2 (polling)
1853 * VirtualEthernet0/0/13 queue 0 (polling)
1854 * VirtualEthernet0/0/13 queue 2 (polling)
1855 * Thread 2 (vpp_wk_1):
1856 * node dpdk-input:
1857 * GigabitEthernet7/0/1 queue 0 (polling)
1858 * node vhost-user-input:
1859 * VirtualEthernet0/0/12 queue 3 (polling)
1860 * VirtualEthernet0/0/13 queue 1 (polling)
1861 * VirtualEthernet0/0/13 queue 3 (polling)
1862 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001863?*/
1864/* *INDENT-OFF* */
1865VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1866 .path = "set interface rx-placement",
Billy McFalle9bac692017-08-11 14:05:11 -04001867 .short_help = "set interface rx-placement <interface> [queue <n>] "
Damjan Marion6f9ac652017-06-15 19:01:31 +02001868 "[worker <n> | main]",
Damjan Marion44036902017-04-28 12:29:15 +02001869 .function = set_interface_rx_placement,
Damjan Marion6f9ac652017-06-15 19:01:31 +02001870 .is_mp_safe = 1,
Damjan Marion44036902017-04-28 12:29:15 +02001871};
Damjan Marion44036902017-04-28 12:29:15 +02001872/* *INDENT-ON* */
Dave Barach5ecd5a52019-02-25 15:27:28 -05001873
Dave Barach33909772019-09-23 10:27:27 -04001874static u8 *
1875format_vnet_pcap (u8 * s, va_list * args)
1876{
1877 vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *);
1878 int type = va_arg (*args, int);
1879 int printed = 0;
1880
1881 if (type == 0)
1882 {
1883 if (pp->pcap_rx_enable)
1884 {
1885 s = format (s, "rx");
1886 printed = 1;
1887 }
1888 if (pp->pcap_tx_enable)
1889 {
1890 if (printed)
1891 s = format (s, " and ");
1892 s = format (s, "tx");
1893 printed = 1;
1894 }
1895 if (pp->pcap_drop_enable)
1896 {
1897 if (printed)
1898 s = format (s, " and ");
1899 s = format (s, "drop");
1900 printed = 1;
1901 }
1902 return s;
1903 }
1904 s = format (s, "unknown type %d!", type);
1905 return s;
1906}
1907
1908
Dave Barachb97641c2019-09-09 16:38:17 -04001909int
1910vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
1911{
1912 vlib_main_t *vm = vlib_get_main ();
Dave Barach33909772019-09-23 10:27:27 -04001913 vnet_pcap_t *pp = &vm->pcap;
Dave Barachb97641c2019-09-09 16:38:17 -04001914 pcap_main_t *pm = &pp->pcap_main;
Dave Barachf5667c32019-09-25 11:27:46 -04001915 vnet_classify_main_t *cm = &vnet_classify_main;
1916 vnet_classify_filter_set_t *set = 0;
Dave Barachb97641c2019-09-09 16:38:17 -04001917
1918 if (a->status)
1919 {
Dave Barach33909772019-09-23 10:27:27 -04001920 if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04001921 {
1922 vlib_cli_output
Dave Barach33909772019-09-23 10:27:27 -04001923 (vm, "pcap %U dispatch capture enabled: %d of %d pkts...",
1924 format_vnet_pcap, pp, 0 /* print type */ ,
Dave Barachb97641c2019-09-09 16:38:17 -04001925 pm->n_packets_captured, pm->n_packets_to_capture);
1926 vlib_cli_output (vm, "capture to file %s", pm->file_name);
1927 }
1928 else
Dave Barach33909772019-09-23 10:27:27 -04001929 vlib_cli_output (vm, "pcap dispatch capture disabled");
1930
Dave Barachb97641c2019-09-09 16:38:17 -04001931 return 0;
1932 }
1933
1934 /* Consistency checks */
1935
1936 /* Enable w/ capture already enabled not allowed */
Dave Barach33909772019-09-23 10:27:27 -04001937 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
1938 && (a->rx_enable + a->tx_enable + a->drop_enable))
Dave Barachb97641c2019-09-09 16:38:17 -04001939 return VNET_API_ERROR_INVALID_VALUE;
1940
1941 /* Disable capture with capture already disabled, not interesting */
Dave Barach33909772019-09-23 10:27:27 -04001942 if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) == 0)
1943 && ((a->rx_enable + a->tx_enable + a->drop_enable == 0)))
Dave Barachb97641c2019-09-09 16:38:17 -04001944 return VNET_API_ERROR_VALUE_EXIST;
1945
1946 /* Change number of packets to capture while capturing */
Dave Barach33909772019-09-23 10:27:27 -04001947 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
1948 && (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04001949 && (pm->n_packets_to_capture != a->packets_to_capture))
1950 return VNET_API_ERROR_INVALID_VALUE_2;
1951
Dave Barachf5667c32019-09-25 11:27:46 -04001952 set = pool_elt_at_index (cm->filter_sets, cm->filter_set_by_sw_if_index[0]);
1953
Dave Barach33909772019-09-23 10:27:27 -04001954 /* Classify filter specified, but no classify filter configured */
Dave Barachf5667c32019-09-25 11:27:46 -04001955 if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter &&
1956 (set->table_indices[0] == ~0))
Dave Barach9137e542019-09-13 17:47:50 -04001957 return VNET_API_ERROR_NO_SUCH_LABEL;
1958
Dave Barach33909772019-09-23 10:27:27 -04001959 if (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04001960 {
Dave Barach33909772019-09-23 10:27:27 -04001961 /* Sanity check max bytes per pkt */
1962 if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000)
1963 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
1964
Dave Barachb97641c2019-09-09 16:38:17 -04001965 /* Clean up from previous run, if any */
1966 vec_free (pm->file_name);
1967 vec_free (pm->pcap_data);
1968 memset (pm, 0, sizeof (*pm));
1969
1970 vec_validate_aligned (vnet_trace_dummy, 2048, CLIB_CACHE_LINE_BYTES);
1971 if (pm->lock == 0)
1972 clib_spinlock_init (&(pm->lock));
1973
1974 if (a->filename == 0)
Dave Barach33909772019-09-23 10:27:27 -04001975 {
1976 u8 *stem = 0;
1977
1978 if (a->rx_enable)
1979 stem = format (stem, "rx");
1980 if (a->tx_enable)
1981 stem = format (stem, "tx");
1982 if (a->drop_enable)
1983 stem = format (stem, "drop");
1984 a->filename = format (0, "/tmp/%s.pcap%c", stem, 0);
1985 vec_free (stem);
1986 }
Dave Barachb97641c2019-09-09 16:38:17 -04001987
1988 pm->file_name = (char *) a->filename;
1989 pm->n_packets_captured = 0;
1990 pm->packet_type = PCAP_PACKET_TYPE_ethernet;
1991 pm->n_packets_to_capture = a->packets_to_capture;
1992 pp->pcap_sw_if_index = a->sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04001993 if (a->filter)
Dave Barachf5667c32019-09-25 11:27:46 -04001994 pp->filter_classify_table_index = set->table_indices[0];
Dave Barach9137e542019-09-13 17:47:50 -04001995 else
1996 pp->filter_classify_table_index = ~0;
Dave Barach33909772019-09-23 10:27:27 -04001997 pp->pcap_rx_enable = a->rx_enable;
1998 pp->pcap_tx_enable = a->tx_enable;
1999 pp->pcap_drop_enable = a->drop_enable;
2000 pp->max_bytes_per_pkt = a->max_bytes_per_pkt;
Dave Barachb97641c2019-09-09 16:38:17 -04002001 }
2002 else
2003 {
Dave Barach33909772019-09-23 10:27:27 -04002004 pp->pcap_rx_enable = 0;
2005 pp->pcap_tx_enable = 0;
2006 pp->pcap_drop_enable = 0;
Dave Barachf5667c32019-09-25 11:27:46 -04002007 pp->filter_classify_table_index = ~0;
Dave Barachb97641c2019-09-09 16:38:17 -04002008 if (pm->n_packets_captured)
2009 {
2010 clib_error_t *error;
2011 pm->n_packets_to_capture = pm->n_packets_captured;
2012 vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
2013 pm->n_packets_captured, pm->file_name);
2014 error = pcap_write (pm);
Andrew Yourtchenko4da15062019-09-11 14:14:43 +00002015 if (pm->flags & PCAP_MAIN_INIT_DONE)
Dave Barachb97641c2019-09-09 16:38:17 -04002016 pcap_close (pm);
2017 /* Report I/O errors... */
2018 if (error)
2019 {
2020 clib_error_report (error);
2021 return VNET_API_ERROR_SYSCALL_ERROR_1;
2022 }
2023 return 0;
2024 }
2025 else
2026 return VNET_API_ERROR_NO_SUCH_ENTRY;
2027 }
2028
2029 return 0;
2030}
2031
2032static clib_error_t *
Dave Barach33909772019-09-23 10:27:27 -04002033pcap_trace_command_fn (vlib_main_t * vm,
2034 unformat_input_t * input, vlib_cli_command_t * cmd)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002035{
Dave Barach5ecd5a52019-02-25 15:27:28 -05002036 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barachb97641c2019-09-09 16:38:17 -04002037 vnet_pcap_dispatch_trace_args_t _a, *a = &_a;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002038 vnet_main_t *vnm = vnet_get_main ();
Dave Barachb97641c2019-09-09 16:38:17 -04002039 u8 *filename = 0;
2040 u32 max = 1000;
Dave Barach33909772019-09-23 10:27:27 -04002041 u32 max_bytes_per_pkt = 512;
Dave Barachb97641c2019-09-09 16:38:17 -04002042 int rv;
Dave Barach33909772019-09-23 10:27:27 -04002043 int rx_enable = 0;
2044 int tx_enable = 0;
2045 int drop_enable = 0;
Dave Barachb97641c2019-09-09 16:38:17 -04002046 int status = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002047 int filter = 0;
Dave Barachf5667c32019-09-25 11:27:46 -04002048 u32 sw_if_index = ~0;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002049
2050 /* Get a line of input. */
2051 if (!unformat_user (input, unformat_line_input, line_input))
2052 return 0;
2053
2054 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2055 {
Dave Barach33909772019-09-23 10:27:27 -04002056 if (unformat (line_input, "rx"))
2057 rx_enable = 1;
2058 else if (unformat (line_input, "tx"))
2059 tx_enable = 1;
2060 else if (unformat (line_input, "drop"))
2061 drop_enable = 1;
2062 else if (unformat (line_input, "off"))
2063 rx_enable = tx_enable = drop_enable = 0;
2064 else if (unformat (line_input, "max-bytes-per-pkt %u",
2065 &max_bytes_per_pkt))
Dave Barachb97641c2019-09-09 16:38:17 -04002066 ;
2067 else if (unformat (line_input, "max %d", &max))
2068 ;
2069 else if (unformat (line_input, "packets-to-capture %d", &max))
2070 ;
2071 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
2072 &filename))
2073 ;
2074 else if (unformat (line_input, "status %=", &status, 1))
2075 ;
2076 else if (unformat (line_input, "intfc %U",
2077 unformat_vnet_sw_interface, vnm, &sw_if_index))
2078 ;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002079 else if (unformat (line_input, "intfc any"))
Dave Barachb97641c2019-09-09 16:38:17 -04002080 sw_if_index = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002081 else if (unformat (line_input, "filter"))
2082 filter = 1;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002083 else
2084 {
Dave Barachb97641c2019-09-09 16:38:17 -04002085 return clib_error_return (0, "unknown input `%U'",
2086 format_unformat_error, line_input);
Dave Barach5ecd5a52019-02-25 15:27:28 -05002087 }
2088 }
Dave Barachb97641c2019-09-09 16:38:17 -04002089
Dave Barach5ecd5a52019-02-25 15:27:28 -05002090 unformat_free (line_input);
2091
Dave Barachb97641c2019-09-09 16:38:17 -04002092 /* no need for memset (a, 0, sizeof (*a)), set all fields here. */
2093 a->filename = filename;
Dave Barach33909772019-09-23 10:27:27 -04002094 a->rx_enable = rx_enable;
2095 a->tx_enable = tx_enable;
2096 a->drop_enable = drop_enable;
Dave Barachb97641c2019-09-09 16:38:17 -04002097 a->status = status;
2098 a->packets_to_capture = max;
Dave Barachb97641c2019-09-09 16:38:17 -04002099 a->sw_if_index = sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04002100 a->filter = filter;
Dave Barach33909772019-09-23 10:27:27 -04002101 a->max_bytes_per_pkt = max_bytes_per_pkt;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002102
Dave Barachb97641c2019-09-09 16:38:17 -04002103 rv = vnet_pcap_dispatch_trace_configure (a);
2104
2105 switch (rv)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002106 {
Dave Barachb97641c2019-09-09 16:38:17 -04002107 case 0:
2108 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002109
Dave Barachb97641c2019-09-09 16:38:17 -04002110 case VNET_API_ERROR_INVALID_VALUE:
2111 return clib_error_return (0, "dispatch trace already enabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002112
Dave Barachb97641c2019-09-09 16:38:17 -04002113 case VNET_API_ERROR_VALUE_EXIST:
2114 return clib_error_return (0, "dispatch trace already disabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002115
Dave Barachb97641c2019-09-09 16:38:17 -04002116 case VNET_API_ERROR_INVALID_VALUE_2:
2117 return clib_error_return
2118 (0, "can't change number of records to capture while tracing...");
2119
2120 case VNET_API_ERROR_SYSCALL_ERROR_1:
2121 return clib_error_return (0, "I/O writing trace capture...");
2122
2123 case VNET_API_ERROR_NO_SUCH_ENTRY:
2124 return clib_error_return (0, "No packets captured...");
2125
Dave Barach33909772019-09-23 10:27:27 -04002126 case VNET_API_ERROR_INVALID_MEMORY_SIZE:
2127 return clib_error_return (0,
2128 "Max bytes per pkt must be > 32, < 9000...");
2129
Dave Barach9137e542019-09-13 17:47:50 -04002130 case VNET_API_ERROR_NO_SUCH_LABEL:
2131 return clib_error_return
2132 (0, "No classify filter configured, see 'classify filter...'");
2133
Dave Barachb97641c2019-09-09 16:38:17 -04002134 default:
2135 vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
2136 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002137 }
Dave Barachb97641c2019-09-09 16:38:17 -04002138 return 0;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002139}
2140
Dave Barach5ecd5a52019-02-25 15:27:28 -05002141/*?
2142 * This command is used to start or stop a packet capture, or show
Dave Barach33909772019-09-23 10:27:27 -04002143 * the status of packet capture.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002144 *
2145 * This command has the following optional parameters:
2146 *
Dave Barach33909772019-09-23 10:27:27 -04002147 *
2148 * - <b>rx</b> - Capture received packets
2149 *
2150 * - <b>tx</b> - Capture transmitted packets
2151 *
2152 * - <b>drop</b> - Capture dropped packets
2153 *
2154 * - <b>off</b> - Stop capturing packets, write results to the specified file
Dave Barach5ecd5a52019-02-25 15:27:28 -05002155 *
2156 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
2157 * of packets have been received, buffer is flushed to file. Once another
2158 * '<em>nn</em>' number of packets have been received, buffer is flushed
2159 * to file, overwriting previous write. If not entered, value defaults
2160 * to 100. Can only be updated if packet capture is off.
2161 *
Dave Barach33909772019-09-23 10:27:27 -04002162 * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture
2163 * for each packet. Must be >= 32, <= 9000.
2164 *
2165 * - <b>intfc <interface-name>|any</b> - Used to specify a given interface,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002166 * or use '<em>any</em>' to run packet capture on all interfaces.
2167 * '<em>any</em>' is the default if not provided. Settings from a previous
2168 * packet capture are preserved, so '<em>any</em>' can be used to reset
2169 * the interface setting.
2170 *
Dave Barachf5667c32019-09-25 11:27:46 -04002171 * - <b>filter</b> - Use the pcap rx / tx / drop trace filter, which
2172 * must be configured. Use <b>classify filter pcap...</b> to configure the
2173 * filter. The filter will only be executed if the per-interface or
2174 * any-interface tests fail.
2175 *
Dave Barach5ecd5a52019-02-25 15:27:28 -05002176 * - <b>file <name></b> - Used to specify the output filename. The file will
2177 * be placed in the '<em>/tmp</em>' directory, so only the filename is
2178 * supported. Directory should not be entered. If file already exists, file
Dave Barach33909772019-09-23 10:27:27 -04002179 * will be overwritten. If no filename is provided, the file will be
2180 * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc.
2181 * Can only be updated if packet capture is off.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002182 *
2183 * - <b>status</b> - Displays the current status and configured attributes
2184 * associated with a packet capture. If packet capture is in progress,
2185 * '<em>status</em>' also will return the number of packets currently in
2186 * the local buffer. All additional attributes entered on command line
2187 * with '<em>status</em>' will be ignored and not applied.
2188 *
2189 * @cliexpar
2190 * Example of how to display the status of a tx packet capture when off:
Dave Barach33909772019-09-23 10:27:27 -04002191 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002192 * max is 100, for any interface to file /tmp/vpe.pcap
2193 * pcap tx capture is off...
2194 * @cliexend
2195 * Example of how to start a tx packet capture:
Dave Barach33909772019-09-23 10:27:27 -04002196 * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file vppTest.pcap}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002197 * @cliexend
2198 * Example of how to display the status of a tx packet capture in progress:
Dave Barach33909772019-09-23 10:27:27 -04002199 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002200 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
2201 * pcap tx capture is on: 20 of 35 pkts...
2202 * @cliexend
2203 * Example of how to stop a tx packet capture:
Dave Barach33909772019-09-23 10:27:27 -04002204 * @cliexstart{pcap trace off}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002205 * captured 21 pkts...
2206 * saved to /tmp/vppTest.pcap...
2207 * @cliexend
2208?*/
2209/* *INDENT-OFF* */
2210
2211VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
Dave Barach33909772019-09-23 10:27:27 -04002212 .path = "pcap trace",
Dave Barach5ecd5a52019-02-25 15:27:28 -05002213 .short_help =
Dave Barachf5667c32019-09-25 11:27:46 -04002214 "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 -04002215 .function = pcap_trace_command_fn,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002216};
2217/* *INDENT-ON* */
2218
Dave Barachba868bb2016-08-08 09:51:21 -04002219/*
2220 * fd.io coding-style-patch-verification: ON
2221 *
2222 * Local Variables:
2223 * eval: (c-set-style "gnu")
2224 * End:
2225 */