diff --git a/src/main/java/de/hsh/inform/orientdb_project/model/EthernetFrameModel.java b/src/main/java/de/hsh/inform/orientdb_project/model/EthernetFrameModel.java index d190a85..49d0d78 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/model/EthernetFrameModel.java +++ b/src/main/java/de/hsh/inform/orientdb_project/model/EthernetFrameModel.java @@ -3,6 +3,7 @@ package de.hsh.inform.orientdb_project.model; import org.pcap4j.packet.EthernetPacket; import com.orientechnologies.orient.core.metadata.schema.OType; +import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; import com.tinkerpop.blueprints.impls.orient.OrientVertexType; @@ -46,6 +47,18 @@ public class EthernetFrameModel { this.microseconds = ms; } + public EthernetFrameModel(Vertex v) { + this.ts = v.getProperty("timestamp"); + this.ms = v.getProperty("microseconds"); + this.sourceMac = v.getProperty("sourceMac"); + this.targetMac = v.getProperty("targetMac"); + this.rawData = v.getProperty("rawData"); + this.size = v.getProperty("size"); + this.payloadSize = v.getProperty("payloadSize"); + this.timestamp = ts; + this.microseconds = ms; + } + public Object[] getArguments() { Object[] arguments = { "sourceMac", this.sourceMac, diff --git a/src/main/java/de/hsh/inform/orientdb_project/model/HostModel.java b/src/main/java/de/hsh/inform/orientdb_project/model/HostModel.java index 2b500d0..5f71f63 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/model/HostModel.java +++ b/src/main/java/de/hsh/inform/orientdb_project/model/HostModel.java @@ -1,6 +1,7 @@ package de.hsh.inform.orientdb_project.model; import com.orientechnologies.orient.core.metadata.schema.OType; +import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; import com.tinkerpop.blueprints.impls.orient.OrientVertexType; @@ -24,6 +25,11 @@ public class HostModel { this.internal = internal; } + public HostModel(Vertex v) { + this.internal = v.getProperty("internal"); + this.ipAddress = v.getProperty("ipAddress"); + } + public Object[] getArguments() { Object[] arguments = { "ipAddress", this.ipAddress, diff --git a/src/main/java/de/hsh/inform/orientdb_project/model/TcpConnectionModel.java b/src/main/java/de/hsh/inform/orientdb_project/model/TcpConnectionModel.java index 8ca9f83..213dc4b 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/model/TcpConnectionModel.java +++ b/src/main/java/de/hsh/inform/orientdb_project/model/TcpConnectionModel.java @@ -60,7 +60,16 @@ public class TcpConnectionModel { } public TcpConnectionModel(Vertex v) { - // TODO! + this.startTs = v.getProperty("startTs"); + this.startMs = v.getProperty("startMs"); + this.endTs = v.getProperty("endTs"); + this.endMs = v.getProperty("endMs"); + this.sourceIp = v.getProperty("sourceIp"); + this.sourcePort = v.getProperty("sourcePort"); + this.targetIp = v.getProperty("targetIp"); + this.targetPort = v.getProperty("targetPort"); + this.volumeSourceToTarget = v.getProperty("volumeSourceToTarget"); + this.volumeTargetToSource = v.getProperty("volumeTargetToSource"); } diff --git a/src/main/java/de/hsh/inform/orientdb_project/repository/EthernetFrameRepository.java b/src/main/java/de/hsh/inform/orientdb_project/repository/EthernetFrameRepository.java index 83438d0..3a2682a 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/repository/EthernetFrameRepository.java +++ b/src/main/java/de/hsh/inform/orientdb_project/repository/EthernetFrameRepository.java @@ -1,7 +1,10 @@ package de.hsh.inform.orientdb_project.repository; +import java.util.ArrayList; import java.util.List; +import com.tinkerpop.blueprints.GraphQuery; +import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; import de.hsh.inform.orientdb_project.model.EthernetFrameModel; @@ -14,8 +17,18 @@ public class EthernetFrameRepository { } public List findAllByRawData(byte[] content) { - // TODO! - return null; + GraphQuery gq = this.ogf.query(); + gq = gq.has("@class", "EthernetFrame"); + // TODO + return this.getListFromVertices(gq.vertices()); + } + + private List getListFromVertices(Iterable vertices) { + List result = new ArrayList(); + for(Vertex v : vertices) { + result.add(new EthernetFrameModel(v)); + } + return result; } } diff --git a/src/main/java/de/hsh/inform/orientdb_project/repository/HostRepository.java b/src/main/java/de/hsh/inform/orientdb_project/repository/HostRepository.java index f82822c..fca305e 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/repository/HostRepository.java +++ b/src/main/java/de/hsh/inform/orientdb_project/repository/HostRepository.java @@ -1,34 +1,50 @@ package de.hsh.inform.orientdb_project.repository; +import java.util.ArrayList; import java.util.List; +import com.tinkerpop.blueprints.GraphQuery; +import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; import de.hsh.inform.orientdb_project.model.HostModel; public class HostRepository { - private OrientGraphNoTx ogf; - - public HostRepository(OrientGraphNoTx ogf) { - this.ogf = ogf; - } - - public List findByConnectionsTo(String ipAddress, int port) { - // TODO! - return null; - } + private OrientGraphNoTx ogf; + + public HostRepository(OrientGraphNoTx ogf) { + this.ogf = ogf; + } + + public List findByConnectionsTo(String ipAddress, int port) { + GraphQuery gq = this.ogf.query(); + gq = gq.has("@class", "Host"); + // TODO + return this.getListFromVertices(gq.vertices()); + } - public List findAllByConnectionsToOutsideHosts() { - // TODO! - return null; - } + public List findAllByConnectionsToOutsideHosts() { + GraphQuery gq = this.ogf.query(); + gq = gq.has("@class", "Host"); + // TODO + return this.getListFromVertices(gq.vertices()); + } - - public List findByIncomingConnectionOnPort(int port) { - return null; + + public List findByIncomingConnectionOnPort(int port) { + GraphQuery gq = this.ogf.query(); + gq = gq.has("@class", "Host"); + // TODO + return this.getListFromVertices(gq.vertices()); + } + + private List getListFromVertices(Iterable vertices) { + List result = new ArrayList(); + for(Vertex v : vertices) { + result.add(new HostModel(v)); } - - - + return result; + } + } diff --git a/src/main/java/de/hsh/inform/orientdb_project/repository/TcpConnectionRepository.java b/src/main/java/de/hsh/inform/orientdb_project/repository/TcpConnectionRepository.java index ff90cdf..c64a7df 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/repository/TcpConnectionRepository.java +++ b/src/main/java/de/hsh/inform/orientdb_project/repository/TcpConnectionRepository.java @@ -1,5 +1,6 @@ package de.hsh.inform.orientdb_project.repository; +import java.util.ArrayList; import java.util.List; import com.tinkerpop.blueprints.GraphQuery; @@ -34,21 +35,23 @@ public class TcpConnectionRepository { return (Long) seen >= (Long) given; } }, ts); - - System.out.println("Ergebnisse:"); - for(Vertex v : gq.vertices()) { - for(String key : v.getPropertyKeys()) { - System.out.print(key + ": " + v.getProperty(key) + ", "); - } - System.out.println(); - } - System.out.println("----"); - return null; + + return this.getListFromVertices(gq.vertices()); } public List getTotalDataVolumeBetweenHosts(String ipA, String ipB) { - // TODO! - return null; + GraphQuery gq = this.ogf.query(); + gq = gq.has("@class", "TcpConnection"); + // TODO + return this.getListFromVertices(gq.vertices()); + } + + private List getListFromVertices(Iterable vertices) { + List result = new ArrayList(); + for(Vertex v : vertices) { + result.add(new TcpConnectionModel(v)); + } + return result; } }