diff options
author | 2016-02-11 18:06:50 +0200 | |
---|---|---|
committer | 2016-02-11 18:06:50 +0200 | |
commit | c480bd24dbbef93661885a91c91c82494b1e9c46 (patch) | |
tree | 5ae48e96aa76da975816db703c36e7496d212927 /scripts/automation/trex_control_plane | |
parent | 06dbed66bb0302f0a4c11fe5b7e65ee323498d55 (diff) | |
parent | e93926178b4a510bd1bec776d69cc77eb7e16aff (diff) |
Integrate python split_by_field
Diffstat (limited to 'scripts/automation/trex_control_plane')
3 files changed, 38 insertions, 10 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py index e319e7d3..56657e22 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_port.py @@ -187,10 +187,13 @@ class Port(object): batch = [] for stream in streams_list: + stream_json = stream.to_json() + stream_json['next_stream_id'] = stream.get_next_id() + params = {"handler": self.handler, "port_id": self.port_id, "stream_id": stream.get_id(), - "stream": stream.to_json()} + "stream": stream_json} cmd = RpcCmdData('add_stream', params) batch.append(cmd) 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 357f54bd..4d720aac 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 @@ -124,7 +124,7 @@ class STLSim(object): duration = -1, mode = 'none'): - if not mode in ['none', 'gdb', 'valgrind', 'json']: + if not mode in ['none', 'gdb', 'valgrind', 'json', 'yaml']: raise STLArgumentError('mode', mode) # listify @@ -173,16 +173,20 @@ class STLSim(object): raise STLError("stream dependency error - unable to find '{0}'".format(next)) next_id = lookup[next] - stream.fields['next_stream_id'] = next_id + stream.set_next_id(next_id) for stream in stream_list: + + stream_json = stream.to_json() + stream_json['next_stream_id'] = stream.get_next_id() + cmd = {"id":1, "jsonrpc": "2.0", "method": "add_stream", "params": {"handler": self.handler, "port_id": self.port_id, "stream_id": stream.get_id(), - "stream": stream.to_json()} + "stream": stream_json} } cmds_json.append(cmd) @@ -195,6 +199,9 @@ class STLSim(object): if mode == 'json': print json.dumps(cmds_json, indent = 4, separators=(',', ': '), sort_keys = True) return + elif mode == 'yaml': + print STLProfile(stream_list).dump_to_yaml() + return # start simulation self.outfile = outfile @@ -376,6 +383,11 @@ def setParserOptions(): action = "store_true", default = False) + group.add_argument("--yaml", + help = "generate YAML from input file [default is False]", + action = "store_true", + default = False) + return parser @@ -404,6 +416,8 @@ def main (): mode = 'gdb' elif options.json: mode = 'json' + elif options.yaml: + mode = 'yaml' else: mode = 'none' 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 609006a8..1a46aae7 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 @@ -127,11 +127,12 @@ class STLStream(object): raise STLError("continuous stream cannot have a next stream ID") # tag for the stream and next - can be anything - self.name = name if name else random_name(8) + self.name = name self.next = next # ID self.set_id(stream_id) + self.set_next_id(None) self.fields = {} @@ -172,7 +173,7 @@ class STLStream(object): return s def to_json (self): - return self.fields + return dict(self.fields) def get_id (self): return self.id @@ -181,10 +182,10 @@ class STLStream(object): self.id = id def get_next_id (self): - return self.fields.get('next_stream_id') + return self.next_id - def set_next_id (self, next_stream_id): - self.fields['next_stream_id'] = next_stream_id + def set_next_id (self, next_id): + self.next_id = next_id def get_name (self): return self.name @@ -210,7 +211,17 @@ class STLStream(object): def to_yaml (self): - return {'name': self.name, 'stream': self.fields} + y = {} + + if self.name: + y['name'] = self.name + + if self.next: + y['next'] = self.next + + y['stream'] = self.fields + + return y def dump_to_yaml (self, yaml_file = None): yaml_dump = yaml.dump([self.to_yaml()], default_flow_style = False) |