diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/bp_sim.cpp | 5 | ||||
-rwxr-xr-x | src/main.cpp | 21 | ||||
-rw-r--r-- | src/sim/trex_sim.h | 17 | ||||
-rw-r--r-- | src/sim/trex_sim_stateless.cpp | 137 | ||||
-rw-r--r-- | src/stateless/cp/trex_stateless_port.h | 4 |
5 files changed, 140 insertions, 44 deletions
diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index fcef049c..5ee06190 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -3537,9 +3537,6 @@ int CNodeGenerator::flush_file(dsec_t max_time, } } - //#ifndef RTE_DPDK - //thread->check_msgs(); - //#endif uint8_t type=node->m_type; @@ -3553,7 +3550,7 @@ int CNodeGenerator::flush_file(dsec_t max_time, } else { node_sl->handle(thread); - #ifdef _DEBUG + #ifdef TREX_SIM update_stl_stats(node_sl); if (has_limit_reached()) { thread->m_stateless_dp_info.stop_traffic(node_sl->get_port_id(), false, 0); diff --git a/src/main.cpp b/src/main.cpp index ea8e1e44..a2d06067 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -36,7 +36,8 @@ using namespace std; // An enum for all the option types enum { OPT_HELP, OPT_CFG, OPT_NODE_DUMP, OP_STATS, OPT_FILE_OUT, OPT_UT, OPT_PCAP, OPT_IPV6, OPT_MAC_FILE, - OPT_SL, OPT_DP_CORE_COUNT, OPT_DP_CORE_INDEX, OPT_LIMIT}; + OPT_SL, OPT_DP_CORE_COUNT, OPT_DP_CORE_INDEX, OPT_LIMIT, + OPT_DRY_RUN}; @@ -75,16 +76,12 @@ static CSimpleOpt::SOption parser_options[] = { OPT_DP_CORE_COUNT, "--cores", SO_REQ_SEP }, { OPT_DP_CORE_INDEX, "--core_index", SO_REQ_SEP }, { OPT_LIMIT, "--limit", SO_REQ_SEP }, + { OPT_DRY_RUN, "--dry", SO_NONE }, SO_END_OF_OPTIONS }; - -static bool in_range(int x, int low, int high) { - return ( (x >= low) && (x <= high) ); -} - static int usage(){ printf(" Usage: bp_sim [OPTION] -f cfg.yaml -o outfile.erf \n"); @@ -189,6 +186,10 @@ static int parse_options(int argc, params["limit"] = atoi(args.OptionArg()); break; + case OPT_DRY_RUN: + params["dry"] = 1; + break; + default: usage(); return -1; @@ -277,12 +278,18 @@ int main(int argc , char * argv[]){ params["limit"] = 5000; } + if (params.count("dry") == 0) { + params["dry"] = 0; + } + return st.run(CGlobalInfo::m_options.cfg_file, CGlobalInfo::m_options.out_file, 2, params["dp_core_count"], params["dp_core_index"], - params["limit"]); + params["limit"], + (params["dry"] == 1) + ); } } } diff --git a/src/sim/trex_sim.h b/src/sim/trex_sim.h index a541ce01..a0f44cdb 100644 --- a/src/sim/trex_sim.h +++ b/src/sim/trex_sim.h @@ -32,6 +32,12 @@ class TrexStateless; class TrexPublisher; class DpToCpHandler; + +static inline bool +in_range(int x, int low, int high) { + return ( (x >= low) && (x <= high) ); +} + /** * interface for a sim target * @@ -103,7 +109,8 @@ public: int port_count, int dp_core_count, int dp_core_index, - int limit); + int limit, + bool is_dry_run); TrexStateless * get_stateless_obj() { return m_trex_stateless; @@ -128,6 +135,12 @@ private: void validate_response(const Json::Value &resp); + bool should_capture_core(int i); + bool is_multiple_capture(); + uint64_t get_limit_per_core(int core_index); + + void show_intro(const std::string &out_filename); + bool is_verbose() { return m_verbose; } @@ -137,12 +150,14 @@ private: TrexPublisher *m_publisher; CFlowGenList m_fl; CErfIFStl m_erf_vif; + CNullIF m_null_erf_vif; bool m_verbose; int m_port_count; int m_dp_core_count; int m_dp_core_index; uint64_t m_limit; + bool m_is_dry_run; }; #endif /* __TREX_SIM_H__ */ diff --git a/src/sim/trex_sim_stateless.cpp b/src/sim/trex_sim_stateless.cpp index 2b73f686..a5d2213e 100644 --- a/src/sim/trex_sim_stateless.cpp +++ b/src/sim/trex_sim_stateless.cpp @@ -121,6 +121,7 @@ SimStateless::SimStateless() { m_dp_core_index = -1; m_port_count = -1; m_limit = 0; + m_is_dry_run = false; /* override ownership checks */ TrexRpcCommand::test_set_override_ownership(true); @@ -133,17 +134,19 @@ SimStateless::run(const string &json_filename, int port_count, int dp_core_count, int dp_core_index, - int limit) { + int limit, + bool is_dry_run) { assert(dp_core_count > 0); /* -1 means its not set or positive value between 0 and the dp core count - 1*/ - assert( (dp_core_index == -1) || ( (dp_core_index >=0 ) && (dp_core_index < dp_core_count) ) ); + assert( (dp_core_index == -1) || ( in_range(dp_core_index, 0, dp_core_count - 1)) ); m_dp_core_count = dp_core_count; m_dp_core_index = dp_core_index; m_port_count = port_count; m_limit = limit; + m_is_dry_run = is_dry_run; prepare_dataplane(); prepare_control_plane(); @@ -220,7 +223,11 @@ SimStateless::prepare_dataplane() { m_fl.generate_p_thread_info(m_dp_core_count); for (int i = 0; i < m_dp_core_count; i++) { - m_fl.m_threads_info[i]->set_vif(&m_erf_vif); + if (should_capture_core(i)) { + m_fl.m_threads_info[i]->set_vif(&m_erf_vif); + } else { + m_fl.m_threads_info[i]->set_vif(&m_null_erf_vif); + } } } @@ -267,47 +274,81 @@ SimStateless::validate_response(const Json::Value &resp) { } +static inline bool is_debug() { + #ifdef DEBUG + return true; + #else + return false; + #endif +} + +void +SimStateless::show_intro(const std::string &out_filename) { + std::cout << "\nGeneral info:\n\n"; + std::cout << "image type: " << (is_debug() ? "debug" : "release") << "\n"; + std::cout << "I/O output: " << (m_is_dry_run ? "*DRY*" : out_filename) << "\n"; + + if (m_limit > 0) { + std::cout << "packet limit: " << m_limit << "\n"; + } else { + std::cout << "packet limit: " << "*NO LIMIT*" << "\n"; + } + + if (m_dp_core_index != -1) { + std::cout << "core recording: " << m_dp_core_index << "\n"; + } else { + std::cout << "core recording: merge all\n"; + } + + std::cout << "\nConfiguration info:\n\n"; + + std::cout << "ports: " << m_port_count << "\n"; + std::cout << "cores: " << m_dp_core_count << "\n"; + + + std::cout << "\nPort Config:\n\n"; + //TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(0); + //std::cout << "stream count:" << port->get_stream_by_id() + + std::cout << "\nStarting simulation...\n"; +} void SimStateless::run_dp(const std::string &out_filename) { uint64_t pkt_cnt = 0; - if (m_dp_core_count == 1) { - pkt_cnt = run_dp_core(0, out_filename); - } else { + show_intro(out_filename); - /* do we have a specific core index to capture ? */ - if (m_dp_core_index != -1) { - for (int i = 0; i < m_dp_core_count; i++) { - if (i == m_dp_core_index) { - pkt_cnt += run_dp_core(i, out_filename); - } else { - run_dp_core(i, "/dev/null"); - } - } - } else { - for (int i = 0; i < m_dp_core_count; i++) { - std::stringstream ss; - ss << out_filename << "-" << i; - pkt_cnt += run_dp_core(i, ss.str()); - } + if (is_multiple_capture()) { + for (int i = 0; i < m_dp_core_count; i++) { + std::stringstream ss; + ss << out_filename << "-" << i; + pkt_cnt += run_dp_core(i, ss.str()); } + } else { + for (int i = 0; i < m_dp_core_count; i++) { + pkt_cnt += run_dp_core(i, out_filename); + } } - std::cout << "\n"; - std::cout << "ports: " << m_port_count << "\n"; - std::cout << "cores: " << m_dp_core_count << "\n"; + std::cout << "\nwritten " << pkt_cnt << " packets " << "to '" << out_filename << "'\n\n"; +} - if (m_dp_core_index != -1) { - std::cout << "core index: " << m_dp_core_index << "\n"; + +uint64_t +SimStateless::get_limit_per_core(int core_index) { + /* global no limit ? */ + if (m_limit == 0) { + return (0); } else { - std::cout << "core index: merge all\n"; + uint64_t l = std::max((uint64_t)1, m_limit / m_dp_core_count); + if (core_index == 0) { + l += (m_limit % m_dp_core_count); + } + return l; } - - std::cout << "pkt limit: " << m_limit << "\n"; - std::cout << "\nwritten " << pkt_cnt << " packets " << "to '" << out_filename << "'\n\n"; } uint64_t @@ -315,12 +356,17 @@ SimStateless::run_dp_core(int core_index, const std::string &out_filename) { CFlowGenListPerThread *lpt = m_fl.m_threads_info[core_index]; - lpt->start_stateless_simulation_file((std::string)out_filename, CGlobalInfo::m_options.preview, m_limit / m_dp_core_count); + lpt->start_stateless_simulation_file((std::string)out_filename, CGlobalInfo::m_options.preview, get_limit_per_core(core_index)); lpt->start_stateless_daemon_simulation(); flush_dp_to_cp_messages_core(core_index); - return lpt->m_node_gen.m_cnt; + if (should_capture_core(core_index)) { + return lpt->m_node_gen.m_cnt; + } else { + return (0); + } + } @@ -344,3 +390,30 @@ SimStateless::flush_dp_to_cp_messages_core(int core_index) { delete msg; } } + +bool +SimStateless::should_capture_core(int i) { + + /* dry run - no core should be recordered */ + if (m_is_dry_run) { + return false; + } + + /* no specific core index ? record all */ + if (m_dp_core_index == -1) { + return true; + } else { + return (i == m_dp_core_index); + } +} + +bool +SimStateless::is_multiple_capture() { + /* dry run - no core should be recordered */ + if (m_is_dry_run) { + return false; + } + + return ( (m_dp_core_count > 1) && (m_dp_core_index == -1) ); +} + diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index a529d38f..784bf4c0 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -259,6 +259,10 @@ public: return m_stream_table.get_stream_by_id(stream_id); } + int get_stream_count() { + return m_stream_table.size(); + } + void get_id_list(std::vector<uint32_t> &id_list) { m_stream_table.get_id_list(id_list); } |