From: Janus Varmarken Date: Fri, 27 Jul 2018 01:16:14 +0000 (-0700) Subject: TriggerTrafficExtractor.java: simplify packet inclusion logic (shouldIncludePacket... X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=4f7f63825ee1eda154c483da89a72400c988efd6;p=pingpong.git 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. --- 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); } } + */ } }