blob: 906164eec1cb8fca6ea6813e40893a398e732da1 [file] [log] [blame]
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +02001# osmo_gsm_tester: base classes to share code among eNodeB subclasses.
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
20from abc import ABCMeta, abstractmethod
Pau Espin Pedrole1a58bd2020-04-10 20:46:07 +020021from ..core import log, config
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020022from ..core import schema
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020023from . import run_node
Pau Espin Pedrol41091232020-10-05 19:23:38 +020024from .rfemu_gnuradio_zmq import GrBroker
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020025
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020026def on_register_schemas():
27 resource_schema = {
28 'label': schema.STR,
29 'type': schema.STR,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020030 'gtp_bind_addr': schema.IPV4,
31 'id': schema.UINT,
32 'num_prb': schema.UINT,
Andre Puschmannd0682ba2020-10-15 15:46:29 +020033 'duplex': schema.STR,
34 'tdd_uldl_config': schema.UINT,
35 'tdd_special_subframe_pattern': schema.UINT,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020036 'transmission_mode': schema.LTE_TRANSMISSION_MODE,
37 'tx_gain': schema.UINT,
38 'rx_gain': schema.UINT,
39 'rf_dev_type': schema.STR,
40 'rf_dev_args': schema.STR,
Andre Puschmannc489f192020-10-09 14:46:38 +020041 'rf_dev_sync': schema.STR,
Pau Espin Pedrole592de82020-06-15 17:01:16 +020042 'additional_args[]': schema.STR,
Andre Puschmann0cfc0842020-08-26 18:19:15 +020043 'inactivity_timer': schema.INT,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020044 'enable_measurements': schema.BOOL_STR,
Andre Puschmann955249d2020-07-01 15:44:09 +020045 'enable_dl_awgn': schema.BOOL_STR,
46 'dl_awgn_snr': schema.INT,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020047 'a1_report_type': schema.STR,
48 'a1_report_value': schema.INT,
49 'a1_hysteresis': schema.INT,
50 'a1_time_to_trigger': schema.INT,
51 'a2_report_type': schema.STR,
52 'a2_report_value': schema.INT,
53 'a2_hysteresis': schema.INT,
54 'a2_time_to_trigger': schema.INT,
55 'a3_report_type': schema.STR,
56 'a3_report_value': schema.INT,
57 'a3_hysteresis': schema.INT,
58 'a3_time_to_trigger': schema.INT,
59 'num_cells': schema.UINT,
60 'cell_list[].cell_id': schema.UINT,
Andre Puschmann549826d2020-04-21 21:14:30 +020061 'cell_list[].rf_port': schema.UINT,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020062 'cell_list[].pci': schema.UINT,
63 'cell_list[].ncell_list[]': schema.UINT,
64 'cell_list[].scell_list[]': schema.UINT,
65 'cell_list[].dl_earfcn': schema.UINT,
66 'cell_list[].dl_rfemu.type': schema.STR,
67 'cell_list[].dl_rfemu.addr': schema.IPV4,
68 'cell_list[].dl_rfemu.ports[]': schema.UINT,
69 }
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020070 for key, val in run_node.RunNode.schema().items():
71 resource_schema['run_node.%s' % key] = val
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020072 schema.register_resource_schema('enb', resource_schema)
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020073
74class eNodeB(log.Origin, metaclass=ABCMeta):
75
76##############
77# PROTECTED
78##############
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020079 def __init__(self, testenv, conf, name):
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020080 super().__init__(log.C_RUN, '%s' % name)
81 self._conf = conf
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020082 self._run_node = run_node.RunNode.from_conf(conf.get('run_node', {}))
Andre Puschmann4b5a09a2020-04-14 22:24:00 +020083 self._gtp_bind_addr = conf.get('gtp_bind_addr', None)
84 if self._gtp_bind_addr is None:
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020085 self._gtp_bind_addr = self._run_node.run_addr()
86 self.set_name('%s_%s' % (name, self._run_node.run_addr()))
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +020087 self._txmode = 0
Pau Espin Pedrol491f77c2020-04-20 14:20:43 +020088 self._id = None
Andre Puschmannd0682ba2020-10-15 15:46:29 +020089 self._duplex = None
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +020090 self._num_prb = 0
Pau Espin Pedrolf46ae222020-04-17 16:23:54 +020091 self._num_cells = None
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +020092 self._epc = None
Pau Espin Pedrol41091232020-10-05 19:23:38 +020093 self.gen_conf = None
94 self.gr_broker = None
95
96 def using_grbroker(self, cfg_values):
97 # whether we are to use Grbroker in between ENB and UE.
98 # Initial checks:
99 if cfg_values['enb'].get('rf_dev_type') != 'zmq':
100 return False
101 cell_list = cfg_values['enb']['cell_list']
102 use_match = False
103 notuse_match = False
104 for cell in cell_list:
105 if cell.get('dl_rfemu', False) and cell['dl_rfemu'].get('type', None) == 'gnuradio_zmq':
106 use_match = True
107 else:
108 notuse_match = True
109 if use_match and notuse_match:
110 raise log.Error('Some Cells are configured to use gnuradio_zmq and some are not, unsupported')
111 return use_match
112
113 def calc_required_zmq_ports(self, cfg_values):
114 cell_list = cfg_values['enb']['cell_list']
115 return len(cell_list) * self.num_ports() # *2 if MIMO
116
117 def calc_required_zmq_ports_joined_earfcn(self, cfg_values):
118 #gr_broker will join the earfcns, so we need to count uniqe earfcns:
119 cell_list = cfg_values['enb']['cell_list']
120 earfcn_li = []
121 [earfcn_li.append(int(cell['dl_earfcn'])) for cell in cell_list if int(cell['dl_earfcn']) not in earfcn_li]
122 return len(earfcn_li) * self.num_ports() # *2 if MIMO
123
124
125 def assign_enb_zmq_ports(self, cfg_values, port_name, base_port):
126 port_offset = 0
127 cell_list = cfg_values['enb']['cell_list']
128 for cell in cell_list:
129 cell[port_name] = base_port + port_offset
130 port_offset += self.num_ports()
131 # TODO: do we need to assign cell_list back?
132
133 def assign_enb_zmq_ports_joined_earfcn(self, cfg_values, port_name, base_port):
134 # TODO: Set in cell one bind port per unique earfcn, this is where UE will connect to when we use grbroker.
135 cell_list = cfg_values['enb']['cell_list']
136 earfcn_li = []
137 [earfcn_li.append(int(cell['dl_earfcn'])) for cell in cell_list if int(cell['dl_earfcn']) not in earfcn_li]
138 for cell in cell_list:
139 cell[port_name] = base_port + earfcn_li.index(int(cell['dl_earfcn'])) * self.num_ports()
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200140
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +0200141 def configure(self, config_specifics_li):
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200142 values = dict(enb=config.get_defaults('enb'))
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +0200143 for config_specifics in config_specifics_li:
144 config.overlay(values, dict(enb=config.get_defaults(config_specifics)))
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200145 config.overlay(values, dict(enb=self.testenv.suite().config().get('enb', {})))
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +0200146 for config_specifics in config_specifics_li:
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200147 config.overlay(values, dict(enb=self.testenv.suite().config().get(config_specifics, {})))
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200148 config.overlay(values, dict(enb=self._conf))
Pau Espin Pedrol491f77c2020-04-20 14:20:43 +0200149 self._id = int(values['enb'].get('id', None))
150 assert self._id is not None
Andre Puschmannd0682ba2020-10-15 15:46:29 +0200151 self._duplex = values['enb'].get('duplex', None)
152 assert self._duplex
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200153 self._num_prb = int(values['enb'].get('num_prb', None))
154 assert self._num_prb
155 self._txmode = int(values['enb'].get('transmission_mode', None))
156 assert self._txmode
157 config.overlay(values, dict(enb={ 'num_ports': self.num_ports() }))
Andre Puschmann0cfc0842020-08-26 18:19:15 +0200158 self._inactivity_timer = int(values['enb'].get('inactivity_timer', None))
159 assert self._inactivity_timer
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200160 assert self._epc is not None
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200161 config.overlay(values, dict(enb={ 'addr': self.addr() }))
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200162 config.overlay(values, dict(enb={ 'mme_addr': self._epc.addr() }))
Andre Puschmann4b5a09a2020-04-14 22:24:00 +0200163 config.overlay(values, dict(enb={ 'gtp_bind_addr': self._gtp_bind_addr }))
Pau Espin Pedrolf46ae222020-04-17 16:23:54 +0200164 self._num_cells = int(values['enb'].get('num_cells', None))
165 assert self._num_cells
166
167 # adjust cell_list to num_cells length:
168 len_cell_list = len(values['enb']['cell_list'])
169 if len_cell_list >= self._num_cells:
170 values['enb']['cell_list'] = values['enb']['cell_list'][:self._num_cells]
171 else:
172 raise log.Error('enb.cell_list items (%d) < enb.num_cells (%d) attribute!' % (len_cell_list, self._num_cells))
173 # adjust scell list (to only contain values available in cell_list):
174 cell_id_list = [c['cell_id'] for c in values['enb']['cell_list']]
175 for i in range(len(values['enb']['cell_list'])):
176 scell_list_old = values['enb']['cell_list'][i]['scell_list']
177 scell_list_new = []
178 for scell_id in scell_list_old:
179 if scell_id in cell_id_list:
180 scell_list_new.append(scell_id)
181 values['enb']['cell_list'][i]['scell_list'] = scell_list_new
182
Pau Espin Pedrol41091232020-10-05 19:23:38 +0200183 # Assign ZMQ ports to each Cell/EARFCN.
184 if values['enb'].get('rf_dev_type') == 'zmq':
185 resourcep = self.testenv.suite().resource_pool()
186 num_ports = self.calc_required_zmq_ports(values)
187 num_ports_joined_earfcn = self.calc_required_zmq_ports_joined_earfcn(values)
188 ue_bind_port = self.ue.zmq_base_bind_port()
189 enb_bind_port = resourcep.next_zmq_port_range(self, num_ports)
190 self.assign_enb_zmq_ports(values, 'zmq_enb_bind_port', enb_bind_port)
191 # If we are to use a GrBroker, then initialize here to have remote zmq ports available:
192 if self.using_grbroker(values):
193 zmq_enb_peer_port = resourcep.next_zmq_port_range(self, num_ports)
194 self.assign_enb_zmq_ports(values, 'zmq_enb_peer_port', zmq_enb_peer_port) # These are actually bound to GrBroker
195 self.assign_enb_zmq_ports_joined_earfcn(values, 'zmq_ue_bind_port', ue_bind_port) # This is were GrBroker binds on the UE side
196 zmq_ue_peer_port = resourcep.next_zmq_port_range(self, num_ports_joined_earfcn)
197 self.assign_enb_zmq_ports_joined_earfcn(values, 'zmq_ue_peer_port', zmq_ue_peer_port) # This is were GrBroker binds on the UE side
198 # Already set gen_conf here in advance since gr_broker needs the cell list
199 self.gen_conf = values
200 self.gr_broker = GrBroker.ref()
201 self.gr_broker.handle_enb(self)
202 else:
203 self.assign_enb_zmq_ports(values, 'zmq_enb_peer_port', ue_bind_port)
204 self.assign_enb_zmq_ports(values, 'zmq_ue_bind_port', ue_bind_port) #If no broker we need to match amount of ports
205 self.assign_enb_zmq_ports(values, 'zmq_ue_peer_port', enb_bind_port)
206
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200207 return values
208
Pau Espin Pedrol491f77c2020-04-20 14:20:43 +0200209 def id(self):
210 return self._id
211
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200212 def num_ports(self):
213 if self._txmode == 1:
214 return 1
215 return 2
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200216
Andre Puschmann0957e9e2020-06-16 16:29:27 +0200217 def num_cells(self):
218 return self._num_cells
219
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200220########################
221# PUBLIC - INTERNAL API
222########################
223 def cleanup(self):
224 'Nothing to do by default. Subclass can override if required.'
Pau Espin Pedrol41091232020-10-05 19:23:38 +0200225 if self.gr_broker:
226 GrBroker.unref()
227 self.gr_broker = None
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200228
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200229 def num_prb(self):
230 return self._num_prb
231
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200232 #reference: srsLTE.git srslte_symbol_sz()
233 def num_prb2symbol_sz(self, num_prb):
Andre Puschmann0a501102020-06-02 22:35:27 +0200234 if num_prb == 6:
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200235 return 128
Andre Puschmann0a501102020-06-02 22:35:27 +0200236 if num_prb == 50:
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200237 return 768
Andre Puschmann0a501102020-06-02 22:35:27 +0200238 if num_prb == 75:
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200239 return 1024
Andre Puschmann0a501102020-06-02 22:35:27 +0200240 return 1536
241
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200242 raise log.Error('invalid num_prb %r', num_prb)
243
244 def num_prb2base_srate(self, num_prb):
245 return self.num_prb2symbol_sz(num_prb) * 15 * 1000
246
Pau Espin Pedrol41091232020-10-05 19:23:38 +0200247 def get_zmq_rf_dev_args(self, cfg_values):
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200248 base_srate = self.num_prb2base_srate(self.num_prb())
Pau Espin Pedrol41091232020-10-05 19:23:38 +0200249
250 if self.gr_broker:
251 ul_rem_addr = self.addr()
252 else:
253 ul_rem_addr = self.ue.addr()
254
255 rf_dev_args = 'fail_on_disconnect=true'
256 idx = 0
257 cell_list = cfg_values['enb']['cell_list']
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200258 # Define all 8 possible RF ports (2x CA with 2x2 MIMO)
Pau Espin Pedrol41091232020-10-05 19:23:38 +0200259 for cell in cell_list:
260 rf_dev_args += ',tx_port%u=tcp://%s:%u' %(idx, self.addr(), cell['zmq_enb_bind_port'] + 0)
261 if self.num_ports() > 1:
262 rf_dev_args += ',tx_port%u=tcp://%s:%u' %(idx + 1, self.addr(), cell['zmq_enb_bind_port'] + 1)
263 rf_dev_args += ',rx_port%u=tcp://%s:%u' %(idx, ul_rem_addr, cell['zmq_enb_peer_port'] + 0)
264 if self.num_ports() > 1:
265 rf_dev_args += ',rx_port%u=tcp://%s:%u' %(idx + 1, ul_rem_addr, cell['zmq_enb_peer_port'] + 1)
266 idx += self.num_ports()
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200267
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200268 rf_dev_args += ',id=enb,base_srate=' + str(base_srate)
Pau Espin Pedrol41091232020-10-05 19:23:38 +0200269 return rf_dev_args
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200270
Pau Espin Pedrol41091232020-10-05 19:23:38 +0200271 def get_zmq_rf_dev_args_for_ue(self, ue):
272 cell_list = self.gen_conf['enb']['cell_list']
273 rf_dev_args = ''
274 idx = 0
275 earfcns_done = []
276 for cell in cell_list:
277 if self.gr_broker:
278 if cell['dl_earfcn'] in earfcns_done:
279 continue
280 earfcns_done.append(cell['dl_earfcn'])
281 rf_dev_args += ',tx_port%u=tcp://%s:%u' %(idx, ue.addr(), cell['zmq_ue_bind_port'] + 0)
282 if self.num_ports() > 1:
283 rf_dev_args += ',tx_port%u=tcp://%s:%u' %(idx + 1, ue.addr(), cell['zmq_ue_bind_port'] + 1)
284 rf_dev_args += ',rx_port%u=tcp://%s:%u' %(idx, self.addr(), cell['zmq_ue_peer_port'] + 0)
285 if self.num_ports() > 1:
286 rf_dev_args += ',rx_port%u=tcp://%s:%u' %(idx + 1, self.addr(), cell['zmq_ue_peer_port'] + 1)
287 idx += self.num_ports()
288 # remove trailing comma:
289 if rf_dev_args[0] == ',':
290 return rf_dev_args[1:]
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200291 return rf_dev_args
292
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200293 def get_instance_by_type(testenv, conf):
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +0200294 """Allocate a ENB child class based on type. Opts are passed to the newly created object."""
295 enb_type = conf.get('type')
296 if enb_type is None:
297 raise RuntimeError('ENB type is not defined!')
298
299 if enb_type == 'amarisoftenb':
300 from .enb_amarisoft import AmarisoftENB
301 enb_class = AmarisoftENB
302 elif enb_type == 'srsenb':
303 from .enb_srs import srsENB
304 enb_class = srsENB
305 else:
306 raise log.Error('ENB type not supported:', enb_type)
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200307 return enb_class(testenv, conf)
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +0200308
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200309###################
310# PUBLIC (test API included)
311###################
312 @abstractmethod
313 def start(self, epc):
314 'Starts ENB, it will connect to "epc"'
315 pass
316
317 @abstractmethod
318 def ue_add(self, ue):
319 pass
320
321 @abstractmethod
322 def running(self):
323 pass
324
325 @abstractmethod
Andre Puschmann7d3b83e2020-09-02 22:17:54 +0200326 def ue_max_rate(self, downlink=True, num_carriers=1):
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200327 pass
328
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200329 @abstractmethod
330 def get_rfemu(self, cell=0, dl=True):
331 'Get rfemu.RFemulation subclass implementation object for given cell index and direction.'
332 pass
333
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200334 def addr(self):
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200335 return self._run_node.run_addr()
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200336
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200337# vim: expandtab tabstop=4 shiftwidth=4