Package org.snmp4j.agent.agentx.master
Class AgentXCommandProcessor
java.lang.Object
org.snmp4j.agent.CommandProcessor
org.snmp4j.agent.agentx.master.AgentXCommandProcessor
- All Implemented Interfaces:
EventListener
,AgentXCommandListener
,AgentXResponseListener
,org.snmp4j.agent.NotificationOriginator
,org.snmp4j.CommandResponder
,org.snmp4j.transport.TransportStateListener
public class AgentXCommandProcessor
extends org.snmp4j.agent.CommandProcessor
implements AgentXCommandListener, org.snmp4j.transport.TransportStateListener, AgentXResponseListener
The
AgentXCommandProcessor
implements the CommandProcessor
interface for AgentX command processing of an AgentX master agent.
It holds the AgentX sessions and region registrations internally.
The context engine ID of the master agent, the AgentXQueue
,
the AgentX
protocol adapter, and the MOServer
s have
to be provided for instance creation.- Author:
- Frank Fock
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
Comparator forAgentXCommandProcessor.AgentXRegEntryComparator
to compare objects by context and region. -
Field Summary
Modifier and TypeFieldDescriptionprotected AgentXIndexRegistry
Index registry of the AgentX master agent.static final int
The default maximum reprocessing count.Fields inherited from class org.snmp4j.agent.CommandProcessor
coexistenceProvider, lockNonNextRequestsSortedByVbOid, moServers, notificationOriginator, ownContextEngineIDs, pduHandler, proxyForwarder, requestFactory, requestList, threadPool, vacm
-
Constructor Summary
ConstructorDescriptionAgentXCommandProcessor
(org.snmp4j.smi.OctetString contextEngineID, AgentXQueue queue, AgentX agentX, org.snmp4j.agent.MOServer[] server) Creates anAgentXCommandProcessor
using aAgentX
entity and an array ofMOServer
instances representing the master agentsManagedObject
s. -
Method Summary
Modifier and TypeMethodDescriptionprotected int
acceptSession
(AgentXMasterSession<?> session) Accept a new session and fire the correspondingAgentXMasterEvent.SESSION_ADDED
event.addAgentCaps
(AgentXAddAgentCapsPDU pdu, AgentXMasterSession<?> session) Process anAgentXAddAgentCapsPDU
.void
Adds aAgentXMasterListener
.protected void
addPeer
(AgentXPeer<?> peer) Adds an AgentXPeer and fires the correspondingAgentXMasterEvent
.protected void
addRegion
(AgentXRegEntry<?> registration, AgentXRegion region) Adds a region to the registry.protected void
addRegistration
(AgentXRegEntry<?> registration) Adds a registration to this master server.protected void
addSession
(AgentXMasterSession<?> session) Add a new session and fire the correspondingAgentXMasterEvent.SESSION_ADDED
event.Map
<AgentXSession<?>, Integer> closeAllSessions
(byte reason) Close all sessions associated with thisAgentXCommandListener
and return the AgentX status of the close operation together with theAgentXSession
object.protected AgentXPeer
<?> closePeer
(org.snmp4j.smi.Address peerAddress, byte reason) Close a peer, i.e.closeSession
(AgentXClosePDU pdu, AgentXMasterSession<?> session) Process anAgentXClosePDU
, close the session and remove all registrations.<A extends org.snmp4j.smi.Address>
intcloseSession
(AgentXMasterSession<A> session, byte reason) Close the specifiedAgentXSession
.void
connectionStateChanged
(org.snmp4j.transport.TransportStateEvent change) Process a connection state change, i.e.protected AgentXResponsePDU
createResponse
(AgentXPDU request, AgentXSession<?> session) Create a response for an AgentX request.protected <A extends org.snmp4j.smi.Address>
voidfinalizeRequest
(org.snmp4j.CommandResponderEvent<A> command, org.snmp4j.agent.request.SnmpRequest req, org.snmp4j.agent.MOServer server) Finish a request a free all related resources.protected void
Fire aAgentXMasterEvent
protected org.snmp4j.agent.mo.snmp.AgentCapabilityList
getAgentCaps
(org.snmp4j.smi.OctetString contextName) Gets the Agent-Capabilities for a context.byte
Gets the AgentX version.protected org.snmp4j.smi.TimeTicks
getContextSysUpTime
(org.snmp4j.smi.OctetString context) Gets the sysUpTime for the specified context.byte
Gets the default timeout for this AgentX entity.int
Gets the maximum number of consecutive timeouts allowed per session.int
Gets the upper limit for parse errors for an AgentX peer.int
Gets the request maximum reprocessing value.protected int
Gets the next session ID.protected <A extends org.snmp4j.smi.Address>
AgentXPeer<A> getPeer
(A address) Gets a peer based on its address.org.snmp4j.agent.MOServer
Deprecated.protected AgentXMasterSession
<?> getSession
(int sessionID) Gets the session for a given session ID.protected AgentXMasterSession
<?> getSession
(AgentXPDU pdu) Gets the session for anAgentXPDU
.indexAllocate
(AgentXIndexAllocatePDU pdu, AgentXMasterSession<?> session) Allocate an index.indexDeallocate
(AgentXIndexDeallocatePDU pdu, AgentXMasterSession<?> session) Deallocate an index.boolean
Indicates whether subagents can register contexts that are not yet supported by this master agent.protected boolean
isDuplicate
(AgentXRegEntry<?> registration) Checks whether a new registration is a duplicate.protected AgentXResponsePDU
notify
(AgentXNotifyPDU pdu, AgentXMasterSession<?> session) Process a notification PDU for anAgentXSession
.void
onResponse
(AgentXResponseEvent<?> event) Process anAgentXResponseEvent
.<A extends org.snmp4j.smi.Address>
AgentXResponsePDUopenSession
(AgentXOpenPDU pdu, AgentXCommandEvent<A> event) Opens a new AgentX session.protected AgentXResponsePDU
ping
(AgentXPingPDU pdu, AgentXMasterSession<?> session) Respond to a Ping request.protected void
processAgentXBulkResponse
(AgentXPending<?> pending, AgentXResponsePDU pdu) Process an AgentX-GETBULK-Response.protected void
processAgentXGetNextResponse
(AgentXPending<?> pending, AgentXResponsePDU pdu) Process a pending GETNEXT response.protected void
processAgentXGetResponse
(AgentXPending<?> pending, AgentXResponsePDU pdu) Process a pending GET response.protected void
processAgentXSetResponse
(AgentXPending<?> pending, AgentXResponsePDU pdu) Process a pending SET response.<A extends org.snmp4j.smi.Address>
voidprocessCommand
(AgentXCommandEvent<A> event) Process anAgentXCommandEvent
.protected static void
processsErrorResponse
(AgentXPending<?> pending, AgentXResponsePDU pdu) Process an error response.protected <A extends org.snmp4j.smi.Address>
AgentXResponsePDUregister
(AgentXRegisterPDU pdu, AgentXCommandEvent<A> command, AgentXMasterSession<A> session) Process aAgentXRegisterPDU
.removeAgentCaps
(AgentXRemoveAgentCapsPDU pdu, AgentXMasterSession<?> session) Process anAgentXRemoveAgentCapsPDU
.void
Remove aAgentXMasterListener
.protected void
removeAllRegistrations
(AgentXMasterSession<?> session) Remove all registrations for a session.protected AgentXPeer
<?> removePeer
(org.snmp4j.smi.Address peerAddress) Removes a peer and all its sessions.protected boolean
removeRegistration
(AgentXRegEntry<?> registration, Iterator<AgentXRegEntry<?>> regIterator) Remove a registrationprotected AgentXMasterSession
<?> removeSession
(int sessionID) Remove a session.protected <A extends org.snmp4j.smi.Address>
voidsendResponse
(AgentXPDU response, AgentXSession<A> session) Sends a response to a session.void
setAcceptNewContexts
(boolean acceptNewContexts) Enables or disables accepting new contexts from subagents.void
setDefaultTimeout
(byte defaultTimeout) Sets the default timeout.void
setMaxConsecutiveTimeouts
(int maxConsecutiveTimeouts) Sets the maximum number of timeouts allowed per session.void
setMaxParseErrors
(int maxParseErrors) Sets the maximum number of parse errors allowed per peer.void
setMaxReprocessing
(int maxReprocessing) Sets the maximum reprocessing.protected <A extends org.snmp4j.smi.Address>
AgentXResponsePDUunregister
(AgentXUnregisterPDU pdu, AgentXCommandEvent<A> event, AgentXMasterSession<A> session) Process aAgentXUnregisterPDU
.Methods inherited from class org.snmp4j.agent.CommandProcessor
addCounterListener, addMOServer, addPduHandler, addProxyForwarder, dispatchCommand, fireIncrementCounter, getCoexistenceProvider, getContextEngineID, getHandler, getInternalRequestTimeout, getNotificationOriginator, getProxyForwarder, getRequestList, getServer, getVacm, getViewName, isContextNotSupported, isLockNonNextRequestsSortedByVbOid, notify, notify, processNextSubRequest, processPdu, processRequest, processRequest, release, removeCounterListener, removeMOServer, removePduHandler, removeProxyForwarder, reprocessRequest, sendResponse, setAuthorizationError, setCoexistenceProvider, setContextEngineID, setInternalRequestTimeout, setLockNonNextRequestsSortedByVbOid, setNotificationOriginator, setThreadPool, setVacm, setWorkerPool, unlockManagedObjectIfLockedByLookup
-
Field Details
-
MAX_REPROCESSING_DEFAULT
public static final int MAX_REPROCESSING_DEFAULTThe default maximum reprocessing count. This value should be high enough to allow enough GETBULK repetitions but low enough to avoid sub-agent overload, if reprocessing fails.- See Also:
-
indexRegistry
Index registry of the AgentX master agent.
-
-
Constructor Details
-
AgentXCommandProcessor
public AgentXCommandProcessor(org.snmp4j.smi.OctetString contextEngineID, AgentXQueue queue, AgentX agentX, org.snmp4j.agent.MOServer[] server) Creates anAgentXCommandProcessor
using aAgentX
entity and an array ofMOServer
instances representing the master agentsManagedObject
s.- Parameters:
contextEngineID
- the context engine ID of associated with this AgentX command processor (by default the master agent's local engine ID).queue
- theAgentXQueue
to store pending requests.agentX
- theAgentX
server.server
- the managed objects of the master agent.
-
-
Method Details
-
setMaxReprocessing
public void setMaxReprocessing(int maxReprocessing) Sets the maximum reprocessing. Default isMAX_REPROCESSING_DEFAULT
- Parameters:
maxReprocessing
- the maximum reprocessing of AgentX requests.
-
getMaxReprocessing
public int getMaxReprocessing()Gets the request maximum reprocessing value.- Returns:
- the maximum reprocessing count of AgentX requests.
-
setMaxParseErrors
public void setMaxParseErrors(int maxParseErrors) Sets the maximum number of parse errors allowed per peer. If this number is exceeded then the peer will be closed with reasonAgentXProtocol.REASON_PARSE_ERROR
.- Parameters:
maxParseErrors
- a positive value (including zero) sets the upper limit of parse errors tolerated per peer. If the number of parse errors exceeds this limit, all sessions with that peer will be closed. A negative value deactivates any limit.- Since:
- 1.0.1
-
getMaxParseErrors
public int getMaxParseErrors()Gets the upper limit for parse errors for an AgentX peer.- Returns:
- a positive value (including zero) indicates the upper limit of parse errors tolerated per peer. A negative value indicates that there is no limit.
- Since:
- 1.0.1
-
finalizeRequest
protected <A extends org.snmp4j.smi.Address> void finalizeRequest(org.snmp4j.CommandResponderEvent<A> command, org.snmp4j.agent.request.SnmpRequest req, org.snmp4j.agent.MOServer server) Finish a request a free all related resources.- Overrides:
finalizeRequest
in classorg.snmp4j.agent.CommandProcessor
- Parameters:
command
- the request processed.req
- the associatedSnmpRequest
.server
- theMOServer
to reprocess the request, if necessary.
-
getNextSessionID
protected int getNextSessionID()Gets the next session ID.- Returns:
- a new session ID.
-
getServer
Deprecated.UseCommandProcessor.getServer(OctetString context)
instead.Gets the default server (for thenull
context).- Returns:
- the default server instance.
-
getDefaultTimeout
public byte getDefaultTimeout()Gets the default timeout for this AgentX entity.- Returns:
- the timout in seconds.
-
getMaxConsecutiveTimeouts
public int getMaxConsecutiveTimeouts()Gets the maximum number of consecutive timeouts allowed per session.- Returns:
- the maximum number of consecutive timeouts allowed per session
-
isAcceptNewContexts
public boolean isAcceptNewContexts()Indicates whether subagents can register contexts that are not yet supported by this master agent.- Returns:
true
if subagents can register objects for new contexts.
-
setDefaultTimeout
public void setDefaultTimeout(byte defaultTimeout) Sets the default timeout.- Parameters:
defaultTimeout
- the default timeout in seconds.
-
setMaxConsecutiveTimeouts
public void setMaxConsecutiveTimeouts(int maxConsecutiveTimeouts) Sets the maximum number of timeouts allowed per session. If the number is exceeded then the session will be closed with reasonAgentXProtocol.REASON_TIMEOUTS
.- Parameters:
maxConsecutiveTimeouts
- the maximum number of timeouts (should be greater than zero).
-
setAcceptNewContexts
public void setAcceptNewContexts(boolean acceptNewContexts) Enables or disables accepting new contexts from subagents.- Parameters:
acceptNewContexts
-true
if subagents are allowed to register objects for new contexts,false
otherwise. Default isfalse
.
-
processCommand
Process anAgentXCommandEvent
.- Specified by:
processCommand
in interfaceAgentXCommandListener
- Type Parameters:
A
-Address
type of peer that trigger this command.- Parameters:
event
- the AgentX message and necessary context information.
-
indexDeallocate
public AgentXResponsePDU indexDeallocate(AgentXIndexDeallocatePDU pdu, AgentXMasterSession<?> session) Deallocate an index.- Parameters:
pdu
- the deallocation PDU.session
- the session deallocating.- Returns:
- the
AgentXResponsePDU
.
-
indexAllocate
Allocate an index.- Parameters:
pdu
- the allocation PDU.session
- the session allocating.- Returns:
- the
AgentXResponsePDU
.
-
processAgentXBulkResponse
Process an AgentX-GETBULK-Response.- Parameters:
pending
- the pending GETBULK requestpdu
- the response PDU.
-
processsErrorResponse
protected static void processsErrorResponse(AgentXPending<?> pending, AgentXResponsePDU pdu) throws NoSuchElementException Process an error response.- Parameters:
pending
- the pending GETBULK requestpdu
- the response PDU.- Throws:
NoSuchElementException
- if there are less sub-request in the pending request that reported by the error statusof the response PDU.
-
ping
Respond to a Ping request.- Parameters:
pdu
- the ping request.session
- the session that received the request.- Returns:
- the ping response PDU.
-
notify
Process a notification PDU for anAgentXSession
.- Parameters:
pdu
- the notification PDU.session
- the source session.- Returns:
- the notification PDU response.
-
getContextSysUpTime
protected org.snmp4j.smi.TimeTicks getContextSysUpTime(org.snmp4j.smi.OctetString context) Gets the sysUpTime for the specified context.- Parameters:
context
- a SNMPv3 context (or an emptyOctetString
for the default context).- Returns:
TimeTicks
value representing the context's sysUpTime.0.
-
addAgentCaps
Process anAgentXAddAgentCapsPDU
.- Parameters:
pdu
- the addAgentCaps-PDU.session
- the source session.- Returns:
- the
AgentXResponsePDU
-
getAgentCaps
protected org.snmp4j.agent.mo.snmp.AgentCapabilityList getAgentCaps(org.snmp4j.smi.OctetString contextName) Gets the Agent-Capabilities for a context.- Parameters:
contextName
- a context name.- Returns:
- the
AgentCapabilityList
associated with the context ornull
if that does not exist.
-
removeAgentCaps
public AgentXResponsePDU removeAgentCaps(AgentXRemoveAgentCapsPDU pdu, AgentXMasterSession<?> session) Process anAgentXRemoveAgentCapsPDU
.- Parameters:
pdu
- the removeAgentCaps-PDU.session
- the source session.- Returns:
- the
AgentXResponsePDU
-
closeSession
Process anAgentXClosePDU
, close the session and remove all registrations.- Parameters:
pdu
- the close-PDU.session
- the source session.- Returns:
- the
AgentXResponsePDU
-
closeAllSessions
Close all sessions associated with thisAgentXCommandListener
and return the AgentX status of the close operation together with theAgentXSession
object.- Specified by:
closeAllSessions
in interfaceAgentXCommandListener
- Parameters:
reason
- the AgentX reason (AgentXProtocol.REASON_SHUTDOWN
,AgentXProtocol.REASON_TIMEOUTS
,AgentXProtocol.REASON_BY_MANAGER
,AgentXProtocol.REASON_PROTOCOL_ERROR
,AgentXProtocol.REASON_PARSE_ERROR
,AgentXProtocol.REASON_OTHER
) for closing the session.- Returns:
- a map of the AgentXSession session objects hold by this agent and the corresponding AgentX error code. An
error code of
AgentXProtocol.AGENTX_SUCCESS
indicates that this session was successfully closed. - Since:
- 3.0.0
-
closeSession
public <A extends org.snmp4j.smi.Address> int closeSession(AgentXMasterSession<A> session, byte reason) Close the specifiedAgentXSession
.- Type Parameters:
A
- the address type.- Parameters:
session
- theAgentXSession
to close.reason
- the AgentX reason (AgentXProtocol.REASON_SHUTDOWN
,AgentXProtocol.REASON_TIMEOUTS
,AgentXProtocol.REASON_BY_MANAGER
,AgentXProtocol.REASON_PROTOCOL_ERROR
,AgentXProtocol.REASON_PARSE_ERROR
,AgentXProtocol.REASON_OTHER
) for closing the session.- Returns:
- the AgentX error/status code.
AgentXProtocol.AGENTX_SUCCESS
is returned on success.
-
removeAllRegistrations
Remove all registrations for a session.- Parameters:
session
- aAgentXSession
to clean its registrations.
-
getSession
Gets the session for a given session ID.- Parameters:
sessionID
- a session ID.- Returns:
- the associated session or
null
if the session could not be found.
-
getSession
Gets the session for anAgentXPDU
.- Parameters:
pdu
- a PDU.- Returns:
- the session for the specified PDU.
-
register
protected <A extends org.snmp4j.smi.Address> AgentXResponsePDU register(AgentXRegisterPDU pdu, AgentXCommandEvent<A> command, AgentXMasterSession<A> session) Process aAgentXRegisterPDU
.- Type Parameters:
A
- the address type.- Parameters:
pdu
- the PDU.command
- the AgentX command.session
- the master agent session.- Returns:
- the response PDU.
-
unregister
protected <A extends org.snmp4j.smi.Address> AgentXResponsePDU unregister(AgentXUnregisterPDU pdu, AgentXCommandEvent<A> event, AgentXMasterSession<A> session) Process aAgentXUnregisterPDU
.- Type Parameters:
A
- the address type.- Parameters:
pdu
- the PDU.event
- the AgentX command.session
- the master agent session.- Returns:
- the response PDU.
-
isDuplicate
Checks whether a new registration is a duplicate.- Parameters:
registration
- a MIB region registration.- Returns:
true
if another region with same or lower priority value intersects/overlaps with this region.
-
addRegistration
protected void addRegistration(AgentXRegEntry<?> registration) throws org.snmp4j.agent.DuplicateRegistrationException Adds a registration to this master server.- Parameters:
registration
- a MIB region registration.- Throws:
org.snmp4j.agent.DuplicateRegistrationException
- if there is already another registration with lower priority value that overlaps/intersects with this region.
-
addRegion
protected void addRegion(AgentXRegEntry<?> registration, AgentXRegion region) throws org.snmp4j.agent.DuplicateRegistrationException Adds a region to the registry.- Parameters:
registration
- a new registration.region
- the new region to add to an existing registration.- Throws:
org.snmp4j.agent.DuplicateRegistrationException
- if there is already MIB region with lower or same priority value registered that intersects/overlaps with this region.
-
removeRegistration
protected boolean removeRegistration(AgentXRegEntry<?> registration, Iterator<AgentXRegEntry<?>> regIterator) Remove a registration- Parameters:
registration
- the registration to be removed.regIterator
- an iterator on all region requests to be removed.- Returns:
true
if a region was removed,false
otherwise.
-
openSession
public <A extends org.snmp4j.smi.Address> AgentXResponsePDU openSession(AgentXOpenPDU pdu, AgentXCommandEvent<A> event) Opens a new AgentX session.- Type Parameters:
A
- the address type.- Parameters:
pdu
- theAgentXOpenPDU
.event
- the AgentX command.- Returns:
- the
AgentXResponsePDU
.
-
addPeer
Adds an AgentXPeer and fires the correspondingAgentXMasterEvent
.- Parameters:
peer
- a peer to add.
-
getPeer
Gets a peer based on its address.- Type Parameters:
A
- the address type.- Parameters:
address
- an AgentX peer address.- Returns:
- the
AgentXPeer
if found ornull
if not.
-
acceptSession
Accept a new session and fire the correspondingAgentXMasterEvent.SESSION_ADDED
event.- Parameters:
session
- a session.- Returns:
- the veto reason, if the session has not been added or
AgentXProtocol.AGENTX_SUCCESS
otherwise.
-
addSession
Add a new session and fire the correspondingAgentXMasterEvent.SESSION_ADDED
event.- Parameters:
session
- a new session.
-
removeSession
Remove a session.- Parameters:
sessionID
- the session ID.- Returns:
- the removed
AgentXMasterSession
ornull
if the session no longer exists.
-
createResponse
Create a response for an AgentX request.- Parameters:
request
- an AgentX PDU.session
- a session.- Returns:
- the generated
AgentXResponsePDU
.
-
sendResponse
protected <A extends org.snmp4j.smi.Address> void sendResponse(AgentXPDU response, AgentXSession<A> session) Sends a response to a session.- Type Parameters:
A
- the address type.- Parameters:
response
- the response to be sent.session
- the session.
-
connectionStateChanged
public void connectionStateChanged(org.snmp4j.transport.TransportStateEvent change) Process a connection state change, i.e. remove the peer if the connect closed.- Specified by:
connectionStateChanged
in interfaceorg.snmp4j.transport.TransportStateListener
- Parameters:
change
- theTransportStateEvent
.
-
removePeer
Removes a peer and all its sessions.- Parameters:
peerAddress
- the peer's address.- Returns:
- the removed
AgentXPeer
.
-
closePeer
Close a peer, i.e. sending a close PDU to that peer.- Parameters:
peerAddress
- the peer to inform about the connection closing.reason
- the reason for closing the session(s), seeAgentXProtocol.REASON_OTHER
for example.- Returns:
- the closed peer.
-
getAgentXVersion
public byte getAgentXVersion()Gets the AgentX version.- Returns:
AgentXProtocol.VERSION_1_0
-
addAgentXMasterListener
Adds aAgentXMasterListener
.- Parameters:
l
- a listener AgentX master agent events.
-
removeAgentXMasterListener
Remove aAgentXMasterListener
.- Parameters:
l
- a listener AgentX master agent events.
-
fireMasterChanged
Fire aAgentXMasterEvent
- Parameters:
event
- the event to fire.
-
onResponse
Process anAgentXResponseEvent
.- Specified by:
onResponse
in interfaceAgentXResponseListener
- Parameters:
event
- an response event including request and response PDU.
-
processAgentXGetResponse
Process a pending GET response.- Parameters:
pending
- theAgentXPending
PDU.pdu
- theAgentXResponsePDU
returned.
-
processAgentXGetNextResponse
Process a pending GETNEXT response.- Parameters:
pending
- theAgentXPending
PDU.pdu
- theAgentXResponsePDU
returned.
-
processAgentXSetResponse
Process a pending SET response.- Parameters:
pending
- theAgentXPending
PDU.pdu
- theAgentXResponsePDU
returned.
-
CommandProcessor.getServer(OctetString context)
instead.