com.voytechs.jnetstream.protocol
Class LegacyProtocolRegistry

java.lang.Object
  extended by com.slytechs.jnetstream.protocol.ProtocolRegistry
      extended by com.voytechs.jnetstream.protocol.LegacyProtocolRegistry

public final class LegacyProtocolRegistry
extends ProtocolRegistry

Main protocol registry. The registry contains the master list of all known protocols and their bindings. You can iterate through each of the known protocols or iterate through all of the protocol bindings.

Protocol bindings define how each protocol is linked or bound to another. For example IP protocol is bound to Ethernet2 frame using etherenet's protocol field when the value of that field is 0x800 in hex. Any number of bindings can be specified for any given protocol. In our example above ip protocol is the source protocol (the one linking to) and Ethernet2 is the sink protocol (the one being linked to.)

 
 IPv4 = link Ethernet2 0x800 HTTP = link TCP sport == 80 || dport == 80
 
 

The registry also contains a list of all of the known protocols. You can retrieve them using the getProtocols() method. Not all the protocols may be loaded into the registry for efficiency. But all the protocols are discovered and Protocol object is created to represent, in somecases a place holder, for all of the known protocols. You can use the Protocol.isLoaded() method to find out if a protocol is actually loaded. Before any packets are dissected (parsed), none of the protocols may be loaded. Protocols may be loaded on demand only when needed. They may also be loaded upfront, this behaviour is release dependent and may be altered via global user accessible properties.

Since:
0.2.4
Author:
Mark Bednarczyk, Sly Technologies, Inc.

Field Summary
static java.lang.String BINDING_EXTENSION
           
protected  ProtocolLoader systemProtocolLoader
           
 
Fields inherited from class com.slytechs.jnetstream.protocol.ProtocolRegistry
BINDING_CMD_DEFAULT, BINDING_CMD_RESET, defaultRegistry
 
Constructor Summary
LegacyProtocolRegistry()
          Default constructor.
 
Method Summary
 Protocol findProtocol(java.lang.String name)
          Retrieves the specified protocol from the protocol repository.
 java.lang.String getDefaultBindingSource()
           
 Protocol getProtocol(java.lang.String name)
          Retrieves the specified protocol from the protocol repository.
 Iterable getProtocolBindings()
          Retruns an Iterable list of all the protocol bindings.
 Iterable getProtocols()
          Returns an Iterable list of currently defined and known protocols.
 ProtocolLoader getSystemProtocolLoader()
           
 void init()
          Because of objects in LegacyPR rely on ProtocolRegistry, we have delay their initialization until such time that a single default PR is created.
 boolean isResetBindings(java.lang.String name)
           
 void loadProtocolBinding(java.lang.String bindingExpression)
          Loads a single binding specified by the bindingExpression.
 void loadProtocolBindings(java.io.File file)
          Loads protocol bindings from the specified url.
 void loadProtocolBindings(java.io.InputStream in, java.lang.String filename)
          Loads protocol bindings from the specified reader.
 void loadProtocolBindings(java.io.Reader reader, java.lang.String filename)
          Loads protocol bindings from the specified reader.
 void loadProtocolBindings(java.net.URL url)
          Loads protocol bindings from the specified url.
 boolean resetProtocolBindings(java.lang.String name)
          Resets any bindings for the specified protocol.
 void setBindingLinked(NPLProtocolBinding binding, boolean linked)
           
 void setLinker(ProtocolLinker linker)
           
 void setResetBindings(java.lang.String name, boolean resetBindings)
           
 void setSystemProtocolImplementationTypes(java.util.Set requestedSet)
          A user requested set of protocol implementations to use.
 
Methods inherited from class com.slytechs.jnetstream.protocol.ProtocolRegistry
getDefault
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BINDING_EXTENSION

public static final java.lang.String BINDING_EXTENSION
See Also:
Constant Field Values

systemProtocolLoader

protected ProtocolLoader systemProtocolLoader
Constructor Detail

LegacyProtocolRegistry

public LegacyProtocolRegistry()
Default constructor. Does not initialize the Registry, that is done through the ProtocolRegistry.getDefault() method at an appropriate time, to prevent recursive calls to itself due to the fact that almost everything depends on this class.

Method Detail

getDefaultBindingSource

public java.lang.String getDefaultBindingSource()
Returns:
Returns the defaultBindingSource.

getProtocol

public Protocol getProtocol(java.lang.String name)
Retrieves the specified protocol from the protocol repository. Use the protocol's Protocol.isLoaded() method to find out if the protocol has actually been loaded. If the protocol does not exist this method will not search for it. Use ProtocolRegistry.findProtocol(String) if you want repository to search for it.

Specified by:
getProtocol in class ProtocolRegistry
Parameters:
name - Name of the protocol to return.
Returns:
Returns the protocol if found, otherwise null.

findProtocol

public Protocol findProtocol(java.lang.String name)
Retrieves the specified protocol from the protocol repository. Use the protocol's Protocol.isLoaded() method to find out if the protocol has actually been loaded. If the protocol does not exist in the repository it will search using the default ProtocolLoader for the protocol with the name.

