blob: fc546ae552781610e477559f628a0413d953bcc2 [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
Pau Espin Pedrol5e0c2512017-11-06 18:40:23 +010032 lac = None
Pau Espin Pedrol4ccce7c2017-11-07 11:13:20 +010033 cellid = None
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020034
35 REMOTE_DIR = '/osmo-gsm-tester'
36 BTS_SYSMO_BIN = 'osmo-bts-sysmo'
37 BTS_SYSMO_CFG = 'osmo-bts-sysmo.cfg'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020038
39 def __init__(self, suite_run, conf):
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020040 super().__init__(log.C_RUN, self.BTS_SYSMO_BIN)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020041 self.suite_run = suite_run
42 self.conf = conf
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020043 self.remote_env = {}
Pau Espin Pedrol3895fec2017-04-28 16:13:03 +020044 self.remote_user = 'root'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020045
46 def start(self):
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020047 if self.bsc is None:
48 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started')
49 log.log('Starting sysmoBTS to connect to', self.bsc)
Pau Espin Pedrold0912332017-06-14 13:27:08 +020050 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020051 self.configure()
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020052
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020053 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(SysmoBts.BTS_SYSMO_BIN)))
54 lib = self.inst.child('lib')
55 if not os.path.isdir(lib):
56 raise log.Error('No lib/ in', self.inst)
57 if not self.inst.isfile('bin', SysmoBts.BTS_SYSMO_BIN):
58 raise log.Error('No osmo-bts-sysmo binary in', self.inst)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020059
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020060 self.remote_dir = util.Dir(SysmoBts.REMOTE_DIR)
61 self.remote_inst = util.Dir(self.remote_dir.child(os.path.basename(str(self.inst))))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020062
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020063 self.run_remote('rm-remote-dir', ('test', '!', '-d', SysmoBts.REMOTE_DIR, '||', 'rm', '-rf', SysmoBts.REMOTE_DIR))
64 self.run_remote('mk-remote-dir', ('mkdir', '-p', SysmoBts.REMOTE_DIR))
65 self.run_local('scp-inst-to-sysmobts',
66 ('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 +020067
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020068 remote_run_dir = self.remote_dir.child(SysmoBts.BTS_SYSMO_BIN)
69 self.run_remote('mk-remote-run-dir', ('mkdir', '-p', remote_run_dir))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020070
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020071 remote_config_file = self.remote_dir.child(SysmoBts.BTS_SYSMO_CFG)
72 self.run_local('scp-cfg-to-sysmobts',
73 ('scp', '-r', self.config_file, '%s@%s:%s' % (self.remote_user, self.remote_addr(), remote_config_file)))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020074
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020075 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 +020076
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020077 remote_lib = self.remote_inst.child('lib')
78 remote_binary = self.remote_inst.child('bin', 'osmo-bts-sysmo')
79 self.launch_remote('osmo-bts-sysmo',
80 ('LD_LIBRARY_PATH=%s' % remote_lib,
81 remote_binary, '-c', remote_config_file, '-r', '1',
82 '-i', self.bsc.addr()),
83 remote_cwd=remote_run_dir)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020084
Pau Espin Pedrol15aae982017-09-08 13:55:54 +020085 def cleanup(self):
86 pass
87
88 def pcu_socket_path(self):
89 return os.path.join(SysmoBts.REMOTE_DIR, 'pcu_bts')
90
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020091 def _process_remote(self, name, popen_args, remote_cwd=None):
92 run_dir = self.run_dir.new_dir(name)
Neels Hofmeyrd41dae92017-05-22 19:58:41 +020093 return process.RemoteProcess(name, run_dir, self.remote_user, self.remote_addr(), remote_cwd,
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020094 popen_args)
95
96 def run_remote(self, name, popen_args, remote_cwd=None):
97 proc = self._process_remote(name, popen_args, remote_cwd)
98 proc.launch()
99 proc.wait()
100 if proc.result != 0:
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200101 log.ctx(proc)
102 raise log.Error('Exited in error')
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200103
104 def launch_remote(self, name, popen_args, remote_cwd=None):
105 proc = self._process_remote(name, popen_args, remote_cwd)
106 self.suite_run.remember_to_stop(proc)
107 proc.launch()
108
109 def run_local(self, name, popen_args):
110 run_dir = self.run_dir.new_dir(name)
111 proc = process.Process(name, run_dir, popen_args)
112 proc.launch()
113 proc.wait()
114 if proc.result != 0:
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200115 log.ctx(proc)
116 raise log.Error('Exited in error')
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200117
Neels Hofmeyrd41dae92017-05-22 19:58:41 +0200118 def remote_addr(self):
119 return self.conf.get('addr')
120
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200121 def configure(self):
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200122 if self.bsc is None:
123 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured')
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200124
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200125 self.config_file = self.run_dir.new_file(SysmoBts.BTS_SYSMO_CFG)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200126 self.dbg(config_file=self.config_file)
127
128 values = { 'osmo_bts_sysmo': config.get_defaults('osmo_bts_sysmo') }
129 config.overlay(values, self.suite_run.config())
Pau Espin Pedrol329b6f42017-08-08 13:55:24 +0200130 config.overlay(values, {
131 'osmo_bts_sysmo': {
132 'oml_remote_ip': self.bsc.addr(),
Pau Espin Pedrol15aae982017-09-08 13:55:54 +0200133 'pcu_socket_path': self.pcu_socket_path(),
Pau Espin Pedrol329b6f42017-08-08 13:55:24 +0200134 }
135 })
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200136 config.overlay(values, { 'osmo_bts_sysmo': self.conf })
Neels Hofmeyr943c81d2017-05-22 20:16:03 +0200137
138 self.dbg('SYSMOBTS CONFIG:\n' + pprint.pformat(values))
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200139
140 with open(self.config_file, 'w') as f:
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200141 r = template.render(SysmoBts.BTS_SYSMO_CFG, values)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200142 self.dbg(r)
143 f.write(r)
144
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200145 def conf_for_bsc(self):
146 values = config.get_defaults('bsc_bts')
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200147 config.overlay(values, config.get_defaults('osmo_bts_sysmo'))
Pau Espin Pedrol5e0c2512017-11-06 18:40:23 +0100148 if self.lac is not None:
149 config.overlay(values, { 'location_area_code': self.lac })
Pau Espin Pedrol4ccce7c2017-11-07 11:13:20 +0100150 if self.cellid is not None:
151 config.overlay(values, { 'cell_identity': self.cellid })
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200152 config.overlay(values, self.conf)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200153 self.dbg(conf=values)
154 return values
155
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200156 def set_bsc(self, bsc):
157 self.bsc = bsc
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200158
Pau Espin Pedrol5e0c2512017-11-06 18:40:23 +0100159 def set_lac(self, lac):
160 self.lac = lac
161
Pau Espin Pedrol4ccce7c2017-11-07 11:13:20 +0100162 def set_cellid(self, cellid):
163 self.cellid = cellid
164
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200165# vim: expandtab tabstop=4 shiftwidth=4