summaryrefslogtreecommitdiffstats
path: root/src/rpc-server
diff options
context:
space:
mode:
Diffstat (limited to 'src/rpc-server')
-rw-r--r--src/rpc-server/include/trex_rpc_cmd_api.h14
-rw-r--r--src/rpc-server/src/commands/trex_rpc_cmd_test.cpp12
-rw-r--r--src/rpc-server/src/commands/trex_rpc_cmds.h10
-rw-r--r--src/rpc-server/src/trex_rpc_jsonrpc_v2_parser.cpp10
4 files changed, 36 insertions, 10 deletions
diff --git a/src/rpc-server/include/trex_rpc_cmd_api.h b/src/rpc-server/include/trex_rpc_cmd_api.h
index 308e344c..c773b15f 100644
--- a/src/rpc-server/include/trex_rpc_cmd_api.h
+++ b/src/rpc-server/include/trex_rpc_cmd_api.h
@@ -69,6 +69,20 @@ protected:
*/
virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result) = 0;
+ /**
+ * error generating functions
+ *
+ */
+ void genernate_err(Json::Value &result, const std::string &msg) {
+ result["specific_err"] = msg;
+ }
+
+ void generate_err_param_count(Json::Value &result, int expected, int provided) {
+ std::stringstream ss;
+ ss << "method expects '" << expected << "' paramteres, '" << provided << "' provided";
+ genernate_err(result, ss.str());
+ }
+
std::string m_name;
};
diff --git a/src/rpc-server/src/commands/trex_rpc_cmd_test.cpp b/src/rpc-server/src/commands/trex_rpc_cmd_test.cpp
index e9cc4665..e2dc8959 100644
--- a/src/rpc-server/src/commands/trex_rpc_cmd_test.cpp
+++ b/src/rpc-server/src/commands/trex_rpc_cmd_test.cpp
@@ -37,11 +37,18 @@ TrexRpcCmdTestAdd::_run(const Json::Value &params, Json::Value &result) {
/* validate count */
if (params.size() != 2) {
+ generate_err_param_count(result, 2, params.size());
return (TrexRpcCommand::RPC_CMD_PARAM_COUNT_ERR);
}
/* check we have all the required paramters */
- if (!x.isInt() || !y.isInt()) {
+ if (!x.isInt()) {
+ genernate_err(result, "'x' is either missing or not an integer");
+ return (TrexRpcCommand::RPC_CMD_PARAM_PARSE_ERR);
+ }
+
+ if (!y.isInt()) {
+ genernate_err(result, "'y' is either missing or not an integer");
return (TrexRpcCommand::RPC_CMD_PARAM_PARSE_ERR);
}
@@ -62,6 +69,7 @@ TrexRpcCmdTestSub::_run(const Json::Value &params, Json::Value &result) {
/* validate count */
if (params.size() != 2) {
+ generate_err_param_count(result, 2, params.size());
return (TrexRpcCommand::RPC_CMD_PARAM_COUNT_ERR);
}
@@ -82,6 +90,7 @@ TrexRpcCmdPing::_run(const Json::Value &params, Json::Value &result) {
/* validate count */
if (params.size() != 0) {
+ generate_err_param_count(result, 0, params.size());
return (TrexRpcCommand::RPC_CMD_PARAM_COUNT_ERR);
}
@@ -98,6 +107,7 @@ TrexRpcCmdGetReg::_run(const Json::Value &params, Json::Value &result) {
/* validate count */
if (params.size() != 0) {
+ generate_err_param_count(result, 0, params.size());
return (TrexRpcCommand::RPC_CMD_PARAM_COUNT_ERR);
}
diff --git a/src/rpc-server/src/commands/trex_rpc_cmds.h b/src/rpc-server/src/commands/trex_rpc_cmds.h
index 0778b75d..e37e1cda 100644
--- a/src/rpc-server/src/commands/trex_rpc_cmds.h
+++ b/src/rpc-server/src/commands/trex_rpc_cmds.h
@@ -35,7 +35,7 @@ limitations under the License.
*/
class TrexRpcCmdTestAdd : public TrexRpcCommand {
public:
- TrexRpcCmdTestAdd() : TrexRpcCommand("rpc_test_add") {}
+ TrexRpcCmdTestAdd() : TrexRpcCommand("test_add") {}
protected:
virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
};
@@ -46,7 +46,7 @@ protected:
*/
class TrexRpcCmdTestSub : public TrexRpcCommand {
public:
- TrexRpcCmdTestSub() : TrexRpcCommand("rpc_test_sub") {} ;
+ TrexRpcCmdTestSub() : TrexRpcCommand("test_sub") {} ;
protected:
virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
};
@@ -57,7 +57,7 @@ protected:
*/
class TrexRpcCmdPing : public TrexRpcCommand {
public:
- TrexRpcCmdPing() : TrexRpcCommand("rpc_ping") {};
+ TrexRpcCmdPing() : TrexRpcCommand("ping") {};
protected:
virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
};
@@ -68,7 +68,7 @@ protected:
*/
class TrexRpcCmdGetReg : public TrexRpcCommand {
public:
- TrexRpcCmdGetReg() : TrexRpcCommand("rpc_get_reg_cmds") {};
+ TrexRpcCmdGetReg() : TrexRpcCommand("get_reg_cmds") {};
protected:
virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
};
@@ -79,7 +79,7 @@ protected:
*/
class TrexRpcCmdGetStatus : public TrexRpcCommand {
public:
- TrexRpcCmdGetStatus() : TrexRpcCommand("rpc_get_status") {};
+ TrexRpcCmdGetStatus() : TrexRpcCommand("get_status") {};
protected:
virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
};
diff --git a/src/rpc-server/src/trex_rpc_jsonrpc_v2_parser.cpp b/src/rpc-server/src/trex_rpc_jsonrpc_v2_parser.cpp
index c11c603f..be1eb2f8 100644
--- a/src/rpc-server/src/trex_rpc_jsonrpc_v2_parser.cpp
+++ b/src/rpc-server/src/trex_rpc_jsonrpc_v2_parser.cpp
@@ -80,13 +80,15 @@ public:
case TrexRpcCommand::RPC_CMD_PARAM_COUNT_ERR:
case TrexRpcCommand::RPC_CMD_PARAM_PARSE_ERR:
- response["error"]["code"] = JSONRPC_V2_ERR_INVALID_PARAMS;
- response["error"]["message"] = "Bad paramters for method";
+ response["error"]["code"] = JSONRPC_V2_ERR_INVALID_PARAMS;
+ response["error"]["message"] = "Bad paramters for method";
+ response["error"]["specific_err"] = result["specific_err"];
break;
case TrexRpcCommand::RPC_CMD_INTERNAL_ERR:
- response["error"]["code"] = JSONRPC_V2_ERR_INTERNAL_ERROR;
- response["error"]["message"] = "Internal Server Error";
+ response["error"]["code"] = JSONRPC_V2_ERR_INTERNAL_ERROR;
+ response["error"]["message"] = "Internal Server Error";
+ response["error"]["specific_err"] = result["specific_err"];
break;
}