summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl/examples
diff options
context:
space:
mode:
authorYaroslav Brustinov <ybrustin@cisco.com>2016-03-24 20:00:27 +0200
committerYaroslav Brustinov <ybrustin@cisco.com>2016-03-24 20:00:27 +0200
commit59f00264f39dfb95a62401776b4ed8c433682fa7 (patch)
tree96b5411f17faed9f62aa9e4722b29d767d502b1b /scripts/automation/trex_control_plane/stl/examples
parent4e8ce34a9ef6b8883cfed47f77c9b753e1cf4248 (diff)
gather stateful client to stf folder, create trex_client package
Diffstat (limited to 'scripts/automation/trex_control_plane/stl/examples')
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/hlt_udp_simple.py12
-rw-r--r--scripts/automation/trex_control_plane/stl/examples/stl_pcap.py52
2 files changed, 47 insertions, 17 deletions
diff --git a/scripts/automation/trex_control_plane/stl/examples/hlt_udp_simple.py b/scripts/automation/trex_control_plane/stl/examples/hlt_udp_simple.py
index 56e2005a..bdec9999 100644
--- a/scripts/automation/trex_control_plane/stl/examples/hlt_udp_simple.py
+++ b/scripts/automation/trex_control_plane/stl/examples/hlt_udp_simple.py
@@ -67,15 +67,15 @@ if __name__ == "__main__":
args = parser.parse_args();
hltapi = CTRexHltApi()
- print 'Connecting to TRex'
+ print('Connecting to TRex')
res = hltapi.connect(device = args.server, port_list = [0, 1], reset = True, break_locks = True)
check_res(res)
ports = res['port_handle']
if len(ports) < 2:
error('Should have at least 2 ports for this test')
- print 'Connected, acquired ports: %s' % ports
+ print('Connected, acquired ports: %s' % ports)
- print 'Creating traffic'
+ print('Creating traffic')
res = hltapi.traffic_config(mode = 'create', bidirectional = True,
port_handle = ports[0], port_handle2 = ports[1],
@@ -91,12 +91,12 @@ if __name__ == "__main__":
)
check_res(res)
- print 'Starting traffic'
+ print('Starting traffic')
res = hltapi.traffic_control(action = 'run', port_handle = ports[:2])
check_res(res)
wait_with_progress(args.duration)
- print 'Stopping traffic'
+ print('Stopping traffic')
res = hltapi.traffic_control(action = 'stop', port_handle = ports[:2])
check_res(res)
@@ -107,4 +107,4 @@ if __name__ == "__main__":
res = hltapi.cleanup_session(port_handle = 'all')
check_res(res)
- print 'Done'
+ print('Done')
diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py b/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py
index 317f44c7..45ddc24b 100644
--- a/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py
+++ b/scripts/automation/trex_control_plane/stl/examples/stl_pcap.py
@@ -1,7 +1,7 @@
import stl_path
from trex_stl_lib.api import *
import argparse
-
+import sys
def create_vm (ip_start, ip_end):
vm =[
@@ -17,11 +17,23 @@ def create_vm (ip_start, ip_end):
return vm
-
-def inject_pcap (pcap_file, port, loop_count, ipg_usec, use_vm):
+# warning: might make test slow
+def alter_streams(streams, remove_fcs, vlan_id):
+ for stream in streams:
+ packet = Ether(stream.pkt)
+ if vlan_id >= 0 and vlan_id <= 4096:
+ packet_l3 = packet.payload
+ packet = Ether() / Dot1Q(vlan = vlan_id) / packet_l3
+ if remove_fcs and packet.lastlayer().name == 'Padding':
+ packet.lastlayer().underlayer.remove_payload()
+ packet = STLPktBuilder(packet)
+ stream.fields['packet'] = packet.dump_pkt()
+ stream.pkt = base64.b64decode(stream.fields['packet']['binary'])
+
+def inject_pcap (pcap_file, server, port, loop_count, ipg_usec, use_vm, remove_fcs, vlan_id):
# create client
- c = STLClient()
+ c = STLClient(server = server)
try:
if use_vm:
@@ -32,13 +44,16 @@ def inject_pcap (pcap_file, port, loop_count, ipg_usec, use_vm):
profile = STLProfile.load_pcap(pcap_file, ipg_usec = ipg_usec, loop_count = loop_count, vm = vm)
print("Loaded pcap {0} with {1} packets...\n".format(pcap_file, len(profile)))
+ streams = profile.get_streams()
+ if remove_fcs or (vlan_id >= 0 and vlan_id <= 4096):
+ alter_streams(streams, remove_fcs, vlan_id)
# uncomment this for simulator run
- #STLSim().run(profile.get_streams(), outfile = 'out.cap')
+ #STLSim().run(profile.get_streams(), outfile = '/auto/srg-sce-swinfra-usr/emb/users/ybrustin/out.pcap')
c.connect()
c.reset(ports = [port])
- stream_ids = c.add_streams(profile.get_streams(), ports = [port])
+ stream_ids = c.add_streams(streams, ports = [port])
c.clear_stats()
@@ -51,6 +66,7 @@ def inject_pcap (pcap_file, port, loop_count, ipg_usec, use_vm):
except STLError as e:
print(e)
+ sys.exit(1)
finally:
c.disconnect()
@@ -59,17 +75,22 @@ def inject_pcap (pcap_file, port, loop_count, ipg_usec, use_vm):
def setParserOptions():
parser = argparse.ArgumentParser(prog="stl_pcap.py")
- parser.add_argument("-f", help = "pcap file to inject",
+ parser.add_argument("-f", "--file", help = "pcap file to inject",
dest = "pcap",
required = True,
type = str)
- parser.add_argument("-p", help = "port to inject on",
+ parser.add_argument("-s", "--server", help = "TRex server address",
+ dest = "server",
+ default = 'localhost',
+ type = str)
+
+ parser.add_argument("-p", "--port", help = "port to inject on",
dest = "port",
required = True,
type = int)
- parser.add_argument("-n", help = "How many times to inject pcap [default is 1, 0 means forever]",
+ parser.add_argument("-n", "--number", help = "How many times to inject pcap [default is 1, 0 means forever]",
dest = "loop_count",
default = 1,
type = int)
@@ -79,19 +100,28 @@ def setParserOptions():
default = 10.0,
type = float)
-
parser.add_argument("-x", help = "Iterate over IP dest",
dest = "use_vm",
default = False,
action = "store_true")
+ parser.add_argument("-r", "--remove-fcs", help = "Remove FCS if exists. Limited by Scapy capabilities.",
+ dest = "remove",
+ default = False,
+ action = "store_true")
+
+ parser.add_argument("-v", "--vlan", help = "Add VLAN header with this ID. Limited by Scapy capabilities.",
+ dest = "vlan",
+ default = -1,
+ type = int)
+
return parser
def main ():
parser = setParserOptions()
options = parser.parse_args()
- inject_pcap(options.pcap, options.port, options.loop_count, options.ipg, options.use_vm)
+ inject_pcap(options.pcap, options.server, options.port, options.loop_count, options.ipg, options.use_vm, options.remove, options.vlan)
# inject pcap
if __name__ == '__main__':