Implement the missing queries
This commit is contained in:
parent
687df96022
commit
cdb36b39d2
|
@ -4,9 +4,11 @@ import java.util.List;
|
||||||
|
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
|
|
||||||
|
import de.hsh.inform.orientdb_project.model.EthernetFrameModel;
|
||||||
import de.hsh.inform.orientdb_project.model.HostModel;
|
import de.hsh.inform.orientdb_project.model.HostModel;
|
||||||
import de.hsh.inform.orientdb_project.model.TcpConnectionModel;
|
import de.hsh.inform.orientdb_project.model.TcpConnectionModel;
|
||||||
import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService;
|
import de.hsh.inform.orientdb_project.orientdb.OrientDbHelperService;
|
||||||
|
import de.hsh.inform.orientdb_project.repository.EthernetFrameRepository;
|
||||||
import de.hsh.inform.orientdb_project.repository.HostRepository;
|
import de.hsh.inform.orientdb_project.repository.HostRepository;
|
||||||
import de.hsh.inform.orientdb_project.repository.TcpConnectionRepository;
|
import de.hsh.inform.orientdb_project.repository.TcpConnectionRepository;
|
||||||
import de.hsh.inform.orientdb_project.util.ConfigPropertiesReader;
|
import de.hsh.inform.orientdb_project.util.ConfigPropertiesReader;
|
||||||
|
@ -36,6 +38,18 @@ public class Main {
|
||||||
System.out.println(hm);
|
System.out.println(hm);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for(HostModel hm : hr.findAllByConnectionsToOutsideHosts()) {
|
||||||
|
System.out.println(hm);
|
||||||
|
}
|
||||||
|
|
||||||
|
EthernetFrameRepository efr = new EthernetFrameRepository(odhs.getDatabaseDocument());
|
||||||
|
List<EthernetFrameModel> efrbyteResult = efr.findAllByRawData(new byte[] {
|
||||||
|
(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF
|
||||||
|
});
|
||||||
|
for(EthernetFrameModel em : efrbyteResult) {
|
||||||
|
System.out.println(em);
|
||||||
|
}
|
||||||
|
|
||||||
// Done
|
// Done
|
||||||
odhs.close();
|
odhs.close();
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package de.hsh.inform.orientdb_project.model;
|
||||||
import org.pcap4j.packet.EthernetPacket;
|
import org.pcap4j.packet.EthernetPacket;
|
||||||
|
|
||||||
import com.orientechnologies.orient.core.metadata.schema.OType;
|
import com.orientechnologies.orient.core.metadata.schema.OType;
|
||||||
|
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||||
import com.tinkerpop.blueprints.Vertex;
|
import com.tinkerpop.blueprints.Vertex;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
|
||||||
|
@ -47,14 +48,14 @@ public class EthernetFrameModel {
|
||||||
this.microseconds = ms;
|
this.microseconds = ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
public EthernetFrameModel(Vertex v) {
|
public EthernetFrameModel(ODocument doc) {
|
||||||
this.ts = v.getProperty("timestamp");
|
this.ts = doc.field("timestamp");
|
||||||
this.ms = v.getProperty("microseconds");
|
this.ms = doc.field("microseconds");
|
||||||
this.sourceMac = v.getProperty("sourceMac");
|
this.sourceMac = doc.field("sourceMac");
|
||||||
this.targetMac = v.getProperty("targetMac");
|
this.targetMac = doc.field("targetMac");
|
||||||
this.rawData = v.getProperty("rawData");
|
this.rawData = doc.field("rawData");
|
||||||
this.size = v.getProperty("size");
|
this.size = doc.field("size");
|
||||||
this.payloadSize = v.getProperty("payloadSize");
|
this.payloadSize = doc.field("payloadSize");
|
||||||
this.timestamp = ts;
|
this.timestamp = ts;
|
||||||
this.microseconds = ms;
|
this.microseconds = ms;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
package de.hsh.inform.orientdb_project.orientdb;
|
package de.hsh.inform.orientdb_project.orientdb;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import com.orientechnologies.orient.client.remote.OServerAdmin;
|
import com.orientechnologies.orient.client.remote.OServerAdmin;
|
||||||
|
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
||||||
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
|
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientConfigurableGraph.THREAD_MODE;
|
import com.tinkerpop.blueprints.impls.orient.OrientConfigurableGraph.THREAD_MODE;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
|
import com.tinkerpop.blueprints.impls.orient.OrientEdgeType;
|
||||||
|
@ -38,6 +38,10 @@ public class OrientDbHelperService {
|
||||||
this.factory = null;
|
this.factory = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public ODatabaseDocumentTx getDatabaseDocument() {
|
||||||
|
return this.factory.getDatabase();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public OrientGraphFactory getOrientGraphFactory() {
|
public OrientGraphFactory getOrientGraphFactory() {
|
||||||
if(this.factory == null) {
|
if(this.factory == null) {
|
||||||
|
|
|
@ -3,30 +3,32 @@ package de.hsh.inform.orientdb_project.repository;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import com.tinkerpop.blueprints.GraphQuery;
|
import com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx;
|
||||||
import com.tinkerpop.blueprints.Vertex;
|
import com.orientechnologies.orient.core.iterator.ORecordIteratorClass;
|
||||||
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
|
import com.orientechnologies.orient.core.record.impl.ODocument;
|
||||||
|
|
||||||
import de.hsh.inform.orientdb_project.model.EthernetFrameModel;
|
import de.hsh.inform.orientdb_project.model.EthernetFrameModel;
|
||||||
|
|
||||||
public class EthernetFrameRepository {
|
public class EthernetFrameRepository {
|
||||||
private OrientGraphNoTx ogf;
|
private ODatabaseDocumentTx db;
|
||||||
|
|
||||||
public EthernetFrameRepository(OrientGraphNoTx ogf) {
|
public EthernetFrameRepository(ODatabaseDocumentTx oDatabaseDocumentTx) {
|
||||||
this.ogf = ogf;
|
this.db = oDatabaseDocumentTx;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<EthernetFrameModel> findAllByRawData(byte[] content) {
|
public List<EthernetFrameModel> findAllByRawData(byte[] needle) {
|
||||||
GraphQuery gq = this.ogf.query();
|
ORecordIteratorClass<ODocument> resultIterator = db.browseClass("EthernetFrame");
|
||||||
gq = gq.has("@class", "EthernetFrame");
|
|
||||||
// TODO
|
|
||||||
return this.getListFromVertices(gq.vertices());
|
|
||||||
}
|
|
||||||
|
|
||||||
private List<EthernetFrameModel> getListFromVertices(Iterable<Vertex> vertices) {
|
|
||||||
List<EthernetFrameModel> result = new ArrayList<EthernetFrameModel>();
|
List<EthernetFrameModel> result = new ArrayList<EthernetFrameModel>();
|
||||||
for(Vertex v : vertices) {
|
for(ODocument doc : resultIterator) {
|
||||||
result.add(new EthernetFrameModel(v));
|
int found = -1;
|
||||||
|
byte[] rawData = (byte[]) doc.field("rawData");
|
||||||
|
// Manually compare bytes... yay! \o/
|
||||||
|
String bigStr = new String(rawData);
|
||||||
|
String smallStr = new String(needle);
|
||||||
|
found = bigStr.indexOf(smallStr);
|
||||||
|
if(found != -1) {
|
||||||
|
result.add(new EthernetFrameModel(doc));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,18 +29,20 @@ public class HostRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<HostModel> findAllByConnectionsToOutsideHosts() {
|
public List<HostModel> findAllByConnectionsToOutsideHosts() {
|
||||||
GraphQuery gq = this.ogf.query();
|
String sql = "" +
|
||||||
gq = gq.has("@class", "Host");
|
"SELECT EXPAND(DISTINCT(out)) FROM (SELECT out('hasSourceHost') AS out FROM TcpConnection WHERE out('hasTargetHost').internal = false);";
|
||||||
// TODO
|
@SuppressWarnings("unchecked") // We know.
|
||||||
return this.getListFromVertices(gq.vertices());
|
Iterable<Vertex> vertices = (Iterable<Vertex>) this.ogf.command(new OCommandSQL(sql)).execute();
|
||||||
|
return this.getListFromVertices(vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public List<HostModel> findByIncomingConnectionOnPort(int port) {
|
public List<HostModel> findAllByIncomingConnectionOnWellKnownPort() {
|
||||||
GraphQuery gq = this.ogf.query();
|
String sql = "" +
|
||||||
gq = gq.has("@class", "Host");
|
"SELECT EXPAND(DISTINCT(out)) FROM (SELECT out('hasTargetHost') FROM TcpConnection WHERE targetPort IN (SELECT port FROM WellKnownPort))";
|
||||||
// TODO
|
@SuppressWarnings("unchecked") // We know.
|
||||||
return this.getListFromVertices(gq.vertices());
|
Iterable<Vertex> vertices = (Iterable<Vertex>) this.ogf.command(new OCommandSQL(sql)).execute();
|
||||||
|
return this.getListFromVertices(vertices);
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<HostModel> getListFromVertices(Iterable<Vertex> vertices) {
|
private List<HostModel> getListFromVertices(Iterable<Vertex> vertices) {
|
||||||
|
|
Loading…
Reference in New Issue