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 | |
Pau Espin Pedrol | ffe1b08 | 2018-12-05 17:46:21 +0100 | [diff] [blame] | 14 | def run_iperf3_cli_parallel(iperf3clients, ms_li, ready_cb): |
Pau Espin Pedrol | 0fc7437 | 2018-11-14 16:44:57 +0100 | [diff] [blame] | 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() |
Pau Espin Pedrol | ffe1b08 | 2018-12-05 17:46:21 +0100 | [diff] [blame] | 23 | if ready_cb: |
| 24 | ready_cb(ms_li) |
Pau Espin Pedrol | 0fc7437 | 2018-11-14 16:44:57 +0100 | [diff] [blame] | 25 | for proc in procs: |
| 26 | proc.wait() |
| 27 | except Exception as e: |
| 28 | for proc in procs: |
Pau Espin Pedrol | a353457 | 2019-04-05 12:44:57 +0200 | [diff] [blame] | 29 | try: |
| 30 | proc.terminate() |
| 31 | except Exception: |
| 32 | print("Exception while terminating process %r" % repr(process)) |
Pau Espin Pedrol | 0fc7437 | 2018-11-14 16:44:57 +0100 | [diff] [blame] | 33 | raise e |
| 34 | |
| 35 | |
Pau Espin Pedrol | ffe1b08 | 2018-12-05 17:46:21 +0100 | [diff] [blame] | 36 | def setup_run_iperf3_test_parallel(num_ms, ready_cb=None): |
Pau Espin Pedrol | 0fc7437 | 2018-11-14 16:44:57 +0100 | [diff] [blame] | 37 | hlr = suite.hlr() |
| 38 | bts = suite.bts() |
| 39 | pcu = bts.pcu() |
| 40 | mgw_msc = suite.mgw() |
| 41 | mgw_bsc = suite.mgw() |
| 42 | stp = suite.stp() |
| 43 | ggsn = suite.ggsn() |
| 44 | sgsn = suite.sgsn(hlr, ggsn) |
| 45 | msc = suite.msc(hlr, mgw_msc, stp) |
| 46 | bsc = suite.bsc(msc, mgw_bsc, stp) |
| 47 | |
| 48 | iperf3srv_addr = suite.ip_address() |
| 49 | servers = [] |
| 50 | clients = [] |
| 51 | ms_li = [] |
| 52 | for i in range(num_ms): |
| 53 | iperf3srv = suite.iperf3srv(iperf3srv_addr) |
| 54 | iperf3srv.set_port(iperf3srv.DEFAULT_SRV_PORT + i) |
| 55 | servers.append(iperf3srv) |
| 56 | |
| 57 | iperf3cli = iperf3srv.create_client() |
| 58 | clients.append(iperf3cli) |
| 59 | |
| 60 | ms = suite.modem() |
| 61 | ms_li.append(ms) |
| 62 | |
| 63 | bsc.bts_add(bts) |
| 64 | sgsn.bts_add(bts) |
| 65 | |
| 66 | for iperf3srv in servers: |
| 67 | print('start iperfv3 server %s...' % str(iperf3srv) ) |
| 68 | iperf3srv.start() |
| 69 | |
| 70 | print('start network...') |
| 71 | hlr.start() |
| 72 | stp.start() |
| 73 | ggsn.start() |
| 74 | sgsn.start() |
| 75 | msc.start() |
| 76 | mgw_msc.start() |
| 77 | mgw_bsc.start() |
| 78 | bsc.start() |
| 79 | |
| 80 | bts.start() |
| 81 | wait(bsc.bts_is_connected, bts) |
| 82 | print('Waiting for bts to be ready...') |
| 83 | wait(bts.ready_for_pcu) |
| 84 | pcu.start() |
| 85 | |
| 86 | for ms in ms_li: |
| 87 | hlr.subscriber_add(ms) |
| 88 | ms.connect(msc.mcc_mnc()) |
| 89 | ms.attach() |
| 90 | ms.log_info() |
| 91 | |
| 92 | print('waiting for modems to attach...') |
| 93 | for ms in ms_li: |
| 94 | wait(ms.is_connected, msc.mcc_mnc()) |
| 95 | wait(msc.subscriber_attached, *ms_li) |
| 96 | |
| 97 | print('waiting for modems to attach to data services...') |
| 98 | for ms in ms_li: |
| 99 | wait(ms.is_attached) |
| 100 | # We need to use inet46 since ofono qmi only uses ipv4v6 eua (OS#2713) |
| 101 | ctx_id_v4 = ms.activate_context(apn='inet46', protocol=ms.CTX_PROT_IPv4) |
| 102 | print("Setting up data plan for %r" % repr(ctx_id_v4)) |
| 103 | ms.setup_context_data_plane(ctx_id_v4) |
| 104 | setattr(ms, 'tmp_ctx_id', ctx_id_v4) |
| 105 | |
Pau Espin Pedrol | ffe1b08 | 2018-12-05 17:46:21 +0100 | [diff] [blame] | 106 | run_iperf3_cli_parallel(clients, ms_li, ready_cb) |
Pau Espin Pedrol | 0fc7437 | 2018-11-14 16:44:57 +0100 | [diff] [blame] | 107 | |
| 108 | for i in range(num_ms): |
| 109 | servers[i].stop() |
| 110 | print("Results for %s through %r" % (str(servers[i]), repr(ms_li[i].tmp_ctx_id))) |
| 111 | print_results(clients[i].get_results(), servers[i].get_results()) |
| 112 | |
| 113 | for ms in ms_li: |
| 114 | ms.deactivate_context(ms.tmp_ctx_id) |
| 115 | delattr(ms, 'tmp_ctx_id') |