add simple example for FixHwChecksum instruction
authorHanoh Haim <[email protected]>
Thu, 29 Sep 2016 11:00:35 +0000 (14:00 +0300)
committerHanoh Haim <[email protected]>
Thu, 29 Sep 2016 13:50:29 +0000 (16:50 +0300)
scripts/stl/syn_attack_fix_cs_hw.py [new file with mode: 0644]

diff --git a/scripts/stl/syn_attack_fix_cs_hw.py b/scripts/stl/syn_attack_fix_cs_hw.py
new file mode 100644 (file)
index 0000000..694a97a
--- /dev/null
@@ -0,0 +1,60 @@
+from trex_stl_lib.api import *
+
+class STLS1(object):
+    """ attack 48.0.0.1 at port 80
+    """
+
+    def __init__ (self):
+        self.max_pkt_size_l3  =9*1024;
+
+    def create_stream (self):
+
+        # TCP SYN
+        base_pkt  = Ether()/IP(dst="48.0.0.1")/TCP(dport=80,flags="S")
+
+
+        # vm
+        vm = STLScVmRaw( [ STLVmFlowVar(name="ip_src", 
+                                              min_value="16.0.0.0", 
+                                              max_value="18.0.0.254", 
+                                              size=4, op="random"),
+
+                           STLVmFlowVar(name="src_port", 
+                                              min_value=1025, 
+                                              max_value=65000, 
+                                              size=2, op="random"),
+
+                           STLVmWrFlowVar(fv_name="ip_src", pkt_offset= "IP.src" ),
+
+
+                           STLVmWrFlowVar(fv_name="src_port", 
+                                          pkt_offset= "TCP.sport"), # fix udp len  
+
+                           # must be last 
+                           STLVmFixChecksumHw(l3_offset = "IP",
+                                              l4_offset = "TCP",
+                                              l4_type  = CTRexVmInsFixHwCs.L4_TYPE_TCP )# hint, TRex can know that 
+
+                          ]
+                       )
+
+        pkt = STLPktBuilder(pkt = base_pkt,
+                            vm = vm)
+
+        return STLStream(packet = pkt,
+                         random_seed = 0x1234,# can be remove. will give the same random value any run
+                         mode = STLTXCont())
+
+
+
+    def get_streams (self, direction = 0, **kwargs):
+        # create 1 stream 
+        return [ self.create_stream() ]
+
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+