blob: a8aa3056572ab0da24d7668be4c7f70509f17940 [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
2 * Copyright (c) 2015 Cisco and/or its affiliates.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at:
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15/*
16 * interface_cli.c: interface CLI
17 *
18 * Copyright (c) 2008 Eliot Dresselhaus
19 *
20 * Permission is hereby granted, free of charge, to any person obtaining
21 * a copy of this software and associated documentation files (the
22 * "Software"), to deal in the Software without restriction, including
23 * without limitation the rights to use, copy, modify, merge, publish,
24 * distribute, sublicense, and/or sell copies of the Software, and to
25 * permit persons to whom the Software is furnished to do so, subject to
26 * the following conditions:
27 *
28 * The above copyright notice and this permission notice shall be
29 * included in all copies or substantial portions of the Software.
30 *
31 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
32 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
33 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
34 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
35 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
36 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
37 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 */
39
Chris Luke16bcf7d2016-09-01 14:31:46 -040040/**
41 * @file
42 * Interface CLI.
43 */
44
Ed Warnickecb9cada2015-12-08 15:45:58 -070045#include <vnet/vnet.h>
46#include <vnet/ip/ip.h>
John Lobcebbb92016-04-05 15:47:43 -040047#include <vppinfra/bitmap.h>
Neale Ranns0bfe5d82016-08-25 15:29:12 +010048#include <vnet/fib/ip4_fib.h>
49#include <vnet/fib/ip6_fib.h>
Eyal Bari942402b2017-07-26 11:57:04 +030050#include <vnet/l2/l2_output.h>
51#include <vnet/l2/l2_input.h>
Ed Warnickecb9cada2015-12-08 15:45:58 -070052
Dave Barachba868bb2016-08-08 09:51:21 -040053static int
54compare_interface_names (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -070055{
Dave Barachba868bb2016-08-08 09:51:21 -040056 u32 *hi1 = a1;
57 u32 *hi2 = a2;
Ed Warnickecb9cada2015-12-08 15:45:58 -070058
Dave Barachba868bb2016-08-08 09:51:21 -040059 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070060}
61
62static clib_error_t *
63show_or_clear_hw_interfaces (vlib_main_t * vm,
64 unformat_input_t * input,
65 vlib_cli_command_t * cmd)
66{
Dave Barachba868bb2016-08-08 09:51:21 -040067 clib_error_t *error = 0;
68 vnet_main_t *vnm = vnet_get_main ();
69 vnet_interface_main_t *im = &vnm->interface_main;
70 vnet_hw_interface_t *hi;
71 u32 hw_if_index, *hw_if_indices = 0;
John Lobcebbb92016-04-05 15:47:43 -040072 int i, verbose = -1, is_show, show_bond = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070073
74 is_show = strstr (cmd->path, "show") != 0;
75 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
76 {
77 /* See if user wants to show a specific interface. */
Dave Barachba868bb2016-08-08 09:51:21 -040078 if (unformat
79 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
80 vec_add1 (hw_if_indices, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -040081
Sean Hope679ea792016-02-22 15:12:01 -050082 /* See if user wants to show an interface with a specific hw_if_index. */
83 else if (unformat (input, "%u", &hw_if_index))
Dave Barachba868bb2016-08-08 09:51:21 -040084 vec_add1 (hw_if_indices, hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070085
86 else if (unformat (input, "verbose"))
Dave Barachba868bb2016-08-08 09:51:21 -040087 verbose = 1; /* this is also the default */
Ed Warnickecb9cada2015-12-08 15:45:58 -070088
89 else if (unformat (input, "detail"))
90 verbose = 2;
91
92 else if (unformat (input, "brief"))
93 verbose = 0;
94
John Lobcebbb92016-04-05 15:47:43 -040095 else if (unformat (input, "bond"))
Dave Barachba868bb2016-08-08 09:51:21 -040096 {
97 show_bond = 1;
98 if (verbose < 0)
99 verbose = 0; /* default to brief for link bonding */
100 }
John Lobcebbb92016-04-05 15:47:43 -0400101
Ed Warnickecb9cada2015-12-08 15:45:58 -0700102 else
103 {
104 error = clib_error_return (0, "unknown input `%U'",
105 format_unformat_error, input);
106 goto done;
107 }
108 }
Dave Barachba868bb2016-08-08 09:51:21 -0400109
Ed Warnickecb9cada2015-12-08 15:45:58 -0700110 /* Gather interfaces. */
111 if (vec_len (hw_if_indices) == 0)
112 pool_foreach (hi, im->hw_interfaces,
113 vec_add1 (hw_if_indices, hi - im->hw_interfaces));
114
Dave Barachba868bb2016-08-08 09:51:21 -0400115 if (verbose < 0)
116 verbose = 1; /* default to verbose (except bond) */
John Lobcebbb92016-04-05 15:47:43 -0400117
Ed Warnickecb9cada2015-12-08 15:45:58 -0700118 if (is_show)
119 {
120 /* Sort by name. */
121 vec_sort_with_function (hw_if_indices, compare_interface_names);
122
123 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
124 for (i = 0; i < vec_len (hw_if_indices); i++)
125 {
126 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
Dave Barachba868bb2016-08-08 09:51:21 -0400127 if (show_bond == 0) /* show all interfaces */
128 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
129 hi, verbose);
130 else if ((hi->bond_info) &&
John Lobcebbb92016-04-05 15:47:43 -0400131 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
Dave Barachba868bb2016-08-08 09:51:21 -0400132 { /* show only bonded interface and all its slave interfaces */
John Lobcebbb92016-04-05 15:47:43 -0400133 int hw_idx;
Dave Barachba868bb2016-08-08 09:51:21 -0400134 vnet_hw_interface_t *shi;
135 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
John Lobcebbb92016-04-05 15:47:43 -0400136 hi, verbose);
Dave Barachba868bb2016-08-08 09:51:21 -0400137
138 /* *INDENT-OFF* */
John Lobcebbb92016-04-05 15:47:43 -0400139 clib_bitmap_foreach (hw_idx, hi->bond_info,
Dave Barachba868bb2016-08-08 09:51:21 -0400140 ({
141 shi = vnet_get_hw_interface(vnm, hw_idx);
142 vlib_cli_output (vm, "%U\n",
143 format_vnet_hw_interface, vnm, shi, verbose);
144 }));
145 /* *INDENT-ON* */
John Lobcebbb92016-04-05 15:47:43 -0400146 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700147 }
148 }
149 else
150 {
151 for (i = 0; i < vec_len (hw_if_indices); i++)
152 {
Dave Barachba868bb2016-08-08 09:51:21 -0400153 vnet_device_class_t *dc;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700154
155 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
156 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400157
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158 if (dc->clear_counters)
159 dc->clear_counters (hi->dev_instance);
160 }
161 }
162
Dave Barachba868bb2016-08-08 09:51:21 -0400163done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700164 vec_free (hw_if_indices);
165 return error;
166}
167
Dave Barachba868bb2016-08-08 09:51:21 -0400168/* *INDENT-OFF* */
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700169/*?
170 * Displays various information about the state of the current terminal
171 * session.
172 *
173 * @cliexpar
174 * @cliexstart{show hardware}
175 * Name Link Hardware
176 * GigabitEthernet2/0/0 up GigabitEthernet2/0/0
177 * Ethernet address 00:50:56:b7:7c:83
178 * Intel 82545em_copper
179 * link up, media 1000T full-duplex, master,
180 * 0 unprocessed, 384 total buffers on rx queue 0 ring
181 * 237 buffers in driver rx cache
182 * rx total packets 1816
183 * rx total bytes 181084
184 * rx good packets 1816
185 * rx good bytes 181084
186 * rx 65 127 byte packets 1586
187 * rx 256 511 byte packets 230
188 * tx total packets 346
189 * tx total bytes 90224
190 * tx good packets 346
191 * tx good bytes 88840
192 * tx 64 byte packets 1
193 * tx 65 127 byte packets 115
194 * tx 256 511 byte packets 230
195 * @cliexend
196 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700197VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
198 .path = "show hardware-interfaces",
John Lobcebbb92016-04-05 15:47:43 -0400199 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] [<if-name1> <if-name2> ...]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700200 .function = show_or_clear_hw_interfaces,
201};
Dave Barachba868bb2016-08-08 09:51:21 -0400202/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700203
Dave Barachba868bb2016-08-08 09:51:21 -0400204/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700205VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
206 .path = "clear hardware-interfaces",
207 .short_help = "Clear hardware interfaces statistics",
208 .function = show_or_clear_hw_interfaces,
209};
Dave Barachba868bb2016-08-08 09:51:21 -0400210/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700211
Dave Barachba868bb2016-08-08 09:51:21 -0400212static int
213sw_interface_name_compare (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700214{
215 vnet_sw_interface_t *si1 = a1;
216 vnet_sw_interface_t *si2 = a2;
217
Dave Barachba868bb2016-08-08 09:51:21 -0400218 return vnet_sw_interface_compare (vnet_get_main (),
219 si1->sw_if_index, si2->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700220}
221
222static clib_error_t *
223show_sw_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400224 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700225{
Dave Barachba868bb2016-08-08 09:51:21 -0400226 clib_error_t *error = 0;
227 vnet_main_t *vnm = vnet_get_main ();
228 vnet_interface_main_t *im = &vnm->interface_main;
229 vnet_sw_interface_t *si, *sorted_sis = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200230 u32 sw_if_index = ~(u32) 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700231 u8 show_addresses = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200232 u8 show_features = 0;
Dave Barach7be864a2016-11-28 11:41:35 -0500233 u8 show_tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700234
235 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
236 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700237 /* See if user wants to show specific interface */
Dave Barachba868bb2016-08-08 09:51:21 -0400238 if (unformat
239 (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700240 {
Dave Barachba868bb2016-08-08 09:51:21 -0400241 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700242 vec_add1 (sorted_sis, si[0]);
243 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700244 else if (unformat (input, "address") || unformat (input, "addr"))
Dave Barachba868bb2016-08-08 09:51:21 -0400245 show_addresses = 1;
Damjan Marion22311502016-10-28 20:30:15 +0200246 else if (unformat (input, "features") || unformat (input, "feat"))
247 show_features = 1;
Dave Barach7be864a2016-11-28 11:41:35 -0500248 else if (unformat (input, "tag"))
249 show_tag = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250 else
Dave Barachba868bb2016-08-08 09:51:21 -0400251 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700252 error = clib_error_return (0, "unknown input `%U'",
253 format_unformat_error, input);
254 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400255 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700256 }
257
Dave Barach7be864a2016-11-28 11:41:35 -0500258 if (show_features || show_tag)
Damjan Marion22311502016-10-28 20:30:15 +0200259 {
260 if (sw_if_index == ~(u32) 0)
261 return clib_error_return (0, "Interface not specified...");
Dave Barach7be864a2016-11-28 11:41:35 -0500262 }
Damjan Marion22311502016-10-28 20:30:15 +0200263
Dave Barach7be864a2016-11-28 11:41:35 -0500264 if (show_features)
265 {
Damjan Marion22311502016-10-28 20:30:15 +0200266 vnet_interface_features_show (vm, sw_if_index);
Eyal Bari942402b2017-07-26 11:57:04 +0300267
268 l2_input_config_t *l2_input = l2input_intf_config (sw_if_index);
269 u32 fb = l2_input->feature_bitmap;
270 /* intf input features are masked by bridge domain */
271 if (l2_input->bridge)
272 fb &= l2input_bd_config (l2_input->bd_index)->feature_bitmap;
273 vlib_cli_output (vm, "\nl2-input:\n%U", format_l2_input_features, fb);
274
275 l2_output_config_t *l2_output = l2output_intf_config (sw_if_index);
276 vlib_cli_output (vm, "\nl2-output:");
277 if (l2_output->out_vtr_flag)
278 vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--");
279 vlib_cli_output (vm, "%U", format_l2_output_features,
280 l2_output->feature_bitmap);
Damjan Marion22311502016-10-28 20:30:15 +0200281 return 0;
282 }
Dave Barach7be864a2016-11-28 11:41:35 -0500283 if (show_tag)
284 {
285 u8 *tag;
286 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
287 vlib_cli_output (vm, "%U: %s",
288 format_vnet_sw_if_index_name, vnm, sw_if_index,
289 tag ? (char *) tag : "(none)");
290 return 0;
291 }
Damjan Marion22311502016-10-28 20:30:15 +0200292
Ed Warnickecb9cada2015-12-08 15:45:58 -0700293 if (!show_addresses)
Dave Barachba868bb2016-08-08 09:51:21 -0400294 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700295
Dave Barachba868bb2016-08-08 09:51:21 -0400296 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700297 {
298 /* Gather interfaces. */
Dave Barachba868bb2016-08-08 09:51:21 -0400299 sorted_sis =
300 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700301 _vec_len (sorted_sis) = 0;
Dave Barachba868bb2016-08-08 09:51:21 -0400302 pool_foreach (si, im->sw_interfaces, (
303 {
Eyal Bari942402b2017-07-26 11:57:04 +0300304 int visible =
305 vnet_swif_is_api_visible (si);
306 if (visible)
307 vec_add1 (sorted_sis, si[0]);}
Dave Barachba868bb2016-08-08 09:51:21 -0400308 ));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700309
310 /* Sort by name. */
311 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
312 }
313
314 if (show_addresses)
315 {
316 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400317 {
Dave Barachba868bb2016-08-08 09:51:21 -0400318 ip4_main_t *im4 = &ip4_main;
319 ip6_main_t *im6 = &ip6_main;
320 ip_lookup_main_t *lm4 = &im4->lookup_main;
321 ip_lookup_main_t *lm6 = &im6->lookup_main;
322 ip_interface_address_t *ia = 0;
323 ip4_address_t *r4;
324 ip6_address_t *r6;
325 u32 fib_index4 = 0, fib_index6 = 0;
326 ip4_fib_t *fib4;
327 ip6_fib_t *fib6;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700328
Dave Barachba868bb2016-08-08 09:51:21 -0400329 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
330 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
331 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700332
Dave Barachba868bb2016-08-08 09:51:21 -0400333 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
334 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
335 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700336
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100337 fib4 = ip4_fib_get (fib_index4);
338 fib6 = ip6_fib_get (fib_index6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700339
Dave Barachba868bb2016-08-08 09:51:21 -0400340 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
341 vlib_cli_output
342 (vm, "%U (%s): \n unnumbered, use %U",
343 format_vnet_sw_if_index_name,
344 vnm, si->sw_if_index,
345 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
346 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700347
Dave Barachba868bb2016-08-08 09:51:21 -0400348 else
349 {
350 vlib_cli_output (vm, "%U (%s):",
351 format_vnet_sw_if_index_name,
352 vnm, si->sw_if_index,
353 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
354 ? "up" : "dn");
355 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700356
Eyal Bari942402b2017-07-26 11:57:04 +0300357 /* Display any L2 info */
358 l2_input_config_t *l2_input = l2input_intf_config (si->sw_if_index);
359 if (l2_input->bridge)
Dave Barachba868bb2016-08-08 09:51:21 -0400360 {
Eyal Bari942402b2017-07-26 11:57:04 +0300361 u32 bd_id = l2input_main.bd_configs[l2_input->bd_index].bd_id;
Dave Barachba868bb2016-08-08 09:51:21 -0400362 vlib_cli_output (vm, " l2 bridge bd_id %d%s%d", bd_id,
Eyal Bari942402b2017-07-26 11:57:04 +0300363 l2_input->bvi ? " bvi shg " : " shg ",
364 l2_input->shg);
Dave Barachba868bb2016-08-08 09:51:21 -0400365 }
Eyal Bari942402b2017-07-26 11:57:04 +0300366 else if (l2_input->xconnect)
Dave Barachba868bb2016-08-08 09:51:21 -0400367 {
368 vlib_cli_output (vm, " l2 xconnect %U",
369 format_vnet_sw_if_index_name,
Eyal Bari942402b2017-07-26 11:57:04 +0300370 vnm, l2_input->output_sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400371 }
372
373 /* Display any IP4 addressing info */
374 /* *INDENT-OFF* */
375 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700376 1 /* honor unnumbered */,
377 ({
378 r4 = ip_interface_address_get_address (lm4, ia);
379 if (fib4->table_id)
380 {
Dave Barachba868bb2016-08-08 09:51:21 -0400381 vlib_cli_output (vm, " %U/%d table %d",
382 format_ip4_address, r4,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700383 ia->address_length,
384 fib4->table_id);
385 }
386 else
387 {
Dave Barachba868bb2016-08-08 09:51:21 -0400388 vlib_cli_output (vm, " %U/%d",
389 format_ip4_address, r4,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700390 ia->address_length);
391 }
392 }));
Dave Barachba868bb2016-08-08 09:51:21 -0400393 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700394
Dave Barachba868bb2016-08-08 09:51:21 -0400395 /* Display any IP6 addressing info */
396 /* *INDENT-OFF* */
397 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700398 1 /* honor unnumbered */,
399 ({
400 r6 = ip_interface_address_get_address (lm6, ia);
401 if (fib6->table_id)
402 {
Dave Barachba868bb2016-08-08 09:51:21 -0400403 vlib_cli_output (vm, " %U/%d table %d",
404 format_ip6_address, r6,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700405 ia->address_length,
406 fib6->table_id);
407 }
408 else
409 {
Dave Barachba868bb2016-08-08 09:51:21 -0400410 vlib_cli_output (vm, " %U/%d",
411 format_ip6_address, r6,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700412 ia->address_length);
413 }
414 }));
Dave Barachba868bb2016-08-08 09:51:21 -0400415 /* *INDENT-ON* */
416 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700417 }
418 else
419 {
420 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400421 {
422 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
423 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700424 }
425
Dave Barachba868bb2016-08-08 09:51:21 -0400426done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700427 vec_free (sorted_sis);
428 return error;
429}
430
Dave Barachba868bb2016-08-08 09:51:21 -0400431/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700432VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
Dave Barach13ad1f02017-03-26 19:36:18 -0400433 .path = "show interface",
434 .short_help = "show interface [address|addr|features|feat] [<if-name1> <if-name2> ...]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700435 .function = show_sw_interfaces,
436};
Dave Barachba868bb2016-08-08 09:51:21 -0400437/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700438
439/* Root of all interface commands. */
Dave Barachba868bb2016-08-08 09:51:21 -0400440/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700441VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
442 .path = "interface",
443 .short_help = "Interface commands",
444};
Dave Barachba868bb2016-08-08 09:51:21 -0400445/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700446
Dave Barachba868bb2016-08-08 09:51:21 -0400447/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700448VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
449 .path = "set interface",
450 .short_help = "Interface commands",
451};
Dave Barachba868bb2016-08-08 09:51:21 -0400452/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700453
454static clib_error_t *
455clear_interface_counters (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400456 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700457{
Dave Barachba868bb2016-08-08 09:51:21 -0400458 vnet_main_t *vnm = vnet_get_main ();
459 vnet_interface_main_t *im = &vnm->interface_main;
460 vlib_simple_counter_main_t *sm;
461 vlib_combined_counter_main_t *cm;
462 static vnet_main_t **my_vnet_mains;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700463 int i, j, n_counters;
464
465 vec_reset_length (my_vnet_mains);
Dave Barachba868bb2016-08-08 09:51:21 -0400466
Ed Warnickecb9cada2015-12-08 15:45:58 -0700467 for (i = 0; i < vec_len (vnet_mains); i++)
468 {
469 if (vnet_mains[i])
Dave Barachba868bb2016-08-08 09:51:21 -0400470 vec_add1 (my_vnet_mains, vnet_mains[i]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700471 }
472
473 if (vec_len (vnet_mains) == 0)
474 vec_add1 (my_vnet_mains, vnm);
475
476 n_counters = vec_len (im->combined_sw_if_counters);
477
478 for (j = 0; j < n_counters; j++)
479 {
Dave Barachba868bb2016-08-08 09:51:21 -0400480 for (i = 0; i < vec_len (my_vnet_mains); i++)
481 {
482 im = &my_vnet_mains[i]->interface_main;
483 cm = im->combined_sw_if_counters + j;
484 vlib_clear_combined_counters (cm);
485 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700486 }
487
488 n_counters = vec_len (im->sw_if_counters);
489
490 for (j = 0; j < n_counters; j++)
491 {
Dave Barachba868bb2016-08-08 09:51:21 -0400492 for (i = 0; i < vec_len (my_vnet_mains); i++)
493 {
494 im = &my_vnet_mains[i]->interface_main;
495 sm = im->sw_if_counters + j;
496 vlib_clear_simple_counters (sm);
497 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700498 }
499
500 return 0;
501}
502
Dave Barachba868bb2016-08-08 09:51:21 -0400503/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700504VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
505 .path = "clear interfaces",
506 .short_help = "Clear interfaces statistics",
507 .function = clear_interface_counters,
508};
Dave Barachba868bb2016-08-08 09:51:21 -0400509/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700510
Chris Luke16bcf7d2016-09-01 14:31:46 -0400511/**
512 * Parse subinterface names.
513 *
Dave Barachba868bb2016-08-08 09:51:21 -0400514 * The following subinterface syntax is supported. The first two are for
515 * backwards compatability:
516 *
517 * <intf-name> <id>
518 * - a subinterface with the name <intf-name>.<id>. The subinterface
519 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
520 *
521 * <intf-name> <min_id>-<max_id>
522 * - a set of the above subinterfaces, repeating for each id
523 * in the range <min_id> to <max_id>
524 *
525 * In the following, exact-match semantics (i.e. the number of vlan tags on the
526 * packet must match the number of tags in the configuration) are used only if
527 * the keyword exact-match is present. Non-exact match is the default.
528 *
529 * <intf-name> <id> dot1q <outer_id> [exact-match]
530 * - a subinterface with the name <intf-name>.<id>. The subinterface
531 * is a single dot1q vlan with vlan id <outer_id>.
532 *
533 * <intf-name> <id> dot1q any [exact-match]
534 * - a subinterface with the name <intf-name>.<id>. The subinterface
535 * is a single dot1q vlan with any vlan id.
536 *
537 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
538 * - a subinterface with the name <intf-name>.<id>. The subinterface
539 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
540 * <inner_id>.
541 *
542 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
543 * - a subinterface with the name <intf-name>.<id>. The subinterface
544 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
545 *
546 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
547 *
548 * - a subinterface with the name <intf-name>.<id>. The subinterface
549 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
550 *
551 * For each of the above CLI, there is a duplicate that uses the keyword
552 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
553 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
554 * tagged packets the inner ethertype is always 0x8100. Also note that
555 * the dot1q and dot1ad naming spaces are independent, so it is legal to
556 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
557 *
558 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
559 * - a subinterface with the name <intf-name>.<id>. The subinterface
560 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
561 * id <inner_id>.
562 *
563 * <intf-name> <id> untagged
564 * - a subinterface with the name <intf-name>.<id>. The subinterface
565 * has no vlan tags. Only one can be specified per interface.
566 *
567 * <intf-name> <id> default
568 * - a subinterface with the name <intf-name>.<id>. This is associated
569 * with a packet that did not match any other configured subinterface
570 * on this interface. Only one can be specified per interface.
571 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700572
573static clib_error_t *
Dave Barachba868bb2016-08-08 09:51:21 -0400574parse_vlan_sub_interfaces (unformat_input_t * input,
575 vnet_sw_interface_t * template)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700576{
Dave Barachba868bb2016-08-08 09:51:21 -0400577 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700578 u32 inner_vlan, outer_vlan;
579
Dave Barachba868bb2016-08-08 09:51:21 -0400580 if (unformat (input, "any inner-dot1q any"))
581 {
582 template->sub.eth.flags.two_tags = 1;
583 template->sub.eth.flags.outer_vlan_id_any = 1;
584 template->sub.eth.flags.inner_vlan_id_any = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700585 }
Dave Barachba868bb2016-08-08 09:51:21 -0400586 else if (unformat (input, "any"))
587 {
588 template->sub.eth.flags.one_tag = 1;
589 template->sub.eth.flags.outer_vlan_id_any = 1;
590 }
591 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
592 {
593 template->sub.eth.flags.two_tags = 1;
594 template->sub.eth.flags.inner_vlan_id_any = 1;
595 template->sub.eth.outer_vlan_id = outer_vlan;
596 }
597 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
598 {
599 template->sub.eth.flags.two_tags = 1;
600 template->sub.eth.outer_vlan_id = outer_vlan;
601 template->sub.eth.inner_vlan_id = inner_vlan;
602 }
603 else if (unformat (input, "%d", &outer_vlan))
604 {
605 template->sub.eth.flags.one_tag = 1;
606 template->sub.eth.outer_vlan_id = outer_vlan;
607 }
608 else
609 {
610 error = clib_error_return (0, "expected dot1q config, got `%U'",
611 format_unformat_error, input);
612 goto done;
613 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700614
Dave Barachba868bb2016-08-08 09:51:21 -0400615 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
616 {
617 if (unformat (input, "exact-match"))
618 {
619 template->sub.eth.flags.exact_match = 1;
620 }
621 }
622
623done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700624 return error;
625}
626
627static clib_error_t *
628create_sub_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400629 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700630{
Dave Barachba868bb2016-08-08 09:51:21 -0400631 vnet_main_t *vnm = vnet_get_main ();
632 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700633 u32 hw_if_index, sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400634 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700635 u32 id, id_min, id_max;
636 vnet_sw_interface_t template;
637
638 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400639 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700640 {
641 error = clib_error_return (0, "unknown interface `%U'",
642 format_unformat_error, input);
643 goto done;
644 }
645
646 memset (&template, 0, sizeof (template));
647 template.sub.eth.raw_flags = 0;
648
Dave Barachba868bb2016-08-08 09:51:21 -0400649 if (unformat (input, "%d default", &id_min))
650 {
651 id_max = id_min;
652 template.sub.eth.flags.default_sub = 1;
653 }
654 else if (unformat (input, "%d untagged", &id_min))
655 {
656 id_max = id_min;
657 template.sub.eth.flags.no_tags = 1;
658 template.sub.eth.flags.exact_match = 1;
659 }
660 else if (unformat (input, "%d dot1q", &id_min))
661 {
662 /* parse dot1q config */
663 id_max = id_min;
664 error = parse_vlan_sub_interfaces (input, &template);
665 if (error)
666 goto done;
667 }
668 else if (unformat (input, "%d dot1ad", &id_min))
669 {
670 /* parse dot1ad config */
671 id_max = id_min;
672 template.sub.eth.flags.dot1ad = 1;
673 error = parse_vlan_sub_interfaces (input, &template);
674 if (error)
675 goto done;
676 }
677 else if (unformat (input, "%d-%d", &id_min, &id_max))
678 {
679 template.sub.eth.flags.one_tag = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400680 template.sub.eth.flags.exact_match = 1;
681 if (id_min > id_max)
682 goto id_error;
683 }
684 else if (unformat (input, "%d", &id_min))
685 {
686 id_max = id_min;
687 template.sub.eth.flags.one_tag = 1;
688 template.sub.eth.outer_vlan_id = id_min;
689 template.sub.eth.flags.exact_match = 1;
690 }
691 else
692 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700693 id_error:
694 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
695 format_unformat_error, input);
696 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400697 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700698
699 hi = vnet_get_hw_interface (vnm, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -0400700
Dave Barachba868bb2016-08-08 09:51:21 -0400701 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
702 {
703 error =
704 clib_error_return (0,
705 "not allowed as %v belong to a BondEthernet interface",
706 hi->name);
707 goto done;
708 }
John Lobcebbb92016-04-05 15:47:43 -0400709
Ed Warnickecb9cada2015-12-08 15:45:58 -0700710 for (id = id_min; id <= id_max; id++)
711 {
Dave Barachba868bb2016-08-08 09:51:21 -0400712 uword *p;
713 vnet_interface_main_t *im = &vnm->interface_main;
714 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
715 u64 *kp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700716
717 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
718 if (p)
Dave Barachba868bb2016-08-08 09:51:21 -0400719 {
720 if (CLIB_DEBUG > 0)
721 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
722 hi->sw_if_index, id);
723 continue;
724 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700725
726 kp = clib_mem_alloc (sizeof (*kp));
727 *kp = sup_and_sub_key;
728
729 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Eyal Baric5b13602016-11-24 19:42:43 +0200730 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700731 template.sup_sw_if_index = hi->sw_if_index;
732 template.sub.id = id;
Eyal Baria4509cf2016-09-26 09:24:09 +0300733 if (id_min < id_max)
734 template.sub.eth.outer_vlan_id = id;
735
Ed Warnickecb9cada2015-12-08 15:45:58 -0700736 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400737 if (error)
738 goto done;
Dave Barach16ad6ae2016-07-28 17:55:30 -0400739
Ed Warnickecb9cada2015-12-08 15:45:58 -0700740 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
741 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400742 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
743 vnet_get_main (), sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700744 }
745
Dave Barachba868bb2016-08-08 09:51:21 -0400746done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700747 return error;
748}
749
Dave Barachba868bb2016-08-08 09:51:21 -0400750/* *INDENT-OFF* */
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700751/*?
752 * Create vlan subinterfaces
753 *
754 * @cliexpar
755 * @cliexstart{create sub-interfaces}
756 *
757 * To create a vlan subinterface 11 to process packets on 802.1q VLAN id 11, use:
758 *
759 * vpp# create sub GigabitEthernet2/0/0 11
760 *
761 * This shorthand is equivalent to:
762 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 11 exact-match
763 *
764 * You can specify a subinterface number that is different from the vlan id:
765 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100
766 *
767 * You can create qinq and q-in-any interfaces:
768 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200
769 * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any
770 *
771 * You can also create dot1ad interfaces:
772 * vpp# create sub GigabitEthernet2/0/0 11 dot1ad 11
773 * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q 200
774 *
775 * Subinterfaces can be configured as either exact-match or non-exact match.
776 * Non-exact match is the CLI default. If exact-match is specified,
777 * packets must have the same number of vlan tags as the configuration.
778 * For non-exact-match, packets must at least that number of tags.
779 * L3 (routed) interfaces must be configured as exact-match.
780 * L2 interfaces are typically configured as non-exact-match.
781 *
782 * For example, a packet with outer vlan 100 and inner 200 would match this interface:
783 * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100
784 *
785 * but would not match this interface:
786 * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100 exact-match
787 *
788 * There are two special subinterfaces that can be configured. Subinterface untagged has no vlan tags:
789 * vpp# create sub GigabitEthernet2/0/0 5 untagged
790 *
791 * The subinterface default matches any packet that does not match any other subinterface:
792 * vpp# create sub GigabitEthernet2/0/0 7 default
793 * @cliexend
794 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700795VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700796 .path = "create sub-interfaces",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700797 .short_help = "create sub-interfaces <nn>[-<nn>] [dot1q|dot1ad|default|untagged]",
798 .function = create_sub_interfaces,
799};
Dave Barachba868bb2016-08-08 09:51:21 -0400800/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700801
802static clib_error_t *
803set_state (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400804 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700805{
Dave Barachba868bb2016-08-08 09:51:21 -0400806 vnet_main_t *vnm = vnet_get_main ();
807 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700808 u32 sw_if_index, flags;
809
810 sw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400811 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700812 {
813 error = clib_error_return (0, "unknown interface `%U'",
814 format_unformat_error, input);
815 goto done;
816 }
817
Dave Barachba868bb2016-08-08 09:51:21 -0400818 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700819 {
820 error = clib_error_return (0, "unknown flags `%U'",
821 format_unformat_error, input);
822 goto done;
823 }
824
825 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
826 if (error)
827 goto done;
828
Dave Barachba868bb2016-08-08 09:51:21 -0400829done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700830 return error;
831}
832
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700833
Dave Barachba868bb2016-08-08 09:51:21 -0400834/* *INDENT-OFF* */
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700835/*?
836 * Interface admin up/down
837 *
838 * @cliexpar
839 * @cliexstart{set interface state}
840 * vpp# set interface state GigabitEthernet2/0/0 up
841 * vpp# set interface state GigabitEthernet2/0/0 down
842 * @cliexend
843 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700844VLIB_CLI_COMMAND (set_state_command, static) = {
845 .path = "set interface state",
Ray Kinsella3ef16712017-04-27 09:57:00 +0100846 .short_help = "set interface state <if-name> [up|down|punt|enable]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700847 .function = set_state,
848};
Dave Barachba868bb2016-08-08 09:51:21 -0400849/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700850
851static clib_error_t *
852set_unnumbered (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400853 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700854{
Dave Barachba868bb2016-08-08 09:51:21 -0400855 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700856 u32 unnumbered_sw_if_index;
857 u32 inherit_from_sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400858 vnet_sw_interface_t *si;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700859 int is_set = 0;
860 int is_del = 0;
Neale Ranns898273f2017-03-18 02:57:38 -0700861 u32 was_unnum;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700862
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700863 if (unformat (input, "%U use %U",
864 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
865 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
866 is_set = 1;
867 else if (unformat (input, "del %U",
868 unformat_vnet_sw_interface, vnm,
869 &unnumbered_sw_if_index))
870 is_del = 1;
871 else
872 return clib_error_return (0, "parse error '%U'",
873 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700874
875 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
Neale Ranns898273f2017-03-18 02:57:38 -0700876 was_unnum = (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED);
877
Dave Barachba868bb2016-08-08 09:51:21 -0400878 if (is_del)
879 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700880 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
Dave Barachba868bb2016-08-08 09:51:21 -0400881 si->unnumbered_sw_if_index = (u32) ~ 0;
Neale Ranns898273f2017-03-18 02:57:38 -0700882
Neale Ranns4b919a52017-03-11 05:55:21 -0800883 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
884 [unnumbered_sw_if_index] = ~0;
885 ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
886 [unnumbered_sw_if_index] = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400887 }
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700888 else if (is_set)
Dave Barachba868bb2016-08-08 09:51:21 -0400889 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700890 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
891 si->unnumbered_sw_if_index = inherit_from_sw_if_index;
Neale Ranns898273f2017-03-18 02:57:38 -0700892
Neale Ranns4b919a52017-03-11 05:55:21 -0800893 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
894 [unnumbered_sw_if_index] =
895 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
896 [inherit_from_sw_if_index];
897 ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
898 [unnumbered_sw_if_index] =
899 ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
900 [inherit_from_sw_if_index];
Dave Barachba868bb2016-08-08 09:51:21 -0400901 }
Neale Ranns898273f2017-03-18 02:57:38 -0700902
903 if (was_unnum != (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
904 {
905 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, !is_del);
906 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, !is_del);
907 }
Dave Barachba868bb2016-08-08 09:51:21 -0400908
Ed Warnickecb9cada2015-12-08 15:45:58 -0700909 return 0;
910}
911
Dave Barachba868bb2016-08-08 09:51:21 -0400912/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700913VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
914 .path = "set interface unnumbered",
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700915 .short_help = "set interface unnumbered [<intfc> use <intfc> | del <intfc>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700916 .function = set_unnumbered,
917};
Dave Barachba868bb2016-08-08 09:51:21 -0400918/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700919
920
921
922static clib_error_t *
923set_hw_class (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400924 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700925{
Dave Barachba868bb2016-08-08 09:51:21 -0400926 vnet_main_t *vnm = vnet_get_main ();
927 vnet_interface_main_t *im = &vnm->interface_main;
928 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700929 u32 hw_if_index, hw_class_index;
930
931 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400932 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700933 {
934 error = clib_error_return (0, "unknown hardware interface `%U'",
935 format_unformat_error, input);
936 goto done;
937 }
938
Dave Barachba868bb2016-08-08 09:51:21 -0400939 if (!unformat_user (input, unformat_hash_string,
940 im->hw_interface_class_by_name, &hw_class_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700941 {
942 error = clib_error_return (0, "unknown hardware class `%U'",
943 format_unformat_error, input);
944 goto done;
945 }
946
947 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
948 if (error)
949 goto done;
950
Dave Barachba868bb2016-08-08 09:51:21 -0400951done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700952 return error;
953}
954
Dave Barachba868bb2016-08-08 09:51:21 -0400955/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700956VLIB_CLI_COMMAND (set_hw_class_command, static) = {
957 .path = "set interface hw-class",
958 .short_help = "Set interface hardware class",
959 .function = set_hw_class,
960};
Dave Barachba868bb2016-08-08 09:51:21 -0400961/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700962
Dave Barachba868bb2016-08-08 09:51:21 -0400963static clib_error_t *
964vnet_interface_cli_init (vlib_main_t * vm)
965{
966 return 0;
967}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700968
969VLIB_INIT_FUNCTION (vnet_interface_cli_init);
970
Dave Barachba868bb2016-08-08 09:51:21 -0400971static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700972renumber_interface_command_fn (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400973 unformat_input_t * input,
974 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700975{
976 u32 hw_if_index;
977 u32 new_dev_instance;
Dave Barachba868bb2016-08-08 09:51:21 -0400978 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700979 int rv;
980
Dave Barachba868bb2016-08-08 09:51:21 -0400981 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700982 return clib_error_return (0, "unknown hardware interface `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -0400983 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700984
Dave Barachba868bb2016-08-08 09:51:21 -0400985 if (!unformat (input, "%d", &new_dev_instance))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700986 return clib_error_return (0, "new dev instance missing");
987
988 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
989
990 switch (rv)
991 {
992 case 0:
993 break;
994
995 default:
996 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
Dave Barachba868bb2016-08-08 09:51:21 -0400997 rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700998
999 }
1000
1001 return 0;
1002}
1003
1004
Dave Barachba868bb2016-08-08 09:51:21 -04001005/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001006VLIB_CLI_COMMAND (renumber_interface_command, static) = {
1007 .path = "renumber interface",
1008 .short_help = "renumber interface <if-name> <new-dev-instance>",
1009 .function = renumber_interface_command_fn,
1010};
Dave Barachba868bb2016-08-08 09:51:21 -04001011/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -07001012
Damjan Marion8358ff92016-04-15 14:26:00 +02001013static clib_error_t *
1014promiscuous_cmd (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001015 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion8358ff92016-04-15 14:26:00 +02001016{
Dave Barachba868bb2016-08-08 09:51:21 -04001017 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001018 u32 hw_if_index;
1019 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
Dave Barachba868bb2016-08-08 09:51:21 -04001020 ethernet_main_t *em = &ethernet_main;
1021 ethernet_interface_t *eif;
Damjan Marion8358ff92016-04-15 14:26:00 +02001022
1023 if (unformat (input, "on %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001024 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001025 ;
1026 else if (unformat (input, "off %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001027 unformat_ethernet_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001028 flags = 0;
1029 else
1030 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001031 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001032
1033 eif = ethernet_get_interface (em, hw_if_index);
1034 if (!eif)
1035 return clib_error_return (0, "not supported");
1036
1037 ethernet_set_flags (vnm, hw_if_index, flags);
1038 return 0;
1039}
1040
Dave Barachba868bb2016-08-08 09:51:21 -04001041/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001042VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1043 .path = "set interface promiscuous",
1044 .short_help = "set interface promiscuous [on | off] <intfc>",
1045 .function = promiscuous_cmd,
1046};
Dave Barachba868bb2016-08-08 09:51:21 -04001047/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001048
1049static clib_error_t *
1050mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1051{
Dave Barachba868bb2016-08-08 09:51:21 -04001052 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001053 u32 hw_if_index, mtu;
1054 u32 flags = ETHERNET_INTERFACE_FLAG_MTU;
Dave Barachba868bb2016-08-08 09:51:21 -04001055 ethernet_main_t *em = &ethernet_main;
Damjan Marion8358ff92016-04-15 14:26:00 +02001056
1057 if (unformat (input, "%d %U", &mtu,
Dave Barachba868bb2016-08-08 09:51:21 -04001058 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001059 {
Dave Barachba868bb2016-08-08 09:51:21 -04001060 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1061 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
Damjan Marion8358ff92016-04-15 14:26:00 +02001062
1063 if (!eif)
Dave Barachba868bb2016-08-08 09:51:21 -04001064 return clib_error_return (0, "not supported");
Damjan Marion8358ff92016-04-15 14:26:00 +02001065
Mohsin Kazmif2ba9aa2016-04-24 18:53:42 +02001066 if (mtu < hi->min_supported_packet_bytes)
Damjan Marion8358ff92016-04-15 14:26:00 +02001067 return clib_error_return (0, "Invalid mtu (%d): "
1068 "must be >= min pkt bytes (%d)", mtu,
Mohsin Kazmif2ba9aa2016-04-24 18:53:42 +02001069 hi->min_supported_packet_bytes);
Damjan Marion8358ff92016-04-15 14:26:00 +02001070
Mohsin Kazmif2ba9aa2016-04-24 18:53:42 +02001071 if (mtu > hi->max_supported_packet_bytes)
1072 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
Dave Barachba868bb2016-08-08 09:51:21 -04001073 hi->max_supported_packet_bytes);
Damjan Marion8358ff92016-04-15 14:26:00 +02001074
1075 if (hi->max_packet_bytes != mtu)
1076 {
1077 hi->max_packet_bytes = mtu;
1078 ethernet_set_flags (vnm, hw_if_index, flags);
1079 }
1080 }
1081 else
1082 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001083 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001084 return 0;
1085}
1086
Dave Barachba868bb2016-08-08 09:51:21 -04001087/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001088VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1089 .path = "set interface mtu",
Mohsin Kazmif2ba9aa2016-04-24 18:53:42 +02001090 .short_help = "set interface mtu <value> <intfc>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001091 .function = mtu_cmd,
1092};
Dave Barachba868bb2016-08-08 09:51:21 -04001093/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001094
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001095static clib_error_t *
1096set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1097 vlib_cli_command_t * cmd)
1098{
1099 vnet_main_t *vnm = vnet_get_main ();
1100 clib_error_t *error = 0;
1101 u32 sw_if_index = ~0;
1102 u64 mac = 0;
1103
1104 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1105 {
1106 error = clib_error_return (0, "unknown interface `%U'",
1107 format_unformat_error, input);
1108 goto done;
1109 }
1110 if (!unformat_user (input, unformat_ethernet_address, &mac))
1111 {
1112 error = clib_error_return (0, "expected mac address `%U'",
1113 format_unformat_error, input);
1114 goto done;
1115 }
1116 error = vnet_hw_interface_change_mac_address (vnm, sw_if_index, mac);
1117done:
1118 return error;
1119}
1120
1121/*?
1122 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1123 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1124 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1125 *
1126 * @cliexpar
1127 * @parblock
1128 * Example of how to change MAC Address of interface:
1129 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1130 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1131 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1132 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1133 * @endparblock
1134?*/
1135/* *INDENT-OFF* */
1136VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1137 .path = "set interface mac address",
1138 .short_help = "set interface mac address <intfc> <mac-address>",
1139 .function = set_interface_mac_address,
1140};
1141/* *INDENT-ON* */
1142
Dave Barach7be864a2016-11-28 11:41:35 -05001143static clib_error_t *
1144set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1145{
1146 vnet_main_t *vnm = vnet_get_main ();
1147 u32 sw_if_index = ~0;
1148 u8 *tag = 0;
1149
1150 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1151 vnm, &sw_if_index, &tag))
1152 return clib_error_return (0, "unknown input `%U'",
1153 format_unformat_error, input);
1154
1155 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1156
1157 return 0;
1158}
1159
1160/* *INDENT-OFF* */
1161VLIB_CLI_COMMAND (set_tag_command, static) = {
1162 .path = "set interface tag",
1163 .short_help = "set interface tag <intfc> <tag>",
1164 .function = set_tag,
1165};
1166/* *INDENT-ON* */
1167
1168static clib_error_t *
1169clear_tag (vlib_main_t * vm, unformat_input_t * input,
1170 vlib_cli_command_t * cmd)
1171{
1172 vnet_main_t *vnm = vnet_get_main ();
1173 u32 sw_if_index = ~0;
1174
1175 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1176 return clib_error_return (0, "unknown input `%U'",
1177 format_unformat_error, input);
1178
1179 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1180
1181 return 0;
1182}
1183
1184/* *INDENT-OFF* */
1185VLIB_CLI_COMMAND (clear_tag_command, static) = {
1186 .path = "clear interface tag",
1187 .short_help = "clear interface tag <intfc>",
1188 .function = clear_tag,
1189};
1190/* *INDENT-ON* */
1191
Damjan Marion44036902017-04-28 12:29:15 +02001192static clib_error_t *
Stevene3a395c2017-05-09 16:19:50 -07001193set_hw_interface_rx_mode (vnet_main_t * vnm, u32 hw_if_index,
1194 u32 queue_id, vnet_hw_interface_rx_mode mode)
1195{
1196 vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index);
1197 vnet_device_class_t *dev_class =
1198 vnet_get_device_class (vnm, hw->dev_class_index);
1199 clib_error_t *error;
1200 vnet_hw_interface_rx_mode old_mode;
1201 int rv;
1202
Damjan Marion4e53a0d2017-06-21 14:29:44 +02001203 if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT)
1204 mode = hw->default_rx_mode;
1205
Stevene3a395c2017-05-09 16:19:50 -07001206 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &old_mode);
1207 switch (rv)
1208 {
1209 case 0:
1210 if (old_mode == mode)
1211 return 0; /* same rx-mode, no change */
1212 break;
1213 case VNET_API_ERROR_INVALID_INTERFACE:
1214 return clib_error_return (0, "invalid interface");
1215 default:
1216 return clib_error_return (0, "unknown error");
1217 }
1218
1219 if (dev_class->rx_mode_change_function)
1220 {
1221 error = dev_class->rx_mode_change_function (vnm, hw_if_index, queue_id,
1222 mode);
1223 if (error)
1224 return (error);
1225 }
1226
1227 rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1228 switch (rv)
1229 {
1230 case 0:
1231 break;
1232 case VNET_API_ERROR_UNSUPPORTED:
1233 return clib_error_return (0, "unsupported");
1234 case VNET_API_ERROR_INVALID_INTERFACE:
1235 return clib_error_return (0, "invalid interface");
1236 default:
1237 return clib_error_return (0, "unknown error");
1238 }
1239
1240 return 0;
1241}
1242
1243static clib_error_t *
Damjan Marion44036902017-04-28 12:29:15 +02001244set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1245 vlib_cli_command_t * cmd)
1246{
1247 clib_error_t *error = 0;
1248 unformat_input_t _line_input, *line_input = &_line_input;
1249 vnet_main_t *vnm = vnet_get_main ();
1250 vnet_hw_interface_t *hw;
1251 u32 hw_if_index = (u32) ~ 0;
1252 u32 queue_id = (u32) ~ 0;
1253 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
Stevene3a395c2017-05-09 16:19:50 -07001254 int i;
Dave Barach7be864a2016-11-28 11:41:35 -05001255
Damjan Marion44036902017-04-28 12:29:15 +02001256 if (!unformat_user (input, unformat_line_input, line_input))
1257 return 0;
1258
1259 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1260 {
1261 if (unformat
1262 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1263 ;
1264 else if (unformat (line_input, "queue %d", &queue_id))
1265 ;
1266 else if (unformat (line_input, "polling"))
1267 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
1268 else if (unformat (line_input, "interrupt"))
1269 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
1270 else if (unformat (line_input, "adaptive"))
1271 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
1272 else
1273 {
1274 error = clib_error_return (0, "parse error: '%U'",
1275 format_unformat_error, line_input);
1276 unformat_free (line_input);
1277 return error;
1278 }
1279 }
1280
1281 unformat_free (line_input);
1282
1283 if (hw_if_index == (u32) ~ 0)
1284 return clib_error_return (0, "please specify valid interface name");
1285
1286 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
1287 return clib_error_return (0, "please specify valid rx-mode");
1288
1289 hw = vnet_get_hw_interface (vnm, hw_if_index);
1290
1291 if (queue_id == ~0)
Damjan Marion4e53a0d2017-06-21 14:29:44 +02001292 {
1293 for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1294 {
1295 error = set_hw_interface_rx_mode (vnm, hw_if_index, i, mode);
1296 if (error)
1297 break;
1298 }
1299 hw->default_rx_mode = mode;
1300 }
Damjan Marion44036902017-04-28 12:29:15 +02001301 else
Stevene3a395c2017-05-09 16:19:50 -07001302 error = set_hw_interface_rx_mode (vnm, hw_if_index, queue_id, mode);
Damjan Marion44036902017-04-28 12:29:15 +02001303
Stevene3a395c2017-05-09 16:19:50 -07001304 return (error);
Damjan Marion44036902017-04-28 12:29:15 +02001305}
1306
1307/*?
1308 * This command is used to assign a given interface, and optionally a
1309 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1310 * it defaults to 0.
1311 *
1312 * @cliexpar
1313 * Example of how to display the interface placement:
1314 * @cliexstart{show interface rx-placement}
1315 * Thread 1 (vpp_wk_0):
1316 * GigabitEthernet0/8/0 queue 0
1317 * GigabitEthernet0/9/0 queue 0
1318 * Thread 2 (vpp_wk_1):
1319 * GigabitEthernet0/8/0 queue 1
1320 * GigabitEthernet0/9/0 queue 1
1321 * @cliexend
1322 * Example of how to assign a interface and queue to a thread:
1323 * @cliexcmd{set interface placement GigabitEthernet0/8/0 queue 1 thread 1}
1324?*/
1325/* *INDENT-OFF* */
1326VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
1327 .path = "set interface rx-mode",
1328 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1329 .function = set_interface_rx_mode,
1330};
1331/* *INDENT-ON* */
1332
1333static clib_error_t *
1334show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1335 vlib_cli_command_t * cmd)
1336{
1337 u8 *s = 0;
1338 vnet_main_t *vnm = vnet_get_main ();
1339 vnet_device_input_runtime_t *rt;
1340 vnet_device_and_queue_t *dq;
1341 vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
1342 uword si;
1343 int index = 0;
1344
1345 /* *INDENT-OFF* */
1346 foreach_vlib_main (({
1347 clib_bitmap_foreach (si, pn->sibling_bitmap,
1348 ({
1349 rt = vlib_node_get_runtime_data (this_vlib_main, si);
1350
1351 if (vec_len (rt->devices_and_queues))
1352 s = format (s, " node %U:\n", format_vlib_node_name, vm, si);
1353
1354 vec_foreach (dq, rt->devices_and_queues)
1355 {
Steven9d6d9892017-06-30 07:15:02 -07001356 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm,
1357 dq->hw_if_index);
Damjan Marion44036902017-04-28 12:29:15 +02001358 s = format (s, " %U queue %u (%U)\n",
Steven9d6d9892017-06-30 07:15:02 -07001359 format_vnet_sw_if_index_name, vnm, hi->sw_if_index,
Damjan Marion44036902017-04-28 12:29:15 +02001360 dq->queue_id,
1361 format_vnet_hw_interface_rx_mode, dq->mode);
1362 }
1363 }));
1364 if (vec_len (s) > 0)
1365 {
1366 vlib_cli_output(vm, "Thread %u (%v):\n%v", index,
1367 vlib_worker_threads[index].name, s);
1368 vec_reset_length (s);
1369 }
1370 index++;
1371 }));
1372 /* *INDENT-ON* */
1373
1374 vec_free (s);
1375 return 0;
1376}
1377
1378/* *INDENT-OFF* */
1379VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1380 .path = "show interface rx-placement",
1381 .short_help = "show interface rx-placement",
1382 .function = show_interface_rx_placement_fn,
1383};
1384/* *INDENT-ON* */
1385
1386static clib_error_t *
1387set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input,
1388 vlib_cli_command_t * cmd)
1389{
1390 clib_error_t *error = 0;
1391 unformat_input_t _line_input, *line_input = &_line_input;
1392 vnet_main_t *vnm = vnet_get_main ();
1393 vnet_device_main_t *vdm = &vnet_device_main;
1394 vnet_hw_interface_rx_mode mode;
1395 u32 hw_if_index = (u32) ~ 0;
1396 u32 queue_id = (u32) 0;
1397 u32 thread_index = (u32) ~ 0;
1398 int rv;
1399
1400 if (!unformat_user (input, unformat_line_input, line_input))
1401 return 0;
1402
1403 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1404 {
1405 if (unformat
1406 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1407 ;
1408 else if (unformat (line_input, "queue %d", &queue_id))
1409 ;
1410 else if (unformat (line_input, "main", &thread_index))
1411 thread_index = 0;
1412 else if (unformat (line_input, "worker %d", &thread_index))
1413 thread_index += vdm->first_worker_thread_index;
1414 else
1415 {
1416 error = clib_error_return (0, "parse error: '%U'",
1417 format_unformat_error, line_input);
1418 unformat_free (line_input);
1419 return error;
1420 }
1421 }
1422
1423 unformat_free (line_input);
1424
1425 if (hw_if_index == (u32) ~ 0)
1426 return clib_error_return (0, "please specify valid interface name");
1427
1428 if (thread_index > vdm->last_worker_thread_index)
1429 return clib_error_return (0,
1430 "please specify valid worker thread or main");
1431
1432 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode);
1433
1434 if (rv)
1435 return clib_error_return (0, "not found");
1436
1437 rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id);
1438
1439 if (rv)
1440 return clib_error_return (0, "not found");
1441
1442 vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id,
1443 thread_index);
1444 vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1445
1446 return 0;
1447}
1448
1449/*?
1450 * This command is used to assign a given interface, and optionally a
1451 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1452 * it defaults to 0.
1453 *
1454 * @cliexpar
1455 * Example of how to display the interface placement:
1456 * @cliexstart{show interface placement}
1457 * Thread 1 (vpp_wk_0):
1458 * GigabitEthernet0/8/0 queue 0
1459 * GigabitEthernet0/9/0 queue 0
1460 * Thread 2 (vpp_wk_1):
1461 * GigabitEthernet0/8/0 queue 1
1462 * GigabitEthernet0/9/0 queue 1
1463 * @cliexend
1464 * Example of how to assign a interface and queue to a thread:
1465 * @cliexcmd{set interface placement GigabitEthernet0/8/0 queue 1 thread 1}
1466?*/
1467/* *INDENT-OFF* */
1468VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1469 .path = "set interface rx-placement",
Damjan Marion6f9ac652017-06-15 19:01:31 +02001470 .short_help = "set interface rx-placement <hw-interface> [queue <n>] "
1471 "[worker <n> | main]",
Damjan Marion44036902017-04-28 12:29:15 +02001472 .function = set_interface_rx_placement,
Damjan Marion6f9ac652017-06-15 19:01:31 +02001473 .is_mp_safe = 1,
Damjan Marion44036902017-04-28 12:29:15 +02001474};
1475
1476/* *INDENT-ON* */
Dave Barachba868bb2016-08-08 09:51:21 -04001477/*
1478 * fd.io coding-style-patch-verification: ON
1479 *
1480 * Local Variables:
1481 * eval: (c-set-style "gnu")
1482 * End:
1483 */