blob: 95d020b57b7ab1b9515110a659d8d5499f0ef82b [file] [log] [blame]
Neels Hofmeyr17c139e2017-04-12 02:42:02 +02001# osmo_gsm_tester: specifics for running an osmo-bts-trx
Neels Hofmeyr3531a192017-03-28 14:30:28 +02002#
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
8# it under the terms of the GNU Affero General Public License as
9# 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
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20import os
Neels Hofmeyr943c81d2017-05-22 20:16:03 +020021import pprint
Neels Hofmeyr206803d2017-05-29 03:45:51 +020022from . import log, config, util, template, process, event_loop
Neels Hofmeyr3531a192017-03-28 14:30:28 +020023
24class OsmoBtsTrx(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 Hofmeyr3531a192017-03-28 14:30:28 +020028 inst = None
29 env = None
Neels Hofmeyrfd39f3e2017-05-07 02:02:35 +020030 proc_trx = None
Neels Hofmeyr3531a192017-03-28 14:30:28 +020031
32 BIN_TRX = 'osmo-trx'
33 BIN_BTS_TRX = 'osmo-bts-trx'
34 BIN_PCU = 'osmo-pcu'
35
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020036 CONF_BTS_TRX = 'osmo-bts-trx.cfg'
37
Neels Hofmeyr3531a192017-03-28 14:30:28 +020038 def __init__(self, suite_run, conf):
39 self.suite_run = suite_run
40 self.conf = conf
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020041 self.set_name(OsmoBtsTrx.BIN_BTS_TRX)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020042 self.set_log_category(log.C_RUN)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020043 self.env = {}
44
Neels Hofmeyrd41dae92017-05-22 19:58:41 +020045 def remote_addr(self):
46 # FIXME
47 return '127.0.0.1'
48
Neels Hofmeyr3531a192017-03-28 14:30:28 +020049 def start(self):
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +020050 if self.bsc is None:
51 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started')
Neels Hofmeyr3531a192017-03-28 14:30:28 +020052 self.suite_run.poll()
53
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +020054 self.log('Starting to connect to', self.bsc)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020055 self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name()))
56 self.configure()
57
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020058 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(OsmoBtsTrx.BIN_BTS_TRX)))
Your Name3c6673a2017-04-08 18:52:39 +020059 lib = self.inst.child('lib')
60 if not os.path.isdir(lib):
61 raise RuntimeError('No lib/ in %r' % self.inst)
Pau Espin Pedrole39c6f12017-05-08 16:21:38 +020062 self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
Neels Hofmeyr3531a192017-03-28 14:30:28 +020063
Neels Hofmeyrfd39f3e2017-05-07 02:02:35 +020064 self.proc_trx = self.launch_process(OsmoBtsTrx.BIN_TRX, '-x')
65 self.log('Waiting for osmo-trx to start up...')
Neels Hofmeyr206803d2017-05-29 03:45:51 +020066 event_loop.wait(self, self.trx_ready)
Neels Hofmeyrfd39f3e2017-05-07 02:02:35 +020067 self.proc_trx.log(self.proc_trx.get_stdout_tail(1))
Pau Espin Pedrol6ab98982017-05-12 16:07:35 +020068 self.launch_process(OsmoBtsTrx.BIN_BTS_TRX, '-r', '1',
69 '-c', os.path.abspath(self.config_file),
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +020070 '-i', self.bsc.addr())
Neels Hofmeyr3531a192017-03-28 14:30:28 +020071 #self.launch_process(OsmoBtsTrx.BIN_PCU, '-r', '1')
72 self.suite_run.poll()
73
Neels Hofmeyrfd39f3e2017-05-07 02:02:35 +020074 def trx_ready(self):
75 if not self.proc_trx or not self.proc_trx.is_running:
76 return False
77 return '-- Transceiver active with' in (self.proc_trx.get_stdout() or '')
78
Neels Hofmeyr3531a192017-03-28 14:30:28 +020079 def launch_process(self, binary_name, *args):
Neels Hofmeyr3531a192017-03-28 14:30:28 +020080 binary = os.path.abspath(self.inst.child('bin', binary_name))
81 run_dir = self.run_dir.new_dir(binary_name)
82 if not os.path.isfile(binary):
83 raise RuntimeError('Binary missing: %r' % binary)
84 proc = process.Process(binary_name, run_dir,
85 (binary,) + args,
86 env=self.env)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020087 self.suite_run.remember_to_stop(proc)
88 proc.launch()
Neels Hofmeyrfd39f3e2017-05-07 02:02:35 +020089 return proc
Neels Hofmeyr3531a192017-03-28 14:30:28 +020090
91 def configure(self):
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +020092 if self.bsc is None:
93 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured')
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020094 self.config_file = self.run_dir.new_file(OsmoBtsTrx.CONF_BTS_TRX)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020095 self.dbg(config_file=self.config_file)
96
97 values = dict(osmo_bts_trx=config.get_defaults('osmo_bts_trx'))
98 config.overlay(values, self.suite_run.config())
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +020099 config.overlay(values, dict(osmo_bts_trx=dict(oml_remote_ip=self.bsc.addr())))
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200100 config.overlay(values, dict(osmo_bts_trx=self.conf))
Neels Hofmeyr943c81d2017-05-22 20:16:03 +0200101
102 self.dbg('OSMO-BTS-TRX CONFIG:\n' + pprint.pformat(values))
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200103
104 with open(self.config_file, 'w') as f:
Neels Hofmeyr17c139e2017-04-12 02:42:02 +0200105 r = template.render(OsmoBtsTrx.CONF_BTS_TRX, values)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200106 self.dbg(r)
107 f.write(r)
108
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200109 def conf_for_bsc(self):
110 values = config.get_defaults('bsc_bts')
Neels Hofmeyr17c139e2017-04-12 02:42:02 +0200111 config.overlay(values, config.get_defaults('osmo_bts_trx'))
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200112 config.overlay(values, self.conf)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200113 self.dbg(conf=values)
114 return values
115
Neels Hofmeyrc4ba4a62017-05-18 19:31:44 +0200116 def set_bsc(self, bsc):
117 self.bsc = bsc
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200118
119# vim: expandtab tabstop=4 shiftwidth=4