DPDK(Data Plane Development Kit)
是一种 SDN 数据平面开发工具包,它由一组用于快速包处理的库和驱动程序组成,用于加速在各种 CPU 架构上运行的包处理工作负载。DPDK 应用程序是运行在 Linux 用户空间,并利用自身提供的 数据平面库
来收发数据包,绕过了 Linux 内核协议栈对数据包处理过程。
相关网址
核心技术
DPDK 提高网络数据处理能力的技术包括:
多核架构
huge page内存
PMD(poll-mode drivers)等库,此方案使用DPDK对OVS加速。
PMD(Poll Mode Driver),是基于用户态的轮询机制的驱动
EAL(Environment Abstraction Layer,环境抽象层)
igb_uio 是 DPDK kit 中拥有与 uio 交互,bind 指定网卡的内核模块
uio 模块,是内核提供的用户态驱动框架
CPU affinity
https://www.sdnlab.com/23551.html
环境抽象层(EAL)是DPDK的核心。它是DPDK的一个库。顾名思义,它负责抽象出环境(硬件、操作系统等)并为软件提供统一的接口。EAL要处理很多东西,所以也不难理解为何它会是DPDK中最复杂的一个部分。由EAL负责处理的包括:
· 管理CPU核心和非统一内存访问(NUMA)节点
· 将硬件设备的寄存器映射到内存中,使它们可受DPDK轮询模式驱动程序(PMDs)驱动
· 管理硬件和软件中断
· 抽象出平台差异,如字节序、缓存行大小等
· 管理内存和多进程同步
· 提供与原子、内存屏障和其他同步原语共通的独立于平台和操作系统的方法
· 加载和枚举硬件总线,设备和PMD
但是,用户不必非要在两者中选择一个。可以自动检测出最合适的IOVA模式,而且默认选项绝对适用于大多数情况,因此不需要用户来做此选择。如果默认选项并不合适,用户可以使用–iova-mode EAL命令行参数尝试使用EAL标志(适用于DPDK 17.11及更高版本)来代替IOVA模式:
1 ./app –iova-mode=pa # use IOVA as PA mode
2 ./app –iova-mode=va # use IOVA as VA mode
大多数情况下,VA和PA模式不会互相排斥,可以使用任一模式,但在某些情况下,作为PA模式的IOVA是唯一可用的选择。当不能使用作为VA模式的IOVA时,即使EAL参数要求使用作为VA模式的IOVA,DPDK也会自动切换为作为PA模式的IOVA。
Run the following command to confirm that DPDK is enabled:
$ sudo ovs-vsctl get Open_vSwitch . iface_types
[dpdk, dpdkr, dpdkvhostuser, dpdkvhostuserclient, geneve, gre, internal, lisp, patch, stt, system, tap, vxlan]
https://www.jianshu.com/p/fa7d9f2c0f55
[root@dpdk ~]# modprobe pktgen
[root@dpdk ~]# lsmod |grep pktgen
pktgen 49284 0
[root@dpdk ~]# modprobe vfio
[root@dpdk ~]# lsmod |grep vfio
vfio_iommu_type1 22440 0
vfio 32657 1 vfio_iommu_type1
modprobe \ lsmod \ insmod
[root@dpdk rpmbuild]# modprobe vfio-pci
[root@dpdk rpmbuild]# lsmod |grep vfio
vfio_pci 41993 0
vfio_iommu_type1 22440 0
vfio 32657 2 vfio_iommu_type1,vfio_pci
irqbypass 13503 1 vfio_pci
cat /proc/net/pktgen/pgctrl
yum install dpdk
$ env |grep RTE
RTE_INCLUDE=/usr/include/dpdk
RTE_SDK=/usr/share/dpdk
RTE_TARGET=x86_64-default-linuxapp-gcc
安装 pktgen-dpdk-pktgen
lua 5.3 安装
yum install -y readline readline-devel ncurses ncurses-devel
wget https://www.lua.org/ftp/lua-5.3.6.tar.gz
tar -zxvf lua-5.3.6.tar.gz
cd lua-5.3.6/
make linux && make install
$ lua -v
Lua 5.3.6 Copyright (C) 1994-2020 Lua.org, PUC-Rio
如果安装了 lua-devel
,使用如下命令删除:
$ rpm -evh lua-devel
build
Create the DPDK build tree:
[root@dpdk dpdk-stable-19.11.7]# ./usertools/dpdk-devbind.py -s
Network devices using kernel driver
0000:02:01.0 ‘82545EM Gigabit Ethernet Controller (Copper) 100f’ if=ens33 drv=e1000 unused=igb_uio,vfio-pci Active
0000:03:00.0 ‘VMXNET3 Ethernet Controller 07b0’ if=ens160 drv=vmxnet3 unused=igb_uio,vfio-pci
[root@dpdk dpdk-stable-19.11.7]# ./usertools/dpdk-devbind.py -b igb_uio 0000:03:00.0
[root@dpdk dpdk-stable-19.11.7]# ./usertools/dpdk-devbind.py -s
Network devices using DPDK-compatible driver
0000:03:00.0 ‘VMXNET3 Ethernet Controller 07b0’ drv=igb_uio unused=vmxnet3
Network devices using kernel driver
0000:02:01.0 ‘82545EM Gigabit Ethernet Controller (Copper) 100f’ if=ens33 drv=e1000 unused=igb_uio Active
http://git.dpdk.org/apps/pktgen-dpdk/refs/
wget http://git.dpdk.org/apps/pktgen-dpdk/snapshot/pktgen-dpdk-pktgen-3.7.2.tar.gz
tar -zxvf pktgen-dpdk-pktgen-3.7.2.tar.gz
cd pktgen-dpdk-pktgen-3.7.2
yum install -y meson ninja-build cmake
export RTE_SDK=/root/dpdk/dpdk-stable-19.11.7
export RTE_TARGET=x86_64-native-linux-gcc
make
编译完成后在 app/x86_64-native-linux-gcc/app/
查看编译包:
$ ll app/x86_64-native-linux-gcc/app/
total 20452
-rwxr-xr-x 1 root root 14603664 Apr 27 02:13 pktgen
-rw-r--r-- 1 root root 6336090 Apr 27 02:13 pktgen.map
修改 ./cfg/default.cfg
:
diff --git a/default.cfg b/default.cfg
index 6687739..fd543e1 100644
--- a/default.cfg
+++ b/default.cfg
@@ -7,10 +7,10 @@ setup = {
),
'devices': (
- '03:00.0', '05:00.0', '81:00.0', '84:00.0'
+ '03:00.0'
),
# UIO module type, igb_uio, vfio-pci or uio_pci_generic
- 'uio': 'vfio-pci'
+ 'uio': 'igb_uio'
}
# Run command and options
@@ -31,7 +31,7 @@ run = {
'./build/app/%(app_name)s',
),
- 'cores': '2,3-4,5-6,16-17,18-19',
+ 'cores': '2,3',
'nrank': '4',
'proc': 'auto',
'log': '7',
@@ -42,9 +42,7 @@ run = {
#'81:00.0', '84:00.0'
),
'whitelist': (
- '05:00.0,safe-mode-support=1',
- '84:00.0,safe-mode-support=1',
- '03:00.0', '81:00.0'
+ '03:00.0'
),
'opts': (
@@ -54,10 +52,7 @@ run = {
'-j',
),
'map': (
- '[3:4].0',
- '[5:6].1',
- '[16:17].2',
- '[18:19].3'
+ '1.0',
),
'theme': 'themes/black-yellow.theme'
$ ./tools/run.py -s default
>>> sdk '/root/dpdk/dpdk-stable-19.11.7', target 'x86_64-native-linux-gcc'
Setup DPDK to run 'pktgen' application from cfg/default.cfg file
$ ./tools/pktgen-run.sh default # 使用 default.cfg 运行
$ cd ./app/x86_64-native-linux-gcc/app
$ ./pktgen -l 2-3 -n 2 -- -P -m "1.0"
Copyright (c) <2010-2019>, Intel Corporation. All rights reserved. Powered by DPDK
EAL: Detected 4 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: VFIO support initialized
EAL: PCI device 0000:02:01.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 8086:100f net_e1000_em
EAL: PCI device 0000:03:00.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 15ad:7b0 net_vmxnet3
Lua 5.3.6 Copyright (C) 1994-2020 Lua.org, PUC-Rio
*** Copyright (c) <2010-2019>, Intel Corporation. All rights reserved.
*** Pktgen created by: Keith Wiles -- >>> Powered by DPDK <<<
Port: Name IfIndex Alias NUMA PCI
0: net_vmxnet3 0 0 15ad:07b0/03:00.0
Initialize Port 0 -- TxQ 1, RxQ 1
Src MAC 00:50:56:29:1b:66
<Promiscuous mode Enabled>
WARNING: Nothing to do on lcore 3: exiting
- Ports 0-0 of 1 <Main Page> Copyright (c) <2010-2019>, Intel Corporation
Flags:Port : P------Single :0
/ink State : <UP-10000-FD> ---Total Rate---
Pkts/s Max/Rx : P------Single :0 0/0
Max/Tx : <UP-10000-FD> 0/0
MBits/s Rx/Tx : 8/0 8/0
Broadcast : 0/0 0/0
Multicast : 0/0 0/0
Sizes 64 : 0
65-127 : 0
128-255 : 0
256-511 : 0
512-1023 : 0
1024-1518 : 0
Runts/Jumbos : 0
ARP/ICMP Pkts : 0
Errors Rx/Tx : 0/0
Total Rx Pkts : 0/0
Tx Pkts : 0/0
Rx MBs : 27
Tx MBs : 0
: 0
Pattern Type : 0
Tx Count/% Rate : Forever /100%
Pkt Size/Tx Burst : 64 / 64
TTL/Port Src/Dest : 4/ 1234/ 5678
Pkt Type:VLAN ID : IPv4 / TCP:0001
-- Pktgen 19.12.0 (D: 15ad:07b0/03:00.0y DPDK (pid:15760) ----------------
** Version: DPDK 19.11.7, Command Line Interface without timers
Pktgen:/>
启动参数配置说明
– 前面为 DPDK EAL 配置
- -l 2-3 : lcores
- -n 2 : Number of memory channels
– 后面为 pktgen app 配置
- -P : 允许所有端口以混杂模式运行
- -m “1.0” : port 与 lcores的绑定关系
pktgen -l 0-4 -n 3 --proc-type auto --socket-mem 256,256
-b 0000:03:00.0 -b 0000:03:00.1 \
--file-prefix pg \
-- -P -m "[1:3].0, [2:4].1
set 0 dst ip 192.168.74.132
set 0 dst mac 00:0c:29:45:e2:b9
set 0 count 100
start 0
set 0 count 1000
str # start all
ethtools -i p2pi
ethtools -K p2p1 hw-tc-offload on
ovs-vsctl set Interface dpdk0 options:rx-checksum-offload=true
ovs-vsctl set Interface dpdk0 options:dpdk-init=true
ovs-vsctl set Interface dpdk0 options:dpdk-socket-mem=true
ovs-vsctl set Interface dpdk0 options:pmd-cpu-mask=true
ovs-vsctl set Interface dpdk0 options:userspace-tso-enable=true
devbind -u
dpdk-devbind -b vfio-pci
ovs-vsctl del-port br_phy dpdk
ovs-vsctl remove Open_ . other_config dpdk-init/cpu-mask-socket-mem userspace-tso-enable
systemctl restart openvswitch
ovs-vsctl add
devbind -s
devbnd -u 44
devbind -b ixgbe 44
ethtool -i p2p1
devbind -b vfio-pic 44
start openvswitch
ovs-vsctl set Open . other_config:dpk-init=true
ovs-vsctl addppoort br-phy dpdk0 – set Interface dpdk0 type=dpdk options:dpdk-devargs=“00:44”
ethtool
dde
ovs-vsctl get Open_vSwtich . dpdk_version
/etc/sysconfig/openvswitch
当前问题
tunneling packets with HW offload flags is not support package drop
flat 网络
package dropped no tcp checksum support
1a:00.0 Ethernet controller: Intel Corporation Ethernet 10G 2P X520 Adapter (rev 01)
1a:00.1 Ethernet controller: Intel Corporation Ethernet 10G 2P X520 Adapter (rev 01)
在X86结构中,处理数据包的传统方式是CPU中断方式,既网卡驱动接收到数据包后通过中断通知CPU处理,然后由CPU拷贝数据并交给协议栈。在数据量大时,这种方式会产生大量CPU中断,导致CPU无法运行其他程序。而DPDK则采用轮询方式实现数据包处理过程:DPDK重载了网卡驱动,该驱动在收到数据包后不中断通知CPU,而是将数据包通过零拷贝技术存入内存,这时应用层程序就可以通过DPDK提供的接口,直接从内存读取数据包。这种处理方式节省了CPU中断时间、内存拷贝时间,并向应用层提供了简单易行且高效的数据包处理方式,使得网络应用的开发更加方便。但是DPDK需要网卡支持,目前以intel的网卡为主,想要知道您的网卡是否支持,可以到DPDK的官网查询:http://dpdk.org。
作者:cjzhao
链接:https://www.jianshu.com/p/072381425b3b
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
If you are not sure, check for a directory named /sys/class/misc/tun. If it does not exist, then attempt to load the module with modprobe tun
ovs-vswitchd will create a TAP device as the bridge’s local interface, named the same as the bridge, as well as for each configured internal interface.
DPDK的思路是,绕过操作系统内核,在用户空间,通过PMD(Poll Mode Driver)直接操作网卡的接收和发送队列
加载 vfio
[root@dpdk ~]# modprobe vfio-pci
[root@dpdk ~]# lsmod |grep vfio
vfio_pci 41993 0
vfio_iommu_type1 22440 0
vfio 32657 2 vfio_iommu_type1,vfio_pci
irqbypass 13503 1 vfio_pci
[root@dpdk ~]# dpdk-devbind -b vfio-pci 0000:03:00.0
Error - no supported modules(DPDK driver) are loaded
[root@dpdk ~]#
[root@dpdk ~]#
[root@dpdk ~]# modprobe vfio-pci
[root@dpdk ~]# dpdk-devbind -b vfio-pci 0000:03:00.0
Routing table indicates that interface 0000:03:00.0 is active. Not modifying
[root@dpdk ~]# dpdk-devbind -s
Network devices using kernel driver
0000:02:01.0 ‘82545EM Gigabit Ethernet Controller (Copper) 100f’ if=ens33 drv=e1000 unused=vfio-pci Active
0000:03:00.0 ‘VMXNET3 Ethernet Controller 07b0’ if=ens160 drv=vmxnet3 unused=vfio-pci Active
No ‘Crypto’ devices detected
No ‘Eventdev’ devices detected
No ‘Mempool’ devices detected
No ‘Compress’ devices detected
[root@dpdk ~]#