Search in sources :

Example 66 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.

the class LinkCollectionCompiler method createForwardingInstruction.

/**
 * Helper method to handle the different scenario (not encap, single hop, encap).
 *
 * @param encapConstraint the encapsulation constraint if it is present
 * @param intent the link collection intent
 * @param inPort the in port
 * @param outPorts the out ports
 * @param deviceId the current device
 * @param labels the labels used by the encapsulation
 * @return the forwarding instruction
 */
protected ForwardingInstructions createForwardingInstruction(Optional<EncapsulationConstraint> encapConstraint, LinkCollectionIntent intent, PortNumber inPort, Set<PortNumber> outPorts, DeviceId deviceId, Map<ConnectPoint, Identifier<?>> labels) {
    ForwardingInstructions instructions = null;
    /*
         * If not encapsulation or single hop.
         */
    if (!encapConstraint.isPresent() || intent.links().isEmpty()) {
        instructions = this.createForwardingInstructions(intent, inPort, deviceId, outPorts);
    /*
         * If encapsulation is present. We retrieve the labels
         * for this iteration;
         */
    } else {
        Identifier<?> inLabel = labels.get(new ConnectPoint(deviceId, inPort));
        Map<ConnectPoint, Identifier<?>> outLabels = Maps.newHashMap();
        outPorts.forEach(outPort -> {
            ConnectPoint key = new ConnectPoint(deviceId, outPort);
            outLabels.put(key, labels.get(key));
        });
        instructions = this.createForwardingInstructions(intent, inPort, inLabel, deviceId, outPorts, outLabels, encapConstraint.get().encapType());
    }
    return instructions;
}
Also used : Identifier(org.onlab.util.Identifier) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 67 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.

the class LinkCollectionCompiler method manageEncapAtCoreAndEgress.

/**
 * Manages the core and transit of the Intents (p2p, sp2mp, mp2sp)
 * with encapsulation.
 *
 * @param selectorBuilder the selector builder to update
 * @param treatmentBuilder the treatment builder to update
 * @param intent the intent to compile
 * @param inPort the input port of this device
 * @param inLabel the label associated to the input port
 * @param deviceId the current device
 * @param outPorts the output ports of this device
 * @param outLabels the labels associated to the output port
 * @param type the encapsulation type
 */
private void manageEncapAtCoreAndEgress(TrafficSelector.Builder selectorBuilder, TrafficTreatment.Builder treatmentBuilder, LinkCollectionIntent intent, PortNumber inPort, Identifier<?> inLabel, DeviceId deviceId, Set<PortNumber> outPorts, Map<ConnectPoint, Identifier<?>> outLabels, EncapsulationType type) {
    /*
         * If there are not labels, we cannot handle.
         */
    ConnectPoint inCp = new ConnectPoint(deviceId, inPort);
    if (inLabel == null) {
        throw new IntentCompilationException(String.format(NO_LABELS, inCp));
    }
    /*
         * In the core and at egress we match using encapsulation.
         */
    updateSelectorFromEncapsulation(selectorBuilder, type, inLabel);
    /*
         * Generate the output actions.
         */
    manageOutputPorts(outPorts, deviceId, intent, outLabels, type, selectorBuilder, treatmentBuilder);
}
Also used : IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 68 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.

the class LinkCollectionCompiler method computePorts.

/**
 * Helper method to compute input and output ports
 * for each device crossed in the path.
 *
 * @param intent the related intents
 * @param inputPorts the input ports to compute
 * @param outputPorts the output ports to compute
 */
protected void computePorts(LinkCollectionIntent intent, SetMultimap<DeviceId, PortNumber> inputPorts, SetMultimap<DeviceId, PortNumber> outputPorts) {
    for (Link link : intent.links()) {
        inputPorts.put(link.dst().deviceId(), link.dst().port());
        outputPorts.put(link.src().deviceId(), link.src().port());
    }
    for (ConnectPoint ingressPoint : intent.ingressPoints()) {
        inputPorts.put(ingressPoint.deviceId(), ingressPoint.port());
    }
    for (ConnectPoint egressPoint : intent.egressPoints()) {
        outputPorts.put(egressPoint.deviceId(), egressPoint.port());
    }
}
Also used : ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) Link(org.onosproject.net.Link)

Example 69 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.

the class LinkCollectionCompiler method manageOutputPorts.

/**
 * Helper method which handles the proper generation of the ouput actions.
 *
 * @param outPorts the output ports
 * @param deviceId the current device
 * @param intent the intent to compile
 * @param outLabels the output labels
 * @param type the encapsulation type
 * @param preCondition the previous state
 * @param treatmentBuilder the builder to update with the ouput actions
 */
