summaryrefslogtreecommitdiffstats
path: root/src/rpc-server/trex_rpc_cmd.cpp
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-09-17 16:27:47 +0300
committerimarom <imarom@cisco.com>2015-09-17 16:27:47 +0300
commit96765d2bf2c416f652da904cf7524ff75b678aee (patch)
treeadaffcbd4782207e03198814cd288b66b07d7b36 /src/rpc-server/trex_rpc_cmd.cpp
parent1e723ff84bb6cdf6dd3a58650af059b6814b5331 (diff)
moved 'owning states' to port granularity instead of machine
Diffstat (limited to 'src/rpc-server/trex_rpc_cmd.cpp')
-rw-r--r--src/rpc-server/trex_rpc_cmd.cpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/rpc-server/trex_rpc_cmd.cpp b/src/rpc-server/trex_rpc_cmd.cpp
index 437e8b1a..6c355e70 100644
--- a/src/rpc-server/trex_rpc_cmd.cpp
+++ b/src/rpc-server/trex_rpc_cmd.cpp
@@ -20,6 +20,7 @@ limitations under the License.
*/
#include <trex_rpc_cmd_api.h>
#include <trex_rpc_server_api.h>
+#include <trex_stateless_api.h>
trex_rpc_cmd_rc_e
TrexRpcCommand::run(const Json::Value &params, Json::Value &result) {
@@ -57,12 +58,32 @@ TrexRpcCommand::check_param_count(const Json::Value &params, int expected, Json:
void
TrexRpcCommand::verify_ownership(const Json::Value &params, Json::Value &result) {
std::string handler = parse_string(params, "handler", result);
+ uint8_t port_id = parse_port(params, result);
- if (!TrexRpcServer::verify_owner_handler(handler)) {
+ TrexStatelessPort *port = TrexStateless::get_instance().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");
}
}
+uint8_t
+TrexRpcCommand::parse_port(const Json::Value &params, Json::Value &result) {
+ uint8_t port_id = parse_byte(params, "port_id", result);
+ validate_port_id(port_id, result);
+
+ return (port_id);
+}
+
+void
+TrexRpcCommand::validate_port_id(uint8_t port_id, Json::Value &result) {
+ if (port_id >= TrexStateless::get_instance().get_port_count()) {
+ std::stringstream ss;
+ ss << "invalid port id - should be between 0 and " << (int)TrexStateless::get_instance().get_port_count() - 1;
+ generate_execute_err(result, ss.str());
+ }
+}
+
const char *
TrexRpcCommand::type_to_str(field_type_e type) {
switch (type) {