Merge "Prohibit the importation of a list of libraries"
[yardstick.git] / yardstick / network_services / traffic_profile / base.py
1 # Copyright (c) 2016-2017 Intel Corporation
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #      http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14
15 from yardstick.common import exceptions
16 from yardstick.common import utils
17
18
19 class TrafficProfile(object):
20     """
21     This class defines the behavior
22
23     """
24     UPLINK = "uplink"
25     DOWNLINK = "downlink"
26
27     @staticmethod
28     def get(tp_config):
29         """Get the traffic profile instance for the given traffic type
30
31         :param tp_config: loaded YAML file
32         :return:
33         """
34         profile_class = tp_config["traffic_profile"]["traffic_type"]
35         try:
36             return next(c for c in utils.itersubclasses(TrafficProfile)
37                         if c.__name__ == profile_class)(tp_config)
38         except StopIteration:
39             raise exceptions.TrafficProfileNotImplemented(
40                 profile_class=profile_class)
41
42     def __init__(self, tp_config):
43         # e.g. RFC2544 start_ip, stop_ip, drop_rate,
44         # IMIX = {"10K": 0.1, "100M": 0.5}
45         self.params = tp_config
46
47     def execute_traffic(self, traffic_generator):
48         """ This methods defines the behavior of the traffic generator.
49         It will be called in a loop until the traffic generator exits.
50
51         :param traffic_generator: TrafficGen instance
52         :return: None
53         """
54         raise NotImplementedError()
55
56
57 class DummyProfile(TrafficProfile):
58     """
59     This is an empty TrafficProfile implementation - if it is used,
60     the traffic will be completely handled by the Traffic Generator
61     implementation with no regard for the Traffic Profile.
62     """
63     def execute(self, traffic_generator):
64         pass