TRex,一個基於DPDK的數據包發生器,測試儀


1. introduction

  TRex是cisco基於Intel dpdk開發的軟件程序。推薦在CentOS/RHEL 7.6, 64bits中運行,否則connectx-4網卡不可使用。

筆者在Ubuntu16.04中Intel-XL710網卡測試也成功。

  使用中高端服務器和最新的Intel網卡,TRex的發包性能可達到200Gbps,使用某些類型的網卡還支持基於硬件的每流統計量匯報(Intel-XL710 支持255條獨立流)。

2. installation

mkdir -p /opt/trex

cd /opt/trex

wget --no-cache https://trex-tgn.cisco.com/trex/release/latest

tar -xzvf latest

  至此就結束了安裝,解壓出來都是可執行文件。

  另外,需要配置網卡設置:

sudo ./dpdk_setup_ports.py -s
# 查看網絡接口配置

  設置配置文件,例如:給DPDK驅動使用:

cp  cfg/simple_cfg.yaml /etc/trex_cfg.yaml
#拷貝例子到默認配置文件路徑

  根據接口情況手動修改配置文件:

sudo vim /etc/trex_cfg.yaml
<none>
- port_limit      : 2
  version         : 2
interfaces    : ["03:00.0", "03:00.1"]  #需要對此進行手動調整,填寫網口pcie編號
port_info       :  
          - ip         : 1.1.1.1
            default_gw : 2.2.2.2
          - ip         : 2.2.2.2
            default_gw : 1.1.1.1

 

3. 配置多流流量

    sudo vim /opt/trex/v2.61/stl/simple_3pkt.py

def create_stream (self):

        # create a base packet and pad it to size
        size = self.fsize - 4 # no FCS
        base_pkt =  Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)       1
        base_pkt1 =  Ether()/IP(src="16.0.0.2",dst="48.0.0.1")/UDP(dport=12,sport=1025)
        base_pkt2 =  Ether()/IP(src="16.0.0.3",dst="48.0.0.1")/UDP(dport=12,sport=1025)
        pad = max(0, size - len(base_pkt)) * 'x'


        return STLProfile( [ STLStream( isg = 0.0,
                                        packet = STLPktBuilder(pkt = base_pkt/pad),
                                        mode = STLTXCont( pps = 10),                         2
                                        ),

                             STLStream( isg = 25000.0, #defined in usec, 25 msec
                                        packet  = STLPktBuilder(pkt = base_pkt1/pad),
                                        mode    = STLTXCont( pps = 20),                      3
                                        ),

                             STLStream(  isg = 50000.0,#defined in usec, 50 msec
                                         packet = STLPktBuilder(pkt = base_pkt2/pad),
                                         mode    = STLTXCont( pps = 40)                      4

                                        )
                            ]).get_streams()

  可分別對三種流量包頭配置(IP),速度配置(PPS),啟動時間配置(isg)。

4. 啟動TRex,測試雙網口網卡回環。

  將光線兩端分別接入網卡的兩個口。

  打開命令行終端,並開啟TRex服務端程序:

sudo ./t-rex-64 -i 
# t-rex-64 是可執行文件,在安裝目錄中

  打開另外一個命令行終端,開啟TRex客戶端程序:

trex-console  

  在客戶端程序中開啟流量發送:

start -f stl/simple_3pkt.py -a

  常用操作:

pause -a 
#暫停所有發送

tui
#流量統計信息

  另外一個比較有用的操作是可以根據流量配置文件生成對應的pcap文件,在流量發送之前,

通過視察pcap文件,我們可以測試配置腳本是否正確:

sudo ./stl-sim -f stl/udp_1pkt_range_clients_splita.py -o flow1a64Byte60000.pcap -l 60000
#-o 輸出文件名 -l 總包數

5. 啟動硬件每流測量

  編寫流量配置文件,其中需要設置流ID(pg_id = 7),以及打開統計功能(flow_stats) ,stl/4flow_stats.py:

from trex_stl_lib.api import *

class STLS1(object):

    def __init__ (self):
        self.fsize  =128; # the size of the packet


    def create_stream (self):

        # Create base packet and pad it to size
        size = self.fsize - 4; # HW will add 4 bytes ethernet FCS
        base_pkt =  Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)
        base_pkt1 =  Ether()/IP(src="16.0.0.2",dst="48.0.0.1")/UDP(dport=12,sport=1025)
        base_pkt2 =  Ether()/IP(src="16.0.0.3",dst="48.0.0.1")/UDP(dport=12,sport=1025)
        base_pkt3 =  Ether()/IP(src="16.0.0.4",dst="48.0.0.1")/UDP(dport=12,sport=1025)
        pad = max(0, size - len(base_pkt)) * 'x'


        return STLProfile( [ STLStream( isg = 1.0, # start in delay in usec
                                        packet = STLPktBuilder(pkt = base_pkt/pad),
                                        mode = STLTXCont( pps = 27500),
                                        flow_stats = STLFlowStats(pg_id = 7),
                                        ),

                             STLStream( isg = 2.0,
                                        packet  = STLPktBuilder(pkt = base_pkt1/pad),
                                        mode    = STLTXCont( pps = 27500),
                                        flow_stats = STLFlowStats(pg_id = 12),
                                        ),

                             STLStream(  isg = 3.0,
                                         packet = STLPktBuilder(pkt = base_pkt2/pad),
                                         mode    = STLTXCont( pps = 27500),
                                         flow_stats = STLFlowStats(pg_id = 15),

                                        ),
                             STLStream( isg = 4.0,
                                        packet = STLPktBuilder(pkt = base_pkt3/pad),
                                        mode    = STLTXCont( pps =27500),
                                        flow_stats = STLFlowStats(pg_id = 17),

                                        )
                            ]).get_streams()


    def get_streams (self, direction = 0, **kwargs):
        # create 1 stream
        return self.create_stream()


# dynamic load - used for trex console or simulator
def register():
    return STLS1()

  開始流量:

start -f stl/4flow_stats.py -a

  打開監控:

tui

  打開每流顯示:

#對於版本不同可能采用不同方式, v2.6的打開方式如下:
# 先按下esc
# 再按下x,啟動每流監控

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM