blob: ae9b12fba67a62d0f7fb4648f2a8a47d7ae2e21c [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
119 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 Pedrolc8b0f932020-02-11 17:45:26 +0100153 '--expert.nof_phy_threads=1',
154 '--expert.rrc_inactivity_timer=1500',
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100155 '--log.filename=' + self.remote_log_file,
156 '--pcap.filename=' + self.remote_pcap_file)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100157
158 self.process = self.rem_host.RemoteProcessFixIgnoreSIGHUP(srsENB.BINFILE, util.Dir(srsENB.REMOTE_DIR), args, remote_env=remote_env)
159 self.suite_run.remember_to_stop(self.process)
160 self.process.launch()
161
162 def start_locally(self):
163 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte')))
164
165 binary = inst.child('bin', BINFILE)
166 if not os.path.isfile(binary):
167 raise log.Error('Binary missing:', binary)
168 lib = inst.child('lib')
169 if not os.path.isdir(lib):
170 raise log.Error('No lib/ in', inst)
171
172 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
173
174 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
175 args = (binary, os.path.abspath(self.config_file),
176 '--enb_files.sib_config=' + os.path.abspath(self.config_sib_file),
177 '--enb_files.rr_config=' + os.path.abspath(self.config_rr_file),
178 '--enb_files.drb_config=' + os.path.abspath(self.config_drb_file),
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100179 '--expert.nof_phy_threads=1',
180 '--expert.rrc_inactivity_timer=1500',
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100181 '--log.filename=' + self.log_file,
182 '--pcap.filename=' + self.pcap_file)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100183
184 self.process = process.Process(self.name(), self.run_dir, args, env=env)
185 self.suite_run.remember_to_stop(self.process)
186 self.process.launch()
187
188 def gen_conf_file(self, path, filename):
189 self.dbg(config_file=path)
190
191 values = dict(enb=config.get_defaults('srsenb'))
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100192 config.overlay(values, dict(enb=self.suite_run.config().get('enb', {})))
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +0100193 config.overlay(values, dict(enb=self._conf))
194 config.overlay(values, dict(enb={ 'mme_addr': self.epc.addr() }))
195
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100196 # Convert parsed boolean string to Python boolean:
197 self.enable_pcap = util.str2bool(values['enb'].get('enable_pcap', 'false'))
198 config.overlay(values, dict(enb={'enable_pcap': self.enable_pcap}))
199
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100200 self._num_prb = int(values['enb'].get('num_prb', None))
201 assert self._num_prb
202 self._txmode = int(values['enb'].get('transmission_mode', None))
203 assert self._txmode
Andre Puschmann82b88902020-03-24 10:04:48 +0100204 self._num_cells = int(values['enb'].get('num_cells', None))
205 assert self._num_cells
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100206 config.overlay(values, dict(enb={ 'num_ports': self.num_ports() }))
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100207
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +0100208 # We need to set some specific variables programatically here to match IP addresses:
209 if self._conf.get('rf_dev_type') == 'zmq':
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +0100210 base_srate = num_prb2base_srate(self._num_prb)
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100211 rf_dev_args = 'fail_on_disconnect=true' \
212 + ',tx_port=tcp://' + self.addr() + ':2000' \
213 + ',tx_port2=tcp://' + self.addr() + ':2002' \
214 + ',rx_port=tcp://' + self.ue.addr() + ':2001' \
215 + ',rx_port2=tcp://' + self.ue.addr() + ':2003' \
Andre Puschmann3ffea802020-03-24 12:09:25 +0100216 + ',tx_freq=2630e6,rx_freq=2510e6,tx_freq2=2650e6,rx_freq2=2530e6' \
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100217 + ',id=enb,base_srate=' + str(base_srate)
Pau Espin Pedrol6c42bb52020-02-27 15:05:11 +0100218 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100219
220 self.dbg('srsENB ' + filename + ':\n' + pprint.pformat(values))
221
222 with open(path, 'w') as f:
223 r = template.render(filename, values)
224 self.dbg(r)
225 f.write(r)
226
227 def configure(self):
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100228 self.config_file = self.run_dir.child(srsENB.CFGFILE)
229 self.config_sib_file = self.run_dir.child(srsENB.CFGFILE_SIB)
230 self.config_rr_file = self.run_dir.child(srsENB.CFGFILE_RR)
231 self.config_drb_file = self.run_dir.child(srsENB.CFGFILE_DRB)
232 self.log_file = self.run_dir.child(srsENB.LOGFILE)
233 self.pcap_file = self.run_dir.child(srsENB.PCAPFILE)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100234
235 self.gen_conf_file(self.config_file, srsENB.CFGFILE)
236 self.gen_conf_file(self.config_sib_file, srsENB.CFGFILE_SIB)
237 self.gen_conf_file(self.config_rr_file, srsENB.CFGFILE_RR)
238 self.gen_conf_file(self.config_drb_file, srsENB.CFGFILE_DRB)
239
240 def ue_add(self, ue):
241 if self.ue is not None:
242 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
243 self.ue = ue
244
245 def running(self):
246 return not self.process.terminated()
247
248 def addr(self):
249 return self._addr
250
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +0100251 def num_prb(self):
252 return self._num_prb
253
Andre Puschmann82b88902020-03-24 10:04:48 +0100254 def num_cells(self):
255 return self._num_cells
256
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100257 def num_ports(self):
258 if self._txmode == 1:
259 return 1
260 return 2
261
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100262 def ue_max_rate(self, downlink=True):
Andre Puschmanne227fa32020-03-19 21:14:04 +0100263 # The max rate for a single UE per PRB configuration in TM1
264 max_phy_rate_tm1_dl = { 6 : 3.5e6,
265 15 : 11e6,
266 25 : 18e6,
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100267 50 : 36e6,
Andre Puschmanne227fa32020-03-19 21:14:04 +0100268 75 : 55e6,
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100269 100 : 75e6 }
Andre Puschmanne227fa32020-03-19 21:14:04 +0100270 max_phy_rate_tm1_ul = { 6 : 0.9e6,
271 15 : 4.7e6,
272 25 : 10e6,
273 50 : 23e6,
274 75 : 34e6,
275 100 : 51e6 }
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100276 if downlink:
277 max_rate = max_phy_rate_tm1_dl[self.num_prb()]
278 else:
279 max_rate = max_phy_rate_tm1_ul[self.num_prb()]
280 #TODO: calculate for non-standard prb numbers.
281 if self._txmode > 2:
282 max_rate *= 2
283 # We use 3 control symbols for 6, 15 and 25 PRBs which results in lower max rate
284 if self.num_prb() < 50:
285 max_rate *= 0.9
286 return max_rate
287
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100288# vim: expandtab tabstop=4 shiftwidth=4