Adding notes in the source code and scripts.
[pingpong.git] / Code / Projects / PacketLevelSignatureExtractor / src / main / java / edu / uci / iotproject / SignatureGenerator.java
index 57e0a0e9ca2d4c5a07f6c49519d114837ddf16a2..786c65f3d4104cd9098af5670dacbf83aab853ac 100644 (file)
@@ -29,9 +29,25 @@ import java.util.stream.Stream;
  * lengths with training data to determine certain events
  * or actions for smart home devices.
  *
+ * Notes:
+ * This first version of software is created based on binary events (i.e., ON/OFF).
+ * We first tested it with the TP-Link plug. The events ON and OFF were generated alternately for 100 times using
+ * the automation scripts (see the automation folder). Thus, this program tries to extract signatures by
+ * assuming that:
+ *
+ * (1) there are 2 types of events (binary), and
+ * (2) the two types are triggered alternately.
+ *
+ * Hence, for non-binary events, we still can trigger the same event for 100 times and PingPong still groups them
+ * in 2 groups of 50 occurrences each. Please keep in mind that the 2 groups are simply named "ON" and "OFF"
+ * in this program although we tested PingPong against other types of events. For non-binary events (e.g., Intensity)
+ * we still trigger the phone app alternately between two values---to have a comprehensive understanding, we alternately
+ * triggered the intensity values of 1% and 100%. We suspect that the variation in lengths are due to the different
+ * lengths of the string "1%" to "100%".
+ *
  * @author Janus Varmarken
  * @author Rahmadi Trimananda (rtrimana@uci.edu)
- * @version 0.1
+ * @version 1.0
  */
 public class SignatureGenerator {
 
@@ -47,6 +63,10 @@ public class SignatureGenerator {
      * Directory for logging.
      */
     private static String LOG_DIRECTORY = "./";
+    /**
+     * Multiplier for cluster bounds.
+     */
+    private static float CLUSTER_BOUNDS_MULTIPLIER = 0.1f;
 
     public static void main(String[] args) throws PcapNativeException, NotOpenException, EOFException,
             TimeoutException, UnknownHostException, IOException {
@@ -214,10 +234,8 @@ public class SignatureGenerator {
         // Perform clustering on conversation logged as part of all ON events.
         // Calculate number of events per type (only ON/only OFF), which means half of the number of all timestamps.
         int numberOfEventsPerType = triggerTimes.size() / 2;
-        int lowerBound = numberOfEventsPerType - (int)(numberOfEventsPerType * 0.1);
-        int upperBound = numberOfEventsPerType + (int)(numberOfEventsPerType * 0.1);
-        //int lowerBound = numberOfEventsPerType - (int)(numberOfEventsPerType * 0.5);
-        //int upperBound = numberOfEventsPerType + (int)(numberOfEventsPerType * 0.5);
+        int lowerBound = numberOfEventsPerType - (int)(numberOfEventsPerType * CLUSTER_BOUNDS_MULTIPLIER);
+        int upperBound = numberOfEventsPerType + (int)(numberOfEventsPerType * CLUSTER_BOUNDS_MULTIPLIER);
         int minPts = lowerBound;
         DBSCANClusterer<PcapPacketPair> onClusterer = new DBSCANClusterer<>(eps, minPts);
         List<Cluster<PcapPacketPair>> onClusters = onClusterer.cluster(onPairs);