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