summaryrefslogtreecommitdiffstats
path: root/src/stateless
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-09-06 15:23:40 +0300
committerimarom <imarom@cisco.com>2015-09-06 15:23:40 +0300
commitc625b6e4f6d71176ef1db5aab93f4e66939d7a25 (patch)
tree25527fa0156bb95434fbd653e938acf986da9636 /src/stateless
parentea30ab5d1165707ffb1297dabf2b24ecbd5d39a5 (diff)
trex stateless changed to singleton.
added some more commands (remove all, get list of streams)
Diffstat (limited to 'src/stateless')
-rw-r--r--src/stateless/trex_stateless.cpp32
-rw-r--r--src/stateless/trex_stateless_api.h40
-rw-r--r--src/stateless/trex_stream.cpp16
-rw-r--r--src/stateless/trex_stream_api.h18
4 files changed, 80 insertions, 26 deletions
diff --git a/src/stateless/trex_stateless.cpp b/src/stateless/trex_stateless.cpp
index 05931983..ff469d7e 100644
--- a/src/stateless/trex_stateless.cpp
+++ b/src/stateless/trex_stateless.cpp
@@ -24,13 +24,30 @@ limitations under the License.
* Trex stateless object
*
**********************************************************/
-TrexStateless::TrexStateless(uint8_t port_count) : m_port_count(port_count) {
+TrexStateless::TrexStateless() {
+ m_is_configured = false;
+}
- m_ports = new TrexStatelessPort*[port_count];
+/**
+ * one time configuration of the stateless object
+ *
+ */
+void TrexStateless::configure(uint8_t port_count) {
- for (int i = 0; i < m_port_count; i++) {
- m_ports[i] = new TrexStatelessPort(i);
+ TrexStateless& instance = get_instance_internal();
+
+ if (instance.m_is_configured) {
+ throw TrexException("re-configuration of stateless object is not allowed");
}
+
+ instance.m_port_count = port_count;
+ instance.m_ports = new TrexStatelessPort*[port_count];
+
+ for (int i = 0; i < instance.m_port_count; i++) {
+ instance.m_ports[i] = new TrexStatelessPort(i);
+ }
+
+ instance.m_is_configured = true;
}
TrexStateless::~TrexStateless() {
@@ -54,10 +71,3 @@ uint8_t TrexStateless::get_port_count() {
return m_port_count;
}
-/******** HACK - REMOVE ME ***********/
-TrexStateless * get_trex_stateless() {
- static TrexStateless trex_stateless(8);
- return &trex_stateless;
-
-}
-
diff --git a/src/stateless/trex_stateless_api.h b/src/stateless/trex_stateless_api.h
index 6406a946..edd7b051 100644
--- a/src/stateless/trex_stateless_api.h
+++ b/src/stateless/trex_stateless_api.h
@@ -71,26 +71,48 @@ private:
*/
class TrexStateless {
public:
+
/**
- * create a T-Rex stateless object
- *
- * @author imarom (31-Aug-15)
+ * configure the stateless object singelton
+ * reconfiguration is not allowed
+ * an exception will be thrown
+ */
+ static void configure(uint8_t port_count);
+
+ /**
+ * singleton public get instance
*
- * @param port_count
*/
- TrexStateless(uint8_t port_count);
- ~TrexStateless();
+ static TrexStateless& get_instance() {
+ TrexStateless& instance = get_instance_internal();
+
+ if (!instance.m_is_configured) {
+ throw TrexException("object is not configured");
+ }
+
+ return instance;
+ }
TrexStatelessPort *get_port_by_id(uint8_t port_id);
uint8_t get_port_count();
protected:
+ TrexStateless();
+ ~TrexStateless();
+
+ static TrexStateless& get_instance_internal () {
+ static TrexStateless instance;
+ return instance;
+ }
+
+ /* c++ 2011 style singleton */
+ TrexStateless(TrexStateless const&) = delete;
+ void operator=(TrexStateless const&) = delete;
+
+ bool m_is_configured;
TrexStatelessPort **m_ports;
uint8_t m_port_count;
};
-/****** HACK *******/
-TrexStateless *get_trex_stateless();
-
#endif /* __TREX_STATELESS_API_H__ */
diff --git a/src/stateless/trex_stream.cpp b/src/stateless/trex_stream.cpp
index 1465b1ba..b3919770 100644
--- a/src/stateless/trex_stream.cpp
+++ b/src/stateless/trex_stream.cpp
@@ -32,16 +32,16 @@ TrexStream::TrexStream(uint8_t port_id, uint32_t stream_id) : m_port_id(port_id)
m_enabled = false;
m_self_start = false;
- m_pkt = NULL;
- m_pkt_len = 0;
+ m_pkt.binary = NULL;
+ m_pkt.len = 0;
m_rx_check.m_enable = false;
}
TrexStream::~TrexStream() {
- if (m_pkt) {
- delete [] m_pkt;
+ if (m_pkt.binary) {
+ delete [] m_pkt.binary;
}
}
@@ -91,3 +91,11 @@ TrexStream * TrexStreamTable::get_stream_by_id(uint32_t stream_id) {
return NULL;
}
}
+
+void TrexStreamTable::get_stream_list(std::vector<uint32_t> &stream_list) {
+ stream_list.clear();
+
+ for (auto stream : m_stream_table) {
+ stream_list.push_back(stream.first);
+ }
+}
diff --git a/src/stateless/trex_stream_api.h b/src/stateless/trex_stream_api.h
index f57b7aae..97e0b7f7 100644
--- a/src/stateless/trex_stream_api.h
+++ b/src/stateless/trex_stream_api.h
@@ -22,7 +22,9 @@ limitations under the License.
#define __TREX_STREAM_API_H__
#include <unordered_map>
+#include <vector>
#include <stdint.h>
+#include <string>
class TrexRpcCmdAddStream;
@@ -58,8 +60,11 @@ private:
bool m_self_start;
/* pkt */
- uint8_t *m_pkt;
- uint16_t m_pkt_len;
+ struct {
+ uint8_t *binary;
+ uint16_t len;
+ std::string meta;
+ } m_pkt;
/* VM */
@@ -157,6 +162,15 @@ public:
*/
TrexStream * get_stream_by_id(uint32_t stream_id);
+ /**
+ * populate a list with all the stream IDs
+ *
+ * @author imarom (06-Sep-15)
+ *
+ * @param stream_list
+ */
+ void get_stream_list(std::vector<uint32_t> &stream_list);
+
private:
/**
* holds all the stream in a hash table by stream id