|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--ipworks.Snmp
The SNMP class is used to implement SNMP Management Applications and SNMP Agent Applications.
The SNMP class implements a standard SNMP Version 1 Manager and/or Agent as specified in RFC 1157.
The class provides both encoding/decoding and transport capabilities, making the task of developing a custom SNMP agent or manager as simple as setting a few key properties and handling a few events. SNMP data, such as for instance SNMP object id-s (OID-s) are exchanged as text strings, thus further simplifying the task of handling them.
The class is activated/deactivated by first setting the LocalPort to 161 or 162, depending on whether you want to implement an SNMP agent or SNMP manager, and then setting the Active property. This property enables or disables sending or receiving. It operates completely asynchronously. Messages are sent to other agents or managers by using the Action property, and are recieved through events such as GetRequest , GetResponse , or Trap .
SNMP object ids, types, and values are provided in arrays such as ObjId , ObjType , and ObjValue , for both sent and received packets. ObjCount provides the number of elements in each of the arrays. Other packet information is provided through corresponding properties, such as Community , or RequestId , or similarly named parameters in events.
The class may behave as an SNMP agent or SNMP manager, depending on the value of the LocalPort property. If the class listens to port 161 it may act as an SNMP agent by responding to SNMP requests from SNMP managers, and sending traps through the Action property. If the LocalPort is set to 162, the class listens for SNMP traps, and may send requests to SNMP agents listening on port 161.
SNMP Traps are received through the Trap event, and may be sent through the Action property by specifying appropriate values in the various trap properties, such as TrapAgentAddress , TrapEnterprise , TrapGenericType , TrapSpecificType , and TrapTimeStamp .
Field Summary | |
static int |
a_Reset
|
static int |
a_SendGetNextRequest
|
static int |
a_SendGetRequest
|
static int |
a_SendGetResponse
|
static int |
a_SendSetRequest
|
static int |
a_SendTrap
|
static int |
ot_Counter32
|
static int |
ot_Counter64
|
static int |
ot_Gauge32
|
static int |
ot_Integer
|
static int |
ot_IPAddress
|
static int |
ot_NSAP
|
static int |
ot_Null
|
static int |
ot_ObjectId
|
static int |
ot_OctetString
|
static int |
ot_Opaque
|
static int |
ot_TimeTicks
|
static int |
ot_UnsignedInteger32
|
static int |
tgt_AuthenticationFailure
|
static int |
tgt_ColdStart
|
static int |
tgt_EGPNeighborLoss
|
static int |
tgt_EnterpriseSpecific
|
static int |
tgt_LinkDown
|
static int |
tgt_LinkUp
|
static int |
tgt_WarmStart
|
Constructor Summary | |
Snmp()
|
Method Summary | |
void |
addSnmpEventListener(SnmpEventListener l)
|
void |
fireError(int errorCode,
java.lang.String description)
Information about errors during data delivery. |
void |
fireGetNextRequest(int requestId,
java.lang.String community,
java.lang.String sourceAddress,
int sourcePort)
Fired when a GetNextRequest packet is received. |
void |
fireGetRequest(int requestId,
java.lang.String community,
java.lang.String sourceAddress,
int sourcePort)
Fired when a GetRequest packet is received. |
void |
fireGetResponse(int requestId,
java.lang.String community,
int errorStatus,
int errorIndex,
java.lang.String sourceAddress,
int sourcePort)
Fired when a GetResponse packet is received. |
void |
fireReadyToSend()
Fired when the component is ready to send data. |
void |
fireSetRequest(int requestId,
java.lang.String community,
java.lang.String sourceAddress,
int sourcePort)
Fired when a SetRequest packet is received. |
void |
fireTrap(java.lang.String community,
java.lang.String enterprise,
java.lang.String agentAddress,
int genericType,
int specificType,
int timeStamp,
java.lang.String sourceAddress,
int sourcePort)
Fired when a SNMP trap packet is received. |
int |
getAction()
An action code for the component. |
java.lang.String |
getCommunity()
The community string used to authenticate SNMP packets. |
int |
getErrorIndex()
Index of the first variable (object) that caused an error. |
int |
getErrorStatus()
Status code for outgoing 'Get-Response' packets. |
int |
getInBufferSize()
The size in bytes of the incoming queue of the socket. |
java.lang.String |
getLocalHost()
The name of the local host. |
int |
getLocalPort()
The UDP port in the local host where the SNMP component listens to. |
int |
getObjCount()
Number of objects in the current request. |
java.lang.String |
getObjId(int objIndex)
Array of OIDs encoded as strings. |
int |
getObjType(int objIndex)
Array of object types. |
byte[] |
getObjValue(int objIndex)
Array of object values. |
int |
getOutBufferSize()
The size in bytes of the outgoing queue of the socket. |
java.lang.String |
getRemoteHost()
The address of the remote host. |
int |
getRemotePort()
The UDP port where the remote SNMP agent is listening. |
int |
getRequestId()
The request-id to mark outgoing packets with. |
java.lang.String |
getTrapAgentAddress()
The address of the object generating the trap. |
java.lang.String |
getTrapEnterprise()
The type of the object generating the trap. |
int |
getTrapGenericType()
The generic type of the trap being sent. |
int |
getTrapSpecificType()
The specific type of the trap being sent. |
int |
getTrapTimeStamp()
Time passed since the agent was initialized (in hundredths of a second). |
boolean |
isActive()
Enables or disables sending and receiving of SNMP packets. |
boolean |
isShareLocalPort()
If set to True, allows more than one instance of the component to be Active on the same LocalPort . |
void |
removeSnmpEventListener(SnmpEventListener l)
|
void |
setAction(int action)
An action code for the component. |
void |
setActive(boolean active)
Enables or disables sending and receiving of SNMP packets. |
void |
setCommunity(java.lang.String community)
The community string used to authenticate SNMP packets. |
void |
setErrorIndex(int errorIndex)
Index of the first variable (object) that caused an error. |
void |
setErrorStatus(int errorStatus)
Status code for outgoing 'Get-Response' packets. |
void |
setInBufferSize(int inBufferSize)
The size in bytes of the incoming queue of the socket. |
void |
setLocalPort(int localPort)
The UDP port in the local host where the SNMP component listens to. |
void |
setObjCount(int objCount)
Number of objects in the current request. |
void |
setObjId(int objIndex,
java.lang.String objId)
Array of OIDs encoded as strings. |
void |
setObjType(int objIndex,
int objType)
Array of object types. |
void |
setObjValue(int objIndex,
byte[] objValue)
Array of object values. |
void |
setOutBufferSize(int outBufferSize)
The size in bytes of the outgoing queue of the socket. |
void |
setRemoteHost(java.lang.String remoteHost)
The address of the remote host. |
void |
setRemotePort(int remotePort)
The UDP port where the remote SNMP agent is listening. |
void |
setRequestId(int requestId)
The request-id to mark outgoing packets with. |
void |
setShareLocalPort(boolean shareLocalPort)
If set to True, allows more than one instance of the component to be Active on the same LocalPort . |
void |
setTrapAgentAddress(java.lang.String trapAgentAddress)
The address of the object generating the trap. |
void |
setTrapEnterprise(java.lang.String trapEnterprise)
The type of the object generating the trap. |
void |
setTrapGenericType(int trapGenericType)
The generic type of the trap being sent. |
void |
setTrapSpecificType(int trapSpecificType)
The specific type of the trap being sent. |
void |
setTrapTimeStamp(int trapTimeStamp)
Time passed since the agent was initialized (in hundredths of a second). |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
toString,
wait,
wait,
wait |
Field Detail |
public static final int a_Reset
public static final int a_SendGetRequest
public static final int a_SendGetNextRequest
public static final int a_SendSetRequest
public static final int a_SendGetResponse
public static final int a_SendTrap
public static final int ot_Integer
public static final int ot_OctetString
public static final int ot_Null
public static final int ot_ObjectId
public static final int ot_IPAddress
public static final int ot_Counter32
public static final int ot_Gauge32
public static final int ot_TimeTicks
public static final int ot_Opaque
public static final int ot_NSAP
public static final int ot_Counter64
public static final int ot_UnsignedInteger32
public static final int tgt_ColdStart
public static final int tgt_WarmStart
public static final int tgt_LinkDown
public static final int tgt_LinkUp
public static final int tgt_AuthenticationFailure
public static final int tgt_EGPNeighborLoss
public static final int tgt_EnterpriseSpecific
Constructor Detail |
public Snmp()
Method Detail |
public int getAction()
For every action except 'Reset' the class creates an SNMP packet based on the values provided in the correspoding properties (described below), and attempts to send it to RemoteHost at the port specified by RemotePort .
The class attempts to send the packet as a complete message. If the socket buffer is full, or the message cannot be delivered for any other reason, an error is returned, and no portion of the packet is sent. You may then try to resend the packet later.
The same thing may happend if you are sending packets to the remote host faster than it can process them, or faster than the network's bandwidth allows. If this is the case, the assignment to Action
The following are the possible values for the Action property:
public void setAction(int action) throws IPWorksException
For every action except 'Reset' the class creates an SNMP packet based on the values provided in the correspoding properties (described below), and attempts to send it to RemoteHost at the port specified by RemotePort .
The class attempts to send the packet as a complete message. If the socket buffer is full, or the message cannot be delivered for any other reason, an error is returned, and no portion of the packet is sent. You may then try to resend the packet later.
The same thing may happend if you are sending packets to the remote host faster than it can process them, or faster than the network's bandwidth allows. If this is the case, the assignment to Action
The following are the possible values for the Action property:
public boolean isActive()
public void setActive(boolean active) throws IPWorksException
public java.lang.String getCommunity()
Typical values are "public" or "private".
This property is used when SNMP packets are sent via the Action property. When a packet is received through events such as Trap , GetRequest etc.., the corresponding value is provided through the respective event parameter.
public void setCommunity(java.lang.String community) throws IPWorksException
Typical values are "public" or "private".
This property is used when SNMP packets are sent via the Action property. When a packet is received through events such as Trap , GetRequest etc.., the corresponding value is provided through the respective event parameter.
public int getErrorIndex()
Variable indexes start with 0. The ErrorIndex property has no meaning when the ErrorStatus property is 0 (no error).
public void setErrorIndex(int errorIndex) throws IPWorksException
Variable indexes start with 0. The ErrorIndex property has no meaning when the ErrorStatus property is 0 (no error).
public int getErrorStatus()
Possible values include:
The default value is 0 (no error).
public void setErrorStatus(int errorStatus) throws IPWorksException
Possible values include:
The default value is 0 (no error).
public int getInBufferSize()
Some TCP/IP implementations do not support variable buffer sizes. If that is the case, when class is activated the InBufferSize property reverts to its defined size. The same happens if you attempt to make it too large or too small.
public void setInBufferSize(int inBufferSize) throws IPWorksException
Some TCP/IP implementations do not support variable buffer sizes. If that is the case, when class is activated the InBufferSize property reverts to its defined size. The same happens if you attempt to make it too large or too small.
public int getLocalPort()
Setting it to 0 (default) allows Winsock to choose a port at random. The value chosen is provided via the $rpLocalPort; property after the class is activated through the Active property.
If you are implementing an SNMP Agent, then LocalPort must be set to 161 to listen for SNMP requests, or 162 to listen for SNMP traps. Note that only one application on the machine may bind to a particular port, so use this property carefully.
LocalPort cannot be changed once the class is Active . Any attempt to set the LocalPort property when the class is Active will generate an error.
public void setLocalPort(int localPort) throws IPWorksException
Setting it to 0 (default) allows Winsock to choose a port at random. The value chosen is provided via the $rpLocalPort; property after the class is activated through the Active property.
If you are implementing an SNMP Agent, then LocalPort must be set to 161 to listen for SNMP requests, or 162 to listen for SNMP traps. Note that only one application on the machine may bind to a particular port, so use this property carefully.
LocalPort cannot be changed once the class is Active . Any attempt to set the LocalPort property when the class is Active will generate an error.
public int getObjCount()
The arrays may be cleared at any time by setting the ObjCount to 0.
public void setObjCount(int objCount) throws IPWorksException
The arrays may be cleared at any time by setting the ObjCount to 0.
public java.lang.String getObjId(int objIndex) throws IPWorksException
The size of the array is determined by the ObjCount property. Element indexes start at 1.
The array is populated and its size is set every time an SNMP packet is received. It is also used to create an outgoing SNMP packet when the Action is set.
The corresponding object type and value (if any) are specified by the ObjType and ObjValue property arrays.
public void setObjId(int objIndex, java.lang.String objId) throws IPWorksException
The size of the array is determined by the ObjCount property. Element indexes start at 1.
The array is populated and its size is set every time an SNMP packet is received. It is also used to create an outgoing SNMP packet when the Action is set.
The corresponding object type and value (if any) are specified by the ObjType and ObjValue property arrays.
public int getObjType(int objIndex) throws IPWorksException
The array is populated and its size is set every time an SNMP packet is received. It is also used to create an outgoing SNMP packet when the Action is set. The default type is OCTET STRING (4).
The corresponding object id and value are specified by the ObjId and ObjValue property arrays.
Possible values include:
public void setObjType(int objIndex, int objType) throws IPWorksException
The array is populated and its size is set every time an SNMP packet is received. It is also used to create an outgoing SNMP packet when the Action is set. The default type is OCTET STRING (4).
The corresponding object id and value are specified by the ObjId and ObjValue property arrays.
Possible values include:
public byte[] getObjValue(int objIndex) throws IPWorksException
The array is populated and its size is set every time an SNMP packet is received. It is also used to create an outgoing SNMP packet when the Action is set.
The corresponding object id and type are specified by the ObjId and ObjType property arrays.
public void setObjValue(int objIndex, byte[] objValue) throws IPWorksException
The array is populated and its size is set every time an SNMP packet is received. It is also used to create an outgoing SNMP packet when the Action is set.
The corresponding object id and type are specified by the ObjId and ObjType property arrays.
public int getOutBufferSize()
Some TCP/IP implementations do not support variable buffer sizes. If that is the case, when the class is activated the OutBufferSize property reverts to its defined size. The same happens if you attempt to make it too large or too small.
public void setOutBufferSize(int outBufferSize) throws IPWorksException
Some TCP/IP implementations do not support variable buffer sizes. If that is the case, when the class is activated the OutBufferSize property reverts to its defined size. The same happens if you attempt to make it too large or too small.
public java.lang.String getRemoteHost()
If RemoteHost is set to 255.255.255.255, the class broadcasts data on the local subnet.
If the RemoteHost property is set to a Domain Name, a DNS request is initiated and upon successful termination of the request, the RemoteHost property is set to the corresponding address. If the search is not successful, an error is returned.
public void setRemoteHost(java.lang.String remoteHost) throws IPWorksException
If RemoteHost is set to 255.255.255.255, the class broadcasts data on the local subnet.
If the RemoteHost property is set to a Domain Name, a DNS request is initiated and upon successful termination of the request, the RemoteHost property is set to the corresponding address. If the search is not successful, an error is returned.
public int getRemotePort()
A valid port number (a value between 1 and 65535) is required. The special value 0 directs class to automatically select 161 for SNMP requests and 162 for SNMP traps.
public void setRemotePort(int remotePort) throws IPWorksException
A valid port number (a value between 1 and 65535) is required. The special value 0 directs class to automatically select 161 for SNMP requests and 162 for SNMP traps.
public int getRequestId()
public void setRequestId(int requestId) throws IPWorksException
public boolean isShareLocalPort()
public void setShareLocalPort(boolean shareLocalPort) throws IPWorksException
public java.lang.String getTrapAgentAddress()
This property is used when traps are sent via the Action property. When a trap is received through the Trap event, the corresponding value is provided through the respective event parameter.
public void setTrapAgentAddress(java.lang.String trapAgentAddress) throws IPWorksException
This property is used when traps are sent via the Action property. When a trap is received through the Trap event, the corresponding value is provided through the respective event parameter.
public java.lang.String getTrapEnterprise()
This property is used when traps are sent via the Action property. When a trap is received through the Trap event, the corresponding value is provided through the respective event parameter.
public void setTrapEnterprise(java.lang.String trapEnterprise) throws IPWorksException
This property is used when traps are sent via the Action property. When a trap is received through the Trap event, the corresponding value is provided through the respective event parameter.
public int getTrapGenericType()
Possible values of TrapGenericType include:
public void setTrapGenericType(int trapGenericType) throws IPWorksException
Possible values of TrapGenericType include:
public int getTrapSpecificType()
public void setTrapSpecificType(int trapSpecificType) throws IPWorksException
public int getTrapTimeStamp()
public void setTrapTimeStamp(int trapTimeStamp) throws IPWorksException
public java.lang.String getLocalHost()
If the class is connected, the LocalHost property shows the IP address of the interface through which the connection is made in internet dotted format (aaa.bbb.ccc.ddd). In most cases, this is the address of the local host, except for multihomed hosts (machines with more than one IP interface).
public void fireGetNextRequest(int requestId, java.lang.String community, java.lang.String sourceAddress, int sourcePort)
SnmpGetNextRequestEvent
public void fireGetRequest(int requestId, java.lang.String community, java.lang.String sourceAddress, int sourcePort)
SnmpGetRequestEvent
public void fireGetResponse(int requestId, java.lang.String community, int errorStatus, int errorIndex, java.lang.String sourceAddress, int sourcePort)
SnmpGetResponseEvent
public void fireReadyToSend()
SnmpReadyToSendEvent
public void fireSetRequest(int requestId, java.lang.String community, java.lang.String sourceAddress, int sourcePort)
SnmpSetRequestEvent
public void fireTrap(java.lang.String community, java.lang.String enterprise, java.lang.String agentAddress, int genericType, int specificType, int timeStamp, java.lang.String sourceAddress, int sourcePort)
SnmpTrapEvent
public void fireError(int errorCode, java.lang.String description)
SnmpErrorEvent
public void addSnmpEventListener(SnmpEventListener l) throws java.util.TooManyListenersException
public void removeSnmpEventListener(SnmpEventListener l)
|
![]() |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |