### Start TRex Server and Console (Bash) Source: https://context7.com/cisco-system-traffic-generator/trex-core/llms.txt These bash commands show how to start the TRex server in stateless mode using a configuration file and how to launch the TRex console in a separate terminal. It assumes TRex is installed and accessible in the specified paths. ```bash # Start TRex server (stateless mode) cd /path/to/trex sudo ./t-rex-64 -i --cfg /etc/trex_cfg.yaml # In another terminal, start TRex console cd /path/to/trex ./trex-console ``` -------------------------------- ### Basic SimpleJSONRPCServer Setup Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonrpclib-pelix-0.4.1/README.md Demonstrates the fundamental setup of a SimpleJSONRPCServer, registering functions, and starting the server to listen for requests on localhost:8080. It requires the 'jsonrpclib' library. ```python from jsonrpclib.SimpleJSONRPCServer import SimpleJSONRPCServer server = SimpleJSONRPCServer(('localhost', 8080)) server.register_function(pow) server.register_function(lambda x,y: x+y, 'add') server.register_function(lambda x: x, 'ping') server.serve_forever() ``` -------------------------------- ### Install Scapy from Source Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/scapy-2.4.3/README.md This example shows the basic steps to clone the Scapy repository from GitHub, navigate into the directory, and run the interactive shell. This is the standard method for installing Scapy on most systems. ```bash git clone https://github.com/secdev/scapy cd scapy ./run_scapy ``` -------------------------------- ### Minimal TRex Client Interaction Example Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_stl/api/client_code.rst A basic example demonstrating the minimal setup for a TRex client to connect to the server, reset ports, add a stream, clear statistics, start traffic, and wait for its completion. Includes basic error handling and disconnection. ```python # Example 1: Minimal example of client interacting with the TRex server c = STLClient() try: # connect to server c.connect() # prepare our ports (my machine has 0 <--> 1 with static route) c.reset(ports = [0, 1]) # add both streams to ports c.add_streams(s1, ports = [0]) # clear the stats before injecting c.clear_stats() c.start(ports = [0, 1], mult = "5mpps", duration = 10) # block until done c.wait_on_traffic(ports = [0, 1]) # check for any warnings if c.get_warnings(): # handle warnings here pass finally: c.disconnect() ``` -------------------------------- ### deck.js Initialization Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/doc/backends/deckjs/deck.js/introduction/index.html Initializes deck.js on HTML elements with the class 'slide' using jQuery. This is a common setup for activating deck.js features. ```javascript $(function() { $.deck('.slide'); }); ``` -------------------------------- ### Including Style Themes in deck.js Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/doc/backends/deckjs/deck.js/introduction/index.html Shows how to link a CSS file to apply a style theme to the deck.js presentation. This controls the visual appearance of the slides. ```html ``` -------------------------------- ### Install Dependencies and Download MLNX_OFED Source Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/external_libs/ibverbs/readme.txt Installs the necessary libnl3 development package using yum and downloads the MLNX_OFED source archive. This is a prerequisite for compiling the Mellanox OFED drivers. ```bash sudo yum install libnl3-devel download MLNX_OFED_SRC-3.4-1.0.0.0.tgz ``` -------------------------------- ### Install MLX5 Driver and Copy Headers Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/external_libs/ibverbs/readme.txt Installs the MLX5 driver and copies the MLX5 hardware header file to the appropriate location for the TRex build. This ensures the driver's interface is accessible. ```bash for mlx5 sudo make install then copy the /usr/local/include/infiniband/mlx5_hw.h to header folder ``` -------------------------------- ### Setup and run tests in a virtual environment Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonpickle-2.0.0/README.rst Creates a Python virtual environment, installs development requirements, and runs tests using `vx` for environment management. This isolates dependencies and ensures reproducible testing. ```bash python3 -mvenv env3x vx env3x pip install --requirement requirements-dev.txt vx env3x make test ``` -------------------------------- ### Start TRex ASTF Server and Console Source: https://context7.com/cisco-system-traffic-generator/trex-core/llms.txt Commands to launch the TRex ASTF (advanced stateful) server and connect to its console for advanced traffic testing. ```bash # Start ASTF (advanced stateful) server sudo ./t-rex-64 --astf -i --cfg /etc/trex_cfg.yaml # Start ASTF console ./trex-console --astf ``` -------------------------------- ### Including Transition Themes in deck.js Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/doc/backends/deckjs/deck.js/introduction/index.html Illustrates how to link a CSS file for transition themes in deck.js. This enables CSS3 transitions between slides, with fallbacks for older browsers. ```html ``` -------------------------------- ### Basic Slide Structure in deck.js Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/doc/backends/deckjs/deck.js/introduction/index.html Demonstrates the fundamental HTML structure for creating a slide in deck.js. Slides are defined as section elements with the class 'slide'. ```html

