diff options
Diffstat (limited to 'src/rpc-server')
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_general.cpp | 57 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmds.h | 13 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmd.cpp | 28 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmd_api.h | 3 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmds_table.cpp | 4 |
5 files changed, 55 insertions, 50 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index 5cea055c..6c239bf3 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -198,10 +198,6 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value ¶ms, Json::Value &result) { } - section["ports"][i]["owner"] = port->get_owner(); - - section["ports"][i]["status"] = port->get_state_as_string(); - } return (TREX_RPC_CMD_OK); @@ -224,7 +220,7 @@ TrexRpcCmdGetOwner::_run(const Json::Value ¶ms, Json::Value &result) { uint8_t port_id = parse_port(params, result); TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); - section["owner"] = port->get_owner(); + section["owner"] = port->get_owner().get_name(); return (TREX_RPC_CMD_OK); } @@ -238,19 +234,20 @@ TrexRpcCmdAcquire::_run(const Json::Value ¶ms, Json::Value &result) { uint8_t port_id = parse_port(params, result); - const string &new_owner = parse_string(params, "user", result); + const string &new_owner = parse_string(params, "user", result); + uint32_t session_id = parse_uint32(params, "session_id", result); bool force = parse_bool(params, "force", result); /* if not free and not you and not force - fail */ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); try { - port->acquire(new_owner, force); + port->acquire(new_owner, session_id, force); } catch (const TrexRpcException &ex) { generate_execute_err(result, ex.what()); } - result["result"] = port->get_owner_handler(); + result["result"] = port->get_owner().get_handler(); return (TREX_RPC_CMD_OK); } @@ -288,8 +285,6 @@ TrexRpcCmdGetPortStats::_run(const Json::Value ¶ms, Json::Value &result) { TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); - result["result"]["status"] = port->get_state_as_string(); - try { port->encode_stats(result["result"]); } catch (const TrexRpcException &ex) { @@ -300,41 +295,25 @@ TrexRpcCmdGetPortStats::_run(const Json::Value ¶ms, Json::Value &result) { } /** - * request the server a sync about a specific user + * fetch the port status + * + * @author imarom (09-Dec-15) + * + * @param params + * @param result * + * @return trex_rpc_cmd_rc_e */ trex_rpc_cmd_rc_e -TrexRpcCmdSyncUser::_run(const Json::Value ¶ms, Json::Value &result) { - - const string &user = parse_string(params, "user", result); - bool sync_streams = parse_bool(params, "sync_streams", result); - - result["result"] = Json::arrayValue; - - for (auto port : get_stateless_obj()->get_port_list()) { - if (port->get_owner() == user) { - - Json::Value owned_port; +TrexRpcCmdGetPortStatus::_run(const Json::Value ¶ms, Json::Value &result) { + uint8_t port_id = parse_port(params, result); - owned_port["port_id"] = port->get_port_id(); - owned_port["handler"] = port->get_owner_handler(); - owned_port["state"] = port->get_state_as_string(); - - /* if sync streams was asked - sync all the streams */ - if (sync_streams) { - owned_port["streams"] = Json::arrayValue; + TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); - std::vector <TrexStream *> streams; - port->get_object_list(streams); + result["result"]["owner"] = (port->get_owner().is_free() ? "" : port->get_owner().get_name()); + result["result"]["state"] = port->get_state_as_string(); - for (auto stream : streams) { - owned_port["streams"].append(stream->get_stream_json()); - } - } - - result["result"].append(owned_port); - } - } return (TREX_RPC_CMD_OK); } + diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h index 80bef3b0..b9be1fbe 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -70,14 +70,15 @@ void get_hostname(std::string &hostname); * ownership */ TREX_RPC_CMD_DEFINE(TrexRpcCmdGetOwner, "get_owner", 1, false); -TREX_RPC_CMD_DEFINE(TrexRpcCmdAcquire, "acquire", 3, false); +TREX_RPC_CMD_DEFINE(TrexRpcCmdAcquire, "acquire", 4, false); TREX_RPC_CMD_DEFINE(TrexRpcCmdRelease, "release", 1, true); /** * port commands */ -TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStats, "get_port_stats", 1, true); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStats, "get_port_stats", 1, false); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStatus, "get_port_status", 1, false); /** @@ -98,10 +99,10 @@ void parse_vm_instr_write_flow_var(const Json::Value &inst, TrexStream *stream, ); -TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStreamList, "get_stream_list", 1, true); -TREX_RPC_CMD_DEFINE(TrexRpcCmdGetAllStreams, "get_all_streams", 2, true); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStreamList, "get_stream_list", 1, false); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetAllStreams, "get_all_streams", 2, false); -TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStream, "get_stream", 3, true); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStream, "get_stream", 3, false); @@ -112,8 +113,6 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdResumeTraffic, "resume_traffic", 1, true); TREX_RPC_CMD_DEFINE(TrexRpcCmdUpdateTraffic, "update_traffic", 2, true); -TREX_RPC_CMD_DEFINE(TrexRpcCmdSyncUser, "sync_user", 2, false); - TREX_RPC_CMD_DEFINE(TrexRpcCmdValidate, "validate", 2, false); #endif /* __TREX_RPC_CMD_H__ */ diff --git a/src/rpc-server/trex_rpc_cmd.cpp b/src/rpc-server/trex_rpc_cmd.cpp index af0db3f4..d4eef1f7 100644 --- a/src/rpc-server/trex_rpc_cmd.cpp +++ b/src/rpc-server/trex_rpc_cmd.cpp @@ -63,8 +63,12 @@ TrexRpcCommand::verify_ownership(const Json::Value ¶ms, Json::Value &result) TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id); - if (!port->verify_owner_handler(handler)) { - generate_execute_err(result, "invalid handler provided. please pass the handler given when calling 'acquire' or take ownership"); + if (port->get_owner().is_free()) { + generate_execute_err(result, "please acquire the port before modifying port state"); + } + + if (!port->get_owner().verify(handler)) { + generate_execute_err(result, "port is not owned by you or your current executing session"); } } @@ -92,6 +96,8 @@ TrexRpcCommand::type_to_str(field_type_e type) { return "byte"; case FIELD_TYPE_UINT16: return "uint16"; + case FIELD_TYPE_UINT32: + return "uint32"; case FIELD_TYPE_BOOL: return "bool"; case FIELD_TYPE_INT: @@ -161,6 +167,18 @@ TrexRpcCommand::parse_uint16(const Json::Value &parent, int index, Json::Value & return parent[index].asUInt(); } +uint32_t +TrexRpcCommand::parse_uint32(const Json::Value &parent, const std::string &name, Json::Value &result) { + check_field_type(parent, name, FIELD_TYPE_UINT32, result); + return parent[name].asUInt(); +} + +uint32_t +TrexRpcCommand::parse_uint32(const Json::Value &parent, int index, Json::Value &result) { + check_field_type(parent, index, FIELD_TYPE_UINT32, result); + return parent[index].asUInt(); +} + int TrexRpcCommand::parse_int(const Json::Value &parent, const std::string &name, Json::Value &result) { check_field_type(parent, name, FIELD_TYPE_INT, result); @@ -250,6 +268,12 @@ TrexRpcCommand::check_field_type_common(const Json::Value &field, const std::str } break; + case FIELD_TYPE_UINT32: + if ( (!field.isUInt()) || (field.asUInt() > 0xFFFFFFFF)) { + rc = false; + } + break; + case FIELD_TYPE_BOOL: if (!field.isBool()) { rc = false; diff --git a/src/rpc-server/trex_rpc_cmd_api.h b/src/rpc-server/trex_rpc_cmd_api.h index e93fb775..f81981d4 100644 --- a/src/rpc-server/trex_rpc_cmd_api.h +++ b/src/rpc-server/trex_rpc_cmd_api.h @@ -99,6 +99,7 @@ protected: enum field_type_e { FIELD_TYPE_BYTE, FIELD_TYPE_UINT16, + FIELD_TYPE_UINT32, FIELD_TYPE_INT, FIELD_TYPE_DOUBLE, FIELD_TYPE_BOOL, @@ -136,6 +137,7 @@ protected: */ uint8_t parse_byte(const Json::Value &parent, const std::string &name, Json::Value &result); uint16_t parse_uint16(const Json::Value &parent, const std::string &name, Json::Value &result); + uint32_t parse_uint32(const Json::Value &parent, const std::string &name, Json::Value &result); int parse_int(const Json::Value &parent, const std::string &name, Json::Value &result); double parse_double(const Json::Value &parent, const std::string &name, Json::Value &result); bool parse_bool(const Json::Value &parent, const std::string &name, Json::Value &result); @@ -145,6 +147,7 @@ protected: uint8_t parse_byte(const Json::Value &parent, int index, Json::Value &result); uint16_t parse_uint16(const Json::Value &parent, int index, Json::Value &result); + uint32_t parse_uint32(const Json::Value &parent, int index, Json::Value &result); int parse_int(const Json::Value &parent, int index, Json::Value &result); double parse_double(const Json::Value &parent, int index, Json::Value &result); bool parse_bool(const Json::Value &parent, int index, Json::Value &result); diff --git a/src/rpc-server/trex_rpc_cmds_table.cpp b/src/rpc-server/trex_rpc_cmds_table.cpp index 52258b88..82c723b7 100644 --- a/src/rpc-server/trex_rpc_cmds_table.cpp +++ b/src/rpc-server/trex_rpc_cmds_table.cpp @@ -41,8 +41,8 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() { register_command(new TrexRpcCmdAcquire()); register_command(new TrexRpcCmdRelease()); register_command(new TrexRpcCmdGetPortStats()); - - register_command(new TrexRpcCmdSyncUser()); + register_command(new TrexRpcCmdGetPortStatus()); + /* stream commands */ register_command(new TrexRpcCmdAddStream()); |