Dangerous SNMP
|
An AgentX represents an AgentX sub-agent. More...
#include <agentx.hpp>
Classes | |
class | OidRegistrationEntry |
An OidRegistrationEntry represents an OID that has been registered. More... | |
class | ValueEntry |
A ValueEntry represents an OID's value. More... | |
Public Member Functions | |
AgentX (const Context &context) | |
Constructor. More... | |
virtual | ~AgentX () |
Destructor. More... | |
void | uri (const std::string &uri) throw ( ParseErrorException, UnknownTransportException, Exception ) |
This sets the URI for the client. More... | |
void | identifier (const NumericOid &oid) |
This sets the identifier OID for the agent. More... | |
NumericOid | identifier () const |
This returns the identifier OID for the agent. More... | |
void | description (const std::string &text) |
This sets the description for the agent. More... | |
std::string | description () const |
This returns the description for the agent. More... | |
void | raw_addAgentCapabilities (const NumericOid &oid, const std::string &description) |
This sends an "AddAgentCaps" PDU to the master agent. More... | |
void | raw_removeAgentCapabilities (const NumericOid &oid) |
This sends a "RemoveAgentCaps" PDU to the master agent. More... | |
void | raw_registerTree (const NumericOid &oid, uint8_t priority=DEFAULT_PRIORITY) |
This sends a "Register" PDU to the master agent. More... | |
void | raw_registerOid (const NumericOid &oid, uint8_t priority=DEFAULT_PRIORITY) |
This sends a "Register" PDU to the master agent with a flag signifying "instance" registration. More... | |
void | addAgentCapabilities (const NumericOid &oid, const std::string &description) throw ( Exception ) |
This adds a new capability for the agent. More... | |
void | removeAgentCapabilities (const NumericOid &oid) throw ( Exception ) |
This removes a previously registered capability. More... | |
void | registerOid (const NumericOid &oid, const OidRegistrationEntry &entry) throw ( Exception ) |
This registers a new OID. More... | |
Static Public Attributes | |
static const uint8_t | DEFAULT_PRIORITY |
This is the default value for the "priority" of an OID registered with the "Register" PDU. More... | |
Protected Types | |
typedef std::map< NumericOid, std::string > | CapabilityMap |
A CapabilityMap maps an OID to a string. | |
typedef std::map< NumericOid, OidRegistrationEntry > | OidRegistrationMap |
An OidRegistrationMap maps an OID to its registration entry. | |
Protected Member Functions | |
OidRegistrationMap::const_iterator | registrationThatCovers (const NumericOid &oid) |
This returns the "oidRegistrationMap" iterator whose entry would be responsible for the OID given. More... | |
void | rawRead (AgentxPacket &packet) |
This reads an AgentxPacket from the transport. More... | |
void | rawWrite (AgentxPacket &packet) |
This writes an AgentxPacket to the transport. More... | |
void | open () |
This connects the agent to the master agent. More... | |
void | close () |
This disconnects the agent from the master agent. | |
void | startMailboxThread () |
This starts the mailbox thread, if it has not already been started. | |
void | stopMailboxThread () |
This stops the mailbox thread, if it has not already been stopped. | |
void | mailboxRead (AgentxPacket &packet, uint32_t packetId) throw ( Exception ) |
This attempts to obtain the packet, with the specified ID, from the mailbox. More... | |
void | mailboxMain () |
This is the main loop for the mailbox thread. | |
Protected Attributes | |
std::weak_ptr < Context::PrivateData > | context |
This is a weak pointer to the Context. | |
NumericOid | _identifier |
This is the OID that identifies the Agent; each Agent should have a unique identifying OID. More... | |
std::string | _description |
This is the description of the Agent. | |
std::unique_ptr< Transport > | transport |
This is a pointer to the "Transport" instance that will be used to communicate with the AgentX "master". More... | |
uint32_t | packetNumber |
This is a counter that is incremented for each packet sent by this agent. More... | |
uint32_t | sessionId |
This is the session ID, as given by the master agent. | |
std::mutex | readMutex |
This is the read mutex used for guaranteeing that only a single thread is working with the inbox for this agent at any one time. More... | |
std::condition_variable | readConditionVariable |
This is used to notify any waiting threads when a new packet is available from the inbox. More... | |
std::mutex | writeMutex |
This is the write mutex used for guaranteeing that only a single thread is speaking for this agent at any one time. More... | |
std::map< uint32_t, std::unique_ptr< AgentxPacket > > | inbox |
This represents an "inbox" of packets received from the master agent. More... | |
bool | isStopped |
This is whether or not the mailbox thread is "stopped"; if the thread has not been started, then it is stopped. More... | |
std::thread | mailboxThread |
This is the thread that runs the main loop for handling the mailbox. | |
CapabilityMap | capabilityMap |
This is the mapping of capability OID to its description; these are created by adding a new "capability" to the agent. More... | |
OidRegistrationMap | oidRegistrationMap |
This is the mapping of an OID to its registration entry. More... | |
An AgentX represents an AgentX sub-agent.
Such a sub-agent is loosely identified by two things:
Neither is particularly necessary, but these help to distinguish (on the master side) one agent from another.
Each instance will have its own thread for handling asynchronous operations (such as those received from the master agent). This is called the "mailbox" thread. This agent will be periodically receiving requests from the master agent; those requests will be stored in the "inbox"; they will be answered appropriately by the agent.
Sometimes, these will call user-specified callbacks, sometimes they won't.
|
virtual |
Destructor.
If the "mailbox" thread is running, then it is stopped.
void addAgentCapabilities | ( | const NumericOid & | oid, |
const std::string & | description | ||
) | |||
throw | ( | Exception | |
) |
This adds a new capability for the agent.
If this capability has already been registered, then an exception will be thrown.
oid | The OID that represents the capability. |
description | The description of the capability. |
|
inline |
This sets the description for the agent.
This must be set before a call to "open" in order to take effect.
text | The new description. |
|
inline |
This returns the description for the agent.
|
inline |
This sets the identifier OID for the agent.
This must be set before a call to "open" in order to take effect.
oid | The new identifier OID. |
|
inline |
This returns the identifier OID for the agent.
|
protected |
This attempts to obtain the packet, with the specified ID, from the mailbox.
If there is no such packet, then this will wait for at most 5 seconds before failing.
Exception conditions:
packet | The packet to store the data from the mailbox. |
packetId | The ID of the packet to retrieve. |
Exception |
|
protected |
This connects the agent to the master agent.
The identifier OID and description are sent to the master agent, and the "open" command is issued.
A session ID is obtained from the master agent, and any pending communication with it is voided.
void raw_addAgentCapabilities | ( | const NumericOid & | oid, |
const std::string & | description | ||
) |
void raw_registerOid | ( | const NumericOid & | oid, |
uint8_t | priority = DEFAULT_PRIORITY |
||
) |
void raw_registerTree | ( | const NumericOid & | oid, |
uint8_t | priority = DEFAULT_PRIORITY |
||
) |
void raw_removeAgentCapabilities | ( | const NumericOid & | oid | ) |
|
protected |
This reads an AgentxPacket from the transport.
packet | The packet in which to store the data. |
|
protected |
This writes an AgentxPacket to the transport.
packet | The packet to write. |
void registerOid | ( | const NumericOid & | oid, |
const OidRegistrationEntry & | entry | ||
) | |||
throw | ( | Exception | |
) |
This registers a new OID.
oid | The OID to register. |
entry | The registration information. |
Exception |
|
protected |
This returns the "oidRegistrationMap" iterator whose entry would be responsible for the OID given.
If the responsible entry is an OBJECT or INSTANCE registration, then its OID will match the one given exactly.
If the responsible entry is a TREE registration, then its OID will be the beginning of the one given.
oid | The OID to search for. |
void removeAgentCapabilities | ( | const NumericOid & | oid | ) | |
throw | ( | Exception | |||
) |
This removes a previously registered capability.
If this capability has not already been registered, then an exception will be thrown.
oid | The OID that represents the capability. |
Exception |
void uri | ( | const std::string & | uri | ) | |
throw | ( | ParseErrorException, | |||
UnknownTransportException, | |||||
Exception | |||||
) |
This sets the URI for the client.
A URI is of the form: {transport}://{address}
Currently, the following transports are supported:
When this is called, the transport is created, and a "mailbox" is created and started for the agent.
uri | The URI to use. |
|
protected |
This is the OID that identifies the Agent; each Agent should have a unique identifying OID.
This will be given to the master agent upon registration.
|
protected |
This is the mapping of capability OID to its description; these are created by adding a new "capability" to the agent.
|
static |
This is the default value for the "priority" of an OID registered with the "Register" PDU.
This is defined in RFC-2741.
|
protected |
This represents an "inbox" of packets received from the master agent.
This maps a packet ID to its packet.
|
protected |
This is whether or not the mailbox thread is "stopped"; if the thread has not been started, then it is stopped.
|
protected |
This is the mapping of an OID to its registration entry.
When operations are requested of us (Get, GetNext, GetBulk, Set), this will be consulted to (1) find the OID, and (2) perform the necessary action.
|
protected |
This is a counter that is incremented for each packet sent by this agent.
|
protected |
This is used to notify any waiting threads when a new packet is available from the inbox.
|
protected |
This is the read mutex used for guaranteeing that only a single thread is working with the inbox for this agent at any one time.
|
protected |
This is a pointer to the "Transport" instance that will be used to communicate with the AgentX "master".
This will be instantiated as a specific subclass of "Transport" when the URI is handled.
|
protected |
This is the write mutex used for guaranteeing that only a single thread is speaking for this agent at any one time.