Merge branch 'master' of https://github.com/OPENNETWORKINGLAB/ONOS

Conflicts:
	src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
diff --git a/src/main/java/net/onrc/onos/graph/GraphDBConnection.java b/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
index 6d79de8..232deed 100644
--- a/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
+++ b/src/main/java/net/onrc/onos/graph/GraphDBConnection.java
@@ -7,6 +7,7 @@
 
 import com.thinkaurelius.titan.core.TitanFactory;
 import com.thinkaurelius.titan.core.TitanGraph;
+import com.thinkaurelius.titan.diskstorage.StorageException;
 import com.tinkerpop.blueprints.TransactionalGraph;
 import com.tinkerpop.blueprints.Vertex;
 import com.tinkerpop.blueprints.util.wrappers.event.EventTransactionalGraph;
@@ -133,15 +134,17 @@
 
 	/**
 	 * Commit changes for the graph operations.
+	 * @throws Exception 
 	 */
 	@Override
 	public void commit() {
-		try {
+//		// Should not catch exception here! 
+//		try {
 			graph.commit();
-		}
-		catch (Exception e) {
-			log.error("{}", e.toString());
-		}
+//		}
+//		catch (Exception e) {
+//			log.error("{}", e.toString());
+//		}
 	}
 
 	/**
@@ -149,12 +152,13 @@
 	 */
 	@Override
 	public void rollback() {
-		try {
+		// Should not catch exception here! 
+//		try {
 			graph.rollback();
-		}
-		catch (Exception e) {
-			log.error("{}", e.toString());
-		}
+//		}
+//		catch (Exception e) {
+//			log.error("{}", e.toString());
+//		}
 	}
 
 	/**
@@ -162,6 +166,10 @@
 	 */
 	@Override
 	public void close() {
-		commit();
+		try {
+			commit();
+		} catch (Exception e) {
+			log.error("{}", e.toString());
+		}
 	}
 }
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
index b56cfef..483fbda 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ILinkStorage.java
@@ -8,33 +8,34 @@
 public interface ILinkStorage extends INetMapStorage {
 	
     /*
-     * Link creation
-     */
-	public void update(Link link, DM_OPERATION op);
-	public void update(Link link, LinkInfo linkinfo, DM_OPERATION op);
-	public void update(List<Link> List, DM_OPERATION op);
-
-	/*
-	 *  Add Linkinfo
+	 * Init with Storage conf
 	 */
-	public void updateLink (Link link, LinkInfo linkinfo, DM_OPERATION op);
+	public void init(String conf);
 	
 	/*
-	 * Delete a single link
+	 * Generic operation method
 	 */
-	public void deleteLink(Link link);
+	public boolean update(Link link, LinkInfo linkinfo, DM_OPERATION op);
+	
+	/*
+     * Link creation
+     */
+	public boolean addLink(Link link);
+	public boolean addLink(Link link, LinkInfo linfo);
+	public boolean addLinks(List<Link> links);
+	
+	/*
+	 * Link deletion
+	 */
+	public boolean deleteLink(Link link);
+	public boolean deleteLinks(List<Link> links);
 
 	/*
-	 * Delete links associated with dpid and port 
+	 * Utility method to delete links associated with dpid and port 
 	 * If only dpid is used, All links associated for switch are removed
 	 * Useful for port up/down and also switch join/remove events
 	 */ 
-	public void deleteLinksOnPort(Long dpid, short port);
-	
-	/*
-	 * Delete a list of links
-	 */
-	public void deleteLinks(List<Link> links);
+	public boolean deleteLinksOnPort(Long dpid, short port);
 
 	/*
 	 * Get Links from Storage
@@ -44,10 +45,6 @@
 	public List<Link> getLinks(Long dpid, short port);
 	public List<Link> getLinks(String dpid);
 	public List<Link> getActiveLinks();
-	
-	/*
-	 * Init with Storage conf
-	 */
-	public void init(String conf);
 
+	public LinkInfo getLinkInfo(Link link);
 }
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
index 4fcebb2..b7825f9 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
@@ -12,33 +12,35 @@
 	}
 	
 	/*
-	 * Update the switch details
-	 */
-	public void update(String dpid,SwitchState state, DM_OPERATION op);
-	/*
-	 * Associate a port on switch
-	 */
-	public void addPort(String dpid, OFPhysicalPort port);
-	/*
-	 * Add a switch and all its associated ports
-	 */
-	public void addSwitch(IOFSwitch sw);
-	/*
-	 * Add a switch
-	 */
-	public void addSwitch(String dpid);
-	/*
-	 * Delete switch and associated ports
-	 */
-	public void deleteSwitch(String dpid);
-	/*
-	 * Delete a port on a switch by num
-	 */
-	public void deletePort(String dpid, short port);
-	/*
 	 * Initialize
 	 */
 	public void init(String conf);
