teststeps: Improvements and bugfixing of teststeps
[vswitchperf.git] / vswitches / vswitch.py
1 # Copyright 2015-2016 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 """Generic interface VSPERF uses for controlling a vSwitch
16 """
17
18 class IVSwitch(object):
19     """Interface class that is implemented by vSwitch-specific classes
20
21     Other methods are called only between start() and stop()
22     """
23     def get_version(self):
24         """Return version of vSwitch and DPDK (if used by vSwitch)
25            This method should be implemented in case, that version
26            of vswitch or DPDK can be read only during vSwitch runtime.
27            Otherwise it can be implemented inside tools/systeminfo.py.
28         """
29         raise NotImplementedError()
30
31     def start(self):
32         """Start the vSwitch
33
34         If vSwitch is split to multiple processes, has kernel modules etc.,
35         this is expected to set them all up in correct sequence
36         """
37         raise NotImplementedError()
38
39     def restart(self):
40         """Retart the vSwitch
41
42         Restart of vSwitch is required for failover testcases.
43         """
44         raise NotImplementedError()
45
46     def stop(self):
47         """Stop the vSwitch
48
49         If vSwitch is split to multiple processes, has kernel modules etc.,
50         this is expected to terminate and clean all of them in correct sequence
51         """
52         raise NotImplementedError()
53
54     def add_switch(self, switch_name, params):
55         """Create a new logical switch with no ports
56
57         :param switch_name: The name of the new logical switch
58         :param params: Optional parameters to configure switch
59
60         :returns: None
61         """
62         raise NotImplementedError()
63
64     def del_switch(self, switch_name):
65         """Destroy the given logical switch
66
67         :param switch_name: The name of the logical switch to be destroyed
68         :returns: None
69         """
70         raise NotImplementedError()
71
72     def add_phy_port(self, switch_name):
73         """Create a new port to the logical switch that is attached to a
74         physical port
75
76         :param switch_name: The switch where the port is attached to
77         :returns: (port name, OpenFlow port number)
78         """
79         raise NotImplementedError()
80
81     def add_vport(self, switch_name):
82         """Create a new port to the logical switch for VM connections
83
84         :param switch_name: The switch where the port is attached to
85         :returns: (port name, OpenFlow port number)
86         """
87         raise NotImplementedError()
88
89     def add_tunnel_port(self, switch_name, remote_ip, tunnel_type, params=None):
90         """Create a new port to the logical switch for tunneling
91
92         :param switch_name: The switch where the port is attached to
93         :returns: (port name, OpenFlow port number)
94         """
95         raise NotImplementedError()
96
97     def get_ports(self, switch_name):
98         """Return a list of tuples describing the ports of the logical switch
99
100         :param switch_name: The switch whose ports to return
101         :returns: [(port name, OpenFlow port number), ...]
102         """
103         raise NotImplementedError()
104
105     def del_port(self, switch_name, port_name):
106         """Delete the port from the logical switch
107
108         The port can be either physical or virtual
109
110         :param switch_name: The switch on which to operate
111         :param port_name: The port to delete
112         """
113         raise NotImplementedError()
114
115     def add_flow(self, switch_name, flow, cache='off'):
116         """Add a flow rule to the logical switch
117
118         :param switch_name: The switch on which to operate
119         :param flow: Flow description as a dictionary
120         :param cache: Optional. Specifies if flow should be inserted
121             to the switch or cached to increase performance during manipulation
122             with large number of flows.
123             Values:
124                 'off'   - cache is off and flow is inserted directly to the switch
125                 'on'    - cache is on and flow is inserted into the cache
126                 'flush' - cache content will be inserted into the switch
127
128         Example flow dictionary:
129             flow = {
130                 'in_port': '1',
131                 'idle_timeout': '0',
132                 'actions': ['output:3']
133             }
134         """
135         raise NotImplementedError()
136
137     def del_flow(self, switch_name, flow=None):
138         """Delete the flow rule from the logical switch
139
140         :param switch_name: The switch on which to operate
141         :param flow: Flow description as a dictionary
142
143         For flow dictionary description, see add_flow
144         For flow==None, all flows are deleted
145         """
146         raise NotImplementedError()
147
148     def add_connection(self, switch_name, port1, port2, bidir=False):
149         """Creates connection between given ports.
150
151         :param switch_name: switch on which to operate
152         :param port1: port to be used in connection
153         :param port2: port to be used in connection
154         :param bidir: switch between uni and bidirectional traffic
155
156         :raises: RuntimeError
157         """
158         raise NotImplementedError()
159
160     def del_connection(self, switch_name, port1, port2, bidir=False):
161         """Remove connection between two interfaces.
162
163         :param switch_name: switch on which to operate
164         :param port1: port to be used in connection
165         :param port2: port to be used in connection
166         :param bidir: switch between uni and bidirectional traffic
167
168         :raises: RuntimeError
169         """
170         raise NotImplementedError()
171
172     def dump_connections(self, switch_name):
173         """Dump connections between interfaces.
174
175         :param switch_name: switch on which to operate
176
177         :raises: RuntimeError
178         """
179         raise NotImplementedError()
180
181     def dump_flows(self, switch_name):
182         """Dump flows from the logical switch
183
184         :param switch_name: The switch on which to operate
185         """
186         raise NotImplementedError()
187
188     def add_route(self, switch_name, network, destination):
189         """Add a route for tunneling routing table
190
191         :param switch_name: The switch on which to operate
192         :param network: Target destination network
193         :param destination: Gateway IP
194         """
195         raise NotImplementedError()
196
197     def set_tunnel_arp(self, ip_addr, mac_addr, switch_name):
198         """Add arp entry for tunneling
199
200         :param ip_addr: IP of bridge
201         :param mac_addr: MAC address of the bridge
202         :param switch_name: Name of the bridge
203         """
204         raise NotImplementedError()