Class SnmpContextv3
- All Implemented Interfaces:
Cloneable
,Runnable
,EventListener
,RawPduListener
,SnmpContextBasisFace
,SnmpContextv3Face
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 adds a UsmBeingDiscoveredBean as listener. This bean handles any incoming discovery PDU. Only when acting as authoritative engine should there be any discovery PDU.
- Version:
- $Revision: 3.31 $ $Date: 2009/03/05 13:12:50 $
- Author:
- Birgit Arkesteijn
- See Also:
-
Field Summary
Fields inherited from class uk.co.westhawk.snmp.stack.SnmpContextv3Basis
AES128_KEY_LENGTH, AES192_KEY_LENGTH, AES256_KEY_LENGTH
Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace
DEFAULT_PORT, MAXPDU, MSS, STANDARD_SOCKET, TCP_SOCKET
Fields 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
ConstructorsConstructorDescriptionSnmpContextv3
(String host, int port) Constructor.SnmpContextv3
(String host, int port, String typeSocketA) Constructor.SnmpContextv3
(String host, int port, String bindAddress, String typeSocketA) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addRequestPduListener
(RequestPduListener l, ListeningContextPool lcontext) Makes sure the UsmBeingDiscoveredBean is added as RequestPduListener, so that discovery requests are handled.clone()
Returns a clone of this SnmpContextv3.processIncomingPdu
(byte[] message) Processes an incoming PDU, that is not a Discovery PDU.processPotentialRequest
(uk.co.westhawk.snmp.stack.AsnDecoderv3 rpdu, uk.co.westhawk.snmp.stack.AsnSequence asnTopSeq, byte[] message) Processes an incoming PDU, to see if it is a Request.processPotentialTrap
(uk.co.westhawk.snmp.stack.AsnDecoderv3 rpdu, uk.co.westhawk.snmp.stack.AsnSequence asnTopSeq, byte[] message) Processes an incoming PDU, to see if it is a Trap.void
Removes the UsmBeingDiscoveredBean as listener.Methods inherited from class uk.co.westhawk.snmp.stack.SnmpContextv3Basis
addDiscoveryPdu, addPdu, cloneParameters, encodeDiscoveryPacket, encodePacket, getAuthenticationProtocol, getContextEngineId, getContextName, getHashKey, getPrivacyProtocol, getUserAuthenticationPassword, getUserName, getUserPrivacyPassword, getUsmAgent, getVersion, isUseAuthentication, isUsePrivacy, removePdu, setAuthenticationProtocol, setContextEngineId, setContextName, setPrivacyProtocol, setUseAuthentication, setUsePrivacy, setUserAuthenticationPassword, setUserName, setUserPrivacyPassword, setUsmAgent, toString
Methods inherited from class uk.co.westhawk.snmp.stack.AbstractSnmpContext
addRequestPduListener, addRequestPduListener, addTrapListener, addTrapListener, addTrapListener, destroy, getBindAddress, getDebugString, getHost, getHostAddress, getMaxRecvSize, getPort, getReceivedFromHostAddress, getSendToHostAddress, getTypeSocket, isDestroyed, rawPduReceived, removeRequestPduListener, removeRequestPduListener, removeTrapListener, removeTrapListener, removeTrapListener, run, sendPacket, setMaxRecvSize, stop
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace
addRequestPduListener, addRequestPduListener, addTrapListener, addTrapListener, addTrapListener, destroy, getBindAddress, getHost, getPort, getReceivedFromHostAddress, getSendToHostAddress, getTypeSocket, isDestroyed, removeRequestPduListener, removeRequestPduListener, removeTrapListener, removeTrapListener, removeTrapListener, sendPacket
-
Constructor Details
-
SnmpContextv3
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)
-
SnmpContextv3
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)
-
SnmpContextv3
public SnmpContextv3(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, String)
SnmpContextBasisFace.STANDARD_SOCKET
SnmpContextBasisFace.TCP_SOCKET
-
-
Method Details
-
addRequestPduListener
public void addRequestPduListener(RequestPduListener l, ListeningContextPool lcontext) throws IOException Makes sure the UsmBeingDiscoveredBean is added as RequestPduListener, so that discovery requests are handled. When listening for incoming requests, the stack become authoritative. You have (!) to create a proper usmAgent so the stack can be discovered.Don't use the TCP_SOCKET when listening for request PDUs. It doesn't provide functionality to send a response back.
- Specified by:
addRequestPduListener
in interfaceSnmpContextBasisFace
- Overrides:
addRequestPduListener
in classSnmpContextv3Basis
- Parameters:
l
- The request PDU listenerlcontext
- The listening context- Throws:
IOException
- See Also:
-
removeRequestPduListener
public void removeRequestPduListener(RequestPduListener l, ListeningContextPool lcontext) throws IOException Removes the UsmBeingDiscoveredBean as listener.- Specified by:
removeRequestPduListener
in interfaceSnmpContextBasisFace
- Overrides:
removeRequestPduListener
in classAbstractSnmpContext
- Parameters:
l
- The request PDU listenerlcontext
- The listening context- Throws:
IOException
- See Also:
-
processIncomingPdu
Processes an incoming PDU, that is not a Discovery PDU.This method calls first processPotentialTrap and then processPotentialRequest. The reason this code is split up is because in one case the stack acts as authoritative engine and as non authoritative engine in the other..
- Specified by:
processIncomingPdu
in interfaceSnmpContextBasisFace
- Specified by:
processIncomingPdu
in classAbstractSnmpContext
- Throws:
DecodingException
IOException
- See Also:
-
processPotentialTrap
public Pdu processPotentialTrap(uk.co.westhawk.snmp.stack.AsnDecoderv3 rpdu, uk.co.westhawk.snmp.stack.AsnSequence asnTopSeq, byte[] message) throws DecodingException, IOException Processes an incoming PDU, to see if it is a Trap. This method is called by processIncomingPdu. When receiving traps the stack is non authoritative. -
processPotentialRequest
public Pdu processPotentialRequest(uk.co.westhawk.snmp.stack.AsnDecoderv3 rpdu, uk.co.westhawk.snmp.stack.AsnSequence asnTopSeq, byte[] message) throws DecodingException, IOException Processes an incoming PDU, to see if it is a Request. This method is called by processIncomingPdu. When receiving pdu requests the stack is authoritative. -
clone
Returns a clone of this SnmpContextv3.- Specified by:
clone
in interfaceSnmpContextBasisFace
- Specified by:
clone
in classAbstractSnmpContext
- Throws:
CloneNotSupportedException
- Thrown when the constructor generates an IOException
-