+ if (log.isTraceEnabled()) {
+ log.trace(
+ "Sending ARP Reply with src {}/{}, target {}/{}",
+ new Object[] { HexEncode.bytesToHexString(sourceMAC), sourceIP,
+ HexEncode.bytesToHexString(host.getDataLayerAddressBytes()), host.getNetworkAddress() });
+ }
+ if (connectionManager.getLocalityStatus(host.getnodeconnectorNode()) == ConnectionLocality.LOCAL) {
+ sendARPReply(host.getnodeConnector(), sourceMAC, sourceIP, host.getDataLayerAddressBytes(),
+ host.getNetworkAddress());
+ } else {
+ /*
+ * In the remote event a requestor moved to another controller
+ * it may turn out it now we need to send the ARP reply from a
+ * different controller, this cover the case
+ */
+ arpRequestReplyEvent.put(
+ new ARPReply(host.getnodeConnector(), sourceIP, sourceMAC, host.getNetworkAddress(), host
+ .getDataLayerAddressBytes()), false);
+ }
+ }
+ }
+
+ @Override
+ public void entryUpdated(ARPEvent key, Boolean new_value, String cacheName, boolean originLocal) {
+ log.trace("Got and entryUpdated for cacheName {} key {} isNew {}", cacheName, key, new_value);
+ enqueueARPCacheEvent(key, new_value);
+ }
+
+ @Override
+ public void entryCreated(ARPEvent key, String cacheName, boolean originLocal) {
+ // nothing to do
+ }
+
+ @Override
+ public void entryDeleted(ARPEvent key, String cacheName, boolean originLocal) {
+ // nothing to do
+ }
+
+ private void enqueueARPCacheEvent(ARPEvent event, boolean new_value) {
+ try {
+ ARPCacheEvent cacheEvent = new ARPCacheEvent(event, new_value);
+ if (!ARPCacheEvents.contains(cacheEvent)) {
+ this.ARPCacheEvents.add(cacheEvent);
+ log.trace("Enqueued {}", event);
+ }
+ } catch (Exception e) {
+ log.debug("enqueueARPCacheEvent caught Interrupt Exception for event {}", event);
+ }
+ }
+
+ /*
+ * this thread monitors the connectionEvent queue for new incoming events
+ * from
+ */
+ private class ARPCacheEventHandler implements Runnable {
+ @Override
+ public void run() {
+ while (!stopping) {
+ try {
+ ARPCacheEvent ev = ARPCacheEvents.take();
+ ARPEvent event = ev.getEvent();
+ if (event instanceof ARPRequest) {
+ ARPRequest req = (ARPRequest) event;
+ // If broadcast request
+ if (req.getHost() == null) {
+ log.trace("Trigger and ARP Broadcast Request upon receipt of {}", req);
+ sendBcastARPRequest(req.getTargetIP(), req.getSubnet());
+
+ // If unicast and local, send reply
+ } else if (connectionManager.getLocalityStatus(req.getHost().getnodeconnectorNode()) == ConnectionLocality.LOCAL) {
+ log.trace("ARPCacheEventHandler - sendUcatARPRequest upon receipt of {}", req);
+ sendUcastARPRequest(req.getHost(), req.getSubnet());
+ }
+ } else if (event instanceof ARPReply) {
+ ARPReply rep = (ARPReply) event;
+ // New reply received by controller, notify all awaiting
+ // requestors across the cluster
+ if (ev.isNewReply()) {
+ log.trace("Trigger a generateAndSendReply in response to {}", rep);
+ generateAndSendReply(rep.getTargetIP(), rep.getTargetMac());
+ // Otherwise, a specific reply. If local, send out.
+ } else if (connectionManager.getLocalityStatus(rep.getPort().getNode()) == ConnectionLocality.LOCAL) {
+ log.trace("ARPCacheEventHandler - sendUcatARPReply locally in response to {}", rep);
+ sendARPReply(rep.getPort(), rep.getSourceMac(), rep.getSourceIP(), rep.getTargetMac(),
+ rep.getTargetIP());
+ }
+ }
+ } catch (InterruptedException e) {
+ ARPCacheEvents.clear();
+ return;
+ }
+ }