From: rtrimana Date: Wed, 31 Oct 2018 23:28:21 +0000 (-0700) Subject: Making sure that merging would fail if there is a situation where two sequences are... X-Git-Url: http://plrg.eecs.uci.edu/git/?p=pingpong.git;a=commitdiff_plain;h=ea9e942e81891808d27fdd01ab2557405eb2a028 Making sure that merging would fail if there is a situation where two sequences are sometimes adjacent and sometimes aren't. The detection part will detect these, instead, as separate ordered sequences (that are in one TCP connection). --- 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 e878339..4d0ead2 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 @@ -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> 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> ll : ppListOfListListOff) { diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/SignatureDetector.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/SignatureDetector.java index 38ae8fa..f67a832 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/SignatureDetector.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/detection/SignatureDetector.java @@ -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"; diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/util/PcapPacketUtils.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/util/PcapPacketUtils.java index 9e51251..c5de954 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/util/PcapPacketUtils.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/util/PcapPacketUtils.java @@ -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>> mergeSignatures(List>> signatures, List conversations) { - // Make a copy first. - List>> copySignatures = new ArrayList<>(signatures); + + // TODO: THIS IS NOT A DEEP COPY; IT BASICALLY CREATES A REFERENCE TO THE SAME LIST OBJECT + // List>> copySignatures = new ArrayList<>(signatures); + // Make a deep copy first. + List>> copySignatures = new ArrayList<>(); + listDeepCopy(copySignatures, signatures); // Traverse and look into the pairs of signatures. for (int first = 0; first < signatures.size(); first++) { List> 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>> destList, List>> sourceList) { + + for(List> llPcapPacket : sourceList) { + List> tmpListOfList = new ArrayList<>(); + for(List lPcapPacket : llPcapPacket) { + List 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