Removing invalid casts from hosttracker.
[controller.git] / opendaylight / hosttracker / implementation / src / main / java / org / opendaylight / controller / hosttracker / internal / HostTracker.java
index 7c312e1577b927850e3c11839c3b817cb9282238..f8534e98101702b6ce1039714eb9a647392cf85f 100644 (file)
@@ -140,12 +140,12 @@ public class HostTracker implements IfIptoHost, IfHostListener,
      * wasn't created for this host in the controller. This would cause
      * arphandler not to know where to send the ARP 2. The host facing port is
      * down 3. The IP host doesn't exist or is not responding to ARP requests
-     * 
+     *
      * Conditions 1 and 2 above can be recovered if ARP is sent when the
      * relevant L3 interface is added or the port facing host comes up. Whenever
      * L3 interface is added or host facing port comes up, ARP will be sent to
      * hosts in this list.
-     * 
+     *
      * We can't recover from condition 3 above
      */
     private ArrayList<ARPPending> failedARPReqList = new ArrayList<HostTracker.ARPPending>();
@@ -394,8 +394,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
         arphost.setHostIP(networkAddr);
         arphost.setSent_count((short) 1);
         ARPPendingList.add(arphost);
-        logger.debug("Host Added to ARPPending List, IP: {}",
-                networkAddr.toString());
+        logger.debug("Host Added to ARPPending List, IP: {}", networkAddr);
     }
 
     private void removePendingARPFromList(int index) {
@@ -434,7 +433,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
                  */
                 removePendingARPFromList(i);
                 logger.debug("Host Removed from ARPPending List, IP: {}",
-                        networkAddr.toString());
+                          networkAddr);
                 return;
             }
         }
@@ -452,7 +451,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
                  */
                 failedARPReqList.remove(i);
                 logger.debug("Host Removed from FailedARPReqList List, IP: {}",
-                        networkAddr.toString());
+                        networkAddr);
                 return;
             }
         }
@@ -576,25 +575,6 @@ public class HostTracker implements IfIptoHost, IfHostListener,
                 Tier tier = new Tier(1);
                 switchManager.setNodeProp(node, tier);
                 topologyManager.updateHostLink(p, h, UpdateType.ADDED, null);
-                /*
-                 * This is a temporary fix for Cisco Live's Hadoop
-                 * Demonstration. The concept of Tiering must be revisited based
-                 * on other application requirements and the design might
-                 * warrant a separate module (as it involves tracking the
-                 * topology/ host changes & updating the Tiering numbers in an
-                 * effective manner).
-                 */
-                updateSwitchTiers(node, 1);
-
-                /*
-                 * The following 2 lines are added for testing purposes. We can
-                 * remove it once the North-Bound APIs are available for
-                 * testing.
-                 * 
-                 * ArrayList<ArrayList<String>> hierarchies =
-                 * getHostNetworkHierarchy(host.getNetworkAddress());
-                 * logHierarchies(hierarchies);
-                 */
             } else {
                 // No need to reset the tiering if no other hosts are currently
                 // connected
@@ -611,10 +591,10 @@ public class HostTracker implements IfIptoHost, IfHostListener,
      * When a new Host is learnt by the hosttracker module, it places the
      * directly connected Node in Tier-1 & using this function, updates the Tier
      * value for all other Nodes in the network hierarchy.
-     * 
+     *
      * This is a recursive function and it takes care of updating the Tier value
      * for all the connected and eligible Nodes.
-     * 
+     *
      * @param n
      *            Node that represents one of the Vertex in the Topology Graph.
      * @param currentTier
@@ -663,7 +643,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
      * Internal convenience routine to check the eligibility of a Switch for a
      * Tier update. Any Node with Tier=0 or a Tier value that is greater than
      * the new Tier Value is eligible for the update.
-     * 
+     *
      * @param n
      *            Node for which the Tier update eligibility is checked
      * @param tier
@@ -727,7 +707,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
             for (String switchName : hierarchy) {
                 buf.append(switchName + "/");
             }
-            logger.debug("{} -> {}", getContainerName(), buf.toString());
+            logger.debug("{} -> {}", getContainerName(), buf);
             num++;
         }
     }
@@ -737,7 +717,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
      * that returns the Network Hierarchy for a given Host. This API is
      * typically used by applications like Hadoop for Rack Awareness
      * functionality.
-     * 
+     *
      * @param hostAddress
      *            IP-Address of the host/node.
      * @return Network Hierarchies represented by an Array of Array (of
@@ -762,7 +742,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
      * is used as the network for Hadoop Demos & in order to give a meaningful
      * rack-awareness switch names, the DPID is organized in ASCII Characters
      * and retrieved as string.
-     * 
+     *
      * @param dpid
      *            Switch DataPath Id
      * @return Ascii String represented by the DPID.
@@ -785,7 +765,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
 
     /**
      * A convenient recursive routine to obtain the Hierarchy of Switches.
-     * 
+     *
      * @param node
      *            Current Node in the Recursive routine.
      * @param currHierarchy
@@ -899,16 +879,6 @@ public class HostTracker implements IfIptoHost, IfHostListener,
         logger.debug(
                 "HostTracker Topology linkUpdate handling src:{}[port {}] dst:{}[port {}] added: {}",
                 new Object[] { srcNid, srcPort, dstNid, dstPort, added });
-        clearTiers();
-        for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
-            HostNodeConnector host = entry.getValue();
-            Node node = host.getnodeconnectorNode();
-            if (node != null) {
-                Tier t = new Tier(1);
-                switchManager.setNodeProp(node, t);
-                updateSwitchTiers(node, 1);
-            }
-        }
     }
 
     @Override
@@ -1020,13 +990,15 @@ public class HostTracker implements IfIptoHost, IfHostListener,
                      * Use the services of arphandler to check if host is still
                      * there
                      */
-                    logger.trace(
-                            "ARP Probing ({}) for {}({})",
-                            new Object[] {
-                                    arp_cntdown,
-                                    host.getNetworkAddress().getHostAddress(),
-                                    HexEncode.bytesToHexString(host
-                                            .getDataLayerAddressBytes()) });
+                    if (logger.isTraceEnabled()) {
+                      logger.trace(
+                              "ARP Probing ({}) for {}({})",
+                              new Object[] {
+                                      arp_cntdown,
+                                      host.getNetworkAddress().getHostAddress(),
+                                      HexEncode.bytesToHexString(host
+                                              .getDataLayerAddressBytes()) });
+                    }
                     host.setArpSendCountDown(arp_cntdown);
                     hostFinder.probe(host);
                 }