-	
-
+	/*
+	 * Update the switch details
+	 */
+	public boolean updateSwitch(String dpid, SwitchState state, DM_OPERATION op);
+	/*
+	 * Add a switch and all its associated ports
+	 */
+	public boolean addSwitch(IOFSwitch sw);
+	/*
+	 * Add a switch
+	 */
+	public boolean addSwitch(String dpid);
+	/*
+	 * Delete switch and associated ports
+	 */
+	public boolean deleteSwitch(String dpid);
+	/*
+	 * Update the port details
+	 */
+	public boolean updatePort(String dpid, short port, int state, String desc);
+	/*
+	 * Associate a port on switch
+	 */
+	public boolean addPort(String dpid, OFPhysicalPort port);
+	/*
+	 * Delete a port on a switch by num
+	 */
+	public boolean deletePort(String dpid, short port);
 }
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
index b32a26e..92e2831 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImpl.java
@@ -14,181 +14,205 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-import com.thinkaurelius.titan.core.TitanException;
 import com.tinkerpop.blueprints.Vertex;
 import com.tinkerpop.pipes.PipeFunction;
 import com.tinkerpop.pipes.transform.PathPipe;
 
 /**
- * This is the class for storing the information of links into CassandraDB
+ * This is the class for storing the information of links into GraphDB
  */
 public class LinkStorageImpl implements ILinkStorage {
 	
 	protected final static Logger log = LoggerFactory.getLogger(LinkStorageImpl.class);
-	protected GraphDBOperation dbop;
+	protected GraphDBOperation op;
 
+	
 	/**
-	 * Update a record in the LinkStorage in a way provided by op.
-	 * @param link Record of a link to be updated.
-	 * @param op Operation to be done.
+	 * Initialize the object. Open LinkStorage using given configuration file.
+	 * @param conf Path (absolute path for now) to configuration file.
 	 */
 	@Override
-	public void update(Link link, DM_OPERATION op) {
-		update(link, (LinkInfo)null, op);
+	public void init(String conf) {
+		this.op = new GraphDBOperation(conf);
 	}
 
+	// Method designing policy:
+	//  op.commit() and op.rollback() MUST called in public (first-class) methods.
+	//  A first-class method MUST NOT call other first-class method.
+	//  Routine process should be implemented in private method.
+	//  A private method MUST NOT call commit or rollback.
+
+	
+	/**
+	 * Update a record in the LinkStorage in a way provided by dmop.
+	 * @param link Record of a link to be updated.
+	 * @param linkinfo Meta-information of a link to be updated.
+	 * @param dmop Operation to be done.
+	 */
+	@Override
+	public boolean update(Link link, LinkInfo linkinfo, DM_OPERATION dmop) {
+		boolean success = false;
+		
+		switch (dmop) {
+		case CREATE:
+		case INSERT:
+			if (link != null) {
+				try {
+					if (addLinkImpl(link)) {
+						op.commit();
+						success = true;
+					}
+				} catch (Exception e) {
+					op.rollback();
+					e.printStackTrace();
+		        	log.error("LinkStorageImpl:update {} link:{} failed", dmop, link);
+				}
+			}
+			break;
+		case UPDATE:
+			if (link != null && linkinfo != null) {
+				try {
+					if (setLinkInfoImpl(link, linkinfo)) {
+						op.commit();
+						success = true;
+					}
+				} catch (Exception e) {
+					op.rollback();
+					e.printStackTrace();
+		        	log.error("LinkStorageImpl:update {} link:{} failed", dmop, link);
+				}
+			}
+			break;
+		case DELETE:
+			if (link != null) {
+				try {
+					if (deleteLinkImpl(link)) {
+						op.commit();
+						success = true;
+		            	log.debug("LinkStorageImpl:update {} link:{} succeeded", dmop, link);
+		            } else {
+						op.rollback();
+		            	log.debug("LinkStorageImpl:update {} link:{} failed", dmop, link);
+					}
+				} catch (Exception e) {
+					op.rollback();
+					e.printStackTrace();
+					log.error("LinkStorageImpl:update {} link:{} failed", dmop, link);
+				}
+			}
+			break;
+		}
+		
+		return success;
+	}
+
+	@Override
+	public boolean addLink(Link link) {
+		return addLink(link, null);
+	}
+
+	@Override
+	public boolean addLink(Link link, LinkInfo linfo) {
+		boolean success = false;
+		
+		try {
+			if (addLinkImpl(link)) {
+				// Set LinkInfo only if linfo is non-null.
+				if (linfo != null && (! setLinkInfoImpl(link, linfo))) {
+					op.rollback();
+				}
+				op.commit();
+				success = true;
+			} else {
+				op.rollback();
+			}
+		} catch (Exception e) {
+			e.printStackTrace();
+			log.error("LinkStorageImpl:addLink link:{} linfo:{} failed", link, linfo);
+		}
+		
+		return success;
+	}
+	
 	/**
 	 * Update multiple records in the LinkStorage in a way provided by op.
 	 * @param links List of records to be updated.
 	 * @param op Operation to be done.
 	 */
 	@Override
-	public void update(List<Link> links, DM_OPERATION op) {
-		for (Link lt: links) {
-			update(lt, (LinkInfo)null, op);
-		}
-	}
-
-	/**
-	 * Update a record of link with meta-information in the LinkStorage in a way provided by op.
-	 * @param link Record of a link to update.
-	 * @param linkinfo Meta-information of a link to be updated.
-	 * @param op Operation to be done.
-	 */
-	@Override
-	public void update(Link link, LinkInfo linkinfo, DM_OPERATION op) {
-		switch (op) {
-		case UPDATE:
-		case CREATE:
-		case INSERT:
-			updateLink(link, linkinfo, op);
-			break;
-		case DELETE:
-			deleteLink(link);
-			break;
-		}
-	}
-	
-	/**
-	 * Perform INSERT/CREATE/UPDATE operation to update the LinkStorage.
-	 * @param lt Record of a link to be updated.
-	 * @param linkinfo Meta-information of a link to be updated.
-	 * @param op Operation to be done. (only INSERT/CREATE/UPDATE is acceptable)
-	 */
-	public void updateLink(Link lt, LinkInfo linkinfo, DM_OPERATION op) {
-		IPortObject vportSrc = null, vportDst = null;
-	
-		log.trace("updateLink(): op {} {} {}", new Object[]{op, lt, linkinfo});
+	public boolean addLinks(List<Link> links) {
+		boolean success = false;
 		
-        try {
-            // get source port vertex
-        	String dpid = HexString.toHexString(lt.getSrc());
-        	short port = lt.getSrcPort();
-        	vportSrc = dbop.searchPort(dpid, port);
-            
-            // get dest port vertex
-            dpid = HexString.toHexString(lt.getDst());
-            port = lt.getDstPort();
-            vportDst = dbop.searchPort(dpid, port);
-                        
-            if (vportSrc != null && vportDst != null) {
-            	// check if the link exists
-            	
-            	Iterable<IPortObject> currPorts = vportSrc.getLinkedPorts();
-            	List<IPortObject> currLinks = new ArrayList<IPortObject>();
-            	for (IPortObject V : currPorts) {
-            		currLinks.add(V);
-            	}
-
-            	if (currLinks.contains(vportDst)) {
-            		// TODO: update linkinfo
-            		if (op.equals(DM_OPERATION.INSERT) || op.equals(DM_OPERATION.CREATE)) {
-            			log.debug("addOrUpdateLink(): failed link exists {} {} src {} dst {}", 
-            					new Object[]{op, lt, vportSrc, vportDst});
-            		}
-            	} else {
-            		vportSrc.setLinkPort(vportDst);
-
-            		dbop.commit();
-            		log.debug("updateLink(): link added {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
-            	}
-            } else {
-            	log.error("updateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
-            	dbop.rollback();
-            }
-        } catch (TitanException e) {
-            /*
-             * retry till we succeed?
-             */
-        	e.printStackTrace();
-        	log.error("updateLink(): titan exception {} {} {}", new Object[]{op, lt, e.toString()});
-        }
-	}
-	
-	/**
-	 * Delete multiple records in LinkStorage.
-	 * @param links List of records to be deleted.
-	 */
-	@Override
-	public void deleteLinks(List<Link> links) {
-
-		for (Link lt : links) {
-			deleteLink(lt);
+		for (Link lt: links) {
+			if (! addLinkImpl(lt)) {
+				return false;
+			}
 		}
+		
+		try {
+			op.commit();
+			success = true;
+		} catch (Exception e) {
+			e.printStackTrace();
+			log.error("LinkStorageImpl:addLinks link:s{} failed", links);
+		}
+		
+		return success;
 	}
-	
+
 	/**
 	 * Delete a record in the LinkStorage.
 	 * @param lt Record to be deleted.
 	 */
 	@Override
-	public void deleteLink(Link lt) {
-		IPortObject vportSrc = null, vportDst = null;
+	public boolean deleteLink(Link lt) {
+		boolean success = false;
 		
-		log.debug("deleteLink(): {}", lt);
+		log.debug("LinkStorageImpl:deleteLink(): {}", lt);
 		
         try {
-            // get source port vertex
-         	String dpid = HexString.toHexString(lt.getSrc());
-         	short port = lt.getSrcPort();
-         	vportSrc = dbop.searchPort(dpid, port);
-            
-            // get dst port vertex
-         	dpid = HexString.toHexString(lt.getDst());
-         	port = lt.getDstPort();
-         	vportDst = dbop.searchPort(dpid, port);
-     		// FIXME: This needs to remove all edges
-         	
-         	if (vportSrc != null && vportDst != null) {
-/*
-        		int count = 0;
-         		for (Edge e : vportSrc.asVertex().getEdges(Direction.OUT)) {
-         			log.debug("deleteLink(): {} in {} out {}", 
-         					new Object[]{e.getLabel(), e.getVertex(Direction.IN), e.getVertex(Direction.OUT)});
-         			if (e.getLabel().equals("link") && e.getVertex(Direction.IN).equals(vportDst)) {
-         				graph.removeEdge(e);
-         				count++;
-         			}
-         		}
-*/
-         		vportSrc.removeLink(vportDst);
-        		dbop.commit();
-            	log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{
-            			lt, vportSrc, vportDst});
-            	
+         	if (deleteLinkImpl(lt)) {
+        		op.commit();
+        		success = true;
+            	log.debug("LinkStorageImpl:deleteLink(): deleted edges {}", lt);
             } else {
-            	log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst});
-            	dbop.rollback();
+            	op.rollback();
+            	log.error("LinkStorageImpl:deleteLink(): failed invalid vertices {}", lt);
             }
-         	
-        } catch (TitanException e) {
-            /*
-             * retry till we succeed?
-             */
-        	log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()});
-        	dbop.rollback();
+        } catch (Exception e) {
+        	op.rollback();
+        	log.error("LinkStorageImpl:deleteLink(): failed {} {}",
+        			new Object[]{lt, e.toString()});
         	e.printStackTrace();
         }
+        
+        return success;
+	}
+
+	/**
+	 * Delete multiple records in LinkStorage.
+	 * @param links List of records to be deleted.
+	 */
+	@Override
+	public boolean deleteLinks(List<Link> links) {
+		boolean success = false;
+		
+		try {
+			for (Link lt : links) {
+				if (! deleteLinkImpl(lt)) {
+					op.rollback();
+					return false;
+				}
+			}
+			op.commit();
+			success = true;
+		} catch (Exception e) {
+        	op.rollback();
+			e.printStackTrace();
+        	log.error("LinkStorageImpl:deleteLinks failed invalid vertices {}", links);
+		}
+		
+		return success;
 	}
 
 	/**
@@ -197,12 +221,11 @@
 	 * @param port Port number of desired port.
 	 * @return List of links. Empty list if no port was found.
 	 */
-	// TODO: Fix me
 	@Override
 	public List<Link> getLinks(Long dpid, short port) {
     	List<Link> links = new ArrayList<Link>();
     	
-    	IPortObject srcPort = dbop.searchPort(HexString.toHexString(dpid), port);
+    	IPortObject srcPort = op.searchPort(HexString.toHexString(dpid), port);
     	ISwitchObject srcSw = srcPort.getSwitch();
     	
     	if(srcSw != null && srcPort != null) {
@@ -221,28 +244,32 @@
 	}
 	
 	/**
-	 * Initialize the object. Open LinkStorage using given configuration file.
-	 * @param conf Path (absolute path for now) to configuration file.
-	 */
-	@Override
-	public void init(String conf) {
-		//TODO extract the DB location from properties
-		this.dbop = new GraphDBOperation(conf);
-	}
-
-	/**
 	 * Delete records of the links connected to the port specified by given DPID and port number.
 	 * @param dpid DPID of desired port.
 	 * @param port Port number of desired port.
 	 */
-	// TODO: Fix me
 	@Override
-	public void deleteLinksOnPort(Long dpid, short port) {
-		List<Link> linksToDelete = getLinks(dpid,port);
+	public boolean deleteLinksOnPort(Long dpid, short port) {
+		boolean success = false;
 		
-		for(Link l : linksToDelete) {
-			deleteLink(l);
+		List<Link> linksToDelete = getLinks(dpid, port);
+		try {
+			for(Link l : linksToDelete) {
+				if (! deleteLinkImpl(l)) {
+					op.rollback();
+					log.error("LinkStorageImpl:deleteLinksOnPort dpid:{} port:{} failed", dpid, port);
+					return false;
+				}
+			}
+			op.commit();
+			success = true;
+		} catch (Exception e) {
+        	op.rollback();
+			e.printStackTrace();
+        	log.error("LinkStorageImpl:deleteLinksOnPort dpid:{} port:{} failed", dpid, port);
 		}
+		
+		return success;
 	}
 
 	/**
@@ -250,12 +277,11 @@
 	 * @param dpid DPID of desired switch.
 	 * @return List of links. Empty list if no port was found.
 	 */
-	// TODO: Fix me
 	@Override
 	public List<Link> getLinks(String dpid) {
 		List<Link> links = new ArrayList<Link>();
 
-		ISwitchObject srcSw = dbop.searchSwitch(dpid);
+		ISwitchObject srcSw = op.searchSwitch(dpid);
 		
 		if(srcSw != null) {
 			for(IPortObject srcPort : srcSw.getPorts()) {
@@ -280,7 +306,7 @@
 	 * @return List of active links. Empty list if no port was found.
 	 */
 	public List<Link> getActiveLinks() {
-		Iterable<ISwitchObject> switches = dbop.getActiveSwitches();
+		Iterable<ISwitchObject> switches = op.getActiveSwitches();
 
 		List<Link> links = new ArrayList<Link>(); 
 		
@@ -302,12 +328,107 @@
 		return links;
 	}
 	
+	@Override
+	public LinkInfo getLinkInfo(Link link) {
+		// TODO implement this
+		return null;
+	}
+
+	/**
+	 * Finalize the object.
+	 */
+	public void finalize() {
+		close();
+	}
+
+	/**
+	 * Close LinkStorage.
+	 */
+	@Override
+	public void close() {
+		// TODO Auto-generated method stub
+//		graph.shutdown();		
+	}
+
+	/**
+	 * Update a record of link with meta-information in the LinkStorage.
+	 * @param link Record of a link to update.
+	 * @param linkinfo Meta-information of a link to be updated.
+	 */
+	private boolean setLinkInfoImpl(Link link, LinkInfo linkinfo) {
+		// TODO implement this
+		
+		return false;
+	}
+
+	private boolean addLinkImpl(Link lt) {
+		boolean success = false;
+		
+		IPortObject vportSrc = null, vportDst = null;
+		
+		// get source port vertex
+		String dpid = HexString.toHexString(lt.getSrc());
+		short port = lt.getSrcPort();
+		vportSrc = op.searchPort(dpid, port);
+		
+		// get dest port vertex
+		dpid = HexString.toHexString(lt.getDst());
+		port = lt.getDstPort();
+		vportDst = op.searchPort(dpid, port);
+		            
+		if (vportSrc != null && vportDst != null) {
+			IPortObject portExist = null;
+			// check if the link exists
+			for (IPortObject V : vportSrc.getLinkedPorts()) {
+				if (V.equals(vportDst)) {
+					portExist = V;
+					break;
+				}
+			}
+		
+			if (portExist == null) {
+				vportSrc.setLinkPort(vportDst);
+				success = true;
+			} else {
+				log.debug("LinkStorageImpl:addLinkImpl failed link exists {} {} src {} dst {}", 
+						new Object[]{op, lt, vportSrc, vportDst});
+			}
+		}
+		
+		return success;
+	}
+
+	private boolean deleteLinkImpl(Link lt) {
+		boolean success = false;
+		IPortObject vportSrc = null, vportDst = null;
+	
+	    // get source port vertex
+	 	String dpid = HexString.toHexString(lt.getSrc());
+	 	short port = lt.getSrcPort();
+	 	vportSrc = op.searchPort(dpid, port);
+	    
+	    // get dst port vertex
+	 	dpid = HexString.toHexString(lt.getDst());
+	 	port = lt.getDstPort();
+	 	vportDst = op.searchPort(dpid, port);
+	 	
+		// FIXME: This needs to remove all edges
+	 	if (vportSrc != null && vportDst != null) {
+	 		vportSrc.removeLink(vportDst);
+	    	log.debug("deleteLinkImpl(): deleted edges src {} dst {}", new Object[]{
+	    			lt, vportSrc, vportDst});
+	    	success = true;
+	    }
+	    
+	 	return success;
+	}
+
+	// TODO should be moved to TopoLinkServiceImpl (never used in this class)
 	static class ExtractLink implements PipeFunction<PathPipe<Vertex>, Link> {
 	
 		@SuppressWarnings("unchecked")
 		@Override
 		public Link compute(PathPipe<Vertex> pipe ) {
-			// TODO Auto-generated method stub
 			long s_dpid = 0;
 			long d_dpid = 0;
 			short s_port = 0;
@@ -328,22 +449,6 @@
 			return l;
 		}
 	}
-	
-	/**
-	 * Finalize the object.
-	 */
-	public void finalize() {
-		close();
-	}
-
-	/**
-	 * Close LinkStorage.
-	 */
-	@Override
-	public void close() {
-		// TODO Auto-generated method stub
-//		graph.shutdown();		
-	}
 
 
 }
diff --git a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
index e184423..26d4e40 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImpl.java
@@ -14,7 +14,7 @@
 import org.slf4j.LoggerFactory;
 
 /**
- * This is the class for storing the information of switches into CassandraDB
+ * This is the class for storing the information of switches into GraphDB
  */
 public class SwitchStorageImpl implements ISwitchStorage {
 	protected GraphDBOperation op;
@@ -47,58 +47,11 @@
 		op.close();		
 	}
 	
-	private void setStatus(String dpid, SwitchState state) {
-		ISwitchObject sw = op.searchSwitch(dpid);
-		
-		try {
-			if (sw != null) {
-				sw.setState(state.toString());
-				op.commit();
-				log.info("SwitchStorage:setStatus dpid:{} state: {} done", dpid, state);
-			}
-		} catch(Exception e) {
-			e.printStackTrace();
-			op.rollback();
-			log.info("SwitchStorage:setStatus dpid:{} state: {} failed: switch not found", dpid, state);	
-		}
-	}
-
-	/***
-	 * This function is for adding the switch into the DB.
-	 * @param dpid The switch dpid you want to add into the DB.
-	 */
-	@Override
-	public void addSwitch(String dpid) {
-		
-		log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
-		try {
-			ISwitchObject sw = newSwitch(dpid);
-			if ( sw == null ) throw new RuntimeException();
-            op.commit();
-		} catch (Exception e) {
-			e.printStackTrace();
-			op.rollback();
-			log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
-		}
-	}
-	
-	private ISwitchObject newSwitch(String dpid) {
-		ISwitchObject sw = op.searchSwitch(dpid);
-		if (sw != null) {
-			//If existing the switch. set The SW state ACTIVE. 
-			log.info("SwitchStorage:newSwitch dpid:{} already exists", dpid);
-			sw.setState(SwitchState.ACTIVE.toString());
-		} else {
-			sw = op.newSwitch(dpid);
-			if (sw != null) {
-				sw.setState(SwitchState.ACTIVE.toString());
-				log.info("SwitchStorage:newSwitch dpid:{} added", dpid);
-			} else {
-				log.error("switchStorage:newSwitch dpid:{} failed -> newSwitch failed", dpid);
-			}
-		}
-		return sw;
-	}
+	// Method designing policy:
+	//  op.commit() and op.rollback() MUST called in public (first-class) methods.
+	//  A first-class method MUST NOT call other first-class method.
+	//  Routine process should be implemented in private method.
+	//  A private method MUST NOT call commit or rollback.
 	
 	/***
 	 * This function is for updating the switch into the DB.
@@ -107,22 +60,129 @@
 	 * @param dmope	The DM_OPERATION of the switch
 	 */
 	@Override
-	public void update(String dpid, SwitchState state, DM_OPERATION dmope) {
-		log.info("SwitchStorage:update dpid:{} state: {} ", dpid, state);
-        switch(dmope) {
-        	case UPDATE:
-        	case INSERT:
-        	case CREATE:
-                addSwitch(dpid);
-                if (state != SwitchState.ACTIVE) {
-                	setStatus(dpid, state);
-                }
-                break;
-        	case DELETE:
-                deleteSwitch(dpid);
-                break;
-        	default:
-        }
+	public boolean updateSwitch(String dpid, SwitchState state, DM_OPERATION dmope) {
+		boolean success = false;
+		ISwitchObject sw = null;
+		
+		log.info("SwitchStorage:update {} dpid:{}", dmope, dpid);
+	    switch(dmope) {
+	    	case UPDATE:
+            	try {
+		    		sw = op.searchSwitch(dpid);
+		    		if (sw != null) {
+			            	setSwitchStateImpl(sw, state);
+							op.commit();
+							success = true;
+		    		}
+				} catch (Exception e) {
+					op.rollback();
+					e.printStackTrace();
+					log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid);
+				}
+	    		break;
+	    	case INSERT:
+	    	case CREATE:
+            	try {
+		            sw = addSwitchImpl(dpid);
+		            if (sw != null) {
+			            if (state != SwitchState.ACTIVE) {
+			            	setSwitchStateImpl(sw, state);
+			            }
+						op.commit();
+						success = true;
+		            }
+				} catch (Exception e) {
+					op.rollback();
+					e.printStackTrace();
+					log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid);
+				}
+	            break;
+	    	case DELETE:
+	            try {
+		    		sw = op.searchSwitch(dpid);
+		    		if (sw != null) {
+				            deleteSwitchImpl(sw);
+							op.commit();
+							success = true;
+		    		}
+				} catch (Exception e) {
+					op.rollback();
+					e.printStackTrace();
+					log.info("SwitchStorage:update {} dpid:{} failed", dmope, dpid);
+				}
+	            break;
+	    	default:
+	    }
+	    
+	    return success;
+	}
+	
+	@Override
+	public boolean addSwitch(IOFSwitch sw) {
+		boolean success = false;
+		
+		String dpid = sw.getStringId();
+		log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
+		
+		try {
+			ISwitchObject curr = op.searchSwitch(dpid);
+			if (curr != null) {
+				//If existing the switch. set The SW state ACTIVE. 
+				log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
+				setSwitchStateImpl(curr, SwitchState.ACTIVE);
+			} else {
+				curr = addSwitchImpl(dpid);
+			}
+	
+			for (OFPhysicalPort port: sw.getPorts()) {
+				IPortObject p = op.searchPort(dpid, port.getPortNumber());
+				if (p != null) {
+		    		log.error("SwitchStorage:addPort dpid:{} port:{} exists", dpid, port.getPortNumber());
+		    		setPortStateImpl(p, port.getState(), port.getName());
+		    		p.setState("ACTIVE");
+				} else {
+					p = addPortImpl(curr, port.getPortNumber());
+					setPortStateImpl(p, port.getState(), port.getName());
+				}         		
+			}
+			op.commit();
+			success = true;
+		} catch (Exception e) {
+			op.rollback();
+			e.printStackTrace();
+			log.error("SwitchStorage:addSwitch dpid:{} failed", dpid);
+		}
+		
+		return success;
+	}
+
+	/***
+	 * This function is for adding the switch into the DB.
+	 * @param dpid The switch dpid you want to add into the DB.
+	 */
+	@Override
+	public boolean addSwitch(String dpid) {
+		boolean success = false;
+		
+		log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
+		try {
+			ISwitchObject sw = op.searchSwitch(dpid);
+			if (sw != null) {
+				//If existing the switch. set The SW state ACTIVE. 
+				log.info("SwitchStorage:addSwitch dpid:{} already exists", dpid);
+				setSwitchStateImpl(sw, SwitchState.ACTIVE);
+			} else {
+				addSwitchImpl(dpid);
+			}
+			op.commit();
+			success = true;
+		} catch (Exception e) {
+			op.rollback();
+			e.printStackTrace();
+			log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
+		}
+		
+		return success;
 	}
 
 	/***
@@ -130,120 +190,178 @@
 	 * @param dpid The switch dpid you want to delete from the DB.
 	 */
 	@Override
-	public void deleteSwitch(String dpid) {
+	public boolean deleteSwitch(String dpid) {
+		boolean success = false;
+		
 		try {
 			ISwitchObject sw = op.searchSwitch(dpid);
-            if (sw  != null) {
-            	op.removeSwitch(sw);
-            	op.commit();
-            	log.info("SwitchStorage:DeleteSwitch dpid:{} done", dpid);
-            }
+			if (sw != null) {
+				deleteSwitchImpl(sw);
+	        	op.commit();
+			}
+			success = true;
 		} catch (Exception e) {
+			op.rollback();
 			e.printStackTrace();
-			op.rollback();			
 			log.error("SwitchStorage:deleteSwitch {} failed", dpid);
 		}
+	
+		return success;
+	}
 
+	public boolean updatePort(String dpid, short portNum, int state, String desc) {
+		boolean success = false;
+		
+		try {
+			ISwitchObject sw = op.searchSwitch(dpid);
+	
+	        if (sw != null) {
+	        	IPortObject p = sw.getPort(portNum);
+	        	log.info("SwitchStorage:updatePort dpid:{} port:{}", dpid, portNum);
+	        	if (p != null) {
+	        		setPortStateImpl(p, state, desc);
+	        	}
+	        	op.commit();
+        		success = true;
+	        } else {
+	    		log.error("SwitchStorage:updatePort dpid:{} port:{} : failed switch does not exist", dpid, portNum);
+	        }
+		} catch (Exception e) {
+			op.rollback();
+			e.printStackTrace();
+			log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, portNum);
+		}	
+
+		return success;
 	}
 
 	/***
 	 * This function is for adding the switch port into the DB.
 	 * @param dpid The switch dpid that has the port.
-	 * @param port The port you want to add the switch.
+	 * @param phport The port you want to add the switch.
 	 */
 	@Override
-	public void addPort(String dpid, OFPhysicalPort port) {
+	public boolean addPort(String dpid, OFPhysicalPort phport) {
+		boolean success = false;
 		
-       if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & port.getConfig()) > 0) ||
-        					((OFPortState.OFPPS_LINK_DOWN.getValue() & port.getState()) > 0)) {
-    	     deletePort(dpid, port.getPortNumber());
-             return;  
-       }
-
+		if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & phport.getConfig()) > 0) ||
+				((OFPortState.OFPPS_LINK_DOWN.getValue() & phport.getState()) > 0)) {
+			// just dispatch to deletePort()
+			return deletePort(dpid, phport.getPortNumber());
+		}
+	
 		try {
 			ISwitchObject sw = op.searchSwitch(dpid);
-
-            if (sw != null) {
-            	IPortObject p = op.searchPort(dpid, port.getPortNumber());
-            	log.info("SwitchStorage:addPort dpid:{} port:{}", dpid, port.getPortNumber());
-            	if (p != null) {
-            		log.error("SwitchStorage:addPort dpid:{} port:{} exists setting as ACTIVE", dpid, port.getPortNumber());
-            		p.setState("ACTIVE");
-            		p.setPortState(port.getState());
-            		p.setDesc(port.getName());
-            		op.commit();
-            	} else {
-            		p = op.newPort(dpid, port.getPortNumber());
-            		p.setState("ACTIVE");
-            		p.setPortState(port.getState());
-            		p.setDesc(port.getName());
-            		sw.addPort(p);
-            		op.commit();
-            	}
-            } else {
-        		log.error("SwitchStorage:addPort dpid:{} port:{} : failed switch does not exist", dpid, port.getPortNumber());
-            }
+	
+	        if (sw != null) {
+	        	IPortObject p = sw.getPort(phport.getPortNumber());
+	        	log.info("SwitchStorage:addPort dpid:{} port:{}", dpid, phport.getPortNumber());
+	        	if (p != null) {
+	        		setPortStateImpl(p, phport.getState(), phport.getName());
+	        		log.error("SwitchStorage:addPort dpid:{} port:{} exists setting as ACTIVE", dpid, phport.getPortNumber());
+	        	} else {
+	        		addPortImpl(sw, phport.getPortNumber());
+	        		setPortStateImpl(p, phport.getState(), phport.getName());
+	        	}
+        		op.commit();
+        		success = true;
+	        } else {
+	    		log.error("SwitchStorage:addPort dpid:{} port:{} : failed switch does not exist", dpid, phport.getPortNumber());
+	        }
 		} catch (Exception e) {
-			e.printStackTrace();
 			op.rollback();
-			log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, port.getPortNumber());
+			e.printStackTrace();
+			log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, phport.getPortNumber());
 		}	
 
+		return success;
 	}
