EVPN spec changes to address few extra use-cases for NAT
[netvirt.git] / docs / specs / conntrack-based-snat.rst
1 .. contents:: Table of Contents
2    :depth: 3
3
4 ====================
5 Conntrack Based SNAT
6 ====================
7
8 https://git.opendaylight.org/gerrit/#/q/topic:snat_conntrack
9
10 The ovs conntrack based SNAT implements Source Network Address Translation using openflow rules by
11 leveraging ovs-netfilter integration.
12
13 Problem description
14 ===================
15
16 Today SNAT is done in Opendaylight netvirt using controller punting and thus controller installing
17 the rules for inbound and outbound NAPT. This causes significant delay as the first packet of all
18 the new connections needs to go through the controller.The number of flows grows linearly with the
19 increase in the vms. Also the current implementation does not support ICMP.
20
21 Use Cases
22 ---------
23 The following use case will be realized by the implementation
24
25 External Network Access
26 The SNAT enables the VM in a tenant network access the external network without using a floating ip. It
27 uses NAPT for sharing the external ip address across multiple VMs that share the same router
28 gateway.
29
30 Proposed change
31 ===============
32
33 The proposed implementation uses linux netfilter framework to do the NAPT (Network Address Port
34 Translation) and for tracking the connection. The first packet of  a traffic will be committed to
35 the netfilter for translation along with the external ip. The subsequent packets will use the entry
36 in the netfilter for inbound and outbound translation. The router id will be used as the zone id in
37 the netfilter. Each zone tracks the connection in its own table. The rest of the implementation for
38 selecting the designated NAPT switch and non designated switches will remain the same. The pipeline
39 changes will happen in the designated switch. With this implementation we will be able to do
40 translation for icmp as well.
41
42 The openflow plugin needs to support new set of actions for conntrack based NAPT. This shall be
43 added in the nicira plugin extension of OpenFlow plugin.
44
45 The new implementation will not re-install the existing NAT entries to the new NAPT switch during
46 fail-over.  Also spec does not cover the use case of having multiple external subnets in the same
47 router.
48
49 Pipeline changes
50 ----------------
51 The ovs based NAPT flows will replace the controller based NAPT flows. The changes are limited
52 to the designated switch for the router. The NAPT INBOUND Table is changed from table 44 to 43
53 for both the implementation. Below is the illustration for flat external network.
54
55 Outbound NAPT
56
57 Table 26 (PSNAT Table)  => submits the packet to netfilter to check whether it is an existing
58 connection. Resubmits the packet back to 46.
59
60 Table 44 => The metadata will be swapped here to that of the external network and packet will
61 be send to table 47.
62
63 Table 46 (NAPT OUTBOUND TABLE) => if it is an established connection which indicates the
64 translation is done and the packet is forwarded to table 44.
65 If it is a new connection the connection will be committed to netfilter and this entry will be
66 used for napt. The translated packet will be resubmitted to table 44.
67
68 Table 47 (NAPT FIB TABLE) => The translated packet will be sent to the egress group.
69
70 Sample Flows
71
72 ::
73
74  table=26, priority=5,ip,metadata=0x222e2/0xfffffffe actions=ct(table=46,zone=5003,nat)
75  table=44, priority=5,ct_state=+snat,ip,metadata=0x222e2/0xfffffffe,nw_src=192.168.111.21 actions=write_metadata:0x222e0/0xfffffffe,goto_table:47
76  table=46, priority=6,ct_state=+snat,ip actions=resubmit(,44)
77  table=46, priority=5,ct_state=+new+trk,ip,metadata=0x222e2/0xfffffffe actions=ct(commit,table=44,zone=5003,nat(src=192.168.111.21))
78  table=47, priority=6,ct_state=+snat,ip,nw_src=192.168.111.21 actions=group:200003
79
80 Inbound NAPT
81
82 Table 43 (NAPT INBOUND Table)=> submits the packet to netfilter to check for an existing
83 connection. The packet will be submitted back to table 44.
84
85 Table 44 => The metadata will be swapped here to that of the internal network and packet will
86 be send to table 47.
87
88 Table 47 (NAPT FIB TABLE) => The translated packet will be sent to table 43 for writing the
89 appropriate metadata and will be submitted back to table 21.
90
91 Sample Flows
92
93 ::
94
95  table=21, priority=42,ip,metadata=0x222e0/0xfffffffe,nw_dst=192.168.111.21 actions=resubmit(,43)
96  table=43, priority=10,ip actions=ct(table=44,zone=5003,nat)
97  table=44, priority=5,ct_state=+dnat,ip,metadata=0x222e0/0xfffffffe actions=write_metadata:0x222e2/0xfffffffe,goto_table:47
98  table=47, priority=5,ct_state=+dnat,ip actions=resubmit(,21)
99
100 Yang changes
101 ------------
102 The nicira-action.yang and the openflowplugin-extension-nicira-action.yang needs to be updated
103 with nat action. The action structure shall be
104
105 ::
106
107   typedef nx-action-nat-range-present {
108       type enumeration {
109           enum NX_NAT_RANGE_IPV4_MIN {
110               value 1;
111               description "IPV4 minimum value is present";
112           }
113           enum NX_NAT_RANGE_IPV4_MAX {
114               value 2;
115               description "IPV4 maximum value is present";
116           }
117           enum NX_NAT_RANGE_IPV6_MIN {
118               value 4;
119               description "IPV6 minimum value is present in range";
120           }
121           enum NX_NAT_RANGE_IPV6_MAX {
122               value 8;
123               description "IPV6 maximum value is present in range";
124           }
125           enum NX_NAT_RANGE_PROTO_MIN {
126               value 16;
127               description "Port minimum value is present in range";
128           }
129           enum NX_NAT_RANGE_PROTO_MAX {
130               value 32;
131               description "Port maximum value is present in range";
132           }
133       }
134    }
135
136   typedef nx-action-nat-flags {
137       type enumeration {
138           enum NX_NAT_F_SRC {
139               value 1;
140               description "Source nat is selected ,Mutually exclusive with NX_NAT_F_DST";
141           }
142           enum NX_NAT_F_DST {
143               value 2;
144               description "Destination nat is selected";
145           }
146           enum NX_NAT_F_PERSISTENT {
147               value 4;
148               description "Persistent flag is selected";
149           }
150           enum NX_NAT_F_PROTO_HASH {
151               value 8;
152               description "Hash mode is selected for port mapping, Mutually exclusive with
153               NX_NAT_F_PROTO_RANDOM ";
154           }
155           enum NX_NAT_F_PROTO_RANDOM {
156               value 16;
157               description "Port mapping will be randomized";
158           }
159       }
160    }
161
162   grouping ofj-nx-action-conntrack-grouping {
163       container nx-action-conntrack {
164           leaf flags {
165               type uint16;
166           }
167           leaf zone-src {
168               type uint32;
169           }
170           leaf conntrack-zone {
171               type uint16;
172           }
173           leaf recirc-table {
174               type uint8;
175           }
176           leaf experimenter-id {
177               type oft:experimenter-id;
178           }
179           list ct-actions{
180               uses ofpact-actions;
181           }
182       }
183    }
184
185   grouping ofpact-actions {
186       description
187          "Actions to be performed with conntrack.";
188       choice ofpact-actions {
189            case nx-action-nat-case {
190               container nx-action-nat {
191                   leaf flags {
192                       type uint16;
193                   }
194                   leaf range_present {
195                       type uint16;
196                   }
197                   leaf ip-address-min {
198                       type inet:ip-address;
199                   }
200                   leaf ip-address-max {
201                       type inet:ip-address;
202                   }
203                   leaf port-min {
204                       type uint16;
205                   }
206                   leaf port-max {
207                       type uint16;
208                   }
209               }
210           }
211       }
212   }
213
214 Configuration impact
215 --------------------
216 The proposed change requires the NAT service to provide a configuration knob to switch between the
217 controller based/conntrack based implementation. A new configuration file shall be added for this.
218
219 Clustering considerations
220 -------------------------
221 NA
222
223 Other Infra considerations
224 --------------------------
225 The implementation requires ovs2.6 with the kernel module installed. OVS currently does not support
226 SNAT connection tracking for dpdk datapath. It would be supported in some future release.
227
228 Security considerations
229 -----------------------
230 NA
231
232 Scale and Performance Impact
233 ----------------------------
234 The new SNAT implementation is expected to improve the performance when compared to the existing
235 one and will reduce the flows in ovs pipeline.
236
237 Targeted Release
238 ----------------
239 Carbon
240
241 Alternatives
242 ------------
243 An alternative implementation of X NAPT switches was discussed, which will not be a part of this
244 document but will be considered as a further enhancement.
245
246 Usage
247 =====
248
249 Create External Network
250 -----------------------
251 Create an external flat network and subnet
252
253 ::
254
255  neutron net-create ext1 --router:external  --provider:physical_network public --provider:network_type flat
256  neutron subnet-create --allocation-pool start=<start-ip>,end=<end-ip> --gateway=<gw-ip> --disable-dhcp --name subext1 ext1 <subnet-cidr>
257
258 Create Internal Network
259 -----------------------
260 Create an internal n/w and subnet
261
262 ::
263
264  neutron net-create vx-net1 --provider:network_type vxlan
265  neutron subnet-create vx-net1 <subnet-cidr> --name vx-subnet1
266
267 Create Router
268 -------------
269 Create a router and add an interface to internal n/w. Set the external n/w as the router gateway.
270
271 ::
272
273  neutron router-create router1
274  neutron router-interface-add  router1 vx-subnet1
275  neutron router-gateway-set router1 ext1
276  nova boot --poll --flavor m1.tiny --image $(nova image-list | grep 'uec\s' | awk '{print $2}' | tail -1) --nic net-id=$(neutron net-list | grep -w vx-net1 | awk '{print $2}') vmvx2
277
278 Features to Install
279 -------------------
280 odl-netvirt-openstack
281
282 REST API
283 --------
284 NA
285
286 CLI
287 ---
288 NA
289
290 Implementation
291 ==============
292
293 Assignee(s)
294 -----------
295 Aswin Suryanarayanan <asuryana@redhat.com>
296
297 Work Items
298 ----------
299 https://trello.com/c/DMLsrLfq/9-snat-decentralized-ovs-nat-based
300
301 * Write a framework which can support multiple modes of NAT implementation.
302 * Add support in openflow plugin for conntrack nat actions.
303 * Add support in genius for conntrack nat actions.
304 * Add a config parameter to select between controller based and conntrack based.
305 * Add the flow programming for SNAT in netvirt.
306 * Write Unit tests for conntrack based snat.
307
308 Dependencies
309 ============
310 NA
311
312 Testing
313 =======
314
315
316 Unit Tests
317 ----------
318 Unit test needs to be added for the new snat mode. It shall use the component tests framework
319
320 Integration Tests
321 -----------------
322 Integration tests needs to be added for the conntrack snat flows.
323
324 CSIT
325 ----
326 Run the CSIT with conntrack based SNAT configured.
327
328 Documentation Impact
329 ====================
330 Necessary documentation would be added on how to use this feature.
331
332 References
333 ==========