use of org.onosproject.net.packet.InboundPacket in project aaa by opencord.
the class PortBasedRadiusCommunicator method handleArpPacketFromServer.
/**
* Handles ARP packets from RADIUS server.
*
* @param context Context for the packet
*/
private void handleArpPacketFromServer(PacketContext context) {
// Extract the original Ethernet frame from the packet information
InboundPacket pkt = context.inPacket();
Ethernet ethPkt = pkt.parsed();
if (ethPkt == null) {
return;
}
ARP arpPacket = (ARP) ethPkt.getPayload();
Ip4Address targetAddress = Ip4Address.valueOf(arpPacket.getTargetProtocolAddress());
String serialNo = ipToSnMap.get(targetAddress);
if (serialNo == null) {
log.info("No mapping found for ARP reply, target address {}", targetAddress);
return;
}
if (subsService == null) {
log.warn(SADIS_NOT_RUNNING);
return;
}
MacAddress senderMac = subsService.get(serialNo).hardwareIdentifier();
if (senderMac == null) {
log.warn("ARP resolution, MAC address not found for SN {}", serialNo);
return;
}
ARP arpReply = (ARP) arpPacket.clone();
arpReply.setOpCode(ARP.OP_REPLY);
arpReply.setTargetProtocolAddress(arpPacket.getSenderProtocolAddress());
arpReply.setTargetHardwareAddress(arpPacket.getSenderHardwareAddress());
arpReply.setSenderProtocolAddress(arpPacket.getTargetProtocolAddress());
arpReply.setSenderHardwareAddress(senderMac.toBytes());
log.debug("AAA Manager: Query for ARP of IP : {}", arpPacket.getTargetProtocolAddress());
// Ethernet Frame.
Ethernet ethReply = new Ethernet();
ethReply.setSourceMACAddress(senderMac);
ethReply.setDestinationMACAddress(ethPkt.getSourceMAC());
ethReply.setEtherType(Ethernet.TYPE_ARP);
ethReply.setVlanID(radiusVlanID);
ethReply.setPriorityCode(ethPkt.getPriorityCode());
ethReply.setPayload(arpReply);
sendFromRadiusServerPort(ethReply);
}
use of org.onosproject.net.packet.InboundPacket in project fabric-tna by stratum.
the class FabricInterpreterTest method testMapInboundPacketWithShortMetadata.
@Test
public void testMapInboundPacketWithShortMetadata() throws ImmutableByteSequence.ByteSequenceTrimException, PiPipelineInterpreter.PiInterpreterException {
PortNumber inputPort = PortNumber.portNumber(1);
PiPacketMetadata pktInMetadata = PiPacketMetadata.builder().withId(P4InfoConstants.INGRESS_PORT).withValue(// deliberately smaller
ImmutableByteSequence.copyFrom(inputPort.toLong()).fit(8)).build();
Ethernet packet = new Ethernet();
packet.setDestinationMACAddress(SRC_MAC);
packet.setSourceMACAddress(DST_MAC);
packet.setEtherType((short) 0xBA00);
packet.setPayload(new Data());
PiPacketOperation pktInOp = PiPacketOperation.builder().withMetadata(pktInMetadata).withData(ImmutableByteSequence.copyFrom(packet.serialize())).withType(PiPacketOperationType.PACKET_IN).build();
InboundPacket result = interpreter.mapInboundPacket(pktInOp, DEVICE_ID);
ConnectPoint receiveFrom = new ConnectPoint(DEVICE_ID, inputPort);
InboundPacket expectedInboundPacket = new DefaultInboundPacket(receiveFrom, packet, ByteBuffer.wrap(packet.serialize()));
assertEquals(result.receivedFrom(), expectedInboundPacket.receivedFrom());
assertEquals(result.parsed(), expectedInboundPacket.parsed());
assertEquals(result.cookie(), expectedInboundPacket.cookie());
assertEquals(result.unparsed(), expectedInboundPacket.unparsed());
}
use of org.onosproject.net.packet.InboundPacket in project fabric-tna by stratum.
the class FabricInterpreterTest method testMapInboundPacketWithCpuPort.
@Test
public void testMapInboundPacketWithCpuPort() throws ImmutableByteSequence.ByteSequenceTrimException, PiPipelineInterpreter.PiInterpreterException {
PortNumber inputPort = PortNumber.portNumber(Constants.PORT_CPU);
PiPacketMetadata pktInMetadata = PiPacketMetadata.builder().withId(P4InfoConstants.INGRESS_PORT).withValue(ImmutableByteSequence.copyFrom(inputPort.toLong()).fit(P4InfoConstants.INGRESS_PORT_BITWIDTH)).build();
Ethernet packet = new Ethernet();
packet.setDestinationMACAddress(SRC_MAC);
packet.setSourceMACAddress(DST_MAC);
packet.setEtherType((short) 0xBA00);
packet.setPayload(new Data());
PiPacketOperation pktInOp = PiPacketOperation.builder().withMetadata(pktInMetadata).withData(ImmutableByteSequence.copyFrom(packet.serialize())).withType(PiPacketOperationType.PACKET_IN).build();
InboundPacket result = interpreter.mapInboundPacket(pktInOp, DEVICE_ID);
ConnectPoint receiveFrom = new ConnectPoint(DEVICE_ID, inputPort);
InboundPacket expectedInboundPacket = new DefaultInboundPacket(receiveFrom, packet, ByteBuffer.wrap(packet.serialize()));
assertEquals(result.receivedFrom(), expectedInboundPacket.receivedFrom());
assertEquals(result.parsed(), expectedInboundPacket.parsed());
assertEquals(result.cookie(), expectedInboundPacket.cookie());
assertEquals(result.unparsed(), expectedInboundPacket.unparsed());
}
Aggregations