Search in sources :

Example 11 with ResourceAllocation

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

the class ContinuousResourceAllocationTest method testReleaseWhenDifferentConsumerIsSpecified.

@Test
public void testReleaseWhenDifferentConsumerIsSpecified() {
    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);
    ResourceConsumer otherConsumer = IntentId.valueOf(2);
    ContinuousResourceAllocation sut = new ContinuousResourceAllocation(original, ImmutableList.of(new ResourceAllocation(allocated, consumer)));
    ContinuousResource request = Resources.continuous(DID, PN1, Bandwidth.class).resource(Bandwidth.mbps(500).bps());
    ImmutableList<ResourceAllocation> allocations = sut.release(request, otherConsumer.consumerId()).allocations();
    assertThat(allocations.size(), is(1));
    assertThat(allocations.get(0).resource().equals(allocated), 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 12 with ResourceAllocation

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

the class ContinuousResourceAllocationTest method testAllocateDifferentValue.

@Test
public void testAllocateDifferentValue() {
    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());
    ContinuousResourceAllocation newValue = sut.allocate(new ResourceAllocation(request, consumer));
    assertThat(newValue.allocations().size(), is(2));
    assertThat(newValue.allocations(), hasItem(new ResourceAllocation(allocated, consumer)));
    assertThat(newValue.allocations(), hasItem(new ResourceAllocation(request, consumer)));
}
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 13 with ResourceAllocation

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

the class ContinuousResourceAllocationTest method testHasEnoughResourceWhenLargeResourceIsRequested.

@Test
public void testHasEnoughResourceWhenLargeResourceIsRequested() {
    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(600).bps());
    assertThat(sut.hasEnoughResource(request), is(false));
}
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 14 with ResourceAllocation

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

the class ContinuousResourceAllocationTest method testHasEnoughResourceWhenExactResourceIsRequested.

@Test
public void testHasEnoughResourceWhenExactResourceIsRequested() {
    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());
    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 15 with ResourceAllocation

use of org.onosproject.net.resource.ResourceAllocation 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)

Aggregations

ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)20 Test (org.junit.Test)14 Bandwidth (org.onlab.util.Bandwidth)13 ContinuousResource (org.onosproject.net.resource.ContinuousResource)13 ResourceService (org.onosproject.net.resource.ResourceService)11 ResourceConsumer (org.onosproject.net.resource.ResourceConsumer)9 ConnectPoint (org.onosproject.net.ConnectPoint)8 Constraint (org.onosproject.net.intent.Constraint)7 Key (org.onosproject.net.intent.Key)7 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)7 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)6 MockResourceService (org.onosproject.net.resource.MockResourceService)6 DeviceId (org.onosproject.net.DeviceId)5 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)5 Resource (org.onosproject.net.resource.Resource)4 Resources (org.onosproject.net.resource.Resources)4 ImmutableList (com.google.common.collect.ImmutableList)3 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3