summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/client/trex_async_client.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/automation/trex_control_plane/client/trex_async_client.py')
-rw-r--r--scripts/automation/trex_control_plane/client/trex_async_client.py45
1 files changed, 24 insertions, 21 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_async_client.py b/scripts/automation/trex_control_plane/client/trex_async_client.py
index e38c6ca7..8fdf7c9b 100644
--- a/scripts/automation/trex_control_plane/client/trex_async_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_async_client.py
@@ -21,13 +21,14 @@ from common.trex_stats import *
from common.trex_streams import *
# basic async stats class
-class TrexAsyncStats(object):
+class CTRexAsyncStats(object):
def __init__ (self):
self.ref_point = None
self.current = {}
self.last_update_ts = datetime.datetime.now()
- def __format_num (self, size, suffix = ""):
+ @staticmethod
+ def format_num (size, suffix = ""):
for unit in ['','K','M','G','T','P']:
if abs(size) < 1000.0:
@@ -45,9 +46,12 @@ class TrexAsyncStats(object):
if self.ref_point == None:
self.ref_point = self.current
+
+ def clear(self):
+ self.ref_point = self.current
- def get (self, field, format = False, suffix = ""):
+ def get(self, field, format=False, suffix=""):
if not field in self.current:
return "N/A"
@@ -55,17 +59,16 @@ class TrexAsyncStats(object):
if not format:
return self.current[field]
else:
- return self.__format_num(self.current[field], suffix)
-
+ return self.format_num(self.current[field], suffix)
- def get_rel (self, field, format = False, suffix = ""):
+ def get_rel (self, field, format=False, suffix=""):
if not field in self.current:
return "N/A"
if not format:
return (self.current[field] - self.ref_point[field])
else:
- return self.__format_num(self.current[field] - self.ref_point[field], suffix)
+ return self.format_num(self.current[field] - self.ref_point[field], suffix)
# return true if new data has arrived in the past 2 seconds
@@ -74,28 +77,28 @@ class TrexAsyncStats(object):
return (delta_ms < 2000)
# describes the general stats provided by TRex
-class TrexAsyncStatsGeneral(TrexAsyncStats):
+class CTRexAsyncStatsGeneral(CTRexAsyncStats):
def __init__ (self):
- super(TrexAsyncStatsGeneral, self).__init__()
+ super(CTRexAsyncStatsGeneral, self).__init__()
# per port stats
-class TrexAsyncStatsPort(TrexAsyncStats):
+class CTRexAsyncStatsPort(CTRexAsyncStats):
def __init__ (self):
- super(TrexAsyncStatsPort, self).__init__()
+ super(CTRexAsyncStatsPort, self).__init__()
def get_stream_stats (self, stream_id):
return None
# stats manager
-class TrexAsyncStatsManager():
+class CTRexAsyncStatsManager():
def __init__ (self):
- self.general_stats = TrexAsyncStatsGeneral()
+ self.general_stats = CTRexAsyncStatsGeneral()
self.port_stats = {}
- def get_general_stats (self):
+ def get_general_stats(self):
return self.general_stats
def get_port_stats (self, port_id):
@@ -106,10 +109,10 @@ class TrexAsyncStatsManager():
return self.port_stats[str(port_id)]
- def update (self, data):
+ def update(self, data):
self.__handle_snapshot(data)
- def __handle_snapshot (self, snapshot):
+ def __handle_snapshot(self, snapshot):
general_stats = {}
port_stats = {}
@@ -140,7 +143,7 @@ class TrexAsyncStatsManager():
for port_id, data in port_stats.iteritems():
if not port_id in self.port_stats:
- self.port_stats[port_id] = TrexAsyncStatsPort()
+ self.port_stats[port_id] = CTRexAsyncStatsPort()
self.port_stats[port_id].update(data)
@@ -157,7 +160,7 @@ class CTRexAsyncClient():
self.raw_snapshot = {}
- self.stats = TrexAsyncStatsManager()
+ self.stats = CTRexAsyncStatsManager()
self.connected = False
@@ -227,7 +230,7 @@ class CTRexAsyncClient():
while self.active:
try:
- line = self.socket.recv_string();
+ line = self.socket.recv_string()
if not self.alive:
self.stateless_client.on_async_alive()
@@ -267,15 +270,15 @@ class CTRexAsyncClient():
def get_raw_snapshot (self):
return self.raw_snapshot
-
# dispatch the message to the right place
def __dispatch (self, name, type, data):
# stats
if name == "trex-global":
- self.stats.update(data)
+ self.stateless_client.handle_async_stats_update(data)
# events
elif name == "trex-event":
self.stateless_client.handle_async_event(type, data)
else:
pass
+