Change in osmo-gsm-tester[master]: enb: Implement initial RF emulation API

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

pespin gerrit-no-reply at lists.osmocom.org
Fri Apr 17 14:33:02 UTC 2020


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-gsm-tester/+/17847 )


Change subject: enb: Implement initial RF emulation API
......................................................................

enb: Implement initial RF emulation API

Two implementations are provided:
* Amarisoft Ctrl interface (websocket)
* Mini-Circuits Programmable Attenuator (HW, HTTP API) [1]

in Amarisoft ENBs, if no rfemu is configured explicitly, the Ctrl
interface one is used by default, while still being possible to use the
HW one.

[1] https://www.minicircuits.com/pdfs/RC4DAT-6G-60.pdf

Change-Id: Ie98a3fb9bcd2b87b96ecbb5b79e0f53981892a32
---
M check_dependencies.py
M src/osmo_gsm_tester/obj/enb.py
M src/osmo_gsm_tester/obj/enb_amarisoft.py
M src/osmo_gsm_tester/obj/enb_srs.py
A src/osmo_gsm_tester/obj/rfemu.py
A src/osmo_gsm_tester/obj/rfemu_amarisoftctrl.py
A src/osmo_gsm_tester/obj/rfemu_minicircuits.py
M src/osmo_gsm_tester/resource.py
A sysmocom/suites/4g/handover.py
9 files changed, 259 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/47/17847/1

diff --git a/check_dependencies.py b/check_dependencies.py
index c3b1d64..c983065 100755
--- a/check_dependencies.py
+++ b/check_dependencies.py
@@ -6,6 +6,7 @@
 from inspect import getframeinfo, stack
 from mako.lookup import TemplateLookup
 from mako.template import Template
+from websocket import create_connection
 import argparse
 import contextlib
 import copy
diff --git a/src/osmo_gsm_tester/obj/enb.py b/src/osmo_gsm_tester/obj/enb.py
index 340ea3a..59b5bfe 100644
--- a/src/osmo_gsm_tester/obj/enb.py
+++ b/src/osmo_gsm_tester/obj/enb.py
@@ -113,6 +113,11 @@
     def ue_max_rate(self, downlink=True):
         pass
 
+    @abstractmethod
+    def get_rfemu(self, cell=0, dl=True):
+        'Get rfemu.RFemulation subclass implementation object for given cell index and direction.'
+        pass
+
     def addr(self):
         return self._addr
 
diff --git a/src/osmo_gsm_tester/obj/enb_amarisoft.py b/src/osmo_gsm_tester/obj/enb_amarisoft.py
index 996af19..0b748e0 100644
--- a/src/osmo_gsm_tester/obj/enb_amarisoft.py
+++ b/src/osmo_gsm_tester/obj/enb_amarisoft.py
@@ -22,6 +22,7 @@
 
 from ..core import log, util, config, template, process, remote
 from . import enb
+from . import rfemu
 
 def rf_type_valid(rf_type_str):
     return rf_type_str in ('uhd', 'zmq')
@@ -62,6 +63,7 @@
         self.run_dir = None
         self.inst = None
         self._bin_prefix = None
+        self.gen_conf = None
         self.config_file = None
         self.config_sib1_file = None
         self.config_sib23_file = None
@@ -209,6 +211,8 @@
         config.overlay(values, dict(trx=dict(rf_dev_type=values['enb'].get('rf_dev_type', None),
                                              rf_dev_args=values['enb'].get('rf_dev_args', None))))
 
+        self.gen_conf = values
+
         self.gen_conf_file(self.config_file, AmarisoftENB.CFGFILE, values)
         self.gen_conf_file(self.config_sib1_file, AmarisoftENB.CFGFILE_SIB1, values)
         self.gen_conf_file(self.config_sib23_file, AmarisoftENB.CFGFILE_SIB23, values)
@@ -233,4 +237,19 @@
     def running(self):
         return not self.process.terminated()
 
