AGENT++  4.0.3
Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | List of all members
Mib Class Reference

#include <mib.h>

Inheritance diagram for Mib:
SimMib

Public Member Functions

 Mib ()
 Default Constructor.
 
 Mib (const NS_SNMP OctetStr &)
 Constructor with path where persistent MIB objects should be stored to and loaded from.
 
virtual ~Mib ()
 Destructor.
 
void set_request_list (RequestList *)
 Set the RequestList to be used for answering request.
 
RequestListget_request_list ()
 Gets the request list associated with all Mib instances.
 
virtual void process_request (Request *)
 Process a request.
 
virtual int notify (const NS_SNMP OctetStr &, const Oidx &, Vbx *, int, unsigned int=0)
 Send a notification.
 
void set_notification_sender (NotificationSender *)
 Sets the notification sender to be used by this Mib.
 
NotificationSenderget_notification_sender () const
 Gets the currently set NotificationSender.
 
virtual void cleanup ()
 Clean up MIB.
 
virtual MibEntryadd (MibEntry *)
 Register a MIB object for the default context.
 
virtual MibEntryadd (const NS_SNMP OctetStr &, MibEntry *)
 Register a MIB object within a given context.
 
virtual MibContextadd_context (const NS_SNMP OctetStr &)
 Add a new context with a given name to the receiver.
 
virtual void remove_context (const NS_SNMP OctetStr &)
 Remove a given context from the receiver.
 
virtual bool add_agent_caps (const NS_SNMP OctetStr &, const Oidx &, const NS_SNMP OctetStr &)
 Add Agent Capabilities to a context.
 
virtual void remove_agent_caps (const NS_SNMP OctetStr &, const Oidx &)
 Remove Agent Capabilities from a context.
 
virtual bool remove (const Oidx &)
 Unregister a MIB object from the agent�s MIB.
 
virtual bool remove (const NS_SNMP OctetStr &, const Oidx &)
 Unregister a MIB object from the agent�s MIB.
 
virtual bool init ()
 Initialize all contexts.
 
virtual void save_all ()
 Save all persistent MIB objects to disk.
 
virtual bool save (unsigned int, const NS_SNMP OctetStr &)
 Save all persistent MIB objects in the supplied format to the supplied path.
 
virtual bool load (unsigned int, const NS_SNMP OctetStr &)
 Load all persistent MIB objects in the supplied format from the supplied path.
 
virtual MibEntryPtr get (const Oidx &)
 Get the MIB object with a given object id.
 
virtual MibEntryPtr get (const NS_SNMP OctetStr &, const Oidx &)
 Get the MIB object with a given object id.
 
virtual MibGroupfind_group_of (const NS_SNMP OctetStr &, const Oidx &)
 Find the MibGroup that contains a MibEntry with a given object ID.
 
virtual NS_SNMP OctetStr get_persistent_objects_path () const
 Get path where persistent MIB objects are stored.
 
virtual void set_persistent_objects_path (const NS_SNMP OctetStr *str)
 Set the path where persistent MIB objects are stored.
 
bool is_persistency_activated () const
 Checks whether a persistent objects path has been set.
 
virtual bool is_complex_node (const MibEntryPtr &)
 Check whether a node (a MIB object) is complex, i.e.
 
bool is_table_node (const MibEntryPtr &e)
 Check whether a node (a MIB object) is a table.
 
bool is_leaf_node (const MibEntryPtr &e)
 Check whether a node (a MIB object) is a leaf node.
 
void lock_mib ()
 Lock the receiver's registration.
 
void unlock_mib ()
 Release the lock on the receiver's registration.
 
virtual MibContextget_context (const NS_SNMP OctetStr &)
 Get a context.
 
MibContextget_default_context ()
 Get the default context.
 
virtual int find_next (MibContext *, const Oidx &oid, MibEntryPtr &, Request *req, const int, Oidx &nextOid)
 Find the next MIB entry which has an oid greater than the given oid.
 
virtual int find_managing_object (MibContext *, const Oidx &, MibEntryPtr &, Request *)
 Find the MIB object (i.e., MibTable, MibLeaf, etc.) that is responsible for the managed object identified by a given oid within a given context.
 
virtual void do_process_request (Request *)
 Internally process a request (typically within its own thread).
 
virtual void process_set_request (Request *)
 Process a set request.
 
