Change for removing ip related info and some fix to our device.
OnosDeviceManager Unit tests have not been done because it is supposed to be done by Patrik.

Change-Id: Icfc5bafe82cc0d4f428926b298f0867ea1be4e7d
diff --git a/src/main/java/net/onrc/onos/core/topology/Device.java b/src/main/java/net/onrc/onos/core/topology/Device.java
index 48035b3..8da4e36 100644
--- a/src/main/java/net/onrc/onos/core/topology/Device.java
+++ b/src/main/java/net/onrc/onos/core/topology/Device.java
@@ -1,8 +1,5 @@
 package net.onrc.onos.core.topology;
 
-import java.net.InetAddress;
-import java.util.Collection;
-
 import net.floodlightcontroller.util.MACAddress;
 
 /**
@@ -22,13 +19,6 @@
     public MACAddress getMacAddress();
 
     /**
-     * Get the device IP addresses.
-     *
-     * @return the device IP addresses.
-     */
-    public Collection<InetAddress> getIpAddress();
-
-    /**
      * Get the device attachment points.
      * <p/>
      * Add requirement for Iteration order? Latest observed port first.
diff --git a/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java b/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java
index 48d50e4..cdef9aa 100644
--- a/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java
+++ b/src/main/java/net/onrc/onos/core/topology/DeviceEvent.java
@@ -1,11 +1,8 @@
 package net.onrc.onos.core.topology;
 
-import java.net.InetAddress;
 import java.nio.ByteBuffer;
-import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Set;
 
 import net.floodlightcontroller.util.MACAddress;
 import net.onrc.onos.core.topology.PortEvent.SwitchPort;
@@ -14,7 +11,7 @@
  * Self-contained Device event(s) Object
  * <p/>
  * Device event differ from other events.
- * Device Event represent add/remove of attachmentPoint or ipAddress.
+ * Device Event represent add/remove of attachmentPoint.
  * Not add/remove of the DeviceObject itself.
  * <p/>
  * Multiple attachmentPoints can be specified to batch events into 1 object.
@@ -25,7 +22,6 @@
 public class DeviceEvent {
     private final MACAddress mac;
     protected List<SwitchPort> attachmentPoints;
-    protected Set<InetAddress> ipAddresses;
     private long lastSeenTime;
 
     /**
@@ -42,7 +38,6 @@
         }
         this.mac = mac;
         this.attachmentPoints = new LinkedList<>();
-        this.ipAddresses = new HashSet<>();
     }
 
     public MACAddress getMac() {
@@ -53,10 +48,6 @@
         return attachmentPoints;
     }
 
-    public Set<InetAddress> getIpAddresses() {
-        return ipAddresses;
-    }
-
     public void setAttachmentPoints(List<SwitchPort> attachmentPoints) {
         this.attachmentPoints = attachmentPoints;
     }
@@ -66,18 +57,9 @@
         this.attachmentPoints.add(0, attachmentPoint);
     }
 
-
-    public boolean addIpAddress(InetAddress addr) {
-        return this.ipAddresses.add(addr);
-    }
-
-    public boolean removeIpAddress(InetAddress addr) {
-        return this.ipAddresses.remove(addr);
-    }
-
     @Override
     public String toString() {
-        return "[DeviceEvent " + mac + " attachmentPoints:" + attachmentPoints + " ipAddr:" + ipAddresses + "]";
+        return "[DeviceEvent " + mac + " attachmentPoints:" + attachmentPoints + "]";
     }
 
     // Assuming mac is unique cluster-wide
diff --git a/src/main/java/net/onrc/onos/core/topology/DeviceImpl.java b/src/main/java/net/onrc/onos/core/topology/DeviceImpl.java
index 28a7796..d070570 100644
--- a/src/main/java/net/onrc/onos/core/topology/DeviceImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/DeviceImpl.java
@@ -1,11 +1,7 @@
 package net.onrc.onos.core.topology;
 
-import java.net.InetAddress;
-import java.util.Collection;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.LinkedList;
-import java.util.Set;
 
 import net.floodlightcontroller.util.MACAddress;
 
@@ -16,14 +12,12 @@
 
     private final MACAddress macAddr;
     protected LinkedList<Port> attachmentPoints;
-    protected Set<InetAddress> ipAddresses;
     private long lastSeenTime;
 
     public DeviceImpl(NetworkGraph graph, MACAddress mac) {
         super(graph);
         this.macAddr = mac;
         this.attachmentPoints = new LinkedList<>();
-        this.ipAddresses = new HashSet<>();
     }
 
     @Override
@@ -32,11 +26,6 @@
     }
 
     @Override
-    public Collection<InetAddress> getIpAddress() {
-        return Collections.unmodifiableSet(ipAddresses);
-    }
-
-    @Override
     public Iterable<Port> getAttachmentPoints() {
         return Collections.unmodifiableList(this.attachmentPoints);
     }
@@ -73,22 +62,4 @@
     boolean removeAttachmentPoint(Port p) {
         return this.attachmentPoints.remove(p);
     }
-
-    /**
-     * Only {@link TopologyManager} should use this method.
-     *
-     * @param p
-     */
-    boolean addIpAddress(InetAddress addr) {
-        return this.ipAddresses.add(addr);
-    }
-
-    /**
-     * Only {@link TopologyManager} should use this method.
-     *
-     * @param p
-     */
-    boolean removeIpAddress(InetAddress addr) {
-        return this.ipAddresses.remove(addr);
-    }
 }
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraph.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraph.java
index 3c583b4..99f7eda 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraph.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraph.java
@@ -1,7 +1,5 @@
 package net.onrc.onos.core.topology;
 
