2017-12-19 15:48:59 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2010-2014 Intel Corporation
|
2012-09-04 12:54:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <inttypes.h>
|
|
|
|
|
|
|
|
#include <sys/queue.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#include <rte_common.h>
|
|
|
|
#include <rte_byteorder.h>
|
|
|
|
#include <rte_log.h>
|
|
|
|
#include <rte_debug.h>
|
|
|
|
#include <rte_cycles.h>
|
|
|
|
#include <rte_memory.h>
|
|
|
|
#include <rte_memcpy.h>
|
|
|
|
#include <rte_launch.h>
|
|
|
|
#include <rte_eal.h>
|
|
|
|
#include <rte_per_lcore.h>
|
|
|
|
#include <rte_lcore.h>
|
|
|
|
#include <rte_atomic.h>
|
|
|
|
#include <rte_branch_prediction.h>
|
|
|
|
#include <rte_mempool.h>
|
|
|
|
#include <rte_mbuf.h>
|
|
|
|
#include <rte_interrupts.h>
|
|
|
|
#include <rte_pci.h>
|
|
|
|
#include <rte_ether.h>
|
|
|
|
#include <rte_ethdev.h>
|
|
|
|
#include <rte_ip.h>
|
|
|
|
#include <rte_string_fns.h>
|
2016-12-21 14:51:22 +00:00
|
|
|
#include <rte_flow.h>
|
2012-09-04 12:54:00 +00:00
|
|
|
|
|
|
|
#include "testpmd.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Forwarding of packets in MAC mode.
|
|
|
|
* Change the source and the destination Ethernet addressed of packets
|
|
|
|
* before forwarding them.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pkt_burst_mac_forward(struct fwd_stream *fs)
|
|
|
|
{
|
|
|
|
struct rte_mbuf *pkts_burst[MAX_PKT_BURST];
|
|
|
|
struct rte_port *txp;
|
|
|
|
struct rte_mbuf *mb;
|
2019-05-21 16:13:03 +00:00
|
|
|
struct rte_ether_hdr *eth_hdr;
|
2016-06-14 23:08:02 +00:00
|
|
|
uint32_t retry;
|
2012-09-04 12:54:00 +00:00
|
|
|
uint16_t nb_rx;
|
|
|
|
uint16_t nb_tx;
|
|
|
|
uint16_t i;
|
2014-11-26 15:04:49 +00:00
|
|
|
uint64_t ol_flags = 0;
|
2018-01-10 09:09:14 +00:00
|
|
|
uint64_t tx_offloads;
|
2020-07-14 21:51:03 +00:00
|
|
|
uint64_t start_tsc = 0;
|
2012-09-04 12:54:00 +00:00
|
|
|
|
2020-07-14 21:51:03 +00:00
|
|
|
get_start_cycles(&start_tsc);
|
2012-09-04 12:54:00 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Receive a burst of packets and forward them.
|
|
|
|
*/
|
|
|
|
nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, pkts_burst,
|
|
|
|
nb_pkt_per_burst);
|
2020-07-14 21:51:05 +00:00
|
|
|
inc_rx_burst_stats(fs, nb_rx);
|
2020-07-06 23:32:31 +00:00
|
|
|
if (unlikely(nb_rx == 0))
|
|
|
|
return;
|
|
|
|
|
2012-09-04 12:54:00 +00:00
|
|
|
fs->rx_packets += nb_rx;
|
|
|
|
txp = &ports[fs->tx_port];
|
2018-01-10 09:09:14 +00:00
|
|
|
tx_offloads = txp->dev_conf.txmode.offloads;
|
|
|
|
if (tx_offloads & DEV_TX_OFFLOAD_VLAN_INSERT)
|
2014-11-26 15:04:49 +00:00
|
|
|
ol_flags = PKT_TX_VLAN_PKT;
|
2018-01-10 09:09:14 +00:00
|
|
|
if (tx_offloads & DEV_TX_OFFLOAD_QINQ_INSERT)
|
2015-06-11 07:03:58 +00:00
|
|
|
ol_flags |= PKT_TX_QINQ_PKT;
|
2018-01-10 09:09:14 +00:00
|
|
|
if (tx_offloads & DEV_TX_OFFLOAD_MACSEC_INSERT)
|
2017-01-13 11:21:40 +00:00
|
|
|
ol_flags |= PKT_TX_MACSEC;
|
2012-09-04 12:54:00 +00:00
|
|
|
for (i = 0; i < nb_rx; i++) {
|
2016-05-03 14:07:45 +00:00
|
|
|
if (likely(i < nb_rx - 1))
|
|
|
|
rte_prefetch0(rte_pktmbuf_mtod(pkts_burst[i + 1],
|
|
|
|
void *));
|
2012-09-04 12:54:00 +00:00
|
|
|
mb = pkts_burst[i];
|
2019-05-21 16:13:03 +00:00
|
|
|
eth_hdr = rte_pktmbuf_mtod(mb, struct rte_ether_hdr *);
|
2019-05-21 16:13:04 +00:00
|
|
|
rte_ether_addr_copy(&peer_eth_addrs[fs->peer_addr],
|
2021-10-07 22:07:49 +00:00
|
|
|
ð_hdr->dst_addr);
|
2019-05-21 16:13:04 +00:00
|
|
|
rte_ether_addr_copy(&ports[fs->tx_port].eth_addr,
|
2021-10-07 22:07:49 +00:00
|
|
|
ð_hdr->src_addr);
|
2018-04-27 17:22:52 +00:00
|
|
|
mb->ol_flags &= IND_ATTACHED_MBUF | EXT_ATTACHED_MBUF;
|
|
|
|
mb->ol_flags |= ol_flags;
|
2019-05-21 16:13:03 +00:00
|
|
|
mb->l2_len = sizeof(struct rte_ether_hdr);
|
2019-05-21 16:13:10 +00:00
|
|
|
mb->l3_len = sizeof(struct rte_ipv4_hdr);
|
2014-09-09 14:40:56 +00:00
|
|
|
mb->vlan_tci = txp->tx_vlan_id;
|
2015-06-11 07:03:58 +00:00
|
|
|
mb->vlan_tci_outer = txp->tx_vlan_id_outer;
|
2012-09-04 12:54:00 +00:00
|
|
|
}
|
|
|
|
nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, nb_rx);
|
2016-06-14 23:08:02 +00:00
|
|
|
/*
|
|
|
|
* Retry if necessary
|
|
|
|
*/
|
|
|
|
if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) {
|
|
|
|
retry = 0;
|
|
|
|
while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) {
|
|
|
|
rte_delay_us(burst_tx_delay_time);
|
|
|
|
nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue,
|
|
|
|
&pkts_burst[nb_tx], nb_rx - nb_tx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-09-04 12:54:00 +00:00
|
|
|
fs->tx_packets += nb_tx;
|
2020-07-14 21:51:05 +00:00
|
|
|
inc_tx_burst_stats(fs, nb_tx);
|
2012-09-04 12:54:00 +00:00
|
|
|
if (unlikely(nb_tx < nb_rx)) {
|
|
|
|
fs->fwd_dropped += (nb_rx - nb_tx);
|
|
|
|
do {
|
|
|
|
rte_pktmbuf_free(pkts_burst[nb_tx]);
|
|
|
|
} while (++nb_tx < nb_rx);
|
|
|
|
}
|
2020-07-14 21:51:03 +00:00
|
|
|
|
|
|
|
get_end_cycles(fs, start_tsc);
|
2012-09-04 12:54:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct fwd_engine mac_fwd_engine = {
|
|
|
|
.fwd_mode_name = "mac",
|
|
|
|
.port_fwd_begin = NULL,
|
|
|
|
.port_fwd_end = NULL,
|
|
|
|
.packet_fwd = pkt_burst_mac_forward,
|
|
|
|
};
|