Search in sources :

Example 11 with Intent

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

the class ProtectedTransportIntentCompiler method createFreshProtectedPaths.

/**
 * Creates new protected paths.
 *
 * @param intent    original intention
 * @param did1      identifier of first device
 * @param did2      identifier of second device
 * @return compilation result
 * @throws IntentCompilationException when there's no satisfying path.
 */
private List<Intent> createFreshProtectedPaths(ProtectedTransportIntent intent, DeviceId did1, DeviceId did2) {
    DisjointPath disjointPath = getDisjointPath(intent, did1, did2);
    if (disjointPath == null || disjointPath.backup() == null) {
        log.error("Unable to find disjoint path between {}, {}", did1, did2);
        throw new IntentCompilationException("Unable to find disjoint paths.");
    }
    Path primary = disjointPath.primary();
    Path secondary = disjointPath.backup();
    String fingerprint = intent.key().toString();
    // pick and allocate Vlan to use as S-tag
    Pair<VlanId, VlanId> vlans = allocateEach(intent, primary, secondary, VlanId.class);
    VlanId primaryVlan = vlans.getLeft();
    VlanId secondaryVlan = vlans.getRight();
    // Build edge Intents for head/tail
    // resource for head/tail
    Collection<NetworkResource> oneResources = new ArrayList<>();
    Collection<NetworkResource> twoResources = new ArrayList<>();
    List<TransportEndpointDescription> onePaths = new ArrayList<>();
    onePaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(primary.src(), primaryVlan)).build());
    onePaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(secondary.src(), secondaryVlan)).build());
    List<TransportEndpointDescription> twoPaths = new ArrayList<>();
    twoPaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(primary.dst(), primaryVlan)).build());
    twoPaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(secondary.dst(), secondaryVlan)).build());
    ProtectionEndpointIntent oneIntent = ProtectionEndpointIntent.builder().key(intent.key()).appId(intent.appId()).priority(intent.priority()).resources(oneResources).deviceId(did1).description(buildDescription(onePaths, did2, fingerprint)).build();
    ProtectionEndpointIntent twoIntent = ProtectionEndpointIntent.builder().key(intent.key()).appId(intent.appId()).resources(twoResources).deviceId(did2).description(buildDescription(twoPaths, did1, fingerprint)).build();
    // Build transit intent for primary/secondary path
    Collection<NetworkResource> resources1 = ImmutableList.of(marker("protection1"));
    Collection<NetworkResource> resources2 = ImmutableList.of(marker("protection2"));
    ImmutableList<Intent> result = ImmutableList.<Intent>builder().addAll(createTransitIntent(intent, primary, primaryVlan, resources1)).addAll(createTransitIntent(intent, secondary, secondaryVlan, resources2)).add(oneIntent).add(twoIntent).build();
    log.trace("createFreshProtectedPaths result: {}", result);
    return result;
}
Also used : DefaultPath(org.onosproject.net.DefaultPath) Path(org.onosproject.net.Path) DisjointPath(org.onosproject.net.DisjointPath) ArrayList(java.util.ArrayList) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) ProtectedTransportIntent(org.onosproject.net.intent.ProtectedTransportIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) NetworkResource(org.onosproject.net.NetworkResource) TransportEndpointDescription(org.onosproject.net.behaviour.protection.TransportEndpointDescription) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) DisjointPath(org.onosproject.net.DisjointPath) VlanId(org.onlab.packet.VlanId)

Example 12 with Intent

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

the class ProtectedTransportIntentCompiler method compile.

@Override
public List<Intent> compile(ProtectedTransportIntent intent, List<Intent> installable) {
    log.trace("compiling {} {}", intent, installable);
    // case 0 hop, same device
    final DeviceId did1 = intent.one();
    final DeviceId did2 = intent.two();
    if (Objects.equals(did1, did2)) {
        // Doesn't really make sense to create 0 hop protected path, but
        // can generate Flow for the device, just to provide connectivity.
        // future work.
        log.error("0 hop not supported yet.");
        throw new IntentCompilationException("0 hop not supported yet.");
    }
    List<Intent> reusable = Optional.ofNullable(installable).orElse(ImmutableList.of()).stream().filter(this::isIntact).collect(Collectors.toList());
    if (reusable.isEmpty() || reusable.stream().allMatch(ProtectionEndpointIntent.class::isInstance)) {
        // case re-compilation (total failure -> restoration)
        return createFreshProtectedPaths(intent, did1, did2);
    } else {
        // case re-compilation (partial failure)
        log.warn("Re-computing adding new backup path not supported yet. No-Op.");
        // TODO do we need to prune broken
        return installable;
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) ProtectedTransportIntent(org.onosproject.net.intent.ProtectedTransportIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) ProtectionEndpointIntent(org.onosproject.net.intent.ProtectionEndpointIntent) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException)

Example 13 with Intent

use of org.onosproject.net.intent.Intent 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 14 with Intent

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

the class IntentManager method getIntentsByAppId.

@Override
public Iterable<Intent> getIntentsByAppId(ApplicationId id) {
    checkPermission(INTENT_READ);
    ImmutableSet.Builder<Intent> builder = ImmutableSet.builder();
    for (Intent intent : store.getIntents()) {
        if (intent.appId().equals(id)) {
            builder.add(intent);
        }
    }
    return builder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Intent(org.onosproject.net.intent.Intent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent)

Example 15 with Intent

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

the class IntentManager method buildAndSubmitBatches.

private void buildAndSubmitBatches(Iterable<Key> intentKeys, boolean compileAllFailed) {
    // Attempt recompilation of the specified intents first.
    for (Key key : intentKeys) {
        if (!store.isMaster(key)) {
            continue;
        }
        Intent intent = store.getIntent(key);
        if (intent == null) {
            continue;
        }
        if (store.getPendingData(key) != null) {
            continue;
        }
        submit(intent);
    }
    if (compileAllFailed) {
        // If required, compile all currently failed intents.
        for (Intent intent : getIntents()) {
            if (!store.isMaster(intent.key())) {
                continue;
            }
            if (store.getPendingData(intent.key()) != null) {
                continue;
            }
            IntentState state = getIntentState(intent.key());
            if (RECOMPILE.contains(state) || intentAllowsPartialFailure(intent)) {
                if (WITHDRAW.contains(state)) {
                    withdraw(intent);
                } else {
                    submit(intent);
                }
            }
        }
    }
}
Also used : IntentState(org.onosproject.net.intent.IntentState) Intent(org.onosproject.net.intent.Intent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) Key(org.onosproject.net.intent.Key) GroupKey(org.onosproject.net.group.GroupKey)

Aggregations

Intent (org.onosproject.net.intent.Intent)282 Test (org.junit.Test)176 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)133 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)110 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)108 FlowRule (org.onosproject.net.flow.FlowRule)90 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)87 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)84 ConnectPoint (org.onosproject.net.ConnectPoint)78 DeviceId (org.onosproject.net.DeviceId)77 List (java.util.List)75 Collectors (java.util.stream.Collectors)71 AbstractIntentTest (org.onosproject.net.intent.AbstractIntentTest)70 PathIntent (org.onosproject.net.intent.PathIntent)70 Collection (java.util.Collection)60 VlanId (org.onlab.packet.VlanId)60 TrafficSelector (org.onosproject.net.flow.TrafficSelector)60 CoreService (org.onosproject.core.CoreService)59 Collections (java.util.Collections)57 ImmutableSet (com.google.common.collect.ImmutableSet)54