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