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 | |
Pau Espin Pedrol | e1a58bd | 2020-04-10 20:46:07 +0200 | [diff] [blame] | 23 | from ..core import log, util, config, template, process, remote |
Pau Espin Pedrol | ea8c3d4 | 2020-05-04 12:05:05 +0200 | [diff] [blame] | 24 | from ..core import schema |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 25 | from . import enb |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 26 | from . import rfemu |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 27 | |
Pau Espin Pedrol | ea8c3d4 | 2020-05-04 12:05:05 +0200 | [diff] [blame] | 28 | def on_register_schemas(): |
| 29 | config_schema = { |
| 30 | 'license_server_addr': schema.IPV4, |
| 31 | } |
| 32 | schema.register_config_schema('amarisoft', config_schema) |
| 33 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 34 | def rf_type_valid(rf_type_str): |
Pau Espin Pedrol | d45a29e | 2020-04-02 17:21:47 +0200 | [diff] [blame] | 35 | return rf_type_str in ('uhd', 'zmq') |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 36 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 37 | class AmarisoftENB(enb.eNodeB): |
| 38 | |
| 39 | REMOTE_DIR = '/osmo-gsm-tester-amarisoftenb' |
| 40 | BINFILE = 'lteenb' |
Andre Puschmann | e4d5a13 | 2020-04-14 22:23:06 +0200 | [diff] [blame] | 41 | CFGFILE = 'amarisoft_enb.cfg' |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 42 | CFGFILE_SIB1 = 'amarisoft_sib1.asn' |
| 43 | CFGFILE_SIB23 = 'amarisoft_sib23.asn' |
| 44 | CFGFILE_RF = 'amarisoft_rf_driver.cfg' |
| 45 | CFGFILE_DRB = 'amarisoft_drb.cfg' |
| 46 | LOGFILE = 'lteenb.log' |
| 47 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 48 | def __init__(self, testenv, conf): |
| 49 | super().__init__(testenv, conf, 'amarisoftenb') |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 50 | self.ue = None |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 51 | self.run_dir = None |
Pau Espin Pedrol | 214f15e | 2020-04-03 16:56:12 +0200 | [diff] [blame] | 52 | self.inst = None |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 53 | self._bin_prefix = None |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 54 | self.gen_conf = None |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 55 | self.config_file = None |
| 56 | self.config_sib1_file = None |
| 57 | self.config_sib23_file = None |
| 58 | self.config_rf_file = None |
| 59 | self.config_drb_file = None |
| 60 | self.log_file = None |
| 61 | self.process = None |
| 62 | self.rem_host = None |
Pau Espin Pedrol | 214f15e | 2020-04-03 16:56:12 +0200 | [diff] [blame] | 63 | self.remote_inst = None |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 64 | self.remote_config_file = None |
| 65 | self.remote_config_sib1_file = None |
| 66 | self.remote_config_sib23_file = None |
| 67 | self.remote_config_rf_file = None |
| 68 | self.remote_config_drb_file = None |
| 69 | self.remote_log_file = None |
Andre Puschmann | a7f1983 | 2020-04-07 14:38:27 +0200 | [diff] [blame] | 70 | self.enable_measurements = False |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 71 | self.testenv = testenv |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 72 | self.remote_user = conf.get('remote_user', None) |
| 73 | if not rf_type_valid(conf.get('rf_dev_type', None)): |
| 74 | raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None)) |
| 75 | |
| 76 | def bin_prefix(self): |
| 77 | if self._bin_prefix is None: |
Pau Espin Pedrol | 17253af | 2020-04-02 21:11:19 +0200 | [diff] [blame] | 78 | self._bin_prefix = os.getenv('AMARISOFT_PATH_ENB', None) |
| 79 | if self._bin_prefix == None: |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 80 | self._bin_prefix = self.testenv.suite().trial().get_inst('amarisoftenb') |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 81 | return self._bin_prefix |
| 82 | |
| 83 | def cleanup(self): |
| 84 | if self.process is None: |
| 85 | return |
| 86 | if self.setup_runs_locally(): |
| 87 | return |
| 88 | # copy back files (may not exist, for instance if there was an early error of process): |
| 89 | try: |
| 90 | self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file) |
| 91 | except Exception as e: |
| 92 | self.log(repr(e)) |
| 93 | |
| 94 | |
| 95 | def setup_runs_locally(self): |
| 96 | return self.remote_user is None |
| 97 | |
| 98 | def start(self, epc): |
| 99 | self.log('Starting AmarisoftENB') |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 100 | self._epc = epc |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 101 | self.run_dir = util.Dir(self.testenv.suite().get_run_dir().new_dir(self.name())) |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 102 | self.configure() |
| 103 | self._start() |
| 104 | |
| 105 | # send t+Enter to enable console trace |
| 106 | self.dbg('Enabling console trace') |
| 107 | self.process.stdin_write('t\n') |
| 108 | |
| 109 | def _start(self): |
| 110 | if self.setup_runs_locally(): |
| 111 | env = { 'LD_LIBRARY_PATH': util.prepend_library_path(self.inst) } |
| 112 | binary = self.inst.child('.', AmarisoftENB.BINFILE) |
| 113 | self.dbg(run_dir=self.run_dir, binary=binary, env=env) |
| 114 | args = (binary, os.path.abspath(self.config_file)) |
| 115 | self.process = process.Process(self.name(), self.run_dir, args, env=env) |
| 116 | else: |
| 117 | remote_env = { 'LD_LIBRARY_PATH': self.remote_inst } |
| 118 | remote_binary = self.remote_inst.child('', AmarisoftENB.BINFILE) |
| 119 | args = (remote_binary, self.remote_config_file) |
| 120 | self.process = self.rem_host.RemoteProcess(AmarisoftENB.BINFILE, args, remote_env=remote_env) |
| 121 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 122 | self.testenv.remember_to_stop(self.process) |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 123 | self.process.launch() |
| 124 | |
| 125 | def gen_conf_file(self, path, filename, values): |
| 126 | self.dbg('AmarisoftENB ' + filename + ':\n' + pprint.pformat(values)) |
| 127 | with open(path, 'w') as f: |
| 128 | r = template.render(filename, values) |
| 129 | self.dbg(r) |
| 130 | f.write(r) |
| 131 | |
| 132 | def configure(self): |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 133 | self.inst = util.Dir(os.path.abspath(self.bin_prefix())) |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 134 | if not self.inst.isfile('', AmarisoftENB.BINFILE): |
| 135 | raise log.Error('No %s binary in' % AmarisoftENB.BINFILE, self.inst) |
| 136 | |
| 137 | self.config_file = self.run_dir.child(AmarisoftENB.CFGFILE) |
| 138 | self.config_sib1_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB1) |
| 139 | self.config_sib23_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB23) |
| 140 | self.config_rf_file = self.run_dir.child(AmarisoftENB.CFGFILE_RF) |
| 141 | self.config_drb_file = self.run_dir.child(AmarisoftENB.CFGFILE_DRB) |
| 142 | self.log_file = self.run_dir.child(AmarisoftENB.LOGFILE) |
| 143 | |
| 144 | if not self.setup_runs_locally(): |
| 145 | self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr) |
| 146 | remote_prefix_dir = util.Dir(AmarisoftENB.REMOTE_DIR) |
| 147 | self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst)))) |
| 148 | remote_run_dir = util.Dir(remote_prefix_dir.child(AmarisoftENB.BINFILE)) |
| 149 | |
| 150 | self.remote_config_file = remote_run_dir.child(AmarisoftENB.CFGFILE) |
| 151 | self.remote_config_sib1_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB1) |
| 152 | self.remote_config_sib23_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB23) |
| 153 | self.remote_config_rf_file = remote_run_dir.child(AmarisoftENB.CFGFILE_RF) |
| 154 | self.remote_config_drb_file = remote_run_dir.child(AmarisoftENB.CFGFILE_DRB) |
| 155 | self.remote_log_file = remote_run_dir.child(AmarisoftENB.LOGFILE) |
| 156 | |
Pau Espin Pedrol | c04528c | 2020-04-01 13:55:51 +0200 | [diff] [blame] | 157 | values = super().configure(['amarisoft', 'amarisoftenb']) |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 158 | |
Andre Puschmann | a7f1983 | 2020-04-07 14:38:27 +0200 | [diff] [blame] | 159 | # Convert parsed boolean string to Python boolean: |
| 160 | self.enable_measurements = util.str2bool(values['enb'].get('enable_measurements', 'false')) |
| 161 | config.overlay(values, dict(enb={'enable_measurements': self.enable_measurements})) |
| 162 | |
Pau Espin Pedrol | d45a29e | 2020-04-02 17:21:47 +0200 | [diff] [blame] | 163 | # We need to set some specific variables programatically here to match IP addresses: |
| 164 | if self._conf.get('rf_dev_type') == 'zmq': |
Andre Puschmann | e2a6da6 | 2020-04-20 20:39:34 +0200 | [diff] [blame] | 165 | base_srate = self.num_prb2base_srate(self.num_prb()) |
| 166 | rf_dev_args = self.get_zmq_rf_dev_args() |
Pau Espin Pedrol | d45a29e | 2020-04-02 17:21:47 +0200 | [diff] [blame] | 167 | config.overlay(values, dict(enb=dict(sample_rate = base_srate / (1000*1000), |
Andre Puschmann | e2a6da6 | 2020-04-20 20:39:34 +0200 | [diff] [blame] | 168 | rf_dev_args = rf_dev_args))) |
Pau Espin Pedrol | d45a29e | 2020-04-02 17:21:47 +0200 | [diff] [blame] | 169 | |
| 170 | # Set UHD frame size as a function of the cell bandwidth on B2XX |
Pau Espin Pedrol | 6b8f5ae | 2020-04-07 18:51:57 +0200 | [diff] [blame] | 171 | if self._conf.get('rf_dev_type') == 'uhd' and values['enb'].get('rf_dev_args', None) is not None: |
Pau Espin Pedrol | d45a29e | 2020-04-02 17:21:47 +0200 | [diff] [blame] | 172 | if 'b200' in values['enb'].get('rf_dev_args'): |
| 173 | rf_dev_args = values['enb'].get('rf_dev_args', '') |
| 174 | rf_dev_args += ',' if rf_dev_args != '' and not rf_dev_args.endswith(',') else '' |
| 175 | |
| 176 | if self._num_prb < 25: |
| 177 | rf_dev_args += 'send_frame_size=512,recv_frame_size=512' |
| 178 | elif self._num_prb == 25: |
| 179 | rf_dev_args += 'send_frame_size=1024,recv_frame_size=1024' |
| 180 | elif self._num_prb > 25: |
| 181 | rf_dev_args += 'num_recv_frames=64,num_send_frames=64' |
| 182 | |
| 183 | if self._num_prb > 50: |
| 184 | # Reduce over the wire format to sc12 |
| 185 | rf_dev_args += ',otw_format=sc12' |
| 186 | |
| 187 | config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args))) |
| 188 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 189 | logfile = self.log_file if self.setup_runs_locally() else self.remote_log_file |
| 190 | config.overlay(values, dict(enb=dict(log_filename=logfile))) |
| 191 | |
Pau Espin Pedrol | 65beb8f | 2020-03-31 12:03:19 +0200 | [diff] [blame] | 192 | # rf driver is shared between amarisoft enb and ue, so it has a |
| 193 | # different cfg namespace 'trx'. Copy needed values over there: |
| 194 | config.overlay(values, dict(trx=dict(rf_dev_type=values['enb'].get('rf_dev_type', None), |
Pau Espin Pedrol | a6d6304 | 2020-04-20 15:14:51 +0200 | [diff] [blame] | 195 | rf_dev_args=values['enb'].get('rf_dev_args', None), |
| 196 | rx_gain=values['enb'].get('rx_gain', None), |
| 197 | tx_gain=values['enb'].get('tx_gain', None), |
| 198 | ))) |
Pau Espin Pedrol | 65beb8f | 2020-03-31 12:03:19 +0200 | [diff] [blame] | 199 | |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 200 | self.gen_conf = values |
| 201 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 202 | self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values) |
| 203 | self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values) |
| 204 | self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values) |
| 205 | self.gen_conf_file(self.config_rf_file, AmarisoftENB.CFGFILE_RF, values) |
| 206 | self.gen_conf_file(self.config_drb_file, AmarisoftENB.CFGFILE_DRB, values) |
| 207 | |
| 208 | if not self.setup_runs_locally(): |
| 209 | self.rem_host.recreate_remote_dir(self.remote_inst) |
| 210 | self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir) |
| 211 | self.rem_host.recreate_remote_dir(remote_run_dir) |
| 212 | self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file) |
| 213 | self.rem_host.scp('scp-cfg-sib1-to-remote', self.config_sib1_file, self.remote_config_sib1_file) |
| 214 | self.rem_host.scp('scp-cfg-sib23-to-remote', self.config_sib23_file, self.remote_config_sib23_file) |
| 215 | self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rf_file, self.remote_config_rf_file) |
| 216 | self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file) |
| 217 | |
| 218 | def ue_add(self, ue): |
| 219 | if self.ue is not None: |
| 220 | raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)") |
| 221 | self.ue = ue |
| 222 | |
| 223 | def running(self): |
| 224 | return not self.process.terminated() |
| 225 | |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 226 | def get_rfemu(self, cell=0, dl=True): |
| 227 | cell_list = self.gen_conf['enb'].get('cell_list', None) |
| 228 | if cell_list is None or len(cell_list) < cell + 1: |
| 229 | raise log.Error('cell_list attribute or subitem not found!') |
| 230 | rfemu_cfg = cell_list[cell].get('dl_rfemu', None) |
| 231 | if rfemu_cfg is None: # craft amarisfot by default: |
| 232 | rfemu_cfg = {'type': 'amarisoftctl', |
| 233 | 'addr': self.addr(), |
| 234 | 'ports': [9001] |
| 235 | } |
| 236 | if rfemu_cfg['type'] == 'amarisoftctl': # this one requires extra config: |
| 237 | config.overlay(rfemu_cfg, dict(cell_id=cell_list[cell]['cell_id'])) |
| 238 | rfemu_obj = rfemu.get_instance_by_type(rfemu_cfg['type'], rfemu_cfg) |
| 239 | return rfemu_obj |
| 240 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 241 | # vim: expandtab tabstop=4 shiftwidth=4 |