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 d73ea02..04a4c17 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/Main.java +++ b/src/main/java/de/hsh/inform/orientdb_project/Main.java @@ -4,8 +4,10 @@ import java.util.List; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; +import de.hsh.inform.orientdb_project.model.HostModel; import de.hsh.inform.orientdb_project.model.TcpConnectionModel; import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService; +import de.hsh.inform.orientdb_project.repository.HostRepository; import de.hsh.inform.orientdb_project.repository.TcpConnectionRepository; import de.hsh.inform.orientdb_project.util.ConfigPropertiesReader; @@ -29,6 +31,11 @@ public class Main { long r = tcr.getTotalDataVolumePerMinuteBetweenHosts("172.16.114.207", "206.251.19.72"); System.out.println("Bytes per Second: " + r); + HostRepository hr = new HostRepository(ogf); + for(HostModel hm : hr.findByConnectionsTo("197.218.177.69", 25)) { + System.out.println(hm); + } + // Done odhs.close(); } 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 5f71f63..6d3e5e1 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 @@ -37,5 +37,14 @@ public class HostModel { }; return arguments; } + + public String toString() { + StringBuilder sb = new StringBuilder("[Host ipAddress="); + sb.append(this.ipAddress); + sb.append(", internal="); + sb.append(this.internal); + sb.append("]"); + return sb.toString(); + } } 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 2e63274..7abb7b6 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 @@ -146,13 +146,13 @@ public class NodeBasedImportService extends AbstractNetdataImportService { } private void addHostIfNew(Inet4Address ipAddress) { - if(this.knownHosts.containsKey(ipAddress)) { + String ipAddressStr = ipAddress.toString().split("/")[1]; + if(this.knownHosts.containsKey(ipAddressStr)) { return; // Host already known, nothing to do! } else { // Check internal/external by IP boolean isInternal = ipAddress.isSiteLocalAddress(); // TODO: VERIFY IF THIS IS CORRECT! // Create Vertex and add to HashMap - String ipAddressStr = ipAddress.toString().split("/")[1]; HostModel hostModel = new HostModel(ipAddressStr, isInternal); Vertex host = this.og.addVertex("class:Host", hostModel.getArguments()); this.knownHosts.put(ipAddressStr, host); 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 fca305e..9acc594 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 @@ -3,6 +3,7 @@ package de.hsh.inform.orientdb_project.repository; import java.util.ArrayList; import java.util.List; +import com.orientechnologies.orient.core.sql.OCommandSQL; import com.tinkerpop.blueprints.GraphQuery; import com.tinkerpop.blueprints.Vertex; import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx; @@ -18,10 +19,13 @@ public class HostRepository { } public List findByConnectionsTo(String ipAddress, int port) { - GraphQuery gq = this.ogf.query(); - gq = gq.has("@class", "Host"); - // TODO - return this.getListFromVertices(gq.vertices()); + String sql = "" + + "SELECT EXPAND(out('isTargetHostFor')[targetPort=" + port + "].out('hasSourceHost')) " + + "FROM Host WHERE ipAddress = '" + ipAddress + "';"; + + @SuppressWarnings("unchecked") // We know. + Iterable vertices = (Iterable) this.ogf.command(new OCommandSQL(sql)).execute(); + return this.getListFromVertices(vertices); } public List findAllByConnectionsToOutsideHosts() {