Search in sources :

Example 26 with LinkKey

use of org.onosproject.net.LinkKey in project onos by opennetworkinglab.

the class SimpleLinkStoreTest method testEvents.

// If Delegates should be called only on remote events,
// then Simple* should never call them, thus not test required.
@Ignore("Ignore until Delegate spec. is clear.")
@Test
public final void testEvents() throws InterruptedException {
    final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
    final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
    final LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
    final CountDownLatch addLatch = new CountDownLatch(1);
    LinkStoreDelegate checkAdd = event -> {
        assertEquals(LINK_ADDED, event.type());
        assertLink(linkId1, INDIRECT, event.subject());
        addLatch.countDown();
    };
    final CountDownLatch updateLatch = new CountDownLatch(1);
    LinkStoreDelegate checkUpdate = event -> {
        assertEquals(LINK_UPDATED, event.type());
        assertLink(linkId1, DIRECT, event.subject());
        updateLatch.countDown();
    };
    final CountDownLatch removeLatch = new CountDownLatch(1);
    LinkStoreDelegate checkRemove = event -> {
        assertEquals(LINK_REMOVED, event.type());
        assertLink(linkId1, DIRECT, event.subject());
        removeLatch.countDown();
    };
    linkStore.setDelegate(checkAdd);
    putLink(linkId1, INDIRECT);
    assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS));
    linkStore.unsetDelegate(checkAdd);
    linkStore.setDelegate(checkUpdate);
    putLink(linkId1, DIRECT);
    assertTrue("Update event fired", updateLatch.await(1, TimeUnit.SECONDS));
    linkStore.unsetDelegate(checkUpdate);
    linkStore.setDelegate(checkRemove);
    linkStore.removeOrDownLink(d1P1, d2P2);
    assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS));
}
Also used : Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) LinkEvent(org.onosproject.net.link.LinkEvent) PortNumber(org.onosproject.net.PortNumber) HashMap(java.util.HashMap) AnnotationKeys(org.onosproject.net.AnnotationKeys) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Link(org.onosproject.net.Link) ConnectPoint(org.onosproject.net.ConnectPoint) NetTestTools.assertAnnotationsEquals(org.onosproject.net.NetTestTools.assertAnnotationsEquals) Type(org.onosproject.net.link.LinkEvent.Type) After(org.junit.After) Map(java.util.Map) DeviceId.deviceId(org.onosproject.net.DeviceId.deviceId) Before(org.junit.Before) LinkKey(org.onosproject.net.LinkKey) AfterClass(org.junit.AfterClass) LinkStoreDelegate(org.onosproject.net.link.LinkStoreDelegate) Set(java.util.Set) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) TimeUnit(java.util.concurrent.TimeUnit) CountDownLatch(java.util.concurrent.CountDownLatch) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Ignore(org.junit.Ignore) SparseAnnotations(org.onosproject.net.SparseAnnotations) LinkStore(org.onosproject.net.link.LinkStore) DeviceId(org.onosproject.net.DeviceId) Assert(org.junit.Assert) Type(org.onosproject.net.Link.Type) LinkKey(org.onosproject.net.LinkKey) LinkStoreDelegate(org.onosproject.net.link.LinkStoreDelegate) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectPoint(org.onosproject.net.ConnectPoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 27 with LinkKey

use of org.onosproject.net.LinkKey in project onos by opennetworkinglab.

the class SimpleLinkStoreTest method testGetDeviceEgressLinks.

@Test
public final void testGetDeviceEgressLinks() {
    LinkKey linkId1 = LinkKey.linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
    LinkKey linkId2 = LinkKey.linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
    LinkKey linkId3 = LinkKey.linkKey(new ConnectPoint(DID1, P2), new ConnectPoint(DID2, P3));
    putLink(linkId1, DIRECT);
    putLink(linkId2, DIRECT);
    putLink(linkId3, DIRECT);
    // DID1,P1 => DID2,P2
    // DID2,P2 => DID1,P1
    // DID1,P2 => DID2,P3
    Set<Link> links1 = linkStore.getDeviceEgressLinks(DID1);
    assertEquals(2, links1.size());
    // check
    Set<Link> links2 = linkStore.getDeviceEgressLinks(DID2);
    assertEquals(1, links2.size());
    assertLink(linkId2, DIRECT, links2.iterator().next());
}
Also used : LinkKey(org.onosproject.net.LinkKey) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) Test(org.junit.Test)

