SnmpKit.SnmpSim.Device (snmpkit v2.0.1)
Lightweight Device GenServer for handling SNMP requests. Uses shared profiles and minimal device-specific state for scalability.
Features:
- Dynamic value generation with realistic patterns
- Shared profile system for memory efficiency
- Counter and gauge simulation with proper incrementing
- Comprehensive error handling and fallback mechanisms
- Support for SNMP walk operations
Summary
Functions
Returns a specification to start this module under a supervisor.
Cleanup all orphaned SNMP simulator device processes. Useful for test cleanup when devices may have been left running.
Get an OID value from the device (for testing).
Get bulk OID values from the device (for testing).
Get device information and statistics.
Get the next OID value from the device (for testing).
Monitor a device process and get notified when it dies. Returns a monitor reference that can be used with Process.demonitor/1.
Simulate a device reboot.
Sends a trap from this device to a receiver, using the device's community
and uptime. opts must include to: target (host, "host:port" or
{host, port}, port 162 by default); the other options are those of
SnmpKit.SnmpMgr.Notify.send_trap/4.
Set a gauge value manually (useful for testing).
Start a device with the given device configuration.
Create a device with monitoring enabled. Returns {:ok, {device_pid, monitor_ref}} or {:error, reason}.
Stop a device gracefully with resilient error handling.
Update device counters manually (useful for testing).
Walk OID values from the device (for testing).
Functions
Returns a specification to start this module under a supervisor.
See Supervisor.
Cleanup all orphaned SNMP simulator device processes. Useful for test cleanup when devices may have been left running.
Get an OID value from the device (for testing).
Get bulk OID values from the device (for testing).
Get device information and statistics.
Get the next OID value from the device (for testing).
Monitor a device process and get notified when it dies. Returns a monitor reference that can be used with Process.demonitor/1.
Simulate a device reboot.
Sends a trap from this device to a receiver, using the device's community
and uptime. opts must include to: target (host, "host:port" or
{host, port}, port 162 by default); the other options are those of
SnmpKit.SnmpMgr.Notify.send_trap/4.
:ok = SnmpKit.SnmpSim.Device.send_trap(device, "linkDown", [{"ifIndex.1", :integer, 1}], to: "127.0.0.1:1162")
Set a gauge value manually (useful for testing).
Start a device with the given device configuration.
Device Config
Device config should contain:
:port- UDP port for the device (required):device_type- Type of device (:cable_modem, :switch, etc.):device_id- Unique device identifier:community- SNMP community string (default: "public"):mac_address- MAC address (auto-generated if not provided):seed- integer seed for the device process's random number generator. Probabilistic error injection (SnmpKit.SnmpSim.ErrorInjector) draws from it, so two devices started with the same seed and the same error conditions answer an identical request sequence identically. Unseeded devices use the VM's default per-process seeding.
Examples
device_config = %{
port: 9001,
device_type: :cable_modem,
device_id: "cable_modem_9001",
community: "public"
}
{:ok, device} = SnmpKit.SnmpSim.Device.start_link(device_config)
Create a device with monitoring enabled. Returns {:ok, {device_pid, monitor_ref}} or {:error, reason}.
Stop a device gracefully with resilient error handling.
Update device counters manually (useful for testing).
Walk OID values from the device (for testing).