use of org.onosproject.ui.model.topo.UiLinkId in project onos by opennetworkinglab.
the class Topo2Jsonifier method collateSynthLinks.
private ArrayNode collateSynthLinks(List<UiSynthLink> links) {
Map<UiLinkId, Set<UiSynthLink>> collation = new HashMap<>();
// first, group together the synthlinks into sets per ID...
for (UiSynthLink sl : links) {
UiLinkId id = sl.link().id();
Set<UiSynthLink> rollup = collation.computeIfAbsent(id, k -> new HashSet<>());
rollup.add(sl);
}
// now add json nodes per set, and return the array of them
ArrayNode array = arrayNode();
for (UiLinkId id : collation.keySet()) {
array.add(json(collation.get(id)));
}
return array;
}
use of org.onosproject.ui.model.topo.UiLinkId in project onos by opennetworkinglab.
the class Traffic2Monitor method doAggregation.
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
// -- link aggregation
@Override
protected Set<TrafficLink> doAggregation(Set<TrafficLink> linksWithTraffic) {
log.debug("Need to aggregate {} links", linksWithTraffic.size());
// first, retrieve from the shared topology model those synth links that
// are part of the region currently being viewed by the user...
Map<UiLinkId, UiSynthLink> synthLinkMap = msgHandler.retrieveRelevantSynthLinks();
// NOTE: compute Set<TrafficLink> which represents the consolidated links
Map<UiLinkId, TrafficLink> mappedByUiLinkId = new HashMap<>();
for (TrafficLink tl : linksWithTraffic) {
UiLinkId tlid = uiLinkId(tl.key());
UiSynthLink sl = synthLinkMap.get(tlid);
if (sl != null) {
UiLinkId aggrid = sl.link().id();
TrafficLink aggregated = mappedByUiLinkId.computeIfAbsent(aggrid, TrafficLink::new);
aggregated.mergeStats(tl);
}
}
Set<TrafficLink> result = new HashSet<>();
result.addAll(mappedByUiLinkId.values());
return result;
}
use of org.onosproject.ui.model.topo.UiLinkId in project onos by opennetworkinglab.
the class Topo2JsonifierTest method validateLinkRollup.
private void validateLinkRollup(ObjectNode link, UiLinkId id, UiLinkId... expInRollup) {
String actId = link.get("id").asText();
assertEquals("unexp id", id.toString(), actId);
Set<String> rollupIds = new HashSet<>();
ArrayNode rollupArray = (ArrayNode) link.get("rollup");
for (JsonNode n : rollupArray) {
ObjectNode o = (ObjectNode) n;
rollupIds.add(o.get("id").asText());
}
for (UiLinkId expId : expInRollup) {
assertTrue("missing exp id: " + expId, rollupIds.contains(expId.toString()));
}
}
use of org.onosproject.ui.model.topo.UiLinkId in project onos by opennetworkinglab.
the class ModelCacheTest method addHosts.
@Test
public void addHosts() {
title("addHosts");
assertHostLinkCounts(0, 0);
Host hostA = createHost(DEV_1, 101, "a");
Host hostB = createHost(DEV_1, 102, "b");
// add a host
cache.addOrUpdateHost(hostA);
UiLinkId hostALinkId = cache.accessHost(hostA.id()).edgeLinkId();
dispatcher.assertLast(Type.LINK_ADDED_OR_UPDATED, hostALinkId.toString());
dispatcher.assertEventCount(2);
assertHostLinkCounts(1, 1);
assertLocation(hostA.id(), DEVID_1, 101);
// add a second host
cache.addOrUpdateHost(hostB);
UiLinkId hostBLinkId = cache.accessHost(hostB.id()).edgeLinkId();
dispatcher.assertLast(Type.LINK_ADDED_OR_UPDATED, hostBLinkId.toString());
dispatcher.assertEventCount(4);
assertHostLinkCounts(2, 2);
assertLocation(hostB.id(), DEVID_1, 102);
// update the first host
cache.addOrUpdateHost(hostA);
dispatcher.assertLast(Type.LINK_ADDED_OR_UPDATED, hostALinkId.toString());
dispatcher.assertEventCount(6);
assertHostLinkCounts(2, 2);
assertLocation(hostA.id(), DEVID_1, 101);
print(cache.dumpString());
// remove the second host
cache.removeHost(hostB);
dispatcher.assertLast(Type.HOST_REMOVED, hostB.id().toString());
dispatcher.assertEventCount(8);
assertHostLinkCounts(1, 1);
assertNull("still host B?", cache.accessHost(hostB.id()));
print(cache.dumpString());
// first, verify where host A is currently residing
assertLocation(hostA.id(), DEVID_1, 101);
// now let's move hostA to a different port
Host movedHost = createHost(DEV_1, 200, "a");
print(hostA);
print(movedHost);
cache.moveHost(movedHost, hostA);
dispatcher.assertLast(Type.HOST_MOVED, hostA.id().toString());
dispatcher.assertEventCount(9);
assertHostLinkCounts(1, 1);
assertLocation(hostA.id(), DEVID_1, 200);
print(cache.dumpString());
// finally, let's move the host to a different device and port
Host movedAgain = createHost(DEV_8, 800, "a");
cache.moveHost(movedAgain, movedHost);
dispatcher.assertLast(Type.HOST_MOVED, hostA.id().toString());
dispatcher.assertEventCount(10);
assertHostLinkCounts(1, 1);
assertLocation(hostA.id(), DEVID_8, 800);
print(cache.dumpString());
}
use of org.onosproject.ui.model.topo.UiLinkId 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);
}
}
Aggregations