MSC+BSC: add test api to run OsmoMSC and OsmoBSC with AoIP

Change-Id: I5842e8f1cba8e8e6bedfc08540efcafe207159cb
This commit is contained in:
Neels Hofmeyr 2017-05-18 15:24:02 +02:00
parent 52261b3f14
commit 798e592fd6
11 changed files with 643 additions and 3 deletions

View File

@ -17,6 +17,7 @@ Packages required to run the osmo-gsm-tester:
apt-get install \
dbus \
tcpdump \
sqlite3 \
python3 \
python3-yaml \
python3-mako \

View File

@ -2,8 +2,26 @@ nitb:
net:
mcc: 901
mnc: 70
short_name: osmo-gsm-tester
long_name: osmo-gsm-tester
short_name: osmo-gsm-tester-nitb
long_name: osmo-gsm-tester-nitb
auth_policy: closed
encryption: a5 0
bsc:
net:
mcc: 901
mnc: 70
short_name: osmo-gsm-tester-msc
long_name: osmo-gsm-tester-msc
auth_policy: closed
encryption: a5 0
msc:
net:
mcc: 901
mnc: 70
short_name: osmo-gsm-tester-msc
long_name: osmo-gsm-tester-msc
auth_policy: closed
encryption: a5 0

View File

@ -0,0 +1,102 @@
# osmo_gsm_tester: specifics for running an osmo-bsc
#
# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
#
# Author: Neels Hofmeyr <neels@hofmeyr.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import pprint
from . import log, util, config, template, process, osmo_ctrl, pcap_recorder
class OsmoBsc(log.Origin):
suite_run = None
ip_address = None
run_dir = None
config_file = None
process = None
bts = None
def __init__(self, suite_run, msc, ip_address):
self.suite_run = suite_run
self.ip_address = ip_address
self.set_log_category(log.C_RUN)
self.set_name('osmo-bsc_%s' % ip_address.get('addr'))
self.bts = []
self.msc = msc
def start(self):
self.log('Starting osmo-bsc')
self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name()))
self.configure()
# NOTE: While OsmoMSC and OsmoBSC live in the same git repository, the
# osmo-msc build will also provide the OsmoBSC binary. As soon as the
# repositories are separate, there shall be a separate artifact.
inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-msc')))
binary = inst.child('bin', 'osmo-bsc')
if not os.path.isfile(binary):
raise RuntimeError('Binary missing: %r' % binary)
lib = inst.child('lib')
if not os.path.isdir(lib):
raise RuntimeError('No lib/ in %r' % inst)
iface = util.ip_to_iface(self.addr())
pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), iface,
'host %s and port not 22' % self.addr())
env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
self.dbg(run_dir=self.run_dir, binary=binary, env=env)
self.process = process.Process(self.name(), self.run_dir,
(binary, '-c',
os.path.abspath(self.config_file)),
env=env)
self.suite_run.remember_to_stop(self.process)
self.process.launch()
def configure(self):
self.config_file = self.run_dir.new_file('osmo-bsc.cfg')
self.dbg(config_file=self.config_file)
values = dict(bsc=config.get_defaults('bsc'))
config.overlay(values, self.suite_run.config())
config.overlay(values, dict(bsc=dict(ip_address=self.ip_address)))
bts_list = []
for bts in self.bts:
bts_list.append(bts.conf_for_bsc())
config.overlay(values, dict(bsc=dict(net=dict(bts_list=bts_list))))
self.dbg('BSC CONFIG:\n' + pprint.pformat(values))
with open(self.config_file, 'w') as f:
r = template.render('osmo-bsc.cfg', values)
self.dbg(r)
f.write(r)
def addr(self):
return self.ip_address.get('addr')
def bts_add(self, bts):
self.bts.append(bts)
bts.set_bsc(self)
def running(self):
return not self.process.terminated()
# vim: expandtab tabstop=4 shiftwidth=4

View File

