org.opennms.bb.dp.capsd.plugin
Class TestForDnsServer

java.lang.Object
  |
  +--org.opennms.bb.dp.capsd.plugin.TestForDnsServer
All Implemented Interfaces:
CapsdPlugin

public class TestForDnsServer
extends Object
implements CapsdPlugin

Tests if a node is a DNS server. Sends a DNS address request for localhost and expects a response of the IP address. The request is retries 3 times.

Version:
$Revision: 1.8 $
Author:
Sowmya, OpenNMS

Field Summary
private static String CAPABILITY_NAME
          The capability name.
private static int DEFAULT_PORT
          The port on which the host is checked to see if it supports DNS.
 
Constructor Summary
TestForDnsServer()
          The Default constructor.
 
Method Summary
 String getCapabilityName()
          Returns the capability string.
private  void getResponse(DNSAddressRequest request, DatagramSocket socket)
          Receives the data packet and retrieves the address from the packet.
 boolean isProtocolSupported(InetAddress host)
          Returns true if the address is a DNS server.
 boolean isProtocolSupported(InetAddress host, int port)
          returns true if the address is a DNS server and responds to DNS queries at the specified port
 boolean isProtocolSupported(InetAddress host, int port, String capName)
          returns true only if the address is a DNS server and the capability queried for is 'isDns' and if the interface answers a DNS query on the port number specified.
 boolean isProtocolSupported(InetAddress host, String capName)
          Returns true only if the address is a DNS server and the capability queried for is 'isDNS'
private  boolean isServer(InetAddress nserver, int port)
          Sends a DNS address request for 'localhost' - if a reply is received, the interface is a DNS server.
private  void sendRequest(DNSAddressRequest request, DatagramSocket socket, InetAddress nameServer, int port)
          Sends a DNSAddressRequest to the name server.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

CAPABILITY_NAME

private static final String CAPABILITY_NAME

The capability name.


DEFAULT_PORT

private static int DEFAULT_PORT

The port on which the host is checked to see if it supports DNS.

Constructor Detail

TestForDnsServer

public TestForDnsServer()

The Default constructor.

Method Detail

sendRequest

private void sendRequest(DNSAddressRequest request,
                         DatagramSocket socket,
                         InetAddress nameServer,
                         int port)
                  throws IOException

Sends a DNSAddressRequest to the name server.

Parameters:
request - The address request to send to the name server.
socket - The datagram socket the request is sent on.
nameServer - The nameserver address for the packet destination.
port - The port number to send the address.
Throws:
IOException - Thrown if an error occurs while sending the datagram packet.

getResponse

private void getResponse(DNSAddressRequest request,
                         DatagramSocket socket)
                  throws IOException

Receives the data packet and retrieves the address from the packet.

Parameters:
request - the DNSAddressRequest whose response is to be got
socket - the socket on which the response is recieved
Throws:
IOException - Thrown if response is not decoded as expected.

isServer

private boolean isServer(InetAddress nserver,
                         int port)

Sends a DNS address request for 'localhost' - if a reply is received, the interface is a DNS server.

Returns:
True if server, false if not.

isProtocolSupported

public boolean isProtocolSupported(InetAddress host)

Returns true if the address is a DNS server.

Specified by:
isProtocolSupported in interface CapsdPlugin
Returns:
True if DNS server, false otherwise

isProtocolSupported

public boolean isProtocolSupported(InetAddress host,
                                   int port)
returns true if the address is a DNS server and responds to DNS queries at the specified port
Returns:
true if DNS server, false otherwise

isProtocolSupported

public boolean isProtocolSupported(InetAddress host,
                                   String capName)
                            throws UnsupportedProtocolException

Returns true only if the address is a DNS server and the capability queried for is 'isDNS'

Specified by:
isProtocolSupported in interface CapsdPlugin
Returns:
True if DNS server, false otherwise

isProtocolSupported

public boolean isProtocolSupported(InetAddress host,
                                   int port,
                                   String capName)
                            throws UnsupportedProtocolException

returns true only if the address is a DNS server and the capability queried for is 'isDns' and if the interface answers a DNS query on the port number specified.

Returns:
True if DNS server, false otherwise

getCapabilityName

public String getCapabilityName()

Returns the capability string.

Specified by:
getCapabilityName in interface CapsdPlugin
Returns:
The capbility name