Linear Backoff for Net SNMP retries

By default, all snmp retries are transmitted at the same interval. However, we don’t want that to happen when the client is on a vpn connection or the network is flaky and the responses to snmp requests reach later than the timeout period. In such cases, we would want an increasing timeout value to accommodate snmp entities which cannot respond within the timeout interval.

Does that sound too complicated? In fact, this can be done very easily. Here’s a little tip.

All this needs is a one line change in the snmp code.

Download the net-snmp code either from the Net Snmp website or from you Linux distribution website.

For Ubuntu, you can use the following command.

apt-get source snmp

Now, look up the function snmp_resend_request present in snmp_api.c

static int
snmp_resend_request(...)
{

.

.

rp->retries++;
result = transpor->f_send(...);

.

.

gettimeofday(&now, (struct timezone *) 0);
tv = now;
rp->time = tv;
tv.tv_usec += rp->timeout;
tv.tv_sec += tv.tv_usec / 1000000L;
tv.tv_usec %= 1000000L;
rp->expire = tv;
}
return 0;
}

In the code above change, tv.tv_usec += rp->timeout to tv.tv_usec += rp->timeout*(rp->retries+1);

This would change the timeout values to multiples of the original timeout value, for the nth retries the timeout value would be n*(default timeout value).

The above change isn’t really ‘exponential’ backoff, but you could use your own formula to implement the real exponential backoff mechanism.

About Pratik Sinha

Linux Nerd, Socialist, Atheist, Adventuristic, Nature Lover, Geeky.

Leave a Reply