From 49f6b00b58c3ec734218fcd69259771a42c157bd Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Sun, 23 Aug 2015 17:41:23 +0300 Subject: Added dkpt package, created basic shell for packetGen usage --- .../examples/client_interactive_example.py | 1 - .../examples/interactive_stateless.py | 78 ++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 scripts/automation/trex_control_plane/examples/interactive_stateless.py (limited to 'scripts/automation/trex_control_plane/examples') diff --git a/scripts/automation/trex_control_plane/examples/client_interactive_example.py b/scripts/automation/trex_control_plane/examples/client_interactive_example.py index d45e4cef..dbca7615 100755 --- a/scripts/automation/trex_control_plane/examples/client_interactive_example.py +++ b/scripts/automation/trex_control_plane/examples/client_interactive_example.py @@ -13,7 +13,6 @@ import time import socket import errno - class InteractiveTRexClient(cmd.Cmd): intro = termstyle.green("\nInteractive shell to play with Cisco's T-Rex API.\nType help to view available pre-defined scenarios\n(c) All rights reserved.\n") diff --git a/scripts/automation/trex_control_plane/examples/interactive_stateless.py b/scripts/automation/trex_control_plane/examples/interactive_stateless.py new file mode 100644 index 00000000..c0fc51a7 --- /dev/null +++ b/scripts/automation/trex_control_plane/examples/interactive_stateless.py @@ -0,0 +1,78 @@ +#!/router/bin/python + +import trex_root_path +from client.trex_client import * +from common.trex_exceptions import * +import cmd +from python_lib.termstyle import termstyle +import os +from argparse import ArgumentParser +import socket +import errno + + +class InteractiveStatelessTRex(cmd.Cmd): + + intro = termstyle.green("\nInteractive shell to play with Cisco's TRex stateless API.\ + \nType help to view available pre-defined scenarios\n(c) All rights reserved.\n") + prompt = '> ' + + def __init__(self, verbose_mode=False): + cmd.Cmd.__init__(self) + self.verbose = verbose_mode + self.trex = None + self.DEFAULT_RUN_PARAMS = dict(m=1.5, + nc=True, + p=True, + d=100, + f='avl/sfr_delay_10_1g.yaml', + l=1000) + self.run_params = dict(self.DEFAULT_RUN_PARAMS) + + def do_push_files(self, filepaths): + """Pushes a custom file to be stored locally on T-Rex server.\ + \nPush multiple files by specifying their path separated by ' ' (space).""" + try: + filepaths = filepaths.split(' ') + print termstyle.green("*** Starting pushing files ({trex_files}) to T-Rex. ***".format( + trex_files=', '.join(filepaths)) + ) + ret_val = self.trex.push_files(filepaths) + if ret_val: + print termstyle.green("*** End of T-Rex push_files method (success) ***") + else: + print termstyle.magenta("*** End of T-Rex push_files method (failed) ***") + + except IOError as inst: + print termstyle.magenta(inst) + +if __name__ == "__main__": + parser = ArgumentParser(description=termstyle.cyan('Run T-Rex client API demos and scenarios.'), + usage="client_interactive_example [options]") + + parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0 \t (C) Cisco Systems Inc.\n') + + # parser.add_argument("-t", "--trex-host", required = True, dest="trex_host", + # action="store", help="Specify the hostname or ip to connect with T-Rex server.", + # metavar="HOST" ) + # parser.add_argument("-p", "--trex-port", type=int, default = 8090, metavar="PORT", dest="trex_port", + # help="Select port on which the T-Rex server listens. Default port is 8090.", action="store") + # parser.add_argument("-m", "--maxhist", type=int, default = 100, metavar="SIZE", dest="hist_size", + # help="Specify maximum history size saved at client side. Default size is 100.", action="store") + parser.add_argument("--verbose", dest="verbose", + action="store_true", + help="Switch ON verbose option at T-Rex client. Default is: OFF.", + default=False) + args = parser.parse_args() + + try: + InteractiveStatelessTRex(args.verbose).cmdloop() + + except KeyboardInterrupt: + print termstyle.cyan('Bye Bye!') + exit(-1) + except socket.error, e: + if e.errno == errno.ECONNREFUSED: + raise socket.error(errno.ECONNREFUSED, + "Connection from T-Rex server was terminated. \ + Please make sure the server is up.") -- cgit From cdcc62972d42f009f55e6aeb2ca5c60c3acd75eb Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Wed, 26 Aug 2015 14:27:43 +0300 Subject: added dpkt package, initial stateless client implementation --- .../examples/interactive_stateless.py | 74 ++++++++++++++++++---- 1 file changed, 62 insertions(+), 12 deletions(-) (limited to 'scripts/automation/trex_control_plane/examples') diff --git a/scripts/automation/trex_control_plane/examples/interactive_stateless.py b/scripts/automation/trex_control_plane/examples/interactive_stateless.py index c0fc51a7..016888d2 100644 --- a/scripts/automation/trex_control_plane/examples/interactive_stateless.py +++ b/scripts/automation/trex_control_plane/examples/interactive_stateless.py @@ -1,14 +1,17 @@ #!/router/bin/python import trex_root_path -from client.trex_client import * +from client.trex_stateless_client import * from common.trex_exceptions import * import cmd -from python_lib.termstyle import termstyle +from termstyle import termstyle +# import termstyle import os from argparse import ArgumentParser import socket import errno +import ast +import json class InteractiveStatelessTRex(cmd.Cmd): @@ -17,10 +20,12 @@ class InteractiveStatelessTRex(cmd.Cmd): \nType help to view available pre-defined scenarios\n(c) All rights reserved.\n") prompt = '> ' - def __init__(self, verbose_mode=False): + def __init__(self, trex_host, trex_port, virtual, verbose): cmd.Cmd.__init__(self) - self.verbose = verbose_mode - self.trex = None + + self.verbose = verbose + self.virtual = virtual + self.trex = CTRexStatelessClient(trex_host, trex_port, self.virtual) self.DEFAULT_RUN_PARAMS = dict(m=1.5, nc=True, p=True, @@ -29,6 +34,47 @@ class InteractiveStatelessTRex(cmd.Cmd): l=1000) self.run_params = dict(self.DEFAULT_RUN_PARAMS) + def do_transmit(self, line): + """Transmits a request over using a given link to server.\ + \nuse: transmit [method_name] [method_params]""" + if line == "": + print "\nUsage: [method name] [param dict as string]\n" + print "Example: rpc test_add {'x': 12, 'y': 17}\n" + return + + args = line.split(' ', 1) # args will have max length of 2 + method_name = args[0] + params = None + bad_parse = False + + try: + params = ast.literal_eval(args[1]) + if not isinstance(params, dict): + bad_parse = True + except ValueError as e1: + bad_parse = True + except SyntaxError as e2: + bad_parse = True + + if bad_parse: + print "\nValue should be a valid dict: '{0}'".format(args[1]) + print "\nUsage: [method name] [param dict as string]\n" + print "Example: rpc test_add {'x': 12, 'y': 17}\n" + return + + response = self.trex.transmit(method_name, params) + if not self.virtual: + # expect response + rc, msg = response + if rc: + print "\nServer Response:\n\n" + json.dumps(msg) + "\n" + else: + print "\n*** " + msg + "\n" + + + + + def do_push_files(self, filepaths): """Pushes a custom file to be stored locally on T-Rex server.\ \nPush multiple files by specifying their path separated by ' ' (space).""" @@ -52,21 +98,25 @@ if __name__ == "__main__": parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0 \t (C) Cisco Systems Inc.\n') - # parser.add_argument("-t", "--trex-host", required = True, dest="trex_host", - # action="store", help="Specify the hostname or ip to connect with T-Rex server.", - # metavar="HOST" ) - # parser.add_argument("-p", "--trex-port", type=int, default = 8090, metavar="PORT", dest="trex_port", - # help="Select port on which the T-Rex server listens. Default port is 8090.", action="store") + parser.add_argument("-t", "--trex-host", required = True, dest="trex_host", + action="store", help="Specify the hostname or ip to connect with T-Rex server.", + metavar="HOST" ) + parser.add_argument("-p", "--trex-port", type=int, default = 8090, metavar="PORT", dest="trex_port", + help="Select port on which the T-Rex server listens. Default port is 8090.", action="store") # parser.add_argument("-m", "--maxhist", type=int, default = 100, metavar="SIZE", dest="hist_size", # help="Specify maximum history size saved at client side. Default size is 100.", action="store") + parser.add_argument("--virtual", dest="virtual", + action="store_true", + help="Switch ON virtual option at TRex client. Default is: OFF.", + default=False) parser.add_argument("--verbose", dest="verbose", action="store_true", - help="Switch ON verbose option at T-Rex client. Default is: OFF.", + help="Switch ON verbose option at TRex client. Default is: OFF.", default=False) args = parser.parse_args() try: - InteractiveStatelessTRex(args.verbose).cmdloop() + InteractiveStatelessTRex(**vars(args)).cmdloop() except KeyboardInterrupt: print termstyle.cyan('Bye Bye!') -- cgit From 68df86e2005dc4693b1270a3e663e2450f81fa93 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Thu, 27 Aug 2015 19:18:16 +0300 Subject: progress in packet builder module --- .../automation/trex_control_plane/examples/interactive_stateless.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'scripts/automation/trex_control_plane/examples') diff --git a/scripts/automation/trex_control_plane/examples/interactive_stateless.py b/scripts/automation/trex_control_plane/examples/interactive_stateless.py index 016888d2..7c25b4ef 100644 --- a/scripts/automation/trex_control_plane/examples/interactive_stateless.py +++ b/scripts/automation/trex_control_plane/examples/interactive_stateless.py @@ -93,7 +93,7 @@ class InteractiveStatelessTRex(cmd.Cmd): print termstyle.magenta(inst) if __name__ == "__main__": - parser = ArgumentParser(description=termstyle.cyan('Run T-Rex client API demos and scenarios.'), + parser = ArgumentParser(description=termstyle.cyan('Run TRex client stateless API demos and scenarios.'), usage="client_interactive_example [options]") parser.add_argument('-v', '--version', action='version', version='%(prog)s 1.0 \t (C) Cisco Systems Inc.\n') @@ -101,8 +101,8 @@ if __name__ == "__main__": parser.add_argument("-t", "--trex-host", required = True, dest="trex_host", action="store", help="Specify the hostname or ip to connect with T-Rex server.", metavar="HOST" ) - parser.add_argument("-p", "--trex-port", type=int, default = 8090, metavar="PORT", dest="trex_port", - help="Select port on which the T-Rex server listens. Default port is 8090.", action="store") + parser.add_argument("-p", "--trex-port", type=int, default = 5050, metavar="PORT", dest="trex_port", + help="Select port on which the T-Rex server listens. Default port is 5050.", action="store") # parser.add_argument("-m", "--maxhist", type=int, default = 100, metavar="SIZE", dest="hist_size", # help="Specify maximum history size saved at client side. Default size is 100.", action="store") parser.add_argument("--virtual", dest="virtual", -- cgit