Search in sources :

Example 31 with Link

use of org.onosproject.net.Link in project onos by opennetworkinglab.

the class PathCompiler method compile.

/**
 * Compiles an intent down to flows.
 *
 * @param creator how to create the flows
 * @param intent intent to process
 * @param flows list of generated flows
 * @param devices list of devices that correspond to the flows
 */
public void compile(PathCompilerCreateFlow<T> creator, PathIntent intent, List<T> flows, List<DeviceId> devices) {
    // Note: right now recompile is not considered
    // TODO: implement recompile behavior
    List<Link> links = intent.path().links();
    Optional<EncapsulationConstraint> encapConstraint = intent.constraints().stream().filter(constraint -> constraint instanceof EncapsulationConstraint).map(x -> (EncapsulationConstraint) x).findAny();
    // if no encapsulation or is involved only a single switch use the default behaviour
    if (!encapConstraint.isPresent() || links.size() == 2) {
        for (int i = 0; i < links.size() - 1; i++) {
            ConnectPoint ingress = links.get(i).dst();
            ConnectPoint egress = links.get(i + 1).src();
            creator.createFlow(intent.selector(), intent.treatment(), ingress, egress, intent.priority(), isLast(links, i), flows, devices);
        }
        return;
    }
    encapConstraint.map(EncapsulationConstraint::encapType).map(type -> {
        switch(type) {
            case VLAN:
                manageVlanEncap(creator, flows, devices, intent);
                break;
            case MPLS:
                manageMplsEncap(creator, flows, devices, intent);
                break;
            default:
        }
        return 0;
    });
}
Also used : EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) Identifier(org.onlab.util.Identifier) LabelAllocator(org.onosproject.net.resource.impl.LabelAllocator) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) ResourceService(org.onosproject.net.resource.ResourceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) LinkKey(org.onosproject.net.LinkKey) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MplsLabel(org.onlab.packet.MplsLabel) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Sets(com.google.common.collect.Sets) EthType(org.onlab.packet.EthType) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint)

Example 32 with Link

use of org.onosproject.net.Link in project onos by opennetworkinglab.

the class PointToPointIntentCompiler method createSinglePathIntent.

private List<Intent> createSinglePathIntent(ConnectPoint ingressPoint, ConnectPoint egressPoint, PointToPointIntent intent, List<Intent> installable) {
    List<Link> links = new ArrayList<>();
    Path onlyPath = getPathOrException(intent, ingressPoint.deviceId(), egressPoint.deviceId());
    List<Intent> reusableIntents = null;
    if (installable != null) {
        reusableIntents = filterInvalidSubIntents(installable, intent);
        if (reusableIntents.size() == installable.size()) {
            // all old paths are still viable
            return installable;
        }
    }
    // return the intents that comprise it.
    if (reusableIntents != null && reusableIntents.size() > 1) {
        return reusableIntents;
    } else {
        // Allocate bandwidth if a bandwidth constraint is set
        allocateIntentBandwidth(intent, onlyPath);
        links.add(createEdgeLink(ingressPoint, true));
        links.addAll(onlyPath.links());
        links.add(createEdgeLink(egressPoint, false));
        return asList(createPathIntent(new DefaultPath(PID, links, onlyPath.weight(), onlyPath.annotations()), intent, PathIntent.ProtectionType.PRIMARY));
    }
}
Also used : Path(org.onosproject.net.Path) DefaultPath(org.onosproject.net.DefaultPath) DisjointPath(org.onosproject.net.DisjointPath) ArrayList(java.util.ArrayList) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) DefaultPath(org.onosproject.net.DefaultPath) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) Link(org.onosproject.net.Link) EdgeLink(org.onosproject.net.EdgeLink)

Example 33 with Link

use of org.onosproject.net.Link in project onos by opennetworkinglab.

the class PointToPointIntentCompiler method pathAvailable.

/**
 * Checks suggested path availability.
 * It checks:
 * - single links availability;
 * - that first and last device of the path are coherent with ingress and egress devices;
 * - links contiguity.
 *
 * @param intent    Intent with suggested path to check
 * @return true if the suggested path is available
 */
