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>
54 #include <rte_tailq.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
61 #include <rte_memory.h>
62 #include <rte_mempool.h>
64 #include <rte_interrupts.h>
66 #include <rte_ether.h>
67 #include <rte_ethdev.h>
68 #include <rte_string_fns.h>
74 #define MAX_PKT_RX_FLAGS 13
75 static const char *pkt_rx_flag_names[MAX_PKT_RX_FLAGS] = {
95 print_ether_addr(const char *what, struct ether_addr *eth_addr)
97 char buf[ETHER_ADDR_FMT_SIZE];
98 ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
99 printf("%s%s", what, buf);
103 * Received a burst of packets.
106 pkt_burst_receive(struct fwd_stream *fs)
108 struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
110 struct ether_hdr *eth_hdr;
114 uint16_t i, packet_type;
115 uint64_t is_encapsulation;
117 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
120 uint64_t core_cycles;
123 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
124 start_tsc = rte_rdtsc();
128 * Receive a burst of packets.
130 nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
132 if (unlikely(nb_rx == 0))
135 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
136 fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
138 fs->rx_packets += nb_rx;
141 * Dump each received packet if verbose_level > 0.
143 if (verbose_level > 0)
144 printf("port %u/queue %u: received %u packets\n",
145 (unsigned) fs->rx_port,
146 (unsigned) fs->rx_queue,
148 for (i = 0; i < nb_rx; i++) {
150 if (verbose_level == 0) {
151 rte_pktmbuf_free(mb);
154 eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
155 eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
156 ol_flags = mb->ol_flags;
157 packet_type = mb->packet_type;
159 is_encapsulation = ol_flags & (PKT_RX_TUNNEL_IPV4_HDR |
160 PKT_RX_TUNNEL_IPV6_HDR);
162 print_ether_addr(" src=", ð_hdr->s_addr);
163 print_ether_addr(" - dst=", ð_hdr->d_addr);
164 printf(" - type=0x%04x - length=%u - nb_segs=%d",
165 eth_type, (unsigned) mb->pkt_len,
167 if (ol_flags & PKT_RX_RSS_HASH) {
168 printf(" - RSS hash=0x%x", (unsigned) mb->hash.rss);
169 printf(" - RSS queue=0x%x",(unsigned) fs->rx_queue);
171 else if (ol_flags & PKT_RX_FDIR)
172 printf(" - FDIR hash=0x%x - FDIR id=0x%x ",
173 mb->hash.fdir.hash, mb->hash.fdir.id);
174 if (ol_flags & PKT_RX_VLAN_PKT)
175 printf(" - VLAN tci=0x%x", mb->vlan_tci);
176 if (is_encapsulation) {
177 struct ipv4_hdr *ipv4_hdr;
178 struct ipv6_hdr *ipv6_hdr;
179 struct udp_hdr *udp_hdr;
184 struct vxlan_hdr *vxlan_hdr;
186 l2_len = sizeof(struct ether_hdr);
188 /* Do not support ipv4 option field */
189 if (ol_flags & PKT_RX_TUNNEL_IPV4_HDR) {
190 l3_len = sizeof(struct ipv4_hdr);
191 ipv4_hdr = (struct ipv4_hdr *) (rte_pktmbuf_mtod(mb,
192 unsigned char *) + l2_len);
193 l4_proto = ipv4_hdr->next_proto_id;
195 l3_len = sizeof(struct ipv6_hdr);
196 ipv6_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(mb,
197 unsigned char *) + l2_len);
198 l4_proto = ipv6_hdr->proto;
200 if (l4_proto == IPPROTO_UDP) {
201 udp_hdr = (struct udp_hdr *) (rte_pktmbuf_mtod(mb,
202 unsigned char *) + l2_len + l3_len);
203 l4_len = sizeof(struct udp_hdr);
204 vxlan_hdr = (struct vxlan_hdr *) (rte_pktmbuf_mtod(mb,
205 unsigned char *) + l2_len + l3_len
208 printf(" - VXLAN packet: packet type =%d, "
209 "Destination UDP port =%d, VNI = %d",
210 packet_type, RTE_BE_TO_CPU_16(udp_hdr->dst_port),
211 rte_be_to_cpu_32(vxlan_hdr->vx_vni) >> 8);
214 printf(" - Receive queue=0x%x", (unsigned) fs->rx_queue);
219 for (rxf = 0; rxf < MAX_PKT_RX_FLAGS; rxf++) {
220 if (ol_flags & (1 << rxf))
221 printf(" PKT_RX_%s\n",
222 pkt_rx_flag_names[rxf]);
225 rte_pktmbuf_free(mb);
228 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
229 end_tsc = rte_rdtsc();
230 core_cycles = (end_tsc - start_tsc);
231 fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
235 struct fwd_engine rx_only_engine = {
236 .fwd_mode_name = "rxonly",
237 .port_fwd_begin = NULL,
238 .port_fwd_end = NULL,
239 .packet_fwd = pkt_burst_receive,