+    def get_rfemu(self, cell=0, dl=True):
+        cell_list = self.gen_conf['enb'].get('cell_list', None)
+        if cell_list is None or len(cell_list) < cell + 1:
+            raise log.Error('cell_list attribute or subitem not found!')
+        rfemu_cfg = cell_list[cell].get('dl_rfemu', None)
+        if rfemu_cfg is None: # craft amarisfot by default:
+            rfemu_cfg = {'type': 'amarisoftctl',
+                         'addr': self.addr(),
+                         'ports': [9001]
+                         }
+        if rfemu_cfg['type'] == 'amarisoftctl': # this one requires extra config:
+            config.overlay(rfemu_cfg, dict(cell_id=cell_list[cell]['cell_id']))
+        rfemu_obj = rfemu.get_instance_by_type(rfemu_cfg['type'], rfemu_cfg)
+        return rfemu_obj
+
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/obj/enb_srs.py b/src/osmo_gsm_tester/obj/enb_srs.py
index c9721d1..e657b04 100644
--- a/src/osmo_gsm_tester/obj/enb_srs.py
+++ b/src/osmo_gsm_tester/obj/enb_srs.py
@@ -22,6 +22,7 @@
 
 from ..core import log, util, config, template, process, remote
 from . import enb
+from . import rfemu
 
 def rf_type_valid(rf_type_str):
     return rf_type_str in ('zmq', 'uhd', 'soapy', 'bladerf')
@@ -60,6 +61,7 @@
         super().__init__(suite_run, conf, srsENB.BINFILE)
         self.ue = None
         self.run_dir = None
+        self.gen_conf = None
         self.config_file = None
         self.config_sib_file = None
         self.config_rr_file = None
@@ -221,6 +223,8 @@
 
                 config.overlay(values, dict(enb=dict(rf_dev_args=rf_dev_args)))
 
+        self.gen_conf = values
+
         self.gen_conf_file(self.config_file, srsENB.CFGFILE, values)
         self.gen_conf_file(self.config_sib_file, srsENB.CFGFILE_SIB, values)
         self.gen_conf_file(self.config_rr_file, srsENB.CFGFILE_RR, values)
@@ -243,4 +247,14 @@
     def running(self):
         return not self.process.terminated()
 
+    def get_rfemu(self, cell=0, dl=True):
+        cell_list = self.gen_conf['enb'].get('cell_list', None)
+        if cell_list is None or len(cell_list) < cell + 1:
+            raise log.Error('cell_list attribute or subitem not found!')
+        rfemu_cfg = cell_list[cell].get('dl_rfemu', None)
+        if rfemu_cfg is None: # craft amarisfot by default:
+            raise log.Error('rfemu attribute not found in cell_list item!')
+        rfemu_obj = rfemu.get_instance_by_type(rfemu_cfg['type'], rfemu_cfg)
+        return rfemu_obj
+
 # vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/obj/rfemu.py b/src/osmo_gsm_tester/obj/rfemu.py
