Search in sources :

Example 11 with MplsLabel

use of org.onlab.packet.MplsLabel in project onos by opennetworkinglab.

the class ResourceDeviceListener method registerPortResource.

private void registerPortResource(Device device, Port port) {
    Resource portPath = Resources.discrete(device.id(), port.number()).resource();
    if (!adminService.register(portPath)) {
        log.error("Failed to register Port: {}", portPath.id());
    }
    queryBandwidth(device.id(), port.number()).map(bw -> portPath.child(Bandwidth.class, bw.bps())).map(adminService::register).ifPresent(success -> {
        if (!success) {
            log.error("Failed to register Bandwidth for {}", portPath.id());
        }
    });
    // for VLAN IDs
    Set<VlanId> vlans = queryVlanIds(device.id(), port.number());
    if (!vlans.isEmpty()) {
        boolean success = adminService.register(vlans.stream().map(portPath::child).collect(Collectors.toList()));
        if (!success) {
            log.error("Failed to register VLAN IDs for {}", portPath.id());
        }
    }
    // for MPLS labels
    Set<MplsLabel> mplsLabels = queryMplsLabels(device.id(), port.number());
    if (!mplsLabels.isEmpty()) {
        boolean success = adminService.register(mplsLabels.stream().map(portPath::child).collect(Collectors.toList()));
        if (!success) {
            log.error("Failed to register MPLS Labels for {}", portPath.id());
        }
    }
    // for Lambdas
    Set<OchSignal> lambdas = queryLambdas(device.id(), port.number());
    if (!lambdas.isEmpty()) {
        boolean success = adminService.register(lambdas.stream().map(portPath::child).collect(Collectors.toList()));
        if (!success) {
            log.error("Failed to register lambdas for {}", portPath.id());
        }
    }
    // for Tributary slots
    Set<TributarySlot> tSlots = queryTributarySlots(device.id(), port.number());
    if (!tSlots.isEmpty()) {
        boolean success = adminService.register(tSlots.stream().map(portPath::child).collect(Collectors.toList()));
        if (!success) {
            log.error("Failed to register tributary slots for {}", portPath.id());
        }
    }
}
Also used : Bandwidth(org.onlab.util.Bandwidth) Resource(org.onosproject.net.resource.Resource) DiscreteResource(org.onosproject.net.resource.DiscreteResource) TributarySlot(org.onosproject.net.TributarySlot) MplsLabel(org.onlab.packet.MplsLabel) OchSignal(org.onosproject.net.OchSignal) VlanId(org.onlab.packet.VlanId)

Example 12 with MplsLabel

use of org.onlab.packet.MplsLabel in project onos by opennetworkinglab.

the class NextObjectiveTranslator method nextMpls.

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

Example 13 with MplsLabel

use of org.onlab.packet.MplsLabel in project onos by opennetworkinglab.

the class LinkCollectionCompiler method updateSelectorFromEncapsulation.

/**
 * The method generates a selector starting from
 * the encapsulation information (type and label to match).
 *
 * @param selectorBuilder the builder to update
 * @param type the type of encapsulation
 * @param identifier the label to match
 */
private void updateSelectorFromEncapsulation(TrafficSelector.Builder selectorBuilder, EncapsulationType type, Identifier<?> identifier) {
    switch(type) {
        case MPLS:
            MplsLabel label = (MplsLabel) identifier;
            selectorBuilder.matchMplsLabel(label);
            selectorBuilder.matchEthType(Ethernet.MPLS_UNICAST);
            break;
        case VLAN:
            VlanId id = (VlanId) identifier;
            selectorBuilder.matchVlanId(id);
            break;
        default:
            throw new IntentCompilationException(UNKNOWN_ENCAPSULATION);
    }
}
Also used : MplsLabel(org.onlab.packet.MplsLabel) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) VlanId(org.onlab.packet.VlanId)

Example 14 with MplsLabel

use of org.onlab.packet.MplsLabel in project onos by opennetworkinglab.

the class PathCompiler method manageMplsEncap.

