[trex篇] trex的hello world 使用

前言

编程过程中,应该一遍敲代码,一遍验证代码的正确性。如果仅仅在代码敲完的时候进行验证,代码中可能会潜藏未知的问题。vpp相关的网络编程中,最好让代码编写环境一直有流量,边写代码边测试。

trex 是一个低成本的流量生成工具,值得学习以掌握它的使用方法。

本文将使用testpmd运行一个二层转发程序,使用trex给testpmd打流量。

本文的测试环境是在vmware虚拟机中。(vmware比virtualbox好用,vmware可以创建更多的网卡,而 virtualbox只能创建四个虚拟网卡)网络拓扑大体如下。

相关连接:TRex 教程 | GuoYi的博客

使用testpmd进行数据包转发

相关连接:testpmd 设置io转发

准备工作。

# 下载一份dpdk源码
git clone --depth 1 https://github.com/DPDK/dpdk.git

# 编译dpdk,生成 app/dpdk-testpmd 可执行文件
meson setup -Dcpu_instruction_set=corei7 -Dbuildtype=debug -Dexamples=all build
cd build && ninja

# 使用dpdk-hugepages.py给系统设置大页。
## 如果设置失败了,是因为编译导致系统上没有足够的连续内存。重启下系统,重新设置即可
cd usertools
## 每个page为2M,总共1G的大页
./dpdk-hugepages.py -p 2048k --setup 1G
./dpdk-hugepages.py -s

# 查看当前系统上的网卡信息
root@localhost ~/w/3/d/usertools (main)# lshw -c network -businfo
Bus info          Device          Class          Description
============================================================
pci@0000:03:00.0  ens160          network        VMXNET3 Ethernet Controller #ssh网卡
pci@0000:04:00.0  ens161          network        VMXNET3 Ethernet Controller #VMnet2
pci@0000:0c:00.0  ens193          network        VMXNET3 Ethernet Controller #VMnet3
pci@0000:13:00.0  ens224          network        VMXNET3 Ethernet Controller #VMnet4
pci@0000:1b:00.0  ens256          network        VMXNET3 Ethernet Controller #VMnet5


# 为dpdk绑定2张网卡
modprobe vfio-pci
./dpdk-devbind.py --bind=vfio-pci ens161 --noiommu-mode
./dpdk-devbind.py --bind=vfio-pci ens193 --noiommu-mode

启动testpmd,设置转发模式为I/O。 I/O 模式,不访问数据包数据,“按原样”转发数据包,这是最快的转发操作,也是最简单的操作。

./dpdk-testpmd -- -i
testpmd> show port stats all
testpmd> set fwd io

testpmd> show port 0 macs 
Number of MAC address added: 1
  00:0C:29:B9:06:A1
testpmd> show port 1 macs 
Number of MAC address added: 1
  00:0C:29:B9:06:AB

使用trex生成流量

相关连接:trex_manual#_first_time_running

下载trex。目前trex只支持x86版本,无arm版本。似乎也没必要有arm版本,但某些场景确实有点不方便。

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

trex 需要一个配置文件。最简单的方式是,使用 ./dpdk_setup_ports.py 交互式的生成一个配置文件。

注1:DUT是“Device Under Test”的缩写,中文通常翻译为“被测设备”。这里的DUT是运行testpmd的设备。

注2:这里面的dst_mac 没有修改。原因一是,testpmd的io模式是直接转发,不看包。原因二是,trex网卡收到包的dst_mac地址,得和自己网卡的mac地址,对的上才行。

root@localhost ~/w/3/v3.06 [255]# ./dpdk_setup_ports.py -i
By default, IP based configuration file will be created. Do you want to use MAC based config? (y/N)y
+----+------+---------+-------------------+-----------------------------+-----------------+----------+----------+
| ID | NUMA |   PCI   |        MAC        |            Name             |     Driver      | Linux IF |  Active  |
+====+======+=========+===================+=============================+=================+==========+==========+
| 0  | -1   | 03:00.0 | 00:0c:29:13:56:f7 | VMXNET3 Ethernet Controller | vmxnet3         | ens160   | *Active* |
+----+------+---------+-------------------+-----------------------------+-----------------+----------+----------+
| 1  | -1   | 04:00.0 | 00:0c:29:13:56:15 | VMXNET3 Ethernet Controller | uio_pci_generic |          |          |
+----+------+---------+-------------------+-----------------------------+-----------------+----------+----------+
| 2  | -1   | 0c:00.0 | 00:0c:29:13:56:1f | VMXNET3 Ethernet Controller | uio_pci_generic |          |          |
+----+------+---------+-------------------+-----------------------------+-----------------+----------+----------+
| 3  | -1   | 13:00.0 | 00:0c:29:13:56:01 | VMXNET3 Ethernet Controller | vmxnet3         | ens224   |          |
+----+------+---------+-------------------+-----------------------------+-----------------+----------+----------+
| 4  | -1   | 1b:00.0 | 00:0c:29:13:56:0b | VMXNET3 Ethernet Controller | vmxnet3         | ens256   |          |
+----+------+---------+-------------------+-----------------------------+-----------------+----------+----------+
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) : 1 2

For interface 1, assuming loopback to its dual interface 2.
Destination MAC is 00:0c:29:13:56:1f. Change it to MAC of DUT? (y/N).n
For interface 2, assuming loopback to its dual interface 1.
Destination MAC is 00:0c:29:13:56:15. Change it to MAC of DUT? (y/N).n
Print preview of generated config? (Y/n)y
### Config file generated by dpdk_setup_ports.py ###

- version: 2
  interfaces: ['04:00.0', '0c:00.0']
  port_info:
      - dest_mac: 00:0c:29:13:56:1f # MAC OF LOOPBACK TO IT'S DUAL INTERFACE
        src_mac:  00:0c:29:13:56:15
      - dest_mac: 00:0c:29:13:56:15 # MAC OF LOOPBACK TO IT'S DUAL INTERFACE
        src_mac:  00:0c:29:13:56:1f

  platform:
      master_thread_id: 0
      latency_thread_id: 1
      dual_if:
        - socket: 0
          threads: [2,3,4,5,6,7]


Save the config to file? (Y/n)y
Default filename is /etc/trex_cfg.yaml
Press ENTER to confirm or enter new file: 
File /etc/trex_cfg.yaml already exist, overwrite? (y/N)y
Saved to /etc/trex_cfg.yaml.

启动trex,给testpmd发送流量。

./t-rex-64 -f cap2/dns.yaml -c 1 -m 1 -d 10000000

最后

对于trex的使用,我们应该按照下面的角度进行考虑

  1. 对于收发包端口的控制。
  2. 对于收发包速度的控制。
  3. 对于收发包内容的控制。
  4. 其他:对hugepage,core 的使用控制等。

这些内容就比较复杂-有意思了,我得摸摸。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