blob: e16fe7f4576a5da1f133a211469b73ba0061bd55 [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
62 self.epc = None
63 self.run_dir = None
64 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
73 self.remote_config_file = None
74 self.remote_config_sib1_file = None
75 self.remote_config_sib23_file = None
76 self.remote_config_rf_file = None
77 self.remote_config_drb_file = None
78 self.remote_log_file = None
79 self._num_prb = 0
80 self._txmode = 0
81 self.suite_run = suite_run
82 self.remote_user = conf.get('remote_user', None)
83 if not rf_type_valid(conf.get('rf_dev_type', None)):
84 raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None))
85
86 def bin_prefix(self):
87 if self._bin_prefix is None:
88 self._bin_prefix = os.getenv('AMARISOFT_PATH_ENB', AmarisoftENB.REMOTE_DIR)
89 return self._bin_prefix
90
91 def cleanup(self):
92 if self.process is None:
93 return
94 if self.setup_runs_locally():
95 return
96 # copy back files (may not exist, for instance if there was an early error of process):
97 try:
98 self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file)
99 except Exception as e:
100 self.log(repr(e))
101
102
103 def setup_runs_locally(self):
104 return self.remote_user is None
105
106 def start(self, epc):
107 self.log('Starting AmarisoftENB')
108 self.epc = epc
109 self.run_dir = util.Dir(self.suite_run.get_test_run_dir().new_dir(self.name()))
110 self.configure()
111 self._start()
112
113 # send t+Enter to enable console trace
114 self.dbg('Enabling console trace')
115 self.process.stdin_write('t\n')
116
117 def _start(self):
118 if self.setup_runs_locally():
119 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(self.inst) }
120 binary = self.inst.child('.', AmarisoftENB.BINFILE)
121 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
122 args = (binary, os.path.abspath(self.config_file))
123 self.process = process.Process(self.name(), self.run_dir, args, env=env)
124 else:
125 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst }
126 remote_binary = self.remote_inst.child('', AmarisoftENB.BINFILE)
127 args = (remote_binary, self.remote_config_file)
128 self.process = self.rem_host.RemoteProcess(AmarisoftENB.BINFILE, args, remote_env=remote_env)
129
130 self.suite_run.remember_to_stop(self.process)
131 self.process.launch()
132
133 def gen_conf_file(self, path, filename, values):
134 self.dbg('AmarisoftENB ' + filename + ':\n' + pprint.pformat(values))
135 with open(path, 'w') as f:
136 r = template.render(filename, values)
137 self.dbg(r)
138 f.write(r)
139
140 def configure(self):
141
142 self.inst = util.Dir(os.path.abspath(self.bin_prefix()))
143 lib = self.inst.child('lib')
144 if not self.inst.isfile('', AmarisoftENB.BINFILE):
145 raise log.Error('No %s binary in' % AmarisoftENB.BINFILE, self.inst)
146
147 self.config_file = self.run_dir.child(AmarisoftENB.CFGFILE)
148 self.config_sib1_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB1)
149 self.config_sib23_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB23)
150 self.config_rf_file = self.run_dir.child(AmarisoftENB.CFGFILE_RF)
151 self.config_drb_file = self.run_dir.child(AmarisoftENB.CFGFILE_DRB)
152 self.log_file = self.run_dir.child(AmarisoftENB.LOGFILE)
153
154 if not self.setup_runs_locally():
155 self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr)
156 remote_prefix_dir = util.Dir(AmarisoftENB.REMOTE_DIR)
157 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
158 remote_run_dir = util.Dir(remote_prefix_dir.child(AmarisoftENB.BINFILE))
159
160 self.remote_config_file = remote_run_dir.child(AmarisoftENB.CFGFILE)
161 self.remote_config_sib1_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB1)
162 self.remote_config_sib23_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB23)
163 self.remote_config_rf_file = remote_run_dir.child(AmarisoftENB.CFGFILE_RF)
164 self.remote_config_drb_file = remote_run_dir.child(AmarisoftENB.CFGFILE_DRB)
165 self.remote_log_file = remote_run_dir.child(AmarisoftENB.LOGFILE)
166
167 values = dict(enb=config.get_defaults('enb'))
168 config.overlay(values, dict(enb=config.get_defaults('amarisoftenb')))
169 config.overlay(values, dict(enb=self.suite_run.config().get('enb', {})))
170 config.overlay(values, dict(enb=self._conf))
171 config.overlay(values, dict(enb={ 'mme_addr': self.epc.addr() }))
172
173 self._num_prb = int(values['enb'].get('num_prb', None))
174 assert self._num_prb
175 self._txmode = int(values['enb'].get('transmission_mode', None))
176 assert self._txmode
177 self._num_cells = int(values['enb'].get('num_cells', None))
178 assert self._num_cells
179 config.overlay(values, dict(enb={ 'num_ports': self.num_ports() }))
180
181 logfile = self.log_file if self.setup_runs_locally() else self.remote_log_file
182 config.overlay(values, dict(enb=dict(log_filename=logfile)))
183
184 self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values)
185 self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values)
186 self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values)
187 self.gen_conf_file(self.config_rf_file, AmarisoftENB.CFGFILE_RF, values)
188 self.gen_conf_file(self.config_drb_file, AmarisoftENB.CFGFILE_DRB, values)
189
190 if not self.setup_runs_locally():
191 self.rem_host.recreate_remote_dir(self.remote_inst)
192 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
193 self.rem_host.recreate_remote_dir(remote_run_dir)
194 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
195 self.rem_host.scp('scp-cfg-sib1-to-remote', self.config_sib1_file, self.remote_config_sib1_file)
196 self.rem_host.scp('scp-cfg-sib23-to-remote', self.config_sib23_file, self.remote_config_sib23_file)
197 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rf_file, self.remote_config_rf_file)
198 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
199
200 def ue_add(self, ue):
201 if self.ue is not None:
202 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
203 self.ue = ue
204
205 def running(self):
206 return not self.process.terminated()
207
208 def num_prb(self):
209 return self._num_prb
210
211 def num_ports(self):
212 if self._txmode == 1:
213 return 1
214 return 2
215
216 def ue_max_rate(self, downlink=True):
217 # The max rate for a single UE per PRB configuration in TM1
218 max_phy_rate_tm1_dl = { 6 : 3.5e6,
219 15 : 11e6,
220 25 : 18e6,
221 50 : 36e6,
222 75 : 55e6,
223 100 : 75e6 }
224 max_phy_rate_tm1_ul = { 6 : 0.9e6,
225 15 : 4.7e6,
226 25 : 10e6,
227 50 : 23e6,
228 75 : 34e6,
229 100 : 51e6 }
230 if downlink:
231 max_rate = max_phy_rate_tm1_dl[self.num_prb()]
232 else:
233 max_rate = max_phy_rate_tm1_ul[self.num_prb()]
234 #TODO: calculate for non-standard prb numbers.
235 if self._txmode > 2:
236 max_rate *= 2
237 # We use 3 control symbols for 6, 15 and 25 PRBs which results in lower max rate
238 if self.num_prb() < 50:
239 max_rate *= 0.9
240 return max_rate
241
242# vim: expandtab tabstop=4 shiftwidth=4