mirror of
				https://github.com/opennetworkinglab/onos.git
				synced 2025-11-04 10:11:16 +01:00 
			
		
		
		
	Update SimpleLinkResourceStore to obtain capacities from link annotations
Change-Id: I98f8959fdc00953c98a151ad7b0bfa1041b118d7
This commit is contained in:
		
							parent
							
								
									452071656a
								
							
						
					
					
						commit
						8e5e91e296
					
				@ -29,6 +29,8 @@ import org.apache.felix.scr.annotations.Activate;
 | 
				
			|||||||
import org.apache.felix.scr.annotations.Component;
 | 
					import org.apache.felix.scr.annotations.Component;
 | 
				
			||||||
import org.apache.felix.scr.annotations.Deactivate;
 | 
					import org.apache.felix.scr.annotations.Deactivate;
 | 
				
			||||||
import org.apache.felix.scr.annotations.Service;
 | 
					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.Link;
 | 
				
			||||||
import org.onlab.onos.net.intent.IntentId;
 | 
					import org.onlab.onos.net.intent.IntentId;
 | 
				
			||||||
import org.onlab.onos.net.resource.Bandwidth;
 | 
					import org.onlab.onos.net.resource.Bandwidth;
 | 
				
			||||||
@ -74,12 +76,26 @@ public class SimpleLinkResourceStore implements LinkResourceStore {
 | 
				
			|||||||
     * @return free resources
 | 
					     * @return free resources
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private synchronized Set<ResourceAllocation> readOriginalFreeResources(Link link) {
 | 
					    private synchronized Set<ResourceAllocation> readOriginalFreeResources(Link link) {
 | 
				
			||||||
        // TODO read capacity and lambda resources from topology
 | 
					        Annotations annotations = link.annotations();
 | 
				
			||||||
        Set<ResourceAllocation> allocations = new HashSet<>();
 | 
					        Set<ResourceAllocation> allocations = new HashSet<>();
 | 
				
			||||||
        for (int i = 1; i <= 100; 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)));
 | 
					                allocations.add(new LambdaResourceAllocation(Lambda.valueOf(i)));
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        allocations.add(new BandwidthResourceAllocation(Bandwidth.valueOf(1000000)));
 | 
					        } catch (NumberFormatException e) {
 | 
				
			||||||
 | 
					            log.debug("No optical.wave annotation on link %s", link);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        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;
 | 
					        return allocations;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -92,7 +108,8 @@ public class SimpleLinkResourceStore implements LinkResourceStore {
 | 
				
			|||||||
     *         {@link BandwidthResourceAllocation} object with 0 bandwidth
 | 
					     *         {@link BandwidthResourceAllocation} object with 0 bandwidth
 | 
				
			||||||
     *
 | 
					     *
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private synchronized BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) {
 | 
					    private synchronized BandwidthResourceAllocation getBandwidth(
 | 
				
			||||||
 | 
					            Set<ResourceAllocation> freeRes) {
 | 
				
			||||||
        for (ResourceAllocation res : freeRes) {
 | 
					        for (ResourceAllocation res : freeRes) {
 | 
				
			||||||
            if (res.type() == ResourceType.BANDWIDTH) {
 | 
					            if (res.type() == ResourceType.BANDWIDTH) {
 | 
				
			||||||
                return (BandwidthResourceAllocation) res;
 | 
					                return (BandwidthResourceAllocation) res;
 | 
				
			||||||
@ -107,7 +124,8 @@ public class SimpleLinkResourceStore implements LinkResourceStore {
 | 
				
			|||||||
     * @param link the target link
 | 
					     * @param link the target link
 | 
				
			||||||
     * @param allocations the resources to be subtracted
 | 
					     * @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.
 | 
					        // TODO Use lock or version for updating freeResources.
 | 
				
			||||||
        checkNotNull(link);
 | 
					        checkNotNull(link);
 | 
				
			||||||
        Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link));
 | 
					        Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link));
 | 
				
			||||||
@ -141,7 +159,8 @@ public class SimpleLinkResourceStore implements LinkResourceStore {
 | 
				
			|||||||
     * @param link the target link
 | 
					     * @param link the target link
 | 
				
			||||||
     * @param allocations the resources to be added
 | 
					     * @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.
 | 
					        // TODO Use lock or version for updating freeResources.
 | 
				
			||||||
        Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link));
 | 
					        Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link));
 | 
				
			||||||
        Set<ResourceAllocation> addRes = allocations.getResourceAllocation(link);
 | 
					        Set<ResourceAllocation> addRes = allocations.getResourceAllocation(link);
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,10 @@ import java.util.Set;
 | 
				
			|||||||
import org.junit.After;
 | 
					import org.junit.After;
 | 
				
			||||||
import org.junit.Before;
 | 
					import org.junit.Before;
 | 
				
			||||||
import org.junit.Test;
 | 
					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.ConnectPoint;
 | 
				
			||||||
 | 
					import org.onlab.onos.net.DefaultAnnotations;
 | 
				
			||||||
import org.onlab.onos.net.DefaultLink;
 | 
					import org.onlab.onos.net.DefaultLink;
 | 
				
			||||||
import org.onlab.onos.net.Link;
 | 
					import org.onlab.onos.net.Link;
 | 
				
			||||||
import org.onlab.onos.net.provider.ProviderId;
 | 
					import org.onlab.onos.net.provider.ProviderId;
 | 
				
			||||||
@ -61,11 +64,15 @@ public class SimpleLinkResourceStoreTest {
 | 
				
			|||||||
     * @return created {@link Link} object
 | 
					     * @return created {@link Link} object
 | 
				
			||||||
     */
 | 
					     */
 | 
				
			||||||
    private Link newLink(String dev1, int port1, String dev2, int port2) {
 | 
					    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(
 | 
					        return new DefaultLink(
 | 
				
			||||||
                new ProviderId("of", "foo"),
 | 
					                new ProviderId("of", "foo"),
 | 
				
			||||||
                new ConnectPoint(deviceId(dev1), portNumber(port1)),
 | 
					                new ConnectPoint(deviceId(dev1), portNumber(port1)),
 | 
				
			||||||
                new ConnectPoint(deviceId(dev2), portNumber(port2)),
 | 
					                new ConnectPoint(deviceId(dev2), portNumber(port2)),
 | 
				
			||||||
                DIRECT);
 | 
					                DIRECT, annotations);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Before
 | 
					    @Before
 | 
				
			||||||
@ -158,6 +165,6 @@ public class SimpleLinkResourceStoreTest {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        final Set<LambdaResourceAllocation> res = getLambdaObjs(freeRes);
 | 
					        final Set<LambdaResourceAllocation> res = getLambdaObjs(freeRes);
 | 
				
			||||||
        assertNotNull(res);
 | 
					        assertNotNull(res);
 | 
				
			||||||
        assertEquals(100, res.size());
 | 
					        assertEquals(80, res.size());
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user