Splitter - padding for non circular VMs
authorimarom <[email protected]>
Wed, 21 Sep 2016 15:12:46 +0000 (18:12 +0300)
committerimarom <[email protected]>
Sun, 25 Sep 2016 12:08:06 +0000 (15:08 +0300)
scripts/automation/regression/functional_tests/stl_basic_tests.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py
scripts/exp/imix_3pkt_vm.pcap
scripts/exp/udp_1pkt_range_clients_split.pcap
scripts/exp/udp_1pkt_src_ip_split.pcap
scripts/exp/udp_1pkt_tuple_gen_split.pcap
scripts/stl/tests/multi_core_test.py
src/rpc-server/commands/trex_rpc_cmd_stream.cpp
src/rpc-server/commands/trex_rpc_cmds.h

index e9409ba..2817832 100644 (file)
@@ -253,12 +253,12 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
              ["udp_3pkt_pcap.py","-m 1 -l 10",True, False],
              #["udp_1pkt_simple.py","-m 1 -l 3",True],
              ["udp_1pkt_pcap_relative_path.py","-m 1 -l 3",True, False],
-             ["udp_1pkt_tuple_gen_split.py","-m 1 -c 2 -l 100",True],
-             ["udp_1pkt_range_clients_split.py","-m 1 -c 2 -l 100",True],
-             ["udp_1pkt_vxlan.py","-m 1 -c 1 -l 17",True, False], # can't generate: no VXLAN in Scapy, only in profile
-             ["udp_1pkt_ipv6_in_ipv4.py","-m 1 -c 1 -l 17",True],
-             ["yaml/imix_3pkt.yaml","-m 50kpps --limit 20 --cores 2",True],
-             ["yaml/imix_3pkt_vm.yaml","-m 50kpps --limit 20 --cores 2",True],
+             ["udp_1pkt_tuple_gen_split.py","-m 1 -l 100",True],
+             ["udp_1pkt_range_clients_split.py","-m 1 -l 100",True],
+             ["udp_1pkt_vxlan.py","-m 1 -l 17",True, False], # can't generate: no VXLAN in Scapy, only in profile
+             ["udp_1pkt_ipv6_in_ipv4.py","-m 1 -l 17",True],
+             ["yaml/imix_3pkt.yaml","-m 50kpps --limit 20",True],
+             ["yaml/imix_3pkt_vm.yaml","-m 50kpps --limit 20",True],
              ["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],
@@ -271,13 +271,12 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
              ["udp_1pkt_simple_test.py","-m 1 -l 10 ",True, False],
              ["udp_1pkt_mac_mask5.py","-m 1 -l 30 ",True],
              ["udp_1pkt_range_clients_split_garp.py","-m 1 -l 50",True],
-             ["udp_1pkt_src_ip_split.py","-m 1 -l 50 --cores 2",True],
+             ["udp_1pkt_src_ip_split.py","-m 1 -l 50",True],
              ["udp_1pkt_repeat_random.py","-m 1 -l 50",True],
           ];
 
         p1 = [ ["udp_1pkt_repeat_random.py","-m 1 -l 50",True] ];
 
-
         for obj in p:
             try:
                 test_generated = obj[3]
@@ -337,13 +336,29 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
 
 
     def test_multicore_scheduling (self):
-        mc_tests = ['stl/tests/single_cont.py',
+        
+        seed = time.time()
+
+        # test with simple vars
+        rc = self.run_sim('stl/tests/multi_core_test.py', output = None, options = '--test_multi_core --limit=840 -t test_type=plain#seed={0} -m 27kpps'.format(seed), silent = True)
+        assert_equal(rc, True)
+
+
+        # test with tuple
+        rc = self.run_sim('stl/tests/multi_core_test.py', output = None, options = '--test_multi_core --limit=840 -t test_type=tuple#seed={0} -m 27kpps'.format(seed), silent = True)
+        assert_equal(rc, True)
+
+        # some tests
+        mc_tests = [
+                    'stl/tests/single_cont.py',
                     'stl/tests/single_burst.py',
                     'stl/tests/multi_burst.py',
-                    'stl/tests/many_streams.py',
                    ]
 
         for mc_test in mc_tests:
-            rc = self.run_sim(mc_test, output = None, options = '--test_multi_core --limit=3840 -m 27kpps', silent = True)
+            rc = self.run_sim(mc_test, output = None, options = '--test_multi_core --limit=840 -m 27kpps', silent = True)
             assert_equal(rc, True)
 
+        return
+
+
index 0394cf4..63a1232 100644 (file)
@@ -111,8 +111,6 @@ class STLSim(object):
         # handle YAMLs
         if tunables == None:
             tunables = {}
-        else:
-            tunables = tunables[0]
 
         for input_file in input_files:
             try:
@@ -556,7 +554,7 @@ def test_multi_core (r, options):
               duration = options.duration,
               mode = 'none',
               silent = True,
-              tunables = [{'seed': 5}])
+              tunables = options.tunables)
 
     print("")
 
