Search in sources :

Example 11 with DefaultInboundPacket

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

the class DefaultVirtualPacketProviderTest method virtualizePacket.

/**
 * Test the physical packet context is delivered to a proper (physical)
 *  virtual network and device.
 */
@Test
public void virtualizePacket() {
    Ethernet eth = new Ethernet();
    eth.setSourceMACAddress(SRC_MAC_ADDR);
    eth.setDestinationMACAddress(DST_MAC_ADDR);
    eth.setVlanID((short) 1);
    eth.setPayload(null);
    InboundPacket pInPacket = new DefaultInboundPacket(CP22, eth, ByteBuffer.wrap(eth.serialize()));
    PacketContext pContext = new TestPacketContext(System.nanoTime(), pInPacket, null, false);
    testPacketService.sendTestPacketContext(pContext);
    PacketContext vContext = providerService.getRequestedPacketContext(0);
    InboundPacket vInPacket = vContext.inPacket();
    assertEquals("the packet should be received from VCP12", VCP12, vInPacket.receivedFrom());
    assertEquals("VLAN tag should be excludede", VlanId.UNTAGGED, vInPacket.parsed().getVlanID());
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Ethernet(org.onlab.packet.Ethernet) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) Test(org.junit.Test)

Example 12 with DefaultInboundPacket

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

the class OpenstackRoutingSnatIcmpHandlerTest method sendPacket.

private void sendPacket(Ethernet ethernet) {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(ethernet.serialize());
    InboundPacket inPacket = new DefaultInboundPacket(connectPoint(srcDeviceId1.toString(), Integer.parseInt(srcPortNum1.toString())), ethernet, byteBuffer);
    PacketContext context = new TestPacketContext(127L, inPacket, null, false);
    packetProcessor.process(context);
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) ByteBuffer(java.nio.ByteBuffer)

Example 13 with DefaultInboundPacket

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

the class OpenstackSwitchingArpHandlerTest method sendPacket.

/**
 * Sends an Ethernet packet to the process method of the Packet processor.
 *
 * @param ethernet Ethernet packet
 */
private void sendPacket(Ethernet ethernet) {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(ethernet.serialize());
    InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), ethernet, byteBuffer);
    PacketContext context = new TestPacketContext(127L, inPacket, null, false);
    packetProcessor.process(context);
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) ByteBuffer(java.nio.ByteBuffer)

Example 14 with DefaultInboundPacket

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

the class OpenstackSwitchingDhcpHandlerTest method sendPacket.

/**
 * Sends an Ethernet packet to the process method of the Packet Processor.
 *
 * @param ethernet Ethernet packet
 */
private void sendPacket(Ethernet ethernet) {
    final ByteBuffer byteBuffer = ByteBuffer.wrap(ethernet.serialize());
    InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), ethernet, byteBuffer);
    PacketContext context = new TestPacketContext(127L, inPacket, null, false);
    packetProcessor.process(context);
}
Also used : DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) InboundPacket(org.onosproject.net.packet.InboundPacket) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) DefaultPacketContext(org.onosproject.net.packet.DefaultPacketContext) PacketContext(org.onosproject.net.packet.PacketContext) ByteBuffer(java.nio.ByteBuffer)

Example 15 with DefaultInboundPacket

use of org.onosproject.net.packet.DefaultInboundPacket in project TFG by mattinelorza.

the class InterpreterImpl method mapInboundPacket.

/**
 * Returns an ONS InboundPacket equivalent to the given pipeconf-specific
 * packet-in operation.
 *
 * @param packetIn packet operation
 * @param deviceId ID of the device that originated the packet-in
 * @return inbound packet
 * @throws PiInterpreterException if the packet operation cannot be mapped
 *                                to an inbound packet
 */
