diff options
author | 2015-11-12 15:33:30 +0200 | |
---|---|---|
committer | 2015-11-12 15:33:30 +0200 | |
commit | 45b71cff9d0465b77f82e4cd40b64a9f3183c1c7 (patch) | |
tree | 131242205381140fffeab0e7c2e05618efcc39ce /src/stateless | |
parent | 12aa72196b6ccac1b335fa7f06e9351c28c79158 (diff) |
refactor stream object
Diffstat (limited to 'src/stateless')
-rw-r--r-- | src/stateless/cp/trex_stream.cpp | 9 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream.h | 132 | ||||
-rw-r--r-- | src/stateless/cp/trex_streams_compiler.cpp | 7 | ||||
-rw-r--r-- | src/stateless/dp/trex_stateless_dp_core.cpp | 18 |
4 files changed, 93 insertions, 73 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 5e6ac19a..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 * @@ -48,7 +67,7 @@ public: public: - TrexStream(uint8_t port_id, uint32_t stream_id); + TrexStream(uint8_t type,uint8_t port_id, uint32_t stream_id); virtual ~TrexStream(); /* defines the min max per packet supported */ @@ -65,6 +84,53 @@ public: 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 */ @@ -80,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; @@ -102,63 +164,17 @@ public: double m_pps; + uint32_t m_burst_total_pkts; /* valid in case of burst stSINGLE_BURST,stMULTI_BURST*/ - /* original template provided by requester */ - Json::Value m_stream_json; - - -}; + uint32_t m_num_bursts; /* valid in case of 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_type= TrexStream::stCONTINUOUS; - m_pps=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_type= TrexStream::stSINGLE_BURST; - m_pps=pps; + double m_ibg_usec; /* valid in case of stMULTI_BURST */ - } + /* original template provided by requester */ + Json::Value m_stream_json; -public: - uint32_t m_total_pkts; }; -/** - * 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) { - m_type= TrexStream::stMULTI_BURST; - } - -public: - 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 c7b881c5..80cdb31c 100644 --- a/src/stateless/cp/trex_streams_compiler.cpp +++ b/src/stateless/cp/trex_streams_compiler.cpp @@ -27,18 +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_stream; + } m_objs.clear(); - m_duration_sim=-1.0; } void TrexStreamsCompiledObj::add_compiled_stream(TrexStream * stream) { obj_st obj; - obj.m_stream = stream; + obj.m_stream = stream->clone_as_dp(); m_objs.push_back(obj); } diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp index 899e14be..96c18dbd 100644 --- a/src/stateless/dp/trex_stateless_dp_core.cpp +++ b/src/stateless/dp/trex_stateless_dp_core.cpp @@ -146,9 +146,6 @@ TrexStatelessDpCore::add_cont_stream(TrexStream * stream, uint16_t pkt_size = stream->m_pkt.len; const uint8_t *stream_pkt = stream->m_pkt.binary; - TrexStreamBurst * lpburst; - TrexStreamMultiBurst * lpmulti; - node->m_stream_type = stream->m_type; node->m_next_time_offset = 1.0 / (stream->get_pps() * comp->get_multiplier()) ; @@ -161,20 +158,17 @@ TrexStatelessDpCore::add_cont_stream(TrexStream * stream, case TrexStream::stSINGLE_BURST : node->m_stream_type = TrexStream::stMULTI_BURST; - lpburst = (TrexStreamBurst *)stream; - node->m_single_burst = lpburst->m_total_pkts; - node->m_single_burst_refill = lpburst->m_total_pkts; + 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 : - lpmulti =(TrexStreamMultiBurst *)stream; - - node->m_single_burst = lpmulti->m_total_pkts; - node->m_single_burst_refill = lpmulti->m_total_pkts ; - node->m_multi_bursts = lpmulti->m_num_bursts; - node->m_ibg_sec = usec_to_sec( lpmulti->m_ibg_usec ); + 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: |