blob: d9fe1a594cd8a8afe7a47b9fe5d90a11b463efe0 [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 Pedrol786a6bc2020-03-30 13:51:21 +020024
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020025def on_register_schemas():
26 resource_schema = {
27 'label': schema.STR,
28 'type': schema.STR,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020029 'gtp_bind_addr': schema.IPV4,
30 'id': schema.UINT,
31 'num_prb': schema.UINT,
32 'transmission_mode': schema.LTE_TRANSMISSION_MODE,
33 'tx_gain': schema.UINT,
34 'rx_gain': schema.UINT,
35 'rf_dev_type': schema.STR,
36 'rf_dev_args': schema.STR,
Pau Espin Pedrole592de82020-06-15 17:01:16 +020037 'additional_args[]': schema.STR,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020038 'enable_measurements': schema.BOOL_STR,
39 'a1_report_type': schema.STR,
40 'a1_report_value': schema.INT,
41 'a1_hysteresis': schema.INT,
42 'a1_time_to_trigger': schema.INT,
43 'a2_report_type': schema.STR,
44 'a2_report_value': schema.INT,
45 'a2_hysteresis': schema.INT,
46 'a2_time_to_trigger': schema.INT,
47 'a3_report_type': schema.STR,
48 'a3_report_value': schema.INT,
49 'a3_hysteresis': schema.INT,
50 'a3_time_to_trigger': schema.INT,
51 'num_cells': schema.UINT,
52 'cell_list[].cell_id': schema.UINT,
Andre Puschmann549826d2020-04-21 21:14:30 +020053 'cell_list[].rf_port': schema.UINT,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020054 'cell_list[].pci': schema.UINT,
55 'cell_list[].ncell_list[]': schema.UINT,
56 'cell_list[].scell_list[]': schema.UINT,
57 'cell_list[].dl_earfcn': schema.UINT,
58 'cell_list[].dl_rfemu.type': schema.STR,
59 'cell_list[].dl_rfemu.addr': schema.IPV4,
60 'cell_list[].dl_rfemu.ports[]': schema.UINT,
61 }
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020062 for key, val in run_node.RunNode.schema().items():
63 resource_schema['run_node.%s' % key] = val
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020064 schema.register_resource_schema('enb', resource_schema)
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020065
66class eNodeB(log.Origin, metaclass=ABCMeta):
67
68##############
69# PROTECTED
70##############
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020071 def __init__(self, testenv, conf, name):
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +020072 super().__init__(log.C_RUN, '%s' % name)
73 self._conf = conf
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020074 self._run_node = run_node.RunNode.from_conf(conf.get('run_node', {}))
Andre Puschmann4b5a09a2020-04-14 22:24:00 +020075 self._gtp_bind_addr = conf.get('gtp_bind_addr', None)
76 if self._gtp_bind_addr is None:
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +020077 self._gtp_bind_addr = self._run_node.run_addr()
78 self.set_name('%s_%s' % (name, self._run_node.run_addr()))
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +020079 self._txmode = 0
Pau Espin Pedrol491f77c2020-04-20 14:20:43 +020080 self._id = None
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +020081 self._num_prb = 0
Pau Espin Pedrolf46ae222020-04-17 16:23:54 +020082 self._num_cells = None
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +020083 self._epc = None
84
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +020085 def configure(self, config_specifics_li):
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +020086 values = dict(enb=config.get_defaults('enb'))
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +020087 for config_specifics in config_specifics_li:
88 config.overlay(values, dict(enb=config.get_defaults(config_specifics)))
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020089 config.overlay(values, dict(enb=self.testenv.suite().config().get('enb', {})))
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +020090 for config_specifics in config_specifics_li:
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020091 config.overlay(values, dict(enb=self.testenv.suite().config().get(config_specifics, {})))
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +020092 config.overlay(values, dict(enb=self._conf))
Pau Espin Pedrol491f77c2020-04-20 14:20:43 +020093 self._id = int(values['enb'].get('id', None))
94 assert self._id is not None
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +020095 self._num_prb = int(values['enb'].get('num_prb', None))
96 assert self._num_prb
97 self._txmode = int(values['enb'].get('transmission_mode', None))
98 assert self._txmode
99 config.overlay(values, dict(enb={ 'num_ports': self.num_ports() }))
100 assert self._epc is not None
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200101 config.overlay(values, dict(enb={ 'addr': self.addr() }))
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200102 config.overlay(values, dict(enb={ 'mme_addr': self._epc.addr() }))
Andre Puschmann4b5a09a2020-04-14 22:24:00 +0200103 config.overlay(values, dict(enb={ 'gtp_bind_addr': self._gtp_bind_addr }))
Pau Espin Pedrolf46ae222020-04-17 16:23:54 +0200104 self._num_cells = int(values['enb'].get('num_cells', None))
105 assert self._num_cells
106
107 # adjust cell_list to num_cells length:
108 len_cell_list = len(values['enb']['cell_list'])
109 if len_cell_list >= self._num_cells:
110 values['enb']['cell_list'] = values['enb']['cell_list'][:self._num_cells]
111 else:
112 raise log.Error('enb.cell_list items (%d) < enb.num_cells (%d) attribute!' % (len_cell_list, self._num_cells))
113 # adjust scell list (to only contain values available in cell_list):
114 cell_id_list = [c['cell_id'] for c in values['enb']['cell_list']]
115 for i in range(len(values['enb']['cell_list'])):
116 scell_list_old = values['enb']['cell_list'][i]['scell_list']
117 scell_list_new = []
118 for scell_id in scell_list_old:
119 if scell_id in cell_id_list:
120 scell_list_new.append(scell_id)
121 values['enb']['cell_list'][i]['scell_list'] = scell_list_new
122
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200123 return values
124
Pau Espin Pedrol491f77c2020-04-20 14:20:43 +0200125 def id(self):
126 return self._id
127
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200128 def num_ports(self):
129 if self._txmode == 1:
130 return 1
131 return 2
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200132
Andre Puschmann0957e9e2020-06-16 16:29:27 +0200133 def num_cells(self):
134 return self._num_cells
135
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200136########################
137# PUBLIC - INTERNAL API
138########################
139 def cleanup(self):
140 'Nothing to do by default. Subclass can override if required.'
141 pass
142
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200143 def num_prb(self):
144 return self._num_prb
145
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200146 #reference: srsLTE.git srslte_symbol_sz()
147 def num_prb2symbol_sz(self, num_prb):
Andre Puschmann0a501102020-06-02 22:35:27 +0200148 if num_prb == 6:
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200149 return 128
Andre Puschmann0a501102020-06-02 22:35:27 +0200150 if num_prb == 50:
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200151 return 768
Andre Puschmann0a501102020-06-02 22:35:27 +0200152 if num_prb == 75:
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200153 return 1024
Andre Puschmann0a501102020-06-02 22:35:27 +0200154 return 1536
155
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200156 raise log.Error('invalid num_prb %r', num_prb)
157
158 def num_prb2base_srate(self, num_prb):
159 return self.num_prb2symbol_sz(num_prb) * 15 * 1000
160
161 def get_zmq_rf_dev_args(self):
162 base_srate = self.num_prb2base_srate(self.num_prb())
163 # Define all 8 possible RF ports (2x CA with 2x2 MIMO)
164 rf_dev_args = 'fail_on_disconnect=true' \
165 + ',tx_port0=tcp://' + self.addr() + ':2000' \
166 + ',tx_port1=tcp://' + self.addr() + ':2002' \
167 + ',tx_port2=tcp://' + self.addr() + ':2004' \
168 + ',tx_port3=tcp://' + self.addr() + ':2006' \
169 + ',rx_port0=tcp://' + self.ue.addr() + ':2001' \
170 + ',rx_port1=tcp://' + self.ue.addr() + ':2003' \
171 + ',rx_port2=tcp://' + self.ue.addr() + ':2005' \
172 + ',rx_port3=tcp://' + self.ue.addr() + ':2007'
173
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200174 rf_dev_args += ',id=enb,base_srate=' + str(base_srate)
175
176 return rf_dev_args
177
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200178 def get_instance_by_type(testenv, conf):
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +0200179 """Allocate a ENB child class based on type. Opts are passed to the newly created object."""
180 enb_type = conf.get('type')
181 if enb_type is None:
182 raise RuntimeError('ENB type is not defined!')
183
184 if enb_type == 'amarisoftenb':
185 from .enb_amarisoft import AmarisoftENB
186 enb_class = AmarisoftENB
187 elif enb_type == 'srsenb':
188 from .enb_srs import srsENB
189 enb_class = srsENB
190 else:
191 raise log.Error('ENB type not supported:', enb_type)
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200192 return enb_class(testenv, conf)
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +0200193
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200194###################
195# PUBLIC (test API included)
196###################
197 @abstractmethod
198 def start(self, epc):
199 'Starts ENB, it will connect to "epc"'
200 pass
201
202 @abstractmethod
203 def ue_add(self, ue):
204 pass
205
206 @abstractmethod
207 def running(self):
208 pass
209
210 @abstractmethod
211 def ue_max_rate(self, downlink=True):
212 pass
213
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200214 @abstractmethod
215 def get_rfemu(self, cell=0, dl=True):
216 'Get rfemu.RFemulation subclass implementation object for given cell index and direction.'
217 pass
218
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200219 def addr(self):
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200220 return self._run_node.run_addr()
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200221
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200222# vim: expandtab tabstop=4 shiftwidth=4