Class SnmpContextv3Basis
- All Implemented Interfaces:
 Cloneable,Runnable,EventListener,RawPduListener,SnmpContextBasisFace,SnmpContextv3Face
- Direct Known Subclasses:
 SnmpContextv3,SnmpContextv3Discovery
 This class will perform the v3 discovery of the SNMP engine ID and
 time line if necessary. This is done with the classes
 TimeWindow and UsmDiscoveryBean.
 
Now that the stack can send traps and receive requests, it needs to be able to act as an authoritative SNMP engine. This is done via the interface UsmAgent. The DefaultUsmAgent is not guaranteed to work; agents (or rather authoritative engines) should provide a better implementation.
This class will use the User Security Model (USM) as described in SNMP-USER-BASED-SM-MIB. See also RFC 3411.
 It is advised to set all the properties of this class before any PDU,
 using this class, is sent. 
 All properties are being used to encode the message. Some properties are 
 being used to decode the Response or Report PDU. 
 When any of these last properties were changed in between flight there 
 is a possibility the decoding fails, causing a
 DecodingException. 
 
 destroy() should be called when the context is no longer
 used. This is the only way the threads will be stopped and garbage
 collected.
 
- Since:
 - 4_14
 - Version:
 - $Revision: 3.17 $ $Date: 2009/03/05 15:51:42 $
 - Author:
 - Birgit Arkesteijn
 - See Also:
 
- 
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intstatic final intstatic final intFields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace
DEFAULT_PORT, MAXPDU, MSS, STANDARD_SOCKET, TCP_SOCKETFields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextv3Face
AES_ENCRYPT, AES_PRIVACY_PROTOCOLS, AES192_ENCRYPT, AES256_ENCRYPT, AUTH_PROTOCOLS, DEFAULT_CONTEXT_NAME, DEFAULT_USERNAME, DES_ENCRYPT, MD5_PROTOCOL, NO_AUTH_PROTOCOL, PRIVACY_PROTOCOLS, PROTOCOL_NAMES, SHA1_PROTOCOL, SHA224_PROTOCOL, SHA256_PROTOCOL, SHA384_PROTOCOL, SHA512_PROTOCOL, SNMPv1_Security_Model, SNMPv2c_Security_Model, USM_Security_Model - 
Constructor Summary
ConstructorsConstructorDescriptionSnmpContextv3Basis(String host, int port) Constructor.SnmpContextv3Basis(String host, int port, String typeSocketA) Constructor.SnmpContextv3Basis(String host, int port, String bindAddress, String typeSocketA) Constructor. - 
Method Summary
Modifier and TypeMethodDescriptionbooleanAdds a discovery pdu.booleanAdds a PDU.voidaddRequestPduListener(RequestPduListener l, ListeningContextPool lcontext) Adds the specified request pdu listener to receive PDUs on the specified listening context that matches this context.cloneParameters(SnmpContextv3Face clContext) Copies all parameters into another SnmpContextv3.byte[]encodeDiscoveryPacket(byte msg_type, int rId, int errstat, int errind, Enumeration ve, Object obj) Encodes a discovery PDU packet.byte[]encodePacket(byte msg_type, int rId, int errstat, int errind, Enumeration ve, Object obj) Encodes a PDU.intReturns the protocol to be used for authentication.byte[]Returns the contextEngineID.Returns the contextName.Returns the hash key.intReturns the protocol to be used for privacy.Returns the user authentication password.Returns the username.Returns the user privacy password.Returns the UsmAgent.intReturns the SNMP version of this context.booleanReturns if authentication is used or not.booleanReturns if privacy is used or not.booleanremovePdu(int rid) Removes a PDU.voidsetAuthenticationProtocol(int protocol) Sets the protocol to be used for authentication.voidsetContextEngineId(byte[] newContextEngineId) Sets the contextEngineID.voidsetContextName(String newContextName) Sets the contextName.voidsetPrivacyProtocol(int protocol) Sets the protocol to be used for privacy.voidsetUseAuthentication(boolean newUseAuthentication) Sets whether authentication has to be used.voidsetUsePrivacy(boolean newUsePrivacy) Sets whether privacy has to be used.voidsetUserAuthenticationPassword(String newUserAuthPassword) Sets the user authentication password.voidsetUserName(String newUserName) Sets the username.voidsetUserPrivacyPassword(String newUserPrivacyPassword) Sets the user privacy password.voidsetUsmAgent(UsmAgent agent) Sets the UsmAgent, needed when this stack is used as authoritative SNMP engine.toString()Returns a string representation of the object.Methods inherited from class uk.co.westhawk.snmp.stack.AbstractSnmpContext
addRequestPduListener, addRequestPduListener, addTrapListener, addTrapListener, addTrapListener, clone, destroy, getBindAddress, getDebugString, getHost, getHostAddress, getMaxRecvSize, getPort, getReceivedFromHostAddress, getSendToHostAddress, getTypeSocket, isDestroyed, processIncomingPdu, rawPduReceived, removeRequestPduListener, removeRequestPduListener, removeRequestPduListener, removeTrapListener, removeTrapListener, removeTrapListener, run, sendPacket, setMaxRecvSize, stopMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace
addRequestPduListener, addRequestPduListener, addTrapListener, addTrapListener, addTrapListener, clone, destroy, getBindAddress, getHost, getPort, getReceivedFromHostAddress, getSendToHostAddress, getTypeSocket, isDestroyed, processIncomingPdu, removeRequestPduListener, removeRequestPduListener, removeRequestPduListener, removeTrapListener, removeTrapListener, removeTrapListener, sendPacket 
- 
Field Details
- 
AES128_KEY_LENGTH
public static final int AES128_KEY_LENGTH- See Also:
 
 - 