new file mode 100644
index 0000000..80869bb
--- /dev/null
+++ b/src/osmo_gsm_tester/obj/rfemu.py
@@ -0,0 +1,59 @@
+# osmo_gsm_tester: class defining a RF emulation object
+#
+# Copyright (C) 2020 by sysmocom - s.f.m.c. GmbH
+#
+# Author: Pau Espin Pedrol <pespin at sysmocom.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+from abc import ABCMeta, abstractmethod
+from ..core import log
+from ..core.event_loop import MainLoop
+
+class RFemulation(log.Origin, metaclass=ABCMeta):
+
+##############
+# PROTECTED
+##############
+    def __init__(self, conf, name):
+        """Base constructor. Must be called by subclass."""
+        super().__init__(log.C_RUN, name)
+        self.conf = conf
+
+#############################
+# PUBLIC (test API included)
+#############################
+    @abstractmethod
+    def set_attenuation(self, db):
+        """Set attenuation in dB on the configured channel"""
+        pass
+
+
+from . import rfemu_amarisoftctrl, rfemu_minicircuits
+
+KNOWN_RFEMU_TYPES = {
+        'amarisoftctl' : rfemu_amarisoftctrl.RFemulationAmarisoftCtrl,
+        'minicircuits' : rfemu_minicircuits.RFemulationMinicircuitsHTTP,
+}
+
+def get_instance_by_type(rfemu_type, rfemu_opt):
+    """Allocate a RFemulation child class based on type. Opts are passed to the newly created object."""
+    obj = KNOWN_RFEMU_TYPES.get(rfemu_type, None)
+    if not obj:
+        raise log.Error('RFemulation type not supported:', rfemu_type)
+    return obj(rfemu_opt)
+
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/obj/rfemu_amarisoftctrl.py b/src/osmo_gsm_tester/obj/rfemu_amarisoftctrl.py
new file mode 100644
index 0000000..87e4cbd
--- /dev/null
+++ b/src/osmo_gsm_tester/obj/rfemu_amarisoftctrl.py
@@ -0,0 +1,62 @@
+# osmo_gsm_tester: class defining a RF emulation object implemented using Amarisoft Ctl interface
+#
+# Copyright (C) 2020 by sysmocom - s.f.m.c. GmbH
+#
+# Author: Pau Espin Pedrol <pespin at sysmocom.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import json
+from websocket import create_connection
+
+from ..core import log
+from .rfemu import RFemulation
+
+class RFemulationAmarisoftCtrl(RFemulation):
+##############
+# PROTECTED
+##############
+    def __init__(self, conf):
+        super().__init__(conf, 'amarisoftctl')
+        self.addr = conf.get('addr')
+        self.port = conf.get('ports')
+        if self.addr is None:
+            raise log.Error('No "addr" attribute provided in supply conf!')
+        if self.port is None or len(self.port) != 1:
+            raise log.Error('No "port" attribute provided in supply conf!')
+        self.port = self.port[0]
+        self.set_name('amarisoftctl(%s:%d)' % (self.addr, self.port))
+        self.cell_id = conf.get('cell_id')
+        if self.cell_id is None:
+            raise log.Error('No "cell_id" attribute provided in supply conf!')
+        self.ws = create_connection("ws://%s:%s" % (self.addr, self.port))
+
+    def __del__(self):
+        self.dbg('closing CTRL websocket')
+        self.ws.close()
+
+#############################
+# PUBLIC (test API included)
+#############################
+    def set_attenuation(self, db):
+        msg = { "message": "cell_gain", "cell_id": int(self.cell_id), "gain": -db }
+        msg_str = json.dumps(msg)
+        self.dbg('sending CTRL msg: "%s"' % msg_str)
+        self.ws.send(msg_str)
+        self.dbg('waiting CTRL recv...')
+        result = self.ws.recv()
+        self.dbg('Received CTRL msg: "%s"' % result)
+
+
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/obj/rfemu_minicircuits.py b/src/osmo_gsm_tester/obj/rfemu_minicircuits.py
new file mode 100644
index 0000000..eea3a0e
--- /dev/null
+++ b/src/osmo_gsm_tester/obj/rfemu_minicircuits.py
@@ -0,0 +1,67 @@
+# osmo_gsm_tester: class defining a RF emulation object implemented using a Minicircuits RC4DAT-6G-60 device
+#
+# Copyright (C) 2020 by sysmocom - s.f.m.c. GmbH
+#
+# Author: Pau Espin Pedrol <pespin at sysmocom.de>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+import urllib.request
+import xml.etree.ElementTree as ET
+
+from ..core import log
+from .rfemu import RFemulation
+
+# https://www.minicircuits.com/softwaredownload/Prog_Manual-6-Programmable_Attenuator.pdf
+class RFemulationMinicircuitsHTTP(RFemulation):
+
+    # HTTP request timeout, in seconds
+    HTTP_TIMEOUT = 5
+
+##############
+# PROTECTED
+##############
+    def __init__(self, conf):
+        super().__init__(conf, 'minicircuits')
+        self.addr = conf.get('addr')
+        self.ports = conf.get('ports')
+        if self.addr is None:
+            raise log.Error('No "addr" attribute provided in supply conf!')
+        if self.ports is None or len(self.ports) == 0:
+            raise log.Error('No "port" attribute provided in supply conf!')
+        self.set_name('minicircuits(%s:%r)' % (self.addr, self.ports))
+
+    def _url_prefix(self):
+        #http://10.12.1.216/:SetAttPerChan:1:0_2:0_3:0_4:0
+        return 'http://' + self.addr
+
+    def _utl_set_attenauation(self, db):
+        ports_str = ""
+        for port in self.ports:
+            ports_str = ports_str + str(port) + ":"
+
+        return self._url_prefix() + '/:CHAN:' + ports_str + 'SETATT:' + str(db)
+
+#############################
+# PUBLIC (test API included)
+#############################
+    def set_attenuation(self, db):
+        url = self._utl_set_attenauation(db)
+        self.dbg('sending HTTP req: "%s"' % url)
+        data = urllib.request.urlopen(url, timeout = self.HTTP_TIMEOUT).read()
+        data_str = str(data, 'utf-8')
+        self.dbg('Received response: "%s"' % data_str)
+        if data_str != '1':
+            raise log.Error('Mini-circuits attenuation device returned failure! %s' & data_str)
+# vim: expandtab tabstop=4 shiftwidth=4
diff --git a/src/osmo_gsm_tester/resource.py b/src/osmo_gsm_tester/resource.py
index efb7d5a..d4757f3 100644
--- a/src/osmo_gsm_tester/resource.py
+++ b/src/osmo_gsm_tester/resource.py
@@ -111,6 +111,9 @@
         'enb[].cell_list[].cell_id': schema.UINT,
         'enb[].cell_list[].scell_list[]': schema.UINT,
         'enb[].cell_list[].dl_earfcn': schema.UINT,