index e1de6b5..65333e0 100755 (executable)
@@ -213,19 +213,25 @@ def is_valid_file(filename):
     return filename
 
 
-def decode_tunables_to_dict (**kwargs):
-    return kwargs
 
 def decode_tunables (tunable_str):
-    try:
-        tunables = [eval('decode_tunables_to_dict({0})'.format(t)) for t in tunable_str.split('#')]
+    tunables = {}
 
-    except (SyntaxError, NameError):
-        raise argparse.ArgumentTypeError("bad syntax for tunables: {0}".format(tunable_str))
+    # split by diaz to tokens
+    tokens = tunable_str.split('#')
+
+    # each token is of form X=Y
+    for token in tokens:
+        print(token)
+        m = re.search('(.*)=(.*)', token)
+        if not m:
+            raise argparse.ArgumentTypeError("bad syntax for tunables: {0}".format(token))
+        tunables[m.group(1)] = m.group(2)
 
     return tunables
 
 
+
 OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'],
                                  {'help': match_multiplier_help,
                                   'dest': "mult",
index 4a97280..de78d57 100644 (file)
Binary files a/scripts/exp/imix_3pkt_vm.pcap and b/scripts/exp/imix_3pkt_vm.pcap differ
index fb5037c..203de6e 100644 (file)
Binary files a/scripts/exp/udp_1pkt_range_clients_split.pcap and b/scripts/exp/udp_1pkt_range_clients_split.pcap differ
index 08ba764..af254c4 100644 (file)
Binary files a/scripts/exp/udp_1pkt_src_ip_split.pcap and b/scripts/exp/udp_1pkt_src_ip_split.pcap differ
index 873ab47..2b7c797 100644 (file)
Binary files a/scripts/exp/udp_1pkt_tuple_gen_split.pcap and b/scripts/exp/udp_1pkt_tuple_gen_split.pcap differ
index 17896b5..918a30b 100644 (file)
@@ -24,7 +24,7 @@ class STLMultiCore(object):
                          mode = STLTXCont(pps = pps))
 
 
-    def generate_var (self, rng, i, vm, pkt_offset):
+    def generate_var (self, rng, i, vm, pkt_offset, verbose = False):
 
         name = "var-{0}".format(i)
 
@@ -36,7 +36,7 @@ class STLMultiCore(object):
         step      = rng.randint(1, 1000)
         op        = rng.choice(['inc', 'dec'])
         
