Search in sources :

Example 1 with IntentException

use of org.onosproject.net.intent.IntentException in project onos by opennetworkinglab.

the class SinglePointToMultiPointIntentCompiler method compile.

@Override
public List<Intent> compile(SinglePointToMultiPointIntent intent, List<Intent> installable) {
    Set<Link> links = new HashSet<>();
    final boolean allowMissingPaths = intentAllowsPartialFailure(intent);
    boolean hasPaths = false;
    boolean missingSomePaths = false;
    for (ConnectPoint egressPoint : intent.egressPoints()) {
        if (egressPoint.deviceId().equals(intent.ingressPoint().deviceId())) {
            // devices are the same.
            if (deviceService.isAvailable(egressPoint.deviceId())) {
                hasPaths = true;
            } else {
                missingSomePaths = true;
            }
            continue;
        }
        Path path = getPath(intent, intent.ingressPoint().deviceId(), egressPoint.deviceId());
        if (path != null) {
            hasPaths = true;
            links.addAll(path.links());
        } else {
            missingSomePaths = true;
        }
    }
    // Allocate bandwidth if a bandwidth constraint is set
    ConnectPoint ingressCP = intent.filteredIngressPoint().connectPoint();
    List<ConnectPoint> egressCPs = intent.filteredEgressPoints().stream().map(fcp -> fcp.connectPoint()).collect(Collectors.toList());
    List<ConnectPoint> pathCPs = links.stream().flatMap(l -> Stream.of(l.src(), l.dst())).collect(Collectors.toList());
    pathCPs.add(ingressCP);
    pathCPs.addAll(egressCPs);
    allocateBandwidth(intent, pathCPs);
    if (!hasPaths) {
        throw new IntentException("Cannot find any path between ingress and egress points.");
    } else if (!allowMissingPaths && missingSomePaths) {
        throw new IntentException("Missing some paths between ingress and egress points.");
    }
    Intent result = LinkCollectionIntent.builder().appId(intent.appId()).key(intent.key()).selector(intent.selector()).treatment(intent.treatment()).links(links).filteredIngressPoints(ImmutableSet.of(intent.filteredIngressPoint())).filteredEgressPoints(intent.filteredEgressPoints()).priority(intent.priority()).applyTreatmentOnEgress(true).constraints(intent.constraints()).resourceGroup(intent.resourceGroup()).build();
    return Collections.singletonList(result);
}
Also used : Path(org.onosproject.net.Path) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) Link(org.onosproject.net.Link) Collectors(java.util.stream.Collectors) ConnectPoint(org.onosproject.net.ConnectPoint) PartialFailureConstraint.intentAllowsPartialFailure(org.onosproject.net.intent.constraint.PartialFailureConstraint.intentAllowsPartialFailure) HashSet(java.util.HashSet) IntentException(org.onosproject.net.intent.IntentException) Component(org.osgi.service.component.annotations.Component) List(java.util.List) Stream(java.util.stream.Stream) Intent(org.onosproject.net.intent.Intent) Path(org.onosproject.net.Path) Activate(org.osgi.service.component.annotations.Activate) Collections(java.util.Collections) IntentException(org.onosproject.net.intent.IntentException) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) SinglePointToMultiPointIntent(org.onosproject.net.intent.SinglePointToMultiPointIntent) Intent(org.onosproject.net.intent.Intent) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) HashSet(java.util.HashSet)

Example 2 with IntentException

use of org.onosproject.net.intent.IntentException in project onos by opennetworkinglab.

the class MultiPointToSinglePointIntentCompiler method compile.