How to Make a Deck

  1. Write Slides

    Slide content is simple HTML.

  2. Choose Themes

    One for slide styles and one for deck transitions.

``` -------------------------------- ### Install jsonpickle from source Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonpickle-2.0.0/docs/index.rst Installs jsonpickle from its source code. This method is useful if you have downloaded the source or checked it out from version control. It relies on the setup.py script. ```bash $ python setup.py install ``` -------------------------------- ### Run Basic TRex Example Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_stl/index.rst A basic command to run an example traffic generation script using the TRex client. Requires specifying the server address. This demonstrates sending traffic and verifying its reception. ```bash cd trex_client/stl/examples python stl_imix.py -s ``` -------------------------------- ### Install jsonrpclib-pelix from source Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonrpclib-pelix-0.4.1/README.md This snippet demonstrates how to clone the source code from GitHub and manually install the jsonrpclib-pelix library. This method is useful if you need to work with the source code directly or if PyPI installation is not feasible. ```shell git clone git://github.com/tcalmant/jsonrpclib.git cd jsonrpclib python setup.py install ``` -------------------------------- ### TRex Client Association and DHCP Example Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/interactive/trex/wireless/docs/source/plugins.rst An example demonstrating advanced plugin usage where one plugin launches other plugins, specifically showcasing the sequence of client association followed by DHCP. This highlights coordinated service execution within the TRex framework. ```python from wireless.services.trex_wireless_service import WirelessService from wireless.services.client.client_service_association import ClientAssociationService from wireless.services.client.client_service_dhcp import ClientDHCPService class ClientAssociationAndDHCP(WirelessService): def __init__(self, client): super(ClientAssociationAndDHCP, self).__init__(client) self.client = client self.association_service = ClientAssociationService(client) self.dhcp_service = ClientDHCPService(client) async def start(self, first_start=False): await super(ClientAssociationAndDHCP, self).start(first_start=first_start) # Ensure services are requested to start if they need it await self.association_service.async_request_start() await self.dhcp_service.async_request_start() async def run(self): # Run association first, then DHCP await self.association_service.run() await self.dhcp_service.run() ``` -------------------------------- ### Configure and Compile MLNX_OFED Driver Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/external_libs/ibverbs/readme.txt Builds the MLNX_OFED driver from source. This involves running the standard autoconf, configure, and make build steps. ```bash ./autogen.sh ./configure make ``` -------------------------------- ### Install jsonpickle from GitHub Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonpickle-2.0.0/README.rst Installs the latest development version of jsonpickle directly from its GitHub repository. This is useful for users who want to access the newest features or contribute to the project. ```bash pip install git+https://github.com/jsonpickle/jsonpickle.git ``` -------------------------------- ### Install pyATS for Python 2 and 3 Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_stl/index.rst Commands to install pyATS, a testing framework, for both Python 2 and Python 3 environments. These commands are typically executed from a specific environment path. ```bash /auto/pyats/bin/pyats-install --python2 /auto/pyats/bin/pyats-install --python3 ``` -------------------------------- ### Python Function Docstring Example (PEP8) Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/python-daemon-2.0.5/doc/hacking.txt Illustrates the recommended format for Python docstrings according to PEP8 guidelines. It includes a synopsis, parameter descriptions, return value description, and detailed explanations, all marked up with reStructuredText. ```python def frobnicate(spam, algorithm="dv"): """ Perform frobnication on ``spam``. :param spam: A travortionate (as a sequence of strings). :param algorithm: The name of the algorithm to use for frobnicating the travortionate. :return: The frobnicated travortionate, if it is non-empty; otherwise None. The frobnication is done by the Dietzel-Venkman algorithm, and optimises for the case where ``spam`` is freebled and agglutinative. """ spagnify(spam) # … ``` -------------------------------- ### Install TRex Client Package Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_stl/index.rst Instructions on how to install the TRex client package. It involves unpacking a tarball. Ensure the trex_client directory is in sys.path if it's not co-located with your scripts. ```bash tar -xzf trex_client.tar.gz ``` -------------------------------- ### Install Asciidoc Deck.js Backend Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/doc/backends/deckjs/README.md Installs the Deck.js backend for Asciidoc by downloading and using the provided zip package. This places the backend in the user's local Asciidoc backend directory. ```bash asciidoc --backend install deckjs-X.Y.Z.zip ``` -------------------------------- ### Extract RPM Packages Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/external_libs/ibverbs/readme.txt Demonstrates methods to extract the contents of RPM packages. This is often necessary to access source files or headers contained within the RPM. ```bash rpm2cpio myrpmfile.rpm | cpio -idmv tar -xvzf myrpmfile.rpm ``` -------------------------------- ### Install jsonrpclib-pelix using pip Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonrpclib-pelix-0.4.1/README.md This snippet shows how to install the jsonrpclib-pelix library globally or locally using pip. Ensure you have pip installed and potentially administrator privileges if installing globally. ```shell # Global installation pip install jsonrpclib-pelix # Local installation pip install --user jsonrpclib-pelix ``` -------------------------------- ### Install jsonpickle using pip Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonpickle-2.0.0/README.rst Installs the latest stable release of jsonpickle from PyPI using pip. This is the recommended method for most users. ```bash pip install jsonpickle ``` -------------------------------- ### Example TRex EMU Profile (Python) Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_emu/api/profile_code.rst This is an example of a simple EMU profile for TRex, demonstrating the basic structure and usage of EMU profiles. It likely includes argument parsing for tunable parameters and definitions for namespaces and clients. ```python import argparse from trex.emu.trex_emu_profile import EMUProfile def register(): return { "MyProfile": MyProfile } class MyProfile(EMUProfile): def create_profile(self): # Example: Define a namespace and add clients to it ns_key = self.create_namespace_key(vlan_tci=100) ns = self.create_namespace(ns_key, "default_plugin") client_key = self.create_client_key(mac="00:00:00:00:00:01") client = ns.add_client(client_key, "default_plugin") # Add IPv4 address to the client client.add_ipv4("192.168.1.1/24", "192.168.1.254") # Add more clients or namespaces as needed return ns if __name__ == '__main__': parser = argparse.ArgumentParser(description='TRex EMU Profile Example') args = parser.parse_args() profile = MyProfile(args) profile.run_profile() ``` -------------------------------- ### Python Packaging Configuration with pyproject.toml and setup.cfg Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonpickle-2.0.0/skeleton.md This configuration uses pyproject.toml for build system requirements (PEP 517/518) and setup.cfg for project metadata and build options. It declares universal wheel compatibility, includes LICENSE and README.rst, specifies Python version requirements, and defines 'testing' and 'docs' extras. ```toml # pyproject.toml [build-system] requires = ["setuptools>=42", "wheel"] build-backend = "setuptools.build_meta" ``` ```ini ; setup.cfg [metadata] license-file = LICENSE long_description = file: README.rst classifiers = Programming Language :: Python :: 3 Programming Language :: Python :: 3.8 Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 [options] packages = find: include_package_data = True python_requires = >=3.8 install_requires = [options.extras_require] testing = pytest docs = sphinx ; Placeholder for entry points ; [options.entry_points] ; console_scripts = ; my-command = my_package.module:main ``` -------------------------------- ### Embedding Videos in deck.js Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/doc/backends/deckjs/deck.js/introduction/index.html Illustrates how to embed video content into deck.js slides using an iframe element. This example shows embedding a Vimeo video. ```html ``` -------------------------------- ### Documentation Building with tox and Read the Docs Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonpickle-2.0.0/skeleton.md This configuration involves building documentation using Sphinx, with support for Read the Docs. The tox -e docs command can be used for local builds, relying on dependencies specified in setup.cfg's 'docs' extra. The process includes generating a history.html file by injecting release dates and hyperlinks into CHANGES.rst. ```shell # To test docs build manually: tox -e docs ``` ```ini # In setup.cfg, under [options.extras_require] docs = sphinx # other documentation build dependencies... ``` -------------------------------- ### Nested Slides Structure in deck.js Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/doc/backends/deckjs/deck.js/introduction/index.html Provides an example of creating nested slides (substeps) within a main slide in deck.js. This is achieved by nesting elements with the 'slide' class. ```html

