use of org.onlab.packet.Ethernet in project dhcpl2relay by opencord.
the class DhcpL2RelayTestBase method constructDhcpDiscoverPacket.
/**
* Constructs DHCP Discover Packet.
*
* @return Ethernet packet
*/
Ethernet constructDhcpDiscoverPacket(MacAddress clientMac) {
Ethernet pkt = construcEthernetPacket(clientMac, MacAddress.BROADCAST, "255.255.255.255", DHCP.OPCODE_REQUEST, clientMac, Ip4Address.valueOf("0.0.0.0"));
IPv4 ipv4Packet = (IPv4) pkt.getPayload();
UDP udpPacket = (UDP) ipv4Packet.getPayload();
DHCP dhcpPacket = (DHCP) udpPacket.getPayload();
dhcpPacket.setOptions(constructDhcpOptions(DHCP.MsgType.DHCPDISCOVER));
log.info("Sending discover packet {}", dhcpPacket.getOptions());
return pkt;
}
use of org.onlab.packet.Ethernet in project aaa by opencord.
the class PortBasedRadiusCommunicator method sendRadiusPacket.
@Override
public void sendRadiusPacket(RADIUS radiusPacket, InboundPacket inPkt) {
// create the packet
Ethernet ethReply = new Ethernet();
ethReply.setSourceMACAddress(nasMacAddress);
ethReply.setDestinationMACAddress(radiusMacAddress);
ethReply.setEtherType(Ethernet.TYPE_IPV4);
ethReply.setVlanID(radiusVlanID);
ethReply.setPriorityCode(radiusPBit);
IPv4 ipv4Packet = new IPv4();
ipv4Packet.setTtl((byte) 64);
ipv4Packet.setSourceAddress(Ip4Address.valueOf(nasIpAddress).toInt());
ipv4Packet.setDestinationAddress(Ip4Address.valueOf(radiusIpAddress).toInt());
UDP udpPacket = new UDP();
udpPacket.setSourcePort(radiusServerPort);
udpPacket.setDestinationPort(radiusServerPort);
udpPacket.setPayload(radiusPacket);
ipv4Packet.setPayload(udpPacket);
ethReply.setPayload(ipv4Packet);
// store the IP address and SN of the device, later to be used
// for ARP responses
String serialNo = deviceService.getDevice(inPkt.receivedFrom().deviceId()).serialNumber();
if (subsService == null) {
log.warn(SADIS_NOT_RUNNING);
aaaManager.radiusOperationalStatusService.setStatusServerReqSent(false);
return;
}
SubscriberAndDeviceInformation deviceInfo = subsService.get(serialNo);
if (deviceInfo == null) {
log.warn("No Device found with SN {}", serialNo);
aaaManager.radiusOperationalStatusService.setStatusServerReqSent(false);
return;
}
if (radiusPacket.getIdentifier() == RadiusOperationalStatusManager.AAA_REQUEST_ID_STATUS_REQUEST || radiusPacket.getIdentifier() == RadiusOperationalStatusManager.AAA_REQUEST_ID_FAKE_ACCESS_REQUEST) {
aaaManager.radiusOperationalStatusService.setOutTimeInMillis(radiusPacket.getIdentifier());
} else {
aaaManager.aaaStatisticsManager.putOutgoingIdentifierToMap(radiusPacket.getIdentifier());
}
Ip4Address ipAddress = deviceInfo.ipAddress();
if (ipAddress != null) {
ipToSnMap.put(ipAddress, serialNo);
} else {
log.warn("Cannot Map IpAddress to SerialNo : ipAddress = {}", ipAddress);
}
// send the message out
sendFromRadiusServerPort(pktCustomizer.customizeEthernetIPHeaders(ethReply, inPkt));
aaaManager.radiusOperationalStatusService.setStatusServerReqSent(true);
}
use of org.onlab.packet.Ethernet 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.Ethernet in project trellis-control by opennetworkinglab.
the class IcmpHandlerTest method testPing6RemoteGatewayLeafDown.
// Ping6 to a gateway but destination leaf is down
@Test
public void testPing6RemoteGatewayLeafDown() {
// Expected behavior
expect(segmentRoutingManager.deviceService.isAvailable(LOCAL_LEAF)).andReturn(false).times(1);
replay(segmentRoutingManager.deviceService);
// Process
icmpHandler.processIcmpv6(ETH_REQ_IPV6, CP11);
// Verify packet-out
Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV6.getSourceMAC());
assertNull(ethernet);
// Verify behavior
verify(segmentRoutingManager.deviceService);
}
use of org.onlab.packet.Ethernet in project trellis-control by opennetworkinglab.
the class IcmpHandlerTest method testPing4Loopback.
// Ping to the looback of our leaf
@Test
public void testPing4Loopback() {
// Expected behavior
expect(segmentRoutingManager.deviceService.isAvailable(REMOTE_LEAF)).andReturn(true).times(1);
replay(segmentRoutingManager.deviceService);
// Process
icmpHandler.processIcmp(ETH_REQ_IPV4_LOOPBACK, CP12);
// Verify packet-out
Ethernet ethernet = packetService.getEthernetPacket(ETH_REQ_IPV4_LOOPBACK.getSourceMAC());
assertNotNull(ethernet);
assertThat(ethernet.getSourceMAC(), is(ETH_REQ_IPV4_LOOPBACK.getDestinationMAC()));
assertThat(ethernet.getDestinationMAC(), is(ETH_REQ_IPV4_LOOPBACK.getSourceMAC()));
assertTrue(ethernet.getPayload() instanceof IPv4);
IPv4 ip = (IPv4) ethernet.getPayload();
assertThat(ip.getSourceAddress(), is(DST_IPV4_LOOPBACK.toInt()));
assertThat(ip.getDestinationAddress(), is(SRC_IPV4_MY.toInt()));
assertTrue(ip.getPayload() instanceof ICMP);
ICMP icmp = (ICMP) ip.getPayload();
assertThat(icmp.getIcmpType(), is(TYPE_ECHO_REPLY));
assertThat(icmp.getIcmpCode(), is(CODE_ECHO_REPLY));
// Verify behavior
verify(segmentRoutingManager.deviceService);
}
Aggregations