blob: 15c1e0c0a6d0f2058859d52a4713c268d922103d [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
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010062 self.run_dir = None
63 self.config_file = None
64 self.config_sib_file = None
65 self.config_rr_file = None
66 self.config_drb_file = None
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +010067 self.log_file = None
68 self.pcap_file = None
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010069 self.process = None
70 self.rem_host = None
71 self.remote_config_file = None
72 self.remote_config_sib_file = None
73 self.remote_config_rr_file = None
74 self.remote_config_drb_file = None
75 self.remote_log_file = None
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +010076 self.remote_pcap_file = None
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +010077 self.enable_pcap = False
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010078 self.suite_run = suite_run
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010079 self.remote_user = conf.get('remote_user', None)
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +010080 if not rf_type_valid(conf.get('rf_dev_type', None)):
81 raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010082
83 def cleanup(self):
84 if self.process is None:
85 return
86 if self.setup_runs_locally():
87 return
88 # copy back files (may not exist, for instance if there was an early error of process):
89 try:
90 self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file)
91 except Exception as e:
92 self.log(repr(e))
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +010093 if self.enable_pcap:
94 try:
95 self.rem_host.scpfrom('scp-back-pcap', self.remote_pcap_file, self.pcap_file)
96 except Exception as e:
97 self.log(repr(e))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010098
99 def setup_runs_locally(self):
100 return self.remote_user is None
101
102 def start(self, epc):
103 self.log('Starting srsENB')
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200104 self._epc = epc
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100105 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
106 self.configure()
107 if self.remote_user:
108 self.start_remotely()
109 else:
110 self.start_locally()
111
Andre Puschmannc2c82212020-03-24 16:39:35 +0100112 # send t+Enter to enable console trace
113 self.dbg('Enabling console trace')
114 self.process.stdin_write('t\n')
115
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100116 def start_remotely(self):
117 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte')))
118 lib = self.inst.child('lib')
119 if not os.path.isdir(lib):
120 raise log.Error('No lib/ in', self.inst)
121 if not self.inst.isfile('bin', srsENB.BINFILE):
122 raise log.Error('No %s binary in' % srsENB.BINFILE, self.inst)
123
124 self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr)
125 remote_prefix_dir = util.Dir(srsENB.REMOTE_DIR)
126 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
127 remote_run_dir = util.Dir(remote_prefix_dir.child(srsENB.BINFILE))
128
129 self.remote_config_file = remote_run_dir.child(srsENB.CFGFILE)
130 self.remote_config_sib_file = remote_run_dir.child(srsENB.CFGFILE_SIB)
131 self.remote_config_rr_file = remote_run_dir.child(srsENB.CFGFILE_RR)
132 self.remote_config_drb_file = remote_run_dir.child(srsENB.CFGFILE_DRB)
133 self.remote_log_file = remote_run_dir.child(srsENB.LOGFILE)
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100134 self.remote_pcap_file = remote_run_dir.child(srsENB.PCAPFILE)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100135
136 self.rem_host.recreate_remote_dir(self.remote_inst)
137 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100138 self.rem_host.recreate_remote_dir(remote_run_dir)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100139 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
140 self.rem_host.scp('scp-cfg-sib-to-remote', self.config_sib_file, self.remote_config_sib_file)
141 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rr_file, self.remote_config_rr_file)
142 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
143
144 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst.child('lib') }
145 remote_binary = self.remote_inst.child('bin', srsENB.BINFILE)
146 args = (remote_binary, self.remote_config_file,
147 '--enb_files.sib_config=' + self.remote_config_sib_file,
148 '--enb_files.rr_config=' + self.remote_config_rr_file,
149 '--enb_files.drb_config=' + self.remote_config_drb_file,
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100150 '--log.filename=' + self.remote_log_file,
151 '--pcap.filename=' + self.remote_pcap_file)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100152
Andre Puschmannc2c82212020-03-24 16:39:35 +0100153 self.process = self.rem_host.RemoteProcess(srsENB.BINFILE, args, remote_env=remote_env)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100154 self.suite_run.remember_to_stop(self.process)
155 self.process.launch()
156
157 def start_locally(self):
158 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte')))
159
Pau Espin Pedrol87413052020-03-31 10:46:18 +0200160 binary = inst.child('bin', srsENB.BINFILE)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100161 if not os.path.isfile(binary):
162 raise log.Error('Binary missing:', binary)
163 lib = inst.child('lib')
164 if not os.path.isdir(lib):
165 raise log.Error('No lib/ in', inst)
166
167 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
168
169 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
170 args = (binary, os.path.abspath(self.config_file),
171 '--enb_files.sib_config=' + os.path.abspath(self.config_sib_file),
172 '--enb_files.rr_config=' + os.path.abspath(self.config_rr_file),
173 '--enb_files.drb_config=' + os.path.abspath(self.config_drb_file),
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100174 '--log.filename=' + self.log_file,
175 '--pcap.filename=' + self.pcap_file)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100176
177 self.process = process.Process(self.name(), self.run_dir, args, env=env)
178 self.suite_run.remember_to_stop(self.process)
179 self.process.launch()
180
Pau Espin Pedrolf4cce262020-03-31 10:49:47 +0200181 def gen_conf_file(self, path, filename, values):
182 self.dbg('srsENB ' + filename + ':\n' + pprint.pformat(values))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100183
Pau Espin Pedrolf4cce262020-03-31 10:49:47 +0200184 with open(path, 'w') as f:
185 r = template.render(filename, values)
186 self.dbg(r)
187 f.write(r)
188
189 def configure(self):
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200190 values = super().configure('srsenb')
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +0100191
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100192 # Convert parsed boolean string to Python boolean:
193 self.enable_pcap = util.str2bool(values['enb'].get('enable_pcap', 'false'))
194 config.overlay(values, dict(enb={'enable_pcap': self.enable_pcap}))
195
Andre Puschmann82b88902020-03-24 10:04:48 +0100196 self._num_cells = int(values['enb'].get('num_cells', None))
197 assert self._num_cells
Pau Espin Pedrol151b08a2020-03-02 14:14:27 +0100198
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +0100199 # We need to set some specific variables programatically here to match IP addresses:
200 if self._conf.get('rf_dev_type') == 'zmq':
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200201 base_srate = num_prb2base_srate(self.num_prb())
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100202 rf_dev_args = 'fail_on_disconnect=true' \
203 + ',tx_port=tcp://' + self.addr() + ':2000' \
204 + ',tx_port2=tcp://' + self.addr() + ':2002' \
205 + ',rx_port=tcp://' + self.ue.addr() + ':2001' \
206 + ',rx_port2=tcp://' + self.ue.addr() + ':2003' \
Andre Puschmann3ffea802020-03-24 12:09:25 +0100207 + ',tx_freq=2630e6,rx_freq=2510e6,tx_freq2=2650e6,rx_freq2=2530e6' \
Pau Espin Pedrolf796ad02020-03-09 15:50:57 +0100208 + ',id=enb,base_srate=' + str(base_srate)
Pau Espin Pedrol6c42bb52020-02-27 15:05:11 +0100209 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100210
Andre Puschmann7225d522020-03-26 20:54:45 +0100211 # Set UHD frame size as a function of the cell bandwidth on B2XX
212 if self._conf.get('rf_dev_type') == 'UHD' and values['enb'].get('rf_dev_args', None) is not None:
213 if 'b200' in values['enb'].get('rf_dev_args'):
214 rf_dev_args = values['enb'].get('rf_dev_args', '')
215 rf_dev_args += ',' if rf_dev_args != '' and not rf_dev_args.endswith(',') else ''
216
217 if self._num_prb < 25:
218 rf_dev_args += 'send_frame_size=512,recv_frame_size=512'
219 elif self._num_prb == 25:
220 rf_dev_args += 'send_frame_size=1024,recv_frame_size=1024'
221 elif self._num_prb > 25:
222 rf_dev_args += 'num_recv_frames=64,num_send_frames=64'
223
224 if self._num_prb > 50:
225 # Reduce over the wire format to sc12
226 rf_dev_args += ',otw_format=sc12'
227
228 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
229
Pau Espin Pedrol1e81b5a2020-03-16 12:42:17 +0100230 self.config_file = self.run_dir.child(srsENB.CFGFILE)
231 self.config_sib_file = self.run_dir.child(srsENB.CFGFILE_SIB)
232 self.config_rr_file = self.run_dir.child(srsENB.CFGFILE_RR)
233 self.config_drb_file = self.run_dir.child(srsENB.CFGFILE_DRB)
234 self.log_file = self.run_dir.child(srsENB.LOGFILE)
235 self.pcap_file = self.run_dir.child(srsENB.PCAPFILE)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100236
Pau Espin Pedrolf4cce262020-03-31 10:49:47 +0200237 self.gen_conf_file(self.config_file, srsENB.CFGFILE, values)
238 self.gen_conf_file(self.config_sib_file, srsENB.CFGFILE_SIB, values)
239 self.gen_conf_file(self.config_rr_file, srsENB.CFGFILE_RR, values)
240 self.gen_conf_file(self.config_drb_file, srsENB.CFGFILE_DRB, values)
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100241
242 def ue_add(self, ue):
243 if self.ue is not None:
244 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
245 self.ue = ue
246
247 def running(self):
248 return not self.process.terminated()
249
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100250# vim: expandtab tabstop=4 shiftwidth=4