Improvie TRex RFC2544 throughput calculation 13/61013/2
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Thu, 16 Aug 2018 11:20:10 +0000 (12:20 +0100)
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Mon, 20 Aug 2018 10:02:56 +0000 (11:02 +0100)
Improve TRex RFC2544 throughput calculation by using the in/out packets
instead of using the throughput samples.

JIRA: YARDSTICK-1387

Change-Id: I877e901c3226d31c6435a877a2924bb95deb1cf0
Signed-off-by: Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
yardstick/network_services/traffic_profile/rfc2544.py
yardstick/network_services/vnf_generic/vnf/tg_trex.py
yardstick/tests/unit/network_services/traffic_profile/test_rfc2544.py

index b54fc57..8983156 100644 (file)
@@ -247,19 +247,16 @@ class RFC2544Profile(trex_traffic_profile.TrexProfile):
                             correlated_traffic):
         """Calculate the drop percentage and run the traffic"""
         completed = False
-        tx_rate_fps = 0
-        rx_rate_fps = 0
-        for sample in samples:
-            tx_rate_fps += sum(
-                port['tx_throughput_fps'] for port in sample.values())
-            rx_rate_fps += sum(
-                port['rx_throughput_fps'] for port in sample.values())
-        tx_rate_fps = round(float(tx_rate_fps) / len(samples), 2)
-        rx_rate_fps = round(float(rx_rate_fps) / len(samples), 2)
-
-        # TODO(esm): RFC2544 doesn't tolerate packet loss, why do we?
-        out_packets = sum(port['out_packets'] for port in samples[-1].values())
-        in_packets = sum(port['in_packets'] for port in samples[-1].values())
+        out_pkt_end = sum(port['out_packets'] for port in samples[-1].values())
+        in_pkt_end = sum(port['in_packets'] for port in samples[-1].values())
+        out_pkt_ini = sum(port['out_packets'] for port in samples[0].values())
+        in_pkt_ini = sum(port['in_packets'] for port in samples[0].values())
+        time_diff = (list(samples[-1].values())[0]['timestamp'] -
+                     list(samples[0].values())[0]['timestamp']).total_seconds()
+        out_packets = out_pkt_end - out_pkt_ini
+        in_packets = in_pkt_end - in_pkt_ini
+        tx_rate_fps = float(out_packets) / time_diff
+        rx_rate_fps = float(in_packets) / time_diff
         drop_percent = 100.0
 
         # https://tools.ietf.org/html/rfc2544#section-26.3
index 58b7348..4296da8 100644 (file)
@@ -11,8 +11,8 @@
 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 # See the License for the specific language governing permissions and
 # limitations under the License.
-""" Trex acts as traffic generation and vnf definitions based on IETS Spec """
 
+import datetime
 import logging
 import os
 
@@ -167,6 +167,7 @@ class TrexResourceHelper(ClientResourceHelper):
 
     def _get_samples(self, ports, port_pg_id=None):
         stats = self.get_stats(ports)
+        timestamp = datetime.datetime.now()
         samples = {}
         for pname in (intf['name'] for intf in self.vnfd_helper.interfaces):
             port_num = self.vnfd_helper.port_num(pname)
@@ -178,6 +179,7 @@ class TrexResourceHelper(ClientResourceHelper):
                 'tx_throughput_bps': float(port_stats.get('tx_bps', 0.0)),
                 'in_packets': int(port_stats.get('ipackets', 0)),
                 'out_packets': int(port_stats.get('opackets', 0)),
+                'timestamp': timestamp
             }
 
             pg_id_list = port_pg_id.get_pg_ids(port_num)
index 2e0331e..d0ad771 100644 (file)
@@ -12,8 +12,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-import mock
+import datetime
 
+import mock
 from trex_stl_lib import api as Pkt
 from trex_stl_lib import trex_stl_client
 from trex_stl_lib import trex_stl_packet_builder_scapy
@@ -219,34 +220,38 @@ class TestRFC2544Profile(base.BaseUnitTestCase):
     def test_get_drop_percentage(self):
         rfc2544_profile = rfc2544.RFC2544Profile(self.TRAFFIC_PROFILE)
         samples = [
-            {'xe1': {'tx_throughput_fps': 100,
+            {'xe1': {'tx_throughput_fps': 110,
                      'rx_throughput_fps': 101,
-                     'out_packets': 2000,
-                     'in_packets': 2010},
-             'xe2': {'tx_throughput_fps': 200,
+                     'out_packets': 2100,
+                     'in_packets': 2010,
+                     'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 1)},
+             'xe2': {'tx_throughput_fps': 210,
                      'rx_throughput_fps': 201,
-                     'out_packets': 4000,
-                     'in_packets': 4010}},
-            {'xe1': {'tx_throughput_fps': 106,
+                     'out_packets': 4100,
+                     'in_packets': 4010,
+                     'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 1)}},
+            {'xe1': {'tx_throughput_fps': 156,
                      'rx_throughput_fps': 108,
-                     'out_packets': 2031,
+                     'out_packets': 2110,
                      'in_packets': 2040,
-                     'latency': 'Latency1'},
-             'xe2': {'tx_throughput_fps': 203,
+                     'latency': 'Latency1',
+                     'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 31)},
+             'xe2': {'tx_throughput_fps': 253,
                      'rx_throughput_fps': 215,
-                     'out_packets': 4025,
-                     'in_packets': 4040,
-                     'latency': 'Latency2'}}
+                     'out_packets': 4150,
+                     'in_packets': 4010,
+                     'latency': 'Latency2',
+                     'timestamp': datetime.datetime(2000, 1, 1, 1, 1, 1, 31)}}
         ]
         completed, output = rfc2544_profile.get_drop_percentage(
             samples, 0, 0, False)
-        expected = {'DropPercentage': 0.3963,
+        expected = {'DropPercentage': 50.0,
                     'Latency': {'xe1': 'Latency1', 'xe2': 'Latency2'},
-                    'RxThroughput': 312.5,
-                    'TxThroughput': 304.5,
-                    'CurrentDropPercentage': 0.3963,
+                    'RxThroughput': 1000000.0,
+                    'TxThroughput': 2000000.0,
+                    'CurrentDropPercentage': 50.0,
                     'Rate': 100.0,
-                    'Throughput': 312.5}
+                    'Throughput': 1000000.0}
         self.assertEqual(expected, output)
         self.assertFalse(completed)