summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_hltapi.py67
-rwxr-xr-xscripts/automation/trex_control_plane/client/trex_stateless_client.py19
2 files changed, 68 insertions, 18 deletions
diff --git a/scripts/automation/trex_control_plane/client/trex_hltapi.py b/scripts/automation/trex_control_plane/client/trex_hltapi.py
index 6194d376..b237071f 100755
--- a/scripts/automation/trex_control_plane/client/trex_hltapi.py
+++ b/scripts/automation/trex_control_plane/client/trex_hltapi.py
@@ -3,6 +3,7 @@
import trex_root_path
from client_utils.packet_builder import CTRexPktBuilder
from trex_stateless_client import CTRexStatelessClient
+import dpkt
class CTRexHltApi(object):
@@ -46,28 +47,68 @@ class CTRexHltApi(object):
ret_dict.update({"log": log})
return ret_dict
print log
- ret_dict.update({"status": 1})
- self.trex_client.disconnect()
+ port_handle = {device: {port: port # since only supporting single TRex at the moment, 1:1 map
+ for port in port_list}
+ }
- pass
+ ret_dict.update({"status": 1,
+ "log": None,
+ "port_handle": port_handle,
+ "offline": 0}) # ports are online
+ return ret_dict
def cleanup_session(self, port_list, maintain_lock=False):
- pass
+ ret_dict = {"status": 0}
+ if not maintain_lock:
+ # release taken ports
+ if port_list == "all":
+ port_list = self.trex_client.get_acquired_ports()
+ else:
+ port_list = self.parse_port_list(port_list)
+ response = self.trex_client.release(port_list)
+ res_ok, log = CTRexHltApi.process_response(port_list, response)
+ print log
+ if not res_ok:
+ ret_dict.update({"log": log})
+ return ret_dict
+ ret_dict.update({"status": 1,
+ "log": None})
+ self.trex_client.disconnect()
+ self.trex_client = None
+ return ret_dict
def interface_config(self, port_handle, mode="config"):
- pass
-
- def get_status(self):
- pass
-
- def get_port_handler(self):
- pass
+ allowed_modes = ["config", "modify", "destroy"]
+ if mode not in allowed_modes:
+ raise ValueError("mode must be one of the following values: {modes}".format(modes=allowed_modes))
+ # pass this function for now...
+ return {"status": 1, "log": None}
+ # ----- traffic functions ----- #
def traffic_config(self, mode, port_handle,
- mac_src, mac_dst,
+ l2_encap, mac_src, mac_dst,
l3_protocol, ip_src_addr, ip_dst_addr, l3_length,
transmit_mode, rate_pps):
- pass
+ allowed_modes = ["create", "modify", "remove", "enable", "disable", "reset"]
+ if mode not in allowed_modes:
+ raise ValueError("mode must be one of the following values: {modes}".format(modes=allowed_modes))
+ if mode == "create":
+ # create a new stream with desired attributes
+ pkt_bld = CTRexPktBuilder()
+ if l2_encap == "ethernet_ii":
+ pkt_bld.add_pkt_layer("l2", dpkt.ethernet.Ethernet())
+ # set Ethernet layer attributes
+ pkt_bld.set_eth_layer_addr("l2", "src", mac_src)
+ pkt_bld.set_eth_layer_addr("l2", "dst", mac_dst)
+ else:
+ raise NotImplementedError("l2_encap does not support the desired encapsulation '{0}'".format(l2_encap))
+ # set l3 attrubutes
+ if l3_protocol == "ipv4":
+
+
+ pass
+ else:
+ raise NotImplementedError("mode '{0}' is not supported yet on TRex".format(mode))
def traffic_control(self, action, port_handle):
pass
diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_client.py b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
index 97d3ec0a..3079ee5e 100755
--- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py
+++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py
@@ -114,6 +114,9 @@ class CTRexStatelessClient(object):
def get_port_count(self):
return self.system_info.get("port_count")
+ def get_acquired_ports(self):
+ return self._conn_handler.keys()
+
def acquire(self, port_id, force=False):
if not self._is_ports_valid(port_id):
raise ValueError("Provided illegal port id input")
@@ -145,14 +148,16 @@ class CTRexStatelessClient(object):
for p_id in port_ids]
rc, resp_list = self.transmit_batch(commands)
if rc:
- self._process_batch_result(commands, resp_list, self._handle_release_response)
+ return self._process_batch_result(commands, resp_list, self._handle_release_response,
+ success_test=self.ack_success_test)
else:
self._conn_handler.pop(port_id)
params = {"handler": self._conn_handler.get(port_id),
"port_id": port_id}
command = RpcCmdData("release", params)
- self._handle_release_response(command, self.transmit(command.method, command.params))
- return
+ return self._handle_release_response(command,
+ self.transmit(command.method, command.params),
+ self.ack_success_test)
@force_status(owned=True)
def add_stream(self, stream_id, stream_obj, port_id=None):
@@ -362,8 +367,12 @@ class CTRexStatelessClient(object):
return RpcResponseStatus(False, port_id, response.data)
def _handle_release_response(self, request, response, success_test):
- if response.success:
- del self._conn_handler[request.get("port_id")]
+ port_id = request.params.get("port_id")
+ if success_test(response):
+ del self._conn_handler[port_id]
+ return RpcResponseStatus(True, port_id, "Released")
+ else:
+ return RpcResponseStatus(False, port_id, response.data)
def _handle_start_traffic_response(self, request, response, success_test):
if response.success: