Search in sources :

Example 16 with Identifier

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

the class LabelAllocatorTest method testFirstFitBehaviorMinSwap.

/**
 * To test the first fit behavior. Using MIN_SWAP optimization
 */
@Test
public void testFirstFitBehaviorMinSwap() {
    // We change to FirstFit and we test the change
    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);
    // Filter reservations
    this.resourceService.filterAssignment = true;
    // We change the available Ids
    this.resourceService.availableVlanLabels = ImmutableSet.of((short) 2, (short) 20, (short) 200);
    // First allocation on a subset of links
    Map<LinkKey, Identifier<?>> allocation = this.allocator.assignLabelToLinks(ImmutableSet.copyOf(links2.subList(2, 3)), IntentId.valueOf(idGenerator.getNewId()), EncapsulationType.VLAN);
    Identifier<?> id = allocation.get(LinkKey.linkKey(d3p0, d4p1));
    // 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(links2.subList(1, 4)), 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, d4p1));
    assertThat(id, instanceOf(VlanId.class));
    vlanId = (VlanId) id;
    assertTrue(VlanId.NO_VID < vlanId.toShort() && vlanId.toShort() < VlanId.MAX_VLAN);
    id = allocation.get(LinkKey.linkKey(d4p0, 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)

Example 17 with Identifier

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

the class LabelAllocatorTest method testRandomBehaviorNoSwap.

/**
 * To test random behavior. Using NO_SWAP optimization
 */
@Test
public void testRandomBehaviorNoSwap() {
    // By default Random is the selection behavior used
    assertThat(this.allocator.getLabelSelection(), instanceOf(RandomSelection.class));
    // Change to NO_SWAP
    this.allocator.setOptLabelSelection(noswap);
    assertEquals(this.allocator.getOptLabelSelection(), LabelAllocator.OptimizationBehavior.NO_SWAP);
    // Filter reservations
    this.resourceService.filterAssignment = true;
    // We change the available Ids
    this.resourceService.availableVlanLabels = ImmutableSet.of((short) 1, (short) 2, (short) 3, (short) 4, (short) 5, (short) 6);
    // 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) RandomSelection(org.onosproject.net.resource.impl.LabelAllocator.RandomSelection) VlanId(org.onlab.packet.VlanId) Test(org.junit.Test)

Example 18 with Identifier

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

the class LabelAllocatorTest method testFirstFitBehaviorNoSwap.

/**
 * To test the first fit behavior. Using NO_SWAP optimization
 */
@Test
public void testFirstFitBehaviorNoSwap() {
    // We change to FirstFit and we test the change
    this.allocator.setLabelSelection(firstFit);
    assertThat(this.allocator.getLabelSelection(), instanceOf(FirstFitSelection.class));
    // / Change to NO_SWAP
    this.allocator.setOptLabelSelection(noswap);
    assertEquals(this.allocator.getOptLabelSelection(), LabelAllocator.OptimizationBehavior.NO_SWAP);
    // Filter reservations
    this.resourceService.filterAssignment = true;
    // We change the available Ids
    this.resourceService.availableMplsLabels = ImmutableSet.of(1, 100, 1000);
    // 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.MPLS);
    Identifier<?> id = allocation.get(LinkKey.linkKey(d3p0, d2p1));
    // value has to be a MPLS label
    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);
    // 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));
    assertThat(id, instanceOf(MplsLabel.class));
    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);
}
Also used : LinkKey(org.onosproject.net.LinkKey) Identifier(org.onlab.util.Identifier) FirstFitSelection(org.onosproject.net.resource.impl.LabelAllocator.FirstFitSelection) MplsLabel(org.onlab.packet.MplsLabel) Test(org.junit.Test)

Example 19 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)

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