《DPDK — 安装部署》
TestPMD 的本质是一个使用 DPDK 库实现的 DPDK Application,作用是在以太网端口之间转发数据包。通过 TestPMD 运行时的命令行,我们可用于配置端口(Port)之间的数据包转发和网卡(Network Interface)支持的其他功能。此外,我们还可以用 TestPMD 来尝试一些不同的驱动程序的功能,例如:RSS、过滤器和 Intel Ethernet Flow Director(以太网流量控制器)。
TestPMD 支持两种配置场景:
测试 testpmd 是否可用:
$ cd ${RTE_SDK}/${RTE_TARGET}/build/app/test-pmd
$ ./testpmd
EAL: Detected 6 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
EAL: VFIO support initialized
EAL: WARNING: cpu flags constant_tsc=yes nonstop_tsc=no -> using unreliable clock cycles !
EAL: PCI device 0000:00:03.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 1af4:1000 net_virtio
EAL: PCI device 0000:00:05.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 15b3:1018 net_mlx5
EAL: PCI device 0000:00:06.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 15b3:1018 net_mlx5
EAL: PCI device 0000:00:07.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 15b3:1018 net_mlx5
testpmd: create a new mbuf pool : n=187456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc
Warning! port-topology=paired and odd forward ports number, the last port will pair with itself.
Configuring Port 0 (socket 0)
Port 0: FA:16:3E:FF:38:D2
Configuring Port 1 (socket 0)
Port 1: FA:16:3E:CD:4A:1D
Configuring Port 2 (socket 0)
Port 2: FA:16:3E:FE:FB:FA
Checking link statuses...
Done
No commandline core given, start packet forwarding
io packet forwarding - ports=3 - cores=1 - streams=3 - NUMA support enabled, MP over anonymous pages disabled
Logical Core 1 (socket 0) forwards packets on 3 streams:
RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
RX P=2/Q=0 (socket 0) -> TX P=2/Q=0 (socket 0) peer=02:00:00:00:00:02
io packet forwarding packets/burst=32
nb forwarding cores=1 - nb forwarding ports=3
port 0: RX queue number: 1 Tx queue number: 1
Rx offloads=0x1000 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0
RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0
TX offloads=0x0 - TX RS bit threshold=0
port 1: RX queue number: 1 Tx queue number: 1
Rx offloads=0x1000 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0
RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0
TX offloads=0x0 - TX RS bit threshold=0
port 2: RX queue number: 1 Tx queue number: 1
Rx offloads=0x1000 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0
RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0
TX offloads=0x0 - TX RS bit threshold=0
Press enter to exit
进入 testpmd 交互环境:
$ ./testpmd -l 1,2,3 --socket-mem 1024 -n 4 --log-level=8 -- -i
EAL: Detected 6 lcore(s)
EAL: Detected 1 NUMA nodes
EAL: Multi-process socket /var/run/dpdk/rte/mp_socket
EAL: No free hugepages reported in hugepages-1048576kB
EAL: Probing VFIO support...
EAL: VFIO support initialized
EAL: WARNING: cpu flags constant_tsc=yes nonstop_tsc=no -> using unreliable clock cycles !
EAL: PCI device 0000:00:03.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 1af4:1000 net_virtio
EAL: PCI device 0000:00:05.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 15b3:1018 net_mlx5
EAL: PCI device 0000:00:06.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 15b3:1018 net_mlx5
EAL: PCI device 0000:00:07.0 on NUMA socket -1
EAL: Invalid NUMA socket, default to 0
EAL: probe driver: 15b3:1018 net_mlx5
Interactive-mode selected
testpmd: create a new mbuf pool : n=163456, size=2176, socket=0
testpmd: preferred mempool ops selected: ring_mp_mc
Warning! port-topology=paired and odd forward ports number, the last port will pair with itself.
Configuring Port 0 (socket 0)
Port 0: FA:16:3E:FF:38:D2
Configuring Port 1 (socket 0)
Port 1: FA:16:3E:CD:4A:1D
Configuring Port 2 (socket 0)
Port 2: FA:16:3E:FE:FB:FA
Checking link statuses...
Done
testpmd>
检查转发配置:
testpmd> show config fwd
io packet forwarding - ports=3 - cores=1 - streams=3 - NUMA support enabled, MP over anonymous pages disabled
Logical Core 2 (socket 0) forwards packets on 3 streams:
RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
RX P=2/Q=0 (socket 0) -> TX P=2/Q=0 (socket 0) peer=02:00:00:00:00:02
这表明 TestPMD 正使用默认的 IO 转发模式,同时也表明 lcore 2(第二个启用的 Core)将用于轮询 Port 0 上的数据包并转发到 Port 1,反之亦然。 lcore 1 用于处理运实时命令行本身。
要开始转发,并检查端口之间是否有包正在转发:
testpmd> start
io packet forwarding - ports=2 - cores=1 - streams=2 - NUMA support enabled, MP over anonymous pages disabled
Logical Core 2 (socket 0) forwards packets on 2 streams:
RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
io packet forwarding packets/burst=32
nb forwarding cores=1 - nb forwarding ports=2
port 0: RX queue number: 1 Tx queue number: 1
Rx offloads=0x1000 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0
RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0
TX offloads=0x0 - TX RS bit threshold=0
port 1: RX queue number: 1 Tx queue number: 1
Rx offloads=0x1000 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0
RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0
TX offloads=0x0 - TX RS bit threshold=0
testpmd> show port stats all
######################## NIC statistics for port 0 ########################
RX-packets: 8361530 RX-missed: 0 RX-bytes: 2859643260
RX-errors: 0
RX-nombuf: 0
TX-packets: 9067686 TX-errors: 0 TX-bytes: 3101148612
Throughput (since last show)
Rx-pps: 835482
Tx-pps: 929853
############################################################################
######################## NIC statistics for port 1 ########################
RX-packets: 9067772 RX-missed: 0 RX-bytes: 3101178024
RX-errors: 0
RX-nombuf: 0
TX-packets: 8361605 TX-errors: 0 TX-bytes: 2859668910
Throughput (since last show)
Rx-pps: 929878
Tx-pps: 835498
############################################################################
此输出显示了 TestPMD 开始转发后的所有数据包总数,包含有这两个端口接收和发送的数据包数。吞吐率是以数据包每秒来显示的。在这个例子中,TestPMD 会自动发包、收发以测试端口的收发速率,可以看见,所有端口上接收到的包都以 8.35Mp/s 往外转发的。需要注意,可以转发的前提是 Port 0 和 Port 1 的物理链路是连通的,否则会出现收发包为 0 的情况。
若要停止转发,只需输入 stop,这会停止转发并显示两个端口的累计统计数字以及一个概要:
testpmd> stop
Telling cores to stop...
Waiting for lcores to finish...
---------------------- Forward statistics for port 0 ----------------------
RX-packets: 10975869 RX-dropped: 0 RX-total: 10975869
TX-packets: 11964848 TX-dropped: 0 TX-total: 11964848
----------------------------------------------------------------------------
---------------------- Forward statistics for port 1 ----------------------
RX-packets: 11964848 RX-dropped: 0 RX-total: 11964848
TX-packets: 10975869 TX-dropped: 0 TX-total: 10975869
----------------------------------------------------------------------------
+++++++++++++++ Accumulated forward statistics for all ports+++++++++++++++
RX-packets: 22940717 RX-dropped: 0 RX-total: 22940717
TX-packets: 22940717 TX-dropped: 0 TX-total: 22940717
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Done.
退出:
testpmd> quit
Shutting down port 0...
Stopping ports...
Done
Closing ports...
Done
Shutting down port 1...
Stopping ports...
Done
Closing ports...
Done
Shutting down port 2...
Stopping ports...
Done
Closing ports...
Done
Bye...
Shutting down port 0...
Stopping ports...
Done
Closing ports...
Port 0 is already closed
Done
Shutting down port 1...
Stopping ports...
Done
Closing ports...
Port 1 is already closed
Done
Shutting down port 2...
Stopping ports...
Done
Closing ports...
Port 2 is already closed
Done
Bye...
对于一个核不足以转发所有收到的包的场景中,多核可以用于处理来自不同端口的数据包。在前面的例子中,Core 2、3 都可用于转发数据包,但默认情况下只有 Core 2 被用到了。要启用另一个核,我们可以使用以下命令:
testpmd> set nbcore 2
Number of forwarding cores set to 2
testpmd> show config fwd
txonly packet forwarding - ports=3 - cores=2 - streams=3 - NUMA support enabled, MP over anonymous pages disabled
Logical Core 2 (socket 0) forwards packets on 1 streams:
RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
Logical Core 3 (socket 0) forwards packets on 2 streams:
RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
RX P=2/Q=0 (socket 0) -> TX P=2/Q=0 (socket 0) peer=02:00:00:00:00:02
这样 Core2 将从 Port 0 接收数据包并转发到 Port 1 发送数据包,而 Core3 将接收来自 Port 1 的数据包,并从 Port 0 上发送。
如上所述,TestPMD 具有不同的转发模式。若要将转发模式更改为发包模式,我们可以使用 set fwd 命令:
testpmd> set fwd txonly
Set txonly packet forwarding mode
testpmd> start
txonly packet forwarding - ports=3 - cores=1 - streams=3 - NUMA support enabled, MP over anonymous pages disabled
Logical Core 2 (socket 0) forwards packets on 3 streams:
RX P=0/Q=0 (socket 0) -> TX P=1/Q=0 (socket 0) peer=02:00:00:00:00:01
RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
RX P=2/Q=0 (socket 0) -> TX P=2/Q=0 (socket 0) peer=02:00:00:00:00:02
txonly packet forwarding packets/burst=32
packet len=64 - nb packet segments=1
nb forwarding cores=1 - nb forwarding ports=3
port 0: RX queue number: 1 Tx queue number: 1
Rx offloads=0x1000 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0
RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0
TX offloads=0x0 - TX RS bit threshold=0
port 1: RX queue number: 1 Tx queue number: 1
Rx offloads=0x1000 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0
RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0
TX offloads=0x0 - TX RS bit threshold=0
port 2: RX queue number: 1 Tx queue number: 1
Rx offloads=0x1000 Tx offloads=0x0
RX queue: 0
RX desc=0 - RX free threshold=0
RX threshold registers: pthresh=0 hthresh=0 wthresh=0
RX Offloads=0x0
TX queue: 0
TX desc=0 - TX free threshold=0
TX threshold registers: pthresh=0 hthresh=0 wthresh=0
TX offloads=0x0 - TX RS bit threshold=0
testpmd> show port stats all
######################## NIC statistics for port 0 ########################
RX-packets: 0 RX-missed: 0 RX-bytes: 0
RX-errors: 0
RX-nombuf: 0
TX-packets: 12099712 TX-errors: 0 TX-bytes: 774381568
Throughput (since last show)
Rx-pps: 0
Tx-pps: 561119
############################################################################
######################## NIC statistics for port 1 ########################
RX-packets: 0 RX-missed: 0 RX-bytes: 0
RX-errors: 0
RX-nombuf: 0
TX-packets: 12084672 TX-errors: 0 TX-bytes: 773419008
Throughput (since last show)
Rx-pps: 0
Tx-pps: 560421
############################################################################
######################## NIC statistics for port 2 ########################
RX-packets: 0 RX-missed: 0 RX-bytes: 0
RX-errors: 0
RX-nombuf: 0
TX-packets: 12086720 TX-errors: 0 TX-bytes: 773550080
Throughput (since last show)
Rx-pps: 0
Tx-pps: 560514
############################################################################
testpmd> help
Help is available for the following sections:
help control : Start and stop forwarding.
help display : Displaying port, stats and config information.
help config : Configuration information.
help ports : Configuring ports.
help registers : Reading and setting port registers.
help filters : Filters configuration help.
help all : All of the above sections.