blob: 1cfd212b8453be385cee172aa132c34e9670770e [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'
56
57 def __init__(self, suite_run, conf):
58 super().__init__(log.C_RUN, 'srsenb')
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +010059 self._conf = conf
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010060 self._addr = conf.get('addr', None)
61 if self._addr is None:
62 raise log.Error('addr not set')
63 self.set_name('srsenb_%s' % self._addr)
64 self.ue = None
65 self.epc = None
66 self.run_dir = None
67 self.config_file = None
68 self.config_sib_file = None
69 self.config_rr_file = None
70 self.config_drb_file = None
71 self.process = None
72 self.rem_host = None
73 self.remote_config_file = None
74 self.remote_config_sib_file = None
75 self.remote_config_rr_file = None
76 self.remote_config_drb_file = None
77 self.remote_log_file = None
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +010078 self._num_prb = 0
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010079 self.suite_run = suite_run
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010080 self.remote_user = conf.get('remote_user', None)
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +010081 if not rf_type_valid(conf.get('rf_dev_type', None)):
82 raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +010083
84 def cleanup(self):
85 if self.process is None:
86 return
87 if self.setup_runs_locally():
88 return
89 # copy back files (may not exist, for instance if there was an early error of process):
90 try:
91 self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file)
92 except Exception as e:
93 self.log(repr(e))
94
95 def setup_runs_locally(self):
96 return self.remote_user is None
97
98 def start(self, epc):
99 self.log('Starting srsENB')
100 self.epc = epc
101 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
102 self.configure()
103 if self.remote_user:
104 self.start_remotely()
105 else:
106 self.start_locally()
107
108 def start_remotely(self):
109 self.inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte')))
110 lib = self.inst.child('lib')
111 if not os.path.isdir(lib):
112 raise log.Error('No lib/ in', self.inst)
113 if not self.inst.isfile('bin', srsENB.BINFILE):
114 raise log.Error('No %s binary in' % srsENB.BINFILE, self.inst)
115
116 self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr)
117 remote_prefix_dir = util.Dir(srsENB.REMOTE_DIR)
118 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
119 remote_run_dir = util.Dir(remote_prefix_dir.child(srsENB.BINFILE))
120
121 self.remote_config_file = remote_run_dir.child(srsENB.CFGFILE)
122 self.remote_config_sib_file = remote_run_dir.child(srsENB.CFGFILE_SIB)
123 self.remote_config_rr_file = remote_run_dir.child(srsENB.CFGFILE_RR)
124 self.remote_config_drb_file = remote_run_dir.child(srsENB.CFGFILE_DRB)
125 self.remote_log_file = remote_run_dir.child(srsENB.LOGFILE)
126
127 self.rem_host.recreate_remote_dir(self.remote_inst)
128 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
129 self.rem_host.create_remote_dir(remote_run_dir)
130 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
131 self.rem_host.scp('scp-cfg-sib-to-remote', self.config_sib_file, self.remote_config_sib_file)
132 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rr_file, self.remote_config_rr_file)
133 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
134
135 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst.child('lib') }
136 remote_binary = self.remote_inst.child('bin', srsENB.BINFILE)
137 args = (remote_binary, self.remote_config_file,
138 '--enb_files.sib_config=' + self.remote_config_sib_file,
139 '--enb_files.rr_config=' + self.remote_config_rr_file,
140 '--enb_files.drb_config=' + self.remote_config_drb_file,
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100141 '--expert.nof_phy_threads=1',
142 '--expert.rrc_inactivity_timer=1500',
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100143 '--log.filename=' + self.remote_log_file)
144
145 self.process = self.rem_host.RemoteProcessFixIgnoreSIGHUP(srsENB.BINFILE, util.Dir(srsENB.REMOTE_DIR), args, remote_env=remote_env)
146 self.suite_run.remember_to_stop(self.process)
147 self.process.launch()
148
149 def start_locally(self):
150 inst = util.Dir(os.path.abspath(self.suite_run.trial.get_inst('srslte')))
151
152 binary = inst.child('bin', BINFILE)
153 if not os.path.isfile(binary):
154 raise log.Error('Binary missing:', binary)
155 lib = inst.child('lib')
156 if not os.path.isdir(lib):
157 raise log.Error('No lib/ in', inst)
158
159 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(lib) }
160
161 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
162 args = (binary, os.path.abspath(self.config_file),
163 '--enb_files.sib_config=' + os.path.abspath(self.config_sib_file),
164 '--enb_files.rr_config=' + os.path.abspath(self.config_rr_file),
165 '--enb_files.drb_config=' + os.path.abspath(self.config_drb_file),
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100166 '--expert.nof_phy_threads=1',
167 '--expert.rrc_inactivity_timer=1500',
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100168 '--log.filename=' + self.log_file)
169
170 self.process = process.Process(self.name(), self.run_dir, args, env=env)
171 self.suite_run.remember_to_stop(self.process)
172 self.process.launch()
173
174 def gen_conf_file(self, path, filename):
175 self.dbg(config_file=path)
176
177 values = dict(enb=config.get_defaults('srsenb'))
178 config.overlay(values, self.suite_run.config())
Pau Espin Pedrola9a2fe22020-02-13 19:29:55 +0100179 config.overlay(values, dict(enb=self._conf))
180 config.overlay(values, dict(enb={ 'mme_addr': self.epc.addr() }))
181
182 # We need to set some specific variables programatically here to match IP addresses:
183 if self._conf.get('rf_dev_type') == 'zmq':
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +0100184 self._num_prb = int(values['enb'].get('num_prb', None))
185 assert self._num_prb
186 base_srate = num_prb2base_srate(self._num_prb)
Pau Espin Pedrol6c42bb52020-02-27 15:05:11 +0100187 rf_dev_args = 'fail_on_disconnect=true,tx_port=tcp://' + self.addr() \
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +0100188 + ':2000,rx_port=tcp://' + self.ue.addr() \
189 + ':2001,id=enb,base_srate=' + str(base_srate)
Pau Espin Pedrol6c42bb52020-02-27 15:05:11 +0100190 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100191
192 self.dbg('srsENB ' + filename + ':\n' + pprint.pformat(values))
193
194 with open(path, 'w') as f:
195 r = template.render(filename, values)
196 self.dbg(r)
197 f.write(r)
198
199 def configure(self):
200 self.config_file = self.run_dir.new_file(srsENB.CFGFILE)
201 self.config_sib_file = self.run_dir.new_file(srsENB.CFGFILE_SIB)
202 self.config_rr_file = self.run_dir.new_file(srsENB.CFGFILE_RR)
203 self.config_drb_file = self.run_dir.new_file(srsENB.CFGFILE_DRB)
204 self.log_file = self.run_dir.new_file(srsENB.LOGFILE)
205
206 self.gen_conf_file(self.config_file, srsENB.CFGFILE)
207 self.gen_conf_file(self.config_sib_file, srsENB.CFGFILE_SIB)
208 self.gen_conf_file(self.config_rr_file, srsENB.CFGFILE_RR)
209 self.gen_conf_file(self.config_drb_file, srsENB.CFGFILE_DRB)
210
211 def ue_add(self, ue):
212 if self.ue is not None:
213 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
214 self.ue = ue
215
216 def running(self):
217 return not self.process.terminated()
218
219 def addr(self):
220 return self._addr
221
Pau Espin Pedrol2aeadeb2020-03-02 11:50:23 +0100222 def num_prb(self):
223 return self._num_prb
224
Pau Espin Pedrolc8b0f932020-02-11 17:45:26 +0100225# vim: expandtab tabstop=4 shiftwidth=4