org.opennms.protocols.icmpd
Class DataSendMessage

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

public final class DataSendMessage
extends MessageHeader

Defines the data send message for the transmission of an icmp message to a remote host. The icmp message is treated as an array of bytes and should be placed onto the wire raw by the daemon. The format of the message is as follows:

 +--------+--------+----------------+
 |  TYPE  |  CODE  |   SEQUENCE     |
 +--------+--------+----------------+
 |     LENGTH      |   ADDR LEN     |
 +-----------------+----------------+
 |            ADDRESS DATA          |
 |                                  |
 +----------------------------------+
 |            DATA LENGTH           |
 +----------------------------------+
 |            ICMP DATA             |
 |                                  |
 +----------------------------------+
 

Version:
0.1
Author:
Brian Weaver

Field Summary
static byte CODE
          The code for the message
private  byte[] m_addrData
           
private  byte[] m_data
           
private  int m_dataLen
           
static byte TYPE
          The type for the message
 
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
  DataSendMessage()
          Class constructor.
  DataSendMessage(InetAddress addr, byte[] icmp)
          Constructs a new DataSendMessage object with the specified IP address and ICMP data.
(package private) DataSendMessage(MessageHeader hdr, InputStream istream)
          Constructs a new object with the passed header and reads the remaining information from the passed input stream.
 
Method Summary
private  void calculateLength()
          Calculates the length of the packet based on the current values of the private fields.
 byte[] getAddress()
          Returns the byte array that contains the address data for the object.
 int getAddressLength()
          Returns the length of the IP address information.
 byte[] getData()
          Retreives the actual data encapsulated by the class.
 int getDataLength()
          Returns the length of the data encapsulated by the class.
 void setAddress(byte[] buf)
          Used to set the address data contained by the message object.
 void setAddress(InetAddress addr)
          Sets the address for the object.
 void setData(byte[] buf)
          Used to set the current data encapsulated by the class.
(package private)  void write(OutputStream ostream)
          Writes self to the passed output 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

m_addrData

private byte[] m_addrData

m_data

private byte[] m_data

m_dataLen

private int m_dataLen

TYPE

public static final byte TYPE
The type for the message

CODE

public static final byte CODE
The code for the message
Constructor Detail

DataSendMessage

public DataSendMessage()
Class constructor. Constructs a new object with the default information. When the object is constructed the next sequence number in the class is assigned to the object. By default the address is set to the IPv4 address "0.0.0.0".

DataSendMessage

DataSendMessage(MessageHeader hdr,
                InputStream istream)
          throws IOException
Constructs a new object with the passed header and reads the remaining information from the passed input stream. The header argument contains the first eight bytes of data for the class. The remaining data must be pulled from the input stream. If there is not enough data in the stream, or an error occurs with the stream, an IOException is thrown. Should the header have an invalid type or code then an IllegalArgumentException is thrown by the constructor.
Parameters:
hdr - The header object to copy into self.
istream - The stream containing the remaining data for the object.
Throws:
IOException - Thrown if an error occurs with the input stream or there is insufficent data returned from the stream.
IllegalArgumentException - Thrown if the header's type and code fields are not valid for the object.

DataSendMessage

public DataSendMessage(InetAddress addr,
                       byte[] icmp)
Constructs a new DataSendMessage object with the specified IP address and ICMP data.
Method Detail

getAddressLength

public int getAddressLength()
Returns the length of the IP address information. The address length is limited to 32767 bytes in length.
Returns:
The length of the address data.

getAddress

public byte[] getAddress()
Returns the byte array that contains the address data for the object. The length of the buffer will always be an integral multiple of 4 (i.e. 0, 4, 8, 12, ...). To find out exactly how many of the bytes are valid the application should call the getAddressLength() method.
Returns:
The address data array.
See Also:
getAddressLength()

setAddress

public void setAddress(byte[] buf)
Used to set the address data contained by the message object. The address data is copied into the object and the valid length is set to the length of the passed array.
Parameters:
buf - The address data.

setAddress

public void setAddress(InetAddress addr)
Sets the address for the object.
Parameters:
addr - The new address for the message.

getDataLength

public int getDataLength()
Returns the length of the data encapsulated by the class.
Returns:
The data length in bytes

getData

public byte[] getData()
Retreives the actual data encapsulated by the class. The array that is returned will always be an intergral of 4 in length (i.e. 0, 4, 8, 12, ...). The actual length of the valid data contained in the buffer can be retreived via a call to getDataLength().
Returns:
The encapsulated data buffer.
See Also:
getDataLength()

setData

public void setData(byte[] buf)
Used to set the current data encapsulated by the class. The length of the data is set to the length of the passed array. The bytes in the passed array are actually copied into the object. Any modifications after the call to the passed buffer will not affect the objects data.
Parameters:
buf - The buffer encapsulate in the object.

calculateLength

private void calculateLength()
Calculates the length of the packet based on the current values of the private fields. This value is updated in the super class member m_length.

write

void write(OutputStream ostream)
     throws IOException
Writes self to the passed output stream. This method serializes the class in the format desired for the icmp daemon.
Overrides:
write in class MessageHeader
Parameters:
ostream - The output stream to write self to.
Throws:
IOException - Thrown if an error occurs with the ostream object.