OpenNMS API 1.2.3

org.opennms.netmgt.ping
Class Packet

java.lang.Object
  extended byorg.opennms.protocols.icmp.ICMPHeader
      extended byorg.opennms.netmgt.ping.Packet

public final class Packet
extends ICMPHeader

The ping packet for discovery

Version:
1.1.1.1
Author:
Brian Weaver , Sowmya , OpenNMS

Field Summary
private  byte[] m_pad
          Padding used to make the packet conform to the defacto unix ping program (56 bytes).
private  long m_recv
          Timestamp of when packet was received.
private  long m_rtt
          The ping rtt (microseconds)
private  long m_sent
          Timestamp when packet was sent
private  long m_tid
          The thread id of the sender.
private static byte[] NAMED_PAD
          Unique named padding that is placed in front of the incremental padding.
private static int PAD_SIZE
          This is the amount of padding required to make the ICMP echo request 56 bytes in length.
 
Fields inherited from class org.opennms.protocols.icmp.ICMPHeader
CODE_BAD_IP_HEADER, CODE_COMMUNICATIONS_ADMIN_PROHIBITIED, CODE_DESTINATION_HOST_ADMIN_PROHIBITED, CODE_DESTINATION_HOST_UNKNOWN, CODE_DESTINATION_NETWORK_ADMIN_PROHIBITED, CODE_DESTINATION_NETWORK_UNKNOWN, CODE_FRAGMENTATION_NEEDED, CODE_HOST_PRECEDENCE_VIOLATION, CODE_HOST_UNREACHABLE, CODE_HOST_UNREACHABLE_FOR_TOS, CODE_NETWORK_UNREACHABLE, CODE_NETWORK_UNREACHABLE_FOR_TOS, CODE_PORT_UNREACHABLE, CODE_PRECEDENCE_CUTOFF_IN_EFFECT, CODE_PROTOCOL_UNREACHABLE, CODE_REDIRECT_FOR_HOST, CODE_REDIRECT_FOR_NETWORK, CODE_REDIRECT_FOR_TYPE_OF_SERVICE_AND_HOST, CODE_REDIRECT_FOR_TYPE_OF_SERVICE_AND_NETWORK, CODE_REQUIRED_OPTION_MISSING, CODE_SOURCE_HOST_ISOLATED, CODE_SOURCE_ROUTE_FAILED, CODE_TTL_EQ_ZERO_IN_REASSEMBLY, CODE_TTL_EQ_ZERO_IN_TRANSIT, TYPE_ADDRESS_MASK_REPLY, TYPE_ADDRESS_MASK_REQUEST, TYPE_DESTINATION_UNREACHABLE, TYPE_ECHO_REPLY, TYPE_ECHO_REQUEST, TYPE_INFORMATION_REPLY, TYPE_INFORMATION_REQUEST, TYPE_PARAMETER_PROBLEM, TYPE_REDIRECT, TYPE_ROUTER_ADVERTISEMENT, TYPE_ROUTER_SOLICITATION, TYPE_SOURCE_QUENCH, TYPE_TIME_EXCEEDED, TYPE_TIMESTAMP_REPLY, TYPE_TIMESTAMP_REQUEST
 
Constructor Summary
private Packet()
          Private constructor to disallow default construction of an object.
  Packet(byte[] buf)
          Creates a new discovery ping packet from the passed buffer.
  Packet(long tid)
          Creates a new discovery ping packet that can be sent to a remote protocol stack.
 
Method Summary
private static long byteToLong(byte b)
          Converts a byte to a long and wraps the value to avoid sign extension.
 void computeChecksum()
          Computes and stores the current checksum based upon the data currently contained in the object.
static int getNetworkSize()
          Returns the network size for this packet.
 long getPingRTT()
          Gets the ping Round Trip Time
 long getReceivedTime()
          Gets the currently set received time.
 long getSentTime()
          Returns the time the packet was sent.
 long getTID()
          Returns the currently set Thread ID
 int loadFromBuffer(byte[] buf, int offset)
          Loads the data from the passed buffer into the current object.
 void setPingRTT(long time)
          Sets the ping Round Trip Time
 long setReceivedTime()
          Sets the recieved time for the packet.
 void setReceivedTime(long time)
          Sets the received time to the passed value.
 long setSentTime()
          Sets the sent time to the current time.
 void setSentTime(long time)
          Sets the sent time to the passed value.
 void setTID(long tid)
          Sets the current Thread Id
 int storeToBuffer(byte[] buf, int offset)
          Writes the objects data out to the specified buffer at the starting offset.
 byte[] toBytes()
          Converts the object into an array of bytes which is suitable for transmission to remote hosts.
 
