RX bytes reporting working
authorIdo Barnea <[email protected]>
Tue, 15 Mar 2016 16:36:04 +0000 (18:36 +0200)
committerIdo Barnea <[email protected]>
Tue, 22 Mar 2016 15:40:02 +0000 (17:40 +0200)
src/debug.cpp
src/flow_stat.cpp
src/flow_stat.h
src/internal_api/trex_platform_api.h
src/main_dpdk.cpp
src/main_dpdk.h

index 902766a..656549d 100644 (file)
@@ -415,11 +415,17 @@ int CTrexDebug::test_send(uint pkt_type) {
         lp->dump_stats_extended(stdout);
     }
     for (port_id = 0; port_id < m_max_ports; port_id++) {
-        uint64_t fdir_stat[MAX_FLOW_STATS];
+        rx_per_flow_t fdir_stat[MAX_FLOW_STATS];
+        uint64_t fdir_stat_64[MAX_FLOW_STATS];
         CPhyEthIF *lp = &m_ports[port_id];
-        if (lp->get_flow_stats(fdir_stat, NULL, 0, MAX_FLOW_STATS, false) == 0)
-            rte_stat_dump_array(fdir_stat, "FDIR stat", MAX_FLOW_STATS);
+        if (lp->get_flow_stats(fdir_stat, NULL, 0, MAX_FLOW_STATS, false) == 0) {
+            for (int i = 0; i < MAX_FLOW_STATS; i++) {
+                fdir_stat_64[i] = fdir_stat[i].get_pkts();
+            }
+            rte_stat_dump_array(fdir_stat_64, "FDIR stat", MAX_FLOW_STATS);
+        }
     }
 
+
     return (0);
 }