AES192_KEY_LENGTH
public static final int AES192_KEY_LENGTH- See Also:
 
 - 
AES256_KEY_LENGTH
public static final int AES256_KEY_LENGTH- See Also:
 
 
 - 
 - 
Constructor Details
- 
SnmpContextv3Basis
Constructor.- Parameters:
 host- The host to which the PDU will be sentport- The port where the SNMP server will be- Throws:
 IOException- See Also:
 - 
AbstractSnmpContext(String, int)
 
 - 
SnmpContextv3Basis
Constructor. Parameter typeSocketA should be either STANDARD_SOCKET, TCP_SOCKET or a fully qualified classname.- Parameters:
 host- The host to which the Pdu will be sentport- The port where the SNMP server will betypeSocketA- The local address the server will bind to- Throws:
 IOException- See Also:
 - 
AbstractSnmpContext(String, int, String)
 
 - 
SnmpContextv3Basis
public SnmpContextv3Basis(String host, int port, String bindAddress, String typeSocketA) throws IOException Constructor. Parameter typeSocketA should be either STANDARD_SOCKET, TCP_SOCKET or a fully qualified classname.- Parameters:
 host- The host to which the PDU will be sentport- The port where the SNMP server will bebindAddress- The local address the server will bind totypeSocketA- The type of socket to use.- Throws:
 IOException- Since:
 - 4_14
 - See Also:
 - 
AbstractSnmpContext(String, int, String)SnmpContextBasisFace.STANDARD_SOCKETSnmpContextBasisFace.TCP_SOCKET
 
 
 - 
 - 
Method Details
- 
getVersion
public int getVersion()Description copied from class:AbstractSnmpContextReturns the SNMP version of this context. Has to be overload by each context.- Specified by:
 getVersionin interfaceSnmpContextBasisFace- Specified by:
 getVersionin classAbstractSnmpContext- Returns:
 - The version
 - See Also:
 
 - 
getUserName
Returns the username.- Specified by:
 getUserNamein interfaceSnmpContextv3Face- Returns:
 - the username
 
 - 
setUserName
Sets the username. This username will be used for all PDUs sent with this context. The username corresponds to the 'msgUserName' in SNMP-USER-BASED-SM-MIB. The default value is "initial".- Specified by:
 setUserNamein interfaceSnmpContextv3Face- Parameters:
 newUserName- The new username- See Also:
 
 - 
isUseAuthentication
public boolean isUseAuthentication()Returns if authentication is used or not. By default no authentication will be used.- Specified by:
 isUseAuthenticationin interfaceSnmpContextv3Face- Returns:
 - true if authentication is used, false if not
 
 - 
setUseAuthentication
public void setUseAuthentication(boolean newUseAuthentication) Sets whether authentication has to be used. By default no authentication will be used.- Specified by:
 setUseAuthenticationin interfaceSnmpContextv3Face- Parameters:
 newUseAuthentication- The use of authentication
 - 
