diff options
author | 2016-05-10 15:36:33 +0300 | |
---|---|---|
committer | 2016-05-10 15:37:42 +0300 | |
commit | 63bf6aba10075a03fe6609369c1c7008afb85ba7 (patch) | |
tree | 8ab016390f9fb07cc29d500120a039b226a0798e /scripts/automation/trex_control_plane/stl/trex_stl_lib | |
parent | 6daea438c392fda4c765d2afa46a34d691799bd7 (diff) |
PCAP API - added packet hook
example is much simpler now
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib')
3 files changed, 45 insertions, 7 deletions
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py index 7f6f3c0d..010d966c 100755 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py @@ -1935,7 +1935,9 @@ class STLClient(object): speedup = 1.0, count = 1, duration = -1, - force = False): + force = False, + vm = None, + packet_hook = None): """ Push a local PCAP to the server This is equivalent to loading a PCAP file to a profile @@ -1965,6 +1967,12 @@ class STLClient(object): force: bool Ignore file size limit - push any file size to the server + vm: list of VM instructions + VM instructions to apply for every packet + + packet_hook : Callable or function + Will be applied to every packet + :raises: + :exc:`STLError` @@ -1977,7 +1985,8 @@ class STLClient(object): validate_type('speedup', speedup, (float, int)) validate_type('count', count, int) validate_type('duration', duration, (float, int)) - + validate_type('vm', vm, (list, type(None))) + # no support for > 1MB PCAP - use push remote if not force and os.path.getsize(pcap_filename) > (1024 * 1024): raise STLError("PCAP size of {:} is too big for local push - consider using remote push or provide 'force'".format(format_num(os.path.getsize(pcap_filename), suffix = 'B'))) @@ -1987,8 +1996,9 @@ class STLClient(object): profile = STLProfile.load_pcap(pcap_filename, ipg_usec, speedup, - count) - + count, + vm = vm, + packet_hook = packet_hook) id_list = self.add_streams(profile.get_streams(), ports) @@ -2077,7 +2087,6 @@ class STLClient(object): if not type(clear_global) is bool: raise STLArgumentError('clear_global', clear_global) - rc = self.__clear_stats(ports, clear_global, clear_flow_stats) if not rc: raise STLError(rc) 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 f8517a47..8c711563 100755 --- 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 @@ -1479,4 +1479,27 @@ class STLPktBuilder(CTrexPktBuilderInterface): pass; +def STLIPRange (src = None, + dst = None, + fix_chksum = True): + + vm = [] + + if src: + vm += [ + STLVmFlowVar(name="src", min_value = src['start'], max_value = src['end'], size = 4, op = "inc", step = src['step']), + STLVmWrFlowVar(fv_name="src",pkt_offset= "IP.src") + ] + + if dst: + vm += [ + STLVmFlowVar(name="dst", min_value = dst['start'], max_value = dst['end'], size = 4, op = "inc", step = dst['step']), + STLVmWrFlowVar(fv_name="dst",pkt_offset= "IP.dst") + ] + + if fix_chksum: + vm.append( STLVmFixIpv4(offset = "IP")) + + + return vm 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 92598312..a7fd3026 100755 --- 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 @@ -928,7 +928,7 @@ class STLProfile(object): # loop_count = 0 means loop forever @staticmethod - def load_pcap (pcap_file, ipg_usec = None, speedup = 1.0, loop_count = 1, vm = None): + def load_pcap (pcap_file, ipg_usec = None, speedup = 1.0, loop_count = 1, vm = None, packet_hook = None): """ Convert a pcap file with a number of packets to a list of connected streams. packet1->packet2->packet3 etc @@ -950,6 +950,9 @@ class STLProfile(object): vm : list List of Field engine instructions + packet_hook : Callable or function + will be applied to every packet + :return: STLProfile """ @@ -973,7 +976,10 @@ class STLProfile(object): except Scapy_Exception as e: raise STLError("failed to open PCAP file '{0}'".format(pcap_file)) - + if packet_hook: + pkts = [(packet_hook(cap), meta) for (cap, meta) in pkts] + + for i, (cap, meta) in enumerate(pkts, start = 1): # IPG - if not provided, take from cap if ipg_usec == None: |