virtual int process_prepare_set_request (Request *)
 Process the prepare phase of a set request.
 
virtual int process_commit_set_request (Request *)
 Process the commit phase of a set request.
 
virtual int process_undo_set_request (Request *)
 Process the undo phase of a set request.
 
virtual void process_cleanup_set_request (Request *)
 Process the clean up phase of a set request.
 
virtual void process_get_bulk_request (Request *)
 Process a get bulk request.
 
MibConfigFormatadd_config_format (unsigned int format, MibConfigFormat *)
 Adds a config format to this Mib instance.
 
MibConfigFormatget_config_format (unsigned int format)
 Returns the config format for the specified format ID.
 

Public Attributes

RequestListrequestList
 Pointer to the RequestList used for answering requests.
 

Static Public Attributes

static Mibinstance
 

Protected Member Functions

virtual bool process_request (Request *, int)
 Process a subrequest.
 
virtual void finalize (Request *)
 Finalize a request.
 
virtual void delete_request (Request *req)
 Deletes the the supplied request.
 

Static Protected Member Functions

static bool set_exception_vb (Request *, int, int)
 Set the exception status for the supplied sub-request.
 

Protected Attributes

OidList< MibContextcontexts
 
MibContextdefaultContext
 
NotificationSendernotificationSender
 
NS_SNMP OctetStr * persistent_objects_path
 
ThreadManager mibLock
 
Array< MibConfigFormatconfigFormats
 

Constructor & Destructor Documentation

Mib::Mib ( )

Default Constructor.

Mib::Mib ( const NS_SNMP OctetStr &  )

Constructor with path where persistent MIB objects should be stored to and loaded from.

Parameters
path- The directory to store persistent objects.
virtual Mib::~Mib ( )
virtual

Destructor.

Member Function Documentation

virtual MibEntry* Mib::add ( MibEntry )
virtual

Register a MIB object for the default context.

Note: This method is synchronized using ::lock_mib()

Parameters
itema pointer to a MibEntry object (i.e., MibLeaf, MibTable, MibGroup, ...).
Returns
the input pointer if the MibEntry could be registered, or 0 otherwise.
virtual MibEntry* Mib::add ( const NS_SNMP OctetStr &  ,
MibEntry  
)
virtual

Register a MIB object within a given context.

If the given context is a new context, it will be added to the list of known contexts.

Note: This method is synchronized using ::lock_mib()

Parameters
contextan OctetStr instance specifiying the target context.
itema pointer to a MibEntry object (i.e., MibLeaf, MibTable, MibGroup, ...).
Returns
the input pointer if the MibEntry could be registered, or 0 otherwise.
virtual bool Mib::add_agent_caps ( const NS_SNMP OctetStr &  ,
const Oidx ,
const NS_SNMP OctetStr &   
)
virtual

Add Agent Capabilities to a context.

Parameters
contexta context. An empty string denotes the default context.
sysORIDan authoritative identification of a capabilities statement with respect to various MIB modules supported by the local SNMPv2 entity acting in an agent role.
sysORDescra textual description of the capabilities identified by the corresponding instance of sysORID.
Returns
TRUE if the context could be found and it contains the sysOR MIB objects, FALSE otherwise.
MibConfigFormat* Mib::add_config_format ( unsigned int  format,
MibConfigFormat  
)

Adds a config format to this Mib instance.

If a format with the specified ID (see AGENTPP-CONFIG-MIB) is already registered, then it will be replaced and the old one will be returned. NOTE: This method is not synchronized and should therefore not be called after agent initialization.

Parameters
formatIDan unsigned integer > 0 that specifies the format as defined in the AGENTPP-CONFIG-MIB or any supplemental MIB specification.
formatthe MibConfigFormat instance implementing the format.
Returns
the MibConfigFormat instance pointer provided as format parameter.
virtual MibContext* Mib::add_context ( const NS_SNMP OctetStr &  )
virtual

Add a new context with a given name to the receiver.

