|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.voytechs.jnetstream.npl.Visitor
com.voytechs.jnetstream.codec.Decoder
public class Decoder
Decoder is the main interpreter for NPL. Not the only one, parsing NPL file
is a 3 stage process:
Decoder has conveniece Constructor methods where you can supply the name of the NPL file and it will actually call on all 2 steps. And do the 3rd last step itself.
The job of the decoder is to based on the NPL compiled down to a AST (Abstract Syntax Tree) use the Visitor pattern to traverse each node of the the AST and perform neccessary actions. These actions result in the creation of Packet, Header and Field objects which read data from the capture stream and advance it appropriately.
The main method is the nextPacket() method which returns Packet object which is the decoded packet created based on the values of the capture stream.
| Field Summary | |
|---|---|
static int |
DEBUG_DEFAULT
Internal debugging flag. |
static int |
DEBUG_STREAM
Internal debuggin flag. |
static java.lang.String |
DO_REASSEMBLY
Name of the variable that set the DO_REASSEMBLY property. |
static int |
DO_REASSEMBLY_DEFAULT
|
static java.lang.String |
PACKET_INDEX
The name of the packet index property. |
| Constructor Summary | |
|---|---|
Decoder()
|
|
Decoder(PacketInputStream captureStream)
Constructor that just requires a capture PacketInputStream. |
|
Decoder(PacketInputStream in,
java.io.InputStream protocolNplDef)
Constructor takes a capture file name. |
|
Decoder(PacketInputStream in,
java.util.List protocolFiles)
Constructor takes a capture file name. |
|
Decoder(PacketInputStream in,
java.util.List protocolFiles,
java.lang.String watchVariable)
Constructor takes a capture file name. |
|
Decoder(java.lang.String captureFile)
Constructor that just requires a capture file name. |
|
Decoder(java.lang.String captureFile,
java.util.List nplFiles,
java.util.List captureFormatFiles)
Constructor takes a capture file name. |
|
| Method Summary | |
|---|---|
void |
addListener(DecoderListener listener)
Add listeners for events. |
void |
addListener(DecoderListener listener,
java.lang.String eventType)
Add listeners for events for specific event. |
void |
close()
Closes the file or input stream. |
boolean |
enableFlowKeys(boolean state)
Sets a flat if flowkeys should be generated for packets. |
protected void |
exportGlobalProperties(Context global)
Utitility method which exports automatic properties. |
protected void |
exportPacketProperties(Context packet,
MutablePacket mpacket)
Utitility method which exports automatic properties. |
PacketInputStream.BufferedHeader |
getFileHeader()
|
PacketInputStream.BufferedHeader |
getRecordHeader()
|
boolean |
isCompressed()
Is file or stream in compressed format. |
boolean |
isEnableFlowKeys()
Returns if flow keys are being created or not. |
boolean |
isIgnoreDefaultCandidate()
Should "Data" or another default header be used. |
boolean |
isUserSubheaders()
A flag that indicates wheather sub headers of headers are merged or added to preserve the hierarchy. |
protected StatementContainer |
lookupTopLevelHeader(java.lang.String name)
Utility method that looks up the name of a NPL header definition at the top of the AST (Abstract Syntax Tree). |
Packet |
nextPacket()
Decode the next packet based on previously initialized PacketInputStream and the parsed NPL AST. |
Packet |
nextPacketWithEOP()
Processes the next packet in the packet-byte-stream. |
PacketInputStream |
openCaptureFile(java.lang.String file)
Open capture file using a list of format files. |
void |
openForDecode(java.lang.String captureFile)
|
protected Packet |
readNextPacket()
Processes the next packet in the packet-byte-stream. |
void |
setDebugHeaders(boolean state)
|
void |
setIgnoreDefaultCandidate(boolean ignore)
Should "Data" or another default header be used. |
void |
setUseSubheaders(boolean keep)
Sets a flag in the decoder to tell it what to do with sub headers of headers. |
boolean |
traverse(AssertStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(BreakStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(BufferStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(ContinueStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(FamilyStatement stat,
java.lang.Object user1,
java.lang.Object user2)
Visitor pattern for FamilyStatement. |
boolean |
traverse(FieldStatement stat,
java.lang.Object user1,
java.lang.Object user2)
FIELD STATEMENT |
boolean |
traverse(FlowentryStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(FlowkeyStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(FlowpairStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(ForStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(HeaderStatement stat,
java.lang.Object user1,
java.lang.Object user2)
Visitor pattern for HeaderStatement. |
boolean |
traverse(IfStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(LinkStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(OpNode node,
java.lang.Object user1,
java.lang.Object user2)
Convenience function that dispatches visitor to all nodes in the list. |
boolean |
traverse(PrintStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(ProcessStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(PropertyStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
boolean |
traverse(VariableStatement stat,
java.lang.Object user1,
java.lang.Object user2)
Visitor pattern. |
boolean |
traverse(WhileStatement stat,
java.lang.Object user1,
java.lang.Object user2)
|
protected void |
updateProperty(java.lang.String name,
Context context,
int value)
Utility method which updates the value of an existing property. |
protected void |
updateProperty(java.lang.String name,
Context context,
IpAddress value)
Utility method which updates the value of an existing property. |
protected void |
updateProperty(java.lang.String name,
Context context,
long value)
Utility method which updates the value of an existing property. |
protected void |
updateProperty(java.lang.String name,
Context context,
java.lang.String value)
Utility method which updates the value of an existing property. |
protected void |
updateProperty(java.lang.String name,
Context context,
java.sql.Timestamp value)
Utility method which updates the value of an existing property. |
| Methods inherited from class com.voytechs.jnetstream.npl.Visitor |
|---|
traverse, traverse, traverse, traverse, traverse, traverse, traverse, traverse, visit |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEBUG_DEFAULT
public static final int DEBUG_STREAM
public static final java.lang.String DO_REASSEMBLY
public static final int DO_REASSEMBLY_DEFAULT
public static final java.lang.String PACKET_INDEX
| Constructor Detail |
|---|
public Decoder()
public Decoder(java.lang.String captureFile)
throws java.io.FileNotFoundException,
java.io.IOException,
SyntaxError
in - Input capture stream with data to be decoded.
java.io.FileNotFoundException - If protocols.npl file could not be found.
java.io.IOException - Any I/O errors.
SyntaxError - Any syntax errors in the protocols.npl file are reported.
public Decoder(PacketInputStream captureStream)
throws java.io.IOException,
SyntaxError
captureStream - Input capture stream with data to be decoded.
java.io.IOException - Any I/O errors.
SyntaxError - Any syntax errors in the protocols.npl file are reported.
public Decoder(PacketInputStream in,
java.util.List protocolFiles,
java.lang.String watchVariable)
throws java.io.FileNotFoundException,
java.io.IOException,
SyntaxError
captureFile - Input capture file name with data to be decoded.nplFile - protocolFiles A list of protocol NPL files.watchVariable - A environment variable name which contains additional protocol
files to load.
java.io.FileNotFoundException - If protocols.npl file could not be found.
java.io.IOException - Any I/O errors.
SyntaxError - Any syntax errors in the protocols.npl file are reported.
public Decoder(PacketInputStream in,
java.io.InputStream protocolNplDef)
throws java.io.FileNotFoundException,
java.io.IOException,
SyntaxError
captureFile - Input capture file name with data to be decoded.protocolNplDef - protocol NPL definition input streamwatchVariable - A environment variable name which contains additional protocol
files to load.
java.io.FileNotFoundException - If protocols.npl file could not be found.
java.io.IOException - Any I/O errors.
SyntaxError - Any syntax errors in the protocols.npl file are reported.
public Decoder(PacketInputStream in,
java.util.List protocolFiles)
throws java.io.FileNotFoundException,
java.io.IOException,
SyntaxError
captureFile - Input capture file name with data to be decoded.nplFile - Main NPL file to use for decoding the capture stream.
java.io.FileNotFoundException - If protocols.npl file could not be found.
java.io.IOException - Any I/O errors.
SyntaxError - Any syntax errors in the protocols.npl file are reported.
public Decoder(java.lang.String captureFile,
java.util.List nplFiles,
java.util.List captureFormatFiles)
throws java.io.FileNotFoundException,
java.io.IOException,
SyntaxError
Constructor takes a capture file name. It performs a file open on the capture file. It uses the user supplied list of protocol NPL files and parses them to a AST Abstract Syntax Tree.
Also takes a list of capture fomat files. These are also searched using same algorithm as the protocol NPL file.
captureFile - Input capture file name with data to be decoded.nplFiles - List of NPL files to use for decoding the capture stream.captureFormatFiles - List of NPL capture format files to use for decoding the
capture files.
java.io.FileNotFoundException - If protocols.npl file could not be found.
java.io.IOException - Any I/O errors.
SyntaxError - Any syntax errors in the protocols.npl file are reported.| Method Detail |
|---|
public void openForDecode(java.lang.String captureFile)
throws java.io.FileNotFoundException,
java.io.IOException,
SyntaxError
java.io.FileNotFoundException
java.io.IOException
SyntaxErrorpublic void setDebugHeaders(boolean state)
public PacketInputStream.BufferedHeader getFileHeader()
public PacketInputStream.BufferedHeader getRecordHeader()
public boolean enableFlowKeys(boolean state)
state - true means flowkeys will be created, otherwise no.
public boolean isEnableFlowKeys()
public PacketInputStream openCaptureFile(java.lang.String file)
throws java.io.FileNotFoundException,
java.io.IOException
Open capture file using a list of format files. The each format of the files is checked and appropriate File reader is used.
First the file is checked if its in GZIP format. If not then normal plain version is checked. File formats are assumed to be the default captureformats.npl file found in the config directory.
file - Filename to locate and open.captureFormatFiles - A list of capture format file names.
java.io.FileNotFoundException - if capture formats file is not found.
java.io.IOException - Any I/O errors.public void addListener(DecoderListener listener)
Add listeners for events.
listener - Listener for all events.
public void addListener(DecoderListener listener,
java.lang.String eventType)
Add listeners for events for specific event.
listener - Listener for specific event.eventType - Type of event to be dispatched on.
public Packet nextPacket()
throws StreamFormatException,
java.io.IOException,
SyntaxError
Decode the next packet based on previously initialized PacketInputStream and the parsed NPL AST.
SyntaxError - Any NPL syntax errors.
java.io.IOException - Any I/O errors.
StreamFormatException - Any problems with the capture stream.
public Packet nextPacketWithEOP()
throws NodeException,
EOPacketStream,
StreamFormatException,
java.io.IOException
Processes the next packet in the packet-byte-stream. A number of exceptions can be thrown by this method. A Packet object is returned containing all of the headers that could be parsed.
NodeException - Any AST errors that occured. A usefull check to see if
AssertionFailure exception occured.
EOPacketStream - Indicates no more packets in the current stream.
StreamFormatException - Stream is not formated properly.
java.io.IOException - any read/write errors that occured on thes tream.
protected Packet readNextPacket()
throws NodeException,
EOPacketStream,
StreamFormatException,
java.io.IOException
Processes the next packet in the packet-byte-stream. A number of exceptions can be thrown by this method. A Packet object is returned containing all of the headers that could be parsed.
NodeException - Any AST errors that occured. A usefull check to see if
AssertionFailure exception occured.
EOPacketStream - Indicates no more packets in the current stream.
StreamFormatException - Stream is not formated properly.
java.io.IOException - any read/write errors that occured on thes tream.
protected void exportPacketProperties(Context packet,
MutablePacket mpacket)
packet - Context to export this to.protected void exportGlobalProperties(Context global)
packet - Context to export this to.
protected void updateProperty(java.lang.String name,
Context context,
IpAddress value)
name - Name of the propertycontext - The context in which the property existsvalue - IP address to set for the property as new value.
protected void updateProperty(java.lang.String name,
Context context,
java.lang.String value)
name - Name of the propertycontext - The context in which the property existsvalue - String value set for the property as new value.
protected void updateProperty(java.lang.String name,
Context context,
int value)
name - Name of the propertycontext - The context in which the property existsvalue - Integer value set for the property as new value.
protected void updateProperty(java.lang.String name,
Context context,
long value)
name - Name of the propertycontext - The context in which the property existsvalue - Long integer value set for the property as new value.
protected void updateProperty(java.lang.String name,
Context context,
java.sql.Timestamp value)
name - Name of the propertycontext - The context in which the property existsvalue - Timestamp value set for the property as new value.
protected StatementContainer lookupTopLevelHeader(java.lang.String name)
throws NodeException
name - Name of the top level header to lookup starting at the root of
the AST.NodeException - If header is not found.
NodeException
public boolean traverse(FamilyStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(HeaderStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class Visitorstat - Header statement from the AST. It contains initialization
values and code for the body of the header statement.user1 - The parent object. It can be either a Packet or Header object.
Do a instanceof comparison method to find out which.user2 - Context in which we set our fields and variables.
NodeException - Any runtime errors.
public boolean traverse(VariableStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class Visitorstat - The variable statement with its initialization parameters and
expression.user1 - Object to which we belong to. Should be a Header.user2 - Context this variable exists in.
NodeException
public boolean traverse(FieldStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(AssertStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(BufferStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(ProcessStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(FlowkeyStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(FlowentryStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(FlowpairStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(LinkStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(OpNode node,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
Visitor
traverse in class VisitorNodeException
public boolean traverse(IfStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(ForStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(WhileStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(ContinueStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(BreakStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(PrintStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeException
public boolean traverse(PropertyStatement stat,
java.lang.Object user1,
java.lang.Object user2)
throws NodeException
traverse in class VisitorNodeExceptionpublic boolean isIgnoreDefaultCandidate()
public void setIgnoreDefaultCandidate(boolean ignore)
ignore - true ignores the default candidate, false the default candidate
usually the "Data" header is appended to all parent header's candidate
list.public boolean isUserSubheaders()
public void setUseSubheaders(boolean keep)
keep - The mergeHeaders to set.
true indicates that sub headers are merged with the parent
header and a single header remains. false indicates that
sub headers are added to parent sub header and complete
hierarchy as defined by the NPL definition remains.
public void close()
throws java.io.IOException
java.io.IOExceptionInputStream.close()public boolean isCompressed()
PacketInputStream.isCompressed()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||