use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class IntentPerfInstaller method createIntent.
private Intent createIntent(Key key, long mac, NodeId node, Multimap<NodeId, Device> devices) {
// choose a random device for which this node is master
List<Device> deviceList = devices.get(node).stream().collect(Collectors.toList());
Device device = deviceList.get(RandomUtils.nextInt(deviceList.size()));
// FIXME we currently ignore the path length and always use the same device
TrafficSelector selector = DefaultTrafficSelector.builder().matchEthDst(MacAddress.valueOf(mac)).build();
TrafficTreatment treatment = DefaultTrafficTreatment.emptyTreatment();
ConnectPoint ingress = new ConnectPoint(device.id(), PortNumber.portNumber(1));
ConnectPoint egress = new ConnectPoint(device.id(), PortNumber.portNumber(2));
return PointToPointIntent.builder().appId(appId).key(key).selector(selector).treatment(treatment).filteredIngressPoint(new FilteredConnectPoint(ingress)).filteredEgressPoint(new FilteredConnectPoint(egress)).build();
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class TestProtectionEndpointIntentCommand method output.
private FilteredConnectPoint output(DeviceId did, String portNumberStr, String vlanStr) {
ConnectPoint cp = new ConnectPoint(did, PortNumber.fromString(portNumberStr));
if (deviceService.getPort(cp) == null) {
print("Unknown port: %s", cp);
}
if (vlanStr == null) {
return new FilteredConnectPoint(cp);
} else {
VlanId vlan = VlanId.vlanId(vlanStr);
TrafficSelector sel = DefaultTrafficSelector.builder().matchVlanId(vlan).build();
return new FilteredConnectPoint(cp, sel);
}
}
use of org.onosproject.net.flow.TrafficSelector in project onos by opennetworkinglab.
the class LinkCollectionCompiler method manageSpIntent.
/**
* Manages the Intents with a single ingress point (p2p, sp2mp)
* 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 deviceId the current device
* @param outPorts the output ports of this device
*/
private void manageSpIntent(TrafficSelector.Builder selectorBuilder, TrafficTreatment.Builder treatmentBuilder, LinkCollectionIntent intent, DeviceId deviceId, Set<PortNumber> outPorts) {
/*
* Sanity check.
*/
if (intent.filteredIngressPoints().size() != 1) {
throw new IntentCompilationException(WRONG_INGRESS);
}
/*
* For the p2p and sp2mp the transition initial state
* to final state is performed at the egress.
*/
Optional<FilteredConnectPoint> filteredIngressPoint = intent.filteredIngressPoints().stream().findFirst();
/*
* 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);
/*
* In this scenario, potentially we can have several output
* ports. First we have to insert in the treatment the actions
* for the core.
*/
List<FilteredConnectPoint> egressPoints = Lists.newArrayList();
for (PortNumber outPort : outPorts) {
Optional<FilteredConnectPoint> filteredEgressPoint = getFilteredConnectPointFromIntent(deviceId, outPort, intent);
if (!filteredEgressPoint.isPresent()) {
treatmentBuilder.setOutput(outPort);
} 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 ingress
* point then the others.
*/
TrafficSelector prevState = filteredIngressPoint.get().trafficSelector();
if (optimizeTreatments()) {
egressPoints = orderedEgressPoints(prevState, egressPoints);
}
/*
* Then we deal with the egress points.
*/
generateEgressActions(treatmentBuilder, egressPoints, prevState, intent);
}
use of org.onosproject.net.flow.TrafficSelector 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.flow.TrafficSelector 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);
}
Aggregations