use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class LinkCollectionCompiler method generateEgressActions.
/**
* Helper method to generate the egress actions.
*
* @param treatmentBuilder the treatment builder to update
* @param egressPoints the egress points
* @param initialState the initial state of the transition
*/
private void generateEgressActions(TrafficTreatment.Builder treatmentBuilder, List<FilteredConnectPoint> egressPoints, TrafficSelector initialState, LinkCollectionIntent intent) {
TrafficSelector prevState = initialState;
for (FilteredConnectPoint egressPoint : egressPoints) {
/*
* If we are at the egress, we have to transit to the final
* state. First we add the Intent treatment.
*/
intent.treatment().allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
/*
* We generate the transition FIP->FEP.
*/
TrafficTreatment forwardingTreatment = forwardingTreatment(prevState, egressPoint.trafficSelector(), getEthType(intent.selector()));
/*
* We add the instruction necessary to the transition.
* Potentially we override the intent treatment.
*/
forwardingTreatment.allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
/*
* Finally we set the output action.
*/
treatmentBuilder.setOutput(egressPoint.connectPoint().port());
if (optimizeTreatments()) {
/*
* We update the previous state. In this way instead of
* transiting from FIP->FEP we do FEP->FEP and so on.
*/
prevState = egressPoint.trafficSelector();
}
}
}
use of org.onosproject.net.intent.Intent in project onos by opennetworkinglab.
the class LinkCollectionIntentFlowObjectiveCompiler method buildFilteringObjective.
private FilteringObjective buildFilteringObjective(LinkCollectionIntent intent, TrafficSelector selector, DeviceId deviceId, PortNumber inPort) {
FilteringObjective.Builder builder = DefaultFilteringObjective.builder();
builder.fromApp(appId).permit().makePermanent().withPriority(intent.priority());
Criterion inPortCriterion = selector.getCriterion(Criterion.Type.IN_PORT);
if (inPortCriterion != null) {
builder.withKey(inPortCriterion);
}
FilteredConnectPoint ingressPoint = intent.filteredIngressPoints().stream().filter(fcp -> fcp.connectPoint().equals(new ConnectPoint(deviceId, inPort))).filter(fcp -> selector.criteria().containsAll(fcp.trafficSelector().criteria())).findFirst().orElse(null);
AtomicBoolean emptyCondition = new AtomicBoolean(true);
if (ingressPoint != null) {
// ingress point, use criterion of it
ingressPoint.trafficSelector().criteria().forEach(criterion -> {
builder.addCondition(criterion);
emptyCondition.set(false);
});
if (emptyCondition.get()) {
return null;
}
return builder.add();
}
Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
if (encapConstraint.isPresent() && !encapConstraint.get().encapType().equals(EncapsulationType.NONE)) {
// encapsulation enabled, use encapsulation label and tag.
EncapsulationConstraint encap = encapConstraint.get();
switch(encap.encapType()) {
case VLAN:
builder.addCondition(selector.getCriterion(Criterion.Type.VLAN_VID));
emptyCondition.set(false);
break;
case MPLS:
builder.addCondition(selector.getCriterion(Criterion.Type.MPLS_LABEL));
emptyCondition.set(false);
break;
default:
log.warn("No filtering rule found because of unknown encapsulation type.");
break;
}
} else {
// encapsulation not enabled, check if the treatment applied to the ingress or not
if (intent.applyTreatmentOnEgress()) {
// filtering criterion will be changed on egress point, use
// criterion of ingress point
ingressPoint = intent.filteredIngressPoints().stream().findFirst().orElse(null);
if (ingressPoint == null) {
log.warn("No filtering rule found because no ingress point in the Intent");
} else {
ingressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
builder.addCondition(criterion);
emptyCondition.set(false);
});
}
} else {
// filtering criterion will be changed on ingress point, use
// criterion of egress point
FilteredConnectPoint egressPoint = intent.filteredEgressPoints().stream().findFirst().orElse(null);
if (egressPoint == null) {
log.warn("No filtering rule found because no egress point in the Intent");
} else {
egressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
builder.addCondition(criterion);
emptyCondition.set(false);
});
}
}
}
if (emptyCondition.get()) {
return null;
}
return builder.add();
}
use of org.onosproject.net.intent.Intent 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.intent.Intent 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.intent.Intent 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));
}
}
Aggregations