summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/examples
diff options
context:
space:
mode:
authoritraviv <itraviv@cisco.com>2016-08-10 16:09:04 +0300
committeritraviv <itraviv@cisco.com>2016-08-10 16:09:04 +0300
commit7aa248272fb7687f6cfd84a1414ddee4f0a47369 (patch)
tree453c15ac79a33705637a0a0d965ec666b854df02 /scripts/automation/trex_control_plane/examples
parent661d27af339a57319d41655b6bfa71810e4e60ba (diff)
***this is an example for a JSON-RPC (over ZMQ) client.***
started with -s for server IP address (default is local-host) started with -p for port number
Diffstat (limited to 'scripts/automation/trex_control_plane/examples')
-rwxr-xr-xscripts/automation/trex_control_plane/examples/zmq_server_client.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/examples/zmq_server_client.py b/scripts/automation/trex_control_plane/examples/zmq_server_client.py
new file mode 100755
index 00000000..15f37f1a
--- /dev/null
+++ b/scripts/automation/trex_control_plane/examples/zmq_server_client.py
@@ -0,0 +1,45 @@
+import sys
+import os
+python2_zmq_path = os.path.abspath(os.path.join(os.pardir,os.pardir,os.pardir,
+ 'external_libs','pyzmq-14.5.0','python2','fedora18','64bit'))
+sys.path.append(python2_zmq_path)
+import zmq
+import json
+from argparse import *
+
+parser = ArgumentParser(description=' Runs a Scapy Server Client example ')
+parser.add_argument('-p','--dest-scapy-port',type=int, default = 4507, dest='dest_scapy_port',
+ help='Select port to which this Scapy Server client will send to.\n default is 4507\n',action='store')
+parser.add_argument('-s','--server',type=str, default = 'localhost', dest='dest_scapy_ip',
+ help='Remote server IP address .\n default is localhost\n',action='store')
+
+args = parser.parse_args()
+
+dest_scapy_port = args.dest_scapy_port
+dest_scapy_ip = args.dest_scapy_ip
+
+context = zmq.Context()
+
+# Socket to talk to server
+print 'Connecting:'
+socket = context.socket(zmq.REQ)
+socket.connect("tcp://"+str(dest_scapy_ip)+":"+str(dest_scapy_port))
+try:
+ while True:
+ command = raw_input("enter RPC command [enter quit to exit]:\n")
+ if (command == 'quit'):
+ break
+ user_parameter = raw_input("input for command [should be left blank if not needed]:\n")
+ json_rpc_req = { "jsonrpc":"2.0","method": command ,"params":[user_parameter], "id":"1"}
+ request = json.dumps(json_rpc_req)
+ print("Sending request in json format %s" % request)
+ socket.send(request)
+
+ # Get the reply.
+ message = socket.recv()
+ print("Received reply %s [ %s ]" % (request, message))
+except KeyboardInterrupt:
+ print('Terminated By Ctrl+C')
+ socket.close()
+ context.destroy()
+