Example 28 with LinkKey

use of org.onosproject.net.LinkKey in project onos by opennetworkinglab.

the class NetworkConfigLinksProviderTest method testConfiguredLink.

/**
 * Tests discovery of an expected link.
 */
@Test
public void testConfiguredLink() {
    LinkKey key = LinkKey.linkKey(src, dst);
    configListener.event(new NetworkConfigEvent(NetworkConfigEvent.Type.CONFIG_ADDED, key, BasicLinkConfig.class));
    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());
    LinkDescription linkDescription = providerService.discoveredLinkDescriptions().get(key);
    assertThat(linkDescription, notNullValue());
    assertThat(linkDescription.isExpected(), is(true));
}
Also used : LinkKey(org.onosproject.net.LinkKey) NetworkConfigEvent(org.onosproject.net.config.NetworkConfigEvent) LinkDescription(org.onosproject.net.link.LinkDescription) DeviceId(org.onosproject.net.DeviceId) PacketContext(org.onosproject.net.packet.PacketContext) BasicLinkConfig(org.onosproject.net.config.basics.BasicLinkConfig) Test(org.junit.Test)

Example 29 with LinkKey

use of org.onosproject.net.LinkKey in project onos by opennetworkinglab.

the class ECLinkStoreTest method testEvents.

