summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/gtest/rpc_test.cpp94
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_general.cpp1
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_stream.cpp3
-rw-r--r--src/stateless/trex_stateless.cpp2
4 files changed, 86 insertions, 14 deletions
diff --git a/src/gtest/rpc_test.cpp b/src/gtest/rpc_test.cpp
index 58197000..015da2f8 100644
--- a/src/gtest/rpc_test.cpp
+++ b/src/gtest/rpc_test.cpp
@@ -113,9 +113,11 @@ public:
class RpcTestOwned : public RpcTest {
public:
- void create_request(Json::Value &request, const string &method, int id = 1) {
+ void create_request(Json::Value &request, const string &method, int id = 1, bool owned = true) {
RpcTest::create_request(request, method, id);
- request["params"]["handler"] = m_ownership_handler;
+ if (owned) {
+ request["params"]["handler"] = m_ownership_handler;
+ }
}
protected:
@@ -212,7 +214,6 @@ TEST_F(RpcTest, basic_rpc_negative_cases) {
TEST_F(RpcTest, test_add_command) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
/* missing parameters */
create_request(request, "test_add");
@@ -305,7 +306,6 @@ TEST_F(RpcTest, batch_rpc_test) {
TEST_F(RpcTest, ping) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
create_request(request, "ping");
send_request(request, response);
@@ -327,7 +327,6 @@ find_member_in_array(const Json::Value &array, const string &member) {
TEST_F(RpcTest, get_supported_cmds) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
create_request(request, "get_supported_cmds");
send_request(request, response);
@@ -341,7 +340,6 @@ TEST_F(RpcTest, get_supported_cmds) {
TEST_F(RpcTest, get_version) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
create_request(request, "get_version");
send_request(request, response);
@@ -355,7 +353,6 @@ TEST_F(RpcTest, get_version) {
TEST_F(RpcTest, get_system_info) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
create_request(request, "get_system_info");
send_request(request, response);
@@ -383,7 +380,6 @@ TEST_F(RpcTest, get_system_info) {
TEST_F(RpcTest, get_owner_acquire_release) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
/* no user before acquring */
create_request(request, "get_owner");
@@ -465,7 +461,6 @@ compare_streams(const Json::Value &s1, const Json::Value &s2) {
TEST_F(RpcTestOwned, add_remove_stream) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
/* verify no such stream */
create_request(request, "get_stream", 1);
@@ -523,14 +518,11 @@ TEST_F(RpcTestOwned, add_remove_stream) {
TEST_F(RpcTestOwned, get_stream_id_list) {
Json::Value request;
Json::Value response;
- Json::Reader reader;
-
/* add stream 1 */
create_request(request, "add_stream");
request["params"]["port_id"] = 1;
-
Json::Value stream;
create_simple_stream(stream);
@@ -579,3 +571,81 @@ TEST_F(RpcTestOwned, get_stream_id_list) {
EXPECT_TRUE(response["result"].isArray());
EXPECT_TRUE(response["result"].size() == 0);
}
+
+
+TEST_F(RpcTestOwned, start_stop_traffic) {
+ Json::Value request;
+ Json::Value response;
+
+ /* add stream #1 */
+ create_request(request, "add_stream");
+ request["params"]["port_id"] = 1;
+ request["params"]["stream_id"] = 5;
+
+ Json::Value stream;
+ create_simple_stream(stream);
+
+ request["params"]["stream"] = stream;
+
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* add stream #1 */
+ create_request(request, "add_stream");
+ request["params"]["port_id"] = 3;
+ request["params"]["stream_id"] = 12;
+ request["params"]["stream"] = stream;
+
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* start port 1 */
+ create_request(request, "start_traffic");
+ request["params"]["port_id"] = 1;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+
+ /* start port 3 */
+ request["params"]["port_id"] = 3;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* start not configured port */
+
+ request["params"]["port_id"] = 2;
+ send_request(request, response);
+ EXPECT_EQ(response["error"]["code"], -32000);
+
+ /* stop port 1 */
+ create_request(request, "stop_traffic");
+ request["params"]["port_id"] = 1;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* stop port 3 */
+ request["params"]["port_id"] = 3;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* start 1 again */
+ create_request(request, "start_traffic");
+ request["params"]["port_id"] = 1;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+
+ /* start 1 twice (error) */
+ send_request(request, response);
+ EXPECT_EQ(response["error"]["code"], -32000);
+
+ /* make sure you cannot release while traffic is active */
+ //create_request(request, "release");
+ //send_request(request, response);
+ //EXPECT_EQ(response["error"]["code"], -32000);
+
+ /* done */
+ create_request(request, "stop_traffic");
+ request["params"]["port_id"] = 1;
+ send_request(request, response);
+ EXPECT_EQ(response["result"], "ACK");
+}
diff --git a/src/rpc-server/commands/trex_rpc_cmd_general.cpp b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
index fcdb7acf..97ccae06 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_general.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_general.cpp
@@ -241,6 +241,7 @@ TrexRpcCmdAcquire::_run(const Json::Value &params, Json::Value &result) {
*/
trex_rpc_cmd_rc_e
TrexRpcCmdRelease::_run(const Json::Value &params, Json::Value &result) {
+
TrexRpcServer::clear_owner();
result["result"] = "ACK";
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
index 41567509..1450e1a9 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
@@ -429,7 +429,8 @@ TrexRpcCmdGetStream::_run(const Json::Value &params, Json::Value &result) {
**************************/
trex_rpc_cmd_rc_e
TrexRpcCmdStartTraffic::_run(const Json::Value &params, Json::Value &result) {
- uint8_t port_id = parse_byte(params, "port_id", result);
+
+ uint8_t port_id = parse_byte(params, "port_id", result);
if (port_id >= TrexStateless::get_instance().get_port_count()) {
std::stringstream ss;
diff --git a/src/stateless/trex_stateless.cpp b/src/stateless/trex_stateless.cpp
index 537dfa4a..dcad1514 100644
--- a/src/stateless/trex_stateless.cpp
+++ b/src/stateless/trex_stateless.cpp
@@ -78,7 +78,7 @@ uint8_t TrexStateless::get_port_count() {
*
**************************/
TrexStatelessPort::TrexStatelessPort(uint8_t port_id) : m_port_id(port_id) {
- m_port_state = PORT_STATE_DOWN;
+ m_port_state = PORT_STATE_UP_IDLE;
}