blob: 364b3fd9feaf1cdc7e76294ba9cabc1930497c4e [file] [log] [blame]
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +01001# 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
23from . import log, util, config, template, process, remote
24
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +010025def rf_type_valid(rf_type_str):
26 return rf_type_str in ('zmq', 'UHD', 'soapy', 'bladeRF')
27
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +010028#reference: srsLTE.git srslte_symbol_sz()
29def 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
44def num_prb2base_srate(num_prb):
45 return num_prb2symbol_sz(num_prb) * 15 * 1000
46
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010047class 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 Pedrol1e81b5a2020-03-16 12:42:17 +010056 PCAPFILE = 'srsenb.pcap'
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010057
58 def __init__(self, suite_run, conf):
59 super().__init__(log.C_RUN, 'srsenb')
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +010060 self._conf = conf
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010061 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 Pedrol1e81b5a2020-03-16 12:42:17 +010072 self.log_file = None
73 self.pcap_file = None
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010074 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 Pedrol1e81b5a2020-03-16 12:42:17 +010081 self.remote_pcap_file = None
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +010082 self._num_prb = 0
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +010083 self._txmode = 0
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +010084 self.enable_pcap = False
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010085 self.suite_run = suite_run
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010086 self.remote_user = conf.get('remote_user', None)
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +010087 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 Pedrolc8b0f932020-02-11 17:45:26 +010089
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 Pedrol1e81b5a2020-03-16 12:42:17 +0100100 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 Pedrolc8b0f932020-02-11 17:45:26 +0100105
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
Andre Puschmannc2c82212020-03-24 16:39:35 +0100119 # send t+Enter to enable console trace
120 self.dbg('Enabling console trace')
121 self.process.stdin_write('t\n')
122
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100123 def start_remotely(self):
124 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte')))
125 lib = self.inst.child('lib')
126 if not os.path.isdir(lib):
127 raise log.Error('No lib/ in', self.inst)
128 if not self.inst.isfile('bin', srsENB.BINFILE):
129 raise log.Error('No %s binary in' % srsENB.BINFILE, self.inst)
130
131 self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr)
132 remote_prefix_dir = util.Dir(srsENB.REMOTE_DIR)
133 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
134 remote_run_dir = util.Dir(remote_prefix_dir.child(srsENB.BINFILE))
135
136 self.remote_config_file = remote_run_dir.child(srsENB.CFGFILE)
137 self.remote_config_sib_file = remote_run_dir.child(srsENB.CFGFILE_SIB)
138 self.remote_config_rr_file = remote_run_dir.child(srsENB.CFGFILE_RR)
139 self.remote_config_drb_file = remote_run_dir.child(srsENB.CFGFILE_DRB)
140 self.remote_log_file = remote_run_dir.child(srsENB.LOGFILE)
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100141 self.remote_pcap_file = remote_run_dir.child(srsENB.PCAPFILE)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100142
143 self.rem_host.recreate_remote_dir(self.remote_inst)
144 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100145 self.rem_host.recreate_remote_dir(remote_run_dir)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100146 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
147 self.rem_host.scp('scp-cfg-sib-to-remote', self.config_sib_file, self.remote_config_sib_file)
148 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rr_file, self.remote_config_rr_file)
149 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
150
151 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst.child('lib') }
152 remote_binary = self.remote_inst.child('bin', srsENB.BINFILE)
153 args = (remote_binary, self.remote_config_file,
154 '--enb_files.sib_config=' + self.remote_config_sib_file,
155 '--enb_files.rr_config=' + self.remote_config_rr_file,
156 '--enb_files.drb_config=' + self.remote_config_drb_file,
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100157 '--expert.nof_phy_threads=1',
158 '--expert.rrc_inactivity_timer=1500',
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100159 '--log.filename=' + self.remote_log_file,
160 '--pcap.filename=' + self.remote_pcap_file)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100161
Andre Puschmannc2c82212020-03-24 16:39:35 +0100162 self.process = self.rem_host.RemoteProcess(srsENB.BINFILE, args, remote_env=remote_env)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100163 self.suite_run.remember_to_stop(self.process)
164 self.process.launch()
165
166 def start_locally(self):
167 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte')))
168
169 binary = inst.child('bin', BINFILE)
170 if not os.path.isfile(binary):
171 raise log.Error('Binary missing:', binary)
172 lib = inst.child('lib')
173 if not os.path.isdir(lib):
174 raise log.Error('No lib/ in', inst)
175
176 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
177
178 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
179 args = (binary, os.path.abspath(self.config_file),
180 '--enb_files.sib_config=' + os.path.abspath(self.config_sib_file),
181 '--enb_files.rr_config=' + os.path.abspath(self.config_rr_file),
182 '--enb_files.drb_config=' + os.path.abspath(self.config_drb_file),
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100183 '--expert.nof_phy_threads=1',
184 '--expert.rrc_inactivity_timer=1500',
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100185 '--log.filename=' + self.log_file,
186 '--pcap.filename=' + self.pcap_file)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100187
188 self.process = process.Process(self.name(), self.run_dir, args, env=env)
189 self.suite_run.remember_to_stop(self.process)
190 self.process.launch()
191
192 def gen_conf_file(self, path, filename):
193 self.dbg(config_file=path)
194
195 values = dict(enb=config.get_defaults('srsenb'))
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100196 config.overlay(values, dict(enb=self.suite_run.config().get('enb', {})))
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +0100197 config.overlay(values, dict(enb=self._conf))
198 config.overlay(values, dict(enb={ 'mme_addr': self.epc.addr() }))
199
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100200 # Convert parsed boolean string to Python boolean:
201 self.enable_pcap = util.str2bool(values['enb'].get('enable_pcap', 'false'))
202 config.overlay(values, dict(enb={'enable_pcap': self.enable_pcap}))
203
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100204 self._num_prb = int(values['enb'].get('num_prb', None))
205 assert self._num_prb
206 self._txmode = int(values['enb'].get('transmission_mode', None))
207 assert self._txmode
Andre Puschmann82b88902020-03-24 10:04:48 +0100208 self._num_cells = int(values['enb'].get('num_cells', None))
209 assert self._num_cells
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100210 config.overlay(values, dict(enb={ 'num_ports': self.num_ports() }))
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100211
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +0100212 # We need to set some specific variables programatically here to match IP addresses:
213 if self._conf.get('rf_dev_type') == 'zmq':
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +0100214 base_srate = num_prb2base_srate(self._num_prb)
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100215 rf_dev_args = 'fail_on_disconnect=true' \
216 + ',tx_port=tcp://' + self.addr() + ':2000' \
217 + ',tx_port2=tcp://' + self.addr() + ':2002' \
218 + ',rx_port=tcp://' + self.ue.addr() + ':2001' \
219 + ',rx_port2=tcp://' + self.ue.addr() + ':2003' \
Andre Puschmann3ffea802020-03-24 12:09:25 +0100220 + ',tx_freq=2630e6,rx_freq=2510e6,tx_freq2=2650e6,rx_freq2=2530e6' \
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100221 + ',id=enb,base_srate=' + str(base_srate)
Pau Espin Pedrol6c42bb52020-02-27 15:05:11 +0100222 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100223
224 self.dbg('srsENB ' + filename + ':\n' + pprint.pformat(values))
225
226 with open(path, 'w') as f:
227 r = template.render(filename, values)
228 self.dbg(r)
229 f.write(r)
230
231 def configure(self):
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100232 self.config_file = self.run_dir.child(srsENB.CFGFILE)
233 self.config_sib_file = self.run_dir.child(srsENB.CFGFILE_SIB)
234 self.config_rr_file = self.run_dir.child(srsENB.CFGFILE_RR)
235 self.config_drb_file = self.run_dir.child(srsENB.CFGFILE_DRB)
236 self.log_file = self.run_dir.child(srsENB.LOGFILE)
237 self.pcap_file = self.run_dir.child(srsENB.PCAPFILE)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100238
239 self.gen_conf_file(self.config_file, srsENB.CFGFILE)
240 self.gen_conf_file(self.config_sib_file, srsENB.CFGFILE_SIB)
241 self.gen_conf_file(self.config_rr_file, srsENB.CFGFILE_RR)
242 self.gen_conf_file(self.config_drb_file, srsENB.CFGFILE_DRB)
243
244 def ue_add(self, ue):
245 if self.ue is not None:
246 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
247 self.ue = ue
248
249 def running(self):
250 return not self.process.terminated()
251
252 def addr(self):
253 return self._addr
254
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +0100255 def num_prb(self):
256 return self._num_prb
257
Andre Puschmann82b88902020-03-24 10:04:48 +0100258 def num_cells(self):
259 return self._num_cells
260
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100261 def num_ports(self):
262 if self._txmode == 1:
263 return 1
264 return 2
265
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100266 def ue_max_rate(self, downlink=True):
Andre Puschmanne227fa32020-03-19 21:14:04 +0100267 # The max rate for a single UE per PRB configuration in TM1
268 max_phy_rate_tm1_dl = { 6 : 3.5e6,
269 15 : 11e6,
270 25 : 18e6,
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100271 50 : 36e6,
Andre Puschmanne227fa32020-03-19 21:14:04 +0100272 75 : 55e6,
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100273 100 : 75e6 }
Andre Puschmanne227fa32020-03-19 21:14:04 +0100274 max_phy_rate_tm1_ul = { 6 : 0.9e6,
275 15 : 4.7e6,
276 25 : 10e6,
277 50 : 23e6,
278 75 : 34e6,
279 100 : 51e6 }
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100280 if downlink:
281 max_rate = max_phy_rate_tm1_dl[self.num_prb()]
282 else:
283 max_rate = max_phy_rate_tm1_ul[self.num_prb()]
284 #TODO: calculate for non-standard prb numbers.
285 if self._txmode > 2:
286 max_rate *= 2
287 # We use 3 control symbols for 6, 15 and 25 PRBs which results in lower max rate
288 if self.num_prb() < 50:
289 max_rate *= 0.9
290 return max_rate
291
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100292# vim: expandtab tabstop=4 shiftwidth=4