use of org.onosproject.net.resource.Resource in project onos by opennetworkinglab.
the class ResourceDeviceListener method unregisterDeviceResource.
private void unregisterDeviceResource(Device device) {
DiscreteResource devResource = Resources.discrete(device.id()).resource();
List<Resource> allResources = getDescendantResources(devResource);
adminService.unregister(Lists.transform(allResources, Resource::id));
}
use of org.onosproject.net.resource.Resource 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.Resource 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.Resource in project onos by opennetworkinglab.
the class OpticalCircuitIntentCompiler method compile.
@Override
public List<Intent> compile(OpticalCircuitIntent intent, List<Intent> installable) {
// Check if ports are OduClt ports
ConnectPoint src = intent.getSrc();
ConnectPoint dst = intent.getDst();
Port srcPort = deviceService.getPort(src.deviceId(), src.port());
Port dstPort = deviceService.getPort(dst.deviceId(), dst.port());
checkArgument(srcPort instanceof OduCltPort);
checkArgument(dstPort instanceof OduCltPort);
log.debug("Compiling optical circuit 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 OduClt ports availability
Resource srcPortResource = Resources.discrete(src.deviceId(), src.port()).resource();
Resource dstPortResource = Resources.discrete(dst.deviceId(), dst.port()).resource();
// If ports are not available, compilation fails
if (!Stream.of(srcPortResource, dstPortResource).allMatch(resourceService::isAvailable)) {
throw new OpticalIntentCompilationException("Ports for the intent are not available. Intent: " + intent);
}
List<Resource> ports = ImmutableList.of(srcPortResource, dstPortResource);
// Check if both devices support multiplexing (usage of TributarySlots)
boolean multiplexingSupported = isMultiplexingSupported(intent.getSrc()) && isMultiplexingSupported(intent.getDst());
OpticalConnectivityIntent connIntent = findOpticalConnectivityIntent(intent.getSrc(), intent.getDst(), intent.getSignalType(), multiplexingSupported);
if (connIntent != null && !multiplexingSupported) {
return compile(intent, src, dst, Optional.of(connIntent), ports, false);
}
// Create optical connectivity intent if needed - no optical intent or not enough slots available
if (connIntent == null) {
return compile(intent, src, dst, Optional.empty(), ports, multiplexingSupported);
}
List<Resource> slots = availableSlotResources(connIntent.getSrc(), connIntent.getDst(), intent.getSignalType());
if (slots.isEmpty()) {
return compile(intent, src, dst, Optional.empty(), ports, true);
}
return compile(intent, src, dst, Optional.of(connIntent), ImmutableList.<Resource>builder().addAll(ports).addAll(slots).build(), false);
}
use of org.onosproject.net.resource.Resource in project onos by opennetworkinglab.
the class OpticalCircuitIntentCompiler method availableSlotResources.
private List<Resource> availableSlotResources(ConnectPoint src, ConnectPoint dst, CltSignalType signalType) {
OduSignalType oduSignalType = OduSignalUtils.mappingCltSignalTypeToOduSignalType(signalType);
int requestedTsNum = oduSignalType.tributarySlots();
Set<TributarySlot> commonTributarySlots = findCommonTributarySlotsOnCps(src, dst);
if (commonTributarySlots.isEmpty()) {
return Collections.emptyList();
}
if (commonTributarySlots.size() < requestedTsNum) {
return Collections.emptyList();
}
Set<TributarySlot> tributarySlots = commonTributarySlots.stream().limit(requestedTsNum).collect(Collectors.toSet());
final List<ConnectPoint> portsList = ImmutableList.of(src, dst);
List<Resource> tributarySlotResources = portsList.stream().flatMap(cp -> tributarySlots.stream().map(ts -> Resources.discrete(cp.deviceId(), cp.port()).resource().child(ts))).collect(Collectors.toList());
if (!tributarySlotResources.stream().allMatch(resourceService::isAvailable)) {
log.debug("Resource allocation for {} on {} and {} failed (resource request: {})", signalType, src, dst, tributarySlotResources);
return Collections.emptyList();
}
return tributarySlotResources;
}
Aggregations