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/trex_rpc_cmd_stream.cpp | |
parent | 0b520a31268bea0492795a56c4a65d93cdb21676 (diff) |
Splitter - padding for non circular VMs
Diffstat (limited to 'src/rpc-server/commands/trex_rpc_cmd_stream.cpp')
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 45 |
1 files changed, 45 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, |