diff options
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/console')
-rwxr-xr-x | scripts/automation/trex_control_plane/stl/console/trex_console.py | 47 | ||||
-rw-r--r-- | scripts/automation/trex_control_plane/stl/console/trex_tui.py | 33 |
2 files changed, 44 insertions, 36 deletions
diff --git a/scripts/automation/trex_control_plane/stl/console/trex_console.py b/scripts/automation/trex_control_plane/stl/console/trex_console.py index e5539b2b..2b53b7ec 100755 --- a/scripts/automation/trex_control_plane/stl/console/trex_console.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py @@ -212,29 +212,7 @@ class TRexConsole(TRexGeneralCmd): return wrap - # TODO: remove this ugly duplication - def verify_connected_and_rw (f): - @wraps(f) - def wrap(*args): - inst = args[0] - func_name = f.__name__ - if func_name.startswith("do_"): - func_name = func_name[3:] - - if not inst.stateless_client.is_connected(): - print(format_text("\n'{0}' cannot be executed on offline mode\n".format(func_name), 'bold')) - return - - if not inst.stateless_client.get_acquired_ports(): - print(format_text("\n'{0}' cannot be executed on read only mode\n".format(func_name), 'bold')) - return - - rc = f(*args) - return rc - - return wrap - - + def get_console_identifier(self): return "{context}_{server}".format(context=get_current_user(), server=self.stateless_client.get_connection_info()['server']) @@ -431,19 +409,22 @@ class TRexConsole(TRexGeneralCmd): self.stateless_client.disconnect_line(line) + @verify_connected def do_acquire (self, line): '''Acquire ports\n''' self.stateless_client.acquire_line(line) - - def help_acquire (self): - self.do_acquire("-h") + + @verify_connected def do_release (self, line): '''Release ports\n''' - self.stateless_client.release_line(line) + + def help_acquire (self): + self.do_acquire("-h") + def help_release (self): self.do_release("-h") @@ -462,7 +443,7 @@ class TRexConsole(TRexGeneralCmd): return TRexConsole.tree_autocomplete(s[l - 1]) - @verify_connected_and_rw + @verify_connected def do_start(self, line): '''Start selected traffic in specified port(s) on TRex\n''' @@ -475,7 +456,7 @@ class TRexConsole(TRexGeneralCmd): self.do_start("-h") ############# stop - @verify_connected_and_rw + @verify_connected def do_stop(self, line): '''stops port(s) transmitting traffic\n''' @@ -485,7 +466,7 @@ class TRexConsole(TRexGeneralCmd): self.do_stop("-h") ############# update - @verify_connected_and_rw + @verify_connected def do_update(self, line): '''update speed of port(s)currently transmitting traffic\n''' @@ -495,14 +476,14 @@ class TRexConsole(TRexGeneralCmd): self.do_update("-h") ############# pause - @verify_connected_and_rw + @verify_connected def do_pause(self, line): '''pause port(s) transmitting traffic\n''' self.stateless_client.pause_line(line) ############# resume - @verify_connected_and_rw + @verify_connected def do_resume(self, line): '''resume port(s) transmitting traffic\n''' @@ -511,7 +492,7 @@ class TRexConsole(TRexGeneralCmd): ########## reset - @verify_connected_and_rw + @verify_connected def do_reset (self, line): '''force stop all ports\n''' self.stateless_client.reset_line(line) diff --git a/scripts/automation/trex_control_plane/stl/console/trex_tui.py b/scripts/automation/trex_control_plane/stl/console/trex_tui.py index a842e172..331baec9 100644 --- a/scripts/automation/trex_control_plane/stl/console/trex_tui.py +++ b/scripts/automation/trex_control_plane/stl/console/trex_tui.py @@ -48,12 +48,17 @@ class TrexTUIPanel(object): def get_key_actions (self): raise NotImplementedError("must implement this") + def get_name (self): return self.name # dashboard panel class TrexTUIDashBoard(TrexTUIPanel): + + FILTER_ACQUIRED = 1 + FILTER_ALL = 2 + def __init__ (self, mng): super(TrexTUIDashBoard, self).__init__(mng, "dashboard") @@ -65,11 +70,23 @@ 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_all_ports() + self.key_actions['o'] = {'action': self.action_show_owned, 'legend': 'owned ports', 'show': True} + self.key_actions['a'] = {'action': self.action_show_all, 'legend': 'all ports', 'show': True} + + self.ports_filter = self.FILTER_ACQUIRED + + + def get_ports (self): + if self.ports_filter == self.FILTER_ACQUIRED: + return self.stateless_client.get_acquired_ports() + elif self.ports_filter == self.FILTER_ALL: + return self.stateless_client.get_all_ports() + + assert(0) def show (self): - stats = self.stateless_client._get_formatted_stats(self.ports) + stats = self.stateless_client._get_formatted_stats(self.get_ports()) # print stats to screen for stat_type, stat_data in stats.items(): text_tables.print_table_with_header(stat_data.text_table, stat_type) @@ -79,8 +96,10 @@ class TrexTUIDashBoard(TrexTUIPanel): allowed = OrderedDict() allowed['c'] = self.key_actions['c'] + allowed['o'] = self.key_actions['o'] + allowed['a'] = self.key_actions['a'] - if self.stateless_client.is_all_ports_acquired(): + if self.ports_filter == self.FILTER_ALL: return allowed if len(self.stateless_client.get_transmitting_ports()) > 0: @@ -133,6 +152,14 @@ class TrexTUIDashBoard(TrexTUIPanel): return "" + def action_show_owned (self): + self.ports_filter = self.FILTER_ACQUIRED + return "" + + def action_show_all (self): + self.ports_filter = self.FILTER_ALL + return "" + def action_clear (self): self.stateless_client.clear_stats(self.mng.ports) return "cleared all stats" |