Search in sources :

Example 1 with DeserializationException

use of org.onlab.packet.DeserializationException in project onos by opennetworkinglab.

the class PipelineInterpreterImpl method mapInboundPacket.

@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId) throws PiInterpreterException {
    // We assume that the packet is ethernet, which is fine since mytunnel.p4
    // can deparse only ethernet packets.
    Ethernet ethPkt;
    try {
        ethPkt = Ethernet.deserializer().deserialize(packetIn.data().asArray(), 0, packetIn.data().size());
    } catch (DeserializationException dex) {
        throw new PiInterpreterException(dex.getMessage());
    }
    // Returns the ingress port packet metadata.
    Optional<PiPacketMetadata> packetMetadata = packetIn.metadatas().stream().filter(metadata -> metadata.id().toString().equals(INGRESS_PORT)).findFirst();
    if (packetMetadata.isPresent()) {
        short s = packetMetadata.get().value().asReadOnlyBuffer().getShort();
        ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(s));
        return new DefaultInboundPacket(receivedFrom, ethPkt, packetIn.data().asReadOnlyBuffer());
    } else {
        throw new PiInterpreterException(format("Missing metadata '%s' in packet-in received from '%s': %s", INGRESS_PORT, deviceId, packetIn));
    }
}
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) PiActionParamId(org.onosproject.net.pi.model.PiActionParamId) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) Ethernet(org.onlab.packet.Ethernet) Lists(com.google.common.collect.Lists) 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) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) FLOOD(org.onosproject.net.PortNumber.FLOOD) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Instruction(org.onosproject.net.flow.instructions.Instruction) Collection(java.util.Collection) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiPacketMetadataId(org.onosproject.net.pi.model.PiPacketMetadataId) String.format(java.lang.String.format) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) PiAction(org.onosproject.net.pi.runtime.PiAction) List(java.util.List) InboundPacket(org.onosproject.net.packet.InboundPacket) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) PiActionId(org.onosproject.net.pi.model.PiActionId) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) Ethernet(org.onlab.packet.Ethernet) ConnectPoint(org.onosproject.net.ConnectPoint) DeserializationException(org.onlab.packet.DeserializationException)

Example 2 with DeserializationException

use of org.onlab.packet.DeserializationException in project onos by opennetworkinglab.

the class BasicInterpreterImpl method mapInboundPacket.