@Override
public List<Intent> compile(MultiPointToSinglePointIntent intent, List<Intent> installable) {
    Map<DeviceId, Link> links = new HashMap<>();
    ConnectPoint egressPoint = intent.egressPoint();
    final boolean allowMissingPaths = intentAllowsPartialFailure(intent);
    boolean hasPaths = false;
    boolean missingSomePaths = false;
    for (ConnectPoint ingressPoint : intent.ingressPoints()) {
        if (ingressPoint.deviceId().equals(egressPoint.deviceId())) {
            if (deviceService.isAvailable(ingressPoint.deviceId())) {
                hasPaths = true;
            } else {
                missingSomePaths = true;
            }
            continue;
        }
        Path path = getPath(intent, ingressPoint.deviceId(), egressPoint.deviceId());
        if (path != null) {
            hasPaths = true;
            for (Link link : path.links()) {
                if (links.containsKey(link.dst().deviceId())) {
                    // We've already reached the existing tree with the first
                    // part of this path. Add the merging point with different
                    // incoming port, but don't add the remainder of the path
                    // in case it differs from the path we already have.
                    links.put(link.src().deviceId(), link);
                    break;
                }
                links.put(link.src().deviceId(), link);
            }
        } else {
            missingSomePaths = true;
        }
    }
    // Allocate bandwidth on existing paths if a bandwidth constraint is set
    List<ConnectPoint> ingressCPs = intent.filteredIngressPoints().stream().map(fcp -> fcp.connectPoint()).collect(Collectors.toList());
    ConnectPoint egressCP = intent.filteredEgressPoint().connectPoint();
    List<ConnectPoint> pathCPs = links.values().stream().flatMap(l -> Stream.of(l.src(), l.dst())).collect(Collectors.toList());
    pathCPs.addAll(ingressCPs);
    pathCPs.add(egressCP);
    allocateBandwidth(intent, pathCPs);
    if (!hasPaths) {
        throw new IntentException("Cannot find any path between ingress and egress points.");
    } else if (!allowMissingPaths && missingSomePaths) {
        throw new IntentException("Missing some paths between ingress and egress points.");
    }
    Intent result = LinkCollectionIntent.builder().appId(intent.appId()).key(intent.key()).treatment(intent.treatment()).selector(intent.selector()).links(Sets.newHashSet(links.values())).filteredIngressPoints(intent.filteredIngressPoints()).filteredEgressPoints(ImmutableSet.of(intent.filteredEgressPoint())).priority(intent.priority()).constraints(intent.constraints()).resourceGroup(intent.resourceGroup()).build();
    return Collections.singletonList(result);
}
Also used : Path(org.onosproject.net.Path) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) HashMap(java.util.HashMap) Link(org.onosproject.net.Link) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ConnectPoint(org.onosproject.net.ConnectPoint) PartialFailureConstraint.intentAllowsPartialFailure(org.onosproject.net.intent.constraint.PartialFailureConstraint.intentAllowsPartialFailure) IntentException(org.onosproject.net.intent.IntentException) Component(org.osgi.service.component.annotations.Component) List(java.util.List) Stream(java.util.stream.Stream) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Map(java.util.Map) Intent(org.onosproject.net.intent.Intent) Path(org.onosproject.net.Path) Activate(org.osgi.service.component.annotations.Activate) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) IntentException(org.onosproject.net.intent.IntentException) HashMap(java.util.HashMap) DeviceId(org.onosproject.net.DeviceId) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) MultiPointToSinglePointIntent(org.onosproject.net.intent.MultiPointToSinglePointIntent) Intent(org.onosproject.net.intent.Intent) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link)

Example 3 with IntentException

use of org.onosproject.net.intent.IntentException in project onos by opennetworkinglab.

the class ProtectionEndpointIntentInstaller method apply.

