diff options
Diffstat (limited to 'src/rpc-server')
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_general.cpp | 49 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmds.h | 3 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmds_table.cpp | 3 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_req_resp_server.cpp | 20 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_server.cpp | 3 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_server_api.h | 9 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_zip.cpp | 2 |
7 files changed, 70 insertions, 19 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index 68ea2587..080856c2 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -92,6 +92,32 @@ TrexRpcCmdPing::_run(const Json::Value ¶ms, Json::Value &result) { } /** + * shutdown command + */ +trex_rpc_cmd_rc_e +TrexRpcCmdShutdown::_run(const Json::Value ¶ms, Json::Value &result) { + + const string &user = parse_string(params, "user", result); + bool force = parse_bool(params, "force", result); + + /* verify every port is either free or owned by the issuer */ + for (auto port : get_stateless_obj()->get_port_list()) { + TrexPortOwner &owner = port->get_owner(); + if ( (!owner.is_free()) && (!owner.is_owned_by(user)) && !force) { + std::stringstream ss; + ss << "port " << int(port->get_port_id()) << " is owned by '" << owner.get_name() << "' - specify 'force' for override"; + generate_execute_err(result, ss.str()); + } + } + + /* signal that we got a shutdown request */ + get_stateless_obj()->get_platform_api()->mark_for_shutdown(); + + result["result"] = Json::objectValue; + return (TREX_RPC_CMD_OK); +} + +/** * query command */ trex_rpc_cmd_rc_e @@ -157,6 +183,29 @@ TrexRpcCmdGetActivePGIds::_run(const Json::Value ¶ms, Json::Value &result) { return (TREX_RPC_CMD_OK); } +// get utilization of CPU per thread with up to 20 latest values + mbufs per socket +trex_rpc_cmd_rc_e +TrexRpcCmdGetUtilization::_run(const Json::Value ¶ms, Json::Value &result) { + cpu_util_full_t cpu_util_full; + + Json::Value §ion = result["result"]; + + if (get_stateless_obj()->get_platform_api()->get_mbuf_util(section) != 0) { + return TREX_RPC_CMD_INTERNAL_ERR; + } + + if (get_stateless_obj()->get_platform_api()->get_cpu_util_full(cpu_util_full) != 0) { + return TREX_RPC_CMD_INTERNAL_ERR; + } + + for (int thread_id = 0; thread_id < cpu_util_full.size(); thread_id++) { + for (int history_id = 0; history_id < cpu_util_full[thread_id].size(); history_id++) { + section["cpu"][thread_id].append(cpu_util_full[thread_id][history_id]); + } + } + return (TREX_RPC_CMD_OK); +} + /** * get the CPU model * diff --git a/src/rpc-server/commands/trex_rpc_cmds.h b/src/rpc-server/commands/trex_rpc_cmds.h index affa65c1..24b95227 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -67,6 +67,7 @@ TREX_RPC_CMD_DEFINE(TrexRpcPublishNow, "publish_now", 2, false, TREX_RPC_CMD_DEFINE(TrexRpcCmdGetCmds, "get_supported_cmds", 0, false, APIClass::API_CLASS_TYPE_CORE); TREX_RPC_CMD_DEFINE(TrexRpcCmdGetVersion, "get_version", 0, false, APIClass::API_CLASS_TYPE_CORE); TREX_RPC_CMD_DEFINE(TrexRpcCmdGetActivePGIds, "get_active_pgids", 0, false, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetUtilization, "get_utilization", 0, false, APIClass::API_CLASS_TYPE_CORE); TREX_RPC_CMD_DEFINE_EXTENDED(TrexRpcCmdGetSysInfo, "get_system_info", 0, false, APIClass::API_CLASS_TYPE_CORE, @@ -132,5 +133,7 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdValidate, "validate", 2, false, APIClass::API_CLAS TREX_RPC_CMD_DEFINE(TrexRpcCmdPushRemote, "push_remote", 6, true, APIClass::API_CLASS_TYPE_CORE); +TREX_RPC_CMD_DEFINE(TrexRpcCmdShutdown, "shutdown", 2, false, APIClass::API_CLASS_TYPE_CORE); + #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 7104792e..762dd614 100644 --- a/src/rpc-server/trex_rpc_cmds_table.cpp +++ b/src/rpc-server/trex_rpc_cmds_table.cpp @@ -39,6 +39,7 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() { register_command(new TrexRpcCmdGetCmds()); register_command(new TrexRpcCmdGetVersion()); register_command(new TrexRpcCmdGetActivePGIds()); + register_command(new TrexRpcCmdGetUtilization()); register_command(new TrexRpcCmdGetSysInfo()); register_command(new TrexRpcCmdGetOwner()); register_command(new TrexRpcCmdAcquire()); @@ -66,6 +67,8 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() { register_command(new TrexRpcCmdValidate()); register_command(new TrexRpcCmdPushRemote()); + + register_command(new TrexRpcCmdShutdown()); } diff --git a/src/rpc-server/trex_rpc_req_resp_server.cpp b/src/rpc-server/trex_rpc_req_resp_server.cpp index 033f265c..e0e7635c 100644 --- a/src/rpc-server/trex_rpc_req_resp_server.cpp +++ b/src/rpc-server/trex_rpc_req_resp_server.cpp @@ -56,7 +56,8 @@ void TrexRpcServerReqRes::_rpc_thread_cb() { std::stringstream ss; int zmq_rc; - m_watchdog_handle = m_watchdog->register_monitor(m_name, 1); + m_monitor.create(m_name, 1); + TrexWatchDog::getInstance().register_monitor(&m_monitor); /* create a socket based on the configuration */ @@ -102,7 +103,7 @@ void TrexRpcServerReqRes::_rpc_thread_cb() { zmq_close(m_socket); /* done */ - m_watchdog->disable_monitor(m_watchdog_handle); + m_monitor.disable(); } bool @@ -115,7 +116,7 @@ TrexRpcServerReqRes::fetch_one_request(std::string &msg) { assert(rc == 0); while (true) { - m_watchdog->tickle(m_watchdog_handle); + m_monitor.tickle(); rc = zmq_msg_recv (&zmq_msg, m_socket, 0); if (rc != -1) { @@ -200,23 +201,24 @@ void TrexRpcServerReqRes::process_request_raw(const std::string &request, std::s int index = 0; - /* expcetion safe */ - std::unique_lock<std::mutex> lock(*m_lock); - /* for every command parsed - launch it */ for (auto command : commands) { Json::Value single_response; + /* the command itself should be protected */ + std::unique_lock<std::mutex> lock(*m_lock); command->execute(single_response); + lock.unlock(); + delete command; response_json[index++] = single_response; + /* batch is like getting all the messages one by one - it should not be considered as stuck thread */ + /* need to think if this is a good thing */ + //m_monitor.tickle(); } - /* done with the lock */ - lock.unlock(); - /* write the JSON to string and sever on ZMQ */ if (response.size() == 1) { diff --git a/src/rpc-server/trex_rpc_server.cpp b/src/rpc-server/trex_rpc_server.cpp index e4ca95c3..6c323c16 100644 --- a/src/rpc-server/trex_rpc_server.cpp +++ b/src/rpc-server/trex_rpc_server.cpp @@ -36,8 +36,6 @@ TrexRpcServerInterface::TrexRpcServerInterface(const TrexRpcServerConfig &cfg, c m_name = name; m_lock = cfg.m_lock; - m_watchdog = cfg.m_watchdog; - m_watchdog_handle = -1; m_is_running = false; m_is_verbose = false; @@ -78,7 +76,6 @@ void TrexRpcServerInterface::start() { /* prepare for run */ _prepare(); - m_watchdog->mark_pending_monitor(); m_thread = new std::thread(&TrexRpcServerInterface::_rpc_thread_cb, this); if (!m_thread) { throw TrexRpcException("unable to create RPC thread"); diff --git a/src/rpc-server/trex_rpc_server_api.h b/src/rpc-server/trex_rpc_server_api.h index 3d9837ef..6df37b17 100644 --- a/src/rpc-server/trex_rpc_server_api.h +++ b/src/rpc-server/trex_rpc_server_api.h @@ -30,10 +30,10 @@ limitations under the License. #include <stdexcept> #include <trex_rpc_exception_api.h> #include <json/json.h> +#include "trex_watchdog.h" class TrexRpcServerInterface; class TrexRpcServerReqRes; -class TrexWatchDog; /** * defines a configuration of generic RPC server @@ -48,11 +48,10 @@ public: RPC_PROT_MOCK }; - TrexRpcServerConfig(rpc_prot_e protocol, uint16_t port, std::mutex *lock, TrexWatchDog *watchdog) { + TrexRpcServerConfig(rpc_prot_e protocol, uint16_t port, std::mutex *lock) { m_protocol = protocol; m_port = port; m_lock = lock; - m_watchdog = watchdog; } uint16_t get_port() const { @@ -69,7 +68,6 @@ private: public: std::mutex *m_lock; - TrexWatchDog *m_watchdog; }; /** @@ -142,8 +140,7 @@ protected: std::string m_name; std::mutex *m_lock; std::mutex m_dummy_lock; - TrexWatchDog *m_watchdog; - int m_watchdog_handle; + TrexMonitor m_monitor; }; /** diff --git a/src/rpc-server/trex_rpc_zip.cpp b/src/rpc-server/trex_rpc_zip.cpp index ef5c4834..f6da00ef 100644 --- a/src/rpc-server/trex_rpc_zip.cpp +++ b/src/rpc-server/trex_rpc_zip.cpp @@ -116,7 +116,7 @@ TrexRpcZip::compress(const std::string &input, std::string &output) { header->magic = htonl(G_HEADER_MAGIC); header->uncmp_size = htonl(input.size()); - output.append((const char *)header, bound_size); + output.append((const char *)header, sizeof(header_st) + destLen); delete [] buffer; |