summaryrefslogtreecommitdiffstats
path: root/src/stateless
diff options
context:
space:
mode:
Diffstat (limited to 'src/stateless')
-rw-r--r--src/stateless/trex_stateless.cpp53
-rw-r--r--src/stateless/trex_stateless_api.h99
-rw-r--r--src/stateless/trex_stream.cpp11
-rw-r--r--src/stateless/trex_stream_api.h24
4 files changed, 163 insertions, 24 deletions
diff --git a/src/stateless/trex_stateless.cpp b/src/stateless/trex_stateless.cpp
index 2ab0c5d9..6a3169d4 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,8 @@ 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_UP_IDLE;
+ clear_owner();
}
@@ -84,25 +87,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 +121,32 @@ 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";
+}
+
+/**
+ * generate a random connection handler
+ *
+ */
+std::string
+TrexStatelessPort::generate_handler() {
+ std::stringstream ss;
+
+ static const char alphanum[] =
+ "0123456789"
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz";
+
+ /* generate 8 bytes of random handler */
+ for (int i = 0; i < 8; ++i) {
+ ss << alphanum[rand() % (sizeof(alphanum) - 1)];
+ }
+
+ return (ss.str());
+}
diff --git a/src/stateless/trex_stateless_api.h b/src/stateless/trex_stateless_api.h
index 358ab339..e02e93da 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,76 @@ 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);
+
+ /**
+ * query for ownership
+ *
+ */
+ const std::string &get_owner() {
+ return m_owner;
+ }
+
+ /**
+ * owner handler
+ * for the connection
+ *
+ */
+ const std::string &get_owner_handler() {
+ return m_owner_handler;
+ }
+
+ bool is_free_to_aquire() {
+ return (m_owner == "none");
+ }
+
+ /**
+ * take ownership of the server array
+ * this is static
+ * ownership is total
+ *
+ */
+ void set_owner(const std::string &owner) {
+ m_owner = owner;
+ m_owner_handler = generate_handler();
+ }
+
+ void clear_owner() {
+ m_owner = "none";
+ m_owner_handler = "";
+ }
+
+ bool verify_owner_handler(const std::string &handler) {
+
+ return ( (m_owner != "none") && (m_owner_handler == handler) );
+
+ }
+
private:
+
+ std::string generate_handler();
+
TrexStreamTable m_stream_table;
uint8_t m_port_id;
- bool m_started;
+ port_state_e m_port_state;
+ std::string m_owner;
+ std::string m_owner_handler;
};
/**
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 26999751..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;
};
/**
@@ -90,15 +100,15 @@ private:
*/
class TrexStreamContinuous : public TrexStream {
public:
- TrexStreamContinuous(uint8_t port_id, uint32_t stream_id, uint32_t pps) : TrexStream(port_id, stream_id), m_pps(pps) {
+ TrexStreamContinuous(uint8_t port_id, uint32_t stream_id, double pps) : TrexStream(port_id, stream_id), m_pps(pps) {
}
- uint32_t get_pps() {
+ double get_pps() {
return m_pps;
}
protected:
- uint32_t m_pps;
+ double m_pps;
};
/**
@@ -107,7 +117,7 @@ protected:
*/
class TrexStreamBurst : public TrexStream {
public:
- TrexStreamBurst(uint8_t port_id, uint32_t stream_id, uint32_t total_pkts, uint32_t pps) :
+ TrexStreamBurst(uint8_t port_id, uint32_t stream_id, uint32_t total_pkts, double pps) :
TrexStream(port_id, stream_id),
m_total_pkts(total_pkts),
m_pps(pps) {
@@ -115,7 +125,7 @@ public:
protected:
uint32_t m_total_pkts;
- uint32_t m_pps;
+ double m_pps;
};
/**
@@ -127,7 +137,7 @@ public:
TrexStreamMultiBurst(uint8_t port_id,
uint32_t stream_id,
uint32_t pkts_per_burst,
- uint32_t pps,
+ double pps,
uint32_t num_bursts,
double ibg_usec) : TrexStreamBurst(port_id, stream_id, pkts_per_burst, pps), m_num_bursts(num_bursts), m_ibg_usec(ibg_usec) {