1 Design Decisions In Open vSwitch
2 ================================
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.
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.
19 First, a service controller never receives any asynchronous messages
20 unless it changes its miss_send_len from the service controller
21 default of zero in one of the following ways:
23 - Sending an OFPT_SET_CONFIG message with nonzero miss_send_len.
25 - Sending any NXT_SET_ASYNC_CONFIG message: as a side effect, this
26 message changes the miss_send_len to
27 OFP_DEFAULT_MISS_SEND_LEN (128) for service controllers.
29 Second, OFPT_FLOW_REMOVED and NXT_FLOW_REMOVED messages are generated
30 only if the flow that was removed had the OFPFF_SEND_FLOW_REM flag
33 Third, OFPT_PACKET_IN and NXT_PACKET_IN messages are sent only to
34 OpenFlow controller connections that have the correct connection ID
35 (see "struct nx_controller_id" and "struct nx_action_controller"):
37 - For packet-in messages generated by a NXAST_CONTROLLER action,
38 the controller ID specified in the action.
40 - For other packet-in messages, controller ID zero. (This is the
41 default ID when an OpenFlow controller does not configure one.)
43 Finally, Open vSwitch consults a per-connection table indexed by the
44 message type, reason code, and current role. The following table
45 shows how this table is initialized by default when an OpenFlow
46 connection is made. An entry labeled "yes" means that the message is
47 sent, an entry labeled "---" means that the message is suppressed.
50 message and reason code other slave
51 ---------------------------------------- ------- -----
52 OFPT_PACKET_IN / NXT_PACKET_IN
55 OFPR_INVALID_TTL --- ---
57 OFPT_FLOW_REMOVED / NXT_FLOW_REMOVED
58 OFPRR_IDLE_TIMEOUT yes ---
59 OFPRR_HARD_TIMEOUT yes ---
67 The NXT_SET_ASYNC_CONFIG message directly sets all of the values in
68 this table for the current connection. The
69 OFPC_INVALID_TTL_TO_CONTROLLER bit in the OFPT_SET_CONFIG message
70 controls the setting for OFPR_INVALID_TTL for the "master" role.
76 The OpenFlow 1.0 specification requires the output port of the OFPAT_ENQUEUE
77 action to "refer to a valid physical port (i.e. < OFPP_MAX) or OFPP_IN_PORT".
78 Although OFPP_LOCAL is not less than OFPP_MAX, it is an 'internal' port which
79 can have QoS applied to it in Linux. Since we allow the OFPAT_ENQUEUE to apply
80 to 'internal' ports whose port numbers are less than OFPP_MAX, we interpret
81 OFPP_LOCAL as a physical port and support OFPAT_ENQUEUE on it as well.
87 The OpenFlow 1.0 specification for the behavior of OFPT_FLOW_MOD is
88 confusing. The following table summarizes the Open vSwitch
89 implementation of its behavior in the following categories:
91 - "match on priority": Whether the flow_mod acts only on flows
92 whose priority matches that included in the flow_mod message.
94 - "match on out_port": Whether the flow_mod acts only on flows
95 that output to the out_port included in the flow_mod message (if
96 out_port is not OFPP_NONE).
98 - "updates flow_cookie": Whether the flow_mod changes the
99 flow_cookie of the flow or flows that it matches to the
100 flow_cookie included in the flow_mod message.
102 - "updates OFPFF_ flags": Whether the flow_mod changes the
103 OFPFF_SEND_FLOW_REM flag of the flow or flows that it matches to
104 the setting included in the flags of the flow_mod message.
106 - "honors OFPFF_CHECK_OVERLAP": Whether the OFPFF_CHECK_OVERLAP
107 flag in the flow_mod is significant.
109 - "updates idle_timeout" and "updates hard_timeout": Whether the
110 idle_timeout and hard_timeout in the flow_mod, respectively,
111 have an effect on the flow or flows matched by the flow_mod.
113 - "updates idle timer": Whether the flow_mod resets the per-flow
114 timer that measures how long a flow has been idle.
116 - "updates hard timer": Whether the flow_mod resets the per-flow
117 timer that measures how long it has been since a flow was
120 - "zeros counters": Whether the flow_mod resets per-flow packet
121 and byte counters to zero.
123 - "sends flow_removed message": Whether the flow_mod generates a
124 flow_removed message for the flow or flows that it affects.
126 An entry labeled "yes" means that the flow mod type does have the
127 indicated behavior, "---" means that it does not, an empty cell means
128 that the property is not applicable, and other values are explained
132 ADD MODIFY STRICT DELETE STRICT
133 === ====== ====== ====== ======
134 match on priority --- --- yes --- yes
135 match on out_port --- --- --- yes yes
136 updates flow_cookie yes yes yes
137 updates OFPFF_SEND_FLOW_REM yes + +
138 honors OFPFF_CHECK_OVERLAP yes + +
139 updates idle_timeout yes + +
140 updates hard_timeout yes + +
141 resets idle timer yes + +
142 resets hard timer yes yes yes
143 zeros counters yes + +
144 sends flow_removed message --- --- --- % %
146 (+) "modify" and "modify-strict" only take these actions when they
147 create a new flow, not when they update an existing flow.
149 (%) "delete" and "delete_strict" generates a flow_removed message if
150 the deleted flow or flows have the OFPFF_SEND_FLOW_REM flag set.
151 (Each controller can separately control whether it wants to
152 receive the generated messages.)
158 OpenFlow 1.0 and later versions have the concept of a "flow cookie",
159 which is a 64-bit integer value attached to each flow. The treatment
160 of the flow cookie has varied greatly across OpenFlow versions,
165 - OFPFC_ADD set the cookie in the flow that it added.
167 - OFPFC_MODIFY and OFPFC_MODIFY_STRICT updated the cookie for
168 the flow or flows that it modified.
170 - OFPST_FLOW messages included the flow cookie.
172 - OFPT_FLOW_REMOVED messages reported the cookie of the flow
175 OpenFlow 1.1 made the following changes:
177 - Flow mod operations OFPFC_MODIFY, OFPFC_MODIFY_STRICT,
178 OFPFC_DELETE, and OFPFC_DELETE_STRICT, plus flow stats
179 requests and aggregate stats requests, gained the ability to
180 match on flow cookies with an arbitrary mask.
182 - OFPFC_MODIFY and OFPFC_MODIFY_STRICT were changed to add a
183 new flow, in the case of no match, only if the flow table
184 modification operation did not match on the cookie field.
185 (In OpenFlow 1.0, modify operations always added a new flow
186 when there was no match.)
188 - OFPFC_MODIFY and OFPFC_MODIFY_STRICT no longer updated flow
191 OpenFlow 1.2 made the following changes:
193 - OFPC_MODIFY and OFPFC_MODIFY_STRICT were changed to never
194 add a new flow, regardless of whether the flow cookie was
197 Open vSwitch support for OpenFlow 1.0 implements the OpenFlow 1.0
198 behavior with the following extensions:
200 - An NXM extension field NXM_NX_COOKIE(_W) allows the NXM
201 versions of OFPFC_MODIFY, OFPFC_MODIFY_STRICT, OFPFC_DELETE,
202 and OFPFC_DELETE_STRICT flow_mods, plus flow stats requests
203 and aggregate stats requests, to match on flow cookies with
204 arbitrary masks. This is much like the equivalent OpenFlow
207 - Like OpenFlow 1.1, OFPC_MODIFY and OFPFC_MODIFY_STRICT add a
208 new flow if there is no match and the mask is zero (or not
211 - The "cookie" field in OFPT_FLOW_MOD and NXT_FLOW_MOD messages
212 is used as the cookie value for OFPFC_ADD commands, as
213 described in OpenFlow 1.0. For OFPFC_MODIFY and
214 OFPFC_MODIFY_STRICT commands, the "cookie" field is used as a
215 new cookie for flows that match unless it is UINT64_MAX, in
216 which case the flow's cookie is not updated.
218 - NXT_PACKET_IN (the Nicira extended version of
219 OFPT_PACKET_IN) reports the cookie of the rule that
220 generated the packet, or all-1-bits if no rule generated the
221 packet. (Older versions of OVS used all-0-bits instead of
224 The following table shows the handling of different protocols when
225 receiving OFPFC_MODIFY and OFPFC_MODIFY_STRICT messages. A mask of 0
226 indicates either an explicit mask of zero or an implicit one by not
227 specifying the NXM_NX_COOKIE(_W) field.
229 Match Update Add on miss Add on miss
230 cookie cookie mask!=0 mask==0
231 ====== ====== =========== ===========
232 OpenFlow 1.0 no yes <always add on miss>
233 OpenFlow 1.1 yes no no yes
234 OpenFlow 1.2 yes no no no
237 * Updates the flow's cookie unless the "cookie" field is UINT64_MAX.
240 Multiple Table Support
241 ======================
243 OpenFlow 1.0 has only rudimentary support for multiple flow tables.
244 Notably, OpenFlow 1.0 does not allow the controller to specify the
245 flow table to which a flow is to be added. Open vSwitch adds an
246 extension for this purpose, which is enabled on a per-OpenFlow
247 connection basis using the NXT_FLOW_MOD_TABLE_ID message. When the
248 extension is enabled, the upper 8 bits of the 'command' member in an
249 OFPT_FLOW_MOD or NXT_FLOW_MOD message designates the table to which a
252 The Open vSwitch software switch implementation offers 255 flow
253 tables. On packet ingress, only the first flow table (table 0) is
254 searched, and the contents of the remaining tables are not considered
255 in any way. Tables other than table 0 only come into play when an
256 NXAST_RESUBMIT_TABLE action specifies another table to search.
258 Tables 128 and above are reserved for use by the switch itself.
259 Controllers should use only tables 0 through 127.
265 Open vSwitch supports stateless handling of IPv6 packets. Flows can be
266 written to support matching TCP, UDP, and ICMPv6 headers within an IPv6
267 packet. Deeper matching of some Neighbor Discovery messages is also
270 IPv6 was not designed to interact well with middle-boxes. This,
271 combined with Open vSwitch's stateless nature, have affected the
272 processing of IPv6 traffic, which is detailed below.
277 The base IPv6 header is incredibly simple with the intention of only
278 containing information relevant for routing packets between two
279 endpoints. IPv6 relies heavily on the use of extension headers to
280 provide any other functionality. Unfortunately, the extension headers
281 were designed in such a way that it is impossible to move to the next
282 header (including the layer-4 payload) unless the current header is
285 Open vSwitch will process the following extension headers and continue
288 * Fragment (see the next section)
289 * AH (Authentication Header)
292 * Destination Options
294 When a header is encountered that is not in that list, it is considered
295 "terminal". A terminal header's IPv6 protocol value is stored in
296 "nw_proto" for matching purposes. If a terminal header is TCP, UDP, or
297 ICMPv6, the packet will be further processed in an attempt to extract
303 IPv6 requires that every link in the internet have an MTU of 1280 octets
304 or greater (RFC 2460). As such, a terminal header (as described above in
305 "Extension Headers") in the first fragment should generally be
306 reachable. In this case, the terminal header's IPv6 protocol type is
307 stored in the "nw_proto" field for matching purposes. If a terminal
308 header cannot be found in the first fragment (one with a fragment offset
309 of zero), the "nw_proto" field is set to 0. Subsequent fragments (those
310 with a non-zero fragment offset) have the "nw_proto" field set to the
311 IPv6 protocol type for fragments (44).
316 An IPv6 jumbogram (RFC 2675) is a packet containing a payload longer
317 than 65,535 octets. A jumbogram is only relevant in subnets with a link
318 MTU greater than 65,575 octets, and are not required to be supported on
319 nodes that do not connect to link with such large MTUs. Currently, Open
320 vSwitch doesn't process jumbograms.
329 An OpenFlow switch must establish and maintain a TCP network
330 connection to its controller. There are two basic ways to categorize
331 the network that this connection traverses: either it is completely
332 separate from the one that the switch is otherwise controlling, or its
333 path may overlap the network that the switch controls. We call the
334 former case "out-of-band control", the latter case "in-band control".
336 Out-of-band control has the following benefits:
338 - Simplicity: Out-of-band control slightly simplifies the switch
341 - Reliability: Excessive switch traffic volume cannot interfere
342 with control traffic.
344 - Integrity: Machines not on the control network cannot
345 impersonate a switch or a controller.
347 - Confidentiality: Machines not on the control network cannot
348 snoop on control traffic.
350 In-band control, on the other hand, has the following advantages:
352 - No dedicated port: There is no need to dedicate a physical
353 switch port to control, which is important on switches that have
354 few ports (e.g. wireless routers, low-end embedded platforms).
356 - No dedicated network: There is no need to build and maintain a
357 separate control network. This is important in many
358 environments because it reduces proliferation of switches and
361 Open vSwitch supports both out-of-band and in-band control. This
362 section describes the principles behind in-band control. See the
363 description of the Controller table in ovs-vswitchd.conf.db(5) to
364 configure OVS for in-band control.
369 The fundamental principle of in-band control is that an OpenFlow
370 switch must recognize and switch control traffic without involving the
371 OpenFlow controller. All the details of implementing in-band control
372 are special cases of this principle.
374 The rationale for this principle is simple. If the switch does not
375 handle in-band control traffic itself, then it will be caught in a
376 contradiction: it must contact the controller, but it cannot, because
377 only the controller can set up the flows that are needed to contact
380 The following points describe important special cases of this
383 - In-band control must be implemented regardless of whether the
386 It is tempting to implement the in-band control rules only when
387 the switch is not connected to the controller, using the
388 reasoning that the controller should have complete control once
389 it has established a connection with the switch.
391 This does not work in practice. Consider the case where the
392 switch is connected to the controller. Occasionally it can
393 happen that the controller forgets or otherwise needs to obtain
394 the MAC address of the switch. To do so, the controller sends a
395 broadcast ARP request. A switch that implements the in-band
396 control rules only when it is disconnected will then send an
397 OFPT_PACKET_IN message up to the controller. The controller will
398 be unable to respond, because it does not know the MAC address of
399 the switch. This is a deadlock situation that can only be
400 resolved by the switch noticing that its connection to the
401 controller has hung and reconnecting.
403 - In-band control must override flows set up by the controller.
405 It is reasonable to assume that flows set up by the OpenFlow
406 controller should take precedence over in-band control, on the
407 basis that the controller should be in charge of the switch.
409 Again, this does not work in practice. Reasonable controller
410 implementations may set up a "last resort" fallback rule that
411 wildcards every field and, e.g., sends it up to the controller or
412 discards it. If a controller does that, then it will isolate
413 itself from the switch.
415 - The switch must recognize all control traffic.
417 The fundamental principle of in-band control states, in part,
418 that a switch must recognize control traffic without involving
419 the OpenFlow controller. More specifically, the switch must
420 recognize *all* control traffic. "False negatives", that is,
421 packets that constitute control traffic but that the switch does
422 not recognize as control traffic, lead to control traffic storms.
424 Consider an OpenFlow switch that only recognizes control packets
425 sent to or from that switch. Now suppose that two switches of
426 this type, named A and B, are connected to ports on an Ethernet
427 hub (not a switch) and that an OpenFlow controller is connected
428 to a third hub port. In this setup, control traffic sent by
429 switch A will be seen by switch B, which will send it to the
430 controller as part of an OFPT_PACKET_IN message. Switch A will
431 then see the OFPT_PACKET_IN message's packet, re-encapsulate it
432 in another OFPT_PACKET_IN, and send it to the controller. Switch
433 B will then see that OFPT_PACKET_IN, and so on in an infinite
436 Incidentally, the consequences of "false positives", where
437 packets that are not control traffic are nevertheless recognized
438 as control traffic, are much less severe. The controller will
439 not be able to control their behavior, but the network will
440 remain in working order. False positives do constitute a
443 - The switch should use echo-requests to detect disconnection.
445 TCP will notice that a connection has hung, but this can take a
446 considerable amount of time. For example, with default settings
447 the Linux kernel TCP implementation will retransmit for between
448 13 and 30 minutes, depending on the connection's retransmission
449 timeout, according to kernel documentation. This is far too long
450 for a switch to be disconnected, so an OpenFlow switch should
451 implement its own connection timeout. OpenFlow OFPT_ECHO_REQUEST
452 messages are the best way to do this, since they test the
453 OpenFlow connection itself.
458 This section describes how Open vSwitch implements in-band control.
459 Correctly implementing in-band control has proven difficult due to its
460 many subtleties, and has thus gone through many iterations. Please
461 read through and understand the reasoning behind the chosen rules
462 before making modifications.
464 Open vSwitch implements in-band control as "hidden" flows, that is,
465 flows that are not visible through OpenFlow, and at a higher priority
466 than wildcarded flows can be set up through OpenFlow. This is done so
467 that the OpenFlow controller cannot interfere with them and possibly
468 break connectivity with its switches. It is possible to see all
469 flows, including in-band ones, with the ovs-appctl "bridge/dump-flows"
472 The Open vSwitch implementation of in-band control can hide traffic to
473 arbitrary "remotes", where each remote is one TCP port on one IP address.
474 Currently the remotes are automatically configured as the in-band OpenFlow
475 controllers plus the OVSDB managers, if any. (The latter is a requirement
476 because OVSDB managers are responsible for configuring OpenFlow controllers,
477 so if the manager cannot be reached then OpenFlow cannot be reconfigured.)
479 The following rules (with the OFPP_NORMAL action) are set up on any bridge
480 that has any remotes:
482 (a) DHCP requests sent from the local port.
483 (b) ARP replies to the local port's MAC address.
484 (c) ARP requests from the local port's MAC address.
486 In-band also sets up the following rules for each unique next-hop MAC
487 address for the remotes' IPs (the "next hop" is either the remote
488 itself, if it is on a local subnet, or the gateway to reach the remote):
490 (d) ARP replies to the next hop's MAC address.
491 (e) ARP requests from the next hop's MAC address.
493 In-band also sets up the following rules for each unique remote IP address:
495 (f) ARP replies containing the remote's IP address as a target.
496 (g) ARP requests containing the remote's IP address as a source.
498 In-band also sets up the following rules for each unique remote (IP,port)
501 (h) TCP traffic to the remote's IP and port.
502 (i) TCP traffic from the remote's IP and port.
504 The goal of these rules is to be as narrow as possible to allow a
505 switch to join a network and be able to communicate with the
506 remotes. As mentioned earlier, these rules have higher priority
507 than the controller's rules, so if they are too broad, they may
508 prevent the controller from implementing its policy. As such,
509 in-band actively monitors some aspects of flow and packet processing
510 so that the rules can be made more precise.
512 In-band control monitors attempts to add flows into the datapath that
513 could interfere with its duties. The datapath only allows exact
514 match entries, so in-band control is able to be very precise about
515 the flows it prevents. Flows that miss in the datapath are sent to
516 userspace to be processed, so preventing these flows from being
517 cached in the "fast path" does not affect correctness. The only type
518 of flow that is currently prevented is one that would prevent DHCP
519 replies from being seen by the local port. For example, a rule that
520 forwarded all DHCP traffic to the controller would not be allowed,
521 but one that forwarded to all ports (including the local port) would.
523 As mentioned earlier, packets that miss in the datapath are sent to
524 the userspace for processing. The userspace has its own flow table,
525 the "classifier", so in-band checks whether any special processing
526 is needed before the classifier is consulted. If a packet is a DHCP
527 response to a request from the local port, the packet is forwarded to
528 the local port, regardless of the flow table. Note that this requires
529 L7 processing of DHCP replies to determine whether the 'chaddr' field
530 matches the MAC address of the local port.
532 It is interesting to note that for an L3-based in-band control
533 mechanism, the majority of rules are devoted to ARP traffic. At first
534 glance, some of these rules appear redundant. However, each serves an
535 important role. First, in order to determine the MAC address of the
536 remote side (controller or gateway) for other ARP rules, we must allow
537 ARP traffic for our local port with rules (b) and (c). If we are
538 between a switch and its connection to the remote, we have to
539 allow the other switch's ARP traffic to through. This is done with
540 rules (d) and (e), since we do not know the addresses of the other
541 switches a priori, but do know the remote's or gateway's. Finally,
542 if the remote is running in a local guest VM that is not reached
543 through the local port, the switch that is connected to the VM must
544 allow ARP traffic based on the remote's IP address, since it will
545 not know the MAC address of the local port that is sending the traffic
546 or the MAC address of the remote in the guest VM.
548 With a few notable exceptions below, in-band should work in most
549 network setups. The following are considered "supported' in the
550 current implementation:
552 - Locally Connected. The switch and remote are on the same
553 subnet. This uses rules (a), (b), (c), (h), and (i).
555 - Reached through Gateway. The switch and remote are on
556 different subnets and must go through a gateway. This uses
557 rules (a), (b), (c), (h), and (i).
559 - Between Switch and Remote. This switch is between another
560 switch and the remote, and we want to allow the other
561 switch's traffic through. This uses rules (d), (e), (h), and
562 (i). It uses (b) and (c) indirectly in order to know the MAC
563 address for rules (d) and (e). Note that DHCP for the other
564 switch will not work unless an OpenFlow controller explicitly lets this
565 switch pass the traffic.
567 - Between Switch and Gateway. This switch is between another
568 switch and the gateway, and we want to allow the other switch's
569 traffic through. This uses the same rules and logic as the
570 "Between Switch and Remote" configuration described earlier.
572 - Remote on Local VM. The remote is a guest VM on the
573 system running in-band control. This uses rules (a), (b), (c),
576 - Remote on Local VM with Different Networks. The remote
577 is a guest VM on the system running in-band control, but the
578 local port is not used to connect to the remote. For
579 example, an IP address is configured on eth0 of the switch. The
580 remote's VM is connected through eth1 of the switch, but an
581 IP address has not been configured for that port on the switch.
582 As such, the switch will use eth0 to connect to the remote,
583 and eth1's rules about the local port will not work. In the
584 example, the switch attached to eth0 would use rules (a), (b),
585 (c), (h), and (i) on eth0. The switch attached to eth1 would use
586 rules (f), (g), (h), and (i).
588 The following are explicitly *not* supported by in-band control:
590 - Specify Remote by Name. Currently, the remote must be
591 identified by IP address. A naive approach would be to permit
592 all DNS traffic. Unfortunately, this would prevent the
593 controller from defining any policy over DNS. Since switches
594 that are located behind us need to connect to the remote,
595 in-band cannot simply add a rule that allows DNS traffic from
596 the local port. The "correct" way to support this is to parse
597 DNS requests to allow all traffic related to a request for the
598 remote's name through. Due to the potential security
599 problems and amount of processing, we decided to hold off for
602 - Differing Remotes for Switches. All switches must know
603 the L3 addresses for all the remotes that other switches
604 may use, since rules need to be set up to allow traffic related
605 to those remotes through. See rules (f), (g), (h), and (i).
607 - Differing Routes for Switches. In order for the switch to
608 allow other switches to connect to a remote through a
609 gateway, it allows the gateway's traffic through with rules (d)
610 and (e). If the routes to the remote differ for the two
611 switches, we will not know the MAC address of the alternate
618 Suggestions to improve Open vSwitch are welcome at discuss@openvswitch.org.