hltapi : add dst_mac vm; vlan mask variable now can be shared; add 2 more profiles...
authorYaroslav Brustinov <[email protected]>
Wed, 24 Feb 2016 19:07:11 +0000 (14:07 -0500)
committerYaroslav Brustinov <[email protected]>
Wed, 24 Feb 2016 19:07:11 +0000 (14:07 -0500)
15 files changed:
scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py
scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
scripts/exp/hlt_david4.pcap
scripts/exp/hlt_udp_ports.pcap [new file with mode: 0644]
scripts/exp/hlt_udp_random_ports.pcap [new file with mode: 0644]
scripts/stl/hlt/hlt_david1.py
scripts/stl/hlt/hlt_david2.py
scripts/stl/hlt/hlt_david3.py
scripts/stl/hlt/hlt_david4.py
scripts/stl/hlt/hlt_imix_4rates.py
scripts/stl/hlt/hlt_tcp_ranges.py
scripts/stl/hlt/hlt_udp_inc_dec_len_9k.py
scripts/stl/hlt/hlt_udp_ports.py [new file with mode: 0755]
scripts/stl/hlt/hlt_udp_random_ports.py [new file with mode: 0755]

index 54daa12..7b501d9 100755 (executable)
@@ -475,34 +475,34 @@ TBD
     self_start: true
     vm:
       instructions:
-      - init_value: 1
-        max_value: 7
-        min_value: 1
-        name: vlan_id0
+      - init_value: 0
+        max_value: 6
+        min_value: 0
+        name: dec_2_3_2
         op: inc
         size: 2
         step: 2
         type: flow_var
-      - add_value: 0
+      - add_value: 1
         is_big_endian: true
         mask: 4095
-        name: vlan_id0
+        name: dec_2_3_2
         pkt_cast_size: 2
         pkt_offset: 14
         shift: 0
         type: write_mask_flow_var
-      - init_value: 1000
-        max_value: 1000
-        min_value: 991
-        name: vlan_id2
+      - init_value: 9
+        max_value: 9
+        min_value: 0
+        name: dec_2_9_1
         op: dec
         size: 2
         step: 1
         type: flow_var
-      - add_value: 0
+      - add_value: 991
         is_big_endian: true
         mask: 4095
-        name: vlan_id2
+        name: dec_2_9_1
         pkt_cast_size: 2
         pkt_offset: 22
         shift: 0
@@ -510,7 +510,7 @@ TBD
       - init_value: 0
         max_value: 65535
         min_value: 0
-        name: vlan_id3
+        name: vlan_id_random
         op: random
         size: 2
         step: 1
@@ -518,12 +518,12 @@ TBD
       - add_value: 0
         is_big_endian: true
         mask: 4095
-        name: vlan_id3
+        name: vlan_id_random
         pkt_cast_size: 2
         pkt_offset: 26
         shift: 0
         type: write_mask_flow_var
