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;
}
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);
}
}
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());
}
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);
}
}
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);
}
Aggregations