private boolean pathAvailable(PointToPointIntent intent) {
    // Check links availability
    List<Link> suggestedPath = intent.suggestedPath();
    for (Link link : suggestedPath) {
        if (!(link instanceof EdgeLink) && !linkService.getLinks(link.src()).contains(link)) {
            return false;
        }
    }
    // Check that first and last device of the path are intent ingress and egress devices
    if (!suggestedPath.get(0).src().deviceId().equals(intent.filteredIngressPoint().connectPoint().deviceId())) {
        return false;
    }
    if (!suggestedPath.get(suggestedPath.size() - 1).dst().deviceId().equals(intent.filteredEgressPoint().connectPoint().deviceId())) {
        return false;
    }
    // Check contiguity
    List<Pair<Link, Link>> linkPairs = IntStream.range(0, suggestedPath.size() - 1).mapToObj(i -> Pair.of(suggestedPath.get(i), suggestedPath.get(i + 1))).collect(Collectors.toList());
    for (Pair<Link, Link> linkPair : linkPairs) {
        if (!linkPair.getKey().dst().deviceId().equals(linkPair.getValue().src().deviceId())) {
            return false;
        }
    }
    return true;
}
Also used : DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) ListIterator(java.util.ListIterator) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) TimeoutException(java.util.concurrent.TimeoutException) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Pair(org.apache.commons.lang3.tuple.Pair) Port(org.onosproject.net.Port) GroupListener(org.onosproject.net.group.GroupListener) Arrays.asList(java.util.Arrays.asList) PathNotFoundException(org.onosproject.net.intent.impl.PathNotFoundException) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) ImmutableSet(com.google.common.collect.ImmutableSet) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) Stream(java.util.stream.Stream) FlowRule(org.onosproject.net.flow.FlowRule) GroupBuckets(org.onosproject.net.group.GroupBuckets) LinkService(org.onosproject.net.link.LinkService) Path(org.onosproject.net.Path) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) IntStream(java.util.stream.IntStream) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) CompletableFuture(java.util.concurrent.CompletableFuture) GroupBucket(org.onosproject.net.group.GroupBucket) GroupKey(org.onosproject.net.group.GroupKey) Group(org.onosproject.net.group.Group) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) DefaultPath(org.onosproject.net.DefaultPath) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) EdgeLink(org.onosproject.net.EdgeLink) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IntentId(org.onosproject.net.intent.IntentId) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Instructions(org.onosproject.net.flow.instructions.Instructions) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Instruction(org.onosproject.net.flow.instructions.Instruction) GroupService(org.onosproject.net.group.GroupService) ProtectionConstraint(org.onosproject.net.intent.constraint.ProtectionConstraint) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) ProviderId(org.onosproject.net.provider.ProviderId) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) ScalarWeight(org.onlab.graph.ScalarWeight) Reference(org.osgi.service.component.annotations.Reference) Collections(java.util.Collections) DisjointPath(org.onosproject.net.DisjointPath) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) EdgeLink(org.onosproject.net.EdgeLink) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) Link(org.onosproject.net.Link) EdgeLink(org.onosproject.net.EdgeLink) Pair(org.apache.commons.lang3.tuple.Pair)

Example 34 with Link

use of org.onosproject.net.Link in project onos by opennetworkinglab.

the class PointToPointIntentCompiler method createProtectedIntent.

