Fix argument order in unidirection related KWs
[csit.git] / resources / libraries / python / TrafficGenerator.py
index b5558e6..6123b87 100644 (file)
@@ -25,6 +25,7 @@ from .topology import Topology
 from .MLRsearch.AbstractMeasurer import AbstractMeasurer
 from .MLRsearch.MultipleLossRatioSearch import MultipleLossRatioSearch
 from .MLRsearch.ReceiveRateMeasurement import ReceiveRateMeasurement
+from .PLRsearch.PLRsearch import PLRsearch
 
 __all__ = ['TGDropRateSearchImpl', 'TrafficGenerator', 'OptimizedSearch']
 
@@ -457,10 +458,9 @@ class TrafficGenerator(AbstractMeasurer):
             self._latency.append(self._result.split(', ')[4].split('=')[1])
             self._latency.append(self._result.split(', ')[5].split('=')[1])
 
-    def trex_stl_start_unidirection(self, duration, rate, framesize,
-                                    traffic_type, tx_port=0, rx_port=1,
-                                    async_call=False, latency=False,
-                                    warmup_time=5.0):
+    def trex_stl_start_unidirection(
+            self, duration, rate, framesize, traffic_type, async_call=False,
+            latency=False, warmup_time=5.0, tx_port=0, rx_port=1):
         """Execute script on remote node over ssh to start unidirection traffic.
         The purpose of this function is to support performance test that need to
         measure unidirectional traffic, e.g. Load balancer maglev mode and l3dsr
@@ -471,21 +471,20 @@ class TrafficGenerator(AbstractMeasurer):
         :param framesize: L2 frame size to send (without padding and IPG).
         :param traffic_type: Module name as a traffic type identifier.
             See resources/traffic_profiles/trex for implemented modules.
-        :param tx_port: Traffic generator transmit port.
-        :param rx_port: Traffic generator receive port.
         :param latency: With latency measurement.
         :param async_call: If enabled then don't wait for all incomming trafic.
         :param warmup_time: Warmup time period.
+        :param tx_port: Traffic generator transmit port.
+        :param rx_port: Traffic generator receive port.
         :type duration: float
         :type rate: str
         :type framesize: str
         :type traffic_type: str
-        :type tx_port: integer
-        :type rx_port: integer
         :type latency: bool
         :type async_call: bool
         :type warmup_time: float
-        :returns: Nothing
+        :type tx_port: integer
+        :type rx_port: integer
         :raises RuntimeError: In case of TG driver issue.
         """
         ssh = SSH()
@@ -547,9 +546,10 @@ class TrafficGenerator(AbstractMeasurer):
         if self._node['subtype'] == NodeSubTypeTG.TREX:
             self.trex_stl_stop_remote_exec(self._node)
 
-    def send_traffic_on_tg(self, duration, rate, framesize, traffic_type,
-                           unidirection=False, tx_port=0, rx_port=1,
-                           warmup_time=5, async_call=False, latency=True):
+    def send_traffic_on_tg(
+            self, duration, rate, framesize, traffic_type, warmup_time=5,
+            async_call=False, latency=True, unidirection=False, tx_port=0,
+            rx_port=1):
         """Send traffic from all configured interfaces on TG.
 
         :param duration: Duration of test traffic generation in seconds.
@@ -557,22 +557,22 @@ class TrafficGenerator(AbstractMeasurer):
         :param framesize: Frame size (L2) in Bytes.
         :param traffic_type: Module name as a traffic type identifier.
             See resources/traffic_profiles/trex for implemented modules.
-        :param unidirection: Traffic is unidirectional.
-        :param tx_port: Traffic generator transmit port.
-        :param rx_port: Traffic generator receive port.
         :param warmup_time: Warmup phase in seconds.
         :param async_call: Async mode.
         :param latency: With latency measurement.
+        :param unidirection: Traffic is unidirectional.
+        :param tx_port: Traffic generator transmit port.
+        :param rx_port: Traffic generator receive port.
         :type duration: str
         :type rate: str
         :type framesize: str
         :type traffic_type: str
-        :type unidirection: bool
-        :type tx_port: integer
-        :type rx_port: integer
         :type warmup_time: float
         :type async_call: bool
         :type latency: bool
+        :type unidirection: bool
+        :type tx_port: integer
+        :type rx_port: integer
         :returns: TG output.
         :rtype: str
         :raises RuntimeError: If TG is not set, or if node is not TG,
@@ -686,7 +686,7 @@ class TrafficGenerator(AbstractMeasurer):
         unit_rate = str(transmit_rate / 2.0) + "pps"
         self.send_traffic_on_tg(
             duration, unit_rate, self.frame_size, self.traffic_type,
-            self.warmup_time, latency=True)
+            warmup_time=self.warmup_time, latency=True)
         transmit_count = int(self.get_sent())
         loss_count = int(self.get_loss())
         measurement = ReceiveRateMeasurement(
@@ -757,3 +757,46 @@ class OptimizedSearch(object):
         result = algorithm.narrow_down_ndr_and_pdr(
             minimum_transmit_rate, maximum_transmit_rate, packet_loss_ratio)
         return result
+
+    @staticmethod
+    def perform_soak_search(
+            frame_size, traffic_type, minimum_transmit_rate,
+            maximum_transmit_rate, plr_target=1e-7, tdpt=0.2,
+            initial_count=50, timeout=1800.0):
+        """Setup initialized TG, perform soak search, return avg and stdev.
+
+        :param frame_size: Frame size identifier or value [B].
+        :param traffic_type: Module name as a traffic type identifier.
+            See resources/traffic_profiles/trex for implemented modules.
+        :param minimum_transmit_rate: Minimal bidirectional
+            target transmit rate [pps].
+        :param maximum_transmit_rate: Maximal bidirectional
+            target transmit rate [pps].
+        :param plr_target: Fraction of packets lost to achieve [1].
+        :param tdpt: Trial duration per trial.
+            The algorithm linearly increases trial duration with trial number,
+            this is the increment between succesive trials, in seconds.
+        :param initial_count: Offset to apply before the first trial.
+            For example initial_count=50 makes first trial to be 51*tdpt long.
+            This is needed because initial "search" phase of integrator
+            takes significant time even without any trial results.
+        :param timeout: The search will stop after this overall time [s].
+        :type frame_size: str or int
+        :type traffic_type: str
+        :type minimum_transmit_rate: float
+        :type maximum_transmit_rate: float
+        :type plr_target: float
+        :type initial_count: int
+        :type timeout: float
+        :returns: Average and stdev of estimated bidirectional rate giving PLR.
+        :rtype: 2-tuple of float
+        """
+        tg_instance = BuiltIn().get_library_instance(
+            'resources.libraries.python.TrafficGenerator')
+        tg_instance.set_rate_provider_defaults(frame_size, traffic_type)
+        algorithm = PLRsearch(
+            measurer=tg_instance, trial_duration_per_trial=tdpt,
+            packet_loss_ratio_target=plr_target,
+            trial_number_offset=initial_count, timeout=timeout)
+        result = algorithm.search(minimum_transmit_rate, maximum_transmit_rate)
+        return result