1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
13 #include <sys/queue.h>
16 #include <rte_common.h>
17 #include <rte_byteorder.h>
19 #include <rte_debug.h>
20 #include <rte_cycles.h>
21 #include <rte_memory.h>
22 #include <rte_memcpy.h>
23 #include <rte_launch.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_atomic.h>
28 #include <rte_branch_prediction.h>
29 #include <rte_mempool.h>
31 #include <rte_interrupts.h>
33 #include <rte_ether.h>
34 #include <rte_ethdev.h>
35 #include <rte_string_fns.h>
44 print_ether_addr(const char *what, struct ether_addr *eth_addr)
46 char buf[ETHER_ADDR_FMT_SIZE];
47 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
48 printf("%s%s", what, buf);
52 * Received a burst of packets.
55 pkt_burst_receive(struct fwd_stream *fs)
57 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
59 struct ether_hdr *eth_hdr;
63 uint16_t i, packet_type;
64 uint16_t is_encapsulation;
66 struct rte_net_hdr_lens hdr_lens;
67 uint32_t sw_packet_type;
69 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
74 start_tsc = rte_rdtsc();
78 * Receive a burst of packets.
80 nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
82 if (unlikely(nb_rx == 0))
85 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
86 fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
88 fs->rx_packets += nb_rx;
91 * Dump each received packet if verbose_level > 0.
93 if (verbose_level > 0)
94 printf("port %u/queue %u: received %u packets\n",
96 (unsigned) fs->rx_queue,
98 for (i = 0; i < nb_rx; i++) {
100 if (verbose_level == 0) {
101 rte_pktmbuf_free(mb);
104 eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
105 eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
106 ol_flags = mb->ol_flags;
107 packet_type = mb->packet_type;
108 is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
110 print_ether_addr(" src=", ð_hdr->s_addr);
111 print_ether_addr(" - dst=", ð_hdr->d_addr);
112 printf(" - type=0x%04x - length=%u - nb_segs=%d",
113 eth_type, (unsigned) mb->pkt_len,
115 if (ol_flags & PKT_RX_RSS_HASH) {
116 printf(" - RSS hash=0x%x", (unsigned) mb->hash.rss);
117 printf(" - RSS queue=0x%x",(unsigned) fs->rx_queue);
119 if (ol_flags & PKT_RX_FDIR) {
120 printf(" - FDIR matched ");
121 if (ol_flags & PKT_RX_FDIR_ID)
124 else if (ol_flags & PKT_RX_FDIR_FLX)
125 printf("flex bytes=0x%08x %08x",
126 mb->hash.fdir.hi, mb->hash.fdir.lo);
128 printf("hash=0x%x ID=0x%x ",
129 mb->hash.fdir.hash, mb->hash.fdir.id);
131 if (ol_flags & PKT_RX_TIMESTAMP)
132 printf(" - timestamp %"PRIu64" ", mb->timestamp);
133 if (ol_flags & PKT_RX_VLAN_STRIPPED)
134 printf(" - VLAN tci=0x%x", mb->vlan_tci);
135 if (ol_flags & PKT_RX_QINQ_STRIPPED)
136 printf(" - QinQ VLAN tci=0x%x, VLAN tci outer=0x%x",
137 mb->vlan_tci, mb->vlan_tci_outer);
138 if (mb->packet_type) {
139 rte_get_ptype_name(mb->packet_type, buf, sizeof(buf));
140 printf(" - hw ptype: %s", buf);
142 sw_packet_type = rte_net_get_ptype(mb, &hdr_lens,
144 rte_get_ptype_name(sw_packet_type, buf, sizeof(buf));
145 printf(" - sw ptype: %s", buf);
146 if (sw_packet_type & RTE_PTYPE_L2_MASK)
147 printf(" - l2_len=%d", hdr_lens.l2_len);
148 if (sw_packet_type & RTE_PTYPE_L3_MASK)
149 printf(" - l3_len=%d", hdr_lens.l3_len);
150 if (sw_packet_type & RTE_PTYPE_L4_MASK)
151 printf(" - l4_len=%d", hdr_lens.l4_len);
152 if (sw_packet_type & RTE_PTYPE_TUNNEL_MASK)
153 printf(" - tunnel_len=%d", hdr_lens.tunnel_len);
154 if (sw_packet_type & RTE_PTYPE_INNER_L2_MASK)
155 printf(" - inner_l2_len=%d", hdr_lens.inner_l2_len);
156 if (sw_packet_type & RTE_PTYPE_INNER_L3_MASK)
157 printf(" - inner_l3_len=%d", hdr_lens.inner_l3_len);
158 if (sw_packet_type & RTE_PTYPE_INNER_L4_MASK)
159 printf(" - inner_l4_len=%d", hdr_lens.inner_l4_len);
160 if (is_encapsulation) {
161 struct ipv4_hdr *ipv4_hdr;
162 struct ipv6_hdr *ipv6_hdr;
163 struct udp_hdr *udp_hdr;
168 struct vxlan_hdr *vxlan_hdr;
170 l2_len = sizeof(struct ether_hdr);
172 /* Do not support ipv4 option field */
173 if (RTE_ETH_IS_IPV4_HDR(packet_type)) {
174 l3_len = sizeof(struct ipv4_hdr);
175 ipv4_hdr = rte_pktmbuf_mtod_offset(mb,
178 l4_proto = ipv4_hdr->next_proto_id;
180 l3_len = sizeof(struct ipv6_hdr);
181 ipv6_hdr = rte_pktmbuf_mtod_offset(mb,
184 l4_proto = ipv6_hdr->proto;
186 if (l4_proto == IPPROTO_UDP) {
187 udp_hdr = rte_pktmbuf_mtod_offset(mb,
190 l4_len = sizeof(struct udp_hdr);
191 vxlan_hdr = rte_pktmbuf_mtod_offset(mb,
193 l2_len + l3_len + l4_len);
195 printf(" - VXLAN packet: packet type =%d, "
196 "Destination UDP port =%d, VNI = %d",
197 packet_type, RTE_BE_TO_CPU_16(udp_hdr->dst_port),
198 rte_be_to_cpu_32(vxlan_hdr->vx_vni) >> 8);
201 printf(" - Receive queue=0x%x", (unsigned) fs->rx_queue);
203 rte_get_rx_ol_flag_list(mb->ol_flags, buf, sizeof(buf));
204 printf(" ol_flags: %s\n", buf);
205 rte_pktmbuf_free(mb);
208 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
209 end_tsc = rte_rdtsc();
210 core_cycles = (end_tsc - start_tsc);
211 fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
215 struct fwd_engine rx_only_engine = {
216 .fwd_mode_name = "rxonly",
217 .port_fwd_begin = NULL,
218 .port_fwd_end = NULL,
219 .packet_fwd = pkt_burst_receive,