use of org.onosproject.net.resource.ResourceAllocation 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.ResourceAllocation 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.ResourceAllocation in project onos by opennetworkinglab.
the class PointToPointIntentCompilerTest method testKeyRGBandwidthConstrainedIntentAllocation.
/**
* Tests if bandwidth resources get allocated correctly using groups.
* An intent asks to allocate bandwidth using the intent key as a reference.
* Then, the intent is submitted with the same key and a group set.
* Previous allocations should be released and new resources should be
* allocated using the group.
*/
@Test
public void testKeyRGBandwidthConstrainedIntentAllocation() {
final double bpsTotal = 1000.0;
String[] hops = { S1, S2, S3 };
final ResourceService resourceService = MockResourceService.makeCustomBandwidthResourceService(bpsTotal);
final List<Constraint> constraints = Collections.singletonList(new BandwidthConstraint(Bandwidth.bps(BPS_TO_RESERVE)));
final PointToPointIntent intent = makeIntent(new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints);
PointToPointIntentCompiler compiler = makeCompiler(hops, resourceService);
compiler.compile(intent, null);
Key intentKey = intent.key();
ResourceGroup resourceGroup = ResourceGroup.of(100);
final PointToPointIntent newIntent = makeIntent(intentKey, new ConnectPoint(DID_1, PORT_1), new ConnectPoint(DID_3, PORT_2), constraints, resourceGroup);
compiler.compile(newIntent, null);
ResourceAllocation rAOne = new ResourceAllocation(RESOURCE_SW1_P1, resourceGroup);
ResourceAllocation rATwo = new ResourceAllocation(RESOURCE_SW1_P2, resourceGroup);
ResourceAllocation rAThree = new ResourceAllocation(RESOURCE_SW2_P1, resourceGroup);
ResourceAllocation rAFour = new ResourceAllocation(RESOURCE_SW2_P2, resourceGroup);
ResourceAllocation rAFive = new ResourceAllocation(RESOURCE_SW3_P1, resourceGroup);
ResourceAllocation rASix = new ResourceAllocation(RESOURCE_SW3_P2, resourceGroup);
Set<ResourceAllocation> expectedresourceAllocations = ImmutableSet.of(rAOne, rATwo, rAThree, rAFour, rAFive, rASix);
Set<ResourceAllocation> resourceAllocations = ImmutableSet.copyOf(resourceService.getResourceAllocations(resourceGroup));
assertThat(resourceAllocations, hasSize(6));
assertEquals(expectedresourceAllocations, resourceAllocations);
}
use of org.onosproject.net.resource.ResourceAllocation 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);
}
}
use of org.onosproject.net.resource.ResourceAllocation in project onos by opennetworkinglab.
the class OpticalPathProvisioner method updateBandwidthUsage.
/**
* Updates usage information of bandwidth based on connectivity which is established.
* @param connectivity Optical connectivity
*/
private void updateBandwidthUsage(OpticalConnectivity connectivity) {
if (NO_BW_REQUIREMENT.equals(connectivity.bandwidth())) {
// no bandwidth requirement, nothing to allocate.
return;
}
OpticalConnectivityId connectivityId = connectivity.id();
List<Link> links = connectivity.links();
List<Resource> resources = links.stream().flatMap(l -> Stream.of(l.src(), l.dst())).filter(cp -> !isTransportLayer(deviceService.getDevice(cp.deviceId()).type())).map(cp -> Resources.continuous(cp.deviceId(), cp.port(), Bandwidth.class).resource(connectivity.bandwidth().bps())).collect(Collectors.toList());
log.debug("allocating bandwidth for {} : {}", connectivityId, resources);
List<ResourceAllocation> allocations = resourceService.allocate(connectivityId, resources);
if (allocations.isEmpty()) {
log.warn("Failed to allocate bandwidth {} to {}", connectivity.bandwidth().bps(), resources);
// TODO any recovery?
}
log.debug("Done allocating bandwidth for {}", connectivityId);
}
Aggregations