Search in sources :

Example 6 with IntentCompilationException

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);
    }
}
Also used : IpPrefix(org.onlab.packet.IpPrefix) ModArpEthInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction) ModIPv6FlowLabelInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) ModArpOpInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModArpIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction)

Example 7 with IntentCompilationException

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)));
}
Also used : IntentData(org.onosproject.net.intent.IntentData) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Test(org.junit.Test) AbstractIntentTest(org.onosproject.net.intent.AbstractIntentTest)

Example 8 with IntentCompilationException

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);
    }
}
Also used : MplsLabel(org.onlab.packet.MplsLabel) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) VlanId(org.onlab.packet.VlanId)

Example 9 with IntentCompilationException

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);
    }
}
Also used : ModMplsLabelInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction) ModTunnelIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction) ModMplsBosInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) ModVlanPcpInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction)

Example 10 with IntentCompilationException

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();
}
Also used : DomainId(org.onosproject.net.domain.DomainId) ImmutableList(com.google.common.collect.ImmutableList) DeviceId(org.onosproject.net.DeviceId) DomainPointToPointIntent(org.onosproject.net.domain.DomainPointToPointIntent) Intent(org.onosproject.net.intent.Intent) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Aggregations

IntentCompilationException (org.onosproject.net.intent.IntentCompilationException)14 ConnectPoint (org.onosproject.net.ConnectPoint)7 DeviceId (org.onosproject.net.DeviceId)7 VlanId (org.onlab.packet.VlanId)6 Link (org.onosproject.net.Link)6 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)6 TrafficSelector (org.onosproject.net.flow.TrafficSelector)6 Intent (org.onosproject.net.intent.Intent)6 LinkCollectionIntent (org.onosproject.net.intent.LinkCollectionIntent)6 List (java.util.List)5 Set (java.util.Set)5 MplsLabel (org.onlab.packet.MplsLabel)5 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)5 Sets (com.google.common.collect.Sets)4 Map (java.util.Map)4 Optional (java.util.Optional)4 EthType (org.onlab.packet.EthType)4 Ethernet (org.onlab.packet.Ethernet)4 Identifier (org.onlab.util.Identifier)4 EncapsulationType (org.onosproject.net.EncapsulationType)4