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 CompilingTest method testWhenIntentCompilationExceptionOccurs.
/**
* Tests a next phase when IntentCompilationException occurs.
*/
@Test
public void testWhenIntentCompilationExceptionOccurs() {
IntentData pending = new IntentData(input, INSTALL_REQ, version);
expect(processor.compile(input, null)).andThrow(new IntentCompilationException());
replay(processor);
Compiling sut = new Compiling(processor, pending, Optional.empty());
Optional<IntentProcessPhase> output = sut.execute();
verify(processor);
assertThat(output.get(), is(instanceOf(Failed.class)));
}
use of org.onosproject.net.intent.IntentCompilationException in project onos by opennetworkinglab.
the class LinkCollectionCompiler method updateSelectorFromEncapsulation.
/**
* The method generates a selector starting from
* the encapsulation information (type and label to match).
*
* @param selectorBuilder the builder to update
* @param type the type of encapsulation
* @param identifier the label to match
*/
private void updateSelectorFromEncapsulation(TrafficSelector.Builder selectorBuilder, EncapsulationType type, Identifier<?> identifier) {
switch(type) {
case MPLS:
MplsLabel label = (MplsLabel) identifier;
selectorBuilder.matchMplsLabel(label);
selectorBuilder.matchEthType(Ethernet.MPLS_UNICAST);
break;
case VLAN:
VlanId id = (VlanId) identifier;
selectorBuilder.matchVlanId(id);
break;
default:
throw new IntentCompilationException(UNKNOWN_ENCAPSULATION);
}
}
use of org.onosproject.net.intent.IntentCompilationException in project onos by opennetworkinglab.
the class LinkCollectionCompiler method updateBuilder.
/**
* Update the selector builder using a L2 instruction.
*
* @param builder the builder to update
* @param l2instruction the l2 instruction to use
*/
private void updateBuilder(TrafficSelector.Builder builder, L2ModificationInstruction l2instruction) {
switch(l2instruction.subtype()) {
case ETH_SRC:
case ETH_DST:
ModEtherInstruction ethInstr = (ModEtherInstruction) l2instruction;
switch(ethInstr.subtype()) {
case ETH_SRC:
builder.matchEthSrc(ethInstr.mac());
break;
case ETH_DST:
builder.matchEthDst(ethInstr.mac());
break;
default:
throw new IntentCompilationException(UNSUPPORTED_ETH_SUBTYPE);
}
break;
case VLAN_ID:
ModVlanIdInstruction vlanIdInstr = (ModVlanIdInstruction) l2instruction;
builder.matchVlanId(vlanIdInstr.vlanId());
break;
case VLAN_PUSH:
// FIXME
break;
case VLAN_POP:
// TODO how do we handle dropped label? remove the selector?
throw new IntentCompilationException(UNSUPPORTED_POP_ACTION);
case VLAN_PCP:
ModVlanPcpInstruction vlanPcpInstruction = (ModVlanPcpInstruction) l2instruction;
builder.matchVlanPcp(vlanPcpInstruction.vlanPcp());
break;
case MPLS_LABEL:
case MPLS_PUSH:
// FIXME
ModMplsLabelInstruction mplsInstr = (ModMplsLabelInstruction) l2instruction;
builder.matchMplsLabel(mplsInstr.label());
break;
case MPLS_POP:
// TODO how do we handle dropped label? remove the selector?
throw new IntentCompilationException(UNSUPPORTED_POP_ACTION);
case DEC_MPLS_TTL:
// no-op
break;
case MPLS_BOS:
ModMplsBosInstruction mplsBosInstr = (ModMplsBosInstruction) l2instruction;
builder.matchMplsBos(mplsBosInstr.mplsBos());
break;
case TUNNEL_ID:
ModTunnelIdInstruction tunInstr = (ModTunnelIdInstruction) l2instruction;
builder.matchTunnelId(tunInstr.tunnelId());
break;
default:
throw new IntentCompilationException(UNSUPPORTED_L2);
}
}
use of org.onosproject.net.intent.IntentCompilationException in project onos by opennetworkinglab.
the class LinkCollectionCompiler method getDomainIntents.
/**
* Creates the domain intents that the {@link LinkCollectionIntent} contains.
*
* @param intent the link collection intent
* @param domainService the domain service
* @return the resulting list of domain intents
*/
protected List<Intent> getDomainIntents(LinkCollectionIntent intent, DomainService domainService) {
ImmutableList.Builder<Intent> intentList = ImmutableList.builder();
// TODO: support multi point to multi point
if (intent.filteredIngressPoints().size() != 1 || intent.filteredEgressPoints().size() != 1) {
log.warn("Multiple ingress or egress ports not supported!");
return intentList.build();
}
ImmutableList.Builder<Link> domainLinks = ImmutableList.builder();
// get the initial ingress connection point
FilteredConnectPoint ingress = intent.filteredIngressPoints().iterator().next();
FilteredConnectPoint egress;
DeviceId currentDevice = ingress.connectPoint().deviceId();
// the current domain (or LOCAL)
DomainId currentDomain = domainService.getDomain(currentDevice);
// if we entered a domain store the domain ingress
FilteredConnectPoint domainIngress = LOCAL.equals(currentDomain) ? null : ingress;
// this is necessary because a set is not sorted by default
for (int i = 0; i < intent.links().size(); i++) {
// find the next link
List<Link> nextLinks = getEgressLinks(intent.links(), currentDevice);
// no matching link exists
if (nextLinks.isEmpty()) {
throw new IntentCompilationException("No matching link starting at " + ingress.connectPoint().deviceId());
}
// get the first link
Link nextLink = nextLinks.get(0);
ingress = new FilteredConnectPoint(nextLink.src());
egress = new FilteredConnectPoint(nextLink.dst());
// query the domain for the domain of the link's destination
DomainId dstDomain = domainService.getDomain(egress.connectPoint().deviceId());
if (!currentDomain.equals(dstDomain)) {
// we are leaving the current domain or LOCAL
log.debug("Domain transition from {} to {}.", currentDomain, dstDomain);
if (!LOCAL.equals(currentDomain)) {
// add the domain intent to the intent list
intentList.add(createDomainP2PIntent(intent, domainIngress, ingress, domainLinks.build()));
// TODO: might end up with an unused builder
// reset domain links builder
domainLinks = ImmutableList.builder();
}
// update current domain (might be LOCAL)
currentDomain = dstDomain;
// update the domain's ingress
domainIngress = LOCAL.equals(currentDomain) ? null : egress;
} else {
if (!LOCAL.equals(currentDomain)) {
// we are staying in the same domain, store the traversed link
domainLinks.add(nextLink);
log.debug("{} belongs to the same domain.", egress.connectPoint().deviceId());
}
}
currentDevice = egress.connectPoint().deviceId();
}
// get the egress point
egress = intent.filteredEgressPoints().iterator().next();
// still inside a domain?
if (!LOCAL.equals(currentDomain) && currentDomain.equals(domainService.getDomain(egress.connectPoint().deviceId()))) {
// add intent
intentList.add(createDomainP2PIntent(intent, domainIngress, egress, domainLinks.build()));
}
return intentList.build();
}
Aggregations