Pau Espin Pedrol | da2e31f | 2020-03-31 13:45:01 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: base classes to share code among EPC 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 | ea8c3d4 | 2020-05-04 12:05:05 +0200 | [diff] [blame] | 22 | from ..core import schema |
Pau Espin Pedrol | da2e31f | 2020-03-31 13:45:01 +0200 | [diff] [blame] | 23 | |
Pau Espin Pedrol | ea8c3d4 | 2020-05-04 12:05:05 +0200 | [diff] [blame] | 24 | def on_register_schemas(): |
| 25 | config_schema = { |
| 26 | 'type': schema.STR, |
| 27 | 'qci': schema.UINT, |
| 28 | } |
| 29 | schema.register_config_schema('epc', config_schema) |
Pau Espin Pedrol | da2e31f | 2020-03-31 13:45:01 +0200 | [diff] [blame] | 30 | |
| 31 | class EPC(log.Origin, metaclass=ABCMeta): |
| 32 | |
| 33 | ############## |
| 34 | # PROTECTED |
| 35 | ############## |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 36 | def __init__(self, testenv, run_node, name): |
Pau Espin Pedrol | da2e31f | 2020-03-31 13:45:01 +0200 | [diff] [blame] | 37 | super().__init__(log.C_RUN, '%s' % name) |
| 38 | self._addr = run_node.run_addr() |
| 39 | self.set_name('%s_%s' % (name, self._addr)) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 40 | self.testenv = testenv |
Pau Espin Pedrol | da2e31f | 2020-03-31 13:45:01 +0200 | [diff] [blame] | 41 | self._run_node = run_node |
| 42 | |
Pau Espin Pedrol | c04528c | 2020-04-01 13:55:51 +0200 | [diff] [blame] | 43 | def configure(self, config_specifics_li): |
Pau Espin Pedrol | da2e31f | 2020-03-31 13:45:01 +0200 | [diff] [blame] | 44 | values = dict(epc=config.get_defaults('epc')) |
Pau Espin Pedrol | c04528c | 2020-04-01 13:55:51 +0200 | [diff] [blame] | 45 | for config_specifics in config_specifics_li: |
| 46 | config.overlay(values, dict(epc=config.get_defaults(config_specifics))) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 47 | config.overlay(values, dict(epc=self.testenv.suite().config().get('epc', {}))) |
Pau Espin Pedrol | c04528c | 2020-04-01 13:55:51 +0200 | [diff] [blame] | 48 | for config_specifics in config_specifics_li: |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 49 | config.overlay(values, dict(epc=self.testenv.suite().config().get(config_specifics, {}))) |
Pau Espin Pedrol | da2e31f | 2020-03-31 13:45:01 +0200 | [diff] [blame] | 50 | config.overlay(values, dict(epc={'run_addr': self.addr()})) |
| 51 | return values |
| 52 | |
| 53 | ######################## |
| 54 | # PUBLIC - INTERNAL API |
| 55 | ######################## |
| 56 | def cleanup(self): |
| 57 | 'Nothing to do by default. Subclass can override if required.' |
| 58 | pass |
| 59 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 60 | def get_instance_by_type(testenv, run_node): |
Pau Espin Pedrol | 1ee5ec5 | 2020-05-04 17:16:39 +0200 | [diff] [blame] | 61 | """Allocate a EPC child class based on type. Opts are passed to the newly created object.""" |
| 62 | values = dict(epc=config.get_defaults('epc')) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 63 | config.overlay(values, dict(epc=testenv.suite().config().get('epc', {}))) |
Pau Espin Pedrol | 1ee5ec5 | 2020-05-04 17:16:39 +0200 | [diff] [blame] | 64 | epc_type = values['epc'].get('type', None) |
| 65 | if epc_type is None: |
| 66 | raise RuntimeError('EPC type is not defined!') |
| 67 | |
| 68 | if epc_type == 'amarisoftepc': |
| 69 | from .epc_amarisoft import AmarisoftEPC |
| 70 | epc_class = AmarisoftEPC |
| 71 | elif epc_type == 'srsepc': |
| 72 | from .epc_srs import srsEPC |
| 73 | epc_class = srsEPC |
| 74 | else: |
| 75 | raise log.Error('EPC type not supported:', epc_type) |
| 76 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 77 | return epc_class(testenv, run_node) |
Pau Espin Pedrol | 1ee5ec5 | 2020-05-04 17:16:39 +0200 | [diff] [blame] | 78 | |
Andre Puschmann | b0ebcbc | 2020-06-12 12:08:02 +0200 | [diff] [blame] | 79 | def prepare_process(self, name, popen_args): |
| 80 | ''' Prepare and return a process to run on EPC node. |
| 81 | Caller calls either launch() or launch_sync() |
| 82 | for non-blocking or blocking operation respectively ''' |
Andre Puschmann | aa7b5b7 | 2020-05-27 18:47:43 +0200 | [diff] [blame] | 83 | if self._run_node.is_local(): |
| 84 | proc = process.Process(name, self.run_dir, popen_args) |
| 85 | else: |
| 86 | proc = self.rem_host.RemoteProcess(name, popen_args) |
Andre Puschmann | aa7b5b7 | 2020-05-27 18:47:43 +0200 | [diff] [blame] | 87 | return proc |
| 88 | |
Pau Espin Pedrol | da2e31f | 2020-03-31 13:45:01 +0200 | [diff] [blame] | 89 | ################### |
| 90 | # PUBLIC (test API included) |
| 91 | ################### |
| 92 | @abstractmethod |
| 93 | def start(self, epc): |
| 94 | 'Starts ENB, it will connect to "epc"' |
| 95 | pass |
| 96 | |
| 97 | @abstractmethod |
| 98 | def subscriber_add(self, modem, msisdn=None, algo_str=None): |
| 99 | pass |
| 100 | |
| 101 | @abstractmethod |
| 102 | def enb_is_connected(self, enb): |
| 103 | pass |
| 104 | |
| 105 | @abstractmethod |
| 106 | def running(self): |
| 107 | pass |
| 108 | |
| 109 | @abstractmethod |
| 110 | def tun_addr(self): |
| 111 | pass |
| 112 | |
| 113 | def addr(self): |
| 114 | return self._addr |
| 115 | |
| 116 | def run_node(self): |
| 117 | return self._run_node |
| 118 | |
| 119 | # vim: expandtab tabstop=4 shiftwidth=4 |