From f5f92b068561dcdf8414494e5daf6d285ea24135 Mon Sep 17 00:00:00 2001 From: imarom Date: Sun, 22 Jan 2017 15:36:20 +0200 Subject: few tweaks Signed-off-by: imarom --- src/rpc-server/commands/trex_rpc_cmd_general.cpp | 5 +++-- src/stateless/rx/trex_stateless_capture.cpp | 19 ++++++++++++++----- src/stateless/rx/trex_stateless_capture.h | 24 ++++++++++++++++++------ 3 files changed, 35 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index be261fbb..55249fc8 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -994,8 +994,9 @@ TrexRpcCmdCapture::parse_cmd_fetch(const Json::Value ¶ms, Json::Value &resul const TrexPktBuffer *pkt_buffer = rc.get_pkt_buffer(); - result["result"]["pending"] = rc.get_pending(); - result["result"]["pkts"] = pkt_buffer->to_json(); + result["result"]["pending"] = rc.get_pending(); + result["result"]["start_ts"] = rc.get_start_ts(); + result["result"]["pkts"] = pkt_buffer->to_json(); /* delete the buffer */ delete pkt_buffer; diff --git a/src/stateless/rx/trex_stateless_capture.cpp b/src/stateless/rx/trex_stateless_capture.cpp index 5d43cede..f0d4e806 100644 --- a/src/stateless/rx/trex_stateless_capture.cpp +++ b/src/stateless/rx/trex_stateless_capture.cpp @@ -26,6 +26,8 @@ TrexStatelessCapture::TrexStatelessCapture(capture_id_t id, uint64_t limit, cons m_pkt_buffer = new TrexPktBuffer(limit, TrexPktBuffer::MODE_DROP_TAIL); m_filter = filter; m_state = STATE_ACTIVE; + m_start_ts = now_sec(); + m_pkt_index = 0; } TrexStatelessCapture::~TrexStatelessCapture() { @@ -35,7 +37,7 @@ TrexStatelessCapture::~TrexStatelessCapture() { } void -TrexStatelessCapture::handle_pkt_tx(const TrexPkt *pkt) { +TrexStatelessCapture::handle_pkt_tx(TrexPkt *pkt) { if (m_state != STATE_ACTIVE) { delete pkt; @@ -48,6 +50,12 @@ TrexStatelessCapture::handle_pkt_tx(const TrexPkt *pkt) { return; } + if (pkt->get_ts() < m_start_ts) { + delete pkt; + return; + } + + pkt->set_index(++m_pkt_index); m_pkt_buffer->push(pkt); } @@ -62,7 +70,7 @@ TrexStatelessCapture::handle_pkt_rx(const rte_mbuf_t *m, int port) { return; } - m_pkt_buffer->push(m, port, TrexPkt::ORIGIN_RX); + m_pkt_buffer->push(m, port, TrexPkt::ORIGIN_RX, ++m_pkt_index); } @@ -110,7 +118,8 @@ TrexStatelessCapture::fetch(uint32_t pkt_limit, uint32_t &pending) { partial->push(pkt); } - pending = m_pkt_buffer->get_element_count(); + pending = m_pkt_buffer->get_element_count(); + return partial; } @@ -181,7 +190,7 @@ TrexStatelessCaptureMngr::fetch(capture_id_t capture_id, uint32_t pkt_limit, Tre uint32_t pending = 0; TrexPktBuffer *pkt_buffer = capture->fetch(pkt_limit, pending); - rc.set_pkt_buffer(pkt_buffer, pending); + rc.set_pkt_buffer(pkt_buffer, pending, capture->get_start_ts()); } void @@ -223,7 +232,7 @@ TrexStatelessCaptureMngr::reset() { } void -TrexStatelessCaptureMngr::handle_pkt_tx(const TrexPkt *pkt) { +TrexStatelessCaptureMngr::handle_pkt_tx(TrexPkt *pkt) { for (TrexStatelessCapture *capture : m_captures) { capture->handle_pkt_tx(pkt); } diff --git a/src/stateless/rx/trex_stateless_capture.h b/src/stateless/rx/trex_stateless_capture.h index 4a9efea7..bc1b88c5 100644 --- a/src/stateless/rx/trex_stateless_capture.h +++ b/src/stateless/rx/trex_stateless_capture.h @@ -121,10 +121,11 @@ public: m_pending = 0; } - void set_pkt_buffer(const TrexPktBuffer *pkt_buffer, uint32_t pending) { - m_pkt_buffer = pkt_buffer; - m_pending = pending; - m_rc = RC_OK; + void set_pkt_buffer(const TrexPktBuffer *pkt_buffer, uint32_t pending, dsec_t start_ts) { + m_pkt_buffer = pkt_buffer; + m_pending = pending; + m_start_ts = start_ts; + m_rc = RC_OK; } const TrexPktBuffer *get_pkt_buffer() const { @@ -135,9 +136,14 @@ public: return m_pending; } + dsec_t get_start_ts() const { + return m_start_ts; + } + private: const TrexPktBuffer *m_pkt_buffer; uint32_t m_pending; + dsec_t m_start_ts; }; class TrexCaptureRCRemove : public TrexCaptureRC { @@ -245,7 +251,7 @@ public: TrexStatelessCapture(capture_id_t id, uint64_t limit, const CaptureFilter &filter); - void handle_pkt_tx(const TrexPkt *pkt); + void handle_pkt_tx(TrexPkt *pkt); void handle_pkt_rx(const rte_mbuf_t *m, int port); ~TrexStatelessCapture(); @@ -274,11 +280,17 @@ public: return m_pkt_buffer->get_element_count(); } + dsec_t get_start_ts() const { + return m_start_ts; + } + private: state_e m_state; TrexPktBuffer *m_pkt_buffer; + dsec_t m_start_ts; CaptureFilter m_filter; uint64_t m_id; + uint64_t m_pkt_index; }; class TrexStatelessCaptureMngr { @@ -341,7 +353,7 @@ public: /** * handle packet from TX */ - void handle_pkt_tx(const TrexPkt *pkt); + void handle_pkt_tx(TrexPkt *pkt); /** * handle packet from RX -- cgit 1.2.3-korg