From 1f90e4ed08414c8aa423693c4ee8fa84e7675230 Mon Sep 17 00:00:00 2001 From: imarom Date: Thu, 24 Sep 2015 17:51:04 +0300 Subject: some improvements to the console --- src/stateless/trex_stateless.cpp | 10 +++++++++- src/stateless/trex_stateless_api.h | 30 +++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 10 deletions(-) (limited to 'src/stateless') diff --git a/src/stateless/trex_stateless.cpp b/src/stateless/trex_stateless.cpp index 0eb96f05..3ec419ea 100644 --- a/src/stateless/trex_stateless.cpp +++ b/src/stateless/trex_stateless.cpp @@ -73,6 +73,15 @@ uint8_t TrexStateless::get_port_count() { return m_port_count; } + +/*************************** + * trex stateless port stats + * + **************************/ +TrexPortStats::TrexPortStats() { + m_stats = {0}; +} + /*************************** * trex stateless port * @@ -80,7 +89,6 @@ uint8_t TrexStateless::get_port_count() { TrexStatelessPort::TrexStatelessPort(uint8_t port_id) : m_port_id(port_id) { m_port_state = PORT_STATE_UP_IDLE; clear_owner(); - m_stats = {0}; } diff --git a/src/stateless/trex_stateless_api.h b/src/stateless/trex_stateless_api.h index 7a9080aa..ca093e03 100644 --- a/src/stateless/trex_stateless_api.h +++ b/src/stateless/trex_stateless_api.h @@ -42,14 +42,17 @@ public: }; /** - * describes a stateless port + * TRex stateless port stats * - * @author imarom (31-Aug-15) + * @author imarom (24-Sep-15) */ -class TrexStatelessPort { +class TrexPortStats { + public: + TrexPortStats(); - struct TrexPortStats { +public: + struct { uint64_t tx_pps; uint64_t tx_bps; uint64_t total_tx_pkts; @@ -61,7 +64,16 @@ public: uint64_t total_rx_bytes; uint64_t tx_rx_errors; - }; + } m_stats; +}; + +/** + * describes a stateless port + * + * @author imarom (31-Aug-15) + */ +class TrexStatelessPort { +public: /** * port state @@ -171,10 +183,10 @@ public: const TrexPortStats & get_port_stats(void) { /* scrabble */ - m_stats.tx_bps += 1 + rand() % 100; - m_stats.tx_pps += 1 + rand() % 10; - m_stats.total_tx_bytes += 1 + rand() % 10; - m_stats.total_tx_pkts += 1 + rand() % 5; + m_stats.m_stats.tx_bps += 1 + rand() % 100; + m_stats.m_stats.tx_pps += 1 + rand() % 10; + m_stats.m_stats.total_tx_bytes += 1 + rand() % 10; + m_stats.m_stats.total_tx_pkts += 1 + rand() % 5; return m_stats; } -- cgit From 73574943ae438985f37aae3ea52e9713c55ef62e Mon Sep 17 00:00:00 2001 From: imarom Date: Tue, 29 Sep 2015 19:47:45 +0300 Subject: just a checkpoint on async server --- src/stateless/trex_stateless_api.h | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'src/stateless') diff --git a/src/stateless/trex_stateless_api.h b/src/stateless/trex_stateless_api.h index ca093e03..fd88baf7 100644 --- a/src/stateless/trex_stateless_api.h +++ b/src/stateless/trex_stateless_api.h @@ -181,13 +181,14 @@ public: } - const TrexPortStats & get_port_stats(void) { - /* scrabble */ - m_stats.m_stats.tx_bps += 1 + rand() % 100; - m_stats.m_stats.tx_pps += 1 + rand() % 10; - m_stats.m_stats.total_tx_bytes += 1 + rand() % 10; - m_stats.m_stats.total_tx_pkts += 1 + rand() % 5; + /** + * update the values of the stats + * + * @author imarom (24-Sep-15) + */ + void update_stats(); + const TrexPortStats & get_stats() { return m_stats; } -- cgit From 4d53d6e2633caed782067965b1b4422b45dab4a2 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 7 Oct 2015 14:57:48 +0200 Subject: added async publisher to the RPC server --- src/stateless/trex_stateless.cpp | 122 +++++++------------- src/stateless/trex_stateless_api.h | 203 ++++++++-------------------------- src/stateless/trex_stateless_port.cpp | 172 ++++++++++++++++++++++++++++ src/stateless/trex_stateless_port.h | 196 ++++++++++++++++++++++++++++++++ 4 files changed, 452 insertions(+), 241 deletions(-) create mode 100644 src/stateless/trex_stateless_port.cpp create mode 100644 src/stateless/trex_stateless_port.h (limited to 'src/stateless') 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 +#include 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()); } + diff --git a/src/stateless/trex_stateless_api.h b/src/stateless/trex_stateless_api.h index fd88baf7..e2bf4e1c 100644 --- a/src/stateless/trex_stateless_api.h +++ b/src/stateless/trex_stateless_api.h @@ -41,167 +41,36 @@ public: } }; -/** - * TRex stateless port stats - * - * @author imarom (24-Sep-15) - */ -class TrexPortStats { - -public: - TrexPortStats(); - -public: - struct { - uint64_t tx_pps; - uint64_t tx_bps; - uint64_t total_tx_pkts; - uint64_t total_tx_bytes; - - uint64_t rx_pps; - uint64_t rx_bps; - uint64_t total_rx_pkts; - uint64_t total_rx_bytes; - - uint64_t tx_rx_errors; - } m_stats; -}; +class TrexStatelessPort; /** - * describes a stateless port + * unified stats * - * @author imarom (31-Aug-15) + * @author imarom (06-Oct-15) */ -class TrexStatelessPort { +class TrexStatelessStats { public: - - /** - * port state - */ - enum port_state_e { - PORT_STATE_DOWN, - PORT_STATE_UP_IDLE, - PORT_STATE_TRANSMITTING - }; - - /** - * describess different error codes for port operations - */ - enum rc_e { - RC_OK, - RC_ERR_BAD_STATE_FOR_OP, - RC_ERR_NO_STREAMS, - RC_ERR_FAILED_TO_COMPILE_STREAMS - }; - - TrexStatelessPort(uint8_t port_id); - - /** - * start traffic - * - */ - rc_e start_traffic(void); - - /** - * stop traffic - * - */ - void stop_traffic(void); - - /** - * access the stream table - * - */ - TrexStreamTable *get_stream_table(); - - /** - * get the port state - * - */ - port_state_e get_state() { - return m_port_state; + TrexStatelessStats() { + m_stats = {0}; } - /** - * port state as string - * - */ - std::string get_state_as_string(); - - /** - * fill up properties of the port - * - * @author imarom (16-Sep-15) - * - * @param driver - * @param speed - */ - void get_properties(std::string &driver, std::string &speed); - - /** - * query for ownership - * - */ - const std::string &get_owner() { - return m_owner; - } - - /** - * owner handler - * for the connection - * - */ - const std::string &get_owner_handler() { - return m_owner_handler; - } - - bool is_free_to_aquire() { - return (m_owner == "none"); - } - - /** - * take ownership of the server array - * this is static - * ownership is total - * - */ - void set_owner(const std::string &owner) { - m_owner = owner; - m_owner_handler = generate_handler(); - } - - void clear_owner() { - m_owner = "none"; - m_owner_handler = ""; - } - - bool verify_owner_handler(const std::string &handler) { - - return ( (m_owner != "none") && (m_owner_handler == handler) ); - - } - - /** - * update the values of the stats - * - * @author imarom (24-Sep-15) - */ - void update_stats(); - - const TrexPortStats & get_stats() { - return m_stats; - } - -private: - - std::string generate_handler(); - - TrexStreamTable m_stream_table; - uint8_t m_port_id; - port_state_e m_port_state; - std::string m_owner; - std::string m_owner_handler; - TrexPortStats m_stats; + struct { + double m_cpu_util; + + double m_tx_bps; + double m_rx_bps; + + double m_tx_pps; + double m_rx_pps; + + uint64_t m_total_tx_pkts; + uint64_t m_total_rx_pkts; + + uint64_t m_total_tx_bytes; + uint64_t m_total_rx_bytes; + + uint64_t m_tx_rx_errors; + } m_stats; }; /** @@ -232,8 +101,22 @@ public: return instance; } - TrexStatelessPort *get_port_by_id(uint8_t port_id); - uint8_t get_port_count(); + TrexStatelessPort * get_port_by_id(uint8_t port_id); + uint8_t get_port_count(); + + /** + * update all the stats (deep update) + * (include all the ports and global stats) + * + */ + void update_stats(); + + /** + * fetch all the stats + * + */ + void encode_stats(Json::Value &global); + protected: TrexStateless(); @@ -248,9 +131,11 @@ protected: TrexStateless(TrexStateless const&) = delete; void operator=(TrexStateless const&) = delete; - bool m_is_configured; - TrexStatelessPort **m_ports; - uint8_t m_port_count; + bool m_is_configured; + TrexStatelessPort **m_ports; + uint8_t m_port_count; + + TrexStatelessStats m_stats; }; #endif /* __TREX_STATELESS_API_H__ */ diff --git a/src/stateless/trex_stateless_port.cpp b/src/stateless/trex_stateless_port.cpp new file mode 100644 index 00000000..7322ef8a --- /dev/null +++ b/src/stateless/trex_stateless_port.cpp @@ -0,0 +1,172 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#include +#include +#include + +using namespace std; + +/*************************** + * trex stateless port + * + **************************/ +TrexStatelessPort::TrexStatelessPort(uint8_t port_id) : m_port_id(port_id) { + m_port_state = PORT_STATE_UP_IDLE; + clear_owner(); +} + + +/** + * starts the traffic on the port + * + */ +TrexStatelessPort::rc_e +TrexStatelessPort::start_traffic(void) { + + if (m_port_state != PORT_STATE_UP_IDLE) { + return (RC_ERR_BAD_STATE_FOR_OP); + } + + if (get_stream_table()->size() == 0) { + return (RC_ERR_NO_STREAMS); + } + + m_port_state = PORT_STATE_TRANSMITTING; + + /* real code goes here */ + return (RC_OK); +} + +void +TrexStatelessPort::stop_traffic(void) { + + /* real code goes here */ + if (m_port_state == PORT_STATE_TRANSMITTING) { + m_port_state = PORT_STATE_UP_IDLE; + } +} + +/** +* access the stream table +* +*/ +TrexStreamTable * TrexStatelessPort::get_stream_table() { + return &m_stream_table; +} + + +std::string +TrexStatelessPort::get_state_as_string() { + + switch (get_state()) { + case PORT_STATE_DOWN: + return "down"; + + case PORT_STATE_UP_IDLE: + return "idle"; + + case PORT_STATE_TRANSMITTING: + return "transmitting"; + } + + return "unknown"; +} + +void +TrexStatelessPort::get_properties(string &driver, string &speed) { + + /* take this from DPDK */ + driver = "e1000"; + speed = "1 Gbps"; +} + + +/** + * 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)]; + } + + return (ss.str()); +} + +/** + * update stats for the port + * + */ +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; + + 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); + + + 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; + + 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; + + #else + /* real update work */ + #endif +} + +const TrexPortStats & +TrexStatelessPort::get_stats() { + return m_stats; +} + +void +TrexStatelessPort::encode_stats(Json::Value &port) { + + port["tx_bps"] = m_stats.m_stats.m_tx_bps; + port["rx_bps"] = m_stats.m_stats.m_rx_bps; + + port["tx_pps"] = m_stats.m_stats.m_tx_pps; + port["rx_pps"] = m_stats.m_stats.m_rx_pps; + + port["total_tx_pkts"] = Json::Value::UInt64(m_stats.m_stats.m_total_tx_pkts); + port["total_rx_pkts"] = Json::Value::UInt64(m_stats.m_stats.m_total_rx_pkts); + + port["total_tx_bytes"] = Json::Value::UInt64(m_stats.m_stats.m_total_tx_bytes); + port["total_rx_bytes"] = Json::Value::UInt64(m_stats.m_stats.m_total_rx_bytes); + + port["tx_rx_errors"] = Json::Value::UInt64(m_stats.m_stats.m_tx_rx_errors); +} + + diff --git a/src/stateless/trex_stateless_port.h b/src/stateless/trex_stateless_port.h new file mode 100644 index 00000000..ea98ddae --- /dev/null +++ b/src/stateless/trex_stateless_port.h @@ -0,0 +1,196 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#ifndef __TREX_STATELESS_PORT_H__ +#define __TREX_STATELESS_PORT_H__ + +#include + +/** + * TRex stateless port stats + * + * @author imarom (24-Sep-15) + */ +class TrexPortStats { + +public: + TrexPortStats() { + m_stats = {0}; + } + +public: + struct { + + double m_tx_bps; + double m_rx_bps; + + double m_tx_pps; + double m_rx_pps; + + uint64_t m_total_tx_pkts; + uint64_t m_total_rx_pkts; + + uint64_t m_total_tx_bytes; + uint64_t m_total_rx_bytes; + + uint64_t m_tx_rx_errors; + } m_stats; +}; + +/** + * describes a stateless port + * + * @author imarom (31-Aug-15) + */ +class TrexStatelessPort { +public: + + /** + * port state + */ + enum port_state_e { + PORT_STATE_DOWN, + PORT_STATE_UP_IDLE, + PORT_STATE_TRANSMITTING + }; + + /** + * describess different error codes for port operations + */ + enum rc_e { + RC_OK, + RC_ERR_BAD_STATE_FOR_OP, + RC_ERR_NO_STREAMS, + RC_ERR_FAILED_TO_COMPILE_STREAMS + }; + + TrexStatelessPort(uint8_t port_id); + + /** + * start traffic + * + */ + rc_e start_traffic(void); + + /** + * stop traffic + * + */ + void stop_traffic(void); + + /** + * access the stream table + * + */ + TrexStreamTable *get_stream_table(); + + /** + * get the port state + * + */ + port_state_e get_state() { + return m_port_state; + } + + /** + * port state as string + * + */ + std::string get_state_as_string(); + + /** + * fill up properties of the port + * + * @author imarom (16-Sep-15) + * + * @param driver + * @param speed + */ + void get_properties(std::string &driver, std::string &speed); + + /** + * query for ownership + * + */ + const std::string &get_owner() { + return m_owner; + } + + /** + * owner handler + * for the connection + * + */ + const std::string &get_owner_handler() { + return m_owner_handler; + } + + bool is_free_to_aquire() { + return (m_owner == "none"); + } + + /** + * take ownership of the server array + * this is static + * ownership is total + * + */ + void set_owner(const std::string &owner) { + m_owner = owner; + m_owner_handler = generate_handler(); + } + + void clear_owner() { + m_owner = "none"; + m_owner_handler = ""; + } + + bool verify_owner_handler(const std::string &handler) { + + return ( (m_owner != "none") && (m_owner_handler == handler) ); + + } + + /** + * update the values of the stats + * + */ + void update_stats(); + + const TrexPortStats & get_stats(); + + /** + * encode stats as JSON + */ + void encode_stats(Json::Value &port); + +private: + + std::string generate_handler(); + + TrexStreamTable m_stream_table; + uint8_t m_port_id; + port_state_e m_port_state; + std::string m_owner; + std::string m_owner_handler; + TrexPortStats m_stats; +}; + +#endif /* __TREX_STATELESS_PORT_H__ */ -- cgit From f47239654fb47d9de81fdb47fc9a16f3f205082f Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 7 Oct 2015 17:07:18 +0200 Subject: added some dir structure to the stateless --- src/stateless/cp/trex_stateless.cpp | 137 ++++++++++++++++++++ src/stateless/cp/trex_stateless_api.h | 142 +++++++++++++++++++++ src/stateless/cp/trex_stateless_port.cpp | 172 +++++++++++++++++++++++++ src/stateless/cp/trex_stateless_port.h | 196 +++++++++++++++++++++++++++++ src/stateless/cp/trex_stream.cpp | 116 +++++++++++++++++ src/stateless/cp/trex_stream_api.h | 209 +++++++++++++++++++++++++++++++ src/stateless/cp/trex_stream_vm.cpp | 54 ++++++++ src/stateless/cp/trex_stream_vm.h | 171 +++++++++++++++++++++++++ src/stateless/trex_stateless.cpp | 137 -------------------- src/stateless/trex_stateless_api.h | 142 --------------------- src/stateless/trex_stateless_port.cpp | 172 ------------------------- src/stateless/trex_stateless_port.h | 196 ----------------------------- src/stateless/trex_stream.cpp | 116 ----------------- src/stateless/trex_stream_api.h | 209 ------------------------------- src/stateless/trex_stream_vm.cpp | 54 -------- src/stateless/trex_stream_vm.h | 171 ------------------------- 16 files changed, 1197 insertions(+), 1197 deletions(-) create mode 100644 src/stateless/cp/trex_stateless.cpp create mode 100644 src/stateless/cp/trex_stateless_api.h create mode 100644 src/stateless/cp/trex_stateless_port.cpp create mode 100644 src/stateless/cp/trex_stateless_port.h create mode 100644 src/stateless/cp/trex_stream.cpp create mode 100644 src/stateless/cp/trex_stream_api.h create mode 100644 src/stateless/cp/trex_stream_vm.cpp create mode 100644 src/stateless/cp/trex_stream_vm.h delete mode 100644 src/stateless/trex_stateless.cpp delete mode 100644 src/stateless/trex_stateless_api.h delete mode 100644 src/stateless/trex_stateless_port.cpp delete mode 100644 src/stateless/trex_stateless_port.h delete mode 100644 src/stateless/trex_stream.cpp delete mode 100644 src/stateless/trex_stream_api.h delete mode 100644 src/stateless/trex_stream_vm.cpp delete mode 100644 src/stateless/trex_stream_vm.h (limited to 'src/stateless') diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp new file mode 100644 index 00000000..0b7947a0 --- /dev/null +++ b/src/stateless/cp/trex_stateless.cpp @@ -0,0 +1,137 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#include +#include + +using namespace std; + +/*********************************************************** + * Trex stateless object + * + **********************************************************/ +TrexStateless::TrexStateless() { + m_is_configured = false; +} + +/** + * one time configuration of the stateless object + * + */ +void TrexStateless::configure(uint8_t port_count) { + + TrexStateless& instance = get_instance_internal(); + + if (instance.m_is_configured) { + throw TrexException("re-configuration of stateless object is not allowed"); + } + + instance.m_port_count = port_count; + instance.m_ports = new TrexStatelessPort*[port_count]; + + for (int i = 0; i < instance.m_port_count; i++) { + instance.m_ports[i] = new TrexStatelessPort(i); + } + + instance.m_is_configured = true; +} + +TrexStateless::~TrexStateless() { + for (int i = 0; i < m_port_count; i++) { + delete m_ports[i]; + } + + delete [] m_ports; +} + +TrexStatelessPort * TrexStateless::get_port_by_id(uint8_t port_id) { + if (port_id >= m_port_count) { + throw TrexException("index out of range"); + } + + return m_ports[port_id]; + +} + +uint8_t TrexStateless::get_port_count() { + return m_port_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 + + /* for every port update and accumulate */ + for (uint8_t i = 0; i < m_port_count; i++) { + m_ports[i]->update_stats(); + + const TrexPortStats & port_stats = m_ports[i]->get_stats(); + + 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_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; + + 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; + + 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; + + m_stats.m_stats.m_tx_rx_errors += port_stats.m_stats.m_tx_rx_errors; + } +} + +void +TrexStateless::encode_stats(Json::Value &global) { + + global["cpu_util"] = m_stats.m_stats.m_cpu_util; + + global["tx_bps"] = m_stats.m_stats.m_tx_bps; + global["rx_bps"] = m_stats.m_stats.m_rx_bps; + + global["tx_pps"] = m_stats.m_stats.m_tx_pps; + global["rx_pps"] = m_stats.m_stats.m_rx_pps; + + 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); + + 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); + + global["tx_rx_errors"] = Json::Value::UInt64(m_stats.m_stats.m_tx_rx_errors); + + for (uint8_t i = 0; i < m_port_count; i++) { + std::stringstream ss; + + ss << "port " << i; + Json::Value &port_section = global[ss.str()]; + + m_ports[i]->encode_stats(port_section); + } +} + diff --git a/src/stateless/cp/trex_stateless_api.h b/src/stateless/cp/trex_stateless_api.h new file mode 100644 index 00000000..e2bf4e1c --- /dev/null +++ b/src/stateless/cp/trex_stateless_api.h @@ -0,0 +1,142 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#ifndef __TREX_STATELESS_API_H__ +#define __TREX_STATELESS_API_H__ + +#include +#include +#include + +#include + +/** + * generic exception for errors + * TODO: move this to a better place + */ +class TrexException : public std::runtime_error +{ +public: + TrexException() : std::runtime_error("") { + + } + TrexException(const std::string &what) : std::runtime_error(what) { + } +}; + +class TrexStatelessPort; + +/** + * unified stats + * + * @author imarom (06-Oct-15) + */ +class TrexStatelessStats { +public: + TrexStatelessStats() { + m_stats = {0}; + } + + struct { + double m_cpu_util; + + double m_tx_bps; + double m_rx_bps; + + double m_tx_pps; + double m_rx_pps; + + uint64_t m_total_tx_pkts; + uint64_t m_total_rx_pkts; + + uint64_t m_total_tx_bytes; + uint64_t m_total_rx_bytes; + + uint64_t m_tx_rx_errors; + } m_stats; +}; + +/** + * defines the T-Rex stateless operation mode + * + */ +class TrexStateless { +public: + + /** + * configure the stateless object singelton + * reconfiguration is not allowed + * an exception will be thrown + */ + static void configure(uint8_t port_count); + + /** + * singleton public get instance + * + */ + static TrexStateless& get_instance() { + TrexStateless& instance = get_instance_internal(); + + if (!instance.m_is_configured) { + throw TrexException("object is not configured"); + } + + return instance; + } + + TrexStatelessPort * get_port_by_id(uint8_t port_id); + uint8_t get_port_count(); + + /** + * update all the stats (deep update) + * (include all the ports and global stats) + * + */ + void update_stats(); + + /** + * fetch all the stats + * + */ + void encode_stats(Json::Value &global); + + +protected: + TrexStateless(); + ~TrexStateless(); + + static TrexStateless& get_instance_internal () { + static TrexStateless instance; + return instance; + } + + /* c++ 2011 style singleton */ + TrexStateless(TrexStateless const&) = delete; + void operator=(TrexStateless const&) = delete; + + bool m_is_configured; + TrexStatelessPort **m_ports; + uint8_t m_port_count; + + TrexStatelessStats m_stats; +}; + +#endif /* __TREX_STATELESS_API_H__ */ + diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp new file mode 100644 index 00000000..7322ef8a --- /dev/null +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -0,0 +1,172 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#include +#include +#include + +using namespace std; + +/*************************** + * trex stateless port + * + **************************/ +TrexStatelessPort::TrexStatelessPort(uint8_t port_id) : m_port_id(port_id) { + m_port_state = PORT_STATE_UP_IDLE; + clear_owner(); +} + + +/** + * starts the traffic on the port + * + */ +TrexStatelessPort::rc_e +TrexStatelessPort::start_traffic(void) { + + if (m_port_state != PORT_STATE_UP_IDLE) { + return (RC_ERR_BAD_STATE_FOR_OP); + } + + if (get_stream_table()->size() == 0) { + return (RC_ERR_NO_STREAMS); + } + + m_port_state = PORT_STATE_TRANSMITTING; + + /* real code goes here */ + return (RC_OK); +} + +void +TrexStatelessPort::stop_traffic(void) { + + /* real code goes here */ + if (m_port_state == PORT_STATE_TRANSMITTING) { + m_port_state = PORT_STATE_UP_IDLE; + } +} + +/** +* access the stream table +* +*/ +TrexStreamTable * TrexStatelessPort::get_stream_table() { + return &m_stream_table; +} + + +std::string +TrexStatelessPort::get_state_as_string() { + + switch (get_state()) { + case PORT_STATE_DOWN: + return "down"; + + case PORT_STATE_UP_IDLE: + return "idle"; + + case PORT_STATE_TRANSMITTING: + return "transmitting"; + } + + return "unknown"; +} + +void +TrexStatelessPort::get_properties(string &driver, string &speed) { + + /* take this from DPDK */ + driver = "e1000"; + speed = "1 Gbps"; +} + + +/** + * 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)]; + } + + return (ss.str()); +} + +/** + * update stats for the port + * + */ +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; + + 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); + + + 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; + + 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; + + #else + /* real update work */ + #endif +} + +const TrexPortStats & +TrexStatelessPort::get_stats() { + return m_stats; +} + +void +TrexStatelessPort::encode_stats(Json::Value &port) { + + port["tx_bps"] = m_stats.m_stats.m_tx_bps; + port["rx_bps"] = m_stats.m_stats.m_rx_bps; + + port["tx_pps"] = m_stats.m_stats.m_tx_pps; + port["rx_pps"] = m_stats.m_stats.m_rx_pps; + + port["total_tx_pkts"] = Json::Value::UInt64(m_stats.m_stats.m_total_tx_pkts); + port["total_rx_pkts"] = Json::Value::UInt64(m_stats.m_stats.m_total_rx_pkts); + + port["total_tx_bytes"] = Json::Value::UInt64(m_stats.m_stats.m_total_tx_bytes); + port["total_rx_bytes"] = Json::Value::UInt64(m_stats.m_stats.m_total_rx_bytes); + + port["tx_rx_errors"] = Json::Value::UInt64(m_stats.m_stats.m_tx_rx_errors); +} + + diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h new file mode 100644 index 00000000..ea98ddae --- /dev/null +++ b/src/stateless/cp/trex_stateless_port.h @@ -0,0 +1,196 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#ifndef __TREX_STATELESS_PORT_H__ +#define __TREX_STATELESS_PORT_H__ + +#include + +/** + * TRex stateless port stats + * + * @author imarom (24-Sep-15) + */ +class TrexPortStats { + +public: + TrexPortStats() { + m_stats = {0}; + } + +public: + struct { + + double m_tx_bps; + double m_rx_bps; + + double m_tx_pps; + double m_rx_pps; + + uint64_t m_total_tx_pkts; + uint64_t m_total_rx_pkts; + + uint64_t m_total_tx_bytes; + uint64_t m_total_rx_bytes; + + uint64_t m_tx_rx_errors; + } m_stats; +}; + +/** + * describes a stateless port + * + * @author imarom (31-Aug-15) + */ +class TrexStatelessPort { +public: + + /** + * port state + */ + enum port_state_e { + PORT_STATE_DOWN, + PORT_STATE_UP_IDLE, + PORT_STATE_TRANSMITTING + }; + + /** + * describess different error codes for port operations + */ + enum rc_e { + RC_OK, + RC_ERR_BAD_STATE_FOR_OP, + RC_ERR_NO_STREAMS, + RC_ERR_FAILED_TO_COMPILE_STREAMS + }; + + TrexStatelessPort(uint8_t port_id); + + /** + * start traffic + * + */ + rc_e start_traffic(void); + + /** + * stop traffic + * + */ + void stop_traffic(void); + + /** + * access the stream table + * + */ + TrexStreamTable *get_stream_table(); + + /** + * get the port state + * + */ + port_state_e get_state() { + return m_port_state; + } + + /** + * port state as string + * + */ + std::string get_state_as_string(); + + /** + * fill up properties of the port + * + * @author imarom (16-Sep-15) + * + * @param driver + * @param speed + */ + void get_properties(std::string &driver, std::string &speed); + + /** + * query for ownership + * + */ + const std::string &get_owner() { + return m_owner; + } + + /** + * owner handler + * for the connection + * + */ + const std::string &get_owner_handler() { + return m_owner_handler; + } + + bool is_free_to_aquire() { + return (m_owner == "none"); + } + + /** + * take ownership of the server array + * this is static + * ownership is total + * + */ + void set_owner(const std::string &owner) { + m_owner = owner; + m_owner_handler = generate_handler(); + } + + void clear_owner() { + m_owner = "none"; + m_owner_handler = ""; + } + + bool verify_owner_handler(const std::string &handler) { + + return ( (m_owner != "none") && (m_owner_handler == handler) ); + + } + + /** + * update the values of the stats + * + */ + void update_stats(); + + const TrexPortStats & get_stats(); + + /** + * encode stats as JSON + */ + void encode_stats(Json::Value &port); + +private: + + std::string generate_handler(); + + TrexStreamTable m_stream_table; + uint8_t m_port_id; + port_state_e m_port_state; + std::string m_owner; + std::string m_owner_handler; + TrexPortStats m_stats; +}; + +#endif /* __TREX_STATELESS_PORT_H__ */ diff --git a/src/stateless/cp/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp new file mode 100644 index 00000000..8bf04748 --- /dev/null +++ b/src/stateless/cp/trex_stream.cpp @@ -0,0 +1,116 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#include +#include + +/************************************** + * stream + *************************************/ +TrexStream::TrexStream(uint8_t port_id, uint32_t stream_id) : m_port_id(port_id), m_stream_id(stream_id) { + + /* default values */ + m_isg_usec = 0; + m_next_stream_id = -1; + m_enabled = false; + m_self_start = false; + + m_pkt.binary = NULL; + m_pkt.len = 0; + + m_rx_check.m_enable = false; + +} + +TrexStream::~TrexStream() { + if (m_pkt.binary) { + delete [] m_pkt.binary; + } +} + +void +TrexStream::store_stream_json(const Json::Value &stream_json) { + /* deep copy */ + m_stream_json = stream_json; +} + +const Json::Value & +TrexStream::get_stream_json() { + return m_stream_json; +} + +/************************************** + * stream table + *************************************/ +TrexStreamTable::TrexStreamTable() { + +} + +TrexStreamTable::~TrexStreamTable() { + for (auto stream : m_stream_table) { + delete stream.second; + } +} + +void TrexStreamTable::add_stream(TrexStream *stream) { + TrexStream *old_stream = get_stream_by_id(stream->m_stream_id); + if (old_stream) { + remove_stream(old_stream); + delete old_stream; + } + + m_stream_table[stream->m_stream_id] = stream; +} + +void TrexStreamTable::remove_stream(TrexStream *stream) { + m_stream_table.erase(stream->m_stream_id); +} + + +void TrexStreamTable::remove_and_delete_all_streams() { + + for (auto stream : m_stream_table) { + delete stream.second; + } + + m_stream_table.clear(); +} + +TrexStream * TrexStreamTable::get_stream_by_id(uint32_t stream_id) { + auto search = m_stream_table.find(stream_id); + + if (search != m_stream_table.end()) { + return search->second; + } else { + return NULL; + } +} + +void TrexStreamTable::get_stream_list(std::vector &stream_list) { + stream_list.clear(); + + for (auto stream : m_stream_table) { + stream_list.push_back(stream.first); + } +} + +int TrexStreamTable::size() { + return m_stream_table.size(); +} diff --git a/src/stateless/cp/trex_stream_api.h b/src/stateless/cp/trex_stream_api.h new file mode 100644 index 00000000..d3c0fb29 --- /dev/null +++ b/src/stateless/cp/trex_stream_api.h @@ -0,0 +1,209 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#ifndef __TREX_STREAM_API_H__ +#define __TREX_STREAM_API_H__ + +#include +#include +#include +#include + +#include + +#include + +class TrexRpcCmdAddStream; + +/** + * Stateless Stream + * + */ +class TrexStream { + /* provide the RPC parser a way to access private fields */ + friend class TrexRpcCmdAddStream; + friend class TrexRpcCmdGetStream; + friend class TrexStreamTable; + +public: + TrexStream(uint8_t port_id, uint32_t stream_id); + virtual ~TrexStream() = 0; + + /* defines the min max per packet supported */ + static const uint32_t MIN_PKT_SIZE_BYTES = 1; + static const uint32_t MAX_PKT_SIZE_BYTES = 9000; + + /* provides storage for the stream json*/ + void store_stream_json(const Json::Value &stream_json); + + /* access the stream json */ + const Json::Value & get_stream_json(); + +protected: + /* basic */ + uint8_t m_port_id; + uint32_t m_stream_id; + + + /* config fields */ + double m_isg_usec; + int m_next_stream_id; + + /* indicators */ + bool m_enabled; + bool m_self_start; + + /* pkt */ + struct { + uint8_t *binary; + uint16_t len; + std::string meta; + } m_pkt; + + /* VM */ + StreamVm m_vm; + + /* RX check */ + struct { + bool m_enable; + bool m_seq_enabled; + bool m_latency; + uint32_t m_stream_id; + + } m_rx_check; + + + /* original template provided by requester */ + Json::Value m_stream_json; +}; + +/** + * continuous stream + * + */ +class TrexStreamContinuous : public TrexStream { +public: + TrexStreamContinuous(uint8_t port_id, uint32_t stream_id, double pps) : TrexStream(port_id, stream_id), m_pps(pps) { + } + + double get_pps() { + return m_pps; + } + +protected: + double m_pps; +}; + +/** + * single burst + * + */ +class TrexStreamBurst : public TrexStream { +public: + TrexStreamBurst(uint8_t port_id, uint32_t stream_id, uint32_t total_pkts, double pps) : + TrexStream(port_id, stream_id), + m_total_pkts(total_pkts), + m_pps(pps) { + } + +protected: + uint32_t m_total_pkts; + double m_pps; +}; + +/** + * multi burst + * + */ +class TrexStreamMultiBurst : public TrexStreamBurst { +public: + TrexStreamMultiBurst(uint8_t port_id, + uint32_t stream_id, + uint32_t pkts_per_burst, + double pps, + uint32_t num_bursts, + double ibg_usec) : TrexStreamBurst(port_id, stream_id, pkts_per_burst, pps), m_num_bursts(num_bursts), m_ibg_usec(ibg_usec) { + + } +protected: + uint32_t m_num_bursts; + double m_ibg_usec; + +}; + +/** + * holds all the streams + * + */ +class TrexStreamTable { +public: + + TrexStreamTable(); + ~TrexStreamTable(); + + /** + * add a stream + * if a previous one exists, the old one will be deleted + */ + void add_stream(TrexStream *stream); + + /** + * remove a stream + */ + void remove_stream(TrexStream *stream); + + /** + * remove all streams on the table + * memory will be deleted + */ + void remove_and_delete_all_streams(); + + /** + * fetch a stream if exists + * o.w NULL + * + */ + TrexStream * get_stream_by_id(uint32_t stream_id); + + /** + * populate a list with all the stream IDs + * + * @author imarom (06-Sep-15) + * + * @param stream_list + */ + void get_stream_list(std::vector &stream_list); + + /** + * get the table size + * + */ + int size(); + +private: + /** + * holds all the stream in a hash table by stream id + * + */ + std::unordered_map m_stream_table; +}; + +#endif /* __TREX_STREAM_API_H__ */ + diff --git a/src/stateless/cp/trex_stream_vm.cpp b/src/stateless/cp/trex_stream_vm.cpp new file mode 100644 index 00000000..2e760ae9 --- /dev/null +++ b/src/stateless/cp/trex_stream_vm.cpp @@ -0,0 +1,54 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#include + +/*************************** + * StreamVmInstruction + * + **************************/ +StreamVmInstruction::~StreamVmInstruction() { + +} + +/*************************** + * StreamVm + * + **************************/ +void StreamVm::add_instruction(StreamVmInstruction *inst) { + m_inst_list.push_back(inst); +} + +const std::vector & +StreamVm::get_instruction_list() { + return m_inst_list; +} + +bool StreamVm::compile() { + /* implement me */ + return (false); +} + +StreamVm::~StreamVm() { + for (auto inst : m_inst_list) { + delete inst; + } +} + diff --git a/src/stateless/cp/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h new file mode 100644 index 00000000..56edbcaf --- /dev/null +++ b/src/stateless/cp/trex_stream_vm.h @@ -0,0 +1,171 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#ifndef __TREX_STREAM_VM_API_H__ +#define __TREX_STREAM_VM_API_H__ + +#include +#include +#include + +/** + * interface for stream VM instruction + * + */ +class StreamVmInstruction { +public: + + virtual ~StreamVmInstruction(); + +private: + static const std::string m_name; +}; + +/** + * fix checksum for ipv4 + * + */ +class StreamVmInstructionFixChecksumIpv4 : public StreamVmInstruction { +public: + StreamVmInstructionFixChecksumIpv4(uint16_t offset) : m_pkt_offset(offset) { + + } + +private: + uint16_t m_pkt_offset; +}; + +/** + * flow manipulation instruction + * + * @author imarom (07-Sep-15) + */ +class StreamVmInstructionFlowMan : public StreamVmInstruction { + +public: + + /** + * different types of operations on the object + */ + enum flow_var_op_e { + FLOW_VAR_OP_INC, + FLOW_VAR_OP_DEC, + FLOW_VAR_OP_RANDOM + }; + + StreamVmInstructionFlowMan(const std::string &var_name, + uint8_t size, + flow_var_op_e op, + uint64_t init_value, + uint64_t min_value, + uint64_t max_value) : + m_var_name(var_name), + m_size_bytes(size), + m_op(op), + m_init_value(init_value), + m_min_value(min_value), + m_max_value(max_value) { + + } + +private: + + + /* flow var name */ + std::string m_var_name; + + /* flow var size */ + uint8_t m_size_bytes; + + /* type of op */ + flow_var_op_e m_op; + + /* range */ + uint64_t m_init_value; + uint64_t m_min_value; + uint64_t m_max_value; + + +}; + +/** + * write flow var to packet + * + */ +class StreamVmInstructionWriteToPkt : public StreamVmInstruction { +public: + + StreamVmInstructionWriteToPkt(const std::string &flow_var_name, + uint16_t pkt_offset, + int32_t add_value = 0, + bool is_big_endian = true) : + + m_flow_var_name(flow_var_name), + m_pkt_offset(pkt_offset), + m_add_value(add_value), + m_is_big_endian(is_big_endian) {} +private: + + /* flow var name to write */ + std::string m_flow_var_name; + + /* where to write */ + uint16_t m_pkt_offset; + + /* add/dec value from field when writing */ + int32_t m_add_value; + + /* writing endian */ + bool m_is_big_endian; +}; + +/** + * describes a VM program + * + */ +class StreamVm { +public: + + /** + * add new instruction to the VM + * + */ + void add_instruction(StreamVmInstruction *inst); + + /** + * get const access to the instruction list + * + */ + const std::vector & get_instruction_list(); + + /** + * compile the VM + * return true of success, o.w false + * + */ + bool compile(); + + ~StreamVm(); + +private: + std::vector m_inst_list; +}; + +#endif /* __TREX_STREAM_VM_API_H__ */ diff --git a/src/stateless/trex_stateless.cpp b/src/stateless/trex_stateless.cpp deleted file mode 100644 index 0b7947a0..00000000 --- a/src/stateless/trex_stateless.cpp +++ /dev/null @@ -1,137 +0,0 @@ -/* - Itay Marom - Cisco Systems, Inc. -*/ - -/* -Copyright (c) 2015-2015 Cisco Systems, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#include -#include - -using namespace std; - -/*********************************************************** - * Trex stateless object - * - **********************************************************/ -TrexStateless::TrexStateless() { - m_is_configured = false; -} - -/** - * one time configuration of the stateless object - * - */ -void TrexStateless::configure(uint8_t port_count) { - - TrexStateless& instance = get_instance_internal(); - - if (instance.m_is_configured) { - throw TrexException("re-configuration of stateless object is not allowed"); - } - - instance.m_port_count = port_count; - instance.m_ports = new TrexStatelessPort*[port_count]; - - for (int i = 0; i < instance.m_port_count; i++) { - instance.m_ports[i] = new TrexStatelessPort(i); - } - - instance.m_is_configured = true; -} - -TrexStateless::~TrexStateless() { - for (int i = 0; i < m_port_count; i++) { - delete m_ports[i]; - } - - delete [] m_ports; -} - -TrexStatelessPort * TrexStateless::get_port_by_id(uint8_t port_id) { - if (port_id >= m_port_count) { - throw TrexException("index out of range"); - } - - return m_ports[port_id]; - -} - -uint8_t TrexStateless::get_port_count() { - return m_port_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 - - /* for every port update and accumulate */ - for (uint8_t i = 0; i < m_port_count; i++) { - m_ports[i]->update_stats(); - - const TrexPortStats & port_stats = m_ports[i]->get_stats(); - - 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_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; - - 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; - - 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; - - m_stats.m_stats.m_tx_rx_errors += port_stats.m_stats.m_tx_rx_errors; - } -} - -void -TrexStateless::encode_stats(Json::Value &global) { - - global["cpu_util"] = m_stats.m_stats.m_cpu_util; - - global["tx_bps"] = m_stats.m_stats.m_tx_bps; - global["rx_bps"] = m_stats.m_stats.m_rx_bps; - - global["tx_pps"] = m_stats.m_stats.m_tx_pps; - global["rx_pps"] = m_stats.m_stats.m_rx_pps; - - 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); - - 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); - - global["tx_rx_errors"] = Json::Value::UInt64(m_stats.m_stats.m_tx_rx_errors); - - for (uint8_t i = 0; i < m_port_count; i++) { - std::stringstream ss; - - ss << "port " << i; - Json::Value &port_section = global[ss.str()]; - - m_ports[i]->encode_stats(port_section); - } -} - diff --git a/src/stateless/trex_stateless_api.h b/src/stateless/trex_stateless_api.h deleted file mode 100644 index e2bf4e1c..00000000 --- a/src/stateless/trex_stateless_api.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - Itay Marom - Cisco Systems, Inc. -*/ - -/* -Copyright (c) 2015-2015 Cisco Systems, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#ifndef __TREX_STATELESS_API_H__ -#define __TREX_STATELESS_API_H__ - -#include -#include -#include - -#include - -/** - * generic exception for errors - * TODO: move this to a better place - */ -class TrexException : public std::runtime_error -{ -public: - TrexException() : std::runtime_error("") { - - } - TrexException(const std::string &what) : std::runtime_error(what) { - } -}; - -class TrexStatelessPort; - -/** - * unified stats - * - * @author imarom (06-Oct-15) - */ -class TrexStatelessStats { -public: - TrexStatelessStats() { - m_stats = {0}; - } - - struct { - double m_cpu_util; - - double m_tx_bps; - double m_rx_bps; - - double m_tx_pps; - double m_rx_pps; - - uint64_t m_total_tx_pkts; - uint64_t m_total_rx_pkts; - - uint64_t m_total_tx_bytes; - uint64_t m_total_rx_bytes; - - uint64_t m_tx_rx_errors; - } m_stats; -}; - -/** - * defines the T-Rex stateless operation mode - * - */ -class TrexStateless { -public: - - /** - * configure the stateless object singelton - * reconfiguration is not allowed - * an exception will be thrown - */ - static void configure(uint8_t port_count); - - /** - * singleton public get instance - * - */ - static TrexStateless& get_instance() { - TrexStateless& instance = get_instance_internal(); - - if (!instance.m_is_configured) { - throw TrexException("object is not configured"); - } - - return instance; - } - - TrexStatelessPort * get_port_by_id(uint8_t port_id); - uint8_t get_port_count(); - - /** - * update all the stats (deep update) - * (include all the ports and global stats) - * - */ - void update_stats(); - - /** - * fetch all the stats - * - */ - void encode_stats(Json::Value &global); - - -protected: - TrexStateless(); - ~TrexStateless(); - - static TrexStateless& get_instance_internal () { - static TrexStateless instance; - return instance; - } - - /* c++ 2011 style singleton */ - TrexStateless(TrexStateless const&) = delete; - void operator=(TrexStateless const&) = delete; - - bool m_is_configured; - TrexStatelessPort **m_ports; - uint8_t m_port_count; - - TrexStatelessStats m_stats; -}; - -#endif /* __TREX_STATELESS_API_H__ */ - diff --git a/src/stateless/trex_stateless_port.cpp b/src/stateless/trex_stateless_port.cpp deleted file mode 100644 index 7322ef8a..00000000 --- a/src/stateless/trex_stateless_port.cpp +++ /dev/null @@ -1,172 +0,0 @@ -/* - Itay Marom - Cisco Systems, Inc. -*/ - -/* -Copyright (c) 2015-2015 Cisco Systems, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#include -#include -#include - -using namespace std; - -/*************************** - * trex stateless port - * - **************************/ -TrexStatelessPort::TrexStatelessPort(uint8_t port_id) : m_port_id(port_id) { - m_port_state = PORT_STATE_UP_IDLE; - clear_owner(); -} - - -/** - * starts the traffic on the port - * - */ -TrexStatelessPort::rc_e -TrexStatelessPort::start_traffic(void) { - - if (m_port_state != PORT_STATE_UP_IDLE) { - return (RC_ERR_BAD_STATE_FOR_OP); - } - - if (get_stream_table()->size() == 0) { - return (RC_ERR_NO_STREAMS); - } - - m_port_state = PORT_STATE_TRANSMITTING; - - /* real code goes here */ - return (RC_OK); -} - -void -TrexStatelessPort::stop_traffic(void) { - - /* real code goes here */ - if (m_port_state == PORT_STATE_TRANSMITTING) { - m_port_state = PORT_STATE_UP_IDLE; - } -} - -/** -* access the stream table -* -*/ -TrexStreamTable * TrexStatelessPort::get_stream_table() { - return &m_stream_table; -} - - -std::string -TrexStatelessPort::get_state_as_string() { - - switch (get_state()) { - case PORT_STATE_DOWN: - return "down"; - - case PORT_STATE_UP_IDLE: - return "idle"; - - case PORT_STATE_TRANSMITTING: - return "transmitting"; - } - - return "unknown"; -} - -void -TrexStatelessPort::get_properties(string &driver, string &speed) { - - /* take this from DPDK */ - driver = "e1000"; - speed = "1 Gbps"; -} - - -/** - * 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)]; - } - - return (ss.str()); -} - -/** - * update stats for the port - * - */ -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; - - 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); - - - 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; - - 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; - - #else - /* real update work */ - #endif -} - -const TrexPortStats & -TrexStatelessPort::get_stats() { - return m_stats; -} - -void -TrexStatelessPort::encode_stats(Json::Value &port) { - - port["tx_bps"] = m_stats.m_stats.m_tx_bps; - port["rx_bps"] = m_stats.m_stats.m_rx_bps; - - port["tx_pps"] = m_stats.m_stats.m_tx_pps; - port["rx_pps"] = m_stats.m_stats.m_rx_pps; - - port["total_tx_pkts"] = Json::Value::UInt64(m_stats.m_stats.m_total_tx_pkts); - port["total_rx_pkts"] = Json::Value::UInt64(m_stats.m_stats.m_total_rx_pkts); - - port["total_tx_bytes"] = Json::Value::UInt64(m_stats.m_stats.m_total_tx_bytes); - port["total_rx_bytes"] = Json::Value::UInt64(m_stats.m_stats.m_total_rx_bytes); - - port["tx_rx_errors"] = Json::Value::UInt64(m_stats.m_stats.m_tx_rx_errors); -} - - diff --git a/src/stateless/trex_stateless_port.h b/src/stateless/trex_stateless_port.h deleted file mode 100644 index ea98ddae..00000000 --- a/src/stateless/trex_stateless_port.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - Itay Marom - Cisco Systems, Inc. -*/ - -/* -Copyright (c) 2015-2015 Cisco Systems, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#ifndef __TREX_STATELESS_PORT_H__ -#define __TREX_STATELESS_PORT_H__ - -#include - -/** - * TRex stateless port stats - * - * @author imarom (24-Sep-15) - */ -class TrexPortStats { - -public: - TrexPortStats() { - m_stats = {0}; - } - -public: - struct { - - double m_tx_bps; - double m_rx_bps; - - double m_tx_pps; - double m_rx_pps; - - uint64_t m_total_tx_pkts; - uint64_t m_total_rx_pkts; - - uint64_t m_total_tx_bytes; - uint64_t m_total_rx_bytes; - - uint64_t m_tx_rx_errors; - } m_stats; -}; - -/** - * describes a stateless port - * - * @author imarom (31-Aug-15) - */ -class TrexStatelessPort { -public: - - /** - * port state - */ - enum port_state_e { - PORT_STATE_DOWN, - PORT_STATE_UP_IDLE, - PORT_STATE_TRANSMITTING - }; - - /** - * describess different error codes for port operations - */ - enum rc_e { - RC_OK, - RC_ERR_BAD_STATE_FOR_OP, - RC_ERR_NO_STREAMS, - RC_ERR_FAILED_TO_COMPILE_STREAMS - }; - - TrexStatelessPort(uint8_t port_id); - - /** - * start traffic - * - */ - rc_e start_traffic(void); - - /** - * stop traffic - * - */ - void stop_traffic(void); - - /** - * access the stream table - * - */ - TrexStreamTable *get_stream_table(); - - /** - * get the port state - * - */ - port_state_e get_state() { - return m_port_state; - } - - /** - * port state as string - * - */ - std::string get_state_as_string(); - - /** - * fill up properties of the port - * - * @author imarom (16-Sep-15) - * - * @param driver - * @param speed - */ - void get_properties(std::string &driver, std::string &speed); - - /** - * query for ownership - * - */ - const std::string &get_owner() { - return m_owner; - } - - /** - * owner handler - * for the connection - * - */ - const std::string &get_owner_handler() { - return m_owner_handler; - } - - bool is_free_to_aquire() { - return (m_owner == "none"); - } - - /** - * take ownership of the server array - * this is static - * ownership is total - * - */ - void set_owner(const std::string &owner) { - m_owner = owner; - m_owner_handler = generate_handler(); - } - - void clear_owner() { - m_owner = "none"; - m_owner_handler = ""; - } - - bool verify_owner_handler(const std::string &handler) { - - return ( (m_owner != "none") && (m_owner_handler == handler) ); - - } - - /** - * update the values of the stats - * - */ - void update_stats(); - - const TrexPortStats & get_stats(); - - /** - * encode stats as JSON - */ - void encode_stats(Json::Value &port); - -private: - - std::string generate_handler(); - - TrexStreamTable m_stream_table; - uint8_t m_port_id; - port_state_e m_port_state; - std::string m_owner; - std::string m_owner_handler; - TrexPortStats m_stats; -}; - -#endif /* __TREX_STATELESS_PORT_H__ */ diff --git a/src/stateless/trex_stream.cpp b/src/stateless/trex_stream.cpp deleted file mode 100644 index 8bf04748..00000000 --- a/src/stateless/trex_stream.cpp +++ /dev/null @@ -1,116 +0,0 @@ -/* - Itay Marom - Cisco Systems, Inc. -*/ - -/* -Copyright (c) 2015-2015 Cisco Systems, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#include -#include - -/************************************** - * stream - *************************************/ -TrexStream::TrexStream(uint8_t port_id, uint32_t stream_id) : m_port_id(port_id), m_stream_id(stream_id) { - - /* default values */ - m_isg_usec = 0; - m_next_stream_id = -1; - m_enabled = false; - m_self_start = false; - - m_pkt.binary = NULL; - m_pkt.len = 0; - - m_rx_check.m_enable = false; - -} - -TrexStream::~TrexStream() { - if (m_pkt.binary) { - delete [] m_pkt.binary; - } -} - -void -TrexStream::store_stream_json(const Json::Value &stream_json) { - /* deep copy */ - m_stream_json = stream_json; -} - -const Json::Value & -TrexStream::get_stream_json() { - return m_stream_json; -} - -/************************************** - * stream table - *************************************/ -TrexStreamTable::TrexStreamTable() { - -} - -TrexStreamTable::~TrexStreamTable() { - for (auto stream : m_stream_table) { - delete stream.second; - } -} - -void TrexStreamTable::add_stream(TrexStream *stream) { - TrexStream *old_stream = get_stream_by_id(stream->m_stream_id); - if (old_stream) { - remove_stream(old_stream); - delete old_stream; - } - - m_stream_table[stream->m_stream_id] = stream; -} - -void TrexStreamTable::remove_stream(TrexStream *stream) { - m_stream_table.erase(stream->m_stream_id); -} - - -void TrexStreamTable::remove_and_delete_all_streams() { - - for (auto stream : m_stream_table) { - delete stream.second; - } - - m_stream_table.clear(); -} - -TrexStream * TrexStreamTable::get_stream_by_id(uint32_t stream_id) { - auto search = m_stream_table.find(stream_id); - - if (search != m_stream_table.end()) { - return search->second; - } else { - return NULL; - } -} - -void TrexStreamTable::get_stream_list(std::vector &stream_list) { - stream_list.clear(); - - for (auto stream : m_stream_table) { - stream_list.push_back(stream.first); - } -} - -int TrexStreamTable::size() { - return m_stream_table.size(); -} diff --git a/src/stateless/trex_stream_api.h b/src/stateless/trex_stream_api.h deleted file mode 100644 index d3c0fb29..00000000 --- a/src/stateless/trex_stream_api.h +++ /dev/null @@ -1,209 +0,0 @@ -/* - Itay Marom - Cisco Systems, Inc. -*/ - -/* -Copyright (c) 2015-2015 Cisco Systems, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#ifndef __TREX_STREAM_API_H__ -#define __TREX_STREAM_API_H__ - -#include -#include -#include -#include - -#include - -#include - -class TrexRpcCmdAddStream; - -/** - * Stateless Stream - * - */ -class TrexStream { - /* provide the RPC parser a way to access private fields */ - friend class TrexRpcCmdAddStream; - friend class TrexRpcCmdGetStream; - friend class TrexStreamTable; - -public: - TrexStream(uint8_t port_id, uint32_t stream_id); - virtual ~TrexStream() = 0; - - /* defines the min max per packet supported */ - static const uint32_t MIN_PKT_SIZE_BYTES = 1; - static const uint32_t MAX_PKT_SIZE_BYTES = 9000; - - /* provides storage for the stream json*/ - void store_stream_json(const Json::Value &stream_json); - - /* access the stream json */ - const Json::Value & get_stream_json(); - -protected: - /* basic */ - uint8_t m_port_id; - uint32_t m_stream_id; - - - /* config fields */ - double m_isg_usec; - int m_next_stream_id; - - /* indicators */ - bool m_enabled; - bool m_self_start; - - /* pkt */ - struct { - uint8_t *binary; - uint16_t len; - std::string meta; - } m_pkt; - - /* VM */ - StreamVm m_vm; - - /* RX check */ - struct { - bool m_enable; - bool m_seq_enabled; - bool m_latency; - uint32_t m_stream_id; - - } m_rx_check; - - - /* original template provided by requester */ - Json::Value m_stream_json; -}; - -/** - * continuous stream - * - */ -class TrexStreamContinuous : public TrexStream { -public: - TrexStreamContinuous(uint8_t port_id, uint32_t stream_id, double pps) : TrexStream(port_id, stream_id), m_pps(pps) { - } - - double get_pps() { - return m_pps; - } - -protected: - double m_pps; -}; - -/** - * single burst - * - */ -class TrexStreamBurst : public TrexStream { -public: - TrexStreamBurst(uint8_t port_id, uint32_t stream_id, uint32_t total_pkts, double pps) : - TrexStream(port_id, stream_id), - m_total_pkts(total_pkts), - m_pps(pps) { - } - -protected: - uint32_t m_total_pkts; - double m_pps; -}; - -/** - * multi burst - * - */ -class TrexStreamMultiBurst : public TrexStreamBurst { -public: - TrexStreamMultiBurst(uint8_t port_id, - uint32_t stream_id, - uint32_t pkts_per_burst, - double pps, - uint32_t num_bursts, - double ibg_usec) : TrexStreamBurst(port_id, stream_id, pkts_per_burst, pps), m_num_bursts(num_bursts), m_ibg_usec(ibg_usec) { - - } -protected: - uint32_t m_num_bursts; - double m_ibg_usec; - -}; - -/** - * holds all the streams - * - */ -class TrexStreamTable { -public: - - TrexStreamTable(); - ~TrexStreamTable(); - - /** - * add a stream - * if a previous one exists, the old one will be deleted - */ - void add_stream(TrexStream *stream); - - /** - * remove a stream - */ - void remove_stream(TrexStream *stream); - - /** - * remove all streams on the table - * memory will be deleted - */ - void remove_and_delete_all_streams(); - - /** - * fetch a stream if exists - * o.w NULL - * - */ - TrexStream * get_stream_by_id(uint32_t stream_id); - - /** - * populate a list with all the stream IDs - * - * @author imarom (06-Sep-15) - * - * @param stream_list - */ - void get_stream_list(std::vector &stream_list); - - /** - * get the table size - * - */ - int size(); - -private: - /** - * holds all the stream in a hash table by stream id - * - */ - std::unordered_map m_stream_table; -}; - -#endif /* __TREX_STREAM_API_H__ */ - diff --git a/src/stateless/trex_stream_vm.cpp b/src/stateless/trex_stream_vm.cpp deleted file mode 100644 index 2e760ae9..00000000 --- a/src/stateless/trex_stream_vm.cpp +++ /dev/null @@ -1,54 +0,0 @@ -/* - Itay Marom - Cisco Systems, Inc. -*/ - -/* -Copyright (c) 2015-2015 Cisco Systems, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#include - -/*************************** - * StreamVmInstruction - * - **************************/ -StreamVmInstruction::~StreamVmInstruction() { - -} - -/*************************** - * StreamVm - * - **************************/ -void StreamVm::add_instruction(StreamVmInstruction *inst) { - m_inst_list.push_back(inst); -} - -const std::vector & -StreamVm::get_instruction_list() { - return m_inst_list; -} - -bool StreamVm::compile() { - /* implement me */ - return (false); -} - -StreamVm::~StreamVm() { - for (auto inst : m_inst_list) { - delete inst; - } -} - diff --git a/src/stateless/trex_stream_vm.h b/src/stateless/trex_stream_vm.h deleted file mode 100644 index 56edbcaf..00000000 --- a/src/stateless/trex_stream_vm.h +++ /dev/null @@ -1,171 +0,0 @@ -/* - Itay Marom - Cisco Systems, Inc. -*/ - -/* -Copyright (c) 2015-2015 Cisco Systems, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#ifndef __TREX_STREAM_VM_API_H__ -#define __TREX_STREAM_VM_API_H__ - -#include -#include -#include - -/** - * interface for stream VM instruction - * - */ -class StreamVmInstruction { -public: - - virtual ~StreamVmInstruction(); - -private: - static const std::string m_name; -}; - -/** - * fix checksum for ipv4 - * - */ -class StreamVmInstructionFixChecksumIpv4 : public StreamVmInstruction { -public: - StreamVmInstructionFixChecksumIpv4(uint16_t offset) : m_pkt_offset(offset) { - - } - -private: - uint16_t m_pkt_offset; -}; - -/** - * flow manipulation instruction - * - * @author imarom (07-Sep-15) - */ -class StreamVmInstructionFlowMan : public StreamVmInstruction { - -public: - - /** - * different types of operations on the object - */ - enum flow_var_op_e { - FLOW_VAR_OP_INC, - FLOW_VAR_OP_DEC, - FLOW_VAR_OP_RANDOM - }; - - StreamVmInstructionFlowMan(const std::string &var_name, - uint8_t size, - flow_var_op_e op, - uint64_t init_value, - uint64_t min_value, - uint64_t max_value) : - m_var_name(var_name), - m_size_bytes(size), - m_op(op), - m_init_value(init_value), - m_min_value(min_value), - m_max_value(max_value) { - - } - -private: - - - /* flow var name */ - std::string m_var_name; - - /* flow var size */ - uint8_t m_size_bytes; - - /* type of op */ - flow_var_op_e m_op; - - /* range */ - uint64_t m_init_value; - uint64_t m_min_value; - uint64_t m_max_value; - - -}; - -/** - * write flow var to packet - * - */ -class StreamVmInstructionWriteToPkt : public StreamVmInstruction { -public: - - StreamVmInstructionWriteToPkt(const std::string &flow_var_name, - uint16_t pkt_offset, - int32_t add_value = 0, - bool is_big_endian = true) : - - m_flow_var_name(flow_var_name), - m_pkt_offset(pkt_offset), - m_add_value(add_value), - m_is_big_endian(is_big_endian) {} -private: - - /* flow var name to write */ - std::string m_flow_var_name; - - /* where to write */ - uint16_t m_pkt_offset; - - /* add/dec value from field when writing */ - int32_t m_add_value; - - /* writing endian */ - bool m_is_big_endian; -}; - -/** - * describes a VM program - * - */ -class StreamVm { -public: - - /** - * add new instruction to the VM - * - */ - void add_instruction(StreamVmInstruction *inst); - - /** - * get const access to the instruction list - * - */ - const std::vector & get_instruction_list(); - - /** - * compile the VM - * return true of success, o.w false - * - */ - bool compile(); - - ~StreamVm(); - -private: - std::vector m_inst_list; -}; - -#endif /* __TREX_STREAM_VM_API_H__ */ -- cgit From 74b648a86c16933680b03a736afe3f0305b4f6d2 Mon Sep 17 00:00:00 2001 From: imarom Date: Thu, 8 Oct 2015 08:34:43 +0200 Subject: some file renaming --- src/stateless/cp/trex_stateless.cpp | 2 +- src/stateless/cp/trex_stateless.h | 142 +++++++++++++++++++++ src/stateless/cp/trex_stateless_api.h | 142 --------------------- src/stateless/cp/trex_stateless_port.cpp | 2 +- src/stateless/cp/trex_stateless_port.h | 2 +- src/stateless/cp/trex_stream.cpp | 2 +- src/stateless/cp/trex_stream.h | 209 +++++++++++++++++++++++++++++++ src/stateless/cp/trex_stream_api.h | 209 ------------------------------- 8 files changed, 355 insertions(+), 355 deletions(-) create mode 100644 src/stateless/cp/trex_stateless.h delete mode 100644 src/stateless/cp/trex_stateless_api.h create mode 100644 src/stateless/cp/trex_stream.h delete mode 100644 src/stateless/cp/trex_stream_api.h (limited to 'src/stateless') diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp index 0b7947a0..92f54bc4 100644 --- a/src/stateless/cp/trex_stateless.cpp +++ b/src/stateless/cp/trex_stateless.cpp @@ -18,7 +18,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include +#include #include using namespace std; diff --git a/src/stateless/cp/trex_stateless.h b/src/stateless/cp/trex_stateless.h new file mode 100644 index 00000000..74e88846 --- /dev/null +++ b/src/stateless/cp/trex_stateless.h @@ -0,0 +1,142 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#ifndef __TREX_STATELESS_H__ +#define __TREX_STATELESS_H__ + +#include +#include +#include + +#include + +/** + * generic exception for errors + * TODO: move this to a better place + */ +class TrexException : public std::runtime_error +{ +public: + TrexException() : std::runtime_error("") { + + } + TrexException(const std::string &what) : std::runtime_error(what) { + } +}; + +class TrexStatelessPort; + +/** + * unified stats + * + * @author imarom (06-Oct-15) + */ +class TrexStatelessStats { +public: + TrexStatelessStats() { + m_stats = {0}; + } + + struct { + double m_cpu_util; + + double m_tx_bps; + double m_rx_bps; + + double m_tx_pps; + double m_rx_pps; + + uint64_t m_total_tx_pkts; + uint64_t m_total_rx_pkts; + + uint64_t m_total_tx_bytes; + uint64_t m_total_rx_bytes; + + uint64_t m_tx_rx_errors; + } m_stats; +}; + +/** + * defines the T-Rex stateless operation mode + * + */ +class TrexStateless { +public: + + /** + * configure the stateless object singelton + * reconfiguration is not allowed + * an exception will be thrown + */ + static void configure(uint8_t port_count); + + /** + * singleton public get instance + * + */ + static TrexStateless& get_instance() { + TrexStateless& instance = get_instance_internal(); + + if (!instance.m_is_configured) { + throw TrexException("object is not configured"); + } + + return instance; + } + + TrexStatelessPort * get_port_by_id(uint8_t port_id); + uint8_t get_port_count(); + + /** + * update all the stats (deep update) + * (include all the ports and global stats) + * + */ + void update_stats(); + + /** + * fetch all the stats + * + */ + void encode_stats(Json::Value &global); + + +protected: + TrexStateless(); + ~TrexStateless(); + + static TrexStateless& get_instance_internal () { + static TrexStateless instance; + return instance; + } + + /* c++ 2011 style singleton */ + TrexStateless(TrexStateless const&) = delete; + void operator=(TrexStateless const&) = delete; + + bool m_is_configured; + TrexStatelessPort **m_ports; + uint8_t m_port_count; + + TrexStatelessStats m_stats; +}; + +#endif /* __TREX_STATELESS_H__ */ + diff --git a/src/stateless/cp/trex_stateless_api.h b/src/stateless/cp/trex_stateless_api.h deleted file mode 100644 index e2bf4e1c..00000000 --- a/src/stateless/cp/trex_stateless_api.h +++ /dev/null @@ -1,142 +0,0 @@ -/* - Itay Marom - Cisco Systems, Inc. -*/ - -/* -Copyright (c) 2015-2015 Cisco Systems, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#ifndef __TREX_STATELESS_API_H__ -#define __TREX_STATELESS_API_H__ - -#include -#include -#include - -#include - -/** - * generic exception for errors - * TODO: move this to a better place - */ -class TrexException : public std::runtime_error -{ -public: - TrexException() : std::runtime_error("") { - - } - TrexException(const std::string &what) : std::runtime_error(what) { - } -}; - -class TrexStatelessPort; - -/** - * unified stats - * - * @author imarom (06-Oct-15) - */ -class TrexStatelessStats { -public: - TrexStatelessStats() { - m_stats = {0}; - } - - struct { - double m_cpu_util; - - double m_tx_bps; - double m_rx_bps; - - double m_tx_pps; - double m_rx_pps; - - uint64_t m_total_tx_pkts; - uint64_t m_total_rx_pkts; - - uint64_t m_total_tx_bytes; - uint64_t m_total_rx_bytes; - - uint64_t m_tx_rx_errors; - } m_stats; -}; - -/** - * defines the T-Rex stateless operation mode - * - */ -class TrexStateless { -public: - - /** - * configure the stateless object singelton - * reconfiguration is not allowed - * an exception will be thrown - */ - static void configure(uint8_t port_count); - - /** - * singleton public get instance - * - */ - static TrexStateless& get_instance() { - TrexStateless& instance = get_instance_internal(); - - if (!instance.m_is_configured) { - throw TrexException("object is not configured"); - } - - return instance; - } - - TrexStatelessPort * get_port_by_id(uint8_t port_id); - uint8_t get_port_count(); - - /** - * update all the stats (deep update) - * (include all the ports and global stats) - * - */ - void update_stats(); - - /** - * fetch all the stats - * - */ - void encode_stats(Json::Value &global); - - -protected: - TrexStateless(); - ~TrexStateless(); - - static TrexStateless& get_instance_internal () { - static TrexStateless instance; - return instance; - } - - /* c++ 2011 style singleton */ - TrexStateless(TrexStateless const&) = delete; - void operator=(TrexStateless const&) = delete; - - bool m_is_configured; - TrexStatelessPort **m_ports; - uint8_t m_port_count; - - TrexStatelessStats m_stats; -}; - -#endif /* __TREX_STATELESS_API_H__ */ - diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 7322ef8a..031efb58 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -18,7 +18,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include +#include #include #include diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index ea98ddae..a19fd981 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -21,7 +21,7 @@ limitations under the License. #ifndef __TREX_STATELESS_PORT_H__ #define __TREX_STATELESS_PORT_H__ -#include +#include /** * TRex stateless port stats diff --git a/src/stateless/cp/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp index 8bf04748..182036f1 100644 --- a/src/stateless/cp/trex_stream.cpp +++ b/src/stateless/cp/trex_stream.cpp @@ -18,7 +18,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ -#include +#include #include /************************************** diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h new file mode 100644 index 00000000..f5bc96ef --- /dev/null +++ b/src/stateless/cp/trex_stream.h @@ -0,0 +1,209 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#ifndef __TREX_STREAM_H__ +#define __TREX_STREAM_H__ + +#include +#include +#include +#include + +#include + +#include + +class TrexRpcCmdAddStream; + +/** + * Stateless Stream + * + */ +class TrexStream { + /* provide the RPC parser a way to access private fields */ + friend class TrexRpcCmdAddStream; + friend class TrexRpcCmdGetStream; + friend class TrexStreamTable; + +public: + TrexStream(uint8_t port_id, uint32_t stream_id); + virtual ~TrexStream() = 0; + + /* defines the min max per packet supported */ + static const uint32_t MIN_PKT_SIZE_BYTES = 1; + static const uint32_t MAX_PKT_SIZE_BYTES = 9000; + + /* provides storage for the stream json*/ + void store_stream_json(const Json::Value &stream_json); + + /* access the stream json */ + const Json::Value & get_stream_json(); + +protected: + /* basic */ + uint8_t m_port_id; + uint32_t m_stream_id; + + + /* config fields */ + double m_isg_usec; + int m_next_stream_id; + + /* indicators */ + bool m_enabled; + bool m_self_start; + + /* pkt */ + struct { + uint8_t *binary; + uint16_t len; + std::string meta; + } m_pkt; + + /* VM */ + StreamVm m_vm; + + /* RX check */ + struct { + bool m_enable; + bool m_seq_enabled; + bool m_latency; + uint32_t m_stream_id; + + } m_rx_check; + + + /* original template provided by requester */ + Json::Value m_stream_json; +}; + +/** + * continuous stream + * + */ +class TrexStreamContinuous : public TrexStream { +public: + TrexStreamContinuous(uint8_t port_id, uint32_t stream_id, double pps) : TrexStream(port_id, stream_id), m_pps(pps) { + } + + double get_pps() { + return m_pps; + } + +protected: + double m_pps; +}; + +/** + * single burst + * + */ +class TrexStreamBurst : public TrexStream { +public: + TrexStreamBurst(uint8_t port_id, uint32_t stream_id, uint32_t total_pkts, double pps) : + TrexStream(port_id, stream_id), + m_total_pkts(total_pkts), + m_pps(pps) { + } + +protected: + uint32_t m_total_pkts; + double m_pps; +}; + +/** + * multi burst + * + */ +class TrexStreamMultiBurst : public TrexStreamBurst { +public: + TrexStreamMultiBurst(uint8_t port_id, + uint32_t stream_id, + uint32_t pkts_per_burst, + double pps, + uint32_t num_bursts, + double ibg_usec) : TrexStreamBurst(port_id, stream_id, pkts_per_burst, pps), m_num_bursts(num_bursts), m_ibg_usec(ibg_usec) { + + } +protected: + uint32_t m_num_bursts; + double m_ibg_usec; + +}; + +/** + * holds all the streams + * + */ +class TrexStreamTable { +public: + + TrexStreamTable(); + ~TrexStreamTable(); + + /** + * add a stream + * if a previous one exists, the old one will be deleted + */ + void add_stream(TrexStream *stream); + + /** + * remove a stream + */ + void remove_stream(TrexStream *stream); + + /** + * remove all streams on the table + * memory will be deleted + */ + void remove_and_delete_all_streams(); + + /** + * fetch a stream if exists + * o.w NULL + * + */ + TrexStream * get_stream_by_id(uint32_t stream_id); + + /** + * populate a list with all the stream IDs + * + * @author imarom (06-Sep-15) + * + * @param stream_list + */ + void get_stream_list(std::vector &stream_list); + + /** + * get the table size + * + */ + int size(); + +private: + /** + * holds all the stream in a hash table by stream id + * + */ + std::unordered_map m_stream_table; +}; + +#endif /* __TREX_STREAM_H__ */ + diff --git a/src/stateless/cp/trex_stream_api.h b/src/stateless/cp/trex_stream_api.h deleted file mode 100644 index d3c0fb29..00000000 --- a/src/stateless/cp/trex_stream_api.h +++ /dev/null @@ -1,209 +0,0 @@ -/* - Itay Marom - Cisco Systems, Inc. -*/ - -/* -Copyright (c) 2015-2015 Cisco Systems, Inc. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -#ifndef __TREX_STREAM_API_H__ -#define __TREX_STREAM_API_H__ - -#include -#include -#include -#include - -#include - -#include - -class TrexRpcCmdAddStream; - -/** - * Stateless Stream - * - */ -class TrexStream { - /* provide the RPC parser a way to access private fields */ - friend class TrexRpcCmdAddStream; - friend class TrexRpcCmdGetStream; - friend class TrexStreamTable; - -public: - TrexStream(uint8_t port_id, uint32_t stream_id); - virtual ~TrexStream() = 0; - - /* defines the min max per packet supported */ - static const uint32_t MIN_PKT_SIZE_BYTES = 1; - static const uint32_t MAX_PKT_SIZE_BYTES = 9000; - - /* provides storage for the stream json*/ - void store_stream_json(const Json::Value &stream_json); - - /* access the stream json */ - const Json::Value & get_stream_json(); - -protected: - /* basic */ - uint8_t m_port_id; - uint32_t m_stream_id; - - - /* config fields */ - double m_isg_usec; - int m_next_stream_id; - - /* indicators */ - bool m_enabled; - bool m_self_start; - - /* pkt */ - struct { - uint8_t *binary; - uint16_t len; - std::string meta; - } m_pkt; - - /* VM */ - StreamVm m_vm; - - /* RX check */ - struct { - bool m_enable; - bool m_seq_enabled; - bool m_latency; - uint32_t m_stream_id; - - } m_rx_check; - - - /* original template provided by requester */ - Json::Value m_stream_json; -}; - -/** - * continuous stream - * - */ -class TrexStreamContinuous : public TrexStream { -public: - TrexStreamContinuous(uint8_t port_id, uint32_t stream_id, double pps) : TrexStream(port_id, stream_id), m_pps(pps) { - } - - double get_pps() { - return m_pps; - } - -protected: - double m_pps; -}; - -/** - * single burst - * - */ -class TrexStreamBurst : public TrexStream { -public: - TrexStreamBurst(uint8_t port_id, uint32_t stream_id, uint32_t total_pkts, double pps) : - TrexStream(port_id, stream_id), - m_total_pkts(total_pkts), - m_pps(pps) { - } - -protected: - uint32_t m_total_pkts; - double m_pps; -}; - -/** - * multi burst - * - */ -class TrexStreamMultiBurst : public TrexStreamBurst { -public: - TrexStreamMultiBurst(uint8_t port_id, - uint32_t stream_id, - uint32_t pkts_per_burst, - double pps, - uint32_t num_bursts, - double ibg_usec) : TrexStreamBurst(port_id, stream_id, pkts_per_burst, pps), m_num_bursts(num_bursts), m_ibg_usec(ibg_usec) { - - } -protected: - uint32_t m_num_bursts; - double m_ibg_usec; - -}; - -/** - * holds all the streams - * - */ -class TrexStreamTable { -public: - - TrexStreamTable(); - ~TrexStreamTable(); - - /** - * add a stream - * if a previous one exists, the old one will be deleted - */ - void add_stream(TrexStream *stream); - - /** - * remove a stream - */ - void remove_stream(TrexStream *stream); - - /** - * remove all streams on the table - * memory will be deleted - */ - void remove_and_delete_all_streams(); - - /** - * fetch a stream if exists - * o.w NULL - * - */ - TrexStream * get_stream_by_id(uint32_t stream_id); - - /** - * populate a list with all the stream IDs - * - * @author imarom (06-Sep-15) - * - * @param stream_list - */ - void get_stream_list(std::vector &stream_list); - - /** - * get the table size - * - */ - int size(); - -private: - /** - * holds all the stream in a hash table by stream id - * - */ - std::unordered_map m_stream_table; -}; - -#endif /* __TREX_STREAM_API_H__ */ - -- cgit From 09c9d77dc2f5a89924bd27226727220801a5df13 Mon Sep 17 00:00:00 2001 From: imarom Date: Thu, 8 Oct 2015 10:23:33 +0200 Subject: fixed some bugs in the async server also added affinity to the stateless main object --- src/stateless/cp/trex_stateless.cpp | 63 +++++++++++++++++++++++++++++++------ src/stateless/cp/trex_stateless.h | 44 +++++++++++++++++++++++--- 2 files changed, 93 insertions(+), 14 deletions(-) (limited to 'src/stateless') diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp index 92f54bc4..1e7e2dfa 100644 --- a/src/stateless/cp/trex_stateless.cpp +++ b/src/stateless/cp/trex_stateless.cpp @@ -21,6 +21,8 @@ limitations under the License. #include #include +#include + using namespace std; /*********************************************************** @@ -31,36 +33,79 @@ TrexStateless::TrexStateless() { m_is_configured = false; } + /** - * one time configuration of the stateless object + * creates the singleton stateless object * */ -void TrexStateless::configure(uint8_t port_count) { +void TrexStateless::create(const TrexStatelessCfg &cfg) { TrexStateless& instance = get_instance_internal(); + /* check status */ if (instance.m_is_configured) { throw TrexException("re-configuration of stateless object is not allowed"); } - instance.m_port_count = port_count; - instance.m_ports = new TrexStatelessPort*[port_count]; + /* pin this process to the current running CPU + any new thread will be called on the same CPU + (control plane restriction) + */ + cpu_set_t mask; + CPU_ZERO(&mask); + CPU_SET(sched_getcpu(), &mask); + sched_setaffinity(0, sizeof(mask), &mask); + + /* start RPC servers */ + instance.m_rpc_server = new TrexRpcServer(cfg.m_rpc_req_resp_cfg, cfg.m_rpc_async_cfg); + instance.m_rpc_server->set_verbose(cfg.m_rpc_server_verbose); + instance.m_rpc_server->start(); + + /* configure ports */ + + instance.m_port_count = cfg.m_port_count; for (int i = 0; i < instance.m_port_count; i++) { - instance.m_ports[i] = new TrexStatelessPort(i); + instance.m_ports.push_back(new TrexStatelessPort(i)); } + /* done */ instance.m_is_configured = true; } -TrexStateless::~TrexStateless() { - for (int i = 0; i < m_port_count; i++) { - delete m_ports[i]; +/** + * destroy the singleton and release all memory + * + * @author imarom (08-Oct-15) + */ +void +TrexStateless::destroy() { + TrexStateless& instance = get_instance_internal(); + + if (!instance.m_is_configured) { + return; } - delete [] m_ports; + /* release memory for ports */ + for (auto port : instance.m_ports) { + delete port; + } + instance.m_ports.clear(); + + /* stops the RPC server */ + instance.m_rpc_server->stop(); + delete instance.m_rpc_server; + + instance.m_rpc_server = NULL; + + /* done */ + instance.m_is_configured = false; } +/** + * fetch a port by ID + * + */ TrexStatelessPort * TrexStateless::get_port_by_id(uint8_t port_id) { if (port_id >= m_port_count) { throw TrexException("index out of range"); diff --git a/src/stateless/cp/trex_stateless.h b/src/stateless/cp/trex_stateless.h index 74e88846..02eda7e2 100644 --- a/src/stateless/cp/trex_stateless.h +++ b/src/stateless/cp/trex_stateless.h @@ -26,6 +26,7 @@ limitations under the License. #include #include +#include /** * generic exception for errors @@ -73,6 +74,27 @@ public: } m_stats; }; +/** + * config object for stateless object + * + * @author imarom (08-Oct-15) + */ +class TrexStatelessCfg { +public: + /* default values */ + TrexStatelessCfg() { + m_port_count = 0; + m_rpc_req_resp_cfg = NULL; + m_rpc_async_cfg = NULL; + m_rpc_server_verbose = false; + } + + const TrexRpcServerConfig *m_rpc_req_resp_cfg; + const TrexRpcServerConfig *m_rpc_async_cfg; + bool m_rpc_server_verbose; + uint8_t m_port_count; +}; + /** * defines the T-Rex stateless operation mode * @@ -85,7 +107,13 @@ public: * reconfiguration is not allowed * an exception will be thrown */ - static void configure(uint8_t port_count); + static void create(const TrexStatelessCfg &cfg); + + /** + * destroy the instance + * + */ + static void destroy(); /** * singleton public get instance @@ -115,12 +143,11 @@ public: * fetch all the stats * */ - void encode_stats(Json::Value &global); + void encode_stats(Json::Value &global); protected: TrexStateless(); - ~TrexStateless(); static TrexStateless& get_instance_internal () { static TrexStateless instance; @@ -131,10 +158,17 @@ protected: TrexStateless(TrexStateless const&) = delete; void operator=(TrexStateless const&) = delete; + /* status */ bool m_is_configured; - TrexStatelessPort **m_ports; - uint8_t m_port_count; + /* RPC server array */ + TrexRpcServer *m_rpc_server; + + /* ports */ + std::vector m_ports; + uint8_t m_port_count; + + /* stats */ TrexStatelessStats m_stats; }; -- cgit From d7af282dc1cd629c251a937c9aa88a9a5a47030b Mon Sep 17 00:00:00 2001 From: imarom Date: Thu, 8 Oct 2015 17:39:51 +0200 Subject: first integration with DPDK layer --- src/stateless/cp/trex_stateless.cpp | 59 ++++++++++++++++++++++++++++--------- src/stateless/cp/trex_stateless.h | 27 ++++++++++++++--- 2 files changed, 68 insertions(+), 18 deletions(-) (limited to 'src/stateless') diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp index 1e7e2dfa..872fdd92 100644 --- a/src/stateless/cp/trex_stateless.cpp +++ b/src/stateless/cp/trex_stateless.cpp @@ -22,6 +22,8 @@ limitations under the License. #include #include +#include +#include using namespace std; @@ -35,10 +37,10 @@ TrexStateless::TrexStateless() { /** - * creates the singleton stateless object + * configure the singleton stateless object * */ -void TrexStateless::create(const TrexStatelessCfg &cfg) { +void TrexStateless::configure(const TrexStatelessCfg &cfg) { TrexStateless& instance = get_instance_internal(); @@ -47,19 +49,9 @@ void TrexStateless::create(const TrexStatelessCfg &cfg) { throw TrexException("re-configuration of stateless object is not allowed"); } - /* pin this process to the current running CPU - any new thread will be called on the same CPU - (control plane restriction) - */ - cpu_set_t mask; - CPU_ZERO(&mask); - CPU_SET(sched_getcpu(), &mask); - sched_setaffinity(0, sizeof(mask), &mask); - - /* start RPC servers */ + /* create RPC servers */ instance.m_rpc_server = new TrexRpcServer(cfg.m_rpc_req_resp_cfg, cfg.m_rpc_async_cfg); instance.m_rpc_server->set_verbose(cfg.m_rpc_server_verbose); - instance.m_rpc_server->start(); /* configure ports */ @@ -69,10 +61,43 @@ void TrexStateless::create(const TrexStatelessCfg &cfg) { instance.m_ports.push_back(new TrexStatelessPort(i)); } + /* cores */ + instance.m_dp_core_count = cfg.m_dp_core_count; + /* done */ instance.m_is_configured = true; } +/** + * starts the control plane side + * + */ +void +TrexStateless::launch_control_plane() { + //std::cout << "\n on control/master core \n"; + + /* pin this process to the current running CPU + any new thread will be called on the same CPU + (control plane restriction) + */ + cpu_set_t mask; + CPU_ZERO(&mask); + CPU_SET(sched_getcpu(), &mask); + sched_setaffinity(0, sizeof(mask), &mask); + + /* start RPC server */ + m_rpc_server->start(); +} + +void +TrexStateless::launch_on_dp_core() { + //std::cout << "\n on DP core \n"; + + while (true) { + sleep(1); + } +} + /** * destroy the singleton and release all memory * @@ -115,10 +140,16 @@ TrexStatelessPort * TrexStateless::get_port_by_id(uint8_t port_id) { } -uint8_t TrexStateless::get_port_count() { +uint8_t +TrexStateless::get_port_count() { return m_port_count; } +uint8_t +TrexStateless::get_dp_core_count() { + return m_dp_core_count; +} + void TrexStateless::update_stats() { diff --git a/src/stateless/cp/trex_stateless.h b/src/stateless/cp/trex_stateless.h index 02eda7e2..5c674fd6 100644 --- a/src/stateless/cp/trex_stateless.h +++ b/src/stateless/cp/trex_stateless.h @@ -83,9 +83,10 @@ class TrexStatelessCfg { public: /* default values */ TrexStatelessCfg() { - m_port_count = 0; - m_rpc_req_resp_cfg = NULL; - m_rpc_async_cfg = NULL; + m_port_count = 0; + m_dp_core_count = 0; + m_rpc_req_resp_cfg = NULL; + m_rpc_async_cfg = NULL; m_rpc_server_verbose = false; } @@ -93,6 +94,7 @@ public: const TrexRpcServerConfig *m_rpc_async_cfg; bool m_rpc_server_verbose; uint8_t m_port_count; + uint8_t m_dp_core_count; }; /** @@ -107,7 +109,7 @@ public: * reconfiguration is not allowed * an exception will be thrown */ - static void create(const TrexStatelessCfg &cfg); + static void configure(const TrexStatelessCfg &cfg); /** * destroy the instance @@ -129,9 +131,23 @@ public: return instance; } + /** + * starts the control plane side + * + */ + void launch_control_plane(); + + /** + * launch on a single DP core + * + */ + void launch_on_dp_core(); + TrexStatelessPort * get_port_by_id(uint8_t port_id); uint8_t get_port_count(); + uint8_t get_dp_core_count(); + /** * update all the stats (deep update) * (include all the ports and global stats) @@ -168,6 +184,9 @@ protected: std::vector m_ports; uint8_t m_port_count; + /* cores */ + uint8_t m_dp_core_count; + /* stats */ TrexStatelessStats m_stats; }; -- cgit From 3b827c9584c28d3f1f573e372f646edfe9f5f007 Mon Sep 17 00:00:00 2001 From: imarom Date: Sun, 11 Oct 2015 10:18:01 +0200 Subject: some DP base files --- src/stateless/cp/trex_stateless.cpp | 11 ++++---- src/stateless/cp/trex_stateless.h | 11 +++++--- src/stateless/cp/trex_stateless_port.cpp | 13 ++++++++- src/stateless/dp/trex_stateless_dp_core.cpp | 37 +++++++++++++++++++++++++ src/stateless/dp/trex_stateless_dp_core.h | 42 +++++++++++++++++++++++++++++ 5 files changed, 103 insertions(+), 11 deletions(-) create mode 100644 src/stateless/dp/trex_stateless_dp_core.cpp create mode 100644 src/stateless/dp/trex_stateless_dp_core.h (limited to 'src/stateless') diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp index 872fdd92..20e001c9 100644 --- a/src/stateless/cp/trex_stateless.cpp +++ b/src/stateless/cp/trex_stateless.cpp @@ -63,6 +63,9 @@ void TrexStateless::configure(const TrexStatelessCfg &cfg) { /* cores */ instance.m_dp_core_count = cfg.m_dp_core_count; + for (int i = 0; i < instance.m_dp_core_count; i++) { + instance.m_dp_cores.push_back(new TrexStatelessDpCore(i)); + } /* done */ instance.m_is_configured = true; @@ -90,12 +93,8 @@ TrexStateless::launch_control_plane() { } void -TrexStateless::launch_on_dp_core() { - //std::cout << "\n on DP core \n"; - - while (true) { - sleep(1); - } +TrexStateless::launch_on_dp_core(uint8_t core_id) { + m_dp_cores[core_id - 1]->run(); } /** diff --git a/src/stateless/cp/trex_stateless.h b/src/stateless/cp/trex_stateless.h index 5c674fd6..ef612e84 100644 --- a/src/stateless/cp/trex_stateless.h +++ b/src/stateless/cp/trex_stateless.h @@ -26,6 +26,8 @@ limitations under the License. #include #include +#include +#include #include /** @@ -141,7 +143,7 @@ public: * launch on a single DP core * */ - void launch_on_dp_core(); + void launch_on_dp_core(uint8_t core_id); TrexStatelessPort * get_port_by_id(uint8_t port_id); uint8_t get_port_count(); @@ -181,11 +183,12 @@ protected: TrexRpcServer *m_rpc_server; /* ports */ - std::vector m_ports; - uint8_t m_port_count; + std::vector m_ports; + uint8_t m_port_count; /* cores */ - uint8_t m_dp_core_count; + std::vector m_dp_cores; + uint8_t m_dp_core_count; /* stats */ TrexStatelessStats m_stats; diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index 031efb58..240b7582 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -22,6 +22,13 @@ limitations under the License. #include #include +// DPDK c++ issue +#define UINT8_MAX 255 +#define UINT16_MAX 0xFFFF +// DPDK c++ issue + +#include + using namespace std; /*************************** @@ -143,7 +150,11 @@ TrexStatelessPort::update_stats() { #else /* real update work */ - #endif + 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 & diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp new file mode 100644 index 00000000..4e9309ab --- /dev/null +++ b/src/stateless/dp/trex_stateless_dp_core.cpp @@ -0,0 +1,37 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include +#include +#include +#include + +TrexStatelessDpCore::TrexStatelessDpCore(uint8_t core_id) : m_core_id(core_id) { +} + +void +TrexStatelessDpCore::run() { + printf("On DP core %d\n", m_core_id); + while (true) { + sleep(1); + TrexStateless::get_instance().get_port_by_id(0)->update_stats(); + } +} diff --git a/src/stateless/dp/trex_stateless_dp_core.h b/src/stateless/dp/trex_stateless_dp_core.h new file mode 100644 index 00000000..d428bac2 --- /dev/null +++ b/src/stateless/dp/trex_stateless_dp_core.h @@ -0,0 +1,42 @@ +/* + Itay Marom + Cisco Systems, Inc. +*/ + +/* +Copyright (c) 2015-2015 Cisco Systems, Inc. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ +#ifndef __TREX_STATELESS_DP_CORE_H__ +#define __TREX_STATELESS_DP_CORE_H__ + +#include + +/** + * stateless DP core object + * + */ +class TrexStatelessDpCore { +public: + + TrexStatelessDpCore(uint8_t core_id); + + /* starts the DP core run */ + void run(); + +private: + uint8_t m_core_id; +}; + +#endif /* __TREX_STATELESS_DP_CORE_H__ */ -- cgit From 6c7880b9881ed6690954f0c29259dd0b584b3970 Mon Sep 17 00:00:00 2001 From: imarom Date: Sun, 11 Oct 2015 14:42:24 +0200 Subject: DP cores now inject a single packet as a dummy to see stats --- src/stateless/cp/trex_stateless.cpp | 14 ++-- src/stateless/cp/trex_stateless.h | 4 ++ src/stateless/cp/trex_stateless_port.cpp | 77 ++++++++++++++++----- src/stateless/cp/trex_stateless_port.h | 34 ++++++++++ src/stateless/dp/trex_stateless_dp_core.cpp | 101 +++++++++++++++++++++++++++- src/stateless/dp/trex_stateless_dp_core.h | 1 + 6 files changed, 204 insertions(+), 27 deletions(-) (limited to 'src/stateless') 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 #include +#include + #include #include #include @@ -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 +#include 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) +/** + * 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 * @@ -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 #include +#include + +// DPDK c++ issue +#define UINT8_MAX 255 +#define UINT16_MAX 0xFFFF +// DPDK c++ issue + +#include +#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; }; -- cgit From 51ad078182d17b42a36c239c3c21381eeb3eec85 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Mon, 19 Oct 2015 17:40:53 +0300 Subject: fix new compiler warning issue in stateless --- src/stateless/cp/trex_stateless_port.cpp | 2 ++ src/stateless/dp/trex_stateless_dp_core.cpp | 3 +++ 2 files changed, 5 insertions(+) (limited to 'src/stateless') diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index f745bee9..a31847a5 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -22,10 +22,12 @@ limitations under the License. #include #include +#ifndef TREX_RPC_MOCK_SERVER // DPDK c++ issue #define UINT8_MAX 255 #define UINT16_MAX 0xFFFF // DPDK c++ issue +#endif #include #include diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp index 1c96487d..3755b82c 100644 --- a/src/stateless/dp/trex_stateless_dp_core.cpp +++ b/src/stateless/dp/trex_stateless_dp_core.cpp @@ -26,10 +26,13 @@ limitations under the License. #include +#ifndef TREX_RPC_MOCK_SERVER + // DPDK c++ issue #define UINT8_MAX 255 #define UINT16_MAX 0xFFFF // DPDK c++ issue +#endif #include #include "mbuf.h" -- cgit