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 TrafficProfileConfig(object):
20 """Class to contain the TrafficProfile class information
22 This object will parse and validate the traffic profile information.
24 def __init__(self, tp_config):
25 self.schema = tp_config.get('schema', 'nsb:traffic_profile:0.1')
26 self.name = tp_config.get('name')
27 self.description = tp_config.get('description')
28 tprofile = tp_config['traffic_profile']
29 self.traffic_type = tprofile.get('traffic_type')
30 self.frame_rate = tprofile.get('frame_rate')
31 self.test_precision = tprofile.get('test_precision')
32 self.packet_sizes = tprofile.get('packet_sizes')
33 self.duration = tprofile.get('duration')
34 self.lower_bound = tprofile.get('lower_bound')
35 self.upper_bound = tprofile.get('upper_bound')
36 self.step_interval = tprofile.get('step_interval')
39 class TrafficProfile(object):
41 This class defines the behavior
50 """Get the traffic profile instance for the given traffic type
52 :param tp_config: loaded YAML file
55 profile_class = tp_config["traffic_profile"]["traffic_type"]
57 return next(c for c in utils.itersubclasses(TrafficProfile)
58 if c.__name__ == profile_class)(tp_config)
60 raise exceptions.TrafficProfileNotImplemented(
61 profile_class=profile_class)
63 def __init__(self, tp_config):
64 # e.g. RFC2544 start_ip, stop_ip, drop_rate,
65 # IMIX = {"10K": 0.1, "100M": 0.5}
66 self.params = tp_config
67 self.config = TrafficProfileConfig(tp_config)
69 def execute_traffic(self, traffic_generator, **kawrgs):
70 """ This methods defines the behavior of the traffic generator.
71 It will be called in a loop until the traffic generator exits.
73 :param traffic_generator: TrafficGen instance
76 raise NotImplementedError()
79 class DummyProfile(TrafficProfile):
81 This is an empty TrafficProfile implementation - if it is used,
82 the traffic will be completely handled by the Traffic Generator
83 implementation with no regard for the Traffic Profile.
85 def execute(self, traffic_generator):