diff options
9 files changed, 154 insertions, 6 deletions
diff --git a/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py b/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py index a9f28ba3..f0dc9dc4 100644 --- a/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py +++ b/scripts/automation/regression/unit_tests/functional_tests/scapy_pkt_builder_test.py @@ -73,6 +73,32 @@ class CTRexPktBuilderSanitySCapy_Test(pkt_bld_general_test.CGeneralPktBld_Test): ) + def test_simple_mac_default(self): + + pkt = Ether()/IP()/UDP() + + + pkt_builder = CScapyTRexPktBuilder(pkt = pkt); + + assert_equal( pkt_builder.is_def_src_mac () ,True) + assert_equal( pkt_builder.is_def_dst_mac () ,True) + + pkt = Ether(src="00:00:00:00:00:01")/IP()/UDP() + + pkt_builder = CScapyTRexPktBuilder(pkt = pkt); + + assert_equal( pkt_builder.is_def_src_mac (), False) + assert_equal( pkt_builder.is_def_dst_mac (), True) + + pkt = Ether(dst="00:00:00:00:00:01")/IP()/UDP() + + pkt_builder = CScapyTRexPktBuilder(pkt = pkt); + + assert_equal( pkt_builder.is_def_src_mac (),True) + assert_equal( pkt_builder.is_def_dst_mac (),False) + + + def test_simple_teredo(self): diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py index f1462ede..1e2286c5 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py @@ -751,7 +751,21 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): else: raise CTRexPacketBuildException(-14, "bad packet" ) - + def is_def_src_mac (self): + p = self.pkt + if isinstance(p, Packet): + if isinstance(p,Ether): + if 'src' in p.fields : + return False + return True + + def is_def_dst_mac (self): + p = self.pkt + if isinstance(p, Packet): + if isinstance(p,Ether): + if 'dst' in p.fields : + return False + return True def compile (self): self.vm_low_level=CTRexVmEngine() diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py index efeb5c8a..68f8f694 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py @@ -93,6 +93,11 @@ class STLTXMultiBurst(STLTXMode): def __str__ (self): return "Multi Burst" +STLStreamDstMAC_CFG_FILE=0 +STLStreamDstMAC_PKT =1 +STLStreamDstMAC_ARP =2 + + class STLStream(object): @@ -105,7 +110,11 @@ class STLStream(object): isg = 0.0, rx_stats = None, next = None, - stream_id = None): + stream_id = None, + action_count =0, + mac_src_override_by_pkt=None, + mac_dst_override_mode=None #see STLStreamDstMAC_xx + ): # type checking if not isinstance(mode, STLTXMode): @@ -134,8 +143,35 @@ class STLStream(object): self.set_id(stream_id) self.set_next_id(None) + self.fields = {} + int_mac_src_override_by_pkt = 0; + int_mac_dst_override_mode = 0; + + + if mac_src_override_by_pkt == None: + int_mac_src_override_by_pkt=0 + if packet : + if packet.is_def_src_mac ()==False: + int_mac_src_override_by_pkt=1 + + else: + int_mac_src_override_by_pkt = int(mac_src_override_by_pkt); + + if mac_dst_override_mode == None: + int_mac_dst_override_mode = 0; + if packet : + if packet.is_def_dst_mac ()==False: + int_mac_dst_override_mode=STLStreamDstMAC_PKT + else: + int_mac_dst_override_mode = int(mac_dst_override_mode); + + + self.fields['flags'] = (int_mac_src_override_by_pkt&1) + ((int_mac_dst_override_mode&3)<<1) + + self.fields['action_count'] = action_count + # basic fields self.fields['enabled'] = enabled self.fields['self_start'] = self_start @@ -327,7 +363,11 @@ class YAMLLoader(object): self_start = s_obj.get('self_start', defaults.fields['self_start']), isg = s_obj.get('isg', defaults.fields['isg']), rx_stats = s_obj.get('rx_stats', defaults.fields['rx_stats']), - next = yaml_object.get('next')) + next = yaml_object.get('next'), + action_count = s_obj.get('action_count', defaults.fields['action_count']), + mac_src_override_by_pkt = s_obj.get('mac_src_override_by_pkt', 0), + mac_dst_override_mode = s_obj.get('mac_src_override_by_pkt', 0) + ) # hack the VM fields for now if 'vm' in s_obj: diff --git a/scripts/stl/udp_1pkt_simple_mac_dst.py b/scripts/stl/udp_1pkt_simple_mac_dst.py new file mode 100644 index 00000000..6b728881 --- /dev/null +++ b/scripts/stl/udp_1pkt_simple_mac_dst.py @@ -0,0 +1,22 @@ +from trex_stl_lib.api import * + +# stream will be sent with src MAC addrees dst="60:60:60:60:60:60" and not from default of trex_cfg.yaml port src mac +class STLS1(object): + + def create_stream (self): + return STLStream( packet = STLPktBuilder(pkt = Ether(dst="60:60:60:60:60:60")/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/(10*'x')), + mode = STLTXCont(), + #mac_dst_override_mode=STLStreamDstMAC_PKT # another way to explictly take it + ) + + def get_streams (self, direction = 0): + # create 1 stream + return [ self.create_stream() ] + + +# dynamic load - used for trex console or simulator +def register(): + return STLS1() + + + diff --git a/scripts/stl/udp_1pkt_simple_mac_dst_src.py b/scripts/stl/udp_1pkt_simple_mac_dst_src.py new file mode 100644 index 00000000..e3df0d0d --- /dev/null +++ b/scripts/stl/udp_1pkt_simple_mac_dst_src.py @@ -0,0 +1,22 @@ +from trex_stl_lib.api import * + +# stream will be sent with src MAC addrees dst="60:60:60:60:60:60" and not from default of trex_cfg.yaml port src mac +class STLS1(object): + + def create_stream (self): + return STLStream( packet = STLPktBuilder(pkt = Ether(src="61:61:61:61:61:61",dst="60:60:60:60:60:60")/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/(10*'x')), + mode = STLTXCont(), + #mac_dst_override_mode=STLStreamDstMAC_PKT # another way to explictly take it + ) + + def get_streams (self, direction = 0): + # create 1 stream + return [ self.create_stream() ] + + +# dynamic load - used for trex console or simulator +def register(): + return STLS1() + + + diff --git a/scripts/stl/udp_1pkt_simple_mac_src.py b/scripts/stl/udp_1pkt_simple_mac_src.py new file mode 100644 index 00000000..fe5a2a80 --- /dev/null +++ b/scripts/stl/udp_1pkt_simple_mac_src.py @@ -0,0 +1,22 @@ +from trex_stl_lib.api import * + +# stream will be sent with src MAC addrees src="60:60:60:60:60:60" and not from default of trex_cfg.yaml port src mac +class STLS1(object): + + def create_stream (self): + return STLStream( packet = STLPktBuilder(pkt = Ether(src="60:60:60:60:60:60")/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/(10*'x')), + mode = STLTXCont(), + #mac_src_override_by_pkt=True # another way to explictly take it + ) + + def get_streams (self, direction = 0): + # create 1 stream + return [ self.create_stream() ] + + +# dynamic load - used for trex console or simulator +def register(): + return STLS1() + + + diff --git a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp index 650720be..87e205b0 100644 --- a/src/rpc-server/commands/trex_rpc_cmd_stream.cpp +++ b/src/rpc-server/commands/trex_rpc_cmd_stream.cpp @@ -56,6 +56,8 @@ TrexRpcCmdAddStream::_run(const Json::Value ¶ms, Json::Value &result) { /* some fields */ stream->m_enabled = parse_bool(section, "enabled", result); stream->m_self_start = parse_bool(section, "self_start", result); + stream->m_flags = parse_int(section, "flags", result); + stream->m_action_count = (uint16_t)parse_int(section, "action_count", result); /* inter stream gap */ stream->m_isg_usec = parse_double(section, "isg", result); diff --git a/src/stateless/cp/trex_stream.cpp b/src/stateless/cp/trex_stream.cpp index af35dbe9..fb0b35d5 100644 --- a/src/stateless/cp/trex_stream.cpp +++ b/src/stateless/cp/trex_stream.cpp @@ -131,7 +131,7 @@ TrexStream::TrexStream(uint8_t type, m_ibg_usec=0.0; m_vm_dp = NULL; m_flags=0; - m_stream_count=0; + m_action_count=0; } TrexStream::~TrexStream() { diff --git a/src/stateless/cp/trex_stream.h b/src/stateless/cp/trex_stream.h index 0f2a16c3..2ab90c99 100644 --- a/src/stateless/cp/trex_stream.h +++ b/src/stateless/cp/trex_stream.h @@ -228,7 +228,7 @@ public: 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; + dp->m_action_count = m_action_count; return(dp); } @@ -290,7 +290,7 @@ public: 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; + uint16_t m_action_count; /* config fields */ |