hltapi: remove default for l3_protocol and l4_protocol, add several profiles
authorYaroslav Brustinov <[email protected]>
Sun, 28 Feb 2016 16:04:50 +0000 (18:04 +0200)
committerYaroslav Brustinov <[email protected]>
Sun, 28 Feb 2016 16:04:50 +0000 (18:04 +0200)
27 files changed:
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_4vlans.pcap [new file with mode: 0644]
scripts/exp/hlt_david1.pcap
scripts/exp/hlt_david2.pcap
scripts/exp/hlt_david3.pcap
scripts/exp/hlt_david4.pcap
scripts/exp/hlt_framesize_vm.pcap [new file with mode: 0644]
scripts/exp/hlt_ipv6_default.pcap [new file with mode: 0644]
scripts/exp/hlt_ipv6_ranges.pcap [new file with mode: 0644]
scripts/exp/hlt_l3_length_vm.pcap [new file with mode: 0644]
scripts/exp/hlt_vlan_default.pcap [new file with mode: 0644]
scripts/exp/hlt_vlans_vm.pcap [new file with mode: 0644]
scripts/stl/hlt/hlt_4vlans.py [new file with mode: 0755]
scripts/stl/hlt/hlt_framesize_vm.py [new file with mode: 0755]
scripts/stl/hlt/hlt_imix_4rates.py
scripts/stl/hlt/hlt_imix_default.py
scripts/stl/hlt/hlt_ip_ranges.py [new file with mode: 0755]
scripts/stl/hlt/hlt_ipv6_default.py [new file with mode: 0755]
scripts/stl/hlt/hlt_ipv6_ranges.py [new file with mode: 0755]
scripts/stl/hlt/hlt_l3_length_vm.py [new file with mode: 0755]
scripts/stl/hlt/hlt_tcp_ranges.py
scripts/stl/hlt/hlt_udp_inc_dec_len_9k.py
scripts/stl/hlt/hlt_udp_ports.py
scripts/stl/hlt/hlt_udp_random_ports.py
scripts/stl/hlt/hlt_vlan_default.py [new file with mode: 0755]
scripts/stl/hlt/hlt_vlans_vm.py [new file with mode: 0755]

index bca44cb..e31ef59 100644 (file)
@@ -212,6 +212,14 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test):
             ['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],
+            #['hlt/hlt_ip_ranges.py', '-m 1 -l 20', True], # can't run now, random on full range issue
+            ['hlt/hlt_framesize_vm.py', '-m 1 -l 20', True],
+            ['hlt/hlt_l3_length_vm.py', '-m 1 -l 20', True],
+            ['hlt/hlt_vlan_default.py', '-m 1 -l 20', True],
+            ['hlt/hlt_4vlans.py', '-m 1 -l 20', True],
+            ['hlt/hlt_vlans_vm.py', '-m 1 -l 20', True],
+            ['hlt/hlt_ipv6_default.py', '-m 1 -l 20', True],
+            ['hlt/hlt_ipv6_ranges.py', '-m 1 -l 20', True],
             )
 
         for obj in p:
