From 3fb4e4c130da10e58af07e1f783f093515e90f96 Mon Sep 17 00:00:00 2001 From: imarom Date: Mon, 2 Nov 2015 16:40:34 +0200 Subject: few bug fixes for last commit --- .../trex_control_plane/client/trex_async_client.py | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'scripts/automation/trex_control_plane/client') 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 ea716057..1ce10288 100644 --- a/scripts/automation/trex_control_plane/client/trex_async_client.py +++ b/scripts/automation/trex_control_plane/client/trex_async_client.py @@ -11,6 +11,7 @@ from client_utils.jsonrpc_client import JsonRpcClient, BatchMessage import json import threading import time +import datetime import zmq import re @@ -21,9 +22,14 @@ from common.trex_streams import * class TrexAsyncStats(object): def __init__ (self): self.ref_point = None + self.current = {} + self.last_update_ts = datetime.datetime.now() def update (self, snapshot): + #update + self.last_update_ts = datetime.datetime.now() + self.current = snapshot if self.ref_point == None: @@ -33,17 +39,22 @@ class TrexAsyncStats(object): def get (self, field): if not field in self.current: - return None + return 0 return self.current[field] def get_rel (self, field): if not field in self.current: - return None + return 0 return self.current[field] - self.ref_point[field] + # return true if new data has arrived in the past 2 seconds + def is_online (self): + delta_ms = (datetime.datetime.now() - self.last_update_ts).total_seconds() * 1000 + return (delta_ms < 2000) + # describes the general stats provided by TRex class TrexAsyncStatsGeneral(TrexAsyncStats): def __init__ (self): @@ -58,12 +69,12 @@ class TrexAsyncStatsPort(TrexAsyncStats): # stats manager class TrexAsyncStatsManager(): - def __init__ (self, port_count): - self.port_count = port_count + def __init__ (self): self.general_stats = TrexAsyncStatsGeneral() self.port_stats = {} + def get_general_stats (self): return self.general_stats @@ -127,7 +138,11 @@ class TrexAsyncClient(): self.raw_snapshot = {} - self.stats = TrexAsyncStatsManager(1) + self.stats = TrexAsyncStatsManager() + + + self.tr = "tcp://localhost:{0}".format(self.port) + print "\nConnecting To ZMQ Publisher At {0}".format(self.tr) self.active = True self.t = threading.Thread(target = self._run) @@ -143,10 +158,7 @@ class TrexAsyncClient(): self.context = zmq.Context() self.socket = self.context.socket(zmq.SUB) - self.c = "tcp://localhost:{0}".format(self.port) - print "Connecting To ZMQ Publisher At {0}".format(self.c) - - self.socket.connect(self.c) + self.socket.connect(self.tr) self.socket.setsockopt(zmq.SUBSCRIBE, '') while self.active: -- cgit 1.2.3-korg