@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId) throws PiInterpreterException {
    // Assuming that the packet is ethernet, which is fine since basic.p4
    // can deparse only ethernet packets.
    Ethernet ethPkt;
    try {
        ethPkt = Ethernet.deserializer().deserialize(packetIn.data().asArray(), 0, packetIn.data().size());
    } catch (DeserializationException dex) {
        throw new PiInterpreterException(dex.getMessage());
    }
    // Returns the ingress port packet metadata.
    Optional<PiPacketMetadata> packetMetadata = packetIn.metadatas().stream().filter(m -> m.id().equals(INGRESS_PORT)).findFirst();
    if (packetMetadata.isPresent()) {
        ImmutableByteSequence portByteSequence = packetMetadata.get().value();
        short s = portByteSequence.asReadOnlyBuffer().getShort();
        ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(s));
        ByteBuffer rawData = ByteBuffer.wrap(packetIn.data().asArray());
        return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
    } else {
        throw new PiInterpreterException(format("Missing metadata '%s' in packet-in received from '%s': %s", INGRESS_PORT, deviceId, packetIn));
    }
}
Also used : PiTableId(org.onosproject.net.pi.model.PiTableId) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) PiActionParam(org.onosproject.net.pi.runtime.PiActionParam) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) Ethernet(org.onlab.packet.Ethernet) ImmutableByteSequence.copyFrom(org.onlab.util.ImmutableByteSequence.copyFrom) INGRESS_WCMP_CONTROL_WCMP_TABLE(org.onosproject.pipelines.basic.BasicConstants.INGRESS_WCMP_CONTROL_WCMP_TABLE) Port(org.onosproject.net.Port) Map(java.util.Map) HDR_STANDARD_METADATA_INGRESS_PORT(org.onosproject.pipelines.basic.BasicConstants.HDR_STANDARD_METADATA_INGRESS_PORT) INGRESS_PORT(org.onosproject.pipelines.basic.BasicConstants.INGRESS_PORT) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) EGRESS_PORT(org.onosproject.pipelines.basic.BasicConstants.EGRESS_PORT) String.format(java.lang.String.format) HDR_HDR_ETHERNET_DST_ADDR(org.onosproject.pipelines.basic.BasicConstants.HDR_HDR_ETHERNET_DST_ADDR) List(java.util.List) InboundPacket(org.onosproject.net.packet.InboundPacket) PORT(org.onosproject.pipelines.basic.BasicConstants.PORT) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) PACKET_OUT(org.onosproject.net.pi.model.PiPacketOperationType.PACKET_OUT) HDR_HDR_ETHERNET_ETHER_TYPE(org.onosproject.pipelines.basic.BasicConstants.HDR_HDR_ETHERNET_ETHER_TYPE) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) INGRESS_TABLE0_CONTROL_DROP(org.onosproject.pipelines.basic.BasicConstants.INGRESS_TABLE0_CONTROL_DROP) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) HDR_HDR_ETHERNET_SRC_ADDR(org.onosproject.pipelines.basic.BasicConstants.HDR_HDR_ETHERNET_SRC_ADDR) ImmutableList(com.google.common.collect.ImmutableList) DeserializationException(org.onlab.packet.DeserializationException) OutboundPacket(org.onosproject.net.packet.OutboundPacket) 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) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Instruction(org.onosproject.net.flow.instructions.Instruction) NO_ACTION(org.onosproject.pipelines.basic.BasicConstants.NO_ACTION) INGRESS_TABLE0_CONTROL_SEND_TO_CPU(org.onosproject.pipelines.basic.BasicConstants.INGRESS_TABLE0_CONTROL_SEND_TO_CPU) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) INGRESS_TABLE0_CONTROL_SET_EGRESS_PORT(org.onosproject.pipelines.basic.BasicConstants.INGRESS_TABLE0_CONTROL_SET_EGRESS_PORT) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) HDR_HDR_IPV4_DST_ADDR(org.onosproject.pipelines.basic.BasicConstants.HDR_HDR_IPV4_DST_ADDR) INGRESS_WCMP_CONTROL_SET_EGRESS_PORT(org.onosproject.pipelines.basic.BasicConstants.INGRESS_WCMP_CONTROL_SET_EGRESS_PORT) PiAction(org.onosproject.net.pi.runtime.PiAction) INGRESS_TABLE0_CONTROL_TABLE0(org.onosproject.pipelines.basic.BasicConstants.INGRESS_TABLE0_CONTROL_TABLE0) Collectors.toList(java.util.stream.Collectors.toList) HDR_HDR_IPV4_SRC_ADDR(org.onosproject.pipelines.basic.BasicConstants.HDR_HDR_IPV4_SRC_ADDR) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) PiActionId(org.onosproject.net.pi.model.PiActionId) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) Ethernet(org.onlab.packet.Ethernet) ConnectPoint(org.onosproject.net.ConnectPoint) ByteBuffer(java.nio.ByteBuffer) DeserializationException(org.onlab.packet.DeserializationException) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence)

Example 3 with DeserializationException

use of org.onlab.packet.DeserializationException in project onos by opennetworkinglab.

the class FabricInterpreter method mapInboundPacket.

@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId) throws PiInterpreterException {
    // Assuming that the packet is ethernet, which is fine since fabric.p4
    // can deparse only ethernet packets.
    Ethernet ethPkt;
    try {
        ethPkt = Ethernet.deserializer().deserialize(packetIn.data().asArray(), 0, packetIn.data().size());
    } catch (DeserializationException dex) {
        throw new PiInterpreterException(dex.getMessage());
    }
    // Returns the ingress port packet metadata.
    Optional<PiPacketMetadata> packetMetadata = packetIn.metadatas().stream().filter(m -> m.id().equals(FabricConstants.INGRESS_PORT)).findFirst();
    if (packetMetadata.isPresent()) {
        ImmutableByteSequence portByteSequence = packetMetadata.get().value();
        short s = portByteSequence.asReadOnlyBuffer().getShort();
        ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(s));
        if (!receivedFrom.port().hasName()) {
            receivedFrom = translateSwitchPort(receivedFrom);
        }
        ByteBuffer rawData = ByteBuffer.wrap(packetIn.data().asArray());
        return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
    } else {
        throw new PiInterpreterException(format("Missing metadata '%s' in packet-in received from '%s': %s", FabricConstants.INGRESS_PORT, deviceId, packetIn));
    }
}
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) 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) 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) Instructions(org.onosproject.net.flow.instructions.Instructions) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Collection(java.util.Collection) Set(java.util.Set) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) FabricConstants(org.onosproject.pipelines.fabric.FabricConstants) String.format(java.lang.String.format) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) PiAction(org.onosproject.net.pi.runtime.PiAction) TABLE(org.onosproject.net.PortNumber.TABLE) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) DriverHandler(org.onosproject.net.driver.DriverHandler) 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) Ethernet(org.onlab.packet.Ethernet) ConnectPoint(org.onosproject.net.ConnectPoint) ByteBuffer(java.nio.ByteBuffer) DeserializationException(org.onlab.packet.DeserializationException) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence)

