diff options
Diffstat (limited to 'src/rpc-server')
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 48 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmd_api.h | 2 |
2 files changed, 13 insertions, 37 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index a5bf0d16..dea4c171 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -475,28 +475,17 @@ TrexRpcCmdStartTraffic::_run(const Json::Value ¶ms, Json::Value &result) { /* multiplier */ const Json::Value &mul_obj = parse_object(params, "mul", result); - std::string mul_type = parse_string(mul_obj, "type", result); - double mul_value = parse_double(mul_obj, "max", result); - /* now create an object for multiplier */ - TrexStatelessPort::mul_st mul; - - mul.value = mul_value; - - /* dispatch according to type of multiplier */ - if (mul_type == "raw") { - mul.type = TrexStatelessPort::MUL_FACTOR; - - } else if (mul_type == "max_bps") { - mul.type = TrexStatelessPort::MUL_MAX_BPS; + std::string type = parse_choice(mul_obj, "type", TrexPortMultiplier::g_types, result); + std::string op = parse_string(mul_obj, "op", result); + double value = parse_double(mul_obj, "value", result); - } else if (mul_type == "max_pps") { - mul.type = TrexStatelessPort::MUL_MAX_PPS; - - } else { - generate_parse_err(result, "multiplier type can be either 'raw', 'max_bps' or 'max_pps'"); + if (op != "abs") { + generate_parse_err(result, "start message can only specify absolute speed rate"); } + TrexPortMultiplier mul(type, op, value); + try { port->start_traffic(mul, duration); @@ -651,28 +640,15 @@ TrexRpcCmdUpdateTraffic::_run(const Json::Value ¶ms, Json::Value &result) { TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); /* multiplier */ - const Json::Value &mul_obj = parse_object(params, "mul", result); - std::string mul_type = parse_string(mul_obj, "type", result); - double mul_value = parse_double(mul_obj, "max", result); - - /* now create an object for multiplier */ - TrexStatelessPort::mul_st mul; - - mul.value = mul_value; - /* dispatch according to type of multiplier */ - if (mul_type == "raw") { - mul.type = TrexStatelessPort::MUL_FACTOR; + const Json::Value &mul_obj = parse_object(params, "mul", result); - } else if (mul_type == "max_bps") { - mul.type = TrexStatelessPort::MUL_MAX_BPS; + std::string type = parse_choice(mul_obj, "type", TrexPortMultiplier::g_types, result); + std::string op = parse_choice(mul_obj, "op", TrexPortMultiplier::g_ops, result); + double value = parse_double(mul_obj, "value", result); - } else if (mul_type == "max_pps") { - mul.type = TrexStatelessPort::MUL_MAX_PPS; + TrexPortMultiplier mul(type, op, value); - } else { - generate_parse_err(result, "multiplier type can be either 'raw', 'max_bps' or 'max_pps'"); - } try { port->update_traffic(mul); diff --git a/src/rpc-server/trex_rpc_cmd_api.h b/src/rpc-server/trex_rpc_cmd_api.h index 3c718eaa..e93fb775 100644 --- a/src/rpc-server/trex_rpc_cmd_api.h +++ b/src/rpc-server/trex_rpc_cmd_api.h @@ -159,7 +159,7 @@ protected: * parse a field from choices * */ - template<typename T> T parse_choice(const Json::Value ¶ms, const std::string &name, std::initializer_list<T> choices, Json::Value &result) { + template<typename T> T parse_choice(const Json::Value ¶ms, const std::string &name, const std::initializer_list<T> choices, Json::Value &result) { const Json::Value &field = params[name]; if (field == Json::Value::null) { |