summaryrefslogtreecommitdiffstats
path: root/src/stateless
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-10-11 14:42:24 +0200
committerimarom <imarom@cisco.com>2015-10-11 14:42:24 +0200
commit6c7880b9881ed6690954f0c29259dd0b584b3970 (patch)
treef8d23267dc0e086f1c622418e8bf68a04d38e64d /src/stateless
parent3b827c9584c28d3f1f573e372f646edfe9f5f007 (diff)
DP cores now inject a single packet as a dummy to see stats
Diffstat (limited to 'src/stateless')
-rw-r--r--src/stateless/cp/trex_stateless.cpp14
-rw-r--r--src/stateless/cp/trex_stateless.h4
-rw-r--r--src/stateless/cp/trex_stateless_port.cpp77
-rw-r--r--src/stateless/cp/trex_stateless_port.h34
-rw-r--r--src/stateless/dp/trex_stateless_dp_core.cpp101
-rw-r--r--src/stateless/dp/trex_stateless_dp_core.h1
6 files changed, 204 insertions, 27 deletions
diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp
index 20e001c9..72762e26 100644
--- a/src/stateless/cp/trex_stateless.cpp
+++ b/src/stateless/cp/trex_stateless.cpp
@@ -50,7 +50,9 @@ void TrexStateless::configure(const TrexStatelessCfg &cfg) {
}
/* create RPC servers */
- instance.m_rpc_server = new TrexRpcServer(cfg.m_rpc_req_resp_cfg, cfg.m_rpc_async_cfg);
+
+ /* set both servers to mutex each other */
+ instance.m_rpc_server = new TrexRpcServer(cfg.m_rpc_req_resp_cfg, cfg.m_rpc_async_cfg, &instance.m_global_cp_lock);
instance.m_rpc_server->set_verbose(cfg.m_rpc_server_verbose);
/* configure ports */
@@ -152,12 +154,10 @@ TrexStateless::get_dp_core_count() {
void
TrexStateless::update_stats() {
- /* update CPU util. */
- #ifdef TREX_RPC_MOCK_SERVER
- m_stats.m_stats.m_cpu_util = 0;
- #else
- m_stats.m_stats.m_cpu_util = 0;
- #endif
+ /* update CPU util.
+ TODO
+ */
+ m_stats.m_stats.m_cpu_util = 0;
/* for every port update and accumulate */
for (uint8_t i = 0; i < m_port_count; i++) {
diff --git a/src/stateless/cp/trex_stateless.h b/src/stateless/cp/trex_stateless.h
index ef612e84..649b25dd 100644
--- a/src/stateless/cp/trex_stateless.h
+++ b/src/stateless/cp/trex_stateless.h
@@ -25,6 +25,8 @@ limitations under the License.
#include <string>
#include <stdexcept>
+#include <mutex>
+
#include <trex_stream.h>
#include <trex_stateless_port.h>
#include <trex_stateless_dp_core.h>
@@ -192,6 +194,8 @@ protected:
/* stats */
TrexStatelessStats m_stats;
+
+ std::mutex m_global_cp_lock;
};
#endif /* __TREX_STATELESS_H__ */
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp
index 240b7582..f745bee9 100644
--- a/src/stateless/cp/trex_stateless_port.cpp
+++ b/src/stateless/cp/trex_stateless_port.cpp
@@ -28,6 +28,7 @@ limitations under the License.
// DPDK c++ issue
#include <rte_ethdev.h>
+#include <os_time.h>
using namespace std;
@@ -133,28 +134,23 @@ TrexStatelessPort::generate_handler() {
*/
void
TrexStatelessPort::update_stats() {
- #ifdef TREX_RPC_MOCK_SERVER
- /* do lies - its a mock */
- m_stats.m_stats.m_tx_bps = rand() % 10000;
- m_stats.m_stats.m_rx_bps = rand() % 10000;
+ struct rte_eth_stats stats;
+ rte_eth_stats_get(m_port_id, &stats);
- m_stats.m_stats.m_tx_pps = m_stats.m_stats.m_tx_bps / (64 + rand() % 1000);
- m_stats.m_stats.m_rx_pps = m_stats.m_stats.m_rx_bps / (64 + rand() % 1000);
+ /* copy straight values */
+ m_stats.m_stats.m_total_tx_bytes = stats.obytes;
+ m_stats.m_stats.m_total_rx_bytes = stats.ibytes;
+ m_stats.m_stats.m_total_tx_pkts = stats.opackets;
+ m_stats.m_stats.m_total_rx_pkts = stats.ipackets;
- m_stats.m_stats.m_total_tx_bytes += m_stats.m_stats.m_tx_bps;
- m_stats.m_stats.m_total_rx_bytes += m_stats.m_stats.m_rx_bps;
+ /* calculate stats */
+ m_stats.m_stats.m_tx_bps = m_stats.m_bw_tx_bps.add(stats.obytes);
+ m_stats.m_stats.m_rx_bps = m_stats.m_bw_rx_bps.add(stats.ibytes);
- m_stats.m_stats.m_total_tx_pkts += m_stats.m_stats.m_tx_pps;
- m_stats.m_stats.m_total_rx_pkts += m_stats.m_stats.m_rx_pps;
+ m_stats.m_stats.m_tx_pps = m_stats.m_bw_tx_pps.add(stats.opackets);
+ m_stats.m_stats.m_rx_pps = m_stats.m_bw_rx_pps.add(stats.ipackets);
- #else
- /* real update work */
- struct rte_eth_stats stats;
- rte_eth_stats_get(m_port_id, &stats);
- printf("ipackets is %u\n", stats.ipackets);
- printf("opackets is %u\n", stats.opackets);
- #endif
}
const TrexPortStats &
@@ -181,3 +177,50 @@ TrexStatelessPort::encode_stats(Json::Value &port) {
}
+
+/***************************
+ * BW measurement
+ *
+ **************************/
+/* TODO: move this to a common place */
+BWMeasure::BWMeasure() {
+ reset();
+}
+
+void BWMeasure::reset(void) {
+ m_start=false;
+ m_last_time_msec=0;
+ m_last_bytes=0;
+ m_last_result=0.0;
+};
+
+double BWMeasure::calc_MBsec(uint32_t dtime_msec,
+ uint64_t dbytes){
+ double rate=0.000008*( ( (double)dbytes*(double)os_get_time_freq())/((double)dtime_msec) );
+ return(rate);
+}
+
+double BWMeasure::add(uint64_t size) {
+ if ( false == m_start ) {
+ m_start=true;
+ m_last_time_msec = os_get_time_msec() ;
+ m_last_bytes=size;
+ return(0.0);
+ }
+
+ uint32_t ctime=os_get_time_msec();
+ if ((ctime - m_last_time_msec) <os_get_time_freq() ) {
+ return(m_last_result);
+ }
+
+ uint32_t dtime_msec = ctime-m_last_time_msec;
+ uint64_t dbytes = size - m_last_bytes;
+
+ m_last_time_msec = ctime;
+ m_last_bytes = size;
+
+ m_last_result= 0.5*calc_MBsec(dtime_msec,dbytes) +0.5*(m_last_result);
+ return( m_last_result );
+}
+
+
diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h
index a19fd981..428d5aee 100644
--- a/src/stateless/cp/trex_stateless_port.h
+++ b/src/stateless/cp/trex_stateless_port.h
@@ -24,6 +24,27 @@ limitations under the License.
#include <trex_stream.h>
/**
+ * bandwidth measurement class
+ *
+ */
+class BWMeasure {
+public:
+ BWMeasure();
+ void reset(void);
+ double add(uint64_t size);
+
+private:
+ double calc_MBsec(uint32_t dtime_msec,
+ uint64_t dbytes);
+
+public:
+ bool m_start;
+ uint32_t m_last_time_msec;
+ uint64_t m_last_bytes;
+ double m_last_result;
+};
+
+/**
* TRex stateless port stats
*
* @author imarom (24-Sep-15)
@@ -33,9 +54,22 @@ class TrexPortStats {
public:
TrexPortStats() {
m_stats = {0};
+
+ m_bw_tx_bps.reset();
+ m_bw_rx_bps.reset();
+
+ m_bw_tx_pps.reset();
+ m_bw_rx_pps.reset();
}
public:
+
+ BWMeasure m_bw_tx_bps;
+ BWMeasure m_bw_rx_bps;
+
+ BWMeasure m_bw_tx_pps;
+ BWMeasure m_bw_rx_pps;
+
struct {
double m_tx_bps;
diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp
index 4e9309ab..1c96487d 100644
--- a/src/stateless/dp/trex_stateless_dp_core.cpp
+++ b/src/stateless/dp/trex_stateless_dp_core.cpp
@@ -24,14 +24,109 @@ limitations under the License.
#include <unistd.h>
#include <trex_stateless.h>
+#include <bp_sim.h>
+
+// DPDK c++ issue
+#define UINT8_MAX 255
+#define UINT16_MAX 0xFFFF
+// DPDK c++ issue
+
+#include <rte_ethdev.h>
+#include "mbuf.h"
+
+/**
+ * TEST
+ *
+ */
+static const uint8_t udp_pkt[]={
+ 0x00,0x00,0x00,0x01,0x00,0x00,
+ 0x00,0x00,0x00,0x01,0x00,0x00,
+ 0x08,0x00,
+
+ 0x45,0x00,0x00,0x81,
+ 0xaf,0x7e,0x00,0x00,
+ 0x12,0x11,0xd9,0x23,
+ 0x01,0x01,0x01,0x01,
+ 0x3d,0xad,0x72,0x1b,
+
+ 0x11,0x11,
+ 0x11,0x11,
+
+ 0x00,0x6d,
+ 0x00,0x00,
+
+ 0x64,0x31,0x3a,0x61,
+ 0x64,0x32,0x3a,0x69,0x64,
+ 0x32,0x30,0x3a,0xd0,0x0e,
+ 0xa1,0x4b,0x7b,0xbd,0xbd,
+ 0x16,0xc6,0xdb,0xc4,0xbb,0x43,
+ 0xf9,0x4b,0x51,0x68,0x33,0x72,
+ 0x20,0x39,0x3a,0x69,0x6e,0x66,0x6f,
+ 0x5f,0x68,0x61,0x73,0x68,0x32,0x30,0x3a,0xee,0xc6,0xa3,
+ 0xd3,0x13,0xa8,0x43,0x06,0x03,0xd8,0x9e,0x3f,0x67,0x6f,
+ 0xe7,0x0a,0xfd,0x18,0x13,0x8d,0x65,0x31,0x3a,0x71,0x39,
+ 0x3a,0x67,0x65,0x74,0x5f,0x70,0x65,0x65,0x72,0x73,0x31,
+ 0x3a,0x74,0x38,0x3a,0x3d,0xeb,0x0c,0xbf,0x0d,0x6a,0x0d,
+ 0xa5,0x31,0x3a,0x79,0x31,0x3a,0x71,0x65,0x87,0xa6,0x7d,
+ 0xe7
+};
+
+static int
+test_inject_pkt(uint8_t *pkt, uint32_t pkt_size) {
+
+ #ifndef TREX_RPC_MOCK_SERVER
+ rte_mempool_t * mp= CGlobalInfo::m_mem_pool[0].m_big_mbuf_pool ;
+ #else
+ rte_mempool_t * mp = NULL;
+ #endif
+
+ rte_mbuf_t *m = rte_pktmbuf_alloc(mp);
+ if ( unlikely(m==0) ) {
+ printf("ERROR no packets \n");
+ return (-1);
+ }
+ char *p = rte_pktmbuf_append(m, pkt_size);
+ assert(p);
+ /* set pkt data */
+ memcpy(p,pkt,pkt_size);
+
+ rte_mbuf_t *tx_pkts[32];
+ tx_pkts[0] = m;
+ uint8_t nb_pkts = 1;
+ uint16_t ret = rte_eth_tx_burst(0, 0, tx_pkts, nb_pkts);
+ (void)ret;
+ rte_pktmbuf_free(m);
+
+ return (0);
+}
+
+static int
+test_inject_udp_pkt(){
+ return (test_inject_pkt((uint8_t*)udp_pkt,sizeof(udp_pkt)));
+}
+
+void
+TrexStatelessDpCore::test_inject_dummy_pkt() {
+ test_inject_udp_pkt();
+}
+
+/***************************
+ * DP core
+ *
+ **************************/
TrexStatelessDpCore::TrexStatelessDpCore(uint8_t core_id) : m_core_id(core_id) {
}
+/**
+ * main function for DP core
+ *
+ */
void
TrexStatelessDpCore::run() {
- printf("On DP core %d\n", m_core_id);
+ printf("\nOn DP core %d\n", m_core_id);
while (true) {
- sleep(1);
- TrexStateless::get_instance().get_port_by_id(0)->update_stats();
+ test_inject_dummy_pkt();
+ rte_pause();
}
}
+
diff --git a/src/stateless/dp/trex_stateless_dp_core.h b/src/stateless/dp/trex_stateless_dp_core.h
index d428bac2..4b09b752 100644
--- a/src/stateless/dp/trex_stateless_dp_core.h
+++ b/src/stateless/dp/trex_stateless_dp_core.h
@@ -36,6 +36,7 @@ public:
void run();
private:
+ void test_inject_dummy_pkt();
uint8_t m_core_id;
};