Search in sources :

Example 56 with VlanIdCriterion

use of org.onosproject.net.flow.criteria.VlanIdCriterion in project onos by opennetworkinglab.

the class LinkCollectionCompiler method forwardingTreatment.

/**
 * Compares tag type between ingress and egress point and generate
 * treatment for egress point of intent.
 *
 * @param ingress ingress selector for the intent
 * @param egress egress selector for the intent
 * @param ethType the ethertype to use in mpls_pop
 * @return Builder of TrafficTreatment
 */
private TrafficTreatment forwardingTreatment(TrafficSelector ingress, TrafficSelector egress, EthType ethType) {
    if (ingress.equals(egress)) {
        return DefaultTrafficTreatment.emptyTreatment();
    }
    TrafficTreatment.Builder builder = DefaultTrafficTreatment.builder();
    /*
         * "null" means there is no tag for the port
         * Tag criterion will be null if port is normal connection point
         */
    Criterion ingressTagCriterion = getTagCriterion(ingress);
    Criterion egressTagCriterion = getTagCriterion(egress);
    if (ingressTagCriterion.type() != egressTagCriterion.type()) {
        /*
             * Tag type of ingress port and egress port are different.
             * Need to remove tag from ingress, then add new tag for egress.
             * Remove nothing if ingress port use VXLAN or there is no tag
             * on ingress port.
             */
        switch(ingressTagCriterion.type()) {
            case VLAN_VID:
                builder.popVlan();
                break;
            case MPLS_LABEL:
                if (copyTtl) {
                    builder.copyTtlIn();
                }
                builder.popMpls(ethType);
                break;
            default:
                break;
        }
        /*
             * Push new tag for egress port.
             */
        switch(egressTagCriterion.type()) {
            case VLAN_VID:
                builder.pushVlan();
                break;
            case MPLS_LABEL:
                builder.pushMpls();
                if (copyTtl) {
                    builder.copyTtlOut();
                }
                break;
            default:
                break;
        }
    }
    switch(egressTagCriterion.type()) {
        case VLAN_VID:
            VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) egressTagCriterion;
            builder.setVlanId(vlanIdCriterion.vlanId());
            break;
        case MPLS_LABEL:
            MplsCriterion mplsCriterion = (MplsCriterion) egressTagCriterion;
            builder.setMpls(mplsCriterion.label());
            break;
        case TUNNEL_ID:
            TunnelIdCriterion tunnelIdCriterion = (TunnelIdCriterion) egressTagCriterion;
            builder.setTunnelId(tunnelIdCriterion.tunnelId());
            break;
        default:
            break;
    }
    return builder.build();
}
Also used : TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 57 with VlanIdCriterion

use of org.onosproject.net.flow.criteria.VlanIdCriterion in project onos by opennetworkinglab.

the class LinkCollectionCompiler method orderedEgressPoints.

/**
 * Helper method to order the egress ports according to a
 * specified criteria. The idea is to generate first the actions
 * for the egress ports which are similar to the specified criteria
 * then the others. In this way we can mitigate the problems related
 * to the chain of actions and we can optimize also the number of
 * actions.
 *
 * @param orderCriteria the ordering criteria
 * @param pointsToOrder the egress points to order
 * @return a list of port ordered
 */
