summaryrefslogtreecommitdiffstats
path: root/src/rpc-server/trex_rpc_cmd.cpp
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-04-03 18:19:20 +0300
committerimarom <imarom@cisco.com>2016-04-04 09:49:54 +0300
commit4eacb570cf24927de536d23671f50609f1a9ffa5 (patch)
tree83b8dcd86994c7668a054413d0ba0449a1cf2816 /src/rpc-server/trex_rpc_cmd.cpp
parent0eb15b2e851b5f50669633678143c5a1d3a7d95b (diff)
API classes (versions)
Diffstat (limited to 'src/rpc-server/trex_rpc_cmd.cpp')
-rw-r--r--src/rpc-server/trex_rpc_cmd.cpp46
1 files changed, 45 insertions, 1 deletions
diff --git a/src/rpc-server/trex_rpc_cmd.cpp b/src/rpc-server/trex_rpc_cmd.cpp
index caf161e3..902e63c7 100644
--- a/src/rpc-server/trex_rpc_cmd.cpp
+++ b/src/rpc-server/trex_rpc_cmd.cpp
@@ -23,6 +23,32 @@ limitations under the License.
#include <trex_stateless.h>
#include <trex_stateless_port.h>
+/**
+ * method name and params
+ *
+ */
+TrexRpcCommand::TrexRpcCommand(const std::string &method_name,
+ int param_count,
+ bool needs_ownership,
+ APIClass::type_e type) : m_name(method_name),
+ m_param_count(param_count),
+ m_needs_ownership(needs_ownership) {
+
+ /* if needs ownership - another field is needed (handler) */
+ if (m_needs_ownership) {
+ m_param_count++;
+ }
+
+ /* API verification */
+ m_api_type = type;
+
+ if (type != APIClass::API_CLASS_TYPE_NO_API) {
+ m_api_handler = get_stateless_obj()->get_api_handler(type);
+ m_param_count++;
+ }
+
+}
+
trex_rpc_cmd_rc_e
TrexRpcCommand::run(const Json::Value &params, Json::Value &result) {
trex_rpc_cmd_rc_e rc;
@@ -30,12 +56,18 @@ 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);
+ /* verify API handler is correct (version mismatch) */
+ if ( (m_api_type != APIClass::API_CLASS_TYPE_NO_API) && !g_test_override_api ) {
+ verify_api_handler(params, result);
+ }
+ /* verify ownership */
if (m_needs_ownership && !g_test_override_ownership) {
verify_ownership(params, result);
}
+ check_param_count(params, m_param_count, result);
+
/* run the command itself*/
rc = _run(params, result);
@@ -72,6 +104,17 @@ TrexRpcCommand::verify_ownership(const Json::Value &params, Json::Value &result)
}
}
+void
+TrexRpcCommand::verify_api_handler(const Json::Value &params, Json::Value &result) {
+ std::string api_handler = parse_string(params, "api_h", result);
+
+ if (m_api_handler != api_handler) {
+ std::stringstream ss;
+ ss << "API verification failed - API handler provided mismatch for class: '" << APIClass::type_to_name(m_api_type) << "'";
+ generate_execute_err(result, ss.str());
+ }
+}
+
uint8_t
TrexRpcCommand::parse_port(const Json::Value &params, Json::Value &result) {
uint8_t port_id = parse_byte(params, "port_id", result);
@@ -281,3 +324,4 @@ TrexRpcCommand::generate_execute_err(Json::Value &result, const std::string &msg
* by default this is off
*/
bool TrexRpcCommand::g_test_override_ownership = false;
+bool TrexRpcCommand::g_test_override_api = false;