OpenNMS API 1.1.5

org.opennms.netmgt.dhcpd
Class Poller

java.lang.Object
  extended byorg.opennms.netmgt.dhcpd.Poller

final class Poller
extends java.lang.Object

Establishes a TCP socket connection with the DHCP daemon and formats and sends request messages.

Version:
CVS 1.1.1.1
Author:
Mike , OpenNMS

Field Summary
(package private) static short BROADCAST_FLAG
          Broadcast flag...when set in the 'flags' portion of the DHCP DISCOVER packet forces the DHCP server to broadcast the DHCP OFFER response.
private static byte[] DEFAULT_ADDRESS
          The hardware address (ex: 00:06:0D:BE:9C:B2)
(package private) static int DEFAULT_RETRIES
          Default retries
(package private) static long DEFAULT_TIMEOUT
          Default timeout
private  java.net.Socket m_connection
          TCP Socket connection with DHCP Daemon
private  java.io.ObjectInputStream m_ins
          Objects from the server.
private static int m_nextXid
          Holds the value for the next identifier sent to the DHCP server.
private  java.io.ObjectOutputStream m_outs
          Output Object stream
private static int MESSAGE_TYPE
          The message type for the DHCP request.
private static byte[] s_hwAddress
           
 
Constructor Summary
private Poller(long timeout)
          Constructor.
 
Method Summary
 void close()
          Closes the client's socket connection to the DHCP daemon.
protected  void finalize()
          Ensures that during garbage collection the resources used by this object are released!
private static Message getDisconnectRequest()
          Returns a disconnection request message that can be sent to the server.
private static Message getPollingRequest(java.net.InetAddress addr)
          Returns a DHCP DISCOVER message that can be sent to the DHCP server.
(package private) static long isServer(java.net.InetAddress host, long timeout, int retries)
           This method actually tests the remote host to determine if it is running a functional DHCP server.
private static void setHwAddress(java.lang.String hwAddressStr)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_ADDRESS

private static final byte[] DEFAULT_ADDRESS
The hardware address (ex: 00:06:0D:BE:9C:B2)


s_hwAddress

private static byte[] s_hwAddress

BROADCAST_FLAG

static final short BROADCAST_FLAG
Broadcast flag...when set in the 'flags' portion of the DHCP DISCOVER packet forces the DHCP server to broadcast the DHCP OFFER response. Without this option set the server will unicast the packet back using the IP address specified in the OFFER response set as the destination. This packet will never reach the application since the IP stack will discard it because the destination address of the packet doesn't match the IP address of the interface.

See Also:
Constant Field Values

DEFAULT_RETRIES

static final int DEFAULT_RETRIES
Default retries

See Also:
Constant Field Values

DEFAULT_TIMEOUT

static final long DEFAULT_TIMEOUT
Default timeout

See Also:
Constant Field Values

MESSAGE_TYPE

private static final int MESSAGE_TYPE
The message type for the DHCP request.

See Also:
Constant Field Values

m_nextXid

private static int m_nextXid
Holds the value for the next identifier sent to the DHCP server.


m_connection

private java.net.Socket m_connection
TCP Socket connection with DHCP Daemon


m_outs

private java.io.ObjectOutputStream m_outs
Output Object stream


m_ins

private java.io.ObjectInputStream m_ins
Objects from the server.

Constructor Detail

Poller

private Poller(long timeout)
        throws java.io.IOException
Constructor. Establishes a TCP socket conection with the DHCP client daemon on port 5818.

Throws:
java.io.IOException - if unable to establish the connection with the DHCP client daemon.
Method Detail

getDisconnectRequest

private static Message getDisconnectRequest()
                                     throws java.net.UnknownHostException
Returns a disconnection request message that can be sent to the server.

Returns:
A disconnection message.
Throws:
java.net.UnknownHostException

getPollingRequest

private static Message getPollingRequest(java.net.InetAddress addr)
Returns a DHCP DISCOVER message that can be sent to the DHCP server. DHCP server should respond with a DHCP OFFER message in response.. NOTE: BROADCAST flag is set on the packet to force the server to broadcast the DHCP OFFER message. Without this flag the message will be unicasted back to the IP address specified in the OFFER and will be discarced by the IP stack never reaching the DHCP client daemon process.

Parameters:
addr - The address to poll
Returns:
The message to send to the DHCP server.

finalize

protected void finalize()
                 throws java.lang.Throwable
Ensures that during garbage collection the resources used by this object are released!

Throws:
java.lang.Throwable

close

public void close()
Closes the client's socket connection to the DHCP daemon.

Throws:
java.io.IOException - if the socket close() method fails.

isServer

static long isServer(java.net.InetAddress host,
                     long timeout,
                     int retries)
              throws java.io.IOException

This method actually tests the remote host to determine if it is running a functional DHCP server.

Formats a DHCP discover message and encodes it in a client request message which is sent to the DHCP daemon over the established TCP socket connection. If a matching DHCP response packet is not received from the DHCP daemon within the specified timeout the client request message will be re-sent up to the specified number of retries.

If a response is received from the DHCP daemon it is validated to ensure that:

If the response validates 'true' is returned. Otherwise the request is resent until max retry count is exceeded.

Before returning, a client disconnect message (remote host field set to zero) is sent to the DHCP daemon.

Returns:
response time in milliseconds if the specified host responded with a valid DHCP offer datagram within the context of the specified timeout and retry values or negative one (-1) otherwise.
Throws:
java.io.IOException

setHwAddress

private static void setHwAddress(java.lang.String hwAddressStr)

OpenNMS API 1.1.5

Generated by root on January 31 2005 0028.