private List<FilteredConnectPoint> orderedEgressPoints(TrafficSelector orderCriteria, List<FilteredConnectPoint> pointsToOrder) {
    /*
         * We are interested only to the labels. The idea is to order
         * by the tags.
         *
         */
    Criterion vlanIdCriterion = orderCriteria.getCriterion(VLAN_VID);
    Criterion mplsLabelCriterion = orderCriteria.getCriterion(MPLS_LABEL);
    /*
         * We collect all the untagged points.
         *
         */
    List<FilteredConnectPoint> untaggedEgressPoints = pointsToOrder.stream().filter(pointToOrder -> {
        TrafficSelector selector = pointToOrder.trafficSelector();
        return selector.getCriterion(VLAN_VID) == null && selector.getCriterion(MPLS_LABEL) == null;
    }).collect(Collectors.toList());
    /*
         * We collect all the vlan points.
         */
    List<FilteredConnectPoint> vlanEgressPoints = pointsToOrder.stream().filter(pointToOrder -> {
        TrafficSelector selector = pointToOrder.trafficSelector();
        return selector.getCriterion(VLAN_VID) != null && selector.getCriterion(MPLS_LABEL) == null;
    }).collect(Collectors.toList());
    /*
         * We collect all the mpls points.
         */
    List<FilteredConnectPoint> mplsEgressPoints = pointsToOrder.stream().filter(pointToOrder -> {
        TrafficSelector selector = pointToOrder.trafficSelector();
        return selector.getCriterion(VLAN_VID) == null && selector.getCriterion(MPLS_LABEL) != null;
    }).collect(Collectors.toList());
    /*
         * We create the final list of ports.
         */
    List<FilteredConnectPoint> orderedList = Lists.newArrayList();
    /*
         * The ordering criteria is vlan id. First we add the vlan
         * ports. Then the others.
         */
    if (vlanIdCriterion != null && mplsLabelCriterion == null) {
        orderedList.addAll(vlanEgressPoints);
        orderedList.addAll(untaggedEgressPoints);
        orderedList.addAll(mplsEgressPoints);
        return orderedList;
    }
    /*
         * The ordering criteria is mpls label. First we add the mpls
         * ports. Then the others.
         */
    if (vlanIdCriterion == null && mplsLabelCriterion != null) {
        orderedList.addAll(mplsEgressPoints);
        orderedList.addAll(untaggedEgressPoints);
        orderedList.addAll(vlanEgressPoints);
        return orderedList;
    }
    /*
         * The ordering criteria is untagged. First we add the untagged
         * ports. Then the others.
         */
    if (vlanIdCriterion == null) {
        orderedList.addAll(untaggedEgressPoints);
        orderedList.addAll(vlanEgressPoints);
        orderedList.addAll(mplsEgressPoints);
        return orderedList;
    }
    /*
         * Unhandled scenario.
         */
    orderedList.addAll(vlanEgressPoints);
    orderedList.addAll(mplsEgressPoints);
    orderedList.addAll(untaggedEgressPoints);
    return orderedList;
}
Also used : PortNumber(org.onosproject.net.PortNumber) LoggerFactory(org.slf4j.LoggerFactory) ModIPv6FlowLabelInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPv6FlowLabelInstruction) Link(org.onosproject.net.Link) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Ip4Address(org.onlab.packet.Ip4Address) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Set(java.util.Set) ModVlanIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanIdInstruction) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) EthType(org.onlab.packet.EthType) ModTransportPortInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction.ModTransportPortInstruction) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) ModEtherInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModEtherInstruction) ModTunnelIdInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModTunnelIdInstruction) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) IpPrefix(org.onlab.packet.IpPrefix) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) Identifier(org.onlab.util.Identifier) L4ModificationInstruction(org.onosproject.net.flow.instructions.L4ModificationInstruction) LabelAllocator(org.onosproject.net.resource.impl.LabelAllocator) ModMplsLabelInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsLabelInstruction) DomainConstraint(org.onosproject.net.intent.constraint.DomainConstraint) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) ModIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModIPInstruction) ModArpIPInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpIPInstruction) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ModVlanPcpInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModVlanPcpInstruction) Type(org.onosproject.net.flow.criteria.Criterion.Type) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DomainService(org.onosproject.net.domain.DomainService) L0ModificationInstruction(org.onosproject.net.flow.instructions.L0ModificationInstruction) DomainPointToPointIntent(org.onosproject.net.domain.DomainPointToPointIntent) Intent(org.onosproject.net.intent.Intent) LOCAL(org.onosproject.net.domain.DomainId.LOCAL) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ModMplsBosInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsBosInstruction) Logger(org.slf4j.Logger) MplsLabel(org.onlab.packet.MplsLabel) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) ModArpEthInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpEthInstruction) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) Maps(com.google.common.collect.Maps) SetMultimap(com.google.common.collect.SetMultimap) DomainId(org.onosproject.net.domain.DomainId) L1ModificationInstruction(org.onosproject.net.flow.instructions.L1ModificationInstruction) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) ModArpOpInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction.ModArpOpInstruction) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) TunnelIdCriterion(org.onosproject.net.flow.criteria.TunnelIdCriterion) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 58 with VlanIdCriterion

use of org.onosproject.net.flow.criteria.VlanIdCriterion in project onos by opennetworkinglab.

the class PathCompiler method manageVlanEncap.

/**
 * Creates the flow rules for the path intent using VLAN
 * encapsulation.
 *
 * @param creator the flowrules creator
 * @param flows the list of flows to fill
 * @param devices the devices on the path
 * @param intent the PathIntent to compile
 */