index 7bd4333..3fad0bf 100755 (executable)
@@ -79,7 +79,7 @@ traffic_config_kwargs = {
     'vlan_cfi': 1,
     'vlan_protocol_tag_id': None,
     #L3, general
-    'l3_protocol': 'ipv4',                  # ( ipv4 | ipv6 )
+    'l3_protocol': None,                  # ( ipv4 | ipv6 )
     'l3_length_min': 110,
     'l3_length_max': 238,
     'l3_length_step': 1,
@@ -122,7 +122,7 @@ traffic_config_kwargs = {
     'ipv6_dst_step': 1,                     # we are changing only 32 lowest bits; can be ipv6 or number
     'ipv6_dst_count': 1,
     #L4, TCP
-    'l4_protocol': 'tcp',                   # ( tcp | udp )
+    'l4_protocol': None,                   # ( tcp | udp )
     'tcp_src_port': 1024,
     'tcp_dst_port': 80,
     'tcp_seq_num': 1,
@@ -673,6 +673,8 @@ def STLHltStream(**user_kwargs):
         rate_key = intersect_rate_args[0]
     except IndexError:
         rate_key = 'rate_percent'
+    if rate_key is 'rate_percent' and float(kwargs['rate_percent']) > 100:
+        raise STLError('rate_percent should not exceed 100%')
 
     if kwargs['length_mode'] == 'imix': # several streams with given length
         streams_arr = []
@@ -732,7 +734,7 @@ def STLHltStream(**user_kwargs):
     # stream generation
     try:
         stream = STLStream(packet = packet,
-                           random_seed = 1 if kwargs['consistent_random'] else 0,
+                           random_seed = 1 if is_true(kwargs['consistent_random']) else 0,
                            #enabled = True,
                            #self_start = True,
                            mode = transmit_mode_class,
@@ -894,7 +896,9 @@ def generate_packet(**user_kwargs):
     base_pkt = l2_layer
 
     ### L3 ###
-    if kwargs['l3_protocol'] == 'ipv4':
+    if kwargs['l3_protocol'] is None:
+        l3_layer = None
+    elif kwargs['l3_protocol'] == 'ipv4':
                 #fields_desc = [ BitField("version" , 4 , 4),
                 #                BitField("ihl", None, 4),
                 #                XByteField("tos", 0),
@@ -1088,12 +1092,15 @@ def generate_packet(**user_kwargs):
                     raise STLError('ipv6_dst_mode %s is not supported' % kwargs['ipv6_dst_mode'])
                 vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'IPv6.dst', offset_fixup = 12, add_val = add_val))
 
-    else:
+    elif kwargs['l3_protocol'] is not None:
         raise NotImplementedError("l3_protocol '%s' is not supported by TRex yet." % kwargs['l3_protocol'])
-    base_pkt /= l3_layer
+    if l3_layer is not None:
+        base_pkt /= l3_layer
 
     ### L4 ###
+    l4_layer = None
     if kwargs['l4_protocol'] == 'tcp':
+        assert kwargs['l3_protocol'] in ('ipv4', 'ipv6'), 'TCP must be over ipv4/ipv6'
                 #fields_desc = [ ShortEnumField("sport", 20, TCP_SERVICES),
                 #                ShortEnumField("dport", 80, TCP_SERVICES),
                 #                IntField("seq", 0),
@@ -1105,6 +1112,7 @@ def generate_packet(**user_kwargs):
                 #                XShortField("chksum", None),
                 #                ShortField("urgptr", 0),
                 #                TCPOptionsField("options", {}) ]
+
         tcp_flags = ('F' if kwargs['tcp_fin_flag'] else '' +
                      'S' if kwargs['tcp_syn_flag'] else '' +
                      'R' if kwargs['tcp_rst_flag'] else '' +
@@ -1190,6 +1198,7 @@ def generate_packet(**user_kwargs):
                 vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'TCP.dport', add_val = add_val))
 
     elif kwargs['l4_protocol'] == 'udp':
+        assert kwargs['l3_protocol'] in ('ipv4', 'ipv6'), 'UDP must be over ipv4/ipv6'
                 #fields_desc = [ ShortEnumField("sport", 53, UDP_SERVICES),
                 #                ShortEnumField("dport", 53, UDP_SERVICES),
                 #                ShortField("len", None),
@@ -1261,9 +1270,10 @@ def generate_packet(**user_kwargs):
                 else:
                     raise STLError('udp_dst_port_mode %s is not supported' % kwargs['udp_dst_port_mode'])
                 vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = var_name, pkt_offset = 'UDP.dport', add_val = add_val))
