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);
}
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;
});
}
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;
});
}
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;
});
}
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);
}
Aggregations