Search in sources :

Example 1 with Identifier

use of org.onlab.util.Identifier 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 2 with Identifier

use of org.onlab.util.Identifier 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 3 with Identifier

use of org.onlab.util.Identifier in project onos by opennetworkinglab.

the class LabelAllocator method minSwapBehavior.

// Implements MIN_SWAP behavior
private Map<LinkKey, Identifier<?>> minSwapBehavior(Set<LinkKey> links, EncapsulationType type) {
    // Init step
    Map<LinkKey, Identifier<?>> ids = Maps.newHashMap();
    Set<Identifier<?>> candidates;
    Identifier<?> selected = null;
    // Iterates for each link selecting a label in the candidate set
    for (LinkKey link : links) {
        // Get candidates set for the current link
        candidates = getCandidates(link, type);
        // If we are in the first link or selected is not available
        if (selected == null || !candidates.contains(selected)) {
            // Select a label for the current link
            selected = labelSelection.select(candidates);
            // If candidates is empty, selected is null
            if (selected == null) {
                log.warn("No labels for {}", link);
                return Collections.emptyMap();
            }
        }
        // Selected is associated to link
        ids.put(link, selected);
    }
    return ids;
}
Also used : LinkKey(org.onosproject.net.LinkKey) Identifier(org.onlab.util.Identifier)

Example 4 with Identifier

use of org.onlab.util.Identifier in project onos by opennetworkinglab.

the class LabelAllocator method noOptimizeBehavior.

// Implements NONE behavior
private Map<LinkKey, Identifier<?>> noOptimizeBehavior(Set<LinkKey> links, EncapsulationType type) {
    // Init step
    Map<LinkKey, Identifier<?>> ids = Maps.newHashMap();
    Set<Identifier<?>> candidates;
    Identifier<?> selected;
    // Iterates for each link selecting a label in the candidate set
    for (LinkKey link : links) {
        // Get candidates set for the current link
        candidates = getCandidates(link, type);
        // Select a label for the current link
        selected = labelSelection.select(candidates);
        // If candidates is empty, selected is null
        if (selected == null) {
            log.warn("No labels for {}", link);
            return Collections.emptyMap();
        }
        // Selected is associated to link
        ids.put(link, selected);
    }
    return ids;
}
Also used : LinkKey(org.onosproject.net.LinkKey) Identifier(org.onlab.util.Identifier)

Example 5 with Identifier

use of org.onlab.util.Identifier in project onos by opennetworkinglab.

the class LabelAllocator method suggestedIdentifierBehavior.

// Implements suggestedIdentifier behavior
private Map<LinkKey, Identifier<?>> suggestedIdentifierBehavior(Set<LinkKey> links, EncapsulationType type, Identifier<?> suggested) {
    // Init step
    Map<LinkKey, Identifier<?>> ids = Maps.newHashMap();
    Set<Identifier<?>> candidates;
    Identifier<?> selected = null;
    // Select the suggested if available on the whole path
    for (LinkKey link : links) {
        // Get candidates set for the current link
        candidates = getCandidates(link, type);
        // Otherwise select an other label for the current link
        if (candidates.contains(suggested)) {
            selected = suggested;
        } else {
            // If candidates is empty or does not contain suggested
            log.warn("Suggested label {} is not available on link {}", suggested, link);
            return Collections.emptyMap();
        }
        // Selected is associated to link
        ids.put(link, selected);
    }
    return ids;
}
Also used : LinkKey(org.onosproject.net.LinkKey) Identifier(org.onlab.util.Identifier)

Aggregations

Identifier (org.onlab.util.Identifier)19 LinkKey (org.onosproject.net.LinkKey)14 Test (org.junit.Test)9 VlanId (org.onlab.packet.VlanId)9 MplsLabel (org.onlab.packet.MplsLabel)8 ConnectPoint (org.onosproject.net.ConnectPoint)7 DeviceId (org.onosproject.net.DeviceId)5 FirstFitSelection (org.onosproject.net.resource.impl.LabelAllocator.FirstFitSelection)5 RandomSelection (org.onosproject.net.resource.impl.LabelAllocator.RandomSelection)5 EncapsulationConstraint (org.onosproject.net.intent.constraint.EncapsulationConstraint)4 ImmutableList (com.google.common.collect.ImmutableList)3 Sets (com.google.common.collect.Sets)3 List (java.util.List)3 Map (java.util.Map)3 Optional (java.util.Optional)3 Set (java.util.Set)3 EthType (org.onlab.packet.EthType)3 Ethernet (org.onlab.packet.Ethernet)3 EncapsulationType (org.onosproject.net.EncapsulationType)3 Link (org.onosproject.net.Link)3