blob: 66d305a6e59d36800ec74b4e2da12286b87d096d [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
Pau Espin Pedrolc9817a52017-12-13 19:52:27 +010022from . import log, config, util, template, process, pcu_sysmo, bts_osmo
Neels Hofmeyr3531a192017-03-28 14:30:28 +020023
Pau Espin Pedrolc9817a52017-12-13 19:52:27 +010024class SysmoBts(bts_osmo.OsmoBts):
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010025##############
26# PROTECTED
27##############
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020028
Pau Espin Pedrolce35d912017-11-23 11:01:24 +010029 REMOTE_DIR = '/osmo-gsm-tester-bts'
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020030 BTS_SYSMO_BIN = 'osmo-bts-sysmo'
31 BTS_SYSMO_CFG = 'osmo-bts-sysmo.cfg'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020032
33 def __init__(self, suite_run, conf):
Pau Espin Pedrole5194622018-05-07 13:36:58 +020034 super().__init__(suite_run, conf, SysmoBts.BTS_SYSMO_BIN, 'osmo_bts_sysmo')
Pau Espin Pedrol58603672018-08-09 13:45:55 +020035 self.run_dir = None
36 self.inst = None
37 self.remote_inst = None
38 self.remote_dir = None
Pau Espin Pedrol3895fec2017-04-28 16:13:03 +020039 self.remote_user = 'root'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020040
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010041 def _direct_pcu_enabled(self):
42 return util.str2bool(self.conf.get('direct_pcu'))
43
Pau Espin Pedrolb1526b92018-05-22 20:32:30 +020044 def launch_remote(self, name, popen_args, remote_cwd=None, keepalive=False):
Pau Espin Pedrole4358a92018-10-01 11:27:55 +020045 run_dir = self.run_dir.new_dir(name)
46 proc = process.RemoteProcess(name, run_dir, self.remote_user, self.remote_addr(), remote_cwd,
47 popen_args)
Pau Espin Pedrolb1526b92018-05-22 20:32:30 +020048 self.suite_run.remember_to_stop(proc, keepalive)
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010049 proc.launch()
50 return proc
51
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010052 def create_pcu(self):
53 return pcu_sysmo.OsmoPcuSysmo(self.suite_run, self, self.conf)
54
55 def configure(self):
56 if self.bsc is None:
57 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured')
58
59 self.config_file = self.run_dir.new_file(SysmoBts.BTS_SYSMO_CFG)
60 self.dbg(config_file=self.config_file)
61
62 values = { 'osmo_bts_sysmo': config.get_defaults('osmo_bts_sysmo') }
63 config.overlay(values, self.suite_run.config())
64 config.overlay(values, {
65 'osmo_bts_sysmo': {
66 'oml_remote_ip': self.bsc.addr(),
67 'pcu_socket_path': self.pcu_socket_path(),
68 }
69 })
70 config.overlay(values, { 'osmo_bts_sysmo': self.conf })
71
72 self.dbg('SYSMOBTS CONFIG:\n' + pprint.pformat(values))
73
74 with open(self.config_file, 'w') as f:
75 r = template.render(SysmoBts.BTS_SYSMO_CFG, values)
76 self.dbg(r)
77 f.write(r)
78
79########################
80# PUBLIC - INTERNAL API
81########################
82 def pcu_socket_path(self):
83 return os.path.join(SysmoBts.REMOTE_DIR, 'pcu_bts')
84
85 def conf_for_bsc(self):
Pau Espin Pedrole5194622018-05-07 13:36:58 +020086 values = self.conf_for_bsc_prepare()
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010087 self.dbg(conf=values)
88 return values
89
90###################
91# PUBLIC (test API included)
92###################
Pau Espin Pedrol302c7562018-10-02 13:08:02 +020093 # We get log from ssh stdout instead of usual stderr.
94 def ready_for_pcu(self):
95 if not self.proc_bts or not self.proc_bts.is_running:
96 return False
97 return 'BTS is up' in (self.proc_bts.get_stdout() or '')
98
Pau Espin Pedrolb1526b92018-05-22 20:32:30 +020099 def start(self, keepalive=False):
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200100 if self.bsc is None:
101 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started')
102 log.log('Starting sysmoBTS to connect to', self.bsc)
Pau Espin Pedrold0912332017-06-14 13:27:08 +0200103 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200104 self.configure()
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200105
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200106 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(SysmoBts.BTS_SYSMO_BIN)))
107 lib = self.inst.child('lib')
108 if not os.path.isdir(lib):
109 raise log.Error('No lib/ in', self.inst)
110 if not self.inst.isfile('bin', SysmoBts.BTS_SYSMO_BIN):
111 raise log.Error('No osmo-bts-sysmo binary in', self.inst)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200112
Pau Espin Pedrole4358a92018-10-01 11:27:55 +0200113 remote_run_dir = util.Dir(SysmoBts.REMOTE_DIR)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200114
Pau Espin Pedrole4358a92018-10-01 11:27:55 +0200115 self.remote_inst = process.copy_inst_ssh(self.run_dir, self.inst, remote_run_dir, self.remote_user,
116 self.remote_addr(), SysmoBts.BTS_SYSMO_BIN, self.config_file)
117 process.run_remote_sync(self.run_dir, self.remote_user, self.remote_addr(), 'reload-dsp-firmware',
118 ('/bin/sh', '-c', '"cat /lib/firmware/sysmobts-v?.bit > /dev/fpgadl_par0 ; cat /lib/firmware/sysmobts-v?.out > /dev/dspdl_dm644x_0"'))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200119
Pau Espin Pedrole4358a92018-10-01 11:27:55 +0200120 remote_config_file = remote_run_dir.child(SysmoBts.BTS_SYSMO_CFG)
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200121 remote_lib = self.remote_inst.child('lib')
122 remote_binary = self.remote_inst.child('bin', 'osmo-bts-sysmo')
Pau Espin Pedrolce35d912017-11-23 11:01:24 +0100123
124 args = ('LD_LIBRARY_PATH=%s' % remote_lib,
125 remote_binary, '-c', remote_config_file, '-r', '1',
126 '-i', self.bsc.addr())
127
128 if self._direct_pcu_enabled():
129 args += ('-M',)
130
Pau Espin Pedrolb1526b92018-05-22 20:32:30 +0200131 self.proc_bts = self.launch_remote('osmo-bts-sysmo', args, remote_cwd=remote_run_dir, keepalive=keepalive)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200132
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200133# vim: expandtab tabstop=4 shiftwidth=4