Fix for optical re-reoute

Change-Id: Iad3ca0e175cb76f66ac276981f4e36bb580566c8
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTracker.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTracker.java
index 53b1239..c984632 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTracker.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/ObjectiveTracker.java
@@ -45,6 +45,7 @@
 import static java.util.concurrent.Executors.newSingleThreadExecutor;
 import static org.onlab.onos.net.LinkKey.linkKey;
 import static org.onlab.onos.net.link.LinkEvent.Type.LINK_REMOVED;
+import static org.onlab.onos.net.link.LinkEvent.Type.LINK_UPDATED;
 import static org.onlab.util.Tools.namedThreads;
 import static org.slf4j.LoggerFactory.getLogger;
 
@@ -152,13 +153,18 @@
                 for (Event reason : event.reasons()) {
                     if (reason instanceof LinkEvent) {
                         LinkEvent linkEvent = (LinkEvent) reason;
-                        if (linkEvent.type() == LINK_REMOVED) {
+                        if (linkEvent.type() == LINK_REMOVED
+                                || (linkEvent.type() == LINK_UPDATED &&
+                                        linkEvent.subject().isDurable())) {
                             final LinkKey linkKey = linkKey(linkEvent.subject());
                             Set<IntentId> intentIds = intentsByLink.get(linkKey);
                             log.debug("recompile triggered by LinkDown {} {}", linkKey, intentIds);
                             toBeRecompiled.addAll(intentIds);
                         }
-                        recompileOnly = recompileOnly && linkEvent.type() == LINK_REMOVED;
+                        recompileOnly = recompileOnly &&
+                                (linkEvent.type() == LINK_REMOVED ||
+                                (linkEvent.type() == LINK_UPDATED &&
+                                linkEvent.subject().isDurable()));
                     }
                 }
 
diff --git a/core/net/src/main/java/org/onlab/onos/net/intent/impl/OpticalConnectivityIntentCompiler.java b/core/net/src/main/java/org/onlab/onos/net/intent/impl/OpticalConnectivityIntentCompiler.java
index e5a1203..85c9f29 100644
--- a/core/net/src/main/java/org/onlab/onos/net/intent/impl/OpticalConnectivityIntentCompiler.java
+++ b/core/net/src/main/java/org/onlab/onos/net/intent/impl/OpticalConnectivityIntentCompiler.java
@@ -79,6 +79,9 @@
         LinkWeight weight = new LinkWeight() {
             @Override
             public double weight(TopologyEdge edge) {
+                if (edge.link().state() == Link.State.INACTIVE) {
+                    return -1;
+                }
                 return edge.link().type() == Link.Type.OPTICAL ? +1 : -1;
             }
         };
@@ -86,7 +89,8 @@
         Set<Path> paths = topologyService.getPaths(topology, start.deviceId(),
                                                    end.deviceId(), weight);
         if (paths.isEmpty()) {
-            throw new PathNotFoundException("No fiber path from " + start + " to " + end);
+            throw new PathNotFoundException("No Optical path found from " +
+                                                    start + " to " + end);
         }
 
         // TODO: let's be more intelligent about this eventually
diff --git a/core/net/src/main/java/org/onlab/onos/net/link/impl/LinkManager.java b/core/net/src/main/java/org/onlab/onos/net/link/impl/LinkManager.java
index 15fc4a1..76ce64a 100644
--- a/core/net/src/main/java/org/onlab/onos/net/link/impl/LinkManager.java
+++ b/core/net/src/main/java/org/onlab/onos/net/link/impl/LinkManager.java
@@ -256,8 +256,19 @@
     }
 
     // Removes all links in the specified set and emits appropriate events.
-    private void removeLinks(Set<Link> links, boolean isSoftRemove) {
+    private void  removeLinks(Set<Link> links, boolean isSoftRemove) {
         for (Link link : links) {
+            if (!deviceService.getDevice(link.src().deviceId()).type().equals(
+                    deviceService.getDevice(link.dst().deviceId()).type())) {
+                //TODO this is aweful. need to be fixed so that we don't down
+                // configured links. perhaps add a mechanism to figure out the
+                // state of this link
+                log.info("Ignoring removal of link as device types are " +
+                                 "different {} {} ",
+                         link.src() ,
+                         link.dst());
+                continue;
+            }
             LinkEvent event = isSoftRemove ?
                     store.removeOrDownLink(link.src(), link.dst()) :
                     store.removeLink(link.src(), link.dst());