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.
15 from yardstick.common import exceptions
16 from yardstick.common import utils
19 class TrafficProfile(object):
21 This class defines the behavior
29 """Get the traffic profile instance for the given traffic type
31 :param tp_config: loaded YAML file
34 profile_class = tp_config["traffic_profile"]["traffic_type"]
36 return next(c for c in utils.itersubclasses(TrafficProfile)
37 if c.__name__ == profile_class)(tp_config)
39 raise exceptions.TrafficProfileNotImplemented(
40 profile_class=profile_class)
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
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.
51 :param traffic_generator: TrafficGen instance
54 raise NotImplementedError()
57 class DummyProfile(TrafficProfile):
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.
63 def execute(self, traffic_generator):