DPDK-可以接收数据包
我是网络和DPDK的新手,我尝试了一个小程序来使用主机收到的DPDK接收和打印数据包,但似乎对DPDK的NIC偏见对这些数据包毫无意义。如何阅读数据包? 换句话说,Eno1和Eno2是绑定到DPDK的接口。 ENP1S0是使用内核驱动程序的接口。 我希望阅读使用DPDK流过ENP1S0的数据包。 我使用TCPREPLAY和NETCAT将数据包发送到主机。我知道主机会收到数据包,但是DPDK应用程序对此完全毫无意义。 你能给我任何建议吗? 小密码
#define RING_SIZE 4096
#define n 16383 //n = 2^12 - 1. Optimized according API
#define MEMPOOL_CACHE_SIZE 256 // n%MEMPOOL_CACHE_SIZE = 0. Optimized according API
//#define DATA_ROOM_SIZE 256
#define NB_DESC 1024
#define BURST_SIZE 32
static int ragequit = 0;
struct rte_mempool *buff;
static struct rte_eth_conf port_conf_default = {
.rxmode = {
.mq_mode = RTE_ETH_MQ_RX_RSS,
},
.txmode = {
.mq_mode = RTE_ETH_MQ_TX_NONE,
},
};
static void handler(int sig_num)
{
if (sig_num == SIGINT)
ragequit = 1;
printf(" packets capture over\n");
}
int main(int argc, char *argv[])
{
int ret, pack;
uint16_t port_id;
struct rte_ring *ring_rx;
struct rte_eth_conf port_conf = port_conf_default;
signal(SIGINT, handler);
//body
//EAL initialization
ret = rte_eal_init(argc, argv);
if (ret < 0)
rte_exit(EXIT_FAILURE, "\nEAL can not start");
//ports available
int nbports = rte_eth_dev_count_avail();
if (nbports < 1)
rte_exit(EXIT_FAILURE, "no ethernet ports found");
buff = rte_pktmbuf_pool_create("buff_pool", n, MEMPOOL_CACHE_SIZE, 0,
RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
if (buff == NULL)
rte_exit(EXIT_FAILURE, "\nCannot create pool buffer | %s\n", rte_strerror(rte_errno));
printf("pool buffer created\n");
RTE_ETH_FOREACH_DEV(port_id) { //iterate over all enabled and ownerless ports
ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf);
if (ret < 0)
rte_exit(EXIT_FAILURE, "\nCannot configure ethernet device");
ret = rte_eth_rx_queue_setup(port_id, 0, NB_DESC, rte_eth_dev_socket_id(port_id), NULL, buff);
if (ret < 0)
rte_exit(EXIT_FAILURE, "\nCannot setup rx queue");
ret = rte_eth_tx_queue_setup(port_id, 0, NB_DESC, rte_eth_dev_socket_id(port_id), NULL);
if (ret < 0)
rte_exit(EXIT_FAILURE, "\nCannot setup tx queue");
ret = rte_eth_dev_start(port_id);
if (ret < 0)
rte_exit(EXIT_FAILURE, "\nCannot start ethernet service");
}
ring_rx = rte_ring_create("RX", RING_SIZE, rte_socket_id(), RING_F_SP_ENQ); //single producer
if (ring_rx == NULL)
rte_exit(EXIT_FAILURE, "\nCannot create RX ring");
struct rte_mbuf *mbuff[BURST_SIZE];
unsigned char *msg = NULL;
while (ragequit == 0)
{
RTE_ETH_FOREACH_DEV(port_id)
{
pack = rte_eth_rx_burst(port_id, 0, mbuff, BURST_SIZE);
if (pack == 0)
{
//sleep(1);
continue;
}
rte_ring_enqueue_burst(ring_rx, (void *) mbuff, pack, NULL);
for (int i = 0; i < pack; i++)
{
msg = rte_pktmbuf_mtod(mbuff[i], unsigned char *);
for (int octet = 1; octet < 96; octet++)
{
printf("%02x ", msg[octet-1]);
if (octet%8 == 0)
{
if (octet%32 == 0)
printf("\n");
else
printf(" ");
}
}
printf("-------------------------------------------------------------- --------------------------------------------------------------\n");
}
}
}
printf("\nEndgame\n");
rte_eal_cleanup();
return 0;
}
这是我执行此操作的 ./ test3 -L 0-1 -n 4- -p 0xfff
感谢您的阅读。 此致
i'm new at networking and dpdk, i tryed a little program to recieve and print packets using dpdk that the host receives, but it appears the nic binded to dpdk is clueless about those packets. How can i read the packets ?
In other words, eno1 and eno2 are interfaces binded to dpdk.
enp1s0 is the interface using kernel driver.
I wish to read packets flowing through enp1s0 with dpdk.
I used tcpreplay, and netcat to send packet to the host. I know the host receives the packets, but the dpdk application is utterly clueless about it.
Could you give me any suggestions ?
Here's the little code
#define RING_SIZE 4096
#define n 16383 //n = 2^12 - 1. Optimized according API
#define MEMPOOL_CACHE_SIZE 256 // n%MEMPOOL_CACHE_SIZE = 0. Optimized according API
//#define DATA_ROOM_SIZE 256
#define NB_DESC 1024
#define BURST_SIZE 32
static int ragequit = 0;
struct rte_mempool *buff;
static struct rte_eth_conf port_conf_default = {
.rxmode = {
.mq_mode = RTE_ETH_MQ_RX_RSS,
},
.txmode = {
.mq_mode = RTE_ETH_MQ_TX_NONE,
},
};
static void handler(int sig_num)
{
if (sig_num == SIGINT)
ragequit = 1;
printf(" packets capture over\n");
}
int main(int argc, char *argv[])
{
int ret, pack;
uint16_t port_id;
struct rte_ring *ring_rx;
struct rte_eth_conf port_conf = port_conf_default;
signal(SIGINT, handler);
//body
//EAL initialization
ret = rte_eal_init(argc, argv);
if (ret < 0)
rte_exit(EXIT_FAILURE, "\nEAL can not start");
//ports available
int nbports = rte_eth_dev_count_avail();
if (nbports < 1)
rte_exit(EXIT_FAILURE, "no ethernet ports found");
buff = rte_pktmbuf_pool_create("buff_pool", n, MEMPOOL_CACHE_SIZE, 0,
RTE_MBUF_DEFAULT_BUF_SIZE, rte_socket_id());
if (buff == NULL)
rte_exit(EXIT_FAILURE, "\nCannot create pool buffer | %s\n", rte_strerror(rte_errno));
printf("pool buffer created\n");
RTE_ETH_FOREACH_DEV(port_id) { //iterate over all enabled and ownerless ports
ret = rte_eth_dev_configure(port_id, 1, 1, &port_conf);
if (ret < 0)
rte_exit(EXIT_FAILURE, "\nCannot configure ethernet device");
ret = rte_eth_rx_queue_setup(port_id, 0, NB_DESC, rte_eth_dev_socket_id(port_id), NULL, buff);
if (ret < 0)
rte_exit(EXIT_FAILURE, "\nCannot setup rx queue");
ret = rte_eth_tx_queue_setup(port_id, 0, NB_DESC, rte_eth_dev_socket_id(port_id), NULL);
if (ret < 0)
rte_exit(EXIT_FAILURE, "\nCannot setup tx queue");
ret = rte_eth_dev_start(port_id);
if (ret < 0)
rte_exit(EXIT_FAILURE, "\nCannot start ethernet service");
}
ring_rx = rte_ring_create("RX", RING_SIZE, rte_socket_id(), RING_F_SP_ENQ); //single producer
if (ring_rx == NULL)
rte_exit(EXIT_FAILURE, "\nCannot create RX ring");
struct rte_mbuf *mbuff[BURST_SIZE];
unsigned char *msg = NULL;
while (ragequit == 0)
{
RTE_ETH_FOREACH_DEV(port_id)
{
pack = rte_eth_rx_burst(port_id, 0, mbuff, BURST_SIZE);
if (pack == 0)
{
//sleep(1);
continue;
}
rte_ring_enqueue_burst(ring_rx, (void *) mbuff, pack, NULL);
for (int i = 0; i < pack; i++)
{
msg = rte_pktmbuf_mtod(mbuff[i], unsigned char *);
for (int octet = 1; octet < 96; octet++)
{
printf("%02x ", msg[octet-1]);
if (octet%8 == 0)
{
if (octet%32 == 0)
printf("\n");
else
printf(" ");
}
}
printf("-------------------------------------------------------------- --------------------------------------------------------------\n");
}
}
}
printf("\nEndgame\n");
rte_eal_cleanup();
return 0;
}
i execute this with./test3 -l 0-1 -n 4 -- -p 0xfff
Thanks for reading.
Best regards
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
@frederic基于共享的信息,存在一个配置问题。让我解释说
您的当前代码与与DPDK的NIC相互作用,例如EN01和EN02。但是,没有添加任何规定来支持内核驱动程序NIC
ENP1S0
。如何解决问题:
我想读取带有dpdk
- vdev = net_pcap0,iface = [Kernel NIC NIC NIC界面读取和编写数据包。实例ENP1S0]
的重定向数据包中 - vdev = net_tap0,iface = [所需的nic名称]
因此,要解决您的当前问题,请确保通过传递EAL ARGS使用正确的虚拟设备
@Frederic based on the information shared, there is a configuration issue. Let me explain
your current code interacts with the NIC bonded with DPDK such as en01 and en02. But there is no provision added to support kernel Driver NIC
enp1s0
.How to solve the problem:
I wish to read packets flowing through enp1s0 with dpdk
--vdev=net_pcap0,iface=[kernel nic interface instance enp1s0]
--vdev=net_tap0,iface=[desired nic name]
Hence to solve your current issue, please make sure to use right virtual device by passing to EAL args