Search in sources :

Example 11 with PiPacketOperation

use of org.onosproject.net.pi.runtime.PiPacketOperation 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)

Example 12 with PiPacketOperation

use of org.onosproject.net.pi.runtime.PiPacketOperation in project onos by opennetworkinglab.

the class FabricInterpreterTest method testMapOutboundPacketWithForwarding.

@Test
public void testMapOutboundPacketWithForwarding() throws Exception {
    PortNumber outputPort = PortNumber.TABLE;
    TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
    ByteBuffer data = ByteBuffer.allocate(64);
    OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
    Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
    assertEquals(result.size(), 1);
    ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
    builder.add(PiPacketMetadata.builder().withId(FabricConstants.DO_FORWARDING).withValue(ImmutableByteSequence.copyFrom(1).fit(1)).build());
    PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
    assertEquals(expectedPktOp, result.iterator().next());
}
Also used : PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) ImmutableList(com.google.common.collect.ImmutableList) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ByteBuffer(java.nio.ByteBuffer) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Test(org.junit.Test)

Example 13 with PiPacketOperation

use of org.onosproject.net.pi.runtime.PiPacketOperation in project onos by opennetworkinglab.

the class FabricInterpreterTest method testMapOutboundPacketWithoutForwarding.

@Test
public void testMapOutboundPacketWithoutForwarding() throws Exception {
    PortNumber outputPort = PortNumber.portNumber(1);
    TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
    ByteBuffer data = ByteBuffer.allocate(64);
    OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
    Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
    assertEquals(result.size(), 1);
    ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
    builder.add(PiPacketMetadata.builder().withId(FabricConstants.EGRESS_PORT).withValue(ImmutableByteSequence.copyFrom(outputPort.toLong()).fit(PORT_BITWIDTH)).build());
    PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
    assertEquals(expectedPktOp, result.iterator().next());
}
Also used : PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) ImmutableList(com.google.common.collect.ImmutableList) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) PortNumber(org.onosproject.net.PortNumber) DefaultTrafficTreatment(org.onosproject.net.flow.DefaultTrafficTreatment) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) ByteBuffer(java.nio.ByteBuffer) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) Test(org.junit.Test)

Example 14 with PiPacketOperation

use of org.onosproject.net.pi.runtime.PiPacketOperation in project onos by opennetworkinglab.

the class StreamClientImpl method handlePacketIn.

private void handlePacketIn(P4RuntimeOuterClass.PacketIn packetInMsg) {
    if (log.isTraceEnabled()) {
        log.trace("Received packet-in from {}: {}", deviceId, packetInMsg);
    }
    if (!pipeconfService.getPipeconf(deviceId).isPresent()) {
        log.warn("Unable to handle packet-in from {}, missing pipeconf: {}", deviceId, TextFormat.shortDebugString(packetInMsg));
        return;
    }
    // Decode packet message and post event.
    // TODO: consider implementing a cache to speed up
    // encoding/deconding of packet-in/out (e.g. LLDP, ARP)
    final PiPipeconf pipeconf = pipeconfService.getPipeconf(deviceId).get();
    final PiPacketOperation pktOperation;
    try {
        pktOperation = CODECS.packetIn().decode(packetInMsg, null, pipeconf);
    } catch (CodecException e) {
        log.warn("Unable to process packet-int: {}", e.getMessage());
        return;
    }
    controller.postEvent(new P4RuntimeEvent(P4RuntimeEvent.Type.PACKET_IN, new PacketInEvent(deviceId, pktOperation)));
}
Also used : PacketInEvent(org.onosproject.p4runtime.ctl.controller.PacketInEvent) PiPipeconf(org.onosproject.net.pi.model.PiPipeconf) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) CodecException(org.onosproject.p4runtime.ctl.codec.CodecException) P4RuntimeEvent(org.onosproject.p4runtime.api.P4RuntimeEvent)

Example 15 with PiPacketOperation

use of org.onosproject.net.pi.runtime.PiPacketOperation in project onos by opennetworkinglab.

the class PipelineInterpreterImpl method mapOutboundPacket.

@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
    TrafficTreatment treatment = packet.treatment();
    // We support only packet-out with OUTPUT instructions.
    if (treatment.allInstructions().size() != 1 && treatment.allInstructions().get(0).type() != OUTPUT) {
        throw new PiInterpreterException("Treatment not supported: " + treatment.toString());
    }
    Instruction instruction = treatment.allInstructions().get(0);
    PortNumber port = ((OutputInstruction) instruction).port();
    List<PiPacketOperation> piPacketOps = Lists.newArrayList();
    if (!port.isLogical()) {
        piPacketOps.add(createPiPacketOp(packet.data(), port.toLong()));
    } else if (port.equals(FLOOD)) {
        // Since mytunnel.p4 does not support flooding, we create a packet
        // operation for each switch port.
        DeviceService deviceService = handler().get(DeviceService.class);
        DeviceId deviceId = packet.sendThrough();
        for (Port p : deviceService.getPorts(deviceId)) {
            piPacketOps.add(createPiPacketOp(packet.data(), p.number().toLong()));
        }
    } else {
        throw new PiInterpreterException(format("Output on logical port '%s' not supported", port));
    }
    return piPacketOps;
}
Also used : OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) DeviceId(org.onosproject.net.DeviceId) Port(org.onosproject.net.Port) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DeviceService(org.onosproject.net.device.DeviceService) TrafficTreatment(org.onosproject.net.flow.TrafficTreatment) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) Instruction(org.onosproject.net.flow.instructions.Instruction) PortNumber(org.onosproject.net.PortNumber)

Aggregations

PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)20 PortNumber (org.onosproject.net.PortNumber)18 PiPacketMetadata (org.onosproject.net.pi.runtime.PiPacketMetadata)17 TrafficTreatment (org.onosproject.net.flow.TrafficTreatment)14 InboundPacket (org.onosproject.net.packet.InboundPacket)14 OutboundPacket (org.onosproject.net.packet.OutboundPacket)14 ImmutableList (com.google.common.collect.ImmutableList)13 ByteBuffer (java.nio.ByteBuffer)13 Ethernet (org.onlab.packet.Ethernet)13 ConnectPoint (org.onosproject.net.ConnectPoint)13 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)13 DeviceId (org.onosproject.net.DeviceId)11 Port (org.onosproject.net.Port)11 DeviceService (org.onosproject.net.device.DeviceService)10 PiPipelineInterpreter (org.onosproject.net.pi.model.PiPipelineInterpreter)10 ImmutableMap (com.google.common.collect.ImmutableMap)9 String.format (java.lang.String.format)9 Collection (java.util.Collection)9 List (java.util.List)9 Optional (java.util.Optional)9