getUserAuthenticationPassword
Returns the user authentication password. This password will be transformed into the user authentication secret key.- Specified by:
 getUserAuthenticationPasswordin interfaceSnmpContextv3Face- Returns:
 - The user authentication password
 
 - 
setUserAuthenticationPassword
Sets the user authentication password. This password will be transformed into the user authentication secret key. A user MUST set this password.- Specified by:
 setUserAuthenticationPasswordin interfaceSnmpContextv3Face- Parameters:
 newUserAuthPassword- The user authentication password
 - 
setAuthenticationProtocol
Sets the protocol to be used for authentication. This can either be MD5 or SHA-1. By default MD5 will be used.- Specified by:
 setAuthenticationProtocolin interfaceSnmpContextv3Face- Parameters:
 protocol- The authentication protocol to be used- Throws:
 IllegalArgumentException- See Also:
 
 - 
getAuthenticationProtocol
public int getAuthenticationProtocol()Returns the protocol to be used for authentication. This can either be MD5 or SHA-1. By default MD5 will be used.- Specified by:
 getAuthenticationProtocolin interfaceSnmpContextv3Face- Returns:
 - The authentication protocol to be used
 - See Also:
 
 - 
setPrivacyProtocol
Sets the protocol to be used for privacy. This can either be DES or AES. By default DES will be used.- Specified by:
 setPrivacyProtocolin interfaceSnmpContextv3Face- Parameters:
 protocol- The privacy protocol to be used- Throws:
 IllegalArgumentException- See Also:
 
 - 
getPrivacyProtocol
public int getPrivacyProtocol()Returns the protocol to be used for privacy. This can either be DES or AES. By default DES will be used.- Specified by:
 getPrivacyProtocolin interfaceSnmpContextv3Face- Returns:
 - The privacy protocol to be used
 - See Also:
 
 - 
isUsePrivacy
public boolean isUsePrivacy()Returns if privacy is used or not. By default privacy is not used.- Specified by:
 isUsePrivacyin interfaceSnmpContextv3Face- Returns:
 - true if privacy is used, false if not
 
 - 
setUsePrivacy
public void setUsePrivacy(boolean newUsePrivacy) Sets whether privacy has to be used. By default privacy is not used. Note, privacy (encryption) without authentication is not allowed.- Specified by:
 setUsePrivacyin interfaceSnmpContextv3Face- Parameters:
 newUsePrivacy- The use of privacy
 - 
getUserPrivacyPassword
Returns the user privacy password. This password will be transformed into the user privacy secret key.- Specified by:
 getUserPrivacyPasswordin interfaceSnmpContextv3Face- Returns:
 - The user privacy password
 
 - 
setUserPrivacyPassword
Sets the user privacy password. This password will be transformed into the user privacy secret key. A user must set this password in order to use privacy.- Specified by:
 setUserPrivacyPasswordin interfaceSnmpContextv3Face- Parameters:
 newUserPrivacyPassword- The user privacy password
 - 
setContextEngineId
Sets the contextEngineID. See RFC 3411. A contextEngineID uniquely identifies an SNMP entity that may realize an instance of a context with a particular contextName.Note, when the stack is an authoritative engine, this parameter should equal the UsmAgent.getSnmpEngineId(). See the StackUsage documentation for an explanation.
If the contextEngineID is of length zero, the encoder will use the (discovered) snmpEngineId.
- Specified by:
 setContextEngineIdin interfaceSnmpContextv3Face- Parameters:
 newContextEngineId- The contextEngineID- Throws:
 IllegalArgumentException- See Also:
 
 - 
getContextEngineId
public byte[] getContextEngineId()Returns the contextEngineID.- Specified by:
 getContextEngineIdin interfaceSnmpContextv3Face- Returns:
 - The contextEngineID
 
 - 
setContextName
Sets the contextName. See RFC 3411. A contextName is used to name a context. Each contextName MUST be unique within an SNMP entity. By default this is "" (the empty String).- Specified by:
 setContextNamein interfaceSnmpContextv3Face- Parameters:
 newContextName- The contextName- See Also:
 
 - 
getContextName
Returns the contextName.- Specified by:
 getContextNamein interfaceSnmpContextv3Face- Returns:
 - The contextName
 
 - 
