SnmpKit.SnmpSim.BulkOperations (snmpkit v0.6.4)
Efficient GETBULK implementation for SNMPv2c. Handles non-repeaters, max-repetitions, and response size management.
GETBULK is a powerful SNMP operation that retrieves multiple variables in a single request. It's particularly useful for retrieving large tables like interface statistics.
Algorithm
- Process first N variable bindings as non-repeaters (like GETNEXT)
- For remaining variable bindings, repeat up to max-repetitions times
- Respect UDP packet size limits (typically 1472 bytes for Ethernet)
- Return tooBig error if response would exceed limits
Summary
Functions
Calculate estimated response size for a list of variable bindings. Used for response size management.
Handle a GETBULK request with proper non-repeaters and max-repetitions processing.
Optimize bulk response to fit within UDP packet size limits. Estimates response size and truncates if necessary.
Process an interface table bulk request efficiently. Optimized for common SNMP table walking operations.
Functions
Calculate estimated response size for a list of variable bindings. Used for response size management.
Examples
size = SnmpKit.SnmpSim.BulkOperations.estimate_response_size(varbinds)
Handle a GETBULK request with proper non-repeaters and max-repetitions processing.
Parameters
oid_tree
: The OID tree to querynon_repeaters
: Number of variables to treat as non-repeating (GETNEXT only)max_repetitions
: Maximum number of repetitions for repeating variablesvarbinds
: List of starting OIDs for the bulk operation
Returns
{:ok, result_varbinds}
: Successful bulk operation results{:error, :too_big}
: Response would exceed UDP size limits{:error, reason}
: Other error conditions
Examples
varbinds = [{"1.3.6.1.2.1.2.2.1.1", nil}, {"1.3.6.1.2.1.2.2.1.2", nil}]
{:ok, results} = SnmpKit.SnmpSim.BulkOperations.handle_bulk_request(
tree, 0, 10, varbinds
)
Optimize bulk response to fit within UDP packet size limits. Estimates response size and truncates if necessary.
Parameters
results
: List of {oid, value, behavior} tuplesmax_size
: Maximum response size in bytes (default: 1400)
Returns
{:ok, optimized_results}
: Results that fit within size limit{:error, :too_big}
: Even minimal response exceeds size limit
Examples
{:ok, optimized} = SnmpKit.SnmpSim.BulkOperations.optimize_bulk_response(results, 1400)
Process an interface table bulk request efficiently. Optimized for common SNMP table walking operations.
Examples
{:ok, results} = SnmpKit.SnmpSim.BulkOperations.process_interface_table(
tree, "1.3.6.1.2.1.2.2.1", 10
)