Search in sources :

Example 1 with P4RuntimePacketIn

use of org.onosproject.p4runtime.api.P4RuntimePacketIn in project onos by opennetworkinglab.

the class P4RuntimePacketProvider method handleP4RuntimeEvent.

private void handleP4RuntimeEvent(P4RuntimeEvent event) {
    // FIXME we need the device ID into p4RuntimeEvnetSubject to check for mastsership
    if (!(event.subject() instanceof P4RuntimePacketIn) || event.type() != P4RuntimeEvent.Type.PACKET_IN) {
        log.debug("Unrecognized event type {}, discarding", event.type());
        // Not a packet-in event, ignore it.
        return;
    }
    P4RuntimePacketIn eventSubject = (P4RuntimePacketIn) event.subject();
    DeviceId deviceId = eventSubject.deviceId();
    Device device = deviceService.getDevice(eventSubject.deviceId());
    if (device == null) {
        log.warn("Unable to process packet-in from {}, device is null in the core", deviceId);
        return;
    }
    if (!device.is(PiPipelineInterpreter.class)) {
        log.warn("Unable to process packet-in from {}, device has no PiPipelineInterpreter behaviour", deviceId);
        return;
    }
    PiPacketOperation operation = eventSubject.packetOperation();
    InboundPacket inPkt;
    try {
        inPkt = device.as(PiPipelineInterpreter.class).mapInboundPacket(operation, deviceId);
    } catch (PiPipelineInterpreter.PiInterpreterException e) {
        log.warn("Unable to interpret inbound packet from {}: {}", deviceId, e.getMessage());
        return;
    }
    if (log.isTraceEnabled()) {
        final EthType.EtherType etherType = getEtherType(inPkt.unparsed());
        log.trace("Received PACKET-IN <<< device={} ingress_port={} eth_type={}", inPkt.receivedFrom().deviceId(), inPkt.receivedFrom().port(), etherType.ethType().toString());
    }
    if (inPkt == null) {
        log.debug("Received null inbound packet. Ignoring.");
        return;
    }
    OutboundPacket outPkt = new DefaultOutboundPacket(eventSubject.deviceId(), null, operation.data().asReadOnlyBuffer());
    PacketContext pktCtx = new P4RuntimePacketContext(System.currentTimeMillis(), inPkt, outPkt, false);
    // Pushing the packet context up for processing.
    providerService.processPacket(pktCtx);
}
Also used : DeviceId(org.onosproject.net.DeviceId) Device(org.onosproject.net.Device) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) OutboundPacket(org.onosproject.net.packet.OutboundPacket) DefaultOutboundPacket(org.onosproject.net.packet.DefaultOutboundPacket) EthType(org.onlab.packet.EthType) P4RuntimePacketIn(org.onosproject.p4runtime.api.P4RuntimePacketIn) InboundPacket(org.onosproject.net.packet.InboundPacket) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext)

Aggregations

EthType (org.onlab.packet.EthType)1 Device (org.onosproject.net.Device)1 DeviceId (org.onosproject.net.DeviceId)1 DefaultOutboundPacket (org.onosproject.net.packet.DefaultOutboundPacket)1 DefaultPacketContext (org.onosproject.net.packet.DefaultPacketContext)1 InboundPacket (org.onosproject.net.packet.InboundPacket)1 OutboundPacket (org.onosproject.net.packet.OutboundPacket)1 PacketContext (org.onosproject.net.packet.PacketContext)1 PiPipelineInterpreter (org.onosproject.net.pi.model.PiPipelineInterpreter)1 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)1 P4RuntimePacketIn (org.onosproject.p4runtime.api.P4RuntimePacketIn)1