ethdev: remove old flex filter API
[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_tailq.h>
55 #include <rte_eal.h>
56 #include <rte_per_lcore.h>
57 #include <rte_lcore.h>
58 #include <rte_atomic.h>
59 #include <rte_branch_prediction.h>
60 #include <rte_ring.h>
61 #include <rte_memory.h>
62 #include <rte_mempool.h>
63 #include <rte_mbuf.h>
64 #include <rte_interrupts.h>
65 #include <rte_pci.h>
66 #include <rte_ether.h>
67 #include <rte_ethdev.h>
68 #include <rte_string_fns.h>
69 #include <rte_ip.h>
70 #include <rte_udp.h>
71
72 #include "testpmd.h"
73
74 static inline void
75 print_ether_addr(const char *what, struct ether_addr *eth_addr)
76 {
77         char buf[ETHER_ADDR_FMT_SIZE];
78         ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
79         printf("%s%s", what, buf);
80 }
81
82 /*
83  * Received a burst of packets.
84  */
85 static void
86 pkt_burst_receive(struct fwd_stream *fs)
87 {
88         struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
89         struct rte_mbuf  *mb;
90         struct ether_hdr *eth_hdr;
91         uint16_t eth_type;
92         uint64_t ol_flags;
93         uint16_t nb_rx;
94         uint16_t i, packet_type;
95         uint64_t is_encapsulation;
96
97 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
98         uint64_t start_tsc;
99         uint64_t end_tsc;
100         uint64_t core_cycles;
101 #endif
102
103 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
104         start_tsc = rte_rdtsc();
105 #endif
106
107         /*
108          * Receive a burst of packets.
109          */
110         nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
111                                  nb_pkt_per_burst);
112         if (unlikely(nb_rx == 0))
113                 return;
114
115 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
116         fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
117 #endif
118         fs->rx_packets += nb_rx;
119
120         /*
121          * Dump each received packet if verbose_level > 0.
122          */
123         if (verbose_level > 0)
124                 printf("port %u/queue %u: received %u packets\n",
125                        (unsigned) fs->rx_port,
126                        (unsigned) fs->rx_queue,
127                        (unsigned) nb_rx);
128         for (i = 0; i < nb_rx; i++) {
129                 mb = pkts_burst[i];
130                 if (verbose_level == 0) {
131                         rte_pktmbuf_free(mb);
132                         continue;
133                 }
134                 eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
135                 eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
136                 ol_flags = mb->ol_flags;
137                 packet_type = mb->packet_type;
138
139                 is_encapsulation = ol_flags & (PKT_RX_TUNNEL_IPV4_HDR |
140                                 PKT_RX_TUNNEL_IPV6_HDR);
141
142                 print_ether_addr("  src=", &eth_hdr->s_addr);
143                 print_ether_addr(" - dst=", &eth_hdr->d_addr);
144                 printf(" - type=0x%04x - length=%u - nb_segs=%d",
145                        eth_type, (unsigned) mb->pkt_len,
146                        (int)mb->nb_segs);
147                 if (ol_flags & PKT_RX_RSS_HASH) {
148                         printf(" - RSS hash=0x%x", (unsigned) mb->hash.rss);
149                         printf(" - RSS queue=0x%x",(unsigned) fs->rx_queue);
150                 } else if (ol_flags & PKT_RX_FDIR) {
151                         printf(" - FDIR matched ");
152                         if (ol_flags & PKT_RX_FDIR_ID)
153                                 printf("ID=0x%x",
154                                        mb->hash.fdir.hi);
155                         else if (ol_flags & PKT_RX_FDIR_FLX)
156                                 printf("flex bytes=0x%08x %08x",
157                                        mb->hash.fdir.hi, mb->hash.fdir.lo);
158                         else
159                                 printf("hash=0x%x ID=0x%x ",
160                                        mb->hash.fdir.hash, mb->hash.fdir.id);
161                 }
162                 if (ol_flags & PKT_RX_VLAN_PKT)
163                         printf(" - VLAN tci=0x%x", mb->vlan_tci);
164                 if (is_encapsulation) {
165                         struct ipv4_hdr *ipv4_hdr;
166                         struct ipv6_hdr *ipv6_hdr;
167                         struct udp_hdr *udp_hdr;
168                         uint8_t l2_len;
169                         uint8_t l3_len;
170                         uint8_t l4_len;
171                         uint8_t l4_proto;
172                         struct  vxlan_hdr *vxlan_hdr;
173
174                         l2_len  = sizeof(struct ether_hdr);
175
176                          /* Do not support ipv4 option field */
177                         if (ol_flags & PKT_RX_TUNNEL_IPV4_HDR) {
178                                 l3_len = sizeof(struct ipv4_hdr);
179                                 ipv4_hdr = (struct ipv4_hdr *) (rte_pktmbuf_mtod(mb,
180                                                 unsigned char *) + l2_len);
181                                 l4_proto = ipv4_hdr->next_proto_id;
182                         } else {
183                                 l3_len = sizeof(struct ipv6_hdr);
184                                 ipv6_hdr = (struct ipv6_hdr *) (rte_pktmbuf_mtod(mb,
185                                                 unsigned char *) + l2_len);
186                                 l4_proto = ipv6_hdr->proto;
187                         }
188                         if (l4_proto == IPPROTO_UDP) {
189                                 udp_hdr = (struct udp_hdr *) (rte_pktmbuf_mtod(mb,
190                                                 unsigned char *) + l2_len + l3_len);
191                                 l4_len = sizeof(struct udp_hdr);
192                                 vxlan_hdr = (struct vxlan_hdr *) (rte_pktmbuf_mtod(mb,
193                                                 unsigned char *) + l2_len + l3_len
194                                                  + l4_len);
195
196                                 printf(" - VXLAN packet: packet type =%d, "
197                                         "Destination UDP port =%d, VNI = %d",
198                                         packet_type, RTE_BE_TO_CPU_16(udp_hdr->dst_port),
199                                         rte_be_to_cpu_32(vxlan_hdr->vx_vni) >> 8);
200                         }
201                 }
202                 printf(" - Receive queue=0x%x", (unsigned) fs->rx_queue);
203                 printf("\n");
204                 if (ol_flags != 0) {
205                         unsigned rxf;
206                         const char *name;
207
208                         for (rxf = 0; rxf < sizeof(mb->ol_flags) * 8; rxf++) {
209                                 if ((ol_flags & (1ULL << rxf)) == 0)
210                                         continue;
211                                 name = rte_get_rx_ol_flag_name(1ULL << rxf);
212                                 if (name == NULL)
213                                         continue;
214                                 printf("  %s\n", name);
215                         }
216                 }
217                 rte_pktmbuf_free(mb);
218         }
219
220 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
221         end_tsc = rte_rdtsc();
222         core_cycles = (end_tsc - start_tsc);
223         fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
224 #endif
225 }
226
227 struct fwd_engine rx_only_engine = {
228         .fwd_mode_name  = "rxonly",
229         .port_fwd_begin = NULL,
230         .port_fwd_end   = NULL,
231         .packet_fwd     = pkt_burst_receive,
232 };