-	
+
 	/***
 	 * This function is for deleting the switch port from the DB.
 	 * @param dpid The switch dpid that has the port.
 	 * @param port The port you want to delete the switch.
 	 */
 	@Override
-	public void deletePort(String dpid, short port) {
+	public boolean deletePort(String dpid, short port) {
+		boolean success = false;
+		
 		try {
 			ISwitchObject sw = op.searchSwitch(dpid);
-
-            if (sw != null) {
-            	IPortObject p = op.searchPort(dpid, port);
-                if (p != null) {
-            		log.info("SwitchStorage:deletePort dpid:{} port:{} found and set INACTIVE", dpid, port);
-            		p.setState("INACTIVE");
-            		op.commit();
-            	}
-            }
+	
+	        if (sw != null) {
+	        	IPortObject p = sw.getPort(port);
+	            if (p != null) {
+	        		log.info("SwitchStorage:deletePort dpid:{} port:{} found and set INACTIVE", dpid, port);
+	        		deletePortImpl(p);
+	        		op.commit();
+	        	}
+	        }
 		} catch (Exception e) {
-			e.printStackTrace();
 			op.rollback();
+			e.printStackTrace();
 			log.info("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port);
-		}	
+		}
+
+		return success;
 	}
 
-	@Override
-	public void addSwitch(IOFSwitch sw) {
-		// TODO Auto-generated method stub
-		String dpid = sw.getStringId();
-		log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
-		try {
-			ISwitchObject switchObject = newSwitch(dpid);
-        	for (OFPhysicalPort port: sw.getPorts()) {
-        		IPortObject p = op.searchPort(dpid, port.getPortNumber());
-        		if (p != null) {
-            		log.error("SwitchStorage:addPort dpid:{} port:{} exists", dpid, port.getPortNumber());
-            		p.setState("ACTIVE");
-            		p.setPortState(port.getState());
-            		p.setDesc(port.getName());
-            	} else {
-            		p = op.newPort(dpid, port.getPortNumber());
-            		p.setState("ACTIVE");
-            		p.setPortState(port.getState());
-            		p.setDesc(port.getName());           		
-            		switchObject.addPort(p);
-            	}         		
-        	}
-            op.commit();
-		} catch (Exception e) {
-			e.printStackTrace();
-			op.rollback();
-			log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
-		}		
+	private ISwitchObject addSwitchImpl(String dpid) {
+		if (dpid != null) {
+			ISwitchObject sw = op.newSwitch(dpid);
+			sw.setState(SwitchState.ACTIVE.toString());
+			log.info("SwitchStorage:addSwitchImpl dpid:{} added", dpid);
+			return sw;
+		} else {
+			return null;
+		}
+	}
+	
+	private void setSwitchStateImpl(ISwitchObject sw, SwitchState state) {
+		if (sw != null && state != null) {
+			sw.setState(state.toString());
+			log.info("SwitchStorage:setSwitchStateImpl dpid:{} updated {}",
+					sw.getDPID(), state.toString());
+		}
+	}
+	
+	private void deleteSwitchImpl(ISwitchObject sw) {
+        if (sw  != null) {
+        	op.removeSwitch(sw);
+        	log.info("SwitchStorage:DeleteSwitchImpl dpid:{} done",
+        			sw.getDPID());
+        }
+	}
+
+	private IPortObject addPortImpl(ISwitchObject sw, short portNum) {
+		IPortObject p = op.newPort(sw.getDPID(), portNum);
+		p.setState("ACTIVE");
+		sw.addPort(p);
+    	log.info("SwitchStorage:addPortImpl dpid:{} port:{} done",
+    			sw.getDPID(), portNum);
 		
+		return p;
+	}
+
+	private void setPortStateImpl(IPortObject port, Integer state, String desc) {
+		if (port != null) {
+			if (state != null) {
+				port.setPortState(state);
+			}
+			if (desc != null) {
+				port.setDesc(desc);
+			}
+			
+	    	log.info("SwitchStorage:setPortStateImpl port:{} state:{} desc:{} done",
+	    			new Object[] {port.getPortId(), state, desc});
+		}
+	}
+	
+	private void deletePortImpl(IPortObject port) {
+		if (port != null) {
+			op.removePort(port);
+	    	log.info("SwitchStorage:deletePortImpl port:{} done",
+	    			port.getPortId());
+		}
 	}
 }
\ No newline at end of file
diff --git a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
index 28966a9..9eefba3 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/floodlightlistener/NetworkGraphPublisher.java
@@ -41,6 +41,7 @@
 import net.onrc.onos.ofcontroller.core.internal.SwitchStorageImpl;
 import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryListener;
 import net.onrc.onos.ofcontroller.linkdiscovery.ILinkDiscoveryService;
+import net.onrc.onos.ofcontroller.linkdiscovery.LinkInfo;
 import net.onrc.onos.registry.controller.IControllerRegistryService;
 import net.onrc.onos.registry.controller.IControllerRegistryService.ControlChangeCallback;
 import net.onrc.onos.registry.controller.RegistryException;
@@ -90,12 +91,17 @@
 
 		@Override
 		public void controlChanged(long dpid, boolean hasControl) {
-			// TODO Auto-generated method stub
-			
 			if (hasControl) {
 				log.debug("got control to set inactive sw {}", HexString.toHexString(dpid));
-				swStore.update(HexString.toHexString(dpid),SwitchState.INACTIVE, DM_OPERATION.UPDATE);
-			    registryService.releaseControl(dpid);	
+				try {
+					if (swStore.updateSwitch(HexString.toHexString(dpid), SwitchState.INACTIVE, DM_OPERATION.UPDATE)) {
+					    registryService.releaseControl(dpid);
+					    
+					    // TODO publish UPDATE_SWITCH event here
+					}
+				} catch (Exception e) {
+	                log.error("Error in SwitchCleanup:controlChanged ", e);
+				}
 			}						
 		}
     }
