Search in sources :

Example 96 with Host

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

Example 97 with Host

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

Example 98 with Host

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

Aggregations

Host (org.onosproject.net.Host)98 IpAddress (org.onlab.packet.IpAddress)40 MacAddress (org.onlab.packet.MacAddress)40 HostService (org.onosproject.net.host.HostService)34 ConnectPoint (org.onosproject.net.ConnectPoint)33 Set (java.util.Set)29 VlanId (org.onlab.packet.VlanId)29 HostLocation (org.onosproject.net.HostLocation)28 HostId (org.onosproject.net.HostId)27 Logger (org.slf4j.Logger)27 Interface (org.onosproject.net.intf.Interface)25 LoggerFactory (org.slf4j.LoggerFactory)25 ImmutableSet (com.google.common.collect.ImmutableSet)23 DeviceId (org.onosproject.net.DeviceId)23 TrafficSelector (org.onosproject.net.flow.TrafficSelector)22 DefaultHostDescription (org.onosproject.net.host.DefaultHostDescription)22 HostDescription (org.onosproject.net.host.HostDescription)22 List (java.util.List)21 Test (org.junit.Test)21 DefaultHost (org.onosproject.net.DefaultHost)21