trex: fix Trex makefile
[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 stop(self):
40         """Stop the vSwitch
41
42         If vSwitch is split to multiple processes, has kernel modules etc.,
43         this is expected to terminate and clean all of them in correct sequence
44         """
45         raise NotImplementedError()
46
47     def add_switch(self, switch_name, params):
48         """Create a new logical switch with no ports
49
50         :param switch_name: The name of the new logical switch
51         :param params: Optional parameters to configure switch
52
53         :returns: None
54         """
55         raise NotImplementedError()
56
57     def del_switch(self, switch_name):
58         """Destroy the given logical switch
59
60         :param switch_name: The name of the logical switch to be destroyed
61         :returns: None
62         """
63         raise NotImplementedError()
64
65     def add_phy_port(self, switch_name):
66         """Create a new port to the logical switch that is attached to a
67         physical port
68
69         :param switch_name: The switch where the port is attached to
70         :returns: (port name, OpenFlow port number)
71         """
72         raise NotImplementedError()
73
74     def add_vport(self, switch_name):
75         """Create a new port to the logical switch for VM connections
76
77         :param switch_name: The switch where the port is attached to
78         :returns: (port name, OpenFlow port number)
79         """
80         raise NotImplementedError()
81
82     def add_tunnel_port(self, switch_name, remote_ip, tunnel_type, params=None):
83         """Create a new port to the logical switch for tunneling
84
85         :param switch_name: The switch where the port is attached to
86         :returns: (port name, OpenFlow port number)
87         """
88         raise NotImplementedError()
89
90     def get_ports(self, switch_name):
91         """Return a list of tuples describing the ports of the logical switch
92
93         :param switch_name: The switch whose ports to return
94         :returns: [(port name, OpenFlow port number), ...]
95         """
96         raise NotImplementedError()
97
98     def del_port(self, switch_name, port_name):
99         """Delete the port from the logical switch
100
101         The port can be either physical or virtual
102
103         :param switch_name: The switch on which to operate
104         :param port_name: The port to delete
105         """
106         raise NotImplementedError()
107
108     def add_flow(self, switch_name, flow, cache='off'):
109         """Add a flow rule to the logical switch
110
111         :param switch_name: The switch on which to operate
112         :param flow: Flow description as a dictionary
113         :param cache: Optional. Specifies if flow should be inserted
114             to the switch or cached to increase performance during manipulation
115             with large number of flows.
116             Values:
117                 'off'   - cache is off and flow is inserted directly to the switch
118                 'on'    - cache is on and flow is inserted into the cache
119                 'flush' - cache content will be inserted into the switch
120
121         Example flow dictionary:
122             flow = {
123                 'in_port': '1',
124                 'idle_timeout': '0',
125                 'actions': ['output:3']
126             }
127         """
128         raise NotImplementedError()
129
130     def del_flow(self, switch_name, flow=None):
131         """Delete the flow rule from the logical switch
132
133         :param switch_name: The switch on which to operate
134         :param flow: Flow description as a dictionary
135
136         For flow dictionary description, see add_flow
137         For flow==None, all flows are deleted
138         """
139         raise NotImplementedError()
140
141     def add_connection(self, switch_name, port1, port2, bidir=False):
142         """Creates connection between given ports.
143
144         :param switch_name: switch on which to operate
145         :param port1: port to be used in connection
146         :param port2: port to be used in connection
147         :param bidir: switch between uni and bidirectional traffic
148
149         :raises: RuntimeError
150         """
151         raise NotImplementedError()
152
153     def del_connection(self, switch_name, port1, port2, bidir=False):
154         """Remove connection between two interfaces.
155
156         :param switch_name: switch on which to operate
157         :param port1: port to be used in connection
158         :param port2: port to be used in connection
159         :param bidir: switch between uni and bidirectional traffic
160
161         :raises: RuntimeError
162         """
163         raise NotImplementedError()
164
165     def dump_connections(self, switch_name):
166         """Dump connections between interfaces.
167
168         :param switch_name: switch on which to operate
169
170         :raises: RuntimeError
171         """
172         raise NotImplementedError()
173
174     def dump_flows(self, switch_name):
175         """Dump flows from the logical switch
176
177         :param switch_name: The switch on which to operate
178         """
179         raise NotImplementedError()
180
181     def add_route(self, switch_name, network, destination):
182         """Add a route for tunneling routing table
183
184         :param switch_name: The switch on which to operate
185         :param network: Target destination network
186         :param destination: Gateway IP
187         """
188         raise NotImplementedError()
189
190     def set_tunnel_arp(self, ip_addr, mac_addr, switch_name):
191         """Add arp entry for tunneling
192
193         :param ip_addr: IP of bridge
194         :param mac_addr: MAC address of the bridge
195         :param switch_name: Name of the bridge
196         """
197         raise NotImplementedError()