Merge "framework: Add reworked framework to repo"
[vswitchperf.git] / core / component_factory.py
1 # Copyright 2015 Intel Corporation.
2 #
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
6 #
7 #   http://www.apache.org/licenses/LICENSE-2.0
8 #
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.
14
15 """Functions for creating controller objects based on deployment or traffic
16 """
17
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
24
25
26 def __init__():
27     """Finds and loads all the modules required.
28
29     Very similar code to load_trafficgens().
30     """
31     pass
32
33 def create_traffic(traffic_type, trafficgen_class):
34     """Return a new IVSwitchController for the traffic type.
35
36     The returned traffic controller has the given traffic type and traffic
37     generator class.
38
39     traffic_types: 'rfc2544_throughput'
40
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
44     """
45     #TODO - full mapping from all traffic_types to
46     #correct controller class
47     return TrafficControllerRFC2544(trafficgen_class)
48
49 def create_vswitch(deployment_scenario, vswitch_class):
50     """Return a new IVSwitchController for the deployment_scenario.
51
52     The returned controller is configured with the given vSwitch class.
53
54     Deployment scenarios: 'p2p', 'pvp'
55
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
59     """
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)
67
68 def create_vnf(deployment_scenario, vnf_class):
69     """Return a new IVnfController for the deployment_scenario.
70
71     The returned controller is configured with the given VNF class.
72
73     Deployment scenarios: 'p2p', 'pvp'
74
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
78     """
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)
86
87 def create_collector(collector, collector_class):
88     """Return a new CollectorController of the given class
89
90     Supported collector type strings:
91     'cpu'
92     'memory':
93
94     :param collector: Collector type string
95     :param collector_class: The collector class to be used.
96     :return: A new CollectorController.
97     """
98     collector = collector.lower()
99     if "cpu" in collector or "memory" in collector:
100         return CollectorController(collector_class)
101