Methods inherited from class org.opennms.protocols.icmp.ICMPHeader
byteToInt, byteToShort, computeChecksum, getChecksum, getCode, getIdentity, getSequenceId, getType, isEchoReply, isEchoRequest, nextSequenceId, setChecksum, setCode, setIdentity, setNextSequenceId, setSequenceId, setType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NAMED_PAD

private static final byte[] NAMED_PAD
Unique named padding that is placed in front of the incremental padding.


m_sent

private long m_sent
Timestamp when packet was sent


m_recv

private long m_recv
Timestamp of when packet was received.


m_tid

private long m_tid
The thread id of the sender. Effective key for the packet.


m_pad

private byte[] m_pad
Padding used to make the packet conform to the defacto unix ping program (56 bytes).


m_rtt

private long m_rtt
The ping rtt (microseconds)


PAD_SIZE

private static final int PAD_SIZE
This is the amount of padding required to make the ICMP echo request 56 bytes in length. This is just following the available code for ping ;)

See Also:
Constant Field Values
Constructor Detail

Packet

private Packet()
Private constructor to disallow default construction of an object.

Throws:
java.lang.UnsupportedOperationException - Always thrown.

Packet

public Packet(long tid)
Creates a new discovery ping packet that can be sent to a remote protocol stack. The ICMP type is set to an Echo Request. The next sequence in the ICMPHeader base class is set and the sent time is set to the current time.

Parameters:
tid - The thread id for the packet.
See Also:
System.currentTimeMillis()

Packet

public Packet(byte[] buf)
Creates a new discovery ping packet from the passed buffer.

Parameters:
buf - The buffer containing a refected ping packet.
Method Detail

byteToLong

private static long byteToLong(byte b)
Converts a byte to a long and wraps the value to avoid sign extension. The method essentially treats the value of 'b' as an 8-bit unsigned value for conversion purposes.

Parameters:
b - The byte to convert.
Returns:
The converted long value.

getSentTime

public final long getSentTime()
Returns the time the packet was sent.


setSentTime

public final long setSentTime()
Sets the sent time to the current time.

See Also:
System.currentTimeMillis()

setSentTime

public final void setSentTime(long time)
Sets the sent time to the passed value.

Parameters:
time - The new sent time.

getReceivedTime

public final long getReceivedTime()
Gets the currently set received time.


setReceivedTime

public final long setReceivedTime()
Sets the recieved time for the packet.

See Also:
System.currentTimeMillis()

setReceivedTime

public final void setReceivedTime(long time)
Sets the received time to the passed value.

Parameters:
time - The new received time.

setPingRTT

public final void setPingRTT(long time)
Sets the ping Round Trip Time


getPingRTT

public final long getPingRTT()
Gets the ping Round Trip Time


getNetworkSize

public static final int getNetworkSize()
Returns the network size for this packet. This is a combination of the headers size, plus the padding, and the IPHeader size.


computeChecksum

public final void computeChecksum()
Computes and stores the current checksum based upon the data currently contained in the object.

Overrides:
computeChecksum in class ICMPHeader

getTID

public final long getTID()
Returns the currently set Thread ID


setTID

public final void setTID(long tid)
Sets the current Thread Id


loadFromBuffer

public final int loadFromBuffer(byte[] buf,
                                int offset)
Loads the data from the passed buffer into the current object. Once loaded the object's values should reflect the contents of the buffer.

Overrides:
loadFromBuffer in class ICMPHeader
Parameters:
buf - The buffer to load from
offset - The offset to begin loading from
Returns:
The offset of the next byte of data that was not used to initialize this object.
Throws:
java.lang.IndexOutOfBoundsException - Thrown if there is not enough data contained in the buffer to sufficent set the state of the object

storeToBuffer

public final int storeToBuffer(byte[] buf,
                               int offset)
Writes the objects data out to the specified buffer at the starting offset. If the buffer does not have sufficent data to store the information then an IndexOutOfBoundsException is thrown.

Overrides:
storeToBuffer in class ICMPHeader
Parameters:
buf - The storage buffer.
offset - The location to start in buf.
Returns:
The new offset after storing to the buffer.
Throws:
java.lang.IndexOutOfBoundsException - Thrown if the buffer does not have enough storage space.

toBytes

public final byte[] toBytes()
Converts the object into an array of bytes which is suitable for transmission to remote hosts.

Overrides:
toBytes in class ICMPHeader
Returns:
The object as an array of bytes.

OpenNMS API 1.2.3

Generated by eevans on May 29 2005 2015.