[Next] [Up] [Previous] [Contents]
Next: AGENT++ Features Up: An Introductory Example Previous: An Introductory Example

Explanation of Introductory Example

The main procedure of an AGENT++ SNMP agent (shown in figure 1) can be divided into three sections:

  1. Setting up the SNMP protocol engine

    First of all an extended version of the SNMP++ Snmp class ( Snmpx) is used to create a SNMP session that will be used for incoming SNMP requests. The example uses the standard SNMP port 161 to listen on, although any (available) UDP port can be chosen. If the session has been created successfully the session object snmp has to be registered to the static class RequestList which queues and manages SNMP requests.

  2. Create and register the MIB objects

    The mib object is created which represents the conceptual database containing the management information of the agent (Management Information Base). Then all objects that should be supported by the agentīs MIB are added. Each such object contains one or more instances of managed objects related to a subtree of the management information tree. The classes systemGroup, snmpGroup, and trapDestGroup are provided by AGENT++, which include the managed objects of the MIB IIīs system and snmp group, as well as managed objects needed for trap destination registration.

  3. Loop forever for incoming SNMP requests

    The receive method of the RequestList object is used to wait for incoming SNMP request. The method takes as argument the maximum time to wait for a request in seconds. Note: If the agent uses multi-threading the RequestList can contain more than one request. A SNMP request is processed through the process_request method which propagates each sub-request to the appropriate MIB object.

  [IMAGE ]
Figure 1: An example for a main routine of a SNMP agent to manage a coffee-percolator.

How a simple managed object like coffeeTemperature can be implemented using the AGENT++ API is shown by figures 2 and 3. The class coffeeTemperature is derived from MibLeaf which is itself derived from MibEntry. MibLeaf is the base class for all instances of managed objects that are leafs of the management information tree, also called scalar managed objects. The constructor of coffeeTemperature calls the constructor of its base class MibLeaf with three arguments:

Because coffeeTemperature has not a constant value, we need to redefine the virtual member function get_request inherited from MibLeaf to get the actual temperature of the coffee from the management instrumentation. To translate between the different management information representations used by the management instrumentation (temperature measured in Fahrenheit) and the SNMP MIB definition (Celsius) the method get_coffee_temperature is used.

The coffeeTemperature::get_request method first gets the actual temperature and stores it in value which is a pointer to the SnmpSyntax object that has been given as third parameter to the MibLeaf constructor. Then MibLeaf::get_request is called to actually answer the SNMP request using the value of value. Thatīs all! Everything else is done by AGENT++.

  [IMAGE ]
Figure 2: Class definition for the managed object representing the coffee temperature

  [IMAGE ]
Figure 3: Class implementation of the managed object representing the coffee temperature


[Next] [Up] [Previous] [Contents]
Next: AGENT++ Features Up: An Introductory Example Previous: An Introductory Example

Copyright Frank Fock 1998