summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mock/trex_rpc_server_mock.cpp25
-rw-r--r--src/rpc-server/commands/trex_rpc_cmd_stream.cpp2
-rw-r--r--src/stateless/cp/trex_stateless_port.cpp19
-rw-r--r--src/stateless/cp/trex_stream.cpp63
-rw-r--r--src/stateless/cp/trex_stream.h39
-rw-r--r--src/stateless/dp/trex_stateless_dp_core.cpp4
-rw-r--r--src/stateless/messaging/trex_stateless_messaging.cpp2
7 files changed, 60 insertions, 94 deletions
diff --git a/src/mock/trex_rpc_server_mock.cpp b/src/mock/trex_rpc_server_mock.cpp
index 6642e50e..8bbcbf5b 100644
--- a/src/mock/trex_rpc_server_mock.cpp
+++ b/src/mock/trex_rpc_server_mock.cpp
@@ -21,12 +21,16 @@ limitations under the License.
#include <trex_rpc_server_api.h>
#include <trex_stateless.h>
+#include <trex_stateless_dp_core.h>
+
+#include <msg_manager.h>
#include <iostream>
#include <sstream>
#include <unistd.h>
#include <string.h>
#include <zmq.h>
+#include <bp_sim.h>
using namespace std;
@@ -123,9 +127,30 @@ static bool parse_uint16(const string arg, uint16_t &port) {
return (x);
}
+static void
+run_dummy_core() {
+ //TODO: connect this to the scheduler
+
+ //CFlowGenList fl;
+ //fl.Create();
+ //CFlowGenListPerThread *lp = new CFlowGenListPerThread();
+ //lp->Create(0, 0, NULL, 0);
+ //TrexStatelessDpCore dummy_core(0, lp);
+ //lp->start_stateless_daemon();
+}
+
int main(int argc, char *argv[]) {
bool is_gtest = false;
+ time_init();
+ CGlobalInfo::m_socket.Create(0);
+
+ CGlobalInfo::init_pools(1000);
+ assert( CMsgIns::Ins()->Create(1));
+
+ std::thread *m_thread = new std::thread(run_dummy_core);
+ (void)m_thread;
+
// gtest ?
if (argc > 1) {
string arg = string(argv[1]);
diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
index 51ac0f92..634f7ddb 100644
--- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
+++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp
@@ -377,7 +377,7 @@ TrexRpcCmdGetStreamList::_run(const Json::Value &params, Json::Value &result) {
TrexStatelessPort *port = get_stateless_obj()->get_port_by_id(port_id);
- port->get_stream_table()->get_stream_list(stream_list);
+ port->get_stream_table()->get_id_list(stream_list);
Json::Value json_list = Json::arrayValue;
diff --git a/src/stateless/cp/trex_stateless_port.cpp b/src/stateless/cp/trex_stateless_port.cpp
index d3828f53..3e6e256f 100644
--- a/src/stateless/cp/trex_stateless_port.cpp
+++ b/src/stateless/cp/trex_stateless_port.cpp
@@ -22,6 +22,7 @@ limitations under the License.
#include <trex_stateless.h>
#include <trex_stateless_port.h>
#include <trex_stateless_messaging.h>
+#include <trex_streams_compiler.h>
#include <string>
@@ -58,14 +59,26 @@ TrexStatelessPort::start_traffic(void) {
return (RC_ERR_BAD_STATE_FOR_OP);
}
- TrexStreamsCompiledObj *compiled_obj = new TrexStreamsCompiledObj();
+ if (get_stream_table()->size() == 0) {
+ return (RC_ERR_NO_STREAMS);
+ }
+
+ /* fetch all the streams from the table */
+ vector<TrexStream *> streams;
+ get_stream_table()->get_object_list(streams);
- /* compile the streams */
- bool rc = get_stream_table()->compile(*compiled_obj);
+ /* compiler it */
+ TrexStreamsCompiler compiler;
+ TrexStreamsCompiledObj *compiled_obj = new TrexStreamsCompiledObj();
+
+ bool rc = compiler.compile(streams, *compiled_obj);
if (!rc) {
return (RC_ERR_FAILED_TO_COMPILE_STREAMS);
}
+ /* move the state to transmiting */
+ m_port_state = PORT_STATE_TRANSMITTING;
+
/* generate a message to all the relevant DP cores to start transmitting */
TrexStatelessCpToDpMsgBase *start_msg = new TrexStatelessDpStart(compiled_obj);
diff --git a/src/stateless/cp/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp
index 2fd91560..ba306137 100644
--- a/src/stateless/cp/trex_stream.cpp
+++ b/src/stateless/cp/trex_stream.cpp
@@ -58,29 +58,6 @@ TrexStream::get_stream_json() {
}
/**************************************
- * stream compiled object
- *************************************/
-TrexStreamsCompiledObj::~TrexStreamsCompiledObj() {
- for (auto &obj : m_objs) {
- delete obj.m_pkt;
- }
- m_objs.clear();
-}
-
-void
-TrexStreamsCompiledObj::add_compiled_stream(double pps, uint8_t *pkt, uint16_t pkt_len) {
- obj_st obj;
-
- obj.m_pps = pps;
- obj.m_pkt_len = pkt_len;
-
- obj.m_pkt = new uint8_t[pkt_len];
- memcpy(obj.m_pkt, pkt, pkt_len);
-
- m_objs.push_back(obj);
-}
-
-/**************************************
* stream table
*************************************/
TrexStreamTable::TrexStreamTable() {
@@ -127,42 +104,24 @@ TrexStream * TrexStreamTable::get_stream_by_id(uint32_t stream_id) {
}
}
-void TrexStreamTable::get_stream_list(std::vector<uint32_t> &stream_list) {
- stream_list.clear();
+void TrexStreamTable::get_id_list(std::vector<uint32_t> &id_list) {
+ id_list.clear();
for (auto stream : m_stream_table) {
- stream_list.push_back(stream.first);
+ id_list.push_back(stream.first);
}
}
-int TrexStreamTable::size() {
- return m_stream_table.size();
-}
-
-
-bool
-TrexStreamTable::compile(TrexStreamsCompiledObj &obj) {
-
- /* for now we do something trivial, */
- for (auto it = m_stream_table.begin(); it != m_stream_table.end(); it++ ) {
- TrexStream *stream = (*it).second;
-
- if (!stream->m_enabled) {
- continue;
- }
- if (!stream->m_self_start) {
- continue;
- }
-
- /* support only continous for now ... */
- TrexStreamContinuous *cont_stream = dynamic_cast<TrexStreamContinuous *>(stream);
- if (!cont_stream) {
- continue;
- }
+void TrexStreamTable::get_object_list(std::vector<TrexStream *> &object_list) {
+ object_list.clear();
- obj.add_compiled_stream(cont_stream->get_pps(), cont_stream->m_pkt.binary, cont_stream->m_pkt.len);
+ for (auto stream : m_stream_table) {
+ object_list.push_back(stream.second);
}
- return true;
+}
+
+int TrexStreamTable::size() {
+ return m_stream_table.size();
}
diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h
index d422f9f4..c8a15240 100644
--- a/src/stateless/cp/trex_stream.h
+++ b/src/stateless/cp/trex_stream.h
@@ -37,11 +37,6 @@ class TrexRpcCmdAddStream;
*
*/
class TrexStream {
- /* provide the RPC parser a way to access private fields */
- friend class TrexRpcCmdAddStream;
- friend class TrexRpcCmdGetStream;
- friend class TrexStreamTable;
- friend class TrexStatelessPort;
public:
TrexStream(uint8_t port_id, uint32_t stream_id);
@@ -57,7 +52,7 @@ public:
/* access the stream json */
const Json::Value & get_stream_json();
-protected:
+public:
/* basic */
uint8_t m_port_id;
uint32_t m_stream_id;
@@ -150,28 +145,6 @@ protected:
};
/**
- * compiled object for a table of streams
- *
- * @author imarom (28-Oct-15)
- */
-class TrexStreamsCompiledObj {
-public:
-
- TrexStreamsCompiledObj() {}
- ~TrexStreamsCompiledObj();
-
- void add_compiled_stream(double pps, uint8_t *pkt, uint16_t pkt_len);
-
- struct obj_st {
- double m_pps;
- uint8_t *m_pkt;
- uint16_t m_pkt_len;
- };
-
- std::vector<obj_st> m_objs;
-};
-
-/**
* holds all the streams
*
*/
@@ -212,17 +185,13 @@ public:
*
* @param stream_list
*/
- void get_stream_list(std::vector<uint32_t> &stream_list);
+ void get_id_list(std::vector<uint32_t> &id_list);
/**
- * compiles all the streams in the table to a DP object that
- * can be passed to the DP cores
- *
- * @author imarom (28-Oct-15)
+ * populate a list with all the stream objects
*
- * @return bool
*/
- bool compile(TrexStreamsCompiledObj &obj);
+ void get_object_list(std::vector<TrexStream *> &object_list);
/**
* get the table size
diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp
index 0262a80a..f64686d4 100644
--- a/src/stateless/dp/trex_stateless_dp_core.cpp
+++ b/src/stateless/dp/trex_stateless_dp_core.cpp
@@ -20,7 +20,7 @@ limitations under the License.
*/
#include <trex_stateless_dp_core.h>
#include <trex_stateless_messaging.h>
-#include <trex_stream.h>
+#include <trex_streams_compiler.h>
#include <bp_sim.h>
@@ -119,7 +119,7 @@ TrexStatelessDpCore::add_cont_stream(double pps, const uint8_t *pkt, uint16_t pk
void
TrexStatelessDpCore::start_traffic(TrexStreamsCompiledObj *obj) {
- for (auto single_stream : obj->m_objs) {
+ for (auto single_stream : obj->get_objects()) {
add_cont_stream(single_stream.m_pps, single_stream.m_pkt, single_stream.m_pkt_len);
}
}
diff --git a/src/stateless/messaging/trex_stateless_messaging.cpp b/src/stateless/messaging/trex_stateless_messaging.cpp
index 4ef508fc..3c6a5933 100644
--- a/src/stateless/messaging/trex_stateless_messaging.cpp
+++ b/src/stateless/messaging/trex_stateless_messaging.cpp
@@ -20,7 +20,7 @@ limitations under the License.
*/
#include <trex_stateless_messaging.h>
#include <trex_stateless_dp_core.h>
-#include <trex_stream.h>
+#include <trex_streams_compiler.h>
#include <string.h>
/*************************