@Test public void testRemoveIp() { Set<IpAddress> ips = new HashSet<>(); ips.add(IP1); ips.add(IP2); HostDescription description = new DefaultHostDescription(HOSTID.mac(), HOSTID.vlanId(), HostLocation.NONE, ips); ecXHostStore.createOrUpdateHost(PID, HOSTID, description, false); ecXHostStore.removeIp(HOSTID, IP1); Host host = ecXHostStore.getHost(HOSTID); assertFalse(host.ipAddresses().contains(IP1)); assertTrue(host.ipAddresses().contains(IP2)); }
@Override public HostEvent removeIp(HostId hostId, IpAddress ipAddress) { hosts.compute(hostId, (id, existingHost) -> { if (existingHost != null) { checkState(Objects.equals(hostId.mac(), existingHost.mac()), "Existing and new MAC addresses differ."); checkState(Objects.equals(hostId.vlanId(), existingHost.vlan()), "Existing and new VLANs differ."); Set<IpAddress> addresses = existingHost.ipAddresses(); if (addresses != null && addresses.contains(ipAddress)) { addresses = new HashSet<>(existingHost.ipAddresses()); addresses.remove(ipAddress); return new DefaultHost(existingHost.providerId(), hostId, existingHost.mac(), existingHost.vlan(), existingHost.location(), ImmutableSet.copyOf(addresses), existingHost.annotations()); } else { return existingHost; } } return null; }); return null; }
DistributedHostStore extends AbstractStore<HostEvent, HostStoreDelegate> implements HostStore { @Override public HostEvent removeIp(HostId hostId, IpAddress ipAddress) { hosts.compute(hostId, (id, existingHost) -> { if (existingHost != null) { checkState(Objects.equals(hostId.mac(), existingHost.mac()), "Existing and new MAC addresses differ."); checkState(Objects.equals(hostId.vlanId(), existingHost.vlan()), "Existing and new VLANs differ."); Set<IpAddress> addresses = existingHost.ipAddresses(); if (addresses != null && addresses.contains(ipAddress)) { addresses = new HashSet<>(existingHost.ipAddresses()); addresses.remove(ipAddress); return new DefaultHost(existingHost.providerId(), hostId, existingHost.mac(), existingHost.vlan(), existingHost.location(), ImmutableSet.copyOf(addresses), existingHost.annotations()); } else { return existingHost; } } return null; }); return null; } }
DistributedHostStore extends AbstractStore<HostEvent, HostStoreDelegate> implements HostStore { @Override public HostEvent removeIp(HostId hostId, IpAddress ipAddress) { hosts.compute(hostId, (id, existingHost) -> { if (existingHost != null) { checkState(Objects.equals(hostId.mac(), existingHost.mac()), "Existing and new MAC addresses differ."); checkState(Objects.equals(hostId.vlanId(), existingHost.vlan()), "Existing and new VLANs differ."); Set<IpAddress> addresses = existingHost.ipAddresses(); if (addresses != null && addresses.contains(ipAddress)) { addresses = new HashSet<>(existingHost.ipAddresses()); addresses.remove(ipAddress); return new DefaultHost(existingHost.providerId(), hostId, existingHost.mac(), existingHost.vlan(), existingHost.location(), ImmutableSet.copyOf(addresses), existingHost.annotations()); } else { return existingHost; } } return null; }); return null; }  }
DistributedHostStore extends AbstractStore<HostEvent, HostStoreDelegate> implements HostStore { @Override public HostEvent removeIp(HostId hostId, IpAddress ipAddress) { hosts.compute(hostId, (id, existingHost) -> { if (existingHost != null) { checkState(Objects.equals(hostId.mac(), existingHost.mac()), "Existing and new MAC addresses differ."); checkState(Objects.equals(hostId.vlanId(), existingHost.vlan()), "Existing and new VLANs differ."); Set<IpAddress> addresses = existingHost.ipAddresses(); if (addresses != null && addresses.contains(ipAddress)) { addresses = new HashSet<>(existingHost.ipAddresses()); addresses.remove(ipAddress); return new DefaultHost(existingHost.providerId(), hostId, existingHost.mac(), existingHost.vlan(), existingHost.location(), ImmutableSet.copyOf(addresses), existingHost.annotations()); } else { return existingHost; } } return null; }); return null; }  @Activate void activate(); @Deactivate void deactivate(); @Override HostEvent createOrUpdateHost(ProviderId providerId,
                                        HostId hostId,
                                        HostDescription hostDescription,
                                        boolean replaceIPs); @Override HostEvent removeHost(HostId hostId); @Override HostEvent removeIp(HostId hostId, IpAddress ipAddress); @Override int getHostCount(); @Override Iterable<Host> getHosts(); @Override Host getHost(HostId hostId); @Override Set<Host> getHosts(VlanId vlanId); @Override Set<Host> getHosts(MacAddress mac); @Override Set<Host> getHosts(IpAddress ip); @Override Set<Host> getConnectedHosts(ConnectPoint connectPoint); @Override Set<Host> getConnectedHosts(DeviceId deviceId); }
DistributedHostStore extends AbstractStore<HostEvent, HostStoreDelegate> implements HostStore { @Override public HostEvent removeIp(HostId hostId, IpAddress ipAddress) { hosts.compute(hostId, (id, existingHost) -> { if (existingHost != null) { checkState(Objects.equals(hostId.mac(), existingHost.mac()), "Existing and new MAC addresses differ."); checkState(Objects.equals(hostId.vlanId(), existingHost.vlan()), "Existing and new VLANs differ."); Set<IpAddress> addresses = existingHost.ipAddresses(); if (addresses != null && addresses.contains(ipAddress)) { addresses = new HashSet<>(existingHost.ipAddresses()); addresses.remove(ipAddress); return new DefaultHost(existingHost.providerId(), hostId, existingHost.mac(), existingHost.vlan(), existingHost.location(), ImmutableSet.copyOf(addresses), existingHost.annotations()); } else { return existingHost; } } return null; }); return null; }  @Activate void activate(); @Deactivate void deactivate(); @Override HostEvent createOrUpdateHost(ProviderId providerId,
                                        HostId hostId,
                                        HostDescription hostDescription,
                                        boolean replaceIPs); @Override HostEvent removeHost(HostId hostId); @Override HostEvent removeIp(HostId hostId, IpAddress ipAddress); @Override int getHostCount(); @Override Iterable<Host> getHosts(); @Override Host getHost(HostId hostId); @Override Set<Host> getHosts(VlanId vlanId); @Override Set<Host> getHosts(MacAddress mac); @Override Set<Host> getHosts(IpAddress ip); @Override Set<Host> getConnectedHosts(ConnectPoint connectPoint); @Override Set<Host> getConnectedHosts(DeviceId deviceId);  }