From 92dea3787ab7b2c9877af9cd539d42a6957f7da6 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 25 Nov 2015 06:56:04 -0500 Subject: added events log --- src/publisher/trex_publisher.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src/publisher') diff --git a/src/publisher/trex_publisher.h b/src/publisher/trex_publisher.h index 82603fda..89336735 100644 --- a/src/publisher/trex_publisher.h +++ b/src/publisher/trex_publisher.h @@ -39,10 +39,11 @@ public: void publish_json(const std::string &s); enum event_type_e { - EVENT_PORT_STOPPED = 0 + EVENT_PORT_STOPPED = 0, + EVENT_SERVER_STOPPED = 1 }; - void publish_event(event_type_e type, const Json::Value &data); + void publish_event(event_type_e type, const Json::Value &data = Json::nullValue); private: void show_zmq_last_error(const std::string &err); -- cgit 1.2.3-korg From b6ec2066653319b60385de1d4117165eb88890a1 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 25 Nov 2015 07:39:39 -0500 Subject: fixed a bug with default start command in the console also added clear events and more types of events --- .../client/trex_stateless_client.py | 30 ++++++++++++++++++++-- .../trex_control_plane/console/parsing_opts.py | 2 +- .../trex_control_plane/console/trex_console.py | 22 ++++++++++++++++ src/publisher/trex_publisher.h | 6 +++-- src/stateless/cp/trex_stateless_port.cpp | 9 ++++++- 5 files changed, 63 insertions(+), 6 deletions(-) (limited to 'src/publisher') 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 1d0ca606..149d2855 100755 --- a/scripts/automation/trex_control_plane/client/trex_stateless_client.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_client.py @@ -410,26 +410,49 @@ class CTRexStatelessClient(object): ev = "[event] - " + show_event = False + + # port started if (type == 0): + port_id = int(data['port_id']) + ev += "Port {0} has started".format(port_id) + + # port stopped + elif (type == 1): port_id = int(data['port_id']) ev += "Port {0} has stopped".format(port_id) + # call the handler self.async_event_port_stopped(port_id) + - elif (type == 1): + # server stopped + elif (type == 2): ev += "Server has stopped" self.async_event_server_stopped() + show_event = True + + # port finished traffic + elif (type == 3): + port_id = int(data['port_id']) + ev += "Port {0} job done".format(port_id) + + # call the handler + self.async_event_port_stopped(port_id) + show_event = True else: # unknown event - ignore return - print format_text("\n" + ev, 'bold') + if show_event: + print format_text("\n" + ev, 'bold') ts = time.time() st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S') self.events.append("{0} - ".format(st) + format_text(ev, 'bold')) + def async_event_port_stopped (self, port_id): self.ports[port_id].async_event_port_stopped() @@ -439,6 +462,9 @@ class CTRexStatelessClient(object): def get_events (self): return self.events + def clear_events (self): + self.events = [] + ############# helper functions section ############## def validate_port_list(self, port_id_list): diff --git a/scripts/automation/trex_control_plane/console/parsing_opts.py b/scripts/automation/trex_control_plane/console/parsing_opts.py index d2484a83..0bcdce84 100755 --- a/scripts/automation/trex_control_plane/console/parsing_opts.py +++ b/scripts/automation/trex_control_plane/console/parsing_opts.py @@ -121,7 +121,7 @@ def is_valid_file(filename): OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], {'help': match_multiplier_help, 'dest': "mult", - 'default': 1.0, + 'default': {'type':'raw', 'max':1}, 'type': match_multiplier}), diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index b164af4e..fc2c845a 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -334,12 +334,34 @@ class TRexConsole(TRexGeneralCmd): self.stateless_client.cmd_reset() + def help_events (self): + self.do_events("-h") + def do_events (self, line): '''shows events recieved from server\n''' + + x = parsing_opts.ArgumentPack(['-c','--clear'], + {'action' : "store_true", + 'default': False, + 'help': "clear the events log"}) + + parser = parsing_opts.gen_parser(self, + "events", + self.do_events.__doc__, + x) + + opts = parser.parse_args(line.split()) + if opts is None: + return + events = self.stateless_client.get_events() for ev in events: print ev + if opts.clear: + self.stateless_client.clear_events() + print format_text("\n\nEvent log was cleared\n\n") + # tui def do_tui (self, line): '''Shows a graphical console\n''' diff --git a/src/publisher/trex_publisher.h b/src/publisher/trex_publisher.h index 89336735..8d1be064 100644 --- a/src/publisher/trex_publisher.h +++ b/src/publisher/trex_publisher.h @@ -39,8 +39,10 @@ public: void publish_json(const std::string &s); enum event_type_e { - EVENT_PORT_STOPPED = 0, - EVENT_SERVER_STOPPED = 1 + EVENT_PORT_STARTED = 0, + EVENT_PORT_STOPPED = 1, + EVENT_SERVER_STOPPED = 2, + EVENT_PORT_FINISHED_TX = 3, }; void publish_event(event_type_e type, const Json::Value &data = Json::nullValue); diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 5f1a3bca..2fd948fd 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -139,6 +139,9 @@ TrexStatelessPort::start_traffic(double mul, double duration) { send_message_to_dp(start_msg); + Json::Value data; + data["port_id"] = m_port_id; + get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_STARTED, data); } void @@ -194,6 +197,10 @@ TrexStatelessPort::stop_traffic(void) { change_state(PORT_STATE_STREAMS); + Json::Value data; + data["port_id"] = m_port_id; + get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_STOPPED, data); + } void @@ -366,7 +373,7 @@ TrexStatelessPort::on_dp_event_occured(TrexDpPortEvent::event_e event_type) { /* send a ZMQ event */ data["port_id"] = m_port_id; - get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_STOPPED, data); + get_stateless_obj()->get_publisher()->publish_event(TrexPublisher::EVENT_PORT_FINISHED_TX, data); break; default: -- cgit 1.2.3-korg