-      split_by_var: vlan_id2
+      split_by_var: dec_2_9_1
 '''
 
 
@@ -621,7 +621,7 @@ TBD
 
 
     def yaml_save_location(self):
-        return os.devnull
+        #return os.devnull
         # debug/deveopment, comment line above
         return '/tmp/%s.yaml' % self._testMethodName
 
index 22a63dd..5ae890b 100644 (file)
@@ -207,6 +207,8 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
             ['hlt/hlt_david3.py', '-m 1 -l 20', True],
             ['hlt/hlt_david4.py', '-m 1 -l 20', True],
             ['hlt/hlt_tcp_ranges.py', '-m 1 -l 20', True],
+            ['hlt/hlt_udp_ports.py', '-m 1 -l 20', True],
+            ['hlt/hlt_udp_random_ports.py', '-m 1 -l 20', True],
             )
 
         for obj in p:
index 593c4c4..2e5d141 100755 (executable)
@@ -3,7 +3,7 @@
 '''
 Supported functions/arguments/defaults:
 '''
-# connect()
+
 connect_kwargs = {
     'device': 'localhost',                  # ip or hostname of TRex
     'port_list': None,                      # list of ports
@@ -12,17 +12,16 @@ connect_kwargs = {
     'break_locks': False,
 }
 
-# cleanup_session()
 cleanup_session_kwargs = {
     'maintain_lock': False,                 # release ports at the end or not
     'port_list': None,
     'port_handle': None,
 }
 
-# traffic_config()
 traffic_config_kwargs = {
     'mode': None,                           # ( create | modify | remove | reset )
     'split_by_cores': 'split',              # ( split | duplicate | single ) TRex extention: split = split traffic by cores, duplicate = duplicate traffic for all cores, single = run only with sinle core (not implemented yet)
+    'consistent_random': False,             # TRex extention: False (default): random sequence will be different every run, True: random sequence will be same every run
     'port_handle': None,
     'port_handle2': None,
     # stream builder parameters
@@ -37,7 +36,7 @@ traffic_config_kwargs = {
     'pkts_per_burst': 1,
     'burst_loop_count': 1,
     'inter_burst_gap': 12,
-    'length_mode': 'fixed',                 #  ( auto | fixed | increment | decrement | random | imix )
+    'length_mode': 'fixed',                 # ( auto | fixed | increment | decrement | random | imix )
     'l3_imix1_size': 60,
     'l3_imix1_ratio': 28,
     'l3_imix2_size': 590,
@@ -156,13 +155,11 @@ traffic_config_kwargs = {
     'udp_dst_port_count': 1,
 }
 
-# traffic_control()
 traffic_control_kwargs = {
     'action': None,                         # ( run | stop )
     'port_handle': None
 }
 
-# traffic_stats()
 traffic_stats_kwargs = {
     'mode': 'aggregate',                    # ( aggregate )
     'port_handle': None
@@ -712,7 +709,6 @@ def STLHltStream(**user_kwargs):
     # packet generation
     packet = generate_packet(**user_kwargs)
     try:
-        # TODO: verify if bps is L1 or L2, use L2 for now
         rate_types_dict = {'rate_pps': 'pps', 'rate_bps': 'bps_L2', 'rate_percent': 'percentage'}
         rate_stateless = {rate_types_dict[rate_key]: float(kwargs[rate_key])}
         transmit_mode = kwargs['transmit_mode']
@@ -732,12 +728,13 @@ def STLHltStream(**user_kwargs):
     # stream generation
     try:
         stream = STLStream(packet = packet,
+                           random_seed = 1 if kwargs['consistent_random'] else 0,
                            #enabled = True,
                            #self_start = True,
                            mode = transmit_mode_class,
                            #rx_stats = rx_stats,
-                           stream_id = kwargs.get('stream_id'),
-                           name = kwargs.get('name'),
+                           stream_id = kwargs['stream_id'],
+                           name = kwargs['name'],
                            )
     except Exception as e:
         raise STLError('Could not create stream: %s' % e if isinstance(e, STLError) else traceback.format_exc())
@@ -770,7 +767,7 @@ def generate_packet(**user_kwargs):
             count = int(kwargs['mac_src_count']) - 1
             if count < 0:
                 raise STLError('mac_src_count has to be at least 1')
-            if count > 0:
+            if count > 0 or kwargs['mac_src_mode'] == 'random':
                 mac_src = mac_str_to_num(mac2str(kwargs['mac_src']))
                 step = kwargs['mac_src_step']
                 if step < 1:
@@ -794,11 +791,44 @@ def generate_packet(**user_kwargs):
                         vm_variables_cache[var_name] = True
                 elif kwargs['mac_src_mode'] == 'random':
                     var_name = 'mac_src_random'
-                    vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffffffff))
+                    vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff))
                 else:
                     raise STLError('mac_src_mode %s is not supported' % kwargs['mac_src_mode'])
                 vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'Ethernet.src', offset_fixup = 2, add_val = add_val))
-        
+
+        if kwargs['mac_dst_mode'] != 'fixed':
+            count = int(kwargs['mac_dst_count']) - 1
+            if count < 0:
+                raise STLError('mac_dst_count has to be at least 1')
+            if count > 0 or kwargs['mac_dst_mode'] == 'random':
+                mac_dst = mac_str_to_num(mac2str(kwargs['mac_dst']))
+                step = kwargs['mac_dst_step']
+                if step < 1:
+                    raise STLError('mac_dst_step has to be at least 1')
+                if type(step) is str:
+                    step = mac_str_to_num(mac2str(step))
+                add_val = 0
+                if kwargs['mac_dst_mode'] == 'increment':
+                    add_val = mac_dst
+                    var_name = '%s_%s_%s_%s' % ('inc', 4, count, step)
+                    if var_name not in vm_variables_cache:
+                        vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'inc', step = step,
+                                                          max_value = count * step))
+                        vm_variables_cache[var_name] = True
+                elif kwargs['mac_dst_mode'] == 'decrement':
+                    add_val = mac_dst - count * step
+                    var_name = '%s_%s_%s_%s' % ('dec', 4, count, step)
+                    if var_name not in vm_variables_cache:
+                        vm_cmds.append(CTRexVmDescFlowVar(name = 'mac_dst', size = 4, op = 'dec', step = step,
+                                                          max_value = count * step))
+                        vm_variables_cache[var_name] = True
+                elif kwargs['mac_dst_mode'] == 'random':
+                    var_name = 'mac_dst_random'
+                    vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 4, op = 'random', max_value = 0xffffffff))
+                else:
+                    raise STLError('mac_dst_mode %s is not supported' % kwargs['mac_dst_mode'])
+                vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'Ethernet.dst', offset_fixup = 2, add_val = add_val))
+
         if kwargs['l2_encap'] == 'ethernet_ii_vlan' or (kwargs['l2_encap'] == 'ethernet_ii' and vlan_in_args(user_kwargs)):
                 #fields_desc =  [ BitField("prio", 0, 3),
                 #                 BitField("id", 0, 1),
@@ -823,25 +853,32 @@ def generate_packet(**user_kwargs):
                     if count < 0:
                         raise STLError('vlan_id_count has to be at least 1')
                     if count > 0 or vlan_id_mode == 'random':
+                        add_val = 0
                         var_name = 'vlan_id%s' % i
                         step = int(vlan_kwargs['vlan_id_step'])
                         if step < 1:
                             raise STLError('vlan_id_step has to be at least 1')
                         if vlan_id_mode == 'increment':
-                            vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step,
-                                                              min_value = vlan_id,
-                                                              max_value = vlan_id + count * step))
+                            add_val = vlan_id
+                            var_name = '%s_%s_%s_%s' % ('dec', 2, count, step)
+                            if var_name not in vm_variables_cache:
+                                vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'inc', step = step,
+                                                                  max_value = count * step))
+                                vm_variables_cache[var_name] = True
                         elif vlan_id_mode == 'decrement':
-                            vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'dec', step = step,
-                                                               min_value = vlan_id - count * step,
-                                                               max_value = vlan_id))
+                            add_val = vlan_id - count * step
+                            var_name = '%s_%s_%s_%s' % ('dec', 2, count, step)
+                            if var_name not in vm_variables_cache:
+                                vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'dec', step = step,
+                                                                  max_value = count * step))
+                                vm_variables_cache[var_name] = True
                         elif vlan_id_mode == 'random':
+                            var_name = 'vlan_id_random'
                             vm_cmds.append(CTRexVmDescFlowVar(name = var_name, size = 2, op = 'random', min_value = 0, max_value = 0xffff))
                         else:
                             raise STLError('vlan_id_mode %s is not supported' % vlan_id_mode)
                         vm_cmds.append(STLVmWrMaskFlowVar(fv_name = var_name, pkt_offset = '802|1Q:%s.vlan' % i,
-                                                          pkt_cast_size = 2, mask = 0xfff))
-
+                                                          pkt_cast_size = 2, mask = 0xfff, add_value = add_val))
     else:
         raise NotImplementedError("l2_encap does not support the desired encapsulation '%s'" % kwargs['l2_encap'])
     base_pkt = l2_layer
@@ -878,7 +915,7 @@ def generate_packet(**user_kwargs):
             count = int(kwargs['ip_src_count']) - 1
             if count < 0:
                 raise STLError('ip_src_count has to be at least 1')
-            if count > 0:
+            if count > 0 or kwargs['ip_src_mode'] == 'random':
                 fix_ipv4_checksum = True
                 add_val = 0
                 ip_src_addr = kwargs['ip_src_addr']
@@ -914,7 +951,7 @@ def generate_packet(**user_kwargs):
             count = int(kwargs['ip_dst_count']) - 1
             if count < 0:
                 raise STLError('ip_dst_count has to be at least 1')
-            if count > 0:
+            if count > 0 or kwargs['ip_dst_mode'] == 'random':
                 fix_ipv4_checksum = True
                 add_val = 0
                 ip_dst_addr = kwargs['ip_dst_addr']
@@ -971,7 +1008,7 @@ def generate_packet(**user_kwargs):
             count = int(kwargs['ipv6_src_count']) - 1
             if count < 0:
                 raise STLError('ipv6_src_count has to be at least 1')
-            if count > 0:
+            if count > 0 or kwargs['ipv6_src_mode'] == 'random':
                 add_val = 0
                 ipv6_src_addr_num = ipv4_str_to_num(is_valid_ipv6(kwargs['ipv6_src_addr'])[-4:])
                 step = kwargs['ipv6_src_step']
@@ -1004,7 +1041,7 @@ def generate_packet(**user_kwargs):
             count = int(kwargs['ipv6_dst_count']) - 1
             if count < 0:
                 raise STLError('ipv6_dst_count has to be at least 1')
-            if count > 0:
+            if count > 0 or kwargs['ipv6_dst_mode'] == 'random':
                 add_val = 0
                 ipv6_dst_addr_num = ipv4_str_to_num(is_valid_ipv6(kwargs['ipv6_dst_addr'])[-4:])
                 step = kwargs['ipv6_dst_step']
@@ -1072,7 +1109,7 @@ def generate_packet(**user_kwargs):
             count = int(kwargs['tcp_src_port_count']) - 1
             if count < 0:
                 raise STLError('tcp_src_port_count has to be at least 1')
-            if count > 0:
+            if count > 0 or kwargs['tcp_src_port_mode'] == 'random':
                 fix_ipv4_checksum = True
                 add_val = 0
                 step = kwargs['tcp_src_port_step']
@@ -1103,7 +1140,7 @@ def generate_packet(**user_kwargs):
             count = int(kwargs['tcp_dst_port_count']) - 1
             if count < 0:
                 raise STLError('tcp_dst_port_count has to be at least 1')
-            if count > 0:
+            if count > 0 or kwargs['tcp_dst_port_mode'] == 'random':
                 fix_ipv4_checksum = True
                 add_val = 0
                 step = kwargs['tcp_dst_port_step']
@@ -1143,7 +1180,7 @@ def generate_packet(**user_kwargs):
             count = int(kwargs['udp_src_port_count']) - 1
             if count < 0:
                 raise STLError('udp_src_port_count has to be at least 1')
-            if count > 0:
+            if count > 0 or kwargs['udp_src_port_mode'] == 'random':
                 fix_ipv4_checksum = True
                 add_val = 0
                 step = kwargs['udp_src_port_step']
@@ -1174,7 +1211,7 @@ def generate_packet(**user_kwargs):
             count = int(kwargs['udp_dst_port_count']) - 1
             if count < 0:
                 raise STLError('udp_dst_port_count has to be at least 1')
-            if count > 0:
+            if count > 0 or kwargs['udp_dst_port_mode'] == 'random':
                 fix_ipv4_checksum = True
                 add_val = 0
                 step = kwargs['udp_dst_port_step']
index a28d8ab..520675c 100644 (file)
Binary files a/scripts/exp/hlt_david4.pcap and b/scripts/exp/hlt_david4.pcap differ
diff --git a/scripts/exp/hlt_udp_ports.pcap b/scripts/exp/hlt_udp_ports.pcap
new file mode 100644 (file)
index 0000000..91905f3
Binary files /dev/null and b/scripts/exp/hlt_udp_ports.pcap differ
diff --git a/scripts/exp/hlt_udp_random_ports.pcap b/scripts/exp/hlt_udp_random_ports.pcap
new file mode 100644 (file)
index 0000000..86c0946
Binary files /dev/null and b/scripts/exp/hlt_udp_random_ports.pcap differ
index 922bb63..73d258e 100755 (executable)
@@ -2,6 +2,10 @@ from trex_stl_lib.trex_stl_hltapi import STLHltStream
 
 
 class STLS1(object):
+    '''
+    Example number 1 of using HLTAPI from David
+    Creates 3 streams (imix) Eth/802.1Q/IP/TCP without VM
+    '''
 
     def create_streams (self, direction = 0):
         return STLHltStream(
index be21c93..d3e669a 100755 (executable)
@@ -2,6 +2,10 @@ from trex_stl_lib.trex_stl_hltapi import STLHltStream
 
 
 class STLS1(object):
+    '''
+    Example number 2 of using HLTAPI from David
+    Creates 3 streams (imix) Eth/802.1Q/IP/TCP without VM
+    '''
 
     def create_streams (self, direction = 0):
         return STLHltStream(
index af41b3d..2144570 100755 (executable)
@@ -2,6 +2,10 @@ from trex_stl_lib.trex_stl_hltapi import STLHltStream
 
 
 class STLS1(object):
+    '''
+    Example number 3 of using HLTAPI from David
+    Creates Eth/802.1Q/802.1Q/IP/TCP stream
+    '''
 
     def create_streams (self, direction = 0):
         return STLHltStream(
index 9624c0b..1019a15 100755 (executable)
@@ -2,6 +2,13 @@ from trex_stl_lib.trex_stl_hltapi import STLHltStream
 
 
 class STLS1(object):
+    '''
+    Example number 3 of using HLTAPI from David
+    Creates Eth/802.1Q/802.1Q/IP/TCP stream with complex VM:
+        The first vlan_id will be incremented, second const.
+        MAC src, IP src, IP dst will have <mac_src_count> number of incremental values
+        MAC dst will have <mac_dst_count> number of incremental values
+    '''
 
     def create_streams (self, direction = 0):
         mac_dst_count = 10
@@ -11,7 +18,7 @@ class STLS1(object):
         intf_traffic_src_ip = '16.0.0.1'
 
         return STLHltStream(
-                #enable_auto_detect_instrumentation = 1, # not supported
+                #enable_auto_detect_instrumentation = 1, # not supported yet
                 ip_dst_addr = intf_traffic_dst_ip,
                 ip_dst_count = mac_src_count,
                 ip_dst_mode = 'increment',
@@ -22,7 +29,7 @@ class STLS1(object):
                 ip_src_step = '0.0.1.0',
                 l3_protocol = 'ipv4',
                 mac_dst_count = mac_dst_count,
-                #mac_dst_mode = 'discovery', # not supported
+                #mac_dst_mode = 'discovery', # not supported yet
                 mac_dst_mode = 'increment',
                 mac_dst_step = 1,
                 mac_src_count = mac_src_count,
index 653c387..f6bfdd3 100755 (executable)
@@ -2,6 +2,10 @@ from trex_stl_lib.trex_stl_hltapi import STLHltStream
 
 
 class STLS1(object):
+    '''
+    Creating 4 streams Eth/IP/UDP with different size and rate (smallest with highest rate)
+    Each stream will get rate_pps * his ratio / sum of ratios
+    '''
 
     def create_streams (self, direction = 0):
         return STLHltStream(length_mode = 'imix', rate_pps = 2,
index b720e1e..28e6685 100755 (executable)
@@ -2,6 +2,9 @@ from trex_stl_lib.trex_stl_hltapi import STLHltStream
 
 
 class STLS1(object):
+    '''
+    Eth/IP/TCP stream with VM to get 10 different TCP ports
+    '''
 
     def create_streams (self, direction = 0):
         return [STLHltStream(tcp_src_port_mode = 'decrement',
index e8766da..b3fec98 100755 (executable)
@@ -2,10 +2,16 @@ from trex_stl_lib.trex_stl_hltapi import STLHltStream
 
 
 class STLS1(object):
+    '''
+    Create 2 Eth/IP/UDP steams with different packet size:
+    First stream will start from 64 bytes (default) and will increase until max_size (9,216)
+    Seconds stream will decrease the packet size in reverse way
+    '''
 
     def create_streams (self):
+        max_size = 9*1024
         return [STLHltStream(length_mode = 'increment',
-                             frame_size_max = 9*1024,
+                             frame_size_max = max_size,
                              ip_src_addr = '16.0.0.1',
                              ip_dst_addr = '48.0.0.1',
                              l4_protocol = 'udp',
@@ -14,7 +20,7 @@ class STLS1(object):
                              rate_pps = 1,
                              ),
                 STLHltStream(length_mode = 'decrement',
-                             frame_size_max = 9*1024,
+                             frame_size_max = max_size,
                              ip_src_addr = '16.0.0.1',
                              ip_dst_addr = '48.0.0.1',
                              l4_protocol = 'udp',
diff --git a/scripts/stl/hlt/hlt_udp_ports.py b/scripts/stl/hlt/hlt_udp_ports.py
new file mode 100755 (executable)
index 0000000..2086214
--- /dev/null
@@ -0,0 +1,33 @@
+from trex_stl_lib.trex_stl_hltapi import STLHltStream
+
+
+class STLS1(object):
+    '''
+    Eth/IP/UDP stream with VM for different UDP ports inc/dec
+    The ports overlap the max and min at very first packets
+    '''
+
+    def create_streams (self, direction = 0):
+        return [STLHltStream(l4_protocol = 'udp',
+                             udp_src_port_mode = 'decrement',
+                             udp_src_port_count = 45,
+                             udp_src_port_step = 20,
+                             udp_src_port = 123,
+                             udp_dst_port_mode = 'increment',
+                             udp_dst_port_count = 100,
+                             udp_dst_port_step = 300,
+                             udp_dst_port = 65000,
+                             direction = direction,
+                             rate_pps = 1000,
+                             ),
+               ]
+
+    def get_streams (self, direction = 0):
+        return self.create_streams(direction)
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+
diff --git a/scripts/stl/hlt/hlt_udp_random_ports.py b/scripts/stl/hlt/hlt_udp_random_ports.py
new file mode 100755 (executable)
index 0000000..0f60958
--- /dev/null
@@ -0,0 +1,28 @@
+from trex_stl_lib.trex_stl_hltapi import STLHltStream
+
+
+class STLS1(object):
+    '''
+    Eth/IP/UDP stream with VM for random UDP ports inc/dec.
+    Using "consistent_random = True" to have same random ports each test
+    '''
+
+    def create_streams (self, direction = 0):
+        return [STLHltStream(l4_protocol = 'udp',
+                             udp_src_port_mode = 'random',
+                             udp_dst_port_mode = 'random',
+                             direction = direction,
+                             rate_pps = 1000,
+                             consistent_random = True,
+                             ),
+               ]
+
+    def get_streams (self, direction = 0):
+        return self.create_streams(direction)
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+