快速记录一下 dpdk-l3fwd 的使用过程。
dpdk-l3fwd 是 dpdk 中的 3 层转发示例程序,可以用来测试系统的转发性能。在转发测试中,我们需要用到两台机器,一台用来发包,一台用来转发。
前置工作:
- 在发包的机器上安装 dpdk 和 dpdk-pktgen
- 在转发的机器上安装 dpdk
上述准备工作可以参看 dpdk-20.11 的编译和安装 和 dpdk-pktgen 的安装和基本使用。
编译 l3fwd:
在转发的机器上进入 l3fwd 的源码目录(dpdk-stable/examples/l3fwd/),直接 make 就可以,前提是已安装好 dpdk。或者是通过 meson 来编译,在 meson 的命令参数中指定编译 l3fwd : meson -Dexamples=l3fwd build,若之前已经构建过,则通过 meson --reconfigure -Dexamples=l3fwd build 来指定。
运行 l3fwd:
l3fwd 支持的命令行参数也不少,像 dpdk 的其他示例程序一样,也分为 EAL 参数部分和 l3fwd 自有参数部分。EAL 参数部分可以参看 DPDK EAL parameter。l3fwd 自有参数部分如下所示:
./dpdk-l3fwd [EAL options] -- -p PORTMASK
[-P]
[--lookup LOOKUP_METHOD]
--config(port,queue,lcore)[,(port,queue,lcore)]
[--eth-dest=X,MM:MM:MM:MM:MM:MM]
[--enable-jumbo [--max-pkt-len PKTLEN]]
[--no-numa]
[--hash-entry-num]
[--ipv6]
[--parse-ptype]
[--per-port-pool]
[--mode]
[--eventq-sched]
[--event-eth-rxqs]
[-E]
[-L]
同样,只挑最重要的几个参数来看,以便快速入门。
- -p PortMask 参数指定使用的网口掩码,例如,假设当前有 4 个网口由 dpdk 进行管理,则 0x3 表示使用网口 0 和 网口 1,0xf 表示使用网口 0、网口 1、网口 2 和网口 3。
- -P 参数表示将所有网口设置为混杂模式,以便收到所有数据包。
- --config (port,queue,lcore)[,(port,queue,lcore)] 参数用以配置网口、队列、核之间的对应关系,例如,--config (0,0,1) 表示网口 0 的队列 0 由核 1 进行处理。
运行效果:
$ ./examples/l3fwd/build/l3fwd -l 1-2 -n 4 -- -P -p 0x3 --config="(0,0,1),(1,0,2)"
EAL: Detected 4 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Detected shared linkage of DPDK
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: Selected IOVA mode 'PA'
EAL: Probing VFIO support...
EAL: Probe PCI driver: net_ixgbe (8086:154d) device: 0000:03:00.0 (socket 0)
EAL: Probe PCI driver: net_ixgbe (8086:154d) device: 0000:03:00.1 (socket 0)
EAL: Probe PCI driver: net_ixgbe (8086:154d) device: 0000:04:00.0 (socket 0)
EAL: Probe PCI driver: net_ixgbe (8086:154d) device: 0000:04:00.1 (socket 0)
EAL: No legacy callbacks, legacy socket not created
LPM or EM none selected, default LPM on
Initializing port 0 ... Creating queues: nb_rxq=1 nb_txq=2... Port 0 modified RSS hash function based on hardware support,requested:0xa38c configured:0x8104
Address:A0:36:9F:30:7A:D8, Destination:02:00:00:00:00:00, Allocated mbuf pool on socket 0
LPM: Adding route 198.18.0.0 / 24 (0)
LPM: Adding route 198.18.1.0 / 24 (1)
LPM: Adding route 2001:200:: / 64 (0)
LPM: Adding route 2001:200:0:1:: / 64 (1)
txq=1,0,0 txq=2,1,0
Initializing port 1 ... Creating queues: nb_rxq=1 nb_txq=2... Port 1 modified RSS hash function based on hardware support,requested:0xa38c configured:0x8104
Address:A0:36:9F:30:7A:DA, Destination:02:00:00:00:00:01, txq=1,0,0 txq=2,1,0
Skipping disabled port 2
Skipping disabled port 3
Initializing rx queues on lcore 1 ... rxq=0,0,0
Initializing rx queues on lcore 2 ... rxq=1,0,0
Checking link statusdone
Port 0 Link up at 10 Gbps FDX Autoneg
Port 1 Link up at 10 Gbps FDX Autoneg
L3FWD: entering main loop on lcore 1
L3FWD: -- lcoreid=1 portid=0 rxqueueid=0
L3FWD: entering main loop on lcore 2
L3FWD: -- lcoreid=2 portid=1 rxqueueid=0
值得注意的是,上述输出中打印了 l3fwd 的默认路由规则,即:
LPM: Adding route 198.18.0.0 / 24 (0)
LPM: Adding route 198.18.1.0 / 24 (1)
LPM: Adding route 2001:200:: / 64 (0)
LPM: Adding route 2001:200:0:1:: / 64 (1)
也就是说,目的 IP 为 198.18.0.0/24 段的数据包将会通过网口 0 进行转发,目的 IP 为 198.18.1.0 / 24 段的数据包将会通过网口 1 进行转发。上述默认路由规则是在源码中配置的,代码如下:
/*
* 198.18.0.0/16 are set aside for RFC2544 benchmarking (RFC5735).
* 198.18.{0-7}.0/24 = Port {0-7}
*/
static const struct ipv4_l3fwd_lpm_route ipv4_l3fwd_lpm_route_array[] = {
{RTE_IPV4(198, 18, 0, 0), 24, 0},
{RTE_IPV4(198, 18, 1, 0), 24, 1},
{RTE_IPV4(198, 18, 2, 0), 24, 2},
{RTE_IPV4(198, 18, 3, 0), 24, 3},
{RTE_IPV4(198, 18, 4, 0), 24, 4},
{RTE_IPV4(198, 18, 5, 0), 24, 5},
{RTE_IPV4(198, 18, 6, 0), 24, 6},
{RTE_IPV4(198, 18, 7, 0), 24, 7},
};