blob: e74377d64d06ba3299a513c0d5e069b1489520be [file] [log] [blame]
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +00001# osmo_gsm_tester: Base class for Mobile Stations (MS)
2#
3# Copyright (C) 2016-2017 by sysmocom - s.f.m.c. GmbH
4#
5# Author: Neels Hofmeyr <neels@hofmeyr.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
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020022from ..core import schema
23
24def on_register_schemas():
25 resource_schema = {
26 'type': schema.STR,
27 'label': schema.STR,
28 'path': schema.STR,
29 'imsi': schema.IMSI,
30 'ki': schema.KI,
31 'auth_algo': schema.AUTH_ALGO,
32 'apn_ipaddr': schema.IPV4,
33 'ciphers[]': schema.CIPHER,
34 'features[]': schema.MODEM_FEATURE
35 }
36 schema.register_resource_schema('modem', resource_schema)
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +000037
38class MS(log.Origin, metaclass=ABCMeta):
39 """Base for everything about mobile/modem and SIMs."""
40
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020041##############
42# PROTECTED
43##############
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +000044 def __init__(self, name, conf):
45 super().__init__(log.C_TST, name)
46 self._conf = conf
47 self.msisdn = None
48
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020049########################
50# PUBLIC - INTERNAL API
51########################
52 @abstractmethod
53 def cleanup(self):
54 """Cleans up resources allocated."""
55 pass
56
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020057 def get_instance_by_type(testenv, conf):
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020058 """Allocate a MS child class based on type. Opts are passed to the newly created object."""
59 ms_type = conf.get('type')
60 if ms_type is None:
61 # Map None to ofono for forward compability
62 ms_type = 'ofono'
63
64 if ms_type == 'ofono':
65 from .ms_ofono import Modem
66 ms_class = Modem
67 elif ms_type == 'osmo-mobile':
68 from .ms_osmo_mobile import MSOsmoMobile
69 ms_class = MSOsmoMobile
70 elif ms_type == 'srsue':
71 from .ms_srs import srsUE
72 ms_class = srsUE
73 elif ms_type == 'amarisoftue':
74 from .ms_amarisoft import AmarisoftUE
75 ms_class = AmarisoftUE
76 else:
77 raise log.Error('MS type not supported:', ms_type)
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020078 return ms_class(testenv, conf)
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020079
80###################
81# PUBLIC (test API included)
82###################
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +000083 def imsi(self):
84 return self._conf.get('imsi')
85
86 def ki(self):
87 return self._conf.get('ki')
88
Andre Puschmann22ec00a2020-03-24 09:58:06 +010089 def apn_ipaddr(self):
90 return self._conf.get('apn_ipaddr', 'dynamic')
91
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +000092 def auth_algo(self):
93 return self._conf.get('auth_algo', None)
94
95 def set_msisdn(self, msisdn):
96 self.msisdn = msisdn
97
98 def msisdn(self):
99 return self.msisdn
Pau Espin Pedroleaefe6b2020-04-20 13:29:59 +0200100
101 def get_counter(self, counter_name):
102 raise log.Error('get_counter() not implemented!')