Search in sources :

Example 6 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 7 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 8 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)

Example 9 with Identifier

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

the class LabelAllocatorTest method noLabelsOnLinkTest.

/**
 * To test the developed algorithms when there are no labels on a specific link.
 */
@Test
public void noLabelsOnLinkTest() {
    // 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(2, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.VLAN);
    Identifier<?> id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    assertThat(id, instanceOf(VlanId.class));
    VlanId 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(2, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.MPLS);
    id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    assertThat(id, instanceOf(MplsLabel.class));
    MplsLabel 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(2, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.VLAN);
    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)

Example 10 with Identifier

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

the class LabelAllocatorTest method testFirstFitBehaviorNone.

/**
 * To test the first fit behavior. Using NONE optimization
 */
@Test
public void testFirstFitBehaviorNone() {
    // We change to FirstFit and we test the change
    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);
    // Filter reservations
    this.resourceService.filterAssignment = true;
    // We change the available Ids
    this.resourceService.availableVlanLabels = ImmutableSet.of((short) 1, (short) 20, (short) 100);
    // First allocation on a subset of links
    Map<LinkKey, Identifier<?>> allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links.subList(2, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.VLAN);
    Identifier<?> id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    // value has to be a Vlan Id
    assertThat(id, instanceOf(VlanId.class));
    // value should not be a forbidden value
    VlanId vlanId = (VlanId) id;
    assertTrue(VlanId.NO_VID < vlanId.toShort() && vlanId.toShort() < VlanId.MAX_VLAN);
    // 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));
    assertThat(id, instanceOf(VlanId.class));
    vlanId = (VlanId) id;
    assertTrue(VlanId.NO_VID < vlanId.toShort() && vlanId.toShort() < VlanId.MAX_VLAN);
    id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    assertThat(id, instanceOf(VlanId.class));
    vlanId = (VlanId) id;
    assertTrue(VlanId.NO_VID < vlanId.toShort() && vlanId.toShort() < VlanId.MAX_VLAN);
}
Also used : LinkKey(org.onosproject.net.LinkKey) Identifier(org.onlab.util.Identifier) FirstFitSelection(org.onosproject.net.resource.impl.LabelAllocator.FirstFitSelection) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test)

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