-    else:
-        raise NotImplementedError("l4_protocol '%s' is not supported by TRex yet." % kwargs['l3_protocol'])
-    base_pkt /= l4_layer
+    elif kwargs['l4_protocol'] is not None:
+        raise NotImplementedError("l4_protocol '%s' is not supported by TRex yet." % kwargs['l4_protocol'])
+    if l4_layer is not None:
+        base_pkt /= l4_layer
 
     trim_dict = {'increment': 'inc', 'decrement': 'dec', 'random': 'random'}
     length_mode = kwargs['length_mode']
@@ -1304,11 +1314,10 @@ def generate_packet(**user_kwargs):
             payload_len = kwargs['l3_length_max'] + len(l2_layer) - len(base_pkt)
             vm_cmds.append(CTRexVmDescTrimPktSize('pkt_len'))
 
-        if l3_layer.name == 'IP' or l4_layer.name == 'UDP': # add here other things need to fix due to size change
-            if l3_layer.name == 'IP':
-                vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = 'pkt_len', pkt_offset = 'IP.len', add_val = -len(l2_layer)))
-            if l4_layer.name == 'UDP':
-                vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = 'pkt_len', pkt_offset = 'UDP.len', add_val = -len(l2_layer) - len(l3_layer)))
+        if (l3_layer and l3_layer.name == 'IP'):
+            vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = 'pkt_len', pkt_offset = 'IP.len', add_val = -len(l2_layer)))
+        if (l4_layer and l4_layer.name == 'UDP'):
+            vm_cmds.append(CTRexVmDescWrFlowVar(fv_name = 'pkt_len', pkt_offset = 'UDP.len', add_val = -len(l2_layer) - len(l3_layer)))
     else:
         raise STLError('length_mode should be one of the following: %s' % ['auto', 'fixed'] + trim_dict.keys())
 
