remove version in all files
[dpdk.git] / app / test-pmd / rxonly.c
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2012 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
35 #include <stdarg.h>
36 #include <string.h>
37 #include <stdio.h>
38 #include <errno.h>
39 #include <stdint.h>
40 #include <unistd.h>
41 #include <inttypes.h>
42
43 #include <sys/queue.h>
44 #include <sys/stat.h>
45
46 #include <rte_common.h>
47 #include <rte_byteorder.h>
48 #include <rte_log.h>
49 #include <rte_debug.h>
50 #include <rte_cycles.h>
51 #include <rte_memory.h>
52 #include <rte_memcpy.h>
53 #include <rte_memzone.h>
54 #include <rte_launch.h>
55 #include <rte_tailq.h>
56 #include <rte_eal.h>
57 #include <rte_per_lcore.h>
58 #include <rte_lcore.h>
59 #include <rte_atomic.h>
60 #include <rte_branch_prediction.h>
61 #include <rte_ring.h>
62 #include <rte_memory.h>
63 #include <rte_mempool.h>
64 #include <rte_mbuf.h>
65 #include <rte_interrupts.h>
66 #include <rte_pci.h>
67 #include <rte_ether.h>
68 #include <rte_ethdev.h>
69 #include <rte_string_fns.h>
70
71 #include "testpmd.h"
72
73 #define MAX_PKT_RX_FLAGS 11
74 static const char *pkt_rx_flag_names[MAX_PKT_RX_FLAGS] = {
75         "VLAN_PKT",
76         "RSS_HASH",
77         "PKT_RX_FDIR",
78         "IP_CKSUM",
79         "IP_CKSUM_BAD",
80
81         "IPV4_HDR",
82         "IPV4_HDR_EXT",
83         "IPV6_HDR",
84         "IPV6_HDR_EXT",
85
86         "IEEE1588_PTP",
87         "IEEE1588_TMST",
88 };
89
90 static inline void
91 print_ether_addr(const char *what, struct ether_addr *eth_addr)
92 {
93         printf("%s%02X:%02X:%02X:%02X:%02X:%02X",
94                what,
95                eth_addr->addr_bytes[0],
96                eth_addr->addr_bytes[1],
97                eth_addr->addr_bytes[2],
98                eth_addr->addr_bytes[3],
99                eth_addr->addr_bytes[4],
100                eth_addr->addr_bytes[5]);
101 }
102
103 /*
104  * Received a burst of packets.
105  */
106 static void
107 pkt_burst_receive(struct fwd_stream *fs)
108 {
109         struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
110         struct rte_mbuf  *mb;
111         struct ether_hdr *eth_hdr;
112         uint16_t eth_type;
113         uint16_t ol_flags;
114         uint16_t nb_rx;
115         uint16_t i;
116 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
117         uint64_t start_tsc;
118         uint64_t end_tsc;
119         uint64_t core_cycles;
120 #endif
121
122 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
123         start_tsc = rte_rdtsc();
124 #endif
125
126         /*
127          * Receive a burst of packets.
128          */
129         nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
130                                  nb_pkt_per_burst);
131         if (unlikely(nb_rx == 0))
132                 return;
133
134 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
135         fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
136 #endif
137         fs->rx_packets += nb_rx;
138
139         /*
140          * Dump each received packet if verbose_level > 0.
141          */
142         if (verbose_level > 0)
143                 printf("port %u/queue %u: received %u packets\n",
144                        (unsigned) fs->rx_port,
145                        (unsigned) fs->rx_queue,
146                        (unsigned) nb_rx);
147         for (i = 0; i < nb_rx; i++) {
148                 mb = pkts_burst[i];
149                 if (verbose_level == 0) {
150                         rte_pktmbuf_free(mb);
151                         continue;
152                 }
153                 eth_hdr = (struct ether_hdr *) mb->pkt.data;
154                 eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
155                 ol_flags = mb->ol_flags;
156                 print_ether_addr("  src=", &eth_hdr->s_addr);
157                 print_ether_addr(" - dst=", &eth_hdr->d_addr);
158                 printf(" - type=0x%04x - length=%u - nb_segs=%d",
159                        eth_type, (unsigned) mb->pkt.pkt_len,
160                        (int)mb->pkt.nb_segs);
161                 if (ol_flags & PKT_RX_RSS_HASH)
162                         printf(" - RSS hash=0x%x", (unsigned) mb->pkt.hash.rss);
163                 else if (ol_flags & PKT_RX_FDIR)
164                         printf(" - FDIR hash=0x%x - FDIR id=0x%x ",
165                                mb->pkt.hash.fdir.hash, mb->pkt.hash.fdir.id);
166                 if (ol_flags & PKT_RX_VLAN_PKT)
167                         printf(" - VLAN tci=0x%x", mb->pkt.vlan_tci);
168                 printf("\n");
169                 if (ol_flags != 0) {
170                         int rxf;
171
172                         for (rxf = 0; rxf < MAX_PKT_RX_FLAGS; rxf++) {
173                                 if (ol_flags & (1 << rxf))
174                                         printf("  PKT_RX_%s\n",
175                                                pkt_rx_flag_names[rxf]);
176                         }
177                 }
178                 rte_pktmbuf_free(mb);
179         }
180
181 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
182         end_tsc = rte_rdtsc();
183         core_cycles = (end_tsc - start_tsc);
184         fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
185 #endif
186 }
187
188 struct fwd_engine rx_only_engine = {
189         .fwd_mode_name  = "rxonly",
190         .port_fwd_begin = NULL,
191         .port_fwd_end   = NULL,
192         .packet_fwd     = pkt_burst_receive,
193 };