{enb,epc,ms}_srs: refactor start/stop and KPI helpers

refactor some of the functionality to srslte_common

Change-Id: I2ff36df6f1a07ed8ddac39d296d62fe44a215283
This commit is contained in:
Andre Puschmann 2020-09-14 18:14:15 +02:00
parent 3d3bbcb3ae
commit 99fb78bfca
4 changed files with 57 additions and 24 deletions

View File

@ -51,6 +51,7 @@ class srsENB(enb.eNodeB, srslte_common):
def __init__(self, testenv, conf):
super().__init__(testenv, conf, srsENB.BINFILE)
srslte_common.__init__(self)
self.ue = None
self.run_dir = None
self.gen_conf = None
@ -73,6 +74,7 @@ class srsENB(enb.eNodeB, srslte_common):
self.metrics_file = None
self.stop_sleep_time = 6 # We require at most 5s to stop
self.testenv = testenv
self.kpis = None
self._additional_args = []
if not rf_type_valid(conf.get('rf_dev_type', None)):
raise log.Error('Invalid rf_dev_type=%s' % conf.get('rf_dev_type', None))
@ -100,12 +102,6 @@ class srsENB(enb.eNodeB, srslte_common):
# Collect KPIs for each TC
self.testenv.test().set_kpis(self.get_kpis())
def sleep_after_stop(self):
# Only sleep once
if self.stop_sleep_time > 0:
MainLoop.sleep(self.stop_sleep_time)
self.stop_sleep_time = 0
def start(self, epc):
self.log('Starting srsENB')
self._epc = epc

View File

@ -23,6 +23,7 @@ import pprint
from ..core import log, util, config, template, process, remote
from ..core import schema
from . import epc
from .srslte_common import srslte_common
def on_register_schemas():
config_schema = {
@ -31,7 +32,7 @@ def on_register_schemas():
}
schema.register_config_schema('epc', config_schema)
class srsEPC(epc.EPC):
class srsEPC(epc.EPC, srslte_common):
REMOTE_DIR = '/osmo-gsm-tester-srsepc'
BINFILE = 'srsepc'
@ -42,6 +43,7 @@ class srsEPC(epc.EPC):
def __init__(self, testenv, run_node):
super().__init__(testenv, run_node, 'srsepc')
srslte_common.__init__(self)
self.run_dir = None
self.config_file = None
self.db_file = None
@ -55,6 +57,7 @@ class srsEPC(epc.EPC):
self.remote_log_file = None
self.remote_pcap_file = None
self.enable_pcap = False
self.kpis = None
self.subscriber_list = []
def cleanup(self):

View File

@ -24,7 +24,6 @@ import re
from ..core import log, util, config, template, process, remote
from ..core import schema
from .run_node import RunNode
from ..core.event_loop import MainLoop
from .ms import MS
from .srslte_common import srslte_common
@ -77,6 +76,7 @@ class srsUE(MS, srslte_common):
def __init__(self, testenv, conf):
self._run_node = RunNode.from_conf(conf.get('run_node', {}))
super().__init__('srsue_%s' % self.addr(), conf)
srslte_common.__init__(self)
self.enb = None
self.run_dir = None
self.config_file = None
@ -92,9 +92,9 @@ class srsUE(MS, srslte_common):
self.remote_log_file = None
self.remote_pcap_file = None
self.remote_metrics_file = None
self.stop_sleep_time = 6 # We require at most 5s to stop
self.enable_pcap = False
self.num_carriers = 1
self.kpis = None
self.testenv = testenv
self._additional_args = []
if not rf_type_valid(conf.get('rf_dev_type', None)):
@ -150,16 +150,6 @@ class srsUE(MS, srslte_common):
def netns(self):
return "srsue1"
def sleep_after_stop(self):
# Only sleep once
if self.stop_sleep_time > 0:
MainLoop.sleep(self.stop_sleep_time)
self.stop_sleep_time = 0
def stop(self):
self.testenv.stop_process(self.process)
self.sleep_after_stop()
def connect(self, enb):
self.log('Starting srsue')
self.enb = enb

View File

@ -18,6 +18,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from ..core import log
from ..core.event_loop import MainLoop
class srslte_common(): # don't inherit from log.Origin here but instead use .name() from whoever inherits from us
@ -25,21 +26,64 @@ class srslte_common(): # don't inherit from log.Origin here but instead use .nam
self.log_file = None
self.process = None
self.metrics_file = None
self.stop_sleep_time = 6 # We require at most 5s to stop
self.kpis = None
def sleep_after_stop(self):
# Only sleep once
if self.stop_sleep_time > 0:
MainLoop.sleep(self.stop_sleep_time)
self.stop_sleep_time = 0
def stop(self):
self.testenv.stop_process(self.process)
self.sleep_after_stop()
def get_kpis(self):
''' Return all KPI '''
if self.kpis is None:
self.extract_kpis()
return self.kpis
def get_log_kpis(self):
''' Return KPIs extracted from log '''
if self.kpis is None:
self.extract_kpis()
# Use log KPIs if they exist for this node
if "log_" + self.name() in self.kpis:
log_kpi = self.kpis["log_" + self.name()]
else:
log_kpi = {}
# Make sure we have the errors and warnings counter in the dict
if 'total_errors' not in log_kpi:
log_kpi['total_errors'] = 0
if 'total_warnings' not in log_kpi:
log_kpi['total_warnings'] = 0
return log_kpi
def extract_kpis(self):
''' Use the srsLTE KPI analyzer module (part of srsLTE.git) if available to collect KPIs '''
kpis = {}
# Stop application, copy back logs and process them
if self.running():
self.stop()
self.cleanup()
self.kpis = {}
try:
# Please make sure the srsLTE scripts folder is included in your PYTHONPATH env variable
from kpi_analyzer import kpi_analyzer
analyzer = kpi_analyzer(self.name())
if self.log_file is not None:
kpis["log_" + self.name()] = analyzer.get_kpi_from_logfile(self.log_file)
self.kpis["log_" + self.name()] = analyzer.get_kpi_from_logfile(self.log_file)
if self.process.get_output_file('stdout') is not None:
kpis["stdout_" + self.name()] = analyzer.get_kpi_from_stdout(self.process.get_output_file('stdout'))
self.kpis["stdout_" + self.name()] = analyzer.get_kpi_from_stdout(self.process.get_output_file('stdout'))
if self.metrics_file is not None:
kpis["csv_" + self.name()] = analyzer.get_kpi_from_csv(self.metrics_file)
self.kpis["csv_" + self.name()] = analyzer.get_kpi_from_csv(self.metrics_file)
except ImportError:
self.log("Can't load KPI analyzer module.")
self.kpis = {}
return kpis
return self.kpis