use of org.onlab.util.Identifier 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.onlab.util.Identifier 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.onlab.util.Identifier in project onos by opennetworkinglab.
the class LabelAllocator method minSwapBehavior.
// Implements MIN_SWAP behavior
private Map<LinkKey, Identifier<?>> minSwapBehavior(Set<LinkKey> links, EncapsulationType type) {
// Init step
Map<LinkKey, Identifier<?>> ids = Maps.newHashMap();
Set<Identifier<?>> candidates;
Identifier<?> selected = null;
// Iterates for each link selecting a label in the candidate set
for (LinkKey link : links) {
// Get candidates set for the current link
candidates = getCandidates(link, type);
// If we are in the first link or selected is not available
if (selected == null || !candidates.contains(selected)) {
// Select a label for the current link
selected = labelSelection.select(candidates);
// If candidates is empty, selected is null
if (selected == null) {
log.warn("No labels for {}", link);
return Collections.emptyMap();
}
}
// Selected is associated to link
ids.put(link, selected);
}
return ids;
}
use of org.onlab.util.Identifier in project onos by opennetworkinglab.
the class LabelAllocator method noOptimizeBehavior.
// Implements NONE behavior
private Map<LinkKey, Identifier<?>> noOptimizeBehavior(Set<LinkKey> links, EncapsulationType type) {
// Init step
Map<LinkKey, Identifier<?>> ids = Maps.newHashMap();
Set<Identifier<?>> candidates;
Identifier<?> selected;
// Iterates for each link selecting a label in the candidate set
for (LinkKey link : links) {
// Get candidates set for the current link
candidates = getCandidates(link, type);
// Select a label for the current link
selected = labelSelection.select(candidates);
// If candidates is empty, selected is null
if (selected == null) {
log.warn("No labels for {}", link);
return Collections.emptyMap();
}
// Selected is associated to link
ids.put(link, selected);
}
return ids;
}
use of org.onlab.util.Identifier in project onos by opennetworkinglab.
the class LabelAllocator method suggestedIdentifierBehavior.
// Implements suggestedIdentifier behavior
private Map<LinkKey, Identifier<?>> suggestedIdentifierBehavior(Set<LinkKey> links, EncapsulationType type, Identifier<?> suggested) {
// Init step
Map<LinkKey, Identifier<?>> ids = Maps.newHashMap();
Set<Identifier<?>> candidates;
Identifier<?> selected = null;
// Select the suggested if available on the whole path
for (LinkKey link : links) {
// Get candidates set for the current link
candidates = getCandidates(link, type);
// Otherwise select an other label for the current link
if (candidates.contains(suggested)) {
selected = suggested;
} else {
// If candidates is empty or does not contain suggested
log.warn("Suggested label {} is not available on link {}", suggested, link);
return Collections.emptyMap();
}
// Selected is associated to link
ids.put(link, selected);
}
return ids;
}
Aggregations