SourceForge.net Logo

org.netsnmp
Class NetSNMPSession

java.lang.Object
  |
  +--org.netsnmp.NetSNMPSession
All Implemented Interfaces:
Serializable

public class NetSNMPSession
extends Object
implements Serializable

A session with a remote agent. Data, as a PDU is sent to the remote agent. The remote agent will respond with a PDU

Author:
Andrew E. Page aepage@users.sourceforge.net
See Also:
Serialized Form

Nested Class Summary
static class NetSNMPSession.readInterrupt
          Deprecated.  
static interface NetSNMPSession.serialEncryption
           
 
Constructor Summary
NetSNMPSession()
          Creates a new instance of Session
NetSNMPSession(String peerName, String community)
          Creates and opens an SNMPv2c session to a remote host
 
Method Summary
 void addListener(NetSNMPAction listener)
          Adds a listener that responds to PDUs from the remote agents.
 NetSNMPAction deleteListener(NetSNMPAction listener)
          Delete the listenen from the list of listeners.
protected  void finalize()
           
 String getAuthPassword()
           
 String getCommunity()
           
 byte[] getContextEngineID()
           
 String getContextName()
           
 String getPeerName()
           
 String getPrivPassword()
           
 long getRcvMsgMaxSize()
           
 int getRetries()
           
 byte[] getSecurityAuthKey()
           
 OID getSecurityAuthOID()
           
 byte[] getSecurityEngineID()
           
 SecurityLevel getSecurityLevel()
           
 int getSecurityModel()
           
 String getSecurityName()
           
 byte[] getSecurityPrivKey()
           
 OID getSecurityPrivOID()
           
 Exception getSerializeException()
           
 long getSessionHandle()
          The session handle is the native pointer to data specific to this session.
 long getSndMsgMaxSize()
           
 SNMPVersion getSnmpVersion()
          Getter for property snmpVersion.
 long getTimeout()
           
 SNMPVersion getVersion()
           
 int hashCode()
           
static void interrupt()
          Deprecated.  
 boolean isOpen()
           
protected  void nativeFinalize()
           
 void open()
          Opens the session given the current set of properties
static void read(double timeout)
          Deprecated. operation has been moved to an internal thread. Further use is now an error
 void send(PDU thePdu, Object o)
          Sends the pdu to the peer
 void setAuthenticationProtocol(OID oid)
          Setter for authentication protocol corresponds to the -a option for snmpcmd(1)
 void setAuthPassword(String string)
           
 void setCommunity(String string)
           
 void setContextEngineID(byte[] bs)
           
 void setContextName(String string)
           
static NetSNMPSession.serialEncryption setDefaultEncryptor(NetSNMPSession.serialEncryption cryptor)
          Set a new default encryptor
 void setPeerName(String hostname)
          Format of the hostname can be as follows:
 void setPrivacyProtocol(OID oid)
          Setter for privacy protocol corresponds to the -x DES option for snmpcmd(1)
 void setPrivPassword(String string)
           
 void setRcvMsgMaxSize(long l)
           
 void setRetries(int i)
           
 void setSecurityAuthKey(byte[] bs)
           
 void setSecurityAuthOID(OID oid)
           
 void setSecurityEngineID(byte[] bs)
           
 void setSecurityLevel(SecurityLevel level)
           
 void setSecurityModel(int i)
           
 void setSecurityName(String string)
           
 void setSecurityPrivKey(byte[] key)
           
 void setSecurityPrivOID(OID oid)
           
 void setSerialEncryptor(NetSNMPSession.serialEncryption encryption)
          Sets the encryption object to use to encrypt/decrypt v1/v2 community names and v3 auth/priv passwords during serialization/deserialization
 void setSndMsgMaxSize(long size)
           
 void setSNMPVersion(SNMPVersion version)
           
 void setTimeout(long t)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetSNMPSession

public NetSNMPSession()
Creates a new instance of Session


NetSNMPSession

public NetSNMPSession(String peerName,
                      String community)
               throws IllegalStateException
