Beispiel #1
0
  void emitOPM(String pid, String connection) {

    try {
      String source, destination, port;
      String[] endPoint, endPoints;
      LinkedHashMap<String, String> annotations;
      boolean endPointMatched = false;
      Date currentTime;

      spade.vertex.opm.Process processVertex;
      spade.vertex.custom.Network networkVertex;
      WasGeneratedBy wasGeneratedByEdge;
      Used usedEdge;

      // Create process vertex.
      annotations = new LinkedHashMap<String, String>();
      annotations.put("pid", pid);
      processVertex = new spade.vertex.opm.Process();
      processVertex.getAnnotations().putAll(annotations);

      if (!putVertex(processVertex)) {
        errorStream.println("Buffer did not accept process artifact:" + "\n\t pid" + pid);
      }

      // Create network artifact.
      annotations = new LinkedHashMap<String, String>();
      endPoints = connection.split("->");

      endPoint = endPoints[0].split(":");
      source = endPoint[0];
      annotations.put("source host", source);
      port = endPoint[1];
      annotations.put("source port", port);

      endPoint = endPoints[1].split(":");
      destination = endPoint[0];
      annotations.put("destination host", destination);
      port = endPoint[1];
      annotations.put("destination port", port);

      networkVertex = new spade.vertex.custom.Network();
      networkVertex.getAnnotations().putAll(annotations);

      if (!putVertex(networkVertex)) {
        errorStream.println("Buffer did not accept connection artifact:" + "\n\t " + connection);
      }

      // Create an outgoing edge.
      if (InetAddress.getByName(destination).isSiteLocalAddress()) {
        annotations = new LinkedHashMap<String, String>();
        currentTime = new Date();
        annotations.put("time", currentTime.toString());
        usedEdge = new Used(processVertex, networkVertex);
        usedEdge.getAnnotations().putAll(annotations);
        if (!putEdge(usedEdge)) {
          errorStream.println(
              "Buffer did not accept outgoing "
                  + "connection edge:\n\t pid: "
                  + pid
                  + "\n\t connection: "
                  + connection
                  + "\n\t time: "
                  + currentTime.toString());
        }
        endPointMatched = true;
      }

      // Create an incoming edge.
      if (InetAddress.getByName(source).isSiteLocalAddress()) {
        annotations = new LinkedHashMap<String, String>();
        currentTime = new Date();
        annotations.put("time", currentTime.toString());
        wasGeneratedByEdge = new WasGeneratedBy(networkVertex, processVertex);
        wasGeneratedByEdge.getAnnotations().putAll(annotations);
        if (!putEdge(wasGeneratedByEdge)) {
          errorStream.println(
              "Buffer did not accept incoming "
                  + "connection edge:\n\t pid: "
                  + pid
                  + "\n\t connection: "
                  + connection
                  + "\n\t time: "
                  + currentTime.toString());
        }

        endPointMatched = true;
      }

      if (!endPointMatched) {
        errorStream.println("Neither endpoint is local:\n\t" + connection);
      }
    } catch (Exception exception) {
      exception.printStackTrace(errorStream);
    }
  }