summaryrefslogtreecommitdiffstats
path: root/scripts/automation
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-03-16 18:32:45 +0200
committerimarom <imarom@cisco.com>2016-03-16 19:17:55 +0200
commitaa334e0ef9258ffc70f0741627861b832d79a69b (patch)
tree2ea277e05acd3c45fafa308fcdfe695bdcfc32e5 /scripts/automation
parent9518c16c5f10bef7a87b2237b635ea47ef5c183a (diff)
tunables show on the console
Diffstat (limited to 'scripts/automation')
-rwxr-xr-xscripts/automation/trex_control_plane/stl/console/trex_console.py7
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py47
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py24
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py47
4 files changed, 117 insertions, 8 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 4b5e5f54..9dbe82c8 100755
--- a/scripts/automation/trex_control_plane/stl/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/stl/console/trex_console.py
@@ -548,6 +548,13 @@ class TRexConsole(TRexGeneralCmd):
print format_text("\n\nEvent log was cleared\n\n")
+ def complete_profile(self, text, line, begidx, endidx):
+ return self.complete_start(text,line, begidx, endidx)
+
+ def do_profile (self, line):
+ '''shows information about a profile'''
+ self.stateless_client.show_profile_line(line)
+
# tui
@verify_connected
def do_tui (self, line):
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
index 3d12f32c..de07e9e4 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
@@ -1977,7 +1977,13 @@ class STLClient(object):
# pack the profile
try:
for port, t in zip(opts.ports, tunables):
- profile = STLProfile.load(opts.file[0], direction = (port % 2), port = port, **t)
+
+ # give priority to the user configuration over default direction
+ if not 'direction' in t:
+ t['direction'] = (port % 2)
+
+ profile = STLProfile.load(opts.file[0], **t)
+
self.add_streams(profile.get_streams(), ports = port)
except STLError as e:
@@ -2270,3 +2276,42 @@ class STLClient(object):
return
+
+ @__console
+ def show_profile_line (self, line):
+ '''Shows profile information'''
+
+ parser = parsing_opts.gen_parser(self,
+ "port",
+ self.show_profile_line.__doc__,
+ parsing_opts.FILE_PATH)
+
+ opts = parser.parse_args(line.split())
+ if opts is None:
+ return
+
+ info = STLProfile.get_info(opts.file[0])
+
+ self.logger.log(format_text('\nProfile Information:\n', 'bold'))
+
+ # general info
+ self.logger.log(format_text('\nGeneral Information:', 'underline'))
+ self.logger.log('Filename: {:^12}'.format(opts.file[0]))
+ self.logger.log('Stream count: {:^12}'.format(info['stream_count']))
+
+ # specific info
+ profile_type = info['type']
+ self.logger.log(format_text('\nSpecific Information:', 'underline'))
+
+ if profile_type == 'python':
+ self.logger.log('Type: {:^12}'.format('Python Module'))
+ self.logger.log('Tunables: {:^12}'.format(['{0} = {1}'.format(k ,v) for k, v in info['tunables'].iteritems()]))
+
+ elif profile_type == 'yaml':
+ self.logger.log('Type: {:^12}'.format('YAML'))
+
+ elif profile_type == 'pcap':
+ self.logger.log('Type: {:^12}'.format('PCAP file'))
+
+ self.logger.log("")
+
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py
index 42c37e63..00fa6a93 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py
@@ -122,7 +122,8 @@ class STLSim(object):
mult = "1",
duration = -1,
mode = 'none',
- silent = False):
+ silent = False,
+ tunables = None):
if not mode in ['none', 'gdb', 'valgrind', 'json', 'yaml','pkt','native']:
raise STLArgumentError('mode', mode)
@@ -139,9 +140,18 @@ class STLSim(object):
stream_list = [x for x in input_list if isinstance(x, STLStream)]
# handle YAMLs
+ if tunables == None:
+ tunables = {}
+ else:
+ tunables = tunables[0]
+
for input_file in input_files:
try:
- profile = STLProfile.load(input_file, direction = (self.port_id % 2), port = self.port_id)
+ if not 'direction' in tunables:
+ tunables['direction'] = self.port_id % 2
+
+ profile = STLProfile.load(input_file, **tunables)
+
except STLError as e:
s = format_text("\nError while loading profile '{0}'\n".format(input_file), 'bold')
s += "\n" + e.brief()
@@ -395,6 +405,13 @@ def setParserOptions():
default = -1,
type = float)
+
+ parser.add_argument('-t',
+ help = 'sets tunable for a profile',
+ dest = 'tunables',
+ default = None,
+ type = parsing_opts.decode_tunables)
+
parser.add_argument('-p', '--path',
help = "BP sim path",
dest = 'bp_sim_path',
@@ -483,7 +500,8 @@ def main (args = None):
mult = options.mult,
duration = options.duration,
mode = mode,
- silent = options.silent)
+ silent = options.silent,
+ tunables = options.tunables)
except KeyboardInterrupt as e:
print "\n\n*** Caught Ctrl + C... Exiting...\n\n"
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
index e0334c7e..8a42145d 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py
@@ -796,7 +796,6 @@ class STLProfile(object):
streams : list of :class:`trex_stl_lib.trex_stl_streams.STLStream`
a list of stream objects
-
"""
@@ -810,6 +809,7 @@ class STLProfile(object):
raise STLArgumentError('streams', streams, valid_values = STLStream)
self.streams = streams
+ self.meta = None
def get_streams (self):
@@ -831,7 +831,28 @@ class STLProfile(object):
yaml_loader = YAMLLoader(yaml_file)
streams = yaml_loader.parse()
- return STLProfile(streams)
+ profile = STLProfile(streams)
+ profile.meta = {'type': 'yaml'}
+
+ return profile
+
+ @staticmethod
+ def get_module_tunables(module):
+ # remove self and variables
+ func = module.register().get_streams
+ argc = func.__code__.co_argcount
+ tunables = func.__code__.co_varnames[1:argc]
+
+ # fetch defaults
+ defaults = func.func_defaults
+ if len(defaults) != (argc - 1):
+ raise STLError("Module should provide default values for all arguments on get_streams()")
+
+ output = {}
+ for t, d in zip(tunables, defaults):
+ output[t] = d
+
+ return output
@staticmethod
@@ -850,9 +871,18 @@ class STLProfile(object):
module = __import__(file, globals(), locals(), [], -1)
reload(module) # reload the update
+ t = STLProfile.get_module_tunables(module)
+ for arg in kwargs:
+ if not arg in t:
+ raise STLError("profile {0} does not support tunable '{1}' - supported tunables are: '{2}'".format(python_file, arg, t))
+
streams = module.register().get_streams(direction = direction, **kwargs)
+ profile = STLProfile(streams)
- return STLProfile(streams)
+ profile.meta = {'type': 'python',
+ 'tunables': t}
+
+ return profile
except Exception as e:
a, b, tb = sys.exc_info()
@@ -936,8 +966,11 @@ class STLProfile(object):
last_ts_usec = ts_usec
+
+ profile = STLProfile(streams)
+ profile.meta = {'type': 'pcap'}
- return STLProfile(streams)
+ return profile
@@ -970,8 +1003,14 @@ class STLProfile(object):
else:
raise STLError("unknown profile file type: '{0}'".format(suffix))
+ profile.meta['stream_count'] = len(profile.get_streams()) if isinstance(profile.get_streams(), list) else 1
return profile
+ @staticmethod
+ def get_info (filename):
+ profile = STLProfile.load(filename)
+ return profile.meta
+
def dump_as_pkt (self):
""" dump the profile as scapy packet. in case it is raw convert to scapy and dump it"""
cnt=0;