summaryrefslogtreecommitdiffstats
path: root/src/rpc-server
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-09-06 15:23:40 +0300
committerimarom <imarom@cisco.com>2015-09-06 15:23:40 +0300
commitc625b6e4f6d71176ef1db5aab93f4e66939d7a25 (patch)
tree25527fa0156bb95434fbd653e938acf986da9636 /src/rpc-server
parentea30ab5d1165707ffb1297dabf2b24ecbd5d39a5 (diff)
trex stateless changed to singleton.
added some more commands (remove all, get list of streams)
Diffstat (limited to 'src/rpc-server')
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_general.cpp12
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_stream.cpp74
-rw-r--r--src/rpc-server/commands/trex_rpc_cmds.h2
-rw-r--r--src/rpc-server/trex_rpc_cmds_table.cpp1
-rw-r--r--src/rpc-server/trex_rpc_server.cpp1
-rw-r--r--src/rpc-server/trex_rpc_server_api.h24
-rw-r--r--src/rpc-server/trex_rpc_server_mock.cpp5
7 files changed, 99 insertions, 20 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
index 6b765aca..32952b1a 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
@@ -20,6 +20,7 @@ limitations under the License.
*/
#include "trex_rpc_cmds.h"
#include <trex_rpc_server_api.h>
+#include <trex_stateless_api.h>
#ifndef TREX_RPC_MOCK_SERVER
#include <../linux_dpdk/version.h>
@@ -41,8 +42,7 @@ TrexRpcCmdGetStatus::_run(const Json::Value &params, Json::Value &result) {
section["general"]["version"] = VERSION_BUILD_NUM;
section["general"]["build_date"] = get_build_date();
section["general"]["build_time"] = get_build_time();
- section["general"]["version_user"] = VERSION_USER;
- section["general"]["uptime"] = TrexRpcServer::get_server_uptime();
+ section["general"]["built_by"] = VERSION_USER;
#else
@@ -50,10 +50,16 @@ TrexRpcCmdGetStatus::_run(const Json::Value &params, Json::Value &result) {
section["general"]["build_date"] = __DATE__;
section["general"]["build_time"] = __TIME__;
section["general"]["version_user"] = "MOCK";
- section["general"]["uptime"] = TrexRpcServer::get_server_uptime();
#endif
+ section["general"]["uptime"] = TrexRpcServer::get_server_uptime();
+ section["general"]["owner"] = TrexRpcServer::get_owner();
+
+ // ports
+
+ section["ports"]["count"] = TrexStateless::get_instance().get_port_count();
+
return (TREX_RPC_CMD_OK);
}
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
index 3ddf07fa..6dfebe6d 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
@@ -52,21 +52,25 @@ TrexRpcCmdAddStream::_run(const Json::Value &params, Json::Value &result) {
stream->m_next_stream_id = parse_int(section, "next_stream_id", result);
- const Json::Value &pkt = parse_array(section, "packet", result);
+ const Json::Value &pkt = parse_object(section, "packet", result);
+ const Json::Value &pkt_binary = parse_array(pkt, "binary", result);
/* fetch the packet from the message */
- stream->m_pkt_len = pkt.size();
- stream->m_pkt = new uint8_t[pkt.size()];
- if (!stream->m_pkt) {
+ stream->m_pkt.len = pkt_binary.size();
+ stream->m_pkt.binary = new uint8_t[pkt_binary.size()];
+ if (!stream->m_pkt.binary) {
generate_internal_err(result, "unable to allocate memory");
}
/* parse the packet */
- for (int i = 0; i < pkt.size(); i++) {
- stream->m_pkt[i] = parse_byte(pkt, i, result);
+ for (int i = 0; i < pkt_binary.size(); i++) {
+ stream->m_pkt.binary[i] = parse_byte(pkt_binary, i, result);
}
+ /* meta data */
+ stream->m_pkt.meta = parse_string(pkt, "meta", result);
+
/* parse RX info */
const Json::Value &rx = parse_object(section, "rx_stats", result);
@@ -82,7 +86,7 @@ TrexRpcCmdAddStream::_run(const Json::Value &params, Json::Value &result) {
/* make sure this is a valid stream to add */
validate_stream(stream, result);
- TrexStatelessPort *port = get_trex_stateless()->get_port_by_id(stream->m_port_id);
+ TrexStatelessPort *port = TrexStateless::get_instance().get_port_by_id(stream->m_port_id);
port->get_stream_table()->add_stream(stream);
result["result"] = "ACK";
@@ -142,7 +146,7 @@ void
TrexRpcCmdAddStream::validate_stream(const TrexStream *stream, Json::Value &result) {
/* check packet size */
- if ( (stream->m_pkt_len < TrexStream::MIN_PKT_SIZE_BYTES) || (stream->m_pkt_len > TrexStream::MAX_PKT_SIZE_BYTES) ) {
+ if ( (stream->m_pkt.len < TrexStream::MIN_PKT_SIZE_BYTES) || (stream->m_pkt.len > TrexStream::MAX_PKT_SIZE_BYTES) ) {
std::stringstream ss;
ss << "bad packet size provided: should be between " << TrexStream::MIN_PKT_SIZE_BYTES << " and " << TrexStream::MAX_PKT_SIZE_BYTES;
delete stream;
@@ -150,15 +154,15 @@ TrexRpcCmdAddStream::validate_stream(const TrexStream *stream, Json::Value &resu
}
/* port id should be between 0 and count - 1 */
- if (stream->m_port_id >= get_trex_stateless()->get_port_count()) {
+ if (stream->m_port_id >= TrexStateless::get_instance().get_port_count()) {
std::stringstream ss;
- ss << "invalid port id - should be between 0 and " << (int)get_trex_stateless()->get_port_count() - 1;
+ ss << "invalid port id - should be between 0 and " << (int)TrexStateless::get_instance().get_port_count() - 1;
delete stream;
generate_execute_err(result, ss.str());
}
/* add the stream to the port's stream table */
- TrexStatelessPort * port = get_trex_stateless()->get_port_by_id(stream->m_port_id);
+ TrexStatelessPort * port = TrexStateless::get_instance().get_port_by_id(stream->m_port_id);
/* does such a stream exists ? */
if (port->get_stream_table()->get_stream_by_id(stream->m_stream_id)) {
@@ -180,13 +184,13 @@ TrexRpcCmdRemoveStream::_run(const Json::Value &params, Json::Value &result) {
uint32_t stream_id = parse_int(params, "stream_id", result);
- if (port_id >= get_trex_stateless()->get_port_count()) {
+ if (port_id >= TrexStateless::get_instance().get_port_count()) {
std::stringstream ss;
- ss << "invalid port id - should be between 0 and " << (int)get_trex_stateless()->get_port_count() - 1;
+ ss << "invalid port id - should be between 0 and " << (int)TrexStateless::get_instance().get_port_count() - 1;
generate_execute_err(result, ss.str());
}
- TrexStatelessPort *port = get_trex_stateless()->get_port_by_id(port_id);
+ TrexStatelessPort *port = TrexStateless::get_instance().get_port_by_id(port_id);
TrexStream *stream = port->get_stream_table()->get_stream_by_id(stream_id);
if (!stream) {
@@ -198,6 +202,8 @@ TrexRpcCmdRemoveStream::_run(const Json::Value &params, Json::Value &result) {
port->get_stream_table()->remove_stream(stream);
result["result"] = "ACK";
+
+ return (TREX_RPC_CMD_OK);
}
/***************************
@@ -209,15 +215,49 @@ trex_rpc_cmd_rc_e
TrexRpcCmdRemoveAllStreams::_run(const Json::Value &params, Json::Value &result) {
uint8_t port_id = parse_byte(params, "port_id", result);
- if (port_id >= get_trex_stateless()->get_port_count()) {
+ if (port_id >= TrexStateless::get_instance().get_port_count()) {
std::stringstream ss;
- ss << "invalid port id - should be between 0 and " << (int)get_trex_stateless()->get_port_count() - 1;
+ ss << "invalid port id - should be between 0 and " << (int)TrexStateless::get_instance().get_port_count() - 1;
generate_execute_err(result, ss.str());
}
- TrexStatelessPort *port = get_trex_stateless()->get_port_by_id(port_id);
+ TrexStatelessPort *port = TrexStateless::get_instance().get_port_by_id(port_id);
port->get_stream_table()->remove_and_delete_all_streams();
result["result"] = "ACK";
+
+ return (TREX_RPC_CMD_OK);
+}
+
+/***************************
+ * get all streams configured
+ * on specific port
+ *
+ **************************/
+trex_rpc_cmd_rc_e
+TrexRpcCmdGetStreamList::_run(const Json::Value &params, Json::Value &result) {
+ std::vector<uint32_t> stream_list;
+
+ uint8_t port_id = parse_byte(params, "port_id", result);
+
+ if (port_id >= TrexStateless::get_instance().get_port_count()) {
+ std::stringstream ss;
+ ss << "invalid port id - should be between 0 and " << (int)TrexStateless::get_instance().get_port_count() - 1;
+ generate_execute_err(result, ss.str());
+ }
+
+ TrexStatelessPort *port = TrexStateless::get_instance().get_port_by_id(port_id);
+
+ port->get_stream_table()->get_stream_list(stream_list);
+
+ Json::Value json_list = Json::arrayValue;
+
+ for (auto stream_id : stream_list) {
+ json_list.append(stream_id);
+ }
+
+ result["result"] = json_list;
+
+ 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 64551fac..e9666f21 100644
--- a/src/rpc-server/commands/trex_rpc_cmds.h
+++ b/src/rpc-server/commands/trex_rpc_cmds.h
@@ -74,4 +74,6 @@ void validate_stream(const TrexStream *stream, Json::Value &result);
);
+TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStreamList, "get_stream_list", 1);
+
#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 7d5d49ae..fc6d7b87 100644
--- a/src/rpc-server/trex_rpc_cmds_table.cpp
+++ b/src/rpc-server/trex_rpc_cmds_table.cpp
@@ -38,6 +38,7 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() {
register_command(new TrexRpcCmdAddStream());
register_command(new TrexRpcCmdRemoveStream());
register_command(new TrexRpcCmdRemoveAllStreams());
+ register_command(new TrexRpcCmdGetStreamList());
}
TrexRpcCommandsTable::~TrexRpcCommandsTable() {
diff --git a/src/rpc-server/trex_rpc_server.cpp b/src/rpc-server/trex_rpc_server.cpp
index 6b8c200d..149bb668 100644
--- a/src/rpc-server/trex_rpc_server.cpp
+++ b/src/rpc-server/trex_rpc_server.cpp
@@ -111,6 +111,7 @@ get_current_date_time() {
}
const std::string TrexRpcServer::s_server_uptime = get_current_date_time();
+std::string TrexRpcServer::s_owner = "none";
TrexRpcServer::TrexRpcServer(const TrexRpcServerConfig &req_resp_cfg) {
diff --git a/src/rpc-server/trex_rpc_server_api.h b/src/rpc-server/trex_rpc_server_api.h
index ab1bc454..b4313670 100644
--- a/src/rpc-server/trex_rpc_server_api.h
+++ b/src/rpc-server/trex_rpc_server_api.h
@@ -163,10 +163,34 @@ public:
return s_server_uptime;
}
+
+ /**
+ * query for ownership
+ *
+ */
+ static const std::string &get_owner() {
+ return s_owner;
+ }
+
+ /**
+ * take ownership of the server array
+ * this is static
+ * ownership is total
+ *
+ */
+ static void set_owner(const std::string &owner) {
+ s_owner = owner;
+ }
+
+ static void clear_owner() {
+ s_owner = "none";
+ }
+
private:
std::vector<TrexRpcServerInterface *> m_servers;
bool m_verbose;
static const std::string s_server_uptime;
+ static std::string s_owner;
};
#endif /* __TREX_RPC_SERVER_API_H__ */
diff --git a/src/rpc-server/trex_rpc_server_mock.cpp b/src/rpc-server/trex_rpc_server_mock.cpp
index 98d1f35d..a248558e 100644
--- a/src/rpc-server/trex_rpc_server_mock.cpp
+++ b/src/rpc-server/trex_rpc_server_mock.cpp
@@ -20,6 +20,8 @@ limitations under the License.
*/
#include <trex_rpc_server_api.h>
+#include <trex_stateless_api.h>
+
#include <iostream>
#include <unistd.h>
@@ -54,6 +56,9 @@ int main(int argc, char *argv[]) {
cout << "\n-= Starting RPC Server Mock =-\n\n";
cout << "Listening on tcp://localhost:5050 [ZMQ]\n\n";
+ /* configure the stateless object with 4 ports */
+ TrexStateless::configure(4);
+
TrexRpcServerConfig rpc_cfg(TrexRpcServerConfig::RPC_PROT_TCP, 5050);
TrexRpcServer rpc(rpc_cfg);