Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 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 Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 40 | /** |
| 41 | * @file |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 42 | * @brief Interface CLI. |
| 43 | * |
| 44 | * Source code for several CLI interface commands. |
| 45 | * |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 46 | */ |
| 47 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | #include <vnet/vnet.h> |
| 49 | #include <vnet/ip/ip.h> |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 50 | #include <vppinfra/bitmap.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 51 | #include <vnet/fib/ip4_fib.h> |
| 52 | #include <vnet/fib/ip6_fib.h> |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 53 | #include <vnet/l2/l2_output.h> |
| 54 | #include <vnet/l2/l2_input.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 56 | static int |
| 57 | compare_interface_names (void *a1, void *a2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 59 | u32 *hi1 = a1; |
| 60 | u32 *hi2 = a2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 61 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 62 | return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static clib_error_t * |
| 66 | show_or_clear_hw_interfaces (vlib_main_t * vm, |
| 67 | unformat_input_t * input, |
| 68 | vlib_cli_command_t * cmd) |
| 69 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 70 | clib_error_t *error = 0; |
| 71 | vnet_main_t *vnm = vnet_get_main (); |
| 72 | vnet_interface_main_t *im = &vnm->interface_main; |
| 73 | vnet_hw_interface_t *hi; |
| 74 | u32 hw_if_index, *hw_if_indices = 0; |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 75 | int i, verbose = -1, is_show, show_bond = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 76 | |
| 77 | is_show = strstr (cmd->path, "show") != 0; |
| 78 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 79 | { |
| 80 | /* See if user wants to show a specific interface. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 81 | if (unformat |
| 82 | (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 83 | vec_add1 (hw_if_indices, hw_if_index); |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 84 | |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 85 | /* See if user wants to show an interface with a specific hw_if_index. */ |
| 86 | else if (unformat (input, "%u", &hw_if_index)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 87 | vec_add1 (hw_if_indices, hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | |
| 89 | else if (unformat (input, "verbose")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 90 | verbose = 1; /* this is also the default */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | |
| 92 | else if (unformat (input, "detail")) |
| 93 | verbose = 2; |
| 94 | |
| 95 | else if (unformat (input, "brief")) |
| 96 | verbose = 0; |
| 97 | |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 98 | else if (unformat (input, "bond")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 99 | { |
| 100 | show_bond = 1; |
| 101 | if (verbose < 0) |
| 102 | verbose = 0; /* default to brief for link bonding */ |
| 103 | } |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 104 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | else |
| 106 | { |
| 107 | error = clib_error_return (0, "unknown input `%U'", |
| 108 | format_unformat_error, input); |
| 109 | goto done; |
| 110 | } |
| 111 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 112 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | /* Gather interfaces. */ |
| 114 | if (vec_len (hw_if_indices) == 0) |
| 115 | pool_foreach (hi, im->hw_interfaces, |
| 116 | vec_add1 (hw_if_indices, hi - im->hw_interfaces)); |
| 117 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 118 | if (verbose < 0) |
| 119 | verbose = 1; /* default to verbose (except bond) */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 120 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | if (is_show) |
| 122 | { |
| 123 | /* Sort by name. */ |
| 124 | vec_sort_with_function (hw_if_indices, compare_interface_names); |
| 125 | |
| 126 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose); |
| 127 | for (i = 0; i < vec_len (hw_if_indices); i++) |
| 128 | { |
| 129 | hi = vnet_get_hw_interface (vnm, hw_if_indices[i]); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 130 | if (show_bond == 0) /* show all interfaces */ |
| 131 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, |
| 132 | hi, verbose); |
| 133 | else if ((hi->bond_info) && |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 134 | (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 135 | { /* show only bonded interface and all its slave interfaces */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 136 | int hw_idx; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 137 | vnet_hw_interface_t *shi; |
| 138 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 139 | hi, verbose); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 140 | |
| 141 | /* *INDENT-OFF* */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 142 | clib_bitmap_foreach (hw_idx, hi->bond_info, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 143 | ({ |
| 144 | shi = vnet_get_hw_interface(vnm, hw_idx); |
| 145 | vlib_cli_output (vm, "%U\n", |
| 146 | format_vnet_hw_interface, vnm, shi, verbose); |
| 147 | })); |
| 148 | /* *INDENT-ON* */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 149 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | for (i = 0; i < vec_len (hw_if_indices); i++) |
| 155 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 156 | vnet_device_class_t *dc; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 157 | |
| 158 | hi = vnet_get_hw_interface (vnm, hw_if_indices[i]); |
| 159 | dc = vec_elt_at_index (im->device_classes, hi->dev_class_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 160 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 161 | if (dc->clear_counters) |
| 162 | dc->clear_counters (hi->dev_instance); |
| 163 | } |
| 164 | } |
| 165 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 166 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 167 | vec_free (hw_if_indices); |
| 168 | return error; |
| 169 | } |
| 170 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 171 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 172 | * Display more detailed information about all or a list of given interfaces. |
| 173 | * The verboseness of the output can be controlled by the following optional |
| 174 | * parameters: |
| 175 | * - brief: Only show name, index and state (default for bonded interfaces). |
| 176 | * - verbose: Also display additional attributes (default for all other interfaces). |
| 177 | * - detail: Also display all remaining attributes and extended statistics. |
| 178 | * |
| 179 | * To limit the output of the command to bonded interfaces and their slave |
| 180 | * interfaces, use the '<em>bond</em>' optional parameter. |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 181 | * |
| 182 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 183 | * Example of how to display default data for all interfaces: |
| 184 | * @cliexstart{show hardware-interfaces} |
| 185 | * Name Idx Link Hardware |
| 186 | * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0 |
| 187 | * Ethernet address ec:f4:bb:c0:bc:fc |
| 188 | * Intel e1000 |
| 189 | * carrier up full duplex speed 1000 mtu 9216 |
| 190 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 191 | * cpu socket 0 |
| 192 | * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1 |
| 193 | * Ethernet address ec:f4:bb:c0:bc:fd |
| 194 | * Intel e1000 |
| 195 | * carrier up full duplex speed 1000 mtu 9216 |
| 196 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 197 | * cpu socket 0 |
| 198 | * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0 |
| 199 | * Ethernet address 02:fe:a5:a9:8b:8e |
| 200 | * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1 |
| 201 | * Ethernet address 02:fe:c0:4e:3b:b0 |
| 202 | * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2 |
| 203 | * Ethernet address 02:fe:1f:73:92:81 |
| 204 | * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3 |
| 205 | * Ethernet address 02:fe:f2:25:c4:68 |
| 206 | * local0 0 down local0 |
| 207 | * local |
| 208 | * @cliexend |
| 209 | * Example of how to display '<em>verbose</em>' data for an interface by name and |
| 210 | * software index (where 2 is the software index): |
| 211 | * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose} |
| 212 | * Name Idx Link Hardware |
| 213 | * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0 |
| 214 | * Ethernet address ec:f4:bb:c0:bc:fc |
| 215 | * Intel e1000 |
| 216 | * carrier up full duplex speed 1000 mtu 9216 |
| 217 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 218 | * cpu socket 0 |
| 219 | * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1 |
| 220 | * Ethernet address ec:f4:bb:c0:bc:fd |
| 221 | * Intel e1000 |
| 222 | * carrier up full duplex speed 1000 mtu 9216 |
| 223 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 224 | * cpu socket 0 |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 225 | * @cliexend |
| 226 | ?*/ |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 227 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = { |
| 229 | .path = "show hardware-interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 230 | .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] " |
| 231 | "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 232 | .function = show_or_clear_hw_interfaces, |
| 233 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 234 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 235 | |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 236 | |
| 237 | /*? |
| 238 | * Clear the extended statistics for all or a list of given interfaces |
| 239 | * (statistics associated with the '<em>show hardware-interfaces</em>' command). |
| 240 | * |
| 241 | * @cliexpar |
| 242 | * Example of how to clear the extended statistics for all interfaces: |
| 243 | * @cliexcmd{clear hardware-interfaces} |
| 244 | * Example of how to clear the extended statistics for an interface by |
| 245 | * name and software index (where 2 is the software index): |
| 246 | * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2} |
| 247 | ?*/ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 248 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 249 | VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = { |
| 250 | .path = "clear hardware-interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 251 | .short_help = "clear hardware-interfaces " |
| 252 | "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 253 | .function = show_or_clear_hw_interfaces, |
| 254 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 255 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 256 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 257 | static int |
| 258 | sw_interface_name_compare (void *a1, void *a2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 259 | { |
| 260 | vnet_sw_interface_t *si1 = a1; |
| 261 | vnet_sw_interface_t *si2 = a2; |
| 262 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 263 | return vnet_sw_interface_compare (vnet_get_main (), |
| 264 | si1->sw_if_index, si2->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static clib_error_t * |
| 268 | show_sw_interfaces (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 269 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 270 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 271 | clib_error_t *error = 0; |
| 272 | vnet_main_t *vnm = vnet_get_main (); |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 273 | unformat_input_t _linput, *linput = &_linput; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 274 | vnet_interface_main_t *im = &vnm->interface_main; |
| 275 | vnet_sw_interface_t *si, *sorted_sis = 0; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 276 | u32 sw_if_index = ~(u32) 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 277 | u8 show_addresses = 0; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 278 | u8 show_features = 0; |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 279 | u8 show_tag = 0; |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 280 | int verbose = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 281 | |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 282 | /* |
| 283 | * Get a line of input. Won't work if the user typed |
| 284 | * "show interface" and nothing more. |
| 285 | */ |
| 286 | if (unformat_user (input, unformat_line_input, linput)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 287 | { |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 288 | while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 289 | { |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 290 | /* See if user wants to show specific interface */ |
| 291 | if (unformat |
| 292 | (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 293 | { |
| 294 | si = pool_elt_at_index (im->sw_interfaces, sw_if_index); |
| 295 | vec_add1 (sorted_sis, si[0]); |
| 296 | } |
| 297 | else if (unformat (linput, "address") || unformat (linput, "addr")) |
| 298 | show_addresses = 1; |
| 299 | else if (unformat (linput, "features") || unformat (linput, "feat")) |
| 300 | show_features = 1; |
| 301 | else if (unformat (linput, "tag")) |
| 302 | show_tag = 1; |
| 303 | else if (unformat (linput, "verbose")) |
| 304 | verbose = 1; |
| 305 | else |
| 306 | { |
| 307 | error = clib_error_return (0, "unknown input `%U'", |
| 308 | format_unformat_error, linput); |
| 309 | goto done; |
| 310 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 311 | } |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 312 | unformat_free (linput); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 313 | } |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 314 | if (show_features || show_tag) |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 315 | { |
| 316 | if (sw_if_index == ~(u32) 0) |
| 317 | return clib_error_return (0, "Interface not specified..."); |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 318 | } |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 319 | |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 320 | if (show_features) |
| 321 | { |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 322 | vnet_interface_features_show (vm, sw_if_index, verbose); |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 323 | |
| 324 | l2_input_config_t *l2_input = l2input_intf_config (sw_if_index); |
| 325 | u32 fb = l2_input->feature_bitmap; |
| 326 | /* intf input features are masked by bridge domain */ |
| 327 | if (l2_input->bridge) |
| 328 | fb &= l2input_bd_config (l2_input->bd_index)->feature_bitmap; |
| 329 | vlib_cli_output (vm, "\nl2-input:\n%U", format_l2_input_features, fb); |
| 330 | |
| 331 | l2_output_config_t *l2_output = l2output_intf_config (sw_if_index); |
| 332 | vlib_cli_output (vm, "\nl2-output:"); |
| 333 | if (l2_output->out_vtr_flag) |
| 334 | vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--"); |
| 335 | vlib_cli_output (vm, "%U", format_l2_output_features, |
| 336 | l2_output->feature_bitmap); |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 337 | return 0; |
| 338 | } |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 339 | if (show_tag) |
| 340 | { |
| 341 | u8 *tag; |
| 342 | tag = vnet_get_sw_interface_tag (vnm, sw_if_index); |
| 343 | vlib_cli_output (vm, "%U: %s", |
| 344 | format_vnet_sw_if_index_name, vnm, sw_if_index, |
| 345 | tag ? (char *) tag : "(none)"); |
| 346 | return 0; |
| 347 | } |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 348 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 349 | if (!show_addresses) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 350 | vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 351 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 352 | if (vec_len (sorted_sis) == 0) /* Get all interfaces */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 353 | { |
| 354 | /* Gather interfaces. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 355 | sorted_sis = |
| 356 | vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 357 | _vec_len (sorted_sis) = 0; |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 358 | /* *INDENT-OFF* */ |
| 359 | pool_foreach (si, im->sw_interfaces, |
| 360 | ({ |
| 361 | int visible = vnet_swif_is_api_visible (si); |
| 362 | if (visible) |
| 363 | vec_add1 (sorted_sis, si[0]);} |
| 364 | )); |
| 365 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 366 | /* Sort by name. */ |
| 367 | vec_sort_with_function (sorted_sis, sw_interface_name_compare); |
| 368 | } |
| 369 | |
| 370 | if (show_addresses) |
| 371 | { |
| 372 | vec_foreach (si, sorted_sis) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 373 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 374 | ip4_main_t *im4 = &ip4_main; |
| 375 | ip6_main_t *im6 = &ip6_main; |
| 376 | ip_lookup_main_t *lm4 = &im4->lookup_main; |
| 377 | ip_lookup_main_t *lm6 = &im6->lookup_main; |
| 378 | ip_interface_address_t *ia = 0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 379 | u32 fib_index4 = 0, fib_index6 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 381 | if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index) |
| 382 | fib_index4 = vec_elt (im4->fib_index_by_sw_if_index, |
| 383 | si->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 384 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 385 | if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index) |
| 386 | fib_index6 = vec_elt (im6->fib_index_by_sw_if_index, |
| 387 | si->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 388 | |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 389 | ip4_fib_t *fib4 = ip4_fib_get (fib_index4); |
| 390 | ip6_fib_t *fib6 = ip6_fib_get (fib_index6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 391 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 392 | if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) |
| 393 | vlib_cli_output |
| 394 | (vm, "%U (%s): \n unnumbered, use %U", |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 395 | format_vnet_sw_if_index_name, vnm, si->sw_if_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 396 | (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn", |
| 397 | format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 398 | else |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 399 | vlib_cli_output |
| 400 | (vm, "%U (%s):", |
| 401 | format_vnet_sw_if_index_name, vnm, si->sw_if_index, |
| 402 | (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 403 | |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 404 | /* Display any L2 info */ |
| 405 | l2_input_config_t *l2_input = l2input_intf_config (si->sw_if_index); |
| 406 | if (l2_input->bridge) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 407 | { |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 408 | bd_main_t *bdm = &bd_main; |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 409 | u32 bd_id = l2input_main.bd_configs[l2_input->bd_index].bd_id; |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 410 | vlib_cli_output (vm, " L2 bridge bd-id %d idx %d shg %d %s", |
| 411 | bd_id, bd_find_index (bdm, bd_id), l2_input->shg, |
| 412 | l2_input->bvi ? "bvi" : " "); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 413 | } |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 414 | else if (l2_input->xconnect) |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 415 | vlib_cli_output (vm, " L2 xconnect %U", |
| 416 | format_vnet_sw_if_index_name, vnm, |
| 417 | l2_input->output_sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 418 | |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 419 | /* *INDENT-OFF* */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 420 | /* Display any IP4 addressing info */ |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 421 | foreach_ip_interface_address (lm4, ia, si->sw_if_index, |
| 422 | 1 /* honor unnumbered */, |
| 423 | ({ |
| 424 | ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia); |
| 425 | if (fib4->table_id) |
| 426 | vlib_cli_output (vm, " L3 %U/%d ip4 table-id %d fib-idx %d", |
| 427 | format_ip4_address, r4, ia->address_length, |
| 428 | fib4->table_id, |
| 429 | ip4_fib_index_from_table_id (fib4->table_id)); |
| 430 | else |
| 431 | vlib_cli_output (vm, " L3 %U/%d", |
| 432 | format_ip4_address, r4, ia->address_length); |
| 433 | })); |
| 434 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 435 | |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 436 | /* *INDENT-OFF* */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 437 | /* Display any IP6 addressing info */ |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 438 | foreach_ip_interface_address (lm6, ia, si->sw_if_index, |
| 439 | 1 /* honor unnumbered */, |
| 440 | ({ |
| 441 | ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia); |
| 442 | if (fib6->table_id) |
| 443 | vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d", |
| 444 | format_ip6_address, r6, ia->address_length, |
| 445 | fib6->table_id, |
| 446 | ip6_fib_index_from_table_id (fib6->table_id)); |
| 447 | else |
| 448 | vlib_cli_output (vm, " L3 %U/%d", |
| 449 | format_ip6_address, r6, ia->address_length); |
| 450 | })); |
| 451 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 452 | } |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 453 | } |
| 454 | |
| 455 | else |
| 456 | { |
| 457 | vec_foreach (si, sorted_sis) |
| 458 | { |
| 459 | vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si); |
| 460 | } |
| 461 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 462 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 463 | done: |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 464 | vec_free (sorted_sis); |
| 465 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 466 | } |
| 467 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 468 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 469 | VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = { |
Dave Barach | 13ad1f0 | 2017-03-26 19:36:18 -0400 | [diff] [blame] | 470 | .path = "show interface", |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 471 | .short_help = "show interface [address|addr|features|feat] [<interface> [<interface> [..]]] [verbose]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 472 | .function = show_sw_interfaces, |
| 473 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 474 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 475 | |
| 476 | /* Root of all interface commands. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 477 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 478 | VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = { |
| 479 | .path = "interface", |
| 480 | .short_help = "Interface commands", |
| 481 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 482 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 483 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 484 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 485 | VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = { |
| 486 | .path = "set interface", |
| 487 | .short_help = "Interface commands", |
| 488 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 489 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 490 | |
| 491 | static clib_error_t * |
| 492 | clear_interface_counters (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 493 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 494 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 495 | vnet_main_t *vnm = vnet_get_main (); |
| 496 | vnet_interface_main_t *im = &vnm->interface_main; |
| 497 | vlib_simple_counter_main_t *sm; |
| 498 | vlib_combined_counter_main_t *cm; |
| 499 | static vnet_main_t **my_vnet_mains; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 500 | int i, j, n_counters; |
| 501 | |
| 502 | vec_reset_length (my_vnet_mains); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 503 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 504 | for (i = 0; i < vec_len (vnet_mains); i++) |
| 505 | { |
| 506 | if (vnet_mains[i]) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 507 | vec_add1 (my_vnet_mains, vnet_mains[i]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | if (vec_len (vnet_mains) == 0) |
| 511 | vec_add1 (my_vnet_mains, vnm); |
| 512 | |
| 513 | n_counters = vec_len (im->combined_sw_if_counters); |
| 514 | |
| 515 | for (j = 0; j < n_counters; j++) |
| 516 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 517 | for (i = 0; i < vec_len (my_vnet_mains); i++) |
| 518 | { |
| 519 | im = &my_vnet_mains[i]->interface_main; |
| 520 | cm = im->combined_sw_if_counters + j; |
| 521 | vlib_clear_combined_counters (cm); |
| 522 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | n_counters = vec_len (im->sw_if_counters); |
| 526 | |
| 527 | for (j = 0; j < n_counters; j++) |
| 528 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 529 | for (i = 0; i < vec_len (my_vnet_mains); i++) |
| 530 | { |
| 531 | im = &my_vnet_mains[i]->interface_main; |
| 532 | sm = im->sw_if_counters + j; |
| 533 | vlib_clear_simple_counters (sm); |
| 534 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 535 | } |
| 536 | |
| 537 | return 0; |
| 538 | } |
| 539 | |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 540 | /*? |
| 541 | * Clear the statistics for all interfaces (statistics associated with the |
| 542 | * '<em>show interface</em>' command). |
| 543 | * |
| 544 | * @cliexpar |
| 545 | * Example of how to clear the statistics for all interfaces: |
| 546 | * @cliexcmd{clear interfaces} |
| 547 | ?*/ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 548 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 549 | VLIB_CLI_COMMAND (clear_interface_counters_command, static) = { |
| 550 | .path = "clear interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 551 | .short_help = "clear interfaces", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 552 | .function = clear_interface_counters, |
| 553 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 554 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 555 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 556 | /** |
| 557 | * Parse subinterface names. |
| 558 | * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 559 | * The following subinterface syntax is supported. The first two are for |
| 560 | * backwards compatability: |
| 561 | * |
| 562 | * <intf-name> <id> |
| 563 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 564 | * is a single dot1q vlan with vlan id <id> and exact-match semantics. |
| 565 | * |
| 566 | * <intf-name> <min_id>-<max_id> |
| 567 | * - a set of the above subinterfaces, repeating for each id |
| 568 | * in the range <min_id> to <max_id> |
| 569 | * |
| 570 | * In the following, exact-match semantics (i.e. the number of vlan tags on the |
| 571 | * packet must match the number of tags in the configuration) are used only if |
| 572 | * the keyword exact-match is present. Non-exact match is the default. |
| 573 | * |
| 574 | * <intf-name> <id> dot1q <outer_id> [exact-match] |
| 575 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 576 | * is a single dot1q vlan with vlan id <outer_id>. |
| 577 | * |
| 578 | * <intf-name> <id> dot1q any [exact-match] |
| 579 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 580 | * is a single dot1q vlan with any vlan id. |
| 581 | * |
| 582 | * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match] |
| 583 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 584 | * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id |
| 585 | * <inner_id>. |
| 586 | * |
| 587 | * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match] |
| 588 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 589 | * is a double dot1q vlan with outer vlan id <id> and any inner vlan id. |
| 590 | * |
| 591 | * <intf-name> <id> dot1q any inner-dot1q any [exact-match] |
| 592 | * |
| 593 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 594 | * is a double dot1q vlan with any outer vlan id and any inner vlan id. |
| 595 | * |
| 596 | * For each of the above CLI, there is a duplicate that uses the keyword |
| 597 | * "dot1ad" in place of the first "dot1q". These interfaces use ethertype |
| 598 | * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double- |
| 599 | * tagged packets the inner ethertype is always 0x8100. Also note that |
| 600 | * the dot1q and dot1ad naming spaces are independent, so it is legal to |
| 601 | * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example: |
| 602 | * |
| 603 | * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match] |
| 604 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 605 | * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan |
| 606 | * id <inner_id>. |
| 607 | * |
| 608 | * <intf-name> <id> untagged |
| 609 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 610 | * has no vlan tags. Only one can be specified per interface. |
| 611 | * |
| 612 | * <intf-name> <id> default |
| 613 | * - a subinterface with the name <intf-name>.<id>. This is associated |
| 614 | * with a packet that did not match any other configured subinterface |
| 615 | * on this interface. Only one can be specified per interface. |
| 616 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 617 | |
| 618 | static clib_error_t * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 619 | parse_vlan_sub_interfaces (unformat_input_t * input, |
| 620 | vnet_sw_interface_t * template) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 621 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 622 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 623 | u32 inner_vlan, outer_vlan; |
| 624 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 625 | if (unformat (input, "any inner-dot1q any")) |
| 626 | { |
| 627 | template->sub.eth.flags.two_tags = 1; |
| 628 | template->sub.eth.flags.outer_vlan_id_any = 1; |
| 629 | template->sub.eth.flags.inner_vlan_id_any = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 630 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 631 | else if (unformat (input, "any")) |
| 632 | { |
| 633 | template->sub.eth.flags.one_tag = 1; |
| 634 | template->sub.eth.flags.outer_vlan_id_any = 1; |
| 635 | } |
| 636 | else if (unformat (input, "%d inner-dot1q any", &outer_vlan)) |
| 637 | { |
| 638 | template->sub.eth.flags.two_tags = 1; |
| 639 | template->sub.eth.flags.inner_vlan_id_any = 1; |
| 640 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 641 | } |
| 642 | else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan)) |
| 643 | { |
| 644 | template->sub.eth.flags.two_tags = 1; |
| 645 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 646 | template->sub.eth.inner_vlan_id = inner_vlan; |
| 647 | } |
| 648 | else if (unformat (input, "%d", &outer_vlan)) |
| 649 | { |
| 650 | template->sub.eth.flags.one_tag = 1; |
| 651 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 652 | } |
| 653 | else |
| 654 | { |
| 655 | error = clib_error_return (0, "expected dot1q config, got `%U'", |
| 656 | format_unformat_error, input); |
| 657 | goto done; |
| 658 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 659 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 660 | if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 661 | { |
| 662 | if (unformat (input, "exact-match")) |
| 663 | { |
| 664 | template->sub.eth.flags.exact_match = 1; |
| 665 | } |
| 666 | } |
| 667 | |
| 668 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 669 | return error; |
| 670 | } |
| 671 | |
| 672 | static clib_error_t * |
| 673 | create_sub_interfaces (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 674 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 675 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 676 | vnet_main_t *vnm = vnet_get_main (); |
| 677 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 678 | u32 hw_if_index, sw_if_index; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 679 | vnet_hw_interface_t *hi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 680 | u32 id, id_min, id_max; |
| 681 | vnet_sw_interface_t template; |
| 682 | |
| 683 | hw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 684 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 685 | { |
| 686 | error = clib_error_return (0, "unknown interface `%U'", |
| 687 | format_unformat_error, input); |
| 688 | goto done; |
| 689 | } |
| 690 | |
| 691 | memset (&template, 0, sizeof (template)); |
| 692 | template.sub.eth.raw_flags = 0; |
| 693 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 694 | if (unformat (input, "%d default", &id_min)) |
| 695 | { |
| 696 | id_max = id_min; |
| 697 | template.sub.eth.flags.default_sub = 1; |
| 698 | } |
| 699 | else if (unformat (input, "%d untagged", &id_min)) |
| 700 | { |
| 701 | id_max = id_min; |
| 702 | template.sub.eth.flags.no_tags = 1; |
| 703 | template.sub.eth.flags.exact_match = 1; |
| 704 | } |
| 705 | else if (unformat (input, "%d dot1q", &id_min)) |
| 706 | { |
| 707 | /* parse dot1q config */ |
| 708 | id_max = id_min; |
| 709 | error = parse_vlan_sub_interfaces (input, &template); |
| 710 | if (error) |
| 711 | goto done; |
| 712 | } |
| 713 | else if (unformat (input, "%d dot1ad", &id_min)) |
| 714 | { |
| 715 | /* parse dot1ad config */ |
| 716 | id_max = id_min; |
| 717 | template.sub.eth.flags.dot1ad = 1; |
| 718 | error = parse_vlan_sub_interfaces (input, &template); |
| 719 | if (error) |
| 720 | goto done; |
| 721 | } |
| 722 | else if (unformat (input, "%d-%d", &id_min, &id_max)) |
| 723 | { |
| 724 | template.sub.eth.flags.one_tag = 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 725 | template.sub.eth.flags.exact_match = 1; |
| 726 | if (id_min > id_max) |
| 727 | goto id_error; |
| 728 | } |
| 729 | else if (unformat (input, "%d", &id_min)) |
| 730 | { |
| 731 | id_max = id_min; |
| 732 | template.sub.eth.flags.one_tag = 1; |
| 733 | template.sub.eth.outer_vlan_id = id_min; |
| 734 | template.sub.eth.flags.exact_match = 1; |
| 735 | } |
| 736 | else |
| 737 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 738 | id_error: |
| 739 | error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'", |
| 740 | format_unformat_error, input); |
| 741 | goto done; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 742 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 743 | |
| 744 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 745 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 746 | if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) |
| 747 | { |
| 748 | error = |
| 749 | clib_error_return (0, |
| 750 | "not allowed as %v belong to a BondEthernet interface", |
| 751 | hi->name); |
| 752 | goto done; |
| 753 | } |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 754 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 755 | for (id = id_min; id <= id_max; id++) |
| 756 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 757 | uword *p; |
| 758 | vnet_interface_main_t *im = &vnm->interface_main; |
| 759 | u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id; |
| 760 | u64 *kp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 761 | |
| 762 | p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key); |
| 763 | if (p) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 764 | { |
| 765 | if (CLIB_DEBUG > 0) |
| 766 | clib_warning ("sup sw_if_index %d, sub id %d already exists\n", |
| 767 | hi->sw_if_index, id); |
| 768 | continue; |
| 769 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 770 | |
| 771 | kp = clib_mem_alloc (sizeof (*kp)); |
| 772 | *kp = sup_and_sub_key; |
| 773 | |
| 774 | template.type = VNET_SW_INTERFACE_TYPE_SUB; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 775 | template.flood_class = VNET_FLOOD_CLASS_NORMAL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 776 | template.sup_sw_if_index = hi->sw_if_index; |
| 777 | template.sub.id = id; |
Eyal Bari | a4509cf | 2016-09-26 09:24:09 +0300 | [diff] [blame] | 778 | if (id_min < id_max) |
| 779 | template.sub.eth.outer_vlan_id = id; |
| 780 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 781 | error = vnet_create_sw_interface (vnm, &template, &sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 782 | if (error) |
| 783 | goto done; |
Dave Barach | 16ad6ae | 2016-07-28 17:55:30 -0400 | [diff] [blame] | 784 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 785 | hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index); |
| 786 | hash_set_mem (im->sw_if_index_by_sup_and_sub, kp, sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 787 | vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, |
| 788 | vnet_get_main (), sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 789 | } |
| 790 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 791 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 792 | return error; |
| 793 | } |
| 794 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 795 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 796 | * This command is used to add VLAN IDs to interfaces, also known as subinterfaces. |
| 797 | * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>' |
| 798 | * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is |
| 799 | * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different, |
| 800 | * but this is not recommended. |
| 801 | * |
| 802 | * This command has several variations: |
| 803 | * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to |
| 804 | * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>'). |
| 805 | * |
| 806 | * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the |
| 807 | * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not |
| 808 | * match any other subinterfaces should be sent to this subinterface. |
| 809 | * |
| 810 | * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the |
| 811 | * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent |
| 812 | * to this subinterface. |
| 813 | * |
| 814 | * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of |
| 815 | * subinterfaces to handle a range of VLAN IDs. |
| 816 | * |
| 817 | * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> - |
| 818 | * Use this command to specify the outer VLAN ID, to either be explicited or to make the |
| 819 | * VLAN ID different from the '<em>subId</em>'. |
| 820 | * |
| 821 | * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q |
| 822 | * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and |
| 823 | * the innner VLAN ID. |
| 824 | * |
| 825 | * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explictly entered, subinterfaces |
| 826 | * can be configured as either exact-match or non-exact match. Non-exact match is the CLI |
| 827 | * default. If '<em>exact-match</em>' is specified, packets must have the same number of |
| 828 | * VLAN tags as the configuration. For non-exact-match, packets must at least that number |
| 829 | * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are |
| 830 | * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT |
| 831 | * entered, then the default behavior is exact-match. |
| 832 | * |
| 833 | * Use the '<em>show interface</em>' command to display all subinterfaces. |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 834 | * |
| 835 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 836 | * @parblock |
| 837 | * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11: |
| 838 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 839 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 840 | * The previous example is shorthand and is equivalent to: |
| 841 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 11 exact-match} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 842 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 843 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 844 | * Example of how to create a subinterface number that is different from the VLAN ID: |
| 845 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 846 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 847 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 848 | * Examples of how to create q-in-q and q-in-any subinterfaces: |
| 849 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200} |
| 850 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1q 100 inner-dot1q any} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 851 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 852 | * Examples of how to create dot1ad interfaces: |
| 853 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11} |
| 854 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 12 dot1ad 100 inner-dot1q 200} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 855 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 856 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 857 | * Examples of '<em>exact-match</em>' versus non-exact match. A packet with |
| 858 | * outer VLAN 100 and inner VLAN 200 would match this interface, because the default |
| 859 | * is non-exact match: |
| 860 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 861 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 862 | * However, the same packet would NOT match this interface because '<em>exact-match</em>' |
| 863 | * is specified and only one VLAN is configured, but packet contains two VLANs: |
| 864 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100 exact-match} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 865 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 866 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 867 | * Example of how to created a subinterface to process untagged packets: |
| 868 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged} |
| 869 | * |
| 870 | * Example of how to created a subinterface to process any packet with a VLAN ID that |
| 871 | * does not match any other subinterface: |
| 872 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default} |
| 873 | * |
| 874 | * When subinterfaces are created, they are in the down state. Example of how to |
| 875 | * enable a newly created subinterface: |
| 876 | * @cliexcmd{set interface GigabitEthernet2/0/0.7 up} |
| 877 | * @endparblock |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 878 | ?*/ |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 879 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 880 | VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = { |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 881 | .path = "create sub-interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 882 | .short_help = "create sub-interfaces <interface> " |
| 883 | "{<subId> [default|untagged]} | " |
| 884 | "{<subId>-<subId>} | " |
| 885 | "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 886 | .function = create_sub_interfaces, |
| 887 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 888 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 889 | |
| 890 | static clib_error_t * |
| 891 | set_state (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 892 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 893 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 894 | vnet_main_t *vnm = vnet_get_main (); |
| 895 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 896 | u32 sw_if_index, flags; |
| 897 | |
| 898 | sw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 899 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 900 | { |
| 901 | error = clib_error_return (0, "unknown interface `%U'", |
| 902 | format_unformat_error, input); |
| 903 | goto done; |
| 904 | } |
| 905 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 906 | if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 907 | { |
| 908 | error = clib_error_return (0, "unknown flags `%U'", |
| 909 | format_unformat_error, input); |
| 910 | goto done; |
| 911 | } |
| 912 | |
| 913 | error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags); |
| 914 | if (error) |
| 915 | goto done; |
| 916 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 917 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 918 | return error; |
| 919 | } |
| 920 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 921 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 922 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 923 | * This command is used to change the admin state (up/down) of an interface. |
| 924 | * |
| 925 | * If an interface is down, the optional '<em>punt</em>' flag can also be set. |
| 926 | * The '<em>punt</em>' flag implies the interface is disabled for forwarding |
| 927 | * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear |
| 928 | * '<em>punt</em>' flag (interface is still down). |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 929 | * |
| 930 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 931 | * Example of how to configure the admin state of an interface to '<em>up</em?': |
| 932 | * @cliexcmd{set interface state GigabitEthernet2/0/0 up} |
| 933 | * Example of how to configure the admin state of an interface to '<em>down</em?': |
| 934 | * @cliexcmd{set interface state GigabitEthernet2/0/0 down} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 935 | ?*/ |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 936 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 937 | VLIB_CLI_COMMAND (set_state_command, static) = { |
| 938 | .path = "set interface state", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 939 | .short_help = "set interface state <interface> [up|down|punt|enable]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 940 | .function = set_state, |
| 941 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 942 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 943 | |
| 944 | static clib_error_t * |
| 945 | set_unnumbered (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 946 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 947 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 948 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 949 | u32 unnumbered_sw_if_index = ~0; |
| 950 | u32 inherit_from_sw_if_index = ~0; |
| 951 | int enable = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 952 | |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 953 | if (unformat (input, "%U use %U", |
| 954 | unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index, |
| 955 | unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index)) |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 956 | enable = 1; |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 957 | else if (unformat (input, "del %U", |
| 958 | unformat_vnet_sw_interface, vnm, |
| 959 | &unnumbered_sw_if_index)) |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 960 | enable = 0; |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 961 | else |
| 962 | return clib_error_return (0, "parse error '%U'", |
| 963 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 964 | |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 965 | if (~0 == unnumbered_sw_if_index) |
| 966 | return clib_error_return (0, "Specify the unnumbered interface"); |
| 967 | if (enable && ~0 == inherit_from_sw_if_index) |
| 968 | return clib_error_return (0, "When enabling unnumberered specify the" |
| 969 | " IP enabled interface that it uses"); |
Neale Ranns | 898273f | 2017-03-18 02:57:38 -0700 | [diff] [blame] | 970 | |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 971 | vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index, |
| 972 | inherit_from_sw_if_index, enable); |
Neale Ranns | 898273f | 2017-03-18 02:57:38 -0700 | [diff] [blame] | 973 | |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 974 | return (NULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 975 | } |
| 976 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 977 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 978 | VLIB_CLI_COMMAND (set_unnumbered_command, static) = { |
| 979 | .path = "set interface unnumbered", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 980 | .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 981 | .function = set_unnumbered, |
| 982 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 983 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 984 | |
| 985 | |
| 986 | |
| 987 | static clib_error_t * |
| 988 | set_hw_class (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 989 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 990 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 991 | vnet_main_t *vnm = vnet_get_main (); |
| 992 | vnet_interface_main_t *im = &vnm->interface_main; |
| 993 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 994 | u32 hw_if_index, hw_class_index; |
| 995 | |
| 996 | hw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 997 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 998 | { |
| 999 | error = clib_error_return (0, "unknown hardware interface `%U'", |
| 1000 | format_unformat_error, input); |
| 1001 | goto done; |
| 1002 | } |
| 1003 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1004 | if (!unformat_user (input, unformat_hash_string, |
| 1005 | im->hw_interface_class_by_name, &hw_class_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1006 | { |
| 1007 | error = clib_error_return (0, "unknown hardware class `%U'", |
| 1008 | format_unformat_error, input); |
| 1009 | goto done; |
| 1010 | } |
| 1011 | |
| 1012 | error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index); |
| 1013 | if (error) |
| 1014 | goto done; |
| 1015 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1016 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1017 | return error; |
| 1018 | } |
| 1019 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1020 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1021 | VLIB_CLI_COMMAND (set_hw_class_command, static) = { |
| 1022 | .path = "set interface hw-class", |
| 1023 | .short_help = "Set interface hardware class", |
| 1024 | .function = set_hw_class, |
| 1025 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1026 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1027 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1028 | static clib_error_t * |
| 1029 | vnet_interface_cli_init (vlib_main_t * vm) |
| 1030 | { |
| 1031 | return 0; |
| 1032 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1033 | |
| 1034 | VLIB_INIT_FUNCTION (vnet_interface_cli_init); |
| 1035 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1036 | static clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1037 | renumber_interface_command_fn (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1038 | unformat_input_t * input, |
| 1039 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1040 | { |
| 1041 | u32 hw_if_index; |
| 1042 | u32 new_dev_instance; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1043 | vnet_main_t *vnm = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1044 | int rv; |
| 1045 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1046 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1047 | return clib_error_return (0, "unknown hardware interface `%U'", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1048 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1049 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1050 | if (!unformat (input, "%d", &new_dev_instance)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1051 | return clib_error_return (0, "new dev instance missing"); |
| 1052 | |
| 1053 | rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance); |
| 1054 | |
| 1055 | switch (rv) |
| 1056 | { |
| 1057 | case 0: |
| 1058 | break; |
| 1059 | |
| 1060 | default: |
| 1061 | return clib_error_return (0, "vnet_interface_name_renumber returned %d", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1062 | rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1063 | |
| 1064 | } |
| 1065 | |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
| 1069 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1070 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1071 | VLIB_CLI_COMMAND (renumber_interface_command, static) = { |
| 1072 | .path = "renumber interface", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1073 | .short_help = "renumber interface <interface> <new-dev-instance>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1074 | .function = renumber_interface_command_fn, |
| 1075 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1076 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1077 | |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1078 | static clib_error_t * |
| 1079 | promiscuous_cmd (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1080 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1081 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1082 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1083 | u32 hw_if_index; |
| 1084 | u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1085 | ethernet_main_t *em = ðernet_main; |
| 1086 | ethernet_interface_t *eif; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1087 | |
| 1088 | if (unformat (input, "on %U", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1089 | unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1090 | ; |
| 1091 | else if (unformat (input, "off %U", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1092 | unformat_ethernet_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1093 | flags = 0; |
| 1094 | else |
| 1095 | return clib_error_return (0, "unknown input `%U'", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1096 | format_unformat_error, input); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1097 | |
| 1098 | eif = ethernet_get_interface (em, hw_if_index); |
| 1099 | if (!eif) |
| 1100 | return clib_error_return (0, "not supported"); |
| 1101 | |
| 1102 | ethernet_set_flags (vnm, hw_if_index, flags); |
| 1103 | return 0; |
| 1104 | } |
| 1105 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1106 | /* *INDENT-OFF* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1107 | VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = { |
| 1108 | .path = "set interface promiscuous", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1109 | .short_help = "set interface promiscuous [on|off] <interface>", |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1110 | .function = promiscuous_cmd, |
| 1111 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1112 | /* *INDENT-ON* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1113 | |
| 1114 | static clib_error_t * |
| 1115 | mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1116 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1117 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1118 | u32 hw_if_index, mtu; |
| 1119 | ethernet_main_t *em = ðernet_main; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1120 | |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1121 | if (unformat (input, "%d %U", &mtu, |
| 1122 | unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1123 | { |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1124 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 1125 | ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index); |
| 1126 | |
| 1127 | if (!eif) |
| 1128 | return clib_error_return (0, "not supported"); |
| 1129 | |
| 1130 | if (mtu < hi->min_supported_packet_bytes) |
| 1131 | return clib_error_return (0, "Invalid mtu (%d): " |
| 1132 | "must be >= min pkt bytes (%d)", mtu, |
| 1133 | hi->min_supported_packet_bytes); |
| 1134 | |
| 1135 | if (mtu > hi->max_supported_packet_bytes) |
| 1136 | return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu, |
| 1137 | hi->max_supported_packet_bytes); |
| 1138 | |
| 1139 | vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1140 | } |
| 1141 | else |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1142 | return clib_error_return (0, "unknown input `%U'", |
| 1143 | format_unformat_error, input); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1144 | return 0; |
| 1145 | } |
| 1146 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1147 | /* *INDENT-OFF* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1148 | VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = { |
| 1149 | .path = "set interface mtu", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1150 | .short_help = "set interface mtu <value> <interface>", |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1151 | .function = mtu_cmd, |
| 1152 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1153 | /* *INDENT-ON* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1154 | |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1155 | static clib_error_t * |
| 1156 | set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input, |
| 1157 | vlib_cli_command_t * cmd) |
| 1158 | { |
| 1159 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | d867a7c | 2017-10-04 02:29:07 -0700 | [diff] [blame] | 1160 | vnet_sw_interface_t *si = NULL; |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1161 | clib_error_t *error = 0; |
| 1162 | u32 sw_if_index = ~0; |
John Lo | 62fcc0a | 2017-10-31 14:31:10 -0400 | [diff] [blame] | 1163 | u8 mac[6] = { 0 }; |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1164 | |
| 1165 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1166 | { |
| 1167 | error = clib_error_return (0, "unknown interface `%U'", |
| 1168 | format_unformat_error, input); |
| 1169 | goto done; |
| 1170 | } |
John Lo | 62fcc0a | 2017-10-31 14:31:10 -0400 | [diff] [blame] | 1171 | if (!unformat_user (input, unformat_ethernet_address, mac)) |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1172 | { |
| 1173 | error = clib_error_return (0, "expected mac address `%U'", |
| 1174 | format_unformat_error, input); |
| 1175 | goto done; |
| 1176 | } |
Neale Ranns | d867a7c | 2017-10-04 02:29:07 -0700 | [diff] [blame] | 1177 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1178 | error = vnet_hw_interface_change_mac_address (vnm, si->hw_if_index, mac); |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1179 | done: |
| 1180 | return error; |
| 1181 | } |
| 1182 | |
| 1183 | /*? |
| 1184 | * The '<em>set interface mac address </em>' command allows to set MAC address of given interface. |
| 1185 | * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address |
| 1186 | * change are changes of MAC addresses in FIB tables (ipv4 and ipv6). |
| 1187 | * |
| 1188 | * @cliexpar |
| 1189 | * @parblock |
| 1190 | * Example of how to change MAC Address of interface: |
| 1191 | * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01} |
| 1192 | * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02} |
| 1193 | * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03} |
| 1194 | * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04} |
| 1195 | * @endparblock |
| 1196 | ?*/ |
| 1197 | /* *INDENT-OFF* */ |
| 1198 | VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = { |
| 1199 | .path = "set interface mac address", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1200 | .short_help = "set interface mac address <interface> <mac-address>", |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1201 | .function = set_interface_mac_address, |
| 1202 | }; |
| 1203 | /* *INDENT-ON* */ |
| 1204 | |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1205 | static clib_error_t * |
| 1206 | set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1207 | { |
| 1208 | vnet_main_t *vnm = vnet_get_main (); |
| 1209 | u32 sw_if_index = ~0; |
| 1210 | u8 *tag = 0; |
| 1211 | |
| 1212 | if (!unformat (input, "%U %s", unformat_vnet_sw_interface, |
| 1213 | vnm, &sw_if_index, &tag)) |
| 1214 | return clib_error_return (0, "unknown input `%U'", |
| 1215 | format_unformat_error, input); |
| 1216 | |
| 1217 | vnet_set_sw_interface_tag (vnm, tag, sw_if_index); |
| 1218 | |
| 1219 | return 0; |
| 1220 | } |
| 1221 | |
| 1222 | /* *INDENT-OFF* */ |
| 1223 | VLIB_CLI_COMMAND (set_tag_command, static) = { |
| 1224 | .path = "set interface tag", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1225 | .short_help = "set interface tag <interface> <tag>", |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1226 | .function = set_tag, |
| 1227 | }; |
| 1228 | /* *INDENT-ON* */ |
| 1229 | |
| 1230 | static clib_error_t * |
| 1231 | clear_tag (vlib_main_t * vm, unformat_input_t * input, |
| 1232 | vlib_cli_command_t * cmd) |
| 1233 | { |
| 1234 | vnet_main_t *vnm = vnet_get_main (); |
| 1235 | u32 sw_if_index = ~0; |
| 1236 | |
| 1237 | if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1238 | return clib_error_return (0, "unknown input `%U'", |
| 1239 | format_unformat_error, input); |
| 1240 | |
| 1241 | vnet_clear_sw_interface_tag (vnm, sw_if_index); |
| 1242 | |
| 1243 | return 0; |
| 1244 | } |
| 1245 | |
| 1246 | /* *INDENT-OFF* */ |
| 1247 | VLIB_CLI_COMMAND (clear_tag_command, static) = { |
| 1248 | .path = "clear interface tag", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1249 | .short_help = "clear interface tag <interface>", |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1250 | .function = clear_tag, |
| 1251 | }; |
| 1252 | /* *INDENT-ON* */ |
| 1253 | |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1254 | static clib_error_t * |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1255 | set_hw_interface_rx_mode (vnet_main_t * vnm, u32 hw_if_index, |
| 1256 | u32 queue_id, vnet_hw_interface_rx_mode mode) |
| 1257 | { |
| 1258 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 1259 | vnet_device_class_t *dev_class = |
| 1260 | vnet_get_device_class (vnm, hw->dev_class_index); |
| 1261 | clib_error_t *error; |
| 1262 | vnet_hw_interface_rx_mode old_mode; |
| 1263 | int rv; |
| 1264 | |
Damjan Marion | 4e53a0d | 2017-06-21 14:29:44 +0200 | [diff] [blame] | 1265 | if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT) |
| 1266 | mode = hw->default_rx_mode; |
| 1267 | |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1268 | rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &old_mode); |
| 1269 | switch (rv) |
| 1270 | { |
| 1271 | case 0: |
| 1272 | if (old_mode == mode) |
| 1273 | return 0; /* same rx-mode, no change */ |
| 1274 | break; |
| 1275 | case VNET_API_ERROR_INVALID_INTERFACE: |
| 1276 | return clib_error_return (0, "invalid interface"); |
Steven | bd8a611 | 2017-07-30 10:29:26 -0700 | [diff] [blame] | 1277 | case VNET_API_ERROR_INVALID_QUEUE: |
| 1278 | return clib_error_return (0, "invalid queue"); |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1279 | default: |
| 1280 | return clib_error_return (0, "unknown error"); |
| 1281 | } |
| 1282 | |
| 1283 | if (dev_class->rx_mode_change_function) |
| 1284 | { |
| 1285 | error = dev_class->rx_mode_change_function (vnm, hw_if_index, queue_id, |
| 1286 | mode); |
| 1287 | if (error) |
| 1288 | return (error); |
| 1289 | } |
| 1290 | |
| 1291 | rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode); |
| 1292 | switch (rv) |
| 1293 | { |
| 1294 | case 0: |
| 1295 | break; |
| 1296 | case VNET_API_ERROR_UNSUPPORTED: |
| 1297 | return clib_error_return (0, "unsupported"); |
| 1298 | case VNET_API_ERROR_INVALID_INTERFACE: |
| 1299 | return clib_error_return (0, "invalid interface"); |
Steven | bd8a611 | 2017-07-30 10:29:26 -0700 | [diff] [blame] | 1300 | case VNET_API_ERROR_INVALID_QUEUE: |
| 1301 | return clib_error_return (0, "invalid queue"); |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1302 | default: |
| 1303 | return clib_error_return (0, "unknown error"); |
| 1304 | } |
| 1305 | |
| 1306 | return 0; |
| 1307 | } |
| 1308 | |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1309 | clib_error_t * |
| 1310 | set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index, |
| 1311 | u8 queue_id_valid, u32 queue_id, |
| 1312 | vnet_hw_interface_rx_mode mode) |
| 1313 | { |
| 1314 | clib_error_t *error = 0; |
| 1315 | vnet_hw_interface_t *hw; |
| 1316 | int i; |
| 1317 | |
| 1318 | hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 1319 | |
| 1320 | if (queue_id_valid == 0) |
| 1321 | { |
| 1322 | for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++) |
| 1323 | { |
| 1324 | error = set_hw_interface_rx_mode (vnm, hw_if_index, i, mode); |
| 1325 | if (error) |
| 1326 | break; |
| 1327 | } |
| 1328 | hw->default_rx_mode = mode; |
| 1329 | } |
| 1330 | else |
| 1331 | error = set_hw_interface_rx_mode (vnm, hw_if_index, queue_id, mode); |
| 1332 | |
| 1333 | return (error); |
| 1334 | } |
| 1335 | |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1336 | static clib_error_t * |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1337 | set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input, |
| 1338 | vlib_cli_command_t * cmd) |
| 1339 | { |
| 1340 | clib_error_t *error = 0; |
| 1341 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1342 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1343 | u32 hw_if_index = (u32) ~ 0; |
| 1344 | u32 queue_id = (u32) ~ 0; |
| 1345 | vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN; |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1346 | u8 queue_id_valid = 0; |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1347 | |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1348 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1349 | return 0; |
| 1350 | |
| 1351 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1352 | { |
| 1353 | if (unformat |
| 1354 | (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 1355 | ; |
| 1356 | else if (unformat (line_input, "queue %d", &queue_id)) |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1357 | queue_id_valid = 1; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1358 | else if (unformat (line_input, "polling")) |
| 1359 | mode = VNET_HW_INTERFACE_RX_MODE_POLLING; |
| 1360 | else if (unformat (line_input, "interrupt")) |
| 1361 | mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT; |
| 1362 | else if (unformat (line_input, "adaptive")) |
| 1363 | mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE; |
| 1364 | else |
| 1365 | { |
| 1366 | error = clib_error_return (0, "parse error: '%U'", |
| 1367 | format_unformat_error, line_input); |
| 1368 | unformat_free (line_input); |
| 1369 | return error; |
| 1370 | } |
| 1371 | } |
| 1372 | |
| 1373 | unformat_free (line_input); |
| 1374 | |
| 1375 | if (hw_if_index == (u32) ~ 0) |
| 1376 | return clib_error_return (0, "please specify valid interface name"); |
| 1377 | |
| 1378 | if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN) |
| 1379 | return clib_error_return (0, "please specify valid rx-mode"); |
| 1380 | |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1381 | error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid, |
| 1382 | queue_id, mode); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1383 | |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1384 | return (error); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1385 | } |
| 1386 | |
| 1387 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1388 | * This command is used to assign the RX packet processing mode (polling, |
| 1389 | * interrupt, adaptive) of the a given interface, and optionally a |
| 1390 | * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>' |
| 1391 | * is applied to all queues of the interface. Not all interfaces support |
| 1392 | * all modes. To display the current rx-mode use the command |
| 1393 | * '<em>show interface rx-placement</em>'. |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1394 | * |
| 1395 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1396 | * Example of how to assign rx-mode to all queues on an interface: |
| 1397 | * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling} |
| 1398 | * Example of how to assign rx-mode to one queue of an interface: |
| 1399 | * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt} |
| 1400 | * Example of how to display the rx-mode of all interfaces: |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1401 | * @cliexstart{show interface rx-placement} |
| 1402 | * Thread 1 (vpp_wk_0): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1403 | * node dpdk-input: |
| 1404 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1405 | * node vhost-user-input: |
| 1406 | * VirtualEthernet0/0/12 queue 0 (interrupt) |
| 1407 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1408 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1409 | * VirtualEthernet0/0/13 queue 2 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1410 | * Thread 2 (vpp_wk_1): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1411 | * node dpdk-input: |
| 1412 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1413 | * node vhost-user-input: |
| 1414 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1415 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1416 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1417 | * VirtualEthernet0/0/13 queue 3 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1418 | * @cliexend |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1419 | ?*/ |
| 1420 | /* *INDENT-OFF* */ |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1421 | VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = { |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1422 | .path = "set interface rx-mode", |
| 1423 | .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]", |
| 1424 | .function = set_interface_rx_mode, |
| 1425 | }; |
| 1426 | /* *INDENT-ON* */ |
| 1427 | |
| 1428 | static clib_error_t * |
| 1429 | show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1430 | vlib_cli_command_t * cmd) |
| 1431 | { |
| 1432 | u8 *s = 0; |
| 1433 | vnet_main_t *vnm = vnet_get_main (); |
| 1434 | vnet_device_input_runtime_t *rt; |
| 1435 | vnet_device_and_queue_t *dq; |
| 1436 | vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input"); |
| 1437 | uword si; |
| 1438 | int index = 0; |
| 1439 | |
| 1440 | /* *INDENT-OFF* */ |
| 1441 | foreach_vlib_main (({ |
| 1442 | clib_bitmap_foreach (si, pn->sibling_bitmap, |
| 1443 | ({ |
| 1444 | rt = vlib_node_get_runtime_data (this_vlib_main, si); |
| 1445 | |
| 1446 | if (vec_len (rt->devices_and_queues)) |
| 1447 | s = format (s, " node %U:\n", format_vlib_node_name, vm, si); |
| 1448 | |
| 1449 | vec_foreach (dq, rt->devices_and_queues) |
| 1450 | { |
Steven | 9d6d989 | 2017-06-30 07:15:02 -0700 | [diff] [blame] | 1451 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, |
| 1452 | dq->hw_if_index); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1453 | s = format (s, " %U queue %u (%U)\n", |
Steven | 9d6d989 | 2017-06-30 07:15:02 -0700 | [diff] [blame] | 1454 | format_vnet_sw_if_index_name, vnm, hi->sw_if_index, |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1455 | dq->queue_id, |
| 1456 | format_vnet_hw_interface_rx_mode, dq->mode); |
| 1457 | } |
| 1458 | })); |
| 1459 | if (vec_len (s) > 0) |
| 1460 | { |
| 1461 | vlib_cli_output(vm, "Thread %u (%v):\n%v", index, |
| 1462 | vlib_worker_threads[index].name, s); |
| 1463 | vec_reset_length (s); |
| 1464 | } |
| 1465 | index++; |
| 1466 | })); |
| 1467 | /* *INDENT-ON* */ |
| 1468 | |
| 1469 | vec_free (s); |
| 1470 | return 0; |
| 1471 | } |
| 1472 | |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1473 | /*? |
| 1474 | * This command is used to display the interface and queue worker |
| 1475 | * thread placement. |
| 1476 | * |
| 1477 | * @cliexpar |
| 1478 | * Example of how to display the interface placement: |
| 1479 | * @cliexstart{show interface rx-placement} |
| 1480 | * Thread 1 (vpp_wk_0): |
| 1481 | * node dpdk-input: |
| 1482 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1483 | * node vhost-user-input: |
| 1484 | * VirtualEthernet0/0/12 queue 0 (polling) |
| 1485 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1486 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1487 | * VirtualEthernet0/0/13 queue 2 (polling) |
| 1488 | * Thread 2 (vpp_wk_1): |
| 1489 | * node dpdk-input: |
| 1490 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1491 | * node vhost-user-input: |
| 1492 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1493 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1494 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1495 | * VirtualEthernet0/0/13 queue 3 (polling) |
| 1496 | * @cliexend |
| 1497 | ?*/ |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1498 | /* *INDENT-OFF* */ |
| 1499 | VLIB_CLI_COMMAND (show_interface_rx_placement, static) = { |
| 1500 | .path = "show interface rx-placement", |
| 1501 | .short_help = "show interface rx-placement", |
| 1502 | .function = show_interface_rx_placement_fn, |
| 1503 | }; |
| 1504 | /* *INDENT-ON* */ |
| 1505 | |
| 1506 | static clib_error_t * |
| 1507 | set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input, |
| 1508 | vlib_cli_command_t * cmd) |
| 1509 | { |
| 1510 | clib_error_t *error = 0; |
| 1511 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1512 | vnet_main_t *vnm = vnet_get_main (); |
| 1513 | vnet_device_main_t *vdm = &vnet_device_main; |
| 1514 | vnet_hw_interface_rx_mode mode; |
| 1515 | u32 hw_if_index = (u32) ~ 0; |
| 1516 | u32 queue_id = (u32) 0; |
| 1517 | u32 thread_index = (u32) ~ 0; |
| 1518 | int rv; |
| 1519 | |
| 1520 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1521 | return 0; |
| 1522 | |
| 1523 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1524 | { |
| 1525 | if (unformat |
| 1526 | (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 1527 | ; |
| 1528 | else if (unformat (line_input, "queue %d", &queue_id)) |
| 1529 | ; |
| 1530 | else if (unformat (line_input, "main", &thread_index)) |
| 1531 | thread_index = 0; |
| 1532 | else if (unformat (line_input, "worker %d", &thread_index)) |
| 1533 | thread_index += vdm->first_worker_thread_index; |
| 1534 | else |
| 1535 | { |
| 1536 | error = clib_error_return (0, "parse error: '%U'", |
| 1537 | format_unformat_error, line_input); |
| 1538 | unformat_free (line_input); |
| 1539 | return error; |
| 1540 | } |
| 1541 | } |
| 1542 | |
| 1543 | unformat_free (line_input); |
| 1544 | |
| 1545 | if (hw_if_index == (u32) ~ 0) |
| 1546 | return clib_error_return (0, "please specify valid interface name"); |
| 1547 | |
| 1548 | if (thread_index > vdm->last_worker_thread_index) |
| 1549 | return clib_error_return (0, |
| 1550 | "please specify valid worker thread or main"); |
| 1551 | |
| 1552 | rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode); |
| 1553 | |
| 1554 | if (rv) |
| 1555 | return clib_error_return (0, "not found"); |
| 1556 | |
| 1557 | rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id); |
| 1558 | |
| 1559 | if (rv) |
| 1560 | return clib_error_return (0, "not found"); |
| 1561 | |
| 1562 | vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id, |
| 1563 | thread_index); |
| 1564 | vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode); |
| 1565 | |
| 1566 | return 0; |
| 1567 | } |
| 1568 | |
| 1569 | /*? |
| 1570 | * This command is used to assign a given interface, and optionally a |
| 1571 | * given queue, to a different thread. If the '<em>queue</em>' is not provided, |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1572 | * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index |
| 1573 | * in the thread name, for example, 0 in the thread name '<em>vpp_wk_0</em>'. |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1574 | * |
| 1575 | * @cliexpar |
| 1576 | * Example of how to display the interface placement: |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1577 | * @cliexstart{show interface rx-placement} |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1578 | * Thread 1 (vpp_wk_0): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1579 | * node dpdk-input: |
| 1580 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1581 | * node vhost-user-input: |
| 1582 | * VirtualEthernet0/0/12 queue 0 (polling) |
| 1583 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1584 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1585 | * VirtualEthernet0/0/13 queue 2 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1586 | * Thread 2 (vpp_wk_1): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1587 | * node dpdk-input: |
| 1588 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1589 | * node vhost-user-input: |
| 1590 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1591 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1592 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1593 | * VirtualEthernet0/0/13 queue 3 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1594 | * @cliexend |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1595 | * Example of how to assign a interface and queue to a worker thread: |
| 1596 | * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0} |
| 1597 | * Example of how to display the interface placement: |
| 1598 | * @cliexstart{show interface rx-placement} |
| 1599 | * Thread 1 (vpp_wk_0): |
| 1600 | * node dpdk-input: |
| 1601 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1602 | * node vhost-user-input: |
| 1603 | * VirtualEthernet0/0/12 queue 0 (polling) |
| 1604 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1605 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1606 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1607 | * VirtualEthernet0/0/13 queue 2 (polling) |
| 1608 | * Thread 2 (vpp_wk_1): |
| 1609 | * node dpdk-input: |
| 1610 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1611 | * node vhost-user-input: |
| 1612 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1613 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1614 | * VirtualEthernet0/0/13 queue 3 (polling) |
| 1615 | * @cliexend |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1616 | ?*/ |
| 1617 | /* *INDENT-OFF* */ |
| 1618 | VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = { |
| 1619 | .path = "set interface rx-placement", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1620 | .short_help = "set interface rx-placement <interface> [queue <n>] " |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 1621 | "[worker <n> | main]", |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1622 | .function = set_interface_rx_placement, |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 1623 | .is_mp_safe = 1, |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1624 | }; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1625 | /* *INDENT-ON* */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1626 | /* |
| 1627 | * fd.io coding-style-patch-verification: ON |
| 1628 | * |
| 1629 | * Local Variables: |
| 1630 | * eval: (c-set-style "gnu") |
| 1631 | * End: |
| 1632 | */ |