diff options
author | Hanoh Haim <hhaim@cisco.com> | 2016-05-11 13:27:22 +0300 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2016-05-11 13:27:22 +0300 |
commit | 0bd2c9ce6c5264b9b3a9a6e42286edae389ebce4 (patch) | |
tree | 8e036d790ef7d5ac0f434e4c821e96a0882790af /scripts/automation/trex_control_plane/doc_stl | |
parent | cd380381f300e5cb5db489a1dfd829350e9ff691 (diff) |
add more example for client api
Diffstat (limited to 'scripts/automation/trex_control_plane/doc_stl')
-rwxr-xr-x | scripts/automation/trex_control_plane/doc_stl/api/client_code.rst | 5 | ||||
-rwxr-xr-x | scripts/automation/trex_control_plane/doc_stl/api/field_engine.rst | 44 |
2 files changed, 49 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/doc_stl/api/client_code.rst b/scripts/automation/trex_control_plane/doc_stl/api/client_code.rst index d3e48dab..165a9a0d 100755 --- a/scripts/automation/trex_control_plane/doc_stl/api/client_code.rst +++ b/scripts/automation/trex_control_plane/doc_stl/api/client_code.rst @@ -42,6 +42,11 @@ Example 1 - Typical Python API:: # 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() diff --git a/scripts/automation/trex_control_plane/doc_stl/api/field_engine.rst b/scripts/automation/trex_control_plane/doc_stl/api/field_engine.rst index 541e195f..d4f95170 100755 --- a/scripts/automation/trex_control_plane/doc_stl/api/field_engine.rst +++ b/scripts/automation/trex_control_plane/doc_stl/api/field_engine.rst @@ -14,6 +14,50 @@ The FE can allocate stream variables in a stream context, write a stream variabl * Update IPv4 checksum +The following snippet creates a range of 64 bytes packets :: + + # split the range of IP to cores + # + class STLS1(object): + + def __init__ (self): + self.fsize =64; + + def create_stream (self): + # create a base packet and pad it to size + size = self.fsize - 4; # no FCS + + base_pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025) + + pad = max(0, size - len(base_pkt)) * 'x' + + vm = STLScVmRaw( [ STLVmFlowVar ( "ip_src", + min_value="10.0.0.1", + max_value="10.0.0.255", + size=4, + step=1, + op="inc"), + STLVmWrFlowVar (fv_name="ip_src", + pkt_offset= "IP.src" ), # write ip to packet IP.src + STLVmFixIpv4(offset = "IP") # fix checksum + ], + split_by_field = "ip_src", + cache_size =255 # cache the packets, much better performance + ); + + pkt = STLPktBuilder(pkt = base_pkt/pad, + vm = vm) + stream = STLStream(packet = pkt, + mode = STLTXCont()) + #print(stream.to_code()) + return stream + + + def get_streams (self, direction = 0, **kwargs): + # create 1 stream + return [ self.create_stream() ] + + The following snippet creates a SYN attack:: # create attack from random src_ip from 16.0.0.0-18.0.0.254 and random src_port 1025-65000 |