@@ -118,12 +124,12 @@
 				//	log.debug("sw {} is controlled by controller: {}",HexString.toHexString(dpid),controller);
 				}
 			} catch (NumberFormatException e) {
-				// TODO Auto-generated catch block
+				log.debug("Caught NumberFormatException trying to requestControl in cleanup thread");
 				e.printStackTrace();
 			} catch (RegistryException e) {
 				log.debug("Caught RegistryException trying to requestControl in cleanup thread");
 				e.printStackTrace();
-			}			
+			}
 		}
     	op.close();
     }
@@ -137,20 +143,27 @@
 		switch (update.getOperation()) {
 			case LINK_REMOVED:
 				log.debug("LinkDiscoveryUpdate(): Removing link {}", lt);
-				linkStore.update(lt, DM_OPERATION.DELETE);
-				// TODO: Move network map link removal here
-				// reconcile paths here
-//				IPortObject srcPort = conn.utils().searchPort(conn, HexString.toHexString(update.getSrc()), update.getSrcPort());
+				
+				if (linkStore.deleteLink(lt)) {
+				    // TODO publish DELETE_LINK event here
+				}
 				break;
 			case LINK_UPDATED:
 				log.debug("LinkDiscoveryUpdate(): Updating link {}", lt);
-				linkStore.update(lt, DM_OPERATION.UPDATE);
+				
+				LinkInfo linfo = linkStore.getLinkInfo(lt);
+				// TODO update "linfo" using portState derived using "update"
+				if (linkStore.update(lt, linfo, DM_OPERATION.UPDATE)) {
+				    // TODO publish UPDATE_LINK event here
+				}
 				break;
 			case LINK_ADDED:
 				log.debug("LinkDiscoveryUpdate(): Adding link {}", lt);
-				linkStore.update(lt, DM_OPERATION.INSERT);
+				
+				if (linkStore.addLink(lt)) {
+				    // TODO publish ADD_LINK event here
+				}
 				break;
-					
 			default:
 				break;
 		}
