in reply to Re: integer encoder/decoder
in thread integer encoder/decoder

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?

Replies are listed 'Best First'.
Re: Re: Re: integer encoder/decoder
by zengargoyle (Deacon) on Mar 14, 2003 at 00:38 UTC

    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???
        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???
        How many times must we say (at least three so far) that you can't put ten pounds of potatoes into a five pound sack?

        This can't be done. Get it?

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

        then you have one hope.

        and it's a slim one.

        but you might be able to wring the last bit of info out.

        the absolute max session id is 999_999_999 which in binary is: $ perl -e 'printf"%032b$/",999999999' 00111011100110101100100111111111 you have the 2 most significant bits to work with. %NASs = ( '192.168.254.12' => 0, '192.168.255.13' => 1, '192.168.256.2' => 2, '192.168.243.1' => 3 ); so you can fit 4 IP's and a session id in 32 bits. if you want to assume that your session id won't go above 463129087 th +en you can steal another bit and have 8 IPs. $ perl -le 'print unpack "N", pack "B*", "0001101110011010110010011111 +1111"' 463129087 or along the same lines, use the NAS number and session id with a dot, only because it's easier for humans. 1.4596831 12.4596831 instead of the 16bit big numbers...

        this assumes an OID part can be 32 bits.

        $ snmpget -v 1 $CENSORED sysDescr.9999999999 Error in packet Reason: (noSuchName) There is no such variable name in this MIB. Failed object: system.sysDescr.4294967295 $ snmpget -v 1 $CENSORED sysDescr.4294967294 Error in packet Reason: (noSuchName) There is no such variable name in this MIB. Failed object: system.sysDescr.4294967294 $ snmpget -v 1 $CENSORED sysDescr.4294967295 Error in packet Reason: (noSuchName) There is no such variable name in this MIB. Failed object: system.sysDescr.4294967295 $ snmpget -v 1 $CENSORED sysDescr.4294967296 Error in packet Reason: (noSuchName) There is no such variable name in this MIB. Failed object: system.sysDescr.4294967295

        which may or may not be true.