Fix TRex RFC2544 traffic profile tolerance definition 41/60941/2
authorRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Tue, 14 Aug 2018 13:50:27 +0000 (14:50 +0100)
committerRodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com>
Tue, 14 Aug 2018 14:36:13 +0000 (15:36 +0100)
In TRex RFC2544 traffic profile, the tolerance limit is not set correctly.
The parameters "tol_high" and "tol_low" in "get_drop_percentage" are
incorrect.

The tolerance limit should be reduced to 0.01.

JIRA: YARDSTICK-1382

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

index 0e1dbd5..b54fc57 100644 (file)
@@ -70,7 +70,7 @@ class PortPgIDMap(object):
 class RFC2544Profile(trex_traffic_profile.TrexProfile):
     """TRex RFC2544 traffic profile"""
 
-    TOLERANCE_LIMIT = 0.05
+    TOLERANCE_LIMIT = 0.01
 
     def __init__(self, traffic_generator):
         super(RFC2544Profile, self).__init__(traffic_generator)
@@ -246,6 +246,7 @@ class RFC2544Profile(trex_traffic_profile.TrexProfile):
     def get_drop_percentage(self, samples, tol_low, tol_high,
                             correlated_traffic):
         """Calculate the drop percentage and run the traffic"""
+        completed = False
         tx_rate_fps = 0
         rx_rate_fps = 0
         for sample in samples:
@@ -266,15 +267,15 @@ class RFC2544Profile(trex_traffic_profile.TrexProfile):
             drop_percent = round(
                 (float(abs(out_packets - in_packets)) / out_packets) * 100, 5)
 
-        tol_high = tol_high if tol_high > self.TOLERANCE_LIMIT else tol_high
-        tol_low = tol_low if tol_low > self.TOLERANCE_LIMIT else tol_low
+        tol_high = max(tol_high, self.TOLERANCE_LIMIT)
+        tol_low = min(tol_low, self.TOLERANCE_LIMIT)
         if drop_percent > tol_high:
             self.max_rate = self.rate
         elif drop_percent < tol_low:
             self.min_rate = self.rate
-        else:
-            # NOTE(ralonsoh): the test should finish here
-            # pass
+        else:
+            completed = True
+
         last_rate = self.rate
         self.rate = round(float(self.max_rate + self.min_rate) / 2.0, 5)
 
@@ -295,4 +296,4 @@ class RFC2544Profile(trex_traffic_profile.TrexProfile):
             'Rate': last_rate,
             'Latency': latency
         }
-        return output
+        return completed, output
index 3ef7c33..a09f2a7 100644 (file)
@@ -426,7 +426,8 @@ class ClientResourceHelper(ResourceHelper):
             iteration_index = 0
             while self._terminated.value == 0:
                 iteration_index += 1
-                self._run_traffic_once(traffic_profile)
+                if self._run_traffic_once(traffic_profile):
+                    self._terminated.value = 1
                 mq_producer.tg_method_iteration(iteration_index)
 
             self.client.stop(self.all_ports)
index cdbb414..7ecb124 100644 (file)
@@ -45,11 +45,12 @@ class TrexRfcResourceHelper(tg_trex.TrexResourceHelper):
             time.sleep(self.SAMPLING_PERIOD)
 
         traffic_profile.stop_traffic(self)
-        output = traffic_profile.get_drop_percentage(
+        completed, output = traffic_profile.get_drop_percentage(
             samples, self.rfc2544_helper.tolerance_low,
             self.rfc2544_helper.tolerance_high,
             self.rfc2544_helper.correlated_traffic)
         self._queue.put(output)
+        return completed
 
     def start_client(self, ports, mult=None, duration=None, force=True):
         self.client.start(ports=ports, mult=mult, duration=duration, force=force)
index a4fdc8d..2e0331e 100644 (file)
@@ -238,15 +238,17 @@ class TestRFC2544Profile(base.BaseUnitTestCase):
                      'in_packets': 4040,
                      'latency': 'Latency2'}}
         ]
-        output = rfc2544_profile.get_drop_percentage(samples, 0, 0, False)
+        completed, output = rfc2544_profile.get_drop_percentage(
+            samples, 0, 0, False)
         expected = {'DropPercentage': 0.3963,
                     'Latency': {'xe1': 'Latency1', 'xe2': 'Latency2'},
                     'RxThroughput': 312.5,
                     'TxThroughput': 304.5,
                     'CurrentDropPercentage': 0.3963,
-                    'Rate': 100,
+                    'Rate': 100.0,
                     'Throughput': 312.5}
         self.assertEqual(expected, output)
+        self.assertFalse(completed)
 
 
 class PortPgIDMapTestCase(base.BaseUnitTestCase):
index c35d2db..4a1d8c3 100644 (file)
@@ -1091,7 +1091,8 @@ class TestClientResourceHelper(unittest.TestCase):
         self.assertIs(client_resource_helper._connect(client), client)
 
     @mock.patch.object(ClientResourceHelper, '_build_ports')
-    @mock.patch.object(ClientResourceHelper, '_run_traffic_once')
+    @mock.patch.object(ClientResourceHelper, '_run_traffic_once',
+                       return_value=(True, mock.ANY))
     def test_run_traffic(self, mock_run_traffic_once, mock_build_ports):
         client_resource_helper = ClientResourceHelper(mock.Mock())
         client = mock.Mock()
@@ -1103,7 +1104,7 @@ class TestClientResourceHelper(unittest.TestCase):
                 as mock_terminated:
             mock_connect.return_value = client
             type(mock_terminated).value = mock.PropertyMock(
-                side_effect=[0, 1, lambda x: x])
+                side_effect=[0, 1, 1, lambda x: x])
             client_resource_helper.run_traffic(traffic_profile, mq_producer)
 
         mock_build_ports.assert_called_once()
index 6aba410..a5b9f25 100644 (file)
@@ -30,13 +30,14 @@ class TestTrexRfcResouceHelper(unittest.TestCase):
         mock_traffic_profile.config.duration = 3
         mock_traffic_profile.execute_traffic.return_value = ('fake_ports',
                                                              'port_pg_id_map')
-        mock_traffic_profile.get_drop_percentage.return_value = 'percentage'
+        mock_traffic_profile.get_drop_percentage.return_value = (True,
+                                                                 'percentage')
         rfc_rh = tg_rfc2544_trex.TrexRfcResourceHelper(mock_setup_helper)
         rfc_rh.TRANSIENT_PERIOD = 0
         rfc_rh.rfc2544_helper = mock.Mock()
 
         with mock.patch.object(rfc_rh, '_get_samples') as mock_get_samples:
-            rfc_rh._run_traffic_once(mock_traffic_profile)
+            self.assertTrue(rfc_rh._run_traffic_once(mock_traffic_profile))
 
         mock_traffic_profile.execute_traffic.assert_called_once_with(rfc_rh)
         mock_traffic_profile.stop_traffic.assert_called_once_with(rfc_rh)