Creates and opens an SNMPv2c session to a remote host

Parameters:
peerName - host name of the remote agent, may be in any format acceptable to net-snmp utilties. Typically in the format of

transport:hostname:portNumber

hostname:portNumber (defaults to UDP transport)

hostname (defaults to UDP transport and port 161)

community - community of the remote agent
Method Detail

addListener

public void addListener(NetSNMPAction listener)
Adds a listener that responds to PDUs from the remote agents. When a pdu is received by this session the NetSNMPAction.actionPerformed(int, org.netsnmp.NetSNMPSession, org.netsnmp.PDU, java.lang.Object) method is called

Parameters:
listener - object that implements the NetSNMPAction.actionPerformed(int, org.netsnmp.NetSNMPSession, org.netsnmp.PDU, java.lang.Object) method to process the information returned from the agent

deleteListener

public NetSNMPAction deleteListener(NetSNMPAction listener)
Delete the listenen from the list of listeners.

Parameters:
listener - listener to be deleted
Returns:
the listener deleted, null if not found. If not found listener list remains unchanged.

finalize

protected void finalize()
                 throws Throwable
Overrides:
finalize in class Object
Throwable

getAuthPassword

public String getAuthPassword()
Returns:
the authentication password in use

getCommunity

public String getCommunity()
Returns:
the community

getContextEngineID

public byte[] getContextEngineID()
Returns:
the context engine ID

getContextName

public String getContextName()
Returns:
context name in use

getPeerName

public String getPeerName()
Returns:
the peer name. This is the name of the remote agent

getPrivPassword

public String getPrivPassword()
Returns:
the privacy password in use

getRcvMsgMaxSize

public long getRcvMsgMaxSize()
Returns:

getRetries

public int getRetries()
Returns:

getSecurityAuthKey

public byte[] getSecurityAuthKey()
Returns:

getSecurityAuthOID

public OID getSecurityAuthOID()
Returns:

getSecurityEngineID

public byte[] getSecurityEngineID()
Returns:

getSecurityLevel

public SecurityLevel getSecurityLevel()
Returns:

getSecurityModel

public int getSecurityModel()
Returns:

getSecurityName

public String getSecurityName()
Returns:

getSecurityPrivKey

public byte[] getSecurityPrivKey()
Returns:

getSecurityPrivOID

public OID getSecurityPrivOID()
Returns:

getSerializeException

public Exception getSerializeException()
Returns:
exception generated the underlying session during serialization

getSessionHandle

public long getSessionHandle()
The session handle is the native pointer to data specific to this session. For debugging purposes it may be prudent to have access to it.

Returns:
the session handle

getSndMsgMaxSize

public long getSndMsgMaxSize()
Returns:

getSnmpVersion

public SNMPVersion getSnmpVersion()
Getter for property snmpVersion.

Returns:
Value of property snmpVersion.
See Also:
NetSNMP.SNMPv1, NetSNMP.SNMPv2c, NetSNMP.SNMPv3

getTimeout

public long getTimeout()
Returns:
the curreent timeout in microseconds

getVersion

public SNMPVersion getVersion()
Returns:
the SNMP protocol version in use

hashCode

public int hashCode()
Overrides:
hashCode in class Object
Returns:
a hash code that can be used for storing object in hashtable

isOpen

public boolean isOpen()
Returns:
true if the session is open

nativeFinalize

protected void nativeFinalize()

open

public void open()
          throws IllegalStateException
Opens the session given the current set of properties

Throws:
IllegalStateException - if the peername or community name have not been set, or the lookup on the peer fails

send

public void send(PDU thePdu,
                 Object o)
          throws NetSNMPSendError,
                 IllegalStateException
Sends the pdu to the peer

Parameters:
thePdu - pdu to send
o - object to be passed to the SNMPEventListener when a response to this pdu is received.
Throws:
NetSNMPSendError - if an error occurs in sending the pdu
IllegalStateException - if the session is not open

setAuthenticationProtocol

