blob: 7a41033d1c00dce776cdf24bf82fd352c8ce38aa [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 Hofmeyr3531a192017-03-28 14:30:28 +020028 run_dir = None
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020029 inst = None
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020030 remote_inst = None
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020031 remote_dir = None
32
Pau Espin Pedrolce35d912017-11-23 11:01:24 +010033 REMOTE_DIR = '/osmo-gsm-tester-bts'
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +020034 BTS_SYSMO_BIN = 'osmo-bts-sysmo'
35 BTS_SYSMO_CFG = 'osmo-bts-sysmo.cfg'
Neels Hofmeyr3531a192017-03-28 14:30:28 +020036
37 def __init__(self, suite_run, conf):
Pau Espin Pedrolc9817a52017-12-13 19:52:27 +010038 super().__init__(suite_run, conf, SysmoBts.BTS_SYSMO_BIN)
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
44 def _process_remote(self, name, popen_args, remote_cwd=None):
45 run_dir = self.run_dir.new_dir(name)
46 return process.RemoteProcess(name, run_dir, self.remote_user, self.remote_addr(), remote_cwd,
47 popen_args)
48
49 def run_remote(self, name, popen_args, remote_cwd=None):
50 proc = self._process_remote(name, popen_args, remote_cwd)
51 proc.launch()
52 proc.wait()
53 if proc.result != 0:
54 log.ctx(proc)
55 raise log.Error('Exited in error')
56
57 def launch_remote(self, name, popen_args, remote_cwd=None):
58 proc = self._process_remote(name, popen_args, remote_cwd)
59 self.suite_run.remember_to_stop(proc)
60 proc.launch()
61 return proc
62
63 def run_local(self, name, popen_args):
64 run_dir = self.run_dir.new_dir(name)
65 proc = process.Process(name, run_dir, popen_args)
66 proc.launch()
67 proc.wait()
68 if proc.result != 0:
69 log.ctx(proc)
70 raise log.Error('Exited in error')
71
72 def create_pcu(self):
73 return pcu_sysmo.OsmoPcuSysmo(self.suite_run, self, self.conf)
74
75 def configure(self):
76 if self.bsc is None:
77 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be configured')
78
79 self.config_file = self.run_dir.new_file(SysmoBts.BTS_SYSMO_CFG)
80 self.dbg(config_file=self.config_file)
81
82 values = { 'osmo_bts_sysmo': config.get_defaults('osmo_bts_sysmo') }
83 config.overlay(values, self.suite_run.config())
84 config.overlay(values, {
85 'osmo_bts_sysmo': {
86 'oml_remote_ip': self.bsc.addr(),
87 'pcu_socket_path': self.pcu_socket_path(),
88 }
89 })
90 config.overlay(values, { 'osmo_bts_sysmo': self.conf })
91
92 self.dbg('SYSMOBTS CONFIG:\n' + pprint.pformat(values))
93
94 with open(self.config_file, 'w') as f:
95 r = template.render(SysmoBts.BTS_SYSMO_CFG, values)
96 self.dbg(r)
97 f.write(r)
98
99########################
100# PUBLIC - INTERNAL API
101########################
102 def pcu_socket_path(self):
103 return os.path.join(SysmoBts.REMOTE_DIR, 'pcu_bts')
104
105 def conf_for_bsc(self):
106 values = config.get_defaults('bsc_bts')
107 config.overlay(values, config.get_defaults('osmo_bts_sysmo'))
108 if self.lac is not None:
109 config.overlay(values, { 'location_area_code': self.lac })
110 if self.rac is not None:
111 config.overlay(values, { 'routing_area_code': self.rac })
112 if self.cellid is not None:
113 config.overlay(values, { 'cell_identity': self.cellid })
114 if self.bvci is not None:
115 config.overlay(values, { 'bvci': self.bvci })
116 config.overlay(values, self.conf)
117
118 sgsn_conf = {} if self.sgsn is None else self.sgsn.conf_for_client()
119 config.overlay(values, sgsn_conf)
120
121 self.dbg(conf=values)
122 return values
123
124###################
125# PUBLIC (test API included)
126###################
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200127 def start(self):
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200128 if self.bsc is None:
129 raise RuntimeError('BTS needs to be added to a BSC or NITB before it can be started')
130 log.log('Starting sysmoBTS to connect to', self.bsc)
Pau Espin Pedrold0912332017-06-14 13:27:08 +0200131 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200132 self.configure()
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200133
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200134 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst(SysmoBts.BTS_SYSMO_BIN)))
135 lib = self.inst.child('lib')
136 if not os.path.isdir(lib):
137 raise log.Error('No lib/ in', self.inst)
138 if not self.inst.isfile('bin', SysmoBts.BTS_SYSMO_BIN):
139 raise log.Error('No osmo-bts-sysmo binary in', self.inst)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200140
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200141 self.remote_dir = util.Dir(SysmoBts.REMOTE_DIR)
142 self.remote_inst = util.Dir(self.remote_dir.child(os.path.basename(str(self.inst))))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200143
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200144 self.run_remote('rm-remote-dir', ('test', '!', '-d', SysmoBts.REMOTE_DIR, '||', 'rm', '-rf', SysmoBts.REMOTE_DIR))
145 self.run_remote('mk-remote-dir', ('mkdir', '-p', SysmoBts.REMOTE_DIR))
146 self.run_local('scp-inst-to-sysmobts',
147 ('scp', '-r', str(self.inst), '%s@%s:%s' % (self.remote_user, self.remote_addr(), str(self.remote_inst))))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200148
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200149 remote_run_dir = self.remote_dir.child(SysmoBts.BTS_SYSMO_BIN)
150 self.run_remote('mk-remote-run-dir', ('mkdir', '-p', remote_run_dir))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200151
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200152 remote_config_file = self.remote_dir.child(SysmoBts.BTS_SYSMO_CFG)
153 self.run_local('scp-cfg-to-sysmobts',
154 ('scp', '-r', self.config_file, '%s@%s:%s' % (self.remote_user, self.remote_addr(), remote_config_file)))
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200155
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200156 self.run_remote('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"'))
Neels Hofmeyr96ed9ab2017-05-04 14:30:39 +0200157
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +0200158 remote_lib = self.remote_inst.child('lib')
159 remote_binary = self.remote_inst.child('bin', 'osmo-bts-sysmo')
Pau Espin Pedrolce35d912017-11-23 11:01:24 +0100160
161 args = ('LD_LIBRARY_PATH=%s' % remote_lib,
162 remote_binary, '-c', remote_config_file, '-r', '1',
163 '-i', self.bsc.addr())
164
165 if self._direct_pcu_enabled():
166 args += ('-M',)
167
168 self.proc_bts = self.launch_remote('osmo-bts-sysmo', args, remote_cwd=remote_run_dir)
Neels Hofmeyr5356d0a2017-04-10 03:45:30 +0200169
Neels Hofmeyr3531a192017-03-28 14:30:28 +0200170# vim: expandtab tabstop=4 shiftwidth=4