Windows上的DPDK L2fwd应用程序可能会接收到乱序数据包,这可能会影响网络性能。为了解决这个问题,您可以将DPDK的ETH_RSS_NONFRAG_IPV4_TCP和ETH_RSS_NONFRAG_IPV4_UDP哈希函数配置为使用TCP或UDP端口信息生成哈希键。
以下是使用TCP端口信息进行哈希化的代码示例:
#define NUM_MBUFS 8191
#define MBUF_CACHE_SIZE 250
#define BURST_SIZE 32
struct rte_mempool *mbuf_pool;
static const struct rte_eth_conf port_conf_default = {
.rxmode = { .max_rx_pkt_len = ETHER_MAX_LEN }
};
static uint16_t
l2fwd_simple_forward(struct lcore_queue_conf *qconf, uint16_t portid,
struct rte_mbuf *m)
{
uint16_t dst_port;
struct ether_hdr *eth;
void *tmp;
struct ipv4_hdr *ipv4_hdr;
struct udp_hdr *udp;
struct tcp_hdr *tcp;
int hash_id;
eth = rte_pktmbuf_mtod(m, struct ether_hdr *);
if (eth->ether_type == rte_cpu_to_be_16(ETHER_TYPE_IPv4)) {
ipv4_hdr = (struct ipv4_hdr *)(eth + 1);
tmp = ipv4_hdr + 1;
if (ipv4_hdr->next_proto_id == IPPROTO_UDP) {
udp = (struct udp_hdr *)tmp;
hash_id = udp->dst_port;
} else if (ipv4_hdr->next_proto_id == IPPROTO_TCP) {
tcp = (struct tcp_hdr *)tmp;
hash_id = tcp->dst_port;
} else {
hash_id = ipv4_hdr->next_proto_id;
}
} else {
hash_id = eth->ether_type;
}
dst_port = qconf->tx_queue_id[hash_id & NUM_TX_QUEUE_MASK];
rte_eth_tx_buffer(dst_port, 0, qconf->tx_mbufs[hash_id & NUM_TX_QUEUE_MASK], m);
return dst_port;
}
static void
l2fwd_rx_loop_stat(void)
{
struct rte_mbuf *pkts_burst[BURST_SIZE];
struct lcore_queue_conf *qconf;
unsigned lcore_id;
uint64_t prev_tsc, diff_tsc, cur_tsc, timer_tsc;
uint64_t total_rx_packets = 0, total_tx_packets = 0;
uint64_t total_packets_dropped = 0;
unsigned i, portid, nb