1461036da250fe756f6bbe10148ba1d7b090c7c8
[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     chain_classes = [ChainType.EXT, ChainType.PVP, ChainType.PVVP]
31
32     chain_stats_classes = {
33         ChainType.EXT: EXTStatsManager,
34         ChainType.PVP: PVPStatsManager,
35         ChainType.PVVP: PVVPStatsManager,
36     }
37
38     stage_clients_classes = {
39         ChainType.EXT: EXTStageClient,
40         ChainType.PVP: PVPStageClient,
41         ChainType.PVVP: PVVPStageClient,
42     }
43
44     def get_stats_class(self, service_chain):
45         CLASS = self.chain_stats_classes.get(service_chain, None)
46         if CLASS is None:
47             raise Exception("Service chain '{}' not supported.".format(service_chain))
48
49         return CLASS
50
51     def get_stage_class(self, service_chain):
52         CLASS = self.stage_clients_classes.get(service_chain, None)
53         if CLASS is None:
54             raise Exception("VM Client for chain '{}' not supported.".format(service_chain))
55
56         return CLASS
57
58     def get_chain_worker(self, encaps, service_chain):
59         return workers.BasicWorker
60
61     def get_tor_class(self, tor_type, no_tor_access):
62         if no_tor_access or not tor_type:
63             # if no TOR access is required, use basic no-op client
64             tor_type = 'BasicTORClient'
65
66         return getattr(tor_client, tor_type)
67
68     def get_config_plugin_class(self):
69         return ConfigPlugin