private void manageVlanEncap(PathCompilerCreateFlow<T> creator, List<T> flows, List<DeviceId> devices, PathIntent intent) {
    Set<Link> linksSet = Sets.newConcurrentHashSet();
    for (int i = 1; i <= intent.path().links().size() - 2; i++) {
        linksSet.add(intent.path().links().get(i));
    }
    Map<LinkKey, Identifier<?>> vlanIds = labelAllocator.assignLabelToLinks(linksSet, intent.key(), EncapsulationType.VLAN);
    Iterator<Link> links = intent.path().links().iterator();
    Link srcLink = links.next();
    Link link = links.next();
    // Ingress traffic
    VlanId vlanId = (VlanId) vlanIds.get(linkKey(link));
    if (vlanId == null) {
        throw new IntentCompilationException(ERROR_VLAN + link);
    }
    VlanId prevVlanId = vlanId;
    Optional<VlanIdCriterion> vlanCriterion = intent.selector().criteria().stream().filter(criterion -> criterion.type() == Criterion.Type.VLAN_VID).map(criterion -> (VlanIdCriterion) criterion).findAny();
    // Push VLAN if selector does not include VLAN
    TrafficTreatment.Builder treatBuilder = DefaultTrafficTreatment.builder();
    if (!vlanCriterion.isPresent()) {
        treatBuilder.pushVlan();
    }
    // Tag the traffic with the new encapsulation VLAN
    treatBuilder.setVlanId(vlanId);
    creator.createFlow(intent.selector(), treatBuilder.build(), srcLink.dst(), link.src(), intent.priority(), true, flows, devices);
    ConnectPoint prev = link.dst();
    while (links.hasNext()) {
        link = links.next();
        if (links.hasNext()) {
            // Transit traffic
            VlanId egressVlanId = (VlanId) vlanIds.get(linkKey(link));
            if (egressVlanId == null) {
                throw new IntentCompilationException(ERROR_VLAN + link);
            }
            TrafficSelector transitSelector = DefaultTrafficSelector.builder().matchInPort(prev.port()).matchVlanId(prevVlanId).build();
            TrafficTreatment.Builder transitTreat = DefaultTrafficTreatment.builder();
            // Set the new vlanId only if the previous one is different
            if (!prevVlanId.equals(egressVlanId)) {
                transitTreat.setVlanId(egressVlanId);
            }
            creator.createFlow(transitSelector, transitTreat.build(), prev, link.src(), intent.priority(), true, flows, devices);
            /* For the next hop we have to remember
                 * the previous egress VLAN id and the egress
                 * node
                 */
            prevVlanId = egressVlanId;
            prev = link.dst();
        } else {
            // Egress traffic
            TrafficSelector egressSelector = DefaultTrafficSelector.builder().matchInPort(prev.port()).matchVlanId(prevVlanId).build();
            TrafficTreatment.Builder egressTreat = DefaultTrafficTreatment.builder(intent.treatment());
            Optional<L2ModificationInstruction.ModVlanIdInstruction> modVlanIdInstruction = intent.treatment().allInstructions().stream().filter(instruction -> instruction instanceof L2ModificationInstruction.ModVlanIdInstruction).map(x -> (L2ModificationInstruction.ModVlanIdInstruction) x).findAny();
            Optional<L2ModificationInstruction.ModVlanHeaderInstruction> popVlanInstruction = intent.treatment().allInstructions().stream().filter(instruction -> instruction instanceof L2ModificationInstruction.ModVlanHeaderInstruction).map(x -> (L2ModificationInstruction.ModVlanHeaderInstruction) x).findAny();
            if (!modVlanIdInstruction.isPresent() && !popVlanInstruction.isPresent()) {
                if (vlanCriterion.isPresent()) {
                    egressTreat.setVlanId(vlanCriterion.get().vlanId());
                } else {
                    egressTreat.popVlan();
                }
            }
            creator.createFlow(egressSelector, egressTreat.build(), prev, link.src(), intent.priority(), true, flows, devices);
        }
    }
}
Also used : MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) Identifier(org.onlab.util.Identifier) LabelAllocator(org.onosproject.net.resource.impl.LabelAllocator) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) ResourceService(org.onosproject.net.resource.ResourceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Ethernet(org.onlab.packet.Ethernet) TrafficSelector(org.onosproject.net.flow.TrafficSelector) Map(java.util.Map) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) LinkKey.linkKey(org.onosproject.net.LinkKey.linkKey) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) LinkKey(org.onosproject.net.LinkKey) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PathIntent(org.onosproject.net.intent.PathIntent) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) MplsLabel(org.onlab.packet.MplsLabel) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) Set(java.util.Set) Sets(com.google.common.collect.Sets) EthType(org.onlab.packet.EthType) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) LinkKey(org.onosproject.net.LinkKey) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Identifier(org.onlab.util.Identifier) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link) VlanId(org.onlab.packet.VlanId) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Example 59 with VlanIdCriterion

