blob: 30fff0e80e2171cc1b459131f42e077a1c777470 [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
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020022from . import log, config, util, template, process
Neels Hofmeyr3531a192017-03-28 14:30:28 +020023
24class SysmoBts(log.Origin):
25 suite_run = None
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +020026 bsc = None
Neels Hofmeyr3531a192017-03-28 14:30:28 +020027 run_dir = None
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020028 inst = None
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020029 remote_inst = None
30 remote_env = None
31 remote_dir = None
32
33 REMOTE_DIR = '/osmo-gsm-tester'
34 BTS_SYSMO_BIN = 'osmo-bts-sysmo'
35 BTS_SYSMO_CFG = 'osmo-bts-sysmo.cfg'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020036
37 def __init__(self, suite_run, conf):
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020038 super().__init__(log.C_RUN, self.BTS_SYSMO_BIN)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020039 self.suite_run = suite_run
40 self.conf = conf
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020041 self.remote_env = {}
Pau Espin Pedrol3895fec2017-04-28 16:13:03 +020042 self.remote_user = 'root'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020043
44 def start(self):
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020045 if self.bsc is None:
46 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started')
47 log.log('Starting sysmoBTS to connect to', self.bsc)
48 self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name()))
49 self.configure()
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020050
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020051 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(SysmoBts.BTS_SYSMO_BIN)))
52 lib = self.inst.child('lib')
53 if not os.path.isdir(lib):
54 raise log.Error('No lib/ in', self.inst)
55 if not self.inst.isfile('bin', SysmoBts.BTS_SYSMO_BIN):
56 raise log.Error('No osmo-bts-sysmo binary in', self.inst)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020057
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020058 self.remote_dir = util.Dir(SysmoBts.REMOTE_DIR)
59 self.remote_inst = util.Dir(self.remote_dir.child(os.path.basename(str(self.inst))))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020060
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020061 self.run_remote('rm-remote-dir', ('test', '!', '-d', SysmoBts.REMOTE_DIR, '||', 'rm', '-rf', SysmoBts.REMOTE_DIR))
62 self.run_remote('mk-remote-dir', ('mkdir', '-p', SysmoBts.REMOTE_DIR))
63 self.run_local('scp-inst-to-sysmobts',
64 ('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 +020065
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020066 remote_run_dir = self.remote_dir.child(SysmoBts.BTS_SYSMO_BIN)
67 self.run_remote('mk-remote-run-dir', ('mkdir', '-p', remote_run_dir))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020068
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020069 remote_config_file = self.remote_dir.child(SysmoBts.BTS_SYSMO_CFG)
70 self.run_local('scp-cfg-to-sysmobts',
71 ('scp', '-r', self.config_file, '%s@%s:%s' % (self.remote_user, self.remote_addr(), remote_config_file)))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020072
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020073 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 +020074
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020075 remote_lib = self.remote_inst.child('lib')
76 remote_binary = self.remote_inst.child('bin', 'osmo-bts-sysmo')
77 self.launch_remote('osmo-bts-sysmo',
78 ('LD_LIBRARY_PATH=%s' % remote_lib,
79 remote_binary, '-c', remote_config_file, '-r', '1',
80 '-i', self.bsc.addr()),
81 remote_cwd=remote_run_dir)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020082
83 def _process_remote(self, name, popen_args, remote_cwd=None):
84 run_dir = self.run_dir.new_dir(name)
Neels Hofmeyrd41dae92017-05-22 19:58:41 +020085 return process.RemoteProcess(name, run_dir, self.remote_user, self.remote_addr(), remote_cwd,
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020086 popen_args)
87
88 def run_remote(self, name, popen_args, remote_cwd=None):
89 proc = self._process_remote(name, popen_args, remote_cwd)
90 proc.launch()
91 proc.wait()
92 if proc.result != 0:
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020093 log.ctx(proc)
94 raise log.Error('Exited in error')
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020095
96 def launch_remote(self, name, popen_args, remote_cwd=None):
97 proc = self._process_remote(name, popen_args, remote_cwd)
98 self.suite_run.remember_to_stop(proc)
99 proc.launch()
100
101 def run_local(self, name, popen_args):
102 run_dir = self.run_dir.new_dir(name)
103 proc = process.Process(name, run_dir, popen_args)
104 proc.launch()
105 proc.wait()
106 if proc.result != 0:
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200107 log.ctx(proc)
108 raise log.Error('Exited in error')
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200109
Neels Hofmeyrd41dae92017-05-22 19:58:41 +0200110 def remote_addr(self):
111 return self.conf.get('addr')
112
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200113 def configure(self):
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200114 if self.bsc is None:
115 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured')
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200116
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200117 self.config_file = self.run_dir.new_file(SysmoBts.BTS_SYSMO_CFG)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200118 self.dbg(config_file=self.config_file)
119
120 values = { 'osmo_bts_sysmo': config.get_defaults('osmo_bts_sysmo') }
121 config.overlay(values, self.suite_run.config())
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200122 config.overlay(values, { 'osmo_bts_sysmo': { 'oml_remote_ip': self.bsc.addr() } })
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200123 config.overlay(values, { 'osmo_bts_sysmo': self.conf })
Neels Hofmeyr943c81d2017-05-22 20:16:03 +0200124
125 self.dbg('SYSMOBTS CONFIG:\n' + pprint.pformat(values))
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200126
127 with open(self.config_file, 'w') as f:
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200128 r = template.render(SysmoBts.BTS_SYSMO_CFG, values)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200129 self.dbg(r)
130 f.write(r)
131
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200132 def conf_for_bsc(self):
133 values = config.get_defaults('bsc_bts')
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200134 config.overlay(values, config.get_defaults('osmo_bts_sysmo'))
135 config.overlay(values, self.conf)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200136 self.dbg(conf=values)
137 return values
138
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200139 def set_bsc(self, bsc):
140 self.bsc = bsc
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200141
142# vim: expandtab tabstop=4 shiftwidth=4