app/testpmd: introduce IP parsing functions 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 static uint16_t
90 get_psd_sum(void *l3_hdr, uint16_t ethertype, uint64_t ol_flags)
91 {
92         if (ethertype == _htons(ETHER_TYPE_IPv4))
93                 return rte_ipv4_phdr_cksum(l3_hdr, ol_flags);
94         else /* assume ethertype == ETHER_TYPE_IPv6 */
95                 return rte_ipv6_phdr_cksum(l3_hdr, ol_flags);
96 }
97
98 static uint16_t
99 get_udptcp_checksum(void *l3_hdr, void *l4_hdr, uint16_t ethertype)
100 {
101         if (ethertype == _htons(ETHER_TYPE_IPv4))
102                 return rte_ipv4_udptcp_cksum(l3_hdr, l4_hdr);
103         else /* assume ethertype == ETHER_TYPE_IPv6 */
104                 return rte_ipv6_udptcp_cksum(l3_hdr, l4_hdr);
105 }
106
107 /* Parse an IPv4 header to fill l3_len, l4_len, and l4_proto */
108 static void
109 parse_ipv4(struct ipv4_hdr *ipv4_hdr, uint16_t *l3_len, uint8_t *l4_proto,
110         uint16_t *l4_len)
111 {
112         struct tcp_hdr *tcp_hdr;
113
114         *l3_len = (ipv4_hdr->version_ihl & 0x0f) * 4;
115         *l4_proto = ipv4_hdr->next_proto_id;
116
117         /* only fill l4_len for TCP, it's useful for TSO */
118         if (*l4_proto == IPPROTO_TCP) {
119                 tcp_hdr = (struct tcp_hdr *)((char *)ipv4_hdr + *l3_len);
120                 *l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
121         } else
122                 *l4_len = 0;
123 }
124
125 /* Parse an IPv6 header to fill l3_len, l4_len, and l4_proto */
126 static void
127 parse_ipv6(struct ipv6_hdr *ipv6_hdr, uint16_t *l3_len, uint8_t *l4_proto,
128         uint16_t *l4_len)
129 {
130         struct tcp_hdr *tcp_hdr;
131
132         *l3_len = sizeof(struct ipv6_hdr);
133         *l4_proto = ipv6_hdr->proto;
134
135         /* only fill l4_len for TCP, it's useful for TSO */
136         if (*l4_proto == IPPROTO_TCP) {
137                 tcp_hdr = (struct tcp_hdr *)((char *)ipv6_hdr + *l3_len);
138                 *l4_len = (tcp_hdr->data_off & 0xf0) >> 2;
139         } else
140                 *l4_len = 0;
141 }
142
143 /*
144  * Parse an ethernet header to fill the ethertype, l2_len, l3_len and
145  * ipproto. This function is able to recognize IPv4/IPv6 with one optional vlan
146  * header. The l4_len argument is only set in case of TCP (useful for TSO).
147  */
148 static void
149 parse_ethernet(struct ether_hdr *eth_hdr, uint16_t *ethertype, uint16_t *l2_len,
150         uint16_t *l3_len, uint8_t *l4_proto, uint16_t *l4_len)
151 {
152         struct ipv4_hdr *ipv4_hdr;
153         struct ipv6_hdr *ipv6_hdr;
154
155         *l2_len = sizeof(struct ether_hdr);
156         *ethertype = eth_hdr->ether_type;
157
158         if (*ethertype == _htons(ETHER_TYPE_VLAN)) {
159                 struct vlan_hdr *vlan_hdr = (struct vlan_hdr *)(eth_hdr + 1);
160
161                 *l2_len  += sizeof(struct vlan_hdr);
162                 *ethertype = vlan_hdr->eth_proto;
163         }
164
165         switch (*ethertype) {
166         case _htons(ETHER_TYPE_IPv4):
167                 ipv4_hdr = (struct ipv4_hdr *) ((char *)eth_hdr + *l2_len);
168                 parse_ipv4(ipv4_hdr, l3_len, l4_proto, l4_len);
169                 break;
170         case _htons(ETHER_TYPE_IPv6):
171                 ipv6_hdr = (struct ipv6_hdr *) ((char *)eth_hdr + *l2_len);
172                 parse_ipv6(ipv6_hdr, l3_len, l4_proto, l4_len);
173                 break;
174         default:
175                 *l4_len = 0;
176                 *l3_len = 0;
177                 *l4_proto = 0;
178                 break;
179         }
180 }
181
182 /* modify the IPv4 or IPv4 source address of a packet */
183 static void
184 change_ip_addresses(void *l3_hdr, uint16_t ethertype)
185 {
186         struct ipv4_hdr *ipv4_hdr = l3_hdr;
187         struct ipv6_hdr *ipv6_hdr = l3_hdr;
188
189         if (ethertype == _htons(ETHER_TYPE_IPv4)) {
190                 ipv4_hdr->src_addr =
191                         rte_cpu_to_be_32(rte_be_to_cpu_32(ipv4_hdr->src_addr) + 1);
192         } else if (ethertype == _htons(ETHER_TYPE_IPv6)) {
193                 ipv6_hdr->src_addr[15] = ipv6_hdr->src_addr[15] + 1;
194         }
195 }
196
197 /* if possible, calculate the checksum of a packet in hw or sw,
198  * depending on the testpmd command line configuration */
199 static uint64_t
200 process_inner_cksums(void *l3_hdr, uint16_t ethertype, uint16_t l3_len,
201         uint8_t l4_proto, uint16_t tso_segsz, uint16_t testpmd_ol_flags)
202 {
203         struct ipv4_hdr *ipv4_hdr = l3_hdr;
204         struct udp_hdr *udp_hdr;
205         struct tcp_hdr *tcp_hdr;
206         struct sctp_hdr *sctp_hdr;
207         uint64_t ol_flags = 0;
208
209         if (ethertype == _htons(ETHER_TYPE_IPv4)) {
210                 ipv4_hdr = l3_hdr;
211                 ipv4_hdr->hdr_checksum = 0;
212
213                 ol_flags |= PKT_TX_IPV4;
214                 if (tso_segsz != 0 && l4_proto == IPPROTO_TCP) {
215                         ol_flags |= PKT_TX_IP_CKSUM;
216                 } else {
217                         if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_IP_CKSUM)
218                                 ol_flags |= PKT_TX_IP_CKSUM;
219                         else
220                                 ipv4_hdr->hdr_checksum =
221                                         rte_ipv4_cksum(ipv4_hdr);
222                 }
223         } else if (ethertype == _htons(ETHER_TYPE_IPv6))
224                 ol_flags |= PKT_TX_IPV6;
225         else
226                 return 0; /* packet type not supported, nothing to do */
227
228         if (l4_proto == IPPROTO_UDP) {
229                 udp_hdr = (struct udp_hdr *)((char *)l3_hdr + l3_len);
230                 /* do not recalculate udp cksum if it was 0 */
231                 if (udp_hdr->dgram_cksum != 0) {
232                         udp_hdr->dgram_cksum = 0;
233                         if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_UDP_CKSUM) {
234                                 ol_flags |= PKT_TX_UDP_CKSUM;
235                                 udp_hdr->dgram_cksum = get_psd_sum(l3_hdr,
236                                         ethertype, ol_flags);
237                         } else {
238                                 udp_hdr->dgram_cksum =
239                                         get_udptcp_checksum(l3_hdr, udp_hdr,
240                                                 ethertype);
241                         }
242                 }
243         } else if (l4_proto == IPPROTO_TCP) {
244                 tcp_hdr = (struct tcp_hdr *)((char *)l3_hdr + l3_len);
245                 tcp_hdr->cksum = 0;
246                 if (tso_segsz != 0) {
247                         ol_flags |= PKT_TX_TCP_SEG;
248                         tcp_hdr->cksum = get_psd_sum(l3_hdr, ethertype, ol_flags);
249                 } else if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_TCP_CKSUM) {
250                         ol_flags |= PKT_TX_TCP_CKSUM;
251                         tcp_hdr->cksum = get_psd_sum(l3_hdr, ethertype, ol_flags);
252                 } else {
253                         tcp_hdr->cksum =
254                                 get_udptcp_checksum(l3_hdr, tcp_hdr, ethertype);
255                 }
256         } else if (l4_proto == IPPROTO_SCTP) {
257                 sctp_hdr = (struct sctp_hdr *)((char *)l3_hdr + l3_len);
258                 sctp_hdr->cksum = 0;
259                 /* sctp payload must be a multiple of 4 to be
260                  * offloaded */
261                 if ((testpmd_ol_flags & TESTPMD_TX_OFFLOAD_SCTP_CKSUM) &&
262                         ((ipv4_hdr->total_length & 0x3) == 0)) {
263                         ol_flags |= PKT_TX_SCTP_CKSUM;
264                 } else {
265                         /* XXX implement CRC32c, example available in
266                          * RFC3309 */
267                 }
268         }
269
270         return ol_flags;
271 }
272
273 /* Calculate the checksum of outer header (only vxlan is supported,
274  * meaning IP + UDP). The caller already checked that it's a vxlan
275  * packet */
276 static uint64_t
277 process_outer_cksums(void *outer_l3_hdr, uint16_t outer_ethertype,
278         uint16_t outer_l3_len, uint16_t testpmd_ol_flags)
279 {
280         struct ipv4_hdr *ipv4_hdr = outer_l3_hdr;
281         struct ipv6_hdr *ipv6_hdr = outer_l3_hdr;
282         struct udp_hdr *udp_hdr;
283         uint64_t ol_flags = 0;
284
285         if (outer_ethertype == _htons(ETHER_TYPE_IPv4)) {
286                 ipv4_hdr->hdr_checksum = 0;
287                 ol_flags |= PKT_TX_OUTER_IPV4;
288
289                 if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
290                         ol_flags |= PKT_TX_OUTER_IP_CKSUM;
291                 else
292                         ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr);
293         } else if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM)
294                 ol_flags |= PKT_TX_OUTER_IPV6;
295
296         /* outer UDP checksum is always done in software as we have no
297          * hardware supporting it today, and no API for it. */
298
299         udp_hdr = (struct udp_hdr *)((char *)outer_l3_hdr + outer_l3_len);
300         /* do not recalculate udp cksum if it was 0 */
301         if (udp_hdr->dgram_cksum != 0) {
302                 udp_hdr->dgram_cksum = 0;
303                 if (outer_ethertype == _htons(ETHER_TYPE_IPv4))
304                         udp_hdr->dgram_cksum =
305                                 rte_ipv4_udptcp_cksum(ipv4_hdr, udp_hdr);
306                 else
307                         udp_hdr->dgram_cksum =
308                                 rte_ipv6_udptcp_cksum(ipv6_hdr, udp_hdr);
309         }
310
311         return ol_flags;
312 }
313
314 /*
315  * Receive a burst of packets, and for each packet:
316  *  - parse packet, and try to recognize a supported packet type (1)
317  *  - if it's not a supported packet type, don't touch the packet, else:
318  *  - modify the IPs in inner headers and in outer headers if any
319  *  - reprocess the checksum of all supported layers. This is done in SW
320  *    or HW, depending on testpmd command line configuration
321  *  - if TSO is enabled in testpmd command line, also flag the mbuf for TCP
322  *    segmentation offload (this implies HW TCP checksum)
323  * Then transmit packets on the output port.
324  *
325  * (1) Supported packets are:
326  *   Ether / (vlan) / IP|IP6 / UDP|TCP|SCTP .
327  *   Ether / (vlan) / outer IP|IP6 / outer UDP / VxLAN / Ether / IP|IP6 /
328  *           UDP|TCP|SCTP
329  *
330  * The testpmd command line for this forward engine sets the flags
331  * TESTPMD_TX_OFFLOAD_* in ports[tx_port].tx_ol_flags. They control
332  * wether a checksum must be calculated in software or in hardware. The
333  * IP, UDP, TCP and SCTP flags always concern the inner layer. The
334  * OUTER_IP is only useful for tunnel packets.
335  */
336 static void
337 pkt_burst_checksum_forward(struct fwd_stream *fs)
338 {
339         struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
340         struct rte_port *txp;
341         struct rte_mbuf *m;
342         struct ether_hdr *eth_hdr;
343         void *l3_hdr = NULL, *outer_l3_hdr = NULL; /* can be IPv4 or IPv6 */
344         struct udp_hdr *udp_hdr;
345         uint16_t nb_rx;
346         uint16_t nb_tx;
347         uint16_t i;
348         uint64_t ol_flags;
349         uint16_t testpmd_ol_flags;
350         uint8_t l4_proto, l4_tun_len = 0;
351         uint16_t ethertype = 0, outer_ethertype = 0;
352         uint16_t l2_len = 0, l3_len = 0, l4_len = 0;
353         uint16_t outer_l2_len = 0, outer_l3_len = 0;
354         uint16_t tso_segsz;
355         int tunnel = 0;
356         uint32_t rx_bad_ip_csum;
357         uint32_t rx_bad_l4_csum;
358
359 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
360         uint64_t start_tsc;
361         uint64_t end_tsc;
362         uint64_t core_cycles;
363 #endif
364
365 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
366         start_tsc = rte_rdtsc();
367 #endif
368
369         /* receive a burst of packet */
370         nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
371                                  nb_pkt_per_burst);
372         if (unlikely(nb_rx == 0))
373                 return;
374
375 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
376         fs->rx_burst_stats.pkt_burst_spread[nb_rx]++;
377 #endif
378         fs->rx_packets += nb_rx;
379         rx_bad_ip_csum = 0;
380         rx_bad_l4_csum = 0;
381
382         txp = &ports[fs->tx_port];
383         testpmd_ol_flags = txp->tx_ol_flags;
384         tso_segsz = txp->tso_segsz;
385
386         for (i = 0; i < nb_rx; i++) {
387
388                 ol_flags = 0;
389                 tunnel = 0;
390                 l4_tun_len = 0;
391                 m = pkts_burst[i];
392
393                 /* Update the L3/L4 checksum error packet statistics */
394                 rx_bad_ip_csum += ((m->ol_flags & PKT_RX_IP_CKSUM_BAD) != 0);
395                 rx_bad_l4_csum += ((m->ol_flags & PKT_RX_L4_CKSUM_BAD) != 0);
396
397                 /* step 1: dissect packet, parsing optional vlan, ip4/ip6, vxlan
398                  * and inner headers */
399
400                 eth_hdr = rte_pktmbuf_mtod(m, struct ether_hdr *);
401                 parse_ethernet(eth_hdr, &ethertype, &l2_len, &l3_len,
402                         &l4_proto, &l4_len);
403                 l3_hdr = (char *)eth_hdr + l2_len;
404
405                 /* check if it's a supported tunnel (only vxlan for now) */
406                 if ((testpmd_ol_flags & TESTPMD_TX_OFFLOAD_PARSE_TUNNEL) &&
407                         l4_proto == IPPROTO_UDP) {
408                         udp_hdr = (struct udp_hdr *)((char *)l3_hdr + l3_len);
409
410                         /* check udp destination port, 4789 is the default
411                          * vxlan port (rfc7348) */
412                         if (udp_hdr->dst_port == _htons(4789)) {
413                                 l4_tun_len = ETHER_VXLAN_HLEN;
414                                 tunnel = 1;
415
416                         /* currently, this flag is set by i40e only if the
417                          * packet is vxlan */
418                         } else if (m->ol_flags & (PKT_RX_TUNNEL_IPV4_HDR |
419                                         PKT_RX_TUNNEL_IPV6_HDR))
420                                 tunnel = 1;
421
422                         if (tunnel == 1) {
423                                 outer_ethertype = ethertype;
424                                 outer_l2_len = l2_len;
425                                 outer_l3_len = l3_len;
426                                 outer_l3_hdr = l3_hdr;
427
428                                 eth_hdr = (struct ether_hdr *)((char *)udp_hdr +
429                                         sizeof(struct udp_hdr) +
430                                         sizeof(struct vxlan_hdr));
431
432                                 parse_ethernet(eth_hdr, &ethertype, &l2_len,
433                                         &l3_len, &l4_proto, &l4_len);
434                                 l3_hdr = (char *)eth_hdr + l2_len;
435                         }
436                 }
437
438                 /* step 2: change all source IPs (v4 or v6) so we need
439                  * to recompute the chksums even if they were correct */
440
441                 change_ip_addresses(l3_hdr, ethertype);
442                 if (tunnel == 1)
443                         change_ip_addresses(outer_l3_hdr, outer_ethertype);
444
445                 /* step 3: depending on user command line configuration,
446                  * recompute checksum either in software or flag the
447                  * mbuf to offload the calculation to the NIC. If TSO
448                  * is configured, prepare the mbuf for TCP segmentation. */
449
450                 /* process checksums of inner headers first */
451                 ol_flags |= process_inner_cksums(l3_hdr, ethertype,
452                         l3_len, l4_proto, tso_segsz, testpmd_ol_flags);
453
454                 /* Then process outer headers if any. Note that the software
455                  * checksum will be wrong if one of the inner checksums is
456                  * processed in hardware. */
457                 if (tunnel == 1) {
458                         ol_flags |= process_outer_cksums(outer_l3_hdr,
459                                 outer_ethertype, outer_l3_len, testpmd_ol_flags);
460                 }
461
462                 /* step 4: fill the mbuf meta data (flags and header lengths) */
463
464                 if (tunnel == 1) {
465                         if (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM) {
466                                 m->outer_l2_len = outer_l2_len;
467                                 m->outer_l3_len = outer_l3_len;
468                                 m->l2_len = l4_tun_len + l2_len;
469                                 m->l3_len = l3_len;
470                         }
471                         else {
472                                 /* if there is a outer UDP cksum
473                                    processed in sw and the inner in hw,
474                                    the outer checksum will be wrong as
475                                    the payload will be modified by the
476                                    hardware */
477                                 m->l2_len = outer_l2_len + outer_l3_len +
478                                         sizeof(struct udp_hdr) +
479                                         sizeof(struct vxlan_hdr) + l2_len;
480                                 m->l3_len = l3_len;
481                                 m->l4_len = l4_len;
482                         }
483                 } else {
484                         /* this is only useful if an offload flag is
485                          * set, but it does not hurt to fill it in any
486                          * case */
487                         m->l2_len = l2_len;
488                         m->l3_len = l3_len;
489                         m->l4_len = l4_len;
490                 }
491                 m->tso_segsz = tso_segsz;
492                 m->ol_flags = ol_flags;
493
494                 /* if verbose mode is enabled, dump debug info */
495                 if (verbose_level > 0) {
496                         struct {
497                                 uint64_t flag;
498                                 uint64_t mask;
499                         } tx_flags[] = {
500                                 { PKT_TX_IP_CKSUM, PKT_TX_IP_CKSUM },
501                                 { PKT_TX_UDP_CKSUM, PKT_TX_L4_MASK },
502                                 { PKT_TX_TCP_CKSUM, PKT_TX_L4_MASK },
503                                 { PKT_TX_SCTP_CKSUM, PKT_TX_L4_MASK },
504                                 { PKT_TX_IPV4, PKT_TX_IPV4 },
505                                 { PKT_TX_IPV6, PKT_TX_IPV6 },
506                                 { PKT_TX_OUTER_IP_CKSUM, PKT_TX_OUTER_IP_CKSUM },
507                                 { PKT_TX_OUTER_IPV4, PKT_TX_OUTER_IPV4 },
508                                 { PKT_TX_OUTER_IPV6, PKT_TX_OUTER_IPV6 },
509                                 { PKT_TX_TCP_SEG, PKT_TX_TCP_SEG },
510                         };
511                         unsigned j;
512                         const char *name;
513
514                         printf("-----------------\n");
515                         /* dump rx parsed packet info */
516                         printf("rx: l2_len=%d ethertype=%x l3_len=%d "
517                                 "l4_proto=%d l4_len=%d\n",
518                                 l2_len, rte_be_to_cpu_16(ethertype),
519                                 l3_len, l4_proto, l4_len);
520                         if (tunnel == 1)
521                                 printf("rx: outer_l2_len=%d outer_ethertype=%x "
522                                         "outer_l3_len=%d\n", outer_l2_len,
523                                         rte_be_to_cpu_16(outer_ethertype),
524                                         outer_l3_len);
525                         /* dump tx packet info */
526                         if ((testpmd_ol_flags & (TESTPMD_TX_OFFLOAD_IP_CKSUM |
527                                                 TESTPMD_TX_OFFLOAD_UDP_CKSUM |
528                                                 TESTPMD_TX_OFFLOAD_TCP_CKSUM |
529                                                 TESTPMD_TX_OFFLOAD_SCTP_CKSUM)) ||
530                                 tso_segsz != 0)
531                                 printf("tx: m->l2_len=%d m->l3_len=%d "
532                                         "m->l4_len=%d\n",
533                                         m->l2_len, m->l3_len, m->l4_len);
534                         if ((tunnel == 1) &&
535                                 (testpmd_ol_flags & TESTPMD_TX_OFFLOAD_OUTER_IP_CKSUM))
536                                 printf("tx: m->outer_l2_len=%d m->outer_l3_len=%d\n",
537                                         m->outer_l2_len, m->outer_l3_len);
538                         if (tso_segsz != 0)
539                                 printf("tx: m->tso_segsz=%d\n", m->tso_segsz);
540                         printf("tx: flags=");
541                         for (j = 0; j < sizeof(tx_flags)/sizeof(*tx_flags); j++) {
542                                 name = rte_get_tx_ol_flag_name(tx_flags[j].flag);
543                                 if ((m->ol_flags & tx_flags[j].mask) ==
544                                         tx_flags[j].flag)
545                                         printf("%s ", name);
546                         }
547                         printf("\n");
548                 }
549         }
550         nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
551         fs->tx_packets += nb_tx;
552         fs->rx_bad_ip_csum += rx_bad_ip_csum;
553         fs->rx_bad_l4_csum += rx_bad_l4_csum;
554
555 #ifdef RTE_TEST_PMD_RECORD_BURST_STATS
556         fs->tx_burst_stats.pkt_burst_spread[nb_tx]++;
557 #endif
558         if (unlikely(nb_tx < nb_rx)) {
559                 fs->fwd_dropped += (nb_rx - nb_tx);
560                 do {
561                         rte_pktmbuf_free(pkts_burst[nb_tx]);
562                 } while (++nb_tx < nb_rx);
563         }
564 #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES
565         end_tsc = rte_rdtsc();
566         core_cycles = (end_tsc - start_tsc);
567         fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles);
568 #endif
569 }
570
571 struct fwd_engine csum_fwd_engine = {
572         .fwd_mode_name  = "csum",
573         .port_fwd_begin = NULL,
574         .port_fwd_end   = NULL,
575         .packet_fwd     = pkt_burst_checksum_forward,
576 };
577