diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/bp_gtest.cpp | 7 | ||||
-rwxr-xr-x | src/bp_sim.cpp | 12 | ||||
-rwxr-xr-x | src/bp_sim.h | 9 | ||||
-rwxr-xr-x | src/common/captureFile.cpp | 27 | ||||
-rwxr-xr-x | src/common/captureFile.h | 2 | ||||
-rw-r--r-- | src/gtest/trex_stateless_gtest.cpp | 80 | ||||
-rwxr-xr-x | src/main.cpp | 10 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream.cpp | 2 | ||||
-rw-r--r-- | src/stateless/cp/trex_stream.h | 35 | ||||
-rw-r--r-- | src/stateless/dp/trex_stateless_dp_core.cpp | 47 | ||||
-rw-r--r-- | src/stateless/dp/trex_stateless_dp_core.h | 5 | ||||
-rw-r--r-- | src/stateless/dp/trex_stream_node.h | 8 |
12 files changed, 225 insertions, 19 deletions
diff --git a/src/bp_gtest.cpp b/src/bp_gtest.cpp index 8d6a7b83..e312abc7 100755 --- a/src/bp_gtest.cpp +++ b/src/bp_gtest.cpp @@ -200,6 +200,7 @@ public: lpt->m_node_gen.DumpHist(stdout); cmp.d_sec = m_time_diff; + //compare if ( cmp.compare(std::string(buf),std::string(buf_ex)) != true ) { res=false; } @@ -686,14 +687,14 @@ bool verify_latency_pkt(uint8_t *p, uint8_t proto, uint16_t icmp_seq, uint8_t icmp_type) { EthernetHeader *eth = (EthernetHeader *)p; IPHeader *ip = (IPHeader *)(p + 14); - uint8_t srcmac[]={0,0,0,1,0,0}; - uint8_t dstmac[]={0,0,0,1,0,0}; + uint8_t srcmac[]={0x10,0x10,0x10,0x10,0x10,0x10}; + //uint8_t dstmac[]={0x0,0x0,0x0,0x0,0x0,0x0}; latency_header * h; // eth EXPECT_EQ_UINT32(eth->getNextProtocol(), 0x0800)<< "Failed ethernet next protocol check"; EXPECT_EQ_UINT32(memcmp(p, srcmac, 6), 0)<< "Failed ethernet source MAC check"; - EXPECT_EQ_UINT32(memcmp(p, dstmac, 6), 0)<< "Failed ethernet dest MAC check"; + //EXPECT_EQ_UINT32(memcmp(p, dstmac, 6), 0)<< "Failed ethernet dest MAC check"; // IP EXPECT_EQ_UINT32(ip->getSourceIp(), l_pkt_test_s_ip)<< "Failed IP src check"; EXPECT_EQ_UINT32(ip->getDestIp(), l_pkt_test_d_ip)<< "Failed IP dst check"; diff --git a/src/bp_sim.cpp b/src/bp_sim.cpp index 72ad1097..a1851b55 100755 --- a/src/bp_sim.cpp +++ b/src/bp_sim.cpp @@ -4726,6 +4726,17 @@ void CErfIF::fill_raw_packet(rte_mbuf_t * m,CGenNode * node,pkt_dir_t dir){ } +pkt_dir_t CErfIFStl::port_id_to_dir(uint8_t port_id) { + return ((pkt_dir_t)(port_id&1)); +} + + +int CErfIFStl::update_mac_addr_from_global_cfg(pkt_dir_t dir, uint8_t * p){ + memcpy(p,CGlobalInfo::m_options.get_dst_src_mac_addr(dir),12); + return (0); +} + + int CErfIFStl::send_node(CGenNode * _no_to_use){ if ( m_preview_mode->getFileWrite() ){ @@ -4757,6 +4768,7 @@ int CErfIFStl::send_node(CGenNode * _no_to_use){ } + int CErfIF::send_node(CGenNode * node){ if ( m_preview_mode->getFileWrite() ){ diff --git a/src/bp_sim.h b/src/bp_sim.h index 9f08cdc9..a51a520d 100755 --- a/src/bp_sim.h +++ b/src/bp_sim.h @@ -1846,6 +1846,12 @@ class CErfIFStl : public CErfIF { public: virtual int send_node(CGenNode * node); + + virtual int update_mac_addr_from_global_cfg(pkt_dir_t dir, uint8_t * p); + + virtual pkt_dir_t port_id_to_dir(uint8_t port_id); + + }; /** @@ -1872,9 +1878,6 @@ public: } - virtual int update_mac_addr_from_global_cfg(pkt_dir_t dir, uint8_t * p){ - return (0); - } virtual int flush_tx_queue(void){ diff --git a/src/common/captureFile.cpp b/src/common/captureFile.cpp index 00625181..e73c37ad 100755 --- a/src/common/captureFile.cpp +++ b/src/common/captureFile.cpp @@ -157,6 +157,33 @@ bool CCapPktRaw::Compare(CCapPktRaw * obj,int dump,double dsec){ } } +#define CPY_BUFSIZE 1024 + +bool CErfCmp::cpy(std::string src,std::string dst){ + + char mybuf[CPY_BUFSIZE] ; + FILE *ifd = NULL; + FILE *ofd = NULL; + ifd = fopen( src.c_str(), "rb" ); + ofd = fopen( dst.c_str(), "w+"); + assert(ifd!=NULL); + assert(ofd!=NULL); + + int n; + while ( true){ + n = fread(mybuf, sizeof(char), CPY_BUFSIZE ,ifd); + if (n>0) { + fwrite(mybuf, sizeof(char),n,ofd); + }else{ + break; + } + } + + fclose(ifd); + fclose(ofd); + return true; +} + bool CErfCmp::compare(std::string f1, std::string f2 ){ diff --git a/src/common/captureFile.h b/src/common/captureFile.h index 16a6120b..3be83432 100755 --- a/src/common/captureFile.h +++ b/src/common/captureFile.h @@ -279,6 +279,8 @@ public: d_sec=0.001; } bool compare(std::string f1, std::string f2 ); + + bool cpy(std::string src,std::string dst); public: bool dump; double d_sec; diff --git a/src/gtest/trex_stateless_gtest.cpp b/src/gtest/trex_stateless_gtest.cpp index fc6c8152..68f9a4b7 100644 --- a/src/gtest/trex_stateless_gtest.cpp +++ b/src/gtest/trex_stateless_gtest.cpp @@ -1437,6 +1437,7 @@ public: //lpt->m_node_gen.DumpHist(stdout); cmp.d_sec = m_time_diff; + if ( cmp.compare(std::string(buf),std::string(buf_ex)) != true ) { res=false; } @@ -2221,6 +2222,7 @@ TEST_F(basic_stl, single_pkt_burst1) { + TEST_F(basic_stl, single_pkt) { CBasicStl t1; @@ -2267,6 +2269,84 @@ TEST_F(basic_stl, single_pkt) { EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; } +void test_mac_replace(bool replace_src_by_pkt, + int replace_dst_mode, + std::string file){ + CBasicStl t1; + CParserOption * po =&CGlobalInfo::m_options; + po->preview.setVMode(7); + po->preview.setFileWrite(true); + po->out_file = file; + + TrexStreamsCompiler compile; + + uint8_t port_id=0; + + std::vector<TrexStream *> streams; + + TrexStream * stream1 = new TrexStream(TrexStream::stCONTINUOUS,0,0); + stream1->set_override_src_mac_by_pkt_data(replace_src_by_pkt); + stream1->set_override_dst_mac_mode((TrexStream::stream_dst_mac_t)replace_dst_mode); + + stream1->set_pps(1.0); + + + 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 + + std::vector<TrexStreamsCompiledObj *>objs; + assert(compile.compile(port_id, streams, objs)); + TrexStatelessDpStart *lpstart = new TrexStatelessDpStart(port_id, 0, objs[0], 10.0 /*sec */ ); + + + t1.m_msg = lpstart; + + bool res=t1.init(); + + delete stream1 ; + + EXPECT_EQ_UINT32(1, res?1:0)<< "pass"; +} + +TEST_F(basic_stl, single_pkt_mac0) { + + test_mac_replace(false, + TrexStream::stCFG_FILE, + "exp/stl_single_stream_mac0"); +} + +TEST_F(basic_stl, single_pkt_mac11) { + + test_mac_replace(true, + TrexStream::stPKT, + "exp/stl_single_stream_mac11"); +} + +TEST_F(basic_stl, single_pkt_mac10) { + + test_mac_replace(false, + TrexStream::stPKT, + "exp/stl_single_stream_mac01"); +} + +TEST_F(basic_stl, single_pkt_mac01) { + + test_mac_replace(true, + TrexStream::stCFG_FILE, + "exp/stl_single_stream_mac10"); +} + TEST_F(basic_stl, multi_pkt1) { diff --git a/src/main.cpp b/src/main.cpp index a2d06067..6ee3a03d 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -238,6 +238,15 @@ static int parse_options(int argc, return 0; } +void set_default_mac_addr(){ + + int i; + for (i=0; i<4; i++) { + memset(CGlobalInfo::m_options.get_dst_src_mac_addr(i),((i+1)<<4),6); + memset(CGlobalInfo::m_options.get_src_mac_addr(i),((i+1)<<4)+8,6); + } +} + int main(int argc , char * argv[]){ @@ -246,6 +255,7 @@ int main(int argc , char * argv[]){ if ( parse_options(argc, argv, &CGlobalInfo::m_options , params) != 0) { exit(-1); } + set_default_mac_addr(); opt_type_e type = (opt_type_e) params["type"]; diff --git a/src/stateless/cp/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp index 256f7de8..af35dbe9 100644 --- a/src/stateless/cp/trex_stream.cpp +++ b/src/stateless/cp/trex_stream.cpp @@ -130,6 +130,8 @@ TrexStream::TrexStream(uint8_t type, m_num_bursts=1; m_ibg_usec=0.0; m_vm_dp = NULL; + m_flags=0; + m_stream_count=0; } TrexStream::~TrexStream() { diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h index 72e7bb8b..0f2a16c3 100644 --- a/src/stateless/cp/trex_stream.h +++ b/src/stateless/cp/trex_stream.h @@ -33,6 +33,8 @@ limitations under the License. #include <stdio.h> #include <string.h> #include <common/captureFile.h> +#include <common/bitMan.h> + class TrexRpcCmdAddStream; @@ -118,6 +120,15 @@ public: typedef uint8_t stream_type_t ; + enum DST_MAC_TYPE { + stCFG_FILE = 0, + stPKT = 1, + stARP = 2 + }; + + typedef uint8_t stream_dst_mac_t ; + + static std::string get_stream_type_str(stream_type_t stream_type); public: @@ -163,8 +174,6 @@ public: return (true); } } - - /* can this stream be split ? */ bool is_splitable(uint8_t dp_core_count) const { @@ -218,6 +227,8 @@ public: dp->m_burst_total_pkts = m_burst_total_pkts; dp->m_num_bursts = m_num_bursts; dp->m_ibg_usec = m_ibg_usec; + dp->m_flags = m_flags; + dp->m_stream_count = m_stream_count; return(dp); } @@ -256,10 +267,30 @@ public: void vm_compile(); public: + + void set_override_src_mac_by_pkt_data(bool enable){ + btSetMaskBit16(m_flags,0,0,enable?1:0); + } + + bool get_override_src_mac_by_pkt_data(){ + return (btGetMaskBit16(m_flags,0,0) ?true:false); + } + + void set_override_dst_mac_mode(stream_dst_mac_t val){ + btSetMaskBit16(m_flags,2,1,val&0x3); + } + + stream_dst_mac_t get_override_dst_mac_mode(){ + return ((stream_dst_mac_t)btGetMaskBit16(m_flags,2,1)); + } + +public: /* basic */ uint8_t m_type; uint8_t m_port_id; + uint16_t m_flags; uint32_t m_stream_id; /* id from RPC can be anything */ + uint16_t m_stream_count; /* config fields */ diff --git a/src/stateless/dp/trex_stateless_dp_core.cpp b/src/stateless/dp/trex_stateless_dp_core.cpp index a80efc08..a84269ab 100644 --- a/src/stateless/dp/trex_stateless_dp_core.cpp +++ b/src/stateless/dp/trex_stateless_dp_core.cpp @@ -506,6 +506,43 @@ TrexStatelessDpCore::add_port_duration(double duration, } +void TrexStatelessDpCore::update_mac_addr(TrexStream * stream, + CGenNodeStateless *node, + pkt_dir_t dir, + char *raw_pkt){ + bool ov_src = stream->get_override_src_mac_by_pkt_data(); + TrexStream::stream_dst_mac_t ov_dst = stream->get_override_dst_mac_mode(); + + + if ( (ov_src == true) && (ov_dst == TrexStream::stPKT) ) { + /* nothing to do, take from the packet both */ + return; + } + + /* take from cfg_file */ + if ( (ov_src == false) && + (ov_dst == TrexStream::stCFG_FILE) ){ + + m_core->m_node_gen.m_v_if->update_mac_addr_from_global_cfg(dir,(uint8_t*)raw_pkt); + return; + } + + /* save the pkt*/ + char tmp_pkt[12]; + memcpy(tmp_pkt,raw_pkt,12); + + m_core->m_node_gen.m_v_if->update_mac_addr_from_global_cfg(dir,(uint8_t*)raw_pkt); + + if ((ov_src == true) && (ov_dst == TrexStream::stCFG_FILE)) { + memcpy(raw_pkt+6,tmp_pkt+6,6); + } + + if ((ov_src == false) && (ov_dst == TrexStream::stPKT)) { + memcpy(raw_pkt,tmp_pkt,6); + } +} + + void TrexStatelessDpCore::add_stream(TrexStatelessDpPerPort * lp_port, TrexStream * stream, @@ -561,7 +598,6 @@ TrexStatelessDpCore::add_stream(TrexStatelessDpPerPort * lp_port, node->m_single_burst=0; node->m_single_burst_refill=0; node->m_multi_bursts=0; - node->m_ibg_sec = 0.0; break; case TrexStream::stSINGLE_BURST : @@ -569,14 +605,12 @@ TrexStatelessDpCore::add_stream(TrexStatelessDpPerPort * lp_port, 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 : 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: @@ -605,8 +639,7 @@ TrexStatelessDpCore::add_stream(TrexStatelessDpPerPort * lp_port, /* copy the packet */ memcpy(p,stream_pkt,pkt_size); - /* TBD repace the mac if req we should add flag */ - m_core->m_node_gen.m_v_if->update_mac_addr_from_global_cfg(dir,(uint8_t*) p); + update_mac_addr(stream,node,dir,p); /* set the packet as a readonly */ node->set_cache_mbuf(m); @@ -659,8 +692,8 @@ TrexStatelessDpCore::add_stream(TrexStatelessDpPerPort * lp_port, assert(p); memcpy(p,stream_pkt , header_size); - /* TBD repace the mac if req we should add flag */ - m_core->m_node_gen.m_v_if->update_mac_addr_from_global_cfg(dir, p); + + update_mac_addr(stream,node,dir,(char *)p); } diff --git a/src/stateless/dp/trex_stateless_dp_core.h b/src/stateless/dp/trex_stateless_dp_core.h index c8a5eff5..3d214655 100644 --- a/src/stateless/dp/trex_stateless_dp_core.h +++ b/src/stateless/dp/trex_stateless_dp_core.h @@ -271,6 +271,11 @@ private: void add_global_duration(double duration); + void update_mac_addr(TrexStream * stream, + CGenNodeStateless *node, + uint8_t dir, + char *raw_pkt); + void add_stream(TrexStatelessDpPerPort * lp_port, TrexStream * stream, TrexStreamsCompiledObj *comp); diff --git a/src/stateless/dp/trex_stream_node.h b/src/stateless/dp/trex_stream_node.h index dfa4cc13..db7f19e8 100644 --- a/src/stateless/dp/trex_stream_node.h +++ b/src/stateless/dp/trex_stream_node.h @@ -81,8 +81,8 @@ private: void * m_cache_mbuf; double m_next_time_offset; /* in sec */ - double m_ibg_sec; /* inter burst time in sec */ - + uint32_t m_pad11; + uint32_t m_pad12; stream_state_t m_state; uint8_t m_port_id; @@ -167,7 +167,7 @@ public: } inline double get_multi_ibg_sec(){ - return (m_ibg_sec); + return (usec_to_sec(m_ref_stream_info->m_ibg_usec)); } inline uint32_t get_multi_burst_cnt(){ @@ -222,7 +222,7 @@ public: } }else{ - m_time += m_ibg_sec; + m_time += get_multi_ibg_sec(); m_single_burst = m_single_burst_refill; thread->m_node_gen.m_p_queue.push( (CGenNode *)this); } |