Search in sources :

Example 1 with ModTunnelIdInstruction

use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction in project onos by opennetworkinglab.

the class Ofdpa3Pipeline method processFilter.

@Override
protected void processFilter(FilteringObjective filteringObjective, boolean install, ApplicationId applicationId) {
    // Check if filter is intended for pseudowire
    boolean isPw = isPseudowire(filteringObjective);
    if (isPw) {
        FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
        PortCriterion portCriterion;
        VlanIdCriterion innerVlanIdCriterion = null;
        for (Criterion criterion : filteringObjective.conditions()) {
            if (criterion.type() == INNER_VLAN_VID) {
                innerVlanIdCriterion = (VlanIdCriterion) criterion;
                break;
            }
        }
        VlanIdCriterion outerVlanIdCriterion = null;
        // We extract the expected port criterion in the key.
        portCriterion = (PortCriterion) filteringObjective.key();
        // We extract the outer vlan id criterion.
        for (Criterion criterion : filteringObjective.conditions()) {
            if (criterion.type() == VLAN_VID) {
                outerVlanIdCriterion = (VlanIdCriterion) criterion;
                break;
            }
        }
        // We extract the tunnel id.
        long tunnelId;
        VlanId egressVlan;
        if (filteringObjective.meta() != null && filteringObjective.meta().allInstructions().size() != 2) {
            log.warn("Bad filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
            fail(filteringObjective, ObjectiveError.BADPARAMS);
            return;
        } else if (filteringObjective.meta() != null && filteringObjective.meta().allInstructions().size() == 2 && filteringObjective.meta().allInstructions().get(0).type() == L2MODIFICATION && filteringObjective.meta().allInstructions().get(1).type() == L2MODIFICATION) {
            L2ModificationInstruction l2instruction = (L2ModificationInstruction) filteringObjective.meta().allInstructions().get(0);
            if (l2instruction.subtype() != L2SubType.TUNNEL_ID) {
                log.warn("Bad filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
                fail(filteringObjective, ObjectiveError.BADPARAMS);
                return;
            } else {
                tunnelId = ((ModTunnelIdInstruction) l2instruction).tunnelId();
            }
            L2ModificationInstruction vlanInstruction = (L2ModificationInstruction) filteringObjective.meta().allInstructions().get(1);
            if (vlanInstruction.subtype() != L2SubType.VLAN_ID) {
                log.warn("Bad filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
                fail(filteringObjective, ObjectiveError.BADPARAMS);
                return;
            } else {
                egressVlan = ((L2ModificationInstruction.ModVlanIdInstruction) vlanInstruction).vlanId();
            }
        } else {
            log.warn("Bad filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
            fail(filteringObjective, ObjectiveError.BADPARAMS);
            return;
        }
        // Mpls tunnel ids according to the OFDPA manual have to be
        // in the range [2^17-1, 2^16].
        tunnelId = MPLS_TUNNEL_ID_BASE | tunnelId;
        // Sanity check for the filtering objective.
        if (portCriterion == null || outerVlanIdCriterion == null || tunnelId > MPLS_TUNNEL_ID_MAX) {
            log.warn("Bad filtering objective from app: {}. Not" + "processing filtering objective", applicationId);
            fail(filteringObjective, ObjectiveError.BADPARAMS);
            return;
        }
        // 0x0000XXXX is UNI interface.
        if (portCriterion.port().toLong() > MPLS_UNI_PORT_MAX) {
            log.error("Filtering Objective invalid logical port {}", portCriterion.port().toLong());
            fail(filteringObjective, ObjectiveError.BADPARAMS);
            return;
        }
        // We create the flows.
        List<FlowRule> pwRules = processPwFilter(portCriterion, innerVlanIdCriterion, outerVlanIdCriterion, tunnelId, applicationId, egressVlan);
        // We tag the flow for adding or for removing.
        for (FlowRule pwRule : pwRules) {
            log.debug("adding filtering rule in VLAN tables: {} for dev: {}", pwRule, deviceId);
            ops = install ? ops.add(pwRule) : ops.remove(pwRule);
        }
        // We push the filtering rules for the pw.
        flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

            @Override
            public void onSuccess(FlowRuleOperations ops) {
                log.info("Applied {} filtering rules in device {}", ops.stages().get(0).size(), deviceId);
                pass(filteringObjective);
            }

            @Override
            public void onError(FlowRuleOperations ops) {
                log.info("Failed to apply all filtering rules in dev {}", deviceId);
                fail(filteringObjective, ObjectiveError.FLOWINSTALLATIONFAILED);
            }
        }));
    } else if (isDoubleTagged(filteringObjective)) {
        processDoubleTaggedFilter(filteringObjective, install, applicationId);
    } else {
        // If it is not a pseudo wire flow or double-tagged filter, we fall back
        // to the OFDPA 2.0 pipeline.
        super.processFilter(filteringObjective, install, applicationId);
    }
}
Also used : ModTunnelIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) VlanId(org.onlab.packet.VlanId) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 2 with ModTunnelIdInstruction

use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction in project onos by opennetworkinglab.

the class FlowModBuilderVer13 method buildL2Modification.

