Bug 8962: Fix non-parameterized LOG statements as per guidelines
[netvirt.git] / vpnservice / vpnmanager / vpnmanager-impl / src / main / java / org / opendaylight / netvirt / vpnmanager / InterfaceStateChangeListener.java
index 7f7a292b94337aea4be3408952be591bcacb84b4..979a9887df6774959adfcf70cc3a946ff4d58e10 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 - 2016 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015, 2017 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
 package org.opendaylight.netvirt.vpnmanager;
 
 import com.google.common.base.Optional;
-
-import com.google.common.util.concurrent.CheckedFuture;
 import com.google.common.util.concurrent.ListenableFuture;
+import java.math.BigInteger;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.concurrent.ExecutionException;
+
 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
-import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
-import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
-import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.genius.datastoreutils.AsyncDataTreeChangeListenerBase;
 import org.opendaylight.genius.datastoreutils.DataStoreJobCoordinator;
 import org.opendaylight.netvirt.vpnmanager.utilities.InterfaceUtils;
 import org.opendaylight.yang.gen.v1.urn.huawei.params.xml.ns.yang.l3vpn.rev140815.vpn.interfaces.VpnInterface;
-import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.Tunnel;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.iana._if.type.rev140508.L2vlan;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.InterfacesState;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.genius.interfacemanager.rpcs.rev160406.OdlInterfaceRpcService;
-import org.opendaylight.yang.gen.v1.urn.opendaylight.netvirt.l3vpn.rev130911.router.interfaces.RouterInterface;
-import org.opendaylight.yangtools.concepts.ListenerRegistration;
+import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.state.Interface.OperStatus;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import java.math.BigInteger;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-
-public class InterfaceStateChangeListener extends AbstractDataChangeListener<Interface> implements AutoCloseable {
+public class InterfaceStateChangeListener
+    extends AsyncDataTreeChangeListenerBase<Interface, InterfaceStateChangeListener> implements AutoCloseable {
     private static final Logger LOG = LoggerFactory.getLogger(InterfaceStateChangeListener.class);
+    private final DataBroker dataBroker;
+    private final VpnInterfaceManager vpnInterfaceManager;
 
-    private ListenerRegistration<DataChangeListener> listenerRegistration;
-    private final DataBroker broker;
-    private VpnInterfaceManager vpnInterfaceManager;
-    private OdlInterfaceRpcService interfaceManager;
-
-
-    public InterfaceStateChangeListener(final DataBroker db, VpnInterfaceManager vpnInterfaceManager) {
-        super(Interface.class);
-        broker = db;
+    public InterfaceStateChangeListener(final DataBroker dataBroker, final VpnInterfaceManager vpnInterfaceManager) {
+        super(Interface.class, InterfaceStateChangeListener.class);
+        this.dataBroker = dataBroker;
         this.vpnInterfaceManager = vpnInterfaceManager;
-        registerListener(db);
     }
 
-    public void setIfaceMgrRpcService(OdlInterfaceRpcService interfaceManager) {
-        this.interfaceManager = interfaceManager;
+    public void start() {
+        LOG.info("{} start", getClass().getSimpleName());
+        registerListener(LogicalDatastoreType.OPERATIONAL, dataBroker);
     }
 
+
     @Override
-    public void close() throws Exception {
-        if (listenerRegistration != null) {
-            try {
-                listenerRegistration.close();
-            } catch (final Exception e) {
-                LOG.error("Error when cleaning up DataChangeListener.", e);
-            }
-            listenerRegistration = null;
-        }
-        LOG.info("Interface listener Closed");
+    protected InstanceIdentifier<Interface> getWildCardPath() {
+        return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
     }
 
-
-    private void registerListener(final DataBroker db) {
-        try {
-            listenerRegistration = db.registerDataChangeListener(LogicalDatastoreType.OPERATIONAL,
-                    getWildCardPath(), InterfaceStateChangeListener.this, DataChangeScope.SUBTREE);
-        } catch (final Exception e) {
-            LOG.error("Interface DataChange listener registration failed", e);
-            throw new IllegalStateException("Nexthop Manager registration Listener failed.", e);
-        }
+    @Override
+    protected InterfaceStateChangeListener getDataTreeChangeListener() {
+        return InterfaceStateChangeListener.this;
     }
 
+
     @Override
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     protected void add(InstanceIdentifier<Interface> identifier, Interface intrf) {
-        LOG.trace("Received interface {} add event", intrf);
         try {
-            final String interfaceName = intrf.getName();
-            LOG.info("Received interface add event for interface {} ", interfaceName);
-            org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface
-                    configInterface = InterfaceUtils.getInterface(broker, interfaceName);
-            if (configInterface != null) {
-                if (!configInterface.getType().equals(Tunnel.class)) {
-                    // We service only VM interfaces and Router interfaces here.
-                    // We donot service Tunnel Interfaces here.
-                    // Tunnel events are directly serviced
-                    // by TunnelInterfacesStateListener present as part of VpnInterfaceManager
-                    final VpnInterface vpnInterface = VpnUtil.getConfiguredVpnInterface(broker, interfaceName);
-                    if (vpnInterface != null) {
-                        final BigInteger dpnId = InterfaceUtils.getDpIdFromInterface(intrf);
-                        final int ifIndex = intrf.getIfIndex();
-                        DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-                        dataStoreCoordinator.enqueueJob("VPNINTERFACE-" + intrf.getName(),
-                                new Callable<List<ListenableFuture<Void>>>() {
-                                    @Override
-                                    public List<ListenableFuture<Void>> call() throws Exception {
-                                        WriteTransaction writeConfigTxn = broker.newWriteOnlyTransaction();
-                                        WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction();
-                                        vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnInterface, ifIndex, false,
-                                                writeConfigTxn, writeOperTxn);
-                                        CheckedFuture<Void, TransactionCommitFailedException> futures = writeOperTxn.submit();
-                                        try {
-                                            futures.get();
-                                        } catch (InterruptedException | ExecutionException e) {
-                                            LOG.error("Error adding Oper data for interface {} to vpn {} on dpn {}", interfaceName,
-                                                    vpnInterface.getVpnInstanceName(), dpnId);
-                                            throw new RuntimeException(e.getMessage());
-                                        }
-                                        futures = writeConfigTxn.submit();
-                                        try {
-                                            futures.get();
-                                        } catch (InterruptedException | ExecutionException e) {
-                                            LOG.error("Error adding Config data for interface {} to vpn {} on dpn {}", interfaceName,
-                                                    vpnInterface.getVpnInstanceName(), dpnId);
-                                            throw new RuntimeException(e.getMessage());
-                                        }
-                                        return null;
-                                    }
-                                });
-                    } else {
-                        RouterInterface routerInterface = VpnUtil.getConfiguredRouterInterface(broker, interfaceName);
-                        if (routerInterface != null) {
-                            final String routerName = routerInterface.getRouterName();
-                            DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-                            dataStoreCoordinator.enqueueJob("VPNINTERFACE-" + intrf.getName(),
-                                    new Callable<List<ListenableFuture<Void>>>() {
-                                        @Override
-                                        public List<ListenableFuture<Void>> call() throws Exception {
-                                            WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction();
-                                            handleRouterInterfacesUpEvent(routerName, interfaceName, writeOperTxn);
-                                            CheckedFuture<Void, TransactionCommitFailedException> futures = writeOperTxn.submit();
-                                            try {
-                                                futures.get();
-                                            } catch (InterruptedException | ExecutionException e) {
-                                                LOG.error("Error adding as router interface for interface {} to router {} ", interfaceName,
-                                                        routerName);
-                                                throw new RuntimeException(e.getMessage());
-                                            }
-                                            return null;
-                                        }
-                                    });
-                        } else {
-                            LOG.info("Unable to process add for interface {} as it is not configured for vpn", interfaceName);
+            if (L2vlan.class.equals(intrf.getType())) {
+                LOG.info("VPN Interface add event - intfName {} from InterfaceStateChangeListener",
+                                intrf.getName());
+                DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
+                dataStoreCoordinator.enqueueJob("VPNINTERFACE-" + intrf.getName(),
+                    () -> {
+                        WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
+                        WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
+                        WriteTransaction writeInvTxn = dataBroker.newWriteOnlyTransaction();
+                        List<ListenableFuture<Void>> futures = new ArrayList<>();
+
+                        final String interfaceName = intrf.getName();
+                        LOG.info("Detected interface add event for interface {}", interfaceName);
+
+                        final VpnInterface vpnInterface =
+                                VpnUtil.getConfiguredVpnInterface(dataBroker, interfaceName);
+                        if (vpnInterface != null) {
+                            String primaryRd = VpnUtil.getPrimaryRd(dataBroker,
+                                    vpnInterface.getVpnInstanceName());
+                            if (!VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
+                                LOG.debug("VPN Interface Name {}", vpnInterface);
+                                BigInteger intfDpnId = BigInteger.ZERO;
+                                try {
+                                    intfDpnId = InterfaceUtils.getDpIdFromInterface(intrf);
+                                } catch (Exception e) {
+                                    LOG.error("Unable to retrieve dpnId for interface {}. "
+                                            + "Process vpn interface add failed",intrf.getName(), e);
+                                    return futures;
+                                }
+                                final BigInteger dpnId = intfDpnId;
+                                final int ifIndex = intrf.getIfIndex();
+                                if (!vpnInterfaceManager.isVpnInstanceReady(vpnInterface.getVpnInstanceName())) {
+                                    LOG.info("VPN Interface add event - intfName {} onto vpnName {} "
+                                                    + "running oper-driven, VpnInstance not ready, holding on",
+                                            vpnInterface.getName(), vpnInterface.getVpnInstanceName());
+                                    return futures;
+
+                                }
+                                LOG.info("VPN Interface add event - intfName {} onto vpnName {} running oper-driven",
+                                        vpnInterface.getName(), vpnInterface.getVpnInstanceName());
+                                vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnInterface, primaryRd, ifIndex,
+                                        false, writeConfigTxn, writeOperTxn, writeInvTxn, intrf);
+                                ListenableFuture<Void> operFuture = writeOperTxn.submit();
+                                try {
+                                    operFuture.get();
+                                } catch (ExecutionException e) {
+                                    LOG.error("InterfaceStateChange - Exception encountered while submitting"
+                                                    + " operational future for addVpnInterface {}",
+                                            vpnInterface.getName(), e);
+                                    return null;
+                                }
+                                futures.add(writeConfigTxn.submit());
+                                futures.add(writeInvTxn.submit());
+                            } else {
+                                LOG.error("add: Ignoring addition of vpnInterface {}, as vpnInstance {}"
+                                        + " with primaryRd {} is already marked for deletion", interfaceName,
+                                        vpnInterface.getVpnInstanceName(), primaryRd);
+                            }
                         }
-                    }
-                }
-            } else {
-                LOG.error("Unable to process add for interface {} ," +
-                        "since Interface ConfigDS entry absent for the same", interfaceName);
+                        return futures;
+                    });
             }
         } catch (Exception e) {
-            LOG.error("Exception caught in Interface Operational State Up event", e);
+            LOG.error("Exception caught in Interface {} Operational State Up event", intrf.getName(), e);
         }
     }
 
-
-    private InstanceIdentifier<Interface> getWildCardPath() {
-        return InstanceIdentifier.create(InterfacesState.class).child(Interface.class);
-    }
-
     @Override
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     protected void remove(InstanceIdentifier<Interface> identifier, Interface intrf) {
-        LOG.trace("Received interface {} down event", intrf);
+        final String interfaceName = intrf.getName();
+        BigInteger dpId = BigInteger.ZERO;
         try {
-            final String interfaceName = intrf.getName();
-            LOG.info("Received port DOWN event for interface {} ", interfaceName);
-            if (intrf != null && intrf.getType() != null && intrf.getType().equals(Tunnel.class)) {
-                //withdraw all prefixes in all vpns for this dpn from bgp
-                // FIXME: Blocked until tunnel event[vxlan/gre] support is available
-                // vpnInterfaceManager.updatePrefixesForDPN(dpId, VpnInterfaceManager.UpdateRouteAction.WITHDRAW_ROUTE);
-            } else {
-                BigInteger dpId = BigInteger.ZERO;
-                InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
-                Optional<VpnInterface> optVpnInterface = VpnUtil.read(broker, LogicalDatastoreType.OPERATIONAL, id);
-                if (!optVpnInterface.isPresent()) {
-                    LOG.debug("Interface {} is not a vpninterface, ignoring.", intrf.getName());
-                    return;
-                }
-                final VpnInterface vpnInterface = optVpnInterface.get();
+            if (L2vlan.class.equals(intrf.getType())) {
+                LOG.info("VPN Interface remove event - intfName {} from InterfaceStateChangeListener",
+                                intrf.getName());
                 try {
                     dpId = InterfaceUtils.getDpIdFromInterface(intrf);
-                } catch (Exception e){
-                    LOG.warn("Unable to retrieve dpnId from interface operational data store for interface {}. Fetching from vpn interface op data store. ", intrf.getName(), e);
-                    dpId = vpnInterface.getDpnId();
+                } catch (Exception e) {
+                    LOG.error("Unable to retrieve dpnId from interface operational data store for interface"
+                            + " {}. Fetching from vpn interface op data store. ", interfaceName, e);
                 }
-                final BigInteger dpnId = dpId;
-                final int ifIndex = intrf.getIfIndex();
+                final BigInteger inputDpId = dpId;
                 DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-                dataStoreCoordinator.enqueueJob("VPNINTERFACE-" + intrf.getName(),
-                        new Callable<List<ListenableFuture<Void>>>() {
-                            @Override
-                            public List<ListenableFuture<Void>> call() throws Exception {
-                                WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction();
-                                WriteTransaction writeConfigTxn = broker.newWriteOnlyTransaction();
-                                vpnInterfaceManager.processVpnInterfaceDown(dpnId, interfaceName, ifIndex, false, false,
-                                        writeConfigTxn, writeOperTxn);
-                                RouterInterface routerInterface = VpnUtil.getConfiguredRouterInterface(broker, interfaceName);
-                                if (routerInterface != null) {
-                                    final String routerName = routerInterface.getRouterName();
-                                    handleRouterInterfacesDownEvent(routerName, interfaceName, dpnId, writeOperTxn);
-                                }
-                                CheckedFuture<Void, TransactionCommitFailedException> futures = writeOperTxn.submit();
-                                try {
-                                    futures.get();
-                                } catch (InterruptedException | ExecutionException e) {
-                                    LOG.error("Error removing Oper data for interface {} from vpn {} on dpn {}", interfaceName,
-                                            vpnInterface.getVpnInstanceName(), dpnId);
-                                    throw new RuntimeException(e.getMessage());
-                                }
-                                futures = writeConfigTxn.submit();
-                                try {
-                                    futures.get();
-                                } catch (InterruptedException | ExecutionException e) {
-                                    LOG.error("Error removing Config data for interface {} from vpn {} on dpn {}", interfaceName,
-                                            vpnInterface.getVpnInstanceName(), dpnId);
-                                    throw new RuntimeException(e.getMessage());
-                                }
+                dataStoreCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName,
+                    () -> {
+                        WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
+                        WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
+                        WriteTransaction writeInvTxn = dataBroker.newWriteOnlyTransaction();
+                        List<ListenableFuture<Void>> futures = new ArrayList<>();
+
+                        InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
+                        Optional<VpnInterface> optVpnInterface =
+                                VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
+                        if (optVpnInterface.isPresent()) {
+                            final VpnInterface vpnInterface = optVpnInterface.get();
+                            BigInteger dpnId = inputDpId;
+                            if (dpnId == null || dpnId.equals(BigInteger.ZERO)) {
+                                dpnId = vpnInterface.getDpnId();
+                            }
+                            final int ifIndex = intrf.getIfIndex();
+                            LOG.info("VPN Interface remove event - intfName {} onto vpnName {} running oper-driven",
+                                    vpnInterface.getName(), vpnInterface.getVpnInstanceName());
+                            vpnInterfaceManager.processVpnInterfaceDown(dpnId, interfaceName, ifIndex, intrf,
+                                    vpnInterface, false, writeConfigTxn, writeOperTxn, writeInvTxn);
+                            ListenableFuture<Void> operFuture = writeOperTxn.submit();
+                            try {
+                                operFuture.get();
+                            } catch (ExecutionException e) {
+                                LOG.error("InterfaceStateChange - Exception encountered while submitting operational"
+                                        + " future for removeVpnInterface {}", vpnInterface.getName(), e);
                                 return null;
                             }
-                        });
+                            futures.add(writeConfigTxn.submit());
+                            futures.add(writeInvTxn.submit());
+                        } else {
+                            LOG.debug("Interface {} is not a vpninterface, ignoring.", interfaceName);
+                        }
+
+                        return futures;
+                    });
             }
         } catch (Exception e) {
-            LOG.error("Exception observed in handling deletion of VPN Interface {}. ", intrf.getName(), e);
+            LOG.error("Exception observed in handling deletion of VPN Interface {}. ", interfaceName, e);
         }
     }
 
+    // TODO Clean up the exception handling
+    @SuppressWarnings("checkstyle:IllegalCatch")
     @Override
     protected void update(InstanceIdentifier<Interface> identifier,
-                          Interface original, Interface update) {
-        LOG.trace("Operation Interface update event - Old: {}, New: {}", original, update);
+                    Interface original, Interface update) {
         final String interfaceName = update.getName();
-        if (original.getOperStatus().equals(Interface.OperStatus.Unknown) ||
-                update.getOperStatus().equals(Interface.OperStatus.Unknown)){
-            LOG.debug("Interface {} state change is from/to UNKNOWN. Ignoring the update event.", interfaceName);
-            return;
-        }
-        final BigInteger dpnId = InterfaceUtils.getDpIdFromInterface(update);
-        final int ifIndex = update.getIfIndex();
-        if (update != null) {
-            if (!update.getType().equals(Tunnel.class)) {
-                final VpnInterface vpnInterface = VpnUtil.getConfiguredVpnInterface(broker, interfaceName);
-                if (vpnInterface != null) {
-                    if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
-                        DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-                        dataStoreCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName,
-                                new Callable<List<ListenableFuture<Void>>>() {
-                                    @Override
-                                    public List<ListenableFuture<Void>> call() throws Exception {
-                                        WriteTransaction writeConfigTxn = broker.newWriteOnlyTransaction();
-                                        WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction();
-                                        vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnInterface, ifIndex,
-                                                true, writeConfigTxn, writeOperTxn);
-                                        CheckedFuture<Void, TransactionCommitFailedException> futures = writeConfigTxn.submit();
-                                        try {
-                                            futures.get();
-                                        } catch (InterruptedException | ExecutionException e) {
-                                            LOG.error("Error updating UP for interface {} in vpn {} on dpn {}", interfaceName,
-                                                    vpnInterface.getVpnInstanceName(), dpnId);
-                                            throw new RuntimeException(e.getMessage());
-                                        }
-                                        return null;
-                                    }
-                                });
-                    } else if (update.getOperStatus().equals(Interface.OperStatus.Down)) {
-                        DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
-                        dataStoreCoordinator.enqueueJob(interfaceName,
-                                new Callable<List<ListenableFuture<Void>>>() {
-                                    @Override
-                                    public List<ListenableFuture<Void>> call() throws Exception {
-                                        WriteTransaction writeConfigTxn = broker.newWriteOnlyTransaction();
-                                        WriteTransaction writeOperTxn = broker.newWriteOnlyTransaction();
-                                        vpnInterfaceManager.processVpnInterfaceDown(dpnId, interfaceName, ifIndex, true, false,
-                                                writeConfigTxn, writeOperTxn);
-                                        CheckedFuture<Void, TransactionCommitFailedException> futures = writeOperTxn.submit();
-                                        try {
-                                            futures.get();
-                                        } catch (InterruptedException | ExecutionException e) {
-                                            LOG.error("Error updating DOWN for interface {} from vpn {} on dpn {}", interfaceName,
-                                                    vpnInterface.getVpnInstanceName(), dpnId);
-                                            throw new RuntimeException(e.getMessage());
-                                        }
-                                        futures = writeConfigTxn.submit();
-                                        try {
-                                            futures.get();
-                                        } catch (InterruptedException | ExecutionException e) {
-                                            LOG.error("Error updating DOWN for interface {} from vpn {} on dpn {}", interfaceName,
-                                                    vpnInterface.getVpnInstanceName(), dpnId);
-                                            throw new RuntimeException(e.getMessage());
-                                        }
-                                        return null;
-                                    }
-                                });
-                    }
-                }
+        try {
+            OperStatus originalOperStatus = original.getOperStatus();
+            OperStatus updateOperStatus = update.getOperStatus();
+            if (originalOperStatus.equals(Interface.OperStatus.Unknown)
+                  || updateOperStatus.equals(Interface.OperStatus.Unknown)) {
+                LOG.debug("Interface {} state change is from/to null/UNKNOWN. Ignoring the update event.",
+                        interfaceName);
+                return;
             }
-        }
-    }
 
-    void handleRouterInterfacesUpEvent(String routerName, String interfaceName, WriteTransaction writeOperTxn) {
-        LOG.debug("Handling UP event for router interface {} in Router {}", interfaceName, routerName);
-        vpnInterfaceManager.addToNeutronRouterDpnsMap(routerName, interfaceName, writeOperTxn);
-    }
+            if (update.getIfIndex() == null) {
+                return;
+            }
+            if (L2vlan.class.equals(update.getType())) {
+                LOG.info("VPN Interface update event - intfName {} from InterfaceStateChangeListener",
+                        update.getName());
+                DataStoreJobCoordinator dataStoreCoordinator = DataStoreJobCoordinator.getInstance();
+                dataStoreCoordinator.enqueueJob("VPNINTERFACE-" + interfaceName,
+                    () -> {
+                        WriteTransaction writeConfigTxn = dataBroker.newWriteOnlyTransaction();
+                        WriteTransaction writeOperTxn = dataBroker.newWriteOnlyTransaction();
+                        WriteTransaction writeInvTxn = dataBroker.newWriteOnlyTransaction();
+                        List<ListenableFuture<Void>> futures = new ArrayList<>();
+                        final VpnInterface vpnInterface =
+                                VpnUtil.getConfiguredVpnInterface(dataBroker, interfaceName);
+                        if (vpnInterface != null) {
+                            final int ifIndex = update.getIfIndex();
+                            final BigInteger dpnId = InterfaceUtils.getDpIdFromInterface(update);
+                            if (update.getOperStatus().equals(Interface.OperStatus.Up)) {
+                                String primaryRd = VpnUtil.getPrimaryRd(dataBroker,
+                                        vpnInterface.getVpnInstanceName());
+                                if (!VpnUtil.isVpnPendingDelete(dataBroker, primaryRd)) {
+                                    LOG.info("VPN Interface update event - intfName {} onto vpnName {} running "
+                                                    + " oper-driven UP", vpnInterface.getName(),
+                                            vpnInterface.getVpnInstanceName());
+                                    if (!vpnInterfaceManager.isVpnInstanceReady(vpnInterface.getVpnInstanceName())) {
+                                        LOG.info("VPN Interface update event - intfName {} onto vpnName {} "
+                                                        + "running oper-driven UP, VpnInstance not ready, holding on",
+                                                vpnInterface.getName(), vpnInterface.getVpnInstanceName());
+                                        return futures;
+                                    }
+                                    vpnInterfaceManager.processVpnInterfaceUp(dpnId, vpnInterface, primaryRd, ifIndex,
+                                            true, writeConfigTxn, writeOperTxn, writeInvTxn, update);
+                                } else {
+                                    LOG.error("update: Ignoring UP event for vpnInterface {}, as vpnInstance {}"
+                                            + " with primaryRd {} is already marked for deletion", interfaceName,
+                                            vpnInterface.getVpnInstanceName(), primaryRd);
+                                }
+                            } else if (update.getOperStatus().equals(Interface.OperStatus.Down)) {
+                                LOG.info("VPN Interface update event - intfName {} onto vpnName {} running oper-driven"
+                                        + " DOWN", vpnInterface.getName(), vpnInterface.getVpnInstanceName());
+                                InstanceIdentifier<VpnInterface> id = VpnUtil.getVpnInterfaceIdentifier(interfaceName);
+                                Optional<VpnInterface> optVpnInterface =
+                                        VpnUtil.read(dataBroker, LogicalDatastoreType.OPERATIONAL, id);
+                                if (optVpnInterface.isPresent()) {
+                                    VpnInterface vpnOpInterface = optVpnInterface.get();
+                                    vpnInterfaceManager.processVpnInterfaceDown(dpnId, interfaceName, ifIndex, update,
+                                            vpnOpInterface, true, writeConfigTxn, writeOperTxn,
+                                            writeInvTxn);
+                                } else {
+                                    LOG.error("InterfaceStateChangeListener Update DOWN - vpnInterface {}"
+                                            + " not available, ignoring event", vpnInterface.getName());
+                                    return futures;
+                                }
+                            }
+                            ListenableFuture<Void> operFuture = writeOperTxn.submit();
+                            try {
+                                operFuture.get();
+                            } catch (ExecutionException e) {
+                                LOG.error("InterfaceStateChange - Exception encountered while submitting operational"
+                                        + " future for updateVpnInterface {}", vpnInterface.getName(), e);
+                                return null;
+                            }
+                            futures.add(writeConfigTxn.submit());
+                            futures.add(writeInvTxn.submit());
+                        } else {
+                            LOG.debug("Interface {} is not a vpninterface, ignoring.", interfaceName);
+                        }
 
-    void handleRouterInterfacesDownEvent(String routerName, String interfaceName, BigInteger dpnId,
-                                         WriteTransaction writeOperTxn) {
-        LOG.debug("Handling DOWN event for router interface {} in Router {}", interfaceName, routerName);
-        vpnInterfaceManager.removeFromNeutronRouterDpnsMap(routerName, interfaceName, dpnId, writeOperTxn);
+                        return futures;
+                    });
+            }
+        } catch (Exception e) {
+            LOG.error("Exception observed in handling updation of VPN Interface {}. ", update.getName(), e);
+        }
     }
-
 }