@ -0,0 +1,129 @@
# osmo_gsm_tester: specifics for running an osmo-hlr
#
# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
#
# Author: Neels Hofmeyr <neels@hofmeyr.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import re
import pprint
from . import log, util, config, template, process, osmo_ctrl, pcap_recorder
class OsmoHlr(log.Origin):
suite_run = None
ip_address = None
run_dir = None
config_file = None
process = None
next_subscriber_id = 1
def __init__(self, suite_run, ip_address):
self.suite_run = suite_run
self.ip_address = ip_address
self.set_log_category(log.C_RUN)
self.set_name('osmo-hlr_%s' % ip_address.get('addr'))
self.bts = []
def start(self):
self.log('Starting osmo-hlr')
self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name()))
self.configure()
inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-hlr')))
binary = inst.child('bin', 'osmo-hlr')
if not os.path.isfile(binary):
self.raise_exn('Binary missing:', binary)
lib = inst.child('lib')
if not os.path.isdir(lib):
self.raise_exn('No lib/ in', inst)
# bootstrap an empty hlr.db
self.db_file = self.run_dir.new_file('hlr.db')
sql_input = inst.child('share/doc/osmo-hlr/hlr.sql')
if not os.path.isfile(sql_input):
self.raise_exn('hlr.sql missing:', sql_input)
self.run_local('create_hlr_db', ('/bin/sh', '-c', 'sqlite3 %r < %r' % (self.db_file, sql_input)))
iface = util.ip_to_iface(self.addr())
pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), iface,
'host %s' % self.addr())
env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
self.dbg(run_dir=self.run_dir, binary=binary, env=env)
self.process = process.Process(self.name(), self.run_dir,
(binary,
'-c', os.path.abspath(self.config_file),
'--database', self.db_file),
env=env)
self.suite_run.remember_to_stop(self.process)
self.process.launch()
def configure(self):
self.config_file = self.run_dir.new_file('osmo-hlr.cfg')
self.dbg(config_file=self.config_file)
values = dict(hlr=config.get_defaults('hlr'))
config.overlay(values, self.suite_run.config())
config.overlay(values, dict(hlr=dict(ip_address=self.ip_address)))
self.dbg('HLR CONFIG:\n' + pprint.pformat(values))
with open(self.config_file, 'w') as f:
r = template.render('osmo-hlr.cfg', values)
self.dbg(r)
f.write(r)
def addr(self):
return self.ip_address.get('addr')
def running(self):
return not self.process.terminated()
def run_local(self, name, popen_args):
with self:
run_dir = self.run_dir.new_dir(name)
proc = process.Process(name, run_dir, popen_args)
proc.launch()
proc.wait()
if proc.result != 0:
proc.raise_exn('Exited in error')
def run_sql_file(self, name, sql_file):
self.run_local(name, ('/bin/sh', '-c', 'sqlite3 %r < %r' % (self.db_file, sql_file)))
def run_sql(self, name, sql):
self.dbg('SQL:', repr(sql))
sql_file = self.run_dir.new_file(name + '.sql')
with open(sql_file, 'w') as f:
f.write(sql)
self.run_sql_file(name, sql_file)
def subscriber_add(self, modem, msisdn=None):
if msisdn is None:
msisdn = self.suite_run.resources_pool.next_msisdn(modem)
modem.set_msisdn(msisdn)
subscriber_id = self.next_subscriber_id
self.next_subscriber_id += 1
self.log('Add subscriber', msisdn=msisdn, imsi=modem.imsi(), subscriber_id=subscriber_id)
self.run_sql('add_subscriber',
'insert into subscriber (id, imsi, msisdn) values (%r, %r, %r);'
% (subscriber_id, modem.imsi(), modem.msisdn))
return subscriber_id
# vim: expandtab tabstop=4 shiftwidth=4

View File

