1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
3 * Copyright(c) 2018 Mellanox Technology
10 #include <rte_ether.h>
11 #include <rte_ethdev.h>
17 print_ether_addr(const char *what, struct rte_ether_addr *eth_addr)
19 char buf[ETHER_ADDR_FMT_SIZE];
20 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
21 printf("%s%s", what, buf);
25 dump_pkt_burst(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
26 uint16_t nb_pkts, int is_rx)
29 struct rte_ether_hdr *eth_hdr;
32 uint16_t i, packet_type;
33 uint16_t is_encapsulation;
35 struct rte_net_hdr_lens hdr_lens;
36 uint32_t sw_packet_type;
42 printf("port %u/queue %u: %s %u packets\n",
44 is_rx ? "received" : "sent",
45 (unsigned int) nb_pkts);
46 for (i = 0; i < nb_pkts; i++) {
48 eth_hdr = rte_pktmbuf_mtod(mb, struct rte_ether_hdr *);
49 eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
50 ol_flags = mb->ol_flags;
51 packet_type = mb->packet_type;
52 is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
54 print_ether_addr(" src=", ð_hdr->s_addr);
55 print_ether_addr(" - dst=", ð_hdr->d_addr);
56 printf(" - type=0x%04x - length=%u - nb_segs=%d",
57 eth_type, (unsigned int) mb->pkt_len,
59 if (ol_flags & PKT_RX_RSS_HASH) {
60 printf(" - RSS hash=0x%x", (unsigned int) mb->hash.rss);
61 printf(" - RSS queue=0x%x", (unsigned int) queue);
63 if (ol_flags & PKT_RX_FDIR) {
64 printf(" - FDIR matched ");
65 if (ol_flags & PKT_RX_FDIR_ID)
68 else if (ol_flags & PKT_RX_FDIR_FLX)
69 printf("flex bytes=0x%08x %08x",
70 mb->hash.fdir.hi, mb->hash.fdir.lo);
72 printf("hash=0x%x ID=0x%x ",
73 mb->hash.fdir.hash, mb->hash.fdir.id);
75 if (ol_flags & PKT_RX_TIMESTAMP)
76 printf(" - timestamp %"PRIu64" ", mb->timestamp);
77 if (ol_flags & PKT_RX_QINQ)
78 printf(" - QinQ VLAN tci=0x%x, VLAN tci outer=0x%x",
79 mb->vlan_tci, mb->vlan_tci_outer);
80 else if (ol_flags & PKT_RX_VLAN)
81 printf(" - VLAN tci=0x%x", mb->vlan_tci);
82 if (mb->packet_type) {
83 rte_get_ptype_name(mb->packet_type, buf, sizeof(buf));
84 printf(" - hw ptype: %s", buf);
86 sw_packet_type = rte_net_get_ptype(mb, &hdr_lens,
88 rte_get_ptype_name(sw_packet_type, buf, sizeof(buf));
89 printf(" - sw ptype: %s", buf);
90 if (sw_packet_type & RTE_PTYPE_L2_MASK)
91 printf(" - l2_len=%d", hdr_lens.l2_len);
92 if (sw_packet_type & RTE_PTYPE_L3_MASK)
93 printf(" - l3_len=%d", hdr_lens.l3_len);
94 if (sw_packet_type & RTE_PTYPE_L4_MASK)
95 printf(" - l4_len=%d", hdr_lens.l4_len);
96 if (sw_packet_type & RTE_PTYPE_TUNNEL_MASK)
97 printf(" - tunnel_len=%d", hdr_lens.tunnel_len);
98 if (sw_packet_type & RTE_PTYPE_INNER_L2_MASK)
99 printf(" - inner_l2_len=%d", hdr_lens.inner_l2_len);
100 if (sw_packet_type & RTE_PTYPE_INNER_L3_MASK)
101 printf(" - inner_l3_len=%d", hdr_lens.inner_l3_len);
102 if (sw_packet_type & RTE_PTYPE_INNER_L4_MASK)
103 printf(" - inner_l4_len=%d", hdr_lens.inner_l4_len);
104 if (is_encapsulation) {
105 struct ipv4_hdr *ipv4_hdr;
106 struct ipv6_hdr *ipv6_hdr;
107 struct udp_hdr *udp_hdr;
112 struct rte_vxlan_hdr *vxlan_hdr;
114 l2_len = sizeof(struct rte_ether_hdr);
116 /* Do not support ipv4 option field */
117 if (RTE_ETH_IS_IPV4_HDR(packet_type)) {
118 l3_len = sizeof(struct ipv4_hdr);
119 ipv4_hdr = rte_pktmbuf_mtod_offset(mb,
122 l4_proto = ipv4_hdr->next_proto_id;
124 l3_len = sizeof(struct ipv6_hdr);
125 ipv6_hdr = rte_pktmbuf_mtod_offset(mb,
128 l4_proto = ipv6_hdr->proto;
130 if (l4_proto == IPPROTO_UDP) {
131 udp_hdr = rte_pktmbuf_mtod_offset(mb,
134 l4_len = sizeof(struct udp_hdr);
135 vxlan_hdr = rte_pktmbuf_mtod_offset(mb,
136 struct rte_vxlan_hdr *,
137 l2_len + l3_len + l4_len);
138 udp_port = RTE_BE_TO_CPU_16(udp_hdr->dst_port);
139 vx_vni = rte_be_to_cpu_32(vxlan_hdr->vx_vni);
140 printf(" - VXLAN packet: packet type =%d, "
141 "Destination UDP port =%d, VNI = %d",
142 packet_type, udp_port, vx_vni >> 8);
145 printf(" - %s queue=0x%x", is_rx ? "Receive" : "Send",
146 (unsigned int) queue);
148 rte_get_rx_ol_flag_list(mb->ol_flags, buf, sizeof(buf));
149 printf(" ol_flags: %s\n", buf);
154 dump_rx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
155 uint16_t nb_pkts, __rte_unused uint16_t max_pkts,
156 __rte_unused void *user_param)
158 dump_pkt_burst(port_id, queue, pkts, nb_pkts, 1);
163 dump_tx_pkts(uint16_t port_id, uint16_t queue, struct rte_mbuf *pkts[],
164 uint16_t nb_pkts, __rte_unused void *user_param)
166 dump_pkt_burst(port_id, queue, pkts, nb_pkts, 0);