org.opennms.netmgt.ping
Class PingReply

java.lang.Object
  extended by org.opennms.netmgt.ping.PingReply
All Implemented Interfaces:
org.opennms.protocols.rt.Response, org.opennms.protocols.rt.ResponseWithId<PingRequestId>

public final class PingReply
extends Object
implements org.opennms.protocols.rt.ResponseWithId<PingRequestId>

This class is use to encapsulate an ICMP reply that conforms to the packetclass. The reply must be of type ICMP Echo Reply and be the correct length.

When constructed by the create method the returned reply encapsulates the sender's address and the received packet as final, non-mutable values for the instance.

Version:
$Id: $
Author:
Brian Weaver , Sowmya , OpenNMS , Brian Weaver , Sowmya , OpenNMS , Brian Weaver , Sowmya , OpenNMS

Constructor Summary
PingReply(InetAddress addr, org.opennms.protocols.icmp.ICMPEchoPacket pkt)
          Constructs a new reply with the passed address and packet as the contents of the reply.
 
Method Summary
static PingReply create(DatagramPacket packet)
           Creates a new instance of the class using the passed datagram as the data source.
 InetAddress getAddress()
          Returns the internet address of the host that sent the reply.
 short getIdentity()
          Returns the identity of the packet.
 org.opennms.protocols.icmp.ICMPEchoPacket getPacket()
          Returns the ICMP packet for the reply.
 PingRequestId getRequestId()
          getRequestId
 boolean isEchoReply()
          Returns true if the recovered packet is an echo reply.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PingReply

public PingReply(InetAddress addr,
                 org.opennms.protocols.icmp.ICMPEchoPacket pkt)
Constructs a new reply with the passed address and packet as the contents of the reply.

Parameters:
addr - The address of the ICMP sender.
pkt - The received packet.
Method Detail

isEchoReply

public boolean isEchoReply()
Returns true if the recovered packet is an echo reply.

Returns:
a boolean.

getIdentity

public final short getIdentity()
Returns the identity of the packet.

Returns:
a short.

getAddress

public final InetAddress getAddress()
Returns the internet address of the host that sent the reply.

Returns:
a InetAddress object.

getPacket

public final org.opennms.protocols.icmp.ICMPEchoPacket getPacket()
Returns the ICMP packet for the reply.

Returns:
a ICMPEchoPacket object.

getRequestId

public PingRequestId getRequestId()

getRequestId

Specified by:
getRequestId in interface org.opennms.protocols.rt.ResponseWithId<PingRequestId>
Returns:
a PingRequestId object.

create

public static PingReply create(DatagramPacket packet)

Creates a new instance of the class using the passed datagram as the data source. The address and ping packet are extracted from the datagram and returned as a new instance of the class. In addition to extracting the packet, the packet's received time is updated to the current time.

If the received datagram is not an echo reply or an incorrect length then an exception is generated to alert the caller.

Parameters:
packet - The packet with the ICMP datagram.
Returns:
a PingReply object.
Throws:
IllegalArgumentException - Throw if the datagram is not the correct length or type.
IndexOutOfBoundsException - Thrown if the datagram does not contain sufficent data.


Copyright © 2011. All Rights Reserved.