use of org.onosproject.net.flow.instructions.Instruction 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.flow.instructions.Instruction in project onos by opennetworkinglab.
the class LinkCollectionIntentCompiler method compactActions.
/**
* This method tries to optimize the chain of actions.
*
* @param oldTreatment the list of instructions to optimize
* @return the optimized set of actions
*/
private TrafficTreatment compactActions(TrafficTreatment oldTreatment) {
TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
Instruction instruction;
Instruction newInstruction;
for (int index = 0; index < oldTreatment.allInstructions().size(); index++) {
instruction = oldTreatment.allInstructions().get(index);
/*
* if the action is not optimizable. We simply add
* to the builder.
*/
if (checkInstruction(instruction)) {
treatmentBuilder.add(instruction);
continue;
}
/*
* We try to run an optimization;
*/
newInstruction = optimizeInstruction(index, instruction, oldTreatment.allInstructions());
if (!newInstruction.type().equals(NOACTION)) {
treatmentBuilder.add(newInstruction);
}
}
return treatmentBuilder.build();
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class PointToPointIntentCompiler method updateFailoverGroup.
// Removes buckets whose treatments rely on disabled ports from the
// failover group.
private void updateFailoverGroup(PointToPointIntent pointIntent) {
DeviceId deviceId = pointIntent.filteredIngressPoint().connectPoint().deviceId();
GroupKey groupKey = makeGroupKey(pointIntent.id());
Group group = waitForGroup(deviceId, groupKey);
Iterator<GroupBucket> groupIterator = group.buckets().buckets().iterator();
while (groupIterator.hasNext()) {
GroupBucket bucket = groupIterator.next();
Instruction individualInstruction = bucket.treatment().allInstructions().get(0);
if (individualInstruction instanceof Instructions.OutputInstruction) {
Instructions.OutputInstruction outInstruction = (Instructions.OutputInstruction) individualInstruction;
Port port = deviceService.getPort(deviceId, outInstruction.port());
if (port == null || !port.isEnabled()) {
GroupBuckets removeBuckets = new GroupBuckets(Collections.singletonList(bucket));
groupService.removeBucketsFromGroup(deviceId, groupKey, removeBuckets, groupKey, pointIntent.appId());
}
}
}
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class FlowObjectiveCompositionManager method forwardingObjectiveToString.
public static String forwardingObjectiveToString(ForwardingObjective forwardingObjective) {
String str = forwardingObjective.priority() + " ";
str += "selector( ";
for (Criterion criterion : forwardingObjective.selector().criteria()) {
str += criterion + " ";
}
str += ") treatment( ";
for (Instruction instruction : forwardingObjective.treatment().allInstructions()) {
str += instruction + " ";
}
str += ")";
return str;
}
use of org.onosproject.net.flow.instructions.Instruction in project onos by opennetworkinglab.
the class OplinkPowerConfigUtil method setChannelAttenuation.
/**
* Sets specified channle attenuation.
*
* @param portNum the port number
* @param och channel signal
* @param power attenuation in 0.01 dB
*/
private void setChannelAttenuation(PortNumber portNum, OchSignal och, long power) {
FlowEntry flowEntry = findFlow(portNum, och);
if (flowEntry == null) {
log.warn("Target channel power not set");
return;
}
final DriverHandler handler = behaviour.handler();
for (Instruction ins : flowEntry.treatment().allInstructions()) {
if (ins.type() != Instruction.Type.EXTENSION) {
continue;
}
ExtensionTreatment ext = ((Instructions.ExtensionInstructionWrapper) ins).extensionInstruction();
if (ext.type() == ExtensionTreatmentType.ExtensionTreatmentTypes.OPLINK_ATTENUATION.type()) {
((OplinkAttenuation) ext).setAttenuation((int) power);
FlowRuleService service = handler.get(FlowRuleService.class);
service.applyFlowRules(flowEntry);
return;
}
}
addAttenuation(flowEntry, power);
}
Aggregations