diff options
author | 2015-12-16 12:19:52 +0200 | |
---|---|---|
committer | 2015-12-16 12:19:52 +0200 | |
commit | a1fbf1730da1b7db6270cd9aa84fa1c63f3f3932 (patch) | |
tree | 1a870baaf99262e13476f5d3ea9c0be696c469b8 /scripts/automation/trex_control_plane/client_utils | |
parent | 31b92c62f1ce84ba44c9fdf6c2f12ae51655f86c (diff) | |
parent | f0919e280a6a7b74a52f05b8e6f591e1b7e08200 (diff) |
Merge from master
Diffstat (limited to 'scripts/automation/trex_control_plane/client_utils')
-rwxr-xr-x | scripts/automation/trex_control_plane/client_utils/packet_builder.py | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/scripts/automation/trex_control_plane/client_utils/packet_builder.py b/scripts/automation/trex_control_plane/client_utils/packet_builder.py index 3aeb6a34..d8070c74 100755 --- a/scripts/automation/trex_control_plane/client_utils/packet_builder.py +++ b/scripts/automation/trex_control_plane/client_utils/packet_builder.py @@ -301,6 +301,30 @@ class CTRexPktBuilder(object): break return + def load_packet_from_pcap(self, pcap_path): + """ + This method loads a pcap file into a parsed packet builder object. + + :parameters: + pcap_path: str + a path to a pcap file, containing a SINGLE packet. + + :raises: + + :exc:`IOError`, in case provided path doesn't exists. + + """ + with open(pcap_path, 'r') as f: + pcap = dpkt.pcap.Reader(f) + first_packet = True + for _, buf in pcap: + # this is an iterator, can't evaluate the number of files in advance + if first_packet: + self.load_packet(dpkt.ethernet.Ethernet(buf)) + else: + raise ValueError("Provided pcap file contains more than single packet.") + # arrive here ONLY if pcap contained SINGLE packet + return + def get_packet(self, get_ptr=False): """ This method provides access to the built packet, as an instance or as a pointer to packet itself. |