Merge "Fixed a bug and added a function for operating on MAC addresses."
authorGiovanni Meo <gmeo@cisco.com>
Wed, 31 Jul 2013 08:02:48 +0000 (08:02 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 31 Jul 2013 08:02:48 +0000 (08:02 +0000)
opendaylight/hosttracker/implementation/src/main/java/org/opendaylight/controller/hosttracker/internal/HostTracker.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/FlowOnNode.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeConnectorStatistics.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeDescription.java
opendaylight/sal/api/src/main/java/org/opendaylight/controller/sal/reader/NodeTableStatistics.java
opendaylight/statisticsmanager/implementation/src/main/java/org/opendaylight/controller/statisticsmanager/internal/StatisticsManager.java

index f600e6b2acc3afbe456b616ae97aadecfd7f056e..af983b3c8b70b61ee804f3d3af8837d2f917bc53 100644 (file)
@@ -95,7 +95,7 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
     private IClusterContainerServices clusterContainerService = null;
     private ISwitchManager switchManager = null;
     private Timer timer;
-    private Timer arp_refresh_timer;
+    private Timer arpRefreshTimer;
     private String containerName = null;
     private ExecutorService executor;
     private static class ARPPending {
@@ -160,8 +160,8 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
         timer.schedule(new OutStandingARPHandler(), 4000, 4000);
         executor = Executors.newFixedThreadPool(2);
         /* ARP Refresh Timer to go off every 5 seconds to implement ARP aging */
-        arp_refresh_timer = new Timer();
-        arp_refresh_timer.schedule(new ARPRefreshHandler(), 5000, 5000);
+        arpRefreshTimer = new Timer();
+        arpRefreshTimer.schedule(new ARPRefreshHandler(), 5000, 5000);
         logger.debug("startUp: Caches created, timers started");
     }
 
@@ -911,7 +911,6 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
         public void run() {
             ARPPending arphost;
             /* This routine runs every 4 seconds */
-            // logger.info ("ARP Handler called");
             for (int i = 0; i < ARPPendingList.size(); i++) {
                 arphost = ARPPendingList.get(i);
                 if (arphost.getSent_count() < switchManager.getHostRetryCount()) {
@@ -943,7 +942,7 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
                     failedARPReqList.add(arphost);
 
                 } else {
-                    logger.error("Inavlid arp_sent count for entery at index: {}", i);
+                    logger.error("Inavlid arp_sent count for entry at index: {}", i);
                 }
             }
         }
@@ -1386,7 +1385,12 @@ public class HostTracker implements IfIptoHost, IfHostListener, ISwitchManagerAw
      * calls
      *
      */
-    void stop() {
+    void stop(){
+    }
+
+    void stopping() {
+        arpRefreshTimer.cancel();
+        timer.cancel();
         executor.shutdown();
     }
 
index 163d04b3ffc253ed028d25b8a8d70686c82b325e..994ee4533e077ab3ad74e65f08306d10a9910320 100644 (file)
@@ -114,6 +114,56 @@ public class FlowOnNode implements Serializable{
         this.durationNanoseconds = durationNanoseconds;
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (int) (byteCount ^ (byteCount >>> 32));
+        result = prime * result + durationNanoseconds;
+        result = prime * result + durationSeconds;
+        result = prime * result + ((flow == null) ? 0 : flow.hashCode());
+        result = prime * result + (int) (packetCount ^ (packetCount >>> 32));
+        result = prime * result + tableId;
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof FlowOnNode)) {
+            return false;
+        }
+        FlowOnNode other = (FlowOnNode) obj;
+        if (byteCount != other.byteCount) {
+            return false;
+        }
+        if (durationNanoseconds != other.durationNanoseconds) {
+            return false;
+        }
+        if (durationSeconds != other.durationSeconds) {
+            return false;
+        }
+        if (flow == null) {
+            if (other.flow != null) {
+                return false;
+            }
+        } else if (!flow.equals(other.flow)) {
+            return false;
+        }
+        if (packetCount != other.packetCount) {
+            return false;
+        }
+        if (tableId != other.tableId) {
+            return false;
+        }
+        return true;
+    }
+
     @Override
     public String toString() {
         return "FlowOnNode[flow =" + flow + ", tableId = " + tableId
index 848b19ee0f0d98070c9571b96a4434741aaef735..fc6a6d87f1c39139c9b29f1a55c060b53f78451d 100644 (file)
@@ -18,7 +18,7 @@ import javax.xml.bind.annotation.XmlRootElement;
 import org.opendaylight.controller.sal.core.NodeConnector;
 
 /**
- * Represents the statistics for the node conenctor
+ * Represents the statistics for a node connector
  */
 @XmlRootElement
 @XmlAccessorType(XmlAccessType.NONE)
@@ -52,6 +52,84 @@ public class NodeConnectorStatistics implements Serializable {
     @XmlElement
     private long collisionCount;
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + (int) (collisionCount ^ (collisionCount >>> 32));
+        result = prime * result + ((nodeConnector == null) ? 0 : nodeConnector.hashCode());
+        result = prime * result + (int) (receiveBytes ^ (receiveBytes >>> 32));
+        result = prime * result + (int) (receiveCrcError ^ (receiveCrcError >>> 32));
+        result = prime * result + (int) (receiveDrops ^ (receiveDrops >>> 32));
+        result = prime * result + (int) (receiveErrors ^ (receiveErrors >>> 32));
+        result = prime * result + (int) (receiveFrameError ^ (receiveFrameError >>> 32));
+        result = prime * result + (int) (receiveOverRunError ^ (receiveOverRunError >>> 32));
+        result = prime * result + (int) (receivePackets ^ (receivePackets >>> 32));
+        result = prime * result + (int) (transmitBytes ^ (transmitBytes >>> 32));
+        result = prime * result + (int) (transmitDrops ^ (transmitDrops >>> 32));
+        result = prime * result + (int) (transmitErrors ^ (transmitErrors >>> 32));
+        result = prime * result + (int) (transmitPackets ^ (transmitPackets >>> 32));
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof NodeConnectorStatistics)) {
+            return false;
+        }
+        NodeConnectorStatistics other = (NodeConnectorStatistics) obj;
+        if (collisionCount != other.collisionCount) {
+            return false;
+        }
+        if (nodeConnector == null) {
+            if (other.nodeConnector != null) {
+                return false;
+            }
+        } else if (!nodeConnector.equals(other.nodeConnector)) {
+            return false;
+        }
+        if (receiveBytes != other.receiveBytes) {
+            return false;
+        }
+        if (receiveCrcError != other.receiveCrcError) {
+            return false;
+        }
+        if (receiveDrops != other.receiveDrops) {
+            return false;
+        }
+        if (receiveErrors != other.receiveErrors) {
+            return false;
+        }
+        if (receiveFrameError != other.receiveFrameError) {
+            return false;
+        }
+        if (receiveOverRunError != other.receiveOverRunError) {
+            return false;
+        }
+        if (receivePackets != other.receivePackets) {
+            return false;
+        }
+        if (transmitBytes != other.transmitBytes) {
+            return false;
+        }
+        if (transmitDrops != other.transmitDrops) {
+            return false;
+        }
+        if (transmitErrors != other.transmitErrors) {
+            return false;
+        }
+        if (transmitPackets != other.transmitPackets) {
+            return false;
+        }
+        return true;
+    }
+
     // To Satisfy JAXB
     public NodeConnectorStatistics() {
 
index 8f99b05a091cdf268619f821d0aaca567a3af82d..12ce4d69482b3f32a61b3aade2b79079aa130f6d 100644 (file)
@@ -68,6 +68,68 @@ public class NodeDescription implements Serializable, Cloneable{
         this.description = description;
     }
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + ((description == null) ? 0 : description.hashCode());
+        result = prime * result + ((hardware == null) ? 0 : hardware.hashCode());
+        result = prime * result + ((manufacturer == null) ? 0 : manufacturer.hashCode());
+        result = prime * result + ((serialNumber == null) ? 0 : serialNumber.hashCode());
+        result = prime * result + ((software == null) ? 0 : software.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof NodeDescription)) {
+            return false;
+        }
+        NodeDescription other = (NodeDescription) obj;
+        if (description == null) {
+            if (other.description != null) {
+                return false;
+            }
+        } else if (!description.equals(other.description)) {
+            return false;
+        }
+        if (hardware == null) {
+            if (other.hardware != null) {
+                return false;
+            }
+        } else if (!hardware.equals(other.hardware)) {
+            return false;
+        }
+        if (manufacturer == null) {
+            if (other.manufacturer != null) {
+                return false;
+            }
+        } else if (!manufacturer.equals(other.manufacturer)) {
+            return false;
+        }
+        if (serialNumber == null) {
+            if (other.serialNumber != null) {
+                return false;
+            }
+        } else if (!serialNumber.equals(other.serialNumber)) {
+            return false;
+        }
+        if (software == null) {
+            if (other.software != null) {
+                return false;
+            }
+        } else if (!software.equals(other.software)) {
+            return false;
+        }
+        return true;
+    }
+
     @Override
     public String toString() {
         return "HwDescription[manufacturer=" + manufacturer + ", hardware="
index 3b359cb812408d0112b07b5e653b6c3e567a9a5b..7c404178cfc195edd206500c90ba4155c7e02f73 100644 (file)
@@ -39,6 +39,56 @@ public class NodeTableStatistics implements Serializable {
     private long matchedCount;
 
 
+    @Override
+    public int hashCode() {
+        final int prime = 31;
+        int result = 1;
+        result = prime * result + activeCount;
+        result = prime * result + (int) (lookupCount ^ (lookupCount >>> 32));
+        result = prime * result + (int) (matchedCount ^ (matchedCount >>> 32));
+        result = prime * result + ((name == null) ? 0 : name.hashCode());
+        result = prime * result + ((nodeTable == null) ? 0 : nodeTable.hashCode());
+        return result;
+    }
+
+    @Override
+    public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
+        if (obj == null) {
+            return false;
+        }
+        if (!(obj instanceof NodeTableStatistics)) {
+            return false;
+        }
+        NodeTableStatistics other = (NodeTableStatistics) obj;
+        if (activeCount != other.activeCount) {
+            return false;
+        }
+        if (lookupCount != other.lookupCount) {
+            return false;
+        }
+        if (matchedCount != other.matchedCount) {
+            return false;
+        }
+        if (name == null) {
+            if (other.name != null) {
+                return false;
+            }
+        } else if (!name.equals(other.name)) {
+            return false;
+        }
+        if (nodeTable == null) {
+            if (other.nodeTable != null) {
+                return false;
+            }
+        } else if (!nodeTable.equals(other.nodeTable)) {
+            return false;
+        }
+        return true;
+    }
+
     //To Satisfy JAXB
     public NodeTableStatistics() {
 
index f5c13b61053ee5eaaa7eab5594608cd3da4ce5d7..eec183d59573aea1bc7deda423416fd4a27b575b 100644 (file)
@@ -167,7 +167,7 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen
      * Function called after registering the service in OSGi service registry.
      */
     void started(){
-        //retrieve current statistics so we don't have to wait for next refresh
+        // Retrieve current statistics so we don't have to wait for next refresh
         ISwitchManager switchManager = (ISwitchManager) ServiceHelper.getInstance(
                 ISwitchManager.class, container.getName(), this);
         if (reader != null && switchManager != null) {
@@ -180,7 +180,7 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen
             }
 
         } else {
-            log.warn("Failed to retrieve current statistics. Statistics will not be immidiately available!");
+            log.trace("Failed to retrieve current statistics. Statistics will not be immediately available!");
         }
     }
 
@@ -247,7 +247,7 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen
         }
 
         Node node;