@ -0,0 +1,90 @@
# osmo_gsm_tester: specifics for running an osmo-mgcp-gw (osmo-bsc_mgcp)
#
# Copyright (C) 2017 by sysmocom - s.f.m.c. GmbH
#
# Author: Neels Hofmeyr <neels@hofmeyr.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import pprint
from . import log, util, config, template, process, osmo_ctrl, pcap_recorder
class OsmoMgcpgw(log.Origin):
suite_run = None
ip_address = None
run_dir = None
config_file = None
process = None
def __init__(self, suite_run, ip_address, bts_ip):
self.suite_run = suite_run
self.ip_address = ip_address
self.set_log_category(log.C_RUN)
self.set_name('osmo-mgcpgw_%s' % ip_address.get('addr'))
# hack: so far mgcpgw needs one specific BTS IP.
self.bts_ip = bts_ip
def start(self):
self.log('Starting osmo-mgcpgw')
self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name()))
self.configure()
inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-msc')))
binary = inst.child('bin', 'osmo-bsc_mgcp')
if not os.path.isfile(binary):
raise RuntimeError('Binary missing: %r' % binary)
lib = inst.child('lib')
if not os.path.isdir(lib):
raise RuntimeError('No lib/ in %r' % inst)
iface = util.ip_to_iface(self.addr())
pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), iface,
'host %s and port not 22' % self.addr())
env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
self.dbg(run_dir=self.run_dir, binary=binary, env=env)
self.process = process.Process(self.name(), self.run_dir,
(binary, '-c',
os.path.abspath(self.config_file)),
env=env)
self.suite_run.remember_to_stop(self.process)
self.process.launch()
def configure(self):
self.config_file = self.run_dir.new_file('osmo-mgcpgw.cfg')
self.dbg(config_file=self.config_file)
values = dict(mgcpgw=config.get_defaults('mgcpgw'))
config.overlay(values, self.suite_run.config())
config.overlay(values, dict(mgcpgw=dict(ip_address=self.ip_address, bts_ip=self.bts_ip)))
self.dbg('MGCPGW CONFIG:\n' + pprint.pformat(values))
with open(self.config_file, 'w') as f:
r = template.render('osmo-mgcpgw.cfg', values)
self.dbg(r)
f.write(r)
def addr(self):
return self.ip_address.get('addr')
def conf_for_msc(self):
return dict(mgcpgw=dict(ip_address=self.ip_address))
def running(self):
return not self.process.terminated()
# vim: expandtab tabstop=4 shiftwidth=4

View File