Extensions

Core gives you basic slide functionality...

``` -------------------------------- ### Serve jsonpickle Documentation Locally Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonpickle-2.0.0/docs/contrib.rst This command starts a local HTTP server to browse the generated jsonpickle documentation. It serves the contents of the build/html directory at http://localhost:8000. ```python python -m http.server -d build/html ``` -------------------------------- ### Install GCC 7.3.1 and Libasan on CentOS 7 Source: https://github.com/cisco-system-traffic-generator/trex-core/wiki/How-to-install-gcc7 This snippet installs the devtoolset-7 GCC compiler and its associated libasan development package on CentOS 7. It then manages the alternatives system to prioritize the new GCC version and verifies the installation. ```bash sudo yum install devtoolset-7-gcc sudo mv /usr/bin/gcc{,-4.8.5} sudo mv /usr/bin/g++{,-4.8.5} #update alternatives sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8.5 30 sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8.5 30 sudo update-alternatives --install /usr/bin/gcc gcc /opt/rh/devtoolset-7/root/usr/bin/gcc 50 sudo update-alternatives --install /usr/bin/g++ g++ /opt/rh/devtoolset-7/root/usr/bin/g++ 50 # install relevant libasan sudo yum install devtoolset-7-libasan-devel.x86_64 # verify that configure shows correct gcc version + libasan is recognized as installed #GCC version : 7.3.1 ``` -------------------------------- ### TRex EMU Client: ARP Example Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_emu/api/client_code.rst A Python example showcasing the Address Resolution Protocol (ARP) functionality within the TRex EMUClient. This is crucial for network communication setup in emulated environments. ```python fromtrex.emu.trex_emu_client import EMUClient client = EMUClient("127.0.0.1", 8080) client.connect() # ARP related operations # ... (specific ARP commands would be here) client.disconnect() ``` -------------------------------- ### TRex Console: Loading Emulation Profiles Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_emu/api/client_code.rst Example of using the TRex console to load an emulation profile. This command allows users to specify the profile file, number of namespaces, and clients per namespace. ```bash ./trex-console --emu (trex)> emu_load_profile -f emu/simple_emu.py -t --ns 2 --clients 5 ``` -------------------------------- ### Embedding Blockquotes in deck.js Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/doc/backends/deckjs/deck.js/introduction/index.html Shows the correct HTML structure for embedding blockquotes in deck.js, including the cite attribute and cite element for attribution. ```html

