Class PduRecorder

java.lang.Object
edu.nps.moves.dis7.utilities.stream.PduRecorder
  • Field Details

    • DEFAULT_DIS_ADDRESS

      public static String DEFAULT_DIS_ADDRESS
      Default multicast group address 239.1.2.3 for send and receive connections.
      See Also:
    • DEFAULT_DIS_PORT

      public static int DEFAULT_DIS_PORT
      Default socket port 3000, matches Wireshark DIS capture default
      See Also:
    • COMMENT_MARKER

      public static final String COMMENT_MARKER
      Character sentinel indicating remainder of line is a comment
      See Also:
    • DEFAULT_FILE_NAME

      public static final String DEFAULT_FILE_NAME
      pattern template for default pdu log file name
      See Also:
    • ENCODING_PLAINTEXT

      public static final String ENCODING_PLAINTEXT
      ENCODING_PLAINTEXT uses a modified comma-separated values (CSV) format to show DIS values readably and is default DIS PDU format
      See Also:
    • ENCODING_BASE64

      public static final String ENCODING_BASE64
      ENCODING_BASE64 uses simple Base64 (MIME type) compression on ENCODING_PLAINTEXT
      See Also:
    • ENCODING_BINARY

      public static final String ENCODING_BINARY
      ENCODING_BINARY is required for DFDL parsing/unparsing
      See Also:
    • ENCODING_XML

      public static final String ENCODING_XML
      TODO ENCODING_XML is default DIS PDU format using NPS DIS XML schema format
      See Also:
    • ENCODING_EXI

      public static final String ENCODING_EXI
      TODO ENCODING_EXI is Efficient XML Interchange (EXI) format for compressed XML
      See Also:
    • ENCODING_CDIS

      public static final String ENCODING_CDIS
      TODO ENCODING_CDIS is Compressed DIS format
      See Also:
    • ENCODING_JSON

      public static final String ENCODING_JSON
      TODO ENCODING_JSON is JavaScript Object Notation (JSON) format
      See Also:
    • ENCODING_WIRESHARK_DATA_LOGGER

      public static final String ENCODING_WIRESHARK_DATA_LOGGER
      TODO ENCODING_WIRESHARK_DATA_LOGGER is likely going to be PCAPng format
      See Also:
    • ENCODING_MAK_DATA_LOGGER

      public static final String ENCODING_MAK_DATA_LOGGER
      TODO ENCODING_MAK_DATA_LOGGER is Mak data logger format
      See Also:
    • ENCODING_OPTIONS_LIST

      public static final List<String> ENCODING_OPTIONS_LIST
      List of supported encodings
    • ENCODING_OPTIONS_TODO

      public static final List<String> ENCODING_OPTIONS_TODO
      TODO list of planned encodings
    • encodingPduLog

      protected String encodingPduLog
      encoding used by log file
    • logFileWriter

      protected Writer logFileWriter
      Writer class for log file
    • pduFactory

      protected final PduFactory pduFactory
      initialize the pduFactory for creating default application id, country, etc.
    • sb

      protected final StringBuilder sb
      initialize the StringBuilder
    • base64Encoder

      protected final Base64.Encoder base64Encoder
      initialize the encoder
    • recordingStartNanoTime

      protected long recordingStartNanoTime
      initialize the clock
    • pduCount

      protected int pduCount
      whether or not header has already been written
    • headerWritten

      protected boolean headerWritten
      whether or not header has already been written
    • recordingDurationNano

      protected long recordingDurationNano
      initialize the clock
    • recordingDuration

      protected LocalTime recordingDuration
      initialize the clock
    • pduTimestampFirst

      protected int pduTimestampFirst
      remember time of first pdu timestamp
  • Constructor Details

    • PduRecorder

      public PduRecorder() throws IOException
      Default constructor that uses default values for output directory, DIS address and port. Each instance must invoke start() to begin operations, pause() to suspend operations, resume() to continue operations, and stop() to terminate operations.
      Throws:
      IOException - if something goes wrong during instantiation
    • PduRecorder

      public PduRecorder(String initialOutputDirectory) throws IOException
      Constructor to let the use specify an output directory. Uses default values for multicast address and port. Each instance must invoke start() to begin operations, pause() to suspend operations, resume() to continue operations, and stop() to terminate operations.
      Parameters:
      initialOutputDirectory - the directory to write log files to
      Throws:
      IOException - if something goes wrong during instantiation
    • PduRecorder

      public PduRecorder(String initialOutputDirectory, String initialAddress, int initialPort)
      Constructor to let the user specify all required parameters. Each instance must invoke start() to begin operations, pause() to suspend operations, resume() to continue operations, and stop() to terminate operations..
      Parameters:
      initialOutputDirectory - local path for directory where the log files are written
      initialAddress - multicast group address to receive data from (TODO allow unicast UDP)
      initialPort - UDP port to listen for data
  • Method Details

    • getEncodingPduLog

      public String getEncodingPduLog()
      TODO change this to enumeration type for strictness
      Returns:
      the pduLogEncoding
    • setEncodingPduLog

      public PduRecorder setEncodingPduLog(String newEncodingPduLog)
      Set encoding for PDU Log
      Parameters:
      newEncodingPduLog - the pduLogEncoding to set
      Returns:
      same object to permit progressive setters
    • resume

      public void resume()
      Resume instance operation
      See Also:
    • start

      public void start()
      Start instance operation, resetting network interface and file recording
      See Also:
    • pause

      public void pause()
      Pause operation of this instance
      See Also:
    • stop

      public File stop()
      End operation of this instance, removing interfaces
      Returns:
      recorder logFile
      See Also:
    • receivePdu

      public void receivePdu(byte[] newBuffer, int newLength)
      receivePdu from DIS data stream, invoked via callback from DisThreadedNetworkInterface.RawPduListener
      Parameters:
      newBuffer - byte array for receiving data
      newLength - length of byte array
    • getLogFilePath

      public String getLogFilePath()
      Retrieve the path to the log file
      Returns:
      the path to the log file
    • getDisThreadedNetIF

      @Deprecated public DisThreadedNetworkInterface getDisThreadedNetIF()
      Deprecated.
      Deprecated due to class rename, use getDisThreadedNetworkInterface() instead
      Returns:
      an instance of this DisThreadedNetworkInterface
      See Also:
    • getDisThreadedNetworkInterface

      public DisThreadedNetworkInterface getDisThreadedNetworkInterface()
      Provide link to singleton disThreadedNetworkInterface
      Returns:
      an instance of this DisThreadedNetworkInterface
    • writeHeader

      protected void writeHeader()
      utility method to write appropriately encoded log file header
    • isRunning

      public boolean isRunning()
      Whether or not PduRecorder is currently running
      Returns:
      the pduRecorderRunning
    • main

      public static void main(String[] args)
      Entry point invocation to facilitate developmental testing, runs selfTest() method.
      Parameters:
      args - none supported, TODO offer path/filename
    • selfTest

      public void selfTest(String[] args)
      This selfTest() method saves PDU output logs to assigned directory using all supported encodings. Further checking can be accomplished by separately Invoking the edu.nps.moves.dis7.examples.PduReaderPlayer which will playback all logs written to that log directory.
      Parameters:
      args - none supported, TODO offer path/filename
    • getAddress

      public String getAddress()
      Get current multicast (or unicast) network address for send and receive connections.
      Returns:
      current multicast address value
      See Also:
    • setAddress

      public PduRecorder setAddress(String newAddress)
      Network address for send and receive connections.
      Parameters:
      newAddress - the new network address to set
      Returns:
      same object to permit progressive setters
      See Also:
    • getPort

      public int getPort()
      Get network port used, multicast or unicast.
      Returns:
      current port value
      See Also:
    • setPort

      public PduRecorder setPort(int newPortValue)
      Set network port used, multicast or unicast.
      Parameters:
      newPortValue - the disPort value to set
      Returns:
      same object to permit progressive setters
      See Also:
    • getDescriptor

      public String getDescriptor()
      Get simple descriptor (such as parent class name) for this network interface, used in trace statements
      Returns:
      simple descriptor name
    • setDescriptor

      public PduRecorder setDescriptor(String newDescriptor)
      Set new simple descriptor (such as parent class name) for this network interface, used in trace statements
      Parameters:
      newDescriptor - simple descriptor name
      Returns:
      same object to permit progressive setters
    • setVerbose

      public PduRecorder setVerbose(boolean newValue)
      Set whether or not trace statements are provided when packets are sent or received.
      Parameters:
      newValue - the verbose status to set, also resets verboseReceipt and verboseSending to match.
      Returns:
      same object to permit progressive setters
      See Also:
      • verboseReceipt
      • verboseSending
    • hasVerboseOutput

      public boolean hasVerboseOutput()
      Whether or not trace statements are provided when packets are sent or received.
      Returns:
      the verbose status
      See Also:
      • verboseReceipt
      • verboseSending
    • setVerboseReceipt

      public PduRecorder setVerboseReceipt(boolean newValue)
      Set whether or not trace statements are provided when packets are received.
      Parameters:
      newValue - the verboseReceipt status to set
      Returns:
      same object to permit progressive setters
      See Also:
      • verbose
      • verboseSending
    • hasVerboseReceipt

      public boolean hasVerboseReceipt()
      Whether or not trace statements are provided when packets are received.
      Returns:
      the verboseReceipt status
    • setVerboseSending

      public PduRecorder setVerboseSending(boolean newValue)
      Set whether or not trace statements are provided when packets are sent.
      Parameters:
      newValue - the verboseSending status to set
      Returns:
      same object to permit progressive setters
      See Also:
      • verbose
      • verboseReceipt
    • hasVerboseSending

      public boolean hasVerboseSending()
      Whether or not trace statements are provided when packets are sent.
      Returns:
      the verboseSending status
    • hasVerboseOutputIncludesTimestamp

      public boolean hasVerboseOutputIncludesTimestamp()
      Whether or not trace statements include timestamp values.
      Returns:
      the verboseIncludesTimestamp value
    • setVerboseIncludesTimestamp

      public PduRecorder setVerboseIncludesTimestamp(boolean verboseIncludesTimestamp)
      Set whether or not trace statements include timestamp values.
      Parameters:
      verboseIncludesTimestamp - the value to set
      Returns:
      same object to permit progressive setters
    • getLogFileName

      public String getLogFileName()
      Provide file name of PDU log
      Returns:
      the logFileName
    • setLogFileName

      public PduRecorder setLogFileName(String logFileName)
      Set file name of PDU log
      Parameters:
      logFileName - the logFileName to set
      Returns:
      same object to permit progressive setters
    • getOutputDirectory

      public String getOutputDirectory()
      Get output directory for this PduRecorder
      Returns:
      the outputDirectory
    • setOutputDirectory

      public PduRecorder setOutputDirectory(String outputDirectory)
      Set output directory for this PduRecorder
      Parameters:
      outputDirectory - the outputDirectory to set
      Returns:
      same object to permit progressive setters
    • getOutputDirectoryPath

      public Path getOutputDirectoryPath()
      Get output directory path for this PduRecorder. To change outputDirectoryPath, invoke setOutputDirectory().
      Returns:
      the outputDirectoryPath
      See Also:
    • includesReadableTimeStamp

      public boolean includesReadableTimeStamp()
      Whether to provide date/time in readable form, otherwise use byte array
      Returns:
      whether readableTimeStamp is used
    • setReadableTimeStamp

      public void setReadableTimeStamp(boolean readableTimeStamp)
      Set whether to provide date/time in readable form, otherwise use byte array
      Parameters:
      readableTimeStamp - whether readableTimeStamp to true
    • getSessionDuration

      public long getSessionDuration()
      get duration of the current session, measured from time of first PDU receipt
      Returns:
      the sessionDurationNano
    • isZeroBasedTimeStamp

      public boolean isZeroBasedTimeStamp()
      Whether timestamp values start at zero or time of initial PDU receipt, default value is true
      Returns:
      the zeroBasedTimeStamp
    • setZeroBasedTimeStamp

      public void setZeroBasedTimeStamp(boolean zeroBasedTimeStamp)
      Set whether timestamp values start at zero or time of initial PDU receipt, default value is true
      Parameters:
      zeroBasedTimeStamp - the zeroBasedTimeStamp to set
    • isIncludeHeaders

      public boolean isIncludeHeaders()
      Whether includeHeaders status is true
      Returns:
      the includeHeaders
    • setIncludeHeaders

      public void setIncludeHeaders(boolean includeHeaders)
      Set the includeHeaders status
      Parameters:
      includeHeaders - the includeHeaders to set