use of org.onosproject.net.packet.InboundPacket in project TFG by mattinelorza.
the class InterpreterImpl method mapInboundPacket.
/**
* Returns an ONS InboundPacket equivalent to the given pipeconf-specific
* packet-in operation.
*
* @param packetIn packet operation
* @param deviceId ID of the device that originated the packet-in
* @return inbound packet
* @throws PiInterpreterException if the packet operation cannot be mapped
* to an inbound packet
*/
@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId) throws PiInterpreterException {
// Find the ingress_port metadata.
// *** TODO EXERCISE 4: modify metadata names to match P4Info
// ---- START SOLUTION ----
final String inportMetadataName = "ADD HERE METADATA NAME FOR THE INGRESS PORT";
// ---- END SOLUTION ----
Optional<PiPacketMetadata> inportMetadata = packetIn.metadatas().stream().filter(meta -> meta.id().id().equals(inportMetadataName)).findFirst();
if (!inportMetadata.isPresent()) {
throw new PiInterpreterException(format("Missing metadata '%s' in packet-in received from '%s': %s", inportMetadataName, deviceId, packetIn));
}
// Build ONOS InboundPacket instance with the given ingress port.
// 1. Parse packet-in object into Ethernet packet instance.
final byte[] payloadBytes = packetIn.data().asArray();
final ByteBuffer rawData = ByteBuffer.wrap(payloadBytes);
final Ethernet ethPkt;
try {
ethPkt = Ethernet.deserializer().deserialize(payloadBytes, 0, packetIn.data().size());
} catch (DeserializationException dex) {
throw new PiInterpreterException(dex.getMessage());
}
// 2. Get ingress port
final ImmutableByteSequence portBytes = inportMetadata.get().value();
final short portNum = portBytes.asReadOnlyBuffer().getShort();
final ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(portNum));
return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
}
use of org.onosproject.net.packet.InboundPacket in project dhcpl2relay by opencord.
the class DhcpL2RelayTestBase method sendPacket.
/**
* Sends an Ethernet packet to the process method of the Packet Processor.
*
* @param pkt Ethernet packet
*/
void sendPacket(Ethernet pkt, ConnectPoint cp) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(pkt.serialize());
InboundPacket inPacket = new DefaultInboundPacket(cp, pkt, byteBuffer);
PacketContext context = new TestPacketContext(127L, inPacket, null, false);
packetProcessor.process(context);
}
use of org.onosproject.net.packet.InboundPacket in project aaa by opencord.
the class AaaStatisticsTest method testRequestRetransmittedCount.
/*
* Tests the retransmitted packet and malformed packet count
*
* @throws DeserializationException
* if packed deserialization fails.
*/
@Test
public void testRequestRetransmittedCount() throws Exception {
// (1) Supplicant start up
Ethernet startPacket = constructSupplicantStartPacket();
sendPacket(startPacket);
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
// (2) Supplicant identify
Ethernet identifyPacket = null;
try {
identifyPacket = constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null);
sendPacket(identifyPacket);
RADIUS radiusIdentifyPacket = (RADIUS) fetchPacket(1);
checkRadiusPacketFromSupplicant(radiusIdentifyPacket);
// again creating pending state for same packet
constructSupplicantIdentifyPacket(null, EAP.ATTR_IDENTITY, (byte) 1, null);
sendPacket(identifyPacket);
} catch (Exception e) {
log.error(e.getMessage());
fail();
}
});
assertAfter(ASSERTION_DELAY, ASSERTION_LENGTH, () -> {
aaaManager.impl.handlePacketFromServer(null);
aaaManager.aaaStatisticsManager.calculatePacketRoundtripTime();
// creating malformed packet
final ByteBuffer byteBuffer = ByteBuffer.wrap(startPacket.serialize());
InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), startPacket, byteBuffer);
PacketContext context = new TestPacketContext(127L, inPacket, null, false);
aaaManager.impl.handlePacketFromServer(context);
// Check for increase of Stats
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolResIdentityMsgTrans(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getEapolStartReqRx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getRadiusAccessRequestsTx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getDroppedResponsesRx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getRadiusPendingRequests(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getMalformedResponsesRx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getRequestReTx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getUnknownTypeRx(), ZERO);
assertNotEquals(aaaStatisticsManager.getAaaStats().getUnknownServerRx(), ZERO);
countAaaStatistics();
});
}
use of org.onosproject.net.packet.InboundPacket in project aaa by opencord.
the class AaaTestBase method sendPacket.
/**
* Sends an Ethernet packet to the process method of the Packet Processor.
*
* @param reply Ethernet packet
*/
void sendPacket(Ethernet reply) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(reply.serialize());
InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), reply, byteBuffer);
PacketContext context = new TestPacketContext(127L, inPacket, null, false);
packetProcessor.process(context);
}
use of org.onosproject.net.packet.InboundPacket in project aaa by opencord.
the class PortBasedRadiusCommunicator method handlePacketFromServer.
@Override
public void handlePacketFromServer(PacketContext context) {
// Extract the original Ethernet frame from the packet information
InboundPacket pkt = context.inPacket();
Ethernet ethPkt = pkt.parsed();
if (ethPkt == null) {
return;
}
// identify if incoming packet
switch(EthType.EtherType.lookup(ethPkt.getEtherType())) {
case ARP:
handleArpPacketFromServer(context);
break;
case IPV4:
handleIPv4PacketFromServer(context);
break;
default:
log.debug("Skipping Ethernet packet type {}", EthType.EtherType.lookup(ethPkt.getEtherType()));
}
}
Aggregations