1. 环境配置及依赖工具,在DPDK使用方法一文中已经介绍,不再重复
yum groupinstall "Development Tools" -y //For RHEL/Fedora
apt install -y build-essential //For Ubuntu/Debian
管理 NUMA 的库:
yum install -y numactl-devel //For RHEL/Fedora
apt install -y libnuma-dev //For Ubuntu/Debian
2. DPDK 源码编译
2.1 解压DPDK
[root@localhost ~]# tar xvf dpdk-19.11.6.tar.xz
2.2 打FPGA卡的补丁,让DPDK可以识别
[root@localhost dpdk-stable-19.11.6.xgap]# patch -p0< dpdk-stable-19.11.14-gap1018.diff
patching file lib/librte_net/rte_ether.h
patching file lib/librte_mempool/rte_mempool.h
patching file drivers/net/anntec/anntec_ethdev.c
patching file drivers/net/anntec/anntec_rxtx.c
patching file drivers/net/anntec/anntec_drv.h
patching file drivers/net/anntec/anntec_eeprom.h
patching file drivers/net/anntec/anntec_ethdev.h
patching file drivers/net/anntec/anntec_hw.c
patching file drivers/net/anntec/anntec_hw.h
patching file drivers/net/anntec/anntec_igic.c
patching file drivers/net/anntec/anntec_igic.h
patching file drivers/net/anntec/anntec_rxtx.h
patching file drivers/net/anntec/Makefile
patching file drivers/net/anntec/anntec_eeprom.c
patching file drivers/net/anntec/anntec_logs.h
patching file drivers/net/anntec/meson.build
patching file drivers/net/anntec/rte_pmd_anntec_version.map
patching file drivers/net/Makefile
patching file config/common_base
patching file mk/rte.app.mk
2.3 设置RTE参数并编译DPDK
[root@localhost dpdk-stable-19.11.6.xgap]# export RTE_SDK=`pwd`
[root@localhost dpdk-stable-19.11.6.xgap]# export RTE_TARGET=x86_64-native-linuxapp-gcc
[root@localhost dpdk-stable-19.11.6.xgap]# make -j 8 install T=$RTE_TARGET
2.4编译kni
[root@localhost dpdk-stable-19.11.6.xgap]# cd examples/kni
[root@localhost kni]# make
CC main.o
LD kni
INSTALL-APP kni
INSTALL-MAP kni.map
3 测试
3.1 加载uio ,igb_uio,rte_kni驱动,配置大页内存
[root@localhost dpdk-stable-19.11.6.xgap]# modprobe uio
[root@localhost dpdk-stable-19.11.6.xgap]# insmod x86_64-native-linuxapp-gcc/kmod/igb_uio.ko
[root@localhost dpdk-stable-19.11.6.xgap]# insmod x86_64-native-linuxapp-gcc/kmod/rte_kni.ko
[root@localhost dpdk-stable-19.11.6.xgap]#echo 1024 > /sys/devices/system/node/node0/hugepages/hugepages-2048kB/nr_hugepages
3.2 FPGA网卡的设备名
01:00.0 Memory controller: ANNTEC Device 1e92 1022 //SAS版
01:00.1 Memory controller: ANNTEC Device 1e92 0022 //SFP版
3.3 绑定FPGA网卡的接口到igb_uio
[root@localhost dpdk-stable-19.11.6.xgap]# echo 1e92 1022 > /sys/bus/pci/drivers/igb_uio/new_id
3.4 启动kni,启动后可以在内核下看到vEth0_0接口
[root@localhost dpdk-stable-19.11.6.xgap]# cd examples/kni/build/
[root@localhost build]# ./kni -l 0-2 -- -P -p 0x1 --config="(0,0,1,0)"
EAL: Detected 8 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Selected IOVA mode 'PA'
EAL: No available hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
EAL: PCI device 0000:01:00.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 1e92:1022 net_anntec
EAL: Product model: ANNTEC-200-M
EAL: FM version: 129.0.1.0 20230428
EAL: mac ff:ff:ff:ff:ff:ff
EAL: Link Speed 10G
EAL: port_id 0 vendorID=0x1e92 deviceID=0x1022, name:0000:01:00.0
EAL: PCI device 0000:01:00.1 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 1e92:1022 net_anntec
EAL: Product model: ANNTEC-200-M
EAL: mac ff:ff:ff:ff:ff:ff
EAL: Link Speed 10G
EAL: port_id 1 vendorID=0x1e92 deviceID=0x1022, name:0000:01:00.1
EAL: PCI device 0000:04:00.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 8086:1533 net_e1000_igb
EAL: PCI device 0000:05:00.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 8086:1533 net_e1000_igb
EAL: PCI device 0000:06:00.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 8086:1533 net_e1000_igb
EAL: PCI device 0000:07:00.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 8086:1533 net_e1000_igb
EAL: PCI device 0000:08:00.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 8086:1533 net_e1000_igb
EAL: PCI device 0000:09:00.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 8086:1533 net_e1000_igb
APP: Initialising port 0 ...
EAL: Dev0000:01:00.0 rx queue setup: queue logic id: 0
EAL: Dev0000:01:00.0 tx queue setup: queue logic id: 0
CPU: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
EAL: Set mac address ff:ff:ff:ff:ff:ff
Checking link status
done
Port0 Link Up - speed 10000Mbps - full-duplex
APP: ========================
APP: KNI Running
APP: kill -SIGUSR1 3245
APP: Show KNI Statistics.
APP: kill -SIGUSR2 3245
APP: Zero KNI Statistics.
APP: ========================
APP: Lcore 1 is writing to port 0
APP: Lcore 0 is reading from port 0
APP: Lcore 2 has nothing to do
APP: Configure network interface of 0 up
EAL: Set mac address ff:ff:ff:ff:ff:ff
10: vEth0_0: mtu 1504 qdisc pfifo_fast state UP group default qlen 1000
link/ether 22:46:be:23:4f:05 brd ff:ff:ff:ff:ff:ff
inet 1.1.1.1/24 brd 1.1.1.255 scope global vEth0_0
valid_lft forever preferred_lft forever
inet6 fe80::2046:beff:fe23:4f05/64 scope link
valid_lft forever preferred_lft forever
3.5 允许内核收发数据
echo 1 > /sys/devices/virtual/net/vEth0_0/carrier
3.6 查看网卡
[root@localhost build]# ethtool vEth0_0
Settings for vEth0_0:
Link detected: yes
[root@localhost build]# ethtool -i vEth0_0
driver: kni
version: 1.0
firmware-version:
expansion-rom-version:
bus-info:
supports-statistics: no
supports-test: no
supports-eeprom-access: no
supports-register-dump: no
supports-priv-flags: no
后续就是用ifconfig, ip等命令对vEth0_0进行配置,收发包测试。
4 初步测试后的优化
4.1 用命令开启混杂模式,和关闭混杂模式
ifconfig ethx promisc 开启混杂模式
ifconfig ethx -promisc 关闭混杂模式
4.2加载rte_kni模块时,如果不指定参数,默认会启动线程,专门处理接收报文
默认是禁止回环模式,也就是dpdk通过kni写入内核,但是无法从内核中获取到结果数据
可以通过加载rte_kni模块时,带参数设置kni内核模式(内存使用(io_mode)、线程
(kthread_mode),链路设置(carrier))等
4.3 kni可以写入内核但是收不到内核回复数据,需要设置链路状态的开与关 carrier=on carrier=off
1:insmod kmod/rte_kni.ko carrier=on
2:通过dpdk提供的函数接口进行设置 :rte_kni_update_link()
===>需要专门启动一个线程对其进行关注写入。
3:echo 1 >/sys/devices/virtual/net/vEth0/carrier 写入
4.4 可以利用tshark监听网卡进行数据监控验证
yum install wireshark
tshark -i vEth0_0 icmp ===》然后使用ping命令,观察有icmp报文请求以及回复。