Food is an important part of a balanced diet.

Fran Lebowitz

``` -------------------------------- ### Embedding Images in deck.js Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/doc/backends/deckjs/deck.js/introduction/index.html Demonstrates how to include an image within a deck.js slide using the HTML img tag. The provided URL points to a placeholder kitten image. ```html Kitties ``` -------------------------------- ### Build Test Suite with CMake Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/external_libs/valijson/README.md Instructions to build the examples and test suite using CMake. This involves creating a build directory, navigating into it, running cmake, and then making the project. The test suite can then be executed from the build directory. ```bash mkdir build cd build cmake .. make # Run test suite (from build directory) ./test_suite ``` -------------------------------- ### Python Version Derivation with setuptools_scm Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/jsonpickle-2.0.0/skeleton.md The setup.py file configures setuptools_scm to automatically derive the project's version from SCM tags. This ensures that all committed files are included in releases, simplifying version management. ```python # setup.py from setuptools import setup setup( use_scm_version=True, # other setup parameters... ) ``` -------------------------------- ### TRex ASTFClient: Connect, Load Profile, Start Traffic, Get Stats (Python) Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_astf/api/client_code.rst This snippet demonstrates the basic workflow of the ASTFClient: connecting to the server, resetting the client, loading a traffic profile, clearing statistics, starting traffic, waiting for it to complete, retrieving statistics, and handling potential errors before disconnecting. It includes error handling for TRexError and AssertionError. ```python c = ASTFClient(server = server) c.connect() try: c.reset() c.load_profile(profile_path) c.clear_stats() c.start(mult = mult, duration = duration, nc = True) c.wait_on_traffic() stats = c.get_stats() pprint.pprint(stats) if c.get_warnings(): for w in c.get_warnings(): print(w) except TRexError as e: print(e) except AssertionError as e: print(e) finally: c.disconnect() ``` -------------------------------- ### TRex ASTFClient: Load Profile, Start Traffic, Get TG Names and Stats (Python) Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_astf/api/client_code.rst This Python snippet demonstrates loading a traffic profile, clearing statistics, starting traffic for a specified duration and multiplier, waiting for traffic completion, and then retrieving specific traffic generator group names and their corresponding statistics. This is useful for granular analysis of traffic generated by specific groups. ```python # Example: tempate group name and counters self.c.load_profile(profile) self.c.clear_stats() self.c.start(duration = 60, mult = 100) self.c.wait_on_traffic() names = self.c.get_tg_names() stats = self.c.get_traffic_tg_stats(names[:2]) ``` -------------------------------- ### Control TRex Traffic Generation and Statistics (Python) Source: https://context7.com/cisco-system-traffic-generator/trex-core/llms.txt This Python script demonstrates how to load a traffic profile, clear statistics, start and stop traffic generation with specified parameters, retrieve statistics, and check for warnings. It requires the TRex client library. ```python from trex.emu.api import * # Load the HTTP profile c.load_profile('/path/to/http_simple.py') # Clear statistics c.clear_stats() # Start traffic with multiplier 100 for 20 seconds print("Starting HTTP traffic...") c.start(mult = 100, duration = 20) # Wait for traffic completion c.wait_on_traffic() # Get and analyze statistics stats = c.get_stats() # Check TCP byte counters client_stats = stats['traffic']['client'] server_stats = stats['traffic']['server'] tcp_sent = client_stats.get('tcps_sndbyte', 0) tcp_received = server_stats.get('tcps_rcvbyte', 0) print(f"TCP bytes sent: {tcp_sent}") print(f"TCP bytes received: {tcp_received}") print(f"Connection rate: {stats['traffic']['client'].get('tcps_connects', 0)} CPS") # Check for warnings if c.get_warnings(): for w in c.get_warnings(): print(f"Warning: {w}") c.disconnect() ``` -------------------------------- ### APPSIM Program Configuration Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_emu/api/plugins/appsim.rst Defines the structure for configuring an APPSIM program, including buffer lists, command sequences, templates, and tunable parameters for client and server behavior. ```APIDOC ## APPSIM Program Structure ### Description This section outlines the structure of a program used by APPSIM to simulate Layer 7 applications. It details the various components that define the communication flow, message content, and timing. ### Method N/A (Configuration Structure) ### Endpoint N/A (Configuration Structure) ### Parameters #### Program Fields - **buf_list** ([]string) - Required - A list of base64 encoded strings representing data buffers to be sent. - **program_list** (object) - Required - Contains a list of program objects, where each object defines a sequence of commands. - **commands** ([]object) - Required - An array of command objects defining the execution flow. - **templates** ([]object) - Required - An array of template objects, each defining client and server configurations. - **client_template** (object) - Required - Configuration for the client side. - **server_template** (object) - Required - Configuration for the server side. - **tunable_list** ([]object) - Required - A list of tunable parameter objects that can be applied to client or server configurations. #### Command Objects - **tx** (object) - Sends data. - **buf_index** (int) - Required - The index in `buf_list` of the buffer to send. - **rx** (object) - Waits for data. - **min_bytes** (int) - Optional - The minimum number of bytes to receive. - **clear** (bool) - Optional - If true, clears the receive buffer before waiting. - **keepalive** (object) - Sends keepalive packets or waits for inactivity. - **msec** (int) - Required - Time in milliseconds for inactivity timeout or keepalive interval. - **rx_msg** (object) - Waits for a specific number of packets on the receive side (UDP). - **min_pkts** (int) - Required - The number of packets to wait for. - **tx_msg** (object) - Sends a message packet (UDP). - **buf_index** (int) - Required - The index in `buf_list` of the buffer to send. #### Tunable Objects - Each object within `tunable_list` is a key-value pair representing a tunable parameter, e.g., `{"tos": 7}` or `{"tos": 2, "mss": 7}`. ### Request Example ```json { "buf_list": [ "R0VUIC8zMzg0IEhUVFAvMS4xD", "SFRUUC8xLjEgMjAwIE9LDQpTZ" ], "tunable_list": [ {"tos": 7}, {"tos": 2, "mss": 7} ], "program_list": [ { "commands": [ {"msec": 10, "name": "keepalive" }, { "buf_index": 0, "name": "tx_msg" }, { "min_pkts": 1, "name": "rx_msg" } ] }, { "commands": [ { "msec": 10, "name": "keepalive" }, { "min_pkts": 1, "name": "rx_msg" }, { "buf_index": 1, "name": "tx_msg" } ] } ], "templates": [{ "client_template" :{ "program_index": 0, "tunable_index": 0, "port": 80, "cps": 1 }, "server_template" : {"assoc": [{"port": 80}], "program_index": 1} } ] } ``` ### Response N/A (Configuration Structure) ``` -------------------------------- ### TRex AP Service Printer Example Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/interactive/trex/wireless/docs/source/plugins.rst A Python plugin for TRex APs that waits for incoming packets, prints their layers using Scapy, and then waits for the next packet. It inherits from APService and manages resource usage by requesting to start and indicating packet reception needs. ```python import scapy.all from wireless.services.trex_wireless_service import WirelessService from wireless.trex_wireless_ap import AP class APServicePrinter(WirelessService): def __init__(self, ap: AP): super(APServicePrinter, self).__init__(ap) self.ap = ap async def start(self, first_start=False): await super(APServicePrinter, self).start(first_start=first_start) # Request to start the service and enable packet reception await self.async_request_start(request_packet=True) async def run(self): while True: # Wait for a packet, returns a list of 0 or 1 packet packets = await self.async_recv_pkt() if packets: packet = packets[0] # Print packet layers using Scapy packet.show() self.logger.info("Received and printed packet.") else: # Handle case where no packet is received (e.g., timeout) self.logger.debug("No packet received.") ``` -------------------------------- ### Python Code Style Hints (Emacs/Vim) Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/python-daemon-2.0.5/doc/hacking.txt Provides example comment blocks for Emacs and Vim editors to set file encoding and mode. These hints are placed at the end of Python files to ensure correct interpretation by the editors. ```python # Local variables: # coding: utf-8 # mode: python # End: # vim: fileencoding=utf-8 filetype=python : ``` -------------------------------- ### Python Import Statements Example (PEP8) Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/external_libs/python-daemon-2.0.5/doc/hacking.txt Demonstrates the PEP8 standard for Python import statements. Imports should be grouped at the top of the module, with each import statement typically importing a single module or multiple names from a single module. ```python import sys import os from spam import foo, bar, baz ``` -------------------------------- ### Pin CPU Cores to TRex Ports for Performance Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_stl/api/client_code.rst Illustrates how to optimize TRex performance by pinning specific CPU cores to network ports during traffic generation. This example shows adding streams, clearing statistics, starting traffic with a core mask, and waiting for completion. ```python c = STLClient() try: c.connect() c.reset(ports = [0, 1]) c.add_streams(s1, ports = [0]) c.clear_stats() c.start(ports = [0, 1], mult = "5mpps", duration = 10, core_mask = [0x1,0x2]) c.wait_on_traffic(ports = [0, 1]) if c.get_warnings(): pass finally: c.disconnect() ``` -------------------------------- ### TRex Console Commands Source: https://context7.com/cisco-system-traffic-generator/trex-core/llms.txt Basic TRex console commands for connecting, resetting ports, starting/stopping traffic, and viewing statistics. ```bash trex> connect # Connect to TRex server trex> reset # Reset all ports trex> start -f stl/udp_1pkt_simple.py -p 0 -m 1gbps # Start traffic trex> stats # Show statistics trex> stop # Stop traffic ``` -------------------------------- ### Configure TRex Server with Network Interfaces (YAML) Source: https://context7.com/cisco-system-traffic-generator/trex-core/llms.txt This YAML file defines the configuration for the TRex server, including the number of ports, threads, and network interface settings. It specifies IP addresses and default gateways for each port. This file is used when starting the TRex server. ```yaml # trex_cfg.yaml - TRex server configuration # Number of ports to use - port_limit: 4 # Configuration version version: 2 # Number of threads/cores to use c: 8 # PCI addresses of network interfaces # Run ./dpdk_nic_bind.py --status to find your interfaces interfaces: ["0b:00.0", "0b:00.1", "13:00.0", "13:00.1"] # Port-specific IP configuration port_info: # Port 0 - ip: 1.1.1.1 default_gw: 4.4.4.4 # Port 1 - ip: 2.2.2.2 default_gw: 3.3.3.3 # Port 2 - ip: 3.3.3.3 default_gw: 2.2.2.2 # Port 3 - ip: 4.4.4.4 default_gw: 1.1.1.1 # Start TRex server with configuration: # ./t-rex-64 -i --cfg /etc/trex_cfg.yaml # Additional options: # --software: Use software mode (no DPDK) # -c : Number of cores per port # --iom 0: Set IO mode for virtual environments ``` -------------------------------- ### Console-based API Example Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/doc_emu/api/client_code.rst Demonstrates how to use the console-based interface for the TRex emulation server, including loading profiles and showing emulation status. ```APIDOC ## Console-based API Usage ### Description This section illustrates the usage of the TRex console-based API for managing emulation profiles and viewing emulation status. It provides examples of common commands and their syntax. ### Method Console Interaction ( not HTTP Method ) ### Endpoint `./trex-console --emu` ### Parameters #### Console Commands * **`emu_load_profile`** - Loads an emulation profile. * `-f ` (string, required) - Path to the emulation profile file (e.g., `emu/simple_emu.py`). * `-t` (flag, required, must be at the end) - Applies the profile configuration. * `--ns ` (integer, optional) - Number of namespaces to configure. * `--clients ` (integer, optional) - Number of clients per namespace. * `--help` (flag, optional) - Displays help for the `emu_load_profile` command. * **`emu_show_all`** - Displays the current emulation status. ### Request Example ```bash $ > ./trex-console --emu (trex)> emu_load_profile -f emu/simple_emu.py -t --ns 2 --clients 5 ... (trex)> emu_show_all ``` ### Response #### Success Response Output varies based on the command executed. `emu_load_profile` typically shows loading progress, and `emu_show_all` displays emulation statistics. ``` -------------------------------- ### Stateless Client Connection and Basic Traffic Source: https://context7.com/cisco-system-traffic-generator/trex-core/llms.txt This API demonstrates how to connect to a TRex server, reset ports, create a simple UDP packet, define a continuous transmission stream, add it to a port, start traffic with specified parameters, wait for completion, retrieve statistics, and disconnect. ```APIDOC ## Connect and Send Basic UDP Traffic (Stateless) ### Description Connects to the TRex server, resets ports, creates a simple UDP packet, configures a continuous traffic stream, starts traffic transmission for a specified duration, retrieves statistics, and disconnects. ### Method Python API calls using `trex.stl.api` ### Endpoint N/A (Client-side API) ### Parameters None (all parameters are within Python code) ### Request Example ```python from trex.stl.api import * # Create and connect to TRex server client = STLClient(server = "127.0.0.1") client.connect() # Reset ports to clear any existing configuration client.reset(ports = [0, 1]) # Create a simple UDP packet packet = Ether()/IP(src="16.0.0.1", dst="48.0.0.1")/UDP(dport=12, sport=1025)/(10*'x') # Create stream with continuous transmission mode stream = STLStream( packet = STLPktBuilder(pkt = packet), mode = STLTXCont(pps = 100) ) # Add stream to port 0 client.add_streams(stream, ports = [0]) # Clear statistics before starting client.clear_stats() # Start traffic: 1 Gbps for 10 seconds client.start(ports = [0], mult = "1gbps", duration = 10) # Wait for traffic to complete client.wait_on_traffic(ports = [0]) # Get statistics stats = client.get_stats() print("TX packets:", stats[0]["opackets"]) print("RX packets:", stats[0]["ipackets"]) # Disconnect client.disconnect() ``` ### Response #### Success Response Prints TX and RX packet counts to the console. #### Response Example ``` TX packets: 100000 RX packets: 99980 ``` ``` -------------------------------- ### WirelessManager Initialization API Source: https://github.com/cisco-system-traffic-generator/trex-core/blob/master/scripts/automation/trex_control_plane/interactive/trex/wireless/docs/source/api.rst This section covers the initialization of the WirelessManager class, including starting the manager and loading plugins. A configuration YAML file is required for initialization. ```APIDOC ## WirelessManager Initialization API ### Description Initializes and starts the WirelessManager, requiring a configuration file and emphasizing the need to load plugins before starting. ### Methods - `WirelessManager.__init__(self, config_yaml_file)` - `WirelessManager.start(self)` ### Parameters #### `WirelessManager.__init__` - **config_yaml_file** (string) - Required - Path to the configuration YAML file. ### Request Example ```python # Assuming a config.yaml file exists from wireless.trex_wireless_manager import WirelessManager config_file = "path/to/your/config.yaml" wm = WirelessManager(config_file) wm.start() ``` ### Response - **Success Response (200)**: The manager is initialized and started successfully. - **Warning**: Load plugins before starting the WirelessManager. ```