4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/queue.h>
45 #include <rte_common.h>
46 #include <rte_byteorder.h>
48 #include <rte_debug.h>
49 #include <rte_cycles.h>
50 #include <rte_memory.h>
51 #include <rte_memcpy.h>
52 #include <rte_memzone.h>
53 #include <rte_launch.h>
55 #include <rte_per_lcore.h>
56 #include <rte_lcore.h>
57 #include <rte_atomic.h>
58 #include <rte_branch_prediction.h>
60 #include <rte_memory.h>
61 #include <rte_mempool.h>
63 #include <rte_interrupts.h>
65 #include <rte_ether.h>
66 #include <rte_ethdev.h>
67 #include <rte_string_fns.h>
74 print_ether_addr(const char *what, struct ether_addr *eth_addr)
76 char buf[ETHER_ADDR_FMT_SIZE];
77 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
78 printf("%s%s", what, buf);
82 * Received a burst of packets.
85 pkt_burst_receive(struct fwd_stream *fs)
87 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
89 struct ether_hdr *eth_hdr;
93 uint16_t i, packet_type;
95 uint16_t is_encapsulation;
97 uint64_t is_encapsulation;
100 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
103 uint64_t core_cycles;
106 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
107 start_tsc = rte_rdtsc();
111 * Receive a burst of packets.
113 nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
115 if (unlikely(nb_rx == 0))
118 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
119 fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
121 fs->rx_packets += nb_rx;
124 * Dump each received packet if verbose_level > 0.
126 if (verbose_level > 0)
127 printf("port %u/queue %u: received %u packets\n",
128 (unsigned) fs->rx_port,
129 (unsigned) fs->rx_queue,
131 for (i = 0; i < nb_rx; i++) {
133 if (verbose_level == 0) {
134 rte_pktmbuf_free(mb);
137 eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
138 eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
139 ol_flags = mb->ol_flags;
140 packet_type = mb->packet_type;
143 is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
145 is_encapsulation = ol_flags & (PKT_RX_TUNNEL_IPV4_HDR |
146 PKT_RX_TUNNEL_IPV6_HDR);
149 print_ether_addr(" src=", ð_hdr->s_addr);
150 print_ether_addr(" - dst=", ð_hdr->d_addr);
151 printf(" - type=0x%04x - length=%u - nb_segs=%d",
152 eth_type, (unsigned) mb->pkt_len,
154 if (ol_flags & PKT_RX_RSS_HASH) {
155 printf(" - RSS hash=0x%x", (unsigned) mb->hash.rss);
156 printf(" - RSS queue=0x%x",(unsigned) fs->rx_queue);
157 } else if (ol_flags & PKT_RX_FDIR) {
158 printf(" - FDIR matched ");
159 if (ol_flags & PKT_RX_FDIR_ID)
162 else if (ol_flags & PKT_RX_FDIR_FLX)
163 printf("flex bytes=0x%08x %08x",
164 mb->hash.fdir.hi, mb->hash.fdir.lo);
166 printf("hash=0x%x ID=0x%x ",
167 mb->hash.fdir.hash, mb->hash.fdir.id);
169 if (ol_flags & PKT_RX_VLAN_PKT)
170 printf(" - VLAN tci=0x%x", mb->vlan_tci);
171 if (ol_flags & PKT_RX_QINQ_PKT)
172 printf(" - QinQ VLAN tci=0x%x, VLAN tci outer=0x%x",
173 mb->vlan_tci, mb->vlan_tci_outer);
175 if (mb->packet_type) {
178 /* (outer) L2 packet type */
179 ptype = mb->packet_type & RTE_PTYPE_L2_MASK;
181 case RTE_PTYPE_L2_ETHER:
182 printf(" - (outer) L2 type: ETHER");
184 case RTE_PTYPE_L2_ETHER_TIMESYNC:
185 printf(" - (outer) L2 type: ETHER_Timesync");
187 case RTE_PTYPE_L2_ETHER_ARP:
188 printf(" - (outer) L2 type: ETHER_ARP");
190 case RTE_PTYPE_L2_ETHER_LLDP:
191 printf(" - (outer) L2 type: ETHER_LLDP");
194 printf(" - (outer) L2 type: Unknown");
198 /* (outer) L3 packet type */
199 ptype = mb->packet_type & RTE_PTYPE_L3_MASK;
201 case RTE_PTYPE_L3_IPV4:
202 printf(" - (outer) L3 type: IPV4");
204 case RTE_PTYPE_L3_IPV4_EXT:
205 printf(" - (outer) L3 type: IPV4_EXT");
207 case RTE_PTYPE_L3_IPV6:
208 printf(" - (outer) L3 type: IPV6");
210 case RTE_PTYPE_L3_IPV4_EXT_UNKNOWN:
211 printf(" - (outer) L3 type: IPV4_EXT_UNKNOWN");
213 case RTE_PTYPE_L3_IPV6_EXT:
214 printf(" - (outer) L3 type: IPV6_EXT");
216 case RTE_PTYPE_L3_IPV6_EXT_UNKNOWN:
217 printf(" - (outer) L3 type: IPV6_EXT_UNKNOWN");
220 printf(" - (outer) L3 type: Unknown");
224 /* (outer) L4 packet type */
225 ptype = mb->packet_type & RTE_PTYPE_L4_MASK;
227 case RTE_PTYPE_L4_TCP:
228 printf(" - (outer) L4 type: TCP");
230 case RTE_PTYPE_L4_UDP:
231 printf(" - (outer) L4 type: UDP");
233 case RTE_PTYPE_L4_FRAG:
234 printf(" - (outer) L4 type: L4_FRAG");
236 case RTE_PTYPE_L4_SCTP:
237 printf(" - (outer) L4 type: SCTP");
239 case RTE_PTYPE_L4_ICMP:
240 printf(" - (outer) L4 type: ICMP");
242 case RTE_PTYPE_L4_NONFRAG:
243 printf(" - (outer) L4 type: L4_NONFRAG");
246 printf(" - (outer) L4 type: Unknown");
250 /* packet tunnel type */
251 ptype = mb->packet_type & RTE_PTYPE_TUNNEL_MASK;
253 case RTE_PTYPE_TUNNEL_IP:
254 printf(" - Tunnel type: IP");
256 case RTE_PTYPE_TUNNEL_GRE:
257 printf(" - Tunnel type: GRE");
259 case RTE_PTYPE_TUNNEL_VXLAN:
260 printf(" - Tunnel type: VXLAN");
262 case RTE_PTYPE_TUNNEL_NVGRE:
263 printf(" - Tunnel type: NVGRE");
265 case RTE_PTYPE_TUNNEL_GENEVE:
266 printf(" - Tunnel type: GENEVE");
268 case RTE_PTYPE_TUNNEL_GRENAT:
269 printf(" - Tunnel type: GRENAT");
272 printf(" - Tunnel type: Unknown");
276 /* inner L2 packet type */
277 ptype = mb->packet_type & RTE_PTYPE_INNER_L2_MASK;
279 case RTE_PTYPE_INNER_L2_ETHER:
280 printf(" - Inner L2 type: ETHER");
282 case RTE_PTYPE_INNER_L2_ETHER_VLAN:
283 printf(" - Inner L2 type: ETHER_VLAN");
286 printf(" - Inner L2 type: Unknown");
290 /* inner L3 packet type */
291 ptype = mb->packet_type & RTE_PTYPE_INNER_INNER_L3_MASK;
293 case RTE_PTYPE_INNER_L3_IPV4:
294 printf(" - Inner L3 type: IPV4");
296 case RTE_PTYPE_INNER_L3_IPV4_EXT:
297 printf(" - Inner L3 type: IPV4_EXT");
299 case RTE_PTYPE_INNER_L3_IPV6:
300 printf(" - Inner L3 type: IPV6");
302 case RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN:
303 printf(" - Inner L3 type: IPV4_EXT_UNKNOWN");
305 case RTE_PTYPE_INNER_L3_IPV6_EXT:
306 printf(" - Inner L3 type: IPV6_EXT");
308 case RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN:
309 printf(" - Inner L3 type: IPV6_EXT_UNKNOWN");
312 printf(" - Inner L3 type: Unknown");
316 /* inner L4 packet type */
317 ptype = mb->packet_type & RTE_PTYPE_INNER_L4_MASK;
319 case RTE_PTYPE_INNER_L4_TCP:
320 printf(" - Inner L4 type: TCP");
322 case RTE_PTYPE_INNER_L4_UDP:
323 printf(" - Inner L4 type: UDP");
325 case RTE_PTYPE_INNER_L4_FRAG:
326 printf(" - Inner L4 type: L4_FRAG");
328 case RTE_PTYPE_INNER_L4_SCTP:
329 printf(" - Inner L4 type: SCTP");
331 case RTE_PTYPE_INNER_L4_ICMP:
332 printf(" - Inner L4 type: ICMP");
334 case RTE_PTYPE_INNER_L4_NONFRAG:
335 printf(" - Inner L4 type: L4_NONFRAG");
338 printf(" - Inner L4 type: Unknown");
343 printf("Unknown packet type\n");
344 #endif /* RTE_NEXT_ABI */
345 if (is_encapsulation) {
346 struct ipv4_hdr *ipv4_hdr;
347 struct ipv6_hdr *ipv6_hdr;
348 struct udp_hdr *udp_hdr;
353 struct vxlan_hdr *vxlan_hdr;
355 l2_len = sizeof(struct ether_hdr);
357 /* Do not support ipv4 option field */
359 if (RTE_ETH_IS_IPV4_HDR(packet_type)) {
361 if (ol_flags & PKT_RX_TUNNEL_IPV4_HDR) {
363 l3_len = sizeof(struct ipv4_hdr);
364 ipv4_hdr = rte_pktmbuf_mtod_offset(mb,
367 l4_proto = ipv4_hdr->next_proto_id;
369 l3_len = sizeof(struct ipv6_hdr);
370 ipv6_hdr = rte_pktmbuf_mtod_offset(mb,
373 l4_proto = ipv6_hdr->proto;
375 if (l4_proto == IPPROTO_UDP) {
376 udp_hdr = rte_pktmbuf_mtod_offset(mb,
379 l4_len = sizeof(struct udp_hdr);
380 vxlan_hdr = rte_pktmbuf_mtod_offset(mb,
382 l2_len + l3_len + l4_len);
384 printf(" - VXLAN packet: packet type =%d, "
385 "Destination UDP port =%d, VNI = %d",
386 packet_type, RTE_BE_TO_CPU_16(udp_hdr->dst_port),
387 rte_be_to_cpu_32(vxlan_hdr->vx_vni) >> 8);
390 printf(" - Receive queue=0x%x", (unsigned) fs->rx_queue);
396 for (rxf = 0; rxf < sizeof(mb->ol_flags) * 8; rxf++) {
397 if ((ol_flags & (1ULL << rxf)) == 0)
399 name = rte_get_rx_ol_flag_name(1ULL << rxf);
402 printf(" %s\n", name);
405 rte_pktmbuf_free(mb);
408 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
409 end_tsc = rte_rdtsc();
410 core_cycles = (end_tsc - start_tsc);
411 fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
415 struct fwd_engine rx_only_engine = {
416 .fwd_mode_name = "rxonly",
417 .port_fwd_begin = NULL,
418 .port_fwd_end = NULL,
419 .packet_fwd = pkt_burst_receive,