blob: 2ef713f4a8dc5f6f3ec499ba1a39726e52bc02a1 [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
Pau Espin Pedrol214f15e2020-04-03 16:56:12 +020063 self.inst = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020064 self._bin_prefix = None
65 self.config_file = None
66 self.config_sib1_file = None
67 self.config_sib23_file = None
68 self.config_rf_file = None
69 self.config_drb_file = None
70 self.log_file = None
71 self.process = None
72 self.rem_host = None
Pau Espin Pedrol214f15e2020-04-03 16:56:12 +020073 self.remote_inst = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020074 self.remote_config_file = None
75 self.remote_config_sib1_file = None
76 self.remote_config_sib23_file = None
77 self.remote_config_rf_file = None
78 self.remote_config_drb_file = None
79 self.remote_log_file = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020080 self.suite_run = suite_run
81 self.remote_user = conf.get('remote_user', None)
82 if not rf_type_valid(conf.get('rf_dev_type', None)):
83 raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None))
84
85 def bin_prefix(self):
86 if self._bin_prefix is None:
Pau Espin Pedrol17253af2020-04-02 21:11:19 +020087 self._bin_prefix = os.getenv('AMARISOFT_PATH_ENB', None)
88 if self._bin_prefix == None:
89 self._bin_prefix = self.suite_run.trial.get_inst('amarisoftenb')
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020090 return self._bin_prefix
91
92 def cleanup(self):
93 if self.process is None:
94 return
95 if self.setup_runs_locally():
96 return
97 # copy back files (may not exist, for instance if there was an early error of process):
98 try:
99 self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file)
100 except Exception as e:
101 self.log(repr(e))
102
103
104 def setup_runs_locally(self):
105 return self.remote_user is None
106
107 def start(self, epc):
108 self.log('Starting AmarisoftENB')
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200109 self._epc = epc
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200110 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
111 self.configure()
112 self._start()
113
114 # send t+Enter to enable console trace
115 self.dbg('Enabling console trace')
116 self.process.stdin_write('t\n')
117
118 def _start(self):
119 if self.setup_runs_locally():
120 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(self.inst) }
121 binary = self.inst.child('.', AmarisoftENB.BINFILE)
122 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
123 args = (binary, os.path.abspath(self.config_file))
124 self.process = process.Process(self.name(), self.run_dir, args, env=env)
125 else:
126 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst }
127 remote_binary = self.remote_inst.child('', AmarisoftENB.BINFILE)
128 args = (remote_binary, self.remote_config_file)
129 self.process = self.rem_host.RemoteProcess(AmarisoftENB.BINFILE, args, remote_env=remote_env)
130
131 self.suite_run.remember_to_stop(self.process)
132 self.process.launch()
133
134 def gen_conf_file(self, path, filename, values):
135 self.dbg('AmarisoftENB ' + filename + ':\n' + pprint.pformat(values))
136 with open(path, 'w') as f:
137 r = template.render(filename, values)
138 self.dbg(r)
139 f.write(r)
140
141 def configure(self):
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200142 self.inst = util.Dir(os.path.abspath(self.bin_prefix()))
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200143 if not self.inst.isfile('', AmarisoftENB.BINFILE):
144 raise log.Error('No %s binary in' % AmarisoftENB.BINFILE, self.inst)
145
146 self.config_file = self.run_dir.child(AmarisoftENB.CFGFILE)
147 self.config_sib1_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB1)
148 self.config_sib23_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB23)
149 self.config_rf_file = self.run_dir.child(AmarisoftENB.CFGFILE_RF)
150 self.config_drb_file = self.run_dir.child(AmarisoftENB.CFGFILE_DRB)
151 self.log_file = self.run_dir.child(AmarisoftENB.LOGFILE)
152
153 if not self.setup_runs_locally():
154 self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr)
155 remote_prefix_dir = util.Dir(AmarisoftENB.REMOTE_DIR)
156 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
157 remote_run_dir = util.Dir(remote_prefix_dir.child(AmarisoftENB.BINFILE))
158
159 self.remote_config_file = remote_run_dir.child(AmarisoftENB.CFGFILE)
160 self.remote_config_sib1_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB1)
161 self.remote_config_sib23_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB23)
162 self.remote_config_rf_file = remote_run_dir.child(AmarisoftENB.CFGFILE_RF)
163 self.remote_config_drb_file = remote_run_dir.child(AmarisoftENB.CFGFILE_DRB)
164 self.remote_log_file = remote_run_dir.child(AmarisoftENB.LOGFILE)
165
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +0200166 values = super().configure(['amarisoft', 'amarisoftenb'])
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200167 self._num_cells = int(values['enb'].get('num_cells', None))
168 assert self._num_cells
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200169
170 logfile = self.log_file if self.setup_runs_locally() else self.remote_log_file
171 config.overlay(values, dict(enb=dict(log_filename=logfile)))
172
173 self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values)
174 self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values)
175 self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values)
176 self.gen_conf_file(self.config_rf_file, AmarisoftENB.CFGFILE_RF, values)
177 self.gen_conf_file(self.config_drb_file, AmarisoftENB.CFGFILE_DRB, values)
178
179 if not self.setup_runs_locally():
180 self.rem_host.recreate_remote_dir(self.remote_inst)
181 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
182 self.rem_host.recreate_remote_dir(remote_run_dir)
183 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
184 self.rem_host.scp('scp-cfg-sib1-to-remote', self.config_sib1_file, self.remote_config_sib1_file)
185 self.rem_host.scp('scp-cfg-sib23-to-remote', self.config_sib23_file, self.remote_config_sib23_file)
186 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rf_file, self.remote_config_rf_file)
187 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
188
189 def ue_add(self, ue):
190 if self.ue is not None:
191 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
192 self.ue = ue
193
194 def running(self):
195 return not self.process.terminated()
196
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200197# vim: expandtab tabstop=4 shiftwidth=4