前言
我之前尝试通过namespace,搭建dpdk的测试环境,但是对于tcp有点问题,而且过程也比较麻烦,见: dpdk网络转发环境的搭建-CSDN博客
下面,我通过多个虚拟机的方式,搭建dpdk的测试环境,感觉还行。
虚拟机的网络拓扑结构
网络拓扑结构
最朴素的想法是:一个客户端; 一个服务端; DPDK运行在网关/防火墙一类的产品上。所有的流量都使用DPDK进行转发。
上面可以,但是日常测试的时候会有点不方便。
我们需要一个流量生成工具。这里使用trex。它会使用一张网卡作为客户端,一张网卡作为服务端。可以省一台机器。也省了路由之类的配置。
每个虚拟机都有个桥接网卡,供外部ssh连接。
dpdk实验的时候,需要将两张网卡直接连接起来。这里使用 virtualbox - Internal Networking 来实现。
Internal networks are created automatically as needed. There is no central configuration. Every internal network is identified simply by its name. Once there is more than one active virtual network card with the same internal network ID, the Oracle VM VirtualBox support driver will automatically wire the cards and act as a network switch. The Oracle VM VirtualBox support driver implements a complete Ethernet switch and supports both broadcast/multicast frames and promiscuous mode.
上面英文的大概意思是:internal netwok 是通过名称来区别。具有相同名称的网卡可以通信。这个通信是虚拟机之间的,不经过主机。VirtualBox 驱动程序将自动连接这些卡并充当网络交换机,支持广播/多播帧和混杂模式。
所以,上面的拓扑结构相当于,名称为intnet0的两张网卡插在一个交换机上。名称为intnet1的两张网卡插在另一个交换机上。而一个交换机上只接了两个网卡,相当于这两张网卡通过网桥连接,或者相当于通过网线直接连接。
virtualbox中配置内部网络的方式,如下图。
DPDK的准备工作
DPDK的编译
关于编译参数,自行参考官方手册和源码。
git clone git@github.com:DPDK/dpdk.git
git checkout v23.11
meson setup -Dcpu_instruction_set=corei7 -Dbuildtype=debug -Dexamples=all -Dprefix=YOUR_DPDK_INSTALL_PATH build
cd build
ninja
ninja install
DPDK机器网卡绑定
# 如果包管理里面有,直接安装。如果没有,则源码编译安装。
## ubuntu
sudo apt install dpdk-igb-uio-dkms
# 编译igb_uio驱动; 在wsl中会编译失败,需要在linux环境中编译
git clone git://dpdk.org/dpdk-kmods
cd dpdk-kmods/linux
make
# 驱动安装
modprobe igb_uio
# 停止网卡
# ip link set enp0s8 down
# ip link set enp0s9 down
# 绑定网卡
./dpdk-devbind.py