diff options
Diffstat (limited to 'scripts/automation/regression')
-rwxr-xr-x | scripts/automation/regression/hltapi_example.py | 69 | ||||
-rwxr-xr-x | scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py | 343 |
2 files changed, 388 insertions, 24 deletions
diff --git a/scripts/automation/regression/hltapi_example.py b/scripts/automation/regression/hltapi_example.py index 2a30d08c..0040219a 100755 --- a/scripts/automation/regression/hltapi_example.py +++ b/scripts/automation/regression/hltapi_example.py @@ -56,45 +56,66 @@ if __name__ == "__main__": print('Connected.') print('Create single_burst 100 packets rate_pps=100 on port 0') - res = check_res(hlt_client.traffic_config('create', port_handle = port_handle[0], transmit_mode = 'single_burst', pkts_per_burst = 100, rate_pps = 100)) - save_streams_id(res, streams_id_arr) + res = check_res(hlt_client.traffic_config(mode = 'create', port_handle = port_handle[0], transmit_mode = 'single_burst', pkts_per_burst = 100, rate_pps = 100)) + #save_streams_id(res, streams_id_arr) + + # playground - creating various streams on port 1 + res = check_res(hlt_client.traffic_config(mode = 'create', port_handle = port_handle[1], save_to_yaml = '/tmp/hlt2.yaml', + tcp_src_port_mode = 'decrement', + tcp_src_port_count = 10, tcp_dst_port_count = 10, tcp_dst_port_mode = 'random')) + + res = check_res(hlt_client.traffic_config(mode = 'create', port_handle = port_handle[1], save_to_yaml = '/tmp/hlt3.yaml', + l4_protocol = 'udp', + udp_src_port_mode = 'decrement', + udp_src_port_count = 10, udp_dst_port_count = 10, udp_dst_port_mode = 'random')) + + res = check_res(hlt_client.traffic_config(mode = 'create', port_handle = port_handle[1], save_to_yaml = '/tmp/hlt4.yaml', + length_mode = 'increment', + #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', ip_dst_count = 2)) + + res = check_res(hlt_client.traffic_config(mode = 'create', port_handle = port_handle[1], save_to_yaml = '/tmp/hlt5.yaml', + length_mode = 'decrement', frame_size_min = 100, frame_size_max = 3000, + #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', ip_dst_count = 2 + )) + # remove the playground + check_res(hlt_client.traffic_config(mode = 'reset', port_handle = port_handle[1])) print('Create continuous stream for port 1, rate_pps = 1') - res = check_res(hlt_client.traffic_config('create', port_handle = port_handle[1])) - save_streams_id(res, streams_id_arr) + res = check_res(hlt_client.traffic_config(mode = 'create', port_handle = port_handle[1], save_to_yaml = '/tmp/hlt1.yaml', + #length_mode = 'increment', l3_length_min = 200, + 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', ip_dst_count = 2)) - print('Run traffic on both ports for 20s') - check_res(hlt_client.traffic_control(action = 'run', port_handle = port_handle, mul = {'type': 'raw', 'op': 'abs', 'value': 1}, duration = 20)) - wait_with_progress(5) - - print('All available HLT stats after 5s') + check_res(hlt_client.traffic_control(action = 'run', port_handle = port_handle)) + wait_with_progress(1) + print('Sample after 1 seconds (only packets count)') res = check_res(hlt_client.traffic_stats(mode = 'all', port_handle = port_handle)) - pprint(res) + print_brief_stats(res) + print '' - # delete the single_burst - print('Port 0 has finished the burst, delete it and put continuous with rate 1000. No stopping of other ports.') - check_res(hlt_client.traffic_config('reset', port_handle = port_handle[0])) - res = check_res(hlt_client.traffic_config('create', port_handle = port_handle[0], rate_pps = 1000)) + print('Port 0 has finished the burst, put continuous instead with rate 1000. No stopping of other ports.') + check_res(hlt_client.traffic_control(action = 'stop', port_handle = port_handle[0])) + check_res(hlt_client.traffic_config(mode = 'reset', port_handle = port_handle[0])) + res = check_res(hlt_client.traffic_config(mode = 'create', port_handle = port_handle[0], rate_pps = 1000)) save_streams_id(res, streams_id_arr) - check_res(hlt_client.traffic_control(action = 'run', port_handle = port_handle[0], mul = {'type': 'raw', 'op': 'abs', 'value': 1}, duration = 15)) + check_res(hlt_client.traffic_control(action = 'run', port_handle = port_handle[0])) wait_with_progress(5) - print('Sample after another %s seconds (only packets count)' % 5) + print('Sample after another 5 seconds (only packets count)') res = check_res(hlt_client.traffic_stats(mode = 'aggregate', port_handle = port_handle)) print_brief_stats(res) - - #print('Stop the traffic on port 1') - #res = check_res(hlt_client.traffic_control('stop', port_handle = port_handle[1])) - #wait_with_progress(sample_duration) - #print('Sample after another %s seconds (only packets count)' % sample_duration) - #res = check_res(hlt_client.traffic_stats(mode = 'all', port_handle = port_handle)) - #print_brief_stats(res) + print '' print('Stop traffic at port 1') - res = check_res(hlt_client.traffic_control('stop', port_handle = port_handle[1])) + res = check_res(hlt_client.traffic_control(action = 'stop', port_handle = port_handle[1])) wait_with_progress(5) print('Sample after another %s seconds (only packets count)' % 5) res = check_res(hlt_client.traffic_stats(mode = 'aggregate', port_handle = port_handle)) print_brief_stats(res) + print '' + print('Full HLT stats:') + pprint(res) check_res(hlt_client.cleanup_session()) except Exception as e: 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 new file mode 100755 index 00000000..eefa1947 --- /dev/null +++ b/scripts/automation/regression/unit_tests/functional_tests/hltapi_stream_builder_test.py @@ -0,0 +1,343 @@ +#!/router/bin/python + +from client.trex_hltapi import CTRexHltApiPktBuilder +import os +import unittest + +gen_stream = CTRexHltApiPktBuilder.generate_stream + +def compare_yamls(yaml1, yaml2): + if type(yaml1) is not str: + raise Exception("yaml1 is '%s', expected str" % type(yaml1)) + if type(yaml2) is not str: + raise Exception("yaml2 is '%s', expected str" % type(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\t<->\n%s' % (i, line1.strip(), line2.strip())) + +class CTRexHltApi_Test(unittest.TestCase): + ''' Checks correct HLTAPI creation of packet/VM ''' + + def setUp(self): + self.golden_yaml = None + self.test_yaml = None + + def tearDown(self): + compare_yamls(self.golden_yaml, self.test_yaml) + + # Eth/IP/TCP, all values default, no VM instructions + def test_default(self): + test_stream = gen_stream() + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location(), test_stream) + self.golden_yaml = ''' +- name: stream-0 + stream: + enabled: true + isg: 0.0 + mode: + pps: 1 + type: continuous + packet: + binary: AAAAAAAAAAABAAABCABFAAAyAAAAAEAGusUAAAAAwAAAAQQAAFAAAAABAAAAAVAAD+U1/QAAISEhISEhISEhIQ== + meta: '' + rx_stats: + enabled: false + self_start: true + vm: + instructions: [] + split_by_var: '' +''' + + # Eth/IP/TCP, ip src and dest is changed by VM + def test_ip_ranges(self): + test_stream = gen_stream(ip_src_addr = '192.168.1.1', + ip_src_mode = 'increment', + ip_src_count = 5, + ip_dst_addr = '5.5.5.5', + ip_dst_count = 2, + ip_dst_mode = 'random') + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location(), test_stream) + self.golden_yaml = ''' +- name: stream-0 + stream: + enabled: true + isg: 0.0 + mode: + pps: 1 + type: continuous + packet: + binary: AAAAAAAAAAABAAABCABFAAAyAAAAAEAGrxPAqAEBBQUFBQQAAFAAAAABAAAAAVAAD+UqSwAAISEhISEhISEhIQ== + meta: '' + rx_stats: + enabled: false + self_start: true + vm: + instructions: + - init_value: 3232235777 + max_value: 3232235781 + min_value: 3232235777 + name: ip_src + op: inc + size: 4 + type: flow_var + - add_value: 0 + is_big_endian: true + name: ip_src + pkt_offset: 26 + type: write_flow_var + - init_value: 84215045 + max_value: 84215046 + min_value: 84215045 + name: ip_dst + op: random + size: 4 + type: flow_var + - add_value: 0 + is_big_endian: true + name: ip_dst + pkt_offset: 30 + type: write_flow_var + - pkt_offset: 14 + type: fix_checksum_ipv4 + split_by_var: '' + +''' + + # Eth / IP / TCP, tcp ports are changed by VM + def test_tcp_ranges(self): + test_stream = gen_stream(tcp_src_port_mode = 'decrement', + tcp_src_port_count = 10, + tcp_dst_port_mode = 'random', + tcp_dst_port_count = 10, + tcp_dst_port = 1234) + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location(), test_stream) + self.golden_yaml = ''' +- name: stream-0 + stream: + enabled: true + isg: 0.0 + mode: + pps: 1 + type: continuous + packet: + binary: AAAAAAAAAAABAAABCABFAAAyAAAAAEAGusUAAAAAwAAAAQQABNIAAAABAAAAAVAAD+UxewAAISEhISEhISEhIQ== + meta: '' + rx_stats: + enabled: false + self_start: true + vm: + instructions: + - init_value: 1024 + max_value: 1024 + min_value: 1015 + name: tcp_src + op: dec + size: 2 + type: flow_var + - add_value: 0 + is_big_endian: true + name: tcp_src + pkt_offset: 34 + type: write_flow_var + - init_value: 1234 + max_value: 1243 + min_value: 1234 + name: tcp_dst + op: random + size: 2 + type: flow_var + - add_value: 0 + is_big_endian: true + name: tcp_dst + pkt_offset: 36 + type: write_flow_var + - pkt_offset: 14 + type: fix_checksum_ipv4 + split_by_var: '' +''' + + # Eth / IP / UDP, udp ports are changed by VM + def test_udp_ranges(self): + # UDP is not set, expecting ignore of wrong UDP arguments + gen_stream(udp_src_port_mode = 'qwerqwer', + udp_src_port_count = 'weqwer', + udp_src_port = 'qwerqwer', + udp_dst_port_mode = 'qwerqwe', + udp_dst_port_count = 'sfgsdfg', + udp_dst_port = 'sdfgsdfg') + # UDP is set, expecting fail due to wrong UDP arguments + with self.assertRaises(Exception): + gen_stream(l4_protocol = 'udp', + udp_src_port_mode = 'qwerqwer', + udp_src_port_count = 'weqwer', + udp_src_port = 'qwerqwer', + udp_dst_port_mode = 'qwerqwe', + udp_dst_port_count = 'sfgsdfg', + udp_dst_port = 'sdfgsdfg') + # generate it already with correct arguments + test_stream = gen_stream(l4_protocol = 'udp', + udp_src_port_mode = 'decrement', + udp_src_port_count = 10, + udp_src_port = 1234, + udp_dst_port_mode = 'increment', + udp_dst_port_count = 10, + udp_dst_port = 1234) + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location(), test_stream) + self.golden_yaml = ''' +- name: stream-0 + stream: + enabled: true + isg: 0.0 + mode: + pps: 1 + type: continuous + packet: + binary: AAAAAAAAAAABAAABCABFAAAyAAAAAEARuroAAAAAwAAAAQTSBNIAHsmgISEhISEhISEhISEhISEhISEhISEhIQ== + meta: '' + rx_stats: + enabled: false + self_start: true + vm: + instructions: + - init_value: 1234 + max_value: 1234 + min_value: 1225 + name: udp_src + op: dec + size: 2 + type: flow_var + - add_value: 0 + is_big_endian: true + name: udp_src + pkt_offset: 34 + type: write_flow_var + - init_value: 1234 + max_value: 1243 + min_value: 1234 + name: udp_dst + op: inc + size: 2 + type: flow_var + - add_value: 0 + is_big_endian: true + name: udp_dst + pkt_offset: 36 + type: write_flow_var + - pkt_offset: 14 + type: fix_checksum_ipv4 + split_by_var: '' +''' + + # 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 = gen_stream(length_mode = 'decrement', + frame_size_min = 100, + frame_size_max = 3000, + frame_size_step = 20) + # just check errors, no compare to golden + gen_stream(length_mode = 'increment', + frame_size_min = 100, + frame_size_max = 3000) + test_stream = gen_stream(length_mode = 'decrement', + frame_size_min = 100, + frame_size_max = 3000) + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location(), test_stream) + self.golden_yaml = ''' +- name: stream-0 + stream: + enabled: true + isg: 0.0 + mode: + pps: 1 + type: continuous + packet: + binary: AAAAAAAAAAABAAABCABFAAAyAAAAAEAGusUAAAAAwAAAAQQAAFAAAAABAAAAAVAAD+U8AwAAISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEh + meta: '' + rx_stats: + enabled: false + self_start: true + vm: + instructions: + - init_value: 3000 + max_value: 3000 + min_value: 100 + name: fv_rand + op: dec + size: 2 + type: flow_var + - name: fv_rand + type: trim_pkt_size + - add_value: -14 + is_big_endian: true + name: fv_rand + pkt_offset: 16 + type: write_flow_var + - pkt_offset: 14 + type: fix_checksum_ipv4 + split_by_var: '' +''' + + # 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): + gen_stream(l4_protocol = 'udp', + length_mode = 'random', + l3_length_min = 100, + l3_length_max = 400, + l3_length_step = 20) + test_stream = gen_stream(l4_protocol = 'udp', + length_mode = 'random', + l3_length_min = 100, + l3_length_max = 400) + self.test_yaml = test_stream.dump_to_yaml(self.yaml_save_location(), test_stream) + self.golden_yaml = ''' +- name: stream-0 + stream: + enabled: true + isg: 0.0 + mode: + pps: 1 + type: continuous + packet: + binary: AAAAAAAAAAABAAABCABFAAAyAAAAAEARuroAAAAAwAAAAQQAAFABfCfxISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEhISEh + meta: '' + rx_stats: + enabled: false + self_start: true + vm: + instructions: + - init_value: 114 + max_value: 414 + min_value: 114 + name: fv_rand + op: random + size: 2 + type: flow_var + - name: fv_rand + type: trim_pkt_size + - add_value: -14 + is_big_endian: true + name: fv_rand + pkt_offset: 16 + type: write_flow_var + - add_value: -34 + is_big_endian: true + name: fv_rand + pkt_offset: 38 + type: write_flow_var + - pkt_offset: 14 + type: fix_checksum_ipv4 + split_by_var: '' +''' + + def yaml_save_location(self): + return os.devnull + # debug/deveopment, comment line above + return '/tmp/%s.yaml' % self._testMethodName + + |