blob: f66797c946374d88f934c7c93b7b4c16b97411ca [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>
Damjan Marion94100532020-11-06 23:25:57 +010045#include <vnet/interface/rx_queue_funcs.h>
Damjan Marion1bd6cbb2021-04-15 13:12:51 +020046#include <vnet/interface/tx_queue_funcs.h>
Jon Loeliger9485d992019-11-08 15:05:23 -060047
48u8 *
49format_vtr (u8 * s, va_list * args)
50{
51 u32 vtr_op = va_arg (*args, u32);
52 u32 dot1q = va_arg (*args, u32);
53 u32 tag1 = va_arg (*args, u32);
54 u32 tag2 = va_arg (*args, u32);
55 switch (vtr_op)
56 {
57 case L2_VTR_DISABLED:
58 return format (s, "none");
59 case L2_VTR_PUSH_1:
60 return format (s, "push-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
61 case L2_VTR_PUSH_2:
62 return format (s, "push-2 %s %d %d", dot1q ? "dot1q" : "dot1ad", tag1,
63 tag2);
64 case L2_VTR_POP_1:
65 return format (s, "pop-1");
66 case L2_VTR_POP_2:
67 return format (s, "pop-2");
68 case L2_VTR_TRANSLATE_1_1:
69 return format (s, "trans-1-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
70 case L2_VTR_TRANSLATE_1_2:
71 return format (s, "trans-1-2 %s %d %d", dot1q ? "dot1q" : "dot1ad",
72 tag1, tag2);
73 case L2_VTR_TRANSLATE_2_1:
74 return format (s, "trans-2-1 %s %d", dot1q ? "dot1q" : "dot1ad", tag1);
75 case L2_VTR_TRANSLATE_2_2:
76 return format (s, "trans-2-2 %s %d %d", dot1q ? "dot1q" : "dot1ad",
77 tag1, tag2);
78 default:
79 return format (s, "none");
80 }
81}
Ed Warnickecb9cada2015-12-08 15:45:58 -070082
Dave Barachba868bb2016-08-08 09:51:21 -040083u8 *
84format_vnet_sw_interface_flags (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -070085{
86 u32 flags = va_arg (*args, u32);
87
Damjan Marionabce5092017-05-10 20:09:31 +020088 if (flags & VNET_SW_INTERFACE_FLAG_ERROR)
89 s = format (s, "error");
Dave Barachba868bb2016-08-08 09:51:21 -040090 else
John Lobcebbb92016-04-05 15:47:43 -040091 {
Dave Barachba868bb2016-08-08 09:51:21 -040092 s = format (s, "%s",
John Lobcebbb92016-04-05 15:47:43 -040093 (flags & VNET_SW_INTERFACE_FLAG_ADMIN_UP) ? "up" : "down");
Dave Barachba868bb2016-08-08 09:51:21 -040094 if (flags & VNET_SW_INTERFACE_FLAG_PUNT)
John Lobcebbb92016-04-05 15:47:43 -040095 s = format (s, "/punt");
96 }
Ed Warnickecb9cada2015-12-08 15:45:58 -070097
98 return s;
99}
100
Dave Barachba868bb2016-08-08 09:51:21 -0400101u8 *
Damjan Marioneabd4242020-10-07 20:59:07 +0200102format_vnet_hw_if_rx_mode (u8 * s, va_list * args)
Damjan Marion44036902017-04-28 12:29:15 +0200103{
Damjan Marioneabd4242020-10-07 20:59:07 +0200104 vnet_hw_if_rx_mode mode = va_arg (*args, vnet_hw_if_rx_mode);
Damjan Marion44036902017-04-28 12:29:15 +0200105
Damjan Marioneabd4242020-10-07 20:59:07 +0200106 if (mode == VNET_HW_IF_RX_MODE_POLLING)
Damjan Marion44036902017-04-28 12:29:15 +0200107 return format (s, "polling");
108
Damjan Marioneabd4242020-10-07 20:59:07 +0200109 if (mode == VNET_HW_IF_RX_MODE_INTERRUPT)
Damjan Marion44036902017-04-28 12:29:15 +0200110 return format (s, "interrupt");
111
Damjan Marioneabd4242020-10-07 20:59:07 +0200112 if (mode == VNET_HW_IF_RX_MODE_ADAPTIVE)
Damjan Marion44036902017-04-28 12:29:15 +0200113 return format (s, "adaptive");
114
115 return format (s, "unknown");
116}
117
118u8 *
Damjan Marion5100aa92018-11-08 15:30:16 +0100119format_vnet_hw_interface_link_speed (u8 * s, va_list * args)
120{
121 u32 link_speed = va_arg (*args, u32);
122
123 if (link_speed == 0)
124 return format (s, "unknown");
125
126 if (link_speed >= 1000000)
127 return format (s, "%f Gbps", (f64) link_speed / 1000000);
128
129 if (link_speed >= 1000)
130 return format (s, "%f Mbps", (f64) link_speed / 1000);
131
132 return format (s, "%u Kbps", link_speed);
133}
134
Chenmin Sunc4665092020-07-06 08:20:39 +0800135u8 *
136format_vnet_hw_interface_rss_queues (u8 * s, va_list * args)
137{
138 clib_bitmap_t *bitmap = va_arg (*args, clib_bitmap_t *);
139 int i;
140
141 if (bitmap == NULL)
142 return s;
143
144 if (bitmap)
145 {
146 /* *INDENT-OFF* */
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100147 clib_bitmap_foreach (i, bitmap) {
Chenmin Sunc4665092020-07-06 08:20:39 +0800148 s = format (s, "%u ", i);
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100149 }
Chenmin Sunc4665092020-07-06 08:20:39 +0800150 /* *INDENT-ON* */
151 }
152
153 return s;
154}
Damjan Marion5100aa92018-11-08 15:30:16 +0100155
156u8 *
Dave Barachba868bb2016-08-08 09:51:21 -0400157format_vnet_hw_interface (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700158{
Dave Barachba868bb2016-08-08 09:51:21 -0400159 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
160 vnet_hw_interface_t *hi = va_arg (*args, vnet_hw_interface_t *);
161 vnet_hw_interface_class_t *hw_class;
162 vnet_device_class_t *dev_class;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700163 int verbose = va_arg (*args, int);
Christophe Fontained3c008d2017-10-02 18:10:54 +0200164 u32 indent;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700165
Dave Barachba868bb2016-08-08 09:51:21 -0400166 if (!hi)
167 return format (s, "%=32s%=6s%=8s%s", "Name", "Idx", "Link", "Hardware");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700168
169 indent = format_get_indent (s);
170
John Lobcebbb92016-04-05 15:47:43 -0400171 s = format (s, "%-32v%=6d", hi->name, hi->hw_if_index);
172
173 if (hi->bond_info == VNET_HW_INTERFACE_BOND_INFO_SLAVE)
174 s = format (s, "%=8s", "slave");
175 else
Dave Barachba868bb2016-08-08 09:51:21 -0400176 s = format (s, "%=8s",
John Lobcebbb92016-04-05 15:47:43 -0400177 hi->flags & VNET_HW_INTERFACE_FLAG_LINK_UP ? "up" : "down");
Ed Warnickecb9cada2015-12-08 15:45:58 -0700178
179 hw_class = vnet_get_hw_interface_class (vnm, hi->hw_class_index);
180 dev_class = vnet_get_device_class (vnm, hi->dev_class_index);
181
Dave Barachba868bb2016-08-08 09:51:21 -0400182 if (hi->bond_info && (hi->bond_info != VNET_HW_INTERFACE_BOND_INFO_SLAVE))
John Lobcebbb92016-04-05 15:47:43 -0400183 {
184 int hw_idx;
185 s = format (s, "Slave-Idx:");
Damjan Marionf0ca1e82020-12-13 23:26:56 +0100186 clib_bitmap_foreach (hw_idx, hi->bond_info)
187 s = format (s, " %d", hw_idx);
John Lobcebbb92016-04-05 15:47:43 -0400188 }
Dave Barachba868bb2016-08-08 09:51:21 -0400189 else if (dev_class->format_device_name)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700190 s = format (s, "%U", dev_class->format_device_name, hi->dev_instance);
191 else
192 s = format (s, "%s%d", dev_class->name, hi->dev_instance);
193
Damjan Marion5100aa92018-11-08 15:30:16 +0100194 s = format (s, "\n%ULink speed: %U", format_white_space, indent + 2,
195 format_vnet_hw_interface_link_speed, hi->link_speed);
196
Damjan Marion94100532020-11-06 23:25:57 +0100197 if (vec_len (hi->rx_queue_indices))
198 {
199 s = format (s, "\n%URX Queues:", format_white_space, indent + 2);
200 s = format (s, "\n%U%-6s%-15s%-10s", format_white_space, indent + 4,
201 "queue", "thread", "mode");
202 for (int i = 0; i < vec_len (hi->rx_queue_indices); i++)
203 {
204 vnet_hw_if_rx_queue_t *rxq;
205 rxq = vnet_hw_if_get_rx_queue (vnm, hi->rx_queue_indices[i]);
206 s = format (s, "\n%U%-6u%-15U%-10U", format_white_space, indent + 4,
207 rxq->queue_id, format_vlib_thread_name_and_index,
208 rxq->thread_index, format_vnet_hw_if_rx_mode, rxq->mode);
209 }
210 }
211
Damjan Marion1bd6cbb2021-04-15 13:12:51 +0200212 if (vec_len (hi->tx_queue_indices))
213 {
214 s = format (s, "\n%UTX Queues:", format_white_space, indent + 2);
215 s = format (s, "\n%U%-6s%-15s", format_white_space, indent + 4, "queue",
216 "thread(s)");
217 for (int i = 0; i < vec_len (hi->tx_queue_indices); i++)
218 {
219 vnet_hw_if_tx_queue_t *txq;
220 txq = vnet_hw_if_get_tx_queue (vnm, hi->tx_queue_indices[i]);
221 s = format (s, "\n%U%-6u%U", format_white_space, indent + 4,
222 txq->queue_id, format_bitmap_list, txq->threads);
223 }
224 }
225
Chenmin Sunc4665092020-07-06 08:20:39 +0800226 if (hi->rss_queues)
227 {
228 s = format (s, "\n%URSS queues: %U", format_white_space, indent + 2,
229 format_vnet_hw_interface_rss_queues, hi->rss_queues);
230 }
231
Ed Warnickecb9cada2015-12-08 15:45:58 -0700232 if (verbose)
233 {
234 if (hw_class->format_device)
235 s = format (s, "\n%U%U",
236 format_white_space, indent + 2,
237 hw_class->format_device, hi->hw_if_index, verbose);
238 else
239 {
240 s = format (s, "\n%U%s",
Dave Barachba868bb2016-08-08 09:51:21 -0400241 format_white_space, indent + 2, hw_class->name);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700242 if (hw_class->format_address && vec_len (hi->hw_address) > 0)
Dave Barachba868bb2016-08-08 09:51:21 -0400243 s =
244 format (s, " address %U", hw_class->format_address,
245 hi->hw_address);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700246 }
247
248 if (dev_class->format_device)
249 s = format (s, "\n%U%U",
250 format_white_space, indent + 2,
251 dev_class->format_device, hi->dev_instance, verbose);
252 }
253
254 return s;
255}
256
Dave Barachba868bb2016-08-08 09:51:21 -0400257u8 *
258format_vnet_sw_interface_name (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700259{
Dave Barachba868bb2016-08-08 09:51:21 -0400260 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
261 vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
262 vnet_sw_interface_t *si_sup =
263 vnet_get_sup_sw_interface (vnm, si->sw_if_index);
264 vnet_hw_interface_t *hi_sup;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700265
266 ASSERT (si_sup->type == VNET_SW_INTERFACE_TYPE_HARDWARE);
267 hi_sup = vnet_get_hw_interface (vnm, si_sup->hw_if_index);
268
269 s = format (s, "%v", hi_sup->name);
270
271 if (si->type != VNET_SW_INTERFACE_TYPE_HARDWARE)
272 s = format (s, ".%d", si->sub.id);
273
274 return s;
275}
276
Dave Barachba868bb2016-08-08 09:51:21 -0400277u8 *
278format_vnet_sw_if_index_name (u8 * s, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700279{
Dave Barachba868bb2016-08-08 09:51:21 -0400280 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700281 u32 sw_if_index = va_arg (*args, u32);
Neale Rannsda78f952017-05-24 09:15:43 -0700282 vnet_sw_interface_t *si;
283
Dave Barach3940de32019-07-23 16:28:36 -0400284 si = vnet_get_sw_interface_or_null (vnm, sw_if_index);
Neale Rannsda78f952017-05-24 09:15:43 -0700285
286 if (NULL == si)
287 {
288 return format (s, "DELETED");
289 }
290 return format (s, "%U", format_vnet_sw_interface_name, vnm, si);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700291}
292
Dave Barachba868bb2016-08-08 09:51:21 -0400293u8 *
Damjan Mariona35cc142018-03-16 01:25:27 +0100294format_vnet_hw_if_index_name (u8 * s, va_list * args)
295{
296 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
297 u32 hw_if_index = va_arg (*args, u32);
298 vnet_hw_interface_t *hi;
299
300 hi = vnet_get_hw_interface (vnm, hw_if_index);
301
302 if (hi == 0)
303 return format (s, "DELETED");
304
305 return format (s, "%v", hi->name);
306}
307
308u8 *
Dave Barachba868bb2016-08-08 09:51:21 -0400309format_vnet_sw_interface_cntrs (u8 * s, vnet_interface_main_t * im,
Dave Barach5554c562019-09-11 21:35:48 -0400310 vnet_sw_interface_t * si, int json)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700311{
Christophe Fontained3c008d2017-10-02 18:10:54 +0200312 u32 indent, n_printed;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400313 int j, n_counters;
Dave Barach5554c562019-09-11 21:35:48 -0400314 char *x = "";
315 int json_need_comma_nl = 0;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400316 u8 *n = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700317
Dave Barach5554c562019-09-11 21:35:48 -0400318 /*
319 * to output a json snippet, stick quotes in lots of places
320 * definitely deserves a one-character variable name.
321 */
322 if (json)
323 x = "\"";
324
Ed Warnickecb9cada2015-12-08 15:45:58 -0700325 indent = format_get_indent (s);
326 n_printed = 0;
327
Dave Barach8fdde3c2019-05-17 10:46:40 -0400328 n_counters = vec_len (im->combined_sw_if_counters);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700329
Dave Barach8fdde3c2019-05-17 10:46:40 -0400330 /* rx, tx counters... */
331 for (j = 0; j < n_counters; j++)
332 {
333 vlib_combined_counter_main_t *cm;
334 vlib_counter_t v, vtotal;
335 vtotal.packets = 0;
336 vtotal.bytes = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700337
Dave Barach8fdde3c2019-05-17 10:46:40 -0400338 cm = im->combined_sw_if_counters + j;
339 vlib_get_combined_counter (cm, si->sw_if_index, &v);
340 vtotal.packets += v.packets;
341 vtotal.bytes += v.bytes;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700342
Dave Barach8fdde3c2019-05-17 10:46:40 -0400343 /* Only display non-zero counters. */
344 if (vtotal.packets == 0)
345 continue;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700346
Dave Barach5554c562019-09-11 21:35:48 -0400347 if (json)
348 {
349 if (json_need_comma_nl)
350 {
351 vec_add1 (s, ',');
352 vec_add1 (s, '\n');
353 }
354 s = format (s, "%s%s_packets%s: %s%Ld%s,\n", x, cm->name, x, x,
355 vtotal.packets, x);
356 s = format (s, "%s%s_bytes%s: %s%Ld%s", x, cm->name, x, x,
357 vtotal.bytes, x);
358 json_need_comma_nl = 1;
359 continue;
360 }
361
Dave Barach8fdde3c2019-05-17 10:46:40 -0400362 if (n_printed > 0)
363 s = format (s, "\n%U", format_white_space, indent);
364 n_printed += 2;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700365
Dave Barach8fdde3c2019-05-17 10:46:40 -0400366 if (n)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700367 _vec_len (n) = 0;
Dave Barach8fdde3c2019-05-17 10:46:40 -0400368 n = format (n, "%s packets", cm->name);
369 s = format (s, "%-16v%16Ld", n, vtotal.packets);
370
371 _vec_len (n) = 0;
372 n = format (n, "%s bytes", cm->name);
373 s = format (s, "\n%U%-16v%16Ld",
374 format_white_space, indent, n, vtotal.bytes);
375 }
376 vec_free (n);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700377
378 {
Dave Barachba868bb2016-08-08 09:51:21 -0400379 vlib_simple_counter_main_t *cm;
380 u64 v, vtotal;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700381
382 n_counters = vec_len (im->sw_if_counters);
383
384 for (j = 0; j < n_counters; j++)
385 {
Dave Barachba868bb2016-08-08 09:51:21 -0400386 vtotal = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700387
Dave Barach8fdde3c2019-05-17 10:46:40 -0400388 cm = im->sw_if_counters + j;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700389
Dave Barach8fdde3c2019-05-17 10:46:40 -0400390 v = vlib_get_simple_counter (cm, si->sw_if_index);
391 vtotal += v;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700392
393 /* Only display non-zero counters. */
394 if (vtotal == 0)
395 continue;
396
Dave Barach5554c562019-09-11 21:35:48 -0400397 if (json)
398 {
399 if (json_need_comma_nl)
400 {
401 vec_add1 (s, ',');
402 vec_add1 (s, '\n');
403 }
404 s = format (s, "%s%s%s: %s%Ld%s", x, cm->name, x, x, vtotal, x);
405 json_need_comma_nl = 1;
406 continue;
407 }
408
409
Ed Warnickecb9cada2015-12-08 15:45:58 -0700410 if (n_printed > 0)
411 s = format (s, "\n%U", format_white_space, indent);
412 n_printed += 1;
413
414 s = format (s, "%-16s%16Ld", cm->name, vtotal);
415 }
416 }
417
418 return s;
419}
420
Ole Troand7231612018-06-07 10:17:57 +0200421static u8 *
422format_vnet_sw_interface_mtu (u8 * s, va_list * args)
423{
424 vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
425
426 return format (s, "%d/%d/%d/%d", si->mtu[VNET_MTU_L3],
427 si->mtu[VNET_MTU_IP4],
428 si->mtu[VNET_MTU_IP6], si->mtu[VNET_MTU_MPLS]);
429}
430
Dave Barachba868bb2016-08-08 09:51:21 -0400431u8 *
432format_vnet_sw_interface (u8 * s, va_list * args)
Sean Hope679ea792016-02-22 15:12:01 -0500433{
Dave Barachba868bb2016-08-08 09:51:21 -0400434 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
435 vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
436 vnet_interface_main_t *im = &vnm->interface_main;
Sean Hope679ea792016-02-22 15:12:01 -0500437
Dave Barachba868bb2016-08-08 09:51:21 -0400438 if (!si)
Ole Troand7231612018-06-07 10:17:57 +0200439 return format (s, "%=32s%=5s%=10s%=21s%=16s%=16s",
440 "Name", "Idx", "State", "MTU (L3/IP4/IP6/MPLS)", "Counter",
441 "Count");
Sean Hope679ea792016-02-22 15:12:01 -0500442
Ole Troand7231612018-06-07 10:17:57 +0200443 s = format (s, "%-32U%=5d%=10U%=21U",
Sean Hope679ea792016-02-22 15:12:01 -0500444 format_vnet_sw_interface_name, vnm, si, si->sw_if_index,
Ole Troand7231612018-06-07 10:17:57 +0200445 format_vnet_sw_interface_flags, si->flags,
446 format_vnet_sw_interface_mtu, si);
Sean Hope679ea792016-02-22 15:12:01 -0500447
Dave Barach5554c562019-09-11 21:35:48 -0400448 s = format_vnet_sw_interface_cntrs (s, im, si, 0 /* want json */ );
Sean Hope679ea792016-02-22 15:12:01 -0500449
450 return s;
451}
452
Dave Barachba868bb2016-08-08 09:51:21 -0400453u8 *
454format_vnet_sw_interface_name_override (u8 * s, va_list * args)
Sean Hope679ea792016-02-22 15:12:01 -0500455{
Dave Barachba868bb2016-08-08 09:51:21 -0400456 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
457 vnet_sw_interface_t *si = va_arg (*args, vnet_sw_interface_t *);
Sean Hope679ea792016-02-22 15:12:01 -0500458 /* caller supplied display name for this interface */
Dave Barachba868bb2016-08-08 09:51:21 -0400459 u8 *name = va_arg (*args, u8 *);
460 vnet_interface_main_t *im = &vnm->interface_main;
Sean Hope679ea792016-02-22 15:12:01 -0500461
462
Dave Barachba868bb2016-08-08 09:51:21 -0400463 if (!si)
Sean Hope679ea792016-02-22 15:12:01 -0500464 return format (s, "%=32s%=5s%=16s%=16s%=16s",
465 "Name", "Idx", "State", "Counter", "Count");
466
467 s = format (s, "%-32v%=5d%=16U",
468 name, si->sw_if_index,
469 format_vnet_sw_interface_flags, si->flags);
470
Dave Barach5554c562019-09-11 21:35:48 -0400471 s = format_vnet_sw_interface_cntrs (s, im, si, 0 /* want json */ );
Sean Hope679ea792016-02-22 15:12:01 -0500472
473 return s;
474}
475
Dave Barach7fff3d22018-11-27 16:52:59 -0500476u8 *
477format_vnet_buffer_flags (u8 * s, va_list * args)
478{
479 vlib_buffer_t *buf = va_arg (*args, vlib_buffer_t *);
480
481#define _(a,b,c,v) if (buf->flags & VNET_BUFFER_F_##b) s = format (s, "%s ", c);
482 foreach_vnet_buffer_flag;
483#undef _
484 return s;
485}
486
487u8 *
488format_vnet_buffer_opaque (u8 * s, va_list * args)
489{
490 vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *);
491 vnet_buffer_opaque_t *o = (vnet_buffer_opaque_t *) b->opaque;
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700492 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
493 vnet_buffer_opquae_formatter_t helper_fp;
Dave Barach7fff3d22018-11-27 16:52:59 -0500494 int i;
495
496 s = format (s, "raw: ");
497
498 for (i = 0; i < ARRAY_LEN (b->opaque); i++)
499 s = format (s, "%08x ", b->opaque[i]);
500
501 vec_add1 (s, '\n');
502
503 s = format (s,
504 "sw_if_index[VLIB_RX]: %d, sw_if_index[VLIB_TX]: %d",
505 o->sw_if_index[0], o->sw_if_index[1]);
506 vec_add1 (s, '\n');
507
508 s = format (s,
509 "L2 offset %d, L3 offset %d, L4 offset %d, feature arc index %d",
510 (u32) (o->l2_hdr_offset),
511 (u32) (o->l3_hdr_offset),
512 (u32) (o->l4_hdr_offset), (u32) (o->feature_arc_index));
513 vec_add1 (s, '\n');
514
515 s = format (s,
516 "ip.adj_index[VLIB_RX]: %d, ip.adj_index[VLIB_TX]: %d",
517 (u32) (o->ip.adj_index[0]), (u32) (o->ip.adj_index[1]));
518 vec_add1 (s, '\n');
519
520 s = format (s,
521 "ip.flow_hash: 0x%x, ip.save_protocol: 0x%x, ip.fib_index: %d",
522 o->ip.flow_hash, o->ip.save_protocol, o->ip.fib_index);
523 vec_add1 (s, '\n');
524
525 s = format (s,
526 "ip.save_rewrite_length: %d, ip.rpf_id: %d",
527 o->ip.save_rewrite_length, o->ip.rpf_id);
528 vec_add1 (s, '\n');
529
530 s = format (s,
531 "ip.icmp.type: %d ip.icmp.code: %d, ip.icmp.data: 0x%x",
532 (u32) (o->ip.icmp.type),
533 (u32) (o->ip.icmp.code), o->ip.icmp.data);
534 vec_add1 (s, '\n');
535
536 s = format (s,
537 "ip.reass.next_index: %d, ip.reass.estimated_mtu: %d",
538 o->ip.reass.next_index, (u32) (o->ip.reass.estimated_mtu));
539 vec_add1 (s, '\n');
Dave Barachd7b30662019-10-24 18:10:10 -0400540 s = format (s,
541 "ip.reass.error_next_index: %d, ip.reass.owner_thread_index: %d",
542 o->ip.reass.error_next_index,
543 (u32) (o->ip.reass.owner_thread_index));
544 vec_add1 (s, '\n');
545 s = format (s,
546 "ip.reass.ip_proto: %d, ip.reass.l4_src_port: %d",
547 o->ip.reass.ip_proto, (u32) (o->ip.reass.l4_src_port));
548 vec_add1 (s, '\n');
549 s = format (s, "ip.reass.l4_dst_port: %d", o->ip.reass.l4_dst_port);
550 vec_add1 (s, '\n');
Dave Barach7fff3d22018-11-27 16:52:59 -0500551
552 s = format (s,
553 "ip.reass.fragment_first: %d ip.reass.fragment_last: %d",
554 (u32) (o->ip.reass.fragment_first),
555 (u32) (o->ip.reass.fragment_last));
556 vec_add1 (s, '\n');
557
558 s = format (s,
559 "ip.reass.range_first: %d ip.reass.range_last: %d",
560 (u32) (o->ip.reass.range_first),
561 (u32) (o->ip.reass.range_last));
562 vec_add1 (s, '\n');
563
564 s = format (s,
565 "ip.reass.next_range_bi: 0x%x, ip.reass.ip6_frag_hdr_offset: %d",
566 o->ip.reass.next_range_bi,
567 (u32) (o->ip.reass.ip6_frag_hdr_offset));
568 vec_add1 (s, '\n');
569
570 s = format (s,
571 "mpls.ttl: %d, mpls.exp: %d, mpls.first: %d, "
572 "mpls.save_rewrite_length: %d, mpls.bier.n_bytes: %d",
573 (u32) (o->mpls.ttl), (u32) (o->mpls.exp), (u32) (o->mpls.first),
574 o->mpls.save_rewrite_length, (u32) (o->mpls.bier.n_bytes));
575 vec_add1 (s, '\n');
Dave Barachd7b30662019-10-24 18:10:10 -0400576 s = format (s, "mpls.mpls_hdr_length: %d", (u32) (o->mpls.mpls_hdr_length));
577 vec_add1 (s, '\n');
Dave Barach7fff3d22018-11-27 16:52:59 -0500578
579 s = format (s,
Dave Barachd7b30662019-10-24 18:10:10 -0400580 "l2.feature_bitmap: %08x, l2.bd_index: %d, l2.l2fib_sn %d, "
581 "l2.l2_len: %d, l2.shg: %d, l2.bd_age: %d",
582 (u32) (o->l2.feature_bitmap), (u32) (o->l2.bd_index),
583 (u32) (o->l2.l2fib_sn),
584 (u32) (o->l2.l2_len), (u32) (o->l2.shg), (u32) (o->l2.bd_age));
Dave Barach7fff3d22018-11-27 16:52:59 -0500585 vec_add1 (s, '\n');
586
587 s = format (s,
Dave Barach7bdaa3f2018-12-03 11:33:09 -0500588 "l2.feature_bitmap_input: %U, L2.feature_bitmap_output: %U",
Neale Ranns47a3d992020-09-29 15:38:51 +0000589 format_l2_input_feature_bitmap, o->l2.feature_bitmap, 0,
Dave Barach7bdaa3f2018-12-03 11:33:09 -0500590 format_l2_output_features, o->l2.feature_bitmap, 0);
591 vec_add1 (s, '\n');
592
593 s = format (s,
Dave Barach7fff3d22018-11-27 16:52:59 -0500594 "l2t.next_index: %d, l2t.session_index: %d",
595 (u32) (o->l2t.next_index), o->l2t.session_index);
596 vec_add1 (s, '\n');
597
598 s = format (s,
599 "l2_classify.table_index: %d, l2_classify.opaque_index: %d, "
600 "l2_classify.hash: 0x%llx",
601 o->l2_classify.table_index,
602 o->l2_classify.opaque_index, o->l2_classify.hash);
603 vec_add1 (s, '\n');
604
605 s = format (s, "policer.index: %d", o->policer.index);
606 vec_add1 (s, '\n');
607
Dave Barachd7b30662019-10-24 18:10:10 -0400608 s = format (s, "ipsec.sad_index: %d, ipsec.protect_index",
609 o->ipsec.sad_index, o->ipsec.protect_index);
Dave Barach7fff3d22018-11-27 16:52:59 -0500610 vec_add1 (s, '\n');
611
612 s = format (s, "map.mtu: %d", (u32) (o->map.mtu));
613 vec_add1 (s, '\n');
614
615 s = format (s,
Dave Barachd7b30662019-10-24 18:10:10 -0400616 "map_t.map_domain_index: %d, map_t.v6.saddr: 0x%x, "
617 "map_t.v6.daddr: 0x%x, map_t.v6.frag_offset: %d, "
618 "map_t.v6.l4_offset: %d, map_t.v6.l4_protocol: %d, "
619 "map.t.checksum_offset: %d",
620 o->map_t.map_domain_index,
Dave Barach7fff3d22018-11-27 16:52:59 -0500621 o->map_t.v6.saddr,
622 o->map_t.v6.daddr,
Dave Barachd7b30662019-10-24 18:10:10 -0400623 (u32) (o->map_t.v6.frag_offset), (u32) (o->map_t.v6.l4_offset),
624 (u32) (o->map_t.v6.l4_protocol),
625 (u32) (o->map_t.checksum_offset));
Dave Barach7fff3d22018-11-27 16:52:59 -0500626 vec_add1 (s, '\n');
627
628 s = format (s,
629 "map_t.v6.l4_protocol: %d, map_t.checksum_offset: %d, "
630 "map_t.mtu: %d",
631 (u32) (o->map_t.v6.l4_protocol),
632 (u32) (o->map_t.checksum_offset), (u32) (o->map_t.mtu));
633 vec_add1 (s, '\n');
634
635 s = format (s,
636 "ip_frag.mtu: %d, ip_frag.next_index: %d, ip_frag.flags: 0x%x",
637 (u32) (o->ip_frag.mtu),
638 (u32) (o->ip_frag.next_index), (u32) (o->ip_frag.flags));
639 vec_add1 (s, '\n');
640
641 s = format (s, "cop.current_config_index: %d", o->cop.current_config_index);
642 vec_add1 (s, '\n');
643
644 s = format (s, "lisp.overlay_afi: %d", (u32) (o->lisp.overlay_afi));
645 vec_add1 (s, '\n');
646
647 s = format
Dave Barachd7b30662019-10-24 18:10:10 -0400648 (s,
649 "tcp.connection_index: %d, tcp.seq_number: %d, tcp.next_node_opaque: %d "
650 "tcp.seq_end: %d, tcp.ack_number: %d, tcp.hdr_offset: %d, "
651 "tcp.data_offset: %d", o->tcp.connection_index, o->tcp.next_node_opaque,
652 o->tcp.seq_number, o->tcp.seq_end, o->tcp.ack_number,
Dave Barach7fff3d22018-11-27 16:52:59 -0500653 (u32) (o->tcp.hdr_offset), (u32) (o->tcp.data_offset));
654 vec_add1 (s, '\n');
655
656 s = format (s,
657 "tcp.data_len: %d, tcp.flags: 0x%x",
658 (u32) (o->tcp.data_len), (u32) (o->tcp.flags));
659 vec_add1 (s, '\n');
660
Dave Barach7fff3d22018-11-27 16:52:59 -0500661 s = format (s, "snat.flags: 0x%x", o->snat.flags);
662 vec_add1 (s, '\n');
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700663
664 for (i = 0; i < vec_len (im->buffer_opaque_format_helpers); i++)
665 {
666 helper_fp = im->buffer_opaque_format_helpers[i];
667 s = (*helper_fp) (b, s);
668 }
669
Dave Barach7fff3d22018-11-27 16:52:59 -0500670 return s;
671}
672
673u8 *
674format_vnet_buffer_opaque2 (u8 * s, va_list * args)
675{
676 vlib_buffer_t *b = va_arg (*args, vlib_buffer_t *);
677 vnet_buffer_opaque2_t *o = (vnet_buffer_opaque2_t *) b->opaque2;
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700678 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
679 vnet_buffer_opquae_formatter_t helper_fp;
Dave Barach7fff3d22018-11-27 16:52:59 -0500680
681 int i;
682
683 s = format (s, "raw: ");
684
685 for (i = 0; i < ARRAY_LEN (b->opaque2); i++)
686 s = format (s, "%08x ", b->opaque2[i]);
687 vec_add1 (s, '\n');
688
689 s = format (s, "qos.bits: %x, qos.source: %x",
690 (u32) (o->qos.bits), (u32) (o->qos.source));
691 vec_add1 (s, '\n');
692 s = format (s, "loop_counter: %d", o->loop_counter);
693 vec_add1 (s, '\n');
694
Neale Ranns4ba67722019-02-28 11:11:39 +0000695 s = format (s, "gbp.flags: %x, gbp.sclass: %d",
696 (u32) (o->gbp.flags), (u32) (o->gbp.sclass));
Dave Barach7fff3d22018-11-27 16:52:59 -0500697 vec_add1 (s, '\n');
698
Dave Barachd7b30662019-10-24 18:10:10 -0400699 s = format (s, "gso_size: %d, gso_l4_hdr_sz: %d",
700 (u32) (o->gso_size), (u32) (o->gso_l4_hdr_sz));
701 vec_add1 (s, '\n');
702
Dave Barach7fff3d22018-11-27 16:52:59 -0500703 s = format (s, "pg_replay_timestamp: %llu", (u32) (o->pg_replay_timestamp));
704 vec_add1 (s, '\n');
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700705
706 for (i = 0; i < vec_len (im->buffer_opaque2_format_helpers); i++)
707 {
708 helper_fp = im->buffer_opaque2_format_helpers[i];
709 s = (*helper_fp) (b, s);
710 }
711
Dave Barach7fff3d22018-11-27 16:52:59 -0500712 return s;
713}
714
Florin Coras3ffe6ca2019-06-26 16:27:13 -0700715void
716vnet_register_format_buffer_opaque_helper (vnet_buffer_opquae_formatter_t fp)
717{
718 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
719 vec_add1 (im->buffer_opaque_format_helpers, fp);
720}
721
722void
723vnet_register_format_buffer_opaque2_helper (vnet_buffer_opquae_formatter_t fp)
724{
725 vnet_interface_main_t *im = &vnet_get_main ()->interface_main;
726 vec_add1 (im->buffer_opaque2_format_helpers, fp);
727}
728
729
Dave Barachba868bb2016-08-08 09:51:21 -0400730uword
Dave Barach08eb2bb2020-04-15 09:34:43 -0400731unformat_vnet_buffer_flags (unformat_input_t * input, va_list * args)
732{
733 u32 *flagp = va_arg (*args, u32 *);
734 int rv = 0;
735 u32 flags = 0;
736
737 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
738 {
739 /* Red herring, there is no such buffer flag */
Mohsin Kazmi68095382021-02-10 11:26:24 +0100740 if (unformat (input, "avail10"))
Dave Barach08eb2bb2020-04-15 09:34:43 -0400741 return 0;
742#define _(bit,enum,str,verbose) \
743 else if (unformat (input, str)) \
744 { \
745 flags |= (1 << LOG2_VLIB_BUFFER_FLAG_USER(bit)); \
746 rv = 1; \
747 }
748 foreach_vnet_buffer_flag
749#undef _
750 else
751 break;
752 }
753 if (rv)
754 *flagp = flags;
755 return rv;
756}
757
758uword
Mohsin Kazmi68095382021-02-10 11:26:24 +0100759unformat_vnet_buffer_offload_flags (unformat_input_t *input, va_list *args)
760{
761 u32 *flagp = va_arg (*args, u32 *);
762 int rv = 0;
Mohsin Kazmi36f7a6a2021-05-05 14:26:38 +0200763 vnet_buffer_oflags_t oflags = 0;
Mohsin Kazmi68095382021-02-10 11:26:24 +0100764
765 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
766 {
767 if (0)
768 ;
769#define _(bit, enum, str, verbose) \
770 else if (unformat (input, str)) \
771 { \
772 oflags |= (1 << bit); \
773 rv = 1; \
774 }
775 foreach_vnet_buffer_offload_flag
776#undef _
777 else break;
778 }
779 if (rv)
Mohsin Kazmi36f7a6a2021-05-05 14:26:38 +0200780 *flagp = (u32) oflags;
Mohsin Kazmi68095382021-02-10 11:26:24 +0100781 return rv;
782}
783
784uword
Dave Barachba868bb2016-08-08 09:51:21 -0400785unformat_vnet_hw_interface (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700786{
Dave Barachba868bb2016-08-08 09:51:21 -0400787 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
788 u32 *hw_if_index = va_arg (*args, u32 *);
789 vnet_interface_main_t *im = &vnm->interface_main;
790 vnet_device_class_t *c;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700791
792 /* Try per device class functions first. */
793 vec_foreach (c, im->device_classes)
Dave Barachba868bb2016-08-08 09:51:21 -0400794 {
795 if (c->unformat_device_name
796 && unformat_user (input, c->unformat_device_name, hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700797 return 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400798 }
Ed Warnickecb9cada2015-12-08 15:45:58 -0700799
800 return unformat_user (input, unformat_hash_vec_string,
801 im->hw_interface_by_name, hw_if_index);
802}
803
Dave Barachba868bb2016-08-08 09:51:21 -0400804uword
805unformat_vnet_sw_interface (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700806{
Dave Barachba868bb2016-08-08 09:51:21 -0400807 vnet_main_t *vnm = va_arg (*args, vnet_main_t *);
808 u32 *result = va_arg (*args, u32 *);
809 vnet_hw_interface_t *hi;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700810 u32 hw_if_index, id, id_specified;
Eyal Bari3212c572017-03-06 11:47:50 +0200811 u32 sw_if_index;
Dave Barachba868bb2016-08-08 09:51:21 -0400812 u8 *if_name = 0;
813 uword *p, error = 0;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700814
815 id = ~0;
816 if (unformat (input, "%_%v.%d%_", &if_name, &id)
817 && ((p = hash_get (vnm->interface_main.hw_interface_by_name, if_name))))
818 {
819 hw_if_index = p[0];
820 id_specified = 1;
821 }
Dave Barachba868bb2016-08-08 09:51:21 -0400822 else
823 if (unformat (input, "%U", unformat_vnet_hw_interface, vnm, &hw_if_index))
Ed Warnickecb9cada2015-12-08 15:45:58 -0700824 id_specified = 0;
825 else
826 goto done;
827
828 hi = vnet_get_hw_interface (vnm, hw_if_index);
Dave Barachba868bb2016-08-08 09:51:21 -0400829 if (!id_specified)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700830 {
Eyal Bari3212c572017-03-06 11:47:50 +0200831 sw_if_index = hi->sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700832 }
833 else
834 {
Dave Barachba868bb2016-08-08 09:51:21 -0400835 if (!(p = hash_get (hi->sub_interface_sw_if_index_by_id, id)))
Eyal Bari3212c572017-03-06 11:47:50 +0200836 goto done;
837 sw_if_index = p[0];
Ed Warnickecb9cada2015-12-08 15:45:58 -0700838 }
Eyal Bari3212c572017-03-06 11:47:50 +0200839 if (!vnet_sw_interface_is_api_visible (vnm, sw_if_index))
840 goto done;
841 *result = sw_if_index;
Ed Warnickecb9cada2015-12-08 15:45:58 -0700842 error = 1;
Dave Barachba868bb2016-08-08 09:51:21 -0400843done:
Ed Warnickecb9cada2015-12-08 15:45:58 -0700844 vec_free (if_name);
845 return error;
846}
847
Dave Barachba868bb2016-08-08 09:51:21 -0400848uword
849unformat_vnet_sw_interface_flags (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700850{
Dave Barachba868bb2016-08-08 09:51:21 -0400851 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700852 u32 flags = 0;
853
854 if (unformat (input, "up"))
855 flags |= VNET_SW_INTERFACE_FLAG_ADMIN_UP;
856 else if (unformat (input, "down"))
857 flags &= ~VNET_SW_INTERFACE_FLAG_ADMIN_UP;
858 else if (unformat (input, "punt"))
859 flags |= VNET_SW_INTERFACE_FLAG_PUNT;
860 else if (unformat (input, "enable"))
861 flags &= ~VNET_SW_INTERFACE_FLAG_PUNT;
862 else
863 return 0;
864
865 *result = flags;
866 return 1;
867}
868
Dave Barachba868bb2016-08-08 09:51:21 -0400869uword
870unformat_vnet_hw_interface_flags (unformat_input_t * input, va_list * args)
Ed Warnickecb9cada2015-12-08 15:45:58 -0700871{
Dave Barachba868bb2016-08-08 09:51:21 -0400872 u32 *result = va_arg (*args, u32 *);
Ed Warnickecb9cada2015-12-08 15:45:58 -0700873 u32 flags = 0;
874
875 if (unformat (input, "up"))
876 flags |= VNET_HW_INTERFACE_FLAG_LINK_UP;
877 else if (unformat (input, "down"))
878 flags &= ~VNET_HW_INTERFACE_FLAG_LINK_UP;
879 else
880 return 0;
881
882 *result = flags;
883 return 1;
884}
885
Dave Barachba868bb2016-08-08 09:51:21 -0400886/*
887 * fd.io coding-style-patch-verification: ON
888 *
889 * Local Variables:
890 * eval: (c-set-style "gnu")
891 * End:
892 */