Traffic profile modules

The TRex ASTFProfile traffic profile define how traffic should be generated for example what is the client ip ranges, server ranges, traffic pattern etc

Example1:

def get_profile(self):
    # ip generator
    ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"],
                             distribution="seq")
    ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.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)

    return ASTFProfile(default_ip_gen=ip_gen,
                        cap_list=[ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap",cps=1)])

Example2:

def create_profile(self):
    # client commands
    prog_c = ASTFProgram()
    prog_c.send(http_req)
    prog_c.recv(len(http_response))

    prog_s = ASTFProgram()
    prog_s.recv(len(http_req))
    prog_s.send(http_response)

    # ip generator
    ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
    ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.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)
    temp_s = ASTFTCPServerTemplate(program=prog_s)  # using default association
    template = ASTFTemplate(client_template=temp_c, server_template=temp_s)

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

Example3:

def create_profile(self):
    ip_gen_c1 = ASTFIPGenDist(ip_range=["16.0.0.1", "16.0.0.255"], distribution="seq")
    ip_gen_s1 = ASTFIPGenDist(ip_range=["48.0.0.1", "48.0.255.255"], distribution="seq")
    ip_gen1 = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
                        dist_client=ip_gen_c1,
                        dist_server=ip_gen_s1)

    ip_gen_c2 = ASTFIPGenDist(ip_range=["10.0.0.1", "10.0.0.255"], distribution="seq")
    ip_gen_s2 = ASTFIPGenDist(ip_range=["20.0.0.1", "20.0.255.255"], distribution="seq")
    ip_gen2 = ASTFIPGen(glob=ASTFIPGenGlobal(ip_offset="1.0.0.0"),
                        dist_client=ip_gen_c2,
                        dist_server=ip_gen_s2)

    profile = ASTFProfile(default_ip_gen=ip_gen1, cap_list=[
        ASTFCapInfo(file="../cap2/http_get.pcap"),
        ASTFCapInfo(file="../cap2/http_get.pcap", ip_gen=ip_gen2, port=8080)
        ])

    return profile

ASTFProfile class

class trex.astf.trex_astf_profile.ASTFProfile(default_ip_gen, default_c_glob_info=None, default_s_glob_info=None, templates=None, cap_list=None)[source]

ASTF profile

ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.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)

