Merge "L2 Gw create changes related to ITM Tunnels creation in neutronvpn module"
[vpnservice.git] / interfacemgr / interfacemgr-impl / src / main / java / org / opendaylight / vpnservice / interfacemgr / listeners / InterfaceConfigListener.java
index a8457c551e7206fab8356f7f6df2eb0177b8e980..7e764aa0adbf251eb91113734a7719abfda0db3f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. and others.  All rights reserved.
+ * Copyright (c) 2015 - 2016 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,
@@ -16,8 +16,11 @@ import org.opendaylight.vpnservice.datastoreutils.DataStoreJobCoordinator;
 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsInterfaceConfigAddHelper;
 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsInterfaceConfigRemoveHelper;
 import org.opendaylight.vpnservice.interfacemgr.renderer.ovs.confighelpers.OvsInterfaceConfigUpdateHelper;
+import org.opendaylight.vpnservice.mdsalutil.interfaces.IMdsalApiManager;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.Interfaces;
 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev140508.interfaces.Interface;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.alivenessmonitor.rev150629.AlivenessMonitorService;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.idmanager.rev150403.IdManagerService;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.vpnservice.interfacemgr.rev150331.ParentRefs;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.slf4j.Logger;
@@ -33,12 +36,19 @@ import java.util.concurrent.Callable;
 public class InterfaceConfigListener extends AsyncDataTreeChangeListenerBase<Interface, InterfaceConfigListener> {
     private static final Logger LOG = LoggerFactory.getLogger(InterfaceConfigListener.class);
     private DataBroker dataBroker;
-    private IdManager idManager;
-
-    public InterfaceConfigListener(final DataBroker dataBroker, final IdManager idManager) {
+    private IdManagerService idManager;
+    private AlivenessMonitorService alivenessMonitorService;
+    private IMdsalApiManager mdsalApiManager;
+    private static final int MAX_RETRIES = 3;
+
+    public InterfaceConfigListener(final DataBroker dataBroker, final IdManagerService idManager,
+                                   final AlivenessMonitorService alivenessMonitorService,
+                                   final IMdsalApiManager mdsalApiManager) {
         super(Interface.class, InterfaceConfigListener.class);
         this.dataBroker = dataBroker;
         this.idManager = idManager;
+        this.alivenessMonitorService = alivenessMonitorService;
+        this.mdsalApiManager = mdsalApiManager;
     }
 
     @Override
@@ -55,62 +65,38 @@ public class InterfaceConfigListener extends AsyncDataTreeChangeListenerBase<Int
     protected void remove(InstanceIdentifier<Interface> key, Interface interfaceOld) {
         LOG.debug("Received Interface Remove Event: {}, {}", key, interfaceOld);
         String ifName = interfaceOld.getName();
-        String parentInterface = null;
-
         ParentRefs parentRefs = interfaceOld.getAugmentation(ParentRefs.class);
-        if (parentRefs != null) {
-            parentInterface = parentRefs.getParentInterface();
-            if (parentInterface != null && !parentInterface.equals(ifName)) {
-                return;
-            }
-            if (parentRefs.getDatapathNodeIdentifier() == null) {
-                return;
-            }
-        }
-
         DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
         RendererConfigRemoveWorker configWorker = new RendererConfigRemoveWorker(key, interfaceOld, ifName, parentRefs);
-        coordinator.enqueueJob(ifName, configWorker);
+        coordinator.enqueueJob(ifName, configWorker, MAX_RETRIES);
     }
 
     @Override
     protected void update(InstanceIdentifier<Interface> key, Interface interfaceOld, Interface interfaceNew) {
         LOG.debug("Received Interface Update Event: {}, {}, {}", key, interfaceOld, interfaceNew);
         String ifNameNew = interfaceNew.getName();
-        String parentInterface = null;
-
         ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
-        if (parentRefs != null) {
-            parentInterface = parentRefs.getParentInterface();
-        }
-
-        if (parentInterface != null && !parentInterface.equals(ifNameNew)) {
+        if (parentRefs == null || parentRefs.getDatapathNodeIdentifier() == null && parentRefs.getParentInterface() == null) {
+            LOG.error("parent refs not specified for {}",interfaceNew.getName());
             return;
         }
-
         DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
         RendererConfigUpdateWorker worker = new RendererConfigUpdateWorker(key, interfaceOld, interfaceNew, ifNameNew);
-        coordinator.enqueueJob(ifNameNew, worker);
+        coordinator.enqueueJob(ifNameNew, worker, MAX_RETRIES);
     }
 
     @Override
     protected void add(InstanceIdentifier<Interface> key, Interface interfaceNew) {
         LOG.debug("Received Interface Add Event: {}, {}", key, interfaceNew);
         String ifName = interfaceNew.getName();
-        String parentInterface = null;
-
         ParentRefs parentRefs = interfaceNew.getAugmentation(ParentRefs.class);
-        if (parentRefs != null) {
-            parentInterface = parentRefs.getParentInterface();
-        }
-
-        if (parentInterface != null && !parentInterface.equals(ifName)) {
+        if (parentRefs == null || parentRefs.getDatapathNodeIdentifier() == null && parentRefs.getParentInterface() == null) {
+            LOG.error("parent refs not specified for {}",interfaceNew.getName());
             return;
         }
-
         DataStoreJobCoordinator coordinator = DataStoreJobCoordinator.getInstance();
         RendererConfigAddWorker configWorker = new RendererConfigAddWorker(key, interfaceNew, parentRefs, ifName);
-        coordinator.enqueueJob(ifName, configWorker);
+        coordinator.enqueueJob(ifName, configWorker, MAX_RETRIES);
     }
 
     private class RendererConfigAddWorker implements Callable<List<ListenableFuture<Void>>> {
@@ -131,7 +117,8 @@ public class InterfaceConfigListener extends AsyncDataTreeChangeListenerBase<Int
         public List<ListenableFuture<Void>> call() throws Exception {
             // If another renderer(for eg : CSS) needs to be supported, check can be performed here
             // to call the respective helpers.
-            return OvsInterfaceConfigAddHelper.addConfiguration(dataBroker, parentRefs, interfaceNew, idManager);
+            return OvsInterfaceConfigAddHelper.addConfiguration(dataBroker, parentRefs, interfaceNew,
+                    idManager, alivenessMonitorService, mdsalApiManager);
         }
 
         @Override
@@ -165,7 +152,8 @@ public class InterfaceConfigListener extends AsyncDataTreeChangeListenerBase<Int
         public List<ListenableFuture<Void>> call() throws Exception {
             // If another renderer(for eg : CSS) needs to be supported, check can be performed here
             // to call the respective helpers.
-            return OvsInterfaceConfigUpdateHelper.updateConfiguration(dataBroker, idManager, interfaceNew, interfaceOld);
+            return OvsInterfaceConfigUpdateHelper.updateConfiguration(dataBroker, alivenessMonitorService, idManager,
+                    mdsalApiManager, interfaceNew, interfaceOld);
         }
 
         @Override
@@ -200,7 +188,8 @@ public class InterfaceConfigListener extends AsyncDataTreeChangeListenerBase<Int
         public List<ListenableFuture<Void>> call() throws Exception {
             // If another renderer(for eg : CSS) needs to be supported, check can be performed here
             // to call the respective helpers.
-            return OvsInterfaceConfigRemoveHelper.removeConfiguration(dataBroker, interfaceOld, idManager, parentRefs);
+            return OvsInterfaceConfigRemoveHelper.removeConfiguration(dataBroker, alivenessMonitorService,
+                    interfaceOld, idManager, mdsalApiManager, parentRefs);
         }
 
         @Override