- boolean matched = sm.matchPacket(newPacket);
- if (matched) {
- if (sm.getMatchedPacketsCount() == sm.getTargetSequencePacketCount()) {
- // Sequence matcher has a match. Report it to observers.
- mObservers.forEach(o -> o.onMatch(this, sm.getMatchedPackets()));
- // Remove the now terminated sequence matcher.
- matcher[j] = null;
- } else {
- // Sequence matcher advanced one step, so move it to its corresponding new position iff the
- // packet that advanced it has a later timestamp than that of the last matched packet of the
- // sequence matcher at the new index, if any. In most traces, a small amount of the packets
- // appear out of order (with regards to their timestamp), which is why this check is required.
- // Obviously it would not be needed if packets where guaranteed to be processed in timestamp
- // order here.
- if (matcher[j+1] == null ||
- newPacket.getTimestamp().isAfter(matcher[j+1].getLastPacket().getTimestamp())) {
- matcher[j+1] = sm;
+ }
+ // Add the new matcher into the list
+ if (addOneArray) {
+ Layer2RangeMatcher newMatcher = new Layer2RangeMatcher(mCluster.get(0), mCluster.get(1),
+ mInclusionTimeMillis, mEps);
+ listMatchers.add(newMatcher);
+ }
+ // Present packet to the sequence matchers.
+ // Make a shallow copy of the list so that we can clean up the actual list when a matcher is terminated.
+ // Otherwise, we would get an exception for changing the list while iterating on it.
+ List<Layer2RangeMatcher> listMatchersCopy = new ArrayList<>(listMatchers);
+ for(Layer2RangeMatcher matcher : listMatchersCopy) {
+ Layer2RangeMatcher sm = matcher;
+ // Check if no packets are matched yet or if there are matched packets, the next packet to be matched
+ // has to be later than the last matched packet.
+ // In most traces, a small amount of the packets appear out of order (with regards to their timestamp),
+ // which is why this check is required.
+ // Obviously it would not be needed if packets where guaranteed to be processed in timestamp
+ // order here.
+ if (sm.getMatchedPacketsCount() == 0 ||
+ newPacket.getTimestamp().isAfter(sm.getLastPacket().getTimestamp())) {
+ boolean matched = sm.matchPacket(newPacket);
+ if (matched) {
+ if (sm.getMatchedPacketsCount() == sm.getTargetSequencePacketCount()) {
+ // Update maximum skipped packets
+ boolean stillMatch = checkMaxSkippedPackets(flow.getPackets(), sm.getMatchedPackets());
+ if (stillMatch) {
+ // Sequence matcher has a match. Report it to observers.
+ mObservers.forEach(o -> o.onMatch(this, sm.getMatchedPackets()));
+ }
+ // Terminate sequence matcher since matching is complete.
+ listMatchers.remove(matcher);