Trex: Software Traffic Generator by cisco

  • official documentation: https://trex-tgn.cisco.com/trex/doc
  • source-code(mirror on github): https://github.com/FDio/trex

Version 2.5

Install

sudo su -
yum install -y pciutils kernel-devel-`uname -r`
yum group install "Development tools"

mkdir -p /opt/trex && cd $_
curl -LO http://trex-tgn.cisco.com/trex/release/<VERSION>
curl -LO http://trex-tgn.cisco.com/trex/release/v2.50.tar.gz
curl -LO http://trex-tgn.cisco.com/trex/release/v2.37.tar.gz
tar xvf <VERSION>.tgz
cd <VERSION>

Launch

# /etc/trex_cfg.yaml
### Config file generated by dpdk_setup_ports.py ###

- version: 2
  interfaces: ['00:07.0', '00:07.1']
  port_info:
      - ip: 1.1.1.1
        default_gw: 1.1.1.3
      - ip: 2.2.2.2
        default_gw: 2.2.2.3

  platform:
      master_thread_id: 0
      latency_thread_id: 1
      dual_if:
        - socket: 0
          threads: [2,3]
## /opt/trex/v2.50/stl/udp_1pkt_2.py
from trex_stl_lib.api import *

class STLS1(object):
    def __init__ (self):
        self.fsize  = 64;

    def create_pkt_base (self):
        return Ether()/IP(src="1.1.1.1",dst="2.2.2.2")/UDP(dport=50000,sport=50001)

    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 = self.create_pkt_base ()
        pad = max(0, size - len(base_pkt)) * 'x'
        pkt = STLPktBuilder(pkt = base_pkt/pad, vm = [])
        return STLStream(packet = pkt, mode = STLTXCont())

    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()
trex/v2.5# ./trex-console
trex> start -p 0 -m 100kbps -f stl/udp_1pkt_2.py -p 0

Good references

  • Explain the simple usecase of trex in japanese. https://foobaron.hatenablog.com/entry/2019/03/10/cisco-trex-traffic-generator-l3-stateless
  • Explain about procedure of setup with mlx-drivers in japanese. https://ameblo.jp/makototgc/entry-12455157774.html