summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-12-08 09:56:15 -0500
committerimarom <imarom@cisco.com>2015-12-08 09:56:15 -0500
commit8ed7433b1509c21e8840e8152c55e69b1a564dd4 (patch)
treefba504493f1745747a57de80c8a9cf32dabc422c /scripts/automation
parent8713749a155b8d1a7e140d073f0092e3b62cacac (diff)
dynamic commands on TUI
Diffstat (limited to 'scripts/automation')
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_stateless_client.py23
-rw-r--r--scripts/automation/trex_control_plane/console/trex_tui.py66
2 files changed, 75 insertions, 14 deletions
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 f23e801c..72dc5e1b 100755
--- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
@@ -228,6 +228,13 @@ class Port(object):
def is_active(self):
return(self.state == self.STATE_TX ) or (self.state == self.STATE_PAUSE)
+ def is_transmitting (self):
+ return (self.state == self.STATE_TX)
+
+ def is_paused (self):
+ return (self.state == self.STATE_PAUSE)
+
+
def sync(self, sync_data):
self.handler = sync_data['handler']
port_state = sync_data['state'].upper()
@@ -558,6 +565,12 @@ class CTRexStatelessClient(object):
self.connected = False
+
+
+ # returns the port object
+ def get_port (self, port_id):
+ return self.ports.get(port_id, None)
+
################# events handler ######################
def add_event_log (self, msg, ev_type, show = False):
@@ -826,6 +839,16 @@ class CTRexStatelessClient(object):
for port_id, port_obj in self.ports.iteritems()
if port_obj.is_active()]
+ def get_paused_ports (self):
+ return [port_id
+ for port_id, port_obj in self.ports.iteritems()
+ if port_obj.is_paused()]
+
+ def get_transmitting_ports (self):
+ return [port_id
+ for port_id, port_obj in self.ports.iteritems()
+ if port_obj.is_transmitting()]
+
def set_verbose(self, mode):
self.comm_link.set_verbose(mode)
self.verbose = mode
diff --git a/scripts/automation/trex_control_plane/console/trex_tui.py b/scripts/automation/trex_control_plane/console/trex_tui.py
index 3b64a02f..ea271985 100644
--- a/scripts/automation/trex_control_plane/console/trex_tui.py
+++ b/scripts/automation/trex_control_plane/console/trex_tui.py
@@ -38,17 +38,32 @@ class TrexTUIDashBoard(TrexTUIPanel):
self.key_actions['+'] = {'action': self.action_raise, 'legend': 'up 5%', 'show': True}
self.key_actions['-'] = {'action': self.action_lower, 'legend': 'low 5%', 'show': True}
+ self.ports = self.stateless_client.get_acquired_ports()
+
+
def show (self):
- ports = self.stateless_client.get_acquired_ports()
- stats = self.stateless_client.cmd_stats(ports, trex_stats.ALL_STATS_OPTS)
+ stats = self.stateless_client.cmd_stats(self.ports, trex_stats.ALL_STATS_OPTS)
# print stats to screen
for stat_type, stat_data in stats.iteritems():
text_tables.print_table_with_header(stat_data.text_table, stat_type)
+
def get_key_actions (self):
- return self.key_actions
+ allowed = {}
- # actions
+ if len(self.stateless_client.get_transmitting_ports()) > 0:
+ allowed['p'] = self.key_actions['p']
+ allowed['+'] = self.key_actions['+']
+ allowed['-'] = self.key_actions['-']
+
+
+ if len(self.stateless_client.get_paused_ports()) > 0:
+ allowed['r'] = self.key_actions['r']
+
+ return allowed
+
+
+ ######### actions
def action_pause (self):
rc = self.stateless_client.pause_traffic(self.mng.acquired_ports)
@@ -110,7 +125,9 @@ class TrexTUIDashBoard(TrexTUIPanel):
class TrexTUIPort(TrexTUIPanel):
def __init__ (self, mng, port_id):
super(TrexTUIPort, self).__init__(mng, "port {0}".format(port_id))
+
self.port_id = port_id
+ self.port = self.mng.stateless_client.get_port(port_id)
self.key_actions = OrderedDict()
self.key_actions['p'] = {'action': self.action_pause, 'legend': 'pause', 'show': True}
@@ -118,27 +135,41 @@ class TrexTUIPort(TrexTUIPanel):
self.key_actions['+'] = {'action': self.action_raise, 'legend': 'up 5%', 'show': True}
self.key_actions['-'] = {'action': self.action_lower, 'legend': 'low 5%', 'show': True}
+
def show (self):
+
stats = self.stateless_client.cmd_stats([self.port_id], trex_stats.ALL_STATS_OPTS)
# print stats to screen
for stat_type, stat_data in stats.iteritems():
text_tables.print_table_with_header(stat_data.text_table, stat_type)
def get_key_actions (self):
- return self.key_actions
+
+ allowed = {}
+
+ if self.port.state == self.port.STATE_TX:
+ allowed['p'] = self.key_actions['p']
+ allowed['+'] = self.key_actions['+']
+ allowed['-'] = self.key_actions['-']
+
+ elif self.port.state == self.port.STATE_PAUSE:
+ allowed['r'] = self.key_actions['r']
+
+
+ return allowed
# actions
def action_pause (self):
rc = self.stateless_client.pause_traffic([self.port_id])
if rc.good():
- return "paused traffic on port {0}".format(self.port_id)
+ return "port {0}: paused traffic".format(self.port_id)
else:
return ""
def action_resume (self):
rc = self.stateless_client.resume_traffic([self.port_id])
if rc.good():
- return "resumed traffic on port {0}".format(self.port_id)
+ return "port {0}: resumed traffic".format(self.port_id)
else:
return ""
@@ -147,7 +178,7 @@ class TrexTUIPort(TrexTUIPanel):
rc = self.stateless_client.update_traffic(mul, [self.port_id])
if rc.good():
- return "raised B/W by 5% on port {0}".format(self.port_id)
+ return "port {0}: raised B/W by 5%".format(self.port_id)
else:
return ""
@@ -156,7 +187,7 @@ class TrexTUIPort(TrexTUIPanel):
rc = self.stateless_client.update_traffic(mul, [self.port_id])
if rc.good():
- return "lowered B/W by 5% on port {0}".format(self.port_id)
+ return "port {0}: lowered B/W by 5%".format(self.port_id)
else:
return ""
@@ -185,6 +216,7 @@ class TrexTUIPanelManager():
self.tui = tui
self.stateless_client = tui.stateless_client
self.acquired_ports = self.stateless_client.get_acquired_ports()
+
self.panels = {}
self.panels['dashboard'] = TrexTUIDashBoard(self)
@@ -200,10 +232,11 @@ class TrexTUIPanelManager():
# start with dashboard
self.main_panel = self.panels['dashboard']
- self.generate_legend()
-
+ # log object
self.log = TrexTUILog()
+ self.generate_legend()
+
def generate_legend (self):
self.legend = "{:<12}".format("browse:")
@@ -215,9 +248,6 @@ class TrexTUIPanelManager():
self.legend += "'0-{0}' - port display".format(len(self.acquired_ports) - 1)
- panel_actions = self.main_panel.get_key_actions()
- if not panel_actions:
- return
self.legend += "\n{:<12}".format(self.main_panel.get_name() + ":")
for k, v in self.main_panel.get_key_actions().iteritems():
@@ -230,6 +260,10 @@ class TrexTUIPanelManager():
print format_text(self.legend, 'bold')
+ # on window switch or turn on / off of the TUI we call this
+ def init (self):
+ self.generate_legend()
+
def show (self):
self.main_panel.show()
self.print_legend()
@@ -265,11 +299,13 @@ class TrexTUIPanelManager():
def action_show_dash (self):
self.main_panel = self.panels['dashboard']
+ self.init()
return ""
def action_show_port (self, port_id):
def action_show_port_x ():
self.main_panel = self.panels['port {0}'.format(port_id)]
+ self.init()
return ""
return action_show_port_x
@@ -309,6 +345,8 @@ class TrexTUI():
new_settings[6][termios.VTIME] = 0 # cc
termios.tcsetattr(sys.stdin, termios.TCSADRAIN, new_settings)
+ self.pm.init()
+
try:
while True:
self.clear_screen()