com.slytechs.jnetstream.protocol
Class ProtocolRegistry

java.lang.Object
  extended by com.slytechs.jnetstream.protocol.ProtocolRegistry
Direct Known Subclasses:
LegacyProtocolRegistry

public abstract class ProtocolRegistry
extends java.lang.Object

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_CMD_DEFAULT
           
static java.lang.String BINDING_CMD_RESET
           
protected static LegacyProtocolRegistry defaultRegistry
           
 
Constructor Summary
protected ProtocolRegistry()
          The instantiation of ProtocolRegistry requires use of factory method ProtocolRegistry.getDefault().
 
Method Summary
abstract  Protocol findProtocol(java.lang.String name)
          Retrieves the specified protocol from the protocol repository.
static ProtocolRegistry getDefault()
          Gets the default protocol registery which contains a list of all the protocols and protocol bindings.
abstract  Protocol getProtocol(java.lang.String name)
          Retrieves the specified protocol from the protocol repository.
abstract  Iterable getProtocolBindings()
          Retruns an Iterable list of all the protocol bindings.
abstract  Iterable getProtocols()
          Returns an Iterable list of currently defined and known protocols.
abstract  void loadProtocolBinding(java.lang.String bindingExpression)
          Loads a single binding specified by the bindingExpression.
abstract  void loadProtocolBindings(java.io.File file)
          Loads protocol bindings from the specified url.
abstract  void loadProtocolBindings(java.io.InputStream in, java.lang.String filename)
          Loads protocol bindings from the specified reader.
abstract  void loadProtocolBindings(java.net.URL url)
          Loads protocol bindings from the specified url.
abstract  boolean resetProtocolBindings(java.lang.String name)
          Resets any bindings for the specified protocol.
abstract  void setSystemProtocolImplementationTypes(java.util.Set requestedSet)
          A user requested set of protocol implementations to use.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

defaultRegistry

protected static LegacyProtocolRegistry defaultRegistry

BINDING_CMD_DEFAULT

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

BINDING_CMD_RESET

public static final java.lang.String BINDING_CMD_RESET
See Also:
Constant Field Values
Constructor Detail

ProtocolRegistry

protected ProtocolRegistry()
The instantiation of ProtocolRegistry requires use of factory method ProtocolRegistry.getDefault().

Method Detail

loadProtocolBindings

public abstract 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. If there are any syntax errors in the stream, error warning will be logged and those entries skipped.

Parameters:
url - URL from which to load the binding definition file.
Throws:
java.io.IOException

loadProtocolBindings

public abstract 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. If there are any syntax errors in the stream, error warning will be logged and those entries skipped.

Parameters:
filename - File from which to load the bindings.
Throws:
java.io.IOException

loadProtocolBindings

public abstract void loadProtocolBindings(java.io.InputStream in,
                                          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. If there are any syntax errors in the stream, error warning will be logged and those entries skipped.

Parameters:
filename - Filename that will be reported if there are any errors.
Throws:
InvalidBindingFormat - Any problems with the syntax.
java.io.IOException

loadProtocolBinding

public abstract 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

Parameters:
bindingExpression - The expression to load the binding
Throws:
InvalidBindingFormat - Any syntax problems with the expression.
ProtocolNotFoundException - if either the source or the sink protocols are not found. In either case when this exception is thrown, no binding will be created at all.

getDefault

public static ProtocolRegistry getDefault()
Gets the default protocol registery which contains a list of all the protocols and protocol bindings.

Returns:
Default registery.

getProtocols

public abstract 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.

Returns:
List of protocols.

getProtocolBindings

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

Returns:
List of protocol bindings.

getProtocol

public abstract 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.

Parameters:
name - Name of the protocol to return.
Returns:
Returns the protocol if found, otherwise null.

findProtocol

public abstract 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.

Parameters:
name - Name of the protocol to return.
Returns:
Returns the protocol if found, otherwise null.

resetProtocolBindings

public abstract boolean resetProtocolBindings(java.lang.String name)

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.

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.

setSystemProtocolImplementationTypes

public abstract void setSystemProtocolImplementationTypes(java.util.Set requestedSet)

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.

Parameters:
requestedSet - A Set of ProtocolImplementationType enum constant objects to use a candidates for protocol implementations.