private void manageOutputPorts(Set<PortNumber> outPorts, DeviceId deviceId, LinkCollectionIntent intent, Map<ConnectPoint, Identifier<?>> outLabels, EncapsulationType type, TrafficSelector.Builder preCondition, TrafficTreatment.Builder treatmentBuilder) {
    /*
         * We need to order the actions. First the actions
         * related to the not-egress points. At the same time we collect
         * also the egress points.
         */
    List<FilteredConnectPoint> egressPoints = Lists.newArrayList();
    for (PortNumber outPort : outPorts) {
        Optional<FilteredConnectPoint> filteredEgressPoint = getFilteredConnectPointFromIntent(deviceId, outPort, intent);
        if (!filteredEgressPoint.isPresent()) {
            /*
                 * We build a temporary selector for the encapsulation.
                 */
            TrafficSelector.Builder encapBuilder = DefaultTrafficSelector.builder();
            /*
                 * We retrieve the associated label to the output port.
                 */
            ConnectPoint cp = new ConnectPoint(deviceId, outPort);
            Identifier<?> outLabel = outLabels.get(cp);
            /*
                 * If there are not labels, we cannot handle.
                 */
            if (outLabel == null) {
                throw new IntentCompilationException(String.format(NO_LABELS, cp));
            }
            /*
                 * In the core we match using encapsulation.
                 */
            updateSelectorFromEncapsulation(encapBuilder, type, outLabel);
            /*
                 * We generate the transition.
                 */
            TrafficTreatment forwardingTreatment = forwardingTreatment(preCondition.build(), encapBuilder.build(), getEthType(intent.selector()));
            /*
                 * We add the instruction necessary to the transition.
                 */
            forwardingTreatment.allInstructions().stream().filter(inst -> inst.type() != Instruction.Type.NOACTION).forEach(treatmentBuilder::add);
            /*
                 * Finally we set the output action.
                 */
            treatmentBuilder.setOutput(outPort);
            /*
                 * The encapsulation modifies the packet. If we are optimizing
                 * we have to update the state.
                 */
            if (optimizeTreatments()) {
                preCondition = encapBuilder;
            }
        } else {
            egressPoints.add(filteredEgressPoint.get());
        }
    }
    /*
         * The idea is to order the egress points. Before we deal
         * with the egress points which looks like similar to the
         * selector derived from the previous state then the
         * the others.
         */
    TrafficSelector prevState = preCondition.build();
    if (optimizeTreatments()) {
        egressPoints = orderedEgressPoints(prevState, egressPoints);
    }
    /*
         * In this case, we have to transit to the final
         * state.
         */
    generateEgressActions(treatmentBuilder, egressPoints, prevState, intent);
}
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) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Example 70 with ConnectPoint

use of org.onosproject.net.ConnectPoint in project onos by opennetworkinglab.

the class LinkCollectionIntentFlowObjectiveCompiler method buildFilteringObjective.

