Class PduRecorder
java.lang.Object
edu.nps.moves.dis7.utilities.stream.PduRecorder
Utility to save PDUs received over the network to disk, greatly simplifying the capture of DIS streams by applications.
Example
main()
self-test response shown in log file, example results also included.- Author:
- Don Brutzman, brutzman@nps.edu, Mike Bailey, jmbailey@nps.edu
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final Base64.Encoder
initialize the encoderstatic final String
Character sentinel indicating remainder of line is a commentstatic String
Default multicast group address239.1.2.3
for send and receive connections.static int
Default socket port3000
, matches Wireshark DIS capture defaultstatic final String
pattern template for default pdu log file namestatic final String
ENCODING_BASE64 uses simple Base64 (MIME type) compression on ENCODING_PLAINTEXTstatic final String
ENCODING_BINARY is required for DFDL parsing/unparsingstatic final String
TODO ENCODING_CDIS is Compressed DIS formatstatic final String
TODO ENCODING_EXI is Efficient XML Interchange (EXI) format for compressed XMLstatic final String
TODO ENCODING_JSON is JavaScript Object Notation (JSON) formatstatic final String
TODO ENCODING_MAK_DATA_LOGGER is Mak data logger formatList of supported encodingsTODO list of planned encodingsstatic final String
ENCODING_PLAINTEXT uses a modified comma-separated values (CSV) format to show DIS values readably and is default DIS PDU formatstatic final String
TODO ENCODING_WIRESHARK_DATA_LOGGER is likely going to be PCAPng formatstatic final String
TODO ENCODING_XML is default DIS PDU format using NPS DIS XML schema formatprotected String
encoding used by log fileprotected boolean
whether or not header has already been writtenprotected Writer
Writer class for log fileprotected int
whether or not header has already been writtenprotected final PduFactory
initialize the pduFactory for creating default application id, country, etc.protected int
remember time of first pdu timestampprotected LocalTime
initialize the clockprotected long
initialize the clockprotected long
initialize the clockprotected final StringBuilder
initialize the StringBuilder -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor that uses default values for output directory, DIS address and port.PduRecorder
(String initialOutputDirectory) Constructor to let the use specify an output directory.PduRecorder
(String initialOutputDirectory, String initialAddress, int initialPort) Constructor to let the user specify all required parameters. -
Method Summary
Modifier and TypeMethodDescriptionGet current multicast (or unicast) network address for send and receive connections.Get simple descriptor (such as parent class name) for this network interface, used in trace statementsDeprecated.Provide link to singleton disThreadedNetworkInterfaceTODO change this to enumeration type for strictnessProvide file name of PDU logRetrieve the path to the log fileGet output directory for this PduRecorderGet output directory path for this PduRecorder.int
getPort()
Get network port used, multicast or unicast.long
get duration of the current session, measured from time of first PDU receiptboolean
Whether or not trace statements are provided when packets are sent or received.boolean
Whether or not trace statements include timestamp values.boolean
Whether or not trace statements are provided when packets are received.boolean
Whether or not trace statements are provided when packets are sent.boolean
Whether to provide date/time in readable form, otherwise use byte arrayboolean
Whether includeHeaders status is trueboolean
Whether or not PduRecorder is currently runningboolean
Whether timestamp values start at zero or time of initial PDU receipt, default value is truestatic void
Entry point invocation to facilitate developmental testing, runs selfTest() method.void
pause()
Pause operation of this instancevoid
receivePdu
(byte[] newBuffer, int newLength) receivePdu from DIS data stream, invoked via callback from DisThreadedNetworkInterface.RawPduListenervoid
resume()
Resume instance operationvoid
This selfTest() method saves PDU output logs to assigned directory using all supported encodings.setAddress
(String newAddress) Network address for send and receive connections.setDescriptor
(String newDescriptor) Set new simple descriptor (such as parent class name) for this network interface, used in trace statementssetEncodingPduLog
(String newEncodingPduLog) Set encoding for PDU Logvoid
setIncludeHeaders
(boolean includeHeaders) Set the includeHeaders statussetLogFileName
(String logFileName) Set file name of PDU logsetOutputDirectory
(String outputDirectory) Set output directory for this PduRecordersetPort
(int newPortValue) Set network port used, multicast or unicast.void
setReadableTimeStamp
(boolean readableTimeStamp) Set whether to provide date/time in readable form, otherwise use byte arraysetVerbose
(boolean newValue) Set whether or not trace statements are provided when packets are sent or received.setVerboseIncludesTimestamp
(boolean verboseIncludesTimestamp) Set whether or not trace statements include timestamp values.setVerboseReceipt
(boolean newValue) Set whether or not trace statements are provided when packets are received.setVerboseSending
(boolean newValue) Set whether or not trace statements are provided when packets are sent.void
setZeroBasedTimeStamp
(boolean zeroBasedTimeStamp) Set whether timestamp values start at zero or time of initial PDU receipt, default value is truevoid
start()
Start instance operation, resetting network interface and file recordingstop()
End operation of this instance, removing interfacesprotected void
utility method to write appropriately encoded log file header
-
Field Details
-
DEFAULT_DIS_ADDRESS
Default multicast group address239.1.2.3
for send and receive connections.- See Also:
-
DEFAULT_DIS_PORT
public static int DEFAULT_DIS_PORTDefault socket port3000
, matches Wireshark DIS capture default- See Also:
-
COMMENT_MARKER
Character sentinel indicating remainder of line is a comment- See Also:
-
DEFAULT_FILE_NAME
pattern template for default pdu log file name- See Also:
-
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
ENCODING_BASE64 uses simple Base64 (MIME type) compression on ENCODING_PLAINTEXT- See Also:
-
ENCODING_BINARY
ENCODING_BINARY is required for DFDL parsing/unparsing- See Also:
-
ENCODING_XML
TODO ENCODING_XML is default DIS PDU format using NPS DIS XML schema format- See Also:
-
ENCODING_EXI
TODO ENCODING_EXI is Efficient XML Interchange (EXI) format for compressed XML- See Also:
-
ENCODING_CDIS
-
ENCODING_JSON
TODO ENCODING_JSON is JavaScript Object Notation (JSON) format- See Also:
-
ENCODING_WIRESHARK_DATA_LOGGER
TODO ENCODING_WIRESHARK_DATA_LOGGER is likely going to be PCAPng format- See Also:
-
ENCODING_MAK_DATA_LOGGER
TODO ENCODING_MAK_DATA_LOGGER is Mak data logger format- See Also:
-
ENCODING_OPTIONS_LIST
-
ENCODING_OPTIONS_TODO
-
encodingPduLog
encoding used by log file -
logFileWriter
Writer class for log file -
pduFactory
initialize the pduFactory for creating default application id, country, etc. -
sb
initialize the StringBuilder -
base64Encoder
initialize the encoder -
recordingStartNanoTime
protected long recordingStartNanoTimeinitialize the clock -
pduCount
protected int pduCountwhether or not header has already been written -
headerWritten
protected boolean headerWrittenwhether or not header has already been written -
recordingDurationNano
protected long recordingDurationNanoinitialize the clock -
recordingDuration
initialize the clock -
pduTimestampFirst
protected int pduTimestampFirstremember time of first pdu timestamp
-
-
Constructor Details
-
PduRecorder
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
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
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 writteninitialAddress
- multicast group address to receive data from (TODO allow unicast UDP)initialPort
- UDP port to listen for data
-
-
Method Details
-
getEncodingPduLog
TODO change this to enumeration type for strictness- Returns:
- the pduLogEncoding
-
setEncodingPduLog
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
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 datanewLength
- length of byte array
-
getLogFilePath
-
getDisThreadedNetIF
Deprecated.Deprecated due to class rename, use getDisThreadedNetworkInterface() instead- Returns:
- an instance of this DisThreadedNetworkInterface
- See Also:
-
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
Entry point invocation to facilitate developmental testing, runs selfTest() method.- Parameters:
args
- none supported, TODO offer path/filename
-
selfTest
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
Get current multicast (or unicast) network address for send and receive connections.- Returns:
- current multicast address value
- See Also:
-
setAddress
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
Set network port used, multicast or unicast.- Parameters:
newPortValue
- the disPort value to set- Returns:
- same object to permit progressive setters
- See Also:
-
getDescriptor
Get simple descriptor (such as parent class name) for this network interface, used in trace statements- Returns:
- simple descriptor name
-
setDescriptor
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
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:
-
hasVerboseOutput
public boolean hasVerboseOutput()Whether or not trace statements are provided when packets are sent or received.- Returns:
- the verbose status
- See Also:
-
setVerboseReceipt
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:
-
hasVerboseReceipt
public boolean hasVerboseReceipt()Whether or not trace statements are provided when packets are received.- Returns:
- the verboseReceipt status
-
setVerboseSending
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:
-
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
Set whether or not trace statements include timestamp values.- Parameters:
verboseIncludesTimestamp
- the value to set- Returns:
- same object to permit progressive setters
-
getLogFileName
-
setLogFileName
Set file name of PDU log- Parameters:
logFileName
- the logFileName to set- Returns:
- same object to permit progressive setters
-
getOutputDirectory
Get output directory for this PduRecorder- Returns:
- the outputDirectory
-
setOutputDirectory
Set output directory for this PduRecorder- Parameters:
outputDirectory
- the outputDirectory to set- Returns:
- same object to permit progressive setters
-
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
-