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