FileDocCategorySizeDatePackage
SnmpPeer.javaAPI DocJava SE 5 API15280Fri Aug 26 14:55:04 BST 2005com.sun.jmx.snmp

SnmpPeer

public class SnmpPeer extends Object implements Serializable
Holds information about an SNMP agent. This information is used to communicate with the agent. These are the IP address, port number, SNMP parameters, and peer channel parameters (such as the maximum request packet size, maximum number of variable bindings in a packet, retries, and timeouts). Changing these would affect all active requests.

The class contains the following properties:

  • destPort: port number of the destination host.
    The default port is 161.
  • maxVarBindLimit: maximum number of OIDs which can be encoded in a single request packet. This is set by the user.
    A request which contains more than this limit will be automatically split into multiple requests. Typically used when multiplexing requests.
    The default value is 25.
  • maxSnmpPacketSize: maximum packet size of the request PDU. This can be set by the user.
    If the request crosses this limit while encoding, the request is automatically split into multiple small requests. Each of these requests will again be within this limit.
    The default value is (2 * 1024).
  • maxTries: number of times to try before giving up.
    The default number is 3.
  • timeout: amount of time to wait for a response from the peer. If this amount of time passes without a response, and if the maxTries value has not been exceeded, the request will be resent.
    The default amount of time is 3000 milliseconds.
  • snmpParameters: SNMP parameters to be used when communicating with the agent. The parameters contain the protocol version and security information (the parameters can be shared amongst several peers).
JavaBean compliant getters and setters allow the properties listed above to be modified.

This API is a Sun Microsystems internal API and is subject to change without notice.

see
com.sun.jmx.snmp.SnmpParameters

Fields Summary
public static int
defaultSnmpRequestPktSize
The default SNMP packet size of an SNMP request (2 * 1024).
The maximum size is initially set to Ethernet maximum transfer unit (MTU).
public static int
defaultSnmpResponsePktSize
The default SNMP packet size of an SNMP response (8 * 1024).
This will be the default size that the session socket uses when receiving a packet.
private int
maxVarBindLimit
The maximum number of variable bindings that can be packed into a request. The default value is 25.
private int
portNum
Port number of the destination host. The default port is 161.
private int
maxTries
Number of times to try before giving up. The default number is 3.
private int
timeout
The amount of time to wait for a response from the peer. The default amount of time is 3000 millisec.
private com.sun.jmx.snmp.SnmpPduFactory
pduFactory
The PDU factory. The default factory is an instance of SnmpPduFactoryBER.
private long
_maxrtt
The maximum round trip time for a packet with the peer.
private long
_minrtt
The minimum round trip time for a packet with the peer.
private long
_avgrtt
The average round trip time for a packet with the peer.
private SnmpParams
_snmpParameter
SNMP parameters for this peer are valid for all requests using this peer.
private InetAddress
_devAddr
Internet address of the peer to be used when communicating with the peer.
private int
maxSnmpPacketSize
Maximum packet size of the request PDU. This can be set by the user. If the request crosses this limit while encoding, the request is automatically split into multiple small request. Each of these requests will again be within this limit. The default value is (2 * 1024).
InetAddress[]
_devAddrList
List of alternate addresses.
int
_addrIndex
The index of address currently being used.
private boolean
customPduFactory
Constructors Summary
public SnmpPeer(String host)
Creates an SNMP peer object for a device. The default port is 161.

param
host The peer name.
exception
UnknownHostException If the host name cannot be resolved.

    
    // CONSTRUCTORS
    //-------------
    
                                    
         
        this(host, (int)161) ;
    
public SnmpPeer(InetAddress netaddr, int port)
Creates an SNMP peer object for a device. The default port is 161.

param
netaddr The peer InetAddress.
param
port The port number.

        _devAddr = netaddr ;
        portNum = port;
   
public SnmpPeer(InetAddress netaddr)
Creates an SNMP peer object for a device. The default port is 161.

param
netaddr The peer InetAddress.

        _devAddr = netaddr ;
     
public SnmpPeer(String host, int port)
Creates an SNMP peer object for a device with the specified port.

param
host The peer name.
param
port The port number.
exception
UnknownHostException If the host name cannot be resolved.

        useIPAddress(host) ;
        portNum = port;
    
Methods Summary
public booleanallowSnmpSets()
Determines whether an SNMP set operation is allowed with this peer object. For now it just makes sure a parameter is configured for a write operation.

return
true if SNMP set is allowed and the parameter is configured, false otherwise.

        return _snmpParameter.allowSnmpSets() ;
    
public booleanequals(java.lang.Object obj)
Compares the two peer objects to determine whether they are the same. This is used to determine whether requests can be multiplexed.

param
obj The object to compare this with.
return
true if they are referring to same peer and using same address; false otherwise.

        if (this == obj)
            return true ;
        /*
          if (obj instanceof SnmpPeer) {
          SnmpPeer peer = (SnmpPeer) obj ;
          if (_devAddr.equals(peer.getDestAddr()) && 
          portNum == peer.getDestPort())
          return true ;
          }
        */
        return false ;
    
public voidfinalize()
Finalizer of the SnmpPeer objects. This method is called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

Sets all the references to this SNMP peer object to null.

        _devAddr = null ;
        _devAddrList = null ;
        _snmpParameter = null ;
    
public longgetAvgRtt()
Gets the average round trip time for a packet with the peer.

