diff --git a/src/main/java/de/hsh/inform/orientdb_project/Main.java b/src/main/java/de/hsh/inform/orientdb_project/Main.java index 782d3c2..d73ea02 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/Main.java +++ b/src/main/java/de/hsh/inform/orientdb_project/Main.java @@ -25,6 +25,9 @@ public class Main { for(TcpConnectionModel m : result) { System.out.println(m.toString()); } + + long r = tcr.getTotalDataVolumePerMinuteBetweenHosts("172.16.114.207", "206.251.19.72"); + System.out.println("Bytes per Second: " + r); // Done odhs.close(); 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 213dc4b..9686d67 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 @@ -101,6 +101,10 @@ public class TcpConnectionModel { sb.append(this.startTs); sb.append("."); sb.append(this.startMs); + sb.append("->"); + sb.append(this.endTs); + sb.append("."); + sb.append(this.endMs); sb.append("] "); sb.append(this.sourceIp); sb.append(":"); 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 beacefb..8a33867 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 @@ -3,9 +3,7 @@ package de.hsh.inform.orientdb_project.repository; import java.util.ArrayList; import java.util.List; -import com.orientechnologies.orient.core.command.OCommandRequest; import com.orientechnologies.orient.core.sql.OCommandSQL; -import com.tinkerpop.blueprints.GraphQuery; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; @@ -46,11 +44,27 @@ public class TcpConnectionRepository { return this.getListFromVertices(vertices); } - public List getTotalDataVolumeBetweenHosts(String ipA, String ipB) { - GraphQuery gq = this.ogf.query(); - gq = gq.has("@class", "TcpConnection"); - // TODO - return this.getListFromVertices(gq.vertices()); + public long getTotalDataVolumePerMinuteBetweenHosts(String ipA, String ipB) { + String sql = "SELECT FROM TcpConnection " + + "WHERE (sourceIp = '" + ipA + "' AND targetIp = '" + ipB + "') " + + "OR (sourceIp = '" + ipB + "' AND targetIp = '" + ipA + "') "; + @SuppressWarnings("unchecked") // We know. + Iterable vertices = (Iterable) this.ogf.command(new OCommandSQL(sql)).execute(); + List result = this.getListFromVertices(vertices); + long earliestStartTs = -1; + long latestEndTs = -1; + long totalVolume = 0; + for(TcpConnectionModel model : result) { + System.out.println(model.toString()); + totalVolume += model.getTotalVolume(); + if(earliestStartTs == -1 || earliestStartTs > model.startTs) { + earliestStartTs = model.startTs; + } + if(latestEndTs == -1 || latestEndTs < model.endTs) { + latestEndTs = model.endTs; + } + } + return (long) ((1.0*totalVolume) / (1.0*(latestEndTs - earliestStartTs))); } private List getListFromVertices(Iterable vertices) {