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 | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 21 | from . 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') |
| 35 | self.set_name('%s_%s' % (name, self._addr)) |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 36 | self._txmode = 0 |
| 37 | self._num_prb = 0 |
| 38 | self._epc = None |
| 39 | |
| 40 | def configure(self, default_specifics): |
| 41 | values = dict(enb=config.get_defaults('enb')) |
| 42 | config.overlay(values, dict(enb=config.get_defaults(default_specifics))) |
| 43 | config.overlay(values, dict(enb=self.suite_run.config().get('enb', {}))) |
| 44 | config.overlay(values, dict(enb=self._conf)) |
| 45 | self._num_prb = int(values['enb'].get('num_prb', None)) |
| 46 | assert self._num_prb |
| 47 | self._txmode = int(values['enb'].get('transmission_mode', None)) |
| 48 | assert self._txmode |
| 49 | config.overlay(values, dict(enb={ 'num_ports': self.num_ports() })) |
| 50 | assert self._epc is not None |
| 51 | config.overlay(values, dict(enb={ 'mme_addr': self._epc.addr() })) |
| 52 | return values |
| 53 | |
| 54 | def num_ports(self): |
| 55 | if self._txmode == 1: |
| 56 | return 1 |
| 57 | return 2 |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 58 | |
| 59 | ######################## |
| 60 | # PUBLIC - INTERNAL API |
| 61 | ######################## |
| 62 | def cleanup(self): |
| 63 | 'Nothing to do by default. Subclass can override if required.' |
| 64 | pass |
| 65 | |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 66 | def num_prb(self): |
| 67 | return self._num_prb |
| 68 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 69 | ################### |
| 70 | # PUBLIC (test API included) |
| 71 | ################### |
| 72 | @abstractmethod |
| 73 | def start(self, epc): |
| 74 | 'Starts ENB, it will connect to "epc"' |
| 75 | pass |
| 76 | |
| 77 | @abstractmethod |
| 78 | def ue_add(self, ue): |
| 79 | pass |
| 80 | |
| 81 | @abstractmethod |
| 82 | def running(self): |
| 83 | pass |
| 84 | |
| 85 | @abstractmethod |
| 86 | def ue_max_rate(self, downlink=True): |
| 87 | pass |
| 88 | |
| 89 | def addr(self): |
| 90 | return self._addr |
| 91 | |
Pau Espin Pedrol | e44e76a | 2020-03-31 12:35:19 +0200 | [diff] [blame] | 92 | def ue_max_rate(self, downlink=True): |
| 93 | # The max rate for a single UE per PRB configuration in TM1 |
| 94 | max_phy_rate_tm1_dl = { 6 : 3.5e6, |
| 95 | 15 : 11e6, |
| 96 | 25 : 18e6, |
| 97 | 50 : 36e6, |
| 98 | 75 : 55e6, |
| 99 | 100 : 75e6 } |
| 100 | max_phy_rate_tm1_ul = { 6 : 0.9e6, |
| 101 | 15 : 4.7e6, |
| 102 | 25 : 10e6, |
| 103 | 50 : 23e6, |
| 104 | 75 : 34e6, |
| 105 | 100 : 51e6 } |
| 106 | if downlink: |
| 107 | max_rate = max_phy_rate_tm1_dl[self.num_prb()] |
| 108 | else: |
| 109 | max_rate = max_phy_rate_tm1_ul[self.num_prb()] |
| 110 | #TODO: calculate for non-standard prb numbers. |
| 111 | if self._txmode > 2: |
| 112 | max_rate *= 2 |
| 113 | # We use 3 control symbols for 6, 15 and 25 PRBs which results in lower max rate |
| 114 | if self.num_prb() < 50: |
| 115 | max_rate *= 0.9 |
| 116 | return max_rate |
| 117 | |
Pau Espin Pedrol | 786a6bc | 2020-03-30 13:51:21 +0200 | [diff] [blame] | 118 | # vim: expandtab tabstop=4 shiftwidth=4 |