console help looks better now
authorHanoh Haim <[email protected]>
Thu, 3 Mar 2016 15:14:12 +0000 (17:14 +0200)
committerHanoh Haim <[email protected]>
Thu, 3 Mar 2016 15:14:12 +0000 (17:14 +0200)
scripts/automation/trex_control_plane/stl/console/trex_console.py
scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows.py
scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows1.py [new file with mode: 0644]

index ffad03f..e037f51 100755 (executable)
@@ -252,16 +252,16 @@ class TRexConsole(TRexGeneralCmd):
     def postcmd(self, stop, line):
 
         if not self.stateless_client.is_connected():
-            self.prompt = "TRex (offline) > "
+            self.prompt = "trex(offline)>"
             self.supported_rpc = None
             return stop
 
         if self.stateless_client.is_all_ports_acquired():
-            self.prompt = "TRex (read only) > "
+            self.prompt = "trex(read-only)>"
             return stop
 
 
-        self.prompt = "TRex > "
+        self.prompt = "trex>"
 
         return stop
 
@@ -614,8 +614,9 @@ class TRexConsole(TRexGeneralCmd):
                      help = "*** Undocumented Function ***\n"
              except AttributeError:
                  help = "*** Undocumented Function ***\n"
-    
-             print "{:<30} {:<30}".format(cmd + " - ", help)
+
+             l=help.splitlines()
+             print "{:<30} {:<30}".format(cmd + " - ",l[0] )
 
     # a custorm cmdloop wrapper
     def start(self):
index 7e90e26..05fff67 100644 (file)
@@ -108,7 +108,7 @@ def simple_burst ():
     else:
         print "\nTest has failed :-(\n"
 
-
+while True:
 # run the tests
-simple_burst()
+  simple_burst()
 
diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows1.py b/scripts/automation/trex_control_plane/stl/examples/stl_bi_dir_flows1.py
new file mode 100644 (file)
index 0000000..264d985
--- /dev/null
@@ -0,0 +1,114 @@
+import stl_path
+from trex_stl_lib.api import *
+
+import time
+import json
+
+# simple packet creation
+def create_pkt (size, direction):
+
+    ip_range = {'src': {'start': "10.0.0.1", 'end': "10.0.0.254"},
+                'dst': {'start': "8.0.0.1",  'end': "8.0.0.254"}}
+
+    if (direction == 0):
+        src = ip_range['src']
+        dst = ip_range['dst']
+    else:
+        src = ip_range['dst']
+        dst = ip_range['src']
+
+    vm = [
+        # src
+        STLVmFlowVar(name="src",min_value=src['start'],max_value=src['end'],size=4,op="inc"),
+        STLVmWrFlowVar(fv_name="src",pkt_offset= "IP.src"),
+
+        # dst
+        STLVmFlowVar(name="dst",min_value=dst['start'],max_value=dst['end'],size=4,op="inc"),
+        STLVmWrFlowVar(fv_name="dst",pkt_offset= "IP.dst"),
+
+        # checksum
+        STLVmFixIpv4(offset = "IP")
+        ]
+
+
+    base = Ether()/IP()/UDP()
+    pad = max(0, len(base)) * 'x'
+
+    return STLPktBuilder(pkt = base/pad,
+                         vm  = vm)
+
+
+def simple_burst ():
+   
+  
+    # create client
+    c = STLClient()
+    passed = True
+
+    try:
+        # turn this on for some information
+        #c.set_verbose("high")
+
+        # create two streams
+        s1 = STLStream(packet = create_pkt(200, 0),
+                       mode = STLTXCont(pps = 100))
+
+        # second stream with a phase of 1ms (inter stream gap)
+        s2 = STLStream(packet = create_pkt(200, 1),
+                       isg = 1000,
+                       mode = STLTXCont(pps = 100))
+
+
+        # connect to server
+        c.connect()
+
+        # prepare our ports (my machine has 0 <--> 1 with static route)
+        c.reset(ports = [2, 3])
+
+        # add both streams to ports
+        c.add_streams(s1, ports = [2])
+        c.add_streams(s2, ports = [3])
+
+        # clear the stats before injecting
+        c.clear_stats()
+
+        # choose rate and start traffic for 10 seconds on 5 mpps
+        print "Running 5 Mpps on ports 0, 1 for 10 seconds..."
+        c.start(ports = [2, 3], mult = "5mpps", duration = 10)
+
+        # block until done
+        c.wait_on_traffic(ports = [2, 3])
+
+        # read the stats after the test
+        stats = c.get_stats()
+
+        print json.dumps(stats[2], indent = 4, separators=(',', ': '), sort_keys = True)
+        print json.dumps(stats[3], indent = 4, separators=(',', ': '), sort_keys = True)
+
+        lost_a = stats[2]["opackets"] - stats[3]["ipackets"]
+        lost_b = stats[3]["opackets"] - stats[2]["ipackets"]
+
+        print "\npackets lost from 0 --> 1:   {0} pkts".format(lost_a)
+        print "packets lost from 1 --> 0:   {0} pkts".format(lost_b)
+
+        if (lost_a == 0) and (lost_b == 0):
+            passed = True
+        else:
+            passed = False
+
+    except STLError as e:
+        passed = False
+        print e
+
+    finally:
+        c.disconnect()
+
+    if passed:
+        print "\nTest has passed :-)\n"
+    else:
+        print "\nTest has failed :-(\n"
+
+while True :
+    # run the tests
+    simple_burst()
+