if not rc:
raise STLError(rc)
- return {'id': rc.data()['capture_id'], 'ts': rc.data()['ts']}
+ return {'id': rc.data()['capture_id'], 'ts': rc.data()['start_ts']}
/* populate the filter */
for (int i = 0; i < tx_json.size(); i++) {
uint8_t tx_port = parse_byte(tx_json, i, result);
+ validate_port_id(tx_port, result);
+
filter.add_tx(tx_port);
ports.insert(tx_port);
}
for (int i = 0; i < rx_json.size(); i++) {
uint8_t rx_port = parse_byte(rx_json, i, result);
+ validate_port_id(rx_port, result);
+
filter.add_rx(rx_port);
ports.insert(rx_port);
}
static MsgReply<TrexCaptureRCStart> reply;
reply.reset();
+ /* send a start message to RX core */
TrexStatelessRxCaptureStart *start_msg = new TrexStatelessRxCaptureStart(filter, limit, reply);
get_stateless_obj()->send_msg_to_rx(start_msg);
}
result["result"]["capture_id"] = rc.get_new_id();
- result["result"]["ts"] = now_sec();
+ result["result"]["start_ts"] = rc.get_start_ts();
}
/**
*
* @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) {
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();
m_index = other.m_index;
}
+
+/**************************************
+ * TRex packet buffer
+ *
+ *************************************/
+
TrexPktBuffer::TrexPktBuffer(uint64_t size, mode_e mode) {
m_mode = mode;
m_buffer = nullptr;
/* 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) {
/* push packet */
m_buffer[m_head] = pkt;
+ m_bytes += pkt->get_size();
+
m_head = next(m_head);
}
return output;
}
-
/**
* 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;
};
+/**************************************
+ * TRex packet buffer
+ *
+ *************************************/
class TrexPktBuffer {
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);
/**
return (m_size - 1);
}
+ /**
+ * see mode_e
+ *
+ */
mode_e get_mode() const {
return m_mode;
}
*/
uint32_t get_element_count() const;
+ /**
+ * current bytes holded by the buffer
+ */
uint32_t get_bytes() const {
return m_bytes;
}
int new_id = m_id_counter++;
- TrexStatelessCapture *new_buffer = new TrexStatelessCapture(new_id, limit, filter);
- m_captures.push_back(new_buffer);
+ TrexStatelessCapture *new_capture = new TrexStatelessCapture(new_id, limit, filter);
+ m_captures.push_back(new_capture);
/* update global filter */
update_global_filter();
/* result */
- rc.set_new_id(new_id);
+ rc.set_rc(new_id, new_capture->get_start_ts());
}
void
}
capture->stop();
- rc.set_count(capture->get_pkt_count());
+ rc.set_rc(capture->get_pkt_count());
}
void
class TrexCaptureRCStart : public TrexCaptureRC {
public:
- void set_new_id(capture_id_t new_id) {
- m_capture_id = new_id;
- m_rc = RC_OK;
+ void set_rc(capture_id_t new_id, dsec_t start_ts) {
+ m_capture_id = new_id;
+ m_start_ts = start_ts;
+ m_rc = RC_OK;
+
}
capture_id_t get_new_id() const {
return m_capture_id;
}
+ dsec_t get_start_ts() const {
+ return m_start_ts;
+ }
+
private:
capture_id_t m_capture_id;
+ dsec_t m_start_ts;
};
class TrexCaptureRCStop : public TrexCaptureRC {
public:
- void set_count(uint32_t pkt_count) {
+ void set_rc(uint32_t pkt_count) {
m_pkt_count = pkt_count;
m_rc = RC_OK;
}
}
/* copy data */
- copy_mbuf(dest, m);
+ mbuf_to_buffer(dest, m);
return clone_mbuf;
}