RX stats API
authorimarom <[email protected]>
Thu, 3 Mar 2016 14:34:20 +0000 (16:34 +0200)
committerimarom <[email protected]>
Thu, 3 Mar 2016 16:11:08 +0000 (18:11 +0200)
scripts/automation/trex_control_plane/stl/examples/stl_run_udp_simple.py
scripts/automation/trex_control_plane/stl/examples/stl_rx_stream.py [new file with mode: 0644]
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_async_client.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_client.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_packet_builder_scapy.py
scripts/automation/trex_control_plane/stl/trex_stl_lib/trex_stl_streams.py

diff --git a/scripts/automation/trex_control_plane/stl/examples/stl_rx_stream.py b/scripts/automation/trex_control_plane/stl/examples/stl_rx_stream.py
new file mode 100644 (file)
index 0000000..daff610
--- /dev/null
@@ -0,0 +1,57 @@
+import stl_path
+from trex_stl_lib.api import *
+
+import time
+import pprint
+
+def rx_example (tx_port, rx_port):
+
+    # create client
+    c = STLClient()
+    passed = True
+    
+    try:
+        pkt = STLPktBuilder(pkt = Ether()/IP(src="16.0.0.1",dst="48.0.0.1")/UDP(dport=12,sport=1025)/IP()/'a_payload_example')
+        total_pkts = 500000
+        s1 = STLStream(name = 'rx',
+                       packet = pkt,
+                       rx_stats = STLRxStats(user_id = 5),
+                       mode = STLTXSingleBurst(total_pkts = total_pkts, bps_L2 = 250000000))
+
+        # connect to server
+        c.connect()
+
+        # prepare our ports
+        c.reset(ports = [tx_port, rx_port])
+
+        # add both streams to ports
+        c.add_streams([s1], ports = [tx_port])
+
+        print "injecting {0} packets on port {1}".format(total_pkts, tx_port)
+        c.clear_stats()
+        c.start(ports = [tx_port])
+        c.wait_on_traffic(ports = [tx_port])
+
+        time.sleep(1)
+        stats = c.get_stats()
+        pprint.pprint(stats['rx_stats'])
+        print "port 3: ipackets {0}, ibytes {1}".format(stats[3]['ipackets'], stats[3]['ibytes'])
+        #rx_stas  = stats['rx_stats']
+
+
+    except STLError as e:
+        passed = False
+        print e
+
+    finally:
+        c.disconnect()
+
+    if passed:
+        print "\nTest has passed :-)\n"
+    else:
+        print "\nTest has failed :-(\n"
+
+
+# run the tests
+rx_example(tx_port = 0, rx_port = 3)
+
index 410482b..f75d200 100644 (file)
@@ -280,6 +280,10 @@ class CTRexAsyncClient():
         # barriers
         elif name == "trex-barrier":
             self.handle_async_barrier(type, data)
+
+        elif name == "rx-stats":
+            self.event_handler.handle_async_rx_stats_event(data)
+
         else:
             pass
 
index 04dd77e..8da7c41 100644 (file)
@@ -155,6 +155,10 @@ class AsyncEventHandler(object):
         pass
 
 
+    def handle_async_rx_stats_event (self, data):
+        self.client.rx_stats = data
+
+
     # handles an async stats update from the subscriber
     def handle_async_stats_update(self, dump_data):
         global_stats = {}
@@ -435,7 +439,7 @@ class STLClient(object):
         self.stats_generator = trex_stl_stats.CTRexInfoGenerator(self.global_stats,
                                                               self.ports)
 
+        self.rx_stats = {}
  
     ############# private functions - used by the class itself ###########
 
@@ -741,6 +745,8 @@ class STLClient(object):
 
         stats['total'] = total
 
+        stats['rx_stats'] = copy.deepcopy(self.rx_stats)
+
         return stats
 
 
index 42d648a..b2843ac 100644 (file)
@@ -668,7 +668,7 @@ class CTRexVmDescTupleGen(CTRexVmDescBase):
 class CScapyTRexPktBuilder(CTrexPktBuilderInterface):
 
     """
-    This class defines the TRex API of building a packet using dpkt package.
+    This class defines the TRex API of building a packet using scapy package.
     Using this class the user can also define how TRex will handle the packet by specifying the VM setting.
     pkt could be Scapy pkt or pcap file name 
 
index b56d870..2dfc5f2 100644 (file)
@@ -6,7 +6,6 @@ from trex_stl_packet_builder_interface import CTrexPktBuilderInterface
 from trex_stl_packet_builder_scapy import CScapyTRexPktBuilder, Ether, IP, UDP, TCP, RawPcapReader
 from collections import OrderedDict, namedtuple
 
-from dpkt import pcap
 import random
 import yaml
 import base64