Search in sources :

Example 16 with Resource

use of org.onosproject.net.resource.Resource 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);
    }
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) DefaultOchSignalComparator(org.onosproject.net.DefaultOchSignalComparator) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) TopologyService(org.onosproject.net.topology.TopologyService) Link(org.onosproject.net.Link) ResourceService(org.onosproject.net.resource.ResourceService) ConnectPoint(org.onosproject.net.ConnectPoint) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Topology(org.onosproject.net.topology.Topology) Port(org.onosproject.net.Port) Map(java.util.Map) OchPort(org.onosproject.net.optical.OchPort) DefaultLink(org.onosproject.net.DefaultLink) OchSignalType(org.onosproject.net.OchSignalType) ImmutableSet(com.google.common.collect.ImmutableSet) Resources(org.onosproject.net.resource.Resources) Deactivate(org.osgi.service.component.annotations.Deactivate) OpticalPathIntent(org.onosproject.net.intent.OpticalPathIntent) Collection(java.util.Collection) Set(java.util.Set) Resource(org.onosproject.net.resource.Resource) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) List(java.util.List) Stream(java.util.stream.Stream) Annotations(org.onosproject.net.Annotations) IntentCompiler(org.onosproject.net.intent.IntentCompiler) Optional(java.util.Optional) Path(org.onosproject.net.Path) ChannelSpacing(org.onosproject.net.ChannelSpacing) DeviceId(org.onosproject.net.DeviceId) IntStream(java.util.stream.IntStream) GridType(org.onosproject.net.GridType) TopologyEdge(org.onosproject.net.topology.TopologyEdge) AnnotationKeys(org.onosproject.net.AnnotationKeys) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) ImmutableList(com.google.common.collect.ImmutableList) DefaultPath(org.onosproject.net.DefaultPath) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) LinkedList(java.util.LinkedList) Logger(org.slf4j.Logger) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) ProviderId(org.onosproject.net.provider.ProviderId) Maps(com.google.common.collect.Maps) OchSignal(org.onosproject.net.OchSignal) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Weight(org.onlab.graph.Weight) OpticalDeviceServiceView.opticalView(org.onosproject.net.optical.device.OpticalDeviceServiceView.opticalView) LinkWeigher(org.onosproject.net.topology.LinkWeigher) Reference(org.osgi.service.component.annotations.Reference) ScalarWeight(org.onlab.graph.ScalarWeight) OpticalConnectivityIntent(org.onosproject.net.intent.OpticalConnectivityIntent) Collections(java.util.Collections) Resource(org.onosproject.net.resource.Resource) OchSignal(org.onosproject.net.OchSignal) ConnectPoint(org.onosproject.net.ConnectPoint) OchPort(org.onosproject.net.optical.OchPort) LinkedList(java.util.LinkedList)

Aggregations

Resource (org.onosproject.net.resource.Resource)16 Set (java.util.Set)8 DiscreteResource (org.onosproject.net.resource.DiscreteResource)8 ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)8 List (java.util.List)7 ConnectPoint (org.onosproject.net.ConnectPoint)7 Resources (org.onosproject.net.resource.Resources)7 Optional (java.util.Optional)6 Collectors (java.util.stream.Collectors)6 Reference (org.osgi.service.component.annotations.Reference)6 ReferenceCardinality (org.osgi.service.component.annotations.ReferenceCardinality)6 Logger (org.slf4j.Logger)6 LoggerFactory (org.slf4j.LoggerFactory)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)5 ImmutableSet (com.google.common.collect.ImmutableSet)5 Collection (java.util.Collection)5 Collections (java.util.Collections)5 DeviceId (org.onosproject.net.DeviceId)5 ImmutableList (com.google.common.collect.ImmutableList)4 ArrayList (java.util.ArrayList)4