1 # Copyright 2015 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 """Functions for creating controller objects based on deployment or traffic
18 from core.traffic_controller_rfc2544 import TrafficControllerRFC2544
19 from core.vswitch_controller_p2p import VswitchControllerP2P
20 from core.vswitch_controller_pvp import VswitchControllerPVP
21 from core.vswitch_controller_pvvp import VswitchControllerPVVP
22 from core.vnf_controller import VnfController
23 from tools.load_gen.stress.stress import Stress
24 from tools.load_gen.stress_ng.stress_ng import StressNg
25 from tools.load_gen.dummy.dummy import DummyLoadGen
29 """Finds and loads all the modules required.
31 Very similar code to load_trafficgens().
35 def create_traffic(traffic_type, trafficgen_class):
36 """Return a new IVSwitchController for the traffic type.
38 The returned traffic controller has the given traffic type and traffic
41 traffic_types: 'rfc2544_throughput'
43 :param traffic_type: Name of traffic type
44 :param trafficgen_class: Reference to traffic generator class to be used.
45 :return: A new ITrafficController
47 return TrafficControllerRFC2544(trafficgen_class)
50 def create_vswitch(deployment_scenario, vswitch_class, traffic):
51 """Return a new IVSwitchController for the deployment_scenario.
53 The returned controller is configured with the given vSwitch class.
55 Deployment scenarios: 'p2p', 'pvp'
57 :param deployment_scenario: The deployment scenario name
58 :param vswitch_class: Reference to vSwitch class to be used.
59 :param traffic: Dictionary with traffic specific details
60 :return: IVSwitchController for the deployment_scenario
62 deployment_scenario = deployment_scenario.lower()
63 if deployment_scenario.find("p2p") >= 0:
64 return VswitchControllerP2P(vswitch_class, traffic)
65 elif deployment_scenario.find("pvp") >= 0:
66 return VswitchControllerPVP(vswitch_class, traffic)
67 elif deployment_scenario.find("pvvp") >= 0:
68 return VswitchControllerPVVP(vswitch_class, traffic)
70 def create_vnf(deployment_scenario, vnf_class):
71 """Return a new VnfController for the deployment_scenario.
73 The returned controller is configured with the given VNF class.
75 Deployment scenarios: 'p2p', 'pvp'
77 :param deployment_scenario: The deployment scenario name
78 :param vswitch_class: Reference to vSwitch class to be used.
79 :return: VnfController for the deployment_scenario
81 return VnfController(deployment_scenario, vnf_class)
83 def create_collector(collector_class, result_dir, test_name):
84 """Return a new Collector of the given class
86 :param collector_class: The collector class to be used.
87 :param result_dir: Directory with test results
88 :param test_name: Test to be run
89 :return: A new CollectorController.
91 return collector_class(result_dir, test_name)
93 def create_loadgen(loadgen_type, loadgen_cfg):
94 """Return a new ILoadGenerator for the loadgen type.
96 The returned load generator has the given loadgen type and loadgen
99 :param loadgen_type: Name of loadgen type
100 :param loadgen_class: Reference to load generator class to be used.
101 :return: A new ILoadGenerator class
103 loadgen_type = loadgen_type.lower()
104 if loadgen_type.find("dummy") >= 0:
105 return DummyLoadGen(loadgen_cfg)
106 elif loadgen_type.find("stress-ng") >= 0:
107 return StressNg(loadgen_cfg)
108 elif loadgen_type.find("stress") >= 0:
109 return Stress(loadgen_cfg)