From 4f7f63825ee1eda154c483da89a72400c988efd6 Mon Sep 17 00:00:00 2001 From: Janus Varmarken Date: Thu, 26 Jul 2018 18:16:14 -0700 Subject: [PATCH] TriggerTrafficExtractor.java: simplify packet inclusion logic (shouldIncludePacket) -- NOTE: this comes with a high cost as it is an inefficient implementation compared to the previous one -- revert to previous implementation once its correctness has been verified. --- .../iotproject/analysis/TriggerTrafficExtractor.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/TriggerTrafficExtractor.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/TriggerTrafficExtractor.java index c0b553c..26276b1 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/TriggerTrafficExtractor.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/TriggerTrafficExtractor.java @@ -22,7 +22,7 @@ public class TriggerTrafficExtractor implements PcapPacketFilter { private int mTriggerIndex = 0; - private static final int INCLUSION_WINDOW_MILLIS = 3_000; + private static final int INCLUSION_WINDOW_MILLIS = 20_000; public TriggerTrafficExtractor(String pcapFilePath, List triggerTimes, String deviceIp) throws PcapNativeException, NotOpenException { mPcapFilePath = pcapFilePath; @@ -55,6 +55,15 @@ public class TriggerTrafficExtractor implements PcapPacketFilter { @Override public boolean shouldIncludePacket(PcapPacket packet) { + // New version. Simpler, but slower: the later a packet arrives, the more elements of mTriggerTimes will need to + // be traversed. + return mTriggerTimes.stream().anyMatch( + trigger -> trigger.isBefore(packet.getTimestamp()) && + packet.getTimestamp().isBefore(trigger.plusMillis(INCLUSION_WINDOW_MILLIS)) + ); + + /* + // Old version. Faster, but more complex - is it correct? if (mTriggerIndex >= mTriggerTimes.size()) { // Don't include packet if we've exhausted the list of trigger times. return false; @@ -78,6 +87,7 @@ public class TriggerTrafficExtractor implements PcapPacketFilter { return shouldIncludePacket(packet); } } + */ } } -- 2.34.1