// FIXME: Compatibility with EncapsulationConstraint
private List<Intent> createProtectedIntent(ConnectPoint ingressPoint, ConnectPoint egressPoint, PointToPointIntent intent, List<Intent> installable) {
    log.trace("createProtectedIntent");
    DisjointPath path = getDisjointPath(intent, ingressPoint.deviceId(), egressPoint.deviceId());
    List<Intent> reusableIntents = null;
    if (installable != null) {
        reusableIntents = filterInvalidSubIntents(installable, intent);
        if (reusableIntents.size() == installable.size()) {
            // all old paths are still viable
            return installable;
        }
    }
    List<Intent> intentList = new ArrayList<>();
    // primary path intent
    List<Link> links = new ArrayList<>();
    links.addAll(path.links());
    links.add(createEdgeLink(egressPoint, false));
    // backup path intent
    List<Link> backupLinks = new ArrayList<>();
    backupLinks.addAll(path.backup().links());
    backupLinks.add(createEdgeLink(egressPoint, false));
    /*
         * One of the old paths is still entirely intact. This old path has
         * already been made primary, so we must add a backup path intent
         * and modify the failover group treatment accordingly.
         */
    if (reusableIntents != null && reusableIntents.size() > 1) {
        /*
             * Ensures that the egress port on source device is different than
             * that of existing path so that failover group will be useful
             * (would not be useful if both output ports in group bucket were
             * the same). Does not necessarily ensure that the new backup path
             * is entirely disjoint from the old path.
             */
        PortNumber primaryPort = getPrimaryPort(intent);
        if (primaryPort != null && !links.get(0).src().port().equals(primaryPort)) {
            reusableIntents.add(createPathIntent(new DefaultPath(PID, links, path.weight(), path.annotations()), intent, PathIntent.ProtectionType.BACKUP));
            updateFailoverGroup(intent, links);
            return reusableIntents;
        } else {
            reusableIntents.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().weight(), path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP));
            updateFailoverGroup(intent, backupLinks);
            return reusableIntents;
        }
    }
    intentList.add(createPathIntent(new DefaultPath(PID, links, path.weight(), path.annotations()), intent, PathIntent.ProtectionType.PRIMARY));
    intentList.add(createPathIntent(new DefaultPath(PID, backupLinks, path.backup().weight(), path.backup().annotations()), intent, PathIntent.ProtectionType.BACKUP));
    // add contents appropriately.
    if (groupService.getGroup(ingressPoint.deviceId(), makeGroupKey(intent.id())) == null) {
        // manufactured fast failover flow rule intent
        createFailoverTreatmentGroup(path.links(), path.backup().links(), intent);
        FlowRuleIntent frIntent = new FlowRuleIntent(intent.appId(), intent.key(), createFailoverFlowRules(intent), asList(ingressPoint.deviceId()), PathIntent.ProtectionType.FAILOVER, intent.resourceGroup());
        intentList.add(frIntent);
    } else {
        updateFailoverGroup(intent, links);
        updateFailoverGroup(intent, backupLinks);
    }
    return intentList;
}
Also used : ArrayList(java.util.ArrayList) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent) Intent(org.onosproject.net.intent.Intent) PathIntent(org.onosproject.net.intent.PathIntent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) PointToPointIntent(org.onosproject.net.intent.PointToPointIntent) DefaultPath(org.onosproject.net.DefaultPath) PortNumber(org.onosproject.net.PortNumber) DisjointPath(org.onosproject.net.DisjointPath) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) Link(org.onosproject.net.Link) EdgeLink(org.onosproject.net.EdgeLink) FlowRuleIntent(org.onosproject.net.intent.FlowRuleIntent)

Example 35 with Link

use of org.onosproject.net.Link 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)

Aggregations

Link (org.onosproject.net.Link)210 ConnectPoint (org.onosproject.net.ConnectPoint)92 Test (org.junit.Test)66 DeviceId (org.onosproject.net.DeviceId)62 DefaultLink (org.onosproject.net.DefaultLink)50 Intent (org.onosproject.net.intent.Intent)40 List (java.util.List)38 Set (java.util.Set)33 Collectors (java.util.stream.Collectors)30 Device (org.onosproject.net.Device)30 TrafficSelector (org.onosproject.net.flow.TrafficSelector)30 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)29 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)28 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)28 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)26 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)26 ArrayList (java.util.ArrayList)24 Collections (java.util.Collections)24 Path (org.onosproject.net.Path)24 FlowRuleIntent (org.onosproject.net.intent.FlowRuleIntent)24