Note: This method is synchronized using ::lock_mib(), thus you may add a context in within the agent`s mainloop in a multi-threaded enivornment, but do not use the return pointer then. The pointer to the MibContext created SHOULD ONLY be used before you enter the main loop.

Parameters
contextNamethe name of the new context.
Returns
a pointer to the created and empty MibContext instance.
virtual void Mib::cleanup ( )
virtual

Clean up MIB.

Currently, the only clean up procedure is to call the remove_unused_rows() method of each MibTable object in the MIB.

virtual void Mib::delete_request ( Request req)
inlineprotectedvirtual

Deletes the the supplied request.

This method can be overwritten by sub-classes to implement special processing before a request object is freed. This method is called at the end of the finalize method.

Parameters
reqa pointer to the Request instance to delete.
Since
3.5.23
virtual void Mib::do_process_request ( Request )
virtual

Internally process a request (typically within its own thread).

Parameters
reqa request.
virtual void Mib::finalize ( Request )
protectedvirtual

Finalize a request.

The finalize method is called if all sub-requests have been successfully processed.

Parameters
requestthe request to finalize.
virtual MibGroup* Mib::find_group_of ( const NS_SNMP OctetStr &  ,
const Oidx  
)
virtual

Find the MibGroup that contains a MibEntry with a given object ID.

(NOT SYNCHRONIZED)

Parameters
contexta context identifier.
oida object identifier.
Returns
a pointer to the MibGroup instance that contains an instance with the given oid, or 0 otherwise.
virtual int Mib::find_managing_object ( MibContext ,
const Oidx ,
MibEntryPtr ,
Request  
)
virtual

Find the MIB object (i.e., MibTable, MibLeaf, etc.) that is responsible for the managed object identified by a given oid within a given context.

Parameters
contextthe target context.
oidan object identifier.
retvalchanged to a pointer to the found entry or unchanged if the return value is different from SNMP_ERROR_SUCCESS.
requesta pointer to the request that is searching.
Returns
SNMP_ERROR_SUCCESS if an entry has been found and SNMP_ERROR_NO_SUCH_NAME otherwise.
virtual int Mib::find_next ( MibContext ,
const Oidx oid,
MibEntryPtr ,
Request req,
const int  ,
Oidx nextOid 
)
virtual

Find the next MIB entry which has an oid greater than the given oid.

Parameters
contextthe target context.
oidthe OID for which a successor OID and managing MibEntry is searched.
entrywill be changed to a pointer to the found entry or remain unchanged if the return value is different from SNMP_ERROR_SUCCESS.
requesta pointer to the Request instance for in whose context the find_next is issued.
subrequestthe subrequest number being processed (starting from 0)
nextOidreturns the successor OID (if found) or a zero length OID (if not found) for objects where the successor could be determined. Otherwise, the oid will be returned unchanged.
Returns
SNMP_ERROR_SUCCESS if an entry has been found and sNMP_SYNTAX_NOSUCHOBJECT otherwise.
virtual MibEntryPtr Mib::get ( const Oidx )
virtual

Get the MIB object with a given object id.

Parameters
keyan object identifier
Returns
a pointer to a MibEntry instance if an object with the given key could be found or 0 otherwise.
virtual MibEntryPtr Mib::get ( const NS_SNMP OctetStr &  ,
const Oidx  
)
virtual

Get the MIB object with a given object id.

Parameters
contextan OctetStr instance specifiying the target context.
keyan object identifier
Returns
a pointer to a MibEntry instance if an object with the given key could be found or 0 otherwise.
MibConfigFormat* Mib::get_config_format ( unsigned int  format)
inline

Returns the config format for the specified format ID.

Parameters
formatIDthe format ID.
Returns
the MibConfigFormat instance registered for the supplied formatID, or NULL if such a format is not registered.
virtual MibContext* Mib::get_context ( const NS_SNMP OctetStr &  )
virtual

Get a context.

Parameters
contexta context.
Returns
a pointer to a MibContext instance, or 0 if no such instance exists.
MibContext* Mib::get_default_context ( )
inline

Get the default context.

Returns
a pointer to the default context.
NotificationSender* Mib::get_notification_sender ( ) const
inline

Gets the currently set NotificationSender.

Returns
a pointer to a NotificationSender instance or 0 if it has not been set yet.
virtual NS_SNMP OctetStr Mib::get_persistent_objects_path ( ) const
virtual

Get path where persistent MIB objects are stored.

Returns
The path string.
RequestList* Mib::get_request_list ( )
inline

Gets the request list associated with all Mib instances.

Returns
a RequestList instance.
virtual bool Mib::init ( )
virtual

Initialize all contexts.

The main purpose of this method is to trigger all MIB objects to load their data from persistent storage. NOTE: If no thread pool has been assigned until calling this method a default ThreadPool will be created with the default stack size. The number of threads and the thread stack size might not match your requirements. To use your own thread pool, simply call set_thread_pool() before calling this method.

@return
   TRUE if initialization was successful, FALSE otherwise.
virtual bool Mib::is_complex_node ( const MibEntryPtr )
virtual

Check whether a node (a MIB object) is complex, i.e.

whether the node manages more than one leaf object.

Parameters
Apointer to a node (MIB object).
bool Mib::is_leaf_node ( const MibEntryPtr e)
inline

Check whether a node (a MIB object) is a leaf node.

Parameters
entrya pointer to a node (MIB object).
bool Mib::is_persistency_activated ( ) const
inline

Checks whether a persistent objects path has been set.

Since get_persistent_objects_path always returns a path, calling this method is the only way to determine whether a path has been explicitly unset, to disable persistent storage at all.

Returns
TRUE if persistent storage is activated.
bool Mib::is_table_node ( const MibEntryPtr e)
inline

Check whether a node (a MIB object) is a table.

Parameters
entrya pointer to a node (MIB object).
virtual bool Mib::load ( unsigned  int,
const NS_SNMP OctetStr &   
)
virtual

Load all persistent MIB objects in the supplied format from the supplied path.

All presistent objects will be resetted.

Parameters
formatthe format of the persistent data.
paththe path where the data should be stored.
Returns
TRUE if data has been saved successfully, FALSE otherwise.
void Mib::lock_mib ( )
inline

Lock the receiver's registration.

Thus, no adding nor removing of MIB objects can be done while the lock is active.

While processing a (sub-)request the locking scheme is as follows:

  1. This MIB lock is acquired.
  2. The MIB object is identified, which is responsible for processing the sub-request.
  3. The MIB objects lock (MibEntry::start_synch()) is acquired.
  4. The MIB lock is released.
  5. The sub-request is propagated to the MIB object.
  6. When finished, the MIB objects lock is released.
virtual int Mib::notify ( const NS_SNMP OctetStr &  ,
const Oidx ,
Vbx ,
int  ,
unsigned  int = 0 
)
virtual

Send a notification.

Parameters
contextthe context originating the notification ("" for the default context).
trapoidthe oid of the notification.
vbsan array of variable bindings.
sizethe size of the above variable binding array.
timestampan optional timestamp.
Returns
SNMP_ERROR_SUCCESS if the notification could be sent successfully, otherwise an appropriate SNMP error is returned.
virtual void Mib::process_cleanup_set_request ( Request )
virtual

Process the clean up phase of a set request.

Parameters
rep- The request.
virtual int Mib::process_commit_set_request ( Request )
virtual

Process the commit phase of a set request.

Parameters
rep- The request.
Returns
SNMP_ERROR_SUCCESS on success or any other SNMP error code on failure.
virtual void Mib::process_get_bulk_request ( Request )
virtual

Process a get bulk request.

Parameters
rep- The request.
virtual int Mib::process_prepare_set_request ( Request )
virtual

Process the prepare phase of a set request.

Parameters
rep- The request.
Returns
SNMP_ERROR_SUCCESS on success or any other SNMP error code on failure.
virtual void Mib::process_request ( Request )
virtual

Process a request.

If multi-threading is activated, start a thread to actually process the request.

Parameters
req- A request.
virtual bool Mib::process_request ( Request ,
int   
)
protectedvirtual

Process a subrequest.

Parameters
reqA pointer to the request
Returns
FALSE if an error occured and the whole request finished
virtual void Mib::process_set_request ( Request )
virtual

Process a set request.

Parameters
repthe set request to process.
virtual int Mib::process_undo_set_request ( Request )
virtual

Process the undo phase of a set request.

Parameters
rep- The request.
Returns
SNMP_ERROR_SUCCESS on success or any other SNMP error code on failure.
virtual bool Mib::remove ( const Oidx )
virtual

Unregister a MIB object from the agent�s MIB.

This method now (>3.3) works for MibGroups, too.

Note: This method is synchronized. It first acquires ::mib_lock(), then searches for the target MIB object and then acquires target::start_synch(). Then it RELEASES the MIB object lock by calldelete_requesting target::end_synch(). The target object is deleted and the MIB lock is released.

Why is this save?

  • we hold the lock for the MIB (lock_mib())
  • before a request can lock a MibEntry object it must get the MIB lock
  • so if we get the MibEntry lock here no other request can be currently using this object
  • even if we release the lock, because we hold the MIB lock
Parameters
oidthe Oidx instance pointing to the key of the MibEntry to be removed.
Returns
TRUE if the entry could be removed, FALSE otherwise
virtual bool Mib::remove ( const NS_SNMP OctetStr &  ,
const Oidx  
)
virtual

Unregister a MIB object from the agent�s MIB.

This method now (>3.3) works for MibGroups, too.

Note: This method is synchronized. It first acquires ::mib_lock(), then searches for the target MIB object and then acquires target::start_synch(). Then it RELEASES the MIB object lock by calling target::end_synch(). The target object is deleted and the MIB lock is released.

Why is this save?

  • we hold the lock for the MIB (lock_mib())
  • before a request can lock a MibEntry object it must get the MIB lock
  • so if we get the MibEntry lock here no other request can be currently using this object
  • even if we release the lock, because we hold the MIB lock
Parameters
contextan OctetStr instance specifying the target context.
oidthe Oidx instance pointing to the key of the MibEntry to be removed.
Returns
TRUE if the entry could be removed, FALSE otherwise
virtual void Mib::remove_agent_caps ( const NS_SNMP OctetStr &  ,
const Oidx  
)
virtual

Remove Agent Capabilities from a context.

Parameters
contexta context. An empty string denotes the default context.
sysORIDan authoritative identification of a capabilities statement with respect to various MIB modules supported by the local SNMPv2 entity acting in an agent role.
virtual void Mib::remove_context ( const NS_SNMP OctetStr &  )
virtual

Remove a given context from the receiver.

Note: This method is synchronized using ::lock_mib().

Parameters
contextNamethe name of the new context.
virtual bool Mib::save ( unsigned  int,
const NS_SNMP OctetStr &   
)
virtual

Save all persistent MIB objects in the supplied format to the supplied path.

Parameters
formatthe format of the persistent data.
paththe path where the data should be stored.
Returns
TRUE if data has been saved successfully, FALSE otherwise.
virtual void Mib::save_all ( )
virtual

Save all persistent MIB objects to disk.

static bool Mib::set_exception_vb ( Request ,
int  ,
int   
)
staticprotected

Set the exception status for the supplied sub-request.

Parameters
reqa pointer to a Request.
reqindthe index of the sub-request to be modified.
Returns
TRUE if the request can be further processed (thus it is not necessarily finished yet) or FALSE if the it has to be finished.
void Mib::set_notification_sender ( NotificationSender )

Sets the notification sender to be used by this Mib.

By default a NotificationOriginator is used, which is created the first time the notify method is called. By setting a different notification sender before notify is called for the first time, the set NotificationSender is used instead. The set NotificationSender is deleted by the destructor of Mib or when this method is called again.

Parameters
notificationSendera pointer to a NotificationSender instance. A previously set notificationSender will be deleted. If notificationSender is set to 0, any previously set instance will be deleted and the default sender will be used when notify is called again.
virtual void Mib::set_persistent_objects_path ( const NS_SNMP OctetStr *  str)
virtual

Set the path where persistent MIB objects are stored.

In order to disable persistent objects, call with NULL.

Parameters
strpointer to the the path (this function calls clone() to get a clean new pointer.
void Mib::set_request_list ( RequestList )

Set the RequestList to be used for answering request.

Note: The request list is NOT deleted by the receiver's destructor. This should be done outside class Mib.

Parameters
requestLista RequestList instance.
void Mib::unlock_mib ( )
inline

Release the lock on the receiver's registration.

See Also
Mib::lock_mib()

Member Data Documentation

Array<MibConfigFormat> Mib::configFormats
protected
OidList<MibContext> Mib::contexts
protected
MibContext* Mib::defaultContext
protected
Mib* Mib::instance
static
ThreadManager Mib::mibLock
protected
NotificationSender* Mib::notificationSender
protected
NS_SNMP OctetStr* Mib::persistent_objects_path
protected
RequestList* Mib::requestList

Pointer to the RequestList used for answering requests.


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