blob: aa41cd266dcb53e3db93955fe191f3945c5ef4e4 [file] [log] [blame]
Andre Puschmannf14ff812020-06-19 15:47:32 +02001# osmo_gsm_tester: common methods shared among srsLTE components
2#
3# Copyright (C) 2020 by Software Radio Systems Ltd
4#
5# Author: Andre Puschmann <andre@softwareradiosystems.com>
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
20from ..core import log
Andre Puschmann99fb78b2020-09-14 18:14:15 +020021from ..core.event_loop import MainLoop
Andre Puschmannf14ff812020-06-19 15:47:32 +020022
23class srslte_common(): # don't inherit from log.Origin here but instead use .name() from whoever inherits from us
24
Andre Puschmann182109d2020-10-05 20:03:13 +020025 def __init__(self):
26 self.log_file = None
27 self.process = None
28 self.metrics_file = None
29 self.stop_sleep_time = 6 # We require at most 5s to stop
Andre Puschmann3ce67252021-01-29 17:45:18 +010030 self.log_kpi = None
31 self.stdout_kpi = None
32 self.csv_kpi = None
Andre Puschmann99fb78b2020-09-14 18:14:15 +020033
Andre Puschmann182109d2020-10-05 20:03:13 +020034 def sleep_after_stop(self):
35 # Only sleep once
36 if self.stop_sleep_time > 0:
37 MainLoop.sleep(self.stop_sleep_time)
38 self.stop_sleep_time = 0
Andre Puschmann99fb78b2020-09-14 18:14:15 +020039
Andre Puschmann182109d2020-10-05 20:03:13 +020040 def stop(self):
Andre Puschmann215bec22021-01-08 12:34:48 +010041 # Send q+Enter to stdin to self-terminate application
42 self.process.stdin_write('q\n')
Andre Puschmann182109d2020-10-05 20:03:13 +020043 self.testenv.stop_process(self.process)
44 self.sleep_after_stop()
Andre Puschmannf14ff812020-06-19 15:47:32 +020045
Andre Puschmann182109d2020-10-05 20:03:13 +020046 def get_kpis(self):
Andre Puschmann3ce67252021-01-29 17:45:18 +010047 ''' Merge all KPI and return as flat dict '''
48 self.extract_kpis()
49 kpi_flat = {}
50 kpi_flat.update(self.log_kpi)
51 kpi_flat.update(self.stdout_kpi)
52 kpi_flat.update(self.csv_kpi)
53 return kpi_flat
Andre Puschmann99fb78b2020-09-14 18:14:15 +020054
Andre Puschmann3ce67252021-01-29 17:45:18 +010055 def get_kpi_tree(self):
56 ''' Return all KPI as dict of dict in which the source (e.g. stdout_srsue1) is the key of the first dict '''
57 self.extract_kpis()
58 kpi_tree = {}
59 kpi_tree["log_" + self.name()] = self.log_kpi
60 kpi_tree["csv_" + self.name()] = self.csv_kpi
61 kpi_tree["stdout_" + self.name()] = self.stdout_kpi
62 return kpi_tree
Andre Puschmann99fb78b2020-09-14 18:14:15 +020063
Andre Puschmann182109d2020-10-05 20:03:13 +020064 def extract_kpis(self):
65 ''' Use the srsLTE KPI analyzer module (part of srsLTE.git) if available to collect KPIs '''
Andre Puschmann99fb78b2020-09-14 18:14:15 +020066
Andre Puschmann3ce67252021-01-29 17:45:18 +010067 # Make sure this only runs once
Andre Puschmann67ab78b2021-03-16 16:44:20 +010068 if self.csv_kpi is not None and self.log_kpi is not None and self.stdout_kpi is not None:
Andre Puschmann3ce67252021-01-29 17:45:18 +010069 return
70
71 # Start with empty KPIs
72 self.log_kpi = {}
73 self.stdout_kpi = {}
74 self.csv_kpi = {}
75
Andre Puschmann182109d2020-10-05 20:03:13 +020076 # Stop application, copy back logs and process them
77 if self.running():
78 self.stop()
79 self.cleanup()
Andre Puschmann182109d2020-10-05 20:03:13 +020080 try:
81 # Please make sure the srsLTE scripts folder is included in your PYTHONPATH env variable
82 from kpi_analyzer import kpi_analyzer
83 analyzer = kpi_analyzer(self.name())
84 if self.log_file is not None:
Andre Puschmann3ce67252021-01-29 17:45:18 +010085 self.log_kpi = analyzer.get_kpi_from_logfile(self.log_file)
Andre Puschmann182109d2020-10-05 20:03:13 +020086 if self.process.get_output_file('stdout') is not None:
Andre Puschmann3ce67252021-01-29 17:45:18 +010087 self.stdout_kpi = analyzer.get_kpi_from_stdout(self.process.get_output_file('stdout'))
Andre Puschmann182109d2020-10-05 20:03:13 +020088 if self.metrics_file is not None:
Andre Puschmann3ce67252021-01-29 17:45:18 +010089 self.csv_kpi = analyzer.get_kpi_from_csv(self.metrics_file)
90 # PHY errors for either UE or eNB components from parsed KPI vector as extra entry in dict
91 self.log_kpi["num_phy_errors"] = analyzer.get_num_phy_errors(self.log_kpi)
Andre Puschmann182109d2020-10-05 20:03:13 +020092 except ImportError:
Andre Puschmann3ce67252021-01-29 17:45:18 +010093 self.log("Can't load KPI analyzer module.")