Search in sources :

Example 6 with ResourceConsumer

use of org.onosproject.net.resource.ResourceConsumer in project onos by opennetworkinglab.

the class ContinuousResourceAllocationTest method testReleaseWhenAllocatedResourceIsRequested.

@Test
public void testReleaseWhenAllocatedResourceIsRequested() {
    ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
    ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
    ResourceConsumer consumer = IntentId.valueOf(1);
    ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
    ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
    ContinuousResourceAllocation released = sut.release(request, consumer.consumerId());
    assertThat(released.allocations().isEmpty(), is(true));
}
Also used : Bandwidth(org.onlab.util.Bandwidth) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ContinuousResource(org.onosproject.net.resource.ContinuousResource) Test(org.junit.Test)

Example 7 with ResourceConsumer

use of org.onosproject.net.resource.ResourceConsumer in project onos by opennetworkinglab.

the class ContinuousResourceAllocationTest method testHasEnoughResourceWhenSmallResourceIsRequested.

@Test
public void testHasEnoughResourceWhenSmallResourceIsRequested() {
    ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
    ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
    ResourceConsumer consumer = IntentId.valueOf(1);
    ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
    ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(200).bps());
    assertThat(sut.hasEnoughResource(request), is(true));
}
Also used : Bandwidth(org.onlab.util.Bandwidth) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ContinuousResource(org.onosproject.net.resource.ContinuousResource) Test(org.junit.Test)

Example 8 with ResourceConsumer

use of org.onosproject.net.resource.ResourceConsumer in project onos by opennetworkinglab.

the class ContinuousResourceAllocationTest method testAllocateSameValue.

@Test
public void testAllocateSameValue() {
    ContinuousResource original = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.gbps(1).bps());
    ContinuousResource allocated = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(300).bps());
    ResourceConsumer consumer = IntentId.valueOf(1);
    ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
    ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(300).bps());
    ContinuousResourceAllocation newValue = sut.allocate(new ResourceAllocation(request, consumer));
    assertThat(newValue.allocations().size(), is(2));
    assertThat(newValue.allocations().stream().allMatch(x -> x.equals(new ResourceAllocation(allocated, consumer))), is(true));
}
Also used : Bandwidth(org.onlab.util.Bandwidth) Resources(org.onosproject.net.resource.Resources) PortNumber(org.onosproject.net.PortNumber) Test(org.junit.Test) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) Assert.assertThat(org.junit.Assert.assertThat) Matchers.hasItem(org.hamcrest.Matchers.hasItem) ImmutableList(com.google.common.collect.ImmutableList) Matchers.is(org.hamcrest.Matchers.is) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) DeviceId(org.onosproject.net.DeviceId) ContinuousResource(org.onosproject.net.resource.ContinuousResource) IntentId(org.onosproject.net.intent.IntentId) Bandwidth(org.onlab.util.Bandwidth) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ContinuousResource(org.onosproject.net.resource.ContinuousResource) Test(org.junit.Test)

Example 9 with ResourceConsumer

use of org.onosproject.net.resource.ResourceConsumer in project onos by opennetworkinglab.

the class TestAllocateResource method doExecute.

@Override
protected void doExecute() {
    resourceService = get(ResourceService.class);
    DeviceId did = DeviceId.deviceId(deviceIdStr);
    PortNumber portNum = PortNumber.fromString(portNumberStr);
    ResourceConsumer consumer = IntentId.valueOf(nIntendId);
    Resource resource = Resources.discrete(did, portNum, createLambda(Integer.parseInt(lambda))).resource();
    Optional<ResourceAllocation> allocate = resourceService.allocate(consumer, resource);
    if (allocate.isPresent()) {
        print("Allocated: %s", allocate.get());
    } else {
        print("Failed to allocate %s for %s", resource, consumer);
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) ResourceService(org.onosproject.net.resource.ResourceService) Resource(org.onosproject.net.resource.Resource) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) PortNumber(org.onosproject.net.PortNumber) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation)

Aggregations

ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)9 ResourceConsumer (org.onosproject.net.resource.ResourceConsumer)9 Bandwidth (org.onlab.util.Bandwidth)8 Test (org.junit.Test)7 ContinuousResource (org.onosproject.net.resource.ContinuousResource)7 DeviceId (org.onosproject.net.DeviceId)3 ImmutableList (com.google.common.collect.ImmutableList)2 PortNumber (org.onosproject.net.PortNumber)2 Resource (org.onosproject.net.resource.Resource)2 ResourceService (org.onosproject.net.resource.ResourceService)2 Resources (org.onosproject.net.resource.Resources)2 FluentIterable (com.google.common.collect.FluentIterable)1 Lists (com.google.common.collect.Lists)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Optional (java.util.Optional)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1