WIP: Add Design memo to each Objects

Change-Id: Ic8dd106508b6c3e1f09e82c11d20dd089d37da99
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Device.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Device.java
index 5124f82..e25e812 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Device.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Device.java
@@ -5,12 +5,19 @@
 
 import net.floodlightcontroller.util.MACAddress;
 
+/**
+ * Interface of Device Object exposed to the "NB" read-only Topology.
+ *
+ * Everything returned by these interfaces must be either Unmodifiable view,
+ * immutable object, or a copy of the original "SB" In-memory Topology.
+ *
+ */
 public interface Device {
 	public MACAddress getMacAddress();
-	
+
 	public Collection<InetAddress> getIpAddress();
-	
+
 	public Iterable<Port> getAttachmentPoints();
-	
+
 	public long getLastSeenTime();
 }
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Link.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Link.java
index 6c84382..0fc72f6 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Link.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Link.java
@@ -1,14 +1,21 @@
 package net.onrc.onos.ofcontroller.networkgraph;
 
+/**
+ * Interface of Link Object exposed to the "NB" read-only Topology.
+ *
+ * Everything returned by these interfaces must be either Unmodifiable view,
+ * immutable object, or a copy of the original "SB" In-memory Topology.
+ *
+ */
 public interface Link {
 	public Port getSourcePort();
 	public Port getDestinationPort();
 	public Switch getSourceSwitch();
 	public Switch getDestinationSwitch();
-	
+
 	public long getLastSeenTime();
 	public int getCost();
-	
+
 	// Not sure if we want to expose these northbound
 	public long getSourceSwitchDpid();
 	public short getSourcePortNumber();
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java
index 888daae..59af6d0 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/LinkImpl.java
@@ -1,12 +1,18 @@
 package net.onrc.onos.ofcontroller.networkgraph;
 
+/**
+ * Link Object stored in In-memory Topology.
+ *
+ * TODO REMOVE following design memo: This object itself may hold the DBObject,
+ * but this Object itself will not issue any read/write to the DataStore.
+ */
 public class LinkImpl extends NetworkGraphObject implements Link {
-	
+
 	private long srcSwitch;
 	private short srcPort;
 	private long dstSwitch;
 	private short dstPort;
-	
+
 	private static final int DEFAULT_COST = 1;
 	private int cost = DEFAULT_COST;
 
@@ -43,12 +49,12 @@
 		// TODO Auto-generated method stub
 		return 0;
 	}
-	
+
 	@Override
 	public int getCost() {
 		return cost;
 	}
-	
+
 	public void setCost(int cost) {
 		this.cost = cost;
 	}
@@ -89,5 +95,5 @@
 		this.dstPort = dstPort;
 	}
 
-	
+
 }
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 5f42ef2..0530147 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
@@ -11,14 +11,21 @@
 
 import edu.stanford.ramcloud.JRamCloud.ObjectDoesntExistException;
 
