summaryrefslogtreecommitdiffstats
path: root/src/stateless/trex_stateless.cpp
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-10-07 14:57:48 +0200
committerimarom <imarom@cisco.com>2015-10-07 14:57:48 +0200
commit4d53d6e2633caed782067965b1b4422b45dab4a2 (patch)
tree84966bcdb944027ded09c78f57f6de0f991cc1f6 /src/stateless/trex_stateless.cpp
parent73574943ae438985f37aae3ea52e9713c55ef62e (diff)
added async publisher to the RPC server
Diffstat (limited to 'src/stateless/trex_stateless.cpp')
-rw-r--r--src/stateless/trex_stateless.cpp122
1 files changed, 40 insertions, 82 deletions
diff --git a/src/stateless/trex_stateless.cpp b/src/stateless/trex_stateless.cpp
index 3ec419ea..0b7947a0 100644
--- a/src/stateless/trex_stateless.cpp
+++ b/src/stateless/trex_stateless.cpp
@@ -19,6 +19,7 @@ See the License for the specific language governing permissions and
limitations under the License.
*/
#include <trex_stateless_api.h>
+#include <trex_stateless_port.h>
using namespace std;
@@ -73,107 +74,64 @@ uint8_t TrexStateless::get_port_count() {
return m_port_count;
}
+void
+TrexStateless::update_stats() {
-/***************************
- * trex stateless port stats
- *
- **************************/
-TrexPortStats::TrexPortStats() {
- m_stats = {0};
-}
-
-/***************************
- * trex stateless port
- *
- **************************/
-TrexStatelessPort::TrexStatelessPort(uint8_t port_id) : m_port_id(port_id) {
- m_port_state = PORT_STATE_UP_IDLE;
- clear_owner();
-}
-
+ /* 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
-/**
- * starts the traffic on the port
- *
- */
-TrexStatelessPort::rc_e
-TrexStatelessPort::start_traffic(void) {
+ /* for every port update and accumulate */
+ for (uint8_t i = 0; i < m_port_count; i++) {
+ m_ports[i]->update_stats();
- if (m_port_state != PORT_STATE_UP_IDLE) {
- return (RC_ERR_BAD_STATE_FOR_OP);
- }
+ const TrexPortStats & port_stats = m_ports[i]->get_stats();
- if (get_stream_table()->size() == 0) {
- return (RC_ERR_NO_STREAMS);
- }
+ m_stats.m_stats.m_tx_bps += port_stats.m_stats.m_tx_bps;
+ m_stats.m_stats.m_rx_bps += port_stats.m_stats.m_rx_bps;
- m_port_state = PORT_STATE_TRANSMITTING;
+ m_stats.m_stats.m_tx_pps += port_stats.m_stats.m_tx_pps;
+ m_stats.m_stats.m_rx_pps += port_stats.m_stats.m_rx_pps;
- /* real code goes here */
- return (RC_OK);
-}
+ m_stats.m_stats.m_total_tx_pkts += port_stats.m_stats.m_total_tx_pkts;
+ m_stats.m_stats.m_total_rx_pkts += port_stats.m_stats.m_total_rx_pkts;
-void
-TrexStatelessPort::stop_traffic(void) {
+ m_stats.m_stats.m_total_tx_bytes += port_stats.m_stats.m_total_tx_bytes;
+ m_stats.m_stats.m_total_rx_bytes += port_stats.m_stats.m_total_rx_bytes;
- /* real code goes here */
- if (m_port_state == PORT_STATE_TRANSMITTING) {
- m_port_state = PORT_STATE_UP_IDLE;
+ m_stats.m_stats.m_tx_rx_errors += port_stats.m_stats.m_tx_rx_errors;
}
}
-/**
-* access the stream table
-*
-*/
-TrexStreamTable * TrexStatelessPort::get_stream_table() {
- return &m_stream_table;
-}
-
+void
+TrexStateless::encode_stats(Json::Value &global) {
-std::string
-TrexStatelessPort::get_state_as_string() {
+ global["cpu_util"] = m_stats.m_stats.m_cpu_util;
- switch (get_state()) {
- case PORT_STATE_DOWN:
- return "down";
+ global["tx_bps"] = m_stats.m_stats.m_tx_bps;
+ global["rx_bps"] = m_stats.m_stats.m_rx_bps;
- case PORT_STATE_UP_IDLE:
- return "idle";
+ global["tx_pps"] = m_stats.m_stats.m_tx_pps;
+ global["rx_pps"] = m_stats.m_stats.m_rx_pps;
- case PORT_STATE_TRANSMITTING:
- return "transmitting";
- }
+ global["total_tx_pkts"] = Json::Value::UInt64(m_stats.m_stats.m_total_tx_pkts);
+ global["total_rx_pkts"] = Json::Value::UInt64(m_stats.m_stats.m_total_rx_pkts);
- return "unknown";
-}
+ global["total_tx_bytes"] = Json::Value::UInt64(m_stats.m_stats.m_total_tx_bytes);
+ global["total_rx_bytes"] = Json::Value::UInt64(m_stats.m_stats.m_total_rx_bytes);
-void
-TrexStatelessPort::get_properties(string &driver, string &speed) {
+ global["tx_rx_errors"] = Json::Value::UInt64(m_stats.m_stats.m_tx_rx_errors);
- /* take this from DPDK */
- driver = "e1000";
- speed = "1 Gbps";
-}
+ for (uint8_t i = 0; i < m_port_count; i++) {
+ std::stringstream ss;
+ ss << "port " << i;
+ Json::Value &port_section = global[ss.str()];
-/**
- * generate a random connection handler
- *
- */
-std::string
-TrexStatelessPort::generate_handler() {
- std::stringstream ss;
-
- static const char alphanum[] =
- "0123456789"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz";
-
- /* generate 8 bytes of random handler */
- for (int i = 0; i < 8; ++i) {
- ss << alphanum[rand() % (sizeof(alphanum) - 1)];
+ m_ports[i]->encode_stats(port_section);
}
-
- return (ss.str());
}
+