|
SNMP Stack 4_12 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--uk.co.westhawk.snmp.stack.AbstractSnmpContext
This class contains the abstract SNMP context that is needed by every Pdu to send a SNMP v1, v2c or v3 request. The context also provides functionality to receive traps.
destroy()
should be called when the context is no longer
used. This is the only way the threads will be stopped and garbage
collected.
SnmpContext
,
SnmpContextv2c
,
SnmpContextv3
Field Summary | |
protected java.lang.String |
hostAddr
|
protected int |
hostPort
|
protected boolean |
isDestroyed
|
protected int |
maxRecvSize
|
protected java.lang.String |
typeSocket
|
Fields inherited from interface uk.co.westhawk.snmp.stack.SnmpContextBasisFace |
DEFAULT_PORT, KVM_SOCKET, MAXPDU, MSS, NETSCAPE_SOCKET, STANDARD_SOCKET, version_id |
Fields inherited from interface uk.co.westhawk.snmp.event.TrapListener |
version_id |
Constructor Summary | |
protected |
AbstractSnmpContext(java.lang.String host,
int port)
Constructor. |
protected |
AbstractSnmpContext(java.lang.String host,
int port,
java.lang.String typeSocketA)
Constructor. |
Method Summary | |
protected void |
activate()
Creates and starts the Receive thread that allows this context to receive packets. |
boolean |
addPdu(Pdu p)
Adds a pdu. |
void |
addTrapListener(TrapListener l)
Adds the specified trap listener to receive traps from the host that matches this context. |
void |
destroy()
This method will stop the thread. |
abstract byte[] |
encodePacket(byte msg_type,
int rId,
int errstat,
int errind,
java.util.Enumeration ve)
Encodes a packet. |
java.lang.String |
getDebugString()
Returns the thread usage of the AbstractSnmpContext. |
java.lang.String |
getHost()
Returns the host |
java.lang.String |
getHostAddress()
Returns the IP address string "%d.%d.%d.%d" of the host. |
int |
getMaxRecvSize()
Returns the maximum number of bytes this context will read from the socket. |
int |
getPort()
Returns the port number |
java.lang.String |
getTypeSocket()
Returns the type socket |
abstract int |
getVersion()
Return the SNMP version of this context. |
protected abstract void |
ProcessIncomingMessage(uk.co.westhawk.snmp.stack.AsnDecoder rpdu,
java.io.ByteArrayInputStream in)
Processes an incoming response. |
abstract Pdu |
processIncomingTrap(byte[] message)
Processes an incoming trap. |
boolean |
removePdu(int rid)
Removes a pdu. |
void |
removeTrapListener(TrapListener l)
Removes the specified trap listener. |
void |
run()
We wait for any incoming packets. |
void |
sendPacket(byte[] p)
Pass a correctly encoded SNMP packet, and we'l send it... |
void |
setMaxRecvSize(int no)
Sets the maximum number of bytes this context will read from the socket. |
void |
stop()
Deprecated. As of version 4_12, should use destroy() |
void |
trapReceived(TrapEvent evt)
Invoked when an undecoded trap is received. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected java.lang.String typeSocket
protected java.lang.String hostAddr
protected int hostPort
protected int maxRecvSize
protected boolean isDestroyed
Constructor Detail |
protected AbstractSnmpContext(java.lang.String host, int port) throws java.io.IOException
host
- The host to which the Pdu will sendport
- The port where the SNMP server will beSnmpContextBasisFace.STANDARD_SOCKET
protected AbstractSnmpContext(java.lang.String host, int port, java.lang.String typeSocketA) throws java.io.IOException
host
- The host to which the Pdu will sendport
- The port where the SNMP server will betypeSocketA
- The type of socket to use.SnmpContextBasisFace.STANDARD_SOCKET
,
SnmpContextBasisFace.NETSCAPE_SOCKET
,
SnmpContextBasisFace.KVM_SOCKET
Method Detail |
protected abstract void ProcessIncomingMessage(uk.co.westhawk.snmp.stack.AsnDecoder rpdu, java.io.ByteArrayInputStream in) throws DecodingException, java.io.IOException
run()
public abstract byte[] encodePacket(byte msg_type, int rId, int errstat, int errind, java.util.Enumeration ve) throws java.io.IOException, EncodingException
encodePacket
in interface SnmpContextBasisFace
uk.co.westhawk.snmp.stack.SnmpContextBasisFace
public abstract Pdu processIncomingTrap(byte[] message) throws DecodingException, java.io.IOException
processIncomingTrap
in interface SnmpContextBasisFace
trapReceived(uk.co.westhawk.snmp.event.TrapEvent)
public abstract int getVersion()
getVersion
in interface SnmpContextBasisFace
uk.co.westhawk.snmp.stack.SnmpContextBasisFace
protected void activate()
PassiveSnmpContext.activate()
,
PassiveSnmpContextv2c.activate()
public java.lang.String getHost()
getHost
in interface SnmpContextBasisFace
public java.lang.String getHostAddress()
InetAddress.getHostAddress()
public int getPort()
getPort
in interface SnmpContextBasisFace
public java.lang.String getTypeSocket()
getTypeSocket
in interface SnmpContextBasisFace
public int getMaxRecvSize()
MSS
(i.e. 1300).SnmpContextBasisFace.MSS
,
setMaxRecvSize(int)
public void setMaxRecvSize(int no)
MSS
(i.e. 1300).
The default size seems a reasonable size. The problem usually occurs
when sending Bulk requests.
If a packet arrives that is bigger than the maximum size of received bytes, the stack will try to decode it nevertheless. The usual error that will occur is:
Error message: "Incorrect packet. No of bytes received less than packet length."
Although UDP datagrams can be fragmented (fragmentation is part of the network layer (IP), not the transport layer (UDP/TCP)), some firewalls reject incoming fragments. Therefor it is best not to set maxRecvSize higher than the largest packet size you can get through your network topology.
Thanks to Pete Kazmier (pete@kazmier.com) for the suggestion.
Note, this property is NOT supported in any of the SNMPContextXXPool classes.
no
- The new numberSnmpContextBasisFace.MSS
,
getMaxRecvSize()
public java.lang.String getDebugString()
=PO=QR--------------0
.
The String represents the array of transmitters. Each character represents a transmitter slot. The transmitters form a thread pool of a maximum size, MAXPDU. Each transmitter is used to wait for one PDU response at a given moment in time. When the response is received the transmitter will stop running, but is not destroyed. It will be reused.
Meaning of each character:
-
a transmitter slot has not yet been allocated a thread=
there is a thread but it is idleA->Z
the thread is transmitting a Pdu0
there isn't one1
it exists but isn't running 2
it exists and is alive.public void destroy()
It closes the socket. The tread will actually stop/finish when the run() finishes. Since the socket is closed, the run() will fall through almost instantly.
Note: The thread(s) will not die immediately; this will take about half a minute.
destroy
in interface SnmpContextBasisFace
public void stop()
It does NOT close the socket. The tread will actually stop/finish when the run() finishes. That is when a packet arrives on the socket or when the socket times out.
We have deprecated this method since there is no point in stopping the context, but not destroying it. The context cannot start again anyway. The difference between destroy() and stop() was not very clear.
destroy()
public void run()
run
in interface java.lang.Runnable
public void sendPacket(byte[] p)
sendPacket
in interface SnmpContextBasisFace
uk.co.westhawk.snmp.stack.SnmpContextBasisFace
packet
- The encoded packetpublic boolean removePdu(int rid)
removePdu
in interface SnmpContextBasisFace
rid
- the Pdu request idpublic boolean addPdu(Pdu p) throws java.io.IOException, PduException
addPdu
in interface SnmpContextBasisFace
pdu
- the Pdupublic void addTrapListener(TrapListener l) throws java.io.IOException
The DefaultTrapContext class will do the actual listening for traps. This context will add itself to the DefaultTrapContext object and will only pass the event to its listeners if the trap matches this context. Note that the portnumber of this class is ignored. Unless there already exists a DefaultTrapContext object, the DEFAULT_TRAP_PORT is used.
addTrapListener
in interface SnmpContextBasisFace
DefaultTrapContext.getInstance(int, String)
,
DefaultTrapContext.addTrapListener(TrapListener)
,
DefaultTrapContext.DEFAULT_TRAP_PORT
public void removeTrapListener(TrapListener l) throws java.io.IOException
removeTrapListener
in interface SnmpContextBasisFace
public void trapReceived(TrapEvent evt)
trapReceived
in interface TrapListener
TrapReceivedSupport.fireTrapReceived(Pdu)
|
SNMP Stack 4_12 | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |