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