Search in sources :

Example 1 with ModMplsLabelInstruction

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

the class InstructionJsonMatcher method matchModMplsLabelInstruction.

/**
 * Matches the contents of a mod MPLS label instruction.
 *
 * @param instructionJson JSON instruction to match
 * @param description Description object used for recording errors
 * @return true if contents match, false otherwise
 */
private boolean matchModMplsLabelInstruction(JsonNode instructionJson, Description description) {
    ModMplsLabelInstruction instructionToMatch = (ModMplsLabelInstruction) instruction;
    final String jsonSubtype = instructionJson.get("subtype").textValue();
    if (!instructionToMatch.subtype().name().equals(jsonSubtype)) {
        description.appendText("subtype was " + jsonSubtype);
        return false;
    }
    final String jsonType = instructionJson.get("type").textValue();
    if (!instructionToMatch.type().name().equals(jsonType)) {
        description.appendText("type was " + jsonType);
        return false;
    }
    final int jsonLabel = instructionJson.get("label").intValue();
    final int label = instructionToMatch.label().toInt();
    if (label != jsonLabel) {
        description.appendText("MPLS label was " + jsonLabel);
        return false;
    }
    return true;
}
Also used : ModMplsLabelInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction) HexString(org.onlab.util.HexString)

Example 2 with ModMplsLabelInstruction

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

the class InstructionJsonMatcher method matchesSafely.

@Override
public boolean matchesSafely(JsonNode jsonInstruction, Description description) {
    // check type
    final JsonNode jsonTypeNode = jsonInstruction.get("type");
    final String jsonType = jsonTypeNode.textValue();
    final String type = instruction.type().name();
    if (!jsonType.equals(type)) {
        description.appendText("type was " + type);
        return false;
    }
    if (instruction instanceof ModMplsHeaderInstruction) {
        return matchModMplsHeaderInstruction(jsonInstruction, description);
    } else if (instruction instanceof OutputInstruction) {
        return matchOutputInstruction(jsonInstruction, description);
    } else if (instruction instanceof GroupInstruction) {
        return matchGroupInstruction(jsonInstruction, description);
    } else if (instruction instanceof MeterInstruction) {
        return matchMeterInstruction(jsonInstruction, description);
    } else if (instruction instanceof SetQueueInstruction) {
        return matchSetQueueInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModOchSignalInstruction) {
        return matchModOchSingalInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModEtherInstruction) {
        return matchModEtherInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModVlanIdInstruction) {
        return matchModVlanIdInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModVlanPcpInstruction) {
        return matchModVlanPcpInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModIPInstruction) {
        return matchModIpInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModIPv6FlowLabelInstruction) {
        return matchModIPv6FlowLabelInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModMplsLabelInstruction) {
        return matchModMplsLabelInstruction(jsonInstruction, description);
    } else if (instruction instanceof ModOduSignalIdInstruction) {
        return matchModOduSingalIdInstruction(jsonInstruction, description);
    } else if (instruction instanceof PiInstruction) {
        return matchPiInstruction(jsonInstruction, description);
    } else if (instruction instanceof NoActionInstruction) {
        return true;
    }
    return false;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ModOchSignalInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction.ModOchSignalInstruction) PiInstruction(org.onosproject.net.flow.instructions.PiInstruction) JsonNode(com.fasterxml.jackson.databind.JsonNode) HexString(org.onlab.util.HexString) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) ModMplsHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModOduSignalIdInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction.ModOduSignalIdInstruction) SetQueueInstruction(org.onosproject.net.flow.instructions.Instructions.SetQueueInstruction) ModMplsLabelInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) MeterInstruction(org.onosproject.net.flow.instructions.Instructions.MeterInstruction) ModIPv6FlowLabelInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction) GroupInstruction(org.onosproject.net.flow.instructions.Instructions.GroupInstruction) ModVlanPcpInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction)

Example 3 with ModMplsLabelInstruction

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

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

the class NextObjectiveTranslator method nextMpls.

