summaryrefslogtreecommitdiffstats
path: root/api
diff options
context:
space:
mode:
authorimarom <imarom@cisco.com>2016-01-26 08:57:43 -0500
committerimarom <imarom@cisco.com>2016-01-26 08:58:49 -0500
commit2828fc9aab33b742c59a499dbf06ea2239ec6220 (patch)
tree8385177f873a06d8c4574fb6721bf8c9a74a60c3 /api
parent4c6450049d82fb9f98dbafe98d3ea1e229bf2a6d (diff)
API simplification and example
Diffstat (limited to 'api')
-rw-r--r--api/stl/examples/stl_simple_burst.py69
-rw-r--r--api/stl/trex_stl_api.py18
2 files changed, 55 insertions, 32 deletions
diff --git a/api/stl/examples/stl_simple_burst.py b/api/stl/examples/stl_simple_burst.py
index b60df4bf..49355890 100644
--- a/api/stl/examples/stl_simple_burst.py
+++ b/api/stl/examples/stl_simple_burst.py
@@ -1,66 +1,83 @@
import sys
sys.path.insert(0, "../")
-import trex_stl_api
-
-from trex_stl_api import STLClient, STLError
-
+from trex_stl_api import *
+import dpkt
import time
-# define a simple burst test
def simple_burst ():
-
- passed = True
-
+
+ # build a simple packet
+
+ pkt_bld = STLPktBuilder()
+ pkt_bld.add_pkt_layer("l2", dpkt.ethernet.Ethernet())
+ # set Ethernet layer attributes
+ pkt_bld.set_eth_layer_addr("l2", "src", "00:15:17:a7:75:a3")
+ pkt_bld.set_eth_layer_addr("l2", "dst", "e0:5f:b9:69:e9:22")
+ pkt_bld.set_layer_attr("l2", "type", dpkt.ethernet.ETH_TYPE_IP)
+ # set IP layer attributes
+ pkt_bld.add_pkt_layer("l3_ip", dpkt.ip.IP())
+ pkt_bld.set_ip_layer_addr("l3_ip", "src", "21.0.0.2")
+ pkt_bld.set_ip_layer_addr("l3_ip", "dst", "22.0.0.12")
+ pkt_bld.set_layer_attr("l3_ip", "p", dpkt.ip.IP_PROTO_TCP)
+ # set TCP layer attributes
+ pkt_bld.add_pkt_layer("l4_tcp", dpkt.tcp.TCP())
+ pkt_bld.set_layer_attr("l4_tcp", "sport", 13311)
+ pkt_bld.set_layer_attr("l4_tcp", "dport", 80)
+ pkt_bld.set_layer_attr("l4_tcp", "flags", 0)
+ pkt_bld.set_layer_attr("l4_tcp", "win", 32768)
+ pkt_bld.set_layer_attr("l4_tcp", "seq", 0)
+ pkt_bld.set_pkt_payload("abcdefgh")
+ pkt_bld.set_layer_attr("l3_ip", "len", len(pkt_bld.get_layer('l3_ip')))
+
+
+ # create client
c = STLClient()
+ passed = True
try:
- # activate this for some logging information
- #c.logger.set_verbose(c.logger.VERBOSE_REGULAR)
+ #c.logger.set_verbose(c.logger.VERBOSE_NORMAL)
+
+ # create two bursts and link them
+ s1 = STLSingleBurstStream(packet = pkt_bld, total_pkts = 5000)
+ s2 = STLSingleBurstStream(packet = pkt_bld, total_pkts = 3000, next_stream_id = s1.get_id())
# connect to server
c.connect()
- # prepare port 0,1
+ # prepare our ports
c.reset(ports = [0, 1])
- # load profile to both ports
- c.load_profile('../profiles/burst.yaml', ports = [0, 1])
+ # add both streams to ports
+ c.add_streams([s1, s2], ports = [0, 1])
- # repeat for 5 times
+ # run 5 times
for i in xrange(1, 6):
-
c.clear_stats()
-
- # start traffic and block until done
- c.start(ports = [0, 1], mult = "1gbps", duration = 5)
+ c.start(ports = [0, 1], mult = "1gbps")
c.wait_on_traffic(ports = [0, 1])
- # read the stats
stats = c.get_stats()
ipackets = stats['total']['ipackets']
print "Test iteration {0} - Packets Received: {1} ".format(i, ipackets)
-
- # we have 600 packets in the burst and two ports
- if (ipackets != (600 * 2)):
+ # (5000 + 3000) * 2 ports = 16,000
+ if (ipackets != (16000)):
passed = False
-
- # error handling
except STLError as e:
passed = False
print e
- # cleanup
finally:
c.disconnect()
-
+
if passed:
print "\nTest has passed :-)\n"
else:
print "\nTest has failed :-(\n"
+# run the tests
simple_burst()
diff --git a/api/stl/trex_stl_api.py b/api/stl/trex_stl_api.py
index aad39916..63a0963b 100644
--- a/api/stl/trex_stl_api.py
+++ b/api/stl/trex_stl_api.py
@@ -6,12 +6,18 @@ import time
# update the import path to include the stateless client
root_path = os.path.dirname(os.path.abspath(__file__))
-sys.path.insert(0, os.path.join(root_path, '../../scripts/automation/trex_control_plane/client/'))
-sys.path.insert(0, os.path.join(root_path, '../../scripts/automation/trex_control_plane/client_utils/'))
-sys.path.insert(0, os.path.join(root_path, '../../scripts/automation/trex_control_plane/client_utils/'))
+sys.path.insert(0, os.path.join(root_path, '../../scripts/automation/trex_control_plane/'))
# aliasing
-import trex_stateless_client
-STLClient = trex_stateless_client.STLClient
-STLError = trex_stateless_client.STLError
+import common.trex_streams
+from client_utils.packet_builder import CTRexPktBuilder
+import common.trex_stl_exceptions
+import client.trex_stateless_client
+
+STLClient = client.trex_stateless_client.STLClient
+STLError = common.trex_stl_exceptions.STLError
+STLContStream = common.trex_streams.STLContStream
+STLSingleBurstStream = common.trex_streams.STLSingleBurstStream
+STLMultiBurstStream = common.trex_streams.STLMultiBurstStream
+STLPktBuilder = CTRexPktBuilder