Merge "docs: Update E release notes"
[vswitchperf.git] / core / component_factory.py
1 # Copyright 2015-2017 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.traffic_controller_rfc2889 import TrafficControllerRFC2889
20 from core.vswitch_controller_clean import VswitchControllerClean
21 from core.vswitch_controller_p2p import VswitchControllerP2P
22 from core.vswitch_controller_pxp import VswitchControllerPXP
23 from core.vswitch_controller_op2p import VswitchControllerOP2P
24 from core.vswitch_controller_ptunp import VswitchControllerPtunP
25 from core.vnf_controller import VnfController
26 from core.pktfwd_controller import PktFwdController
27 from tools.load_gen.stress.stress import Stress
28 from tools.load_gen.stress_ng.stress_ng import StressNg
29 from tools.load_gen.dummy.dummy import DummyLoadGen
30
31
32 def __init__():
33     """Finds and loads all the modules required.
34
35     Very similar code to load_trafficgens().
36     """
37     pass
38
39 def create_traffic(traffic_type, trafficgen_class):
40     """Return a new IVSwitchController for the traffic type.
41
42     The returned traffic controller has the given traffic type and traffic
43     generator class.
44
45     traffic_types: 'rfc2544_throughput'
46
47     :param traffic_type: Name of traffic type
48     :param trafficgen_class: Reference to traffic generator class to be used.
49     :return: A new TrafficController
50     """
51     if traffic_type.lower().startswith('rfc2889'):
52         return TrafficControllerRFC2889(trafficgen_class)
53     else:
54         return TrafficControllerRFC2544(trafficgen_class)
55
56
57 def create_vswitch(deployment_scenario, vswitch_class, traffic,
58                    tunnel_operation=None):
59     """Return a new IVSwitchController for the deployment_scenario.
60
61     The returned controller is configured with the given vSwitch class.
62
63     Deployment scenarios: e.g. 'p2p', 'pvp', 'pvpv12', etc.
64
65     :param deployment_scenario: The deployment scenario name
66     :param vswitch_class: Reference to vSwitch class to be used.
67     :param traffic: Dictionary with traffic specific details
68     :param tunnel_operation encapsulation/decapsulation or None
69     :return: IVSwitchController for the deployment_scenario
70     """
71     # pylint: disable=too-many-return-statements
72     deployment_scenario = deployment_scenario.lower()
73     if deployment_scenario.startswith("p2p"):
74         return VswitchControllerP2P(vswitch_class, traffic)
75     elif deployment_scenario.startswith("pvp"):
76         return VswitchControllerPXP(deployment_scenario, vswitch_class, traffic)
77     elif deployment_scenario.startswith("pvvp"):
78         return VswitchControllerPXP(deployment_scenario, vswitch_class, traffic)
79     elif deployment_scenario.startswith("pvpv"):
80         return VswitchControllerPXP(deployment_scenario, vswitch_class, traffic)
81     elif deployment_scenario.startswith("op2p"):
82         return VswitchControllerOP2P(vswitch_class, traffic, tunnel_operation)
83     elif deployment_scenario.startswith("ptunp"):
84         return VswitchControllerPtunP(vswitch_class, traffic)
85     elif deployment_scenario.startswith("clean"):
86         return VswitchControllerClean(vswitch_class, traffic)
87     else:
88         raise RuntimeError("Unknown deployment scenario '{}'.".format(deployment_scenario))
89
90
91 def create_vnf(deployment_scenario, vnf_class, extra_vnfs):
92     """Return a new VnfController for the deployment_scenario.
93
94     The returned controller is configured with the given VNF class.
95
96     Deployment scenarios: 'p2p', 'pvp'
97
98     :param deployment_scenario: The deployment scenario name
99     :param vswitch_class: Reference to vSwitch class to be used.
100     :param extra_vnfs: The number of VNFs not involved in given
101         deployment scenario. It will be used to correctly expand
102         configuration values and initialize shared dirs. This parameter
103         is used in case, that additional VNFs are executed by TestSteps.
104     :return: VnfController for the deployment_scenario
105     """
106     return VnfController(deployment_scenario, vnf_class, extra_vnfs)
107
108 def create_collector(collector_class, result_dir, test_name):
109     """Return a new Collector of the given class
110
111     :param collector_class: The collector class to be used.
112     :param result_dir: Directory with test results
113     :param test_name: Test to be run
114     :return: A new CollectorController.
115     """
116     return collector_class(result_dir, test_name)
117
118 def create_loadgen(loadgen_type, loadgen_cfg):
119     """Return a new ILoadGenerator for the loadgen type.
120
121     The returned load generator has the given loadgen type and loadgen
122     generator class.
123
124     :param loadgen_type: Name of loadgen type
125     :param loadgen_class: Reference to load generator class to be used.
126     :return: A new ILoadGenerator class
127     """
128     # pylint: disable=too-many-function-args
129     loadgen_type = loadgen_type.lower()
130     if loadgen_type.find("dummy") >= 0:
131         return DummyLoadGen(loadgen_cfg)
132     elif loadgen_type.find("stress-ng") >= 0:
133         return StressNg(loadgen_cfg)
134     elif loadgen_type.find("stress") >= 0:
135         return Stress(loadgen_cfg)
136
137 def create_pktfwd(deployment, pktfwd_class):
138     """Return a new packet forwarder controller
139
140     The returned controller is configured with the given
141     packet forwarder class.
142
143     :param pktfwd_class: Reference to packet forwarder class to be used.
144     :param deployment: The deployment scenario name
145     :return: packet forwarder controller
146     """
147     return PktFwdController(deployment, pktfwd_class)