Add model for well known ports plus some static data

This commit is contained in:
Jan Philipp Timme 2016-12-12 11:36:02 +01:00
parent 542d5939af
commit ed862d2f8f
Signed by untrusted user: JPT
GPG Key ID: 5F2C85EC6F3754B7
2 changed files with 49 additions and 0 deletions

View File

@ -0,0 +1,35 @@
package de.hsh.inform.orientdb_project.model;
import com.orientechnologies.orient.core.metadata.schema.OType;
import com.tinkerpop.blueprints.impls.orient.OrientGraphNoTx;
import com.tinkerpop.blueprints.impls.orient.OrientVertexType;
public class WellKnownPortModel {
public int port;
public String description;
/*
* Static helper method to create type for itself in OrientDb
* Check this.getArguments() to ensure completeness.
*/
public static void createType(OrientGraphNoTx og) {
OrientVertexType portType = og.createVertexType("WellKnownPort", "V");
portType.createProperty("port", OType.INTEGER);
portType.createProperty("description", OType.STRING);
}
public WellKnownPortModel(int port, String description) {
this.port = port;
this.description = description;
}
public Object[] getArguments() {
Object[] arguments = {
"port", this.port,
"description", this.description,
};
return arguments;
}
}

View File

@ -1,6 +1,7 @@
package de.hsh.inform.orientdb_project.orientdb;
import java.io.IOException;
import java.util.List;
import com.orientechnologies.orient.client.remote.OServerAdmin;
import com.orientechnologies.orient.core.intent.OIntentMassiveInsert;
@ -17,6 +18,7 @@ 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;
import de.hsh.inform.orientdb_project.model.WellKnownPortModel;
public class OrientDbHelperService {
@ -102,6 +104,17 @@ public class OrientDbHelperService {
public void setupSchema() {
this.createClasses();
this.createClusters();
this.importStaticData();
}
private void importStaticData() {
int[] ports = {22, 25, 53, 80, 443};
String[] descriptions = {"SSH", "SMTP", "DNS", "HTTP", "HTTPS"};
OrientGraphNoTx og = this.getOrientGraphFactory().getNoTx();
for(int i = 0; i < ports.length; i++) {
WellKnownPortModel m = new WellKnownPortModel(ports[i], descriptions[i]);
og.addVertex("class:WellKnownPort", m.getArguments());
}
}
private void createClusters() {
@ -132,6 +145,7 @@ public class OrientDbHelperService {
HostModel.createType(og);
TcpConnectionModel.createType(og);
WellKnownPortModel.createType(og);
// Edges do not really need their own model (yet), they connect the vertex types
OrientEdgeType isContainedInType = og.createEdgeType("isContainedIn", "E");