blob: 21001b7c5f91d99d0edeb1c2b8cabee57895fde8 [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
30 self.kpis = None
Andre Puschmann99fb78b2020-09-14 18:14:15 +020031
Andre Puschmann182109d2020-10-05 20:03:13 +020032 def sleep_after_stop(self):
33 # Only sleep once
34 if self.stop_sleep_time > 0:
35 MainLoop.sleep(self.stop_sleep_time)
36 self.stop_sleep_time = 0
Andre Puschmann99fb78b2020-09-14 18:14:15 +020037
Andre Puschmann182109d2020-10-05 20:03:13 +020038 def stop(self):
Andre Puschmann215bec22021-01-08 12:34:48 +010039 # Send q+Enter to stdin to self-terminate application
40 self.process.stdin_write('q\n')
Andre Puschmann182109d2020-10-05 20:03:13 +020041 self.testenv.stop_process(self.process)
42 self.sleep_after_stop()
Andre Puschmannf14ff812020-06-19 15:47:32 +020043
Andre Puschmann182109d2020-10-05 20:03:13 +020044 def get_kpis(self):
45 ''' Return all KPI '''
46 if self.kpis is None:
47 self.extract_kpis()
48 return self.kpis
Andre Puschmann99fb78b2020-09-14 18:14:15 +020049
Andre Puschmann182109d2020-10-05 20:03:13 +020050 def get_log_kpis(self):
51 ''' Return KPIs extracted from log '''
52 if self.kpis is None:
53 self.extract_kpis()
Andre Puschmann99fb78b2020-09-14 18:14:15 +020054
Andre Puschmann182109d2020-10-05 20:03:13 +020055 # Use log KPIs if they exist for this node
56 if "log_" + self.name() in self.kpis:
57 log_kpi = self.kpis["log_" + self.name()]
58 else:
59 log_kpi = {}
Andre Puschmann99fb78b2020-09-14 18:14:15 +020060
Andre Puschmann182109d2020-10-05 20:03:13 +020061 # Make sure we have the errors and warnings counter in the dict
62 if 'total_errors' not in log_kpi:
63 log_kpi['total_errors'] = 0
64 if 'total_warnings' not in log_kpi:
65 log_kpi['total_warnings'] = 0
66 return log_kpi
Andre Puschmann99fb78b2020-09-14 18:14:15 +020067
Andre Puschmann182109d2020-10-05 20:03:13 +020068 def extract_kpis(self):
69 ''' Use the srsLTE KPI analyzer module (part of srsLTE.git) if available to collect KPIs '''
Andre Puschmann99fb78b2020-09-14 18:14:15 +020070
Andre Puschmann182109d2020-10-05 20:03:13 +020071 # Stop application, copy back logs and process them
72 if self.running():
73 self.stop()
74 self.cleanup()
Andre Puschmann99fb78b2020-09-14 18:14:15 +020075
Andre Puschmann182109d2020-10-05 20:03:13 +020076 self.kpis = {}
77 try:
78 # Please make sure the srsLTE scripts folder is included in your PYTHONPATH env variable
79 from kpi_analyzer import kpi_analyzer
80 analyzer = kpi_analyzer(self.name())
81 if self.log_file is not None:
82 self.kpis["log_" + self.name()] = analyzer.get_kpi_from_logfile(self.log_file)
83 if self.process.get_output_file('stdout') is not None:
84 self.kpis["stdout_" + self.name()] = analyzer.get_kpi_from_stdout(self.process.get_output_file('stdout'))
85 if self.metrics_file is not None:
86 self.kpis["csv_" + self.name()] = analyzer.get_kpi_from_csv(self.metrics_file)
87 except ImportError:
88 self.log("Can't load KPI analyzer module.")
89 self.kpis = {}
Andre Puschmannf14ff812020-06-19 15:47:32 +020090
Andre Puschmann182109d2020-10-05 20:03:13 +020091 return self.kpis
Andre Puschmannf4fb48a2020-10-05 15:24:17 +020092
Andre Puschmann182109d2020-10-05 20:03:13 +020093 def get_num_phy_errors(self, kpi):
94 """ Use KPI analyzer to calculate the number PHY errors for either UE or eNB components from parsed KPI vector """
95 try:
96 # Same as above, make sure the srsLTE scripts folder is included in your PYTHONPATH env variable
97 from kpi_analyzer import kpi_analyzer
98 analyzer = kpi_analyzer(self.name())
99 return analyzer.get_num_phy_errors(kpi)
100 except ImportError:
101 self.log("Can't load KPI analyzer module.")
Andre Puschmannf249a022021-01-05 14:14:48 +0100102 return 0