Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 1 | # osmo_gsm_tester: class defining a RF emulation object implemented using Amarisoft Ctl interface |
| 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 | |
| 20 | import json |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 21 | |
| 22 | from ..core import log |
| 23 | from .rfemu import RFemulation |
| 24 | |
| 25 | class RFemulationAmarisoftCtrl(RFemulation): |
| 26 | ############## |
| 27 | # PROTECTED |
| 28 | ############## |
| 29 | def __init__(self, conf): |
| 30 | super().__init__(conf, 'amarisoftctl') |
| 31 | self.addr = conf.get('addr') |
| 32 | self.port = conf.get('ports') |
| 33 | if self.addr is None: |
| 34 | raise log.Error('No "addr" attribute provided in supply conf!') |
| 35 | if self.port is None or len(self.port) != 1: |
| 36 | raise log.Error('No "port" attribute provided in supply conf!') |
| 37 | self.port = self.port[0] |
| 38 | self.set_name('amarisoftctl(%s:%d)' % (self.addr, self.port)) |
| 39 | self.cell_id = conf.get('cell_id') |
| 40 | if self.cell_id is None: |
| 41 | raise log.Error('No "cell_id" attribute provided in supply conf!') |
Pau Espin Pedrol | a8b8990 | 2020-05-05 17:48:09 +0200 | [diff] [blame] | 42 | |
| 43 | from websocket import create_connection |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 44 | self.ws = create_connection("ws://%s:%s" % (self.addr, self.port)) |
| 45 | |
| 46 | def __del__(self): |
| 47 | self.dbg('closing CTRL websocket') |
| 48 | self.ws.close() |
| 49 | |
| 50 | ############################# |
| 51 | # PUBLIC (test API included) |
| 52 | ############################# |
| 53 | def set_attenuation(self, db): |
| 54 | msg = { "message": "cell_gain", "cell_id": int(self.cell_id), "gain": -db } |
| 55 | msg_str = json.dumps(msg) |
Andre Puschmann | d899cf4 | 2020-08-24 18:18:20 +0200 | [diff] [blame] | 56 | try: |
| 57 | self.dbg('sending CTRL msg: "%s"' % msg_str) |
| 58 | self.ws.send(msg_str) |
| 59 | self.dbg('waiting CTRL recv...') |
| 60 | result = self.ws.recv() |
| 61 | self.dbg('Received CTRL msg: "%s"' % result) |
| 62 | except Exception: |
| 63 | log.Error('Error sending CTLR msg to eNB. eNB still running?') |
| 64 | pass |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 65 | |
Andre Puschmann | 8b1547b | 2020-06-12 15:10:24 +0200 | [diff] [blame] | 66 | def get_max_attenuation(self): |
| 67 | return 200 # maximum cell_gain value in Amarisoft |
Pau Espin Pedrol | d4404d5 | 2020-04-20 13:29:31 +0200 | [diff] [blame] | 68 | |
| 69 | # vim: expandtab tabstop=4 shiftwidth=4 |