blob: 550cabd0f6110120c0090feda69d3016fea21196 [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
Harald Welte27205342017-06-03 09:51:45 +02008# it under the terms of the GNU General Public License as
Neels Hofmeyr798e5922017-05-18 15:24:02 +02009# 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
Harald Welte27205342017-06-03 09:51:45 +020015# GNU General Public License for more details.
Neels Hofmeyr798e5922017-05-18 15:24:02 +020016#
Harald Welte27205342017-06-03 09:51:45 +020017# You should have received a copy of the GNU General Public License
Neels Hofmeyr798e5922017-05-18 15:24:02 +020018# along with this program. If not, see <http://www.gnu.org/licenses/>.
19
20import os
21import pprint
22
Pau Espin Pedrole1a58bd2020-04-10 20:46:07 +020023from ..core import log, util, config, template, process
Pau Espin Pedrole8bbcbf2020-04-10 19:51:31 +020024from . import pcap_recorder
Neels Hofmeyr798e5922017-05-18 15:24:02 +020025
26class OsmoMgcpgw(log.Origin):
Neels Hofmeyr798e5922017-05-18 15:24:02 +020027
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020028 def __init__(self, testenv, ip_address, bts_ip):
Neels Hofmeyr1a7a3f02017-06-10 01:18:27 +020029 super().__init__(log.C_RUN, 'osmo-mgcpgw_%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 Pedrola442cb82020-05-05 12:54:37 +020033 self.testenv = testenv
Neels Hofmeyr798e5922017-05-18 15:24:02 +020034 self.ip_address = ip_address
Neels Hofmeyr798e5922017-05-18 15:24:02 +020035 # hack: so far mgcpgw needs one specific BTS IP.
36 self.bts_ip = bts_ip
37
38 def start(self):
39 self.log('Starting osmo-mgcpgw')
Pau Espin Pedrol2a2d8462020-05-11 10:56:52 +020040 self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name()))
Neels Hofmeyr798e5922017-05-18 15:24:02 +020041 self.configure()
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020042 inst = util.Dir(os.path.abspath(self.testenv.suite().trial().get_inst('osmo-nitb')))
Neels Hofmeyr798e5922017-05-18 15:24:02 +020043 binary = inst.child('bin', 'osmo-bsc_mgcp')
44 if not os.path.isfile(binary):
45 raise RuntimeError('Binary missing: %r' % binary)
46 lib = inst.child('lib')
47 if not os.path.isdir(lib):
48 raise RuntimeError('No lib/ in %r' % inst)
49
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020050 pcap_recorder.PcapRecorder(self.testenv, self.run_dir.new_dir('pcap'), None,
Neels Hofmeyr798e5922017-05-18 15:24:02 +020051 'host %s and port not 22' % self.addr())
52
53 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
54
55 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
56 self.process = process.Process(self.name(), self.run_dir,
57 (binary, '-c',
58 os.path.abspath(self.config_file)),
59 env=env)
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020060 self.testenv.remember_to_stop(self.process)
Neels Hofmeyr798e5922017-05-18 15:24:02 +020061 self.process.launch()
62
63 def configure(self):
64 self.config_file = self.run_dir.new_file('osmo-mgcpgw.cfg')
65 self.dbg(config_file=self.config_file)
66
67 values = dict(mgcpgw=config.get_defaults('mgcpgw'))
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020068 config.overlay(values, self.testenv.suite().config())
Neels Hofmeyr798e5922017-05-18 15:24:02 +020069 config.overlay(values, dict(mgcpgw=dict(ip_address=self.ip_address, bts_ip=self.bts_ip)))
70
71 self.dbg('MGCPGW CONFIG:\n' + pprint.pformat(values))
72
73 with open(self.config_file, 'w') as f:
74 r = template.render('osmo-mgcpgw.cfg', values)
75 self.dbg(r)
76 f.write(r)
77
78 def addr(self):
79 return self.ip_address.get('addr')
80
81 def conf_for_msc(self):
Pau Espin Pedrol1f5ae7d2017-11-06 14:18:53 +010082 return dict(mgw=dict(ip_address=self.ip_address))
Neels Hofmeyr798e5922017-05-18 15:24:02 +020083
84 def running(self):
85 return not self.process.terminated()
86
87# vim: expandtab tabstop=4 shiftwidth=4