blob: bfce03e155dc78448e5d2c91bb210ccc3db4edbe [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>
Ed Warnickecb9cada2015-12-08 15:45:58 -070050
Dave Barachba868bb2016-08-08 09:51:21 -040051static int
52compare_interface_names (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -070053{
Dave Barachba868bb2016-08-08 09:51:21 -040054 u32 *hi1 = a1;
55 u32 *hi2 = a2;
Ed Warnickecb9cada2015-12-08 15:45:58 -070056
Dave Barachba868bb2016-08-08 09:51:21 -040057 return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2);
Ed Warnickecb9cada2015-12-08 15:45:58 -070058}
59
60static clib_error_t *
61show_or_clear_hw_interfaces (vlib_main_t * vm,
62 unformat_input_t * input,
63 vlib_cli_command_t * cmd)
64{
Dave Barachba868bb2016-08-08 09:51:21 -040065 clib_error_t *error = 0;
66 vnet_main_t *vnm = vnet_get_main ();
67 vnet_interface_main_t *im = &vnm->interface_main;
68 vnet_hw_interface_t *hi;
69 u32 hw_if_index, *hw_if_indices = 0;
John Lobcebbb92016-04-05 15:47:43 -040070 int i, verbose = -1, is_show, show_bond = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -070071
72 is_show = strstr (cmd->path, "show") != 0;
73 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
74 {
75 /* See if user wants to show a specific interface. */
Dave Barachba868bb2016-08-08 09:51:21 -040076 if (unformat
77 (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
78 vec_add1 (hw_if_indices, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -040079
Sean Hope679ea792016-02-22 15:12:01 -050080 /* See if user wants to show an interface with a specific hw_if_index. */
81 else if (unformat (input, "%u", &hw_if_index))
Dave Barachba868bb2016-08-08 09:51:21 -040082 vec_add1 (hw_if_indices, hw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -070083
84 else if (unformat (input, "verbose"))
Dave Barachba868bb2016-08-08 09:51:21 -040085 verbose = 1; /* this is also the default */
Ed Warnickecb9cada2015-12-08 15:45:58 -070086
87 else if (unformat (input, "detail"))
88 verbose = 2;
89
90 else if (unformat (input, "brief"))
91 verbose = 0;
92
John Lobcebbb92016-04-05 15:47:43 -040093 else if (unformat (input, "bond"))
Dave Barachba868bb2016-08-08 09:51:21 -040094 {
95 show_bond = 1;
96 if (verbose < 0)
97 verbose = 0; /* default to brief for link bonding */
98 }
John Lobcebbb92016-04-05 15:47:43 -040099
Ed Warnickecb9cada2015-12-08 15:45:58 -0700100 else
101 {
102 error = clib_error_return (0, "unknown input `%U'",
103 format_unformat_error, input);
104 goto done;
105 }
106 }
Dave Barachba868bb2016-08-08 09:51:21 -0400107
Ed Warnickecb9cada2015-12-08 15:45:58 -0700108 /* Gather interfaces. */
109 if (vec_len (hw_if_indices) == 0)
110 pool_foreach (hi, im->hw_interfaces,
111 vec_add1 (hw_if_indices, hi - im->hw_interfaces));
112
Dave Barachba868bb2016-08-08 09:51:21 -0400113 if (verbose < 0)
114 verbose = 1; /* default to verbose (except bond) */
John Lobcebbb92016-04-05 15:47:43 -0400115
Ed Warnickecb9cada2015-12-08 15:45:58 -0700116 if (is_show)
117 {
118 /* Sort by name. */
119 vec_sort_with_function (hw_if_indices, compare_interface_names);
120
121 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose);
122 for (i = 0; i < vec_len (hw_if_indices); i++)
123 {
124 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
Dave Barachba868bb2016-08-08 09:51:21 -0400125 if (show_bond == 0) /* show all interfaces */
126 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
127 hi, verbose);
128 else if ((hi->bond_info) &&
John Lobcebbb92016-04-05 15:47:43 -0400129 (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
Dave Barachba868bb2016-08-08 09:51:21 -0400130 { /* show only bonded interface and all its slave interfaces */
John Lobcebbb92016-04-05 15:47:43 -0400131 int hw_idx;
Dave Barachba868bb2016-08-08 09:51:21 -0400132 vnet_hw_interface_t *shi;
133 vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm,
John Lobcebbb92016-04-05 15:47:43 -0400134 hi, verbose);
Dave Barachba868bb2016-08-08 09:51:21 -0400135
136 /* *INDENT-OFF* */
John Lobcebbb92016-04-05 15:47:43 -0400137 clib_bitmap_foreach (hw_idx, hi->bond_info,
Dave Barachba868bb2016-08-08 09:51:21 -0400138 ({
139 shi = vnet_get_hw_interface(vnm, hw_idx);
140 vlib_cli_output (vm, "%U\n",
141 format_vnet_hw_interface, vnm, shi, verbose);
142 }));
143 /* *INDENT-ON* */
John Lobcebbb92016-04-05 15:47:43 -0400144 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700145 }
146 }
147 else
148 {
149 for (i = 0; i < vec_len (hw_if_indices); i++)
150 {
Dave Barachba868bb2016-08-08 09:51:21 -0400151 vnet_device_class_t *dc;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700152
153 hi = vnet_get_hw_interface (vnm, hw_if_indices[i]);
154 dc = vec_elt_at_index (im->device_classes, hi->dev_class_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400155
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156 if (dc->clear_counters)
157 dc->clear_counters (hi->dev_instance);
158 }
159 }
160
Dave Barachba868bb2016-08-08 09:51:21 -0400161done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700162 vec_free (hw_if_indices);
163 return error;
164}
165
Dave Barachba868bb2016-08-08 09:51:21 -0400166/* *INDENT-OFF* */
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700167/*?
168 * Displays various information about the state of the current terminal
169 * session.
170 *
171 * @cliexpar
172 * @cliexstart{show hardware}
173 * Name Link Hardware
174 * GigabitEthernet2/0/0 up GigabitEthernet2/0/0
175 * Ethernet address 00:50:56:b7:7c:83
176 * Intel 82545em_copper
177 * link up, media 1000T full-duplex, master,
178 * 0 unprocessed, 384 total buffers on rx queue 0 ring
179 * 237 buffers in driver rx cache
180 * rx total packets 1816
181 * rx total bytes 181084
182 * rx good packets 1816
183 * rx good bytes 181084
184 * rx 65 127 byte packets 1586
185 * rx 256 511 byte packets 230
186 * tx total packets 346
187 * tx total bytes 90224
188 * tx good packets 346
189 * tx good bytes 88840
190 * tx 64 byte packets 1
191 * tx 65 127 byte packets 115
192 * tx 256 511 byte packets 230
193 * @cliexend
194 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700195VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = {
196 .path = "show hardware-interfaces",
John Lobcebbb92016-04-05 15:47:43 -0400197 .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] [<if-name1> <if-name2> ...]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700198 .function = show_or_clear_hw_interfaces,
199};
Dave Barachba868bb2016-08-08 09:51:21 -0400200/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700201
Dave Barachba868bb2016-08-08 09:51:21 -0400202/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700203VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = {
204 .path = "clear hardware-interfaces",
205 .short_help = "Clear hardware interfaces statistics",
206 .function = show_or_clear_hw_interfaces,
207};
Dave Barachba868bb2016-08-08 09:51:21 -0400208/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700209
Dave Barachba868bb2016-08-08 09:51:21 -0400210static int
211sw_interface_name_compare (void *a1, void *a2)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700212{
213 vnet_sw_interface_t *si1 = a1;
214 vnet_sw_interface_t *si2 = a2;
215
Dave Barachba868bb2016-08-08 09:51:21 -0400216 return vnet_sw_interface_compare (vnet_get_main (),
217 si1->sw_if_index, si2->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700218}
219
220static clib_error_t *
221show_sw_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400222 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700223{
Dave Barachba868bb2016-08-08 09:51:21 -0400224 clib_error_t *error = 0;
225 vnet_main_t *vnm = vnet_get_main ();
226 vnet_interface_main_t *im = &vnm->interface_main;
227 vnet_sw_interface_t *si, *sorted_sis = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200228 u32 sw_if_index = ~(u32) 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700229 u8 show_addresses = 0;
Damjan Marion22311502016-10-28 20:30:15 +0200230 u8 show_features = 0;
Dave Barach7be864a2016-11-28 11:41:35 -0500231 u8 show_tag = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700232
233 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
234 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700235 /* See if user wants to show specific interface */
Dave Barachba868bb2016-08-08 09:51:21 -0400236 if (unformat
237 (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700238 {
Dave Barachba868bb2016-08-08 09:51:21 -0400239 si = pool_elt_at_index (im->sw_interfaces, sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700240 vec_add1 (sorted_sis, si[0]);
241 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700242 else if (unformat (input, "address") || unformat (input, "addr"))
Dave Barachba868bb2016-08-08 09:51:21 -0400243 show_addresses = 1;
Damjan Marion22311502016-10-28 20:30:15 +0200244 else if (unformat (input, "features") || unformat (input, "feat"))
245 show_features = 1;
Dave Barach7be864a2016-11-28 11:41:35 -0500246 else if (unformat (input, "tag"))
247 show_tag = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700248 else
Dave Barachba868bb2016-08-08 09:51:21 -0400249 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700250 error = clib_error_return (0, "unknown input `%U'",
251 format_unformat_error, input);
252 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400253 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700254 }
255
Dave Barach7be864a2016-11-28 11:41:35 -0500256 if (show_features || show_tag)
Damjan Marion22311502016-10-28 20:30:15 +0200257 {
258 if (sw_if_index == ~(u32) 0)
259 return clib_error_return (0, "Interface not specified...");
Dave Barach7be864a2016-11-28 11:41:35 -0500260 }
Damjan Marion22311502016-10-28 20:30:15 +0200261
Dave Barach7be864a2016-11-28 11:41:35 -0500262 if (show_features)
263 {
Damjan Marion22311502016-10-28 20:30:15 +0200264 vnet_interface_features_show (vm, sw_if_index);
265 return 0;
266 }
Dave Barach7be864a2016-11-28 11:41:35 -0500267 if (show_tag)
268 {
269 u8 *tag;
270 tag = vnet_get_sw_interface_tag (vnm, sw_if_index);
271 vlib_cli_output (vm, "%U: %s",
272 format_vnet_sw_if_index_name, vnm, sw_if_index,
273 tag ? (char *) tag : "(none)");
274 return 0;
275 }
Damjan Marion22311502016-10-28 20:30:15 +0200276
Ed Warnickecb9cada2015-12-08 15:45:58 -0700277 if (!show_addresses)
Dave Barachba868bb2016-08-08 09:51:21 -0400278 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700279
Dave Barachba868bb2016-08-08 09:51:21 -0400280 if (vec_len (sorted_sis) == 0) /* Get all interfaces */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281 {
282 /* Gather interfaces. */
Dave Barachba868bb2016-08-08 09:51:21 -0400283 sorted_sis =
284 vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700285 _vec_len (sorted_sis) = 0;
Dave Barachba868bb2016-08-08 09:51:21 -0400286 pool_foreach (si, im->sw_interfaces, (
287 {
Eyal Bari3212c572017-03-06 11:47:50 +0200288 if (vnet_swif_is_api_visible
289 (si)) vec_add1 (sorted_sis,
290 si[0]);}
Dave Barachba868bb2016-08-08 09:51:21 -0400291 ));
Ed Warnickecb9cada2015-12-08 15:45:58 -0700292
293 /* Sort by name. */
294 vec_sort_with_function (sorted_sis, sw_interface_name_compare);
295 }
296
297 if (show_addresses)
298 {
299 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400300 {
301 l2input_main_t *l2m = &l2input_main;
302 ip4_main_t *im4 = &ip4_main;
303 ip6_main_t *im6 = &ip6_main;
304 ip_lookup_main_t *lm4 = &im4->lookup_main;
305 ip_lookup_main_t *lm6 = &im6->lookup_main;
306 ip_interface_address_t *ia = 0;
307 ip4_address_t *r4;
308 ip6_address_t *r6;
309 u32 fib_index4 = 0, fib_index6 = 0;
310 ip4_fib_t *fib4;
311 ip6_fib_t *fib6;
312 l2_input_config_t *config;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700313
Dave Barachba868bb2016-08-08 09:51:21 -0400314 if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index)
315 fib_index4 = vec_elt (im4->fib_index_by_sw_if_index,
316 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700317
Dave Barachba868bb2016-08-08 09:51:21 -0400318 if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index)
319 fib_index6 = vec_elt (im6->fib_index_by_sw_if_index,
320 si->sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700321
Neale Ranns0bfe5d82016-08-25 15:29:12 +0100322 fib4 = ip4_fib_get (fib_index4);
323 fib6 = ip6_fib_get (fib_index6);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324
Dave Barachba868bb2016-08-08 09:51:21 -0400325 if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED)
326 vlib_cli_output
327 (vm, "%U (%s): \n unnumbered, use %U",
328 format_vnet_sw_if_index_name,
329 vnm, si->sw_if_index,
330 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn",
331 format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700332
Dave Barachba868bb2016-08-08 09:51:21 -0400333 else
334 {
335 vlib_cli_output (vm, "%U (%s):",
336 format_vnet_sw_if_index_name,
337 vnm, si->sw_if_index,
338 (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP)
339 ? "up" : "dn");
340 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700341
Dave Barachba868bb2016-08-08 09:51:21 -0400342 /* Display any L2 addressing info */
343 vec_validate (l2m->configs, si->sw_if_index);
344 config = vec_elt_at_index (l2m->configs, si->sw_if_index);
345 if (config->bridge)
346 {
347 u32 bd_id = l2input_main.bd_configs[config->bd_index].bd_id;
348 vlib_cli_output (vm, " l2 bridge bd_id %d%s%d", bd_id,
349 config->bvi ? " bvi shg " : " shg ",
350 config->shg);
351 }
352 else if (config->xconnect)
353 {
354 vlib_cli_output (vm, " l2 xconnect %U",
355 format_vnet_sw_if_index_name,
356 vnm, config->output_sw_if_index);
357 }
358
359 /* Display any IP4 addressing info */
360 /* *INDENT-OFF* */
361 foreach_ip_interface_address (lm4, ia, si->sw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700362 1 /* honor unnumbered */,
363 ({
364 r4 = ip_interface_address_get_address (lm4, ia);
365 if (fib4->table_id)
366 {
Dave Barachba868bb2016-08-08 09:51:21 -0400367 vlib_cli_output (vm, " %U/%d table %d",
368 format_ip4_address, r4,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700369 ia->address_length,
370 fib4->table_id);
371 }
372 else
373 {
Dave Barachba868bb2016-08-08 09:51:21 -0400374 vlib_cli_output (vm, " %U/%d",
375 format_ip4_address, r4,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700376 ia->address_length);
377 }
378 }));
Dave Barachba868bb2016-08-08 09:51:21 -0400379 /* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700380
Dave Barachba868bb2016-08-08 09:51:21 -0400381 /* Display any IP6 addressing info */
382 /* *INDENT-OFF* */
383 foreach_ip_interface_address (lm6, ia, si->sw_if_index,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700384 1 /* honor unnumbered */,
385 ({
386 r6 = ip_interface_address_get_address (lm6, ia);
387 if (fib6->table_id)
388 {
Dave Barachba868bb2016-08-08 09:51:21 -0400389 vlib_cli_output (vm, " %U/%d table %d",
390 format_ip6_address, r6,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700391 ia->address_length,
392 fib6->table_id);
393 }
394 else
395 {
Dave Barachba868bb2016-08-08 09:51:21 -0400396 vlib_cli_output (vm, " %U/%d",
397 format_ip6_address, r6,
Ed Warnickecb9cada2015-12-08 15:45:58 -0700398 ia->address_length);
399 }
400 }));
Dave Barachba868bb2016-08-08 09:51:21 -0400401 /* *INDENT-ON* */
402 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700403 }
404 else
405 {
406 vec_foreach (si, sorted_sis)
Dave Barachba868bb2016-08-08 09:51:21 -0400407 {
408 vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si);
409 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410 }
411
Dave Barachba868bb2016-08-08 09:51:21 -0400412done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700413 vec_free (sorted_sis);
414 return error;
415}
416
Dave Barachba868bb2016-08-08 09:51:21 -0400417/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700418VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = {
Dave Barach13ad1f02017-03-26 19:36:18 -0400419 .path = "show interface",
420 .short_help = "show interface [address|addr|features|feat] [<if-name1> <if-name2> ...]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700421 .function = show_sw_interfaces,
422};
Dave Barachba868bb2016-08-08 09:51:21 -0400423/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700424
425/* Root of all interface commands. */
Dave Barachba868bb2016-08-08 09:51:21 -0400426/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700427VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = {
428 .path = "interface",
429 .short_help = "Interface commands",
430};
Dave Barachba868bb2016-08-08 09:51:21 -0400431/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700432
Dave Barachba868bb2016-08-08 09:51:21 -0400433/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700434VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = {
435 .path = "set interface",
436 .short_help = "Interface commands",
437};
Dave Barachba868bb2016-08-08 09:51:21 -0400438/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700439
440static clib_error_t *
441clear_interface_counters (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400442 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700443{
Dave Barachba868bb2016-08-08 09:51:21 -0400444 vnet_main_t *vnm = vnet_get_main ();
445 vnet_interface_main_t *im = &vnm->interface_main;
446 vlib_simple_counter_main_t *sm;
447 vlib_combined_counter_main_t *cm;
448 static vnet_main_t **my_vnet_mains;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700449 int i, j, n_counters;
450
451 vec_reset_length (my_vnet_mains);
Dave Barachba868bb2016-08-08 09:51:21 -0400452
Ed Warnickecb9cada2015-12-08 15:45:58 -0700453 for (i = 0; i < vec_len (vnet_mains); i++)
454 {
455 if (vnet_mains[i])
Dave Barachba868bb2016-08-08 09:51:21 -0400456 vec_add1 (my_vnet_mains, vnet_mains[i]);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700457 }
458
459 if (vec_len (vnet_mains) == 0)
460 vec_add1 (my_vnet_mains, vnm);
461
462 n_counters = vec_len (im->combined_sw_if_counters);
463
464 for (j = 0; j < n_counters; j++)
465 {
Dave Barachba868bb2016-08-08 09:51:21 -0400466 for (i = 0; i < vec_len (my_vnet_mains); i++)
467 {
468 im = &my_vnet_mains[i]->interface_main;
469 cm = im->combined_sw_if_counters + j;
470 vlib_clear_combined_counters (cm);
471 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700472 }
473
474 n_counters = vec_len (im->sw_if_counters);
475
476 for (j = 0; j < n_counters; j++)
477 {
Dave Barachba868bb2016-08-08 09:51:21 -0400478 for (i = 0; i < vec_len (my_vnet_mains); i++)
479 {
480 im = &my_vnet_mains[i]->interface_main;
481 sm = im->sw_if_counters + j;
482 vlib_clear_simple_counters (sm);
483 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700484 }
485
486 return 0;
487}
488
Dave Barachba868bb2016-08-08 09:51:21 -0400489/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700490VLIB_CLI_COMMAND (clear_interface_counters_command, static) = {
491 .path = "clear interfaces",
492 .short_help = "Clear interfaces statistics",
493 .function = clear_interface_counters,
494};
Dave Barachba868bb2016-08-08 09:51:21 -0400495/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700496
Chris Luke16bcf7d2016-09-01 14:31:46 -0400497/**
498 * Parse subinterface names.
499 *
Dave Barachba868bb2016-08-08 09:51:21 -0400500 * The following subinterface syntax is supported. The first two are for
501 * backwards compatability:
502 *
503 * <intf-name> <id>
504 * - a subinterface with the name <intf-name>.<id>. The subinterface
505 * is a single dot1q vlan with vlan id <id> and exact-match semantics.
506 *
507 * <intf-name> <min_id>-<max_id>
508 * - a set of the above subinterfaces, repeating for each id
509 * in the range <min_id> to <max_id>
510 *
511 * In the following, exact-match semantics (i.e. the number of vlan tags on the
512 * packet must match the number of tags in the configuration) are used only if
513 * the keyword exact-match is present. Non-exact match is the default.
514 *
515 * <intf-name> <id> dot1q <outer_id> [exact-match]
516 * - a subinterface with the name <intf-name>.<id>. The subinterface
517 * is a single dot1q vlan with vlan id <outer_id>.
518 *
519 * <intf-name> <id> dot1q any [exact-match]
520 * - a subinterface with the name <intf-name>.<id>. The subinterface
521 * is a single dot1q vlan with any vlan id.
522 *
523 * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match]
524 * - a subinterface with the name <intf-name>.<id>. The subinterface
525 * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id
526 * <inner_id>.
527 *
528 * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match]
529 * - a subinterface with the name <intf-name>.<id>. The subinterface
530 * is a double dot1q vlan with outer vlan id <id> and any inner vlan id.
531 *
532 * <intf-name> <id> dot1q any inner-dot1q any [exact-match]
533 *
534 * - a subinterface with the name <intf-name>.<id>. The subinterface
535 * is a double dot1q vlan with any outer vlan id and any inner vlan id.
536 *
537 * For each of the above CLI, there is a duplicate that uses the keyword
538 * "dot1ad" in place of the first "dot1q". These interfaces use ethertype
539 * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double-
540 * tagged packets the inner ethertype is always 0x8100. Also note that
541 * the dot1q and dot1ad naming spaces are independent, so it is legal to
542 * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example:
543 *
544 * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match]
545 * - a subinterface with the name <intf-name>.<id>. The subinterface
546 * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan
547 * id <inner_id>.
548 *
549 * <intf-name> <id> untagged
550 * - a subinterface with the name <intf-name>.<id>. The subinterface
551 * has no vlan tags. Only one can be specified per interface.
552 *
553 * <intf-name> <id> default
554 * - a subinterface with the name <intf-name>.<id>. This is associated
555 * with a packet that did not match any other configured subinterface
556 * on this interface. Only one can be specified per interface.
557 */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700558
559static clib_error_t *
Dave Barachba868bb2016-08-08 09:51:21 -0400560parse_vlan_sub_interfaces (unformat_input_t * input,
561 vnet_sw_interface_t * template)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700562{
Dave Barachba868bb2016-08-08 09:51:21 -0400563 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700564 u32 inner_vlan, outer_vlan;
565
Dave Barachba868bb2016-08-08 09:51:21 -0400566 if (unformat (input, "any inner-dot1q any"))
567 {
568 template->sub.eth.flags.two_tags = 1;
569 template->sub.eth.flags.outer_vlan_id_any = 1;
570 template->sub.eth.flags.inner_vlan_id_any = 1;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700571 }
Dave Barachba868bb2016-08-08 09:51:21 -0400572 else if (unformat (input, "any"))
573 {
574 template->sub.eth.flags.one_tag = 1;
575 template->sub.eth.flags.outer_vlan_id_any = 1;
576 }
577 else if (unformat (input, "%d inner-dot1q any", &outer_vlan))
578 {
579 template->sub.eth.flags.two_tags = 1;
580 template->sub.eth.flags.inner_vlan_id_any = 1;
581 template->sub.eth.outer_vlan_id = outer_vlan;
582 }
583 else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan))
584 {
585 template->sub.eth.flags.two_tags = 1;
586 template->sub.eth.outer_vlan_id = outer_vlan;
587 template->sub.eth.inner_vlan_id = inner_vlan;
588 }
589 else if (unformat (input, "%d", &outer_vlan))
590 {
591 template->sub.eth.flags.one_tag = 1;
592 template->sub.eth.outer_vlan_id = outer_vlan;
593 }
594 else
595 {
596 error = clib_error_return (0, "expected dot1q config, got `%U'",
597 format_unformat_error, input);
598 goto done;
599 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700600
Dave Barachba868bb2016-08-08 09:51:21 -0400601 if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
602 {
603 if (unformat (input, "exact-match"))
604 {
605 template->sub.eth.flags.exact_match = 1;
606 }
607 }
608
609done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700610 return error;
611}
612
613static clib_error_t *
614create_sub_interfaces (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400615 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700616{
Dave Barachba868bb2016-08-08 09:51:21 -0400617 vnet_main_t *vnm = vnet_get_main ();
618 clib_error_t *error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700619 u32 hw_if_index, sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400620 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700621 u32 id, id_min, id_max;
622 vnet_sw_interface_t template;
623
624 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400625 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700626 {
627 error = clib_error_return (0, "unknown interface `%U'",
628 format_unformat_error, input);
629 goto done;
630 }
631
632 memset (&template, 0, sizeof (template));
633 template.sub.eth.raw_flags = 0;
634
Dave Barachba868bb2016-08-08 09:51:21 -0400635 if (unformat (input, "%d default", &id_min))
636 {
637 id_max = id_min;
638 template.sub.eth.flags.default_sub = 1;
639 }
640 else if (unformat (input, "%d untagged", &id_min))
641 {
642 id_max = id_min;
643 template.sub.eth.flags.no_tags = 1;
644 template.sub.eth.flags.exact_match = 1;
645 }
646 else if (unformat (input, "%d dot1q", &id_min))
647 {
648 /* parse dot1q config */
649 id_max = id_min;
650 error = parse_vlan_sub_interfaces (input, &template);
651 if (error)
652 goto done;
653 }
654 else if (unformat (input, "%d dot1ad", &id_min))
655 {
656 /* parse dot1ad config */
657 id_max = id_min;
658 template.sub.eth.flags.dot1ad = 1;
659 error = parse_vlan_sub_interfaces (input, &template);
660 if (error)
661 goto done;
662 }
663 else if (unformat (input, "%d-%d", &id_min, &id_max))
664 {
665 template.sub.eth.flags.one_tag = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400666 template.sub.eth.flags.exact_match = 1;
667 if (id_min > id_max)
668 goto id_error;
669 }
670 else if (unformat (input, "%d", &id_min))
671 {
672 id_max = id_min;
673 template.sub.eth.flags.one_tag = 1;
674 template.sub.eth.outer_vlan_id = id_min;
675 template.sub.eth.flags.exact_match = 1;
676 }
677 else
678 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700679 id_error:
680 error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'",
681 format_unformat_error, input);
682 goto done;
Dave Barachba868bb2016-08-08 09:51:21 -0400683 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700684
685 hi = vnet_get_hw_interface (vnm, hw_if_index);
John Lobcebbb92016-04-05 15:47:43 -0400686
Dave Barachba868bb2016-08-08 09:51:21 -0400687 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
688 {
689 error =
690 clib_error_return (0,
691 "not allowed as %v belong to a BondEthernet interface",
692 hi->name);
693 goto done;
694 }
John Lobcebbb92016-04-05 15:47:43 -0400695
Ed Warnickecb9cada2015-12-08 15:45:58 -0700696 for (id = id_min; id <= id_max; id++)
697 {
Dave Barachba868bb2016-08-08 09:51:21 -0400698 uword *p;
699 vnet_interface_main_t *im = &vnm->interface_main;
700 u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id;
701 u64 *kp;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700702
703 p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key);
704 if (p)
Dave Barachba868bb2016-08-08 09:51:21 -0400705 {
706 if (CLIB_DEBUG > 0)
707 clib_warning ("sup sw_if_index %d, sub id %d already exists\n",
708 hi->sw_if_index, id);
709 continue;
710 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700711
712 kp = clib_mem_alloc (sizeof (*kp));
713 *kp = sup_and_sub_key;
714
715 template.type = VNET_SW_INTERFACE_TYPE_SUB;
Eyal Baric5b13602016-11-24 19:42:43 +0200716 template.flood_class = VNET_FLOOD_CLASS_NORMAL;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700717 template.sup_sw_if_index = hi->sw_if_index;
718 template.sub.id = id;
Eyal Baria4509cf2016-09-26 09:24:09 +0300719 if (id_min < id_max)
720 template.sub.eth.outer_vlan_id = id;
721
Ed Warnickecb9cada2015-12-08 15:45:58 -0700722 error = vnet_create_sw_interface (vnm, &template, &sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400723 if (error)
724 goto done;
Dave Barach16ad6ae2016-07-28 17:55:30 -0400725
Ed Warnickecb9cada2015-12-08 15:45:58 -0700726 hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index);
727 hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400728 vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name,
729 vnet_get_main (), sw_if_index);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700730 }
731
Dave Barachba868bb2016-08-08 09:51:21 -0400732done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700733 return error;
734}
735
Dave Barachba868bb2016-08-08 09:51:21 -0400736/* *INDENT-OFF* */
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700737/*?
738 * Create vlan subinterfaces
739 *
740 * @cliexpar
741 * @cliexstart{create sub-interfaces}
742 *
743 * To create a vlan subinterface 11 to process packets on 802.1q VLAN id 11, use:
744 *
745 * vpp# create sub GigabitEthernet2/0/0 11
746 *
747 * This shorthand is equivalent to:
748 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 11 exact-match
749 *
750 * You can specify a subinterface number that is different from the vlan id:
751 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100
752 *
753 * You can create qinq and q-in-any interfaces:
754 * vpp# create sub GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200
755 * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any
756 *
757 * You can also create dot1ad interfaces:
758 * vpp# create sub GigabitEthernet2/0/0 11 dot1ad 11
759 * vpp# create sub GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q 200
760 *
761 * Subinterfaces can be configured as either exact-match or non-exact match.
762 * Non-exact match is the CLI default. If exact-match is specified,
763 * packets must have the same number of vlan tags as the configuration.
764 * For non-exact-match, packets must at least that number of tags.
765 * L3 (routed) interfaces must be configured as exact-match.
766 * L2 interfaces are typically configured as non-exact-match.
767 *
768 * For example, a packet with outer vlan 100 and inner 200 would match this interface:
769 * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100
770 *
771 * but would not match this interface:
772 * vpp# create sub GigabitEthernet2/0/0 5 dot1q 100 exact-match
773 *
774 * There are two special subinterfaces that can be configured. Subinterface untagged has no vlan tags:
775 * vpp# create sub GigabitEthernet2/0/0 5 untagged
776 *
777 * The subinterface default matches any packet that does not match any other subinterface:
778 * vpp# create sub GigabitEthernet2/0/0 7 default
779 * @cliexend
780 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700781VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = {
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700782 .path = "create sub-interfaces",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700783 .short_help = "create sub-interfaces <nn>[-<nn>] [dot1q|dot1ad|default|untagged]",
784 .function = create_sub_interfaces,
785};
Dave Barachba868bb2016-08-08 09:51:21 -0400786/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700787
788static clib_error_t *
789set_state (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400790 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700791{
Dave Barachba868bb2016-08-08 09:51:21 -0400792 vnet_main_t *vnm = vnet_get_main ();
793 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700794 u32 sw_if_index, flags;
795
796 sw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400797 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700798 {
799 error = clib_error_return (0, "unknown interface `%U'",
800 format_unformat_error, input);
801 goto done;
802 }
803
Dave Barachba868bb2016-08-08 09:51:21 -0400804 if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700805 {
806 error = clib_error_return (0, "unknown flags `%U'",
807 format_unformat_error, input);
808 goto done;
809 }
810
811 error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags);
812 if (error)
813 goto done;
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
Dave Barachba868bb2016-08-08 09:51:21 -0400820/* *INDENT-OFF* */
Keith Burns (alagalah)6ef7bb92016-09-10 14:55:04 -0700821/*?
822 * Interface admin up/down
823 *
824 * @cliexpar
825 * @cliexstart{set interface state}
826 * vpp# set interface state GigabitEthernet2/0/0 up
827 * vpp# set interface state GigabitEthernet2/0/0 down
828 * @cliexend
829 ?*/
Ed Warnickecb9cada2015-12-08 15:45:58 -0700830VLIB_CLI_COMMAND (set_state_command, static) = {
831 .path = "set interface state",
Ray Kinsella3ef16712017-04-27 09:57:00 +0100832 .short_help = "set interface state <if-name> [up|down|punt|enable]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700833 .function = set_state,
834};
Dave Barachba868bb2016-08-08 09:51:21 -0400835/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700836
837static clib_error_t *
838set_unnumbered (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400839 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700840{
Dave Barachba868bb2016-08-08 09:51:21 -0400841 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700842 u32 unnumbered_sw_if_index;
843 u32 inherit_from_sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400844 vnet_sw_interface_t *si;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700845 int is_set = 0;
846 int is_del = 0;
Neale Ranns898273f2017-03-18 02:57:38 -0700847 u32 was_unnum;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700848
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700849 if (unformat (input, "%U use %U",
850 unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index,
851 unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index))
852 is_set = 1;
853 else if (unformat (input, "del %U",
854 unformat_vnet_sw_interface, vnm,
855 &unnumbered_sw_if_index))
856 is_del = 1;
857 else
858 return clib_error_return (0, "parse error '%U'",
859 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700860
861 si = vnet_get_sw_interface (vnm, unnumbered_sw_if_index);
Neale Ranns898273f2017-03-18 02:57:38 -0700862 was_unnum = (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED);
863
Dave Barachba868bb2016-08-08 09:51:21 -0400864 if (is_del)
865 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700866 si->flags &= ~(VNET_SW_INTERFACE_FLAG_UNNUMBERED);
Dave Barachba868bb2016-08-08 09:51:21 -0400867 si->unnumbered_sw_if_index = (u32) ~ 0;
Neale Ranns898273f2017-03-18 02:57:38 -0700868
Neale Ranns4b919a52017-03-11 05:55:21 -0800869 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
870 [unnumbered_sw_if_index] = ~0;
871 ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
872 [unnumbered_sw_if_index] = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400873 }
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700874 else if (is_set)
Dave Barachba868bb2016-08-08 09:51:21 -0400875 {
Ed Warnickecb9cada2015-12-08 15:45:58 -0700876 si->flags |= VNET_SW_INTERFACE_FLAG_UNNUMBERED;
877 si->unnumbered_sw_if_index = inherit_from_sw_if_index;
Neale Ranns898273f2017-03-18 02:57:38 -0700878
Neale Ranns4b919a52017-03-11 05:55:21 -0800879 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
880 [unnumbered_sw_if_index] =
881 ip4_main.lookup_main.if_address_pool_index_by_sw_if_index
882 [inherit_from_sw_if_index];
883 ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
884 [unnumbered_sw_if_index] =
885 ip6_main.lookup_main.if_address_pool_index_by_sw_if_index
886 [inherit_from_sw_if_index];
Dave Barachba868bb2016-08-08 09:51:21 -0400887 }
Neale Ranns898273f2017-03-18 02:57:38 -0700888
889 if (was_unnum != (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED))
890 {
891 ip4_sw_interface_enable_disable (unnumbered_sw_if_index, !is_del);
892 ip6_sw_interface_enable_disable (unnumbered_sw_if_index, !is_del);
893 }
Dave Barachba868bb2016-08-08 09:51:21 -0400894
Ed Warnickecb9cada2015-12-08 15:45:58 -0700895 return 0;
896}
897
Dave Barachba868bb2016-08-08 09:51:21 -0400898/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700899VLIB_CLI_COMMAND (set_unnumbered_command, static) = {
900 .path = "set interface unnumbered",
Igor Mikhailov (imichail)ab3e42b2016-09-25 15:11:53 -0700901 .short_help = "set interface unnumbered [<intfc> use <intfc> | del <intfc>]",
Ed Warnickecb9cada2015-12-08 15:45:58 -0700902 .function = set_unnumbered,
903};
Dave Barachba868bb2016-08-08 09:51:21 -0400904/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700905
906
907
908static clib_error_t *
909set_hw_class (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400910 unformat_input_t * input, vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700911{
Dave Barachba868bb2016-08-08 09:51:21 -0400912 vnet_main_t *vnm = vnet_get_main ();
913 vnet_interface_main_t *im = &vnm->interface_main;
914 clib_error_t *error;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700915 u32 hw_if_index, hw_class_index;
916
917 hw_if_index = ~0;
Dave Barachba868bb2016-08-08 09:51:21 -0400918 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700919 {
920 error = clib_error_return (0, "unknown hardware interface `%U'",
921 format_unformat_error, input);
922 goto done;
923 }
924
Dave Barachba868bb2016-08-08 09:51:21 -0400925 if (!unformat_user (input, unformat_hash_string,
926 im->hw_interface_class_by_name, &hw_class_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700927 {
928 error = clib_error_return (0, "unknown hardware class `%U'",
929 format_unformat_error, input);
930 goto done;
931 }
932
933 error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index);
934 if (error)
935 goto done;
936
Dave Barachba868bb2016-08-08 09:51:21 -0400937done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700938 return error;
939}
940
Dave Barachba868bb2016-08-08 09:51:21 -0400941/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700942VLIB_CLI_COMMAND (set_hw_class_command, static) = {
943 .path = "set interface hw-class",
944 .short_help = "Set interface hardware class",
945 .function = set_hw_class,
946};
Dave Barachba868bb2016-08-08 09:51:21 -0400947/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700948
Dave Barachba868bb2016-08-08 09:51:21 -0400949static clib_error_t *
950vnet_interface_cli_init (vlib_main_t * vm)
951{
952 return 0;
953}
Ed Warnickecb9cada2015-12-08 15:45:58 -0700954
955VLIB_INIT_FUNCTION (vnet_interface_cli_init);
956
Dave Barachba868bb2016-08-08 09:51:21 -0400957static clib_error_t *
Ed Warnickecb9cada2015-12-08 15:45:58 -0700958renumber_interface_command_fn (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -0400959 unformat_input_t * input,
960 vlib_cli_command_t * cmd)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700961{
962 u32 hw_if_index;
963 u32 new_dev_instance;
Dave Barachba868bb2016-08-08 09:51:21 -0400964 vnet_main_t *vnm = vnet_get_main ();
Ed Warnickecb9cada2015-12-08 15:45:58 -0700965 int rv;
966
Dave Barachba868bb2016-08-08 09:51:21 -0400967 if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700968 return clib_error_return (0, "unknown hardware interface `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -0400969 format_unformat_error, input);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700970
Dave Barachba868bb2016-08-08 09:51:21 -0400971 if (!unformat (input, "%d", &new_dev_instance))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700972 return clib_error_return (0, "new dev instance missing");
973
974 rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance);
975
976 switch (rv)
977 {
978 case 0:
979 break;
980
981 default:
982 return clib_error_return (0, "vnet_interface_name_renumber returned %d",
Dave Barachba868bb2016-08-08 09:51:21 -0400983 rv);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700984
985 }
986
987 return 0;
988}
989
990
Dave Barachba868bb2016-08-08 09:51:21 -0400991/* *INDENT-OFF* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700992VLIB_CLI_COMMAND (renumber_interface_command, static) = {
993 .path = "renumber interface",
994 .short_help = "renumber interface <if-name> <new-dev-instance>",
995 .function = renumber_interface_command_fn,
996};
Dave Barachba868bb2016-08-08 09:51:21 -0400997/* *INDENT-ON* */
Ed Warnickecb9cada2015-12-08 15:45:58 -0700998
Damjan Marion8358ff92016-04-15 14:26:00 +0200999static clib_error_t *
1000promiscuous_cmd (vlib_main_t * vm,
Dave Barachba868bb2016-08-08 09:51:21 -04001001 unformat_input_t * input, vlib_cli_command_t * cmd)
Damjan Marion8358ff92016-04-15 14:26:00 +02001002{
Dave Barachba868bb2016-08-08 09:51:21 -04001003 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001004 u32 hw_if_index;
1005 u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL;
Dave Barachba868bb2016-08-08 09:51:21 -04001006 ethernet_main_t *em = &ethernet_main;
1007 ethernet_interface_t *eif;
Damjan Marion8358ff92016-04-15 14:26:00 +02001008
1009 if (unformat (input, "on %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001010 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001011 ;
1012 else if (unformat (input, "off %U",
Dave Barachba868bb2016-08-08 09:51:21 -04001013 unformat_ethernet_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001014 flags = 0;
1015 else
1016 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001017 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001018
1019 eif = ethernet_get_interface (em, hw_if_index);
1020 if (!eif)
1021 return clib_error_return (0, "not supported");
1022
1023 ethernet_set_flags (vnm, hw_if_index, flags);
1024 return 0;
1025}
1026
Dave Barachba868bb2016-08-08 09:51:21 -04001027/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001028VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = {
1029 .path = "set interface promiscuous",
1030 .short_help = "set interface promiscuous [on | off] <intfc>",
1031 .function = promiscuous_cmd,
1032};
Dave Barachba868bb2016-08-08 09:51:21 -04001033/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001034
1035static clib_error_t *
1036mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1037{
Dave Barachba868bb2016-08-08 09:51:21 -04001038 vnet_main_t *vnm = vnet_get_main ();
Damjan Marion8358ff92016-04-15 14:26:00 +02001039 u32 hw_if_index, mtu;
1040 u32 flags = ETHERNET_INTERFACE_FLAG_MTU;
Dave Barachba868bb2016-08-08 09:51:21 -04001041 ethernet_main_t *em = &ethernet_main;
Damjan Marion8358ff92016-04-15 14:26:00 +02001042
1043 if (unformat (input, "%d %U", &mtu,
Dave Barachba868bb2016-08-08 09:51:21 -04001044 unformat_vnet_hw_interface, vnm, &hw_if_index))
Damjan Marion8358ff92016-04-15 14:26:00 +02001045 {
Dave Barachba868bb2016-08-08 09:51:21 -04001046 vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index);
1047 ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index);
Damjan Marion8358ff92016-04-15 14:26:00 +02001048
1049 if (!eif)
Dave Barachba868bb2016-08-08 09:51:21 -04001050 return clib_error_return (0, "not supported");
Damjan Marion8358ff92016-04-15 14:26:00 +02001051
Mohsin Kazmif2ba9aa2016-04-24 18:53:42 +02001052 if (mtu < hi->min_supported_packet_bytes)
Damjan Marion8358ff92016-04-15 14:26:00 +02001053 return clib_error_return (0, "Invalid mtu (%d): "
1054 "must be >= min pkt bytes (%d)", mtu,
Mohsin Kazmif2ba9aa2016-04-24 18:53:42 +02001055 hi->min_supported_packet_bytes);
Damjan Marion8358ff92016-04-15 14:26:00 +02001056
Mohsin Kazmif2ba9aa2016-04-24 18:53:42 +02001057 if (mtu > hi->max_supported_packet_bytes)
1058 return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu,
Dave Barachba868bb2016-08-08 09:51:21 -04001059 hi->max_supported_packet_bytes);
Damjan Marion8358ff92016-04-15 14:26:00 +02001060
1061 if (hi->max_packet_bytes != mtu)
1062 {
1063 hi->max_packet_bytes = mtu;
1064 ethernet_set_flags (vnm, hw_if_index, flags);
1065 }
1066 }
1067 else
1068 return clib_error_return (0, "unknown input `%U'",
Dave Barachba868bb2016-08-08 09:51:21 -04001069 format_unformat_error, input);
Damjan Marion8358ff92016-04-15 14:26:00 +02001070 return 0;
1071}
1072
Dave Barachba868bb2016-08-08 09:51:21 -04001073/* *INDENT-OFF* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001074VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = {
1075 .path = "set interface mtu",
Mohsin Kazmif2ba9aa2016-04-24 18:53:42 +02001076 .short_help = "set interface mtu <value> <intfc>",
Damjan Marion8358ff92016-04-15 14:26:00 +02001077 .function = mtu_cmd,
1078};
Dave Barachba868bb2016-08-08 09:51:21 -04001079/* *INDENT-ON* */
Damjan Marion8358ff92016-04-15 14:26:00 +02001080
Pavel Kotucekc631f2d2016-09-26 10:40:02 +02001081static clib_error_t *
1082set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input,
1083 vlib_cli_command_t * cmd)
1084{
1085 vnet_main_t *vnm = vnet_get_main ();
1086 clib_error_t *error = 0;
1087 u32 sw_if_index = ~0;
1088 u64 mac = 0;
1089
1090 if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index))
1091 {
1092 error = clib_error_return (0, "unknown interface `%U'",
1093 format_unformat_error, input);
1094 goto done;
1095 }
1096 if (!unformat_user (input, unformat_ethernet_address, &mac))
1097 {
1098 error = clib_error_return (0, "expected mac address `%U'",
1099 format_unformat_error, input);
1100 goto done;
1101 }
1102 error = vnet_hw_interface_change_mac_address (vnm, sw_if_index, mac);
1103done:
1104 return error;
1105}
1106
1107/*?
1108 * The '<em>set interface mac address </em>' command allows to set MAC address of given interface.
1109 * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address
1110 * change are changes of MAC addresses in FIB tables (ipv4 and ipv6).
1111 *
1112 * @cliexpar
1113 * @parblock
1114 * Example of how to change MAC Address of interface:
1115 * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01}
1116 * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02}
1117 * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03}
1118 * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04}
1119 * @endparblock
1120?*/
1121/* *INDENT-OFF* */
1122VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = {
1123 .path = "set interface mac address",
1124 .short_help = "set interface mac address <intfc> <mac-address>",
1125 .function = set_interface_mac_address,
1126};
1127/* *INDENT-ON* */
1128
Dave Barach7be864a2016-11-28 11:41:35 -05001129static clib_error_t *
1130set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd)
1131{
1132 vnet_main_t *vnm = vnet_get_main ();
1133 u32 sw_if_index = ~0;
1134 u8 *tag = 0;
1135
1136 if (!unformat (input, "%U %s", unformat_vnet_sw_interface,
1137 vnm, &sw_if_index, &tag))
1138 return clib_error_return (0, "unknown input `%U'",
1139 format_unformat_error, input);
1140
1141 vnet_set_sw_interface_tag (vnm, tag, sw_if_index);
1142
1143 return 0;
1144}
1145
1146/* *INDENT-OFF* */
1147VLIB_CLI_COMMAND (set_tag_command, static) = {
1148 .path = "set interface tag",
1149 .short_help = "set interface tag <intfc> <tag>",
1150 .function = set_tag,
1151};
1152/* *INDENT-ON* */
1153
1154static clib_error_t *
1155clear_tag (vlib_main_t * vm, unformat_input_t * input,
1156 vlib_cli_command_t * cmd)
1157{
1158 vnet_main_t *vnm = vnet_get_main ();
1159 u32 sw_if_index = ~0;
1160
1161 if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
1162 return clib_error_return (0, "unknown input `%U'",
1163 format_unformat_error, input);
1164
1165 vnet_clear_sw_interface_tag (vnm, sw_if_index);
1166
1167 return 0;
1168}
1169
1170/* *INDENT-OFF* */
1171VLIB_CLI_COMMAND (clear_tag_command, static) = {
1172 .path = "clear interface tag",
1173 .short_help = "clear interface tag <intfc>",
1174 .function = clear_tag,
1175};
1176/* *INDENT-ON* */
1177
Damjan Marion44036902017-04-28 12:29:15 +02001178static clib_error_t *
1179set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input,
1180 vlib_cli_command_t * cmd)
1181{
1182 clib_error_t *error = 0;
1183 unformat_input_t _line_input, *line_input = &_line_input;
1184 vnet_main_t *vnm = vnet_get_main ();
1185 vnet_hw_interface_t *hw;
1186 u32 hw_if_index = (u32) ~ 0;
1187 u32 queue_id = (u32) ~ 0;
1188 vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN;
1189 int i, rv = 0;
Dave Barach7be864a2016-11-28 11:41:35 -05001190
Damjan Marion44036902017-04-28 12:29:15 +02001191 if (!unformat_user (input, unformat_line_input, line_input))
1192 return 0;
1193
1194 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1195 {
1196 if (unformat
1197 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1198 ;
1199 else if (unformat (line_input, "queue %d", &queue_id))
1200 ;
1201 else if (unformat (line_input, "polling"))
1202 mode = VNET_HW_INTERFACE_RX_MODE_POLLING;
1203 else if (unformat (line_input, "interrupt"))
1204 mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT;
1205 else if (unformat (line_input, "adaptive"))
1206 mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE;
1207 else
1208 {
1209 error = clib_error_return (0, "parse error: '%U'",
1210 format_unformat_error, line_input);
1211 unformat_free (line_input);
1212 return error;
1213 }
1214 }
1215
1216 unformat_free (line_input);
1217
1218 if (hw_if_index == (u32) ~ 0)
1219 return clib_error_return (0, "please specify valid interface name");
1220
1221 if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN)
1222 return clib_error_return (0, "please specify valid rx-mode");
1223
1224 hw = vnet_get_hw_interface (vnm, hw_if_index);
1225
1226 if (queue_id == ~0)
1227 for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++)
1228 {
1229 rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, i, mode);
1230 if (rv)
1231 goto error;
1232 }
1233 else
1234 rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1235
1236 if (rv)
1237 goto error;
1238
1239 return 0;
1240
1241error:
1242 if (rv == VNET_API_ERROR_UNSUPPORTED)
1243 return clib_error_return (0, "unsupported");
1244
1245 if (rv == VNET_API_ERROR_INVALID_INTERFACE)
1246 return clib_error_return (0, "invalid interfaace");
1247
1248 return clib_error_return (0, "unknown error");
1249}
1250
1251/*?
1252 * This command is used to assign a given interface, and optionally a
1253 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1254 * it defaults to 0.
1255 *
1256 * @cliexpar
1257 * Example of how to display the interface placement:
1258 * @cliexstart{show interface rx-placement}
1259 * Thread 1 (vpp_wk_0):
1260 * GigabitEthernet0/8/0 queue 0
1261 * GigabitEthernet0/9/0 queue 0
1262 * Thread 2 (vpp_wk_1):
1263 * GigabitEthernet0/8/0 queue 1
1264 * GigabitEthernet0/9/0 queue 1
1265 * @cliexend
1266 * Example of how to assign a interface and queue to a thread:
1267 * @cliexcmd{set interface placement GigabitEthernet0/8/0 queue 1 thread 1}
1268?*/
1269/* *INDENT-OFF* */
1270VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = {
1271 .path = "set interface rx-mode",
1272 .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]",
1273 .function = set_interface_rx_mode,
1274};
1275/* *INDENT-ON* */
1276
1277static clib_error_t *
1278show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input,
1279 vlib_cli_command_t * cmd)
1280{
1281 u8 *s = 0;
1282 vnet_main_t *vnm = vnet_get_main ();
1283 vnet_device_input_runtime_t *rt;
1284 vnet_device_and_queue_t *dq;
1285 vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input");
1286 uword si;
1287 int index = 0;
1288
1289 /* *INDENT-OFF* */
1290 foreach_vlib_main (({
1291 clib_bitmap_foreach (si, pn->sibling_bitmap,
1292 ({
1293 rt = vlib_node_get_runtime_data (this_vlib_main, si);
1294
1295 if (vec_len (rt->devices_and_queues))
1296 s = format (s, " node %U:\n", format_vlib_node_name, vm, si);
1297
1298 vec_foreach (dq, rt->devices_and_queues)
1299 {
1300 s = format (s, " %U queue %u (%U)\n",
1301 format_vnet_sw_if_index_name, vnm, dq->hw_if_index,
1302 dq->queue_id,
1303 format_vnet_hw_interface_rx_mode, dq->mode);
1304 }
1305 }));
1306 if (vec_len (s) > 0)
1307 {
1308 vlib_cli_output(vm, "Thread %u (%v):\n%v", index,
1309 vlib_worker_threads[index].name, s);
1310 vec_reset_length (s);
1311 }
1312 index++;
1313 }));
1314 /* *INDENT-ON* */
1315
1316 vec_free (s);
1317 return 0;
1318}
1319
1320/* *INDENT-OFF* */
1321VLIB_CLI_COMMAND (show_interface_rx_placement, static) = {
1322 .path = "show interface rx-placement",
1323 .short_help = "show interface rx-placement",
1324 .function = show_interface_rx_placement_fn,
1325};
1326/* *INDENT-ON* */
1327
1328static clib_error_t *
1329set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input,
1330 vlib_cli_command_t * cmd)
1331{
1332 clib_error_t *error = 0;
1333 unformat_input_t _line_input, *line_input = &_line_input;
1334 vnet_main_t *vnm = vnet_get_main ();
1335 vnet_device_main_t *vdm = &vnet_device_main;
1336 vnet_hw_interface_rx_mode mode;
1337 u32 hw_if_index = (u32) ~ 0;
1338 u32 queue_id = (u32) 0;
1339 u32 thread_index = (u32) ~ 0;
1340 int rv;
1341
1342 if (!unformat_user (input, unformat_line_input, line_input))
1343 return 0;
1344
1345 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
1346 {
1347 if (unformat
1348 (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
1349 ;
1350 else if (unformat (line_input, "queue %d", &queue_id))
1351 ;
1352 else if (unformat (line_input, "main", &thread_index))
1353 thread_index = 0;
1354 else if (unformat (line_input, "worker %d", &thread_index))
1355 thread_index += vdm->first_worker_thread_index;
1356 else
1357 {
1358 error = clib_error_return (0, "parse error: '%U'",
1359 format_unformat_error, line_input);
1360 unformat_free (line_input);
1361 return error;
1362 }
1363 }
1364
1365 unformat_free (line_input);
1366
1367 if (hw_if_index == (u32) ~ 0)
1368 return clib_error_return (0, "please specify valid interface name");
1369
1370 if (thread_index > vdm->last_worker_thread_index)
1371 return clib_error_return (0,
1372 "please specify valid worker thread or main");
1373
1374 rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode);
1375
1376 if (rv)
1377 return clib_error_return (0, "not found");
1378
1379 rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id);
1380
1381 if (rv)
1382 return clib_error_return (0, "not found");
1383
1384 vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id,
1385 thread_index);
1386 vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode);
1387
1388 return 0;
1389}
1390
1391/*?
1392 * This command is used to assign a given interface, and optionally a
1393 * given queue, to a different thread. If the '<em>queue</em>' is not provided,
1394 * it defaults to 0.
1395 *
1396 * @cliexpar
1397 * Example of how to display the interface placement:
1398 * @cliexstart{show interface placement}
1399 * Thread 1 (vpp_wk_0):
1400 * GigabitEthernet0/8/0 queue 0
1401 * GigabitEthernet0/9/0 queue 0
1402 * Thread 2 (vpp_wk_1):
1403 * GigabitEthernet0/8/0 queue 1
1404 * GigabitEthernet0/9/0 queue 1
1405 * @cliexend
1406 * Example of how to assign a interface and queue to a thread:
1407 * @cliexcmd{set interface placement GigabitEthernet0/8/0 queue 1 thread 1}
1408?*/
1409/* *INDENT-OFF* */
1410VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = {
1411 .path = "set interface rx-placement",
1412 .short_help = "set interface rx-placement <hw-interface> [queue <n>] [thread <n> | main]",
1413 .function = set_interface_rx_placement,
1414};
1415
1416/* *INDENT-ON* */
Dave Barachba868bb2016-08-08 09:51:21 -04001417/*
1418 * fd.io coding-style-patch-verification: ON
1419 *
1420 * Local Variables:
1421 * eval: (c-set-style "gnu")
1422 * End:
1423 */