Holger Hans Peter Freyther | 48c83a8 | 2019-02-27 08:27:46 +0000 | [diff] [blame] | 1 | # 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 | |
| 20 | from abc import ABCMeta, abstractmethod |
Pau Espin Pedrol | e1a58bd | 2020-04-10 20:46:07 +0200 | [diff] [blame] | 21 | from ..core import log |
Pau Espin Pedrol | ea8c3d4 | 2020-05-04 12:05:05 +0200 | [diff] [blame] | 22 | from ..core import schema |
| 23 | |
| 24 | def 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 Pedrol | 0f7f265 | 2020-07-13 12:01:10 +0200 | [diff] [blame] | 31 | 'opc': schema.OPC, |
Pau Espin Pedrol | ea8c3d4 | 2020-05-04 12:05:05 +0200 | [diff] [blame] | 32 | 'auth_algo': schema.AUTH_ALGO, |
| 33 | 'apn_ipaddr': schema.IPV4, |
| 34 | 'ciphers[]': schema.CIPHER, |
| 35 | 'features[]': schema.MODEM_FEATURE |
| 36 | } |
| 37 | schema.register_resource_schema('modem', resource_schema) |
Holger Hans Peter Freyther | 48c83a8 | 2019-02-27 08:27:46 +0000 | [diff] [blame] | 38 | |
| 39 | class MS(log.Origin, metaclass=ABCMeta): |
| 40 | """Base for everything about mobile/modem and SIMs.""" |
| 41 | |
Pau Espin Pedrol | 1ee5ec5 | 2020-05-04 17:16:39 +0200 | [diff] [blame] | 42 | ############## |
| 43 | # PROTECTED |
| 44 | ############## |
Holger Hans Peter Freyther | 48c83a8 | 2019-02-27 08:27:46 +0000 | [diff] [blame] | 45 | def __init__(self, name, conf): |
| 46 | super().__init__(log.C_TST, name) |
| 47 | self._conf = conf |
| 48 | self.msisdn = None |
| 49 | |
Pau Espin Pedrol | 1ee5ec5 | 2020-05-04 17:16:39 +0200 | [diff] [blame] | 50 | ######################## |
| 51 | # PUBLIC - INTERNAL API |
| 52 | ######################## |
| 53 | @abstractmethod |
| 54 | def cleanup(self): |
| 55 | """Cleans up resources allocated.""" |
| 56 | pass |
| 57 | |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 58 | def get_instance_by_type(testenv, conf): |
Pau Espin Pedrol | 1ee5ec5 | 2020-05-04 17:16:39 +0200 | [diff] [blame] | 59 | """Allocate a MS child class based on type. Opts are passed to the newly created object.""" |
| 60 | ms_type = conf.get('type') |
| 61 | if ms_type is None: |
| 62 | # Map None to ofono for forward compability |
| 63 | ms_type = 'ofono' |
| 64 | |
| 65 | if ms_type == 'ofono': |
| 66 | from .ms_ofono import Modem |
| 67 | ms_class = Modem |
| 68 | elif ms_type == 'osmo-mobile': |
| 69 | from .ms_osmo_mobile import MSOsmoMobile |
| 70 | ms_class = MSOsmoMobile |
| 71 | elif ms_type == 'srsue': |
| 72 | from .ms_srs import srsUE |
| 73 | ms_class = srsUE |
| 74 | elif ms_type == 'amarisoftue': |
| 75 | from .ms_amarisoft import AmarisoftUE |
| 76 | ms_class = AmarisoftUE |
| 77 | else: |
| 78 | raise log.Error('MS type not supported:', ms_type) |
Pau Espin Pedrol | a442cb8 | 2020-05-05 12:54:37 +0200 | [diff] [blame] | 79 | return ms_class(testenv, conf) |
Pau Espin Pedrol | 1ee5ec5 | 2020-05-04 17:16:39 +0200 | [diff] [blame] | 80 | |
Andre Puschmann | 419a662 | 2020-05-27 18:46:12 +0200 | [diff] [blame] | 81 | @abstractmethod |
| 82 | def is_registered(self, mcc_mnc=None): |
| 83 | '''Check whether MS is considered registered with the target network. In |
| 84 | 2G networks, and MS is registered if it had a successful Location Update |
| 85 | in CS. In 4G networks, an UE is considered registered with the core |
| 86 | network if it has obtained and IP address. If MCC/MNC are given it tries |
| 87 | to manually register against that specific network.''' |
| 88 | pass |
| 89 | |
| 90 | @abstractmethod |
| 91 | def get_assigned_addr(self, ipv6=False): |
| 92 | ''' Returns last assigned IP address ''' |
| 93 | pass |
| 94 | |
Pau Espin Pedrol | 1ee5ec5 | 2020-05-04 17:16:39 +0200 | [diff] [blame] | 95 | ################### |
| 96 | # PUBLIC (test API included) |
| 97 | ################### |
Holger Hans Peter Freyther | 48c83a8 | 2019-02-27 08:27:46 +0000 | [diff] [blame] | 98 | def imsi(self): |
| 99 | return self._conf.get('imsi') |
| 100 | |
| 101 | def ki(self): |
| 102 | return self._conf.get('ki') |
| 103 | |
Pau Espin Pedrol | 0f7f265 | 2020-07-13 12:01:10 +0200 | [diff] [blame] | 104 | def opc(self): |
| 105 | return self._conf.get('opc', None) |
| 106 | |
Andre Puschmann | 22ec00a | 2020-03-24 09:58:06 +0100 | [diff] [blame] | 107 | def apn_ipaddr(self): |
| 108 | return self._conf.get('apn_ipaddr', 'dynamic') |
| 109 | |
Holger Hans Peter Freyther | 48c83a8 | 2019-02-27 08:27:46 +0000 | [diff] [blame] | 110 | def auth_algo(self): |
| 111 | return self._conf.get('auth_algo', None) |
| 112 | |
| 113 | def set_msisdn(self, msisdn): |
| 114 | self.msisdn = msisdn |
| 115 | |
| 116 | def msisdn(self): |
| 117 | return self.msisdn |
Pau Espin Pedrol | eaefe6b | 2020-04-20 13:29:59 +0200 | [diff] [blame] | 118 | |
| 119 | def get_counter(self, counter_name): |
| 120 | raise log.Error('get_counter() not implemented!') |