/**
 * Creates the flow rules for the path intent using MPLS
 * 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 manageMplsEncap(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<?>> mplsLabels = labelAllocator.assignLabelToLinks(linksSet, intent.key(), EncapsulationType.MPLS);
    Iterator<Link> links = intent.path().links().iterator();
    Link srcLink = links.next();
    Link link = links.next();
    // List of flow rules to be installed
    // Ingress traffic
    MplsLabel mplsLabel = (MplsLabel) mplsLabels.get(linkKey(link));
    if (mplsLabel == null) {
        throw new IntentCompilationException(ERROR_MPLS + link);
    }
    MplsLabel prevMplsLabel = mplsLabel;
    Optional<MplsCriterion> mplsCriterion = intent.selector().criteria().stream().filter(criterion -> criterion.type() == Criterion.Type.MPLS_LABEL).map(criterion -> (MplsCriterion) criterion).findAny();
    // Push MPLS if selector does not include MPLS
    TrafficTreatment.Builder treatBuilder = DefaultTrafficTreatment.builder();
    if (!mplsCriterion.isPresent()) {
        treatBuilder.pushMpls();
    }
    // Tag the traffic with the new encapsulation MPLS label
    treatBuilder.setMpls(mplsLabel);
    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
            MplsLabel transitMplsLabel = (MplsLabel) mplsLabels.get(linkKey(link));
            if (transitMplsLabel == null) {
                throw new IntentCompilationException(ERROR_MPLS + link);
            }
            TrafficSelector transitSelector = DefaultTrafficSelector.builder().matchInPort(prev.port()).matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(prevMplsLabel).build();
            TrafficTreatment.Builder transitTreat = DefaultTrafficTreatment.builder();
            // Set the new MPLS label only if the previous one is different
            if (!prevMplsLabel.equals(transitMplsLabel)) {
                transitTreat.setMpls(transitMplsLabel);
            }
            creator.createFlow(transitSelector, transitTreat.build(), prev, link.src(), intent.priority(), true, flows, devices);
            prevMplsLabel = transitMplsLabel;
            prev = link.dst();
        } else {
            TrafficSelector.Builder egressSelector = DefaultTrafficSelector.builder().matchInPort(prev.port()).matchEthType(Ethernet.MPLS_UNICAST).matchMplsLabel(prevMplsLabel);
            TrafficTreatment.Builder egressTreat = DefaultTrafficTreatment.builder(intent.treatment());
            // than selector needs to match any VlanId
            for (Instruction instruct : intent.treatment().allInstructions()) {
                if (instruct instanceof L2ModificationInstruction) {
                    L2ModificationInstruction l2Mod = (L2ModificationInstruction) instruct;
                    if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_PUSH) {
                        break;
                    }
                    if (l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_POP || l2Mod.subtype() == L2ModificationInstruction.L2SubType.VLAN_ID) {
                        egressSelector.matchVlanId(VlanId.ANY);
                    }
                }
            }
            if (mplsCriterion.isPresent()) {
                egressTreat.setMpls(mplsCriterion.get().label());
            } else {
                egressTreat.popMpls(getEthType(intent.selector()));
            }
            creator.createFlow(egressSelector.build(), 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) L2ModificationInstruction(org.onosproject.net.flow.instructions.L2ModificationInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) EncapsulationConstraint(org.onosproject.net.intent.constraint.EncapsulationConstraint) Identifier(org.onlab.util.Identifier) MplsLabel(org.onlab.packet.MplsLabel) MplsCriterion(org.onosproject.net.flow.criteria.MplsCriterion) TrafficSelector(org.onosproject.net.flow.TrafficSelector) DefaultTrafficSelector(org.onosproject.net.flow.DefaultTrafficSelector) IntentCompilationException(org.onosproject.net.intent.IntentCompilationException) Link(org.onosproject.net.Link)

Example 15 with MplsLabel

use of org.onlab.packet.MplsLabel in project onos by opennetworkinglab.

the class LabelAllocatorTest method noLabelsTest.

/**
 * To test the developed algorithms when there are no labels.
 */
