Search in sources :

Example 16 with HostEvent

use of org.onosproject.net.host.HostEvent in project onos by opennetworkinglab.

the class VplsManagerTest method hostAddEventTest.

/**
 * Trigger host event listener by HOST_ADDED event.
 */
@Test
public void hostAddEventTest() {
    VplsData vplsData = vplsManager.createVpls(VPLS1, NONE);
    vplsManager.addInterface(vplsData, V100H1);
    HostEvent hostEvent = new HostEvent(HostEvent.Type.HOST_ADDED, V100HOST1);
    hostService.postHostEvent(hostEvent);
    vplsData = vplsStore.getVpls(VPLS1);
    assertEquals(UPDATING, vplsData.state());
}
Also used : HostEvent(org.onosproject.net.host.HostEvent) VplsData(org.onosproject.vpls.api.VplsData) Test(org.junit.Test)

Example 17 with HostEvent

use of org.onosproject.net.host.HostEvent in project onos by opennetworkinglab.

the class SimpleHostStore method updateHost.

// checks for type of update to host, sends appropriate event
private HostEvent updateHost(ProviderId providerId, StoredHost host, HostDescription descr, boolean replaceIps) {
    HostEvent event;
    if (!host.location().equals(descr.location())) {
        host.setLocation(descr.location());
        return new HostEvent(HOST_MOVED, host);
    }
    if (host.ipAddresses().containsAll(descr.ipAddress()) && descr.annotations().keys().isEmpty()) {
        return null;
    }
    final Set<IpAddress> addresses;
    if (replaceIps) {
        addresses = ImmutableSet.copyOf(descr.ipAddress());
    } else {
        addresses = new HashSet<>(host.ipAddresses());
        addresses.addAll(descr.ipAddress());
    }
    Annotations annotations = merge((DefaultAnnotations) host.annotations(), descr.annotations());
    StoredHost updated = new StoredHost(providerId, host.id(), host.mac(), host.vlan(), descr.location(), addresses, descr.configured(), annotations);
    event = new HostEvent(HOST_UPDATED, updated);
    synchronized (this) {
        hosts.put(host.id(), updated);
        locations.remove(host.location(), host);
        locations.put(updated.location(), updated);
    }
    return event;
}
Also used : HostEvent(org.onosproject.net.host.HostEvent) DefaultAnnotations(org.onosproject.net.DefaultAnnotations) Annotations(org.onosproject.net.Annotations) IpAddress(org.onlab.packet.IpAddress)

Example 18 with HostEvent

use of org.onosproject.net.host.HostEvent in project onos by opennetworkinglab.

the class SimpleHostStore method removeHost.

@Override
public HostEvent removeHost(HostId hostId) {
    synchronized (this) {
        Host host = hosts.remove(hostId);
        if (host != null) {
            locations.remove((host.location()), host);
            HostEvent hostEvent = new HostEvent(HOST_REMOVED, host);
            notifyDelegate(hostEvent);
            return hostEvent;
        }
        return null;
    }
}
Also used : HostEvent(org.onosproject.net.host.HostEvent) Host(org.onosproject.net.Host) DefaultHost(org.onosproject.net.DefaultHost)

Example 19 with HostEvent

use of org.onosproject.net.host.HostEvent in project onos by opennetworkinglab.

the class SimpleHostStore method createOrUpdateHost.

@Override
public HostEvent createOrUpdateHost(ProviderId providerId, HostId hostId, HostDescription hostDescription, boolean replaceIps) {
    // TODO We need a way to detect conflicting changes and abort update.
    StoredHost host = hosts.get(hostId);
    HostEvent hostEvent;
    if (host == null) {
        hostEvent = createHost(providerId, hostId, hostDescription);
    } else {
        hostEvent = updateHost(providerId, host, hostDescription, replaceIps);
    }
    notifyDelegate(hostEvent);
    return hostEvent;
}
Also used : HostEvent(org.onosproject.net.host.HostEvent)

Example 20 with HostEvent

use of org.onosproject.net.host.HostEvent in project onos by opennetworkinglab.

the class VplsManagerTest method testAddHost.

/**
 * Adds hosts to a VPLS.
 */
@Test
public void testAddHost() {
    VplsData vplsData = VplsData.of(VPLS1, NONE);
    vplsData.addInterface(V100H1);
    vplsData.state(ADDED);
    vplsStore.addVpls(vplsData);
    HostEvent hostEvent = new HostEvent(HostEvent.Type.HOST_ADDED, V100HOST1);
    hostService.postHostEvent(hostEvent);
    vplsData = vplsStore.getVpls(VPLS1);
    assertNotNull(vplsData);
    assertEquals(vplsData.state(), UPDATING);
}
Also used : HostEvent(org.onosproject.net.host.HostEvent) VplsData(org.onosproject.vpls.api.VplsData) Test(org.junit.Test)

Aggregations

HostEvent (org.onosproject.net.host.HostEvent)37 Test (org.junit.Test)29 Host (org.onosproject.net.Host)25 DefaultHost (org.onosproject.net.DefaultHost)22 IpPrefix (org.onlab.packet.IpPrefix)8 List (java.util.List)4 IpAddress (org.onlab.packet.IpAddress)4 MacAddress (org.onlab.packet.MacAddress)4 VplsData (org.onosproject.vpls.api.VplsData)4 Sets (com.google.common.collect.Sets)3 Optional (java.util.Optional)3 Set (java.util.Set)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 Collectors (java.util.stream.Collectors)3 VlanId (org.onlab.packet.VlanId)3 HostLocation (org.onosproject.net.HostLocation)3 ResolvedRoute (org.onosproject.routeservice.ResolvedRoute)3 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)2 Lists (com.google.common.collect.Lists)2