Check Link precondition before loading from DB

Change-Id: Ia38002df18e6d4246d4f1d54b6556ade23051b95
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
index 5d3e60a..c65136b 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
@@ -1185,7 +1185,19 @@
 	    //	}
 
 	    for (RCLink l : RCLink.getAllLinks()) {
-		// TODO check if src/dst switch/port exist before triggering event
+		// check if src/dst switch/port exist before triggering event
+		// Src/Dst Switch must exist
+		Switch srcSw = getSwitch(l.getSrc().dpid);
+		Switch dstSw = getSwitch(l.getDst().dpid);
+		if ( srcSw == null || dstSw == null ) {
+		    continue;
+		}
+		// Src/Dst Port must exist
+		Port srcPort = srcSw.getPort(l.getSrc().number);
+		Port dstPort = dstSw.getPort(l.getDst().number);
+		if ( srcPort == null || dstPort == null ) {
+		    continue;
+		}
 		putLinkReplicationEvent( new LinkEvent(l.getSrc().dpid, l.getSrc().number, l.getDst().dpid, l.getDst().number));
 	    }
 	}