Search documentation of snmpkit

# SnmpKit.SnmpSim.Device.OidHandler (snmpkit v1.3.17)

OID handling and value generation for SNMP device simulation. Handles dynamic OID value generation, interface statistics, and MIB walking.

# Summary

## Functions

build_correlation_factors(state)

Builds correlation factors for related OIDs.

build_device_state(state)

Builds comprehensive device state for monitoring and OID responses.

calculate_cpu_gauge(state)

Calculates CPU utilization gauge with realistic load patterns.

calculate_cpu_utilization(state)

Calculates CPU utilization correlated with network activity.

calculate_error_increment(state, counter_type)

Calculates error increment for error counters with environmental factors.

calculate_error_rate(state)

Calculates error rate as a percentage based on signal quality.

calculate_health_score(state)

Calculates overall device health score.

calculate_interface_utilization(state)

Calculates interface utilization as a percentage.

calculate_packet_increment(state, counter_type)

Calculates packet increment for packet counters.

calculate_signal_quality(state)

Calculates signal quality metric.

calculate_snr_gauge(state)

Calculates Signal-to-Noise Ratio (SNR) gauge value for cable modems.

calculate_storage_gauge(state)

Calculates storage usage gauge in allocation units (typically KB).

calculate_temperature(state)

Calculates device temperature in Celsius.

calculate_traffic_increment(state, counter_type)

Calculates traffic increment for counters based on device type and time.

calculate_uptime(arg1)

Calculates device uptime in milliseconds.

calculate_uptime_ticks(state)

Calculates device uptime in SNMP TimeTicks (centiseconds).

extract_oid(varbind)

Extracts OID from SNMP PDU variable binding.

extract_type_and_value(value)

Extracts type and value from SNMP variable binding.

get_bulk_oid_values(oid, count, state)

Retrieves multiple OIDs for SNMP GetBulk operations.

get_dynamic_oid_value(oid, state)

Gets dynamic OID value based on device state and OID.

get_fallback_bulk_oids(start_oid, max_repetitions, state)

Gets fallback bulk OIDs for SNMP GetBulk operations.

get_fallback_next_oid(oid_list, state)

Gets fallback next OID for SNMP GetNext operations.

get_interface_description(state)

Gets interface description based on device type.

get_next_oid_value(device_type, oid, state)

Finds the next OID in lexicographic order for SNMP GetNext operations.

get_oid_value(oid, state)

Gets OID value based on device state and OID.

get_time_factor()

Gets time-of-day factor for simulating traffic patterns.

handle_docsis_snr_oid(oid, state)

Handles DOCSIS SNR OID.

handle_hc_interface_oid(oid, state)

Handles high capacity interface OID.

handle_host_processor_oid(oid, state)

Handles Host Resources processor OID.

handle_host_storage_oid(oid, state)

Handles Host Resources storage OID.

handle_interface_oid(oid, state)

Handles interface OID.

oid_to_string(oid)

Converts OID list to string representation.

string_to_oid_list(oid_string)

Converts string OID to list of integers.

walk_oid_recursive(oid, root_oid, state, acc)
walk_oid_values(oid, state)

Walks OID values for SNMP MIB walking.

# Functions

# build_correlation_factors(state)

Builds correlation factors for related OIDs.

This can be expanded to track relationships between different metrics.

## Parameters

- `_state` - Device state (currently unused)

## Returns

- Map of correlation factors (currently empty)

# build_device_state(state)

Builds comprehensive device state for monitoring and OID responses.

## Parameters

- `state` - Current device state

## Returns

- Map containing calculated device metrics and status information

# calculate_cpu_gauge(state)

Calculates CPU utilization gauge with realistic load patterns.

## Parameters

- `state` - Device state containing device_type

## Returns

- Integer representing CPU utilization percentage (0-100)

# calculate_cpu_utilization(state)

Calculates CPU utilization correlated with network activity.

## Parameters

- `state` - Device state

## Returns

- Float representing CPU utilization (0.0 to 1.0)

# calculate_error_increment(state, counter_type)

Calculates error increment for error counters with environmental factors.

## Parameters

- `state` - Device state
- `counter_type` - Type of error counter (:in_errors, :out_errors, etc.)

## Returns

- Integer representing error count increment since device start

# calculate_error_rate(state)

Calculates error rate as a percentage based on signal quality.

## Parameters

- `state` - Device state

## Returns

- Float representing error rate percentage (0.0 to 0.05)

# calculate_health_score(state)

Calculates overall device health score.

Health score is based on signal quality, error rate, and uptime stability.

## Parameters

- `state` - Device state

## Returns

- Float representing health score (0.0 to 1.0)

# calculate_interface_utilization(state)

Calculates interface utilization as a percentage.

## Parameters

- `_state` - Device state (currently unused)

## Returns

- Float representing interface utilization (0.1 to 0.8)

# calculate_packet_increment(state, counter_type)

Calculates packet increment for packet counters.

## Parameters

- `state` - Device state
- `counter_type` - Type of packet counter (:in_ucast_pkts, :out_ucast_pkts, etc.)

## Returns

- Integer representing packet count increment since device start

# calculate_signal_quality(state)

Calculates signal quality metric.

## Parameters

- `_state` - Device state (currently unused)

## Returns

- Float representing signal quality (0.0 to 1.0)

# calculate_snr_gauge(state)

Calculates Signal-to-Noise Ratio (SNR) gauge value for cable modems.

## Parameters

- `state` - Device state containing device_type

## Returns

- Integer representing SNR in dB (15-45 range for cable modems)

# calculate_storage_gauge(state)

Calculates storage usage gauge in allocation units (typically KB).

## Parameters

- `state` - Device state containing device_type

