From 597e8221453dfe3d093f9e10878dec8b48f6fb23 Mon Sep 17 00:00:00 2001 From: Vladimir Smirnov Date: Tue, 27 Feb 2024 22:02:10 +0100 Subject: [PATCH 1/2] Make amount of shown ports configurable Currently it is hardcoded to '4' which is suboptimal for bigger screens. Add a new flag to trex-console, `-m` that allows to specify amount of ports user want to see. Keep default value as 4 for compatibility reasons. Related to #1109 --- .../interactive/trex/astf/trex_astf_client.py | 5 +++++ .../interactive/trex/common/trex_client.py | 14 ++++++++++++-- .../interactive/trex/console/trex_console.py | 5 +++++ .../interactive/trex/stl/trex_stl_client.py | 5 +++++ 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_client.py b/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_client.py index 99435823f4..2a6f63ea38 100644 --- a/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_client.py +++ b/scripts/automation/trex_control_plane/interactive/trex/astf/trex_astf_client.py @@ -54,6 +54,7 @@ def __init__(self, server = "localhost", sync_port = 4501, async_port = 4500, + max_ports = 4, verbose_level = "error", logger = None, sync_timeout = None, @@ -75,6 +76,9 @@ def __init__(self, async_port : int the ASYNC port (subscriber port) + max_ports : int + maximum amount of ports to show + verbose_level: str one of "none", "critical", "error", "info", "debug" @@ -99,6 +103,7 @@ def __init__(self, server, sync_port, async_port, + max_ports, verbose_level, logger, sync_timeout, diff --git a/scripts/automation/trex_control_plane/interactive/trex/common/trex_client.py b/scripts/automation/trex_control_plane/interactive/trex/common/trex_client.py index 6b2aeb786f..522290b3fc 100644 --- a/scripts/automation/trex_control_plane/interactive/trex/common/trex_client.py +++ b/scripts/automation/trex_control_plane/interactive/trex/common/trex_client.py @@ -94,6 +94,7 @@ def __init__(self, server = "localhost", sync_port = 4501, async_port = 4500, + max_ports = 4, verbose_level = "error", logger = None, sync_timeout = None, @@ -133,6 +134,8 @@ def __init__(self, # server version check for dynamic port addition self.is_dynamic = False + self.max_ports = max_ports + def get_mode (self): """ @@ -3622,7 +3625,10 @@ def _show_port_stats (self, ports, buffer = sys.stdout): self.logger.warning(format_text('Empty set of ports\n', 'bold')) return - port_stats = [self.ports[port_id].get_port_stats() for port_id in ports[:4]] + if self.max_ports < 1: + port_stats = [self.ports[port_id].get_port_stats() for port_id in ports] + else: + port_stats = [self.ports[port_id].get_port_stats() for port_id in ports[:self.max_ports]] # update in a batch StatsBatch.update(port_stats, self.conn.rpc) @@ -3649,7 +3655,11 @@ def _show_port_xstats (self, ports, include_zero_lines): self.logger.warning(format_text('Empty set of ports\n', 'bold')) return - port_xstats = [self.ports[port_id].get_port_xstats() for port_id in ports[:4]] + if self.max_ports < 1: + port_xstats = [self.ports[port_id].get_port_xstats() for port_id in ports] + else: + port_xstats = [self.ports[port_id].get_port_xstats() for port_id in ports[:self.max_ports]] + # update in a batch StatsBatch.update(port_xstats, self.conn.rpc) diff --git a/scripts/automation/trex_control_plane/interactive/trex/console/trex_console.py b/scripts/automation/trex_control_plane/interactive/trex/console/trex_console.py index 6fe9c4d5fb..56ef9143f4 100644 --- a/scripts/automation/trex_control_plane/interactive/trex/console/trex_console.py +++ b/scripts/automation/trex_control_plane/interactive/trex/console/trex_console.py @@ -852,6 +852,8 @@ def setParserOptions(): action="store_true", help="Starts with all outputs suppressed", default = False) + parser.add_argument("-m", "--max-ports", default=4, help="Set maximum amount of ports to show, any value below 1 is unlimited", type=int) + return parser # a simple info printed on log on @@ -896,6 +898,7 @@ def probe_server_mode (options): server = options.server, sync_port = options.port, async_port = options.pub, + max_ports = options.max_ports, logger = ConsoleLogger(), verbose_level = 'error') @@ -992,6 +995,7 @@ def main(): server = options.server, sync_port = options.port, async_port = options.pub, + max_ports = options.max_ports, logger = logger, verbose_level = verbose_level, sync_timeout = sync_timeout, @@ -1005,6 +1009,7 @@ def main(): server = options.server, sync_port = options.port, async_port = options.pub, + max_ports = options.max_ports, logger = logger, verbose_level = verbose_level, sync_timeout = sync_timeout, diff --git a/scripts/automation/trex_control_plane/interactive/trex/stl/trex_stl_client.py b/scripts/automation/trex_control_plane/interactive/trex/stl/trex_stl_client.py index 60a351a652..5c841cf71a 100644 --- a/scripts/automation/trex_control_plane/interactive/trex/stl/trex_stl_client.py +++ b/scripts/automation/trex_control_plane/interactive/trex/stl/trex_stl_client.py @@ -126,6 +126,7 @@ def __init__(self, server = "localhost", sync_port = 4501, async_port = 4500, + max_ports = 4, verbose_level = "error", logger = None, sync_timeout = None, @@ -147,6 +148,9 @@ def __init__(self, async_port : int the ASYNC port (subscriber port) + max_ports : int + maximum number of ports to show + verbose_level: str one of "none", "critical", "error", "info", "debug" @@ -172,6 +176,7 @@ def __init__(self, server, sync_port, async_port, + max_ports, verbose_level, logger, sync_timeout, From 411efc8a7f40da26db862a059d21f642a20c412d Mon Sep 17 00:00:00 2001 From: Vladimir Smirnov Date: Tue, 27 Feb 2024 22:25:25 +0100 Subject: [PATCH 2/2] Modify MIN_COLS based on amount of ports user want to show That is a quick way to get MIN_COLS check to work again However in case `-m 0` or `-m -1` specified (all ports), check won't be adjusted to actual number of ports available on a system --- .../interactive/trex/console/trex_console.py | 6 +++--- .../trex_control_plane/interactive/trex/console/trex_tui.py | 5 ++++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/scripts/automation/trex_control_plane/interactive/trex/console/trex_console.py b/scripts/automation/trex_control_plane/interactive/trex/console/trex_console.py index 56ef9143f4..f4a8b3a50f 100644 --- a/scripts/automation/trex_control_plane/interactive/trex/console/trex_console.py +++ b/scripts/automation/trex_control_plane/interactive/trex/console/trex_console.py @@ -183,7 +183,7 @@ def completenames(self, text, *ignored): class TRexConsole(TRexGeneralCmd): """Trex Console""" - def __init__(self, client, verbose = False, dummy_client = False): + def __init__(self, client, verbose = False, dummy_client = False, max_ports = 4): # cmd lock is used to make sure background job # of the console is not done while the user excutes commands @@ -202,7 +202,7 @@ def __init__(self, client, verbose = False, dummy_client = False): self.terminal = None - self.tui = trex_tui.TrexTUI(self) + self.tui = trex_tui.TrexTUI(self, max_ports) self.cap_mngr = CaptureManager(client, self.cmd_lock) self.load_client_console_functions() self.postcmd(False, "") @@ -915,7 +915,7 @@ def run_console(client, logger, options): if not cont: return - console = TRexConsole(client = client, verbose = options.verbose, dummy_client = options.emu_only_server is not None) + console = TRexConsole(client = client, verbose = options.verbose, dummy_client = options.emu_only_server is not None, max_ports = options.max_ports) console.server = options.server # set server in console so plugins can use it # run emu if needed diff --git a/scripts/automation/trex_control_plane/interactive/trex/console/trex_tui.py b/scripts/automation/trex_control_plane/interactive/trex/console/trex_tui.py index 90901bffdb..ccbc7bf159 100644 --- a/scripts/automation/trex_control_plane/interactive/trex/console/trex_tui.py +++ b/scripts/automation/trex_control_plane/interactive/trex/console/trex_tui.py @@ -707,7 +707,10 @@ def __init__ (self, cols, rows): super(TrexTUI.ScreenSizeException, self).__init__(msg) - def __init__ (self, console): + def __init__ (self, console, max_ports = 4): + if max_ports > 2: + # Showing one port takes about 20 columns + TrexTUI.MIN_COLS += 20 * (max_ports - 4) self.console = console self.client = console.client