diff --git a/scripts/exp/hlt_4vlans.pcap b/scripts/exp/hlt_4vlans.pcap
new file mode 100644 (file)
index 0000000..642bbee
Binary files /dev/null and b/scripts/exp/hlt_4vlans.pcap differ
index 6c9a1cc..2ce91a9 100644 (file)
Binary files a/scripts/exp/hlt_david1.pcap and b/scripts/exp/hlt_david1.pcap differ
index 2c76a8a..5474dc3 100644 (file)
Binary files a/scripts/exp/hlt_david2.pcap and b/scripts/exp/hlt_david2.pcap differ
index d7c43f2..ce49257 100644 (file)
Binary files a/scripts/exp/hlt_david3.pcap and b/scripts/exp/hlt_david3.pcap differ
index 520675c..f03cbd7 100644 (file)
Binary files a/scripts/exp/hlt_david4.pcap and b/scripts/exp/hlt_david4.pcap differ
diff --git a/scripts/exp/hlt_framesize_vm.pcap b/scripts/exp/hlt_framesize_vm.pcap
new file mode 100644 (file)
index 0000000..69c2e7d
Binary files /dev/null and b/scripts/exp/hlt_framesize_vm.pcap differ
diff --git a/scripts/exp/hlt_ipv6_default.pcap b/scripts/exp/hlt_ipv6_default.pcap
new file mode 100644 (file)
index 0000000..9ca1cd8
Binary files /dev/null and b/scripts/exp/hlt_ipv6_default.pcap differ
diff --git a/scripts/exp/hlt_ipv6_ranges.pcap b/scripts/exp/hlt_ipv6_ranges.pcap
new file mode 100644 (file)
index 0000000..a05aca3
Binary files /dev/null and b/scripts/exp/hlt_ipv6_ranges.pcap differ
diff --git a/scripts/exp/hlt_l3_length_vm.pcap b/scripts/exp/hlt_l3_length_vm.pcap
new file mode 100644 (file)
index 0000000..fd02841
Binary files /dev/null and b/scripts/exp/hlt_l3_length_vm.pcap differ
diff --git a/scripts/exp/hlt_vlan_default.pcap b/scripts/exp/hlt_vlan_default.pcap
new file mode 100644 (file)
index 0000000..fd4d3bd
Binary files /dev/null and b/scripts/exp/hlt_vlan_default.pcap differ
diff --git a/scripts/exp/hlt_vlans_vm.pcap b/scripts/exp/hlt_vlans_vm.pcap
new file mode 100644 (file)
index 0000000..b510763
Binary files /dev/null and b/scripts/exp/hlt_vlans_vm.pcap differ
diff --git a/scripts/stl/hlt/hlt_4vlans.py b/scripts/stl/hlt/hlt_4vlans.py
new file mode 100755 (executable)
index 0000000..bdbd3d3
--- /dev/null
@@ -0,0 +1,28 @@
+from trex_stl_lib.trex_stl_hltapi import STLHltStream
+
+
+class STLS1(object):
+    '''
+    Eth/802.1Q/802.1Q/802.1Q/802.1Q/IPv6/TCP stream without VM
+    Missing values will be filled with defaults
+    '''
+
+    def create_streams (self, direction = 0):
+
+        return STLHltStream(frame_size = 100,
+                            vlan_id = [1, 2, 3, 4], # can be either array or string separated by spaces
+                            vlan_protocol_tag_id = '8100 0x8100', # hex with optional prefix '0x'
+                            vlan_user_priority = '4 3 2', # forth will be default
+                            l3_protocol = 'ipv6',
+                            l4_protocol = 'tcp',
+                            direction = direction)
+
+    def get_streams (self, direction = 0):
+        return self.create_streams(direction = direction)
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+
diff --git a/scripts/stl/hlt/hlt_framesize_vm.py b/scripts/stl/hlt/hlt_framesize_vm.py
new file mode 100755 (executable)
index 0000000..ed1ac54
--- /dev/null
@@ -0,0 +1,36 @@
+from trex_stl_lib.trex_stl_hltapi import STLHltStream
+
+
+class STLS1(object):
+    '''
+    Two Eth/IP/UDP streams with VM to get different size of packet by frame_size
+    '''
+
+    def create_streams (self, direction = 0):
+        return [STLHltStream(length_mode = 'increment',
+                             frame_size_min = 100,
+                             frame_size_max = 3000,
+                             l3_protocol = 'ipv4',
+                             l4_protocol = 'udp',
+                             rate_bps = 1000000,
+                             direction = direction,
+                             ),
+                STLHltStream(length_mode = 'decrement',
+                             frame_size_min = 100,
+                             frame_size_max = 3000,
+                             l3_protocol = 'ipv4',
+                             l4_protocol = 'udp',
+                             rate_bps = 100000,
+                             direction = direction,
+                             )
+               ]
+
+    def get_streams (self, direction = 0):
+        return self.create_streams(direction)
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+
index f6bfdd3..0b24527 100755 (executable)
@@ -13,6 +13,7 @@ class STLS1(object):
                             l3_imix2_size = 400, l3_imix2_ratio = 3,
                             l3_imix3_size = 2000, l3_imix3_ratio = 2,
                             l3_imix4_size = 8000, l3_imix4_ratio = 1,
+                            l3_protocol = 'ipv4',
                             l4_protocol = 'udp', direction = direction,
                             )
 
index ac8762c..85c6b1a 100755 (executable)
@@ -4,7 +4,8 @@ from trex_stl_lib.trex_stl_hltapi import STLHltStream
 class STLS1(object):
 
     def create_streams (self):
-        return STLHltStream(length_mode = 'imix', rate_pps = 2)
+        return STLHltStream(length_mode = 'imix', rate_pps = 2,
+                            l3_protocol = 'ipv4', l4_protocol = 'tcp')
 
     def get_streams (self, direction = 0):
         return self.create_streams()
