我是DPDK的新手,正在尝试创建一个数据包,以将其从启用了DPDK的计算机发送到直接通过以太网连接的另一台计算机。我修改了DPDK两侧提供的example / 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_DEVTX部分的接收方修改为:
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]); } }
如果我错过了什么,请告诉我。