Interface SnmpContextBasisFace
- All Known Subinterfaces:
SnmpContextFace
,SnmpContextv2cFace
,SnmpContextv3Face
- All Known Implementing Classes:
AbstractSnmpContext
,PassiveSnmpContext
,PassiveSnmpContextv2c
,SnmpContext
,SnmpContextPool
,SnmpContextv2c
,SnmpContextv2cPool
,SnmpContextv3
,SnmpContextv3Basis
,SnmpContextv3Discovery
,SnmpContextv3Pool
- Version:
- $Revision: 3.9 $ $Date: 2006/11/29 16:25:19 $
- Author:
- Tim Panton
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The default port number where SNMP requests are sent to (161).static final int
The Maximum number of outstanding PDUs one context can handle at a given moment in time.static final int
The Maximum size of a message in octets (1300).static final String
The Standard Socket type.static final String
The TCP Socket type.static final String
-
Method Summary
Modifier and TypeMethodDescriptionboolean
Adds a PDU to the context.void
Adds the specified request pdu listener to receive PDUs on the default request pdu port 161 from the host that matches this context.void
addRequestPduListener
(RequestPduListener l, int port) Adds the specified request pdu listener to receive PDUs on the specified port from the host that matches this context.void
addRequestPduListener
(RequestPduListener l, ListeningContextPool lcontext) Adds the specified request pdu listener to receive PDUs on the specified listening context that matches this context.void
Adds the specified trap listener to receive traps on the default trap port 162 from the host that matches this context.void
addTrapListener
(TrapListener l, int port) Adds the specified trap listener to receive traps on the specified port from the host that matches this context.void
addTrapListener
(TrapListener l, ListeningContextPool lcontext) Adds the specified trap listener to receive traps on the specified listening context that matches this context.clone()
Returns a clone of this SnmpContext.void
destroy()
Removes the resouces held by this context.byte[]
encodePacket
(byte msg_type, int rId, int errstat, int errind, Enumeration ve, Object obj) Encodes a PDU.Returns the local bind address.Returns the hash key.getHost()
Returns the host.int
getPort()
Returns the port number.Returns the IP address string aaa.bbb.ccc.ddd (IPv4) or a:b:c:d:e:f:g:h (IPv6) of the (latest) host the packets where received from.Returns the IP address string aaa.bbb.ccc.ddd (IPv4) or a:b:c:d:e:f:g:h (IPv6) of the host the packets where sent to.Returns the type of socket.int
Returns the SNMP version of the context.boolean
Returns whether or not this context has been destroyed.processIncomingPdu
(byte[] message) Processes an incoming PDU.boolean
removePdu
(int requestId) Removes a PDU from the context.void
Removes the specified request pdu listener from listening for packets on the default request pdu port 161.void
removeRequestPduListener
(RequestPduListener l, int port) Removes the specified request pdu listener from listening for packets on the specified port.void
Removes the specified request pdu listener from listening for packets on the specified listening context.void
Removes the specified trap listener from listening for packets on the default trap port 162.void
removeTrapListener
(TrapListener l, int port) Removes the specified trap listener from listening for packets on the specified port.void
removeTrapListener
(TrapListener l, ListeningContextPool lcontext) Removes the specified trap listener from listening for packets on the specified listening context.void
sendPacket
(byte[] packet) Sends an encoded PDU.
-
Field Details
-
version_id
- See Also:
-
DEFAULT_PORT
static final int DEFAULT_PORTThe default port number where SNMP requests are sent to (161).- See Also:
-
STANDARD_SOCKET
The Standard Socket type.- See Also:
-
TCP_SOCKET
The TCP Socket type.- See Also:
-
MAXPDU
static final int MAXPDUThe Maximum number of outstanding PDUs one context can handle at a given moment in time.- See Also:
-
MSS
static final int MSSThe Maximum size of a message in octets (1300).- See Also:
-
-
Method Details
-
getVersion
int getVersion()Returns the SNMP version of the context.- Returns:
- The version
- See Also:
-
getHost
String getHost()Returns the host.- Returns:
- The host
-
getPort
int getPort()Returns the port number.- Returns:
- The port no
-
getBindAddress
String getBindAddress()Returns the local bind address. If bindAddress is null, then the system will pick up a valid local address to bind the socket.- Returns:
- The local bind address
- Since:
- 4_14
-
getTypeSocket
String getTypeSocket()Returns the type of socket.- Returns:
- The type of socket
- See Also:
-
getSendToHostAddress
String getSendToHostAddress()Returns the IP address string aaa.bbb.ccc.ddd (IPv4) or a:b:c:d:e:f:g:h (IPv6) of the host the packets where sent to.- Returns:
- The IP address of the host the packets where sent to.
- Since:
- 4_14
- See Also:
-
getReceivedFromHostAddress
String getReceivedFromHostAddress()Returns the IP address string aaa.bbb.ccc.ddd (IPv4) or a:b:c:d:e:f:g:h (IPv6) of the (latest) host the packets where received from.- Returns:
- The IP address of the (latest) host the packets where received from.
- Since:
- 4_14
- See Also:
-
addPdu
Adds a PDU to the context. 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.- Parameters:
pdu
- the PDU- Returns:
- whether the PDU has been successfully added
- Throws:
IOException
PduException
-
removePdu
boolean removePdu(int requestId) Removes a PDU from the context. 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.- Parameters:
requestId
- the PDU request id- Returns:
- whether the PDU has been successfully removed
-
encodePacket
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.- 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:
IOException
EncodingException
-
sendPacket
void sendPacket(byte[] packet) Sends an encoded 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.- Parameters:
packet
- The encoded packet
-
destroy
void destroy()Removes the resouces held by this context. Should be called by the user/developer when the context is no longer needed. -
isDestroyed
boolean isDestroyed()Returns whether or not this context has been destroyed.- Since:
- 4_14
-
addTrapListener
Adds the specified trap listener to receive traps on the default trap port 162 from the host that matches this context.The ListeningContext class will do the actual listening for traps. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a trap pdu.
- Parameters:
l
- The trap listener- Throws:
IOException
- See Also:
-
removeTrapListener
Removes the specified trap listener from listening for packets on the default trap port 162.The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()
- Parameters:
l
- The trap listener- Throws:
IOException
- See Also:
-
addTrapListener
Adds the specified trap listener to receive traps on the specified port from the host that matches this context.The ListeningContext class will do the actual listening for traps. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a trap pdu.
- Parameters:
l
- The trap listenerport
- The port the traps are received on- Throws:
IOException
- Since:
- 4_14
- See Also:
-
removeTrapListener
Removes the specified trap listener from listening for packets on the specified port.The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()
- Parameters:
l
- The trap listenerport
- The port the traps are received on- Throws:
IOException
- Since:
- 4_14
- See Also:
-
addTrapListener
Adds the specified trap listener to receive traps on the specified listening context that matches this context.The ListeningContext class will do the actual listening for traps. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a trap pdu.
- Parameters:
l
- The trap listenerlcontext
- The listening context- Throws:
IOException
- Since:
- 4_14
- See Also:
-
removeTrapListener
Removes the specified trap listener from listening for packets on the specified listening context.The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeTrapListenerFromPool()
- Parameters:
l
- The trap listenerlcontext
- The listening context- Throws:
IOException
- Since:
- 4_14
- See Also:
-
addRequestPduListener
Adds the specified request pdu listener to receive PDUs on the default request pdu port 161 from the host that matches this context.The ListeningContext class will do the actual listening for PDUs. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a request pdu.
Don't use the TCP_SOCKET when listening for request PDUs. It doesn't provide functionality to send a response back.
- Parameters:
l
- The request PDU listener- Throws:
IOException
- Since:
- 4_14
- See Also:
-
removeRequestPduListener
Removes the specified request pdu listener from listening for packets on the default request pdu port 161.The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()
- Parameters:
l
- The request PDU listener- Throws:
IOException
- Since:
- 4_14
- See Also:
-
addRequestPduListener
Adds the specified request pdu listener to receive PDUs on the specified port from the host that matches this context.The ListeningContext class will do the actual listening for PDUs. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a request pdu.
Don't use the TCP_SOCKET when listening for request PDUs. It doesn't provide functionality to send a response back.
- Parameters:
l
- The request PDU listenerport
- The port the request PDUs are received on- Throws:
IOException
- Since:
- 4_14
- See Also:
-
removeRequestPduListener
Removes the specified request pdu listener from listening for packets on the specified port.The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()
- Parameters:
l
- The request PDU listenerport
- The port the request PDUs are received on- Throws:
IOException
- Since:
- 4_14
- See Also:
-
addRequestPduListener
Adds the specified request pdu listener to receive PDUs on the specified listening context that matches this context.The ListeningContext class will do the actual listening for PDUs. This context will add itself to a ListeningContextPool object and will only pass the event to its listeners if the pdu matches this context and is a request pdu.
Don't use the TCP_SOCKET when listening for request PDUs. It doesn't provide functionality to send a response back.
- Parameters:
l
- The request PDU listenerlcontext
- The listening context- Throws:
IOException
- Since:
- 4_14
- See Also:
-
removeRequestPduListener
void removeRequestPduListener(RequestPduListener l, ListeningContextPool lcontext) throws IOException Removes the specified request pdu listener from listening for packets on the specified listening context.The listener will not be removed from all ListeningContext objects that are in the ListeningContextPool. In order to do that, use ListeningContextPool.removeRequestPduListenerFromPool()
- Parameters:
l
- The request PDU listenerlcontext
- The listening context- Throws:
IOException
- Since:
- 4_14
- See Also:
-
processIncomingPdu
Processes an incoming PDU. The context will try to process the incoming PDU, using the SNMP version and other security parameters. If any of these do not correspond, a DecodingException will be thrown.- Throws:
DecodingException
IOException
-
clone
Returns a clone of this SnmpContext.- Throws:
CloneNotSupportedException
- Thrown when the constructor generates an IOException or when in one of the Pool classes.- Since:
- 4_14
-
getHashKey
String getHashKey()Returns the hash key. This key is built out of all properties.- Returns:
- The hash key
- Since:
- 4_14
-