connections: Introduction of generic API
[vswitchperf.git] / core / vswitch_controller.py
1 # Copyright 2015-2018 Intel Corporation., Tieto
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 """Interface for deployment specific vSwitch controllers
15 """
16 import logging
17
18 class IVswitchController(object):
19     """Interface class for a vSwitch controller object
20
21     This interface is used to setup and control a vSwitch provider for a
22     particular deployment scenario.
23     """
24     def __init__(self, deployment, vswitch_class, traffic):
25         """Initializes up the generic prerequisites for deployment scenario.
26
27         :deployment: the deployment scenario to configure
28         :vswitch_class: the vSwitch class to be used.
29         :traffic: dictionary with detailed traffic definition
30         """
31         self._logger = logging.getLogger(__name__)
32         self._vswitch_class = vswitch_class
33         self._vswitch = vswitch_class()
34         self._deployment_scenario = deployment
35         self._logger.debug('Creation using %s', str(self._vswitch_class))
36         self._traffic = traffic.copy()
37         self._bridge = None
38
39     def setup(self):
40         """Sets up the switch for the particular deployment scenario
41         """
42         raise NotImplementedError(
43             "The VswitchController does not implement the \"setup\" function.")
44
45     def stop(self):
46         """Tears down the switch created in setup()
47         """
48         raise NotImplementedError(
49             "The VswitchController does not implement the \"stop\" function.")
50
51     def __enter__(self):
52         """Sets up the switch for the particular deployment scenario
53         """
54         self.setup()
55
56     def __exit__(self, type_, value, traceback):
57         """Tears down the switch created in setup()
58         """
59         self.stop()
60
61     def get_vswitch(self):
62         """Get the controlled vSwitch
63
64         :return: The controlled IVswitch
65         """
66         return self._vswitch
67
68     def get_ports_info(self):
69         """Returns a dictionary describing all ports on the vSwitch.
70
71         See IVswitch for dictionary structure details
72         """
73         raise NotImplementedError(
74             "The VswitchController does not implement the \"get_ports_info\" "
75             "function.")
76
77     def dump_vswitch_connections(self):
78         """ Dumps connections from vswitch
79         """
80         raise NotImplementedError(
81             "The VswitchController does not implement the "
82             "\"dump_vswitch_connections\" function.")