Search in sources :

Example 41 with LinkKey

use of org.onosproject.net.LinkKey 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)

Example 42 with LinkKey

use of org.onosproject.net.LinkKey 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)

Example 43 with LinkKey

use of org.onosproject.net.LinkKey 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 44 with LinkKey

use of org.onosproject.net.LinkKey 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 45 with LinkKey

use of org.onosproject.net.LinkKey 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)

Aggregations

LinkKey (org.onosproject.net.LinkKey)61 Test (org.junit.Test)34 ConnectPoint (org.onosproject.net.ConnectPoint)31 Link (org.onosproject.net.Link)23 Identifier (org.onlab.util.Identifier)14 DeviceId (org.onosproject.net.DeviceId)9 Set (java.util.Set)7 MplsLabel (org.onlab.packet.MplsLabel)7 VlanId (org.onlab.packet.VlanId)7 LinkDescription (org.onosproject.net.link.LinkDescription)7 LinkEvent (org.onosproject.net.link.LinkEvent)7 DefaultLinkDescription (org.onosproject.net.link.DefaultLinkDescription)6 ProviderId (org.onosproject.net.provider.ProviderId)6 HashMap (java.util.HashMap)5 Map (java.util.Map)5 FirstFitSelection (org.onosproject.net.resource.impl.LabelAllocator.FirstFitSelection)5 RandomSelection (org.onosproject.net.resource.impl.LabelAllocator.RandomSelection)5 FilteredConnectPoint (org.onosproject.net.FilteredConnectPoint)4 NetworkConfigService (org.onosproject.net.config.NetworkConfigService)4 BasicLinkConfig (org.onosproject.net.config.basics.BasicLinkConfig)4