Making sure that merging would fail if there is a situation where two sequences are...
authorrtrimana <rtrimana@uci.edu>
Wed, 31 Oct 2018 23:28:21 +0000 (16:28 -0700)
committerrtrimana <rtrimana@uci.edu>
Wed, 31 Oct 2018 23:28:21 +0000 (16:28 -0700)
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.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

index e878339c42508001c3ebc96ed4f049f5078ca0e0..4d0ead286701c9ac70b2bd7202789361dc9534fd 100644 (file)
@@ -83,6 +83,11 @@ public class Main {
 //        final String outputPcapFile = path + "/2018-07/stplug/stplug-processed.pcap";
 //        final String triggerTimesFile = path + "/2018-07/stplug/smartthings-july-25-2018.timestamps";
 //        final String deviceIp = "192.168.1.246"; // .246 == phone; .142 == SmartThings Hub (note: use eth0 capture for this!)
+        // October 18
+        final String inputPcapFile = path + "/2018-10/st-plug/st-plug.wlan1.local.pcap";
+        final String outputPcapFile = path + "/2018-10/st-plug/st-plug-processed.pcap";
+        final String triggerTimesFile = path + "/2018-10/st-plug/st-plug-oct-18-2018.timestamps";
+        final String deviceIp = "192.168.1.246"; // .246 == phone; .142 == SmartThings Hub (note: use eth0 capture for this!)
 
         // 4) Wemo July 30 experiment
 //        final String inputPcapFile = path + "/2018-07/wemo/wemo.wlan1.local.pcap";
@@ -122,6 +127,11 @@ public class Main {
 //        final String outputPcapFile = path + "/2018-08/hue-bulb/hue-bulb-processed.pcap";
 //        final String triggerTimesFile = path + "/2018-08/hue-bulb/hue-bulb-aug-7-2018.timestamps";
 //        final String deviceIp = "192.168.1.246";
+        // October 30 experiment
+//        final String inputPcapFile = path + "/2018-10/hue-bulb/hue-bulb.eth1.local.pcap";
+//        final String outputPcapFile = path + "/2018-10/hue-bulb/hue-bulb-processed.pcap";
+//        final String triggerTimesFile = path + "/2018-10/hue-bulb/hue-bulb-oct-30-2018.timestamps";
+//        final String deviceIp = "192.168.1.100"; // .246 == phone; .100 == Hue hub
 
         // 9) Lifx Bulb August 8 experiment
 //        final String inputPcapFile = path + "/2018-08/lifx-bulb/lifx-bulb.wlan1.local.pcap";
@@ -136,16 +146,16 @@ public class Main {
 //        final String deviceIp = "192.168.1.246"; // .246 == phone; .235 == camera
 
         // 11) Arlo Camera August 10 experiment
-        final String inputPcapFile = path + "/2018-08/arlo-camera/arlo-camera.wlan1.local.pcap";
-        final String outputPcapFile = path + "/2018-08/arlo-camera/arlo-camera-processed.pcap";
-        final String triggerTimesFile = path + "/2018-08/arlo-camera/arlo-camera-aug-10-2018.timestamps";
-        final String deviceIp = "192.168.1.246"; // .246 == phone; .140 == camera
+//        final String inputPcapFile = path + "/2018-08/arlo-camera/arlo-camera.wlan1.local.pcap";
+//        final String outputPcapFile = path + "/2018-08/arlo-camera/arlo-camera-processed.pcap";
+//        final String triggerTimesFile = path + "/2018-08/arlo-camera/arlo-camera-aug-10-2018.timestamps";
+//        final String deviceIp = "192.168.1.246"; // .246 == phone; .140 == camera
 
         // 12) Blossom sprinkler August 13 experiment
 //        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.246"; // .246 == phone; .229 == sprinkler
+//        final String deviceIp = "192.168.1.229"; // .246 == phone; .229 == sprinkler
 
 //        // 13) DLink siren August 14 experiment
 //        final String inputPcapFile = path + "/2018-08/dlink-siren/dlink-siren.wlan1.local.pcap";
@@ -320,8 +330,8 @@ public class Main {
             }
         }
         // TODO: Merging test
-        PcapPacketUtils.mergeSignatures(ppListOfListListOn, sortedAllConversation);
-        PcapPacketUtils.sortSignatures(ppListOfListListOn);
+        ppListOfListListOn = PcapPacketUtils.mergeSignatures(ppListOfListListOn, sortedAllConversation);
+        ppListOfListListOn = PcapPacketUtils.sortSignatures(ppListOfListListOn);
         PcapPacketUtils.printSignatures(ppListOfListListOn);
         //count = 0;
         /*for (List<List<PcapPacket>> ll : ppListOfListListOn) {
@@ -347,8 +357,8 @@ public class Main {
             }
         }
         // TODO: Merging test
-        PcapPacketUtils.mergeSignatures(ppListOfListListOff, sortedAllConversation);
-        PcapPacketUtils.sortSignatures(ppListOfListListOff);
+        ppListOfListListOff = PcapPacketUtils.mergeSignatures(ppListOfListListOff, sortedAllConversation);
+        ppListOfListListOff = PcapPacketUtils.sortSignatures(ppListOfListListOff);
         PcapPacketUtils.printSignatures(ppListOfListListOff);
         //count = 0;
         /*for (List<List<PcapPacket>> ll : ppListOfListListOff) {
index 38ae8fa88f657fadab9446b7a45d423ca5384177..f67a8326d87b12c8be16b3566ba8b41efbdc6144 100644 (file)
@@ -83,11 +83,17 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
         //final String offSignatureFile = path + "/training/tplink-plug/signatures/tplink-plug-offSignature-device-side.sig";
         */
 
-        // TP-Link Plug experiment
-        final String inputPcapFile = path + "/training/arlo-camera/wlan1/arlo-camera.wlan1.local.pcap";
+        // Arlo camera experiment
+//        final String inputPcapFile = path + "/training/arlo-camera/wlan1/arlo-camera.wlan1.local.pcap";
+//        // TP-Link Plug DEVICE signatures
+//        final String onSignatureFile = path + "/training/arlo-camera/signatures/arlo-camera-onSignature-phone-side.sig";
+//        final String offSignatureFile = path + "/training/arlo-camera/signatures/arlo-camera-offSignature-phone-side.sig";
+
+        // Amazon Alexa experiment
+        final String inputPcapFile = path + "/training/amazon-alexa/wlan1/alexa2.wlan1.local.pcap";
         // TP-Link Plug DEVICE signatures
-        final String onSignatureFile = path + "/training/arlo-camera/signatures/arlo-camera-onSignature-phone-side.sig";
-        final String offSignatureFile = path + "/training/arlo-camera/signatures/arlo-camera-offSignature-phone-side.sig";
+        final String onSignatureFile = path + "/training/amazon-alexa/signatures/amazon-alexa-onSignature-device-side.sig";
+        final String offSignatureFile = path + "/training/amazon-alexa/signatures/amazon-alexa-offSignature-device-side.sig";
 
         // SmartThings Plug experiment
 //        final String inputPcapFile = path + "/training/st-plug/wlan1/st-plug.wlan1.local.pcap";
index 9e512510c3237ac4e5f31f3c83a4f13e87202e31..c5de954536d961dc52aa9ebb602ec5890be046bb 100644 (file)
@@ -24,7 +24,7 @@ public final class PcapPacketUtils {
      * If after a merging the number of members of a signature falls below this threshold, then we can boldly
      * get rid of that signature.
      */
-    private static final int SIGNATURE_MERGE_THRESHOLD = 15;
+    private static final int SIGNATURE_MERGE_THRESHOLD = 5;
 
     /**
      * Determines if a given {@link PcapPacket} wraps a {@link TcpPacket}.
@@ -199,8 +199,12 @@ public final class PcapPacketUtils {
      */
     public static List<List<List<PcapPacket>>>
             mergeSignatures(List<List<List<PcapPacket>>> signatures, List<Conversation> conversations) {
-        // Make a copy first.
-        List<List<List<PcapPacket>>> copySignatures = new ArrayList<>(signatures);
+
+        // TODO: THIS IS NOT A DEEP COPY; IT BASICALLY CREATES A REFERENCE TO THE SAME LIST OBJECT
+        // List<List<List<PcapPacket>>> copySignatures = new ArrayList<>(signatures);
+        // Make a deep copy first.
+        List<List<List<PcapPacket>>> copySignatures = new ArrayList<>();
+        listDeepCopy(copySignatures, signatures);
         // Traverse and look into the pairs of signatures.
         for (int first = 0; first < signatures.size(); first++) {
             List<List<PcapPacket>> firstList = signatures.get(first);
@@ -244,7 +248,7 @@ public final class PcapPacketUtils {
                     // TODO: DOUBLE CHECK IF WE REALLY NEED TO PRUNE FAILED BINDINGS
                     // TODO: SOMETIMES THE SEQUENCES ARE JUST INCOMPLETE
                     // TODO: AND BOTH THE COMPLETE AND INCOMPLETE SEQUENCES ARE VALID SIGNATURES!
-                    // firstList.removeIf(el -> el.size() < maxNumOfEl);
+                    firstList.removeIf(el -> el.size() < maxNumOfEl);
                     // Remove the merged set of signatures when successful.
                     signatures.remove(secondList);
                 } else if (secondList.size() < initialSecondListMembers) {
@@ -257,6 +261,28 @@ public final class PcapPacketUtils {
         return signatures;
     }
 
+    /**
+     * Deep copy to create an entirely new {@link List} of {@link List} of {@link List} of {@link PcapPacket} objects.
+     * @param destList A {@link List} of {@link List} of {@link List} of
+     *          {@link PcapPacket} objects that will be the final container of the deep copy
+     * @param sourceList A {@link List} of {@link List} of {@link List} of
+     *          {@link PcapPacket} objects that will be the source of the deep copy.
+     */
+    private static void listDeepCopy(List<List<List<PcapPacket>>> destList, List<List<List<PcapPacket>>> sourceList) {
+
+        for(List<List<PcapPacket>> llPcapPacket : sourceList) {
+            List<List<PcapPacket>> tmpListOfList = new ArrayList<>();
+            for(List<PcapPacket> lPcapPacket : llPcapPacket) {
+                List<PcapPacket> tmpList = new ArrayList<>();
+                for(PcapPacket pcapPacket : lPcapPacket) {
+                    tmpList.add(pcapPacket);
+                }
+                tmpListOfList.add(tmpList);
+            }
+            destList.add(tmpListOfList);
+        }
+    }
+
     /**
      * Sort the signatures in the {@code List} of {@code List} of {@code List} of {@code PcapPacket} objects.
      * The purpose of this is to sort the order of signatures in the signature list. For detection purposes, we need