1 # Copyright (c) 2018 Cisco and/or its affiliates.
2 # Licensed under the Apache License, Version 2.0 (the "License");
3 # you may not use this file except in compliance with the License.
4 # You may obtain a copy of the License at:
6 # http://www.apache.org/licenses/LICENSE-2.0
8 # Unless required by applicable law or agreed to in writing, software
9 # distributed under the License is distributed on an "AS IS" BASIS,
10 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 # See the License for the specific language governing permissions and
12 # limitations under the License.
14 """Module defining ReceiveRateMeasurement class."""
17 class ReceiveRateMeasurement(object):
18 """Structure defining the result of single Rr measurement."""
20 def __init__(self, duration, target_tr, transmit_count, loss_count):
21 """Constructor, normalize primary and compute secondary quantities.
23 :param duration: Measurement duration [s].
24 :param target_tr: Target transmit rate [pps].
25 If bidirectional traffic is measured, this is bidirectional rate.
26 :param transmit_count: Number of packets transmitted [1].
27 :param loss_count: Number of packets transmitted but not received [1].
29 :type target_tr: float
30 :type transmit_count: int
33 self.duration = float(duration)
34 self.target_tr = float(target_tr)
35 self.transmit_count = int(transmit_count)
36 self.loss_count = int(loss_count)
37 self.receive_count = transmit_count - loss_count
38 self.transmit_rate = transmit_count / self.duration
39 self.loss_rate = loss_count / self.duration
40 self.receive_rate = self.receive_count / self.duration
41 self.loss_fraction = float(self.loss_count) / self.transmit_count
42 # TODO: Do we want to store also the real time (duration + overhead)?
45 """Return string reporting input and loss fraction."""
46 return "d={dur!s},Tr={rate!s},Df={frac!s}".format(
47 dur=self.duration, rate=self.target_tr, frac=self.loss_fraction)
50 """Return string evaluable as a constructor call."""
51 return ("ReceiveRateMeasurement(duration={dur!r},target_tr={rate!r}"
52 ",transmit_count={trans!r},loss_count={loss!r})".format(
53 dur=self.duration, rate=self.target_tr,
54 trans=self.transmit_count, loss=self.loss_count))