blob: c331cd8b4bc50fd71f246e86ed4df0aab92e202d [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 if not rf_type_valid(conf.get('rf_dev_type', None)):
73 raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None))
74
75 def bin_prefix(self):
76 if self._bin_prefix is None:
Pau Espin Pedrol17253af2020-04-02 21:11:19 +020077 self._bin_prefix = os.getenv('AMARISOFT_PATH_ENB', None)
78 if self._bin_prefix == None:
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020079 self._bin_prefix = self.testenv.suite().trial().get_inst('amarisoftenb')
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020080 return self._bin_prefix
81
82 def cleanup(self):
83 if self.process is None:
84 return
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020085 if self._run_node.is_local():
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020086 return
87 # copy back files (may not exist, for instance if there was an early error of process):
88 try:
89 self.rem_host.scpfrom('scp-back-log', self.remote_log_file, self.log_file)
90 except Exception as e:
91 self.log(repr(e))
92
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020093 def start(self, epc):
94 self.log('Starting AmarisoftENB')
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +020095 self._epc = epc
Pau Espin Pedrol2a2d8462020-05-11 10:56:52 +020096 self.run_dir = util.Dir(self.testenv.test().get_run_dir().new_dir(self.name()))
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020097 self.configure()
98 self._start()
99
100 # send t+Enter to enable console trace
101 self.dbg('Enabling console trace')
102 self.process.stdin_write('t\n')
103
104 def _start(self):
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200105 if self._run_node.is_local():
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200106 env = { 'LD_LIBRARY_PATH': util.prepend_library_path(self.inst) }
107 binary = self.inst.child('.', AmarisoftENB.BINFILE)
108 self.dbg(run_dir=self.run_dir, binary=binary, env=env)
109 args = (binary, os.path.abspath(self.config_file))
110 self.process = process.Process(self.name(), self.run_dir, args, env=env)
111 else:
112 remote_env = { 'LD_LIBRARY_PATH': self.remote_inst }
113 remote_binary = self.remote_inst.child('', AmarisoftENB.BINFILE)
114 args = (remote_binary, self.remote_config_file)
115 self.process = self.rem_host.RemoteProcess(AmarisoftENB.BINFILE, args, remote_env=remote_env)
116
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200117 self.testenv.remember_to_stop(self.process)
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200118 self.process.launch()
119
120 def gen_conf_file(self, path, filename, values):
121 self.dbg('AmarisoftENB ' + filename + ':\n' + pprint.pformat(values))
122 with open(path, 'w') as f:
123 r = template.render(filename, values)
124 self.dbg(r)
125 f.write(r)
126
127 def configure(self):
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200128 self.inst = util.Dir(os.path.abspath(self.bin_prefix()))
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200129 if not self.inst.isfile('', AmarisoftENB.BINFILE):
130 raise log.Error('No %s binary in' % AmarisoftENB.BINFILE, self.inst)
131
132 self.config_file = self.run_dir.child(AmarisoftENB.CFGFILE)
133 self.config_sib1_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB1)
134 self.config_sib23_file = self.run_dir.child(AmarisoftENB.CFGFILE_SIB23)
135 self.config_rf_file = self.run_dir.child(AmarisoftENB.CFGFILE_RF)
136 self.config_drb_file = self.run_dir.child(AmarisoftENB.CFGFILE_DRB)
137 self.log_file = self.run_dir.child(AmarisoftENB.LOGFILE)
138
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200139 if not self._run_node.is_local():
140 self.rem_host = remote.RemoteHost(self.run_dir, self._run_node.ssh_user(), self._run_node.ssh_addr())
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200141 remote_prefix_dir = util.Dir(AmarisoftENB.REMOTE_DIR)
142 self.remote_inst = util.Dir(remote_prefix_dir.child(os.path.basename(str(self.inst))))
143 remote_run_dir = util.Dir(remote_prefix_dir.child(AmarisoftENB.BINFILE))
144
145 self.remote_config_file = remote_run_dir.child(AmarisoftENB.CFGFILE)
146 self.remote_config_sib1_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB1)
147 self.remote_config_sib23_file = remote_run_dir.child(AmarisoftENB.CFGFILE_SIB23)
148 self.remote_config_rf_file = remote_run_dir.child(AmarisoftENB.CFGFILE_RF)
149 self.remote_config_drb_file = remote_run_dir.child(AmarisoftENB.CFGFILE_DRB)
150 self.remote_log_file = remote_run_dir.child(AmarisoftENB.LOGFILE)
151
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +0200152 values = super().configure(['amarisoft', 'amarisoftenb'])
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200153
Andre Puschmanna7f19832020-04-07 14:38:27 +0200154 # Convert parsed boolean string to Python boolean:
155 self.enable_measurements = util.str2bool(values['enb'].get('enable_measurements', 'false'))
156 config.overlay(values, dict(enb={'enable_measurements': self.enable_measurements}))
157
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200158 # We need to set some specific variables programatically here to match IP addresses:
159 if self._conf.get('rf_dev_type') == 'zmq':
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200160 base_srate = self.num_prb2base_srate(self.num_prb())
161 rf_dev_args = self.get_zmq_rf_dev_args()
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200162 config.overlay(values, dict(enb=dict(sample_rate = base_srate / (1000*1000),
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200163 rf_dev_args = rf_dev_args)))
Pau Espin Pedrold45a29e2020-04-02 17:21:47 +0200164
165 # Set UHD frame size as a function of the cell bandwidth on B2XX
Pau Espin Pedrol6b8f5ae2020-04-07 18:51:57 +0200166 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 +0200167 if 'b200' in values['enb'].get('rf_dev_args'):
168 rf_dev_args = values['enb'].get('rf_dev_args', '')
169 rf_dev_args += ',' if rf_dev_args != '' and not rf_dev_args.endswith(',') else ''
170
171 if self._num_prb < 25:
172 rf_dev_args += 'send_frame_size=512,recv_frame_size=512'
173 elif self._num_prb == 25:
174 rf_dev_args += 'send_frame_size=1024,recv_frame_size=1024'
175 elif self._num_prb > 25:
176 rf_dev_args += 'num_recv_frames=64,num_send_frames=64'
177
178 if self._num_prb > 50:
179 # Reduce over the wire format to sc12
180 rf_dev_args += ',otw_format=sc12'
181
182 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
183
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200184 logfile = self.log_file if self._run_node.is_local() else self.remote_log_file
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200185 config.overlay(values, dict(enb=dict(log_filename=logfile)))
186
Pau Espin Pedrol65beb8f2020-03-31 12:03:19 +0200187 # rf driver is shared between amarisoft enb and ue, so it has a
188 # different cfg namespace 'trx'. Copy needed values over there:
189 config.overlay(values, dict(trx=dict(rf_dev_type=values['enb'].get('rf_dev_type', None),
Pau Espin Pedrola6d63042020-04-20 15:14:51 +0200190 rf_dev_args=values['enb'].get('rf_dev_args', None),
191 rx_gain=values['enb'].get('rx_gain', None),
192 tx_gain=values['enb'].get('tx_gain', None),
193 )))
Pau Espin Pedrol65beb8f2020-03-31 12:03:19 +0200194
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200195 self.gen_conf = values
196
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200197 self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values)
198 self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values)
199 self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values)
200 self.gen_conf_file(self.config_rf_file, AmarisoftENB.CFGFILE_RF, values)
201 self.gen_conf_file(self.config_drb_file, AmarisoftENB.CFGFILE_DRB, values)
202
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200203 if not self._run_node.is_local():
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200204 self.rem_host.recreate_remote_dir(self.remote_inst)
205 self.rem_host.scp('scp-inst-to-remote', str(self.inst), remote_prefix_dir)
206 self.rem_host.recreate_remote_dir(remote_run_dir)
207 self.rem_host.scp('scp-cfg-to-remote', self.config_file, self.remote_config_file)
208 self.rem_host.scp('scp-cfg-sib1-to-remote', self.config_sib1_file, self.remote_config_sib1_file)
209 self.rem_host.scp('scp-cfg-sib23-to-remote', self.config_sib23_file, self.remote_config_sib23_file)
210 self.rem_host.scp('scp-cfg-rr-to-remote', self.config_rf_file, self.remote_config_rf_file)
211 self.rem_host.scp('scp-cfg-drb-to-remote', self.config_drb_file, self.remote_config_drb_file)
212
213 def ue_add(self, ue):
214 if self.ue is not None:
215 raise log.Error("More than one UE per ENB not yet supported (ZeroMQ)")
216 self.ue = ue
217
218 def running(self):
219 return not self.process.terminated()
220
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200221 def get_rfemu(self, cell=0, dl=True):
222 cell_list = self.gen_conf['enb'].get('cell_list', None)
223 if cell_list is None or len(cell_list) < cell + 1:
224 raise log.Error('cell_list attribute or subitem not found!')
225 rfemu_cfg = cell_list[cell].get('dl_rfemu', None)
226 if rfemu_cfg is None: # craft amarisfot by default:
227 rfemu_cfg = {'type': 'amarisoftctl',
228 'addr': self.addr(),
229 'ports': [9001]
230 }
231 if rfemu_cfg['type'] == 'amarisoftctl': # this one requires extra config:
232 config.overlay(rfemu_cfg, dict(cell_id=cell_list[cell]['cell_id']))
233 rfemu_obj = rfemu.get_instance_by_type(rfemu_cfg['type'], rfemu_cfg)
234 return rfemu_obj
235
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200236# vim: expandtab tabstop=4 shiftwidth=4