[VOL-2587] Fixed NullPointerException for PORT_REMOVED event when ONU is deleted
Change-Id: I684e97b9a81f54e8c29478321019910aafc6f2fa
diff --git a/app/src/main/java/org/opencord/aaa/impl/AaaManager.java b/app/src/main/java/org/opencord/aaa/impl/AaaManager.java
index 015f608..1c42ef5 100644
--- a/app/src/main/java/org/opencord/aaa/impl/AaaManager.java
+++ b/app/src/main/java/org/opencord/aaa/impl/AaaManager.java
@@ -959,49 +959,53 @@
@Override
public void event(DeviceEvent event) {
- switch (event.type()) {
- case PORT_REMOVED:
- DeviceId devId = event.subject().id();
- PortNumber portNumber = event.port().number();
- String sessionId = devId.toString() + portNumber.toString();
+ switch (event.type()) {
+ case PORT_REMOVED:
+ DeviceId devId = event.subject().id();
+ PortNumber portNumber = event.port().number();
+ String sessionId = devId.toString() + portNumber.toString();
- log.info("Received PORT_REMOVED event. Clearing AAA Session with Id {}", sessionId);
- flushStateMachineSession(sessionId,
- StateMachine.SessionTerminationReasons.PORT_REMOVED.getReason());
+ log.debug("Received PORT_REMOVED event. Clearing AAA Session with Id {}", sessionId);
+ flushStateMachineSession(sessionId,
+ StateMachine.SessionTerminationReasons.PORT_REMOVED.getReason());
- break;
+ break;
- case DEVICE_REMOVED:
- DeviceId deviceId = event.subject().id();
- log.info("Received DEVICE_REMOVED event for {}", deviceId);
+ case DEVICE_REMOVED:
+ DeviceId deviceId = event.subject().id();
+ log.debug("Received DEVICE_REMOVED event for {}", deviceId);
- Set<String> associatedSessions = Sets.newHashSet();
- for (Entry<String, StateMachine> stateMachineEntry : StateMachine.sessionIdMap().entrySet()) {
- ConnectPoint cp = stateMachineEntry.getValue().supplicantConnectpoint();
- if (cp != null && cp.deviceId().toString().equals(deviceId.toString())) {
- associatedSessions.add(stateMachineEntry.getKey());
- }
- }
+ Set<String> associatedSessions = Sets.newHashSet();
+ for (Entry<String, StateMachine> stateMachineEntry : StateMachine.sessionIdMap().entrySet()) {
+ ConnectPoint cp = stateMachineEntry.getValue().supplicantConnectpoint();
+ if (cp != null && cp.deviceId().toString().equals(deviceId.toString())) {
+ associatedSessions.add(stateMachineEntry.getKey());
+ }
+ }
- for (String session : associatedSessions) {
- log.info("Clearing AAA Session {} associated with Removed Device", session);
- flushStateMachineSession(session,
- StateMachine.SessionTerminationReasons.DEVICE_REMOVED.getReason());
- }
+ for (String session : associatedSessions) {
+ log.debug("Clearing AAA Session {} associated with Removed Device", session);
+ flushStateMachineSession(session,
+ StateMachine.SessionTerminationReasons.DEVICE_REMOVED.getReason());
+ }
- break;
+ break;
- default:
- return;
- }
+ default:
+ return;
+ }
}
private void flushStateMachineSession(String sessionId, String terminationReason) {
StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(sessionId);
- if (stateMachine != null) {
- stateMachine.setSessionTerminateReason(terminationReason);
+ if (stateMachine == null) {
+ // No active AAA sessions for this UNI port
+ log.debug("No Active AAA Session found with Id {}", sessionId);
+ return;
}
+ stateMachine.setSessionTerminateReason(terminationReason);
+
//pushing captured machine stats to kafka
AaaSupplicantMachineStats obj = aaaSupplicantStatsManager.getSupplicantStats(stateMachine);
aaaSupplicantStatsManager.getMachineStatsDelegate()