DPDK — TestPMD

目录

前文列表

DPDK — 安装部署

TestPMD

TestPMD 的本质是一个使用 DPDK 库实现的 DPDK Application,作用是在以太网端口之间转发数据包。通过 TestPMD 运行时的命令行,我们可用于配置端口(Port)之间的数据包转发和网卡(Network Interface)支持的其他功能。此外,我们还可以用 TestPMD 来尝试一些不同的驱动程序的功能,例如:RSS、过滤器和 Intel Ethernet Flow Director(以太网流量控制器)。

TestPMD 支持两种配置场景:

  1. TestPMD 把两个以太网端口连接到外部的流量发生器。
    在这里插入图片描述
  2. TestPMD 把两个以太网端口连成环回模式,这样就可以在没有外部流量发生器的情况下检查网络设备的接收和传输功能。
    在这里插入图片描述

TestPMD 的转发模式

  • io mode(输入/输出模式):通常也被称为 IO 模式,是最常用的转发模式,也是 TestPMD 启动时的默认模式。在该模式下,CPU 从一个端口接收数据包(Rx),并将其发送到另一个端口(Tx)。如果需要的话,一个端口可同时用于接收和发送。
  • rxonly mode(收包模式):在此模式下,TestPMD 会轮询 Rx 端口的数据包,然后直接释放而不发送,以这种方式充当数据包接收器。
  • txonly mode(发包模式):在此模式下,TestPMD 生成 64Byte 的 IP 数据包,并从 Tx 端口发送出去。不接收数据包,仅作为数据包的发送源。
  • mac mode:在转发报文前修改报文的 src MAC 地址和 dst MAC 地址。默认的行为是将 src MAC 地址设置为转发接口的 MAC 地址,将 dst MAC 地址设置为预设的 MAC 地址,可以通过 eth-peer 或 eth-peers-configfile 命令参数,在程序启动时配置预设 MAC 地址。目前还不支持对 src MAC 地址进行预设。
  • macswap mode:MAC 交换转发模式,在转发报文之前交换报文的 src MAC 地址和 dst MAC 地址。
  • flowgen mode:多数据流生成模式,根据不同的 dst IP 地址生成一组数据流,同时终结接收到的流量。
  • csum mode:根据报文的 offload 标记,通过硬件或软件方法修改报文的 checksum 字段。
  • icmpecho mode:接收一组报文,查找是否有 ICMP echo 请求,如果有,就回应 ICMP echo reply。
  • ieee1588 mode:演示对 Rx 和 Tx 基于 L2 IEEE1588 V2 PTP 时间同步特性,需要配置 CONFIG_RTE_LIBRTE_IEEE1588=y。
  • softnic mode:演示软网卡的转发操作,在此模式下,报文转发和 I/O 模式相似,区别在于实际上报文只在 loopback 软网卡接口上转发。因此,portmask 参数只能设置为软网卡端口。各种基于 softnic 固件(DPDK packet framework script)指定的自定义 NIC 软件网卡可以在此模式下进行测试,除此之外,还可以通过 CLI 使能,生成 5 级的 QoS 调度器作为默认的选项。用户可以修改默认的调度器或者通过 CLI 指定新的 QoS 调度器,此模式需要配置 CONFIG_RTE_LIBRTE_PMD_SOFTNIC=y。
  • noisy mode:噪音环境模拟,模拟多个真实客户机器的行为,接收和发送 VNF(Virtual Network Function)报文。

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 <mbuf_pool_socket_0>: 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 <mbuf_pool_socket_0>: 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> 
  • -l:指定运行 TestPMD 的 lcore,Core 1 用于管理命令行,Core 2、3 用于转发数据包。
  • -n:指定系统的内存通道数。
  • –:用于分开 EAL 参数和应用程序参数。

检查转发配置:

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.
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客
应支付0元
点击重新获取
扫码支付

支付成功即可阅读