Skip to content

Commit

Permalink
Merge pull request #111 from tinynetwork/example-trex
Browse files Browse the repository at this point in the history
Example for TRex
  • Loading branch information
slankdev committed Nov 23, 2023
2 parents 83ec2b1 + ce75864 commit 554d4bc
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 0 deletions.
19 changes: 19 additions & 0 deletions Dockerfiles/trex/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM quay.io/centos/centos:stream8
ARG TREX_VERSION=3.04
ENV TREX_VERSION ${TREX_VERSION}

RUN dnf install -y --nodocs \
git wget procps python3 vim python3-pip pciutils gettext \
https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm \
&& dnf clean all \
&& dnf install -y --nodocs \
hostname iproute net-tools ethtool nmap iputils perf numactl \
sysstat htop rdma-core-devel libibverbs libibverbs-devel net-tools \
&& dnf clean all

WORKDIR /opt/
RUN wget --no-check-certificate https://trex-tgn.cisco.com/trex/release/v${TREX_VERSION}.tar.gz && \
tar -xzf v${TREX_VERSION}.tar.gz && \
mv v${TREX_VERSION} trex && \
rm v${TREX_VERSION}.tar.gz
WORKDIR /opt/trex
6 changes: 6 additions & 0 deletions Dockerfiles/trex/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
IMG=tinynetwork/trex:develop
build:
docker build -t $(IMG) .
push:
docker push $(IMG)
all: build push
9 changes: 9 additions & 0 deletions examples/trex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# TRex

```
tinet upconf | sudo sh -xe
docker exec -it T1
./t-rex-64 -i --astf --cfg ./cfg.yaml
./trex-console
trex>start -f http_eflow.py -t cps=10
```
3 changes: 3 additions & 0 deletions examples/trex/cfg.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
- port_limit: 2
version: 2
interfaces: ["net0", "net1"]
31 changes: 31 additions & 0 deletions examples/trex/spec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
nodes:
- name: DUT1
image: nicolaka/netshoot
docker_run_extra_args: --entrypoint bash
interfaces:
- { name: net0, type: direct, args: T1#net0 }
- { name: net1, type: direct, args: T1#net1 }
sysctls:
- sysctl: net.ipv4.ip_forward=1
- name: T1
image: tinynetwork/trex:develop
docker_run_extra_args: --entrypoint bash
interfaces:
- { name: net0, type: direct, args: DUT1#net0 }
- { name: net1, type: direct, args: DUT1#net1 }

node_configs:
- name: DUT1
cmds:
- cmd: ip link add br0 type bridge
- cmd: ip link set br0 up
- cmd: ip link set net0 master br0
- cmd: ip link set net1 master br0

postinit:
cmds:
- cmd: mkdir -p /var/run/netns
- cmd: ln -s /proc/$(docker inspect T1 -f {{.State.Pid}})/ns/net /var/run/netns/T1
- cmd: docker cp cfg.yaml T1:/opt/trex
- cmd: docker cp tcp_open.py T1:/opt/trex
- cmd: docker cp tcp_openclose.py T1:/opt/trex
43 changes: 43 additions & 0 deletions examples/trex/tcp_open.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from trex.astf.api import *
import argparse


class Prof1():
def __init__(self):
pass # tunables

def create_profile(self, cps):
prog_c = ASTFProgram()
prog_c.connect()
prog_c.reset()
prog_s = ASTFProgram()
prog_s.wait_for_peer_close()

# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["20.0.0.0", "20.0.255.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["30.0.0.0", "30.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
dist_client=ip_gen_c,
dist_server=ip_gen_s)

# template
temp_c = ASTFTCPClientTemplate(program=prog_c, ip_gen=ip_gen, cps=cps,limit=cps)
temp_s = ASTFTCPServerTemplate(program=prog_s)
template = ASTFTemplate(client_template=temp_c, server_template=temp_s)

# profile
profile = ASTFProfile(default_ip_gen=ip_gen,
templates=template)
return profile

def get_profile(self, tunables, **kwargs):
parser = argparse.ArgumentParser(
description='Argparser for {}'.format(os.path.basename(__file__)),
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--cps', type=int, default=1)
args = parser.parse_args(tunables)
return self.create_profile(args.cps)


def register():
return Prof1()
42 changes: 42 additions & 0 deletions examples/trex/tcp_openclose.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from trex.astf.api import *
import argparse


class Prof1():
def __init__(self):
pass # tunables

def create_profile(self, cps):
prog_c = ASTFProgram()
prog_c.connect()
prog_s = ASTFProgram()
prog_s.wait_for_peer_close()

# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["20.0.0.0", "20.0.255.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["30.0.0.0", "30.0.255.255"], distribution="seq")
ip_gen = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
dist_client=ip_gen_c,
dist_server=ip_gen_s)

# template
temp_c = ASTFTCPClientTemplate(program=prog_c, ip_gen=ip_gen, cps=cps,limit=cps)
temp_s = ASTFTCPServerTemplate(program=prog_s)
template = ASTFTemplate(client_template=temp_c, server_template=temp_s)

# profile
profile = ASTFProfile(default_ip_gen=ip_gen,
templates=template)
return profile

def get_profile(self, tunables, **kwargs):
parser = argparse.ArgumentParser(
description='Argparser for {}'.format(os.path.basename(__file__)),
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('--cps', type=int, default=1)
args = parser.parse_args(tunables)
return self.create_profile(args.cps)


def register():
return Prof1()

0 comments on commit 554d4bc

Please sign in to comment.