blob: 624f8ef0c1307a1e626e5aa87b86a48f14439b32 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/*
16 * interface_cli.c: interface CLI
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
Chris Luke16bcf7d2016-09-01 14:31:46 -040040/**
41 * @file
Billy McFalle9bac692017-08-11 14:05:11 -040042 * @brief Interface CLI.
43 *
44 * Source code for several CLI interface commands.
45 *
Chris Luke16bcf7d2016-09-01 14:31:46 -040046 */
47
Ed Warnickecb9cada2015-12-08 15:45:58 -070048#include <vnet/vnet.h>
49#include <vnet/ip/ip.h>
John Lobcebbb92016-04-05 15:47:43 -040050#include <vppinfra/bitmap.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010051#include <vnet/fib/ip4_fib.h>
52#include <vnet/fib/ip6_fib.h>
Eyal Bari942402b2017-07-26 11:57:04 +030053#include <vnet/l2/l2_output.h>
54#include <vnet/l2/l2_input.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070055
Dave Barachba868bb2016-08-08 09:51:21 -040056static int
57compare_interface_names (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -070058{
Dave Barachba868bb2016-08-08 09:51:21 -040059 u32 *hi1 = a1;
60 u32 *hi2 = a2;
Ed Warnickecb9cada2015-12-08 15:45:58 -070061
Dave Barachba868bb2016-08-08 09:51:21 -040062 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070063}
64
65static clib_error_t *
66show_or_clear_hw_interfaces (vlib_main_t * vm,
67 unformat_input_t * input,
68 vlib_cli_command_t * cmd)
69{
Dave Barachba868bb2016-08-08 09:51:21 -040070 clib_error_t *error = 0;
71 vnet_main_t *vnm = vnet_get_main ();
72 vnet_interface_main_t *im = &vnm->interface_main;
73 vnet_hw_interface_t *hi;
74 u32 hw_if_index, *hw_if_indices = 0;
John Lobcebbb92016-04-05 15:47:43 -040075 int i, verbose = -1, is_show, show_bond = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070076
77 is_show = strstr (cmd->path, "show") != 0;
78 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
79 {
80 /* See if user wants to show a specific interface. */
Dave Barachba868bb2016-08-08 09:51:21 -040081 if (unformat
82 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
83 vec_add1 (hw_if_indices, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -040084
Sean Hope679ea792016-02-22 15:12:01 -050085 /* See if user wants to show an interface with a specific hw_if_index. */
86 else if (unformat (input, "%u", &hw_if_index))
Dave Barachba868bb2016-08-08 09:51:21 -040087 vec_add1 (hw_if_indices, hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070088
89 else if (unformat (input, "verbose"))
Dave Barachba868bb2016-08-08 09:51:21 -040090 verbose = 1; /* this is also the default */
Ed Warnickecb9cada2015-12-08 15:45:58 -070091
92 else if (unformat (input, "detail"))
93 verbose = 2;
94
95 else if (unformat (input, "brief"))
96 verbose = 0;
97
John Lobcebbb92016-04-05 15:47:43 -040098 else if (unformat (input, "bond"))
Dave Barachba868bb2016-08-08 09:51:21 -040099 {
100 show_bond = 1;
101 if (verbose < 0)
102 verbose = 0; /* default to brief for link bonding */
103 }
John Lobcebbb92016-04-05 15:47:43 -0400104
Ed Warnickecb9cada2015-12-08 15:45:58 -0700105 else
106 {
107 error = clib_error_return (0, "unknown input `%U'",
108 format_unformat_error, input);
109 goto done;
110 }
111 }
Dave Barachba868bb2016-08-08 09:51:21 -0400112
Ed Warnickecb9cada2015-12-08 15:45:58 -0700113 /* Gather interfaces. */
114 if (vec_len (hw_if_indices) == 0)
115 pool_foreach (hi, im->hw_interfaces,
116 vec_add1 (hw_if_indices, hi - im->hw_interfaces));
117
Dave Barachba868bb2016-08-08 09:51:21 -0400118 if (verbose < 0)
119 verbose = 1; /* default to verbose (except bond) */
John Lobcebbb92016-04-05 15:47:43 -0400120
Ed Warnickecb9cada2015-12-08 15:45:58 -0700121 if (is_show)
122 {
123 /* Sort by name. */
124 vec_sort_with_function (hw_if_indices, compare_interface_names);
125
126 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
127 for (i = 0; i < vec_len (hw_if_indices); i++)
128 {
129 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
Dave Barachba868bb2016-08-08 09:51:21 -0400130 if (show_bond == 0) /* show all interfaces */
131 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
132 hi, verbose);
133 else if ((hi->bond_info) &&
John Lobcebbb92016-04-05 15:47:43 -0400134 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
Dave Barachba868bb2016-08-08 09:51:21 -0400135 { /* show only bonded interface and all its slave interfaces */
John Lobcebbb92016-04-05 15:47:43 -0400136 int hw_idx;
Dave Barachba868bb2016-08-08 09:51:21 -0400137 vnet_hw_interface_t *shi;
138 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
John Lobcebbb92016-04-05 15:47:43 -0400139 hi, verbose);
Dave Barachba868bb2016-08-08 09:51:21 -0400140
141 /* *INDENT-OFF* */
John Lobcebbb92016-04-05 15:47:43 -0400142 clib_bitmap_foreach (hw_idx, hi->bond_info,
Dave Barachba868bb2016-08-08 09:51:21 -0400143 ({
144 shi = vnet_get_hw_interface(vnm, hw_idx);
145 vlib_cli_output (vm, "%U\n",
146 format_vnet_hw_interface, vnm, shi, verbose);
147 }));
148 /* *INDENT-ON* */
John Lobcebbb92016-04-05 15:47:43 -0400149 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700150 }
151 }
152 else
153 {
154 for (i = 0; i < vec_len (hw_if_indices); i++)
155 {
Dave Barachba868bb2016-08-08 09:51:21 -0400156 vnet_device_class_t *dc;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700157
158 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
159 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400160
Ed Warnickecb9cada2015-12-08 15:45:58 -0700161 if (dc->clear_counters)
162 dc->clear_counters (hi->dev_instance);
163 }
164 }
165
Dave Barachba868bb2016-08-08 09:51:21 -0400166done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700167 vec_free (hw_if_indices);
168 return error;
169}
170
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700171/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400172 * Display more detailed information about all or a list of given interfaces.
173 * The verboseness of the output can be controlled by the following optional
174 * parameters:
175 * - brief: Only show name, index and state (default for bonded interfaces).
176 * - verbose: Also display additional attributes (default for all other interfaces).
177 * - detail: Also display all remaining attributes and extended statistics.
178 *
179 * To limit the output of the command to bonded interfaces and their slave
180 * interfaces, use the '<em>bond</em>' optional parameter.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700181 *
182 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400183 * Example of how to display default data for all interfaces:
184 * @cliexstart{show hardware-interfaces}
185 * Name Idx Link Hardware
186 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
187 * Ethernet address ec:f4:bb:c0:bc:fc
188 * Intel e1000
189 * carrier up full duplex speed 1000 mtu 9216
190 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
191 * cpu socket 0
192 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
193 * Ethernet address ec:f4:bb:c0:bc:fd
194 * Intel e1000
195 * carrier up full duplex speed 1000 mtu 9216
196 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
197 * cpu socket 0
198 * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0
199 * Ethernet address 02:fe:a5:a9:8b:8e
200 * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1
201 * Ethernet address 02:fe:c0:4e:3b:b0
202 * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2
203 * Ethernet address 02:fe:1f:73:92:81
204 * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3
205 * Ethernet address 02:fe:f2:25:c4:68
206 * local0 0 down local0
207 * local
208 * @cliexend
209 * Example of how to display '<em>verbose</em>' data for an interface by name and
210 * software index (where 2 is the software index):
211 * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose}
212 * Name Idx Link Hardware
213 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
214 * Ethernet address ec:f4:bb:c0:bc:fc
215 * Intel e1000
216 * carrier up full duplex speed 1000 mtu 9216
217 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
218 * cpu socket 0
219 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
220 * Ethernet address ec:f4:bb:c0:bc:fd
221 * Intel e1000
222 * carrier up full duplex speed 1000 mtu 9216
223 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
224 * cpu socket 0
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700225 * @cliexend
226 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400227/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700228VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
229 .path = "show hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400230 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
231 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700232 .function = show_or_clear_hw_interfaces,
233};
Dave Barachba868bb2016-08-08 09:51:21 -0400234/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700235
Billy McFalle9bac692017-08-11 14:05:11 -0400236
237/*?
238 * Clear the extended statistics for all or a list of given interfaces
239 * (statistics associated with the '<em>show hardware-interfaces</em>' command).
240 *
241 * @cliexpar
242 * Example of how to clear the extended statistics for all interfaces:
243 * @cliexcmd{clear hardware-interfaces}
244 * Example of how to clear the extended statistics for an interface by
245 * name and software index (where 2 is the software index):
246 * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2}
247 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400248/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700249VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
250 .path = "clear hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400251 .short_help = "clear hardware-interfaces "
252 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700253 .function = show_or_clear_hw_interfaces,
254};
Dave Barachba868bb2016-08-08 09:51:21 -0400255/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256
Dave Barachba868bb2016-08-08 09:51:21 -0400257static int
258sw_interface_name_compare (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700259{
260 vnet_sw_interface_t *si1 = a1;
261 vnet_sw_interface_t *si2 = a2;
262
Dave Barachba868bb2016-08-08 09:51:21 -0400263 return vnet_sw_interface_compare (vnet_get_main (),
264 si1->sw_if_index, si2->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265}
266
267static clib_error_t *
268show_sw_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400269 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700270{
Dave Barachba868bb2016-08-08 09:51:21 -0400271 clib_error_t *error = 0;
272 vnet_main_t *vnm = vnet_get_main ();
Dave Barach525c9d02018-05-26 10:48:55 -0400273 unformat_input_t _linput, *linput = &_linput;
Dave Barachba868bb2016-08-08 09:51:21 -0400274 vnet_interface_main_t *im = &vnm->interface_main;
275 vnet_sw_interface_t *si, *sorted_sis = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200276 u32 sw_if_index = ~(u32) 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700277 u8 show_addresses = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200278 u8 show_features = 0;
Dave Barach7be864a2016-11-28 11:41:35 -0500279 u8 show_tag = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400280 int verbose = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281
Dave Barach525c9d02018-05-26 10:48:55 -0400282 /*
283 * Get a line of input. Won't work if the user typed
284 * "show interface" and nothing more.
285 */
286 if (unformat_user (input, unformat_line_input, linput))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700287 {
Dave Barach525c9d02018-05-26 10:48:55 -0400288 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700289 {
Dave Barach525c9d02018-05-26 10:48:55 -0400290 /* See if user wants to show specific interface */
291 if (unformat
292 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
293 {
294 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
295 vec_add1 (sorted_sis, si[0]);
296 }
297 else if (unformat (linput, "address") || unformat (linput, "addr"))
298 show_addresses = 1;
299 else if (unformat (linput, "features") || unformat (linput, "feat"))
300 show_features = 1;
301 else if (unformat (linput, "tag"))
302 show_tag = 1;
303 else if (unformat (linput, "verbose"))
304 verbose = 1;
305 else
306 {
307 error = clib_error_return (0, "unknown input `%U'",
308 format_unformat_error, linput);
309 goto done;
310 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700311 }
Dave Barach525c9d02018-05-26 10:48:55 -0400312 unformat_free (linput);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700313 }
Dave Barach7be864a2016-11-28 11:41:35 -0500314 if (show_features || show_tag)
Damjan Marion22311502016-10-28 20:30:15 +0200315 {
316 if (sw_if_index == ~(u32) 0)
317 return clib_error_return (0, "Interface not specified...");
Dave Barach7be864a2016-11-28 11:41:35 -0500318 }
Damjan Marion22311502016-10-28 20:30:15 +0200319
Dave Barach7be864a2016-11-28 11:41:35 -0500320 if (show_features)
321 {
Dave Barach525c9d02018-05-26 10:48:55 -0400322 vnet_interface_features_show (vm, sw_if_index, verbose);
Eyal Bari942402b2017-07-26 11:57:04 +0300323
324 l2_input_config_t *l2_input = l2input_intf_config (sw_if_index);
325 u32 fb = l2_input->feature_bitmap;
326 /* intf input features are masked by bridge domain */
327 if (l2_input->bridge)
328 fb &= l2input_bd_config (l2_input->bd_index)->feature_bitmap;
Neale Ranns5d9df1d2018-11-09 08:19:27 -0800329 vlib_cli_output (vm, "\nl2-input:\n%U", format_l2_input_features, fb,
330 1);
Eyal Bari942402b2017-07-26 11:57:04 +0300331
332 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
333 vlib_cli_output (vm, "\nl2-output:");
334 if (l2_output->out_vtr_flag)
335 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
336 vlib_cli_output (vm, "%U", format_l2_output_features,
Neale Ranns5d9df1d2018-11-09 08:19:27 -0800337 l2_output->feature_bitmap, 1);
Damjan Marion22311502016-10-28 20:30:15 +0200338 return 0;
339 }
Dave Barach7be864a2016-11-28 11:41:35 -0500340 if (show_tag)
341 {
342 u8 *tag;
343 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
344 vlib_cli_output (vm, "%U: %s",
345 format_vnet_sw_if_index_name, vnm, sw_if_index,
346 tag ? (char *) tag : "(none)");
347 return 0;
348 }
Damjan Marion22311502016-10-28 20:30:15 +0200349
Ed Warnickecb9cada2015-12-08 15:45:58 -0700350 if (!show_addresses)
Dave Barachba868bb2016-08-08 09:51:21 -0400351 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700352
Dave Barachba868bb2016-08-08 09:51:21 -0400353 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700354 {
355 /* Gather interfaces. */
Dave Barachba868bb2016-08-08 09:51:21 -0400356 sorted_sis =
357 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700358 _vec_len (sorted_sis) = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400359 /* *INDENT-OFF* */
360 pool_foreach (si, im->sw_interfaces,
361 ({
362 int visible = vnet_swif_is_api_visible (si);
363 if (visible)
364 vec_add1 (sorted_sis, si[0]);}
365 ));
Ole Troand7231612018-06-07 10:17:57 +0200366 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700367 /* Sort by name. */
368 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
369 }
370
371 if (show_addresses)
372 {
373 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400374 {
Dave Barachba868bb2016-08-08 09:51:21 -0400375 ip4_main_t *im4 = &ip4_main;
376 ip6_main_t *im6 = &ip6_main;
377 ip_lookup_main_t *lm4 = &im4->lookup_main;
378 ip_lookup_main_t *lm6 = &im6->lookup_main;
379 ip_interface_address_t *ia = 0;
Dave Barachba868bb2016-08-08 09:51:21 -0400380 u32 fib_index4 = 0, fib_index6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700381
Dave Barachba868bb2016-08-08 09:51:21 -0400382 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
383 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
384 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700385
Dave Barachba868bb2016-08-08 09:51:21 -0400386 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
387 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
388 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700389
John Lo4478d8e2018-01-12 17:15:25 -0500390 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
391 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700392
Dave Barachba868bb2016-08-08 09:51:21 -0400393 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
394 vlib_cli_output
395 (vm, "%U (%s): \n unnumbered, use %U",
John Lo4478d8e2018-01-12 17:15:25 -0500396 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400397 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
398 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400399 else
John Lo4478d8e2018-01-12 17:15:25 -0500400 vlib_cli_output
401 (vm, "%U (%s):",
402 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
403 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700404
Eyal Bari942402b2017-07-26 11:57:04 +0300405 /* Display any L2 info */
406 l2_input_config_t *l2_input = l2input_intf_config (si->sw_if_index);
407 if (l2_input->bridge)
Dave Barachba868bb2016-08-08 09:51:21 -0400408 {
John Lo4478d8e2018-01-12 17:15:25 -0500409 bd_main_t *bdm = &bd_main;
Eyal Bari942402b2017-07-26 11:57:04 +0300410 u32 bd_id = l2input_main.bd_configs[l2_input->bd_index].bd_id;
John Lo4478d8e2018-01-12 17:15:25 -0500411 vlib_cli_output (vm, " L2 bridge bd-id %d idx %d shg %d %s",
412 bd_id, bd_find_index (bdm, bd_id), l2_input->shg,
413 l2_input->bvi ? "bvi" : " ");
Dave Barachba868bb2016-08-08 09:51:21 -0400414 }
Eyal Bari942402b2017-07-26 11:57:04 +0300415 else if (l2_input->xconnect)
John Lo4478d8e2018-01-12 17:15:25 -0500416 vlib_cli_output (vm, " L2 xconnect %U",
417 format_vnet_sw_if_index_name, vnm,
418 l2_input->output_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400419
John Lo4478d8e2018-01-12 17:15:25 -0500420 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400421 /* Display any IP4 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500422 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
423 1 /* honor unnumbered */,
424 ({
425 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
426 if (fib4->table_id)
427 vlib_cli_output (vm, " L3 %U/%d ip4 table-id %d fib-idx %d",
428 format_ip4_address, r4, ia->address_length,
429 fib4->table_id,
430 ip4_fib_index_from_table_id (fib4->table_id));
431 else
432 vlib_cli_output (vm, " L3 %U/%d",
433 format_ip4_address, r4, ia->address_length);
434 }));
435 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700436
John Lo4478d8e2018-01-12 17:15:25 -0500437 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400438 /* Display any IP6 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500439 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
440 1 /* honor unnumbered */,
441 ({
442 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
443 if (fib6->table_id)
444 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
445 format_ip6_address, r6, ia->address_length,
446 fib6->table_id,
447 ip6_fib_index_from_table_id (fib6->table_id));
448 else
449 vlib_cli_output (vm, " L3 %U/%d",
450 format_ip6_address, r6, ia->address_length);
451 }));
452 /* *INDENT-ON* */
Ole Troand7231612018-06-07 10:17:57 +0200453 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700454 }
Ole Troand7231612018-06-07 10:17:57 +0200455 else
456 {
457 vec_foreach (si, sorted_sis)
458 {
459 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
460 }
461 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700462
Dave Barachba868bb2016-08-08 09:51:21 -0400463done:
Ole Troand7231612018-06-07 10:17:57 +0200464 vec_free (sorted_sis);
465 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700466}
467
Dave Barachba868bb2016-08-08 09:51:21 -0400468/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700469VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
Dave Barach13ad1f02017-03-26 19:36:18 -0400470 .path = "show interface",
Dave Barach525c9d02018-05-26 10:48:55 -0400471 .short_help = "show interface [address|addr|features|feat] [<interface> [<interface> [..]]] [verbose]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700472 .function = show_sw_interfaces,
Steven Luongc5fa2b82019-04-25 11:19:49 -0700473 .is_mp_safe = 1,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700474};
Dave Barachba868bb2016-08-08 09:51:21 -0400475/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700476
477/* Root of all interface commands. */
Dave Barachba868bb2016-08-08 09:51:21 -0400478/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700479VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
480 .path = "interface",
481 .short_help = "Interface commands",
482};
Dave Barachba868bb2016-08-08 09:51:21 -0400483/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700484
Dave Barachba868bb2016-08-08 09:51:21 -0400485/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700486VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
487 .path = "set interface",
488 .short_help = "Interface commands",
489};
Dave Barachba868bb2016-08-08 09:51:21 -0400490/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700491
492static clib_error_t *
493clear_interface_counters (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400494 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700495{
Dave Barachba868bb2016-08-08 09:51:21 -0400496 vnet_main_t *vnm = vnet_get_main ();
497 vnet_interface_main_t *im = &vnm->interface_main;
498 vlib_simple_counter_main_t *sm;
499 vlib_combined_counter_main_t *cm;
500 static vnet_main_t **my_vnet_mains;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700501 int i, j, n_counters;
502
503 vec_reset_length (my_vnet_mains);
Dave Barachba868bb2016-08-08 09:51:21 -0400504
Ed Warnickecb9cada2015-12-08 15:45:58 -0700505 for (i = 0; i < vec_len (vnet_mains); i++)
506 {
507 if (vnet_mains[i])
Dave Barachba868bb2016-08-08 09:51:21 -0400508 vec_add1 (my_vnet_mains, vnet_mains[i]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700509 }
510
511 if (vec_len (vnet_mains) == 0)
512 vec_add1 (my_vnet_mains, vnm);
513
514 n_counters = vec_len (im->combined_sw_if_counters);
515
516 for (j = 0; j < n_counters; j++)
517 {
Dave Barachba868bb2016-08-08 09:51:21 -0400518 for (i = 0; i < vec_len (my_vnet_mains); i++)
519 {
520 im = &my_vnet_mains[i]->interface_main;
521 cm = im->combined_sw_if_counters + j;
522 vlib_clear_combined_counters (cm);
523 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700524 }
525
526 n_counters = vec_len (im->sw_if_counters);
527
528 for (j = 0; j < n_counters; j++)
529 {
Dave Barachba868bb2016-08-08 09:51:21 -0400530 for (i = 0; i < vec_len (my_vnet_mains); i++)
531 {
532 im = &my_vnet_mains[i]->interface_main;
533 sm = im->sw_if_counters + j;
534 vlib_clear_simple_counters (sm);
535 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700536 }
537
538 return 0;
539}
540
Billy McFalle9bac692017-08-11 14:05:11 -0400541/*?
542 * Clear the statistics for all interfaces (statistics associated with the
543 * '<em>show interface</em>' command).
544 *
545 * @cliexpar
546 * Example of how to clear the statistics for all interfaces:
547 * @cliexcmd{clear interfaces}
548 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400549/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700550VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
551 .path = "clear interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400552 .short_help = "clear interfaces",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700553 .function = clear_interface_counters,
554};
Dave Barachba868bb2016-08-08 09:51:21 -0400555/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700556
Chris Luke16bcf7d2016-09-01 14:31:46 -0400557/**
558 * Parse subinterface names.
559 *
Dave Barachba868bb2016-08-08 09:51:21 -0400560 * The following subinterface syntax is supported. The first two are for
561 * backwards compatability:
562 *
563 * <intf-name> <id>
564 * - a subinterface with the name <intf-name>.<id>. The subinterface
565 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
566 *
567 * <intf-name> <min_id>-<max_id>
568 * - a set of the above subinterfaces, repeating for each id
569 * in the range <min_id> to <max_id>
570 *
571 * In the following, exact-match semantics (i.e. the number of vlan tags on the
572 * packet must match the number of tags in the configuration) are used only if
573 * the keyword exact-match is present. Non-exact match is the default.
574 *
575 * <intf-name> <id> dot1q <outer_id> [exact-match]
576 * - a subinterface with the name <intf-name>.<id>. The subinterface
577 * is a single dot1q vlan with vlan id <outer_id>.
578 *
579 * <intf-name> <id> dot1q any [exact-match]
580 * - a subinterface with the name <intf-name>.<id>. The subinterface
581 * is a single dot1q vlan with any vlan id.
582 *
583 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
584 * - a subinterface with the name <intf-name>.<id>. The subinterface
585 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
586 * <inner_id>.
587 *
588 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
589 * - a subinterface with the name <intf-name>.<id>. The subinterface
590 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
591 *
592 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
593 *
594 * - a subinterface with the name <intf-name>.<id>. The subinterface
595 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
596 *
597 * For each of the above CLI, there is a duplicate that uses the keyword
598 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
599 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
600 * tagged packets the inner ethertype is always 0x8100. Also note that
601 * the dot1q and dot1ad naming spaces are independent, so it is legal to
602 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
603 *
604 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
605 * - a subinterface with the name <intf-name>.<id>. The subinterface
606 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
607 * id <inner_id>.
608 *
609 * <intf-name> <id> untagged
610 * - a subinterface with the name <intf-name>.<id>. The subinterface
611 * has no vlan tags. Only one can be specified per interface.
612 *
613 * <intf-name> <id> default
614 * - a subinterface with the name <intf-name>.<id>. This is associated
615 * with a packet that did not match any other configured subinterface
616 * on this interface. Only one can be specified per interface.
617 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700618
619static clib_error_t *
Dave Barachba868bb2016-08-08 09:51:21 -0400620parse_vlan_sub_interfaces (unformat_input_t * input,
621 vnet_sw_interface_t * template)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700622{
Dave Barachba868bb2016-08-08 09:51:21 -0400623 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700624 u32 inner_vlan, outer_vlan;
625
Dave Barachba868bb2016-08-08 09:51:21 -0400626 if (unformat (input, "any inner-dot1q any"))
627 {
628 template->sub.eth.flags.two_tags = 1;
629 template->sub.eth.flags.outer_vlan_id_any = 1;
630 template->sub.eth.flags.inner_vlan_id_any = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700631 }
Dave Barachba868bb2016-08-08 09:51:21 -0400632 else if (unformat (input, "any"))
633 {
634 template->sub.eth.flags.one_tag = 1;
635 template->sub.eth.flags.outer_vlan_id_any = 1;
636 }
637 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
638 {
639 template->sub.eth.flags.two_tags = 1;
640 template->sub.eth.flags.inner_vlan_id_any = 1;
641 template->sub.eth.outer_vlan_id = outer_vlan;
642 }
643 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
644 {
645 template->sub.eth.flags.two_tags = 1;
646 template->sub.eth.outer_vlan_id = outer_vlan;
647 template->sub.eth.inner_vlan_id = inner_vlan;
648 }
649 else if (unformat (input, "%d", &outer_vlan))
650 {
651 template->sub.eth.flags.one_tag = 1;
652 template->sub.eth.outer_vlan_id = outer_vlan;
653 }
654 else
655 {
656 error = clib_error_return (0, "expected dot1q config, got `%U'",
657 format_unformat_error, input);
658 goto done;
659 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700660
Dave Barachba868bb2016-08-08 09:51:21 -0400661 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
662 {
663 if (unformat (input, "exact-match"))
664 {
665 template->sub.eth.flags.exact_match = 1;
666 }
667 }
668
669done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700670 return error;
671}
672
673static clib_error_t *
674create_sub_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400675 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700676{
Dave Barachba868bb2016-08-08 09:51:21 -0400677 vnet_main_t *vnm = vnet_get_main ();
678 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700679 u32 hw_if_index, sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400680 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700681 u32 id, id_min, id_max;
682 vnet_sw_interface_t template;
683
684 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400685 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700686 {
687 error = clib_error_return (0, "unknown interface `%U'",
688 format_unformat_error, input);
689 goto done;
690 }
691
Dave Barachb7b92992018-10-17 10:38:51 -0400692 clib_memset (&template, 0, sizeof (template));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700693 template.sub.eth.raw_flags = 0;
694
Dave Barachba868bb2016-08-08 09:51:21 -0400695 if (unformat (input, "%d default", &id_min))
696 {
697 id_max = id_min;
698 template.sub.eth.flags.default_sub = 1;
699 }
700 else if (unformat (input, "%d untagged", &id_min))
701 {
702 id_max = id_min;
703 template.sub.eth.flags.no_tags = 1;
704 template.sub.eth.flags.exact_match = 1;
705 }
706 else if (unformat (input, "%d dot1q", &id_min))
707 {
708 /* parse dot1q config */
709 id_max = id_min;
710 error = parse_vlan_sub_interfaces (input, &template);
711 if (error)
712 goto done;
713 }
714 else if (unformat (input, "%d dot1ad", &id_min))
715 {
716 /* parse dot1ad config */
717 id_max = id_min;
718 template.sub.eth.flags.dot1ad = 1;
719 error = parse_vlan_sub_interfaces (input, &template);
720 if (error)
721 goto done;
722 }
723 else if (unformat (input, "%d-%d", &id_min, &id_max))
724 {
725 template.sub.eth.flags.one_tag = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400726 template.sub.eth.flags.exact_match = 1;
727 if (id_min > id_max)
728 goto id_error;
729 }
730 else if (unformat (input, "%d", &id_min))
731 {
732 id_max = id_min;
733 template.sub.eth.flags.one_tag = 1;
734 template.sub.eth.outer_vlan_id = id_min;
735 template.sub.eth.flags.exact_match = 1;
736 }
737 else
738 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700739 id_error:
740 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
741 format_unformat_error, input);
742 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400743 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744
745 hi = vnet_get_hw_interface (vnm, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -0400746
Dave Barachba868bb2016-08-08 09:51:21 -0400747 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
748 {
749 error =
750 clib_error_return (0,
751 "not allowed as %v belong to a BondEthernet interface",
752 hi->name);
753 goto done;
754 }
John Lobcebbb92016-04-05 15:47:43 -0400755
Ed Warnickecb9cada2015-12-08 15:45:58 -0700756 for (id = id_min; id <= id_max; id++)
757 {
Dave Barachba868bb2016-08-08 09:51:21 -0400758 uword *p;
759 vnet_interface_main_t *im = &vnm->interface_main;
760 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
761 u64 *kp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700762
763 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
764 if (p)
Dave Barachba868bb2016-08-08 09:51:21 -0400765 {
766 if (CLIB_DEBUG > 0)
767 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
768 hi->sw_if_index, id);
769 continue;
770 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700771
772 kp = clib_mem_alloc (sizeof (*kp));
773 *kp = sup_and_sub_key;
774
775 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Eyal Baric5b13602016-11-24 19:42:43 +0200776 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700777 template.sup_sw_if_index = hi->sw_if_index;
778 template.sub.id = id;
Eyal Baria4509cf2016-09-26 09:24:09 +0300779 if (id_min < id_max)
780 template.sub.eth.outer_vlan_id = id;
781
Ed Warnickecb9cada2015-12-08 15:45:58 -0700782 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400783 if (error)
784 goto done;
Dave Barach16ad6ae2016-07-28 17:55:30 -0400785
Ed Warnickecb9cada2015-12-08 15:45:58 -0700786 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
787 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400788 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
789 vnet_get_main (), sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700790 }
791
Dave Barachba868bb2016-08-08 09:51:21 -0400792done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700793 return error;
794}
795
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700796/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400797 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
798 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
799 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
800 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
801 * but this is not recommended.
802 *
803 * This command has several variations:
804 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
805 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
806 *
807 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
808 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
809 * match any other subinterfaces should be sent to this subinterface.
810 *
811 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
812 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
813 * to this subinterface.
814 *
815 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
816 * subinterfaces to handle a range of VLAN IDs.
817 *
818 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700819 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
Billy McFalle9bac692017-08-11 14:05:11 -0400820 * VLAN ID different from the '<em>subId</em>'.
821 *
822 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
823 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700824 * the inner VLAN ID.
Billy McFalle9bac692017-08-11 14:05:11 -0400825 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700826 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
Billy McFalle9bac692017-08-11 14:05:11 -0400827 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
828 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
829 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
830 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
831 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
832 * entered, then the default behavior is exact-match.
833 *
834 * Use the '<em>show interface</em>' command to display all subinterfaces.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700835 *
836 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400837 * @parblock
838 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
839 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700840 *
Billy McFalle9bac692017-08-11 14:05:11 -0400841 * The previous example is shorthand and is equivalent to:
842 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700843 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700844 *
Billy McFalle9bac692017-08-11 14:05:11 -0400845 * Example of how to create a subinterface number that is different from the VLAN ID:
846 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700847 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700848 *
Billy McFalle9bac692017-08-11 14:05:11 -0400849 * Examples of how to create q-in-q and q-in-any subinterfaces:
850 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
851 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700852 *
Billy McFalle9bac692017-08-11 14:05:11 -0400853 * Examples of how to create dot1ad interfaces:
854 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
855 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700856 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700857 *
Billy McFalle9bac692017-08-11 14:05:11 -0400858 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
859 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
860 * is non-exact match:
861 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700862 *
Billy McFalle9bac692017-08-11 14:05:11 -0400863 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
864 * is specified and only one VLAN is configured, but packet contains two VLANs:
865 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700866 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700867 *
Billy McFalle9bac692017-08-11 14:05:11 -0400868 * Example of how to created a subinterface to process untagged packets:
869 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
870 *
871 * Example of how to created a subinterface to process any packet with a VLAN ID that
872 * does not match any other subinterface:
873 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
874 *
875 * When subinterfaces are created, they are in the down state. Example of how to
876 * enable a newly created subinterface:
877 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
878 * @endparblock
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700879 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400880/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700881VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700882 .path = "create sub-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400883 .short_help = "create sub-interfaces <interface> "
884 "{<subId> [default|untagged]} | "
885 "{<subId>-<subId>} | "
886 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700887 .function = create_sub_interfaces,
888};
Dave Barachba868bb2016-08-08 09:51:21 -0400889/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700890
891static clib_error_t *
892set_state (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400893 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700894{
Dave Barachba868bb2016-08-08 09:51:21 -0400895 vnet_main_t *vnm = vnet_get_main ();
896 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700897 u32 sw_if_index, flags;
898
899 sw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400900 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700901 {
902 error = clib_error_return (0, "unknown interface `%U'",
903 format_unformat_error, input);
904 goto done;
905 }
906
Dave Barachba868bb2016-08-08 09:51:21 -0400907 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700908 {
909 error = clib_error_return (0, "unknown flags `%U'",
910 format_unformat_error, input);
911 goto done;
912 }
913
914 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
915 if (error)
916 goto done;
917
Dave Barachba868bb2016-08-08 09:51:21 -0400918done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700919 return error;
920}
921
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700922
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700923/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400924 * This command is used to change the admin state (up/down) of an interface.
925 *
926 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
927 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
928 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
929 * '<em>punt</em>' flag (interface is still down).
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700930 *
931 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400932 * Example of how to configure the admin state of an interface to '<em>up</em?':
933 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
934 * Example of how to configure the admin state of an interface to '<em>down</em?':
935 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700936 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400937/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700938VLIB_CLI_COMMAND (set_state_command, static) = {
939 .path = "set interface state",
Billy McFalle9bac692017-08-11 14:05:11 -0400940 .short_help = "set interface state <interface> [up|down|punt|enable]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700941 .function = set_state,
942};
Dave Barachba868bb2016-08-08 09:51:21 -0400943/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700944
945static clib_error_t *
946set_unnumbered (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400947 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700948{
Dave Barachba868bb2016-08-08 09:51:21 -0400949 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700950 u32 unnumbered_sw_if_index = ~0;
951 u32 inherit_from_sw_if_index = ~0;
952 int enable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700953
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700954 if (unformat (input, "%U use %U",
955 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
956 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700957 enable = 1;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700958 else if (unformat (input, "del %U",
959 unformat_vnet_sw_interface, vnm,
960 &unnumbered_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700961 enable = 0;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700962 else
963 return clib_error_return (0, "parse error '%U'",
964 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700965
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700966 if (~0 == unnumbered_sw_if_index)
967 return clib_error_return (0, "Specify the unnumbered interface");
968 if (enable && ~0 == inherit_from_sw_if_index)
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700969 return clib_error_return (0, "When enabling unnumbered specify the"
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700970 " IP enabled interface that it uses");
Neale Ranns898273f2017-03-18 02:57:38 -0700971
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700972 vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index,
973 inherit_from_sw_if_index, enable);
Neale Ranns898273f2017-03-18 02:57:38 -0700974
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700975 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700976}
977
Dave Barachba868bb2016-08-08 09:51:21 -0400978/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700979VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
980 .path = "set interface unnumbered",
Billy McFalle9bac692017-08-11 14:05:11 -0400981 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700982 .function = set_unnumbered,
983};
Dave Barachba868bb2016-08-08 09:51:21 -0400984/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700985
986
987
988static clib_error_t *
989set_hw_class (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400990 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700991{
Dave Barachba868bb2016-08-08 09:51:21 -0400992 vnet_main_t *vnm = vnet_get_main ();
993 vnet_interface_main_t *im = &vnm->interface_main;
994 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700995 u32 hw_if_index, hw_class_index;
996
997 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400998 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700999 {
1000 error = clib_error_return (0, "unknown hardware interface `%U'",
1001 format_unformat_error, input);
1002 goto done;
1003 }
1004
Dave Barachba868bb2016-08-08 09:51:21 -04001005 if (!unformat_user (input, unformat_hash_string,
1006 im->hw_interface_class_by_name, &hw_class_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001007 {
1008 error = clib_error_return (0, "unknown hardware class `%U'",
1009 format_unformat_error, input);
1010 goto done;
1011 }
1012
1013 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1014 if (error)
1015 goto done;
1016
Dave Barachba868bb2016-08-08 09:51:21 -04001017done:
Ed Warnickecb9cada2015-12-08 15:45:58 -07001018 return error;
1019}
1020
Dave Barachba868bb2016-08-08 09:51:21 -04001021/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001022VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1023 .path = "set interface hw-class",
1024 .short_help = "Set interface hardware class",
1025 .function = set_hw_class,
1026};
Dave Barachba868bb2016-08-08 09:51:21 -04001027/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001028
Dave Barachba868bb2016-08-08 09:51:21 -04001029static clib_error_t *
1030vnet_interface_cli_init (vlib_main_t * vm)
1031{
1032 return 0;
1033}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001034
1035VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1036
Dave Barachba868bb2016-08-08 09:51:21 -04001037static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07001038renumber_interface_command_fn (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001039 unformat_input_t * input,
1040 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001041{
1042 u32 hw_if_index;
1043 u32 new_dev_instance;
Dave Barachba868bb2016-08-08 09:51:21 -04001044 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001045 int rv;
1046
Dave Barachba868bb2016-08-08 09:51:21 -04001047 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001048 return clib_error_return (0, "unknown hardware interface `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001049 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001050
Dave Barachba868bb2016-08-08 09:51:21 -04001051 if (!unformat (input, "%d", &new_dev_instance))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001052 return clib_error_return (0, "new dev instance missing");
1053
1054 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1055
1056 switch (rv)
1057 {
1058 case 0:
1059 break;
1060
1061 default:
1062 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
Dave Barachba868bb2016-08-08 09:51:21 -04001063 rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001064
1065 }
1066
1067 return 0;
1068}
1069
1070
Dave Barachba868bb2016-08-08 09:51:21 -04001071/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001072VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1073 .path = "renumber interface",
Billy McFalle9bac692017-08-11 14:05:11 -04001074 .short_help = "renumber interface <interface> <new-dev-instance>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001075 .function = renumber_interface_command_fn,
1076};
Dave Barachba868bb2016-08-08 09:51:21 -04001077/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001078
Damjan Marion8358ff92016-04-15 14:26:00 +02001079static clib_error_t *
1080promiscuous_cmd (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001081 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion8358ff92016-04-15 14:26:00 +02001082{
Dave Barachba868bb2016-08-08 09:51:21 -04001083 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001084 u32 hw_if_index;
1085 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
Dave Barachba868bb2016-08-08 09:51:21 -04001086 ethernet_main_t *em = &ethernet_main;
1087 ethernet_interface_t *eif;
Damjan Marion8358ff92016-04-15 14:26:00 +02001088
1089 if (unformat (input, "on %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001090 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001091 ;
1092 else if (unformat (input, "off %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001093 unformat_ethernet_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001094 flags = 0;
1095 else
1096 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001097 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001098
1099 eif = ethernet_get_interface (em, hw_if_index);
1100 if (!eif)
1101 return clib_error_return (0, "not supported");
1102
1103 ethernet_set_flags (vnm, hw_if_index, flags);
1104 return 0;
1105}
1106
Dave Barachba868bb2016-08-08 09:51:21 -04001107/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001108VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1109 .path = "set interface promiscuous",
Billy McFalle9bac692017-08-11 14:05:11 -04001110 .short_help = "set interface promiscuous [on|off] <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001111 .function = promiscuous_cmd,
1112};
Dave Barachba868bb2016-08-08 09:51:21 -04001113/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001114
1115static clib_error_t *
1116mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1117{
Dave Barachba868bb2016-08-08 09:51:21 -04001118 vnet_main_t *vnm = vnet_get_main ();
Ole Troand7231612018-06-07 10:17:57 +02001119 u32 hw_if_index, sw_if_index, mtu;
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001120 ethernet_main_t *em = &ethernet_main;
Ole Troand7231612018-06-07 10:17:57 +02001121 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
Damjan Marion8358ff92016-04-15 14:26:00 +02001122
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001123 if (unformat (input, "%d %U", &mtu,
1124 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001125 {
Ole Troand7231612018-06-07 10:17:57 +02001126 /*
1127 * Change physical MTU on interface. Only supported for Ethernet
1128 * interfaces
1129 */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001130 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1131 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1132
1133 if (!eif)
1134 return clib_error_return (0, "not supported");
1135
1136 if (mtu < hi->min_supported_packet_bytes)
1137 return clib_error_return (0, "Invalid mtu (%d): "
1138 "must be >= min pkt bytes (%d)", mtu,
1139 hi->min_supported_packet_bytes);
1140
1141 if (mtu > hi->max_supported_packet_bytes)
1142 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1143 hi->max_supported_packet_bytes);
1144
1145 vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
Ole Troand7231612018-06-07 10:17:57 +02001146 goto done;
Damjan Marion8358ff92016-04-15 14:26:00 +02001147 }
Ole Troand7231612018-06-07 10:17:57 +02001148 else if (unformat (input, "packet %d %U", &mtu,
1149 unformat_vnet_sw_interface, vnm, &sw_if_index))
1150 /* Set default packet MTU (including L3 header */
1151 mtus[VNET_MTU_L3] = mtu;
1152 else if (unformat (input, "ip4 %d %U", &mtu,
1153 unformat_vnet_sw_interface, vnm, &sw_if_index))
1154 mtus[VNET_MTU_IP4] = mtu;
1155 else if (unformat (input, "ip6 %d %U", &mtu,
1156 unformat_vnet_sw_interface, vnm, &sw_if_index))
1157 mtus[VNET_MTU_IP6] = mtu;
1158 else if (unformat (input, "mpls %d %U", &mtu,
1159 unformat_vnet_sw_interface, vnm, &sw_if_index))
1160 mtus[VNET_MTU_MPLS] = mtu;
Damjan Marion8358ff92016-04-15 14:26:00 +02001161 else
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001162 return clib_error_return (0, "unknown input `%U'",
1163 format_unformat_error, input);
Ole Troand7231612018-06-07 10:17:57 +02001164
1165 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1166
1167done:
Damjan Marion8358ff92016-04-15 14:26:00 +02001168 return 0;
1169}
1170
Dave Barachba868bb2016-08-08 09:51:21 -04001171/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001172VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1173 .path = "set interface mtu",
Ole Troand7231612018-06-07 10:17:57 +02001174 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001175 .function = mtu_cmd,
1176};
Dave Barachba868bb2016-08-08 09:51:21 -04001177/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001178
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001179static clib_error_t *
1180set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1181 vlib_cli_command_t * cmd)
1182{
1183 vnet_main_t *vnm = vnet_get_main ();
Neale Rannsd867a7c2017-10-04 02:29:07 -07001184 vnet_sw_interface_t *si = NULL;
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001185 clib_error_t *error = 0;
1186 u32 sw_if_index = ~0;
John Lo62fcc0a2017-10-31 14:31:10 -04001187 u8 mac[6] = { 0 };
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001188
1189 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1190 {
1191 error = clib_error_return (0, "unknown interface `%U'",
1192 format_unformat_error, input);
1193 goto done;
1194 }
John Lo62fcc0a2017-10-31 14:31:10 -04001195 if (!unformat_user (input, unformat_ethernet_address, mac))
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001196 {
1197 error = clib_error_return (0, "expected mac address `%U'",
1198 format_unformat_error, input);
1199 goto done;
1200 }
Neale Rannsd867a7c2017-10-04 02:29:07 -07001201 si = vnet_get_sw_interface (vnm, sw_if_index);
1202 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001203done:
1204 return error;
1205}
1206
1207/*?
1208 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1209 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1210 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1211 *
1212 * @cliexpar
1213 * @parblock
1214 * Example of how to change MAC Address of interface:
1215 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1216 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1217 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1218 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1219 * @endparblock
1220?*/
1221/* *INDENT-OFF* */
1222VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1223 .path = "set interface mac address",
Billy McFalle9bac692017-08-11 14:05:11 -04001224 .short_help = "set interface mac address <interface> <mac-address>",
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001225 .function = set_interface_mac_address,
1226};
1227/* *INDENT-ON* */
1228
Dave Barach7be864a2016-11-28 11:41:35 -05001229static clib_error_t *
1230set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1231{
1232 vnet_main_t *vnm = vnet_get_main ();
1233 u32 sw_if_index = ~0;
1234 u8 *tag = 0;
1235
1236 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1237 vnm, &sw_if_index, &tag))
1238 return clib_error_return (0, "unknown input `%U'",
1239 format_unformat_error, input);
1240
1241 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1242
1243 return 0;
1244}
1245
1246/* *INDENT-OFF* */
1247VLIB_CLI_COMMAND (set_tag_command, static) = {
1248 .path = "set interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001249 .short_help = "set interface tag <interface> <tag>",
Dave Barach7be864a2016-11-28 11:41:35 -05001250 .function = set_tag,
1251};
1252/* *INDENT-ON* */
1253
1254static clib_error_t *
1255clear_tag (vlib_main_t * vm, unformat_input_t * input,
1256 vlib_cli_command_t * cmd)
1257{
1258 vnet_main_t *vnm = vnet_get_main ();
1259 u32 sw_if_index = ~0;
1260
1261 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1262 return clib_error_return (0, "unknown input `%U'",
1263 format_unformat_error, input);
1264
1265 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1266
1267 return 0;
1268}
1269
1270/* *INDENT-OFF* */
1271VLIB_CLI_COMMAND (clear_tag_command, static) = {
1272 .path = "clear interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001273 .short_help = "clear interface tag <interface>",
Dave Barach7be864a2016-11-28 11:41:35 -05001274 .function = clear_tag,
1275};
1276/* *INDENT-ON* */
1277
Damjan Marion44036902017-04-28 12:29:15 +02001278static clib_error_t *
Neale Ranns1855b8e2018-07-11 10:31:26 -07001279set_ip_directed_broadcast (vlib_main_t * vm,
1280 unformat_input_t * input, vlib_cli_command_t * cmd)
1281{
1282 vnet_main_t *vnm = vnet_get_main ();
1283 u32 sw_if_index = ~0;
1284 u8 enable = 0;
1285
1286 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1287 else if (unformat (input, "enable"))
1288 enable = 1;
1289 else if (unformat (input, "disable"))
1290 enable = 0;
1291 else
1292 return clib_error_return (0, "unknown input: `%U'",
1293 format_unformat_error, input);
1294
1295 if (~0 == sw_if_index)
1296 return clib_error_return (0, "specify an interface: `%U'",
1297 format_unformat_error, input);
1298
1299 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1300
1301 return 0;
1302}
1303
1304/*?
1305 * This command is used to enable/disable IP directed broadcast
1306 * If directed broadcast is enabled a packet sent to the interface's
1307 * subnet broadcast address will be sent L2 broadcast on the interface,
1308 * otherwise it is dropped.
1309 ?*/
1310/* *INDENT-OFF* */
1311VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1312 .path = "set interface ip directed-broadcast",
1313 .short_help = "set interface enable <interface> <enable|disable>",
1314 .function = set_ip_directed_broadcast,
1315};
1316/* *INDENT-ON* */
1317
1318static clib_error_t *
Stevene3a395c2017-05-09 16:19:50 -07001319set_hw_interface_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1320 u32 queue_id, vnet_hw_interface_rx_mode mode)
1321{
1322 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1323 vnet_device_class_t *dev_class =
1324 vnet_get_device_class (vnm, hw->dev_class_index);
1325 clib_error_t *error;
1326 vnet_hw_interface_rx_mode old_mode;
1327 int rv;
1328
Damjan Marion4e53a0d2017-06-21 14:29:44 +02001329 if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT)
1330 mode = hw->default_rx_mode;
1331
Stevene3a395c2017-05-09 16:19:50 -07001332 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &old_mode);
1333 switch (rv)
1334 {
1335 case 0:
1336 if (old_mode == mode)
1337 return 0; /* same rx-mode, no change */
1338 break;
1339 case VNET_API_ERROR_INVALID_INTERFACE:
1340 return clib_error_return (0, "invalid interface");
Stevenbd8a6112017-07-30 10:29:26 -07001341 case VNET_API_ERROR_INVALID_QUEUE:
1342 return clib_error_return (0, "invalid queue");
Stevene3a395c2017-05-09 16:19:50 -07001343 default:
1344 return clib_error_return (0, "unknown error");
1345 }
1346
1347 if (dev_class->rx_mode_change_function)
1348 {
1349 error = dev_class->rx_mode_change_function (vnm, hw_if_index, queue_id,
1350 mode);
1351 if (error)
1352 return (error);
1353 }
1354
1355 rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1356 switch (rv)
1357 {
1358 case 0:
1359 break;
1360 case VNET_API_ERROR_UNSUPPORTED:
1361 return clib_error_return (0, "unsupported");
1362 case VNET_API_ERROR_INVALID_INTERFACE:
1363 return clib_error_return (0, "invalid interface");
Stevenbd8a6112017-07-30 10:29:26 -07001364 case VNET_API_ERROR_INVALID_QUEUE:
1365 return clib_error_return (0, "invalid queue");
Stevene3a395c2017-05-09 16:19:50 -07001366 default:
1367 return clib_error_return (0, "unknown error");
1368 }
1369
1370 return 0;
1371}
1372
Stevenad8015b2017-10-29 22:10:46 -07001373clib_error_t *
1374set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1375 u8 queue_id_valid, u32 queue_id,
1376 vnet_hw_interface_rx_mode mode)
1377{
1378 clib_error_t *error = 0;
1379 vnet_hw_interface_t *hw;
1380 int i;
1381
1382 hw = vnet_get_hw_interface (vnm, hw_if_index);
1383
1384 if (queue_id_valid == 0)
1385 {
1386 for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1387 {
1388 error = set_hw_interface_rx_mode (vnm, hw_if_index, i, mode);
1389 if (error)
1390 break;
1391 }
1392 hw->default_rx_mode = mode;
1393 }
1394 else
1395 error = set_hw_interface_rx_mode (vnm, hw_if_index, queue_id, mode);
1396
1397 return (error);
1398}
1399
Stevene3a395c2017-05-09 16:19:50 -07001400static clib_error_t *
Damjan Marion44036902017-04-28 12:29:15 +02001401set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1402 vlib_cli_command_t * cmd)
1403{
1404 clib_error_t *error = 0;
1405 unformat_input_t _line_input, *line_input = &_line_input;
1406 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion44036902017-04-28 12:29:15 +02001407 u32 hw_if_index = (u32) ~ 0;
1408 u32 queue_id = (u32) ~ 0;
1409 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
Stevenad8015b2017-10-29 22:10:46 -07001410 u8 queue_id_valid = 0;
Dave Barach7be864a2016-11-28 11:41:35 -05001411
Damjan Marion44036902017-04-28 12:29:15 +02001412 if (!unformat_user (input, unformat_line_input, line_input))
1413 return 0;
1414
1415 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1416 {
1417 if (unformat
1418 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1419 ;
1420 else if (unformat (line_input, "queue %d", &queue_id))
Stevenad8015b2017-10-29 22:10:46 -07001421 queue_id_valid = 1;
Damjan Marion44036902017-04-28 12:29:15 +02001422 else if (unformat (line_input, "polling"))
1423 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
1424 else if (unformat (line_input, "interrupt"))
1425 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
1426 else if (unformat (line_input, "adaptive"))
1427 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
1428 else
1429 {
1430 error = clib_error_return (0, "parse error: '%U'",
1431 format_unformat_error, line_input);
1432 unformat_free (line_input);
1433 return error;
1434 }
1435 }
1436
1437 unformat_free (line_input);
1438
1439 if (hw_if_index == (u32) ~ 0)
1440 return clib_error_return (0, "please specify valid interface name");
1441
1442 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
1443 return clib_error_return (0, "please specify valid rx-mode");
1444
Stevenad8015b2017-10-29 22:10:46 -07001445 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1446 queue_id, mode);
Damjan Marion44036902017-04-28 12:29:15 +02001447
Stevene3a395c2017-05-09 16:19:50 -07001448 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001449}
1450
1451/*?
Billy McFalle9bac692017-08-11 14:05:11 -04001452 * This command is used to assign the RX packet processing mode (polling,
1453 * interrupt, adaptive) of the a given interface, and optionally a
1454 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1455 * is applied to all queues of the interface. Not all interfaces support
1456 * all modes. To display the current rx-mode use the command
1457 * '<em>show interface rx-placement</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001458 *
1459 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -04001460 * Example of how to assign rx-mode to all queues on an interface:
1461 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1462 * Example of how to assign rx-mode to one queue of an interface:
1463 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1464 * Example of how to display the rx-mode of all interfaces:
Damjan Marion44036902017-04-28 12:29:15 +02001465 * @cliexstart{show interface rx-placement}
1466 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001467 * node dpdk-input:
1468 * GigabitEthernet7/0/0 queue 0 (polling)
1469 * node vhost-user-input:
1470 * VirtualEthernet0/0/12 queue 0 (interrupt)
1471 * VirtualEthernet0/0/12 queue 2 (polling)
1472 * VirtualEthernet0/0/13 queue 0 (polling)
1473 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001474 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001475 * node dpdk-input:
1476 * GigabitEthernet7/0/1 queue 0 (polling)
1477 * node vhost-user-input:
1478 * VirtualEthernet0/0/12 queue 1 (polling)
1479 * VirtualEthernet0/0/12 queue 3 (polling)
1480 * VirtualEthernet0/0/13 queue 1 (polling)
1481 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001482 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001483?*/
1484/* *INDENT-OFF* */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001485VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
Damjan Marion44036902017-04-28 12:29:15 +02001486 .path = "set interface rx-mode",
1487 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1488 .function = set_interface_rx_mode,
1489};
1490/* *INDENT-ON* */
1491
1492static clib_error_t *
1493show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1494 vlib_cli_command_t * cmd)
1495{
1496 u8 *s = 0;
1497 vnet_main_t *vnm = vnet_get_main ();
1498 vnet_device_input_runtime_t *rt;
1499 vnet_device_and_queue_t *dq;
1500 vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
1501 uword si;
1502 int index = 0;
1503
1504 /* *INDENT-OFF* */
1505 foreach_vlib_main (({
1506 clib_bitmap_foreach (si, pn->sibling_bitmap,
1507 ({
1508 rt = vlib_node_get_runtime_data (this_vlib_main, si);
1509
1510 if (vec_len (rt->devices_and_queues))
1511 s = format (s, " node %U:\n", format_vlib_node_name, vm, si);
1512
1513 vec_foreach (dq, rt->devices_and_queues)
1514 {
Steven9d6d9892017-06-30 07:15:02 -07001515 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm,
1516 dq->hw_if_index);
Damjan Marion44036902017-04-28 12:29:15 +02001517 s = format (s, " %U queue %u (%U)\n",
Steven9d6d9892017-06-30 07:15:02 -07001518 format_vnet_sw_if_index_name, vnm, hi->sw_if_index,
Damjan Marion44036902017-04-28 12:29:15 +02001519 dq->queue_id,
1520 format_vnet_hw_interface_rx_mode, dq->mode);
1521 }
1522 }));
1523 if (vec_len (s) > 0)
1524 {
Steven84f36cb2018-09-26 10:44:54 -07001525 vlib_cli_output(vm, "Thread %u (%s):\n%v", index,
Damjan Marion44036902017-04-28 12:29:15 +02001526 vlib_worker_threads[index].name, s);
1527 vec_reset_length (s);
1528 }
1529 index++;
1530 }));
1531 /* *INDENT-ON* */
1532
1533 vec_free (s);
1534 return 0;
1535}
1536
Billy McFalle9bac692017-08-11 14:05:11 -04001537/*?
1538 * This command is used to display the interface and queue worker
1539 * thread placement.
1540 *
1541 * @cliexpar
1542 * Example of how to display the interface placement:
1543 * @cliexstart{show interface rx-placement}
1544 * Thread 1 (vpp_wk_0):
1545 * node dpdk-input:
1546 * GigabitEthernet7/0/0 queue 0 (polling)
1547 * node vhost-user-input:
1548 * VirtualEthernet0/0/12 queue 0 (polling)
1549 * VirtualEthernet0/0/12 queue 2 (polling)
1550 * VirtualEthernet0/0/13 queue 0 (polling)
1551 * VirtualEthernet0/0/13 queue 2 (polling)
1552 * Thread 2 (vpp_wk_1):
1553 * node dpdk-input:
1554 * GigabitEthernet7/0/1 queue 0 (polling)
1555 * node vhost-user-input:
1556 * VirtualEthernet0/0/12 queue 1 (polling)
1557 * VirtualEthernet0/0/12 queue 3 (polling)
1558 * VirtualEthernet0/0/13 queue 1 (polling)
1559 * VirtualEthernet0/0/13 queue 3 (polling)
1560 * @cliexend
1561?*/
Damjan Marion44036902017-04-28 12:29:15 +02001562/* *INDENT-OFF* */
1563VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1564 .path = "show interface rx-placement",
1565 .short_help = "show interface rx-placement",
1566 .function = show_interface_rx_placement_fn,
1567};
1568/* *INDENT-ON* */
1569
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001570clib_error_t *
1571set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1572 u32 thread_index, u8 is_main)
Damjan Marion44036902017-04-28 12:29:15 +02001573{
Damjan Marion44036902017-04-28 12:29:15 +02001574 vnet_main_t *vnm = vnet_get_main ();
1575 vnet_device_main_t *vdm = &vnet_device_main;
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001576 clib_error_t *error = 0;
1577 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
Damjan Marion44036902017-04-28 12:29:15 +02001578 int rv;
1579
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001580 if (is_main)
1581 thread_index = 0;
1582 else
1583 thread_index += vdm->first_worker_thread_index;
Damjan Marion44036902017-04-28 12:29:15 +02001584
1585 if (thread_index > vdm->last_worker_thread_index)
1586 return clib_error_return (0,
1587 "please specify valid worker thread or main");
1588
1589 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode);
1590
1591 if (rv)
1592 return clib_error_return (0, "not found");
1593
1594 rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id);
1595
1596 if (rv)
1597 return clib_error_return (0, "not found");
1598
1599 vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id,
1600 thread_index);
1601 vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1602
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001603 return (error);
1604}
1605
1606static clib_error_t *
1607set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input,
1608 vlib_cli_command_t * cmd)
1609{
1610 clib_error_t *error = 0;
1611 unformat_input_t _line_input, *line_input = &_line_input;
1612 vnet_main_t *vnm = vnet_get_main ();
1613 u32 hw_if_index = (u32) ~ 0;
1614 u32 queue_id = (u32) 0;
1615 u32 thread_index = (u32) ~ 0;
1616 u8 is_main = 0;
1617
1618 if (!unformat_user (input, unformat_line_input, line_input))
1619 return 0;
1620
1621 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1622 {
1623 if (unformat
1624 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1625 ;
1626 else if (unformat (line_input, "queue %d", &queue_id))
1627 ;
1628 else if (unformat (line_input, "main", &thread_index))
1629 is_main = 1;
1630 else if (unformat (line_input, "worker %d", &thread_index))
1631 ;
1632 else
1633 {
1634 error = clib_error_return (0, "parse error: '%U'",
1635 format_unformat_error, line_input);
1636 unformat_free (line_input);
1637 return error;
1638 }
1639 }
1640
1641 unformat_free (line_input);
1642
1643 if (hw_if_index == (u32) ~ 0)
1644 return clib_error_return (0, "please specify valid interface name");
1645
1646 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1647 is_main);
1648
1649 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001650}
1651
1652/*?
1653 * This command is used to assign a given interface, and optionally a
1654 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
Billy McFalle9bac692017-08-11 14:05:11 -04001655 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1656 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001657 *
1658 * @cliexpar
1659 * Example of how to display the interface placement:
Billy McFalle9bac692017-08-11 14:05:11 -04001660 * @cliexstart{show interface rx-placement}
Damjan Marion44036902017-04-28 12:29:15 +02001661 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001662 * node dpdk-input:
1663 * GigabitEthernet7/0/0 queue 0 (polling)
1664 * node vhost-user-input:
1665 * VirtualEthernet0/0/12 queue 0 (polling)
1666 * VirtualEthernet0/0/12 queue 2 (polling)
1667 * VirtualEthernet0/0/13 queue 0 (polling)
1668 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001669 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001670 * node dpdk-input:
1671 * GigabitEthernet7/0/1 queue 0 (polling)
1672 * node vhost-user-input:
1673 * VirtualEthernet0/0/12 queue 1 (polling)
1674 * VirtualEthernet0/0/12 queue 3 (polling)
1675 * VirtualEthernet0/0/13 queue 1 (polling)
1676 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001677 * @cliexend
Billy McFalle9bac692017-08-11 14:05:11 -04001678 * Example of how to assign a interface and queue to a worker thread:
1679 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1680 * Example of how to display the interface placement:
1681 * @cliexstart{show interface rx-placement}
1682 * Thread 1 (vpp_wk_0):
1683 * node dpdk-input:
1684 * GigabitEthernet7/0/0 queue 0 (polling)
1685 * node vhost-user-input:
1686 * VirtualEthernet0/0/12 queue 0 (polling)
1687 * VirtualEthernet0/0/12 queue 1 (polling)
1688 * VirtualEthernet0/0/12 queue 2 (polling)
1689 * VirtualEthernet0/0/13 queue 0 (polling)
1690 * VirtualEthernet0/0/13 queue 2 (polling)
1691 * Thread 2 (vpp_wk_1):
1692 * node dpdk-input:
1693 * GigabitEthernet7/0/1 queue 0 (polling)
1694 * node vhost-user-input:
1695 * VirtualEthernet0/0/12 queue 3 (polling)
1696 * VirtualEthernet0/0/13 queue 1 (polling)
1697 * VirtualEthernet0/0/13 queue 3 (polling)
1698 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001699?*/
1700/* *INDENT-OFF* */
1701VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1702 .path = "set interface rx-placement",
Billy McFalle9bac692017-08-11 14:05:11 -04001703 .short_help = "set interface rx-placement <interface> [queue <n>] "
Damjan Marion6f9ac652017-06-15 19:01:31 +02001704 "[worker <n> | main]",
Damjan Marion44036902017-04-28 12:29:15 +02001705 .function = set_interface_rx_placement,
Damjan Marion6f9ac652017-06-15 19:01:31 +02001706 .is_mp_safe = 1,
Damjan Marion44036902017-04-28 12:29:15 +02001707};
Damjan Marion44036902017-04-28 12:29:15 +02001708/* *INDENT-ON* */
Dave Barach5ecd5a52019-02-25 15:27:28 -05001709
1710static inline clib_error_t *
1711pcap_trace_command_internal (vlib_main_t * vm,
1712 unformat_input_t * input,
1713 vlib_cli_command_t * cmd, int rx_tx)
1714{
1715#define PCAP_DEF_PKT_TO_CAPTURE (1000)
1716
1717 unformat_input_t _line_input, *line_input = &_line_input;
1718 u8 *filename;
1719 u8 *chroot_filename = 0;
1720 u32 max = 0;
1721 int enabled = 0;
1722 int errorFlag = 0;
1723 clib_error_t *error = 0;
1724 vnet_main_t *vnm = vnet_get_main ();
1725
1726 /* Get a line of input. */
1727 if (!unformat_user (input, unformat_line_input, line_input))
1728 return 0;
1729
1730 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1731 {
1732 if (unformat (line_input, "on"))
1733 {
1734 if (vm->pcap[rx_tx].pcap_enable == 0)
1735 {
1736 enabled = 1;
1737 }
1738 else
1739 {
Jack Xuf7537442019-03-26 13:46:00 -04001740 vlib_cli_output (vm, "pcap %s capture already on...",
1741 (rx_tx == VLIB_RX) ? "rx" : "tx");
Dave Barach5ecd5a52019-02-25 15:27:28 -05001742 errorFlag = 1;
1743 break;
1744 }
1745 }
1746 else if (unformat (line_input, "off"))
1747 {
1748 if (vm->pcap[rx_tx].pcap_enable)
1749 {
1750 vlib_cli_output
1751 (vm, "captured %d pkts...",
1752 vm->pcap[rx_tx].pcap_main.n_packets_captured);
1753 if (vm->pcap[rx_tx].pcap_main.n_packets_captured)
1754 {
1755 vm->pcap[rx_tx].pcap_main.n_packets_to_capture =
1756 vm->pcap[rx_tx].pcap_main.n_packets_captured;
1757 error = pcap_write (&vm->pcap[rx_tx].pcap_main);
1758 if (error)
1759 clib_error_report (error);
1760 else
1761 vlib_cli_output (vm, "saved to %s...",
1762 vm->pcap[rx_tx].pcap_main.file_name);
1763 }
1764
1765 vm->pcap[rx_tx].pcap_enable = 0;
1766 }
1767 else
1768 {
Jack Xuf7537442019-03-26 13:46:00 -04001769 vlib_cli_output (vm, "pcap %s capture already off...",
1770 (rx_tx == VLIB_RX) ? "rx" : "tx");
Dave Barach5ecd5a52019-02-25 15:27:28 -05001771 errorFlag = 1;
1772 break;
1773 }
1774 }
1775 else if (unformat (line_input, "max %d", &max))
1776 {
1777 if (vm->pcap[rx_tx].pcap_enable)
1778 {
1779 vlib_cli_output
1780 (vm,
1781 "can't change max value while pcap tx capture active...");
1782 errorFlag = 1;
1783 break;
1784 }
1785 vm->pcap[rx_tx].pcap_main.n_packets_to_capture = max;
1786 }
1787 else if (unformat (line_input, "intfc %U",
1788 unformat_vnet_sw_interface, vnm,
1789 &vm->pcap[rx_tx].pcap_sw_if_index))
1790 ;
1791
1792 else if (unformat (line_input, "intfc any"))
1793 {
1794 vm->pcap[rx_tx].pcap_sw_if_index = 0;
1795 }
1796 else if (unformat (line_input, "file %s", &filename))
1797 {
1798 if (vm->pcap[rx_tx].pcap_enable)
1799 {
1800 vlib_cli_output
1801 (vm, "can't change file while pcap tx capture active...");
1802 errorFlag = 1;
1803 break;
1804 }
1805
1806 /* Brain-police user path input */
1807 if (strstr ((char *) filename, "..")
1808 || index ((char *) filename, '/'))
1809 {
1810 vlib_cli_output (vm, "illegal characters in filename '%s'",
1811 filename);
1812 vlib_cli_output (vm, "Hint: .. and / are not allowed.");
1813 vec_free (filename);
1814 errorFlag = 1;
1815 break;
1816 }
1817
1818 chroot_filename = format (0, "/tmp/%s%c", filename, 0);
1819 vec_free (filename);
1820 }
1821 else if (unformat (line_input, "status"))
1822 {
1823 if (vm->pcap[rx_tx].pcap_sw_if_index == 0)
1824 {
1825 vlib_cli_output
1826 (vm, "max is %d for any interface to file %s",
1827 vm->pcap[rx_tx].pcap_main.n_packets_to_capture ?
1828 vm->pcap[rx_tx].pcap_main.n_packets_to_capture
1829 : PCAP_DEF_PKT_TO_CAPTURE,
1830 vm->pcap[rx_tx].pcap_main.file_name ?
1831 (u8 *) vm->pcap[rx_tx].pcap_main.file_name :
1832 (u8 *) "/tmp/vpe.pcap");
1833 }
1834 else
1835 {
1836 vlib_cli_output (vm, "max is %d for interface %U to file %s",
1837 vm->pcap[rx_tx].pcap_main.n_packets_to_capture
1838 ? vm->pcap[rx_tx].
1839 pcap_main.n_packets_to_capture :
1840 PCAP_DEF_PKT_TO_CAPTURE,
1841 format_vnet_sw_if_index_name, vnm,
Dave Barachcac8f9b2019-04-16 08:07:06 -04001842 vm->pcap[rx_tx].pcap_sw_if_index,
Dave Barach5ecd5a52019-02-25 15:27:28 -05001843 vm->pcap[rx_tx].
1844 pcap_main.file_name ? (u8 *) vm->pcap[rx_tx].
1845 pcap_main.file_name : (u8 *) "/tmp/vpe.pcap");
1846 }
1847
1848 if (vm->pcap[rx_tx].pcap_enable == 0)
1849 {
1850 vlib_cli_output (vm, "pcap %s capture is off...",
1851 (rx_tx == VLIB_RX) ? "rx" : "tx");
1852 }
1853 else
1854 {
1855 vlib_cli_output (vm, "pcap %s capture is on: %d of %d pkts...",
1856 (rx_tx == VLIB_RX) ? "rx" : "tx",
1857 vm->pcap[rx_tx].pcap_main.n_packets_captured,
1858 vm->pcap[rx_tx].
1859 pcap_main.n_packets_to_capture);
1860 }
1861 break;
1862 }
1863
1864 else
1865 {
1866 error = clib_error_return (0, "unknown input `%U'",
1867 format_unformat_error, line_input);
1868 errorFlag = 1;
1869 break;
1870 }
1871 }
1872 unformat_free (line_input);
1873
1874
1875 if (errorFlag == 0)
1876 {
1877 /* Since no error, save configured values. */
1878 if (chroot_filename)
1879 {
1880 if (vm->pcap[rx_tx].pcap_main.file_name)
1881 vec_free (vm->pcap[rx_tx].pcap_main.file_name);
1882 vec_add1 (chroot_filename, 0);
1883 vm->pcap[rx_tx].pcap_main.file_name = (char *) chroot_filename;
1884 }
1885
1886 if (max)
1887 vm->pcap[rx_tx].pcap_main.n_packets_to_capture = max;
1888
1889 if (enabled)
1890 {
1891 if (vm->pcap[rx_tx].pcap_main.file_name == 0)
1892 vm->pcap[rx_tx].pcap_main.file_name
1893 = (char *) format (0, "/tmp/vpe.pcap%c", 0);
1894
1895 vm->pcap[rx_tx].pcap_main.n_packets_captured = 0;
1896 vm->pcap[rx_tx].pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet;
1897 if (vm->pcap[rx_tx].pcap_main.lock == 0)
1898 clib_spinlock_init (&(vm->pcap[rx_tx].pcap_main.lock));
1899 vm->pcap[rx_tx].pcap_enable = 1;
1900 vlib_cli_output (vm, "pcap %s capture on...",
1901 rx_tx == VLIB_RX ? "rx" : "tx");
1902 }
1903 }
1904 else if (chroot_filename)
1905 vec_free (chroot_filename);
1906
1907 return error;
1908}
1909
1910static clib_error_t *
1911pcap_rx_trace_command_fn (vlib_main_t * vm,
1912 unformat_input_t * input, vlib_cli_command_t * cmd)
1913{
1914 return pcap_trace_command_internal (vm, input, cmd, VLIB_RX);
1915}
1916
1917static clib_error_t *
1918pcap_tx_trace_command_fn (vlib_main_t * vm,
1919 unformat_input_t * input, vlib_cli_command_t * cmd)
1920{
1921 return pcap_trace_command_internal (vm, input, cmd, VLIB_TX);
1922}
1923
1924
1925/*?
1926 * This command is used to start or stop a packet capture, or show
1927 * the status of packet capture. Note that both "pcap rx trace" and
1928 * "pcap tx trace" are implemented. The command syntax is identical,
1929 * simply substitute rx for tx as needed.
1930 *
1931 * This command has the following optional parameters:
1932 *
1933 * - <b>on|off</b> - Used to start or stop a packet capture.
1934 *
1935 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
1936 * of packets have been received, buffer is flushed to file. Once another
1937 * '<em>nn</em>' number of packets have been received, buffer is flushed
1938 * to file, overwriting previous write. If not entered, value defaults
1939 * to 100. Can only be updated if packet capture is off.
1940 *
1941 * - <b>intfc <interface>|any</b> - Used to specify a given interface,
1942 * or use '<em>any</em>' to run packet capture on all interfaces.
1943 * '<em>any</em>' is the default if not provided. Settings from a previous
1944 * packet capture are preserved, so '<em>any</em>' can be used to reset
1945 * the interface setting.
1946 *
1947 * - <b>file <name></b> - Used to specify the output filename. The file will
1948 * be placed in the '<em>/tmp</em>' directory, so only the filename is
1949 * supported. Directory should not be entered. If file already exists, file
1950 * will be overwritten. If no filename is provided, '<em>/tmp/vpe.pcap</em>'
1951 * will be used. Can only be updated if packet capture is off.
1952 *
1953 * - <b>status</b> - Displays the current status and configured attributes
1954 * associated with a packet capture. If packet capture is in progress,
1955 * '<em>status</em>' also will return the number of packets currently in
1956 * the local buffer. All additional attributes entered on command line
1957 * with '<em>status</em>' will be ignored and not applied.
1958 *
1959 * @cliexpar
1960 * Example of how to display the status of a tx packet capture when off:
1961 * @cliexstart{pcap tx trace status}
1962 * max is 100, for any interface to file /tmp/vpe.pcap
1963 * pcap tx capture is off...
1964 * @cliexend
1965 * Example of how to start a tx packet capture:
1966 * @cliexstart{pcap tx trace on max 35 intfc GigabitEthernet0/8/0 file vppTest.pcap}
1967 * pcap tx capture on...
1968 * @cliexend
1969 * Example of how to display the status of a tx packet capture in progress:
1970 * @cliexstart{pcap tx trace status}
1971 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
1972 * pcap tx capture is on: 20 of 35 pkts...
1973 * @cliexend
1974 * Example of how to stop a tx packet capture:
1975 * @cliexstart{vppctl pcap tx trace off}
1976 * captured 21 pkts...
1977 * saved to /tmp/vppTest.pcap...
1978 * @cliexend
1979?*/
1980/* *INDENT-OFF* */
1981
1982VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
1983 .path = "pcap tx trace",
1984 .short_help =
1985 "pcap tx trace [on|off] [max <nn>] [intfc <interface>|any] [file <name>] [status]",
1986 .function = pcap_tx_trace_command_fn,
1987};
1988VLIB_CLI_COMMAND (pcap_rx_trace_command, static) = {
1989 .path = "pcap rx trace",
1990 .short_help =
1991 "pcap rx trace [on|off] [max <nn>] [intfc <interface>|any] [file <name>] [status]",
1992 .function = pcap_rx_trace_command_fn,
1993};
1994/* *INDENT-ON* */
1995
1996
Dave Barachba868bb2016-08-08 09:51:21 -04001997/*
1998 * fd.io coding-style-patch-verification: ON
1999 *
2000 * Local Variables:
2001 * eval: (c-set-style "gnu")
2002 * End:
2003 */