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>
59 #include <rte_memory.h>
60 #include <rte_mempool.h>
62 #include <rte_interrupts.h>
64 #include <rte_ether.h>
65 #include <rte_ethdev.h>
66 #include <rte_string_fns.h>
73 print_ether_addr(const char *what, struct ether_addr *eth_addr)
75 char buf[ETHER_ADDR_FMT_SIZE];
76 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
77 printf("%s%s", what, buf);
81 * Received a burst of packets.
84 pkt_burst_receive(struct fwd_stream *fs)
86 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
88 struct ether_hdr *eth_hdr;
92 uint16_t i, packet_type;
93 uint16_t is_encapsulation;
95 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
101 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
102 start_tsc = rte_rdtsc();
106 * Receive a burst of packets.
108 nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
110 if (unlikely(nb_rx == 0))
113 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
114 fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
116 fs->rx_packets += nb_rx;
119 * Dump each received packet if verbose_level > 0.
121 if (verbose_level > 0)
122 printf("port %u/queue %u: received %u packets\n",
123 (unsigned) fs->rx_port,
124 (unsigned) fs->rx_queue,
126 for (i = 0; i < nb_rx; i++) {
128 if (verbose_level == 0) {
129 rte_pktmbuf_free(mb);
132 eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
133 eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
134 ol_flags = mb->ol_flags;
135 packet_type = mb->packet_type;
136 is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
138 print_ether_addr(" src=", ð_hdr->s_addr);
139 print_ether_addr(" - dst=", ð_hdr->d_addr);
140 printf(" - type=0x%04x - length=%u - nb_segs=%d",
141 eth_type, (unsigned) mb->pkt_len,
143 if (ol_flags & PKT_RX_RSS_HASH) {
144 printf(" - RSS hash=0x%x", (unsigned) mb->hash.rss);
145 printf(" - RSS queue=0x%x",(unsigned) fs->rx_queue);
146 } else if (ol_flags & PKT_RX_FDIR) {
147 printf(" - FDIR matched ");
148 if (ol_flags & PKT_RX_FDIR_ID)
151 else if (ol_flags & PKT_RX_FDIR_FLX)
152 printf("flex bytes=0x%08x %08x",
153 mb->hash.fdir.hi, mb->hash.fdir.lo);
155 printf("hash=0x%x ID=0x%x ",
156 mb->hash.fdir.hash, mb->hash.fdir.id);
158 if (ol_flags & PKT_RX_VLAN_STRIPPED)
159 printf(" - VLAN tci=0x%x", mb->vlan_tci);
160 if (ol_flags & PKT_RX_QINQ_STRIPPED)
161 printf(" - QinQ VLAN tci=0x%x, VLAN tci outer=0x%x",
162 mb->vlan_tci, mb->vlan_tci_outer);
163 if (mb->packet_type) {
166 /* (outer) L2 packet type */
167 ptype = mb->packet_type & RTE_PTYPE_L2_MASK;
169 case RTE_PTYPE_L2_ETHER:
170 printf(" - (outer) L2 type: ETHER");
172 case RTE_PTYPE_L2_ETHER_TIMESYNC:
173 printf(" - (outer) L2 type: ETHER_Timesync");
175 case RTE_PTYPE_L2_ETHER_ARP:
176 printf(" - (outer) L2 type: ETHER_ARP");
178 case RTE_PTYPE_L2_ETHER_LLDP:
179 printf(" - (outer) L2 type: ETHER_LLDP");
181 case RTE_PTYPE_L2_ETHER_NSH:
182 printf(" - (outer) L2 type: ETHER_NSH");
185 printf(" - (outer) L2 type: Unknown");
189 /* (outer) L3 packet type */
190 ptype = mb->packet_type & RTE_PTYPE_L3_MASK;
192 case RTE_PTYPE_L3_IPV4:
193 printf(" - (outer) L3 type: IPV4");
195 case RTE_PTYPE_L3_IPV4_EXT:
196 printf(" - (outer) L3 type: IPV4_EXT");
198 case RTE_PTYPE_L3_IPV6:
199 printf(" - (outer) L3 type: IPV6");
201 case RTE_PTYPE_L3_IPV4_EXT_UNKNOWN:
202 printf(" - (outer) L3 type: IPV4_EXT_UNKNOWN");
204 case RTE_PTYPE_L3_IPV6_EXT:
205 printf(" - (outer) L3 type: IPV6_EXT");
207 case RTE_PTYPE_L3_IPV6_EXT_UNKNOWN:
208 printf(" - (outer) L3 type: IPV6_EXT_UNKNOWN");
211 printf(" - (outer) L3 type: Unknown");
215 /* (outer) L4 packet type */
216 ptype = mb->packet_type & RTE_PTYPE_L4_MASK;
218 case RTE_PTYPE_L4_TCP:
219 printf(" - (outer) L4 type: TCP");
221 case RTE_PTYPE_L4_UDP:
222 printf(" - (outer) L4 type: UDP");
224 case RTE_PTYPE_L4_FRAG:
225 printf(" - (outer) L4 type: L4_FRAG");
227 case RTE_PTYPE_L4_SCTP:
228 printf(" - (outer) L4 type: SCTP");
230 case RTE_PTYPE_L4_ICMP:
231 printf(" - (outer) L4 type: ICMP");
233 case RTE_PTYPE_L4_NONFRAG:
234 printf(" - (outer) L4 type: L4_NONFRAG");
237 printf(" - (outer) L4 type: Unknown");
241 /* packet tunnel type */
242 ptype = mb->packet_type & RTE_PTYPE_TUNNEL_MASK;
244 case RTE_PTYPE_TUNNEL_IP:
245 printf(" - Tunnel type: IP");
247 case RTE_PTYPE_TUNNEL_GRE:
248 printf(" - Tunnel type: GRE");
250 case RTE_PTYPE_TUNNEL_VXLAN:
251 printf(" - Tunnel type: VXLAN");
253 case RTE_PTYPE_TUNNEL_NVGRE:
254 printf(" - Tunnel type: NVGRE");
256 case RTE_PTYPE_TUNNEL_GENEVE:
257 printf(" - Tunnel type: GENEVE");
259 case RTE_PTYPE_TUNNEL_GRENAT:
260 printf(" - Tunnel type: GRENAT");
263 printf(" - Tunnel type: Unknown");
267 /* inner L2 packet type */
268 ptype = mb->packet_type & RTE_PTYPE_INNER_L2_MASK;
270 case RTE_PTYPE_INNER_L2_ETHER:
271 printf(" - Inner L2 type: ETHER");
273 case RTE_PTYPE_INNER_L2_ETHER_VLAN:
274 printf(" - Inner L2 type: ETHER_VLAN");
277 printf(" - Inner L2 type: Unknown");
281 /* inner L3 packet type */
282 ptype = mb->packet_type & RTE_PTYPE_INNER_L3_MASK;
284 case RTE_PTYPE_INNER_L3_IPV4:
285 printf(" - Inner L3 type: IPV4");
287 case RTE_PTYPE_INNER_L3_IPV4_EXT:
288 printf(" - Inner L3 type: IPV4_EXT");
290 case RTE_PTYPE_INNER_L3_IPV6:
291 printf(" - Inner L3 type: IPV6");
293 case RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN:
294 printf(" - Inner L3 type: IPV4_EXT_UNKNOWN");
296 case RTE_PTYPE_INNER_L3_IPV6_EXT:
297 printf(" - Inner L3 type: IPV6_EXT");
299 case RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN:
300 printf(" - Inner L3 type: IPV6_EXT_UNKNOWN");
303 printf(" - Inner L3 type: Unknown");
307 /* inner L4 packet type */
308 ptype = mb->packet_type & RTE_PTYPE_INNER_L4_MASK;
310 case RTE_PTYPE_INNER_L4_TCP:
311 printf(" - Inner L4 type: TCP");
313 case RTE_PTYPE_INNER_L4_UDP:
314 printf(" - Inner L4 type: UDP");
316 case RTE_PTYPE_INNER_L4_FRAG:
317 printf(" - Inner L4 type: L4_FRAG");
319 case RTE_PTYPE_INNER_L4_SCTP:
320 printf(" - Inner L4 type: SCTP");
322 case RTE_PTYPE_INNER_L4_ICMP:
323 printf(" - Inner L4 type: ICMP");
325 case RTE_PTYPE_INNER_L4_NONFRAG:
326 printf(" - Inner L4 type: L4_NONFRAG");
329 printf(" - Inner L4 type: Unknown");
334 printf("Unknown packet type\n");
335 if (is_encapsulation) {
336 struct ipv4_hdr *ipv4_hdr;
337 struct ipv6_hdr *ipv6_hdr;
338 struct udp_hdr *udp_hdr;
343 struct vxlan_hdr *vxlan_hdr;
345 l2_len = sizeof(struct ether_hdr);
347 /* Do not support ipv4 option field */
348 if (RTE_ETH_IS_IPV4_HDR(packet_type)) {
349 l3_len = sizeof(struct ipv4_hdr);
350 ipv4_hdr = rte_pktmbuf_mtod_offset(mb,
353 l4_proto = ipv4_hdr->next_proto_id;
355 l3_len = sizeof(struct ipv6_hdr);
356 ipv6_hdr = rte_pktmbuf_mtod_offset(mb,
359 l4_proto = ipv6_hdr->proto;
361 if (l4_proto == IPPROTO_UDP) {
362 udp_hdr = rte_pktmbuf_mtod_offset(mb,
365 l4_len = sizeof(struct udp_hdr);
366 vxlan_hdr = rte_pktmbuf_mtod_offset(mb,
368 l2_len + l3_len + l4_len);
370 printf(" - VXLAN packet: packet type =%d, "
371 "Destination UDP port =%d, VNI = %d",
372 packet_type, RTE_BE_TO_CPU_16(udp_hdr->dst_port),
373 rte_be_to_cpu_32(vxlan_hdr->vx_vni) >> 8);
376 printf(" - Receive queue=0x%x", (unsigned) fs->rx_queue);
382 for (rxf = 0; rxf < sizeof(mb->ol_flags) * 8; rxf++) {
383 if ((ol_flags & (1ULL << rxf)) == 0)
385 name = rte_get_rx_ol_flag_name(1ULL << rxf);
388 printf(" %s\n", name);
391 rte_pktmbuf_free(mb);
394 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
395 end_tsc = rte_rdtsc();
396 core_cycles = (end_tsc - start_tsc);
397 fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
401 struct fwd_engine rx_only_engine = {
402 .fwd_mode_name = "rxonly",
403 .port_fwd_begin = NULL,
404 .port_fwd_end = NULL,
405 .packet_fwd = pkt_burst_receive,