Good implementation for getnext/getbulk operations with STL - SNMP

This is a discussion on Good implementation for getnext/getbulk operations with STL - SNMP ; [My apologies if this is deemed OT] I have some STL data-structures in my application. Up until this point, I had no requirement to satisfy SNMP getbulk and getnext operations. I am now trying to build support for these operations, ...

+ Reply to Thread
Results 1 to 3 of 3

Thread: Good implementation for getnext/getbulk operations with STL

  1. Good implementation for getnext/getbulk operations with STL

    [My apologies if this is deemed OT]
    I have some STL data-structures in my application. Up until this
    point, I had no requirement to satisfy SNMP getbulk and getnext
    operations. I am now trying to build support for these operations,
    without changing my data structures and without making the software
    overly SNMP aware. I have posted some code to the comp.sources.d
    newsgroup (under this title) that shows a sample implementation, using
    the lower_bound operation. I am not fully satisfied with the
    implementation (although it works). Can anyone suggest a good way to
    provide support for these operations.

    As I mentioned earlier, there is a requirement to not make the
    application SNMP aware.

    Thanks,
    Bhat


  2. Re: Good implementation for getnext/getbulk operations with STL

    kbhat@kaxy.com wrote:
    > [My apologies if this is deemed OT]
    > I have some STL data-structures in my application. Up until this
    > point, I had no requirement to satisfy SNMP getbulk and getnext
    > operations. I am now trying to build support for these operations,
    > without changing my data structures and without making the software
    > overly SNMP aware. I have posted some code to the comp.sources.d
    > newsgroup (under this title) that shows a sample implementation,

    using
    > the lower_bound operation. I am not fully satisfied with the
    > implementation (although it works). Can anyone suggest a good way to
    > provide support for these operations.
    >
    > As I mentioned earlier, there is a requirement to not make the
    > application SNMP aware.
    >
    > Thanks,
    > Bhat



    I have worked out an implementation for doing OID comparisons. For
    this I have defined my own comparison criteria, which I use with
    associative STL containers like map and set. This comparison criterion
    does an "element-by-element" numerical comparison of two OID strings.
    Since this is such a common "problem" in the SNMP domain, I am sure
    that some generic solutions to this do exist. I am extremely curious
    to know what those are. Any pointers will be appreciated.

    Meanwhile, here's what I have. Comments welcome.

    Bhat

    /////////////////////////////////////////////////////////////
    using namespace std;

    #define OidToken "."

    struct OidLessublic binary_function

    {
    bool operator()(const string s1, const string s2) const
    {
    bool status = false;

    string s1Copy = s1;
    string s2Copy = s2;

    string::size_type str1Pos = 0, str2Pos = 0;
    string basename1, basename2;

    for(;
    {
    str1Pos = s1Copy.find(OidToken);
    str2Pos = s2Copy.find(OidToken);

    basename1 = s1Copy.substr(0, str1Pos);
    basename2 = s2Copy.substr(0, str2Pos);

    int val1 = atoi(basename1.c_str());
    int val2 = atoi(basename2.c_str());


    if(val1 < val2)
    {
    status = true;
    break;
    }
    else if(val1 > val2)
    {
    status = false;
    break;
    }
    // else val1 == val2 ---- keep going

    if((str1Pos == string::npos) || (str2Pos == string::npos)) break;

    s1Copy = s1Copy.substr(str1Pos+1);
    s2Copy = s2Copy.substr(str2Pos+1);
    }
    return status;
    }
    };




    In order to define an associative container, I will have to do
    something like this:


    #include

    typedef map MyMap;


  3. Re: Good implementation for getnext/getbulk operations with STL

    In comp.protocols.snmp kbhat@kaxy.com wrote:

    > I have some STL data-structures in my application. Up until this
    > point, I had no requirement to satisfy SNMP getbulk and getnext
    > operations. I am now trying to build support for these operations,
    > without changing my data structures and without making the software
    > overly SNMP aware. I have posted some code to the comp.sources.d
    > newsgroup (under this title) that shows a sample implementation, using
    > the lower_bound operation. I am not fully satisfied with the
    > implementation (although it works). Can anyone suggest a good way to
    > provide support for these operations.
    >
    > As I mentioned earlier, there is a requirement to not make the
    > application SNMP aware.


    Most implementations I am aware of have functions to convert OIDs from
    a string representation into an internal representation and back. Once
    you have a binary internal represenation, OID comparison can be made
    much faster. (Of course, most implementations I have see are written
    in straight C without all the C++ STL stuff on board.)

    /js

    --
    Juergen Schoenwaelder International University Bremen
    P.O. Box 750 561, 28725 Bremen, Germany

+ Reply to Thread