summaryrefslogtreecommitdiffstats
path: root/src/stateless
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-09-16 16:22:48 +0300
committerimarom <imarom@cisco.com>2015-09-16 16:22:48 +0300
commitdd99c3890d3bb7b4aab833927e85648cd6e86c85 (patch)
tree35712a3a46eab3cde24fbe06ca6426ed351e0e41 /src/stateless
parent54f8323b3938bf4ab672cde01a06711bfc522a2e (diff)
added many tests to the RPC server
also, few tweaks for handling RPC server errors
Diffstat (limited to 'src/stateless')
-rw-r--r--src/stateless/trex_stateless.cpp30
-rw-r--r--src/stateless/trex_stateless_api.h51
-rw-r--r--src/stateless/trex_stream.cpp11
-rw-r--r--src/stateless/trex_stream_api.h12
4 files changed, 86 insertions, 18 deletions
diff --git a/src/stateless/trex_stateless.cpp b/src/stateless/trex_stateless.cpp
index 2ab0c5d9..b51c4e69 100644
--- a/src/stateless/trex_stateless.cpp
+++ b/src/stateless/trex_stateless.cpp
@@ -20,6 +20,8 @@ limitations under the License.
*/
#include <trex_stateless_api.h>
+using namespace std;
+
/***********************************************************
* Trex stateless object
*
@@ -76,7 +78,7 @@ uint8_t TrexStateless::get_port_count() {
*
**************************/
TrexStatelessPort::TrexStatelessPort(uint8_t port_id) : m_port_id(port_id) {
- m_started = false;
+ m_port_state = PORT_STATE_DOWN;
}
@@ -84,25 +86,29 @@ TrexStatelessPort::TrexStatelessPort(uint8_t port_id) : m_port_id(port_id) {
* starts the traffic on the port
*
*/
-TrexStatelessPort::traffic_rc_e
+TrexStatelessPort::rc_e
TrexStatelessPort::start_traffic(void) {
- if (m_started) {
- return (TRAFFIC_ERR_ALREADY_STARTED);
+
+ if (m_port_state != PORT_STATE_UP_IDLE) {
+ return (RC_ERR_BAD_STATE_FOR_OP);
}
if (get_stream_table()->size() == 0) {
- return (TRAFFIC_ERR_NO_STREAMS);
+ return (RC_ERR_NO_STREAMS);
}
- m_started = true;
+ m_port_state = PORT_STATE_TRANSMITTING;
- return (TRAFFIC_OK);
+ /* real code goes here */
+ return (RC_OK);
}
void
TrexStatelessPort::stop_traffic(void) {
- if (m_started) {
- m_started = false;
+
+ /* real code goes here */
+ if (m_port_state = PORT_STATE_TRANSMITTING) {
+ m_port_state = PORT_STATE_UP_IDLE;
}
}
@@ -114,4 +120,10 @@ TrexStreamTable * TrexStatelessPort::get_stream_table() {
return &m_stream_table;
}
+void
+TrexStatelessPort::get_properties(string &driver, string &speed) {
+ /* take this from DPDK */
+ driver = "Unknown Driver";
+ speed = "Unknown Speed";
+}
diff --git a/src/stateless/trex_stateless_api.h b/src/stateless/trex_stateless_api.h
index 358ab339..60d26878 100644
--- a/src/stateless/trex_stateless_api.h
+++ b/src/stateless/trex_stateless_api.h
@@ -50,19 +50,36 @@ class TrexStatelessPort {
public:
/**
- * describess error codes for starting traffic
+ * port state
*/
- enum traffic_rc_e {
- TRAFFIC_OK,
- TRAFFIC_ERR_ALREADY_STARTED,
- TRAFFIC_ERR_NO_STREAMS,
- TRAFFIC_ERR_FAILED_TO_COMPILE_STREAMS
+ enum port_state_e {
+ PORT_STATE_DOWN,
+ PORT_STATE_UP_IDLE,
+ PORT_STATE_TRANSMITTING
+ };
+
+ /**
+ * describess different error codes for port operations
+ */
+ enum rc_e {
+ RC_OK,
+ RC_ERR_BAD_STATE_FOR_OP,
+ RC_ERR_NO_STREAMS,
+ RC_ERR_FAILED_TO_COMPILE_STREAMS
};
TrexStatelessPort(uint8_t port_id);
- traffic_rc_e start_traffic(void);
+ /**
+ * start traffic
+ *
+ */
+ rc_e start_traffic(void);
+ /**
+ * stop traffic
+ *
+ */
void stop_traffic(void);
/**
@@ -71,10 +88,28 @@ public:
*/
TrexStreamTable *get_stream_table();
+ /**
+ * get the port state
+ *
+ */
+ port_state_e get_state() {
+ return m_port_state;
+ }
+
+ /**
+ * fill up properties of the port
+ *
+ * @author imarom (16-Sep-15)
+ *
+ * @param driver
+ * @param speed
+ */
+ void get_properties(std::string &driver, std::string &speed);
+
private:
TrexStreamTable m_stream_table;
uint8_t m_port_id;
- bool m_started;
+ port_state_e m_port_state;
};
/**
diff --git a/src/stateless/trex_stream.cpp b/src/stateless/trex_stream.cpp
index 2b5b2424..8bf04748 100644
--- a/src/stateless/trex_stream.cpp
+++ b/src/stateless/trex_stream.cpp
@@ -45,6 +45,17 @@ TrexStream::~TrexStream() {
}
}
+void
+TrexStream::store_stream_json(const Json::Value &stream_json) {
+ /* deep copy */
+ m_stream_json = stream_json;
+}
+
+const Json::Value &
+TrexStream::get_stream_json() {
+ return m_stream_json;
+}
+
/**************************************
* stream table
*************************************/
diff --git a/src/stateless/trex_stream_api.h b/src/stateless/trex_stream_api.h
index 0a955ff7..d3c0fb29 100644
--- a/src/stateless/trex_stream_api.h
+++ b/src/stateless/trex_stream_api.h
@@ -26,6 +26,8 @@ limitations under the License.
#include <stdint.h>
#include <string>
+#include <json/json.h>
+
#include <trex_stream_vm.h>
class TrexRpcCmdAddStream;
@@ -48,7 +50,13 @@ public:
static const uint32_t MIN_PKT_SIZE_BYTES = 1;
static const uint32_t MAX_PKT_SIZE_BYTES = 9000;
-private:
+ /* provides storage for the stream json*/
+ void store_stream_json(const Json::Value &stream_json);
+
+ /* access the stream json */
+ const Json::Value & get_stream_json();
+
+protected:
/* basic */
uint8_t m_port_id;
uint32_t m_stream_id;
@@ -82,6 +90,8 @@ private:
} m_rx_check;
+ /* original template provided by requester */
+ Json::Value m_stream_json;
};
/**