SnmpKit.SnmpSim (snmpkit v1.4.0)
Top-level API for the SNMP device simulator.
The simulator can be driven two ways:
- Programmatically, one device at a time, with
start_device/2(or theSnmpKit.Simfacade) and a profile fromSnmpKit.SnmpSim.ProfileLoader. - From a configuration, describing whole device groups, with
start/1orstart_link/1. The configuration is a map (seesample_config/0) or the path of a JSON / YAML file (seeload_config/1).
Devices started from a configuration run under the application's device
supervisor (SnmpSim.DeviceSupervisor), so they survive the caller and can
be inspected with list_devices/0 and torn down with stop/0.
Example
config = %{
snmp_sim: %{
device_groups: [
%{
name: "cable_modems",
device_type: "cable_modem",
count: 10,
port_range: %{start: 30_000, end: 30_009},
community: "public",
walk_file: "priv/walks/cable_modem.walk"
}
]
}
}
{:ok, _supervisor} = SnmpKit.SnmpSim.start(config)
10 = SnmpKit.SnmpSim.device_count()
{:ok, %{value: descr}} = SnmpKit.SNMP.get("127.0.0.1", "sysDescr.0", port: 30_000)
:ok = SnmpKit.SnmpSim.stop()
Summary
Functions
Number of devices running under the device supervisor.
Lists the devices running under the device supervisor.
Loads a configuration file. .json files are decoded with Jason; .yaml /
.yml files require the optional yaml_elixir dependency.
A complete example configuration, useful as a starting point.
Starts every device group in config under the device supervisor.
Starts one device from a SnmpKit.SnmpSim.ProfileLoader profile.
Starts a mixed population of devices; see SnmpKit.TestSupport.start_device_population/2.
Same as start/1.
Stops every device running under the device supervisor.
Stops one device, given its pid or its UDP port.
The device supervisor pid, or {:error, :not_started} if the application is not running.
Validates a configuration map without starting anything.
Writes sample_config/0 to path as :json or :yaml.
Types
Functions
@spec device_count() :: non_neg_integer()
Number of devices running under the device supervisor.
@spec list_devices() :: [device_info()]
Lists the devices running under the device supervisor.
Each entry has :pid, :device_id, :device_type and :port; the last
three are nil if a device did not answer its info call in time.
Loads a configuration file. .json files are decoded with Jason; .yaml /
.yml files require the optional yaml_elixir dependency.
A complete example configuration, useful as a starting point.
Starts every device group in config under the device supervisor.
config is a configuration map (with or without the top-level :snmp_sim
key) or the path of a JSON / YAML file. Returns {:ok, supervisor_pid}; the
started devices are available through list_devices/0.
Starts one device from a SnmpKit.SnmpSim.ProfileLoader profile.
Options: :port (required), :device_id, :community. The device is
linked to the caller; see SnmpKit.TestSupport.start_device/2.
Starts a mixed population of devices; see SnmpKit.TestSupport.start_device_population/2.
Same as start/1.
The name is kept for compatibility with the original draft of this module. Note that the devices are supervised by the application, not linked to the caller, so this is safe to call from any process.
@spec stop() :: :ok
Stops every device running under the device supervisor.
@spec stop_device(pid() | non_neg_integer()) :: :ok | {:error, :not_found}
Stops one device, given its pid or its UDP port.
@spec supervisor() :: {:ok, pid()} | {:error, :not_started}
The device supervisor pid, or {:error, :not_started} if the application is not running.
Validates a configuration map without starting anything.
Writes sample_config/0 to path as :json or :yaml.