blob: 7a9c5ff6e67e05677ae662ef73590c4d7acfb5b1 [file] [log] [blame]
Pau Espin Pedrol4796b352017-11-23 11:07:42 +01001# osmo_gsm_tester: specifics for running an osmo-sgsn
2#
3# Copyright (C) 2016-2017 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
22
23from . import log, util, config, template, process, osmo_ctrl, pcap_recorder
24
25class OsmoSgsn(log.Origin):
26 suite_run = None
27 ip_address = None
28 run_dir = None
29 config_file = None
30 process = None
31 hlr = None
32 ggsn = None
33
34 def __init__(self, suite_run, hlr, ggsn, ip_address):
35 super().__init__(log.C_RUN, 'osmo-sgsn_%s' % ip_address.get('addr'))
36 self.suite_run = suite_run
37 self.hlr = hlr
38 self.ggsn = ggsn
39 self.ip_address = ip_address
40
41 def start(self):
42 self.log('Starting osmo-sgsn')
43 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
44 self.configure()
45
46 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-sgsn')))
47
48 binary = inst.child('bin', 'osmo-sgsn')
49 if not os.path.isfile(binary):
50 raise log.Error('Binary missing:', binary)
51 lib = inst.child('lib')
52 if not os.path.isdir(lib):
53 raise log.Error('No lib/ in', inst)
54
55 pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), None,
56 'host %s' % self.addr())
57
58 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
59
60 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
61 self.process = process.Process(self.name(), self.run_dir,
62 (binary,
63 '-c', os.path.abspath(self.config_file)),
64 env=env)
65 self.suite_run.remember_to_stop(self.process)
66 self.process.launch()
67
68 def configure(self):
69 self.config_file = self.run_dir.new_file('osmo-sgsn.cfg')
70 self.dbg(config_file=self.config_file)
71
72 values = dict(sgsn=config.get_defaults('sgsn'))
73 config.overlay(values, self.suite_run.config())
74 config.overlay(values, dict(sgsn=dict(ip_address=self.ip_address)))
75 config.overlay(values, self.hlr.conf_for_client())
76 config.overlay(values, self.ggsn.conf_for_client())
77
78 self.dbg('SGSN CONFIG:\n' + pprint.pformat(values))
79
80 with open(self.config_file, 'w') as f:
81 r = template.render('osmo-sgsn.cfg', values)
82 self.dbg(r)
83 f.write(r)
84
85 def conf_for_client(self):
86 return dict(sgsn=dict(ip_address=self.ip_address))
87
88 def addr(self):
89 return self.ip_address.get('addr')
90
91 def running(self):
92 return not self.process.terminated()
93
94# vim: expandtab tabstop=4 shiftwidth=4