Prepare code for execution on Hera (networking group server)
authorJanus Varmarken <varmarken@gmail.com>
Tue, 27 Nov 2018 21:35:17 +0000 (13:35 -0800)
committerJanus Varmarken <varmarken@gmail.com>
Tue, 27 Nov 2018 21:35:17 +0000 (13:35 -0800)
Code/Projects/SmartPlugDetector/.idea/modules/SmartPlugDetector_main.iml
Code/Projects/SmartPlugDetector/.idea/modules/SmartPlugDetector_test.iml
Code/Projects/SmartPlugDetector/build.gradle
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/SignatureDetector.java

index 15e9a30..9353a45 100644 (file)
@@ -5,6 +5,7 @@
     <exclude-output />
     <content url="file://$MODULE_DIR$/../../src/main">
       <sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
+      <sourceFolder url="file://$MODULE_DIR$/../../src/main/resources" type="java-resource" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
index d8e4114..d10f1b0 100644 (file)
@@ -5,6 +5,7 @@
     <exclude-output />
     <content url="file://$MODULE_DIR$/../../src/test">
       <sourceFolder url="file://$MODULE_DIR$/../../src/test/java" isTestSource="true" />
+      <sourceFolder url="file://$MODULE_DIR$/../../src/test/resources" type="java-test-resource" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
index f8f539c..aed9fd1 100644 (file)
@@ -6,7 +6,9 @@ apply plugin: 'application'
 
 sourceCompatibility = 1.8
 
