use of org.onlab.packet.Ethernet 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.Ethernet in project dhcpl2relay by opencord.
the class DhcpL2RelayTest method testDhcpOffer.
/**
* Tests the DHCP relay app by sending DHCP Offer Packet with app-defined
* circuit id. App should use the circuit id for forwarding.
*
* @throws Exception when an unhandled error occurs
*/
@Test
public void testDhcpOffer() throws InterruptedException {
// Sending DHCP Offer packet
Ethernet offerPacket = constructDhcpOfferPacket(SERVER_MAC, CLIENT_MAC, DESTINATION_ADDRESS_IP, DHCP_CLIENT_IP_ADDRESS);
sendPacket(offerPacket, ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + String.valueOf(UPLINK_PORT)));
Ethernet offerRelayed = (Ethernet) getPacket();
compareServerPackets(offerPacket, offerRelayed);
String expectedCircuitId = OLT_DEV_ID + "/" + CLIENT_PORT + ":vlan" + CLIENT_C_TAG + ":pcp" + CLIENT_C_PBIT;
checkAllocation(DHCP.MsgType.DHCPOFFER, expectedCircuitId);
}
use of org.onlab.packet.Ethernet in project dhcpl2relay by opencord.
the class DhcpL2RelayTest method testDhcpDiscover.
/**
* Tests the DHCP relay app by sending DHCP discovery Packet. The circuitId
* and remote-Id for this client is operator defined in MockSadis.
*
* @throws Exception when an unhandled error occurs
*/
@Test
public void testDhcpDiscover() throws Exception {
// Sending DHCP Discover packet
dhcpL2Relay.clearAllocations();
Ethernet discoverPacket = constructDhcpDiscoverPacket(CLIENT_MAC);
ConnectPoint clientCp = ConnectPoint.deviceConnectPoint(OLT_DEV_ID + "/" + String.valueOf(CLIENT_PORT));
// send a copy of the packet as the app code modifies the sent packet
sendPacket(discoverPacket.duplicate(), clientCp);
Ethernet discoverRelayed = (Ethernet) getPacket();
compareClientPackets(discoverPacket, discoverRelayed);
checkAllocation(DHCP.MsgType.DHCPDISCOVER, CLIENT_CIRCUIT_ID);
}
use of org.onlab.packet.Ethernet in project dhcpl2relay by opencord.
the class DhcpL2RelayTest method testMultipleAllocations.
@Test
public void testMultipleAllocations() throws Exception {
dhcpL2Relay.clearAllocations();
// Trigger a discover from one RG on port 32
MacAddress mac32 = MacAddress.valueOf("b4:96:91:0c:4f:e4");
VlanId vlan32a = VlanId.vlanId((short) 801);
Ethernet discover32a = constructDhcpDiscoverPacket(mac32, vlan32a, (short) 0);
ConnectPoint client32 = ConnectPoint.deviceConnectPoint("of:0000b86a974385f7/32");
sendPacket(discover32a, client32);
allocs = dhcpL2Relay.getAllocationInfo();
assertEquals(1, allocs.size());
// Trigger a discover from another RG on port 4112
MacAddress mac4112 = MacAddress.valueOf("b4:96:91:0c:4f:c9");
VlanId vlan4112 = VlanId.vlanId((short) 101);
Ethernet discover4112 = constructDhcpDiscoverPacket(mac4112, vlan4112, (short) 0);
ConnectPoint client4112 = ConnectPoint.deviceConnectPoint("of:0000b86a974385f7/4112");
sendPacket(discover4112, client4112);
allocs = dhcpL2Relay.getAllocationInfo();
assertEquals(2, allocs.size());
// Trigger a discover for another service with a different vlan
// from the same UNI port 32
VlanId vlan32b = VlanId.vlanId((short) 802);
Ethernet discover32b = constructDhcpDiscoverPacket(mac32, vlan32b, (short) 0);
sendPacket(discover32b, client32);
allocs = dhcpL2Relay.getAllocationInfo();
assertEquals(3, allocs.size());
allocs.forEach((k, v) -> {
log.info("Allocation {} : {}", k, v);
assertEquals(v.type(), DHCP.MsgType.DHCPDISCOVER);
if (v.subscriberId().equals("ALPHe3d1cea3-1")) {
assertEquals(v.macAddress(), mac32);
assertEquals(v.location(), client32);
if (!(v.vlanId().equals(vlan32a) || v.vlanId().equals(vlan32b))) {
assert false;
}
} else if (v.subscriberId().equals("ALPHe3d1ceb7-1")) {
assertEquals(v.macAddress(), mac4112);
assertEquals(v.location(), client4112);
assertEquals(v.vlanId(), vlan4112);
} else {
assert false;
}
});
dhcpL2Relay.clearAllocations();
assert dhcpL2Relay.getAllocationInfo().size() == 0;
}
use of org.onlab.packet.Ethernet in project dhcpl2relay by opencord.
the class DhcpL2RelayTestBase method constructDhcpOfferPacket.
/**
* Constructs DHCP Offer Packet.
*
* @return Ethernet packet
*/
Ethernet constructDhcpOfferPacket(MacAddress servMac, MacAddress clientMac, String ipAddress, String dhcpClientIpAddress) {
Ethernet pkt = construcEthernetPacket(servMac, clientMac, ipAddress, DHCP.OPCODE_REPLY, clientMac, Ip4Address.valueOf(dhcpClientIpAddress));
IPv4 ipv4Packet = (IPv4) pkt.getPayload();
UDP udpPacket = (UDP) ipv4Packet.getPayload();
DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
dhcpPacket.setOptions(constructDhcpOptions(DHCP.MsgType.DHCPOFFER));
log.info("Sending offer packet {}", dhcpPacket.getOptions());
return pkt;
}
Aggregations