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