-import java.net.InetAddress;
-
 import net.floodlightcontroller.util.MACAddress;
 
 /**
@@ -66,14 +64,6 @@
     public Iterable<Link> getLinks();
 
     /**
-     * Get the network devices for a given IP address.
-     *
-     * @param ipAddress the IP address to use.
-     * @return the network devices for the IP address.
-     */
-    public Iterable<Device> getDevicesByIp(InetAddress ipAddress);
-
-    /**
      * Get the network device for a given MAC address.
      *
      * @param address the MAC address to use.
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraphDatastore.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraphDatastore.java
index 488915f..f5aec14 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraphDatastore.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraphDatastore.java
@@ -1,6 +1,5 @@
 package net.onrc.onos.core.topology;
 
-import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -19,8 +18,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.net.InetAddresses;
-
 /**
  * The southbound interface to the network graph which allows clients to
  * mutate the graph. This class will maintain the invariants of the network
@@ -193,18 +190,12 @@
         log.debug("Adding device into DB. mac {}", device.getMac());
 
         KVDevice rcDevice = new KVDevice(device.getMac().toBytes());
-        rcDevice.setLastSeenTime(device.getLastSeenTime());
 
         for (SwitchPort sp : device.getAttachmentPoints()) {
             byte[] portId = KVPort.getPortID(sp.getDpid(), sp.getNumber());
             rcDevice.addPortId(portId);
         }
 
-        for (InetAddress addr : device.getIpAddresses()) {
-            //It assume only one ip on a device now.
-            rcDevice.setIp(InetAddresses.coerceToInteger(addr));
-        }
-
         rcDevice.forceCreate();
 
         return true;
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraphImpl.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraphImpl.java
index d28e8bb..115afb5 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraphImpl.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraphImpl.java
@@ -1,11 +1,8 @@
 package net.onrc.onos.core.topology;
 
-import java.net.InetAddress;
 import java.util.Collections;
-import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Set;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.ConcurrentMap;
 import java.util.concurrent.locks.Lock;
@@ -23,8 +20,6 @@
 
     // DPID -> Switch
     private ConcurrentMap<Long, Switch> switches;
-
-    private ConcurrentMap<InetAddress, Set<Device>> addr2Device;
     private ConcurrentMap<MACAddress, Device> mac2Device;
 
     private ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
@@ -35,7 +30,6 @@
     public NetworkGraphImpl() {
         // TODO: Does these object need to be stored in Concurrent Collection?
         switches = new ConcurrentHashMap<>();
-        addr2Device = new ConcurrentHashMap<>();
         mac2Device = new ConcurrentHashMap<>();
     }
 
@@ -107,42 +101,16 @@
     }
 
     @Override
-    public Iterable<Device> getDevicesByIp(InetAddress ipAddress) {
-        Set<Device> devices = addr2Device.get(ipAddress);
-        if (devices == null) {
-            return Collections.emptySet();
-        }
-        return Collections.unmodifiableCollection(devices);
-    }
-
-    @Override
     public Device getDeviceByMac(MACAddress address) {
         return mac2Device.get(address);
     }
 
     protected void putDevice(Device device) {
         mac2Device.put(device.getMacAddress(), device);
-        for (InetAddress ipAddr : device.getIpAddress()) {
-            Set<Device> devices = addr2Device.get(ipAddr);
-            if (devices == null) {
-                devices = new HashSet<>();
-                addr2Device.put(ipAddr, devices);
-            }
-            devices.add(device);
-        }
     }
 
     protected void removeDevice(Device device) {
         mac2Device.remove(device.getMacAddress());
-        for (InetAddress ipAddr : device.getIpAddress()) {
-            Set<Device> devices = addr2Device.get(ipAddr);
-            if (devices != null) {
-                devices.remove(device);
-                if (devices.isEmpty()) {
-                    addr2Device.remove(ipAddr);
-                }
-            }
-        }
     }
 
     @Override
diff --git a/src/main/java/net/onrc/onos/core/topology/NetworkGraphPublisher.java b/src/main/java/net/onrc/onos/core/topology/NetworkGraphPublisher.java
index e00e3c9..6f9b332 100644
--- a/src/main/java/net/onrc/onos/core/topology/NetworkGraphPublisher.java
+++ b/src/main/java/net/onrc/onos/core/topology/NetworkGraphPublisher.java
@@ -1,6 +1,5 @@
 package net.onrc.onos.core.topology;
 
-import java.net.InetAddress;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
@@ -31,8 +30,6 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.google.common.net.InetAddresses;
-
 /**
  * The NetworkGraphPublisher subscribes to topology network events from the
  * discovery modules. These events are reformatted and relayed to the topology
@@ -286,10 +283,6 @@
         DeviceEvent event = new DeviceEvent(device.getMacAddress());
         event.setAttachmentPoints(spLists);
         event.setLastSeenTime(device.getLastSeenTimestamp().getTime());
-        if (device.getIpv4Address() != null) {
-            InetAddress ip = InetAddresses.fromInteger(device.getIpv4Address());
-            event.addIpAddress(ip);
-        }
         // Does not use vlan info now.
 
         networkGraphDiscoveryInterface.putDeviceDiscoveryEvent(event);
diff --git a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
index bc1fc9a..bf3874b 100644
--- a/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/core/topology/TopologyManager.java
@@ -1,6 +1,5 @@
 package net.onrc.onos.core.topology;
 
-import java.net.InetAddress;
 import java.nio.ByteBuffer;
 import java.util.ArrayList;
 import java.util.Collection;
@@ -14,9 +13,11 @@
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.LinkedBlockingQueue;
 
+import net.floodlightcontroller.util.MACAddress;
 import net.onrc.onos.core.datagrid.IDatagridService;
 import net.onrc.onos.core.datagrid.IEventChannel;
 import net.onrc.onos.core.datagrid.IEventChannelListener;
+import net.onrc.onos.core.datastore.topology.KVDevice;
 import net.onrc.onos.core.datastore.topology.KVLink;
 import net.onrc.onos.core.datastore.topology.KVPort;
 import net.onrc.onos.core.datastore.topology.KVSwitch;
@@ -1034,20 +1035,16 @@
      * @param deviceEvent the Device Event with the device to add.
      */
     private void addDevice(DeviceEvent deviceEvent) {
+        log.debug("Adding a device to the Network Graph with mac {}", deviceEvent.getMac());
         Device device = networkGraph.getDeviceByMac(deviceEvent.getMac());
 
         if (device == null) {
-            log.debug("Existing device was not found in networkGraph. New device. mac {}", deviceEvent.getMac());
+            log.debug("Existing device was not found in the NetworkGraph: Adding new device: mac {}", deviceEvent.getMac());
             device = new DeviceImpl(networkGraph, deviceEvent.getMac());
         }
 
         DeviceImpl deviceImpl = getDeviceImpl(device);
 
-        // Update the IP addresses
-        for (InetAddress ipAddr : deviceEvent.getIpAddresses()) {
-            deviceImpl.addIpAddress(ipAddr);
-        }
-
         // Process each attachment point
         boolean attachmentFound = false;
         for (SwitchPort swp : deviceEvent.getAttachmentPoints()) {
@@ -1077,7 +1074,7 @@
 
         // Update the device in the Network Graph
         if (attachmentFound) {
-            log.debug("Storing the info into networkGraph. mac {}", deviceEvent.getMac());
+            log.debug("Storing the device info into the NetworkGraph: mac {}", deviceEvent.getMac());
             networkGraph.putDevice(device);
             apiAddedDeviceEvents.add(deviceEvent);
         }
@@ -1091,6 +1088,7 @@
      * @param deviceEvent the Device Event with the device to remove.
      */
     private void removeDevice(DeviceEvent deviceEvent) {
+        log.debug("Removing a device to the Network Graph: mac {}", deviceEvent.getMac());
         Device device = networkGraph.getDeviceByMac(deviceEvent.getMac());
         if (device == null) {
             log.warn("Device {} already removed, ignoring", deviceEvent);
@@ -1113,6 +1111,7 @@
             deviceImpl.removeAttachmentPoint(port);
         }
 
+        log.debug("Removing the device info into the NetworkGraph: mac {}", deviceEvent.getMac());
         networkGraph.removeDevice(device);
         apiRemovedDeviceEvents.add(deviceEvent);
     }
@@ -1210,13 +1209,12 @@
             collection.add(eventEntry);
         }
 
-        // TODO Is Device going to be in DB? If so, read from DB.
-        //      for (KVDevice d : KVDevice.getAllDevices()) {
-        //          DeviceEvent devEvent = new DeviceEvent( MACAddress.valueOf(d.getMac()) );
-        //          for (byte[] portId : d.getAllPortIds() ) {
-        //              devEvent.addAttachmentPoint( new SwitchPort( KVPort.getDpidFromKey(portId), KVPort.getNumberFromKey(portId) ));
-        //          }
-        //      }
+         for (KVDevice d : KVDevice.getAllDevices()) {
+              DeviceEvent devEvent = new DeviceEvent(MACAddress.valueOf(d.getMac()));
+              for (byte[] portId : d.getAllPortIds()) {
+                  devEvent.addAttachmentPoint(new SwitchPort(KVPort.getDpidFromKey(portId), KVPort.getNumberFromKey(portId)));
+              }
+         }
 
         for (KVLink l : KVLink.getAllLinks()) {
             LinkEvent linkEvent = new LinkEvent(l.getSrc().dpid,