-        vm += [STLVmFlowVar(name      = str(i),
+        vm += [STLVmFlowVar(name      = name,
                             min_value = min_value,
                             max_value = max_value,
                             size      = size,
@@ -44,17 +44,18 @@ class STLMultiCore(object):
                STLVmWrFlowVar(fv_name = name, pkt_offset = pkt_offset),
                ]
 
-        print('name: {:}, start: {:}, end: {:}, size: {:}, op: {:}, step {:}'.format(name,
-                                                                                     min_value,
-                                                                                     max_value,
-                                                                                     size,
-                                                                                     op,
-                                                                                     step))
+        if verbose:
+            print('name: {:}, start: {:}, end: {:}, size: {:}, op: {:}, step {:}'.format(name,
+                                                                                         min_value,
+                                                                                         max_value,
+                                                                                         size,
+                                                                                         op,
+                                                                                         step))
 
         return size
 
 
-    def generate_tuple_var (self, rng, i, vm, pkt_offset):
+    def generate_tuple_var (self, rng, i, vm, pkt_offset, verbose = False):
         name = "tuple-{0}".format(i)
 
         # ip
@@ -74,11 +75,12 @@ class STLMultiCore(object):
                STLVmWrFlowVar (fv_name = name + ".port", pkt_offset = (pkt_offset + 4) ),
                ]
 
-        print('name: {:}, ip_start: {:}, ip_end: {:}, port_start: {:}, port_end: {:}'.format(name,
-                                                                                             ip_min,
-                                                                                             ip_max,
-                                                                                             port_min,
-                                                                                             port_max))
+        if verbose:
+            print('name: {:}, ip_start: {:}, ip_end: {:}, port_start: {:}, port_end: {:}'.format(name,
+                                                                                                 ip_min,
+                                                                                                 ip_max,
+                                                                                                 port_min,
+                                                                                                 port_max))
 
         return 8
         
@@ -88,27 +90,23 @@ class STLMultiCore(object):
     def get_streams (self, direction = 0, **kwargs):
       
         rng = random.Random(kwargs.get('seed', 1))
+        test_type = kwargs.get('test_type', 'plain')
 
-        var_type = kwargs.get('var_type', 'plain')
-
-
-        var_type = 'tuple'
-        vm = []
         # base offset
         pkt_offset = 42
-        print("\nusing the following vars:\n")
 
-        if var_type == 'plain':
+        vm = []
+
+        if test_type == 'plain':
             for i in range(20):
                 pkt_offset += self.generate_var(rng, i, vm, pkt_offset)
-        else:
+        elif test_type == 'tuple':
             for i in range(5):
                 pkt_offset += self.generate_tuple_var(rng, i, vm, pkt_offset)
+        else:
+            raise STLError('unknown mutli core test type')
 
 
-
-
-        print("\n")
         # create imix streams
         return [self.create_stream(x['size'], x['pps'],x['isg'] , vm) for x in self.streams_def]
 
index e5072b9..becd51c 100644 (file)
@@ -252,6 +252,51 @@ TrexRpcCmdAddStream::parse_vm_instr_tuple_flow_var(const Json::Value &inst, std:
 }
 
 
+/**
+ * if a user specify min_value and max_value with a step 
+ * that does not create a full cycle - pad the values to allow 
+ * a true cycle 
+ * 
+ */
+void
+TrexRpcCmdAddStream::handle_range_padding(uint64_t &max_value,
+                                          uint64_t &min_value,
+                                          uint64_t step,
+                                          int op,
+                                          Json::Value &result) {
+
+    /* pad for the step */
+    uint64_t pad = (max_value - min_value + 1) % step; 
+    if (pad == 0) {
+        return;
+    }
+
+    /* the leftover rounded up */
+    uint64_t step_pad = step - pad;
+
+    switch (op) {
+    case StreamVmInstructionFlowMan::FLOW_VAR_OP_INC:
+
+        if ( (UINT64_MAX - max_value) < step_pad ) {
+            generate_parse_err(result, "VM: could not pad range to be a true cycle - '(max_value - min_value + 1) % step' should be zero");
+        }
+        max_value += step_pad;
+
+        break;
+
+    case StreamVmInstructionFlowMan::FLOW_VAR_OP_DEC:
+        if ( min_value < step_pad ) {
+            generate_parse_err(result, "VM: could not pad range to be a true cycle - '(max_value - min_value + 1) % step' should be zero");
+        }
+        min_value -= step_pad;
+
+        break;
+
+    default:
+        break;
+    }
+}
+
 void 
 TrexRpcCmdAddStream::check_min_max(uint8_t flow_var_size, 
                                    uint64_t init_value,
index c987f32..506bd2c 100644 (file)
@@ -114,6 +114,7 @@ void parse_vm_instr_trim_pkt_size(const Json::Value &inst, std::unique_ptr<TrexS
 void parse_rate(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result);
 void parse_vm_instr_write_flow_var(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result);
 void parse_vm_instr_write_mask_flow_var(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result);
+void handle_range_padding(uint64_t &max_value, uint64_t &min_value, uint64_t step, int op, Json::Value &result);
 
 );