Search in sources :

Example 6 with UiLinkId

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;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) UiLinkId(org.onosproject.ui.model.topo.UiLinkId) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) UiSynthLink(org.onosproject.ui.model.topo.UiSynthLink) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode)

Example 7 with UiLinkId

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;
}
Also used : TrafficLink(org.onosproject.ui.impl.topo.util.TrafficLink) UiLinkId(org.onosproject.ui.model.topo.UiLinkId) HashMap(java.util.HashMap) UiSynthLink(org.onosproject.ui.model.topo.UiSynthLink) HashSet(java.util.HashSet)

Example 8 with UiLinkId

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()));
    }
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) UiLinkId(org.onosproject.ui.model.topo.UiLinkId) JsonNode(com.fasterxml.jackson.databind.JsonNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) HashSet(java.util.HashSet)

Example 9 with UiLinkId

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());
}
Also used : UiLinkId(org.onosproject.ui.model.topo.UiLinkId) Host(org.onosproject.net.Host) UiHost(org.onosproject.ui.model.topo.UiHost) Test(org.junit.Test)

Example 10 with UiLinkId

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

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