diff options
Diffstat (limited to 'src/gtest/trex_stateless_gtest.cpp')
-rw-r--r-- | src/gtest/trex_stateless_gtest.cpp | 454 |
1 files changed, 445 insertions, 9 deletions
diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp index c845c32e..93e8387f 100644 --- a/src/gtest/trex_stateless_gtest.cpp +++ b/src/gtest/trex_stateless_gtest.cpp @@ -1,5 +1,5 @@ /* - Hanoh Haim + Hanoch Haim Cisco Systems, Inc. */ @@ -29,7 +29,7 @@ limitations under the License. #include <trex_stream.h> #include <trex_stateless_port.h> #include <trex_rpc_server_api.h> - +#include <iostream> #define EXPECT_EQ_UINT32(a,b) EXPECT_EQ((uint32_t)(a),(uint32_t)(b)) @@ -91,6 +91,7 @@ public: lpt->start_stateless_daemon_simulation(); + //lpt->m_node_gen.DumpHist(stdout); cmp.d_sec = m_time_diff; @@ -109,7 +110,6 @@ public: return (res); } - public: int m_threads; double m_time_diff; @@ -224,6 +224,200 @@ TEST_F(basic_stl, load_pcap_file) { } + +TEST_F(basic_stl, simple_prog3) { + + CBasicStl t1; + CParserOption * po =&CGlobalInfo::m_options; + po->preview.setVMode(7); + po->preview.setFileWrite(true); + po->out_file ="exp/stl_simple_prog3"; + + TrexStreamsCompiler compile; + + + std::vector<TrexStream *> streams; + + /* stream1 */ + TrexStream * stream1 = new TrexStream(TrexStream::stSINGLE_BURST, 0,100); + stream1->set_pps(1.0); + stream1->set_single_burst(5); + stream1->m_enabled = true; + stream1->m_self_start = true; + stream1->m_next_stream_id=200; + + 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); + + + /* stream1 */ + + TrexStream * stream2 = new TrexStream(TrexStream::stMULTI_BURST, 0,200); + stream2->set_pps(1.0); + stream2->m_isg_usec = 1000000; /*time betwean stream 1 to stream 2 */ + stream2->m_enabled = true; + stream2->m_self_start = false; + stream2->set_multi_burst(5, + 3, + 2000000.0); + + // next stream is 100 - loop + stream2->m_next_stream_id=100; + + + pcap.load_pcap_file("cap2/udp_64B.pcap",0); + pcap.update_ip_src(0x10000002); + pcap.clone_packet_into_stream(stream2); + streams.push_back(stream2); + + + TrexStreamsCompiledObj comp_obj(0,1.0); + + EXPECT_TRUE(compile.compile(streams, comp_obj) ); + + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 50.0 ); + + + t1.m_msg = lpstart; + + bool res=t1.init(); + + delete stream1 ; + delete stream2 ; + + EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; +} + + +TEST_F(basic_stl, simple_prog2) { + + CBasicStl t1; + CParserOption * po =&CGlobalInfo::m_options; + po->preview.setVMode(7); + po->preview.setFileWrite(true); + po->out_file ="exp/stl_simple_prog2"; + + TrexStreamsCompiler compile; + + + std::vector<TrexStream *> streams; + + /* stream1 */ + TrexStream * stream1 = new TrexStream(TrexStream::stSINGLE_BURST, 0,100); + stream1->set_pps(1.0); + stream1->set_single_burst(5); + stream1->m_enabled = true; + stream1->m_self_start = true; + stream1->m_next_stream_id=200; + + 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); + + + /* stream1 */ + + TrexStream * stream2 = new TrexStream(TrexStream::stSINGLE_BURST, 0,200); + stream2->set_pps(1.0); + stream2->set_single_burst(5); + stream2->m_isg_usec = 2000000; /*time betwean stream 1 to stream 2 */ + stream2->m_enabled = true; + stream2->m_self_start = false; + + pcap.load_pcap_file("cap2/udp_64B.pcap",0); + pcap.update_ip_src(0x10000002); + pcap.clone_packet_into_stream(stream2); + streams.push_back(stream2); + + + TrexStreamsCompiledObj comp_obj(0,1.0); + + EXPECT_TRUE(compile.compile(streams, comp_obj) ); + + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 10.0 ); + + + t1.m_msg = lpstart; + + bool res=t1.init(); + + delete stream1 ; + delete stream2 ; + + EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; +} + + + +TEST_F(basic_stl, simple_prog1) { + + CBasicStl t1; + CParserOption * po =&CGlobalInfo::m_options; + po->preview.setVMode(7); + po->preview.setFileWrite(true); + po->out_file ="exp/stl_simple_prog1"; + + TrexStreamsCompiler compile; + + + std::vector<TrexStream *> streams; + + /* stream1 */ + TrexStream * stream1 = new TrexStream(TrexStream::stSINGLE_BURST, 0,100); + stream1->set_pps(1.0); + stream1->set_single_burst(5); + stream1->m_enabled = true; + stream1->m_self_start = true; + stream1->m_next_stream_id=200; + + 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); + + + /* stream1 */ + + TrexStream * stream2 = new TrexStream(TrexStream::stSINGLE_BURST, 0,200); + stream2->set_pps(1.0); + stream2->set_single_burst(5); + stream2->m_enabled = true; + stream2->m_self_start = false; + + pcap.load_pcap_file("cap2/udp_64B.pcap",0); + pcap.update_ip_src(0x10000002); + pcap.clone_packet_into_stream(stream2); + streams.push_back(stream2); + + + TrexStreamsCompiledObj comp_obj(0,1.0); + + EXPECT_TRUE(compile.compile(streams, comp_obj) ); + + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 10.0 ); + + + t1.m_msg = lpstart; + + bool res=t1.init(); + + delete stream1 ; + delete stream2 ; + + EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; +} + + + TEST_F(basic_stl, single_pkt_burst1) { CBasicStl t1; @@ -239,7 +433,7 @@ TEST_F(basic_stl, single_pkt_burst1) { TrexStream * stream1 = new TrexStream(TrexStream::stSINGLE_BURST, 0,0); stream1->set_pps(1.0); - stream1->set_signle_burtst(5); + stream1->set_single_burst(5); stream1->m_enabled = true; stream1->m_self_start = true; @@ -279,6 +473,7 @@ TEST_F(basic_stl, single_pkt) { TrexStreamsCompiler compile; + uint8_t port_id=0; std::vector<TrexStream *> streams; @@ -288,23 +483,23 @@ TEST_F(basic_stl, single_pkt) { stream1->m_enabled = true; stream1->m_self_start = true; + stream1->m_port_id= port_id; 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); // stream - clean - TrexStreamsCompiledObj comp_obj(0,1.0); + TrexStreamsCompiledObj comp_obj(port_id, 1.0 /*mul*/); assert(compile.compile(streams, comp_obj) ); - TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 10 ); + TrexStatelessDpStart * lpstart = new TrexStatelessDpStart( comp_obj.clone(), 10.0 /*sec */ ); t1.m_msg = lpstart; @@ -344,7 +539,7 @@ TEST_F(basic_stl, multi_pkt1) { streams.push_back(stream1); - TrexStream * stream2 = new TrexStream(TrexStream::stCONTINUOUS,0,0); + TrexStream * stream2 = new TrexStream(TrexStream::stCONTINUOUS,0,1); stream2->set_pps(2.0); stream2->m_enabled = true; @@ -482,6 +677,247 @@ TEST_F(basic_stl, multi_burst1) { EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; } +/********************************************* Itay Tests Start *************************************/ + +/** + * check that continous stream does not point to another stream + * (makes no sense) + */ +TEST_F(basic_stl, compile_bad_1) { + + TrexStreamsCompiler compile; + std::vector<TrexStream *> streams; + + TrexStream * stream1 = new TrexStream(TrexStream::stCONTINUOUS,0,2); + stream1->m_enabled = true; + stream1->set_pps(52.0); + stream1->m_next_stream_id = 3; + + streams.push_back(stream1); + + TrexStreamsCompiledObj comp_obj(0,1.0); + + std::string err_msg; + EXPECT_FALSE(compile.compile(streams, comp_obj, &err_msg)); + + delete stream1; + +} + +/** + * check for streams pointing to non exsistant streams + * + * @author imarom (16-Nov-15) + */ +TEST_F(basic_stl, compile_bad_2) { + + TrexStreamsCompiler compile; + std::vector<TrexStream *> streams; + + TrexStream * stream1 = new TrexStream(TrexStream::stSINGLE_BURST,0,1); + stream1->m_enabled = true; + stream1->set_pps(1.0); + stream1->set_single_burst(200); + + /* non existant next stream */ + stream1->m_next_stream_id = 5; + + TrexStream * stream2 = new TrexStream(TrexStream::stCONTINUOUS,0,2); + stream1->set_pps(52.0); + + streams.push_back(stream1); + streams.push_back(stream2); + + TrexStreamsCompiledObj comp_obj(0,1.0); + + std::string err_msg; + EXPECT_FALSE(compile.compile(streams, comp_obj, &err_msg)); + + delete stream1; + delete stream2; + +} + +/** + * check for "dead streams" in the mesh + * a streams that cannot be reached + * + * @author imarom (16-Nov-15) + */ +TEST_F(basic_stl, compile_bad_3) { + + TrexStreamsCompiler compile; + std::vector<TrexStream *> streams; + TrexStream *stream; + + /* stream 1 */ + stream = new TrexStream(TrexStream::stSINGLE_BURST, 0, 231); + stream->m_enabled = true; + stream->set_pps(1.0); + stream->set_single_burst(200); + + stream->m_next_stream_id = 5481; + stream->m_self_start = true; + + streams.push_back(stream); + + /* stream 2 */ + stream = new TrexStream(TrexStream::stCONTINUOUS, 0, 5481); + stream->m_enabled = true; + stream->m_next_stream_id = -1; + stream->m_self_start = false; + stream->set_pps(52.0); + + streams.push_back(stream); + + /* stream 3 */ + + stream = new TrexStream(TrexStream::stSINGLE_BURST, 0, 1928); + stream->m_enabled = true; + stream->set_pps(1.0); + stream->set_single_burst(200); + + stream->m_next_stream_id = -1; + stream->m_self_start = true; + + streams.push_back(stream); + + /* stream 4 */ + + stream = new TrexStream(TrexStream::stSINGLE_BURST, 0, 41231); + stream->m_enabled = true; + stream->set_pps(1.0); + stream->set_single_burst(200); + + stream->m_next_stream_id = 3928; + stream->m_self_start = false; + + streams.push_back(stream); + + /* stream 5 */ + + stream = new TrexStream(TrexStream::stSINGLE_BURST, 0, 3928); + stream->m_enabled = true; + stream->set_pps(1.0); + stream->set_single_burst(200); + + stream->m_next_stream_id = 41231; + stream->m_self_start = false; + + streams.push_back(stream); + + /* compile */ + TrexStreamsCompiledObj comp_obj(0,1.0); + + std::string err_msg; + EXPECT_FALSE(compile.compile(streams, comp_obj, &err_msg)); + + for (auto stream : streams) { + delete stream; + } + +} + +TEST_F(basic_stl, compile_with_warnings) { + + TrexStreamsCompiler compile; + std::vector<TrexStream *> streams; + TrexStream *stream; + + /* stream 1 */ + stream = new TrexStream(TrexStream::stSINGLE_BURST, 0, 231); + stream->m_enabled = true; + stream->set_pps(1.0); + stream->set_single_burst(200); + + stream->m_next_stream_id = 1928; + stream->m_self_start = true; + + streams.push_back(stream); + + /* stream 2 */ + stream = new TrexStream(TrexStream::stSINGLE_BURST, 0, 5481); + stream->m_enabled = true; + stream->m_next_stream_id = 1928; + stream->m_self_start = true; + stream->set_pps(52.0); + + streams.push_back(stream); + + /* stream 3 */ + + stream = new TrexStream(TrexStream::stSINGLE_BURST, 0, 1928); + stream->m_enabled = true; + stream->set_pps(1.0); + stream->set_single_burst(200); + + stream->m_next_stream_id = -1; + stream->m_self_start = true; + + streams.push_back(stream); + + + + /* compile */ + TrexStreamsCompiledObj comp_obj(0,1.0); + + std::string err_msg; + EXPECT_TRUE(compile.compile(streams, comp_obj, &err_msg)); + + EXPECT_TRUE(compile.get_last_compile_warnings().size() == 1); + + for (auto stream : streams) { + delete stream; + } + +} + + +TEST_F(basic_stl, compile_good_stream_id_compres) { + + TrexStreamsCompiler compile; + std::vector<TrexStream *> streams; + + TrexStream * stream1 = new TrexStream(TrexStream::stSINGLE_BURST,0,700); + stream1->m_self_start = true; + stream1->m_enabled = true; + stream1->set_pps(1.0); + stream1->set_single_burst(200); + + /* non existant next stream */ + stream1->m_next_stream_id = 800; + + + TrexStream * stream2 = new TrexStream(TrexStream::stSINGLE_BURST,0,800); + stream2->set_pps(52.0); + stream2->m_enabled = true; + stream2->m_next_stream_id = 700; + stream2->set_single_burst(300); + + + streams.push_back(stream1); + streams.push_back(stream2); + + TrexStreamsCompiledObj comp_obj(0,1.0); + + std::string err_msg; + EXPECT_TRUE(compile.compile(streams, comp_obj, &err_msg)); + + printf(" %s \n",err_msg.c_str()); + + comp_obj.Dump(stdout); + + EXPECT_EQ_UINT32(comp_obj.get_objects()[0].m_stream->m_stream_id,0); + EXPECT_EQ_UINT32(comp_obj.get_objects()[0].m_stream->m_next_stream_id,1); + + EXPECT_EQ_UINT32(comp_obj.get_objects()[1].m_stream->m_stream_id,1); + EXPECT_EQ_UINT32(comp_obj.get_objects()[1].m_stream->m_next_stream_id,0); + + delete stream1; + delete stream2; + +} +/********************************************* Itay Tests End *************************************/ |