refactor limit split
authorHanoh Haim <[email protected]>
Fri, 30 Sep 2016 09:27:25 +0000 (12:27 +0300)
committerHanoh Haim <[email protected]>
Fri, 30 Sep 2016 09:27:25 +0000 (12:27 +0300)
src/rpc-server/commands/trex_rpc_cmd_stream.cpp
src/stateless/cp/trex_stream_vm.h

index 9bb2d55..c950e01 100644 (file)
@@ -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());
        }
 
index f3c3501..8d993ff 100644 (file)
@@ -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);
         }
         
     }