return
The average round trip time for a packet with the peer.

        return _avgrtt ;
    
public final java.net.InetAddressgetDestAddr()
Gets the InetAddress object for this peer.

return
The InetAddress of the peer.

        return _devAddr ;
    
public final java.net.InetAddress[]getDestAddrList()
Gets the list of alternate InetAddress configured for this peer.

return
The InetAddress of the peer.

        return _devAddrList;
    
public final intgetDestPort()
Gets the destination port number of the peer to which SNMP requests are to be sent.

return
The destination port number.

        return portNum ;
    
public final java.lang.StringgetDevName()
Gets the name specified in the constructor while creating this object.

return
The name of the host as specified while creating this object.

        return getDestAddr().getHostName() ;
    
public longgetMaxRtt()
Gets the maximum round trip time for a packet with the peer.

return
The maximum round trip time for a packet with the peer.

        return _maxrtt ;
    
public final intgetMaxSnmpPktSize()
Gets the maximum request packet size that is currently used.

return
The maximum request packet size.

        return maxSnmpPacketSize ;
    
public final intgetMaxTries()
Gets the number of times to try before giving up.

return
The maximun number of tries.

        return maxTries;
    
public longgetMinRtt()
Gets the minimum round trip time for a packet with the peer.

return
The minimum round trip time for a packet with the peer.

        return _minrtt ;
    
public SnmpParamsgetParams()
Gets the SnmpParams object associated with the peer.

return
The associated parameters.

	return _snmpParameter;
    
public final intgetTimeout()
Gets the timeout to wait for a response from the peer.

return
The value of the timeout property.

        return timeout;
    
public final synchronized intgetVarBindLimit()
Gets the maximum number of variable bindings that can be sent to a peer.

return
The maximum variable bindings that can be encoded into a request packet.

        return maxVarBindLimit ;
    
public final synchronized java.lang.StringipAddressInUse()
Returns the dot-formatted IP address string (for example 171.69.220.224). Useful when you want to know which IP address is used when the address was resolved using a DNS name.

return
The dot-formatted IP address being used.

        byte [] adr = _devAddr.getAddress() ;
        return
	    (adr[0]&0xFF) + "." + (adr[1]&0xFF) + "." + 
	    (adr[2]&0xFF) + "." + (adr[3]&0xFF);
    
booleanisCustomPduFactory()

	return customPduFactory;
    
public final synchronized voidsetDestPort(int newPort)
Changes the port address of the destination for the request.

param
newPort The destination port.

        portNum = newPort ;
    
public final synchronized voidsetMaxSnmpPktSize(int newsize)
Configures the maximum packet size that can be used when generating an SNMP request.

param
newsize The desired packet size.

        maxSnmpPacketSize = newsize ;
    
public final synchronized voidsetMaxTries(int newMaxTries)
Changes the maximun number of times to try before giving up.

param
newMaxTries The maximun number of tries.

        if (newMaxTries < 0)
            throw new IllegalArgumentException();
        maxTries= newMaxTries;
    
public voidsetParams(SnmpParams params)
Sets the SnmpParams object associated with the peer.

param
params The desired parameters.

	_snmpParameter = params;
    
public final synchronized voidsetTimeout(int newTimeout)
Changes the timeout to wait for a response from the peer.

param
newTimeout The timeout (in milliseconds).

        if (newTimeout < 0)
            throw new IllegalArgumentException();
        timeout= newTimeout;
    
public final synchronized voidsetVarBindLimit(int limit)
Configures the maximum number of variable bindings that can be sent to a peer.

param
limit The desired limit.

        maxVarBindLimit = limit ;
    
public java.lang.StringtoString()
Returns the String representation for this SnmpPeer.

return
The String representation.

        return "Peer/Port : " + getDevName() + "/" + getDestPort() ;
    
private voidupdateRttStats(long tm)

        if (_minrtt > tm)
            _minrtt = tm ;
        else if (_maxrtt < tm)
            _maxrtt = tm ;
        else
            _avgrtt = tm ;  // to do later.
    
public final synchronized voiduseAddressList(java.net.InetAddress[] adrList)
Specifies the list of addresses to be used. When a host is not responding the user can switch to the next address by calling useNextAddress.

param
adrList The list of InetAddresses.

        _devAddrList = adrList ;
        _addrIndex = 0 ;
        useNextAddress() ;
    
public final synchronized voiduseIPAddress(java.lang.String ipaddr)
Sets a specific IP address to which the peer will communicate. Typically used to set an alternate IP address or a specific address which is known to respond to requests. The IP address String can either be a machine name, such as ibiza, or a String representing its IP address, such as "206.26.48.100".

param
ipaddr Dot formatted IP address or logical host name.
exception
UnknownHostException If the host name cannot be resolved.

        _devAddr = InetAddress.getByName(ipaddr) ;
    
public final synchronized voiduseNextAddress()
Causes all subsequent requests to go to the new address obtained from the specified list of alternate addresses. If it reaches the end of list, it starts again at the first address.

        if (_devAddrList == null)
            return ;
/* NPCTE fix for bug 4486059, esc 0 MR 03-August-2001 */
/*      if (_addrIndex > _devAddrList.length) */
	if (_addrIndex > _devAddrList.length-1)
/* end of NPCTE fix for bugid 4486059 */
            _addrIndex = 0 ;
        _devAddr = _devAddrList[_addrIndex++] ;