1 package edu.uci.iotproject;
3 import edu.uci.iotproject.comparison.seqalignment.AlignmentPricer;
4 import edu.uci.iotproject.comparison.seqalignment.SequenceAlignment;
5 import org.pcap4j.core.PcapPacket;
11 * TODO add class documentation.
13 * @author Janus Varmarken
15 public class SequenceExtraction {
18 private final SequenceAlignment<Integer> mAlignmentAlg;
21 public SequenceExtraction() {
22 mAlignmentAlg = new SequenceAlignment<>(new AlignmentPricer<>((i1,i2) -> Math.abs(i1-i2), i -> 10));
26 public SequenceExtraction(SequenceAlignment<Integer> alignmentAlgorithm) {
27 mAlignmentAlg = alignmentAlgorithm;
33 // * @param convsForAction A set of {@link Conversation}s known to be associated with a single type of user action.
35 // public void extract(List<Conversation> convsForAction) {
36 // int maxDifference = 0;
38 // for (int i = 0; i < convsForAction.size(); i++) {
39 // for (int j = i+1; j < convsForAction.size(); i++) {
40 // Integer[] sequence1 = getPacketLengthSequence(convsForAction.get(i));
41 // Integer[] sequence2 = getPacketLengthSequence(convsForAction.get(j));
42 // int alignmentCost = mAlignmentAlg.calculateAlignment(sequence1, sequence2);
43 // if (alignmentCost > maxDifference) {
44 // maxDifference = alignmentCost;
52 // public void extract(Map<String, List<Conversation>> hostnameToConvs) {
53 // int maxDifference = 0;
55 // for (int i = 0; i < convsForAction.size(); i++) {
56 // for (int j = i+1; j < convsForAction.size(); i++) {
57 // Integer[] sequence1 = getPacketLengthSequence(convsForAction.get(i));
58 // Integer[] sequence2 = getPacketLengthSequence(convsForAction.get(j));
59 // int alignmentCost = mAlignmentAlg.calculateAlignment(sequence1, sequence2);
60 // if (alignmentCost > maxDifference) {
61 // maxDifference = alignmentCost;
68 private Integer[] getPacketLengthSequence(Conversation c) {
69 List<PcapPacket> packets = c.getPackets();
70 Integer[] packetLengthSequence = new Integer[packets.size()];
71 for (int i = 0; i < packetLengthSequence.length; i++) {
72 packetLengthSequence[i] = packets.get(i).length();
74 return packetLengthSequence;