公司测试仪器紧张,打算安装Trex做简单的测试。如下下载最新的trex工程。

rz@trex:~$ sudo mkdir /opt/trex
rz@trex:~$ cd /opt/trex/
rz@trex:/opt/trex$
rz@trex:/opt/trex$ sudo wget --no-cache https://trex-tgn.cisco.com/trex/release/latest --no-check-certificate
--2024-06-11 08:51:28--  https://trex-tgn.cisco.com/trex/release/latest
Resolving trex-tgn.cisco.com (trex-tgn.cisco.com)... 173.36.109.208
Connecting to trex-tgn.cisco.com (trex-tgn.cisco.com)|173.36.109.208|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 248025436 (237M) [application/x-tar]
Saving to: ‘latest’

latest                           100%[==========================================================>] 236.54M  2.13MB/s    in 2m 25s  

2024-06-11 08:53:53 (1.63 MB/s) - ‘latest’ saved [248025436/248025436]

解压,得到版本v3.04。

rz@trex:/opt/trex$ sudo tar -xf latest
rz@trex:/opt/trex$ ls
latest  v3.04
rz@trex:/opt/trex$ cd v3.04/
rz@trex:/opt/trex/v3.04$

运行脚本dpdk_setup_ports.py,配置trex使用的网卡。需要配置偶数的接口数量,可以使用ID,PCI地址或者linux接口名称来指定trex使用的接口。这里根据ID,指定ID为4和5的接口,即linux接口enp7s0和enp8s0。

rz@trex:/opt/trex/v3.04$ sudo ./dpdk_setup_ports.py -i
By default, IP based configuration file will be created. Do you want to use MAC based config? (y/N)
+----+------+---------+-------------------+---------------------------------+--------+----------+--------+
| ID | NUMA |   PCI   |        MAC        |              Name               | Driver | Linux IF | Active |
+====+======+=========+===================+=================================+========+==========+========+

| 3  | -1   | 06:00.0 | 94:09:d3:2b:72:fe | I210 Gigabit Network Connection | igb    | enp6s0   |        |
+----+------+---------+-------------------+---------------------------------+--------+----------+--------+
| 4  | -1   | 07:00.0 | 94:09:d3:2b:72:ff | I210 Gigabit Network Connection | igb    | enp7s0   |        |
+----+------+---------+-------------------+---------------------------------+--------+----------+--------+
| 5  | -1   | 08:00.0 | 94:09:d3:2b:73:00 | I210 Gigabit Network Connection | igb    | enp8s0   |        |
+----+------+---------+-------------------+---------------------------------+--------+----------+--------+
Please choose an even number of interfaces from the list above, either by ID, PCI or Linux IF
Stateful will use order of interfaces: Client1 Server1 Client2 Server2 etc. for flows.
Stateless can be in any order.
Enter list of interfaces separated by space (for example: 1 3) : 4 5

脚本默认配置两个接口为回环模式。先都采用默认的配置,稍后在修改。

For interface 4, assuming loopback to its dual interface 5.
Putting IP 1.1.1.1, default gw 2.2.2.2 Change it?(y/N).
For interface 5, assuming loopback to its dual interface 4.
Putting IP 2.2.2.2, default gw 1.1.1.1 Change it?(y/N).
Print preview of generated config? (Y/n)
### Config file generated by dpdk_setup_ports.py ###

配置完之后,预览配置内容如下,保存到/etc/trex_cfg.yaml。

- version: 2
  interfaces: ['07:00.0', '08:00.0']
  port_info:
      - ip: 1.1.1.1
        default_gw: 2.2.2.2
      - ip: 2.2.2.2
        default_gw: 1.1.1.1

  platform:
      master_thread_id: 0
      latency_thread_id: 1
      dual_if:
        - socket: 0
          threads: [2,3]

Save the config to file? (Y/n)
Default filename is /etc/trex_cfg.yaml
Press ENTER to confirm or enter new file:
Saved to /etc/trex_cfg.yaml.

修改trex_cfg.yaml文件如下:

rz@trex:/opt/trex/v3.04$ sudo vim /etc/trex_cfg.yaml
### Config file generated by dpdk_setup_ports.py ###

- version: 2
  interfaces: ['07:00.0', '08:00.0']
  port_info:
      - ip: 1.1.1.2
        default_gw: 1.1.1.1
      - ip: 2.2.2.2
        default_gw: 2.2.2.1

  platform:
      master_thread_id: 0
      latency_thread_id: 1
      dual_if:
        - socket: 0
          threads: [2,3]
"/etc/trex_cfg.yaml" 17L, 340B written

对应的拓扑如下图。

              |---------------|
              |      Trex     |
      1.1.1.2 |               | 2.2.2.2
 |------------|enp7s0  enp8s0 |------------|
 |            |---------------|            |
 |                                         |
 |                                         |
 |            |---------------|            |
 |    1.1.1.1 |      DUT      | 2.2.2.1    |
 |------------| eth0     eth1 |------------|
              |---------------|

被测设备DUT

被测设备位移台ubuntu设备,安装有两个网卡。如下打开转发,配置接口的IPv4地址,配置路由。

echo 1 > /proc/sys/net/ipv4/ip_forward

ifconfig eth0 1.1.1.1/24
ifconfig eth1 2.2.2.1/24

ip route add 16.0.0.0/8 via 1.1.1.2
ip route add 48.0.0.0/8 via 2.2.2.2

查看路由配置:

# ip route
1.1.1.0/24 dev eth0 proto kernel scope link src 1.1.1.1
2.2.2.0/24 dev eth1 proto kernel scope link src 2.2.2.1
16.0.0.0/8 via 1.1.1.2 dev eth0
48.0.0.0/8 via 2.2.2.2 dev eth1

