summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-11-02 16:40:34 +0200
committerimarom <imarom@cisco.com>2015-11-02 16:40:34 +0200
commit3fb4e4c130da10e58af07e1f783f093515e90f96 (patch)
treee0e9ccbf230884efb58a74cbba8f88953c34196d
parent1586ab131f28c03ea65373d9e702e4051ffb9a56 (diff)
few bug fixes for last commit
-rw-r--r--scripts/automation/trex_control_plane/client/trex_async_client.py30
-rwxr-xr-xscripts/automation/trex_control_plane/console/trex_console.py4
-rw-r--r--scripts/automation/trex_control_plane/console/trex_status.py11
3 files changed, 34 insertions, 11 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 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:
diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py
index bd79cb42..549262c5 100755
--- a/scripts/automation/trex_control_plane/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/console/trex_console.py
@@ -409,6 +409,10 @@ class TRexConsole(cmd.Cmd):
def do_status (self, line):
'''Shows a graphical console\n'''
+ if not self.stateless_client.is_connected():
+ print "Not connected to server\n"
+ return
+
self.do_verbose('off')
trex_status.show_trex_status(self.stateless_client)
diff --git a/scripts/automation/trex_control_plane/console/trex_status.py b/scripts/automation/trex_control_plane/console/trex_status.py
index 4cd07358..4e73e0bb 100644
--- a/scripts/automation/trex_control_plane/console/trex_status.py
+++ b/scripts/automation/trex_control_plane/console/trex_status.py
@@ -113,6 +113,10 @@ class GeneralInfoPanel(TrexStatusPanel):
def draw (self):
self.clear()
+ if not self.general_stats.is_online():
+ self.getwin().addstr(3, 2, "No Published Data From TRex Server")
+ return
+
self.getwin().addstr(3, 2, "{:<30} {:0.2f} %".format("CPU util.:", self.general_stats.get("m_cpu_util")))
self.getwin().addstr(5, 2, "{:<30} {:} / {:}".format("Total Tx. rate:",
@@ -366,6 +370,10 @@ class TrexStatus():
self.stdscr = stdscr
self.stateless_client = stateless_client
+
+ self.log = TrexStatusLog()
+ self.cmds = TrexStatusCommands(self)
+
self.general_stats = stateless_client.get_stats_async().get_general_stats()
# fetch server info
@@ -379,8 +387,7 @@ class TrexStatus():
self.owned_ports = self.stateless_client.get_acquired_ports()
- self.log = TrexStatusLog()
- self.cmds = TrexStatusCommands(self)
+
def generate_layout (self):
self.max_y = self.stdscr.getmaxyx()[0]