Re: Delayed response

Sverre Moe <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <51f5a597-1d9c-4a6a-8ca5-6ab9c8308805@zcs>
New update: 


I have put all incoming requests in an active request list to avoid querying the device multiple times for one request. 


However: 
If I am using a delayed time of more than 7 seconds, I get a timeout from the master agent and my subagent gets disconnected. 


AgentX master disconnected us, reconnecting in 15 
NET-SNMP version 5.7.1 AgentX subagent connected 



/var/log/net-snmp.log 
Connection from UDP: [127.0.0.1]:47426->[127.0.0.1]:161 
agentx/master: agentx master handler starting, mode = 0xa0 
agentx/master: request for variable (SNMPv2-SMI::enterprises.49463.1.3.40.0) 
agentx/master: sending pdu (req=0x17d,trans=0x17c,sess=0x6b) 
agentx_build: packet built okay 
Connection from UDP: [127.0.0.1]:47426->[127.0.0.1]:161 
agentx/master: agentx master handler starting, mode = 0xa0 
agentx/master: request for variable (SNMPv2-SMI::enterprises.49463.1.3.40.0) 
agentx/master: sending pdu (req=0x17f,trans=0x17e,sess=0x6b) 
agentx_build: packet built okay 
agentx_build: packet built okay 
Connection from UDP: [127.0.0.1]:47426->[127.0.0.1]:161 
agentx/master: agentx master handler starting, mode = 0xa0 
agentx/master: request for variable (SNMPv2-SMI::enterprises.49463.1.3.40.0) 
agentx/master: sending pdu (req=0x181,trans=0x180,sess=0x6b) 
agentx_build: packet built okay 
agentx_build: packet built okay 
agentx_build: packet built okay 
agentx_build: packet built okay 
agentx_build: packet built okay 
agentx_build: packet built okay 
Connection from UDP: [127.0.0.1]:47426->[127.0.0.1]:161 
agentx/master: agentx master handler starting, mode = 0xa0 
agentx/master: request for variable (SNMPv2-SMI::enterprises.49463.1.3.40.0) 
agentx/master: sending pdu (req=0x183,trans=0x182,sess=0x6b) 
agentx_build: packet built okay 
agentx_build: packet built okay 
agentx_build: packet built okay 
agentx_build: packet built okay 
agentx_build: packet built okay 
Connection from UDP: [127.0.0.1]:47426->[127.0.0.1]:161 
agentx/master: agentx master handler starting, mode = 0xa0 
agentx/master: request for variable (SNMPv2-SMI::enterprises.49463.1.3.40.0) 
agentx/master: sending pdu (req=0x187,trans=0x186,sess=0x6b) 
agentx_build: packet built okay 
agentx_build: packet built okay 
agentx/master: timeout on session 0x7f6ecc8ceb10 req=0x17d 
agentx/master: close 0x7f6ecc8ceb10, -1 
agentx/master: Continue removing delegated subsession reqests 
agentx/master: close transport 
agentx/master: response too late on session 0x7f6ecc8ceb10 
agentx/master: response too late on session 0x7f6ecc8ceb10 
agentx/master: response too late on session 0x7f6ecc8ceb10 
agentx/master: response too late on session 0x7f6ecc8ceb10 
agentx/master: response too late on session 0x7f6ecc8ceb10 



----- Original Message -----

Fra: "Sverre Moe" <[email protected]> 
Til: [email protected] 
Sendt: 31. oktober 2012 14:23:00 
Emne: Re: Delayed response 



Update: 


Running: snmpget -v2c -c public localhost 1.3.6.1.4.1.49463.1.3.40.0 


This is the frequency my handle_snmp and delayed_response gets called. 
handle_snmp 
handle_snmp 
handle_snmp 
handle_snmp 
handle_snmp 
handle_snmp 
delayed_response 
handle_snmp 
handle_snmp 
handle_snmp 
delayed_response 
delayed_response 
handle_snmp 
delayed_response 
delayed_response 
delayed_response 
handle_snmp 
delayed_response 
delayed_response 
delayed_response 
delayed_response 
delayed_response 



The response are sent to the requester(snmpget) at line 7(the first delayed_response). Why does both the handler method and my delayed callback get called so many times. Delayed time is set to 3 seconds. If I also sends two snmpget at the same time, this output gets jumbled for each call. Is there a way to have some sort of synchronization on the handler. Can I have new calls to wait until the current one has been dispatched? 




/Sverre 

----- Original Message -----

Fra: "Sverre Moe" <[email protected]> 
Til: [email protected] 
Sendt: 30. oktober 2012 15:01:19 
Emne: Delayed response 



Is registering an Net-SNMP alarm the only way to delay a response? 



I don't need to delay for a given amount of time, but until a signal is received (sigc signal). Anyway I could do that? 


If not, the only possible way I see to get around this is to use an alarm with a timeout delay. Wait for 5-10 seconds, check if signal is received and data ready and then send it to the requester, if not send error SNMP_ERR_RESOURCEUNAVAILABLE . 




