1 # Copyright 2015-2016 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_clean import VswitchControllerClean
20 from core.vswitch_controller_p2p import VswitchControllerP2P
21 from core.vswitch_controller_pvp import VswitchControllerPVP
22 from core.vswitch_controller_pvvp import VswitchControllerPVVP
23 from core.vswitch_controller_op2p import VswitchControllerOP2P
24 from core.vnf_controller import VnfController
25 from core.pktfwd_controller import PktFwdController
26 from tools.load_gen.stress.stress import Stress
27 from tools.load_gen.stress_ng.stress_ng import StressNg
28 from tools.load_gen.dummy.dummy import DummyLoadGen
32 """Finds and loads all the modules required.
34 Very similar code to load_trafficgens().
38 def create_traffic(traffic_type, trafficgen_class):
39 """Return a new IVSwitchController for the traffic type.
41 The returned traffic controller has the given traffic type and traffic
44 traffic_types: 'rfc2544_throughput'
46 :param traffic_type: Name of traffic type
47 :param trafficgen_class: Reference to traffic generator class to be used.
48 :return: A new ITrafficController
50 return TrafficControllerRFC2544(trafficgen_class)
53 def create_vswitch(deployment_scenario, vswitch_class, traffic,
54 tunnel_operation=None):
55 """Return a new IVSwitchController for the deployment_scenario.
57 The returned controller is configured with the given vSwitch class.
59 Deployment scenarios: 'p2p', 'pvp'
61 :param deployment_scenario: The deployment scenario name
62 :param vswitch_class: Reference to vSwitch class to be used.
63 :param traffic: Dictionary with traffic specific details
64 :param tunnel_operation encapsulation/decapsulation or None
65 :return: IVSwitchController for the deployment_scenario
67 deployment_scenario = deployment_scenario.lower()
68 if deployment_scenario.find("p2p") == 0:
69 return VswitchControllerP2P(vswitch_class, traffic)
70 elif deployment_scenario.find("pvp") >= 0:
71 return VswitchControllerPVP(vswitch_class, traffic)
72 elif deployment_scenario.find("pvvp") >= 0:
73 return VswitchControllerPVVP(vswitch_class, traffic)
74 elif deployment_scenario.find("op2p") >= 0:
75 return VswitchControllerOP2P(vswitch_class, traffic, tunnel_operation)
76 elif deployment_scenario.find("clean") >= 0:
77 return VswitchControllerClean(vswitch_class, traffic)
80 def create_vnf(deployment_scenario, vnf_class):
81 """Return a new VnfController for the deployment_scenario.
83 The returned controller is configured with the given VNF class.
85 Deployment scenarios: 'p2p', 'pvp'
87 :param deployment_scenario: The deployment scenario name
88 :param vswitch_class: Reference to vSwitch class to be used.
89 :return: VnfController for the deployment_scenario
91 return VnfController(deployment_scenario, vnf_class)
93 def create_collector(collector_class, result_dir, test_name):
94 """Return a new Collector of the given class
96 :param collector_class: The collector class to be used.
97 :param result_dir: Directory with test results
98 :param test_name: Test to be run
99 :return: A new CollectorController.
101 return collector_class(result_dir, test_name)
103 def create_loadgen(loadgen_type, loadgen_cfg):
104 """Return a new ILoadGenerator for the loadgen type.
106 The returned load generator has the given loadgen type and loadgen
109 :param loadgen_type: Name of loadgen type
110 :param loadgen_class: Reference to load generator class to be used.
111 :return: A new ILoadGenerator class
113 loadgen_type = loadgen_type.lower()
114 if loadgen_type.find("dummy") >= 0:
115 return DummyLoadGen(loadgen_cfg)
116 elif loadgen_type.find("stress-ng") >= 0:
117 return StressNg(loadgen_cfg)
118 elif loadgen_type.find("stress") >= 0:
119 return Stress(loadgen_cfg)
121 def create_pktfwd(deployment, pktfwd_class):
122 """Return a new packet forwarder controller
124 The returned controller is configured with the given
125 packet forwarder class.
127 :param pktfwd_class: Reference to packet forwarder class to be used.
128 :param deployment: The deployment scenario name
129 :return: packet forwarder controller
131 return PktFwdController(deployment, pktfwd_class)