Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [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 | from . import enb |
| 25 | |
| 26 | def rf_type_valid(rf_type_str): |
| 27 | return rf_type_str in ('uhd') |
| 28 | |
| 29 | #reference: srsLTE.git srslte_symbol_sz() |
| 30 | def num_prb2symbol_sz(num_prb): |
| 31 | if num_prb <= 6: |
| 32 | return 128 |
| 33 | if num_prb <= 15: |
| 34 | return 256 |
| 35 | if num_prb <= 25: |
| 36 | return 384 |
| 37 | if num_prb <= 50: |
| 38 | return 768 |
| 39 | if num_prb <= 75: |
| 40 | return 1024 |
| 41 | if num_prb <= 110: |
| 42 | return 1536 |
| 43 | raise log.Error('invalid num_prb %r', num_prb) |
| 44 | |
| 45 | def num_prb2base_srate(num_prb): |
| 46 | return num_prb2symbol_sz(num_prb) * 15 * 1000 |
| 47 | |
| 48 | class AmarisoftENB(enb.eNodeB): |
| 49 | |
| 50 | REMOTE_DIR = '/osmo-gsm-tester-amarisoftenb' |
| 51 | BINFILE = 'lteenb' |
| 52 | CFGFILE = 'amarisoft_enb.cfg' |
| 53 | CFGFILE_SIB1 = 'amarisoft_sib1.asn' |
| 54 | CFGFILE_SIB23 = 'amarisoft_sib23.asn' |
| 55 | CFGFILE_RF = 'amarisoft_rf_driver.cfg' |
| 56 | CFGFILE_DRB = 'amarisoft_drb.cfg' |
| 57 | LOGFILE = 'lteenb.log' |
| 58 | |
| 59 | def __init__(self, suite_run, conf): |
| 60 | super().__init__(suite_run, conf, 'amarisoftenb') |
| 61 | self.ue = None |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 62 | self.run_dir = None |
| 63 | self._bin_prefix = None |
| 64 | self.config_file = None |
| 65 | self.config_sib1_file = None |
| 66 | self.config_sib23_file = None |
| 67 | self.config_rf_file = None |
| 68 | self.config_drb_file = None |
| 69 | self.log_file = None |
| 70 | self.process = None |
| 71 | self.rem_host = None |
| 72 | self.remote_config_file = None |
| 73 | self.remote_config_sib1_file = None |
| 74 | self.remote_config_sib23_file = None |
| 75 | self.remote_config_rf_file = None |
| 76 | self.remote_config_drb_file = None |
| 77 | self.remote_log_file = None |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 78 | self.suite_run = suite_run |
| 79 | self.remote_user = conf.get('remote_user', None) |
| 80 | if not rf_type_valid(conf.get('rf_dev_type', None)): |
| 81 | raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None)) |
| 82 | |
| 83 | def bin_prefix(self): |
| 84 | if self._bin_prefix is None: |
| 85 | self._bin_prefix = os.getenv('AMARISOFT_PATH_ENB', AmarisoftENB.REMOTE_DIR) |
| 86 | return self._bin_prefix |
| 87 | |
| 88 | def cleanup(self): |
| 89 | if self.process is None: |
| 90 | return |
| 91 | if self.setup_runs_locally(): |
| 92 | return |
| 93 | # copy back files (may not exist, for instance if there was an early error of process): |
| 94 | try: |
| 95 | self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file) |
| 96 | except Exception as e: |
| 97 | self.log(repr(e)) |
| 98 | |
| 99 | |
| 100 | def setup_runs_locally(self): |
| 101 | return self.remote_user is None |
| 102 | |
| 103 | def start(self, epc): |
| 104 | self.log('Starting AmarisoftENB') |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 105 | self._epc = epc |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 106 | self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name())) |
| 107 | self.configure() |
| 108 | self._start() |
| 109 | |
| 110 | # send t+Enter to enable console trace |
| 111 | self.dbg('Enabling console trace') |
| 112 | self.process.stdin_write('t\n') |
| 113 | |
| 114 | def _start(self): |
| 115 | if self.setup_runs_locally(): |
| 116 | env = { 'LD_LIBRARY_PATH': util.prepend_library_path(self.inst) } |
| 117 | binary = self.inst.child('.', AmarisoftENB.BINFILE) |
| 118 | self.dbg(run_dir=self.run_dir, binary=binary, env=env) |
| 119 | args = (binary, os.path.abspath(self.config_file)) |
| 120 | self.process = process.Process(self.name(), self.run_dir, args, env=env) |
| 121 | else: |
| 122 | remote_env = { 'LD_LIBRARY_PATH': self.remote_inst } |
| 123 | remote_binary = self.remote_inst.child('', AmarisoftENB.BINFILE) |
| 124 | args = (remote_binary, self.remote_config_file) |
| 125 | self.process = self.rem_host.RemoteProcess(AmarisoftENB.BINFILE, args, remote_env=remote_env) |
| 126 | |
| 127 | self.suite_run.remember_to_stop(self.process) |
| 128 | self.process.launch() |
| 129 | |
| 130 | def gen_conf_file(self, path, filename, values): |
| 131 | self.dbg('AmarisoftENB ' + filename + ':\n' + pprint.pformat(values)) |
| 132 | with open(path, 'w') as f: |
| 133 | r = template.render(filename, values) |
| 134 | self.dbg(r) |
| 135 | f.write(r) |
| 136 | |
| 137 | def configure(self): |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 138 | self.inst = util.Dir(os.path.abspath(self.bin_prefix())) |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 139 | if not self.inst.isfile('', AmarisoftENB.BINFILE): |
| 140 | raise log.Error('No %s binary in' % AmarisoftENB.BINFILE, self.inst) |
| 141 | |
| 142 | self.config_file = self.run_dir.child(AmarisoftENB.CFGFILE) |
| 143 | self.config_sib1_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB1) |
| 144 | self.config_sib23_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB23) |
| 145 | self.config_rf_file = self.run_dir.child(AmarisoftENB.CFGFILE_RF) |
| 146 | self.config_drb_file = self.run_dir.child(AmarisoftENB.CFGFILE_DRB) |
| 147 | self.log_file = self.run_dir.child(AmarisoftENB.LOGFILE) |
| 148 | |
| 149 | if not self.setup_runs_locally(): |
| 150 | self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr) |
| 151 | remote_prefix_dir = util.Dir(AmarisoftENB.REMOTE_DIR) |
| 152 | self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst)))) |
| 153 | remote_run_dir = util.Dir(remote_prefix_dir.child(AmarisoftENB.BINFILE)) |
| 154 | |
| 155 | self.remote_config_file = remote_run_dir.child(AmarisoftENB.CFGFILE) |
| 156 | self.remote_config_sib1_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB1) |
| 157 | self.remote_config_sib23_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB23) |
| 158 | self.remote_config_rf_file = remote_run_dir.child(AmarisoftENB.CFGFILE_RF) |
| 159 | self.remote_config_drb_file = remote_run_dir.child(AmarisoftENB.CFGFILE_DRB) |
| 160 | self.remote_log_file = remote_run_dir.child(AmarisoftENB.LOGFILE) |
| 161 | |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 162 | values = super().configure('amarisoftenb') |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 163 | self._num_cells = int(values['enb'].get('num_cells', None)) |
| 164 | assert self._num_cells |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 165 | |
| 166 | logfile = self.log_file if self.setup_runs_locally() else self.remote_log_file |
| 167 | config.overlay(values, dict(enb=dict(log_filename=logfile))) |
| 168 | |
| 169 | self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values) |
| 170 | self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values) |
| 171 | self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values) |
| 172 | self.gen_conf_file(self.config_rf_file, AmarisoftENB.CFGFILE_RF, values) |
| 173 | self.gen_conf_file(self.config_drb_file, AmarisoftENB.CFGFILE_DRB, values) |
| 174 | |
| 175 | if not self.setup_runs_locally(): |
| 176 | self.rem_host.recreate_remote_dir(self.remote_inst) |
| 177 | self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir) |
| 178 | self.rem_host.recreate_remote_dir(remote_run_dir) |
| 179 | self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file) |
| 180 | self.rem_host.scp('scp-cfg-sib1-to-remote', self.config_sib1_file, self.remote_config_sib1_file) |
| 181 | self.rem_host.scp('scp-cfg-sib23-to-remote', self.config_sib23_file, self.remote_config_sib23_file) |
| 182 | self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rf_file, self.remote_config_rf_file) |
| 183 | self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file) |
| 184 | |
| 185 | def ue_add(self, ue): |
| 186 | if self.ue is not None: |
| 187 | raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)") |
| 188 | self.ue = ue |
| 189 | |
| 190 | def running(self): |
| 191 | return not self.process.terminated() |
| 192 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 193 | # vim: expandtab tabstop=4 shiftwidth=4 |