summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/client/trex_stateless_client.py
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2015-09-20 17:34:55 +0300
committerHanoh Haim <hhaim@cisco.com>2015-09-20 17:34:55 +0300
commit3fe28431157f7b2ed2ed8184ed85017c42a4cb6c (patch)
tree41fa17684842885e1664cc63ff1520157f191261 /scripts/automation/trex_control_plane/client/trex_stateless_client.py
parent588bb20e9c8f8438db4eb3e8db85111f41bd7306 (diff)
parent28fef018f75b5a54ac69ac7c919127bf47f5b61f (diff)
Merge branch 'master' of csi-sceasr-b45:/auto/proj-pcube-b/apps/PL-b/tools/repo//trex-core into wen
Diffstat (limited to 'scripts/automation/trex_control_plane/client/trex_stateless_client.py')
-rw-r--r--scripts/automation/trex_control_plane/client/trex_stateless_client.py51
1 files changed, 51 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
new file mode 100644
index 00000000..5513f420
--- /dev/null
+++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
@@ -0,0 +1,51 @@
+#!/router/bin/python
+
+try:
+ # support import for Python 2
+ import outer_packages
+except ImportError:
+ # support import for Python 3
+ import client.outer_packages
+from client_utils.jsonrpc_client import JsonRpcClient
+
+
+
+class CTRexStatelessClient(object):
+ """docstring for CTRexStatelessClient"""
+ def __init__(self, server="localhost", port=5050, virtual=False):
+ super(CTRexStatelessClient, self).__init__()
+ self.tx_link = CTRexStatelessClient.CTxLink(server, port, virtual)
+
+
+ def transmit(self, method_name, params = {}):
+ return self.tx_link.transmit(method_name, params)
+
+
+
+ class CTxLink(object):
+ """describes the connectivity of the stateless client method"""
+ def __init__(self, server="localhost", port=5050, virtual=False):
+ super(CTRexStatelessClient.CTxLink, self).__init__()
+ self.virtual = virtual
+ self.server = server
+ self.port = port
+ self.rpc_link = JsonRpcClient(self.server, self.port)
+ if not self.virtual:
+ self.rpc_link.connect()
+
+ def transmit(self, method_name, params = {}):
+ if self.virtual:
+ print "Transmitting virtually over tcp://{server}:{port}".format(
+ server=self.server,
+ port=self.port)
+ id, msg = self.rpc_link.create_jsonrpc_v2(method_name, params)
+ print msg
+ return
+ else:
+ return self.rpc_link.invoke_rpc_method(method_name, params)
+
+
+
+
+if __name__ == "__main__":
+ pass