diff options
-rwxr-xr-x | scripts/automation/trex_control_plane/client/trex_stateless_client.py | 19 | ||||
-rwxr-xr-x | scripts/automation/trex_control_plane/client_utils/jsonrpc_client.py | 56 | ||||
-rwxr-xr-x | scripts/automation/trex_control_plane/console/parsing_opts.py | 7 | ||||
-rwxr-xr-x | scripts/automation/trex_control_plane/console/trex_console.py | 1 | ||||
-rw-r--r-- | src/gtest/trex_stateless_gtest.cpp | 15 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 7 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmds.h | 2 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.cpp | 4 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.h | 2 | ||||
-rw-r--r-- | src/stateless/cp/trex_streams_compiler.cpp | 3 | ||||
-rw-r--r-- | src/stateless/cp/trex_streams_compiler.h | 8 | ||||
-rw-r--r-- | src/stateless/dp/trex_stateless_dp_core.cpp | 6 | ||||
-rw-r--r-- | src/stateless/dp/trex_stateless_dp_core.h | 2 | ||||
-rw-r--r-- | src/stateless/messaging/trex_stateless_messaging.cpp | 6 | ||||
-rw-r--r-- | src/stateless/messaging/trex_stateless_messaging.h | 3 |
15 files changed, 66 insertions, 75 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" diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp index 8b96ef88..c845c32e 100644 --- a/src/gtest/trex_stateless_gtest.cpp +++ b/src/gtest/trex_stateless_gtest.cpp @@ -252,10 +252,9 @@ TEST_F(basic_stl, single_pkt_burst1) { TrexStreamsCompiledObj comp_obj(0,1.0); - comp_obj.set_simulation_duration( 10.0); assert(compile.compile(streams, comp_obj) ); - TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 10.0 ); t1.m_msg = lpstart; @@ -303,10 +302,9 @@ TEST_F(basic_stl, single_pkt) { TrexStreamsCompiledObj comp_obj(0,1.0); - comp_obj.set_simulation_duration( 10.0); assert(compile.compile(streams, comp_obj) ); - TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 10 ); t1.m_msg = lpstart; @@ -361,10 +359,9 @@ TEST_F(basic_stl, multi_pkt1) { // stream - clean TrexStreamsCompiledObj comp_obj(0,1.0); - comp_obj.set_simulation_duration( 10.0); assert(compile.compile(streams, comp_obj) ); - TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 10 ); t1.m_msg = lpstart; @@ -425,10 +422,9 @@ TEST_F(basic_stl, multi_pkt2) { // stream - clean TrexStreamsCompiledObj comp_obj(0,5.0); - comp_obj.set_simulation_duration( 10.0); assert(compile.compile(streams, comp_obj) ); - TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 10 ); t1.m_msg = lpstart; @@ -472,10 +468,9 @@ TEST_F(basic_stl, multi_burst1) { TrexStreamsCompiledObj comp_obj(0,1.0); - comp_obj.set_simulation_duration( 40.0); assert(compile.compile(streams, comp_obj) ); - TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 40 ); t1.m_msg = lpstart; diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index e32073b0..5ec92afc 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -458,8 +458,9 @@ TrexRpcCmdGetStream::_run(const Json::Value ¶ms, Json::Value &result) { trex_rpc_cmd_rc_e TrexRpcCmdStartTraffic::_run(const Json::Value ¶ms, Json::Value &result) { - uint8_t port_id = parse_byte(params, "port_id", result); - double mul = parse_double(params, "mul", result); + uint8_t port_id = parse_byte(params, "port_id", result); + double mul = parse_double(params, "mul", result); + double duration = parse_double(params, "duration", result); if (port_id >= get_stateless_obj()->get_port_count()) { std::stringstream ss; @@ -470,7 +471,7 @@ TrexRpcCmdStartTraffic::_run(const Json::Value ¶ms, Json::Value &result) { TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); try { - port->start_traffic(mul); + port->start_traffic(mul, duration); } catch (const TrexRpcException &ex) { generate_execute_err(result, ex.what()); } diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h index d7265ff2..b4f37e3b 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -105,7 +105,7 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStream, "get_stream", 3, true); -TREX_RPC_CMD_DEFINE(TrexRpcCmdStartTraffic, "start_traffic", 2, true); +TREX_RPC_CMD_DEFINE(TrexRpcCmdStartTraffic, "start_traffic", 3, true); TREX_RPC_CMD_DEFINE(TrexRpcCmdStopTraffic, "stop_traffic", 1, true); TREX_RPC_CMD_DEFINE(TrexRpcCmdPauseTraffic, "pause_traffic", 1, true); TREX_RPC_CMD_DEFINE(TrexRpcCmdResumeTraffic, "resume_traffic", 1, true); diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 7f2382d3..cbc5a328 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -86,7 +86,7 @@ TrexStatelessPort::release(void) { * */ void -TrexStatelessPort::start_traffic(double mul) { +TrexStatelessPort::start_traffic(double mul, double duration) { /* command allowed only on state stream */ verify_state(PORT_STATE_STREAMS); @@ -105,7 +105,7 @@ TrexStatelessPort::start_traffic(double mul) { } /* generate a message to all the relevant DP cores to start transmitting */ - TrexStatelessCpToDpMsgBase *start_msg = new TrexStatelessDpStart(compiled_obj); + TrexStatelessCpToDpMsgBase *start_msg = new TrexStatelessDpStart(compiled_obj, duration); send_message_to_dp(start_msg); diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index 90bf936e..b533f793 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -72,7 +72,7 @@ public: * start traffic * throws TrexException in case of an error */ - void start_traffic(double mul); + void start_traffic(double mul, double duration = -1); /** * stop traffic diff --git a/src/stateless/cp/trex_streams_compiler.cpp b/src/stateless/cp/trex_streams_compiler.cpp index 80cdb31c..580db51c 100644 --- a/src/stateless/cp/trex_streams_compiler.cpp +++ b/src/stateless/cp/trex_streams_compiler.cpp @@ -27,7 +27,6 @@ limitations under the License. * stream compiled object *************************************/ TrexStreamsCompiledObj::TrexStreamsCompiledObj(uint8_t port_id, double mul) : m_port_id(port_id), m_mul(mul) { - m_duration_sim=-1.0; } TrexStreamsCompiledObj::~TrexStreamsCompiledObj() { @@ -61,8 +60,6 @@ TrexStreamsCompiledObj::clone() { new_compiled_obj->m_mul = m_mul; - new_compiled_obj->m_duration_sim = m_duration_sim; - return new_compiled_obj; } diff --git a/src/stateless/cp/trex_streams_compiler.h b/src/stateless/cp/trex_streams_compiler.h index 78ac1ac7..44c8a0fc 100644 --- a/src/stateless/cp/trex_streams_compiler.h +++ b/src/stateless/cp/trex_streams_compiler.h @@ -48,13 +48,6 @@ public: return m_objs; } - void set_simulation_duration(double duration){ - m_duration_sim=duration; - } - - double get_simulation_duration(){ - return (m_duration_sim); - } /** * clone the compiled object * @@ -71,7 +64,6 @@ private: uint8_t m_port_id; double m_mul; - double m_duration_sim; /* duration for all simulation */ }; class TrexStreamsCompiler { diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp index 96c18dbd..eabd6fdb 100644 --- a/src/stateless/dp/trex_stateless_dp_core.cpp +++ b/src/stateless/dp/trex_stateless_dp_core.cpp @@ -207,14 +207,12 @@ TrexStatelessDpCore::add_cont_stream(TrexStream * stream, } void -TrexStatelessDpCore::start_traffic(TrexStreamsCompiledObj *obj) { +TrexStatelessDpCore::start_traffic(TrexStreamsCompiledObj *obj, double duration) { for (auto single_stream : obj->get_objects()) { add_cont_stream(single_stream.m_stream,obj); } - double duration=obj->get_simulation_duration(); - - if ( duration >0.0){ + if ( duration > 0.0 ){ add_duration( duration ); } } diff --git a/src/stateless/dp/trex_stateless_dp_core.h b/src/stateless/dp/trex_stateless_dp_core.h index 1029213d..7448d215 100644 --- a/src/stateless/dp/trex_stateless_dp_core.h +++ b/src/stateless/dp/trex_stateless_dp_core.h @@ -75,7 +75,7 @@ public: * @param pkt * @param pkt_len */ - void start_traffic(TrexStreamsCompiledObj *obj); + void start_traffic(TrexStreamsCompiledObj *obj, double duration = -1); /** * stop all traffic for this core diff --git a/src/stateless/messaging/trex_stateless_messaging.cpp b/src/stateless/messaging/trex_stateless_messaging.cpp index 032559bc..d8ebc52c 100644 --- a/src/stateless/messaging/trex_stateless_messaging.cpp +++ b/src/stateless/messaging/trex_stateless_messaging.cpp @@ -26,7 +26,7 @@ limitations under the License. /************************* start traffic message ************************/ -TrexStatelessDpStart::TrexStatelessDpStart(TrexStreamsCompiledObj *obj) : m_obj(obj) { +TrexStatelessDpStart::TrexStatelessDpStart(TrexStreamsCompiledObj *obj, double duration) : m_obj(obj), m_duration(duration) { } @@ -39,7 +39,7 @@ TrexStatelessDpStart::clone() { TrexStreamsCompiledObj *new_obj = m_obj->clone(); - TrexStatelessCpToDpMsgBase *new_msg = new TrexStatelessDpStart(new_obj); + TrexStatelessCpToDpMsgBase *new_msg = new TrexStatelessDpStart(new_obj, m_duration); return new_msg; } @@ -53,7 +53,7 @@ TrexStatelessDpStart::~TrexStatelessDpStart() { bool TrexStatelessDpStart::handle(TrexStatelessDpCore *dp_core) { - dp_core->start_traffic(m_obj); + dp_core->start_traffic(m_obj, m_duration); return true; } diff --git a/src/stateless/messaging/trex_stateless_messaging.h b/src/stateless/messaging/trex_stateless_messaging.h index d288fc83..90897665 100644 --- a/src/stateless/messaging/trex_stateless_messaging.h +++ b/src/stateless/messaging/trex_stateless_messaging.h @@ -66,7 +66,7 @@ public: class TrexStatelessDpStart : public TrexStatelessCpToDpMsgBase { public: - TrexStatelessDpStart(TrexStreamsCompiledObj *obj); + TrexStatelessDpStart(TrexStreamsCompiledObj *obj, double duration); ~TrexStatelessDpStart(); @@ -77,6 +77,7 @@ public: private: TrexStreamsCompiledObj *m_obj; + double m_duration; }; /** |