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