+ def get_measurement_result(self, duration=None, transmit_rate=None):
+ """Return the result of last measurement as ReceiveRateMeasurement.
+
+ Separate function, as measurements can end either by time
+ or by explicit call, this is the common block at the end.
+
+ TODO: Fail on running or already reported measurement.
+
+ :param duration: Measurement duration [s] if known beforehand.
+ For explicitly stopped measurement it is estimated.
+ :param transmit_rate: Target aggregate transmit rate [pps].
+ If not given, computed assuming it was bidirectional.
+ :type duration: float or NoneType
+ :type transmit_rate: float or NoneType
+ :returns: Structure containing the result of the measurement.
+ :rtype: ReceiveRateMeasurement
+ """
+ if duration is None:
+ duration = time.time() - self._start_time
+ self._start_time = None
+ if transmit_rate is None:
+ # Assuming bi-directional traffic here.
+ transmit_rate = self._rate * 2.0
+ 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
+