From 00dd1f9a6cae9e90f01d433e19f8f91115e79d2a Mon Sep 17 00:00:00 2001 From: Praseed Balakrishnan Date: Wed, 19 Nov 2014 17:12:36 -0800 Subject: [PATCH] Fix for optical re-reoute Change-Id: Iad3ca0e175cb76f66ac276981f4e36bb580566c8 --- .../onos/optical/OpticalPathProvisioner.java | 3 +++ .../onos/net/intent/OpticalPathIntent.java | 3 ++- .../net/intent/impl/ObjectiveTracker.java | 10 ++++++-- .../OpticalConnectivityIntentCompiler.java | 6 ++++- .../onlab/onos/net/link/impl/LinkManager.java | 13 ++++++++++- .../onos/net/link/impl/LinkManagerTest.java | 23 ++++++++++++++++++- 6 files changed, 52 insertions(+), 6 deletions(-) diff --git a/apps/optical/src/main/java/org/onlab/onos/optical/OpticalPathProvisioner.java b/apps/optical/src/main/java/org/onlab/onos/optical/OpticalPathProvisioner.java index 1ad55aeb98..5aaa359dcd 100644 --- a/apps/optical/src/main/java/org/onlab/onos/optical/OpticalPathProvisioner.java +++ b/apps/optical/src/main/java/org/onlab/onos/optical/OpticalPathProvisioner.java @@ -206,6 +206,9 @@ public class OpticalPathProvisioner { private static class OpticalLinkWeight implements LinkWeight { @Override public double weight(TopologyEdge edge) { + if (edge.link().state() == Link.State.INACTIVE) { + return -1; // ignore inactive links + } if (isOpticalLink(edge.link())) { return 1000.0; // optical links } else { diff --git a/core/api/src/main/java/org/onlab/onos/net/intent/OpticalPathIntent.java b/core/api/src/main/java/org/onlab/onos/net/intent/OpticalPathIntent.java index 92017f1e0e..71a91870dc 100644 --- a/core/api/src/main/java/org/onlab/onos/net/intent/OpticalPathIntent.java +++ b/core/api/src/main/java/org/onlab/onos/net/intent/OpticalPathIntent.java @@ -37,7 +37,7 @@ public class OpticalPathIntent extends Intent { ConnectPoint src, ConnectPoint dst, Path path) { - super(id(OpticalPathIntent.class, src, dst), + super(id(OpticalPathIntent.class, src, dst, path), appId, ImmutableSet.copyOf(path.links())); this.src = src; @@ -78,6 +78,7 @@ public class OpticalPathIntent extends Intent { .toString(); } + public Collection requiredLinks() { return path.links(); } 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 53b1239fee..c984632669 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 com.google.common.collect.Multimaps.synchronizedSetMultimap; 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 @@ public class ObjectiveTracker implements ObjectiveTrackerService { 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 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 e5a12036c1..85c9f295c1 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 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler 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 15fc4a176a..76ce64a16b 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 @@ public class LinkManager } // Removes all links in the specified set and emits appropriate events. - private void removeLinks(Set links, boolean isSoftRemove) { + private void removeLinks(Set 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()); diff --git a/core/net/src/test/java/org/onlab/onos/net/link/impl/LinkManagerTest.java b/core/net/src/test/java/org/onlab/onos/net/link/impl/LinkManagerTest.java index 2cab8fe4ee..665a550370 100644 --- a/core/net/src/test/java/org/onlab/onos/net/link/impl/LinkManagerTest.java +++ b/core/net/src/test/java/org/onlab/onos/net/link/impl/LinkManagerTest.java @@ -21,6 +21,7 @@ import org.junit.Before; import org.junit.Test; import org.onlab.onos.event.Event; import org.onlab.onos.net.ConnectPoint; +import org.onlab.onos.net.DefaultDevice; import org.onlab.onos.net.Device; import org.onlab.onos.net.DeviceId; import org.onlab.onos.net.Link; @@ -41,8 +42,10 @@ import org.onlab.onos.net.device.impl.DeviceManager; import org.onlab.onos.store.trivial.impl.SimpleLinkStore; import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.Set; import static org.junit.Assert.*; @@ -60,11 +63,17 @@ public class LinkManagerTest { private static final DeviceId DID1 = deviceId("of:foo"); private static final DeviceId DID2 = deviceId("of:bar"); private static final DeviceId DID3 = deviceId("of:goo"); + private static final Device DEV1 = new DefaultDevice( + PID, DID1, Device.Type.SWITCH, "", "", "", "", null); + private static final Device DEV2 = new DefaultDevice( + PID, DID2, Device.Type.SWITCH, "", "", "", "", null); + private static final Device DEV3 = new DefaultDevice( + PID, DID2, Device.Type.SWITCH, "", "", "", "", null); private static final PortNumber P1 = PortNumber.portNumber(1); private static final PortNumber P2 = PortNumber.portNumber(2); private static final PortNumber P3 = PortNumber.portNumber(3); - + private static final Map DEVICEIDMAP = new HashMap<>(); private LinkManager mgr; @@ -76,6 +85,7 @@ public class LinkManagerTest { protected TestListener listener = new TestListener(); protected DeviceManager devmgr = new TestDeviceManager(); + @Before public void setUp() { mgr = new LinkManager(); @@ -87,6 +97,10 @@ public class LinkManagerTest { mgr.deviceService = devmgr; mgr.activate(); + DEVICEIDMAP.put(DID1, DEV1); + DEVICEIDMAP.put(DID2, DEV2); + DEVICEIDMAP.put(DID3, DEV3); + service.addListener(listener); provider = new TestProvider(); @@ -276,10 +290,17 @@ public class LinkManagerTest { } private static class TestDeviceManager extends DeviceManager { + @Override public MastershipRole getRole(DeviceId deviceId) { return MastershipRole.MASTER; } + + @Override + public Device getDevice(DeviceId deviceId) { + return DEVICEIDMAP.get(deviceId); + } + } }