diff --git a/scripts/stl/hlt/hlt_ip_ranges.py b/scripts/stl/hlt/hlt_ip_ranges.py
new file mode 100755 (executable)
index 0000000..4346065
--- /dev/null
@@ -0,0 +1,29 @@
+from trex_stl_lib.trex_stl_hltapi import STLHltStream
+
+
+class STLS1(object):
+    '''
+    Eth/IP/TCP stream with VM to get different ip addresses
+    '''
+
+    def create_streams (self, direction = 0):
+        return [STLHltStream(split_by_cores = 'duplicate',
+                             l3_protocol = 'ipv4',
+                             ip_src_addr = '192.168.1.1',
+                             ip_src_mode = 'increment',
+                             ip_src_count = 5,
+                             ip_dst_addr = '5.5.5.5',
+                             ip_dst_mode = 'random',
+                             consistent_random = True,
+                             rate_pps = 1),
+               ]
+
+    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_ipv6_default.py b/scripts/stl/hlt/hlt_ipv6_default.py
new file mode 100755 (executable)
index 0000000..4cc73d6
--- /dev/null
@@ -0,0 +1,25 @@
+from trex_stl_lib.trex_stl_hltapi import STLHltStream
+
+
+class STLS1(object):
+    '''
+    Eth/IPv6/UDP stream without VM, default values
+    '''
+
+    def create_streams (self, direction = 0):
+        return [STLHltStream(l3_protocol = 'ipv6',
+                             l3_length = 150,
+                             l4_protocol = 'udp',
+                             direction = direction,
+                             ),
+               ]
+
+    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_ipv6_ranges.py b/scripts/stl/hlt/hlt_ipv6_ranges.py
new file mode 100755 (executable)
index 0000000..6d9c157
--- /dev/null
@@ -0,0 +1,25 @@
+from trex_stl_lib.trex_stl_hltapi import STLHltStream
+
+
+class STLS1(object):
+    '''
+    Eth/IPv6/UDP stream with VM, to change the ipv6 addr (only 32 lsb)
+    '''
+
+    def create_streams (self, direction = 0):
+        return STLHltStream(l3_protocol = 'ipv6', l3_length = 150, l4_protocol = 'udp',
+                            ipv6_src_addr = '1111:2222:3333:4444:5555:6666:7777:8888',
+                            ipv6_dst_addr = '1111:1111:1111:1111:1111:1111:1111:1111',
+                            ipv6_src_mode = 'increment', ipv6_src_step = 5, ipv6_src_count = 10,
+                            ipv6_dst_mode = 'decrement', ipv6_dst_step = '1111:1111:1111:1111:1111:0000:0000:0011', ipv6_dst_count = 150,
+                            )
+
+    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_l3_length_vm.py b/scripts/stl/hlt/hlt_l3_length_vm.py
new file mode 100755 (executable)
index 0000000..e9b6654
--- /dev/null
@@ -0,0 +1,36 @@
+from trex_stl_lib.trex_stl_hltapi import STLHltStream
+
+
+class STLS1(object):
+    '''
+    Two Eth/IP/UDP streams with VM to get different size of packet by l3_length
+    '''
+
+    def create_streams (self, direction = 0):
+        return [STLHltStream(length_mode = 'increment',
+                             l3_length_min = 100,
+                             l3_length_max = 3000,
+                             l3_protocol = 'ipv4',
+                             l4_protocol = 'udp',
+                             rate_bps = 1000000,
+                             direction = direction,
+                             ),
+                STLHltStream(length_mode = 'decrement',
+                             l3_length_min = 100,
+                             l3_length_max = 3000,
+                             l3_protocol = 'ipv4',
+                             l4_protocol = 'udp',
+                             rate_bps = 1000000,
+                             direction = direction,
+                             )
+               ]
+
+    def get_streams (self, direction = 0):
+        return self.create_streams(direction)
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+
index 28e6685..911fdec 100755 (executable)
@@ -7,7 +7,9 @@ class STLS1(object):
     '''
 
     def create_streams (self, direction = 0):
-        return [STLHltStream(tcp_src_port_mode = 'decrement',
+        return [STLHltStream(l3_protocol = 'ipv4',
+                             l4_protocol = 'tcp',
+                             tcp_src_port_mode = 'decrement',
                              tcp_src_port_count = 10,
                              tcp_src_port = 1234,
                              tcp_dst_port_mode = 'increment',
index b3fec98..5fb8687 100755 (executable)
@@ -12,6 +12,7 @@ class STLS1(object):
         max_size = 9*1024
         return [STLHltStream(length_mode = 'increment',
                              frame_size_max = max_size,
+                             l3_protocol = 'ipv4',
                              ip_src_addr = '16.0.0.1',
                              ip_dst_addr = '48.0.0.1',
                              l4_protocol = 'udp',
@@ -21,6 +22,7 @@ class STLS1(object):
                              ),
                 STLHltStream(length_mode = 'decrement',
                              frame_size_max = max_size,
+                             l3_protocol = 'ipv4',
                              ip_src_addr = '16.0.0.1',
                              ip_dst_addr = '48.0.0.1',
                              l4_protocol = 'udp',
index 2086214..cdb1af1 100755 (executable)
@@ -8,7 +8,8 @@ class STLS1(object):
     '''
 
     def create_streams (self, direction = 0):
