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));
}
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));
}
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));
}
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);
}
}
Aggregations