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_format.c: interface formatting |
| 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 | |
| 40 | #include <vnet/vnet.h> |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 41 | #include <vppinfra/bitmap.h> |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 42 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 43 | u8 * |
| 44 | format_vnet_sw_interface_flags (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 45 | { |
| 46 | u32 flags = va_arg (*args, u32); |
| 47 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 48 | if (flags & VNET_SW_INTERFACE_FLAG_BOND_SLAVE) |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 49 | s = format (s, "bond-slave"); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 50 | else |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 51 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 52 | s = format (s, "%s", |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 53 | (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "down"); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 54 | if (flags & VNET_SW_INTERFACE_FLAG_PUNT) |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 55 | s = format (s, "/punt"); |
| 56 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 57 | |
| 58 | return s; |
| 59 | } |
| 60 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 61 | u8 * |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 62 | format_vnet_hw_interface_rx_mode (u8 * s, va_list * args) |
| 63 | { |
| 64 | vnet_hw_interface_rx_mode mode = va_arg (*args, vnet_hw_interface_rx_mode); |
| 65 | |
| 66 | if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING) |
| 67 | return format (s, "polling"); |
| 68 | |
| 69 | if (mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT) |
| 70 | return format (s, "interrupt"); |
| 71 | |
| 72 | if (mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE) |
| 73 | return format (s, "adaptive"); |
| 74 | |
| 75 | return format (s, "unknown"); |
| 76 | } |
| 77 | |
| 78 | u8 * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 79 | format_vnet_hw_interface (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 80 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 81 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 82 | vnet_hw_interface_t *hi = va_arg (*args, vnet_hw_interface_t *); |
| 83 | vnet_hw_interface_class_t *hw_class; |
| 84 | vnet_device_class_t *dev_class; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 85 | int verbose = va_arg (*args, int); |
| 86 | uword indent; |
| 87 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 88 | if (!hi) |
| 89 | return format (s, "%=32s%=6s%=8s%s", "Name", "Idx", "Link", "Hardware"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 90 | |
| 91 | indent = format_get_indent (s); |
| 92 | |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 93 | s = format (s, "%-32v%=6d", hi->name, hi->hw_if_index); |
| 94 | |
| 95 | if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) |
| 96 | s = format (s, "%=8s", "slave"); |
| 97 | else |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 98 | s = format (s, "%=8s", |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 99 | hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP ? "up" : "down"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 100 | |
| 101 | hw_class = vnet_get_hw_interface_class (vnm, hi->hw_class_index); |
| 102 | dev_class = vnet_get_device_class (vnm, hi->dev_class_index); |
| 103 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 104 | if (hi->bond_info && (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE)) |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 105 | { |
| 106 | int hw_idx; |
| 107 | s = format (s, "Slave-Idx:"); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 108 | clib_bitmap_foreach (hw_idx, hi->bond_info, s = |
| 109 | format (s, " %d", hw_idx)); |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 110 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 111 | else if (dev_class->format_device_name) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 112 | s = format (s, "%U", dev_class->format_device_name, hi->dev_instance); |
| 113 | else |
| 114 | s = format (s, "%s%d", dev_class->name, hi->dev_instance); |
| 115 | |
| 116 | if (verbose) |
| 117 | { |
| 118 | if (hw_class->format_device) |
| 119 | s = format (s, "\n%U%U", |
| 120 | format_white_space, indent + 2, |
| 121 | hw_class->format_device, hi->hw_if_index, verbose); |
| 122 | else |
| 123 | { |
| 124 | s = format (s, "\n%U%s", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 125 | format_white_space, indent + 2, hw_class->name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 126 | if (hw_class->format_address && vec_len (hi->hw_address) > 0) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 127 | s = |
| 128 | format (s, " address %U", hw_class->format_address, |
| 129 | hi->hw_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | if (dev_class->format_device) |
| 133 | s = format (s, "\n%U%U", |
| 134 | format_white_space, indent + 2, |
| 135 | dev_class->format_device, hi->dev_instance, verbose); |
| 136 | } |
| 137 | |
| 138 | return s; |
| 139 | } |
| 140 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 141 | u8 * |
| 142 | format_vnet_sw_interface_name (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 143 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 144 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 145 | vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *); |
| 146 | vnet_sw_interface_t *si_sup = |
| 147 | vnet_get_sup_sw_interface (vnm, si->sw_if_index); |
| 148 | vnet_hw_interface_t *hi_sup; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 149 | |
| 150 | ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE); |
| 151 | hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index); |
| 152 | |
| 153 | s = format (s, "%v", hi_sup->name); |
| 154 | |
| 155 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 156 | s = format (s, ".%d", si->sub.id); |
| 157 | |
| 158 | return s; |
| 159 | } |
| 160 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 161 | u8 * |
| 162 | format_vnet_sw_if_index_name (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 163 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 164 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 165 | u32 sw_if_index = va_arg (*args, u32); |
| 166 | return format (s, "%U", |
| 167 | format_vnet_sw_interface_name, vnm, |
| 168 | vnet_get_sw_interface (vnm, sw_if_index)); |
| 169 | } |
| 170 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 171 | u8 * |
| 172 | format_vnet_sw_interface_cntrs (u8 * s, vnet_interface_main_t * im, |
| 173 | vnet_sw_interface_t * si) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 174 | { |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 175 | uword indent, n_printed; |
| 176 | int i, j, n_counters; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 177 | static vnet_main_t **my_vnet_mains; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 178 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 179 | vec_reset_length (my_vnet_mains); |
| 180 | |
| 181 | indent = format_get_indent (s); |
| 182 | n_printed = 0; |
| 183 | |
| 184 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 185 | vlib_combined_counter_main_t *cm; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 186 | vlib_counter_t v, vtotal; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 187 | u8 *n = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 188 | |
| 189 | for (i = 0; i < vec_len (vnet_mains); i++) |
| 190 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 191 | if (vnet_mains[i]) |
| 192 | vec_add1 (my_vnet_mains, vnet_mains[i]); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 195 | if (vec_len (my_vnet_mains) == 0) |
| 196 | vec_add1 (my_vnet_mains, &vnet_main); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 197 | |
| 198 | /* Each vnet_main_t has its own copy of the interface counters */ |
| 199 | n_counters = vec_len (im->combined_sw_if_counters); |
| 200 | |
| 201 | /* rx, tx counters... */ |
| 202 | for (j = 0; j < n_counters; j++) |
| 203 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 204 | vtotal.packets = 0; |
| 205 | vtotal.bytes = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 206 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 207 | for (i = 0; i < vec_len (my_vnet_mains); i++) |
| 208 | { |
| 209 | im = &my_vnet_mains[i]->interface_main; |
| 210 | cm = im->combined_sw_if_counters + j; |
| 211 | vlib_get_combined_counter (cm, si->sw_if_index, &v); |
| 212 | vtotal.packets += v.packets; |
| 213 | vtotal.bytes += v.bytes; |
| 214 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 215 | |
| 216 | /* Only display non-zero counters. */ |
| 217 | if (vtotal.packets == 0) |
| 218 | continue; |
| 219 | |
| 220 | if (n_printed > 0) |
| 221 | s = format (s, "\n%U", format_white_space, indent); |
| 222 | n_printed += 2; |
| 223 | |
| 224 | if (n) |
| 225 | _vec_len (n) = 0; |
| 226 | n = format (n, "%s packets", cm->name); |
| 227 | s = format (s, "%-16v%16Ld", n, vtotal.packets); |
| 228 | |
| 229 | _vec_len (n) = 0; |
| 230 | n = format (n, "%s bytes", cm->name); |
| 231 | s = format (s, "\n%U%-16v%16Ld", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 232 | format_white_space, indent, n, vtotal.bytes); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 233 | } |
| 234 | vec_free (n); |
| 235 | } |
| 236 | |
| 237 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 238 | vlib_simple_counter_main_t *cm; |
| 239 | u64 v, vtotal; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 240 | |
| 241 | n_counters = vec_len (im->sw_if_counters); |
| 242 | |
| 243 | for (j = 0; j < n_counters; j++) |
| 244 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 245 | vtotal = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 246 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 247 | for (i = 0; i < vec_len (my_vnet_mains); i++) |
| 248 | { |
| 249 | im = &my_vnet_mains[i]->interface_main; |
| 250 | cm = im->sw_if_counters + j; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 251 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 252 | v = vlib_get_simple_counter (cm, si->sw_if_index); |
| 253 | vtotal += v; |
| 254 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 255 | |
| 256 | /* Only display non-zero counters. */ |
| 257 | if (vtotal == 0) |
| 258 | continue; |
| 259 | |
| 260 | if (n_printed > 0) |
| 261 | s = format (s, "\n%U", format_white_space, indent); |
| 262 | n_printed += 1; |
| 263 | |
| 264 | s = format (s, "%-16s%16Ld", cm->name, vtotal); |
| 265 | } |
| 266 | } |
| 267 | |
| 268 | return s; |
| 269 | } |
| 270 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 271 | u8 * |
| 272 | format_vnet_sw_interface (u8 * s, va_list * args) |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 273 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 274 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 275 | vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *); |
| 276 | vnet_interface_main_t *im = &vnm->interface_main; |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 277 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 278 | if (!si) |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 279 | return format (s, "%=32s%=5s%=16s%=16s%=16s", |
| 280 | "Name", "Idx", "State", "Counter", "Count"); |
| 281 | |
| 282 | s = format (s, "%-32U%=5d%=16U", |
| 283 | format_vnet_sw_interface_name, vnm, si, si->sw_if_index, |
| 284 | format_vnet_sw_interface_flags, si->flags); |
| 285 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 286 | s = format_vnet_sw_interface_cntrs (s, im, si); |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 287 | |
| 288 | return s; |
| 289 | } |
| 290 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 291 | u8 * |
| 292 | format_vnet_sw_interface_name_override (u8 * s, va_list * args) |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 293 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 294 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 295 | vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *); |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 296 | /* caller supplied display name for this interface */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 297 | u8 *name = va_arg (*args, u8 *); |
| 298 | vnet_interface_main_t *im = &vnm->interface_main; |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 299 | |
| 300 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 301 | if (!si) |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 302 | return format (s, "%=32s%=5s%=16s%=16s%=16s", |
| 303 | "Name", "Idx", "State", "Counter", "Count"); |
| 304 | |
| 305 | s = format (s, "%-32v%=5d%=16U", |
| 306 | name, si->sw_if_index, |
| 307 | format_vnet_sw_interface_flags, si->flags); |
| 308 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 309 | s = format_vnet_sw_interface_cntrs (s, im, si); |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 310 | |
| 311 | return s; |
| 312 | } |
| 313 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 314 | uword |
| 315 | unformat_vnet_hw_interface (unformat_input_t * input, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 316 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 317 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 318 | u32 *hw_if_index = va_arg (*args, u32 *); |
| 319 | vnet_interface_main_t *im = &vnm->interface_main; |
| 320 | vnet_device_class_t *c; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 321 | |
| 322 | /* Try per device class functions first. */ |
| 323 | vec_foreach (c, im->device_classes) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 324 | { |
| 325 | if (c->unformat_device_name |
| 326 | && unformat_user (input, c->unformat_device_name, hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 327 | return 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 328 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 329 | |
| 330 | return unformat_user (input, unformat_hash_vec_string, |
| 331 | im->hw_interface_by_name, hw_if_index); |
| 332 | } |
| 333 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 334 | uword |
| 335 | unformat_vnet_sw_interface (unformat_input_t * input, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 336 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 337 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 338 | u32 *result = va_arg (*args, u32 *); |
| 339 | vnet_hw_interface_t *hi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 340 | u32 hw_if_index, id, id_specified; |
Eyal Bari | 3212c57 | 2017-03-06 11:47:50 +0200 | [diff] [blame] | 341 | u32 sw_if_index; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 342 | u8 *if_name = 0; |
| 343 | uword *p, error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 344 | |
| 345 | id = ~0; |
| 346 | if (unformat (input, "%_%v.%d%_", &if_name, &id) |
| 347 | && ((p = hash_get (vnm->interface_main.hw_interface_by_name, if_name)))) |
| 348 | { |
| 349 | hw_if_index = p[0]; |
| 350 | id_specified = 1; |
| 351 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 352 | else |
| 353 | if (unformat (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 354 | id_specified = 0; |
| 355 | else |
| 356 | goto done; |
| 357 | |
| 358 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 359 | if (!id_specified) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 360 | { |
Eyal Bari | 3212c57 | 2017-03-06 11:47:50 +0200 | [diff] [blame] | 361 | sw_if_index = hi->sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 362 | } |
| 363 | else |
| 364 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 365 | if (!(p = hash_get (hi->sub_interface_sw_if_index_by_id, id))) |
Eyal Bari | 3212c57 | 2017-03-06 11:47:50 +0200 | [diff] [blame] | 366 | goto done; |
| 367 | sw_if_index = p[0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 368 | } |
Eyal Bari | 3212c57 | 2017-03-06 11:47:50 +0200 | [diff] [blame] | 369 | if (!vnet_sw_interface_is_api_visible (vnm, sw_if_index)) |
| 370 | goto done; |
| 371 | *result = sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 372 | error = 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 373 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 374 | vec_free (if_name); |
| 375 | return error; |
| 376 | } |
| 377 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 378 | uword |
| 379 | unformat_vnet_sw_interface_flags (unformat_input_t * input, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 380 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 381 | u32 *result = va_arg (*args, u32 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 382 | u32 flags = 0; |
| 383 | |
| 384 | if (unformat (input, "up")) |
| 385 | flags |= VNET_SW_INTERFACE_FLAG_ADMIN_UP; |
| 386 | else if (unformat (input, "down")) |
| 387 | flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP; |
| 388 | else if (unformat (input, "punt")) |
| 389 | flags |= VNET_SW_INTERFACE_FLAG_PUNT; |
| 390 | else if (unformat (input, "enable")) |
| 391 | flags &= ~VNET_SW_INTERFACE_FLAG_PUNT; |
| 392 | else |
| 393 | return 0; |
| 394 | |
| 395 | *result = flags; |
| 396 | return 1; |
| 397 | } |
| 398 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 399 | uword |
| 400 | unformat_vnet_hw_interface_flags (unformat_input_t * input, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 401 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 402 | u32 *result = va_arg (*args, u32 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 403 | u32 flags = 0; |
| 404 | |
| 405 | if (unformat (input, "up")) |
| 406 | flags |= VNET_HW_INTERFACE_FLAG_LINK_UP; |
| 407 | else if (unformat (input, "down")) |
| 408 | flags &= ~VNET_HW_INTERFACE_FLAG_LINK_UP; |
| 409 | else |
| 410 | return 0; |
| 411 | |
| 412 | *result = flags; |
| 413 | return 1; |
| 414 | } |
| 415 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 416 | /* |
| 417 | * fd.io coding-style-patch-verification: ON |
| 418 | * |
| 419 | * Local Variables: |
| 420 | * eval: (c-set-style "gnu") |
| 421 | * End: |
| 422 | */ |