summaryrefslogtreecommitdiffstats
path: root/src/gtest/trex_stateless_gtest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/gtest/trex_stateless_gtest.cpp')
-rw-r--r--src/gtest/trex_stateless_gtest.cpp360
1 files changed, 104 insertions, 256 deletions
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 <common/gtest.h>
#include <common/basic_utils.h>
+#include <trex_stateless_dp_core.h>
+#include <trex_stateless_messaging.h>
+#include <trex_streams_compiler.h>
+#include <trex_stream_node.h>
+#include <trex_stream.h>
+#include <trex_stateless_port.h>
+#include <trex_rpc_server_api.h>
#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<TrexStream *> 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