blob: 44b9513188bacff040f42a6d93c91732b82fd645 [file] [log] [blame]
Neels Hofmeyr798e5922017-05-18 15:24:02 +02001# osmo_gsm_tester: specifics for running an osmo-mgcp-gw (osmo-bsc_mgcp)
2#
3# Copyright (C) 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 OsmoMgcpgw(log.Origin):
26 suite_run = None
27 ip_address = None
28 run_dir = None
29 config_file = None
30 process = None
31
32 def __init__(self, suite_run, ip_address, bts_ip):
33 self.suite_run = suite_run
34 self.ip_address = ip_address
35 self.set_log_category(log.C_RUN)
36 self.set_name('osmo-mgcpgw_%s' % ip_address.get('addr'))
37 # hack: so far mgcpgw needs one specific BTS IP.
38 self.bts_ip = bts_ip
39
40 def start(self):
41 self.log('Starting osmo-mgcpgw')
42 self.run_dir = util.Dir(self.suite_run.trial.get_run_dir().new_dir(self.name()))
43 self.configure()
44 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-msc')))
45 binary = inst.child('bin', 'osmo-bsc_mgcp')
46 if not os.path.isfile(binary):
47 raise RuntimeError('Binary missing: %r' % binary)
48 lib = inst.child('lib')
49 if not os.path.isdir(lib):
50 raise RuntimeError('No lib/ in %r' % inst)
51
52 iface = util.ip_to_iface(self.addr())
53 pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), iface,
54 'host %s and port not 22' % self.addr())
55
56 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
57
58 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
59 self.process = process.Process(self.name(), self.run_dir,
60 (binary, '-c',
61 os.path.abspath(self.config_file)),
62 env=env)
63 self.suite_run.remember_to_stop(self.process)
64 self.process.launch()
65
66 def configure(self):
67 self.config_file = self.run_dir.new_file('osmo-mgcpgw.cfg')
68 self.dbg(config_file=self.config_file)
69
70 values = dict(mgcpgw=config.get_defaults('mgcpgw'))
71 config.overlay(values, self.suite_run.config())
72 config.overlay(values, dict(mgcpgw=dict(ip_address=self.ip_address, bts_ip=self.bts_ip)))
73
74 self.dbg('MGCPGW CONFIG:\n' + pprint.pformat(values))
75
76 with open(self.config_file, 'w') as f:
77 r = template.render('osmo-mgcpgw.cfg', values)
78 self.dbg(r)
79 f.write(r)
80
81 def addr(self):
82 return self.ip_address.get('addr')
83
84 def conf_for_msc(self):
85 return dict(mgcpgw=dict(ip_address=self.ip_address))
86
87 def running(self):
88 return not self.process.terminated()
89
90# vim: expandtab tabstop=4 shiftwidth=4