我是DPDK的新手,尝试创建一个数据包,将其从一台支持DPDK的机器发送到另一台直接通过以太网连接的机器我修改了两边都有DPDK的示例/rxtx_callbacks/main.c但是,我没有收到任何东西在接收器我做错什么了?
修改了发射机的功能:lcore_main

static  __attribute__((noreturn)) void lcore_main()
{
    uint16_t port;
    struct ether_hdr *eth_hdr;
    struct ether_addr daddr;
    daddr.addr_bytes[0] = 116;
    daddr.addr_bytes[1] = 225;
    daddr.addr_bytes[2] = 228;
    daddr.addr_bytes[3] = 204;
    daddr.addr_bytes[4] = 106;
    daddr.addr_bytes[5] = 82;

    //rte_eth_macaddr_get(portid, &addr);
    struct ipv4_hdr *ipv4_hdr;
    int32_t i;
    int ret;
    RTE_ETH_FOREACH_DEV(port)
        if (rte_eth_dev_socket_id(port) > 0 &&
                rte_eth_dev_socket_id(port) !=
                        (int)rte_socket_id())
            printf("WARNING, port %u is on remote NUMA node to "
                    "polling thread.\n\tPerformance will "
                    "not be optimal.\n", port);

    printf("\nCore %u forwarding packets.  [Ctrl+C to quit]\n",
            rte_lcore_id());
    //struct rte_mbuf *m_head = rte_pktmbuf_alloc(mbuf_pool);
    struct rte_mbuf *m_head[BURST_SIZE];

    for (;;) {
        RTE_ETH_FOREACH_DEV(port) {
            if(rte_pktmbuf_alloc_bulk(mbuf_pool, m_head, BURST_SIZE)!=0)
            {
                printf("Allocation problem\n");
            }
            for(i  = 0; i < BURST_SIZE; i++) {
                eth_hdr = rte_pktmbuf_mtod(m_head[i], struct ether_hdr *);
                //eth_hdr = (struct ether_hdr *)rte_pktmbuf_append(m_head[i],
                //           sizeof(struct ether_hdr));
                eth_hdr->ether_type = htons(ETHER_TYPE_IPv4);
                rte_memcpy(&(eth_hdr->s_addr), &addr, sizeof(struct ether_addr));
                rte_memcpy(&(eth_hdr->d_addr), &daddr, sizeof(struct ether_addr));
            }
            const uint16_t nb_tx = rte_eth_tx_burst(port, 0, m_head, BURST_SIZE);
            if (unlikely(nb_tx < BURST_SIZE)) {
                uint16_t buf;

                for (buf = nb_tx; buf < BURST_SIZE; buf++)
                    rte_pktmbuf_free(m_head[buf]);
            }
        }
    }
}

发送部分的接收器侧修改为:
RTE_ETH_FOREACH_DEV(port) {
    struct rte_mbuf *bufs[BURST_SIZE];
    const uint16_t nb_rx = rte_eth_rx_burst(port, bufs, BURST_SIZE);
    //printf("Number of Packets received %d\n", nb_rx);
    for(i  = 0; i < nb_rx; i++) {
        //ipv4_hdr = rte_pktmbuf_mtod_offset(bufs[i], struct ipv4_hdr *,
        //                                   sizeof(struct ether_hdr));
        //printf("Packet ip received %d\n", ipv4_hdr->src_addr);
        eth_hdr = rte_pktmbuf_mtod(bufs[i], struct ether_hdr *);
        printf("Packet ip received %d\n", eth_hdr->ether_type);
    }

    if (unlikely(nb_rx == 0))
        continue;

    const uint16_t nb_tx = 0; // = rte_eth_tx_burst(port ^ 1, 0, bufs, nb_rx);
    if (unlikely(nb_tx < nb_rx)) {
        uint16_t buf;

        for (buf = nb_tx; buf < nb_rx; buf++)
            rte_pktmbuf_free(bufs[buf]);
    }
}

如果我遗漏了什么,请告诉我。

最佳答案

代码几乎没有问题:
eth_hdr=rte_pktmbuf_mtod(m_head[i],struct ether_hdr*);
rte_pktmbuf_append()不同,rte_pktmbuf_mtod()不会更改数据包长度,因此应在发送之前手动设置。
eth_hdr->ether_type=htons(ether_type_IPv4);
如果设置ETHER_TYPE_IPv4,则必须遵循正确的IPv4头因此,我们需要添加标题或更改乙醚类型。
rte_memcpy(&(eth_hdr->s_addr),&addr,sizeof(struct ether_addr));
源地址从哪里来?
const uint16_t nb_tx=rte_eth_tx_突发(端口,0,m_头,突发大小);
看起来我们传输了一个零大小的包突发,其IPv4头无效请确保源/目标地址正确。

09-06 18:30