Add a simple performance test that sends a continuous stream
[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     return TrafficControllerRFC2544(trafficgen_class)
46
47
48 def create_vswitch(deployment_scenario, vswitch_class):
49     """Return a new IVSwitchController for the deployment_scenario.
50
51     The returned controller is configured with the given vSwitch class.
52
53     Deployment scenarios: 'p2p', 'pvp'
54
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
58     """
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)
66
67 def create_vnf(deployment_scenario, vnf_class):
68     """Return a new IVnfController for the deployment_scenario.
69
70     The returned controller is configured with the given VNF class.
71
72     Deployment scenarios: 'p2p', 'pvp'
73
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
77     """
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)
85
86 def create_collector(collector, collector_class):
87     """Return a new CollectorController of the given class
88
89     Supported collector type strings:
90     'cpu'
91     'memory':
92
93     :param collector: Collector type string
94     :param collector_class: The collector class to be used.
95     :return: A new CollectorController.
96     """
97     collector = collector.lower()
98     if "cpu" in collector or "memory" in collector:
99         return CollectorController(collector_class)
100