blob: 507e2676ccb2976810de558e7febe2295c0b9b6a [file] [log] [blame]
Ed Warnickecb9cada2015-12-08 15:45:58 -07001/*
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 Lobcebbb92016-04-05 15:47:43 -040041#include <vppinfra/bitmap.h>
Dave Barach7bdaa3f2018-12-03 11:33:09 -050042#include <vnet/l2/l2_input.h>
43#include <vnet/l2/l2_output.h>
Jon Loeliger9485d992019-11-08 15:05:23 -060044#include <vnet/l2/l2_vtr.h>
45
46u8 *
47format_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 Warnickecb9cada2015-12-08 15:45:58 -070080
Dave Barachba868bb2016-08-08 09:51:21 -040081u8 *
82format_vnet_sw_interface_flags (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070083{
84 u32 flags = va_arg (*args, u32);
85
Damjan Marionabce5092017-05-10 20:09:31 +020086 if (flags & VNET_SW_INTERFACE_FLAG_ERROR)
87 s = format (s, "error");
Dave Barachba868bb2016-08-08 09:51:21 -040088 else
John Lobcebbb92016-04-05 15:47:43 -040089 {
Dave Barachba868bb2016-08-08 09:51:21 -040090 s = format (s, "%s",
John Lobcebbb92016-04-05 15:47:43 -040091 (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "down");
Dave Barachba868bb2016-08-08 09:51:21 -040092 if (flags & VNET_SW_INTERFACE_FLAG_PUNT)
John Lobcebbb92016-04-05 15:47:43 -040093 s = format (s, "/punt");
94 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070095
96 return s;
97}
98
Dave Barachba868bb2016-08-08 09:51:21 -040099u8 *
Damjan Marion44036902017-04-28 12:29:15 +0200100format_vnet_hw_interface_rx_mode (u8 * s, va_list * args)
101{
102 vnet_hw_interface_rx_mode mode = va_arg (*args, vnet_hw_interface_rx_mode);
103
104 if (mode == VNET_HW_INTERFACE_RX_MODE_POLLING)
105 return format (s, "polling");
106
107 if (mode == VNET_HW_INTERFACE_RX_MODE_INTERRUPT)
108 return format (s, "interrupt");
109
110 if (mode == VNET_HW_INTERFACE_RX_MODE_ADAPTIVE)
111 return format (s, "adaptive");
112
113 return format (s, "unknown");
114}
115
116u8 *
Damjan Marion5100aa92018-11-08 15:30:16 +0100117format_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
133
134u8 *
Dave Barachba868bb2016-08-08 09:51:21 -0400135format_vnet_hw_interface (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700136{
Dave Barachba868bb2016-08-08 09:51:21 -0400137 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
138 vnet_hw_interface_t *hi = va_arg (*args, vnet_hw_interface_t *);
139 vnet_hw_interface_class_t *hw_class;
140 vnet_device_class_t *dev_class;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700141 int verbose = va_arg (*args, int);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200142 u32 indent;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700143
Dave Barachba868bb2016-08-08 09:51:21 -0400144 if (!hi)
145 return format (s, "%=32s%=6s%=8s%s", "Name", "Idx", "Link", "Hardware");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700146
147 indent = format_get_indent (s);
148
John Lobcebbb92016-04-05 15:47:43 -0400149 s = format (s, "%-32v%=6d", hi->name, hi->hw_if_index);
150
151 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
152 s = format (s, "%=8s", "slave");
153 else
Dave Barachba868bb2016-08-08 09:51:21 -0400154 s = format (s, "%=8s",
John Lobcebbb92016-04-05 15:47:43 -0400155 hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP ? "up" : "down");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700156
157 hw_class = vnet_get_hw_interface_class (vnm, hi->hw_class_index);
158 dev_class = vnet_get_device_class (vnm, hi->dev_class_index);
159
Dave Barachba868bb2016-08-08 09:51:21 -0400160 if (hi->bond_info && (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
John Lobcebbb92016-04-05 15:47:43 -0400161 {
162 int hw_idx;
163 s = format (s, "Slave-Idx:");
Dave Barachba868bb2016-08-08 09:51:21 -0400164 clib_bitmap_foreach (hw_idx, hi->bond_info, s =
165 format (s, " %d", hw_idx));
John Lobcebbb92016-04-05 15:47:43 -0400166 }
Dave Barachba868bb2016-08-08 09:51:21 -0400167 else if (dev_class->format_device_name)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700168 s = format (s, "%U", dev_class->format_device_name, hi->dev_instance);
169 else
170 s = format (s, "%s%d", dev_class->name, hi->dev_instance);
171
Damjan Marion5100aa92018-11-08 15:30:16 +0100172 s = format (s, "\n%ULink speed: %U", format_white_space, indent + 2,
173 format_vnet_hw_interface_link_speed, hi->link_speed);
174
Ed Warnickecb9cada2015-12-08 15:45:58 -0700175 if (verbose)
176 {
177 if (hw_class->format_device)
178 s = format (s, "\n%U%U",
179 format_white_space, indent + 2,
180 hw_class->format_device, hi->hw_if_index, verbose);
181 else
182 {
183 s = format (s, "\n%U%s",
Dave Barachba868bb2016-08-08 09:51:21 -0400184 format_white_space, indent + 2, hw_class->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700185 if (hw_class->format_address && vec_len (hi->hw_address) > 0)
Dave Barachba868bb2016-08-08 09:51:21 -0400186 s =
187 format (s, " address %U", hw_class->format_address,
188 hi->hw_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700189 }
190
191 if (dev_class->format_device)
192 s = format (s, "\n%U%U",
193 format_white_space, indent + 2,
194 dev_class->format_device, hi->dev_instance, verbose);
195 }
196
197 return s;
198}
199
Dave Barachba868bb2016-08-08 09:51:21 -0400200u8 *
201format_vnet_sw_interface_name (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700202{
Dave Barachba868bb2016-08-08 09:51:21 -0400203 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
204 vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
205 vnet_sw_interface_t *si_sup =
206 vnet_get_sup_sw_interface (vnm, si->sw_if_index);
207 vnet_hw_interface_t *hi_sup;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700208
209 ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
210 hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);
211
212 s = format (s, "%v", hi_sup->name);
213
214 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
215 s = format (s, ".%d", si->sub.id);
216
217 return s;
218}
219
Dave Barachba868bb2016-08-08 09:51:21 -0400220u8 *
221format_vnet_sw_if_index_name (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700222{
Dave Barachba868bb2016-08-08 09:51:21 -0400223 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700224 u32 sw_if_index = va_arg (*args, u32);
Neale Rannsda78f952017-05-24 09:15:43 -0700225 vnet_sw_interface_t *si;
226
Dave Barach3940de32019-07-23 16:28:36 -0400227 si = vnet_get_sw_interface_or_null (vnm, sw_if_index);
Neale Rannsda78f952017-05-24 09:15:43 -0700228
229 if (NULL == si)
230 {
231 return format (s, "DELETED");
232 }
233 return format (s, "%U", format_vnet_sw_interface_name, vnm, si);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700234}
235
Dave Barachba868bb2016-08-08 09:51:21 -0400236u8 *
Damjan Mariona35cc142018-03-16 01:25:27 +0100237format_vnet_hw_if_index_name (u8 * s, va_list * args)
238{
239 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
240 u32 hw_if_index = va_arg (*args, u32);
241 vnet_hw_interface_t *hi;
242
243 hi = vnet_get_hw_interface (vnm, hw_if_index);
244
245 if (hi == 0)
246 return format (s, "DELETED");
247
248 return format (s, "%v", hi->name);
249}
250
251u8 *
Dave Barachba868bb2016-08-08 09:51:21 -0400252format_vnet_sw_interface_cntrs (u8 * s, vnet_interface_main_t * im,
Dave Barach5554c562019-09-11 21:35:48 -0400253 vnet_sw_interface_t * si, int json)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700254{
Christophe Fontained3c008d2017-10-02 18:10:54 +0200255 u32 indent, n_printed;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400256 int j, n_counters;
Dave Barach5554c562019-09-11 21:35:48 -0400257 char *x = "";
258 int json_need_comma_nl = 0;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400259 u8 *n = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700260
Dave Barach5554c562019-09-11 21:35:48 -0400261 /*
262 * to output a json snippet, stick quotes in lots of places
263 * definitely deserves a one-character variable name.
264 */
265 if (json)
266 x = "\"";
267
Ed Warnickecb9cada2015-12-08 15:45:58 -0700268 indent = format_get_indent (s);
269 n_printed = 0;
270
Dave Barach8fdde3c2019-05-17 10:46:40 -0400271 n_counters = vec_len (im->combined_sw_if_counters);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700272
Dave Barach8fdde3c2019-05-17 10:46:40 -0400273 /* rx, tx counters... */
274 for (j = 0; j < n_counters; j++)
275 {
276 vlib_combined_counter_main_t *cm;
277 vlib_counter_t v, vtotal;
278 vtotal.packets = 0;
279 vtotal.bytes = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700280
Dave Barach8fdde3c2019-05-17 10:46:40 -0400281 cm = im->combined_sw_if_counters + j;
282 vlib_get_combined_counter (cm, si->sw_if_index, &v);
283 vtotal.packets += v.packets;
284 vtotal.bytes += v.bytes;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700285
Dave Barach8fdde3c2019-05-17 10:46:40 -0400286 /* Only display non-zero counters. */
287 if (vtotal.packets == 0)
288 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700289
Dave Barach5554c562019-09-11 21:35:48 -0400290 if (json)
291 {
292 if (json_need_comma_nl)
293 {
294 vec_add1 (s, ',');
295 vec_add1 (s, '\n');
296 }
297 s = format (s, "%s%s_packets%s: %s%Ld%s,\n", x, cm->name, x, x,
298 vtotal.packets, x);
299 s = format (s, "%s%s_bytes%s: %s%Ld%s", x, cm->name, x, x,
300 vtotal.bytes, x);
301 json_need_comma_nl = 1;
302 continue;
303 }
304
Dave Barach8fdde3c2019-05-17 10:46:40 -0400305 if (n_printed > 0)
306 s = format (s, "\n%U", format_white_space, indent);
307 n_printed += 2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700308
Dave Barach8fdde3c2019-05-17 10:46:40 -0400309 if (n)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700310 _vec_len (n) = 0;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400311 n = format (n, "%s packets", cm->name);
312 s = format (s, "%-16v%16Ld", n, vtotal.packets);
313
314 _vec_len (n) = 0;
315 n = format (n, "%s bytes", cm->name);
316 s = format (s, "\n%U%-16v%16Ld",
317 format_white_space, indent, n, vtotal.bytes);
318 }
319 vec_free (n);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700320
321 {
Dave Barachba868bb2016-08-08 09:51:21 -0400322 vlib_simple_counter_main_t *cm;
323 u64 v, vtotal;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700324
325 n_counters = vec_len (im->sw_if_counters);
326
327 for (j = 0; j < n_counters; j++)
328 {
Dave Barachba868bb2016-08-08 09:51:21 -0400329 vtotal = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700330
Dave Barach8fdde3c2019-05-17 10:46:40 -0400331 cm = im->sw_if_counters + j;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700332
Dave Barach8fdde3c2019-05-17 10:46:40 -0400333 v = vlib_get_simple_counter (cm, si->sw_if_index);
334 vtotal += v;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700335
336 /* Only display non-zero counters. */
337 if (vtotal == 0)
338 continue;
339
Dave Barach5554c562019-09-11 21:35:48 -0400340 if (json)
341 {
342 if (json_need_comma_nl)
343 {
344 vec_add1 (s, ',');
345 vec_add1 (s, '\n');
346 }
347 s = format (s, "%s%s%s: %s%Ld%s", x, cm->name, x, x, vtotal, x);
348 json_need_comma_nl = 1;
349 continue;
350 }
351
352
Ed Warnickecb9cada2015-12-08 15:45:58 -0700353 if (n_printed > 0)
354 s = format (s, "\n%U", format_white_space, indent);
355 n_printed += 1;
356
357 s = format (s, "%-16s%16Ld", cm->name, vtotal);
358 }
359 }
360
361 return s;
362}
363
Ole Troand7231612018-06-07 10:17:57 +0200364static u8 *
365format_vnet_sw_interface_mtu (u8 * s, va_list * args)
366{
367 vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
368
369 return format (s, "%d/%d/%d/%d", si->mtu[VNET_MTU_L3],
370 si->mtu[VNET_MTU_IP4],
371 si->mtu[VNET_MTU_IP6], si->mtu[VNET_MTU_MPLS]);
372}
373
Dave Barachba868bb2016-08-08 09:51:21 -0400374u8 *
375format_vnet_sw_interface (u8 * s, va_list * args)
Sean Hope679ea792016-02-22 15:12:01 -0500376{
Dave Barachba868bb2016-08-08 09:51:21 -0400377 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
378 vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
379 vnet_interface_main_t *im = &vnm->interface_main;
Sean Hope679ea792016-02-22 15:12:01 -0500380
Dave Barachba868bb2016-08-08 09:51:21 -0400381 if (!si)
Ole Troand7231612018-06-07 10:17:57 +0200382 return format (s, "%=32s%=5s%=10s%=21s%=16s%=16s",
383 "Name", "Idx", "State", "MTU (L3/IP4/IP6/MPLS)", "Counter",
384 "Count");
Sean Hope679ea792016-02-22 15:12:01 -0500385
Ole Troand7231612018-06-07 10:17:57 +0200386 s = format (s, "%-32U%=5d%=10U%=21U",
Sean Hope679ea792016-02-22 15:12:01 -0500387 format_vnet_sw_interface_name, vnm, si, si->sw_if_index,
Ole Troand7231612018-06-07 10:17:57 +0200388 format_vnet_sw_interface_flags, si->flags,
389 format_vnet_sw_interface_mtu, si);
Sean Hope679ea792016-02-22 15:12:01 -0500390
Dave Barach5554c562019-09-11 21:35:48 -0400391 s = format_vnet_sw_interface_cntrs (s, im, si, 0 /* want json */ );
Sean Hope679ea792016-02-22 15:12:01 -0500392
393 return s;
394}
395
Dave Barachba868bb2016-08-08 09:51:21 -0400396u8 *
397format_vnet_sw_interface_name_override (u8 * s, va_list * args)
Sean Hope679ea792016-02-22 15:12:01 -0500398{
Dave Barachba868bb2016-08-08 09:51:21 -0400399 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
400 vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
Sean Hope679ea792016-02-22 15:12:01 -0500401 /* caller supplied display name for this interface */
Dave Barachba868bb2016-08-08 09:51:21 -0400402 u8 *name = va_arg (*args, u8 *);
403 vnet_interface_main_t *im = &vnm->interface_main;
Sean Hope679ea792016-02-22 15:12:01 -0500404
405
Dave Barachba868bb2016-08-08 09:51:21 -0400406 if (!si)
Sean Hope679ea792016-02-22 15:12:01 -0500407 return format (s, "%=32s%=5s%=16s%=16s%=16s",
408 "Name", "Idx", "State", "Counter", "Count");
409
410 s = format (s, "%-32v%=5d%=16U",
411 name, si->sw_if_index,
412 format_vnet_sw_interface_flags, si->flags);
413
Dave Barach5554c562019-09-11 21:35:48 -0400414 s = format_vnet_sw_interface_cntrs (s, im, si, 0 /* want json */ );
Sean Hope679ea792016-02-22 15:12:01 -0500415
416 return s;
417}
418
Dave Barach7fff3d22018-11-27 16:52:59 -0500419u8 *
420format_vnet_buffer_flags (u8 * s, va_list * args)
421{
422 vlib_buffer_t *buf = va_arg (*args, vlib_buffer_t *);
423
424#define _(a,b,c,v) if (buf->flags & VNET_BUFFER_F_##b) s = format (s, "%s ", c);
425 foreach_vnet_buffer_flag;
426#undef _
427 return s;
428}
429
430u8 *
431format_vnet_buffer_opaque (u8 * s, va_list * args)
432{
433 vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *);
434 vnet_buffer_opaque_t *o = (vnet_buffer_opaque_t *) b->opaque;
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700435 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
436 vnet_buffer_opquae_formatter_t helper_fp;
Dave Barach7fff3d22018-11-27 16:52:59 -0500437 int i;
438
439 s = format (s, "raw: ");
440
441 for (i = 0; i < ARRAY_LEN (b->opaque); i++)
442 s = format (s, "%08x ", b->opaque[i]);
443
444 vec_add1 (s, '\n');
445
446 s = format (s,
447 "sw_if_index[VLIB_RX]: %d, sw_if_index[VLIB_TX]: %d",
448 o->sw_if_index[0], o->sw_if_index[1]);
449 vec_add1 (s, '\n');
450
451 s = format (s,
452 "L2 offset %d, L3 offset %d, L4 offset %d, feature arc index %d",
453 (u32) (o->l2_hdr_offset),
454 (u32) (o->l3_hdr_offset),
455 (u32) (o->l4_hdr_offset), (u32) (o->feature_arc_index));
456 vec_add1 (s, '\n');
457
458 s = format (s,
459 "ip.adj_index[VLIB_RX]: %d, ip.adj_index[VLIB_TX]: %d",
460 (u32) (o->ip.adj_index[0]), (u32) (o->ip.adj_index[1]));
461 vec_add1 (s, '\n');
462
463 s = format (s,
464 "ip.flow_hash: 0x%x, ip.save_protocol: 0x%x, ip.fib_index: %d",
465 o->ip.flow_hash, o->ip.save_protocol, o->ip.fib_index);
466 vec_add1 (s, '\n');
467
468 s = format (s,
469 "ip.save_rewrite_length: %d, ip.rpf_id: %d",
470 o->ip.save_rewrite_length, o->ip.rpf_id);
471 vec_add1 (s, '\n');
472
473 s = format (s,
474 "ip.icmp.type: %d ip.icmp.code: %d, ip.icmp.data: 0x%x",
475 (u32) (o->ip.icmp.type),
476 (u32) (o->ip.icmp.code), o->ip.icmp.data);
477 vec_add1 (s, '\n');
478
479 s = format (s,
480 "ip.reass.next_index: %d, ip.reass.estimated_mtu: %d",
481 o->ip.reass.next_index, (u32) (o->ip.reass.estimated_mtu));
482 vec_add1 (s, '\n');
Dave Barachd7b30662019-10-24 18:10:10 -0400483 s = format (s,
484 "ip.reass.error_next_index: %d, ip.reass.owner_thread_index: %d",
485 o->ip.reass.error_next_index,
486 (u32) (o->ip.reass.owner_thread_index));
487 vec_add1 (s, '\n');
488 s = format (s,
489 "ip.reass.ip_proto: %d, ip.reass.l4_src_port: %d",
490 o->ip.reass.ip_proto, (u32) (o->ip.reass.l4_src_port));
491 vec_add1 (s, '\n');
492 s = format (s, "ip.reass.l4_dst_port: %d", o->ip.reass.l4_dst_port);
493 vec_add1 (s, '\n');
Dave Barach7fff3d22018-11-27 16:52:59 -0500494
495 s = format (s,
496 "ip.reass.fragment_first: %d ip.reass.fragment_last: %d",
497 (u32) (o->ip.reass.fragment_first),
498 (u32) (o->ip.reass.fragment_last));
499 vec_add1 (s, '\n');
500
501 s = format (s,
502 "ip.reass.range_first: %d ip.reass.range_last: %d",
503 (u32) (o->ip.reass.range_first),
504 (u32) (o->ip.reass.range_last));
505 vec_add1 (s, '\n');
506
507 s = format (s,
508 "ip.reass.next_range_bi: 0x%x, ip.reass.ip6_frag_hdr_offset: %d",
509 o->ip.reass.next_range_bi,
510 (u32) (o->ip.reass.ip6_frag_hdr_offset));
511 vec_add1 (s, '\n');
512
513 s = format (s,
514 "mpls.ttl: %d, mpls.exp: %d, mpls.first: %d, "
515 "mpls.save_rewrite_length: %d, mpls.bier.n_bytes: %d",
516 (u32) (o->mpls.ttl), (u32) (o->mpls.exp), (u32) (o->mpls.first),
517 o->mpls.save_rewrite_length, (u32) (o->mpls.bier.n_bytes));
518 vec_add1 (s, '\n');
Dave Barachd7b30662019-10-24 18:10:10 -0400519 s = format (s, "mpls.mpls_hdr_length: %d", (u32) (o->mpls.mpls_hdr_length));
520 vec_add1 (s, '\n');
Dave Barach7fff3d22018-11-27 16:52:59 -0500521
522 s = format (s,
Dave Barachd7b30662019-10-24 18:10:10 -0400523 "l2.feature_bitmap: %08x, l2.bd_index: %d, l2.l2fib_sn %d, "
524 "l2.l2_len: %d, l2.shg: %d, l2.bd_age: %d",
525 (u32) (o->l2.feature_bitmap), (u32) (o->l2.bd_index),
526 (u32) (o->l2.l2fib_sn),
527 (u32) (o->l2.l2_len), (u32) (o->l2.shg), (u32) (o->l2.bd_age));
Dave Barach7fff3d22018-11-27 16:52:59 -0500528 vec_add1 (s, '\n');
529
530 s = format (s,
Dave Barach7bdaa3f2018-12-03 11:33:09 -0500531 "l2.feature_bitmap_input: %U, L2.feature_bitmap_output: %U",
532 format_l2_input_features, o->l2.feature_bitmap, 0,
533 format_l2_output_features, o->l2.feature_bitmap, 0);
534 vec_add1 (s, '\n');
535
536 s = format (s,
Dave Barach7fff3d22018-11-27 16:52:59 -0500537 "l2t.next_index: %d, l2t.session_index: %d",
538 (u32) (o->l2t.next_index), o->l2t.session_index);
539 vec_add1 (s, '\n');
540
541 s = format (s,
542 "l2_classify.table_index: %d, l2_classify.opaque_index: %d, "
543 "l2_classify.hash: 0x%llx",
544 o->l2_classify.table_index,
545 o->l2_classify.opaque_index, o->l2_classify.hash);
546 vec_add1 (s, '\n');
547
548 s = format (s, "policer.index: %d", o->policer.index);
549 vec_add1 (s, '\n');
550
Dave Barachd7b30662019-10-24 18:10:10 -0400551 s = format (s, "ipsec.sad_index: %d, ipsec.protect_index",
552 o->ipsec.sad_index, o->ipsec.protect_index);
Dave Barach7fff3d22018-11-27 16:52:59 -0500553 vec_add1 (s, '\n');
554
555 s = format (s, "map.mtu: %d", (u32) (o->map.mtu));
556 vec_add1 (s, '\n');
557
558 s = format (s,
Dave Barachd7b30662019-10-24 18:10:10 -0400559 "map_t.map_domain_index: %d, map_t.v6.saddr: 0x%x, "
560 "map_t.v6.daddr: 0x%x, map_t.v6.frag_offset: %d, "
561 "map_t.v6.l4_offset: %d, map_t.v6.l4_protocol: %d, "
562 "map.t.checksum_offset: %d",
563 o->map_t.map_domain_index,
Dave Barach7fff3d22018-11-27 16:52:59 -0500564 o->map_t.v6.saddr,
565 o->map_t.v6.daddr,
Dave Barachd7b30662019-10-24 18:10:10 -0400566 (u32) (o->map_t.v6.frag_offset), (u32) (o->map_t.v6.l4_offset),
567 (u32) (o->map_t.v6.l4_protocol),
568 (u32) (o->map_t.checksum_offset));
Dave Barach7fff3d22018-11-27 16:52:59 -0500569 vec_add1 (s, '\n');
570
571 s = format (s,
572 "map_t.v6.l4_protocol: %d, map_t.checksum_offset: %d, "
573 "map_t.mtu: %d",
574 (u32) (o->map_t.v6.l4_protocol),
575 (u32) (o->map_t.checksum_offset), (u32) (o->map_t.mtu));
576 vec_add1 (s, '\n');
577
578 s = format (s,
579 "ip_frag.mtu: %d, ip_frag.next_index: %d, ip_frag.flags: 0x%x",
580 (u32) (o->ip_frag.mtu),
581 (u32) (o->ip_frag.next_index), (u32) (o->ip_frag.flags));
582 vec_add1 (s, '\n');
583
584 s = format (s, "cop.current_config_index: %d", o->cop.current_config_index);
585 vec_add1 (s, '\n');
586
587 s = format (s, "lisp.overlay_afi: %d", (u32) (o->lisp.overlay_afi));
588 vec_add1 (s, '\n');
589
590 s = format
Dave Barachd7b30662019-10-24 18:10:10 -0400591 (s,
592 "tcp.connection_index: %d, tcp.seq_number: %d, tcp.next_node_opaque: %d "
593 "tcp.seq_end: %d, tcp.ack_number: %d, tcp.hdr_offset: %d, "
594 "tcp.data_offset: %d", o->tcp.connection_index, o->tcp.next_node_opaque,
595 o->tcp.seq_number, o->tcp.seq_end, o->tcp.ack_number,
Dave Barach7fff3d22018-11-27 16:52:59 -0500596 (u32) (o->tcp.hdr_offset), (u32) (o->tcp.data_offset));
597 vec_add1 (s, '\n');
598
599 s = format (s,
600 "tcp.data_len: %d, tcp.flags: 0x%x",
601 (u32) (o->tcp.data_len), (u32) (o->tcp.flags));
602 vec_add1 (s, '\n');
603
Dave Barach7fff3d22018-11-27 16:52:59 -0500604 s = format (s, "snat.flags: 0x%x", o->snat.flags);
605 vec_add1 (s, '\n');
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700606
607 for (i = 0; i < vec_len (im->buffer_opaque_format_helpers); i++)
608 {
609 helper_fp = im->buffer_opaque_format_helpers[i];
610 s = (*helper_fp) (b, s);
611 }
612
Dave Barach7fff3d22018-11-27 16:52:59 -0500613 return s;
614}
615
616u8 *
617format_vnet_buffer_opaque2 (u8 * s, va_list * args)
618{
619 vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *);
620 vnet_buffer_opaque2_t *o = (vnet_buffer_opaque2_t *) b->opaque2;
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700621 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
622 vnet_buffer_opquae_formatter_t helper_fp;
Dave Barach7fff3d22018-11-27 16:52:59 -0500623
624 int i;
625
626 s = format (s, "raw: ");
627
628 for (i = 0; i < ARRAY_LEN (b->opaque2); i++)
629 s = format (s, "%08x ", b->opaque2[i]);
630 vec_add1 (s, '\n');
631
632 s = format (s, "qos.bits: %x, qos.source: %x",
633 (u32) (o->qos.bits), (u32) (o->qos.source));
634 vec_add1 (s, '\n');
635 s = format (s, "loop_counter: %d", o->loop_counter);
636 vec_add1 (s, '\n');
637
Neale Ranns4ba67722019-02-28 11:11:39 +0000638 s = format (s, "gbp.flags: %x, gbp.sclass: %d",
639 (u32) (o->gbp.flags), (u32) (o->gbp.sclass));
Dave Barach7fff3d22018-11-27 16:52:59 -0500640 vec_add1 (s, '\n');
641
Dave Barachd7b30662019-10-24 18:10:10 -0400642 s = format (s, "gso_size: %d, gso_l4_hdr_sz: %d",
643 (u32) (o->gso_size), (u32) (o->gso_l4_hdr_sz));
644 vec_add1 (s, '\n');
645
Dave Barach7fff3d22018-11-27 16:52:59 -0500646 s = format (s, "pg_replay_timestamp: %llu", (u32) (o->pg_replay_timestamp));
647 vec_add1 (s, '\n');
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700648
649 for (i = 0; i < vec_len (im->buffer_opaque2_format_helpers); i++)
650 {
651 helper_fp = im->buffer_opaque2_format_helpers[i];
652 s = (*helper_fp) (b, s);
653 }
654
Dave Barach7fff3d22018-11-27 16:52:59 -0500655 return s;
656}
657
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700658void
659vnet_register_format_buffer_opaque_helper (vnet_buffer_opquae_formatter_t fp)
660{
661 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
662 vec_add1 (im->buffer_opaque_format_helpers, fp);
663}
664
665void
666vnet_register_format_buffer_opaque2_helper (vnet_buffer_opquae_formatter_t fp)
667{
668 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
669 vec_add1 (im->buffer_opaque2_format_helpers, fp);
670}
671
672
Dave Barachba868bb2016-08-08 09:51:21 -0400673uword
674unformat_vnet_hw_interface (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700675{
Dave Barachba868bb2016-08-08 09:51:21 -0400676 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
677 u32 *hw_if_index = va_arg (*args, u32 *);
678 vnet_interface_main_t *im = &vnm->interface_main;
679 vnet_device_class_t *c;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700680
681 /* Try per device class functions first. */
682 vec_foreach (c, im->device_classes)
Dave Barachba868bb2016-08-08 09:51:21 -0400683 {
684 if (c->unformat_device_name
685 && unformat_user (input, c->unformat_device_name, hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700686 return 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400687 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700688
689 return unformat_user (input, unformat_hash_vec_string,
690 im->hw_interface_by_name, hw_if_index);
691}
692
Dave Barachba868bb2016-08-08 09:51:21 -0400693uword
694unformat_vnet_sw_interface (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700695{
Dave Barachba868bb2016-08-08 09:51:21 -0400696 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
697 u32 *result = va_arg (*args, u32 *);
698 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700699 u32 hw_if_index, id, id_specified;
Eyal Bari3212c572017-03-06 11:47:50 +0200700 u32 sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400701 u8 *if_name = 0;
702 uword *p, error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700703
704 id = ~0;
705 if (unformat (input, "%_%v.%d%_", &if_name, &id)
706 && ((p = hash_get (vnm->interface_main.hw_interface_by_name, if_name))))
707 {
708 hw_if_index = p[0];
709 id_specified = 1;
710 }
Dave Barachba868bb2016-08-08 09:51:21 -0400711 else
712 if (unformat (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700713 id_specified = 0;
714 else
715 goto done;
716
717 hi = vnet_get_hw_interface (vnm, hw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400718 if (!id_specified)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700719 {
Eyal Bari3212c572017-03-06 11:47:50 +0200720 sw_if_index = hi->sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700721 }
722 else
723 {
Dave Barachba868bb2016-08-08 09:51:21 -0400724 if (!(p = hash_get (hi->sub_interface_sw_if_index_by_id, id)))
Eyal Bari3212c572017-03-06 11:47:50 +0200725 goto done;
726 sw_if_index = p[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700727 }
Eyal Bari3212c572017-03-06 11:47:50 +0200728 if (!vnet_sw_interface_is_api_visible (vnm, sw_if_index))
729 goto done;
730 *result = sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700731 error = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400732done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700733 vec_free (if_name);
734 return error;
735}
736
Dave Barachba868bb2016-08-08 09:51:21 -0400737uword
738unformat_vnet_sw_interface_flags (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700739{
Dave Barachba868bb2016-08-08 09:51:21 -0400740 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700741 u32 flags = 0;
742
743 if (unformat (input, "up"))
744 flags |= VNET_SW_INTERFACE_FLAG_ADMIN_UP;
745 else if (unformat (input, "down"))
746 flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP;
747 else if (unformat (input, "punt"))
748 flags |= VNET_SW_INTERFACE_FLAG_PUNT;
749 else if (unformat (input, "enable"))
750 flags &= ~VNET_SW_INTERFACE_FLAG_PUNT;
751 else
752 return 0;
753
754 *result = flags;
755 return 1;
756}
757
Dave Barachba868bb2016-08-08 09:51:21 -0400758uword
759unformat_vnet_hw_interface_flags (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700760{
Dave Barachba868bb2016-08-08 09:51:21 -0400761 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700762 u32 flags = 0;
763
764 if (unformat (input, "up"))
765 flags |= VNET_HW_INTERFACE_FLAG_LINK_UP;
766 else if (unformat (input, "down"))
767 flags &= ~VNET_HW_INTERFACE_FLAG_LINK_UP;
768 else
769 return 0;
770
771 *result = flags;
772 return 1;
773}
774
Dave Barachba868bb2016-08-08 09:51:21 -0400775/*
776 * fd.io coding-style-patch-verification: ON
777 *
778 * Local Variables:
779 * eval: (c-set-style "gnu")
780 * End:
781 */