@@ -159,36 +172,41 @@
 
 	@Override
 	public void addedSwitch(IOFSwitch sw) {
-
 		if (registryService.hasControl(sw.getId())) {
-	        	swStore.addSwitch(sw);
+			if (swStore.addSwitch(sw)) {
+			    // TODO publish ADD_SWITCH event here
+			}
 		}
-
 	}
 
 	@Override
 	public void removedSwitch(IOFSwitch sw) {
-		// TODO Auto-generated method stub
-
+		if (registryService.hasControl(sw.getId())) {
+			if (swStore.deleteSwitch(sw.getStringId())) {
+			    // TODO publish DELETE_SWITCH event here
+			}
+		}
 	}
 
 	@Override
 	public void switchPortChanged(Long switchId) {
 		// TODO Auto-generated method stub
-
+		// NOTE: Event not needed here. This callback always coincide with add/remove callback.
 	}
 
 
 	@Override
 	public void switchPortAdded(Long switchId, OFPhysicalPort port) {
-		// TODO Auto-generated method stub
-		swStore.addPort(HexString.toHexString(switchId), port);
+		if (swStore.addPort(HexString.toHexString(switchId), port)) {
+		    // TODO publish ADD_PORT event here
+		}
 	}
 
 	@Override
 	public void switchPortRemoved(Long switchId, OFPhysicalPort port) {
-		// TODO Auto-generated method stub
-		swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber());		
+		if (swStore.deletePort(HexString.toHexString(switchId), port.getPortNumber())) {
+		    // TODO publish DELETE_PORT event here
+		}
 	}
 
 	@Override
@@ -198,7 +216,6 @@
 
 	@Override
 	public void deviceAdded(IDevice device) {
-		// TODO Auto-generated method stub
 		log.debug("{}:deviceAdded(): Adding device {}",this.getClass(),device.getMACAddressString());
 		devStore.addDevice(device);
 	}
@@ -211,16 +228,12 @@
 
 	@Override
 	public void deviceMoved(IDevice device) {
-		// TODO Auto-generated method stub
 		devStore.changeDeviceAttachments(device);
-
 	}
 
 	@Override
 	public void deviceIPV4AddrChanged(IDevice device) {
-		// TODO Auto-generated method stub
 		devStore.changeDeviceIPv4Address(device);
-
 	}
 
 	@Override
