From 5e727474efe18b3800df6130c068e668fadd2e0b Mon Sep 17 00:00:00 2001 From: imarom Date: Wed, 23 Mar 2016 09:19:46 +0200 Subject: Python 3 - another drop (package fixups) --- .../stl/trex_stl_lib/utils/parsing_opts.py | 2 +- .../stl/trex_stl_lib/utils/pcap.py | 29 ++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/pcap.py (limited to 'scripts/automation/trex_control_plane/stl/trex_stl_lib/utils') diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py index 6ec2d189..c4f2b358 100755 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/parsing_opts.py @@ -225,7 +225,7 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], IPG: ArgumentPack(['-i', '--ipg'], {'help': "IPG value in usec between packets. default will be from the pcap", 'dest': "ipg_usec", - 'default': 100.0, + 'default': None, 'type': float}), diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/pcap.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/pcap.py new file mode 100644 index 00000000..ab4f98a7 --- /dev/null +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/utils/pcap.py @@ -0,0 +1,29 @@ +import os +from ..trex_stl_packet_builder_scapy import RawPcapReader, RawPcapWriter + + +def __ts_key (a): + return float(a[1][0]) + (float(a[1][1]) / 1e6) + +def merge_cap_files (pcap_file_list, out_filename, delete_src = False): + + if not all([os.path.exists(f) for f in pcap_file_list]): + print("failed to merge cap file list...\nnot all files exist\n") + return + + out_pkts = [] + for src in pcap_file_list: + pkts = RawPcapReader(src) + out_pkts += pkts + if delete_src: + os.unlink(src) + + # sort by timestamp + out_pkts = sorted(out_pkts, key = __ts_key) + + writer = RawPcapWriter(out_filename, linktype = 1) + + writer._write_header(None) + for pkt in out_pkts: + writer._write_packet(pkt[0], sec=pkt[1][0], usec=pkt[1][1], caplen=pkt[1][2], wirelen=None) + -- cgit