本文介紹了數據平面開發工具包(DPDK)TestPMD應用程序,展示了如何構建和配置TestPMD, 以及如何用它來檢查使用DPDK的不同網絡設備的性能和功能。
TestPMD是一個使用DPDK軟件包分發的參考應用程序。其主要目的是在網絡接口的以太網端口之間轉發數據包。此外,用戶還可以用TestPMD嘗試一些不同驅動程序的功能,例如RSS,過濾器和英特爾®以太網流量控制器(Intel® Ethernet Flow Director)。
我們還將研究TestPMD運行時的命令行,命令行可用於配置端口之間的數據包轉發和網絡接口支持的其他功能。TestPMD應用程序適用於所有版本的DPDK。
TestPMD的配置示例
為了展示如何使用TestPMD,我們會考慮兩個典型的硬件設置。
如圖1所示,第一個配置,TestPMD應用程序把兩個以太網口連接到外部的流量發生器。這樣用戶可以在不同的網絡工作負載下測試吞吐量和功能。
第二個設置,TestPMD應用程序把兩個以太網端口連成環回模式。 這樣用戶可以在沒有外部流量發生器的情況下檢查網絡設備的接收和傳輸功能。
轉發模式
TestPMD可以使用如下幾種不同的轉發模式。
輸入/輸出模式(INPUT/OUTPUT MODE)
此模式通常稱為IO模式,是最常用的轉發模式,也是TestPMD啟動時的默認模式。 在IO模式下,CPU內核從一個端口接收數據包(Rx),並將其發送到另一個端口(Tx)。 如果需要的話,一個端口可同時用於接收和發送。
收包模式(RX-ONLY MODE)
在此模式下,應用程序會輪詢Rx端口的數據包,然后直接釋放而不發送。 它以這種方式充當數據包接收器。
發包模式(TX-ONLY MODE)
在此模式下,應用程序生成64字節的IP數據包,並從Tx端口發送出去。 它不接收數據包,僅作為數據包源。
后兩種模式(收包模式和發包模式)對於單獨檢查收包或者發包非常有用。
除了這三種模式,TestPMD文檔中還介紹了其他一些轉發模式。
編譯、准備TestPMD
以下步驟用於編譯和設置TestPMD應用程序:
1.如下命令從源目錄中編譯DPDK,默認也編譯了TestPMD應用程序:
1
|
$ make config T = x86_64-native-linuxapp-gcc
|
2.初始化內核模塊uio:
1
|
$ sudo modprobe uio
|
3.加載內核模塊igb_uio:
1
|
$ sudo insmod ./build/kmod/igb_uio.ko
|
4.預留大頁內存以供DPDK TestPMD 應用程序使用,最簡單的方法是通過使用DPDK附帶的dpdk-setup.sh腳本工具(更多信息請參閱DPDK Getting Started Guide):
1
|
$ sudo ./usertools/dpdk-setup.sh
|
5.將網絡接口端口綁定到igb_uio。舉例來說,我們假設使用的端口PCI地址為0000:83:00.1和0000:87:00.1:(可左右滑動↓)
1
|
$ sudo ./usertools/dpdk-devbind.py -b igb_uio 0000:83:00.1 0000:87:00.1
|
運行TestPMD
TestPMD可以使用一系列命令行參數在非交互模式下運行,也可以使用-i選項運行在交互模式,來實時接收命令行。實時命令行可以動態配置TestPMD:(可左右滑動↓)
1
|
$ sudo ./build/app/testpmd –l 12,13,14 –n 4 -- -i
|
在此例中, –l選項指定了邏輯核。核12用於管理命令行,核13和14將用於轉發數據包。 -n選項用於指定系統的內存通道數。–(破折號)分開了EAL參數和應用程序參數。程序運行時可以看到如下所示的輸出:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
$ sudo ./build/app/testpmd –l 12,13,14 –n 4 -- -i
EAL: Detected 40 lcore(s)
EAL: Probing VFIO support...
EAL: PCI device 0000:83:00.0 on NUMA socket 1
EAL: probe driver: 8086:10fb net_ixgbe
EAL: PCI device 0000:83:00.1 on NUMA socket 1
EAL: probe driver: 8086:10fb net_ixgbe
EAL: PCI device 0000:87:00.0 on NUMA socket 1
EAL: probe driver: 8086:10fb net_ixgbe
EAL: PCI device 0000:87:00.1 on NUMA socket 1
EAL: probe driver: 8086:10fb net_ixgbe
Interactive-mode selected
USER1: create a new mbuf pool <mbuf_pool_socket_0>:
n=163456, size=2176, socket=0
Configuring Port 0 (socket 0)
Port 0: 00:1B:21:B3:44:51
Configuring Port 1 (socket 0)
Port 1: 00:1B:21:57:EE:71
Checking link statuses...
Port 0 Link Up - speed 10000 Mbps - full-duplex
Port 1 Link Up - speed 10000 Mbps - full-duplex
Done
testpmd>
|
testpmd>提示符允許用戶輸入命令,這被稱為實時命令行。例如,我們可以用它來輸入命令,來檢查轉發配置:
1
2
3
4
5
6
|
testpmd> show config fwd
io packet forwarding - ports=2 - cores=1 - streams=2
- NUMA support disabled, MP over anonymous pages disabled
Logical Core 13 (socket 1) 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
|
這表明TestPMD正使用前面介紹過的默認io轉發模式,同時也表明核13(第二個啟用的內核)將輪詢端口0上的數據包,然后轉發到端口1,反之亦然。 核12,也就是命令行中第一個核正用於處理運實時命令行本身。
要開始轉發,只需鍵入命令’start’:
1
|
testpmd> start
|
然后,要檢查端口之間是否有包正在轉發,執行以下命令來顯示應用程序正在使用的所有端口的統計信息:(可左右滑動↓)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
testpmd> show port stats all
################### NIC statistics for port 0 ######################
RX-packets: 8480274 RX-missed: 0 RX-bytes: 508816632
RX-errors: 0
RX-nombuf: 0
TX-packets: 5763344 TX-errors: 0 TX-bytes: 345800320
Throughput (since last show)
Rx-pps: 1488117
Tx-pps: 1488116
############################################################
################### NIC statistics for port 1 ######################
RX-packets: 5763454 RX-missed: 0 RX-bytes: 345807432
RX-errors: 0
RX-nombuf: 0
TX-packets: 8480551 TX-errors: 0 TX-bytes: 508832612
Throughput (since last show)
Rx-pps: 1488085
Tx-pps: 1488084
############################################################
|
此輸出顯示了應用程序開始轉發后的所有數據包總數,包含有這兩個端口接收和發送的數據包數。吞吐率是以數據包每秒來顯示的。在這個例子中,所有端口上接收到的包都以理論線速14.88Mpps往外轉發。線速是指給定數據包大小和網絡接口的最大速度。若要停止轉發,只需輸入 stop,這會停止轉發並顯示兩個端口的累計統計數字以及一個概要。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
testpmd> stop
Telling cores to stop...
Waiting for lcores to finish...
------------------ Forward statistics for port 0 ----------------------
RX-packets: 136718750 RX-dropped: 0 RX-total: 136718750
TX-packets: 136718750 TX-dropped: 0 TX-total: 136718750
---------------------------------------------------------------------
------------------ Forward statistics for port 1 ----------------------
RX-packets: 136718750 RX-dropped: 0 RX-total: 136718750
TX-packets: 136718750 TX-dropped: 0 TX-total: 136718750
---------------------------------------------------------------------
++++++++++Accumulated forward statistics for all ports +++++++++
RX-packets: 273437500 RX-dropped: 0 RX-total: 273437500
TX-packets: 273437500 TX-dropped: 0 TX-total: 273437500
+++++++++++++++++++++++++++++++++++++++++++++++++++
|
使用多核
對於一個核不足以轉發所有收到的包的情況,多核可以用於處理來自不同端口的數據包。在前面的例子中,核 13和14可用於轉發數據包,但只有核 13被用到了。要啟用另一個核,我們可以使用以下命令:
1
2
3
4
5
6
7
8
9
10
|
testpmd> set nbcore 2
testpmd> show config fwd
io packet forwarding - ports=2 - cores=2 - streams=2
- NUMA support disabled, MP over anonymous pages disabled
Logical Core 13 (socket 1) 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 14 (socket 1) forwards packets on 1 streams:
RX P=1/Q=0 (socket 0) -> TX P=0/Q=0 (socket 0) peer=02:00:00:00:00:00
|
這樣核13將從端口0接收數據包,並從端口1發送數據包,而core14將接收來自端口1的數據包,並從端口0上發送。
改變轉發模式
如上所述,TestPMD具有不同的轉發模式。若要將轉發模式更改為收包模式,我們可以使用set fwd命令:
1
2
|
testpmd> set fwd rxonly
testpmd> start
|
現在,如果我們看端口統計數據,可以看到只有接收到的數據包才會顯示。由於沒有發送的數據包,Tx數據仍然為0:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
testpmd> show port stats all
####################### NIC statistics for port 0 ##########################
RX-packets: 524182888 RX-missed: 0 RX-bytes: 31450974816
RX-errors: 0
RX-nombuf: 0
TX-packets: 0 TX-errors: 0 TX-bytes: 0
Throughput (since last show)
Rx-pps: 14880770
Tx-pps: 0
####################################################################
####################### NIC statistics for port 1 ##########################
RX-packets: 486924876 RX-missed: 0 RX-bytes: 29215494352
RX-errors: 0
RX-nombuf: 0
TX-packets: 0 TX-errors: 0 TX-bytes: 0
Throughput (since last show)
Rx-pps: 14880788
Tx-pps: 0
####################################################################
|
在TestPMD獲得幫助
TestPMD為運行時可用的命令提供在線幫助。這些幫助分為幾個部分,可以通過幫助命令獲取。
1
|
testpmd> help
|
以下部分可用“幫助”:
1
2
3
4
5
6
7
|
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.
|
例如,要獲取有關顯示數據和其他信息的命令的幫助:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
testpmd> help display
Display:
--------
show port (info|stats|xstats|fdir|stat_qmap|dcb_tc|cap) (port_id|all)
Display information for port_id, or all.
show port X rss reta (size) (mask0,mask1,...)
Display the rss redirection table entry indicated by masks on port X. size is used to indicate the hardware supported reta size
show port rss-hash ipv4|ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2-payload|ipv6-ex|ipv6-tcp-ex|ipv6-udp-ex [key]
Display the RSS hash functions and RSS hash key of port X
clear port (info|stats|xstats|fdir|stat_qmap) (port_id|all)
Clear information for port_id, or all.
show (rxq|txq) info (port_id) (queue_id)
Display information for configured RX/TX queue.
show config (rxtx|cores|fwd|txpkts)
Display the given configuration.
read rxd (port_id) (queue_id) (rxd_id)
Display an RX descriptor of a port RX queue.
read txd (port_id) (queue_id) (txd_id)
Display a TX descriptor of a port TX queue.
|
結論
本文研究了如何編譯、設置和運行TestPMD以及如何通過實時命令行進行配置。
原文:DPDK開源社區