diff options
author | 2017-01-24 14:11:32 +0200 | |
---|---|---|
committer | 2017-01-24 14:11:32 +0200 | |
commit | 19df06349d311377ca1ef10f91ef1f786b41418b (patch) | |
tree | 3c5fa2e76fd5dd0dff370df7013e757e289b1ac5 /src/stateless/common | |
parent | 418fd3d0a7169f2d8934e8be82d11e1a388d681c (diff) |
code review cleanups - C++
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'src/stateless/common')
-rw-r--r-- | src/stateless/common/trex_stateless_pkt.cpp | 18 | ||||
-rw-r--r-- | src/stateless/common/trex_stateless_pkt.h | 58 |
2 files changed, 60 insertions, 16 deletions
diff --git a/src/stateless/common/trex_stateless_pkt.cpp b/src/stateless/common/trex_stateless_pkt.cpp index f7d47ec0..14c14462 100644 --- a/src/stateless/common/trex_stateless_pkt.cpp +++ b/src/stateless/common/trex_stateless_pkt.cpp @@ -34,7 +34,7 @@ * * @return uint8_t* */ -void copy_mbuf(uint8_t *dest, const rte_mbuf_t *m) { +void mbuf_to_buffer(uint8_t *dest, const rte_mbuf_t *m) { int index = 0; for (const rte_mbuf_t *it = m; it != NULL; it = it->next) { @@ -55,7 +55,7 @@ TrexPkt::TrexPkt(const rte_mbuf_t *m, int port, origin_e origin, uint64_t index) m_raw = new uint8_t[m_size]; /* copy data */ - copy_mbuf(m_raw, m); + mbuf_to_buffer(m_raw, m); /* generate a packet timestamp */ m_timestamp = now_sec(); @@ -76,6 +76,12 @@ TrexPkt::TrexPkt(const TrexPkt &other) { m_index = other.m_index; } + +/************************************** + * TRex packet buffer + * + *************************************/ + TrexPktBuffer::TrexPktBuffer(uint64_t size, mode_e mode) { m_mode = mode; m_buffer = nullptr; @@ -117,13 +123,14 @@ TrexPktBuffer::push(const rte_mbuf_t *m, int port, TrexPkt::origin_e origin, uin /* push packet */ m_buffer[m_head] = new TrexPkt(m, port, origin, pkt_index); m_bytes += m_buffer[m_head]->get_size(); - - m_head = next(m_head); + /* advance */ + m_head = next(m_head); } /** * packet will be handled internally + * packet pointer is invalid after this call */ void TrexPktBuffer::push(const TrexPkt *pkt) { @@ -140,6 +147,8 @@ TrexPktBuffer::push(const TrexPkt *pkt) { /* push packet */ m_buffer[m_head] = pkt; + m_bytes += pkt->get_size(); + m_head = next(m_head); } @@ -179,4 +188,3 @@ TrexPktBuffer::to_json() const { return output; } - diff --git a/src/stateless/common/trex_stateless_pkt.h b/src/stateless/common/trex_stateless_pkt.h index 1b6bd2f8..573f4950 100644 --- a/src/stateless/common/trex_stateless_pkt.h +++ b/src/stateless/common/trex_stateless_pkt.h @@ -32,33 +32,45 @@ /** * copies MBUF to a flat buffer * - * @author imarom (1/1/2017) - * - * @param dest - * @param m */ -void copy_mbuf(uint8_t *dest, const rte_mbuf_t *m); +void mbuf_to_buffer(uint8_t *dest, const rte_mbuf_t *m); -/** - * describes a single saved packet +/************************************** + * TRex packet * - */ + *************************************/ class TrexPkt { public: + /** + * origin of the created packet + */ enum origin_e { ORIGIN_NONE = 1, ORIGIN_TX, ORIGIN_RX }; + /** + * generate a packet from MBUF + */ TrexPkt(const rte_mbuf_t *m, int port = -1, origin_e origin = ORIGIN_NONE, uint64_t index = 0); + + /** + * duplicate an existing packet + */ TrexPkt(const TrexPkt &other); + + /** + * sets a packet index + * used by a buffer of packets + */ void set_index(uint64_t index) { m_index = index; } + /* slow path and also RVO - pass by value is ok */ Json::Value to_json() const { Json::Value output; @@ -115,6 +127,10 @@ private: }; +/************************************** + * TRex packet buffer + * + *************************************/ class TrexPktBuffer { public: @@ -136,10 +152,23 @@ public: ~TrexPktBuffer(); /** - * push a packet to the buffer - * + * push a packet to the buffer + * packet will be generated from a MBUF + * + */ + void push(const rte_mbuf_t *m, + int port = -1, + TrexPkt::origin_e origin = TrexPkt::ORIGIN_NONE, + uint64_t pkt_index = 0); + + /** + * push an existing packet structure + * packet will *not* be duplicated + * + * after calling this function + * the packet is no longer usable + * from caller prespective */ - void push(const rte_mbuf_t *m, int port = -1, TrexPkt::origin_e origin = TrexPkt::ORIGIN_NONE, uint64_t pkt_index = 0); void push(const TrexPkt *pkt); /** @@ -171,6 +200,10 @@ public: return (m_size - 1); } + /** + * see mode_e + * + */ mode_e get_mode() const { return m_mode; } @@ -180,6 +213,9 @@ public: */ uint32_t get_element_count() const; + /** + * current bytes holded by the buffer + */ uint32_t get_bytes() const { return m_bytes; } |