org.opennms.protocols.icmpd
Class CtrlFilterMessage

java.lang.Object
  |
  +--org.opennms.protocols.icmpd.MessageHeader
        |
        +--org.opennms.protocols.icmpd.CtrlFilterMessage

public final class CtrlFilterMessage
extends MessageHeader

Defines the control filter message for filtering received icmp messages from a remote host. The format of the message is as follows:


 +--------+--------+----------------+
 |  TYPE  |  CODE  |   SEQUENCE     |
 +--------+--------+--------+-------+
 |     LENGTH      |FILTERON| ACTION|
 +-----------------+--------+-------+
 |           PACKET OFFSET          |
 +----------------------------------+
 |           FILTER LENGTH          |
 +----------------------------------+
 |            FILTER DATA           |
 |                                  |
 +----------------------------------+

 

Version:
0.1
Author:
Brian Weaver

Field Summary
static byte ACTION_DISCARD
          If the filter matches discard the datagram.
static byte ACTION_PASS
          If the filter matches return the datagram.
static byte CODE
          The code for the class.
static byte FILTER_ON_ICMP
          Filter on the ICMP message.
static byte FILTER_ON_IPHEADER
          Filter on the IP Header.
private  byte[] m_filterData
          The actual filter data.
private  int m_filterLen
          The valid length of the filter data
private  int m_packetOffset
          The offset into the icmp or ip header packet.
static byte TYPE
          The type for the class.
 
Fields inherited from class org.opennms.protocols.icmpd.MessageHeader
m_code, m_length, m_reserved, m_sequence, m_type, sm_seq, TYPE_CONTROL, TYPE_DATA
 
Constructor Summary
  CtrlFilterMessage()
          Creates a new control filter message for sending to the icmp daemon.
  CtrlFilterMessage(byte filterOn, byte action, int offset, byte[] data)
          Creates a new control filter message based on the passed parameters.
(package private) CtrlFilterMessage(MessageHeader hdr, InputStream istream)
          Creates a new control filter message based on the message header and the input stream.
 
Method Summary
private  void calculateLength()
           
 byte[] getFilter()
          Returns the encapsulated filter data.
 int getFilterLength()
          Returns the number of valid bytes of filter data
 int getOffset()
          Returns the starting offset for the filter when comparing it against retreived icmp messages or received ip headers.
 boolean isDiscardAction()
          Returns true if the filter is marked for discarding matched packets.
 boolean isICMPFilter()
          Returns true fi the filter is set to check ICMP messages.
 boolean isIPFilter()
          Returns true if the filter is set to check IP headers
 boolean isPassAction()
          Returns true if the filter is marked for sending matched packets.
 void setAction(byte action)
          Sets the action for the filter object.
 void setFilter(int offset, byte[] data)
          Sets the encapsulated filter data.
 void setFilterOn(byte filterOn)
          Sets teh filter field of the object.
(package private)  void write(OutputStream ostream)
          Seralizes the object to the icmp daemon using the passed connection stream.
 
Methods inherited from class org.opennms.protocols.icmpd.MessageHeader
align4, getCode, getLength, getSequence, getType, makeInt, makeShort, nextSequenceId, read, setSequence
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

TYPE

public static final byte TYPE
The type for the class.

CODE

public static final byte CODE
The code for the class.

FILTER_ON_IPHEADER

public static final byte FILTER_ON_IPHEADER
Filter on the IP Header.

FILTER_ON_ICMP

public static final byte FILTER_ON_ICMP
Filter on the ICMP message.

ACTION_DISCARD

public static final byte ACTION_DISCARD
If the filter matches discard the datagram.

ACTION_PASS

public static final byte ACTION_PASS
If the filter matches return the datagram.

m_packetOffset

private int m_packetOffset
The offset into the icmp or ip header packet.

m_filterData

private byte[] m_filterData
The actual filter data.

m_filterLen

private int m_filterLen
The valid length of the filter data
Constructor Detail

CtrlFilterMessage

public CtrlFilterMessage()
Creates a new control filter message for sending to the icmp daemon. The values in the object are set to the default value. The offset is set to zero and the data field to null. By default the filter is set to icmp and action is pass.

CtrlFilterMessage

CtrlFilterMessage(MessageHeader hdr,
                  InputStream istream)
            throws IOException
Creates a new control filter message based on the message header and the input stream. If the stream encounters an error or there is insufficent data then an IOException is thrown. If the header is not valid then an IllegalArgumentException is thrown.
Parameters:
hdr - The message header.
istream - The input stream containing the reamining data.
Throws:
IOException - Thrown if an error occurs with the input stream
IllegalArgumentException - Thrown if the header is not valid.

CtrlFilterMessage

public CtrlFilterMessage(byte filterOn,
                         byte action,
                         int offset,
                         byte[] data)
Creates a new control filter message based on the passed parameters.
Parameters:
filterOn - Filter on IP header or ICMP data.
action - Pass or Discard matched packets.
offset - The offset into the packet.
data - The filter data.
Method Detail

calculateLength

private void calculateLength()

isIPFilter

public boolean isIPFilter()
Returns true if the filter is set to check IP headers

isICMPFilter

public boolean isICMPFilter()
Returns true fi the filter is set to check ICMP messages.

setFilterOn

public void setFilterOn(byte filterOn)
Sets teh filter field of the object. The filterOn parameter should be either FILTER_ON_IPHEADER || FILTER_ON_ICMP.
Parameters:
filterOn - The part of the received message to perform filtering on.

setFilter

public void setFilter(int offset,
                      byte[] data)
Sets the encapsulated filter data. When the method is called the passed data is copied so that any changes after the call to the data parameter will not affect the object.
Parameters:
offset - The offset into the packet.
data - The comparison data.

getFilter

public byte[] getFilter()
Returns the encapsulated filter data. The length of the data will alsways be an integral multiple of 4 (i.e. (length % 4) == 0). The actual number of valid bytes can be determined with a call to getFilterLength() method.
Returns:
The array of bytes containing the filter data
See Also:
getFilterLength()

getFilterLength

public int getFilterLength()
Returns the number of valid bytes of filter data

getOffset

public int getOffset()
Returns the starting offset for the filter when comparing it against retreived icmp messages or received ip headers.
Returns:
the 32-bit offset.

isDiscardAction

public boolean isDiscardAction()
Returns true if the filter is marked for discarding matched packets.

isPassAction

public boolean isPassAction()
Returns true if the filter is marked for sending matched packets.

setAction

public void setAction(byte action)
Sets the action for the filter object. The action should be on of the two values: ACTION_PASS || ACTION_DISCARD.
Parameters:
byte - The action to be performed by the filter.

write

void write(OutputStream ostream)
     throws IOException
Seralizes the object to the icmp daemon using the passed connection stream.
Overrides:
write in class MessageHeader
Parameters:
ostream - The connection sink.
Throws:
IOException - Thrown if an I/O error occurs.