use of org.onosproject.net.resource.Resources 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);
}
use of org.onosproject.net.resource.Resources in project onos by opennetworkinglab.
the class OpticalConnectivityIntentCompiler method compile.
@Override
public List<Intent> compile(OpticalConnectivityIntent intent, List<Intent> installable) {
// Check if source and destination are optical OCh ports
ConnectPoint src = intent.getSrc();
ConnectPoint dst = intent.getDst();
checkArgument(deviceService.getPort(src.deviceId(), src.port()) instanceof OchPort);
checkArgument(deviceService.getPort(dst.deviceId(), dst.port()) instanceof OchPort);
List<Resource> resources = new LinkedList<>();
log.debug("Compiling optical connectivity intent between {} and {}", src, dst);
// Release of intent resources here is only a temporary solution for handling the
// case of recompiling due to intent restoration (when intent state is FAILED).
// TODO: try to release intent resources in IntentManager.
resourceService.release(intent.key());
// Check OCh port availability
// If ports are not available, compilation fails
// Else add port to resource reservation list
Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
log.error("Ports for the intent are not available. Intent: {}", intent);
throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
}
resources.add(srcPortResource);
resources.add(dstPortResource);
// If there is a suggestedPath, use this path without further checking, otherwise trigger path computation
Stream<Path> paths;
if (intent.suggestedPath().isPresent()) {
paths = Stream.of(intent.suggestedPath().get());
} else {
paths = getOpticalPaths(intent);
}
// Find first path that has the required resources
Optional<Map.Entry<Path, List<OchSignal>>> found = paths.map(path -> Maps.immutableEntry(path, findFirstAvailableLambda(intent, path))).filter(entry -> !entry.getValue().isEmpty()).filter(entry -> convertToResources(entry.getKey(), entry.getValue()).stream().allMatch(resourceService::isAvailable)).findFirst();
// Allocate resources and create optical path intent
if (found.isPresent()) {
log.debug("Suitable lightpath FOUND for intent {}", intent);
resources.addAll(convertToResources(found.get().getKey(), found.get().getValue()));
allocateResources(intent, resources);
OchSignal ochSignal = OchSignal.toFixedGrid(found.get().getValue(), ChannelSpacing.CHL_50GHZ);
return ImmutableList.of(createIntent(intent, found.get().getKey(), ochSignal));
} else {
log.error("Unable to find suitable lightpath for intent {}", intent);
throw new OpticalIntentCompilationException("Unable to find suitable lightpath for intent " + intent);
}
}
Aggregations