xref: /dpdk/app/test-pmd/macswap.c (revision 655131ccf727d536b1b3f6abbdb054297f0ef869)
180139e35SThomas Monjalon /* SPDX-License-Identifier: BSD-3-Clause
280139e35SThomas Monjalon  * Copyright 2014-2020 Mellanox Technologies, Ltd
3d47388f1SCyril Chemparathy  */
4d47388f1SCyril Chemparathy 
5d47388f1SCyril Chemparathy #include <stdarg.h>
6d47388f1SCyril Chemparathy #include <string.h>
7d47388f1SCyril Chemparathy #include <stdio.h>
8d47388f1SCyril Chemparathy #include <errno.h>
9d47388f1SCyril Chemparathy #include <stdint.h>
10d47388f1SCyril Chemparathy #include <unistd.h>
11d47388f1SCyril Chemparathy #include <inttypes.h>
12d47388f1SCyril Chemparathy 
13d47388f1SCyril Chemparathy #include <sys/queue.h>
14d47388f1SCyril Chemparathy #include <sys/stat.h>
15d47388f1SCyril Chemparathy 
16d47388f1SCyril Chemparathy #include <rte_common.h>
17d47388f1SCyril Chemparathy #include <rte_byteorder.h>
18d47388f1SCyril Chemparathy #include <rte_log.h>
19d47388f1SCyril Chemparathy #include <rte_debug.h>
20d47388f1SCyril Chemparathy #include <rte_cycles.h>
21d47388f1SCyril Chemparathy #include <rte_memory.h>
22d47388f1SCyril Chemparathy #include <rte_memcpy.h>
23d47388f1SCyril Chemparathy #include <rte_launch.h>
24d47388f1SCyril Chemparathy #include <rte_eal.h>
25d47388f1SCyril Chemparathy #include <rte_per_lcore.h>
26d47388f1SCyril Chemparathy #include <rte_lcore.h>
27d47388f1SCyril Chemparathy #include <rte_branch_prediction.h>
28d47388f1SCyril Chemparathy #include <rte_mempool.h>
29d47388f1SCyril Chemparathy #include <rte_mbuf.h>
30d47388f1SCyril Chemparathy #include <rte_interrupts.h>
31d47388f1SCyril Chemparathy #include <rte_ether.h>
32d47388f1SCyril Chemparathy #include <rte_ethdev.h>
33d47388f1SCyril Chemparathy #include <rte_ip.h>
34d47388f1SCyril Chemparathy #include <rte_string_fns.h>
35938a184aSAdrien Mazarguil #include <rte_flow.h>
36d47388f1SCyril Chemparathy 
37d47388f1SCyril Chemparathy #include "testpmd.h"
380ef246a7SRuifeng Wang #if defined(RTE_ARCH_X86)
39a68b6168SQi Zhang #include "macswap_sse.h"
4084fb33feSRadu Nicolau #elif defined(__ARM_NEON)
410ef246a7SRuifeng Wang #include "macswap_neon.h"
42a68b6168SQi Zhang #else
43a825afdbSQi Zhang #include "macswap.h"
44a68b6168SQi Zhang #endif
45d47388f1SCyril Chemparathy 
46d47388f1SCyril Chemparathy /*
47d47388f1SCyril Chemparathy  * MAC swap forwarding mode: Swap the source and the destination Ethernet
48d47388f1SCyril Chemparathy  * addresses of packets before forwarding them.
49d47388f1SCyril Chemparathy  */
5006c20561SDavid Marchand static bool
pkt_burst_mac_swap(struct fwd_stream * fs)51d47388f1SCyril Chemparathy pkt_burst_mac_swap(struct fwd_stream *fs)
52d47388f1SCyril Chemparathy {
53d47388f1SCyril Chemparathy 	struct rte_mbuf  *pkts_burst[MAX_PKT_BURST];
54d47388f1SCyril Chemparathy 	uint16_t nb_rx;
55d47388f1SCyril Chemparathy 
56d47388f1SCyril Chemparathy 	/*
57d47388f1SCyril Chemparathy 	 * Receive a burst of packets and forward them.
58d47388f1SCyril Chemparathy 	 */
59d3dae396SDavid Marchand 	nb_rx = common_fwd_stream_receive(fs, pkts_burst, nb_pkt_per_burst);
607569b8c1SHonnappa Nagarahalli 	if (unlikely(nb_rx == 0))
6106c20561SDavid Marchand 		return false;
627569b8c1SHonnappa Nagarahalli 
63*655131ccSDavid Marchand 	do_macswap(pkts_burst, nb_rx, &ports[fs->tx_port]);
64*655131ccSDavid Marchand 	common_fwd_stream_transmit(fs, pkts_burst, nb_rx);
6506c20561SDavid Marchand 
6606c20561SDavid Marchand 	return true;
67d47388f1SCyril Chemparathy }
68d47388f1SCyril Chemparathy 
69d47388f1SCyril Chemparathy struct fwd_engine mac_swap_engine = {
70d47388f1SCyril Chemparathy 	.fwd_mode_name  = "macswap",
71180ba023SDavid Marchand 	.stream_init    = common_fwd_stream_init,
72d47388f1SCyril Chemparathy 	.packet_fwd     = pkt_burst_mac_swap,
73d47388f1SCyril Chemparathy };
74