+
+ def set_rate_provider_defaults(self, frame_size, traffic_type,
+ warmup_time=0.0):
+ """Store values accessed by measure().
+
+ :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 warmup_time: Traffic duration before measurement starts [s].
+ :type frame_size: str or int
+ :type traffic_type: str
+ :type warmup_time: float
+ """
+ self.frame_size = frame_size
+ self.traffic_type = str(traffic_type)
+ self.warmup_time = float(warmup_time)
+
+ def measure(self, duration, transmit_rate):
+ """Run bi-directional measurement, parse and return results.
+
+ :param duration: Trial duration [s].
+ :param transmit_rate: Target bidirectional transmit rate [pps].
+ :type duration: float
+ :type transmit_rate: float
+ :returns: Structure containing the result of the measurement.
+ :rtype: ReceiveRateMeasurement
+ :raises RuntimeError: If TG is not set, or if node is not TG,
+ or if subtype is not specified.
+ :raises NotImplementedError: If TG is not supported.
+ """
+ duration = float(duration)
+ transmit_rate = float(transmit_rate)
+ # Trex needs target Tr per stream, but reports aggregate Tx and Dx.
+ unit_rate = str(transmit_rate / 2.0) + "pps"
+ self.send_traffic_on_tg(
+ duration, unit_rate, self.frame_size, self.traffic_type,
+ warmup_time=self.warmup_time, latency=True)
+ transmit_count = int(self.get_sent())
+ loss_count = int(self.get_loss())
+ measurement = ReceiveRateMeasurement(
+ duration, transmit_rate, transmit_count, loss_count)
+ measurement.latency = self.get_latency_int()
+ return measurement
+
+
+class OptimizedSearch(object):
+ """Class to be imported as Robot Library, containing a single keyword."""
+
+ @staticmethod
+ def perform_optimized_ndrpdr_search(
+ frame_size, traffic_type, minimum_transmit_rate,
+ maximum_transmit_rate, packet_loss_ratio=0.005,
+ final_relative_width=0.005, final_trial_duration=30.0,
+ initial_trial_duration=1.0, number_of_intermediate_phases=2,
+ timeout=720.0, doublings=1):
+ """Setup initialized TG, perform optimized search, return intervals.
+
+ :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 packet_loss_ratio: Fraction of packets lost, for PDR [1].
+ :param final_relative_width: Final lower bound transmit rate
+ cannot be more distant that this multiple of upper bound [1].
+ :param final_trial_duration: Trial duration for the final phase [s].
+ :param initial_trial_duration: Trial duration for the initial phase
+ and also for the first intermediate phase [s].
+ :param number_of_intermediate_phases: Number of intermediate phases
+ to perform before the final phase [1].
+ :param timeout: The search will fail itself when not finished
+ before this overall time [s].
+ :param doublings: How many doublings to do in external search step.
+ Default 1 is suitable for fairly stable tests,
+ less stable tests might get better overal duration with 2 or more.
+ :type frame_size: str or int
+ :type traffic_type: str
+ :type minimum_transmit_rate: float
+ :type maximum_transmit_rate: float
+ :type packet_loss_ratio: float
+ :type final_relative_width: float
+ :type final_trial_duration: float
+ :type initial_trial_duration: float
+ :type number_of_intermediate_phases: int
+ :type timeout: float
+ :type doublings: int
+ :returns: Structure containing narrowed down NDR and PDR intervals
+ and their measurements.
+ :rtype: NdrPdrResult
+ :raises RuntimeError: If total duration is larger than timeout.
+ """
+ # we need instance of TrafficGenerator instantiated by Robot Framework
+ # to be able to use trex_stl-*()
+ tg_instance = BuiltIn().get_library_instance(
+ 'resources.libraries.python.TrafficGenerator')
+ tg_instance.set_rate_provider_defaults(frame_size, traffic_type)
+ algorithm = MultipleLossRatioSearch(
+ measurer=tg_instance, final_trial_duration=final_trial_duration,
+ final_relative_width=final_relative_width,
+ number_of_intermediate_phases=number_of_intermediate_phases,
+ initial_trial_duration=initial_trial_duration, timeout=timeout,
+ doublings=doublings)
+ 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