Adding a method to delete a bad sequence in a signature after we test the produced...
authorrtrimana <rtrimana@uci.edu>
Wed, 7 Nov 2018 19:03:20 +0000 (11:03 -0800)
committerrtrimana <rtrimana@uci.edu>
Wed, 7 Nov 2018 19:03:20 +0000 (11:03 -0800)
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/ClusterMatcher.java
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/SignatureDetector.java
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/util/PcapPacketUtils.java
python_ml/validate-detection.py

index 598cc99..ab3bab5 100644 (file)
@@ -144,10 +144,10 @@ public class Main {
 //        final String triggerTimesFile = path + "/2018-10/lifx-bulb/lifx-bulb-oct-18-2018.timestamps";
 //        final String deviceIp = "192.168.1.231"; // .246 == phone; .231 == Lifx
         // November 1
-        final String inputPcapFile = path + "/2018-10/lifx-bulb/lifx-bulb.wlan1.local.pcap";
-        final String outputPcapFile = path + "/2018-10/lifx-bulb/lifx-bulb-processed.pcap";
-        final String triggerTimesFile = path + "/2018-10/lifx-bulb/lifx-bulb-nov-1-2018.timestamps";
-        final String deviceIp = "192.168.1.231"; // .246 == phone; .231 == Lifx
+//        final String inputPcapFile = path + "/2018-10/lifx-bulb/lifx-bulb.wlan1.local.pcap";
+//        final String outputPcapFile = path + "/2018-10/lifx-bulb/lifx-bulb-processed.pcap";
+//        final String triggerTimesFile = path + "/2018-10/lifx-bulb/lifx-bulb-nov-1-2018.timestamps";
+//        final String deviceIp = "192.168.1.231"; // .246 == phone; .231 == Lifx
 
         // 10) Amcrest Camera August 9 experiment
 //        final String inputPcapFile = path + "/2018-08/amcrest-camera/amcrest-camera.wlan1.local.pcap";
@@ -165,6 +165,11 @@ public class Main {
 //        final String inputPcapFile = path + "/2018-08/blossom/blossom.wlan1.local.pcap";
 //        final String outputPcapFile = path + "/2018-08/blossom/blossom-processed.pcap";
 //        final String triggerTimesFile = path + "/2018-08/blossom/blossom-aug-13-2018.timestamps";
+//        final String deviceIp = "192.168.1.229"; // .246 == phone; .229 == sprinkler
+        // 2 November
+//        final String inputPcapFile = path + "/2018-10/blossom-sprinkler/blossom-sprinkler.wlan1.local.pcap";
+//        final String outputPcapFile = path + "/2018-10/blossom-sprinkler/blossom-sprinkler-processed.pcap";
+//        final String triggerTimesFile = path + "/2018-10/blossom-sprinkler/blossom-sprinkler-nov-2-2018.timestamps";
 //        final String deviceIp = "192.168.1.229"; // .246 == phone; .229 == sprinkler
 
 //        // 13) DLink siren August 14 experiment
@@ -177,10 +182,10 @@ public class Main {
 //        final String deviceIp = "192.168.1.246"; // .246 == phone; .183 == siren
 
         // 14) Nest thermostat August 15 experiment
-//        final String inputPcapFile = path + "/2018-08/nest/nest.wlan1.local.pcap";
-//        final String outputPcapFile = path + "/2018-08/nest/nest-processed.pcap";
-//        final String triggerTimesFile = path + "/2018-08/nest/nest-aug-15-2018.timestamps";
-//        final String deviceIp = "192.168.1.246"; // .246 == phone; .127 == Nest thermostat
+        final String inputPcapFile = path + "/2018-08/nest/nest.wlan1.local.pcap";
+        final String outputPcapFile = path + "/2018-08/nest/nest-processed.pcap";
+        final String triggerTimesFile = path + "/2018-08/nest/nest-aug-15-2018.timestamps";
+        final String deviceIp = "192.168.1.246"; // .246 == phone; .127 == Nest thermostat
 
         // 15) Alexa August 16 experiment
 //        final String inputPcapFile = path + "/2018-08/alexa/alexa.wlan1.local.pcap";
@@ -369,6 +374,8 @@ public class Main {
         // TODO: Merging test
         ppListOfListListOff = PcapPacketUtils.mergeSignatures(ppListOfListListOff, sortedAllConversation);
         ppListOfListListOff = PcapPacketUtils.sortSignatures(ppListOfListListOff);
+        // TODO: Need to remove sequence number 1 for Nest Thermostat since it is not a good signature!
+        PcapPacketUtils.removeSequenceFromSignature(ppListOfListListOff, 1);
         PcapPacketUtils.printSignatures(ppListOfListListOff);
         //count = 0;
         /*for (List<List<PcapPacket>> ll : ppListOfListListOff) {
@@ -386,8 +393,6 @@ public class Main {
         File fileOnEvents = new File(onPairsPath);
         PrintWriter pwOn = null;
         try {
-
-
             pwOn = new PrintWriter(fileOnEvents);
         } catch(Exception ex) {
             ex.printStackTrace();
index 2697909..279ceea 100644 (file)
@@ -134,16 +134,6 @@ public class ClusterMatcher implements PacketListener {
                 // Skip empty conversations.
                 continue;
             }
-            // TODO: DEBUG!!!
-            /*List<PcapPacket> listPP = c.getPackets();
-            if(listPP.size() > 1000) {
-                for (PcapPacket pp : listPP) {
-                    if (pp.length() == 639) {
-                        boolean test = c.isTls();
-                        System.out.println("Sequence has 639! " + test);
-                    }
-                }
-            }*/
             for (List<PcapPacket> signatureSequence : mCluster) {
                 if (isTlsSequence(signatureSequence) != c.isTls()) {
                     // We consider it a mismatch if one is a TLS application data sequence and the other is not.
index d21e6d1..6fa3549 100644 (file)
@@ -44,12 +44,14 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
 //        final String onSignatureFile = path + "/2018-08/dlink-siren/onSignature-DLink-Siren-phone.sig";
 //        final String offSignatureFile = path + "/2018-08/dlink-siren/offSignature-DLink-Siren-phone.sig";
 
+        /*
         // Kwikset Doorlock Sep 12 experiment
 //        final String inputPcapFile = path + "/evaluation/kwikset-doorlock/kwikset-doorlock.data.wlan1.pcap";
         final String inputPcapFile = path + "/evaluation/kwikset-doorlock/kwikset-doorlock.data.eth0.pcap";
 //        // Kwikset Doorlock PHONE signatures
         final String onSignatureFile = path + "/2018-08/kwikset-doorlock/onSignature-Kwikset-Doorlock-phone-new.sig";
         final String offSignatureFile = path + "/2018-08/kwikset-doorlock/offSignature-Kwikset-Doorlock-phone-new.sig";
+        */
 
         // D-Link Plug experiment
         //final String inputPcapFile = path + "/evaluation/dlink/dlink-plug.data.wlan1.pcap";
@@ -69,11 +71,11 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
         // D-Link Plug experiment
         final String inputPcapFile = path + "/training/dlink-plug/wlan1/dlink-plug.wlan1.local.pcap";
         // D-Link Plug DEVICE signatures
-        final String onSignatureFile = path + "/training/dlink-plug/signatures/dlink-plug-onSignature-device-side.sig";
-        final String offSignatureFile = path + "/training/dlink-plug/signatures/dlink-plug-offSignature-device-side.sig";
+        //final String onSignatureFile = path + "/training/dlink-plug/signatures/dlink-plug-onSignature-device-side.sig";
+        //final String offSignatureFile = path + "/training/dlink-plug/signatures/dlink-plug-offSignature-device-side.sig";
         // D-Link Plug PHONE signatures
-        //final String onSignatureFile = path + "/training/dlink-plug/signatures/dlink-plug-onSignature-phone-side.sig";
-        //final String offSignatureFile = path + "/training/dlink-plug/signatures/dlink-plug-offSignature-phone-side.sig";
+        final String onSignatureFile = path + "/training/dlink-plug/signatures/dlink-plug-onSignature-phone-side.sig";
+        final String offSignatureFile = path + "/training/dlink-plug/signatures/dlink-plug-offSignature-phone-side.sig";
         */
 
         /*
@@ -118,14 +120,13 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
 
         /*
         // Blossom Sprinkler experiment
-        final String inputPcapFile = path + "/training/blossom-sprinkler/wlan1/blossom-sprinkler.wlan1.local.pcap";
+        //final String inputPcapFile = path + "/training/blossom-sprinkler/wlan1/blossom-sprinkler.wlan1.local.pcap";
+        final String inputPcapFile = path + "/training/blossom-sprinkler/eth0/blossom-sprinkler.eth0.local.pcap";
         // Blossom Sprinkler DEVICE signatures
         final String onSignatureFile = path + "/training/blossom-sprinkler/signatures/blossom-sprinkler-onSignature-device-side.sig";
         final String offSignatureFile = path + "/training/blossom-sprinkler/signatures/blossom-sprinkler-offSignature-device-side.sig";
         */
 
-
-        /*
         // Nest Thermostat experiment
         final String inputPcapFile = path + "/training/nest-thermostat/wlan1/nest-thermostat.wlan1.local.pcap";
         // Nest Thermostat DEVICE signatures
@@ -134,7 +135,6 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
         // Nest Thermostat PHONE signatures
         final String onSignatureFile = path + "/training/nest-thermostat/signatures/nest-thermostat-onSignature-phone-side.sig";
         final String offSignatureFile = path + "/training/nest-thermostat/signatures/nest-thermostat-offSignature-phone-side.sig";
-        */
 
         /*
         // Hue Bulb experiment
@@ -168,13 +168,13 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
         final String offSignatureFile = path + "/training/wemo-insight-plug/signatures/wemo-insight-plug-offSignature-device-side.sig";
         */
 
-        /*
+
         // Kwikset Doorlock Sep 12 experiment
-        final String inputPcapFile = path + "/2018-08/kwikset-doorlock/kwikset3.wlan1.local.pcap";
-        // Kwikset Doorlock PHONE signatures
-        final String onSignatureFile = path + "/2018-08/kwikset-doorlock/onSignature-Kwikset-Doorlock-phone.sig";
-        final String offSignatureFile = path + "/2018-08/kwikset-doorlock/offSignature-Kwikset-Doorlock-phone.sig";
-        */
+//        final String inputPcapFile = path + "/2018-08/kwikset-doorlock/kwikset3.wlan1.local.pcap";
+//        // Kwikset Doorlock PHONE signatures
+//        final String onSignatureFile = path + "/2018-08/kwikset-doorlock/onSignature-Kwikset-Doorlock-phone.sig";
+//        final String offSignatureFile = path + "/2018-08/kwikset-doorlock/offSignature-Kwikset-Doorlock-phone.sig";
+
 
         /*
         // D-Link Siren experiment
@@ -191,11 +191,11 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
         List<List<List<PcapPacket>>> offSignature = PrintUtils.deserializeSignatureFromFile(offSignatureFile);
 
         // LAN
-//        SignatureDetector onDetector = new SignatureDetector(onSignature, null);
-//        SignatureDetector offDetector = new SignatureDetector(offSignature, null);
+        SignatureDetector onDetector = new SignatureDetector(onSignature, null);
+        SignatureDetector offDetector = new SignatureDetector(offSignature, null);
         // WAN
-        SignatureDetector onDetector = new SignatureDetector(onSignature, "128.195.205.105");
-        SignatureDetector offDetector = new SignatureDetector(offSignature, "128.195.205.105");
+//        SignatureDetector onDetector = new SignatureDetector(onSignature, "128.195.205.105");
+//        SignatureDetector offDetector = new SignatureDetector(offSignature, "128.195.205.105");
 
         final DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.MEDIUM).
                 withLocale(Locale.US).withZone(ZoneId.of("America/Los_Angeles"));
index c5de954..c205126 100644 (file)
@@ -363,7 +363,7 @@ public final class PcapPacketUtils {
     public static void printSignatures(List<List<List<PcapPacket>>> signatures) {
 
         // Iterate over the list of all clusters/sequences
-        int sequenceCounter = 1;
+        int sequenceCounter = 0;
         for(List<List<PcapPacket>> listListPcapPacket : signatures) {
             // Iterate over every member of a cluster/sequence
             System.out.print("====== SEQUENCE " + sequenceCounter++);
@@ -383,4 +383,18 @@ public final class PcapPacketUtils {
             }
         }
     }
+
+    /**
+     * Remove a sequence in a signature object.
+     *
+     * @param signatures A {@link List} of {@link List} of {@link List} of
+     *          {@link PcapPacket} objects.
+     * @param sequenceIndex An index for a sequence that consists of {{@link List} of {@link List} of
+     *          {@link PcapPacket} objects.
+     */
+    public static void removeSequenceFromSignature(List<List<List<PcapPacket>>> signatures, int sequenceIndex) {
+
+        // Sequence index starts from 0
+        signatures.remove(sequenceIndex);
+    }
 }
index c4335eb..8b04ead 100644 (file)
@@ -16,9 +16,9 @@ path = "/scratch/July-2018/training/"
 #fileExperiment = "blossom-sprinkler-aug-13-2018.timestamps"
 #fileDetection = "detection-on-training-device-side"
 # Nest thermostat
-#device = "nest-thermostat/self-test"
-#fileExperiment = "nest-aug-15-2018.timestamps"
-#fileDetection = "detection-on-training-phone-side"
+device = "nest-thermostat/self-test"
+fileExperiment = "nest-aug-15-2018.timestamps"
+fileDetection = "detection-on-training-phone-side"
 # Hue bulb
 #device = "hue-bulb/self-test"
 #fileExperiment = "hue-bulb-aug-7-2018.timestamps"
@@ -28,9 +28,9 @@ path = "/scratch/July-2018/training/"
 #fileExperiment = "tplink-bulb-aug-3-2018.timestamps"
 #fileDetection = "detection-on-training-phone-side"
 # WeMo Insight Plug
-device = "wemo-insight-plug/self-test"
-fileExperiment = "wemo-insight-july-31-2018.timestamps"
-fileDetection = "detection-on-training-device-side"
+#device = "wemo-insight-plug/self-test"
+#fileExperiment = "wemo-insight-july-31-2018.timestamps"
+#fileDetection = "detection-on-training-device-side"
 
 TIME_WINDOW = 15 # detection/signature window of 15 seconds
 #NEG_TIME_WINDOW = -15 # detection/signature window of 15 seconds