summaryrefslogtreecommitdiffstats
path: root/src/rpc-server/commands/trex_rpc_cmd_general.cpp
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2015-12-13 17:18:02 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2015-12-13 17:18:02 +0200
commit9738e267d806223ee25e013b5959ccac26c1a14a (patch)
tree590c8f329f2ab68c7da3f1f8f4c55f81243a08bc /src/rpc-server/commands/trex_rpc_cmd_general.cpp
parenta573adc6395c9ad8d96978508a07a654ef48c7a9 (diff)
parent301341ddb1bf17387d7fea19667bedd40fce4509 (diff)
Merge branch 'master' into get_logs_and_version
Diffstat (limited to 'src/rpc-server/commands/trex_rpc_cmd_general.cpp')
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_general.cpp103
1 files changed, 71 insertions, 32 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
index ae87d749..a2d4c284 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
@@ -25,11 +25,13 @@ limitations under the License.
#include <trex_stateless_port.h>
#include <trex_rpc_cmds_table.h>
+#include <internal_api/trex_platform_api.h>
+
#include <fstream>
#include <iostream>
#include <unistd.h>
-#ifndef TREX_RPC_MOCK_SERVER
+#ifdef RTE_DPDK
#include <../linux_dpdk/version.h>
#endif
@@ -41,7 +43,7 @@ using namespace std;
trex_rpc_cmd_rc_e
TrexRpcCmdPing::_run(const Json::Value &params, Json::Value &result) {
- result["result"] = "ACK";
+ result["result"] = Json::objectValue;
return (TREX_RPC_CMD_OK);
}
@@ -73,7 +75,7 @@ TrexRpcCmdGetVersion::_run(const Json::Value &params, Json::Value &result) {
Json::Value &section = result["result"];
- #ifndef TREX_RPC_MOCK_SERVER
+ #ifdef RTE_DPDK
section["version"] = VERSION_BUILD_NUM;
section["build_date"] = get_build_date();
@@ -145,7 +147,7 @@ trex_rpc_cmd_rc_e
TrexRpcCmdGetSysInfo::_run(const Json::Value &params, Json::Value &result) {
string hostname;
- TrexStateless & instance = TrexStateless::get_instance();
+ TrexStateless * main = get_stateless_obj();
Json::Value &section = result["result"];
@@ -155,30 +157,46 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value &params, Json::Value &result) {
section["uptime"] = TrexRpcServer::get_server_uptime();
/* FIXME: core count */
- section["dp_core_count"] = instance.get_dp_core_count();
+ section["dp_core_count"] = main->get_dp_core_count();
section["core_type"] = get_cpu_model();
/* ports */
- section["port_count"] = instance.get_port_count();
+ section["port_count"] = main->get_port_count();
section["ports"] = Json::arrayValue;
- for (int i = 0; i < instance.get_port_count(); i++) {
+ for (int i = 0; i < main->get_port_count(); i++) {
string driver;
- string speed;
+ TrexPlatformApi::driver_speed_e speed;
- TrexStatelessPort *port = instance.get_port_by_id(i);
+ TrexStatelessPort *port = main->get_port_by_id(i);
port->get_properties(driver, speed);
section["ports"][i]["index"] = i;
+
section["ports"][i]["driver"] = driver;
- section["ports"][i]["speed"] = speed;
- section["ports"][i]["owner"] = port->get_owner();
+ switch (speed) {
+ case TrexPlatformApi::SPEED_1G:
+ section["ports"][i]["speed"] = 1;
+ break;
+
+ case TrexPlatformApi::SPEED_10G:
+ section["ports"][i]["speed"] = 10;
+ break;
+
+ case TrexPlatformApi::SPEED_40G:
+ section["ports"][i]["speed"] = 40;
+ break;
+
+ default:
+ /* unknown value */
+ section["ports"][i]["speed"] = 0;
+ break;
+ }
- section["ports"][i]["status"] = port->get_state_as_string();
}
@@ -201,8 +219,8 @@ TrexRpcCmdGetOwner::_run(const Json::Value &params, Json::Value &result) {
uint8_t port_id = parse_port(params, result);
- TrexStatelessPort *port = TrexStateless::get_instance().get_port_by_id(port_id);
- section["owner"] = port->get_owner();
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
+ section["owner"] = port->get_owner().get_name();
return (TREX_RPC_CMD_OK);
}
@@ -216,19 +234,19 @@ TrexRpcCmdAcquire::_run(const Json::Value &params, Json::Value &result) {
uint8_t port_id = parse_port(params, result);
- const string &new_owner = parse_string(params, "user", result);
+ const string &new_owner = parse_string(params, "user", result);
bool force = parse_bool(params, "force", result);
/* if not free and not you and not force - fail */
- TrexStatelessPort *port = TrexStateless::get_instance().get_port_by_id(port_id);
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- if ( (!port->is_free_to_aquire()) && (port->get_owner() != new_owner) && (!force)) {
- generate_execute_err(result, "port is already taken by '" + port->get_owner() + "'");
+ try {
+ port->acquire(new_owner, force);
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
}
- port->set_owner(new_owner);
-
- result["result"] = port->get_owner_handler();
+ result["result"] = port->get_owner().get_handler();
return (TREX_RPC_CMD_OK);
}
@@ -242,15 +260,15 @@ TrexRpcCmdRelease::_run(const Json::Value &params, Json::Value &result) {
uint8_t port_id = parse_port(params, result);
- TrexStatelessPort *port = TrexStateless::get_instance().get_port_by_id(port_id);
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- if (port->get_state() == TrexStatelessPort::PORT_STATE_TRANSMITTING) {
- generate_execute_err(result, "cannot release a port during transmission");
+ try {
+ port->release();
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
}
- port->clear_owner();
-
- result["result"] = "ACK";
+ result["result"] = Json::objectValue;
return (TREX_RPC_CMD_OK);
}
@@ -264,15 +282,36 @@ TrexRpcCmdGetPortStats::_run(const Json::Value &params, Json::Value &result) {
uint8_t port_id = parse_port(params, result);
- TrexStatelessPort *port = TrexStateless::get_instance().get_port_by_id(port_id);
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- if (port->get_state() == TrexStatelessPort::PORT_STATE_DOWN) {
- generate_execute_err(result, "cannot get stats - port is down");
+ try {
+ port->encode_stats(result["result"]);
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
}
- result["result"]["status"] = port->get_state_as_string();
+ return (TREX_RPC_CMD_OK);
+}
+
+/**
+ * fetch the port status
+ *
+ * @author imarom (09-Dec-15)
+ *
+ * @param params
+ * @param result
+ *
+ * @return trex_rpc_cmd_rc_e
+ */
+trex_rpc_cmd_rc_e
+TrexRpcCmdGetPortStatus::_run(const Json::Value &params, Json::Value &result) {
+ uint8_t port_id = parse_port(params, result);
+
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
+
+ result["result"]["owner"] = (port->get_owner().is_free() ? "" : port->get_owner().get_name());
+ result["result"]["state"] = port->get_state_as_string();
- port->encode_stats(result["result"]);
return (TREX_RPC_CMD_OK);
}