Hello All, Sorry if this has been discussed already. I just thought I would share my experience with trying to use just one client UDP socket for many SNMPv3 sessions.
Using just one socket was easy enough for SNMP v1 and v2 because I could use the single-session API and multiplex all requests through it, but with SNMPv3 the session holds more per-agent state. So given that I have no choice but to run a separate session for every agent, the question is: how to get them to share a single UDP socket as their underlying transport? The library seems to make the assumption that every session has it's own socket and uses that as a convenient way to jump straight from select() and recv_from() to the session, and to the list of outstanding requests for that session. That's nice and tidy, but what happens when you have 4000 sessions? Are you really going to open 4000 sockets? So here's what I did. It required two new data-structures: (A) a hash table to map efficiently from sessid to session (B) an array to map efficiently from msgid to sessid All sessions were forced to use the same UDP socket, so when a packet was received on that socket the first step was to decide what session it belonged to. The SNMP protocol offers the msgid for this (just like the reqid can be used with V1 and V2). So the sequence was: When sending a request: 1. write the sessid into the array (B) at the slot for that msgid i.e. array[msgid] = sessid When receiving a packet: 1. recv_from() the single socket 2. decode header to get version 3. if version==3, decode further to get msgid 4. look up msgid->sessid in array (B) 5. look up sessid->session in hash-table (A) 6. process the packet as before When closing a session: 1. remove the session from the hash table (A) Note that using the sessid in the array acts a sort of "weak reference". It allows you to use a smaller (16bit or 32bit) cell-size, and means you don't ever have to search linearly through the whole array to remove all references to a closing session. If a response arrives just after the session closes then the sessid->session lookup fails and the response can be discarded. It seems to work OK, but maybe I missed something. Does anyone have comments? Neil ------------------------------------------------------------------------------ Don't let slow site performance ruin your business. Deploy New Relic APM Deploy New Relic app performance management and know exactly what is happening inside your Ruby, Python, PHP, Java, and .NET app Try New Relic at no cost today and get our sweet Data Nerd shirt too! http://p.sf.net/sfu/newrelic-dev2dev _______________________________________________ Net-snmp-coders mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
