Skip to content

Commit 080969a

Browse files
ccasconeAndrea-Campanella
authored andcommitted
Simplify packet i/o trace logging for P4Runtime
Change-Id: I3b45597fc68fefb485f860597bcc65d7c03e523a
1 parent 86231ef commit 080969a

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

drivers/p4runtime/src/main/java/org/onosproject/drivers/p4runtime/P4RuntimePacketProgrammable.java

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616

1717
package org.onosproject.drivers.p4runtime;
1818

19+
import org.onlab.packet.EthType;
20+
import org.onosproject.net.flow.instructions.Instructions;
1921
import org.onosproject.net.packet.OutboundPacket;
2022
import org.onosproject.net.packet.PacketProgrammable;
2123
import org.onosproject.net.pi.model.PiPipelineInterpreter;
22-
import org.onosproject.net.pi.runtime.PiPacketOperation;
2324

24-
import java.util.Collection;
25+
import java.nio.ByteBuffer;
26+
import java.util.stream.Collectors;
2527

2628
import static org.onosproject.drivers.p4runtime.P4RuntimeDriverUtils.getInterpreter;
29+
import static org.onosproject.net.flow.instructions.Instruction.Type.OUTPUT;
2730

2831
/**
2932
* Implementation of PacketProgrammable behaviour for P4Runtime.
@@ -45,15 +48,36 @@ public void emit(OutboundPacket packet) {
4548
return;
4649
}
4750

51+
if (log.isTraceEnabled()) {
52+
logPacketOut(packet);
53+
}
54+
4855
try {
49-
Collection<PiPacketOperation> operations = interpreter.mapOutboundPacket(packet);
50-
operations.forEach(piPacketOperation -> {
51-
log.debug("Doing PiPacketOperation {}", piPacketOperation);
52-
client.packetOut(p4DeviceId, piPacketOperation, pipeconf);
53-
});
56+
interpreter.mapOutboundPacket(packet).forEach(
57+
op -> client.packetOut(p4DeviceId, op, pipeconf));
5458
} catch (PiPipelineInterpreter.PiInterpreterException e) {
5559
log.error("Unable to translate outbound packet for {} with pipeconf {}: {}",
5660
deviceId, pipeconf.id(), e.getMessage());
5761
}
5862
}
63+
64+
private void logPacketOut(OutboundPacket packet) {
65+
final EthType.EtherType etherType = getEtherType(packet.data());
66+
final String outPorts = packet.treatment().immediate().stream()
67+
.filter(i -> i.type().equals(OUTPUT))
68+
.map(i -> Long.toString(((Instructions.OutputInstruction) i).port().toLong()))
69+
.collect(Collectors.joining(","));
70+
final String desc = outPorts.isBlank()
71+
? "treatment=" + packet.treatment().toString()
72+
: "egress_ports=" + outPorts;
73+
log.trace("Sending PACKET-OUT >>> device={} {} eth_type={}",
74+
packet.sendThrough(), desc,
75+
etherType.ethType().toString());
76+
}
77+
78+
private EthType.EtherType getEtherType(ByteBuffer data) {
79+
final short shortEthType = data.getShort(12);
80+
data.rewind();
81+
return EthType.EtherType.lookup(shortEthType);
82+
}
5983
}

providers/p4runtime/packet/src/main/java/org/onosproject/provider/p4runtime/packet/impl/P4RuntimePacketProvider.java

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.onosproject.provider.p4runtime.packet.impl;
1818

1919

20+
import org.onlab.packet.EthType;
2021
import org.onosproject.mastership.MastershipService;
2122
import org.onosproject.net.Device;
2223
import org.onosproject.net.DeviceId;
@@ -111,6 +112,12 @@ public void emit(OutboundPacket packet) {
111112
}
112113
}
113114

115+
private EthType.EtherType getEtherType(ByteBuffer data) {
116+
final short shortEthType = data.getShort(12);
117+
data.rewind();
118+
return EthType.EtherType.lookup(shortEthType);
119+
}
120+
114121
/**
115122
* Internal packet context implementation.
116123
*/
@@ -139,7 +146,6 @@ public void send() {
139146
}
140147

141148
OutboundPacket outboundPacket = new DefaultOutboundPacket(deviceId, treatment, rawData);
142-
log.debug("Processing outbound packet: {}", outboundPacket);
143149

144150
emit(outboundPacket);
145151
}
@@ -155,7 +161,7 @@ public void event(P4RuntimeEvent event) {
155161
//Masterhip message is sent to everybody but picked up only by master.
156162
//FIXME we need the device ID into p4RuntimeEvnetSubject to check for mastsership
157163
if (!(event.subject() instanceof P4RuntimePacketIn) || event.type() != P4RuntimeEvent.Type.PACKET_IN) {
158-
log.debug("Event type {}", event.type());
164+
log.debug("Unrecognized event type {}, discarding", event.type());
159165
// Not a packet-in event, ignore it.
160166
return;
161167
}
@@ -183,13 +189,18 @@ public void event(P4RuntimeEvent event) {
183189
return;
184190
}
185191

192+
if (log.isTraceEnabled()) {
193+
final EthType.EtherType etherType = getEtherType(inPkt.unparsed());
194+
log.trace("Received PACKET-IN <<< device={} ingress_port={} eth_type={}",
195+
inPkt.receivedFrom().deviceId(), inPkt.receivedFrom().port(),
196+
etherType.ethType().toString());
197+
}
198+
186199
if (inPkt == null) {
187200
log.debug("Received null inbound packet. Ignoring.");
188201
return;
189202
}
190203

191-
log.debug("Processing inbound packet: {}", inPkt.toString());
192-
193204
OutboundPacket outPkt = new DefaultOutboundPacket(eventSubject.deviceId(), null,
194205
operation.data().asReadOnlyBuffer());
195206
PacketContext pktCtx = new P4RuntimePacketContext(System.currentTimeMillis(), inPkt, outPkt, false);

0 commit comments

Comments
 (0)