Merge "test_spec: Clarify LTD.Throughput.RFC2544.PacketLossRatioFrameModification"
[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
24 class Loader(object):
25     """Loader class - main object context holder.
26     """
27     _trafficgen_loader = None
28     _metrics_loader = None
29     _vswitch_loader = None
30
31     def __init__(self):
32         """Loader ctor - initialization method.
33
34         All data is read from configuration each time Loader instance is
35         created. It is up to creator to maintain object life cycle if this
36         behavior is unwanted.
37         """
38         self._trafficgen_loader = LoaderServant(
39             settings.getValue('TRAFFICGEN_DIR'),
40             settings.getValue('TRAFFICGEN'),
41             ITrafficGenerator)
42
43         self._metrics_loader = LoaderServant(
44             settings.getValue('COLLECTOR_DIR'),
45             settings.getValue('COLLECTOR'),
46             ICollector)
47
48         self._vswitch_loader = LoaderServant(
49             settings.getValue('VSWITCH_DIR'),
50             settings.getValue('VSWITCH'),
51             IVSwitch)
52
53     def get_trafficgen(self):
54         """Returns a new instance configured traffic generator.
55
56         :return: ITrafficGenerator implementation if available, None otherwise.
57         """
58         return self._trafficgen_loader.get_class()()
59
60     def get_trafficgen_class(self):
61         """Returns type of currently configured traffic generator.
62
63         :return: Type of ITrafficGenerator implementation if available.
64             None otherwise.
65         """
66         return self._trafficgen_loader.get_class()
67
68     def get_trafficgens(self):
69         """Returns dictionary of all available traffic generators.
70
71         :return: Dictionary of traffic generators.
72             - key: name of the class which implements ITrafficGenerator,
73             - value: Type of traffic generator which implements
74               ITrafficGenerator.
75         """
76         return self._trafficgen_loader.get_classes()
77
78     def get_trafficgens_printable(self):
79         """Returns all available traffic generators in printable format.
80
81         :return: String containing printable list of traffic generators.
82         """
83         return self._trafficgen_loader.get_classes_printable()
84
85     def get_collector(self):
86         """Returns instance of currently configured collector implementation.
87
88         :return: ICollector implementation if available, None otherwise.
89         """
90         return self._metrics_loader.get_class()()
91
92     def get_collector_class(self):
93         """Returns type of currently configured collector implementation.
94
95         :return: Type of ICollector implementation if available.
96             None otherwise.
97         """
98         return self._metrics_loader.get_class()
99
100     def get_collectors(self):
101         """Returns dictionary of all available collectors.
102
103         :return: Dictionary of collectors.
104             - key: name of the class which implements ICollector,
105             - value: Type of traffic generator which implements ICollector.
106         """
107         return self._metrics_loader.get_classes()
108
109     def get_collectors_printable(self):
110         """Returns all available collectors in printable format.
111
112         :return: String containing printable list of collectors.
113         """
114         return self._metrics_loader.get_classes_printable()
115
116     def get_vswitch(self):
117         """Returns instance of currently configured vswitch implementation.
118
119         :return: IVSwitch implementation if available, None otherwise.
120         """
121         return self._vswitch_loader.get_class()()
122
123     def get_vswitch_class(self):
124         """Returns type of currently configured vswitch implementation.
125
126         :return: Type of IVSwitch implementation if available.
127             None otherwise.
128         """
129         return self._vswitch_loader.get_class()
130
131     def get_vswitches(self):
132         """Returns dictionary of all available vswitches.
133
134         :return: Dictionary of vswitches.
135             - key: name of the class which implements IVSwitch,
136             - value: Type of traffic generator which implements IVSwitch.
137         """
138         return self._vswitch_loader.get_classes()
139
140     def get_vswitches_printable(self):
141         """Returns all available vswitches in printable format.
142
143         :return: String containing printable list of vswitches.
144         """
145         return self._vswitch_loader.get_classes_printable()
146
147     def get_vnf_class(self):
148         """Returns a new instance of the configured VNF
149
150         Currently always returns None
151         """
152         #TODO: Load the VNF class
153         return None