Search in sources :

Example 46 with LinkKey

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);
}
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 47 with LinkKey

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);
}
Also used : LinkKey(org.onosproject.net.LinkKey) LinkDiscovery(org.onosproject.provider.lldpcommon.LinkDiscovery) LinkedList(java.util.LinkedList)

Example 48 with LinkKey

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));
}
Also used : LinkKey(org.onosproject.net.LinkKey) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) PacketContext(org.onosproject.net.packet.PacketContext) Test(org.junit.Test)

Example 49 with LinkKey

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));
}
Also used : LinkKey(org.onosproject.net.LinkKey) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) BasicLinkConfig(org.onosproject.net.config.basics.BasicLinkConfig) Test(org.junit.Test)

Example 50 with LinkKey

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);
    }
}
Also used : ProviderId(org.onosproject.net.provider.ProviderId) LinkKey(org.onosproject.net.LinkKey) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) LinkDescription(org.onosproject.net.link.LinkDescription) Link(org.onosproject.net.Link) DefaultLink(org.onosproject.net.DefaultLink)

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