1 # Copyright (c) 2016-2017 Intel Corporation
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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 """
16 from __future__ import absolute_import
17 from yardstick.common.utils import import_modules_from_package, itersubclasses
20 class TrafficProfile(object):
22 This class defines the behavior
30 """Get the traffic profile instance for the given traffic type
32 :param tp_config: loaded YAML file
35 profile_class = tp_config["traffic_profile"]["traffic_type"]
36 import_modules_from_package(
37 "yardstick.network_services.traffic_profile")
39 return next(c for c in itersubclasses(TrafficProfile)
40 if c.__name__ == profile_class)(tp_config)
42 raise RuntimeError("No implementation for %s", profile_class)
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
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.
53 :param traffic_generator: TrafficGen instance
56 raise NotImplementedError()
59 class DummyProfile(TrafficProfile):
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.
65 def execute(self, traffic_generator):