Search in sources :

Example 1 with UiDeviceLink

use of org.onosproject.ui.model.topo.UiDeviceLink in project onos by opennetworkinglab.

the class ModelCache method addNewDeviceLink.

// === LINKS ===
private UiDeviceLink addNewDeviceLink(UiLinkId id) {
    UiDeviceLink uiDeviceLink = new UiDeviceLink(uiTopology, id);
    uiTopology.add(uiDeviceLink);
    return uiDeviceLink;
}
Also used : UiDeviceLink(org.onosproject.ui.model.topo.UiDeviceLink)

Example 2 with UiDeviceLink

use of org.onosproject.ui.model.topo.UiDeviceLink in project onos by opennetworkinglab.

the class ModelCache method removeDeviceLink.

// invoked from UiSharedTopologyModel link listener
void removeDeviceLink(Link link) {
    UiLinkId id = uiLinkId(link);
    UiDeviceLink uiDeviceLink = uiTopology.findDeviceLink(id);
    if (uiDeviceLink != null) {
        boolean remaining = uiDeviceLink.detachBackingLink(link);
        if (remaining) {
            postEvent(LINK_ADDED_OR_UPDATED, uiDeviceLink, MEMO_UPDATED);
        } else {
            uiTopology.remove(uiDeviceLink);
            postEvent(LINK_REMOVED, uiDeviceLink, MEMO_REMOVED);
        }
    } else {
        log.warn(E_NO_ELEMENT, "Device link", id);
    }
}
Also used : UiDeviceLink(org.onosproject.ui.model.topo.UiDeviceLink) UiLinkId(org.onosproject.ui.model.topo.UiLinkId)

Example 3 with UiDeviceLink

use of org.onosproject.ui.model.topo.UiDeviceLink in project onos by opennetworkinglab.

the class ModelCacheTest method addLinks.

@Test
public void addLinks() {
    title("addLinks");
    Iterator<Link> iter = makeLinkPair(LINKS_2_7).iterator();
    Link link1 = iter.next();
    Link link2 = iter.next();
    print(link1);
    print(link2);
    UiLinkId idA2B = uiLinkId(link1);
    UiLinkId idB2A = uiLinkId(link2);
    // remember, link IDs are canonicalized
    assertEquals("not same link ID", idA2B, idB2A);
    // we've established that the ID is the same for both
    UiLinkId linkId = idA2B;
    cache.addOrUpdateDeviceLink(link1);
    dispatcher.assertLast(Type.LINK_ADDED_OR_UPDATED, linkId.toString());
    dispatcher.assertEventCount(1);
    assertEquals("unex # links", 1, cache.deviceLinkCount());
    UiDeviceLink link = cache.accessDeviceLink(linkId);
    assertEquals("dev A not d2", DEVID_2, link.deviceA());
    assertEquals("dev B not d7", DEVID_7, link.deviceB());
    assertEquals("wrong backing link A-B", link1, link.linkAtoB());
    assertEquals("backing link B-A?", null, link.linkBtoA());
    cache.addOrUpdateDeviceLink(link2);
    dispatcher.assertLast(Type.LINK_ADDED_OR_UPDATED, linkId.toString());
    dispatcher.assertEventCount(2);
    // NOTE: yes! expect 1 UiLink
    assertEquals("unex # links", 1, cache.deviceLinkCount());
    link = cache.accessDeviceLink(linkId);
    assertEquals("dev A not d2", DEVID_2, link.deviceA());
    assertEquals("dev B not d7", DEVID_7, link.deviceB());
    assertEquals("wrong backing link A-B", link1, link.linkAtoB());
    assertEquals("wrong backing link B-A", link2, link.linkBtoA());
    // now remove links one at a time
    cache.removeDeviceLink(link1);
    // NOTE: yes! ADD_OR_UPDATE, since the link was updated
    dispatcher.assertLast(Type.LINK_ADDED_OR_UPDATED, linkId.toString());
    dispatcher.assertEventCount(3);
    // NOTE: yes! expect 1 UiLink (still)
    assertEquals("unex # links", 1, cache.deviceLinkCount());
    link = cache.accessDeviceLink(linkId);
    assertEquals("dev A not d2", DEVID_2, link.deviceA());
    assertEquals("dev B not d7", DEVID_7, link.deviceB());
    assertEquals("backing link A-B?", null, link.linkAtoB());
    assertEquals("wrong backing link B-A", link2, link.linkBtoA());
    // remove final link
    cache.removeDeviceLink(link2);
    dispatcher.assertLast(Type.LINK_REMOVED, linkId.toString());
    dispatcher.assertEventCount(4);
    // NOTE: finally link should be removed from cache
    assertEquals("unex # links", 0, cache.deviceLinkCount());
}
Also used : UiDeviceLink(org.onosproject.ui.model.topo.UiDeviceLink) UiLinkId(org.onosproject.ui.model.topo.UiLinkId) Link(org.onosproject.net.Link) UiDeviceLink(org.onosproject.ui.model.topo.UiDeviceLink) Test(org.junit.Test)

Example 4 with UiDeviceLink

use of org.onosproject.ui.model.topo.UiDeviceLink in project onos by opennetworkinglab.

the class ModelCache method loadDeviceLinks.

private void loadDeviceLinks() {
    for (Link link : services.link().getLinks()) {
        UiLinkId id = uiLinkId(link);
        UiDeviceLink uiDeviceLink = uiTopology.findDeviceLink(id);
        if (uiDeviceLink == null) {
            uiDeviceLink = addNewDeviceLink(id);
        }
        updateDeviceLink(uiDeviceLink, link);
    }
}
Also used : UiDeviceLink(org.onosproject.ui.model.topo.UiDeviceLink) UiLinkId(org.onosproject.ui.model.topo.UiLinkId) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) Link(org.onosproject.net.Link) UiDeviceLink(org.onosproject.ui.model.topo.UiDeviceLink) UiSynthLink(org.onosproject.ui.model.topo.UiSynthLink) EdgeLink(org.onosproject.net.EdgeLink) UiEdgeLink(org.onosproject.ui.model.topo.UiEdgeLink)

Example 5 with UiDeviceLink

use of org.onosproject.ui.model.topo.UiDeviceLink in project onos by opennetworkinglab.

the class ModelCache method addOrUpdateDeviceLink.

// invoked from UiSharedTopologyModel link listener
void addOrUpdateDeviceLink(Link link) {
    UiLinkId id = uiLinkId(link);
    String memo = MEMO_UPDATED;
    UiDeviceLink uiDeviceLink = uiTopology.findDeviceLink(id);
    if (uiDeviceLink == null) {
        uiDeviceLink = addNewDeviceLink(id);
        memo = MEMO_ADDED;
    }
    updateDeviceLink(uiDeviceLink, link);
    postEvent(LINK_ADDED_OR_UPDATED, uiDeviceLink, memo);
}
Also used : UiDeviceLink(org.onosproject.ui.model.topo.UiDeviceLink) UiLinkId(org.onosproject.ui.model.topo.UiLinkId)

Aggregations

UiDeviceLink (org.onosproject.ui.model.topo.UiDeviceLink)5 UiLinkId (org.onosproject.ui.model.topo.UiLinkId)4 Link (org.onosproject.net.Link)2 Test (org.junit.Test)1 DefaultEdgeLink.createEdgeLink (org.onosproject.net.DefaultEdgeLink.createEdgeLink)1 EdgeLink (org.onosproject.net.EdgeLink)1 UiEdgeLink (org.onosproject.ui.model.topo.UiEdgeLink)1 UiSynthLink (org.onosproject.ui.model.topo.UiSynthLink)1