blob: 90a6cbbe3de020eb4752193403f3440d16d2d36f [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
Andre Puschmannb9c96122021-05-10 16:39:44 +020074 elif epc_type == 'open5gs':
Pau Espin Pedrol0696c602021-03-16 14:25:37 +010075 from .epc_open5gs import Open5gsEPC
76 epc_class = Open5gsEPC
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020077 else:
78 raise log.Error('EPC type not supported:', epc_type)
79
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020080 return epc_class(testenv, run_node)
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020081
Andre Puschmannb0ebcbc2020-06-12 12:08:02 +020082 def prepare_process(self, name, popen_args):
83 ''' Prepare and return a process to run on EPC node.
84 Caller calls either launch() or launch_sync()
85 for non-blocking or blocking operation respectively '''
Andre Puschmannaa7b5b72020-05-27 18:47:43 +020086 if self._run_node.is_local():
87 proc = process.Process(name, self.run_dir, popen_args)
88 else:
89 proc = self.rem_host.RemoteProcess(name, popen_args)
Andre Puschmannaa7b5b72020-05-27 18:47:43 +020090 return proc
91
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +020092###################
93# PUBLIC (test API included)
94###################
95 @abstractmethod
96 def start(self, epc):
97 'Starts ENB, it will connect to "epc"'
98 pass
99
100 @abstractmethod
101 def subscriber_add(self, modem, msisdn=None, algo_str=None):
102 pass
103
104 @abstractmethod
105 def enb_is_connected(self, enb):
106 pass
107
108 @abstractmethod
109 def running(self):
110 pass
111
112 @abstractmethod
113 def tun_addr(self):
114 pass
115
116 def addr(self):
117 return self._addr
118
119 def run_node(self):
120 return self._run_node
121
Andre Puschmann3ce67252021-01-29 17:45:18 +0100122 @abstractmethod
123 def get_kpis(self):
124 pass
125
Pau Espin Pedrolda2e31f2020-03-31 13:45:01 +0200126# vim: expandtab tabstop=4 shiftwidth=4