diff options
author | 2016-11-30 13:00:54 +0200 | |
---|---|---|
committer | 2016-11-30 13:35:40 +0200 | |
commit | 051a334b6f57280faa9dd90eeab922fb51f3c89e (patch) | |
tree | d7b1784e99edc8b71befc7f6a84d0cedb80f7667 /src/stateless/messaging | |
parent | ba3a6e1edd85873be62f17881e4a95df7daf098d (diff) |
reply to messages
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'src/stateless/messaging')
-rw-r--r-- | src/stateless/messaging/trex_stateless_messaging.cpp | 29 | ||||
-rw-r--r-- | src/stateless/messaging/trex_stateless_messaging.h | 158 |
2 files changed, 116 insertions, 71 deletions
diff --git a/src/stateless/messaging/trex_stateless_messaging.cpp b/src/stateless/messaging/trex_stateless_messaging.cpp index cad4fe7a..53d5a87e 100644 --- a/src/stateless/messaging/trex_stateless_messaging.cpp +++ b/src/stateless/messaging/trex_stateless_messaging.cpp @@ -259,9 +259,10 @@ bool TrexStatelessRxQuit::handle (CRxCoreStateless *rx_core) { bool TrexStatelessRxStartCapture::handle(CRxCoreStateless *rx_core) { - rx_core->start_recorder(m_port_id, m_pcap_filename, m_limit, m_shared_counter); + rx_core->start_recorder(m_port_id, m_pcap_filename, m_limit); - set_reply(true); + /* mark as done */ + m_reply.set_reply(true); return true; } @@ -275,10 +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); + rx_core->start_queue(m_port_id, m_size); /* mark as done */ - set_reply(true); + m_reply.set_reply(true); return true; } @@ -292,12 +293,24 @@ 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); +bool +TrexStatelessRxQueueGetPkts::handle(CRxCoreStateless *rx_core) { + const RXPacketBuffer *pkt_buffer = rx_core->get_rx_queue_pkts(m_port_id); /* set the reply */ - set_reply(pkt_buffer); + m_reply.set_reply(pkt_buffer); return true; } + + +bool +TrexStatelessRxFeaturesToJson::handle(CRxCoreStateless *rx_core) { + Json::Value output = rx_core->get_rx_port_mngr(m_port_id).to_json(); + + /* set the reply */ + m_reply.set_reply(output); + + return true; +} + diff --git a/src/stateless/messaging/trex_stateless_messaging.h b/src/stateless/messaging/trex_stateless_messaging.h index b1d9117f..303548aa 100644 --- a/src/stateless/messaging/trex_stateless_messaging.h +++ b/src/stateless/messaging/trex_stateless_messaging.h @@ -35,6 +35,57 @@ class CFlowGenListPerThread; class RXPacketBuffer; /** + * Generic message reply object + * + * @author imarom (11/27/2016) + */ +template<typename T> class MsgReply { + +public: + + MsgReply() { + reset(); + } + + void reset() { + m_pending = true; + } + + bool is_pending() const { + return m_pending; + } + + void set_reply(const T &reply) { + m_reply = reply; + + /* before marking as done make sure all stores are committed */ + 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: failed to get reply from core"); + } + + delay(backoff_ms); + } + + return m_reply; + + } + +protected: + volatile bool m_pending; + T m_reply; +}; + + +/** * defines the base class for CP to DP messages * * @author imarom (27-Oct-15) @@ -408,52 +459,6 @@ 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); @@ -469,22 +474,25 @@ class TrexStatelessRxQuit : public TrexStatelessCpToRxMsgBase { -class TrexStatelessRxStartCapture : public TrexStatelessCpToRxMsgReply<bool> { +class TrexStatelessRxStartCapture : public TrexStatelessCpToRxMsgBase { public: - TrexStatelessRxStartCapture(uint8_t port_id, RXCaptureInfo &rx_capture_info) { + TrexStatelessRxStartCapture(uint8_t port_id, + const std::string &pcap_filename, + uint64_t limit, + MsgReply<bool> &reply) : m_reply(reply) { + m_port_id = port_id; - m_limit = rx_capture_info.m_limit; - m_pcap_filename = rx_capture_info.m_pcap_filename; - m_shared_counter = &rx_capture_info.m_shared_counter; + m_limit = limit; + m_pcap_filename = pcap_filename; } virtual bool handle(CRxCoreStateless *rx_core); private: - uint8_t m_port_id; - std::string m_pcap_filename; - uint64_t m_limit; - uint64_t *m_shared_counter; + uint8_t m_port_id; + std::string m_pcap_filename; + uint64_t m_limit; + MsgReply<bool> &m_reply; }; @@ -501,12 +509,14 @@ private: }; -class TrexStatelessRxStartQueue : public TrexStatelessCpToRxMsgReply<bool> { +class TrexStatelessRxStartQueue : public TrexStatelessCpToRxMsgBase { public: - TrexStatelessRxStartQueue(uint8_t port_id, RXQueueInfo &rx_queue_info) { + TrexStatelessRxStartQueue(uint8_t port_id, + uint64_t size, + MsgReply<bool> &reply) : m_reply(reply) { + m_port_id = port_id; - m_size = rx_queue_info.m_size; - m_shared_counter = &rx_queue_info.m_shared_counter; + m_size = size; } virtual bool handle(CRxCoreStateless *rx_core); @@ -514,7 +524,7 @@ public: private: uint8_t m_port_id; uint64_t m_size; - uint64_t *m_shared_counter; + MsgReply<bool> &m_reply; }; @@ -532,10 +542,10 @@ private: -class TrexStatelessRxQueueGetPkts : public TrexStatelessCpToRxMsgReply<RXPacketBuffer *> { +class TrexStatelessRxQueueGetPkts : public TrexStatelessCpToRxMsgBase { public: - TrexStatelessRxQueueGetPkts(uint8_t port_id) { + TrexStatelessRxQueueGetPkts(uint8_t port_id, MsgReply<const RXPacketBuffer *> &reply) : m_reply(reply) { m_port_id = port_id; } @@ -546,8 +556,30 @@ public: virtual bool handle(CRxCoreStateless *rx_core); private: - uint8_t m_port_id; + uint8_t m_port_id; + MsgReply<const RXPacketBuffer *> &m_reply; + }; +/** + * a request from RX core to dump to Json the RX features + */ +class TrexStatelessRxFeaturesToJson : public TrexStatelessCpToRxMsgBase { +public: + + TrexStatelessRxFeaturesToJson(uint8_t port_id, MsgReply<Json::Value> &reply) : m_reply(reply) { + m_port_id = port_id; + } + + /** + * virtual function to handle a message + * + */ + virtual bool handle(CRxCoreStateless *rx_core); + +private: + uint8_t m_port_id; + MsgReply<Json::Value> &m_reply; +}; #endif /* __TREX_STATELESS_MESSAGING_H__ */ |