diff --git a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStore.java b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStore.java index 78cd341b10..52f60afb32 100644 --- a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStore.java +++ b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStore.java @@ -29,6 +29,8 @@ import org.apache.felix.scr.annotations.Activate; import org.apache.felix.scr.annotations.Component; import org.apache.felix.scr.annotations.Deactivate; import org.apache.felix.scr.annotations.Service; +import org.onlab.onos.net.AnnotationKeys; +import org.onlab.onos.net.Annotations; import org.onlab.onos.net.Link; import org.onlab.onos.net.intent.IntentId; import org.onlab.onos.net.resource.Bandwidth; @@ -74,12 +76,26 @@ public class SimpleLinkResourceStore implements LinkResourceStore { * @return free resources */ private synchronized Set readOriginalFreeResources(Link link) { - // TODO read capacity and lambda resources from topology + Annotations annotations = link.annotations(); Set allocations = new HashSet<>(); - for (int i = 1; i <= 100; i++) { - allocations.add(new LambdaResourceAllocation(Lambda.valueOf(i))); + + try { + int waves = Integer.parseInt(annotations.value(AnnotationKeys.OPTICAL_WAVES)); + for (int i = 1; i <= waves; i++) { + allocations.add(new LambdaResourceAllocation(Lambda.valueOf(i))); + } + } catch (NumberFormatException e) { + log.debug("No optical.wave annotation on link %s", link); } - allocations.add(new BandwidthResourceAllocation(Bandwidth.valueOf(1000000))); + + try { + int bandwidth = Integer.parseInt(annotations.value(AnnotationKeys.BANDWIDTH)); + allocations.add( + new BandwidthResourceAllocation(Bandwidth.valueOf(bandwidth))); + } catch (NumberFormatException e) { + log.debug("No bandwidth annotation on link %s", link); + } + return allocations; } @@ -92,7 +108,8 @@ public class SimpleLinkResourceStore implements LinkResourceStore { * {@link BandwidthResourceAllocation} object with 0 bandwidth * */ - private synchronized BandwidthResourceAllocation getBandwidth(Set freeRes) { + private synchronized BandwidthResourceAllocation getBandwidth( + Set freeRes) { for (ResourceAllocation res : freeRes) { if (res.type() == ResourceType.BANDWIDTH) { return (BandwidthResourceAllocation) res; @@ -107,7 +124,8 @@ public class SimpleLinkResourceStore implements LinkResourceStore { * @param link the target link * @param allocations the resources to be subtracted */ - private synchronized void subtractFreeResources(Link link, LinkResourceAllocations allocations) { + private synchronized void subtractFreeResources(Link link, + LinkResourceAllocations allocations) { // TODO Use lock or version for updating freeResources. checkNotNull(link); Set freeRes = new HashSet<>(getFreeResources(link)); @@ -141,7 +159,8 @@ public class SimpleLinkResourceStore implements LinkResourceStore { * @param link the target link * @param allocations the resources to be added */ - private synchronized void addFreeResources(Link link, LinkResourceAllocations allocations) { + private synchronized void addFreeResources(Link link, + LinkResourceAllocations allocations) { // TODO Use lock or version for updating freeResources. Set freeRes = new HashSet<>(getFreeResources(link)); Set addRes = allocations.getResourceAllocation(link); diff --git a/core/store/trivial/src/test/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStoreTest.java b/core/store/trivial/src/test/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStoreTest.java index 1daad2f4e2..f28bb63b17 100644 --- a/core/store/trivial/src/test/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStoreTest.java +++ b/core/store/trivial/src/test/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStoreTest.java @@ -28,7 +28,10 @@ import java.util.Set; import org.junit.After; import org.junit.Before; import org.junit.Test; +import org.onlab.onos.net.AnnotationKeys; +import org.onlab.onos.net.Annotations; import org.onlab.onos.net.ConnectPoint; +import org.onlab.onos.net.DefaultAnnotations; import org.onlab.onos.net.DefaultLink; import org.onlab.onos.net.Link; import org.onlab.onos.net.provider.ProviderId; @@ -61,11 +64,15 @@ public class SimpleLinkResourceStoreTest { * @return created {@link Link} object */ private Link newLink(String dev1, int port1, String dev2, int port2) { + Annotations annotations = DefaultAnnotations.builder() + .set(AnnotationKeys.OPTICAL_WAVES, "80") + .set(AnnotationKeys.BANDWIDTH, "1000000") + .build(); return new DefaultLink( new ProviderId("of", "foo"), new ConnectPoint(deviceId(dev1), portNumber(port1)), new ConnectPoint(deviceId(dev2), portNumber(port2)), - DIRECT); + DIRECT, annotations); } @Before @@ -158,6 +165,6 @@ public class SimpleLinkResourceStoreTest { final Set res = getLambdaObjs(freeRes); assertNotNull(res); - assertEquals(100, res.size()); + assertEquals(80, res.size()); } }