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.
25 DEFAULT_SCHEMA = 'nsb:traffic_profile:0.1'
26 DEFAULT_FRAME_RATE = 100
29 def __init__(self, tp_config):
30 self.schema = tp_config.get('schema', self.DEFAULT_SCHEMA)
31 self.name = tp_config.get('name')
32 self.description = tp_config.get('description')
33 tprofile = tp_config['traffic_profile']
34 self.traffic_type = tprofile.get('traffic_type')
35 self.frame_rate = tprofile.get('frame_rate', self.DEFAULT_FRAME_RATE)
36 self.test_precision = tprofile.get('test_precision')
37 self.packet_sizes = tprofile.get('packet_sizes')
38 self.duration = tprofile.get('duration', self.DEFAULT_DURATION)
39 self.lower_bound = tprofile.get('lower_bound')
40 self.upper_bound = tprofile.get('upper_bound')
41 self.step_interval = tprofile.get('step_interval')
44 class TrafficProfile(object):
46 This class defines the behavior
54 """Get the traffic profile instance for the given traffic type
56 :param tp_config: loaded YAML file
59 profile_class = tp_config["traffic_profile"]["traffic_type"]
61 return next(c for c in utils.itersubclasses(TrafficProfile)
62 if c.__name__ == profile_class)(tp_config)
64 raise exceptions.TrafficProfileNotImplemented(
65 profile_class=profile_class)
67 def __init__(self, tp_config):
68 # e.g. RFC2544 start_ip, stop_ip, drop_rate,
69 # IMIX = {"10K": 0.1, "100M": 0.5}
70 self.params = tp_config
71 self.config = TrafficProfileConfig(tp_config)
73 def execute_traffic(self, traffic_generator, **kawrgs):
74 """ This methods defines the behavior of the traffic generator.
75 It will be called in a loop until the traffic generator exits.
77 :param traffic_generator: TrafficGen instance
80 raise NotImplementedError()
83 class DummyProfile(TrafficProfile):
85 This is an empty TrafficProfile implementation - if it is used,
86 the traffic will be completely handled by the Traffic Generator
87 implementation with no regard for the Traffic Profile.
89 def execute(self, traffic_generator):