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 #TODO - full mapping from all traffic_types to
46 #correct controller class
47 return TrafficControllerRFC2544(trafficgen_class)
49 def create_vswitch(deployment_scenario, vswitch_class):
50 """Return a new IVSwitchController for the deployment_scenario.
52 The returned controller is configured with the given vSwitch class.
54 Deployment scenarios: 'p2p', 'pvp'
56 :param deployment_scenario: The deployment scenario name
57 :param vswitch_class: Reference to vSwitch class to be used.
58 :return: IVSwitchController for the deployment_scenario
60 #TODO - full mapping from all deployment_scenarios to
61 #correct controller class
62 deployment_scenario = deployment_scenario.lower()
63 if deployment_scenario.find("p2p") >= 0:
64 return VswitchControllerP2P(vswitch_class)
65 elif deployment_scenario.find("pvp") >= 0:
66 return VswitchControllerPVP(vswitch_class)
68 def create_vnf(deployment_scenario, vnf_class):
69 """Return a new IVnfController for the deployment_scenario.
71 The returned controller is configured with the given VNF class.
73 Deployment scenarios: 'p2p', 'pvp'
75 :param deployment_scenario: The deployment scenario name
76 :param vswitch_class: Reference to vSwitch class to be used.
77 :return: IVnfController for the deployment_scenario
79 #TODO - full mapping from all deployment_scenarios to
80 #correct controller class
81 deployment_scenario = deployment_scenario.lower()
82 if deployment_scenario.find("p2p") >= 0:
83 return VnfControllerP2P(vnf_class)
84 elif deployment_scenario.find("pvp") >= 0:
85 return VnfControllerPVP(vnf_class)
87 def create_collector(collector, collector_class):
88 """Return a new CollectorController of the given class
90 Supported collector type strings:
94 :param collector: Collector type string
95 :param collector_class: The collector class to be used.
96 :return: A new CollectorController.
98 collector = collector.lower()
99 if "cpu" in collector or "memory" in collector:
100 return CollectorController(collector_class)