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, s_delay=None, udp_mtu=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 at least a template or a cap_list, maybe both.
- Parameters
- default_ip_genASTFIPGen
trex.astf.trex_astf_profile.ASTFIPGen tuple generator object
- default_c_glob_infoASTFGlobalInfo
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_infoASTFGlobalInfo
trex.astf.trex_astf_global_info.ASTFGlobalInfo Same as default_tcp_server_info for client side.
- templatesASTFTemplate see
trex.astf.trex_astf_profile.ASTFTemplate define a list of manual templates or one template
- cap_listASTFCapInfo see
trex.astf.trex_astf_profile.ASTFCapInfo define a list of pcap files list in case there is no templates
- s_delayASTFCmdDelay or ASTFCmdDelayRnd see
trex.astf.trex_astf_profile.ASTFCmdDelayandtrex.astf.trex_astf_profile.ASTFCmdDelayRnd Server delay command before sending response back to client. This will be applied on all cap in cap list, unless cap specified his own s_delay. defaults to None means no delay.
- udp_mtu: int or None
MTU for udp packets, if packets exceeding the specified value they will be cut down from L7 in order to fit. This will be applied on all cap in cap list, unless cap specified his own udp_mtu. defaults to None.
- default_ip_genASTFIPGen
ASTFTemplate class¶
- class trex.astf.trex_astf_profile.ASTFTemplate(client_template=None, server_template=None, tg_name=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_templateASTFTCPClientTemplate see
trex.astf.trex_astf_profile.ASTFTCPClientTemplate client side template info
- server_templateASTFTCPServerTemplate see
trex.astf.trex_astf_profile.ASTFTCPServerTemplate server side template info
- tg_namestring or None
All the templates within the tg_name (template group name) will have shared statistics. All the templates that haven’t defined tg_name are collected under the same group.
- client_templateASTFTCPClientTemplate see
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, cont=None, tg_name=None, s_delay=None, udp_mtu=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
- filestring
pcap file name. Filesystem directory location is relative to the profile file in case it is not start with /
- cpsfloat
new connection per second rate
- assocASTFAssociation see
trex.astf.trex_astf_profile.ASTFAssociation rule for server association in default take the destination port from pcap file
- ip_genASTFIPGen see
trex.astf.trex_astf_profile.ASTFIPGen tuple generator for this template
- portuint16_t
Override destination port, by default is taken from pcap
- l7_percentfloat
L7 stream bandwidth percent
- limituint32_t
Limit the number of flows
- contbool
try to keep the number of flows up to limit.
s_glob_info : ASTFGlobalInfoPerTemplate see
trex.astf.trex_astf_global_info.ASTFGlobalInfoPerTemplatec_glob_info : ASTFGlobalInfoPerTemplate see
trex.astf.trex_astf_global_info.ASTFGlobalInfoPerTemplate- tg_namesstring or None
All the templates within the tg_name (template group name) will have shared statistics. All the templates that haven’t defined tg_name are collected under the same group.
- s_delayASTFCmdDelay or ASTFCmdDelayRnd see
trex.astf.trex_astf_profile.ASTFCmdDelayandtrex.astf.trex_astf_profile.ASTFCmdDelayRnd Server delay command before sending response back to client. defaults to None means no delay.
- udp_mtu: int or None
MTU for udp packets, if packets exceeding the specified value they will be cut down from L7 in order to fit. defaults to None.
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
- programASTFProgram see
trex.astf.trex_astf_profile.ASTFProgram L7 emulation program
glob_info : ASTFGlobalInfoPerTemplate see
trex.astf.trex_astf_global_info.ASTFGlobalInfoPerTemplateassoc : ASTFAssociation see
trex.astf.trex_astf_profile.ASTFAssociation- programASTFProgram see
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, cont=None, core_base=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_genASTFIPGen see
trex.astf.trex_astf_profile.ASTFIPGen generator
cluster : ASTFCluster see
trex.astf.trex_astf_profile.ASTFCluster- programASTFProgram see
trex.astf.trex_astf_profile.ASTFProgram L7 emulation program
- portuint16_t
destination port
- cpsfloat
New connection per second rate. Minimal value is 0.5
- limituint32_t
limit the number of flows. default is None which means zero (there is no limit)
- contbool
try to keep the number of flows up to limit.
- core_baseuint16_t
preferred core base hint when limit value is less than the number of cores. default is pseudo random value.
glob_info : ASTFGlobalInfoPerTemplate see
trex.astf.trex_astf_global_info.ASTFGlobalInfoPerTemplate- ip_genASTFIPGen see
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.ASTFIPGenDistdist_server : Server side ASTFIPGenDist
trex.astf.trex_astf_profile.ASTFIPGenDistglob : ASTFIPGenGlobal see
trex.astf.trex_astf_profile.ASTFIPGenGlobal
ASTFIPGenGlobal class¶
- class trex.astf.trex_astf_profile.ASTFIPGenGlobal(ip_offset='1.0.0.0', ip_offset_server=None)[source]¶
ip_gen_c = ASTFIPGenGlobal(ip_offset="1.0.0.0")
Global properties for IP generator
- Parameters
- ip_offset:
- Offset for dual mask ports.This value is added to each next pair of ports - ports 1 and 2 will have ip_offset added to IPs in their pool, ports 3 and 4 will have added ip_offset*2 and so on.
- ip_offset_server:
set in case you want offset per side.
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
- distributionstring
“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, s_delay=None, udp_mtu=None, addon=None)[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
- filestring
pcap file to analyze
- sidestring
“c” for client side or “s” for server side
- commandslist
list of command objects cound be NULL in case you call the API
- streambool
is stream based (TCP) or packet based (UDP)
- s_delayASTFCmdDelay or ASTFCmdDelayRnd see
trex.astf.trex_astf_profile.ASTFCmdDelayandtrex.astf.trex_astf_profile.ASTFCmdDelayRnd Server delay command before sending response back to client. This will override ASTFProfile s_delay if supplied. defaults to None means no delay.
- udp_mtu: int or None
MTU for udp packets, if packets exceeding the specified value they will be cut down from L7 in order to fit. defaults to None.
- addonstring
add-on name to handle data between program and base protocol.
- 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_bufstring
l7 stream as string
- chunk_sizeuint32_t
size of each chunk
- delay_usecuint32_t
the delay in usec to insert betwean each write
- send_msg(buf, size=0, fill=None)[source]¶
send UDP message (buf)
- example1
send_msg (buffer1) recv_msg (1)
- Parameters
- bufstring
l7 stream as string
- sizeuint32_t
total size of l7 stream, effective only when size > len(buf).
- fillstring
l7 stream filled by string, only if size is effective.
- 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, rx_mode=False)[source]¶
set_keepalive_msg (msec), set the keepalive timer for UDP flows
- Parameters
- msecuint32_t
the keepalive time in msec
- rx_modebool
reset by rx packets only. i.e. send_msg does not reset the keepalive timer.
- recv_msg(pkts)[source]¶
works for UDP flow
- Parameters
- pktsuint64_t
wait until the rx packet watermark is reached on flow counter.
- clearbool
when reach the watermark clear the flow counter
- send(buf, size=0, fill=None)[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
- bufstring
l7 stream as string
- sizeuint32_t
total size of l7 stream, effective only when size > len(buf).
- fillstring
l7 stream filled by string, only if size is effective.
- recv(bytes)[source]¶
- Parameters
- bytesuint64_t
wait until the rx bytes watermark is reached on flow counter.
- clearbool
when reach the watermark clear the flow counter
- 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_usecfloat
min delay for this time in usec
- max_usecfloat
min delay for this time in usec
- set_var(var_id, val)[source]¶
Set a flow variable
- Parameters
- var_idstring
var-id there are limited number of variables
- valuint64_t
value of the variable
- add_var(var_id, val)[source]¶
Add a value to a flow variable
- Parameters
- var_idstring
var-id there are limited number of variables
- valint
value to be added
- set_tick_var(var_id)[source]¶
Set a flow variable used with jmp_nz command. Timer will be started when declaring tick var.
- Parameters
- var_idstring
var-id there are limited number of variables
- add_tick_var(var_id, duration)[source]¶
Add a tick value to a flow variable
- Parameters
- var_idstring
var-id there are limited number of variables
- duartionfloat
duration of time in seconds to be added
- add_stats(stats_id, val)[source]¶
Add counter value to a statistics counter
- Parameters
- stats_idint or string
statistics counter index (0, 1, 2, … or ‘A’, ‘B’, ‘C’, …)
- valuint64_t
counter value to be added
- add_tick_stats(stats_id, var_id)[source]¶
Add elapsed time from a flow tick variable to a statistics counter
- Parameters
- stats_idint or string
statistics counter index (0, 1, 2, … or ‘A’, ‘B’, ‘C’, …)
- var_idstring
flow tick variable that the base time is saved
- jmp_nz(var_id, label)[source]¶
Decrement the flow variable, in case of none zero jump to label
- Parameters
- var_idint
flow var id
- labelstring
label id
- jmp_dp(var_id, label, duration)[source]¶
Check the time passed from flow variable, in case of time passed is less then duration jump to label.
- Parameters
- var_idint
flow var id
- labelstring
label id
- durationdouble
duration of time in seconds
- jmp_cmp(var_id, label, cmp_op, cmp_val)[source]¶
Jump to label if the result of comparison operation is true.
- Parameters
- var_idstring
flow var id
- labelstring
label id
- cmp_opstring
comparison operator: ‘lt’, ‘gt’, ‘eq’, ‘ge’, ‘le’, ‘ne’
- cmp_valint
a value to compare with flow variable id
ASTFAssociation class¶
- class trex.astf.trex_astf_profile.ASTFAssociation(rules=<trex.astf.trex_astf_profile.ASTFAssociationRule object>)[source]¶
assoc=ASTFAssociationRule(port=81)
- Parameters
- rulesASTFAssociationRule see
trex.astf.trex_astf_profile.ASTFAssociationRule rule or rules list
- rulesASTFAssociationRule see
ASTFAssociationRule class¶
- class trex.astf.trex_astf_profile.ASTFAssociationRule(port=80, ip_start=None, ip_end=None, l7_map=None, assoc_id=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") # port with L7 content mapping rule assoc=ASTFAssociationRule(port=81,l7_map=[0,1,2,3]) # port with L7 content mapping value (server-only mode) assoc=ASTFAssociationRule(port=81,l7_map={ "offset": [0,1], "value": [0,42] })
- Parameters
- port: uint16_t
destination port
- ip_start: string
ip range start
- ip_end: string
ip range end
- l7_map: list or dict
L7 mapping content by byte offsets with optional masks and values
- assoc_id: uint64_t
to specify a known value for the ASTFProgram addon handling