summaryrefslogtreecommitdiffstats
path: root/src/sim
diff options
context:
space:
mode:
Diffstat (limited to 'src/sim')
-rw-r--r--src/sim/trex_sim.h17
-rw-r--r--src/sim/trex_sim_stateless.cpp137
2 files changed, 121 insertions, 33 deletions
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) );
+}
+