Pau Espin Pedrol | 0fc7437 | 2018-11-14 16:44:57 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | from osmo_gsm_tester.testenv import * |
| 3 | |
| 4 | def print_results(cli_res, srv_res): |
| 5 | cli_sent = cli_res['end']['sum_sent'] |
| 6 | cli_recv = cli_res['end']['sum_received'] |
| 7 | print("RESULT client:") |
| 8 | print("\tSEND: %d KB, %d kbps, %d seconds (%d retrans)" % (cli_sent['bytes']/1000, cli_sent['bits_per_second']/1000, cli_sent['seconds'], cli_sent['retransmits'])) |
| 9 | print("\tRECV: %d KB, %d kbps, %d seconds" % (cli_recv['bytes']/1000, cli_recv['bits_per_second']/1000, cli_recv['seconds'])) |
| 10 | print("RESULT server:") |
| 11 | print("\tSEND: %d KB, %d kbps, %d seconds" % (cli_sent['bytes']/1000, cli_sent['bits_per_second']/1000, cli_sent['seconds'])) |
| 12 | print("\tRECV: %d KB, %d kbps, %d seconds" % (cli_recv['bytes']/1000, cli_recv['bits_per_second']/1000, cli_recv['seconds'])) |
| 13 | |
| 14 | def run_iperf3_cli_parallel(iperf3clients, ms_li): |
| 15 | assert len(iperf3clients) == len(ms_li) |
| 16 | procs = [] |
| 17 | for i in range(len(iperf3clients)): |
| 18 | print("Running iperf3 client to %s through %r" % (str(iperf3clients[i]), repr(ms_li[i].tmp_ctx_id))) |
| 19 | procs.append(iperf3clients[i].prepare_test_proc(ms_li[i].netns())) |
| 20 | try: |
| 21 | for proc in procs: |
| 22 | proc.launch() |
| 23 | for proc in procs: |
| 24 | proc.wait() |
| 25 | except Exception as e: |
| 26 | for proc in procs: |
| 27 | proc.terminate() |
| 28 | raise e |
| 29 | |
| 30 | |
| 31 | def setup_run_iperf3_test_parallel(num_ms): |
| 32 | hlr = suite.hlr() |
| 33 | bts = suite.bts() |
| 34 | pcu = bts.pcu() |
| 35 | mgw_msc = suite.mgw() |
| 36 | mgw_bsc = suite.mgw() |
| 37 | stp = suite.stp() |
| 38 | ggsn = suite.ggsn() |
| 39 | sgsn = suite.sgsn(hlr, ggsn) |
| 40 | msc = suite.msc(hlr, mgw_msc, stp) |
| 41 | bsc = suite.bsc(msc, mgw_bsc, stp) |
| 42 | |
| 43 | iperf3srv_addr = suite.ip_address() |
| 44 | servers = [] |
| 45 | clients = [] |
| 46 | ms_li = [] |
| 47 | for i in range(num_ms): |
| 48 | iperf3srv = suite.iperf3srv(iperf3srv_addr) |
| 49 | iperf3srv.set_port(iperf3srv.DEFAULT_SRV_PORT + i) |
| 50 | servers.append(iperf3srv) |
| 51 | |
| 52 | iperf3cli = iperf3srv.create_client() |
| 53 | clients.append(iperf3cli) |
| 54 | |
| 55 | ms = suite.modem() |
| 56 | ms_li.append(ms) |
| 57 | |
| 58 | bsc.bts_add(bts) |
| 59 | sgsn.bts_add(bts) |
| 60 | |
| 61 | for iperf3srv in servers: |
| 62 | print('start iperfv3 server %s...' % str(iperf3srv) ) |
| 63 | iperf3srv.start() |
| 64 | |
| 65 | print('start network...') |
| 66 | hlr.start() |
| 67 | stp.start() |
| 68 | ggsn.start() |
| 69 | sgsn.start() |
| 70 | msc.start() |
| 71 | mgw_msc.start() |
| 72 | mgw_bsc.start() |
| 73 | bsc.start() |
| 74 | |
| 75 | bts.start() |
| 76 | wait(bsc.bts_is_connected, bts) |
| 77 | print('Waiting for bts to be ready...') |
| 78 | wait(bts.ready_for_pcu) |
| 79 | pcu.start() |
| 80 | |
| 81 | for ms in ms_li: |
| 82 | hlr.subscriber_add(ms) |
| 83 | ms.connect(msc.mcc_mnc()) |
| 84 | ms.attach() |
| 85 | ms.log_info() |
| 86 | |
| 87 | print('waiting for modems to attach...') |
| 88 | for ms in ms_li: |
| 89 | wait(ms.is_connected, msc.mcc_mnc()) |
| 90 | wait(msc.subscriber_attached, *ms_li) |
| 91 | |
| 92 | print('waiting for modems to attach to data services...') |
| 93 | for ms in ms_li: |
| 94 | wait(ms.is_attached) |
| 95 | # We need to use inet46 since ofono qmi only uses ipv4v6 eua (OS#2713) |
| 96 | ctx_id_v4 = ms.activate_context(apn='inet46', protocol=ms.CTX_PROT_IPv4) |
| 97 | print("Setting up data plan for %r" % repr(ctx_id_v4)) |
| 98 | ms.setup_context_data_plane(ctx_id_v4) |
| 99 | setattr(ms, 'tmp_ctx_id', ctx_id_v4) |
| 100 | |
| 101 | run_iperf3_cli_parallel(clients, ms_li) |
| 102 | |
| 103 | for i in range(num_ms): |
| 104 | servers[i].stop() |
| 105 | print("Results for %s through %r" % (str(servers[i]), repr(ms_li[i].tmp_ctx_id))) |
| 106 | print_results(clients[i].get_results(), servers[i].get_results()) |
| 107 | |
| 108 | for ms in ms_li: |
| 109 | ms.deactivate_context(ms.tmp_ctx_id) |
| 110 | delattr(ms, 'tmp_ctx_id') |