@ -0,0 +1,128 @@
# osmo_gsm_tester: specifics for running an osmo-msc
#
# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
#
# Author: Neels Hofmeyr <neels@hofmeyr.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
import pprint
from . import log, util, config, template, process, osmo_ctrl, pcap_recorder
class OsmoMsc(log.Origin):
suite_run = None
ip_address = None
run_dir = None
config_file = None
process = None
hlr = None
def __init__(self, suite_run, hlr, mgcpgw, ip_address):
self.suite_run = suite_run
self.ip_address = ip_address
self.set_log_category(log.C_RUN)
self.set_name('osmo-msc_%s' % ip_address.get('addr'))
self.hlr = hlr
self.mgcpgw = mgcpgw
def start(self):
self.log('Starting osmo-msc')
self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name()))
self.configure()
inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-msc')))
binary = inst.child('bin', 'osmo-msc')
if not os.path.isfile(binary):
raise RuntimeError('Binary missing: %r' % binary)
lib = inst.child('lib')
if not os.path.isdir(lib):
raise RuntimeError('No lib/ in %r' % inst)
iface = util.ip_to_iface(self.addr())
pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), iface,
'host %s and port not 22' % self.addr())
env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
self.dbg(run_dir=self.run_dir, binary=binary, env=env)
self.process = process.Process(self.name(), self.run_dir,
(binary, '-c',
os.path.abspath(self.config_file)),
env=env)
self.suite_run.remember_to_stop(self.process)
self.process.launch()
def configure(self):
self.config_file = self.run_dir.new_file('osmo-msc.cfg')
self.dbg(config_file=self.config_file)
values = dict(msc=config.get_defaults('msc'))
config.overlay(values, self.suite_run.config())
config.overlay(values, dict(msc=dict(ip_address=self.ip_address)))
config.overlay(values, self.mgcpgw.conf_for_msc())
self.dbg('MSC CONFIG:\n' + pprint.pformat(values))
with open(self.config_file, 'w') as f:
r = template.render('osmo-msc.cfg', values)
self.dbg(r)
f.write(r)
def addr(self):
return self.ip_address.get('addr')
def subscriber_attached(self, *modems):
return self.imsi_attached(*[m.imsi() for m in modems])
def imsi_attached(self, *imsis):
attached = self.imsi_list_attached()
self.dbg('attached:', attached)
return all([(imsi in attached) for imsi in imsis])
def imsi_list_attached(self):
with self:
return OsmoMscCtrl(self).subscriber_list_active()
def running(self):
return not self.process.terminated()
class OsmoMscCtrl(log.Origin):
PORT = 4255
SUBSCR_LIST_ACTIVE_VAR = 'subscriber-list-active-v1'
def __init__(self, msc):
self.msc = msc
self.set_name('CTRL(%s:%d)' % (self.msc.addr(), self.PORT))
self.set_child_of(msc)
def ctrl(self):
return osmo_ctrl.OsmoCtrl(self.msc.addr(), self.PORT)
def subscriber_list_active(self):
aslist_str = ""
with self.ctrl() as ctrl:
ctrl.do_get(self.SUBSCR_LIST_ACTIVE_VAR)
# This is legacy code from the old osmo-gsm-tester.
# looks like this doesn't work for long data.
data = ctrl.receive()
while (len(data) > 0):
(answer, data) = ctrl.remove_ipa_ctrl_header(data)
answer_str = answer.decode('utf-8')
answer_str = answer_str.replace('\n', ' ')
aslist_str = answer_str
return aslist_str
# vim: expandtab tabstop=4 shiftwidth=4

View File

@ -23,7 +23,9 @@ import time
import copy
import traceback
import pprint
from . import config, log, template, util, resource, schema, ofono_client, osmo_nitb, event_loop
from . import config, log, template, util, resource, schema, ofono_client, event_loop
from . import osmo_nitb
from . import osmo_hlr, osmo_mgcpgw, osmo_msc, osmo_bsc
from . import test
class Timeout(Exception):
@ -274,6 +276,26 @@ class SuiteRun(log.Origin):
ip_address = self.ip_address()
return osmo_nitb.OsmoNitb(self, ip_address)
def hlr(self, ip_address=None):
if ip_address is None:
ip_address = self.ip_address()
return osmo_hlr.OsmoHlr(self, ip_address)
def mgcpgw(self, ip_address=None, bts_ip=None):
if ip_address is None:
ip_address = self.ip_address()
return osmo_mgcpgw.OsmoMgcpgw(self, ip_address, bts_ip)
def msc(self, hlr, mgcpgw, ip_address=None):
if ip_address is None:
ip_address = self.ip_address()
return osmo_msc.OsmoMsc(self, hlr, mgcpgw, ip_address)
def bsc(self, msc, ip_address=None):
if ip_address is None:
ip_address = self.ip_address()
return osmo_bsc.OsmoBsc(self, msc, ip_address)
def bts(self):
return bts_obj(self, self.reserved_resources.get(resource.R_BTS))

View File

