summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/common
diff options
context:
space:
mode:
authorDan Klein <danklein10@gmail.com>2015-11-26 13:06:36 +0200
committerDan Klein <danklein10@gmail.com>2015-11-26 13:06:36 +0200
commit91f6c24f45cbb0cbf8568a9938059a1a934e6ae6 (patch)
tree0977d1129173d2b2be8e36c91aa5b7ec97b035a1 /scripts/automation/trex_control_plane/common
parente7cb8b0f6c2fbe08d2086a7408040ac7d12aee5a (diff)
Initial implementation of stats prompting
Diffstat (limited to 'scripts/automation/trex_control_plane/common')
-rwxr-xr-xscripts/automation/trex_control_plane/common/trex_stats.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/common/trex_stats.py b/scripts/automation/trex_control_plane/common/trex_stats.py
index b7e768c1..bf5ba2bb 100755
--- a/scripts/automation/trex_control_plane/common/trex_stats.py
+++ b/scripts/automation/trex_control_plane/common/trex_stats.py
@@ -1,6 +1,86 @@
#!/router/bin/python
+from collections import namedtuple, OrderedDict
+from client_utils import text_tables
import copy
+GLOBAL_STATS = 'g'
+PORT_STATS = 'p'
+PORT_STATUS = 'ps'
+ALL_STATS_OPTS = {GLOBAL_STATS, PORT_STATS, PORT_STATUS}
+ExportableStats = namedtuple('ExportableStats', ['raw_data', 'text_table'])
+
+
+class CTRexInformationCenter(object):
+
+ def __init__(self, connection_info, ports_ref, async_stats_ref):
+ self.connection_info = connection_info
+ self.server_version = None
+ self.system_info = None
+ self._ports = ports_ref
+ self._async_stats = async_stats_ref
+
+ # def __getitem__(self, item):
+ # stats_obj = getattr(self, item)
+ # if stats_obj:
+ # return stats_obj.get_stats()
+ # else:
+ # return None
+
+ def generate_single_statistic(self, statistic_type):
+ if statistic_type == GLOBAL_STATS:
+ return self._generate_global_stats()
+ elif statistic_type == PORT_STATS:
+ # return generate_global_stats()
+ pass
+ elif statistic_type == PORT_STATUS:
+ pass
+ else:
+ # ignore by returning empty object
+ return {}
+
+ def _generate_global_stats(self):
+ stats_obj = self._async_stats.get_general_stats()
+ return_stats_data = \
+ OrderedDict([("connection", "{host}, Port {port}".format(host=self.connection_info.get("server"),
+ port=self.connection_info.get("sync_port"))),
+ ("version", self.server_version.get("version", "N/A")),
+ ("cpu_util", stats_obj.get("m_cpu_util")),
+ ("total_tx", stats_obj.get("m_tx_bps", format=True, suffix="b/sec")),
+ # {'m_tx_bps': stats_obj.get("m_tx_bps", format= True, suffix= "b/sec"),
+ # 'm_tx_pps': stats_obj.get("m_tx_pps", format= True, suffix= "pkt/sec"),
+ # 'm_total_tx_bytes':stats_obj.get_rel("m_total_tx_bytes",
+ # format= True,
+ # suffix = "B"),
+ # 'm_total_tx_pkts': stats_obj.get_rel("m_total_tx_pkts",
+ # format= True,
+ # suffix = "pkts")},
+ ("total_rx", stats_obj.get("m_rx_bps", format=True, suffix="b/sec")),
+ # {'m_rx_bps': stats_obj.get("m_rx_bps", format= True, suffix= "b/sec"),
+ # 'm_rx_pps': stats_obj.get("m_rx_pps", format= True, suffix= "pkt/sec"),
+ # 'm_total_rx_bytes': stats_obj.get_rel("m_total_rx_bytes",
+ # format= True,
+ # suffix = "B"),
+ # 'm_total_rx_pkts': stats_obj.get_rel("m_total_rx_pkts",
+ # format= True,
+ # suffix = "pkts")},
+ ("total_pps", stats_obj.format_num(stats_obj.get("m_tx_pps") + stats_obj.get("m_rx_pps"),
+ suffix="pkt/sec")),
+ ("total_streams", sum([len(port.streams)
+ for port in self._ports])),
+ ("active_ports", sum([port.is_active()
+ for port in self._ports]))
+ ]
+ )
+
+ # build table representation
+ stats_table = text_tables.TRexTextInfo()
+ stats_table.set_cols_align(["l", "l"])
+ stats_table.add_rows([[k.replace("_", " ").title(), v]
+ for k, v in return_stats_data.iteritems()],
+ header=False)
+
+ return {"global_statistics": ExportableStats(return_stats_data, stats_table)}
+
class CTRexStatsManager(object):