@@ -260,7 +273,6 @@
 	@Override
 	public void init(FloodlightModuleContext context)
 			throws FloodlightModuleException {
-		// TODO Auto-generated method stub
 		Map<String, String> configMap = context.getConfigParams(this);
 		String conf = configMap.get(DBConfigFile);
 		op = new GraphDBOperation(conf);
@@ -287,7 +299,6 @@
 
 	@Override
 	public void startUp(FloodlightModuleContext context) {
-		// TODO Auto-generated method stub
 		Map<String, String> configMap = context.getConfigParams(this);
 		String cleanupNeeded = configMap.get(CleanupEnabled);
 
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
index fcc753f..abb8809 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/LinkStorageImplTest.java
@@ -1,8 +1,6 @@
 package net.onrc.onos.ofcontroller.core.internal;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
 
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -134,12 +132,41 @@
 		linkStorage.close();
 	}
 	
+
+	/**
+	 * Test if {@link LinkStorageImpl#addLink(Link)} can correctly creates a Link.
+	 */
+	@Test
+	public void testAddLink() {
+		Link linkToCreate = createFeasibleLink();
+		Link linkToVerify = createFeasibleLink();
+		
+		//Use the link storage API to add the link
+		linkStorage.addLink(linkToCreate);
+		doTestLinkExist(linkToVerify);
+	}
+	
+	/**
+	 * Test if {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly creates multiple Links.
+	 */
+	@Test
+	public void testAddLinks() {
+		List<Link> linksToCreate = createFeasibleLinks();
+		List<Link> linksToVerify = createFeasibleLinks();
+	
+		// Test creation of new links
+		linkStorage.addLinks(linksToCreate);
+		for(Link l : linksToVerify) {
+			doTestLinkExist(l);
+		}
+	}
+
 	// TODO: remove @Ignore after UPDATE method is implemented
 	/**
-	 * Test if {@link LinkStorageImpl#update(Link, LinkInfo, DM_OPERATION)} can correctly updates LinkInfo for a Link.
+	 * Test if {@link LinkStorageImpl#updateLinkInfo(Link, LinkInfo, DM_OPERATION)} can correctly updates LinkInfo for a Link.
 	 */
 	@Ignore @Test
-	public void testUpdate_UpdateSingleLink() {
+	public void testUpdate_Update() {
 		Link linkToUpdate= createExistingLink();
 		long currentTime = System.currentTimeMillis();
 		LinkInfo infoToUpdate = createFeasibleLinkInfo(currentTime);
@@ -154,12 +181,12 @@
 	 * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)} can correctly creates a Link.
 	 */
 	@Test
-	public void testUpdate_CreateSingleLink() {
+	public void testUpdate_Create() {
 		Link linkToCreate = createFeasibleLink();
 		Link linkToVerify = createFeasibleLink();
 		
 		//Use the link storage API to add the link
-		linkStorage.update(linkToCreate, ILinkStorage.DM_OPERATION.CREATE);
+		linkStorage.update(linkToCreate, null, ILinkStorage.DM_OPERATION.CREATE);
 		doTestLinkExist(linkToVerify);
 	}
 
@@ -167,12 +194,12 @@
 	 * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)}can correctly inserts a Link.
 	 */
 	@Test
