Revert "CSIT-986: Use MLRsearch from pip"
[csit.git] / resources / libraries / python / search / ReceiveRateMeasurement.py
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:
5 #
6 #     http://www.apache.org/licenses/LICENSE-2.0
7 #
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.
13
14 """Module defining ReceiveRateMeasurement class."""
15
16
17 class ReceiveRateMeasurement(object):
18     """Structure defining the result of single Rr measurement."""
19
20     def __init__(self, duration, target_tr, transmit_count, loss_count):
21         """Constructor, normalize primary and compute secondary quantities.
22
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].
28         :type duration: float
29         :type target_tr: float
30         :type transmit_count: int
31         :type loss_count: int
32         """
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)?
43
44     def __str__(self):
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)
48
49     def __repr__(self):
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))

©2016 FD.io a Linux Foundation Collaborative Project. All Rights Reserved.
Linux Foundation is a registered trademark of The Linux Foundation. Linux is a registered trademark of Linus Torvalds.
Please see our privacy policy and terms of use.