@@ -1037,7 +1009,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
     /**
      * Inform the controller IP to MAC binding of a host and its connectivity to
      * an openflow switch in terms of Node, port, and VLAN.
-     * 
+     *
      * @param networkAddr
      *            IP address of the host
      * @param dataLayer
@@ -1048,7 +1020,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
      *            Port of the switch to which host is connected
      * @param vlan
      *            Vlan of which this host is member of
-     * 
+     *
      * @return Status The status object as described in {@code Status}
      *         indicating the result of this action.
      */
@@ -1095,7 +1067,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
     /**
      * Update the controller IP to MAC binding of a host and its connectivity to
      * an openflow switch in terms of switch id, switch port, and VLAN.
-     * 
+     *
      * @param networkAddr
      *            IP address of the host
      * @param dataLayer
@@ -1106,7 +1078,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
      *            Port of the switch to which host is connected
      * @param vlan
      *            Vlan of which this host is member of
-     * 
+     *
      * @return boolean true if the host was added successfully, false otherwise
      */
     public boolean updateHostReq(InetAddress networkAddr,
@@ -1135,10 +1107,10 @@ public class HostTracker implements IfIptoHost, IfHostListener,
     /**
      * Remove from the controller IP to MAC binding of a host and its
      * connectivity to an openflow switch
-     * 
+     *
      * @param networkAddr
      *            IP address of the host
-     * 
+     *
      * @return boolean true if the host was removed successfully, false
      *         otherwise
      */
@@ -1188,15 +1160,12 @@ public class HostTracker implements IfIptoHost, IfHostListener,
 
         switch (type) {
         case REMOVED:
-            long sid = (Long) node.getID();
-            logger.debug("Received removedSwitch for sw id {}",
-                    HexEncode.longToHexString(sid));
+            logger.debug("Received removed node {}", node);
             for (Entry<InetAddress, HostNodeConnector> entry : hostsDB
                     .entrySet()) {
                 HostNodeConnector host = entry.getValue();
-                if (host.getnodeconnectornodeId() == sid) {
-                    logger.debug("Switch: {} is down, remove from Hosts_DB",
-                            sid);
+                if (host.getnodeconnectorNode().equals(node)) {
+                    logger.debug("Node: {} is down, remove from Hosts_DB", node);
                     removeKnownHost(entry.getKey());
                     notifyHostLearnedOrRemoved(host, false);
                 }
@@ -1286,18 +1255,12 @@ public class HostTracker implements IfIptoHost, IfHostListener,
     }
 
     private void handleNodeConnectorStatusDown(NodeConnector nodeConnector) {
-        long sid = (Long) nodeConnector.getNode().getID();
-        short port = (Short) nodeConnector.getID();
-
         logger.debug("handleNodeConnectorStatusDown {}", nodeConnector);
 
         for (Entry<InetAddress, HostNodeConnector> entry : hostsDB.entrySet()) {
             HostNodeConnector host = entry.getValue();
-            if ((host.getnodeconnectornodeId() == sid)
-                    && (host.getnodeconnectorportId() == port)) {
-                logger.debug(
-                        "Switch: {}, Port: {} is down, remove from Hosts_DB",
-                        sid, port);
+            if (host.getnodeConnector().equals(nodeConnector)) {
+                logger.debug(" NodeConnector: {} is down, remove from Hosts_DB", nodeConnector);
                 removeKnownHost(entry.getKey());
                 notifyHostLearnedOrRemoved(host, false);
             }
@@ -1337,7 +1300,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
     /**
      * Function called by the dependency manager when all the required
      * dependencies are satisfied
-     * 
+     *
      */
     void init(Component c) {
         Dictionary<?, ?> props = c.getServiceProperties();
@@ -1355,7 +1318,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
      * Function called by the dependency manager when at least one dependency
      * become unsatisfied or when the component is shutting down because for
      * example bundle is being stopped.
-     * 
+     *
      */
     void destroy() {
         destroyCache();
@@ -1364,7 +1327,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
     /**
      * Function called by dependency manager after "init ()" is called and after
      * the services provided by the class are registered in the service registry
-     * 
+     *
      */
     void start() {
     }
@@ -1373,7 +1336,7 @@ public class HostTracker implements IfIptoHost, IfHostListener,
      * Function called by the dependency manager before the services exported by
      * the component are unregistered, this will be followed by a "destroy ()"
      * calls
-     * 
+     *
      */
     void stop() {
     }