diff options
author | imarom <imarom@cisco.com> | 2016-03-16 18:32:45 +0200 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-03-16 19:17:55 +0200 |
commit | aa334e0ef9258ffc70f0741627861b832d79a69b (patch) | |
tree | 2ea277e05acd3c45fafa308fcdfe695bdcfc32e5 /scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py | |
parent | 9518c16c5f10bef7a87b2237b635ea47ef5c183a (diff) |
tunables show on the console
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py')
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py | 47 |
1 files changed, 43 insertions, 4 deletions
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; |