osmo-gsm-tester/sysmocom/suites/nitb_debug/interactive.py

112 lines
3.3 KiB
Python
Raw Normal View History

#!/usr/bin/env python3
from osmo_gsm_tester.testenv import *
print('use resources...')
nitb = suite.nitb()
bts = suite.bts()
modems = suite.modems(int(prompt('How many modems?')))
print('start nitb and bts...')
nitb.bts_add(bts)
nitb.start()
bts.start()
wait(nitb.bts_is_connected, bts)
for m in modems:
nitb.subscriber_add(m)
m.connect(nitb.mcc_mnc())
while True:
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>')
cmd = cmd.strip().lower()
if not cmd:
continue
params = cmd.split()
if 'quit'.startswith(cmd):
break
elif 'wait-registered'.startswith(cmd):
try:
ofono_client: Implement network registration during connect() A new mcc_mnc parameter is now optionally passed to connect() in order to manually register to a specific network with a given MCC+MNC pair. If no parameter is passed (or None), then the modem will be instructed to attempt an automatic registration with any available network which permits it. We get the MCC+MNC parameter from the MSC/NITB and we pass it to the modem object at connect time as shown in the modified tests. Two new simple tests to check network registration is working are added in this commit. Ofono modems seem to be automatically registering at some point after they are set Online=true, and we were actually using that 'feature' before this patch. Thus, it is possible that a modem quickly becomes registered, and we then check so before starting the scan+registration process, which can take a few seconds. The scanning method can take a few seconds to complete. To avoid blocking in the dbus ofono Scan() method, this commit adds some code to make use of glib/gdbus async methods, which are not yet supported directly by pydbus. This way, we can continue polling while waiting for the scan process to complete and we can register several modems in parallel. When scan completes, a callback is run which attempts to register. If no MCC+MNC was passed, as we just finished scanning the modem should have enough fresh operator information to take good and quick decisions on where to connect. If we have an MCC+MNC, then we check the operator list received by Scan() method. If operator with desired MCC+MNC is there, we register with it. If it's not there, we start scanning() again asynchronously hoping the operator will show up in next scan. As scanning() and registration is done in the background, tests are expected to call connect(), and then later on wait for the modem to register by waiting/polling the method "modem.is_connected()". Tests first check for the modem being connected and after with MSC subscriber_attached(). The order is intentional because the later has to poll through network and adds unneeded garbage to the pcap files bein recorded. Change-Id: I8d9eb47eac1044550d3885adb55105c304b0c15c
2017-05-29 12:25:22 +00:00
for m in modems:
wait(m.is_connected, nitb.mcc_mnc())
wait(nitb.subscriber_attached, *modems)
except Timeout:
print('Timeout while waiting for registration.')
elif 'get-registered'.startswith(cmd):
print(nitb.imsi_list_attached())
print('RESULT: %s' %
('All modems are registered.' if nitb.subscriber_attached(*modems)
else 'Some modem(s) not registered yet.'))
elif 'sms'.startswith(cmd):
for mo in modems:
for mt in modems:
mo.sms_send(mt.msisdn, 'to ' + mt.name())
elif cmd.startswith('call-list'):
if len(params) != 1 and len(params) != 2:
print('wrong format')
continue
for ms in modems:
if len(params) == 1 or str(ms.msisdn) == params[1]:
print('call-list: %r %r' % (ms.name(), ms.call_id_list()))
elif cmd.startswith('call-dial'):
if len(params) != 3:
print('wrong format')
continue
src_msisdn, dst_msisdn = params[1:]
for mo in modems:
if str(mo.msisdn) == src_msisdn:
print('dialing %s->%s' % (src_msisdn, dst_msisdn))
call_id = mo.call_dial(dst_msisdn)
print('dial success: call_id=%r' % call_id)
elif cmd.startswith('call-wait-incoming'):
if len(params) != 3:
print('wrong format')
continue
src_msisdn, dst_msisdn = params[1:]
for mt in modems:
if str(mt.msisdn) == dst_msisdn:
print('waiting for incoming %s->%s' % (src_msisdn, dst_msisdn))
call_id = mt.call_wait_incoming(src_msisdn)
print('incoming call success: call_id=%r' % call_id)
elif cmd.startswith('call-answer'):
if len(params) != 3:
print('wrong format')
continue
mt_msisdn, call_id = params[1:]
for mt in modems:
if str(mt.msisdn) == mt_msisdn:
print('answering %s %r' % (mt.name(), call_id))
mt.call_answer(call_id)
elif cmd.startswith('call-hangup'):
if len(params) != 3:
print('wrong format')
continue
ms_msisdn, call_id = params[1:]
for ms in modems:
if str(ms.msisdn) == ms_msisdn:
print('hanging up %s %r' % (ms.name(), call_id))
ms.call_hangup(call_id)
elif cmd.startswith('ussd'):
if len(params) != 2:
print('wrong format')
continue
ussd_cmd = params[1]
for ms in modems:
print('modem %s: ussd %s' % (ms.name(), ussd_cmd))
response = ms.ussd_send(ussd_cmd)
print('modem %s: response=%r' % (ms.name(), response))
else:
print('Unknown command: %s' % cmd)