@ -0,0 +1,90 @@
! Configuration rendered by osmo-gsm-tester
log stderr
logging filter all 1
logging color 1
logging print category 1
logging print extended-timestamp 1
logging level all debug
line vty
no login
bind ${bsc.ip_address.addr}
e1_input
e1_line 0 driver ipa
ipa bind ${bsc.ip_address.addr}
network
network country code ${bsc.net.mcc}
mobile network code ${bsc.net.mnc}
short name ${bsc.net.short_name}
long name ${bsc.net.long_name}
auth policy ${bsc.net.auth_policy}
location updating reject cause 13
encryption ${bsc.net.encryption}
neci 1
rrlp mode none
mm info 1
handover 0
handover window rxlev averaging 10
handover window rxqual averaging 1
handover window rxlev neighbor averaging 10
handover power budget interval 6
handover power budget hysteresis 3
handover maximum distance 9999
timer t3101 10
timer t3103 0
timer t3105 0
timer t3107 0
timer t3109 4
timer t3111 0
timer t3113 60
timer t3115 0
timer t3117 0
timer t3119 0
timer t3141 0
%for bts in bsc.net.bts_list:
bts ${loop.index}
type ${bts.osmobsc_bts_type}
band ${bts.band}
cell_identity 0
location_area_code ${bts.location_area_code}
training_sequence_code 7
base_station_id_code ${bts.base_station_id_code}
ms max power 33
cell reselection hysteresis 4
rxlev access min 0
channel allocator ascending
rach tx integer 9
rach max transmission 7
ip.access unit_id ${bts.ipa_unit_id} 0
oml ip.access stream_id ${bts.stream_id} line 0
gprs mode none
% for trx in bts.trx_list:
trx ${loop.index}
rf_locked 0
arfcn ${trx.arfcn}
nominal power 23
max_power_red ${trx.max_power_red}
rsl e1 tei 0
% for ts in trx.timeslot_list:
timeslot ${loop.index}
phys_chan_config ${ts.phys_chan_config}
% endfor
% endfor
%endfor
msc
token msc_token_23_42
core-mobile-country-code ${bsc.net.mcc}
core-mobile-network-code ${bsc.net.mnc}
ip.access rtp-base 8000
timeout-ping 1800
timeout-ping advanced
timeout-pong 60
codec-list hr3
dest 151.80.237.229 5000 184
amr-config 12_2k forbidden
amr-config 10_2k forbidden
amr-config 7_95k forbidden
amr-config 7_40k forbidden
amr-config 6_70k forbidden
amr-config 5_90k allowed
amr-config 5_15k forbidden
amr-config 4_75k forbidden

View File

@ -0,0 +1,12 @@
! Configuration rendered by osmo-gsm-tester
log stderr
logging filter all 1
logging color 1
logging print category 1
logging print extended-timestamp 1
logging level all debug
line vty
no login
bind ${hlr.ip_address.addr}
ctrl
bind ${hlr.ip_address.addr}

View File

@ -0,0 +1,18 @@
! Configuration rendered by osmo-gsm-tester
log stderr
logging filter all 1
logging color 1
logging print category 1
logging print extended-timestamp 1
logging level all debug
mgcp
local ip ${mgcpgw.ip_address.addr}
bts ip ${mgcpgw.bts_ip}
bind ip ${mgcpgw.ip_address.addr}
bind port 2427
rtp base 4000
rtp force-ptime 20
sdp audio payload number 98
sdp audio payload name AMR/8000
number endpoints 31
no rtcp-omit

View File

@ -0,0 +1,30 @@
! Configuration rendered by osmo-gsm-tester
log stderr
logging filter all 1
logging color 1
logging print category 1
logging print extended-timestamp 1
logging level all debug
line vty
no login
bind ${msc.ip_address.addr}
network
network country code ${msc.net.mcc}
mobile network code ${msc.net.mnc}
short name ${msc.net.short_name}
long name ${msc.net.long_name}
auth policy ${msc.net.auth_policy}
location updating reject cause 13
encryption ${msc.net.encryption}
msc
mgcpgw remote-ip ${mgcpgw.ip_address.addr}
assign-tmsi
ctrl
bind ${msc.ip_address.addr}
smpp
local-tcp-ip ${msc.ip_address.addr} 2775
system-id test
policy closed
esme test
password test
default-route