in reply to integer encoder/decoder

The way you can do it, is by storing the data in a database, with an auto-increment index, and use that index as the reference. You can get the original data back by looking it up in the same database.

Replies are listed 'Best First'.
Re: Re: integer encoder/decoder
by Anonymous Monk on Mar 13, 2003 at 23:30 UTC
    Hehe,

    Nice idea. Unfortunately it won't work in my situation.

    Here are the specifics of my project. I have many NASes throughout my network. Each NAS has users online identified by a 9 digit session id. I access relevant user info via SNMP. Every specified interval a user dump is taken from each NAS and populated into a database. The application I am writing is a snmpd fronted to the database. So a client can walk my snmpd and get a list of their users. However, for simplicity and for certain functions to work, they need to be able to referrence a uniqe session id. Since the session id's on the NASes can be the same, I need to generate a new sessionid based on the NAS ip and sessionid.

    I can't use an auto-incrementing id from a database table since the users are dumped every 5 min or so and I can't guarantee that the same id with be associated with the same user after each dump, and I'd also have to worry about users connecting and disconnecting. That is why I need to be able to generate a new sessionid. The 9 digit limitation is due to net-snmp. The maximum number of an oid level is 2147483647.

    The idea is for the 9 digit sessionid to be part of the oid, so they can easily reference their users, instead of an auto-incrementing number.
    enterprises.10000.10182.398820668 enterprises.10000.10182.548131831 enterprises.10000.10182.872131658
    If it was an auto-incrementing number, that number would change when users connect/disconnect and unless they walk the tree again, they might access the wrong users info. It's more complicated than I am explaining it, but I think you get the basic idea of what I need.

    I realize that encoding the IP and sessionid into a 9 digit number is not possible now, due to the reply's above. All I really want now is a way to take the IP and sessionid, do whatever to it, and get a 9 digit number that I is unique to that specific IP and sessionid. I don't care if I can't go backwards. Understand?

      yes, i think i understand. but i don't see the reason to limit yourself to a 9 digit sessionid. just use more than one OID slot and give the client people a sessionid with a dots in it.

      enterprise.10000.10182.192.168.254.12.3888206 for NAS 192.168.254.12 session 3888206 or take IP and convert to two 16bit numbers and do ...10182.49128.64782.3888206 ( give person 49128.64782.3888206 as sessionid )

      i've seen both. another really cool thing i came across recently is to use a timestamp as part of the OID, like ...1.3.1.$time.$id = $value. then you can keep a history of values in your MIB and the user can walk your table from ...1.3.1 and get all of the history or walk the table from ...1.3.1.$last and get all of the updates that have happend since they last walked the table.

      Update: if all of your NAS IPs are in the same subnet (/16 or less) you could just forget about the first two octets. give them: 64782.3888206 as the session id if all your NAS are in 192.168.0.0/16.

        I thought about splitting it up actually. I didn't want to just do the whole ip like
        enterprise.10000.10182.192.168.254.12.3888206
        even though I have seen that before because I don't really want them knowing the IP.

        I also could split to two 16bit numbers, but it just comes down to simplicity. Why add 3 extra oid levels if I can just make one? That also makes it easier on the client, only having to remember one.

        That was the whole point of this node. To find a way to get one unique 9 digit number out of the IP and sessionid.

        There must be some kind of mathematical munging formula. I don't care really..it can use mod, division, whatever. As long as it's unique for that IP and sessionid. I don't even really need to be able to decode it. Can't anybody help???