Process host pending list on a Cache sync update. 12/812/2
authorMadhu Venugopal <vmadhu@cisco.com>
Wed, 7 Aug 2013 05:27:20 +0000 (22:27 -0700)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 7 Aug 2013 07:43:53 +0000 (07:43 +0000)
In a Clustered Controller environment, with switches connected to different controllers, ARP messages originated from
a Controller may not see the ARP reply on the same controller. The ARP response from the Host might end up in another
controller. Hence it is not appropriate to expect responses from host to terminate in the originating controller.
discoverHost is one such method that has this wrong assumption. This fix is to listen to Active Cache update and
trigger a Pending list processing (In addition to existing code that just waits on a Future object for ARP response
on the local controller).

Change-Id: I4223db66ff75bbf4d60011c9581e4dff594c0a9c
Signed-off-by: Madhu Venugopal <vmadhu@cisco.com>
opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/Activator.java
opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java

index 65cb8225c856ef9d5c0a693284e3266e72c0a2ae..e60b02d83b881a06f215644d7af8216369921357 100644 (file)
@@ -8,7 +8,13 @@
 
 package org.opendaylight.controller.hosttracker.internal;
 
+import java.util.Dictionary;
+import java.util.HashSet;
+import java.util.Hashtable;
+import java.util.Set;
+
 import org.apache.felix.dm.Component;
+import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
 import org.opendaylight.controller.hosttracker.IfHostListener;
 import org.opendaylight.controller.hosttracker.IfIptoHost;
@@ -74,13 +80,19 @@ public class Activator extends ComponentActivatorAbstractBase {
      */
     public void configureInstance(Component c, Object imp, String containerName) {
         if (imp.equals(HostTracker.class)) {
+            Dictionary<String, Object> props = new Hashtable<String, Object>();
+            Set<String> propSet = new HashSet<String>();
+            propSet.add(HostTracker.ACTIVE_HOST_CACHE);
+            props.put("cachenames", propSet);
+
             // export the service
             c.setInterface(
                     new String[] { ISwitchManagerAware.class.getName(),
                             IInventoryListener.class.getName(),
                             IfIptoHost.class.getName(),
                             IfHostListener.class.getName(),
-                            ITopologyManagerAware.class.getName() }, null);
+                            ITopologyManagerAware.class.getName(),
+                            ICacheUpdateAware.class.getName() }, props);
 
             c.add(createContainerServiceDependency(containerName)
                     .setService(ISwitchManager.class)
index 0f07ff60af44433fbd11ad784b57c75e691f4cdf..3ff474732fe01628996d0c8685b04910080b26e3 100644 (file)
@@ -31,6 +31,7 @@ import java.util.concurrent.Future;
 import org.apache.felix.dm.Component;
 import org.opendaylight.controller.clustering.services.CacheConfigException;
 import org.opendaylight.controller.clustering.services.CacheExistException;
+import org.opendaylight.controller.clustering.services.ICacheUpdateAware;
 import org.opendaylight.controller.clustering.services.IClusterContainerServices;
 import org.opendaylight.controller.clustering.services.IClusterServices;
 import org.opendaylight.controller.hosttracker.IfHostListener;
@@ -79,7 +80,9 @@ import org.slf4j.LoggerFactory;
  */
 
 public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAware, IInventoryListener,
-        ITopologyManagerAware {
+        ITopologyManagerAware, ICacheUpdateAware<InetAddress, HostNodeConnector> {
+    static final String ACTIVE_HOST_CACHE = "hostTrackerAH";
+    static final String INACTIVE_HOST_CACHE = "hostTrackerIH";
     private static final Logger logger = LoggerFactory.getLogger(HostTracker.class);
     private IHostFinder hostFinder;
     private ConcurrentMap<InetAddress, HostNodeConnector> hostsDB;
@@ -173,9 +176,9 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
         }
         logger.debug("Creating Cache for HostTracker");
         try {
-            this.clusterContainerService.createCache("hostTrackerAH",
+            this.clusterContainerService.createCache(ACTIVE_HOST_CACHE,
                     EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
-            this.clusterContainerService.createCache("hostTrackerIH",
+            this.clusterContainerService.createCache(INACTIVE_HOST_CACHE,
                     EnumSet.of(IClusterServices.cacheMode.NON_TRANSACTIONAL));
         } catch (CacheConfigException cce) {
             logger.error("Cache couldn't be created for HostTracker -  check cache mode");
@@ -193,14 +196,14 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
         }
         logger.debug("Retrieving cache for HostTrackerAH");
         hostsDB = (ConcurrentMap<InetAddress, HostNodeConnector>) this.clusterContainerService
-                .getCache("hostTrackerAH");
+                .getCache(ACTIVE_HOST_CACHE);
         if (hostsDB == null) {
             logger.error("Cache couldn't be retrieved for HostTracker");
         }
         logger.debug("Cache was successfully retrieved for HostTracker");
         logger.debug("Retrieving cache for HostTrackerIH");
         inactiveStaticHosts = (ConcurrentMap<NodeConnector, HostNodeConnector>) this.clusterContainerService
-                .getCache("hostTrackerIH");
+                .getCache(INACTIVE_HOST_CACHE);
         if (inactiveStaticHosts == null) {
             logger.error("Cache couldn't be retrieved for HostTrackerIH");
         }
@@ -401,7 +404,7 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
         }
     }
 
-    private void ProcPendingARPReqs(InetAddress networkAddr) {
+    private void processPendingARPReqs(InetAddress networkAddr) {
         ARPPending arphost;
 
         for (int i = 0; i < ARPPendingList.size(); i++) {
@@ -469,7 +472,7 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
         notifyHostLearnedOrRemoved(removedHost, false);
         notifyHostLearnedOrRemoved(newHost, true);
         if (!newHost.isStaticHost()) {
-            ProcPendingARPReqs(networkAddr);
+            processPendingARPReqs(networkAddr);
         }
     }
 
@@ -520,7 +523,7 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
             }
 
             /* check if there is an outstanding request for this host */
-            ProcPendingARPReqs(networkAddr);
+            processPendingARPReqs(networkAddr);
             notifyHostLearnedOrRemoved(host, true);
         }
     }
@@ -1409,4 +1412,21 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
 
     }
 
+    @Override
+    public void entryCreated(InetAddress key, String cacheName,
+            boolean originLocal) {
+        if (originLocal) return;
+        processPendingARPReqs(key);
+    }
+
+    @Override
+    public void entryUpdated(InetAddress key, HostNodeConnector new_value,
+            String cacheName, boolean originLocal) {
+    }
+
+    @Override
+    public void entryDeleted(InetAddress key, String cacheName,
+            boolean originLocal) {
+    }
+
 }