DESIGN: Describe principles of in-band control.
[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 Motivation
236 ----------
237
238 An OpenFlow switch must establish and maintain a TCP network
239 connection to its controller.  There are two basic ways to categorize
240 the network that this connection traverses: either it is completely
241 separate from the one that the switch is otherwise controlling, or its
242 path may overlap the network that the switch controls.  We call the
243 former case "out-of-band control", the latter case "in-band control".
244
245 Out-of-band control has the following benefits:
246
247     - Simplicity: Out-of-band control slightly simplifies the switch
248       implementation.
249
250     - Reliability: Excessive switch traffic volume cannot interfere
251       with control traffic.
252
253     - Integrity: Machines not on the control network cannot
254       impersonate a switch or a controller.
255
256     - Confidentiality: Machines not on the control network cannot
257       snoop on control traffic.
258
259 In-band control, on the other hand, has the following advantages:
260
261     - No dedicated port: There is no need to dedicate a physical
262       switch port to control, which is important on switches that have
263       few ports (e.g. wireless routers, low-end embedded platforms).
264
265     - No dedicated network: There is no need to build and maintain a
266       separate control network.  This is important in many
267       environments because it reduces proliferation of switches and
268       wiring.
269
270 Open vSwitch supports both out-of-band and in-band control.  This
271 section describes the principles behind in-band control.  See the
272 description of the Controller table in ovs-vswitchd.conf.db(5) to
273 configure OVS for in-band control.
274
275 Principles
276 ----------
277
278 The fundamental principle of in-band control is that an OpenFlow
279 switch must recognize and switch control traffic without involving the
280 OpenFlow controller.  All the details of implementing in-band control
281 are special cases of this principle.
282
283 The rationale for this principle is simple.  If the switch does not
284 handle in-band control traffic itself, then it will be caught in a
285 contradiction: it must contact the controller, but it cannot, because
286 only the controller can set up the flows that are needed to contact
287 the controller.
288
289 The following points describe important special cases of this
290 principle.
291
292    - In-band control must be implemented regardless of whether the
293      switch is connected.
294
295      It is tempting to implement the in-band control rules only when
296      the switch is not connected to the controller, using the
297      reasoning that the controller should have complete control once
298      it has established a connection with the switch.
299
300      This does not work in practice.  Consider the case where the
301      switch is connected to the controller.  Occasionally it can
302      happen that the controller forgets or otherwise needs to obtain
303      the MAC address of the switch.  To do so, the controller sends a
304      broadcast ARP request.  A switch that implements the in-band
305      control rules only when it is disconnected will then send an
306      OFPT_PACKET_IN message up to the controller.  The controller will
307      be unable to respond, because it does not know the MAC address of
308      the switch.  This is a deadlock situation that can only be
309      resolved by the switch noticing that its connection to the
310      controller has hung and reconnecting.
311
312    - In-band control must override flows set up by the controller.
313
314      It is reasonable to assume that flows set up by the OpenFlow
315      controller should take precedence over in-band control, on the
316      basis that the controller should be in charge of the switch.
317
318      Again, this does not work in practice.  Reasonable controller
319      implementations may set up a "last resort" fallback rule that
320      wildcards every field and, e.g., sends it up to the controller or
321      discards it.  If a controller does that, then it will isolate
322      itself from the switch.
323
324    - The switch must recognize all control traffic.
325
326      The fundamental principle of in-band control states, in part,
327      that a switch must recognize control traffic without involving
328      the OpenFlow controller.  More specifically, the switch must
329      recognize *all* control traffic.  "False negatives", that is,
330      packets that constitute control traffic but that the switch does
331      not recognize as control traffic, lead to control traffic storms.
332
333      Consider an OpenFlow switch that only recognizes control packets
334      sent to or from that switch.  Now suppose that two switches of
335      this type, named A and B, are connected to ports on an Ethernet
336      hub (not a switch) and that an OpenFlow controller is connected
337      to a third hub port.  In this setup, control traffic sent by
338      switch A will be seen by switch B, which will send it to the
339      controller as part of an OFPT_PACKET_IN message.  Switch A will
340      then see the OFPT_PACKET_IN message's packet, re-encapsulate it
341      in another OFPT_PACKET_IN, and send it to the controller.  Switch
342      B will then see that OFPT_PACKET_IN, and so on in an infinite
343      loop.
344
345      Incidentally, the consequences of "false positives", where
346      packets that are not control traffic are nevertheless recognized
347      as control traffic, are much less severe.  The controller will
348      not be able to control their behavior, but the network will
349      remain in working order.  False positives do constitute a
350      security problem.
351
352    - The switch should use echo-requests to detect disconnection.
353
354      TCP will notice that a connection has hung, but this can take a
355      considerable amount of time.  For example, with default settings
356      the Linux kernel TCP implementation will retransmit for between
357      13 and 30 minutes, depending on the connection's retransmission
358      timeout, according to kernel documentation.  This is far too long
359      for a switch to be disconnected, so an OpenFlow switch should
360      implement its own connection timeout.  OpenFlow OFPT_ECHO_REQUEST
361      messages are the best way to do this, since they test the
362      OpenFlow connection itself.
363
364 Implementation
365 --------------
366
367 This section describes how Open vSwitch implements in-band control.
368 Correctly implementing in-band control has proven difficult due to its
369 many subtleties, and has thus gone through many iterations.  Please
370 read through and understand the reasoning behind the chosen rules
371 before making modifications.
372
373 Open vSwitch implements in-band control as "hidden" flows, that is,
374 flows that are not visible through OpenFlow, and at a higher priority
375 than wildcarded flows can be set up through OpenFlow.  This is done so
376 that the OpenFlow controller cannot interfere with them and possibly
377 break connectivity with its switches.  It is possible to see all
378 flows, including in-band ones, with the ovs-appctl "bridge/dump-flows"
379 command.
380
381 The Open vSwitch implementation of in-band control can hide traffic to
382 arbitrary "remotes", where each remote is one TCP port on one IP address.
383 Currently the remotes are automatically configured as the in-band OpenFlow
384 controllers plus the OVSDB managers, if any.  (The latter is a requirement
385 because OVSDB managers are responsible for configuring OpenFlow controllers,
386 so if the manager cannot be reached then OpenFlow cannot be reconfigured.)
387
388 The following rules (with the OFPP_NORMAL action) are set up on any bridge
389 that has any remotes:
390
391    (a) DHCP requests sent from the local port.
392    (b) ARP replies to the local port's MAC address.
393    (c) ARP requests from the local port's MAC address.
394
395 In-band also sets up the following rules for each unique next-hop MAC
396 address for the remotes' IPs (the "next hop" is either the remote
397 itself, if it is on a local subnet, or the gateway to reach the remote):
398
399    (d) ARP replies to the next hop's MAC address.
400    (e) ARP requests from the next hop's MAC address.
401
402 In-band also sets up the following rules for each unique remote IP address:
403
404    (f) ARP replies containing the remote's IP address as a target.
405    (g) ARP requests containing the remote's IP address as a source.
406
407 In-band also sets up the following rules for each unique remote (IP,port)
408 pair:
409
410    (h) TCP traffic to the remote's IP and port.
411    (i) TCP traffic from the remote's IP and port.
412
413 The goal of these rules is to be as narrow as possible to allow a
414 switch to join a network and be able to communicate with the
415 remotes.  As mentioned earlier, these rules have higher priority
416 than the controller's rules, so if they are too broad, they may
417 prevent the controller from implementing its policy.  As such,
418 in-band actively monitors some aspects of flow and packet processing
419 so that the rules can be made more precise.
420
421 In-band control monitors attempts to add flows into the datapath that
422 could interfere with its duties.  The datapath only allows exact
423 match entries, so in-band control is able to be very precise about
424 the flows it prevents.  Flows that miss in the datapath are sent to
425 userspace to be processed, so preventing these flows from being
426 cached in the "fast path" does not affect correctness.  The only type
427 of flow that is currently prevented is one that would prevent DHCP
428 replies from being seen by the local port.  For example, a rule that
429 forwarded all DHCP traffic to the controller would not be allowed,
430 but one that forwarded to all ports (including the local port) would.
431
432 As mentioned earlier, packets that miss in the datapath are sent to
433 the userspace for processing.  The userspace has its own flow table,
434 the "classifier", so in-band checks whether any special processing
435 is needed before the classifier is consulted.  If a packet is a DHCP
436 response to a request from the local port, the packet is forwarded to
437 the local port, regardless of the flow table.  Note that this requires
438 L7 processing of DHCP replies to determine whether the 'chaddr' field
439 matches the MAC address of the local port.
440
441 It is interesting to note that for an L3-based in-band control
442 mechanism, the majority of rules are devoted to ARP traffic.  At first
443 glance, some of these rules appear redundant.  However, each serves an
444 important role.  First, in order to determine the MAC address of the
445 remote side (controller or gateway) for other ARP rules, we must allow
446 ARP traffic for our local port with rules (b) and (c).  If we are
447 between a switch and its connection to the remote, we have to
448 allow the other switch's ARP traffic to through.  This is done with
449 rules (d) and (e), since we do not know the addresses of the other
450 switches a priori, but do know the remote's or gateway's.  Finally,
451 if the remote is running in a local guest VM that is not reached
452 through the local port, the switch that is connected to the VM must
453 allow ARP traffic based on the remote's IP address, since it will
454 not know the MAC address of the local port that is sending the traffic
455 or the MAC address of the remote in the guest VM.
456
457 With a few notable exceptions below, in-band should work in most
458 network setups.  The following are considered "supported' in the
459 current implementation:
460
461    - Locally Connected.  The switch and remote are on the same
462      subnet.  This uses rules (a), (b), (c), (h), and (i).
463
464    - Reached through Gateway.  The switch and remote are on
465      different subnets and must go through a gateway.  This uses
466      rules (a), (b), (c), (h), and (i).
467
468    - Between Switch and Remote.  This switch is between another
469      switch and the remote, and we want to allow the other
470      switch's traffic through.  This uses rules (d), (e), (h), and
471      (i).  It uses (b) and (c) indirectly in order to know the MAC
472      address for rules (d) and (e).  Note that DHCP for the other
473      switch will not work unless an OpenFlow controller explicitly lets this
474      switch pass the traffic.
475
476    - Between Switch and Gateway.  This switch is between another
477      switch and the gateway, and we want to allow the other switch's
478      traffic through.  This uses the same rules and logic as the
479      "Between Switch and Remote" configuration described earlier.
480
481    - Remote on Local VM.  The remote is a guest VM on the
482      system running in-band control.  This uses rules (a), (b), (c),
483      (h), and (i).
484
485    - Remote on Local VM with Different Networks.  The remote
486      is a guest VM on the system running in-band control, but the
487      local port is not used to connect to the remote.  For
488      example, an IP address is configured on eth0 of the switch.  The
489      remote's VM is connected through eth1 of the switch, but an
490      IP address has not been configured for that port on the switch.
491      As such, the switch will use eth0 to connect to the remote,
492      and eth1's rules about the local port will not work.  In the
493      example, the switch attached to eth0 would use rules (a), (b),
494      (c), (h), and (i) on eth0.  The switch attached to eth1 would use
495      rules (f), (g), (h), and (i).
496
497 The following are explicitly *not* supported by in-band control:
498
499    - Specify Remote by Name.  Currently, the remote must be
500      identified by IP address.  A naive approach would be to permit
501      all DNS traffic.  Unfortunately, this would prevent the
502      controller from defining any policy over DNS.  Since switches
503      that are located behind us need to connect to the remote,
504      in-band cannot simply add a rule that allows DNS traffic from
505      the local port.  The "correct" way to support this is to parse
506      DNS requests to allow all traffic related to a request for the
507      remote's name through.  Due to the potential security
508      problems and amount of processing, we decided to hold off for
509      the time-being.
510
511    - Differing Remotes for Switches.  All switches must know
512      the L3 addresses for all the remotes that other switches
513      may use, since rules need to be set up to allow traffic related
514      to those remotes through.  See rules (f), (g), (h), and (i).
515
516    - Differing Routes for Switches.  In order for the switch to
517      allow other switches to connect to a remote through a
518      gateway, it allows the gateway's traffic through with rules (d)
519      and (e).  If the routes to the remote differ for the two
520      switches, we will not know the MAC address of the alternate
521      gateway.
522
523
524 Suggestions
525 ===========
526
527 Suggestions to improve Open vSwitch are welcome at discuss@openvswitch.org.