From de90762476583bed8c3a2c1e15158b85e4231ad0 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Mon, 26 Oct 2015 01:19:06 +0200 Subject: fixed streamlist loading --- scripts/automation/trex_control_plane/common/trex_streams.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'scripts/automation/trex_control_plane/common') diff --git a/scripts/automation/trex_control_plane/common/trex_streams.py b/scripts/automation/trex_control_plane/common/trex_streams.py index 783f2769..efa8e5cc 100755 --- a/scripts/automation/trex_control_plane/common/trex_streams.py +++ b/scripts/automation/trex_control_plane/common/trex_streams.py @@ -48,6 +48,7 @@ class CStreamList(object): self.streams_list.clear() streams_data = load_yaml_to_obj(file_path) assert isinstance(streams_data, list) + new_streams_data = [] for stream in streams_data: stream_name = stream.get("name") raw_stream = stream.get("stream") @@ -58,10 +59,11 @@ class CStreamList(object): new_stream_data = self.yaml_loader.validate_yaml(raw_stream, "stream", multiplier= multiplier) + new_streams_data.append(new_stream_data) new_stream_obj = CStream() new_stream_obj.load_data(**new_stream_data) self.append_stream(stream_name, new_stream_obj) - return new_stream_data + return new_streams_data def compile_streams(self): # first, assign an id to each stream @@ -156,7 +158,6 @@ class CStream(object): """docstring for CStream""" FIELDS = ["enabled", "self_start", "next_stream_id", "isg", "mode", "rx_stats", "packet", "vm"] - # COMPILE_FIELDS = ["enabled", "self_start", "next_stream_id", "isg", "mode", "rx_stats", "packet", "vm"] def __init__(self): self.is_loaded = False -- cgit From b44239e4c6019f10fa7cf4fe0fef8c3726435033 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Mon, 26 Oct 2015 09:41:51 +0200 Subject: add disconnect functionality --- scripts/automation/trex_control_plane/common/trex_streams.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'scripts/automation/trex_control_plane/common') diff --git a/scripts/automation/trex_control_plane/common/trex_streams.py b/scripts/automation/trex_control_plane/common/trex_streams.py index efa8e5cc..750da198 100755 --- a/scripts/automation/trex_control_plane/common/trex_streams.py +++ b/scripts/automation/trex_control_plane/common/trex_streams.py @@ -227,8 +227,7 @@ class CStream(object): return - def dump(self, compilation=False): - # fields = CStream.COMPILE_FIELDS if compilation else CStream.FIELDS + def dump(self): if self.is_loaded: dump = {} for key in CStream.FIELDS: @@ -240,10 +239,6 @@ class CStream(object): else: raise RuntimeError("CStream object isn't loaded with data. Use 'load_data' method.") - def dump_compiled(self): - return self.dump(compilation=True) - - if __name__ == "__main__": pass -- cgit From 0c2b3c83f9cc0c25277c39660dce132aad55c3d7 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Wed, 28 Oct 2015 07:28:37 +0200 Subject: updated more HLTAPI functionality and fixed found bugs. Working: Start/stop traffic, traffic config (semi), connect, clean Missing: stats Next: boost console --- scripts/automation/trex_control_plane/common/trex_streams.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'scripts/automation/trex_control_plane/common') diff --git a/scripts/automation/trex_control_plane/common/trex_streams.py b/scripts/automation/trex_control_plane/common/trex_streams.py index 750da198..bb4c72ca 100755 --- a/scripts/automation/trex_control_plane/common/trex_streams.py +++ b/scripts/automation/trex_control_plane/common/trex_streams.py @@ -23,7 +23,7 @@ class CStreamList(object): if name in self.streams_list: raise NameError("A stream with this name already exists on this list.") self.streams_list[name]=stream_obj - return + return name def remove_stream(self, name): popped = self.streams_list.pop(name) @@ -184,6 +184,7 @@ class CStream(object): if isinstance(kwargs[k], CTRexPktBuilder): if "vm" not in kwargs: self.load_packet_obj(kwargs[k]) + break # vm field check is skipped else: raise ValueError("When providing packet object with a CTRexPktBuilder, vm parameter " "should not be supplied") -- cgit From 5377774afbf00b0da0ad0b74d3be207f6eb9124e Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Thu, 29 Oct 2015 07:54:21 +0200 Subject: Added module for text formatting, such that coloring, bold, underline. --- .../trex_control_plane/common/text_opts.py | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 scripts/automation/trex_control_plane/common/text_opts.py (limited to 'scripts/automation/trex_control_plane/common') diff --git a/scripts/automation/trex_control_plane/common/text_opts.py b/scripts/automation/trex_control_plane/common/text_opts.py new file mode 100644 index 00000000..8ab03eeb --- /dev/null +++ b/scripts/automation/trex_control_plane/common/text_opts.py @@ -0,0 +1,72 @@ + + +TEXT_CODES = {'bold': {'start': '\x1b[1m', + 'end': '\x1b[22m'}, + 'cyan': {'start': '\x1b[36m', + 'end': '\x1b[39m'}, + 'blue': {'start': '\x1b[34m', + 'end': '\x1b[39m'}, + 'red': {'start': '\x1b[31m', + 'end': '\x1b[39m'}, + 'magenta': {'start': '\x1b[35m', + 'end': '\x1b[39m'}, + 'green': {'start': '\x1b[32m', + 'end': '\x1b[39m'}, + 'underline': {'start': '\x1b[4m', + 'end': '\x1b[24m'}} + + +def bold(text): + return text_attribute(text, 'bold') + + +def cyan(text): + return text_attribute(text, 'cyan') + + +def blue(text): + return text_attribute(text, 'blue') + + +def red(text): + return text_attribute(text, 'red') + + +def magenta(text): + return text_attribute(text, 'magenta') + + +def green(text): + return text_attribute(text, 'green') + + +def underline(text): + return text_attribute(text, 'underline') + + +def text_attribute(text, attribute): + return "{start}{txt}{stop}".format(start=TEXT_CODES[attribute]['start'], + txt=text, + stop=TEXT_CODES[attribute]['end']) + + +FUNC_DICT = {'blue': blue, + 'bold': bold, + 'green': green, + 'cyan': cyan, + 'magenta': magenta, + 'underline': underline, + 'red': red} + + +def format_text(text, *args): + return_string = text + for i in args: + func = FUNC_DICT.get(i) + if func: + return_string = func(return_string) + return return_string + + +if __name__ == "__main__": + pass -- cgit From aa37a0abb00cbf4cb1611f9c0eefcb1ab850bc45 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Thu, 29 Oct 2015 11:34:03 +0200 Subject: Console redesign using trex_stateless_client module --- .../trex_control_plane/common/text_opts.py | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'scripts/automation/trex_control_plane/common') diff --git a/scripts/automation/trex_control_plane/common/text_opts.py b/scripts/automation/trex_control_plane/common/text_opts.py index 8ab03eeb..0d8323db 100644 --- a/scripts/automation/trex_control_plane/common/text_opts.py +++ b/scripts/automation/trex_control_plane/common/text_opts.py @@ -1,4 +1,5 @@ - +import json +import re TEXT_CODES = {'bold': {'start': '\x1b[1m', 'end': '\x1b[22m'}, @@ -65,7 +66,29 @@ def format_text(text, *args): func = FUNC_DICT.get(i) if func: return_string = func(return_string) - return return_string + return + +# pretty print for JSON +def pretty_json (json_str, use_colors = True): + pretty_str = json.dumps(json.loads(json_str), indent = 4, separators=(',', ': '), sort_keys = True) + + if not use_colors: + return pretty_str + + try: + # int numbers + pretty_str = re.sub(r'([ ]*:[ ]+)(\-?[1-9][0-9]*[^.])',r'\1{0}'.format(blue(r'\2')), pretty_str) + # float + pretty_str = re.sub(r'([ ]*:[ ]+)(\-?[1-9][0-9]*\.[0-9]+)',r'\1{0}'.format(magenta(r'\2')), pretty_str) + # # strings + # + pretty_str = re.sub(r'([ ]*:[ ]+)("[^"]*")',r'\1{0}'.format(red(r'\2')), pretty_str) + pretty_str = re.sub(r"('[^']*')", r'{0}\1{1}'.format(TEXT_CODES['magenta']['start'], + TEXT_CODES['red']['start']), pretty_str) + except : + pass + + return pretty_str if __name__ == "__main__": -- cgit From 13c353b9e4f3f0177458c5bef729de31ec03135d Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Thu, 29 Oct 2015 03:59:43 +0200 Subject: fixed console issues after testsing them --- scripts/automation/trex_control_plane/common/text_opts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) mode change 100644 => 100755 scripts/automation/trex_control_plane/common/text_opts.py (limited to 'scripts/automation/trex_control_plane/common') diff --git a/scripts/automation/trex_control_plane/common/text_opts.py b/scripts/automation/trex_control_plane/common/text_opts.py old mode 100644 new mode 100755 index 0d8323db..4d1cb0fd --- a/scripts/automation/trex_control_plane/common/text_opts.py +++ b/scripts/automation/trex_control_plane/common/text_opts.py @@ -66,7 +66,7 @@ def format_text(text, *args): func = FUNC_DICT.get(i) if func: return_string = func(return_string) - return + return return_string # pretty print for JSON def pretty_json (json_str, use_colors = True): -- cgit From d78150a66de591a77df2496e5de828d3232a931a Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Thu, 29 Oct 2015 06:18:54 +0200 Subject: Awesome working start/stop traffic console Fixed more stability issues :) Ready for merging. --- scripts/automation/trex_control_plane/common/text_opts.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'scripts/automation/trex_control_plane/common') diff --git a/scripts/automation/trex_control_plane/common/text_opts.py b/scripts/automation/trex_control_plane/common/text_opts.py index 4d1cb0fd..06c2c056 100755 --- a/scripts/automation/trex_control_plane/common/text_opts.py +++ b/scripts/automation/trex_control_plane/common/text_opts.py @@ -13,6 +13,8 @@ TEXT_CODES = {'bold': {'start': '\x1b[1m', 'end': '\x1b[39m'}, 'green': {'start': '\x1b[32m', 'end': '\x1b[39m'}, + 'yellow': {'start': '\x1b[33m', + 'end': '\x1b[39m'}, 'underline': {'start': '\x1b[4m', 'end': '\x1b[24m'}} @@ -40,6 +42,8 @@ def magenta(text): def green(text): return text_attribute(text, 'green') +def yellow(text): + return text_attribute(text, 'yellow') def underline(text): return text_attribute(text, 'underline') @@ -54,6 +58,7 @@ def text_attribute(text, attribute): FUNC_DICT = {'blue': blue, 'bold': bold, 'green': green, + 'yellow': yellow, 'cyan': cyan, 'magenta': magenta, 'underline': underline, -- cgit