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 """ Base class for the generic traffic profile implementation """
15
16 from __future__ import absolute_import
17 from yardstick.common.utils import import_modules_from_package, itersubclasses
18
19
20 class TrafficProfile(object):
21     """
22     This class defines the behavior
23
24     """
25     UPLINK = "uplink"
26     DOWNLINK = "downlink"
27
28     @staticmethod
29     def get(tp_config):
30         """Get the traffic profile instance for the given traffic type
31
32         :param tp_config: loaded YAML file
33         :return:
34         """
35         profile_class = tp_config["traffic_profile"]["traffic_type"]
36         import_modules_from_package(
37             "yardstick.network_services.traffic_profile")
38         try:
39             return next(c for c in itersubclasses(TrafficProfile)
40                         if c.__name__ == profile_class)(tp_config)
41         except StopIteration:
42             raise RuntimeError("No implementation for %s", profile_class)
43
44     def __init__(self, tp_config):
45         # e.g. RFC2544 start_ip, stop_ip, drop_rate,
46         # IMIX = {"10K": 0.1, "100M": 0.5}
47         self.params = tp_config
48
49     def execute_traffic(self, traffic_generator):
50         """ This methods defines the behavior of the traffic generator.
51         It will be called in a loop until the traffic generator exits.
52
53         :param traffic_generator: TrafficGen instance
54         :return: None
55         """
56         raise NotImplementedError()
57
58
59 class DummyProfile(TrafficProfile):
60     """
61     This is an empty TrafficProfile implementation - if it is used,
62     the traffic will be completely handled by the Traffic Generator
63     implementation with no regard for the Traffic Profile.
64     """
65     def execute(self, traffic_generator):
66         pass