summaryrefslogtreecommitdiffstats
path: root/src/rpc-server/trex_rpc_cmd.cpp
diff options
context:
space:
mode:
authorHanoh Haim <hhaim@cisco.com>2015-09-17 21:46:17 +0300
committerHanoh Haim <hhaim@cisco.com>2015-09-17 21:46:17 +0300
commita78680a896f65dd6733d27d99e9cd8440eb185e9 (patch)
treed7b9e514b413847944e39eb1dcc874b4c9044c42 /src/rpc-server/trex_rpc_cmd.cpp
parentf885ac59cebcf1e87b97b0e6ef6e9eb032f9f733 (diff)
parentf61bbcca4ab21100068887b1a08bf9bdf250f14d (diff)
Merge branch 'master' of csi-sceasr-b45:/auto/proj-pcube-b/apps/PL-b/tools/repo//trex-corev1.76
Diffstat (limited to 'src/rpc-server/trex_rpc_cmd.cpp')
-rw-r--r--src/rpc-server/trex_rpc_cmd.cpp39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/rpc-server/trex_rpc_cmd.cpp b/src/rpc-server/trex_rpc_cmd.cpp
index 3fc77f71..6c355e70 100644
--- a/src/rpc-server/trex_rpc_cmd.cpp
+++ b/src/rpc-server/trex_rpc_cmd.cpp
@@ -19,6 +19,8 @@ See the License for the specific language governing permissions and
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) {
@@ -26,8 +28,16 @@ TrexRpcCommand::run(const Json::Value &params, Json::Value &result) {
/* the internal run can throw a parser error / other error */
try {
+
check_param_count(params, m_param_count, result);
+
+ if (m_needs_ownership) {
+ verify_ownership(params, result);
+ }
+
+ /* run the command itself*/
rc = _run(params, result);
+
} catch (TrexRpcCommandException &e) {
return e.get_rc();
}
@@ -45,6 +55,35 @@ 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);
+
+ 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) {