FD.io VPP  v18.07.1-19-g511ce25
Vector Packet Processing
format.c
Go to the documentation of this file.
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 #include <vnet/vnet.h>
16 #include <vppinfra/vec.h>
17 #include <vppinfra/format.h>
18 #include <vlib/unix/cj.h>
19 #include <assert.h>
20 
21 #define __USE_GNU
22 #include <dlfcn.h>
23 
24 #include <vnet/ethernet/ethernet.h>
25 #include <dpdk/device/dpdk.h>
26 
27 #include <dpdk/device/dpdk_priv.h>
28 #include <vppinfra/error.h>
29 
30 #define foreach_dpdk_counter \
31  _ (tx_frames_ok, opackets) \
32  _ (tx_bytes_ok, obytes) \
33  _ (tx_errors, oerrors) \
34  _ (rx_frames_ok, ipackets) \
35  _ (rx_bytes_ok, ibytes) \
36  _ (rx_errors, ierrors) \
37  _ (rx_missed, imissed) \
38  _ (rx_no_bufs, rx_nombuf)
39 
40 #define foreach_dpdk_q_counter \
41  _ (rx_frames_ok, q_ipackets) \
42  _ (tx_frames_ok, q_opackets) \
43  _ (rx_bytes_ok, q_ibytes) \
44  _ (tx_bytes_ok, q_obytes) \
45  _ (rx_errors, q_errors)
46 
47 #define foreach_dpdk_rss_hf \
48  _(ETH_RSS_FRAG_IPV4, "ipv4-frag") \
49  _(ETH_RSS_NONFRAG_IPV4_TCP, "ipv4-tcp") \
50  _(ETH_RSS_NONFRAG_IPV4_UDP, "ipv4-udp") \
51  _(ETH_RSS_NONFRAG_IPV4_SCTP, "ipv4-sctp") \
52  _(ETH_RSS_NONFRAG_IPV4_OTHER, "ipv4-other") \
53  _(ETH_RSS_IPV4, "ipv4") \
54  _(ETH_RSS_IPV6_TCP_EX, "ipv6-tcp-ex") \
55  _(ETH_RSS_IPV6_UDP_EX, "ipv6-udp-ex") \
56  _(ETH_RSS_FRAG_IPV6, "ipv6-frag") \
57  _(ETH_RSS_NONFRAG_IPV6_TCP, "ipv6-tcp") \
58  _(ETH_RSS_NONFRAG_IPV6_UDP, "ipv6-udp") \
59  _(ETH_RSS_NONFRAG_IPV6_SCTP, "ipv6-sctp") \
60  _(ETH_RSS_NONFRAG_IPV6_OTHER, "ipv6-other") \
61  _(ETH_RSS_L2_PAYLOAD, "l2-payload") \
62  _(ETH_RSS_IPV6_EX, "ipv6-ex") \
63  _(ETH_RSS_IPV6, "ipv6")
64 
65 
66 #define foreach_dpdk_rx_offload_caps \
67  _(DEV_RX_OFFLOAD_VLAN_STRIP, "vlan-strip") \
68  _(DEV_RX_OFFLOAD_IPV4_CKSUM, "ipv4-cksum") \
69  _(DEV_RX_OFFLOAD_UDP_CKSUM , "udp-cksum") \
70  _(DEV_RX_OFFLOAD_TCP_CKSUM , "tcp-cksum") \
71  _(DEV_RX_OFFLOAD_TCP_LRO , "rcp-lro") \
72  _(DEV_RX_OFFLOAD_QINQ_STRIP, "qinq-strip")
73 
74 #define foreach_dpdk_tx_offload_caps \
75  _(DEV_TX_OFFLOAD_VLAN_INSERT, "vlan-insert") \
76  _(DEV_TX_OFFLOAD_IPV4_CKSUM, "ipv4-cksum") \
77  _(DEV_TX_OFFLOAD_UDP_CKSUM , "udp-cksum") \
78  _(DEV_TX_OFFLOAD_TCP_CKSUM , "tcp-cksum") \
79  _(DEV_TX_OFFLOAD_SCTP_CKSUM , "sctp-cksum") \
80  _(DEV_TX_OFFLOAD_TCP_TSO , "tcp-tso") \
81  _(DEV_TX_OFFLOAD_UDP_TSO , "udp-tso") \
82  _(DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM, "outer-ipv4-cksum") \
83  _(DEV_TX_OFFLOAD_QINQ_INSERT, "qinq-insert")
84 
85 #define foreach_dpdk_pkt_rx_offload_flag \
86  _ (PKT_RX_VLAN, "RX packet is a 802.1q VLAN packet") \
87  _ (PKT_RX_RSS_HASH, "RX packet with RSS hash result") \
88  _ (PKT_RX_FDIR, "RX packet with FDIR infos") \
89  _ (PKT_RX_L4_CKSUM_BAD, "L4 cksum of RX pkt. is not OK") \
90  _ (PKT_RX_IP_CKSUM_BAD, "IP cksum of RX pkt. is not OK") \
91  _ (PKT_RX_EIP_CKSUM_BAD, "External IP header checksum error") \
92  _ (PKT_RX_VLAN_STRIPPED, "RX packet VLAN tag stripped") \
93  _ (PKT_RX_IP_CKSUM_GOOD, "IP cksum of RX pkt. is valid") \
94  _ (PKT_RX_L4_CKSUM_GOOD, "L4 cksum of RX pkt. is valid") \
95  _ (PKT_RX_IEEE1588_PTP, "RX IEEE1588 L2 Ethernet PT Packet") \
96  _ (PKT_RX_IEEE1588_TMST, "RX IEEE1588 L2/L4 timestamped packet") \
97  _ (PKT_RX_QINQ_STRIPPED, "RX packet QinQ tags stripped") \
98  _ (PKT_RX_TIMESTAMP, "Timestamp field is valid")
99 
100 #define foreach_dpdk_pkt_type \
101  _ (L2, ETHER, "Ethernet packet") \
102  _ (L2, ETHER_TIMESYNC, "Ethernet packet for time sync") \
103  _ (L2, ETHER_ARP, "ARP packet") \
104  _ (L2, ETHER_LLDP, "LLDP (Link Layer Discovery Protocol) packet") \
105  _ (L2, ETHER_NSH, "NSH (Network Service Header) packet") \
106  _ (L2, ETHER_VLAN, "VLAN packet") \
107  _ (L2, ETHER_QINQ, "QinQ packet") \
108  _ (L3, IPV4, "IPv4 packet without extension headers") \
109  _ (L3, IPV4_EXT, "IPv4 packet with extension headers") \
110  _ (L3, IPV4_EXT_UNKNOWN, "IPv4 packet with or without extension headers") \
111  _ (L3, IPV6, "IPv6 packet without extension headers") \
112  _ (L3, IPV6_EXT, "IPv6 packet with extension headers") \
113  _ (L3, IPV6_EXT_UNKNOWN, "IPv6 packet with or without extension headers") \
114  _ (L4, TCP, "TCP packet") \
115  _ (L4, UDP, "UDP packet") \
116  _ (L4, FRAG, "Fragmented IP packet") \
117  _ (L4, SCTP, "SCTP (Stream Control Transmission Protocol) packet") \
118  _ (L4, ICMP, "ICMP packet") \
119  _ (L4, NONFRAG, "Non-fragmented IP packet") \
120  _ (TUNNEL, GRE, "GRE tunneling packet") \
121  _ (TUNNEL, VXLAN, "VXLAN tunneling packet") \
122  _ (TUNNEL, NVGRE, "NVGRE Tunneling packet") \
123  _ (TUNNEL, GENEVE, "GENEVE Tunneling packet") \
124  _ (TUNNEL, GRENAT, "Teredo, VXLAN or GRE Tunneling packet") \
125  _ (INNER_L2, ETHER, "Inner Ethernet packet") \
126  _ (INNER_L2, ETHER_VLAN, "Inner Ethernet packet with VLAN") \
127  _ (INNER_L3, IPV4, "Inner IPv4 packet without extension headers") \
128  _ (INNER_L3, IPV4_EXT, "Inner IPv4 packet with extension headers") \
129  _ (INNER_L3, IPV4_EXT_UNKNOWN, "Inner IPv4 packet with or without extension headers") \
130  _ (INNER_L3, IPV6, "Inner IPv6 packet without extension headers") \
131  _ (INNER_L3, IPV6_EXT, "Inner IPv6 packet with extension headers") \
132  _ (INNER_L3, IPV6_EXT_UNKNOWN, "Inner IPv6 packet with or without extension headers") \
133  _ (INNER_L4, TCP, "Inner TCP packet") \
134  _ (INNER_L4, UDP, "Inner UDP packet") \
135  _ (INNER_L4, FRAG, "Inner fagmented IP packet") \
136  _ (INNER_L4, SCTP, "Inner SCTP (Stream Control Transmission Protocol) packet") \
137  _ (INNER_L4, ICMP, "Inner ICMP packet") \
138  _ (INNER_L4, NONFRAG, "Inner non-fragmented IP packet")
139 
140 #define foreach_dpdk_pkt_tx_offload_flag \
141  _ (PKT_TX_VLAN_PKT, "TX packet is a 802.1q VLAN packet") \
142  _ (PKT_TX_IP_CKSUM, "IP cksum of TX pkt. computed by NIC") \
143  _ (PKT_TX_TCP_CKSUM, "TCP cksum of TX pkt. computed by NIC") \
144  _ (PKT_TX_SCTP_CKSUM, "SCTP cksum of TX pkt. computed by NIC") \
145  _ (PKT_TX_IEEE1588_TMST, "TX IEEE1588 packet to timestamp")
146 
147 #define foreach_dpdk_pkt_offload_flag \
148  foreach_dpdk_pkt_rx_offload_flag \
149  foreach_dpdk_pkt_tx_offload_flag
150 
151 #define foreach_dpdk_log_level \
152  _ (EMERG, "emergency") \
153  _ (ALERT, "alert") \
154  _ (CRIT, "critical") \
155  _ (ERR, "error") \
156  _ (WARNING, "warning") \
157  _ (NOTICE, "notice") \
158  _ (INFO, "info") \
159  _ (DEBUG, "debug")
160 
161 u8 *
162 format_dpdk_device_name (u8 * s, va_list * args)
163 {
164  dpdk_main_t *dm = &dpdk_main;
165  char *devname_format;
166  char *device_name;
167  u32 i = va_arg (*args, u32);
168  struct rte_eth_dev_info dev_info;
169  struct rte_pci_device *pci_dev;
170  u8 *ret;
171 
173  devname_format = "%s%d/%d/%d";
174  else
175  devname_format = "%s%x/%x/%x";
176 
177  switch (dm->devices[i].port_type)
178  {
180  device_name = "GigabitEthernet";
181  break;
182 
184  device_name = "Two_FiveGigabitEthernet";
185  break;
186 
188  device_name = "FiveGigabitEthernet";
189  break;
190 
192  device_name = "TenGigabitEthernet";
193  break;
194 
196  device_name = "TwentyGigabitEthernet";
197  break;
198 
200  device_name = "TwentyFiveGigabitEthernet";
201  break;
202 
204  device_name = "FortyGigabitEthernet";
205  break;
206 
208  device_name = "FiftyGigabitEthernet";
209  break;
210 
212  device_name = "FiftySixGigabitEthernet";
213  break;
214 
216  device_name = "HundredGigabitEthernet";
217  break;
218 
220  return format (s, "BondEthernet%d", dm->devices[i].bond_instance_num);
221 
223  device_name = "EthernetSwitch";
224  break;
225 
227  device_name = "VirtualFunctionEthernet";
228  break;
229 
231  rte_eth_dev_info_get (i, &dev_info);
232  return format (s, "af_packet%d", dm->devices[i].af_packet_instance_num);
233 
235  device_name = "VirtioUser";
236  break;
237 
239  device_name = "VhostEthernet";
240  break;
241 
243  device_name = "FailsafeEthernet";
244  break;
245 
246  default:
248  device_name = "UnknownEthernet";
249  break;
250  }
251 
252  rte_eth_dev_info_get (i, &dev_info);
253 #if RTE_VERSION < RTE_VERSION_NUM(18, 5, 0, 0)
254  pci_dev = dev_info.pci_dev;
255 #else
256  pci_dev = RTE_DEV_TO_PCI (dev_info.device);
257 #endif
258 
259  if (pci_dev && dm->devices[i].port_type != VNET_DPDK_PORT_TYPE_FAILSAFE)
260  ret = format (s, devname_format, device_name, pci_dev->addr.bus,
261  pci_dev->addr.devid, pci_dev->addr.function);
262  else
263  ret = format (s, "%s%d", device_name, dm->devices[i].port_id);
264 
265  if (dm->devices[i].interface_name_suffix)
266  return format (ret, "/%s", dm->devices[i].interface_name_suffix);
267  return ret;
268 }
269 
270 u8 *
271 format_dpdk_device_flags (u8 * s, va_list * args)
272 {
273  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
274  u8 *t = 0;
275 
276 #define _(a, b, c) if (xd->flags & (1 << a)) \
277 t = format (t, "%s%s", t ? " ":"", c);
279 #undef _
280  s = format (s, "%v", t);
281  vec_free (t);
282  return s;
283 }
284 
285 static u8 *
286 format_dpdk_device_type (u8 * s, va_list * args)
287 {
288  dpdk_main_t *dm = &dpdk_main;
289  char *dev_type;
290  u32 i = va_arg (*args, u32);
291 
292  switch (dm->devices[i].pmd)
293  {
294  case VNET_DPDK_PMD_E1000EM:
295  dev_type = "Intel 82540EM (e1000)";
296  break;
297 
298  case VNET_DPDK_PMD_IGB:
299  dev_type = "Intel e1000";
300  break;
301 
302  case VNET_DPDK_PMD_I40E:
303  dev_type = "Intel X710/XL710 Family";
304  break;
305 
306  case VNET_DPDK_PMD_I40EVF:
307  dev_type = "Intel X710/XL710 Family VF";
308  break;
309 
310  case VNET_DPDK_PMD_FM10K:
311  dev_type = "Intel FM10000 Family Ethernet Switch";
312  break;
313 
314  case VNET_DPDK_PMD_IGBVF:
315  dev_type = "Intel e1000 VF";
316  break;
317 
318  case VNET_DPDK_PMD_VIRTIO:
319  dev_type = "Red Hat Virtio";
320  break;
321 
322  case VNET_DPDK_PMD_IXGBEVF:
323  dev_type = "Intel 82599 VF";
324  break;
325 
326  case VNET_DPDK_PMD_IXGBE:
327  dev_type = "Intel 82599";
328  break;
329 
330  case VNET_DPDK_PMD_ENIC:
331  dev_type = "Cisco VIC";
332  break;
333 
334  case VNET_DPDK_PMD_CXGBE:
335  dev_type = "Chelsio T4/T5";
336  break;
337 
338  case VNET_DPDK_PMD_MLX4:
339  dev_type = "Mellanox ConnectX-3 Family";
340  break;
341 
342  case VNET_DPDK_PMD_MLX5:
343  dev_type = "Mellanox ConnectX-4 Family";
344  break;
345 
346  case VNET_DPDK_PMD_VMXNET3:
347  dev_type = "VMware VMXNET3";
348  break;
349 
350  case VNET_DPDK_PMD_AF_PACKET:
351  dev_type = "af_packet";
352  break;
353 
354  case VNET_DPDK_PMD_BOND:
355  dev_type = "Ethernet Bonding";
356  break;
357 
358  case VNET_DPDK_PMD_DPAA2:
359  dev_type = "NXP DPAA2 Mac";
360  break;
361 
362  case VNET_DPDK_PMD_VIRTIO_USER:
363  dev_type = "Virtio User";
364  break;
365 
366  case VNET_DPDK_PMD_THUNDERX:
367  dev_type = "Cavium ThunderX";
368  break;
369 
370  case VNET_DPDK_PMD_VHOST_ETHER:
371  dev_type = "VhostEthernet";
372  break;
373 
374  case VNET_DPDK_PMD_ENA:
375  dev_type = "AWS ENA VF";
376  break;
377 
378  case VNET_DPDK_PMD_FAILSAFE:
379  dev_type = "FailsafeEthernet";
380  break;
381 
382  case VNET_DPDK_PMD_LIOVF_ETHER:
383  dev_type = "Cavium Lio VF";
384  break;
385 
386  case VNET_DPDK_PMD_QEDE:
387  dev_type = "Cavium QLogic FastLinQ QL4xxxx";
388  break;
389 
390  default:
392  dev_type = "### UNKNOWN ###";
393  break;
394  }
395 
396  return format (s, dev_type);
397 }
398 
399 static u8 *
400 format_dpdk_link_status (u8 * s, va_list * args)
401 {
402  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
403  struct rte_eth_link *l = &xd->link;
404  vnet_main_t *vnm = vnet_get_main ();
406 
407  s = format (s, "%s ", l->link_status ? "up" : "down");
408  if (l->link_status)
409  {
410  u32 promisc = rte_eth_promiscuous_get (xd->port_id);
411 
412  s = format (s, "%s duplex ", (l->link_duplex == ETH_LINK_FULL_DUPLEX) ?
413  "full" : "half");
414  s = format (s, "speed %u mtu %d %s\n", l->link_speed,
415  hi->max_packet_bytes, promisc ? " promisc" : "");
416  }
417  else
418  s = format (s, "\n");
419 
420  return s;
421 }
422 
423 #define _line_len 72
424 #define _(v, str) \
425 if (bitmap & v) { \
426  if (format_get_indent (s) > next_split ) { \
427  next_split += _line_len; \
428  s = format(s,"\n%U", format_white_space, indent); \
429  } \
430  s = format(s, "%s ", str); \
431 }
432 
433 static u8 *
434 format_dpdk_rss_hf_name (u8 * s, va_list * args)
435 {
436  u64 bitmap = va_arg (*args, u64);
437  int next_split = _line_len;
438  u32 indent = format_get_indent (s);
439 
440  if (!bitmap)
441  return format (s, "none");
442 
443  foreach_dpdk_rss_hf return s;
444 }
445 
446 static u8 *
447 format_dpdk_rx_offload_caps (u8 * s, va_list * args)
448 {
449  u32 bitmap = va_arg (*args, u32);
450  int next_split = _line_len;
451  u32 indent = format_get_indent (s);
452 
453  if (!bitmap)
454  return format (s, "none");
455 
457 }
458 
459 static u8 *
460 format_dpdk_tx_offload_caps (u8 * s, va_list * args)
461 {
462  u32 bitmap = va_arg (*args, u32);
463  int next_split = _line_len;
464  u32 indent = format_get_indent (s);
465  if (!bitmap)
466  return format (s, "none");
467 
469 }
470 
471 #undef _line_len
472 #undef _
473 
474 u8 *
475 format_dpdk_device_errors (u8 * s, va_list * args)
476 {
477  dpdk_device_t *xd = va_arg (*args, dpdk_device_t *);
478  clib_error_t *e;
479  u32 indent = format_get_indent (s);
480 
481  vec_foreach (e, xd->errors)
482  {
483  s = format (s, "%U%v\n", format_white_space, indent, e->what);
484  }
485  return s;
486 }
487 
488 static const char *
489 ptr2sname (void *p)
490 {
491  Dl_info info = { 0 };
492 
493  if (dladdr (p, &info) == 0)
494  return 0;
495 
496  return info.dli_sname;
497 }
498 
499 u8 *
500 format_dpdk_device (u8 * s, va_list * args)
501 {
502  u32 dev_instance = va_arg (*args, u32);
503  int verbose = va_arg (*args, int);
504  dpdk_main_t *dm = &dpdk_main;
505  dpdk_device_t *xd = vec_elt_at_index (dm->devices, dev_instance);
506  u32 indent = format_get_indent (s);
507  f64 now = vlib_time_now (dm->vlib_main);
508  struct rte_eth_dev_info di;
509 
510  dpdk_update_counters (xd, now);
511  dpdk_update_link_state (xd, now);
512 
513  s = format (s, "%U\n%Ucarrier %U",
516  s = format (s, "%Uflags: %U\n",
518 
519  rte_eth_dev_info_get (xd->port_id, &di);
520 
521  if (verbose > 1 && xd->flags & DPDK_DEVICE_FLAG_PMD)
522  {
523  struct rte_pci_device *pci;
524  struct rte_eth_rss_conf rss_conf;
525  int vlan_off;
526  int retval;
527 
528  rss_conf.rss_key = 0;
529  retval = rte_eth_dev_rss_hash_conf_get (xd->port_id, &rss_conf);
530  if (retval < 0)
531  clib_warning ("rte_eth_dev_rss_hash_conf_get returned %d", retval);
532 #if RTE_VERSION < RTE_VERSION_NUM(18, 5, 0, 0)
533  pci = di.pci_dev;
534 #else
535  pci = RTE_DEV_TO_PCI (di.device);
536 #endif
537 
538  if (pci)
539  s =
540  format (s,
541  "%Upci id: device %04x:%04x subsystem %04x:%04x\n"
542  "%Upci address: %04x:%02x:%02x.%02x\n",
543  format_white_space, indent + 2, pci->id.vendor_id,
544  pci->id.device_id, pci->id.subsystem_vendor_id,
545  pci->id.subsystem_device_id, format_white_space, indent + 2,
546  pci->addr.domain, pci->addr.bus, pci->addr.devid,
547  pci->addr.function);
548  s =
549  format (s, "%Umax rx packet len: %d\n", format_white_space,
550  indent + 2, di.max_rx_pktlen);
551  s =
552  format (s, "%Umax num of queues: rx %d tx %d\n", format_white_space,
553  indent + 2, di.max_rx_queues, di.max_tx_queues);
554  s =
555  format (s, "%Upromiscuous: unicast %s all-multicast %s\n",
556  format_white_space, indent + 2,
557  rte_eth_promiscuous_get (xd->port_id) ?
558  "on" : "off",
559  rte_eth_allmulticast_get (xd->port_id) ? "on" : "off");
560  vlan_off = rte_eth_dev_get_vlan_offload (xd->port_id);
561  s = format (s, "%Uvlan offload: strip %s filter %s qinq %s\n",
562  format_white_space, indent + 2,
563  vlan_off & ETH_VLAN_STRIP_OFFLOAD ? "on" : "off",
564  vlan_off & ETH_VLAN_FILTER_OFFLOAD ? "on" : "off",
565  vlan_off & ETH_VLAN_EXTEND_OFFLOAD ? "on" : "off");
566  s = format (s, "%Urx offload caps: %U\n",
567  format_white_space, indent + 2,
568  format_dpdk_rx_offload_caps, di.rx_offload_capa);
569  s = format (s, "%Utx offload caps: %U\n",
570  format_white_space, indent + 2,
571  format_dpdk_tx_offload_caps, di.tx_offload_capa);
572  s = format (s, "%Urss active: %U\n"
573  "%Urss supported: %U\n",
574  format_white_space, indent + 2,
575  format_dpdk_rss_hf_name, rss_conf.rss_hf,
576  format_white_space, indent + 2,
577  format_dpdk_rss_hf_name, di.flow_type_rss_offloads);
578  s = format (s, "%Utx burst function: %s\n",
579  format_white_space, indent + 2,
580  ptr2sname (rte_eth_devices[xd->port_id].tx_pkt_burst));
581  s = format (s, "%Urx burst function: %s\n",
582  format_white_space, indent + 2,
583  ptr2sname (rte_eth_devices[xd->port_id].rx_pkt_burst));
584  }
585 
586  s = format (s, "%Urx queues %d, rx desc %d, tx queues %d, tx desc %d\n",
587  format_white_space, indent + 2,
588  xd->rx_q_used, xd->nb_rx_desc, xd->tx_q_used, xd->nb_tx_desc);
589 
590  if (xd->cpu_socket > -1)
591  s = format (s, "%Ucpu socket %d\n",
592  format_white_space, indent + 2, xd->cpu_socket);
593 
594  /* $$$ MIB counters */
595  {
596 #define _(N, V) \
597  if ((xd->stats.V - xd->last_cleared_stats.V) != 0) { \
598  s = format (s, "\n%U%-40U%16Ld", \
599  format_white_space, indent + 2, \
600  format_c_identifier, #N, \
601  xd->stats.V - xd->last_cleared_stats.V); \
602  } \
603 
605 #undef _
606  }
607 
608  u8 *xs = 0;
609  u32 i = 0;
610  struct rte_eth_xstat *xstat, *last_xstat;
611  struct rte_eth_xstat_name *xstat_names = 0;
612  int len = rte_eth_xstats_get_names (xd->port_id, NULL, 0);
613  vec_validate (xstat_names, len - 1);
614  rte_eth_xstats_get_names (xd->port_id, xstat_names, len);
615 
617 
618  /* *INDENT-OFF* */
619  vec_foreach_index(i, xd->xstats)
620  {
621  u64 delta = 0;
622  xstat = vec_elt_at_index(xd->xstats, i);
623  last_xstat = vec_elt_at_index(xd->last_cleared_xstats, i);
624 
625  delta = xstat->value - last_xstat->value;
626  if (verbose == 2 || (verbose && delta))
627  {
628  /* format_c_identifier doesn't like c strings inside vector */
629  u8 * name = format(0,"%s", xstat_names[i].name);
630  xs = format(xs, "\n%U%-38U%16Ld",
631  format_white_space, indent + 4,
632  format_c_identifier, name, delta);
633  vec_free(name);
634  }
635  }
636  /* *INDENT-ON* */
637 
638  vec_free (xstat_names);
639 
640  if (xs)
641  {
642  s = format (s, "\n%Uextended stats:%v",
643  format_white_space, indent + 2, xs);
644  vec_free (xs);
645  }
646 
647  if (vec_len (xd->errors))
648  {
649  s = format (s, "%UErrors:\n %U", format_white_space, indent,
651  }
652 
653  return s;
654 }
655 
656 u8 *
657 format_dpdk_tx_trace (u8 * s, va_list * va)
658 {
659  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
660  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
662  dpdk_tx_trace_t *t = va_arg (*va, dpdk_tx_trace_t *);
663  dpdk_main_t *dm = &dpdk_main;
665  u32 indent = format_get_indent (s);
667 
668  s = format (s, "%U tx queue %d",
670 
671  s = format (s, "\n%Ubuffer 0x%x: %U",
672  format_white_space, indent,
674 
675  s = format (s, "\n%U%U",
676  format_white_space, indent,
677  format_dpdk_rte_mbuf, &t->mb, &t->data);
678 
679  s = format (s, "\n%U%U", format_white_space, indent,
681  sizeof (t->buffer.pre_data));
682 
683  return s;
684 }
685 
686 u8 *
687 format_dpdk_rx_trace (u8 * s, va_list * va)
688 {
689  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*va, vlib_main_t *);
690  CLIB_UNUSED (vlib_node_t * node) = va_arg (*va, vlib_node_t *);
692  dpdk_rx_trace_t *t = va_arg (*va, dpdk_rx_trace_t *);
693  dpdk_main_t *dm = &dpdk_main;
696  u32 indent = format_get_indent (s);
698 
699  s = format (s, "%U rx queue %d",
701 
702  s = format (s, "\n%Ubuffer 0x%x: %U",
703  format_white_space, indent,
705 
706  s = format (s, "\n%U%U",
707  format_white_space, indent,
708  format_dpdk_rte_mbuf, &t->mb, &t->data);
709 
710  if (vm->trace_main.verbose)
711  {
712  s = format (s, "\n%UPacket Dump%s", format_white_space, indent + 2,
713  t->mb.data_len > sizeof (t->data) ? " (truncated)" : "");
714  s = format (s, "\n%U%U", format_white_space, indent + 4,
715  format_hexdump, &t->data,
716  t->mb.data_len >
717  sizeof (t->data) ? sizeof (t->data) : t->mb.data_len);
718  }
719  f = node->format_buffer;
720  if (!f)
721  f = format_hex_bytes;
722  s = format (s, "\n%U%U", format_white_space, indent,
723  f, t->buffer.pre_data, sizeof (t->buffer.pre_data));
724 
725  return s;
726 }
727 
728 
729 static inline u8 *
730 format_dpdk_pkt_types (u8 * s, va_list * va)
731 {
732  u32 *pkt_types = va_arg (*va, u32 *);
733  u32 indent __attribute__ ((unused)) = format_get_indent (s) + 2;
734 
735  if (!*pkt_types)
736  return s;
737 
738  s = format (s, "Packet Types");
739 
740 #define _(L, F, S) \
741  if ((*pkt_types & RTE_PTYPE_##L##_MASK) == RTE_PTYPE_##L##_##F) \
742  { \
743  s = format (s, "\n%U%s (0x%04x) %s", format_white_space, indent, \
744  "RTE_PTYPE_" #L "_" #F, RTE_PTYPE_##L##_##F, S); \
745  }
746 
748 #undef _
749  return s;
750 }
751 
752 static inline u8 *
754 {
755  u64 *ol_flags = va_arg (*va, u64 *);
756  u32 indent = format_get_indent (s) + 2;
757 
758  if (!*ol_flags)
759  return s;
760 
761  s = format (s, "Packet Offload Flags");
762 
763 #define _(F, S) \
764  if (*ol_flags & F) \
765  { \
766  s = format (s, "\n%U%s (0x%04x) %s", \
767  format_white_space, indent, #F, F, S); \
768  }
769 
771 #undef _
772  return s;
773 }
774 
775 u8 *
776 format_dpdk_rte_mbuf_vlan (u8 * s, va_list * va)
777 {
778  ethernet_vlan_header_tv_t *vlan_hdr =
779  va_arg (*va, ethernet_vlan_header_tv_t *);
780 
781  if (clib_net_to_host_u16 (vlan_hdr->type) == ETHERNET_TYPE_DOT1AD)
782  {
783  s = format (s, "%U 802.1q vlan ",
785  clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
786  vlan_hdr++;
787  }
788 
789  s = format (s, "%U",
791  clib_net_to_host_u16 (vlan_hdr->priority_cfi_and_id));
792 
793  return s;
794 }
795 
796 u8 *
797 format_dpdk_rte_mbuf (u8 * s, va_list * va)
798 {
799  struct rte_mbuf *mb = va_arg (*va, struct rte_mbuf *);
800  ethernet_header_t *eth_hdr = va_arg (*va, ethernet_header_t *);
801  u32 indent = format_get_indent (s) + 2;
802 
803  s = format (s, "PKT MBUF: port %d, nb_segs %d, pkt_len %d"
804  "\n%Ubuf_len %d, data_len %d, ol_flags 0x%lx, data_off %d, phys_addr 0x%x"
805  "\n%Upacket_type 0x%x l2_len %u l3_len %u outer_l2_len %u outer_l3_len %u"
806  "\n%Urss 0x%x fdir.hi 0x%x fdir.lo 0x%x",
807  mb->port, mb->nb_segs, mb->pkt_len,
808  format_white_space, indent,
809  mb->buf_len, mb->data_len, mb->ol_flags, mb->data_off,
810  mb->buf_physaddr, format_white_space, indent, mb->packet_type,
811  mb->l2_len, mb->l3_len, mb->outer_l2_len, mb->outer_l3_len,
812  format_white_space, indent, mb->hash.rss, mb->hash.fdir.hi,
813  mb->hash.fdir.lo);
814 
815  if (mb->ol_flags)
816  s = format (s, "\n%U%U", format_white_space, indent,
817  format_dpdk_pkt_offload_flags, &mb->ol_flags);
818 
819  if ((mb->ol_flags & PKT_RX_VLAN) &&
820  ((mb->ol_flags & (PKT_RX_VLAN_STRIPPED | PKT_RX_QINQ_STRIPPED)) == 0))
821  {
822  ethernet_vlan_header_tv_t *vlan_hdr =
823  ((ethernet_vlan_header_tv_t *) & (eth_hdr->type));
824  s = format (s, " %U", format_dpdk_rte_mbuf_vlan, vlan_hdr);
825  }
826 
827  if (mb->packet_type)
828  s = format (s, "\n%U%U", format_white_space, indent,
829  format_dpdk_pkt_types, &mb->packet_type);
830 
831  return s;
832 }
833 
834 clib_error_t *
836 {
838  {
839  if (0)
840  ;
841 #undef _
842 #define _(f, s) \
843  else if (unformat (input, s)) \
844  *rss_fn |= f;
845 
847 #undef _
848  else
849  {
850  return clib_error_return (0, "unknown input `%U'",
851  format_unformat_error, input);
852  }
853  }
854  return 0;
855 }
856 
857 uword
858 unformat_dpdk_log_level (unformat_input_t * input, va_list * args)
859 {
860  u32 *r = va_arg (*args, u32 *);
861 
862  if (0);
863 #define _(v,s) else if (unformat (input, s)) *r = RTE_LOG_##v;
865 #undef _
866  else
867  return 0;
868  return 1;
869 }
870 
871 clib_error_t *
873 {
874  clib_error_t *error = 0;
875 
877  {
878  if (unformat (input, "hqos-thread %u", &hqos->hqos_thread))
879  hqos->hqos_thread_valid = 1;
880  else
881  {
882  error = clib_error_return (0, "unknown input `%U'",
883  format_unformat_error, input);
884  break;
885  }
886  }
887 
888  return error;
889 }
890 
891 /*
892  * fd.io coding-style-patch-verification: ON
893  *
894  * Local Variables:
895  * eval: (c-set-style "gnu")
896  * End:
897  */
static u8 * format_dpdk_tx_offload_caps(u8 *s, va_list *args)
Definition: format.c:460
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
Definition: vec.h:437
u8 * format_dpdk_device(u8 *s, va_list *args)
Definition: format.c:500
vmrglw vmrglh hi
#define vec_foreach_index(var, v)
Iterate over vector indices.
u8 * format_dpdk_device_flags(u8 *s, va_list *args)
Definition: format.c:271
#define CLIB_UNUSED(x)
Definition: clib.h:79
u8 * format_dpdk_tx_trace(u8 *s, va_list *va)
Definition: format.c:657
u8 * format_dpdk_rte_mbuf_vlan(u8 *s, va_list *va)
Definition: format.c:776
u8 interface_name_format_decimal
Definition: dpdk.h:367
dpdk_main_t dpdk_main
Definition: init.c:42
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static u8 * format_dpdk_rss_hf_name(u8 *s, va_list *args)
Definition: format.c:434
unsigned long u64
Definition: types.h:89
u32 sw_if_index
Definition: dpdk.h:204
#define NULL
Definition: clib.h:55
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:228
clib_error_t * unformat_hqos(unformat_input_t *input, dpdk_device_config_hqos_t *hqos)
Definition: format.c:872
u16 flags
Definition: dpdk.h:212
static vnet_hw_interface_t * vnet_get_hw_interface(vnet_main_t *vnm, u32 hw_if_index)
clib_error_t * errors
Definition: dpdk.h:266
int i
static u8 * format_dpdk_pkt_offload_flags(u8 *s, va_list *va)
Definition: format.c:753
static u32 format_get_indent(u8 *s)
Definition: format.h:72
static vnet_sw_interface_t * vnet_get_sw_interface(vnet_main_t *vnm, u32 sw_if_index)
u8 * format_dpdk_rte_mbuf(u8 *s, va_list *va)
Definition: format.c:797
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
u8 *( format_function_t)(u8 *s, va_list *args)
Definition: format.h:48
u16 bond_instance_num
Definition: dpdk.h:245
struct rte_eth_xstat * last_cleared_xstats
Definition: dpdk.h:258
unsigned char u8
Definition: types.h:56
double f64
Definition: types.h:142
static u8 * format_dpdk_rx_offload_caps(u8 *s, va_list *args)
Definition: format.c:447
u8 * format_dpdk_device_name(u8 *s, va_list *args)
Definition: format.c:162
#define foreach_dpdk_rss_hf
Definition: format.c:47
dpdk_portid_t port_id
Definition: dpdk.h:201
uword unformat_dpdk_log_level(unformat_input_t *input, va_list *args)
Definition: format.c:858
u32 buffer_index
Definition: dpdk.h:456
u8 * format_white_space(u8 *s, va_list *va)
Definition: std-formats.c:113
#define foreach_dpdk_pkt_type
Definition: format.c:100
#define vec_elt_at_index(v, i)
Get vector value at index i checking that i is in bounds.
#define foreach_dpdk_rx_offload_caps
Definition: format.c:66
u8 * format_hex_bytes(u8 *s, va_list *va)
Definition: std-formats.c:84
#define clib_error_return(e, args...)
Definition: error.h:99
u16 rx_q_used
Definition: dpdk.h:224
u8 * format_ethernet_header_with_length(u8 *s, va_list *args)
Definition: format.c:91
u8 pre_data[VLIB_BUFFER_PRE_DATA_SIZE]
Space for inserting data before buffer start.
Definition: buffer.h:164
unsigned int u32
Definition: types.h:88
static u8 * format_dpdk_pkt_types(u8 *s, va_list *va)
Definition: format.c:730
u8 * format_c_identifier(u8 *s, va_list *va)
Definition: std-formats.c:258
format_function_t format_vnet_sw_interface_name
format_function_t format_vnet_buffer
Definition: buffer.h:413
u8 * format_dpdk_rx_trace(u8 *s, va_list *va)
Definition: format.c:687
struct _unformat_input_t unformat_input_t
#define foreach_dpdk_counter
Definition: format.c:30
u8 data[256]
Definition: dpdk.h:462
#define foreach_dpdk_log_level
Definition: format.c:151
dpdk_port_type_t port_type
Definition: dpdk.h:260
format_function_t * format_buffer
Definition: node.h:347
u16 tx_q_used
Definition: dpdk.h:223
u16 nb_rx_desc
Definition: dpdk.h:225
u32 hw_if_index
Definition: dpdk.h:203
u16 af_packet_instance_num
Definition: dpdk.h:244
#define UNFORMAT_END_OF_INPUT
Definition: format.h:144
dpdk_device_t * devices
Definition: dpdk.h:404
vlib_main_t * vm
Definition: buffer.c:294
static void dpdk_update_counters(dpdk_device_t *xd, f64 now)
Definition: dpdk_priv.h:87
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:339
#define clib_warning(format, args...)
Definition: error.h:59
dpdk_pmd_t pmd
Definition: dpdk.h:209
u8 * format_hexdump(u8 *s, va_list *va)
Definition: std-formats.c:281
struct rte_eth_xstat * xstats
Definition: dpdk.h:257
struct rte_mbuf mb
Definition: dpdk.h:459
u8 * interface_name_suffix
Definition: dpdk.h:217
static const char * ptr2sname(void *p)
Definition: format.c:489
u16 device_index
Definition: dpdk.h:468
#define ASSERT(truth)
u8 * format_dpdk_device_errors(u8 *s, va_list *args)
Definition: format.c:475
clib_error_t * unformat_rss_fn(unformat_input_t *input, uword *rss_fn)
Definition: format.c:835
#define foreach_dpdk_tx_offload_caps
Definition: format.c:74
vlib_buffer_t buffer
Definition: dpdk.h:471
vlib_trace_main_t trace_main
Definition: main.h:141
void dpdk_update_link_state(dpdk_device_t *xd, f64 now)
Definition: init.c:1421
struct rte_eth_link link
Definition: dpdk.h:251
u32 buffer_index
Definition: dpdk.h:467
vlib_buffer_t buffer
Definition: dpdk.h:461
u8 data[256]
Definition: dpdk.h:472
static u8 * format_dpdk_device_type(u8 *s, va_list *args)
Definition: format.c:286
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
u64 uword
Definition: types.h:112
u16 device_index
Definition: dpdk.h:457
#define foreach_dpdk_pkt_offload_flag
Definition: format.c:147
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
#define vec_foreach(var, vec)
Vector iterator.
i8 cpu_socket
Definition: dpdk.h:210
static u8 * format_dpdk_link_status(u8 *s, va_list *args)
Definition: format.c:400
struct rte_mbuf mb
Definition: dpdk.h:470
u8 queue_index
Definition: dpdk.h:458
u16 nb_tx_desc
Definition: dpdk.h:214
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
CLIB vectors are ubiquitous dynamically resized arrays with by user defined "headers".
u8 * format_ethernet_vlan_tci(u8 *s, va_list *va)
Definition: format.c:73
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:170
dpdk_config_main_t * conf
Definition: dpdk.h:440
u16 queue_index
Definition: dpdk.h:469
vlib_main_t * vlib_main
Definition: dpdk.h:438