diff options
author | imarom <imarom@cisco.com> | 2016-09-21 18:12:46 +0300 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-09-25 15:08:06 +0300 |
commit | 2cf444195c3d8a0215216e5f1899fded15bd7627 (patch) | |
tree | 10f17d20f2bcc98a1635f767a7acca97a6e0eadb /src/rpc-server/commands | |
parent | 0b520a31268bea0492795a56c4a65d93cdb21676 (diff) |
Splitter - padding for non circular VMs
Diffstat (limited to 'src/rpc-server/commands')
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 45 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmds.h | 1 |
2 files changed, 46 insertions, 0 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index e5072b9e..becd51c5 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -252,6 +252,51 @@ TrexRpcCmdAddStream::parse_vm_instr_tuple_flow_var(const Json::Value &inst, std: } +/** + * if a user specify min_value and max_value with a step + * that does not create a full cycle - pad the values to allow + * a true cycle + * + */ +void +TrexRpcCmdAddStream::handle_range_padding(uint64_t &max_value, + uint64_t &min_value, + uint64_t step, + int op, + Json::Value &result) { + + /* pad for the step */ + uint64_t pad = (max_value - min_value + 1) % step; + if (pad == 0) { + return; + } + + /* the leftover rounded up */ + uint64_t step_pad = step - pad; + + switch (op) { + case StreamVmInstructionFlowMan::FLOW_VAR_OP_INC: + + if ( (UINT64_MAX - max_value) < step_pad ) { + generate_parse_err(result, "VM: could not pad range to be a true cycle - '(max_value - min_value + 1) % step' should be zero"); + } + max_value += step_pad; + + break; + + case StreamVmInstructionFlowMan::FLOW_VAR_OP_DEC: + if ( min_value < step_pad ) { + generate_parse_err(result, "VM: could not pad range to be a true cycle - '(max_value - min_value + 1) % step' should be zero"); + } + min_value -= step_pad; + + break; + + default: + break; + } +} + void TrexRpcCmdAddStream::check_min_max(uint8_t flow_var_size, uint64_t init_value, diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h index c987f325..506bd2c9 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -114,6 +114,7 @@ void parse_vm_instr_trim_pkt_size(const Json::Value &inst, std::unique_ptr<TrexS void parse_rate(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result); void parse_vm_instr_write_flow_var(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result); void parse_vm_instr_write_mask_flow_var(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result); +void handle_range_padding(uint64_t &max_value, uint64_t &min_value, uint64_t step, int op, Json::Value &result); ); |