summaryrefslogtreecommitdiffstats
path: root/scripts/automation/trex_control_plane/stl
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/automation/trex_control_plane/stl')
-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
-rw-r--r--scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py9
-rwxr-xr-xscripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py6
4 files changed, 56 insertions, 23 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__':
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py
index c614c4bd..d6d66ec3 100644
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_ext.py
@@ -7,11 +7,14 @@ import platform
TREX_STL_EXT_PATH = os.environ.get('TREX_STL_EXT_PATH')
# take default
-if not TREX_STL_EXT_PATH:
+if not TREX_STL_EXT_PATH or not os.path.exists(TREX_STL_EXT_PATH):
CURRENT_PATH = os.path.dirname(os.path.realpath(__file__))
+ TREX_STL_EXT_PATH = os.path.normpath(os.path.join(CURRENT_PATH, os.pardir, 'external_libs'))
+if not os.path.exists(TREX_STL_EXT_PATH):
# ../../../../external_libs
- TREX_STL_EXT_PATH = os.path.abspath(os.path.join(CURRENT_PATH, os.pardir, os.pardir, os.pardir, os.pardir, 'external_libs'))
-
+ TREX_STL_EXT_PATH = os.path.normpath(os.path.join(CURRENT_PATH, os.pardir, os.pardir, os.pardir, os.pardir, 'external_libs'))
+if not os.path.exists(TREX_STL_EXT_PATH):
+ raise Exception('Could not determine path of external_libs, try setting TREX_STL_EXT_PATH variable')
# the modules required
# py-dep requires python2/python3 directories
diff --git a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
index 9387c3a6..b506137b 100755
--- a/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
+++ b/scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_hltapi.py
@@ -174,7 +174,7 @@ import socket
import copy
from collections import defaultdict
-from trex_stl_lib.api import *
+from .api import *
from .trex_stl_types import *
from .utils.common import get_number
@@ -249,7 +249,7 @@ def print_brief_stats(res):
title_str = ' '*3
tx_str = 'TX:'
rx_str = 'RX:'
- for port_id, stat in res.iteritems():
+ for port_id, stat in res.items():
if type(port_id) is not int:
continue
title_str += ' '*10 + 'Port%s' % port_id
@@ -663,7 +663,7 @@ class CTRexHltApi(object):
stats = self.trex_client.get_stats(port_handle)
except Exception as e:
return HLT_ERR('Could not retrieve stats: %s' % e if isinstance(e, STLError) else traceback.format_exc())
- for port_id, stat_dict in stats.iteritems():
+ for port_id, stat_dict in stats.items():
if is_integer(port_id):
hlt_stats_dict[port_id] = {
'aggregate': {