addDiscoveryPdu
Adds a discovery pdu. This method adds the PDU (without checking if discovery is needed).- Specified by:
 addDiscoveryPduin interfaceSnmpContextv3Face- Parameters:
 pdu- the discovery pdu- Returns:
 - pdu is succesful added
 - Throws:
 IOExceptionPduException- See Also:
 
 - 
addPdu
Adds a PDU. This method adds the PDU and blocks until it has all the discovery parameters it needs.- Specified by:
 addPduin interfaceSnmpContextBasisFace- Overrides:
 addPduin classAbstractSnmpContext- Parameters:
 pdu- the PDU- Returns:
 - pdu is succesful added
 - Throws:
 IOExceptionPduException- See Also:
 
 - 
setUsmAgent
Sets the UsmAgent, needed when this stack is used as authoritative SNMP engine. This interface provides authentiation details, like its clock and its Engine ID.- Specified by:
 setUsmAgentin interfaceSnmpContextv3Face- Parameters:
 agent- The USM authoritative interface- Since:
 - 4_14
 - See Also:
 
 - 
getUsmAgent
Returns the UsmAgent.- Specified by:
 getUsmAgentin interfaceSnmpContextv3Face- Since:
 - 4_14
 - See Also:
 
 - 
removePdu
public boolean removePdu(int rid) Removes a PDU. This removes the PDU from the AbstractSnmpContext and clears the link with the SNMPv3 msgId.- Specified by:
 removePduin interfaceSnmpContextBasisFace- Overrides:
 removePduin classAbstractSnmpContext- Parameters:
 rid- the PDU request id- Returns:
 - whether the PDU has been successfully removed
 - See Also:
 
 - 
encodeDiscoveryPacket
public byte[] encodeDiscoveryPacket(byte msg_type, int rId, int errstat, int errind, Enumeration ve, Object obj) throws IOException, EncodingException Encodes a discovery PDU packet. This methods encodes without checking if the discovery parameters are all known.- Specified by:
 encodeDiscoveryPacketin interfaceSnmpContextv3Face- Returns:
 - The encoded packet
 - Throws:
 IOExceptionEncodingException
 - 
encodePacket
public byte[] encodePacket(byte msg_type, int rId, int errstat, int errind, Enumeration ve, Object obj) throws IOException, EncodingException Encodes a PDU. This is for internal use only and should NOT be called by the developer. This is called by the the PDU itself and is added to the interface to cover the different kind of Contexts.When the stack is
- authoritative, the timeline details are retrieved from the UsmAgent.
 - 
 non authoritative, this methods first checks if all the discovery
 parameters are known;
 
- If so, it encodes and returns the bytes.
 - If not, it will throw an EncodingException.
 
 
- Specified by:
 encodePacketin interfaceSnmpContextBasisFace- Specified by:
 encodePacketin classAbstractSnmpContext- Parameters:
 msg_type- The message typerId- The message iderrstat- The error statuserrind- The error indexve- The varbind listobj- Additional object (only used in SNMPv3)- Returns:
 - The encoded packet
 - Throws:
 IOExceptionEncodingException- See Also:
 - 
isAuthoritative(byte)
 
 - 
addRequestPduListener
public void addRequestPduListener(RequestPduListener l, ListeningContextPool lcontext) throws IOException Adds the specified request pdu listener to receive PDUs on the specified listening context that matches this context. This method will call usmAgent.setSnmpContext(this).Don't use the TCP_SOCKET when listening for request PDUs. It doesn't provide functionality to send a response back.
- Specified by:
 addRequestPduListenerin interfaceSnmpContextBasisFace- Overrides:
 addRequestPduListenerin classAbstractSnmpContext- Parameters:
 l- The request PDU listenerlcontext- The listening context- Throws:
 IOException- See Also:
 
 - 
cloneParameters
Copies all parameters into another SnmpContextv3. - 
getHashKey
Returns the hash key. This key is built out of all properties. It serves as key for a hashtable of (v3) contexts.- Specified by:
 getHashKeyin interfaceSnmpContextBasisFace- Specified by:
 getHashKeyin classAbstractSnmpContext- Returns:
 - The hash key
 - Since:
 - 4_14
 
 - 
toString
Returns a string representation of the object. 
 -