blob: e97bb90fccb26d0377de5fe2362c82c065a5e896 [file] [log] [blame]
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +02001# 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
20import os
21import pprint
22
Pau Espin Pedrole1a58bd2020-04-10 20:46:07 +020023from ..core import log, util, config, template, process, remote
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020024from ..core import schema
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020025from . import enb
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020026from . import rfemu
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020027
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020028def on_register_schemas():
29 config_schema = {
30 'license_server_addr': schema.IPV4,
31 }
32 schema.register_config_schema('amarisoft', config_schema)
33
Andre Puschmann2ebcff92020-07-01 12:28:31 +020034 config_schema = {
35 'log_options': schema.STR,
36 }
37 schema.register_config_schema('amarisoftenb', config_schema)
38
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020039def rf_type_valid(rf_type_str):
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +020040 return rf_type_str in ('uhd', 'zmq')
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020041
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020042class AmarisoftENB(enb.eNodeB):
43
44 REMOTE_DIR = '/osmo-gsm-tester-amarisoftenb'
45 BINFILE = 'lteenb'
Andre Puschmanne4d5a132020-04-14 22:23:06 +020046 CFGFILE = 'amarisoft_enb.cfg'
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020047 CFGFILE_SIB1 = 'amarisoft_sib1.asn'
48 CFGFILE_SIB23 = 'amarisoft_sib23.asn'
49 CFGFILE_RF = 'amarisoft_rf_driver.cfg'
50 CFGFILE_DRB = 'amarisoft_drb.cfg'
51 LOGFILE = 'lteenb.log'
Andre Puschmann008fd312020-07-06 12:28:43 +020052 PHY_SIGNAL_FILE = 'lteenb.log.bin'
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020053
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020054 def __init__(self, testenv, conf):
55 super().__init__(testenv, conf, 'amarisoftenb')
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020056 self.ue = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020057 self.run_dir = None
Pau Espin Pedrol214f15e2020-04-03 16:56:12 +020058 self.inst = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020059 self._bin_prefix = None
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020060 self.gen_conf = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020061 self.config_file = None
62 self.config_sib1_file = None
63 self.config_sib23_file = None
64 self.config_rf_file = None
65 self.config_drb_file = None
66 self.log_file = None
67 self.process = None
68 self.rem_host = None
Pau Espin Pedrol214f15e2020-04-03 16:56:12 +020069 self.remote_inst = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020070 self.remote_config_file = None
71 self.remote_config_sib1_file = None
72 self.remote_config_sib23_file = None
73 self.remote_config_rf_file = None
74 self.remote_config_drb_file = None
75 self.remote_log_file = None
Andre Puschmanna7f19832020-04-07 14:38:27 +020076 self.enable_measurements = False
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020077 self.testenv = testenv
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020078 if not rf_type_valid(conf.get('rf_dev_type', None)):
79 raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None))
80
81 def bin_prefix(self):
82 if self._bin_prefix is None:
Pau Espin Pedrol17253af2020-04-02 21:11:19 +020083 self._bin_prefix = os.getenv('AMARISOFT_PATH_ENB', None)
84 if self._bin_prefix == None:
Pau Espin Pedrolb452ed62020-05-26 12:51:44 +020085 self._bin_prefix = self.testenv.suite().trial().get_inst('amarisoftenb', self._run_node.run_label())
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020086 return self._bin_prefix
87
88 def cleanup(self):
89 if self.process is None:
90 return
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020091 if self._run_node.is_local():
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020092 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
Andre Puschmann008fd312020-07-06 12:28:43 +020099 try:
100 self.rem_host.scpfrom('scp-back-phy-signal-log', self.remote_phy_signal_file, self.phy_signal_file)
101 except Exception as e:
102 self.log(repr(e))
Pau Espin Pedrol41091232020-10-05 19:23:38 +0200103 # Clean up for parent class:
104 super().cleanup()
Andre Puschmann008fd312020-07-06 12:28:43 +0200105
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200106 def start(self, epc):
107 self.log('Starting AmarisoftENB')
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200108 self._epc = epc
Pau Espin Pedrol2a2d8462020-05-11 10:56:52 +0200109 self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name()))
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200110 self.configure()
111 self._start()
112
113 # send t+Enter to enable console trace
114 self.dbg('Enabling console trace')
115 self.process.stdin_write('t\n')
116
117 def _start(self):
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200118 if self._run_node.is_local():
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200119 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(self.inst) }
120 binary = self.inst.child('.', AmarisoftENB.BINFILE)
121 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
122 args = (binary, os.path.abspath(self.config_file))
123 self.process = process.Process(self.name(), self.run_dir, args, env=env)
124 else:
125 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst }
126 remote_binary = self.remote_inst.child('', AmarisoftENB.BINFILE)
127 args = (remote_binary, self.remote_config_file)
128 self.process = self.rem_host.RemoteProcess(AmarisoftENB.BINFILE, args, remote_env=remote_env)
129
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200130 self.testenv.remember_to_stop(self.process)
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200131 self.process.launch()
132
Andre Puschmann215bec22021-01-08 12:34:48 +0100133 def stop(self):
134 # Not implemented
135 pass
136
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200137 def gen_conf_file(self, path, filename, values):
138 self.dbg('AmarisoftENB ' + filename + ':\n' + pprint.pformat(values))
139 with open(path, 'w') as f:
140 r = template.render(filename, values)
141 self.dbg(r)
142 f.write(r)
143
144 def configure(self):
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200145 self.inst = util.Dir(os.path.abspath(self.bin_prefix()))
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200146 if not self.inst.isfile('', AmarisoftENB.BINFILE):
147 raise log.Error('No %s binary in' % AmarisoftENB.BINFILE, self.inst)
148
149 self.config_file = self.run_dir.child(AmarisoftENB.CFGFILE)
150 self.config_sib1_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB1)
151 self.config_sib23_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB23)
152 self.config_rf_file = self.run_dir.child(AmarisoftENB.CFGFILE_RF)
153 self.config_drb_file = self.run_dir.child(AmarisoftENB.CFGFILE_DRB)
154 self.log_file = self.run_dir.child(AmarisoftENB.LOGFILE)
Andre Puschmann008fd312020-07-06 12:28:43 +0200155 self.phy_signal_file = self.run_dir.child(AmarisoftENB.PHY_SIGNAL_FILE)
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200156
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200157 if not self._run_node.is_local():
158 self.rem_host = remote.RemoteHost(self.run_dir, self._run_node.ssh_user(), self._run_node.ssh_addr())
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200159 remote_prefix_dir = util.Dir(AmarisoftENB.REMOTE_DIR)
160 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
161 remote_run_dir = util.Dir(remote_prefix_dir.child(AmarisoftENB.BINFILE))
162
163 self.remote_config_file = remote_run_dir.child(AmarisoftENB.CFGFILE)
164 self.remote_config_sib1_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB1)
165 self.remote_config_sib23_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB23)
166 self.remote_config_rf_file = remote_run_dir.child(AmarisoftENB.CFGFILE_RF)
167 self.remote_config_drb_file = remote_run_dir.child(AmarisoftENB.CFGFILE_DRB)
168 self.remote_log_file = remote_run_dir.child(AmarisoftENB.LOGFILE)
Andre Puschmann008fd312020-07-06 12:28:43 +0200169 self.remote_phy_signal_file = remote_run_dir.child(AmarisoftENB.PHY_SIGNAL_FILE)
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200170
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +0200171 values = super().configure(['amarisoft', 'amarisoftenb'])
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200172
Andre Puschmanna7f19832020-04-07 14:38:27 +0200173 # Convert parsed boolean string to Python boolean:
174 self.enable_measurements = util.str2bool(values['enb'].get('enable_measurements', 'false'))
175 config.overlay(values, dict(enb={'enable_measurements': self.enable_measurements}))
176
Andre Puschmann955249d2020-07-01 15:44:09 +0200177 config.overlay(values, dict(enb={'enable_dl_awgn': util.str2bool(values['enb'].get('enable_dl_awgn', 'false'))}))
178
Nils Fürstea8180152020-12-03 14:14:31 +0100179 # Remove EEA0 from cipher list, if specified, as it's always assumed as default
180 cipher_list = values['enb'].get('cipher_list', None)
181 if "eea0" in cipher_list: cipher_list.remove("eea0")
182
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200183 # We need to set some specific variables programatically here to match IP addresses:
184 if self._conf.get('rf_dev_type') == 'zmq':
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200185 base_srate = self.num_prb2base_srate(self.num_prb())
Pau Espin Pedrol41091232020-10-05 19:23:38 +0200186 rf_dev_args = self.get_zmq_rf_dev_args(values)
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200187 config.overlay(values, dict(enb=dict(sample_rate = base_srate / (1000*1000),
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200188 rf_dev_args = rf_dev_args)))
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200189
190 # Set UHD frame size as a function of the cell bandwidth on B2XX
Pau Espin Pedrol6b8f5ae2020-04-07 18:51:57 +0200191 if self._conf.get('rf_dev_type') == 'uhd' and values['enb'].get('rf_dev_args', None) is not None:
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200192 if 'b200' in values['enb'].get('rf_dev_args'):
193 rf_dev_args = values['enb'].get('rf_dev_args', '')
194 rf_dev_args += ',' if rf_dev_args != '' and not rf_dev_args.endswith(',') else ''
195
Andre Puschmann0e00f382020-09-23 17:07:07 +0200196 if self._txmode == 1:
197 # SISO config
198 if self._num_prb < 25:
199 rf_dev_args += 'send_frame_size=512,recv_frame_size=512'
200 elif self._num_prb == 25:
201 rf_dev_args += 'send_frame_size=1024,recv_frame_size=1024'
202 else:
203 rf_dev_args += ''
204 else:
205 # MIMO config
206 if self._num_prb == 6:
207 rf_dev_args += 'send_frame_size=512,recv_frame_size=512'
208 else:
209 rf_dev_args += 'num_recv_frames=64,num_send_frames=64'
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200210
Andre Puschmann0e00f382020-09-23 17:07:07 +0200211 if self._num_prb > 50:
212 # Reduce over the wire format to sc12
213 rf_dev_args += ',otw_format=sc12'
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200214
215 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
216
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200217 logfile = self.log_file if self._run_node.is_local() else self.remote_log_file
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200218 config.overlay(values, dict(enb=dict(log_filename=logfile)))
219
Andre Puschmann008fd312020-07-06 12:28:43 +0200220 phy_signal_file = self.phy_signal_file if self._run_node.is_local() else self.remote_phy_signal_file
221 config.overlay(values, dict(enb=dict(phy_signal_file=phy_signal_file)))
222
Pau Espin Pedrol65beb8f2020-03-31 12:03:19 +0200223 # rf driver is shared between amarisoft enb and ue, so it has a
224 # different cfg namespace 'trx'. Copy needed values over there:
225 config.overlay(values, dict(trx=dict(rf_dev_type=values['enb'].get('rf_dev_type', None),
Pau Espin Pedrola6d63042020-04-20 15:14:51 +0200226 rf_dev_args=values['enb'].get('rf_dev_args', None),
Andre Puschmannc489f192020-10-09 14:46:38 +0200227 rf_dev_sync=values['enb'].get('rf_dev_sync', None),
Pau Espin Pedrola6d63042020-04-20 15:14:51 +0200228 rx_gain=values['enb'].get('rx_gain', None),
229 tx_gain=values['enb'].get('tx_gain', None),
230 )))
Pau Espin Pedrol65beb8f2020-03-31 12:03:19 +0200231
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200232 self.gen_conf = values
233
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200234 self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values)
235 self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values)
236 self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values)
237 self.gen_conf_file(self.config_rf_file, AmarisoftENB.CFGFILE_RF, values)
238 self.gen_conf_file(self.config_drb_file, AmarisoftENB.CFGFILE_DRB, values)
239
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200240 if not self._run_node.is_local():
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200241 self.rem_host.recreate_remote_dir(self.remote_inst)
242 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
243 self.rem_host.recreate_remote_dir(remote_run_dir)
244 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
245 self.rem_host.scp('scp-cfg-sib1-to-remote', self.config_sib1_file, self.remote_config_sib1_file)
246 self.rem_host.scp('scp-cfg-sib23-to-remote', self.config_sib23_file, self.remote_config_sib23_file)
247 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rf_file, self.remote_config_rf_file)
248 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
249
250 def ue_add(self, ue):
251 if self.ue is not None:
252 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
253 self.ue = ue
254
255 def running(self):
256 return not self.process.terminated()
257
Andre Puschmannf249a022021-01-05 14:14:48 +0100258 def get_counter(self, counter_name):
259 if counter_name == 'prach_received':
260 return self.process.get_counter_stdout('PRACH:')
261 raise log.Error('counter %s not implemented!' % counter_name)
262
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200263 def get_rfemu(self, cell=0, dl=True):
264 cell_list = self.gen_conf['enb'].get('cell_list', None)
265 if cell_list is None or len(cell_list) < cell + 1:
266 raise log.Error('cell_list attribute or subitem not found!')
267 rfemu_cfg = cell_list[cell].get('dl_rfemu', None)
Andre Puschmannccb63202020-06-12 15:09:00 +0200268 if rfemu_cfg is None: # craft amarisoft by default:
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200269 rfemu_cfg = {'type': 'amarisoftctl',
270 'addr': self.addr(),
271 'ports': [9001]
272 }
273 if rfemu_cfg['type'] == 'amarisoftctl': # this one requires extra config:
274 config.overlay(rfemu_cfg, dict(cell_id=cell_list[cell]['cell_id']))
275 rfemu_obj = rfemu.get_instance_by_type(rfemu_cfg['type'], rfemu_cfg)
276 return rfemu_obj
277
Andre Puschmann7d3b83e2020-09-02 22:17:54 +0200278 def ue_max_rate(self, downlink=True, num_carriers=1):
Andre Puschmannd0682ba2020-10-15 15:46:29 +0200279 if self._duplex == 'fdd':
280 return self.ue_max_rate_fdd(downlink, num_carriers)
281 else:
282 return self.ue_max_rate_tdd(downlink, num_carriers)
283
284 def ue_max_rate_fdd(self, downlink, num_carriers):
Andre Puschmann61d150b2020-05-27 10:37:46 +0200285 # The max rate for a single UE per PRB configuration in TM1 with MCS 28 QAM64
286 max_phy_rate_tm1_dl = { 6 : 3.2e6,
287 15 : 9.2e6,
288 25 : 18e6,
289 50 : 36e6,
290 75 : 55e6,
291 100 : 75e6 }
292 max_phy_rate_tm1_ul = { 6 : 2.0e6,
293 15 : 5.1e6,
294 25 : 10e6,
295 50 : 21e6,
296 75 : 32e6,
Andre Puschmannc1c2f3d2020-09-30 14:41:11 +0200297 100 : 47e6 }
Andre Puschmann61d150b2020-05-27 10:37:46 +0200298 if downlink:
299 max_rate = max_phy_rate_tm1_dl[self.num_prb()]
300 else:
301 max_rate = max_phy_rate_tm1_ul[self.num_prb()]
302
303 # MIMO only supported for Downlink
Andre Puschmannacdf4162020-06-05 14:25:11 +0200304 if downlink:
305 if self._txmode > 2:
306 max_rate *= 2
307 # Lower max MCS for TM2 and above results in lower max rate
308 if self._txmode >= 2 and self.num_prb() <= 25:
309 max_rate *= 0.85
Andre Puschmann61d150b2020-05-27 10:37:46 +0200310
Andre Puschmann7d3b83e2020-09-02 22:17:54 +0200311 # Assume we schedule all carriers
312 max_rate *= num_carriers
313
Andre Puschmann645b5cc2020-09-02 23:02:23 +0200314 # Reduce expected UL rate due to bug in UCI scheduling in Amarisoft eNB
315 if downlink == False and num_carriers == 2:
316 # 2nd carrier @ 25%
317 max_rate = max_rate / 2 + (.25 * max_rate / 2)
318
Andre Puschmann61d150b2020-05-27 10:37:46 +0200319 return max_rate
320
Andre Puschmannd0682ba2020-10-15 15:46:29 +0200321 def ue_max_rate_tdd(self, downlink, num_carriers):
322 # Max rate calculation for TDD depends on the acutal TDD configuration
323 # See: https://www.sharetechnote.com/html/Handbook_LTE_ThroughputCalculationExample_TDD.html
324 # and https://i0.wp.com/www.techtrained.com/wp-content/uploads/2017/09/Blog_Post_1_TDD_Max_Throughput_Theoretical.jpg
325 max_phy_rate_tdd_uldl_config0_sp0 = { 6 : 1.5e6,
326 15 : 3.7e6,
327 25 : 6.1e6,
328 50 : 12.2e6,
329 75 : 18.4e6,
330 100 : 54.5e6 }
331 if downlink:
332 max_rate = max_phy_rate_tdd_uldl_config0_sp0[self.num_prb()]
333 else:
334 return 1e6 # dummy value, we need to replace that later
335
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200336# vim: expandtab tabstop=4 shiftwidth=4