use of org.onosproject.net.LinkKey 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.onosproject.net.LinkKey in project onos by opennetworkinglab.
the class LldpLinkProvider method updateDevice.
/**
* Updates discovery helper for specified device.
*
* Adds and starts a discovery helper for specified device if enabled,
* calls {@link #removeDevice(DeviceId)} otherwise.
*
* @param device device to add
* @return discovery helper if discovery is enabled for the device
*/
private Optional<LinkDiscovery> updateDevice(Device device) {
if (device == null) {
return Optional.empty();
}
if (!masterService.isLocalMaster(device.id())) {
// Reset the last seen time for all links to this device
// then stop discovery for this device
List<LinkKey> updateLinks = new LinkedList<>();
linkTimes.forEach((link, time) -> {
if (link.dst().deviceId().equals(device.id())) {
updateLinks.add(link);
}
});
updateLinks.forEach(link -> linkTimes.remove(link));
removeDevice(device.id());
return Optional.empty();
}
if (rules.isSuppressed(device) || isBlacklisted(device.id())) {
log.trace("LinkDiscovery from {} disabled by configuration", device.id());
removeDevice(device.id());
return Optional.empty();
}
LinkDiscovery ld = discoverers.computeIfAbsent(device.id(), did -> new LinkDiscovery(device.id(), context));
if (ld.isStopped()) {
ld.start();
}
return Optional.of(ld);
}
use of org.onosproject.net.LinkKey in project onos by opennetworkinglab.
the class NetworkConfigLinksProviderTest method testNotConfiguredLink.
/**
* Tests discovery of a link that is not expected in the configuration.
*/
@Test
public void testNotConfiguredLink() {
PacketContext pktCtx = new TestPacketContext(src, dst);
testProcessor.process(pktCtx);
assertThat(providerService.discoveredLinks().entrySet(), hasSize(1));
DeviceId destination = providerService.discoveredLinks().get(dev1.id());
assertThat(destination, notNullValue());
LinkKey key = LinkKey.linkKey(src, dst);
LinkDescription linkDescription = providerService.discoveredLinkDescriptions().get(key);
assertThat(linkDescription, notNullValue());
assertThat(linkDescription.isExpected(), is(false));
}
use of org.onosproject.net.LinkKey in project onos by opennetworkinglab.
the class NetworkConfigLinksProviderTest method testRemoveLink.
/**
* Tests removal of a link from the configuration.
*/
@Test
public void testRemoveLink() {
LinkKey key = LinkKey.linkKey(src, dst);
configListener.event(new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED, key, BasicLinkConfig.class));
assertThat(provider.configuredLinks, hasSize(1));
configListener.event(new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_REMOVED, key, BasicLinkConfig.class));
assertThat(provider.configuredLinks, hasSize(0));
}
use of org.onosproject.net.LinkKey in project onos by opennetworkinglab.
the class SimpleLinkStore method createOrUpdateLink.
@Override
public LinkEvent createOrUpdateLink(ProviderId providerId, LinkDescription linkDescription) {
LinkKey key = linkKey(linkDescription.src(), linkDescription.dst());
Map<ProviderId, LinkDescription> descs = getOrCreateLinkDescriptions(key);
synchronized (descs) {
final Link oldLink = links.get(key);
// update description
createOrUpdateLinkDescription(descs, providerId, linkDescription);
final Link newLink = composeLink(descs);
if (oldLink == null) {
return createLink(key, newLink);
}
return updateLink(key, oldLink, newLink);
}
}
Aggregations