-        //index FlowEntries' flows by node so we don't traverse entire flow list for each flowEntry
+        // Index FlowEntries' flows by node so we don't traverse entire flow list for each flowEntry
         Map<Node, Set<Flow>> index = new HashMap<Node, Set<Flow>>();
         for (FlowEntry flowEntry : flowList) {
             node = flowEntry.getNode();
@@ -256,7 +256,7 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen
             index.put(node, set);
         }
 
-        //iterate over flows per indexed node and add to output
+        // Iterate over flows per indexed node and add to output
         for (Entry<Node, Set<Flow>> indexEntry : index.entrySet()) {
             node = indexEntry.getKey();
             List<FlowOnNode> flowsPerNode = flowStatistics.get(node);
@@ -356,27 +356,40 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen
 
     @Override
     public void nodeFlowStatisticsUpdated(Node node, List<FlowOnNode> flowStatsList) {
-        this.flowStatistics.put(node, flowStatsList);
+        List<FlowOnNode> currentStat = this.flowStatistics.get(node);
+        // Update cache only if changed to avoid unnecessary cache sync operations
+        if (! flowStatsList.equals(currentStat)){
+            this.flowStatistics.put(node, flowStatsList);
+        }
     }
 
     @Override
     public void nodeConnectorStatisticsUpdated(Node node, List<NodeConnectorStatistics> ncStatsList) {
-        this.nodeConnectorStatistics.put(node, ncStatsList);
+        List<NodeConnectorStatistics> currentStat = this.nodeConnectorStatistics.get(node);
+        if (! ncStatsList.equals(currentStat)){
+            this.nodeConnectorStatistics.put(node, ncStatsList);
+        }
     }
 
     @Override
     public void nodeTableStatisticsUpdated(Node node, List<NodeTableStatistics> tableStatsList) {
-        this.tableStatistics.put(node, tableStatsList);
+        List<NodeTableStatistics> currentStat = this.tableStatistics.get(node);
+        if (! tableStatsList.equals(currentStat)) {
+            this.tableStatistics.put(node, tableStatsList);
+        }
     }
 
     @Override
     public void descriptionStatisticsUpdated(Node node, NodeDescription nodeDescription) {
-        this.descriptionStatistics.put(node, nodeDescription);
+        NodeDescription currentDesc = this.descriptionStatistics.get(node);
+        if (! nodeDescription.equals(currentDesc)){
+            this.descriptionStatistics.put(node, nodeDescription);
+        }
     }
 
     @Override
     public void updateNode(Node node, UpdateType type, Set<Property> props) {
-        //if node is removed, remove stats mappings
+        // If node is removed, clean up stats mappings
         if (type == UpdateType.REMOVED) {
             flowStatistics.remove(node);
             nodeConnectorStatistics.remove(node);
@@ -387,6 +400,6 @@ public class StatisticsManager implements IStatisticsManager, IReadServiceListen
 
     @Override
     public void updateNodeConnector(NodeConnector nodeConnector, UpdateType type, Set<Property> props) {
-        // not interested in this update
+        // Not interested in this update
     }
 }