From 72ca9e76d4c6a5fe48e8cd7e1e49b9e54e40fca9 Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 6 Jan 2016 11:14:08 -0500 Subject: more options to the stateless simulation --- src/bp_sim.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/bp_sim.cpp') 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); -- cgit 1.2.3-korg From 2dff2ccf6fd6e4dae2556c1cf392473989a826b9 Mon Sep 17 00:00:00 2001 From: imarom Date: Thu, 7 Jan 2016 04:38:38 -0500 Subject: yet another stateless simulation phase --- .../client/trex_stateless_sim.py | 8 +- src/bp_sim.cpp | 2 + src/sim/trex_sim.h | 6 +- src/sim/trex_sim_stateless.cpp | 89 +++++++++++++++++----- src/stateless/cp/trex_stateless_port.cpp | 10 +++ src/stateless/cp/trex_stateless_port.h | 11 +++ 6 files changed, 107 insertions(+), 19 deletions(-) (limited to 'src/bp_sim.cpp') diff --git a/scripts/automation/trex_control_plane/client/trex_stateless_sim.py b/scripts/automation/trex_control_plane/client/trex_stateless_sim.py index 4382e9fb..b621be20 100644 --- a/scripts/automation/trex_control_plane/client/trex_stateless_sim.py +++ b/scripts/automation/trex_control_plane/client/trex_stateless_sim.py @@ -165,7 +165,11 @@ class SimRun(object): cmd = ['gdb', '--args'] + cmd print "executing command: '{0}'".format(" ".join(cmd)) - subprocess.call(cmd) + try: + subprocess.call(cmd) + except KeyboardInterrupt as e: + print "\n\n*** Caught Ctrl + C... Exiting...\n\n" + exit(-1) self.merge_results() @@ -181,11 +185,13 @@ class SimRun(object): return + print "Mering cores output to a single pcap file...\n" inputs = ["{0}-{1}".format(self.options.output_file, index) for index in xrange(0, self.options.cores)] merge_cap_files(inputs, self.options.output_file, delete_src = True) + def is_valid_file(filename): if not os.path.isfile(filename): raise argparse.ArgumentTypeError("The file '%s' does not exist" % filename) diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index 5ee06190..040c0858 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -3180,10 +3180,12 @@ int CNodeGenerator::close_file(CFlowGenListPerThread * thread){ int CNodeGenerator::update_stl_stats(CGenNodeStateless *node_sl){ m_cnt++; + #ifdef _DEBUG if ( m_preview_mode.getVMode() >2 ){ fprintf(stdout," %4lu ,", (ulong)m_cnt); node_sl->Dump(stdout); } + #endif return (0); } diff --git a/src/sim/trex_sim.h b/src/sim/trex_sim.h index a0f44cdb..f11f01c4 100644 --- a/src/sim/trex_sim.h +++ b/src/sim/trex_sim.h @@ -129,7 +129,11 @@ private: void execute_json(const std::string &json_filename); void run_dp(const std::string &out_filename); - uint64_t run_dp_core(int core_index, const std::string &out_filename); + + void run_dp_core(int core_index, + const std::string &out_filename, + uint64_t &simulated_pkts, + uint64_t &written_pkts); void flush_dp_to_cp_messages_core(int core_index); diff --git a/src/sim/trex_sim_stateless.cpp b/src/sim/trex_sim_stateless.cpp index a5d2213e..215315e0 100644 --- a/src/sim/trex_sim_stateless.cpp +++ b/src/sim/trex_sim_stateless.cpp @@ -26,9 +26,34 @@ limitations under the License. #include #include #include +#include using namespace std; +/****** utils ******/ +static string format_num(double num, const string &suffix = "") { + const char x[] = {' ','K','M','G','T','P'}; + + double my_num = num; + + for (int i = 0; i < sizeof(x); i++) { + if (std::abs(my_num) < 1000.0) { + stringstream ss; + + char buf[100]; + snprintf(buf, sizeof(buf), "%.2f", my_num); + + ss << buf << " " << x[i] << suffix; + return ss.str(); + + } else { + my_num /= 1000.0; + } + } + + return "NaN"; +} + TrexStateless * get_stateless_obj() { return SimStateless::get_instance().get_stateless_obj(); } @@ -57,8 +82,12 @@ public: virtual void get_global_stats(TrexPlatformGlobalStats &stats) const { } + virtual void get_interface_info(uint8_t interface_id, std::string &driver_name, driver_speed_e &speed) const { + driver_name = "TEST"; + speed = TrexPlatformApi::SPEED_10G; } + virtual void get_interface_stats(uint8_t interface_id, TrexPlatformInterfaceStats &stats) const { } @@ -284,7 +313,12 @@ static inline bool is_debug() { void SimStateless::show_intro(const std::string &out_filename) { - std::cout << "\nGeneral info:\n\n"; + uint64_t bps = 0; + uint64_t pps = 0; + + std::cout << "\nGeneral info:\n"; + std::cout << "------------\n\n"; + std::cout << "image type: " << (is_debug() ? "debug" : "release") << "\n"; std::cout << "I/O output: " << (m_is_dry_run ? "*DRY*" : out_filename) << "\n"; @@ -300,22 +334,32 @@ SimStateless::show_intro(const std::string &out_filename) { std::cout << "core recording: merge all\n"; } - std::cout << "\nConfiguration info:\n\n"; + std::cout << "\nConfiguration info:\n"; + std::cout << "-------------------\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 << "\nPort Config:\n"; + std::cout << "------------\n\n"; - std::cout << "\nStarting simulation...\n"; + TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(0); + + std::cout << "stream count: " << port->get_stream_count() << "\n"; + + port->get_port_effective_rate(bps, pps); + + std::cout << "max BPS: " << format_num(bps, "bps") << "\n"; + std::cout << "max PPS: " << format_num(pps, "pps") << "\n"; + + std::cout << "\n\nStarting simulation...\n"; } void SimStateless::run_dp(const std::string &out_filename) { - uint64_t pkt_cnt = 0; + uint64_t simulated_pkts_cnt = 0; + uint64_t written_pkts_cnt = 0; show_intro(out_filename); @@ -323,17 +367,26 @@ SimStateless::run_dp(const std::string &out_filename) { 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()); + run_dp_core(i, ss.str(), simulated_pkts_cnt, written_pkts_cnt); } } else { for (int i = 0; i < m_dp_core_count; i++) { - pkt_cnt += run_dp_core(i, out_filename); + run_dp_core(i, out_filename, simulated_pkts_cnt, written_pkts_cnt); } } - - std::cout << "\nwritten " << pkt_cnt << " packets " << "to '" << out_filename << "'\n\n"; + std::cout << "\n\nSimulation summary:\n"; + std::cout << "-------------------\n\n"; + std::cout << "simulated " << simulated_pkts_cnt << " packets\n"; + + if (m_is_dry_run) { + std::cout << "*DRY RUN* - no packets were written\n"; + } else { + std::cout << "written " << written_pkts_cnt << " packets " << "to '" << out_filename << "'\n\n"; + } + + std::cout << "\n"; } @@ -351,8 +404,11 @@ SimStateless::get_limit_per_core(int core_index) { } } -uint64_t -SimStateless::run_dp_core(int core_index, const std::string &out_filename) { +void +SimStateless::run_dp_core(int core_index, + const std::string &out_filename, + uint64_t &simulated_pkts, + uint64_t &written_pkts) { CFlowGenListPerThread *lpt = m_fl.m_threads_info[core_index]; @@ -361,12 +417,11 @@ SimStateless::run_dp_core(int core_index, const std::string &out_filename) { flush_dp_to_cp_messages_core(core_index); + simulated_pkts += lpt->m_node_gen.m_cnt; + if (should_capture_core(core_index)) { - return lpt->m_node_gen.m_cnt; - } else { - return (0); + written_pkts += lpt->m_node_gen.m_cnt; } - } diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp index aa34e87b..0055b5ef 100644 --- a/src/stateless/cp/trex_stateless_port.cpp +++ b/src/stateless/cp/trex_stateless_port.cpp @@ -589,6 +589,16 @@ TrexStatelessPort::validate(void) { } + +void +TrexStatelessPort::get_port_effective_rate(uint64_t &bps, uint64_t &pps) { + if (!m_graph_obj) { + return; + } + bps = m_graph_obj->get_max_bps() * m_factor; + pps = m_graph_obj->get_max_pps() * m_factor; +} + /************* Trex Port Owner **************/ TrexPortOwner::TrexPortOwner() { diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h index 784bf4c0..d0e75744 100644 --- a/src/stateless/cp/trex_stateless_port.h +++ b/src/stateless/cp/trex_stateless_port.h @@ -302,6 +302,17 @@ public: return m_owner; } + + /** + * get the port effective rate (on a started / paused port) + * + * @author imarom (07-Jan-16) + * + * @param bps + * @param pps + */ + void get_port_effective_rate(uint64_t &bps, uint64_t &pps); + private: -- cgit 1.2.3-korg From c068b9e06666534ac3a426cfe2eb8c3c844eaa95 Mon Sep 17 00:00:00 2001 From: imarom Date: Thu, 7 Jan 2016 09:13:12 -0500 Subject: stateless sim dry was "too much" dry - no only I/O is skipped --- src/bp_sim.cpp | 18 ++++++------------ src/bp_sim.h | 37 ++++++++++++++++++++++++++++++++++++- src/sim/trex_sim.h | 2 +- 3 files changed, 43 insertions(+), 14 deletions(-) (limited to 'src/bp_sim.cpp') diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index 040c0858..31ce0440 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -4705,13 +4705,11 @@ int CErfIFStl::send_node(CGenNode * _no_to_use){ rte_pktmbuf_free(m); } - - BP_ASSERT(m_writer); - bool res=m_writer->write_packet(m_raw); - - - BP_ASSERT(res); + + int rc = write_pkt(m_raw); + BP_ASSERT(rc == 0); } + return (0); } @@ -4749,13 +4747,9 @@ int CErfIF::send_node(CGenNode * node){ //utl_DumpBuffer(stdout,p, 12,0); - BP_ASSERT(m_writer); - - bool res=m_writer->write_packet(m_raw); - - //utl_DumpBuffer(stdout,m_raw->raw,m_raw->pkt_len,0); + int rc = write_pkt(m_raw); + BP_ASSERT(rc == 0); - BP_ASSERT(res); rte_pktmbuf_free(m); } return (0); diff --git a/src/bp_sim.h b/src/bp_sim.h index 4b906912..c8775a61 100755 --- a/src/bp_sim.h +++ b/src/bp_sim.h @@ -1835,7 +1835,7 @@ public: protected: - void fill_raw_packet(rte_mbuf_t * m,CGenNode * node,pkt_dir_t dir); + virtual void fill_raw_packet(rte_mbuf_t * m,CGenNode * node,pkt_dir_t dir); CFileWriterBase * m_writer; CCapPktRaw * m_raw; @@ -1849,6 +1849,41 @@ public: virtual int send_node(CGenNode * node); }; +/** + * same as regular STL but no I/O (dry run) + * + * @author imarom (07-Jan-16) + */ +class CErfIFStlNull : public CErfIFStl { +public: + + virtual int open_file(std::string file_name) { + return (0); + } + + virtual int write_pkt(CCapPktRaw *pkt_raw) { + return (0); + } + + virtual int close_file(void) { + return (0); + } + + virtual void fill_raw_packet(rte_mbuf_t * m,CGenNode * node,pkt_dir_t dir) { + + } + + virtual int update_mac_addr_from_global_cfg(pkt_dir_t dir, uint8_t * p){ + return (0); + } + + + virtual int flush_tx_queue(void){ + return (0); + + } + +}; static inline int fill_pkt(CCapPktRaw * raw,rte_mbuf_t * m){ diff --git a/src/sim/trex_sim.h b/src/sim/trex_sim.h index f11f01c4..8feb7bc0 100644 --- a/src/sim/trex_sim.h +++ b/src/sim/trex_sim.h @@ -154,7 +154,7 @@ private: TrexPublisher *m_publisher; CFlowGenList m_fl; CErfIFStl m_erf_vif; - CNullIF m_null_erf_vif; + CErfIFStlNull m_null_erf_vif; bool m_verbose; int m_port_count; -- cgit 1.2.3-korg