blob: d7f9f8765e0b72f28e914df2d5c9523ed02ff98b [file] [log] [blame]
Neels Hofmeyr798e5922017-05-18 15:24:02 +02001# osmo_gsm_tester: specifics for running an osmo-bsc
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
8# it under the terms of the GNU Affero 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 Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20import os
21import pprint
22
23from . import log, util, config, template, process, osmo_ctrl, pcap_recorder
24
25class OsmoBsc(log.Origin):
26 suite_run = None
27 ip_address = None
28 run_dir = None
29 config_file = None
30 process = None
31 bts = None
32
33 def __init__(self, suite_run, msc, ip_address):
34 self.suite_run = suite_run
35 self.ip_address = ip_address
36 self.set_log_category(log.C_RUN)
37 self.set_name('osmo-bsc_%s' % ip_address.get('addr'))
38 self.bts = []
39 self.msc = msc
40
41 def start(self):
42 self.log('Starting osmo-bsc')
43 self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name()))
44 self.configure()
45
46 # NOTE: While OsmoMSC and OsmoBSC live in the same git repository, the
47 # osmo-msc build will also provide the OsmoBSC binary. As soon as the
48 # repositories are separate, there shall be a separate artifact.
49 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-msc')))
50
51 binary = inst.child('bin', 'osmo-bsc')
52 if not os.path.isfile(binary):
53 raise RuntimeError('Binary missing: %r' % binary)
54 lib = inst.child('lib')
55 if not os.path.isdir(lib):
56 raise RuntimeError('No lib/ in %r' % inst)
57
58 iface = util.ip_to_iface(self.addr())
59 pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), iface,
60 'host %s and port not 22' % self.addr())
61
62 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
63
64 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
65 self.process = process.Process(self.name(), self.run_dir,
66 (binary, '-c',
67 os.path.abspath(self.config_file)),
68 env=env)
69 self.suite_run.remember_to_stop(self.process)
70 self.process.launch()
71
72 def configure(self):
73 self.config_file = self.run_dir.new_file('osmo-bsc.cfg')
74 self.dbg(config_file=self.config_file)
75
76 values = dict(bsc=config.get_defaults('bsc'))
77 config.overlay(values, self.suite_run.config())
78 config.overlay(values, dict(bsc=dict(ip_address=self.ip_address)))
79
80 bts_list = []
81 for bts in self.bts:
82 bts_list.append(bts.conf_for_bsc())
83 config.overlay(values, dict(bsc=dict(net=dict(bts_list=bts_list))))
84
85 self.dbg('BSC CONFIG:\n' + pprint.pformat(values))
86
87 with open(self.config_file, 'w') as f:
88 r = template.render('osmo-bsc.cfg', values)
89 self.dbg(r)
90 f.write(r)
91
92 def addr(self):
93 return self.ip_address.get('addr')
94
95 def bts_add(self, bts):
96 self.bts.append(bts)
97 bts.set_bsc(self)
98
99 def running(self):
100 return not self.process.terminated()
101
102# vim: expandtab tabstop=4 shiftwidth=4