add python profile for new write_mask command
authorHanoh Haim <[email protected]>
Thu, 18 Feb 2016 14:10:30 +0000 (16:10 +0200)
committerHanoh Haim <[email protected]>
Thu, 18 Feb 2016 14:10:30 +0000 (16:10 +0200)
scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/api.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py
scripts/exp/udp_1pkt_mac_mask1.pcap [new file with mode: 0644]
scripts/exp/udp_1pkt_mac_mask2.pcap [new file with mode: 0644]
scripts/exp/udp_1pkt_mac_mask3.pcap [new file with mode: 0644]
scripts/stl/udp_1pkt_mac_mask1.py [new file with mode: 0644]
scripts/stl/udp_1pkt_mac_mask2.py [new file with mode: 0644]
scripts/stl/udp_1pkt_mac_mask3.py [new file with mode: 0644]
src/rpc-server/commands/trex_rpc_cmd_stream.cpp
src/rpc-server/commands/trex_rpc_cmds.h

index a2249d5..9419ab6 100644 (file)
@@ -139,7 +139,7 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
 
     def test_stl_profiles (self):
 
-        p = [ 
+        p0 = [ 
             ["udp_1pkt_1mac_override.py","-m 1 -l 50",True],
             ["syn_attack.py","-m 1 -l 50",False],               # can't compare random now 
             ["udp_1pkt_1mac.py","-m 1 -l 50",True],
@@ -175,12 +175,17 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
             ["udp_1pkt_simple_mac_dst.py","-m 1 -l 1 ",True],
             ["udp_1pkt_simple_mac_src.py","-m 1 -l 1 ",True],
             ["udp_1pkt_simple_mac_dst_src.py","-m 1 -l 1 ",True],
-            ["burst_3st_loop_x_times.py","-m 1 -l 20 ",True]
+            ["burst_3st_loop_x_times.py","-m 1 -l 20 ",True],
+            ["udp_1pkt_mac_step.py","-m 1 -l 20 ",True],
+            ["udp_1pkt_mac_mask1.py","-m 1 -l 20 ",True] ,
+            ["udp_1pkt_mac_mask2.py","-m 1 -l 20 ",True],
+            ["udp_1pkt_mac_mask3.py","-m 1 -l 20 ",True]
+
 
           ];
 
 
-        p1  = [ ["udp_1pkt_mac_step.py","-m 1 -l 20 ",True] ]
+        p  = [ ["udp_1pkt_mac_mask3.py","-m 1 -l 20 ",True] ]
         
 
         for obj in p:
index 9ce9f7f..d19dcaf 100644 (file)
@@ -16,6 +16,7 @@ STLPktBuilder          = CScapyTRexPktBuilder
 # VM
 STLVmFlowVar           = CTRexVmDescFlowVar
 STLVmWrFlowVar         = CTRexVmDescWrFlowVar
+STLVmWrMaskFlowVar     = CTRexVmDescWrMaskFlowVar
 STLVmFixIpv4           = CTRexVmDescFixIpv4
 STLVmTrimPktSize       = CTRexVmDescTrimPktSize
 STLVmTupleGen          = CTRexVmDescTupleGen
index c788e27..95c32b2 100644 (file)
@@ -234,6 +234,22 @@ class CTRexVmInsWrFlowVar(CTRexVmInsBase):
         self.is_big_endian = is_big_endian
         assert type(is_big_endian)==bool, 'type of is_big_endian is not bool'
 
+class CTRexVmInsWrMaskFlowVar(CTRexVmInsBase):
+    def __init__(self, fv_name, pkt_offset,pkt_cast_size,mask,shift, is_big_endian=True):
+        super(CTRexVmInsWrMaskFlowVar, self).__init__("write_mask_flow_var")
+        self.name = fv_name
+        assert type(fv_name)==str, 'type of fv_name is not str'
+        self.pkt_offset = pkt_offset
+        assert type(pkt_offset)==int, 'type of pkt_offset is not int'
+        self.pkt_cast_size = pkt_cast_size
+        assert type(pkt_cast_size)==int, 'type of pkt_cast_size is not int'
+        self.mask = mask
+        assert type(mask)==int, 'type of mask is not int'
+        self.shift = shift
+        assert type(shift)==int, 'type of shift is not int'
+        self.is_big_endian = is_big_endian
+        assert type(is_big_endian)==bool, 'type of is_big_endian is not bool'
+
 class CTRexVmInsTrimPktSize(CTRexVmInsBase):
     def __init__(self,fv_name):
         super(CTRexVmInsTrimPktSize, self).__init__("trim_pkt_size")
@@ -562,6 +578,37 @@ class CTRexVmDescWrFlowVar(CTRexVmDescBase):
             t=parent._name_to_offset(self.pkt_offset)
             self.pkt_offset = t[0]
 
+class CTRexVmDescWrMaskFlowVar(CTRexVmDescBase):
+    def __init__(self, fv_name, pkt_offset, pkt_cast_size=1, mask=0xff, shift=0, offset_fixup=0, is_big=True):
+        super(CTRexVmDescWrMaskFlowVar, self).__init__()
+        self.name =fv_name
+        assert type(fv_name)==str, 'type of fv_name is not str'
+        self.offset_fixup =offset_fixup
+        assert type(offset_fixup)==int, 'type of offset_fixup is not int'
+        self.pkt_offset =pkt_offset
+        self.pkt_cast_size =pkt_cast_size
+        assert type(pkt_cast_size)==int,'type of pkt_cast_size is not int'
+        if not (pkt_cast_size in [1,2,4]):
+            raise CTRexPacketBuildException(-10,"not valid cast size");
+
+        self.mask = mask
+        assert type(mask)==int,'type of mask is not int'
+        self.shift = shift
+        assert type(shift)==int,'type of shift is not int'
+        self.is_big =is_big;
+        assert type(is_big)==bool,'type of is_big_endian is not bool'
+
+    def get_var_ref (self):
+        return self.name
+
+    def get_obj (self):
+            return  CTRexVmInsWrMaskFlowVar(self.name,self.pkt_offset+self.offset_fixup,self.pkt_cast_size,self.mask,self.shift,self.is_big)
+
+    def compile(self,parent): 
+        if type(self.pkt_offset)==str:
+            t=parent._name_to_offset(self.pkt_offset)
+            self.pkt_offset = t[0]
+
 
 class CTRexVmDescTrimPktSize(CTRexVmDescBase):
     def __init__(self,fv_name):
diff --git a/scripts/exp/udp_1pkt_mac_mask1.pcap b/scripts/exp/udp_1pkt_mac_mask1.pcap
new file mode 100644 (file)
index 0000000..65adb5e
Binary files /dev/null and b/scripts/exp/udp_1pkt_mac_mask1.pcap differ
diff --git a/scripts/exp/udp_1pkt_mac_mask2.pcap b/scripts/exp/udp_1pkt_mac_mask2.pcap
new file mode 100644 (file)
index 0000000..07b0011
Binary files /dev/null and b/scripts/exp/udp_1pkt_mac_mask2.pcap differ
diff --git a/scripts/exp/udp_1pkt_mac_mask3.pcap b/scripts/exp/udp_1pkt_mac_mask3.pcap
new file mode 100644 (file)
index 0000000..d168dee
Binary files /dev/null and b/scripts/exp/udp_1pkt_mac_mask3.pcap differ
diff --git a/scripts/stl/udp_1pkt_mac_mask1.py b/scripts/stl/udp_1pkt_mac_mask1.py
new file mode 100644 (file)
index 0000000..37f5079
--- /dev/null
@@ -0,0 +1,35 @@
+from trex_stl_lib.api import *
+
+
+# step is not 1. 
+class STLS1(object):
+
+    def __init__ (self):
+        self.fsize  =64; # the size of the packet 
+
+    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 = CTRexScRaw( [ STLVmFlowVar(name="mac_src", min_value=1, max_value=30, size=2, op="dec",step=1), 
+                           STLVmWrMaskFlowVar(fv_name="mac_src", pkt_offset= 11,pkt_cast_size=1, mask=0xff) # mask command ->write it as one byte
+                          ]
+                       )
+
+        return STLStream(packet = STLPktBuilder(pkt = base_pkt/pad,vm = vm),
+                         mode = STLTXCont( pps=10 ))
+
+    def get_streams (self, direction = 0):
+        # create 1 stream 
+        return [ self.create_stream() ]
+
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+
diff --git a/scripts/stl/udp_1pkt_mac_mask2.py b/scripts/stl/udp_1pkt_mac_mask2.py
new file mode 100644 (file)
index 0000000..b72f0c3
--- /dev/null
@@ -0,0 +1,35 @@
+from trex_stl_lib.api import *
+
+
+# step is not 1. 
+class STLS1(object):
+
+    def __init__ (self):
+        self.fsize  =64; # the size of the packet 
+
+    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 = CTRexScRaw( [ STLVmFlowVar(name="mac_src", min_value=1, max_value=30, size=2, op="dec",step=1), 
+                           STLVmWrMaskFlowVar(fv_name="mac_src", pkt_offset= 10,pkt_cast_size=2, mask=0xff00,shift=8) # take the var shift it 8 (x256) write only to LSB
+                          ]
+                       )
+
+        return STLStream(packet = STLPktBuilder(pkt = base_pkt/pad,vm = vm),
+                         mode = STLTXCont( pps=10 ))
+
+    def get_streams (self, direction = 0):
+        # create 1 stream 
+        return [ self.create_stream() ]
+
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+
diff --git a/scripts/stl/udp_1pkt_mac_mask3.py b/scripts/stl/udp_1pkt_mac_mask3.py
new file mode 100644 (file)
index 0000000..ef5bc4f
--- /dev/null
@@ -0,0 +1,35 @@
+from trex_stl_lib.api import *
+
+
+# step is not 1. 
+class STLS1(object):
+
+    def __init__ (self):
+        self.fsize  =64; # the size of the packet 
+
+    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 = CTRexScRaw( [ STLVmFlowVar(name="mac_src", min_value=1, max_value=30, size=2, op="dec",step=1), 
+                           STLVmWrMaskFlowVar(fv_name="mac_src", pkt_offset= 10,pkt_cast_size=1, mask=0x1,shift=-1) # take var mac_src>>1 and write the LSB every two packet there should be a change
+                          ]
+                       )
+
+        return STLStream(packet = STLPktBuilder(pkt = base_pkt/pad,vm = vm),
+                         mode = STLTXCont( pps=10 ))
+
+    def get_streams (self, direction = 0):
+        # create 1 stream 
+        return [ self.create_stream() ]
+
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+
index 508967b..920991e 100644 (file)
@@ -292,6 +292,25 @@ TrexRpcCmdAddStream::parse_vm_instr_flow_var(const Json::Value &inst, TrexStream
                                  );
 }
 
