diff --git a/src/main/java/de/hsh/inform/orientdb_project/model/Ipv4PacketModel.java b/src/main/java/de/hsh/inform/orientdb_project/model/IpPacketModel.java similarity index 81% rename from src/main/java/de/hsh/inform/orientdb_project/model/Ipv4PacketModel.java rename to src/main/java/de/hsh/inform/orientdb_project/model/IpPacketModel.java index 05364ae..b3a6124 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/model/Ipv4PacketModel.java +++ b/src/main/java/de/hsh/inform/orientdb_project/model/IpPacketModel.java @@ -1,14 +1,12 @@ package de.hsh.inform.orientdb_project.model; -import java.net.Inet4Address; - import org.pcap4j.packet.IpV4Packet; import com.orientechnologies.orient.core.metadata.schema.OType; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; import com.tinkerpop.blueprints.impls.orient.OrientVertexType; -public class Ipv4PacketModel { +public class IpPacketModel { public long ts; public int ms; @@ -30,14 +28,13 @@ public class Ipv4PacketModel { ipPacketType.createProperty("payloadSize", OType.INTEGER); } - public Ipv4PacketModel(IpV4Packet ipv4, Inet4Address sourceIp, Inet4Address targetIp, long ts, int ms) { + public IpPacketModel(IpV4Packet ipv4, long ts, int ms) { this.ts = ts; this.ms = ms; - this.sourceIp = sourceIp.toString().split("/")[1]; - this.targetIp = targetIp.toString().split("/")[1]; + this.sourceIp = ipv4.getHeader().getSrcAddr().toString().split("/")[1]; + this.targetIp = ipv4.getHeader().getDstAddr().toString().split("/")[1]; this.size = ipv4.getRawData().length; this.payloadSize = ipv4.getRawData().length - ipv4.getHeader().length(); - } public Object[] getArguments() { diff --git a/src/main/java/de/hsh/inform/orientdb_project/orientdb/NodeBasedImportService.java b/src/main/java/de/hsh/inform/orientdb_project/orientdb/NodeBasedImportService.java index bdf9b11..7c90dba 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/orientdb/NodeBasedImportService.java +++ b/src/main/java/de/hsh/inform/orientdb_project/orientdb/NodeBasedImportService.java @@ -19,7 +19,7 @@ import de.hsh.inform.orientdb_project.model.ArpPacketModel; import de.hsh.inform.orientdb_project.model.EthernetFrameModel; import de.hsh.inform.orientdb_project.model.HostModel; import de.hsh.inform.orientdb_project.model.IcmpPacketModel; -import de.hsh.inform.orientdb_project.model.Ipv4PacketModel; +import de.hsh.inform.orientdb_project.model.IpPacketModel; import de.hsh.inform.orientdb_project.model.TcpConnectionModel; import de.hsh.inform.orientdb_project.model.TcpPacketModel; import de.hsh.inform.orientdb_project.model.UdpPacketModel; @@ -38,7 +38,7 @@ public class NodeBasedImportService extends AbstractNetdataImportService { // References to already created model instances (these are reseted before processing a new ethernetFrame) private EthernetFrameModel ethernetFrameModel; private ArpPacketModel arpPacketModel; - private Ipv4PacketModel ipv4PacketModel; + private IpPacketModel ipPacketModel; private TcpPacketModel tcpPacketModel; private UdpPacketModel udpPacketModel; private IcmpPacketModel icmpPacketModel; @@ -69,7 +69,7 @@ public class NodeBasedImportService extends AbstractNetdataImportService { // Also clean model instances this.ethernetFrameModel = null; this.arpPacketModel = null; - this.ipv4PacketModel = null; + this.ipPacketModel = null; this.tcpPacketModel = null; this.udpPacketModel = null; this.icmpPacketModel = null; @@ -88,13 +88,11 @@ public class NodeBasedImportService extends AbstractNetdataImportService { } public void handleIpV4Packet(IpV4Packet ipv4, long ts, int ms) { - Inet4Address sourceIp = ipv4.getHeader().getSrcAddr(); - Inet4Address targetIp = ipv4.getHeader().getDstAddr(); + this.ipPacketModel = new IpPacketModel(ipv4, ts, ms); + this.ipPacketVertex = this.og.addVertex("class:IpPacket", this.ipPacketModel.getArguments()); // Add hosts to database if new - this.addHostIfNew(sourceIp); - this.addHostIfNew(targetIp); - this.ipv4PacketModel = new Ipv4PacketModel(ipv4, sourceIp, targetIp, ts, ms); - this.ipPacketVertex = this.og.addVertex("class:IpPacket", this.ipv4PacketModel.getArguments()); + this.addHostIfNew(ipv4.getHeader().getSrcAddr()); + this.addHostIfNew(ipv4.getHeader().getDstAddr()); // Wire up to its ethernet frame Edge containsEdge = this.og.addEdge("class:contains", this.ethernetFrameVertex, this.ipPacketVertex, "contains"); Edge isContainedInEdge = this.og.addEdge("class:isContainedIn", this.ipPacketVertex, this.ethernetFrameVertex, "isContainedIn"); @@ -119,7 +117,7 @@ public class NodeBasedImportService extends AbstractNetdataImportService { TcpConnectionModel tcpConnection = this.getTcpConnectionFor(tcp); if(tcpConnection != null) { // If connection exists ... if(ts - tcpConnection.endTs < 2) { // ... and still "up to date" aka time difference < 2s - if(tcpConnection.sourceIp.equals(this.ipv4PacketModel.sourceIp)) { + if(tcpConnection.sourceIp.equals(this.ipPacketModel.sourceIp)) { // Update connection data in direction SourceIp -> TargetIp tcpConnection.addVolumeSourceToTarget(this.tcpPacketModel.payloadSize); } else { diff --git a/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java b/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java index 10ed8d6..671c913 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java +++ b/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java @@ -4,18 +4,16 @@ import java.io.IOException; import com.orientechnologies.orient.client.remote.OServerAdmin; import com.orientechnologies.orient.core.intent.OIntentMassiveInsert; -import com.orientechnologies.orient.core.metadata.schema.OType; import com.tinkerpop.blueprints.impls.orient.OrientConfigurableGraph.THREAD_MODE; import com.tinkerpop.blueprints.impls.orient.OrientEdgeType; import com.tinkerpop.blueprints.impls.orient.OrientGraphFactory; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; -import com.tinkerpop.blueprints.impls.orient.OrientVertexType; import de.hsh.inform.orientdb_project.model.ArpPacketModel; import de.hsh.inform.orientdb_project.model.EthernetFrameModel; import de.hsh.inform.orientdb_project.model.HostModel; import de.hsh.inform.orientdb_project.model.IcmpPacketModel; -import de.hsh.inform.orientdb_project.model.Ipv4PacketModel; +import de.hsh.inform.orientdb_project.model.IpPacketModel; import de.hsh.inform.orientdb_project.model.TcpConnectionModel; import de.hsh.inform.orientdb_project.model.TcpPacketModel; import de.hsh.inform.orientdb_project.model.UdpPacketModel; @@ -127,7 +125,7 @@ public class OrientDbHelperService { // These are the vertex types used in our model EthernetFrameModel.createType(og); ArpPacketModel.createType(og); - Ipv4PacketModel.createType(og); + IpPacketModel.createType(og); UdpPacketModel.createType(og); TcpPacketModel.createType(og); IcmpPacketModel.createType(og);