summaryrefslogtreecommitdiffstats
path: root/src/rpc-server
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-11-09 17:10:24 +0200
committerimarom <imarom@cisco.com>2015-11-09 17:10:24 +0200
commit9c32c36b6006d2a81e1a5658a1fb1616eff650f3 (patch)
tree6c768596aedd26eea82ec22cb61a04da7d8a3304 /src/rpc-server
parent67bcc46be09049d2ca65c0af2aa6a2fe0821eb04 (diff)
moved logic to the port class
also implemented the state machine for CP port
Diffstat (limited to 'src/rpc-server')
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_general.cpp28
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_stream.cpp160
-rw-r--r--src/rpc-server/commands/trex_rpc_cmds.h8
-rw-r--r--src/rpc-server/trex_rpc_cmds_table.cpp3
4 files changed, 150 insertions, 49 deletions
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
index b40e996f..b6d06cfc 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
@@ -222,12 +222,12 @@ TrexRpcCmdAcquire::_run(const Json::Value &params, Json::Value &result) {
/* if not free and not you and not force - fail */
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();
return (TREX_RPC_CMD_OK);
@@ -244,12 +244,12 @@ TrexRpcCmdRelease::_run(const Json::Value &params, Json::Value &result) {
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";
return (TREX_RPC_CMD_OK);
@@ -266,13 +266,13 @@ TrexRpcCmdGetPortStats::_run(const Json::Value &params, Json::Value &result) {
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");
- }
-
result["result"]["status"] = port->get_state_as_string();
- port->encode_stats(result["result"]);
+ try {
+ port->encode_stats(result["result"]);
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
+ }
return (TREX_RPC_CMD_OK);
}
@@ -303,7 +303,7 @@ TrexRpcCmdSyncUser::_run(const Json::Value &params, Json::Value &result) {
owned_port["streams"] = Json::arrayValue;
std::vector <TrexStream *> streams;
- port->get_stream_table()->get_object_list(streams);
+ port->get_object_list(streams);
for (auto stream : streams) {
owned_port["streams"].append(stream->get_stream_json());
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
index 4fa0956d..fffc800a 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
@@ -115,7 +115,12 @@ TrexRpcCmdAddStream::_run(const Json::Value &params, Json::Value &result) {
validate_stream(stream, result);
TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(stream->m_port_id);
- port->get_stream_table()->add_stream(stream);
+
+ try {
+ port->add_stream(stream);
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
+ }
result["result"] = "ACK";
@@ -293,7 +298,7 @@ TrexRpcCmdAddStream::validate_stream(const TrexStream *stream, Json::Value &resu
TrexStatelessPort * port = get_stateless_obj()->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)) {
+ if (port->get_stream_by_id(stream->m_stream_id)) {
std::stringstream ss;
ss << "stream " << stream->m_stream_id << " already exists";
delete stream;
@@ -319,7 +324,7 @@ TrexRpcCmdRemoveStream::_run(const Json::Value &params, Json::Value &result) {
}
TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- TrexStream *stream = port->get_stream_table()->get_stream_by_id(stream_id);
+ TrexStream *stream = port->get_stream_by_id(stream_id);
if (!stream) {
std::stringstream ss;
@@ -327,7 +332,12 @@ TrexRpcCmdRemoveStream::_run(const Json::Value &params, Json::Value &result) {
generate_execute_err(result, ss.str());
}
- port->get_stream_table()->remove_stream(stream);
+ try {
+ port->remove_stream(stream);
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
+ }
+
delete stream;
result["result"] = "ACK";
@@ -350,12 +360,18 @@ TrexRpcCmdRemoveAllStreams::_run(const Json::Value &params, Json::Value &result)
generate_execute_err(result, ss.str());
}
- TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- port->get_stream_table()->remove_and_delete_all_streams();
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- result["result"] = "ACK";
+ try {
+ port->remove_and_delete_all_streams();
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
+ }
- return (TREX_RPC_CMD_OK);
+
+ result["result"] = "ACK";
+
+ return (TREX_RPC_CMD_OK);
}
/***************************
@@ -377,7 +393,7 @@ TrexRpcCmdGetStreamList::_run(const Json::Value &params, Json::Value &result) {
TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- port->get_stream_table()->get_id_list(stream_list);
+ port->get_id_list(stream_list);
Json::Value json_list = Json::arrayValue;
@@ -409,7 +425,7 @@ TrexRpcCmdGetStream::_run(const Json::Value &params, Json::Value &result) {
TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- TrexStream *stream = port->get_stream_table()->get_stream_by_id(stream_id);
+ TrexStream *stream = port->get_stream_by_id(stream_id);
if (!stream) {
std::stringstream ss;
@@ -447,32 +463,19 @@ TrexRpcCmdStartTraffic::_run(const Json::Value &params, Json::Value &result) {
TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- TrexStatelessPort::rc_e rc = port->start_traffic(mul);
-
- if (rc == TrexStatelessPort::RC_OK) {
- result["result"] = "ACK";
- } else {
- std::stringstream ss;
- switch (rc) {
- case TrexStatelessPort::RC_ERR_BAD_STATE_FOR_OP:
- ss << "bad state for operations: port is either transmitting traffic or down";
- break;
- case TrexStatelessPort::RC_ERR_NO_STREAMS:
- ss << "no active streams on that port";
- break;
- default:
- ss << "failed to start traffic";
- break;
- }
-
- generate_execute_err(result, ss.str());
+ try {
+ port->start_traffic(mul);
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
}
- return (TREX_RPC_CMD_OK);
+ result["result"] = "ACK";
+
+ return (TREX_RPC_CMD_OK);
}
/***************************
- * start traffic on port
+ * stop traffic on port
*
**************************/
trex_rpc_cmd_rc_e
@@ -487,7 +490,12 @@ TrexRpcCmdStopTraffic::_run(const Json::Value &params, Json::Value &result) {
TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- port->stop_traffic();
+ try {
+ port->stop_traffic();
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
+ }
+
result["result"] = "ACK";
return (TREX_RPC_CMD_OK);
@@ -511,7 +519,7 @@ TrexRpcCmdGetAllStreams::_run(const Json::Value &params, Json::Value &result) {
TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
std::vector <TrexStream *> streams;
- port->get_stream_table()->get_object_list(streams);
+ port->get_object_list(streams);
Json::Value streams_json = Json::objectValue;
for (auto stream : streams) {
@@ -533,3 +541,89 @@ TrexRpcCmdGetAllStreams::_run(const Json::Value &params, Json::Value &result) {
return (TREX_RPC_CMD_OK);
}
+
+/***************************
+ * pause traffic
+ *
+ **************************/
+trex_rpc_cmd_rc_e
+TrexRpcCmdPauseTraffic::_run(const Json::Value &params, Json::Value &result) {
+
+ uint8_t port_id = parse_byte(params, "port_id", result);
+
+ if (port_id >= get_stateless_obj()->get_port_count()) {
+ std::stringstream ss;
+ ss << "invalid port id - should be between 0 and " << (int)get_stateless_obj()->get_port_count() - 1;
+ generate_execute_err(result, ss.str());
+ }
+
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
+
+ try {
+ port->pause_traffic();
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
+ }
+
+ result["result"] = "ACK";
+
+ return (TREX_RPC_CMD_OK);
+}
+
+/***************************
+ * resume traffic
+ *
+ **************************/
+trex_rpc_cmd_rc_e
+TrexRpcCmdResumeTraffic::_run(const Json::Value &params, Json::Value &result) {
+
+ uint8_t port_id = parse_byte(params, "port_id", result);
+
+ if (port_id >= get_stateless_obj()->get_port_count()) {
+ std::stringstream ss;
+ ss << "invalid port id - should be between 0 and " << (int)get_stateless_obj()->get_port_count() - 1;
+ generate_execute_err(result, ss.str());
+ }
+
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
+
+ try {
+ port->resume_traffic();
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
+ }
+
+ result["result"] = "ACK";
+
+ return (TREX_RPC_CMD_OK);
+}
+
+/***************************
+ * update traffic
+ *
+ **************************/
+trex_rpc_cmd_rc_e
+TrexRpcCmdUpdateTraffic::_run(const Json::Value &params, Json::Value &result) {
+
+ uint8_t port_id = parse_byte(params, "port_id", result);
+ double mul = parse_double(params, "mul", result);
+
+ if (port_id >= get_stateless_obj()->get_port_count()) {
+ std::stringstream ss;
+ ss << "invalid port id - should be between 0 and " << (int)get_stateless_obj()->get_port_count() - 1;
+ generate_execute_err(result, ss.str());
+ }
+
+ TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
+
+ try {
+ port->update_traffic(mul);
+ } catch (const TrexRpcException &ex) {
+ generate_execute_err(result, ex.what());
+ }
+
+ result["result"] = "ACK";
+
+ 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 a604d9a1..8b173cb9 100644
--- a/src/rpc-server/commands/trex_rpc_cmds.h
+++ b/src/rpc-server/commands/trex_rpc_cmds.h
@@ -105,8 +105,12 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStream, "get_stream", 3, true);
-TREX_RPC_CMD_DEFINE(TrexRpcCmdStartTraffic, "start_traffic", 2, true);
-TREX_RPC_CMD_DEFINE(TrexRpcCmdStopTraffic, "stop_traffic", 1, true);
+TREX_RPC_CMD_DEFINE(TrexRpcCmdStartTraffic, "start_traffic", 2, true);
+TREX_RPC_CMD_DEFINE(TrexRpcCmdStopTraffic, "stop_traffic", 1, true);
+TREX_RPC_CMD_DEFINE(TrexRpcCmdPauseTraffic, "pause_traffic", 1, true);
+TREX_RPC_CMD_DEFINE(TrexRpcCmdResumeTraffic, "resume_traffic", 1, true);
+
+TREX_RPC_CMD_DEFINE(TrexRpcCmdUpdateTraffic, "update_traffic", 1, true);
TREX_RPC_CMD_DEFINE(TrexRpcCmdSyncUser, "sync_user", 2, false);
diff --git a/src/rpc-server/trex_rpc_cmds_table.cpp b/src/rpc-server/trex_rpc_cmds_table.cpp
index e3bd7848..f38b4df4 100644
--- a/src/rpc-server/trex_rpc_cmds_table.cpp
+++ b/src/rpc-server/trex_rpc_cmds_table.cpp
@@ -51,8 +51,11 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() {
register_command(new TrexRpcCmdGetStreamList());
register_command(new TrexRpcCmdGetStream());
register_command(new TrexRpcCmdGetAllStreams());
+
register_command(new TrexRpcCmdStartTraffic());
register_command(new TrexRpcCmdStopTraffic());
+ register_command(new TrexRpcCmdPauseTraffic());
+ register_command(new TrexRpcCmdResumeTraffic());
}
TrexRpcCommandsTable::~TrexRpcCommandsTable() {