[SEBA-935] Including session timeout scenario of authentication session level statistics
Change-Id: Ibed87f4d028104f79ab5337ff369277a5882b266
diff --git a/app/src/main/java/org/opencord/aaa/impl/StateMachine.java b/app/src/main/java/org/opencord/aaa/impl/StateMachine.java
index 2c0d29f..c60605e 100644
--- a/app/src/main/java/org/opencord/aaa/impl/StateMachine.java
+++ b/app/src/main/java/org/opencord/aaa/impl/StateMachine.java
@@ -27,6 +27,8 @@
import org.onosproject.net.ConnectPoint;
import org.opencord.aaa.AuthenticationEvent;
import org.opencord.aaa.StateMachineDelegate;
+import org.opencord.aaa.AaaSupplicantMachineStats;
+import org.opencord.aaa.AaaMachineStatisticsEvent;
import org.slf4j.Logger;
import com.google.common.collect.Maps;
@@ -789,6 +791,14 @@
if (stateMachine.state() == STATE_PENDING && stateMachine.isWaitingForRadiusResponse()) {
aaaManager.aaaStatisticsManager.getAaaStats().increaseTimedOutPackets();
}
+ //pushing captured machine stats to kafka
+ stateMachine.setSessionTerminateReason("Time out");
+ AaaSupplicantMachineStats obj = aaaManager.aaaSupplicantStatsManager
+ .getSupplicantStats(stateMachine);
+ aaaManager.aaaSupplicantStatsManager.getMachineStatsDelegate()
+ .notify(new AaaMachineStatisticsEvent(
+ AaaMachineStatisticsEvent.Type.STATS_UPDATE, obj));
+
deleteStateMachineId(sessionId);
deleteStateMachineMapping(stateMachine);
diff --git a/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java b/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java
index 87c39f3..28d789d 100644
--- a/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java
+++ b/app/src/test/java/org/opencord/aaa/impl/AaaStatisticsTest.java
@@ -553,6 +553,55 @@
}
+
+ /** Tests the authentication path through the AAA application.
+ * And counts the aaa Stats for timeout.
+ * @throws DeserializationException
+ * if packed deserialization fails.
+ */
+ @Test
+ public void testAaaStatisticsForTimeoutPackets() throws Exception {
+
+ // (1) Supplicant start up
+ Ethernet startPacket = constructSupplicantStartPacket();
+ sendPacket(startPacket);
+
+ Ethernet responsePacket = (Ethernet) fetchPacket(0);
+ checkRadiusPacket(aaaManager, responsePacket, EAP.ATTR_IDENTITY);
+
+ // (2) Supplicant identify
+
+ Ethernet identifyPacket = constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null);
+ sendPacket(identifyPacket);
+
+ RADIUS radiusIdentifyPacket = (RADIUS) fetchPacket(1);
+ checkRadiusPacketFromSupplicant(radiusIdentifyPacket);
+
+ assertThat(radiusIdentifyPacket.getCode(), is(RADIUS.RADIUS_CODE_ACCESS_REQUEST));
+ assertThat(new String(radiusIdentifyPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME).getValue()),
+ is("testuser"));
+ IpAddress nasIp = IpAddress.valueOf(IpAddress.Version.INET,
+ radiusIdentifyPacket.getAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP).getValue());
+ assertThat(nasIp.toString(), is(aaaManager.nasIpAddress.getHostAddress()));
+
+ // State machine should have been created by now
+
+ StateMachine stateMachine = StateMachine.lookupStateMachineBySessionId(SESSION_ID);
+ assertThat(stateMachine, notNullValue());
+ assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING));
+ Thread.sleep((aaaManager.cleanupTimerTimeOutInMins / 2) + 1);
+
+ // State machine should be in timeout state
+ assertThat(stateMachine, notNullValue());
+ assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING));
+
+ //Check for increase in stats
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolResIdentityMsgTrans(), ZERO);
+ assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolStartReqTrans(), ZERO);
+ countAaaStatistics();
+
+ }
+
// Calculates the AAA statistics count.
public void countAaaStatistics() {
assertThat(aaaStatisticsManager.getAaaStats().getAcceptResponsesRx(), notNullValue());