use of org.onosproject.net.pi.runtime.PiPacketOperation 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.pi.runtime.PiPacketOperation in project onos by opennetworkinglab.
the class FabricInterpreterTest method testMapOutboundPacketWithForwarding.
@Test
public void testMapOutboundPacketWithForwarding() throws Exception {
PortNumber outputPort = PortNumber.TABLE;
TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
ByteBuffer data = ByteBuffer.allocate(64);
OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
assertEquals(result.size(), 1);
ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
builder.add(PiPacketMetadata.builder().withId(FabricConstants.DO_FORWARDING).withValue(ImmutableByteSequence.copyFrom(1).fit(1)).build());
PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
assertEquals(expectedPktOp, result.iterator().next());
}
use of org.onosproject.net.pi.runtime.PiPacketOperation in project onos by opennetworkinglab.
the class FabricInterpreterTest method testMapOutboundPacketWithoutForwarding.
@Test
public void testMapOutboundPacketWithoutForwarding() throws Exception {
PortNumber outputPort = PortNumber.portNumber(1);
TrafficTreatment outputTreatment = DefaultTrafficTreatment.builder().setOutput(outputPort).build();
ByteBuffer data = ByteBuffer.allocate(64);
OutboundPacket outPkt = new DefaultOutboundPacket(DEVICE_ID, outputTreatment, data);
Collection<PiPacketOperation> result = interpreter.mapOutboundPacket(outPkt);
assertEquals(result.size(), 1);
ImmutableList.Builder<PiPacketMetadata> builder = ImmutableList.builder();
builder.add(PiPacketMetadata.builder().withId(FabricConstants.EGRESS_PORT).withValue(ImmutableByteSequence.copyFrom(outputPort.toLong()).fit(PORT_BITWIDTH)).build());
PiPacketOperation expectedPktOp = PiPacketOperation.builder().withType(PiPacketOperationType.PACKET_OUT).withData(ImmutableByteSequence.copyFrom(data)).withMetadatas(builder.build()).build();
assertEquals(expectedPktOp, result.iterator().next());
}
use of org.onosproject.net.pi.runtime.PiPacketOperation in project onos by opennetworkinglab.
the class StreamClientImpl method handlePacketIn.
private void handlePacketIn(P4RuntimeOuterClass.PacketIn packetInMsg) {
if (log.isTraceEnabled()) {
log.trace("Received packet-in from {}: {}", deviceId, packetInMsg);
}
if (!pipeconfService.getPipeconf(deviceId).isPresent()) {
log.warn("Unable to handle packet-in from {}, missing pipeconf: {}", deviceId, TextFormat.shortDebugString(packetInMsg));
return;
}
// Decode packet message and post event.
// TODO: consider implementing a cache to speed up
// encoding/deconding of packet-in/out (e.g. LLDP, ARP)
final PiPipeconf pipeconf = pipeconfService.getPipeconf(deviceId).get();
final PiPacketOperation pktOperation;
try {
pktOperation = CODECS.packetIn().decode(packetInMsg, null, pipeconf);
} catch (CodecException e) {
log.warn("Unable to process packet-int: {}", e.getMessage());
return;
}
controller.postEvent(new P4RuntimeEvent(P4RuntimeEvent.Type.PACKET_IN, new PacketInEvent(deviceId, pktOperation)));
}
use of org.onosproject.net.pi.runtime.PiPacketOperation in project onos by opennetworkinglab.
the class PipelineInterpreterImpl method mapOutboundPacket.
@Override
public Collection<PiPacketOperation> mapOutboundPacket(OutboundPacket packet) throws PiInterpreterException {
TrafficTreatment treatment = packet.treatment();
// We support only packet-out with OUTPUT instructions.
if (treatment.allInstructions().size() != 1 && treatment.allInstructions().get(0).type() != OUTPUT) {
throw new PiInterpreterException("Treatment not supported: " + treatment.toString());
}
Instruction instruction = treatment.allInstructions().get(0);
PortNumber port = ((OutputInstruction) instruction).port();
List<PiPacketOperation> piPacketOps = Lists.newArrayList();
if (!port.isLogical()) {
piPacketOps.add(createPiPacketOp(packet.data(), port.toLong()));
} else if (port.equals(FLOOD)) {
// Since mytunnel.p4 does not support flooding, we create a packet
// operation for each switch port.
DeviceService deviceService = handler().get(DeviceService.class);
DeviceId deviceId = packet.sendThrough();
for (Port p : deviceService.getPorts(deviceId)) {
piPacketOps.add(createPiPacketOp(packet.data(), p.number().toLong()));
}
} else {
throw new PiInterpreterException(format("Output on logical port '%s' not supported", port));
}
return piPacketOps;
}
Aggregations