blob: d286d02ce23538b4c606044b87d9e2de8ecb6653 [file] [log] [blame]
Neels Hofmeyr3531a192017-03-28 14:30:28 +02001# osmo_gsm_tester: specifics for running a sysmoBTS
2#
3# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
4#
5# Author: Neels Hofmeyr <neels@hofmeyr.de>
6#
7# This program is free software: you can redistribute it and/or modify
Harald Welte27205342017-06-03 09:51:45 +02008# it under the terms of the GNU General Public License as
Neels Hofmeyr3531a192017-03-28 14:30:28 +02009# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte27205342017-06-03 09:51:45 +020015# GNU General Public License for more details.
Neels Hofmeyr3531a192017-03-28 14:30:28 +020016#
Harald Welte27205342017-06-03 09:51:45 +020017# You should have received a copy of the GNU General Public License
Neels Hofmeyr3531a192017-03-28 14:30:28 +020018# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020020import os
Neels Hofmeyr943c81d2017-05-22 20:16:03 +020021import pprint
Pau Espin Pedrolc9817a52017-12-13 19:52:27 +010022from . import log, config, util, template, process, pcu_sysmo, bts_osmo
Neels Hofmeyr3531a192017-03-28 14:30:28 +020023
Pau Espin Pedrolc9817a52017-12-13 19:52:27 +010024class SysmoBts(bts_osmo.OsmoBts):
Neels Hofmeyr3531a192017-03-28 14:30:28 +020025 run_dir = None
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020026 inst = None
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020027 remote_inst = None
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020028 remote_dir = None
29
Pau Espin Pedrolce35d912017-11-23 11:01:24 +010030 REMOTE_DIR = '/osmo-gsm-tester-bts'
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020031 BTS_SYSMO_BIN = 'osmo-bts-sysmo'
32 BTS_SYSMO_CFG = 'osmo-bts-sysmo.cfg'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020033
34 def __init__(self, suite_run, conf):
Pau Espin Pedrolc9817a52017-12-13 19:52:27 +010035 super().__init__(suite_run, conf, SysmoBts.BTS_SYSMO_BIN)
Pau Espin Pedrol3895fec2017-04-28 16:13:03 +020036 self.remote_user = 'root'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020037
38 def start(self):
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020039 if self.bsc is None:
40 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started')
41 log.log('Starting sysmoBTS to connect to', self.bsc)
Pau Espin Pedrold0912332017-06-14 13:27:08 +020042 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020043 self.configure()
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020044
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020045 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(SysmoBts.BTS_SYSMO_BIN)))
46 lib = self.inst.child('lib')
47 if not os.path.isdir(lib):
48 raise log.Error('No lib/ in', self.inst)
49 if not self.inst.isfile('bin', SysmoBts.BTS_SYSMO_BIN):
50 raise log.Error('No osmo-bts-sysmo binary in', self.inst)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020051
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020052 self.remote_dir = util.Dir(SysmoBts.REMOTE_DIR)
53 self.remote_inst = util.Dir(self.remote_dir.child(os.path.basename(str(self.inst))))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020054
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020055 self.run_remote('rm-remote-dir', ('test', '!', '-d', SysmoBts.REMOTE_DIR, '||', 'rm', '-rf', SysmoBts.REMOTE_DIR))
56 self.run_remote('mk-remote-dir', ('mkdir', '-p', SysmoBts.REMOTE_DIR))
57 self.run_local('scp-inst-to-sysmobts',
58 ('scp', '-r', str(self.inst), '%s@%s:%s' % (self.remote_user, self.remote_addr(), str(self.remote_inst))))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020059
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020060 remote_run_dir = self.remote_dir.child(SysmoBts.BTS_SYSMO_BIN)
61 self.run_remote('mk-remote-run-dir', ('mkdir', '-p', remote_run_dir))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020062
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020063 remote_config_file = self.remote_dir.child(SysmoBts.BTS_SYSMO_CFG)
64 self.run_local('scp-cfg-to-sysmobts',
65 ('scp', '-r', self.config_file, '%s@%s:%s' % (self.remote_user, self.remote_addr(), remote_config_file)))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020066
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020067 self.run_remote('reload-dsp-firmware', ('/bin/sh', '-c', '"cat /lib/firmware/sysmobts-v?.bit > /dev/fpgadl_par0 ; cat /lib/firmware/sysmobts-v?.out > /dev/dspdl_dm644x_0"'))
Neels Hofmeyr96ed9ab2017-05-04 14:30:39 +020068
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020069 remote_lib = self.remote_inst.child('lib')
70 remote_binary = self.remote_inst.child('bin', 'osmo-bts-sysmo')
Pau Espin Pedrolce35d912017-11-23 11:01:24 +010071
72 args = ('LD_LIBRARY_PATH=%s' % remote_lib,
73 remote_binary, '-c', remote_config_file, '-r', '1',
74 '-i', self.bsc.addr())
75
76 if self._direct_pcu_enabled():
77 args += ('-M',)
78
79 self.proc_bts = self.launch_remote('osmo-bts-sysmo', args, remote_cwd=remote_run_dir)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020080
Pau Espin Pedrolce35d912017-11-23 11:01:24 +010081 def _direct_pcu_enabled(self):
82 return util.str2bool(self.conf.get('direct_pcu'))
83
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020084 def _process_remote(self, name, popen_args, remote_cwd=None):
85 run_dir = self.run_dir.new_dir(name)
Neels Hofmeyrd41dae92017-05-22 19:58:41 +020086 return process.RemoteProcess(name, run_dir, self.remote_user, self.remote_addr(), remote_cwd,
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020087 popen_args)
88
89 def run_remote(self, name, popen_args, remote_cwd=None):
90 proc = self._process_remote(name, popen_args, remote_cwd)
91 proc.launch()
92 proc.wait()
93 if proc.result != 0:
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020094 log.ctx(proc)
95 raise log.Error('Exited in error')
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020096
97 def launch_remote(self, name, popen_args, remote_cwd=None):
98 proc = self._process_remote(name, popen_args, remote_cwd)
99 self.suite_run.remember_to_stop(proc)
100 proc.launch()
Pau Espin Pedrold0a01112017-11-28 12:15:10 +0100101 return proc
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200102
103 def run_local(self, name, popen_args):
104 run_dir = self.run_dir.new_dir(name)
105 proc = process.Process(name, run_dir, popen_args)
106 proc.launch()
107 proc.wait()
108 if proc.result != 0:
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200109 log.ctx(proc)
110 raise log.Error('Exited in error')
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200111
Pau Espin Pedrolc9817a52017-12-13 19:52:27 +0100112 def create_pcu(self):
113 return pcu_sysmo.OsmoPcuSysmo(self.suite_run, self, self.conf)
Neels Hofmeyrd41dae92017-05-22 19:58:41 +0200114
Pau Espin Pedrolce35d912017-11-23 11:01:24 +0100115 def pcu_socket_path(self):
116 return os.path.join(SysmoBts.REMOTE_DIR, 'pcu_bts')
117
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200118 def configure(self):
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200119 if self.bsc is None:
120 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured')
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200121
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200122 self.config_file = self.run_dir.new_file(SysmoBts.BTS_SYSMO_CFG)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200123 self.dbg(config_file=self.config_file)
124
125 values = { 'osmo_bts_sysmo': config.get_defaults('osmo_bts_sysmo') }
126 config.overlay(values, self.suite_run.config())
Pau Espin Pedrol329b6f42017-08-08 13:55:24 +0200127 config.overlay(values, {
128 'osmo_bts_sysmo': {
129 'oml_remote_ip': self.bsc.addr(),
Pau Espin Pedrol15aae982017-09-08 13:55:54 +0200130 'pcu_socket_path': self.pcu_socket_path(),
Pau Espin Pedrol329b6f42017-08-08 13:55:24 +0200131 }
132 })
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200133 config.overlay(values, { 'osmo_bts_sysmo': self.conf })
Neels Hofmeyr943c81d2017-05-22 20:16:03 +0200134
135 self.dbg('SYSMOBTS CONFIG:\n' + pprint.pformat(values))
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200136
137 with open(self.config_file, 'w') as f:
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200138 r = template.render(SysmoBts.BTS_SYSMO_CFG, values)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200139 self.dbg(r)
140 f.write(r)
141
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200142 def conf_for_bsc(self):
143 values = config.get_defaults('bsc_bts')
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200144 config.overlay(values, config.get_defaults('osmo_bts_sysmo'))
Pau Espin Pedrol5e0c2512017-11-06 18:40:23 +0100145 if self.lac is not None:
146 config.overlay(values, { 'location_area_code': self.lac })
Pau Espin Pedrol8a3a7b52017-11-28 15:50:02 +0100147 if self.rac is not None:
148 config.overlay(values, { 'routing_area_code': self.rac })
Pau Espin Pedrol4ccce7c2017-11-07 11:13:20 +0100149 if self.cellid is not None:
150 config.overlay(values, { 'cell_identity': self.cellid })
Pau Espin Pedrol8a3a7b52017-11-28 15:50:02 +0100151 if self.bvci is not None:
152 config.overlay(values, { 'bvci': self.bvci })
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200153 config.overlay(values, self.conf)
Pau Espin Pedrolce35d912017-11-23 11:01:24 +0100154
155 sgsn_conf = {} if self.sgsn is None else self.sgsn.conf_for_client()
156 config.overlay(values, sgsn_conf)
157
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200158 self.dbg(conf=values)
159 return values
160
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200161# vim: expandtab tabstop=4 shiftwidth=4