public void setAuthenticationProtocol(OID oid)
Setter for authentication protocol corresponds to the -a option for snmpcmd(1)

Parameters:
oid - Identifier for the authentication protocol to use
See Also:
NetSNMP.usmNoAuthOID, NetSNMP.usmMD5AuthOID, NetSNMP.usmSHAAuthOID

setAuthPassword

public void setAuthPassword(String string)
Parameters:
string - authorization password

setCommunity

public void setCommunity(String string)
Parameters:
string - the V1/V2c community

setContextEngineID

public void setContextEngineID(byte[] bs)
Parameters:
bs -

setContextName

public void setContextName(String string)
Parameters:
string -

setPeerName

public void setPeerName(String hostname)
Format of the hostname can be as follows:
 
transport:hostname:portNumber

hostname:portNumber (defaults to UDP transport)

hostname (defaults to UDP transport and port 161)

Parameters:
hostname - name of the remote agent to connect to

setPrivacyProtocol

public void setPrivacyProtocol(OID oid)
Setter for privacy protocol corresponds to the -x DES option for snmpcmd(1)

Parameters:
oid -
See Also:
NetSNMP.usmNoPrivOID, NetSNMP.usmDESPrivOID

setPrivPassword

public void setPrivPassword(String string)
Parameters:
string -

setRcvMsgMaxSize

public void setRcvMsgMaxSize(long l)
Parameters:
l -

setRetries

public void setRetries(int i)
Parameters:
i -

setSecurityAuthKey

public void setSecurityAuthKey(byte[] bs)
Parameters:
bs -

setSecurityAuthOID

public void setSecurityAuthOID(OID oid)
Parameters:
oid -

setSecurityEngineID

public void setSecurityEngineID(byte[] bs)
Parameters:
bs -

setSecurityLevel

public void setSecurityLevel(SecurityLevel level)
See Also:
NetSNMP.noAuth, NetSNMP.authNoPriv, NetSNMP.authPriv

setSecurityModel

public void setSecurityModel(int i)
Parameters:
i -

setSecurityName

public void setSecurityName(String string)
Parameters:
string - security name corresponds to the snmpget -u user option

setSecurityPrivKey

public void setSecurityPrivKey(byte[] key)
Parameters:
key - encryption key to use for V3 privacy correpsonds to the snmpget -X key option

setSecurityPrivOID

public void setSecurityPrivOID(OID oid)
Parameters:
oid - identifier of the privacy protocol to use
See Also:
NetSNMP.usmDESPrivOID

setSerialEncryptor

public void setSerialEncryptor(NetSNMPSession.serialEncryption encryption)
Sets the encryption object to use to encrypt/decrypt v1/v2 community names and v3 auth/priv passwords during serialization/deserialization

Parameters:
encryption - to use

setSndMsgMaxSize

public void setSndMsgMaxSize(long size)
Parameters:
size - largest message to send

setSNMPVersion

public void setSNMPVersion(SNMPVersion version)
Parameters:
version - sets the SNMPVersion to be used.
See Also:
NetSNMP.SNMPv1, NetSNMP.SNMPv2c, NetSNMP.SNMPv3

setTimeout

public void setTimeout(long t)
Parameters:
t - timeout in microseconds before the first timeout

interrupt

public static void interrupt()
Deprecated.  

Interupt the reading thread


read

public static void read(double timeout)
                 throws IOException,
                        NetSNMPSession.readInterrupt
Deprecated. operation has been moved to an internal thread. Further use is now an error

Reads on all pending SNMP operations on all currently open sessions

Parameters:
timeout - time in seconds to wait for an event(micro second) effective granularity
Returns:
whenever a read operation has been completed on at least 1 session
Throws:
an - IOException if an error occurs
IOException
NetSNMPSession.readInterrupt

setDefaultEncryptor

public static NetSNMPSession.serialEncryption setDefaultEncryptor(NetSNMPSession.serialEncryption cryptor)
Set a new default encryptor

Parameters:
cryptor - new default encyprtor
Returns:
previous encryptor

SourceForge.net Logo