Search in sources :

Example 76 with ConnectPoint

use of org.onosproject.net.ConnectPoint 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 77 with ConnectPoint

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

the class ProtectionConfigMonitor method updateProtection.

private void updateProtection(DeviceId did, ProtectionConfig before, ProtectionConfig after) {
    ProtectedTransportEndpointDescription description = after.asDescription();
    log.info("updating protection {}-{}", did, description);
    ProtectionConfigBehaviour behaviour = getBehaviour(did);
    Optional<ConnectPoint> existing = findFirstVirtualPort(behaviour, after.fingerprint());
    if (!existing.isPresent()) {
        log.warn("Update requested, but not found, falling back as add");
        addProtection(did, after);
        return;
    }
    ConnectPoint vPort = existing.get();
    log.info("updating protection virtual Port {} : {}", vPort, description);
    behaviour.updateProtectionEndpoint(vPort, description).handle((vPortNew, e) -> {
        if (vPort != null) {
            log.info("Virtual Port {} updated for {}", vPort, description);
            log.debug("{}", deviceService.getPort(vPort));
        } else {
            log.error("Protection {} -> {} exceptionally failed.", before, after, e);
        }
        return vPort;
    });
}
Also used : ProtectionConfigBehaviour(org.onosproject.net.behaviour.protection.ProtectionConfigBehaviour) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 78 with ConnectPoint

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

the class ProtectionConfigMonitor method addProtection.

private void addProtection(DeviceId did, ProtectionConfig added) {
    ProtectedTransportEndpointDescription description = added.asDescription();
    log.info("adding protection {}-{}", did, description);
    ProtectionConfigBehaviour behaviour = getBehaviour(did);
    CompletableFuture<ConnectPoint> result;
    result = behaviour.createProtectionEndpoint(description);
    result.handle((vPort, e) -> {
        if (vPort != null) {
            log.info("Virtual Port {} created for {}", vPort, description);
            log.debug("{}", deviceService.getPort(vPort));
        } else {
            log.error("Protection {} exceptionally failed.", added, e);
        }
        return vPort;
    });
}
Also used : ProtectionConfigBehaviour(org.onosproject.net.behaviour.protection.ProtectionConfigBehaviour) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 79 with ConnectPoint

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

the class ProtectionConfigMonitor method removeProtection.

private void removeProtection(DeviceId did, ProtectionConfig removed) {
    ProtectedTransportEndpointDescription description = removed.asDescription();
    log.info("removing protection {}-{}", did, description);
    ProtectionConfigBehaviour behaviour = getBehaviour(did);
    Optional<ConnectPoint> existing = findFirstVirtualPort(behaviour, removed.fingerprint());
    if (!existing.isPresent()) {
        log.warn("Remove requested, but not found, ignoring");
        return;
    }
    ConnectPoint vPort = existing.get();
    log.info("removing protection virtual port {} : {}", vPort, description);
    behaviour.deleteProtectionEndpoint(vPort).handle((result, ex) -> {
        if (ex != null) {
            log.info("removed protection {} : {}", vPort, result);
        } else {
            log.warn("removed protection {} failed.", vPort, ex);
        }
        return result;
    });
}
Also used : ProtectionConfigBehaviour(org.onosproject.net.behaviour.protection.ProtectionConfigBehaviour) ProtectedTransportEndpointDescription(org.onosproject.net.behaviour.protection.ProtectedTransportEndpointDescription) ConnectPoint(org.onosproject.net.ConnectPoint)

Example 80 with ConnectPoint

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

the class ConnectivityIntentCompiler method allocateBandwidth.

/**
 * Allocates the bandwidth specified as intent constraint on each link
 * composing the intent, if a bandwidth constraint is specified.
 *
 * @param intent the intent requesting bandwidth allocation
 * @param connectPoints the connect points composing the intent path computed
 */
