summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-11-25 06:56:04 -0500
committerimarom <imarom@cisco.com>2015-11-25 06:56:04 -0500
commit92dea3787ab7b2c9877af9cd539d42a6957f7da6 (patch)
tree1cb27bc6eb3ffe3ea06609448e9dfb4dd47d1f5d /scripts
parent4a41c26a5cf23635a5b1332af6e806c915cf7e6c (diff)
added events log
Diffstat (limited to 'scripts')
-rw-r--r--scripts/automation/trex_control_plane/client/trex_async_client.py11
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_stateless_client.py35
-rwxr-xr-xscripts/automation/trex_control_plane/console/trex_console.py6
3 files changed, 42 insertions, 10 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 adb91d97..7641a1e3 100644
--- a/scripts/automation/trex_control_plane/client/trex_async_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_async_client.py
@@ -197,7 +197,6 @@ class CTRexAsyncClient():
return self.stats
def get_raw_snapshot (self):
- #return str(self.stats.global_stats.get('m_total_tx_bytes')) + " / " + str(self.stats.global_stats.get_rel('m_total_tx_bytes'))
return self.raw_snapshot
@@ -208,18 +207,10 @@ class CTRexAsyncClient():
self.stats.update(data)
# events
elif name == "trex-event":
- self.__handle_async_event(type, data)
+ self.stateless_client.handle_async_event(type, data)
else:
- # ignore
pass
- def __handle_async_event (self, type, data):
- # DP stopped
- if (type == 0):
- port_id = int(data['port_id'])
- print format_text("\n[Event] - Port {0} Stopped".format(port_id), 'bold')
- # call the handler
- self.stateless_client.async_event_port_stopped(port_id)
def stop (self):
self.active = False
diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
index 30550ca3..1d0ca606 100755
--- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
@@ -16,6 +16,7 @@ from collections import namedtuple
from common.text_opts import *
import parsing_opts
import time
+import datetime
from trex_async_client import CTRexAsyncClient
@@ -400,10 +401,44 @@ class CTRexStatelessClient(object):
self.connected = False
+ self.events = []
+
################# events handler ######################
+
+ def handle_async_event (self, type, data):
+ # DP stopped
+
+ ev = "[event] - "
+
+ if (type == 0):
+ port_id = int(data['port_id'])
+ ev += "Port {0} has stopped".format(port_id)
+ # call the handler
+ self.async_event_port_stopped(port_id)
+
+ elif (type == 1):
+ ev += "Server has stopped"
+ self.async_event_server_stopped()
+
+ else:
+ # unknown event - ignore
+ return
+
+ print format_text("\n" + ev, 'bold')
+
+ ts = time.time()
+ st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
+ self.events.append("{0} - ".format(st) + format_text(ev, 'bold'))
+
def async_event_port_stopped (self, port_id):
self.ports[port_id].async_event_port_stopped()
+ def async_event_server_stopped (self):
+ self.disconnect()
+
+ def get_events (self):
+ return self.events
+
############# helper functions section ##############
def validate_port_list(self, port_id_list):
diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py
index dc1515e0..b164af4e 100755
--- a/scripts/automation/trex_control_plane/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/console/trex_console.py
@@ -334,6 +334,12 @@ class TRexConsole(TRexGeneralCmd):
self.stateless_client.cmd_reset()
+ def do_events (self, line):
+ '''shows events recieved from server\n'''
+ events = self.stateless_client.get_events()
+ for ev in events:
+ print ev
+
# tui
def do_tui (self, line):
'''Shows a graphical console\n'''