@Override
public void apply(IntentOperationContext<ProtectionEndpointIntent> context) {
    Optional<IntentData> toUninstall = context.toUninstall();
    Optional<IntentData> toInstall = context.toInstall();
    List<ProtectionEndpointIntent> uninstallIntents = context.intentsToUninstall();
    List<ProtectionEndpointIntent> installIntents = context.intentsToInstall();
    if (!toInstall.isPresent() && !toUninstall.isPresent()) {
        intentInstallCoordinator.intentInstallSuccess(context);
        return;
    }
    if (toUninstall.isPresent()) {
        IntentData intentData = toUninstall.get();
        trackerService.removeTrackedResources(intentData.key(), intentData.intent().resources());
        uninstallIntents.forEach(installable -> trackerService.removeTrackedResources(intentData.intent().key(), installable.resources()));
    }
    if (toInstall.isPresent()) {
        IntentData intentData = toInstall.get();
        trackerService.addTrackedResources(intentData.key(), intentData.intent().resources());
        installIntents.forEach(installable -> trackerService.addTrackedResources(intentData.key(), installable.resources()));
    }
    List<Stage> stages = new ArrayList<>();
    stages.add(new Stage(uninstallIntents.stream().map(i -> Pair.of(i, REMOVE)).collect(Collectors.toList())));
    stages.add(new Stage(installIntents.stream().map(i -> Pair.of(i, ADD)).collect(Collectors.toList())));
    for (Stage stage : stages) {
        log.debug("applying Stage {}", stage);
        try {
            // wait for stage completion
            stage.apply();
            stage.listeners().forEach(networkConfigService::removeListener);
        } catch (IntentException e) {
            log.error("Stage {} failed, reason: {}", stage, e.toString());
            intentInstallCoordinator.intentInstallFailed(context);
            return;
        }
    }
    // All stage success
    intentInstallCoordinator.intentInstallSuccess(context);
}
Also used : NetworkConfigService(org.onosproject.net.config.NetworkConfigService) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) IntentData(org.onosproject.net.intent.IntentData) ArrayList(java.util.ArrayList) ADD(org.onosproject.net.intent.IntentInstaller.Direction.ADD) Component(org.osgi.service.component.annotations.Component) Pair(org.apache.commons.lang3.tuple.Pair) Activate(org.osgi.service.component.annotations.Activate) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) IntentInstaller(org.onosproject.net.intent.IntentInstaller) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Deactivate(org.osgi.service.component.annotations.Deactivate) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Collection(java.util.Collection) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Set(java.util.Set) IntentOperationContext(org.onosproject.net.intent.IntentOperationContext) ProtectionConfig(org.onosproject.net.behaviour.protection.ProtectionConfig) IntentManager(org.onosproject.net.intent.impl.IntentManager) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ObjectiveTrackerService(org.onosproject.net.intent.ObjectiveTrackerService) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) IntentException(org.onosproject.net.intent.IntentException) List(java.util.List) REMOVE(org.onosproject.net.intent.IntentInstaller.Direction.REMOVE) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Optional(java.util.Optional) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) IntentInstallCoordinator(org.onosproject.net.intent.IntentInstallCoordinator) NetworkConfigListener(org.onosproject.net.config.NetworkConfigListener) Type(org.onosproject.net.config.NetworkConfigEvent.Type) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) IntentException(org.onosproject.net.intent.IntentException) IntentData(org.onosproject.net.intent.IntentData) ArrayList(java.util.ArrayList) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent)

Aggregations

ImmutableSet (com.google.common.collect.ImmutableSet)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 IntentException (org.onosproject.net.intent.IntentException)3 Activate (org.osgi.service.component.annotations.Activate)3 Component (org.osgi.service.component.annotations.Component)3 Deactivate (org.osgi.service.component.annotations.Deactivate)3 Sets (com.google.common.collect.Sets)2 Collections (java.util.Collections)2 Set (java.util.Set)2 Stream (java.util.stream.Stream)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 DeviceId (org.onosproject.net.DeviceId)2 Link (org.onosproject.net.Link)2 Path (org.onosproject.net.Path)2 Intent (org.onosproject.net.intent.Intent)2 Preconditions.checkNotNull (com.google.common.base.Preconditions.checkNotNull)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1