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/rpc-server/commands/trex_rpc_cmd_general.cpp | 18 +++++++------- src/stateless/trex_stateless.cpp | 10 +++++++- src/stateless/trex_stateless_api.h | 30 +++++++++++++++++------- 3 files changed, 39 insertions(+), 19 deletions(-) (limited to 'src') diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index 0c9f2c49..940baf3d 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -271,17 +271,17 @@ TrexRpcCmdGetPortStats::_run(const Json::Value ¶ms, Json::Value &result) { result["result"]["status"] = port->get_state_as_string(); - result["result"]["tx_bps"] = Json::Value::UInt64(port->get_port_stats().tx_bps); - result["result"]["tx_pps"] = Json::Value::UInt64(port->get_port_stats().tx_pps); - result["result"]["total_tx_pkts"] = Json::Value::UInt64(port->get_port_stats().total_tx_pkts); - result["result"]["total_tx_bytes"] = Json::Value::UInt64(port->get_port_stats().total_tx_bytes); + result["result"]["tx_bps"] = Json::Value::UInt64(port->get_port_stats().m_stats.tx_bps); + result["result"]["tx_pps"] = Json::Value::UInt64(port->get_port_stats().m_stats.tx_pps); + result["result"]["total_tx_pkts"] = Json::Value::UInt64(port->get_port_stats().m_stats.total_tx_pkts); + result["result"]["total_tx_bytes"] = Json::Value::UInt64(port->get_port_stats().m_stats.total_tx_bytes); - result["result"]["rx_bps"] = Json::Value::UInt64(port->get_port_stats().rx_bps); - result["result"]["rx_pps"] = Json::Value::UInt64(port->get_port_stats().rx_pps); - result["result"]["total_rx_pkts"] = Json::Value::UInt64(port->get_port_stats().total_rx_pkts); - result["result"]["total_rx_bytes"] = Json::Value::UInt64(port->get_port_stats().total_rx_bytes); + result["result"]["rx_bps"] = Json::Value::UInt64(port->get_port_stats().m_stats.rx_bps); + result["result"]["rx_pps"] = Json::Value::UInt64(port->get_port_stats().m_stats.rx_pps); + result["result"]["total_rx_pkts"] = Json::Value::UInt64(port->get_port_stats().m_stats.total_rx_pkts); + result["result"]["total_rx_bytes"] = Json::Value::UInt64(port->get_port_stats().m_stats.total_rx_bytes); - result["result"]["tx_rx_error"] = Json::Value::UInt64(port->get_port_stats().tx_rx_errors); + result["result"]["tx_rx_error"] = Json::Value::UInt64(port->get_port_stats().m_stats.tx_rx_errors); return (TREX_RPC_CMD_OK); } 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/rpc-server/commands/trex_rpc_cmd_general.cpp | 18 +++--- src/rpc-server/trex_rpc_async_server.cpp | 77 ++++++++++++++++++++++++ src/rpc-server/trex_rpc_async_server.h | 53 ++++++++++++++++ src/stateless/trex_stateless_api.h | 13 ++-- 4 files changed, 146 insertions(+), 15 deletions(-) create mode 100644 src/rpc-server/trex_rpc_async_server.cpp create mode 100644 src/rpc-server/trex_rpc_async_server.h (limited to 'src') diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index 940baf3d..7721526c 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -271,17 +271,17 @@ TrexRpcCmdGetPortStats::_run(const Json::Value ¶ms, Json::Value &result) { result["result"]["status"] = port->get_state_as_string(); - result["result"]["tx_bps"] = Json::Value::UInt64(port->get_port_stats().m_stats.tx_bps); - result["result"]["tx_pps"] = Json::Value::UInt64(port->get_port_stats().m_stats.tx_pps); - result["result"]["total_tx_pkts"] = Json::Value::UInt64(port->get_port_stats().m_stats.total_tx_pkts); - result["result"]["total_tx_bytes"] = Json::Value::UInt64(port->get_port_stats().m_stats.total_tx_bytes); + result["result"]["tx_bps"] = Json::Value::UInt64(port->get_stats().m_stats.tx_bps); + result["result"]["tx_pps"] = Json::Value::UInt64(port->get_stats().m_stats.tx_pps); + result["result"]["total_tx_pkts"] = Json::Value::UInt64(port->get_stats().m_stats.total_tx_pkts); + result["result"]["total_tx_bytes"] = Json::Value::UInt64(port->get_stats().m_stats.total_tx_bytes); - result["result"]["rx_bps"] = Json::Value::UInt64(port->get_port_stats().m_stats.rx_bps); - result["result"]["rx_pps"] = Json::Value::UInt64(port->get_port_stats().m_stats.rx_pps); - result["result"]["total_rx_pkts"] = Json::Value::UInt64(port->get_port_stats().m_stats.total_rx_pkts); - result["result"]["total_rx_bytes"] = Json::Value::UInt64(port->get_port_stats().m_stats.total_rx_bytes); + result["result"]["rx_bps"] = Json::Value::UInt64(port->get_stats().m_stats.rx_bps); + result["result"]["rx_pps"] = Json::Value::UInt64(port->get_stats().m_stats.rx_pps); + result["result"]["total_rx_pkts"] = Json::Value::UInt64(port->get_stats().m_stats.total_rx_pkts); + result["result"]["total_rx_bytes"] = Json::Value::UInt64(port->get_stats().m_stats.total_rx_bytes); - result["result"]["tx_rx_error"] = Json::Value::UInt64(port->get_port_stats().m_stats.tx_rx_errors); + result["result"]["tx_rx_error"] = Json::Value::UInt64(port->get_stats().m_stats.tx_rx_errors); return (TREX_RPC_CMD_OK); } diff --git a/src/rpc-server/trex_rpc_async_server.cpp b/src/rpc-server/trex_rpc_async_server.cpp new file mode 100644 index 00000000..76549cbd --- /dev/null +++ b/src/rpc-server/trex_rpc_async_server.cpp @@ -0,0 +1,77 @@ +/* + 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 + +/** + * ZMQ based publisher server + * + */ +TrexRpcServerAsync::TrexRpcServerAsync(const TrexRpcServerConfig &cfg) : TrexRpcServerInterface(cfg, "publisher") { + /* ZMQ is not thread safe - this should be outside */ + m_context = zmq_ctx_new(); +} + +void +TrexRpcServerAsync::_rpc_thread_cb() { + std::stringstream ss; + + /* create a socket based on the configuration */ + m_socket = zmq_socket (m_context, ZMQ_PUB); + + switch (m_cfg.get_protocol()) { + case TrexRpcServerConfig::RPC_PROT_TCP: + ss << "tcp://*:"; + break; + default: + throw TrexRpcException("unknown protocol for RPC"); + } + + ss << m_cfg.get_port(); + + /* bind the scoket */ + int rc = zmq_bind (m_socket, ss.str().c_str()); + if (rc != 0) { + throw TrexRpcException("Unable to start ZMQ server at: " + ss.str()); + } + + /* while the server is running - publish results */ + while (m_is_running) { + /* update all ports for their stats */ + uint8_t port_count = TrexStateless::get_instance().get_port_count(); + for (uint8_t i = 0; i < port_count; i++) { + TrexStateless::get_instance().get_port_by_id(i).update_stats(); + const TrexPortStats &stats = TrexStateless::get_instance().get_port_by_id(i).get_stats(); + + + + } + } +} + +void +TrexRpcServerAsync::_stop_rpc_thread() { + m_is_running = false; + this->m_thread.join(); + zmq_term(m_context); +} diff --git a/src/rpc-server/trex_rpc_async_server.h b/src/rpc-server/trex_rpc_async_server.h new file mode 100644 index 00000000..d0a1ee90 --- /dev/null +++ b/src/rpc-server/trex_rpc_async_server.h @@ -0,0 +1,53 @@ +/* + 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_RPC_ASYNC_SERVER_H__ +#define __TREX_RPC_ASYNC_SERVER_H__ + +#include + +/** + * async RPC server + * + * @author imarom (11-Aug-15) + */ +class TrexRpcServerAsync : public TrexRpcServerInterface { +public: + + TrexRpcServerAsync(const TrexRpcServerConfig &cfg); + +protected: + void _rpc_thread_cb(); + void _stop_rpc_thread(); + +private: + + void handle_server_error(const std::string &specific_err); + + static const int RPC_MAX_MSG_SIZE = (20 * 1024); + void *m_context; + void *m_socket; + uint8_t m_msg_buffer[RPC_MAX_MSG_SIZE]; +}; + + +#endif /* __TREX_RPC_ASYNC_SERVER_H__ */ + 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 894ec2ddcd9965f60c4bc7a0b48edf41bfc167d8 Mon Sep 17 00:00:00 2001 From: wenxian li Date: Thu, 1 Oct 2015 22:29:46 -0400 Subject: Code change according to code review comments after Tuple Generator phase 2 commit. --- src/bp_sim.cpp | 28 ++---------- src/bp_sim.h | 5 ++- src/gtest/tuple_gen_test.cpp | 2 +- src/tuple_gen.cpp | 14 +++--- src/tuple_gen.h | 104 ++++++++++++++++++++++++++++++++++--------- 5 files changed, 98 insertions(+), 55 deletions(-) (limited to 'src') diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index 7cbeb09d..fcefa50c 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -3177,7 +3177,7 @@ bool CFlowGenListPerThread::Create(uint32_t thread_id, /* split the clients to threads */ CTupleGenYamlInfo * tuple_gen = &m_flow_list->m_yaml_info.m_tuple_gen; - m_smart_gen.Create(0,m_thread_id,m_flow_list->is_mac_info_configured); + m_smart_gen.Create(0,m_thread_id,m_flow_list->get_is_mac_conf()); /* split the clients to threads using the mask */ CIpPortion portion; @@ -3191,7 +3191,7 @@ bool CFlowGenListPerThread::Create(uint32_t thread_id, portion.m_ip_end, get_longest_flow(i,true), get_total_kcps(i,true)*1000, - m_flow_list, + &m_flow_list->m_mac_info, tuple_gen->m_client_pool[i].m_tcp_aging_sec, tuple_gen->m_client_pool[i].m_udp_aging_sec ); @@ -3962,7 +3962,7 @@ int CFlowGenList::load_from_mac_file(std::string file_name) { printf(" ERROR no mac_file is set, file %s does not exist \n",file_name.c_str()); exit(-1); } - is_mac_info_configured = true; + m_mac_info.set_configured(true); try { std::ifstream fin((char *)file_name.c_str()); @@ -3970,7 +3970,7 @@ int CFlowGenList::load_from_mac_file(std::string file_name) { YAML::Node doc; parser.GetNextDocument(doc); - doc[0] >> m_mac_info; + doc[0] >> m_mac_info.get_mac_info(); } catch ( const std::exception& e ) { std::cout << e.what() << "\n"; m_mac_info.clear(); @@ -3982,7 +3982,6 @@ int CFlowGenList::load_from_mac_file(std::string file_name) { int CFlowGenList::load_from_yaml(std::string file_name, uint32_t num_threads){ - is_mac_info_configured = false; uint8_t idx; m_yaml_info.load_from_yaml_file(file_name); if (m_yaml_info.verify_correctness(num_threads) ==false){ @@ -6643,25 +6642,6 @@ void CFlowYamlDynamicPyloadPlugin::Dump(FILE *fd){ } } -bool is_mac_info_conf(CFlowGenList *fl_list) { - if (fl_list) { - return fl_list->is_mac_info_configured; - } - return false; -} - -mac_addr_align_t * get_mac_addr_by_ip(CFlowGenList *fl_list, - uint32_t ip) { - if (fl_list && - fl_list->is_mac_info_configured && - fl_list->m_mac_info.count(ip)>0) { - return &fl_list->m_mac_info[ip]; - } - return NULL; -} - - - uint16_t CSimplePacketParser::getPktSize(){ uint16_t ip_len=0; if (m_ipv4) { diff --git a/src/bp_sim.h b/src/bp_sim.h index 29b9a724..675e88b4 100755 --- a/src/bp_sim.h +++ b/src/bp_sim.h @@ -3430,6 +3430,7 @@ inline void CFlowGenListPerThread::free_last_flow_node(CGenNode *p){ free_node( p); } + class CFlowGenList { public: @@ -3457,12 +3458,12 @@ public: double get_total_tx_bps(); uint32_t get_total_repeat_flows(); double get_delta_flow_is_sec(); + bool get_is_mac_conf() { return m_mac_info.is_configured();} public: std::vector m_cap_gen; /* global info */ CFlowsYamlInfo m_yaml_info; /* global yaml*/ std::vector m_threads_info; - bool is_mac_info_configured; - std::map m_mac_info; /* global mac info loaded form mac_file*/ + CFlowGenListMac m_mac_info; }; diff --git a/src/gtest/tuple_gen_test.cpp b/src/gtest/tuple_gen_test.cpp index 8791b67d..fd5e9a9a 100755 --- a/src/gtest/tuple_gen_test.cpp +++ b/src/gtest/tuple_gen_test.cpp @@ -334,7 +334,7 @@ TEST(tuple_gen,GenerateTupleMac) { CClientPool gen; gen.Create(cdSEQ_DIST, - 0x10000001, 0x1000000f, 64000,2, &fl,true,0,0); + 0x10000001, 0x1000000f, 64000,2, &fl.m_mac_info,true,0,0); CTupleBase result; uint32_t result_src; uint16_t result_port; diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp index e408f275..d725de44 100755 --- a/src/tuple_gen.cpp +++ b/src/tuple_gen.cpp @@ -57,7 +57,7 @@ void CClientPool::Create(IP_DIST_t dist_value, uint32_t max_ip, double l_flow, double t_cps, - CFlowGenList* fl_list, + CFlowGenListMac* mac_info, bool has_mac_map, uint16_t tcp_aging, uint16_t udp_aging) { @@ -65,10 +65,10 @@ void CClientPool::Create(IP_DIST_t dist_value, set_dist(dist_value); uint32_t total_ip = max_ip - min_ip +1; uint32_t avail_ip = total_ip; - if (has_mac_map && (fl_list!=NULL)) { + if (has_mac_map && (mac_info!=NULL)) { for(int idx=0;idxget_mac_addr_by_ip(min_ip+idx); if (mac_adr == NULL) { avail_ip--; } @@ -86,7 +86,7 @@ void CClientPool::Create(IP_DIST_t dist_value, if (has_mac_map) { for(int idx=0;idxget_mac_addr_by_ip( min_ip+idx); if (mac_adr != NULL) { m_ip_info[idx] = new CClientInfoL(has_mac_map); m_ip_info[idx]->set_ip(min_ip+idx); @@ -103,7 +103,7 @@ void CClientPool::Create(IP_DIST_t dist_value, if (has_mac_map) { for(int idx=0;idxget_mac_addr_by_ip(min_ip+idx); if (mac_adr != NULL) { m_ip_info[idx] = new CClientInfo(has_mac_map); m_ip_info[idx]->set_ip(min_ip+idx); @@ -130,13 +130,13 @@ bool CTupleGeneratorSmart::add_client_pool(IP_DIST_t client_dist, uint32_t max_client, double l_flow, double t_cps, - CFlowGenList* fl_list, + CFlowGenListMac* mac_info, uint16_t tcp_aging, uint16_t udp_aging){ assert(max_client>=min_client); CClientPool* pool = new CClientPool(); pool->Create(client_dist, min_client, max_client, - l_flow, t_cps, fl_list, has_mac_mapping, + l_flow, t_cps, mac_info, has_mac_mapping, tcp_aging, udp_aging); m_client_pool.push_back(pool); diff --git a/src/tuple_gen.h b/src/tuple_gen.h index fb856538..8efa07a4 100755 --- a/src/tuple_gen.h +++ b/src/tuple_gen.h @@ -99,6 +99,47 @@ typedef struct mac_mapping_ { #define TYPE2 1 #define MAX_TYPE 3 +class CFlowGenListMac { +public: + CFlowGenListMac() { + set_configured(false); + } + + std::map & + get_mac_info () { + return m_mac_info; + } + + bool is_configured() { + return is_mac_info_configured; + } + + void set_configured(bool is_conf) { + is_mac_info_configured = is_conf; + } + + void clear() { + set_configured(false); + m_mac_info.clear(); + } + + uint32_t get_mac_info_cnt(uint32_t ip) { + if (is_configured()) { + return m_mac_info.count(ip); + } else { + return 0; + } + } + mac_addr_align_t* get_mac_addr_by_ip(uint32_t ip) { + if (get_mac_info_cnt(ip)>0) { + return &(m_mac_info[ip]); + } + return NULL; + } +private: + bool is_mac_info_configured; + std::map m_mac_info; /* global mac info loaded form mac_file*/ +}; class CIpInfoBase { public: @@ -113,7 +154,7 @@ class CIpInfoBase { void set_ip(uint32_t ip) { m_ip = ip; } - public: + private: uint32_t m_ip; }; @@ -254,6 +295,7 @@ class CClientInfo : public CIpInfo { ~CClientInfo() { if (m_mac!=NULL){ delete m_mac; + m_mac=NULL; } } private: @@ -282,6 +324,7 @@ public: ~CClientInfoL() { if (m_mac!=NULL) { delete m_mac; + m_mac=NULL; } } private: @@ -350,6 +393,31 @@ public: m_client_mac.inused = UNUSED; } } + void setClientAll(uint32_t id, uint32_t ip,mac_addr_align_t*mac,uint16_t port) { + setClientId(id); + setClient(ip); + setClientMac(mac); + setClientPort(port); + } + void setClientAll2(uint32_t id, uint32_t ip,uint16_t port) { + setClientId(id); + setClient(ip); + setClientPort(port); + } + + void setServerAll(uint32_t id, uint32_t ip) { + setServerId(id); + setServer(ip); + } + void getClientAll(uint32_t & id, uint32_t & ip, uint32_t & port) { + id = getClientId(); + ip = getClient(); + port = getClientPort(); + } + void getServerAll(uint32_t & id, uint32_t & ip) { + id = getServerId(); + ip = getServer(); + } private: uint32_t m_client_ip; uint32_t m_client_idx; @@ -362,10 +430,6 @@ private: -class CFlowGenList; -mac_addr_align_t * get_mac_addr_by_ip(CFlowGenList *fl_list, - uint32_t ip); -bool is_mac_info_conf(CFlowGenList *fl_list); class CIpPool { public: @@ -493,10 +557,10 @@ class CClientPool : public CIpPool { public: void GenerateTuple(CTupleBase & tuple) { uint32_t idx = generate_ip(); - tuple.setClientId(idx); - tuple.setClient(get_ip(idx)); - tuple.setClientMac(get_mac(idx)); - tuple.setClientPort(GenerateOnePort(idx)); + tuple.setClientAll(idx, + get_ip(idx), + get_mac(idx), + GenerateOnePort(idx)); } uint16_t get_tcp_aging() { return m_tcp_aging; @@ -509,7 +573,7 @@ public: uint32_t max_ip, double l_flow, double t_cps, - CFlowGenList* fl_list, + CFlowGenListMac* mac_info, bool has_mac_map, uint16_t tcp_aging, uint16_t udp_aging); @@ -571,8 +635,7 @@ public: CIpPool *gen; void GenerateTuple(CTupleBase & tuple) { uint32_t idx = gen->generate_ip(); - tuple.setServerId(idx); - tuple.setServer(gen->get_ip(idx)); + tuple.setServerAll(idx, gen->get_ip(idx)); } uint16_t GenerateOnePort(uint32_t idx) { return gen->GenerateOnePort(idx); @@ -587,6 +650,7 @@ public: if (gen!=NULL) { gen->Delete(); delete gen; + gen=NULL; } } uint32_t get_total_ips() { @@ -672,7 +736,7 @@ public: uint32_t max_client, double l_flow, double t_cps, - CFlowGenList* fl_list, + CFlowGenListMac* mac_info, uint16_t tcp_aging, uint16_t udp_aging); bool add_server_pool(IP_DIST_t server_dist, @@ -718,15 +782,13 @@ public: m_server_gen->GenerateTuple(tuple); m_cache_client_ip = tuple.getClient(); m_cache_client_idx = tuple.getClientId(); - m_cache_server_ip = tuple.getServer(); - m_cache_server_idx = tuple.getServerId(); + tuple.getServerAll(m_cache_server_idx, m_cache_server_ip); }else{ - tuple.setServer(m_cache_server_ip); - tuple.setServerId(m_cache_server_idx); - tuple.setClient(m_cache_client_ip); - tuple.setClientId(m_cache_client_idx); - tuple.setClientPort( - m_client_gen->GenerateOnePort(m_cache_client_idx)); + tuple.setServerAll(m_cache_server_idx, + m_cache_server_ip); + tuple.setClientAll2(m_cache_client_idx, + m_cache_client_ip, + m_client_gen->GenerateOnePort(m_cache_client_idx)); } m_cnt++; if (m_cnt>=m_w) { -- cgit From e2b63ecc0544c82590c9aeb9a44a8a4bcb869cb6 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 1 Oct 2015 22:58:16 -0400 Subject: minor change --- src/tuple_gen.cpp | 7 +++---- src/tuple_gen.h | 7 ++++--- 2 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp index d725de44..3a477338 100755 --- a/src/tuple_gen.cpp +++ b/src/tuple_gen.cpp @@ -123,7 +123,6 @@ void CClientPool::Create(IP_DIST_t dist_value, CreateBase(); } -void delay(int msec); bool CTupleGeneratorSmart::add_client_pool(IP_DIST_t client_dist, uint32_t min_client, @@ -136,7 +135,7 @@ bool CTupleGeneratorSmart::add_client_pool(IP_DIST_t client_dist, assert(max_client>=min_client); CClientPool* pool = new CClientPool(); pool->Create(client_dist, min_client, max_client, - l_flow, t_cps, mac_info, has_mac_mapping, + l_flow, t_cps, mac_info, m_has_mac_mapping, tcp_aging, udp_aging); m_client_pool.push_back(pool); @@ -171,13 +170,13 @@ bool CTupleGeneratorSmart::Create(uint32_t _id, m_thread_id = thread_id; m_id = _id; m_was_init=true; - has_mac_mapping = has_mac; + m_has_mac_mapping = has_mac; return(true); } void CTupleGeneratorSmart::Delete(){ m_was_init=false; - has_mac_mapping = false; + m_has_mac_mapping = false; for (int idx=0;idxDelete(); diff --git a/src/tuple_gen.h b/src/tuple_gen.h index 8efa07a4..205014c5 100755 --- a/src/tuple_gen.h +++ b/src/tuple_gen.h @@ -632,7 +632,6 @@ private: class CServerPool : public CServerPoolBase { public: - CIpPool *gen; void GenerateTuple(CTupleBase & tuple) { uint32_t idx = gen->generate_ip(); tuple.setServerAll(idx, gen->get_ip(idx)); @@ -656,6 +655,8 @@ public: uint32_t get_total_ips() { return gen->m_ip_info.size(); } +private: + CIpPool *gen; }; /* generate for each template */ @@ -712,7 +713,7 @@ public: public: CTupleGeneratorSmart(){ m_was_init=false; - has_mac_mapping = false; + m_has_mac_mapping = false; } bool Create(uint32_t _id, uint32_t thread_id, bool has_mac=false); @@ -763,7 +764,7 @@ private: std::vector m_client_pool; std::vector m_server_pool; bool m_was_init; - bool has_mac_mapping; + bool m_has_mac_mapping; }; class CTupleTemplateGeneratorSmart { -- cgit From a17963de76f9d99ee14f9a90526d4343360a1b45 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 1 Oct 2015 23:03:32 -0400 Subject: fix a build error --- src/main_dpdk.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index 820fb3fa..0d03a207 100755 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -4100,9 +4100,9 @@ int CGlobalPortCfg::start_send_master(){ if (CGlobalInfo::m_options.mac_file != "") { CGlobalInfo::m_options.preview.set_mac_ip_mapping_enable(true); m_fl.load_from_mac_file(CGlobalInfo::m_options.mac_file); - m_fl.is_mac_info_configured = true; + m_fl.m_mac_info.set_configured(true); } else { - m_fl.is_mac_info_configured = false; + m_fl.m_mac_info.set_configured(false); } m_expected_pps = m_fl.get_total_pps(); -- 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/gtest/rpc_test.cpp | 5 +- src/rpc-server/commands/trex_rpc_cmd_general.cpp | 13 +- src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 1 + src/rpc-server/trex_rpc_async_server.cpp | 36 +++- src/rpc-server/trex_rpc_async_server.h | 1 + src/rpc-server/trex_rpc_cmd.cpp | 1 + src/rpc-server/trex_rpc_server.cpp | 6 +- src/rpc-server/trex_rpc_server_api.h | 6 +- src/rpc-server/trex_rpc_server_mock.cpp | 6 +- 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 ++++++++++++++++++++++ 13 files changed, 502 insertions(+), 266 deletions(-) create mode 100644 src/stateless/trex_stateless_port.cpp create mode 100644 src/stateless/trex_stateless_port.h (limited to 'src') diff --git a/src/gtest/rpc_test.cpp b/src/gtest/rpc_test.cpp index 38d34320..4084b664 100644 --- a/src/gtest/rpc_test.cpp +++ b/src/gtest/rpc_test.cpp @@ -42,9 +42,10 @@ protected: m_verbose = false; - TrexRpcServerConfig cfg = TrexRpcServerConfig(TrexRpcServerConfig::RPC_PROT_TCP, 5050); + TrexRpcServerConfig req_resp_cfg = TrexRpcServerConfig(TrexRpcServerConfig::RPC_PROT_TCP, 5050); + TrexRpcServerConfig async_cfg = TrexRpcServerConfig(TrexRpcServerConfig::RPC_PROT_TCP, 5051); - m_rpc = new TrexRpcServer(cfg); + m_rpc = new TrexRpcServer(req_resp_cfg, async_cfg); m_rpc->start(); m_context = zmq_ctx_new (); diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index 7721526c..3a0a12f8 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -22,6 +22,7 @@ limitations under the License. #include "trex_rpc_cmds.h" #include #include +#include #include #include @@ -271,17 +272,7 @@ TrexRpcCmdGetPortStats::_run(const Json::Value ¶ms, Json::Value &result) { result["result"]["status"] = port->get_state_as_string(); - result["result"]["tx_bps"] = Json::Value::UInt64(port->get_stats().m_stats.tx_bps); - result["result"]["tx_pps"] = Json::Value::UInt64(port->get_stats().m_stats.tx_pps); - result["result"]["total_tx_pkts"] = Json::Value::UInt64(port->get_stats().m_stats.total_tx_pkts); - result["result"]["total_tx_bytes"] = Json::Value::UInt64(port->get_stats().m_stats.total_tx_bytes); - - result["result"]["rx_bps"] = Json::Value::UInt64(port->get_stats().m_stats.rx_bps); - result["result"]["rx_pps"] = Json::Value::UInt64(port->get_stats().m_stats.rx_pps); - result["result"]["total_rx_pkts"] = Json::Value::UInt64(port->get_stats().m_stats.total_rx_pkts); - result["result"]["total_rx_bytes"] = Json::Value::UInt64(port->get_stats().m_stats.total_rx_bytes); - - result["result"]["tx_rx_error"] = Json::Value::UInt64(port->get_stats().m_stats.tx_rx_errors); + port->encode_stats(result["result"]); return (TREX_RPC_CMD_OK); } diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index 1450e1a9..97c2b791 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -22,6 +22,7 @@ limitations under the License. #include #include #include +#include #include diff --git a/src/rpc-server/trex_rpc_async_server.cpp b/src/rpc-server/trex_rpc_async_server.cpp index 76549cbd..40d16dfe 100644 --- a/src/rpc-server/trex_rpc_async_server.cpp +++ b/src/rpc-server/trex_rpc_async_server.cpp @@ -18,10 +18,19 @@ 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. */ + +/* required for sleep_for c++ 2011 + https://bugs.launchpad.net/ubuntu/+source/gcc-4.4/+bug/608145 +*/ +#define _GLIBCXX_USE_NANOSLEEP + #include +#include #include #include #include +#include +#include /** * ZMQ based publisher server @@ -32,6 +41,10 @@ TrexRpcServerAsync::TrexRpcServerAsync(const TrexRpcServerConfig &cfg) : TrexRpc m_context = zmq_ctx_new(); } +/** + * publisher thread + * + */ void TrexRpcServerAsync::_rpc_thread_cb() { std::stringstream ss; @@ -57,21 +70,30 @@ TrexRpcServerAsync::_rpc_thread_cb() { /* while the server is running - publish results */ while (m_is_running) { - /* update all ports for their stats */ - uint8_t port_count = TrexStateless::get_instance().get_port_count(); - for (uint8_t i = 0; i < port_count; i++) { - TrexStateless::get_instance().get_port_by_id(i).update_stats(); - const TrexPortStats &stats = TrexStateless::get_instance().get_port_by_id(i).get_stats(); + Json::Value snapshot; + Json::FastWriter writer; + + /* trigger a full update for stats */ + TrexStateless::get_instance().update_stats(); + + /* encode them to JSON */ + TrexStateless::get_instance().encode_stats(snapshot); + + /* write to string and publish */ + std::string snapshot_str = writer.write(snapshot); + zmq_send(m_socket, snapshot_str.c_str(), snapshot_str.size(), 0); + //std::cout << "sending " << snapshot_str << "\n"; + /* relax for some time */ + std::this_thread::sleep_for (std::chrono::milliseconds(1000)); - } } } void TrexRpcServerAsync::_stop_rpc_thread() { m_is_running = false; - this->m_thread.join(); + this->m_thread->join(); zmq_term(m_context); } diff --git a/src/rpc-server/trex_rpc_async_server.h b/src/rpc-server/trex_rpc_async_server.h index d0a1ee90..13525c01 100644 --- a/src/rpc-server/trex_rpc_async_server.h +++ b/src/rpc-server/trex_rpc_async_server.h @@ -23,6 +23,7 @@ limitations under the License. #define __TREX_RPC_ASYNC_SERVER_H__ #include +#include /** * async RPC server diff --git a/src/rpc-server/trex_rpc_cmd.cpp b/src/rpc-server/trex_rpc_cmd.cpp index 6c355e70..f7cb5259 100644 --- a/src/rpc-server/trex_rpc_cmd.cpp +++ b/src/rpc-server/trex_rpc_cmd.cpp @@ -21,6 +21,7 @@ limitations under the License. #include #include #include +#include trex_rpc_cmd_rc_e TrexRpcCommand::run(const Json::Value ¶ms, Json::Value &result) { diff --git a/src/rpc-server/trex_rpc_server.cpp b/src/rpc-server/trex_rpc_server.cpp index 6b8c200d..18265a0e 100644 --- a/src/rpc-server/trex_rpc_server.cpp +++ b/src/rpc-server/trex_rpc_server.cpp @@ -21,6 +21,7 @@ limitations under the License. #include #include +#include #include #include #include @@ -112,10 +113,13 @@ get_current_date_time() { const std::string TrexRpcServer::s_server_uptime = get_current_date_time(); -TrexRpcServer::TrexRpcServer(const TrexRpcServerConfig &req_resp_cfg) { +TrexRpcServer::TrexRpcServer(const TrexRpcServerConfig &req_resp_cfg, + const TrexRpcServerConfig &async_cfg) { /* add the request response server */ m_servers.push_back(new TrexRpcServerReqRes(req_resp_cfg)); + /* add async publisher */ + m_servers.push_back(new TrexRpcServerAsync(async_cfg)); } TrexRpcServer::~TrexRpcServer() { diff --git a/src/rpc-server/trex_rpc_server_api.h b/src/rpc-server/trex_rpc_server_api.h index 06bbe10c..5a7cad48 100644 --- a/src/rpc-server/trex_rpc_server_api.h +++ b/src/rpc-server/trex_rpc_server_api.h @@ -139,8 +139,10 @@ protected: class TrexRpcServer { public: - /* currently only request response server config is required */ - TrexRpcServer(const TrexRpcServerConfig &req_resp_cfg); + /* creates the collection of servers using configurations */ + TrexRpcServer(const TrexRpcServerConfig &req_resp_cfg, + const TrexRpcServerConfig &async_cfg); + ~TrexRpcServer(); /** diff --git a/src/rpc-server/trex_rpc_server_mock.cpp b/src/rpc-server/trex_rpc_server_mock.cpp index 835e28b8..16aa6774 100644 --- a/src/rpc-server/trex_rpc_server_mock.cpp +++ b/src/rpc-server/trex_rpc_server_mock.cpp @@ -59,8 +59,10 @@ int main(int argc, char *argv[]) { cout << "\n-= Starting RPC Server Mock =-\n\n"; cout << "Listening on tcp://localhost:5050 [ZMQ]\n\n"; - TrexRpcServerConfig rpc_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5050); - TrexRpcServer rpc(rpc_cfg); + TrexRpcServerConfig rpc_req_resp_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5050); + TrexRpcServerConfig rpc_async_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5051); + + TrexRpcServer rpc(rpc_req_resp_cfg, rpc_async_cfg); /* init the RPC server */ rpc.start(); 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') 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/rpc-server/commands/trex_rpc_cmd_general.cpp | 2 +- src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 4 +- src/rpc-server/trex_rpc_async_server.cpp | 2 +- src/rpc-server/trex_rpc_cmd.cpp | 2 +- src/rpc-server/trex_rpc_server_mock.cpp | 2 +- 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 ----------------------- 13 files changed, 361 insertions(+), 361 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') diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index 3a0a12f8..b440fa81 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -21,7 +21,7 @@ limitations under the License. #include "trex_rpc_cmds.h" #include -#include +#include #include #include diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index 97c2b791..812d819e 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -20,8 +20,8 @@ limitations under the License. */ #include "trex_rpc_cmds.h" #include -#include -#include +#include +#include #include #include diff --git a/src/rpc-server/trex_rpc_async_server.cpp b/src/rpc-server/trex_rpc_async_server.cpp index 40d16dfe..01f03af3 100644 --- a/src/rpc-server/trex_rpc_async_server.cpp +++ b/src/rpc-server/trex_rpc_async_server.cpp @@ -24,7 +24,7 @@ limitations under the License. */ #define _GLIBCXX_USE_NANOSLEEP -#include +#include #include #include #include diff --git a/src/rpc-server/trex_rpc_cmd.cpp b/src/rpc-server/trex_rpc_cmd.cpp index f7cb5259..920a8d30 100644 --- a/src/rpc-server/trex_rpc_cmd.cpp +++ b/src/rpc-server/trex_rpc_cmd.cpp @@ -20,7 +20,7 @@ limitations under the License. */ #include #include -#include +#include #include trex_rpc_cmd_rc_e diff --git a/src/rpc-server/trex_rpc_server_mock.cpp b/src/rpc-server/trex_rpc_server_mock.cpp index 16aa6774..32635c75 100644 --- a/src/rpc-server/trex_rpc_server_mock.cpp +++ b/src/rpc-server/trex_rpc_server_mock.cpp @@ -20,7 +20,7 @@ limitations under the License. */ #include -#include +#include #include #include 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/gtest/rpc_test.cpp | 10 +---- src/rpc-server/trex_rpc_async_server.cpp | 6 +-- src/rpc-server/trex_rpc_server.cpp | 13 +++++-- src/rpc-server/trex_rpc_server_api.h | 4 +- src/rpc-server/trex_rpc_server_mock.cpp | 35 +++++++++++------- src/stateless/cp/trex_stateless.cpp | 63 +++++++++++++++++++++++++++----- src/stateless/cp/trex_stateless.h | 44 +++++++++++++++++++--- 7 files changed, 129 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/gtest/rpc_test.cpp b/src/gtest/rpc_test.cpp index 4084b664..250d5342 100644 --- a/src/gtest/rpc_test.cpp +++ b/src/gtest/rpc_test.cpp @@ -42,12 +42,6 @@ protected: m_verbose = false; - TrexRpcServerConfig req_resp_cfg = TrexRpcServerConfig(TrexRpcServerConfig::RPC_PROT_TCP, 5050); - TrexRpcServerConfig async_cfg = TrexRpcServerConfig(TrexRpcServerConfig::RPC_PROT_TCP, 5051); - - m_rpc = new TrexRpcServer(req_resp_cfg, async_cfg); - m_rpc->start(); - m_context = zmq_ctx_new (); m_socket = zmq_socket (m_context, ZMQ_REQ); zmq_connect (m_socket, "tcp://localhost:5050"); @@ -55,9 +49,6 @@ protected: } virtual void TearDown() { - m_rpc->stop(); - - delete m_rpc; zmq_close(m_socket); zmq_term(m_context); } @@ -658,3 +649,4 @@ TEST_F(RpcTestOwned, start_stop_traffic) { send_request(request, response); EXPECT_EQ(response["result"], "ACK"); } + diff --git a/src/rpc-server/trex_rpc_async_server.cpp b/src/rpc-server/trex_rpc_async_server.cpp index 01f03af3..3313e42e 100644 --- a/src/rpc-server/trex_rpc_async_server.cpp +++ b/src/rpc-server/trex_rpc_async_server.cpp @@ -87,13 +87,13 @@ TrexRpcServerAsync::_rpc_thread_cb() { /* relax for some time */ std::this_thread::sleep_for (std::chrono::milliseconds(1000)); - } + + /* must be closed from the same thread */ + zmq_close(m_socket); } void TrexRpcServerAsync::_stop_rpc_thread() { - m_is_running = false; - this->m_thread->join(); zmq_term(m_context); } diff --git a/src/rpc-server/trex_rpc_server.cpp b/src/rpc-server/trex_rpc_server.cpp index 18265a0e..8749c9b4 100644 --- a/src/rpc-server/trex_rpc_server.cpp +++ b/src/rpc-server/trex_rpc_server.cpp @@ -113,13 +113,18 @@ get_current_date_time() { const std::string TrexRpcServer::s_server_uptime = get_current_date_time(); -TrexRpcServer::TrexRpcServer(const TrexRpcServerConfig &req_resp_cfg, - const TrexRpcServerConfig &async_cfg) { +TrexRpcServer::TrexRpcServer(const TrexRpcServerConfig *req_resp_cfg, + const TrexRpcServerConfig *async_cfg) { /* add the request response server */ - m_servers.push_back(new TrexRpcServerReqRes(req_resp_cfg)); + if (req_resp_cfg) { + m_servers.push_back(new TrexRpcServerReqRes(*req_resp_cfg)); + } + /* add async publisher */ - m_servers.push_back(new TrexRpcServerAsync(async_cfg)); + if (async_cfg) { + m_servers.push_back(new TrexRpcServerAsync(*async_cfg)); + } } TrexRpcServer::~TrexRpcServer() { diff --git a/src/rpc-server/trex_rpc_server_api.h b/src/rpc-server/trex_rpc_server_api.h index 5a7cad48..327c6eaa 100644 --- a/src/rpc-server/trex_rpc_server_api.h +++ b/src/rpc-server/trex_rpc_server_api.h @@ -140,8 +140,8 @@ class TrexRpcServer { public: /* creates the collection of servers using configurations */ - TrexRpcServer(const TrexRpcServerConfig &req_resp_cfg, - const TrexRpcServerConfig &async_cfg); + TrexRpcServer(const TrexRpcServerConfig *req_resp_cfg, + const TrexRpcServerConfig *async_cfg); ~TrexRpcServer(); diff --git a/src/rpc-server/trex_rpc_server_mock.cpp b/src/rpc-server/trex_rpc_server_mock.cpp index 32635c75..8dae42d7 100644 --- a/src/rpc-server/trex_rpc_server_mock.cpp +++ b/src/rpc-server/trex_rpc_server_mock.cpp @@ -44,31 +44,39 @@ int gtest_main(int argc, char **argv); int main(int argc, char *argv[]) { - /* configure the stateless object with 4 ports */ - TrexStateless::configure(4); + bool is_gtest = false; - // gtest ? + // gtest ? if (argc > 1) { if (string(argv[1]) != "--ut") { cout << "\n[Usage] " << argv[0] << ": " << " [--ut]\n\n"; exit(-1); } - return gtest_main(argc, argv); + is_gtest = true; } - cout << "\n-= Starting RPC Server Mock =-\n\n"; - cout << "Listening on tcp://localhost:5050 [ZMQ]\n\n"; + /* configure the stateless object with 4 ports */ + TrexStatelessCfg cfg; TrexRpcServerConfig rpc_req_resp_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5050); TrexRpcServerConfig rpc_async_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5051); - TrexRpcServer rpc(rpc_req_resp_cfg, rpc_async_cfg); + cfg.m_port_count = 4; + cfg.m_rpc_req_resp_cfg = &rpc_req_resp_cfg; + cfg.m_rpc_async_cfg = &rpc_async_cfg; + cfg.m_rpc_server_verbose = (is_gtest ? false : true); - /* init the RPC server */ - rpc.start(); + TrexStateless::create(cfg); - cout << "Setting Server To Full Verbose\n\n"; - rpc.set_verbose(true); + /* gtest handling */ + if (is_gtest) { + int rc = gtest_main(argc, argv); + TrexStateless::destroy(); + return rc; + } + + cout << "\n-= Starting RPC Server Mock =-\n\n"; + cout << "Listening on tcp://localhost:5050 [ZMQ]\n\n"; cout << "Server Started\n\n"; @@ -76,7 +84,6 @@ int main(int argc, char *argv[]) { sleep(1); } - rpc.stop(); - - + TrexStateless::destroy(); } + 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/bp_sim.h | 21 +++- src/main_dpdk.cpp | 135 ++++++++++++++++++----- src/rpc-server/commands/trex_rpc_cmd_general.cpp | 2 +- src/rpc-server/trex_rpc_server_mock.cpp | 5 +- src/stateless/cp/trex_stateless.cpp | 59 +++++++--- src/stateless/cp/trex_stateless.h | 27 ++++- 6 files changed, 198 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/bp_sim.h b/src/bp_sim.h index 29b9a724..2f445cb7 100755 --- a/src/bp_sim.h +++ b/src/bp_sim.h @@ -688,6 +688,15 @@ public: RUN_FLAGS_RXCHECK_CONST_TS =1, }; + /** + * different running modes for Trex + */ + enum trex_run_mode_e { + RUN_MODE_INVALID, + RUN_MODE_BATCH, + RUN_MODE_INTERACTIVE + }; + public: CParserOption(){ m_factor=1.0; @@ -707,6 +716,7 @@ public: m_run_flags=0; prefix=""; m_mac_splitter=0; + m_run_mode = RUN_MODE_INVALID; } CPreviewMode preview; @@ -730,13 +740,14 @@ public: uint8_t m_mac_splitter; uint8_t m_pad; + trex_run_mode_e m_run_mode; - std::string cfg_file; - std::string mac_file; - std::string platform_cfg_file; + std::string cfg_file; + std::string mac_file; + std::string platform_cfg_file; - std::string out_file; - std::string prefix; + std::string out_file; + std::string prefix; CMacAddrCfg m_mac_addr[MAX_LATENCY_PORTS]; diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index 820fb3fa..e3d13f2b 100755 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -55,6 +55,7 @@ limitations under the License. #include #include #include +#include #include <../linux_dpdk/version.h> extern "C" { @@ -426,7 +427,8 @@ static char global_loglevel_str[20]; // cores =0==1,1*2,2,3,4,5,6 // An enum for all the option types enum { OPT_HELP, - OPT_CFG, + OPT_MODE_BATCH, + OPT_MODE_INTERACTIVE, OPT_NODE_DUMP, OPT_UT, OPT_FILE_OUT, @@ -478,15 +480,16 @@ enum { OPT_HELP, */ static CSimpleOpt::SOption parser_options[] = { - { OPT_HELP, "-?", SO_NONE }, - { OPT_HELP, "-h", SO_NONE }, - { OPT_HELP, "--help", SO_NONE }, - { OPT_UT, "--ut", SO_NONE }, - { OPT_CFG, "-f", SO_REQ_SEP}, - { OPT_PLAT_CFG_FILE,"--cfg", SO_REQ_SEP}, - { OPT_REAL_TIME , "-r", SO_NONE }, - { OPT_SINGLE_CORE , "-s", SO_NONE }, - { OPT_FILE_OUT , "-o" , SO_REQ_SEP}, + { OPT_HELP, "-?", SO_NONE }, + { OPT_HELP, "-h", SO_NONE }, + { OPT_HELP, "--help", SO_NONE }, + { OPT_UT, "--ut", SO_NONE }, + { OPT_MODE_BATCH, "-f", SO_REQ_SEP}, + { OPT_MODE_INTERACTIVE, "-i", SO_NONE }, + { OPT_PLAT_CFG_FILE, "--cfg", SO_REQ_SEP}, + { OPT_REAL_TIME , "-r", SO_NONE }, + { OPT_SINGLE_CORE, "-s", SO_NONE }, + { OPT_FILE_OUT, "-o" , SO_REQ_SEP}, { OPT_FLIP_CLIENT_SERVER,"--flip",SO_NONE }, { OPT_FLOW_FLIP_CLIENT_SERVER,"-p",SO_NONE }, { OPT_FLOW_FLIP_CLIENT_SERVER_SIDE,"-e",SO_NONE }, @@ -533,13 +536,18 @@ static CSimpleOpt::SOption parser_options[] = static int usage(){ - printf(" Usage: t-rex-64 [OPTION] -f cfg.yaml -c cores \n"); + printf(" Usage: t-rex-64 [MODE] [OPTION] -f cfg.yaml -c cores \n"); printf(" \n"); printf(" \n"); - printf(" options \n"); + + printf(" mode \n\n"); printf(" -f [file] : YAML file with template configuration \n"); + printf(" -i : launch TRex in interactive mode (RPC server)\n"); printf(" \n\n"); - printf(" --mac [file] : YAML file with configuration \n"); + + printf(" options \n\n"); + + printf(" --mac [file] : YAML file with configuration \n"); printf(" \n\n"); printf(" -r : realtime enable \n"); printf(" \n\n"); @@ -612,7 +620,8 @@ static int usage(){ printf(" --mac-spread : Spread the destination mac-order by this factor. e.g 2 will generate the traffic to 2 devices DEST-MAC ,DEST-MAC+1 \n"); printf(" maximum is up to 128 devices \n"); - printf(" simulation mode : \n"); + + printf("\n simulation mode : \n"); printf(" Using this mode you can generate the traffic into a pcap file and learn how trex works \n"); printf(" With this version you must be SUDO to use this mode ( I know this is not normal ) \n"); printf(" you can use the Linux CEL version of t-rex to do it without super user \n"); @@ -653,6 +662,7 @@ static int usage(){ printf(" Open Source Components / Libraries \n"); printf(" DPDK (BSD) \n"); printf(" YAML-CPP (BSD) \n"); + printf(" JSONCPP (MIT) \n"); printf(" \n"); printf(" Open Source Binaries \n"); printf(" ZMQ (LGPL v3plus) \n"); @@ -667,6 +677,11 @@ static int usage(){ int gtest_main(int argc, char **argv) ; +static void parse_err(const std::string &msg) { + std::cout << "\nArgument Parsing Error: \n\n" << "*** "<< msg << "\n\n"; + exit(-1); +} + static int parse_options(int argc, char *argv[], CParserOption* po, bool first_time ) { CSimpleOpt args(argc, argv, parser_options); @@ -679,36 +694,55 @@ static int parse_options(int argc, char *argv[], CParserOption* po, bool first_t int res1; uint32_t tmp_data; + po->m_run_mode = CParserOption::RUN_MODE_INVALID; while ( args.Next() ){ if (args.LastError() == SO_SUCCESS) { switch (args.OptionId()) { + case OPT_UT : - printf(" Supported only in simulation \n"); - res1=0; - exit(res1); + parse_err("Supported only in simulation"); break; + case OPT_HELP: usage(); return -1; - case OPT_CFG: + + case OPT_MODE_BATCH: + if (po->m_run_mode != CParserOption::RUN_MODE_INVALID) { + parse_err("Please specify single run mode"); + } + po->m_run_mode = CParserOption::RUN_MODE_BATCH; po->cfg_file = args.OptionArg(); break; + + case OPT_MODE_INTERACTIVE: + if (po->m_run_mode != CParserOption::RUN_MODE_INVALID) { + parse_err("Please specify single run mode"); + } + po->m_run_mode = CParserOption::RUN_MODE_INTERACTIVE; + break; + case OPT_NO_KEYBOARD_INPUT : po->preview.set_no_keyboard(true); break; + case OPT_MAC_FILE : po->mac_file = args.OptionArg(); break; + case OPT_PLAT_CFG_FILE : po->platform_cfg_file = args.OptionArg(); break; + case OPT_SINGLE_CORE : po->preview.setSingleCore(true); break; + case OPT_IPV6: po->preview.set_ipv6_mode_enable(true); break; + case OPT_VLAN: po->preview.set_vlan_mode_enable(true); break; @@ -726,6 +760,7 @@ static int parse_options(int argc, char *argv[], CParserOption* po, bool first_t printf(" warning -r is deprecated, real time is not needed any more , it is the default \n"); po->preview.setRealTime(true); break; + case OPT_NO_FLOW_CONTROL: po->preview.set_disable_flow_control_setting(true); break; @@ -832,21 +867,20 @@ static int parse_options(int argc, char *argv[], CParserOption* po, bool first_t } // End of while - if ((po->cfg_file =="") ) { - printf("Invalid combination of parameters you must add -f with configuration file \n"); - return -1; + if ((po->m_run_mode == CParserOption::RUN_MODE_INVALID) ) { + parse_err("Please provide single run mode (e.g. batch or interactive)"); } if ( po->m_mac_splitter > 128 ){ - printf("maximum mac spreading is 128 you set it to %d \n",po->m_mac_splitter); - return -1; + std::stringstream ss; + ss << "maximum mac spreading is 128 you set it to: " << po->m_mac_splitter; + parse_err(ss.str()); } if ( po->preview.get_learn_mode_enable() ){ if ( po->preview.get_ipv6_mode_enable() ){ - printf("--learn mode is not supported with --ipv6, beacuse there is not such thing NAT66 ( ipv6-ipv6) \n"); - printf("if you think it is important,open a defect \n"); - return -1; + parse_err("--learn mode is not supported with --ipv6, beacuse there is not such thing NAT66 ( ipv6-ipv6) \n" \ + "if you think it is important,open a defect \n"); } if ( po->is_latency_disabled() ){ /* set latency thread */ @@ -3863,6 +3897,7 @@ int CGlobalPortCfg::run_in_master(){ std::string json; bool was_stopped=false; + while ( true ) { if ( CGlobalInfo::m_options.preview.get_no_keyboard() ==false ){ @@ -3976,6 +4011,7 @@ int CGlobalPortCfg::run_in_master(){ break; } } + m_mg.stop(); delay(1000); if ( was_stopped ){ @@ -4172,7 +4208,18 @@ static int latency_one_lcore(__attribute__((unused)) void *dummy) } +static int stateless_entry(__attribute__((unused)) void *dummy) { + CPlatformSocketInfo * lpsock=&CGlobalInfo::m_socket; + physical_thread_id_t phy_id = rte_lcore_id(); + + if (lpsock->thread_phy_is_master( phy_id )) { + TrexStateless::get_instance().launch_control_plane(); + } else { + TrexStateless::get_instance().launch_on_dp_core(); + } + return (0); +} static int slave_one_lcore(__attribute__((unused)) void *dummy) { @@ -4381,7 +4428,37 @@ int sim_load_list_of_cap_files(CParserOption * op){ +static int +launch_stateless_trex() { + CPlatformSocketInfo *lpsock=&CGlobalInfo::m_socket; + CParserOption *lpop= &CGlobalInfo::m_options; + CPlatformYamlInfo *cg=&global_platform_cfg_info; + + TrexStatelessCfg cfg; + + TrexRpcServerConfig rpc_req_resp_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5050); + TrexRpcServerConfig rpc_async_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5051); + cfg.m_dp_core_count = lpop->preview.getCores(); + cfg.m_port_count = lpop->m_expected_portd; + cfg.m_rpc_req_resp_cfg = &rpc_req_resp_cfg; + cfg.m_rpc_async_cfg = &rpc_async_cfg; + cfg.m_rpc_server_verbose = true; + + TrexStateless::configure(cfg); + + printf("\nStarting T-Rex Stateless\n"); + printf("Starting RPC Server...\n\n"); + + rte_eal_mp_remote_launch(stateless_entry, NULL, CALL_MASTER); + + unsigned lcore_id; + RTE_LCORE_FOREACH_SLAVE(lcore_id) { + if (rte_eal_wait_lcore(lcore_id) < 0) + return -1; + } + return (0); +} @@ -4436,6 +4513,11 @@ int main_test(int argc , char * argv[]){ rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n"); } + /* patch here */ + if (CGlobalInfo::m_options.m_run_mode == CParserOption::RUN_MODE_INTERACTIVE) { + return launch_stateless_trex(); + } + time_init(); @@ -4518,6 +4600,7 @@ int main_test(int argc , char * argv[]){ if (rte_eal_wait_lcore(lcore_id) < 0) return -1; } + ports_cfg.stop_master(); ports_cfg.Delete(); utl_termio_reset(); diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index b440fa81..ae87d749 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -155,7 +155,7 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value ¶ms, Json::Value &result) { section["uptime"] = TrexRpcServer::get_server_uptime(); /* FIXME: core count */ - section["dp_core_count"] = 1; + section["dp_core_count"] = instance.get_dp_core_count(); section["core_type"] = get_cpu_model(); /* ports */ diff --git a/src/rpc-server/trex_rpc_server_mock.cpp b/src/rpc-server/trex_rpc_server_mock.cpp index 8dae42d7..de43f92f 100644 --- a/src/rpc-server/trex_rpc_server_mock.cpp +++ b/src/rpc-server/trex_rpc_server_mock.cpp @@ -62,11 +62,14 @@ int main(int argc, char *argv[]) { TrexRpcServerConfig rpc_async_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5051); cfg.m_port_count = 4; + cfg.m_dp_core_count = 2; cfg.m_rpc_req_resp_cfg = &rpc_req_resp_cfg; cfg.m_rpc_async_cfg = &rpc_async_cfg; cfg.m_rpc_server_verbose = (is_gtest ? false : true); - TrexStateless::create(cfg); + TrexStateless::configure(cfg); + + TrexStateless::get_instance().launch_control_plane(); /* gtest handling */ if (is_gtest) { 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 31d21b32b4a9d49bb55115fa50cf9dbf4d8b0d3b Mon Sep 17 00:00:00 2001 From: root Date: Fri, 9 Oct 2015 14:10:38 -0400 Subject: code update after review --- src/gtest/tuple_gen_test.cpp | 2 + src/mac_mapping.h | 60 ++++++++ src/tuple_gen.h | 340 ++++++++++++++++++++----------------------- 3 files changed, 216 insertions(+), 186 deletions(-) create mode 100644 src/mac_mapping.h (limited to 'src') diff --git a/src/gtest/tuple_gen_test.cpp b/src/gtest/tuple_gen_test.cpp index fd5e9a9a..8a774e38 100755 --- a/src/gtest/tuple_gen_test.cpp +++ b/src/gtest/tuple_gen_test.cpp @@ -335,6 +335,7 @@ TEST(tuple_gen,GenerateTupleMac) { CClientPool gen; gen.Create(cdSEQ_DIST, 0x10000001, 0x1000000f, 64000,2, &fl.m_mac_info,true,0,0); + CTupleBase result; uint32_t result_src; uint16_t result_port; @@ -348,6 +349,7 @@ TEST(tuple_gen,GenerateTupleMac) { result_mac = result.getClientMac(); EXPECT_EQ(result_src, (uint32_t)(0x10000001+i%2)); EXPECT_EQ(result_port, 1024+i/2); + printf("i:%d,mac:%d\n",i,result_mac->mac[3]); if (i%2==0) EXPECT_EQ(result_mac->mac[3], 5); else diff --git a/src/mac_mapping.h b/src/mac_mapping.h new file mode 100644 index 00000000..84151e8c --- /dev/null +++ b/src/mac_mapping.h @@ -0,0 +1,60 @@ +#ifndef MAC_MAPPING_H_ +#define MAC_MAPPING_H_ + +#define INUSED 0 +#define UNUSED 1 +typedef struct mac_addr_align_ { +public: + uint8_t mac[6]; + uint8_t inused; + uint8_t pad; +} mac_addr_align_t; + +typedef struct mac_mapping_ { + mac_addr_align_t mac; + uint32_t ip; +} mac_mapping_t; + +class CFlowGenListMac { +public: + CFlowGenListMac() { + set_configured(false); + } + + std::map & + get_mac_info () { + return m_mac_info; + } + + bool is_configured() { + return is_mac_info_configured; + } + + void set_configured(bool is_conf) { + is_mac_info_configured = is_conf; + } + + void clear() { + set_configured(false); + m_mac_info.clear(); + } + + uint32_t is_mac_exist(uint32_t ip) { + if (is_configured()) { + return m_mac_info.count(ip); + } else { + return 0; + } + } + mac_addr_align_t* get_mac_addr_by_ip(uint32_t ip) { + if (is_mac_exist(ip)!=0) { + return &(m_mac_info[ip]); + } + return NULL; + } +private: + bool is_mac_info_configured; + std::map m_mac_info; /* global mac info loaded form mac_file*/ +}; + +#endif //MAC_MAPPING_H_ diff --git a/src/tuple_gen.h b/src/tuple_gen.h index 205014c5..204dda0d 100755 --- a/src/tuple_gen.h +++ b/src/tuple_gen.h @@ -37,10 +37,97 @@ limitations under the License. #include "common/c_common.h" #include #include - +#include #include +class CTupleBase { +public: + CTupleBase() { + m_client_mac.inused = UNUSED; + } + uint32_t getClient() { + return m_client_ip; + } + void setClient(uint32_t ip) { + m_client_ip = ip; + } + uint32_t getClientId() { + return m_client_idx; + } + void setClientId(uint32_t id) { + m_client_idx = id; + } + + uint32_t getServer(){ + return m_server_ip; + } + void setServer(uint32_t ip) { + m_server_ip = ip; + } + uint32_t getServerId(){ + return m_server_idx; + } + void setServerId(uint32_t id) { + m_server_idx = id; + } + uint16_t getServerPort() { + return m_server_port; + } + void setServerPort(uint16_t port) { + m_server_port = port; + } + uint16_t getClientPort() { + return m_client_port; + } + void setClientPort(uint16_t port) { + m_client_port = port; + } + mac_addr_align_t* getClientMac() { + return &m_client_mac; + } + void setClientMac(mac_addr_align_t* mac_info) { + if (mac_info != NULL) { + memcpy(&m_client_mac, mac_info, sizeof(mac_addr_align_t)); + m_client_mac.inused = INUSED; + } else { + m_client_mac.inused = UNUSED; + } + } + void setClientTuple(uint32_t ip,mac_addr_align_t*mac,uint16_t port) { + setClient(ip); + setClientMac(mac); + setClientPort(port); + } + void setClientAll2(uint32_t id, uint32_t ip,uint16_t port) { + setClientId(id); + setClient(ip); + setClientPort(port); + } + + void setServerAll(uint32_t id, uint32_t ip) { + setServerId(id); + setServer(ip); + } + void getClientAll(uint32_t & id, uint32_t & ip, uint32_t & port) { + id = getClientId(); + ip = getClient(); + port = getClientPort(); + } + void getServerAll(uint32_t & id, uint32_t & ip) { + id = getServerId(); + ip = getServer(); + } +private: + uint32_t m_client_ip; + uint32_t m_client_idx; + uint32_t m_server_ip; + uint32_t m_server_idx; + mac_addr_align_t m_client_mac; + uint16_t m_client_port; + uint16_t m_server_port; +}; + /* @@ -59,9 +146,8 @@ limitations under the License. #define FOREACH(vector) for(int i=0;i & - get_mac_info () { - return m_mac_info; - } - - bool is_configured() { - return is_mac_info_configured; - } - - void set_configured(bool is_conf) { - is_mac_info_configured = is_conf; - } - - void clear() { - set_configured(false); - m_mac_info.clear(); - } - - uint32_t get_mac_info_cnt(uint32_t ip) { - if (is_configured()) { - return m_mac_info.count(ip); - } else { - return 0; - } - } - mac_addr_align_t* get_mac_addr_by_ip(uint32_t ip) { - if (get_mac_info_cnt(ip)>0) { - return &(m_mac_info[ip]); - } - return NULL; - } -private: - bool is_mac_info_configured; - std::map m_mac_info; /* global mac info loaded form mac_file*/ -}; - class CIpInfoBase { public: virtual mac_addr_align_t* get_mac() { return NULL;} virtual void set_mac(mac_addr_align_t*){;} virtual uint16_t get_new_free_port() = 0; virtual void return_port(uint16_t a) = 0; + virtual void generate_tuple(CTupleBase & tuple) = 0; virtual void return_all_ports() = 0; uint32_t get_ip() { return m_ip; @@ -154,7 +183,7 @@ class CIpInfoBase { void set_ip(uint32_t ip) { m_ip = ip; } - private: + protected: uint32_t m_ip; }; @@ -274,32 +303,37 @@ class CIpInfo : public CIpInfoBase { }; class CClientInfo : public CIpInfo { - public: - CClientInfo (bool has_mac) { - if (has_mac==true) { - m_mac = new mac_addr_align_t(); - } else { - m_mac = NULL; - } - } - CClientInfo () { +public: + CClientInfo (bool has_mac) { + if (has_mac==true) { + m_mac = new mac_addr_align_t(); + } else { m_mac = NULL; } - - mac_addr_align_t* get_mac() { - return m_mac; - } - void set_mac(mac_addr_align_t *mac) { - memcpy(m_mac, mac, sizeof(mac_addr_align_t)); - } - ~CClientInfo() { - if (m_mac!=NULL){ - delete m_mac; - m_mac=NULL; - } + } + CClientInfo () { + m_mac = NULL; + } + + mac_addr_align_t* get_mac() { + return m_mac; + } + void set_mac(mac_addr_align_t *mac) { + memcpy(m_mac, mac, sizeof(mac_addr_align_t)); + } + ~CClientInfo() { + if (m_mac!=NULL){ + delete m_mac; + m_mac=NULL; } - private: - mac_addr_align_t *m_mac; + } + + void generate_tuple(CTupleBase & tuple) { + tuple.setClientTuple(m_ip, m_mac, + get_new_free_port()); + } +private: + mac_addr_align_t *m_mac; }; class CClientInfoL : public CIpInfoL { @@ -314,118 +348,40 @@ public: CClientInfoL () { m_mac = NULL; } - + mac_addr_align_t* get_mac() { return m_mac; } + void set_mac(mac_addr_align_t *mac) { memcpy(m_mac, mac, sizeof(mac_addr_align_t)); } + ~CClientInfoL() { - if (m_mac!=NULL) { + if (m_mac!=NULL){ delete m_mac; m_mac=NULL; } } + + void generate_tuple(CTupleBase & tuple) { + tuple.setClientTuple(m_ip, m_mac, + get_new_free_port()); + } private: mac_addr_align_t *m_mac; }; class CServerInfo : public CIpInfo { - ; + void generate_tuple(CTupleBase & tuple) { + tuple.setServer(m_ip); + } }; class CServerInfoL : public CIpInfoL { - ; -}; - - -class CTupleBase { -public: - CTupleBase() { - m_client_mac.inused = UNUSED; - } - uint32_t getClient() { - return m_client_ip; - } - void setClient(uint32_t ip) { - m_client_ip = ip; - } - uint32_t getClientId() { - return m_client_idx; - } - void setClientId(uint32_t id) { - m_client_idx = id; - } - - uint32_t getServer(){ - return m_server_ip; - } - void setServer(uint32_t ip) { - m_server_ip = ip; - } - uint32_t getServerId(){ - return m_server_idx; - } - void setServerId(uint32_t id) { - m_server_idx = id; - } - uint16_t getServerPort() { - return m_server_port; - } - void setServerPort(uint16_t port) { - m_server_port = port; - } - uint16_t getClientPort() { - return m_client_port; - } - void setClientPort(uint16_t port) { - m_client_port = port; - } - mac_addr_align_t* getClientMac() { - return &m_client_mac; - } - void setClientMac(mac_addr_align_t* mac_info) { - if (mac_info != NULL) { - memcpy(&m_client_mac, mac_info, sizeof(mac_addr_align_t)); - m_client_mac.inused = INUSED; - } else { - m_client_mac.inused = UNUSED; - } - } - void setClientAll(uint32_t id, uint32_t ip,mac_addr_align_t*mac,uint16_t port) { - setClientId(id); - setClient(ip); - setClientMac(mac); - setClientPort(port); - } - void setClientAll2(uint32_t id, uint32_t ip,uint16_t port) { - setClientId(id); - setClient(ip); - setClientPort(port); - } - - void setServerAll(uint32_t id, uint32_t ip) { - setServerId(id); - setServer(ip); - } - void getClientAll(uint32_t & id, uint32_t & ip, uint32_t & port) { - id = getClientId(); - ip = getClient(); - port = getClientPort(); - } - void getServerAll(uint32_t & id, uint32_t & ip) { - id = getServerId(); - ip = getServer(); - } -private: - uint32_t m_client_ip; - uint32_t m_client_idx; - uint32_t m_server_ip; - uint32_t m_server_idx; - mac_addr_align_t m_client_mac; - uint16_t m_client_port; - uint16_t m_server_port; + void generate_tuple(CTupleBase & tuple) { + tuple.setServer(m_ip); + } }; @@ -445,7 +401,8 @@ class CIpPool { m_active_alloc++; return (port); } - bool is_valid_ip(uint32_t ip){ + + bool is_valid_ip(uint32_t ip){ CIpInfoBase* ip_front = m_ip_info.front(); CIpInfoBase* ip_back = m_ip_info.back(); if ((ip>=ip_front->get_ip()) && @@ -486,6 +443,9 @@ class CIpPool { inc_cur_idx(); return res_idx; } + + + void set_dist(IP_DIST_t dist) { if (dist>=cdMAX_DIST) { m_dist = cdSEQ_DIST; @@ -555,13 +515,6 @@ class CIpPool { class CClientPool : public CIpPool { public: - void GenerateTuple(CTupleBase & tuple) { - uint32_t idx = generate_ip(); - tuple.setClientAll(idx, - get_ip(idx), - get_mac(idx), - GenerateOnePort(idx)); - } uint16_t get_tcp_aging() { return m_tcp_aging; } @@ -577,6 +530,21 @@ public: bool has_mac_map, uint16_t tcp_aging, uint16_t udp_aging); + + uint32_t GenerateTuple(CTupleBase & tuple) { + uint32_t idx = generate_ip(); + CIpInfoBase* ip_info = m_ip_info[idx]; + ip_info->generate_tuple(tuple); + + tuple.setClientId(idx); + if (tuple.getClientPort()==ILLEGAL_PORT) { + m_port_allocation_error++; + } + m_active_alloc++; + return idx; + } + + public: uint16_t m_tcp_aging; uint16_t m_udp_aging; -- cgit From 0fa1d736246a7efc9aec1e9030a60954649a8d2d Mon Sep 17 00:00:00 2001 From: root Date: Fri, 9 Oct 2015 14:19:11 -0400 Subject: minor change --- src/tuple_gen.h | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/tuple_gen.h b/src/tuple_gen.h index 204dda0d..4b181ad5 100755 --- a/src/tuple_gen.h +++ b/src/tuple_gen.h @@ -515,6 +515,20 @@ class CIpPool { class CClientPool : public CIpPool { public: + + uint32_t GenerateTuple(CTupleBase & tuple) { + uint32_t idx = generate_ip(); + CIpInfoBase* ip_info = m_ip_info[idx]; + ip_info->generate_tuple(tuple); + + tuple.setClientId(idx); + if (tuple.getClientPort()==ILLEGAL_PORT) { + m_port_allocation_error++; + } + m_active_alloc++; + return idx; + } + uint16_t get_tcp_aging() { return m_tcp_aging; } @@ -531,20 +545,6 @@ public: uint16_t tcp_aging, uint16_t udp_aging); - uint32_t GenerateTuple(CTupleBase & tuple) { - uint32_t idx = generate_ip(); - CIpInfoBase* ip_info = m_ip_info[idx]; - ip_info->generate_tuple(tuple); - - tuple.setClientId(idx); - if (tuple.getClientPort()==ILLEGAL_PORT) { - m_port_allocation_error++; - } - m_active_alloc++; - return idx; - } - - public: uint16_t m_tcp_aging; uint16_t m_udp_aging; -- 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/main_dpdk.cpp | 2 +- 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 +++++++++++++++++++++++++++++ 6 files changed, 104 insertions(+), 12 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') diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index e3d13f2b..36d5052e 100755 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -4215,7 +4215,7 @@ static int stateless_entry(__attribute__((unused)) void *dummy) { if (lpsock->thread_phy_is_master( phy_id )) { TrexStateless::get_instance().launch_control_plane(); } else { - TrexStateless::get_instance().launch_on_dp_core(); + TrexStateless::get_instance().launch_on_dp_core(phy_id); } return (0); 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/bp_sim.h | 13 +++- src/main_dpdk.cpp | 35 +++++----- src/mock/rte_ethdev.h | 44 ++++++++++++ src/mock/trex_rpc_server_mock.cpp | 92 +++++++++++++++++++++++++ src/rpc-server/trex_rpc_async_server.cpp | 12 +++- src/rpc-server/trex_rpc_async_server.h | 2 +- src/rpc-server/trex_rpc_req_resp_server.cpp | 12 +++- src/rpc-server/trex_rpc_req_resp_server.h | 2 +- src/rpc-server/trex_rpc_server.cpp | 9 +-- src/rpc-server/trex_rpc_server_api.h | 7 +- src/rpc-server/trex_rpc_server_mock.cpp | 92 ------------------------- 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 + src/tuple_gen.h | 5 +- 18 files changed, 408 insertions(+), 148 deletions(-) create mode 100644 src/mock/rte_ethdev.h create mode 100644 src/mock/trex_rpc_server_mock.cpp delete mode 100644 src/rpc-server/trex_rpc_server_mock.cpp (limited to 'src') diff --git a/src/bp_sim.h b/src/bp_sim.h index 2f445cb7..18cd9b97 100755 --- a/src/bp_sim.h +++ b/src/bp_sim.h @@ -221,7 +221,9 @@ private: memset(m_pyload_mbuf_ptr+len+m_new_pkt_size,0xa,(-m_new_pkt_size)); } + return (0); } + public: int16_t m_new_pkt_size; /* New packet size after transform by plugin */ CFlowPktInfo * m_pkt_info; @@ -302,7 +304,7 @@ public: void CVirtualIFPerSideStats::Dump(FILE *fd){ - #define DP_B(f) if (f) printf(" %-40s : %llu \n",#f,f) + #define DP_B(f) if (f) printf(" %-40s : %lu \n",#f,f) DP_B(m_tx_pkt); DP_B(m_tx_rx_check_pkt); DP_B(m_tx_bytes); @@ -1440,7 +1442,7 @@ public: inline bool is_eligible_from_server_side(){ - return ( (m_src_ip&1==1)?true:false); + return ( ( (m_src_ip&1) == 1)?true:false); } @@ -1647,7 +1649,7 @@ public: */ inline int check_objects_sizes(void){ if ( sizeof(CGenNodeDeferPort) != sizeof(CGenNode) ) { - printf("ERROR sizeof(CGenNodeDeferPort) %d != sizeof(CGenNode) %d must be the same size \n",sizeof(CGenNodeDeferPort),sizeof(CGenNode)); + printf("ERROR sizeof(CGenNodeDeferPort) %lu != sizeof(CGenNode) %lu must be the same size \n",sizeof(CGenNodeDeferPort),sizeof(CGenNode)); assert(0); } if ( (int)offsetof(struct CGenNodeDeferPort,m_type)!=offsetof(struct CGenNode,m_type) ){ @@ -2587,6 +2589,8 @@ inline void CFlowPktInfo::update_pkt_info2(char *p, EthernetHeader * et = (EthernetHeader * )(p + m_pkt_indication.getFastEtherOffset()); + (void)et; + if ( unlikely (m_pkt_indication.is_ipv6())) { IPv6Header *ipv6= (IPv6Header *)ipv4; @@ -2669,6 +2673,8 @@ inline void CFlowPktInfo::update_pkt_info(char *p, EthernetHeader * et = (EthernetHeader * )(p + m_pkt_indication.getFastEtherOffset()); + (void)et; + uint16_t src_port = node->m_src_port; pkt_dir_t ip_dir = node->cur_pkt_ip_addr_dir(); @@ -2869,6 +2875,7 @@ inline rte_mbuf_t * CFlowPktInfo::do_generate_new_mbuf_ex_vm(CGenNode * node, /* need to update the mbuf size here .., this is not must but needed for accuracy */ uint16_t buf_adjust = len - vm.m_new_pkt_size; int rc = rte_pktmbuf_trim(m, buf_adjust); + (void)rc; /* update IP length , and TCP checksum , we can accelerate this using hardware ! */ uint16_t pkt_adjust = vm.m_new_pkt_size - m_packet->pkt_len; diff --git a/src/main_dpdk.cpp b/src/main_dpdk.cpp index 36d5052e..fe972d2f 100755 --- a/src/main_dpdk.cpp +++ b/src/main_dpdk.cpp @@ -2735,7 +2735,7 @@ public: } public: - bool Create(); + bool Create(bool is_stateless); void Delete(); int ixgbe_prob_init(); @@ -3409,18 +3409,22 @@ int CGlobalPortCfg::ixgbe_start(void){ } -bool CGlobalPortCfg::Create(){ - - if ( !m_zmq_publisher.Create( CGlobalInfo::m_options.m_zmq_port, - !CGlobalInfo::m_options.preview.get_zmq_publish_enable() ) ){ - return (false); - } +bool CGlobalPortCfg::Create(bool is_stateless){ + /* hack - need to refactor */ + if (!is_stateless) { + if ( !m_zmq_publisher.Create( CGlobalInfo::m_options.m_zmq_port, + !CGlobalInfo::m_options.preview.get_zmq_publish_enable() ) ){ + return (false); + } + } /* We load the YAML twice, this is the first time. to update global flags */ CFlowsYamlInfo pre_yaml_info; - pre_yaml_info.load_from_yaml_file(CGlobalInfo::m_options.cfg_file); + if (!is_stateless) { + pre_yaml_info.load_from_yaml_file(CGlobalInfo::m_options.cfg_file); + } if ( pre_yaml_info.m_vlan_info.m_enable ){ CGlobalInfo::m_options.preview.set_vlan_mode_enable(true); @@ -4513,12 +4517,6 @@ int main_test(int argc , char * argv[]){ rte_exit(EXIT_FAILURE, "Invalid EAL arguments\n"); } - /* patch here */ - if (CGlobalInfo::m_options.m_run_mode == CParserOption::RUN_MODE_INTERACTIVE) { - return launch_stateless_trex(); - } - - time_init(); /* check if we are in simulation mode */ @@ -4527,11 +4525,18 @@ int main_test(int argc , char * argv[]){ return ( sim_load_list_of_cap_files(&CGlobalInfo::m_options) ); } + bool is_stateless = (CGlobalInfo::m_options.m_run_mode == CParserOption::RUN_MODE_INTERACTIVE); - if ( !ports_cfg.Create() ){ + if ( !ports_cfg.Create(is_stateless) ){ exit(1); } + /* patch here */ + if (is_stateless) { + return launch_stateless_trex(); + } + + if (po->preview.get_is_rx_check_enable() && (po->m_rx_check_sampe< get_min_sample_rate()) ) { po->m_rx_check_sampe = get_min_sample_rate(); printf("Warning rx check sample rate should be lower than %d setting it to %d\n",get_min_sample_rate(),get_min_sample_rate()); diff --git a/src/mock/rte_ethdev.h b/src/mock/rte_ethdev.h new file mode 100644 index 00000000..046d8366 --- /dev/null +++ b/src/mock/rte_ethdev.h @@ -0,0 +1,44 @@ +/* + 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 __MOCK_FILE_RTE_ETHDEV_H__ +#define __MOCK_FILE_RTE_ETHDEV_H__ + +#include + +struct rte_eth_stats { + uint64_t obytes; + uint64_t ibytes; + uint64_t opackets; + uint64_t ipackets; +}; + +static inline void +rte_eth_stats_get(uint8_t port_id, struct rte_eth_stats *stats) { + memset(stats, 0, sizeof(rte_eth_stats)); +} + +static inline uint16_t +rte_eth_tx_burst(uint8_t port_id, uint16_t queue_id, + struct rte_mbuf **tx_pkts, uint16_t nb_pkts) { + return (0); +} + +#endif /* __MOCK_FILE_RTE_ETHDEV_H__ */ diff --git a/src/mock/trex_rpc_server_mock.cpp b/src/mock/trex_rpc_server_mock.cpp new file mode 100644 index 00000000..de43f92f --- /dev/null +++ b/src/mock/trex_rpc_server_mock.cpp @@ -0,0 +1,92 @@ +/* + 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 + +using namespace std; + +/** + * on simulation this is not rebuild every version + * (improved stub) + * + */ +extern "C" const char * get_build_date(void){ + return (__DATE__); +} + +extern "C" const char * get_build_time(void){ + return (__TIME__ ); +} + +int gtest_main(int argc, char **argv); + +int main(int argc, char *argv[]) { + + bool is_gtest = false; + + // gtest ? + if (argc > 1) { + if (string(argv[1]) != "--ut") { + cout << "\n[Usage] " << argv[0] << ": " << " [--ut]\n\n"; + exit(-1); + } + is_gtest = true; + } + + /* configure the stateless object with 4 ports */ + TrexStatelessCfg cfg; + + TrexRpcServerConfig rpc_req_resp_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5050); + TrexRpcServerConfig rpc_async_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5051); + + cfg.m_port_count = 4; + cfg.m_dp_core_count = 2; + cfg.m_rpc_req_resp_cfg = &rpc_req_resp_cfg; + cfg.m_rpc_async_cfg = &rpc_async_cfg; + cfg.m_rpc_server_verbose = (is_gtest ? false : true); + + TrexStateless::configure(cfg); + + TrexStateless::get_instance().launch_control_plane(); + + /* gtest handling */ + if (is_gtest) { + int rc = gtest_main(argc, argv); + TrexStateless::destroy(); + return rc; + } + + cout << "\n-= Starting RPC Server Mock =-\n\n"; + cout << "Listening on tcp://localhost:5050 [ZMQ]\n\n"; + + cout << "Server Started\n\n"; + + while (true) { + sleep(1); + } + + TrexStateless::destroy(); +} + diff --git a/src/rpc-server/trex_rpc_async_server.cpp b/src/rpc-server/trex_rpc_async_server.cpp index 3313e42e..f4d21f2f 100644 --- a/src/rpc-server/trex_rpc_async_server.cpp +++ b/src/rpc-server/trex_rpc_async_server.cpp @@ -36,7 +36,7 @@ limitations under the License. * ZMQ based publisher server * */ -TrexRpcServerAsync::TrexRpcServerAsync(const TrexRpcServerConfig &cfg) : TrexRpcServerInterface(cfg, "publisher") { +TrexRpcServerAsync::TrexRpcServerAsync(const TrexRpcServerConfig &cfg, std::mutex *lock) : TrexRpcServerInterface(cfg, "publisher", lock) { /* ZMQ is not thread safe - this should be outside */ m_context = zmq_ctx_new(); } @@ -73,9 +73,19 @@ TrexRpcServerAsync::_rpc_thread_cb() { Json::Value snapshot; Json::FastWriter writer; + /* if lock was provided - take it */ + if (m_lock) { + m_lock->lock(); + } + /* trigger a full update for stats */ TrexStateless::get_instance().update_stats(); + /* done with the lock */ + if (m_lock) { + m_lock->unlock(); + } + /* encode them to JSON */ TrexStateless::get_instance().encode_stats(snapshot); diff --git a/src/rpc-server/trex_rpc_async_server.h b/src/rpc-server/trex_rpc_async_server.h index 13525c01..02d1490e 100644 --- a/src/rpc-server/trex_rpc_async_server.h +++ b/src/rpc-server/trex_rpc_async_server.h @@ -33,7 +33,7 @@ limitations under the License. class TrexRpcServerAsync : public TrexRpcServerInterface { public: - TrexRpcServerAsync(const TrexRpcServerConfig &cfg); + TrexRpcServerAsync(const TrexRpcServerConfig &cfg, std::mutex *lock = NULL); protected: void _rpc_thread_cb(); diff --git a/src/rpc-server/trex_rpc_req_resp_server.cpp b/src/rpc-server/trex_rpc_req_resp_server.cpp index 3d52686c..9147f75d 100644 --- a/src/rpc-server/trex_rpc_req_resp_server.cpp +++ b/src/rpc-server/trex_rpc_req_resp_server.cpp @@ -34,7 +34,7 @@ limitations under the License. * ZMQ based request-response server * */ -TrexRpcServerReqRes::TrexRpcServerReqRes(const TrexRpcServerConfig &cfg) : TrexRpcServerInterface(cfg, "req resp") { +TrexRpcServerReqRes::TrexRpcServerReqRes(const TrexRpcServerConfig &cfg, std::mutex *lock) : TrexRpcServerInterface(cfg, "req resp", lock) { /* ZMQ is not thread safe - this should be outside */ m_context = zmq_ctx_new(); } @@ -127,6 +127,11 @@ void TrexRpcServerReqRes::handle_request(const std::string &request) { int index = 0; + /* if lock was provided, take it */ + if (m_lock) { + m_lock->lock(); + } + /* for every command parsed - launch it */ for (auto command : commands) { Json::Value single_response; @@ -138,6 +143,11 @@ void TrexRpcServerReqRes::handle_request(const std::string &request) { } + /* done with the lock */ + if (m_lock) { + m_lock->unlock(); + } + /* write the JSON to string and sever on ZMQ */ std::string response_str; diff --git a/src/rpc-server/trex_rpc_req_resp_server.h b/src/rpc-server/trex_rpc_req_resp_server.h index 7c1d66d1..1f638adf 100644 --- a/src/rpc-server/trex_rpc_req_resp_server.h +++ b/src/rpc-server/trex_rpc_req_resp_server.h @@ -32,7 +32,7 @@ limitations under the License. class TrexRpcServerReqRes : public TrexRpcServerInterface { public: - TrexRpcServerReqRes(const TrexRpcServerConfig &cfg); + TrexRpcServerReqRes(const TrexRpcServerConfig &cfg, std::mutex *lock = NULL); protected: void _rpc_thread_cb(); diff --git a/src/rpc-server/trex_rpc_server.cpp b/src/rpc-server/trex_rpc_server.cpp index 8749c9b4..a14e6f97 100644 --- a/src/rpc-server/trex_rpc_server.cpp +++ b/src/rpc-server/trex_rpc_server.cpp @@ -30,7 +30,7 @@ limitations under the License. /************** RPC server interface ***************/ -TrexRpcServerInterface::TrexRpcServerInterface(const TrexRpcServerConfig &cfg, const std::string &name) : m_cfg(cfg), m_name(name) { +TrexRpcServerInterface::TrexRpcServerInterface(const TrexRpcServerConfig &cfg, const std::string &name, std::mutex *lock) : m_cfg(cfg), m_name(name), m_lock(lock) { m_is_running = false; m_is_verbose = false; } @@ -114,16 +114,17 @@ get_current_date_time() { const std::string TrexRpcServer::s_server_uptime = get_current_date_time(); TrexRpcServer::TrexRpcServer(const TrexRpcServerConfig *req_resp_cfg, - const TrexRpcServerConfig *async_cfg) { + const TrexRpcServerConfig *async_cfg, + std::mutex *lock) { /* add the request response server */ if (req_resp_cfg) { - m_servers.push_back(new TrexRpcServerReqRes(*req_resp_cfg)); + m_servers.push_back(new TrexRpcServerReqRes(*req_resp_cfg, lock)); } /* add async publisher */ if (async_cfg) { - m_servers.push_back(new TrexRpcServerAsync(*async_cfg)); + m_servers.push_back(new TrexRpcServerAsync(*async_cfg, lock)); } } diff --git a/src/rpc-server/trex_rpc_server_api.h b/src/rpc-server/trex_rpc_server_api.h index 327c6eaa..ff876ac4 100644 --- a/src/rpc-server/trex_rpc_server_api.h +++ b/src/rpc-server/trex_rpc_server_api.h @@ -24,6 +24,7 @@ limitations under the License. #include #include +#include #include #include #include @@ -68,7 +69,7 @@ private: class TrexRpcServerInterface { public: - TrexRpcServerInterface(const TrexRpcServerConfig &cfg, const std::string &name); + TrexRpcServerInterface(const TrexRpcServerConfig &cfg, const std::string &name, std::mutex *m_lock = NULL); virtual ~TrexRpcServerInterface(); /** @@ -127,6 +128,7 @@ protected: bool m_is_verbose; std::thread *m_thread; std::string m_name; + std::mutex *m_lock; }; /** @@ -141,7 +143,8 @@ public: /* creates the collection of servers using configurations */ TrexRpcServer(const TrexRpcServerConfig *req_resp_cfg, - const TrexRpcServerConfig *async_cfg); + const TrexRpcServerConfig *async_cfg, + std::mutex *m_lock = NULL); ~TrexRpcServer(); diff --git a/src/rpc-server/trex_rpc_server_mock.cpp b/src/rpc-server/trex_rpc_server_mock.cpp deleted file mode 100644 index de43f92f..00000000 --- a/src/rpc-server/trex_rpc_server_mock.cpp +++ /dev/null @@ -1,92 +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 -#include - -using namespace std; - -/** - * on simulation this is not rebuild every version - * (improved stub) - * - */ -extern "C" const char * get_build_date(void){ - return (__DATE__); -} - -extern "C" const char * get_build_time(void){ - return (__TIME__ ); -} - -int gtest_main(int argc, char **argv); - -int main(int argc, char *argv[]) { - - bool is_gtest = false; - - // gtest ? - if (argc > 1) { - if (string(argv[1]) != "--ut") { - cout << "\n[Usage] " << argv[0] << ": " << " [--ut]\n\n"; - exit(-1); - } - is_gtest = true; - } - - /* configure the stateless object with 4 ports */ - TrexStatelessCfg cfg; - - TrexRpcServerConfig rpc_req_resp_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5050); - TrexRpcServerConfig rpc_async_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5051); - - cfg.m_port_count = 4; - cfg.m_dp_core_count = 2; - cfg.m_rpc_req_resp_cfg = &rpc_req_resp_cfg; - cfg.m_rpc_async_cfg = &rpc_async_cfg; - cfg.m_rpc_server_verbose = (is_gtest ? false : true); - - TrexStateless::configure(cfg); - - TrexStateless::get_instance().launch_control_plane(); - - /* gtest handling */ - if (is_gtest) { - int rc = gtest_main(argc, argv); - TrexStateless::destroy(); - return rc; - } - - cout << "\n-= Starting RPC Server Mock =-\n\n"; - cout << "Listening on tcp://localhost:5050 [ZMQ]\n\n"; - - cout << "Server Started\n\n"; - - while (true) { - sleep(1); - } - - TrexStateless::destroy(); -} - 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; }; diff --git a/src/tuple_gen.h b/src/tuple_gen.h index fb856538..c0add0be 100755 --- a/src/tuple_gen.h +++ b/src/tuple_gen.h @@ -113,6 +113,9 @@ class CIpInfoBase { void set_ip(uint32_t ip) { m_ip = ip; } + + virtual ~CIpInfoBase() {} + public: uint32_t m_ip; }; @@ -388,7 +391,7 @@ class CIpPool { (ip<=ip_back->get_ip())) { return(true); } - printf("invalid ip:%x, min_ip:%x, max_ip:%x, this:%x\n", + printf("invalid ip:%x, min_ip:%x, max_ip:%x, this:%p\n", ip, ip_front->get_ip(), ip_back->get_ip(),this); return(false); -- cgit From ba9973506c1de58c87ccaa59798fb4e6252a186e Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Sun, 18 Oct 2015 14:43:49 +0300 Subject: fix trex-130 issue --- src/platform_cfg.cpp | 64 +++++++++++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/platform_cfg.cpp b/src/platform_cfg.cpp index a226a9ac..db563cc9 100755 --- a/src/platform_cfg.cpp +++ b/src/platform_cfg.cpp @@ -262,12 +262,6 @@ void operator >> (const YAML::Node& node, CPlatformMemoryYamlInfo & plat_info) { void operator >> (const YAML::Node& node, CPlatformYamlInfo & plat_info) { - try { - node["port_limit"] >> plat_info.m_port_limit; - plat_info.m_port_limit_exist=true; - } catch ( const std::exception& e ) { - plat_info.m_port_limit=0xffffffff; - } try { @@ -284,14 +278,6 @@ void operator >> (const YAML::Node& node, CPlatformYamlInfo & plat_info) { } - try { - node["enable_zmq_pub"] >> plat_info.m_enable_zmq_pub; - node["zmq_pub_port"] >> plat_info.m_zmq_pub_port; - plat_info.m_enable_zmq_pub_exist = true; - } catch ( const std::exception& e ) { - plat_info.m_enable_zmq_pub_exist = false; - } - /* must have interfaces */ const YAML::Node& interfaces = node["interfaces"]; for(unsigned i=0;i> (const YAML::Node& node, CPlatformYamlInfo & plat_info) { plat_info.m_if_list.push_back(fi); } - try { - node["prefix"] >> plat_info.m_prefix; - } catch ( const std::exception& e ) { + + if ( node.FindValue("port_limit") ){ + node["port_limit"] >> plat_info.m_port_limit; + plat_info.m_port_limit_exist=true; } - try { - node["limit_memory"] >> plat_info.m_limit_memory; - } catch ( const std::exception& e ) { + + + plat_info.m_enable_zmq_pub_exist = true; + + if ( node.FindValue("enable_zmq_pub") ){ + node["enable_zmq_pub"] >> plat_info.m_enable_zmq_pub; + plat_info.m_enable_zmq_pub_exist = true; } - try { - node["c"] >> plat_info.m_thread_per_dual_if; - } catch ( const std::exception& e ) { + + if ( node.FindValue("zmq_pub_port") ){ + node["zmq_pub_port"] >> plat_info.m_zmq_pub_port; + plat_info.m_enable_zmq_pub_exist = true; } + if ( node.FindValue("prefix") ){ + node["prefix"] >> plat_info.m_prefix; + } + if ( node.FindValue("limit_memory") ){ + node["limit_memory"] >> plat_info.m_limit_memory; + } - try { - node["telnet_port"] >> plat_info.m_telnet_port; - plat_info.m_telnet_exist=true; - } catch ( const std::exception& e ) { - plat_info.m_telnet_port=4501; + if ( node.FindValue("c") ){ + node["c"] >> plat_info.m_thread_per_dual_if; } - try { - node["port_bandwidth_gb"] >> plat_info.m_port_bandwidth_gb; - } catch ( const std::exception& e ) { + if ( node.FindValue("telnet_port") ){ + node["telnet_port"] >> plat_info.m_telnet_port; + plat_info.m_telnet_exist=true; + } + + if ( node.FindValue("port_bandwidth_gb") ){ + node["port_bandwidth_gb"] >> plat_info.m_port_bandwidth_gb; } if ( node.FindValue("memory") ){ @@ -337,7 +336,7 @@ void operator >> (const YAML::Node& node, CPlatformYamlInfo & plat_info) { plat_info.m_platform.m_is_exists=true; } - try { + if ( node.FindValue("port_info") ) { const YAML::Node& mac_info = node["port_info"]; for(unsigned i=0;i> (const YAML::Node& node, CPlatformYamlInfo & plat_info) { plat_info.m_mac_info.push_back(fi); } plat_info.m_mac_info_exist = true; - }catch ( const std::exception& e ) { } } -- cgit From cf5dc18ecbeca6b4be9a171d996bba1cba9c3679 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Sun, 18 Oct 2015 16:16:39 +0300 Subject: another small fix for trex-130 --- src/bp_sim.cpp | 158 +++++++++++++++++++++++---------------------------- src/platform_cfg.cpp | 87 +++++++++++----------------- src/tuple_gen.cpp | 30 ++-------- src/utl_yaml.cpp | 18 +++--- 4 files changed, 117 insertions(+), 176 deletions(-) (limited to 'src') diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index fcefa50c..c3581c55 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -2350,21 +2350,13 @@ void operator >> (const YAML::Node& node, CFlowYamlDpPkt & fi) { void operator >> (const YAML::Node& node, CVlanYamlInfo & fi) { uint32_t tmp; - try { - node["enable"] >> tmp ; - fi.m_enable=tmp; - }catch ( const std::exception& e ) { - - } - - try { - node["vlan0"] >> tmp; - fi.m_vlan_per_port[0] = tmp; - node["vlan1"] >> tmp; - fi.m_vlan_per_port[1] = tmp; - }catch ( const std::exception& e ) { - // there is a default - + if ( node.FindValue("enable") ){ + node["enable"] >> tmp ; + fi.m_enable=tmp; + node["vlan0"] >> tmp; + fi.m_vlan_per_port[0] = tmp; + node["vlan1"] >> tmp; + fi.m_vlan_per_port[1] = tmp; } } @@ -2372,15 +2364,15 @@ void operator >> (const YAML::Node& node, CVlanYamlInfo & fi) { void operator >> (const YAML::Node& node, CFlowYamlInfo & fi) { node["name"] >> fi.m_name; - - try { + + if ( node.FindValue("client_pool") ){ node["client_pool"] >> fi.m_client_pool_name; - } catch ( const std::exception& e ) { + }else{ fi.m_client_pool_name = "default"; } - try { + if ( node.FindValue("server_pool") ){ node["server_pool"] >> fi.m_server_pool_name; - } catch ( const std::exception& e ) { + }else{ fi.m_server_pool_name = "default"; } @@ -2393,37 +2385,38 @@ void operator >> (const YAML::Node& node, CFlowYamlInfo & fi) { fi.m_rtt_sec = t/1000000.0; node["w"] >> fi.m_w; - try { + if ( node.FindValue("cap_ipg") ){ node["cap_ipg"] >> fi.m_cap_mode; fi.m_cap_mode_was_set =true; - } catch ( const std::exception& e ) { + }else{ fi.m_cap_mode_was_set =false; } - try { + if ( node.FindValue("wlength") ){ node["wlength"] >> fi.m_wlength; fi.m_wlength_set=true; - } catch ( const std::exception& e ) { + }else{ fi.m_wlength_set=false; fi.m_wlength =500; } - try { + if ( node.FindValue("limit") ){ node["limit"] >> fi.m_limit; fi.m_limit_was_set = true; - } catch ( const std::exception& e ) { + }else{ fi.m_limit_was_set = false; fi.m_limit = 0; } - try { + if ( node.FindValue("plugin_id") ){ uint32_t plugin_val; node["plugin_id"] >> plugin_val; fi.m_plugin_id=plugin_val; - } catch ( const std::exception& e ) { + }else{ fi.m_plugin_id=0; } + fi.m_one_app_server_was_set = false; fi.m_one_app_server = false; if ( utl_yaml_read_ip_addr(node, @@ -2446,30 +2439,26 @@ void operator >> (const YAML::Node& node, CFlowYamlInfo & fi) { } - try { - int i; - const YAML::Node& dyn_pyload = node["dyn_pyload"]; - for(unsigned i=0;i> fd; - if ( fi.m_dpPkt == 0 ){ - fi.m_dpPkt = new CFlowYamlDynamicPyloadPlugin(); - if (fi.m_plugin_id == 0) { - fi.m_plugin_id = mpDYN_PYLOAD; - }else{ - fprintf(stderr," plugin should be zero with dynamic pyload program"); - exit(-1); - } - } - - fd.Dump(stdout); - - fi.m_dpPkt->Add(fd); - printf(" here "); - } - } catch ( const std::exception& e ) { - fi.m_dpPkt=0; - } + if ( node.FindValue("dyn_pyload") ){ + int i; + const YAML::Node& dyn_pyload = node["dyn_pyload"]; + for(unsigned i=0;i> fd; + if ( fi.m_dpPkt == 0 ){ + fi.m_dpPkt = new CFlowYamlDynamicPyloadPlugin(); + if (fi.m_plugin_id == 0) { + fi.m_plugin_id = mpDYN_PYLOAD; + }else{ + fprintf(stderr," plugin should be zero with dynamic pyload program"); + exit(-1); + } + } + fi.m_dpPkt->Add(fd); + } + }else{ + fi.m_dpPkt=0; + } } @@ -2478,13 +2467,12 @@ void operator >> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { node["duration"] >> flows_info.m_duration_sec; - try { - node["generator"] >> flows_info.m_tuple_gen; - flows_info.m_tuple_gen_was_set =true; - } catch ( const std::exception& e ) { - flows_info.m_tuple_gen_was_set =false; + if ( node.FindValue("generator") ) { + node["generator"] >> flows_info.m_tuple_gen; + flows_info.m_tuple_gen_was_set =true; + }else{ + flows_info.m_tuple_gen_was_set =false; } - // m_ipv6_set will be true if and only if both src_ipv6 // and dst_ipv6 are provided. These are used to set @@ -2500,7 +2488,8 @@ void operator >> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { // formed by providing src_ipv6,dst_ipv6 and specifying // {0,0,0,0,0,0xffff} flows_info.m_ipv6_set=true; - try { + + if ( node.FindValue("src_ipv6") ) { const YAML::Node& src_ipv6_info = node["src_ipv6"]; if (src_ipv6_info.size() == 6 ){ for(unsigned i=0;i> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { node[i] >> fi; flows_info.m_src_ipv6.push_back(fi); } - }else{ - flows_info.m_ipv6_set=false; } - } catch ( const std::exception& e ) { + }else{ flows_info.m_ipv6_set=false; } - try { + + if ( node.FindValue("dst_ipv6") ) { const YAML::Node& dst_ipv6_info = node["dst_ipv6"]; if (dst_ipv6_info.size() == 6 ){ for(unsigned i=0;i> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { node[i] >> fi; flows_info.m_dst_ipv6.push_back(fi); } - }else{ - flows_info.m_ipv6_set=false; } - } catch ( const std::exception& e ) { + }else{ flows_info.m_ipv6_set=false; } - try { + if ( node.FindValue("cap_ipg") ) { node["cap_ipg"] >> flows_info.m_cap_mode; flows_info.m_cap_mode_set=true; - } catch ( const std::exception& e ) { + }else{ flows_info.m_cap_mode=false; flows_info.m_cap_mode_set=false; } - double t; - try { + double t=0.0; + + if ( node.FindValue("cap_ipg_min") ) { node["cap_ipg_min"] >> t ; flows_info.m_cap_ipg_min = t/1000000.0; flows_info.m_cap_ipg_min_set=true; - } catch ( const std::exception& e ) { + }else{ flows_info.m_cap_ipg_min_set=false; flows_info.m_cap_ipg_min = 20; } - try { + if ( node.FindValue("cap_override_ipg") ) { node["cap_override_ipg"] >> t; flows_info.m_cap_overide_ipg = t/1000000.0; flows_info.m_cap_overide_ipg_set = true; - } catch ( const std::exception& e ) { + }else{ flows_info.m_cap_overide_ipg_set = false; flows_info.m_cap_overide_ipg = 0; } - try { + if (node.FindValue("wlength")) { node["wlength"] >> flows_info.m_wlength; flows_info.m_wlength_set=true; - } catch ( const std::exception& e ) { + }else{ flows_info.m_wlength_set=false; flows_info.m_wlength =100; } - try { + if (node.FindValue("one_app_server")) { node["one_app_server"] >> flows_info.m_one_app_server; flows_info.m_one_app_server_was_set=true; - } catch ( const std::exception& e ) { + }else{ flows_info.m_one_app_server =false; flows_info.m_one_app_server_was_set=false; } - try { - node["vlan"] >> flows_info.m_vlan_info; - } catch ( const std::exception& e ) { - } - try { - node["mac_override_by_ip"] >> flows_info.m_mac_replace_by_ip; - } catch ( const std::exception& e ) { - flows_info.m_mac_replace_by_ip =false; + if (node.FindValue("vlan")) { + node["vlan"] >> flows_info.m_vlan_info; } + if (node.FindValue("mac_override_by_ip")) { + node["mac_override_by_ip"] >> flows_info.m_mac_replace_by_ip; + }else{ + flows_info.m_mac_replace_by_ip =false; + } const YAML::Node& mac_info = node["mac"]; for(unsigned i=0;i> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { const YAML::Node & node =mac_info; node[i] >> fi; flows_info.m_mac_base.push_back(fi); - } + } const YAML::Node& cap_info = node["cap_info"]; for(unsigned i=0;i> (const YAML::Node& node, CMacYamlInfo & mac_info) { } void operator >> (const YAML::Node& node, CPlatformMemoryYamlInfo & plat_info) { - try { - node["mbuf_64"] >> plat_info.m_mbuf[MBUF_64]; - } catch ( const std::exception& e ) { + + if ( node.FindValue("mbuf_64") ){ + node["mbuf_64"] >> plat_info.m_mbuf[MBUF_64]; } - try { - node["mbuf_128"] >> plat_info.m_mbuf[MBUF_128]; - } catch ( const std::exception& e ) { + if ( node.FindValue("mbuf_128") ){ + node["mbuf_128"] >> plat_info.m_mbuf[MBUF_128]; } - try { - node["mbuf_256"] >> plat_info.m_mbuf[MBUF_256]; - } catch ( const std::exception& e ) { + if ( node.FindValue("mbuf_256") ){ + node["mbuf_256"] >> plat_info.m_mbuf[MBUF_256]; } - try { - node["mbuf_512"] >> plat_info.m_mbuf[MBUF_512]; - } catch ( const std::exception& e ) { + if ( node.FindValue("mbuf_512") ){ + node["mbuf_512"] >> plat_info.m_mbuf[MBUF_512]; } - try { - node["mbuf_1024"] >> plat_info.m_mbuf[MBUF_1024]; - } catch ( const std::exception& e ) { + if ( node.FindValue("mbuf_1024") ){ + node["mbuf_1024"] >> plat_info.m_mbuf[MBUF_1024]; } - try { - node["mbuf_2048"] >> plat_info.m_mbuf[MBUF_2048]; - } catch ( const std::exception& e ) { + if ( node.FindValue("mbuf_2048") ){ + node["mbuf_2048"] >> plat_info.m_mbuf[MBUF_2048]; } - try { - node["traffic_mbuf_64"] >> plat_info.m_mbuf[TRAFFIC_MBUF_64]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_64") ){ + node["traffic_mbuf_64"] >> plat_info.m_mbuf[TRAFFIC_MBUF_64]; } - try { - node["traffic_mbuf_128"] >> plat_info.m_mbuf[TRAFFIC_MBUF_128]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_128") ){ + node["traffic_mbuf_128"] >> plat_info.m_mbuf[TRAFFIC_MBUF_128]; } - try { - node["traffic_mbuf_256"] >> plat_info.m_mbuf[TRAFFIC_MBUF_256]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_256") ){ + node["traffic_mbuf_256"] >> plat_info.m_mbuf[TRAFFIC_MBUF_256]; } - try { - node["traffic_mbuf_512"] >> plat_info.m_mbuf[TRAFFIC_MBUF_512]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_512") ){ + node["traffic_mbuf_512"] >> plat_info.m_mbuf[TRAFFIC_MBUF_512]; } - try { - node["traffic_mbuf_1024"] >> plat_info.m_mbuf[TRAFFIC_MBUF_1024]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_1024") ){ + node["traffic_mbuf_1024"] >> plat_info.m_mbuf[TRAFFIC_MBUF_1024]; } - try { - node["traffic_mbuf_2048"] >> plat_info.m_mbuf[TRAFFIC_MBUF_2048]; - } catch ( const std::exception& e ) { + if ( node.FindValue("traffic_mbuf_2048") ){ + node["traffic_mbuf_2048"] >> plat_info.m_mbuf[TRAFFIC_MBUF_2048]; } - try { - node["dp_flows"] >> plat_info.m_mbuf[MBUF_DP_FLOWS]; - } catch ( const std::exception& e ) { + if ( node.FindValue("dp_flows") ){ + node["dp_flows"] >> plat_info.m_mbuf[MBUF_DP_FLOWS]; } - try { - node["global_flows"] >> plat_info.m_mbuf[MBUF_GLOBAL_FLOWS]; - } catch ( const std::exception& e ) { + if ( node.FindValue("global_flows") ){ + node["global_flows"] >> plat_info.m_mbuf[MBUF_GLOBAL_FLOWS]; } + } void operator >> (const YAML::Node& node, CPlatformYamlInfo & plat_info) { - - try { - const YAML::Node& interface_mask = node["interface_mask"]; - for(unsigned i=0;i> fi; - plat_info.m_if_mask.push_back(fi); - } - plat_info.m_if_mask_exist=true; - } catch ( const std::exception& e ) { - + if (node.FindValue("interface_mask")) { + printf("WARNING interface_mask in not used any more !\n"); } - /* must have interfaces */ const YAML::Node& interfaces = node["interfaces"]; for(unsigned i=0;i> (const YAML::Node& node, CTupleGenPoolYaml & fi) { fi.m_tcp_aging_sec = 0; fi.m_udp_aging_sec = 0; fi.m_dual_interface_mask = 0; - try { - utl_yaml_read_uint32(node,"clients_per_gb",fi.m_number_of_clients_per_gb); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_uint32(node,"min_clients",fi.m_min_clients); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_ip_addr(node,"dual_port_mask",fi.m_dual_interface_mask); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_uint16(node,"tcp_aging",fi.m_tcp_aging_sec); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_uint16(node,"udp_aging",fi.m_udp_aging_sec); - } catch ( const std::exception& e ) { - ;} - try { - node["track_ports"] >> fi.m_is_bundling; - } catch ( const std::exception& e ) { - ;} + utl_yaml_read_uint32(node,"clients_per_gb",fi.m_number_of_clients_per_gb); + utl_yaml_read_uint32(node,"min_clients",fi.m_min_clients); + utl_yaml_read_ip_addr(node,"dual_port_mask",fi.m_dual_interface_mask); + utl_yaml_read_uint16(node,"tcp_aging",fi.m_tcp_aging_sec); + utl_yaml_read_uint16(node,"udp_aging",fi.m_udp_aging_sec); + utl_yaml_read_bool(node,"track_ports",fi.m_is_bundling); } void copy_global_pool_para(CTupleGenPoolYaml & src, CTupleGenPoolYaml & dst) { if (src.m_number_of_clients_per_gb == 0) diff --git a/src/utl_yaml.cpp b/src/utl_yaml.cpp index 237e85af..5f3ca735 100755 --- a/src/utl_yaml.cpp +++ b/src/utl_yaml.cpp @@ -70,13 +70,15 @@ bool utl_yaml_read_ip_addr(const YAML::Node& node, std::string tmp; uint32_t ip; bool res=false; - try { + if ( node.FindValue(name) ) { node[name] >> tmp ; if ( my_inet_pton4((char *)tmp.c_str(), (unsigned char *)&ip) ){ val=PKT_NTOHL(ip); res=true; + }else{ + printf(" ERROR not a valid ip %s \n",(char *)tmp.c_str()); + exit(-1); } - }catch ( const std::exception& e ) { } return (res); } @@ -85,14 +87,11 @@ bool utl_yaml_read_uint32(const YAML::Node& node, std::string name, uint32_t & val){ bool res=false; - - try { + if ( node.FindValue(name) ) { node[name] >> val ; res=true; - }catch ( const std::exception& e ) { } return (res); - } bool utl_yaml_read_uint16(const YAML::Node& node, @@ -100,12 +99,10 @@ bool utl_yaml_read_uint16(const YAML::Node& node, uint16_t & val){ uint32_t val_tmp; bool res=false; - - try { + if ( node.FindValue(name) ) { node[name] >> val_tmp ; val = (uint16_t)val_tmp; res=true; - }catch ( const std::exception& e ) { } } @@ -113,10 +110,9 @@ bool utl_yaml_read_bool(const YAML::Node& node, std::string name, bool & val){ bool res=false; - try { + if ( node.FindValue(name) ) { node[name] >> val ; res=true; - }catch ( const std::exception& e ) { } return( res); } -- cgit From b9be7cb7e926c29706126d0bccf9e32c99c75070 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Mon, 19 Oct 2015 17:21:26 +0300 Subject: fix flow_var_name -> name --- src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index 812d819e..629e2f76 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -233,7 +233,7 @@ TrexRpcCmdAddStream::parse_vm_instr_flow_var(const Json::Value &inst, TrexStream void TrexRpcCmdAddStream::parse_vm_instr_write_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result) { - std::string flow_var_name = parse_string(inst, "flow_var_name", result); + std::string flow_var_name = parse_string(inst, "name", result); uint16_t pkt_offset = parse_uint16(inst, "pkt_offset", result); int add_value = parse_int(inst, "add_value", result); bool is_big_endian = parse_bool(inst, "is_big_endian", result); -- 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') 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 From f2d4fdad463a6d4ba0c3d8d0622fb6931425c7f9 Mon Sep 17 00:00:00 2001 From: wenxian li Date: Tue, 20 Oct 2015 00:45:49 -0400 Subject: trex-131 --- src/bp_sim.cpp | 83 +++++++++++++++++++++++++------------------------- src/tuple_gen.cpp | 90 +++++++++++++++++++++++++++---------------------------- 2 files changed, 85 insertions(+), 88 deletions(-) (limited to 'src') diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index fcefa50c..a51c20c3 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -2350,21 +2350,18 @@ void operator >> (const YAML::Node& node, CFlowYamlDpPkt & fi) { void operator >> (const YAML::Node& node, CVlanYamlInfo & fi) { uint32_t tmp; - try { + if (node.FindValue("enable")) { node["enable"] >> tmp ; fi.m_enable=tmp; - }catch ( const std::exception& e ) { - - } + } - try { + if (node.FindValue("vlan0")) { node["vlan0"] >> tmp; fi.m_vlan_per_port[0] = tmp; + } + if (node.FindValue("vlan1")) { node["vlan1"] >> tmp; fi.m_vlan_per_port[1] = tmp; - }catch ( const std::exception& e ) { - // there is a default - } } @@ -2373,14 +2370,15 @@ void operator >> (const YAML::Node& node, CVlanYamlInfo & fi) { void operator >> (const YAML::Node& node, CFlowYamlInfo & fi) { node["name"] >> fi.m_name; - try { + if (node.FindValue("client_pool")) { node["client_pool"] >> fi.m_client_pool_name; - } catch ( const std::exception& e ) { + } else { fi.m_client_pool_name = "default"; } - try { + + if (node.FindValue("server_pool")) { node["server_pool"] >> fi.m_server_pool_name; - } catch ( const std::exception& e ) { + } else { fi.m_server_pool_name = "default"; } @@ -2392,35 +2390,35 @@ void operator >> (const YAML::Node& node, CFlowYamlInfo & fi) { node["rtt"] >> t; fi.m_rtt_sec = t/1000000.0; node["w"] >> fi.m_w; - - try { + + if (node.FindValue("cap_ipg")) { node["cap_ipg"] >> fi.m_cap_mode; fi.m_cap_mode_was_set =true; - } catch ( const std::exception& e ) { + } else { fi.m_cap_mode_was_set =false; } - try { + if (node.FindValue("wlength")) { node["wlength"] >> fi.m_wlength; fi.m_wlength_set=true; - } catch ( const std::exception& e ) { + } else { fi.m_wlength_set=false; fi.m_wlength =500; } - try { + if (node.FindValue("limit")) { node["limit"] >> fi.m_limit; fi.m_limit_was_set = true; - } catch ( const std::exception& e ) { + } else { fi.m_limit_was_set = false; fi.m_limit = 0; } - try { + if (node.FindValue("plugin_id")) { uint32_t plugin_val; node["plugin_id"] >> plugin_val; fi.m_plugin_id=plugin_val; - } catch ( const std::exception& e ) { + } else { fi.m_plugin_id=0; } @@ -2429,10 +2427,10 @@ void operator >> (const YAML::Node& node, CFlowYamlInfo & fi) { if ( utl_yaml_read_ip_addr(node, "server_addr", fi.m_server_addr) ){ - try { + if (node.FindValue("one_app_server")) { node["one_app_server"] >> fi.m_one_app_server; fi.m_one_app_server_was_set=true; - } catch ( const std::exception& e ) { + } else { fi.m_one_app_server_was_set = false; fi.m_one_app_server = false; } @@ -2478,10 +2476,10 @@ void operator >> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { node["duration"] >> flows_info.m_duration_sec; - try { + if (node.FindValue("generator")) { node["generator"] >> flows_info.m_tuple_gen; flows_info.m_tuple_gen_was_set =true; - } catch ( const std::exception& e ) { + } else { flows_info.m_tuple_gen_was_set =false; } @@ -2500,7 +2498,7 @@ void operator >> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { // formed by providing src_ipv6,dst_ipv6 and specifying // {0,0,0,0,0,0xffff} flows_info.m_ipv6_set=true; - try { + if (node.FindValue("src_ipv6")) { const YAML::Node& src_ipv6_info = node["src_ipv6"]; if (src_ipv6_info.size() == 6 ){ for(unsigned i=0;i> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { }else{ flows_info.m_ipv6_set=false; } - } catch ( const std::exception& e ) { + } else { flows_info.m_ipv6_set=false; } - try { + if (node.FindValue("dst_ipv6")) { const YAML::Node& dst_ipv6_info = node["dst_ipv6"]; if (dst_ipv6_info.size() == 6 ){ for(unsigned i=0;i> (const YAML::Node& node, CFlowsYamlInfo & flows_info) { }else{ flows_info.m_ipv6_set=false; } - } catch ( const std::exception& e ) { + } else { flows_info.m_ipv6_set=false; } - try { + if (node.FindValue("cap_ipg")) { node["cap_ipg"] >> flows_info.m_cap_mode; flows_info.m_cap_mode_set=true; - } catch ( const std::exception& e ) { + } else { flows_info.m_cap_mode=false; flows_info.m_cap_mode_set=false; } double t; - try { + if (node.FindValue("cap_ipg_min")) { node["cap_ipg_min"] >> t ; flows_info.m_cap_ipg_min = t/1000000.0; flows_info.m_cap_ipg_min_set=true; - } catch ( const std::exception& e ) { + } else { flows_info.m_cap_ipg_min_set=false; flows_info.m_cap_ipg_min = 20; } - try { + if (node.FindValue("cap_override_ipg")) { node["cap_override_ipg"] >> t; flows_info.m_cap_overide_ipg = t/1000000.0; flows_info.m_cap_overide_ipg_set = true; - } catch ( const std::exception& e ) { + } else { flows_info.m_cap_overide_ipg_set = false; flows_info.m_cap_overide_ipg = 0; } - try { + if (node.FindValue("wlength")) { node["wlength"] >> flows_info.m_wlength; flows_info.m_wlength_set=true; - } catch ( const std::exception& e ) { + } else { flows_info.m_wlength_set=false; flows_info.m_wlength =100; } - try { + if (node.FindValue("one_app_server")) { node["one_app_server"] >> flows_info.m_one_app_server; flows_info.m_one_app_server_was_set=true; - } catch ( const std::exception& e ) { + } else { flows_info.m_one_app_server =false; flows_info.m_one_app_server_was_set=false; } - try { + if (node.FindValue("vlan")) { node["vlan"] >> flows_info.m_vlan_info; - } catch ( const std::exception& e ) { } - try { + if (node.FindValue("mac_override_by_ip")) { node["mac_override_by_ip"] >> flows_info.m_mac_replace_by_ip; - } catch ( const std::exception& e ) { + } else { flows_info.m_mac_replace_by_ip =false; } diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp index 3a477338..80a25f1a 100755 --- a/src/tuple_gen.cpp +++ b/src/tuple_gen.cpp @@ -223,12 +223,22 @@ bool CTupleGenPoolYaml::is_valid(uint32_t num_threads,bool is_plugins){ +#define UTL_YAML_READ(type, field, target) if (node.FindValue(#field)) { \ + utl_yaml_read_ ## type (node, #field , target); \ + } else { printf("error in generator definition -- " #field "\n"); } void operator >> (const YAML::Node& node, CTupleGenPoolYaml & fi) { std::string tmp; - node["name"] >> fi.m_name; - node["distribution"] >> tmp ; + if (node.FindValue("name")) { + node["name"] >> fi.m_name; + } else { + printf("error in generator definition, name missing\n"); + assert(0); + } + if (node.FindValue("distribution")) { + node["distribution"] >> tmp ; + } if (tmp == "random") { fi.m_dist=cdRANDOM_DIST; }else if (tmp == "normal") { @@ -236,39 +246,24 @@ void operator >> (const YAML::Node& node, CTupleGenPoolYaml & fi) { } else { fi.m_dist=cdSEQ_DIST; } - utl_yaml_read_ip_addr(node,"ip_start",fi.m_ip_start); - utl_yaml_read_ip_addr(node,"ip_end",fi.m_ip_end); - fi.m_number_of_clients_per_gb = 0; + UTL_YAML_READ(ip_addr, ip_start, fi.m_ip_start); + UTL_YAML_READ(ip_addr, ip_end, fi.m_ip_end); + fi.m_number_of_clients_per_gb = 0; fi.m_min_clients = 0; fi.m_is_bundling = false; fi.m_tcp_aging_sec = 0; fi.m_udp_aging_sec = 0; fi.m_dual_interface_mask = 0; - try { - utl_yaml_read_uint32(node,"clients_per_gb",fi.m_number_of_clients_per_gb); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_uint32(node,"min_clients",fi.m_min_clients); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_ip_addr(node,"dual_port_mask",fi.m_dual_interface_mask); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_uint16(node,"tcp_aging",fi.m_tcp_aging_sec); - } catch ( const std::exception& e ) { - ;} - try { - utl_yaml_read_uint16(node,"udp_aging",fi.m_udp_aging_sec); - } catch ( const std::exception& e ) { - ;} - try { + + UTL_YAML_READ(uint32, clients_per_gb, fi.m_number_of_clients_per_gb); + UTL_YAML_READ(uint32, min_clients, fi.m_min_clients); + UTL_YAML_READ(ip_addr, dual_port_mask, fi.m_dual_interface_mask); + UTL_YAML_READ(uint16, tcp_aging, fi.m_tcp_aging_sec); + UTL_YAML_READ(uint16, udp_aging, fi.m_udp_aging_sec); + if (node.FindValue("track_ports")) { node["track_ports"] >> fi.m_is_bundling; - } catch ( const std::exception& e ) { - ;} + } } void copy_global_pool_para(CTupleGenPoolYaml & src, CTupleGenPoolYaml & dst) { if (src.m_number_of_clients_per_gb == 0) @@ -282,12 +277,15 @@ void copy_global_pool_para(CTupleGenPoolYaml & src, CTupleGenPoolYaml & dst) { if (src.m_udp_aging_sec == 0) src.m_udp_aging_sec = dst.m_udp_aging_sec; } + + void operator >> (const YAML::Node& node, CTupleGenYamlInfo & fi) { std::string tmp; - try { - CTupleGenPoolYaml c_pool; - CTupleGenPoolYaml s_pool; + CTupleGenPoolYaml c_pool; + CTupleGenPoolYaml s_pool; + + if (node.FindValue("distribution")) { node["distribution"] >> tmp ; if (tmp == "random") { c_pool.m_dist=cdRANDOM_DIST; @@ -297,23 +295,24 @@ void operator >> (const YAML::Node& node, CTupleGenYamlInfo & fi) { c_pool.m_dist=cdSEQ_DIST; } s_pool.m_dist = c_pool.m_dist; - utl_yaml_read_ip_addr(node,"clients_start",c_pool.m_ip_start); - utl_yaml_read_ip_addr(node,"clients_end",c_pool.m_ip_end); - utl_yaml_read_ip_addr(node,"servers_start",s_pool.m_ip_start); - utl_yaml_read_ip_addr(node,"servers_end",s_pool.m_ip_end); - utl_yaml_read_uint32(node,"clients_per_gb",c_pool.m_number_of_clients_per_gb); - utl_yaml_read_uint32(node,"min_clients",c_pool.m_min_clients); - utl_yaml_read_ip_addr(node,"dual_port_mask",c_pool.m_dual_interface_mask); - utl_yaml_read_uint16(node,"tcp_aging",c_pool.m_tcp_aging_sec); - utl_yaml_read_uint16(node,"udp_aging",c_pool.m_udp_aging_sec); + UTL_YAML_READ(ip_addr, clients_start, c_pool.m_ip_start); + UTL_YAML_READ(ip_addr, clients_end, c_pool.m_ip_end); + UTL_YAML_READ(ip_addr, servers_start, s_pool.m_ip_start); + UTL_YAML_READ(ip_addr, servers_end, s_pool.m_ip_end); + UTL_YAML_READ(uint32, clients_per_gb, c_pool.m_number_of_clients_per_gb); + UTL_YAML_READ(uint32, min_clients, c_pool.m_min_clients); + UTL_YAML_READ(ip_addr, dual_port_mask, c_pool.m_dual_interface_mask); + UTL_YAML_READ(uint16, tcp_aging, c_pool.m_tcp_aging_sec); + UTL_YAML_READ(uint16, udp_aging, c_pool.m_udp_aging_sec); s_pool.m_dual_interface_mask = c_pool.m_dual_interface_mask; s_pool.m_is_bundling = false; fi.m_client_pool.push_back(c_pool); fi.m_server_pool.push_back(s_pool); - }catch ( const std::exception& e ) { + } else { printf("No default generator defined.\n"); } - try{ + + if (node.FindValue("generator_clients")) { const YAML::Node& c_pool_info = node["generator_clients"]; for (uint16_t idx=0;idx> (const YAML::Node& node, CTupleGenYamlInfo & fi) { printf("client pool in YAML is wrong\n"); } } - }catch ( const std::exception& e ) { + } else { printf("no client generator pool configured, using default pool\n"); } - try { + + if (node.FindValue("generator_servers")) { const YAML::Node& s_pool_info = node["generator_servers"]; for (uint16_t idx=0;idx> (const YAML::Node& node, CTupleGenYamlInfo & fi) { } fi.m_server_pool.push_back(pool); } - }catch ( const std::exception& e ) { + } else { printf("no server generator pool configured, using default pool\n"); } } -- cgit From b8e15f0ec903d0e8f7fd23d8e0e03b89b50b817b Mon Sep 17 00:00:00 2001 From: wenxian li Date: Tue, 20 Oct 2015 00:55:53 -0400 Subject: minor change --- src/tuple_gen.cpp | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp index 80a25f1a..3352c482 100755 --- a/src/tuple_gen.cpp +++ b/src/tuple_gen.cpp @@ -316,15 +316,11 @@ void operator >> (const YAML::Node& node, CTupleGenYamlInfo & fi) { const YAML::Node& c_pool_info = node["generator_clients"]; for (uint16_t idx=0;idx> pool; - if (fi.m_client_pool.size()>0) { - copy_global_pool_para(pool, fi.m_client_pool[0]); - } - fi.m_client_pool.push_back(pool); - } catch ( const std::exception& e ) { - printf("client pool in YAML is wrong\n"); + c_pool_info[idx] >> pool; + if (fi.m_client_pool.size()>0) { + copy_global_pool_para(pool, fi.m_client_pool[0]); } + fi.m_client_pool.push_back(pool); } } else { printf("no client generator pool configured, using default pool\n"); @@ -334,11 +330,7 @@ void operator >> (const YAML::Node& node, CTupleGenYamlInfo & fi) { const YAML::Node& s_pool_info = node["generator_servers"]; for (uint16_t idx=0;idx> pool; - } catch ( const std::exception& e ) { - printf("server pool in YAML is wrong\n"); - } + s_pool_info[idx] >> pool; if (fi.m_server_pool.size()>0) { copy_global_pool_para(pool, fi.m_server_pool[0]); } -- cgit From 7a7c328c767eeb9466138233fd53d51565f92b37 Mon Sep 17 00:00:00 2001 From: wenxian li Date: Tue, 20 Oct 2015 01:16:20 -0400 Subject: clean up the code --- src/tuple_gen.cpp | 52 +++++++++++++++++++++++----------------------------- 1 file changed, 23 insertions(+), 29 deletions(-) (limited to 'src') diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp index 3352c482..84a4b332 100755 --- a/src/tuple_gen.cpp +++ b/src/tuple_gen.cpp @@ -227,9 +227,27 @@ bool CTupleGenPoolYaml::is_valid(uint32_t num_threads,bool is_plugins){ utl_yaml_read_ ## type (node, #field , target); \ } else { printf("error in generator definition -- " #field "\n"); } +IP_DIST_t convert_distribution (const YAML::Node& node) { + std::string tmp; + node["distribution"] >> tmp ; + if (tmp == "random") { + return cdRANDOM_DIST; + }else if (tmp == "normal") { + return cdNORMAL_DIST; + } else { + return cdSEQ_DIST; + } +} + +void read_tuple_para(const YAML::Node& node, CTupleGenPoolYaml & fi) { + UTL_YAML_READ(uint32, clients_per_gb, fi.m_number_of_clients_per_gb); + UTL_YAML_READ(uint32, min_clients, fi.m_min_clients); + UTL_YAML_READ(ip_addr, dual_port_mask, fi.m_dual_interface_mask); + UTL_YAML_READ(uint16, tcp_aging, fi.m_tcp_aging_sec); + UTL_YAML_READ(uint16, udp_aging, fi.m_udp_aging_sec); +} void operator >> (const YAML::Node& node, CTupleGenPoolYaml & fi) { - std::string tmp; if (node.FindValue("name")) { node["name"] >> fi.m_name; } else { @@ -237,15 +255,8 @@ void operator >> (const YAML::Node& node, CTupleGenPoolYaml & fi) { assert(0); } if (node.FindValue("distribution")) { - node["distribution"] >> tmp ; + fi.m_dist = convert_distribution(node); } - if (tmp == "random") { - fi.m_dist=cdRANDOM_DIST; - }else if (tmp == "normal") { - fi.m_dist=cdNORMAL_DIST; - } else { - fi.m_dist=cdSEQ_DIST; - } UTL_YAML_READ(ip_addr, ip_start, fi.m_ip_start); UTL_YAML_READ(ip_addr, ip_end, fi.m_ip_end); @@ -255,12 +266,7 @@ void operator >> (const YAML::Node& node, CTupleGenPoolYaml & fi) { fi.m_tcp_aging_sec = 0; fi.m_udp_aging_sec = 0; fi.m_dual_interface_mask = 0; - - UTL_YAML_READ(uint32, clients_per_gb, fi.m_number_of_clients_per_gb); - UTL_YAML_READ(uint32, min_clients, fi.m_min_clients); - UTL_YAML_READ(ip_addr, dual_port_mask, fi.m_dual_interface_mask); - UTL_YAML_READ(uint16, tcp_aging, fi.m_tcp_aging_sec); - UTL_YAML_READ(uint16, udp_aging, fi.m_udp_aging_sec); + read_tuple_para(node, fi); if (node.FindValue("track_ports")) { node["track_ports"] >> fi.m_is_bundling; } @@ -280,30 +286,18 @@ void copy_global_pool_para(CTupleGenPoolYaml & src, CTupleGenPoolYaml & dst) { void operator >> (const YAML::Node& node, CTupleGenYamlInfo & fi) { - std::string tmp; CTupleGenPoolYaml c_pool; CTupleGenPoolYaml s_pool; if (node.FindValue("distribution")) { - node["distribution"] >> tmp ; - if (tmp == "random") { - c_pool.m_dist=cdRANDOM_DIST; - }else if (tmp == "normal") { - c_pool.m_dist=cdNORMAL_DIST; - } else { - c_pool.m_dist=cdSEQ_DIST; - } + c_pool.m_dist = convert_distribution(node); s_pool.m_dist = c_pool.m_dist; UTL_YAML_READ(ip_addr, clients_start, c_pool.m_ip_start); UTL_YAML_READ(ip_addr, clients_end, c_pool.m_ip_end); UTL_YAML_READ(ip_addr, servers_start, s_pool.m_ip_start); UTL_YAML_READ(ip_addr, servers_end, s_pool.m_ip_end); - UTL_YAML_READ(uint32, clients_per_gb, c_pool.m_number_of_clients_per_gb); - UTL_YAML_READ(uint32, min_clients, c_pool.m_min_clients); - UTL_YAML_READ(ip_addr, dual_port_mask, c_pool.m_dual_interface_mask); - UTL_YAML_READ(uint16, tcp_aging, c_pool.m_tcp_aging_sec); - UTL_YAML_READ(uint16, udp_aging, c_pool.m_udp_aging_sec); + read_tuple_para(node, c_pool); s_pool.m_dual_interface_mask = c_pool.m_dual_interface_mask; s_pool.m_is_bundling = false; fi.m_client_pool.push_back(c_pool); -- cgit From 74c3cc9a88beef73d6f319e39a5c51b1d074be18 Mon Sep 17 00:00:00 2001 From: wenxian li Date: Tue, 20 Oct 2015 01:22:29 -0400 Subject: minor --- src/tuple_gen.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/tuple_gen.cpp b/src/tuple_gen.cpp index 84a4b332..d3538ce6 100755 --- a/src/tuple_gen.cpp +++ b/src/tuple_gen.cpp @@ -225,7 +225,7 @@ bool CTupleGenPoolYaml::is_valid(uint32_t num_threads,bool is_plugins){ #define UTL_YAML_READ(type, field, target) if (node.FindValue(#field)) { \ utl_yaml_read_ ## type (node, #field , target); \ - } else { printf("error in generator definition -- " #field "\n"); } + } else { printf("generator definition mising " #field "\n"); } IP_DIST_t convert_distribution (const YAML::Node& node) { std::string tmp; -- cgit