1 # Copyright 2015 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.pkt_gen.trafficgen import ITrafficGenerator
21 from tools.collectors.collector import ICollector
22 from vswitches.vswitch import IVSwitch
23 from vnfs.vnf.vnf import IVnf
24 from tools.pkt_fwd.pkt_fwd import IPktFwd
27 """Loader class - main object context holder.
29 _trafficgen_loader = None
30 _metrics_loader = None
31 _vswitch_loader = None
35 """Loader ctor - initialization method.
37 All data is read from configuration each time Loader instance is
38 created. It is up to creator to maintain object life cycle if this
41 self._trafficgen_loader = LoaderServant(
42 settings.getValue('TRAFFICGEN_DIR'),
43 settings.getValue('TRAFFICGEN'),
46 self._metrics_loader = LoaderServant(
47 settings.getValue('COLLECTOR_DIR'),
48 settings.getValue('COLLECTOR'),
51 self._vswitch_loader = LoaderServant(
52 settings.getValue('VSWITCH_DIR'),
53 settings.getValue('VSWITCH'),
56 self._vnf_loader = LoaderServant(
57 settings.getValue('VNF_DIR'),
58 settings.getValue('VNF'),
61 self._pktfwd_loader = LoaderServant(
62 settings.getValue('PKTFWD_DIR'),
63 settings.getValue('PKTFWD'),
66 def get_trafficgen(self):
67 """Returns a new instance configured traffic generator.
69 :return: ITrafficGenerator implementation if available, None otherwise.
71 return self._trafficgen_loader.get_class()()
73 def get_trafficgen_class(self):
74 """Returns type of currently configured traffic generator.
76 :return: Type of ITrafficGenerator implementation if available.
79 return self._trafficgen_loader.get_class()
81 def get_trafficgens(self):
82 """Returns dictionary of all available traffic generators.
84 :return: Dictionary of traffic generators.
85 - key: name of the class which implements ITrafficGenerator,
86 - value: Type of traffic generator which implements
89 return self._trafficgen_loader.get_classes()
91 def get_trafficgens_printable(self):
92 """Returns all available traffic generators in printable format.
94 :return: String containing printable list of traffic generators.
96 return self._trafficgen_loader.get_classes_printable()
98 def get_collector(self):
99 """Returns instance of currently configured collector implementation.
101 :return: ICollector implementation if available, None otherwise.
103 return self._metrics_loader.get_class()()
105 def get_collector_class(self):
106 """Returns type of currently configured collector implementation.
108 :return: Type of ICollector implementation if available.
111 return self._metrics_loader.get_class()
113 def get_collectors(self):
114 """Returns dictionary of all available collectors.
116 :return: Dictionary of collectors.
117 - key: name of the class which implements ICollector,
118 - value: Type of collector which implements ICollector.
120 return self._metrics_loader.get_classes()
122 def get_collectors_printable(self):
123 """Returns all available collectors in printable format.
125 :return: String containing printable list of collectors.
127 return self._metrics_loader.get_classes_printable()
129 def get_vswitch(self):
130 """Returns instance of currently configured vswitch implementation.
132 :return: IVSwitch implementation if available, None otherwise.
134 return self._vswitch_loader.get_class()()
136 def get_vswitch_class(self):
137 """Returns type of currently configured vswitch implementation.
139 :return: Type of IVSwitch implementation if available.
142 return self._vswitch_loader.get_class()
144 def get_vswitches(self):
145 """Returns dictionary of all available vswitches.
147 :return: Dictionary of vswitches.
148 - key: name of the class which implements IVSwitch,
149 - value: Type of vswitch which implements IVSwitch.
151 return self._vswitch_loader.get_classes()
153 def get_vswitches_printable(self):
154 """Returns all available vswitches in printable format.
156 :return: String containing printable list of vswitches.
158 return self._vswitch_loader.get_classes_printable()
161 """Returns instance of currently configured vnf implementation.
163 :return: IVnf implementation if available, None otherwise.
165 return self._vnf_loader.get_class()()
167 def get_vnf_class(self):
168 """Returns type of currently configured vnf implementation.
170 :return: Type of IVnf implementation if available.
173 return self._vnf_loader.get_class()
176 """Returns dictionary of all available vnfs.
178 :return: Dictionary of vnfs.
179 - key: name of the class which implements IVnf,
180 - value: Type of vnf which implements IVnf.
182 return self._vnf_loader.get_classes()
184 def get_vnfs_printable(self):
185 """Returns all available vnfs in printable format.
187 :return: String containing printable list of vnfs.
189 return self._vnf_loader.get_classes_printable()
191 def get_pktfwd(self):
192 """Returns instance of currently configured packet forwarder implementation.
194 :return: IPktFwd implementation if available, None otherwise.
196 return self._pktfwd_loader.get_class()()
198 def get_pktfwd_class(self):
199 """Returns type of currently configured packet forwarder implementation.
201 :return: Type of IPktFwd implementation if available.
204 return self._pktfwd_loader.get_class()
206 def get_pktfwds(self):
207 """Returns dictionary of all available packet forwarders.
209 :return: Dictionary of packet forwarders.
210 - key: name of the class which implements IPktFwd,
211 - value: Type of packet forwarder which implements IPktFwd.
213 return self._pktfwd_loader.get_classes()
215 def get_pktfwds_printable(self):
216 """Returns all available packet forwarders in printable format.
218 :return: String containing printable list of packet forwarders.
220 return self._pktfwd_loader.get_classes_printable()