@Test
public void noLabelsTest() {
    // Verify the first fit behavior with NONE optimization
    this.allocator.setLabelSelection(firstFit);
    assertThat(this.allocator.getLabelSelection(), instanceOf(FirstFitSelection.class));
    // It has to be an instance of NONE
    assertEquals(this.allocator.getOptLabelSelection(), LabelAllocator.OptimizationBehavior.NONE);
    // We change the available Ids
    this.resourceService.availableVlanLabels = ImmutableSet.of((short) 10);
    // Enable filtering of the reservation
    this.resourceService.filterAssignment = true;
    // We test the behavior for VLAN
    Map<LinkKey, Identifier<?>> allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(1, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.VLAN);
    Identifier<?> id = allocation.get(LinkKey.linkKey(d1p1, d3p1));
    // value has to be a VlanId
    assertThat(id, instanceOf(VlanId.class));
    // value should not be a forbidden value
    VlanId label = (VlanId) id;
    assertTrue(VlanId.NO_VID < label.toShort() && label.toShort() < VlanId.MAX_VLAN);
    // Next hop
    id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    assertThat(id, instanceOf(VlanId.class));
    label = (VlanId) id;
    assertTrue(VlanId.NO_VID < label.toShort() && label.toShort() < VlanId.MAX_VLAN);
    // No labels are available, reservation is not possible
    allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(1, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.VLAN);
    id = allocation.get(LinkKey.linkKey(d1p1, d3p1));
    // value has to be null
    assertNull(id);
    id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    // value has to be null
    assertNull(id);
    // Verify the random behavior with NONE_SWAP optimization
    this.allocator.setLabelSelection(random);
    assertThat(this.allocator.getLabelSelection(), instanceOf(RandomSelection.class));
    // Change to NO_SWAP
    this.allocator.setOptLabelSelection(noswap);
    assertEquals(this.allocator.getOptLabelSelection(), LabelAllocator.OptimizationBehavior.NO_SWAP);
    // We change the available Ids
    this.resourceService.availableMplsLabels = ImmutableSet.of(2000);
    // Enable filtering of the reservation
    this.resourceService.filterAssignment = true;
    // We test the behavior for MPLS
    allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(1, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
    id = allocation.get(LinkKey.linkKey(d1p1, d3p1));
    // value has to be a Mplslabel
    assertThat(id, instanceOf(MplsLabel.class));
    // value should not be a forbidden value
    MplsLabel mplsLabel = (MplsLabel) id;
    assertTrue(0 <= mplsLabel.toInt() && mplsLabel.toInt() <= MplsLabel.MAX_MPLS);
    id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    assertThat(id, instanceOf(MplsLabel.class));
    mplsLabel = (MplsLabel) id;
    assertTrue(0 <= mplsLabel.toInt() && mplsLabel.toInt() <= MplsLabel.MAX_MPLS);
    // No labels are available, reservation is not possible
    allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(1, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
    id = allocation.get(LinkKey.linkKey(d1p1, d3p1));
    // value has to be null
    assertNull(id);
    id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    // value has to be null
    assertNull(id);
    // Verify the first fit behavior with MIN optimization
    this.allocator.setLabelSelection(firstFit);
    assertThat(this.allocator.getLabelSelection(), instanceOf(FirstFitSelection.class));
    // Change to MIN_SWAP
    this.allocator.setOptLabelSelection(minswap);
    assertEquals(this.allocator.getOptLabelSelection(), LabelAllocator.OptimizationBehavior.MIN_SWAP);
    // We change the available Ids
    this.resourceService.availableVlanLabels = ImmutableSet.of((short) 11);
    // Enable filtering of the reservation
    this.resourceService.filterAssignment = true;
    // We test the behavior for VLAN
    allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(1, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.VLAN);
    id = allocation.get(LinkKey.linkKey(d1p1, d3p1));
    // value has to be a VlanId
    assertThat(id, instanceOf(VlanId.class));
    // value should not be a forbidden value
    label = (VlanId) id;
    assertTrue(VlanId.NO_VID < label.toShort() && label.toShort() < VlanId.MAX_VLAN);
    // Next hop
    id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    assertThat(id, instanceOf(VlanId.class));
    label = (VlanId) id;
    assertTrue(VlanId.NO_VID < label.toShort() && label.toShort() < VlanId.MAX_VLAN);
    // No labels are available, reservation is not possible
    allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(1, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.VLAN);
    id = allocation.get(LinkKey.linkKey(d1p1, d3p1));
    // value has to be null
    assertNull(id);
    id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    // value has to be null
    assertNull(id);
}
Also used : LinkKey(org.onosproject.net.LinkKey) Identifier(org.onlab.util.Identifier) FirstFitSelection(org.onosproject.net.resource.impl.LabelAllocator.FirstFitSelection) RandomSelection(org.onosproject.net.resource.impl.LabelAllocator.RandomSelection) MplsLabel(org.onlab.packet.MplsLabel) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test)

Aggregations

MplsLabel (org.onlab.packet.MplsLabel)18 Test (org.junit.Test)9 VlanId (org.onlab.packet.VlanId)9 DefaultTrafficTreatment (org.onosproject.net.flow.DefaultTrafficTreatment)7 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)7 Identifier (org.onlab.util.Identifier)6 LinkKey (org.onosproject.net.LinkKey)6 List (java.util.List)5 TrafficSelector (org.onosproject.net.flow.TrafficSelector)5 Instruction (org.onosproject.net.flow.instructions.Instruction)5 Set (java.util.Set)4 DeviceId (org.onosproject.net.DeviceId)4 DefaultTrafficSelector (org.onosproject.net.flow.DefaultTrafficSelector)4 RandomSelection (org.onosproject.net.resource.impl.LabelAllocator.RandomSelection)4 Collection (java.util.Collection)3 Collections (java.util.Collections)3 Collectors (java.util.stream.Collectors)3 L2ModificationInstruction (org.onosproject.net.flow.instructions.L2ModificationInstruction)3 DefaultGroupDescription (org.onosproject.net.group.DefaultGroupDescription)3 DefaultGroupKey (org.onosproject.net.group.DefaultGroupKey)3