net/fm10k: remove unused constant
[dpdk.git] / app / test-pmd / rxonly.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4
5 #include <stdarg.h>
6 #include <string.h>
7 #include <stdio.h>
8 #include <errno.h>
9 #include <stdint.h>
10 #include <unistd.h>
11 #include <inttypes.h>
12
13 #include <sys/queue.h>
14 #include <sys/stat.h>
15
16 #include <rte_common.h>
17 #include <rte_byteorder.h>
18 #include <rte_log.h>
19 #include <rte_debug.h>
20 #include <rte_cycles.h>
21 #include <rte_memory.h>
22 #include <rte_memcpy.h>
23 #include <rte_launch.h>
24 #include <rte_eal.h>
25 #include <rte_per_lcore.h>
26 #include <rte_lcore.h>
27 #include <rte_atomic.h>
28 #include <rte_branch_prediction.h>
29 #include <rte_mempool.h>
30 #include <rte_mbuf.h>
31 #include <rte_interrupts.h>
32 #include <rte_pci.h>
33 #include <rte_ether.h>
34 #include <rte_ethdev.h>
35 #include <rte_string_fns.h>
36 #include <rte_ip.h>
37 #include <rte_udp.h>
38 #include <rte_net.h>
39 #include <rte_flow.h>
40
41 #include "testpmd.h"
42
43 static inline void
44 print_ether_addr(const char *what, struct ether_addr *eth_addr)
45 {
46         char buf[ETHER_ADDR_FMT_SIZE];
47         ether_format_addr(buf, ETHER_ADDR_FMT_SIZE, eth_addr);
48         printf("%s%s", what, buf);
49 }
50
51 /*
52  * Received a burst of packets.
53  */
54 static void
55 pkt_burst_receive(struct fwd_stream *fs)
56 {
57         struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
58         struct rte_mbuf  *mb;
59         struct ether_hdr *eth_hdr;
60         uint16_t eth_type;
61         uint64_t ol_flags;
62         uint16_t nb_rx;
63         uint16_t i, packet_type;
64         uint16_t is_encapsulation;
65         char buf[256];
66         struct rte_net_hdr_lens hdr_lens;
67         uint32_t sw_packet_type;
68
69 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
70         uint64_t start_tsc;
71         uint64_t end_tsc;
72         uint64_t core_cycles;
73
74         start_tsc = rte_rdtsc();
75 #endif
76
77         /*
78          * Receive a burst of packets.
79          */
80         nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
81                                  nb_pkt_per_burst);
82         if (unlikely(nb_rx == 0))
83                 return;
84
85 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
86         fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
87 #endif
88         fs->rx_packets += nb_rx;
89
90         /*
91          * Dump each received packet if verbose_level > 0.
92          */
93         if (verbose_level > 0)
94                 printf("port %u/queue %u: received %u packets\n",
95                        fs->rx_port,
96                        (unsigned) fs->rx_queue,
97                        (unsigned) nb_rx);
98         for (i = 0; i < nb_rx; i++) {
99                 mb = pkts_burst[i];
100                 if (verbose_level == 0) {
101                         rte_pktmbuf_free(mb);
102                         continue;
103                 }
104                 eth_hdr = rte_pktmbuf_mtod(mb, struct ether_hdr *);
105                 eth_type = RTE_BE_TO_CPU_16(eth_hdr->ether_type);
106                 ol_flags = mb->ol_flags;
107                 packet_type = mb->packet_type;
108                 is_encapsulation = RTE_ETH_IS_TUNNEL_PKT(packet_type);
109
110                 print_ether_addr("  src=", &eth_hdr->s_addr);
111                 print_ether_addr(" - dst=", &eth_hdr->d_addr);
112                 printf(" - type=0x%04x - length=%u - nb_segs=%d",
113                        eth_type, (unsigned) mb->pkt_len,
114                        (int)mb->nb_segs);
115                 if (ol_flags & PKT_RX_RSS_HASH) {
116                         printf(" - RSS hash=0x%x", (unsigned) mb->hash.rss);
117                         printf(" - RSS queue=0x%x",(unsigned) fs->rx_queue);
118                 }
119                 if (ol_flags & PKT_RX_FDIR) {
120                         printf(" - FDIR matched ");
121                         if (ol_flags & PKT_RX_FDIR_ID)
122                                 printf("ID=0x%x",
123                                        mb->hash.fdir.hi);
124                         else if (ol_flags & PKT_RX_FDIR_FLX)
125                                 printf("flex bytes=0x%08x %08x",
126                                        mb->hash.fdir.hi, mb->hash.fdir.lo);
127                         else
128                                 printf("hash=0x%x ID=0x%x ",
129                                        mb->hash.fdir.hash, mb->hash.fdir.id);
130                 }
131                 if (ol_flags & PKT_RX_TIMESTAMP)
132                         printf(" - timestamp %"PRIu64" ", mb->timestamp);
133                 if (ol_flags & PKT_RX_VLAN_STRIPPED)
134                         printf(" - VLAN tci=0x%x", mb->vlan_tci);
135                 if (ol_flags & PKT_RX_QINQ_STRIPPED)
136                         printf(" - QinQ VLAN tci=0x%x, VLAN tci outer=0x%x",
137                                         mb->vlan_tci, mb->vlan_tci_outer);
138                 if (mb->packet_type) {
139                         rte_get_ptype_name(mb->packet_type, buf, sizeof(buf));
140                         printf(" - hw ptype: %s", buf);
141                 }
142                 sw_packet_type = rte_net_get_ptype(mb, &hdr_lens,
143                         RTE_PTYPE_ALL_MASK);
144                 rte_get_ptype_name(sw_packet_type, buf, sizeof(buf));
145                 printf(" - sw ptype: %s", buf);
146                 if (sw_packet_type & RTE_PTYPE_L2_MASK)
147                         printf(" - l2_len=%d", hdr_lens.l2_len);
148                 if (sw_packet_type & RTE_PTYPE_L3_MASK)
149                         printf(" - l3_len=%d", hdr_lens.l3_len);
150                 if (sw_packet_type & RTE_PTYPE_L4_MASK)
151                         printf(" - l4_len=%d", hdr_lens.l4_len);
152                 if (sw_packet_type & RTE_PTYPE_TUNNEL_MASK)
153                         printf(" - tunnel_len=%d", hdr_lens.tunnel_len);
154                 if (sw_packet_type & RTE_PTYPE_INNER_L2_MASK)
155                         printf(" - inner_l2_len=%d", hdr_lens.inner_l2_len);
156                 if (sw_packet_type & RTE_PTYPE_INNER_L3_MASK)
157                         printf(" - inner_l3_len=%d", hdr_lens.inner_l3_len);
158                 if (sw_packet_type & RTE_PTYPE_INNER_L4_MASK)
159                         printf(" - inner_l4_len=%d", hdr_lens.inner_l4_len);
160                 if (is_encapsulation) {
161                         struct ipv4_hdr *ipv4_hdr;
162                         struct ipv6_hdr *ipv6_hdr;
163                         struct udp_hdr *udp_hdr;
164                         uint8_t l2_len;
165                         uint8_t l3_len;
166                         uint8_t l4_len;
167                         uint8_t l4_proto;
168                         struct  vxlan_hdr *vxlan_hdr;
169
170                         l2_len  = sizeof(struct ether_hdr);
171
172                          /* Do not support ipv4 option field */
173                         if (RTE_ETH_IS_IPV4_HDR(packet_type)) {
174                                 l3_len = sizeof(struct ipv4_hdr);
175                                 ipv4_hdr = rte_pktmbuf_mtod_offset(mb,
176                                                                    struct ipv4_hdr *,
177                                                                    l2_len);
178                                 l4_proto = ipv4_hdr->next_proto_id;
179                         } else {
180                                 l3_len = sizeof(struct ipv6_hdr);
181                                 ipv6_hdr = rte_pktmbuf_mtod_offset(mb,
182                                                                    struct ipv6_hdr *,
183                                                                    l2_len);
184                                 l4_proto = ipv6_hdr->proto;
185                         }
186                         if (l4_proto == IPPROTO_UDP) {
187                                 udp_hdr = rte_pktmbuf_mtod_offset(mb,
188                                                                   struct udp_hdr *,
189                                                                   l2_len + l3_len);
190                                 l4_len = sizeof(struct udp_hdr);
191                                 vxlan_hdr = rte_pktmbuf_mtod_offset(mb,
192                                                                     struct vxlan_hdr *,
193                                                                     l2_len + l3_len + l4_len);
194
195                                 printf(" - VXLAN packet: packet type =%d, "
196                                         "Destination UDP port =%d, VNI = %d",
197                                         packet_type, RTE_BE_TO_CPU_16(udp_hdr->dst_port),
198                                         rte_be_to_cpu_32(vxlan_hdr->vx_vni) >> 8);
199                         }
200                 }
201                 printf(" - Receive queue=0x%x", (unsigned) fs->rx_queue);
202                 printf("\n");
203                 rte_get_rx_ol_flag_list(mb->ol_flags, buf, sizeof(buf));
204                 printf("  ol_flags: %s\n", buf);
205                 rte_pktmbuf_free(mb);
206         }
207
208 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
209         end_tsc = rte_rdtsc();
210         core_cycles = (end_tsc - start_tsc);
211         fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
212 #endif
213 }
214
215 struct fwd_engine rx_only_engine = {
216         .fwd_mode_name  = "rxonly",
217         .port_fwd_begin = NULL,
218         .port_fwd_end   = NULL,
219         .packet_fwd     = pkt_burst_receive,
220 };