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> |
Dave Barach | 7bdaa3f | 2018-12-03 11:33:09 -0500 | [diff] [blame] | 42 | #include <vnet/l2/l2_input.h> |
| 43 | #include <vnet/l2/l2_output.h> |
Jon Loeliger | 9485d99 | 2019-11-08 15:05:23 -0600 | [diff] [blame] | 44 | #include <vnet/l2/l2_vtr.h> |
| 45 | |
| 46 | u8 * |
| 47 | format_vtr (u8 * s, va_list * args) |
| 48 | { |
| 49 | u32 vtr_op = va_arg (*args, u32); |
| 50 | u32 dot1q = va_arg (*args, u32); |
| 51 | u32 tag1 = va_arg (*args, u32); |
| 52 | u32 tag2 = va_arg (*args, u32); |
| 53 | switch (vtr_op) |
| 54 | { |
| 55 | case L2_VTR_DISABLED: |
| 56 | return format (s, "none"); |
| 57 | case L2_VTR_PUSH_1: |
| 58 | return format (s, "push-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); |
| 59 | case L2_VTR_PUSH_2: |
| 60 | return format (s, "push-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1, |
| 61 | tag2); |
| 62 | case L2_VTR_POP_1: |
| 63 | return format (s, "pop-1"); |
| 64 | case L2_VTR_POP_2: |
| 65 | return format (s, "pop-2"); |
| 66 | case L2_VTR_TRANSLATE_1_1: |
| 67 | return format (s, "trans-1-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); |
| 68 | case L2_VTR_TRANSLATE_1_2: |
| 69 | return format (s, "trans-1-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", |
| 70 | tag1, tag2); |
| 71 | case L2_VTR_TRANSLATE_2_1: |
| 72 | return format (s, "trans-2-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1); |
| 73 | case L2_VTR_TRANSLATE_2_2: |
| 74 | return format (s, "trans-2-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", |
| 75 | tag1, tag2); |
| 76 | default: |
| 77 | return format (s, "none"); |
| 78 | } |
| 79 | } |
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 | u8 * |
| 82 | format_vnet_sw_interface_flags (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 83 | { |
| 84 | u32 flags = va_arg (*args, u32); |
| 85 | |
Damjan Marion | abce509 | 2017-05-10 20:09:31 +0200 | [diff] [blame] | 86 | if (flags & VNET_SW_INTERFACE_FLAG_ERROR) |
| 87 | s = format (s, "error"); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 88 | else |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 89 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 90 | s = format (s, "%s", |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 91 | (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "down"); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 92 | if (flags & VNET_SW_INTERFACE_FLAG_PUNT) |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 93 | s = format (s, "/punt"); |
| 94 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 95 | |
| 96 | return s; |
| 97 | } |
| 98 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 99 | u8 * |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 100 | format_vnet_hw_if_rx_mode (u8 * s, va_list * args) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 101 | { |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 102 | vnet_hw_if_rx_mode mode = va_arg (*args, vnet_hw_if_rx_mode); |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 103 | |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 104 | if (mode == VNET_HW_IF_RX_MODE_POLLING) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 105 | return format (s, "polling"); |
| 106 | |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 107 | if (mode == VNET_HW_IF_RX_MODE_INTERRUPT) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 108 | return format (s, "interrupt"); |
| 109 | |
Damjan Marion | eabd424 | 2020-10-07 20:59:07 +0200 | [diff] [blame] | 110 | if (mode == VNET_HW_IF_RX_MODE_ADAPTIVE) |
Damjan Marion | 4403690 | 2017-04-28 12:29:15 +0200 | [diff] [blame] | 111 | return format (s, "adaptive"); |
| 112 | |
| 113 | return format (s, "unknown"); |
| 114 | } |
| 115 | |
| 116 | u8 * |
Damjan Marion | 5100aa9 | 2018-11-08 15:30:16 +0100 | [diff] [blame] | 117 | format_vnet_hw_interface_link_speed (u8 * s, va_list * args) |
| 118 | { |
| 119 | u32 link_speed = va_arg (*args, u32); |
| 120 | |
| 121 | if (link_speed == 0) |
| 122 | return format (s, "unknown"); |
| 123 | |
| 124 | if (link_speed >= 1000000) |
| 125 | return format (s, "%f Gbps", (f64) link_speed / 1000000); |
| 126 | |
| 127 | if (link_speed >= 1000) |
| 128 | return format (s, "%f Mbps", (f64) link_speed / 1000); |
| 129 | |
| 130 | return format (s, "%u Kbps", link_speed); |
| 131 | } |
| 132 | |
Chenmin Sun | c466509 | 2020-07-06 08:20:39 +0800 | [diff] [blame] | 133 | u8 * |
| 134 | format_vnet_hw_interface_rss_queues (u8 * s, va_list * args) |
| 135 | { |
| 136 | clib_bitmap_t *bitmap = va_arg (*args, clib_bitmap_t *); |
| 137 | int i; |
| 138 | |
| 139 | if (bitmap == NULL) |
| 140 | return s; |
| 141 | |
| 142 | if (bitmap) |
| 143 | { |
| 144 | /* *INDENT-OFF* */ |
| 145 | clib_bitmap_foreach (i, bitmap, ({ |
| 146 | s = format (s, "%u ", i); |
| 147 | })); |
| 148 | /* *INDENT-ON* */ |
| 149 | } |
| 150 | |
| 151 | return s; |
| 152 | } |
Damjan Marion | 5100aa9 | 2018-11-08 15:30:16 +0100 | [diff] [blame] | 153 | |
| 154 | u8 * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 155 | format_vnet_hw_interface (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 156 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 157 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 158 | vnet_hw_interface_t *hi = va_arg (*args, vnet_hw_interface_t *); |
| 159 | vnet_hw_interface_class_t *hw_class; |
| 160 | vnet_device_class_t *dev_class; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 161 | int verbose = va_arg (*args, int); |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 162 | u32 indent; |
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 | if (!hi) |
| 165 | return format (s, "%=32s%=6s%=8s%s", "Name", "Idx", "Link", "Hardware"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 166 | |
| 167 | indent = format_get_indent (s); |
| 168 | |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 169 | s = format (s, "%-32v%=6d", hi->name, hi->hw_if_index); |
| 170 | |
| 171 | if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE) |
| 172 | s = format (s, "%=8s", "slave"); |
| 173 | else |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 174 | s = format (s, "%=8s", |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 175 | hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP ? "up" : "down"); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 176 | |
| 177 | hw_class = vnet_get_hw_interface_class (vnm, hi->hw_class_index); |
| 178 | dev_class = vnet_get_device_class (vnm, hi->dev_class_index); |
| 179 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 180 | 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] | 181 | { |
| 182 | int hw_idx; |
| 183 | s = format (s, "Slave-Idx:"); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 184 | clib_bitmap_foreach (hw_idx, hi->bond_info, s = |
| 185 | format (s, " %d", hw_idx)); |
John Lo | bcebbb9 | 2016-04-05 15:47:43 -0400 | [diff] [blame] | 186 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 187 | else if (dev_class->format_device_name) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 188 | s = format (s, "%U", dev_class->format_device_name, hi->dev_instance); |
| 189 | else |
| 190 | s = format (s, "%s%d", dev_class->name, hi->dev_instance); |
| 191 | |
Damjan Marion | 5100aa9 | 2018-11-08 15:30:16 +0100 | [diff] [blame] | 192 | s = format (s, "\n%ULink speed: %U", format_white_space, indent + 2, |
| 193 | format_vnet_hw_interface_link_speed, hi->link_speed); |
| 194 | |
Chenmin Sun | c466509 | 2020-07-06 08:20:39 +0800 | [diff] [blame] | 195 | if (hi->rss_queues) |
| 196 | { |
| 197 | s = format (s, "\n%URSS queues: %U", format_white_space, indent + 2, |
| 198 | format_vnet_hw_interface_rss_queues, hi->rss_queues); |
| 199 | } |
| 200 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 201 | if (verbose) |
| 202 | { |
| 203 | if (hw_class->format_device) |
| 204 | s = format (s, "\n%U%U", |
| 205 | format_white_space, indent + 2, |
| 206 | hw_class->format_device, hi->hw_if_index, verbose); |
| 207 | else |
| 208 | { |
| 209 | s = format (s, "\n%U%s", |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 210 | format_white_space, indent + 2, hw_class->name); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 211 | if (hw_class->format_address && vec_len (hi->hw_address) > 0) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 212 | s = |
| 213 | format (s, " address %U", hw_class->format_address, |
| 214 | hi->hw_address); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 215 | } |
| 216 | |
| 217 | if (dev_class->format_device) |
| 218 | s = format (s, "\n%U%U", |
| 219 | format_white_space, indent + 2, |
| 220 | dev_class->format_device, hi->dev_instance, verbose); |
| 221 | } |
| 222 | |
| 223 | return s; |
| 224 | } |
| 225 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 226 | u8 * |
| 227 | format_vnet_sw_interface_name (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 228 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 229 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 230 | vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *); |
| 231 | vnet_sw_interface_t *si_sup = |
| 232 | vnet_get_sup_sw_interface (vnm, si->sw_if_index); |
| 233 | vnet_hw_interface_t *hi_sup; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 234 | |
| 235 | ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE); |
| 236 | hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index); |
| 237 | |
| 238 | s = format (s, "%v", hi_sup->name); |
| 239 | |
| 240 | if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE) |
| 241 | s = format (s, ".%d", si->sub.id); |
| 242 | |
| 243 | return s; |
| 244 | } |
| 245 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 246 | u8 * |
| 247 | format_vnet_sw_if_index_name (u8 * s, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 248 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 249 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 250 | u32 sw_if_index = va_arg (*args, u32); |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 251 | vnet_sw_interface_t *si; |
| 252 | |
Dave Barach | 3940de3 | 2019-07-23 16:28:36 -0400 | [diff] [blame] | 253 | si = vnet_get_sw_interface_or_null (vnm, sw_if_index); |
Neale Ranns | da78f95 | 2017-05-24 09:15:43 -0700 | [diff] [blame] | 254 | |
| 255 | if (NULL == si) |
| 256 | { |
| 257 | return format (s, "DELETED"); |
| 258 | } |
| 259 | return format (s, "%U", format_vnet_sw_interface_name, vnm, si); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 262 | u8 * |
Damjan Marion | a35cc14 | 2018-03-16 01:25:27 +0100 | [diff] [blame] | 263 | format_vnet_hw_if_index_name (u8 * s, va_list * args) |
| 264 | { |
| 265 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 266 | u32 hw_if_index = va_arg (*args, u32); |
| 267 | vnet_hw_interface_t *hi; |
| 268 | |
| 269 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
| 270 | |
| 271 | if (hi == 0) |
| 272 | return format (s, "DELETED"); |
| 273 | |
| 274 | return format (s, "%v", hi->name); |
| 275 | } |
| 276 | |
| 277 | u8 * |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 278 | format_vnet_sw_interface_cntrs (u8 * s, vnet_interface_main_t * im, |
Dave Barach | 5554c56 | 2019-09-11 21:35:48 -0400 | [diff] [blame] | 279 | vnet_sw_interface_t * si, int json) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 280 | { |
Christophe Fontaine | d3c008d | 2017-10-02 18:10:54 +0200 | [diff] [blame] | 281 | u32 indent, n_printed; |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 282 | int j, n_counters; |
Dave Barach | 5554c56 | 2019-09-11 21:35:48 -0400 | [diff] [blame] | 283 | char *x = ""; |
| 284 | int json_need_comma_nl = 0; |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 285 | u8 *n = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 286 | |
Dave Barach | 5554c56 | 2019-09-11 21:35:48 -0400 | [diff] [blame] | 287 | /* |
| 288 | * to output a json snippet, stick quotes in lots of places |
| 289 | * definitely deserves a one-character variable name. |
| 290 | */ |
| 291 | if (json) |
| 292 | x = "\""; |
| 293 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 294 | indent = format_get_indent (s); |
| 295 | n_printed = 0; |
| 296 | |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 297 | n_counters = vec_len (im->combined_sw_if_counters); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 298 | |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 299 | /* rx, tx counters... */ |
| 300 | for (j = 0; j < n_counters; j++) |
| 301 | { |
| 302 | vlib_combined_counter_main_t *cm; |
| 303 | vlib_counter_t v, vtotal; |
| 304 | vtotal.packets = 0; |
| 305 | vtotal.bytes = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 306 | |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 307 | cm = im->combined_sw_if_counters + j; |
| 308 | vlib_get_combined_counter (cm, si->sw_if_index, &v); |
| 309 | vtotal.packets += v.packets; |
| 310 | vtotal.bytes += v.bytes; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 311 | |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 312 | /* Only display non-zero counters. */ |
| 313 | if (vtotal.packets == 0) |
| 314 | continue; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 315 | |
Dave Barach | 5554c56 | 2019-09-11 21:35:48 -0400 | [diff] [blame] | 316 | if (json) |
| 317 | { |
| 318 | if (json_need_comma_nl) |
| 319 | { |
| 320 | vec_add1 (s, ','); |
| 321 | vec_add1 (s, '\n'); |
| 322 | } |
| 323 | s = format (s, "%s%s_packets%s: %s%Ld%s,\n", x, cm->name, x, x, |
| 324 | vtotal.packets, x); |
| 325 | s = format (s, "%s%s_bytes%s: %s%Ld%s", x, cm->name, x, x, |
| 326 | vtotal.bytes, x); |
| 327 | json_need_comma_nl = 1; |
| 328 | continue; |
| 329 | } |
| 330 | |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 331 | if (n_printed > 0) |
| 332 | s = format (s, "\n%U", format_white_space, indent); |
| 333 | n_printed += 2; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 334 | |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 335 | if (n) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 336 | _vec_len (n) = 0; |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 337 | n = format (n, "%s packets", cm->name); |
| 338 | s = format (s, "%-16v%16Ld", n, vtotal.packets); |
| 339 | |
| 340 | _vec_len (n) = 0; |
| 341 | n = format (n, "%s bytes", cm->name); |
| 342 | s = format (s, "\n%U%-16v%16Ld", |
| 343 | format_white_space, indent, n, vtotal.bytes); |
| 344 | } |
| 345 | vec_free (n); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 346 | |
| 347 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 348 | vlib_simple_counter_main_t *cm; |
| 349 | u64 v, vtotal; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 350 | |
| 351 | n_counters = vec_len (im->sw_if_counters); |
| 352 | |
| 353 | for (j = 0; j < n_counters; j++) |
| 354 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 355 | vtotal = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 356 | |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 357 | cm = im->sw_if_counters + j; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 358 | |
Dave Barach | 8fdde3c | 2019-05-17 10:46:40 -0400 | [diff] [blame] | 359 | v = vlib_get_simple_counter (cm, si->sw_if_index); |
| 360 | vtotal += v; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 361 | |
| 362 | /* Only display non-zero counters. */ |
| 363 | if (vtotal == 0) |
| 364 | continue; |
| 365 | |
Dave Barach | 5554c56 | 2019-09-11 21:35:48 -0400 | [diff] [blame] | 366 | if (json) |
| 367 | { |
| 368 | if (json_need_comma_nl) |
| 369 | { |
| 370 | vec_add1 (s, ','); |
| 371 | vec_add1 (s, '\n'); |
| 372 | } |
| 373 | s = format (s, "%s%s%s: %s%Ld%s", x, cm->name, x, x, vtotal, x); |
| 374 | json_need_comma_nl = 1; |
| 375 | continue; |
| 376 | } |
| 377 | |
| 378 | |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 379 | if (n_printed > 0) |
| 380 | s = format (s, "\n%U", format_white_space, indent); |
| 381 | n_printed += 1; |
| 382 | |
| 383 | s = format (s, "%-16s%16Ld", cm->name, vtotal); |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | return s; |
| 388 | } |
| 389 | |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 390 | static u8 * |
| 391 | format_vnet_sw_interface_mtu (u8 * s, va_list * args) |
| 392 | { |
| 393 | vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *); |
| 394 | |
| 395 | return format (s, "%d/%d/%d/%d", si->mtu[VNET_MTU_L3], |
| 396 | si->mtu[VNET_MTU_IP4], |
| 397 | si->mtu[VNET_MTU_IP6], si->mtu[VNET_MTU_MPLS]); |
| 398 | } |
| 399 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 400 | u8 * |
| 401 | format_vnet_sw_interface (u8 * s, va_list * args) |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 402 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 403 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 404 | vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *); |
| 405 | vnet_interface_main_t *im = &vnm->interface_main; |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 406 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 407 | if (!si) |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 408 | return format (s, "%=32s%=5s%=10s%=21s%=16s%=16s", |
| 409 | "Name", "Idx", "State", "MTU (L3/IP4/IP6/MPLS)", "Counter", |
| 410 | "Count"); |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 411 | |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 412 | s = format (s, "%-32U%=5d%=10U%=21U", |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 413 | format_vnet_sw_interface_name, vnm, si, si->sw_if_index, |
Ole Troan | d723161 | 2018-06-07 10:17:57 +0200 | [diff] [blame] | 414 | format_vnet_sw_interface_flags, si->flags, |
| 415 | format_vnet_sw_interface_mtu, si); |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 416 | |
Dave Barach | 5554c56 | 2019-09-11 21:35:48 -0400 | [diff] [blame] | 417 | s = format_vnet_sw_interface_cntrs (s, im, si, 0 /* want json */ ); |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 418 | |
| 419 | return s; |
| 420 | } |
| 421 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 422 | u8 * |
| 423 | format_vnet_sw_interface_name_override (u8 * s, va_list * args) |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 424 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 425 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 426 | vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *); |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 427 | /* caller supplied display name for this interface */ |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 428 | u8 *name = va_arg (*args, u8 *); |
| 429 | vnet_interface_main_t *im = &vnm->interface_main; |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 430 | |
| 431 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 432 | if (!si) |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 433 | return format (s, "%=32s%=5s%=16s%=16s%=16s", |
| 434 | "Name", "Idx", "State", "Counter", "Count"); |
| 435 | |
| 436 | s = format (s, "%-32v%=5d%=16U", |
| 437 | name, si->sw_if_index, |
| 438 | format_vnet_sw_interface_flags, si->flags); |
| 439 | |
Dave Barach | 5554c56 | 2019-09-11 21:35:48 -0400 | [diff] [blame] | 440 | s = format_vnet_sw_interface_cntrs (s, im, si, 0 /* want json */ ); |
Sean Hope | 679ea79 | 2016-02-22 15:12:01 -0500 | [diff] [blame] | 441 | |
| 442 | return s; |
| 443 | } |
| 444 | |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 445 | u8 * |
| 446 | format_vnet_buffer_flags (u8 * s, va_list * args) |
| 447 | { |
| 448 | vlib_buffer_t *buf = va_arg (*args, vlib_buffer_t *); |
| 449 | |
| 450 | #define _(a,b,c,v) if (buf->flags & VNET_BUFFER_F_##b) s = format (s, "%s ", c); |
| 451 | foreach_vnet_buffer_flag; |
| 452 | #undef _ |
| 453 | return s; |
| 454 | } |
| 455 | |
| 456 | u8 * |
| 457 | format_vnet_buffer_opaque (u8 * s, va_list * args) |
| 458 | { |
| 459 | vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *); |
| 460 | vnet_buffer_opaque_t *o = (vnet_buffer_opaque_t *) b->opaque; |
Florin Coras | 3ffe6ca | 2019-06-26 16:27:13 -0700 | [diff] [blame] | 461 | vnet_interface_main_t *im = &vnet_get_main ()->interface_main; |
| 462 | vnet_buffer_opquae_formatter_t helper_fp; |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 463 | int i; |
| 464 | |
| 465 | s = format (s, "raw: "); |
| 466 | |
| 467 | for (i = 0; i < ARRAY_LEN (b->opaque); i++) |
| 468 | s = format (s, "%08x ", b->opaque[i]); |
| 469 | |
| 470 | vec_add1 (s, '\n'); |
| 471 | |
| 472 | s = format (s, |
| 473 | "sw_if_index[VLIB_RX]: %d, sw_if_index[VLIB_TX]: %d", |
| 474 | o->sw_if_index[0], o->sw_if_index[1]); |
| 475 | vec_add1 (s, '\n'); |
| 476 | |
| 477 | s = format (s, |
| 478 | "L2 offset %d, L3 offset %d, L4 offset %d, feature arc index %d", |
| 479 | (u32) (o->l2_hdr_offset), |
| 480 | (u32) (o->l3_hdr_offset), |
| 481 | (u32) (o->l4_hdr_offset), (u32) (o->feature_arc_index)); |
| 482 | vec_add1 (s, '\n'); |
| 483 | |
| 484 | s = format (s, |
| 485 | "ip.adj_index[VLIB_RX]: %d, ip.adj_index[VLIB_TX]: %d", |
| 486 | (u32) (o->ip.adj_index[0]), (u32) (o->ip.adj_index[1])); |
| 487 | vec_add1 (s, '\n'); |
| 488 | |
| 489 | s = format (s, |
| 490 | "ip.flow_hash: 0x%x, ip.save_protocol: 0x%x, ip.fib_index: %d", |
| 491 | o->ip.flow_hash, o->ip.save_protocol, o->ip.fib_index); |
| 492 | vec_add1 (s, '\n'); |
| 493 | |
| 494 | s = format (s, |
| 495 | "ip.save_rewrite_length: %d, ip.rpf_id: %d", |
| 496 | o->ip.save_rewrite_length, o->ip.rpf_id); |
| 497 | vec_add1 (s, '\n'); |
| 498 | |
| 499 | s = format (s, |
| 500 | "ip.icmp.type: %d ip.icmp.code: %d, ip.icmp.data: 0x%x", |
| 501 | (u32) (o->ip.icmp.type), |
| 502 | (u32) (o->ip.icmp.code), o->ip.icmp.data); |
| 503 | vec_add1 (s, '\n'); |
| 504 | |
| 505 | s = format (s, |
| 506 | "ip.reass.next_index: %d, ip.reass.estimated_mtu: %d", |
| 507 | o->ip.reass.next_index, (u32) (o->ip.reass.estimated_mtu)); |
| 508 | vec_add1 (s, '\n'); |
Dave Barach | d7b3066 | 2019-10-24 18:10:10 -0400 | [diff] [blame] | 509 | s = format (s, |
| 510 | "ip.reass.error_next_index: %d, ip.reass.owner_thread_index: %d", |
| 511 | o->ip.reass.error_next_index, |
| 512 | (u32) (o->ip.reass.owner_thread_index)); |
| 513 | vec_add1 (s, '\n'); |
| 514 | s = format (s, |
| 515 | "ip.reass.ip_proto: %d, ip.reass.l4_src_port: %d", |
| 516 | o->ip.reass.ip_proto, (u32) (o->ip.reass.l4_src_port)); |
| 517 | vec_add1 (s, '\n'); |
| 518 | s = format (s, "ip.reass.l4_dst_port: %d", o->ip.reass.l4_dst_port); |
| 519 | vec_add1 (s, '\n'); |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 520 | |
| 521 | s = format (s, |
| 522 | "ip.reass.fragment_first: %d ip.reass.fragment_last: %d", |
| 523 | (u32) (o->ip.reass.fragment_first), |
| 524 | (u32) (o->ip.reass.fragment_last)); |
| 525 | vec_add1 (s, '\n'); |
| 526 | |
| 527 | s = format (s, |
| 528 | "ip.reass.range_first: %d ip.reass.range_last: %d", |
| 529 | (u32) (o->ip.reass.range_first), |
| 530 | (u32) (o->ip.reass.range_last)); |
| 531 | vec_add1 (s, '\n'); |
| 532 | |
| 533 | s = format (s, |
| 534 | "ip.reass.next_range_bi: 0x%x, ip.reass.ip6_frag_hdr_offset: %d", |
| 535 | o->ip.reass.next_range_bi, |
| 536 | (u32) (o->ip.reass.ip6_frag_hdr_offset)); |
| 537 | vec_add1 (s, '\n'); |
| 538 | |
| 539 | s = format (s, |
| 540 | "mpls.ttl: %d, mpls.exp: %d, mpls.first: %d, " |
| 541 | "mpls.save_rewrite_length: %d, mpls.bier.n_bytes: %d", |
| 542 | (u32) (o->mpls.ttl), (u32) (o->mpls.exp), (u32) (o->mpls.first), |
| 543 | o->mpls.save_rewrite_length, (u32) (o->mpls.bier.n_bytes)); |
| 544 | vec_add1 (s, '\n'); |
Dave Barach | d7b3066 | 2019-10-24 18:10:10 -0400 | [diff] [blame] | 545 | s = format (s, "mpls.mpls_hdr_length: %d", (u32) (o->mpls.mpls_hdr_length)); |
| 546 | vec_add1 (s, '\n'); |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 547 | |
| 548 | s = format (s, |
Dave Barach | d7b3066 | 2019-10-24 18:10:10 -0400 | [diff] [blame] | 549 | "l2.feature_bitmap: %08x, l2.bd_index: %d, l2.l2fib_sn %d, " |
| 550 | "l2.l2_len: %d, l2.shg: %d, l2.bd_age: %d", |
| 551 | (u32) (o->l2.feature_bitmap), (u32) (o->l2.bd_index), |
| 552 | (u32) (o->l2.l2fib_sn), |
| 553 | (u32) (o->l2.l2_len), (u32) (o->l2.shg), (u32) (o->l2.bd_age)); |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 554 | vec_add1 (s, '\n'); |
| 555 | |
| 556 | s = format (s, |
Dave Barach | 7bdaa3f | 2018-12-03 11:33:09 -0500 | [diff] [blame] | 557 | "l2.feature_bitmap_input: %U, L2.feature_bitmap_output: %U", |
Neale Ranns | 47a3d99 | 2020-09-29 15:38:51 +0000 | [diff] [blame] | 558 | format_l2_input_feature_bitmap, o->l2.feature_bitmap, 0, |
Dave Barach | 7bdaa3f | 2018-12-03 11:33:09 -0500 | [diff] [blame] | 559 | format_l2_output_features, o->l2.feature_bitmap, 0); |
| 560 | vec_add1 (s, '\n'); |
| 561 | |
| 562 | s = format (s, |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 563 | "l2t.next_index: %d, l2t.session_index: %d", |
| 564 | (u32) (o->l2t.next_index), o->l2t.session_index); |
| 565 | vec_add1 (s, '\n'); |
| 566 | |
| 567 | s = format (s, |
| 568 | "l2_classify.table_index: %d, l2_classify.opaque_index: %d, " |
| 569 | "l2_classify.hash: 0x%llx", |
| 570 | o->l2_classify.table_index, |
| 571 | o->l2_classify.opaque_index, o->l2_classify.hash); |
| 572 | vec_add1 (s, '\n'); |
| 573 | |
| 574 | s = format (s, "policer.index: %d", o->policer.index); |
| 575 | vec_add1 (s, '\n'); |
| 576 | |
Dave Barach | d7b3066 | 2019-10-24 18:10:10 -0400 | [diff] [blame] | 577 | s = format (s, "ipsec.sad_index: %d, ipsec.protect_index", |
| 578 | o->ipsec.sad_index, o->ipsec.protect_index); |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 579 | vec_add1 (s, '\n'); |
| 580 | |
| 581 | s = format (s, "map.mtu: %d", (u32) (o->map.mtu)); |
| 582 | vec_add1 (s, '\n'); |
| 583 | |
| 584 | s = format (s, |
Dave Barach | d7b3066 | 2019-10-24 18:10:10 -0400 | [diff] [blame] | 585 | "map_t.map_domain_index: %d, map_t.v6.saddr: 0x%x, " |
| 586 | "map_t.v6.daddr: 0x%x, map_t.v6.frag_offset: %d, " |
| 587 | "map_t.v6.l4_offset: %d, map_t.v6.l4_protocol: %d, " |
| 588 | "map.t.checksum_offset: %d", |
| 589 | o->map_t.map_domain_index, |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 590 | o->map_t.v6.saddr, |
| 591 | o->map_t.v6.daddr, |
Dave Barach | d7b3066 | 2019-10-24 18:10:10 -0400 | [diff] [blame] | 592 | (u32) (o->map_t.v6.frag_offset), (u32) (o->map_t.v6.l4_offset), |
| 593 | (u32) (o->map_t.v6.l4_protocol), |
| 594 | (u32) (o->map_t.checksum_offset)); |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 595 | vec_add1 (s, '\n'); |
| 596 | |
| 597 | s = format (s, |
| 598 | "map_t.v6.l4_protocol: %d, map_t.checksum_offset: %d, " |
| 599 | "map_t.mtu: %d", |
| 600 | (u32) (o->map_t.v6.l4_protocol), |
| 601 | (u32) (o->map_t.checksum_offset), (u32) (o->map_t.mtu)); |
| 602 | vec_add1 (s, '\n'); |
| 603 | |
| 604 | s = format (s, |
| 605 | "ip_frag.mtu: %d, ip_frag.next_index: %d, ip_frag.flags: 0x%x", |
| 606 | (u32) (o->ip_frag.mtu), |
| 607 | (u32) (o->ip_frag.next_index), (u32) (o->ip_frag.flags)); |
| 608 | vec_add1 (s, '\n'); |
| 609 | |
| 610 | s = format (s, "cop.current_config_index: %d", o->cop.current_config_index); |
| 611 | vec_add1 (s, '\n'); |
| 612 | |
| 613 | s = format (s, "lisp.overlay_afi: %d", (u32) (o->lisp.overlay_afi)); |
| 614 | vec_add1 (s, '\n'); |
| 615 | |
| 616 | s = format |
Dave Barach | d7b3066 | 2019-10-24 18:10:10 -0400 | [diff] [blame] | 617 | (s, |
| 618 | "tcp.connection_index: %d, tcp.seq_number: %d, tcp.next_node_opaque: %d " |
| 619 | "tcp.seq_end: %d, tcp.ack_number: %d, tcp.hdr_offset: %d, " |
| 620 | "tcp.data_offset: %d", o->tcp.connection_index, o->tcp.next_node_opaque, |
| 621 | o->tcp.seq_number, o->tcp.seq_end, o->tcp.ack_number, |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 622 | (u32) (o->tcp.hdr_offset), (u32) (o->tcp.data_offset)); |
| 623 | vec_add1 (s, '\n'); |
| 624 | |
| 625 | s = format (s, |
| 626 | "tcp.data_len: %d, tcp.flags: 0x%x", |
| 627 | (u32) (o->tcp.data_len), (u32) (o->tcp.flags)); |
| 628 | vec_add1 (s, '\n'); |
| 629 | |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 630 | s = format (s, "snat.flags: 0x%x", o->snat.flags); |
| 631 | vec_add1 (s, '\n'); |
Florin Coras | 3ffe6ca | 2019-06-26 16:27:13 -0700 | [diff] [blame] | 632 | |
| 633 | for (i = 0; i < vec_len (im->buffer_opaque_format_helpers); i++) |
| 634 | { |
| 635 | helper_fp = im->buffer_opaque_format_helpers[i]; |
| 636 | s = (*helper_fp) (b, s); |
| 637 | } |
| 638 | |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 639 | return s; |
| 640 | } |
| 641 | |
| 642 | u8 * |
| 643 | format_vnet_buffer_opaque2 (u8 * s, va_list * args) |
| 644 | { |
| 645 | vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *); |
| 646 | vnet_buffer_opaque2_t *o = (vnet_buffer_opaque2_t *) b->opaque2; |
Florin Coras | 3ffe6ca | 2019-06-26 16:27:13 -0700 | [diff] [blame] | 647 | vnet_interface_main_t *im = &vnet_get_main ()->interface_main; |
| 648 | vnet_buffer_opquae_formatter_t helper_fp; |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 649 | |
| 650 | int i; |
| 651 | |
| 652 | s = format (s, "raw: "); |
| 653 | |
| 654 | for (i = 0; i < ARRAY_LEN (b->opaque2); i++) |
| 655 | s = format (s, "%08x ", b->opaque2[i]); |
| 656 | vec_add1 (s, '\n'); |
| 657 | |
| 658 | s = format (s, "qos.bits: %x, qos.source: %x", |
| 659 | (u32) (o->qos.bits), (u32) (o->qos.source)); |
| 660 | vec_add1 (s, '\n'); |
| 661 | s = format (s, "loop_counter: %d", o->loop_counter); |
| 662 | vec_add1 (s, '\n'); |
| 663 | |
Neale Ranns | 4ba6772 | 2019-02-28 11:11:39 +0000 | [diff] [blame] | 664 | s = format (s, "gbp.flags: %x, gbp.sclass: %d", |
| 665 | (u32) (o->gbp.flags), (u32) (o->gbp.sclass)); |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 666 | vec_add1 (s, '\n'); |
| 667 | |
Dave Barach | d7b3066 | 2019-10-24 18:10:10 -0400 | [diff] [blame] | 668 | s = format (s, "gso_size: %d, gso_l4_hdr_sz: %d", |
| 669 | (u32) (o->gso_size), (u32) (o->gso_l4_hdr_sz)); |
| 670 | vec_add1 (s, '\n'); |
| 671 | |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 672 | s = format (s, "pg_replay_timestamp: %llu", (u32) (o->pg_replay_timestamp)); |
| 673 | vec_add1 (s, '\n'); |
Florin Coras | 3ffe6ca | 2019-06-26 16:27:13 -0700 | [diff] [blame] | 674 | |
| 675 | for (i = 0; i < vec_len (im->buffer_opaque2_format_helpers); i++) |
| 676 | { |
| 677 | helper_fp = im->buffer_opaque2_format_helpers[i]; |
| 678 | s = (*helper_fp) (b, s); |
| 679 | } |
| 680 | |
Dave Barach | 7fff3d2 | 2018-11-27 16:52:59 -0500 | [diff] [blame] | 681 | return s; |
| 682 | } |
| 683 | |
Florin Coras | 3ffe6ca | 2019-06-26 16:27:13 -0700 | [diff] [blame] | 684 | void |
| 685 | vnet_register_format_buffer_opaque_helper (vnet_buffer_opquae_formatter_t fp) |
| 686 | { |
| 687 | vnet_interface_main_t *im = &vnet_get_main ()->interface_main; |
| 688 | vec_add1 (im->buffer_opaque_format_helpers, fp); |
| 689 | } |
| 690 | |
| 691 | void |
| 692 | vnet_register_format_buffer_opaque2_helper (vnet_buffer_opquae_formatter_t fp) |
| 693 | { |
| 694 | vnet_interface_main_t *im = &vnet_get_main ()->interface_main; |
| 695 | vec_add1 (im->buffer_opaque2_format_helpers, fp); |
| 696 | } |
| 697 | |
| 698 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 699 | uword |
Dave Barach | 08eb2bb | 2020-04-15 09:34:43 -0400 | [diff] [blame] | 700 | unformat_vnet_buffer_flags (unformat_input_t * input, va_list * args) |
| 701 | { |
| 702 | u32 *flagp = va_arg (*args, u32 *); |
| 703 | int rv = 0; |
| 704 | u32 flags = 0; |
| 705 | |
| 706 | while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) |
| 707 | { |
| 708 | /* Red herring, there is no such buffer flag */ |
| 709 | if (unformat (input, "avail8")) |
| 710 | return 0; |
| 711 | #define _(bit,enum,str,verbose) \ |
| 712 | else if (unformat (input, str)) \ |
| 713 | { \ |
| 714 | flags |= (1 << LOG2_VLIB_BUFFER_FLAG_USER(bit)); \ |
| 715 | rv = 1; \ |
| 716 | } |
| 717 | foreach_vnet_buffer_flag |
| 718 | #undef _ |
| 719 | else |
| 720 | break; |
| 721 | } |
| 722 | if (rv) |
| 723 | *flagp = flags; |
| 724 | return rv; |
| 725 | } |
| 726 | |
| 727 | uword |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 728 | unformat_vnet_hw_interface (unformat_input_t * input, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 729 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 730 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 731 | u32 *hw_if_index = va_arg (*args, u32 *); |
| 732 | vnet_interface_main_t *im = &vnm->interface_main; |
| 733 | vnet_device_class_t *c; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 734 | |
| 735 | /* Try per device class functions first. */ |
| 736 | vec_foreach (c, im->device_classes) |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 737 | { |
| 738 | if (c->unformat_device_name |
| 739 | && unformat_user (input, c->unformat_device_name, hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 740 | return 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 741 | } |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 742 | |
| 743 | return unformat_user (input, unformat_hash_vec_string, |
| 744 | im->hw_interface_by_name, hw_if_index); |
| 745 | } |
| 746 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 747 | uword |
| 748 | unformat_vnet_sw_interface (unformat_input_t * input, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 749 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 750 | vnet_main_t *vnm = va_arg (*args, vnet_main_t *); |
| 751 | u32 *result = va_arg (*args, u32 *); |
| 752 | vnet_hw_interface_t *hi; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 753 | u32 hw_if_index, id, id_specified; |
Eyal Bari | 3212c57 | 2017-03-06 11:47:50 +0200 | [diff] [blame] | 754 | u32 sw_if_index; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 755 | u8 *if_name = 0; |
| 756 | uword *p, error = 0; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 757 | |
| 758 | id = ~0; |
| 759 | if (unformat (input, "%_%v.%d%_", &if_name, &id) |
| 760 | && ((p = hash_get (vnm->interface_main.hw_interface_by_name, if_name)))) |
| 761 | { |
| 762 | hw_if_index = p[0]; |
| 763 | id_specified = 1; |
| 764 | } |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 765 | else |
| 766 | if (unformat (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index)) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 767 | id_specified = 0; |
| 768 | else |
| 769 | goto done; |
| 770 | |
| 771 | hi = vnet_get_hw_interface (vnm, hw_if_index); |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 772 | if (!id_specified) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 773 | { |
Eyal Bari | 3212c57 | 2017-03-06 11:47:50 +0200 | [diff] [blame] | 774 | sw_if_index = hi->sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 775 | } |
| 776 | else |
| 777 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 778 | 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] | 779 | goto done; |
| 780 | sw_if_index = p[0]; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 781 | } |
Eyal Bari | 3212c57 | 2017-03-06 11:47:50 +0200 | [diff] [blame] | 782 | if (!vnet_sw_interface_is_api_visible (vnm, sw_if_index)) |
| 783 | goto done; |
| 784 | *result = sw_if_index; |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 785 | error = 1; |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 786 | done: |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 787 | vec_free (if_name); |
| 788 | return error; |
| 789 | } |
| 790 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 791 | uword |
| 792 | unformat_vnet_sw_interface_flags (unformat_input_t * input, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 793 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 794 | u32 *result = va_arg (*args, u32 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 795 | u32 flags = 0; |
| 796 | |
| 797 | if (unformat (input, "up")) |
| 798 | flags |= VNET_SW_INTERFACE_FLAG_ADMIN_UP; |
| 799 | else if (unformat (input, "down")) |
| 800 | flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP; |
| 801 | else if (unformat (input, "punt")) |
| 802 | flags |= VNET_SW_INTERFACE_FLAG_PUNT; |
| 803 | else if (unformat (input, "enable")) |
| 804 | flags &= ~VNET_SW_INTERFACE_FLAG_PUNT; |
| 805 | else |
| 806 | return 0; |
| 807 | |
| 808 | *result = flags; |
| 809 | return 1; |
| 810 | } |
| 811 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 812 | uword |
| 813 | unformat_vnet_hw_interface_flags (unformat_input_t * input, va_list * args) |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 814 | { |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 815 | u32 *result = va_arg (*args, u32 *); |
Ed Warnicke | cb9cada | 2015-12-08 15:45:58 -0700 | [diff] [blame] | 816 | u32 flags = 0; |
| 817 | |
| 818 | if (unformat (input, "up")) |
| 819 | flags |= VNET_HW_INTERFACE_FLAG_LINK_UP; |
| 820 | else if (unformat (input, "down")) |
| 821 | flags &= ~VNET_HW_INTERFACE_FLAG_LINK_UP; |
| 822 | else |
| 823 | return 0; |
| 824 | |
| 825 | *result = flags; |
| 826 | return 1; |
| 827 | } |
| 828 | |
Dave Barach | ba868bb | 2016-08-08 09:51:21 -0400 | [diff] [blame] | 829 | /* |
| 830 | * fd.io coding-style-patch-verification: ON |
| 831 | * |
| 832 | * Local Variables: |
| 833 | * eval: (c-set-style "gnu") |
| 834 | * End: |
| 835 | */ |