Merge "VOL-2343: Remove DHCP Allocations upon OLT Removal"
diff --git a/app/src/main/java/org/opencord/dhcpl2relay/impl/DhcpL2Relay.java b/app/src/main/java/org/opencord/dhcpl2relay/impl/DhcpL2Relay.java
index 411d763..2cd4f88 100755
--- a/app/src/main/java/org/opencord/dhcpl2relay/impl/DhcpL2Relay.java
+++ b/app/src/main/java/org/opencord/dhcpl2relay/impl/DhcpL2Relay.java
@@ -1088,6 +1088,20 @@
private class InnerDeviceListener implements DeviceListener {
@Override
public void event(DeviceEvent event) {
+ switch (event.type()) {
+ case DEVICE_AVAILABILITY_CHANGED:
+ log.info("Device Avail Changed {}", event.subject().id());
+ DeviceId deviceId = event.subject().id();
+ if (!deviceService.isAvailable(deviceId)) {
+ log.warn("Device {} is not available ", deviceId);
+ allocationMap.entrySet().removeIf(entry -> deviceId.equals(entry.getValue().
+ location().deviceId()));
+ log.info("Device {} is removed from DHCP allocationmap ", deviceId);
+ }
+ break;
+ default:
+ break;
+ }
if (log.isTraceEnabled() &&
!event.type().equals(DeviceEvent.Type.PORT_STATS_UPDATED)) {
log.trace("Device Event received for {} event {}",