remove unused ring includes
[dpdk.git] / app / test-pmd / rxonly.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include <stdarg.h>
35 #include <string.h>
36 #include <stdio.h>
37 #include <errno.h>
38 #include <stdint.h>
39 #include <unistd.h>
40 #include <inttypes.h>
41
42 #include <sys/queue.h>
43 #include <sys/stat.h>
44
45 #include <rte_common.h>
46 #include <rte_byteorder.h>
47 #include <rte_log.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_eal.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>
61 #include <rte_mbuf.h>
62 #include <rte_interrupts.h>
63 #include <rte_pci.h>
64 #include <rte_ether.h>
65 #include <rte_ethdev.h>
66 #include <rte_string_fns.h>
67 #include <rte_ip.h>
68 #include <rte_udp.h>
69
70 #include "testpmd.h"
71
72 static inline void
73 print_ether_addr(const char *what, struct ether_addr *eth_addr)
74 {
75         char buf[ETHER_ADDR_FMT_SIZE];
76         ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
77         printf("%s%s", what, buf);
78 }
79
80 /*
81  * Received a burst of packets.
82  */
83 static void
84 pkt_burst_receive(struct fwd_stream *fs)
85 {
86         struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
87         struct rte_mbuf  *mb;
88         struct ether_hdr *eth_hdr;
89         uint16_t eth_type;
90         uint64_t ol_flags;
91         uint16_t nb_rx;
92         uint16_t i, packet_type;
93         uint16_t is_encapsulation;
94
95 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
96         uint64_t start_tsc;
97         uint64_t end_tsc;
98         uint64_t core_cycles;
99 #endif
100
101 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
102         start_tsc = rte_rdtsc();
103 #endif
104
105         /*
106          * Receive a burst of packets.
107          */
108         nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
109                                  nb_pkt_per_burst);
110         if (unlikely(nb_rx == 0))
111                 return;
112
113 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
114         fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
115 #endif
116         fs->rx_packets += nb_rx;
117
118         /*
119          * Dump each received packet if verbose_level > 0.
120          */
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,
125                        (unsigned) nb_rx);
126         for (i = 0; i < nb_rx; i++) {
127                 mb = pkts_burst[i];
128                 if (verbose_level == 0) {
129                         rte_pktmbuf_free(mb);
130                         continue;
131                 }
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);
137
138                 print_ether_addr("  src=", &eth_hdr->s_addr);
139                 print_ether_addr(" - dst=", &eth_hdr->d_addr);
140                 printf(" - type=0x%04x - length=%u - nb_segs=%d",
141                        eth_type, (unsigned) mb->pkt_len,
142                        (int)mb->nb_segs);
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)
149                                 printf("ID=0x%x",
150                                        mb->hash.fdir.hi);
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);
154                         else
155                                 printf("hash=0x%x ID=0x%x ",
156                                        mb->hash.fdir.hash, mb->hash.fdir.id);
157                 }
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) {
164                         uint32_t ptype;
165
166                         /* (outer) L2 packet type */
167                         ptype = mb->packet_type & RTE_PTYPE_L2_MASK;
168                         switch (ptype) {
169                         case RTE_PTYPE_L2_ETHER:
170                                 printf(" - (outer) L2 type: ETHER");
171                                 break;
172                         case RTE_PTYPE_L2_ETHER_TIMESYNC:
173                                 printf(" - (outer) L2 type: ETHER_Timesync");
174                                 break;
175                         case RTE_PTYPE_L2_ETHER_ARP:
176                                 printf(" - (outer) L2 type: ETHER_ARP");
177                                 break;
178                         case RTE_PTYPE_L2_ETHER_LLDP:
179                                 printf(" - (outer) L2 type: ETHER_LLDP");
180                                 break;
181                         case RTE_PTYPE_L2_ETHER_NSH:
182                                 printf(" - (outer) L2 type: ETHER_NSH");
183                                 break;
184                         default:
185                                 printf(" - (outer) L2 type: Unknown");
186                                 break;
187                         }
188
189                         /* (outer) L3 packet type */
190                         ptype = mb->packet_type & RTE_PTYPE_L3_MASK;
191                         switch (ptype) {
192                         case RTE_PTYPE_L3_IPV4:
193                                 printf(" - (outer) L3 type: IPV4");
194                                 break;
195                         case RTE_PTYPE_L3_IPV4_EXT:
196                                 printf(" - (outer) L3 type: IPV4_EXT");
197                                 break;
198                         case RTE_PTYPE_L3_IPV6:
199                                 printf(" - (outer) L3 type: IPV6");
200                                 break;
201                         case RTE_PTYPE_L3_IPV4_EXT_UNKNOWN:
202                                 printf(" - (outer) L3 type: IPV4_EXT_UNKNOWN");
203                                 break;
204                         case RTE_PTYPE_L3_IPV6_EXT:
205                                 printf(" - (outer) L3 type: IPV6_EXT");
206                                 break;
207                         case RTE_PTYPE_L3_IPV6_EXT_UNKNOWN:
208                                 printf(" - (outer) L3 type: IPV6_EXT_UNKNOWN");
209                                 break;
210                         default:
211                                 printf(" - (outer) L3 type: Unknown");
212                                 break;
213                         }
214
215                         /* (outer) L4 packet type */
216                         ptype = mb->packet_type & RTE_PTYPE_L4_MASK;
217                         switch (ptype) {
218                         case RTE_PTYPE_L4_TCP:
219                                 printf(" - (outer) L4 type: TCP");
220                                 break;
221                         case RTE_PTYPE_L4_UDP:
222                                 printf(" - (outer) L4 type: UDP");
223                                 break;
224                         case RTE_PTYPE_L4_FRAG:
225                                 printf(" - (outer) L4 type: L4_FRAG");
226                                 break;
227                         case RTE_PTYPE_L4_SCTP:
228                                 printf(" - (outer) L4 type: SCTP");
229                                 break;
230                         case RTE_PTYPE_L4_ICMP:
231                                 printf(" - (outer) L4 type: ICMP");
232                                 break;
233                         case RTE_PTYPE_L4_NONFRAG:
234                                 printf(" - (outer) L4 type: L4_NONFRAG");
235                                 break;
236                         default:
237                                 printf(" - (outer) L4 type: Unknown");
238                                 break;
239                         }
240
241                         /* packet tunnel type */
242                         ptype = mb->packet_type & RTE_PTYPE_TUNNEL_MASK;
243                         switch (ptype) {
244                         case RTE_PTYPE_TUNNEL_IP:
245                                 printf(" - Tunnel type: IP");
246                                 break;
247                         case RTE_PTYPE_TUNNEL_GRE:
248                                 printf(" - Tunnel type: GRE");
249                                 break;
250                         case RTE_PTYPE_TUNNEL_VXLAN:
251                                 printf(" - Tunnel type: VXLAN");
252                                 break;
253                         case RTE_PTYPE_TUNNEL_NVGRE:
254                                 printf(" - Tunnel type: NVGRE");
255                                 break;
256                         case RTE_PTYPE_TUNNEL_GENEVE:
257                                 printf(" - Tunnel type: GENEVE");
258                                 break;
259                         case RTE_PTYPE_TUNNEL_GRENAT:
260                                 printf(" - Tunnel type: GRENAT");
261                                 break;
262                         default:
263                                 printf(" - Tunnel type: Unknown");
264                                 break;
265                         }
266
267                         /* inner L2 packet type */
268                         ptype = mb->packet_type & RTE_PTYPE_INNER_L2_MASK;
269                         switch (ptype) {
270                         case RTE_PTYPE_INNER_L2_ETHER:
271                                 printf(" - Inner L2 type: ETHER");
272                                 break;
273                         case RTE_PTYPE_INNER_L2_ETHER_VLAN:
274                                 printf(" - Inner L2 type: ETHER_VLAN");
275                                 break;
276                         default:
277                                 printf(" - Inner L2 type: Unknown");
278                                 break;
279                         }
280
281                         /* inner L3 packet type */
282                         ptype = mb->packet_type & RTE_PTYPE_INNER_L3_MASK;
283                         switch (ptype) {
284                         case RTE_PTYPE_INNER_L3_IPV4:
285                                 printf(" - Inner L3 type: IPV4");
286                                 break;
287                         case RTE_PTYPE_INNER_L3_IPV4_EXT:
288                                 printf(" - Inner L3 type: IPV4_EXT");
289                                 break;
290                         case RTE_PTYPE_INNER_L3_IPV6:
291                                 printf(" - Inner L3 type: IPV6");
292                                 break;
293                         case RTE_PTYPE_INNER_L3_IPV4_EXT_UNKNOWN:
294                                 printf(" - Inner L3 type: IPV4_EXT_UNKNOWN");
295                                 break;
296                         case RTE_PTYPE_INNER_L3_IPV6_EXT:
297                                 printf(" - Inner L3 type: IPV6_EXT");
298                                 break;
299                         case RTE_PTYPE_INNER_L3_IPV6_EXT_UNKNOWN:
300                                 printf(" - Inner L3 type: IPV6_EXT_UNKNOWN");
301                                 break;
302                         default:
303                                 printf(" - Inner L3 type: Unknown");
304                                 break;
305                         }
306
307                         /* inner L4 packet type */
308                         ptype = mb->packet_type & RTE_PTYPE_INNER_L4_MASK;
309                         switch (ptype) {
310                         case RTE_PTYPE_INNER_L4_TCP:
311                                 printf(" - Inner L4 type: TCP");
312                                 break;
313                         case RTE_PTYPE_INNER_L4_UDP:
314                                 printf(" - Inner L4 type: UDP");
315                                 break;
316                         case RTE_PTYPE_INNER_L4_FRAG:
317                                 printf(" - Inner L4 type: L4_FRAG");
318                                 break;
319                         case RTE_PTYPE_INNER_L4_SCTP:
320                                 printf(" - Inner L4 type: SCTP");
321                                 break;
322                         case RTE_PTYPE_INNER_L4_ICMP:
323                                 printf(" - Inner L4 type: ICMP");
324                                 break;
325                         case RTE_PTYPE_INNER_L4_NONFRAG:
326                                 printf(" - Inner L4 type: L4_NONFRAG");
327                                 break;
328                         default:
329                                 printf(" - Inner L4 type: Unknown");
330                                 break;
331                         }
332                         printf("\n");
333                 } else
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;
339                         uint8_t l2_len;
340                         uint8_t l3_len;
341                         uint8_t l4_len;
342                         uint8_t l4_proto;
343                         struct  vxlan_hdr *vxlan_hdr;
344
345                         l2_len  = sizeof(struct ether_hdr);
346
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,
351                                                                    struct ipv4_hdr *,
352                                                                    l2_len);
353                                 l4_proto = ipv4_hdr->next_proto_id;
354                         } else {
355                                 l3_len = sizeof(struct ipv6_hdr);
356                                 ipv6_hdr = rte_pktmbuf_mtod_offset(mb,
357                                                                    struct ipv6_hdr *,
358                                                                    l2_len);
359                                 l4_proto = ipv6_hdr->proto;
360                         }
361                         if (l4_proto == IPPROTO_UDP) {
362                                 udp_hdr = rte_pktmbuf_mtod_offset(mb,
363                                                                   struct udp_hdr *,
364                                                                   l2_len + l3_len);
365                                 l4_len = sizeof(struct udp_hdr);
366                                 vxlan_hdr = rte_pktmbuf_mtod_offset(mb,
367                                                                     struct vxlan_hdr *,
368                                                                     l2_len + l3_len + l4_len);
369
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);
374                         }
375                 }
376                 printf(" - Receive queue=0x%x", (unsigned) fs->rx_queue);
377                 printf("\n");
378                 if (ol_flags != 0) {
379                         unsigned rxf;
380                         const char *name;
381
382                         for (rxf = 0; rxf < sizeof(mb->ol_flags) * 8; rxf++) {
383                                 if ((ol_flags & (1ULL << rxf)) == 0)
384                                         continue;
385                                 name = rte_get_rx_ol_flag_name(1ULL << rxf);
386                                 if (name == NULL)
387                                         continue;
388                                 printf("  %s\n", name);
389                         }
390                 }
391                 rte_pktmbuf_free(mb);
392         }
393
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);
398 #endif
399 }
400
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,
406 };