From 6f4a51c126b7a78ee8e37d396ed2b61b05fa506c Mon Sep 17 00:00:00 2001 From: imarom Date: Sun, 24 Jan 2016 04:01:30 -0500 Subject: added example --- .../trex_control_plane/client/trex_hltapi.py | 4 ++-- .../client/trex_stateless_client.py | 11 ++++++---- .../trex_control_plane/common/trex_stats.py | 5 ++++- .../trex_control_plane/common/trex_streams.py | 1 - .../trex_control_plane/console/trex_console.py | 25 ++++++++++------------ .../examples/interactive_stateless.py | 2 +- 6 files changed, 25 insertions(+), 23 deletions(-) (limited to 'scripts/automation/trex_control_plane') diff --git a/scripts/automation/trex_control_plane/client/trex_hltapi.py b/scripts/automation/trex_control_plane/client/trex_hltapi.py index 848d5a9e..c25c73cb 100755 --- a/scripts/automation/trex_control_plane/client/trex_hltapi.py +++ b/scripts/automation/trex_control_plane/client/trex_hltapi.py @@ -2,7 +2,7 @@ import trex_root_path from client_utils.packet_builder import CTRexPktBuilder -from trex_stateless_client import CTRexStatelessClient +from trex_stateless_client import STLClient from common.trex_streams import * from client_utils.general_utils import id_count_gen import dpkt @@ -20,7 +20,7 @@ class CTRexHltApi(object): # sync = RPC, async = ZMQ def connect(self, device, port_list, username, sync_port = 4501, async_port = 4500, reset=False, break_locks=False): ret_dict = {"status": 0} - self.trex_client = CTRexStatelessClient(username, device, sync_port, async_port) + self.trex_client = STLClient(username, device, sync_port, async_port) rc = self.trex_client.connect() if rc.bad(): 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 c5d7e053..c1a4d1d1 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -419,8 +419,8 @@ class CCommLink(object): ############################ ############################# ############################ ############################# -class CTRexStatelessClient(object): - """docstring for CTRexStatelessClient""" +class STLClient(object): + """docstring for STLClient""" def __init__(self, username = general_utils.get_current_user(), @@ -968,6 +968,7 @@ class CTRexStatelessClient(object): stats_obj = {} for stats_type in stats_opts: stats_obj.update(self.stats_generator.generate_single_statistic(port_id_list, stats_type)) + return stats_obj def _get_streams(self, port_id_list, streams_mask=set()): @@ -1244,9 +1245,11 @@ class CTRexStatelessClient(object): # pings the server on the RPC channel @__api_check(True) def ping(self): - rc = self.__ping() self.logger.pre_cmd( "Pinging the server on '{0}' port '{1}': ".format(self.connection_info['server'], - self.connection_info['sync_port'])) + self.connection_info['sync_port'])) + rc = self.__ping() + + self.logger.post_cmd(rc) if not rc: raise STLError(rc) diff --git a/scripts/automation/trex_control_plane/common/trex_stats.py b/scripts/automation/trex_control_plane/common/trex_stats.py index 9c2cd7f1..3f64310f 100755 --- a/scripts/automation/trex_control_plane/common/trex_stats.py +++ b/scripts/automation/trex_control_plane/common/trex_stats.py @@ -59,7 +59,7 @@ def calculate_diff_raw (samples): class CTRexInfoGenerator(object): """ This object is responsible of generating stats and information from objects maintained at - CTRexStatelessClient and the ports. + STLClient and the ports. """ def __init__(self, global_stats_ref, ports_dict_ref): @@ -477,6 +477,9 @@ class CPortStats(CTRexStats): raise TypeError("cannot add non stats object to stats") # main stats + if not self.latest_stats: + self.latest_stats = {} + self.__merge_dicts(self.latest_stats, x.latest_stats) # reference stats diff --git a/scripts/automation/trex_control_plane/common/trex_streams.py b/scripts/automation/trex_control_plane/common/trex_streams.py index 800b6d49..ea3d71d1 100755 --- a/scripts/automation/trex_control_plane/common/trex_streams.py +++ b/scripts/automation/trex_control_plane/common/trex_streams.py @@ -210,7 +210,6 @@ class CStream(object): setattr(self, k, kwargs[k]) # TODO: load to _pkt_bld_obj also when passed as byte array! elif isinstance(binary, str) and binary.endswith(".pcap"): - # self.load_packet_from_pcap(binary, kwargs[k]["meta"]) self._pkt_bld_obj.load_packet_from_pcap(binary) self._pkt_bld_obj.metadata = kwargs[k]["meta"] self.packet = self._pkt_bld_obj.dump_pkt() diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index 34494561..88ff45dc 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -29,7 +29,7 @@ import sys import tty, termios import trex_root_path from common.trex_streams import * -from client.trex_stateless_client import CTRexStatelessClient, LoggerApi, STLError +from client.trex_stateless_client import STLClient, LoggerApi, STLError from common.text_opts import * from client_utils.general_utils import user_input, get_current_user from client_utils import parsing_opts @@ -175,6 +175,7 @@ class TRexConsole(TRexGeneralCmd): ################### internal section ######################## def prompt_redraw (self): + self.postcmd(False, "") sys.stdout.write("\n" + self.prompt + readline.get_line_buffer()) sys.stdout.flush() @@ -293,9 +294,7 @@ class TRexConsole(TRexGeneralCmd): @verify_connected def do_ping (self, line): '''Ping the server\n''' - rc = self.stateless_client.ping() - if rc.bad(): - return + self.stateless_client.ping() # set verbose on / off @@ -632,9 +631,7 @@ def run_script_file (self, filename, stateless_client): stateless_client.logger.log(format_text("unknown command '{0}'\n".format(cmd), 'bold')) return False - rc = cmd_table[cmd](args) - if rc.bad(): - return False + cmd_table[cmd](args) stateless_client.logger.log(format_text("\n[Done]", 'bold')) @@ -670,7 +667,7 @@ def setParserOptions(): default = get_current_user(), type = str) - parser.add_argument("--verbose", dest="verbose", + parser.add_argument("-v", "--verbose", dest="verbose", action="store_true", help="Switch ON verbose option. Default is: OFF.", default = False) @@ -711,12 +708,12 @@ def main(): # Stateless client connection logger = ConsoleLogger() - stateless_client = CTRexStatelessClient(username = options.user, - server = options.server, - sync_port = options.port, - async_port = options.pub, - verbose_level = verbose_level, - logger = logger) + stateless_client = STLClient(username = options.user, + server = options.server, + sync_port = options.port, + async_port = options.pub, + verbose_level = verbose_level, + logger = logger) # TUI or no acquire will give us READ ONLY mode try: diff --git a/scripts/automation/trex_control_plane/examples/interactive_stateless.py b/scripts/automation/trex_control_plane/examples/interactive_stateless.py index e64b4755..f6ada17d 100644 --- a/scripts/automation/trex_control_plane/examples/interactive_stateless.py +++ b/scripts/automation/trex_control_plane/examples/interactive_stateless.py @@ -25,7 +25,7 @@ class InteractiveStatelessTRex(cmd.Cmd): self.verbose = verbose self.virtual = virtual - self.trex = CTRexStatelessClient(trex_host, trex_port, self.virtual) + self.trex = STLClient(trex_host, trex_port, self.virtual) self.DEFAULT_RUN_PARAMS = dict(m=1.5, nc=True, p=True, -- cgit 1.2.3-korg