Search in sources :

Example 1 with VLAN_ID

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

the class NextObjectiveTranslator method nextVlan.

private void nextVlan(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    // We expect NextObjective treatments to contain one or two VLAN instructions.
    // If two, this treatment should be mapped to an action for double-vlan push.
    // In fabric.p4, mapping next IDs to VLAN IDs is done by a direct table (next_vlan),
    // for this reason, we also make sure that all treatments in the NextObjective
    // have exactly the same VLAN instructions, as they will be mapped to a single action
    // Try to extract VLAN instructions in the treatment,
    // later we check if we support multiple VLAN termination.
    final List<List<ModVlanIdInstruction>> vlanInstructions = defaultNextTreatments(obj.nextTreatments(), false).stream().map(defaultNextTreatment -> l2Instructions(defaultNextTreatment.treatment(), VLAN_ID).stream().map(v -> (ModVlanIdInstruction) v).collect(Collectors.toList())).filter(l -> !l.isEmpty()).collect(Collectors.toList());
    final VlanIdCriterion vlanIdCriterion = obj.meta() == null ? null : (VlanIdCriterion) criterion(obj.meta().criteria(), Criterion.Type.VLAN_VID);
    final List<VlanId> vlanIdList;
    if (vlanInstructions.isEmpty() && vlanIdCriterion == null) {
        // No VLAN_ID to apply.
        return;
    }
    if (!vlanInstructions.isEmpty()) {
        // Give priority to what found in the instructions.
        // Expect the same VLAN ID (or two VLAN IDs in the same order) for all instructions.
        final Set<List<VlanId>> vlanIds = vlanInstructions.stream().map(l -> l.stream().map(ModVlanIdInstruction::vlanId).collect(Collectors.toList())).collect(Collectors.toSet());
        if (obj.nextTreatments().size() != vlanInstructions.size() || vlanIds.size() != 1) {
            throw new FabricPipelinerException("Inconsistent VLAN_ID instructions, cannot process " + "next_vlan rule. It is required that all " + "treatments have the same VLAN_ID instructions.");
        }
        vlanIdList = vlanIds.iterator().next();
    } else {
        // Use the value in meta.
        // FIXME: there should be no need to generate a next_vlan rule for
        // the value found in meta. Meta describes the fields that were
        // expected to be matched in previous pipeline stages, i.e.
        // existing packet fields. But, for some reason, if we remove this
        // rule, traffic is not forwarded at spines. We might need to look
        // at the way default VLANs are handled in fabric.p4.
        vlanIdList = List.of(vlanIdCriterion.vlanId());
    }
    final TrafficSelector selector = nextIdSelector(obj.id());
    final TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    vlanIdList.stream().forEach(vlanId -> treatmentBuilder.setVlanId(vlanId));
    final TrafficTreatment treatment = treatmentBuilder.build();
    resultBuilder.addFlowRule(flowRule(obj, FabricConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN, 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) 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) VlanId(org.onlab.packet.VlanId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 2 with VLAN_ID

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

the class CorsaPipelineV39 method processNextTreatment.

@Override
protected CorsaTrafficTreatment processNextTreatment(TrafficTreatment treatment) {
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    treatment.immediate().stream().filter(i -> {
        switch(i.type()) {
            case L2MODIFICATION:
                L2ModificationInstruction l2i = (L2ModificationInstruction) i;
                return l2i.subtype() == VLAN_ID || l2i.subtype() == VLAN_POP || l2i.subtype() == ETH_DST || l2i.subtype() == ETH_SRC;
            case OUTPUT:
                return true;
            default:
                return false;
        }
    }).forEach(i -> tb.add(i));
    TrafficTreatment t = tb.build();
    boolean isPresentModVlanId = false;
    boolean isPresentModEthSrc = false;
    boolean isPresentModEthDst = false;
    boolean isPresentOutpuPort = false;
    for (Instruction instruction : t.immediate()) {
        switch(instruction.type()) {
            case L2MODIFICATION:
                L2ModificationInstruction l2i = (L2ModificationInstruction) instruction;
                if (l2i instanceof L2ModificationInstruction.ModVlanIdInstruction) {
                    isPresentModVlanId = true;
                }
                if (l2i instanceof L2ModificationInstruction.ModEtherInstruction) {
                    L2ModificationInstruction.L2SubType subType = l2i.subtype();
                    if (subType.equals(L2ModificationInstruction.L2SubType.ETH_SRC)) {
                        isPresentModEthSrc = true;
                    } else if (subType.equals(L2ModificationInstruction.L2SubType.ETH_DST)) {
                        isPresentModEthDst = true;
                    }
                }
                break;
            case OUTPUT:
                isPresentOutpuPort = true;
                break;
            default:
        }
    }
    CorsaTrafficTreatmentType type = CorsaTrafficTreatmentType.ACTIONS;
    /**
     * These are the allowed groups for CorsaPipelinev39
     */
    if (isPresentModVlanId && isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) {
        type = CorsaTrafficTreatmentType.GROUP;
    } else if ((!isPresentModVlanId && isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) || (!isPresentModVlanId && !isPresentModEthSrc && isPresentModEthDst && isPresentOutpuPort) || (!isPresentModVlanId && !isPresentModEthSrc && !isPresentModEthDst && isPresentOutpuPort)) {
        type = CorsaTrafficTreatmentType.GROUP;
        TrafficTreatment.Builder tb2 = DefaultTrafficTreatment.builder(t);
        tb2.add(Instructions.popVlan());
        t = tb2.build();
    }
    CorsaTrafficTreatment corsaTreatment = new CorsaTrafficTreatment(type, t);
    return corsaTreatment;
}
Also used : VLAN_POP(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_POP) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) ETH_DST(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.ETH_DST) IPProtocolCriterion(org.onosproject.net.flow.criteria.IPProtocolCriterion) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) VLAN_ID(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_ID) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Instructions(org.onosproject.net.flow.instructions.Instructions) ImmutableSet(com.google.common.collect.ImmutableSet) Logger(org.slf4j.Logger) Instruction(org.onosproject.net.flow.instructions.Instruction) Collection(java.util.Collection) VlanId(org.onlab.packet.VlanId) ETH_SRC(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.ETH_SRC) IPv4(org.onlab.packet.IPv4) Builder(org.onosproject.net.flow.FlowRule.Builder) FlowRule(org.onosproject.net.flow.FlowRule) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Collections(java.util.Collections) Builder(org.onosproject.net.flow.FlowRule.Builder) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction)

Example 3 with VLAN_ID

use of org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_ID in project fabric-tna by stratum.

the class NextObjectiveTranslator method nextVlan.

private void nextVlan(NextObjective obj, ObjectiveTranslation.Builder resultBuilder) throws FabricPipelinerException {
    // We expect NextObjective treatments to contain one or two VLAN instructions.
    // If two, this treatment should be mapped to an action for double-vlan push.
    // In fabric.p4, mapping next IDs to VLAN IDs is done by a direct table (next_vlan),
    // for this reason, we also make sure that all treatments in the NextObjective
    // have exactly the same VLAN instructions, as they will be mapped to a single action
    // Try to extract VLAN instructions in the treatment,
    // later we check if we support multiple VLAN termination.
    final List<List<ModVlanIdInstruction>> vlanInstructions = defaultNextTreatments(obj.nextTreatments(), false).stream().map(defaultNextTreatment -> l2Instructions(defaultNextTreatment.treatment(), VLAN_ID).stream().map(v -> (ModVlanIdInstruction) v).collect(Collectors.toList())).filter(l -> !l.isEmpty()).collect(Collectors.toList());
    final VlanIdCriterion vlanIdCriterion = obj.meta() == null ? null : (VlanIdCriterion) criterion(obj.meta().criteria(), Criterion.Type.VLAN_VID);
    final List<VlanId> vlanIdList;
    if (vlanInstructions.isEmpty() && vlanIdCriterion == null) {
        // No VLAN_ID to apply.
        return;
    }
    if (!vlanInstructions.isEmpty()) {
        // Give priority to what found in the instructions.
        // Expect the same VLAN ID (or two VLAN IDs in the same order) for all instructions.
        final Set<List<VlanId>> vlanIds = vlanInstructions.stream().map(l -> l.stream().map(ModVlanIdInstruction::vlanId).collect(Collectors.toList())).collect(Collectors.toSet());
        if (obj.nextTreatments().size() != vlanInstructions.size() || vlanIds.size() != 1) {
            throw new FabricPipelinerException("Inconsistent VLAN_ID instructions, cannot process " + "next_vlan rule. It is required that all " + "treatments have the same VLAN_ID instructions.");
        }
        vlanIdList = vlanIds.iterator().next();
    } else {
        // Use the value in meta.
        // FIXME: there should be no need to generate a next_vlan rule for
        // the value found in meta. Meta describes the fields that were
        // expected to be matched in previous pipeline stages, i.e.
        // existing packet fields. But, for some reason, if we remove this
        // rule, traffic is not forwarded at spines. We might need to look
        // at the way default VLANs are handled in fabric.p4.
        vlanIdList = List.of(vlanIdCriterion.vlanId());
    }
    final TrafficSelector selector = nextIdSelector(obj.id());
    final TrafficTreatment.Builder treatmentBuilder = DefaultTrafficTreatment.builder();
    vlanIdList.forEach(treatmentBuilder::setVlanId);
    final TrafficTreatment treatment = treatmentBuilder.build();
    resultBuilder.addFlowRule(flowRule(obj, P4InfoConstants.FABRIC_INGRESS_PRE_NEXT_NEXT_VLAN, selector, treatment));
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) FabricUtils.criterion(org.stratumproject.fabric.tna.behaviour.FabricUtils.criterion) FabricUtils.l2Instruction(org.stratumproject.fabric.tna.behaviour.FabricUtils.l2Instruction) 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.outputPort(org.stratumproject.fabric.tna.behaviour.FabricUtils.outputPort) PiCriterion(org.onosproject.net.flow.criteria.PiCriterion) NextObjective(org.onosproject.net.flowobjective.NextObjective) MPLS_LABEL(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.MPLS_LABEL) FabricCapabilities(org.stratumproject.fabric.tna.behaviour.FabricCapabilities) FabricUtils(org.stratumproject.fabric.tna.behaviour.FabricUtils) 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) 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) FabricUtils.l2Instructions(org.stratumproject.fabric.tna.behaviour.FabricUtils.l2Instructions) 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) P4InfoConstants(org.stratumproject.fabric.tna.behaviour.P4InfoConstants) 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) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MplsLabel(org.onlab.packet.MplsLabel) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) DefaultGroupBucket(org.onosproject.net.group.DefaultGroupBucket) PiAction(org.onosproject.net.pi.runtime.PiAction) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) KRYO(org.stratumproject.fabric.tna.behaviour.FabricUtils.KRYO) Objective(org.onosproject.net.flowobjective.Objective) Collections(java.util.Collections) 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) VlanId(org.onlab.packet.VlanId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Aggregations

Collection (java.util.Collection)3 Collections (java.util.Collections)3 VlanId (org.onlab.packet.VlanId)3 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)3 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)3 TrafficSelector (org.onosproject.net.flow.TrafficSelector)3 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)3 Criterion (org.onosproject.net.flow.criteria.Criterion)3 Instruction (org.onosproject.net.flow.instructions.Instruction)3 VLAN_ID (org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_ID)3 VLAN_POP (org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType.VLAN_POP)3 ObjectiveError (org.onosproject.net.flowobjective.ObjectiveError)3 Lists (com.google.common.collect.Lists)2 String.format (java.lang.String.format)2 List (java.util.List)2 Objects (java.util.Objects)2 Set (java.util.Set)2 Collectors (java.util.stream.Collectors)2 MplsLabel (org.onlab.packet.MplsLabel)2 DeviceId (org.onosproject.net.DeviceId)2