diff options
-rw-r--r-- | scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py | 7 | ||||
-rw-r--r-- | scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py | 34 | ||||
-rw-r--r-- | scripts/exp/udp_1pkt_pcap_relative_path.pcap | bin | 0 -> 252 bytes | |||
-rw-r--r-- | scripts/stl/udp_1pkt_pcap_relative_path.py | 19 |
4 files changed, 54 insertions, 6 deletions
diff --git a/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py b/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py index cfdba3c3..d37b9f50 100644 --- a/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py +++ b/scripts/automation/regression/unit_tests/functional_tests/stl_basic_tests.py @@ -147,7 +147,7 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): self.golden_run("basic_tuple_gen", "imix_tuple_gen", "-m 50kpps --limit 500 --cores 8", silent = False) def test_stl_profiles (self): - p = [ + p1 = [ ["udp_1pkt_1mac_override.py","-m 1 -l 50",True], ["syn_attack.py","-m 1 -l 50",False], # can't compare random now ["udp_1pkt_1mac.py","-m 1 -l 50",True], @@ -172,12 +172,13 @@ class CStlBasic_Test(functional_general_test.CGeneralFunctional_Test): ["yaml/imix_1pkt_vm.yaml","-m 1 -l 100",True], ["udp_1pkt_pcap.py","-m 1 -l 10",True], ["udp_3pkt_pcap.py","-m 1 -l 10",True], - ["udp_1pkt_simple.py","-m 1 -l 3",True] + ["udp_1pkt_simple.py","-m 1 -l 3",True], + ["udp_1pkt_pcap_relative_path.py","-m 1 -l 3",True] ]; - p0 =[ ["udp_1pkt_simple.py","-m 1 -l 3",True] ] + p =[ ["udp_1pkt_pcap_relative_path.py","-m 1 -l 3",True] ] for obj in p: 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 ca02f004..de96350a 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 @@ -6,6 +6,7 @@ import json import yaml import binascii import base64 +import inspect from trex_stl_packet_builder_interface import CTrexPktBuilderInterface @@ -591,8 +592,10 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): This class defines the TRex API of building a packet using dpkt package. Using this class the user can also define how TRex will handle the packet by specifying the VM setting. pkt could be Scapy pkt or pcap file name + + When path_relative_to_profile is True load pcap file from path relative to the profile """ - def __init__(self, pkt = None, pkt_buffer = None, vm = None): + def __init__(self, pkt = None, pkt_buffer = None, vm = None, path_relative_to_profile = False): """ Instantiate a CTRexPktBuilder object @@ -607,6 +610,8 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): self.vm_scripts = [] # list of high level instructions self.vm_low_level = None self.metadata="" + self.path_relative_to_profile = path_relative_to_profile + was_set=False if pkt != None and pkt_buffer != None: @@ -703,6 +708,7 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): assert type(pkt_buffer)==str, "pkt_buffer should be string" self.pkt_raw = pkt_buffer + def set_pcap_file (self, pcap_file): """ load raw pcap file into a buffer. load only the first packet @@ -714,8 +720,9 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): + :exc:`AssertionError`, in case packet is empty. """ + f_path = self._get_pcap_file_path (pcap_file) - p=RawPcapReader(pcap_file) + p=RawPcapReader(f_path) was_set = False for pkt in p: @@ -723,7 +730,7 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): self.pkt_raw = str(pkt[0]) break if not was_set : - raise CTRexPacketBuildException(-14, "no buffer inside the pcap file") + raise CTRexPacketBuildException(-14, "no buffer inside the pcap file {0}".format(f_path)) def set_packet (self, pkt): """ @@ -759,6 +766,27 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): #################################################### # private + + def _get_pcap_file_path (self,pcap_file_name): + f_path = pcap_file_name + if os.path.isabs(pcap_file_name): + f_path = pcap_file_name + else: + if self.path_relative_to_profile: + p = self._get_path_relative_to_profile () # loader + if p : + f_path=os.path.abspath(os.path.join(os.path.dirname(p),pcap_file_name)) + + return f_path + + + def _get_path_relative_to_profile (self): + p = inspect.stack() + for obj in p: + if obj[3]=='get_streams': + return obj[1] + return None + def _compile_raw (self,obj): # make sure we have varibles once diff --git a/scripts/exp/udp_1pkt_pcap_relative_path.pcap b/scripts/exp/udp_1pkt_pcap_relative_path.pcap Binary files differnew file mode 100644 index 00000000..56ae1bac --- /dev/null +++ b/scripts/exp/udp_1pkt_pcap_relative_path.pcap diff --git a/scripts/stl/udp_1pkt_pcap_relative_path.py b/scripts/stl/udp_1pkt_pcap_relative_path.py new file mode 100644 index 00000000..91b32d0f --- /dev/null +++ b/scripts/stl/udp_1pkt_pcap_relative_path.py @@ -0,0 +1,19 @@ +from trex_stl_lib.api import * + +# stream from pcap file. continues pps 10 in sec +# path_relative_to_profile = True + +class STLS1(object): + + def get_streams (self, direction = 0): + return [STLStream(packet = STLPktBuilder(pkt ="yaml/udp_64B_no_crc.pcap", + path_relative_to_profile = True), # path relative to profile and not to loader path + mode = STLTXCont(pps=10)) ] #rate continues, could be STLTXSingleBurst,STLTXMultiBurst + + +# dynamic load - used for trex console or simulator +def register(): + return STLS1() + + + |