use of org.onosproject.net.flow.criteria.VlanIdCriterion in project onos by opennetworkinglab.

the class Ofdpa2Pipeline method processEgress.

/**
 * In the OF-DPA 2.0 pipeline, egress forwarding objectives go to the
 * egress tables.
 * @param fwd  the forwarding objective of type 'egress'
 * @return     a collection of flow rules to be sent to the switch. An empty
 *             collection may be returned if there is a problem in processing
 *             the flow rule
 */
protected Collection<FlowRule> processEgress(ForwardingObjective fwd) {
    log.debug("Processing egress forwarding objective:{} in dev:{}", fwd, deviceId);
    List<FlowRule> rules = new ArrayList<>();
    // Build selector
    TrafficSelector.Builder sb = DefaultTrafficSelector.builder();
    VlanIdCriterion vlanIdCriterion = (VlanIdCriterion) fwd.selector().getCriterion(Criterion.Type.VLAN_VID);
    if (vlanIdCriterion == null) {
        log.error("Egress forwarding objective:{} must include vlanId", fwd.id());
        fail(fwd, ObjectiveError.BADPARAMS);
        return rules;
    }
    Optional<Instruction> outInstr = fwd.treatment().allInstructions().stream().filter(instruction -> instruction instanceof OutputInstruction).findFirst();
    if (!outInstr.isPresent()) {
        log.error("Egress forwarding objective:{} must include output port", fwd.id());
        fail(fwd, ObjectiveError.BADPARAMS);
        return rules;
    }
    PortNumber portNumber = ((OutputInstruction) outInstr.get()).port();
    sb.matchVlanId(vlanIdCriterion.vlanId());
    OfdpaMatchActsetOutput actsetOutput = new OfdpaMatchActsetOutput(portNumber);
    sb.extension(actsetOutput, deviceId);
    sb.extension(new OfdpaMatchAllowVlanTranslation(ALLOW_VLAN_TRANSLATION), deviceId);
    // Build a flow rule for Egress VLAN Flow table
    TrafficTreatment.Builder tb = DefaultTrafficTreatment.builder();
    tb.transition(EGRESS_DSCP_PCP_REMARK_FLOW_TABLE);
    if (fwd.treatment() != null) {
        for (Instruction instr : fwd.treatment().allInstructions()) {
            if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_ID) {
                tb.immediate().add(instr);
            }
            if (instr instanceof L2ModificationInstruction && ((L2ModificationInstruction) instr).subtype() == L2SubType.VLAN_PUSH) {
                tb.immediate().pushVlan();
                EthType ethType = ((L2ModificationInstruction.ModVlanHeaderInstruction) instr).ethernetType();
                if (ethType.equals(EtherType.QINQ.ethType())) {
                    // Build a flow rule for Egress TPID Flow table
                    TrafficSelector tpidSelector = DefaultTrafficSelector.builder().extension(actsetOutput, deviceId).matchVlanId(VlanId.ANY).build();
                    TrafficTreatment tpidTreatment = DefaultTrafficTreatment.builder().extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, COPY_FIELD_OFFSET, OXM_ID_VLAN_VID, OXM_ID_PACKET_REG_1), deviceId).popVlan().pushVlan(EtherType.QINQ.ethType()).extension(new Ofdpa3CopyField(COPY_FIELD_NBITS, COPY_FIELD_OFFSET, COPY_FIELD_OFFSET, OXM_ID_PACKET_REG_1, OXM_ID_VLAN_VID), deviceId).build();
                    FlowRule.Builder tpidRuleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(tpidSelector).withTreatment(tpidTreatment).makePermanent().forTable(EGRESS_TPID_FLOW_TABLE);
                    rules.add(tpidRuleBuilder.build());
                }
            }
        }
    }
    FlowRule.Builder ruleBuilder = DefaultFlowRule.builder().fromApp(fwd.appId()).withPriority(fwd.priority()).forDevice(deviceId).withSelector(sb.build()).withTreatment(tb.build()).makePermanent().forTable(EGRESS_VLAN_FLOW_TABLE);
    rules.add(ruleBuilder.build());
    return rules;
}
Also used : OfdpaPipelineUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaPipelineUtility) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) OfdpaMatchActsetOutput(org.onosproject.driver.extensions.OfdpaMatchActsetOutput) ObjectiveError(org.onosproject.net.flowobjective.ObjectiveError) Executors.newSingleThreadScheduledExecutor(java.util.concurrent.Executors.newSingleThreadScheduledExecutor) FlowRuleService(org.onosproject.net.flow.FlowRuleService) Pair(org.apache.commons.lang3.tuple.Pair) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) Port(org.onosproject.net.Port) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) KryoNamespaces(org.onosproject.store.serializers.KryoNamespaces) SELECT(org.onosproject.net.group.GroupDescription.Type.SELECT) MPLS_BOS(org.onosproject.net.flow.criteria.Criterion.Type.MPLS_BOS) Ofdpa3MplsType(org.onosproject.driver.extensions.Ofdpa3MplsType) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) AbstractAccumulator(org.onlab.util.AbstractAccumulator) OfdpaMatchVlanVid(org.onosproject.driver.extensions.OfdpaMatchVlanVid) OfdpaMatchAllowVlanTranslation(org.onosproject.driver.extensions.OfdpaMatchAllowVlanTranslation) DeviceId(org.onosproject.net.DeviceId) L3SubType(org.onosproject.net.flow.instructions.L3ModificationInstruction.L3SubType) L2SubType(org.onosproject.net.flow.instructions.L2ModificationInstruction.L2SubType) Pipeliner(org.onosproject.net.behaviour.Pipeliner) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) OfdpaSetVlanVid(org.onosproject.driver.extensions.OfdpaSetVlanVid) KryoNamespace(org.onlab.util.KryoNamespace) NextGroup(org.onosproject.net.behaviour.NextGroup) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) Criteria(org.onosproject.net.flow.criteria.Criteria) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) Criterion(org.onosproject.net.flow.criteria.Criterion) Ofdpa3CopyField(org.onosproject.driver.extensions.Ofdpa3CopyField) FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EthTypeCriterion(org.onosproject.net.flow.criteria.EthTypeCriterion) UdpPortCriterion(org.onosproject.net.flow.criteria.UdpPortCriterion) Instruction(org.onosproject.net.flow.instructions.Instruction) VlanId(org.onlab.packet.VlanId) GroupService(org.onosproject.net.group.GroupService) Icmpv6CodeCriterion(org.onosproject.net.flow.criteria.Icmpv6CodeCriterion) OXM_ID_VLAN_VID(org.onosproject.driver.extensions.Ofdpa3CopyField.OXM_ID_VLAN_VID) EtherType(org.onlab.packet.EthType.EtherType) Accumulator(org.onlab.util.Accumulator) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) Objective(org.onosproject.net.flowobjective.Objective) MacAddress(org.onlab.packet.MacAddress) ArrayDeque(java.util.ArrayDeque) MplsBosCriterion(org.onosproject.net.flow.criteria.MplsBosCriterion) CoreService(org.onosproject.core.CoreService) Tools.groupedThreads(org.onlab.util.Tools.groupedThreads) Timer(java.util.Timer) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ServiceDirectory(org.onlab.osgi.ServiceDirectory) Ethernet(org.onlab.packet.Ethernet) OXM_ID_PACKET_REG_1(org.onosproject.driver.extensions.Ofdpa3CopyField.OXM_ID_PACKET_REG_1) SPECIFIC(org.onosproject.net.flowobjective.ForwardingObjective.Flag.SPECIFIC) Ofdpa3SetMplsType(org.onosproject.driver.extensions.Ofdpa3SetMplsType) IPCriterion(org.onosproject.net.flow.criteria.IPCriterion) PipelinerContext(org.onosproject.net.behaviour.PipelinerContext) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Collection(java.util.Collection) FlowObjectiveStore(org.onosproject.net.flowobjective.FlowObjectiveStore) Sets(com.google.common.collect.Sets) Icmpv6TypeCriterion(org.onosproject.net.flow.criteria.Icmpv6TypeCriterion) Objects(java.util.Objects) EthType(org.onlab.packet.EthType) List(java.util.List) FlowRule(org.onosproject.net.flow.FlowRule) Optional(java.util.Optional) IpPrefix(org.onlab.packet.IpPrefix) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) GroupKey(org.onosproject.net.group.GroupKey) Deque(java.util.Deque) Group(org.onosproject.net.group.Group) ImmutableList(com.google.common.collect.ImmutableList) DefaultGroupKey(org.onosproject.net.group.DefaultGroupKey) TcpPortCriterion(org.onosproject.net.flow.criteria.TcpPortCriterion) OfdpaGroupHandlerUtility(org.onosproject.driver.pipeline.ofdpa.OfdpaGroupHandlerUtility) IpAddress(org.onlab.packet.IpAddress) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) ModMplsHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction) TimeUnit(java.util.concurrent.TimeUnit) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Collections(java.util.Collections) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) OfdpaMatchActsetOutput(org.onosproject.driver.extensions.OfdpaMatchActsetOutput) ArrayList(java.util.ArrayList) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) L3ModificationInstruction(org.onosproject.net.flow.instructions.L3ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) NoActionInstruction(org.onosproject.net.flow.instructions.Instructions.NoActionInstruction) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ModMplsHeaderInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction.ModMplsHeaderInstruction) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) EthType(org.onlab.packet.EthType) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) OfdpaMatchAllowVlanTranslation(org.onosproject.driver.extensions.OfdpaMatchAllowVlanTranslation) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) PortNumber(org.onosproject.net.PortNumber) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion) Ofdpa3CopyField(org.onosproject.driver.extensions.Ofdpa3CopyField)

