AGENT++
4.0.3
|
The RequestList represents a non ordered queue of Requests. More...
#include <request.h>
Public Member Functions | |
RequestList () | |
Default constructor. | |
virtual | ~RequestList () |
Destructor (SYNCHRONIZED) | |
virtual void | set_address_validation (bool) |
Activate or deactivate source address validation for SNMP v1/v2c requests (SNMP-COMMUNITY-MIB). | |
bool | get_address_validation () |
Gets the current state of the source address validation for community base SNMP versions. | |
virtual void | set_snmp (Snmpx *session) |
Set the Snmpx session to be used for incoming requests. | |
Snmpx * | get_snmp () |
Get the Snmpx session used by this RequestList. | |
void | set_read_community (const NS_SNMP OctetStr &) |
Set READ community. | |
void | set_write_community (const NS_SNMP OctetStr &) |
Set WRITE community. | |
virtual Request * | receive (int) |
Wait a given time for an incoming request. | |
virtual unsigned long | get_request_id (const Vbx &) |
Return the corresponding request id of a request in the receiver RequestList that contains the specified variable binding. | |
virtual bool | done (unsigned long, int, const Vbx &) |
Mark a sub-request as done and put the result of the sub-request into the response PDU. | |
virtual void | error (unsigned long, int, int) |
Mark a sub-request as done with an error and put the corresponding SNMP error code for the sub-request into the response PDU. | |
virtual Request * | get_request (unsigned long) |
Return a pointer to the request identified by a given transaction id. | |
virtual Request * | find_request_on_id (unsigned long) |
Return a pointer to the request identified by a given request id. | |
virtual void | answer (Request *) |
Answer a Request by sending the corresponding response PDU. | |
unsigned long | create_transaction_id () |
Get next transaction id. | |
bool | is_empty () |
Check whether the request list (queue) is empty or not. | |
unsigned long | size () |
Get the actual size of the request list. | |
virtual void | remove_request (Request *req) |
Remove a request that should not be processed. | |
Public Member Functions inherited from ThreadManager | |
ThreadManager () | |
Default constructor. | |
virtual | ~ThreadManager () |
Destructor. | |
void | start_synch () |
Start synchronized execution. | |
void | end_synch () |
End synchronized execution. | |
Public Member Functions inherited from Synchronized | |
Synchronized () | |
~Synchronized () | |
void | wait () |
Causes current thread to wait until another thread invokes the notify() method or the notifyAll() method for this object. | |
bool | wait (unsigned long timeout) |
Causes current thread to wait until either another thread invokes the notify() method or the notifyAll() method for this object, or a specified amount of time has elapsed. | |
void | notify () |
Wakes up a single thread that is waiting on this object's monitor. | |
void | notify_all () |
Wakes up all threads that are waiting on this object's monitor. | |
bool | lock () |
Enter a critical section. | |
TryLockResult | trylock () |
Try to enter a critical section. | |
bool | unlock () |
Leave a critical section. | |
Protected Member Functions | |
virtual Request * | add_request (Request *) |
Add a Request to the RequestList. | |
virtual bool | community_ok (int, const NS_SNMP OctetStr &) |
Check whether a given community is acceptable for the specified PDU type. | |
virtual void | authenticationFailure (const NS_SNMP OctetStr &context, const NS_SNMP GenAddress &sourceAddress, int status) |
Sends an authenticationFailure notification if the corresponding MIB object is enabled. | |
Static Protected Member Functions | |
static void | null_vbs (Request *req) |
Set all variable bindings (for response) to null values. | |
Protected Attributes | |
List< Request > * | requests |
Snmpx * | snmp |
NS_SNMP OctetStr * | write_community |
NS_SNMP OctetStr * | read_community |
unsigned long | next_transaction_id |
bool | sourceAddressValidation |
Additional Inherited Members | |
Public Types inherited from Synchronized | |
enum | TryLockResult { LOCKED = 1, BUSY = 0, OWNED = -1 } |
Static Public Member Functions inherited from ThreadManager | |
static void | start_global_synch () |
Start global synchronized execution. | |
static void | end_global_synch () |
End global synchronized execution. | |
The RequestList represents a non ordered queue of Requests.
On multi-threaded SNMP agents this queue could contain more than one pending Request at once. The RequestList provides member functions to receive, process, lookup, and modify Requests.
The following example illustrates, how RequestList may be used in an v1 or v2c SNMP agent:
main (int argc, char* argv[]) { int status; Snmpx snmp(status, 161); // create SNMP++ session
if (status != SNMP_CLASS_SUCCESS) { // if fail print error cout << snmp.error_msg(status); // message exit(1); }
Mib mib; // create the agents MIB RequestList reqList;
mib.set_request_list(&reqList); // register RequestList // to be used by mib for outgoing requests
reqList.set_snmp(&snmp); // register the Snmpx object to // be used by the RequestList for incoming SNMP requests
mib.add(new systemGroup()); // add sysGroup and snmpGroup mib.add(new snmpGroup()); // (provided with AGENT++) to mib ...
Request* req; // pointer to an incoming SNMP request for (;;) { // loop forever (agent is a daemon)
// wait for incoming request max 120 sec // and then just loop once req = reqList.receive(120); if (req) mib.process_request(req); // process the request
} }
RequestList::RequestList | ( | ) |
Default constructor.
|
virtual |
Destructor (SYNCHRONIZED)
Add a Request to the RequestList.
(SYNCHRONIZED)
req | - A pointer to a Request. |
|
virtual |
|
protectedvirtual |
Sends an authenticationFailure notification if the corresponding MIB object is enabled.
context | in which the failure occured. In most cases this is the default context (""). |
sourceAddress | the source address of the host that sent the unauthenticated SNMP message. |
status | the error code that further classifies the authentication failure. |
|
protectedvirtual |
Check whether a given community is acceptable for the specified PDU type.
pdutype | - A PDU type (e.g., sNMP_PDU_SET, sNMP_PDU_GET, etc.) |
community | - A v1 or v2c community string. |
|
inline |
Get next transaction id.
|
virtual |
Mark a sub-request as done and put the result of the sub-request into the response PDU.
(SYNCHRONIZED)
request_id | a request id of a pending request. |
index | the index of the target sub-request. |
vb | a variable binding containing the result of an sub-request. |
|
virtual |
Mark a sub-request as done with an error and put the corresponding SNMP error code for the sub-request into the response PDU.
(SYNCHRONIZED)
request_id | a request id of a pending request. |
index | the index of a failed sub-request. |
err | an SNMP error status. |
|
virtual |
Return a pointer to the request identified by a given request id.
(NOT SYNCHRONIZED)
request_id | - A request id. |
|
inline |
Gets the current state of the source address validation for community base SNMP versions.
|
virtual |
Return a pointer to the request identified by a given transaction id.
(SYNCHRONIZED)
request_id | a transaction id. |
|
virtual |
Return the corresponding request id of a request in the receiver RequestList that contains the specified variable binding.
(SYNCHRONIZED)
vb | - A variable binding. |
|
inline |
Get the Snmpx session used by this RequestList.
|
inline |
Check whether the request list (queue) is empty or not.
|
staticprotected |
Set all variable bindings (for response) to null values.
req | a pointer to a Request instance. |
|
virtual |
Wait a given time for an incoming request.
timeout | The maximum time in seconds to wait for an incoming request. If timeout is 0 receive will not block, if it is <0 receive will wait forever. |
|
virtual |
Remove a request that should not be processed.
req | - The pointer returned from receive(), the pointer is invalid after this function returns. |
|
virtual |
Activate or deactivate source address validation for SNMP v1/v2c requests (SNMP-COMMUNITY-MIB).
sourceAddressFiltering | if TRUE incoming v1/v2c requests will be validated (not only) on the transport address including the UDP port. |
void RequestList::set_read_community | ( | const NS_SNMP OctetStr & | ) |
Set READ community.
readCommunity | the new community for all GET type requests. |
|
inlinevirtual |
void RequestList::set_write_community | ( | const NS_SNMP OctetStr & | ) |
Set WRITE community.
writeCommunity | the new community for SET requests. |
|
inline |
Get the actual size of the request list.
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |