blob: cd4a8a116ef1c83737d9e3cbdc477a9431542b5a [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,
Pau Espin Pedrol0f7f2652020-07-13 12:01:10 +020031 'opc': schema.OPC,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020032 'auth_algo': schema.AUTH_ALGO,
33 'apn_ipaddr': schema.IPV4,
Nils Fürstea8180152020-12-03 14:14:31 +010034 'ciphers[]': schema.CIPHER_2G,
Pau Espin Pedrolea8c3d42020-05-04 12:05:05 +020035 'features[]': schema.MODEM_FEATURE
36 }
37 schema.register_resource_schema('modem', resource_schema)
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +000038
Andre Puschmann65a9e742020-11-20 11:48:38 +010039 config_schema = {
40 'count': schema.UINT
41 }
42 schema.register_config_schema('modem', config_schema)
43
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +000044class MS(log.Origin, metaclass=ABCMeta):
45 """Base for everything about mobile/modem and SIMs."""
46
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020047##############
48# PROTECTED
49##############
Pau Espin Pedrol83a2fdc2020-10-15 16:33:47 +020050 def __init__(self, name, testenv, conf):
Nils Fürstea8263f42020-11-23 14:45:15 +010051 log.Origin.__init__(self, log.C_TST, name)
Pau Espin Pedrol83a2fdc2020-10-15 16:33:47 +020052 self.testenv = testenv
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +000053 self._conf = conf
Pau Espin Pedrol4b7c5852020-10-14 14:48:21 +020054 self._msisdn = None
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +000055
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020056########################
57# PUBLIC - INTERNAL API
58########################
59 @abstractmethod
60 def cleanup(self):
61 """Cleans up resources allocated."""
62 pass
63
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020064 def get_instance_by_type(testenv, conf):
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020065 """Allocate a MS child class based on type. Opts are passed to the newly created object."""
66 ms_type = conf.get('type')
67 if ms_type is None:
68 # Map None to ofono for forward compability
69 ms_type = 'ofono'
70
71 if ms_type == 'ofono':
72 from .ms_ofono import Modem
73 ms_class = Modem
74 elif ms_type == 'osmo-mobile':
75 from .ms_osmo_mobile import MSOsmoMobile
76 ms_class = MSOsmoMobile
77 elif ms_type == 'srsue':
78 from .ms_srs import srsUE
79 ms_class = srsUE
Nils Fürstea8263f42020-11-23 14:45:15 +010080 elif ms_type == 'androidue':
81 from .ms_android import AndroidUE
82 ms_class = AndroidUE
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020083 elif ms_type == 'amarisoftue':
84 from .ms_amarisoft import AmarisoftUE
85 ms_class = AmarisoftUE
86 else:
87 raise log.Error('MS type not supported:', ms_type)
Pau Espin Pedrola442cb82020-05-05 12:54:37 +020088 return ms_class(testenv, conf)
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +020089
Andre Puschmann419a6622020-05-27 18:46:12 +020090 @abstractmethod
91 def is_registered(self, mcc_mnc=None):
92 '''Check whether MS is considered registered with the target network. In
93 2G networks, and MS is registered if it had a successful Location Update
94 in CS. In 4G networks, an UE is considered registered with the core
95 network if it has obtained and IP address. If MCC/MNC are given it tries
96 to manually register against that specific network.'''
97 pass
98
99 @abstractmethod
100 def get_assigned_addr(self, ipv6=False):
101 ''' Returns last assigned IP address '''
102 pass
103
Pau Espin Pedrol1ee5ec52020-05-04 17:16:39 +0200104###################
105# PUBLIC (test API included)
106###################
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +0000107 def imsi(self):
108 return self._conf.get('imsi')
109
110 def ki(self):
111 return self._conf.get('ki')
112
Pau Espin Pedrol0f7f2652020-07-13 12:01:10 +0200113 def opc(self):
114 return self._conf.get('opc', None)
115
Andre Puschmann22ec00a2020-03-24 09:58:06 +0100116 def apn_ipaddr(self):
117 return self._conf.get('apn_ipaddr', 'dynamic')
118
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +0000119 def auth_algo(self):
120 return self._conf.get('auth_algo', None)
121
122 def set_msisdn(self, msisdn):
Pau Espin Pedrol4b7c5852020-10-14 14:48:21 +0200123 self._msisdn = msisdn
Holger Hans Peter Freyther48c83a82019-02-27 08:27:46 +0000124
125 def msisdn(self):
Pau Espin Pedrol83a2fdc2020-10-15 16:33:47 +0200126 # If none was set, allocate next one available:
127 if self._msisdn is None:
128 self.set_msisdn(self.testenv.msisdn())
Pau Espin Pedrol4b7c5852020-10-14 14:48:21 +0200129 return self._msisdn
Pau Espin Pedroleaefe6b2020-04-20 13:29:59 +0200130
Pau Espin Pedrol680ba032020-10-14 14:49:05 +0200131 def emergency_numbers(self):
132 return ['112']
133
Pau Espin Pedroleaefe6b2020-04-20 13:29:59 +0200134 def get_counter(self, counter_name):
135 raise log.Error('get_counter() not implemented!')
Andre Puschmann65a9e742020-11-20 11:48:38 +0100136
137 def features(self):
138 return self._conf.get('features', [])