app/testpmd: introduce vxlan parsing function in csum fwd engine
[dpdk.git] / app / test-pmd / csumonly.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   Copyright 2014 6WIND S.A.
6  *   All rights reserved.
7  *
8  *   Redistribution and use in source and binary forms, with or without
9  *   modification, are permitted provided that the following conditions
10  *   are met:
11  *
12  *     * Redistributions of source code must retain the above copyright
13  *       notice, this list of conditions and the following disclaimer.
14  *     * Redistributions in binary form must reproduce the above copyright
15  *       notice, this list of conditions and the following disclaimer in
16  *       the documentation and/or other materials provided with the
17  *       distribution.
18  *     * Neither the name of Intel Corporation nor the names of its
19  *       contributors may be used to endorse or promote products derived
20  *       from this software without specific prior written permission.
21  *
22  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  */
34
35 #include <stdarg.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_memcpy.h>
65 #include <rte_interrupts.h>
66 #include <rte_pci.h>
67 #include <rte_ether.h>
68 #include <rte_ethdev.h>
69 #include <rte_ip.h>
70 #include <rte_tcp.h>
71 #include <rte_udp.h>
72 #include <rte_sctp.h>
73 #include <rte_prefetch.h>
74 #include <rte_string_fns.h>
75 #include "testpmd.h"
76
77 #define IP_DEFTTL  64   /* from RFC 1340. */
78 #define IP_VERSION 0x40
79 #define IP_HDRLEN  0x05 /* default IP header length == five 32-bits words. */
80 #define IP_VHL_DEF (IP_VERSION | IP_HDRLEN)
81
82 /* We cannot use rte_cpu_to_be_16() on a constant in a switch/case */
83 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
84 #define _htons(x) ((uint16_t)((((x) & 0x00ffU) << 8) | (((x) & 0xff00U) >> 8)))
85 #else
86 #define _htons(x) (x)
87 #endif
88
89 /* structure that caches offload info for the current packet */
90 struct testpmd_offload_info {
91         uint16_t ethertype;
92         uint16_t l2_len;
93         uint16_t l3_len;
94         uint16_t l4_len;
95         uint8_t l4_proto;
96         uint8_t is_tunnel;
97         uint16_t outer_ethertype;
98         uint16_t outer_l2_len;
99         uint16_t outer_l3_len;
100         uint16_t tso_segsz;
101 };
102
103 static uint16_t
104 get_psd_sum(void *l3_hdr, uint16_t ethertype, uint64_t ol_flags)
105 {
106         if (ethertype == _htons(ETHER_TYPE_IPv4))
107                 return rte_ipv4_phdr_cksum(l3_hdr, ol_flags);
108         else /* assume ethertype == ETHER_TYPE_IPv6 */
109                 return rte_ipv6_phdr_cksum(l3_hdr, ol_flags);
110 }
111
112 static uint16_t
113 get_udptcp_checksum(void *l3_hdr, void *l4_hdr, uint16_t ethertype)
114 {
115         if (ethertype == _htons(ETHER_TYPE_IPv4))
116                 return rte_ipv4_udptcp_cksum(l3_hdr, l4_hdr);
117         else /* assume ethertype == ETHER_TYPE_IPv6 */
118                 return rte_ipv6_udptcp_cksum(l3_hdr, l4_hdr);
119 }
120
121 /* Parse an IPv4 header to fill l3_len, l4_len, and l4_proto */
122 static void
123 parse_ipv4(struct ipv4_hdr *ipv4_hdr, struct testpmd_offload_info *info)
124 {
125         struct tcp_hdr *tcp_hdr;
126
127         info->l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4;
128         info->l4_proto = ipv4_hdr->next_proto_id;
129
130         /* only fill l4_len for TCP, it's useful for TSO */
131         if (info->l4_proto == IPPROTO_TCP) {
132                 tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + info->l3_len);
133                 info->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
134         } else
135                 info->l4_len = 0;
136 }
137
138 /* Parse an IPv6 header to fill l3_len, l4_len, and l4_proto */
139 static void
140 parse_ipv6(struct ipv6_hdr *ipv6_hdr, struct testpmd_offload_info *info)
141 {
142         struct tcp_hdr *tcp_hdr;
143
144         info->l3_len = sizeof(struct ipv6_hdr);
145         info->l4_proto = ipv6_hdr->proto;
146
147         /* only fill l4_len for TCP, it's useful for TSO */
148         if (info->l4_proto == IPPROTO_TCP) {
149                 tcp_hdr = (struct tcp_hdr *)((char *)ipv6_hdr + info->l3_len);
150                 info->l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
151         } else
152                 info->l4_len = 0;
153 }
154
155 /*
156  * Parse an ethernet header to fill the ethertype, l2_len, l3_len and
157  * ipproto. This function is able to recognize IPv4/IPv6 with one optional vlan
158  * header. The l4_len argument is only set in case of TCP (useful for TSO).
159  */
160 static void
161 parse_ethernet(struct ether_hdr *eth_hdr, struct testpmd_offload_info *info)
162 {
163         struct ipv4_hdr *ipv4_hdr;
164         struct ipv6_hdr *ipv6_hdr;
165
166         info->l2_len = sizeof(struct ether_hdr);
167         info->ethertype = eth_hdr->ether_type;
168
169         if (info->ethertype == _htons(ETHER_TYPE_VLAN)) {
170                 struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
171
172                 info->l2_len  += sizeof(struct vlan_hdr);
173                 info->ethertype = vlan_hdr->eth_proto;
174         }
175
176         switch (info->ethertype) {
177         case _htons(ETHER_TYPE_IPv4):
178                 ipv4_hdr = (struct ipv4_hdr *) ((char *)eth_hdr + info->l2_len);
179                 parse_ipv4(ipv4_hdr, info);
180                 break;
181         case _htons(ETHER_TYPE_IPv6):
182                 ipv6_hdr = (struct ipv6_hdr *) ((char *)eth_hdr + info->l2_len);
183                 parse_ipv6(ipv6_hdr, info);
184                 break;
185         default:
186                 info->l4_len = 0;
187                 info->l3_len = 0;
188                 info->l4_proto = 0;
189                 break;
190         }
191 }
192
193 /* Parse a vxlan header */
194 static void
195 parse_vxlan(struct udp_hdr *udp_hdr, struct testpmd_offload_info *info,
196         uint64_t mbuf_olflags)
197 {
198         struct ether_hdr *eth_hdr;
199
200         /* check udp destination port, 4789 is the default vxlan port
201          * (rfc7348) or that the rx offload flag is set (i40e only
202          * currently) */
203         if (udp_hdr->dst_port != _htons(4789) &&
204                 (mbuf_olflags & (PKT_RX_TUNNEL_IPV4_HDR |
205                         PKT_RX_TUNNEL_IPV6_HDR)) == 0)
206                 return;
207
208         info->is_tunnel = 1;
209         info->outer_ethertype = info->ethertype;
210         info->outer_l2_len = info->l2_len;
211         info->outer_l3_len = info->l3_len;
212
213         eth_hdr = (struct ether_hdr *)((char *)udp_hdr +
214                 sizeof(struct udp_hdr) +
215                 sizeof(struct vxlan_hdr));
216
217         parse_ethernet(eth_hdr, info);
218         info->l2_len += ETHER_VXLAN_HLEN; /* add udp + vxlan */
219 }
220
221 /* modify the IPv4 or IPv4 source address of a packet */
222 static void
223 change_ip_addresses(void *l3_hdr, uint16_t ethertype)
224 {
225         struct ipv4_hdr *ipv4_hdr = l3_hdr;
226         struct ipv6_hdr *ipv6_hdr = l3_hdr;
227
228         if (ethertype == _htons(ETHER_TYPE_IPv4)) {
229                 ipv4_hdr->src_addr =
230                         rte_cpu_to_be_32(rte_be_to_cpu_32(ipv4_hdr->src_addr) + 1);
231         } else if (ethertype == _htons(ETHER_TYPE_IPv6)) {
232                 ipv6_hdr->src_addr[15] = ipv6_hdr->src_addr[15] + 1;
233         }
234 }
235
236 /* if possible, calculate the checksum of a packet in hw or sw,
237  * depending on the testpmd command line configuration */
238 static uint64_t
239 process_inner_cksums(void *l3_hdr, const struct testpmd_offload_info *info,
240         uint16_t testpmd_ol_flags)
241 {
242         struct ipv4_hdr *ipv4_hdr = l3_hdr;
243         struct udp_hdr *udp_hdr;
244         struct tcp_hdr *tcp_hdr;
245         struct sctp_hdr *sctp_hdr;
246         uint64_t ol_flags = 0;
247
248         if (info->ethertype == _htons(ETHER_TYPE_IPv4)) {
249                 ipv4_hdr = l3_hdr;
250                 ipv4_hdr->hdr_checksum = 0;
251
252                 ol_flags |= PKT_TX_IPV4;
253                 if (info->tso_segsz != 0 && info->l4_proto == IPPROTO_TCP) {
254                         ol_flags |= PKT_TX_IP_CKSUM;
255                 } else {
256                         if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
257                                 ol_flags |= PKT_TX_IP_CKSUM;
258                         else
259                                 ipv4_hdr->hdr_checksum =
260                                         rte_ipv4_cksum(ipv4_hdr);
261                 }
262         } else if (info->ethertype == _htons(ETHER_TYPE_IPv6))
263                 ol_flags |= PKT_TX_IPV6;
264         else
265                 return 0; /* packet type not supported, nothing to do */
266
267         if (info->l4_proto == IPPROTO_UDP) {
268                 udp_hdr = (struct udp_hdr *)((char *)l3_hdr + info->l3_len);
269                 /* do not recalculate udp cksum if it was 0 */
270                 if (udp_hdr->dgram_cksum != 0) {
271                         udp_hdr->dgram_cksum = 0;
272                         if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) {
273                                 ol_flags |= PKT_TX_UDP_CKSUM;
274                                 udp_hdr->dgram_cksum = get_psd_sum(l3_hdr,
275                                         info->ethertype, ol_flags);
276                         } else {
277                                 udp_hdr->dgram_cksum =
278                                         get_udptcp_checksum(l3_hdr, udp_hdr,
279                                                 info->ethertype);
280                         }
281                 }
282         } else if (info->l4_proto == IPPROTO_TCP) {
283                 tcp_hdr = (struct tcp_hdr *)((char *)l3_hdr + info->l3_len);
284                 tcp_hdr->cksum = 0;
285                 if (info->tso_segsz != 0) {
286                         ol_flags |= PKT_TX_TCP_SEG;
287                         tcp_hdr->cksum = get_psd_sum(l3_hdr, info->ethertype,
288                                 ol_flags);
289                 } else if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) {
290                         ol_flags |= PKT_TX_TCP_CKSUM;
291                         tcp_hdr->cksum = get_psd_sum(l3_hdr, info->ethertype,
292                                 ol_flags);
293                 } else {
294                         tcp_hdr->cksum =
295                                 get_udptcp_checksum(l3_hdr, tcp_hdr,
296                                         info->ethertype);
297                 }
298         } else if (info->l4_proto == IPPROTO_SCTP) {
299                 sctp_hdr = (struct sctp_hdr *)((char *)l3_hdr + info->l3_len);
300                 sctp_hdr->cksum = 0;
301                 /* sctp payload must be a multiple of 4 to be
302                  * offloaded */
303                 if ((testpmd_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
304                         ((ipv4_hdr->total_length & 0x3) == 0)) {
305                         ol_flags |= PKT_TX_SCTP_CKSUM;
306                 } else {
307                         /* XXX implement CRC32c, example available in
308                          * RFC3309 */
309                 }
310         }
311
312         return ol_flags;
313 }
314
315 /* Calculate the checksum of outer header (only vxlan is supported,
316  * meaning IP + UDP). The caller already checked that it's a vxlan
317  * packet */
318 static uint64_t
319 process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info,
320 uint16_t testpmd_ol_flags)
321 {
322         struct ipv4_hdr *ipv4_hdr = outer_l3_hdr;
323         struct ipv6_hdr *ipv6_hdr = outer_l3_hdr;
324         struct udp_hdr *udp_hdr;
325         uint64_t ol_flags = 0;
326
327         if (info->outer_ethertype == _htons(ETHER_TYPE_IPv4)) {
328                 ipv4_hdr->hdr_checksum = 0;
329                 ol_flags |= PKT_TX_OUTER_IPV4;
330
331                 if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
332                         ol_flags |= PKT_TX_OUTER_IP_CKSUM;
333                 else
334                         ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
335         } else if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
336                 ol_flags |= PKT_TX_OUTER_IPV6;
337
338         /* outer UDP checksum is always done in software as we have no
339          * hardware supporting it today, and no API for it. */
340
341         udp_hdr = (struct udp_hdr *)((char *)outer_l3_hdr + info->outer_l3_len);
342         /* do not recalculate udp cksum if it was 0 */
343         if (udp_hdr->dgram_cksum != 0) {
344                 udp_hdr->dgram_cksum = 0;
345                 if (info->outer_ethertype == _htons(ETHER_TYPE_IPv4))
346                         udp_hdr->dgram_cksum =
347                                 rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr);
348                 else
349                         udp_hdr->dgram_cksum =
350                                 rte_ipv6_udptcp_cksum(ipv6_hdr, udp_hdr);
351         }
352
353         return ol_flags;
354 }
355
356 /*
357  * Receive a burst of packets, and for each packet:
358  *  - parse packet, and try to recognize a supported packet type (1)
359  *  - if it's not a supported packet type, don't touch the packet, else:
360  *  - modify the IPs in inner headers and in outer headers if any
361  *  - reprocess the checksum of all supported layers. This is done in SW
362  *    or HW, depending on testpmd command line configuration
363  *  - if TSO is enabled in testpmd command line, also flag the mbuf for TCP
364  *    segmentation offload (this implies HW TCP checksum)
365  * Then transmit packets on the output port.
366  *
367  * (1) Supported packets are:
368  *   Ether / (vlan) / IP|IP6 / UDP|TCP|SCTP .
369  *   Ether / (vlan) / outer IP|IP6 / outer UDP / VxLAN / Ether / IP|IP6 /
370  *           UDP|TCP|SCTP
371  *
372  * The testpmd command line for this forward engine sets the flags
373  * TESTPMD_TX_OFFLOAD_* in ports[tx_port].tx_ol_flags. They control
374  * wether a checksum must be calculated in software or in hardware. The
375  * IP, UDP, TCP and SCTP flags always concern the inner layer. The
376  * OUTER_IP is only useful for tunnel packets.
377  */
378 static void
379 pkt_burst_checksum_forward(struct fwd_stream *fs)
380 {
381         struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
382         struct rte_port *txp;
383         struct rte_mbuf *m;
384         struct ether_hdr *eth_hdr;
385         void *l3_hdr = NULL, *outer_l3_hdr = NULL; /* can be IPv4 or IPv6 */
386         uint16_t nb_rx;
387         uint16_t nb_tx;
388         uint16_t i;
389         uint64_t ol_flags;
390         uint16_t testpmd_ol_flags;
391         uint32_t rx_bad_ip_csum;
392         uint32_t rx_bad_l4_csum;
393         struct testpmd_offload_info info;
394
395 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
396         uint64_t start_tsc;
397         uint64_t end_tsc;
398         uint64_t core_cycles;
399 #endif
400
401 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
402         start_tsc = rte_rdtsc();
403 #endif
404
405         /* receive a burst of packet */
406         nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
407                                  nb_pkt_per_burst);
408         if (unlikely(nb_rx == 0))
409                 return;
410
411 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
412         fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
413 #endif
414         fs->rx_packets += nb_rx;
415         rx_bad_ip_csum = 0;
416         rx_bad_l4_csum = 0;
417
418         txp = &ports[fs->tx_port];
419         testpmd_ol_flags = txp->tx_ol_flags;
420         memset(&info, 0, sizeof(info));
421         info.tso_segsz = txp->tso_segsz;
422
423         for (i = 0; i < nb_rx; i++) {
424
425                 ol_flags = 0;
426                 info.is_tunnel = 0;
427                 m = pkts_burst[i];
428
429                 /* Update the L3/L4 checksum error packet statistics */
430                 rx_bad_ip_csum += ((m->ol_flags & PKT_RX_IP_CKSUM_BAD) != 0);
431                 rx_bad_l4_csum += ((m->ol_flags & PKT_RX_L4_CKSUM_BAD) != 0);
432
433                 /* step 1: dissect packet, parsing optional vlan, ip4/ip6, vxlan
434                  * and inner headers */
435
436                 eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
437                 parse_ethernet(eth_hdr, &info);
438                 l3_hdr = (char *)eth_hdr + info.l2_len;
439
440                 /* check if it's a supported tunnel (only vxlan for now) */
441                 if ((testpmd_ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) &&
442                         info.l4_proto == IPPROTO_UDP) {
443                         struct udp_hdr *udp_hdr;
444                         udp_hdr = (struct udp_hdr *)((char *)l3_hdr + info.l3_len);
445                         parse_vxlan(udp_hdr, &info, m->ol_flags);
446                 }
447
448                 /* update l3_hdr and outer_l3_hdr if a tunnel was parsed */
449                 if (info.is_tunnel) {
450                         outer_l3_hdr = l3_hdr;
451                         l3_hdr = (char *)l3_hdr + info.outer_l3_len + info.l2_len;
452                 }
453
454                 /* step 2: change all source IPs (v4 or v6) so we need
455                  * to recompute the chksums even if they were correct */
456
457                 change_ip_addresses(l3_hdr, info.ethertype);
458                 if (info.is_tunnel == 1)
459                         change_ip_addresses(outer_l3_hdr, info.outer_ethertype);
460
461                 /* step 3: depending on user command line configuration,
462                  * recompute checksum either in software or flag the
463                  * mbuf to offload the calculation to the NIC. If TSO
464                  * is configured, prepare the mbuf for TCP segmentation. */
465
466                 /* process checksums of inner headers first */
467                 ol_flags |= process_inner_cksums(l3_hdr, &info, testpmd_ol_flags);
468
469                 /* Then process outer headers if any. Note that the software
470                  * checksum will be wrong if one of the inner checksums is
471                  * processed in hardware. */
472                 if (info.is_tunnel == 1) {
473                         ol_flags |= process_outer_cksums(outer_l3_hdr, &info,
474                                 testpmd_ol_flags);
475                 }
476
477                 /* step 4: fill the mbuf meta data (flags and header lengths) */
478
479                 if (info.is_tunnel == 1) {
480                         if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) {
481                                 m->outer_l2_len = info.outer_l2_len;
482                                 m->outer_l3_len = info.outer_l3_len;
483                                 m->l2_len = info.l2_len;
484                                 m->l3_len = info.l3_len;
485                         }
486                         else {
487                                 /* if there is a outer UDP cksum
488                                    processed in sw and the inner in hw,
489                                    the outer checksum will be wrong as
490                                    the payload will be modified by the
491                                    hardware */
492                                 m->l2_len = info.outer_l2_len +
493                                         info.outer_l3_len + info.l2_len;
494                                 m->l3_len = info.l3_len;
495                                 m->l4_len = info.l4_len;
496                         }
497                 } else {
498                         /* this is only useful if an offload flag is
499                          * set, but it does not hurt to fill it in any
500                          * case */
501                         m->l2_len = info.l2_len;
502                         m->l3_len = info.l3_len;
503                         m->l4_len = info.l4_len;
504                 }
505                 m->tso_segsz = info.tso_segsz;
506                 m->ol_flags = ol_flags;
507
508                 /* if verbose mode is enabled, dump debug info */
509                 if (verbose_level > 0) {
510                         struct {
511                                 uint64_t flag;
512                                 uint64_t mask;
513                         } tx_flags[] = {
514                                 { PKT_TX_IP_CKSUM, PKT_TX_IP_CKSUM },
515                                 { PKT_TX_UDP_CKSUM, PKT_TX_L4_MASK },
516                                 { PKT_TX_TCP_CKSUM, PKT_TX_L4_MASK },
517                                 { PKT_TX_SCTP_CKSUM, PKT_TX_L4_MASK },
518                                 { PKT_TX_IPV4, PKT_TX_IPV4 },
519                                 { PKT_TX_IPV6, PKT_TX_IPV6 },
520                                 { PKT_TX_OUTER_IP_CKSUM, PKT_TX_OUTER_IP_CKSUM },
521                                 { PKT_TX_OUTER_IPV4, PKT_TX_OUTER_IPV4 },
522                                 { PKT_TX_OUTER_IPV6, PKT_TX_OUTER_IPV6 },
523                                 { PKT_TX_TCP_SEG, PKT_TX_TCP_SEG },
524                         };
525                         unsigned j;
526                         const char *name;
527
528                         printf("-----------------\n");
529                         /* dump rx parsed packet info */
530                         printf("rx: l2_len=%d ethertype=%x l3_len=%d "
531                                 "l4_proto=%d l4_len=%d\n",
532                                 info.l2_len, rte_be_to_cpu_16(info.ethertype),
533                                 info.l3_len, info.l4_proto, info.l4_len);
534                         if (info.is_tunnel == 1)
535                                 printf("rx: outer_l2_len=%d outer_ethertype=%x "
536                                         "outer_l3_len=%d\n", info.outer_l2_len,
537                                         rte_be_to_cpu_16(info.outer_ethertype),
538                                         info.outer_l3_len);
539                         /* dump tx packet info */
540                         if ((testpmd_ol_flags & (TESTPMD_TX_OFFLOAD_IP_CKSUM |
541                                                 TESTPMD_TX_OFFLOAD_UDP_CKSUM |
542                                                 TESTPMD_TX_OFFLOAD_TCP_CKSUM |
543                                                 TESTPMD_TX_OFFLOAD_SCTP_CKSUM)) ||
544                                 info.tso_segsz != 0)
545                                 printf("tx: m->l2_len=%d m->l3_len=%d "
546                                         "m->l4_len=%d\n",
547                                         m->l2_len, m->l3_len, m->l4_len);
548                         if ((info.is_tunnel == 1) &&
549                                 (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
550                                 printf("tx: m->outer_l2_len=%d m->outer_l3_len=%d\n",
551                                         m->outer_l2_len, m->outer_l3_len);
552                         if (info.tso_segsz != 0)
553                                 printf("tx: m->tso_segsz=%d\n", m->tso_segsz);
554                         printf("tx: flags=");
555                         for (j = 0; j < sizeof(tx_flags)/sizeof(*tx_flags); j++) {
556                                 name = rte_get_tx_ol_flag_name(tx_flags[j].flag);
557                                 if ((m->ol_flags & tx_flags[j].mask) ==
558                                         tx_flags[j].flag)
559                                         printf("%s ", name);
560                         }
561                         printf("\n");
562                 }
563         }
564         nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
565         fs->tx_packets += nb_tx;
566         fs->rx_bad_ip_csum += rx_bad_ip_csum;
567         fs->rx_bad_l4_csum += rx_bad_l4_csum;
568
569 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
570         fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
571 #endif
572         if (unlikely(nb_tx < nb_rx)) {
573                 fs->fwd_dropped += (nb_rx - nb_tx);
574                 do {
575                         rte_pktmbuf_free(pkts_burst[nb_tx]);
576                 } while (++nb_tx < nb_rx);
577         }
578 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
579         end_tsc = rte_rdtsc();
580         core_cycles = (end_tsc - start_tsc);
581         fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
582 #endif
583 }
584
585 struct fwd_engine csum_fwd_engine = {
586         .fwd_mode_name  = "csum",
587         .port_fwd_begin = NULL,
588         .port_fwd_end   = NULL,
589         .packet_fwd     = pkt_burst_checksum_forward,
590 };
591