blob: e6992031cfb55192d9ec0568f8570cdf9e36fa00 [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
Pau Espin Pedrole8bbcbf2020-04-10 19:51:31 +020023from .core import log, util, config, template, process
24from . import pcap_recorder
Pau Espin Pedrol30ceb5c2017-08-31 18:30:11 +020025
26class OsmoGgsn(log.Origin):
Pau Espin Pedrol30ceb5c2017-08-31 18:30:11 +020027
28 def __init__(self, suite_run, ip_address):
29 super().__init__(log.C_RUN, 'osmo-ggsn_%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 Pedrol30ceb5c2017-08-31 18:30:11 +020033 self.suite_run = suite_run
34 self.ip_address = ip_address
35
36 def start(self):
37 self.log('Starting osmo-ggsn')
38 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
39 self.configure()
40
41 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-ggsn')))
42
43 binary = inst.child('bin', 'osmo-ggsn')
44 if not os.path.isfile(binary):
45 raise log.Error('Binary missing:', binary)
46 lib = inst.child('lib')
47 if not os.path.isdir(lib):
48 raise log.Error('No lib/ in', inst)
49
50 pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), None,
51 'host %s' % self.addr())
52
Pau Espin Pedrolf0b8e372017-12-13 16:08:35 +010053 env = {}
54
55 # setting capabilities will later disable use of LD_LIBRARY_PATH from ELF loader -> modify RPATH instead.
56 self.log('Setting RPATH for osmo-ggsn')
57 util.change_elf_rpath(binary, util.prepend_library_path(lib), self.run_dir.new_dir('patchelf'))
58 # osmo-ggsn requires CAP_NET_ADMIN to create tunnel devices: ioctl(TUNSETIFF):
59 self.log('Applying CAP_NET_ADMIN capability to osmo-ggsn')
60 util.setcap_net_admin(binary, self.run_dir.new_dir('setcap_net_admin'))
Pau Espin Pedrol30ceb5c2017-08-31 18:30:11 +020061
62 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
63 self.process = process.Process(self.name(), self.run_dir,
64 (binary,
65 '-c', os.path.abspath(self.config_file)),
66 env=env)
67 self.suite_run.remember_to_stop(self.process)
68 self.process.launch()
69
70 def configure(self):
71 self.config_file = self.run_dir.new_file('osmo-ggsn.cfg')
72 self.dbg(config_file=self.config_file)
73
74 values = dict(ggsn=config.get_defaults('ggsn'))
75 config.overlay(values, self.suite_run.config())
76 config.overlay(values, dict(ggsn=dict(ip_address=self.ip_address)))
77 config.overlay(values, dict(ggsn=dict(statedir=self.run_dir.new_dir('statedir'))))
78
79 self.dbg('GGSN CONFIG:\n' + pprint.pformat(values))
80
81 with open(self.config_file, 'w') as f:
82 r = template.render('osmo-ggsn.cfg', values)
83 self.dbg(r)
84 f.write(r)
85
86 def conf_for_client(self):
87 return dict(ggsn=dict(ip_address=self.ip_address))
88
89 def addr(self):
90 return self.ip_address.get('addr')
91
92 def running(self):
93 return not self.process.terminated()
94
95# vim: expandtab tabstop=4 shiftwidth=4