Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame^] | 1 | # osmo_gsm_tester: specifics for running an SRS eNodeB process |
| 2 | # |
| 3 | # Copyright (C) 2020 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 | |
| 20 | import os |
| 21 | import pprint |
| 22 | |
| 23 | from . import log, util, config, template, process, remote |
| 24 | |
| 25 | class srsENB(log.Origin): |
| 26 | |
| 27 | REMOTE_DIR = '/osmo-gsm-tester-srsenb' |
| 28 | BINFILE = 'srsenb' |
| 29 | CFGFILE = 'srsenb.conf' |
| 30 | CFGFILE_SIB = 'srsenb_sib.conf' |
| 31 | CFGFILE_RR = 'srsenb_rr.conf' |
| 32 | CFGFILE_DRB = 'srsenb_drb.conf' |
| 33 | LOGFILE = 'srsenb.log' |
| 34 | |
| 35 | def __init__(self, suite_run, conf): |
| 36 | super().__init__(log.C_RUN, 'srsenb') |
| 37 | self._addr = conf.get('addr', None) |
| 38 | if self._addr is None: |
| 39 | raise log.Error('addr not set') |
| 40 | self.set_name('srsenb_%s' % self._addr) |
| 41 | self.ue = None |
| 42 | self.epc = None |
| 43 | self.run_dir = None |
| 44 | self.config_file = None |
| 45 | self.config_sib_file = None |
| 46 | self.config_rr_file = None |
| 47 | self.config_drb_file = None |
| 48 | self.process = None |
| 49 | self.rem_host = None |
| 50 | self.remote_config_file = None |
| 51 | self.remote_config_sib_file = None |
| 52 | self.remote_config_rr_file = None |
| 53 | self.remote_config_drb_file = None |
| 54 | self.remote_log_file = None |
| 55 | self.suite_run = suite_run |
| 56 | self.nof_prb=100 |
| 57 | if self.nof_prb == 75: |
| 58 | self.base_srate=15.36e6 |
| 59 | else: |
| 60 | self.base_srate=23.04e6 |
| 61 | self.remote_user = conf.get('remote_user', None) |
| 62 | |
| 63 | def cleanup(self): |
| 64 | if self.process is None: |
| 65 | return |
| 66 | if self.setup_runs_locally(): |
| 67 | return |
| 68 | # copy back files (may not exist, for instance if there was an early error of process): |
| 69 | try: |
| 70 | self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file) |
| 71 | except Exception as e: |
| 72 | self.log(repr(e)) |
| 73 | |
| 74 | def setup_runs_locally(self): |
| 75 | return self.remote_user is None |
| 76 | |
| 77 | def start(self, epc): |
| 78 | self.log('Starting srsENB') |
| 79 | self.epc = epc |
| 80 | self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name())) |
| 81 | self.configure() |
| 82 | if self.remote_user: |
| 83 | self.start_remotely() |
| 84 | else: |
| 85 | self.start_locally() |
| 86 | |
| 87 | def start_remotely(self): |
| 88 | self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte'))) |
| 89 | lib = self.inst.child('lib') |
| 90 | if not os.path.isdir(lib): |
| 91 | raise log.Error('No lib/ in', self.inst) |
| 92 | if not self.inst.isfile('bin', srsENB.BINFILE): |
| 93 | raise log.Error('No %s binary in' % srsENB.BINFILE, self.inst) |
| 94 | |
| 95 | self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr) |
| 96 | remote_prefix_dir = util.Dir(srsENB.REMOTE_DIR) |
| 97 | self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst)))) |
| 98 | remote_run_dir = util.Dir(remote_prefix_dir.child(srsENB.BINFILE)) |
| 99 | |
| 100 | self.remote_config_file = remote_run_dir.child(srsENB.CFGFILE) |
| 101 | self.remote_config_sib_file = remote_run_dir.child(srsENB.CFGFILE_SIB) |
| 102 | self.remote_config_rr_file = remote_run_dir.child(srsENB.CFGFILE_RR) |
| 103 | self.remote_config_drb_file = remote_run_dir.child(srsENB.CFGFILE_DRB) |
| 104 | self.remote_log_file = remote_run_dir.child(srsENB.LOGFILE) |
| 105 | |
| 106 | self.rem_host.recreate_remote_dir(self.remote_inst) |
| 107 | self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir) |
| 108 | self.rem_host.create_remote_dir(remote_run_dir) |
| 109 | self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file) |
| 110 | self.rem_host.scp('scp-cfg-sib-to-remote', self.config_sib_file, self.remote_config_sib_file) |
| 111 | self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rr_file, self.remote_config_rr_file) |
| 112 | self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file) |
| 113 | |
| 114 | remote_env = { 'LD_LIBRARY_PATH': self.remote_inst.child('lib') } |
| 115 | remote_binary = self.remote_inst.child('bin', srsENB.BINFILE) |
| 116 | args = (remote_binary, self.remote_config_file, |
| 117 | '--enb_files.sib_config=' + self.remote_config_sib_file, |
| 118 | '--enb_files.rr_config=' + self.remote_config_rr_file, |
| 119 | '--enb_files.drb_config=' + self.remote_config_drb_file, |
| 120 | '--rf.device_name=zmq', |
| 121 | '--rf.device_args="fail_on_disconnect=true,tx_port=tcp://'+ self.addr() +':2000,rx_port=tcp://'+ self.ue.addr() +':2001,id=enb,base_srate='+ str(self.base_srate) + '"', |
| 122 | '--expert.nof_phy_threads=1', |
| 123 | '--expert.rrc_inactivity_timer=1500', |
| 124 | '--enb.n_prb=' + str(self.nof_prb), |
| 125 | '--log.filename=' + self.remote_log_file) |
| 126 | |
| 127 | self.process = self.rem_host.RemoteProcessFixIgnoreSIGHUP(srsENB.BINFILE, util.Dir(srsENB.REMOTE_DIR), args, remote_env=remote_env) |
| 128 | self.suite_run.remember_to_stop(self.process) |
| 129 | self.process.launch() |
| 130 | |
| 131 | def start_locally(self): |
| 132 | inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte'))) |
| 133 | |
| 134 | binary = inst.child('bin', BINFILE) |
| 135 | if not os.path.isfile(binary): |
| 136 | raise log.Error('Binary missing:', binary) |
| 137 | lib = inst.child('lib') |
| 138 | if not os.path.isdir(lib): |
| 139 | raise log.Error('No lib/ in', inst) |
| 140 | |
| 141 | env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) } |
| 142 | |
| 143 | self.dbg(run_dir=self.run_dir, binary=binary, env=env) |
| 144 | args = (binary, os.path.abspath(self.config_file), |
| 145 | '--enb_files.sib_config=' + os.path.abspath(self.config_sib_file), |
| 146 | '--enb_files.rr_config=' + os.path.abspath(self.config_rr_file), |
| 147 | '--enb_files.drb_config=' + os.path.abspath(self.config_drb_file), |
| 148 | '--rf.device_name=zmq', |
| 149 | '--rf.device_args="fail_on_disconnect=true,tx_port=tcp://'+ self.addr() +':2000,rx_port=tcp://'+ self.ue.addr() +':2001,id=enb,base_srate='+ str(self.base_srate) + '"', |
| 150 | '--expert.nof_phy_threads=1', |
| 151 | '--expert.rrc_inactivity_timer=1500', |
| 152 | '--enb.n_prb=' + str(self.nof_prb), |
| 153 | '--log.filename=' + self.log_file) |
| 154 | |
| 155 | self.process = process.Process(self.name(), self.run_dir, args, env=env) |
| 156 | self.suite_run.remember_to_stop(self.process) |
| 157 | self.process.launch() |
| 158 | |
| 159 | def gen_conf_file(self, path, filename): |
| 160 | self.dbg(config_file=path) |
| 161 | |
| 162 | values = dict(enb=config.get_defaults('srsenb')) |
| 163 | config.overlay(values, self.suite_run.config()) |
| 164 | config.overlay(values, dict(enb={ 'run_addr': self.addr(), |
| 165 | 'mme_addr': self.epc.addr()})) |
| 166 | |
| 167 | self.dbg('srsENB ' + filename + ':\n' + pprint.pformat(values)) |
| 168 | |
| 169 | with open(path, 'w') as f: |
| 170 | r = template.render(filename, values) |
| 171 | self.dbg(r) |
| 172 | f.write(r) |
| 173 | |
| 174 | def configure(self): |
| 175 | self.config_file = self.run_dir.new_file(srsENB.CFGFILE) |
| 176 | self.config_sib_file = self.run_dir.new_file(srsENB.CFGFILE_SIB) |
| 177 | self.config_rr_file = self.run_dir.new_file(srsENB.CFGFILE_RR) |
| 178 | self.config_drb_file = self.run_dir.new_file(srsENB.CFGFILE_DRB) |
| 179 | self.log_file = self.run_dir.new_file(srsENB.LOGFILE) |
| 180 | |
| 181 | self.gen_conf_file(self.config_file, srsENB.CFGFILE) |
| 182 | self.gen_conf_file(self.config_sib_file, srsENB.CFGFILE_SIB) |
| 183 | self.gen_conf_file(self.config_rr_file, srsENB.CFGFILE_RR) |
| 184 | self.gen_conf_file(self.config_drb_file, srsENB.CFGFILE_DRB) |
| 185 | |
| 186 | def ue_add(self, ue): |
| 187 | if self.ue is not None: |
| 188 | raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)") |
| 189 | self.ue = ue |
| 190 | |
| 191 | def running(self): |
| 192 | return not self.process.terminated() |
| 193 | |
| 194 | def addr(self): |
| 195 | return self._addr |
| 196 | |
| 197 | # vim: expandtab tabstop=4 shiftwidth=4 |