Search in sources :

Example 6 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 7 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 8 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 9 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 10 with DeserializationException

use of org.onlab.packet.DeserializationException in project fabric-tna by stratum.

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(P4InfoConstants.INGRESS_PORT)).findFirst();
    if (packetMetadata.isPresent()) {
        try {
            ImmutableByteSequence portByteSequence = packetMetadata.get().value().fit(P4InfoConstants.INGRESS_PORT_BITWIDTH);
            UnsignedInteger ui = UnsignedInteger.fromIntBits(portByteSequence.asReadOnlyBuffer().getInt());
            ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(ui.longValue()));
            if (!receivedFrom.port().hasName()) {
                receivedFrom = translateSwitchPort(receivedFrom);
            }
            ByteBuffer rawData = ByteBuffer.wrap(packetIn.data().asArray());
            return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
        } catch (ImmutableByteSequence.ByteSequenceTrimException e) {
            throw new PiInterpreterException(format("Malformed metadata '%s' in packet-in received from '%s': %s", P4InfoConstants.INGRESS_PORT, deviceId, packetIn));
        }
    } else {
        throw new PiInterpreterException(format("Missing metadata '%s' in packet-in received from '%s': %s", P4InfoConstants.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) ZERO(org.stratumproject.fabric.tna.Constants.ZERO) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence) PortNumber(org.onosproject.net.PortNumber) DeviceService(org.onosproject.net.device.DeviceService) FabricTreatmentInterpreter.mapNextTreatment(org.stratumproject.fabric.tna.behaviour.FabricTreatmentInterpreter.mapNextTreatment) 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) UnsignedInteger(com.google.common.primitives.UnsignedInteger) 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) FabricTreatmentInterpreter.mapForwardingTreatment(org.stratumproject.fabric.tna.behaviour.FabricTreatmentInterpreter.mapForwardingTreatment) Set(java.util.Set) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) SlicingService(org.stratumproject.fabric.tna.slicing.api.SlicingService) FabricTreatmentInterpreter.mapAclTreatment(org.stratumproject.fabric.tna.behaviour.FabricTreatmentInterpreter.mapAclTreatment) 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) FabricTreatmentInterpreter.mapEgressNextTreatment(org.stratumproject.fabric.tna.behaviour.FabricTreatmentInterpreter.mapEgressNextTreatment) Optional(java.util.Optional) DeviceId(org.onosproject.net.DeviceId) OUTPUT(org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT) ONE(org.stratumproject.fabric.tna.Constants.ONE) FabricTreatmentInterpreter.mapPreNextTreatment(org.stratumproject.fabric.tna.behaviour.FabricTreatmentInterpreter.mapPreNextTreatment) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) Ethernet(org.onlab.packet.Ethernet) UnsignedInteger(com.google.common.primitives.UnsignedInteger) ConnectPoint(org.onosproject.net.ConnectPoint) ByteBuffer(java.nio.ByteBuffer) DeserializationException(org.onlab.packet.DeserializationException) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence)

Aggregations

DeserializationException (org.onlab.packet.DeserializationException)21 Ethernet (org.onlab.packet.Ethernet)17 ByteBuffer (java.nio.ByteBuffer)10 RADIUS (org.onlab.packet.RADIUS)9 UnknownHostException (java.net.UnknownHostException)7 Test (org.junit.Test)7 InboundPacket (org.onosproject.net.packet.InboundPacket)6 IpAddress (org.onlab.packet.IpAddress)5 ConnectPoint (org.onosproject.net.ConnectPoint)5 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)5 ImmutableList (com.google.common.collect.ImmutableList)4 ImmutableMap (com.google.common.collect.ImmutableMap)4 String.format (java.lang.String.format)4 Collection (java.util.Collection)4 List (java.util.List)4 Optional (java.util.Optional)4 IPv4 (org.onlab.packet.IPv4)4 ImmutableByteSequence (org.onlab.util.ImmutableByteSequence)4 ImmutableByteSequence.copyFrom (org.onlab.util.ImmutableByteSequence.copyFrom)4 DeviceId (org.onosproject.net.DeviceId)4