diff options
Diffstat (limited to 'scripts/automation/trex_control_plane')
4 files changed, 45 insertions, 38 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 index 0df2ac5d..4478ed3f 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -280,7 +280,7 @@ class Port: return self.ok() # start traffic - def start (self, mul): + def start (self, mul, duration): if self.state == self.STATE_DOWN: return self.err("Unable to start traffic - port is down") @@ -292,7 +292,8 @@ class Port: params = {"handler": self.handler, "port_id": self.port_id, - "mul": mul} + "mul": mul, + "duration": duration} rc, data = self.transmit("start_traffic", params) if not rc: @@ -419,7 +420,7 @@ class CTRexStatelessClient(object): return RC_OK() def is_connected (self): - return self.connected + return self.connected and self.comm_link.is_connected def disconnect(self): @@ -580,14 +581,14 @@ class CTRexStatelessClient(object): return self.ports[port_id].get_stream_id_list() - def start_traffic (self, multiplier, port_id_list = None): + def start_traffic (self, multiplier, duration, port_id_list = None): port_id_list = self.__ports(port_id_list) rc = RC() for port_id in port_id_list: - rc.add(self.ports[port_id].start(multiplier)) + rc.add(self.ports[port_id].start(multiplier, duration)) return rc @@ -685,7 +686,7 @@ class CTRexStatelessClient(object): return RC_OK() # start cmd - def cmd_start (self, port_id_list, stream_list, mult, force): + def cmd_start (self, port_id_list, stream_list, mult, force, duration): active_ports = list(set(self.get_active_ports()).intersection(port_id_list)) @@ -713,7 +714,7 @@ class CTRexStatelessClient(object): # finally, start the traffic - rc = self.start_traffic(mult, port_id_list) + rc = self.start_traffic(mult, duration, port_id_list) rc.annotate("Starting traffic on port(s) {0}:".format(port_id_list)) if rc.bad(): return rc @@ -754,7 +755,7 @@ class CTRexStatelessClient(object): return RC_ERR("Failed to load stream pack") - return self.cmd_start(opts.ports, stream_list, opts.mult, opts.force) + return self.cmd_start(opts.ports, stream_list, opts.mult, opts.force, opts.duration) def cmd_stop_line (self, line): '''Stop active traffic in specified ports on TRex\n''' @@ -820,7 +821,7 @@ class CTRexStatelessClient(object): cmd_table['wait'] = self.cmd_wait_line cmd_table['exit'] = self.cmd_exit_line - for index, line in enumerate(script_lines): + for index, line in enumerate(script_lines, start = 1): line = line.strip() if line == "": continue diff --git a/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py b/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py index 077c82ad..b826f02f 100755 --- a/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py +++ b/scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py @@ -110,45 +110,45 @@ class JsonRpcClient(object): return id, msg - def invoke_rpc_method (self, method_name, params = {}, block = True): + def invoke_rpc_method (self, method_name, params = {}): if not self.connected: return False, "Not connected to server" id, msg = self.create_jsonrpc_v2(method_name, params) - return self.send_raw_msg(msg, block) + return self.send_raw_msg(msg) # low level send of string message - def send_raw_msg (self, msg, block = True): + def send_raw_msg (self, msg): + self.verbose_msg("Sending Request To Server:\n\n" + self.pretty_json(msg) + "\n") - if block: - self.socket.send(msg) - else: + tries = 0 + while True: try: - self.socket.send(msg, flags = zmq.NOBLOCK) - except zmq.error.ZMQError as e: - self.disconnect() - return CmdResponse(False, "Failed To Get Send Message") - - got_response = False + self.socket.send(msg) + break + except zmq.Again: + sleep(0.1) + tries += 1 + if tries > 10: + self.disconnect() + return CmdResponse(False, "Failed to send message to server") + + + tries = 0 + while True: + try: + response = self.socket.recv() + break + except zmq.Again: + sleep(0.1) + tries += 1 + if tries > 10: + self.disconnect() + return CmdResponse(False, "Failed to get server response") - if block: - response = self.socket.recv() - got_response = True - else: - for i in xrange(0 ,10): - try: - response = self.socket.recv(flags = zmq.NOBLOCK) - got_response = True - break - except zmq.Again: - sleep(0.2) - - if not got_response: - self.disconnect() - return CmdResponse(False, "Failed To Get Server Response") self.verbose_msg("Server Response:\n\n" + self.pretty_json(response) + "\n") @@ -223,6 +223,8 @@ class JsonRpcClient(object): except zmq.error.ZMQError as e: return False, "ZMQ Error: Bad server or port name: " + str(e) + self.socket.setsockopt(zmq.SNDTIMEO, 5) + self.socket.setsockopt(zmq.RCVTIMEO, 5) self.connected = True diff --git a/scripts/automation/trex_control_plane/console/parsing_opts.py b/scripts/automation/trex_control_plane/console/parsing_opts.py index c154ce24..d5c21af0 100755 --- a/scripts/automation/trex_control_plane/console/parsing_opts.py +++ b/scripts/automation/trex_control_plane/console/parsing_opts.py @@ -89,10 +89,13 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], "dest": "all_ports", 'help': "Set this flag to apply the command on all available ports"}), DURATION: ArgumentPack(['-d'], - {"action": "store", + {'action': "store", 'metavar': 'TIME', - "type": match_time_unit, + 'dest': 'duration', + 'type': match_time_unit, + 'default': -1.0, 'help': "Set duration time for TRex."}), + FORCE: ArgumentPack(['--force'], {"action": "store_true", 'default': False, diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index 88e8dede..7cb65fa6 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -33,6 +33,7 @@ from client.trex_stateless_client import CTRexStatelessClient from common.text_opts import * from client_utils.general_utils import user_input, get_current_user import trex_status +import parsing_opts __version__ = "1.0" |