Changes in different modules
[genius.git] / interfacemanager / interfacemanager-impl / src / main / java / org / opendaylight / genius / interfacemanager / rpcservice / InterfaceManagerRpcService.java
1 /*
2  * Copyright (c) 2016 Ericsson India Global Services Pvt Ltd. 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
9 package org.opendaylight.genius.interfacemanager.rpcservice;
10
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.FutureCallback;
13 import com.google.common.util.concurrent.Futures;
14 import com.google.common.util.concurrent.ListenableFuture;
15 import com.google.common.util.concurrent.SettableFuture;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
18 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
19 import org.opendaylight.genius.interfacemanager.IfmConstants;
20 import org.opendaylight.genius.interfacemanager.IfmUtil;
21 import org.opendaylight.genius.interfacemanager.commons.InterfaceManagerCommonUtils;
22 import org.opendaylight.genius.interfacemanager.commons.InterfaceMetaUtils;
23 import org.opendaylight.genius.mdsalutil.*;
24 import org.opendaylight.genius.mdsalutil.interfaces.IMdsalApiManager;
25 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
26 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
27 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.InterfaceKey;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.IfIndexesInterfaceMap;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterface;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406._if.indexes._interface.map.IfIndexInterfaceKey;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge._interface.info.BridgeEntry;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge._interface.info.BridgeEntryKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.meta.rev160406.bridge._interface.info.bridge.entry.BridgeInterfaceEntry;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.IfTunnel;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.ParentRefs;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeBase;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rev160406.TunnelTypeMplsOverGre;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.*;
43 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
44 import org.opendaylight.yangtools.yang.common.RpcError;
45 import org.opendaylight.yangtools.yang.common.RpcResult;
46 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
47 import org.slf4j.Logger;
48 import org.slf4j.LoggerFactory;
49
50 import java.math.BigInteger;
51 import java.util.ArrayList;
52 import java.util.Arrays;
53 import java.util.List;
54 import java.util.concurrent.Future;
55
56 public class InterfaceManagerRpcService implements OdlInterfaceRpcService {
57     private static final Logger LOG = LoggerFactory.getLogger(InterfaceManagerRpcService.class);
58     DataBroker dataBroker;
59     IMdsalApiManager mdsalMgr;
60
61
62     public InterfaceManagerRpcService(DataBroker dataBroker, IMdsalApiManager mdsalMgr) {
63         this.dataBroker = dataBroker;
64         this.mdsalMgr = mdsalMgr;
65     }
66
67     @Override
68     public Future<RpcResult<GetDpidFromInterfaceOutput>> getDpidFromInterface(GetDpidFromInterfaceInput input) {
69         String interfaceName = input.getIntfName();
70         RpcResultBuilder<GetDpidFromInterfaceOutput> rpcResultBuilder;
71         try {
72             BigInteger dpId = null;
73             InterfaceKey interfaceKey = new InterfaceKey(interfaceName);
74             Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
75             if (Tunnel.class.equals(interfaceInfo.getType())) {
76                 ParentRefs parentRefs = interfaceInfo.getAugmentation(ParentRefs.class);
77                 dpId = parentRefs.getDatapathNodeIdentifier();
78             } else {
79                 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
80                         InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker);
81                 String lowerLayerIf = ifState.getLowerLayerIf().get(0);
82                 NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
83                 dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
84             }
85             GetDpidFromInterfaceOutputBuilder output = new GetDpidFromInterfaceOutputBuilder().setDpid(
86                     (dpId));
87             rpcResultBuilder = RpcResultBuilder.success();
88             rpcResultBuilder.withResult(output.build());
89         } catch (Exception e) {
90             LOG.error("Retrieval of datapath id for the key {} failed due to {}", interfaceName, e);
91             rpcResultBuilder = RpcResultBuilder.failed();
92         }
93         return Futures.immediateFuture(rpcResultBuilder.build());
94     }
95
96     @Override
97     public Future<RpcResult<Void>> createTerminatingServiceActions(final CreateTerminatingServiceActionsInput input) {
98         final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
99         try{
100             LOG.info("create terminatingServiceAction on DpnId = {} for tunnel-key {}", input.getDpid() , input.getTunnelKey());
101             Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(input.getInterfaceName()),dataBroker);
102             IfTunnel tunnelInfo = interfaceInfo.getAugmentation(IfTunnel.class);
103             if(tunnelInfo != null) {
104                 ListenableFuture<Void> installFlowResult =(tunnelInfo.getTunnelInterfaceType().isAssignableFrom(TunnelTypeMplsOverGre.class))?
105                         makeLFIBFlow(input.getDpid(),input.getTunnelKey(), input.getInstruction(), NwConstants.ADD_FLOW) :
106                         makeTerminatingServiceFlow(tunnelInfo, input.getDpid(), input.getTunnelKey(), input.getInstruction(), NwConstants.ADD_FLOW);
107                 Futures.addCallback(installFlowResult, new FutureCallback<Void>(){
108
109                     @Override
110                     public void onSuccess(Void aVoid) {
111                         result.set(RpcResultBuilder.<Void>success().build());
112                     }
113
114                     @Override
115                     public void onFailure(Throwable error) {
116                         String msg = String.format("Unable to install terminating service flow for %s", input.getInterfaceName());
117                         LOG.error("create terminating service actions failed. {}. {}", msg, error);
118                         result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
119                     }
120                 });
121                 result.set(RpcResultBuilder.<Void>success().build());
122             } else {
123                 String msg = String.format("Terminating Service Actions cannot be created for a non-tunnel interface %s",input.getInterfaceName());
124                 LOG.error(msg);
125                 result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg).build());
126             }
127         }catch(Exception e){
128             String msg = String.format("create Terminating Service Actions for %s failed",input.getInterfaceName());
129             LOG.error("create Terminating Service Actions for {} failed due to {}" ,input.getDpid(), e);
130             result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, e.getMessage()).build());
131         }
132         return result;
133     }
134
135     @Override
136     public Future<RpcResult<Void>> removeTerminatingServiceActions(final RemoveTerminatingServiceActionsInput input) {
137         final SettableFuture<RpcResult<Void>> result = SettableFuture.create();
138         try{
139             WriteTransaction t = dataBroker.newWriteOnlyTransaction();
140             LOG.info("remove terminatingServiceAction on DpnId = {} for tunnel-key {}", input.getDpid() , input.getTunnelKey());
141
142             Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(new InterfaceKey(input.getInterfaceName()),dataBroker);
143             IfTunnel tunnelInfo = interfaceInfo.getAugmentation(IfTunnel.class);
144             if(tunnelInfo != null) {
145                 ListenableFuture<Void> removeFlowResult = (tunnelInfo.getTunnelInterfaceType().isAssignableFrom(TunnelTypeMplsOverGre.class))?
146                         makeLFIBFlow(input.getDpid(),input.getTunnelKey(), null, NwConstants.DEL_FLOW) :
147                         makeTerminatingServiceFlow(tunnelInfo, input.getDpid(), input.getTunnelKey(), null, NwConstants.DEL_FLOW);
148                 Futures.addCallback(removeFlowResult, new FutureCallback<Void>(){
149
150                     @Override
151                     public void onSuccess(Void aVoid) {
152                         result.set(RpcResultBuilder.<Void>success().build());
153                     }
154
155                     @Override
156                     public void onFailure(Throwable error) {
157                         String msg = String.format("Unable to install terminating service flow %s", input.getInterfaceName());
158                         LOG.error("create terminating service actions failed. {}. {}", msg, error);
159                         result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, error).build());
160                     }
161                 });
162                 result.set(RpcResultBuilder.<Void>success().build());
163             } else {
164                 String msg = String.format("Terminating Service Actions cannot be removed for a non-tunnel interface %s",
165                         input.getInterfaceName());
166                 LOG.error(msg);
167                 result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg).build());
168             }
169         }catch(Exception e){
170             LOG.error("Remove Terminating Service Actions for {} failed due to {}" ,input.getDpid(), e);
171             String msg = String.format("Remove Terminating Service Actions for %d failed.", input.getDpid());
172             result.set(RpcResultBuilder.<Void>failed().withError(RpcError.ErrorType.APPLICATION, msg, e.getMessage()).build());
173         }
174         return result;
175     }
176
177     @Override
178     public Future<RpcResult<GetEndpointIpForDpnOutput>> getEndpointIpForDpn(GetEndpointIpForDpnInput input) {
179         RpcResultBuilder<GetEndpointIpForDpnOutput> rpcResultBuilder;
180         try {
181             BridgeEntryKey bridgeEntryKey = new BridgeEntryKey(input.getDpid());
182             InstanceIdentifier<BridgeEntry> bridgeEntryInstanceIdentifier =
183                     InterfaceMetaUtils.getBridgeEntryIdentifier(bridgeEntryKey);
184             BridgeEntry bridgeEntry =
185                     InterfaceMetaUtils.getBridgeEntryFromConfigDS(bridgeEntryInstanceIdentifier,
186                             dataBroker);
187             // local ip of any of the bridge interface entry will be the dpn end point ip
188             BridgeInterfaceEntry bridgeInterfaceEntry = bridgeEntry.getBridgeInterfaceEntry().get(0);
189             InterfaceKey interfaceKey = new InterfaceKey(bridgeInterfaceEntry.getInterfaceName());
190             Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
191             IfTunnel tunnel = interfaceInfo.getAugmentation(IfTunnel.class);
192             GetEndpointIpForDpnOutputBuilder endpointIpForDpnOutput = new GetEndpointIpForDpnOutputBuilder().setLocalIps(Arrays.asList(tunnel.getTunnelSource()));
193             rpcResultBuilder = RpcResultBuilder.success();
194             rpcResultBuilder.withResult(endpointIpForDpnOutput.build());
195         }catch(Exception e){
196             LOG.error("Retrieval of endpoint of for dpn {} failed due to {}" ,input.getDpid(), e);
197             rpcResultBuilder = RpcResultBuilder.failed();
198         }
199         return Futures.immediateFuture(rpcResultBuilder.build());
200     }
201
202     @Override
203     public Future<RpcResult<GetEgressInstructionsForInterfaceOutput>> getEgressInstructionsForInterface(GetEgressInstructionsForInterfaceInput input) {
204         RpcResultBuilder<GetEgressInstructionsForInterfaceOutput> rpcResultBuilder;
205         try {
206             List<InstructionInfo> instructionInfo = new ArrayList<InstructionInfo>();
207             List<ActionInfo> actionInfo = IfmUtil.getEgressActionInfosForInterface(input.getIntfName(),
208                     input.getTunnelKey(),
209                     0,  /* ActionKey starting value */
210                     dataBroker);
211             instructionInfo.add(new InstructionInfo(InstructionType.write_actions, actionInfo));
212             GetEgressInstructionsForInterfaceOutputBuilder output = new GetEgressInstructionsForInterfaceOutputBuilder().
213                     setInstruction(buildInstructions(instructionInfo));
214             rpcResultBuilder = RpcResultBuilder.success();
215             rpcResultBuilder.withResult(output.build());
216         }catch(Exception e){
217             LOG.error("Retrieval of egress actions for the key {} failed due to {}" ,input.getIntfName(), e.getMessage());
218             rpcResultBuilder = RpcResultBuilder.failed();
219         }
220         return Futures.immediateFuture(rpcResultBuilder.build());
221     }
222
223     @Override
224     public Future<RpcResult<GetInterfaceTypeOutput>> getInterfaceType(GetInterfaceTypeInput input) {
225         String interfaceName = input.getIntfName();
226         RpcResultBuilder<GetInterfaceTypeOutput> rpcResultBuilder;
227         try {
228             InterfaceKey interfaceKey = new InterfaceKey(interfaceName);
229             Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
230
231             GetInterfaceTypeOutputBuilder output = new GetInterfaceTypeOutputBuilder().setInterfaceType(interfaceInfo.getType());
232             rpcResultBuilder = RpcResultBuilder.success();
233             rpcResultBuilder.withResult(output.build());
234         } catch (Exception e) {
235             LOG.error("Retrieval of interface type for the key {} failed due to {}", interfaceName, e);
236             rpcResultBuilder = RpcResultBuilder.failed();
237         }
238         return Futures.immediateFuture(rpcResultBuilder.build());
239     }
240
241     @Override
242     public Future<RpcResult<GetTunnelTypeOutput>> getTunnelType(GetTunnelTypeInput input) {
243         String interfaceName = input.getIntfName();
244         RpcResultBuilder<GetTunnelTypeOutput> rpcResultBuilder;
245         try {
246             InterfaceKey interfaceKey = new InterfaceKey(interfaceName);
247             Interface interfaceInfo = InterfaceManagerCommonUtils.getInterfaceFromConfigDS(interfaceKey, dataBroker);
248
249             if (Tunnel.class.equals(interfaceInfo.getType())) {
250                 IfTunnel tnl = interfaceInfo.getAugmentation(IfTunnel.class);
251                 Class <? extends TunnelTypeBase> tun_type = tnl.getTunnelInterfaceType();
252                 GetTunnelTypeOutputBuilder output = new GetTunnelTypeOutputBuilder().setTunnelType(tun_type);
253                 rpcResultBuilder = RpcResultBuilder.success();
254                 rpcResultBuilder.withResult(output.build());
255             } else {
256                 LOG.error("Retrieval of interface type for the key {} failed", interfaceName);
257                 rpcResultBuilder = RpcResultBuilder.failed();
258             }
259         } catch (Exception e) {
260             LOG.error("Retrieval of interface type for the key {} failed due to {}", interfaceName, e);
261             rpcResultBuilder = RpcResultBuilder.failed();
262         }
263         return Futures.immediateFuture(rpcResultBuilder.build());
264     }
265
266     @Override
267     public Future<RpcResult<GetEgressActionsForInterfaceOutput>> getEgressActionsForInterface(GetEgressActionsForInterfaceInput input) {
268         RpcResultBuilder<GetEgressActionsForInterfaceOutput> rpcResultBuilder;
269         try {
270             LOG.debug("Get Egress Action for interface {} with key {}", input.getIntfName(), input.getTunnelKey());
271             List<Action> actionsList = IfmUtil.getEgressActionsForInterface(input.getIntfName(),
272                     input.getTunnelKey(),
273                     dataBroker);
274             GetEgressActionsForInterfaceOutputBuilder output = new GetEgressActionsForInterfaceOutputBuilder().
275                     setAction(actionsList);
276             rpcResultBuilder = RpcResultBuilder.success();
277             rpcResultBuilder.withResult(output.build());
278         }catch(Exception e){
279             LOG.error("Retrieval of egress actions for the key {} failed due to {}" ,input.getIntfName(), e.getMessage());
280             rpcResultBuilder = RpcResultBuilder.failed();
281         }
282         return Futures.immediateFuture(rpcResultBuilder.build());
283     }
284
285
286     @Override
287     public Future<RpcResult<GetPortFromInterfaceOutput>> getPortFromInterface(GetPortFromInterfaceInput input) {
288         RpcResultBuilder<GetPortFromInterfaceOutput> rpcResultBuilder;
289         String interfaceName = input.getIntfName();
290         try {
291             BigInteger dpId = null;
292             long portNo = 0;
293             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
294                     InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker);
295             String lowerLayerIf = ifState.getLowerLayerIf().get(0);
296             NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
297             dpId = new BigInteger(IfmUtil.getDpnFromNodeConnectorId(nodeConnectorId));
298             portNo = Long.valueOf(IfmUtil.getPortNoFromNodeConnectorId(nodeConnectorId));
299             // FIXME Assuming portName and interfaceName are same
300             GetPortFromInterfaceOutputBuilder output = new GetPortFromInterfaceOutputBuilder().setDpid(dpId).
301                     setPortname(interfaceName).setPortno(Long.valueOf(portNo));
302             rpcResultBuilder = RpcResultBuilder.success();
303             rpcResultBuilder.withResult(output.build());
304         }catch(Exception e){
305             LOG.error("Retrieval of lport tag for the key {} failed due to {}" ,input.getIntfName(), e);
306             rpcResultBuilder = RpcResultBuilder.failed();
307         }
308         return Futures.immediateFuture(rpcResultBuilder.build());
309     }
310
311     @Override
312     public Future<RpcResult<GetNodeconnectorIdFromInterfaceOutput>> getNodeconnectorIdFromInterface(GetNodeconnectorIdFromInterfaceInput input) {
313         String interfaceName = input.getIntfName();
314         RpcResultBuilder<GetNodeconnectorIdFromInterfaceOutput> rpcResultBuilder;
315         try {
316             org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface ifState =
317                     InterfaceManagerCommonUtils.getInterfaceStateFromOperDS(interfaceName, dataBroker);
318             String lowerLayerIf = ifState.getLowerLayerIf().get(0);
319             NodeConnectorId nodeConnectorId = new NodeConnectorId(lowerLayerIf);
320
321             GetNodeconnectorIdFromInterfaceOutputBuilder output = new GetNodeconnectorIdFromInterfaceOutputBuilder().setNodeconnectorId(nodeConnectorId);
322             rpcResultBuilder = RpcResultBuilder.success();
323             rpcResultBuilder.withResult(output.build());
324         } catch (Exception e) {
325             LOG.error("Retrieval of nodeconnector id for the key {} failed due to {}", interfaceName, e);
326             rpcResultBuilder = RpcResultBuilder.failed();
327         }
328         return Futures.immediateFuture(rpcResultBuilder.build());
329     }
330
331     @Override
332     public Future<RpcResult<GetInterfaceFromIfIndexOutput>> getInterfaceFromIfIndex(GetInterfaceFromIfIndexInput input) {
333         Integer ifIndex = input.getIfIndex();
334         RpcResultBuilder<GetInterfaceFromIfIndexOutput> rpcResultBuilder = null;
335         try {
336             InstanceIdentifier<IfIndexInterface> id = InstanceIdentifier.builder(IfIndexesInterfaceMap.class).child(IfIndexInterface.class, new IfIndexInterfaceKey(ifIndex)).build();
337             Optional<IfIndexInterface> ifIndexesInterface = IfmUtil.read(LogicalDatastoreType.OPERATIONAL, id, dataBroker);
338             if(ifIndexesInterface.isPresent()) {
339                 String interfaceName = ifIndexesInterface.get().getInterfaceName();
340                 GetInterfaceFromIfIndexOutputBuilder output = new GetInterfaceFromIfIndexOutputBuilder().setInterfaceName(interfaceName);
341                 rpcResultBuilder = RpcResultBuilder.success();
342                 rpcResultBuilder.withResult(output.build());
343             }
344         } catch (Exception e) {
345             LOG.error("Retrieval of interfaceName for the key {} failed due to {}", ifIndex, e);
346             rpcResultBuilder = RpcResultBuilder.failed();
347         }
348         return Futures.immediateFuture(rpcResultBuilder.build());
349     }
350
351     protected static List<Instruction> buildInstructions(List<InstructionInfo> listInstructionInfo) {
352         if (listInstructionInfo != null) {
353             List<Instruction> instructions = new ArrayList<Instruction>();
354             int instructionKey = 0;
355
356             for (InstructionInfo instructionInfo : listInstructionInfo) {
357                 instructions.add(instructionInfo.buildInstruction(instructionKey));
358                 instructionKey++;
359             }
360             return instructions;
361         }
362
363         return null;
364     }
365
366     private ListenableFuture<Void> makeTerminatingServiceFlow(IfTunnel tunnelInfo, BigInteger dpnId, BigInteger tunnelKey, List<Instruction> instruction, int addOrRemove) {
367         List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
368         mkMatches.add(new MatchInfo(MatchFieldType.tunnel_id, new BigInteger[] {tunnelKey}));
369         short tableId = tunnelInfo.isInternal() ? NwConstants.INTERNAL_TUNNEL_TABLE :
370                 NwConstants.EXTERNAL_TUNNEL_TABLE;
371         final String flowRef = getFlowRef(dpnId,tableId, tunnelKey);
372         Flow terminatingSerFlow = MDSALUtil.buildFlowNew(tableId, flowRef,
373                 5, "TST Flow Entry", 0, 0,
374                 IfmConstants.TUNNEL_TABLE_COOKIE.add(tunnelKey), mkMatches, instruction);
375         if (addOrRemove == NwConstants.ADD_FLOW) {
376             return mdsalMgr.installFlow(dpnId, terminatingSerFlow);
377         }
378
379         return mdsalMgr.removeFlow(dpnId, terminatingSerFlow);
380     }
381
382     private ListenableFuture<Void> makeLFIBFlow(BigInteger dpnId, BigInteger tunnelKey, List<Instruction> instruction, int addOrRemove) {
383         List<MatchInfo> mkMatches = new ArrayList<MatchInfo>();
384         mkMatches.add(new MatchInfo(MatchFieldType.eth_type,
385                 new long[]{0x8847L}));
386         mkMatches.add(new MatchInfo(MatchFieldType.mpls_label, new String[]{Long.toString(tunnelKey.longValue())}));
387         // Install the flow entry in L3_LFIB_TABLE
388         String flowRef = getFlowRef(dpnId, NwConstants.L3_LFIB_TABLE, tunnelKey);
389
390         Flow lfibFlow = MDSALUtil.buildFlowNew(NwConstants.L3_LFIB_TABLE, flowRef,
391                 IfmConstants.DEFAULT_FLOW_PRIORITY, "LFIB Entry", 0, 0,
392                 IfmConstants.COOKIE_VM_LFIB_TABLE, mkMatches, instruction);
393         if (addOrRemove == NwConstants.ADD_FLOW) {
394             return mdsalMgr.installFlow(dpnId, lfibFlow);
395         }
396         return mdsalMgr.removeFlow(dpnId, lfibFlow);
397     }
398
399     private String getFlowRef(BigInteger dpnId, short tableId, BigInteger tunnelKey) {
400         return new StringBuffer().append(IfmConstants.TUNNEL_TABLE_FLOWID_PREFIX).append(dpnId).append(NwConstants.FLOWID_SEPARATOR)
401                 .append(tableId).append(NwConstants.FLOWID_SEPARATOR).append(tunnelKey).toString();
402     }
403 }