docs: adding license to rest of rst files
[vswitchperf.git] / core / component_factory.py
1 # Copyright 2015-2016 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.vswitch_controller_pvvp import VswitchControllerPVVP
22 from core.vswitch_controller_op2p import VswitchControllerOP2P
23 from core.vnf_controller import VnfController
24 from core.pktfwd_controller import PktFwdController
25 from tools.load_gen.stress.stress import Stress
26 from tools.load_gen.stress_ng.stress_ng import StressNg
27 from tools.load_gen.dummy.dummy import DummyLoadGen
28
29
30 def __init__():
31     """Finds and loads all the modules required.
32
33     Very similar code to load_trafficgens().
34     """
35     pass
36
37 def create_traffic(traffic_type, trafficgen_class):
38     """Return a new IVSwitchController for the traffic type.
39
40     The returned traffic controller has the given traffic type and traffic
41     generator class.
42
43     traffic_types: 'rfc2544_throughput'
44
45     :param traffic_type: Name of traffic type
46     :param trafficgen_class: Reference to traffic generator class to be used.
47     :return: A new ITrafficController
48     """
49     return TrafficControllerRFC2544(trafficgen_class)
50
51
52 def create_vswitch(deployment_scenario, vswitch_class, traffic,
53                    tunnel_operation=None):
54     """Return a new IVSwitchController for the deployment_scenario.
55
56     The returned controller is configured with the given vSwitch class.
57
58     Deployment scenarios: 'p2p', 'pvp'
59
60     :param deployment_scenario: The deployment scenario name
61     :param vswitch_class: Reference to vSwitch class to be used.
62     :param traffic: Dictionary with traffic specific details
63     :param tunnel_operation encapsulation/decapsulation or None
64     :return: IVSwitchController for the deployment_scenario
65     """
66     deployment_scenario = deployment_scenario.lower()
67     if deployment_scenario.find("p2p") == 0:
68         return VswitchControllerP2P(vswitch_class, traffic)
69     elif deployment_scenario.find("pvp") >= 0:
70         return VswitchControllerPVP(vswitch_class, traffic)
71     elif deployment_scenario.find("pvvp") >= 0:
72         return VswitchControllerPVVP(vswitch_class, traffic)
73     elif deployment_scenario.find("op2p") >= 0:
74         return VswitchControllerOP2P(vswitch_class, traffic, tunnel_operation)
75
76
77 def create_vnf(deployment_scenario, vnf_class):
78     """Return a new VnfController for the deployment_scenario.
79
80     The returned controller is configured with the given VNF class.
81
82     Deployment scenarios: 'p2p', 'pvp'
83
84     :param deployment_scenario: The deployment scenario name
85     :param vswitch_class: Reference to vSwitch class to be used.
86     :return: VnfController for the deployment_scenario
87     """
88     return VnfController(deployment_scenario, vnf_class)
89
90 def create_collector(collector_class, result_dir, test_name):
91     """Return a new Collector of the given class
92
93     :param collector_class: The collector class to be used.
94     :param result_dir: Directory with test results
95     :param test_name: Test to be run
96     :return: A new CollectorController.
97     """
98     return collector_class(result_dir, test_name)
99
100 def create_loadgen(loadgen_type, loadgen_cfg):
101     """Return a new ILoadGenerator for the loadgen type.
102
103     The returned load generator has the given loadgen type and loadgen
104     generator class.
105
106     :param loadgen_type: Name of loadgen type
107     :param loadgen_class: Reference to load generator class to be used.
108     :return: A new ILoadGenerator class
109     """
110     loadgen_type = loadgen_type.lower()
111     if loadgen_type.find("dummy") >= 0:
112         return DummyLoadGen(loadgen_cfg)
113     elif loadgen_type.find("stress-ng") >= 0:
114         return StressNg(loadgen_cfg)
115     elif loadgen_type.find("stress") >= 0:
116         return Stress(loadgen_cfg)
117
118 def create_pktfwd(pktfwd_class):
119     """Return a new packet forwarder controller
120
121     The returned controller is configured with the given
122     packet forwarder class.
123
124     :param pktfwd_class: Reference to packet forwarder class to be used.
125     :return: packet forwarder controller
126     """
127     return PktFwdController(pktfwd_class)