From cc352e04fd45913132f3e1ddc86d88571c926879 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Wed, 11 Nov 2015 15:37:46 +0200 Subject: add first stl test and cleanup valgrind --- src/gtest/trex_stateless_gtest.cpp | 360 +++++++++++-------------------------- 1 file changed, 104 insertions(+), 256 deletions(-) (limited to 'src/gtest/trex_stateless_gtest.cpp') diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp index 2bab4dff..36e48f6e 100644 --- a/src/gtest/trex_stateless_gtest.cpp +++ b/src/gtest/trex_stateless_gtest.cpp @@ -22,332 +22,180 @@ limitations under the License. #include "bp_sim.h" #include #include +#include +#include +#include +#include +#include +#include +#include #define EXPECT_EQ_UINT32(a,b) EXPECT_EQ((uint32_t)(a),(uint32_t)(b)) -// one stream info with const packet , no VM -class CTRexDpStatelessVM { -}; - -//- add dump function -// - check one object -// create frame work -class CTRexDpStreamModeContinues{ +/* basic stateless test */ +class basic_stl : public testing::Test { + protected: + virtual void SetUp() { + } + virtual void TearDown() { + } public: - void set_pps(double pps){ - m_pps=pps; - } - double get_pps(){ - return (m_pps); - } - - void dump(FILE *fd); -private: - double m_pps; }; -void CTRexDpStreamModeContinues::dump(FILE *fd){ - fprintf (fd," pps : %f \n",m_pps); -} +class CBasicStl { - -class CTRexDpStreamModeSingleBurst{ public: - void set_pps(double pps){ - m_pps=pps; - } - double get_pps(){ - return (m_pps); - } - - void set_total_packets(uint64_t total_packets){ - m_total_packets =total_packets; - } - - uint64_t get_total_packets(){ - return (m_total_packets); + CBasicStl(){ + m_time_diff=0.001; + m_threads=1; } - void dump(FILE *fd); - -private: - double m_pps; - uint64_t m_total_packets; -}; - - -void CTRexDpStreamModeSingleBurst::dump(FILE *fd){ - fprintf (fd," pps : %f \n",m_pps); - fprintf (fd," total_packets : %llu \n", (unsigned long long)m_total_packets); -} - + bool init(void){ -class CTRexDpStreamModeMultiBurst{ -public: - void set_pps(double pps){ - m_pps=pps; - } - double get_pps(){ - return (m_pps); - } + CErfIFStl erf_vif; + fl.Create(); + fl.generate_p_thread_info(1); + CFlowGenListPerThread * lpt; - void set_pkts_per_burst(uint64_t pkts_per_burst){ - m_pkts_per_burst =pkts_per_burst; - } + fl.m_threads_info[0]->set_vif(&erf_vif); - uint64_t get_pkts_per_burst(){ - return (m_pkts_per_burst); - } + CErfCmp cmp; + cmp.dump=1; - void set_ibg(double ibg){ - m_ibg = ibg; - } + CMessagingManager * cp_dp = CMsgIns::Ins()->getCpDp(); - double get_ibg(){ - return ( m_ibg ); - } + m_ring_from_cp = cp_dp->getRingCpToDp(0); - void set_number_of_bursts(uint32_t number_of_bursts){ - m_number_of_bursts = number_of_bursts; - } - uint32_t get_number_of_bursts(){ - return (m_number_of_bursts); - } + bool res=true; - void dump(FILE *fd); + lpt=fl.m_threads_info[0]; -private: - double m_pps; - double m_ibg; // inter burst gap - uint64_t m_pkts_per_burst; - uint32_t m_number_of_bursts; -}; + char buf[100]; + char buf_ex[100]; + sprintf(buf,"%s-%d.erf",CGlobalInfo::m_options.out_file.c_str(),0); + sprintf(buf_ex,"%s-%d-ex.erf",CGlobalInfo::m_options.out_file.c_str(),0); -void CTRexDpStreamModeMultiBurst::dump(FILE *fd){ - fprintf (fd," pps : %f \n",m_pps); - fprintf (fd," total_packets : %llu \n", (unsigned long long)m_pkts_per_burst); - fprintf (fd," ibg : %f \n",m_ibg); - fprintf (fd," num_of_bursts : %lu \n", (ulong)m_number_of_bursts); -} + lpt->start_stateless_simulation_file(buf,CGlobalInfo::m_options.preview); + /* add stream to the queue */ + assert(m_msg); + assert(m_ring_from_cp->Enqueue((CGenNode *)m_msg)==0); -class CTRexDpStreamMode { -public: - enum MODES { - moCONTINUES = 0x0, - moSINGLE_BURST = 0x1, - moMULTI_BURST = 0x2 - } ; - typedef uint8_t MODE_TYPE_t; + lpt->start_stateless_daemon_simulation(); - void reset(); + #if 0 + lpt->m_node_gen.DumpHist(stdout); - void set_mode(MODE_TYPE_t mode ){ - m_type = mode; - } - MODE_TYPE_t get_mode(){ - return (m_type); - } + cmp.d_sec = m_time_diff; + if ( cmp.compare(std::string(buf),std::string(buf_ex)) != true ) { + res=false; + } - CTRexDpStreamModeContinues & cont(void){ - return (m_data.m_cont); - } - CTRexDpStreamModeSingleBurst & single_burst(void){ - return (m_data.m_signle_burst); - } + if ( m_dump_json ){ + printf(" dump json ...........\n"); + std::string s; + fl.m_threads_info[0]->m_node_gen.dump_json(s); + printf(" %s \n",s.c_str()); + } + #endif - CTRexDpStreamModeMultiBurst & multi_burst(void){ - return (m_data.m_multi_burst); + fl.Delete(); + return (res); } - void dump(FILE *fd); -private: - uint8_t m_type; - union Data { - CTRexDpStreamModeContinues m_cont; - CTRexDpStreamModeSingleBurst m_signle_burst; - CTRexDpStreamModeMultiBurst m_multi_burst; - } m_data; +public: + int m_threads; + double m_time_diff; + bool m_dump_json; + TrexStatelessCpToDpMsgBase * m_msg; + CNodeRing *m_ring_from_cp; + CFlowGenList fl; }; -void CTRexDpStreamMode::reset(){ - m_type =CTRexDpStreamMode::moCONTINUES; - memset(&m_data,0,sizeof(m_data)); -} - -void CTRexDpStreamMode::dump(FILE *fd){ - const char * table[3] = {"CONTINUES","SINGLE_BURST","MULTI_BURST"}; - - fprintf(fd," mode : %s \n", (char*)table[m_type]); - switch (m_type) { - case CTRexDpStreamMode::moCONTINUES : - cont().dump(fd); - break; - case CTRexDpStreamMode::moSINGLE_BURST : - single_burst().dump(fd); - break; - case CTRexDpStreamMode::moMULTI_BURST : - multi_burst().dump(fd); - break; - default: - fprintf(fd," ERROR type if not valid %d \n",m_type); - break; - } -} +const uint8_t my_test_pkt[]={ + 0x00,0x04,0x96,0x08,0xe0,0x40, + 0x00,0x0e,0x2e,0x24,0x37,0x5f, + 0x08,0x00, + 0x45,0x02,0x00,0x30, + 0x00,0x00,0x40,0x00, + 0x40,0x84,0xbd,0x04, + 0x9b,0xe6,0x18,0x9b, //sIP + 0xcb,0xff,0xfc,0xc2, //DIP -class CTRexDpStatelessStream { + 0x80,0x44,//SPORT + 0x00,0x50,//DPORT -public: - enum FLAGS_0{ - _ENABLE = 0, - _SELF_START = 1, - _VM_ENABLE =2, - _END_STREAM =-1 - }; - - CTRexDpStatelessStream(){ - reset(); - } + 0x00,0x00,0x00,0x00, //checksum - void reset(){ - m_packet =0; - m_vm=0; - m_flags=0; - m_isg_sec=0.0; - m_next_stream = CTRexDpStatelessStream::_END_STREAM ; // END - m_mode.reset(); - } + 0x11,0x22,0x33,0x44, // magic + 0x00,0x00,0x00,0x00, //64 bit counter + 0x00,0x00,0x00,0x00, + 0x00,0x01,0xa0,0x00, //seq + 0x00,0x00,0x00,0x00, +}; - void set_enable(bool enable){ - btSetMaskBit32(m_flags,_ENABLE,_ENABLE,enable?1:0); - } - bool get_enabled(){ - return (btGetMaskBit32(m_flags,_ENABLE,_ENABLE)?true:false); - } - void set_self_start(bool enable){ - btSetMaskBit32(m_flags,_SELF_START,_SELF_START,enable?1:0); - } - bool get_self_start(bool enable){ - return (btGetMaskBit32(m_flags,_SELF_START,_SELF_START)?true:false); - } +TEST_F(basic_stl, limit_single_pkt) { - /* if we don't have VM we could just replicate the mbuf and allocate it once */ - void set_vm_enable(bool enable){ - btSetMaskBit32(m_flags,_VM_ENABLE,_VM_ENABLE,enable?1:0); - } + CBasicStl t1; + CParserOption * po =&CGlobalInfo::m_options; + po->preview.setVMode(0); + po->preview.setFileWrite(true); + po->out_file ="exp/stl_single_sctp_pkt"; - bool get_vm_enabled(bool enable){ - return (btGetMaskBit32(m_flags,_VM_ENABLE,_VM_ENABLE)?true:false); - } + TrexStreamsCompiler compile; - void set_inter_stream_gap(double isg_sec){ - m_isg_sec =isg_sec; - } - double get_inter_stream_gap(){ - return (m_isg_sec); - } + std::vector streams; - CTRexDpStreamMode & get_mode(); + TrexStream * stream1 = new TrexStreamContinuous(0,0,1.0); + stream1->m_enabled = true; + stream1->m_self_start = true; + uint8_t *binary = new uint8_t[sizeof(my_test_pkt)]; + memcpy(binary,my_test_pkt,sizeof(my_test_pkt)); - // CTRexDpStatelessStream::_END_STREAM for END - void set_next_stream(int32_t next_stream){ - m_next_stream =next_stream; - } + stream1->m_pkt.binary = binary; + stream1->m_pkt.len = sizeof(my_test_pkt); - int32_t get_next_stream(void){ - return ( m_next_stream ); - } - void dump(FILE *fd); + streams.push_back(stream1); -private: - char * m_packet; - CTRexDpStatelessVM * m_vm; - uint32_t m_flags; - double m_isg_sec; // in second - CTRexDpStreamMode m_mode; - int32_t m_next_stream; // next stream id -}; + // stream - clean -//- list of streams info with const packet , no VM -// - object that include the stream /scheduler/ packet allocation / need to create an object for one thread that works for test -// generate pcap file and compare it - -#if 0 -void CTRexDpStatelessStream::dump(FILE *fd){ - - fprintf(fd," enabled : %d \n",get_enabled()?1:0); - fprintf(fd," self_start : %d \n",get_self_start()?1:0); - fprintf(fd," vm : %d \n",get_vm_enabled()?1:0); - fprintf(" isg : %f \n",m_isg_sec); - m_mode.dump(fd); - if (m_next_stream == CTRexDpStatelessStream::_END_STREAM ) { - fprintf(fd," action : End of Stream \n"); - }else{ - fprintf(" next : %d \n",m_next_stream); - } -} + TrexStreamsCompiledObj comp_obj(0,1.0); + assert(compile.compile(streams, comp_obj) ); + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); -class CTRexStatelessBasic { - -public: - CTRexStatelessBasic(){ - m_threads=1; - } - - bool init(void){ - return (true); - } - -public: - bool m_threads; -}; + t1.m_msg = lpstart; + bool res=t1.init(); -/* stateless basic */ -class dp_sl_basic : public testing::Test { - protected: - virtual void SetUp() { - } - virtual void TearDown() { - } -public: -}; - + delete stream1 ; - -TEST_F(dp_sl_basic, test1) { - CTRexDpStatelessStream s1; - s1.set_enable(true); - s1.set_self_start(true); - s1.set_inter_stream_gap(0.77); - s1.get_mode().set_mode(CTRexDpStreamMode::moCONTINUES); - s1.get_mode().cont().set_pps(100.2); - s1.dump(stdout); + EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; } + #endif -- cgit 1.2.3-korg From d5361e483d135e60b1b40a05b283cf704697504a Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Wed, 11 Nov 2015 15:48:44 +0200 Subject: remove default duration --- src/gtest/trex_stateless_gtest.cpp | 3 ++- src/stateless/dp/trex_stateless_dp_core.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'src/gtest/trex_stateless_gtest.cpp') diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp index 36e48f6e..9634d01f 100644 --- a/src/gtest/trex_stateless_gtest.cpp +++ b/src/gtest/trex_stateless_gtest.cpp @@ -46,6 +46,7 @@ public: }; + class CBasicStl { public: @@ -198,4 +199,4 @@ TEST_F(basic_stl, limit_single_pkt) { -#endif + diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp index c9e47090..480606e8 100644 --- a/src/stateless/dp/trex_stateless_dp_core.cpp +++ b/src/stateless/dp/trex_stateless_dp_core.cpp @@ -194,7 +194,7 @@ TrexStatelessDpCore::start_traffic(TrexStreamsCompiledObj *obj) { } /* TBD need to fix this */ - add_duration(0,10.0); + //add_duration(0,10.0); } void -- cgit 1.2.3-korg From 6294136db42a3327049c67c12eab4684c4abbe47 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Wed, 11 Nov 2015 16:14:28 +0200 Subject: fix duration for stl tests --- scripts/exp/stl_single_sctp_pkt-0-ex.erf | Bin 0 -> 880 bytes src/gtest/trex_stateless_gtest.cpp | 8 ++++---- src/stateless/cp/trex_streams_compiler.cpp | 4 +++- src/stateless/cp/trex_streams_compiler.h | 8 ++++++++ src/stateless/dp/trex_stateless_dp_core.cpp | 13 +++++++------ src/stateless/dp/trex_stateless_dp_core.h | 4 ++-- 6 files changed, 24 insertions(+), 13 deletions(-) create mode 100644 scripts/exp/stl_single_sctp_pkt-0-ex.erf (limited to 'src/gtest/trex_stateless_gtest.cpp') diff --git a/scripts/exp/stl_single_sctp_pkt-0-ex.erf b/scripts/exp/stl_single_sctp_pkt-0-ex.erf new file mode 100644 index 00000000..5b991b8f Binary files /dev/null and b/scripts/exp/stl_single_sctp_pkt-0-ex.erf differ diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp index 9634d01f..7850e8da 100644 --- a/src/gtest/trex_stateless_gtest.cpp +++ b/src/gtest/trex_stateless_gtest.cpp @@ -53,6 +53,7 @@ public: CBasicStl(){ m_time_diff=0.001; m_threads=1; + m_dump_json=false; } bool init(void){ @@ -90,7 +91,6 @@ public: lpt->start_stateless_daemon_simulation(); - #if 0 lpt->m_node_gen.DumpHist(stdout); @@ -99,14 +99,12 @@ public: res=false; } - if ( m_dump_json ){ printf(" dump json ...........\n"); std::string s; fl.m_threads_info[0]->m_node_gen.dump_json(s); printf(" %s \n",s.c_str()); } - #endif fl.Delete(); return (res); @@ -156,7 +154,7 @@ TEST_F(basic_stl, limit_single_pkt) { CBasicStl t1; CParserOption * po =&CGlobalInfo::m_options; - po->preview.setVMode(0); + po->preview.setVMode(7); po->preview.setFileWrite(true); po->out_file ="exp/stl_single_sctp_pkt"; @@ -182,10 +180,12 @@ TEST_F(basic_stl, limit_single_pkt) { TrexStreamsCompiledObj comp_obj(0,1.0); + comp_obj.set_simulation_duration( 10.0); assert(compile.compile(streams, comp_obj) ); TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); + t1.m_msg = lpstart; bool res=t1.init(); diff --git a/src/stateless/cp/trex_streams_compiler.cpp b/src/stateless/cp/trex_streams_compiler.cpp index 8238bac7..7891077b 100644 --- a/src/stateless/cp/trex_streams_compiler.cpp +++ b/src/stateless/cp/trex_streams_compiler.cpp @@ -34,6 +34,7 @@ TrexStreamsCompiledObj::~TrexStreamsCompiledObj() { delete [] obj.m_pkt; } m_objs.clear(); + m_duration_sim=-1.0; } void @@ -67,9 +68,10 @@ TrexStreamsCompiledObj::clone() { obj.m_pkt_len); } - /* fix the multiplier */ new_compiled_obj->m_mul = m_mul; + new_compiled_obj->m_duration_sim = m_duration_sim; + return new_compiled_obj; } diff --git a/src/stateless/cp/trex_streams_compiler.h b/src/stateless/cp/trex_streams_compiler.h index 404fdd21..d86d16c6 100644 --- a/src/stateless/cp/trex_streams_compiler.h +++ b/src/stateless/cp/trex_streams_compiler.h @@ -51,6 +51,13 @@ public: 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 * @@ -63,6 +70,7 @@ private: 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 480606e8..e1664bd9 100644 --- a/src/stateless/dp/trex_stateless_dp_core.cpp +++ b/src/stateless/dp/trex_stateless_dp_core.cpp @@ -109,10 +109,8 @@ TrexStatelessDpCore::start() { } void -TrexStatelessDpCore::add_duration(uint8_t port_id, - double duration){ +TrexStatelessDpCore::add_duration(double duration){ if (duration > 0.0) { - CGenNode *node = m_core->create_node() ; node->m_type = CGenNode::EXIT_SCHED; @@ -121,7 +119,6 @@ TrexStatelessDpCore::add_duration(uint8_t port_id, node->m_time = m_core->m_cur_time_sec + duration ; m_core->m_node_gen.add_node(node); - } } @@ -193,8 +190,12 @@ TrexStatelessDpCore::start_traffic(TrexStreamsCompiledObj *obj) { single_stream.m_pkt_len); } - /* TBD need to fix this */ - //add_duration(0,10.0); + double duration=obj->get_simulation_duration(); + printf("duration %f \n",duration); + + if ( duration >0.0){ + add_duration( duration ); + } } void diff --git a/src/stateless/dp/trex_stateless_dp_core.h b/src/stateless/dp/trex_stateless_dp_core.h index a23e81c9..51f882b2 100644 --- a/src/stateless/dp/trex_stateless_dp_core.h +++ b/src/stateless/dp/trex_stateless_dp_core.h @@ -131,8 +131,8 @@ private: */ void handle_cp_msg(TrexStatelessCpToDpMsgBase *msg); - void add_duration(uint8_t port_id, - double duration); + /* add global exit */ + void add_duration(double duration); void add_cont_stream(uint8_t dir, double isg, -- cgit 1.2.3-korg From 151266e34245b99ce4cac70d82be79bfb5a3ebf9 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Wed, 11 Nov 2015 22:10:05 +0200 Subject: add support for multi-burst --- scripts/exp/stl_multi_burst1-0-ex.erf | Bin 0 -> 1320 bytes scripts/exp/stl_multi_pkt1-0-ex.erf | Bin 0 -> 2640 bytes scripts/exp/stl_multi_pkt2-0-ex.erf | Bin 0 -> 4488 bytes scripts/exp/stl_single_pkt_burst1-0-ex.erf | Bin 0 -> 440 bytes scripts/exp/stl_single_stream-0-ex.erf | Bin 0 -> 880 bytes src/bp_sim.cpp | 1 - src/gtest/trex_stateless_gtest.cpp | 324 +++++++++++++++++++++++++--- src/stateless/cp/trex_stream.h | 42 ++-- src/stateless/cp/trex_streams_compiler.cpp | 29 +-- src/stateless/cp/trex_streams_compiler.h | 13 +- src/stateless/dp/trex_stateless_dp_core.cpp | 61 ++++-- src/stateless/dp/trex_stateless_dp_core.h | 7 +- src/stateless/dp/trex_stream_node.h | 90 +++++++- 13 files changed, 464 insertions(+), 103 deletions(-) create mode 100644 scripts/exp/stl_multi_burst1-0-ex.erf create mode 100644 scripts/exp/stl_multi_pkt1-0-ex.erf create mode 100644 scripts/exp/stl_multi_pkt2-0-ex.erf create mode 100644 scripts/exp/stl_single_pkt_burst1-0-ex.erf create mode 100644 scripts/exp/stl_single_stream-0-ex.erf (limited to 'src/gtest/trex_stateless_gtest.cpp') diff --git a/scripts/exp/stl_multi_burst1-0-ex.erf b/scripts/exp/stl_multi_burst1-0-ex.erf new file mode 100644 index 00000000..c5cc7484 Binary files /dev/null and b/scripts/exp/stl_multi_burst1-0-ex.erf differ diff --git a/scripts/exp/stl_multi_pkt1-0-ex.erf b/scripts/exp/stl_multi_pkt1-0-ex.erf new file mode 100644 index 00000000..de109191 Binary files /dev/null and b/scripts/exp/stl_multi_pkt1-0-ex.erf differ diff --git a/scripts/exp/stl_multi_pkt2-0-ex.erf b/scripts/exp/stl_multi_pkt2-0-ex.erf new file mode 100644 index 00000000..eec33117 Binary files /dev/null and b/scripts/exp/stl_multi_pkt2-0-ex.erf differ diff --git a/scripts/exp/stl_single_pkt_burst1-0-ex.erf b/scripts/exp/stl_single_pkt_burst1-0-ex.erf new file mode 100644 index 00000000..08afdf4b Binary files /dev/null and b/scripts/exp/stl_single_pkt_burst1-0-ex.erf differ diff --git a/scripts/exp/stl_single_stream-0-ex.erf b/scripts/exp/stl_single_stream-0-ex.erf new file mode 100644 index 00000000..92883717 Binary files /dev/null and b/scripts/exp/stl_single_stream-0-ex.erf differ diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index c63ad1af..39d46d16 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -3517,7 +3517,6 @@ int CNodeGenerator::flush_file(dsec_t max_time, /* if the stream has been deactivated - end */ if (unlikely(!node_sl->is_active())) { thread->free_node(node); - } else { node_sl->handle(thread); } diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp index 7850e8da..1ea0373c 100644 --- a/src/gtest/trex_stateless_gtest.cpp +++ b/src/gtest/trex_stateless_gtest.cpp @@ -91,8 +91,7 @@ public: lpt->start_stateless_daemon_simulation(); - lpt->m_node_gen.DumpHist(stdout); - + //lpt->m_node_gen.DumpHist(stdout); cmp.d_sec = m_time_diff; if ( cmp.compare(std::string(buf),std::string(buf_ex)) != true ) { @@ -121,42 +120,161 @@ public: }; +class CPcapLoader { +public: + CPcapLoader(); + ~CPcapLoader(); + + +public: + bool load_pcap_file(std::string file,int pkt_id=0); + void update_ip_src(uint32_t ip_addr); + void clone_packet_into_stream(TrexStream * stream); + void dump_packet(); + +public: + bool m_valid; + CCapPktRaw m_raw; + CPacketIndication m_pkt_indication; +}; + +CPcapLoader::~CPcapLoader(){ +} -const uint8_t my_test_pkt[]={ +bool CPcapLoader::load_pcap_file(std::string cap_file,int pkt_id){ + m_valid=false; + CPacketParser parser; - 0x00,0x04,0x96,0x08,0xe0,0x40, - 0x00,0x0e,0x2e,0x24,0x37,0x5f, - 0x08,0x00, + CCapReaderBase * lp=CCapReaderFactory::CreateReader((char *)cap_file.c_str(),0); - 0x45,0x02,0x00,0x30, - 0x00,0x00,0x40,0x00, - 0x40,0x84,0xbd,0x04, - 0x9b,0xe6,0x18,0x9b, //sIP - 0xcb,0xff,0xfc,0xc2, //DIP + if (lp == 0) { + printf(" ERROR file %s does not exist or not supported \n",(char *)cap_file.c_str()); + return false; + } - 0x80,0x44,//SPORT - 0x00,0x50,//DPORT + int cnt=0; + bool found =false; - 0x00,0x00,0x00,0x00, //checksum - 0x11,0x22,0x33,0x44, // magic - 0x00,0x00,0x00,0x00, //64 bit counter - 0x00,0x00,0x00,0x00, - 0x00,0x01,0xa0,0x00, //seq - 0x00,0x00,0x00,0x00, -}; + while ( true ) { + /* read packet */ + if ( lp->ReadPacket(&m_raw) ==false ){ + break; + } + if (cnt==pkt_id) { + found = true; + break; + } + cnt++; + } + if ( found ){ + if ( parser.ProcessPacket(&m_pkt_indication, &m_raw) ){ + m_valid = true; + } + } + + delete lp; + return (m_valid); +} + +void CPcapLoader::update_ip_src(uint32_t ip_addr){ + + if ( m_pkt_indication.l3.m_ipv4 ) { + m_pkt_indication.l3.m_ipv4->setSourceIp(ip_addr); + m_pkt_indication.l3.m_ipv4->updateCheckSum(); + } +} + +void CPcapLoader::clone_packet_into_stream(TrexStream * stream){ + + uint16_t pkt_size=m_raw.getTotalLen(); + uint8_t *binary = new uint8_t[pkt_size]; + memcpy(binary,m_raw.raw,pkt_size); + stream->m_pkt.binary = binary; + stream->m_pkt.len = pkt_size; +} + + + + +CPcapLoader::CPcapLoader(){ + +} + +void CPcapLoader::dump_packet(){ + if (m_valid ) { + m_pkt_indication.Dump(stdout,1); + }else{ + fprintf(stdout," no packets were found \n"); + } +} + + +TEST_F(basic_stl, load_pcap_file) { + printf (" stateles %d \n",(int)sizeof(CGenNodeStateless)); + CPcapLoader pcap; + pcap.load_pcap_file("cap2/udp_64B.pcap",0); + pcap.update_ip_src(0x10000001); + pcap.load_pcap_file("cap2/udp_64B.pcap",0); + pcap.update_ip_src(0x10000001); + //pcap.dump_packet(); +} -TEST_F(basic_stl, limit_single_pkt) { +TEST_F(basic_stl, single_pkt_burst1) { CBasicStl t1; CParserOption * po =&CGlobalInfo::m_options; po->preview.setVMode(7); po->preview.setFileWrite(true); - po->out_file ="exp/stl_single_sctp_pkt"; + po->out_file ="exp/stl_single_pkt_burst1"; + + TrexStreamsCompiler compile; + + + std::vector streams; + + TrexStream * stream1 = new TrexStreamBurst(0,0,5, 1.0); + stream1->m_enabled = true; + stream1->m_self_start = true; + + CPcapLoader pcap; + pcap.load_pcap_file("cap2/udp_64B.pcap",0); + pcap.update_ip_src(0x10000001); + pcap.clone_packet_into_stream(stream1); + + streams.push_back(stream1); + + TrexStreamsCompiledObj comp_obj(0,1.0); + + comp_obj.set_simulation_duration( 10.0); + assert(compile.compile(streams, comp_obj) ); + + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); + + + t1.m_msg = lpstart; + + bool res=t1.init(); + + delete stream1 ; + + EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; +} + + + + +TEST_F(basic_stl, single_pkt) { + + CBasicStl t1; + CParserOption * po =&CGlobalInfo::m_options; + po->preview.setVMode(7); + po->preview.setFileWrite(true); + po->out_file ="exp/stl_single_stream"; TrexStreamsCompiler compile; @@ -167,11 +285,11 @@ TEST_F(basic_stl, limit_single_pkt) { stream1->m_enabled = true; stream1->m_self_start = true; - uint8_t *binary = new uint8_t[sizeof(my_test_pkt)]; - memcpy(binary,my_test_pkt,sizeof(my_test_pkt)); - stream1->m_pkt.binary = binary; - stream1->m_pkt.len = sizeof(my_test_pkt); + CPcapLoader pcap; + pcap.load_pcap_file("cap2/udp_64B.pcap",0); + pcap.update_ip_src(0x10000001); + pcap.clone_packet_into_stream(stream1); streams.push_back(stream1); @@ -196,6 +314,160 @@ TEST_F(basic_stl, limit_single_pkt) { } +TEST_F(basic_stl, multi_pkt1) { + + CBasicStl t1; + CParserOption * po =&CGlobalInfo::m_options; + po->preview.setVMode(7); + po->preview.setFileWrite(true); + po->out_file ="exp/stl_multi_pkt1"; + + TrexStreamsCompiler compile; + + + std::vector streams; + + TrexStream * stream1 = new TrexStreamContinuous(0,0,1.0); + stream1->m_enabled = true; + stream1->m_self_start = true; + + CPcapLoader pcap; + pcap.load_pcap_file("cap2/udp_64B.pcap",0); + pcap.update_ip_src(0x10000001); + pcap.clone_packet_into_stream(stream1); + + streams.push_back(stream1); + + + TrexStream * stream2 = new TrexStreamContinuous(0,1,2.0); + stream2->m_enabled = true; + stream2->m_self_start = true; + stream2->m_isg_usec = 1000.0; /* 1 msec */ + pcap.update_ip_src(0x20000001); + pcap.clone_packet_into_stream(stream2); + + streams.push_back(stream2); + + + // stream - clean + TrexStreamsCompiledObj comp_obj(0,1.0); + + comp_obj.set_simulation_duration( 10.0); + assert(compile.compile(streams, comp_obj) ); + + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); + + t1.m_msg = lpstart; + + bool res=t1.init(); + + delete stream1 ; + delete stream2 ; + + EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; +} + + + + + +/* check disabled stream with multiplier of 5*/ +TEST_F(basic_stl, multi_pkt2) { + + CBasicStl t1; + CParserOption * po =&CGlobalInfo::m_options; + po->preview.setVMode(7); + po->preview.setFileWrite(true); + po->out_file ="exp/stl_multi_pkt2"; + + TrexStreamsCompiler compile; + + + std::vector streams; + + TrexStream * stream1 = new TrexStreamContinuous(0,0,1.0); + stream1->m_enabled = true; + stream1->m_self_start = true; + + CPcapLoader pcap; + pcap.load_pcap_file("cap2/udp_64B.pcap",0); + pcap.update_ip_src(0x10000001); + pcap.clone_packet_into_stream(stream1); + + streams.push_back(stream1); + + + TrexStream * stream2 = new TrexStreamContinuous(0,1,2.0); + stream2->m_enabled = false; + stream2->m_self_start = false; + stream2->m_isg_usec = 1000.0; /* 1 msec */ + pcap.update_ip_src(0x20000001); + pcap.clone_packet_into_stream(stream2); + + streams.push_back(stream2); + + + // stream - clean + TrexStreamsCompiledObj comp_obj(0,5.0); + + comp_obj.set_simulation_duration( 10.0); + assert(compile.compile(streams, comp_obj) ); + + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); + + t1.m_msg = lpstart; + + bool res=t1.init(); + + delete stream1 ; + delete stream2 ; + + EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; +} + + +TEST_F(basic_stl, multi_burst1) { + + CBasicStl t1; + CParserOption * po =&CGlobalInfo::m_options; + po->preview.setVMode(7); + po->preview.setFileWrite(true); + po->out_file ="exp/stl_multi_burst1"; + + TrexStreamsCompiler compile; + + + std::vector streams; + + + + TrexStream * stream1 = new TrexStreamMultiBurst(0,0,5, 1.0,3,2000000.0); + stream1->m_enabled = true; + stream1->m_self_start = true; + + CPcapLoader pcap; + pcap.load_pcap_file("cap2/udp_64B.pcap",0); + pcap.update_ip_src(0x10000001); + pcap.clone_packet_into_stream(stream1); + + streams.push_back(stream1); + + TrexStreamsCompiledObj comp_obj(0,1.0); + + comp_obj.set_simulation_duration( 40.0); + assert(compile.compile(streams, comp_obj) ); + + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone() ); + + + t1.m_msg = lpstart; + + bool res=t1.init(); + + delete stream1 ; + + EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; +} diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h index d1a44909..5e6ac19a 100644 --- a/src/stateless/cp/trex_stream.h +++ b/src/stateless/cp/trex_stream.h @@ -38,6 +38,15 @@ class TrexRpcCmdAddStream; */ class TrexStream { +public: + enum STREAM_TYPE { + stNONE = 0, + stCONTINUOUS = 4, + stSINGLE_BURST = 5, + stMULTI_BURST = 6 + }; + + public: TrexStream(uint8_t port_id, uint32_t stream_id); virtual ~TrexStream(); @@ -52,8 +61,14 @@ public: /* access the stream json */ const Json::Value & get_stream_json(); + double get_pps() { + return m_pps; + } + + public: /* basic */ + uint8_t m_type; uint8_t m_port_id; uint32_t m_stream_id; @@ -85,6 +100,8 @@ public: } m_rx_check; + double m_pps; + /* original template provided by requester */ Json::Value m_stream_json; @@ -98,15 +115,10 @@ public: */ class TrexStreamContinuous : public TrexStream { public: - TrexStreamContinuous(uint8_t port_id, uint32_t stream_id, double pps) : TrexStream(port_id, stream_id), m_pps(pps) { + TrexStreamContinuous(uint8_t port_id, uint32_t stream_id, double pps) : TrexStream(port_id, stream_id) { + m_type= TrexStream::stCONTINUOUS; + m_pps=pps; } - - double get_pps() { - return m_pps; - } - -protected: - double m_pps; }; /** @@ -117,13 +129,14 @@ 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) { + m_total_pkts(total_pkts){ + m_type= TrexStream::stSINGLE_BURST; + m_pps=pps; + } -protected: +public: uint32_t m_total_pkts; - double m_pps; }; /** @@ -138,9 +151,10 @@ public: 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; } -protected: + +public: uint32_t m_num_bursts; double m_ibg_usec; diff --git a/src/stateless/cp/trex_streams_compiler.cpp b/src/stateless/cp/trex_streams_compiler.cpp index 7891077b..c7b881c5 100644 --- a/src/stateless/cp/trex_streams_compiler.cpp +++ b/src/stateless/cp/trex_streams_compiler.cpp @@ -30,24 +30,15 @@ TrexStreamsCompiledObj::TrexStreamsCompiledObj(uint8_t port_id, double mul) : m_ } TrexStreamsCompiledObj::~TrexStreamsCompiledObj() { - for (auto &obj : m_objs) { - delete [] obj.m_pkt; - } m_objs.clear(); m_duration_sim=-1.0; } 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; m_objs.push_back(obj); } @@ -62,10 +53,7 @@ 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); } new_compiled_obj->m_mul = m_mul; @@ -93,17 +81,8 @@ TrexStreamsCompiler::compile(const std::vector &streams, TrexStrea continue; } - /* for now support only continous ... */ - TrexStreamContinuous *cont_stream = dynamic_cast(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 d86d16c6..78ac1ac7 100644 --- a/src/stateless/cp/trex_streams_compiler.h +++ b/src/stateless/cp/trex_streams_compiler.h @@ -40,11 +40,8 @@ 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 & get_objects() { @@ -64,8 +61,12 @@ public: */ 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 m_objs; uint8_t m_port_id; diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp index e1664bd9..899e14be 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 #include #include +#include #include @@ -124,33 +125,64 @@ TrexStatelessDpCore::add_duration(double duration){ 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; + + TrexStreamBurst * lpburst; + TrexStreamMultiBurst * lpmulti; + + 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; + lpburst = (TrexStreamBurst *)stream; + node->m_single_burst = lpburst->m_total_pkts; + node->m_single_burst_refill = lpburst->m_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 ); + 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); @@ -183,15 +215,10 @@ 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(); - printf("duration %f \n",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 51f882b2..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 { @@ -134,11 +135,7 @@ private: /* add global exit */ void add_duration(double duration); - void add_cont_stream(uint8_t dir, - double isg, - double pps, - const uint8_t *pkt, - uint16_t pkt_len); + void add_cont_stream(TrexStream * stream,TrexStreamsCompiledObj *comp); uint8_t m_thread_id; state_e m_state; diff --git a/src/stateless/dp/trex_stream_node.h b/src/stateless/dp/trex_stream_node.h index 2ffe04c3..e4cf964d 100644 --- a/src/stateless/dp/trex_stream_node.h +++ b/src/stateless/dp/trex_stream_node.h @@ -25,6 +25,7 @@ limitations under the License. #include class TrexStatelessDpCore; +#include /* this is a event for stateless */ struct CGenNodeStateless : public CGenNodeBase { @@ -33,28 +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 */ @@ -64,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; } @@ -106,6 +175,9 @@ public: } __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__ */ -- cgit 1.2.3-korg From 45b71cff9d0465b77f82e4cd40b64a9f3183c1c7 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Thu, 12 Nov 2015 15:33:30 +0200 Subject: refactor stream object --- .../trex_control_plane/client/trex_async_client.py | 3 +- .../trex_control_plane/console/trex_console.py | 8 +- src/gtest/trex_stateless_gtest.cpp | 34 ++++-- src/platform_cfg.cpp | 2 + src/platform_cfg.h | 2 +- src/rpc-server/commands/trex_rpc_cmd_stream.cpp | 14 ++- src/stateless/cp/trex_stream.cpp | 9 +- src/stateless/cp/trex_stream.h | 132 ++++++++++++--------- src/stateless/cp/trex_streams_compiler.cpp | 7 +- src/stateless/dp/trex_stateless_dp_core.cpp | 18 +-- 10 files changed, 138 insertions(+), 91 deletions(-) (limited to 'src/gtest/trex_stateless_gtest.cpp') diff --git a/scripts/automation/trex_control_plane/client/trex_async_client.py b/scripts/automation/trex_control_plane/client/trex_async_client.py index 72cce5aa..d13513bf 100644 --- a/scripts/automation/trex_control_plane/client/trex_async_client.py +++ b/scripts/automation/trex_control_plane/client/trex_async_client.py @@ -181,7 +181,8 @@ class CTRexAsyncClient(): self.socket.setsockopt(zmq.SUBSCRIBE, '') while self.active: - msg = json.loads(self.socket.recv_string()) + line = self.socket.recv_string(); + msg = json.loads(line) key = msg['name'] self.raw_snapshot[key] = msg['data'] diff --git a/scripts/automation/trex_control_plane/console/trex_console.py b/scripts/automation/trex_control_plane/console/trex_console.py index 06ae762a..5470e694 100755 --- a/scripts/automation/trex_control_plane/console/trex_console.py +++ b/scripts/automation/trex_control_plane/console/trex_console.py @@ -371,12 +371,12 @@ def setParserOptions(): default = "localhost", type = str) - parser.add_argument("-p", "--port", help = "TRex Server Port [default is 5505]\n", - default = 5505, + parser.add_argument("-p", "--port", help = "TRex Server Port [default is 4501]\n", + default = 4501, type = int) - parser.add_argument("--async_port", help = "TRex ASync Publisher Port [default is 4505]\n", - default = 4505, + parser.add_argument("--async_port", help = "TRex ASync Publisher Port [default is 4500]\n", + default = 4500, dest='pub', type = int) diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp index 1ea0373c..8b96ef88 100644 --- a/src/gtest/trex_stateless_gtest.cpp +++ b/src/gtest/trex_stateless_gtest.cpp @@ -237,7 +237,9 @@ TEST_F(basic_stl, single_pkt_burst1) { std::vector streams; - TrexStream * stream1 = new TrexStreamBurst(0,0,5, 1.0); + TrexStream * stream1 = new TrexStream(TrexStream::stSINGLE_BURST, 0,0); + stream1->set_pps(1.0); + stream1->set_signle_burtst(5); stream1->m_enabled = true; stream1->m_self_start = true; @@ -281,7 +283,10 @@ TEST_F(basic_stl, single_pkt) { std::vector streams; - TrexStream * stream1 = new TrexStreamContinuous(0,0,1.0); + TrexStream * stream1 = new TrexStream(TrexStream::stCONTINUOUS,0,0); + stream1->set_pps(1.0); + + stream1->m_enabled = true; stream1->m_self_start = true; @@ -327,7 +332,10 @@ TEST_F(basic_stl, multi_pkt1) { std::vector streams; - TrexStream * stream1 = new TrexStreamContinuous(0,0,1.0); + TrexStream * stream1 = new TrexStream(TrexStream::stCONTINUOUS,0,0); + stream1->set_pps(1.0); + + stream1->m_enabled = true; stream1->m_self_start = true; @@ -338,8 +346,9 @@ TEST_F(basic_stl, multi_pkt1) { streams.push_back(stream1); + TrexStream * stream2 = new TrexStream(TrexStream::stCONTINUOUS,0,0); + stream2->set_pps(2.0); - TrexStream * stream2 = new TrexStreamContinuous(0,1,2.0); stream2->m_enabled = true; stream2->m_self_start = true; stream2->m_isg_usec = 1000.0; /* 1 msec */ @@ -385,7 +394,11 @@ TEST_F(basic_stl, multi_pkt2) { std::vector streams; - TrexStream * stream1 = new TrexStreamContinuous(0,0,1.0); + + TrexStream * stream1 = new TrexStream(TrexStream::stCONTINUOUS,0,0); + stream1->set_pps(1.0); + + stream1->m_enabled = true; stream1->m_self_start = true; @@ -397,7 +410,9 @@ TEST_F(basic_stl, multi_pkt2) { streams.push_back(stream1); - TrexStream * stream2 = new TrexStreamContinuous(0,1,2.0); + TrexStream * stream2 = new TrexStream(TrexStream::stCONTINUOUS,0,1); + stream2->set_pps(2.0); + stream2->m_enabled = false; stream2->m_self_start = false; stream2->m_isg_usec = 1000.0; /* 1 msec */ @@ -439,9 +454,12 @@ TEST_F(basic_stl, multi_burst1) { std::vector streams; + TrexStream * stream1 = new TrexStream(TrexStream::stMULTI_BURST,0,0); + stream1->set_pps(1.0); + stream1->set_multi_burst(5, + 3, + 2000000.0); - - TrexStream * stream1 = new TrexStreamMultiBurst(0,0,5, 1.0,3,2000000.0); stream1->m_enabled = true; stream1->m_self_start = true; diff --git a/src/platform_cfg.cpp b/src/platform_cfg.cpp index df04cd89..547cc3ad 100755 --- a/src/platform_cfg.cpp +++ b/src/platform_cfg.cpp @@ -414,7 +414,9 @@ void CPlatformYamlInfo::Dump(FILE *fd){ } if ( m_telnet_exist ){ fprintf(fd," telnet_port : %d \n",m_telnet_port); + } + fprintf(fd," m_zmq_rpc_port : %d \n",m_zmq_rpc_port); if ( m_mac_info_exist ){ int i; diff --git a/src/platform_cfg.h b/src/platform_cfg.h index b4b03b10..4fc3c3dd 100755 --- a/src/platform_cfg.h +++ b/src/platform_cfg.h @@ -180,11 +180,11 @@ public: m_enable_zmq_pub_exist=false; m_enable_zmq_pub=true; m_zmq_pub_port=4500; + m_zmq_rpc_port = 4501; m_telnet_exist=false; m_telnet_port=4502 ; - m_zmq_rpc_port = 5050; m_mac_info_exist=false; m_port_bandwidth_gb = 10; diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index fffc800a..e32073b0 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -140,14 +140,18 @@ TrexRpcCmdAddStream::allocate_new_stream(const Json::Value §ion, uint8_t por if (type == "continuous") { double pps = parse_double(mode, "pps", result); - stream = new TrexStreamContinuous(port_id, stream_id, pps); + stream = new TrexStream( TrexStream::stCONTINUOUS, port_id, stream_id); + stream->set_pps(pps); } else if (type == "single_burst") { uint32_t total_pkts = parse_int(mode, "total_pkts", result); double pps = parse_double(mode, "pps", result); - stream = new TrexStreamBurst(port_id, stream_id, total_pkts, pps); + stream = new TrexStream(TrexStream::stSINGLE_BURST,port_id, stream_id); + stream->set_pps(pps); + stream->set_signle_burtst(total_pkts); + } else if (type == "multi_burst") { @@ -156,8 +160,10 @@ TrexRpcCmdAddStream::allocate_new_stream(const Json::Value §ion, uint8_t por uint32_t num_bursts = parse_int(mode, "number_of_bursts", result); uint32_t pkts_per_burst = parse_int(mode, "pkts_per_burst", result); - stream = new TrexStreamMultiBurst(port_id, stream_id, pkts_per_burst, pps, num_bursts, ibg_usec); - + stream = new TrexStream(TrexStream::stMULTI_BURST,port_id, stream_id ); + stream->set_pps(pps); + stream->set_multi_burst(pkts_per_burst,num_bursts,ibg_usec); + } else { generate_parse_err(result, "bad stream type provided: '" + type + "'"); 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 #include +#include +#include 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: -- cgit 1.2.3-korg