35a8c1b9ca32f8d98d671e904f2fbf6f56a1547a
[nfvbench.git] / nfvbench / factory.py
1 #!/usr/bin/env python
2 # Copyright 2017 Cisco Systems, Inc.  All rights reserved.
3 #
4 #    Licensed under the Apache License, Version 2.0 (the "License"); you may
5 #    not use this file except in compliance with the License. You may obtain
6 #    a copy of the License at
7 #
8 #         http://www.apache.org/licenses/LICENSE-2.0
9 #
10 #    Unless required by applicable law or agreed to in writing, software
11 #    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 #    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 #    License for the specific language governing permissions and limitations
14 #    under the License.
15 #
16
17 from chain_clients import EXTStageClient
18 from chain_clients import PVPStageClient
19 from chain_clients import PVVPStageClient
20 from chain_managers import EXTStatsManager
21 from chain_managers import PVPStatsManager
22 from chain_managers import PVVPStatsManager
23 import chain_workers as workers
24 from config_plugin import ConfigPlugin
25 from specs import ChainType
26 import tor_client
27
28
29 class BasicFactory(object):
30
31     chain_classes = [ChainType.EXT, ChainType.PVP, ChainType.PVVP]
32
33     chain_stats_classes = {
34         ChainType.EXT: EXTStatsManager,
35         ChainType.PVP: PVPStatsManager,
36         ChainType.PVVP: PVVPStatsManager,
37     }
38
39     stage_clients_classes = {
40         ChainType.EXT: EXTStageClient,
41         ChainType.PVP: PVPStageClient,
42         ChainType.PVVP: PVVPStageClient,
43     }
44
45     def get_stats_class(self, service_chain):
46         CLASS = self.chain_stats_classes.get(service_chain, None)
47         if CLASS is None:
48             raise Exception("Service chain '{}' not supported.".format(service_chain))
49
50         return CLASS
51
52     def get_stage_class(self, service_chain):
53         CLASS = self.stage_clients_classes.get(service_chain, None)
54         if CLASS is None:
55             raise Exception("VM Client for chain '{}' not supported.".format(service_chain))
56
57         return CLASS
58
59     def get_chain_worker(self, encaps, service_chain):
60         return workers.BasicWorker
61
62     def get_tor_class(self, tor_type, no_tor_access):
63         if no_tor_access or not tor_type:
64             # if no TOR access is required, use basic no-op client
65             tor_type = 'BasicTORClient'
66
67         return getattr(tor_client, tor_type)
68
69     def get_config_plugin_class(self):
70         return ConfigPlugin