summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/client/trex_hltapi.py
diff options
context:
space:
mode:
authorDan Klein <danklei@cisco.com>2015-10-27 10:00:18 +0200
committerDan Klein <danklei@cisco.com>2015-10-27 10:00:18 +0200
commita39e4416cd78fc3b147695465c4de1c896b3face (patch)
tree4d5f1fd6737bbe6159303fe21b0518a539c0a665 /scripts/automation/trex_control_plane/client/trex_hltapi.py
parentb44239e4c6019f10fa7cf4fe0fef8c3726435033 (diff)
more hltapi progress
connect working
Diffstat (limited to 'scripts/automation/trex_control_plane/client/trex_hltapi.py')
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_hltapi.py72
1 files changed, 68 insertions, 4 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_hltapi.py b/scripts/automation/trex_control_plane/client/trex_hltapi.py
index 7453d8ec..6194d376 100755
--- a/scripts/automation/trex_control_plane/client/trex_hltapi.py
+++ b/scripts/automation/trex_control_plane/client/trex_hltapi.py
@@ -4,14 +4,54 @@ import trex_root_path
from client_utils.packet_builder import CTRexPktBuilder
from trex_stateless_client import CTRexStatelessClient
-print "done!"
class CTRexHltApi(object):
def __init__(self):
+ self.trex_client = None
+ self.connected = False
+
+ pass
+
+ # ----- session functions ----- #
+
+ def connect(self, device, port_list, username, port=5050, reset=False, break_locks=False):
+ ret_dict = {"status": 0}
+ self.trex_client = CTRexStatelessClient(username, device, port)
+ res_ok, msg = self.trex_client.connect()
+ if not res_ok:
+ self.trex_client = None
+ ret_dict.update({"log": msg})
+ return ret_dict
+ # arrived here, connection successfully created with server
+ # next, try acquiring ports of TRex
+ port_list = self.parse_port_list(port_list)
+ response = self.trex_client.acquire(port_list, force=break_locks)
+ res_ok, log = CTRexHltApi.process_response(port_list, response)
+ if not res_ok:
+ self.trex_client.disconnect()
+ self.trex_client = None
+ ret_dict.update({"log": log})
+ # TODO: should revert taken ports?!
+ return ret_dict
+ # arrived here, all desired ports were successfully acquired
+ print log
+ if reset:
+ # remove all port traffic configuration from TRex
+ response = self.trex_client.remove_all_streams(port_list)
+ res_ok, log = CTRexHltApi.process_response(port_list, response)
+ if not res_ok:
+ self.trex_client.disconnect()
+ self.trex_client = None
+ ret_dict.update({"log": log})
+ return ret_dict
+ print log
+ ret_dict.update({"status": 1})
+ self.trex_client.disconnect()
+
pass
- def connect(self, device, port_list, username, reset=False, break_locks=False):
+ def cleanup_session(self, port_list, maintain_lock=False):
pass
def interface_config(self, port_handle, mode="config"):
@@ -41,8 +81,32 @@ class CTRexHltApi(object):
def get_stream_stats(self, port_handle):
return self.traffic_stats(port_handle, mode="stream")
-
-
+ # ----- internal functions ----- #
+ @staticmethod
+ def process_response(port_list, response):
+ if isinstance(port_list, list):
+ res_ok, response = response
+ log = CTRexHltApi.join_batch_response(response)
+ else:
+ res_ok = response.success
+ log = str(response)
+ return res_ok, log
+
+ @staticmethod
+ def parse_port_list(port_list):
+ if isinstance(port_list, str):
+ return [int(port)
+ for port in port_list.split()]
+ elif isinstance(port_list, list):
+ return [int(port)
+ for port in port_list]
+ else:
+ return port_list
+
+ @staticmethod
+ def join_batch_response(responses):
+ return "\n".join([str(response)
+ for response in responses])
if __name__ == "__main__":