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.vnf_controller_p2p import VnfControllerP2P
22 from core.vnf_controller_pvp import VnfControllerPVP
23 from core.collector_controller import CollectorController
27 """Finds and loads all the modules required.
29 Very similar code to load_trafficgens().
33 def create_traffic(traffic_type, trafficgen_class):
34 """Return a new IVSwitchController for the traffic type.
36 The returned traffic controller has the given traffic type and traffic
39 traffic_types: 'rfc2544_throughput'
41 :param traffic_type: Name of traffic type
42 :param trafficgen_class: Reference to traffic generator class to be used.
43 :return: A new ITrafficController
45 return TrafficControllerRFC2544(trafficgen_class)
48 def create_vswitch(deployment_scenario, vswitch_class):
49 """Return a new IVSwitchController for the deployment_scenario.
51 The returned controller is configured with the given vSwitch class.
53 Deployment scenarios: 'p2p', 'pvp'
55 :param deployment_scenario: The deployment scenario name
56 :param vswitch_class: Reference to vSwitch class to be used.
57 :return: IVSwitchController for the deployment_scenario
59 #TODO - full mapping from all deployment_scenarios to
60 #correct controller class
61 deployment_scenario = deployment_scenario.lower()
62 if deployment_scenario.find("p2p") >= 0:
63 return VswitchControllerP2P(vswitch_class)
64 elif deployment_scenario.find("pvp") >= 0:
65 return VswitchControllerPVP(vswitch_class)
67 def create_vnf(deployment_scenario, vnf_class):
68 """Return a new IVnfController for the deployment_scenario.
70 The returned controller is configured with the given VNF class.
72 Deployment scenarios: 'p2p', 'pvp'
74 :param deployment_scenario: The deployment scenario name
75 :param vswitch_class: Reference to vSwitch class to be used.
76 :return: IVnfController for the deployment_scenario
78 #TODO - full mapping from all deployment_scenarios to
79 #correct controller class
80 deployment_scenario = deployment_scenario.lower()
81 if deployment_scenario.find("p2p") >= 0:
82 return VnfControllerP2P(vnf_class)
83 elif deployment_scenario.find("pvp") >= 0:
84 return VnfControllerPVP(vnf_class)
86 def create_collector(collector, collector_class):
87 """Return a new CollectorController of the given class
89 Supported collector type strings:
93 :param collector: Collector type string
94 :param collector_class: The collector class to be used.
95 :return: A new CollectorController.
97 collector = collector.lower()
98 if "cpu" in collector or "memory" in collector:
99 return CollectorController(collector_class)