1 # Copyright 2015-2017 Intel Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 """Loader module definition.
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
27 # pylint: disable=too-many-public-methods
29 """Loader class - main object context holder.
31 _trafficgen_loader = None
32 _metrics_loader = None
33 _vswitch_loader = None
35 _loadgen_loader = None
38 """Loader ctor - initialization method.
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
44 self._trafficgen_loader = LoaderServant(
45 settings.getValue('TRAFFICGEN_DIR'),
46 settings.getValue('TRAFFICGEN'),
49 self._metrics_loader = LoaderServant(
50 settings.getValue('COLLECTOR_DIR'),
51 settings.getValue('COLLECTOR'),
54 self._loadgen_loader = LoaderServant(
55 settings.getValue('LOADGEN_DIR'),
56 settings.getValue('LOADGEN'),
59 self._vswitch_loader = LoaderServant(
60 settings.getValue('VSWITCH_DIR'),
61 settings.getValue('VSWITCH'),
64 self._vnf_loader = LoaderServant(
65 settings.getValue('VNF_DIR'),
66 settings.getValue('VNF'),
69 self._pktfwd_loader = LoaderServant(
70 settings.getValue('PKTFWD_DIR'),
71 settings.getValue('PKTFWD'),
74 def get_trafficgen(self):
75 """Returns a new instance configured traffic generator.
77 :return: ITrafficGenerator implementation if available, None otherwise.
79 return self._trafficgen_loader.get_class()()
81 def get_trafficgen_class(self):
82 """Returns type of currently configured traffic generator.
84 :return: Type of ITrafficGenerator implementation if available.
87 return self._trafficgen_loader.get_class()
89 def get_trafficgens(self):
90 """Returns dictionary of all available traffic generators.
92 :return: Dictionary of traffic generators.
93 - key: name of the class which implements ITrafficGenerator,
94 - value: Type of traffic generator which implements
97 return self._trafficgen_loader.get_classes()
99 def get_trafficgens_printable(self):
100 """Returns all available traffic generators in printable format.
102 :return: String containing printable list of traffic generators.
104 return self._trafficgen_loader.get_classes_printable()
106 def get_collector(self):
107 """Returns instance of currently configured collector implementation.
109 :return: ICollector implementation if available, None otherwise.
111 return self._metrics_loader.get_class()()
113 def get_collector_class(self):
114 """Returns type of currently configured collector implementation.
116 :return: Type of ICollector implementation if available.
119 return self._metrics_loader.get_class()
121 def get_collectors(self):
122 """Returns dictionary of all available collectors.
124 :return: Dictionary of collectors.
125 - key: name of the class which implements ICollector,
126 - value: Type of collector which implements ICollector.
128 return self._metrics_loader.get_classes()
130 def get_collectors_printable(self):
131 """Returns all available collectors in printable format.
133 :return: String containing printable list of collectors.
135 return self._metrics_loader.get_classes_printable()
137 def get_loadgen_class(self):
138 """Returns type of currently configured loadgen implementation.
140 :return: Type of ILoadGenerator implementation if available.
143 return self._loadgen_loader.get_class()
145 def get_loadgens(self):
146 """Returns dictionary of all available loadgens
148 :return: Dictionary of loadgens
149 - key: name of the class which implements ILoadGenerator
150 - value: Type of class which implements ILoadGenerator
152 return self._loadgen_loader.get_classes()
154 def get_loadgens_printable(self):
155 """Returns all available loadgens in printable format
157 :return: String containing printable list of loadgens
159 return self._loadgen_loader.get_classes_printable()
161 def get_vswitch(self):
162 """Returns instance of currently configured vswitch implementation.
164 :return: IVSwitch implementation if available, None otherwise.
166 return self._vswitch_loader.get_class()()
168 def get_vswitch_class(self):
169 """Returns type of currently configured vswitch implementation.
171 :return: Type of IVSwitch implementation if available.
174 return self._vswitch_loader.get_class()
176 def get_vswitches(self):
177 """Returns dictionary of all available vswitches.
179 :return: Dictionary of vswitches.
180 - key: name of the class which implements IVSwitch,
181 - value: Type of vswitch which implements IVSwitch.
183 return self._vswitch_loader.get_classes()
185 def get_vswitches_printable(self):
186 """Returns all available vswitches in printable format.
188 :return: String containing printable list of vswitches.
190 return self._vswitch_loader.get_classes_printable()
193 """Returns instance of currently configured vnf implementation.
195 :return: IVnf implementation if available, None otherwise.
197 return self._vnf_loader.get_class()()
199 def get_vnf_class(self):
200 """Returns type of currently configured vnf implementation.
202 :return: Type of IVnf implementation if available.
205 return self._vnf_loader.get_class()
208 """Returns dictionary of all available vnfs.
210 :return: Dictionary of vnfs.
211 - key: name of the class which implements IVnf,
212 - value: Type of vnf which implements IVnf.
214 return self._vnf_loader.get_classes()
216 def get_vnfs_printable(self):
217 """Returns all available vnfs in printable format.
219 :return: String containing printable list of vnfs.
221 return self._vnf_loader.get_classes_printable()
223 def get_pktfwd(self):
224 """Returns instance of currently configured packet forwarder implementation.
226 :return: IPktFwd implementation if available, None otherwise.
228 return self._pktfwd_loader.get_class()()
230 def get_pktfwd_class(self):
231 """Returns type of currently configured packet forwarder implementation.
233 :return: Type of IPktFwd implementation if available.
236 return self._pktfwd_loader.get_class()
238 def get_pktfwds(self):
239 """Returns dictionary of all available packet forwarders.
241 :return: Dictionary of packet forwarders.
242 - key: name of the class which implements IPktFwd,
243 - value: Type of packet forwarder which implements IPktFwd.
245 return self._pktfwd_loader.get_classes()
247 def get_pktfwds_printable(self):
248 """Returns all available packet forwarders in printable format.
250 :return: String containing printable list of packet forwarders.
252 return self._pktfwd_loader.get_classes_printable()