connections: Introduction of generic API
[vswitchperf.git] / vswitches / vswitch.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
15 """Generic interface VSPERF uses for controlling a vSwitch
16 """
17 import logging
18
19 class IVSwitch(object):
20     """Interface class that is implemented by vSwitch-specific classes
21
22     Other methods are called only between start() and stop()
23     """
24     def __init__(self):
25         """Initialization of vswitch class
26         """
27         self._timeout = 30
28         self._switches = {}
29         self._logger = logging.getLogger(__name__)
30         self._cmd = []
31         self._vswitch_args = []
32         self._stamp = None
33
34     def get_version(self):
35         """Return version of vSwitch and DPDK (if used by vSwitch)
36            This method should be implemented in case, that version
37            of vswitch or DPDK can be read only during vSwitch runtime.
38            Otherwise it can be implemented inside tools/systeminfo.py.
39         """
40         raise NotImplementedError()
41
42     def start(self):
43         """Start the vSwitch
44
45         If vSwitch is split to multiple processes, has kernel modules etc.,
46         this is expected to set them all up in correct sequence
47         """
48         raise NotImplementedError()
49
50     def restart(self):
51         """Retart the vSwitch
52
53         Restart of vSwitch is required for failover testcases.
54         """
55         raise NotImplementedError()
56
57     def stop(self):
58         """Stop the vSwitch
59
60         If vSwitch is split to multiple processes, has kernel modules etc.,
61         this is expected to terminate and clean all of them in correct sequence
62         """
63         raise NotImplementedError()
64
65     def add_switch(self, switch_name, params):
66         """Create a new logical switch with no ports
67
68         :param switch_name: The name of the new logical switch
69         :param params: Optional parameters to configure switch
70
71         :returns: None
72         """
73         raise NotImplementedError()
74
75     def del_switch(self, switch_name):
76         """Destroy the given logical switch
77
78         :param switch_name: The name of the logical switch to be destroyed
79         :returns: None
80         """
81         raise NotImplementedError()
82
83     def add_phy_port(self, switch_name):
84         """Create a new port to the logical switch that is attached to a
85         physical port
86
87         :param switch_name: The switch where the port is attached to
88         :returns: (port name, OpenFlow port number)
89         """
90         raise NotImplementedError()
91
92     def add_vport(self, switch_name):
93         """Create a new port to the logical switch for VM connections
94
95         :param switch_name: The switch where the port is attached to
96         :returns: (port name, OpenFlow port number)
97         """
98         raise NotImplementedError()
99
100     def add_tunnel_port(self, switch_name, remote_ip, tunnel_type, params=None):
101         """Create a new port to the logical switch for tunneling
102
103         :param switch_name: The switch where the port is attached to
104         :returns: (port name, OpenFlow port number)
105         """
106         raise NotImplementedError()
107
108     def get_ports(self, switch_name):
109         """Return a list of tuples describing the ports of the logical switch
110
111         :param switch_name: The switch whose ports to return
112         :returns: [(port name, OpenFlow port number), ...]
113         """
114         raise NotImplementedError()
115
116     def del_port(self, switch_name, port_name):
117         """Delete the port from the logical switch
118
119         The port can be either physical or virtual
120
121         :param switch_name: The switch on which to operate
122         :param port_name: The port to delete
123         """
124         raise NotImplementedError()
125
126     def add_connection(self, switch_name, port1, port2, traffic=None):
127         """Creates connection between given ports.
128
129         :param switch_name: switch on which to operate
130         :param port1: port to be used in connection
131         :param port2: port to be used in connection
132
133         :raises: RuntimeError
134         """
135         raise NotImplementedError()
136
137     def del_connection(self, switch_name, port1=None, port2=None):
138         """Remove connection between two interfaces.
139
140         :param switch_name: switch on which to operate
141         :param port1: port to be used in connection
142         :param port2: port to be used in connection
143
144         :raises: RuntimeError
145         """
146         raise NotImplementedError()
147
148     def dump_connections(self, switch_name):
149         """Dump connections between interfaces.
150
151         :param switch_name: switch on which to operate
152
153         :raises: RuntimeError
154         """
155         raise NotImplementedError()
156
157     def add_route(self, switch_name, network, destination):
158         """Add a route for tunneling routing table
159
160         :param switch_name: The switch on which to operate
161         :param network: Target destination network
162         :param destination: Gateway IP
163         """
164         raise NotImplementedError()
165
166     def set_tunnel_arp(self, ip_addr, mac_addr, switch_name):
167         """Add arp entry for tunneling
168
169         :param ip_addr: IP of bridge
170         :param mac_addr: MAC address of the bridge
171         :param switch_name: Name of the bridge
172         """
173         raise NotImplementedError()