Cherry-pick from https://gerrit.onos.onlab.us/#/c/342/

Cherry-pick from https://gerrit.onos.onlab.us/#/c/322/

Suppress device update for the same device.
Add function to clean devices.

Conflicts:

	src/main/java/net/onrc/onos/ofcontroller/devicemanager/OnosDeviceManager.java

NOTE: The above conflict has been resolved by hand.
The conflict was in the number of parameters when
calling deviceStorage.init() inside file OnosDeviceManager.java:
deviceStorage.init("") -> deviceStorage.init("","")

Conflicts:

	src/main/java/net/onrc/onos/datagrid/HazelcastDatagrid.java
	src/main/java/net/onrc/onos/datagrid/IDatagridService.java

NOTE: The above conflict has been resolved by hand.

Change-Id: I831e391efce9a795370be99238834b6bc7db2bee
diff --git a/src/main/java/net/onrc/onos/ofcontroller/devicemanager/OnosDevice.java b/src/main/java/net/onrc/onos/ofcontroller/devicemanager/OnosDevice.java
index 34d2c38..4b47501 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/devicemanager/OnosDevice.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/devicemanager/OnosDevice.java
@@ -17,6 +17,7 @@
 
 package net.onrc.onos.ofcontroller.devicemanager;
 
+import java.io.Serializable;
 import java.util.Date;
 
 import net.floodlightcontroller.devicemanager.internal.Entity;
@@ -37,7 +38,7 @@
  * @author readams
  *
  */
-public class OnosDevice { //implements Comparable<OnosDevice> {
+public class OnosDevice implements Serializable { //implements Comparable<OnosDevice> {
     /**
      * Timeout for computing {@link Entity#activeSince}.
      * @see {@link Entity#activeSince}
@@ -126,6 +127,10 @@
     public Integer getIpv4Address() {
         return ipv4Address;
     }
+    
+    public void setIpv4Address(Integer ipv4Address) {
+    	this.ipv4Address = ipv4Address;
+    }
 
     public Short getVlan() {
         return vlan;
@@ -134,10 +139,18 @@
     public Long getSwitchDPID() {
         return switchDPID;
     }
+    
+    public void setSwitchDPID(long dpid) {
+    	this.switchDPID = dpid;
+    }
 
     public short getSwitchPort() {
         return switchPort;
     }
+    
+    public void setSwitchPort(short port) {
+    	this.switchPort = port;
+    }
 
     public Date getLastSeenTimestamp() {
         return lastSeenTimestamp;
@@ -165,7 +178,6 @@
         this.activeSince = activeSince;
     }
     
-    /*
     @Override
     public int hashCode() {
         if (hashCode != 0) return hashCode;
@@ -173,10 +185,9 @@
         hashCode = 1;
         hashCode = prime * hashCode
                  + ((ipv4Address == null) ? 0 : ipv4Address.hashCode());
-        //hashCode = prime * hashCode + (int) (macAddress ^ (macAddress >>> 32));
-        hashCode = prime * macAddress.hashCode();
-        hashCode = prime * hashCode + (int) (switchDPID ^ (switchDPID >>> 32));
-        hashCode = prime * hashCode + switchPort;
+        hashCode = prime * hashCode + (int) (macAddress.toLong() ^ (macAddress.toLong() >>> 32));
+        hashCode = prime * hashCode + (int)switchDPID;
+        hashCode = prime * hashCode + (int)switchPort;
         hashCode = prime * hashCode + ((vlan == null) ? 0 : vlan.hashCode());
         return hashCode;
     }
@@ -186,26 +197,21 @@
         if (this == obj) return true;
         if (obj == null) return false;
         if (getClass() != obj.getClass()) return false;
-        Entity other = (Entity) obj;
+        OnosDevice other = (OnosDevice) obj;
         if (hashCode() != other.hashCode()) return false;
         if (ipv4Address == null) {
             if (other.ipv4Address != null) return false;
-        } else if (!ipv4Address.equals(other.ipv4Address)) return false;
-        if (macAddress != other.macAddress) return false;
-        if (switchDPID == null) {
-            if (other.switchDPID != null) return false;
-        } else if (!switchDPID.equals(other.switchDPID)) return false;
-        if (switchPort == null) {
-            if (other.switchPort != null) return false;
-        } else if (!switchPort.equals(other.switchPort)) return false;
+        } else if (!ipv4Address.equals(other.ipv4Address)) return false; 
+        if (macAddress == null) {
+            if (other.macAddress != null) return false;
+        } else if (!macAddress.equals(other.macAddress)) return false;
+        if(switchDPID != other.switchDPID) return false;
+        if (switchPort != other.switchPort) return false;
         if (vlan == null) {
             if (other.vlan != null) return false;
         } else if (!vlan.equals(other.vlan)) return false;
         return true;
     }
-    */
-
-    
     
     @Override
     public String toString() {