Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: specifics for running an osmo-bts-trx |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 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 Welte | 2720534 | 2017-06-03 09:51:45 +0200 | [diff] [blame] | 8 | # it under the terms of the GNU General Public License as |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 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 |
Harald Welte | 2720534 | 2017-06-03 09:51:45 +0200 | [diff] [blame] | 15 | # GNU General Public License for more details. |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 16 | # |
Harald Welte | 2720534 | 2017-06-03 09:51:45 +0200 | [diff] [blame] | 17 | # You should have received a copy of the GNU General Public License |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | import os |
Neels Hofmeyr | 943c81d | 2017-05-22 20:16:03 +0200 | [diff] [blame] | 21 | import pprint |
Neels Hofmeyr | 206803d | 2017-05-29 03:45:51 +0200 | [diff] [blame] | 22 | from . import log, config, util, template, process, event_loop |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 23 | |
| 24 | class OsmoBtsTrx(log.Origin): |
| 25 | suite_run = None |
Neels Hofmeyr | c4ba4a6 | 2017-05-18 19:31:44 +0200 | [diff] [blame] | 26 | bsc = None |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 27 | run_dir = None |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 28 | inst = None |
| 29 | env = None |
Neels Hofmeyr | fd39f3e | 2017-05-07 02:02:35 +0200 | [diff] [blame] | 30 | proc_trx = None |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 31 | |
| 32 | BIN_TRX = 'osmo-trx' |
| 33 | BIN_BTS_TRX = 'osmo-bts-trx' |
| 34 | BIN_PCU = 'osmo-pcu' |
| 35 | |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 36 | CONF_BTS_TRX = 'osmo-bts-trx.cfg' |
| 37 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 38 | def __init__(self, suite_run, conf): |
Neels Hofmeyr | 1a7a3f0 | 2017-06-10 01:18:27 +0200 | [diff] [blame] | 39 | super().__init__(log.C_RUN, OsmoBtsTrx.BIN_BTS_TRX) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 40 | self.suite_run = suite_run |
| 41 | self.conf = conf |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 42 | self.env = {} |
| 43 | |
Neels Hofmeyr | d41dae9 | 2017-05-22 19:58:41 +0200 | [diff] [blame] | 44 | def remote_addr(self): |
| 45 | # FIXME |
| 46 | return '127.0.0.1' |
| 47 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 48 | def start(self): |
Neels Hofmeyr | c4ba4a6 | 2017-05-18 19:31:44 +0200 | [diff] [blame] | 49 | if self.bsc is None: |
| 50 | raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started') |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 51 | self.suite_run.poll() |
| 52 | |
Neels Hofmeyr | c4ba4a6 | 2017-05-18 19:31:44 +0200 | [diff] [blame] | 53 | self.log('Starting to connect to', self.bsc) |
Pau Espin Pedrol | d091233 | 2017-06-14 13:27:08 +0200 | [diff] [blame] | 54 | self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name())) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 55 | self.configure() |
| 56 | |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 57 | self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(OsmoBtsTrx.BIN_BTS_TRX))) |
Your Name | 3c6673a | 2017-04-08 18:52:39 +0200 | [diff] [blame] | 58 | lib = self.inst.child('lib') |
| 59 | if not os.path.isdir(lib): |
| 60 | raise RuntimeError('No lib/ in %r' % self.inst) |
Pau Espin Pedrol | e39c6f1 | 2017-05-08 16:21:38 +0200 | [diff] [blame] | 61 | self.env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) } |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 62 | |
Neels Hofmeyr | fd39f3e | 2017-05-07 02:02:35 +0200 | [diff] [blame] | 63 | self.proc_trx = self.launch_process(OsmoBtsTrx.BIN_TRX, '-x') |
| 64 | self.log('Waiting for osmo-trx to start up...') |
Neels Hofmeyr | 206803d | 2017-05-29 03:45:51 +0200 | [diff] [blame] | 65 | event_loop.wait(self, self.trx_ready) |
Neels Hofmeyr | fd39f3e | 2017-05-07 02:02:35 +0200 | [diff] [blame] | 66 | self.proc_trx.log(self.proc_trx.get_stdout_tail(1)) |
Pau Espin Pedrol | 6ab9898 | 2017-05-12 16:07:35 +0200 | [diff] [blame] | 67 | self.launch_process(OsmoBtsTrx.BIN_BTS_TRX, '-r', '1', |
| 68 | '-c', os.path.abspath(self.config_file), |
Neels Hofmeyr | c4ba4a6 | 2017-05-18 19:31:44 +0200 | [diff] [blame] | 69 | '-i', self.bsc.addr()) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 70 | #self.launch_process(OsmoBtsTrx.BIN_PCU, '-r', '1') |
| 71 | self.suite_run.poll() |
| 72 | |
Neels Hofmeyr | fd39f3e | 2017-05-07 02:02:35 +0200 | [diff] [blame] | 73 | def trx_ready(self): |
| 74 | if not self.proc_trx or not self.proc_trx.is_running: |
| 75 | return False |
| 76 | return '-- Transceiver active with' in (self.proc_trx.get_stdout() or '') |
| 77 | |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 78 | def launch_process(self, binary_name, *args): |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 79 | binary = os.path.abspath(self.inst.child('bin', binary_name)) |
| 80 | run_dir = self.run_dir.new_dir(binary_name) |
| 81 | if not os.path.isfile(binary): |
| 82 | raise RuntimeError('Binary missing: %r' % binary) |
| 83 | proc = process.Process(binary_name, run_dir, |
| 84 | (binary,) + args, |
| 85 | env=self.env) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 86 | self.suite_run.remember_to_stop(proc) |
| 87 | proc.launch() |
Neels Hofmeyr | fd39f3e | 2017-05-07 02:02:35 +0200 | [diff] [blame] | 88 | return proc |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 89 | |
| 90 | def configure(self): |
Neels Hofmeyr | c4ba4a6 | 2017-05-18 19:31:44 +0200 | [diff] [blame] | 91 | if self.bsc is None: |
| 92 | raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured') |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 93 | self.config_file = self.run_dir.new_file(OsmoBtsTrx.CONF_BTS_TRX) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 94 | self.dbg(config_file=self.config_file) |
| 95 | |
| 96 | values = dict(osmo_bts_trx=config.get_defaults('osmo_bts_trx')) |
| 97 | config.overlay(values, self.suite_run.config()) |
Neels Hofmeyr | c4ba4a6 | 2017-05-18 19:31:44 +0200 | [diff] [blame] | 98 | config.overlay(values, dict(osmo_bts_trx=dict(oml_remote_ip=self.bsc.addr()))) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 99 | config.overlay(values, dict(osmo_bts_trx=self.conf)) |
Neels Hofmeyr | 943c81d | 2017-05-22 20:16:03 +0200 | [diff] [blame] | 100 | |
| 101 | self.dbg('OSMO-BTS-TRX CONFIG:\n' + pprint.pformat(values)) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 102 | |
| 103 | with open(self.config_file, 'w') as f: |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 104 | r = template.render(OsmoBtsTrx.CONF_BTS_TRX, values) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 105 | self.dbg(r) |
| 106 | f.write(r) |
| 107 | |
Neels Hofmeyr | c4ba4a6 | 2017-05-18 19:31:44 +0200 | [diff] [blame] | 108 | def conf_for_bsc(self): |
| 109 | values = config.get_defaults('bsc_bts') |
Neels Hofmeyr | 17c139e | 2017-04-12 02:42:02 +0200 | [diff] [blame] | 110 | config.overlay(values, config.get_defaults('osmo_bts_trx')) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 111 | config.overlay(values, self.conf) |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 112 | self.dbg(conf=values) |
| 113 | return values |
| 114 | |
Neels Hofmeyr | c4ba4a6 | 2017-05-18 19:31:44 +0200 | [diff] [blame] | 115 | def set_bsc(self, bsc): |
| 116 | self.bsc = bsc |
Neels Hofmeyr | 3531a19 | 2017-03-28 14:30:28 +0200 | [diff] [blame] | 117 | |
| 118 | # vim: expandtab tabstop=4 shiftwidth=4 |