use of org.onosproject.net.packet.DefaultInboundPacket 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());
}
use of org.onosproject.net.packet.DefaultInboundPacket in project fabric-tna by stratum.
the class FabricInterpreterTest method testMapInboundPacketWithPortTranslation.
@Test
public void testMapInboundPacketWithPortTranslation() throws ImmutableByteSequence.ByteSequenceTrimException, PiPipelineInterpreter.PiInterpreterException {
PortNumber inputPort = PortNumber.portNumber(1, "ONE");
ConnectPoint receiveFrom = new ConnectPoint(DEVICE_ID, inputPort);
Port port = createNiceMock(Port.class);
expect(port.number()).andReturn(inputPort).anyTimes();
replay(port);
expect(deviceService.getPort(receiveFrom)).andReturn(port).anyTimes();
replay(deviceService);
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);
InboundPacket expectedInboundPacket = new DefaultInboundPacket(receiveFrom, packet, ByteBuffer.wrap(packet.serialize()));
assertEquals(result.receivedFrom(), expectedInboundPacket.receivedFrom());
assertEquals(result.receivedFrom().port().name(), expectedInboundPacket.receivedFrom().port().name());
assertEquals(result.parsed(), expectedInboundPacket.parsed());
assertEquals(result.cookie(), expectedInboundPacket.cookie());
assertEquals(result.unparsed(), expectedInboundPacket.unparsed());
}
use of org.onosproject.net.packet.DefaultInboundPacket in project onos by opennetworkinglab.
the class DhcpManagerTest method sendPacket.
/**
* Sends an Ethernet packet to the process method of the Packet Processor.
* @param reply Ethernet packet
*/
private void sendPacket(Ethernet reply) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(reply.serialize());
InboundPacket inPacket = new DefaultInboundPacket(connectPoint("1", 1), reply, byteBuffer);
PacketContext context = new TestPacketContext(127L, inPacket, null, false);
packetProcessor.process(context);
}
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);
}
use of org.onosproject.net.packet.DefaultInboundPacket in project dhcpl2relay by opencord.
the class DhcpL2RelayTestBase method sendPacket.
/**
* Sends an Ethernet packet to the process method of the Packet Processor.
*
* @param pkt Ethernet packet
*/
void sendPacket(Ethernet pkt, ConnectPoint cp) {
final ByteBuffer byteBuffer = ByteBuffer.wrap(pkt.serialize());
InboundPacket inPacket = new DefaultInboundPacket(cp, pkt, byteBuffer);
PacketContext context = new TestPacketContext(127L, inPacket, null, false);
packetProcessor.process(context);
}
Aggregations