summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-08-18 10:49:59 +0300
committerimarom <imarom@cisco.com>2015-08-18 10:49:59 +0300
commitf88f9364a3a608bd60cf797e36b371cbc217336e (patch)
treeb461e52bb1647dc19fc7e450f033a4f670ecb506
parentcbc645cba025f2098031350fc1323e6ffff33633 (diff)
some minor fixes
-rw-r--r--src/rpc-server/include/trex_rpc_cmds_table.h14
-rw-r--r--src/rpc-server/src/commands/trex_rpc_cmd_test.cpp54
-rw-r--r--src/rpc-server/src/commands/trex_rpc_cmds.h22
-rw-r--r--src/rpc-server/src/trex_rpc_cmds_table.cpp12
4 files changed, 84 insertions, 18 deletions
diff --git a/src/rpc-server/include/trex_rpc_cmds_table.h b/src/rpc-server/include/trex_rpc_cmds_table.h
index 3cf67669..a41944f1 100644
--- a/src/rpc-server/include/trex_rpc_cmds_table.h
+++ b/src/rpc-server/include/trex_rpc_cmds_table.h
@@ -43,10 +43,24 @@ public:
return instance;
}
+ /**
+ * register a new command
+ *
+ */
void register_command(TrexRpcCommand *command);
+ /**
+ * lookup for a command
+ *
+ */
TrexRpcCommand * lookup(const std::string &method_name);
+ /**
+ * query all commands registered
+ *
+ */
+ void query(std::vector<std::string> &cmds);
+
private:
TrexRpcCommandsTable();
~TrexRpcCommandsTable();
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 913736af..f2d4121e 100644
--- a/src/rpc-server/src/commands/trex_rpc_cmd_test.cpp
+++ b/src/rpc-server/src/commands/trex_rpc_cmd_test.cpp
@@ -20,6 +20,8 @@ limitations under the License.
*/
#include "trex_rpc_cmds.h"
#include <iostream>
+#include <sstream>
+#include <trex_rpc_cmds_table.h>
using namespace std;
@@ -27,13 +29,8 @@ using namespace std;
* add command
*
*/
-
-TestRpcAddMethod::TestRpcAddMethod() : TrexRpcCommand("test_rpc_add") {
-
-}
-
TrexRpcCommand::rpc_cmd_rc_e
-TestRpcAddMethod::_run(const Json::Value &params, Json::Value &result) {
+TrexRpcCmdTestAdd::_run(const Json::Value &params, Json::Value &result) {
const Json::Value &x = params["x"];
const Json::Value &y = params["y"];
@@ -57,13 +54,8 @@ TestRpcAddMethod::_run(const Json::Value &params, Json::Value &result) {
*
* @author imarom (16-Aug-15)
*/
-
-TestRpcSubMethod::TestRpcSubMethod() : TrexRpcCommand("test_rpc_sub") {
-
-}
-
TrexRpcCommand::rpc_cmd_rc_e
-TestRpcSubMethod::_run(const Json::Value &params, Json::Value &result) {
+TrexRpcCmdTestSub::_run(const Json::Value &params, Json::Value &result) {
const Json::Value &x = params["x"];
const Json::Value &y = params["y"];
@@ -82,3 +74,41 @@ TestRpcSubMethod::_run(const Json::Value &params, Json::Value &result) {
return (RPC_CMD_OK);
}
+/**
+ * ping command
+ */
+TrexRpcCommand::rpc_cmd_rc_e
+TrexRpcCmdPing::_run(const Json::Value &params, Json::Value &result) {
+
+ /* validate count */
+ if (params.size() != 0) {
+ return (TrexRpcCommand::RPC_CMD_PARAM_COUNT_ERR);
+ }
+
+ result["result"] = "ACK";
+ return (RPC_CMD_OK);
+}
+
+/**
+ * query command
+ */
+TrexRpcCommand::rpc_cmd_rc_e
+TrexRpcCmdGetReg::_run(const Json::Value &params, Json::Value &result) {
+ vector<string> cmds;
+ stringstream ss;
+
+ /* validate count */
+ if (params.size() != 0) {
+ return (TrexRpcCommand::RPC_CMD_PARAM_COUNT_ERR);
+ }
+
+
+ TrexRpcCommandsTable::get_instance().query(cmds);
+ for (auto cmd : cmds) {
+ ss << cmd << "\n";
+ }
+
+ result["result"] = ss.str();
+ return (RPC_CMD_OK);
+}
+
diff --git a/src/rpc-server/src/commands/trex_rpc_cmds.h b/src/rpc-server/src/commands/trex_rpc_cmds.h
index ea6e1081..44b72c4c 100644
--- a/src/rpc-server/src/commands/trex_rpc_cmds.h
+++ b/src/rpc-server/src/commands/trex_rpc_cmds.h
@@ -28,16 +28,30 @@ limitations under the License.
/* all the RPC commands decl. goes here */
/******************* test section ************/
-class TestRpcAddMethod : public TrexRpcCommand {
+class TrexRpcCmdTestAdd : public TrexRpcCommand {
public:
- TestRpcAddMethod();
+ TrexRpcCmdTestAdd() : TrexRpcCommand("rpc_test_add") {}
protected:
virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
};
-class TestRpcSubMethod : public TrexRpcCommand {
+class TrexRpcCmdTestSub : public TrexRpcCommand {
public:
- TestRpcSubMethod();
+ TrexRpcCmdTestSub() : TrexRpcCommand("rpc_test_sub") {} ;
+protected:
+ virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
+};
+
+class TrexRpcCmdPing : public TrexRpcCommand {
+public:
+ TrexRpcCmdPing() : TrexRpcCommand("rpc_ping") {};
+protected:
+ virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
+};
+
+class TrexRpcCmdGetReg : public TrexRpcCommand {
+public:
+ TrexRpcCmdGetReg() : TrexRpcCommand("rpc_get_reg_cmds") {};
protected:
virtual rpc_cmd_rc_e _run(const Json::Value &params, Json::Value &result);
};
diff --git a/src/rpc-server/src/trex_rpc_cmds_table.cpp b/src/rpc-server/src/trex_rpc_cmds_table.cpp
index 4bc1ef29..7635f14f 100644
--- a/src/rpc-server/src/trex_rpc_cmds_table.cpp
+++ b/src/rpc-server/src/trex_rpc_cmds_table.cpp
@@ -28,8 +28,10 @@ using namespace std;
/************* table related methods ***********/
TrexRpcCommandsTable::TrexRpcCommandsTable() {
/* add the test command (for gtest) */
- register_command(new TestRpcAddMethod());
- register_command(new TestRpcSubMethod());
+ register_command(new TrexRpcCmdTestAdd());
+ register_command(new TrexRpcCmdTestSub());
+ register_command(new TrexRpcCmdPing());
+ register_command(new TrexRpcCmdGetReg());
}
TrexRpcCommandsTable::~TrexRpcCommandsTable() {
@@ -48,3 +50,9 @@ void TrexRpcCommandsTable::register_command(TrexRpcCommand *command) {
m_rpc_cmd_table[command->get_name()] = command;
}
+void TrexRpcCommandsTable::query(vector<string> &cmds) {
+ for (auto cmd : m_rpc_cmd_table) {
+ cmds.push_back(cmd.first);
+ }
+}
+