Neels Hofmeyr | 798e592 | 2017-05-18 15:24:02 +0200 | [diff] [blame] | 1 | # 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 Welte | 2720534 | 2017-06-03 09:51:45 +0200 | [diff] [blame] | 8 | # it under the terms of the GNU General Public License as |
Neels Hofmeyr | 798e592 | 2017-05-18 15:24:02 +0200 | [diff] [blame] | 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 |
Harald Welte | 2720534 | 2017-06-03 09:51:45 +0200 | [diff] [blame] | 15 | # GNU General Public License for more details. |
Neels Hofmeyr | 798e592 | 2017-05-18 15:24:02 +0200 | [diff] [blame] | 16 | # |
Harald Welte | 2720534 | 2017-06-03 09:51:45 +0200 | [diff] [blame] | 17 | # You should have received a copy of the GNU General Public License |
Neels Hofmeyr | 798e592 | 2017-05-18 15:24:02 +0200 | [diff] [blame] | 18 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 19 | |
| 20 | import os |
| 21 | import pprint |
| 22 | |
| 23 | from . import log, util, config, template, process, osmo_ctrl, pcap_recorder |
| 24 | |
| 25 | class 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): |
Neels Hofmeyr | 1a7a3f0 | 2017-06-10 01:18:27 +0200 | [diff] [blame] | 33 | super().__init__(log.C_RUN, 'osmo-mgcpgw_%s' % ip_address.get('addr')) |
Neels Hofmeyr | 798e592 | 2017-05-18 15:24:02 +0200 | [diff] [blame] | 34 | self.suite_run = suite_run |
| 35 | self.ip_address = ip_address |
Neels Hofmeyr | 798e592 | 2017-05-18 15:24:02 +0200 | [diff] [blame] | 36 | # hack: so far mgcpgw needs one specific BTS IP. |
| 37 | self.bts_ip = bts_ip |
| 38 | |
| 39 | def start(self): |
| 40 | self.log('Starting osmo-mgcpgw') |
Pau Espin Pedrol | d091233 | 2017-06-14 13:27:08 +0200 | [diff] [blame] | 41 | self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name())) |
Neels Hofmeyr | 798e592 | 2017-05-18 15:24:02 +0200 | [diff] [blame] | 42 | self.configure() |
Neels Hofmeyr | 36e0404 | 2017-09-04 16:49:17 +0200 | [diff] [blame] | 43 | inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('osmo-mgw'))) |
Neels Hofmeyr | 798e592 | 2017-05-18 15:24:02 +0200 | [diff] [blame] | 44 | binary = inst.child('bin', 'osmo-bsc_mgcp') |
| 45 | if not os.path.isfile(binary): |
| 46 | raise RuntimeError('Binary missing: %r' % binary) |
| 47 | lib = inst.child('lib') |
| 48 | if not os.path.isdir(lib): |
| 49 | raise RuntimeError('No lib/ in %r' % inst) |
| 50 | |
Pau Espin Pedrol | 9cc1d08 | 2017-11-20 17:40:25 +0100 | [diff] [blame] | 51 | pcap_recorder.PcapRecorder(self.suite_run, self.run_dir.new_dir('pcap'), None, |
Neels Hofmeyr | 798e592 | 2017-05-18 15:24:02 +0200 | [diff] [blame] | 52 | 'host %s and port not 22' % self.addr()) |
| 53 | |
| 54 | env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) } |
| 55 | |
| 56 | self.dbg(run_dir=self.run_dir, binary=binary, env=env) |
| 57 | self.process = process.Process(self.name(), self.run_dir, |
| 58 | (binary, '-c', |
| 59 | os.path.abspath(self.config_file)), |
| 60 | env=env) |
| 61 | self.suite_run.remember_to_stop(self.process) |
| 62 | self.process.launch() |
| 63 | |
| 64 | def configure(self): |
| 65 | self.config_file = self.run_dir.new_file('osmo-mgcpgw.cfg') |
| 66 | self.dbg(config_file=self.config_file) |
| 67 | |
| 68 | values = dict(mgcpgw=config.get_defaults('mgcpgw')) |
| 69 | config.overlay(values, self.suite_run.config()) |
| 70 | config.overlay(values, dict(mgcpgw=dict(ip_address=self.ip_address, bts_ip=self.bts_ip))) |
| 71 | |
| 72 | self.dbg('MGCPGW CONFIG:\n' + pprint.pformat(values)) |
| 73 | |
| 74 | with open(self.config_file, 'w') as f: |
| 75 | r = template.render('osmo-mgcpgw.cfg', values) |
| 76 | self.dbg(r) |
| 77 | f.write(r) |
| 78 | |
| 79 | def addr(self): |
| 80 | return self.ip_address.get('addr') |
| 81 | |
| 82 | def conf_for_msc(self): |
Pau Espin Pedrol | 1f5ae7d | 2017-11-06 14:18:53 +0100 | [diff] [blame] | 83 | return dict(mgw=dict(ip_address=self.ip_address)) |
Neels Hofmeyr | 798e592 | 2017-05-18 15:24:02 +0200 | [diff] [blame] | 84 | |
| 85 | def running(self): |
| 86 | return not self.process.terminated() |
| 87 | |
| 88 | # vim: expandtab tabstop=4 shiftwidth=4 |