blob: 740a8af78ec8c1c320b42ae41385b7b80c58b714 [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 */
Chris Luke16bcf7d2016-09-01 14:31:46 -040039/**
40 * @file
Billy McFalle9bac692017-08-11 14:05:11 -040041 * @brief Interface CLI.
42 *
43 * Source code for several CLI interface commands.
44 *
Chris Luke16bcf7d2016-09-01 14:31:46 -040045 */
Ed Warnickecb9cada2015-12-08 15:45:58 -070046#include <vnet/vnet.h>
47#include <vnet/ip/ip.h>
John Lobcebbb92016-04-05 15:47:43 -040048#include <vppinfra/bitmap.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010049#include <vnet/fib/ip4_fib.h>
50#include <vnet/fib/ip6_fib.h>
Eyal Bari942402b2017-07-26 11:57:04 +030051#include <vnet/l2/l2_output.h>
52#include <vnet/l2/l2_input.h>
Neale Rannsba4a5bf2020-01-09 06:43:14 +000053#include <vnet/classify/vnet_classify.h>
Damjan Marion94100532020-11-06 23:25:57 +010054#include <vnet/interface/rx_queue_funcs.h>
Mohsin Kazmi005605f2021-05-24 18:33:50 +020055#include <vnet/interface/tx_queue_funcs.h>
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +000056#include <vnet/hash/hash.h>
Dave Barachba868bb2016-08-08 09:51:21 -040057static int
58compare_interface_names (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -070059{
Dave Barachba868bb2016-08-08 09:51:21 -040060 u32 *hi1 = a1;
61 u32 *hi2 = a2;
Ed Warnickecb9cada2015-12-08 15:45:58 -070062
Dave Barachba868bb2016-08-08 09:51:21 -040063 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070064}
65
66static clib_error_t *
67show_or_clear_hw_interfaces (vlib_main_t * vm,
68 unformat_input_t * input,
Benoît Ganne17814d72020-07-24 09:57:11 +020069 vlib_cli_command_t * cmd, int is_show)
Ed Warnickecb9cada2015-12-08 15:45:58 -070070{
Dave Barachba868bb2016-08-08 09:51:21 -040071 clib_error_t *error = 0;
72 vnet_main_t *vnm = vnet_get_main ();
73 vnet_interface_main_t *im = &vnm->interface_main;
74 vnet_hw_interface_t *hi;
75 u32 hw_if_index, *hw_if_indices = 0;
Benoît Ganne17814d72020-07-24 09:57:11 +020076 int i, verbose = -1, show_bond = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070077
Ed Warnickecb9cada2015-12-08 15:45:58 -070078 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)
Damjan Marionb2c31b62020-12-13 21:47:40 +0100115 pool_foreach (hi, im->hw_interfaces)
116 vec_add1 (hw_if_indices, hi - im->hw_interfaces);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700117
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* */
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100142 clib_bitmap_foreach (hw_idx, hi->bond_info)
143 {
Dave Barachba868bb2016-08-08 09:51:21 -0400144 shi = vnet_get_hw_interface(vnm, hw_idx);
145 vlib_cli_output (vm, "%U\n",
146 format_vnet_hw_interface, vnm, shi, verbose);
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100147 }
Dave Barachba868bb2016-08-08 09:51:21 -0400148 /* *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
Benoît Ganne17814d72020-07-24 09:57:11 +0200171static clib_error_t *
172show_hw_interfaces (vlib_main_t * vm,
173 unformat_input_t * input, vlib_cli_command_t * cmd)
174{
175 return show_or_clear_hw_interfaces (vm, input, cmd, 1 /* is_show */ );
176}
177
178static clib_error_t *
179clear_hw_interfaces (vlib_main_t * vm,
180 unformat_input_t * input, vlib_cli_command_t * cmd)
181{
182 return show_or_clear_hw_interfaces (vm, input, cmd, 0 /* is_show */ );
183}
184
185
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700186/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400187 * Display more detailed information about all or a list of given interfaces.
188 * The verboseness of the output can be controlled by the following optional
189 * parameters:
190 * - brief: Only show name, index and state (default for bonded interfaces).
191 * - verbose: Also display additional attributes (default for all other interfaces).
192 * - detail: Also display all remaining attributes and extended statistics.
193 *
194 * To limit the output of the command to bonded interfaces and their slave
195 * interfaces, use the '<em>bond</em>' optional parameter.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700196 *
197 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400198 * Example of how to display default data for all interfaces:
199 * @cliexstart{show hardware-interfaces}
200 * Name Idx Link Hardware
201 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
202 * Ethernet address ec:f4:bb:c0:bc:fc
203 * Intel e1000
204 * carrier up full duplex speed 1000 mtu 9216
205 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
206 * cpu socket 0
207 * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1
208 * Ethernet address ec:f4:bb:c0:bc:fd
209 * Intel e1000
210 * carrier up full duplex speed 1000 mtu 9216
211 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
212 * cpu socket 0
213 * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0
214 * Ethernet address 02:fe:a5:a9:8b:8e
215 * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1
216 * Ethernet address 02:fe:c0:4e:3b:b0
217 * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2
218 * Ethernet address 02:fe:1f:73:92:81
219 * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3
220 * Ethernet address 02:fe:f2:25:c4:68
221 * local0 0 down local0
222 * local
223 * @cliexend
224 * Example of how to display '<em>verbose</em>' data for an interface by name and
225 * software index (where 2 is the software index):
226 * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose}
227 * Name Idx Link Hardware
228 * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0
229 * Ethernet address ec:f4:bb:c0:bc:fc
230 * Intel e1000
231 * carrier up full duplex speed 1000 mtu 9216
232 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
233 * cpu socket 0
234 * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1
235 * Ethernet address ec:f4:bb:c0:bc:fd
236 * Intel e1000
237 * carrier up full duplex speed 1000 mtu 9216
238 * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024
239 * cpu socket 0
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700240 * @cliexend
241 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400242/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700243VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
244 .path = "show hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400245 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] "
246 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Benoît Ganne17814d72020-07-24 09:57:11 +0200247 .function = show_hw_interfaces,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700248};
Dave Barachba868bb2016-08-08 09:51:21 -0400249/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250
Billy McFalle9bac692017-08-11 14:05:11 -0400251
252/*?
253 * Clear the extended statistics for all or a list of given interfaces
254 * (statistics associated with the '<em>show hardware-interfaces</em>' command).
255 *
256 * @cliexpar
257 * Example of how to clear the extended statistics for all interfaces:
258 * @cliexcmd{clear hardware-interfaces}
259 * Example of how to clear the extended statistics for an interface by
260 * name and software index (where 2 is the software index):
261 * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2}
262 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400263/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700264VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
265 .path = "clear hardware-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400266 .short_help = "clear hardware-interfaces "
267 "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]",
Benoît Ganne17814d72020-07-24 09:57:11 +0200268 .function = clear_hw_interfaces,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700269};
Dave Barachba868bb2016-08-08 09:51:21 -0400270/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700271
Dave Barachba868bb2016-08-08 09:51:21 -0400272static int
273sw_interface_name_compare (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700274{
275 vnet_sw_interface_t *si1 = a1;
276 vnet_sw_interface_t *si2 = a2;
277
Dave Barachba868bb2016-08-08 09:51:21 -0400278 return vnet_sw_interface_compare (vnet_get_main (),
279 si1->sw_if_index, si2->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700280}
281
282static clib_error_t *
283show_sw_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400284 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700285{
Dave Barachba868bb2016-08-08 09:51:21 -0400286 clib_error_t *error = 0;
287 vnet_main_t *vnm = vnet_get_main ();
Dave Barach525c9d02018-05-26 10:48:55 -0400288 unformat_input_t _linput, *linput = &_linput;
Dave Barachba868bb2016-08-08 09:51:21 -0400289 vnet_interface_main_t *im = &vnm->interface_main;
290 vnet_sw_interface_t *si, *sorted_sis = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200291 u32 sw_if_index = ~(u32) 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700292 u8 show_addresses = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200293 u8 show_features = 0;
Dave Barach7be864a2016-11-28 11:41:35 -0500294 u8 show_tag = 0;
Jon Loeliger9485d992019-11-08 15:05:23 -0600295 u8 show_vtr = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400296 int verbose = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700297
Dave Barach525c9d02018-05-26 10:48:55 -0400298 /*
299 * Get a line of input. Won't work if the user typed
300 * "show interface" and nothing more.
301 */
302 if (unformat_user (input, unformat_line_input, linput))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700303 {
Dave Barach525c9d02018-05-26 10:48:55 -0400304 while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700305 {
Dave Barach525c9d02018-05-26 10:48:55 -0400306 /* See if user wants to show specific interface */
307 if (unformat
308 (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
309 {
310 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
311 vec_add1 (sorted_sis, si[0]);
312 }
313 else if (unformat (linput, "address") || unformat (linput, "addr"))
314 show_addresses = 1;
315 else if (unformat (linput, "features") || unformat (linput, "feat"))
316 show_features = 1;
317 else if (unformat (linput, "tag"))
318 show_tag = 1;
Jon Loeliger9485d992019-11-08 15:05:23 -0600319 else if (unformat (linput, "vtr"))
320 show_vtr = 1;
Dave Barach525c9d02018-05-26 10:48:55 -0400321 else if (unformat (linput, "verbose"))
322 verbose = 1;
Neale Rannse619ada2021-09-22 10:49:43 +0000323 else if (unformat (linput, "%d", &sw_if_index))
324 {
325 if (!pool_is_free_index (im->sw_interfaces, sw_if_index))
326 {
327 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
328 vec_add1 (sorted_sis, si[0]);
329 }
330 else
331 {
332 vec_free (sorted_sis);
333 error = clib_error_return (0, "unknown interface index `%d'",
334 sw_if_index);
335 goto done;
336 }
337 }
Dave Barach525c9d02018-05-26 10:48:55 -0400338 else
339 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400340 vec_free (sorted_sis);
Dave Barach525c9d02018-05-26 10:48:55 -0400341 error = clib_error_return (0, "unknown input `%U'",
342 format_unformat_error, linput);
343 goto done;
344 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700345 }
Dave Barach525c9d02018-05-26 10:48:55 -0400346 unformat_free (linput);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700347 }
Jon Loeliger9485d992019-11-08 15:05:23 -0600348 if (show_features || show_tag || show_vtr)
Damjan Marion22311502016-10-28 20:30:15 +0200349 {
350 if (sw_if_index == ~(u32) 0)
Dave Barach8fdde3c2019-05-17 10:46:40 -0400351 {
352 vec_free (sorted_sis);
353 return clib_error_return (0, "Interface not specified...");
354 }
Dave Barach7be864a2016-11-28 11:41:35 -0500355 }
Damjan Marion22311502016-10-28 20:30:15 +0200356
Dave Barach7be864a2016-11-28 11:41:35 -0500357 if (show_features)
358 {
Dave Barach525c9d02018-05-26 10:48:55 -0400359 vnet_interface_features_show (vm, sw_if_index, verbose);
Neale Ranns47a3d992020-09-29 15:38:51 +0000360 vlib_cli_output (vm, "%U", format_l2_input_features, sw_if_index, 1);
Eyal Bari942402b2017-07-26 11:57:04 +0300361
362 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
363 vlib_cli_output (vm, "\nl2-output:");
364 if (l2_output->out_vtr_flag)
365 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
366 vlib_cli_output (vm, "%U", format_l2_output_features,
Neale Ranns5d9df1d2018-11-09 08:19:27 -0800367 l2_output->feature_bitmap, 1);
Dave Barach8fdde3c2019-05-17 10:46:40 -0400368 vec_free (sorted_sis);
Damjan Marion22311502016-10-28 20:30:15 +0200369 return 0;
370 }
Dave Barach7be864a2016-11-28 11:41:35 -0500371 if (show_tag)
372 {
373 u8 *tag;
374 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
375 vlib_cli_output (vm, "%U: %s",
376 format_vnet_sw_if_index_name, vnm, sw_if_index,
377 tag ? (char *) tag : "(none)");
Dave Barach8fdde3c2019-05-17 10:46:40 -0400378 vec_free (sorted_sis);
Dave Barach7be864a2016-11-28 11:41:35 -0500379 return 0;
380 }
Damjan Marion22311502016-10-28 20:30:15 +0200381
Jon Loeliger9485d992019-11-08 15:05:23 -0600382 /*
383 * Show vlan tag rewrite data for one interface.
384 */
385 if (show_vtr)
386 {
387 u32 vtr_op = L2_VTR_DISABLED;
388 u32 push_dot1q = 0, tag1 = 0, tag2 = 0;
389
390 if (l2vtr_get (vm, vnm, sw_if_index,
391 &vtr_op, &push_dot1q, &tag1, &tag2) != 0)
392 {
393 vlib_cli_output (vm, "%U: Problem getting vlan tag-rewrite data",
394 format_vnet_sw_if_index_name, vnm, sw_if_index);
395 return 0;
396 }
397 vlib_cli_output (vm, "%U: VTR %0U",
398 format_vnet_sw_if_index_name, vnm, sw_if_index,
399 format_vtr, vtr_op, push_dot1q, tag1, tag2);
400 return 0;
401 }
402
Ed Warnickecb9cada2015-12-08 15:45:58 -0700403 if (!show_addresses)
Dave Barachba868bb2016-08-08 09:51:21 -0400404 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700405
Dave Barachba868bb2016-08-08 09:51:21 -0400406 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700407 {
408 /* Gather interfaces. */
Dave Barachba868bb2016-08-08 09:51:21 -0400409 sorted_sis =
410 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700411 _vec_len (sorted_sis) = 0;
Dave Barach525c9d02018-05-26 10:48:55 -0400412 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +0100413 pool_foreach (si, im->sw_interfaces)
414 {
Dave Barach525c9d02018-05-26 10:48:55 -0400415 int visible = vnet_swif_is_api_visible (si);
416 if (visible)
Damjan Marionb2c31b62020-12-13 21:47:40 +0100417 vec_add1 (sorted_sis, si[0]);
418 }
Ole Troand7231612018-06-07 10:17:57 +0200419 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700420 /* Sort by name. */
421 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
422 }
423
424 if (show_addresses)
425 {
426 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400427 {
Dave Barachba868bb2016-08-08 09:51:21 -0400428 ip4_main_t *im4 = &ip4_main;
429 ip6_main_t *im6 = &ip6_main;
430 ip_lookup_main_t *lm4 = &im4->lookup_main;
431 ip_lookup_main_t *lm6 = &im6->lookup_main;
432 ip_interface_address_t *ia = 0;
Dave Barachba868bb2016-08-08 09:51:21 -0400433 u32 fib_index4 = 0, fib_index6 = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700434
Dave Barachba868bb2016-08-08 09:51:21 -0400435 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
436 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
437 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700438
Dave Barachba868bb2016-08-08 09:51:21 -0400439 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
440 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
441 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700442
John Lo4478d8e2018-01-12 17:15:25 -0500443 ip4_fib_t *fib4 = ip4_fib_get (fib_index4);
444 ip6_fib_t *fib6 = ip6_fib_get (fib_index6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700445
Dave Barachba868bb2016-08-08 09:51:21 -0400446 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
447 vlib_cli_output
448 (vm, "%U (%s): \n unnumbered, use %U",
John Lo4478d8e2018-01-12 17:15:25 -0500449 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
Dave Barachba868bb2016-08-08 09:51:21 -0400450 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
451 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400452 else
John Lo4478d8e2018-01-12 17:15:25 -0500453 vlib_cli_output
454 (vm, "%U (%s):",
455 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
456 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700457
Eyal Bari942402b2017-07-26 11:57:04 +0300458 /* Display any L2 info */
Neale Ranns47a3d992020-09-29 15:38:51 +0000459 vlib_cli_output (vm, "%U", format_l2_input, si->sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400460
John Lo4478d8e2018-01-12 17:15:25 -0500461 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400462 /* Display any IP4 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500463 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
464 1 /* honor unnumbered */,
465 ({
466 ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia);
Neale Rannsd6953332021-08-10 07:39:18 +0000467 if (fib4->hash.table_id)
468 vlib_cli_output (
469 vm, " L3 %U/%d ip4 table-id %d fib-idx %d", format_ip4_address,
470 r4, ia->address_length, fib4->hash.table_id,
471 ip4_fib_index_from_table_id (fib4->hash.table_id));
John Lo4478d8e2018-01-12 17:15:25 -0500472 else
473 vlib_cli_output (vm, " L3 %U/%d",
474 format_ip4_address, r4, ia->address_length);
475 }));
476 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700477
John Lo4478d8e2018-01-12 17:15:25 -0500478 /* *INDENT-OFF* */
Dave Barachba868bb2016-08-08 09:51:21 -0400479 /* Display any IP6 addressing info */
John Lo4478d8e2018-01-12 17:15:25 -0500480 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
481 1 /* honor unnumbered */,
482 ({
483 ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia);
484 if (fib6->table_id)
485 vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d",
486 format_ip6_address, r6, ia->address_length,
487 fib6->table_id,
488 ip6_fib_index_from_table_id (fib6->table_id));
489 else
490 vlib_cli_output (vm, " L3 %U/%d",
491 format_ip6_address, r6, ia->address_length);
492 }));
493 /* *INDENT-ON* */
Ole Troand7231612018-06-07 10:17:57 +0200494 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700495 }
Ole Troand7231612018-06-07 10:17:57 +0200496 else
497 {
498 vec_foreach (si, sorted_sis)
499 {
500 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
501 }
502 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700503
Dave Barachba868bb2016-08-08 09:51:21 -0400504done:
Ole Troand7231612018-06-07 10:17:57 +0200505 vec_free (sorted_sis);
506 return error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700507}
508
Dave Barachba868bb2016-08-08 09:51:21 -0400509/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700510VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
Dave Barach13ad1f02017-03-26 19:36:18 -0400511 .path = "show interface",
Jon Loeliger9485d992019-11-08 15:05:23 -0600512 .short_help = "show interface [address|addr|features|feat|vtr] [<interface> [<interface> [..]]] [verbose]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700513 .function = show_sw_interfaces,
Steven Luongc5fa2b82019-04-25 11:19:49 -0700514 .is_mp_safe = 1,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700515};
Dave Barachba868bb2016-08-08 09:51:21 -0400516/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700517
518/* Root of all interface commands. */
Dave Barachba868bb2016-08-08 09:51:21 -0400519/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700520VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
521 .path = "interface",
522 .short_help = "Interface commands",
523};
Dave Barachba868bb2016-08-08 09:51:21 -0400524/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700525
Dave Barachba868bb2016-08-08 09:51:21 -0400526/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700527VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
528 .path = "set interface",
529 .short_help = "Interface commands",
530};
Dave Barachba868bb2016-08-08 09:51:21 -0400531/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700532
533static clib_error_t *
534clear_interface_counters (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400535 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700536{
Dave Barachba868bb2016-08-08 09:51:21 -0400537 vnet_main_t *vnm = vnet_get_main ();
538 vnet_interface_main_t *im = &vnm->interface_main;
539 vlib_simple_counter_main_t *sm;
540 vlib_combined_counter_main_t *cm;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400541 int j, n_counters;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700542
543 n_counters = vec_len (im->combined_sw_if_counters);
544
545 for (j = 0; j < n_counters; j++)
546 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400547 im = &vnm->interface_main;
548 cm = im->combined_sw_if_counters + j;
549 vlib_clear_combined_counters (cm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700550 }
551
552 n_counters = vec_len (im->sw_if_counters);
553
554 for (j = 0; j < n_counters; j++)
555 {
Dave Barach8fdde3c2019-05-17 10:46:40 -0400556 im = &vnm->interface_main;
557 sm = im->sw_if_counters + j;
558 vlib_clear_simple_counters (sm);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700559 }
560
561 return 0;
562}
563
Billy McFalle9bac692017-08-11 14:05:11 -0400564/*?
565 * Clear the statistics for all interfaces (statistics associated with the
566 * '<em>show interface</em>' command).
567 *
568 * @cliexpar
569 * Example of how to clear the statistics for all interfaces:
570 * @cliexcmd{clear interfaces}
571 ?*/
Dave Barachba868bb2016-08-08 09:51:21 -0400572/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700573VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
574 .path = "clear interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400575 .short_help = "clear interfaces",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700576 .function = clear_interface_counters,
577};
Dave Barachba868bb2016-08-08 09:51:21 -0400578/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700579
Chris Luke16bcf7d2016-09-01 14:31:46 -0400580/**
581 * Parse subinterface names.
582 *
Dave Barachba868bb2016-08-08 09:51:21 -0400583 * The following subinterface syntax is supported. The first two are for
584 * backwards compatability:
585 *
586 * <intf-name> <id>
587 * - a subinterface with the name <intf-name>.<id>. The subinterface
588 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
589 *
590 * <intf-name> <min_id>-<max_id>
591 * - a set of the above subinterfaces, repeating for each id
592 * in the range <min_id> to <max_id>
593 *
594 * In the following, exact-match semantics (i.e. the number of vlan tags on the
595 * packet must match the number of tags in the configuration) are used only if
596 * the keyword exact-match is present. Non-exact match is the default.
597 *
598 * <intf-name> <id> dot1q <outer_id> [exact-match]
599 * - a subinterface with the name <intf-name>.<id>. The subinterface
600 * is a single dot1q vlan with vlan id <outer_id>.
601 *
602 * <intf-name> <id> dot1q any [exact-match]
603 * - a subinterface with the name <intf-name>.<id>. The subinterface
604 * is a single dot1q vlan with any vlan id.
605 *
606 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
607 * - a subinterface with the name <intf-name>.<id>. The subinterface
608 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
609 * <inner_id>.
610 *
611 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
612 * - a subinterface with the name <intf-name>.<id>. The subinterface
613 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
614 *
615 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
616 *
617 * - a subinterface with the name <intf-name>.<id>. The subinterface
618 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
619 *
620 * For each of the above CLI, there is a duplicate that uses the keyword
621 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
622 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
623 * tagged packets the inner ethertype is always 0x8100. Also note that
624 * the dot1q and dot1ad naming spaces are independent, so it is legal to
625 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
626 *
627 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
628 * - a subinterface with the name <intf-name>.<id>. The subinterface
629 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
630 * id <inner_id>.
631 *
632 * <intf-name> <id> untagged
633 * - a subinterface with the name <intf-name>.<id>. The subinterface
634 * has no vlan tags. Only one can be specified per interface.
635 *
636 * <intf-name> <id> default
637 * - a subinterface with the name <intf-name>.<id>. This is associated
638 * with a packet that did not match any other configured subinterface
639 * on this interface. Only one can be specified per interface.
640 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700641
642static clib_error_t *
Dave Barachba868bb2016-08-08 09:51:21 -0400643parse_vlan_sub_interfaces (unformat_input_t * input,
644 vnet_sw_interface_t * template)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700645{
Dave Barachba868bb2016-08-08 09:51:21 -0400646 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700647 u32 inner_vlan, outer_vlan;
648
Dave Barachba868bb2016-08-08 09:51:21 -0400649 if (unformat (input, "any inner-dot1q any"))
650 {
651 template->sub.eth.flags.two_tags = 1;
652 template->sub.eth.flags.outer_vlan_id_any = 1;
653 template->sub.eth.flags.inner_vlan_id_any = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700654 }
Dave Barachba868bb2016-08-08 09:51:21 -0400655 else if (unformat (input, "any"))
656 {
657 template->sub.eth.flags.one_tag = 1;
658 template->sub.eth.flags.outer_vlan_id_any = 1;
659 }
660 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
661 {
662 template->sub.eth.flags.two_tags = 1;
663 template->sub.eth.flags.inner_vlan_id_any = 1;
664 template->sub.eth.outer_vlan_id = outer_vlan;
665 }
666 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
667 {
668 template->sub.eth.flags.two_tags = 1;
669 template->sub.eth.outer_vlan_id = outer_vlan;
670 template->sub.eth.inner_vlan_id = inner_vlan;
671 }
672 else if (unformat (input, "%d", &outer_vlan))
673 {
674 template->sub.eth.flags.one_tag = 1;
675 template->sub.eth.outer_vlan_id = outer_vlan;
676 }
677 else
678 {
679 error = clib_error_return (0, "expected dot1q config, got `%U'",
680 format_unformat_error, input);
681 goto done;
682 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700683
Dave Barachba868bb2016-08-08 09:51:21 -0400684 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
685 {
686 if (unformat (input, "exact-match"))
687 {
688 template->sub.eth.flags.exact_match = 1;
689 }
690 }
691
692done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700693 return error;
694}
695
696static clib_error_t *
697create_sub_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400698 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700699{
Dave Barachba868bb2016-08-08 09:51:21 -0400700 vnet_main_t *vnm = vnet_get_main ();
701 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700702 u32 hw_if_index, sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400703 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700704 u32 id, id_min, id_max;
705 vnet_sw_interface_t template;
706
707 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400708 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700709 {
710 error = clib_error_return (0, "unknown interface `%U'",
711 format_unformat_error, input);
712 goto done;
713 }
714
Dave Barachb7b92992018-10-17 10:38:51 -0400715 clib_memset (&template, 0, sizeof (template));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700716 template.sub.eth.raw_flags = 0;
717
Dave Barachba868bb2016-08-08 09:51:21 -0400718 if (unformat (input, "%d default", &id_min))
719 {
720 id_max = id_min;
721 template.sub.eth.flags.default_sub = 1;
722 }
723 else if (unformat (input, "%d untagged", &id_min))
724 {
725 id_max = id_min;
726 template.sub.eth.flags.no_tags = 1;
727 template.sub.eth.flags.exact_match = 1;
728 }
729 else if (unformat (input, "%d dot1q", &id_min))
730 {
731 /* parse dot1q config */
732 id_max = id_min;
733 error = parse_vlan_sub_interfaces (input, &template);
734 if (error)
735 goto done;
736 }
737 else if (unformat (input, "%d dot1ad", &id_min))
738 {
739 /* parse dot1ad config */
740 id_max = id_min;
741 template.sub.eth.flags.dot1ad = 1;
742 error = parse_vlan_sub_interfaces (input, &template);
743 if (error)
744 goto done;
745 }
746 else if (unformat (input, "%d-%d", &id_min, &id_max))
747 {
748 template.sub.eth.flags.one_tag = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400749 template.sub.eth.flags.exact_match = 1;
750 if (id_min > id_max)
751 goto id_error;
752 }
753 else if (unformat (input, "%d", &id_min))
754 {
755 id_max = id_min;
756 template.sub.eth.flags.one_tag = 1;
757 template.sub.eth.outer_vlan_id = id_min;
758 template.sub.eth.flags.exact_match = 1;
759 }
760 else
761 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700762 id_error:
763 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
764 format_unformat_error, input);
765 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400766 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700767
768 hi = vnet_get_hw_interface (vnm, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -0400769
Dave Barachba868bb2016-08-08 09:51:21 -0400770 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
771 {
772 error =
773 clib_error_return (0,
774 "not allowed as %v belong to a BondEthernet interface",
775 hi->name);
776 goto done;
777 }
John Lobcebbb92016-04-05 15:47:43 -0400778
Ed Warnickecb9cada2015-12-08 15:45:58 -0700779 for (id = id_min; id <= id_max; id++)
780 {
Dave Barachba868bb2016-08-08 09:51:21 -0400781 uword *p;
782 vnet_interface_main_t *im = &vnm->interface_main;
783 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
784 u64 *kp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700785
786 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
787 if (p)
Dave Barachba868bb2016-08-08 09:51:21 -0400788 {
789 if (CLIB_DEBUG > 0)
790 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
791 hi->sw_if_index, id);
792 continue;
793 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700794
Ed Warnickecb9cada2015-12-08 15:45:58 -0700795 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Eyal Baric5b13602016-11-24 19:42:43 +0200796 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700797 template.sup_sw_if_index = hi->sw_if_index;
798 template.sub.id = id;
Eyal Baria4509cf2016-09-26 09:24:09 +0300799 if (id_min < id_max)
800 template.sub.eth.outer_vlan_id = id;
801
Ed Warnickecb9cada2015-12-08 15:45:58 -0700802 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400803 if (error)
804 goto done;
Dave Barach16ad6ae2016-07-28 17:55:30 -0400805
Jon Loeligerb22e1f02019-12-19 09:03:52 -0600806 kp = clib_mem_alloc (sizeof (*kp));
807 *kp = sup_and_sub_key;
808
Ed Warnickecb9cada2015-12-08 15:45:58 -0700809 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
810 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400811 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
812 vnet_get_main (), sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700813 }
814
Dave Barachba868bb2016-08-08 09:51:21 -0400815done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700816 return error;
817}
818
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700819/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400820 * This command is used to add VLAN IDs to interfaces, also known as subinterfaces.
821 * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>'
822 * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is
823 * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different,
824 * but this is not recommended.
825 *
826 * This command has several variations:
827 * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to
828 * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>').
829 *
830 * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the
831 * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not
832 * match any other subinterfaces should be sent to this subinterface.
833 *
834 * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the
835 * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent
836 * to this subinterface.
837 *
838 * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of
839 * subinterfaces to handle a range of VLAN IDs.
840 *
841 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> -
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700842 * Use this command to specify the outer VLAN ID, to either be explicit or to make the
Billy McFalle9bac692017-08-11 14:05:11 -0400843 * VLAN ID different from the '<em>subId</em>'.
844 *
845 * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q
846 * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700847 * the inner VLAN ID.
Billy McFalle9bac692017-08-11 14:05:11 -0400848 *
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700849 * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces
Billy McFalle9bac692017-08-11 14:05:11 -0400850 * can be configured as either exact-match or non-exact match. Non-exact match is the CLI
851 * default. If '<em>exact-match</em>' is specified, packets must have the same number of
852 * VLAN tags as the configuration. For non-exact-match, packets must at least that number
853 * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are
854 * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT
855 * entered, then the default behavior is exact-match.
856 *
857 * Use the '<em>show interface</em>' command to display all subinterfaces.
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700858 *
859 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -0400860 * @parblock
861 * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11:
862 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700863 *
Billy McFalle9bac692017-08-11 14:05:11 -0400864 * The previous example is shorthand and is equivalent to:
865 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 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 create a subinterface number that is different from the VLAN ID:
869 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700870 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700871 *
Billy McFalle9bac692017-08-11 14:05:11 -0400872 * Examples of how to create q-in-q and q-in-any subinterfaces:
873 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200}
874 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700875 *
Billy McFalle9bac692017-08-11 14:05:11 -0400876 * Examples of how to create dot1ad interfaces:
877 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11}
878 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700879 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700880 *
Billy McFalle9bac692017-08-11 14:05:11 -0400881 * Examples of '<em>exact-match</em>' versus non-exact match. A packet with
882 * outer VLAN 100 and inner VLAN 200 would match this interface, because the default
883 * is non-exact match:
884 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700885 *
Billy McFalle9bac692017-08-11 14:05:11 -0400886 * However, the same packet would NOT match this interface because '<em>exact-match</em>'
887 * is specified and only one VLAN is configured, but packet contains two VLANs:
888 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700889 *
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700890 *
Billy McFalle9bac692017-08-11 14:05:11 -0400891 * Example of how to created a subinterface to process untagged packets:
892 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged}
893 *
894 * Example of how to created a subinterface to process any packet with a VLAN ID that
895 * does not match any other subinterface:
896 * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default}
897 *
898 * When subinterfaces are created, they are in the down state. Example of how to
899 * enable a newly created subinterface:
900 * @cliexcmd{set interface GigabitEthernet2/0/0.7 up}
901 * @endparblock
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700902 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400903/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700904VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700905 .path = "create sub-interfaces",
Billy McFalle9bac692017-08-11 14:05:11 -0400906 .short_help = "create sub-interfaces <interface> "
907 "{<subId> [default|untagged]} | "
908 "{<subId>-<subId>} | "
909 "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700910 .function = create_sub_interfaces,
911};
Dave Barachba868bb2016-08-08 09:51:21 -0400912/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700913
914static clib_error_t *
915set_state (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400916 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700917{
Dave Barachba868bb2016-08-08 09:51:21 -0400918 vnet_main_t *vnm = vnet_get_main ();
919 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700920 u32 sw_if_index, flags;
921
922 sw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400923 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700924 {
925 error = clib_error_return (0, "unknown interface `%U'",
926 format_unformat_error, input);
927 goto done;
928 }
929
Dave Barachba868bb2016-08-08 09:51:21 -0400930 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700931 {
932 error = clib_error_return (0, "unknown flags `%U'",
933 format_unformat_error, input);
934 goto done;
935 }
936
937 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
938 if (error)
939 goto done;
940
Dave Barachba868bb2016-08-08 09:51:21 -0400941done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700942 return error;
943}
944
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700945/*?
Billy McFalle9bac692017-08-11 14:05:11 -0400946 * This command is used to change the admin state (up/down) of an interface.
947 *
948 * If an interface is down, the optional '<em>punt</em>' flag can also be set.
949 * The '<em>punt</em>' flag implies the interface is disabled for forwarding
950 * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear
951 * '<em>punt</em>' flag (interface is still down).
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700952 *
953 * @cliexpar
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +0200954 * Example of how to configure the admin state of an interface to
955 '<em>up</em>':
Billy McFalle9bac692017-08-11 14:05:11 -0400956 * @cliexcmd{set interface state GigabitEthernet2/0/0 up}
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +0200957 * Example of how to configure the admin state of an interface to
958 '<em>down</em>':
Billy McFalle9bac692017-08-11 14:05:11 -0400959 * @cliexcmd{set interface state GigabitEthernet2/0/0 down}
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700960 ?*/
Billy McFalle9bac692017-08-11 14:05:11 -0400961/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700962VLIB_CLI_COMMAND (set_state_command, static) = {
963 .path = "set interface state",
Billy McFalle9bac692017-08-11 14:05:11 -0400964 .short_help = "set interface state <interface> [up|down|punt|enable]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700965 .function = set_state,
966};
Dave Barachba868bb2016-08-08 09:51:21 -0400967/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700968
969static clib_error_t *
970set_unnumbered (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400971 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700972{
Dave Barachba868bb2016-08-08 09:51:21 -0400973 vnet_main_t *vnm = vnet_get_main ();
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700974 u32 unnumbered_sw_if_index = ~0;
975 u32 inherit_from_sw_if_index = ~0;
976 int enable = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700977
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700978 if (unformat (input, "%U use %U",
979 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
980 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700981 enable = 1;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700982 else if (unformat (input, "del %U",
983 unformat_vnet_sw_interface, vnm,
984 &unnumbered_sw_if_index))
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700985 enable = 0;
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700986 else
987 return clib_error_return (0, "parse error '%U'",
988 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700989
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700990 if (~0 == unnumbered_sw_if_index)
991 return clib_error_return (0, "Specify the unnumbered interface");
992 if (enable && ~0 == inherit_from_sw_if_index)
Paul Vinciguerrabdc0e6b2018-09-22 05:32:50 -0700993 return clib_error_return (0, "When enabling unnumbered specify the"
Neale Ranns2ae2bc52018-03-16 03:22:39 -0700994 " IP enabled interface that it uses");
Neale Ranns898273f2017-03-18 02:57:38 -0700995
Stanislav Zaikin328b5da2021-07-15 16:27:29 +0200996 int rv = vnet_sw_interface_update_unnumbered (
997 unnumbered_sw_if_index, inherit_from_sw_if_index, enable);
998
999 switch (rv)
1000 {
1001 case 0:
1002 break;
1003
1004 case VNET_API_ERROR_UNEXPECTED_INTF_STATE:
1005 return clib_error_return (
1006 0,
1007 "When enabling unnumbered both interfaces must be in the same tables");
1008
1009 default:
1010 return clib_error_return (
1011 0, "vnet_sw_interface_update_unnumbered returned %d", rv);
1012 }
Neale Ranns898273f2017-03-18 02:57:38 -07001013
Neale Ranns2ae2bc52018-03-16 03:22:39 -07001014 return (NULL);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001015}
1016
Dave Barachba868bb2016-08-08 09:51:21 -04001017/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001018VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
1019 .path = "set interface unnumbered",
Billy McFalle9bac692017-08-11 14:05:11 -04001020 .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001021 .function = set_unnumbered,
1022};
Dave Barachba868bb2016-08-08 09:51:21 -04001023/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001024
1025
1026
1027static clib_error_t *
1028set_hw_class (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001029 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001030{
Dave Barachba868bb2016-08-08 09:51:21 -04001031 vnet_main_t *vnm = vnet_get_main ();
1032 vnet_interface_main_t *im = &vnm->interface_main;
1033 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -07001034 u32 hw_if_index, hw_class_index;
1035
1036 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -04001037 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001038 {
1039 error = clib_error_return (0, "unknown hardware interface `%U'",
1040 format_unformat_error, input);
1041 goto done;
1042 }
1043
Dave Barachba868bb2016-08-08 09:51:21 -04001044 if (!unformat_user (input, unformat_hash_string,
1045 im->hw_interface_class_by_name, &hw_class_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001046 {
1047 error = clib_error_return (0, "unknown hardware class `%U'",
1048 format_unformat_error, input);
1049 goto done;
1050 }
1051
1052 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
1053 if (error)
1054 goto done;
1055
Dave Barachba868bb2016-08-08 09:51:21 -04001056done:
Ed Warnickecb9cada2015-12-08 15:45:58 -07001057 return error;
1058}
1059
Dave Barachba868bb2016-08-08 09:51:21 -04001060/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001061VLIB_CLI_COMMAND (set_hw_class_command, static) = {
1062 .path = "set interface hw-class",
1063 .short_help = "Set interface hardware class",
1064 .function = set_hw_class,
1065};
Dave Barachba868bb2016-08-08 09:51:21 -04001066/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001067
Dave Barachba868bb2016-08-08 09:51:21 -04001068static clib_error_t *
1069vnet_interface_cli_init (vlib_main_t * vm)
1070{
1071 return 0;
1072}
Ed Warnickecb9cada2015-12-08 15:45:58 -07001073
1074VLIB_INIT_FUNCTION (vnet_interface_cli_init);
1075
Dave Barachba868bb2016-08-08 09:51:21 -04001076static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -07001077renumber_interface_command_fn (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001078 unformat_input_t * input,
1079 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -07001080{
1081 u32 hw_if_index;
1082 u32 new_dev_instance;
Dave Barachba868bb2016-08-08 09:51:21 -04001083 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -07001084 int rv;
1085
Dave Barachba868bb2016-08-08 09:51:21 -04001086 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001087 return clib_error_return (0, "unknown hardware interface `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001088 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001089
Dave Barachba868bb2016-08-08 09:51:21 -04001090 if (!unformat (input, "%d", &new_dev_instance))
Ed Warnickecb9cada2015-12-08 15:45:58 -07001091 return clib_error_return (0, "new dev instance missing");
1092
1093 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
1094
1095 switch (rv)
1096 {
1097 case 0:
1098 break;
1099
1100 default:
1101 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
Dave Barachba868bb2016-08-08 09:51:21 -04001102 rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -07001103
1104 }
1105
1106 return 0;
1107}
1108
1109
Dave Barachba868bb2016-08-08 09:51:21 -04001110/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001111VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1112 .path = "renumber interface",
Billy McFalle9bac692017-08-11 14:05:11 -04001113 .short_help = "renumber interface <interface> <new-dev-instance>",
Ed Warnickecb9cada2015-12-08 15:45:58 -07001114 .function = renumber_interface_command_fn,
1115};
Dave Barachba868bb2016-08-08 09:51:21 -04001116/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001117
Damjan Marion8358ff92016-04-15 14:26:00 +02001118static clib_error_t *
1119promiscuous_cmd (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001120 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion8358ff92016-04-15 14:26:00 +02001121{
Dave Barachba868bb2016-08-08 09:51:21 -04001122 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001123 u32 hw_if_index;
1124 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
Dave Barachba868bb2016-08-08 09:51:21 -04001125 ethernet_main_t *em = &ethernet_main;
1126 ethernet_interface_t *eif;
Damjan Marion8358ff92016-04-15 14:26:00 +02001127
1128 if (unformat (input, "on %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001129 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001130 ;
1131 else if (unformat (input, "off %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001132 unformat_ethernet_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001133 flags = 0;
1134 else
1135 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001136 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001137
1138 eif = ethernet_get_interface (em, hw_if_index);
1139 if (!eif)
1140 return clib_error_return (0, "not supported");
1141
1142 ethernet_set_flags (vnm, hw_if_index, flags);
1143 return 0;
1144}
1145
Dave Barachba868bb2016-08-08 09:51:21 -04001146/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001147VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1148 .path = "set interface promiscuous",
Billy McFalle9bac692017-08-11 14:05:11 -04001149 .short_help = "set interface promiscuous [on|off] <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001150 .function = promiscuous_cmd,
1151};
Dave Barachba868bb2016-08-08 09:51:21 -04001152/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001153
1154static clib_error_t *
1155mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1156{
Dave Barachba868bb2016-08-08 09:51:21 -04001157 vnet_main_t *vnm = vnet_get_main ();
Ole Troand7231612018-06-07 10:17:57 +02001158 u32 hw_if_index, sw_if_index, mtu;
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001159 ethernet_main_t *em = &ethernet_main;
Ole Troand7231612018-06-07 10:17:57 +02001160 u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 };
Damjan Marion81bb6fc2022-01-16 22:47:55 +01001161 clib_error_t *err;
Damjan Marion8358ff92016-04-15 14:26:00 +02001162
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001163 if (unformat (input, "%d %U", &mtu,
1164 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001165 {
Ole Troand7231612018-06-07 10:17:57 +02001166 /*
1167 * Change physical MTU on interface. Only supported for Ethernet
1168 * interfaces
1169 */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001170 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1171 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
1172
1173 if (!eif)
1174 return clib_error_return (0, "not supported");
1175
1176 if (mtu < hi->min_supported_packet_bytes)
1177 return clib_error_return (0, "Invalid mtu (%d): "
1178 "must be >= min pkt bytes (%d)", mtu,
1179 hi->min_supported_packet_bytes);
1180
1181 if (mtu > hi->max_supported_packet_bytes)
1182 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
1183 hi->max_supported_packet_bytes);
1184
Damjan Marion81bb6fc2022-01-16 22:47:55 +01001185 err = vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu);
1186 if (err)
1187 return err;
Ole Troand7231612018-06-07 10:17:57 +02001188 goto done;
Damjan Marion8358ff92016-04-15 14:26:00 +02001189 }
Ole Troand7231612018-06-07 10:17:57 +02001190 else if (unformat (input, "packet %d %U", &mtu,
1191 unformat_vnet_sw_interface, vnm, &sw_if_index))
1192 /* Set default packet MTU (including L3 header */
1193 mtus[VNET_MTU_L3] = mtu;
1194 else if (unformat (input, "ip4 %d %U", &mtu,
1195 unformat_vnet_sw_interface, vnm, &sw_if_index))
1196 mtus[VNET_MTU_IP4] = mtu;
1197 else if (unformat (input, "ip6 %d %U", &mtu,
1198 unformat_vnet_sw_interface, vnm, &sw_if_index))
1199 mtus[VNET_MTU_IP6] = mtu;
1200 else if (unformat (input, "mpls %d %U", &mtu,
1201 unformat_vnet_sw_interface, vnm, &sw_if_index))
1202 mtus[VNET_MTU_MPLS] = mtu;
Damjan Marion8358ff92016-04-15 14:26:00 +02001203 else
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001204 return clib_error_return (0, "unknown input `%U'",
1205 format_unformat_error, input);
Ole Troand7231612018-06-07 10:17:57 +02001206
1207 vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus);
1208
1209done:
Damjan Marion8358ff92016-04-15 14:26:00 +02001210 return 0;
1211}
1212
Dave Barachba868bb2016-08-08 09:51:21 -04001213/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001214VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1215 .path = "set interface mtu",
Ole Troand7231612018-06-07 10:17:57 +02001216 .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001217 .function = mtu_cmd,
1218};
Dave Barachba868bb2016-08-08 09:51:21 -04001219/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001220
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001221static clib_error_t *
Matthew Smithe0792fd2019-07-12 11:48:24 -05001222show_interface_sec_mac_addr_fn (vlib_main_t * vm, unformat_input_t * input,
1223 vlib_cli_command_t * cmd)
1224{
1225 vnet_main_t *vnm = vnet_get_main ();
1226 vnet_interface_main_t *im = &vnm->interface_main;
1227 ethernet_main_t *em = &ethernet_main;
1228 u32 sw_if_index = ~0;
1229 vnet_sw_interface_t *si, *sorted_sis = 0;
1230
1231 if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1232 {
1233 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
1234 vec_add1 (sorted_sis, si[0]);
1235 }
1236
1237 /* if an interface name was not passed, get all interfaces */
1238 if (vec_len (sorted_sis) == 0)
1239 {
1240 sorted_sis =
1241 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
1242 _vec_len (sorted_sis) = 0;
1243 /* *INDENT-OFF* */
Damjan Marionb2c31b62020-12-13 21:47:40 +01001244 pool_foreach (si, im->sw_interfaces)
1245 {
Matthew Smithe0792fd2019-07-12 11:48:24 -05001246 int visible = vnet_swif_is_api_visible (si);
1247 if (visible)
Damjan Marionb2c31b62020-12-13 21:47:40 +01001248 vec_add1 (sorted_sis, si[0]);
1249 }
Matthew Smithe0792fd2019-07-12 11:48:24 -05001250 /* *INDENT-ON* */
1251 /* Sort by name. */
1252 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
1253 }
1254
1255 vec_foreach (si, sorted_sis)
1256 {
1257 vnet_sw_interface_t *sup_si;
1258 ethernet_interface_t *ei;
1259
1260 sup_si = vnet_get_sup_sw_interface (vnm, si->sw_if_index);
1261 ei = ethernet_get_interface (em, sup_si->hw_if_index);
1262
1263 vlib_cli_output (vm, "%U (%s):",
1264 format_vnet_sw_if_index_name, vnm, si->sw_if_index,
1265 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ?
1266 "up" : "dn");
1267
1268 if (ei && ei->secondary_addrs)
1269 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001270 ethernet_interface_address_t *sec_addr;
Matthew Smithe0792fd2019-07-12 11:48:24 -05001271
1272 vec_foreach (sec_addr, ei->secondary_addrs)
1273 {
Benoît Ganneb44c77d2020-10-20 16:24:17 +02001274 vlib_cli_output (vm, " %U", format_mac_address_t, &sec_addr->mac);
Matthew Smithe0792fd2019-07-12 11:48:24 -05001275 }
1276 }
1277 }
1278
1279 vec_free (sorted_sis);
1280 return 0;
1281}
1282
1283/*?
1284 * This command is used to display interface secondary mac addresses.
1285 *
1286 * @cliexpar
1287 * Example of how to display interface secondary mac addresses:
1288 * @cliexstart{show interface secondary-mac-address}
1289 * @cliexend
1290?*/
1291/* *INDENT-OFF* */
1292VLIB_CLI_COMMAND (show_interface_sec_mac_addr, static) = {
1293 .path = "show interface secondary-mac-address",
1294 .short_help = "show interface secondary-mac-address [<interface>]",
1295 .function = show_interface_sec_mac_addr_fn,
1296};
1297/* *INDENT-ON* */
1298
1299static clib_error_t *
1300interface_add_del_mac_address (vlib_main_t * vm, unformat_input_t * input,
1301 vlib_cli_command_t * cmd)
1302{
1303 vnet_main_t *vnm = vnet_get_main ();
1304 vnet_sw_interface_t *si = NULL;
1305 clib_error_t *error = 0;
1306 u32 sw_if_index = ~0;
1307 u8 mac[6] = { 0 };
1308 u8 is_add, is_del;
1309
1310 is_add = is_del = 0;
1311
1312 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1313 {
1314 error = clib_error_return (0, "unknown interface `%U'",
1315 format_unformat_error, input);
1316 goto done;
1317 }
1318 if (!unformat_user (input, unformat_ethernet_address, mac))
1319 {
1320 error = clib_error_return (0, "expected mac address `%U'",
1321 format_unformat_error, input);
1322 goto done;
1323 }
1324
1325 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
1326 {
1327 if (unformat (input, "add"))
1328 is_add = 1;
1329 else if (unformat (input, "del"))
1330 is_del = 1;
1331 else
1332 break;
1333 }
1334
1335 if (is_add == is_del)
1336 {
1337 error = clib_error_return (0, "must choose one of add or del");
1338 goto done;
1339 }
1340
1341 si = vnet_get_sw_interface (vnm, sw_if_index);
1342 error =
1343 vnet_hw_interface_add_del_mac_address (vnm, si->hw_if_index, mac, is_add);
1344
1345done:
1346 return error;
1347}
1348
1349/*?
1350 * The '<em>set interface secondary-mac-address </em>' command allows adding
1351 * or deleting extra MAC addresses on a given interface without changing the
1352 * default MAC address. This could allow packets sent to these MAC addresses
1353 * to be received without setting the interface to promiscuous mode.
1354 * Not all interfaces support this operation. The ones that do are mostly
1355 * hardware NICs, though virtio does also.
1356 *
1357 * @cliexpar
1358 * @parblock
1359 * Example of how to add a secondary MAC Address on an interface:
1360 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 add}
1361 * Example of how to delete a secondary MAC address from an interface:
1362 * @cliexcmd{set interface secondary-mac-address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01 del}
1363 * @endparblock
1364?*/
1365/* *INDENT-OFF* */
1366VLIB_CLI_COMMAND (interface_add_del_mac_address_cmd, static) = {
1367 .path = "set interface secondary-mac-address",
1368 .short_help = "set interface secondary-mac-address <interface> <mac-address> [(add|del)]",
1369 .function = interface_add_del_mac_address,
1370};
1371/* *INDENT-ON* */
1372
1373static clib_error_t *
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001374set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1375 vlib_cli_command_t * cmd)
1376{
1377 vnet_main_t *vnm = vnet_get_main ();
Neale Rannsd867a7c2017-10-04 02:29:07 -07001378 vnet_sw_interface_t *si = NULL;
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001379 clib_error_t *error = 0;
1380 u32 sw_if_index = ~0;
John Lo62fcc0a2017-10-31 14:31:10 -04001381 u8 mac[6] = { 0 };
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001382
1383 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1384 {
1385 error = clib_error_return (0, "unknown interface `%U'",
1386 format_unformat_error, input);
1387 goto done;
1388 }
John Lo62fcc0a2017-10-31 14:31:10 -04001389 if (!unformat_user (input, unformat_ethernet_address, mac))
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001390 {
1391 error = clib_error_return (0, "expected mac address `%U'",
1392 format_unformat_error, input);
1393 goto done;
1394 }
Neale Rannsd867a7c2017-10-04 02:29:07 -07001395 si = vnet_get_sw_interface (vnm, sw_if_index);
1396 error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac);
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001397done:
1398 return error;
1399}
1400
1401/*?
1402 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1403 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1404 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1405 *
1406 * @cliexpar
1407 * @parblock
1408 * Example of how to change MAC Address of interface:
1409 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1410 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1411 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1412 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1413 * @endparblock
1414?*/
1415/* *INDENT-OFF* */
1416VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1417 .path = "set interface mac address",
Billy McFalle9bac692017-08-11 14:05:11 -04001418 .short_help = "set interface mac address <interface> <mac-address>",
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001419 .function = set_interface_mac_address,
1420};
1421/* *INDENT-ON* */
1422
Dave Barach7be864a2016-11-28 11:41:35 -05001423static clib_error_t *
1424set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1425{
1426 vnet_main_t *vnm = vnet_get_main ();
1427 u32 sw_if_index = ~0;
1428 u8 *tag = 0;
1429
1430 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1431 vnm, &sw_if_index, &tag))
1432 return clib_error_return (0, "unknown input `%U'",
1433 format_unformat_error, input);
1434
1435 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1436
1437 return 0;
1438}
1439
1440/* *INDENT-OFF* */
1441VLIB_CLI_COMMAND (set_tag_command, static) = {
1442 .path = "set interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001443 .short_help = "set interface tag <interface> <tag>",
Dave Barach7be864a2016-11-28 11:41:35 -05001444 .function = set_tag,
1445};
1446/* *INDENT-ON* */
1447
1448static clib_error_t *
1449clear_tag (vlib_main_t * vm, unformat_input_t * input,
1450 vlib_cli_command_t * cmd)
1451{
1452 vnet_main_t *vnm = vnet_get_main ();
1453 u32 sw_if_index = ~0;
1454
1455 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1456 return clib_error_return (0, "unknown input `%U'",
1457 format_unformat_error, input);
1458
1459 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1460
1461 return 0;
1462}
1463
1464/* *INDENT-OFF* */
1465VLIB_CLI_COMMAND (clear_tag_command, static) = {
1466 .path = "clear interface tag",
Billy McFalle9bac692017-08-11 14:05:11 -04001467 .short_help = "clear interface tag <interface>",
Dave Barach7be864a2016-11-28 11:41:35 -05001468 .function = clear_tag,
1469};
1470/* *INDENT-ON* */
1471
Damjan Marion44036902017-04-28 12:29:15 +02001472static clib_error_t *
Neale Ranns1855b8e2018-07-11 10:31:26 -07001473set_ip_directed_broadcast (vlib_main_t * vm,
1474 unformat_input_t * input, vlib_cli_command_t * cmd)
1475{
1476 vnet_main_t *vnm = vnet_get_main ();
1477 u32 sw_if_index = ~0;
1478 u8 enable = 0;
1479
1480 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index));
1481 else if (unformat (input, "enable"))
1482 enable = 1;
1483 else if (unformat (input, "disable"))
1484 enable = 0;
1485 else
1486 return clib_error_return (0, "unknown input: `%U'",
1487 format_unformat_error, input);
1488
1489 if (~0 == sw_if_index)
1490 return clib_error_return (0, "specify an interface: `%U'",
1491 format_unformat_error, input);
1492
1493 vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable);
1494
1495 return 0;
1496}
1497
1498/*?
1499 * This command is used to enable/disable IP directed broadcast
1500 * If directed broadcast is enabled a packet sent to the interface's
1501 * subnet broadcast address will be sent L2 broadcast on the interface,
1502 * otherwise it is dropped.
1503 ?*/
1504/* *INDENT-OFF* */
1505VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = {
1506 .path = "set interface ip directed-broadcast",
1507 .short_help = "set interface enable <interface> <enable|disable>",
1508 .function = set_ip_directed_broadcast,
1509};
1510/* *INDENT-ON* */
1511
Stevenad8015b2017-10-29 22:10:46 -07001512clib_error_t *
1513set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1514 u8 queue_id_valid, u32 queue_id,
Damjan Marioneabd4242020-10-07 20:59:07 +02001515 vnet_hw_if_rx_mode mode)
Stevenad8015b2017-10-29 22:10:46 -07001516{
1517 clib_error_t *error = 0;
1518 vnet_hw_interface_t *hw;
Damjan Marion94100532020-11-06 23:25:57 +01001519 u32 *queue_indices = 0;
Stevenad8015b2017-10-29 22:10:46 -07001520
1521 hw = vnet_get_hw_interface (vnm, hw_if_index);
1522
Damjan Marion94100532020-11-06 23:25:57 +01001523 if (queue_id_valid)
1524 {
1525 u32 queue_index;
1526 queue_index =
1527 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1528 if (queue_index == ~0)
1529 return clib_error_return (0, "unknown queue %u on interface %s",
1530 queue_id, hw->name);
1531 vec_add1 (queue_indices, queue_index);
Stevenad8015b2017-10-29 22:10:46 -07001532 }
1533 else
Damjan Marion94100532020-11-06 23:25:57 +01001534 queue_indices = hw->rx_queue_indices;
Stevenad8015b2017-10-29 22:10:46 -07001535
Damjan Marion94100532020-11-06 23:25:57 +01001536 for (int i = 0; i < vec_len (queue_indices); i++)
1537 {
1538 int rv = vnet_hw_if_set_rx_queue_mode (vnm, queue_indices[i], mode);
1539 if (rv)
1540 goto done;
1541 }
1542
1543done:
1544 if (queue_indices != hw->rx_queue_indices)
1545 vec_free (queue_indices);
1546 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1547 return error;
Stevenad8015b2017-10-29 22:10:46 -07001548}
1549
Stevene3a395c2017-05-09 16:19:50 -07001550static clib_error_t *
Damjan Marion44036902017-04-28 12:29:15 +02001551set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1552 vlib_cli_command_t * cmd)
1553{
1554 clib_error_t *error = 0;
1555 unformat_input_t _line_input, *line_input = &_line_input;
1556 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion44036902017-04-28 12:29:15 +02001557 u32 hw_if_index = (u32) ~ 0;
1558 u32 queue_id = (u32) ~ 0;
Damjan Marioneabd4242020-10-07 20:59:07 +02001559 vnet_hw_if_rx_mode mode = VNET_HW_IF_RX_MODE_UNKNOWN;
Stevenad8015b2017-10-29 22:10:46 -07001560 u8 queue_id_valid = 0;
Dave Barach7be864a2016-11-28 11:41:35 -05001561
Damjan Marion44036902017-04-28 12:29:15 +02001562 if (!unformat_user (input, unformat_line_input, line_input))
1563 return 0;
1564
1565 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1566 {
1567 if (unformat
1568 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1569 ;
1570 else if (unformat (line_input, "queue %d", &queue_id))
Stevenad8015b2017-10-29 22:10:46 -07001571 queue_id_valid = 1;
Damjan Marion44036902017-04-28 12:29:15 +02001572 else if (unformat (line_input, "polling"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001573 mode = VNET_HW_IF_RX_MODE_POLLING;
Damjan Marion44036902017-04-28 12:29:15 +02001574 else if (unformat (line_input, "interrupt"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001575 mode = VNET_HW_IF_RX_MODE_INTERRUPT;
Damjan Marion44036902017-04-28 12:29:15 +02001576 else if (unformat (line_input, "adaptive"))
Damjan Marioneabd4242020-10-07 20:59:07 +02001577 mode = VNET_HW_IF_RX_MODE_ADAPTIVE;
Damjan Marion44036902017-04-28 12:29:15 +02001578 else
1579 {
1580 error = clib_error_return (0, "parse error: '%U'",
1581 format_unformat_error, line_input);
1582 unformat_free (line_input);
1583 return error;
1584 }
1585 }
1586
1587 unformat_free (line_input);
1588
1589 if (hw_if_index == (u32) ~ 0)
1590 return clib_error_return (0, "please specify valid interface name");
1591
Damjan Marioneabd4242020-10-07 20:59:07 +02001592 if (mode == VNET_HW_IF_RX_MODE_UNKNOWN)
Damjan Marion44036902017-04-28 12:29:15 +02001593 return clib_error_return (0, "please specify valid rx-mode");
1594
Stevenad8015b2017-10-29 22:10:46 -07001595 error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid,
1596 queue_id, mode);
Damjan Marion44036902017-04-28 12:29:15 +02001597
Stevene3a395c2017-05-09 16:19:50 -07001598 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001599}
1600
1601/*?
Billy McFalle9bac692017-08-11 14:05:11 -04001602 * This command is used to assign the RX packet processing mode (polling,
1603 * interrupt, adaptive) of the a given interface, and optionally a
1604 * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>'
1605 * is applied to all queues of the interface. Not all interfaces support
1606 * all modes. To display the current rx-mode use the command
1607 * '<em>show interface rx-placement</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001608 *
1609 * @cliexpar
Billy McFalle9bac692017-08-11 14:05:11 -04001610 * Example of how to assign rx-mode to all queues on an interface:
1611 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling}
1612 * Example of how to assign rx-mode to one queue of an interface:
1613 * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt}
1614 * Example of how to display the rx-mode of all interfaces:
Damjan Marion44036902017-04-28 12:29:15 +02001615 * @cliexstart{show interface rx-placement}
1616 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001617 * node dpdk-input:
1618 * GigabitEthernet7/0/0 queue 0 (polling)
1619 * node vhost-user-input:
1620 * VirtualEthernet0/0/12 queue 0 (interrupt)
1621 * VirtualEthernet0/0/12 queue 2 (polling)
1622 * VirtualEthernet0/0/13 queue 0 (polling)
1623 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001624 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001625 * node dpdk-input:
1626 * GigabitEthernet7/0/1 queue 0 (polling)
1627 * node vhost-user-input:
1628 * VirtualEthernet0/0/12 queue 1 (polling)
1629 * VirtualEthernet0/0/12 queue 3 (polling)
1630 * VirtualEthernet0/0/13 queue 1 (polling)
1631 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001632 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001633?*/
1634/* *INDENT-OFF* */
Damjan Marionfe7d4a22018-04-13 19:43:39 +02001635VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
Damjan Marion44036902017-04-28 12:29:15 +02001636 .path = "set interface rx-mode",
1637 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1638 .function = set_interface_rx_mode,
1639};
1640/* *INDENT-ON* */
1641
1642static clib_error_t *
1643show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1644 vlib_cli_command_t * cmd)
1645{
1646 u8 *s = 0;
1647 vnet_main_t *vnm = vnet_get_main ();
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001648 vnet_hw_if_rx_queue_t **all_queues = 0;
1649 vnet_hw_if_rx_queue_t **qptr;
1650 vnet_hw_if_rx_queue_t *q;
Nathan Skrzypczak455779f2021-02-15 14:48:33 +01001651 pool_foreach (q, vnm->interface_main.hw_if_rx_queues)
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001652 vec_add1 (all_queues, q);
1653 vec_sort_with_function (all_queues, vnet_hw_if_rxq_cmp_cli_api);
1654 u32 prev_node = ~0;
Damjan Marion44036902017-04-28 12:29:15 +02001655
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001656 vec_foreach (qptr, all_queues)
1657 {
1658 u32 current_thread = qptr[0]->thread_index;
1659 u32 hw_if_index = qptr[0]->hw_if_index;
1660 vnet_hw_interface_t *hw_if = vnet_get_hw_interface (vnm, hw_if_index);
1661 u32 current_node = hw_if->input_node_index;
1662 if (current_node != prev_node)
1663 s = format (s, " node %U:\n", format_vlib_node_name, vm, current_node);
1664 s = format (s, " %U queue %u (%U)\n", format_vnet_sw_if_index_name,
1665 vnm, hw_if->sw_if_index, qptr[0]->queue_id,
1666 format_vnet_hw_if_rx_mode, qptr[0]->mode);
1667 if (qptr == all_queues + vec_len (all_queues) - 1 ||
1668 current_thread != qptr[1]->thread_index)
1669 {
1670 vlib_cli_output (vm, "Thread %u (%s):\n%v", current_thread,
1671 vlib_worker_threads[current_thread].name, s);
1672 vec_reset_length (s);
1673 }
1674 prev_node = current_node;
1675 }
Damjan Marion44036902017-04-28 12:29:15 +02001676 vec_free (s);
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001677 vec_free (all_queues);
Damjan Marion44036902017-04-28 12:29:15 +02001678 return 0;
1679}
1680
Billy McFalle9bac692017-08-11 14:05:11 -04001681/*?
1682 * This command is used to display the interface and queue worker
1683 * thread placement.
1684 *
1685 * @cliexpar
1686 * Example of how to display the interface placement:
1687 * @cliexstart{show interface rx-placement}
1688 * Thread 1 (vpp_wk_0):
1689 * node dpdk-input:
1690 * GigabitEthernet7/0/0 queue 0 (polling)
1691 * node vhost-user-input:
1692 * VirtualEthernet0/0/12 queue 0 (polling)
1693 * VirtualEthernet0/0/12 queue 2 (polling)
1694 * VirtualEthernet0/0/13 queue 0 (polling)
1695 * VirtualEthernet0/0/13 queue 2 (polling)
1696 * Thread 2 (vpp_wk_1):
1697 * node dpdk-input:
1698 * GigabitEthernet7/0/1 queue 0 (polling)
1699 * node vhost-user-input:
1700 * VirtualEthernet0/0/12 queue 1 (polling)
1701 * VirtualEthernet0/0/12 queue 3 (polling)
1702 * VirtualEthernet0/0/13 queue 1 (polling)
1703 * VirtualEthernet0/0/13 queue 3 (polling)
1704 * @cliexend
1705?*/
Damjan Marion44036902017-04-28 12:29:15 +02001706/* *INDENT-OFF* */
1707VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1708 .path = "show interface rx-placement",
1709 .short_help = "show interface rx-placement",
1710 .function = show_interface_rx_placement_fn,
1711};
1712/* *INDENT-ON* */
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001713clib_error_t *
1714set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id,
1715 u32 thread_index, u8 is_main)
Damjan Marion44036902017-04-28 12:29:15 +02001716{
Damjan Marion44036902017-04-28 12:29:15 +02001717 vnet_main_t *vnm = vnet_get_main ();
1718 vnet_device_main_t *vdm = &vnet_device_main;
Damjan Marion94100532020-11-06 23:25:57 +01001719 vnet_hw_interface_t *hw;
1720 u32 queue_index;
Damjan Marion44036902017-04-28 12:29:15 +02001721
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001722 if (is_main)
1723 thread_index = 0;
1724 else
1725 thread_index += vdm->first_worker_thread_index;
Damjan Marion44036902017-04-28 12:29:15 +02001726
1727 if (thread_index > vdm->last_worker_thread_index)
1728 return clib_error_return (0,
1729 "please specify valid worker thread or main");
1730
Damjan Marion94100532020-11-06 23:25:57 +01001731 hw = vnet_get_hw_interface (vnm, hw_if_index);
Damjan Marion44036902017-04-28 12:29:15 +02001732
Damjan Marion94100532020-11-06 23:25:57 +01001733 queue_index =
1734 vnet_hw_if_get_rx_queue_index_by_id (vnm, hw_if_index, queue_id);
1735 if (queue_index == ~0)
1736 return clib_error_return (0, "unknown queue %u on interface %s", queue_id,
1737 hw->name);
1738 vnet_hw_if_set_rx_queue_thread_index (vnm, queue_index, thread_index);
1739 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1740 return 0;
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001741}
1742
1743static clib_error_t *
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01001744set_interface_rx_placement (vlib_main_t *vm, unformat_input_t *input,
1745 vlib_cli_command_t *cmd)
Mohsin Kazmi54f7c512018-08-23 18:28:11 +02001746{
1747 clib_error_t *error = 0;
1748 unformat_input_t _line_input, *line_input = &_line_input;
1749 vnet_main_t *vnm = vnet_get_main ();
1750 u32 hw_if_index = (u32) ~ 0;
1751 u32 queue_id = (u32) 0;
1752 u32 thread_index = (u32) ~ 0;
1753 u8 is_main = 0;
1754
1755 if (!unformat_user (input, unformat_line_input, line_input))
1756 return 0;
1757
1758 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1759 {
1760 if (unformat
1761 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1762 ;
1763 else if (unformat (line_input, "queue %d", &queue_id))
1764 ;
1765 else if (unformat (line_input, "main", &thread_index))
1766 is_main = 1;
1767 else if (unformat (line_input, "worker %d", &thread_index))
1768 ;
1769 else
1770 {
1771 error = clib_error_return (0, "parse error: '%U'",
1772 format_unformat_error, line_input);
1773 unformat_free (line_input);
1774 return error;
1775 }
1776 }
1777
1778 unformat_free (line_input);
1779
1780 if (hw_if_index == (u32) ~ 0)
1781 return clib_error_return (0, "please specify valid interface name");
1782
1783 error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index,
1784 is_main);
1785
1786 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001787}
1788
1789/*?
1790 * This command is used to assign a given interface, and optionally a
1791 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
Billy McFalle9bac692017-08-11 14:05:11 -04001792 * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index
1793 * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'.
Damjan Marion44036902017-04-28 12:29:15 +02001794 *
1795 * @cliexpar
1796 * Example of how to display the interface placement:
Billy McFalle9bac692017-08-11 14:05:11 -04001797 * @cliexstart{show interface rx-placement}
Damjan Marion44036902017-04-28 12:29:15 +02001798 * Thread 1 (vpp_wk_0):
Billy McFalle9bac692017-08-11 14:05:11 -04001799 * node dpdk-input:
1800 * GigabitEthernet7/0/0 queue 0 (polling)
1801 * node vhost-user-input:
1802 * VirtualEthernet0/0/12 queue 0 (polling)
1803 * VirtualEthernet0/0/12 queue 2 (polling)
1804 * VirtualEthernet0/0/13 queue 0 (polling)
1805 * VirtualEthernet0/0/13 queue 2 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001806 * Thread 2 (vpp_wk_1):
Billy McFalle9bac692017-08-11 14:05:11 -04001807 * node dpdk-input:
1808 * GigabitEthernet7/0/1 queue 0 (polling)
1809 * node vhost-user-input:
1810 * VirtualEthernet0/0/12 queue 1 (polling)
1811 * VirtualEthernet0/0/12 queue 3 (polling)
1812 * VirtualEthernet0/0/13 queue 1 (polling)
1813 * VirtualEthernet0/0/13 queue 3 (polling)
Damjan Marion44036902017-04-28 12:29:15 +02001814 * @cliexend
Billy McFalle9bac692017-08-11 14:05:11 -04001815 * Example of how to assign a interface and queue to a worker thread:
1816 * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0}
1817 * Example of how to display the interface placement:
1818 * @cliexstart{show interface rx-placement}
1819 * Thread 1 (vpp_wk_0):
1820 * node dpdk-input:
1821 * GigabitEthernet7/0/0 queue 0 (polling)
1822 * node vhost-user-input:
1823 * VirtualEthernet0/0/12 queue 0 (polling)
1824 * VirtualEthernet0/0/12 queue 1 (polling)
1825 * VirtualEthernet0/0/12 queue 2 (polling)
1826 * VirtualEthernet0/0/13 queue 0 (polling)
1827 * VirtualEthernet0/0/13 queue 2 (polling)
1828 * Thread 2 (vpp_wk_1):
1829 * node dpdk-input:
1830 * GigabitEthernet7/0/1 queue 0 (polling)
1831 * node vhost-user-input:
1832 * VirtualEthernet0/0/12 queue 3 (polling)
1833 * VirtualEthernet0/0/13 queue 1 (polling)
1834 * VirtualEthernet0/0/13 queue 3 (polling)
1835 * @cliexend
Damjan Marion44036902017-04-28 12:29:15 +02001836?*/
1837/* *INDENT-OFF* */
1838VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1839 .path = "set interface rx-placement",
Billy McFalle9bac692017-08-11 14:05:11 -04001840 .short_help = "set interface rx-placement <interface> [queue <n>] "
Damjan Marion6f9ac652017-06-15 19:01:31 +02001841 "[worker <n> | main]",
Damjan Marion44036902017-04-28 12:29:15 +02001842 .function = set_interface_rx_placement,
Damjan Marion6f9ac652017-06-15 19:01:31 +02001843 .is_mp_safe = 1,
Damjan Marion44036902017-04-28 12:29:15 +02001844};
Damjan Marion44036902017-04-28 12:29:15 +02001845/* *INDENT-ON* */
Dave Barach5ecd5a52019-02-25 15:27:28 -05001846
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001847int
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001848set_hw_interface_tx_queue (u32 hw_if_index, u32 queue_id, uword *bitmap)
1849{
1850 vnet_main_t *vnm = vnet_get_main ();
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001851 vlib_thread_main_t *vtm = vlib_get_thread_main ();
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001852 vnet_hw_if_tx_queue_t *txq;
1853 u32 queue_index;
1854 u32 thread_index;
1855
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001856 /* highest set bit in bitmap should not exceed last worker thread index */
Steven Luong8e3f1092021-06-17 08:22:50 -07001857 thread_index = clib_bitmap_last_set (bitmap);
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001858 if ((thread_index != ~0) && (thread_index >= vtm->n_vlib_mains))
1859 return VNET_API_ERROR_INVALID_VALUE;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001860
1861 queue_index =
1862 vnet_hw_if_get_tx_queue_index_by_id (vnm, hw_if_index, queue_id);
1863 if (queue_index == ~0)
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001864 return VNET_API_ERROR_INVALID_QUEUE;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001865
1866 txq = vnet_hw_if_get_tx_queue (vnm, queue_index);
1867
1868 // free the existing bitmap
1869 if (clib_bitmap_count_set_bits (txq->threads))
1870 {
1871 txq->shared_queue = 0;
1872 clib_bitmap_free (txq->threads);
1873 }
1874
1875 clib_bitmap_foreach (thread_index, bitmap)
1876 vnet_hw_if_tx_queue_assign_thread (vnm, queue_index, thread_index);
1877
1878 vnet_hw_if_update_runtime_data (vnm, hw_if_index);
1879 return 0;
1880}
1881
1882static clib_error_t *
1883set_interface_tx_queue (vlib_main_t *vm, unformat_input_t *input,
1884 vlib_cli_command_t *cmd)
1885{
1886 clib_error_t *error = 0;
1887 unformat_input_t _line_input, *line_input = &_line_input;
1888 vnet_main_t *vnm = vnet_get_main ();
1889 u32 hw_if_index = (u32) ~0;
1890 u32 queue_id = (u32) 0;
1891 uword *bitmap = 0;
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001892 int rv = 0;
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001893
1894 if (!unformat_user (input, unformat_line_input, line_input))
1895 return 0;
1896
1897 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1898 {
1899 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
1900 &hw_if_index))
1901 ;
1902 else if (unformat (line_input, "queue %d", &queue_id))
1903 ;
1904 else if (unformat (line_input, "threads %U", unformat_bitmap_list,
1905 &bitmap))
1906 ;
1907 else
1908 {
1909 error = clib_error_return (0, "parse error: '%U'",
1910 format_unformat_error, line_input);
1911 unformat_free (line_input);
1912 return error;
1913 }
1914 }
1915
1916 unformat_free (line_input);
1917
1918 if (hw_if_index == (u32) ~0)
1919 {
1920 error = clib_error_return (0, "please specify valid interface name");
1921 goto error;
1922 }
1923
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00001924 rv = set_hw_interface_tx_queue (hw_if_index, queue_id, bitmap);
1925
1926 switch (rv)
1927 {
1928 case VNET_API_ERROR_INVALID_VALUE:
1929 error = clib_error_return (
1930 0, "please specify valid thread(s) - last thread index %u",
1931 clib_bitmap_last_set (bitmap));
1932 break;
1933 case VNET_API_ERROR_INVALID_QUEUE:
1934 error = clib_error_return (
1935 0, "unknown queue %u on interface %s", queue_id,
1936 vnet_get_hw_interface (vnet_get_main (), hw_if_index)->name);
1937 break;
1938 default:
1939 break;
1940 }
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001941
1942error:
1943 clib_bitmap_free (bitmap);
1944 return (error);
1945}
1946
1947VLIB_CLI_COMMAND (cmd_set_if_tx_queue, static) = {
1948 .path = "set interface tx-queue",
1949 .short_help = "set interface tx-queue <interface> queue <n> "
Steven Luong8e3f1092021-06-17 08:22:50 -07001950 "[threads <list>]",
Mohsin Kazmi005605f2021-05-24 18:33:50 +02001951 .function = set_interface_tx_queue,
1952 .is_mp_safe = 1,
1953};
1954
1955clib_error_t *
Chenmin Sunc4665092020-07-06 08:20:39 +08001956set_interface_rss_queues (vlib_main_t * vm, u32 hw_if_index,
1957 clib_bitmap_t * bitmap)
1958{
1959 vnet_main_t *vnm = vnet_get_main ();
1960 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1961
1962 return vnet_hw_interface_set_rss_queues (vnm, hi, bitmap);
1963}
1964
1965static clib_error_t *
1966set_interface_rss_queues_fn (vlib_main_t * vm,
1967 unformat_input_t * input,
1968 vlib_cli_command_t * cmd)
1969{
1970 clib_error_t *error = 0;
1971 unformat_input_t _line_input, *line_input = &_line_input;
1972 vnet_main_t *vnm = vnet_get_main ();
1973 u32 hw_if_index = (u32) ~ 0;
1974 clib_bitmap_t *bitmap = NULL;
1975
1976 if (!unformat_user (input, unformat_line_input, line_input))
1977 return 0;
1978
1979 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1980 {
1981 if (unformat
1982 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1983 ;
1984 else
1985 if (unformat (line_input, "list %U", unformat_bitmap_list, &bitmap))
1986 ;
1987 else
1988 {
1989 error = clib_error_return (0, "parse error: '%U'",
1990 format_unformat_error, line_input);
1991 unformat_free (line_input);
1992 goto done;
1993 }
1994 }
1995
1996 unformat_free (line_input);
1997
1998 if (hw_if_index == (u32) ~ 0)
1999 {
2000 error = clib_error_return (0, "please specify valid interface name");
2001 goto done;
2002 }
2003
2004 if (bitmap == NULL)
2005 {
2006 error = clib_error_return (0, "please specify the valid rss queues");
2007 goto done;
2008 }
2009
2010 error = set_interface_rss_queues (vm, hw_if_index, bitmap);
2011
2012done:
2013 if (bitmap)
2014 clib_bitmap_free (bitmap);
2015
2016 return (error);
2017}
2018
2019/*?
2020 * This command is used to set the rss queues of a given interface
2021 * Not all the interfaces support this operation.
2022 * To display the current rss queues, use the command
2023 * '<em>show hardware-interfaces</em>'.
2024 *
2025 * @cliexpar
2026 * Example of how to set the rss queues to 0,2-5,7 of an interface:
2027 * @cliexstart{set interface rss queues VirtualFunctionEthernet18/1/0 list 0,2-5,7}
2028 * @cliexend
2029?*/
2030/* *INDENT-OFF* */
2031VLIB_CLI_COMMAND (cmd_set_interface_rss_queues,static) = {
2032 .path = "set interface rss queues",
2033 .short_help = "set interface rss queues <interface> <list <queue-list>>",
2034 .function = set_interface_rss_queues_fn,
2035};
2036/* *INDENT-ON* */
2037
Dave Barach33909772019-09-23 10:27:27 -04002038static u8 *
2039format_vnet_pcap (u8 * s, va_list * args)
2040{
2041 vnet_pcap_t *pp = va_arg (*args, vnet_pcap_t *);
2042 int type = va_arg (*args, int);
2043 int printed = 0;
2044
2045 if (type == 0)
2046 {
2047 if (pp->pcap_rx_enable)
2048 {
2049 s = format (s, "rx");
2050 printed = 1;
2051 }
2052 if (pp->pcap_tx_enable)
2053 {
2054 if (printed)
2055 s = format (s, " and ");
2056 s = format (s, "tx");
2057 printed = 1;
2058 }
2059 if (pp->pcap_drop_enable)
2060 {
2061 if (printed)
2062 s = format (s, " and ");
2063 s = format (s, "drop");
2064 printed = 1;
2065 }
2066 return s;
2067 }
2068 s = format (s, "unknown type %d!", type);
2069 return s;
2070}
2071
2072
Dave Barachb97641c2019-09-09 16:38:17 -04002073int
2074vnet_pcap_dispatch_trace_configure (vnet_pcap_dispatch_trace_args_t * a)
2075{
2076 vlib_main_t *vm = vlib_get_main ();
Damjan Marion8fb5add2021-03-04 18:41:59 +01002077 vnet_main_t *vnm = vnet_get_main ();
2078 vnet_pcap_t *pp = &vnm->pcap;
Dave Barachb97641c2019-09-09 16:38:17 -04002079 pcap_main_t *pm = &pp->pcap_main;
Dave Barachf5667c32019-09-25 11:27:46 -04002080 vnet_classify_main_t *cm = &vnet_classify_main;
Dave Barachb97641c2019-09-09 16:38:17 -04002081
2082 if (a->status)
2083 {
Dave Barach33909772019-09-23 10:27:27 -04002084 if (pp->pcap_rx_enable || pp->pcap_tx_enable || pp->pcap_drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002085 {
2086 vlib_cli_output
Dave Barach33909772019-09-23 10:27:27 -04002087 (vm, "pcap %U dispatch capture enabled: %d of %d pkts...",
2088 format_vnet_pcap, pp, 0 /* print type */ ,
Dave Barachb97641c2019-09-09 16:38:17 -04002089 pm->n_packets_captured, pm->n_packets_to_capture);
2090 vlib_cli_output (vm, "capture to file %s", pm->file_name);
2091 }
2092 else
Dave Barach33909772019-09-23 10:27:27 -04002093 vlib_cli_output (vm, "pcap dispatch capture disabled");
2094
Dave Barachb97641c2019-09-09 16:38:17 -04002095 return 0;
2096 }
2097
2098 /* Consistency checks */
2099
2100 /* Enable w/ capture already enabled not allowed */
Dave Barach33909772019-09-23 10:27:27 -04002101 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2102 && (a->rx_enable + a->tx_enable + a->drop_enable))
Dave Barachb97641c2019-09-09 16:38:17 -04002103 return VNET_API_ERROR_INVALID_VALUE;
2104
2105 /* Disable capture with capture already disabled, not interesting */
Mohammed Hawari9fecbe12020-12-11 19:36:37 +01002106 if (((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable) ==
2107 0) &&
2108 ((a->rx_enable + a->tx_enable + a->drop_enable == 0)))
Dave Barachb97641c2019-09-09 16:38:17 -04002109 return VNET_API_ERROR_VALUE_EXIST;
2110
2111 /* Change number of packets to capture while capturing */
Dave Barach33909772019-09-23 10:27:27 -04002112 if ((pp->pcap_rx_enable + pp->pcap_tx_enable + pp->pcap_drop_enable)
2113 && (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002114 && (pm->n_packets_to_capture != a->packets_to_capture))
2115 return VNET_API_ERROR_INVALID_VALUE_2;
2116
Dave Barach33909772019-09-23 10:27:27 -04002117 /* Classify filter specified, but no classify filter configured */
Dave Barachf5667c32019-09-25 11:27:46 -04002118 if ((a->rx_enable + a->tx_enable + a->drop_enable) && a->filter &&
Benoît Ganne5943e362021-02-26 14:46:58 +01002119 (!cm->classify_table_index_by_sw_if_index ||
2120 cm->classify_table_index_by_sw_if_index[0] == ~0))
Dave Barach9137e542019-09-13 17:47:50 -04002121 return VNET_API_ERROR_NO_SUCH_LABEL;
2122
Dave Barach33909772019-09-23 10:27:27 -04002123 if (a->rx_enable + a->tx_enable + a->drop_enable)
Dave Barachb97641c2019-09-09 16:38:17 -04002124 {
Dave Barach586462f2020-08-05 16:12:35 -04002125 void *save_pcap_data;
2126
Dave Barach33909772019-09-23 10:27:27 -04002127 /* Sanity check max bytes per pkt */
2128 if (a->max_bytes_per_pkt < 32 || a->max_bytes_per_pkt > 9000)
2129 return VNET_API_ERROR_INVALID_MEMORY_SIZE;
2130
Dave Barachb97641c2019-09-09 16:38:17 -04002131 /* Clean up from previous run, if any */
Dave Barach586462f2020-08-05 16:12:35 -04002132 vec_reset_length (pm->pcap_data);
2133
2134 /* Throw away the data buffer? */
2135 if (a->free_data)
2136 vec_free (pm->pcap_data);
2137
2138 save_pcap_data = pm->pcap_data;
2139
Dave Barachb97641c2019-09-09 16:38:17 -04002140 memset (pm, 0, sizeof (*pm));
2141
Dave Barach586462f2020-08-05 16:12:35 -04002142 pm->pcap_data = save_pcap_data;
2143
Dave Barach11fb09e2020-08-06 12:10:09 -04002144 vec_validate_aligned (vnet_trace_placeholder, 2048,
2145 CLIB_CACHE_LINE_BYTES);
Dave Barachb97641c2019-09-09 16:38:17 -04002146 if (pm->lock == 0)
2147 clib_spinlock_init (&(pm->lock));
2148
2149 if (a->filename == 0)
Dave Barach33909772019-09-23 10:27:27 -04002150 {
2151 u8 *stem = 0;
2152
2153 if (a->rx_enable)
2154 stem = format (stem, "rx");
2155 if (a->tx_enable)
2156 stem = format (stem, "tx");
2157 if (a->drop_enable)
2158 stem = format (stem, "drop");
Benoît Ganne7d4a9972020-07-17 11:49:56 +02002159 a->filename = format (0, "/tmp/%v.pcap%c", stem, 0);
Dave Barach33909772019-09-23 10:27:27 -04002160 vec_free (stem);
2161 }
Dave Barachb97641c2019-09-09 16:38:17 -04002162
2163 pm->file_name = (char *) a->filename;
2164 pm->n_packets_captured = 0;
2165 pm->packet_type = PCAP_PACKET_TYPE_ethernet;
Dave Barach586462f2020-08-05 16:12:35 -04002166 /* Preallocate the data vector? */
2167 if (a->preallocate_data)
2168 {
2169 vec_validate
2170 (pm->pcap_data, a->packets_to_capture
2171 * ((sizeof (pcap_packet_header_t) + a->max_bytes_per_pkt)));
2172 vec_reset_length (pm->pcap_data);
2173 }
Dave Barachb97641c2019-09-09 16:38:17 -04002174 pm->n_packets_to_capture = a->packets_to_capture;
2175 pp->pcap_sw_if_index = a->sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04002176 if (a->filter)
Jon Loeliger5c1e48c2020-10-15 14:41:36 -04002177 pp->filter_classify_table_index =
2178 cm->classify_table_index_by_sw_if_index[0];
Dave Barach9137e542019-09-13 17:47:50 -04002179 else
2180 pp->filter_classify_table_index = ~0;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002181 pp->pcap_error_index = a->drop_err;
Dave Barach33909772019-09-23 10:27:27 -04002182 pp->pcap_rx_enable = a->rx_enable;
2183 pp->pcap_tx_enable = a->tx_enable;
2184 pp->pcap_drop_enable = a->drop_enable;
2185 pp->max_bytes_per_pkt = a->max_bytes_per_pkt;
Dave Barachb97641c2019-09-09 16:38:17 -04002186 }
2187 else
2188 {
Dave Barach33909772019-09-23 10:27:27 -04002189 pp->pcap_rx_enable = 0;
2190 pp->pcap_tx_enable = 0;
2191 pp->pcap_drop_enable = 0;
Dave Barachf5667c32019-09-25 11:27:46 -04002192 pp->filter_classify_table_index = ~0;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002193 pp->pcap_error_index = ~0;
Dave Barachb97641c2019-09-09 16:38:17 -04002194 if (pm->n_packets_captured)
2195 {
2196 clib_error_t *error;
2197 pm->n_packets_to_capture = pm->n_packets_captured;
2198 vlib_cli_output (vm, "Write %d packets to %s, and stop capture...",
2199 pm->n_packets_captured, pm->file_name);
2200 error = pcap_write (pm);
Andrew Yourtchenko4da15062019-09-11 14:14:43 +00002201 if (pm->flags & PCAP_MAIN_INIT_DONE)
Dave Barachb97641c2019-09-09 16:38:17 -04002202 pcap_close (pm);
2203 /* Report I/O errors... */
2204 if (error)
2205 {
2206 clib_error_report (error);
2207 return VNET_API_ERROR_SYSCALL_ERROR_1;
2208 }
Dave Barach586462f2020-08-05 16:12:35 -04002209 vec_free (pm->file_name);
2210 if (a->free_data)
2211 vec_free (pm->pcap_data);
Dave Barachb97641c2019-09-09 16:38:17 -04002212 return 0;
2213 }
2214 else
2215 return VNET_API_ERROR_NO_SUCH_ENTRY;
2216 }
2217
2218 return 0;
2219}
2220
2221static clib_error_t *
Dave Barach33909772019-09-23 10:27:27 -04002222pcap_trace_command_fn (vlib_main_t * vm,
2223 unformat_input_t * input, vlib_cli_command_t * cmd)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002224{
Dave Barach5ecd5a52019-02-25 15:27:28 -05002225 unformat_input_t _line_input, *line_input = &_line_input;
Dave Barachb97641c2019-09-09 16:38:17 -04002226 vnet_pcap_dispatch_trace_args_t _a, *a = &_a;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002227 vnet_main_t *vnm = vnet_get_main ();
Dave Barachb97641c2019-09-09 16:38:17 -04002228 u8 *filename = 0;
2229 u32 max = 1000;
Dave Barach33909772019-09-23 10:27:27 -04002230 u32 max_bytes_per_pkt = 512;
Dave Barachb97641c2019-09-09 16:38:17 -04002231 int rv;
Dave Barach33909772019-09-23 10:27:27 -04002232 int rx_enable = 0;
2233 int tx_enable = 0;
Dave Barach586462f2020-08-05 16:12:35 -04002234 int preallocate_data = 0;
Dave Barach33909772019-09-23 10:27:27 -04002235 int drop_enable = 0;
Dave Barachb97641c2019-09-09 16:38:17 -04002236 int status = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002237 int filter = 0;
Dave Barach586462f2020-08-05 16:12:35 -04002238 int free_data = 0;
Dave Barach4330c462020-06-10 17:07:32 -04002239 u32 sw_if_index = 0; /* default: any interface */
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002240 vlib_error_t drop_err = ~0; /* default: any error */
Dave Barach5ecd5a52019-02-25 15:27:28 -05002241
2242 /* Get a line of input. */
2243 if (!unformat_user (input, unformat_line_input, line_input))
2244 return 0;
2245
2246 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2247 {
Dave Barach33909772019-09-23 10:27:27 -04002248 if (unformat (line_input, "rx"))
2249 rx_enable = 1;
2250 else if (unformat (line_input, "tx"))
2251 tx_enable = 1;
2252 else if (unformat (line_input, "drop"))
2253 drop_enable = 1;
2254 else if (unformat (line_input, "off"))
2255 rx_enable = tx_enable = drop_enable = 0;
2256 else if (unformat (line_input, "max-bytes-per-pkt %u",
2257 &max_bytes_per_pkt))
Dave Barachb97641c2019-09-09 16:38:17 -04002258 ;
2259 else if (unformat (line_input, "max %d", &max))
2260 ;
2261 else if (unformat (line_input, "packets-to-capture %d", &max))
2262 ;
2263 else if (unformat (line_input, "file %U", unformat_vlib_tmpfile,
2264 &filename))
2265 ;
2266 else if (unformat (line_input, "status %=", &status, 1))
2267 ;
2268 else if (unformat (line_input, "intfc %U",
2269 unformat_vnet_sw_interface, vnm, &sw_if_index))
2270 ;
Dave Barach586462f2020-08-05 16:12:35 -04002271 else if (unformat (line_input, "interface %U",
2272 unformat_vnet_sw_interface, vnm, &sw_if_index))
2273 ;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002274 else if (unformat (line_input, "error %U", unformat_vlib_error, vm,
2275 &drop_err))
2276 ;
Dave Barach586462f2020-08-05 16:12:35 -04002277 else if (unformat (line_input, "preallocate-data %=",
2278 &preallocate_data, 1))
2279 ;
2280 else if (unformat (line_input, "free-data %=", &free_data, 1))
2281 ;
2282 else if (unformat (line_input, "intfc any")
2283 || unformat (line_input, "interface any"))
Dave Barachb97641c2019-09-09 16:38:17 -04002284 sw_if_index = 0;
Dave Barach9137e542019-09-13 17:47:50 -04002285 else if (unformat (line_input, "filter"))
2286 filter = 1;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002287 else
2288 {
Dave Barachb97641c2019-09-09 16:38:17 -04002289 return clib_error_return (0, "unknown input `%U'",
2290 format_unformat_error, line_input);
Dave Barach5ecd5a52019-02-25 15:27:28 -05002291 }
2292 }
Dave Barachb97641c2019-09-09 16:38:17 -04002293
Dave Barach5ecd5a52019-02-25 15:27:28 -05002294 unformat_free (line_input);
2295
Dave Barachb97641c2019-09-09 16:38:17 -04002296 /* no need for memset (a, 0, sizeof (*a)), set all fields here. */
2297 a->filename = filename;
Dave Barach33909772019-09-23 10:27:27 -04002298 a->rx_enable = rx_enable;
2299 a->tx_enable = tx_enable;
Dave Barach586462f2020-08-05 16:12:35 -04002300 a->preallocate_data = preallocate_data;
2301 a->free_data = free_data;
Dave Barach33909772019-09-23 10:27:27 -04002302 a->drop_enable = drop_enable;
Dave Barachb97641c2019-09-09 16:38:17 -04002303 a->status = status;
2304 a->packets_to_capture = max;
Dave Barachb97641c2019-09-09 16:38:17 -04002305 a->sw_if_index = sw_if_index;
Dave Barach9137e542019-09-13 17:47:50 -04002306 a->filter = filter;
Dave Barach33909772019-09-23 10:27:27 -04002307 a->max_bytes_per_pkt = max_bytes_per_pkt;
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002308 a->drop_err = drop_err;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002309
Dave Barachb97641c2019-09-09 16:38:17 -04002310 rv = vnet_pcap_dispatch_trace_configure (a);
2311
2312 switch (rv)
Dave Barach5ecd5a52019-02-25 15:27:28 -05002313 {
Dave Barachb97641c2019-09-09 16:38:17 -04002314 case 0:
2315 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002316
Dave Barachb97641c2019-09-09 16:38:17 -04002317 case VNET_API_ERROR_INVALID_VALUE:
2318 return clib_error_return (0, "dispatch trace already enabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002319
Dave Barachb97641c2019-09-09 16:38:17 -04002320 case VNET_API_ERROR_VALUE_EXIST:
2321 return clib_error_return (0, "dispatch trace already disabled...");
Dave Barach5ecd5a52019-02-25 15:27:28 -05002322
Dave Barachb97641c2019-09-09 16:38:17 -04002323 case VNET_API_ERROR_INVALID_VALUE_2:
2324 return clib_error_return
2325 (0, "can't change number of records to capture while tracing...");
2326
2327 case VNET_API_ERROR_SYSCALL_ERROR_1:
2328 return clib_error_return (0, "I/O writing trace capture...");
2329
2330 case VNET_API_ERROR_NO_SUCH_ENTRY:
2331 return clib_error_return (0, "No packets captured...");
2332
Dave Barach33909772019-09-23 10:27:27 -04002333 case VNET_API_ERROR_INVALID_MEMORY_SIZE:
2334 return clib_error_return (0,
2335 "Max bytes per pkt must be > 32, < 9000...");
2336
Dave Barach9137e542019-09-13 17:47:50 -04002337 case VNET_API_ERROR_NO_SUCH_LABEL:
2338 return clib_error_return
2339 (0, "No classify filter configured, see 'classify filter...'");
2340
Dave Barachb97641c2019-09-09 16:38:17 -04002341 default:
2342 vlib_cli_output (vm, "WARNING: trace configure returned %d", rv);
2343 break;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002344 }
Dave Barachb97641c2019-09-09 16:38:17 -04002345 return 0;
Dave Barach5ecd5a52019-02-25 15:27:28 -05002346}
2347
Dave Barach5ecd5a52019-02-25 15:27:28 -05002348/*?
2349 * This command is used to start or stop a packet capture, or show
Dave Barach33909772019-09-23 10:27:27 -04002350 * the status of packet capture.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002351 *
2352 * This command has the following optional parameters:
2353 *
Dave Barach33909772019-09-23 10:27:27 -04002354 *
2355 * - <b>rx</b> - Capture received packets
2356 *
2357 * - <b>tx</b> - Capture transmitted packets
2358 *
2359 * - <b>drop</b> - Capture dropped packets
2360 *
2361 * - <b>off</b> - Stop capturing packets, write results to the specified file
Dave Barach5ecd5a52019-02-25 15:27:28 -05002362 *
2363 * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number
2364 * of packets have been received, buffer is flushed to file. Once another
2365 * '<em>nn</em>' number of packets have been received, buffer is flushed
2366 * to file, overwriting previous write. If not entered, value defaults
2367 * to 100. Can only be updated if packet capture is off.
2368 *
Dave Barach33909772019-09-23 10:27:27 -04002369 * - <b>max-bytes-per-pkt <nnnn></b> - Maximum number of bytes to capture
2370 * for each packet. Must be >= 32, <= 9000.
2371 *
Dave Barach586462f2020-08-05 16:12:35 -04002372 * - <b>preallocate-data</b> - Preallocate the data buffer, to avoid
2373 * vector expansion delays during pcap capture
2374 *
2375 * - <b>free-data</b> - Free the data buffer. Ordinarily it's a feature
2376 * to retain the data buffer so this option is seldom used.
2377 *
Dave Barach33909772019-09-23 10:27:27 -04002378 * - <b>intfc <interface-name>|any</b> - Used to specify a given interface,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002379 * or use '<em>any</em>' to run packet capture on all interfaces.
2380 * '<em>any</em>' is the default if not provided. Settings from a previous
2381 * packet capture are preserved, so '<em>any</em>' can be used to reset
2382 * the interface setting.
2383 *
Dave Barachf5667c32019-09-25 11:27:46 -04002384 * - <b>filter</b> - Use the pcap rx / tx / drop trace filter, which
2385 * must be configured. Use <b>classify filter pcap...</b> to configure the
2386 * filter. The filter will only be executed if the per-interface or
2387 * any-interface tests fail.
2388 *
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002389 * - <b>error <node>.<error></b> - filter packets based on a specific error.
2390 * For example: error {ip4-udp-lookup}.{No listener for dst port}
2391 *
Dave Barach5ecd5a52019-02-25 15:27:28 -05002392 * - <b>file <name></b> - Used to specify the output filename. The file will
2393 * be placed in the '<em>/tmp</em>' directory, so only the filename is
2394 * supported. Directory should not be entered. If file already exists, file
Dave Barach33909772019-09-23 10:27:27 -04002395 * will be overwritten. If no filename is provided, the file will be
2396 * named "/tmp/rx.pcap", "/tmp/tx.pcap", "/tmp/rxandtx.pcap", etc.
2397 * Can only be updated if packet capture is off.
Dave Barach5ecd5a52019-02-25 15:27:28 -05002398 *
2399 * - <b>status</b> - Displays the current status and configured attributes
2400 * associated with a packet capture. If packet capture is in progress,
2401 * '<em>status</em>' also will return the number of packets currently in
2402 * the local buffer. All additional attributes entered on command line
2403 * with '<em>status</em>' will be ignored and not applied.
2404 *
2405 * @cliexpar
2406 * Example of how to display the status of a tx packet capture when off:
Dave Barach33909772019-09-23 10:27:27 -04002407 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002408 * max is 100, for any interface to file /tmp/vpe.pcap
2409 * pcap tx capture is off...
2410 * @cliexend
2411 * Example of how to start a tx packet capture:
Benoît Ganne5cfe4522021-03-03 17:37:25 +01002412 * @cliexstart{pcap trace tx max 35 intfc GigabitEthernet0/8/0 file
Nathan Skrzypczak2c77ae42021-09-29 15:36:51 +02002413 * vppTest.pcap}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002414 * @cliexend
2415 * Example of how to display the status of a tx packet capture in progress:
Dave Barach33909772019-09-23 10:27:27 -04002416 * @cliexstart{pcap trace status}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002417 * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap
2418 * pcap tx capture is on: 20 of 35 pkts...
2419 * @cliexend
2420 * Example of how to stop a tx packet capture:
Dave Barach33909772019-09-23 10:27:27 -04002421 * @cliexstart{pcap trace off}
Dave Barach5ecd5a52019-02-25 15:27:28 -05002422 * captured 21 pkts...
2423 * saved to /tmp/vppTest.pcap...
2424 * @cliexend
2425?*/
2426/* *INDENT-OFF* */
2427
2428VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = {
Dave Barach33909772019-09-23 10:27:27 -04002429 .path = "pcap trace",
Dave Barach5ecd5a52019-02-25 15:27:28 -05002430 .short_help =
Dave Barach586462f2020-08-05 16:12:35 -04002431 "pcap trace [rx] [tx] [drop] [off] [max <nn>] [intfc <interface>|any]\n"
2432 " [file <name>] [status] [max-bytes-per-pkt <nnnn>][filter]\n"
2433 " [preallocate-data][free-data]",
Dave Barach33909772019-09-23 10:27:27 -04002434 .function = pcap_trace_command_fn,
Dave Barach5ecd5a52019-02-25 15:27:28 -05002435};
2436/* *INDENT-ON* */
2437
Steven Luongf49734d2021-07-26 13:38:05 -07002438static clib_error_t *
2439set_interface_name (vlib_main_t *vm, unformat_input_t *input,
2440 vlib_cli_command_t *cmd)
2441{
2442 clib_error_t *error = 0;
2443 unformat_input_t _line_input, *line_input = &_line_input;
2444 vnet_main_t *vnm = vnet_get_main ();
2445 u32 hw_if_index = ~0;
2446 char *name = 0;
2447
2448 if (!unformat_user (input, unformat_line_input, line_input))
2449 return 0;
2450
2451 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2452 {
2453 if (unformat (line_input, "%U %s", unformat_vnet_hw_interface, vnm,
2454 &hw_if_index, &name))
2455 ;
2456 else
2457 {
2458 error = clib_error_return (0, "parse error: '%U'",
2459 format_unformat_error, line_input);
2460 unformat_free (line_input);
2461 vec_free (name);
2462 return error;
2463 }
2464 }
2465
2466 unformat_free (line_input);
2467
2468 if (hw_if_index == (u32) ~0 || name == 0)
2469 {
2470 vec_free (name);
2471 error = clib_error_return (0, "please specify valid interface name");
2472 return error;
2473 }
2474
2475 error = vnet_rename_interface (vnm, hw_if_index, name);
2476 vec_free (name);
2477
2478 return (error);
2479}
2480
2481VLIB_CLI_COMMAND (cmd_set_if_name, static) = {
2482 .path = "set interface name",
2483 .short_help = "set interface name <interface-name> <new-interface-name>",
2484 .function = set_interface_name,
2485 .is_mp_safe = 1,
2486};
Mohsin Kazmi0d05c0d2021-11-09 17:44:10 +00002487
2488static clib_error_t *
2489set_interface_tx_hash_cmd (vlib_main_t *vm, unformat_input_t *input,
2490 vlib_cli_command_t *cmd)
2491{
2492 clib_error_t *error = 0;
2493 unformat_input_t _line_input, *line_input = &_line_input;
2494 vnet_main_t *vnm = vnet_get_main ();
2495 vnet_hw_interface_t *hi;
2496 u8 *hash_name = 0;
2497 u32 hw_if_index = (u32) ~0;
2498 vnet_hash_fn_t hf;
2499 vnet_hash_fn_type_t ftype;
2500
2501 if (!unformat_user (input, unformat_line_input, line_input))
2502 return 0;
2503
2504 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2505 {
2506 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2507 &hw_if_index))
2508 ;
2509 else if (unformat (line_input, "hash-name %s", &hash_name))
2510 ;
2511 else
2512 {
2513 error = clib_error_return (0, "parse error: '%U'",
2514 format_unformat_error, line_input);
2515 unformat_free (line_input);
2516 return error;
2517 }
2518 }
2519
2520 unformat_free (line_input);
2521
2522 if (hw_if_index == (u32) ~0)
2523 {
2524 error = clib_error_return (0, "please specify valid interface name");
2525 goto error;
2526 }
2527
2528 hi = vnet_get_hw_interface (vnm, hw_if_index);
2529 ftype =
2530 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2531 hf = vnet_hash_function_from_name ((const char *) hash_name, ftype);
2532
2533 if (!hf)
2534 {
2535 error = clib_error_return (0, "please specify valid hash name");
2536 goto error;
2537 }
2538
2539 hi->hf = hf;
2540error:
2541 vec_free (hash_name);
2542 return (error);
2543}
2544
2545VLIB_CLI_COMMAND (cmd_set_if_tx_hash, static) = {
2546 .path = "set interface tx-hash",
2547 .short_help = "set interface tx-hash <interface> hash-name <hash-name>",
2548 .function = set_interface_tx_hash_cmd,
2549};
2550
2551static clib_error_t *
2552show_tx_hash (vlib_main_t *vm, unformat_input_t *input,
2553 vlib_cli_command_t *cmd)
2554{
2555 clib_error_t *error = 0;
2556 unformat_input_t _line_input, *line_input = &_line_input;
2557 vnet_main_t *vnm = vnet_get_main ();
2558 vnet_hw_interface_t *hi;
2559 vnet_hash_function_registration_t *hash;
2560 u32 hw_if_index = (u32) ~0;
2561 vnet_hash_fn_type_t ftype;
2562
2563 if (!unformat_user (input, unformat_line_input, line_input))
2564 return 0;
2565
2566 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
2567 {
2568 if (unformat (line_input, "%U", unformat_vnet_hw_interface, vnm,
2569 &hw_if_index))
2570 ;
2571 else
2572 {
2573 error = clib_error_return (0, "parse error: '%U'",
2574 format_unformat_error, line_input);
2575 unformat_free (line_input);
2576 goto error;
2577 }
2578 }
2579
2580 unformat_free (line_input);
2581
2582 if (hw_if_index == (u32) ~0)
2583 {
2584 error = clib_error_return (0, "please specify valid interface name");
2585 goto error;
2586 }
2587
2588 hi = vnet_get_hw_interface (vnm, hw_if_index);
2589 ftype =
2590 vnet_get_hw_interface_class (vnm, hi->hw_class_index)->tx_hash_fn_type;
2591
2592 if (hi->hf)
2593 {
2594 hash = vnet_hash_function_from_func (hi->hf, ftype);
2595 if (hash)
2596 vlib_cli_output (vm, "%U", format_vnet_hash, hash);
2597 else
2598 vlib_cli_output (vm, "no matching hash function found");
2599 }
2600 else
2601 vlib_cli_output (vm, "no hashing function set");
2602
2603error:
2604 return (error);
2605}
2606
2607VLIB_CLI_COMMAND (cmd_show_tx_hash, static) = {
2608 .path = "show interface tx-hash",
2609 .short_help = "show interface tx-hash [interface]",
2610 .function = show_tx_hash,
2611};
2612
Dave Barachba868bb2016-08-08 09:51:21 -04002613/*
2614 * fd.io coding-style-patch-verification: ON
2615 *
2616 * Local Variables:
2617 * eval: (c-set-style "gnu")
2618 * End:
2619 */