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