feat(MLRsearch): MLRsearch v7
[csit.git] / resources / libraries / python / MLRsearch / trial_measurement / abstract_measurer.py
1 # Copyright (c) 2023 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 AbstractMeasurer class."""
15
16 from abc import ABCMeta, abstractmethod
17
18 from .measurement_result import MeasurementResult as Result
19
20
21 class AbstractMeasurer(metaclass=ABCMeta):
22     """Abstract class defining common API for trial measurement providers.
23
24     The original use of this class was in the realm of
25     RFC 2544 Throughput search, which explains the teminology
26     related to networks, frames, packets, offered load, forwarding rate
27     and similar.
28
29     But the same logic can be used in higher level networking scenarios
30     (e.g. https requests) or even outside networking (database transactions).
31
32     The current code uses language from packet forwarding,
33     docstring sometimes mention transactions as an alternative view.
34     """
35
36     @abstractmethod
37     def measure(self, intended_duration: float, intended_load: float) -> Result:
38         """Perform trial measurement and return the result.
39
40         It is assumed the measurer got already configured with anything else
41         needed to perform the measurement (e.g. traffic profile
42         or transaction limit).
43
44         Duration and load are the only values expected to vary
45         during the search.
46
47         :param intended_duration: Intended trial duration [s].
48         :param intended_load: Intended rate of transactions (packets) [tps].
49             It is a per-port rate, e.g. uni-directional for SUTs
50             with two ports.
51         :type intended_duration: float
52         :type intended_load: float
53         :returns: Structure detailing the result of the measurement.
54         :rtype: measurement_result.MeasurementResult
55         """