Search in sources :

Example 1 with UiLinkId

use of org.onosproject.ui.model.topo.UiLinkId 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 2 with UiLinkId

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

the class TrafficLinkTest method emptyStats.

@Test
public void emptyStats() {
    title("emptyStats");
    UiLinkId uiLinkId = UiLinkId.uiLinkId(RA, RB);
    TrafficLink tl = new TrafficLink(uiLinkId);
    assertEquals("wrong id", EXP_RA_RB, tl.linkId());
}
Also used : UiLinkId(org.onosproject.ui.model.topo.UiLinkId) Test(org.junit.Test) AbstractUiImplTest(org.onosproject.ui.impl.AbstractUiImplTest)

Example 3 with UiLinkId

use of org.onosproject.ui.model.topo.UiLinkId 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 4 with UiLinkId

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

the class ModelCache method updateHost.

private void updateHost(UiHost uiHost, Host h) {
    UiEdgeLink existing = uiTopology.findEdgeLink(uiHost.edgeLinkId());
    // TODO: review - do we need EdgeLink now that we are creating from id only?
    EdgeLink currentElink = synthesizeLink(h);
    UiLinkId currentElinkId = uiLinkId(currentElink);
    if (existing != null) {
        if (!currentElinkId.equals(existing.id())) {
            // edge link has changed
            insertNewUiEdgeLink(currentElinkId);
            uiHost.setEdgeLinkId(currentElinkId);
            uiTopology.remove(existing);
        }
    } else {
        // no previously existing edge link
        insertNewUiEdgeLink(currentElinkId);
        uiHost.setEdgeLinkId(currentElinkId);
    }
    HostLocation hloc = h.location();
    uiHost.setLocation(hloc.deviceId(), hloc.port());
}
Also used : UiEdgeLink(org.onosproject.ui.model.topo.UiEdgeLink) DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) EdgeLink(org.onosproject.net.EdgeLink) UiEdgeLink(org.onosproject.ui.model.topo.UiEdgeLink) UiLinkId(org.onosproject.ui.model.topo.UiLinkId) HostLocation(org.onosproject.net.HostLocation)

Example 5 with UiLinkId

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

the class ModelCache method addNewHost.

private UiHost addNewHost(Host h) {
    UiHost host = new UiHost(uiTopology, h);
    uiTopology.add(host);
    EdgeLink elink = synthesizeLink(h);
    UiLinkId elinkId = uiLinkId(elink);
    host.setEdgeLinkId(elinkId);
    // add synthesized edge link to the topology
    addNewEdgeLink(elinkId);
    return host;
}
Also used : DefaultEdgeLink.createEdgeLink(org.onosproject.net.DefaultEdgeLink.createEdgeLink) EdgeLink(org.onosproject.net.EdgeLink) UiEdgeLink(org.onosproject.ui.model.topo.UiEdgeLink) UiLinkId(org.onosproject.ui.model.topo.UiLinkId) UiHost(org.onosproject.ui.model.topo.UiHost)

Aggregations

UiLinkId (org.onosproject.ui.model.topo.UiLinkId)11 UiDeviceLink (org.onosproject.ui.model.topo.UiDeviceLink)4 HashSet (java.util.HashSet)3 Test (org.junit.Test)3 DefaultEdgeLink.createEdgeLink (org.onosproject.net.DefaultEdgeLink.createEdgeLink)3 EdgeLink (org.onosproject.net.EdgeLink)3 UiEdgeLink (org.onosproject.ui.model.topo.UiEdgeLink)3 UiSynthLink (org.onosproject.ui.model.topo.UiSynthLink)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 HashMap (java.util.HashMap)2 Link (org.onosproject.net.Link)2 UiHost (org.onosproject.ui.model.topo.UiHost)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Host (org.onosproject.net.Host)1 HostLocation (org.onosproject.net.HostLocation)1 AbstractUiImplTest (org.onosproject.ui.impl.AbstractUiImplTest)1 TrafficLink (org.onosproject.ui.impl.topo.util.TrafficLink)1