Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 Cisco and/or its affiliates. |
| 3 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | * you may not use this file except in compliance with the License. |
| 5 | * You may obtain a copy of the License at: |
| 6 | * |
| 7 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | * |
| 9 | * Unless required by applicable law or agreed to in writing, software |
| 10 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | * See the License for the specific language governing permissions and |
| 13 | * limitations under the License. |
| 14 | */ |
| 15 | /* |
| 16 | * interface_cli.c: interface CLI |
| 17 | * |
| 18 | * Copyright (c) 2008 Eliot Dresselhaus |
| 19 | * |
| 20 | * Permission is hereby granted, free of charge, to any person obtaining |
| 21 | * a copy of this software and associated documentation files (the |
| 22 | * "Software"), to deal in the Software without restriction, including |
| 23 | * without limitation the rights to use, copy, modify, merge, publish, |
| 24 | * distribute, sublicense, and/or sell copies of the Software, and to |
| 25 | * permit persons to whom the Software is furnished to do so, subject to |
| 26 | * the following conditions: |
| 27 | * |
| 28 | * The above copyright notice and this permission notice shall be |
| 29 | * included in all copies or substantial portions of the Software. |
| 30 | * |
| 31 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 32 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 33 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 34 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE |
| 35 | * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION |
| 36 | * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 37 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 38 | */ |
| 39 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 40 | /** |
| 41 | * @file |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 42 | * @brief Interface CLI. |
| 43 | * |
| 44 | * Source code for several CLI interface commands. |
| 45 | * |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 46 | */ |
| 47 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 48 | #include <vnet/vnet.h> |
| 49 | #include <vnet/ip/ip.h> |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 50 | #include <vppinfra/bitmap.h> |
Neale Ranns | 0bfe5d8 | 2016-08-25 15:29:12 +0100 | [diff] [blame] | 51 | #include <vnet/fib/ip4_fib.h> |
| 52 | #include <vnet/fib/ip6_fib.h> |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 53 | #include <vnet/l2/l2_output.h> |
| 54 | #include <vnet/l2/l2_input.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 55 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 56 | static int |
| 57 | compare_interface_names (void *a1, void *a2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 58 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 59 | u32 *hi1 = a1; |
| 60 | u32 *hi2 = a2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 61 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 62 | return vnet_hw_interface_compare (vnet_get_main (), *hi1, *hi2); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 63 | } |
| 64 | |
| 65 | static clib_error_t * |
| 66 | show_or_clear_hw_interfaces (vlib_main_t * vm, |
| 67 | unformat_input_t * input, |
| 68 | vlib_cli_command_t * cmd) |
| 69 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 70 | clib_error_t *error = 0; |
| 71 | vnet_main_t *vnm = vnet_get_main (); |
| 72 | vnet_interface_main_t *im = &vnm->interface_main; |
| 73 | vnet_hw_interface_t *hi; |
| 74 | u32 hw_if_index, *hw_if_indices = 0; |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 75 | int i, verbose = -1, is_show, show_bond = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 76 | |
| 77 | is_show = strstr (cmd->path, "show") != 0; |
| 78 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 79 | { |
| 80 | /* See if user wants to show a specific interface. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 81 | if (unformat |
| 82 | (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 83 | vec_add1 (hw_if_indices, hw_if_index); |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 84 | |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 85 | /* See if user wants to show an interface with a specific hw_if_index. */ |
| 86 | else if (unformat (input, "%u", &hw_if_index)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 87 | vec_add1 (hw_if_indices, hw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 88 | |
| 89 | else if (unformat (input, "verbose")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 90 | verbose = 1; /* this is also the default */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 91 | |
| 92 | else if (unformat (input, "detail")) |
| 93 | verbose = 2; |
| 94 | |
| 95 | else if (unformat (input, "brief")) |
| 96 | verbose = 0; |
| 97 | |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 98 | else if (unformat (input, "bond")) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 99 | { |
| 100 | show_bond = 1; |
| 101 | if (verbose < 0) |
| 102 | verbose = 0; /* default to brief for link bonding */ |
| 103 | } |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 104 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 105 | else |
| 106 | { |
| 107 | error = clib_error_return (0, "unknown input `%U'", |
| 108 | format_unformat_error, input); |
| 109 | goto done; |
| 110 | } |
| 111 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 112 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 113 | /* Gather interfaces. */ |
| 114 | if (vec_len (hw_if_indices) == 0) |
| 115 | pool_foreach (hi, im->hw_interfaces, |
| 116 | vec_add1 (hw_if_indices, hi - im->hw_interfaces)); |
| 117 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 118 | if (verbose < 0) |
| 119 | verbose = 1; /* default to verbose (except bond) */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 120 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 121 | if (is_show) |
| 122 | { |
| 123 | /* Sort by name. */ |
| 124 | vec_sort_with_function (hw_if_indices, compare_interface_names); |
| 125 | |
| 126 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, 0, verbose); |
| 127 | for (i = 0; i < vec_len (hw_if_indices); i++) |
| 128 | { |
| 129 | hi = vnet_get_hw_interface (vnm, hw_if_indices[i]); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 130 | if (show_bond == 0) /* show all interfaces */ |
| 131 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, |
| 132 | hi, verbose); |
| 133 | else if ((hi->bond_info) && |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 134 | (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE)) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 135 | { /* show only bonded interface and all its slave interfaces */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 136 | int hw_idx; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 137 | vnet_hw_interface_t *shi; |
| 138 | vlib_cli_output (vm, "%U\n", format_vnet_hw_interface, vnm, |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 139 | hi, verbose); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 140 | |
| 141 | /* *INDENT-OFF* */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 142 | clib_bitmap_foreach (hw_idx, hi->bond_info, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 143 | ({ |
| 144 | shi = vnet_get_hw_interface(vnm, hw_idx); |
| 145 | vlib_cli_output (vm, "%U\n", |
| 146 | format_vnet_hw_interface, vnm, shi, verbose); |
| 147 | })); |
| 148 | /* *INDENT-ON* */ |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 149 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 150 | } |
| 151 | } |
| 152 | else |
| 153 | { |
| 154 | for (i = 0; i < vec_len (hw_if_indices); i++) |
| 155 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 156 | vnet_device_class_t *dc; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 157 | |
| 158 | hi = vnet_get_hw_interface (vnm, hw_if_indices[i]); |
| 159 | dc = vec_elt_at_index (im->device_classes, hi->dev_class_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 160 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 161 | if (dc->clear_counters) |
| 162 | dc->clear_counters (hi->dev_instance); |
| 163 | } |
| 164 | } |
| 165 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 166 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 167 | vec_free (hw_if_indices); |
| 168 | return error; |
| 169 | } |
| 170 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 171 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 172 | * Display more detailed information about all or a list of given interfaces. |
| 173 | * The verboseness of the output can be controlled by the following optional |
| 174 | * parameters: |
| 175 | * - brief: Only show name, index and state (default for bonded interfaces). |
| 176 | * - verbose: Also display additional attributes (default for all other interfaces). |
| 177 | * - detail: Also display all remaining attributes and extended statistics. |
| 178 | * |
| 179 | * To limit the output of the command to bonded interfaces and their slave |
| 180 | * interfaces, use the '<em>bond</em>' optional parameter. |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 181 | * |
| 182 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 183 | * Example of how to display default data for all interfaces: |
| 184 | * @cliexstart{show hardware-interfaces} |
| 185 | * Name Idx Link Hardware |
| 186 | * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0 |
| 187 | * Ethernet address ec:f4:bb:c0:bc:fc |
| 188 | * Intel e1000 |
| 189 | * carrier up full duplex speed 1000 mtu 9216 |
| 190 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 191 | * cpu socket 0 |
| 192 | * GigabitEthernet7/0/1 2 up GigabitEthernet7/0/1 |
| 193 | * Ethernet address ec:f4:bb:c0:bc:fd |
| 194 | * Intel e1000 |
| 195 | * carrier up full duplex speed 1000 mtu 9216 |
| 196 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 197 | * cpu socket 0 |
| 198 | * VirtualEthernet0/0/0 3 up VirtualEthernet0/0/0 |
| 199 | * Ethernet address 02:fe:a5:a9:8b:8e |
| 200 | * VirtualEthernet0/0/1 4 up VirtualEthernet0/0/1 |
| 201 | * Ethernet address 02:fe:c0:4e:3b:b0 |
| 202 | * VirtualEthernet0/0/2 5 up VirtualEthernet0/0/2 |
| 203 | * Ethernet address 02:fe:1f:73:92:81 |
| 204 | * VirtualEthernet0/0/3 6 up VirtualEthernet0/0/3 |
| 205 | * Ethernet address 02:fe:f2:25:c4:68 |
| 206 | * local0 0 down local0 |
| 207 | * local |
| 208 | * @cliexend |
| 209 | * Example of how to display '<em>verbose</em>' data for an interface by name and |
| 210 | * software index (where 2 is the software index): |
| 211 | * @cliexstart{show hardware-interfaces GigabitEthernet7/0/0 2 verbose} |
| 212 | * Name Idx Link Hardware |
| 213 | * GigabitEthernet7/0/0 1 up GigabitEthernet7/0/0 |
| 214 | * Ethernet address ec:f4:bb:c0:bc:fc |
| 215 | * Intel e1000 |
| 216 | * carrier up full duplex speed 1000 mtu 9216 |
| 217 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 218 | * cpu socket 0 |
| 219 | * GigabitEthernet7/0/1 2 down GigabitEthernet7/0/1 |
| 220 | * Ethernet address ec:f4:bb:c0:bc:fd |
| 221 | * Intel e1000 |
| 222 | * carrier up full duplex speed 1000 mtu 9216 |
| 223 | * rx queues 1, rx desc 1024, tx queues 3, tx desc 1024 |
| 224 | * cpu socket 0 |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 225 | * @cliexend |
| 226 | ?*/ |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 227 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | VLIB_CLI_COMMAND (show_hw_interfaces_command, static) = { |
| 229 | .path = "show hardware-interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 230 | .short_help = "show hardware-interfaces [brief|verbose|detail] [bond] " |
| 231 | "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 232 | .function = show_or_clear_hw_interfaces, |
| 233 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 234 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 235 | |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 236 | |
| 237 | /*? |
| 238 | * Clear the extended statistics for all or a list of given interfaces |
| 239 | * (statistics associated with the '<em>show hardware-interfaces</em>' command). |
| 240 | * |
| 241 | * @cliexpar |
| 242 | * Example of how to clear the extended statistics for all interfaces: |
| 243 | * @cliexcmd{clear hardware-interfaces} |
| 244 | * Example of how to clear the extended statistics for an interface by |
| 245 | * name and software index (where 2 is the software index): |
| 246 | * @cliexcmd{clear hardware-interfaces GigabitEthernet7/0/0 2} |
| 247 | ?*/ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 248 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 249 | VLIB_CLI_COMMAND (clear_hw_interface_counters_command, static) = { |
| 250 | .path = "clear hardware-interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 251 | .short_help = "clear hardware-interfaces " |
| 252 | "[<interface> [<interface> [..]]] [<sw_idx> [<sw_idx> [..]]]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 253 | .function = show_or_clear_hw_interfaces, |
| 254 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 255 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 256 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 257 | static int |
| 258 | sw_interface_name_compare (void *a1, void *a2) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 259 | { |
| 260 | vnet_sw_interface_t *si1 = a1; |
| 261 | vnet_sw_interface_t *si2 = a2; |
| 262 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 263 | return vnet_sw_interface_compare (vnet_get_main (), |
| 264 | si1->sw_if_index, si2->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | static clib_error_t * |
| 268 | show_sw_interfaces (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 269 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 270 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 271 | clib_error_t *error = 0; |
| 272 | vnet_main_t *vnm = vnet_get_main (); |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 273 | unformat_input_t _linput, *linput = &_linput; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 274 | vnet_interface_main_t *im = &vnm->interface_main; |
| 275 | vnet_sw_interface_t *si, *sorted_sis = 0; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 276 | u32 sw_if_index = ~(u32) 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 277 | u8 show_addresses = 0; |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 278 | u8 show_features = 0; |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 279 | u8 show_tag = 0; |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 280 | int verbose = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 281 | |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 282 | /* |
| 283 | * Get a line of input. Won't work if the user typed |
| 284 | * "show interface" and nothing more. |
| 285 | */ |
| 286 | if (unformat_user (input, unformat_line_input, linput)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 287 | { |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 288 | while (unformat_check_input (linput) != UNFORMAT_END_OF_INPUT) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 289 | { |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 290 | /* See if user wants to show specific interface */ |
| 291 | if (unformat |
| 292 | (linput, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 293 | { |
| 294 | si = pool_elt_at_index (im->sw_interfaces, sw_if_index); |
| 295 | vec_add1 (sorted_sis, si[0]); |
| 296 | } |
| 297 | else if (unformat (linput, "address") || unformat (linput, "addr")) |
| 298 | show_addresses = 1; |
| 299 | else if (unformat (linput, "features") || unformat (linput, "feat")) |
| 300 | show_features = 1; |
| 301 | else if (unformat (linput, "tag")) |
| 302 | show_tag = 1; |
| 303 | else if (unformat (linput, "verbose")) |
| 304 | verbose = 1; |
| 305 | else |
| 306 | { |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 307 | vec_free (sorted_sis); |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 308 | error = clib_error_return (0, "unknown input `%U'", |
| 309 | format_unformat_error, linput); |
| 310 | goto done; |
| 311 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 312 | } |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 313 | unformat_free (linput); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 314 | } |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 315 | if (show_features || show_tag) |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 316 | { |
| 317 | if (sw_if_index == ~(u32) 0) |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 318 | { |
| 319 | vec_free (sorted_sis); |
| 320 | return clib_error_return (0, "Interface not specified..."); |
| 321 | } |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 322 | } |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 323 | |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 324 | if (show_features) |
| 325 | { |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 326 | vnet_interface_features_show (vm, sw_if_index, verbose); |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 327 | |
| 328 | l2_input_config_t *l2_input = l2input_intf_config (sw_if_index); |
| 329 | u32 fb = l2_input->feature_bitmap; |
| 330 | /* intf input features are masked by bridge domain */ |
| 331 | if (l2_input->bridge) |
| 332 | fb &= l2input_bd_config (l2_input->bd_index)->feature_bitmap; |
Neale Ranns | 5d9df1d | 2018-11-09 08:19:27 -0800 | [diff] [blame] | 333 | vlib_cli_output (vm, "\nl2-input:\n%U", format_l2_input_features, fb, |
| 334 | 1); |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 335 | |
| 336 | l2_output_config_t *l2_output = l2output_intf_config (sw_if_index); |
| 337 | vlib_cli_output (vm, "\nl2-output:"); |
| 338 | if (l2_output->out_vtr_flag) |
| 339 | vlib_cli_output (vm, "%10s (%s)", "VTR", "--internal--"); |
| 340 | vlib_cli_output (vm, "%U", format_l2_output_features, |
Neale Ranns | 5d9df1d | 2018-11-09 08:19:27 -0800 | [diff] [blame] | 341 | l2_output->feature_bitmap, 1); |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 342 | vec_free (sorted_sis); |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 343 | return 0; |
| 344 | } |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 345 | if (show_tag) |
| 346 | { |
| 347 | u8 *tag; |
| 348 | tag = vnet_get_sw_interface_tag (vnm, sw_if_index); |
| 349 | vlib_cli_output (vm, "%U: %s", |
| 350 | format_vnet_sw_if_index_name, vnm, sw_if_index, |
| 351 | tag ? (char *) tag : "(none)"); |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 352 | vec_free (sorted_sis); |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 353 | return 0; |
| 354 | } |
Damjan Marion | 2231150 | 2016-10-28 20:30:15 +0200 | [diff] [blame] | 355 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 356 | if (!show_addresses) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 357 | vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, 0); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 358 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 359 | if (vec_len (sorted_sis) == 0) /* Get all interfaces */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 360 | { |
| 361 | /* Gather interfaces. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 362 | sorted_sis = |
| 363 | vec_new (vnet_sw_interface_t, pool_elts (im->sw_interfaces)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 364 | _vec_len (sorted_sis) = 0; |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 365 | /* *INDENT-OFF* */ |
| 366 | pool_foreach (si, im->sw_interfaces, |
| 367 | ({ |
| 368 | int visible = vnet_swif_is_api_visible (si); |
| 369 | if (visible) |
| 370 | vec_add1 (sorted_sis, si[0]);} |
| 371 | )); |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 372 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 373 | /* Sort by name. */ |
| 374 | vec_sort_with_function (sorted_sis, sw_interface_name_compare); |
| 375 | } |
| 376 | |
| 377 | if (show_addresses) |
| 378 | { |
| 379 | vec_foreach (si, sorted_sis) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 380 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 381 | ip4_main_t *im4 = &ip4_main; |
| 382 | ip6_main_t *im6 = &ip6_main; |
| 383 | ip_lookup_main_t *lm4 = &im4->lookup_main; |
| 384 | ip_lookup_main_t *lm6 = &im6->lookup_main; |
| 385 | ip_interface_address_t *ia = 0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 386 | u32 fib_index4 = 0, fib_index6 = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 387 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 388 | if (vec_len (im4->fib_index_by_sw_if_index) > si->sw_if_index) |
| 389 | fib_index4 = vec_elt (im4->fib_index_by_sw_if_index, |
| 390 | si->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 391 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 392 | if (vec_len (im6->fib_index_by_sw_if_index) > si->sw_if_index) |
| 393 | fib_index6 = vec_elt (im6->fib_index_by_sw_if_index, |
| 394 | si->sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 395 | |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 396 | ip4_fib_t *fib4 = ip4_fib_get (fib_index4); |
| 397 | ip6_fib_t *fib6 = ip6_fib_get (fib_index6); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 398 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 399 | if (si->flags & VNET_SW_INTERFACE_FLAG_UNNUMBERED) |
| 400 | vlib_cli_output |
| 401 | (vm, "%U (%s): \n unnumbered, use %U", |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 402 | format_vnet_sw_if_index_name, vnm, si->sw_if_index, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 403 | (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn", |
| 404 | format_vnet_sw_if_index_name, vnm, si->unnumbered_sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 405 | else |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 406 | vlib_cli_output |
| 407 | (vm, "%U (%s):", |
| 408 | format_vnet_sw_if_index_name, vnm, si->sw_if_index, |
| 409 | (si->flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "dn"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 410 | |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 411 | /* Display any L2 info */ |
| 412 | l2_input_config_t *l2_input = l2input_intf_config (si->sw_if_index); |
| 413 | if (l2_input->bridge) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 414 | { |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 415 | bd_main_t *bdm = &bd_main; |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 416 | u32 bd_id = l2input_main.bd_configs[l2_input->bd_index].bd_id; |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 417 | vlib_cli_output (vm, " L2 bridge bd-id %d idx %d shg %d %s", |
| 418 | bd_id, bd_find_index (bdm, bd_id), l2_input->shg, |
| 419 | l2_input->bvi ? "bvi" : " "); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 420 | } |
Eyal Bari | 942402b | 2017-07-26 11:57:04 +0300 | [diff] [blame] | 421 | else if (l2_input->xconnect) |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 422 | vlib_cli_output (vm, " L2 xconnect %U", |
| 423 | format_vnet_sw_if_index_name, vnm, |
| 424 | l2_input->output_sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 425 | |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 426 | /* *INDENT-OFF* */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 427 | /* Display any IP4 addressing info */ |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 428 | foreach_ip_interface_address (lm4, ia, si->sw_if_index, |
| 429 | 1 /* honor unnumbered */, |
| 430 | ({ |
| 431 | ip4_address_t *r4 = ip_interface_address_get_address (lm4, ia); |
| 432 | if (fib4->table_id) |
| 433 | vlib_cli_output (vm, " L3 %U/%d ip4 table-id %d fib-idx %d", |
| 434 | format_ip4_address, r4, ia->address_length, |
| 435 | fib4->table_id, |
| 436 | ip4_fib_index_from_table_id (fib4->table_id)); |
| 437 | else |
| 438 | vlib_cli_output (vm, " L3 %U/%d", |
| 439 | format_ip4_address, r4, ia->address_length); |
| 440 | })); |
| 441 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 442 | |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 443 | /* *INDENT-OFF* */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 444 | /* Display any IP6 addressing info */ |
John Lo | 4478d8e | 2018-01-12 17:15:25 -0500 | [diff] [blame] | 445 | foreach_ip_interface_address (lm6, ia, si->sw_if_index, |
| 446 | 1 /* honor unnumbered */, |
| 447 | ({ |
| 448 | ip6_address_t *r6 = ip_interface_address_get_address (lm6, ia); |
| 449 | if (fib6->table_id) |
| 450 | vlib_cli_output (vm, " L3 %U/%d ip6 table-id %d fib-idx %d", |
| 451 | format_ip6_address, r6, ia->address_length, |
| 452 | fib6->table_id, |
| 453 | ip6_fib_index_from_table_id (fib6->table_id)); |
| 454 | else |
| 455 | vlib_cli_output (vm, " L3 %U/%d", |
| 456 | format_ip6_address, r6, ia->address_length); |
| 457 | })); |
| 458 | /* *INDENT-ON* */ |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 459 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 460 | } |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 461 | else |
| 462 | { |
| 463 | vec_foreach (si, sorted_sis) |
| 464 | { |
| 465 | vlib_cli_output (vm, "%U\n", format_vnet_sw_interface, vnm, si); |
| 466 | } |
| 467 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 468 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 469 | done: |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 470 | vec_free (sorted_sis); |
| 471 | return error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 472 | } |
| 473 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 474 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 475 | VLIB_CLI_COMMAND (show_sw_interfaces_command, static) = { |
Dave Barach | 13ad1f0 | 2017-03-26 19:36:18 -0400 | [diff] [blame] | 476 | .path = "show interface", |
Dave Barach | 525c9d0 | 2018-05-26 10:48:55 -0400 | [diff] [blame] | 477 | .short_help = "show interface [address|addr|features|feat] [<interface> [<interface> [..]]] [verbose]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 478 | .function = show_sw_interfaces, |
Steven Luong | c5fa2b8 | 2019-04-25 11:19:49 -0700 | [diff] [blame] | 479 | .is_mp_safe = 1, |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 480 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 481 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 482 | |
| 483 | /* Root of all interface commands. */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 484 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 485 | VLIB_CLI_COMMAND (vnet_cli_interface_command, static) = { |
| 486 | .path = "interface", |
| 487 | .short_help = "Interface commands", |
| 488 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 489 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 490 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 491 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 492 | VLIB_CLI_COMMAND (vnet_cli_set_interface_command, static) = { |
| 493 | .path = "set interface", |
| 494 | .short_help = "Interface commands", |
| 495 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 496 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 497 | |
| 498 | static clib_error_t * |
| 499 | clear_interface_counters (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 500 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 501 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 502 | vnet_main_t *vnm = vnet_get_main (); |
| 503 | vnet_interface_main_t *im = &vnm->interface_main; |
| 504 | vlib_simple_counter_main_t *sm; |
| 505 | vlib_combined_counter_main_t *cm; |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 506 | int j, n_counters; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 507 | |
| 508 | n_counters = vec_len (im->combined_sw_if_counters); |
| 509 | |
| 510 | for (j = 0; j < n_counters; j++) |
| 511 | { |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 512 | im = &vnm->interface_main; |
| 513 | cm = im->combined_sw_if_counters + j; |
| 514 | vlib_clear_combined_counters (cm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 515 | } |
| 516 | |
| 517 | n_counters = vec_len (im->sw_if_counters); |
| 518 | |
| 519 | for (j = 0; j < n_counters; j++) |
| 520 | { |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 521 | im = &vnm->interface_main; |
| 522 | sm = im->sw_if_counters + j; |
| 523 | vlib_clear_simple_counters (sm); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | return 0; |
| 527 | } |
| 528 | |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 529 | /*? |
| 530 | * Clear the statistics for all interfaces (statistics associated with the |
| 531 | * '<em>show interface</em>' command). |
| 532 | * |
| 533 | * @cliexpar |
| 534 | * Example of how to clear the statistics for all interfaces: |
| 535 | * @cliexcmd{clear interfaces} |
| 536 | ?*/ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 537 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 538 | VLIB_CLI_COMMAND (clear_interface_counters_command, static) = { |
| 539 | .path = "clear interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 540 | .short_help = "clear interfaces", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 541 | .function = clear_interface_counters, |
| 542 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 543 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 544 | |
Chris Luke | 16bcf7d | 2016-09-01 14:31:46 -0400 | [diff] [blame] | 545 | /** |
| 546 | * Parse subinterface names. |
| 547 | * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 548 | * The following subinterface syntax is supported. The first two are for |
| 549 | * backwards compatability: |
| 550 | * |
| 551 | * <intf-name> <id> |
| 552 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 553 | * is a single dot1q vlan with vlan id <id> and exact-match semantics. |
| 554 | * |
| 555 | * <intf-name> <min_id>-<max_id> |
| 556 | * - a set of the above subinterfaces, repeating for each id |
| 557 | * in the range <min_id> to <max_id> |
| 558 | * |
| 559 | * In the following, exact-match semantics (i.e. the number of vlan tags on the |
| 560 | * packet must match the number of tags in the configuration) are used only if |
| 561 | * the keyword exact-match is present. Non-exact match is the default. |
| 562 | * |
| 563 | * <intf-name> <id> dot1q <outer_id> [exact-match] |
| 564 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 565 | * is a single dot1q vlan with vlan id <outer_id>. |
| 566 | * |
| 567 | * <intf-name> <id> dot1q any [exact-match] |
| 568 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 569 | * is a single dot1q vlan with any vlan id. |
| 570 | * |
| 571 | * <intf-name> <id> dot1q <outer_id> inner-dot1q <inner_id> [exact-match] |
| 572 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 573 | * is a double dot1q vlan with outer vlan id <outer_id> and inner vlan id |
| 574 | * <inner_id>. |
| 575 | * |
| 576 | * <intf-name> <id> dot1q <outer_id> inner-dot1q any [exact-match] |
| 577 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 578 | * is a double dot1q vlan with outer vlan id <id> and any inner vlan id. |
| 579 | * |
| 580 | * <intf-name> <id> dot1q any inner-dot1q any [exact-match] |
| 581 | * |
| 582 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 583 | * is a double dot1q vlan with any outer vlan id and any inner vlan id. |
| 584 | * |
| 585 | * For each of the above CLI, there is a duplicate that uses the keyword |
| 586 | * "dot1ad" in place of the first "dot1q". These interfaces use ethertype |
| 587 | * 0x88ad in place of 0x8100 for the outer ethertype. Note that for double- |
| 588 | * tagged packets the inner ethertype is always 0x8100. Also note that |
| 589 | * the dot1q and dot1ad naming spaces are independent, so it is legal to |
| 590 | * have both "Gig3/0/0.1 dot1q 100" and "Gig3/0/0.2 dot1ad 100". For example: |
| 591 | * |
| 592 | * <intf-name> <id> dot1ad <outer_id> inner-dot1q <inner_id> [exact-match] |
| 593 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 594 | * is a double dot1ad vlan with outer vlan id <outer_id> and inner vlan |
| 595 | * id <inner_id>. |
| 596 | * |
| 597 | * <intf-name> <id> untagged |
| 598 | * - a subinterface with the name <intf-name>.<id>. The subinterface |
| 599 | * has no vlan tags. Only one can be specified per interface. |
| 600 | * |
| 601 | * <intf-name> <id> default |
| 602 | * - a subinterface with the name <intf-name>.<id>. This is associated |
| 603 | * with a packet that did not match any other configured subinterface |
| 604 | * on this interface. Only one can be specified per interface. |
| 605 | */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 606 | |
| 607 | static clib_error_t * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 608 | parse_vlan_sub_interfaces (unformat_input_t * input, |
| 609 | vnet_sw_interface_t * template) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 610 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 611 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 612 | u32 inner_vlan, outer_vlan; |
| 613 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 614 | if (unformat (input, "any inner-dot1q any")) |
| 615 | { |
| 616 | template->sub.eth.flags.two_tags = 1; |
| 617 | template->sub.eth.flags.outer_vlan_id_any = 1; |
| 618 | template->sub.eth.flags.inner_vlan_id_any = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 619 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 620 | else if (unformat (input, "any")) |
| 621 | { |
| 622 | template->sub.eth.flags.one_tag = 1; |
| 623 | template->sub.eth.flags.outer_vlan_id_any = 1; |
| 624 | } |
| 625 | else if (unformat (input, "%d inner-dot1q any", &outer_vlan)) |
| 626 | { |
| 627 | template->sub.eth.flags.two_tags = 1; |
| 628 | template->sub.eth.flags.inner_vlan_id_any = 1; |
| 629 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 630 | } |
| 631 | else if (unformat (input, "%d inner-dot1q %d", &outer_vlan, &inner_vlan)) |
| 632 | { |
| 633 | template->sub.eth.flags.two_tags = 1; |
| 634 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 635 | template->sub.eth.inner_vlan_id = inner_vlan; |
| 636 | } |
| 637 | else if (unformat (input, "%d", &outer_vlan)) |
| 638 | { |
| 639 | template->sub.eth.flags.one_tag = 1; |
| 640 | template->sub.eth.outer_vlan_id = outer_vlan; |
| 641 | } |
| 642 | else |
| 643 | { |
| 644 | error = clib_error_return (0, "expected dot1q config, got `%U'", |
| 645 | format_unformat_error, input); |
| 646 | goto done; |
| 647 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 648 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 649 | if (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 650 | { |
| 651 | if (unformat (input, "exact-match")) |
| 652 | { |
| 653 | template->sub.eth.flags.exact_match = 1; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 658 | return error; |
| 659 | } |
| 660 | |
| 661 | static clib_error_t * |
| 662 | create_sub_interfaces (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 663 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 664 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 665 | vnet_main_t *vnm = vnet_get_main (); |
| 666 | clib_error_t *error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 667 | u32 hw_if_index, sw_if_index; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 668 | vnet_hw_interface_t *hi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 669 | u32 id, id_min, id_max; |
| 670 | vnet_sw_interface_t template; |
| 671 | |
| 672 | hw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 673 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 674 | { |
| 675 | error = clib_error_return (0, "unknown interface `%U'", |
| 676 | format_unformat_error, input); |
| 677 | goto done; |
| 678 | } |
| 679 | |
Dave Barach | b7b9299 | 2018-10-17 10:38:51 -0400 | [diff] [blame] | 680 | clib_memset (&template, 0, sizeof (template)); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 681 | template.sub.eth.raw_flags = 0; |
| 682 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 683 | if (unformat (input, "%d default", &id_min)) |
| 684 | { |
| 685 | id_max = id_min; |
| 686 | template.sub.eth.flags.default_sub = 1; |
| 687 | } |
| 688 | else if (unformat (input, "%d untagged", &id_min)) |
| 689 | { |
| 690 | id_max = id_min; |
| 691 | template.sub.eth.flags.no_tags = 1; |
| 692 | template.sub.eth.flags.exact_match = 1; |
| 693 | } |
| 694 | else if (unformat (input, "%d dot1q", &id_min)) |
| 695 | { |
| 696 | /* parse dot1q config */ |
| 697 | id_max = id_min; |
| 698 | error = parse_vlan_sub_interfaces (input, &template); |
| 699 | if (error) |
| 700 | goto done; |
| 701 | } |
| 702 | else if (unformat (input, "%d dot1ad", &id_min)) |
| 703 | { |
| 704 | /* parse dot1ad config */ |
| 705 | id_max = id_min; |
| 706 | template.sub.eth.flags.dot1ad = 1; |
| 707 | error = parse_vlan_sub_interfaces (input, &template); |
| 708 | if (error) |
| 709 | goto done; |
| 710 | } |
| 711 | else if (unformat (input, "%d-%d", &id_min, &id_max)) |
| 712 | { |
| 713 | template.sub.eth.flags.one_tag = 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 714 | template.sub.eth.flags.exact_match = 1; |
| 715 | if (id_min > id_max) |
| 716 | goto id_error; |
| 717 | } |
| 718 | else if (unformat (input, "%d", &id_min)) |
| 719 | { |
| 720 | id_max = id_min; |
| 721 | template.sub.eth.flags.one_tag = 1; |
| 722 | template.sub.eth.outer_vlan_id = id_min; |
| 723 | template.sub.eth.flags.exact_match = 1; |
| 724 | } |
| 725 | else |
| 726 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 727 | id_error: |
| 728 | error = clib_error_return (0, "expected ID or ID MIN-MAX, got `%U'", |
| 729 | format_unformat_error, input); |
| 730 | goto done; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 731 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 732 | |
| 733 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 734 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 735 | if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) |
| 736 | { |
| 737 | error = |
| 738 | clib_error_return (0, |
| 739 | "not allowed as %v belong to a BondEthernet interface", |
| 740 | hi->name); |
| 741 | goto done; |
| 742 | } |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 743 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 744 | for (id = id_min; id <= id_max; id++) |
| 745 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 746 | uword *p; |
| 747 | vnet_interface_main_t *im = &vnm->interface_main; |
| 748 | u64 sup_and_sub_key = ((u64) (hi->sw_if_index) << 32) | (u64) id; |
| 749 | u64 *kp; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 750 | |
| 751 | p = hash_get_mem (im->sw_if_index_by_sup_and_sub, &sup_and_sub_key); |
| 752 | if (p) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 753 | { |
| 754 | if (CLIB_DEBUG > 0) |
| 755 | clib_warning ("sup sw_if_index %d, sub id %d already exists\n", |
| 756 | hi->sw_if_index, id); |
| 757 | continue; |
| 758 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 759 | |
| 760 | kp = clib_mem_alloc (sizeof (*kp)); |
| 761 | *kp = sup_and_sub_key; |
| 762 | |
| 763 | template.type = VNET_SW_INTERFACE_TYPE_SUB; |
Eyal Bari | c5b1360 | 2016-11-24 19:42:43 +0200 | [diff] [blame] | 764 | template.flood_class = VNET_FLOOD_CLASS_NORMAL; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 765 | template.sup_sw_if_index = hi->sw_if_index; |
| 766 | template.sub.id = id; |
Eyal Bari | a4509cf | 2016-09-26 09:24:09 +0300 | [diff] [blame] | 767 | if (id_min < id_max) |
| 768 | template.sub.eth.outer_vlan_id = id; |
| 769 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 770 | error = vnet_create_sw_interface (vnm, &template, &sw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 771 | if (error) |
| 772 | goto done; |
Dave Barach | 16ad6ae | 2016-07-28 17:55:30 -0400 | [diff] [blame] | 773 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 774 | hash_set (hi->sub_interface_sw_if_index_by_id, id, sw_if_index); |
| 775 | 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] | 776 | vlib_cli_output (vm, "%U\n", format_vnet_sw_if_index_name, |
| 777 | vnet_get_main (), sw_if_index); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 778 | } |
| 779 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 780 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 781 | return error; |
| 782 | } |
| 783 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 784 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 785 | * This command is used to add VLAN IDs to interfaces, also known as subinterfaces. |
| 786 | * The primary input to this command is the '<em>interface</em>' and '<em>subId</em>' |
| 787 | * (subinterface Id) parameters. If no additional VLAN ID is provide, the VLAN ID is |
| 788 | * assumed to be the '<em>subId</em>'. The VLAN ID and '<em>subId</em>' can be different, |
| 789 | * but this is not recommended. |
| 790 | * |
| 791 | * This command has several variations: |
| 792 | * - <b>create sub-interfaces <interface> <subId></b> - Create a subinterface to |
| 793 | * process packets with a given 802.1q VLAN ID (same value as the '<em>subId</em>'). |
| 794 | * |
| 795 | * - <b>create sub-interfaces <interface> <subId> default</b> - Adding the |
| 796 | * '<em>default</em>' parameter indicates that packets with VLAN IDs that do not |
| 797 | * match any other subinterfaces should be sent to this subinterface. |
| 798 | * |
| 799 | * - <b>create sub-interfaces <interface> <subId> untagged</b> - Adding the |
| 800 | * '<em>untagged</em>' parameter indicates that packets no VLAN IDs should be sent |
| 801 | * to this subinterface. |
| 802 | * |
| 803 | * - <b>create sub-interfaces <interface> <subId>-<subId></b> - Create a range of |
| 804 | * subinterfaces to handle a range of VLAN IDs. |
| 805 | * |
| 806 | * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any [exact-match]</b> - |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 807 | * Use this command to specify the outer VLAN ID, to either be explicit or to make the |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 808 | * VLAN ID different from the '<em>subId</em>'. |
| 809 | * |
| 810 | * - <b>create sub-interfaces <interface> <subId> dot1q|dot1ad <vlanId>|any inner-dot1q |
| 811 | * <vlanId>|any [exact-match]</b> - Use this command to specify the outer VLAN ID and |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 812 | * the inner VLAN ID. |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 813 | * |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 814 | * When '<em>dot1q</em>' or '<em>dot1ad</em>' is explicitly entered, subinterfaces |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 815 | * can be configured as either exact-match or non-exact match. Non-exact match is the CLI |
| 816 | * default. If '<em>exact-match</em>' is specified, packets must have the same number of |
| 817 | * VLAN tags as the configuration. For non-exact-match, packets must at least that number |
| 818 | * of tags. L3 (routed) interfaces must be configured as exact-match. L2 interfaces are |
| 819 | * typically configured as non-exact-match. If '<em>dot1q</em>' or '<em>dot1ad</em>' is NOT |
| 820 | * entered, then the default behavior is exact-match. |
| 821 | * |
| 822 | * Use the '<em>show interface</em>' command to display all subinterfaces. |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 823 | * |
| 824 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 825 | * @parblock |
| 826 | * Example of how to create a VLAN subinterface 11 to process packets on 802.1q VLAN ID 11: |
| 827 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 828 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 829 | * The previous example is shorthand and is equivalent to: |
| 830 | * @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] | 831 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 832 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 833 | * Example of how to create a subinterface number that is different from the VLAN ID: |
| 834 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 835 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 836 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 837 | * Examples of how to create q-in-q and q-in-any subinterfaces: |
| 838 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1q 100 inner-dot1q 200} |
| 839 | * @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] | 840 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 841 | * Examples of how to create dot1ad interfaces: |
| 842 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 11 dot1ad 11} |
| 843 | * @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] | 844 | * |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 845 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 846 | * Examples of '<em>exact-match</em>' versus non-exact match. A packet with |
| 847 | * outer VLAN 100 and inner VLAN 200 would match this interface, because the default |
| 848 | * is non-exact match: |
| 849 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 dot1q 100} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 850 | * |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 851 | * However, the same packet would NOT match this interface because '<em>exact-match</em>' |
| 852 | * is specified and only one VLAN is configured, but packet contains two VLANs: |
| 853 | * @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] | 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 | * Example of how to created a subinterface to process untagged packets: |
| 857 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 5 untagged} |
| 858 | * |
| 859 | * Example of how to created a subinterface to process any packet with a VLAN ID that |
| 860 | * does not match any other subinterface: |
| 861 | * @cliexcmd{create sub-interfaces GigabitEthernet2/0/0 7 default} |
| 862 | * |
| 863 | * When subinterfaces are created, they are in the down state. Example of how to |
| 864 | * enable a newly created subinterface: |
| 865 | * @cliexcmd{set interface GigabitEthernet2/0/0.7 up} |
| 866 | * @endparblock |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 867 | ?*/ |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 868 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 869 | VLIB_CLI_COMMAND (create_sub_interfaces_command, static) = { |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 870 | .path = "create sub-interfaces", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 871 | .short_help = "create sub-interfaces <interface> " |
| 872 | "{<subId> [default|untagged]} | " |
| 873 | "{<subId>-<subId>} | " |
| 874 | "{<subId> dot1q|dot1ad <vlanId>|any [inner-dot1q <vlanId>|any] [exact-match]}", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 875 | .function = create_sub_interfaces, |
| 876 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 877 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 878 | |
| 879 | static clib_error_t * |
| 880 | set_state (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 881 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 882 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 883 | vnet_main_t *vnm = vnet_get_main (); |
| 884 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 885 | u32 sw_if_index, flags; |
| 886 | |
| 887 | sw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 888 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 889 | { |
| 890 | error = clib_error_return (0, "unknown interface `%U'", |
| 891 | format_unformat_error, input); |
| 892 | goto done; |
| 893 | } |
| 894 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 895 | if (!unformat (input, "%U", unformat_vnet_sw_interface_flags, &flags)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 896 | { |
| 897 | error = clib_error_return (0, "unknown flags `%U'", |
| 898 | format_unformat_error, input); |
| 899 | goto done; |
| 900 | } |
| 901 | |
| 902 | error = vnet_sw_interface_set_flags (vnm, sw_if_index, flags); |
| 903 | if (error) |
| 904 | goto done; |
| 905 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 906 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 907 | return error; |
| 908 | } |
| 909 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 910 | |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 911 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 912 | * This command is used to change the admin state (up/down) of an interface. |
| 913 | * |
| 914 | * If an interface is down, the optional '<em>punt</em>' flag can also be set. |
| 915 | * The '<em>punt</em>' flag implies the interface is disabled for forwarding |
| 916 | * but punt all traffic to slow-path. Use the '<em>enable</em>' flag to clear |
| 917 | * '<em>punt</em>' flag (interface is still down). |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 918 | * |
| 919 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 920 | * Example of how to configure the admin state of an interface to '<em>up</em?': |
| 921 | * @cliexcmd{set interface state GigabitEthernet2/0/0 up} |
| 922 | * Example of how to configure the admin state of an interface to '<em>down</em?': |
| 923 | * @cliexcmd{set interface state GigabitEthernet2/0/0 down} |
Keith Burns (alagalah) | 6ef7bb9 | 2016-09-10 14:55:04 -0700 | [diff] [blame] | 924 | ?*/ |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 925 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 926 | VLIB_CLI_COMMAND (set_state_command, static) = { |
| 927 | .path = "set interface state", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 928 | .short_help = "set interface state <interface> [up|down|punt|enable]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 929 | .function = set_state, |
| 930 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 931 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 932 | |
| 933 | static clib_error_t * |
| 934 | set_unnumbered (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 935 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 936 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 937 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 938 | u32 unnumbered_sw_if_index = ~0; |
| 939 | u32 inherit_from_sw_if_index = ~0; |
| 940 | int enable = 1; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 941 | |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 942 | if (unformat (input, "%U use %U", |
| 943 | unformat_vnet_sw_interface, vnm, &unnumbered_sw_if_index, |
| 944 | unformat_vnet_sw_interface, vnm, &inherit_from_sw_if_index)) |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 945 | enable = 1; |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 946 | else if (unformat (input, "del %U", |
| 947 | unformat_vnet_sw_interface, vnm, |
| 948 | &unnumbered_sw_if_index)) |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 949 | enable = 0; |
Igor Mikhailov (imichail) | ab3e42b | 2016-09-25 15:11:53 -0700 | [diff] [blame] | 950 | else |
| 951 | return clib_error_return (0, "parse error '%U'", |
| 952 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 953 | |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 954 | if (~0 == unnumbered_sw_if_index) |
| 955 | return clib_error_return (0, "Specify the unnumbered interface"); |
| 956 | if (enable && ~0 == inherit_from_sw_if_index) |
Paul Vinciguerra | bdc0e6b | 2018-09-22 05:32:50 -0700 | [diff] [blame] | 957 | return clib_error_return (0, "When enabling unnumbered specify the" |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 958 | " IP enabled interface that it uses"); |
Neale Ranns | 898273f | 2017-03-18 02:57:38 -0700 | [diff] [blame] | 959 | |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 960 | vnet_sw_interface_update_unnumbered (unnumbered_sw_if_index, |
| 961 | inherit_from_sw_if_index, enable); |
Neale Ranns | 898273f | 2017-03-18 02:57:38 -0700 | [diff] [blame] | 962 | |
Neale Ranns | 2ae2bc5 | 2018-03-16 03:22:39 -0700 | [diff] [blame] | 963 | return (NULL); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 964 | } |
| 965 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 966 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 967 | VLIB_CLI_COMMAND (set_unnumbered_command, static) = { |
| 968 | .path = "set interface unnumbered", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 969 | .short_help = "set interface unnumbered [<interface> use <interface> | del <interface>]", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 970 | .function = set_unnumbered, |
| 971 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 972 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 973 | |
| 974 | |
| 975 | |
| 976 | static clib_error_t * |
| 977 | set_hw_class (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 978 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 979 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 980 | vnet_main_t *vnm = vnet_get_main (); |
| 981 | vnet_interface_main_t *im = &vnm->interface_main; |
| 982 | clib_error_t *error; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 983 | u32 hw_if_index, hw_class_index; |
| 984 | |
| 985 | hw_if_index = ~0; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 986 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 987 | { |
| 988 | error = clib_error_return (0, "unknown hardware interface `%U'", |
| 989 | format_unformat_error, input); |
| 990 | goto done; |
| 991 | } |
| 992 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 993 | if (!unformat_user (input, unformat_hash_string, |
| 994 | im->hw_interface_class_by_name, &hw_class_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 995 | { |
| 996 | error = clib_error_return (0, "unknown hardware class `%U'", |
| 997 | format_unformat_error, input); |
| 998 | goto done; |
| 999 | } |
| 1000 | |
| 1001 | error = vnet_hw_interface_set_class (vnm, hw_if_index, hw_class_index); |
| 1002 | if (error) |
| 1003 | goto done; |
| 1004 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1005 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1006 | return error; |
| 1007 | } |
| 1008 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1009 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1010 | VLIB_CLI_COMMAND (set_hw_class_command, static) = { |
| 1011 | .path = "set interface hw-class", |
| 1012 | .short_help = "Set interface hardware class", |
| 1013 | .function = set_hw_class, |
| 1014 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1015 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1016 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1017 | static clib_error_t * |
| 1018 | vnet_interface_cli_init (vlib_main_t * vm) |
| 1019 | { |
| 1020 | return 0; |
| 1021 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1022 | |
| 1023 | VLIB_INIT_FUNCTION (vnet_interface_cli_init); |
| 1024 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1025 | static clib_error_t * |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1026 | renumber_interface_command_fn (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1027 | unformat_input_t * input, |
| 1028 | vlib_cli_command_t * cmd) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1029 | { |
| 1030 | u32 hw_if_index; |
| 1031 | u32 new_dev_instance; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1032 | vnet_main_t *vnm = vnet_get_main (); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1033 | int rv; |
| 1034 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1035 | if (!unformat_user (input, unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1036 | return clib_error_return (0, "unknown hardware interface `%U'", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1037 | format_unformat_error, input); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1038 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1039 | if (!unformat (input, "%d", &new_dev_instance)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1040 | return clib_error_return (0, "new dev instance missing"); |
| 1041 | |
| 1042 | rv = vnet_interface_name_renumber (hw_if_index, new_dev_instance); |
| 1043 | |
| 1044 | switch (rv) |
| 1045 | { |
| 1046 | case 0: |
| 1047 | break; |
| 1048 | |
| 1049 | default: |
| 1050 | return clib_error_return (0, "vnet_interface_name_renumber returned %d", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1051 | rv); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1052 | |
| 1053 | } |
| 1054 | |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
| 1058 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1059 | /* *INDENT-OFF* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1060 | VLIB_CLI_COMMAND (renumber_interface_command, static) = { |
| 1061 | .path = "renumber interface", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1062 | .short_help = "renumber interface <interface> <new-dev-instance>", |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1063 | .function = renumber_interface_command_fn, |
| 1064 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1065 | /* *INDENT-ON* */ |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 1066 | |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1067 | static clib_error_t * |
| 1068 | promiscuous_cmd (vlib_main_t * vm, |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1069 | unformat_input_t * input, vlib_cli_command_t * cmd) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1070 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1071 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1072 | u32 hw_if_index; |
| 1073 | u32 flags = ETHERNET_INTERFACE_FLAG_ACCEPT_ALL; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1074 | ethernet_main_t *em = ðernet_main; |
| 1075 | ethernet_interface_t *eif; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1076 | |
| 1077 | if (unformat (input, "on %U", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1078 | unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1079 | ; |
| 1080 | else if (unformat (input, "off %U", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1081 | unformat_ethernet_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1082 | flags = 0; |
| 1083 | else |
| 1084 | return clib_error_return (0, "unknown input `%U'", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1085 | format_unformat_error, input); |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1086 | |
| 1087 | eif = ethernet_get_interface (em, hw_if_index); |
| 1088 | if (!eif) |
| 1089 | return clib_error_return (0, "not supported"); |
| 1090 | |
| 1091 | ethernet_set_flags (vnm, hw_if_index, flags); |
| 1092 | return 0; |
| 1093 | } |
| 1094 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1095 | /* *INDENT-OFF* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1096 | VLIB_CLI_COMMAND (set_interface_promiscuous_cmd, static) = { |
| 1097 | .path = "set interface promiscuous", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1098 | .short_help = "set interface promiscuous [on|off] <interface>", |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1099 | .function = promiscuous_cmd, |
| 1100 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1101 | /* *INDENT-ON* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1102 | |
| 1103 | static clib_error_t * |
| 1104 | mtu_cmd (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1105 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1106 | vnet_main_t *vnm = vnet_get_main (); |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1107 | u32 hw_if_index, sw_if_index, mtu; |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1108 | ethernet_main_t *em = ðernet_main; |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1109 | u32 mtus[VNET_N_MTU] = { 0, 0, 0, 0 }; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1110 | |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1111 | if (unformat (input, "%d %U", &mtu, |
| 1112 | unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1113 | { |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1114 | /* |
| 1115 | * Change physical MTU on interface. Only supported for Ethernet |
| 1116 | * interfaces |
| 1117 | */ |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1118 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 1119 | ethernet_interface_t *eif = ethernet_get_interface (em, hw_if_index); |
| 1120 | |
| 1121 | if (!eif) |
| 1122 | return clib_error_return (0, "not supported"); |
| 1123 | |
| 1124 | if (mtu < hi->min_supported_packet_bytes) |
| 1125 | return clib_error_return (0, "Invalid mtu (%d): " |
| 1126 | "must be >= min pkt bytes (%d)", mtu, |
| 1127 | hi->min_supported_packet_bytes); |
| 1128 | |
| 1129 | if (mtu > hi->max_supported_packet_bytes) |
| 1130 | return clib_error_return (0, "Invalid mtu (%d): must be <= (%d)", mtu, |
| 1131 | hi->max_supported_packet_bytes); |
| 1132 | |
| 1133 | vnet_hw_interface_set_mtu (vnm, hw_if_index, mtu); |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1134 | goto done; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1135 | } |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1136 | else if (unformat (input, "packet %d %U", &mtu, |
| 1137 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1138 | /* Set default packet MTU (including L3 header */ |
| 1139 | mtus[VNET_MTU_L3] = mtu; |
| 1140 | else if (unformat (input, "ip4 %d %U", &mtu, |
| 1141 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1142 | mtus[VNET_MTU_IP4] = mtu; |
| 1143 | else if (unformat (input, "ip6 %d %U", &mtu, |
| 1144 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1145 | mtus[VNET_MTU_IP6] = mtu; |
| 1146 | else if (unformat (input, "mpls %d %U", &mtu, |
| 1147 | unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1148 | mtus[VNET_MTU_MPLS] = mtu; |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1149 | else |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1150 | return clib_error_return (0, "unknown input `%U'", |
| 1151 | format_unformat_error, input); |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1152 | |
| 1153 | vnet_sw_interface_set_protocol_mtu (vnm, sw_if_index, mtus); |
| 1154 | |
| 1155 | done: |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1156 | return 0; |
| 1157 | } |
| 1158 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1159 | /* *INDENT-OFF* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1160 | VLIB_CLI_COMMAND (set_interface_mtu_cmd, static) = { |
| 1161 | .path = "set interface mtu", |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 1162 | .short_help = "set interface mtu [packet|ip4|ip6|mpls] <value> <interface>", |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1163 | .function = mtu_cmd, |
| 1164 | }; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1165 | /* *INDENT-ON* */ |
Damjan Marion | 8358ff9 | 2016-04-15 14:26:00 +0200 | [diff] [blame] | 1166 | |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1167 | static clib_error_t * |
| 1168 | set_interface_mac_address (vlib_main_t * vm, unformat_input_t * input, |
| 1169 | vlib_cli_command_t * cmd) |
| 1170 | { |
| 1171 | vnet_main_t *vnm = vnet_get_main (); |
Neale Ranns | d867a7c | 2017-10-04 02:29:07 -0700 | [diff] [blame] | 1172 | vnet_sw_interface_t *si = NULL; |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1173 | clib_error_t *error = 0; |
| 1174 | u32 sw_if_index = ~0; |
John Lo | 62fcc0a | 2017-10-31 14:31:10 -0400 | [diff] [blame] | 1175 | u8 mac[6] = { 0 }; |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1176 | |
| 1177 | if (!unformat_user (input, unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1178 | { |
| 1179 | error = clib_error_return (0, "unknown interface `%U'", |
| 1180 | format_unformat_error, input); |
| 1181 | goto done; |
| 1182 | } |
John Lo | 62fcc0a | 2017-10-31 14:31:10 -0400 | [diff] [blame] | 1183 | if (!unformat_user (input, unformat_ethernet_address, mac)) |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1184 | { |
| 1185 | error = clib_error_return (0, "expected mac address `%U'", |
| 1186 | format_unformat_error, input); |
| 1187 | goto done; |
| 1188 | } |
Neale Ranns | d867a7c | 2017-10-04 02:29:07 -0700 | [diff] [blame] | 1189 | si = vnet_get_sw_interface (vnm, sw_if_index); |
| 1190 | 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] | 1191 | done: |
| 1192 | return error; |
| 1193 | } |
| 1194 | |
| 1195 | /*? |
| 1196 | * The '<em>set interface mac address </em>' command allows to set MAC address of given interface. |
| 1197 | * In case of NIC interfaces the one has to support MAC address change. A side effect of MAC address |
| 1198 | * change are changes of MAC addresses in FIB tables (ipv4 and ipv6). |
| 1199 | * |
| 1200 | * @cliexpar |
| 1201 | * @parblock |
| 1202 | * Example of how to change MAC Address of interface: |
| 1203 | * @cliexcmd{set interface mac address GigabitEthernet0/8/0 aa:bb:cc:dd:ee:01} |
| 1204 | * @cliexcmd{set interface mac address host-vpp0 aa:bb:cc:dd:ee:02} |
| 1205 | * @cliexcmd{set interface mac address tap-0 aa:bb:cc:dd:ee:03} |
| 1206 | * @cliexcmd{set interface mac address pg0 aa:bb:cc:dd:ee:04} |
| 1207 | * @endparblock |
| 1208 | ?*/ |
| 1209 | /* *INDENT-OFF* */ |
| 1210 | VLIB_CLI_COMMAND (set_interface_mac_address_cmd, static) = { |
| 1211 | .path = "set interface mac address", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1212 | .short_help = "set interface mac address <interface> <mac-address>", |
Pavel Kotucek | c631f2d | 2016-09-26 10:40:02 +0200 | [diff] [blame] | 1213 | .function = set_interface_mac_address, |
| 1214 | }; |
| 1215 | /* *INDENT-ON* */ |
| 1216 | |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1217 | static clib_error_t * |
| 1218 | set_tag (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1219 | { |
| 1220 | vnet_main_t *vnm = vnet_get_main (); |
| 1221 | u32 sw_if_index = ~0; |
| 1222 | u8 *tag = 0; |
| 1223 | |
| 1224 | if (!unformat (input, "%U %s", unformat_vnet_sw_interface, |
| 1225 | vnm, &sw_if_index, &tag)) |
| 1226 | return clib_error_return (0, "unknown input `%U'", |
| 1227 | format_unformat_error, input); |
| 1228 | |
| 1229 | vnet_set_sw_interface_tag (vnm, tag, sw_if_index); |
| 1230 | |
| 1231 | return 0; |
| 1232 | } |
| 1233 | |
| 1234 | /* *INDENT-OFF* */ |
| 1235 | VLIB_CLI_COMMAND (set_tag_command, static) = { |
| 1236 | .path = "set interface tag", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1237 | .short_help = "set interface tag <interface> <tag>", |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1238 | .function = set_tag, |
| 1239 | }; |
| 1240 | /* *INDENT-ON* */ |
| 1241 | |
| 1242 | static clib_error_t * |
| 1243 | clear_tag (vlib_main_t * vm, unformat_input_t * input, |
| 1244 | vlib_cli_command_t * cmd) |
| 1245 | { |
| 1246 | vnet_main_t *vnm = vnet_get_main (); |
| 1247 | u32 sw_if_index = ~0; |
| 1248 | |
| 1249 | if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)) |
| 1250 | return clib_error_return (0, "unknown input `%U'", |
| 1251 | format_unformat_error, input); |
| 1252 | |
| 1253 | vnet_clear_sw_interface_tag (vnm, sw_if_index); |
| 1254 | |
| 1255 | return 0; |
| 1256 | } |
| 1257 | |
| 1258 | /* *INDENT-OFF* */ |
| 1259 | VLIB_CLI_COMMAND (clear_tag_command, static) = { |
| 1260 | .path = "clear interface tag", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1261 | .short_help = "clear interface tag <interface>", |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1262 | .function = clear_tag, |
| 1263 | }; |
| 1264 | /* *INDENT-ON* */ |
| 1265 | |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1266 | static clib_error_t * |
Neale Ranns | 1855b8e | 2018-07-11 10:31:26 -0700 | [diff] [blame] | 1267 | set_ip_directed_broadcast (vlib_main_t * vm, |
| 1268 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1269 | { |
| 1270 | vnet_main_t *vnm = vnet_get_main (); |
| 1271 | u32 sw_if_index = ~0; |
| 1272 | u8 enable = 0; |
| 1273 | |
| 1274 | if (!unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index)); |
| 1275 | else if (unformat (input, "enable")) |
| 1276 | enable = 1; |
| 1277 | else if (unformat (input, "disable")) |
| 1278 | enable = 0; |
| 1279 | else |
| 1280 | return clib_error_return (0, "unknown input: `%U'", |
| 1281 | format_unformat_error, input); |
| 1282 | |
| 1283 | if (~0 == sw_if_index) |
| 1284 | return clib_error_return (0, "specify an interface: `%U'", |
| 1285 | format_unformat_error, input); |
| 1286 | |
| 1287 | vnet_sw_interface_ip_directed_broadcast (vnm, sw_if_index, enable); |
| 1288 | |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | /*? |
| 1293 | * This command is used to enable/disable IP directed broadcast |
| 1294 | * If directed broadcast is enabled a packet sent to the interface's |
| 1295 | * subnet broadcast address will be sent L2 broadcast on the interface, |
| 1296 | * otherwise it is dropped. |
| 1297 | ?*/ |
| 1298 | /* *INDENT-OFF* */ |
| 1299 | VLIB_CLI_COMMAND (set_ip_directed_broadcast_command, static) = { |
| 1300 | .path = "set interface ip directed-broadcast", |
| 1301 | .short_help = "set interface enable <interface> <enable|disable>", |
| 1302 | .function = set_ip_directed_broadcast, |
| 1303 | }; |
| 1304 | /* *INDENT-ON* */ |
| 1305 | |
| 1306 | static clib_error_t * |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1307 | set_hw_interface_rx_mode (vnet_main_t * vnm, u32 hw_if_index, |
| 1308 | u32 queue_id, vnet_hw_interface_rx_mode mode) |
| 1309 | { |
| 1310 | vnet_hw_interface_t *hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 1311 | vnet_device_class_t *dev_class = |
| 1312 | vnet_get_device_class (vnm, hw->dev_class_index); |
| 1313 | clib_error_t *error; |
| 1314 | vnet_hw_interface_rx_mode old_mode; |
| 1315 | int rv; |
| 1316 | |
Damjan Marion | 4e53a0d | 2017-06-21 14:29:44 +0200 | [diff] [blame] | 1317 | if (mode == VNET_HW_INTERFACE_RX_MODE_DEFAULT) |
| 1318 | mode = hw->default_rx_mode; |
| 1319 | |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1320 | rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &old_mode); |
| 1321 | switch (rv) |
| 1322 | { |
| 1323 | case 0: |
| 1324 | if (old_mode == mode) |
| 1325 | return 0; /* same rx-mode, no change */ |
| 1326 | break; |
| 1327 | case VNET_API_ERROR_INVALID_INTERFACE: |
| 1328 | return clib_error_return (0, "invalid interface"); |
Steven | bd8a611 | 2017-07-30 10:29:26 -0700 | [diff] [blame] | 1329 | case VNET_API_ERROR_INVALID_QUEUE: |
| 1330 | return clib_error_return (0, "invalid queue"); |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1331 | default: |
| 1332 | return clib_error_return (0, "unknown error"); |
| 1333 | } |
| 1334 | |
| 1335 | if (dev_class->rx_mode_change_function) |
| 1336 | { |
| 1337 | error = dev_class->rx_mode_change_function (vnm, hw_if_index, queue_id, |
| 1338 | mode); |
| 1339 | if (error) |
| 1340 | return (error); |
| 1341 | } |
| 1342 | |
| 1343 | rv = vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode); |
| 1344 | switch (rv) |
| 1345 | { |
| 1346 | case 0: |
| 1347 | break; |
| 1348 | case VNET_API_ERROR_UNSUPPORTED: |
| 1349 | return clib_error_return (0, "unsupported"); |
| 1350 | case VNET_API_ERROR_INVALID_INTERFACE: |
| 1351 | return clib_error_return (0, "invalid interface"); |
Steven | bd8a611 | 2017-07-30 10:29:26 -0700 | [diff] [blame] | 1352 | case VNET_API_ERROR_INVALID_QUEUE: |
| 1353 | return clib_error_return (0, "invalid queue"); |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1354 | default: |
| 1355 | return clib_error_return (0, "unknown error"); |
| 1356 | } |
| 1357 | |
| 1358 | return 0; |
| 1359 | } |
| 1360 | |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1361 | clib_error_t * |
| 1362 | set_hw_interface_change_rx_mode (vnet_main_t * vnm, u32 hw_if_index, |
| 1363 | u8 queue_id_valid, u32 queue_id, |
| 1364 | vnet_hw_interface_rx_mode mode) |
| 1365 | { |
| 1366 | clib_error_t *error = 0; |
| 1367 | vnet_hw_interface_t *hw; |
| 1368 | int i; |
| 1369 | |
| 1370 | hw = vnet_get_hw_interface (vnm, hw_if_index); |
| 1371 | |
| 1372 | if (queue_id_valid == 0) |
| 1373 | { |
| 1374 | for (i = 0; i < vec_len (hw->dq_runtime_index_by_queue); i++) |
| 1375 | { |
| 1376 | error = set_hw_interface_rx_mode (vnm, hw_if_index, i, mode); |
| 1377 | if (error) |
| 1378 | break; |
| 1379 | } |
| 1380 | hw->default_rx_mode = mode; |
| 1381 | } |
| 1382 | else |
| 1383 | error = set_hw_interface_rx_mode (vnm, hw_if_index, queue_id, mode); |
| 1384 | |
| 1385 | return (error); |
| 1386 | } |
| 1387 | |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1388 | static clib_error_t * |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1389 | set_interface_rx_mode (vlib_main_t * vm, unformat_input_t * input, |
| 1390 | vlib_cli_command_t * cmd) |
| 1391 | { |
| 1392 | clib_error_t *error = 0; |
| 1393 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1394 | vnet_main_t *vnm = vnet_get_main (); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1395 | u32 hw_if_index = (u32) ~ 0; |
| 1396 | u32 queue_id = (u32) ~ 0; |
| 1397 | vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN; |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1398 | u8 queue_id_valid = 0; |
Dave Barach | 7be864a | 2016-11-28 11:41:35 -0500 | [diff] [blame] | 1399 | |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 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)) |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1409 | queue_id_valid = 1; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1410 | else if (unformat (line_input, "polling")) |
| 1411 | mode = VNET_HW_INTERFACE_RX_MODE_POLLING; |
| 1412 | else if (unformat (line_input, "interrupt")) |
| 1413 | mode = VNET_HW_INTERFACE_RX_MODE_INTERRUPT; |
| 1414 | else if (unformat (line_input, "adaptive")) |
| 1415 | mode = VNET_HW_INTERFACE_RX_MODE_ADAPTIVE; |
| 1416 | else |
| 1417 | { |
| 1418 | error = clib_error_return (0, "parse error: '%U'", |
| 1419 | format_unformat_error, line_input); |
| 1420 | unformat_free (line_input); |
| 1421 | return error; |
| 1422 | } |
| 1423 | } |
| 1424 | |
| 1425 | unformat_free (line_input); |
| 1426 | |
| 1427 | if (hw_if_index == (u32) ~ 0) |
| 1428 | return clib_error_return (0, "please specify valid interface name"); |
| 1429 | |
| 1430 | if (mode == VNET_HW_INTERFACE_RX_MODE_UNKNOWN) |
| 1431 | return clib_error_return (0, "please specify valid rx-mode"); |
| 1432 | |
Steven | ad8015b | 2017-10-29 22:10:46 -0700 | [diff] [blame] | 1433 | error = set_hw_interface_change_rx_mode (vnm, hw_if_index, queue_id_valid, |
| 1434 | queue_id, mode); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1435 | |
Steven | e3a395c | 2017-05-09 16:19:50 -0700 | [diff] [blame] | 1436 | return (error); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | /*? |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1440 | * This command is used to assign the RX packet processing mode (polling, |
| 1441 | * interrupt, adaptive) of the a given interface, and optionally a |
| 1442 | * given queue. If the '<em>queue</em>' is not provided, the '<em>mode</em>' |
| 1443 | * is applied to all queues of the interface. Not all interfaces support |
| 1444 | * all modes. To display the current rx-mode use the command |
| 1445 | * '<em>show interface rx-placement</em>'. |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1446 | * |
| 1447 | * @cliexpar |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1448 | * Example of how to assign rx-mode to all queues on an interface: |
| 1449 | * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 polling} |
| 1450 | * Example of how to assign rx-mode to one queue of an interface: |
| 1451 | * @cliexcmd{set interface rx-mode VirtualEthernet0/0/12 queue 0 interrupt} |
| 1452 | * Example of how to display the rx-mode of all interfaces: |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1453 | * @cliexstart{show interface rx-placement} |
| 1454 | * Thread 1 (vpp_wk_0): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1455 | * node dpdk-input: |
| 1456 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1457 | * node vhost-user-input: |
| 1458 | * VirtualEthernet0/0/12 queue 0 (interrupt) |
| 1459 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1460 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1461 | * VirtualEthernet0/0/13 queue 2 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1462 | * Thread 2 (vpp_wk_1): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1463 | * node dpdk-input: |
| 1464 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1465 | * node vhost-user-input: |
| 1466 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1467 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1468 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1469 | * VirtualEthernet0/0/13 queue 3 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1470 | * @cliexend |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1471 | ?*/ |
| 1472 | /* *INDENT-OFF* */ |
Damjan Marion | fe7d4a2 | 2018-04-13 19:43:39 +0200 | [diff] [blame] | 1473 | VLIB_CLI_COMMAND (cmd_set_if_rx_mode,static) = { |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1474 | .path = "set interface rx-mode", |
| 1475 | .short_help = "set interface rx-mode <interface> [queue <n>] [polling | interrupt | adaptive]", |
| 1476 | .function = set_interface_rx_mode, |
| 1477 | }; |
| 1478 | /* *INDENT-ON* */ |
| 1479 | |
| 1480 | static clib_error_t * |
| 1481 | show_interface_rx_placement_fn (vlib_main_t * vm, unformat_input_t * input, |
| 1482 | vlib_cli_command_t * cmd) |
| 1483 | { |
| 1484 | u8 *s = 0; |
| 1485 | vnet_main_t *vnm = vnet_get_main (); |
| 1486 | vnet_device_input_runtime_t *rt; |
| 1487 | vnet_device_and_queue_t *dq; |
| 1488 | vlib_node_t *pn = vlib_get_node_by_name (vm, (u8 *) "device-input"); |
| 1489 | uword si; |
| 1490 | int index = 0; |
| 1491 | |
| 1492 | /* *INDENT-OFF* */ |
| 1493 | foreach_vlib_main (({ |
| 1494 | clib_bitmap_foreach (si, pn->sibling_bitmap, |
| 1495 | ({ |
| 1496 | rt = vlib_node_get_runtime_data (this_vlib_main, si); |
| 1497 | |
| 1498 | if (vec_len (rt->devices_and_queues)) |
| 1499 | s = format (s, " node %U:\n", format_vlib_node_name, vm, si); |
| 1500 | |
| 1501 | vec_foreach (dq, rt->devices_and_queues) |
| 1502 | { |
Steven | 9d6d989 | 2017-06-30 07:15:02 -0700 | [diff] [blame] | 1503 | vnet_hw_interface_t *hi = vnet_get_hw_interface (vnm, |
| 1504 | dq->hw_if_index); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1505 | s = format (s, " %U queue %u (%U)\n", |
Steven | 9d6d989 | 2017-06-30 07:15:02 -0700 | [diff] [blame] | 1506 | format_vnet_sw_if_index_name, vnm, hi->sw_if_index, |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1507 | dq->queue_id, |
| 1508 | format_vnet_hw_interface_rx_mode, dq->mode); |
| 1509 | } |
| 1510 | })); |
| 1511 | if (vec_len (s) > 0) |
| 1512 | { |
Steven | 84f36cb | 2018-09-26 10:44:54 -0700 | [diff] [blame] | 1513 | vlib_cli_output(vm, "Thread %u (%s):\n%v", index, |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1514 | vlib_worker_threads[index].name, s); |
| 1515 | vec_reset_length (s); |
| 1516 | } |
| 1517 | index++; |
| 1518 | })); |
| 1519 | /* *INDENT-ON* */ |
| 1520 | |
| 1521 | vec_free (s); |
| 1522 | return 0; |
| 1523 | } |
| 1524 | |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1525 | /*? |
| 1526 | * This command is used to display the interface and queue worker |
| 1527 | * thread placement. |
| 1528 | * |
| 1529 | * @cliexpar |
| 1530 | * Example of how to display the interface placement: |
| 1531 | * @cliexstart{show interface rx-placement} |
| 1532 | * Thread 1 (vpp_wk_0): |
| 1533 | * node dpdk-input: |
| 1534 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1535 | * node vhost-user-input: |
| 1536 | * VirtualEthernet0/0/12 queue 0 (polling) |
| 1537 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1538 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1539 | * VirtualEthernet0/0/13 queue 2 (polling) |
| 1540 | * Thread 2 (vpp_wk_1): |
| 1541 | * node dpdk-input: |
| 1542 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1543 | * node vhost-user-input: |
| 1544 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1545 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1546 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1547 | * VirtualEthernet0/0/13 queue 3 (polling) |
| 1548 | * @cliexend |
| 1549 | ?*/ |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1550 | /* *INDENT-OFF* */ |
| 1551 | VLIB_CLI_COMMAND (show_interface_rx_placement, static) = { |
| 1552 | .path = "show interface rx-placement", |
| 1553 | .short_help = "show interface rx-placement", |
| 1554 | .function = show_interface_rx_placement_fn, |
| 1555 | }; |
| 1556 | /* *INDENT-ON* */ |
| 1557 | |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1558 | clib_error_t * |
| 1559 | set_hw_interface_rx_placement (u32 hw_if_index, u32 queue_id, |
| 1560 | u32 thread_index, u8 is_main) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1561 | { |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1562 | vnet_main_t *vnm = vnet_get_main (); |
| 1563 | vnet_device_main_t *vdm = &vnet_device_main; |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1564 | clib_error_t *error = 0; |
| 1565 | vnet_hw_interface_rx_mode mode = VNET_HW_INTERFACE_RX_MODE_UNKNOWN; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1566 | int rv; |
| 1567 | |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1568 | if (is_main) |
| 1569 | thread_index = 0; |
| 1570 | else |
| 1571 | thread_index += vdm->first_worker_thread_index; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1572 | |
| 1573 | if (thread_index > vdm->last_worker_thread_index) |
| 1574 | return clib_error_return (0, |
| 1575 | "please specify valid worker thread or main"); |
| 1576 | |
| 1577 | rv = vnet_hw_interface_get_rx_mode (vnm, hw_if_index, queue_id, &mode); |
| 1578 | |
| 1579 | if (rv) |
| 1580 | return clib_error_return (0, "not found"); |
| 1581 | |
| 1582 | rv = vnet_hw_interface_unassign_rx_thread (vnm, hw_if_index, queue_id); |
| 1583 | |
| 1584 | if (rv) |
| 1585 | return clib_error_return (0, "not found"); |
| 1586 | |
| 1587 | vnet_hw_interface_assign_rx_thread (vnm, hw_if_index, queue_id, |
| 1588 | thread_index); |
| 1589 | vnet_hw_interface_set_rx_mode (vnm, hw_if_index, queue_id, mode); |
| 1590 | |
Mohsin Kazmi | 54f7c51 | 2018-08-23 18:28:11 +0200 | [diff] [blame] | 1591 | return (error); |
| 1592 | } |
| 1593 | |
| 1594 | static clib_error_t * |
| 1595 | set_interface_rx_placement (vlib_main_t * vm, unformat_input_t * input, |
| 1596 | vlib_cli_command_t * cmd) |
| 1597 | { |
| 1598 | clib_error_t *error = 0; |
| 1599 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1600 | vnet_main_t *vnm = vnet_get_main (); |
| 1601 | u32 hw_if_index = (u32) ~ 0; |
| 1602 | u32 queue_id = (u32) 0; |
| 1603 | u32 thread_index = (u32) ~ 0; |
| 1604 | u8 is_main = 0; |
| 1605 | |
| 1606 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1607 | return 0; |
| 1608 | |
| 1609 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1610 | { |
| 1611 | if (unformat |
| 1612 | (line_input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
| 1613 | ; |
| 1614 | else if (unformat (line_input, "queue %d", &queue_id)) |
| 1615 | ; |
| 1616 | else if (unformat (line_input, "main", &thread_index)) |
| 1617 | is_main = 1; |
| 1618 | else if (unformat (line_input, "worker %d", &thread_index)) |
| 1619 | ; |
| 1620 | else |
| 1621 | { |
| 1622 | error = clib_error_return (0, "parse error: '%U'", |
| 1623 | format_unformat_error, line_input); |
| 1624 | unformat_free (line_input); |
| 1625 | return error; |
| 1626 | } |
| 1627 | } |
| 1628 | |
| 1629 | unformat_free (line_input); |
| 1630 | |
| 1631 | if (hw_if_index == (u32) ~ 0) |
| 1632 | return clib_error_return (0, "please specify valid interface name"); |
| 1633 | |
| 1634 | error = set_hw_interface_rx_placement (hw_if_index, queue_id, thread_index, |
| 1635 | is_main); |
| 1636 | |
| 1637 | return (error); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | /*? |
| 1641 | * This command is used to assign a given interface, and optionally a |
| 1642 | * 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] | 1643 | * it defaults to 0. The '<em>worker</em>' parameter is zero based and the index |
| 1644 | * 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] | 1645 | * |
| 1646 | * @cliexpar |
| 1647 | * Example of how to display the interface placement: |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1648 | * @cliexstart{show interface rx-placement} |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1649 | * Thread 1 (vpp_wk_0): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1650 | * node dpdk-input: |
| 1651 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1652 | * node vhost-user-input: |
| 1653 | * VirtualEthernet0/0/12 queue 0 (polling) |
| 1654 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1655 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1656 | * VirtualEthernet0/0/13 queue 2 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1657 | * Thread 2 (vpp_wk_1): |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1658 | * node dpdk-input: |
| 1659 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1660 | * node vhost-user-input: |
| 1661 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1662 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1663 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1664 | * VirtualEthernet0/0/13 queue 3 (polling) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1665 | * @cliexend |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1666 | * Example of how to assign a interface and queue to a worker thread: |
| 1667 | * @cliexcmd{set interface rx-placement VirtualEthernet0/0/12 queue 1 worker 0} |
| 1668 | * Example of how to display the interface placement: |
| 1669 | * @cliexstart{show interface rx-placement} |
| 1670 | * Thread 1 (vpp_wk_0): |
| 1671 | * node dpdk-input: |
| 1672 | * GigabitEthernet7/0/0 queue 0 (polling) |
| 1673 | * node vhost-user-input: |
| 1674 | * VirtualEthernet0/0/12 queue 0 (polling) |
| 1675 | * VirtualEthernet0/0/12 queue 1 (polling) |
| 1676 | * VirtualEthernet0/0/12 queue 2 (polling) |
| 1677 | * VirtualEthernet0/0/13 queue 0 (polling) |
| 1678 | * VirtualEthernet0/0/13 queue 2 (polling) |
| 1679 | * Thread 2 (vpp_wk_1): |
| 1680 | * node dpdk-input: |
| 1681 | * GigabitEthernet7/0/1 queue 0 (polling) |
| 1682 | * node vhost-user-input: |
| 1683 | * VirtualEthernet0/0/12 queue 3 (polling) |
| 1684 | * VirtualEthernet0/0/13 queue 1 (polling) |
| 1685 | * VirtualEthernet0/0/13 queue 3 (polling) |
| 1686 | * @cliexend |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1687 | ?*/ |
| 1688 | /* *INDENT-OFF* */ |
| 1689 | VLIB_CLI_COMMAND (cmd_set_if_rx_placement,static) = { |
| 1690 | .path = "set interface rx-placement", |
Billy McFall | e9bac69 | 2017-08-11 14:05:11 -0400 | [diff] [blame] | 1691 | .short_help = "set interface rx-placement <interface> [queue <n>] " |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 1692 | "[worker <n> | main]", |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1693 | .function = set_interface_rx_placement, |
Damjan Marion | 6f9ac65 | 2017-06-15 19:01:31 +0200 | [diff] [blame] | 1694 | .is_mp_safe = 1, |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1695 | }; |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 1696 | /* *INDENT-ON* */ |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 1697 | |
| 1698 | static inline clib_error_t * |
| 1699 | pcap_trace_command_internal (vlib_main_t * vm, |
| 1700 | unformat_input_t * input, |
| 1701 | vlib_cli_command_t * cmd, int rx_tx) |
| 1702 | { |
| 1703 | #define PCAP_DEF_PKT_TO_CAPTURE (1000) |
| 1704 | |
| 1705 | unformat_input_t _line_input, *line_input = &_line_input; |
| 1706 | u8 *filename; |
| 1707 | u8 *chroot_filename = 0; |
| 1708 | u32 max = 0; |
| 1709 | int enabled = 0; |
| 1710 | int errorFlag = 0; |
| 1711 | clib_error_t *error = 0; |
| 1712 | vnet_main_t *vnm = vnet_get_main (); |
| 1713 | |
| 1714 | /* Get a line of input. */ |
| 1715 | if (!unformat_user (input, unformat_line_input, line_input)) |
| 1716 | return 0; |
| 1717 | |
| 1718 | while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT) |
| 1719 | { |
| 1720 | if (unformat (line_input, "on")) |
| 1721 | { |
| 1722 | if (vm->pcap[rx_tx].pcap_enable == 0) |
| 1723 | { |
| 1724 | enabled = 1; |
| 1725 | } |
| 1726 | else |
| 1727 | { |
Jack Xu | f753744 | 2019-03-26 13:46:00 -0400 | [diff] [blame] | 1728 | vlib_cli_output (vm, "pcap %s capture already on...", |
| 1729 | (rx_tx == VLIB_RX) ? "rx" : "tx"); |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 1730 | errorFlag = 1; |
| 1731 | break; |
| 1732 | } |
| 1733 | } |
| 1734 | else if (unformat (line_input, "off")) |
| 1735 | { |
| 1736 | if (vm->pcap[rx_tx].pcap_enable) |
| 1737 | { |
| 1738 | vlib_cli_output |
| 1739 | (vm, "captured %d pkts...", |
| 1740 | vm->pcap[rx_tx].pcap_main.n_packets_captured); |
| 1741 | if (vm->pcap[rx_tx].pcap_main.n_packets_captured) |
| 1742 | { |
| 1743 | vm->pcap[rx_tx].pcap_main.n_packets_to_capture = |
| 1744 | vm->pcap[rx_tx].pcap_main.n_packets_captured; |
| 1745 | error = pcap_write (&vm->pcap[rx_tx].pcap_main); |
| 1746 | if (error) |
| 1747 | clib_error_report (error); |
| 1748 | else |
| 1749 | vlib_cli_output (vm, "saved to %s...", |
| 1750 | vm->pcap[rx_tx].pcap_main.file_name); |
| 1751 | } |
| 1752 | |
| 1753 | vm->pcap[rx_tx].pcap_enable = 0; |
| 1754 | } |
| 1755 | else |
| 1756 | { |
Jack Xu | f753744 | 2019-03-26 13:46:00 -0400 | [diff] [blame] | 1757 | vlib_cli_output (vm, "pcap %s capture already off...", |
| 1758 | (rx_tx == VLIB_RX) ? "rx" : "tx"); |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 1759 | errorFlag = 1; |
| 1760 | break; |
| 1761 | } |
| 1762 | } |
| 1763 | else if (unformat (line_input, "max %d", &max)) |
| 1764 | { |
| 1765 | if (vm->pcap[rx_tx].pcap_enable) |
| 1766 | { |
| 1767 | vlib_cli_output |
| 1768 | (vm, |
| 1769 | "can't change max value while pcap tx capture active..."); |
| 1770 | errorFlag = 1; |
| 1771 | break; |
| 1772 | } |
| 1773 | vm->pcap[rx_tx].pcap_main.n_packets_to_capture = max; |
| 1774 | } |
| 1775 | else if (unformat (line_input, "intfc %U", |
| 1776 | unformat_vnet_sw_interface, vnm, |
| 1777 | &vm->pcap[rx_tx].pcap_sw_if_index)) |
| 1778 | ; |
| 1779 | |
| 1780 | else if (unformat (line_input, "intfc any")) |
| 1781 | { |
| 1782 | vm->pcap[rx_tx].pcap_sw_if_index = 0; |
| 1783 | } |
| 1784 | else if (unformat (line_input, "file %s", &filename)) |
| 1785 | { |
| 1786 | if (vm->pcap[rx_tx].pcap_enable) |
| 1787 | { |
| 1788 | vlib_cli_output |
| 1789 | (vm, "can't change file while pcap tx capture active..."); |
| 1790 | errorFlag = 1; |
| 1791 | break; |
| 1792 | } |
| 1793 | |
| 1794 | /* Brain-police user path input */ |
| 1795 | if (strstr ((char *) filename, "..") |
| 1796 | || index ((char *) filename, '/')) |
| 1797 | { |
| 1798 | vlib_cli_output (vm, "illegal characters in filename '%s'", |
| 1799 | filename); |
| 1800 | vlib_cli_output (vm, "Hint: .. and / are not allowed."); |
| 1801 | vec_free (filename); |
| 1802 | errorFlag = 1; |
| 1803 | break; |
| 1804 | } |
| 1805 | |
| 1806 | chroot_filename = format (0, "/tmp/%s%c", filename, 0); |
| 1807 | vec_free (filename); |
| 1808 | } |
| 1809 | else if (unformat (line_input, "status")) |
| 1810 | { |
| 1811 | if (vm->pcap[rx_tx].pcap_sw_if_index == 0) |
| 1812 | { |
| 1813 | vlib_cli_output |
| 1814 | (vm, "max is %d for any interface to file %s", |
| 1815 | vm->pcap[rx_tx].pcap_main.n_packets_to_capture ? |
| 1816 | vm->pcap[rx_tx].pcap_main.n_packets_to_capture |
| 1817 | : PCAP_DEF_PKT_TO_CAPTURE, |
| 1818 | vm->pcap[rx_tx].pcap_main.file_name ? |
| 1819 | (u8 *) vm->pcap[rx_tx].pcap_main.file_name : |
| 1820 | (u8 *) "/tmp/vpe.pcap"); |
| 1821 | } |
| 1822 | else |
| 1823 | { |
| 1824 | vlib_cli_output (vm, "max is %d for interface %U to file %s", |
| 1825 | vm->pcap[rx_tx].pcap_main.n_packets_to_capture |
| 1826 | ? vm->pcap[rx_tx]. |
| 1827 | pcap_main.n_packets_to_capture : |
| 1828 | PCAP_DEF_PKT_TO_CAPTURE, |
| 1829 | format_vnet_sw_if_index_name, vnm, |
Dave Barach | cac8f9b | 2019-04-16 08:07:06 -0400 | [diff] [blame] | 1830 | vm->pcap[rx_tx].pcap_sw_if_index, |
Dave Barach | 5ecd5a5 | 2019-02-25 15:27:28 -0500 | [diff] [blame] | 1831 | vm->pcap[rx_tx]. |
| 1832 | pcap_main.file_name ? (u8 *) vm->pcap[rx_tx]. |
| 1833 | pcap_main.file_name : (u8 *) "/tmp/vpe.pcap"); |
| 1834 | } |
| 1835 | |
| 1836 | if (vm->pcap[rx_tx].pcap_enable == 0) |
| 1837 | { |
| 1838 | vlib_cli_output (vm, "pcap %s capture is off...", |
| 1839 | (rx_tx == VLIB_RX) ? "rx" : "tx"); |
| 1840 | } |
| 1841 | else |
| 1842 | { |
| 1843 | vlib_cli_output (vm, "pcap %s capture is on: %d of %d pkts...", |
| 1844 | (rx_tx == VLIB_RX) ? "rx" : "tx", |
| 1845 | vm->pcap[rx_tx].pcap_main.n_packets_captured, |
| 1846 | vm->pcap[rx_tx]. |
| 1847 | pcap_main.n_packets_to_capture); |
| 1848 | } |
| 1849 | break; |
| 1850 | } |
| 1851 | |
| 1852 | else |
| 1853 | { |
| 1854 | error = clib_error_return (0, "unknown input `%U'", |
| 1855 | format_unformat_error, line_input); |
| 1856 | errorFlag = 1; |
| 1857 | break; |
| 1858 | } |
| 1859 | } |
| 1860 | unformat_free (line_input); |
| 1861 | |
| 1862 | |
| 1863 | if (errorFlag == 0) |
| 1864 | { |
| 1865 | /* Since no error, save configured values. */ |
| 1866 | if (chroot_filename) |
| 1867 | { |
| 1868 | if (vm->pcap[rx_tx].pcap_main.file_name) |
| 1869 | vec_free (vm->pcap[rx_tx].pcap_main.file_name); |
| 1870 | vec_add1 (chroot_filename, 0); |
| 1871 | vm->pcap[rx_tx].pcap_main.file_name = (char *) chroot_filename; |
| 1872 | } |
| 1873 | |
| 1874 | if (max) |
| 1875 | vm->pcap[rx_tx].pcap_main.n_packets_to_capture = max; |
| 1876 | |
| 1877 | if (enabled) |
| 1878 | { |
| 1879 | if (vm->pcap[rx_tx].pcap_main.file_name == 0) |
| 1880 | vm->pcap[rx_tx].pcap_main.file_name |
| 1881 | = (char *) format (0, "/tmp/vpe.pcap%c", 0); |
| 1882 | |
| 1883 | vm->pcap[rx_tx].pcap_main.n_packets_captured = 0; |
| 1884 | vm->pcap[rx_tx].pcap_main.packet_type = PCAP_PACKET_TYPE_ethernet; |
| 1885 | if (vm->pcap[rx_tx].pcap_main.lock == 0) |
| 1886 | clib_spinlock_init (&(vm->pcap[rx_tx].pcap_main.lock)); |
| 1887 | vm->pcap[rx_tx].pcap_enable = 1; |
| 1888 | vlib_cli_output (vm, "pcap %s capture on...", |
| 1889 | rx_tx == VLIB_RX ? "rx" : "tx"); |
| 1890 | } |
| 1891 | } |
| 1892 | else if (chroot_filename) |
| 1893 | vec_free (chroot_filename); |
| 1894 | |
| 1895 | return error; |
| 1896 | } |
| 1897 | |
| 1898 | static clib_error_t * |
| 1899 | pcap_rx_trace_command_fn (vlib_main_t * vm, |
| 1900 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1901 | { |
| 1902 | return pcap_trace_command_internal (vm, input, cmd, VLIB_RX); |
| 1903 | } |
| 1904 | |
| 1905 | static clib_error_t * |
| 1906 | pcap_tx_trace_command_fn (vlib_main_t * vm, |
| 1907 | unformat_input_t * input, vlib_cli_command_t * cmd) |
| 1908 | { |
| 1909 | return pcap_trace_command_internal (vm, input, cmd, VLIB_TX); |
| 1910 | } |
| 1911 | |
| 1912 | |
| 1913 | /*? |
| 1914 | * This command is used to start or stop a packet capture, or show |
| 1915 | * the status of packet capture. Note that both "pcap rx trace" and |
| 1916 | * "pcap tx trace" are implemented. The command syntax is identical, |
| 1917 | * simply substitute rx for tx as needed. |
| 1918 | * |
| 1919 | * This command has the following optional parameters: |
| 1920 | * |
| 1921 | * - <b>on|off</b> - Used to start or stop a packet capture. |
| 1922 | * |
| 1923 | * - <b>max <nn></b> - Depth of local buffer. Once '<em>nn</em>' number |
| 1924 | * of packets have been received, buffer is flushed to file. Once another |
| 1925 | * '<em>nn</em>' number of packets have been received, buffer is flushed |
| 1926 | * to file, overwriting previous write. If not entered, value defaults |
| 1927 | * to 100. Can only be updated if packet capture is off. |
| 1928 | * |
| 1929 | * - <b>intfc <interface>|any</b> - Used to specify a given interface, |
| 1930 | * or use '<em>any</em>' to run packet capture on all interfaces. |
| 1931 | * '<em>any</em>' is the default if not provided. Settings from a previous |
| 1932 | * packet capture are preserved, so '<em>any</em>' can be used to reset |
| 1933 | * the interface setting. |
| 1934 | * |
| 1935 | * - <b>file <name></b> - Used to specify the output filename. The file will |
| 1936 | * be placed in the '<em>/tmp</em>' directory, so only the filename is |
| 1937 | * supported. Directory should not be entered. If file already exists, file |
| 1938 | * will be overwritten. If no filename is provided, '<em>/tmp/vpe.pcap</em>' |
| 1939 | * will be used. Can only be updated if packet capture is off. |
| 1940 | * |
| 1941 | * - <b>status</b> - Displays the current status and configured attributes |
| 1942 | * associated with a packet capture. If packet capture is in progress, |
| 1943 | * '<em>status</em>' also will return the number of packets currently in |
| 1944 | * the local buffer. All additional attributes entered on command line |
| 1945 | * with '<em>status</em>' will be ignored and not applied. |
| 1946 | * |
| 1947 | * @cliexpar |
| 1948 | * Example of how to display the status of a tx packet capture when off: |
| 1949 | * @cliexstart{pcap tx trace status} |
| 1950 | * max is 100, for any interface to file /tmp/vpe.pcap |
| 1951 | * pcap tx capture is off... |
| 1952 | * @cliexend |
| 1953 | * Example of how to start a tx packet capture: |
| 1954 | * @cliexstart{pcap tx trace on max 35 intfc GigabitEthernet0/8/0 file vppTest.pcap} |
| 1955 | * pcap tx capture on... |
| 1956 | * @cliexend |
| 1957 | * Example of how to display the status of a tx packet capture in progress: |
| 1958 | * @cliexstart{pcap tx trace status} |
| 1959 | * max is 35, for interface GigabitEthernet0/8/0 to file /tmp/vppTest.pcap |
| 1960 | * pcap tx capture is on: 20 of 35 pkts... |
| 1961 | * @cliexend |
| 1962 | * Example of how to stop a tx packet capture: |
| 1963 | * @cliexstart{vppctl pcap tx trace off} |
| 1964 | * captured 21 pkts... |
| 1965 | * saved to /tmp/vppTest.pcap... |
| 1966 | * @cliexend |
| 1967 | ?*/ |
| 1968 | /* *INDENT-OFF* */ |
| 1969 | |
| 1970 | VLIB_CLI_COMMAND (pcap_tx_trace_command, static) = { |
| 1971 | .path = "pcap tx trace", |
| 1972 | .short_help = |
| 1973 | "pcap tx trace [on|off] [max <nn>] [intfc <interface>|any] [file <name>] [status]", |
| 1974 | .function = pcap_tx_trace_command_fn, |
| 1975 | }; |
| 1976 | VLIB_CLI_COMMAND (pcap_rx_trace_command, static) = { |
| 1977 | .path = "pcap rx trace", |
| 1978 | .short_help = |
| 1979 | "pcap rx trace [on|off] [max <nn>] [intfc <interface>|any] [file <name>] [status]", |
| 1980 | .function = pcap_rx_trace_command_fn, |
| 1981 | }; |
| 1982 | /* *INDENT-ON* */ |
| 1983 | |
| 1984 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 1985 | /* |
| 1986 | * fd.io coding-style-patch-verification: ON |
| 1987 | * |
| 1988 | * Local Variables: |
| 1989 | * eval: (c-set-style "gnu") |
| 1990 | * End: |
| 1991 | */ |