From 0af59f17029acc700b3a8bc569e05b5603d0a114 Mon Sep 17 00:00:00 2001 From: Hanoh Haim Date: Tue, 1 Mar 2016 13:49:56 +0200 Subject: add --pkt to stl-sim --- .../stl/trex_stl_lib/trex_stl_packet_builder_scapy.py | 13 +++++++++++++ .../trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py | 13 ++++++++++++- .../stl/trex_stl_lib/trex_stl_streams.py | 15 +++++++++++++++ scripts/stl/udp_1pkt_simple.py | 9 +++++++-- scripts/stl/udp_1pkt_vxlan.py | 3 ++- 5 files changed, 49 insertions(+), 4 deletions(-) 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 e27563eb..42d648a5 100644 --- 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 @@ -814,6 +814,19 @@ class CScapyTRexPktBuilder(CTrexPktBuilderInterface): if not was_set : raise CTRexPacketBuildException(-14, "no buffer inside the pcap file {0}".format(f_path)) + def to_pkt_dump(self): + p = self.pkt + if p and isinstance(p, Packet): + p.show2(); + hexdump(p); + return; + p = self.pkt_raw; + if p: + scapy_pkt = Ether(p); + scapy_pkt.show2(); + hexdump(p); + + def set_packet (self, pkt): """ Scapy packet Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/IP()/"A"*10 diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py index 54d699d8..9db34737 100644 --- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py +++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_sim.py @@ -123,7 +123,7 @@ class STLSim(object): duration = -1, mode = 'none'): - if not mode in ['none', 'gdb', 'valgrind', 'json', 'yaml']: + if not mode in ['none', 'gdb', 'valgrind', 'json', 'yaml','pkt']: raise STLArgumentError('mode', mode) # listify @@ -208,6 +208,10 @@ class STLSim(object): elif mode == 'yaml': print STLProfile(stream_list).dump_to_yaml() return + elif mode == 'pkt': + print STLProfile(stream_list).dump_as_pkt(); + return + # start simulation self.outfile = outfile @@ -392,6 +396,11 @@ def setParserOptions(): action = "store_true", default = False) + group.add_argument("--pkt", + help = "Parse the packet and show it as hex", + action = "store_true", + default = False) + group.add_argument("--yaml", help = "generate YAML from input file [default is False]", action = "store_true", @@ -427,6 +436,8 @@ def main (): mode = 'json' elif options.yaml: mode = 'yaml' + elif options.pkt: + mode = 'pkt' else: mode = 'none' 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 7964992b..24acd28b 100644 --- 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 @@ -224,6 +224,7 @@ class STLStream(object): if not packet: packet = CScapyTRexPktBuilder(pkt = Ether()/IP()) + self.scapy_pkt_builder = packet # packet builder packet.compile() @@ -299,6 +300,14 @@ class STLStream(object): def get_rate (self): return self.get_rate_from_field(self.fields['mode']['rate']) + def to_pkt_dump (self): + scapy_b = self.scapy_pkt_builder; + if scapy_b and isinstance(scapy_b,CScapyTRexPktBuilder): + scapy_b.to_pkt_dump() + else: + print "Nothing to dump" + + def to_yaml (self): y = {} @@ -598,6 +607,12 @@ class STLProfile(object): return profile + def dump_as_pkt (self): + cnt=0; + for stream in self.streams: + print "Stream %d" % cnt + cnt = cnt +1 + stream.to_pkt_dump() def dump_to_yaml (self, yaml_file = None): yaml_list = [stream.to_yaml() for stream in self.streams] diff --git a/scripts/stl/udp_1pkt_simple.py b/scripts/stl/udp_1pkt_simple.py index 2a2c8838..09643fe9 100644 --- a/scripts/stl/udp_1pkt_simple.py +++ b/scripts/stl/udp_1pkt_simple.py @@ -3,8 +3,13 @@ from trex_stl_lib.api import * class STLS1(object): def create_stream (self): - return STLStream( packet = STLPktBuilder(pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/(10*'x')), - mode = STLTXCont()) + return STLStream( + packet = + STLPktBuilder( + pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/ + UDP(dport=12,sport=1025)/(10*'x') + ), + mode = STLTXCont()) def get_streams (self, direction = 0): # create 1 stream diff --git a/scripts/stl/udp_1pkt_vxlan.py b/scripts/stl/udp_1pkt_vxlan.py index 3cb3dfbb..9d56fe36 100644 --- a/scripts/stl/udp_1pkt_vxlan.py +++ b/scripts/stl/udp_1pkt_vxlan.py @@ -30,7 +30,8 @@ class STLS1(object): def create_stream (self): pkt = Ether()/IP()/UDP(sport=1337,dport=4789)/VXLAN(vni=42)/Ether()/IP()/('x'*20) - pkt.show2() + #pkt.show2() + #hexdump(pkt) # burst of 17 packets return STLStream(packet = STLPktBuilder(pkt = pkt ,vm = []), -- cgit 1.2.3-korg