blob: 5b4e99ef5a732d5b6d76cf703b98eb5f89ba931f [file] [log] [blame]
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +02001# 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
24from . import enb
25
26def rf_type_valid(rf_type_str):
27 return rf_type_str in ('uhd')
28
29#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
48class AmarisoftENB(enb.eNodeB):
49
50 REMOTE_DIR = '/osmo-gsm-tester-amarisoftenb'
51 BINFILE = 'lteenb'
52 CFGFILE = 'amarisoft_enb.cfg'
53 CFGFILE_SIB1 = 'amarisoft_sib1.asn'
54 CFGFILE_SIB23 = 'amarisoft_sib23.asn'
55 CFGFILE_RF = 'amarisoft_rf_driver.cfg'
56 CFGFILE_DRB = 'amarisoft_drb.cfg'
57 LOGFILE = 'lteenb.log'
58
59 def __init__(self, suite_run, conf):
60 super().__init__(suite_run, conf, 'amarisoftenb')
61 self.ue = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020062 self.run_dir = None
63 self._bin_prefix = None
64 self.config_file = None
65 self.config_sib1_file = None
66 self.config_sib23_file = None
67 self.config_rf_file = None
68 self.config_drb_file = None
69 self.log_file = None
70 self.process = None
71 self.rem_host = None
72 self.remote_config_file = None
73 self.remote_config_sib1_file = None
74 self.remote_config_sib23_file = None
75 self.remote_config_rf_file = None
76 self.remote_config_drb_file = None
77 self.remote_log_file = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020078 self.suite_run = suite_run
79 self.remote_user = conf.get('remote_user', None)
80 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))
82
83 def bin_prefix(self):
84 if self._bin_prefix is None:
Pau Espin Pedrol17253af2020-04-02 21:11:19 +020085 self._bin_prefix = os.getenv('AMARISOFT_PATH_ENB', None)
86 if self._bin_prefix == None:
87 self._bin_prefix = self.suite_run.trial.get_inst('amarisoftenb')
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020088 return self._bin_prefix
89
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))
100
101
102 def setup_runs_locally(self):
103 return self.remote_user is None
104
105 def start(self, epc):
106 self.log('Starting AmarisoftENB')
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200107 self._epc = epc
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200108 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
109 self.configure()
110 self._start()
111
112 # send t+Enter to enable console trace
113 self.dbg('Enabling console trace')
114 self.process.stdin_write('t\n')
115
116 def _start(self):
117 if self.setup_runs_locally():
118 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(self.inst) }
119 binary = self.inst.child('.', AmarisoftENB.BINFILE)
120 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
121 args = (binary, os.path.abspath(self.config_file))
122 self.process = process.Process(self.name(), self.run_dir, args, env=env)
123 else:
124 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst }
125 remote_binary = self.remote_inst.child('', AmarisoftENB.BINFILE)
126 args = (remote_binary, self.remote_config_file)
127 self.process = self.rem_host.RemoteProcess(AmarisoftENB.BINFILE, args, remote_env=remote_env)
128
129 self.suite_run.remember_to_stop(self.process)
130 self.process.launch()
131
132 def gen_conf_file(self, path, filename, values):
133 self.dbg('AmarisoftENB ' + filename + ':\n' + pprint.pformat(values))
134 with open(path, 'w') as f:
135 r = template.render(filename, values)
136 self.dbg(r)
137 f.write(r)
138
139 def configure(self):
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200140 self.inst = util.Dir(os.path.abspath(self.bin_prefix()))
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200141 if not self.inst.isfile('', AmarisoftENB.BINFILE):
142 raise log.Error('No %s binary in' % AmarisoftENB.BINFILE, self.inst)
143
144 self.config_file = self.run_dir.child(AmarisoftENB.CFGFILE)
145 self.config_sib1_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB1)
146 self.config_sib23_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB23)
147 self.config_rf_file = self.run_dir.child(AmarisoftENB.CFGFILE_RF)
148 self.config_drb_file = self.run_dir.child(AmarisoftENB.CFGFILE_DRB)
149 self.log_file = self.run_dir.child(AmarisoftENB.LOGFILE)
150
151 if not self.setup_runs_locally():
152 self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr)
153 remote_prefix_dir = util.Dir(AmarisoftENB.REMOTE_DIR)
154 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
155 remote_run_dir = util.Dir(remote_prefix_dir.child(AmarisoftENB.BINFILE))
156
157 self.remote_config_file = remote_run_dir.child(AmarisoftENB.CFGFILE)
158 self.remote_config_sib1_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB1)
159 self.remote_config_sib23_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB23)
160 self.remote_config_rf_file = remote_run_dir.child(AmarisoftENB.CFGFILE_RF)
161 self.remote_config_drb_file = remote_run_dir.child(AmarisoftENB.CFGFILE_DRB)
162 self.remote_log_file = remote_run_dir.child(AmarisoftENB.LOGFILE)
163
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +0200164 values = super().configure(['amarisoft', 'amarisoftenb'])
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200165 self._num_cells = int(values['enb'].get('num_cells', None))
166 assert self._num_cells
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200167
168 logfile = self.log_file if self.setup_runs_locally() else self.remote_log_file
169 config.overlay(values, dict(enb=dict(log_filename=logfile)))
170
171 self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values)
172 self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values)
173 self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values)
174 self.gen_conf_file(self.config_rf_file, AmarisoftENB.CFGFILE_RF, values)
175 self.gen_conf_file(self.config_drb_file, AmarisoftENB.CFGFILE_DRB, values)
176
177 if not self.setup_runs_locally():
178 self.rem_host.recreate_remote_dir(self.remote_inst)
179 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
180 self.rem_host.recreate_remote_dir(remote_run_dir)
181 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
182 self.rem_host.scp('scp-cfg-sib1-to-remote', self.config_sib1_file, self.remote_config_sib1_file)
183 self.rem_host.scp('scp-cfg-sib23-to-remote', self.config_sib23_file, self.remote_config_sib23_file)
184 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rf_file, self.remote_config_rf_file)
185 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
186
187 def ue_add(self, ue):
188 if self.ue is not None:
189 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
190 self.ue = ue
191
192 def running(self):
193 return not self.process.terminated()
194
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200195# vim: expandtab tabstop=4 shiftwidth=4