Search documentation of snmpkit

# SnmpKit.SnmpSim.BulkOperations (snmpkit v1.3.17)

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

1. Process first N variable bindings as non-repeaters (like GETNEXT)
2. For remaining variable bindings, repeat up to max-repetitions times
3. Respect UDP packet size limits (typically 1472 bytes for Ethernet)
4. Return tooBig error if response would exceed limits

# Summary

## Functions

estimate_response_size(varbinds)

Calculate estimated response size for a list of variable bindings. Used for response size management.

handle_bulk_request(oid_tree, non_repeaters, max_repetitions, varbinds)

Handle a GETBULK request with proper non-repeaters and max-repetitions processing.

optimize_bulk_response(results, max_size \\ 1400)

Optimize bulk response to fit within UDP packet size limits. Estimates response size and truncates if necessary.

process_interface_table(oid_tree, table_oid, max_repetitions)

Process an interface table bulk request efficiently. Optimized for common SNMP table walking operations.

# Functions

# estimate_response_size(varbinds)

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_bulk_request(oid_tree, non_repeaters, max_repetitions, varbinds)

Handle a GETBULK request with proper non-repeaters and max-repetitions processing.

## Parameters

- `oid_tree`: The OID tree to query
- `non_repeaters`: Number of variables to treat as non-repeating (GETNEXT only)
- `max_repetitions`: Maximum number of repetitions for repeating variables
- `varbinds`: 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(results, max_size \\ 1400)

Optimize bulk response to fit within UDP packet size limits. Estimates response size and truncates if necessary.

## Parameters

- `results`: List of {oid, value, behavior} tuples
- `max_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_interface_table(oid_tree, table_oid, max_repetitions)

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
    )