+/**
+ * The "NB" read-only Network Map.
+ *
+ * TODO Current implementation directly read from DB, but
+ * eventually, it should read from In-memory shared Network Map instance within ONOS process.
+ *
+ */
 public class NetworkGraphImpl implements NetworkGraph {
 
 	private static final Logger log = LoggerFactory.getLogger(NetworkGraphImpl.class);
-	
+
 	@Override
 	public Switch getSwitch(long dpid) {
 		SwitchImpl sw = new SwitchImpl(this);
-		
+
 		RCSwitch rcSwitch = new RCSwitch(dpid);
 		try {
 			rcSwitch.read();
@@ -26,28 +33,28 @@
 			log.warn("Tried to get a switch that doesn't exist {}", dpid);
 			return null;
 		}
-		
+
 		sw.setDpid(rcSwitch.getDpid());
-		
+
 		for (byte[] portId : rcSwitch.getAllPortIds()) {
 			RCPort rcPort = RCPort.createFromKey(portId);
 			try {
 				rcPort.read();
-				
+
 				PortImpl port = new PortImpl(this);
 				//port.setDpid(dpid);
-				
+
 				// TODO why are port numbers long?
 				//port.setPortNumber((short)rcPort.getNumber());
-				
+
 				port.setSwitch(sw);
 				sw.addPort(port);
-				
+
 			} catch (ObjectDoesntExistException e) {
 				log.warn("Tried to read port that doesn't exist", rcPort);
 			}
 		}
-		
+
 		return sw;
 	}
 
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Port.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Port.java
index 8299022..453dd14 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Port.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Port.java
@@ -2,12 +2,19 @@
 
 
 
+/**
+ * Interface of Port Object exposed to the "NB" read-only Topology.
+ *
+ * Everything returned by these interfaces must be either Unmodifiable view,
+ * immutable object, or a copy of the original "SB" In-memory Topology.
+ *
+ */
 public interface Port {
 	public short getNumber();
 	public String getName();
 	public long getHardwareAddress();
-	
+
 	public Switch getSwitch();
-	
+
 	public Link getLink();
 }
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortImpl.java
index d0b605d..2e1086c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/PortImpl.java
@@ -1,7 +1,13 @@
 package net.onrc.onos.ofcontroller.networkgraph;
 
+/**
+ * Port Object stored in In-memory Topology.
+ *
+ * TODO REMOVE following design memo: This object itself may hold the DBObject,
+ * but this Object itself will not issue any read/write to the DataStore.
+ */
 public class PortImpl extends NetworkGraphObject implements Port {
-	
+
 	//private long dpid;
 	private Switch sw;
 	private short number;
@@ -9,7 +15,7 @@
 	public PortImpl(NetworkGraph graph) {
 		super(graph);
 	}
-	
+
 	public void setPortNumber(short portNumber) {
 		number = portNumber;
 	}
@@ -18,12 +24,12 @@
 	public short getNumber() {
 		return number;
 	}
-	
+
 	/*
 	public void setDpid(long dpid) {
 		this.dpid = dpid;
 	}
-	
+
 	public long getDpid() {
 		return dpid;
 	}
@@ -40,12 +46,12 @@
 		// TODO Auto-generated method stub
 		return 0;
 	}
-	
+
 	@Override
 	public Switch getSwitch() {
 		return sw;
 	}
-	
+
 	public void setSwitch(Switch sw) {
 		this.sw = sw;
 	}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SouthboundNetworkGraph.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SouthboundNetworkGraph.java
index b38c057..b1f4213 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SouthboundNetworkGraph.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SouthboundNetworkGraph.java
@@ -22,6 +22,15 @@
  * graph. The southbound discovery modules will use this interface to update
  * the network graph as they learn about the state of the network.
  *
+ * Modification to the Network Map by this module will:
+ * 1. Writes to Cluster-wide DataStore.
+ * 2. Update ONOS instance In-memory Network Map.
+ * 3. Send-out Notification. (TBD)
+ *    (XXX: To update other instances In-memory Network Map,
+ *          notification should be triggered here.
+ *          But if we want to aggregate notification to minimize notification,
+ *          It might be better for the caller to trigger notification.)
+ *
  */
 public class SouthboundNetworkGraph {
 	private static final Logger log = LoggerFactory.getLogger(SouthboundNetworkGraph.class);
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Switch.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Switch.java
index 3de47ce..7552399 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Switch.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/Switch.java
@@ -4,23 +4,30 @@
 
 import net.onrc.onos.ofcontroller.util.FlowEntry;
 
+/**
+ * Interface of Switch Object exposed to the "NB" read-only Topology.
+ *
+ * Everything returned by these interfaces must be either Unmodifiable view,
+ * immutable object, or a copy of the original "SB" In-memory Topology.
+ *
+ */
 public interface Switch {
 	public long getDpid();
-	
+
 	public Collection<Port> getPorts();
-	
+
 	public Port getPort(short number);
-	
-	
+
+
 	// Flows
 	public Collection<FlowEntry> getFlowEntries();
-	
+
 	// Graph traversal API
 	public Iterable<Switch> getNeighbors();
-	
+
 	public Iterable<Link> getLinks();
-	
+
 	public Link getLinkToNeighbor(long dpid);
-	
+
 	public Collection<Device> getDevices();
 }
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchImpl.java
index 7b83224..6e250bc 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/SwitchImpl.java
@@ -11,14 +11,20 @@
 import net.onrc.onos.datastore.topology.RCSwitch;
 import net.onrc.onos.ofcontroller.util.FlowEntry;
 
+/**
+ * Switch Object stored in In-memory Topology.
+ *
+ * TODO REMOVE following design memo: This object itself may hold the DBObject,
+ * but this Object itself will not issue any read/write to the DataStore.
+ */
 public class SwitchImpl extends NetworkGraphObject implements Switch {
-	
+
 	private long dpid;
 	private final Map<Short, Port> ports;
 
 	public SwitchImpl(NetworkGraph graph) {
 		super(graph);
-		
+
 		ports = new HashMap<Short, Port>();
 	}
 
@@ -68,7 +74,7 @@
 	public void setDpid(long dpid) {
 		this.dpid = dpid;
 	}
-	
+
 	public void addPort(Port port) {
 		this.ports.put(port.getNumber(), port);
 	}
@@ -77,23 +83,23 @@
 	public Iterable<Link> getLinks() {
 		return graph.getLinksFromSwitch(dpid);
 	}
-	
+
 	public void store() {
 		RCSwitch rcSwitch = new RCSwitch(dpid);
-		
+
 		for (Port port : ports.values()) {
 			RCPort rcPort = new RCPort(dpid, (long)port.getNumber());
 			rcSwitch.addPortId(rcPort.getId());
 		}
-		
-		
+
+
 		try {
 			rcSwitch.update();
-			
+
 		} catch (ObjectDoesntExistException | WrongVersionException e) {
 			// TODO Auto-generated catch block
 			e.printStackTrace();
 		}
-		
+
 	}
 }