From 5257dbb8253fe5b70b75f9c064c4593ca7aee99f Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 4 Jan 2017 18:46:45 +0200 Subject: draft - unreviewed Signed-off-by: imarom --- src/stateless/cp/trex_stateless.cpp | 83 +++++++++++----------------- src/stateless/cp/trex_stateless.h | 30 ++++------ src/stateless/cp/trex_stateless_port.cpp | 28 +++------- src/stateless/cp/trex_stateless_port.h | 95 +++++++++++++++++++++++++++++--- 4 files changed, 137 insertions(+), 99 deletions(-) (limited to 'src/stateless/cp') diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp index c31ba0a5..32babbf7 100644 --- a/src/stateless/cp/trex_stateless.cpp +++ b/src/stateless/cp/trex_stateless.cpp @@ -18,13 +18,15 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include -#include -#include +//#include #include #include +#include "trex_stateless.h" +#include "trex_stateless_port.h" +#include "trex_stateless_messaging.h" + using namespace std; /*********************************************************** @@ -140,54 +142,35 @@ TrexStateless::get_dp_core_count() { return m_platform_api->get_dp_core_count(); } -void -TrexStateless::encode_stats(Json::Value &global) { - - TrexPlatformGlobalStats stats; - m_platform_api->get_global_stats(stats); - - global["cpu_util"] = stats.m_stats.m_cpu_util; - global["rx_cpu_util"] = stats.m_stats.m_rx_cpu_util; - - global["tx_bps"] = stats.m_stats.m_tx_bps; - global["rx_bps"] = stats.m_stats.m_rx_bps; - - global["tx_pps"] = stats.m_stats.m_tx_pps; - global["rx_pps"] = stats.m_stats.m_rx_pps; - - global["total_tx_pkts"] = Json::Value::UInt64(stats.m_stats.m_total_tx_pkts); - global["total_rx_pkts"] = Json::Value::UInt64(stats.m_stats.m_total_rx_pkts); - - global["total_tx_bytes"] = Json::Value::UInt64(stats.m_stats.m_total_tx_bytes); - global["total_rx_bytes"] = Json::Value::UInt64(stats.m_stats.m_total_rx_bytes); - - global["tx_rx_errors"] = Json::Value::UInt64(stats.m_stats.m_tx_rx_errors); - - for (uint8_t i = 0; i < m_port_count; i++) { - std::stringstream ss; - - ss << "port " << i; - Json::Value &port_section = global[ss.str()]; - - m_ports[i]->encode_stats(port_section); - } +capture_id_t +TrexStateless::start_capture(const CaptureFilter &filter, uint64_t limit) { + static MsgReply reply; + + reply.reset(); + + CNodeRing *ring = CMsgIns::Ins()->getCpRx()->getRingCpToDp(0); + TrexStatelessRxStartCapture *msg = new TrexStatelessRxStartCapture(filter, limit, reply); + + ring->Enqueue((CGenNode *)msg); + + capture_id_t new_id = reply.wait_for_reply(); + + return (new_id); } -/** - * generate a snapshot for publish (async publish) - * - */ -void -TrexStateless::generate_publish_snapshot(std::string &snapshot) { - Json::FastWriter writer; - Json::Value root; - - root["name"] = "trex-stateless-info"; - root["type"] = 0; - - /* stateless specific info goes here */ - root["data"] = Json::nullValue; - - snapshot = writer.write(root); +capture_id_t +TrexStateless::stop_capture(capture_id_t capture_id) { + static MsgReply reply; + + reply.reset(); + + CNodeRing *ring = CMsgIns::Ins()->getCpRx()->getRingCpToDp(0); + TrexStatelessRxStopCapture *msg = new TrexStatelessRxStopCapture(capture_id, reply); + + ring->Enqueue((CGenNode *)msg); + + capture_id_t rc = reply.wait_for_reply(); + + return (rc); } diff --git a/src/stateless/cp/trex_stateless.h b/src/stateless/cp/trex_stateless.h index 3a1a2c24..33f16ce9 100644 --- a/src/stateless/cp/trex_stateless.h +++ b/src/stateless/cp/trex_stateless.h @@ -102,6 +102,7 @@ public: * defines the TRex stateless operation mode * */ +class CaptureFilter; class TrexStateless { public: @@ -132,32 +133,21 @@ public: /** - * shutdown the server - */ - void shutdown(); - - /** - * fetch xstats names (keys of dict) - * - */ - void encode_xstats_names(Json::Value &global); - - /** - * fetch xstats values - * + * starts a capture on a 'filter' of ports + * with a limit of packets */ - void encode_xstats_values(Json::Value &global); - + capture_id_t start_capture(const CaptureFilter &filter, uint64_t limit); + /** - * fetch all the stats + * stops an active capture * */ - void encode_stats(Json::Value &global); - + capture_id_t stop_capture(capture_id_t capture_id); + /** - * generate a snapshot for publish + * shutdown the server */ - void generate_publish_snapshot(std::string &snapshot); + void shutdown(); const TrexPlatformApi * get_platform_api() { return (m_platform_api); diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 7d331c6e..9cf048b0 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -162,7 +162,7 @@ private: * trex stateless port * **************************/ -TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api) : m_dp_events(this) { +TrexStatelessPort::TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api) : m_dp_events(this), m_service_mode(port_id, api) { std::vector> core_pair_list; m_port_id = port_id; @@ -948,24 +948,6 @@ TrexStatelessPort::remove_and_delete_all_streams() { } } -void -TrexStatelessPort::start_rx_capture(const std::string &pcap_filename, uint64_t limit) { - static MsgReply reply; - - reply.reset(); - - TrexStatelessRxStartCapture *msg = new TrexStatelessRxStartCapture(m_port_id, pcap_filename, limit, reply); - send_message_to_rx((TrexStatelessCpToRxMsgBase *)msg); - - /* as below, must wait for ACK from RX core before returning ACK */ - reply.wait_for_reply(); -} - -void -TrexStatelessPort::stop_rx_capture() { - TrexStatelessCpToRxMsgBase *msg = new TrexStatelessRxStopCapture(m_port_id); - send_message_to_rx(msg); -} void TrexStatelessPort::start_rx_queue(uint64_t size) { @@ -980,18 +962,22 @@ TrexStatelessPort::start_rx_queue(uint64_t size) { this might cause the user to lose some packets from the queue */ reply.wait_for_reply(); + + m_service_mode.set_rx_queue(); } void TrexStatelessPort::stop_rx_queue() { TrexStatelessCpToRxMsgBase *msg = new TrexStatelessRxStopQueue(m_port_id); send_message_to_rx(msg); + + m_service_mode.unset_rx_queue(); } -const RXPacketBuffer * +const TrexPktBuffer * TrexStatelessPort::get_rx_queue_pkts() { - static MsgReply reply; + static MsgReply reply; reply.reset(); diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index d4ac4018..2cc1b9ca 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -26,12 +26,14 @@ limitations under the License. #include "trex_dp_port_events.h" #include "trex_stateless_rx_defs.h" #include "trex_stream.h" +#include "trex_exception.h" +#include "trex_stateless_capture.h" class TrexStatelessCpToDpMsgBase; class TrexStatelessCpToRxMsgBase; class TrexStreamsGraphObj; class TrexPortMultiplier; -class RXPacketBuffer; +class TrexPktBuffer; /** @@ -113,6 +115,56 @@ private: static const std::string g_unowned_handler; }; +/** + * enforces in/out from service mode + * + * @author imarom (1/4/2017) + */ +class TrexServiceMode { +public: + TrexServiceMode(uint8_t port_id, const TrexPlatformApi *api) { + m_is_enabled = false; + m_has_rx_queue = false; + m_port_id = port_id; + m_port_attr = api->getPortAttrObj(port_id); + } + + void enable() { + m_port_attr->set_rx_filter_mode(RX_FILTER_MODE_ALL); + m_is_enabled = true; + } + + void disable() { + if (m_has_rx_queue) { + throw TrexException("unable to disable service mode - please remove RX queue"); + } + + if (TrexStatelessCaptureMngr::getInstance().is_active(m_port_id)) { + throw TrexException("unable to disable service - an active capture on port " + std::to_string(m_port_id) + " exists"); + } + + m_port_attr->set_rx_filter_mode(RX_FILTER_MODE_HW); + m_is_enabled = false; + } + + bool is_enabled() const { + return m_is_enabled; + } + + void set_rx_queue() { + m_has_rx_queue = true; + } + + void unset_rx_queue() { + m_has_rx_queue = false; + } + +private: + bool m_is_enabled; + bool m_has_rx_queue; + TRexPortAttr *m_port_attr; + uint8_t m_port_id; +}; class AsyncStopEvent; @@ -150,7 +202,15 @@ public: RC_ERR_FAILED_TO_COMPILE_STREAMS }; - + /** + * port capture mode + */ + enum capture_mode_e { + PORT_CAPTURE_NONE = 0, + PORT_CAPTURE_RX, + PORT_CAPTURE_ALL + }; + TrexStatelessPort(uint8_t port_id, const TrexPlatformApi *api); ~TrexStatelessPort(); @@ -227,6 +287,20 @@ public: double duration, bool is_dual); + /** + * moves port to / out service mode + */ + void set_service_mode(bool enabled) { + if (enabled) { + m_service_mode.enable(); + } else { + m_service_mode.disable(); + } + } + bool is_service_mode_on() const { + return m_service_mode.is_enabled(); + } + /** * get the port state * @@ -367,16 +441,16 @@ public: /** - * enable RX capture on port + * starts capturing packets * */ - void start_rx_capture(const std::string &pcap_filename, uint64_t limit); + void start_capture(capture_mode_e mode, uint64_t limit); /** - * disable RX capture if on + * stops capturing packets * */ - void stop_rx_capture(); + void stop_capture(); /** * start RX queueing of packets @@ -398,7 +472,7 @@ public: * fetch the RX queue packets from the queue * */ - const RXPacketBuffer *get_rx_queue_pkts(); + const TrexPktBuffer *get_rx_queue_pkts(); /** * configures port for L2 mode @@ -429,7 +503,9 @@ public: } private: - + void set_service_mode_on(); + void set_service_mode_off(); + bool is_core_active(int core_id); const std::vector get_core_id_list () { @@ -514,6 +590,9 @@ private: TrexPortOwner m_owner; int m_pending_async_stop_event; + + TrexServiceMode m_service_mode; + static const uint32_t MAX_STREAMS = 20000; }; -- cgit 1.2.3-korg