Search in sources :

Example 11 with LinkKey

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

the class BasicLinkConfigTest method testConstruction.

/**
 * Tests construction, setters and getters of a BasicLinkConfig object.
 */
@Test
public void testConstruction() {
    BasicLinkConfig config = new BasicLinkConfig();
    ConfigApplyDelegate delegate = configApply -> {
    };
    ObjectMapper mapper = new ObjectMapper();
    LinkKey linkKey = LinkKey.linkKey(NetTestTools.connectPoint("device1", 1), NetTestTools.connectPoint("device2", 2));
    config.init(linkKey, "KEY", JsonNodeFactory.instance.objectNode(), mapper, delegate);
    config.bandwidth(BANDWIDTH).jitter(JITTER).delay(DELAY).loss(LOSS).availability(AVAILABILITY).flapping(FLAPPING).isDurable(FALSE).metric(METRIC).type(Link.Type.DIRECT).latency(LATENCY).isBidirectional(FALSE).isMetered(TRUE).tier(TIER).meteredUsage(METERED_USAGE);
    assertThat(config.bandwidth(), is(BANDWIDTH));
    assertThat(config.jitter(), is(JITTER));
    assertThat(config.delay(), is(DELAY));
    assertThat(config.loss(), is(LOSS));
    assertThat(config.availability(), is(AVAILABILITY));
    assertThat(config.flapping(), is(FLAPPING));
    assertThat(config.isDurable(), is(FALSE));
    assertThat(config.metric(), is(METRIC));
    assertThat(config.type(), is(Link.Type.DIRECT));
    assertThat(config.latency(), is(LATENCY));
    assertThat(config.isBidirectional(), is(FALSE));
    assertThat(config.isValid(), is(true));
    assertThat(config.isMetered(), is(TRUE));
    assertThat(config.tier(), is(TIER));
    assertThat(config.meteredUsage(), is(METERED_USAGE));
}
Also used : FALSE(java.lang.Boolean.FALSE) NetTestTools(org.onosproject.net.NetTestTools) JsonNodeFactory(com.fasterxml.jackson.databind.node.JsonNodeFactory) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Duration(java.time.Duration) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test) Matchers.is(org.hamcrest.Matchers.is) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Link(org.onosproject.net.Link) TRUE(java.lang.Boolean.TRUE) LinkKey(org.onosproject.net.LinkKey) LinkKey(org.onosproject.net.LinkKey) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ConfigApplyDelegate(org.onosproject.net.config.ConfigApplyDelegate) Test(org.junit.Test)

Example 12 with LinkKey

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

the class SubjectFactoriesTest method testLinkFactory.

@Test
public void testLinkFactory() {
    SubjectFactory<LinkKey> linkFactory = SubjectFactories.LINK_SUBJECT_FACTORY;
    assertThat(linkFactory, notNullValue());
    String deviceName1 = "d1";
    String deviceName2 = "d2";
    String ofDeviceName1 = "of:" + deviceName1;
    String ofDeviceName2 = "of:" + deviceName2;
    int devicePort1 = 2;
    int devicePort2 = 3;
    String cpString1 = ofDeviceName1 + "/" + Integer.toString(devicePort1);
    String cpString2 = ofDeviceName2 + "/" + Integer.toString(devicePort2);
    ConnectPoint cp1 = NetTestTools.connectPoint(deviceName1, devicePort1);
    ConnectPoint cp2 = NetTestTools.connectPoint(deviceName2, devicePort2);
    String linkString1 = cpString1 + '-' + cpString2;
    LinkKey key1 = LinkKey.linkKey(cp1, cp2);
    LinkKey createdLink1 = linkFactory.createSubject(linkString1);
    assertThat(createdLink1.asId(), is(linkString1));
    assertThat(linkFactory.subjectKey(key1), is(linkString1));
}
Also used : LinkKey(org.onosproject.net.LinkKey) ConnectPoint(org.onosproject.net.ConnectPoint) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 13 with LinkKey

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

the class ECLinkStoreTest method testGetLinks.

@Test
public final void testGetLinks() {
    assertEquals("initialy empty", 0, Iterables.size(linkStore.getLinks()));
    LinkKey linkId1 = LinkKey.linkKey(new ConnectPoint(DID1, P1), new ConnectPoint(DID2, P2));
    LinkKey linkId2 = LinkKey.linkKey(new ConnectPoint(DID2, P2), new ConnectPoint(DID1, P1));
    putLink(linkId1, DIRECT);
    putLink(linkId2, DIRECT);
    putLink(linkId1, DIRECT);
    assertEquals("expecting 2 unique link", 2, Iterables.size(linkStore.getLinks()));
    Map<LinkKey, Link> links = new HashMap<>();
    for (Link link : linkStore.getLinks()) {
        links.put(LinkKey.linkKey(link), link);
    }
    assertLink(linkId1, DIRECT, links.get(linkId1));
    assertLink(linkId2, DIRECT, links.get(linkId2));
}
Also used : LinkKey(org.onosproject.net.LinkKey) HashMap(java.util.HashMap) ConnectPoint(org.onosproject.net.ConnectPoint) Link(org.onosproject.net.Link) Test(org.junit.Test)

Example 14 with LinkKey

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

the class ECLinkStoreTest method testRemoveLink.

@Test
public final void testRemoveLink() {
    final ConnectPoint d1P1 = new ConnectPoint(DID1, P1);
    final ConnectPoint d2P2 = new ConnectPoint(DID2, P2);
    LinkKey linkId1 = LinkKey.linkKey(d1P1, d2P2);
    LinkKey linkId2 = LinkKey.linkKey(d2P2, d1P1);
    putLink(linkId1, DIRECT, A1);
    putLink(linkId2, DIRECT, A2);
    // DID1,P1 => DID2,P2
    // DID2,P2 => DID1,P1
    // DID1,P2 => DID2,P3
    LinkEvent event = linkStore.removeLink(d1P1, d2P2);
    assertEquals(LINK_REMOVED, event.type());
    assertAnnotationsEquals(event.subject().annotations(), A1);
    LinkEvent event2 = linkStore.removeLink(d1P1, d2P2);
    assertNull(event2);
    assertLink(linkId2, DIRECT, linkStore.getLink(d2P2, d1P1));
    assertAnnotationsEquals(linkStore.getLink(d2P2, d1P1).annotations(), A2);
    // annotations, etc. should not survive remove
    putLink(linkId1, DIRECT);
    assertLink(linkId1, DIRECT, linkStore.getLink(d1P1, d2P2));
    assertAnnotationsEquals(linkStore.getLink(d1P1, d2P2).annotations());
}
Also used : LinkKey(org.onosproject.net.LinkKey) LinkEvent(org.onosproject.net.link.LinkEvent) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Example 15 with LinkKey

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

the class ECLinkStoreTest method testGetDeviceIngressLinks.

@Test
public final void testGetDeviceIngressLinks() {
    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.getDeviceIngressLinks(DID2);
    assertEquals(2, links1.size());
    // check
    Set<Link> links2 = linkStore.getDeviceIngressLinks(DID1);
    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)

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