return ASTFProfile(default_ip_gen=ip_gen,
                    cap_list=[ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap",cps=1)])

Define a ASTF profile

You should give either templates or cap_list (mutual exclusion).

Parameters:
default_ip_gen : ASTFIPGen trex.astf.trex_astf_profile.ASTFIPGen

tuple generator object

default_c_glob_info : ASTFGlobalInfo trex.astf.trex_astf_global_info.ASTFGlobalInfo

tcp parameters to be used for client side, if cap_list is given. This is optional. If not specified, TCP parameters for each flow will be taken from its cap file.

default_s_glob_info : ASTFGlobalInfo trex.astf.trex_astf_global_info.ASTFGlobalInfo

Same as default_tcp_server_info for client side.

templates : ASTFTemplate see trex.astf.trex_astf_profile.ASTFTemplate

define a list of manual templates or one template

cap_list : ASTFCapInfo see trex.astf.trex_astf_profile.ASTFCapInfo

define a list of pcap files list in case there is no templates

classmethod load_py(python_file, **kwargs)[source]

Load from ASTF Python profile

static load_json(json_file)[source]

Load (from JSON file) a profile with a number of streams

classmethod load(filename, **kwargs)[source]

Load a profile by its type. Supported types are: * py * json

Parameters:filename : string as filename kwargs : forward those key-value pairs to the profile

ASTFTemplate class

class trex.astf.trex_astf_profile.ASTFTemplate(client_template=None, server_template=None)[source]

One manual template

# client commands
prog_c = ASTFProgram()
prog_c.send(http_req)
prog_c.recv(len(http_response))

prog_s = ASTFProgram()
prog_s.recv(len(http_req))
prog_s.send(http_response)

# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.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)
temp_s = ASTFTCPServerTemplate(program=prog_s)  # using default association
template = ASTFTemplate(client_template=temp_c, server_template=temp_s)

Define a ASTF profile

You should give either templates or cap_list (mutual exclusion).

Parameters:
client_template : ASTFTCPClientTemplate see trex.astf.trex_astf_profile.ASTFTCPClientTemplate

client side template info

server_template : ASTFTCPServerTemplate see trex.astf.trex_astf_profile.ASTFTCPServerTemplate

server side template info

ASTFCapInfo class

class trex.astf.trex_astf_profile.ASTFCapInfo(file=None, cps=None, assoc=None, ip_gen=None, port=None, l7_percent=None, s_glob_info=None, c_glob_info=None, limit=None)[source]
ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap",cps=1)

ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap",l7_percent=10.0)

ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap",l7_percent=10.0,port=8080)

ASTFCapInfo(file="../avl/delay_10_http_browsing_0.pcap",l7_percent=10.0,port=8080,ip_gen=Mygen)

Define one template information based on pcap file analysis

Parameters:
file : string

pcap file name. Filesystem directory location is relative to the profile file in case it is not start with /

cps : float

new connection per second rate

assoc : ASTFAssociation see trex.astf.trex_astf_profile.ASTFAssociation

rule for server association in default take the destination port from pcap file

ip_gen : ASTFIPGen see trex.astf.trex_astf_profile.ASTFIPGen

tuple generator for this template

port : uint16_t

Override destination port, by default is taken from pcap

l7_percent : float

L7 stream bandwidth percent

limit : uint32_t

Limit the number of flows

s_glob_info : ASTFGlobalInfoPerTemplate see trex.astf.trex_astf_global_info.ASTFGlobalInfoPerTemplate

c_glob_info : ASTFGlobalInfoPerTemplate see trex.astf.trex_astf_global_info.ASTFGlobalInfoPerTemplate

ASTFTCPServerTemplate class

class trex.astf.trex_astf_profile.ASTFTCPServerTemplate(program=None, assoc=<trex.astf.trex_astf_profile.ASTFAssociation object>, glob_info=None)[source]

One server side template

# server commands
prog_s = ASTFProgram()
prog_s.recv(len(http_req))
prog_s.send(http_response)


# template
temp_s = ASTFTCPServerTemplate(program=prog_s, tcp_info=tcp_params)  # using default association
Parameters:
program : ASTFProgram see trex.astf.trex_astf_profile.ASTFProgram

L7 emulation program

glob_info : ASTFGlobalInfoPerTemplate see trex.astf.trex_astf_global_info.ASTFGlobalInfoPerTemplate

assoc : ASTFAssociation see trex.astf.trex_astf_profile.ASTFAssociation

ASTFTCPClientTemplate class

class trex.astf.trex_astf_profile.ASTFTCPClientTemplate(ip_gen, cluster=<trex.astf.trex_astf_profile.ASTFCluster object>, program=None, port=80, cps=1, glob_info=None, limit=None)[source]

One manual template

# client commands
prog_c = ASTFProgram()
prog_c.send(http_req)
prog_c.recv(len(http_response))


# ip generator
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.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)
Parameters:
ip_gen : ASTFIPGen see trex.astf.trex_astf_profile.ASTFIPGen

generator

cluster : ASTFCluster see trex.astf.trex_astf_profile.ASTFCluster

program : ASTFProgram see trex.astf.trex_astf_profile.ASTFProgram

L7 emulation program

port : uint16_t

destination port

cps : float

New connection per second rate. Minimal value is 0.5

limit : uint32_t

limit the number of flows. default is None which means zero (there is no limit)

glob_info : ASTFGlobalInfoPerTemplate see trex.astf.trex_astf_global_info.ASTFGlobalInfoPerTemplate

ASTFIPGen class

class trex.astf.trex_astf_profile.ASTFIPGen(dist_client, dist_server, glob=<trex.astf.trex_astf_profile.ASTFIPGenGlobal object>)[source]
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")
ip_gen_s = ASTFIPGenDist(ip_range=["48.0.0.0", "48.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)

Define a ASTFIPGen generator

Parameters:

dist_client : Client side ASTFIPGenDist trex.astf.trex_astf_profile.ASTFIPGenDist

dist_server : Server side ASTFIPGenDist trex.astf.trex_astf_profile.ASTFIPGenDist

glob : ASTFIPGenGlobal see trex.astf.trex_astf_profile.ASTFIPGenGlobal

ASTFIPGenGlobal class

class trex.astf.trex_astf_profile.ASTFIPGenGlobal(ip_offset='1.0.0.0')[source]
ip_gen_c = ASTFIPGenGlobal(ip_offset="1.0.0.0")

Global properties for IP generator

Parameters:ip_offset : offset for dual mask ports

ASTFIPGenDist class

class trex.astf.trex_astf_profile.ASTFIPGenDist(ip_range, distribution='seq', per_core_distribution=None)[source]
ip_gen_c = ASTFIPGenDist(ip_range=["16.0.0.0", "16.0.0.255"], distribution="seq")

Define a ASTFIPGenDist

Parameters:

ip_range : list of min-max ip strings

distribution : string

“seq” or “rand”

per_core_distribution : “seq” or “default”

in case of “seq” each core will get continuous range of Ip. in case of “default” it is not necessarily the case.

ASTFProgram class

class trex.astf.trex_astf_profile.ASTFProgram(file=None, side='c', commands=None, stream=True)[source]

Emulation L7 program

# server commands
prog_s = ASTFProgram()
prog_s.recv(len(http_req))
prog_s.send(http_response)
prog_s.delay(10)
prog_s.reset()
Parameters:
file : string

pcap file to analyze

side : string

“c” for client side or “s” for server side

commands : list

list of command objects cound be NULL in case you call the API

stream : bool

is stream based (TCP) or packet based (UDP)

update_keepalive(prog_s)[source]

in case of pcap file need to copy the keepalive command from client to server side

send_chunk(l7_buf, chunk_size, delay_usec)[source]

Send l7_buffer by splitting it into small chunks and issue a delay betwean each chunk. This is a utility command that works on top of send/delay command

example1
send (buffer1,100,10) will split the buffer to buffers of 100 bytes with delay of 10usec
Parameters:
l7_buf : string

l7 stream as string

chunk_size : uint32_t

size of each chunk

delay_usec : uint32_t

the delay in usec to insert betwean each write

close_msg()[source]

explicit UDP flow close

send_msg(buf)[source]

send UDP message (buf)

example1
send_msg (buffer1) recv_msg (1)
Parameters:
buf : string

l7 stream as string

set_send_blocking(block)[source]

set_send_blocking (block), set the stream transmit mode

block : for send command wait until the last byte is ack

non-block: continue to the next command when the queue is almost empty, this is good for pipeline the transmit

Parameters:block : bool
set_keepalive_msg(msec)[source]

set_keepalive_msg (sec), set the keepalive timer for UDP flows

Parameters:
msec : uint32_t

the keepalive time in msec

recv_msg(pkts)[source]

works for UDP flow

Parameters:
pkts : uint32_t

wait until the rx packet watermark is reached on flow counter.

clear : bool

when reach the watermark clear the flow counter

send(buf)[source]

send (l7_buffer) over TCP and wait for the buffer to be acked by peer. Rx side could work in parallel

example1

send (buffer1) send (buffer2)

Will behave differently than

example1 send (buffer1+ buffer2)

in the first example there would be PUSH in the last byte of the buffer and immediate ACK from peer while in the last example the buffer will be sent together (might be one segment)

Parameters:
buf : string

l7 stream as string

recv(bytes)[source]
Parameters:
bytes : uint32_t

wait until the rx bytes watermark is reached on flow counter.

clear : bool

when reach the watermark clear the flow counter

delay(usec)[source]

delay for x usec

Parameters:
usec : uint32_t

delay for this time in usec

reset()[source]

For TCP connection send RST to peer. Should be the last command

wait_for_peer_close()[source]

For TCP connection wait for peer side to close (read==0) and only then close. Should be the last command This simulates server side that waits for a requests until client retire with close().

connect()[source]

for TCP connection wait for the connection to be connected. should be the first command in the client side

accept()[source]

for TCP connection wait for the connection to be accepted. should be the first command in the server side

delay_rand(min_usec, max_usec)[source]

delay for a random time betwean min-max usec with uniform distribution

Parameters:
min_usec : float

min delay for this time in usec

max_usec : float

min delay for this time in usec

set_var(var_id, val)[source]

Set a flow variable

Parameters:
var_id : string

var-id there are limited number of variables

val : uint32_t

value of the variable

set_label(label)[source]

Set a location label name. used with jmp_nz command

jmp_nz(var_id, label)[source]

Decrement the flow variable, in case of none zero jump to label

Parameters:
var_id : int

flow var id

label : string

label id

ASTFAssociation class

class trex.astf.trex_astf_profile.ASTFAssociation(rules=<trex.astf.trex_astf_profile.ASTFAssociationRule object>)[source]
assoc=ASTFAssociationRule(port=81)
Parameters:
rules : ASTFAssociationRule see trex.astf.trex_astf_profile.ASTFAssociationRule

rule or rules list

ASTFAssociationRule class

class trex.astf.trex_astf_profile.ASTFAssociationRule(port=80, ip_start=None, ip_end=None)[source]
# only port
assoc=ASTFAssociationRule(port=81)

# port with range or destination ips
assoc=ASTFAssociationRule(port=81,ip_start="48.0.0.1",ip_end="48.0.0,16")
Parameters:
port: uint16_t

destination port

ip_start: string

ip range start

ip_end: string

ip range end

ASTFGlobalInfo class

class trex.astf.trex_astf_global_info.ASTFGlobalInfo[source]

TODO: add description

ASTFGlobalInfoPerTemplate class

class trex.astf.trex_astf_global_info.ASTFGlobalInfoPerTemplate[source]

TODO: add description