use of org.onosproject.net.intent.IntentCompilationException 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.intent.IntentCompilationException 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.intent.IntentCompilationException 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.intent.IntentCompilationException in project onos by opennetworkinglab.
the class LinkCollectionCompiler method updateBuilder.
/**
* Update the selector builder using a L3 instruction.
*
* @param builder the builder to update
* @param l3instruction the l3 instruction to use
*/
private void updateBuilder(TrafficSelector.Builder builder, L3ModificationInstruction l3instruction) {
// TODO check ethernet proto
switch(l3instruction.subtype()) {
case IPV4_SRC:
case IPV4_DST:
case IPV6_SRC:
case IPV6_DST:
ModIPInstruction ipInstr = (ModIPInstruction) l3instruction;
// TODO check if ip falls in original prefix
IpPrefix prefix = ipInstr.ip().toIpPrefix();
switch(ipInstr.subtype()) {
case IPV4_SRC:
builder.matchIPSrc(prefix);
break;
case IPV4_DST:
builder.matchIPSrc(prefix);
break;
case IPV6_SRC:
builder.matchIPv6Src(prefix);
break;
case IPV6_DST:
builder.matchIPv6Dst(prefix);
break;
default:
throw new IntentCompilationException(UNSUPPORTED_IP_SUBTYPE);
}
break;
case IPV6_FLABEL:
ModIPv6FlowLabelInstruction ipFlowInstr = (ModIPv6FlowLabelInstruction) l3instruction;
builder.matchIPv6FlowLabel(ipFlowInstr.flowLabel());
break;
case DEC_TTL:
// no-op
break;
case TTL_OUT:
// no-op
break;
case TTL_IN:
// no-op
break;
case ARP_SPA:
ModArpIPInstruction srcArpIpInstr = (ModArpIPInstruction) l3instruction;
if (srcArpIpInstr.ip().isIp4()) {
builder.matchArpSpa((Ip4Address) srcArpIpInstr.ip());
} else {
throw new IntentCompilationException(UNSUPPORTED_ARP);
}
break;
case ARP_SHA:
ModArpEthInstruction srcArpEthInstr = (ModArpEthInstruction) l3instruction;
builder.matchArpSha(srcArpEthInstr.mac());
break;
case ARP_TPA:
ModArpIPInstruction dstArpIpInstr = (ModArpIPInstruction) l3instruction;
if (dstArpIpInstr.ip().isIp4()) {
builder.matchArpTpa((Ip4Address) dstArpIpInstr.ip());
} else {
throw new IntentCompilationException(UNSUPPORTED_ARP);
}
break;
case ARP_THA:
ModArpEthInstruction dstArpEthInstr = (ModArpEthInstruction) l3instruction;
builder.matchArpTha(dstArpEthInstr.mac());
break;
case ARP_OP:
ModArpOpInstruction arpOpInstr = (ModArpOpInstruction) l3instruction;
// FIXME is the long to int cast safe?
builder.matchArpOp((int) arpOpInstr.op());
break;
default:
throw new IntentCompilationException(UNSUPPORTED_L3);
}
}
use of org.onosproject.net.intent.IntentCompilationException in project onos by opennetworkinglab.
the class ProtectedTransportIntentCompiler method createFreshProtectedPaths.
/**
* Creates new protected paths.
*
* @param intent original intention
* @param did1 identifier of first device
* @param did2 identifier of second device
* @return compilation result
* @throws IntentCompilationException when there's no satisfying path.
*/
private List<Intent> createFreshProtectedPaths(ProtectedTransportIntent intent, DeviceId did1, DeviceId did2) {
DisjointPath disjointPath = getDisjointPath(intent, did1, did2);
if (disjointPath == null || disjointPath.backup() == null) {
log.error("Unable to find disjoint path between {}, {}", did1, did2);
throw new IntentCompilationException("Unable to find disjoint paths.");
}
Path primary = disjointPath.primary();
Path secondary = disjointPath.backup();
String fingerprint = intent.key().toString();
// pick and allocate Vlan to use as S-tag
Pair<VlanId, VlanId> vlans = allocateEach(intent, primary, secondary, VlanId.class);
VlanId primaryVlan = vlans.getLeft();
VlanId secondaryVlan = vlans.getRight();
// Build edge Intents for head/tail
// resource for head/tail
Collection<NetworkResource> oneResources = new ArrayList<>();
Collection<NetworkResource> twoResources = new ArrayList<>();
List<TransportEndpointDescription> onePaths = new ArrayList<>();
onePaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(primary.src(), primaryVlan)).build());
onePaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(secondary.src(), secondaryVlan)).build());
List<TransportEndpointDescription> twoPaths = new ArrayList<>();
twoPaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(primary.dst(), primaryVlan)).build());
twoPaths.add(TransportEndpointDescription.builder().withOutput(vlanPort(secondary.dst(), secondaryVlan)).build());
ProtectionEndpointIntent oneIntent = ProtectionEndpointIntent.builder().key(intent.key()).appId(intent.appId()).priority(intent.priority()).resources(oneResources).deviceId(did1).description(buildDescription(onePaths, did2, fingerprint)).build();
ProtectionEndpointIntent twoIntent = ProtectionEndpointIntent.builder().key(intent.key()).appId(intent.appId()).resources(twoResources).deviceId(did2).description(buildDescription(twoPaths, did1, fingerprint)).build();
// Build transit intent for primary/secondary path
Collection<NetworkResource> resources1 = ImmutableList.of(marker("protection1"));
Collection<NetworkResource> resources2 = ImmutableList.of(marker("protection2"));
ImmutableList<Intent> result = ImmutableList.<Intent>builder().addAll(createTransitIntent(intent, primary, primaryVlan, resources1)).addAll(createTransitIntent(intent, secondary, secondaryVlan, resources2)).add(oneIntent).add(twoIntent).build();
log.trace("createFreshProtectedPaths result: {}", result);
return result;
}
Aggregations