blob: 7004805a8b559680eee02ceb57f78c33cbcc6c85 [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,
37 'additional_args': schema.STR,
38 '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
133########################
134# PUBLIC - INTERNAL API
135########################
136 def cleanup(self):
137 'Nothing to do by default. Subclass can override if required.'
138 pass
139
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200140 def num_prb(self):
141 return self._num_prb
142
Andre Puschmanne2a6da62020-04-20 20:39:34 +0200143 #reference: srsLTE.git srslte_symbol_sz()
144 def num_prb2symbol_sz(self, num_prb):
145 if num_prb <= 6:
146 return 128
147 if num_prb <= 15:
148 return 256
149 if num_prb <= 25:
150 return 384
151 if num_prb <= 50:
152 return 768
153 if num_prb <= 75:
154 return 1024
155 if num_prb <= 110:
156 return 1536
157 raise log.Error('invalid num_prb %r', num_prb)
158
159 def num_prb2base_srate(self, num_prb):
160 return self.num_prb2symbol_sz(num_prb) * 15 * 1000
161
162 def get_zmq_rf_dev_args(self):
163 base_srate = self.num_prb2base_srate(self.num_prb())
164 # Define all 8 possible RF ports (2x CA with 2x2 MIMO)
165 rf_dev_args = 'fail_on_disconnect=true' \
166 + ',tx_port0=tcp://' + self.addr() + ':2000' \
167 + ',tx_port1=tcp://' + self.addr() + ':2002' \
168 + ',tx_port2=tcp://' + self.addr() + ':2004' \
169 + ',tx_port3=tcp://' + self.addr() + ':2006' \
170 + ',rx_port0=tcp://' + self.ue.addr() + ':2001' \
171 + ',rx_port1=tcp://' + self.ue.addr() + ':2003' \
172 + ',rx_port2=tcp://' + self.ue.addr() + ':2005' \
173 + ',rx_port3=tcp://' + self.ue.addr() + ':2007'
174
175 if self._num_cells == 1:
176 # Single carrier
177 if self.num_ports() == 1:
178 # SISO
179 rf_dev_args += ',tx_freq0=2630e6,rx_freq0=2510e6'
180 elif self.num_ports() == 2:
181 # MIMO
182 rf_dev_args += ',tx_freq0=2630e6,tx_freq1=2630e6,rx_freq0=2510e6,rx_freq1=2510e6'
183 elif self._num_cells == 2:
184 # 2x class
185 if self.num_ports() == 1:
186 # SISO
187 rf_dev_args += ',tx_freq0=2630e6,tx_freq1=2650e6,rx_freq0=2510e6,rx_freq1=2530e6'
188 elif self.num_ports() == 2:
189 # MIMO
190 rf_dev_args += ',tx_freq0=2630e6,tx_freq1=2630e6,tx_freq2=2650e6,tx_freq3=2650e6,rx_freq0=2510e6,rx_freq1=2510e6,rx_freq2=2530e6,rx_freq3=2530e6'
191
192 rf_dev_args += ',id=enb,base_srate=' + str(base_srate)
193
194 return rf_dev_args
195
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200196 def get_instance_by_type(testenv, conf):
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +0200197 """Allocate a ENB child class based on type. Opts are passed to the newly created object."""
198 enb_type = conf.get('type')
199 if enb_type is None:
200 raise RuntimeError('ENB type is not defined!')
201
202 if enb_type == 'amarisoftenb':
203 from .enb_amarisoft import AmarisoftENB
204 enb_class = AmarisoftENB
205 elif enb_type == 'srsenb':
206 from .enb_srs import srsENB
207 enb_class = srsENB
208 else:
209 raise log.Error('ENB type not supported:', enb_type)
Pau Espin Pedrola442cb82020-05-05 12:54:37 +0200210 return enb_class(testenv, conf)
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +0200211
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200212###################
213# PUBLIC (test API included)
214###################
215 @abstractmethod
216 def start(self, epc):
217 'Starts ENB, it will connect to "epc"'
218 pass
219
220 @abstractmethod
221 def ue_add(self, ue):
222 pass
223
224 @abstractmethod
225 def running(self):
226 pass
227
228 @abstractmethod
229 def ue_max_rate(self, downlink=True):
230 pass
231
Pau Espin Pedrold4404d52020-04-20 13:29:31 +0200232 @abstractmethod
233 def get_rfemu(self, cell=0, dl=True):
234 'Get rfemu.RFemulation subclass implementation object for given cell index and direction.'
235 pass
236
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200237 def addr(self):
Pau Espin Pedrol1abff4e2020-05-26 12:32:19 +0200238 return self._run_node.run_addr()
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200239
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200240 def ue_max_rate(self, downlink=True):
Andre Puschmann71b430c2020-05-26 11:32:27 +0200241 # The max rate for a single UE per PRB configuration in TM1 with MCS 28 QAM64
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200242 max_phy_rate_tm1_dl = { 6 : 3.5e6,
243 15 : 11e6,
244 25 : 18e6,
245 50 : 36e6,
246 75 : 55e6,
247 100 : 75e6 }
248 max_phy_rate_tm1_ul = { 6 : 0.9e6,
249 15 : 4.7e6,
250 25 : 10e6,
251 50 : 23e6,
252 75 : 34e6,
253 100 : 51e6 }
254 if downlink:
255 max_rate = max_phy_rate_tm1_dl[self.num_prb()]
256 else:
257 max_rate = max_phy_rate_tm1_ul[self.num_prb()]
Andre Puschmann71b430c2020-05-26 11:32:27 +0200258
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200259 #TODO: calculate for non-standard prb numbers.
Andre Puschmann71b430c2020-05-26 11:32:27 +0200260 if downlink and self._txmode > 2:
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200261 max_rate *= 2
Andre Puschmann71b430c2020-05-26 11:32:27 +0200262
Pau Espin Pedrole44e76a2020-03-31 12:35:19 +0200263 return max_rate
264
Pau Espin Pedrol786a6bc2020-03-30 13:51:21 +0200265# vim: expandtab tabstop=4 shiftwidth=4