Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make amount of shown ports configurable #1113

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"

Expand All @@ -99,6 +103,7 @@ def __init__(self,
server,
sync_port,
async_port,
max_ports,
verbose_level,
logger,
sync_timeout,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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, "")
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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')

Expand All @@ -912,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
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"

Expand All @@ -172,6 +176,7 @@ def __init__(self,
server,
sync_port,
async_port,
max_ports,
verbose_level,
logger,
sync_timeout,
Expand Down