1 # Copyright 2015-2016 Intel Corporation.
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
7 # http://www.apache.org/licenses/LICENSE-2.0
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.
15 """Generic interface VSPERF uses for controlling a vSwitch
18 class IVSwitch(object):
19 """Interface class that is implemented by vSwitch-specific classes
21 Other methods are called only between start() and stop()
26 If vSwitch is split to multiple processes, has kernel modules etc.,
27 this is expected to set them all up in correct sequence
29 raise NotImplementedError()
34 If vSwitch is split to multiple processes, has kernel modules etc.,
35 this is expected to terminate and clean all of them in correct sequence
37 raise NotImplementedError()
39 def add_switch(self, switch_name, params):
40 """Create a new logical switch with no ports
42 :param switch_name: The name of the new logical switch
43 :param params: Optional parameters to configure switch
47 raise NotImplementedError()
49 def del_switch(self, switch_name):
50 """Destroy the given logical switch
52 :param switch_name: The name of the logical switch to be destroyed
55 raise NotImplementedError()
57 def add_phy_port(self, switch_name):
58 """Create a new port to the logical switch that is attached to a
61 :param switch_name: The switch where the port is attached to
62 :returns: (port name, OpenFlow port number)
64 raise NotImplementedError()
66 def add_vport(self, switch_name):
67 """Create a new port to the logical switch for VM connections
69 :param switch_name: The switch where the port is attached to
70 :returns: (port name, OpenFlow port number)
72 raise NotImplementedError()
74 def add_tunnel_port(self, switch_name, remote_ip, tunnel_type, params=None):
75 """Create a new port to the logical switch for tunneling
77 :param switch_name: The switch where the port is attached to
78 :returns: (port name, OpenFlow port number)
80 raise NotImplementedError()
82 def get_ports(self, switch_name):
83 """Return a list of tuples describing the ports of the logical switch
85 :param switch_name: The switch whose ports to return
86 :returns: [(port name, OpenFlow port number), ...]
88 raise NotImplementedError()
90 def del_port(self, switch_name, port_name):
91 """Delete the port from the logical switch
93 The port can be either physical or virtual
95 :param switch_name: The switch on which to operate
96 :param port_name: The port to delete
98 raise NotImplementedError()
100 def add_flow(self, switch_name, flow, cache='off'):
101 """Add a flow rule to the logical switch
103 :param switch_name: The switch on which to operate
104 :param flow: Flow description as a dictionary
105 :param cache: Optional. Specifies if flow should be inserted
106 to the switch or cached to increase performance during manipulation
107 with large number of flows.
109 'off' - cache is off and flow is inserted directly to the switch
110 'on' - cache is on and flow is inserted into the cache
111 'flush' - cache content will be inserted into the switch
113 Example flow dictionary:
117 'actions': ['output:3']
120 raise NotImplementedError()
122 def del_flow(self, switch_name, flow=None):
123 """Delete the flow rule from the logical switch
125 :param switch_name: The switch on which to operate
126 :param flow: Flow description as a dictionary
128 For flow dictionary description, see add_flow
129 For flow==None, all flows are deleted
131 raise NotImplementedError()
133 def add_connection(self, switch_name, port1, port2, bidir=False):
134 """Creates connection between given ports.
136 :param switch_name: switch on which to operate
137 :param port1: port to be used in connection
138 :param port2: port to be used in connection
139 :param bidir: switch between uni and bidirectional traffic
141 :raises: RuntimeError
143 raise NotImplementedError()
145 def del_connection(self, switch_name, port1, port2, bidir=False):
146 """Remove connection between two interfaces.
148 :param switch_name: switch on which to operate
149 :param port1: port to be used in connection
150 :param port2: port to be used in connection
151 :param bidir: switch between uni and bidirectional traffic
153 :raises: RuntimeError
155 raise NotImplementedError()
157 def dump_connections(self, switch_name):
158 """Dump connections between interfaces.
160 :param switch_name: switch on which to operate
162 :raises: RuntimeError
164 raise NotImplementedError()
166 def dump_flows(self, switch_name):
167 """Dump flows from the logical switch
169 :param switch_name: The switch on which to operate
171 raise NotImplementedError()
173 def add_route(self, switch_name, network, destination):
174 """Add a route for tunneling routing table
176 :param switch_name: The switch on which to operate
177 :param network: Target destination network
178 :param destination: Gateway IP
180 raise NotImplementedError()
182 def set_tunnel_arp(self, ip_addr, mac_addr, switch_name):
183 """Add arp entry for tunneling
185 :param ip_addr: IP of bridge
186 :param mac_addr: MAC address of the bridge
187 :param switch_name: Name of the bridge
189 raise NotImplementedError()