Adding EPS value back into the range.
[pingpong.git] / Code / Projects / PacketLevelSignatureExtractor / src / main / java / edu / uci / iotproject / detection / layer2 / Layer2RangeMatcher.java
index cc1a3d1c13956941a08d39fc125fdd731ac8e092..eb3b34e8e5c90661afcf5fb973f8ed3b2df75892 100644 (file)
@@ -23,6 +23,7 @@ public class Layer2RangeMatcher extends Layer2AbstractMatcher {
     private final List<PcapPacket> mLowerBound;
     private final List<PcapPacket> mUpperBound;
     private final double mEps;
+    private int mInclusionTimeMillis;
 
     /**
      * Create a {@code Layer2RangeMatcher}.
@@ -30,13 +31,16 @@ public class Layer2RangeMatcher extends Layer2AbstractMatcher {
      * @param upperBound The upper bound of the sequence to match against (search for).
      * @param eps The epsilon value used in the DBSCAN algorithm.
      */
-    public Layer2RangeMatcher(List<PcapPacket> lowerBound, List<PcapPacket> upperBound, double eps) {
+    public Layer2RangeMatcher(List<PcapPacket> lowerBound, List<PcapPacket> upperBound,
+                              int inclusionTimeMillis, double eps) {
         // TODO: Just use the lower bound since both lower and upper bounds' packets essentially have the same direction
         // TODO: for the same position in the array. Both arrays also have the same length.
         super(lowerBound);
         mLowerBound = lowerBound;
         mUpperBound = upperBound;
         mEps = eps;
+        mInclusionTimeMillis =
+                inclusionTimeMillis == 0 ? TriggerTrafficExtractor.INCLUSION_WINDOW_MILLIS : inclusionTimeMillis;
     }
 
     /**
@@ -70,6 +74,9 @@ public class Layer2RangeMatcher extends Layer2AbstractMatcher {
         // First verify if the received packet has the length we're looking for (the length should be within the range).
         if (expectedLowerBound.getOriginalLength() - (int) mEps <= packet.getOriginalLength() &&
                 packet.getOriginalLength() <= expectedUpperBound.getOriginalLength() + (int) mEps){
+        // TODO: TEMPORARILY WITHOUT EPS
+//        if (expectedLowerBound.getOriginalLength() <= packet.getOriginalLength() &&
+//                packet.getOriginalLength() <= expectedUpperBound.getOriginalLength()){
             // If this is the first packet, we only need to verify that its length is correct. Time constraints are
             // obviously satisfied as there are no previous packets. Furthermore, direction matches by definition as we
             // don't know the MAC of the device (or phone) in advance, so we can't enforce a rule saying "first packet
@@ -92,8 +99,10 @@ public class Layer2RangeMatcher extends Layer2AbstractMatcher {
             if (!packet.getTimestamp().isAfter(mMatchedPackets.get(getMatchedPacketsCount()-1).getTimestamp())) {
                 return false;
             }
+//            if (packet.getTimestamp().isAfter(mMatchedPackets.get(0).getTimestamp().
+//                    plusMillis(TriggerTrafficExtractor.INCLUSION_WINDOW_MILLIS))) {
             if (packet.getTimestamp().isAfter(mMatchedPackets.get(0).getTimestamp().
-                    plusMillis(TriggerTrafficExtractor.INCLUSION_WINDOW_MILLIS))) {
+                    plusMillis(mInclusionTimeMillis))) {
                 return false;
             }
             // If we made it here, it means that this packet has the expected length, direction, and obeys the timing
@@ -101,9 +110,6 @@ public class Layer2RangeMatcher extends Layer2AbstractMatcher {
             mMatchedPackets.add(packet);
             if (mMatchedPackets.size() == mLowerBound.size()) {
                 // TODO report (to observers?) that we are done?
-                if (mMatchedPackets.size() == 4) {
-                    System.out.println();
-                }
             }
             return true;
         }