use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class LinkCollectionCompiler method createForwardingInstruction.
/**
* Helper method to handle the different scenario (not encap, single hop, encap).
*
* @param encapConstraint the encapsulation constraint if it is present
* @param intent the link collection intent
* @param inPort the in port
* @param outPorts the out ports
* @param deviceId the current device
* @param labels the labels used by the encapsulation
* @return the forwarding instruction
*/
protected ForwardingInstructions createForwardingInstruction(Optional<EncapsulationConstraint> encapConstraint, LinkCollectionIntent intent, PortNumber inPort, Set<PortNumber> outPorts, DeviceId deviceId, Map<ConnectPoint, Identifier<?>> labels) {
ForwardingInstructions instructions = null;
/*
* If not encapsulation or single hop.
*/
if (!encapConstraint.isPresent() || intent.links().isEmpty()) {
instructions = this.createForwardingInstructions(intent, inPort, deviceId, outPorts);
/*
* If encapsulation is present. We retrieve the labels
* for this iteration;
*/
} else {
Identifier<?> inLabel = labels.get(new ConnectPoint(deviceId, inPort));
Map<ConnectPoint, Identifier<?>> outLabels = Maps.newHashMap();
outPorts.forEach(outPort -> {
ConnectPoint key = new ConnectPoint(deviceId, outPort);
outLabels.put(key, labels.get(key));
});
instructions = this.createForwardingInstructions(intent, inPort, inLabel, deviceId, outPorts, outLabels, encapConstraint.get().encapType());
}
return instructions;
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class LinkCollectionCompiler method manageEncapAtCoreAndEgress.
/**
* Manages the core and transit of the Intents (p2p, sp2mp, mp2sp)
* with encapsulation.
*
* @param selectorBuilder the selector builder to update
* @param treatmentBuilder the treatment builder to update
* @param intent the intent to compile
* @param inPort the input port of this device
* @param inLabel the label associated to the input port
* @param deviceId the current device
* @param outPorts the output ports of this device
* @param outLabels the labels associated to the output port
* @param type the encapsulation type
*/
private void manageEncapAtCoreAndEgress(TrafficSelector.Builder selectorBuilder, TrafficTreatment.Builder treatmentBuilder, LinkCollectionIntent intent, PortNumber inPort, Identifier<?> inLabel, DeviceId deviceId, Set<PortNumber> outPorts, Map<ConnectPoint, Identifier<?>> outLabels, EncapsulationType type) {
/*
* If there are not labels, we cannot handle.
*/
ConnectPoint inCp = new ConnectPoint(deviceId, inPort);
if (inLabel == null) {
throw new IntentCompilationException(String.format(NO_LABELS, inCp));
}
/*
* In the core and at egress we match using encapsulation.
*/
updateSelectorFromEncapsulation(selectorBuilder, type, inLabel);
/*
* Generate the output actions.
*/
manageOutputPorts(outPorts, deviceId, intent, outLabels, type, selectorBuilder, treatmentBuilder);
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class LinkCollectionCompiler method computePorts.
/**
* Helper method to compute input and output ports
* for each device crossed in the path.
*
* @param intent the related intents
* @param inputPorts the input ports to compute
* @param outputPorts the output ports to compute
*/
protected void computePorts(LinkCollectionIntent intent, SetMultimap<DeviceId, PortNumber> inputPorts, SetMultimap<DeviceId, PortNumber> outputPorts) {
for (Link link : intent.links()) {
inputPorts.put(link.dst().deviceId(), link.dst().port());
outputPorts.put(link.src().deviceId(), link.src().port());
}
for (ConnectPoint ingressPoint : intent.ingressPoints()) {
inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
}
for (ConnectPoint egressPoint : intent.egressPoints()) {
outputPorts.put(egressPoint.deviceId(), egressPoint.port());
}
}
use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.
the class LinkCollectionCompiler method manageOutputPorts.
/**
* Helper method which handles the proper generation of the ouput actions.
*
* @param outPorts the output ports
* @param deviceId the current device
* @param intent the intent to compile
* @param outLabels the output labels
* @param type the encapsulation type
* @param preCondition the previous state
* @param treatmentBuilder the builder to update with the ouput actions
*/
private void manageOutputPorts(Set<PortNumber> outPorts, DeviceId deviceId, LinkCollectionIntent intent, Map<ConnectPoint, Identifier<?>> outLabels, EncapsulationType type, TrafficSelector.Builder preCondition, TrafficTreatment.Builder treatmentBuilder) {
/*
* We need to order the actions. First the actions
* related to the not-egress points. At the same time we collect
* also the egress points.
*/
List<FilteredConnectPoint> egressPoints = Lists.newArrayList();
for (PortNumber outPort : outPorts) {
Optional<FilteredConnectPoint> filteredEgressPoint = getFilteredConnectPointFromIntent(deviceId, outPort, intent);
if (!filteredEgressPoint.isPresent()) {
/*
* We build a temporary selector for the encapsulation.
*/
TrafficSelector.Builder encapBuilder = DefaultTrafficSelector.builder();
/*
* We retrieve the associated label to the output port.
*/
ConnectPoint cp = new ConnectPoint(deviceId, outPort);
Identifier<?> outLabel = outLabels.get(cp);
/*
* If there are not labels, we cannot handle.
*/
if (outLabel == null) {
throw new IntentCompilationException(String.format(NO_LABELS, cp));
}
/*
* In the core we match using encapsulation.
*/
updateSelectorFromEncapsulation(encapBuilder, type, outLabel);
/*
* We generate the transition.
*/
TrafficTreatment forwardingTreatment = forwardingTreatment(preCondition.build(), encapBuilder.build(), getEthType(intent.selector()));
/*
* We add the instruction necessary to the transition.
*/
forwardingTreatment.allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
/*
* Finally we set the output action.
*/
treatmentBuilder.setOutput(outPort);
/*
* The encapsulation modifies the packet. If we are optimizing
* we have to update the state.
*/
if (optimizeTreatments()) {
preCondition = encapBuilder;
}
} else {
egressPoints.add(filteredEgressPoint.get());
}
}
/*
* The idea is to order the egress points. Before we deal
* with the egress points which looks like similar to the
* selector derived from the previous state then the
* the others.
*/
TrafficSelector prevState = preCondition.build();
if (optimizeTreatments()) {
egressPoints = orderedEgressPoints(prevState, egressPoints);
}
/*
* In this case, we have to transit to the final
* state.
*/
generateEgressActions(treatmentBuilder, egressPoints, prevState, intent);
}
use of org.onosproject.net.ConnectPoint 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();
}
Aggregations