Add ability to direct "packet-in"s to particular controllers.
[sliver-openvswitch.git] / DESIGN
1                      Design Decisions In Open vSwitch
2                      ================================
3
4 This document describes design decisions that went into implementing
5 Open vSwitch.  While we believe these to be reasonable decisions, it is
6 impossible to predict how Open vSwitch will be used in all environments.
7 Understanding assumptions made by Open vSwitch is critical to a
8 successful deployment.  The end of this document contains contact
9 information that can be used to let us know how we can make Open vSwitch
10 more generally useful.
11
12 Asynchronous Messages
13 =====================
14
15 Over time, Open vSwitch has added many knobs that control whether a
16 given controller receives OpenFlow asynchronous messages.  This
17 section describes how all of these features interact.
18
19 First, a service controller never receives any asynchronous messages
20 unless it explicitly configures a miss_send_len greater than zero with
21 an OFPT_SET_CONFIG message.
22
23 Second, OFPT_FLOW_REMOVED and NXT_FLOW_REMOVED messages are generated
24 only if the flow that was removed had the OFPFF_SEND_FLOW_REM flag
25 set.
26
27 Third, OFPT_PACKET_IN and NXT_PACKET_IN messages are sent only to
28 OpenFlow controller connections that have the correct connection ID
29 (see "struct nx_controller_id" and "struct nx_action_controller"):
30
31     - For packet-in messages generated by a NXAST_CONTROLLER action,
32       the controller ID specified in the action.
33
34     - For other packet-in messages, controller ID zero.  (This is the
35       default ID when an OpenFlow controller does not configure one.)
36
37 Finally, Open vSwitch consults a per-connection table indexed by the
38 message type, reason code, and current role.  The following table
39 shows how this table is initialized by default when an OpenFlow
40 connection is made.  An entry labeled "yes" means that the message is
41 sent, an entry labeled "---" means that the message is suppressed.
42
43                                              master/
44   message and reason code                     other     slave
45   ----------------------------------------   -------    -----
46   OFPT_PACKET_IN / NXT_PACKET_IN
47     OFPR_NO_MATCH                              yes       ---
48     OFPR_ACTION                                yes       ---
49     OFPR_INVALID_TTL                           ---       ---
50
51   OFPT_FLOW_REMOVED / NXT_FLOW_REMOVED
52     OFPRR_IDLE_TIMEOUT                         yes       ---
53     OFPRR_HARD_TIMEOUT                         yes       ---
54     OFPRR_DELETE                               yes       ---
55
56   OFPT_PORT_STATUS
57     OFPPR_ADD                                  yes       yes
58     OFPPR_DELETE                               yes       yes
59     OFPPR_MODIFY                               yes       yes
60
61 The NXT_SET_ASYNC_CONFIG message directly sets all of the values in
62 this table for the current connection.  The
63 OFPC_INVALID_TTL_TO_CONTROLLER bit in the OFPT_SET_CONFIG message
64 controls the setting for OFPR_INVALID_TTL for the "master" role.
65
66
67 OFPAT_ENQUEUE
68 =============
69
70 The OpenFlow 1.0 specification requires the output port of the OFPAT_ENQUEUE
71 action to "refer to a valid physical port (i.e. < OFPP_MAX) or OFPP_IN_PORT".
72 Although OFPP_LOCAL is not less than OFPP_MAX, it is an 'internal' port which
73 can have QoS applied to it in Linux.  Since we allow the OFPAT_ENQUEUE to apply
74 to 'internal' ports whose port numbers are less than OFPP_MAX, we interpret
75 OFPP_LOCAL as a physical port and support OFPAT_ENQUEUE on it as well.
76
77
78 OFPT_FLOW_MOD
79 =============
80
81 The OpenFlow 1.0 specification for the behavior of OFPT_FLOW_MOD is
82 confusing.  The following table summarizes the Open vSwitch
83 implementation of its behavior in the following categories:
84
85     - "match on priority": Whether the flow_mod acts only on flows
86       whose priority matches that included in the flow_mod message.
87
88     - "match on out_port": Whether the flow_mod acts only on flows
89       that output to the out_port included in the flow_mod message (if
90       out_port is not OFPP_NONE).
91
92     - "updates flow_cookie": Whether the flow_mod changes the
93       flow_cookie of the flow or flows that it matches to the
94       flow_cookie included in the flow_mod message.
95
96     - "updates OFPFF_ flags": Whether the flow_mod changes the
97       OFPFF_SEND_FLOW_REM flag of the flow or flows that it matches to
98       the setting included in the flags of the flow_mod message.
99
100     - "honors OFPFF_CHECK_OVERLAP": Whether the OFPFF_CHECK_OVERLAP
101       flag in the flow_mod is significant.
102
103     - "updates idle_timeout" and "updates hard_timeout": Whether the
104       idle_timeout and hard_timeout in the flow_mod, respectively,
105       have an effect on the flow or flows matched by the flow_mod.
106
107     - "updates idle timer": Whether the flow_mod resets the per-flow
108       timer that measures how long a flow has been idle.
109
110     - "updates hard timer": Whether the flow_mod resets the per-flow
111       timer that measures how long it has been since a flow was
112       modified.
113
114     - "zeros counters": Whether the flow_mod resets per-flow packet
115       and byte counters to zero.
116
117     - "sends flow_removed message": Whether the flow_mod generates a
118       flow_removed message for the flow or flows that it affects.
119
120 An entry labeled "yes" means that the flow mod type does have the
121 indicated behavior, "---" means that it does not, an empty cell means
122 that the property is not applicable, and other values are explained
123 below the table.
124
125                                           MODIFY          DELETE
126                              ADD  MODIFY  STRICT  DELETE  STRICT
127                              ===  ======  ======  ======  ======
128 match on priority           ---    ---     yes     ---     yes
129 match on out_port           ---    ---     ---     yes     yes
130 updates flow_cookie          yes    yes     yes
131 updates OFPFF_SEND_FLOW_REM  yes     +       +
132 honors OFPFF_CHECK_OVERLAP   yes     +       +
133 updates idle_timeout         yes     +       +
134 updates hard_timeout         yes     +       +
135 resets idle timer            yes     +       +
136 resets hard timer            yes    yes     yes
137 zeros counters               yes     +       +
138 sends flow_removed message   ---    ---     ---      %       %
139
140 (+) "modify" and "modify-strict" only take these actions when they
141     create a new flow, not when they update an existing flow.
142
143 (%) "delete" and "delete_strict" generates a flow_removed message if
144     the deleted flow or flows have the OFPFF_SEND_FLOW_REM flag set.
145     (Each controller can separately control whether it wants to
146     receive the generated messages.)
147
148
149 Multiple Table Support
150 ======================
151
152 OpenFlow 1.0 has only rudimentary support for multiple flow tables.
153 Notably, OpenFlow 1.0 does not allow the controller to specify the
154 flow table to which a flow is to be added.  Open vSwitch adds an
155 extension for this purpose, which is enabled on a per-OpenFlow
156 connection basis using the NXT_FLOW_MOD_TABLE_ID message.  When the
157 extension is enabled, the upper 8 bits of the 'command' member in an
158 OFPT_FLOW_MOD or NXT_FLOW_MOD message designates the table to which a
159 flow is to be added.
160
161 The Open vSwitch software switch implementation offers 255 flow
162 tables.  On packet ingress, only the first flow table (table 0) is
163 searched, and the contents of the remaining tables are not considered
164 in any way.  Tables other than table 0 only come into play when an
165 NXAST_RESUBMIT_TABLE action specifies another table to search.
166
167 Tables 128 and above are reserved for use by the switch itself.
168 Controllers should use only tables 0 through 127.
169
170
171 IPv6
172 ====
173
174 Open vSwitch supports stateless handling of IPv6 packets.  Flows can be
175 written to support matching TCP, UDP, and ICMPv6 headers within an IPv6
176 packet.  Deeper matching of some Neighbor Discovery messages is also
177 supported.
178
179 IPv6 was not designed to interact well with middle-boxes.  This,
180 combined with Open vSwitch's stateless nature, have affected the
181 processing of IPv6 traffic, which is detailed below.
182
183 Extension Headers
184 -----------------
185
186 The base IPv6 header is incredibly simple with the intention of only
187 containing information relevant for routing packets between two
188 endpoints.  IPv6 relies heavily on the use of extension headers to
189 provide any other functionality.  Unfortunately, the extension headers
190 were designed in such a way that it is impossible to move to the next
191 header (including the layer-4 payload) unless the current header is
192 understood.
193
194 Open vSwitch will process the following extension headers and continue
195 to the next header:
196
197     * Fragment (see the next section)
198     * AH (Authentication Header)
199     * Hop-by-Hop Options
200     * Routing
201     * Destination Options
202
203 When a header is encountered that is not in that list, it is considered
204 "terminal".  A terminal header's IPv6 protocol value is stored in
205 "nw_proto" for matching purposes.  If a terminal header is TCP, UDP, or
206 ICMPv6, the packet will be further processed in an attempt to extract
207 layer-4 information.
208
209 Fragments
210 ---------
211
212 IPv6 requires that every link in the internet have an MTU of 1280 octets
213 or greater (RFC 2460).  As such, a terminal header (as described above in
214 "Extension Headers") in the first fragment should generally be
215 reachable.  In this case, the terminal header's IPv6 protocol type is
216 stored in the "nw_proto" field for matching purposes.  If a terminal
217 header cannot be found in the first fragment (one with a fragment offset
218 of zero), the "nw_proto" field is set to 0.  Subsequent fragments (those
219 with a non-zero fragment offset) have the "nw_proto" field set to the
220 IPv6 protocol type for fragments (44).
221
222 Jumbograms
223 ----------
224
225 An IPv6 jumbogram (RFC 2675) is a packet containing a payload longer
226 than 65,535 octets.  A jumbogram is only relevant in subnets with a link
227 MTU greater than 65,575 octets, and are not required to be supported on
228 nodes that do not connect to link with such large MTUs.  Currently, Open
229 vSwitch doesn't process jumbograms.
230
231
232 In-Band Control
233 ===============
234
235 In-band control allows a single network to be used for OpenFlow traffic and
236 other data traffic.  See ovs-vswitchd.conf.db(5) for a description of
237 configuring in-band control.
238
239 This comment is an attempt to describe how in-band control works at a
240 wire- and implementation-level.  Correctly implementing in-band
241 control has proven difficult due to its many subtleties, and has thus
242 gone through many iterations.  Please read through and understand the
243 reasoning behind the chosen rules before making modifications.
244
245 In Open vSwitch, in-band control is implemented as "hidden" flows (in that
246 they are not visible through OpenFlow) and at a higher priority than
247 wildcarded flows can be set up by through OpenFlow.  This is done so that
248 the OpenFlow controller cannot interfere with them and possibly break
249 connectivity with its switches.  It is possible to see all flows, including
250 in-band ones, with the ovs-appctl "bridge/dump-flows" command.
251
252 The Open vSwitch implementation of in-band control can hide traffic to
253 arbitrary "remotes", where each remote is one TCP port on one IP address.
254 Currently the remotes are automatically configured as the in-band OpenFlow
255 controllers plus the OVSDB managers, if any.  (The latter is a requirement
256 because OVSDB managers are responsible for configuring OpenFlow controllers,
257 so if the manager cannot be reached then OpenFlow cannot be reconfigured.)
258
259 The following rules (with the OFPP_NORMAL action) are set up on any bridge
260 that has any remotes:
261
262    (a) DHCP requests sent from the local port.
263    (b) ARP replies to the local port's MAC address.
264    (c) ARP requests from the local port's MAC address.
265
266 In-band also sets up the following rules for each unique next-hop MAC
267 address for the remotes' IPs (the "next hop" is either the remote
268 itself, if it is on a local subnet, or the gateway to reach the remote):
269
270    (d) ARP replies to the next hop's MAC address.
271    (e) ARP requests from the next hop's MAC address.
272
273 In-band also sets up the following rules for each unique remote IP address:
274
275    (f) ARP replies containing the remote's IP address as a target.
276    (g) ARP requests containing the remote's IP address as a source.
277
278 In-band also sets up the following rules for each unique remote (IP,port)
279 pair:
280
281    (h) TCP traffic to the remote's IP and port.
282    (i) TCP traffic from the remote's IP and port.
283
284 The goal of these rules is to be as narrow as possible to allow a
285 switch to join a network and be able to communicate with the
286 remotes.  As mentioned earlier, these rules have higher priority
287 than the controller's rules, so if they are too broad, they may
288 prevent the controller from implementing its policy.  As such,
289 in-band actively monitors some aspects of flow and packet processing
290 so that the rules can be made more precise.
291
292 In-band control monitors attempts to add flows into the datapath that
293 could interfere with its duties.  The datapath only allows exact
294 match entries, so in-band control is able to be very precise about
295 the flows it prevents.  Flows that miss in the datapath are sent to
296 userspace to be processed, so preventing these flows from being
297 cached in the "fast path" does not affect correctness.  The only type
298 of flow that is currently prevented is one that would prevent DHCP
299 replies from being seen by the local port.  For example, a rule that
300 forwarded all DHCP traffic to the controller would not be allowed,
301 but one that forwarded to all ports (including the local port) would.
302
303 As mentioned earlier, packets that miss in the datapath are sent to
304 the userspace for processing.  The userspace has its own flow table,
305 the "classifier", so in-band checks whether any special processing
306 is needed before the classifier is consulted.  If a packet is a DHCP
307 response to a request from the local port, the packet is forwarded to
308 the local port, regardless of the flow table.  Note that this requires
309 L7 processing of DHCP replies to determine whether the 'chaddr' field
310 matches the MAC address of the local port.
311
312 It is interesting to note that for an L3-based in-band control
313 mechanism, the majority of rules are devoted to ARP traffic.  At first
314 glance, some of these rules appear redundant.  However, each serves an
315 important role.  First, in order to determine the MAC address of the
316 remote side (controller or gateway) for other ARP rules, we must allow
317 ARP traffic for our local port with rules (b) and (c).  If we are
318 between a switch and its connection to the remote, we have to
319 allow the other switch's ARP traffic to through.  This is done with
320 rules (d) and (e), since we do not know the addresses of the other
321 switches a priori, but do know the remote's or gateway's.  Finally,
322 if the remote is running in a local guest VM that is not reached
323 through the local port, the switch that is connected to the VM must
324 allow ARP traffic based on the remote's IP address, since it will
325 not know the MAC address of the local port that is sending the traffic
326 or the MAC address of the remote in the guest VM.
327
328 With a few notable exceptions below, in-band should work in most
329 network setups.  The following are considered "supported' in the
330 current implementation:
331
332    - Locally Connected.  The switch and remote are on the same
333      subnet.  This uses rules (a), (b), (c), (h), and (i).
334
335    - Reached through Gateway.  The switch and remote are on
336      different subnets and must go through a gateway.  This uses
337      rules (a), (b), (c), (h), and (i).
338
339    - Between Switch and Remote.  This switch is between another
340      switch and the remote, and we want to allow the other
341      switch's traffic through.  This uses rules (d), (e), (h), and
342      (i).  It uses (b) and (c) indirectly in order to know the MAC
343      address for rules (d) and (e).  Note that DHCP for the other
344      switch will not work unless an OpenFlow controller explicitly lets this
345      switch pass the traffic.
346
347    - Between Switch and Gateway.  This switch is between another
348      switch and the gateway, and we want to allow the other switch's
349      traffic through.  This uses the same rules and logic as the
350      "Between Switch and Remote" configuration described earlier.
351
352    - Remote on Local VM.  The remote is a guest VM on the
353      system running in-band control.  This uses rules (a), (b), (c),
354      (h), and (i).
355
356    - Remote on Local VM with Different Networks.  The remote
357      is a guest VM on the system running in-band control, but the
358      local port is not used to connect to the remote.  For
359      example, an IP address is configured on eth0 of the switch.  The
360      remote's VM is connected through eth1 of the switch, but an
361      IP address has not been configured for that port on the switch.
362      As such, the switch will use eth0 to connect to the remote,
363      and eth1's rules about the local port will not work.  In the
364      example, the switch attached to eth0 would use rules (a), (b),
365      (c), (h), and (i) on eth0.  The switch attached to eth1 would use
366      rules (f), (g), (h), and (i).
367
368 The following are explicitly *not* supported by in-band control:
369
370    - Specify Remote by Name.  Currently, the remote must be
371      identified by IP address.  A naive approach would be to permit
372      all DNS traffic.  Unfortunately, this would prevent the
373      controller from defining any policy over DNS.  Since switches
374      that are located behind us need to connect to the remote,
375      in-band cannot simply add a rule that allows DNS traffic from
376      the local port.  The "correct" way to support this is to parse
377      DNS requests to allow all traffic related to a request for the
378      remote's name through.  Due to the potential security
379      problems and amount of processing, we decided to hold off for
380      the time-being.
381
382    - Differing Remotes for Switches.  All switches must know
383      the L3 addresses for all the remotes that other switches
384      may use, since rules need to be set up to allow traffic related
385      to those remotes through.  See rules (f), (g), (h), and (i).
386
387    - Differing Routes for Switches.  In order for the switch to
388      allow other switches to connect to a remote through a
389      gateway, it allows the gateway's traffic through with rules (d)
390      and (e).  If the routes to the remote differ for the two
391      switches, we will not know the MAC address of the alternate
392      gateway.
393
394
395 Suggestions
396 ===========
397
398 Suggestions to improve Open vSwitch are welcome at discuss@openvswitch.org.