diff options
author | 2016-09-25 18:45:04 +0300 | |
---|---|---|
committer | 2016-09-25 18:45:04 +0300 | |
commit | f6d11f9e01e39fe2688558c7598f22ce9feb35da (patch) | |
tree | 672f5e4c5010484569edbbe8b29c4c03b2cd7ef4 /src | |
parent | d94e6a00edc22a1dd4946b3603aebb29319ce5ce (diff) |
merge issues with rand limit
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 12 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream_vm.cpp | 60 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream_vm.h | 60 |
3 files changed, 61 insertions, 71 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index 3afa2457..bf48931a 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -312,6 +312,10 @@ TrexRpcCmdAddStream::check_min_max(uint8_t flow_var_size, uint64_t max_value, Json::Value &result){ + if (step == 0) { + generate_parse_err(result, "VM: step cannot be 0"); + } + if (max_value < min_value ) { std::stringstream ss; ss << "VM: request flow var variable '" << max_value << "' is smaller than " << min_value; @@ -341,6 +345,7 @@ TrexRpcCmdAddStream::check_min_max(uint8_t flow_var_size, generate_parse_err(result, ss.str()); } } + } void @@ -360,11 +365,11 @@ TrexRpcCmdAddStream::parse_vm_instr_flow_var_rand_limit(const Json::Value &inst, generate_parse_err(result, ss.str()); } - check_min_max(flow_var_size, 0, 0, min_value, max_value, result); + check_min_max(flow_var_size, 0, 1, min_value, max_value, result); stream->m_vm.add_instruction(new StreamVmInstructionFlowRandLimit(flow_var_name, flow_var_size, - (int)limit, + limit, min_value, max_value, seed) @@ -400,6 +405,9 @@ TrexRpcCmdAddStream::parse_vm_instr_flow_var(const Json::Value &inst, std::uniqu check_min_max(flow_var_size, init_value, step, min_value, max_value, result); + /* implicit range padding if possible */ + handle_range_padding(max_value,min_value,step, op_type, result); + stream->m_vm.add_instruction(new StreamVmInstructionFlowMan(flow_var_name, flow_var_size, op_type, diff --git a/src/stateless/cp/trex_stream_vm.cpp b/src/stateless/cp/trex_stream_vm.cpp index 106b5ea3..c157ab06 100644 --- a/src/stateless/cp/trex_stream_vm.cpp +++ b/src/stateless/cp/trex_stream_vm.cpp @@ -133,30 +133,27 @@ void StreamVmInstructionFlowMan::sanity_check_valid_range(uint32_t ins_id,Stream -uint8_t StreamVmInstructionFlowMan::bss_init_value(uint8_t *p){ - uint8_t res; +uint8_t StreamVmInstructionFlowMan::set_bss_init_value(uint8_t *p) { + + uint64_t prev = peek_prev(); switch (m_size_bytes) { case 1: - *p=(uint8_t)get_bss_init_value(); - res=1; - break; + *p=(uint8_t)prev; + return 1; case 2: - *((uint16_t*)p)=(uint16_t)get_bss_init_value(); - res=2; - break; + *((uint16_t*)p)=(uint16_t)prev; + return 2; case 4: - *((uint32_t*)p)=(uint32_t)get_bss_init_value(); - res=4; - break; + *((uint32_t*)p)=(uint32_t)prev; + return 4; case 8: - *((uint64_t*)p)=(uint64_t)get_bss_init_value(); - res=8; - break; + *((uint64_t*)p)=(uint64_t)prev; + return 8; default: assert(0); + return(0); } - return(res); } @@ -179,7 +176,7 @@ void StreamVmInstructionFlowRandLimit::sanity_check(uint32_t ins_id,StreamVm *lp } -uint8_t StreamVmInstructionFlowRandLimit::bss_init_value(uint8_t *p){ +uint8_t StreamVmInstructionFlowRandLimit::set_bss_init_value(uint8_t *p){ uint8_t res; typedef union ua_ { @@ -305,26 +302,25 @@ void StreamVmInstructionFlowClient::Dump(FILE *fd){ } -uint8_t StreamVmInstructionFlowClient::bss_init_value(uint8_t *p){ +uint8_t StreamVmInstructionFlowClient::set_bss_init_value(uint8_t *p) { - if (m_client_min>0) { - *((uint32_t*)p)=(uint32_t)(m_client_min-1); - }else{ - *((uint32_t*)p)=(uint32_t)m_client_min; - } + uint32_t bss_ip; + uint16_t bss_port; - p+=4; + /* fetch the previous values by 1 */ + peek_prev(bss_ip, bss_port, 1); - if (is_unlimited_flows() ) { - *((uint16_t*)p)=StreamDPOpClientsUnLimit::CLIENT_UNLIMITED_MIN_PORT; - }else{ - *((uint16_t*)p)=(uint16_t)m_port_min; - } + /* ip */ + *((uint32_t*)p) = bss_ip; + p += 4; - p+=2; + /* port */ + *((uint16_t*)p) = bss_port; + p += 2; - *((uint32_t*)p)=0; - p+=4; + /* reserve */ + *((uint32_t*)p) = 0; + p += 4; return (get_flow_var_size()); } @@ -1057,7 +1053,7 @@ void StreamVm::build_bss() { } for (auto inst : m_inst_list) { - p+=inst->bss_init_value(p); + p+=inst->set_bss_init_value(p); } } diff --git a/src/stateless/cp/trex_stream_vm.h b/src/stateless/cp/trex_stream_vm.h index 92fefbb3..be0c03ba 100644 --- a/src/stateless/cp/trex_stream_vm.h +++ b/src/stateless/cp/trex_stream_vm.h @@ -912,11 +912,11 @@ public: bool is_var_instruction() const { instruction_type_t type = get_instruction_type(); - return ( (type == itFLOW_MAN) || (type == itFLOW_CLIENT) ); + return ( (type == itFLOW_MAN) || (type == itFLOW_CLIENT) || (type == itFLOW_RAND_LIMIT) ); } /* nothing to init */ - virtual uint8_t bss_init_value(uint8_t *p){ + virtual uint8_t set_bss_init_value(uint8_t *p) { return (0); } @@ -941,11 +941,6 @@ public: return m_var_name; } - /** - * what is the split range for this var - * - */ - //virtual uint64_t get_range() const = 0; /** * allows a var instruction to be updated @@ -1010,7 +1005,7 @@ public: } - virtual uint8_t bss_init_value(uint8_t *p); + virtual uint8_t set_bss_init_value(uint8_t *p); /** @@ -1022,17 +1017,6 @@ public: FLOW_VAR_OP_RANDOM }; - - /** - * for BSS we take one previous value - * because the VM will be executed before writing to pkt - * so the init value is one step's advanced - * - */ - uint64_t get_bss_init_value() const { - return peek_prev(); - } - StreamVmInstructionFlowMan(const std::string &var_name, uint8_t size, flow_var_op_e op, @@ -1121,7 +1105,7 @@ private: public: /* flow var size */ - uint8_t m_size_bytes; + uint8_t m_size_bytes; /* type of op */ flow_var_op_e m_op; @@ -1148,22 +1132,16 @@ public: return ( StreamVmInstruction::itFLOW_RAND_LIMIT); } - virtual bool is_valid_for_split() const { - return (false); - } - - - virtual uint64_t get_splitable_range() const { - return (1); + virtual bool need_split() const { + return true; } - StreamVmInstructionFlowRandLimit(const std::string &var_name, uint8_t size, uint64_t limit, uint64_t min_value, uint64_t max_value, - int seed + uint64_t seed ) : StreamVmInstructionVar(var_name) { m_size_bytes = size; @@ -1177,7 +1155,7 @@ public: void sanity_check(uint32_t ins_id,StreamVm *lp); - virtual uint8_t bss_init_value(uint8_t *p); + virtual uint8_t set_bss_init_value(uint8_t *p); virtual StreamVmInstruction * clone() { return new StreamVmInstructionFlowRandLimit(m_var_name, @@ -1188,6 +1166,19 @@ public: m_seed); } + virtual void update(uint64_t phase, uint64_t step_mul) { + + /* phase */ + 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; + } + private: void sanity_check_valid_size(uint32_t ins_id,StreamVm *lp); @@ -1197,7 +1188,7 @@ public: uint64_t m_min_value; uint64_t m_max_value; - int m_seed; + uint64_t m_seed; uint8_t m_size_bytes; }; @@ -1332,7 +1323,7 @@ public: } - virtual uint8_t bss_init_value(uint8_t *p); + virtual uint8_t set_bss_init_value(uint8_t *p); bool is_unlimited_flows(){ @@ -1340,11 +1331,6 @@ public: StreamVmInstructionFlowClient::CLIENT_F_UNLIMITED_FLOWS ); } - void get_bss_init_value(uint32_t &ip, uint16_t &port) { - /* fetch the previous values by 1 */ - peek_prev(ip, port, 1); - } - virtual StreamVmInstruction * clone() { return new StreamVmInstructionFlowClient(*this); } |