From c17add108ead1ffbdf0c909684c5f8b18632f3d8 Mon Sep 17 00:00:00 2001 From: imarom Date: Tue, 1 Sep 2015 17:16:27 +0300 Subject: draft --- src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 45 +++++++++++++++++++++++-- src/rpc-server/commands/trex_rpc_cmd_test.cpp | 8 +---- src/rpc-server/commands/trex_rpc_cmds.h | 3 +- src/rpc-server/trex_rpc_cmds_table.cpp | 1 + src/stateless/trex_stream.cpp | 10 ++++++ src/stateless/trex_stream_api.h | 9 +++-- 6 files changed, 63 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index 57fa23d4..cda917ac 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -28,10 +28,10 @@ limitations under the License. using namespace std; -/** +/*************************** * add new stream * - */ + **************************/ trex_rpc_cmd_rc_e TrexRpcCmdAddStream::_run(const Json::Value ¶ms, Json::Value &result) { @@ -63,10 +63,23 @@ TrexRpcCmdAddStream::_run(const Json::Value ¶ms, Json::Value &result) { 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); } + /* parse RX info */ + const Json::Value &rx = parse_object(section, "rx_stats", result); + + stream->m_rx_check.m_enable = parse_bool(rx, "enabled", result); + + /* if it is enabled - we need more fields */ + if (stream->m_rx_check.m_enable) { + stream->m_rx_check.m_stream_id = parse_int(rx, "stream_id", result); + stream->m_rx_check.m_seq_enabled = parse_bool(rx, "seq_enabled", result); + stream->m_rx_check.m_latency = parse_bool(rx, "latency", result); + } + /* make sure this is a valid stream to add */ validate_stream(stream, result); @@ -117,6 +130,7 @@ TrexRpcCmdAddStream::allocate_new_stream(const Json::Value §ion, Json::Value generate_parse_err(result, "bad stream type provided: '" + type + "'"); } + /* make sure we were able to allocate the memory */ if (!stream) { generate_internal_err(result, "unable to allocate memory"); } @@ -157,6 +171,10 @@ TrexRpcCmdAddStream::validate_stream(const TrexStream *stream, Json::Value &resu } +/*************************** + * remove stream + * + **************************/ trex_rpc_cmd_rc_e TrexRpcCmdRemoveStream::_run(const Json::Value ¶ms, Json::Value &result) { uint8_t port_id = parse_byte(params, "port_id", result); @@ -170,7 +188,7 @@ TrexRpcCmdRemoveStream::_run(const Json::Value ¶ms, Json::Value &result) { } TrexStatelessPort *port = get_trex_stateless()->get_port_by_id(port_id); - TrexStream *stream = port->get_stream_table()->get_stream_by_id(stream_id); + TrexStream *stream = port->get_stream_table()->get_stream_by_id(stream_id); if (!stream) { std::stringstream ss; @@ -183,3 +201,24 @@ TrexRpcCmdRemoveStream::_run(const Json::Value ¶ms, Json::Value &result) { result["result"] = "ACK"; } +/*************************** + * remove all streams + * for a port + * + **************************/ +trex_rpc_cmd_rc_e +TrexRpcCmdRemoveAllStreams::_run(const Json::Value ¶ms, Json::Value &result) { + uint8_t port_id = parse_byte(params, "port_id", result); + + if (port_id >= get_trex_stateless()->get_port_count()) { + std::stringstream ss; + ss << "invalid port id - should be between 0 and " << (int)get_trex_stateless()->get_port_count() - 1; + generate_execute_err(result, ss.str()); + } + + TrexStatelessPort *port = get_trex_stateless()->get_port_by_id(port_id); + port->get_stream_table()->remove_and_delete_all_streams(); + + result["result"] = "ACK"; +} + diff --git a/src/rpc-server/commands/trex_rpc_cmd_test.cpp b/src/rpc-server/commands/trex_rpc_cmd_test.cpp index 382279ba..3153317e 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_test.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_test.cpp @@ -32,11 +32,8 @@ using namespace std; trex_rpc_cmd_rc_e TrexRpcCmdTestAdd::_run(const Json::Value ¶ms, Json::Value &result) { - const Json::Value &x = params["x"]; - const Json::Value &y = params["y"]; - result["result"] = parse_int(params, "x", result) + parse_int(params, "y", result); - + return (TREX_RPC_CMD_OK); } @@ -48,9 +45,6 @@ TrexRpcCmdTestAdd::_run(const Json::Value ¶ms, Json::Value &result) { trex_rpc_cmd_rc_e TrexRpcCmdTestSub::_run(const Json::Value ¶ms, Json::Value &result) { - const Json::Value &x = params["x"]; - const Json::Value &y = params["y"]; - result["result"] = parse_int(params, "x", result) - parse_int(params, "y", result); 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 7ec8aba3..64551fac 100644 --- a/src/rpc-server/commands/trex_rpc_cmds.h +++ b/src/rpc-server/commands/trex_rpc_cmds.h @@ -62,7 +62,8 @@ TREX_RPC_CMD_DEFINE(TrexRpcCmdGetStatus, "get_status", 0); /** * stream cmds */ -TREX_RPC_CMD_DEFINE(TrexRpcCmdRemoveStream, "remove_stream", 2); +TREX_RPC_CMD_DEFINE(TrexRpcCmdRemoveAllStreams, "remove_all_streams", 1); +TREX_RPC_CMD_DEFINE(TrexRpcCmdRemoveStream, "remove_stream", 2); TREX_RPC_CMD_DEFINE_EXTENED(TrexRpcCmdAddStream, "add_stream", 1, diff --git a/src/rpc-server/trex_rpc_cmds_table.cpp b/src/rpc-server/trex_rpc_cmds_table.cpp index e586c3d6..7d5d49ae 100644 --- a/src/rpc-server/trex_rpc_cmds_table.cpp +++ b/src/rpc-server/trex_rpc_cmds_table.cpp @@ -37,6 +37,7 @@ TrexRpcCommandsTable::TrexRpcCommandsTable() { /* stream commands */ register_command(new TrexRpcCmdAddStream()); register_command(new TrexRpcCmdRemoveStream()); + register_command(new TrexRpcCmdRemoveAllStreams()); } TrexRpcCommandsTable::~TrexRpcCommandsTable() { diff --git a/src/stateless/trex_stream.cpp b/src/stateless/trex_stream.cpp index 5bc9421f..1465b1ba 100644 --- a/src/stateless/trex_stream.cpp +++ b/src/stateless/trex_stream.cpp @@ -72,6 +72,16 @@ void TrexStreamTable::remove_stream(TrexStream *stream) { m_stream_table.erase(stream->m_stream_id); } + +void TrexStreamTable::remove_and_delete_all_streams() { + + for (auto stream : m_stream_table) { + delete stream.second; + } + + m_stream_table.clear(); +} + TrexStream * TrexStreamTable::get_stream_by_id(uint32_t stream_id) { auto search = m_stream_table.find(stream_id); diff --git a/src/stateless/trex_stream_api.h b/src/stateless/trex_stream_api.h index bae82862..f57b7aae 100644 --- a/src/stateless/trex_stream_api.h +++ b/src/stateless/trex_stream_api.h @@ -66,7 +66,7 @@ private: /* RX check */ struct { bool m_enable; - bool m_seq_enable; + bool m_seq_enabled; bool m_latency; uint32_t m_stream_id; @@ -141,10 +141,15 @@ public: /** * remove a stream - * */ void remove_stream(TrexStream *stream); + /** + * remove all streams on the table + * memory will be deleted + */ + void remove_and_delete_all_streams(); + /** * fetch a stream if exists * o.w NULL -- cgit 1.2.3-korg