Example 4 with DeserializationException

use of org.onlab.packet.DeserializationException in project onos by opennetworkinglab.

the class OpenFlowCorePacketContext method send.

@Override
public void send() {
    if (!this.block()) {
        if (outPacket() == null) {
            sendPacket(null);
        } else {
            try {
                Ethernet eth = Ethernet.deserializer().deserialize(outPacket().data().array(), 0, outPacket().data().array().length);
                sendPacket(eth);
            } catch (DeserializationException e) {
                log.warn("Unable to deserialize packet");
            }
        }
    }
}
Also used : Ethernet(org.onlab.packet.Ethernet) DeserializationException(org.onlab.packet.DeserializationException)

Example 5 with DeserializationException

use of org.onlab.packet.DeserializationException in project onos by opennetworkinglab.

the class OpenstackRoutingSnatIcmpHandlerTest method constructIcmpRequestPacket.

private Ethernet constructIcmpRequestPacket(IpAddress srcIp, MacAddress srcMac, IpAddress dstIp, MacAddress dstMac, byte icmpType) {
    try {
        ICMPEcho icmpEcho = new ICMPEcho();
        icmpEcho.setIdentifier((short) 0).setSequenceNum((short) 0);
        ByteBuffer byteBufferIcmpEcho = ByteBuffer.wrap(icmpEcho.serialize());
        ICMP icmp = new ICMP();
        icmp.setIcmpType(icmpType).setIcmpCode(icmpType == TYPE_ECHO_REQUEST ? CODE_ECHO_REQUEST : CODE_ECHO_REPLY).setChecksum((short) 0);
        icmp.setPayload(ICMPEcho.deserializer().deserialize(byteBufferIcmpEcho.array(), 0, ICMPEcho.ICMP_ECHO_HEADER_LENGTH));
        ByteBuffer byteBufferIcmp = ByteBuffer.wrap(icmp.serialize());
        IPv4 iPacket = new IPv4();
        iPacket.setDestinationAddress(dstIp.toString());
        iPacket.setSourceAddress(srcIp.toString());
        iPacket.setTtl((byte) 64);
        iPacket.setChecksum((short) 0);
        iPacket.setDiffServ((byte) 0);
        iPacket.setProtocol(IPv4.PROTOCOL_ICMP);
        iPacket.setPayload(ICMP.deserializer().deserialize(byteBufferIcmp.array(), 0, 8));
        Ethernet ethPacket = new Ethernet();
        ethPacket.setEtherType(TYPE_IPV4);
        ethPacket.setSourceMACAddress(srcMac);
        ethPacket.setDestinationMACAddress(dstMac);
        ethPacket.setPayload(iPacket);
        return ethPacket;
    } catch (DeserializationException e) {
        return null;
    }
}
Also used : ICMPEcho(org.onlab.packet.ICMPEcho) IPv4(org.onlab.packet.IPv4) Ethernet(org.onlab.packet.Ethernet) ByteBuffer(java.nio.ByteBuffer) DeserializationException(org.onlab.packet.DeserializationException) ICMP(org.onlab.packet.ICMP)

Aggregations

DeserializationException (org.onlab.packet.DeserializationException)9 ByteBuffer (java.nio.ByteBuffer)8 Ethernet (org.onlab.packet.Ethernet)6 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 String.format (java.lang.String.format)3 Collection (java.util.Collection)3 List (java.util.List)3 Optional (java.util.Optional)3 ImmutableByteSequence (org.onlab.util.ImmutableByteSequence)3 ImmutableByteSequence.copyFrom (org.onlab.util.ImmutableByteSequence.copyFrom)3 ConnectPoint (org.onosproject.net.ConnectPoint)3 DeviceId (org.onosproject.net.DeviceId)3 Port (org.onosproject.net.Port)3 PortNumber (org.onosproject.net.PortNumber)3 CONTROLLER (org.onosproject.net.PortNumber.CONTROLLER)3 FLOOD (org.onosproject.net.PortNumber.FLOOD)3 DeviceService (org.onosproject.net.device.DeviceService)3 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)3 Criterion (org.onosproject.net.flow.criteria.Criterion)3