// If Delegates should be called only on remote events,
// then Simple* should never call them, thus not test required.
@Ignore("Ignore until Delegate spec. is clear.")
@Test
public final void testEvents() throws InterruptedException {
    final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
    final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
    final LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
    final CountDownLatch addLatch = new CountDownLatch(1);
    LinkStoreDelegate checkAdd = event -> {
        assertEquals(LINK_ADDED, event.type());
        assertLink(linkId1, INDIRECT, event.subject());
        addLatch.countDown();
    };
    final CountDownLatch updateLatch = new CountDownLatch(1);
    LinkStoreDelegate checkUpdate = event -> {
        assertEquals(LINK_UPDATED, event.type());
        assertLink(linkId1, DIRECT, event.subject());
        updateLatch.countDown();
    };
    final CountDownLatch removeLatch = new CountDownLatch(1);
    LinkStoreDelegate checkRemove = event -> {
        assertEquals(LINK_REMOVED, event.type());
        assertLink(linkId1, DIRECT, event.subject());
        removeLatch.countDown();
    };
    linkStore.setDelegate(checkAdd);
    putLink(linkId1, INDIRECT);
    assertTrue("Add event fired", addLatch.await(1, TimeUnit.SECONDS));
    linkStore.unsetDelegate(checkAdd);
    linkStore.setDelegate(checkUpdate);
    putLink(linkId1, DIRECT);
    assertTrue("Update event fired", updateLatch.await(1, TimeUnit.SECONDS));
    linkStore.unsetDelegate(checkUpdate);
    linkStore.setDelegate(checkRemove);
    linkStore.removeLink(d1P1, d2P2);
    assertTrue("Remove event fired", removeLatch.await(1, TimeUnit.SECONDS));
}
Also used : LINK_ADDED(org.onosproject.net.link.LinkEvent.Type.LINK_ADDED) DeviceClockServiceAdapter(org.onosproject.net.device.DeviceClockServiceAdapter) PortNumber(org.onosproject.net.PortNumber) DefaultLinkDescription(org.onosproject.net.link.DefaultLinkDescription) Link(org.onosproject.net.Link) DefaultControllerNode(org.onosproject.cluster.DefaultControllerNode) ConnectPoint(org.onosproject.net.ConnectPoint) LINK_REMOVED(org.onosproject.net.link.LinkEvent.Type.LINK_REMOVED) INDIRECT(org.onosproject.net.Link.Type.INDIRECT) After(org.junit.After) Map(java.util.Map) MessageSubject(org.onosproject.store.cluster.messaging.MessageSubject) DeviceId.deviceId(org.onosproject.net.DeviceId.deviceId) LinkKey(org.onosproject.net.LinkKey) NodeId(org.onosproject.cluster.NodeId) LinkDescription(org.onosproject.net.link.LinkDescription) AfterClass(org.junit.AfterClass) LinkStoreDelegate(org.onosproject.net.link.LinkStoreDelegate) Set(java.util.Set) CountDownLatch(java.util.concurrent.CountDownLatch) DeviceClockService(org.onosproject.net.device.DeviceClockService) SparseAnnotations(org.onosproject.net.SparseAnnotations) ClusterCommunicationService(org.onosproject.store.cluster.messaging.ClusterCommunicationService) DeviceId(org.onosproject.net.DeviceId) DIRECT(org.onosproject.net.Link.Type.DIRECT) Iterables(com.google.common.collect.Iterables) BeforeClass(org.junit.BeforeClass) LinkEvent(org.onosproject.net.link.LinkEvent) HashMap(java.util.HashMap) ControllerNode(org.onosproject.cluster.ControllerNode) NetTestTools.assertAnnotationsEquals(org.onosproject.net.NetTestTools.assertAnnotationsEquals) Timestamp(org.onosproject.store.Timestamp) ACTIVE(org.onosproject.cluster.ControllerNode.State.ACTIVE) ExecutorService(java.util.concurrent.ExecutorService) LINK_UPDATED(org.onosproject.net.link.LinkEvent.Type.LINK_UPDATED) Before(org.junit.Before) IpAddress(org.onlab.packet.IpAddress) StaticClusterService(org.onosproject.store.cluster.StaticClusterService) ClusterMessageHandler(org.onosproject.store.cluster.messaging.ClusterMessageHandler) Test(org.junit.Test) ProviderId(org.onosproject.net.provider.ProviderId) MastershipBasedTimestamp(org.onosproject.store.impl.MastershipBasedTimestamp) EasyMock(org.easymock.EasyMock) TimeUnit(java.util.concurrent.TimeUnit) AtomicLong(java.util.concurrent.atomic.AtomicLong) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Ignore(org.junit.Ignore) EDGE(org.onosproject.net.Link.Type.EDGE) LinkStore(org.onosproject.net.link.LinkStore) MastershipServiceAdapter(org.onosproject.mastership.MastershipServiceAdapter) Assert(org.junit.Assert) Type(org.onosproject.net.Link.Type) LinkKey(org.onosproject.net.LinkKey) LinkStoreDelegate(org.onosproject.net.link.LinkStoreDelegate) CountDownLatch(java.util.concurrent.CountDownLatch) ConnectPoint(org.onosproject.net.ConnectPoint) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 30 with LinkKey

use of org.onosproject.net.LinkKey in project onos by opennetworkinglab.

the class ECLinkStoreTest method testGetLink.

@Test
public final void testGetLink() {
    ConnectPoint src = new ConnectPoint(DID1, P1);
    ConnectPoint dst = new ConnectPoint(DID2, P2);
    LinkKey linkId1 = LinkKey.linkKey(src, dst);
    putLink(linkId1, DIRECT);
    Link link = linkStore.getLink(src, dst);
    assertLink(linkId1, DIRECT, link);
    assertNull("There shouldn't be reverese link", linkStore.getLink(dst, src));
}
Also used : LinkKey(org.onosproject.net.LinkKey) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) 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