blob: fa79cbf96adaa6ae441b9195e5aa09afc3dbbe92 [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
Pau Espin Pedrole1a58bd2020-04-10 20:46:07 +020023from ..core import log, util, config, template, process, remote
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020024from ..core import schema
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020025from . import enb
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020026from . import rfemu
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020027
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020028def on_register_schemas():
29 config_schema = {
30 'license_server_addr': schema.IPV4,
31 }
32 schema.register_config_schema('amarisoft', config_schema)
33
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020034def rf_type_valid(rf_type_str):
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +020035 return rf_type_str in ('uhd', 'zmq')
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020036
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020037class AmarisoftENB(enb.eNodeB):
38
39 REMOTE_DIR = '/osmo-gsm-tester-amarisoftenb'
40 BINFILE = 'lteenb'
Andre Puschmanne4d5a132020-04-14 22:23:06 +020041 CFGFILE = 'amarisoft_enb.cfg'
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020042 CFGFILE_SIB1 = 'amarisoft_sib1.asn'
43 CFGFILE_SIB23 = 'amarisoft_sib23.asn'
44 CFGFILE_RF = 'amarisoft_rf_driver.cfg'
45 CFGFILE_DRB = 'amarisoft_drb.cfg'
46 LOGFILE = 'lteenb.log'
47
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020048 def __init__(self, testenv, conf):
49 super().__init__(testenv, conf, 'amarisoftenb')
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020050 self.ue = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020051 self.run_dir = None
Pau Espin Pedrol214f15e2020-04-03 16:56:12 +020052 self.inst = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020053 self._bin_prefix = None
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020054 self.gen_conf = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020055 self.config_file = None
56 self.config_sib1_file = None
57 self.config_sib23_file = None
58 self.config_rf_file = None
59 self.config_drb_file = None
60 self.log_file = None
61 self.process = None
62 self.rem_host = None
Pau Espin Pedrol214f15e2020-04-03 16:56:12 +020063 self.remote_inst = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020064 self.remote_config_file = None
65 self.remote_config_sib1_file = None
66 self.remote_config_sib23_file = None
67 self.remote_config_rf_file = None
68 self.remote_config_drb_file = None
69 self.remote_log_file = None
Andre Puschmanna7f19832020-04-07 14:38:27 +020070 self.enable_measurements = False
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020071 self.testenv = testenv
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020072 self.remote_user = conf.get('remote_user', None)
73 if not rf_type_valid(conf.get('rf_dev_type', None)):
74 raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None))
75
76 def bin_prefix(self):
77 if self._bin_prefix is None:
Pau Espin Pedrol17253af2020-04-02 21:11:19 +020078 self._bin_prefix = os.getenv('AMARISOFT_PATH_ENB', None)
79 if self._bin_prefix == None:
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020080 self._bin_prefix = self.testenv.suite().trial().get_inst('amarisoftenb')
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020081 return self._bin_prefix
82
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))
93
94
95 def setup_runs_locally(self):
96 return self.remote_user is None
97
98 def start(self, epc):
99 self.log('Starting AmarisoftENB')
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200100 self._epc = epc
Pau Espin Pedrol2a2d8462020-05-11 10:56:52 +0200101 self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name()))
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200102 self.configure()
103 self._start()
104
105 # send t+Enter to enable console trace
106 self.dbg('Enabling console trace')
107 self.process.stdin_write('t\n')
108
109 def _start(self):
110 if self.setup_runs_locally():
111 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(self.inst) }
112 binary = self.inst.child('.', AmarisoftENB.BINFILE)
113 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
114 args = (binary, os.path.abspath(self.config_file))
115 self.process = process.Process(self.name(), self.run_dir, args, env=env)
116 else:
117 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst }
118 remote_binary = self.remote_inst.child('', AmarisoftENB.BINFILE)
119 args = (remote_binary, self.remote_config_file)
120 self.process = self.rem_host.RemoteProcess(AmarisoftENB.BINFILE, args, remote_env=remote_env)
121
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200122 self.testenv.remember_to_stop(self.process)
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200123 self.process.launch()
124
125 def gen_conf_file(self, path, filename, values):
126 self.dbg('AmarisoftENB ' + filename + ':\n' + pprint.pformat(values))
127 with open(path, 'w') as f:
128 r = template.render(filename, values)
129 self.dbg(r)
130 f.write(r)
131
132 def configure(self):
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200133 self.inst = util.Dir(os.path.abspath(self.bin_prefix()))
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200134 if not self.inst.isfile('', AmarisoftENB.BINFILE):
135 raise log.Error('No %s binary in' % AmarisoftENB.BINFILE, self.inst)
136
137 self.config_file = self.run_dir.child(AmarisoftENB.CFGFILE)
138 self.config_sib1_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB1)
139 self.config_sib23_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB23)
140 self.config_rf_file = self.run_dir.child(AmarisoftENB.CFGFILE_RF)
141 self.config_drb_file = self.run_dir.child(AmarisoftENB.CFGFILE_DRB)
142 self.log_file = self.run_dir.child(AmarisoftENB.LOGFILE)
143
144 if not self.setup_runs_locally():
145 self.rem_host = remote.RemoteHost(self.run_dir, self.remote_user, self._addr)
146 remote_prefix_dir = util.Dir(AmarisoftENB.REMOTE_DIR)
147 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
148 remote_run_dir = util.Dir(remote_prefix_dir.child(AmarisoftENB.BINFILE))
149
150 self.remote_config_file = remote_run_dir.child(AmarisoftENB.CFGFILE)
151 self.remote_config_sib1_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB1)
152 self.remote_config_sib23_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB23)
153 self.remote_config_rf_file = remote_run_dir.child(AmarisoftENB.CFGFILE_RF)
154 self.remote_config_drb_file = remote_run_dir.child(AmarisoftENB.CFGFILE_DRB)
155 self.remote_log_file = remote_run_dir.child(AmarisoftENB.LOGFILE)
156
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +0200157 values = super().configure(['amarisoft', 'amarisoftenb'])
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200158
Andre Puschmanna7f19832020-04-07 14:38:27 +0200159 # Convert parsed boolean string to Python boolean:
160 self.enable_measurements = util.str2bool(values['enb'].get('enable_measurements', 'false'))
161 config.overlay(values, dict(enb={'enable_measurements': self.enable_measurements}))
162
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200163 # We need to set some specific variables programatically here to match IP addresses:
164 if self._conf.get('rf_dev_type') == 'zmq':
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200165 base_srate = self.num_prb2base_srate(self.num_prb())
166 rf_dev_args = self.get_zmq_rf_dev_args()
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200167 config.overlay(values, dict(enb=dict(sample_rate = base_srate / (1000*1000),
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200168 rf_dev_args = rf_dev_args)))
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200169
170 # Set UHD frame size as a function of the cell bandwidth on B2XX
Pau Espin Pedrol6b8f5ae2020-04-07 18:51:57 +0200171 if self._conf.get('rf_dev_type') == 'uhd' and values['enb'].get('rf_dev_args', None) is not None:
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200172 if 'b200' in values['enb'].get('rf_dev_args'):
173 rf_dev_args = values['enb'].get('rf_dev_args', '')
174 rf_dev_args += ',' if rf_dev_args != '' and not rf_dev_args.endswith(',') else ''
175
176 if self._num_prb < 25:
177 rf_dev_args += 'send_frame_size=512,recv_frame_size=512'
178 elif self._num_prb == 25:
179 rf_dev_args += 'send_frame_size=1024,recv_frame_size=1024'
180 elif self._num_prb > 25:
181 rf_dev_args += 'num_recv_frames=64,num_send_frames=64'
182
183 if self._num_prb > 50:
184 # Reduce over the wire format to sc12
185 rf_dev_args += ',otw_format=sc12'
186
187 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
188
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200189 logfile = self.log_file if self.setup_runs_locally() else self.remote_log_file
190 config.overlay(values, dict(enb=dict(log_filename=logfile)))
191
Pau Espin Pedrol65beb8f2020-03-31 12:03:19 +0200192 # rf driver is shared between amarisoft enb and ue, so it has a
193 # different cfg namespace 'trx'. Copy needed values over there:
194 config.overlay(values, dict(trx=dict(rf_dev_type=values['enb'].get('rf_dev_type', None),
Pau Espin Pedrola6d63042020-04-20 15:14:51 +0200195 rf_dev_args=values['enb'].get('rf_dev_args', None),
196 rx_gain=values['enb'].get('rx_gain', None),
197 tx_gain=values['enb'].get('tx_gain', None),
198 )))
Pau Espin Pedrol65beb8f2020-03-31 12:03:19 +0200199
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200200 self.gen_conf = values
201
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200202 self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values)
203 self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values)
204 self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values)
205 self.gen_conf_file(self.config_rf_file, AmarisoftENB.CFGFILE_RF, values)
206 self.gen_conf_file(self.config_drb_file, AmarisoftENB.CFGFILE_DRB, values)
207
208 if not self.setup_runs_locally():
209 self.rem_host.recreate_remote_dir(self.remote_inst)
210 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
211 self.rem_host.recreate_remote_dir(remote_run_dir)
212 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
213 self.rem_host.scp('scp-cfg-sib1-to-remote', self.config_sib1_file, self.remote_config_sib1_file)
214 self.rem_host.scp('scp-cfg-sib23-to-remote', self.config_sib23_file, self.remote_config_sib23_file)
215 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rf_file, self.remote_config_rf_file)
216 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
217
218 def ue_add(self, ue):
219 if self.ue is not None:
220 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
221 self.ue = ue
222
223 def running(self):
224 return not self.process.terminated()
225
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200226 def get_rfemu(self, cell=0, dl=True):
227 cell_list = self.gen_conf['enb'].get('cell_list', None)
228 if cell_list is None or len(cell_list) < cell + 1:
229 raise log.Error('cell_list attribute or subitem not found!')
230 rfemu_cfg = cell_list[cell].get('dl_rfemu', None)
231 if rfemu_cfg is None: # craft amarisfot by default:
232 rfemu_cfg = {'type': 'amarisoftctl',
233 'addr': self.addr(),
234 'ports': [9001]
235 }
236 if rfemu_cfg['type'] == 'amarisoftctl': # this one requires extra config:
237 config.overlay(rfemu_cfg, dict(cell_id=cell_list[cell]['cell_id']))
238 rfemu_obj = rfemu.get_instance_by_type(rfemu_cfg['type'], rfemu_cfg)
239 return rfemu_obj
240
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200241# vim: expandtab tabstop=4 shiftwidth=4