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 | |
Pau Espin Pedrol | a9a2fe2 | 2020-02-13 19:29:55 +0100 | [diff] [blame] | 25 | def rf_type_valid(rf_type_str): |
| 26 | return rf_type_str in ('zmq', 'UHD', 'soapy', 'bladeRF') |
| 27 | |
Pau Espin Pedrol | 2aeadeb | 2020-03-02 11:50:23 +0100 | [diff] [blame] | 28 | #reference: srsLTE.git srslte_symbol_sz() |
| 29 | def num_prb2symbol_sz(num_prb): |
| 30 | if num_prb <= 6: |
| 31 | return 128 |
| 32 | if num_prb <= 15: |
| 33 | return 256 |
| 34 | if num_prb <= 25: |
| 35 | return 384 |
| 36 | if num_prb <= 50: |
| 37 | return 768 |
| 38 | if num_prb <= 75: |
| 39 | return 1024 |
| 40 | if num_prb <= 110: |
| 41 | return 1536 |
| 42 | raise log.Error('invalid num_prb %r', num_prb) |
| 43 | |
| 44 | def num_prb2base_srate(num_prb): |
| 45 | return num_prb2symbol_sz(num_prb) * 15 * 1000 |
| 46 | |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 47 | class srsENB(log.Origin): |
| 48 | |
| 49 | REMOTE_DIR = '/osmo-gsm-tester-srsenb' |
| 50 | BINFILE = 'srsenb' |
| 51 | CFGFILE = 'srsenb.conf' |
| 52 | CFGFILE_SIB = 'srsenb_sib.conf' |
| 53 | CFGFILE_RR = 'srsenb_rr.conf' |
| 54 | CFGFILE_DRB = 'srsenb_drb.conf' |
| 55 | LOGFILE = 'srsenb.log' |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 56 | PCAPFILE = 'srsenb.pcap' |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 57 | |
| 58 | def __init__(self, suite_run, conf): |
| 59 | super().__init__(log.C_RUN, 'srsenb') |
Pau Espin Pedrol | a9a2fe2 | 2020-02-13 19:29:55 +0100 | [diff] [blame] | 60 | self._conf = conf |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 61 | self._addr = conf.get('addr', None) |
| 62 | if self._addr is None: |
| 63 | raise log.Error('addr not set') |
| 64 | self.set_name('srsenb_%s' % self._addr) |
| 65 | self.ue = None |
| 66 | self.epc = None |
| 67 | self.run_dir = None |
| 68 | self.config_file = None |
| 69 | self.config_sib_file = None |
| 70 | self.config_rr_file = None |
| 71 | self.config_drb_file = None |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 72 | self.log_file = None |
| 73 | self.pcap_file = None |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 74 | self.process = None |
| 75 | self.rem_host = None |
| 76 | self.remote_config_file = None |
| 77 | self.remote_config_sib_file = None |
| 78 | self.remote_config_rr_file = None |
| 79 | self.remote_config_drb_file = None |
| 80 | self.remote_log_file = None |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 81 | self.remote_pcap_file = None |
Pau Espin Pedrol | 2aeadeb | 2020-03-02 11:50:23 +0100 | [diff] [blame] | 82 | self._num_prb = 0 |
Pau Espin Pedrol | 151b08a | 2020-03-02 14:14:27 +0100 | [diff] [blame] | 83 | self._txmode = 0 |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 84 | self.enable_pcap = False |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 85 | self.suite_run = suite_run |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 86 | self.remote_user = conf.get('remote_user', None) |
Pau Espin Pedrol | a9a2fe2 | 2020-02-13 19:29:55 +0100 | [diff] [blame] | 87 | if not rf_type_valid(conf.get('rf_dev_type', None)): |
| 88 | raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None)) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 89 | |
| 90 | def cleanup(self): |
| 91 | if self.process is None: |
| 92 | return |
| 93 | if self.setup_runs_locally(): |
| 94 | return |
| 95 | # copy back files (may not exist, for instance if there was an early error of process): |
| 96 | try: |
| 97 | self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file) |
| 98 | except Exception as e: |
| 99 | self.log(repr(e)) |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 100 | if self.enable_pcap: |
| 101 | try: |
| 102 | self.rem_host.scpfrom('scp-back-pcap', self.remote_pcap_file, self.pcap_file) |
| 103 | except Exception as e: |
| 104 | self.log(repr(e)) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 105 | |
| 106 | def setup_runs_locally(self): |
| 107 | return self.remote_user is None |
| 108 | |
| 109 | def start(self, epc): |
| 110 | self.log('Starting srsENB') |
| 111 | self.epc = epc |
| 112 | self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name())) |
| 113 | self.configure() |
| 114 | if self.remote_user: |
| 115 | self.start_remotely() |
| 116 | else: |
| 117 | self.start_locally() |
| 118 | |
| 119 | def start_remotely(self): |
| 120 | self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte'))) |
| 121 | lib = self.inst.child('lib') |
| 122 | if not os.path.isdir(lib): |
| 123 | raise log.Error('No lib/ in', self.inst) |
| 124 | if not self.inst.isfile('bin', srsENB.BINFILE): |
| 125 | raise log.Error('No %s binary in' % srsENB.BINFILE, self.inst) |
| 126 | |
| 127 | self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr) |
| 128 | remote_prefix_dir = util.Dir(srsENB.REMOTE_DIR) |
| 129 | self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst)))) |
| 130 | remote_run_dir = util.Dir(remote_prefix_dir.child(srsENB.BINFILE)) |
| 131 | |
| 132 | self.remote_config_file = remote_run_dir.child(srsENB.CFGFILE) |
| 133 | self.remote_config_sib_file = remote_run_dir.child(srsENB.CFGFILE_SIB) |
| 134 | self.remote_config_rr_file = remote_run_dir.child(srsENB.CFGFILE_RR) |
| 135 | self.remote_config_drb_file = remote_run_dir.child(srsENB.CFGFILE_DRB) |
| 136 | self.remote_log_file = remote_run_dir.child(srsENB.LOGFILE) |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 137 | self.remote_pcap_file = remote_run_dir.child(srsENB.PCAPFILE) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 138 | |
| 139 | self.rem_host.recreate_remote_dir(self.remote_inst) |
| 140 | self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir) |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 141 | self.rem_host.recreate_remote_dir(remote_run_dir) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 142 | self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file) |
| 143 | self.rem_host.scp('scp-cfg-sib-to-remote', self.config_sib_file, self.remote_config_sib_file) |
| 144 | self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rr_file, self.remote_config_rr_file) |
| 145 | self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file) |
| 146 | |
| 147 | remote_env = { 'LD_LIBRARY_PATH': self.remote_inst.child('lib') } |
| 148 | remote_binary = self.remote_inst.child('bin', srsENB.BINFILE) |
| 149 | args = (remote_binary, self.remote_config_file, |
| 150 | '--enb_files.sib_config=' + self.remote_config_sib_file, |
| 151 | '--enb_files.rr_config=' + self.remote_config_rr_file, |
| 152 | '--enb_files.drb_config=' + self.remote_config_drb_file, |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 153 | '--expert.nof_phy_threads=1', |
| 154 | '--expert.rrc_inactivity_timer=1500', |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 155 | '--log.filename=' + self.remote_log_file, |
| 156 | '--pcap.filename=' + self.remote_pcap_file) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 157 | |
| 158 | self.process = self.rem_host.RemoteProcessFixIgnoreSIGHUP(srsENB.BINFILE, util.Dir(srsENB.REMOTE_DIR), args, remote_env=remote_env) |
| 159 | self.suite_run.remember_to_stop(self.process) |
| 160 | self.process.launch() |
| 161 | |
| 162 | def start_locally(self): |
| 163 | inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte'))) |
| 164 | |
| 165 | binary = inst.child('bin', BINFILE) |
| 166 | if not os.path.isfile(binary): |
| 167 | raise log.Error('Binary missing:', binary) |
| 168 | lib = inst.child('lib') |
| 169 | if not os.path.isdir(lib): |
| 170 | raise log.Error('No lib/ in', inst) |
| 171 | |
| 172 | env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) } |
| 173 | |
| 174 | self.dbg(run_dir=self.run_dir, binary=binary, env=env) |
| 175 | args = (binary, os.path.abspath(self.config_file), |
| 176 | '--enb_files.sib_config=' + os.path.abspath(self.config_sib_file), |
| 177 | '--enb_files.rr_config=' + os.path.abspath(self.config_rr_file), |
| 178 | '--enb_files.drb_config=' + os.path.abspath(self.config_drb_file), |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 179 | '--expert.nof_phy_threads=1', |
| 180 | '--expert.rrc_inactivity_timer=1500', |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 181 | '--log.filename=' + self.log_file, |
| 182 | '--pcap.filename=' + self.pcap_file) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 183 | |
| 184 | self.process = process.Process(self.name(), self.run_dir, args, env=env) |
| 185 | self.suite_run.remember_to_stop(self.process) |
| 186 | self.process.launch() |
| 187 | |
| 188 | def gen_conf_file(self, path, filename): |
| 189 | self.dbg(config_file=path) |
| 190 | |
| 191 | values = dict(enb=config.get_defaults('srsenb')) |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 192 | config.overlay(values, dict(enb=self.suite_run.config().get('enb', {}))) |
Pau Espin Pedrol | a9a2fe2 | 2020-02-13 19:29:55 +0100 | [diff] [blame] | 193 | config.overlay(values, dict(enb=self._conf)) |
| 194 | config.overlay(values, dict(enb={ 'mme_addr': self.epc.addr() })) |
| 195 | |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 196 | # Convert parsed boolean string to Python boolean: |
| 197 | self.enable_pcap = util.str2bool(values['enb'].get('enable_pcap', 'false')) |
| 198 | config.overlay(values, dict(enb={'enable_pcap': self.enable_pcap})) |
| 199 | |
Pau Espin Pedrol | 151b08a | 2020-03-02 14:14:27 +0100 | [diff] [blame] | 200 | self._num_prb = int(values['enb'].get('num_prb', None)) |
| 201 | assert self._num_prb |
| 202 | self._txmode = int(values['enb'].get('transmission_mode', None)) |
| 203 | assert self._txmode |
Andre Puschmann | 82b8890 | 2020-03-24 10:04:48 +0100 | [diff] [blame] | 204 | self._num_cells = int(values['enb'].get('num_cells', None)) |
| 205 | assert self._num_cells |
Pau Espin Pedrol | f796ad0 | 2020-03-09 15:50:57 +0100 | [diff] [blame] | 206 | config.overlay(values, dict(enb={ 'num_ports': self.num_ports() })) |
Pau Espin Pedrol | 151b08a | 2020-03-02 14:14:27 +0100 | [diff] [blame] | 207 | |
Pau Espin Pedrol | a9a2fe2 | 2020-02-13 19:29:55 +0100 | [diff] [blame] | 208 | # We need to set some specific variables programatically here to match IP addresses: |
| 209 | if self._conf.get('rf_dev_type') == 'zmq': |
Pau Espin Pedrol | 2aeadeb | 2020-03-02 11:50:23 +0100 | [diff] [blame] | 210 | base_srate = num_prb2base_srate(self._num_prb) |
Pau Espin Pedrol | f796ad0 | 2020-03-09 15:50:57 +0100 | [diff] [blame] | 211 | rf_dev_args = 'fail_on_disconnect=true' \ |
| 212 | + ',tx_port=tcp://' + self.addr() + ':2000' \ |
| 213 | + ',tx_port2=tcp://' + self.addr() + ':2002' \ |
| 214 | + ',rx_port=tcp://' + self.ue.addr() + ':2001' \ |
| 215 | + ',rx_port2=tcp://' + self.ue.addr() + ':2003' \ |
| 216 | + ',id=enb,base_srate=' + str(base_srate) |
Pau Espin Pedrol | 6c42bb5 | 2020-02-27 15:05:11 +0100 | [diff] [blame] | 217 | config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args))) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 218 | |
| 219 | self.dbg('srsENB ' + filename + ':\n' + pprint.pformat(values)) |
| 220 | |
| 221 | with open(path, 'w') as f: |
| 222 | r = template.render(filename, values) |
| 223 | self.dbg(r) |
| 224 | f.write(r) |
| 225 | |
| 226 | def configure(self): |
Pau Espin Pedrol | 1e81b5a | 2020-03-16 12:42:17 +0100 | [diff] [blame] | 227 | self.config_file = self.run_dir.child(srsENB.CFGFILE) |
| 228 | self.config_sib_file = self.run_dir.child(srsENB.CFGFILE_SIB) |
| 229 | self.config_rr_file = self.run_dir.child(srsENB.CFGFILE_RR) |
| 230 | self.config_drb_file = self.run_dir.child(srsENB.CFGFILE_DRB) |
| 231 | self.log_file = self.run_dir.child(srsENB.LOGFILE) |
| 232 | self.pcap_file = self.run_dir.child(srsENB.PCAPFILE) |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 233 | |
| 234 | self.gen_conf_file(self.config_file, srsENB.CFGFILE) |
| 235 | self.gen_conf_file(self.config_sib_file, srsENB.CFGFILE_SIB) |
| 236 | self.gen_conf_file(self.config_rr_file, srsENB.CFGFILE_RR) |
| 237 | self.gen_conf_file(self.config_drb_file, srsENB.CFGFILE_DRB) |
| 238 | |
| 239 | def ue_add(self, ue): |
| 240 | if self.ue is not None: |
| 241 | raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)") |
| 242 | self.ue = ue |
| 243 | |
| 244 | def running(self): |
| 245 | return not self.process.terminated() |
| 246 | |
| 247 | def addr(self): |
| 248 | return self._addr |
| 249 | |
Pau Espin Pedrol | 2aeadeb | 2020-03-02 11:50:23 +0100 | [diff] [blame] | 250 | def num_prb(self): |
| 251 | return self._num_prb |
| 252 | |
Andre Puschmann | 82b8890 | 2020-03-24 10:04:48 +0100 | [diff] [blame] | 253 | def num_cells(self): |
| 254 | return self._num_cells |
| 255 | |
Pau Espin Pedrol | f796ad0 | 2020-03-09 15:50:57 +0100 | [diff] [blame] | 256 | def num_ports(self): |
| 257 | if self._txmode == 1: |
| 258 | return 1 |
| 259 | return 2 |
| 260 | |
Pau Espin Pedrol | 151b08a | 2020-03-02 14:14:27 +0100 | [diff] [blame] | 261 | def ue_max_rate(self, downlink=True): |
Andre Puschmann | e227fa3 | 2020-03-19 21:14:04 +0100 | [diff] [blame] | 262 | # The max rate for a single UE per PRB configuration in TM1 |
| 263 | max_phy_rate_tm1_dl = { 6 : 3.5e6, |
| 264 | 15 : 11e6, |
| 265 | 25 : 18e6, |
Pau Espin Pedrol | 151b08a | 2020-03-02 14:14:27 +0100 | [diff] [blame] | 266 | 50 : 36e6, |
Andre Puschmann | e227fa3 | 2020-03-19 21:14:04 +0100 | [diff] [blame] | 267 | 75 : 55e6, |
Pau Espin Pedrol | 151b08a | 2020-03-02 14:14:27 +0100 | [diff] [blame] | 268 | 100 : 75e6 } |
Andre Puschmann | e227fa3 | 2020-03-19 21:14:04 +0100 | [diff] [blame] | 269 | max_phy_rate_tm1_ul = { 6 : 0.9e6, |
| 270 | 15 : 4.7e6, |
| 271 | 25 : 10e6, |
| 272 | 50 : 23e6, |
| 273 | 75 : 34e6, |
| 274 | 100 : 51e6 } |
Pau Espin Pedrol | 151b08a | 2020-03-02 14:14:27 +0100 | [diff] [blame] | 275 | if downlink: |
| 276 | max_rate = max_phy_rate_tm1_dl[self.num_prb()] |
| 277 | else: |
| 278 | max_rate = max_phy_rate_tm1_ul[self.num_prb()] |
| 279 | #TODO: calculate for non-standard prb numbers. |
| 280 | if self._txmode > 2: |
| 281 | max_rate *= 2 |
| 282 | # We use 3 control symbols for 6, 15 and 25 PRBs which results in lower max rate |
| 283 | if self.num_prb() < 50: |
| 284 | max_rate *= 0.9 |
| 285 | return max_rate |
| 286 | |
Pau Espin Pedrol | c8b0f93 | 2020-02-11 17:45:26 +0100 | [diff] [blame] | 287 | # vim: expandtab tabstop=4 shiftwidth=4 |