Added support for VPN Intent
[vpnservice.git] / vpnmanager / vpnmanager-impl / src / main / java / org / opendaylight / vpnservice / VpnInterfaceManager.java
index 45a21744d21cc205ecb875b304cca06009c75628..525d30bd0cd1d3e970c139ffbefa99062218e71d 100644 (file)
@@ -212,7 +212,7 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
         List<Instruction> instructions = new ArrayList<Instruction>();
 
         instructions.add(MDSALUtil.buildAndGetWriteMetadaInstruction(BigInteger.valueOf(vpnId), MetaDataUtil.METADATA_MASK_VRFID, ++instructionKey));
-        instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(VpnConstants.FIB_TABLE, ++instructionKey));
+        instructions.add(MDSALUtil.buildAndGetGotoTableInstruction(NwConstants.L3_FIB_TABLE, ++instructionKey));
 
         BoundServices
             serviceInfo =
@@ -305,10 +305,10 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
 
         // Install the flow entry in L3_INTERFACE_TABLE
         BigInteger dpId = InterfaceUtils.getDpnForInterface(interfaceManager, vpnInterfaceName);
-        String flowRef = VpnUtil.getFlowRef(dpId, VpnConstants.L3_INTERFACE_TABLE,
+        String flowRef = VpnUtil.getFlowRef(dpId, NwConstants.L3_INTERFACE_TABLE,
                     NwConstants.ETHTYPE_ARP, lPortTag, replyOrRequest.getArpOperation());
         FlowEntity flowEntity;
-        flowEntity = MDSALUtil.buildFlowEntity(dpId, VpnConstants.L3_INTERFACE_TABLE, flowRef,
+        flowEntity = MDSALUtil.buildFlowEntity(dpId, NwConstants.L3_INTERFACE_TABLE, flowRef,
                 NwConstants.DEFAULT_ARP_FLOW_PRIORITY, replyOrRequest.getName(), 0, 0,
                 VpnUtil.getCookieArpFlow(lPortTag), matches, instructions);
 
@@ -423,13 +423,13 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
             InterfaceUtils.getInterfaceStateFromOperDS(broker, interfaceName);
 
         if (existingVpnInterface.isPresent() && interfaceState != null) {
-            processVpnInterfaceDown(interfaceName, interfaceState.getIfIndex());
+            processVpnInterfaceDown(interfaceName, interfaceState.getIfIndex(), false);
         } else {
             LOG.warn("VPN interface {} was unavailable in operational data store to handle remove event", interfaceName);
         }
     }
 
-    protected synchronized void processVpnInterfaceDown(String interfaceName, int lPortTag) {
+    protected synchronized void processVpnInterfaceDown(String interfaceName, int lPortTag, boolean isInterfaceStateDown) {
         VpnInterface vpnInterface = VpnUtil.getOperationalVpnInterface(broker, interfaceName);
         if(vpnInterface == null) {
             LOG.info("Unable to process delete/down for interface {} as it is not available in operational data store", interfaceName);
@@ -440,7 +440,7 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
 
         removeAdjacenciesFromVpn(identifier, vpnInterface);
         LOG.info("Unbinding vpn service from interface {} ", interfaceName);
-        unbindService(vpnName, interfaceName, lPortTag);
+        unbindService(vpnName, interfaceName, lPortTag, isInterfaceStateDown);
         updateDpnDbs(vpnName, interfaceName, false);
         VpnUtil.delete(broker, LogicalDatastoreType.OPERATIONAL, identifier, VpnUtil.DEFAULT_CALLBACK);
     }
@@ -477,10 +477,13 @@ public class VpnInterfaceManager extends AbstractDataChangeListener<VpnInterface
     }
 
 
-    private void unbindService(String vpnInstanceName, String vpnInterfaceName, int lPortTag) {
-        VpnUtil.delete(broker, LogicalDatastoreType.CONFIGURATION,
-                       InterfaceUtils.buildServiceId(vpnInterfaceName,VpnConstants.L3VPN_SERVICE_IDENTIFIER),
-                       VpnUtil.DEFAULT_CALLBACK);
+    private void unbindService(String vpnInstanceName, String vpnInterfaceName, int lPortTag, boolean isInterfaceStateDown) {
+        if (!isInterfaceStateDown) {
+            VpnUtil.delete(broker, LogicalDatastoreType.CONFIGURATION,
+                           InterfaceUtils.buildServiceId(vpnInterfaceName,
+                                                         VpnConstants.L3VPN_SERVICE_IDENTIFIER),
+                           VpnUtil.DEFAULT_CALLBACK);
+        }
         long vpnId = VpnUtil.getVpnId(broker, vpnInstanceName);
         makeArpFlow(VpnConstants.L3VPN_SERVICE_IDENTIFIER, lPortTag, vpnInterfaceName,
                     vpnId, ArpReplyOrRequest.REQUEST, NwConstants.DEL_FLOW);