+
+void 
+TrexRpcCmdAddStream::parse_vm_instr_write_mask_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result) {
+    std::string  flow_var_name = parse_string(inst, "name", result);
+    uint16_t     pkt_offset    = parse_uint16(inst, "pkt_offset", result);
+    uint16_t      pkt_cast_size = parse_uint16(inst, "pkt_cast_size", result);
+    uint32_t     mask          = parse_uint32(inst, "mask", result);
+    int          shift         = parse_int(inst, "shift", result);
+    bool         is_big_endian = parse_bool(inst,   "is_big_endian", result);
+
+    stream->m_vm.add_instruction(new StreamVmInstructionWriteMaskToPkt(flow_var_name,
+                                                                       pkt_offset,
+                                                                       (uint8_t)pkt_cast_size,
+                                                                       mask,
+                                                                       shift,
+                                                                       is_big_endian));
+}
+
+
 void 
 TrexRpcCmdAddStream::parse_vm_instr_write_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result) {
     std::string  flow_var_name = parse_string(inst, "name", result);
@@ -314,7 +333,7 @@ TrexRpcCmdAddStream::parse_vm(const Json::Value &vm, TrexStream *stream, Json::V
     for (int i = 0; i < instructions.size(); i++) {
         const Json::Value & inst = parse_object(instructions, i, result);
 
-        auto vm_types = {"fix_checksum_ipv4", "flow_var", "write_flow_var","tuple_flow_var","trim_pkt_size"};
+        auto vm_types = {"fix_checksum_ipv4", "flow_var", "write_flow_var","tuple_flow_var","trim_pkt_size","write_mask_flow_var"};
         std::string vm_type = parse_choice(inst, "type", vm_types, result);
 
         // checksum instruction
@@ -332,6 +351,8 @@ TrexRpcCmdAddStream::parse_vm(const Json::Value &vm, TrexStream *stream, Json::V
 
         } else if (vm_type == "trim_pkt_size") {
             parse_vm_instr_trim_pkt_size(inst, stream, result);
+        }else if (vm_type == "write_mask_flow_var") {
+            parse_vm_instr_write_mask_flow_var(inst, stream, result);
         } else {
             /* internal error */
             throw TrexRpcException("internal error");
index 48a3878..3dc2ce0 100644 (file)
@@ -100,6 +100,8 @@ void parse_vm_instr_tuple_flow_var(const Json::Value &inst, TrexStream *stream,
 void parse_vm_instr_trim_pkt_size(const Json::Value &inst, TrexStream *stream, Json::Value &result);
 
 void parse_vm_instr_write_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result);
+void parse_vm_instr_write_mask_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result);
+
 );