blob: 07f7d6ef05f8fe6ed34e86aa7cd8667a64de9275 [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
21from . import log, config, util, template, process
22
23class OsmoBtsTrx(log.Origin):
24 suite_run = None
25 nitb = None
26 run_dir = None
Neels Hofmeyr3531a192017-03-28 14:30:28 +020027 inst = None
28 env = None
Neels Hofmeyrfd39f3e2017-05-07 02:02:35 +020029 proc_trx = None
Neels Hofmeyr3531a192017-03-28 14:30:28 +020030
31 BIN_TRX = 'osmo-trx'
32 BIN_BTS_TRX = 'osmo-bts-trx'
33 BIN_PCU = 'osmo-pcu'
34
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020035 CONF_BTS_TRX = 'osmo-bts-trx.cfg'
36
Neels Hofmeyr3531a192017-03-28 14:30:28 +020037 def __init__(self, suite_run, conf):
38 self.suite_run = suite_run
39 self.conf = conf
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020040 self.set_name(OsmoBtsTrx.BIN_BTS_TRX)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020041 self.set_log_category(log.C_RUN)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020042 self.env = {}
43
44 def start(self):
45 if self.nitb is None:
46 raise RuntimeError('BTS needs to be added to a NITB before it can be started')
47 self.suite_run.poll()
48
49 self.log('Starting to connect to', self.nitb)
50 self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name()))
51 self.configure()
52
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020053 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(OsmoBtsTrx.BIN_BTS_TRX)))
Your Name3c6673a2017-04-08 18:52:39 +020054 lib = self.inst.child('lib')
55 if not os.path.isdir(lib):
56 raise RuntimeError('No lib/ in %r' % self.inst)
Pau Espin Pedrole39c6f12017-05-08 16:21:38 +020057 self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
Neels Hofmeyr3531a192017-03-28 14:30:28 +020058
Neels Hofmeyrfd39f3e2017-05-07 02:02:35 +020059 self.proc_trx = self.launch_process(OsmoBtsTrx.BIN_TRX, '-x')
60 self.log('Waiting for osmo-trx to start up...')
61 self.suite_run.wait(self.trx_ready)
62 self.proc_trx.log(self.proc_trx.get_stdout_tail(1))
Pau Espin Pedrol6ab98982017-05-12 16:07:35 +020063 self.launch_process(OsmoBtsTrx.BIN_BTS_TRX, '-r', '1',
64 '-c', os.path.abspath(self.config_file),
65 '-i', self.nitb.addr())
Neels Hofmeyr3531a192017-03-28 14:30:28 +020066 #self.launch_process(OsmoBtsTrx.BIN_PCU, '-r', '1')
67 self.suite_run.poll()
68
Neels Hofmeyrfd39f3e2017-05-07 02:02:35 +020069 def trx_ready(self):
70 if not self.proc_trx or not self.proc_trx.is_running:
71 return False
72 return '-- Transceiver active with' in (self.proc_trx.get_stdout() or '')
73
Neels Hofmeyr3531a192017-03-28 14:30:28 +020074 def launch_process(self, binary_name, *args):
Neels Hofmeyr3531a192017-03-28 14:30:28 +020075 binary = os.path.abspath(self.inst.child('bin', binary_name))
76 run_dir = self.run_dir.new_dir(binary_name)
77 if not os.path.isfile(binary):
78 raise RuntimeError('Binary missing: %r' % binary)
79 proc = process.Process(binary_name, run_dir,
80 (binary,) + args,
81 env=self.env)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020082 self.suite_run.remember_to_stop(proc)
83 proc.launch()
Neels Hofmeyrfd39f3e2017-05-07 02:02:35 +020084 return proc
Neels Hofmeyr3531a192017-03-28 14:30:28 +020085
86 def configure(self):
87 if self.nitb is None:
88 raise RuntimeError('BTS needs to be added to a NITB before it can be configured')
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020089 self.config_file = self.run_dir.new_file(OsmoBtsTrx.CONF_BTS_TRX)
Neels Hofmeyr3531a192017-03-28 14:30:28 +020090 self.dbg(config_file=self.config_file)
91
92 values = dict(osmo_bts_trx=config.get_defaults('osmo_bts_trx'))
93 config.overlay(values, self.suite_run.config())
94 config.overlay(values, dict(osmo_bts_trx=dict(oml_remote_ip=self.nitb.addr())))
95 config.overlay(values, dict(osmo_bts_trx=self.conf))
96 self.dbg(conf=values)
97
98 with open(self.config_file, 'w') as f:
Neels Hofmeyr17c139e2017-04-12 02:42:02 +020099 r = template.render(OsmoBtsTrx.CONF_BTS_TRX, values)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200100 self.dbg(r)
101 f.write(r)
102
103 def conf_for_nitb(self):
104 values = config.get_defaults('nitb_bts')
Neels Hofmeyr17c139e2017-04-12 02:42:02 +0200105 config.overlay(values, config.get_defaults('osmo_bts_trx'))
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200106 config.overlay(values, self.conf)
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200107 self.dbg(conf=values)
108 return values
109
110 def set_nitb(self, nitb):
111 self.nitb = nitb
112
113# vim: expandtab tabstop=4 shiftwidth=4