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