diff options
author | 2016-02-18 16:48:47 +0200 | |
---|---|---|
committer | 2016-02-18 16:48:47 +0200 | |
commit | 2c9504ac710b7ae9021601b8947069d922040a34 (patch) | |
tree | a518fd36d927126c7ceb2cbe1af078be56436d57 /scripts/automation/regression/unit_tests | |
parent | c6f710bc844e812fe448f7a2850fe15058328777 (diff) |
hltapi update: vlans (one or nested), ipv6, "imix" moved to stream builder
Diffstat (limited to 'scripts/automation/regression/unit_tests')
-rwxr-xr-x | scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py | 198 | ||||
-rw-r--r-- | scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py | 7 |
2 files changed, 184 insertions, 21 deletions
diff --git a/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py b/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py index d0adb546..e76e3bb0 100755 --- a/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py +++ b/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py @@ -5,6 +5,7 @@ import unittest from trex_stl_lib.trex_stl_hltapi import STLHltStream from trex_stl_lib.trex_stl_types import validate_type from nose.plugins.attrib import attr +from nose.tools import nottest def compare_yamls(yaml1, yaml2): validate_type('yaml1', yaml1, str) @@ -12,8 +13,7 @@ def compare_yamls(yaml1, yaml2): i = 0 for line1, line2 in zip(yaml1.strip().split('\n'), yaml2.strip().split('\n')): i += 1 - if line1 != line2: - raise Exception('yamls are not equal starting from line %s:\n%s\n Golden <-> Generated\n%s' % (i, line1.strip(), line2.strip())) + assert line1 == line2, 'yamls are not equal starting from line %s:\n%s\n Golden <-> Generated\n%s' % (i, line1.strip(), line2.strip()) class CTRexHltApi_Test(unittest.TestCase): @@ -26,8 +26,18 @@ class CTRexHltApi_Test(unittest.TestCase): def tearDown(self): compare_yamls(self.golden_yaml, self.test_yaml) - # Eth/IP/TCP, all values default, no VM instructions - def test_default(self): + # Eth/IP/TCP, all values default, no VM instructions + test MACs correction + def test_hlt_basic(self): + STLHltStream(mac_src = 'a0:00:01:::01', mac_dst = '0d 00 01 00 00 01', + mac_src2 = '{00 b0 01 00 00 01}', mac_dst2 = 'd0.00.01.00.00.01') + with self.assertRaises(Exception): + STLHltStream(mac_src2 = '00:00:00:00:00:0k') + with self.assertRaises(Exception): + STLHltStream(mac_dst2 = '100:00:00:00:00:00') + # wrong encap + with self.assertRaises(Exception): + STLHltStream(l2_encap = 'ethernet_sdfgsdfg') + # all default values test_stream = STLHltStream(name = 'stream-0') self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location()) self.golden_yaml = ''' @@ -51,6 +61,16 @@ class CTRexHltApi_Test(unittest.TestCase): split_by_var: '' ''' + # Eth/IP/TCP, test L2 fields, wait for masking of variables for MAC + @nottest + def test_l2_basic(self): + test_stream = STLHltStream(name = 'stream-0') + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location()) + self.golden_yaml = ''' +TBD +''' + + # Eth/IP/TCP, ip src and dest is changed by VM def test_ip_ranges(self): test_stream = STLHltStream(ip_src_addr = '192.168.1.1', @@ -247,12 +267,6 @@ class CTRexHltApi_Test(unittest.TestCase): # Eth/IP/TCP, packet length is changed in VM by frame_size def test_pkt_len_by_framesize(self): - # frame_size_step should be 1 (as default) - with self.assertRaises(Exception): - test_stream = STLHltStream(length_mode = 'decrement', - frame_size_min = 100, - frame_size_max = 3000, - frame_size_step = 20) # just check errors, no compare to golden STLHltStream(length_mode = 'increment', frame_size_min = 100, @@ -302,13 +316,6 @@ class CTRexHltApi_Test(unittest.TestCase): # Eth/IP/UDP, packet length is changed in VM by l3_length def test_pkt_len_by_l3length(self): - # l3_length_step should be 1 - with self.assertRaises(Exception): - STLHltStream(l4_protocol = 'udp', - length_mode = 'random', - l3_length_min = 100, - l3_length_max = 400, - l3_length_step = 20) test_stream = STLHltStream(l4_protocol = 'udp', length_mode = 'random', l3_length_min = 100, @@ -358,8 +365,163 @@ class CTRexHltApi_Test(unittest.TestCase): split_by_var: '' ''' + # Eth/IP/TCP, with vlan, no VM + def test_vlan_basic(self): + with self.assertRaises(Exception): + STLHltStream(l2_encap = 'ethernet_ii', + vlan_id = 'sdfgsdgf') + test_stream = STLHltStream(l2_encap = 'ethernet_ii') + assert ':802.1Q:' not in test_stream.get_pkt_type(), 'Default packet should not include dot1q' + + test_stream = STLHltStream(name = 'stream-0', l2_encap = 'ethernet_ii_vlan') + assert ':802.1Q:' in test_stream.get_pkt_type(), 'No dot1q in packet with encap ethernet_ii_vlan' + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location()) + self.golden_yaml = ''' +- name: stream-0 + stream: + action_count: 0 + enabled: true + flags: 3 + isg: 0.0 + mode: + pps: 1 + type: continuous + packet: + binary: AAAAAAAAAAABAAABgQAwAAgARQAALgAAAABABrrJAAAAAMAAAAEEAABQAAAAAQAAAAFQAA/leEMAACEhISEhIQ== + meta: '' + rx_stats: + enabled: false + self_start: true + vm: + instructions: [] + split_by_var: '' +''' + + # Eth/IP/TCP, with 4 vlan + def test_vlan_multiple(self): + # default frame size should be not enough + with self.assertRaises(Exception): + STLHltStream(vlan_id = [1, 2, 3, 4]) + test_stream = STLHltStream(name = 'stream-0', frame_size = 100, vlan_id = [1, 2, 3, 4], vlan_protocol_tag_id = '8100 0x8100') + pkt_layers = test_stream.get_pkt_type() + assert ':802.1Q:802.1Q:802.1Q:802.1Q:' in pkt_layers, 'No four dot1q layers in packet: %s' % pkt_layers + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location()) + self.golden_yaml = ''' +- name: stream-0 + stream: + action_count: 0 + enabled: true + flags: 3 + isg: 0.0 + mode: + pps: 1 + type: continuous + packet: + binary: AAAAAAAAAAABAAABgQAwAYEAMAKBADADgQAwBAgARQAARgAAAABABrqxAAAAAMAAAAEEAABQAAAAAQAAAAFQAA/l6p0AACEhISEhISEhISEhISEhISEhISEhISEhISEhISEhIQ== + meta: '' + rx_stats: + enabled: false + self_start: true + vm: + instructions: [] + split_by_var: '' +''' + + # Eth/IPv6/TCP, no VM + def test_ipv6_basic(self): + # default frame size should be not enough + with self.assertRaises(Exception): + STLHltStream(l3_protocol = 'ipv6') + # error should not affect + STLHltStream(ipv6_src_addr = 'asdfasdfasgasdf') + # error should affect + with self.assertRaises(Exception): + STLHltStream(l3_protocol = 'ipv6', ipv6_src_addr = 'asdfasdfasgasdf') + test_stream = STLHltStream(name = 'stream-0', l3_protocol = 'ipv6', length_mode = 'fixed', l3_length = 150, ) + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location()) + self.golden_yaml = ''' +- name: stream-0 + stream: + action_count: 0 + enabled: true + flags: 3 + isg: 0.0 + mode: + pps: 1 + type: continuous + packet: + binary: AAAAAAAAAAABAAABht1gAAAAAFIGQP6AAAAAAAAAAAAAAAAAABL+gAAAAAAAAAAAAAAAAAAiBAAAUAAAAAEAAAABUAAP5Zs3AAAhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhIQ== + meta: '' + rx_stats: + enabled: false + self_start: true + vm: + instructions: [] + split_by_var: '' +''' + + # Eth/IPv6/UDP, VM on ipv6 fields + def test_ipv6_src_dst_ranges(self): + test_stream = STLHltStream(name = 'stream-0', 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:1111:0000:0011', ipv6_dst_count = 150, + ) + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location()) + self.golden_yaml = ''' +- name: stream-0 + stream: + action_count: 0 + enabled: true + flags: 3 + isg: 0.0 + mode: + pps: 1 + type: continuous + packet: + binary: AAAAAAAAAAABAAABht1gAAAAAFIRQBERIiIzM0REVVVmZnd3iIgRERERERERERERERERERERBAAAUABSQkIhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhIQ== + meta: '' + rx_stats: + enabled: false + self_start: true + vm: + instructions: + - init_value: 2004322440 + max_value: 2004322449 + min_value: 2004322440 + name: ipv6_src + op: inc + size: 4 + step: 5 + type: flow_var + - add_value: 0 + is_big_endian: true + name: ipv6_src + pkt_offset: 34 + type: write_flow_var + - init_value: 286331153 + max_value: 286331153 + min_value: 286331004 + name: ipv6_dst + op: dec + size: 4 + step: 17 + type: flow_var + - add_value: 0 + is_big_endian: true + name: ipv6_dst + pkt_offset: 50 + type: write_flow_var + split_by_var: '' +''' + + + + + def yaml_save_location(self): - #return os.devnull + return os.devnull # debug/deveopment, comment line above return '/tmp/%s.yaml' % self._testMethodName diff --git a/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py b/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py index a2249d5a..34bd42df 100644 --- a/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py +++ b/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py @@ -187,14 +187,15 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): self.run_py_profile_path (obj[0],obj[1],compare =obj[2], do_no_remove=True) - def hlt_profiles (self): + def test_hlt_profiles (self): p = ( - ['hlt/hlt_udp_inc_dec_len_9k.py', '-m 1 -l 40', True], + ['hlt/hlt_udp_inc_dec_len_9k.py', '-m 1 -l 20', True], + ['hlt/hlt_imix_default.py', '-m 1 -l 40', True], ) for obj in p: - self.run_py_profile_path (obj[0], obj[1], compare =obj[2], do_no_remove=False) + self.run_py_profile_path (obj[0], obj[1], compare =obj[2], do_no_remove=True) # valgrind tests def test_valgrind_various_profiles (self): |