protected void allocateBandwidth(ConnectivityIntent intent, List<ConnectPoint> connectPoints) {
    // Retrieve bandwidth constraint if exists
    List<Constraint> constraints = intent.constraints();
    if (constraints == null) {
        return;
    }
    Optional<Constraint> constraint = constraints.stream().filter(c -> c instanceof BandwidthConstraint).findAny();
    // If there is no bandwidth constraint continue
    if (!constraint.isPresent()) {
        return;
    }
    BandwidthConstraint bwConstraint = (BandwidthConstraint) constraint.get();
    double bw = bwConstraint.bandwidth().bps();
    // If a resource group is set on the intent, the resource consumer is
    // set equal to it. Otherwise it's set to the intent key
    ResourceConsumer newResourceConsumer = intent.resourceGroup() != null ? intent.resourceGroup() : intent.key();
    // Get the list of current resource allocations
    Collection<ResourceAllocation> resourceAllocations = resourceService.getResourceAllocations(newResourceConsumer);
    // Get the list of resources already allocated from resource allocations
    List<Resource> resourcesAllocated = resourcesFromAllocations(resourceAllocations);
    // Get the list of resource ids for resources already allocated
    List<ResourceId> idsResourcesAllocated = resourceIds(resourcesAllocated);
    // Create the list of incoming resources requested. Exclude resources
    // already allocated.
    List<Resource> incomingResources = resources(connectPoints, bw).stream().filter(r -> !resourcesAllocated.contains(r)).collect(Collectors.toList());
    if (incomingResources.isEmpty()) {
        return;
    }
    // Create the list of resources to be added, meaning their key is not
    // present in the resources already allocated
    List<Resource> resourcesToAdd = incomingResources.stream().filter(r -> !idsResourcesAllocated.contains(r.id())).collect(Collectors.toList());
    // Resources to updated are all the new valid resources except the
    // resources to be added
    List<Resource> resourcesToUpdate = Lists.newArrayList(incomingResources);
    resourcesToUpdate.removeAll(resourcesToAdd);
    // If there are no resources to update skip update procedures
    if (!resourcesToUpdate.isEmpty()) {
        // Remove old resources that need to be updated
        // TODO: use transaction updates when available in the resource service
        List<ResourceAllocation> resourceAllocationsToUpdate = resourceAllocations.stream().filter(rA -> resourceIds(resourcesToUpdate).contains(rA.resource().id())).collect(Collectors.toList());
        log.debug("Releasing bandwidth for intent {}: {} bps", newResourceConsumer, resourcesToUpdate);
        resourceService.release(resourceAllocationsToUpdate);
        // Update resourcesToAdd with the list of both the new resources and
        // the resources to update
        resourcesToAdd.addAll(resourcesToUpdate);
    }
    // remove them
    if (intent.resourceGroup() != null) {
        // Get the list of current resource allocations made by intent key
        Collection<ResourceAllocation> resourceAllocationsByKey = resourceService.getResourceAllocations(intent.key());
        resourceService.release(Lists.newArrayList(resourceAllocationsByKey));
    }
    // Allocate resources
    log.debug("Allocating bandwidth for intent {}: {} bps", newResourceConsumer, resourcesToAdd);
    List<ResourceAllocation> allocations = resourceService.allocate(newResourceConsumer, resourcesToAdd);
    if (allocations.isEmpty()) {
        log.debug("No resources allocated for intent {}", newResourceConsumer);
    }
    log.debug("Done allocating bandwidth for intent {}", newResourceConsumer);
}
Also used : HashedPathSelectionConstraint(org.onosproject.net.intent.constraint.HashedPathSelectionConstraint) TopologyEdge(org.onosproject.net.topology.TopologyEdge) DeviceService(org.onosproject.net.device.DeviceService) LoggerFactory(org.slf4j.LoggerFactory) ElementId(org.onosproject.net.ElementId) ResourceService(org.onosproject.net.resource.ResourceService) ConnectPoint(org.onosproject.net.ConnectPoint) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) FluentIterable(com.google.common.collect.FluentIterable) PathNotFoundException(org.onosproject.net.intent.impl.PathNotFoundException) PathViabilityConstraint(org.onosproject.net.intent.constraint.PathViabilityConstraint) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) Bandwidth(org.onlab.util.Bandwidth) IntentExtensionService(org.onosproject.net.intent.IntentExtensionService) Resources(org.onosproject.net.resource.Resources) PathService(org.onosproject.net.topology.PathService) Collection(java.util.Collection) Set(java.util.Set) ProviderId(org.onosproject.net.provider.ProviderId) Resource(org.onosproject.net.resource.Resource) Collectors(java.util.stream.Collectors) Constraint(org.onosproject.net.intent.Constraint) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) DefaultEdgeWeigher(org.onlab.graph.DefaultEdgeWeigher) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) List(java.util.List) Weight(org.onlab.graph.Weight) ResourceId(org.onosproject.net.resource.ResourceId) TopologyVertex(org.onosproject.net.topology.TopologyVertex) ConnectivityIntent(org.onosproject.net.intent.ConnectivityIntent) IntentCompiler(org.onosproject.net.intent.IntentCompiler) Optional(java.util.Optional) Path(org.onosproject.net.Path) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) LinkWeigher(org.onosproject.net.topology.LinkWeigher) Reference(org.osgi.service.component.annotations.Reference) ScalarWeight(org.onlab.graph.ScalarWeight) DeviceId(org.onosproject.net.DeviceId) Collections(java.util.Collections) DisjointPath(org.onosproject.net.DisjointPath) MarkerConstraint(org.onosproject.net.intent.constraint.MarkerConstraint) HashedPathSelectionConstraint(org.onosproject.net.intent.constraint.HashedPathSelectionConstraint) PathViabilityConstraint(org.onosproject.net.intent.constraint.PathViabilityConstraint) Constraint(org.onosproject.net.intent.Constraint) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint) MarkerConstraint(org.onosproject.net.intent.constraint.MarkerConstraint) Resource(org.onosproject.net.resource.Resource) ResourceConsumer(org.onosproject.net.resource.ResourceConsumer) ResourceAllocation(org.onosproject.net.resource.ResourceAllocation) ResourceId(org.onosproject.net.resource.ResourceId) BandwidthConstraint(org.onosproject.net.intent.constraint.BandwidthConstraint)

Aggregations

ConnectPoint (org.onosproject.net.ConnectPoint)536 Test (org.junit.Test)149 DeviceId (org.onosproject.net.DeviceId)125 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)91 Link (org.onosproject.net.Link)88 Set (java.util.Set)86 PortNumber (org.onosproject.net.PortNumber)86 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)83 VlanId (org.onlab.packet.VlanId)78 TrafficSelector (org.onosproject.net.flow.TrafficSelector)75 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)72 Logger (org.slf4j.Logger)71 Port (org.onosproject.net.Port)70 List (java.util.List)69 Ethernet (org.onlab.packet.Ethernet)69 DeviceService (org.onosproject.net.device.DeviceService)67 Collectors (java.util.stream.Collectors)66 MacAddress (org.onlab.packet.MacAddress)64 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)64 Intent (org.onosproject.net.intent.Intent)62