From 0bd2c9ce6c5264b9b3a9a6e42286edae389ebce4 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Wed, 11 May 2016 13:27:22 +0300 Subject: add more example for client api --- .../trex_control_plane/doc_stl/api/client_code.rst | 5 +++ .../doc_stl/api/field_engine.rst | 44 ++++++++++++++++++++++ 2 files changed, 49 insertions(+) (limited to 'scripts/automation/trex_control_plane/doc_stl') 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 -- cgit 1.2.3-korg