diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmd_general.cpp | 51 | ||||
-rw-r--r-- | src/rpc-server/commands/trex_rpc_cmds.h | 7 | ||||
-rw-r--r-- | src/rpc-server/trex_rpc_cmds_table.cpp | 1 | ||||
-rw-r--r-- | src/stateless/trex_stateless.cpp | 23 | ||||
-rw-r--r-- | src/stateless/trex_stateless_api.h | 31 |
5 files changed, 95 insertions, 18 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp index 106a167a..0c9f2c49 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp @@ -81,7 +81,7 @@ TrexRpcCmdGetVersion::_run(const Json::Value ¶ms, Json::Value &result) { #else - section["version"] = "v0.0"; + section["version"] = "v1.75"; section["build_date"] = __DATE__; section["build_time"] = __TIME__; section["built_by"] = "MOCK"; @@ -177,19 +177,7 @@ TrexRpcCmdGetSysInfo::_run(const Json::Value ¶ms, Json::Value &result) { section["ports"][i]["owner"] = port->get_owner(); - switch (port->get_state()) { - case TrexStatelessPort::PORT_STATE_DOWN: - section["ports"][i]["status"] = "down"; - break; - - case TrexStatelessPort::PORT_STATE_UP_IDLE: - section["ports"][i]["status"] = "idle"; - break; - - case TrexStatelessPort::PORT_STATE_TRANSMITTING: - section["ports"][i]["status"] = "transmitting"; - break; - } + section["ports"][i]["status"] = port->get_state_as_string(); } @@ -234,7 +222,7 @@ TrexRpcCmdAcquire::_run(const Json::Value ¶ms, Json::Value &result) { TrexStatelessPort *port = TrexStateless::get_instance().get_port_by_id(port_id); if ( (!port->is_free_to_aquire()) && (port->get_owner() != new_owner) && (!force)) { - generate_execute_err(result, "device is already taken by '" + port->get_owner() + "'"); + generate_execute_err(result, "port is already taken by '" + port->get_owner() + "'"); } port->set_owner(new_owner); @@ -265,3 +253,36 @@ TrexRpcCmdRelease::_run(const Json::Value ¶ms, Json::Value &result) { return (TREX_RPC_CMD_OK); } + +/** + * get port stats + * + */ +trex_rpc_cmd_rc_e +TrexRpcCmdGetPortStats::_run(const Json::Value ¶ms, Json::Value &result) { + + uint8_t port_id = parse_port(params, result); + + TrexStatelessPort *port = TrexStateless::get_instance().get_port_by_id(port_id); + + if (port->get_state() == TrexStatelessPort::PORT_STATE_DOWN) { + generate_execute_err(result, "cannot get stats - port is down"); + } + + result["result"]["status"] = port->get_state_as_string(); + + result["result"]["tx_bps"] = Json::Value::UInt64(port->get_port_stats().tx_bps); + result["result"]["tx_pps"] = Json::Value::UInt64(port->get_port_stats().tx_pps); + result["result"]["total_tx_pkts"] = Json::Value::UInt64(port->get_port_stats().total_tx_pkts); + result["result"]["total_tx_bytes"] = Json::Value::UInt64(port->get_port_stats().total_tx_bytes); + + result["result"]["rx_bps"] = Json::Value::UInt64(port->get_port_stats().rx_bps); + result["result"]["rx_pps"] = Json::Value::UInt64(port->get_port_stats().rx_pps); + result["result"]["total_rx_pkts"] = Json::Value::UInt64(port->get_port_stats().total_rx_pkts); + result["result"]["total_rx_bytes"] = Json::Value::UInt64(port->get_port_stats().total_rx_bytes); + + result["result"]["tx_rx_error"] = Json::Value::UInt64(port->get_port_stats().tx_rx_errors); + + 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 e261d1c6..5926a8d8 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -75,6 +75,12 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdRelease, "release", 1, true); /** + * port commands + */ +TREX_RPC_CMD_DEFINE(TrexRpcCmdGetPortStats, "get_port_stats", 1, true); + + +/** * stream cmds */ TREX_RPC_CMD_DEFINE(TrexRpcCmdRemoveAllStreams, "remove_all_streams", 1, true); @@ -100,5 +106,4 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdStartTraffic, "start_traffic", 1, true); TREX_RPC_CMD_DEFINE(TrexRpcCmdStopTraffic, "stop_traffic", 1, true); - #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 170f0de1..c1c546f3 100644 --- a/src/rpc-server/trex_rpc_cmds_table.cpp +++ b/src/rpc-server/trex_rpc_cmds_table.cpp @@ -40,6 +40,7 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() { register_command(new TrexRpcCmdGetOwner()); register_command(new TrexRpcCmdAcquire()); register_command(new TrexRpcCmdRelease()); + register_command(new TrexRpcCmdGetPortStats()); /* stream commands */ register_command(new TrexRpcCmdAddStream()); diff --git a/src/stateless/trex_stateless.cpp b/src/stateless/trex_stateless.cpp index 6a3169d4..0eb96f05 100644 --- a/src/stateless/trex_stateless.cpp +++ b/src/stateless/trex_stateless.cpp @@ -80,6 +80,7 @@ uint8_t TrexStateless::get_port_count() { TrexStatelessPort::TrexStatelessPort(uint8_t port_id) : m_port_id(port_id) { m_port_state = PORT_STATE_UP_IDLE; clear_owner(); + m_stats = {0}; } @@ -121,12 +122,30 @@ TrexStreamTable * TrexStatelessPort::get_stream_table() { return &m_stream_table; } + +std::string +TrexStatelessPort::get_state_as_string() { + + switch (get_state()) { + case PORT_STATE_DOWN: + return "down"; + + case PORT_STATE_UP_IDLE: + return "idle"; + + case PORT_STATE_TRANSMITTING: + return "transmitting"; + } + + return "unknown"; +} + void TrexStatelessPort::get_properties(string &driver, string &speed) { /* take this from DPDK */ - driver = "Unknown Driver"; - speed = "Unknown Speed"; + driver = "e1000"; + speed = "1 Gbps"; } diff --git a/src/stateless/trex_stateless_api.h b/src/stateless/trex_stateless_api.h index e02e93da..7a9080aa 100644 --- a/src/stateless/trex_stateless_api.h +++ b/src/stateless/trex_stateless_api.h @@ -49,6 +49,20 @@ public: class TrexStatelessPort { public: + struct TrexPortStats { + uint64_t tx_pps; + uint64_t tx_bps; + uint64_t total_tx_pkts; + uint64_t total_tx_bytes; + + uint64_t rx_pps; + uint64_t rx_bps; + uint64_t total_rx_pkts; + uint64_t total_rx_bytes; + + uint64_t tx_rx_errors; + }; + /** * port state */ @@ -97,6 +111,12 @@ public: } /** + * port state as string + * + */ + std::string get_state_as_string(); + + /** * fill up properties of the port * * @author imarom (16-Sep-15) @@ -149,6 +169,16 @@ public: } + const TrexPortStats & get_port_stats(void) { + /* scrabble */ + m_stats.tx_bps += 1 + rand() % 100; + m_stats.tx_pps += 1 + rand() % 10; + m_stats.total_tx_bytes += 1 + rand() % 10; + m_stats.total_tx_pkts += 1 + rand() % 5; + + return m_stats; + } + private: std::string generate_handler(); @@ -158,6 +188,7 @@ private: port_state_e m_port_state; std::string m_owner; std::string m_owner_handler; + TrexPortStats m_stats; }; /** |