blob: 0ece596d845ae64c94ec363fd36fe55fa9660f72 [file] [log] [blame]
Pau Espin Pedrol30ceb5c2017-08-31 18:30:11 +02001# osmo_gsm_tester: specifics for running an openggsn
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
Holger Hans Peter Freyther91067232019-02-27 04:33:21 +000023from . import log, util, config, template, process, pcap_recorder
Pau Espin Pedrol30ceb5c2017-08-31 18:30:11 +020024
25class OsmoGgsn(log.Origin):
Pau Espin Pedrol30ceb5c2017-08-31 18:30:11 +020026
27 def __init__(self, suite_run, ip_address):
28 super().__init__(log.C_RUN, 'osmo-ggsn_%s' % ip_address.get('addr'))
Pau Espin Pedrol58603672018-08-09 13:45:55 +020029 self.run_dir = None
30 self.config_file = None
31 self.process = None
Pau Espin Pedrol30ceb5c2017-08-31 18:30:11 +020032 self.suite_run = suite_run
33 self.ip_address = ip_address
34
35 def start(self):
36 self.log('Starting osmo-ggsn')
37 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
38 self.configure()
39
40 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-ggsn')))
41
42 binary = inst.child('bin', 'osmo-ggsn')
43 if not os.path.isfile(binary):
44 raise log.Error('Binary missing:', binary)
45 lib = inst.child('lib')
46 if not os.path.isdir(lib):
47 raise log.Error('No lib/ in', inst)
48
49 pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), None,
50 'host %s' % self.addr())
51
Pau Espin Pedrolf0b8e372017-12-13 16:08:35 +010052 env = {}
53
54 # setting capabilities will later disable use of LD_LIBRARY_PATH from ELF loader -> modify RPATH instead.
55 self.log('Setting RPATH for osmo-ggsn')
56 util.change_elf_rpath(binary, util.prepend_library_path(lib), self.run_dir.new_dir('patchelf'))
57 # osmo-ggsn requires CAP_NET_ADMIN to create tunnel devices: ioctl(TUNSETIFF):
58 self.log('Applying CAP_NET_ADMIN capability to osmo-ggsn')
59 util.setcap_net_admin(binary, self.run_dir.new_dir('setcap_net_admin'))
Pau Espin Pedrol30ceb5c2017-08-31 18:30:11 +020060
61 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
62 self.process = process.Process(self.name(), self.run_dir,
63 (binary,
64 '-c', os.path.abspath(self.config_file)),
65 env=env)
66 self.suite_run.remember_to_stop(self.process)
67 self.process.launch()
68
69 def configure(self):
70 self.config_file = self.run_dir.new_file('osmo-ggsn.cfg')
71 self.dbg(config_file=self.config_file)
72
73 values = dict(ggsn=config.get_defaults('ggsn'))
74 config.overlay(values, self.suite_run.config())
75 config.overlay(values, dict(ggsn=dict(ip_address=self.ip_address)))
76 config.overlay(values, dict(ggsn=dict(statedir=self.run_dir.new_dir('statedir'))))
77
78 self.dbg('GGSN CONFIG:\n' + pprint.pformat(values))
79
80 with open(self.config_file, 'w') as f:
81 r = template.render('osmo-ggsn.cfg', values)
82 self.dbg(r)
83 f.write(r)
84
85 def conf_for_client(self):
86 return dict(ggsn=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