@Override
public InboundPacket mapInboundPacket(PiPacketOperation packetIn, DeviceId deviceId) throws PiInterpreterException {
    // Find the ingress_port metadata.
    // *** TODO EXERCISE 4: modify metadata names to match P4Info
    // ---- START SOLUTION ----
    final String inportMetadataName = "ADD HERE METADATA NAME FOR THE INGRESS PORT";
    // ---- END SOLUTION ----
    Optional<PiPacketMetadata> inportMetadata = packetIn.metadatas().stream().filter(meta -> meta.id().id().equals(inportMetadataName)).findFirst();
    if (!inportMetadata.isPresent()) {
        throw new PiInterpreterException(format("Missing metadata '%s' in packet-in received from '%s': %s", inportMetadataName, deviceId, packetIn));
    }
    // Build ONOS InboundPacket instance with the given ingress port.
    // 1. Parse packet-in object into Ethernet packet instance.
    final byte[] payloadBytes = packetIn.data().asArray();
    final ByteBuffer rawData = ByteBuffer.wrap(payloadBytes);
    final Ethernet ethPkt;
    try {
        ethPkt = Ethernet.deserializer().deserialize(payloadBytes, 0, packetIn.data().size());
    } catch (DeserializationException dex) {
        throw new PiInterpreterException(dex.getMessage());
    }
    // 2. Get ingress port
    final ImmutableByteSequence portBytes = inportMetadata.get().value();
    final short portNum = portBytes.asReadOnlyBuffer().getShort();
    final ConnectPoint receivedFrom = new ConnectPoint(deviceId, PortNumber.portNumber(portNum));
    return new DefaultInboundPacket(receivedFrom, ethPkt, rawData);
}
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) AbstractHandlerBehaviour(org.onosproject.net.driver.AbstractHandlerBehaviour) 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) Map(java.util.Map) 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) OutputInstruction(org.onosproject.net.flow.instructions.Instructions.OutputInstruction) PiPipelineInterpreter(org.onosproject.net.pi.model.PiPipelineInterpreter) ImmutableMap(com.google.common.collect.ImmutableMap) DefaultInboundPacket(org.onosproject.net.packet.DefaultInboundPacket) Collection(java.util.Collection) PiMatchFieldId(org.onosproject.net.pi.model.PiMatchFieldId) PiPacketMetadataId(org.onosproject.net.pi.model.PiPacketMetadataId) CPU_PORT_ID(org.onosproject.ngsdn.tutorial.AppConstants.CPU_PORT_ID) String.format(java.lang.String.format) CONTROLLER(org.onosproject.net.PortNumber.CONTROLLER) PiAction(org.onosproject.net.pi.runtime.PiAction) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) 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) ByteBuffer(java.nio.ByteBuffer) ConnectPoint(org.onosproject.net.ConnectPoint) DeserializationException(org.onlab.packet.DeserializationException) Ethernet(org.onlab.packet.Ethernet) ImmutableByteSequence(org.onlab.util.ImmutableByteSequence)

Aggregations

DefaultInboundPacket (org.onosproject.net.packet.DefaultInboundPacket)20 InboundPacket (org.onosproject.net.packet.InboundPacket)19 ByteBuffer (java.nio.ByteBuffer)12 Ethernet (org.onlab.packet.Ethernet)12 ConnectPoint (org.onosproject.net.ConnectPoint)11 PortNumber (org.onosproject.net.PortNumber)9 PiPacketMetadata (org.onosproject.net.pi.runtime.PiPacketMetadata)9 PiPacketOperation (org.onosproject.net.pi.runtime.PiPacketOperation)9 PacketContext (org.onosproject.net.packet.PacketContext)7 Test (org.junit.Test)6 DeserializationException (org.onlab.packet.DeserializationException)6 DeviceId (org.onosproject.net.DeviceId)6 Port (org.onosproject.net.Port)6 DefaultPacketContext (org.onosproject.net.packet.DefaultPacketContext)6 OutboundPacket (org.onosproject.net.packet.OutboundPacket)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