summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/console/trex_console.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/automation/trex_control_plane/console/trex_console.py')
-rwxr-xr-x[-rw-r--r--]scripts/automation/trex_control_plane/console/trex_console.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py
index 9478db5a..945bb177 100644..100755
--- a/scripts/automation/trex_control_plane/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/console/trex_console.py
@@ -9,9 +9,13 @@ import string
import sys
import trex_root_path
+from common.trex_streams import *
from client_utils.jsonrpc_client import TrexStatelessClient
import trex_status
+from collections import namedtuple
+
+LoadedStreamList = namedtuple('LoadedStreamList', ['loaded', 'compiled'])
class TrexConsole(cmd.Cmd):
"""Trex Console"""
@@ -29,6 +33,8 @@ class TrexConsole(cmd.Cmd):
self.verbose = False
self.postcmd(False, "")
+
+ self.user_streams = {}
# a cool hack - i stole this function and added space
@@ -312,6 +318,86 @@ class TrexConsole(cmd.Cmd):
print "{:<30} {:<30}".format(cmd + " - ", help)
+ def do_load_stream_list(self, line):
+ '''Loads a YAML stream list serialization into user console \n'''
+ args = line.split()
+ if args >= 2:
+ name = args[0]
+ yaml_path = args[1]
+ stream_list = CStreamList()
+ loaded_obj = stream_list.load_yaml(yaml_path)
+ # print self.rpc_client.pretty_json(json.dumps(loaded_obj))
+ if name in self.user_streams:
+ print "Picked name already exist. Please pick another name."
+ else:
+ try:
+ compiled_streams = stream_list.compile_streams()
+ self.user_streams[name] = LoadedStreamList(loaded_obj,
+ [StreamPack(v.stream_id, v.stream.dump_compiled())
+ for k, v in compiled_streams.items()])
+
+ print "Stream '{0}' loaded successfully".format(name)
+ except Exception as e:
+ raise
+ return
+ else:
+ print "please provide load name and YAML path, separated by space."
+
+ def do_show_stream_list(self, line):
+ '''Shows the loaded stream list named [name] \n'''
+ args = line.split()
+ if args:
+ list_name = args[0]
+ try:
+ stream = self.user_streams[list_name]
+ if len(args) >= 2 and args[1] == "full":
+ print self.rpc_client.pretty_json(json.dumps(stream.compiled))
+ else:
+ print self.rpc_client.pretty_json(json.dumps(stream.loaded))
+ except KeyError as e:
+ print "Unknown stream list name provided"
+ else:
+ print "\nAvailable stream lists:\n{0}".format(', '.join([x
+ for x in self.user_streams.keys()]))
+
+ def complete_show_stream_list (self, text, line, begidx, endidx):
+ return [x
+ for x in self.user_streams.keys()
+ if x.startswith(text)]
+
+ def do_attach(self, line):
+ args = line.split()
+ if len(args) >= 1:
+ try:
+ stream_list = self.user_streams[args[0]]
+ port_list = self.parse_ports_from_line(' '.join(args[1:]))
+ owned = set(self.rpc_client.get_owned_ports())
+ if set(port_list).issubset(owned):
+ rc, resp_list = self.rpc_client.add_stream(port_list, stream_list.compiled)
+ if not rc:
+ print "\n*** " + resp_list + "\n"
+ return
+ else:
+ print "Not all desired ports are aquired.\n" \
+ "Acquired ports are: {acq}\n" \
+ "Requested ports: {req}\n" \
+ "Missing ports: {miss}".format(acq=list(owned),
+ req=port_list,
+ miss=list(set(port_list).difference(owned)))
+ except KeyError as e:
+ cause = e.args[0]
+ print "Provided stream list name '{0}' doesn't exists.".format(cause)
+ else:
+ print "Please provide list name and ports to attach to, or leave empty to attach to all ports."
+
+
+
+
+
+
+
+
+
# do
#def do_snapshot (self, line):