diff options
author | imarom <imarom@cisco.com> | 2016-02-21 08:34:28 -0500 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2016-02-23 03:08:00 -0500 |
commit | bc7f0b85b85a8deb6bc58bcca32ff11d9289cd92 (patch) | |
tree | c6a12c9f126f6b74acb6ce740e134dd00e746679 /src/rpc-server/commands/trex_rpc_cmd_stream.cpp | |
parent | a88db6885843221757f3cfb4bb3b2e74f57395bb (diff) |
rate per stream
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, 29 insertions, 16 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index 920991e2..bcfa7df1 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -60,6 +60,10 @@ TrexRpcCmdAddStream::_run(const Json::Value ¶ms, Json::Value &result) { stream->m_flags = parse_int(section, "flags", result); stream->m_action_count = parse_uint16(section, "action_count", result); + /* parse the rate of the stream */ + const Json::Value &rate = parse_object(section ,"rate", result); + parse_rate(rate, stream.get(), result); + /* inter stream gap */ stream->m_isg_usec = parse_double(section, "isg", result); @@ -138,35 +142,26 @@ TrexRpcCmdAddStream::allocate_new_stream(const Json::Value §ion, uint8_t por const Json::Value &mode = parse_object(section, "mode", result); std::string type = parse_string(mode, "type", result); + if (type == "continuous") { - double pps = parse_double(mode, "pps", result); stream = new TrexStream( TrexStream::stCONTINUOUS, port_id, stream_id); - stream->set_pps(pps); - - if (stream->m_next_stream_id != -1) { - generate_parse_err(result, "continious stream cannot provide next stream id - only -1 is valid"); - } } else if (type == "single_burst") { uint32_t total_pkts = parse_int(mode, "total_pkts", result); - double pps = parse_double(mode, "pps", result); - stream = new TrexStream(TrexStream::stSINGLE_BURST,port_id, stream_id); - stream->set_pps(pps); + stream = new TrexStream(TrexStream::stSINGLE_BURST, port_id, stream_id); stream->set_single_burst(total_pkts); } else if (type == "multi_burst") { - double pps = parse_double(mode, "pps", result); double ibg_usec = parse_double(mode, "ibg", result); uint32_t num_bursts = parse_int(mode, "count", result); uint32_t pkts_per_burst = parse_int(mode, "pkts_per_burst", result); stream = new TrexStream(TrexStream::stMULTI_BURST,port_id, stream_id ); - stream->set_pps(pps); stream->set_multi_burst(pkts_per_burst,num_bursts,ibg_usec); @@ -174,16 +169,34 @@ TrexRpcCmdAddStream::allocate_new_stream(const Json::Value §ion, uint8_t por generate_parse_err(result, "bad stream type provided: '" + type + "'"); } - /* make sure we were able to allocate the memory */ - if (!stream) { - generate_internal_err(result, "unable to allocate memory"); - } - return (stream); } void +TrexRpcCmdAddStream::parse_rate(const Json::Value &rate, TrexStream *stream, Json::Value &result) { + + double value = parse_double(rate, "value", result); + + auto rate_types = {"pps", "bps_L1", "bps_L2", "percentage"}; + std::string rate_type = parse_choice(rate, "type", rate_types, result); + + if (rate_type == "pps") { + stream->set_rate(TrexStreamRate::RATE_PPS, value); + } else if (rate_type == "bps_L1") { + stream->set_rate(TrexStreamRate::RATE_BPS_L1, value); + } else if (rate_type == "bps_L2") { + stream->set_rate(TrexStreamRate::RATE_BPS_L2, value); + } else if (rate_type == "percentage") { + stream->set_rate(TrexStreamRate::RATE_PERCENTAGE, value); + } else { + /* impossible */ + assert(0); + } + +} + +void TrexRpcCmdAddStream::parse_vm_instr_checksum(const Json::Value &inst, TrexStream *stream, Json::Value &result) { uint16_t pkt_offset = parse_uint16(inst, "pkt_offset", result); |