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