blob: d1f80b750b1de5b0ae68b66d6e5bb9ebc2ebe1be [file] [log] [blame]
Pau Espin Pedrolfeb66e72019-03-04 18:37:04 +01001# osmo_gsm_tester: specifics for running a osmo-bts-oc2g
2#
3# Copyright (C) 2019 by sysmocom - s.f.m.c. GmbH
4#
5# Author: Pau Espin Pedrol <pespin@sysmocom.de>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU 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 General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20import os
21import pprint
Pau Espin Pedrol19155242020-04-10 02:09:22 +020022from . import log, config, util, template, process, remote, pcu_oc2g, bts_osmo
Pau Espin Pedrolfeb66e72019-03-04 18:37:04 +010023
24class OsmoBtsOC2G(bts_osmo.OsmoBts):
25##############
26# PROTECTED
27##############
28
29 REMOTE_DIR = '/osmo-gsm-tester-bts'
30 BTS_OC2G_BIN = 'osmo-bts-oc2g'
31 BTS_OC2G_CFG = 'osmo-bts-oc2g.cfg'
32
33 def __init__(self, suite_run, conf):
34 super().__init__(suite_run, conf, OsmoBtsOC2G.BTS_OC2G_BIN, 'osmo_bts_oc2g')
35 self.run_dir = None
36 self.inst = None
37 self.remote_inst = None
38 self.remote_dir = None
Pau Espin Pedrolbd552f92020-04-10 02:18:05 +020039 self.proc_bts = None
Pau Espin Pedrolfeb66e72019-03-04 18:37:04 +010040 self.remote_user = 'root'
41
42 def _direct_pcu_enabled(self):
43 return util.str2bool(self.conf.get('direct_pcu'))
44
Pau Espin Pedrolfeb66e72019-03-04 18:37:04 +010045 def create_pcu(self):
46 return pcu_oc2g.OsmoPcuOC2G(self.suite_run, self, self.conf)
47
48 def configure(self):
49 if self.bsc is None:
50 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured')
51
52 self.config_file = self.run_dir.new_file(OsmoBtsOC2G.BTS_OC2G_CFG)
53 self.dbg(config_file=self.config_file)
54
55 values = { 'osmo_bts_oc2g': config.get_defaults('osmo_bts_oc2g') }
56 config.overlay(values, self.suite_run.config())
57 config.overlay(values, {
58 'osmo_bts_oc2g': {
59 'oml_remote_ip': self.bsc.addr(),
60 'pcu_socket_path': self.pcu_socket_path(),
61 }
62 })
63 config.overlay(values, { 'osmo_bts_oc2g': self.conf })
64
65 self.dbg('OSMO-BTS-OC2G CONFIG:\n' + pprint.pformat(values))
66
67 with open(self.config_file, 'w') as f:
68 r = template.render(OsmoBtsOC2G.BTS_OC2G_CFG, values)
69 self.dbg(r)
70 f.write(r)
71
72########################
73# PUBLIC - INTERNAL API
74########################
75 def pcu_socket_path(self):
76 return os.path.join(OsmoBtsOC2G.REMOTE_DIR, 'pcu_bts')
77
78 def conf_for_bsc(self):
79 values = self.conf_for_bsc_prepare()
80 # Hack until we have proper ARFCN resource allocation support (OS#2230)
81 band = values.get('band')
82 trx_list = values.get('trx_list')
83 if band == 'GSM-900':
84 for trx_i in range(len(trx_list)):
85 config.overlay(trx_list[trx_i], { 'arfcn' : str(50 + trx_i * 2) })
86 self.dbg(conf=values)
87 return values
88
89###################
90# PUBLIC (test API included)
91###################
92 # We get log from ssh stdout instead of usual stderr.
93 def ready_for_pcu(self):
94 if not self.proc_bts or not self.proc_bts.is_running:
95 return False
96 return 'BTS is up' in (self.proc_bts.get_stdout() or '')
97
98 def start(self, keepalive=False):
99 if self.bsc is None:
100 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started')
101 log.log('Starting OsmoBtsOC2G to connect to', self.bsc)
102 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
103 self.configure()
104
105 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(OsmoBtsOC2G.BTS_OC2G_BIN)))
106 lib = self.inst.child('lib')
107 if not os.path.isdir(lib):
108 raise log.Error('No lib/ in', self.inst)
109 if not self.inst.isfile('bin', OsmoBtsOC2G.BTS_OC2G_BIN):
110 raise log.Error('No osmo-bts-oc2g binary in', self.inst)
111
Pau Espin Pedrol2eafb032020-01-29 17:56:14 +0100112 rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self.remote_addr())
113 remote_prefix_dir = util.Dir(OsmoBtsOC2G.REMOTE_DIR)
114 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
115 remote_run_dir = util.Dir(remote_prefix_dir.child(OsmoBtsOC2G.BTS_OC2G_BIN))
Pau Espin Pedrolfeb66e72019-03-04 18:37:04 +0100116 remote_config_file = remote_run_dir.child(OsmoBtsOC2G.BTS_OC2G_CFG)
Pau Espin Pedrolfeb66e72019-03-04 18:37:04 +0100117
Pau Espin Pedrol2eafb032020-01-29 17:56:14 +0100118 rem_host.recreate_remote_dir(self.remote_inst)
119 rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
120 rem_host.create_remote_dir(remote_run_dir)
121 rem_host.scp('scp-cfg-to-remote', self.config_file, remote_config_file)
122
123 remote_lib = self.remote_inst.child('lib')
124 remote_binary = self.remote_inst.child('bin', OsmoBtsOC2G.BTS_OC2G_BIN)
Pau Espin Pedrolfeb66e72019-03-04 18:37:04 +0100125 args = ('LD_LIBRARY_PATH=%s' % remote_lib,
126 remote_binary, '-c', remote_config_file, '-r', '1',
127 '-i', self.bsc.addr())
128
129 if self._direct_pcu_enabled():
130 args += ('-M',)
131
Pau Espin Pedrolbd552f92020-04-10 02:18:05 +0200132 self.proc_bts = rem_host.RemoteProcess(OsmoBtsOC2G.BTS_OC2G_BIN, args)
133 self.suite_run.remember_to_stop(self.proc_bts, keepalive)
134 self.proc_bts.launch()
Pau Espin Pedrolfeb66e72019-03-04 18:37:04 +0100135# vim: expandtab tabstop=4 shiftwidth=4