use of org.onlab.packet.RADIUS in project aaa by opencord.
the class AaaStatisticsTest method testAaaStatisticsForAcceptedPackets.
/**
* Tests the authentication path through the AAA application.
* And counts the aaa Stats for successful transmission.
*
* @throws DeserializationException if packed deserialization fails.
*/
@Test
public void testAaaStatisticsForAcceptedPackets() throws Exception {
// (1) Supplicant start up
Ethernet startPacket = constructSupplicantStartPacket();
sendPacket(startPacket);
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
Ethernet responsePacket = (Ethernet) fetchPacket(0);
checkRadiusPacket(aaaManager, responsePacket, EAP.ATTR_IDENTITY);
// (2) Supplicant identify
Ethernet identifyPacket = null;
try {
identifyPacket = constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null);
sendPacket(identifyPacket);
} catch (Exception e) {
log.error(e.getMessage());
fail();
}
});
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
try {
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 = aaaManager.getStateMachine(SESSION_ID);
assertThat(stateMachine, notNullValue());
assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING));
// (3) RADIUS MD5 challenge
RADIUS radiusCodeAccessChallengePacket = constructRadiusCodeAccessChallengePacket(RADIUS.RADIUS_CODE_ACCESS_CHALLENGE, EAP.ATTR_MD5, radiusIdentifyPacket.getIdentifier(), aaaManager.radiusSecret.getBytes());
aaaManager.handleRadiusPacket(radiusCodeAccessChallengePacket);
} catch (Exception e) {
log.error(e.getMessage());
fail();
}
});
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
StateMachine stateMachine = aaaManager.getStateMachine(SESSION_ID);
Ethernet radiusChallengeMD5Packet = (Ethernet) fetchPacket(2);
checkRadiusPacket(aaaManager, radiusChallengeMD5Packet, EAP.ATTR_MD5);
// (4) Supplicant MD5 response
Ethernet md5RadiusPacket = null;
try {
md5RadiusPacket = constructSupplicantIdentifyPacket(stateMachine, EAP.ATTR_MD5, stateMachine.challengeIdentifier(), radiusChallengeMD5Packet);
} catch (Exception e) {
log.error(e.getMessage());
fail();
}
sendPacket(md5RadiusPacket);
});
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
StateMachine stateMachine = aaaManager.getStateMachine(SESSION_ID);
RADIUS responseMd5RadiusPacket = (RADIUS) fetchPacket(3);
try {
checkRadiusPacketFromSupplicant(responseMd5RadiusPacket);
} catch (DeserializationException e) {
log.error(e.getMessage());
fail();
}
// assertThat(responseMd5RadiusPacket.getIdentifier(), is((byte) 9));
assertThat(responseMd5RadiusPacket.getCode(), is(RADIUS.RADIUS_CODE_ACCESS_REQUEST));
// State machine should be in pending state
assertThat(stateMachine, notNullValue());
assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING));
// (5) RADIUS Success
RADIUS successPacket = constructRadiusCodeAccessChallengePacket(RADIUS.RADIUS_CODE_ACCESS_ACCEPT, EAP.SUCCESS, responseMd5RadiusPacket.getIdentifier(), aaaManager.radiusSecret.getBytes());
aaaManager.handleRadiusPacket((successPacket));
});
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
StateMachine stateMachine = aaaManager.getStateMachine(SESSION_ID);
Ethernet supplicantSuccessPacket = (Ethernet) fetchPacket(4);
checkRadiusPacket(aaaManager, supplicantSuccessPacket, EAP.SUCCESS);
// State machine should be in authorized state
assertThat(stateMachine, notNullValue());
assertThat(stateMachine.state(), is(StateMachine.STATE_AUTHORIZED));
// Check for increase of Stats
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolResIdentityMsgTrans(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolAuthSuccessTx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolStartReqRx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolTransRespNotNak(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolChallengeReqTx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolValidFramesRx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolFramesTx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolReqFramesTx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolIdRequestFramesTx(), ZERO);
assertEquals(aaaStatisticsManager.getAaaStats().getInvalidBodyLength(), ZERO);
assertEquals(aaaStatisticsManager.getAaaStats().getInvalidPktType(), ZERO);
assertEquals(aaaStatisticsManager.getAaaStats().getEapolPendingReq(), ZERO);
// Counts the aaa Statistics count and displays in the log
countAaaStatistics();
});
}
use of org.onlab.packet.RADIUS in project aaa by opencord.
the class AaaStatisticsTest method testAaaStatisticsForTimeoutPackets.
/**
* 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);
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
Ethernet responsePacket = (Ethernet) fetchPacket(0);
checkRadiusPacket(aaaManager, responsePacket, EAP.ATTR_IDENTITY);
// (2) Supplicant identify
Ethernet identifyPacket = null;
try {
identifyPacket = constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null);
} catch (Exception e) {
log.error(e.getMessage());
fail();
}
sendPacket(identifyPacket);
});
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
RADIUS radiusIdentifyPacket = (RADIUS) fetchPacket(1);
try {
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 = aaaManager.getStateMachine(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().getEapolStartReqRx(), ZERO);
countAaaStatistics();
} catch (Exception e) {
log.error(e.getMessage());
fail();
}
});
}
use of org.onlab.packet.RADIUS in project aaa by opencord.
the class AaaStatisticsTest method testStatisticsForInvalidPackets.
/**
* Tests invalid packets reaching AAA.
* And counts the aaa Stats for successful transmission.
* @throws DeserializationException
* if packed deserialization fails.
*/
@Test
public void testStatisticsForInvalidPackets() throws Exception {
// Test Authenticator State Machine Status. Should be Pending
// (1) Supplicant start up
Ethernet startPacket = constructSupplicantStartPacket();
sendPacket(startPacket);
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
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);
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
RADIUS radiusIdentifyPacket = (RADIUS) fetchPacket(1);
try {
checkRadiusPacketFromSupplicant(radiusIdentifyPacket);
} catch (DeserializationException e) {
log.error(e.getMessage());
fail();
}
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 = aaaManager.getStateMachine(SESSION_ID);
assertThat(stateMachine, notNullValue());
assertThat(stateMachine.state(), is(StateMachine.STATE_PENDING));
// (3) RADIUS NAK challenge
RADIUS radiusCodeAccessChallengePacket = constructRadiusCodeAccessChallengePacket(RADIUS.RADIUS_CODE_ACCESS_CHALLENGE, EAP.ATTR_NAK, radiusIdentifyPacket.getIdentifier(), aaaManager.radiusSecret.getBytes());
aaaManager.handleRadiusPacket(radiusCodeAccessChallengePacket);
});
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
Ethernet radiusChallengeNakPacket = (Ethernet) fetchPacket(2);
checkRadiusPacket(aaaManager, radiusChallengeNakPacket, EAP.ATTR_NAK);
// (4) Supplicant NAK response
StateMachine stateMachine = aaaManager.getStateMachine(SESSION_ID);
assertThat(stateMachine, notNullValue());
Ethernet nakRadiusPacket = null;
try {
nakRadiusPacket = constructSupplicantIdentifyPacket(stateMachine, EAP.ATTR_NAK, stateMachine.challengeIdentifier(), radiusChallengeNakPacket);
} catch (Exception e) {
log.error(e.getMessage());
fail();
}
sendPacket(nakRadiusPacket);
});
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
// Statistic Should be increased.
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolPendingReq(), ZERO);
// Test if packet with invalid eapol type recieved.
// Supplicant ASF Packet
Ethernet invalidPacket = constructSupplicantAsfPacket();
sendPacket(invalidPacket);
});
// Statistic Should be increased.
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
assertNotEquals(aaaStatisticsManager.getAaaStats().getInvalidPktType(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getRadiusAccessRequestsTx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getRadiusChallengeResponsesRx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getDroppedResponsesRx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getInvalidValidatorsRx(), ZERO);
// Counts the aaa Statistics count and displays in the log
countAaaStatistics();
});
}
use of org.onlab.packet.RADIUS in project aaa by opencord.
the class PortBasedRadiusCommunicator method handleIPv4PacketFromServer.
/**
* Handles IP packets from RADIUS server.
*
* @param context Context for the packet
*/
private void handleIPv4PacketFromServer(PacketContext context) {
// Extract the original Ethernet frame from the packet information
InboundPacket pkt = context.inPacket();
Ethernet ethPkt = pkt.parsed();
if (ethPkt == null) {
return;
}
IPv4 ipv4Packet = (IPv4) ethPkt.getPayload();
if (ipv4Packet.getProtocol() == IPv4.PROTOCOL_UDP) {
UDP udpPacket = (UDP) ipv4Packet.getPayload();
if (udpPacket.getSourcePort() == radiusServerPort) {
// This packet is RADIUS packet from the server.
RADIUS radiusMsg;
try {
radiusMsg = RADIUS.deserializer().deserialize(udpPacket.serialize(), 8, udpPacket.getLength() - 8);
aaaManager.aaaStatisticsManager.handleRoundtripTime(radiusMsg.getIdentifier());
aaaManager.handleRadiusPacket(radiusMsg);
} catch (DeserializationException dex) {
log.error("Cannot deserialize packet", dex);
}
}
}
}
use of org.onlab.packet.RADIUS in project aaa by opencord.
the class RadiusOperationalStatusManager method checkServerStatusUsingFakeAccessRequest.
public void checkServerStatusUsingFakeAccessRequest() throws InterruptedException {
RADIUS radiusDummyAccessRequest;
// identifier = 1 for fake accessRequest
radiusDummyAccessRequest = new RADIUS(RADIUS.RADIUS_CODE_ACCESS_REQUEST, AAA_REQUEST_ID_FAKE_ACCESS_REQUEST);
radiusDummyAccessRequest.setIdentifier(AAA_REQUEST_ID_FAKE_ACCESS_REQUEST);
radiusDummyAccessRequest.setAttribute(RADIUSAttribute.RADIUS_ATTR_USERNAME, DUMMY_USER.getBytes());
radiusDummyAccessRequest.setAttribute(RADIUSAttribute.RADIUS_ATTR_NAS_IP, address);
radiusDummyAccessRequest.addMessageAuthenticator(secret);
setOutTimeInMillis(radiusDummyAccessRequest.getIdentifier());
impl.sendRadiusPacket(radiusDummyAccessRequest, null);
synchronized (fakeAccessRequestPacketRecieved) {
fakeAccessRequestPacketRecieved.wait(operationalStatusServerTimeoutInMillis);
}
}
Aggregations