ovn-northd: Introduce stateful table.
[cascardo/ovs.git] / ovn / northd / ovn-northd.8.xml
1 <?xml version="1.0" encoding="utf-8"?>
2 <manpage program="ovn-northd" section="8" title="ovn-northd">
3     <h1>Name</h1>
4     <p>ovn-northd -- Open Virtual Network central control daemon</p>
5
6     <h1>Synopsis</h1>
7     <p><code>ovn-northd</code> [<var>options</var>]</p>
8
9     <h1>Description</h1>
10     <p>
11       <code>ovn-northd</code> is a centralized daemon responsible for
12       translating the high-level OVN configuration into logical
13       configuration consumable by daemons such as
14       <code>ovn-controller</code>.  It translates the logical network
15       configuration in terms of conventional network concepts, taken
16       from the OVN Northbound Database (see <code>ovn-nb</code>(5)),
17       into logical datapath flows in the OVN Southbound Database (see
18       <code>ovn-sb</code>(5)) below it.
19     </p>
20
21     <h1>Configuration</h1>
22     <p>
23       <code>ovn-northd</code> requires a connection to the Northbound
24       and Southbound databases.  The defaults are <code>ovnnb_db.sock</code>
25       and <code>ovnsb_db.sock</code> respectively
26       in the local Open vSwitch's "run" directory.  This may be
27       overridden with the following commands:
28     </p>
29     <ul>
30       <li>
31         <p>
32           <code>--ovnnb-db=<var>database</var></code>
33         </p>
34         <p>
35           The database containing the OVN Northbound Database.
36         </p>
37       </li>
38       <li>
39         <p>
40           <code>--ovnsb-db=<var>database</var></code>
41         </p>
42         <p>
43           The database containing the OVN Southbound Database.
44         </p>
45       </li>
46     </ul>
47     <p>
48       The <var>database</var> argument must take one of the following forms:
49     </p>
50     <ul>
51       <li>
52         <p>
53           <code>ssl:<var>ip</var>:<var>port</var></code>
54         </p>
55         <p>
56           The specified SSL <var>port</var> on the host at the given
57           <var>ip</var>, which must be expressed as an IP address (not a DNS
58           name) in IPv4 or IPv6 address format.  If <var>ip</var> is an IPv6
59           address, then wrap <var>ip</var> with square brackets, e.g.:
60           <code>ssl:[::1]:6640</code>.  The <code>--private-key</code>,
61           <code>--certificate</code>, and <code>--ca-cert</code> options are
62           mandatory when this form is used.
63         </p>
64       </li>
65       <li>
66         <p>
67           <code>tcp:<var>ip</var>:<var>port</var></code>
68         </p>
69         <p>
70           Connect to the given TCP <var>port</var> on <var>ip</var>, where
71           <var>ip</var> can be IPv4 or IPv6 address. If <var>ip</var> is an
72           IPv6 address, then wrap <var>ip</var> with square brackets, e.g.:
73           <code>tcp:[::1]:6640</code>.
74         </p>
75       </li>
76       <li>
77         <p>
78           <code>unix:<var>file</var></code>
79         </p>
80         <p>
81           On POSIX, connect to the Unix domain server socket named
82           <var>file</var>.
83         </p>
84         <p>
85           On Windows, connect to a localhost TCP port whose value is written
86           in <var>file</var>.
87         </p>
88       </li>
89     </ul>
90
91     <h1>Runtime Management Commands</h1>
92     <p>
93       <code>ovs-appctl</code> can send commands to a running
94       <code>ovn-northd</code> process.  The currently supported commands
95       are described below.
96       <dl>
97       <dt><code>exit</code></dt>
98       <dd>
99         Causes <code>ovn-northd</code> to gracefully terminate.
100       </dd>
101       </dl>
102     </p>
103
104     <h1>Logical Flow Table Structure</h1>
105
106     <p>
107       One of the main purposes of <code>ovn-northd</code> is to populate the
108       <code>Logical_Flow</code> table in the <code>OVN_Southbound</code>
109       database.  This section describes how <code>ovn-northd</code> does this
110       for switch and router logical datapaths.
111     </p>
112
113     <h2>Logical Switch Datapaths</h2>
114
115     <h3>Ingress Table 0: Admission Control and Ingress Port Security - L2</h3>
116
117     <p>
118       Ingress table 0 contains these logical flows:
119     </p>
120
121     <ul>
122       <li>
123         Priority 100 flows to drop packets with VLAN tags or multicast Ethernet
124         source addresses.
125       </li>
126
127       <li>
128         Priority 50 flows that implement ingress port security for each enabled
129         logical port.  For logical ports on which port security is enabled,
130         these match the <code>inport</code> and the valid <code>eth.src</code>
131         address(es) and advance only those packets to the next flow table.  For
132         logical ports on which port security is not enabled, these advance all
133         packets that match the <code>inport</code>.
134       </li>
135     </ul>
136
137     <p>
138       There are no flows for disabled logical ports because the default-drop
139       behavior of logical flow tables causes packets that ingress from them to
140       be dropped.
141     </p>
142
143     <h3>Ingress Table 1: Ingress Port Security - IP</h3>
144
145     <p>
146       Ingress table 1 contains these logical flows:
147     </p>
148
149     <ul>
150       <li>
151         <p>
152           For each element in the port security set having one or more IPv4 or
153           IPv6 addresses (or both),
154         </p>
155
156         <ul>
157           <li>
158             Priority 90 flow to allow IPv4 traffic if it has IPv4 addresses
159             which match the <code>inport</code>, valid <code>eth.src</code>
160             and valid <code>ip4.src</code> address(es).
161           </li>
162
163           <li>
164             Priority 90 flow to allow IPv4 DHCP discovery traffic if it has a
165             valid <code>eth.src</code>. This is necessary since DHCP discovery
166             messages are sent from the unspecified IPv4 address (0.0.0.0) since
167             the IPv4 address has not yet been assigned.
168           </li>
169
170           <li>
171             Priority 90 flow to allow IPv6 traffic if it has IPv6 addresses
172             which match the <code>inport</code>, valid <code>eth.src</code> and
173             valid <code>ip6.src</code> address(es).
174           </li>
175
176           <li>
177             Priority 90 flow to allow IPv6 DAD (Duplicate Address Detection)
178             traffic if it has a valid <code>eth.src</code>. This is is
179             necessary since DAD include requires joining an multicast group and
180             sending neighbor solicitations for the newly assigned address. Since
181             no address is yet assigned, these are sent from the unspecified
182             IPv6 address (::).
183           </li>
184
185           <li>
186             Priority 80 flow to drop IP (both IPv4 and IPv6) traffic which
187             match the <code>inport</code> and valid <code>eth.src</code>.
188           </li>
189         </ul>
190       </li>
191
192       <li>
193         One priority-0 fallback flow that matches all packets and advances to
194         the next table.
195       </li>
196     </ul>
197
198     <h3>Ingress Table 2: Ingress Port Security - Neighbor discovery</h3>
199
200     <p>
201       Ingress table 2 contains these logical flows:
202     </p>
203
204     <ul>
205       <li>
206         <p>
207           For each element in the port security set,
208         </p>
209
210         <ul>
211           <li>
212             Priority 90 flow to allow ARP traffic which match the
213             <code>inport</code> and valid <code>eth.src</code> and
214             <code>arp.sha</code>. If the element has one or more
215             IPv4 addresses, then it also matches the valid
216             <code>arp.spa</code>.
217           </li>
218
219           <li>
220             Priority 90 flow to allow IPv6 Neighbor Solicitation and
221             Advertisement traffic which match the <code>inport</code>,
222             valid <code>eth.src</code> and
223             <code>nd.sll</code>/<code>nd.tll</code>.
224             If the element has one or more IPv6 addresses, then it also
225             matches the valid <code>nd.target</code> address(es) for Neighbor
226             Advertisement traffic.
227           </li>
228
229           <li>
230             Priority 80 flow to drop ARP and IPv6 Neighbor Solicitation and
231             Advertisement traffic which match the <code>inport</code> and
232             valid <code>eth.src</code>.
233           </li>
234         </ul>
235       </li>
236
237       <li>
238         One priority-0 fallback flow that matches all packets and advances to
239         the next table.
240       </li>
241     </ul>
242
243     <h3>Ingress Table 3: <code>from-lport</code> Pre-ACLs</h3>
244
245     <p>
246       This table prepares flows for possible stateful ACL processing in
247       ingress table <code>ACLs</code>.  It contains a priority-0 flow that
248       simply moves traffic to the next table.  If stateful ACLs are used in the
249       logical datapath, a priority-100 flow is added that sets a hint
250       (with <code>reg0[0] = 1; next;</code>) for table
251       <code>Pre-stateful</code> to send IP packets to the connection tracker
252       before eventually advancing to ingress table <code>ACLs</code>.
253     </p>
254
255     <h3>Ingress Table 4: Pre-stateful</h3>
256
257     <p>
258       This table prepares flows for all possible stateful processing
259       in next tables.  It contains a priority-0 flow that simply moves
260       traffic to the next table.  A priority-100 flow sends the packets to
261       connection tracker based on a hint provided by the previous tables
262       (with a match for <code>reg0[0] == 1</code>) by using the
263       <code>ct_next;</code> action.
264     </p>
265
266     <h3>Ingress table 5: <code>from-lport</code> ACLs</h3>
267
268     <p>
269       Logical flows in this table closely reproduce those in the
270       <code>ACL</code> table in the <code>OVN_Northbound</code> database
271       for the <code>from-lport</code> direction.  <code>allow</code>
272       ACLs translate into logical flows with the <code>next;</code>
273       action, <code>allow-related</code> ACLs translate into logical
274       flows with the <code>reg0[1] = 1; next;</code> actions (which acts
275       as a hint for the next tables to commit the connection to conntrack),
276       other ACLs translate to <code>drop;</code>.  The <code>priority</code>
277       values from the <code>ACL</code> table have a limited range and have 1000
278       added to them to leave room for OVN default flows at both higher
279       and lower priorities.
280     </p>
281
282     <p>
283       This table also contains a priority 0 flow with action
284       <code>next;</code>, so that ACLs allow packets by default.  If the
285       logical datapath has a statetful ACL, the following flows will
286       also be added:
287     </p>
288
289     <ul>
290       <li>
291         A priority-1 flow that sets the hint to commit IP traffic to the
292         connection tracker (with action <code>reg0[1] = 1; next;</code>).  This
293         is needed for the default allow policy because, while the initiator's
294         direction may not have any stateful rules, the server's may and then
295         its return traffic would not be known and marked as invalid.
296       </li>
297
298       <li>
299         A priority-65535 flow that allows any traffic that has been
300         committed to the connection tracker (i.e., established flows).
301       </li>
302
303       <li>
304         A priority-65535 flow that allows any traffic that is considered
305         related to a committed flow in the connection tracker (e.g., an
306         ICMP Port Unreachable from a non-listening UDP port).
307       </li>
308
309       <li>
310         A priority-65535 flow that drops all traffic marked by the
311         connection tracker as invalid.
312       </li>
313     </ul>
314
315     <h3>Ingress Table 6: Stateful</h3>
316
317     <p>
318       It contains a priority-0 flow that simply moves traffic to the next
319       table.  A priority-100 flow commits packets to connection tracker using
320       <code>ct_commit; next;</code> action based on a hint provided by
321       the previous tables (with a match for <code>reg0[1] == 1</code>).
322     </p>
323
324     <h3>Ingress Table 7: ARP responder</h3>
325
326     <p>
327       This table implements ARP responder for known IPs.  It contains these
328       logical flows:
329     </p>
330
331     <ul>
332       <li>
333         Priority-100 flows to skip ARP responder if inport is of type
334         <code>localnet</code>, and advances directly to the next table.
335       </li>
336
337       <li>
338         <p>
339           Priority-50 flows that matches ARP requests to each known IP address
340           <var>A</var> of logical port <var>P</var>, and respond with ARP
341           replies directly with corresponding Ethernet address <var>E</var>:
342         </p>
343
344         <pre>
345 eth.dst = eth.src;
346 eth.src = <var>E</var>;
347 arp.op = 2; /* ARP reply. */
348 arp.tha = arp.sha;
349 arp.sha = <var>E</var>;
350 arp.tpa = arp.spa;
351 arp.spa = <var>A</var>;
352 outport = <var>P</var>;
353 inport = ""; /* Allow sending out inport. */
354 output;
355         </pre>
356
357         <p>
358           These flows are omitted for logical ports (other than router ports)
359           that are down.
360         </p>
361       </li>
362
363       <li>
364         One priority-0 fallback flow that matches all packets and advances to
365         the next table.
366       </li>
367     </ul>
368
369     <h3>Ingress Table 8: Destination Lookup</h3>
370
371     <p>
372       This table implements switching behavior.  It contains these logical
373       flows:
374     </p>
375
376     <ul>
377       <li>
378         A priority-100 flow that outputs all packets with an Ethernet broadcast
379         or multicast <code>eth.dst</code> to the <code>MC_FLOOD</code>
380         multicast group, which <code>ovn-northd</code> populates with all
381         enabled logical ports.
382       </li>
383
384       <li>
385         One priority-50 flow that matches each known Ethernet address against
386         <code>eth.dst</code> and outputs the packet to the single associated
387         output port.
388       </li>
389
390       <li>
391         One priority-0 fallback flow that matches all packets and outputs them
392         to the <code>MC_UNKNOWN</code> multicast group, which
393         <code>ovn-northd</code> populates with all enabled logical ports that
394         accept unknown destination packets.  As a small optimization, if no
395         logical ports accept unknown destination packets,
396         <code>ovn-northd</code> omits this multicast group and logical flow.
397       </li>
398     </ul>
399
400     <h3>Egress Table 0: <code>to-lport</code> Pre-ACLs</h3>
401
402     <p>
403       This is similar to ingress table <code>Pre-ACLs</code> except for
404      <code>to-lport</code> traffic.
405     </p>
406
407     <h3>Egress Table 1: Pre-stateful</h3>
408
409     <p>
410       This is similar to ingress table <code>Pre-stateful</code>.
411     </p>
412
413     <h3>Egress Table 2: <code>to-lport</code> ACLs</h3>
414
415     <p>
416       This is similar to ingress table <code>ACLs</code> except for
417       <code>to-lport</code> ACLs.
418     </p>
419
420     <h3>Egress Table 3: Stateful</h3>
421
422     <p>
423       This is similar to ingress table <code>Stateful</code>.
424     </p>
425
426     <h3>Egress Table 4: Egress Port Security - IP</h3>
427
428     <p>
429       This is similar to the port security logic in table
430       <code>Ingress Port Security - IP</code> except that <code>outport</code>,
431       <code>eth.dst</code>, <code>ip4.dst</code> and <code>ip6.dst</code>
432       are checked instead of <code>inport</code>, <code>eth.src</code>,
433       <code>ip4.src</code> and <code>ip6.src</code>
434     </p>
435
436     <h3>Egress Table 5: Egress Port Security - L2</h3>
437
438     <p>
439       This is similar to the ingress port security logic in ingress table
440       <code>Admission Control and Ingress Port Security - L2</code>,
441       but with important differences.  Most obviously, <code>outport</code> and
442       <code>eth.dst</code> are checked instead of <code>inport</code> and
443       <code>eth.src</code>.  Second, packets directed to broadcast or multicast
444       <code>eth.dst</code> are always accepted instead of being subject to the
445       port security rules; this is implemented through a priority-100 flow that
446       matches on <code>eth.mcast</code> with action <code>output;</code>.
447       Finally, to ensure that even broadcast and multicast packets are not
448       delivered to disabled logical ports, a priority-150 flow for each
449       disabled logical <code>outport</code> overrides the priority-100 flow
450       with a <code>drop;</code> action.
451     </p>
452
453     <h2>Logical Router Datapaths</h2>
454
455     <p>
456       Logical router datapaths will only exist for <ref table="Logical_Router"
457       db="OVN_Northbound"/> rows in the <ref db="OVN_Northbound"/> database
458       that do not have <ref column="enabled" table="Logical_Router"
459       db="OVN_Northbound"/> set to <code>false</code>
460     </p>
461
462     <h3>Ingress Table 0: L2 Admission Control</h3>
463
464     <p>
465       This table drops packets that the router shouldn't see at all based on
466       their Ethernet headers.  It contains the following flows:
467     </p>
468
469     <ul>
470       <li>
471         Priority-100 flows to drop packets with VLAN tags or multicast Ethernet
472         source addresses.
473       </li>
474
475       <li>
476         For each enabled router port <var>P</var> with Ethernet address
477         <var>E</var>, a priority-50 flow that matches <code>inport ==
478         <var>P</var> &amp;&amp; (eth.mcast || eth.dst ==
479         <var>E</var></code>), with action <code>next;</code>.
480       </li>
481     </ul>
482
483     <p>
484       Other packets are implicitly dropped.
485     </p>
486
487     <h3>Ingress Table 1: IP Input</h3>
488
489     <p>
490       This table is the core of the logical router datapath functionality.  It
491       contains the following flows to implement very basic IP host
492       functionality.
493     </p>
494
495     <ul>
496       <li>
497         <p>
498           L3 admission control: A priority-100 flow drops packets that match
499           any of the following:
500         </p>
501
502         <ul>
503           <li>
504             <code>ip4.src[28..31] == 0xe</code> (multicast source)
505           </li>
506           <li>
507             <code>ip4.src == 255.255.255.255</code> (broadcast source)
508           </li>
509           <li>
510             <code>ip4.src == 127.0.0.0/8 || ip4.dst == 127.0.0.0/8</code>
511             (localhost source or destination)
512           </li>
513           <li>
514             <code>ip4.src == 0.0.0.0/8 || ip4.dst == 0.0.0.0/8</code> (zero
515             network source or destination)
516           </li>
517           <li>
518             <code>ip4.src</code> is any IP address owned by the router.
519           </li>
520           <li>
521             <code>ip4.src</code> is the broadcast address of any IP network
522             known to the router.
523           </li>
524         </ul>
525       </li>
526
527       <li>
528         <p>
529           ICMP echo reply.  These flows reply to ICMP echo requests received
530           for the router's IP address.  Let <var>A</var> be an IP address
531           owned by a router port.  Then, for each <var>A</var>, a priority-90
532           flow matches on <code>ip4.dst == <var>A</var></code> and <code>
533           icmp4.type == 8 &amp;&amp; icmp4.code == 0</code> (ICMP echo
534           request).  The port of the router that receives the echo request
535           does not matter. Also, the ip.ttl of the echo request packet is not
536           checked, so it complies with RFC 1812, section 4.2.2.9. These flows
537           use the following actions where <var>S</var> is the router's IP
538           address:
539         </p>
540
541         <pre>
542 ip4.dst = ip4.src;
543 ip4.src = <var>S</var>;
544 ip.ttl = 255;
545 icmp4.type = 0;
546 inport = ""; /* Allow sending out inport. */
547 next;
548         </pre>
549       </li>
550
551       <li>
552         <p>
553           Reply to ARP requests.
554         </p>
555
556         <p>
557           These flows reply to ARP requests for the router's own IP address.
558           For each router port <var>P</var> that owns IP address <var>A</var>
559           and Ethernet address <var>E</var>, a priority-90 flow matches
560           <code>inport == <var>P</var> &amp;&amp; arp.op == 1 &amp;&amp;
561           arp.tpa == <var>A</var></code> (ARP request) with the following
562           actions:
563         </p>
564
565         <pre>
566 eth.dst = eth.src;
567 eth.src = <var>E</var>;
568 arp.op = 2; /* ARP reply. */
569 arp.tha = arp.sha;
570 arp.sha = <var>E</var>;
571 arp.tpa = arp.spa;
572 arp.spa = <var>A</var>;
573 outport = <var>P</var>;
574 inport = ""; /* Allow sending out inport. */
575 output;
576         </pre>
577       </li>
578
579       <li>
580         <p>
581           These flows reply to ARP requests for the virtual IP addresses
582           configured in the router for DNAT. For a configured DNAT IP address
583           <var>A</var>, for each router port <var>P</var> with Ethernet
584           address <var>E</var>, a priority-90 flow matches
585           <code>inport == <var>P</var> &amp;&amp; arp.op == 1 &amp;&amp;
586           arp.tpa == <var>A</var></code> (ARP request)
587           with the following actions:
588         </p>
589
590         <pre>
591 eth.dst = eth.src;
592 eth.src = <var>E</var>;
593 arp.op = 2; /* ARP reply. */
594 arp.tha = arp.sha;
595 arp.sha = <var>E</var>;
596 arp.tpa = arp.spa;
597 arp.spa = <var>A</var>;
598 outport = <var>P</var>;
599 inport = ""; /* Allow sending out inport. */
600 output;
601         </pre>
602       </li>
603
604       <li>
605         ARP reply handling.  These flows use ARP replies to populate the
606         logical router's ARP table.  A priority-90 flow with match <code>arp.op
607         == 2</code> has actions <code>put_arp(inport, arp.spa,
608         arp.sha);</code>.
609       </li>
610
611       <li>
612         <p>
613           UDP port unreachable.  Priority-80 flows generate ICMP port
614           unreachable messages in reply to UDP datagrams directed to the
615           router's IP address.  The logical router doesn't accept any UDP
616           traffic so it always generates such a reply.
617         </p>
618
619         <p>
620           These flows should not match IP fragments with nonzero offset.
621         </p>
622
623         <p>
624           Details TBD.  Not yet implemented.
625         </p>
626       </li>
627
628       <li>
629         <p>
630           TCP reset.  Priority-80 flows generate TCP reset messages in reply to
631           TCP datagrams directed to the router's IP address.  The logical
632           router doesn't accept any TCP traffic so it always generates such a
633           reply.
634         </p>
635
636         <p>
637           These flows should not match IP fragments with nonzero offset.
638         </p>
639
640         <p>
641           Details TBD.  Not yet implemented.
642         </p>
643       </li>
644
645       <li>
646         <p>
647           Protocol unreachable.  Priority-70 flows generate ICMP protocol
648           unreachable messages in reply to packets directed to the router's IP
649           address on IP protocols other than UDP, TCP, and ICMP.
650         </p>
651
652         <p>
653           These flows should not match IP fragments with nonzero offset.
654         </p>
655
656         <p>
657           Details TBD.  Not yet implemented.
658         </p>
659       </li>
660
661       <li>
662         Drop other IP traffic to this router.  These flows drop any other
663         traffic destined to an IP address of this router that is not already
664         handled by one of the flows above, which amounts to ICMP (other than
665         echo requests) and fragments with nonzero offsets.  For each IP address
666         <var>A</var> owned by the router, a priority-60 flow matches
667         <code>ip4.dst == <var>A</var></code> and drops the traffic.  An
668         exception is made and the above flow is not added if the router
669         port's own IP address is used to SNAT packets passing through that
670         router.
671       </li>
672     </ul>
673
674     <p>
675       The flows above handle all of the traffic that might be directed to the
676       router itself.  The following flows (with lower priorities) handle the
677       remaining traffic, potentially for forwarding:
678     </p>
679
680     <ul>
681       <li>
682         Drop Ethernet local broadcast.  A priority-50 flow with match
683         <code>eth.bcast</code> drops traffic destined to the local Ethernet
684         broadcast address.  By definition this traffic should not be forwarded.
685       </li>
686
687       <li>
688         Drop IP multicast.  A priority-50 flow with match
689         <code>ip4.mcast</code> drops IP multicast traffic.
690       </li>
691
692       <li>
693         <p>
694           ICMP time exceeded.  For each router port <var>P</var>, whose IP
695           address is <var>A</var>, a priority-40 flow with match <code>inport
696           == <var>P</var> &amp;&amp; ip.ttl == {0, 1} &amp;&amp;
697           !ip.later_frag</code> matches packets whose TTL has expired, with the
698           following actions to send an ICMP time exceeded reply:
699         </p>
700
701         <pre>
702 icmp4 {
703     icmp4.type = 11; /* Time exceeded. */
704     icmp4.code = 0;  /* TTL exceeded in transit. */
705     ip4.dst = ip4.src;
706     ip4.src = <var>A</var>;
707     ip.ttl = 255;
708     next;
709 };
710         </pre>
711
712         <p>
713           Not yet implemented.
714         </p>
715       </li>
716
717       <li>
718         TTL discard.  A priority-30 flow with match <code>ip.ttl == {0,
719         1}</code> and actions <code>drop;</code> drops other packets whose TTL
720         has expired, that should not receive a ICMP error reply (i.e. fragments
721         with nonzero offset).
722       </li>
723
724       <li>
725         Next table.  A priority-0 flows match all packets that aren't already
726         handled and uses actions <code>next;</code> to feed them to the ingress
727         table for routing.
728       </li>
729     </ul>
730
731     <h3>Ingress Table 2: UNSNAT</h3>
732
733     <p>
734       This is for already established connections' reverse traffic.
735       i.e., SNAT has already been done in egress pipeline and now the
736       packet has entered the ingress pipeline as part of a reply.  It is
737       unSNATted here.
738     </p>
739
740     <ul>
741       <li>
742         <p>
743           For each configuration in the OVN Northbound database, that asks
744           to change the source IP address of a packet from <var>A</var> to
745           <var>B</var>, a priority-100 flow matches <code>ip &amp;&amp;
746           ip4.dst == <var>B</var></code> with an action
747           <code>ct_snat; next;</code>.
748         </p>
749
750         <p>
751           A priority-0 logical flow with match <code>1</code> has actions
752           <code>next;</code>.
753         </p>
754       </li>
755     </ul>
756
757     <h3>Ingress Table 3: DNAT</h3>
758
759     <p>
760       Packets enter the pipeline with destination IP address that needs to
761       be DNATted from a virtual IP address to a real IP address.  Packets
762       in the reverse direction needs to be unDNATed.
763     </p>
764     <ul>
765       <li>
766         <p>
767           For each configuration in the OVN Northbound database, that asks
768           to change the destination IP address of a packet from <var>A</var> to
769           <var>B</var>, a priority-100 flow matches <code>ip &amp;&amp;
770           ip4.dst == <var>A</var></code> with an action <code>inport = "";
771           ct_dnat(<var>B</var>);</code>.
772         </p>
773
774         <p>
775           For all IP packets of a Gateway router, a priority-50 flow with an
776           action <code>inport = ""; ct_dnat;</code>.
777         </p>
778
779         <p>
780           A priority-0 logical flow with match <code>1</code> has actions
781           <code>next;</code>.
782         </p>
783       </li>
784     </ul>
785
786     <h3>Ingress Table 4: IP Routing</h3>
787
788     <p>
789       A packet that arrives at this table is an IP packet that should be routed
790       to the address in <code>ip4.dst</code>.  This table implements IP
791       routing, setting <code>reg0</code> to the next-hop IP address (leaving
792       <code>ip4.dst</code>, the packet's final destination, unchanged) and
793       advances to the next table for ARP resolution.  It also sets
794       <code>reg1</code> to the IP address owned by the selected router port
795       (which is used later in table 6 as the IP source address for an ARP
796       request, if needed).
797     </p>
798
799     <p>
800       This table contains the following logical flows:
801     </p>
802
803     <ul>
804       <li>
805         <p>
806           Routing table.  For each route to IPv4 network <var>N</var> with
807           netmask <var>M</var>, on router port <var>P</var> with IP address
808           <var>A</var> and Ethernet
809           address <var>E</var>, a logical flow with match <code>ip4.dst ==
810           <var>N</var>/<var>M</var></code>, whose priority is the number of
811           1-bits in <var>M</var>, has the following actions:
812         </p>
813
814         <pre>
815 ip.ttl--;
816 reg0 = <var>G</var>;
817 reg1 = <var>A</var>;
818 eth.src = <var>E</var>;
819 outport = <var>P</var>;
820 next;
821         </pre>
822
823         <p>
824           (Ingress table 1 already verified that <code>ip.ttl--;</code> will
825           not yield a TTL exceeded error.)
826         </p>
827
828         <p>
829           If the route has a gateway, <var>G</var> is the gateway IP address.
830           Instead, if the route is from a configured static route, <var>G</var>
831           is the next hop IP address.  Else it is <code>ip4.dst</code>.
832         </p>
833       </li>
834
835       <li>
836         <p>
837           Destination unreachable.  For each router port <var>P</var>, which
838           owns IP address <var>A</var>, a priority-0 logical flow with match
839           <code>in_port == <var>P</var> &amp;&amp; !ip.later_frag &amp;&amp;
840           !icmp</code> has the following actions:
841         </p>
842
843         <pre>
844 icmp4 {
845     icmp4.type = 3; /* Destination unreachable. */
846     icmp4.code = 0; /* Network unreachable. */
847     ip4.dst = ip4.src;
848     ip4.src = <var>A</var>;
849     ip.ttl = 255;
850     next(2);
851 };
852         </pre>
853
854         <p>
855           (The <code>!icmp</code> check prevents recursion if the destination
856           unreachable message itself cannot be routed.)
857         </p>
858
859         <p>
860           These flows are omitted if the logical router has a default route,
861           that is, a route with netmask 0.0.0.0.
862         </p>
863       </li>
864     </ul>
865
866     <h3>Ingress Table 5: ARP Resolution</h3>
867
868     <p>
869       Any packet that reaches this table is an IP packet whose next-hop IP
870       address is in <code>reg0</code>.  (<code>ip4.dst</code> is the final
871       destination.)  This table resolves the IP address in <code>reg0</code>
872       into an output port in <code>outport</code> and an Ethernet address in
873       <code>eth.dst</code>, using the following flows:
874     </p>
875
876     <ul>
877       <li>
878         <p>
879           Static MAC bindings.  MAC bindings can be known statically based on
880           data in the <code>OVN_Northbound</code> database.  For router ports
881           connected to logical switches, MAC bindings can be known statically
882           from the <code>addresses</code> column in the
883           <code>Logical_Switch_Port</code> table.  For router ports
884           connected to other logical routers, MAC bindings can be known
885           statically from the <code>mac</code> and <code>network</code>
886           column in the <code>Logical_Router_Port</code> table.
887         </p>
888
889         <p>
890           For each IP address <var>A</var> whose host is known to have Ethernet
891           address <var>E</var> on router port <var>P</var>, a priority-100 flow
892           with match <code>outport === <var>P</var> &amp;&amp; reg0 ==
893           <var>A</var></code> has actions <code>eth.dst = <var>E</var>;
894           next;</code>.
895         </p>
896
897         <p>
898           For each logical router port with an IP address <var>A</var> and
899           a mac address of <var>E</var> that is reachable via a different
900           logical router port <var>P</var>, a priority-100 flow with
901           match <code>outport === <var>P</var> &amp;&amp; reg0 ==
902           <var>A</var></code> has actions <code>eth.dst = <var>E</var>;
903           next;</code>.
904         </p>
905       </li>
906
907       <li>
908         <p>
909           Dynamic MAC bindings.  This flows resolves MAC-to-IP bindings that
910           have become known dynamically through ARP.  (The next table will
911           issue an ARP request for cases where the binding is not yet known.)
912         </p>
913
914         <p>
915           A priority-0 logical flow with match <code>1</code> has actions
916           <code>get_arp(outport, reg0); next;</code>.
917         </p>
918       </li>
919     </ul>
920
921     <h3>Ingress Table 6: ARP Request</h3>
922
923     <p>
924       In the common case where the Ethernet destination has been resolved, this
925       table outputs the packet.  Otherwise, it composes and sends an ARP
926       request.  It holds the following flows:
927     </p>
928
929     <ul>
930       <li>
931         <p>
932           Unknown MAC address.  A priority-100 flow with match <code>eth.dst ==
933           00:00:00:00:00:00</code> has the following actions:
934         </p>
935
936         <pre>
937 arp {
938     eth.dst = ff:ff:ff:ff:ff:ff;
939     arp.spa = reg1;
940     arp.op = 1;  /* ARP request. */
941     output;
942 };
943         </pre>
944
945         <p>
946           (Ingress table 4 initialized <code>reg1</code> with the IP address
947           owned by <code>outport</code>.)
948         </p>
949
950         <p>
951           The IP packet that triggers the ARP request is dropped.
952         </p>
953       </li>
954
955       <li>
956         Known MAC address.  A priority-0 flow with match <code>1</code> has
957         actions <code>output;</code>.
958       </li>
959     </ul>
960
961     <h3>Egress Table 0: SNAT</h3>
962
963     <p>
964       Packets that are configured to be SNATed get their source IP address
965       changed based on the configuration in the OVN Northbound database.
966     </p>
967     <ul>
968       <li>
969         <p>
970           For each configuration in the OVN Northbound database, that asks
971           to change the source IP address of a packet from an IP address of
972           <var>A</var> or to change the source IP address of a packet that
973           belongs to network <var>A</var> to <var>B</var>, a flow matches
974           <code>ip &amp;&amp; ip4.src == <var>A</var></code> with an action
975           <code>ct_snat(<var>B</var>);</code>.  The priority of the flow
976           is calculated based on the mask of <var>A</var>, with matches
977           having larger masks getting higher priorities.
978         </p>
979         <p>
980           A priority-0 logical flow with match <code>1</code> has actions
981           <code>next;</code>.
982         </p>
983       </li>
984     </ul>
985
986     <h3>Egress Table 1: Delivery</h3>
987
988     <p>
989       Packets that reach this table are ready for delivery.  It contains
990       priority-100 logical flows that match packets on each enabled logical
991       router port, with action <code>output;</code>.
992     </p>
993
994 </manpage>