-        return [STLHltStream(l4_protocol = 'udp',
+        return [STLHltStream(l3_protocol = 'ipv4',
+                             l4_protocol = 'udp',
                              udp_src_port_mode = 'decrement',
                              udp_src_port_count = 45,
                              udp_src_port_step = 20,
index 0f60958..6397ba1 100755 (executable)
@@ -8,7 +8,8 @@ class STLS1(object):
     '''
 
     def create_streams (self, direction = 0):
-        return [STLHltStream(l4_protocol = 'udp',
+        return [STLHltStream(l3_protocol = 'ipv4',
+                             l4_protocol = 'udp',
                              udp_src_port_mode = 'random',
                              udp_dst_port_mode = 'random',
                              direction = direction,
diff --git a/scripts/stl/hlt/hlt_vlan_default.py b/scripts/stl/hlt/hlt_vlan_default.py
new file mode 100755 (executable)
index 0000000..8e50eef
--- /dev/null
@@ -0,0 +1,23 @@
+from trex_stl_lib.trex_stl_hltapi import STLHltStream
+
+
+class STLS1(object):
+    '''
+    Default Eth/802.1Q/IP/TCP stream without VM
+    '''
+
+    def create_streams (self, direction = 0):
+
+        return STLHltStream(l2_encap = 'ethernet_ii_vlan',
+                            l3_protocol = 'ipv4', l4_protocol = 'tcp',
+                            direction = direction)
+
+    def get_streams (self, direction = 0):
+        return self.create_streams(direction = direction)
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+
diff --git a/scripts/stl/hlt/hlt_vlans_vm.py b/scripts/stl/hlt/hlt_vlans_vm.py
new file mode 100755 (executable)
index 0000000..aa4881c
--- /dev/null
@@ -0,0 +1,30 @@
+from trex_stl_lib.trex_stl_hltapi import STLHltStream
+
+
+class STLS1(object):
+    '''
+    Eth/802.1Q/802.1Q/802.1Q/802.1Q/802.1Q/IPv4/UDP stream with complex VM on vlan_id's
+    Missing values will be filled with defaults
+    '''
+
+    def create_streams (self, direction = 0):
+
+        return STLHltStream(frame_size = 100,
+                            vlan_id = '1 2 1000 4 5',                          # 5 vlans
+                            vlan_id_mode = 'increment fixed decrement random', # 5th vlan will be default fixed
+                            vlan_id_step = 2,                                  # 1st vlan step will be 2, others - default 1
+                            vlan_id_count = [4, 1, 10],                        # 4th independent on count, 5th will be fixed
+                            l3_protocol = 'ipv4',
+                            l4_protocol = 'udp',
+                            direction = direction,
+                            )
+
+    def get_streams (self, direction = 0):
+        return self.create_streams(direction = direction)
+
+# dynamic load - used for trex console or simulator
+def register():
+    return STLS1()
+
+
+