-	public void testUpdate_InsertSingleLink(){
+	public void testUpdate_Insert(){
 		Link linkToInsert = createFeasibleLink();
 		Link linkToVerify = createFeasibleLink();
 		
 		//Use the link storage API to add the link
-		linkStorage.update(linkToInsert, ILinkStorage.DM_OPERATION.INSERT);
+		linkStorage.update(linkToInsert, null, ILinkStorage.DM_OPERATION.INSERT);
 		doTestLinkExist(linkToVerify);
 	}
 	
@@ -180,125 +207,16 @@
 	 * Test if {@link LinkStorageImpl#update(Link, DM_OPERATION)} can correctly deletes a Link.
 	 */
 	@Test
-	public void testUpdate_DeleteSingleLink(){
+	public void testUpdate_Delete(){
 		Link linkToDelete = createExistingLink();
 		Link linkToVerify = createExistingLink();
 
 		// Test deletion of existing link
-		linkStorage.update(linkToDelete, DM_OPERATION.DELETE);
+		linkStorage.update(linkToDelete, null, DM_OPERATION.DELETE);
 		doTestLinkNotExist(linkToVerify);
 	}
 
 	/**
-	 * Test if {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly creates multiple Links.
-	 */
-	@Test
-	public void testUpdate_CreateLinks(){
-		List<Link> linksToCreate = createFeasibleLinks();
-		List<Link> linksToVerify = createFeasibleLinks();
-
-		// Test creation of new links
-		linkStorage.update(linksToCreate, ILinkStorage.DM_OPERATION.CREATE);
-		for(Link l : linksToVerify) {
-			doTestLinkExist(l);
-		}
-	}
-
-	/**
-	 * Test if {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly inserts multiple Links.
-	 */
-	@Test
-	public void testUpdate_InsertLinks(){
-		List<Link> linksToInsert = createFeasibleLinks();
-		List<Link> linksToVerify = createFeasibleLinks();
-		
-		// Test insertion of new links
-		linkStorage.update(linksToInsert, ILinkStorage.DM_OPERATION.INSERT);
-		for(Link l : linksToVerify) {
-			doTestLinkExist(l);
-		}
-	}
-	
-	/**
-	 * Test if  {@link LinkStorageImpl#update(List, DM_OPERATION)} can correctly deletes multiple Links.
-	 */
-	@Test
-	public void testUpdate_DeleteLinks(){
-		List<Link> linksToDelete = createExistingLinks();
-		List<Link> linksToVerify = createExistingLinks();
-		
-		// Test deletion of existing links
-		linkStorage.update(linksToDelete, ILinkStorage.DM_OPERATION.DELETE);
-		for(Link l : linksToVerify) {
-			doTestLinkNotExist(l);
-		}
-	}
-	
-	// TODO: remove @Ignore after UPDATE method is implemented
-	/**
-	 * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly updates LinkInfo for a Link.
-	 */
-	@Ignore @Test
-	public void testUpdateLink_Update() {
-		Link linkToUpdate= createExistingLink();
-		long currentTime = System.currentTimeMillis();
-		LinkInfo infoToUpdate = createFeasibleLinkInfo(currentTime);
-		LinkInfo infoToVerify = createFeasibleLinkInfo(currentTime);
-
-		linkStorage.updateLink(linkToUpdate, infoToUpdate, ILinkStorage.DM_OPERATION.UPDATE);
-		
-		doTestLinkHasStateOf(linkToUpdate, infoToVerify);
-	}
-	
-	/**
-	 * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly creates a Link.
-	 */
-	@Test
-	public void testUpdateLink_Create() {
-		Link linkToCreate = createFeasibleLink();
-		Link linkToVerify = createFeasibleLink();
-		
-		//Use the link storage API to add the link
-		linkStorage.updateLink(linkToCreate, null, ILinkStorage.DM_OPERATION.CREATE);
-		doTestLinkExist(linkToVerify);
-	}
-	
-	/**
-	 * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly inserts a Link.
-	 */
-	@Test
-	public void testUpdateLink_Insert() {
-		Link linkToInsert = createFeasibleLink();
-		Link linkToVerify = createFeasibleLink();
-		
-		//Use the link storage API to add the link
-		linkStorage.updateLink(linkToInsert, null, ILinkStorage.DM_OPERATION.INSERT);
-
-		doTestLinkExist(linkToVerify);
-	}
-	
-	// TODO: Check if addOrUpdateLink() should accept DELETE operation. If not, remove this test.
-	/**
-	 * Test if {@link LinkStorageImpl#updateLink(Link, LinkInfo, DM_OPERATION)} can correctly deletes a Link.
-	 */
-	@Ignore @Test
-	public void testUpdateLink_Delete() {
-		Link linkToDelete = createExistingLink();
-		Link linkToVerify = createExistingLink();
-
-		// Test deletion of existing link
-		linkStorage.updateLink(linkToDelete, null, DM_OPERATION.DELETE);
-		doTestLinkNotExist(linkToVerify);
-		
-		linkToDelete = createFeasibleLink();
-		linkToVerify = createFeasibleLink();
-
-		// Test deletion of not-existing link
-		linkStorage.updateLink(linkToDelete, null, DM_OPERATION.DELETE);
-		doTestLinkNotExist(linkToVerify);
-	}
-	
-	/**
 	 * Test if {@link LinkStorageImpl#getLinks(Long, short)} can correctly return Links connected to specific DPID and port.
 	 */
 	@Test
@@ -392,6 +310,14 @@
 		
 		doTestLinkNotExist(linkToVerify);
 	}
+	
+	/**
+	 * Test if {@link LinkStorageImpl#getLinkInfo(Link)} can delete Links.
+	 */
+	@Ignore @Test
+	public void testGetLinkInfo() {
+		fail("not yet implemented");
+	}
 
 	/**
 	 * Test if specific link exists
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
index 24c17f4..53a5b12 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTest.java
@@ -115,6 +115,7 @@
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState(state);
 		mockISw.setState(state);
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
@@ -204,21 +205,18 @@
 		
 		//Mock Switch
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
-		mockISw.setState("ACTIVE");
 		mockISw.setState(stateINACTIVE.toString());
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
-		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
-		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);	
-		mockOpe.commit();
 		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
 		mockOpe.commit();
 		mockOpe.close();
 		replay(mockOpe);
 		
 		swSt.init(conf);
-		swSt.update(dpid, stateINACTIVE, opUPDATE);
+		swSt.updateSwitch(dpid, stateINACTIVE, opUPDATE);
 	}
 	
 	/**
@@ -241,19 +239,17 @@
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState("ACTIVE");
 		mockISw.setState(stateINACTIVE.toString());
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
-		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
 		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);	
 		mockOpe.commit();
-		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
-		mockOpe.commit();
 		mockOpe.close();
 		replay(mockOpe);
 		
 		swSt.init(conf);
-		swSt.update(dpid, stateINACTIVE, opCREATE);
+		swSt.updateSwitch(dpid, stateINACTIVE, opCREATE);
 	}
 	
 	/**
@@ -276,19 +272,17 @@
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState("ACTIVE");
 		mockISw.setState(stateINACTIVE.toString());
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
-		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
 		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
 		mockOpe.commit();
-		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
-		mockOpe.commit();
 		mockOpe.close();
 		replay(mockOpe);
 		
 		swSt.init(conf);
-		swSt.update(dpid, stateINACTIVE, opINSERT);
+		swSt.updateSwitch(dpid, stateINACTIVE, opINSERT);
 	}
 	
 	/**
@@ -310,6 +304,7 @@
 		//Mock Switch
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState(stateACTIVE.toString());
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
@@ -324,7 +319,7 @@
 		
 		swSt.init(conf);
 		swSt.addSwitch(dpid);
-		swSt.update(dpid, stateACTIVE, opDELETE);
+		swSt.updateSwitch(dpid, stateACTIVE, opDELETE);
 	}
 	
 	/**
@@ -344,6 +339,7 @@
 		//Mock Switch
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState(state);
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
@@ -380,6 +376,7 @@
 		//Mock Switch
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState(state);
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
@@ -432,6 +429,8 @@
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState(state);
 		mockISw.addPort(mockIPort);
+		expect(mockISw.getPort(anyShort())).andReturn(null);
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
@@ -439,7 +438,7 @@
 		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
 		mockOpe.commit();
 		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
-		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+//		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
 		expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);	
 		mockOpe.commit();
 		mockOpe.close();
@@ -464,7 +463,8 @@
 		String dpid = "00:00:00:00:00:00:0a:01";
 		short portNumber = 5;
 		String swState = "ACTIVE";
-		String portState = "INACTIVE";
+//		String portState = "INACTIVE";
+		String portId = "5";
 		String name = "port 5 at SEA switch";
 		
 		OFPhysicalPort portToAdd = new OFPhysicalPort();
@@ -475,24 +475,27 @@
 		
 		//Expectation of  mock Port
 		IPortObject mockIPort = createMock(IPortObject.class);
-		mockIPort.setState(portState);
-		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
-		mockIPort.setDesc(name);
+		expect(mockIPort.getPortId()).andReturn(portId);
+//		mockIPort.setState(portState);
+//		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
+//		mockIPort.setDesc(name);
 		replay(mockIPort);
 		
 		//Expectation of mock Switch
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState(swState);
 //		mockISw.removePort(mockIPort);
+		expect(mockISw.getPort(anyShort())).andReturn(mockIPort);
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
 		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
 		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);	
-		mockOpe.commit();	
+		mockOpe.commit();
 		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
-		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
-//		mockOpe.removePort(mockIPort);
+//		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
+		mockOpe.removePort(mockIPort);
 		mockOpe.commit();
 		mockOpe.close();
 		replay(mockOpe);
@@ -528,6 +531,7 @@
 		
 		//Expectation of mock Switch
 		ISwitchObject mockISw = createStrictMock(ISwitchObject.class);
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
@@ -572,6 +576,8 @@
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState(state);
 		mockISw.addPort(mockIPort);
+		expect(mockISw.getPort(portNumber)).andReturn(null);
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
@@ -579,7 +585,7 @@
 		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
 		mockOpe.commit();
 		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
-		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+//		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
 		expect(mockOpe.newPort(dpid, portNumber)).andReturn(null);	
 		mockOpe.rollback();
 		mockOpe.close();
@@ -623,6 +629,8 @@
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState(state);
 		mockISw.addPort(mockIPort);
+		expect(mockISw.getPort(portNumber)).andReturn(null);
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
@@ -630,7 +638,7 @@
 		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
 		mockOpe.commit();
 		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
-		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+//		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
 		expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);	
 		mockOpe.commit();
 		expectLastCall().andThrow(new RuntimeException());
@@ -658,6 +666,7 @@
 		short portNumber = 5;
 		String portState = "INACTIVE";
 		String swState = "ACTIVE";
+		String portId = "5";
 		String name = "port 5 at SEA switch";
 		
 		OFPhysicalPort portToAdd = new OFPhysicalPort();
@@ -669,31 +678,33 @@
 		//Expectation of  mock Port
 		IPortObject mockIPort = createMock(IPortObject.class);
 		mockIPort.setState(swState);
-		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
+//		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
 		mockIPort.setDesc(name);
 		mockIPort.setState(portState);
+		expect(mockIPort.getPortId()).andReturn(portId);
 		replay(mockIPort);
 		
 		//Expectation of mock Switch
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState(swState);
-		mockISw.addPort(mockIPort);
 //		mockISw.removePort(mockIPort);
+		expect(mockISw.getPort(portNumber)).andReturn(null);
+		mockISw.addPort(mockIPort);
+		expect(mockISw.getPort(portNumber)).andReturn(mockIPort);
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
-		
-
 		//Expectation of mock operation.
 		expect(mockOpe.searchSwitch(dpid)).andReturn(null);
 		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
 		mockOpe.commit();
 		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
-		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+//		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
 		expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);	
 		mockOpe.commit();
 		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
-		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
-//		mockOpe.removePort(mockIPort);
+//		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
+		mockOpe.removePort(mockIPort);
 		mockOpe.commit();
 		mockOpe.close();
 		replay(mockOpe);
@@ -719,6 +730,7 @@
 		short portNumber = 5;
 		String swState = "ACTIVE";
 		String portState = "INACTIVE";
+		String portId = "5";
 		String name = "port 5 at SEA switch";
 		
 		OFPhysicalPort portToAdd = new OFPhysicalPort();
@@ -733,13 +745,18 @@
 		mockIPort.setPortState(OFPortState.OFPPS_STP_FORWARD.getValue());
 		mockIPort.setDesc(name);
 		mockIPort.setState(portState);
+		expect(mockIPort.getPortId()).andReturn(portId);
 		replay(mockIPort);
 		
 		//Expectation of mock Switch
 		ISwitchObject mockISw = createMock(ISwitchObject.class);
 		mockISw.setState(swState);
 		mockISw.addPort(mockIPort);
+		expect(mockISw.getPort(portNumber)).andReturn(null);
+		expect(mockISw.getPort(portNumber)).andReturn(mockIPort).anyTimes();
 //		mockISw.removePort(mockIPort);
+		
+		expect(mockISw.getDPID()).andReturn(dpid).anyTimes();
 		replay(mockISw);
 		
 		//Expectation of mock operation.
@@ -747,15 +764,15 @@
 		expect(mockOpe.newSwitch(dpid)).andReturn(mockISw);
 		mockOpe.commit();
 		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
-		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
+//		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(null);
 		expect(mockOpe.newPort(dpid, portNumber)).andReturn(mockIPort);	
 		mockOpe.commit();
 		expect(mockOpe.searchSwitch(dpid)).andReturn(mockISw);
-		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
-		mockOpe.commit(); // Cannot generate exception..need to revisit this test
-//		mockOpe.removePort(mockIPort);
-//		expectLastCall().andThrow(new RuntimeException());
-//		mockOpe.rollback();
+//		expect(mockOpe.searchPort(dpid, portNumber)).andReturn(mockIPort);
+//		mockOpe.commit(); // Cannot generate exception..need to revisit this test
+		mockOpe.removePort(mockIPort);
+		expectLastCall().andThrow(new RuntimeException());
+		mockOpe.rollback();
 		mockOpe.close();
 		replay(mockOpe);
 	
diff --git a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
index 19ac709..585a8fd 100644
--- a/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
+++ b/src/test/java/net/onrc/onos/ofcontroller/core/internal/SwitchStorageImplTestBB.java
@@ -106,7 +106,7 @@
 	public void testAddSwitchExisting() {
 		String dpid = "00:00:00:00:00:00:0a:06";
 		
-		swSt.update(dpid, SwitchState.INACTIVE, DM_OPERATION.UPDATE);
+		swSt.updateSwitch(dpid, SwitchState.INACTIVE, DM_OPERATION.UPDATE);
 		ISwitchObject sw = ope.searchSwitch(dpid);
 		assertTrue(sw != null);
 		assertEquals(sw.getState(), SwitchState.INACTIVE.toString());
@@ -136,7 +136,7 @@
 		
 		ISwitchObject sw = ope.searchSwitch(dpid);
 		assertTrue(sw == null);
-		swSt.update(dpid, state, dmope);
+		swSt.updateSwitch(dpid, state, dmope);
 		ISwitchObject sw2 = ope.searchSwitch(dpid);
 		assertTrue(sw2 != null);
 		assertEquals(sw2.getState(), state.toString());
@@ -161,7 +161,7 @@
 		
 		ISwitchObject sw = ope.searchSwitch(dpid);
 		assertTrue(sw != null);
-		swSt.update(dpid, state, dmope);
+		swSt.updateSwitch(dpid, state, dmope);
 		ISwitchObject sw2 = ope.searchSwitch(dpid);
 		assertTrue(sw2 == null);
 	}
diff --git a/start-onos-embedded.sh b/start-onos-embedded.sh
index afe8f85..8688f69 100755
--- a/start-onos-embedded.sh
+++ b/start-onos-embedded.sh
@@ -4,7 +4,7 @@
 if [ -z "${ONOS_HOME}" ]; then
         ONOS_HOME=`dirname $0`
 fi
-ONOS_LOGBACK="${ONOS_HOME}/logback.xml"
+ONOS_LOGBACK="${ONOS_HOME}/logback.`hostname`.xml"
 LOGDIR=${ONOS_HOME}/onos-logs
 ONOS_LOG="${LOGDIR}/onos.`hostname`.log"
 PCAP_LOG="${LOGDIR}/onos.`hostname`.pcap"
@@ -96,6 +96,7 @@
 
   # XXX MVN has to run at the project top dir..
   cd ${ONOS_HOME}
+  echo "${MVN} exec:exec -Dexec.executable=\"java\" -Dexec.args=\"${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos-embedded.properties\""
   ${MVN} exec:exec -Dexec.executable="java" -Dexec.args="${JVM_OPTS} -Dlogback.configurationFile=${ONOS_LOGBACK} -cp %classpath ${MAIN_CLASS} -cf ${ONOS_HOME}/conf/onos-embedded.properties" > ${LOGDIR}/onos.stdout 2>${LOGDIR}/onos.stderr &
 
   echo "Waiting for ONOS to start..."
diff --git a/test-network/mininet/network.py b/test-network/mininet/network.py
new file mode 100755
index 0000000..0eb519a
--- /dev/null
+++ b/test-network/mininet/network.py
@@ -0,0 +1,175 @@
+#!/usr/bin/python
+
+"""
+Start up a Simple topology
+"""
+from mininet.net import Mininet
+from mininet.node import Controller, RemoteController
+from mininet.log import setLogLevel, info, error, warn, debug
+from mininet.cli import CLI
+from mininet.topo import Topo
+from mininet.util import quietRun
+from mininet.moduledeps import pathCheck
+from mininet.link import Link, TCLink
+
+from sys import exit
+import os.path
+from subprocess import Popen, STDOUT, PIPE
+
+import sys
+
+NR_NODES=10  #; Switches per rigonal networks
+
+class MyController( Controller ):
+    def __init__( self, name, ip='127.0.0.1', port=6633, **kwargs):
+        """Init.
+           name: name to give controller
+           ip: the IP address where the remote controller is
+           listening
+           port: the port where the remote controller is listening"""
+        Controller.__init__( self, name, ip=ip, port=port, **kwargs )
+
+    def start( self ):
+        "Overridden to do nothing."
+        return
+
+    def stop( self ):
+        "Overridden to do nothing."
+        return
+
+    def checkListening( self ):
+        "Warn if remote controller is not accessible"
+        listening = self.cmd( "echo A | telnet -e A %s %d" %
+                              ( self.ip, self.port ) )
+        if 'Unable' in listening:
+            warn( "Unable to contact the remote controller"
+                  " at %s:%d\n" % ( self.ip, self.port ) )
+
+class SDNTopo( Topo ):
+    "SDN Topology"
+
+    def __init__( self, *args, **kwargs ):
+        Topo.__init__( self, *args, **kwargs )
+        sw1 = self.addSwitch('sw1', dpid='0000000000000101')
+        sw2 = self.addSwitch('sw2', dpid='0000000000000102')
+        sw3 = self.addSwitch('sw3', dpid='0000000000000103')
+        sw4 = self.addSwitch('sw4', dpid='0000000000000104')
+        sw5 = self.addSwitch('sw5', dpid='0000000000000105')
+        sw6 = self.addSwitch('sw6', dpid='0000000000000106')
+
+        self.addLink( sw1, sw2 )
+        self.addLink( sw1, sw6 )
+        self.addLink( sw2, sw3 )
+        self.addLink( sw3, sw4 )
+        self.addLink( sw3, sw6 )
+        self.addLink( sw4, sw5 )
+        self.addLink( sw5, sw6 )
+        self.addLink( sw4, sw6 )
+
+        switches=[]
+        for n in range(2, 9):
+            NWID=n 
+            switch = []
+            host = []
+            for i in range (NR_NODES):
+                name_suffix = '%02d' % NWID + "." + '%02d' % (int(i)+1)
+                dpid_suffix = '%02x' % NWID + '%02x' % (int(i)+1)
+                dpid = '0000' + '0000' + '0000' + dpid_suffix
+                sw = self.addSwitch('sw'+name_suffix, dpid=dpid)
+                switch.append(sw)
+
+            for i in range (NR_NODES):
+                host.append(self.addHost( 'host%d.%d' % (n,int(i)+1) ))
+
+            for i in range (NR_NODES):
+                self.addLink(host[i], switch[i])
+
+            for i in range (1, NR_NODES):
+                self.addLink(switch[0], switch[i])
+
+            switches.append(switch)
+
+        self.addLink(switches[8-2][0],sw1)
+        self.addLink(switches[2-2][0],sw2)
+        self.addLink(switches[3-2][0],sw3)
+        self.addLink(switches[4-2][0],sw4)
+        self.addLink(switches[5-2][0],sw4)
+        self.addLink(switches[6-2][0],sw5)
+        self.addLink(switches[7-2][0],sw6)
+
+
+def startsshd( host ):
+    "Start sshd on host"
+    info( '*** Starting sshd\n' )
+    name, intf, ip = host.name, host.defaultIntf(), host.IP()
+    banner = '/tmp/%s.banner' % name
+    host.cmd( 'echo "Welcome to %s at %s" >  %s' % ( name, ip, banner ) )
+    host.cmd( '/usr/sbin/sshd -o "Banner %s"' % banner, '-o "UseDNS no"' )
+    info( '***', host.name, 'is running sshd on', intf, 'at', ip, '\n' )
+
+def startsshds ( hosts ):
+    for h in hosts:
+        startsshd( h )
+
+def stopsshd( ):
+    "Stop *all* sshd processes with a custom banner"
+    info( '*** Shutting down stale sshd/Banner processes ',
+          quietRun( "pkill -9 -f Banner" ), '\n' )
+
+def sdnnet(opt):
+#    os.system('/home/ubuntu/openflow/controller/controller ptcp: &')
+#    os.system('/home/ubuntu/openflow/controller/controller ptcp:7000 &')
+
+    topo = SDNTopo()
+    info( '*** Creating network\n' )
+#    net = Mininet( topo=topo, controller=RemoteController )
+    net = Mininet( topo=topo, controller=MyController, link=TCLink)
+#    dc = DebugController('c3', ip='127.0.0.1', port=7000)
+#    net.addController(dc)
+#    net.addController(controller=RemoteController)
+#    host1, host2, host3, host4, host5, host6 = net.get( 'host1', 'host2', 'host3', 'host4', 'host5', 'host6')
+
+    ## Adding 2nd, 3rd and 4th interface to host1 connected to sw1 (for another BGP peering)
+    sw1 = net.get('sw1')
+    sw2 = net.get('sw2')
+    sw3 = net.get('sw3')
+    sw4 = net.get('sw4')
+    sw5 = net.get('sw5')
+    sw6 = net.get('sw6')
+
+    hosts = []
+    for n in range(2, 9):
+        host = []
+        for i in range (NR_NODES):
+            host.append(net.get( 'host%d.%d' % (n, int(i)+1) ))
+        hosts.append(host)
+
+    net.start()
+
+    for n in range(2, 9):
+        for i in range (NR_NODES):
+            hosts[n-2][i].defaultIntf().setIP('192.168.%d.%d/16' % (n,(int(i)+1))) 
+            hosts[n-2][i].defaultIntf().setMAC('00:00:%02x:%02x:%02x:%02x' % (192,168,n,(int(i)+1))) 
+
+        for i in range (NR_NODES):
+            for k in range (2,9):
+                for h in range (NR_NODES):
+                    hosts[n-2][i].setARP('192.168.%d.%d' % (k, (int(h)+1)), '00:00:%02x:%02x:%02x:%02x' % (192,168,k,(int(h)+1))) 
+
+    stopsshd ()
+    for n in range(2, 9):
+        startsshds ( hosts[n-2] )
+
+    if opt=="cli":
+        CLI(net)
+        stopsshd()
+        net.stop()
+
+if __name__ == '__main__':
+    setLogLevel( 'info' )
+    if len(sys.argv) == 1:
+      sdnnet("cli")
+    elif len(sys.argv) == 2 and sys.argv[1] == "-n":
+      sdnnet("nocli")
+    else:
+      print "%s [-n]" % sys.argv[0]