Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
| 2 | from osmo_gsm_tester.test import * |
| 3 | hlr = suite.hlr() |
| 4 | bts = suite.bts() |
| 5 | mgcpgw = suite.mgcpgw(bts_ip=bts.remote_addr()) |
| 6 | msc = suite.msc(hlr, mgcpgw) |
| 7 | bsc = suite.bsc(msc) |
Neels Hofmeyr | 38b051c | 2017-06-13 16:26:06 +0200 | [diff] [blame] | 8 | stp = suite.stp() |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 9 | modems = suite.modems(int(prompt('How many modems?'))) |
| 10 | |
| 11 | hlr.start() |
Neels Hofmeyr | 38b051c | 2017-06-13 16:26:06 +0200 | [diff] [blame] | 12 | stp.start() |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 13 | msc.start() |
Pau Espin Pedrol | 1ba2ded | 2017-05-30 16:39:44 +0200 | [diff] [blame] | 14 | mgcpgw.start() |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 15 | |
| 16 | bsc.bts_add(bts) |
| 17 | bsc.start() |
| 18 | |
| 19 | bts.start() |
| 20 | |
| 21 | for m in modems: |
| 22 | hlr.subscriber_add(m) |
Pau Espin Pedrol | 0e57aad | 2017-05-29 14:25:22 +0200 | [diff] [blame] | 23 | m.connect(msc.mcc_mnc()) |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 24 | |
| 25 | while True: |
Pau Espin Pedrol | d27de2b | 2017-11-06 17:42:41 +0100 | [diff] [blame] | 26 | 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>') |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 27 | cmd = cmd.strip().lower() |
| 28 | |
| 29 | if not cmd: |
| 30 | continue |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 31 | |
| 32 | params = cmd.split() |
| 33 | |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 34 | if 'quit'.startswith(cmd): |
| 35 | break |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 36 | |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 37 | elif 'wait-registered'.startswith(cmd): |
| 38 | try: |
Pau Espin Pedrol | 0e57aad | 2017-05-29 14:25:22 +0200 | [diff] [blame] | 39 | for m in modems: |
| 40 | wait(m.is_connected, msc.mcc_mnc()) |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 41 | wait(msc.subscriber_attached, *modems) |
| 42 | except Timeout: |
| 43 | print('Timeout while waiting for registration.') |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 44 | |
Neels Hofmeyr | aea2f2c | 2017-05-18 22:01:59 +0200 | [diff] [blame] | 45 | elif 'get-registered'.startswith(cmd): |
| 46 | print(msc.imsi_list_attached()) |
| 47 | print('RESULT: %s' % |
| 48 | ('All modems are registered.' if msc.subscriber_attached(*modems) |
| 49 | else 'Some modem(s) not registered yet.')) |
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 'sms'.startswith(cmd): |
| 52 | for mo in modems: |
| 53 | for mt in modems: |
| 54 | mo.sms_send(mt.msisdn, 'to ' + mt.name()) |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 55 | |
| 56 | elif cmd.startswith('call-list'): |
| 57 | if len(params) != 1 and len(params) != 2: |
| 58 | print('wrong format') |
| 59 | continue |
| 60 | for ms in modems: |
| 61 | if len(params) == 1 or str(ms.msisdn) == params[1]: |
| 62 | print('call-list: %r %r' % (ms.name(), ms.call_id_list())) |
| 63 | |
| 64 | elif cmd.startswith('call-dial'): |
| 65 | if len(params) != 3: |
| 66 | print('wrong format') |
| 67 | continue |
| 68 | src_msisdn, dst_msisdn = params[1:] |
| 69 | for mo in modems: |
| 70 | if str(mo.msisdn) == src_msisdn: |
| 71 | print('dialing %s->%s' % (src_msisdn, dst_msisdn)) |
| 72 | call_id = mo.call_dial(dst_msisdn) |
| 73 | print('dial success: call_id=%r' % call_id) |
| 74 | |
| 75 | elif cmd.startswith('call-wait-incoming'): |
| 76 | if len(params) != 3: |
| 77 | print('wrong format') |
| 78 | continue |
| 79 | src_msisdn, dst_msisdn = params[1:] |
| 80 | for mt in modems: |
| 81 | if str(mt.msisdn) == dst_msisdn: |
| 82 | print('waiting for incoming %s->%s' % (src_msisdn, dst_msisdn)) |
| 83 | call_id = mt.call_wait_incoming(src_msisdn) |
| 84 | print('incoming call success: call_id=%r' % call_id) |
| 85 | |
| 86 | elif cmd.startswith('call-answer'): |
| 87 | if len(params) != 3: |
| 88 | print('wrong format') |
| 89 | continue |
| 90 | mt_msisdn, call_id = params[1:] |
| 91 | for mt in modems: |
| 92 | if str(mt.msisdn) == mt_msisdn: |
| 93 | print('answering %s %r' % (mt.name(), call_id)) |
| 94 | mt.call_answer(call_id) |
| 95 | |
| 96 | elif cmd.startswith('call-hangup'): |
| 97 | if len(params) != 3: |
| 98 | print('wrong format') |
| 99 | continue |
| 100 | ms_msisdn, call_id = params[1:] |
| 101 | for ms in modems: |
| 102 | if str(ms.msisdn) == ms_msisdn: |
| 103 | print('hanging up %s %r' % (ms.name(), call_id)) |
| 104 | ms.call_hangup(call_id) |
| 105 | |
Pau Espin Pedrol | d27de2b | 2017-11-06 17:42:41 +0100 | [diff] [blame] | 106 | elif cmd.startswith('ussd'): |
| 107 | if len(params) != 2: |
| 108 | print('wrong format') |
| 109 | continue |
| 110 | ussd_cmd = params[1] |
| 111 | for ms in modems: |
| 112 | print('modem %s: ussd %s' % (ms.name(), ussd_cmd)) |
| 113 | response = ms.ussd_send(ussd_cmd) |
| 114 | print('modem %s: response=%r' % (ms.name(), response)) |
| 115 | |
Pau Espin Pedrol | 4897e7a | 2017-10-06 18:41:20 +0200 | [diff] [blame] | 116 | else: |
| 117 | print('Unknown command: %s' % cmd) |