+ return None if async_call else self._get_measurement_result()
+
+ def _send_traffic_on_tg_with_ramp_up(
+ self, duration, rate, async_call=False, ramp_up_only=False):
+ """Send traffic from all interfaces on TG, maybe after ramp-up.
+
+ This is an internal function, it assumes set_rate_provider_defaults
+ has been called to remember most values.
+ The reason why need to remember various values is that
+ the traffic can be asynchronous, and parsing needs those values.
+ The reason why this is a separate function from the one
+ which calls set_rate_provider_defaults is that some search algorithms
+ need to specify their own values, and we do not want the measure call
+ to overwrite them with defaults.
+
+ If ramp-up tracking is detected, a computation is performed,
+ and if state timeout is near, trial at ramp-up rate and duration
+ is inserted before the main trial measurement.
+
+ The ramp_up_only parameter forces a ramp-up without immediate
+ trial measurement, which is useful in case self remembers
+ a previous ramp-up trial that belongs to a different test (phase).
+
+ Return None if trial is async or ramp-up only.
+
+ :param duration: Duration of test traffic generation in seconds.
+ :param rate: Traffic rate in transactions per second.
+ :param async_call: Async mode.
+ :param ramp_up_only: If true, do not perform main trial measurement.
+ :type duration: float
+ :type rate: float
+ :type async_call: bool
+ :type ramp_up_only: bool
+ :returns: TG results.
+ :rtype: ReceiveRateMeasurement or None
+ :raises ValueError: If TG traffic profile is not supported.
+ """
+ complete = False
+ if self.ramp_up_rate:
+ # Figure out whether we need to insert a ramp-up trial.
+ # TODO: Give up on async_call=True?
+ if ramp_up_only or self.ramp_up_start is None:
+ # We never ramped up yet (at least not in this test case).
+ ramp_up_needed = True
+ else:
+ # We ramped up before, but maybe it was too long ago.
+ # Adding a constant overhead to be safe.
+ time_now = time.monotonic() + 1.0
+ computed_duration, complete = self._compute_duration(
+ duration=duration,
+ multiplier=rate,
+ )
+ # There are two conditions for inserting ramp-up.
+ # If early sessions are expiring already,
+ # or if late sessions are to expire before measurement is over.
+ ramp_up_start_delay = time_now - self.ramp_up_start
+ ramp_up_stop_delay = time_now - self.ramp_up_stop
+ ramp_up_stop_delay += computed_duration
+ bigger_delay = max(ramp_up_start_delay, ramp_up_stop_delay)
+ # Final boolean decision.
+ ramp_up_needed = (bigger_delay >= self.state_timeout)
+ if ramp_up_needed:
+ logger.debug(
+ u"State may time out during next real trial, "
+ u"inserting a ramp-up trial."
+ )
+ self.ramp_up_start = time.monotonic()
+ self._send_traffic_on_tg_internal(
+ duration=self.ramp_up_duration,
+ rate=self.ramp_up_rate,
+ async_call=async_call,
+ )
+ self.ramp_up_stop = time.monotonic()
+ logger.debug(u"Ramp-up done.")
+ else:
+ logger.debug(
+ u"State will probably not time out during next real trial, "
+ u"no ramp-up trial needed just yet."
+ )
+ if ramp_up_only:
+ return None
+ trial_start = time.monotonic()
+ result = self._send_traffic_on_tg_internal(
+ duration=duration,
+ rate=rate,
+ async_call=async_call,
+ )
+ trial_end = time.monotonic()
+ if self.ramp_up_rate:
+ # Optimization: No loss acts as a good ramp-up, if it was complete.
+ if complete and result is not None and result.loss_count == 0:
+ logger.debug(u"Good trial acts as a ramp-up")
+ self.ramp_up_start = trial_start
+ self.ramp_up_stop = trial_end
+ else:
+ logger.debug(u"Loss or incomplete, does not act as a ramp-up.")
+ return result