summaryrefslogtreecommitdiffstats
path: root/src/rpc-server
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-11-01 18:03:17 +0200
committerimarom <imarom@cisco.com>2015-11-01 18:03:17 +0200
commit7d7767e17b1a4e54a8934ded724f54dc5b6228ce (patch)
treeb9669fbed7820f52444cf220a2647ad3594cf55b /src/rpc-server
parenteacf2829c309011bf15d56b7b531b22ebeaf4d7d (diff)
added support for a new RPC command : sync_user
provides a way to sync a console / GUI to the server for a specific user
Diffstat (limited to 'src/rpc-server')
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_general.cpp39
-rw-r--r--src/rpc-server/commands/trex_rpc_cmds.h2
-rw-r--r--src/rpc-server/trex_rpc_cmds_table.cpp2
3 files changed, 43 insertions, 0 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
index bb54e4a1..b40e996f 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
@@ -277,3 +277,42 @@ TrexRpcCmdGetPortStats::_run(const Json::Value &params, Json::Value &result) {
return (TREX_RPC_CMD_OK);
}
+/**
+ * request the server a sync about a specific user
+ *
+ */
+trex_rpc_cmd_rc_e
+TrexRpcCmdSyncUser::_run(const Json::Value &params, Json::Value &result) {
+
+ const string &user = parse_string(params, "user", result);
+ bool sync_streams = parse_bool(params, "sync_streams", result);
+
+ result["result"] = Json::arrayValue;
+
+ for (auto port : get_stateless_obj()->get_port_list()) {
+ if (port->get_owner() == user) {
+
+ Json::Value owned_port;
+
+ owned_port["port_id"] = port->get_port_id();
+ owned_port["handler"] = port->get_owner_handler();
+ owned_port["state"] = port->get_state_as_string();
+
+ /* if sync streams was asked - sync all the streams */
+ if (sync_streams) {
+ owned_port["streams"] = Json::arrayValue;
+
+ std::vector <TrexStream *> streams;
+ port->get_stream_table()->get_object_list(streams);
+
+ for (auto stream : streams) {
+ owned_port["streams"].append(stream->get_stream_json());
+ }
+ }
+
+ result["result"].append(owned_port);
+ }
+ }
+
+ return (TREX_RPC_CMD_OK);
+}
diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h
index 51db3f40..91c29548 100644
--- a/src/rpc-server/commands/trex_rpc_cmds.h
+++ b/src/rpc-server/commands/trex_rpc_cmds.h
@@ -105,5 +105,7 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStream, "get_stream", 2, true);
TREX_RPC_CMD_DEFINE(TrexRpcCmdStartTraffic, "start_traffic", 2, true);
TREX_RPC_CMD_DEFINE(TrexRpcCmdStopTraffic, "stop_traffic", 1, true);
+TREX_RPC_CMD_DEFINE(TrexRpcCmdSyncUser, "sync_user", 2, false);
+
#endif /* __TREX_RPC_CMD_H__ */
diff --git a/src/rpc-server/trex_rpc_cmds_table.cpp b/src/rpc-server/trex_rpc_cmds_table.cpp
index c1c546f3..46281aff 100644
--- a/src/rpc-server/trex_rpc_cmds_table.cpp
+++ b/src/rpc-server/trex_rpc_cmds_table.cpp
@@ -42,6 +42,8 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() {
register_command(new TrexRpcCmdRelease());
register_command(new TrexRpcCmdGetPortStats());
+ register_command(new TrexRpcCmdSyncUser());
+
/* stream commands */
register_command(new TrexRpcCmdAddStream());
register_command(new TrexRpcCmdRemoveStream());