Search in sources :

Example 16 with ResourceService

use of org.onosproject.net.resource.ResourceService 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

ResourceService (org.onosproject.net.resource.ResourceService)16 ConnectPoint (org.onosproject.net.ConnectPoint)12 Test (org.junit.Test)11 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)11 Constraint (org.onosproject.net.intent.Constraint)11 BandwidthConstraint (org.onosproject.net.intent.constraint.BandwidthConstraint)11 MockResourceService (org.onosproject.net.resource.MockResourceService)11 ResourceAllocation (org.onosproject.net.resource.ResourceAllocation)11 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)10 PointToPointIntent (org.onosproject.net.intent.PointToPointIntent)8 Key (org.onosproject.net.intent.Key)5 Bandwidth (org.onlab.util.Bandwidth)4 DeviceId (org.onosproject.net.DeviceId)4 DeviceService (org.onosproject.net.device.DeviceService)4 Collections (java.util.Collections)3 List (java.util.List)3 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 Link (org.onosproject.net.Link)3 Intent (org.onosproject.net.intent.Intent)3