diff options
author | Hanoh Haim <hhaim@cisco.com> | 2016-02-23 15:32:19 +0200 |
---|---|---|
committer | Hanoh Haim <hhaim@cisco.com> | 2016-02-23 15:32:19 +0200 |
commit | 36cc1ecef32dcee3640e6ddf96422c07d89777b3 (patch) | |
tree | 6a9eadb662ad0f98395886077fe32943512fd040 /src/rpc-server | |
parent | 68ebd739646a27f1bb92ce8eacb5bb76f6399580 (diff) | |
parent | 81059eb5df274efe48ad3914039ddb657c3285ab (diff) |
Merge ipv4 checksum issue
Diffstat (limited to 'src/rpc-server')
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 80 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmds.h | 21 |
2 files changed, 60 insertions, 41 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..50295c7c 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -49,7 +49,7 @@ TrexRpcCmdAddStream::_run(const Json::Value ¶ms, Json::Value &result) { string type = parse_string(mode, "type", result); /* allocate a new stream based on the type */ - std::unique_ptr<TrexStream> stream( allocate_new_stream(section, port_id, stream_id, result) ); + std::unique_ptr<TrexStream> stream = allocate_new_stream(section, port_id, stream_id, result); /* save this for future queries */ stream->store_stream_json(section); @@ -59,6 +59,7 @@ TrexRpcCmdAddStream::_run(const Json::Value ¶ms, Json::Value &result) { stream->m_self_start = parse_bool(section, "self_start", result); stream->m_flags = parse_int(section, "flags", result); stream->m_action_count = parse_uint16(section, "action_count", result); + /* inter stream gap */ stream->m_isg_usec = parse_double(section, "isg", result); @@ -97,7 +98,7 @@ TrexRpcCmdAddStream::_run(const Json::Value ¶ms, Json::Value &result) { /* parse VM */ const Json::Value &vm = parse_object(section ,"vm", result); - parse_vm(vm, stream.get(), result); + parse_vm(vm, stream, result); /* parse RX info */ const Json::Value &rx = parse_object(section, "rx_stats", result); @@ -112,7 +113,7 @@ TrexRpcCmdAddStream::_run(const Json::Value ¶ms, Json::Value &result) { } /* make sure this is a valid stream to add */ - validate_stream(stream.get(), result); + validate_stream(stream, result); TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(stream->m_port_id); @@ -130,43 +131,34 @@ TrexRpcCmdAddStream::_run(const Json::Value ¶ms, Json::Value &result) { -TrexStream * +std::unique_ptr<TrexStream> TrexRpcCmdAddStream::allocate_new_stream(const Json::Value §ion, uint8_t port_id, uint32_t stream_id, Json::Value &result) { - TrexStream *stream = NULL; + std::unique_ptr<TrexStream> stream; 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 (type == "continuous") { - if (stream->m_next_stream_id != -1) { - generate_parse_err(result, "continious stream cannot provide next stream id - only -1 is valid"); - } + stream.reset(new TrexStream( TrexStream::stCONTINUOUS, port_id, stream_id)); } 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.reset(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.reset(new TrexStream(TrexStream::stMULTI_BURST,port_id, stream_id )); stream->set_multi_burst(pkts_per_burst,num_bursts,ibg_usec); @@ -174,17 +166,44 @@ 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"); - } + /* parse the rate of the stream */ + const Json::Value &rate = parse_object(mode ,"rate", result); + parse_rate(rate, stream, result); return (stream); } void -TrexRpcCmdAddStream::parse_vm_instr_checksum(const Json::Value &inst, TrexStream *stream, Json::Value &result) { +TrexRpcCmdAddStream::parse_rate(const Json::Value &rate, std::unique_ptr<TrexStream> &stream, Json::Value &result) { + + double value = parse_double(rate, "value", result); + if (value <= 0) { + std::stringstream ss; + ss << "rate value must be a positive number - got: '" << value << "'"; + generate_parse_err(result, ss.str()); + } + + 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, std::unique_ptr<TrexStream> &stream, Json::Value &result) { uint16_t pkt_offset = parse_uint16(inst, "pkt_offset", result); stream->m_vm.add_instruction(new StreamVmInstructionFixChecksumIpv4(pkt_offset)); @@ -192,7 +211,7 @@ TrexRpcCmdAddStream::parse_vm_instr_checksum(const Json::Value &inst, TrexStream void -TrexRpcCmdAddStream::parse_vm_instr_trim_pkt_size(const Json::Value &inst, TrexStream *stream, Json::Value &result){ +TrexRpcCmdAddStream::parse_vm_instr_trim_pkt_size(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result){ std::string flow_var_name = parse_string(inst, "name", result); @@ -201,7 +220,7 @@ TrexRpcCmdAddStream::parse_vm_instr_trim_pkt_size(const Json::Value &inst, TrexS void -TrexRpcCmdAddStream::parse_vm_instr_tuple_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result){ +TrexRpcCmdAddStream::parse_vm_instr_tuple_flow_var(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result){ std::string flow_var_name = parse_string(inst, "name", result); @@ -225,7 +244,7 @@ TrexRpcCmdAddStream::parse_vm_instr_tuple_flow_var(const Json::Value &inst, Trex void -TrexRpcCmdAddStream::parse_vm_instr_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result) { +TrexRpcCmdAddStream::parse_vm_instr_flow_var(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result) { std::string flow_var_name = parse_string(inst, "name", result); auto sizes = {1, 2, 4, 8}; @@ -294,7 +313,7 @@ TrexRpcCmdAddStream::parse_vm_instr_flow_var(const Json::Value &inst, TrexStream void -TrexRpcCmdAddStream::parse_vm_instr_write_mask_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result) { +TrexRpcCmdAddStream::parse_vm_instr_write_mask_flow_var(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result) { std::string flow_var_name = parse_string(inst, "name", result); uint16_t pkt_offset = parse_uint16(inst, "pkt_offset", result); uint16_t pkt_cast_size = parse_uint16(inst, "pkt_cast_size", result); @@ -312,7 +331,7 @@ TrexRpcCmdAddStream::parse_vm_instr_write_mask_flow_var(const Json::Value &inst, void -TrexRpcCmdAddStream::parse_vm_instr_write_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result) { +TrexRpcCmdAddStream::parse_vm_instr_write_flow_var(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result) { std::string flow_var_name = parse_string(inst, "name", result); uint16_t pkt_offset = parse_uint16(inst, "pkt_offset", result); int add_value = parse_int(inst, "add_value", result); @@ -325,7 +344,7 @@ TrexRpcCmdAddStream::parse_vm_instr_write_flow_var(const Json::Value &inst, Trex } void -TrexRpcCmdAddStream::parse_vm(const Json::Value &vm, TrexStream *stream, Json::Value &result) { +TrexRpcCmdAddStream::parse_vm(const Json::Value &vm, std::unique_ptr<TrexStream> &stream, Json::Value &result) { const Json::Value &instructions = parse_array(vm ,"instructions", result); @@ -372,7 +391,7 @@ TrexRpcCmdAddStream::parse_vm(const Json::Value &vm, TrexStream *stream, Json::V } void -TrexRpcCmdAddStream::validate_stream(const TrexStream *stream, Json::Value &result) { +TrexRpcCmdAddStream::validate_stream(const std::unique_ptr<TrexStream> &stream, Json::Value &result) { /* add the stream to the port's stream table */ TrexStatelessPort * port = get_stateless_obj()->get_port_by_id(stream->m_port_id); @@ -381,7 +400,6 @@ TrexRpcCmdAddStream::validate_stream(const TrexStream *stream, Json::Value &resu if (port->get_stream_by_id(stream->m_stream_id)) { std::stringstream ss; ss << "stream " << stream->m_stream_id << " already exists"; - delete stream; generate_execute_err(result, ss.str()); } diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h index 3dc2ce0a..d90d880e 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -24,6 +24,7 @@ limitations under the License. #include <trex_rpc_cmd_api.h> #include <json/json.h> +#include <memory> class TrexStream; @@ -91,16 +92,16 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdRemoveStream, "remove_stream", 2, tru TREX_RPC_CMD_DEFINE_EXTENDED(TrexRpcCmdAddStream, "add_stream", 3, true, /* extended part */ -TrexStream * allocate_new_stream(const Json::Value §ion, uint8_t port_id, uint32_t stream_id, Json::Value &result); -void validate_stream(const TrexStream *stream, Json::Value &result); -void parse_vm(const Json::Value &vm, TrexStream *stream, Json::Value &result); -void parse_vm_instr_checksum(const Json::Value &inst, TrexStream *stream, Json::Value &result); -void parse_vm_instr_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result); -void parse_vm_instr_tuple_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result); -void parse_vm_instr_trim_pkt_size(const Json::Value &inst, TrexStream *stream, Json::Value &result); - -void parse_vm_instr_write_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result); -void parse_vm_instr_write_mask_flow_var(const Json::Value &inst, TrexStream *stream, Json::Value &result); +std::unique_ptr<TrexStream> allocate_new_stream(const Json::Value §ion, uint8_t port_id, uint32_t stream_id, Json::Value &result); +void validate_stream(const std::unique_ptr<TrexStream> &stream, Json::Value &result); +void parse_vm(const Json::Value &vm, std::unique_ptr<TrexStream> &stream, Json::Value &result); +void parse_vm_instr_checksum(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result); +void parse_vm_instr_flow_var(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result); +void parse_vm_instr_tuple_flow_var(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result); +void parse_vm_instr_trim_pkt_size(const Json::Value &inst, std::unique_ptr<TrexStream> &stream, Json::Value &result); +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); ); |