dcd77cede8cd8463c0281d8612a4e8c8b8d8b20e
[vswitchperf.git] / core / loader / loader.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 """Loader module definition.
16 """
17
18 from conf import settings
19 from core.loader.loader_servant import LoaderServant
20 from tools.collectors.collector import ICollector
21 from tools.load_gen.load_gen import ILoadGenerator
22 from tools.pkt_fwd.pkt_fwd import IPktFwd
23 from tools.pkt_gen.trafficgen import ITrafficGenerator
24 from vswitches.vswitch import IVSwitch
25 from vnfs.vnf.vnf import IVnf
26
27 # pylint: disable=too-many-public-methods
28 class Loader(object):
29     """Loader class - main object context holder.
30     """
31     _trafficgen_loader = None
32     _metrics_loader = None
33     _vswitch_loader = None
34     _vnf_loader = None
35     _loadgen_loader = None
36
37     def __init__(self):
38         """Loader ctor - initialization method.
39
40         All data is read from configuration each time Loader instance is
41         created. It is up to creator to maintain object life cycle if this
42         behavior is unwanted.
43         """
44         self._trafficgen_loader = LoaderServant(
45             settings.getValue('TRAFFICGEN_DIR'),
46             settings.getValue('TRAFFICGEN'),
47             ITrafficGenerator)
48
49         self._metrics_loader = LoaderServant(
50             settings.getValue('COLLECTOR_DIR'),
51             settings.getValue('COLLECTOR'),
52             ICollector)
53
54         self._loadgen_loader = LoaderServant(
55             settings.getValue('LOADGEN_DIR'),
56             settings.getValue('LOADGEN'),
57             ILoadGenerator)
58
59         self._vswitch_loader = LoaderServant(
60             settings.getValue('VSWITCH_DIR'),
61             settings.getValue('VSWITCH'),
62             IVSwitch)
63
64         self._vnf_loader = LoaderServant(
65             settings.getValue('VNF_DIR'),
66             settings.getValue('VNF'),
67             IVnf)
68
69         self._pktfwd_loader = LoaderServant(
70             settings.getValue('PKTFWD_DIR'),
71             settings.getValue('PKTFWD'),
72             IPktFwd)
73
74     def get_trafficgen(self):
75         """Returns a new instance configured traffic generator.
76
77         :return: ITrafficGenerator implementation if available, None otherwise.
78         """
79         return self._trafficgen_loader.get_class()()
80
81     def get_trafficgen_class(self):
82         """Returns type of currently configured traffic generator.
83
84         :return: Type of ITrafficGenerator implementation if available.
85             None otherwise.
86         """
87         return self._trafficgen_loader.get_class()
88
89     def get_trafficgens(self):
90         """Returns dictionary of all available traffic generators.
91
92         :return: Dictionary of traffic generators.
93             - key: name of the class which implements ITrafficGenerator,
94             - value: Type of traffic generator which implements
95               ITrafficGenerator.
96         """
97         return self._trafficgen_loader.get_classes()
98
99     def get_trafficgens_printable(self):
100         """Returns all available traffic generators in printable format.
101
102         :return: String containing printable list of traffic generators.
103         """
104         return self._trafficgen_loader.get_classes_printable()
105
106     def get_collector(self):
107         """Returns instance of currently configured collector implementation.
108
109         :return: ICollector implementation if available, None otherwise.
110         """
111         return self._metrics_loader.get_class()()
112
113     def get_collector_class(self):
114         """Returns type of currently configured collector implementation.
115
116         :return: Type of ICollector implementation if available.
117             None otherwise.
118         """
119         return self._metrics_loader.get_class()
120
121     def get_collectors(self):
122         """Returns dictionary of all available collectors.
123
124         :return: Dictionary of collectors.
125             - key: name of the class which implements ICollector,
126             - value: Type of collector which implements ICollector.
127         """
128         return self._metrics_loader.get_classes()
129
130     def get_collectors_printable(self):
131         """Returns all available collectors in printable format.
132
133         :return: String containing printable list of collectors.
134         """
135         return self._metrics_loader.get_classes_printable()
136
137     def get_loadgen_class(self):
138         """Returns type of currently configured loadgen implementation.
139
140         :return: Type of ILoadGenerator implementation if available.
141             None otherwise.
142         """
143         return self._loadgen_loader.get_class()
144
145     def get_loadgens(self):
146         """Returns dictionary of all available loadgens
147
148         :return: Dictionary of loadgens
149             - key: name of the class which implements ILoadGenerator
150             - value: Type of class which implements ILoadGenerator
151         """
152         return self._loadgen_loader.get_classes()
153
154     def get_loadgens_printable(self):
155         """Returns all available loadgens in printable format
156
157         :return: String containing printable list of loadgens
158         """
159         return self._loadgen_loader.get_classes_printable()
160
161     def get_vswitch(self):
162         """Returns instance of currently configured vswitch implementation.
163
164         :return: IVSwitch implementation if available, None otherwise.
165         """
166         return self._vswitch_loader.get_class()()
167
168     def get_vswitch_class(self):
169         """Returns type of currently configured vswitch implementation.
170
171         :return: Type of IVSwitch implementation if available.
172             None otherwise.
173         """
174         return self._vswitch_loader.get_class()
175
176     def get_vswitches(self):
177         """Returns dictionary of all available vswitches.
178
179         :return: Dictionary of vswitches.
180             - key: name of the class which implements IVSwitch,
181             - value: Type of vswitch which implements IVSwitch.
182         """
183         return self._vswitch_loader.get_classes()
184
185     def get_vswitches_printable(self):
186         """Returns all available vswitches in printable format.
187
188         :return: String containing printable list of vswitches.
189         """
190         return self._vswitch_loader.get_classes_printable()
191
192     def get_vnf(self):
193         """Returns instance of currently configured vnf implementation.
194
195         :return: IVnf implementation if available, None otherwise.
196         """
197         return self._vnf_loader.get_class()()
198
199     def get_vnf_class(self):
200         """Returns type of currently configured vnf implementation.
201
202         :return: Type of IVnf implementation if available.
203             None otherwise.
204         """
205         return self._vnf_loader.get_class()
206
207     def get_vnfs(self):
208         """Returns dictionary of all available vnfs.
209
210         :return: Dictionary of vnfs.
211             - key: name of the class which implements IVnf,
212             - value: Type of vnf which implements IVnf.
213         """
214         return self._vnf_loader.get_classes()
215
216     def get_vnfs_printable(self):
217         """Returns all available vnfs in printable format.
218
219         :return: String containing printable list of vnfs.
220         """
221         return self._vnf_loader.get_classes_printable()
222
223     def get_pktfwd(self):
224         """Returns instance of currently configured packet forwarder implementation.
225
226         :return: IPktFwd implementation if available, None otherwise.
227         """
228         return self._pktfwd_loader.get_class()()
229
230     def get_pktfwd_class(self):
231         """Returns type of currently configured packet forwarder implementation.
232
233         :return: Type of IPktFwd implementation if available.
234             None otherwise.
235         """
236         return self._pktfwd_loader.get_class()
237
238     def get_pktfwds(self):
239         """Returns dictionary of all available packet forwarders.
240
241         :return: Dictionary of packet forwarders.
242             - key: name of the class which implements IPktFwd,
243             - value: Type of packet forwarder which implements IPktFwd.
244         """
245         return self._pktfwd_loader.get_classes()
246
247     def get_pktfwds_printable(self):
248         """Returns all available packet forwarders in printable format.
249
250         :return: String containing printable list of packet forwarders.
251         """
252         return self._pktfwd_loader.get_classes_printable()