summaryrefslogtreecommitdiffstats
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
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
-rwxr-xr-xscripts/automation/trex_control_plane/console/trex_console.py4
-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
-rw-r--r--src/stateless/cp/trex_stateless.h4
-rw-r--r--src/stateless/cp/trex_stateless_port.h4
6 files changed, 53 insertions, 2 deletions
diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py
index 51a1f8cc..ec23eb0c 100755
--- a/scripts/automation/trex_control_plane/console/trex_console.py
+++ b/scripts/automation/trex_control_plane/console/trex_console.py
@@ -393,9 +393,9 @@ class TRexConsole(cmd.Cmd):
print "Example: rpc test_add {'x': 12, 'y': 17}\n"
return
- res_ok, msg = self.stateless_client.invoke_rpc_method(method, params)
+ res_ok, msg = self.stateless_client.transmit(method, params)
if res_ok:
- print "\nServer Response:\n\n" + self.stateless_client.pretty_json(json.dumps(msg)) + "\n"
+ print "\nServer Response:\n\n" + pretty_json(json.dumps(msg)) + "\n"
else:
print "\n*** " + msg + "\n"
#print "Please try 'reconnect' to reconnect to server"
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());
diff --git a/src/stateless/cp/trex_stateless.h b/src/stateless/cp/trex_stateless.h
index 758707a2..57c6ef1d 100644
--- a/src/stateless/cp/trex_stateless.h
+++ b/src/stateless/cp/trex_stateless.h
@@ -150,6 +150,10 @@ public:
return (m_platform_api);
}
+ const std::vector <TrexStatelessPort *> get_port_list() {
+ return m_ports;
+ }
+
protected:
/* no copy or assignment */
diff --git a/src/stateless/cp/trex_stateless_port.h b/src/stateless/cp/trex_stateless_port.h
index 79bde01b..3e071954 100644
--- a/src/stateless/cp/trex_stateless_port.h
+++ b/src/stateless/cp/trex_stateless_port.h
@@ -142,6 +142,10 @@ public:
*/
void encode_stats(Json::Value &port);
+ uint8_t get_port_id() {
+ return m_port_id;
+ }
+
private:
std::string generate_handler();