blob: cbca0fb37d05986dee5966194d9c93b2cc6e43d9 [file] [log] [blame]
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +02001# 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
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 Pedrolda2e31f2020-03-31 13:45:01 +020023
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020024def 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 Pedrolda2e31f2020-03-31 13:45:01 +020030
31class EPC(log.Origin, metaclass=ABCMeta):
32
33##############
34# PROTECTED
35##############
36 def __init__(self, suite_run, run_node, name):
37 super().__init__(log.C_RUN, '%s' % name)
38 self._addr = run_node.run_addr()
39 self.set_name('%s_%s' % (name, self._addr))
40 self.suite_run = suite_run
41 self._run_node = run_node
42
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +020043 def configure(self, config_specifics_li):
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +020044 values = dict(epc=config.get_defaults('epc'))
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +020045 for config_specifics in config_specifics_li:
46 config.overlay(values, dict(epc=config.get_defaults(config_specifics)))
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +020047 config.overlay(values, dict(epc=self.suite_run.config().get('epc', {})))
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +020048 for config_specifics in config_specifics_li:
49 config.overlay(values, dict(epc=self.suite_run.config().get(config_specifics, {})))
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +020050 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 Pedrol1ee5ec52020-05-04 17:16:39 +020060 def get_instance_by_type(suite_run, run_node):
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'))
63 config.overlay(values, dict(epc=suite_run.config().get('epc', {})))
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
77 return epc_class(suite_run, run_node)
78
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +020079###################
80# PUBLIC (test API included)
81###################
82 @abstractmethod
83 def start(self, epc):
84 'Starts ENB, it will connect to "epc"'
85 pass
86
87 @abstractmethod
88 def subscriber_add(self, modem, msisdn=None, algo_str=None):
89 pass
90
91 @abstractmethod
92 def enb_is_connected(self, enb):
93 pass
94
95 @abstractmethod
96 def running(self):
97 pass
98
99 @abstractmethod
100 def tun_addr(self):
101 pass
102
103 def addr(self):
104 return self._addr
105
106 def run_node(self):
107 return self._run_node
108
109# vim: expandtab tabstop=4 shiftwidth=4