SNMP Code Example: Bulk 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 result set of a call to SendGetBulkRequest is controlled by two parameters: nonRepeaters and maxRepetitions. To help explain what effect these parameters have when calling SendGetBulkRequest, I will first provide a code snippet and the output that would result. The code snippet uses SNMPMgr, but the same concepts apply for SNMPTCPMgr.
C#
// 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);
}
As you can see, I've included four OIDs with my request, 1.3.6.1.2.1.1.1-1.3.6.1.2.1.1.4. I've also set nonRepeaters to '2' and maxRepetitions to '3'. The output of this code snippet would be:
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.7The number of objects returned in the response may vary based on packet size constraints, but it will never be more than N + (M * R), where N is the value of nonRepeaters, M is the value of maxRepetitions, and R is the number OIDs in the request minus N (so in our example, N=2, M=3, and R=2). Now, let's discuss why we got the results we did.
The effect of nonRepeaters
By setting nonRepeaters to '2', I requested that the agent do a single GetNext for the first two OIDs I provided (1.3.6.1.2.1.1.1 and 1.3.6.1.2.1.1.2). The following OIDs are the result of that:
1.3.6.1.2.1.1.2 1.3.6.1.2.1.1.3
The effect of maxRepetitions
By setting maxRepetitions to '3', I've requested that the agent then continually do GetNext, up to three times, for the remaining OIDs (1.3.6.1.2.1.1.3 and 1.3.6.1.2.1.1.4). The following OIDs are the result of that:
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)
We appreciate your feedback. If you have any questions, comments, or suggestions about this article please contact our support team at support@nsoftware.com.