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