Network Graph Refactoring: create a separate NetworkGraphImpl instance
within TopologyManager instead of extending it.

Change-Id: I01126a2004af984b873e46d86fbe521ca1f86ddb
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
index 88cedac..4425a7d 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
@@ -3,6 +3,7 @@
 import java.net.InetAddress;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.LinkedList;
 import java.util.List;
 import java.util.Set;
@@ -19,10 +20,10 @@
 	private static final Logger log = LoggerFactory.getLogger(NetworkGraphImpl.class);
 
 	// DPID -> Switch
-	protected ConcurrentMap<Long, Switch> switches;
+	private ConcurrentMap<Long, Switch> switches;
 
-	protected ConcurrentMap<InetAddress, Set<Device>> addr2Device;
-	protected ConcurrentMap<MACAddress, Device> mac2Device;
+	private ConcurrentMap<InetAddress, Set<Device>> addr2Device;
+	private ConcurrentMap<MACAddress, Device> mac2Device;
 
 	public NetworkGraphImpl() {
 		// TODO: Does these object need to be stored in Concurrent Collection?
@@ -37,6 +38,14 @@
 		return switches.get(dpid);
 	}
 
+	protected void putSwitch(Switch sw) {
+		switches.put(sw.getDpid(), sw);
+	}
+
+	protected void removeSwitch(Long dpid) {
+		switches.remove(dpid);
+	}
+
 	@Override
 	public Iterable<Switch> getSwitches() {
 		// TODO Check if it is safe to directly return this Object.
@@ -106,4 +115,28 @@
 	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);
+		}
+	    }
+	}
 }