summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2017-02-13 08:43:39 +0200
committerimarom <imarom@cisco.com>2017-02-16 15:20:23 +0200
commitd9e19ba46d441b8e208f223add5a612183e5157c (patch)
tree53ea22e98cc577e20ea67ad3b3a92032eb72a8d2 /src
parent8ed3bb7219e4548031d3e07d929d9d5e1f6840af (diff)
TX feature - draft
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'src')
-rw-r--r--src/main_dpdk.cpp5
-rw-r--r--src/stateless/rx/trex_stateless_capture.cpp38
-rw-r--r--src/stateless/rx/trex_stateless_capture.h65
3 files changed, 42 insertions, 66 deletions
diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp
index de825b34..f227b2d8 100644
--- a/src/main_dpdk.cpp
+++ b/src/main_dpdk.cpp
@@ -2310,6 +2310,9 @@ int CCoreEthIF::send_pkt(CCorePerPort * lp_port,
uint16_t len = lp_port->m_len;
lp_port->m_table[len]=m;
len++;
+
+ TrexStatelessCaptureMngr::getInstance().handle_pkt_tx(m, lp_port->m_port->get_port_id());
+
/* enough pkts to be sent */
if (unlikely(len == MAX_PKT_BURST)) {
send_burst(lp_port, MAX_PKT_BURST,lp_stats);
@@ -2324,6 +2327,8 @@ int CCoreEthIF::send_pkt_lat(CCorePerPort *lp_port, rte_mbuf_t *m, CVirtualIFPer
// We allow sending only from first core of each port. This is serious internal bug otherwise.
assert(lp_port->m_tx_queue_id_lat != INVALID_Q_ID);
+ TrexStatelessCaptureMngr::getInstance().handle_pkt_tx(m, lp_port->m_port->get_port_id());
+
int ret = lp_port->m_port->tx_burst(lp_port->m_tx_queue_id_lat, &m, 1);
#ifdef DELAY_IF_NEEDED
diff --git a/src/stateless/rx/trex_stateless_capture.cpp b/src/stateless/rx/trex_stateless_capture.cpp
index bf7623d5..d9813cac 100644
--- a/src/stateless/rx/trex_stateless_capture.cpp
+++ b/src/stateless/rx/trex_stateless_capture.cpp
@@ -45,36 +45,18 @@ TrexStatelessCapture::~TrexStatelessCapture() {
}
void
-TrexStatelessCapture::handle_pkt_tx(const TrexPkt *pkt) {
+TrexStatelessCapture::handle_pkt(const rte_mbuf_t *m, int port, TrexPkt::origin_e origin) {
if (m_state != STATE_ACTIVE) {
return;
}
/* if not in filter - back off */
- if (!m_filter.in_filter(pkt)) {
+ if (!m_filter.in_x(port, origin)) {
return;
}
- if (pkt->get_ts() < m_start_ts) {
- return;
- }
-
- m_pkt_buffer->push(pkt, ++m_pkt_index);
-}
-
-void
-TrexStatelessCapture::handle_pkt_rx(const rte_mbuf_t *m, int port) {
-
- if (m_state != STATE_ACTIVE) {
- return;
- }
-
- if (!m_filter.in_rx(port)) {
- return;
- }
-
- m_pkt_buffer->push(m, port, TrexPkt::ORIGIN_RX, ++m_pkt_index);
+ m_pkt_buffer->push(m, port, origin, ++m_pkt_index);
}
@@ -266,16 +248,11 @@ TrexStatelessCaptureMngr::reset() {
}
void
-TrexStatelessCaptureMngr::handle_pkt_tx_slow_path(const TrexPkt *pkt) {
- for (TrexStatelessCapture *capture : m_captures) {
- capture->handle_pkt_tx(pkt);
- }
-}
-
-void
-TrexStatelessCaptureMngr::handle_pkt_rx_slow_path(const rte_mbuf_t *m, int port) {
+TrexStatelessCaptureMngr::handle_pkt_slow_path(const rte_mbuf_t *m, int port, TrexPkt::origin_e origin) {
+ std::unique_lock<std::mutex> lock(m_lock);
+
for (TrexStatelessCapture *capture : m_captures) {
- capture->handle_pkt_rx(m, port);
+ capture->handle_pkt(m, port, origin);
}
}
@@ -290,3 +267,4 @@ TrexStatelessCaptureMngr::to_json() const {
return lst;
}
+TrexStatelessCaptureMngr TrexStatelessCaptureMngr::g_instance;
diff --git a/src/stateless/rx/trex_stateless_capture.h b/src/stateless/rx/trex_stateless_capture.h
index e4a2e632..6288ac56 100644
--- a/src/stateless/rx/trex_stateless_capture.h
+++ b/src/stateless/rx/trex_stateless_capture.h
@@ -23,6 +23,7 @@ limitations under the License.
#include <stdint.h>
#include <assert.h>
+#include <mutex>
#include "trex_stateless_pkt.h"
#include "trex_stateless_capture_rc.h"
@@ -59,17 +60,12 @@ public:
add_rx(port_id);
}
- bool in_filter(const TrexPkt *pkt) {
- switch (pkt->get_origin()) {
- case TrexPkt::ORIGIN_TX:
- return in_tx(pkt->get_port());
-
- case TrexPkt::ORIGIN_RX:
- return in_rx(pkt->get_port());
-
- default:
- return false;
- }
+ bool in_x(uint8_t port_id, TrexPkt::origin_e origin) {
+ return (
+ ( (origin == TrexPkt::ORIGIN_RX) && (in_rx(port_id)) )
+ ||
+ ( (origin == TrexPkt::ORIGIN_TX) && (in_tx(port_id)) )
+ );
}
bool in_rx(uint8_t port_id) const {
@@ -133,14 +129,9 @@ public:
~TrexStatelessCapture();
/**
- * handles a packet from the TX side
- */
- void handle_pkt_tx(const TrexPkt *pkt);
-
- /**
- * handles a packet from the RX side
+ * handles a packet
*/
- void handle_pkt_rx(const rte_mbuf_t *m, int port);
+ void handle_pkt(const rte_mbuf_t *m, int port, TrexPkt::origin_e origin);
uint64_t get_id() const {
@@ -199,10 +190,9 @@ class TrexStatelessCaptureMngr {
public:
+ static TrexStatelessCaptureMngr g_instance;
static TrexStatelessCaptureMngr& getInstance() {
- static TrexStatelessCaptureMngr instance;
-
- return instance;
+ return g_instance;
}
@@ -257,27 +247,27 @@ public:
}
/**
- * handle packet from TX
+ * handle packet on TX side
*/
- void handle_pkt_tx(const TrexPkt *pkt) {
- if (!m_global_filter.in_filter(pkt)) {
- return;
+ inline void handle_pkt_tx(const rte_mbuf_t *m, int port) {
+
+ /* fast bail out IF */
+ if (unlikely(m_global_filter.in_tx(port))) {
+ handle_pkt_slow_path(m, port, TrexPkt::ORIGIN_TX);
}
- handle_pkt_tx_slow_path(pkt);
}
/**
- * handle packet from RX
+ * handle packet on RX side
*/
- void handle_pkt_rx(const rte_mbuf_t *m, int port) {
- /* fast path - check the global filter */
- if (!m_global_filter.in_rx(port)) {
- return;
+ inline void handle_pkt_rx(const rte_mbuf_t *m, int port) {
+
+ /* fast bail out IF */
+ if (unlikely(m_global_filter.in_rx(port))) {
+ handle_pkt_slow_path(m, port, TrexPkt::ORIGIN_RX);
}
- /* slow path */
- handle_pkt_rx_slow_path(m, port);
}
Json::Value to_json() const;
@@ -293,9 +283,8 @@ private:
TrexStatelessCapture * lookup(capture_id_t capture_id);
int lookup_index(capture_id_t capture_id);
- void handle_pkt_rx_slow_path(const rte_mbuf_t *m, int port);
- void handle_pkt_tx_slow_path(const TrexPkt *pkt);
-
+ void handle_pkt_slow_path(const rte_mbuf_t *m, int port, TrexPkt::origin_e origin) __attribute__ ((noinline));
+
void update_global_filter();
std::vector<TrexStatelessCapture *> m_captures;
@@ -305,7 +294,11 @@ private:
/* a union of all the filters curently active */
CaptureFilter m_global_filter;
+ /* slow path lock*/
+ std::mutex m_lock;
+
static const int MAX_CAPTURE_SIZE = 10;
+
};
#endif /* __TREX_STATELESS_CAPTURE_H__ */