Search in sources :

Example 21 with InboundPacket

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);
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) PACKET_OUT(org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Ethernet(org.onlab.packet.Ethernet) ImmutableList(com.google.common.collect.ImmutableList) DeserializationException(org.onlab.packet.DeserializationException) OutboundPacket(org.onosproject.net.packet.OutboundPacket) ImmutableByteSequence.copyFrom(org.onlab.util.ImmutableByteSequence.copyFrom) Port(org.onosproject.net.Port) Map(java.util.Map) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) Criterion(org.onosproject.net.flow.criteria.Criterion) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) FLOOD(org.onosproject.net.PortNumber.FLOOD) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Collection(java.util.Collection) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiPacketMetadataId(org.onosproject.net.pi.model.PiPacketMetadataId) CPU_PORT_ID(org.onosproject.ngsdn.tutorial.AppConstants.CPU_PORT_ID) String.format(java.lang.String.format) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) PiAction(org.onosproject.net.pi.runtime.PiAction) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) InboundPacket(org.onosproject.net.packet.InboundPacket) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) DeserializationException(org.onlab.packet.DeserializationException) Ethernet(org.onlab.packet.Ethernet) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence)

Example 22 with InboundPacket

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);
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) ByteBuffer(java.nio.ByteBuffer)

Example 23 with InboundPacket

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();
    });
}
Also used : RADIUS(org.onlab.packet.RADIUS) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Ethernet(org.onlab.packet.Ethernet) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) PacketContext(org.onosproject.net.packet.PacketContext) ByteBuffer(java.nio.ByteBuffer) DeserializationException(org.onlab.packet.DeserializationException) UnknownHostException(java.net.UnknownHostException) Test(org.junit.Test)

Example 24 with InboundPacket

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);
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) ByteBuffer(java.nio.ByteBuffer)

Example 25 with InboundPacket

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()));
    }
}
Also used : InboundPacket(org.onosproject.net.packet.InboundPacket) Ethernet(org.onlab.packet.Ethernet)

Aggregations

InboundPacket (org.onosproject.net.packet.InboundPacket)28 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)19 Ethernet (org.onlab.packet.Ethernet)18 ByteBuffer (java.nio.ByteBuffer)12 ConnectPoint (org.onosproject.net.ConnectPoint)10 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)10 PortNumber (org.onosproject.net.PortNumber)9 PiPacketMetadata (org.onosproject.net.pi.runtime.PiPacketMetadata)9 DeserializationException (org.onlab.packet.DeserializationException)7 OutboundPacket (org.onosproject.net.packet.OutboundPacket)7 PacketContext (org.onosproject.net.packet.PacketContext)7 Test (org.junit.Test)6 DeviceId (org.onosproject.net.DeviceId)6 Port (org.onosproject.net.Port)6 DefaultPacketContext (org.onosproject.net.packet.DefaultPacketContext)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 String.format (java.lang.String.format)5 Collection (java.util.Collection)5 List (java.util.List)5