Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Pau Espin Pedrol | dfe38ad | 2017-11-09 13:57:39 +0100 | [diff] [blame] | 2 | from osmo_gsm_tester.testenv import * |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 3 | hlr = suite.hlr() |
| 4 | bts = suite.bts() |
Pau Espin Pedrol | a5ed18a | 2017-11-23 11:03:07 +0100 | [diff] [blame] | 5 | pcu = bts.pcu() |
Pau Espin Pedrol | 86ea02f | 2018-02-26 12:14:46 +0100 | [diff] [blame] | 6 | mgw_msc = suite.mgw() |
Pau Espin Pedrol | 386b78d | 2017-11-09 13:02:09 +0100 | [diff] [blame] | 7 | mgw_bsc = suite.mgw() |
Neels Hofmeyr | 38b051c | 2017-06-13 16:26:06 +0200 | [diff] [blame] | 8 | stp = suite.stp() |
Pau Espin Pedrol | a5ed18a | 2017-11-23 11:03:07 +0100 | [diff] [blame] | 9 | ggsn = suite.ggsn() |
| 10 | sgsn = suite.sgsn(hlr, ggsn) |
Pau Espin Pedrol | 86ea02f | 2018-02-26 12:14:46 +0100 | [diff] [blame] | 11 | msc = suite.msc(hlr, mgw_msc, stp) |
Pau Espin Pedrol | 1e1d381 | 2017-11-16 18:06:37 +0100 | [diff] [blame] | 12 | bsc = suite.bsc(msc, mgw_bsc, stp) |
Pau Espin Pedrol | a5ed18a | 2017-11-23 11:03:07 +0100 | [diff] [blame] | 13 | |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 14 | modems = suite.modems(int(prompt('How many modems?'))) |
| 15 | |
Pau Espin Pedrol | a5ed18a | 2017-11-23 11:03:07 +0100 | [diff] [blame] | 16 | bsc.bts_add(bts) |
| 17 | sgsn.bts_add(bts) |
| 18 | |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 19 | hlr.start() |
Neels Hofmeyr | 38b051c | 2017-06-13 16:26:06 +0200 | [diff] [blame] | 20 | stp.start() |
Pau Espin Pedrol | a5ed18a | 2017-11-23 11:03:07 +0100 | [diff] [blame] | 21 | ggsn.start() |
| 22 | sgsn.start() |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 23 | msc.start() |
Pau Espin Pedrol | 86ea02f | 2018-02-26 12:14:46 +0100 | [diff] [blame] | 24 | mgw_msc.start() |
Pau Espin Pedrol | 386b78d | 2017-11-09 13:02:09 +0100 | [diff] [blame] | 25 | mgw_bsc.start() |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 26 | bsc.start() |
| 27 | |
| 28 | bts.start() |
Pau Espin Pedrol | 1e19151 | 2017-12-11 15:12:55 +0100 | [diff] [blame] | 29 | print('Waiting for bts to connect to bsc...') |
| 30 | wait(bsc.bts_is_connected, bts) |
Pau Espin Pedrol | a5ed18a | 2017-11-23 11:03:07 +0100 | [diff] [blame] | 31 | print('Waiting for bts to be ready...') |
| 32 | wait(bts.ready_for_pcu) |
| 33 | pcu.start() |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 34 | |
| 35 | for m in modems: |
| 36 | hlr.subscriber_add(m) |
Pau Espin Pedrol | 0e57aad | 2017-05-29 14:25:22 +0200 | [diff] [blame] | 37 | m.connect(msc.mcc_mnc()) |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 38 | |
| 39 | while True: |
Pau Espin Pedrol | a5ed18a | 2017-11-23 11:03:07 +0100 | [diff] [blame] | 40 | cmd = prompt('Enter command: (q)uit (s)ms (g)et-registered (w)ait-registered, call-list [<ms_msisdn>], call-dial <src_msisdn> <dst_msisdn>, call-wait-incoming <src_msisdn> <dst_msisdn>, call-answer <mt_msisdn> <call_id>, call-hangup <ms_msisdn> <call_id>, ussd <command>, data-attach, data-wait, data-detach, data-activate') |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 41 | cmd = cmd.strip().lower() |
| 42 | |
| 43 | if not cmd: |
| 44 | continue |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 45 | |
| 46 | params = cmd.split() |
| 47 | |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 48 | if 'quit'.startswith(cmd): |
| 49 | break |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 50 | |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 51 | elif 'wait-registered'.startswith(cmd): |
| 52 | try: |
Pau Espin Pedrol | 0e57aad | 2017-05-29 14:25:22 +0200 | [diff] [blame] | 53 | for m in modems: |
| 54 | wait(m.is_connected, msc.mcc_mnc()) |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 55 | wait(msc.subscriber_attached, *modems) |
| 56 | except Timeout: |
| 57 | print('Timeout while waiting for registration.') |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 58 | |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 59 | elif 'get-registered'.startswith(cmd): |
| 60 | print(msc.imsi_list_attached()) |
| 61 | print('RESULT: %s' % |
| 62 | ('All modems are registered.' if msc.subscriber_attached(*modems) |
| 63 | else 'Some modem(s) not registered yet.')) |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 64 | |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 65 | elif 'sms'.startswith(cmd): |
| 66 | for mo in modems: |
| 67 | for mt in modems: |
| 68 | mo.sms_send(mt.msisdn, 'to ' + mt.name()) |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 69 | |
| 70 | elif cmd.startswith('call-list'): |
| 71 | if len(params) != 1 and len(params) != 2: |
| 72 | print('wrong format') |
| 73 | continue |
| 74 | for ms in modems: |
| 75 | if len(params) == 1 or str(ms.msisdn) == params[1]: |
| 76 | print('call-list: %r %r' % (ms.name(), ms.call_id_list())) |
| 77 | |
| 78 | elif cmd.startswith('call-dial'): |
| 79 | if len(params) != 3: |
| 80 | print('wrong format') |
| 81 | continue |
| 82 | src_msisdn, dst_msisdn = params[1:] |
| 83 | for mo in modems: |
| 84 | if str(mo.msisdn) == src_msisdn: |
| 85 | print('dialing %s->%s' % (src_msisdn, dst_msisdn)) |
| 86 | call_id = mo.call_dial(dst_msisdn) |
| 87 | print('dial success: call_id=%r' % call_id) |
| 88 | |
| 89 | elif cmd.startswith('call-wait-incoming'): |
| 90 | if len(params) != 3: |
| 91 | print('wrong format') |
| 92 | continue |
| 93 | src_msisdn, dst_msisdn = params[1:] |
| 94 | for mt in modems: |
| 95 | if str(mt.msisdn) == dst_msisdn: |
| 96 | print('waiting for incoming %s->%s' % (src_msisdn, dst_msisdn)) |
| 97 | call_id = mt.call_wait_incoming(src_msisdn) |
| 98 | print('incoming call success: call_id=%r' % call_id) |
| 99 | |
| 100 | elif cmd.startswith('call-answer'): |
| 101 | if len(params) != 3: |
| 102 | print('wrong format') |
| 103 | continue |
| 104 | mt_msisdn, call_id = params[1:] |
| 105 | for mt in modems: |
| 106 | if str(mt.msisdn) == mt_msisdn: |
| 107 | print('answering %s %r' % (mt.name(), call_id)) |
| 108 | mt.call_answer(call_id) |
| 109 | |
| 110 | elif cmd.startswith('call-hangup'): |
| 111 | if len(params) != 3: |
| 112 | print('wrong format') |
| 113 | continue |
| 114 | ms_msisdn, call_id = params[1:] |
| 115 | for ms in modems: |
| 116 | if str(ms.msisdn) == ms_msisdn: |
| 117 | print('hanging up %s %r' % (ms.name(), call_id)) |
| 118 | ms.call_hangup(call_id) |
| 119 | |
Pau Espin Pedrol | d27de2b | 2017-11-06 17:42:41 +0100 | [diff] [blame] | 120 | elif cmd.startswith('ussd'): |
| 121 | if len(params) != 2: |
| 122 | print('wrong format') |
| 123 | continue |
| 124 | ussd_cmd = params[1] |
| 125 | for ms in modems: |
| 126 | print('modem %s: ussd %s' % (ms.name(), ussd_cmd)) |
| 127 | response = ms.ussd_send(ussd_cmd) |
| 128 | print('modem %s: response=%r' % (ms.name(), response)) |
| 129 | |
Pau Espin Pedrol | a5ed18a | 2017-11-23 11:03:07 +0100 | [diff] [blame] | 130 | elif cmd.startswith('data-attach'): |
| 131 | if len(params) != 1: |
| 132 | print('wrong format') |
| 133 | continue |
| 134 | for ms in modems: |
| 135 | print('modem %s: attach' % ms.name()) |
| 136 | ms.attach() |
| 137 | wait(ms.is_attached) |
| 138 | print('modem %s: attached' % ms.name()) |
| 139 | |
| 140 | elif cmd.startswith('data-detach'): |
| 141 | if len(params) != 1: |
| 142 | print('wrong format') |
| 143 | continue |
| 144 | for ms in modems: |
| 145 | print('modem %s: detach' % ms.name()) |
| 146 | ms.attach() |
| 147 | wait(lambda: not ms.is_attached()) |
| 148 | print('modem %s: detached' % ms.name()) |
| 149 | |
| 150 | elif cmd.startswith('data-activate'): |
| 151 | if len(params) != 1: |
| 152 | print('wrong format') |
| 153 | continue |
| 154 | for ms in modems: |
| 155 | print('modem %s: activate' % ms.name()) |
| 156 | response = ms.activate_context() |
| 157 | print('modem %s: response=%r' % (ms.name(), response)) |
| 158 | |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 159 | else: |
| 160 | print('Unknown command: %s' % cmd) |