Perform trigger traffic extraction on data from Feb 13 experiment
authorJanus Varmarken <varmarken@gmail.com>
Fri, 20 Jul 2018 20:50:59 +0000 (13:50 -0700)
committerJanus Varmarken <varmarken@gmail.com>
Fri, 20 Jul 2018 20:50:59 +0000 (13:50 -0700)
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/PcapHandleReader.java
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/TriggerTrafficExtractor.java

index b1e5650..7cf0c3c 100644 (file)
@@ -3,10 +3,14 @@ package edu.uci.iotproject;
 import edu.uci.iotproject.analysis.PcapPacketPair;
 import edu.uci.iotproject.analysis.PcapProcessingPipeline;
 import edu.uci.iotproject.analysis.TcpConversationUtils;
+import edu.uci.iotproject.analysis.TriggerTrafficExtractor;
+import edu.uci.iotproject.io.TriggerTimesFileReader;
 import org.pcap4j.core.*;
+import org.pcap4j.packet.namednumber.DataLinkType;
 
 import java.io.EOFException;
 import java.net.UnknownHostException;
+import java.time.Instant;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.concurrent.TimeoutException;
@@ -87,6 +91,7 @@ public class Main {
         }
         */
 
+        /*
         // -------- 07-17-2018 --------
         // Only consider packets to/from the TP-Link plug.
         PcapReader pcapReader = new PcapReader(args[0], "ip host 192.168.1.159");
@@ -107,9 +112,26 @@ public class Main {
         }
 
         // ----------------------------
+        */
 
-
-
+        // -------- 07-19-2018 --------
+        TriggerTimesFileReader ttfr = new TriggerTimesFileReader();
+        List<Instant> triggerTimes = ttfr.readTriggerTimes("/Users/varmarken/Downloads/tplink-feb-13-2018.timestamps", false);
+//        triggerTimes.stream().forEach(i -> System.out.println(i.atZone(TriggerTimesFileReader.ZONE_ID_LOS_ANGELES).toString()));
+        String pcapFile = "/Users/varmarken/Development/Repositories/UCI/NetworkingGroup/smart_home_traffic/Code/Projects/SmartPlugDetector/pcap/wlan1.local.dns.pcap";
+        String tpLinkPlugIp = "192.168.1.159";
+        TriggerTrafficExtractor tte = new TriggerTrafficExtractor(pcapFile, triggerTimes, tpLinkPlugIp);
+        final PcapDumper outputter = Pcaps.openDead(DataLinkType.EN10MB, 65536).dumpOpen("/Users/varmarken/temp/traces/output/tplink-filtered.pcap");
+        tte.performExtraction(pkt -> {
+            try {
+                outputter.dump(pkt);
+            } catch (NotOpenException e) {
+                e.printStackTrace();
+            }
+        });
+        outputter.flush();
+        outputter.close();
+        // ----------------------------
 
 
     }
index 968f5de..e8fc4f5 100644 (file)
@@ -46,9 +46,12 @@ public class PcapHandleReader {
             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");
+                    /*
                     // Fail early if assumption doesn't hold.
                     mHandle.close();
                     throw new AssertionError("Packets not in ascending temporal order");
+                    */
                 }
                 if (mPacketFilter.shouldIncludePacket(packet)) {
                     // Packet accepted for inclusion; deliver it to observing client code.
index b17fa5e..86cce07 100644 (file)
@@ -54,6 +54,11 @@ public class TriggerTrafficExtractor implements PcapPacketFilter {
 
     @Override
     public boolean shouldIncludePacket(PcapPacket packet) {
+        if (mTriggerIndex >= mTriggerTimes.size()) {
+            // Don't include packet if we've exhausted the list of trigger times.
+            return false;
+        }
+
         // TODO hmm, is this correct?
         Instant trigger = mTriggerTimes.get(mTriggerIndex);
         if (trigger.isBefore(packet.getTimestamp()) &&