import edu.uci.iotproject.trafficreassembly.layer2.Layer2FlowObserver;
import org.pcap4j.core.*;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import java.util.*;
import java.util.function.Function;
/**
private String mTrainingRouterWlanMac;
private String mRouterWlanMac;
+ /**
+ * Relaxed matching
+ */
+ private int mDelta;
+ private Set<Integer> mPacketSet;
+
/**
* Create a new {@link Layer2ClusterMatcher} that attempts to find occurrences of {@code cluster}'s members.
* @param cluster The sequence mutations that the new {@link Layer2ClusterMatcher} should search for.
*/
public Layer2ClusterMatcher(List<List<PcapPacket>> cluster, String trainingRouterWlanMac, String routerWlanMac, int inclusionTimeMillis,
- boolean isRangeBased, double eps, int limitSkippedPackets) {
+ boolean isRangeBased, double eps, int limitSkippedPackets, int delta, Set<Integer> packetSet) {
// Consider all flows if no flow filter specified.
this(cluster, trainingRouterWlanMac, routerWlanMac, flow -> true, inclusionTimeMillis, isRangeBased, eps,
- limitSkippedPackets);
+ limitSkippedPackets, delta, packetSet);
}
/**
*/
public Layer2ClusterMatcher(List<List<PcapPacket>> cluster, String trainingRouterWlanMac, String routerWlanMac,
Function<Layer2Flow, Boolean> flowFilter, int inclusionTimeMillis, boolean isRangeBased,
- double eps, int limitSkippedPackets) {
+ double eps, int limitSkippedPackets, int delta, Set<Integer> packetSet) {
super(cluster, isRangeBased);
mFlowFilter = flowFilter;
mTrainingRouterWlanMac = trainingRouterWlanMac;
mSkippedPackets = new ArrayList<>();
// Give integer's MAX_VALUE if -1
mLimitSkippedPackets = limitSkippedPackets == -1 ? Integer.MAX_VALUE : limitSkippedPackets;
+ mDelta = delta;
+ mPacketSet = packetSet;
}
@Override
}
}
+ // TODO: Relaxed matching is applied in conservative matching
private void conservativeMatching(Layer2Flow flow, PcapPacket newPacket) {
if (mPerFlowSeqMatchers.get(flow) == null) {
// If this is the first time we encounter this flow, we need to set up sequence matchers for it.
// Prepare a "state 0" sequence matcher for each sequence variation in the cluster.
for (int i = 0; i < matchers.length; i++) {
matchers[i][0] = new Layer2SequenceMatcher(mCluster.get(i), mInclusionTimeMillis, mTrainingRouterWlanMac,
- mRouterWlanMac);
+ mRouterWlanMac, mDelta, mPacketSet);
}
// Associate the new sequence matcher table with the new flow
mPerFlowSeqMatchers.put(flow, matchers);
// from state zero completed its matching or if it replaced a different one in state 1 or not.
if (sm.getMatchedPacketsCount() == 1) {
matchers[i][j] = new Layer2SequenceMatcher(sm.getTargetSequence(), mInclusionTimeMillis,
- mTrainingRouterWlanMac, mRouterWlanMac);
+ mTrainingRouterWlanMac, mRouterWlanMac, mDelta, mPacketSet);
}
}
}