index f03065d..0103829 100644 (file)
@@ -121,7 +121,7 @@ void CFlowStatUserIdInfo::reset_hw_id() {
     // Next session will start counting from 0.
     for (int i = 0; i < TREX_MAX_PORTS; i++) {
         m_rx_counter_base[i] += m_rx_counter[i];
-        m_rx_counter[i] = 0;
+        memset(&m_rx_counter[i], 0, sizeof(m_rx_counter[0]));
         m_tx_counter_base[i] += m_tx_counter[i];
         memset(&m_tx_counter[i], 0, sizeof(m_tx_counter[0]));
     }
@@ -590,7 +590,7 @@ int CFlowStatRuleMgr::stop_stream(const TrexStream * stream) {
             // update counters, and reset before unmapping
             CFlowStatUserIdInfo *p_user_id = m_user_id_map.find_user_id(m_hw_id_map.get_user_id(hw_id));
             assert(p_user_id != NULL);
-            uint64_t rx_counter;
+            rx_per_flow_t rx_counter;
             tx_per_flow_t tx_counter;
             for (uint8_t port = 0; port < m_num_ports; port++) {
                 m_api->del_rx_flow_stat_rule(port, FLOW_STAT_RULE_TYPE_IPV4_ID, proto, hw_id);
@@ -620,7 +620,7 @@ int CFlowStatRuleMgr::get_active_pgids(flow_stat_active_t &result) {
 
 // return false if no counters changed since last run. true otherwise
 bool CFlowStatRuleMgr::dump_json(std::string & json, bool baseline) {
-    uint64_t rx_stats[MAX_FLOW_STATS];
+    rx_per_flow_t rx_stats[MAX_FLOW_STATS];
     tx_per_flow_t tx_stats[MAX_FLOW_STATS];
     Json::FastWriter writer;
     Json::Value root;
@@ -645,15 +645,16 @@ bool CFlowStatRuleMgr::dump_json(std::string & json, bool baseline) {
     for (uint8_t port = 0; port < m_num_ports; port++) {
         m_api->get_flow_stats(port, rx_stats, (void *)tx_stats, 0, m_max_hw_id, false);
         for (int i = 0; i <= m_max_hw_id; i++) {
-            if (rx_stats[i] != 0) {
+            if (rx_stats[i].get_pkts() != 0) {
+                rx_per_flow_t rx_pkts = rx_stats[i];
                 CFlowStatUserIdInfo *p_user_id = m_user_id_map.find_user_id(m_hw_id_map.get_user_id(i));
                 if (likely(p_user_id != NULL)) {
-                    if (p_user_id->get_rx_counter(port) != rx_stats[i]) {
-                        p_user_id->set_rx_counter(port, rx_stats[i]);
+                    if (p_user_id->get_rx_counter(port) != rx_pkts) {
+                        p_user_id->set_rx_counter(port, rx_pkts);
                         p_user_id->set_need_to_send_rx(port);
                     }
                 } else {
-                    std::cerr <<  __METHOD_NAME__ << i << ":Could not count " << rx_stats[i] << " rx packets, on port "
+                    std::cerr <<  __METHOD_NAME__ << i << ":Could not count " << rx_pkts << " rx packets, on port "
                               << (uint16_t)port << ", because no mapping was found." << std::endl;
                 }
             }
@@ -690,7 +691,8 @@ bool CFlowStatRuleMgr::dump_json(std::string & json, bool baseline) {
             std::string str_port = static_cast<std::ostringstream*>( &(std::ostringstream() << int(port) ) )->str();
             if (user_id_info->need_to_send_rx(port) || baseline) {
                 user_id_info->set_no_need_to_send_rx(port);
-                data_section[str_user_id]["rx_pkts"][str_port] = Json::Value::UInt64(user_id_info->get_rx_counter(port));
+                data_section[str_user_id]["rx_pkts"][str_port] = Json::Value::UInt64(user_id_info->get_rx_counter(port).get_pkts());
+                data_section[str_user_id]["rx_bytes"][str_port] = Json::Value::UInt64(user_id_info->get_rx_counter(port).get_bytes());
                 send_empty = false;
             }
             if (user_id_info->need_to_send_tx(port) || baseline) {
index 3e00a18..0fb4fed 100644 (file)
@@ -50,7 +50,7 @@ class tx_per_flow_t_ {
     inline void set_bytes(uint64_t bytes) {
         m_bytes = bytes;;
     }
-    inline void get_pkts(uint64_t pkts) {
+    inline void set_pkts(uint64_t pkts) {
         m_pkts = pkts;
     }
     inline void add_bytes(uint64_t bytes) {
@@ -100,6 +100,7 @@ class tx_per_flow_t_ {
 };
 
 typedef class tx_per_flow_t_ tx_per_flow_t;
+typedef class tx_per_flow_t_ rx_per_flow_t;
 
 class CPhyEthIF;
 class Cxl710Parser;
@@ -108,8 +109,8 @@ class CFlowStatUserIdInfo {
  public:
     CFlowStatUserIdInfo(uint8_t proto);
     friend std::ostream& operator<<(std::ostream& os, const CFlowStatUserIdInfo& cf);
-    void set_rx_counter(uint8_t port, uint64_t val) {m_rx_counter[port] = val;}
-    uint64_t get_rx_counter(uint8_t port) {return m_rx_counter[port] + m_rx_counter_base[port];}
+    void set_rx_counter(uint8_t port, rx_per_flow_t val) {m_rx_counter[port] = val;}
+    rx_per_flow_t get_rx_counter(uint8_t port) {return m_rx_counter[port] + m_rx_counter_base[port];}
     void set_tx_counter(uint8_t port, tx_per_flow_t val) {m_tx_counter[port] = val;}
     tx_per_flow_t get_tx_counter(uint8_t port) {return m_tx_counter[port] + m_tx_counter_base[port];}
     void set_hw_id(uint16_t hw_id) {m_hw_id = hw_id;}
@@ -135,9 +136,9 @@ class CFlowStatUserIdInfo {
  private:
     bool m_rx_changed[TREX_MAX_PORTS]; // Which RX counters changed since we last published
     bool m_tx_changed[TREX_MAX_PORTS]; // Which TX counters changed since we last published
-    uint64_t m_rx_counter[TREX_MAX_PORTS]; // How many packets received with this user id since stream start
+    rx_per_flow_t m_rx_counter[TREX_MAX_PORTS]; // How many packets received with this user id since stream start
     // How many packets received with this user id, since stream creation, before stream start.
-    uint64_t m_rx_counter_base[TREX_MAX_PORTS];
+    rx_per_flow_t m_rx_counter_base[TREX_MAX_PORTS];
     tx_per_flow_t m_tx_counter[TREX_MAX_PORTS]; // How many packets transmitted with this user id since stream start
     // How many packets transmitted with this user id, since stream creation, before stream start.
     tx_per_flow_t m_tx_counter_base[TREX_MAX_PORTS];
index f8f7658..fc5da49 100644 (file)
@@ -142,7 +142,7 @@ public:
     virtual void publish_async_data_now(uint32_t key, bool baseline) const = 0;
     virtual uint8_t get_dp_core_count() const = 0;
     virtual void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const =0;
-    virtual int get_flow_stats(uint8_t port_id, uint64_t *stats, void *tx_stats, int min, int max, bool reset) const = 0;
+    virtual int get_flow_stats(uint8_t port_id, void *stats, void *tx_stats, int min, int max, bool reset) const = 0;
     virtual int reset_hw_flow_stats(uint8_t port_id) const = 0;
     virtual void get_port_num(uint8_t &port_num) const = 0;
     virtual int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const = 0;
@@ -171,7 +171,7 @@ public:
     void publish_async_data_now(uint32_t key, bool baseline) const;
     uint8_t get_dp_core_count() const;
     void get_interface_stat_info(uint8_t interface_id, uint16_t &num_counters, uint16_t &capabilities) const;
-    int get_flow_stats(uint8_t port_id, uint64_t *stats, void *tx_stats, int min, int max, bool reset) const;
+    int get_flow_stats(uint8_t port_id, void *stats, void *tx_stats, int min, int max, bool reset) const;
     int reset_hw_flow_stats(uint8_t port_id) const;
     void get_port_num(uint8_t &port_num) const;
     int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const;
@@ -225,7 +225,7 @@ public:
     virtual void publish_async_data_now(uint32_t key, bool baseline) const {
 
     }
-    virtual int get_flow_stats(uint8_t port_id, uint64_t *stats, void *tx_stats, int min, int max, bool reset) const {return 0;};
+    virtual int get_flow_stats(uint8_t port_id, void *stats, void *tx_stats, int min, int max, bool reset) const {return 0;};
     virtual int reset_hw_flow_stats(uint8_t port_id) const {return 0;};
     virtual void get_port_num(uint8_t &port_num) const {port_num = 2;};
     virtual int add_rx_flow_stat_rule(uint8_t port_id, uint8_t type, uint16_t proto, uint16_t id) const {return 0;}
index 111426c..4fc048f 100644 (file)
@@ -1190,7 +1190,8 @@ void CPhyEthIFStats::Clear(){
     oerrors = 0;
     imcasts = 0;
     rx_nombuf = 0;
-    memset(m_rx_per_flow, 0, sizeof(m_rx_per_flow));
+    memset(m_rx_per_flow_pkts, 0, sizeof(m_rx_per_flow_pkts));
+    memset(m_rx_per_flow_bytes, 0, sizeof(m_rx_per_flow_bytes));
 }
 
 
@@ -3990,7 +3991,7 @@ int CPhyEthIF::reset_hw_flow_stats() {
 // rx_stats, tx_stats - arrays of len max - min + 1. Returning rx, tx updated absolute values.
 // min, max - minimum, maximum counters range to get
 // reset - If true, need to reset counter value after reading
-int CPhyEthIF::get_flow_stats(uint64_t *rx_stats, tx_per_flow_t *tx_stats, int min, int max, bool reset) {
+int CPhyEthIF::get_flow_stats(rx_per_flow_t *rx_stats, tx_per_flow_t *tx_stats, int min, int max, bool reset) {
     uint32_t diff_pkts[MAX_FLOW_STATS];
     uint32_t diff_bytes[MAX_FLOW_STATS];
 
@@ -4003,16 +4004,20 @@ int CPhyEthIF::get_flow_stats(uint64_t *rx_stats, tx_per_flow_t *tx_stats, int m
         if ( reset ) {
             // return value so far, and reset
             if (rx_stats != NULL) {
-                rx_stats[i - min] = m_stats.m_rx_per_flow[i] + diff_pkts[i];
+                rx_stats[i - min].set_pkts(m_stats.m_rx_per_flow_pkts[i] + diff_pkts[i]);
+                rx_stats[i - min].set_bytes(m_stats.m_rx_per_flow_bytes[i] + diff_bytes[i]);
             }
             if (tx_stats != NULL) {
                 tx_stats[i - min] = g_trex.clear_flow_tx_stats(m_port_id, i);
             }
-            m_stats.m_rx_per_flow[i] = 0;
+            m_stats.m_rx_per_flow_pkts[i] = 0;
+            m_stats.m_rx_per_flow_bytes[i] = 0;
         } else {
-            m_stats.m_rx_per_flow[i] += diff_pkts[i];
+            m_stats.m_rx_per_flow_pkts[i] += diff_pkts[i];
+            m_stats.m_rx_per_flow_bytes[i] += diff_bytes[i];
             if (rx_stats != NULL) {
-                rx_stats[i - min] = m_stats.m_rx_per_flow[i];
+                rx_stats[i - min].set_pkts(m_stats.m_rx_per_flow_pkts[i]);
+                rx_stats[i - min].set_bytes(m_stats.m_rx_per_flow_bytes[i]);
             }
             if (tx_stats != NULL) {
                 tx_stats[i - min] = g_trex.get_flow_tx_stats(m_port_id, i);
@@ -5288,8 +5293,8 @@ TrexDpdkPlatformApi::get_interface_stat_info(uint8_t interface_id, uint16_t &num
     capabilities = CTRexExtendedDriverDb::Ins()->get_drv()->get_rx_stat_capabilities();
 }
 
-int TrexDpdkPlatformApi::get_flow_stats(uint8 port_id, uint64_t *rx_stats, void *tx_stats, int min, int max, bool reset) const {
-    return g_trex.m_ports[port_id].get_flow_stats(rx_stats, (tx_per_flow_t *)tx_stats, min, max, reset);
+int TrexDpdkPlatformApi::get_flow_stats(uint8 port_id, void *rx_stats, void *tx_stats, int min, int max, bool reset) const {
+    return g_trex.m_ports[port_id].get_flow_stats((rx_per_flow_t *)rx_stats, (tx_per_flow_t *)tx_stats, min, max, reset);
 }
 
 int TrexDpdkPlatformApi::reset_hw_flow_stats(uint8_t port_id) const {
index c5d2d4d..ff1ea78 100644 (file)
@@ -38,7 +38,8 @@ class CPhyEthIFStats {
     uint64_t oerrors;   /**< Total number of failed transmitted packets. */
     uint64_t imcasts;   /**< Total number of multicast received packets. */
     uint64_t rx_nombuf; /**< Total number of RX mbuf allocation failures. */
-    uint64_t  m_rx_per_flow [MAX_FLOW_STATS]; // Per flow RX statistics
+    uint64_t m_rx_per_flow_pkts [MAX_FLOW_STATS]; // Per flow RX pkts
+    uint64_t m_rx_per_flow_bytes[MAX_FLOW_STATS]; // Per flow RX bytes
     // Previous fdir stats values read from driver. Since on xl710 this is 32 bit, we save old value, to handle wrap around.
     uint32_t  m_fdir_prev_pkts [MAX_FLOW_STATS];
     uint32_t  m_fdir_prev_bytes [MAX_FLOW_STATS];
@@ -74,7 +75,7 @@ class CPhyEthIF  {
     void get_stats(CPhyEthIFStats *stats);
     int dump_fdir_global_stats(FILE *fd);
     int reset_hw_flow_stats();
-    int get_flow_stats(uint64_t *rx_stats, tx_per_flow_t *tx_stats, int min, int max, bool reset);
+    int get_flow_stats(rx_per_flow_t *rx_stats, tx_per_flow_t *tx_stats, int min, int max, bool reset);
     void get_stats_1g(CPhyEthIFStats *stats);
     void rx_queue_setup(uint16_t rx_queue_id,
                         uint16_t nb_rx_desc,