code review cleanups - C++ 76/5276/1
authorimarom <[email protected]>
Tue, 24 Jan 2017 12:11:32 +0000 (14:11 +0200)
committerimarom <[email protected]>
Tue, 24 Jan 2017 12:11:32 +0000 (14:11 +0200)
Signed-off-by: imarom <[email protected]>
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
src/rpc-server/commands/trex_rpc_cmd_general.cpp
src/stateless/common/trex_stateless_pkt.cpp
src/stateless/common/trex_stateless_pkt.h
src/stateless/rx/trex_stateless_capture.cpp
src/stateless/rx/trex_stateless_capture.h
src/stateless/rx/trex_stateless_rx_port_mngr.cpp

index f743210..d81765c 100755 (executable)
@@ -3049,7 +3049,7 @@ class STLClient(object):
         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']}
 
 
         
index 6f0ab09..c20c77d 100644 (file)
@@ -901,12 +901,16 @@ TrexRpcCmdCapture::parse_cmd_start(const Json::Value &params, Json::Value &resul
     /* 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);
     }
@@ -922,6 +926,7 @@ TrexRpcCmdCapture::parse_cmd_start(const Json::Value &params, Json::Value &resul
     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);
     
@@ -931,7 +936,7 @@ TrexRpcCmdCapture::parse_cmd_start(const Json::Value &params, Json::Value &resul
     }
     
     result["result"]["capture_id"] = rc.get_new_id();
-    result["result"]["ts"]         = now_sec();
+    result["result"]["start_ts"]   = rc.get_start_ts();
 }
 
 /**
index f7d47ec..14c1446 100644 (file)
@@ -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;
 }
 
-
index 1b6bd2f..573f495 100644 (file)
 /**
  * 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; 
     }
index f0d4e80..7b02044 100644 (file)
@@ -157,14 +157,14 @@ TrexStatelessCaptureMngr::start(const CaptureFilter &filter, uint64_t limit, Tre
     
 
     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
@@ -176,7 +176,7 @@ TrexStatelessCaptureMngr::stop(capture_id_t capture_id, TrexCaptureRCStop &rc) {
     }
     
     capture->stop();
-    rc.set_count(capture->get_pkt_count());
+    rc.set_rc(capture->get_pkt_count());
 }
 
 void
index 0f98fd9..852aee2 100644 (file)
@@ -83,23 +83,30 @@ public:
 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;
     }
index ede8606..b01665e 100644 (file)
@@ -492,7 +492,7 @@ RXServer::duplicate_mbuf(const rte_mbuf_t *m) {
     }
     
     /* copy data */
-    copy_mbuf(dest, m);
+    mbuf_to_buffer(dest, m);
     
     return clone_mbuf;
 }