Example 60 with VlanIdCriterion

use of org.onosproject.net.flow.criteria.VlanIdCriterion in project onos by opennetworkinglab.

the class Ofdpa3Pipeline method processDoubleTaggedFilter.

/**
 * Configure filtering rules of outer and inner VLAN IDs, and a MAC address.
 * Filtering happens in three tables (VLAN_TABLE, VLAN_1_TABLE, TMAC_TABLE).
 *
 * @param filteringObjective the filtering objective
 * @param install            true to add, false to remove
 * @param applicationId      for application programming this filter
 */
private void processDoubleTaggedFilter(FilteringObjective filteringObjective, boolean install, ApplicationId applicationId) {
    PortCriterion portCriterion = null;
    EthCriterion ethCriterion = null;
    VlanIdCriterion innervidCriterion = null;
    VlanIdCriterion outerVidCriterion = null;
    boolean popVlan = false;
    boolean removeDoubleTagged = true;
    if (filteringObjective.meta().writeMetadata() != null) {
        removeDoubleTagged = shouldRemoveDoubleTagged(filteringObjective.meta().writeMetadata());
    }
    log.info("HERE , removeDoubleTagged {}", removeDoubleTagged);
    TrafficTreatment meta = filteringObjective.meta();
    if (!filteringObjective.key().equals(Criteria.dummy()) && filteringObjective.key().type() == Criterion.Type.IN_PORT) {
        portCriterion = (PortCriterion) filteringObjective.key();
    }
    if (portCriterion == null) {
        log.warn("No IN_PORT defined in filtering objective from app: {}" + "Failed to program VLAN tables.", applicationId);
        return;
    } else {
        log.debug("Received filtering objective for dev/port: {}/{}", deviceId, portCriterion.port());
    }
    // meta should have only one instruction, popVlan.
    if (meta != null && meta.allInstructions().size() == 1) {
        L2ModificationInstruction l2Inst = (L2ModificationInstruction) meta.allInstructions().get(0);
        if (l2Inst.subtype().equals(L2SubType.VLAN_POP)) {
            popVlan = true;
        } else {
            log.warn("Filtering objective can have only VLAN_POP instruction.");
            return;
        }
    } else {
        log.warn("Filtering objective should have one instruction.");
        return;
    }
    FlowRuleOperations.Builder ops = FlowRuleOperations.builder();
    for (Criterion criterion : filteringObjective.conditions()) {
        switch(criterion.type()) {
            case ETH_DST:
            case ETH_DST_MASKED:
                ethCriterion = (EthCriterion) criterion;
                break;
            case VLAN_VID:
                outerVidCriterion = (VlanIdCriterion) criterion;
                break;
            case INNER_VLAN_VID:
                innervidCriterion = (VlanIdCriterion) criterion;
                break;
            default:
                log.warn("Unsupported filter {}", criterion);
                fail(filteringObjective, ObjectiveError.UNSUPPORTED);
                return;
        }
    }
    if (innervidCriterion == null || outerVidCriterion == null) {
        log.warn("filtering objective should have two vidCriterion.");
        return;
    }
    if (ethCriterion == null || ethCriterion.mac().equals(NONE)) {
        // NOTE: it is possible that a filtering objective only has vidCriterion
        log.warn("filtering objective missing dstMac, cannot program TMAC table");
        return;
    } else {
        MacAddress unicastMac = readEthDstFromTreatment(filteringObjective.meta());
        List<List<FlowRule>> allStages = processEthDstFilter(portCriterion, ethCriterion, innervidCriterion, innervidCriterion.vlanId(), unicastMac, applicationId);
        for (List<FlowRule> flowRules : allStages) {
            log.trace("Starting a new flow rule stage for TMAC table flow");
            ops.newStage();
            for (FlowRule flowRule : flowRules) {
                log.trace("{} flow rules in TMAC table: {} for dev: {}", (install) ? "adding" : "removing", flowRules, deviceId);
                if (install) {
                    ops = ops.add(flowRule);
                } else {
                    // same VLAN on this device if TMAC doesn't support matching on in_port.
                    if (matchInPortTmacTable() || (filteringObjective.meta() != null && filteringObjective.meta().clearedDeferred())) {
                        // if metadata instruction not null and not removeDoubleTagged move on.
                        if ((filteringObjective.meta().writeMetadata() != null) && (!removeDoubleTagged)) {
                            log.info("Skipping removal of tmac rule for device {}", deviceId);
                            continue;
                        } else {
                            ops = ops.remove(flowRule);
                        }
                    } else {
                        log.debug("Abort TMAC flow removal on {}. Some other ports still share this TMAC flow");
                    }
                }
            }
        }
    }
    List<FlowRule> rules;
    rules = processDoubleVlanIdFilter(portCriterion, innervidCriterion, outerVidCriterion, popVlan, applicationId);
    for (FlowRule flowRule : rules) {
        log.trace("{} flow rule in VLAN table: {} for dev: {}", (install) ? "adding" : "removing", flowRule, deviceId);
        // if context is remove, table is vlan_1 and removeDoubleTagged is false, continue.
        if (flowRule.table().equals(IndexTableId.of(VLAN_TABLE)) && !removeDoubleTagged && !install) {
            log.info("Skipping removal of vlan table rule for now!");
            continue;
        }
        ops = install ? ops.add(flowRule) : ops.remove(flowRule);
    }
    // apply filtering flow rules
    flowRuleService.apply(ops.build(new FlowRuleOperationsContext() {

        @Override
        public void onSuccess(FlowRuleOperations ops) {
            log.debug("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);
        }
    }));
}
Also used : FlowRuleOperations(org.onosproject.net.flow.FlowRuleOperations) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) PortCriterion(org.onosproject.net.flow.criteria.PortCriterion) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) MacAddress(org.onlab.packet.MacAddress) 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) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) DefaultFlowRule(org.onosproject.net.flow.DefaultFlowRule) FlowRule(org.onosproject.net.flow.FlowRule) FlowRuleOperationsContext(org.onosproject.net.flow.FlowRuleOperationsContext) VlanIdCriterion(org.onosproject.net.flow.criteria.VlanIdCriterion)

Aggregations

VlanIdCriterion (org.onosproject.net.flow.criteria.VlanIdCriterion)65 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)48 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)45 FlowRule (org.onosproject.net.flow.FlowRule)41 VlanId (org.onlab.packet.VlanId)37 MplsCriterion (org.onosproject.net.flow.criteria.MplsCriterion)35 List (java.util.List)32 DeviceId (org.onosproject.net.DeviceId)30 TrafficSelector (org.onosproject.net.flow.TrafficSelector)30 PortCriterion (org.onosproject.net.flow.criteria.PortCriterion)30 EthCriterion (org.onosproject.net.flow.criteria.EthCriterion)28 Collection (java.util.Collection)27 Collections (java.util.Collections)27 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)27 Collectors (java.util.stream.Collectors)26 Criterion (org.onosproject.net.flow.criteria.Criterion)26 Test (org.junit.Test)25 ImmutableSet (com.google.common.collect.ImmutableSet)24 CoreService (org.onosproject.core.CoreService)24 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)24