summaryrefslogtreecommitdiffstats
path: root/src/stateless
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2015-11-13 14:28:54 +0200
committerimarom <imarom@cisco.com>2015-11-13 14:28:54 +0200
commit1f98e85aba1fb41110ea9743a69c075eeb60f476 (patch)
treee5c4216361e75df62d4790ec50776451c979b5ea /src/stateless
parent57e67fd2ae248039951798978cc8c1c219c3d752 (diff)
parent45b71cff9d0465b77f82e4cd40b64a9f3183c1c7 (diff)
Merge branch 'rpc_intg1' of csi-sceasr-b45:/auto/proj-pcube-b/apps/PL-b/tools/repo//trex-core into rpc_intg1
Diffstat (limited to 'src/stateless')
-rw-r--r--src/stateless/cp/trex_stream.cpp9
-rw-r--r--src/stateless/cp/trex_stream.h150
-rw-r--r--src/stateless/cp/trex_streams_compiler.cpp34
-rw-r--r--src/stateless/cp/trex_streams_compiler.h21
-rw-r--r--src/stateless/dp/trex_stateless_dp_core.cpp98
-rw-r--r--src/stateless/dp/trex_stateless_dp_core.h17
-rw-r--r--src/stateless/dp/trex_stream_node.h100
-rw-r--r--src/stateless/messaging/trex_stateless_messaging.h1
8 files changed, 305 insertions, 125 deletions
diff --git a/src/stateless/cp/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp
index ba306137..1a05257c 100644
--- a/src/stateless/cp/trex_stream.cpp
+++ b/src/stateless/cp/trex_stream.cpp
@@ -25,9 +25,11 @@ limitations under the License.
/**************************************
* stream
*************************************/
-TrexStream::TrexStream(uint8_t port_id, uint32_t stream_id) : m_port_id(port_id), m_stream_id(stream_id) {
+TrexStream::TrexStream(uint8_t type,
+ uint8_t port_id, uint32_t stream_id) : m_port_id(port_id), m_stream_id(stream_id) {
/* default values */
+ m_type = type;
m_isg_usec = 0;
m_next_stream_id = -1;
m_enabled = false;
@@ -38,6 +40,11 @@ TrexStream::TrexStream(uint8_t port_id, uint32_t stream_id) : m_port_id(port_id)
m_rx_check.m_enable = false;
+
+ m_pps=-1.0;
+ m_burst_total_pkts=0;
+ m_num_bursts=1;
+ m_ibg_usec=0.0;
}
TrexStream::~TrexStream() {
diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h
index c8a15240..151723ad 100644
--- a/src/stateless/cp/trex_stream.h
+++ b/src/stateless/cp/trex_stream.h
@@ -29,9 +29,28 @@ limitations under the License.
#include <json/json.h>
#include <trex_stream_vm.h>
+#include <stdio.h>
+#include <string.h>
class TrexRpcCmdAddStream;
+
+struct CStreamPktData {
+ uint8_t *binary;
+ uint16_t len;
+
+ std::string meta;
+
+public:
+ inline void clone(uint8_t * in_binary,
+ uint32_t in_pkt_size){
+ binary = new uint8_t[in_pkt_size];
+ len = in_pkt_size;
+ memcpy(binary,in_binary,in_pkt_size);
+ }
+};
+
+
/**
* Stateless Stream
*
@@ -39,8 +58,17 @@ class TrexRpcCmdAddStream;
class TrexStream {
public:
- TrexStream(uint8_t port_id, uint32_t stream_id);
- virtual ~TrexStream() = 0;
+ enum STREAM_TYPE {
+ stNONE = 0,
+ stCONTINUOUS = 4,
+ stSINGLE_BURST = 5,
+ stMULTI_BURST = 6
+ };
+
+
+public:
+ TrexStream(uint8_t type,uint8_t port_id, uint32_t stream_id);
+ virtual ~TrexStream();
/* defines the min max per packet supported */
static const uint32_t MIN_PKT_SIZE_BYTES = 1;
@@ -52,8 +80,61 @@ public:
/* access the stream json */
const Json::Value & get_stream_json();
+ double get_pps() {
+ return m_pps;
+ }
+
+ void set_pps(double pps){
+ m_pps = pps;
+ }
+
+ void set_type(uint8_t type){
+ m_type = type;
+ }
+
+ uint8_t get_type(void){
+ return ( m_type );
+ }
+
+
+
+ void set_multi_burst(uint32_t burst_total_pkts,
+ uint32_t num_bursts,
+ double ibg_usec){
+ m_burst_total_pkts = burst_total_pkts;
+ m_num_bursts = num_bursts;
+ m_ibg_usec = ibg_usec;
+ }
+
+ void set_signle_burtst(uint32_t burst_total_pkts){
+ set_multi_burst(burst_total_pkts,1,0.0);
+ }
+
+ /* create new stream */
+ TrexStream * clone_as_dp(){
+ TrexStream * dp=new TrexStream(m_type,m_port_id,m_stream_id);
+
+
+ dp->m_isg_usec = m_isg_usec;
+ dp->m_next_stream_id = m_next_stream_id;
+
+ dp->m_enabled = m_enabled;
+ dp->m_self_start = m_self_start;
+
+ /* deep copy */
+ dp->m_pkt.clone(m_pkt.binary,m_pkt.len);
+
+ dp->m_rx_check = m_rx_check;
+ dp->m_pps = m_pps;
+ dp->m_burst_total_pkts = m_burst_total_pkts;
+ dp->m_num_bursts = m_num_bursts;
+ dp->m_ibg_usec = m_ibg_usec ;
+ return (dp);
+ }
+
public:
/* basic */
+ uint8_t m_type;
uint8_t m_port_id;
uint32_t m_stream_id;
@@ -65,13 +146,9 @@ public:
/* indicators */
bool m_enabled;
bool m_self_start;
-
+
+ CStreamPktData m_pkt;
/* pkt */
- struct {
- uint8_t *binary;
- uint16_t len;
- std::string meta;
- } m_pkt;
/* VM */
StreamVm m_vm;
@@ -85,64 +162,19 @@ public:
} m_rx_check;
+ double m_pps;
- /* original template provided by requester */
- Json::Value m_stream_json;
-};
+ uint32_t m_burst_total_pkts; /* valid in case of burst stSINGLE_BURST,stMULTI_BURST*/
-/**
- * continuous stream
- *
- */
-class TrexStreamContinuous : public TrexStream {
-public:
- TrexStreamContinuous(uint8_t port_id, uint32_t stream_id, double pps) : TrexStream(port_id, stream_id), m_pps(pps) {
- }
+ uint32_t m_num_bursts; /* valid in case of stMULTI_BURST */
- double get_pps() {
- return m_pps;
- }
+ double m_ibg_usec; /* valid in case of stMULTI_BURST */
-protected:
- double m_pps;
-};
-
-/**
- * single burst
- *
- */
-class TrexStreamBurst : public TrexStream {
-public:
- 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) {
- }
+ /* original template provided by requester */
+ Json::Value m_stream_json;
-protected:
- uint32_t m_total_pkts;
- double m_pps;
};
-/**
- * multi burst
- *
- */
-class TrexStreamMultiBurst : public TrexStreamBurst {
-public:
- TrexStreamMultiBurst(uint8_t port_id,
- uint32_t stream_id,
- uint32_t pkts_per_burst,
- 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) {
-
- }
-protected:
- uint32_t m_num_bursts;
- double m_ibg_usec;
-
-};
/**
* holds all the streams
diff --git a/src/stateless/cp/trex_streams_compiler.cpp b/src/stateless/cp/trex_streams_compiler.cpp
index 0b2549a0..80cdb31c 100644
--- a/src/stateless/cp/trex_streams_compiler.cpp
+++ b/src/stateless/cp/trex_streams_compiler.cpp
@@ -27,26 +27,21 @@ limitations under the License.
* stream compiled object
*************************************/
TrexStreamsCompiledObj::TrexStreamsCompiledObj(uint8_t port_id, double mul) : m_port_id(port_id), m_mul(mul) {
+ m_duration_sim=-1.0;
}
TrexStreamsCompiledObj::~TrexStreamsCompiledObj() {
- for (auto &obj : m_objs) {
- delete obj.m_pkt;
+ for (auto obj : m_objs) {
+ delete obj.m_stream;
}
m_objs.clear();
}
void
-TrexStreamsCompiledObj::add_compiled_stream(double isg_usec, double pps, uint8_t *pkt, uint16_t pkt_len) {
+TrexStreamsCompiledObj::add_compiled_stream(TrexStream * stream) {
obj_st obj;
- obj.m_isg_usec = isg_usec;
- obj.m_port_id = m_port_id;
- obj.m_pps = pps * m_mul;
- obj.m_pkt_len = pkt_len;
-
- obj.m_pkt = new uint8_t[pkt_len];
- memcpy(obj.m_pkt, pkt, pkt_len);
+ obj.m_stream = stream->clone_as_dp();
m_objs.push_back(obj);
}
@@ -61,15 +56,13 @@ TrexStreamsCompiledObj::clone() {
* clone each element
*/
for (auto obj : m_objs) {
- new_compiled_obj->add_compiled_stream(obj.m_isg_usec,
- obj.m_pps,
- obj.m_pkt,
- obj.m_pkt_len);
+ new_compiled_obj->add_compiled_stream(obj.m_stream);
}
- /* fix the multiplier */
new_compiled_obj->m_mul = m_mul;
+ new_compiled_obj->m_duration_sim = m_duration_sim;
+
return new_compiled_obj;
}
@@ -91,17 +84,8 @@ TrexStreamsCompiler::compile(const std::vector<TrexStream *> &streams, TrexStrea
continue;
}
- /* for now support only continous ... */
- TrexStreamContinuous *cont_stream = dynamic_cast<TrexStreamContinuous *>(stream);
- if (!cont_stream) {
- continue;
- }
-
/* add it */
- obj.add_compiled_stream(cont_stream->m_isg_usec,
- cont_stream->get_pps(),
- cont_stream->m_pkt.binary,
- cont_stream->m_pkt.len);
+ obj.add_compiled_stream(stream);
}
return true;
diff --git a/src/stateless/cp/trex_streams_compiler.h b/src/stateless/cp/trex_streams_compiler.h
index 404fdd21..78ac1ac7 100644
--- a/src/stateless/cp/trex_streams_compiler.h
+++ b/src/stateless/cp/trex_streams_compiler.h
@@ -40,29 +40,38 @@ public:
~TrexStreamsCompiledObj();
struct obj_st {
- double m_isg_usec;
- double m_pps;
- uint8_t *m_pkt;
- uint16_t m_pkt_len;
- uint8_t m_port_id;
+
+ TrexStream * m_stream;
};
const std::vector<obj_st> & get_objects() {
return m_objs;
}
+ void set_simulation_duration(double duration){
+ m_duration_sim=duration;
+ }
+
+ double get_simulation_duration(){
+ return (m_duration_sim);
+ }
/**
* clone the compiled object
*
*/
TrexStreamsCompiledObj * clone();
+ double get_multiplier(){
+ return (m_mul);
+ }
+
private:
- void add_compiled_stream(double isg_usec, double pps, uint8_t *pkt, uint16_t pkt_len);
+ void add_compiled_stream(TrexStream * stream);
std::vector<obj_st> m_objs;
uint8_t m_port_id;
double m_mul;
+ double m_duration_sim; /* duration for all simulation */
};
class TrexStreamsCompiler {
diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp
index b2bd0152..96c18dbd 100644
--- a/src/stateless/dp/trex_stateless_dp_core.cpp
+++ b/src/stateless/dp/trex_stateless_dp_core.cpp
@@ -22,6 +22,7 @@ limitations under the License.
#include <trex_stateless_messaging.h>
#include <trex_streams_compiler.h>
#include <trex_stream_node.h>
+#include <trex_stream.h>
#include <bp_sim.h>
@@ -31,6 +32,18 @@ usec_to_sec(double usec) {
}
+
+void CGenNodeStateless::free_stl_node(){
+ /* if we have cache mbuf free it */
+ rte_mbuf_t * m=get_cache_mbuf();
+ if (m) {
+ rte_pktmbuf_free(m);
+ m_cache_mbuf=0;
+ }
+}
+
+
+
void
TrexStatelessDpCore::create(uint8_t thread_id, CFlowGenListPerThread *core) {
m_thread_id = thread_id;
@@ -79,44 +92,91 @@ TrexStatelessDpCore::start_scheduler() {
m_core->m_node_gen.close_file(m_core);
}
+
+void
+TrexStatelessDpCore::run_once(){
+
+ idle_state_loop();
+ start_scheduler();
+}
+
+
void
TrexStatelessDpCore::start() {
while (true) {
- idle_state_loop();
+ run_once();
+ }
+}
+
+void
+TrexStatelessDpCore::add_duration(double duration){
+ if (duration > 0.0) {
+ CGenNode *node = m_core->create_node() ;
+
+ node->m_type = CGenNode::EXIT_SCHED;
- start_scheduler();
+ /* make sure it will be scheduled after the current node */
+ node->m_time = m_core->m_cur_time_sec + duration ;
+
+ m_core->m_node_gen.add_node(node);
}
}
+
void
-TrexStatelessDpCore::add_cont_stream(uint8_t port_id,
- double isg_usec,
- double pps,
- const uint8_t *pkt,
- uint16_t pkt_len) {
+TrexStatelessDpCore::add_cont_stream(TrexStream * stream,
+ TrexStreamsCompiledObj *comp) {
CGenNodeStateless *node = m_core->create_node_sl();
/* add periodic */
node->m_type = CGenNode::STATELESS_PKT;
- node->m_time = m_core->m_cur_time_sec + usec_to_sec(isg_usec);
+ node->m_time = m_core->m_cur_time_sec + usec_to_sec(stream->m_isg_usec);
- pkt_dir_t dir = m_core->m_node_gen.m_v_if->port_id_to_dir(port_id);
+ pkt_dir_t dir = m_core->m_node_gen.m_v_if->port_id_to_dir(stream->m_port_id);
node->m_flags = 0;
/* set socket id */
node->set_socket_id(m_core->m_node_gen.m_socket_id);
/* build a mbuf from a packet */
- uint16_t pkt_size = pkt_len;
- const uint8_t *stream_pkt = pkt;
+
+ uint16_t pkt_size = stream->m_pkt.len;
+ const uint8_t *stream_pkt = stream->m_pkt.binary;
+
+ node->m_stream_type = stream->m_type;
+ node->m_next_time_offset = 1.0 / (stream->get_pps() * comp->get_multiplier()) ;
+
/* stateless specific fields */
- node->m_next_time_offset = 1.0 / pps;
+ switch ( stream->m_type ) {
+
+ case TrexStream::stCONTINUOUS :
+ break;
+
+ case TrexStream::stSINGLE_BURST :
+ node->m_stream_type = TrexStream::stMULTI_BURST;
+ node->m_single_burst = stream->m_burst_total_pkts;
+ node->m_single_burst_refill = stream->m_burst_total_pkts;
+ node->m_multi_bursts = 1; /* single burst in multi burst of 1 */
+ node->m_ibg_sec = 0.0;
+ break;
+
+ case TrexStream::stMULTI_BURST :
+ node->m_single_burst = stream->m_burst_total_pkts;
+ node->m_single_burst_refill = stream->m_burst_total_pkts;
+ node->m_multi_bursts = stream->m_num_bursts;
+ node->m_ibg_sec = usec_to_sec( stream->m_ibg_usec );
+ break;
+ default:
+
+ assert(0);
+ };
+
node->m_is_stream_active = 1;
- node->m_port_id = port_id;
+ node->m_port_id = stream->m_port_id;
/* allocate const mbuf */
rte_mbuf_t *m = CGlobalInfo::pktmbuf_alloc(node->get_socket_id(), pkt_size);
@@ -149,11 +209,13 @@ TrexStatelessDpCore::add_cont_stream(uint8_t port_id,
void
TrexStatelessDpCore::start_traffic(TrexStreamsCompiledObj *obj) {
for (auto single_stream : obj->get_objects()) {
- add_cont_stream(single_stream.m_port_id,
- single_stream.m_isg_usec,
- single_stream.m_pps,
- single_stream.m_pkt,
- single_stream.m_pkt_len);
+ add_cont_stream(single_stream.m_stream,obj);
+ }
+
+ double duration=obj->get_simulation_duration();
+
+ if ( duration >0.0){
+ add_duration( duration );
}
}
diff --git a/src/stateless/dp/trex_stateless_dp_core.h b/src/stateless/dp/trex_stateless_dp_core.h
index f4dbad08..1029213d 100644
--- a/src/stateless/dp/trex_stateless_dp_core.h
+++ b/src/stateless/dp/trex_stateless_dp_core.h
@@ -31,6 +31,7 @@ class TrexStatelessDpStart;
class CFlowGenListPerThread;
class CGenNodeStateless;
class TrexStreamsCompiledObj;
+class TrexStream;
class TrexStatelessDpCore {
@@ -45,6 +46,7 @@ public:
TrexStatelessDpCore() {
m_thread_id = 0;
m_core = NULL;
+ m_duration = -1;
}
/**
@@ -61,6 +63,10 @@ public:
*/
void start();
+
+ /* exit after batch of commands */
+ void run_once();
+
/**
* dummy traffic creator
*
@@ -126,11 +132,10 @@ private:
*/
void handle_cp_msg(TrexStatelessCpToDpMsgBase *msg);
- void add_cont_stream(uint8_t dir,
- double isg,
- double pps,
- const uint8_t *pkt,
- uint16_t pkt_len);
+ /* add global exit */
+ void add_duration(double duration);
+
+ void add_cont_stream(TrexStream * stream,TrexStreamsCompiledObj *comp);
uint8_t m_thread_id;
state_e m_state;
@@ -142,6 +147,8 @@ private:
/* pointer to the main object */
CFlowGenListPerThread *m_core;
+
+ double m_duration;
};
#endif /* __TREX_STATELESS_DP_CORE_H__ */
diff --git a/src/stateless/dp/trex_stream_node.h b/src/stateless/dp/trex_stream_node.h
index 92b428ab..e4cf964d 100644
--- a/src/stateless/dp/trex_stream_node.h
+++ b/src/stateless/dp/trex_stream_node.h
@@ -22,8 +22,10 @@ limitations under the License.
#define __TREX_STREAM_NODE_H__
#include <bp_sim.h>
+#include <stdio.h>
class TrexStatelessDpCore;
+#include <trex_stream.h>
/* this is a event for stateless */
struct CGenNodeStateless : public CGenNodeBase {
@@ -32,27 +34,51 @@ friend class TrexStatelessDpCore;
private:
void * m_cache_mbuf;
- double m_next_time_offset;
+ double m_next_time_offset; /* in sec */
+ double m_ibg_sec; /* inter burst time in sec */
+
+
uint8_t m_is_stream_active;
uint8_t m_port_id;
+ uint8_t m_stream_type; /* TrexStream::STREAM_TYPE */
+ uint8_t m_pad;
+
+ uint32_t m_single_burst; /* the number of bursts in case of burst */
+ uint32_t m_single_burst_refill;
+
+ uint32_t m_multi_bursts; /* in case of multi_burst how many bursts */
+
+
/* pad to match the size of CGenNode */
- uint8_t m_pad_end[87];
+ uint8_t m_pad_end[65];
public:
+ inline uint8_t get_stream_type(){
+ return (m_stream_type);
+ }
+
+ inline uint32_t get_single_burst_cnt(){
+ return (m_single_burst);
+ }
+
+ inline double get_multi_ibg_sec(){
+ return (m_ibg_sec);
+ }
+
+ inline uint32_t get_multi_burst_cnt(){
+ return (m_multi_bursts);
+ }
+
+
inline bool is_active() {
return m_is_stream_active;
}
-
- /**
- * main function to handle an event of a packet tx
- *
- */
- inline void handle(CFlowGenListPerThread *thread) {
+ inline void handle_continues(CFlowGenListPerThread *thread) {
thread->m_node_gen.m_v_if->send_node( (CGenNode *)this);
/* in case of continues */
@@ -62,6 +88,51 @@ public:
thread->m_node_gen.m_p_queue.push( (CGenNode *)this);
}
+ inline void handle_multi_burst(CFlowGenListPerThread *thread) {
+ thread->m_node_gen.m_v_if->send_node( (CGenNode *)this);
+
+ m_single_burst--;
+ if (m_single_burst > 0 ) {
+ /* in case of continues */
+ m_time += m_next_time_offset;
+
+ thread->m_node_gen.m_p_queue.push( (CGenNode *)this);
+ }else{
+ m_multi_bursts--;
+ if ( m_multi_bursts == 0 ) {
+ /* stop */
+ m_is_stream_active =0;
+ }else{
+ m_time += m_ibg_sec;
+ m_single_burst = m_single_burst_refill;
+
+ }
+ thread->m_node_gen.m_p_queue.push( (CGenNode *)this);
+ }
+ }
+
+
+ /**
+ * main function to handle an event of a packet tx
+ *
+ *
+ *
+ */
+
+ inline void handle(CFlowGenListPerThread *thread) {
+
+ if (m_stream_type == TrexStream::stCONTINUOUS ) {
+ handle_continues(thread) ;
+ }else{
+ if (m_stream_type == TrexStream::stMULTI_BURST) {
+ handle_multi_burst(thread);
+ }else{
+ assert(0);
+ }
+ }
+
+ }
+
void set_socket_id(socket_id_t socket){
m_socket_id=socket;
}
@@ -82,8 +153,6 @@ public:
return ((pkt_dir_t)( m_flags &1));
}
-
-
inline void set_cache_mbuf(rte_mbuf_t * m){
m_cache_mbuf=(void *)m;
m_flags |= NODE_FLAGS_MBUF_CACHE;
@@ -97,9 +166,18 @@ public:
}
}
+ void free_stl_node();
+
+
+ void Dump(FILE *fd){
+ fprintf(fd," %f, %lu, %lu \n",m_time,(ulong)m_port_id,(ulong)get_mbuf_cache_dir());
+ }
} __rte_cache_aligned;
-static_assert(sizeof(CGenNodeStateless) == sizeof(CGenNode), "sizeof(CGenNodeStateless) != sizeof(CGenNode)");
+static_assert(sizeof(CGenNodeStateless) == sizeof(CGenNode), "sizeof(CGenNodeStateless) != sizeof(CGenNode)" );
+
+
+
#endif /* __TREX_STREAM_NODE_H__ */
diff --git a/src/stateless/messaging/trex_stateless_messaging.h b/src/stateless/messaging/trex_stateless_messaging.h
index 7978b7f9..d288fc83 100644
--- a/src/stateless/messaging/trex_stateless_messaging.h
+++ b/src/stateless/messaging/trex_stateless_messaging.h
@@ -74,6 +74,7 @@ public:
virtual TrexStatelessCpToDpMsgBase * clone();
+
private:
TrexStreamsCompiledObj *m_obj;
};