+        'enb[].cell_list[].dl_rfemu.type': schema.STR,
+        'enb[].cell_list[].dl_rfemu.addr': schema.IPV4,
+        'enb[].cell_list[].dl_rfemu.ports[]': schema.UINT,
         'arfcn[].arfcn': schema.INT,
         'arfcn[].band': schema.BAND,
         'modem[].type': schema.STR,
diff --git a/sysmocom/suites/4g/handover.py b/sysmocom/suites/4g/handover.py
new file mode 100755
index 0000000..3a49321
--- /dev/null
+++ b/sysmocom/suites/4g/handover.py
@@ -0,0 +1,29 @@
+#!/usr/bin/env python3
+from osmo_gsm_tester.testenv import *
+
+epc = suite.epc()
+enb = suite.enb()
+ue = suite.modem()
+
+epc.subscriber_add(ue)
+epc.start()
+enb.ue_add(ue)
+enb.start(epc)
+
+print('waiting for ENB to connect to EPC...')
+wait(epc.enb_is_connected, enb)
+print('ENB is connected to EPC')
+
+ue.connect(enb)
+print('waiting for UE to attach...')
+wait(ue.is_connected, None)
+print('UE is attached')
+
+sleep(2)
+
+rfemu = enb.get_rfemu()
+for att in range(1, 10, 1):
+    print("Setting cell attenuation %d..." % att)
+    rfemu.set_attenuation(att)
+    sleep(1)
+print("Done")

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-gsm-tester/+/17847
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Change-Id: Ie98a3fb9bcd2b87b96ecbb5b79e0f53981892a32
Gerrit-Change-Number: 17847
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200417/3232dd9a/attachment.htm>


More information about the gerrit-log mailing list