summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2016-09-30 12:27:25 +0300
committerHanoh Haim <hhaim@cisco.com>2016-09-30 12:27:25 +0300
commit2e02d8cb37b98794d2d280f0cdc817752f051e5f (patch)
tree010784ea3c1d7e7bdf2c2af963d81e8cc59fa0f8
parentecd18a7e43bf03f0984b033f73bc2a306910dcdc (diff)
refactor limit split
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_stream.cpp4
-rw-r--r--src/stateless/cp/trex_stream_vm.h36
2 files changed, 26 insertions, 14 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
index 9bb2d552..c950e011 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
@@ -369,9 +369,9 @@ TrexRpcCmdAddStream::parse_vm_instr_flow_var_rand_limit(const Json::Value &inst,
uint64_t max_value = parse_uint64(inst, "max_value", result);
/* archiecture limitation - limit_flows must be greater or equal to DP core count */
- if (limit < get_stateless_obj()->get_dp_core_count()) {
+ if (limit < 1) {
std::stringstream ss;
- ss << "VM limit random: cannot specify limit less than " << (uint32_t)get_stateless_obj()->get_dp_core_count();
+ ss << "VM: request random flow var variable with limit of zero '";
generate_parse_err(result, ss.str());
}
diff --git a/src/stateless/cp/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h
index f3c35013..8d993ffc 100644
--- a/src/stateless/cp/trex_stream_vm.h
+++ b/src/stateless/cp/trex_stream_vm.h
@@ -39,6 +39,28 @@ limitations under the License.
class StreamVmInstructionFlowClient;
+
+inline uint64_t utl_split_limit(uint64_t limit,
+ uint64_t phase,
+ uint64_t step_mul){
+
+ uint64_t per_core_limit = (limit / step_mul);
+
+ if (phase == 0) {
+ per_core_limit += (limit % step_mul);
+ }
+
+ if (per_core_limit == 0) {
+ per_core_limit=1;
+ }
+ return ( per_core_limit);
+}
+
+
+
+
+
+
/**
* two functions ahead are used by both control plane and
* dataplane to allow fast inc/dec and handle overflow
@@ -1298,11 +1320,7 @@ public:
m_seed = m_seed * ( ( (phase + 1) * 514229 ) & 0xFFFFFFFF );
/* limit */
- uint64_t per_core_limit = (m_limit / step_mul);
- if (phase == 0) {
- per_core_limit += (m_limit % step_mul);
- }
- m_limit = per_core_limit;
+ m_limit = utl_split_limit(m_limit, phase, step_mul);
}
private:
@@ -1475,13 +1493,7 @@ public:
/* update the limit per core */
if (m_limit_num_flows) {
- uint64_t per_core_limit = m_limit_num_flows / step_mul;
- if (phase == 0) {
- per_core_limit += m_limit_num_flows % step_mul;
- }
-
- m_limit_num_flows = per_core_limit;
- assert(per_core_limit > 0);
+ m_limit_num_flows = utl_split_limit(m_limit_num_flows, phase, step_mul);
}
}