Andre Puschmann | f14ff81 | 2020-06-19 15:47:32 +0200 | [diff] [blame] | 1 | # 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 | |
| 20 | from ..core import log |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 21 | from ..core.event_loop import MainLoop |
Andre Puschmann | f14ff81 | 2020-06-19 15:47:32 +0200 | [diff] [blame] | 22 | |
| 23 | class srslte_common(): # don't inherit from log.Origin here but instead use .name() from whoever inherits from us |
| 24 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 25 | 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 Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 31 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 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 |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 37 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 38 | def stop(self): |
| 39 | self.testenv.stop_process(self.process) |
| 40 | self.sleep_after_stop() |
Andre Puschmann | f14ff81 | 2020-06-19 15:47:32 +0200 | [diff] [blame] | 41 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 42 | def get_kpis(self): |
| 43 | ''' Return all KPI ''' |
| 44 | if self.kpis is None: |
| 45 | self.extract_kpis() |
| 46 | return self.kpis |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 47 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 48 | def get_log_kpis(self): |
| 49 | ''' Return KPIs extracted from log ''' |
| 50 | if self.kpis is None: |
| 51 | self.extract_kpis() |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 52 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 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 = {} |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 58 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 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 |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 65 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 66 | def extract_kpis(self): |
| 67 | ''' Use the srsLTE KPI analyzer module (part of srsLTE.git) if available to collect KPIs ''' |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 68 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 69 | # Stop application, copy back logs and process them |
| 70 | if self.running(): |
| 71 | self.stop() |
| 72 | self.cleanup() |
Andre Puschmann | 99fb78b | 2020-09-14 18:14:15 +0200 | [diff] [blame] | 73 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 74 | self.kpis = {} |
| 75 | 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: |
| 80 | self.kpis["log_" + self.name()] = analyzer.get_kpi_from_logfile(self.log_file) |
| 81 | if self.process.get_output_file('stdout') is not None: |
| 82 | self.kpis["stdout_" + self.name()] = analyzer.get_kpi_from_stdout(self.process.get_output_file('stdout')) |
| 83 | if self.metrics_file is not None: |
| 84 | self.kpis["csv_" + self.name()] = analyzer.get_kpi_from_csv(self.metrics_file) |
| 85 | except ImportError: |
| 86 | self.log("Can't load KPI analyzer module.") |
| 87 | self.kpis = {} |
Andre Puschmann | f14ff81 | 2020-06-19 15:47:32 +0200 | [diff] [blame] | 88 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 89 | return self.kpis |
Andre Puschmann | f4fb48a | 2020-10-05 15:24:17 +0200 | [diff] [blame] | 90 | |
Andre Puschmann | 182109d | 2020-10-05 20:03:13 +0200 | [diff] [blame] | 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 |