RequestList Class Reference

The RequestList represents a non ordered queue of Requests. More...

#include <request.h>

Inheritance diagram for RequestList:

ThreadManager Synchronized

List of all members.

Public Member Functions

 RequestList ()
 Default constructor.
virtual ~RequestList ()
 Destructor (SYNCHRONIZED).
virtual void set_address_validation (boolean)
 Activate or deactivate source address validation for SNMP v1/v2c requests (SNMP-COMMUNITY-MIB).
boolean 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.
Snmpxget_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 Requestreceive (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 boolean 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 Requestget_request (unsigned long)
 Return a pointer to the request identified by a given transaction id.
virtual Requestfind_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.
boolean 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.

Protected Member Functions

virtual Requestadd_request (Request *)
 Add a Request to the RequestList.
virtual boolean 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
Snmpxsnmp
NS_SNMP OctetStr * write_community
NS_SNMP OctetStr * read_community
unsigned long next_transaction_id
boolean sourceAddressValidation


Detailed Description

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 } }

Author:
Frank Fock
Version:
3.5.14

Constructor & Destructor Documentation

RequestList::RequestList (  ) 

Default constructor.

virtual RequestList::~RequestList (  )  [virtual]

Destructor (SYNCHRONIZED).


Member Function Documentation

virtual void RequestList::set_address_validation ( boolean   )  [virtual]

Activate or deactivate source address validation for SNMP v1/v2c requests (SNMP-COMMUNITY-MIB).

Parameters:
sourceAddressFiltering if TRUE incoming v1/v2c requests will be validated (not only) on the transport address including the UDP port.

boolean RequestList::get_address_validation (  )  [inline]

Gets the current state of the source address validation for community base SNMP versions.

Returns:
TRUE if source address validation is activated.

virtual void RequestList::set_snmp ( Snmpx session  )  [inline, virtual]

Set the Snmpx session to be used for incoming requests.

Parameters:
session - A pointer to Snmpx instance.

Snmpx* RequestList::get_snmp (  )  [inline]

Get the Snmpx session used by this RequestList.

Returns:
a Snmpx instance.

void RequestList::set_read_community ( const NS_SNMP OctetStr &   ) 

Set READ community.

Parameters:
readCommunity the new community for all GET type requests.

void RequestList::set_write_community ( const NS_SNMP OctetStr &   ) 

Set WRITE community.

Parameters:
writeCommunity the new community for SET requests.

virtual Request* RequestList::receive ( int   )  [virtual]

Wait a given time for an incoming request.

Parameters:
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.
Returns:
A pointer to the received request or 0 if within the timeout period no request has been received.

virtual unsigned long RequestList::get_request_id ( const Vbx  )  [virtual]

Return the corresponding request id of a request in the receiver RequestList that contains the specified variable binding.

(SYNCHRONIZED)

Parameters:
vb - A variable binding.
Returns:
A request id or 0 if a corresponding request could not have been found.

virtual boolean RequestList::done ( unsigned  long,
int  ,
const Vbx  
) [virtual]

Mark a sub-request as done and put the result of the sub-request into the response PDU.

(SYNCHRONIZED)

Parameters:
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.
Returns:
TRUE if request is ready to answer, FALSE otherwise.

virtual void RequestList::error ( unsigned  long,
int  ,
int   
) [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)

Parameters:
request_id a request id of a pending request.
index the index of a failed sub-request.
err an SNMP error status.

virtual Request* RequestList::get_request ( unsigned  long  )  [virtual]

Return a pointer to the request identified by a given transaction id.

(SYNCHRONIZED)

Parameters:
request_id a transaction id.
Returns:
a pointer to a Request or 0 if there is no request pending with the given transaction id.

virtual Request* RequestList::find_request_on_id ( unsigned  long  )  [virtual]

Return a pointer to the request identified by a given request id.

(NOT SYNCHRONIZED)

Parameters:
request_id - A request id.
Returns:
A pointer to a Request or 0 if there is no request pending with the given request id.

virtual void RequestList::answer ( Request  )  [virtual]

Answer a Request by sending the corresponding response PDU.

(SYNCHRONIZED)

Parameters:
req - A pointer to a processed Request.

unsigned long RequestList::create_transaction_id (  )  [inline]

Get next transaction id.

Returns:
a unique transaction id.

boolean RequestList::is_empty (  )  [inline]

Check whether the request list (queue) is empty or not.

Returns:
TRUE if the queue is empty.

unsigned long RequestList::size (  )  [inline]

Get the actual size of the request list.

Returns:
the size of the queue.

virtual void RequestList::remove_request ( Request req  )  [virtual]

Remove a request that should not be processed.

Parameters:
req - The pointer returned from receive(), the pointer is invalid after this function returns.

virtual Request* RequestList::add_request ( Request  )  [protected, virtual]

Add a Request to the RequestList.

(SYNCHRONIZED)

Parameters:
req - A pointer to a Request.
Returns:
A pointer to the added Request.

virtual boolean RequestList::community_ok ( int  ,
const NS_SNMP OctetStr &   
) [protected, virtual]

Check whether a given community is acceptable for the specified PDU type.

Parameters:
pdutype - A PDU type (e.g., sNMP_PDU_SET, sNMP_PDU_GET, etc.)
community - A v1 or v2c community string.
Returns:
TRUE if the given community is ok, FALSE otherwise.

virtual void RequestList::authenticationFailure ( const NS_SNMP OctetStr &  context,
const NS_SNMP GenAddress &  sourceAddress,
int  status 
) [protected, virtual]

Sends an authenticationFailure notification if the corresponding MIB object is enabled.

Parameters:
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.

static void RequestList::null_vbs ( Request req  )  [static, protected]

Set all variable bindings (for response) to null values.

Parameters:
req a pointer to a Request instance.


Member Data Documentation

Snmpx* RequestList::snmp [protected]

NS_SNMP OctetStr* RequestList::write_community [protected]

NS_SNMP OctetStr* RequestList::read_community [protected]

unsigned long RequestList::next_transaction_id [protected]


The documentation for this class was generated from the following file:

Generated on Fri May 29 22:36:55 2009 for AGENT++ by  doxygen 1.5.6