blob: c4d8e623c7849000a794bca8568894628d2ca160 [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
25 def __init__(self):
26 self.log_file = None
27 self.process = None
28 self.metrics_file = None
Andre Puschmann99fb78b2020-09-14 18:14:15 +020029 self.stop_sleep_time = 6 # We require at most 5s to stop
30 self.kpis = None
31
32 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
37
38 def stop(self):
39 self.testenv.stop_process(self.process)
40 self.sleep_after_stop()
Andre Puschmannf14ff812020-06-19 15:47:32 +020041
42 def get_kpis(self):
Andre Puschmann99fb78b2020-09-14 18:14:15 +020043 ''' Return all KPI '''
44 if self.kpis is None:
45 self.extract_kpis()
46 return self.kpis
47
48 def get_log_kpis(self):
49 ''' Return KPIs extracted from log '''
50 if self.kpis is None:
51 self.extract_kpis()
52
53 # Use log KPIs if they exist for this node
54 if "log_" + self.name() in self.kpis:
55 log_kpi = self.kpis["log_" + self.name()]
56 else:
57 log_kpi = {}
58
59 # Make sure we have the errors and warnings counter in the dict
60 if 'total_errors' not in log_kpi:
61 log_kpi['total_errors'] = 0
62 if 'total_warnings' not in log_kpi:
63 log_kpi['total_warnings'] = 0
64 return log_kpi
65
66 def extract_kpis(self):
Andre Puschmannf14ff812020-06-19 15:47:32 +020067 ''' Use the srsLTE KPI analyzer module (part of srsLTE.git) if available to collect KPIs '''
Andre Puschmann99fb78b2020-09-14 18:14:15 +020068
69 # Stop application, copy back logs and process them
70 if self.running():
71 self.stop()
72 self.cleanup()
73
74 self.kpis = {}
Andre Puschmannf14ff812020-06-19 15:47:32 +020075 try:
76 # Please make sure the srsLTE scripts folder is included in your PYTHONPATH env variable
77 from kpi_analyzer import kpi_analyzer
78 analyzer = kpi_analyzer(self.name())
79 if self.log_file is not None:
Andre Puschmann99fb78b2020-09-14 18:14:15 +020080 self.kpis["log_" + self.name()] = analyzer.get_kpi_from_logfile(self.log_file)
Andre Puschmannf14ff812020-06-19 15:47:32 +020081 if self.process.get_output_file('stdout') is not None:
Andre Puschmann99fb78b2020-09-14 18:14:15 +020082 self.kpis["stdout_" + self.name()] = analyzer.get_kpi_from_stdout(self.process.get_output_file('stdout'))
Andre Puschmannf14ff812020-06-19 15:47:32 +020083 if self.metrics_file is not None:
Andre Puschmann99fb78b2020-09-14 18:14:15 +020084 self.kpis["csv_" + self.name()] = analyzer.get_kpi_from_csv(self.metrics_file)
Andre Puschmannf14ff812020-06-19 15:47:32 +020085 except ImportError:
86 self.log("Can't load KPI analyzer module.")
Andre Puschmann99fb78b2020-09-14 18:14:15 +020087 self.kpis = {}
Andre Puschmannf14ff812020-06-19 15:47:32 +020088
Andre Puschmann99fb78b2020-09-14 18:14:15 +020089 return self.kpis
Andre Puschmannf4fb48a2020-10-05 15:24:17 +020090
91 def get_num_phy_errors(self, kpi):
92 """ Use KPI analyzer to calculate the number PHY errors for either UE or eNB components from parsed KPI vector """
93 try:
94 # Same as above, make sure the srsLTE scripts folder is included in your PYTHONPATH env variable
95 from kpi_analyzer import kpi_analyzer
96 analyzer = kpi_analyzer(self.name())
97 return analyzer.get_num_phy_errors(kpi)
98 except ImportError:
99 self.log("Can't load KPI analyzer module.")
100 return 0