Search in sources :

Example 1 with FLOOD

use of org.onosproject.net.PortNumber.FLOOD in project onos by opennetworkinglab.

the class BasicInterpreterImpl method mapOutboundPacket.

@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
    TrafficTreatment treatment = packet.treatment();
    // basic.p4 supports only OUTPUT instructions.
    List<OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (OutputInstruction) i).collect(toList());
    if (treatment.allInstructions().size() != outInstructions.size()) {
        // There are other instructions that are not of type OUTPUT.
        throw new PiInterpreterException("Treatment not supported: " + treatment);
    }
    ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
    for (OutputInstruction outInst : outInstructions) {
        if (outInst.port().isLogical() && !outInst.port().equals(FLOOD)) {
            throw new PiInterpreterException(format("Output on logical port '%s' not supported", outInst.port()));
        } else if (outInst.port().equals(FLOOD)) {
            // Since basic.p4 does not support flooding, we create a packet
            // operation for each switch port.
            final DeviceService deviceService = handler().get(DeviceService.class);
            for (Port port : deviceService.getPorts(packet.sendThrough())) {
                builder.add(createPiPacketOperation(packet.data(), port.number().toLong()));
            }
        } else {
            builder.add(createPiPacketOperation(packet.data(), outInst.port().toLong()));
        }
    }
    return builder.build();
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) 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) ImmutableList(com.google.common.collect.ImmutableList) Port(org.onosproject.net.Port) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DeviceService(org.onosproject.net.device.DeviceService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment)

Example 2 with FLOOD

use of org.onosproject.net.PortNumber.FLOOD in project onos by opennetworkinglab.

the class FabricInterpreter method mapOutboundPacket.

@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
    DeviceId deviceId = packet.sendThrough();
    TrafficTreatment treatment = packet.treatment();
    // fabric.p4 supports only OUTPUT instructions.
    List<Instructions.OutputInstruction> outInstructions = treatment.allInstructions().stream().filter(i -> i.type().equals(OUTPUT)).map(i -> (Instructions.OutputInstruction) i).collect(toList());
    if (treatment.allInstructions().size() != outInstructions.size()) {
        // There are other instructions that are not of type OUTPUT.
        throw new PiInterpreterException("Treatment not supported: " + treatment);
    }
    ImmutableList.Builder<PiPacketOperation> builder = ImmutableList.builder();
    for (Instructions.OutputInstruction outInst : outInstructions) {
        if (outInst.port().equals(TABLE)) {
            // Logical port. Forward using the switch tables like a regular packet.
            builder.add(createPiPacketOperation(packet.data(), -1, true));
        } else if (outInst.port().equals(FLOOD)) {
            // Logical port. Create a packet operation for each switch port.
            final DeviceService deviceService = handler().get(DeviceService.class);
            for (Port port : deviceService.getPorts(packet.sendThrough())) {
                builder.add(createPiPacketOperation(packet.data(), port.number().toLong(), false));
            }
        } else if (outInst.port().isLogical()) {
            throw new PiInterpreterException(format("Output on logical port '%s' not supported", outInst.port()));
        } else {
            // Send as-is to given port bypassing all switch tables.
            builder.add(createPiPacketOperation(packet.data(), outInst.port().toLong(), false));
        }
    }
    return builder.build();
}
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) DeviceId(org.onosproject.net.DeviceId) ImmutableList(com.google.common.collect.ImmutableList) Port(org.onosproject.net.Port) DeviceService(org.onosproject.net.device.DeviceService) Instructions(org.onosproject.net.flow.instructions.Instructions) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation)

Aggregations

ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 String.format (java.lang.String.format)2 ByteBuffer (java.nio.ByteBuffer)2 Collection (java.util.Collection)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors.toList (java.util.stream.Collectors.toList)2 DeserializationException (org.onlab.packet.DeserializationException)2 Ethernet (org.onlab.packet.Ethernet)2 ImmutableByteSequence (org.onlab.util.ImmutableByteSequence)2 ImmutableByteSequence.copyFrom (org.onlab.util.ImmutableByteSequence.copyFrom)2 ConnectPoint (org.onosproject.net.ConnectPoint)2 DeviceId (org.onosproject.net.DeviceId)2 Port (org.onosproject.net.Port)2 PortNumber (org.onosproject.net.PortNumber)2 CONTROLLER (org.onosproject.net.PortNumber.CONTROLLER)2 FLOOD (org.onosproject.net.PortNumber.FLOOD)2 DeviceService (org.onosproject.net.device.DeviceService)2 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)2