Testing the flow starting from D-Link plug for training and signature generation.
authorrtrimana <rtrimana@uci.edu>
Thu, 18 Oct 2018 20:19:38 +0000 (13:19 -0700)
committerrtrimana <rtrimana@uci.edu>
Thu, 18 Oct 2018 20:19:38 +0000 (13:19 -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 0bec8e0..f579cea 100644 (file)
@@ -57,7 +57,7 @@ public class Main {
         final String inputPcapFile = path + "/2018-10/dlink-plug/dlink-plug.wlan1.local.pcap";
         final String outputPcapFile = path + "/2018-10/dlink-plug/dlink-plug-processed.pcap";
         final String triggerTimesFile = path + "/2018-10/dlink-plug/dlink-plug-oct-17-2018.timestamps";
-        final String deviceIp = "192.168.1.246"; // .246 == phone; .199 == dlink plug?
+        final String deviceIp = "192.168.1.199"; // .246 == phone; .199 == dlink plug?
 
         // 2) TP-Link July 25 experiment
 //        final String inputPcapFile = path + "/2018-07/tplink/tplink.wlan1.local.pcap";
@@ -189,7 +189,6 @@ public class Main {
 //        final String triggerTimesFile = path + "/2018-08/noise/kwikset-doorlock-noise-sept-27-2018.timestamps";
 //        final String deviceIp = "192.168.1.142"; //  .142 == SmartThings Hub;
 
-
         TriggerTimesFileReader ttfr = new TriggerTimesFileReader();
         List<Instant> triggerTimes = ttfr.readTriggerTimes(triggerTimesFile, false);
         // Tag each trigger with "ON" or "OFF", assuming that the first trigger is an "ON" and that they alternate.
@@ -323,7 +322,8 @@ public class Main {
         // TODO: Merging test
         PcapPacketUtils.mergeSignatures(ppListOfListListOn, sortedAllConversation);
         PcapPacketUtils.sortSignatures(ppListOfListListOn);
-        count = 0;
+        PcapPacketUtils.printSignatures(ppListOfListListOn);
+        //count = 0;
         /*for (List<List<PcapPacket>> ll : ppListOfListListOn) {
             PrintUtils.serializeClustersIntoFile("./onSignature" + ++count + ".sig", ll);
             ppListOfListReadOn.add(PrintUtils.deserializeClustersFromFile("./onSignature" + count + ".sig"));
@@ -349,7 +349,8 @@ public class Main {
         // TODO: Merging test
         PcapPacketUtils.mergeSignatures(ppListOfListListOff, sortedAllConversation);
         PcapPacketUtils.sortSignatures(ppListOfListListOff);
-        count = 0;
+        PcapPacketUtils.printSignatures(ppListOfListListOff);
+        //count = 0;
         /*for (List<List<PcapPacket>> ll : ppListOfListListOff) {
             PrintUtils.serializeClustersIntoFile("./offSignature" + ++count + ".sig", ll);
             ppListOfListReadOff.add(PrintUtils.deserializeClustersFromFile("./offSignature" + count + ".sig"));
index 5dec8ea..64ed6ef 100644 (file)
@@ -43,10 +43,10 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
 //        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";
-        // 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";
+//        final String inputPcapFile = path + "/evaluation/kwikset-doorlock/kwikset-doorlock.data.wlan1.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";
@@ -60,6 +60,17 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
         */
 
         // TODO: The following are tests for signatures against training data
+
+        // 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";
+        // D-Link Plug PHONE signatures
+        //final String onSignatureFile = path + "/2018-07/dlink/onSignature-DLink-Plug-phone.sig";
+        //final String offSignatureFile = path + "/2018-07/dlink/offSignature-DLink-Plug-phone.sig";
+
+
         /*
         // Kwikset Doorlock Sep 12 experiment
         final String inputPcapFile = path + "/2018-08/kwikset-doorlock/kwikset3.wlan1.local.pcap";
@@ -68,17 +79,6 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
         final String offSignatureFile = path + "/2018-08/kwikset-doorlock/offSignature-Kwikset-Doorlock-phone.sig";
         */
 
-        /*
-        // D-Link Plug experiment
-        final String inputPcapFile = path + "/2018-07/dlink/dlink.wlan1.local.pcap";
-        // D-Link Plug DEVICE signatures
-        final String onSignatureFile = path + "/2018-07/dlink/onSignature-DLink-Plug-device.sig";
-        final String offSignatureFile = path + "/2018-07/dlink/offSignature-DLink-Plug-device.sig";
-        // D-Link Plug PHONE signatures
-        final String onSignatureFile = path + "/2018-07/dlink/onSignature-DLink-Plug-phone.sig";
-        final String offSignatureFile = path + "/2018-07/dlink/offSignature-DLink-Plug-phone.sig";
-        */
-
         /*
         // D-Link Siren experiment
         final String inputPcapFile = path + "/2018-08/dlink-siren/dlink-siren.wlan1.local.pcap";
index 715f2e2..ccd3d9a 100644 (file)
@@ -324,4 +324,34 @@ public final class PcapPacketUtils {
     private static IpV4Packet getIpV4PacketOrThrow(PcapPacket packet) {
         return Objects.requireNonNull(packet.get(IpV4Packet.class), "not an IPv4 packet");
     }
+
+    /**
+     * Print signatures in {@code List} of {@code List} of {@code List} of {@code PcapPacket} objects.
+     *
+     * @param signatures A {@link List} of {@link List} of {@link List} of
+     *          {@link PcapPacket} objects that needs to be printed.
+     */
+    public static void printSignatures(List<List<List<PcapPacket>>> signatures) {
+
+        // Iterate over the list of all clusters/sequences
+        int sequenceCounter = 0;
+        for(List<List<PcapPacket>> listListPcapPacket : signatures) {
+            // Iterate over every member of a cluster/sequence
+            System.out.print("====== SEQUENCE " + sequenceCounter++);
+            System.out.println(" - " + listListPcapPacket.size() + " MEMBERS ======");
+            for(List<PcapPacket> listPcapPacket : listListPcapPacket) {
+                // Print out packet lengths in a sequence
+                int packetCounter = 0;
+                for(PcapPacket pcapPacket : listPcapPacket) {
+                    System.out.print(pcapPacket.length());
+                    if(packetCounter < listPcapPacket.size() - 1) {
+                        System.out.print(" ");  // Provide space if not last packet
+                    } else {
+                        System.out.println();      // Newline if last packet
+                    }
+                    packetCounter++;
+                }
+            }
+        }
+    }
 }