diff options
author | Dan Klein <danklein10@gmail.com> | 2016-01-08 13:54:36 +0200 |
---|---|---|
committer | Dan Klein <danklein10@gmail.com> | 2016-01-08 13:54:36 +0200 |
commit | 8e037c2bd51844dc7c42ce7b2339806d9dcb964b (patch) | |
tree | cd45e5214e3db13f214a0e68b3fd37f366438b80 /scripts/automation/trex_control_plane/client_utils/packet_builder.py | |
parent | 8db09096b9dcf030b7dc744fbd7ee463d8e6fd1b (diff) | |
parent | 9fc980b8aa43cf53446eeeb5184f10a86476da28 (diff) |
Merge branch 'dan_stateless'
Added the support for "streams" command
Missing:
1. "--full" output
2. sync with server after crash
3. merging output for identical port streams
Diffstat (limited to 'scripts/automation/trex_control_plane/client_utils/packet_builder.py')
-rwxr-xr-x | scripts/automation/trex_control_plane/client_utils/packet_builder.py | 38 |
1 files changed, 38 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 1ca01a33..e7fdb5d9 100755 --- a/scripts/automation/trex_control_plane/client_utils/packet_builder.py +++ b/scripts/automation/trex_control_plane/client_utils/packet_builder.py @@ -9,6 +9,7 @@ import random import string import struct import re +import itertools from abc import ABCMeta, abstractmethod from collections import namedtuple @@ -325,6 +326,17 @@ class CTRexPktBuilder(object): # arrive here ONLY if pcap contained SINGLE packet return + def load_from_stream_obj(self, stream_obj): + self.load_packet_from_byte_list(stream_obj['packet']['binary']) + + + def load_packet_from_byte_list(self, byte_list): + # convert byte array into buffer + buf = struct.pack('B'*len(byte_list), *byte_list) + + # thn, load it based on dpkt parsing + self.load_packet(dpkt.ethernet.Ethernet(buf)) + 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. @@ -349,6 +361,9 @@ class CTRexPktBuilder(object): else: return copy.copy(self._packet) + def get_packet_length(self): + return len(self._packet) + def get_layer(self, layer_name): """ This method provides access to a specific layer of the packet, as a **copy of the layer instance**. @@ -502,6 +517,29 @@ class CTRexPktBuilder(object): except IOError: raise IOError(2, "The provided path could not be accessed") + def get_packet_layers(self, depth_limit=Ellipsis): + if self._packet is None: + raise CTRexPktBuilder.EmptyPacketError() + cur_layer = self._packet + layer_types = [] + if depth_limit == Ellipsis: + iterator = itertools.count(1) + else: + iterator = xrange(depth_limit) + for _ in iterator: + # append current layer type + if isinstance(cur_layer, dpkt.Packet): + layer_types.append(type(cur_layer).__name__) + else: + # if not dpkt layer, refer as payload + layer_types.append("PLD") + # advance to next layer + if not hasattr(cur_layer, "data"): + break + else: + cur_layer = cur_layer.data + return layer_types + def export_pkt(self, file_path, link_pcap=False, pcap_name=None, pcap_ts=None): pass |