blob: b7ede3b907ccde03ef7bbef59c26d5272776ad1d [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
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200179 # We need to set some specific variables programatically here to match IP addresses:
180 if self._conf.get('rf_dev_type') == 'zmq':
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200181 base_srate = self.num_prb2base_srate(self.num_prb())
Pau Espin Pedrol41091232020-10-05 19:23:38 +0200182 rf_dev_args = self.get_zmq_rf_dev_args(values)
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200183 config.overlay(values, dict(enb=dict(sample_rate = base_srate / (1000*1000),
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200184 rf_dev_args = rf_dev_args)))
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200185
186 # Set UHD frame size as a function of the cell bandwidth on B2XX
Pau Espin Pedrol6b8f5ae2020-04-07 18:51:57 +0200187 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 +0200188 if 'b200' in values['enb'].get('rf_dev_args'):
189 rf_dev_args = values['enb'].get('rf_dev_args', '')
190 rf_dev_args += ',' if rf_dev_args != '' and not rf_dev_args.endswith(',') else ''
191
Andre Puschmann0e00f382020-09-23 17:07:07 +0200192 if self._txmode == 1:
193 # SISO config
194 if self._num_prb < 25:
195 rf_dev_args += 'send_frame_size=512,recv_frame_size=512'
196 elif self._num_prb == 25:
197 rf_dev_args += 'send_frame_size=1024,recv_frame_size=1024'
198 else:
199 rf_dev_args += ''
200 else:
201 # MIMO config
202 if self._num_prb == 6:
203 rf_dev_args += 'send_frame_size=512,recv_frame_size=512'
204 else:
205 rf_dev_args += 'num_recv_frames=64,num_send_frames=64'
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200206
Andre Puschmann0e00f382020-09-23 17:07:07 +0200207 if self._num_prb > 50:
208 # Reduce over the wire format to sc12
209 rf_dev_args += ',otw_format=sc12'
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200210
211 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
212
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200213 logfile = self.log_file if self._run_node.is_local() else self.remote_log_file
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200214 config.overlay(values, dict(enb=dict(log_filename=logfile)))
215
Andre Puschmann008fd312020-07-06 12:28:43 +0200216 phy_signal_file = self.phy_signal_file if self._run_node.is_local() else self.remote_phy_signal_file
217 config.overlay(values, dict(enb=dict(phy_signal_file=phy_signal_file)))
218
Pau Espin Pedrol65beb8f2020-03-31 12:03:19 +0200219 # rf driver is shared between amarisoft enb and ue, so it has a
220 # different cfg namespace 'trx'. Copy needed values over there:
221 config.overlay(values, dict(trx=dict(rf_dev_type=values['enb'].get('rf_dev_type', None),
Pau Espin Pedrola6d63042020-04-20 15:14:51 +0200222 rf_dev_args=values['enb'].get('rf_dev_args', None),
Andre Puschmannc489f192020-10-09 14:46:38 +0200223 rf_dev_sync=values['enb'].get('rf_dev_sync', None),
Pau Espin Pedrola6d63042020-04-20 15:14:51 +0200224 rx_gain=values['enb'].get('rx_gain', None),
225 tx_gain=values['enb'].get('tx_gain', None),
226 )))
Pau Espin Pedrol65beb8f2020-03-31 12:03:19 +0200227
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200228 self.gen_conf = values
229
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200230 self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values)
231 self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values)
232 self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values)
233 self.gen_conf_file(self.config_rf_file, AmarisoftENB.CFGFILE_RF, values)
234 self.gen_conf_file(self.config_drb_file, AmarisoftENB.CFGFILE_DRB, values)
235
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200236 if not self._run_node.is_local():
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200237 self.rem_host.recreate_remote_dir(self.remote_inst)
238 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
239 self.rem_host.recreate_remote_dir(remote_run_dir)
240 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
241 self.rem_host.scp('scp-cfg-sib1-to-remote', self.config_sib1_file, self.remote_config_sib1_file)
242 self.rem_host.scp('scp-cfg-sib23-to-remote', self.config_sib23_file, self.remote_config_sib23_file)
243 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rf_file, self.remote_config_rf_file)
244 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
245
246 def ue_add(self, ue):
247 if self.ue is not None:
248 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
249 self.ue = ue
250
251 def running(self):
252 return not self.process.terminated()
253
Andre Puschmannf249a022021-01-05 14:14:48 +0100254 def get_counter(self, counter_name):
255 if counter_name == 'prach_received':
256 return self.process.get_counter_stdout('PRACH:')
257 raise log.Error('counter %s not implemented!' % counter_name)
258
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200259 def get_rfemu(self, cell=0, dl=True):
260 cell_list = self.gen_conf['enb'].get('cell_list', None)
261 if cell_list is None or len(cell_list) < cell + 1:
262 raise log.Error('cell_list attribute or subitem not found!')
263 rfemu_cfg = cell_list[cell].get('dl_rfemu', None)
Andre Puschmannccb63202020-06-12 15:09:00 +0200264 if rfemu_cfg is None: # craft amarisoft by default:
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200265 rfemu_cfg = {'type': 'amarisoftctl',
266 'addr': self.addr(),
267 'ports': [9001]
268 }
269 if rfemu_cfg['type'] == 'amarisoftctl': # this one requires extra config:
270 config.overlay(rfemu_cfg, dict(cell_id=cell_list[cell]['cell_id']))
271 rfemu_obj = rfemu.get_instance_by_type(rfemu_cfg['type'], rfemu_cfg)
272 return rfemu_obj
273
Andre Puschmann7d3b83e2020-09-02 22:17:54 +0200274 def ue_max_rate(self, downlink=True, num_carriers=1):
Andre Puschmannd0682ba2020-10-15 15:46:29 +0200275 if self._duplex == 'fdd':
276 return self.ue_max_rate_fdd(downlink, num_carriers)
277 else:
278 return self.ue_max_rate_tdd(downlink, num_carriers)
279
280 def ue_max_rate_fdd(self, downlink, num_carriers):
Andre Puschmann61d150b2020-05-27 10:37:46 +0200281 # The max rate for a single UE per PRB configuration in TM1 with MCS 28 QAM64
282 max_phy_rate_tm1_dl = { 6 : 3.2e6,
283 15 : 9.2e6,
284 25 : 18e6,
285 50 : 36e6,
286 75 : 55e6,
287 100 : 75e6 }
288 max_phy_rate_tm1_ul = { 6 : 2.0e6,
289 15 : 5.1e6,
290 25 : 10e6,
291 50 : 21e6,
292 75 : 32e6,
Andre Puschmannc1c2f3d2020-09-30 14:41:11 +0200293 100 : 47e6 }
Andre Puschmann61d150b2020-05-27 10:37:46 +0200294 if downlink:
295 max_rate = max_phy_rate_tm1_dl[self.num_prb()]
296 else:
297 max_rate = max_phy_rate_tm1_ul[self.num_prb()]
298
299 # MIMO only supported for Downlink
Andre Puschmannacdf4162020-06-05 14:25:11 +0200300 if downlink:
301 if self._txmode > 2:
302 max_rate *= 2
303 # Lower max MCS for TM2 and above results in lower max rate
304 if self._txmode >= 2 and self.num_prb() <= 25:
305 max_rate *= 0.85
Andre Puschmann61d150b2020-05-27 10:37:46 +0200306
Andre Puschmann7d3b83e2020-09-02 22:17:54 +0200307 # Assume we schedule all carriers
308 max_rate *= num_carriers
309
Andre Puschmann645b5cc2020-09-02 23:02:23 +0200310 # Reduce expected UL rate due to bug in UCI scheduling in Amarisoft eNB
311 if downlink == False and num_carriers == 2:
312 # 2nd carrier @ 25%
313 max_rate = max_rate / 2 + (.25 * max_rate / 2)
314
Andre Puschmann61d150b2020-05-27 10:37:46 +0200315 return max_rate
316
Andre Puschmannd0682ba2020-10-15 15:46:29 +0200317 def ue_max_rate_tdd(self, downlink, num_carriers):
318 # Max rate calculation for TDD depends on the acutal TDD configuration
319 # See: https://www.sharetechnote.com/html/Handbook_LTE_ThroughputCalculationExample_TDD.html
320 # and https://i0.wp.com/www.techtrained.com/wp-content/uploads/2017/09/Blog_Post_1_TDD_Max_Throughput_Theoretical.jpg
321 max_phy_rate_tdd_uldl_config0_sp0 = { 6 : 1.5e6,
322 15 : 3.7e6,
323 25 : 6.1e6,
324 50 : 12.2e6,
325 75 : 18.4e6,
326 100 : 54.5e6 }
327 if downlink:
328 max_rate = max_phy_rate_tdd_uldl_config0_sp0[self.num_prb()]
329 else:
330 return 1e6 # dummy value, we need to replace that later
331
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200332# vim: expandtab tabstop=4 shiftwidth=4