|
SNMP Stack 5_1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Object
|
+--uk.co.westhawk.snmp.stack.AbstractSnmpContext
|
+--uk.co.westhawk.snmp.stack.SnmpContextv3Basis
This class contains the basis for the SNMP v3 contexts that is needed by every PDU to send a SNMP v3 request.
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.
SnmpContextv3Face,
SnmpContextv3Pool,
TimeWindow,
UsmAgent,
DefaultUsmAgent,
setUsmAgent(UsmAgent),
UsmDiscoveryBean| Field Summary | |
protected int |
authenticationProtocol
|
protected byte[] |
contextEngineId
|
protected java.lang.String |
contextName
|
protected boolean |
useAuthentication
|
protected boolean |
usePrivacy
|
protected java.lang.String |
userAuthenticationPassword
|
protected byte[] |
userAuthKeyMD5
|
protected byte[] |
userAuthKeySHA1
|
protected java.lang.String |
userName
|
protected java.lang.String |
userPrivacyPassword
|
protected byte[] |
userPrivKeyMD5
|
protected byte[] |
userPrivKeySHA1
|
protected UsmAgent |
usmAgent
|
| Fields inherited from class uk.co.westhawk.snmp.stack.AbstractSnmpContext |
anyPduExpectingResponse, bindAddr, hostname, hostPort, isDestroyed, maxRecvSize, pduSupport, trapSupport, typeSocket |
| Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextv3Face |
Default_ContextName, Default_UserName, MD5_PROTOCOL, ProtocolNames, SHA1_PROTOCOL, SNMPv1_Security_Model, SNMPv2c_Security_Model, USM_Security_Model, version_id |
| Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace |
DEFAULT_PORT, KVM_SOCKET, MAXPDU, MSS, NETSCAPE_SOCKET, STANDARD_SOCKET, TCP_SOCKET |
| Fields inherited from interface uk.co.westhawk.snmp.event.RawPduListener |
version_id |
| Constructor Summary | |
SnmpContextv3Basis(java.lang.String host,
int port)
Constructor. |
|
SnmpContextv3Basis(java.lang.String host,
int port,
java.lang.String typeSocketA)
Constructor. |
|
SnmpContextv3Basis(java.lang.String host,
int port,
java.lang.String bindAddress,
java.lang.String typeSocketA)
Constructor. |
|
| Method Summary | |
protected byte[] |
actualEncodePacket(byte msg_type,
int rId,
int errstat,
int errind,
java.util.Enumeration ve,
uk.co.westhawk.snmp.stack.TimeWindowNode node,
java.lang.Object obj)
Does the actual encoding. |
boolean |
addDiscoveryPdu(DiscoveryPdu pdu)
Adds a discovery pdu. |
boolean |
addPdu(Pdu pdu)
Adds a PDU. |
protected boolean |
addPdu(Pdu pdu,
boolean checkDiscovery)
Adds a PDU. |
void |
addRequestPduListener(RequestPduListener l,
ListeningContextPool lcontext)
Adds the specified request pdu listener to receive PDUs on the specified listening context that matches this context. |
protected java.lang.String |
checkContextSanity()
Checks the sanity of the context and returns an error message when it is not correct. |
java.lang.Object |
cloneParameters(SnmpContextv3Face clContext)
Copies all parameters into another SnmpContextv3. |
protected UsmAgent |
createUsmAgent()
Creates the USM agent. |
byte[] |
encodeDiscoveryPacket(byte msg_type,
int rId,
int errstat,
int errind,
java.util.Enumeration ve,
java.lang.Object obj)
Encodes a discovery PDU packet. |
byte[] |
encodePacket(byte msg_type,
int rId,
int errstat,
int errind,
java.util.Enumeration ve,
java.lang.Object obj)
Encodes a PDU. |
int |
getAuthenticationProtocol()
Returns the protocol to be used for authentication. |
byte[] |
getContextEngineId()
Returns the contextEngineID. |
java.lang.String |
getContextName()
Returns the contextName. |
java.lang.String |
getHashKey()
Returns the hash key. |
java.lang.String |
getUserAuthenticationPassword()
Returns the user authentication password. |
java.lang.String |
getUserName()
Returns the username. |
java.lang.String |
getUserPrivacyPassword()
Returns the user privacy password. |
UsmAgent |
getUsmAgent()
Returns the UsmAgent. |
int |
getVersion()
Returns the SNMP version of the context. |
protected boolean |
isAuthoritative(byte msg_type)
Returns if we send this PDU in authoritative role or not. |
boolean |
isUseAuthentication()
Returns if authentication is used or not. |
boolean |
isUsePrivacy()
Returns if privacy is used or not. |
protected void |
processIncomingResponse(java.io.ByteArrayInputStream in)
Processes an incoming SNMP v3 response. |
boolean |
removePdu(int rid)
Removes a PDU. |
void |
setAuthenticationProtocol(int protocol)
Sets the protocol to be used for authentication. |
void |
setContextEngineId(byte[] newContextEngineId)
Sets the contextEngineID. |
void |
setContextName(java.lang.String newContextName)
Sets the contextName. |
void |
setUseAuthentication(boolean newUseAuthentication)
Sets whether authentication has to be used. |
void |
setUsePrivacy(boolean newUsePrivacy)
Sets whether privacy has to be used. |
void |
setUserAuthenticationPassword(java.lang.String newUserAuthPassword)
Sets the user authentication password. |
void |
setUserName(java.lang.String newUserName)
Sets the username. |
void |
setUserPrivacyPassword(java.lang.String newUserPrivacyPassword)
Sets the user privacy password. |
void |
setUsmAgent(UsmAgent agent)
Sets the UsmAgent, needed when this stack is used as authoritative SNMP engine. |
java.lang.String |
toString()
Returns a string representation of the object. |
| Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Methods 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 Detail |
protected java.lang.String userName
protected boolean useAuthentication
protected java.lang.String userAuthenticationPassword
protected byte[] userAuthKeyMD5
protected byte[] userAuthKeySHA1
protected int authenticationProtocol
protected boolean usePrivacy
protected java.lang.String userPrivacyPassword
protected byte[] userPrivKeyMD5
protected byte[] userPrivKeySHA1
protected byte[] contextEngineId
protected java.lang.String contextName
protected UsmAgent usmAgent
| Constructor Detail |
public SnmpContextv3Basis(java.lang.String host,
int port)
throws java.io.IOException
host - The host to which the PDU will be sentport - The port where the SNMP server will beAbstractSnmpContext.AbstractSnmpContext(String, int)
public SnmpContextv3Basis(java.lang.String host,
int port,
java.lang.String typeSocketA)
throws java.io.IOException
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 toAbstractSnmpContext.AbstractSnmpContext(String, int, String)
public SnmpContextv3Basis(java.lang.String host,
int port,
java.lang.String bindAddress,
java.lang.String typeSocketA)
throws java.io.IOException
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.AbstractSnmpContext.AbstractSnmpContext(String, int, String),
SnmpContextBasisFace.STANDARD_SOCKET,
SnmpContextBasisFace.TCP_SOCKET,
SnmpContextBasisFace.NETSCAPE_SOCKET,
SnmpContextBasisFace.KVM_SOCKET| Method Detail |
public int getVersion()
SnmpContextBasisFace
getVersion in interface SnmpContextBasisFacegetVersion in class AbstractSnmpContextSnmpConstants.SNMP_VERSION_1,
SnmpConstants.SNMP_VERSION_2c,
SnmpConstants.SNMP_VERSION_3public java.lang.String getUserName()
getUserName in interface SnmpContextv3Facepublic void setUserName(java.lang.String newUserName)
setUserName in interface SnmpContextv3FacenewUserName - The new usernameSnmpContextv3Face.Default_UserNamepublic boolean isUseAuthentication()
isUseAuthentication in interface SnmpContextv3Facepublic void setUseAuthentication(boolean newUseAuthentication)
setUseAuthentication in interface SnmpContextv3FacenewUseAuthentication - The use of authenticationpublic java.lang.String getUserAuthenticationPassword()
getUserAuthenticationPassword in interface SnmpContextv3Facepublic void setUserAuthenticationPassword(java.lang.String newUserAuthPassword)
setUserAuthenticationPassword in interface SnmpContextv3FacenewUserAuthPassword - The user authentication password
public void setAuthenticationProtocol(int protocol)
throws java.lang.IllegalArgumentException
setAuthenticationProtocol in interface SnmpContextv3Faceprotocol - The authentication protocol to be used
java.lang.IllegalArgumentExceptionSnmpContextv3Face.MD5_PROTOCOL,
SnmpContextv3Face.SHA1_PROTOCOLpublic int getAuthenticationProtocol()
getAuthenticationProtocol in interface SnmpContextv3FaceSnmpContextv3Face.MD5_PROTOCOL,
SnmpContextv3Face.SHA1_PROTOCOLpublic boolean isUsePrivacy()
isUsePrivacy in interface SnmpContextv3Facepublic void setUsePrivacy(boolean newUsePrivacy)
setUsePrivacy in interface SnmpContextv3FacenewUsePrivacy - The use of privacypublic java.lang.String getUserPrivacyPassword()
getUserPrivacyPassword in interface SnmpContextv3Facepublic void setUserPrivacyPassword(java.lang.String newUserPrivacyPassword)
setUserPrivacyPassword in interface SnmpContextv3FacenewUserPrivacyPassword - The user privacy password
public void setContextEngineId(byte[] newContextEngineId)
throws java.lang.IllegalArgumentException
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.
setContextEngineId in interface SnmpContextv3FacenewContextEngineId - The contextEngineID
java.lang.IllegalArgumentExceptionUsmAgent.getSnmpEngineId()public byte[] getContextEngineId()
getContextEngineId in interface SnmpContextv3Facepublic void setContextName(java.lang.String newContextName)
setContextName in interface SnmpContextv3FacenewContextName - The contextNameSnmpContextv3Face.Default_ContextNamepublic java.lang.String getContextName()
getContextName in interface SnmpContextv3Face
public boolean addDiscoveryPdu(DiscoveryPdu pdu)
throws java.io.IOException,
PduException
addDiscoveryPdu in interface SnmpContextv3Facepdu - the discovery pdu
java.io.IOException
PduExceptionAbstractSnmpContext.addPdu(Pdu),
addPdu(Pdu)
public boolean addPdu(Pdu pdu)
throws java.io.IOException,
PduException
addPdu in interface SnmpContextBasisFaceaddPdu in class AbstractSnmpContextpdu - the PDU
java.io.IOException
PduExceptionAbstractSnmpContext.addPdu(Pdu),
addDiscoveryPdu(DiscoveryPdu)protected UsmAgent createUsmAgent()
DefaultUsmAgent,
isAuthoritative(byte)public void setUsmAgent(UsmAgent agent)
setUsmAgent in interface SnmpContextv3Faceagent - The USM authoritative interfaceDefaultUsmAgentpublic UsmAgent getUsmAgent()
getUsmAgent in interface SnmpContextv3FacesetUsmAgent(uk.co.westhawk.snmp.stack.UsmAgent)
protected boolean addPdu(Pdu pdu,
boolean checkDiscovery)
throws java.io.IOException,
PduException
checkDiscovery.
If discovery is needed this method will block until it has done so.
Discovery is only needed if the stack is non authoritative.
This method stores the SNMPv3 msgId and PDU request id in a Hashtable. Since the encoding only happens once and every retry sends the same encoded packet, only one msgId is used.
pdu - the PDUcheckDiscovery - check if discovery is needed
java.io.IOException
PduExceptionAbstractSnmpContext.addPdu(Pdu),
addDiscoveryPdu(DiscoveryPdu),
addPdu(Pdu)public boolean removePdu(int rid)
removePdu in interface SnmpContextBasisFaceremovePdu in class AbstractSnmpContextrid - the PDU request id
AbstractSnmpContext.removePdu(int)
public byte[] encodeDiscoveryPacket(byte msg_type,
int rId,
int errstat,
int errind,
java.util.Enumeration ve,
java.lang.Object obj)
throws java.io.IOException,
EncodingException
encodeDiscoveryPacket in interface SnmpContextv3Facejava.io.IOException
EncodingException
public byte[] encodePacket(byte msg_type,
int rId,
int errstat,
int errind,
java.util.Enumeration ve,
java.lang.Object obj)
throws java.io.IOException,
EncodingException
When the stack is
encodePacket in interface SnmpContextBasisFaceencodePacket in class AbstractSnmpContextmsg_type - The message typerId - The message iderrstat - The error statuserrind - The error indexve - The varbind listobj - Additional object (only used in SNMPv3)
java.io.IOException
EncodingExceptionisAuthoritative(byte)protected java.lang.String checkContextSanity()
protected byte[] actualEncodePacket(byte msg_type,
int rId,
int errstat,
int errind,
java.util.Enumeration ve,
uk.co.westhawk.snmp.stack.TimeWindowNode node,
java.lang.Object obj)
throws java.io.IOException,
EncodingException
java.io.IOException
EncodingExceptionencodeDiscoveryPacket(byte, int, int, int, java.util.Enumeration, java.lang.Object),
encodePacket(byte, int, int, int, java.util.Enumeration, java.lang.Object)
protected void processIncomingResponse(java.io.ByteArrayInputStream in)
throws DecodingException,
java.io.IOException
processIncomingResponse in class AbstractSnmpContextDecodingException
java.io.IOExceptionAbstractSnmpContext.run()protected boolean isAuthoritative(byte msg_type)
public void addRequestPduListener(RequestPduListener l,
ListeningContextPool lcontext)
throws java.io.IOException
Don't use the TCP_SOCKET when listening for request PDUs. It doesn't provide functionality to send a response back.
addRequestPduListener in interface SnmpContextBasisFaceaddRequestPduListener in class AbstractSnmpContextl - The request PDU listenerlcontext - The listening context
java.io.IOExceptionAbstractSnmpContext.addRequestPduListener(RequestPduListener, ListeningContextPool)public java.lang.Object cloneParameters(SnmpContextv3Face clContext)
public java.lang.String getHashKey()
getHashKey in interface SnmpContextBasisFacegetHashKey in class AbstractSnmpContextpublic java.lang.String toString()
toString in class java.lang.Object
|
SNMP Stack 5_1 | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||