Sysmetrics implementation update
[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 tools.load_gen.stress.stress import Stress
24 from tools.load_gen.stress_ng.stress_ng import StressNg
25 from tools.load_gen.dummy.dummy import DummyLoadGen
26
27
28 def __init__():
29     """Finds and loads all the modules required.
30
31     Very similar code to load_trafficgens().
32     """
33     pass
34
35 def create_traffic(traffic_type, trafficgen_class):
36     """Return a new IVSwitchController for the traffic type.
37
38     The returned traffic controller has the given traffic type and traffic
39     generator class.
40
41     traffic_types: 'rfc2544_throughput'
42
43     :param traffic_type: Name of traffic type
44     :param trafficgen_class: Reference to traffic generator class to be used.
45     :return: A new ITrafficController
46     """
47     return TrafficControllerRFC2544(trafficgen_class)
48
49
50 def create_vswitch(deployment_scenario, vswitch_class, bidir=True):
51     """Return a new IVSwitchController for the deployment_scenario.
52
53     The returned controller is configured with the given vSwitch class.
54
55     Deployment scenarios: 'p2p', 'pvp'
56
57     :param deployment_scenario: The deployment scenario name
58     :param vswitch_class: Reference to vSwitch class to be used.
59     :return: IVSwitchController for the deployment_scenario
60     """
61     #TODO - full mapping from all deployment_scenarios to
62     #correct controller class
63     deployment_scenario = deployment_scenario.lower()
64     if deployment_scenario.find("p2p") >= 0:
65         return VswitchControllerP2P(vswitch_class)
66     elif deployment_scenario.find("pvp") >= 0:
67         return VswitchControllerPVP(vswitch_class, bidir)
68
69 def create_vnf(deployment_scenario, vnf_class):
70     """Return a new IVnfController for the deployment_scenario.
71
72     The returned controller is configured with the given VNF class.
73
74     Deployment scenarios: 'p2p', 'pvp'
75
76     :param deployment_scenario: The deployment scenario name
77     :param vswitch_class: Reference to vSwitch class to be used.
78     :return: IVnfController for the deployment_scenario
79     """
80     #TODO - full mapping from all deployment_scenarios to
81     #correct controller class
82     deployment_scenario = deployment_scenario.lower()
83     if deployment_scenario.find("p2p") >= 0:
84         return VnfControllerP2P(None)
85     elif deployment_scenario.find("pvp") >= 0:
86         return VnfControllerPVP(vnf_class)
87
88 def create_collector(collector_class, result_dir, test_name):
89     """Return a new Collector of the given class
90
91     :param collector_class: The collector class to be used.
92     :param result_dir: Directory with test results
93     :param test_name: Test to be run
94     :return: A new CollectorController.
95     """
96     return collector_class(result_dir, test_name)
97
98 def create_loadgen(loadgen_type, loadgen_cfg):
99     """Return a new ILoadGenerator for the loadgen type.
100
101     The returned load generator has the given loadgen type and loadgen
102     generator class.
103
104     :param loadgen_type: Name of loadgen type
105     :param loadgen_class: Reference to load generator class to be used.
106     :return: A new ILoadGenerator class
107     """
108     loadgen_type = loadgen_type.lower()
109     if loadgen_type.find("dummy") >= 0:
110         return DummyLoadGen(loadgen_cfg)
111     elif loadgen_type.find("stress-ng") >= 0:
112         return StressNg(loadgen_cfg)
113     elif loadgen_type.find("stress") >= 0:
114         return Stress(loadgen_cfg)
115
116