ab3e0a16b472b6b4bd32072c9b1b2b0e0178bf34
[netvirt.git] / natservice / impl / src / main / java / org / opendaylight / netvirt / natservice / internal / ConntrackBasedSnatService.java
1 /*
2  * Copyright (c) 2017 Red Hat, Inc. and others. All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8 package org.opendaylight.netvirt.natservice.internal;
9
10 import com.google.common.base.Optional;
11 import java.math.BigInteger;
12 import java.util.ArrayList;
13 import java.util.List;
14 import java.util.concurrent.ExecutionException;
15 import org.apache.commons.lang3.tuple.ImmutablePair;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.genius.datastoreutils.listeners.DataTreeEventCallbackRegistrar;
18 import org.opendaylight.genius.infra.Datastore.Configuration;
19 import org.opendaylight.genius.infra.TypedReadWriteTransaction;
20 import org.opendaylight.genius.infra.TypedWriteTransaction;
21 import org.opendaylight.genius.interfacemanager.interfaces.IInterfaceManager;
22 import org.opendaylight.genius.mdsalutil.ActionInfo;
23 import org.opendaylight.genius.mdsalutil.InstructionInfo;
24 import org.opendaylight.genius.mdsalutil.MatchInfo;
25 import org.opendaylight.genius.mdsalutil.MatchInfoBase;
26 import org.opendaylight.genius.mdsalutil.MetaDataUtil;
27 import org.opendaylight.genius.mdsalutil.NWUtil;
28 import org.opendaylight.genius.mdsalutil.NwConstants;
29 import org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack;
30 import org.opendaylight.genius.mdsalutil.actions.ActionNxConntrack.NxCtAction;
31 import org.opendaylight.genius.mdsalutil.actions.ActionNxCtClear;
32 import org.opendaylight.genius.mdsalutil.actions.ActionNxLoadInPort;
33 import org.opendaylight.genius.mdsalutil.actions.ActionNxLoadMetadata;
34 import org.opendaylight.genius.mdsalutil.actions.ActionNxResubmit;
35 import org.opendaylight.genius.mdsalutil.actions.ActionSetFieldEthernetSource;
36 import org.opendaylight.genius.mdsalutil.instructions.InstructionApplyActions;
37 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
38 import org.opendaylight.genius.mdsalutil.matches.MatchEthernetType;
39 import org.opendaylight.genius.mdsalutil.matches.MatchIpv4Destination;
40 import org.opendaylight.genius.mdsalutil.matches.MatchMetadata;
41 import org.opendaylight.genius.mdsalutil.nxmatches.NxMatchCtState;
42 import org.opendaylight.netvirt.fibmanager.api.IFibManager;
43 import org.opendaylight.netvirt.natservice.ha.NatDataUtil;
44 import org.opendaylight.netvirt.vpnmanager.api.IVpnFootprintService;
45 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.MacAddress;
46 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.idmanager.rev160406.IdManagerService;
47 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
48 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.itm.rpcs.rev160406.ItmRpcService;
49 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.vpn.instance.op.data.vpn.instance.op.data.entry.vpn.to.dpn.list.IpAddresses;
50 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.Routers;
51 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.ext.routers.routers.ExternalIps;
52 import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.natservice.rev160111.external.subnets.Subnets;
53 import org.opendaylight.yang.gen.v1.urn.opendaylight.neutron.types.rev160517.IpPrefixOrAddressBuilder;
54 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.NxActionNatFlags;
55 import org.opendaylight.yang.gen.v1.urn.opendaylight.openflowjava.nx.action.rev140421.NxActionNatRangePresent;
56 import org.opendaylight.yangtools.yang.common.Uint32;
57 import org.opendaylight.yangtools.yang.common.Uint64;
58 import org.slf4j.Logger;
59 import org.slf4j.LoggerFactory;
60
61 public abstract class ConntrackBasedSnatService extends AbstractSnatService {
62     private static final Logger LOG = LoggerFactory.getLogger(ConntrackBasedSnatService.class);
63
64     protected static final int TRACKED_NEW_CT_STATE = 0x21;
65     protected static final int TRACKED_NEW_CT_MASK = 0x21;
66     protected static final int SNAT_CT_STATE = 0x40;
67     protected static final int SNAT_CT_STATE_MASK = 0x40;
68     protected static final int DNAT_CT_STATE = 0x80;
69     protected static final int DNAT_CT_STATE_MASK = 0x80;
70
71     public ConntrackBasedSnatService(DataBroker dataBroker, IMdsalApiManager mdsalManager, ItmRpcService itmManager,
72                                      IdManagerService idManager, NAPTSwitchSelector naptSwitchSelector,
73                                      OdlInterfaceRpcService odlInterfaceRpcService,
74                                      IInterfaceManager interfaceManager, IVpnFootprintService vpnFootprintService,
75                                      IFibManager fibManager, NatDataUtil natDataUtil,
76                                      DataTreeEventCallbackRegistrar eventCallbacks) {
77         super(dataBroker, mdsalManager, itmManager, odlInterfaceRpcService, idManager, naptSwitchSelector,
78                 interfaceManager, vpnFootprintService, fibManager, natDataUtil, eventCallbacks);
79     }
80
81     @Override
82     protected void addSnatSpecificEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
83         Routers routers, Uint64 dpnId) {
84         LOG.info("installSnatSpecificEntriesForNaptSwitch: called for router {}",
85             routers.getRouterName());
86         String routerName = routers.getRouterName();
87         Uint32 routerId = NatUtil.getVpnId(confTx, routerName);
88         int elanId = NatUtil.getElanInstanceByName(confTx, routers.getNetworkId().getValue())
89             .getElanTag().intValue();
90         if (routerId == NatConstants.INVALID_ID) {
91             LOG.error("InvalidRouterId: unable to installSnatSpecificEntriesForNaptSwitch on dpn {}", dpnId);
92             return;
93         }
94         /* Install Outbound NAT entries */
95
96         addSnatMissEntryForPrimrySwch(confTx, dpnId, routerId, elanId);
97
98         String extGwMacAddress = NatUtil.getExtGwMacAddFromRouterName(confTx, routerName);
99         addOutboundTblTrackEntry(confTx, dpnId, routerId, extGwMacAddress);
100         for (ExternalIps externalIp : routers.nonnullExternalIps()) {
101             if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
102                 // In this class we handle only IPv4 use-cases.
103                 continue;
104             }
105             //The logic now handle only one external IP per router, others if present will be ignored.
106             Uint32 extSubnetId = NatUtil.getExternalSubnetVpnId(confTx, externalIp.getSubnetId());
107             addOutboundTblEntry(confTx, dpnId, routerId, externalIp.getIpAddress(), elanId, extGwMacAddress);
108             addNaptPfibFlow(confTx, routers, dpnId, routerId, extSubnetId);
109
110             //Install Inbound NAT entries
111             addInboundEntry(confTx, dpnId, routerId, externalIp.getIpAddress(), elanId, extSubnetId);
112             addNaptPfibEntry(confTx, dpnId, routerId);
113
114             String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp.getIpAddress());
115             Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(confTx, externalIp.getSubnetId());
116             if (externalSubnet.isPresent()) {
117                 String externalVpn =  externalIp.getSubnetId().getValue();
118                 String vpnRd = NatUtil.getVpnRd(confTx, externalVpn);
119                 vpnFootprintService.updateVpnToDpnMapping(dpnId, externalVpn, vpnRd,
120                         null /* interfaceName*/, new ImmutablePair<>(IpAddresses
121                                 .IpAddressSource.ExternalFixedIP, fibExternalIp), true);
122             }
123             break;
124         }
125     }
126
127     @Override
128     protected void removeSnatSpecificEntriesForNaptSwitch(TypedReadWriteTransaction<Configuration> confTx,
129             Routers routers, Uint64 dpnId) throws ExecutionException, InterruptedException {
130         LOG.info("installSnatSpecificEntriesForNaptSwitch: called for router {}",
131             routers.getRouterName());
132         String routerName = routers.getRouterName();
133         Uint32 routerId = NatUtil.getVpnId(confTx, routerName);
134         if (routerId == NatConstants.INVALID_ID) {
135             LOG.error("InvalidRouterId: unable to installSnatSpecificEntriesForNaptSwitch on dpn {}", dpnId);
136             return;
137         }
138         /* Remove Outbound NAT entries */
139
140         removeSnatMissEntryForPrimrySwch(confTx, dpnId, routerId);
141
142         removeOutboundTblTrackEntry(confTx, dpnId, routerId);
143         for (ExternalIps externalIp : routers.nonnullExternalIps()) {
144             if (!NWUtil.isIpv4Address(externalIp.getIpAddress())) {
145                 // In this class we handle only IPv4 use-cases.
146                 continue;
147             }
148             //The logic now handle only one external IP per router, others if present will be ignored.
149             removeOutboundTblEntry(confTx, dpnId, routerId);
150             removeNaptPfibFlow(confTx, routers, dpnId, routerId);
151
152             //Install Inbound NAT entries
153             removeInboundEntry(confTx, dpnId, routerId);
154             removeNaptPfibEntry(confTx, dpnId, routerId);
155
156             String fibExternalIp = NatUtil.validateAndAddNetworkMask(externalIp.getIpAddress());
157             Optional<Subnets> externalSubnet = NatUtil.getOptionalExternalSubnets(confTx, externalIp.getSubnetId());
158             if (externalSubnet.isPresent()) {
159                 String externalVpn =  externalIp.getSubnetId().getValue();
160                 String vpnRd = NatUtil.getVpnRd(confTx, externalVpn);
161                 vpnFootprintService.updateVpnToDpnMapping(dpnId, externalVpn, vpnRd, null /* interfaceName*/,
162                     new ImmutablePair<>(IpAddresses.IpAddressSource.ExternalFixedIP, fibExternalIp),
163                     false);
164             }
165             break;
166         }
167     }
168
169     @Override
170     protected void addSnatSpecificEntriesForNonNaptSwitch() {
171         // Nothing to to do here
172     }
173
174     @Override
175     protected void removeSnatSpecificEntriesForNonNaptSwitch() {
176         // Nothing to to do here
177     }
178
179     protected void addSnatMissEntryForPrimrySwch(TypedWriteTransaction<Configuration> confTx, Uint64 dpnId,
180                                                  Uint32 routerId, int elanId) {
181         LOG.info("installSnatSpecificEntriesForNaptSwitch : called for the primary NAPT switch dpnId {}", dpnId);
182         List<MatchInfo> matches = new ArrayList<>();
183         matches.add(MatchEthernetType.IPV4);
184         matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId.longValue()),
185                 MetaDataUtil.METADATA_MASK_VRFID));
186         List<InstructionInfo> instructions = new ArrayList<>();
187         List<ActionInfo> actionsInfos = new ArrayList<>();
188         List<NxCtAction> ctActionsList = new ArrayList<>();
189         NxCtAction nxCtAction = new ActionNxConntrack.NxNat(0, 0, 0,null, null,0, 0);
190         ctActionsList.add(nxCtAction);
191         ActionNxConntrack actionNxConntrack = new ActionNxConntrack(0, 0, elanId,
192                 NwConstants.OUTBOUND_NAPT_TABLE,ctActionsList);
193
194         actionsInfos.add(actionNxConntrack);
195         instructions.add(new InstructionApplyActions(actionsInfos));
196
197         String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
198         NatUtil.addFlow(confTx, mdsalManager, dpnId, NwConstants.PSNAT_TABLE, flowRef,
199                 NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches,
200                 instructions);
201     }
202
203     protected void removeSnatMissEntryForPrimrySwch(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId,
204                                                     Uint32 routerId) throws ExecutionException, InterruptedException {
205         LOG.info("installSnatSpecificEntriesForNaptSwitch : called for the primary NAPT switch dpnId {}", dpnId);
206
207         String flowRef = getFlowRef(dpnId, NwConstants.PSNAT_TABLE, routerId);
208         NatUtil.removeFlow(confTx, mdsalManager, dpnId, NwConstants.PSNAT_TABLE, flowRef);
209     }
210
211     protected void addOutboundTblTrackEntry(TypedWriteTransaction<Configuration> confTx, Uint64 dpnId,
212                                             Uint32 routerId, String extGwMacAddress) {
213         LOG.info("createOutboundTblTrackEntry : called for switch {}, routerId {}", dpnId, routerId);
214         List<MatchInfoBase> matches = new ArrayList<>();
215         matches.add(MatchEthernetType.IPV4);
216         matches.add(new NxMatchCtState(SNAT_CT_STATE, SNAT_CT_STATE_MASK));
217         matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId.longValue()),
218                 MetaDataUtil.METADATA_MASK_VRFID));
219         ArrayList<ActionInfo> listActionInfo = new ArrayList<>();
220         listActionInfo.add(new ActionSetFieldEthernetSource(new MacAddress(extGwMacAddress)));
221         ArrayList<InstructionInfo> instructionInfo = new ArrayList<>();
222         listActionInfo.add(new ActionNxResubmit(NwConstants.NAPT_PFIB_TABLE));
223         instructionInfo.add(new InstructionApplyActions(listActionInfo));
224
225         String flowRef = getFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId) + "trkest";
226         NatUtil.addFlow(confTx, mdsalManager, dpnId, NwConstants.OUTBOUND_NAPT_TABLE, flowRef,
227                 NatConstants.SNAT_TRK_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches,
228                 instructionInfo);
229     }
230
231     protected void removeOutboundTblTrackEntry(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId,
232                                                Uint32 routerId) throws ExecutionException, InterruptedException {
233         LOG.info("createOutboundTblTrackEntry : called for switch {}, routerId {}", dpnId, routerId);
234
235         String flowRef = getFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId) + "trkest";
236         NatUtil.removeFlow(confTx, mdsalManager, dpnId, NwConstants.OUTBOUND_NAPT_TABLE, flowRef);
237     }
238
239     protected void addOutboundTblEntry(TypedWriteTransaction<Configuration> confTx, Uint64 dpnId, Uint32 routerId,
240         String externalIp, int elanId, String extGwMacAddress) {
241         LOG.info("createOutboundTblEntry : dpId {} and routerId {}", dpnId, routerId);
242         List<MatchInfoBase> matches = new ArrayList<>();
243         matches.add(MatchEthernetType.IPV4);
244         matches.add(new NxMatchCtState(TRACKED_NEW_CT_STATE, TRACKED_NEW_CT_MASK));
245         matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId.longValue()),
246                 MetaDataUtil.METADATA_MASK_VRFID));
247         List<ActionInfo> actionsInfos = new ArrayList<>();
248         actionsInfos.add(new ActionSetFieldEthernetSource(new MacAddress(extGwMacAddress)));
249         List<NxCtAction> ctActionsListCommit = new ArrayList<>();
250         int rangePresent = NxActionNatRangePresent.NXNATRANGEIPV4MIN.getIntValue();
251         int flags = NxActionNatFlags.NXNATFSRC.getIntValue();
252         NxCtAction nxCtActionCommit = new ActionNxConntrack.NxNat(0, flags, rangePresent,
253             IpPrefixOrAddressBuilder.getDefaultInstance(externalIp).getIpAddress(), null,0, 0);
254         ctActionsListCommit.add(nxCtActionCommit);
255         int ctCommitFlag = 1;
256         ActionNxConntrack actionNxConntrackSubmit = new ActionNxConntrack(ctCommitFlag, 0, elanId,
257             NwConstants.NAPT_PFIB_TABLE, ctActionsListCommit);
258         actionsInfos.add(actionNxConntrackSubmit);
259         List<InstructionInfo> instructions = new ArrayList<>();
260         instructions.add(new InstructionApplyActions(actionsInfos));
261         String flowRef = getFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
262         NatUtil.addFlow(confTx, mdsalManager, dpnId, NwConstants.OUTBOUND_NAPT_TABLE, flowRef,
263                 NatConstants.SNAT_NEW_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions);
264     }
265
266     protected void removeOutboundTblEntry(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId,
267                                           Uint32 routerId) throws ExecutionException, InterruptedException {
268         LOG.info("createOutboundTblEntry : dpId {} and routerId {}", dpnId, routerId);
269         String flowRef = getFlowRef(dpnId, NwConstants.OUTBOUND_NAPT_TABLE, routerId);
270         NatUtil.removeFlow(confTx, mdsalManager, dpnId, NwConstants.OUTBOUND_NAPT_TABLE, flowRef);
271     }
272
273     protected void addNaptPfibFlow(TypedReadWriteTransaction<Configuration> confTx, Routers routers, Uint64 dpnId,
274                                    Uint32 routerId, Uint32 extSubnetId) {
275         Uint32 extNetId = NatUtil.getVpnId(confTx, routers.getNetworkId().getValue());
276         LOG.info("installNaptPfibFlow : dpId {}, extNetId {}", dpnId, extNetId);
277         List<MatchInfoBase> matches = new ArrayList<>();
278         matches.add(MatchEthernetType.IPV4);
279         matches.add(new NxMatchCtState(SNAT_CT_STATE, SNAT_CT_STATE_MASK));
280         matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId.longValue()),
281                 MetaDataUtil.METADATA_MASK_VRFID));
282         List<ActionInfo> listActionInfo = new ArrayList<>();
283         if (extSubnetId == NatConstants.INVALID_ID) {
284             LOG.error("installNaptPfibFlow : external subnet id is invalid.");
285             return;
286         }
287         ActionNxLoadMetadata actionLoadMeta = new ActionNxLoadMetadata(MetaDataUtil
288             .getVpnIdMetadata(extSubnetId.longValue()), LOAD_START, LOAD_END);
289         listActionInfo.add(actionLoadMeta);
290         listActionInfo.add(new ActionNxLoadInPort(Uint64.valueOf(BigInteger.ZERO)));
291         listActionInfo.add(new ActionNxCtClear());
292         listActionInfo.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
293         ArrayList<InstructionInfo> instructions = new ArrayList<>();
294         instructions.add(new InstructionApplyActions(listActionInfo));
295         String flowRef = getFlowRef(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId);
296         flowRef = flowRef + "OUTBOUND";
297         NatUtil.addFlow(confTx, mdsalManager, dpnId, NwConstants.NAPT_PFIB_TABLE, flowRef,
298                 NatConstants.SNAT_TRK_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions);
299     }
300
301     protected void removeNaptPfibFlow(TypedReadWriteTransaction<Configuration> confTx, Routers routers,
302             Uint64 dpnId, Uint32 routerId) throws ExecutionException, InterruptedException {
303         Uint32 extNetId = NatUtil.getVpnId(confTx, routers.getNetworkId().getValue());
304         LOG.info("installNaptPfibFlow : dpId {}, extNetId {}", dpnId, extNetId);
305         String flowRef = getFlowRef(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId) + "OUTBOUND";
306         NatUtil.removeFlow(confTx, mdsalManager, dpnId, NwConstants.NAPT_PFIB_TABLE, flowRef);
307     }
308
309     protected void addInboundEntry(TypedWriteTransaction<Configuration> confTx, Uint64 dpnId, Uint32 routerId,
310         String externalIp, int elanId, Uint32 extSubnetId) {
311         LOG.info("installInboundEntry : dpId {} and routerId {}", dpnId, routerId);
312         List<MatchInfoBase> matches = new ArrayList<>();
313         matches.add(MatchEthernetType.IPV4);
314         matches.add(new MatchIpv4Destination(externalIp,"32"));
315         if (extSubnetId == NatConstants.INVALID_ID) {
316             LOG.error("installInboundEntry : external subnet id is invalid.");
317             return;
318         }
319         matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(extSubnetId.longValue()),
320             MetaDataUtil.METADATA_MASK_VRFID));
321         List<ActionInfo> actionsInfos = new ArrayList<>();
322         List<NxCtAction> ctActionsList = new ArrayList<>();
323         NxCtAction nxCtAction = new ActionNxConntrack.NxNat(0, 0, 0,null, null,0, 0);
324         ActionNxLoadMetadata actionLoadMeta = new ActionNxLoadMetadata(MetaDataUtil
325             .getVpnIdMetadata(routerId.longValue()), LOAD_START, LOAD_END);
326         actionsInfos.add(actionLoadMeta);
327         ctActionsList.add(nxCtAction);
328         ActionNxConntrack actionNxConntrack = new ActionNxConntrack(0, 0, elanId, NwConstants
329             .NAPT_PFIB_TABLE,ctActionsList);
330
331         actionsInfos.add(actionNxConntrack);
332         List<InstructionInfo> instructions = new ArrayList<>();
333         instructions.add(new InstructionApplyActions(actionsInfos));
334         String flowRef = getFlowRef(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId);
335         flowRef = flowRef + "OUTBOUND";
336         NatUtil.addFlow(confTx, mdsalManager, dpnId, NwConstants.INBOUND_NAPT_TABLE, flowRef,
337                 NatConstants.DEFAULT_TS_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches, instructions);
338     }
339
340     protected void removeInboundEntry(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId,
341                                       Uint32 routerId) throws ExecutionException, InterruptedException {
342         LOG.info("installInboundEntry : dpId {} and routerId {}", dpnId, routerId);
343
344         String flowRef = getFlowRef(dpnId, NwConstants.INBOUND_NAPT_TABLE, routerId) + "OUTBOUND";
345         NatUtil.removeFlow(confTx, mdsalManager, dpnId, NwConstants.INBOUND_NAPT_TABLE, flowRef);
346     }
347
348     protected void addNaptPfibEntry(TypedWriteTransaction<Configuration> confTx, Uint64 dpnId, Uint32 routerId) {
349         LOG.info("installNaptPfibEntry : called for dpnId {} and routerId {} ", dpnId, routerId);
350         List<MatchInfoBase> matches = new ArrayList<>();
351         matches.add(MatchEthernetType.IPV4);
352         matches.add(new NxMatchCtState(DNAT_CT_STATE, DNAT_CT_STATE_MASK));
353         matches.add(new MatchMetadata(MetaDataUtil.getVpnIdMetadata(routerId.longValue()),
354                 MetaDataUtil.METADATA_MASK_VRFID));
355
356         ArrayList<ActionInfo> listActionInfo = new ArrayList<>();
357         ArrayList<InstructionInfo> instructionInfo = new ArrayList<>();
358         listActionInfo.add(new ActionNxLoadInPort(Uint64.valueOf(BigInteger.ZERO)));
359         listActionInfo.add(new ActionNxResubmit(NwConstants.L3_FIB_TABLE));
360         instructionInfo.add(new InstructionApplyActions(listActionInfo));
361
362         String flowRef = getFlowRef(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId) + "INBOUND";
363         NatUtil.addFlow(confTx, mdsalManager, dpnId, NwConstants.NAPT_PFIB_TABLE, flowRef,
364                 NatConstants.DEFAULT_PSNAT_FLOW_PRIORITY, flowRef, NwConstants.COOKIE_SNAT_TABLE, matches,
365                 instructionInfo);
366     }
367
368     protected void removeNaptPfibEntry(TypedReadWriteTransaction<Configuration> confTx, Uint64 dpnId,
369                                        Uint32 routerId) throws ExecutionException, InterruptedException {
370         LOG.info("installNaptPfibEntry : called for dpnId {} and routerId {} ", dpnId, routerId);
371         String flowRef = getFlowRef(dpnId, NwConstants.NAPT_PFIB_TABLE, routerId) + "INBOUND";
372         NatUtil.removeFlow(confTx, mdsalManager, dpnId, NwConstants.NAPT_PFIB_TABLE, flowRef);
373     }
374 }