summaryrefslogtreecommitdiffstats
path: root/src/stateless/common
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2017-01-25 13:54:51 +0200
committerimarom <imarom@cisco.com>2017-01-25 13:54:51 +0200
commit3689edf311778c8cb921db61f293db6cd43a9b14 (patch)
treecf683e96d5de5cd1218060d6630f97c4052e1b62 /src/stateless/common
parent19df06349d311377ca1ef10f91ef1f786b41418b (diff)
capture - personal code review
Signed-off-by: imarom <imarom@cisco.com>
Diffstat (limited to 'src/stateless/common')
-rw-r--r--src/stateless/common/trex_stateless_pkt.cpp43
-rw-r--r--src/stateless/common/trex_stateless_pkt.h23
2 files changed, 51 insertions, 15 deletions
diff --git a/src/stateless/common/trex_stateless_pkt.cpp b/src/stateless/common/trex_stateless_pkt.cpp
index 14c14462..43cbbe1c 100644
--- a/src/stateless/common/trex_stateless_pkt.cpp
+++ b/src/stateless/common/trex_stateless_pkt.cpp
@@ -120,12 +120,7 @@ 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();
-
- /* advance */
- m_head = next(m_head);
+ push_internal(new TrexPkt(m, port, origin, pkt_index));
}
/**
@@ -133,19 +128,32 @@ TrexPktBuffer::push(const rte_mbuf_t *m, int port, TrexPkt::origin_e origin, uin
* packet pointer is invalid after this call
*/
void
-TrexPktBuffer::push(const TrexPkt *pkt) {
+TrexPktBuffer::push(const TrexPkt *pkt, uint64_t pkt_index) {
/* if full - decide by the policy */
if (is_full()) {
if (m_mode == MODE_DROP_HEAD) {
delete pop();
} else {
/* drop the tail (current packet) */
- delete pkt;
return;
}
}
- /* push packet */
+ /* duplicate packet */
+ TrexPkt *dup = new TrexPkt(*pkt);
+
+ /* update packet index if given */
+ if (pkt_index != 0) {
+ dup->set_index(pkt_index);
+ }
+
+ push_internal(dup);
+}
+
+
+void
+TrexPktBuffer::push_internal(const TrexPkt *pkt) {
+ /* push the packet */
m_buffer[m_head] = pkt;
m_bytes += pkt->get_size();
@@ -188,3 +196,20 @@ TrexPktBuffer::to_json() const {
return output;
}
+TrexPktBuffer *
+TrexPktBuffer::pop_n(uint32_t count) {
+ /* can't pop more than total */
+ assert(count <= get_element_count());
+
+ // TODO: consider returning NULL if no packets exists
+ // to avoid mallocing
+
+ TrexPktBuffer *partial = new TrexPktBuffer(count);
+
+ for (int i = 0; i < count; i++) {
+ const TrexPkt *pkt = pop();
+ partial->push_internal(pkt);
+ }
+
+ return partial;
+}
diff --git a/src/stateless/common/trex_stateless_pkt.h b/src/stateless/common/trex_stateless_pkt.h
index 573f4950..f44355dc 100644
--- a/src/stateless/common/trex_stateless_pkt.h
+++ b/src/stateless/common/trex_stateless_pkt.h
@@ -70,6 +70,9 @@ public:
m_index = index;
}
+ uint64_t get_index() const {
+ return m_index;
+ }
/* slow path and also RVO - pass by value is ok */
Json::Value to_json() const {
@@ -163,13 +166,10 @@ public:
/**
* push an existing packet structure
- * packet will *not* be duplicated
- *
- * after calling this function
- * the packet is no longer usable
- * from caller prespective
+ * packet will be duplicated
+ * if pkt_index is non zero - it will be updated
*/
- void push(const TrexPkt *pkt);
+ void push(const TrexPkt *pkt, uint64_t pkt_index = 0);
/**
* pops a packet from the buffer
@@ -178,6 +178,15 @@ public:
const TrexPkt * pop();
/**
+ * pops N packets from the buffer
+ * N must be <= get_element_count()
+ *
+ * returns a new buffer
+ */
+ TrexPktBuffer * pop_n(uint32_t count);
+
+
+ /**
* generate a JSON output of the queue
*
*/
@@ -225,6 +234,8 @@ private:
return ( (v + 1) % m_size );
}
+ void push_internal(const TrexPkt *pkt);
+
mode_e m_mode;
int m_head;
int m_tail;