From 29f11f822dee21c6020c25c0b1552fb12f98913a Mon Sep 17 00:00:00 2001 From: Janus Varmarken Date: Fri, 20 Jul 2018 14:18:13 -0700 Subject: [PATCH] Delete PcapReader.java, PcapProcessingPipeline.java and PcapPacketConsumer.java --- .../uci/iotproject/PcapPacketConsumer.java | 14 ----- .../java/edu/uci/iotproject/PcapReader.java | 59 ------------------- .../analysis/PcapProcessingPipeline.java | 49 --------------- 3 files changed, 122 deletions(-) delete mode 100644 Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PcapPacketConsumer.java delete mode 100644 Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PcapReader.java delete mode 100644 Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/PcapProcessingPipeline.java 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 index fb78eb7..0000000 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PcapPacketConsumer.java +++ /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 index bf618eb..0000000 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/PcapReader.java +++ /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 } - * @author Rahmadi Trimananda {@literal } - */ -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 index 9746102..0000000 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/analysis/PcapProcessingPipeline.java +++ /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 } - * @author Rahmadi Trimananda {@literal } - */ -public class PcapProcessingPipeline { - - private final PcapReader mPcapReader; - private final List 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"); - } - } - } - -} -- 2.34.1