From d47fb3a17b0f426eec5382bfe1abb2c444c0cdcc Mon Sep 17 00:00:00 2001 From: Janus Varmarken Date: Thu, 26 Jul 2018 15:34:36 -0700 Subject: [PATCH] Main.java: re-add counting of statistics using TcpConversationUtils --- .../main/java/edu/uci/iotproject/Main.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java index 76134dc..0ddae8d 100644 --- a/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java +++ b/Code/Projects/SmartPlugDetector/src/main/java/edu/uci/iotproject/Main.java @@ -1,5 +1,6 @@ package edu.uci.iotproject; +import edu.uci.iotproject.analysis.TcpConversationUtils; import edu.uci.iotproject.analysis.TriggerTrafficExtractor; import edu.uci.iotproject.io.TriggerTimesFileReader; import org.pcap4j.core.*; @@ -49,6 +50,24 @@ public class Main { }, dnsMap, tcpReassembler); outputter.flush(); outputter.close(); + + // Extract all conversations present in the filtered trace. + List allConversations = tcpReassembler.getTcpConversations(); + // Group conversations by hostname. + Map> convsByHostname = TcpConversationUtils.groupConversationsByHostname(allConversations, dnsMap); + System.out.println("Grouped conversations by hostname."); + // For each hostname, count the frequencies of packet lengths exchanged with that hostname. + final Map> pktLenFreqsByHostname = new HashMap<>(); + convsByHostname.forEach((host, convs) -> pktLenFreqsByHostname.put(host, TcpConversationUtils.countPacketLengthFrequencies(convs))); + System.out.println("Counted frequencies of packet lengths exchanged with each hostname."); + // For each hostname, count the frequencies of packet sequences (i.e., count how many conversations exchange a + // sequence of packets of some specific lengths). + final Map> pktSeqFreqsByHostname = new HashMap<>(); + convsByHostname.forEach((host, convs) -> pktSeqFreqsByHostname.put(host, TcpConversationUtils.countPacketSequenceFrequencies(convs))); + System.out.println("Counted frequencies of packet sequences exchanged with each hostname."); + + + // ------------------------------------------------------------------------------------------------------------- // ------------------------------------------------------------------------------------------------------------- } -- 2.34.1