use of org.onosproject.net.flow.criteria.Criteria in project onos by opennetworkinglab.
the class OplinkOpticalUtility method fromFlowRule.
/**
* Transforms a flow FlowRule object to an OplinkCrossConnect object.
* @param behaviour the parent driver handler
* @param rule FlowRule object
* @return cross connect object
*/
public static OplinkCrossConnect fromFlowRule(HandlerBehaviour behaviour, FlowRule rule) {
// TrafficSelector
Set<Criterion> criterions = rule.selector().criteria();
int channel = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
PortNumber inPort = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
// TrafficTreatment
List<Instruction> instructions = rule.treatment().immediate();
PortNumber outPort = instructions.stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
int attenuation = instructions.stream().filter(c -> c instanceof Instructions.ExtensionInstructionWrapper).map(c -> ((Instructions.ExtensionInstructionWrapper) c).extensionInstruction()).filter(c -> c instanceof OplinkAttenuation).map(c -> ((OplinkAttenuation) c).getAttenuation()).findAny().orElse(DEFAULT_ATT);
return new OplinkCrossConnect(inPort, outPort, channel, attenuation);
}
use of org.onosproject.net.flow.criteria.Criteria in project onos by opennetworkinglab.
the class LinkCollectionCompiler method orderedEgressPoints.
/**
* Helper method to order the egress ports according to a
* specified criteria. The idea is to generate first the actions
* for the egress ports which are similar to the specified criteria
* then the others. In this way we can mitigate the problems related
* to the chain of actions and we can optimize also the number of
* actions.
*
* @param orderCriteria the ordering criteria
* @param pointsToOrder the egress points to order
* @return a list of port ordered
*/
private List<FilteredConnectPoint> orderedEgressPoints(TrafficSelector orderCriteria, List<FilteredConnectPoint> pointsToOrder) {
/*
* We are interested only to the labels. The idea is to order
* by the tags.
*
*/
Criterion vlanIdCriterion = orderCriteria.getCriterion(VLAN_VID);
Criterion mplsLabelCriterion = orderCriteria.getCriterion(MPLS_LABEL);
/*
* We collect all the untagged points.
*
*/
List<FilteredConnectPoint> untaggedEgressPoints = pointsToOrder.stream().filter(pointToOrder -> {
TrafficSelector selector = pointToOrder.trafficSelector();
return selector.getCriterion(VLAN_VID) == null && selector.getCriterion(MPLS_LABEL) == null;
}).collect(Collectors.toList());
/*
* We collect all the vlan points.
*/
List<FilteredConnectPoint> vlanEgressPoints = pointsToOrder.stream().filter(pointToOrder -> {
TrafficSelector selector = pointToOrder.trafficSelector();
return selector.getCriterion(VLAN_VID) != null && selector.getCriterion(MPLS_LABEL) == null;
}).collect(Collectors.toList());
/*
* We collect all the mpls points.
*/
List<FilteredConnectPoint> mplsEgressPoints = pointsToOrder.stream().filter(pointToOrder -> {
TrafficSelector selector = pointToOrder.trafficSelector();
return selector.getCriterion(VLAN_VID) == null && selector.getCriterion(MPLS_LABEL) != null;
}).collect(Collectors.toList());
/*
* We create the final list of ports.
*/
List<FilteredConnectPoint> orderedList = Lists.newArrayList();
/*
* The ordering criteria is vlan id. First we add the vlan
* ports. Then the others.
*/
if (vlanIdCriterion != null && mplsLabelCriterion == null) {
orderedList.addAll(vlanEgressPoints);
orderedList.addAll(untaggedEgressPoints);
orderedList.addAll(mplsEgressPoints);
return orderedList;
}
/*
* The ordering criteria is mpls label. First we add the mpls
* ports. Then the others.
*/
if (vlanIdCriterion == null && mplsLabelCriterion != null) {
orderedList.addAll(mplsEgressPoints);
orderedList.addAll(untaggedEgressPoints);
orderedList.addAll(vlanEgressPoints);
return orderedList;
}
/*
* The ordering criteria is untagged. First we add the untagged
* ports. Then the others.
*/
if (vlanIdCriterion == null) {
orderedList.addAll(untaggedEgressPoints);
orderedList.addAll(vlanEgressPoints);
orderedList.addAll(mplsEgressPoints);
return orderedList;
}
/*
* Unhandled scenario.
*/
orderedList.addAll(vlanEgressPoints);
orderedList.addAll(mplsEgressPoints);
orderedList.addAll(untaggedEgressPoints);
return orderedList;
}
use of org.onosproject.net.flow.criteria.Criteria in project onos by opennetworkinglab.
the class LinkCollectionCompiler method manageMpIntent.
/**
* Manages the Intents with multiple ingress points creating properly
* the selector builder and the treatment builder.
*
* @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 the current device
* @param deviceId the current device
* @param outPorts the output ports of this device
*/
private void manageMpIntent(TrafficSelector.Builder selectorBuilder, TrafficTreatment.Builder treatmentBuilder, LinkCollectionIntent intent, PortNumber inPort, DeviceId deviceId, Set<PortNumber> outPorts) {
/*
* Sanity check
*/
if (intent.filteredEgressPoints().size() != 1) {
throw new IntentCompilationException(WRONG_EGRESS);
}
/*
* We try to understand if the device is one of the ingress points.
*/
Optional<FilteredConnectPoint> filteredIngressPoint = getFilteredConnectPointFromIntent(deviceId, inPort, intent);
/*
* We retrieve from the Intent the unique egress points.
*/
Optional<FilteredConnectPoint> filteredEgressPoint = intent.filteredEgressPoints().stream().findFirst();
/*
* We check if the device is the ingress device
*/
if (filteredIngressPoint.isPresent()) {
/*
* We are at ingress, so basically what we have to do is this:
* apply a set of operations (treatment, FEP) in order to have
* a transition from the initial state to the final state.
*
* We initialize the treatment with the Intent treatment
*/
intent.treatment().allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
/*
* We build the final selector, adding the selector
* of the FIP to the Intent selector and potentially
* overriding its matches.
*/
filteredIngressPoint.get().trafficSelector().criteria().forEach(selectorBuilder::add);
/*
* We define the transition FIP->FEP, basically
* the set of the operations we need for reaching
* the final state.
*/
TrafficTreatment forwardingTreatment = forwardingTreatment(filteredIngressPoint.get().trafficSelector(), filteredEgressPoint.get().trafficSelector(), getEthType(intent.selector()));
/*
* We add to the treatment the actions necessary for the
* transition, potentially overriding the treatment of the
* Intent. The Intent treatment has always a low priority
* in respect of the FEP.
*/
forwardingTreatment.allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
} else {
/*
* We are in the core or in the egress switch.
* The packets are in their final state. We need
* to match against this final state.
*
* we derive the final state defined by the intent
* treatment.
*/
updateBuilder(selectorBuilder, intent.treatment());
/*
* We derive the final state defined by the unique
* FEP. We merge the two states.
*/
filteredEgressPoint.get().trafficSelector().criteria().forEach(selectorBuilder::add);
}
/*
* Finally we set the output action.
*/
outPorts.forEach(treatmentBuilder::setOutput);
}
use of org.onosproject.net.flow.criteria.Criteria in project onos by opennetworkinglab.
the class OplinkOpticalUtility method toFlowRule.
/**
* Finds the FlowRule from flow rule store by the given ports and channel.
* Returns an extra flow to remove the flow by ONOS if not found.
* @param behaviour the parent driver handler
* @param inPort the input port
* @param outPort the output port
* @param channel the specified channel
* @return the flow rule
*/
public static FlowRule toFlowRule(HandlerBehaviour behaviour, PortNumber inPort, PortNumber outPort, Integer channel) {
FlowRuleService service = behaviour.handler().get(FlowRuleService.class);
Iterable<FlowEntry> entries = service.getFlowEntries(behaviour.data().deviceId());
// Try to Find the flow from flow rule store.
for (FlowEntry entry : entries) {
Set<Criterion> criterions = entry.selector().criteria();
// input port
PortNumber ip = criterions.stream().filter(c -> c instanceof PortCriterion).map(c -> ((PortCriterion) c).port()).findAny().orElse(null);
// channel
Integer ch = criterions.stream().filter(c -> c instanceof OchSignalCriterion).map(c -> ((OchSignalCriterion) c).lambda().spacingMultiplier()).findAny().orElse(null);
// output port
PortNumber op = entry.treatment().immediate().stream().filter(c -> c instanceof Instructions.OutputInstruction).map(c -> ((Instructions.OutputInstruction) c).port()).findAny().orElse(null);
if (inPort.equals(ip) && channel.equals(ch) && outPort.equals(op)) {
// Find the flow.
return entry;
}
}
// Cannot find the flow from store. So report an extra flow to remove the flow by ONOS.
TrafficSelector selector = DefaultTrafficSelector.builder().matchInPort(inPort).add(Criteria.matchOchSignalType(OchSignalType.FIXED_GRID)).add(Criteria.matchLambda(Lambda.ochSignal(GRID_TYPE, CHANNEL_SPACING, channel, SLOT_GRANULARITY))).build();
TrafficTreatment treatment = DefaultTrafficTreatment.builder().setOutput(outPort).build();
return DefaultFlowRule.builder().forDevice(behaviour.data().deviceId()).withSelector(selector).withTreatment(treatment).withPriority(DEFAULT_PRIORITY).makePermanent().fromApp(behaviour.handler().get(CoreService.class).getAppId(DEFAULT_APP)).build();
}
Aggregations