Delete PcapReader.java, PcapProcessingPipeline.java and PcapPacketConsumer.java
authorJanus Varmarken <varmarken@gmail.com>
Fri, 20 Jul 2018 21:18:13 +0000 (14:18 -0700)
committerJanus Varmarken <varmarken@gmail.com>
Fri, 20 Jul 2018 21:18:13 +0000 (14:18 -0700)
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PcapPacketConsumer.java [deleted file]
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PcapReader.java [deleted file]
Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/PcapProcessingPipeline.java [deleted file]

diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PcapPacketConsumer.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PcapPacketConsumer.java
deleted file mode 100644 (file)
index fb78eb7..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-package edu.uci.iotproject;
-
-import org.pcap4j.core.PcapPacket;
-
-/**
- * TODO add class documentation.
- *
- * @author Janus Varmarken
- */
-public interface PcapPacketConsumer {
-
-    void consumePacket(PcapPacket pcapPacket);
-
-}
diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PcapReader.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PcapReader.java
deleted file mode 100644 (file)
index bf618eb..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-package edu.uci.iotproject;
-
-import org.pcap4j.core.*;
-
-import java.io.EOFException;
-import java.util.concurrent.TimeoutException;
-/**
- * Opens and reads from a pcap file.
- * This class is nothing but a simple wrapper around some functionality in {@link Pcaps} and {@link PcapHandle} which
- * serves to simplify client code.
- * Note that the file is read in offline mode, i.e., this class does not support live processing of packets.
- *
- * @author Janus Varmarken {@literal <jvarmark@uci.edu>}
- * @author Rahmadi Trimananda {@literal <rtrimana@uci.edu>}
- */
-public class PcapReader {
-
-    private final PcapHandle mHandle;
-
-    /**
-     * Create a new {@code PcapReader} that reads the file specified by the absolute path {@code fileName}.
-     * @param fileName The absolute path to the pcap file to be read.
-     * @param berkeleyPacketFilter A Berkeley Packet Filter to be applied when reading the PCAP file to filter out
-     *                             unwanted packets immediately. May be {@code null} if no filter is to be applied.
-     * @throws PcapNativeException If an error occurs in the pcap native library.
-     * @throws NotOpenException If the pcap file cannot be opened.
-     */
-    public PcapReader(String fileName, String berkeleyPacketFilter) throws PcapNativeException, NotOpenException {
-        PcapHandle handle;
-        try {
-            handle = Pcaps.openOffline(fileName, PcapHandle.TimestampPrecision.NANO);
-        } catch (PcapNativeException pne) {
-            handle = Pcaps.openOffline(fileName);
-        }
-        if(!handle.isOpen()) {
-            throw new NotOpenException("could not open pcap file " + fileName);
-        }
-        if (berkeleyPacketFilter != null) {
-            handle.setFilter(berkeleyPacketFilter, BpfProgram.BpfCompileMode.OPTIMIZE);
-        }
-        mHandle = handle;
-    }
-
-    /**
-     * Reads the next packet in the pcap file.
-     * @return The next packet in the pcap file, or {@code null} if all packets have been read.
-     */
-    public PcapPacket readNextPacket() {
-        try {
-            return mHandle.getNextPacketEx();
-        } catch (EOFException eofe) {
-            return null;
-        } catch (PcapNativeException|TimeoutException|NotOpenException e) {
-            // Wrap checked exceptions in unchecked exceptions to simplify client code.
-            throw new RuntimeException(e);
-        }
-    }
-
-}
diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/PcapProcessingPipeline.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/PcapProcessingPipeline.java
deleted file mode 100644 (file)
index 9746102..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-package edu.uci.iotproject.analysis;
-
-import edu.uci.iotproject.PcapPacketConsumer;
-import edu.uci.iotproject.PcapReader;
-import org.pcap4j.core.PcapPacket;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * TODO add class documentation.
- *
- * @author Janus Varmarken {@literal <jvarmark@uci.edu>}
- * @author Rahmadi Trimananda {@literal <rtrimana@uci.edu>}
- */
-public class PcapProcessingPipeline {
-
-    private final PcapReader mPcapReader;
-    private final List<PcapPacketConsumer> mPacketConsumers;
-    private final PcapPacketFilter mPacketFilter;
-
-    public PcapProcessingPipeline(PcapReader pcapReader, PcapPacketFilter packetFilter) {
-        mPcapReader = pcapReader;
-        mPacketConsumers = new ArrayList<>();
-        mPacketFilter = packetFilter;
-    }
-
-    public void addPcapPacketConsumer(PcapPacketConsumer packetConsumer) {
-        mPacketConsumers.add(packetConsumer);
-    }
-
-    public void executePipeline() {
-        PcapPacket packet;
-        long count = 0;
-        while ((packet = mPcapReader.readNextPacket()) != null) {
-            if (mPacketFilter != null && !mPacketFilter.shouldIncludePacket(packet)) {
-                continue;
-            }
-            for (PcapPacketConsumer consumer : mPacketConsumers) {
-                consumer.consumePacket(packet);
-            }
-            count++;
-            if (count % 1000 == 0) {
-                System.out.println("Processed " + count + " packets");
-            }
-        }
-    }
-
-}