Search in sources :

Example 6 with InboundPacket

use of org.onosproject.net.packet.InboundPacket in project onos by opennetworkinglab.

the class CastorArpManager method handlePacket.

@Override
public boolean handlePacket(PacketContext context) {
    InboundPacket pkt = context.inPacket();
    Ethernet ethPkt = pkt.parsed();
    if (ethPkt == null) {
        return false;
    }
    MessageContext msgContext = createContext(ethPkt, pkt.receivedFrom());
    if (msgContext == null) {
        return false;
    }
    switch(msgContext.type()) {
        case REPLY:
            forward(msgContext);
            updateMac(msgContext);
            handleArpForL2(msgContext);
            break;
        case REQUEST:
            forward(msgContext);
            updateMac(msgContext);
            handleArpForL2(msgContext);
            break;
        default:
            return false;
    }
    context.block();
    return true;
}
Also used : InboundPacket(org.onosproject.net.packet.InboundPacket) Ethernet(org.onlab.packet.Ethernet)

Example 7 with InboundPacket

use of org.onosproject.net.packet.InboundPacket 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 8 with InboundPacket

use of org.onosproject.net.packet.InboundPacket 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)

Example 9 with InboundPacket

use of org.onosproject.net.packet.InboundPacket 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 10 with InboundPacket

use of org.onosproject.net.packet.InboundPacket in project fabric-tna by stratum.

the class FabricInterpreterTest method testMapInboundPacket.

@Test
public void testMapInboundPacket() throws ImmutableByteSequence.ByteSequenceTrimException, PiPipelineInterpreter.PiInterpreterException {
    PortNumber inputPort = PortNumber.portNumber(1);
    PiPacketMetadata pktInMetadata = PiPacketMetadata.builder().withId(P4InfoConstants.INGRESS_PORT).withValue(ImmutableByteSequence.copyFrom(inputPort.toLong()).fit(P4InfoConstants.INGRESS_PORT_BITWIDTH)).build();
    Ethernet packet = new Ethernet();
    packet.setDestinationMACAddress(SRC_MAC);
    packet.setSourceMACAddress(DST_MAC);
    packet.setEtherType((short) 0xBA00);
    packet.setPayload(new Data());
    PiPacketOperation pktInOp = PiPacketOperation.builder().withMetadata(pktInMetadata).withData(ImmutableByteSequence.copyFrom(packet.serialize())).withType(PiPacketOperationType.PACKET_IN).build();
    InboundPacket result = interpreter.mapInboundPacket(pktInOp, DEVICE_ID);
    ConnectPoint receiveFrom = new ConnectPoint(DEVICE_ID, inputPort);
    InboundPacket expectedInboundPacket = new DefaultInboundPacket(receiveFrom, packet, ByteBuffer.wrap(packet.serialize()));
    assertEquals(result.receivedFrom(), expectedInboundPacket.receivedFrom());
    assertEquals(result.parsed(), expectedInboundPacket.parsed());
    assertEquals(result.cookie(), expectedInboundPacket.cookie());
    assertEquals(result.unparsed(), expectedInboundPacket.unparsed());
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) PiPacketMetadata(org.onosproject.net.pi.runtime.PiPacketMetadata) Ethernet(org.onlab.packet.Ethernet) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) PiPacketOperation(org.onosproject.net.pi.runtime.PiPacketOperation) DriverData(org.onosproject.net.driver.DriverData) Data(org.onlab.packet.Data) PortNumber(org.onosproject.net.PortNumber) ConnectPoint(org.onosproject.net.ConnectPoint) Test(org.junit.Test)

Aggregations

InboundPacket (org.onosproject.net.packet.InboundPacket)28 DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)19 Ethernet (org.onlab.packet.Ethernet)18 ByteBuffer (java.nio.ByteBuffer)12 ConnectPoint (org.onosproject.net.ConnectPoint)10 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)10 PortNumber (org.onosproject.net.PortNumber)9 PiPacketMetadata (org.onosproject.net.pi.runtime.PiPacketMetadata)9 DeserializationException (org.onlab.packet.DeserializationException)7 OutboundPacket (org.onosproject.net.packet.OutboundPacket)7 PacketContext (org.onosproject.net.packet.PacketContext)7 Test (org.junit.Test)6 DeviceId (org.onosproject.net.DeviceId)6 Port (org.onosproject.net.Port)6 DefaultPacketContext (org.onosproject.net.packet.DefaultPacketContext)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 String.format (java.lang.String.format)5 Collection (java.util.Collection)5 List (java.util.List)5