blob: aaa96b7c7e817d82ba7021b4e1731983daef6a8e [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##############
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020036 def __init__(self, testenv, run_node, name):
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +020037 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 Pedrola442cb82020-05-05 12:54:37 +020040 self.testenv = testenv
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +020041 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 Pedrola442cb82020-05-05 12:54:37 +020047 config.overlay(values, dict(epc=self.testenv.suite().config().get('epc', {})))
Pau Espin Pedrolc04528c2020-04-01 13:55:51 +020048 for config_specifics in config_specifics_li:
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020049 config.overlay(values, dict(epc=self.testenv.suite().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 Pedrola442cb82020-05-05 12:54:37 +020060 def get_instance_by_type(testenv, run_node):
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020061 """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 Pedrola442cb82020-05-05 12:54:37 +020063 config.overlay(values, dict(epc=testenv.suite().config().get('epc', {})))
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020064 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 Pedrola442cb82020-05-05 12:54:37 +020077 return epc_class(testenv, run_node)
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020078
Andre Puschmannb0ebcbc2020-06-12 12:08:02 +020079 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 Puschmannaa7b5b72020-05-27 18:47:43 +020083 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 Puschmannaa7b5b72020-05-27 18:47:43 +020087 return proc
88
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +020089###################
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
Andre Puschmann3ce67252021-01-29 17:45:18 +0100119 @abstractmethod
120 def get_kpis(self):
121 pass
122
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +0200123# vim: expandtab tabstop=4 shiftwidth=4