private FilteringObjective buildFilteringObjective(LinkCollectionIntent intent, TrafficSelector selector, DeviceId deviceId, PortNumber inPort) {
    FilteringObjective.Builder builder = DefaultFilteringObjective.builder();
    builder.fromApp(appId).permit().makePermanent().withPriority(intent.priority());
    Criterion inPortCriterion = selector.getCriterion(Criterion.Type.IN_PORT);
    if (inPortCriterion != null) {
        builder.withKey(inPortCriterion);
    }
    FilteredConnectPoint ingressPoint = intent.filteredIngressPoints().stream().filter(fcp -> fcp.connectPoint().equals(new ConnectPoint(deviceId, inPort))).filter(fcp -> selector.criteria().containsAll(fcp.trafficSelector().criteria())).findFirst().orElse(null);
    AtomicBoolean emptyCondition = new AtomicBoolean(true);
    if (ingressPoint != null) {
        // ingress point, use criterion of it
        ingressPoint.trafficSelector().criteria().forEach(criterion -> {
            builder.addCondition(criterion);
            emptyCondition.set(false);
        });
        if (emptyCondition.get()) {
            return null;
        }
        return builder.add();
    }
    Optional<EncapsulationConstraint> encapConstraint = this.getIntentEncapConstraint(intent);
    if (encapConstraint.isPresent() && !encapConstraint.get().encapType().equals(EncapsulationType.NONE)) {
        // encapsulation enabled, use encapsulation label and tag.
        EncapsulationConstraint encap = encapConstraint.get();
        switch(encap.encapType()) {
            case VLAN:
                builder.addCondition(selector.getCriterion(Criterion.Type.VLAN_VID));
                emptyCondition.set(false);
                break;
            case MPLS:
                builder.addCondition(selector.getCriterion(Criterion.Type.MPLS_LABEL));
                emptyCondition.set(false);
                break;
            default:
                log.warn("No filtering rule found because of unknown encapsulation type.");
                break;
        }
    } else {
        // encapsulation not enabled, check if the treatment applied to the ingress or not
        if (intent.applyTreatmentOnEgress()) {
            // filtering criterion will be changed on egress point, use
            // criterion of ingress point
            ingressPoint = intent.filteredIngressPoints().stream().findFirst().orElse(null);
            if (ingressPoint == null) {
                log.warn("No filtering rule found because no ingress point in the Intent");
            } else {
                ingressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
                    builder.addCondition(criterion);
                    emptyCondition.set(false);
                });
            }
        } else {
            // filtering criterion will be changed on ingress point, use
            // criterion of egress point
            FilteredConnectPoint egressPoint = intent.filteredEgressPoints().stream().findFirst().orElse(null);
            if (egressPoint == null) {
                log.warn("No filtering rule found because no egress point in the Intent");
            } else {
                egressPoint.trafficSelector().criteria().stream().filter(criterion -> !criterion.type().equals(Criterion.Type.IN_PORT)).forEach(criterion -> {
                    builder.addCondition(criterion);
                    emptyCondition.set(false);
                });
            }
        }
    }
    if (emptyCondition.get()) {
        return null;
    }
    return builder.add();
}
Also used : CoreService(org.onosproject.core.CoreService) PortNumber(org.onosproject.net.PortNumber) DefaultNextObjective(org.onosproject.net.flowobjective.DefaultNextObjective) ForwardingObjective(org.onosproject.net.flowobjective.ForwardingObjective) ResourceService(org.onosproject.net.resource.ResourceService) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) ConnectPoint(org.onosproject.net.ConnectPoint) HashMultimap(com.google.common.collect.HashMultimap) Map(java.util.Map) ApplicationId(org.onosproject.core.ApplicationId) NextObjective(org.onosproject.net.flowobjective.NextObjective) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) Deactivate(org.osgi.service.component.annotations.Deactivate) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) Set(java.util.Set) DefaultForwardingObjective(org.onosproject.net.flowobjective.DefaultForwardingObjective) Sets(com.google.common.collect.Sets) List(java.util.List) EncapsulationType(org.onosproject.net.EncapsulationType) IntentCompiler(org.onosproject.net.intent.IntentCompiler) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) Identifier(org.onlab.util.Identifier) LabelAllocator(org.onosproject.net.resource.impl.LabelAllocator) FlowObjectiveIntent(org.onosproject.net.intent.FlowObjectiveIntent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) ArrayList(java.util.ArrayList) FlowObjectiveService(org.onosproject.net.flowobjective.FlowObjectiveService) Component(org.osgi.service.component.annotations.Component) Lists(com.google.common.collect.Lists) TrafficSelector(org.onosproject.net.flow.TrafficSelector) ImmutableList(com.google.common.collect.ImmutableList) DomainService(org.onosproject.net.domain.DomainService) Intent(org.onosproject.net.intent.Intent) LOCAL(org.onosproject.net.domain.DomainId.LOCAL) Activate(org.osgi.service.component.annotations.Activate) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) Logger(org.slf4j.Logger) Instruction(org.onosproject.net.flow.instructions.Instruction) LinkCollectionIntent(org.onosproject.net.intent.LinkCollectionIntent) SetMultimap(com.google.common.collect.SetMultimap) ReferenceCardinality(org.osgi.service.component.annotations.ReferenceCardinality) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) Objective(org.onosproject.net.flowobjective.Objective) Reference(org.osgi.service.component.annotations.Reference) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) EthCriterion(org.onosproject.net.flow.criteria.EthCriterion) Criterion(org.onosproject.net.flow.criteria.Criterion) DefaultFilteringObjective(org.onosproject.net.flowobjective.DefaultFilteringObjective) FilteringObjective(org.onosproject.net.flowobjective.FilteringObjective) ConnectPoint(org.onosproject.net.ConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint) FilteredConnectPoint(org.onosproject.net.FilteredConnectPoint)

Aggregations

ConnectPoint (org.onosproject.net.ConnectPoint)536 Test (org.junit.Test)149 DeviceId (org.onosproject.net.DeviceId)125 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)91 Link (org.onosproject.net.Link)88 Set (java.util.Set)86 PortNumber (org.onosproject.net.PortNumber)86 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)83 VlanId (org.onlab.packet.VlanId)78 TrafficSelector (org.onosproject.net.flow.TrafficSelector)75 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)72 Logger (org.slf4j.Logger)71 Port (org.onosproject.net.Port)70 List (java.util.List)69 Ethernet (org.onlab.packet.Ethernet)69 DeviceService (org.onosproject.net.device.DeviceService)67 Collectors (java.util.stream.Collectors)66 MacAddress (org.onlab.packet.MacAddress)64 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)64 Intent (org.onosproject.net.intent.Intent)62