Merge "Add traffic duration support in test case"
[yardstick.git] / yardstick / network_services / vnf_generic / vnf / prox_helpers.py
index ad826f9..321c057 100644 (file)
@@ -398,8 +398,14 @@ class ProxSocketHelper(object):
 
     def stop(self, cores, task=''):
         """ stop specific cores on the remote instance """
-        LOG.debug("Stopping cores %s", cores)
-        self.put_command("stop {} {}\n".format(join_non_strings(',', cores), task))
+
+        tmpcores = []
+        for core in cores:
+            if core not in tmpcores:
+                tmpcores.append(core)
+
+        LOG.debug("Stopping cores %s", tmpcores)
+        self.put_command("stop {} {}\n".format(join_non_strings(',', tmpcores), task))
         time.sleep(3)
 
     def start_all(self):
@@ -409,8 +415,14 @@ class ProxSocketHelper(object):
 
     def start(self, cores):
         """ start specific cores on the remote instance """
-        LOG.debug("Starting cores %s", cores)
-        self.put_command("start {}\n".format(join_non_strings(',', cores)))
+
+        tmpcores = []
+        for core in cores:
+            if core not in tmpcores:
+                tmpcores.append(core)
+
+        LOG.debug("Starting cores %s", tmpcores)
+        self.put_command("start {}\n".format(join_non_strings(',', tmpcores)))
         time.sleep(3)
 
     def reset_stats(self):
@@ -957,7 +969,7 @@ class ProxResourceHelper(ClientResourceHelper):
             self._test_type = self.setup_helper.find_in_section('global', 'name', None)
         return self._test_type
 
-    def run_traffic(self, traffic_profile):
+    def run_traffic(self, traffic_profile, *args):
         self._queue.cancel_join_thread()
         self.lower = 0.0
         self.upper = 100.0
@@ -972,7 +984,7 @@ class ProxResourceHelper(ClientResourceHelper):
 
     def _run_traffic_once(self, traffic_profile):
         traffic_profile.execute_traffic(self)
-        if traffic_profile.done:
+        if traffic_profile.done.is_set():
             self._queue.put({'done': True})
             LOG.debug("tg_prox done")
             self._terminated.value = 1
@@ -1214,12 +1226,32 @@ class ProxProfileHelper(object):
 
         return cores
 
+    def pct_10gbps(self, percent, line_speed):
+        """Get rate in percent of 10 Gbps.
+
+        Returns the rate in percent of 10 Gbps.
+        For instance 100.0 = 10 Gbps; 400.0 = 40 Gbps.
+
+        This helper method isrequired when setting interface_speed option in
+        the testcase because NSB/PROX considers 10Gbps as 100% of line rate,
+        this means that the line rate must be expressed as a percentage of
+        10Gbps.
+
+        :param percent: (float) Percent of line rate (100.0 = line rate).
+        :param line_speed: (int) line rate speed, in bits per second.
+
+        :return: (float) Represents the rate in percent of 10Gbps.
+        """
+        return (percent * line_speed / (
+            constants.ONE_GIGABIT_IN_BITS * constants.NIC_GBPS_DEFAULT))
+
     def run_test(self, pkt_size, duration, value, tolerated_loss=0.0,
                  line_speed=(constants.ONE_GIGABIT_IN_BITS * constants.NIC_GBPS_DEFAULT)):
         data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size,
                                      value, tolerated_loss, line_speed)
 
-        with data_helper, self.traffic_context(pkt_size, value):
+        with data_helper, self.traffic_context(pkt_size,
+                                               self.pct_10gbps(value, line_speed)):
             with data_helper.measure_tot_stats():
                 time.sleep(duration)
                 # Getting statistics to calculate PPS at right speed....
@@ -1479,7 +1511,8 @@ class ProxBngProfileHelper(ProxProfileHelper):
         data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size,
                                      value, tolerated_loss, line_speed)
 
-        with data_helper, self.traffic_context(pkt_size, value):
+        with data_helper, self.traffic_context(pkt_size,
+                                               self.pct_10gbps(value, line_speed)):
             with data_helper.measure_tot_stats():
                 time.sleep(duration)
                 # Getting statistics to calculate PPS at right speed....
@@ -1668,7 +1701,8 @@ class ProxVpeProfileHelper(ProxProfileHelper):
         data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size,
                                      value, tolerated_loss, line_speed)
 
-        with data_helper, self.traffic_context(pkt_size, value):
+        with data_helper, self.traffic_context(pkt_size,
+                                               self.pct_10gbps(value, line_speed)):
             with data_helper.measure_tot_stats():
                 time.sleep(duration)
                 # Getting statistics to calculate PPS at right speed....
@@ -1859,7 +1893,8 @@ class ProxlwAFTRProfileHelper(ProxProfileHelper):
         data_helper = ProxDataHelper(self.vnfd_helper, self.sut, pkt_size,
                                      value, tolerated_loss, line_speed)
 
-        with data_helper, self.traffic_context(pkt_size, value):
+        with data_helper, self.traffic_context(pkt_size,
+                                               self.pct_10gbps(value, line_speed)):
             with data_helper.measure_tot_stats():
                 time.sleep(duration)
                 # Getting statistics to calculate PPS at right speed....