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);
}
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);
}
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);
}
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);
}
Aggregations