blob: 585166ab53fb03f432f4c947d42e3f31afaedc8e [file] [log] [blame]
Pau Espin Pedrold4404d52020-04-20 13:29:31 +02001# 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
20import json
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020021
22from ..core import log
23from .rfemu import RFemulation
24
25class 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 Pedrola8b89902020-05-05 17:48:09 +020042
43 from websocket import create_connection
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020044 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 Puschmannd899cf42020-08-24 18:18:20 +020056 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 Pedrold4404d52020-04-20 13:29:31 +020065
Andre Puschmann8b1547b2020-06-12 15:10:24 +020066 def get_max_attenuation(self):
67 return 200 # maximum cell_gain value in Amarisoft
Pau Espin Pedrold4404d52020-04-20 13:29:31 +020068
69# vim: expandtab tabstop=4 shiftwidth=4