blob: 91a46be1b009f09509d68fb6d4b36e268c2a54f4 [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 Pedrole1a58bd2020-04-10 20:46:07 +020022from ..core import log, config, util, template, process, remote
Pau Espin Pedrole8bbcbf2020-04-10 19:51:31 +020023from . import pcu_sysmo, bts_osmo
Neels Hofmeyr3531a192017-03-28 14:30:28 +020024
Pau Espin Pedrolc9817a52017-12-13 19:52:27 +010025class SysmoBts(bts_osmo.OsmoBts):
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010026##############
27# PROTECTED
28##############
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020029
Pau Espin Pedrolce35d912017-11-23 11:01:24 +010030 REMOTE_DIR = '/osmo-gsm-tester-bts'
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020031 BTS_SYSMO_BIN = 'osmo-bts-sysmo'
32 BTS_SYSMO_CFG = 'osmo-bts-sysmo.cfg'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020033
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020034 def __init__(self, testenv, conf):
35 super().__init__(testenv, conf, SysmoBts.BTS_SYSMO_BIN, 'osmo_bts_sysmo')
Pau Espin Pedrol58603672018-08-09 13:45:55 +020036 self.run_dir = None
37 self.inst = None
38 self.remote_inst = None
39 self.remote_dir = None
Pau Espin Pedrol2eafb032020-01-29 17:56:14 +010040 self.proc_bts = None
Pau Espin Pedrol3895fec2017-04-28 16:13:03 +020041 self.remote_user = 'root'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020042
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010043 def _direct_pcu_enabled(self):
44 return util.str2bool(self.conf.get('direct_pcu'))
45
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010046 def create_pcu(self):
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020047 return pcu_sysmo.OsmoPcuSysmo(self.testenv, self, self.conf)
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010048
49 def configure(self):
50 if self.bsc is None:
51 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured')
52
53 self.config_file = self.run_dir.new_file(SysmoBts.BTS_SYSMO_CFG)
54 self.dbg(config_file=self.config_file)
55
56 values = { 'osmo_bts_sysmo': config.get_defaults('osmo_bts_sysmo') }
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020057 config.overlay(values, self.testenv.suite().config())
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010058 config.overlay(values, {
59 'osmo_bts_sysmo': {
60 'oml_remote_ip': self.bsc.addr(),
61 'pcu_socket_path': self.pcu_socket_path(),
62 }
63 })
64 config.overlay(values, { 'osmo_bts_sysmo': self.conf })
65
66 self.dbg('SYSMOBTS CONFIG:\n' + pprint.pformat(values))
67
68 with open(self.config_file, 'w') as f:
69 r = template.render(SysmoBts.BTS_SYSMO_CFG, values)
70 self.dbg(r)
71 f.write(r)
72
73########################
74# PUBLIC - INTERNAL API
75########################
76 def pcu_socket_path(self):
77 return os.path.join(SysmoBts.REMOTE_DIR, 'pcu_bts')
78
79 def conf_for_bsc(self):
Pau Espin Pedrole5194622018-05-07 13:36:58 +020080 values = self.conf_for_bsc_prepare()
Pau Espin Pedrol81aaeef2017-12-14 19:14:12 +010081 self.dbg(conf=values)
82 return values
83
84###################
85# PUBLIC (test API included)
86###################
Pau Espin Pedrol302c7562018-10-02 13:08:02 +020087 # We get log from ssh stdout instead of usual stderr.
88 def ready_for_pcu(self):
89 if not self.proc_bts or not self.proc_bts.is_running:
90 return False
Pau Espin Pedrol3b351712021-03-08 12:01:32 +010091 return 'Started listening on PCU socket' in (self.proc_bts.get_stdout() or '')
Pau Espin Pedrol302c7562018-10-02 13:08:02 +020092
Pau Espin Pedrolb1526b92018-05-22 20:32:30 +020093 def start(self, keepalive=False):
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020094 if self.bsc is None:
95 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started')
96 log.log('Starting sysmoBTS to connect to', self.bsc)
Pau Espin Pedrol2a2d8462020-05-11 10:56:52 +020097 self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name()))
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020098 self.configure()
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020099
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200100 self.inst = util.Dir(os.path.abspath(self.testenv.suite().trial().get_inst(SysmoBts.BTS_SYSMO_BIN)))
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200101 lib = self.inst.child('lib')
102 if not os.path.isdir(lib):
103 raise log.Error('No lib/ in', self.inst)
104 if not self.inst.isfile('bin', SysmoBts.BTS_SYSMO_BIN):
105 raise log.Error('No osmo-bts-sysmo binary in', self.inst)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200106
Pau Espin Pedrol2eafb032020-01-29 17:56:14 +0100107 rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self.remote_addr())
108 remote_prefix_dir = util.Dir(SysmoBts.REMOTE_DIR)
109 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
110 remote_run_dir = util.Dir(remote_prefix_dir.child(SysmoBts.BTS_SYSMO_BIN))
Pau Espin Pedrole4358a92018-10-01 11:27:55 +0200111 remote_config_file = remote_run_dir.child(SysmoBts.BTS_SYSMO_CFG)
Pau Espin Pedrolce35d912017-11-23 11:01:24 +0100112
Pau Espin Pedrol2eafb032020-01-29 17:56:14 +0100113 rem_host.recreate_remote_dir(self.remote_inst)
114 rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
115 rem_host.create_remote_dir(remote_run_dir)
116 rem_host.scp('scp-cfg-to-remote', self.config_file, remote_config_file)
117
118 rem_host.run_remote_sync('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"'))
119
120 remote_lib = self.remote_inst.child('lib')
121 remote_binary = self.remote_inst.child('bin', SysmoBts.BTS_SYSMO_BIN)
Pau Espin Pedrolce35d912017-11-23 11:01:24 +0100122 args = ('LD_LIBRARY_PATH=%s' % remote_lib,
123 remote_binary, '-c', remote_config_file, '-r', '1',
124 '-i', self.bsc.addr())
125
126 if self._direct_pcu_enabled():
127 args += ('-M',)
128
Pau Espin Pedrol2eafb032020-01-29 17:56:14 +0100129 self.proc_bts = rem_host.RemoteProcess(SysmoBts.BTS_SYSMO_BIN, args)
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200130 self.testenv.remember_to_stop(self.proc_bts, keepalive)
Pau Espin Pedrol2eafb032020-01-29 17:56:14 +0100131 self.proc_bts.launch()
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200132
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200133# vim: expandtab tabstop=4 shiftwidth=4