X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fhosttracker%2Fimplementation%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fhosttracker%2Finternal%2FHostTracker.java;h=df62c1985a62b5e7b11db450a39586d3ce0a8d58;hb=cf4834ff659cecdeb08a247679dfbf6b10f4ea73;hp=d7941f9cce19f90e9dc4494b5c074be3b90d4a82;hpb=6fda9993ad4fb9e0ac911543bbd87b7cd0eb1b0f;p=controller.git diff --git a/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java b/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java index d7941f9cce..df62c1985a 100644 --- a/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java +++ b/opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java @@ -24,6 +24,7 @@ import java.util.TimerTask; import java.util.concurrent.Callable; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; +import java.util.concurrent.CopyOnWriteArraySet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.Future; @@ -88,7 +89,7 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw static final String ACTIVE_HOST_CACHE = "hosttracker.ActiveHosts"; static final String INACTIVE_HOST_CACHE = "hosttracker.InactiveHosts"; private static final Logger logger = LoggerFactory.getLogger(HostTracker.class); - protected IHostFinder hostFinder; + protected final Set hostFinder = new CopyOnWriteArraySet();; protected ConcurrentMap hostsDB; /* * Following is a list of hosts which have been requested by NB APIs to be @@ -237,13 +238,15 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw } public void setArpHandler(IHostFinder hostFinder) { - this.hostFinder = hostFinder; + if (this.hostFinder != null) { + this.hostFinder.add(hostFinder); + } } public void unsetArpHandler(IHostFinder hostFinder) { - if (this.hostFinder == hostFinder) { + if (this.hostFinder != null) { logger.debug("Arp Handler Service removed!"); - this.hostFinder = null; + this.hostFinder.remove(hostFinder); } } @@ -343,8 +346,9 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw networkAddress.getHostAddress()); /* host is not found, initiate a discovery */ - - hostFinder.find(networkAddress); + for (IHostFinder hf : hostFinder) { + hf.find(networkAddress); + } return null; } @@ -512,8 +516,7 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw @Override public void hostListener(HostNodeConnector host) { - - logger.debug("ARP received for Host: IP {}, MAC {}, {}", host.getNetworkAddress().getHostAddress(), + logger.debug("Received for Host: IP {}, MAC {}, {}", host.getNetworkAddress().getHostAddress(), HexEncode.bytesToHexString(host.getDataLayerAddressBytes()), host); if (hostExists(host)) { HostNodeConnector existinghost = hostsDB.get(host.getNetworkAddress()); @@ -696,9 +699,9 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw int num = 1; for (ArrayList hierarchy : hierarchies) { StringBuffer buf = new StringBuffer(); - buf.append("Hierarchy#" + num + " : "); + buf.append("Hierarchy#").append(num).append(" : "); for (String switchName : hierarchy) { - buf.append(switchName + "/"); + buf.append(switchName).append("/"); } logger.debug("{} -> {}", getContainerName(), buf); num++; @@ -773,7 +776,6 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw */ @SuppressWarnings("unchecked") private void updateCurrentHierarchy(Node node, ArrayList currHierarchy, List> fullHierarchy) { - // currHierarchy.add(String.format("%x", currSw.getId())); currHierarchy.add(dpidToHostNameHack((Long) node.getID())); // Shallow copy as required ArrayList currHierarchyClone = (ArrayList) currHierarchy.clone(); @@ -909,7 +911,9 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw continue; } logger.debug("Sending the ARP from FailedARPReqList fors IP: {}", arphost.getHostIP().getHostAddress()); - hostFinder.find(arphost.getHostIP()); + for (IHostFinder hf : hostFinder) { + hf.find(arphost.getHostIP()); + } } } } @@ -945,7 +949,9 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw logger.warn("ARPHandler Services are not available for Outstanding ARPs"); continue; } - hostFinder.find(arphost.getHostIP()); + for (IHostFinder hf : hostFinder) { + hf.find(arphost.getHostIP()); + } arphost.sent_count++; logger.debug("ARP Sent from ARPPending List, IP: {}", arphost.getHostIP().getHostAddress()); } else if (arphost.getSent_count() >= hostRetryCount) { @@ -1029,7 +1035,9 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw logger.trace("ARPHandler is not avaialable, can't send the probe"); continue; } - hostFinder.probe(host); + for (IHostFinder hf : hostFinder) { + hf.probe(host); + } } } } @@ -1334,7 +1342,9 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw try { byte[] dataLayerAddress = NetUtils.getBroadcastMACAddr(); host = new HostNodeConnector(dataLayerAddress, arphost.getHostIP(), nodeConnector, (short) 0); - hostFinder.probe(host); + for (IHostFinder hf : hostFinder) { + hf.probe(host); + } } catch (ConstructionException e) { logger.debug("HostNodeConnector couldn't be created for Host: {}, NodeConnector: {}", arphost.getHostIP(), nodeConnector);