use of org.onosproject.net.Host 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);
}
use of org.onosproject.net.Host in project onos by opennetworkinglab.
the class ModelCache method loadHosts.
private void loadHosts() {
for (Host h : services.host().getHosts()) {
UiHost host = addNewHost(h);
updateHost(host, h);
}
}
use of org.onosproject.net.Host 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());
}
Aggregations