diff options
Diffstat (limited to 'src/stateless/messaging')
-rw-r--r-- | src/stateless/messaging/trex_stateless_messaging.cpp | 15 | ||||
-rw-r--r-- | src/stateless/messaging/trex_stateless_messaging.h | 100 |
2 files changed, 66 insertions, 49 deletions
diff --git a/src/stateless/messaging/trex_stateless_messaging.cpp b/src/stateless/messaging/trex_stateless_messaging.cpp index a8fb7ba9..cad4fe7a 100644 --- a/src/stateless/messaging/trex_stateless_messaging.cpp +++ b/src/stateless/messaging/trex_stateless_messaging.cpp @@ -259,14 +259,16 @@ bool TrexStatelessRxQuit::handle (CRxCoreStateless *rx_core) { bool TrexStatelessRxStartCapture::handle(CRxCoreStateless *rx_core) { - rx_core->start_capture(m_port_id, m_pcap_filename, m_limit, m_shared_counter); + rx_core->start_recorder(m_port_id, m_pcap_filename, m_limit, m_shared_counter); + set_reply(true); + return true; } bool TrexStatelessRxStopCapture::handle(CRxCoreStateless *rx_core) { - rx_core->stop_capture(m_port_id); + rx_core->stop_recorder(m_port_id); return true; } @@ -274,7 +276,10 @@ TrexStatelessRxStopCapture::handle(CRxCoreStateless *rx_core) { bool TrexStatelessRxStartQueue::handle(CRxCoreStateless *rx_core) { rx_core->start_queue(m_port_id, m_size, m_shared_counter); - + + /* mark as done */ + set_reply(true); + return true; } @@ -290,7 +295,9 @@ TrexStatelessRxStopQueue::handle(CRxCoreStateless *rx_core) { bool TrexStatelessRxQueueGetPkts::handle(CRxCoreStateless *rx_core) { RXPacketBuffer *pkt_buffer = rx_core->get_rx_queue_pkts(m_port_id); assert(pkt_buffer); - m_reply.set(pkt_buffer); + + /* set the reply */ + set_reply(pkt_buffer); return true; } diff --git a/src/stateless/messaging/trex_stateless_messaging.h b/src/stateless/messaging/trex_stateless_messaging.h index ed2ec90e..b1d9117f 100644 --- a/src/stateless/messaging/trex_stateless_messaging.h +++ b/src/stateless/messaging/trex_stateless_messaging.h @@ -408,6 +408,53 @@ public: }; +/** + * defines the base class for CP to RX with reply + * + * @author imarom (11/27/2016) + */ +template<typename T> class TrexStatelessCpToRxMsgReply : public TrexStatelessCpToRxMsgBase { + +public: + + TrexStatelessCpToRxMsgReply() { + m_pending = true; + } + + bool is_pending() const { + return m_pending; + } + + void set_reply(const T &reply) { + m_reply = reply; + + /* before marking as done - memory fence */ + asm volatile("mfence" ::: "memory"); + m_pending = false; + } + + T wait_for_reply(int timeout_ms = 100, int backoff_ms = 1) { + int guard = timeout_ms; + + while (is_pending()) { + guard -= backoff_ms; + if (guard < 0) { + throw TrexException("timeout: RX core has failed to reply"); + } + + delay(backoff_ms); + } + + return m_reply; + + } + +protected: + volatile bool m_pending; + T m_reply; +}; + + class TrexStatelessRxEnableLatency : public TrexStatelessCpToRxMsgBase { bool handle (CRxCoreStateless *rx_core); }; @@ -421,7 +468,8 @@ class TrexStatelessRxQuit : public TrexStatelessCpToRxMsgBase { }; -class TrexStatelessRxStartCapture : public TrexStatelessCpToRxMsgBase { + +class TrexStatelessRxStartCapture : public TrexStatelessCpToRxMsgReply<bool> { public: TrexStatelessRxStartCapture(uint8_t port_id, RXCaptureInfo &rx_capture_info) { m_port_id = port_id; @@ -452,7 +500,8 @@ private: uint8_t m_port_id; }; -class TrexStatelessRxStartQueue : public TrexStatelessCpToRxMsgBase { + +class TrexStatelessRxStartQueue : public TrexStatelessCpToRxMsgReply<bool> { public: TrexStatelessRxStartQueue(uint8_t port_id, RXQueueInfo &rx_queue_info) { m_port_id = port_id; @@ -468,6 +517,7 @@ private: uint64_t *m_shared_counter; }; + class TrexStatelessRxStopQueue : public TrexStatelessCpToRxMsgBase { public: TrexStatelessRxStopQueue(uint8_t port_id) { @@ -481,50 +531,11 @@ private: }; -template<typename T> class TrexStatelessMsgReply { -public: - TrexStatelessMsgReply() { - m_pending = true; - } - - bool is_pending() const { - return m_pending; - } - - void set(T reply) { - m_reply = reply; - - /* before marking as done - memory fence */ - asm volatile("mfence" ::: "memory"); - m_pending = false; - } - - T wait_for_reply(int timeout_ms = 100, int backoff_ms = 1) { - int guard = timeout_ms; - - while (is_pending()) { - guard -= backoff_ms; - if (guard < 0) { - throw TrexException("timeout: RX core has failed to reply"); - } - - delay(backoff_ms); - - } - return m_reply; - - } -private: - bool m_pending; - T m_reply; -}; - - -class TrexStatelessRxQueueGetPkts : public TrexStatelessCpToRxMsgBase { +class TrexStatelessRxQueueGetPkts : public TrexStatelessCpToRxMsgReply<RXPacketBuffer *> { public: - TrexStatelessRxQueueGetPkts(uint8_t port_id, TrexStatelessMsgReply<RXPacketBuffer *> &reply) : m_reply(reply) { + TrexStatelessRxQueueGetPkts(uint8_t port_id) { m_port_id = port_id; } @@ -535,8 +546,7 @@ public: virtual bool handle(CRxCoreStateless *rx_core); private: - uint8_t m_port_id; - TrexStatelessMsgReply<RXPacketBuffer*> &m_reply; + uint8_t m_port_id; }; |