From 9fc980b8aa43cf53446eeeb5184f10a86476da28 Mon Sep 17 00:00:00 2001 From: Dan Klein Date: Thu, 7 Jan 2016 13:31:11 +0200 Subject: Working version of streams view in TRex console. TODO: sync when console crashes isn't integrated yet --- .../client_utils/packet_builder.py | 38 ++++++++++++++++++++++ .../client_utils/parsing_opts.py | 19 +++++++++++ .../trex_control_plane/client_utils/text_tables.py | 5 ++- 3 files changed, 59 insertions(+), 3 deletions(-) (limited to 'scripts/automation/trex_control_plane/client_utils') 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 d8070c74..19ac7f32 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 diff --git a/scripts/automation/trex_control_plane/client_utils/parsing_opts.py b/scripts/automation/trex_control_plane/client_utils/parsing_opts.py index 5cb06604..43c97a1d 100755 --- a/scripts/automation/trex_control_plane/client_utils/parsing_opts.py +++ b/scripts/automation/trex_control_plane/client_utils/parsing_opts.py @@ -23,12 +23,19 @@ FORCE = 11 DRY_RUN = 12 XTERM = 13 TOTAL = 14 +FULL_OUTPUT = 15 GLOBAL_STATS = 50 PORT_STATS = 51 PORT_STATUS = 52 STATS_MASK = 53 +STREAMS_MASK = 60 +# ALL_STREAMS = 61 +# STREAM_LIST_WITH_ALL = 62 + + + # list of ArgumentGroup types MUTEX = 1 @@ -221,6 +228,10 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], 'default': False, 'help': "Starts TUI in xterm window"}), + FULL_OUTPUT: ArgumentPack(['--full'], + {'action': 'store_true', + 'help': "Prompt full info in a JSON format"}), + GLOBAL_STATS: ArgumentPack(['-g'], {'action': 'store_true', 'help': "Fetch only global statistics"}), @@ -233,6 +244,14 @@ OPTIONS_DB = {MULTIPLIER: ArgumentPack(['-m', '--multiplier'], {'action': 'store_true', 'help': "Fetch only port status data"}), + STREAMS_MASK: ArgumentPack(['--streams'], + {"nargs": '+', + 'dest':'streams', + 'metavar': 'STREAMS', + 'type': int, + 'help': "A list of stream IDs to query about. Default: analyze all streams", + 'default': []}), + # advanced options PORT_LIST_WITH_ALL: ArgumentGroup(MUTEX, [PORT_LIST, diff --git a/scripts/automation/trex_control_plane/client_utils/text_tables.py b/scripts/automation/trex_control_plane/client_utils/text_tables.py index 2debca38..2fa17f09 100644 --- a/scripts/automation/trex_control_plane/client_utils/text_tables.py +++ b/scripts/automation/trex_control_plane/client_utils/text_tables.py @@ -22,12 +22,11 @@ class TRexTextInfo(Texttable): def generate_trex_stats_table(): pass -def print_table_with_header(texttable_obj, header=""): - header = header.replace("_", " ").title() +def print_table_with_header(texttable_obj, header="", untouched_header=""): + header = header.replace("_", " ").title() + untouched_header print format_text(header, 'cyan', 'underline') + "\n" print texttable_obj.draw() + "\n" - pass if __name__ == "__main__": pass -- cgit 1.2.3-korg