X-Git-Url: http://plrg.eecs.uci.edu/git/?p=pingpong.git;a=blobdiff_plain;f=Code%2FProjects%2FSmartPlugDetector%2Fsrc%2Fmain%2Fjava%2Fedu%2Fuci%2Fiotproject%2FMain.java;h=022052f6201509dc8551af0807691da782907d4a;hp=d909be89739e9df373b893a95b48d5907abdeb09;hb=ded2d1a37e4db8d7b996121a2d1d3f98ebc1ffa1;hpb=6c8b27ed9430116d35e4d1644c17785dd809e154 diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java index d909be8..022052f 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java @@ -49,10 +49,10 @@ public class Main { final String offPairsPath = "/scratch/July-2018/off.txt"; // 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.199"; // .246 == phone; .199 == dlink plug? // 2) TP-Link July 25 experiment // final String inputPcapFile = path + "/2018-07/tplink/tplink.wlan1.local.pcap"; @@ -93,10 +93,10 @@ public class Main { // final String deviceIp = "192.168.1.140"; // .246 == phone; .140 == TP-Link bulb // 7) Kwikset Doorlock August 6 experiment - final String inputPcapFile = path + "/2018-08/kwikset-doorlock/kwikset-doorlock.wlan1.local.pcap"; - final String outputPcapFile = path + "/2018-08/kwikset-doorlock/kwikset-doorlock-processed.pcap"; - final String triggerTimesFile = path + "/2018-08/kwikset-doorlock/kwikset-doorlock-aug-6-2018.timestamps"; - final String deviceIp = "192.168.1.246"; // .246 == phone; .142 == SmartThings Hub (note: use eth0 capture for this!) +// final String inputPcapFile = path + "/2018-08/kwikset-doorlock/kwikset-doorlock.wlan1.local.pcap"; +// final String outputPcapFile = path + "/2018-08/kwikset-doorlock/kwikset-doorlock-processed.pcap"; +// final String triggerTimesFile = path + "/2018-08/kwikset-doorlock/kwikset-doorlock-aug-6-2018.timestamps"; +// final String deviceIp = "192.168.1.246"; // .246 == phone; .142 == SmartThings Hub (note: use eth0 capture for this!) // September 12, 2018 - includes both wlan1 and eth1 interfaces //final String inputPcapFile = path + "/2018-08/kwikset-doorlock/kwikset3.wlan1.local.pcap"; @@ -256,6 +256,8 @@ public class Main { map(e -> e.getValue()). flatMap(List::stream). collect(Collectors.toList()); + //Collections.sort(onConversations, (c1, c2) -> c1.getPackets().) + List onPairs = onConversations.stream(). map(c -> c.isTls() ? TcpConversationUtils.extractTlsAppDataPacketPairs(c) : TcpConversationUtils.extractPacketPairs(c)). @@ -274,39 +276,55 @@ public class Main { // Perform clustering on conversation logged as part of all OFF events. DBSCANClusterer offClusterer = new DBSCANClusterer<>(10.0, 45); List> offClusters = offClusterer.cluster(offPairs); + // Sort the conversations as reference + List sortedAllConversation = TcpConversationUtils.sortConversationList(allConversations); // Output clusters System.out.println("========================================"); System.out.println(" Clustering results for ON "); System.out.println(" Number of clusters: " + onClusters.size()); int count = 0; - List> ppListOfListReadOn = null; + List>> ppListOfListReadOn = new ArrayList<>(); + List>> ppListOfListListOn = new ArrayList<>(); for (Cluster c : onClusters) { System.out.println(String.format("<<< Cluster #%02d (%03d points) >>>", ++count, c.getPoints().size())); System.out.print(PrintUtils.toSummaryString(c)); if(c.getPoints().size() > 45 && c.getPoints().size() < 55) { // Print to file List> ppListOfList = PcapPacketUtils.clusterToListOfPcapPackets(c); - PrintUtils.serializeClustersIntoFile("./onSignature" + count + ".sig", ppListOfList); - ppListOfListReadOn = - PrintUtils.serializeClustersFromFile("./onSignature" + count + ".sig"); + ppListOfListListOn.add(ppListOfList); } } + // TODO: Merging test + ppListOfListListOn = PcapPacketUtils.mergeSignatures(ppListOfListListOn, sortedAllConversation); + count = 0; + for (List> ll : ppListOfListListOn) { + PrintUtils.serializeClustersIntoFile("./onSignature" + ++count + ".sig", ll); + ppListOfListReadOn.add(PrintUtils.serializeClustersFromFile("./onSignature" + count + ".sig")); + } + System.out.println("========================================"); System.out.println(" Clustering results for OFF "); System.out.println(" Number of clusters: " + offClusters.size()); count = 0; - List> ppListOfListReadOff = null; + List>> ppListOfListReadOff = new ArrayList<>(); + List>> ppListOfListListOff = new ArrayList<>(); for (Cluster c : offClusters) { System.out.println(String.format("<<< Cluster #%03d (%06d points) >>>", ++count, c.getPoints().size())); System.out.print(PrintUtils.toSummaryString(c)); if(c.getPoints().size() > 45 && c.getPoints().size() < 55) { // Print to file List> ppListOfList = PcapPacketUtils.clusterToListOfPcapPackets(c); - PrintUtils.serializeClustersIntoFile("./offSignature" + count + ".sig", ppListOfList); - ppListOfListReadOff = - PrintUtils.serializeClustersFromFile("./offSignature" + count + ".sig"); + ppListOfListListOff.add(ppListOfList); } } + // TODO: Merging test + ppListOfListListOff = PcapPacketUtils.mergeSignatures(ppListOfListListOff, sortedAllConversation); + count = 0; + for (List> ll : ppListOfListListOff) { + PrintUtils.serializeClustersIntoFile("./offSignature" + ++count + ".sig", ll); + ppListOfListReadOff.add(PrintUtils.serializeClustersFromFile("./offSignature" + count + ".sig")); + } + System.out.println("========================================"); // ============================================================================================================