diff options
Diffstat (limited to 'src/stateless')
-rw-r--r-- | src/stateless/cp/trex_stateless.cpp | 212 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless.h | 202 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.cpp | 226 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.h (renamed from src/stateless/trex_stateless_api.h) | 158 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream.cpp (renamed from src/stateless/trex_stream.cpp) | 2 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream.h (renamed from src/stateless/trex_stream_api.h) | 6 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream_vm.cpp (renamed from src/stateless/trex_stream_vm.cpp) | 0 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream_vm.h (renamed from src/stateless/trex_stream_vm.h) | 0 | ||||
-rw-r--r-- | src/stateless/dp/trex_stateless_dp_core.cpp | 132 | ||||
-rw-r--r-- | src/stateless/dp/trex_stateless_dp_core.h | 43 | ||||
-rw-r--r-- | src/stateless/trex_stateless.cpp | 171 |
11 files changed, 891 insertions, 261 deletions
diff --git a/src/stateless/cp/trex_stateless.cpp b/src/stateless/cp/trex_stateless.cpp new file mode 100644 index 00000000..72762e26 --- /dev/null +++ b/src/stateless/cp/trex_stateless.cpp @@ -0,0 +1,212 @@ +/* + 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 <trex_stateless.h> +#include <trex_stateless_port.h> + +#include <sched.h> +#include <iostream> +#include <unistd.h> + +using namespace std; + +/*********************************************************** + * Trex stateless object + * + **********************************************************/ +TrexStateless::TrexStateless() { + m_is_configured = false; +} + + +/** + * configure the singleton stateless object + * + */ +void TrexStateless::configure(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"); + } + + /* create RPC servers */ + + /* 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 */ + + instance.m_port_count = cfg.m_port_count; + + for (int i = 0; i < instance.m_port_count; i++) { + instance.m_ports.push_back(new TrexStatelessPort(i)); + } + + /* 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; +} + +/** + * 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(uint8_t core_id) { + m_dp_cores[core_id - 1]->run(); +} + +/** + * 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; + } + + /* 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"); + } + + return m_ports[port_id]; + +} + +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() { + + /* 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++) { + 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.h b/src/stateless/cp/trex_stateless.h new file mode 100644 index 00000000..649b25dd --- /dev/null +++ b/src/stateless/cp/trex_stateless.h @@ -0,0 +1,202 @@ +/* + 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 <stdint.h> +#include <string> +#include <stdexcept> + +#include <mutex> + +#include <trex_stream.h> +#include <trex_stateless_port.h> +#include <trex_stateless_dp_core.h> +#include <trex_rpc_server_api.h> + +/** + * 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; +}; + +/** + * config object for stateless object + * + * @author imarom (08-Oct-15) + */ +class TrexStatelessCfg { +public: + /* default values */ + TrexStatelessCfg() { + 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; + } + + const TrexRpcServerConfig *m_rpc_req_resp_cfg; + const TrexRpcServerConfig *m_rpc_async_cfg; + bool m_rpc_server_verbose; + uint8_t m_port_count; + uint8_t m_dp_core_count; +}; + +/** + * 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(const TrexStatelessCfg &cfg); + + /** + * destroy the instance + * + */ + static void destroy(); + + /** + * 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; + } + + /** + * starts the control plane side + * + */ + void launch_control_plane(); + + /** + * launch on a single 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(); + + uint8_t get_dp_core_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(); + + static TrexStateless& get_instance_internal () { + static TrexStateless instance; + return instance; + } + + /* c++ 2011 style singleton */ + TrexStateless(TrexStateless const&) = delete; + void operator=(TrexStateless const&) = delete; + + /* status */ + bool m_is_configured; + + /* RPC server array */ + TrexRpcServer *m_rpc_server; + + /* ports */ + std::vector <TrexStatelessPort *> m_ports; + uint8_t m_port_count; + + /* cores */ + std::vector <TrexStatelessDpCore *> m_dp_cores; + uint8_t m_dp_core_count; + + /* 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 new file mode 100644 index 00000000..f745bee9 --- /dev/null +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -0,0 +1,226 @@ +/* + 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 <trex_stateless.h> +#include <trex_stateless_port.h> +#include <string> + +// DPDK c++ issue +#define UINT8_MAX 255 +#define UINT16_MAX 0xFFFF +// DPDK c++ issue + +#include <rte_ethdev.h> +#include <os_time.h> + +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() { + struct rte_eth_stats stats; + rte_eth_stats_get(m_port_id, &stats); + + /* 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; + + /* 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_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); + +} + +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); +} + + + +/*************************** + * BW measurement + * + **************************/ +/* TODO: move this to a common place */ +BWMeasure::BWMeasure() { + reset(); +} + +void BWMeasure::reset(void) { + m_start=false; + m_last_time_msec=0; + m_last_bytes=0; + m_last_result=0.0; +}; + +double BWMeasure::calc_MBsec(uint32_t dtime_msec, + uint64_t dbytes){ + double rate=0.000008*( ( (double)dbytes*(double)os_get_time_freq())/((double)dtime_msec) ); + return(rate); +} + +double BWMeasure::add(uint64_t size) { + if ( false == m_start ) { + m_start=true; + m_last_time_msec = os_get_time_msec() ; + m_last_bytes=size; + return(0.0); + } + + uint32_t ctime=os_get_time_msec(); + if ((ctime - m_last_time_msec) <os_get_time_freq() ) { + return(m_last_result); + } + + uint32_t dtime_msec = ctime-m_last_time_msec; + uint64_t dbytes = size - m_last_bytes; + + m_last_time_msec = ctime; + m_last_bytes = size; + + m_last_result= 0.5*calc_MBsec(dtime_msec,dbytes) +0.5*(m_last_result); + return( m_last_result ); +} + + diff --git a/src/stateless/trex_stateless_api.h b/src/stateless/cp/trex_stateless_port.h index 7a9080aa..428d5aee 100644 --- a/src/stateless/trex_stateless_api.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -18,27 +18,74 @@ 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__ +#ifndef __TREX_STATELESS_PORT_H__ +#define __TREX_STATELESS_PORT_H__ -#include <stdint.h> -#include <string> -#include <stdexcept> +#include <trex_stream.h> -#include <trex_stream_api.h> +/** + * bandwidth measurement class + * + */ +class BWMeasure { +public: + BWMeasure(); + void reset(void); + double add(uint64_t size); + +private: + double calc_MBsec(uint32_t dtime_msec, + uint64_t dbytes); + +public: + bool m_start; + uint32_t m_last_time_msec; + uint64_t m_last_bytes; + double m_last_result; +}; /** - * generic exception for errors - * TODO: move this to a better place + * TRex stateless port stats + * + * @author imarom (24-Sep-15) */ -class TrexException : public std::runtime_error -{ +class TrexPortStats { + public: - TrexException() : std::runtime_error("") { + TrexPortStats() { + m_stats = {0}; + m_bw_tx_bps.reset(); + m_bw_rx_bps.reset(); + + m_bw_tx_pps.reset(); + m_bw_rx_pps.reset(); } - TrexException(const std::string &what) : std::runtime_error(what) { - } + +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; + 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; }; /** @@ -49,20 +96,6 @@ public: class TrexStatelessPort { public: - struct TrexPortStats { - 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; - }; - /** * port state */ @@ -169,15 +202,18 @@ 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; + /** + * update the values of the stats + * + */ + void update_stats(); + + const TrexPortStats & get_stats(); - return m_stats; - } + /** + * encode stats as JSON + */ + void encode_stats(Json::Value &port); private: @@ -191,54 +227,4 @@ private: TrexPortStats 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(); - -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; -}; - -#endif /* __TREX_STATELESS_API_H__ */ - +#endif /* __TREX_STATELESS_PORT_H__ */ diff --git a/src/stateless/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp index 8bf04748..182036f1 100644 --- a/src/stateless/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 <trex_stream_api.h> +#include <trex_stream.h> #include <cstddef> /************************************** diff --git a/src/stateless/trex_stream_api.h b/src/stateless/cp/trex_stream.h index d3c0fb29..f5bc96ef 100644 --- a/src/stateless/trex_stream_api.h +++ b/src/stateless/cp/trex_stream.h @@ -18,8 +18,8 @@ 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__ +#ifndef __TREX_STREAM_H__ +#define __TREX_STREAM_H__ #include <unordered_map> #include <vector> @@ -205,5 +205,5 @@ private: std::unordered_map<int, TrexStream *> m_stream_table; }; -#endif /* __TREX_STREAM_API_H__ */ +#endif /* __TREX_STREAM_H__ */ diff --git a/src/stateless/trex_stream_vm.cpp b/src/stateless/cp/trex_stream_vm.cpp index 2e760ae9..2e760ae9 100644 --- a/src/stateless/trex_stream_vm.cpp +++ b/src/stateless/cp/trex_stream_vm.cpp diff --git a/src/stateless/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h index 56edbcaf..56edbcaf 100644 --- a/src/stateless/trex_stream_vm.h +++ b/src/stateless/cp/trex_stream_vm.h 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..1c96487d --- /dev/null +++ b/src/stateless/dp/trex_stateless_dp_core.cpp @@ -0,0 +1,132 @@ +/* + 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 <trex_stateless_dp_core.h> +#include <stdio.h> +#include <unistd.h> +#include <trex_stateless.h> + +#include <bp_sim.h> + +// DPDK c++ issue +#define UINT8_MAX 255 +#define UINT16_MAX 0xFFFF +// DPDK c++ issue + +#include <rte_ethdev.h> +#include "mbuf.h" + +/** + * TEST + * + */ +static const uint8_t udp_pkt[]={ + 0x00,0x00,0x00,0x01,0x00,0x00, + 0x00,0x00,0x00,0x01,0x00,0x00, + 0x08,0x00, + + 0x45,0x00,0x00,0x81, + 0xaf,0x7e,0x00,0x00, + 0x12,0x11,0xd9,0x23, + 0x01,0x01,0x01,0x01, + 0x3d,0xad,0x72,0x1b, + + 0x11,0x11, + 0x11,0x11, + + 0x00,0x6d, + 0x00,0x00, + + 0x64,0x31,0x3a,0x61, + 0x64,0x32,0x3a,0x69,0x64, + 0x32,0x30,0x3a,0xd0,0x0e, + 0xa1,0x4b,0x7b,0xbd,0xbd, + 0x16,0xc6,0xdb,0xc4,0xbb,0x43, + 0xf9,0x4b,0x51,0x68,0x33,0x72, + 0x20,0x39,0x3a,0x69,0x6e,0x66,0x6f, + 0x5f,0x68,0x61,0x73,0x68,0x32,0x30,0x3a,0xee,0xc6,0xa3, + 0xd3,0x13,0xa8,0x43,0x06,0x03,0xd8,0x9e,0x3f,0x67,0x6f, + 0xe7,0x0a,0xfd,0x18,0x13,0x8d,0x65,0x31,0x3a,0x71,0x39, + 0x3a,0x67,0x65,0x74,0x5f,0x70,0x65,0x65,0x72,0x73,0x31, + 0x3a,0x74,0x38,0x3a,0x3d,0xeb,0x0c,0xbf,0x0d,0x6a,0x0d, + 0xa5,0x31,0x3a,0x79,0x31,0x3a,0x71,0x65,0x87,0xa6,0x7d, + 0xe7 +}; + +static int +test_inject_pkt(uint8_t *pkt, uint32_t pkt_size) { + + #ifndef TREX_RPC_MOCK_SERVER + rte_mempool_t * mp= CGlobalInfo::m_mem_pool[0].m_big_mbuf_pool ; + #else + rte_mempool_t * mp = NULL; + #endif + + rte_mbuf_t *m = rte_pktmbuf_alloc(mp); + if ( unlikely(m==0) ) { + printf("ERROR no packets \n"); + return (-1); + } + char *p = rte_pktmbuf_append(m, pkt_size); + assert(p); + /* set pkt data */ + memcpy(p,pkt,pkt_size); + + rte_mbuf_t *tx_pkts[32]; + tx_pkts[0] = m; + uint8_t nb_pkts = 1; + uint16_t ret = rte_eth_tx_burst(0, 0, tx_pkts, nb_pkts); + (void)ret; + rte_pktmbuf_free(m); + + return (0); +} + +static int +test_inject_udp_pkt(){ + return (test_inject_pkt((uint8_t*)udp_pkt,sizeof(udp_pkt))); +} + +void +TrexStatelessDpCore::test_inject_dummy_pkt() { + test_inject_udp_pkt(); +} + +/*************************** + * DP core + * + **************************/ +TrexStatelessDpCore::TrexStatelessDpCore(uint8_t core_id) : m_core_id(core_id) { +} + +/** + * main function for DP core + * + */ +void +TrexStatelessDpCore::run() { + printf("\nOn DP core %d\n", m_core_id); + while (true) { + 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 new file mode 100644 index 00000000..4b09b752 --- /dev/null +++ b/src/stateless/dp/trex_stateless_dp_core.h @@ -0,0 +1,43 @@ +/* + 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 <stdint.h> + +/** + * stateless DP core object + * + */ +class TrexStatelessDpCore { +public: + + TrexStatelessDpCore(uint8_t core_id); + + /* starts the DP core run */ + void run(); + +private: + void test_inject_dummy_pkt(); + uint8_t m_core_id; +}; + +#endif /* __TREX_STATELESS_DP_CORE_H__ */ diff --git a/src/stateless/trex_stateless.cpp b/src/stateless/trex_stateless.cpp deleted file mode 100644 index 0eb96f05..00000000 --- a/src/stateless/trex_stateless.cpp +++ /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. -*/ -#include <trex_stateless_api.h> - -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; -} - -/*************************** - * trex stateless port - * - **************************/ -TrexStatelessPort::TrexStatelessPort(uint8_t port_id) : m_port_id(port_id) { - m_port_state = PORT_STATE_UP_IDLE; - clear_owner(); - m_stats = {0}; -} - - -/** - * 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()); -} |