use of org.onosproject.net.packet.InboundPacket 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.InboundPacket 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));
}
}
use of org.onosproject.net.packet.InboundPacket in project onos by opennetworkinglab.
the class NeighbourResolutionManager method handlePacket.
private void handlePacket(PacketContext context) {
InboundPacket pkt = context.inPacket();
Ethernet ethPkt = pkt.parsed();
NeighbourMessageContext msgContext = DefaultNeighbourMessageContext.createContext(ethPkt, pkt.receivedFrom(), actions);
if (msgContext == null) {
return;
}
if (handleMessage(msgContext)) {
context.block();
}
}
use of org.onosproject.net.packet.InboundPacket in project onos by opennetworkinglab.
the class NeighbourResolutionManagerTest method context.
/**
* Creates a packet context for the given packet coming in the given port.
*
* @param packet packet to wrap in a packet context
* @param inPort input port of the packet
* @return packet context
*/
private static PacketContext context(Ethernet packet, ConnectPoint inPort) {
InboundPacket inboundPacket = new DefaultInboundPacket(inPort, packet, null);
OutboundPacket outboundPacket = new DefaultOutboundPacket(null, null, null);
return new PacketContextAdapter(0, inboundPacket, outboundPacket, false);
}
use of org.onosproject.net.packet.InboundPacket 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());
}
Aggregations