blob: 17721731559c3084705d266ec1bd4689de4ea4bc [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 Pedrol786a6bc2020-03-30 13:51:21 +020024from . import enb
25
26def rf_type_valid(rf_type_str):
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +020027 return rf_type_str in ('uhd', 'zmq')
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020028
29#reference: srsLTE.git srslte_symbol_sz()
30def 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
45def num_prb2base_srate(num_prb):
46 return num_prb2symbol_sz(num_prb) * 15 * 1000
47
48class AmarisoftENB(enb.eNodeB):
49
50 REMOTE_DIR = '/osmo-gsm-tester-amarisoftenb'
51 BINFILE = 'lteenb'
Andre Puschmanne4d5a132020-04-14 22:23:06 +020052 CFGFILE = 'amarisoft_enb.cfg'
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020053 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 Pedrol786a6bc2020-03-30 13:51:21 +020062 self.run_dir = None
Pau Espin Pedrol214f15e2020-04-03 16:56:12 +020063 self.inst = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020064 self._bin_prefix = None
65 self.config_file = None
66 self.config_sib1_file = None
67 self.config_sib23_file = None
68 self.config_rf_file = None
69 self.config_drb_file = None
70 self.log_file = None
71 self.process = None
72 self.rem_host = None
Pau Espin Pedrol214f15e2020-04-03 16:56:12 +020073 self.remote_inst = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020074 self.remote_config_file = None
75 self.remote_config_sib1_file = None
76 self.remote_config_sib23_file = None
77 self.remote_config_rf_file = None
78 self.remote_config_drb_file = None
79 self.remote_log_file = None
Andre Puschmanna7f19832020-04-07 14:38:27 +020080 self.enable_measurements = False
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020081 self.suite_run = suite_run
82 self.remote_user = conf.get('remote_user', None)
83 if not rf_type_valid(conf.get('rf_dev_type', None)):
84 raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None))
85
86 def bin_prefix(self):
87 if self._bin_prefix is None:
Pau Espin Pedrol17253af2020-04-02 21:11:19 +020088 self._bin_prefix = os.getenv('AMARISOFT_PATH_ENB', None)
89 if self._bin_prefix == None:
90 self._bin_prefix = self.suite_run.trial.get_inst('amarisoftenb')
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020091 return self._bin_prefix
92
93 def cleanup(self):
94 if self.process is None:
95 return
96 if self.setup_runs_locally():
97 return
98 # copy back files (may not exist, for instance if there was an early error of process):
99 try:
100 self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file)
101 except Exception as e:
102 self.log(repr(e))
103
104
105 def setup_runs_locally(self):
106 return self.remote_user is None
107
108 def start(self, epc):
109 self.log('Starting AmarisoftENB')
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200110 self._epc = epc
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200111 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
112 self.configure()
113 self._start()
114
115 # send t+Enter to enable console trace
116 self.dbg('Enabling console trace')
117 self.process.stdin_write('t\n')
118
119 def _start(self):
120 if self.setup_runs_locally():
121 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(self.inst) }
122 binary = self.inst.child('.', AmarisoftENB.BINFILE)
123 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
124 args = (binary, os.path.abspath(self.config_file))
125 self.process = process.Process(self.name(), self.run_dir, args, env=env)
126 else:
127 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst }
128 remote_binary = self.remote_inst.child('', AmarisoftENB.BINFILE)
129 args = (remote_binary, self.remote_config_file)
130 self.process = self.rem_host.RemoteProcess(AmarisoftENB.BINFILE, args, remote_env=remote_env)
131
132 self.suite_run.remember_to_stop(self.process)
133 self.process.launch()
134
135 def gen_conf_file(self, path, filename, values):
136 self.dbg('AmarisoftENB ' + filename + ':\n' + pprint.pformat(values))
137 with open(path, 'w') as f:
138 r = template.render(filename, values)
139 self.dbg(r)
140 f.write(r)
141
142 def configure(self):
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200143 self.inst = util.Dir(os.path.abspath(self.bin_prefix()))
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200144 if not self.inst.isfile('', AmarisoftENB.BINFILE):
145 raise log.Error('No %s binary in' % AmarisoftENB.BINFILE, self.inst)
146
147 self.config_file = self.run_dir.child(AmarisoftENB.CFGFILE)
148 self.config_sib1_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB1)
149 self.config_sib23_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB23)
150 self.config_rf_file = self.run_dir.child(AmarisoftENB.CFGFILE_RF)
151 self.config_drb_file = self.run_dir.child(AmarisoftENB.CFGFILE_DRB)
152 self.log_file = self.run_dir.child(AmarisoftENB.LOGFILE)
153
154 if not self.setup_runs_locally():
155 self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr)
156 remote_prefix_dir = util.Dir(AmarisoftENB.REMOTE_DIR)
157 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
158 remote_run_dir = util.Dir(remote_prefix_dir.child(AmarisoftENB.BINFILE))
159
160 self.remote_config_file = remote_run_dir.child(AmarisoftENB.CFGFILE)
161 self.remote_config_sib1_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB1)
162 self.remote_config_sib23_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB23)
163 self.remote_config_rf_file = remote_run_dir.child(AmarisoftENB.CFGFILE_RF)
164 self.remote_config_drb_file = remote_run_dir.child(AmarisoftENB.CFGFILE_DRB)
165 self.remote_log_file = remote_run_dir.child(AmarisoftENB.LOGFILE)
166
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +0200167 values = super().configure(['amarisoft', 'amarisoftenb'])
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200168 self._num_cells = int(values['enb'].get('num_cells', None))
169 assert self._num_cells
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200170
Andre Puschmanna7f19832020-04-07 14:38:27 +0200171 # Convert parsed boolean string to Python boolean:
172 self.enable_measurements = util.str2bool(values['enb'].get('enable_measurements', 'false'))
173 config.overlay(values, dict(enb={'enable_measurements': self.enable_measurements}))
174
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200175 # We need to set some specific variables programatically here to match IP addresses:
176 if self._conf.get('rf_dev_type') == 'zmq':
177 base_srate = num_prb2base_srate(self.num_prb())
178 rf_dev_args = 'fail_on_disconnect=true' \
179 + ',tx_port0=tcp://' + self.addr() + ':2000' \
180 + ',tx_port1=tcp://' + self.addr() + ':2002' \
181 + ',rx_port0=tcp://' + self.ue.addr() + ':2001' \
182 + ',rx_port1=tcp://' + self.ue.addr() + ':2003' \
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200183 + ',id=enb,base_srate=' + str(base_srate)
184 config.overlay(values, dict(enb=dict(sample_rate = base_srate / (1000*1000),
185 rf_dev_args=rf_dev_args)))
186
187 # Set UHD frame size as a function of the cell bandwidth on B2XX
Pau Espin Pedrol6b8f5ae2020-04-07 18:51:57 +0200188 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 +0200189 if 'b200' in values['enb'].get('rf_dev_args'):
190 rf_dev_args = values['enb'].get('rf_dev_args', '')
191 rf_dev_args += ',' if rf_dev_args != '' and not rf_dev_args.endswith(',') else ''
192
193 if self._num_prb < 25:
194 rf_dev_args += 'send_frame_size=512,recv_frame_size=512'
195 elif self._num_prb == 25:
196 rf_dev_args += 'send_frame_size=1024,recv_frame_size=1024'
197 elif self._num_prb > 25:
198 rf_dev_args += 'num_recv_frames=64,num_send_frames=64'
199
200 if self._num_prb > 50:
201 # Reduce over the wire format to sc12
202 rf_dev_args += ',otw_format=sc12'
203
204 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
205
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200206 logfile = self.log_file if self.setup_runs_locally() else self.remote_log_file
207 config.overlay(values, dict(enb=dict(log_filename=logfile)))
208
Pau Espin Pedrol65beb8f2020-03-31 12:03:19 +0200209 # rf driver is shared between amarisoft enb and ue, so it has a
210 # different cfg namespace 'trx'. Copy needed values over there:
211 config.overlay(values, dict(trx=dict(rf_dev_type=values['enb'].get('rf_dev_type', None),
212 rf_dev_args=values['enb'].get('rf_dev_args', None))))
213
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200214 self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values)
215 self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values)
216 self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values)
217 self.gen_conf_file(self.config_rf_file, AmarisoftENB.CFGFILE_RF, values)
218 self.gen_conf_file(self.config_drb_file, AmarisoftENB.CFGFILE_DRB, values)
219
220 if not self.setup_runs_locally():
221 self.rem_host.recreate_remote_dir(self.remote_inst)
222 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
223 self.rem_host.recreate_remote_dir(remote_run_dir)
224 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
225 self.rem_host.scp('scp-cfg-sib1-to-remote', self.config_sib1_file, self.remote_config_sib1_file)
226 self.rem_host.scp('scp-cfg-sib23-to-remote', self.config_sib23_file, self.remote_config_sib23_file)
227 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rf_file, self.remote_config_rf_file)
228 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
229
230 def ue_add(self, ue):
231 if self.ue is not None:
232 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
233 self.ue = ue
234
235 def running(self):
236 return not self.process.terminated()
237
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200238# vim: expandtab tabstop=4 shiftwidth=4