TRex Stateless Python API¶
TRex is a traffic generator
This site covers the Python API of TRex and explains how to utilize it to your needs. To understand the entirely how the API works and how to set up the server side, check out the trex-core Wiki under the documentation section of TRex website.
Use the table of contents below or the menu to your left to navigate through the site
How to Install¶
Un-pack it using command:
tar -xzf trex_client.tar.gz
How to use¶
cd trex_client/stl/examples
python stl_imix.py -s <server address>
You can verify that the traffic was sent and arrives properly if you see something like this::
Mapped ports to sides [0, 2] <--> [1, 3]
Injecting [0, 2] <--> [1, 3] on total rate of '30%' for 10 seconds
Packets injected from [0, 2]: 473,856
Packets injected from [1, 3]: 473,856
packets lost from [0, 2] --> [0, 2]: 0 pkts
packets lost from [1, 3] --> [1, 3]: 0 pkts
Test has passed :-)
Also, in the stl folder there are directories with profiles that define streams and the console (with which you can easily send the profiles)
How to pyATS¶
pyATS Compatibility
TRex supports both Python2 and Python3 pyATS.
- Install python2/python3 pyats
/auto/pyats/bin/pyats-install –python2 /auto/pyats/bin/pyats-install –python3
Update the path
Option 1 (better)
export PYTHONPATH=[your path]/automation/trex_control_plane/interactive or in case of a client lib export PYTHONPATH=[your path]trex_client_v2xx/interactive
$PYTHON -m [your main] -p $PWD $INPUT_ARGS
Option 2
setenv TREX_PATH to the trex stateless lib path setenv TREX_PATH <your path>/automation/trex_control_plane/interactive/ or in case of a client lib setenv TREX_PATH <your path>/trex_client_v2xx/interactive
In the script or job file, add the TREX_PATH to sys.path:
import sys, os; sys.path.append(os.environ['TREX_PATH'])
In any case do not include a path internal than ../interactive. This could lead to unexpected behavior
Source trex stateless libs in scripts:
from trex.stl.api import * from scapy.contrib.mpls import * from trex.stl.trex_stl_hltapi import *
API Reference¶
Indices and tables¶
Footnotes