My code for the delayed handler. I doesn't work if I keep the snmp_alarm_register inside the for-loop. Why is that? It will fail on the line with " if (!cache) { ". 
Also, somehow handle_snmp gets called 4 times when delayed 1 second, 9 times for 2 seconds, 14 times for 3 seconds. I can't have that. Inside my if-statement in the for-loop I call my device to get the information for the request, I cannot call this so many times for one only request. 



[CODE] 

int 
handle_snmp(netsnmp_mib_handler *handler, 
netsnmp_handler_registration *reginfo, 
netsnmp_agent_request_info *reqinfo, 
netsnmp_request_info *requests) { 

const oid* request_oid = (*reginfo).rootoid; 
map<oid_wrapper, scalar>::iterator scalar_iterator; 
for (scalar_iterator = scalars.begin(); 
scalar_iterator != scalars.end(); 
scalar_iterator++) { 
const oid_wrapper oid_wrapper = (*scalar_iterator).first; 
const scalar _scalar = (*scalar_iterator).second; 

const oid* oid_value = oid_wrapper.get_oid(); 
const int oid_length = oid_wrapper.get_length(); 
if (netsnmp_oid_equals(oid_value, oid_length, request_oid, oid_length) == 0) { 
cout << "We got here..." << endl; 

requests->delegated = 1; 
snmp_alarm_register(1, 
0, 
delayed_response, 
(void *) 
netsnmp_create_delegated_cache(handler, 
reginfo, 
reqinfo, 
requests, 
NULL)); 
} else { 
netsnmp_set_request_error(reqinfo, 
requests, 
SNMP_ERR_RESOURCEUNAVAILABLE); 
} 
} 

return SNMP_ERR_NOERROR; 
} 

void 
delayed_response(unsigned int clientreg, void *clientarg) { 
netsnmp_delegated_cache *cache = (netsnmp_delegated_cache *) clientarg; 
netsnmp_request_info *requests; 
netsnmp_agent_request_info *reqinfo; 
cache = netsnmp_handler_check_cache(cache); 

if (!cache) { 
snmp_log(LOG_ERR, "illegal call to return delayed response\n"); 
return; 
} 

reqinfo = cache->reqinfo; 
requests = cache->requests; 

void* datapointer; 
char buffer[2048]; 
int dataint; 
int length = 0; 
u_char type; 

strcpy(buffer, "Testing delayed SNMP"); 
datapointer = buffer; 
length = strlen(buffer); 
type = ASN_OCTET_STR; 

requests->delegated = 0; 
switch(reqinfo->mode) { 
case MODE_GET: 
snmp_set_var_typed_value(requests->requestvb, 
type, 
datapointer, 
length); 
break; 

default: 
snmp_log(LOG_ERR, "unknown mode (%d) in delayed_response\n", reqinfo->mode ); 
} 

netsnmp_free_delegated_cache(cache); 
} 

[/CODE] 


CONFIDENTIALITY
This e-mail and any attachment contain KONGSBERG information which may be
proprietary, confidential or subject to export regulations, and is only meant
for the intended recipient(s). Any disclosure, copying, distribution or use is
prohibited, if not otherwise explicitly agreed with KONGSBERG. If received in
error, please delete it immediately from your system and notify the sender
properly. 



------------------------------------------------------------------------------ 
Everyone hates slow websites. So do we. 
Make your web apps faster with AppDynamics 
Download AppDynamics Lite for free today: 
http://p.sf.net/sfu/appdyn_sfd2d_oct 
_______________________________________________ 
Net-snmp-users mailing list 
[email protected] 
Please see the following page to unsubscribe or change other options: 
https://lists.sourceforge.net/lists/listinfo/net-snmp-users 



CONFIDENTIALITY
This e-mail and any attachment contain KONGSBERG information which may be
proprietary, confidential or subject to export regulations, and is only meant
for the intended recipient(s). Any disclosure, copying, distribution or use is
prohibited, if not otherwise explicitly agreed with KONGSBERG. If received in
error, please delete it immediately from your system and notify the sender
properly. 



------------------------------------------------------------------------------ 
Everyone hates slow websites. So do we. 
Make your web apps faster with AppDynamics 
Download AppDynamics Lite for free today: 
http://p.sf.net/sfu/appdyn_sfd2d_oct 
_______________________________________________ 
Net-snmp-users mailing list 
[email protected] 
Please see the following page to unsubscribe or change other options: 
https://lists.sourceforge.net/lists/listinfo/net-snmp-users 



CONFIDENTIALITY
This e-mail and any attachment contain KONGSBERG information which may be 
proprietary, confidential or subject to export regulations, and is only meant 
for the intended recipient(s). Any disclosure, copying, distribution or use is 
prohibited, if not otherwise explicitly agreed with KONGSBERG. If received in 
error, please delete it immediately from your system and notify the sender 
properly.

------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_sfd2d_oct

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.