1 package edu.uci.iotproject.analysis;
3 import edu.uci.iotproject.PcapPacketConsumer;
4 import edu.uci.iotproject.PcapReader;
5 import org.pcap4j.core.PcapPacket;
7 import java.util.ArrayList;
11 * TODO add class documentation.
13 * @author Janus Varmarken {@literal <jvarmark@uci.edu>}
14 * @author Rahmadi Trimananda {@literal <rtrimana@uci.edu>}
16 public class PcapProcessingPipeline {
18 private final PcapReader mPcapReader;
19 private final List<PcapPacketConsumer> mPacketConsumers;
20 private final PcapPacketFilter mPacketFilter;
22 public PcapProcessingPipeline(PcapReader pcapReader, PcapPacketFilter packetFilter) {
23 mPcapReader = pcapReader;
24 mPacketConsumers = new ArrayList<>();
25 mPacketFilter = packetFilter;
28 public void addPcapPacketConsumer(PcapPacketConsumer packetConsumer) {
29 mPacketConsumers.add(packetConsumer);
32 public void executePipeline() {
35 while ((packet = mPcapReader.readNextPacket()) != null) {
36 if (mPacketFilter != null && !mPacketFilter.shouldIncludePacket(packet)) {
39 for (PcapPacketConsumer consumer : mPacketConsumers) {
40 consumer.consumePacket(packet);
43 if (count % 1000 == 0) {
44 System.out.println("Processed " + count + " packets");