Trex配置

如下启动trex服务。

rz@trex:/opt/trex/v3.04$ sudo ./t-rex-64 -i 

启动终端trex-console连接服务端:

rz@trex:/opt/trex/v3.04$ ./trex-console 

Using 'python3' as Python interpeter
Connecting to RPC server on localhost:4501                   [SUCCESS]
Connecting to publisher server on localhost:4500             [SUCCESS]
Acquiring ports [0, 1]:                                      [SUCCESS]
*** Warning - Port 0 destination is unresolved ***
*** Warning - Port 1 destination is unresolved ***
Server Info:
Server version:   v3.04 @ STL
Server mode:      Stateless
Server CPU:       1 x Intel(R) Celeron(R) CPU  J1900  @ 1.99GHz
Ports count:      2 x 1Gbps @ I210 Gigabit Network Connection
-=TRex Console v3.0=-
Type 'help' or '?' for supported actions
trex>

进入服务模式service,ping测试与DUT设备的连通性。

trex>service
Enabling service mode on port(s): [0, 1]                     [SUCCESS]
15.69 [ms]
trex(service)>
trex(service)>ping -d 2.2.2.1 -p 1

Pinging 2.2.2.1 from port 1 with 64 bytes of data:           
Reply from 2.2.2.1: bytes=64, time=0.89ms, TTL=64
Reply from 2.2.2.1: bytes=64, time=0.63ms, TTL=64
Reply from 2.2.2.1: bytes=64, time=1.07ms, TTL=64
Reply from 2.2.2.1: bytes=64, time=1.02ms, TTL=64
Reply from 2.2.2.1: bytes=64, time=0.56ms, TTL=64
trex(service)>
trex(service)>ping -d 1.1.1.1 -p 0   

Pinging 1.1.1.1 from port 0 with 64 bytes of data:           
Reply from 1.1.1.1: bytes=64, time=1.42ms, TTL=64
Reply from 1.1.1.1: bytes=64, time=1.46ms, TTL=64
Reply from 1.1.1.1: bytes=64, time=0.51ms, TTL=64
Reply from 1.1.1.1: bytes=64, time=0.97ms, TTL=64
Reply from 1.1.1.1: bytes=64, time=0.70ms, TTL=64

statefull模式

rz@trex:/opt/trex/v3.04$ 
rz@trex:/opt/trex/v3.04$ sudo ./t-rex-64 -f cap2/http_simple.yaml -d 100 -m 1 --nc

在DUT设备上抓包,查看报文:

06:33:41.894512 ARP, Request who-has 2.2.2.2 (01:03:05:07:09:00) tell 2.2.2.2, length 46
06:33:41.894578 ARP, Request who-has 2.2.2.1 (01:03:05:07:09:01) tell 2.2.2.2, length 46
06:33:41.894638 ARP, Reply 2.2.2.1 is-at 94:09:d3:2a:f6:dd, length 28
06:33:41.894676 ARP, Request who-has 1.1.1.2 (01:03:05:07:09:00) tell 1.1.1.2, length 46
06:33:41.894699 ARP, Request who-has 1.1.1.1 (01:03:05:07:09:00) tell 1.1.1.2, length 46
06:33:41.894722 ARP, Reply 1.1.1.1 is-at 94:09:d3:2a:f6:dc, length 28
06:33:42.011447 IP 16.0.0.1.41668 > 48.0.0.1.http: Flags [S], seq 404375002, win 32768, options [mss 1460], length 0
06:33:42.011546 IP 16.0.0.1.41668 > 48.0.0.1.http: Flags [S], seq 404375002, win 32768, options [mss 1460], length 0
06:33:42.022162 IP 48.0.0.1.http > 16.0.0.1.41668: Flags [S.], seq 404419109, ack 404375003, win 32768, options [mss 1460], length 0
06:33:42.022198 IP 48.0.0.1.http > 16.0.0.1.41668: Flags [S.], seq 404419109, ack 404375003, win 32768, options [mss 1460], length 0
06:33:42.033376 IP 16.0.0.1.41668 > 48.0.0.1.http: Flags [.], ack 1, win 32768, length 0
06:33:42.033394 IP 16.0.0.1.41668 > 48.0.0.1.http: Flags [.], ack 1, win 32768, length 0
06:33:42.033412 IP 16.0.0.1.41668 > 48.0.0.1.http: Flags [P.], seq 1:250, ack 1, win 32768, length 249: HTTP: GET /3384 HTTP/1.1
06:33:42.033420 IP 16.0.0.1.41668 > 48.0.0.1.http: Flags [P.], seq 1:250, ack 1, win 32768, length 249: HTTP: GET /3384 HTTP/1.1
06:33:42.044175 IP 48.0.0.1.http > 16.0.0.1.41668: Flags [P.], seq 1:1461, ack 250, win 32768, length 1460: HTTP: HTTP/1.1 200 OK
06:33:42.044194 IP 48.0.0.1.http > 16.0.0.1.41668: Flags [P.], seq 1:1461, ack 250, win 32768, length 1460: HTTP: HTTP/1.1 200 OK
06:33:42.044215 IP 48.0.0.1.http > 16.0.0.1.41668: Flags [P.], seq 1461:2921, ack 250, win 32768, length 1460: HTTP
06:33:42.044224 IP 48.0.0.1.http > 16.0.0.1.41668: Flags [P.], seq 1461:2921, ack 250, win 32768, length 1460: HTTP
Logo

技术共进,成长同行——讯飞AI开发者社区

更多推荐