private void nextMpls(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    // Next objective can contain only one mpls push and one mpls label
    // instruction. Pipeliner does not support other configurations.
    final List<List<ModMplsLabelInstruction>> mplsInstructions = defaultNextTreatments(obj.nextTreatments(), false).stream().map(defaultNextTreatment -> l2Instructions(defaultNextTreatment.treatment(), MPLS_LABEL).stream().map(v -> (ModMplsLabelInstruction) v).collect(Collectors.toList())).filter(l -> !l.isEmpty()).collect(Collectors.toList());
    if (mplsInstructions.isEmpty()) {
        // No need to apply next mpls table
        return;
    }
    // We expect one mpls label for each treatment and the label has to be the same
    final Set<MplsLabel> mplsLabels = mplsInstructions.stream().flatMap(Collection::stream).map(ModMplsLabelInstruction::label).collect(Collectors.toSet());
    if (obj.nextTreatments().size() != mplsInstructions.size() || mplsLabels.size() != 1) {
        throw new FabricPipelinerException("Inconsistent MPLS_LABEL instructions, cannot process " + "next_mpls rule. It is required that all " + "treatments have the same MPLS_LABEL instructions.");
    }
    final TrafficSelector selector = nextIdSelector(obj.id());
    final TrafficTreatment treatment = DefaultTrafficTreatment.builder().setMpls(mplsLabels.iterator().next()).build();
    resultBuilder.addFlowRule(flowRule(obj, FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_MPLS, selector, treatment));
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PortNumber(org.onosproject.net.PortNumber) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) FabricUtils.l2Instructions(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2Instructions) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) NextObjective(org.onosproject.net.flowobjective.NextObjective) FabricUtils.l2Instruction(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.l2Instruction) MPLS_LABEL(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.MPLS_LABEL) Collection(java.util.Collection) Set(java.util.Set) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) PiGroupKey(org.onosproject.net.pi.runtime.PiGroupKey) Collectors(java.util.stream.Collectors) String.format(java.lang.String.format) Objects(java.util.Objects) List(java.util.List) FabricUtils.outputPort(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.outputPort) GroupBuckets(org.onosproject.net.group.GroupBuckets) DeviceId(org.onosproject.net.DeviceId) DefaultGroupDescription(org.onosproject.net.group.DefaultGroupDescription) GroupDescription(org.onosproject.net.group.GroupDescription) PiActionProfileGroupId(org.onosproject.net.pi.runtime.PiActionProfileGroupId) VLAN_POP(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_POP) ModMplsLabelInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction) NextTreatment(org.onosproject.net.flowobjective.NextTreatment) DefaultNextTreatment(org.onosproject.net.flowobjective.DefaultNextTreatment) GroupBucket(org.onosproject.net.group.GroupBucket) GroupKey(org.onosproject.net.group.GroupKey) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) VLAN_ID(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_ID) FabricUtils(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) FabricCapabilities(org.onosproject.pipelines.fabric.impl.behaviour.FabricCapabilities) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MplsLabel(org.onlab.packet.MplsLabel) Instruction(org.onosproject.net.flow.instructions.Instruction) FabricUtils.criterion(org.onosproject.pipelines.fabric.impl.behaviour.FabricUtils.criterion) VlanId(org.onlab.packet.VlanId) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PiAction(org.onosproject.net.pi.runtime.PiAction) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) MplsLabel(org.onlab.packet.MplsLabel) Collection(java.util.Collection) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) List(java.util.List) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 5 with ModMplsLabelInstruction

use of org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction 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)

Aggregations

ModMplsLabelInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction)5 ModVlanIdInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction)4 ModEtherInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction)3 ModVlanPcpInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction)3 HexString (org.onlab.util.HexString)2 ModMplsBosInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction)2 ModMplsHeaderInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction)2 ModTunnelIdInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Lists (com.google.common.collect.Lists)1 String.format (java.lang.String.format)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Objects (java.util.Objects)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 MplsLabel (org.onlab.packet.MplsLabel)1 VlanId (org.onlab.packet.VlanId)1 DeviceId (org.onosproject.net.DeviceId)1