Search in sources :

Example 6 with Path

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

the class HostToHostIntentCompiler method compile.

@Override
public List<Intent> compile(HostToHostIntent intent, List<Intent> installable) {
    // If source and destination are the same, there are never any installables.
    if (Objects.equals(intent.one(), intent.two())) {
        return ImmutableList.of();
    }
    boolean isAsymmetric = intent.constraints().contains(new AsymmetricPathConstraint());
    Path pathOne = getPathOrException(intent, intent.one(), intent.two());
    Path pathTwo = isAsymmetric ? getPathOrException(intent, intent.two(), intent.one()) : invertPath(pathOne);
    Host one = hostService.getHost(intent.one());
    Host two = hostService.getHost(intent.two());
    return Arrays.asList(createLinkCollectionIntent(pathOne, one, two, intent), createLinkCollectionIntent(pathTwo, two, one, intent));
}
Also used : DefaultPath(org.onosproject.net.DefaultPath) Path(org.onosproject.net.Path) Host(org.onosproject.net.Host) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint)

Example 7 with Path

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

the class HostToHostIntentCompiler method createLinkCollectionIntent.

private Intent createLinkCollectionIntent(Path path, Host src, Host dst, HostToHostIntent intent) {
    // Try to allocate bandwidth
    List<ConnectPoint> pathCPs = path.links().stream().flatMap(l -> Stream.of(l.src(), l.dst())).collect(Collectors.toList());
    allocateBandwidth(intent, pathCPs);
    Link ingressLink = path.links().get(0);
    Link egressLink = path.links().get(path.links().size() - 1);
    FilteredConnectPoint ingressPoint = getFilteredPointFromLink(ingressLink);
    FilteredConnectPoint egressPoint = getFilteredPointFromLink(egressLink);
    TrafficSelector selector = builder(intent.selector()).matchEthSrc(src.mac()).matchEthDst(dst.mac()).build();
    /*
         * The path contains also the edge links, these are not necessary
         * for the LinkCollectionIntent.
         */
    Set<Link> coreLinks = path.links().stream().filter(link -> !link.type().equals(EDGE)).collect(Collectors.toSet());
    return LinkCollectionIntent.builder().key(intent.key()).appId(intent.appId()).selector(selector).treatment(intent.treatment()).links(coreLinks).filteredIngressPoints(ImmutableSet.of(ingressPoint)).filteredEgressPoints(ImmutableSet.of(egressPoint)).applyTreatmentOnEgress(true).constraints(intent.constraints()).priority(intent.priority()).resourceGroup(intent.resourceGroup()).build();
}
Also used : Arrays(java.util.Arrays) Host(org.onosproject.net.Host) AsymmetricPathConstraint(org.onosproject.net.intent.constraint.AsymmetricPathConstraint) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) HostService(org.onosproject.net.host.HostService) ConnectPoint(org.onosproject.net.ConnectPoint) ArrayList(java.util.ArrayList) Component(org.osgi.service.component.annotations.Component) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DefaultPath(org.onosproject.net.DefaultPath) Intent(org.onosproject.net.intent.Intent) Activate(org.osgi.service.component.annotations.Activate) DefaultLink(org.onosproject.net.DefaultLink) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) HostToHostIntent(org.onosproject.net.intent.HostToHostIntent) Deactivate(org.osgi.service.component.annotations.Deactivate) Set(java.util.Set) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) DefaultTrafficSelector.builder(org.onosproject.net.flow.DefaultTrafficSelector.builder) Collectors(java.util.stream.Collectors) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) EDGE(org.onosproject.net.Link.Type.EDGE) Path(org.onosproject.net.Path) Reference(org.osgi.service.component.annotations.Reference) DeviceId(org.onosproject.net.DeviceId) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 8 with Path

use of org.onosproject.net.Path 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 9 with Path

use of org.onosproject.net.Path 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 10 with Path

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

Path (org.onosproject.net.Path)60 DeviceId (org.onosproject.net.DeviceId)27 DefaultPath (org.onosproject.net.DefaultPath)24 Link (org.onosproject.net.Link)23 DisjointPath (org.onosproject.net.DisjointPath)22 ConnectPoint (org.onosproject.net.ConnectPoint)18 Test (org.junit.Test)16 ImmutableSet (com.google.common.collect.ImmutableSet)12 ArrayList (java.util.ArrayList)11 List (java.util.List)11 Set (java.util.Set)11 Collectors (java.util.stream.Collectors)10 DefaultLink (org.onosproject.net.DefaultLink)10 Intent (org.onosproject.net.intent.Intent)10 Collections (java.util.Collections)9 Topology (org.onosproject.net.topology.Topology)8 Logger (org.slf4j.Logger)8 Stream (java.util.stream.Stream)7 ScalarWeight (org.onlab.graph.ScalarWeight)7 HostId (org.onosproject.net.HostId)7