From ed862d2f8fb819640d9dd1f6c586ce6c331585b3 Mon Sep 17 00:00:00 2001 From: Jan Philipp Timme Date: Mon, 12 Dec 2016 11:36:02 +0100 Subject: [PATCH] Add model for well known ports plus some static data --- .../model/WellKnownPortModel.java | 35 +++++++++++++++++++ .../orientdb/OrientDbHelperService.java | 14 ++++++++ 2 files changed, 49 insertions(+) create mode 100644 src/main/java/de/hsh/inform/orientdb_project/model/WellKnownPortModel.java diff --git a/src/main/java/de/hsh/inform/orientdb_project/model/WellKnownPortModel.java b/src/main/java/de/hsh/inform/orientdb_project/model/WellKnownPortModel.java new file mode 100644 index 0000000..c2a676a --- /dev/null +++ b/src/main/java/de/hsh/inform/orientdb_project/model/WellKnownPortModel.java @@ -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; + } + +} diff --git a/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java b/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java index e6a9382..7360a11 100644 --- a/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java +++ b/src/main/java/de/hsh/inform/orientdb_project/orientdb/OrientDbHelperService.java @@ -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");