How to Use SNMP GetBulk Requests


When using SNMP version 2 or higher, the SNMPMgr and SNMPTCPMgr components can make use of the SendGetBulkRequest method in order to avoid repeated calls to SendGetNextRequest.

The behavior of SendGetBulkRequest is controlled by two parameters: nonRepeaters and maxRepetitions. The example below demonstrates how these parameters affect the results.

C# Example

// Specify some OIDs that we are interested in getting information about.
snmpmgr1.Objects.Add(new SNMPObject("1.3.6.1.2.1.1.1"));
snmpmgr1.Objects.Add(new SNMPObject("1.3.6.1.2.1.1.2"));
snmpmgr1.Objects.Add(new SNMPObject("1.3.6.1.2.1.1.3"));
snmpmgr1.Objects.Add(new SNMPObject("1.3.6.1.2.1.1.4"));
// Send the GetBulk request to MyAgent with nonRepeaters=2 and maxRepetitions=3.
snmpmgr1.RemoteHost = "MyAgent";
snmpmgr1.SendGetBulkRequest(2, 3);
// Print the returned OIDs
for (int i = 0; i < snmpmgr1.Objects.Count; i++) {
    Console.WriteLine(snmpmgr1.Objects[i].Oid);
}

Resulting Output

1.3.6.1.2.1.1.2 
1.3.6.1.2.1.1.3 
1.3.6.1.2.1.1.4 
1.3.6.1.2.1.1.5 
1.3.6.1.2.1.1.5 
1.3.6.1.2.1.1.6 
1.3.6.1.2.1.1.6 
1.3.6.1.2.1.1.7 

In this example, four OIDs are requested, with nonRepeaters = 2 and maxRepetitions = 3. The total number of returned objects will not exceed N + (M * R), where: - N = nonRepeaters - M = maxRepetitions - R = number of requested OIDs minus N

The Effect of nonRepeaters

Setting nonRepeaters to 2 causes the first two OIDs to be processed with a single GetNext request each, resulting in:

1.3.6.1.2.1.1.2 
1.3.6.1.2.1.1.3 

The Effect of maxRepetitions

Setting maxRepetitions to 3 causes the remaining OIDs to be iterated using GetNext up to three times each, resulting in:

1.3.6.1.2.1.1.4 (First GetNext originating from 1.3.6.1.2.1.1.3) 
1.3.6.1.2.1.1.5 (First GetNext originating from 1.3.6.1.2.1.1.4) 
1.3.6.1.2.1.1.5 (Second GetNext originating from 1.3.6.1.2.1.1.3) 
1.3.6.1.2.1.1.6 (Second GetNext originating from 1.3.6.1.2.1.1.4) 
1.3.6.1.2.1.1.6 (Third GetNext originating from 1.3.6.1.2.1.1.3) 
1.3.6.1.2.1.1.7 (Third GetNext originating from 1.3.6.1.2.1.1.4) 

Using SendGetBulkRequest reduces the number of requests required to retrieve sequential SNMP data, making it more efficient than issuing multiple GetNext requests individually.

We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.