SnmpKit.SnmpSim.Device.OidHandler (snmpkit v0.6.4)
OID handling and value generation for SNMP device simulation. Handles dynamic OID value generation, interface statistics, and MIB walking.
Summary
Functions
Builds correlation factors for related OIDs.
Builds comprehensive device state for monitoring and OID responses.
Calculates CPU utilization gauge with realistic load patterns.
Calculates CPU utilization correlated with network activity.
Calculates error increment for error counters with environmental factors.
Calculates error rate as a percentage based on signal quality.
Calculates overall device health score.
Calculates interface utilization as a percentage.
Calculates packet increment for packet counters.
Calculates signal quality metric.
Calculates Signal-to-Noise Ratio (SNR) gauge value for cable modems.
Calculates storage usage gauge in allocation units (typically KB).
Calculates device temperature in Celsius.
Calculates traffic increment for counters based on device type and time.
Calculates device uptime in milliseconds.
Calculates device uptime in SNMP TimeTicks (centiseconds).
Extracts OID from SNMP PDU variable binding.
Extracts type and value from SNMP variable binding.
Retrieves multiple OIDs for SNMP GetBulk operations.
Gets dynamic OID value based on device state and OID.
Gets fallback bulk OIDs for SNMP GetBulk operations.
Gets fallback next OID for SNMP GetNext operations.
Gets interface description based on device type.
Finds the next OID in lexicographic order for SNMP GetNext operations.
Gets OID value based on device state and OID.
Gets time-of-day factor for simulating traffic patterns.
Handles DOCSIS SNR OID.
Handles high capacity interface OID.
Handles Host Resources processor OID.
Handles Host Resources storage OID.
Handles interface OID.
Converts OID list to string representation.
Converts string OID to list of integers.
Walks OID values for SNMP MIB walking.
Functions
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)
Builds comprehensive device state for monitoring and OID responses.
Parameters
state
- Current device state
Returns
- Map containing calculated device metrics and status information
Calculates CPU utilization gauge with realistic load patterns.
Parameters
state
- Device state containing device_type
Returns
- Integer representing CPU utilization percentage (0-100)
Calculates CPU utilization correlated with network activity.
Parameters
state
- Device state
Returns
- Float representing CPU utilization (0.0 to 1.0)
Calculates error increment for error counters with environmental factors.
Parameters
state
- Device statecounter_type
- Type of error counter (:in_errors, :out_errors, etc.)
Returns
- Integer representing error count increment since device start
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)
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)
Calculates interface utilization as a percentage.
Parameters
_state
- Device state (currently unused)
Returns
- Float representing interface utilization (0.1 to 0.8)
Calculates packet increment for packet counters.
Parameters
state
- Device statecounter_type
- Type of packet counter (:in_ucast_pkts, :out_ucast_pkts, etc.)
Returns
- Integer representing packet count increment since device start
Calculates signal quality metric.
Parameters
_state
- Device state (currently unused)
Returns
- Float representing signal quality (0.0 to 1.0)
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)
Calculates storage usage gauge in allocation units (typically KB).
Parameters
state
- Device state containing device_type
Returns
- Integer representing storage usage in allocation units
Calculates device temperature in Celsius.
Temperature is affected by CPU load and ambient conditions.
Parameters
state
- Device state
Returns
- Float representing temperature in Celsius
Calculates traffic increment for counters based on device type and time.
Parameters
state
- Device statecounter_type
- Type of traffic counter (:in_octets, :out_octets, etc.)
Returns
- Integer representing traffic increment since device start
Calculates device uptime in milliseconds.
Parameters
state
- Device state containing uptime_start timestamp
Returns
- Integer representing uptime in milliseconds
Calculates device uptime in SNMP TimeTicks (centiseconds).
Parameters
state
- Device state
Returns
- Integer representing uptime in centiseconds (1/100th of a second)
Extracts OID from SNMP PDU variable binding.
Parameters
varbind
- SNMP variable binding containing OID and value
Returns
oid
- Successfully extracted OID
Extracts type and value from SNMP variable binding.
Parameters
varbind
- SNMP variable binding
Returns
{type, value}
- Tuple containing SNMP type and value
Retrieves multiple OIDs for SNMP GetBulk operations.
Parameters
oid
- Starting OIDcount
- Maximum number of OIDs to retrievestate
- Device state
Returns
- List of
{oid, type, value}
tuples
Gets dynamic OID value based on device state and OID.
Parameters
oid
- OID as stringstate
- Device state containing configuration and counters
Returns
{:ok, {type, value}}
- Successfully retrieved OID value with type{:error, reason}
- Failed to retrieve OID value
Gets fallback bulk OIDs for SNMP GetBulk operations.
Parameters
oid
- Starting OIDcount
- Maximum number of OIDs to retrievestate
- Device state
Returns
- List of
{oid, type, value}
tuples
Gets fallback next OID for SNMP GetNext operations.
Parameters
oid_list
- Starting OID as list of integersstate
- Device state
Returns
{next_oid, type, value}
- Next OID with its type and value
Gets interface description based on device type.
Parameters
state
- Device state containing device_type
Returns
- String description of the interface
Finds the next OID in lexicographic order for SNMP GetNext operations.
Parameters
oid
- Starting OID as list of integersstate
- Device state
Returns
{:ok, {next_oid, type, value}}
- Next OID with its type and value{:error, :end_of_mib}
- No more OIDs available
Gets OID value based on device state and OID.
Parameters
oid
- OID as list of integers or binary stringstate
- Device state containing configuration and counters or device type
Returns
{:ok, value}
- Successfully retrieved OID value{:error, reason}
- Failed to retrieve OID value
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)
Handles DOCSIS SNR OID.
Parameters
oid
- DOCSIS SNR OID as stringstate
- Device state
Returns
{:ok, value}
- Successfully retrieved OID value{:error, reason}
- Failed to retrieve OID value
Handles high capacity interface OID.
Parameters
oid
- High capacity interface OID as stringstate
- Device state
Returns
{:ok, value}
- Successfully retrieved OID value{:error, reason}
- Failed to retrieve OID value
Handles Host Resources processor OID.
Parameters
oid
- Host Resources processor OID as stringstate
- Device state
Returns
{:ok, value}
- Successfully retrieved OID value{:error, reason}
- Failed to retrieve OID value
Handles Host Resources storage OID.
Parameters
oid
- Host Resources storage OID as stringstate
- Device state
Returns
{:ok, value}
- Successfully retrieved OID value{:error, reason}
- Failed to retrieve OID value
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
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")
Converts string OID to list of integers.
Parameters
oid_string
- String representation of OID
Returns
- List of integers representing OID
Walks OID values for SNMP MIB walking.
Parameters
oid
- Starting OID as list of integersstate
- Device state
Returns
{:ok, oid_values}
- List of OID values