Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 1 | # 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 | |
| 20 | from abc import ABCMeta, abstractmethod |
Pau Espin Pedrol | e1a58bd | 2020-04-10 20:46:07 +0200 | [diff] [blame] | 21 | from ..core import log, config |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class eNodeB(log.Origin, metaclass=ABCMeta): |
| 25 | |
| 26 | ############## |
| 27 | # PROTECTED |
| 28 | ############## |
| 29 | def __init__(self, suite_run, conf, name): |
| 30 | super().__init__(log.C_RUN, '%s' % name) |
| 31 | self._conf = conf |
| 32 | self._addr = conf.get('addr', None) |
| 33 | if self._addr is None: |
| 34 | raise log.Error('addr not set') |
Andre Puschmann | 4b5a09a | 2020-04-14 22:24:00 +0200 | [diff] [blame] | 35 | self._gtp_bind_addr = conf.get('gtp_bind_addr', None) |
| 36 | if self._gtp_bind_addr is None: |
| 37 | self._gtp_bind_addr = self._addr |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 38 | self.set_name('%s_%s' % (name, self._addr)) |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 39 | self._txmode = 0 |
Pau Espin Pedrol | 491f77c | 2020-04-20 14:20:43 +0200 | [diff] [blame] | 40 | self._id = None |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 41 | self._num_prb = 0 |
Pau Espin Pedrol | f46ae22 | 2020-04-17 16:23:54 +0200 | [diff] [blame] | 42 | self._num_cells = None |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 43 | self._epc = None |
| 44 | |
Pau Espin Pedrol | c04528c | 2020-04-01 13:55:51 +0200 | [diff] [blame] | 45 | def configure(self, config_specifics_li): |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 46 | values = dict(enb=config.get_defaults('enb')) |
Pau Espin Pedrol | c04528c | 2020-04-01 13:55:51 +0200 | [diff] [blame] | 47 | for config_specifics in config_specifics_li: |
| 48 | config.overlay(values, dict(enb=config.get_defaults(config_specifics))) |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 49 | config.overlay(values, dict(enb=self.suite_run.config().get('enb', {}))) |
Pau Espin Pedrol | c04528c | 2020-04-01 13:55:51 +0200 | [diff] [blame] | 50 | for config_specifics in config_specifics_li: |
| 51 | config.overlay(values, dict(enb=self.suite_run.config().get(config_specifics, {}))) |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 52 | config.overlay(values, dict(enb=self._conf)) |
Pau Espin Pedrol | 491f77c | 2020-04-20 14:20:43 +0200 | [diff] [blame] | 53 | self._id = int(values['enb'].get('id', None)) |
| 54 | assert self._id is not None |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 55 | self._num_prb = int(values['enb'].get('num_prb', None)) |
| 56 | assert self._num_prb |
| 57 | self._txmode = int(values['enb'].get('transmission_mode', None)) |
| 58 | assert self._txmode |
| 59 | config.overlay(values, dict(enb={ 'num_ports': self.num_ports() })) |
| 60 | assert self._epc is not None |
| 61 | config.overlay(values, dict(enb={ 'mme_addr': self._epc.addr() })) |
Andre Puschmann | 4b5a09a | 2020-04-14 22:24:00 +0200 | [diff] [blame] | 62 | config.overlay(values, dict(enb={ 'gtp_bind_addr': self._gtp_bind_addr })) |
Pau Espin Pedrol | f46ae22 | 2020-04-17 16:23:54 +0200 | [diff] [blame] | 63 | self._num_cells = int(values['enb'].get('num_cells', None)) |
| 64 | assert self._num_cells |
| 65 | |
| 66 | # adjust cell_list to num_cells length: |
| 67 | len_cell_list = len(values['enb']['cell_list']) |
| 68 | if len_cell_list >= self._num_cells: |
| 69 | values['enb']['cell_list'] = values['enb']['cell_list'][:self._num_cells] |
| 70 | else: |
| 71 | raise log.Error('enb.cell_list items (%d) < enb.num_cells (%d) attribute!' % (len_cell_list, self._num_cells)) |
| 72 | # adjust scell list (to only contain values available in cell_list): |
| 73 | cell_id_list = [c['cell_id'] for c in values['enb']['cell_list']] |
| 74 | for i in range(len(values['enb']['cell_list'])): |
| 75 | scell_list_old = values['enb']['cell_list'][i]['scell_list'] |
| 76 | scell_list_new = [] |
| 77 | for scell_id in scell_list_old: |
| 78 | if scell_id in cell_id_list: |
| 79 | scell_list_new.append(scell_id) |
| 80 | values['enb']['cell_list'][i]['scell_list'] = scell_list_new |
| 81 | |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 82 | return values |
| 83 | |
Pau Espin Pedrol | 491f77c | 2020-04-20 14:20:43 +0200 | [diff] [blame] | 84 | def id(self): |
| 85 | return self._id |
| 86 | |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 87 | def num_ports(self): |
| 88 | if self._txmode == 1: |
| 89 | return 1 |
| 90 | return 2 |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 91 | |
| 92 | ######################## |
| 93 | # PUBLIC - INTERNAL API |
| 94 | ######################## |
| 95 | def cleanup(self): |
| 96 | 'Nothing to do by default. Subclass can override if required.' |
| 97 | pass |
| 98 | |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 99 | def num_prb(self): |
| 100 | return self._num_prb |
| 101 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 102 | ################### |
| 103 | # PUBLIC (test API included) |
| 104 | ################### |
| 105 | @abstractmethod |
| 106 | def start(self, epc): |
| 107 | 'Starts ENB, it will connect to "epc"' |
| 108 | pass |
| 109 | |
| 110 | @abstractmethod |
| 111 | def ue_add(self, ue): |
| 112 | pass |
| 113 | |
| 114 | @abstractmethod |
| 115 | def running(self): |
| 116 | pass |
| 117 | |
| 118 | @abstractmethod |
| 119 | def ue_max_rate(self, downlink=True): |
| 120 | pass |
| 121 | |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 122 | @abstractmethod |
| 123 | def get_rfemu(self, cell=0, dl=True): |
| 124 | 'Get rfemu.RFemulation subclass implementation object for given cell index and direction.' |
| 125 | pass |
| 126 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 127 | def addr(self): |
| 128 | return self._addr |
| 129 | |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 130 | def ue_max_rate(self, downlink=True): |
| 131 | # The max rate for a single UE per PRB configuration in TM1 |
| 132 | max_phy_rate_tm1_dl = { 6 : 3.5e6, |
| 133 | 15 : 11e6, |
| 134 | 25 : 18e6, |
| 135 | 50 : 36e6, |
| 136 | 75 : 55e6, |
| 137 | 100 : 75e6 } |
| 138 | max_phy_rate_tm1_ul = { 6 : 0.9e6, |
| 139 | 15 : 4.7e6, |
| 140 | 25 : 10e6, |
| 141 | 50 : 23e6, |
| 142 | 75 : 34e6, |
| 143 | 100 : 51e6 } |
| 144 | if downlink: |
| 145 | max_rate = max_phy_rate_tm1_dl[self.num_prb()] |
| 146 | else: |
| 147 | max_rate = max_phy_rate_tm1_ul[self.num_prb()] |
| 148 | #TODO: calculate for non-standard prb numbers. |
| 149 | if self._txmode > 2: |
| 150 | max_rate *= 2 |
| 151 | # We use 3 control symbols for 6, 15 and 25 PRBs which results in lower max rate |
| 152 | if self.num_prb() < 50: |
| 153 | max_rate *= 0.9 |
| 154 | return max_rate |
| 155 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 156 | # vim: expandtab tabstop=4 shiftwidth=4 |