From 0990ea745f5e7976cf71a75e971ce78c98ae9a4a Mon Sep 17 00:00:00 2001 From: Janus Varmarken Date: Tue, 24 Jul 2018 14:41:16 -0700 Subject: [PATCH] PcapHandleReader: count and print (to std.err) the number of packets that appear out of order --- .../main/java/edu/uci/iotproject/io/PcapHandleReader.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/io/PcapHandleReader.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/io/PcapHandleReader.java index 2c387f3..e01f712 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/io/PcapHandleReader.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/io/PcapHandleReader.java @@ -43,12 +43,13 @@ public class PcapHandleReader { * @throws TimeoutException if packets are being read from a live capture and the timeout expired. */ public void readFromHandle() throws PcapNativeException, NotOpenException, TimeoutException { + int outOfOrderPackets = 0; try { PcapPacket prevPacket = null; PcapPacket packet; while ((packet = mHandle.getNextPacketEx()) != null) { if (prevPacket != null && packet.getTimestamp().isBefore(prevPacket.getTimestamp())) { - System.out.println("Out-of-order (in terms of timestamp) packet detected"); + outOfOrderPackets++; /* // Fail early if assumption doesn't hold. mHandle.close(); @@ -67,6 +68,11 @@ public class PcapHandleReader { // Reached end of file. All good. System.out.println(String.format("%s: finished reading pcap file", getClass().getSimpleName())); } + if (outOfOrderPackets > 0) { + System.err.println( + String.format("[[[ %s: %d packets appeared out of order (with regards to their timestamps) ]]]", + getClass().getSimpleName(), outOfOrderPackets)); + } mHandle.close(); } -- 2.34.1