Refactored LinkStorage and SwitchStorage preparing for event notification implementation.
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..ce2379b 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,33 @@
 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 update(Link link, LinkInfo linkinfo, DM_OPERATION op);
+	
+	/*
+     * Link creation
+     */
+	public void addLink(Link link);
+	public void addLinks(List<Link> links);
+	
+	/*
+	 * Link deletion
 	 */
 	public void deleteLink(Link link);
+	public void 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);
 
 	/*
 	 * Get Links from Storage
@@ -44,10 +44,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..bc50049 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/core/ISwitchStorage.java
@@ -12,6 +12,10 @@
 	}
 	
 	/*
+	 * Initialize
+	 */
+	public void init(String conf);
+	/*
 	 * Update the switch details
 	 */
 	public void update(String dpid,SwitchState state, DM_OPERATION op);
@@ -20,6 +24,10 @@
 	 */
 	public void addPort(String dpid, OFPhysicalPort port);
 	/*
+	 * Delete a port on a switch by num
+	 */
+	public void deletePort(String dpid, short port);
+	/*
 	 * Add a switch and all its associated ports
 	 */
 	public void addSwitch(IOFSwitch sw);
@@ -31,14 +39,6 @@
 	 * 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);
 	
 
 }
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 8ee346b..753563e 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
@@ -20,32 +20,117 @@
 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 static Logger log = LoggerFactory.getLogger(LinkStorageImpl.class);
 	protected GraphDBOperation dbop;
 
+	
+	/**
+	 * 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) {
+		this.dbop = new GraphDBOperation(conf);
+	}
+
 	/**
 	 * 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.
 	 */
 	@Override
