vnfs: Enable PVP using vhost-user
[vswitchperf.git] / core / loader / loader.py
1 # Copyright 2015 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.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
25 class Loader(object):
26     """Loader class - main object context holder.
27     """
28     _trafficgen_loader = None
29     _metrics_loader = None
30     _vswitch_loader = None
31     _vnf_loader = None
32
33     def __init__(self):
34         """Loader ctor - initialization method.
35
36         All data is read from configuration each time Loader instance is
37         created. It is up to creator to maintain object life cycle if this
38         behavior is unwanted.
39         """
40         self._trafficgen_loader = LoaderServant(
41             settings.getValue('TRAFFICGEN_DIR'),
42             settings.getValue('TRAFFICGEN'),
43             ITrafficGenerator)
44
45         self._metrics_loader = LoaderServant(
46             settings.getValue('COLLECTOR_DIR'),
47             settings.getValue('COLLECTOR'),
48             ICollector)
49
50         self._vswitch_loader = LoaderServant(
51             settings.getValue('VSWITCH_DIR'),
52             settings.getValue('VSWITCH'),
53             IVSwitch)
54
55         self._vnf_loader = LoaderServant(
56             settings.getValue('VNF_DIR'),
57             settings.getValue('VNF'),
58             IVnf)
59
60     def get_trafficgen(self):
61         """Returns a new instance configured traffic generator.
62
63         :return: ITrafficGenerator implementation if available, None otherwise.
64         """
65         return self._trafficgen_loader.get_class()()
66
67     def get_trafficgen_class(self):
68         """Returns type of currently configured traffic generator.
69
70         :return: Type of ITrafficGenerator implementation if available.
71             None otherwise.
72         """
73         return self._trafficgen_loader.get_class()
74
75     def get_trafficgens(self):
76         """Returns dictionary of all available traffic generators.
77
78         :return: Dictionary of traffic generators.
79             - key: name of the class which implements ITrafficGenerator,
80             - value: Type of traffic generator which implements
81               ITrafficGenerator.
82         """
83         return self._trafficgen_loader.get_classes()
84
85     def get_trafficgens_printable(self):
86         """Returns all available traffic generators in printable format.
87
88         :return: String containing printable list of traffic generators.
89         """
90         return self._trafficgen_loader.get_classes_printable()
91
92     def get_collector(self):
93         """Returns instance of currently configured collector implementation.
94
95         :return: ICollector implementation if available, None otherwise.
96         """
97         return self._metrics_loader.get_class()()
98
99     def get_collector_class(self):
100         """Returns type of currently configured collector implementation.
101
102         :return: Type of ICollector implementation if available.
103             None otherwise.
104         """
105         return self._metrics_loader.get_class()
106
107     def get_collectors(self):
108         """Returns dictionary of all available collectors.
109
110         :return: Dictionary of collectors.
111             - key: name of the class which implements ICollector,
112             - value: Type of traffic generator which implements ICollector.
113         """
114         return self._metrics_loader.get_classes()
115
116     def get_collectors_printable(self):
117         """Returns all available collectors in printable format.
118
119         :return: String containing printable list of collectors.
120         """
121         return self._metrics_loader.get_classes_printable()
122
123     def get_vswitch(self):
124         """Returns instance of currently configured vswitch implementation.
125
126         :return: IVSwitch implementation if available, None otherwise.
127         """
128         return self._vswitch_loader.get_class()()
129
130     def get_vswitch_class(self):
131         """Returns type of currently configured vswitch implementation.
132
133         :return: Type of IVSwitch implementation if available.
134             None otherwise.
135         """
136         return self._vswitch_loader.get_class()
137
138     def get_vswitches(self):
139         """Returns dictionary of all available vswitches.
140
141         :return: Dictionary of vswitches.
142             - key: name of the class which implements IVSwitch,
143             - value: Type of traffic generator which implements IVSwitch.
144         """
145         return self._vswitch_loader.get_classes()
146
147     def get_vswitches_printable(self):
148         """Returns all available vswitches in printable format.
149
150         :return: String containing printable list of vswitches.
151         """
152         return self._vswitch_loader.get_classes_printable()
153
154     def get_vnf(self):
155         """Returns instance of currently configured vnf implementation.
156
157         :return: IVnf implementation if available, None otherwise.
158         """
159         return self._vnf_loader.get_class()()
160
161     def get_vnf_class(self):
162         """Returns type of currently configured vnf implementation.
163
164         :return: Type of IVnf implementation if available.
165             None otherwise.
166         """
167         return self._vnf_loader.get_class()
168
169     def get_vnfs(self):
170         """Returns dictionary of all available vnfs.
171
172         :return: Dictionary of vnfs.
173             - key: name of the class which implements IVnf,
174             - value: Type of vnf which implements IVnf.
175         """
176         return self._vnf_loader.get_classes()
177
178     def get_vnfs_printable(self):
179         """Returns all available vnfs in printable format.
180
181         :return: String containing printable list of vnfs.
182         """
183         return self._vnf_loader.get_classes_printable()
184