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