diff options
author | imarom <imarom@cisco.com> | 2015-08-31 17:26:08 +0300 |
---|---|---|
committer | imarom <imarom@cisco.com> | 2015-08-31 17:26:08 +0300 |
commit | 40461a9752437ee541d797f76d2fba77cad9d0e2 (patch) | |
tree | 4ff731920ccd25a0fa5080a4553f0300d49db7a8 /src/rpc-server/commands | |
parent | 499b4d6221c023d656663fe441bbf5d194886efb (diff) |
...draft...
Diffstat (limited to 'src/rpc-server/commands')
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_general.cpp | 3 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 143 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_test.cpp | 10 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmds.h | 38 |
4 files changed, 139 insertions, 55 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index 484cd2b9..6b765aca 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -34,9 +34,6 @@ using namespace std; trex_rpc_cmd_rc_e TrexRpcCmdGetStatus::_run(const Json::Value ¶ms, Json::Value &result) { - /* validate count */ - check_param_count(params, 0, result); - Json::Value §ion = result["result"]; #ifndef TREX_RPC_MOCK_SERVER diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index fcd91ab7..25dee501 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -35,65 +35,148 @@ using namespace std; trex_rpc_cmd_rc_e TrexRpcCmdAddStream::_run(const Json::Value ¶ms, Json::Value &result) { - TrexStream *stream; - - check_param_count(params, 1, result); - const Json::Value §ion = parse_object(params, "stream", result); /* get the type of the stream */ const Json::Value &mode = parse_object(section, "mode", result); string type = parse_string(mode, "type", result); + TrexStream *stream = allocate_new_stream(section, result); + + /* create a new steram and populate it */ + + stream->m_isg_usec = parse_double(section, "Is", result); + + stream->m_next_stream_id = parse_int(section, "next_stream_id", result); + stream->m_loop_count = parse_int(section, "loop_count", result); + + const Json::Value &pkt = parse_array(section, "packet", result); + + /* fetch the packet from the message */ + + stream->m_pkt_len = pkt.size(); + stream->m_pkt = new uint8_t[pkt.size()]; + if (!stream->m_pkt) { + generate_internal_err(result, "unable to allocate memory"); + } + + for (int i = 0; i < pkt.size(); i++) { + stream->m_pkt[i] = parse_byte(pkt, i, result); + } + + /* make sure this is a valid stream to add */ + validate_stream(stream, result); + + TrexStatelessPort *port = get_trex_stateless()->get_port_by_id(stream->m_port_id); + port->get_stream_table()->add_stream(stream); + + result["result"] = "ACK"; + + return (TREX_RPC_CMD_OK); +} + + + +TrexStream * +TrexRpcCmdAddStream::allocate_new_stream(const Json::Value §ion, Json::Value &result) { + + uint8_t port_id = parse_int(section, "port_id", result); + uint32_t stream_id = parse_int(section, "stream_id", result); + + TrexStream *stream; + + const Json::Value &mode = parse_object(section, "mode", result); + std::string type = parse_string(mode, "type", result); + if (type == "continuous") { - stream = new TrexStreamContinuous(); + + uint32_t pps = parse_int(mode, "pps", result); + stream = new TrexStreamContinuous(port_id, stream_id, pps); + } else if (type == "single_burst") { - stream = new TrexStreamSingleBurst(); + + uint32_t pps = parse_int(mode, "pps", result); + uint32_t packets = parse_int(type, "packets", result); + + stream = new TrexStreamSingleBurst(port_id, stream_id, pps, packets); + } else if (type == "multi_burst") { - stream = new TrexStreamMultiBurst(); + + uint32_t pps = parse_int(mode, "pps", result); + double ibg_usec = parse_double(mode, "ibg", result); + uint32_t num_bursts = parse_int(mode, "number_of_bursts", result); + uint32_t pkt_per_burst = parse_int(mode, "pkt_per_burst", result); + + stream = new TrexStreamMultiBurst(port_id, stream_id, pps, ibg_usec, num_bursts, pkt_per_burst); + + } else { - generate_err(result, "bad stream type provided: '" + type + "'"); + generate_parse_err(result, "bad stream type provided: '" + type + "'"); } if (!stream) { generate_internal_err(result, "unable to allocate memory"); } - /* create a new steram and populate it */ - stream->stream_id = parse_int(section, "stream_id", result); - stream->port_id = parse_int(section, "port_id", result); - stream->isg_usec = parse_double(section, "Is", result); + return (stream); - stream->next_stream_id = parse_int(section, "next_stream_id", result); - stream->loop_count = parse_int(section, "loop_count", result); +} - const Json::Value &pkt = parse_array(section, "packet", result); +void +TrexRpcCmdAddStream::validate_stream(const TrexStream *stream, Json::Value &result) { - if ( (pkt.size() < TrexStream::MIN_PKT_SIZE_BYTES) || (pkt.size() > TrexStream::MAX_PKT_SIZE_BYTES) ) { - generate_err(result, "bad packet size provided: should be between 64B and 9K"); + /* check packet size */ + if ( (stream->m_pkt_len < TrexStream::MIN_PKT_SIZE_BYTES) || (stream->m_pkt_len > TrexStream::MAX_PKT_SIZE_BYTES) ) { + std::stringstream ss; + ss << "bad packet size provided: should be between " << TrexStream::MIN_PKT_SIZE_BYTES << " and " << TrexStream::MAX_PKT_SIZE_BYTES; + delete stream; + generate_execute_err(result, ss.str()); } - stream->pkt = new uint8_t[pkt.size()]; - if (!stream->pkt) { - generate_internal_err(result, "unable to allocate memory"); + /* port id should be between 0 and count - 1 */ + if (stream->m_port_id >= get_trex_stateless()->get_port_count()) { + std::stringstream ss; + ss << "invalid port id - should be between 0 and " << (int)get_trex_stateless()->get_port_count() - 1; + delete stream; + generate_execute_err(result, ss.str()); } - for (int i = 0; i < pkt.size(); i++) { - stream->pkt[i] = parse_byte(pkt, i, result); + /* add the stream to the port's stream table */ + TrexStatelessPort * port = get_trex_stateless()->get_port_by_id(stream->m_port_id); + + /* does such a stream exists ? */ + if (port->get_stream_table()->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()); } - /* register the stream to the port */ +} + +trex_rpc_cmd_rc_e +TrexRpcCmdRemoveStream::_run(const Json::Value ¶ms, Json::Value &result) { + uint8_t port_id = parse_byte(params, "port_id", result); + uint32_t stream_id = parse_int(params, "stream_id", result); + - /* port id should be between 0 and count - 1 */ - if (stream->port_id >= get_trex_stateless()->get_port_count()) { + if (port_id >= get_trex_stateless()->get_port_count()) { std::stringstream ss; - ss << "invalid port id - should be between 0 and " << get_trex_stateless()->get_port_count(); - generate_err(result, ss.str()); + ss << "invalid port id - should be between 0 and " << (int)get_trex_stateless()->get_port_count() - 1; + generate_execute_err(result, ss.str()); } - TrexStatelessPort * port = get_trex_stateless()->get_port_by_id(stream->port_id); - port->get_stream_table()->add_stream(stream); + TrexStatelessPort *port = get_trex_stateless()->get_port_by_id(port_id); + TrexStream *stream = port->get_stream_table()->get_stream_by_id(stream_id); - return (TREX_RPC_CMD_OK); + if (!stream) { + std::stringstream ss; + ss << "stream " << stream_id << " does not exists"; + generate_execute_err(result, ss.str()); + } + + port->get_stream_table()->remove_stream(stream); + + result["result"] = "ACK"; } diff --git a/src/rpc-server/commands/trex_rpc_cmd_test.cpp b/src/rpc-server/commands/trex_rpc_cmd_test.cpp index 473cbb70..382279ba 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_test.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_test.cpp @@ -35,8 +35,6 @@ TrexRpcCmdTestAdd::_run(const Json::Value ¶ms, Json::Value &result) { const Json::Value &x = params["x"]; const Json::Value &y = params["y"]; - check_param_count(params, 2, result); - result["result"] = parse_int(params, "x", result) + parse_int(params, "y", result); return (TREX_RPC_CMD_OK); @@ -53,8 +51,6 @@ TrexRpcCmdTestSub::_run(const Json::Value ¶ms, Json::Value &result) { const Json::Value &x = params["x"]; const Json::Value &y = params["y"]; - check_param_count(params, 2, result); - result["result"] = parse_int(params, "x", result) - parse_int(params, "y", result); return (TREX_RPC_CMD_OK); @@ -66,9 +62,6 @@ TrexRpcCmdTestSub::_run(const Json::Value ¶ms, Json::Value &result) { trex_rpc_cmd_rc_e TrexRpcCmdPing::_run(const Json::Value ¶ms, Json::Value &result) { - /* validate count */ - check_param_count(params, 0, result); - result["result"] = "ACK"; return (TREX_RPC_CMD_OK); } @@ -80,9 +73,6 @@ trex_rpc_cmd_rc_e TrexRpcCmdGetReg::_run(const Json::Value ¶ms, Json::Value &result) { vector<string> cmds; - /* validate count */ - check_param_count(params, 0, result); - TrexRpcCommandsTable::get_instance().query(cmds); Json::Value test = Json::arrayValue; diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h index 5c425856..7ec8aba3 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -25,6 +25,8 @@ limitations under the License. #include <trex_rpc_cmd_api.h> #include <json/json.h> +class TrexStream; + /* all the RPC commands decl. goes here */ /******************* test section ************/ @@ -32,31 +34,43 @@ limitations under the License. /** * syntactic sugar for creating a simple command */ -#define TREX_RPC_CMD_DEFINE(class_name, cmd_name) \ - class class_name : public TrexRpcCommand { \ - public: \ - class_name () : TrexRpcCommand(cmd_name) {} \ - protected: \ - virtual trex_rpc_cmd_rc_e _run(const Json::Value ¶ms, Json::Value &result); \ + +#define TREX_RPC_CMD_DEFINE_EXTENED(class_name, cmd_name, param_count, ext) \ + class class_name : public TrexRpcCommand { \ + public: \ + class_name () : TrexRpcCommand(cmd_name, param_count) {} \ + protected: \ + virtual trex_rpc_cmd_rc_e _run(const Json::Value ¶ms, Json::Value &result); \ + ext \ } +#define TREX_RPC_CMD_DEFINE(class_name, cmd_name, param_count) TREX_RPC_CMD_DEFINE_EXTENED(class_name, cmd_name, param_count, ;) /** * test cmds */ -TREX_RPC_CMD_DEFINE(TrexRpcCmdTestAdd, "test_add"); -TREX_RPC_CMD_DEFINE(TrexRpcCmdTestSub, "test_sub"); +TREX_RPC_CMD_DEFINE(TrexRpcCmdTestAdd, "test_add", 2); +TREX_RPC_CMD_DEFINE(TrexRpcCmdTestSub, "test_sub", 2); /** * general cmds */ -TREX_RPC_CMD_DEFINE(TrexRpcCmdPing, "ping"); -TREX_RPC_CMD_DEFINE(TrexRpcCmdGetReg, "get_reg_cmds"); -TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStatus, "get_status"); +TREX_RPC_CMD_DEFINE(TrexRpcCmdPing, "ping", 0); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetReg, "get_reg_cmds", 0); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStatus, "get_status", 0); /** * stream cmds */ -TREX_RPC_CMD_DEFINE(TrexRpcCmdAddStream, "add_stream"); +TREX_RPC_CMD_DEFINE(TrexRpcCmdRemoveStream, "remove_stream", 2); + +TREX_RPC_CMD_DEFINE_EXTENED(TrexRpcCmdAddStream, "add_stream", 1, + +/* extended part */ +TrexStream * allocate_new_stream(const Json::Value §ion, Json::Value &result); +void validate_stream(const TrexStream *stream, Json::Value &result); + +); + #endif /* __TREX_RPC_CMD_H__ */ |