Implementing relaxed matching for layer 2 and layer 3.
[pingpong.git] / Code / Projects / PacketLevelSignatureExtractor / src / main / java / edu / uci / iotproject / SignatureGenerator.java
index 50417e71bf3d222f75156dea895a3e454a1a5a2d..ea3e39b41b49e24e00847d2c41481b5fc5d69917 100644 (file)
@@ -47,6 +47,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,8 +218,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 * 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);
@@ -282,7 +286,7 @@ public class SignatureGenerator {
             }
             PcapPacketUtils.removeSequenceFromSignature(ppListOfListListOn, sequenceToDelete);
         }
-        PrintWriterUtils.println("ON Sequences after removal: ", resultsWriter,
+        PrintWriterUtils.println("ON Sequences: ", resultsWriter,
                 DUPLICATE_OUTPUT_TO_STD_OUT);
         for(List<List<PcapPacket>> listOfList : ppListOfListListOn) {
             PrintWriterUtils.println(listOfList.get(0).get(0).length() + "...", resultsWriter,
@@ -303,7 +307,7 @@ public class SignatureGenerator {
             }
             PcapPacketUtils.removeSequenceFromSignature(ppListOfListListOff, sequenceToDelete);
         }
-        PrintWriterUtils.println("OFF Sequences after removal: ", resultsWriter,
+        PrintWriterUtils.println("OFF Sequences: ", resultsWriter,
                 DUPLICATE_OUTPUT_TO_STD_OUT);
         for(List<List<PcapPacket>> listOfList : ppListOfListListOff) {
             PrintWriterUtils.println(listOfList.get(0).get(0).length() + "...", resultsWriter,
@@ -328,6 +332,9 @@ public class SignatureGenerator {
         PrintWriterUtils.println("========================================", resultsWriter,
                 DUPLICATE_OUTPUT_TO_STD_OUT);
         PcapPacketUtils.printSignatures(ppListOfListListOff, resultsWriter, DUPLICATE_OUTPUT_TO_STD_OUT);
+        // Clean signatures from null elements
+        PcapPacketUtils.cleanSignature(ppListOfListListOn);
+        PcapPacketUtils.cleanSignature(ppListOfListListOff);
         // Printing signatures into files
         PrintUtils.serializeIntoFile(onSignatureFile, ppListOfListListOn);
         PrintUtils.serializeIntoFile(offSignatureFile, ppListOfListListOff);