Specified by:
findProtocol in class ProtocolRegistry
Parameters:
name - Name of the protocol to return.
Returns:
Returns the protocol if found, otherwise null.

getProtocolBindings

public Iterable getProtocolBindings()
Retruns an Iterable list of all the protocol bindings.

Specified by:
getProtocolBindings in class ProtocolRegistry
Returns:
List of protocol bindings.

getProtocols

public Iterable getProtocols()
Returns an Iterable list of currently defined and known protocols. The protocols may not neccessarily be loaded. Use the Protocol.isLoaded() method to find out if a protocol has been loaded.

Specified by:
getProtocols in class ProtocolRegistry
Returns:
List of protocols.

getSystemProtocolLoader

public ProtocolLoader getSystemProtocolLoader()
Returns:

init

public void init()
Because of objects in LegacyPR rely on ProtocolRegistry, we have delay their initialization until such time that a single default PR is created.


isResetBindings

public boolean isResetBindings(java.lang.String name)
Returns:
Returns the resetBindings.

loadProtocolBinding

public void loadProtocolBinding(java.lang.String bindingExpression)
                         throws InvalidBindingFormat,
                                ProtocolNotFoundException
Loads a single binding specified by the bindingExpression. The expression must be in the format protocol=binding statement

Specified by:
loadProtocolBinding in class ProtocolRegistry
Parameters:
bindingExpression - The expression to load the binding
Throws:
InvalidBindingFormat - Any syntax problems with the expression.
ProtocolNotFoundException

loadProtocolBindings

public void loadProtocolBindings(java.io.File file)
                          throws java.io.IOException
Loads protocol bindings from the specified url. The data must be in the format protocol=binding statement

Specified by:
loadProtocolBindings in class ProtocolRegistry
Parameters:
filename - File from which to load the bindings.
Throws:
InvalidBindingFormat - Any problems with the syntax.
java.io.IOException

loadProtocolBindings

public void loadProtocolBindings(java.io.InputStream in,
                                 java.lang.String filename)
                          throws java.io.IOException
Description copied from class: ProtocolRegistry
Loads protocol bindings from the specified reader. The data must be in the format protocol=binding statement. If there are any syntax errors in the stream, error warning will be logged and those entries skipped.

Specified by:
loadProtocolBindings in class ProtocolRegistry
filename - Filename that will be reported if there are any errors.
Throws:
java.io.IOException

loadProtocolBindings

public void loadProtocolBindings(java.io.Reader reader,
                                 java.lang.String filename)
                          throws java.io.IOException
Loads protocol bindings from the specified reader. The data must be in the format protocol=binding statement

Parameters:
filename - File from which to load the bindings.
Throws:
InvalidBindingFormat - Any problems with the syntax.
java.io.IOException
ProtocolNotFoundException

loadProtocolBindings

public void loadProtocolBindings(java.net.URL url)
                          throws java.io.IOException
Loads protocol bindings from the specified url. The data must be in the format protocol=binding statement

Specified by:
loadProtocolBindings in class ProtocolRegistry
Parameters:
filename - File from which to load the bindings.
Throws:
InvalidBindingFormat - Any problems with the syntax.
java.io.IOException

setLinker

public void setLinker(ProtocolLinker linker)
Parameters:
linker - The linker to set.

setResetBindings

public void setResetBindings(java.lang.String name,
                             boolean resetBindings)
Parameters:
resetBindings - The resetBindings to set.

resetProtocolBindings

public boolean resetProtocolBindings(java.lang.String name)
Description copied from class: ProtocolRegistry

Resets any bindings for the specified protocol. The specified protocol will have all of its bindings cleared. Any bindings that have been linked into the runtime environment, will be unlinked and removed.

Specified by:
resetProtocolBindings in class ProtocolRegistry
Parameters:
name - Protocol name to clear the binding for.
Returns:
it will true if protocol was found and even when protocol had no bindings. False will only be returned if the protocol was not found.

setBindingLinked

public void setBindingLinked(NPLProtocolBinding binding,
                             boolean linked)
Parameters:
b -

setSystemProtocolImplementationTypes

public void setSystemProtocolImplementationTypes(java.util.Set requestedSet)
Description copied from class: ProtocolRegistry

A user requested set of protocol implementations to use. Only these implementation types will be considered when making the decision which protocol implementation types to use during protocol loading and during the packet decoding process.

Changing this set will modify what is returned as available protocol implementations for each protocol using the Protocol.getAvailableProtocolImplementationTypes(). Only types as specified in this Set will be ever returned as available even if other types are available. Thus the user can explicitely force a particular implementation of a protocol only.

Default is to consider all implementation types as defined by the enum class ProtocolImplementationType.

Specified by:
setSystemProtocolImplementationTypes in class ProtocolRegistry
Parameters:
requestedSet - A Set of ProtocolImplementationType enum constant objects to use a candidates for protocol implementations.