## Returns

- Integer representing storage usage in allocation units

# calculate_temperature(state)

Calculates device temperature in Celsius.

Temperature is affected by CPU load and ambient conditions.

## Parameters

- `state` - Device state

## Returns

- Float representing temperature in Celsius

# calculate_traffic_increment(state, counter_type)

Calculates traffic increment for counters based on device type and time.

## Parameters

- `state` - Device state
- `counter_type` - Type of traffic counter (:in_octets, :out_octets, etc.)

## Returns

- Integer representing traffic increment since device start

# calculate_uptime(arg1)

Calculates device uptime in milliseconds.

## Parameters

- `state` - Device state containing uptime_start timestamp

## Returns

- Integer representing uptime in milliseconds

# calculate_uptime_ticks(state)

Calculates device uptime in SNMP TimeTicks (centiseconds).

## Parameters

- `state` - Device state

## Returns

- Integer representing uptime in centiseconds (1/100th of a second)

# extract_oid(varbind)

Extracts OID from SNMP PDU variable binding.

## Parameters

- `varbind` - SNMP variable binding containing OID and value

## Returns

- `oid` - Successfully extracted OID

# extract_type_and_value(value)

Extracts type and value from SNMP variable binding.

## Parameters

- `varbind` - SNMP variable binding

## Returns

- `{type, value}` - Tuple containing SNMP type and value

# get_bulk_oid_values(oid, count, state)

Retrieves multiple OIDs for SNMP GetBulk operations.

## Parameters

- `oid` - Starting OID
- `count` - Maximum number of OIDs to retrieve
- `state` - Device state

## Returns

- List of `{oid, type, value}` tuples

# get_dynamic_oid_value(oid, state)

Gets dynamic OID value based on device state and OID.

## Parameters

- `oid` - OID as string
- `state` - Device state containing configuration and counters

## Returns

- `{:ok, {type, value}}` - Successfully retrieved OID value with type
- `{:error, reason}` - Failed to retrieve OID value

# get_fallback_bulk_oids(start_oid, max_repetitions, state)

Gets fallback bulk OIDs for SNMP GetBulk operations.

## Parameters

- `oid` - Starting OID
- `count` - Maximum number of OIDs to retrieve
- `state` - Device state

## Returns

- List of `{oid, type, value}` tuples

# get_fallback_next_oid(oid_list, state)

Gets fallback next OID for SNMP GetNext operations.

## Parameters

- `oid_list` - Starting OID as list of integers
- `state` - Device state

## Returns

- `{next_oid, type, value}` - Next OID with its type and value

# get_interface_description(state)

Gets interface description based on device type.

## Parameters

- `state` - Device state containing device_type

## Returns

- String description of the interface

# get_next_oid_value(device_type, oid, state)

Finds the next OID in lexicographic order for SNMP GetNext operations.

## Parameters

- `oid` - Starting OID as list of integers
- `state` - Device state

## Returns

- `{:ok, {next_oid, type, value}}` - Next OID with its type and value
- `{:error, :end_of_mib}` - No more OIDs available

# get_oid_value(oid, state)

Gets OID value based on device state and OID.

## Parameters

- `oid` - OID as list of integers or binary string
- `state` - Device state containing configuration and counters or device type

## Returns

- `{:ok, value}` - Successfully retrieved OID value
- `{:error, reason}` - Failed to retrieve OID value

# get_time_factor()

Gets time-of-day factor for simulating traffic patterns.

Peak traffic occurs during evening hours (8-10 PM) with lower utilization during overnight and early morning hours.

## Returns

- Float representing traffic multiplier (0.6 to 1.5)

# handle_docsis_snr_oid(oid, state)

Handles DOCSIS SNR OID.

## Parameters

- `oid` - DOCSIS SNR OID as string
- `state` - Device state

## Returns

- `{:ok, value}` - Successfully retrieved OID value
- `{:error, reason}` - Failed to retrieve OID value

# handle_hc_interface_oid(oid, state)

Handles high capacity interface OID.

## Parameters

- `oid` - High capacity interface OID as string
- `state` - Device state

## Returns

- `{:ok, value}` - Successfully retrieved OID value
- `{:error, reason}` - Failed to retrieve OID value

# handle_host_processor_oid(oid, state)

Handles Host Resources processor OID.

## Parameters

- `oid` - Host Resources processor OID as string
- `state` - Device state

## Returns

- `{:ok, value}` - Successfully retrieved OID value
- `{:error, reason}` - Failed to retrieve OID value

# handle_host_storage_oid(oid, state)

Handles Host Resources storage OID.

## Parameters

- `oid` - Host Resources storage OID as string
- `state` - Device state

## Returns

- `{:ok, value}` - Successfully retrieved OID value
- `{:error, reason}` - Failed to retrieve OID value

# handle_interface_oid(oid, state)

Handles interface OID.

## Parameters

- `oid` - Interface OID as string
- `_state` - Device state (unused)

## Returns

- `{:ok, value}` - Successfully retrieved OID value
- `{:error, reason}` - Failed to retrieve OID value

# oid_to_string(oid)

Converts OID list to string representation.

## Parameters

- `oid` - List of integers representing OID

## Returns

- String representation of OID (e.g., "1.3.6.1.2.1.1.1.0")

# string_to_oid_list(oid_string)

Converts string OID to list of integers.

## Parameters

- `oid_string` - String representation of OID

## Returns

- List of integers representing OID

# walk_oid_recursive(oid, root_oid, state, acc)

# walk_oid_values(oid, state)

Walks OID values for SNMP MIB walking.

## Parameters

- `oid` - Starting OID as list of integers
- `state` - Device state

## Returns

- `{:ok, oid_values}` - List of OID values