Adding a boolean variable to choose between the verbose or the concise version of...
[pingpong.git] / Code / Projects / SmartPlugDetector / src / main / java / edu / uci / iotproject / Main.java
index ed8c1bd27a4d61f54e0ea9200a74403311394860..1addfb313266c94a74575a9edfdf5f0e6bbb6295 100644 (file)
@@ -37,14 +37,15 @@ public class Main {
         // ------------ # Code for extracting traffic generated by a device within x seconds of a trigger # ------------
         // Paths to input and output files (consider supplying these as arguments instead) and IP of the device for
         // which traffic is to be extracted:
-//        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
+        boolean verbose = true;
 
         // 1) D-Link July 26 experiment
-        final String inputPcapFile = path + "/2018-07/dlink/dlink.wlan1.local.pcap";
-        final String outputPcapFile = path + "/2018-07/dlink/dlink-processed.pcap";
-        final String triggerTimesFile = path + "/2018-07/dlink/dlink-july-26-2018.timestamps";
-        final String deviceIp = "192.168.1.246"; // .246 == phone; .199 == dlink plug?
+//        final String inputPcapFile = path + "/2018-07/dlink/dlink.wlan1.local.pcap";
+//        final String outputPcapFile = path + "/2018-07/dlink/dlink-processed.pcap";
+//        final String triggerTimesFile = path + "/2018-07/dlink/dlink-july-26-2018.timestamps";
+//        final String deviceIp = "192.168.1.246"; // .246 == phone; .199 == dlink plug?
 
         // 2) TP-Link July 25 experiment
 //        final String inputPcapFile = path + "/2018-07/tplink/tplink.wlan1.local.pcap";
@@ -55,10 +56,10 @@ public class Main {
         // 2b) TP-Link July 25 experiment TRUNCATED:
         // Only contains "true local" events, i.e., before the behavior changes to remote-like behavior.
         // Last included event is at July 25 10:38:11; file filtered to only include packets with arrival time <= 10:38:27.
-        final String inputPcapFile = path + "/2018-07/tplink/tplink.wlan1.local.truncated.pcap";
-        final String outputPcapFile = path + "/2018-07/tplink/tplink-processed.truncated.pcap";
-        final String triggerTimesFile = path + "/2018-07/tplink/tplink-july-25-2018.truncated.timestamps";
-        final String deviceIp = "192.168.1.159";
+//        final String inputPcapFile = path + "/2018-07/tplink/tplink.wlan1.local.truncated.pcap";
+//        final String outputPcapFile = path + "/2018-07/tplink/tplink-processed.truncated.pcap";
+//        final String triggerTimesFile = path + "/2018-07/tplink/tplink-july-25-2018.truncated.timestamps";
+//        final String deviceIp = "192.168.1.159";
 
         // 3) SmartThings Plug July 25 experiment
 //        final String inputPcapFile = path + "/2018-07/stplug/stplug.wlan1.local.pcap";
@@ -67,10 +68,10 @@ public class Main {
 //        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";
-//        final String outputPcapFile = path + "/2018-07/wemo/wemo-processed.pcap";
-//        final String triggerTimesFile = path + "/2018-07/wemo/wemo-july-30-2018.timestamps";
-//        final String deviceIp = "192.168.1.145";
+        final String inputPcapFile = path + "/2018-07/wemo/wemo.wlan1.local.pcap";
+        final String outputPcapFile = path + "/2018-07/wemo/wemo-processed.pcap";
+        final String triggerTimesFile = path + "/2018-07/wemo/wemo-july-30-2018.timestamps";
+        final String deviceIp = "192.168.1.145";
 
         // 5) Wemo Insight July 31 experiment
 //        final String inputPcapFile = path + "/2018-07/wemoinsight/wemoinsight.wlan1.local.pcap";
@@ -200,20 +201,38 @@ public class Main {
         Map<String, Map<String, List<Conversation>>> ons = new HashMap<>();
         // Contains all OFF events: hostname -> sequence identifier -> list of conversations with that sequence
         Map<String, Map<String, List<Conversation>>> offs = new HashMap<>();
-        userActionsToConvsByHostname.forEach((ua, hostnameToConvs) -> {
-            Map<String, Map<String, List<Conversation>>> outer = ua.getType() == Type.TOGGLE_ON ? ons : offs;
-            hostnameToConvs.forEach((host, convs) -> {
-                Map<String, List<Conversation>> seqsToConvs = TcpConversationUtils.
-                        groupConversationsByPacketSequence(convs);
-                outer.merge(host, seqsToConvs, (oldMap, newMap) -> {
-                    newMap.forEach((sequence, cs) -> oldMap.merge(sequence, cs, (list1, list2) -> {
-                        list1.addAll(list2);
-                        return list1;
-                    }));
-                    return oldMap;
+
+        if (verbose) {
+            userActionsToConvsByHostname.forEach((ua, hostnameToConvs) -> {
+                Map<String, Map<String, List<Conversation>>> outer = ua.getType() == Type.TOGGLE_ON ? ons : offs;
+                hostnameToConvs.forEach((host, convs) -> {
+                    Map<String, List<Conversation>> seqsToConvs = TcpConversationUtils.
+                            groupConversationsByPacketSequenceVerbose(convs);
+                    outer.merge(host, seqsToConvs, (oldMap, newMap) -> {
+                        newMap.forEach((sequence, cs) -> oldMap.merge(sequence, cs, (list1, list2) -> {
+                            list1.addAll(list2);
+                            return list1;
+                        }));
+                        return oldMap;
+                    });
                 });
             });
-        });
+        } else {
+            userActionsToConvsByHostname.forEach((ua, hostnameToConvs) -> {
+                Map<String, Map<String, List<Conversation>>> outer = ua.getType() == Type.TOGGLE_ON ? ons : offs;
+                hostnameToConvs.forEach((host, convs) -> {
+                    Map<String, List<Conversation>> seqsToConvs = TcpConversationUtils.
+                            groupConversationsByPacketSequence(convs);
+                    outer.merge(host, seqsToConvs, (oldMap, newMap) -> {
+                        newMap.forEach((sequence, cs) -> oldMap.merge(sequence, cs, (list1, list2) -> {
+                            list1.addAll(list2);
+                            return list1;
+                        }));
+                        return oldMap;
+                    });
+                });
+            });
+        }
 
         // ================================================================================================
         // <<< Some work-in-progress/explorative code that extracts a "representative" sequence >>>