Praseed Balakrishnan

Fix for optical re-reoute

Change-Id: Iad3ca0e175cb76f66ac276981f4e36bb580566c8
......@@ -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 {
......
......@@ -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.<NetworkResource>copyOf(path.links()));
this.src = src;
......@@ -78,6 +78,7 @@ public class OpticalPathIntent extends Intent {
.toString();
}
public Collection<Link> requiredLinks() {
return path.links();
}
......
......@@ -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<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()));
}
}
......
......@@ -79,6 +79,9 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
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 @@ public class OpticalConnectivityIntentCompiler implements IntentCompiler<Optical
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
......
......@@ -256,8 +256,19 @@ public class LinkManager
}
// 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());
......
......@@ -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<DeviceId, Device> 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);
}
}
}
......