Search in sources :

Example 1 with UiDevice

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

the class Topo2Jsonifier method json.

private ObjectNode json(String ridStr, UiDevice device) {
    ObjectNode node = objectNode().put("id", device.idAsString()).put("nodeType", DEVICE).put("type", device.type()).put("online", deviceService.isAvailable(device.id())).put("master", master(device.id())).put("layer", device.layer());
    Device d = device.backingDevice();
    if (d != null) {
        addProps(node, d);
        addGeoGridLocation(node, d);
    }
    addMetaUi(node, ridStr, device.idAsString());
    return node;
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Device(org.onosproject.net.Device) UiDevice(org.onosproject.ui.model.topo.UiDevice)

Example 2 with UiDevice

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

the class ModelCache method addNewDevice.

// === DEVICES
private UiDevice addNewDevice(Device d) {
    UiDevice device = new UiDevice(uiTopology, d);
    updateDevice(device);
    uiTopology.add(device);
    log.debug("Device {} added to topology", device);
    return device;
}
Also used : UiDevice(org.onosproject.ui.model.topo.UiDevice)

Example 3 with UiDevice

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

the class ModelCache method removeDevice.

// invoked from UiSharedTopologyModel device listener
void removeDevice(Device device) {
    DeviceId id = device.id();
    UiDevice uiDevice = uiTopology.findDevice(id);
    if (uiDevice != null) {
        uiTopology.remove(uiDevice);
        postEvent(DEVICE_REMOVED, uiDevice, MEMO_REMOVED);
    } else {
        log.warn(E_NO_ELEMENT, "device", id);
    }
}
Also used : DeviceId(org.onosproject.net.DeviceId) UiDevice(org.onosproject.ui.model.topo.UiDevice)

Example 4 with UiDevice

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

the class ModelCache method refresh.

/**
 * Refreshes the internal state.
 */
public void refresh() {
    // fix up internal linkages to ensure they are correct
    // make sure regions reflect layout containment hierarchy
    fixupContainmentHierarchy(uiTopology.nullRegion());
    uiTopology.allRegions().forEach(this::fixupContainmentHierarchy);
    // make sure devices and hosts are in the correct region
    Set<UiDevice> allDevices = uiTopology.allDevices();
    Set<UiHost> allHosts = uiTopology.allHosts();
    services.region().getRegions().forEach(r -> {
        RegionId rid = r.id();
        UiRegion region = uiTopology.findRegion(rid);
        if (region != null) {
            reconcileDevicesAndHostsWithRegion(allDevices, allHosts, rid, region);
        } else {
            log.warn("No UiRegion in topology for ID {}", rid);
        }
    });
    // what is left over, must belong to the null-region
    Set<DeviceId> leftOver = new HashSet<>(allDevices.size());
    allDevices.forEach(d -> leftOver.add(d.id()));
    uiTopology.nullRegion().reconcileDevices(leftOver);
    Set<HostId> leftOverHosts = new HashSet<>(allHosts.size());
    allHosts.forEach(h -> leftOverHosts.add(h.id()));
    uiTopology.nullRegion().reconcileHosts(leftOverHosts);
    // now that we have correct region hierarchy, and devices are in their
    // respective regions, we can compute synthetic links for each region.
    uiTopology.computeSynthLinks();
}
Also used : DeviceId(org.onosproject.net.DeviceId) UiRegion(org.onosproject.ui.model.topo.UiRegion) UiDevice(org.onosproject.ui.model.topo.UiDevice) UiHost(org.onosproject.ui.model.topo.UiHost) RegionId(org.onosproject.net.region.RegionId) HostId(org.onosproject.net.HostId) HashSet(java.util.HashSet)

Example 5 with UiDevice

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

the class ModelCache method reconcileDevicesAndHostsWithRegion.

private void reconcileDevicesAndHostsWithRegion(Set<UiDevice> allDevices, Set<UiHost> allHosts, RegionId rid, UiRegion region) {
    Set<DeviceId> deviceIds = services.region().getRegionDevices(rid);
    Set<HostId> hostIds = new HashSet<>();
    region.reconcileDevices(deviceIds);
    deviceIds.forEach(devId -> {
        UiDevice dev = uiTopology.findDevice(devId);
        if (dev != null) {
            dev.setRegionId(rid);
            allDevices.remove(dev);
        } else {
            log.warn("Region device ID {} but no UiDevice in topology", devId);
        }
        Set<Host> hosts = services.host().getConnectedHosts(devId);
        for (Host h : hosts) {
            HostId hid = h.id();
            hostIds.add(hid);
            UiHost host = uiTopology.findHost(hid);
            if (host != null) {
                host.setRegionId(rid);
                allHosts.remove(host);
            } else {
                log.warn("Region host ID {} but no UiHost in topology", hid);
            }
        }
    });
    region.reconcileHosts(hostIds);
}
Also used : DeviceId(org.onosproject.net.DeviceId) UiDevice(org.onosproject.ui.model.topo.UiDevice) UiHost(org.onosproject.ui.model.topo.UiHost) Host(org.onosproject.net.Host) UiHost(org.onosproject.ui.model.topo.UiHost) HostId(org.onosproject.net.HostId) HashSet(java.util.HashSet)

Aggregations

UiDevice (org.onosproject.ui.model.topo.UiDevice)8 DeviceId (org.onosproject.net.DeviceId)5 HostId (org.onosproject.net.HostId)3 UiHost (org.onosproject.ui.model.topo.UiHost)3 HashSet (java.util.HashSet)2 Device (org.onosproject.net.Device)2 RegionId (org.onosproject.net.region.RegionId)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Test (org.junit.Test)1 Host (org.onosproject.net.Host)1 UiRegion (org.onosproject.ui.model.topo.UiRegion)1