-mainClassName = "edu.uci.iotproject.Main"
+//mainClassName = "edu.uci.iotproject.Main"
+mainClassName = "edu.uci.iotproject.detection.SignatureDetector"
+
 
 repositories {
     mavenCentral()
index 22e4964..76294a8 100644 (file)
@@ -17,6 +17,7 @@ import java.time.format.DateTimeFormatter;
 import java.time.format.FormatStyle;
 import java.util.*;
 import java.util.function.Consumer;
+import java.util.stream.Collectors;
 
 /**
  * Detects an event signature that spans one or multiple TCP connections.
@@ -28,8 +29,9 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
 
     // Test client
     public static void main(String[] args) throws PcapNativeException, NotOpenException {
-        String path = "/scratch/July-2018"; // Rahmadi
-        //String path = "/Users/varmarken/temp/UCI IoT Project/experiments"; // Janus
+//        String path = "/scratch/July-2018"; // Rahmadi
+//        String path = "/Users/varmarken/temp/UCI IoT Project/experiments"; // Janus
+        String path = "/home/jvarmark/iot_project/datasets"; // Hera (server)
 
         // No activity test
         //final String inputPcapFile = path + "/evaluation/no-activity/no-activity.wlan1.pcap";
@@ -81,7 +83,6 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
 //                final String inputPcapFile = path + "/UNSW/16-10-10.pcap"; // TODO: Seems to be broken!
 //                final String inputPcapFile = path + "/UNSW/16-10-11.pcap"; // TODO: Seems to be broken!
 
-
 //        final String inputPcapFile = path + "/UNSW/16-09-23.pcap";
 //        final String inputPcapFile = path + "/UNSW/16-09-24.pcap";
 //        final String inputPcapFile = path + "/UNSW/16-09-25.pcap";
@@ -90,6 +91,9 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
 //        final String inputPcapFile = path + "/UNSW/16-09-29.pcap";
 //        final String inputPcapFile = path + "/UNSW/16-10-01.pcap";
 //        final String inputPcapFile = path + "/UNSW/16-10-06.pcap";
+        // Negative test: dataset from UNB
+//        final String inputPcapFile = path + "/evaluation/negative-datasets/UNB/Monday-WorkingHours_one-local-endpoint.pcap";
+        final String inputPcapFile = path + "/evaluation/negative-datasets/UNB/Monday-WorkingHours_one-local-endpoint-subsample_00009_20170703102920.pcap";
 
         // TODO: The following one is very long!!!
 //        final String inputPcapFile = path + "/UNSW/16-10-12.pcap";
@@ -129,6 +133,8 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
         // D-Link Siren PHONE signatures
 //        final String onSignatureFile = path + "/experimental_result/standalone/dlink-siren/signatures/dlink-siren-onSignature-phone-side.sig";
 //        final String offSignatureFile = path + "/experimental_result/standalone/dlink-siren/signatures/dlink-siren-offSignature-phone-side.sig";
+        final String onSignatureFile = path + "/training/signatures/dlink-siren/dlink-siren-onSignature-phone-side.sig";
+        final String offSignatureFile = path + "/training/signatures/dlink-siren/dlink-siren-offSignature-phone-side.sig";
 
         // TP-Link Plug experiment
         //final String inputPcapFile = path + "/training/tplink-plug/wlan1/tplink-plug.wlan1.local.pcap";
@@ -283,11 +289,11 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
 //        final String inputPcapFile = path + "/experimental_result/standalone/wemo-insight-plug/wlan1/wemo-insight-plug.wlan1.local.pcap";
 //        final String inputPcapFile = path + "/experimental_result/standalone/wemo-insight-plug/eth0/wemo-insight-plug.eth0.local.pcap";
         // TODO: WE HAVE 1 ADDITIONAL EVENT (FROM WEMO PLUG)
-        final String inputPcapFile = path + "/experimental_result/smarthome/wemo-insight-plug/wlan1/wemo-insight-plug.wlan1.detection.pcap";
+//        final String inputPcapFile = path + "/experimental_result/smarthome/wemo-insight-plug/wlan1/wemo-insight-plug.wlan1.detection.pcap";
 //        final String inputPcapFile = path + "/experimental_result/smarthome/wemo-insight-plug/eth0/wemo-insight-plug.eth0.detection.pcap";
         // WeMo Insight Plug PHONE signatures
-        final String onSignatureFile = path + "/experimental_result/standalone/wemo-insight-plug/signatures/wemo-insight-plug-onSignature-phone-side.sig";
-        final String offSignatureFile = path + "/experimental_result/standalone/wemo-insight-plug/signatures/wemo-insight-plug-offSignature-phone-side.sig";
+//        final String onSignatureFile = path + "/experimental_result/standalone/wemo-insight-plug/signatures/wemo-insight-plug-onSignature-phone-side.sig";
+//        final String offSignatureFile = path + "/experimental_result/standalone/wemo-insight-plug/signatures/wemo-insight-plug-offSignature-phone-side.sig";
 
 
         // Kwikset Doorlock Sep 12 experiment
@@ -306,26 +312,26 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
 
 
 
-        /*
+
         // D-Link Siren experiment
-        final String inputPcapFile = path + "/2018-08/dlink-siren/dlink-siren.wlan1.local.pcap";
+//        final String inputPcapFile = path + "/2018-08/dlink-siren/dlink-siren.wlan1.local.pcap";
         // D-Link Siren DEVICE signatures
         //final String onSignatureFile = path + "/2018-08/dlink-siren/onSignature-DLink-Siren-device.sig";
         //final String offSignatureFile = path + "/2018-08/dlink-siren/offSignature-DLink-Siren-device.sig";
         // D-Link Siren PHONE signatures
-        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";
-        */
+//        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";
+
 
         List<List<List<PcapPacket>>> onSignature = PrintUtils.deserializeSignatureFromFile(onSignatureFile);
         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"));
@@ -378,13 +384,18 @@ public class SignatureDetector implements PacketListener, ClusterMatcher.Cluster
         // times file.
         Collections.sort(detectedEvents, Comparator.comparing(UserAction::getTimestamp));
 
-
         // Output the detected events
-        //detectedEvents.forEach(outputter);
+        detectedEvents.forEach(outputter);
+
+        System.out.println("Number of detected events of type " + UserAction.Type.TOGGLE_ON + ": " +
+                detectedEvents.stream().filter(ua -> ua.getType() == UserAction.Type.TOGGLE_ON).count());
+        System.out.println("Number of detected events of type " + UserAction.Type.TOGGLE_OFF + ": " +
+                detectedEvents.stream().filter(ua -> ua.getType() == UserAction.Type.TOGGLE_OFF).count());
+
 
         // TODO: Temporary clean up until we clean the pipeline
-        List<UserAction> cleanedDetectedEvents = SignatureDetector.removeDuplicates(detectedEvents);
-        cleanedDetectedEvents.forEach(outputter);
+//        List<UserAction> cleanedDetectedEvents = SignatureDetector.removeDuplicates(detectedEvents);
+//        cleanedDetectedEvents.forEach(outputter);
     }
 
     /**