-	public void update(Link link, DM_OPERATION op) {
-		update(link, (LinkInfo)null, op);
+	public void update(Link link, LinkInfo linkinfo, DM_OPERATION op) {
+		switch (op) {
+		case CREATE:
+		case INSERT:
+			addLinkImpl(link,op);
+			break;
+		case UPDATE:
+			if (linkinfo != null) {
+				setLinkInfo(link, linkinfo);
+			} else {
+				deleteLinkInfo(link);
+			}
+			break;
+		case DELETE:
+			deleteLink(link);
+			break;
+		}
 	}
 
+	@Override
+	public void addLink(Link link) {
+		addLinkImpl(link, DM_OPERATION.INSERT);
+	}
+	
 	/**
 	 * 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) {
+	public void addLinks(List<Link> links) {
 		for (Link lt: links) {
-			update(lt, (LinkInfo)null, op);
+			addLinkImpl(lt, DM_OPERATION.INSERT);
+		}
+	}
+
+	/**
+		 * Delete a record in the LinkStorage.
+		 * @param lt Record to be deleted.
+		 */
+		@Override
+		public void deleteLink(Link lt) {
+			IPortObject vportSrc = null, vportDst = null;
+			
+			log.debug("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) {
+	         		vportSrc.removeLink(vportDst);
+	        		dbop.commit();
+	            	log.debug("deleteLink(): deleted edges src {} dst {}", new Object[]{
+	            			lt, vportSrc, vportDst});
+	            	
+	        		// TODO publish DELETE_LINK event here
+	            } else {
+	            	log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst});
+	            	dbop.rollback();
+	            }
+	         	
+	        } catch (TitanException e) {
+	            /*
+	             * retry till we succeed?
+	             */
+	        	log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()});
+	        	dbop.rollback();
+	        	e.printStackTrace();
+	        }
+		}
+
+	/**
+	 * 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);
 		}
 	}
 
@@ -55,30 +140,28 @@
 	 * @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;
-		}
+	private void setLinkInfo(Link link, LinkInfo linkinfo) {
+		// TODO implement this
+		
+		// TODO publish UPDATE_LINK event here
 	}
 	
+	private void deleteLinkInfo(Link link) {
+		// TODO implement this
+		
+		// TODO publish UPDATE_LINK event here
+	}
+
 	/**
 	 * 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) {
+	private void addLinkImpl(Link lt, DM_OPERATION op) {
 		IPortObject vportSrc = null, vportDst = null;
 	
-		log.trace("updateLink(): op {} {} {}", new Object[]{op, lt, linkinfo});
+		log.trace("updateLink(): op {} {}", new Object[]{op, lt});
 		
         try {
             // get source port vertex
@@ -101,7 +184,6 @@
             	}
 
             	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});
@@ -111,6 +193,8 @@
 
             		dbop.commit();
             		log.debug("updateLink(): link added {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
+            		
+            		// TODO publish ADD_LINK event here
             	}
             } else {
             	log.error("updateLink(): failed invalid vertices {} {} src {} dst {}", new Object[]{op, lt, vportSrc, vportDst});
@@ -126,78 +210,11 @@
 	}
 	
 	/**
-	 * 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);
-		}
-	}
-	
-	/**
-	 * Delete a record in the LinkStorage.
-	 * @param lt Record to be deleted.
-	 */
-	@Override
-	public void deleteLink(Link lt) {
-		IPortObject vportSrc = null, vportDst = null;
-		
-		log.debug("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});
-            	
-            } else {
-            	log.error("deleteLink(): failed invalid vertices {} src {} dst {}", new Object[]{lt, vportSrc, vportDst});
-            	dbop.rollback();
-            }
-         	
-        } catch (TitanException e) {
-            /*
-             * retry till we succeed?
-             */
-        	log.error("deleteLink(): titan exception {} {}", new Object[]{lt, e.toString()});
-        	dbop.rollback();
-        	e.printStackTrace();
-        }
-	}
-
-	/**
 	 * Get list of all 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.
 	 * @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>();
@@ -221,24 +238,13 @@
 	}
 	
 	/**
-	 * 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);
+		List<Link> linksToDelete = getLinks(dpid, port);
 		
 		for(Link l : linksToDelete) {
 			deleteLink(l);
@@ -250,7 +256,6 @@
 	 * @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>();
@@ -302,12 +307,34 @@
 		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();		
+	}
+
+	// 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 +355,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 b7c97f8..d9f24e0 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
@@ -1,5 +1,8 @@
 package net.onrc.onos.ofcontroller.core.internal;
 
+import java.util.ArrayList;
+import java.util.List;
+
 import net.floodlightcontroller.core.IOFSwitch;
 import net.onrc.onos.graph.GraphDBConnection;
 import net.onrc.onos.graph.GraphDBOperation;
@@ -55,6 +58,7 @@
 				sw.setState(state.toString());
 				op.commit();
 				log.info("SwitchStorage:setStatus dpid:{} state: {} done", dpid, state);
+			    // TODO publish UPDATE_SWITCH event here
 			}
 		} catch(Exception e) {
 			e.printStackTrace();
@@ -64,43 +68,6 @@
 	}
 
 	/***
-	 * 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;
-	}
-	
-	/***
 	 * This function is for updating the switch into the DB.
 	 * @param dpid The switch dpid you want to update from the DB
 	 * @param state The state of the switch like ACTIVE, INACTIVE
@@ -109,20 +76,193 @@
 	@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:
-        }
+	    switch(dmope) {
+	    	case UPDATE:
+	    	case INSERT:
+	    	case CREATE:
+	            addSwitch(dpid);
+	            if (state != SwitchState.ACTIVE) {
+	            	setStatus(dpid, state);
+	            }
+	            break;
+	    	case DELETE:
+	            deleteSwitch(dpid);
+	            break;
+	    	default:
+	    }
+	}
+
+	/***
+	 * 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.
+	 */
+	@Override
+	public void addPort(String dpid, OFPhysicalPort port) {
+		
+	   if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & port.getConfig()) > 0) ||
+	    					((OFPortState.OFPPS_LINK_DOWN.getValue() & port.getState()) > 0)) {
+		     deletePort(dpid, port.getPortNumber());
+	         return;  
+	   }
+	
+		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();
+	        		
+	    		    // TODO publish UPDATE_PORT event here
+	        	} else {
+	        		p = op.newPort(dpid, port.getPortNumber());
+	        		p.setState("ACTIVE");
+	        		p.setPortState(port.getState());
+	        		p.setDesc(port.getName());
+	        		sw.addPort(p);
+	        		op.commit();
+	        		
+	    		    // TODO publish ADD_PORT event here
+	        	}
+	        } else {
+	    		log.error("SwitchStorage:addPort dpid:{} port:{} : failed switch does not exist", dpid, port.getPortNumber());
+	        }
+		} catch (Exception e) {
+			e.printStackTrace();
+			op.rollback();
+			log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, port.getPortNumber());
+		}	
+	
+	}
+
+	/***
+	 * 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) {
+		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();
+	    		    // TODO publish DELETE_PORT event here
+	        	}
+	        }
+		} catch (Exception e) {
+			e.printStackTrace();
+			op.rollback();
+			log.info("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port);
+		}	
+	}
+
+	@Override
+	public void addSwitch(IOFSwitch sw) {
+		String dpid = sw.getStringId();
+		log.info("SwitchStorage:addSwitch(): dpid {} ", dpid);
+		
+		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);
+		}
+
+		try {
+			List<IPortObject> added_ports = new ArrayList<IPortObject>();
+			List<IPortObject> updated_ports = new ArrayList<IPortObject>();
+			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());
+		    		
+		       		added_ports.add(p);
+				} else {
+		    		p = op.newPort(dpid, port.getPortNumber());
+		    		p.setState("ACTIVE");
+		    		p.setPortState(port.getState());
+		    		p.setDesc(port.getName());           		
+		    		curr.addPort(p);
+		    		
+		       		updated_ports.add(p);
+				}         		
+			}
+	
+			op.commit();
+		    
+		    // TODO publish ADD_PORT event here
+		    // TODO publish UPDATE_PORT event here
+		} catch (Exception e) {
+			e.printStackTrace();
+			op.rollback();
+			log.info("SwitchStorage:addSwitch dpid:{} failed", dpid);
+		}		
+	}
+
+	/***
+	 * 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);
+		
+		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);
+		}
+	}
+	
+	private ISwitchObject addSwitchImpl(String dpid) {
+		try {
+			ISwitchObject sw = op.newSwitch(dpid);
+			if (sw != null) {
+				sw.setState(SwitchState.ACTIVE.toString());
+				log.info("SwitchStorage:addSwitchImpl dpid:{} added", dpid);
+			} else {
+				log.error("switchStorage:addSwitchImpl dpid:{} failed", dpid);
+				throw new RuntimeException();
+			}
+
+            op.commit();
+            
+            // TODO publish ADD_SWITCH event here
+    		return sw;
+		} catch (Exception e) {
+			e.printStackTrace();
+			op.rollback();
+			log.info("SwitchStorage:addSwitchImpl dpid:{} failed", dpid);
+			return null;
+		}
+	}
+	
+	private void setSwitchStateImpl(ISwitchObject sw, SwitchState state) {
+		if (sw != null && state != null) {
+			sw.setState(state.toString());
+            op.commit();
+            
+			// TODO publish UPDATE_SWITCH event here
+		}
 	}
 
 	/***
@@ -137,6 +277,8 @@
             	op.removeSwitch(sw);
             	op.commit();
             	log.info("SwitchStorage:DeleteSwitch dpid:{} done", dpid);
+
+            	// TODO publish DELETE_SWITCH event here
             }
 		} catch (Exception e) {
 			e.printStackTrace();
@@ -145,105 +287,5 @@
 		}
 
 	}
-
-	/***
-	 * 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.
-	 */
-	@Override
-	public void addPort(String dpid, OFPhysicalPort port) {
-		
-       if(((OFPortConfig.OFPPC_PORT_DOWN.getValue() & port.getConfig()) > 0) ||
-        					((OFPortState.OFPPS_LINK_DOWN.getValue() & port.getState()) > 0)) {
-    	     deletePort(dpid, port.getPortNumber());
-             return;  
-       }
-
-		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());
-            }
-		} catch (Exception e) {
-			e.printStackTrace();
-			op.rollback();
-			log.error("SwitchStorage:addPort dpid:{} port:{} failed", dpid, port.getPortNumber());
-		}	
-
-	}
 	
-	/***
-	 * 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) {
-		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();
-            	}
-            }
-		} catch (Exception e) {
-			e.printStackTrace();
-			op.rollback();
-			log.info("SwitchStorage:deletePort dpid:{} port:{} failed", dpid, port);
-		}	
-	}
-
-	@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);
-		}		
-		
-	}
 }
\ No newline at end of file