protected OFAction buildL2Modification(Instruction i) {
    L2ModificationInstruction l2m = (L2ModificationInstruction) i;
    ModEtherInstruction eth;
    OFOxm<?> oxm = null;
    switch(l2m.subtype()) {
        case ETH_DST:
            eth = (ModEtherInstruction) l2m;
            oxm = factory().oxms().ethDst(MacAddress.of(eth.mac().toLong()));
            break;
        case ETH_SRC:
            eth = (ModEtherInstruction) l2m;
            oxm = factory().oxms().ethSrc(MacAddress.of(eth.mac().toLong()));
            break;
        case VLAN_ID:
            ModVlanIdInstruction vlanId = (ModVlanIdInstruction) l2m;
            oxm = factory().oxms().vlanVid(OFVlanVidMatch.ofVlan(vlanId.vlanId().toShort()));
            break;
        case VLAN_PCP:
            ModVlanPcpInstruction vlanPcp = (ModVlanPcpInstruction) l2m;
            oxm = factory().oxms().vlanPcp(VlanPcp.of(vlanPcp.vlanPcp()));
            break;
        case MPLS_PUSH:
            ModMplsHeaderInstruction pushHeaderInstructions = (ModMplsHeaderInstruction) l2m;
            return factory().actions().pushMpls(EthType.of(pushHeaderInstructions.ethernetType().toShort()));
        case MPLS_POP:
            ModMplsHeaderInstruction popHeaderInstructions = (ModMplsHeaderInstruction) l2m;
            return factory().actions().popMpls(EthType.of(popHeaderInstructions.ethernetType().toShort()));
        case MPLS_LABEL:
            ModMplsLabelInstruction mplsLabel = (ModMplsLabelInstruction) l2m;
            oxm = factory().oxms().mplsLabel(U32.of(mplsLabel.label().toInt()));
            break;
        case MPLS_BOS:
            ModMplsBosInstruction mplsBos = (ModMplsBosInstruction) l2m;
            oxm = factory().oxms().mplsBos(mplsBos.mplsBos() ? OFBooleanValue.TRUE : OFBooleanValue.FALSE);
            break;
        case DEC_MPLS_TTL:
            return factory().actions().decMplsTtl();
        case VLAN_POP:
            return factory().actions().popVlan();
        case VLAN_PUSH:
            ModVlanHeaderInstruction pushVlanInstruction = (ModVlanHeaderInstruction) l2m;
            return factory().actions().pushVlan(EthType.of(pushVlanInstruction.ethernetType().toShort()));
        case TUNNEL_ID:
            ModTunnelIdInstruction tunnelId = (ModTunnelIdInstruction) l2m;
            oxm = factory().oxms().tunnelId(U64.of(tunnelId.tunnelId()));
            break;
        default:
            log.warn("Unimplemented action type {}.", l2m.subtype());
            break;
    }
    if (oxm != null) {
        return factory().actions().buildSetField().setField(oxm).build();
    }
    return null;
}
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) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) ModVlanHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanHeaderInstruction) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) ModMplsHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction) ModVlanPcpInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction)

Example 3 with ModTunnelIdInstruction

use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction 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 4 with ModTunnelIdInstruction

use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction in project onos by opennetworkinglab.

the class Ofdpa3Pipeline method processVersatile.

@Override
protected Collection<FlowRule> processVersatile(ForwardingObjective fwd) {
    // We use the tunnel id to identify pw related flows.
    // Looking for the fwd objective of the initiation.
    TunnelIdCriterion tunnelIdCriterion = (TunnelIdCriterion) fwd.selector().getCriterion(TUNNEL_ID);
    if (tunnelIdCriterion != null) {
        return processInitPwVersatile(fwd);
    }
    // Looking for the fwd objective of the termination.
    ModTunnelIdInstruction modTunnelIdInstruction = getModTunnelIdInstruction(fwd.treatment());
    OutputInstruction outputInstruction = getOutputInstruction(fwd.treatment());
    if (modTunnelIdInstruction != null && outputInstruction != null) {
        return processTermPwVersatile(fwd, modTunnelIdInstruction, outputInstruction);
    }
    // to the OFDPA 2.0 pipeline.
    return super.processVersatile(fwd);
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ModTunnelIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion)

Aggregations

ModTunnelIdInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction)4 TunnelIdCriterion (org.onosproject.net.flow.criteria.TunnelIdCriterion)2 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)2 ModEtherInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction)2 ModMplsBosInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction)2 ModMplsLabelInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction)2 ModVlanIdInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction)2 ModVlanPcpInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction)2 VlanId (org.onlab.packet.VlanId)1 DefaultFlowRule (org.onosproject.net.flow.DefaultFlowRule)1 FlowRule (org.onosproject.net.flow.FlowRule)1 FlowRuleOperations (org.onosproject.net.flow.FlowRuleOperations)1 FlowRuleOperationsContext (org.onosproject.net.flow.FlowRuleOperationsContext)1 Criterion (org.onosproject.net.flow.criteria.Criterion)1 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)1 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)1 VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)1 OutputInstruction (org.onosproject.net.flow.instructions.Instructions.OutputInstruction)1 ModMplsHeaderInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction)1 ModVlanHeaderInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanHeaderInstruction)1