diff options
Diffstat (limited to 'src/stateless/cp')
-rw-r--r-- | src/stateless/cp/trex_stream.cpp | 9 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream.h | 150 | ||||
-rw-r--r-- | src/stateless/cp/trex_streams_compiler.cpp | 34 | ||||
-rw-r--r-- | src/stateless/cp/trex_streams_compiler.h | 21 |
4 files changed, 123 insertions, 91 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 { |