ComplexMibEntry

Todd Wang toddw____vocent.com
Fri May 9 03:24:47 CEST 2003


hi stefan,

i'm posting this to the agent++ mailing list as well, in case anyone
else is interested.

BACKGROUND:
basically i wanted to use agent++ to implement a SNMP agent that would
take an incoming SNMP GET request, translate the request into an
operation on another C++ component, and take the results of that
operation and return it as the result of the SNMP GET request.  i wanted
to do this for both scalar values as well as table values.  note that
the C++ component (in my case) is wholly unrelated to SNMP, and in
particular, knows nothing of SNMP OIDs or their relevance in SNMP
tables.

SCALARS:
for scalars my approach is to inherit directly from MibLeaf and override
clone() and get_request().  MibLeaf nicely takes care of forwarding
get_next_request() to get_request() (i'm new to agent++, but from the
looks of it and from some comments, it seems the need for
get_next_request() has been replaced by the framework directly handling
finding the next oid).  some sample code:

    class SampleScalar : public MibLeaf
    {
        SampleScalar ();
        virtual ~SampleScalar ();

        // methods inherited from MibLeaf
        virtual MibEntry * clone () { return(new SampleScalar(*this)); }
        virtual void get_request (Request * p_request,
                                  int request_index)
        {
            MibLeaf::set_value(Gauge32(MethodReturningTheValue()));
            MibLeaf::get_request(p_request, request_index);
        }
     ...
    };

TABLES:
for tables the approach is to inherit from MibComplexEntry and override
clone(), is_empty(), find_succ(), get_request() and get_next_request().
is_empty() needs to return whether the table is empty.  find_succ()
needs to return the next logical oid.  get_request() needs to return the
actual value.  get_next_request() simply forwards to get_request().

    class SampleTable :
        public MibComplexEntry
    {
    public:
        SampleTable ();
        virtual ~SampleTable ();

        // methods inherited from MibComplexEntry
        virtual MibEntry * clone () { return(new SampleTable(*this)); }
        virtual boolean is_empty () { /* fill this in */ }
        virtual Oidx find_succ (Oidx const & find_oid,
                                Request *)
        {
            // find the next oid (that we're managing), given
            // find_oid as a starting point.  if we can't find one,
            // return Oidx() to signal that we don't know.

            /* fill this in */

            return(Oidx());
        }
        
        virtual void get_request (Request * p_request,
                                  int request_index)
        {
            Oidx const request_oid(p_request->get_oid(request_index));

            // using request_oid, figure out exactly what piece of
information
            // we're looking for and go get it.  the oid is useful since
the index
            // of the table is usually significant in determining
exactly what
            // piece of information might be needed.
            unsigned int const value = GetValue(request_oid);

            // fill in info
            Vbx vb(request_oid);
            vb.set_value(Gauge32(value));
            p_request->finish(request_index, vb);
        }
        
        virtual void get_next_request (Request * p_request,
                                       int request_index)
        {
            get_request(p_request, request_index);
        }
   ... 
   };

hope this helps.  the code above is copied from my working version but
modified for brevity and simplicity.  in particular,
SampleTable::find_succ() and SampleTable::get_request() need to be
filled in with real code to do their job.  in short, take the code as a
reference only.

Todd

-----Original Message-----
From: Stefan.Mueller-Wilken____resco.de
[mailto:Stefan.Mueller-Wilken____resco.de] 
Sent: Thursday, May 08, 2003 1:30 PM
To: toddw____vocent.com
Subject: ComplexMibEntry


Hi there Todd,

[...]
>an alternative approach (that you mention in your docs) is
>to inherit from MibComplexEntry directly, providing a much more
>lightweight solution.  just wanted to report a MibComplexEntry-based
>success story (i'm inheriting from MibLeaf directly for scalars and
>MibComplexEntry for tables), to allow the SNMP requests to basically be
>translated into queries to another software component.
[...]

as I have been one of the blokes to struggle with the use of adapters to
integrate MIB tables with C++ structures, I am quite eager to hear your
success story. Will you be able to give more details?

Cheers,
 Stefan


Dr. Stefan Müller-Wilken
Resco GmbH
Millerntorplatz 1
20359 Hamburg
Tel.: 040-82 22 59 - 0
Fax: 040-82 22 59 - 100
http://www.resco.de
stefan.mueller-wilken at resco.de




More information about the AGENTPP mailing list