blob: f5d3fdf74dbd024c3db00523d3595a61c36a03ac [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
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020024from . import enb
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010025
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +010026def rf_type_valid(rf_type_str):
27 return rf_type_str in ('zmq', 'UHD', 'soapy', 'bladeRF')
28
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +010029#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
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020048class srsENB(enb.eNodeB):
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010049
50 REMOTE_DIR = '/osmo-gsm-tester-srsenb'
51 BINFILE = 'srsenb'
52 CFGFILE = 'srsenb.conf'
53 CFGFILE_SIB = 'srsenb_sib.conf'
54 CFGFILE_RR = 'srsenb_rr.conf'
55 CFGFILE_DRB = 'srsenb_drb.conf'
56 LOGFILE = 'srsenb.log'
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +010057 PCAPFILE = 'srsenb.pcap'
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010058
59 def __init__(self, suite_run, conf):
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020060 super().__init__(suite_run, conf, srsENB.BINFILE)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010061 self.ue = None
62 self.epc = None
63 self.run_dir = None
64 self.config_file = None
65 self.config_sib_file = None
66 self.config_rr_file = None
67 self.config_drb_file = None
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +010068 self.log_file = None
69 self.pcap_file = None
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010070 self.process = None
71 self.rem_host = None
72 self.remote_config_file = None
73 self.remote_config_sib_file = None
74 self.remote_config_rr_file = None
75 self.remote_config_drb_file = None
76 self.remote_log_file = None
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +010077 self.remote_pcap_file = None
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +010078 self._num_prb = 0
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +010079 self._txmode = 0
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +010080 self.enable_pcap = False
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010081 self.suite_run = suite_run
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010082 self.remote_user = conf.get('remote_user', None)
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +010083 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))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010085
86 def cleanup(self):
87 if self.process is None:
88 return
89 if self.setup_runs_locally():
90 return
91 # copy back files (may not exist, for instance if there was an early error of process):
92 try:
93 self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file)
94 except Exception as e:
95 self.log(repr(e))
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +010096 if self.enable_pcap:
97 try:
98 self.rem_host.scpfrom('scp-back-pcap', self.remote_pcap_file, self.pcap_file)
99 except Exception as e:
100 self.log(repr(e))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100101
102 def setup_runs_locally(self):
103 return self.remote_user is None
104
105 def start(self, epc):
106 self.log('Starting srsENB')
107 self.epc = epc
108 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
109 self.configure()
110 if self.remote_user:
111 self.start_remotely()
112 else:
113 self.start_locally()
114
Andre Puschmannc2c82212020-03-24 16:39:35 +0100115 # send t+Enter to enable console trace
116 self.dbg('Enabling console trace')
117 self.process.stdin_write('t\n')
118
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100119 def start_remotely(self):
120 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte')))
121 lib = self.inst.child('lib')
122 if not os.path.isdir(lib):
123 raise log.Error('No lib/ in', self.inst)
124 if not self.inst.isfile('bin', srsENB.BINFILE):
125 raise log.Error('No %s binary in' % srsENB.BINFILE, self.inst)
126
127 self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr)
128 remote_prefix_dir = util.Dir(srsENB.REMOTE_DIR)
129 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
130 remote_run_dir = util.Dir(remote_prefix_dir.child(srsENB.BINFILE))
131
132 self.remote_config_file = remote_run_dir.child(srsENB.CFGFILE)
133 self.remote_config_sib_file = remote_run_dir.child(srsENB.CFGFILE_SIB)
134 self.remote_config_rr_file = remote_run_dir.child(srsENB.CFGFILE_RR)
135 self.remote_config_drb_file = remote_run_dir.child(srsENB.CFGFILE_DRB)
136 self.remote_log_file = remote_run_dir.child(srsENB.LOGFILE)
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100137 self.remote_pcap_file = remote_run_dir.child(srsENB.PCAPFILE)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100138
139 self.rem_host.recreate_remote_dir(self.remote_inst)
140 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100141 self.rem_host.recreate_remote_dir(remote_run_dir)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100142 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
143 self.rem_host.scp('scp-cfg-sib-to-remote', self.config_sib_file, self.remote_config_sib_file)
144 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rr_file, self.remote_config_rr_file)
145 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
146
147 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst.child('lib') }
148 remote_binary = self.remote_inst.child('bin', srsENB.BINFILE)
149 args = (remote_binary, self.remote_config_file,
150 '--enb_files.sib_config=' + self.remote_config_sib_file,
151 '--enb_files.rr_config=' + self.remote_config_rr_file,
152 '--enb_files.drb_config=' + self.remote_config_drb_file,
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100153 '--log.filename=' + self.remote_log_file,
154 '--pcap.filename=' + self.remote_pcap_file)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100155
Andre Puschmannc2c82212020-03-24 16:39:35 +0100156 self.process = self.rem_host.RemoteProcess(srsENB.BINFILE, args, remote_env=remote_env)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100157 self.suite_run.remember_to_stop(self.process)
158 self.process.launch()
159
160 def start_locally(self):
161 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte')))
162
163 binary = inst.child('bin', BINFILE)
164 if not os.path.isfile(binary):
165 raise log.Error('Binary missing:', binary)
166 lib = inst.child('lib')
167 if not os.path.isdir(lib):
168 raise log.Error('No lib/ in', inst)
169
170 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
171
172 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
173 args = (binary, os.path.abspath(self.config_file),
174 '--enb_files.sib_config=' + os.path.abspath(self.config_sib_file),
175 '--enb_files.rr_config=' + os.path.abspath(self.config_rr_file),
176 '--enb_files.drb_config=' + os.path.abspath(self.config_drb_file),
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100177 '--log.filename=' + self.log_file,
178 '--pcap.filename=' + self.pcap_file)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100179
180 self.process = process.Process(self.name(), self.run_dir, args, env=env)
181 self.suite_run.remember_to_stop(self.process)
182 self.process.launch()
183
184 def gen_conf_file(self, path, filename):
185 self.dbg(config_file=path)
186
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200187 values = dict(enb=config.get_defaults('enb'))
188 config.overlay(values, dict(enb=config.get_defaults('srsenb')))
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100189 config.overlay(values, dict(enb=self.suite_run.config().get('enb', {})))
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +0100190 config.overlay(values, dict(enb=self._conf))
191 config.overlay(values, dict(enb={ 'mme_addr': self.epc.addr() }))
192
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100193 # Convert parsed boolean string to Python boolean:
194 self.enable_pcap = util.str2bool(values['enb'].get('enable_pcap', 'false'))
195 config.overlay(values, dict(enb={'enable_pcap': self.enable_pcap}))
196
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100197 self._num_prb = int(values['enb'].get('num_prb', None))
198 assert self._num_prb
199 self._txmode = int(values['enb'].get('transmission_mode', None))
200 assert self._txmode
Andre Puschmann82b88902020-03-24 10:04:48 +0100201 self._num_cells = int(values['enb'].get('num_cells', None))
202 assert self._num_cells
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100203 config.overlay(values, dict(enb={ 'num_ports': self.num_ports() }))
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100204
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +0100205 # We need to set some specific variables programatically here to match IP addresses:
206 if self._conf.get('rf_dev_type') == 'zmq':
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +0100207 base_srate = num_prb2base_srate(self._num_prb)
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100208 rf_dev_args = 'fail_on_disconnect=true' \
209 + ',tx_port=tcp://' + self.addr() + ':2000' \
210 + ',tx_port2=tcp://' + self.addr() + ':2002' \
211 + ',rx_port=tcp://' + self.ue.addr() + ':2001' \
212 + ',rx_port2=tcp://' + self.ue.addr() + ':2003' \
Andre Puschmann3ffea802020-03-24 12:09:25 +0100213 + ',tx_freq=2630e6,rx_freq=2510e6,tx_freq2=2650e6,rx_freq2=2530e6' \
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100214 + ',id=enb,base_srate=' + str(base_srate)
Pau Espin Pedrol6c42bb52020-02-27 15:05:11 +0100215 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100216
217 self.dbg('srsENB ' + filename + ':\n' + pprint.pformat(values))
218
219 with open(path, 'w') as f:
220 r = template.render(filename, values)
221 self.dbg(r)
222 f.write(r)
223
224 def configure(self):
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100225 self.config_file = self.run_dir.child(srsENB.CFGFILE)
226 self.config_sib_file = self.run_dir.child(srsENB.CFGFILE_SIB)
227 self.config_rr_file = self.run_dir.child(srsENB.CFGFILE_RR)
228 self.config_drb_file = self.run_dir.child(srsENB.CFGFILE_DRB)
229 self.log_file = self.run_dir.child(srsENB.LOGFILE)
230 self.pcap_file = self.run_dir.child(srsENB.PCAPFILE)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100231
232 self.gen_conf_file(self.config_file, srsENB.CFGFILE)
233 self.gen_conf_file(self.config_sib_file, srsENB.CFGFILE_SIB)
234 self.gen_conf_file(self.config_rr_file, srsENB.CFGFILE_RR)
235 self.gen_conf_file(self.config_drb_file, srsENB.CFGFILE_DRB)
236
237 def ue_add(self, ue):
238 if self.ue is not None:
239 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
240 self.ue = ue
241
242 def running(self):
243 return not self.process.terminated()
244
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +0100245 def num_prb(self):
246 return self._num_prb
247
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100248 def num_ports(self):
249 if self._txmode == 1:
250 return 1
251 return 2
252
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100253 def ue_max_rate(self, downlink=True):
Andre Puschmanne227fa32020-03-19 21:14:04 +0100254 # The max rate for a single UE per PRB configuration in TM1
255 max_phy_rate_tm1_dl = { 6 : 3.5e6,
256 15 : 11e6,
257 25 : 18e6,
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100258 50 : 36e6,
Andre Puschmanne227fa32020-03-19 21:14:04 +0100259 75 : 55e6,
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100260 100 : 75e6 }
Andre Puschmanne227fa32020-03-19 21:14:04 +0100261 max_phy_rate_tm1_ul = { 6 : 0.9e6,
262 15 : 4.7e6,
263 25 : 10e6,
264 50 : 23e6,
265 75 : 34e6,
266 100 : 51e6 }
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100267 if downlink:
268 max_rate = max_phy_rate_tm1_dl[self.num_prb()]
269 else:
270 max_rate = max_phy_rate_tm1_ul[self.num_prb()]
271 #TODO: calculate for non-standard prb numbers.
272 if self._txmode > 2:
273 max_rate *= 2
274 # We use 3 control symbols for 6, 15 and 25 PRBs which results in lower max rate
275 if self.num_prb() < 50:
276 max_rate *= 0.9
277 return max_rate
278
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100279# vim: expandtab tabstop=4 shiftwidth=4