Search documentation of snmpkit

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

Pre-built test scenarios for common network conditions.

Simplify complex error injection patterns with realistic network scenarios that test SNMP polling systems under various failure conditions.

## Scenario Categories

- Network Outages: Complete connectivity loss and recovery patterns
- Signal Degradation: DOCSIS/wireless signal quality issues
- High Load: Network congestion and overload conditions
- Device Failures: Equipment failures, reboots, and recovery
- Intermittent Issues: Flapping, sporadic failures, timing issues
- Environmental: Weather, power, temperature-related problems

## Usage

    # Apply network outage scenario to all devices
    TestScenarios.network_outage_scenario(devices, duration_seconds: 300)

    # Simulate signal degradation for cable modems
    TestScenarios.signal_degradation_scenario(cable_modems,
      snr_degradation: 10, duration_minutes: 15
    )

    # Test high load conditions
    TestScenarios.high_load_scenario(devices, utilization_percent: 95)

# Summary

## Types

device_list()
scenario_result()

## Functions

cascading_failure_scenario(devices, opts \\ [])

Simulate cascading failure - devices fail in sequence.

device_flapping_scenario(devices, opts \\ [])

Simulate device flapping - intermittent connectivity issues.

environmental_scenario(devices, opts \\ [])

Simulate environmental conditions affecting network equipment.

high_load_scenario(devices, opts \\ [])

Simulate high network load and congestion conditions.

multi_scenario_test(devices, scenarios)

Apply multiple scenarios simultaneously for complex testing.

network_outage_scenario(devices, opts \\ [])

Simulate complete network outage affecting all devices.

signal_degradation_scenario(devices, opts \\ [])

Simulate signal degradation for wireless/cable devices.

# Types

# device_list()

    @type device_list() :: [pid()] | [{:device_type, integer()}]

# scenario_result()

    @type scenario_result() :: %{
      scenario_id: String.t(),
      start_time: DateTime.t(),
      devices_affected: integer(),
      conditions_applied: [map()],
      estimated_duration_ms: integer()
    }

# Functions

# cascading_failure_scenario(devices, opts \\ [])

    @spec cascading_failure_scenario(
      device_list(),
      keyword()
    ) :: scenario_result()

Simulate cascading failure - devices fail in sequence.

Models scenarios where initial failures trigger subsequent failures, testing system resilience under escalating conditions.

## Options

- `initial_failure_percentage`: Initial devices that fail (default: 0.1)
- `cascade_delay_seconds`: Time between cascade waves (default: 60)
- `cascade_growth_factor`: How much each wave grows (default: 1.5)
- `max_affected_percentage`: Maximum devices affected (default: 0.8)

## Examples

    # Start with 5% failure, cascade every 30 seconds
    TestScenarios.cascading_failure_scenario(devices,
      initial_failure_percentage: 0.05,
      cascade_delay_seconds: 30,
      cascade_growth_factor: 2.0
    )

# device_flapping_scenario(devices, opts \\ [])

    @spec device_flapping_scenario(
      device_list(),
      keyword()
    ) :: scenario_result()

Simulate device flapping - intermittent connectivity issues.

Models unstable devices that repeatedly go offline and come back online.

## Options

- `flap_interval_seconds`: Time between state changes (default: 30)
- `down_duration_seconds`: How long device stays down (default: 10)
- `total_duration_minutes`: Total scenario duration (default: 30)

- `flap_pattern`: `:regular` | `:irregular` | `:degrading` (default: :irregular)

## Examples

    # Regular flapping every 60 seconds
    TestScenarios.device_flapping_scenario(devices,
      flap_interval_seconds: 60,
      down_duration_seconds: 15,
      flap_pattern: :regular
    )

    # Irregular flapping with degrading stability
    TestScenarios.device_flapping_scenario(devices,
      flap_pattern: :degrading,
      total_duration_minutes: 45
    )

# environmental_scenario(devices, opts \\ [])

    @spec environmental_scenario(
      device_list(),
      keyword()
    ) :: scenario_result()

Simulate environmental conditions affecting network equipment.

Models weather, power, or temperature-related issues that affect multiple devices simultaneously.

## Options

- `condition_type`: `:weather` | `:power` | `:temperature` | `:interference`

- `severity`: `:mild` | `:moderate` | `:severe` (default: :moderate)

- `duration_hours`: Condition duration (default: 2)

- `geographic_pattern`: `:random` | `:clustered` | `:linear` (default: :clustered)

## Examples

    # Severe weather affecting clustered devices
    TestScenarios.environmental_scenario(devices,
      condition_type: :weather,
      severity: :severe,
      duration_hours: 4,
      geographic_pattern: :clustered
    )

    # Power instability
    TestScenarios.environmental_scenario(devices,
      condition_type: :power,
      severity: :moderate,
      duration_hours: 1
    )

# high_load_scenario(devices, opts \\ [])

    @spec high_load_scenario(
      device_list(),
      keyword()
    ) :: scenario_result()

Simulate high network load and congestion conditions.

Tests poller behavior under network stress with increased latency, packet loss, and timeout conditions.

## Options

- `utilization_percent`: Network utilization level (default: 85)
- `duration_minutes`: Load duration (default: 60)

- `congestion_type`: `:steady` | `:bursty` | `:cascade` (default: :bursty)

- `error_rate_multiplier`: Error rate increase factor (default: 5.0)

## Examples

    # Sustained high load
    TestScenarios.high_load_scenario(devices,
      utilization_percent: 95,
      duration_minutes: 120,
      congestion_type: :steady
    )

    # Bursty congestion with high error rates
    TestScenarios.high_load_scenario(devices,
      utilization_percent: 90,
      congestion_type: :bursty,
      error_rate_multiplier: 10.0
    )

# multi_scenario_test(devices, scenarios)

    @spec multi_scenario_test(device_list(), [{atom(), keyword()}]) :: [scenario_result()]

Apply multiple scenarios simultaneously for complex testing.

Combines different failure patterns to test system behavior under realistic multi-factor conditions.

## Examples

    scenarios = [
      {:signal_degradation, [snr_degradation: 8, duration_minutes: 60]},
      {:high_load, [utilization_percent: 90, duration_minutes: 45]},
      {:device_flapping, [flap_interval_seconds: 120]}
    ]

    TestScenarios.multi_scenario_test(devices, scenarios)

# network_outage_scenario(devices, opts \\ [])

    @spec network_outage_scenario(
      device_list(),
      keyword()
    ) :: scenario_result()

Simulate complete network outage affecting all devices.

Tests poller behavior during total connectivity loss and recovery.

## Options

- `duration_seconds`: Outage duration (default: 300)

- `recovery_type`: `:immediate` | `:gradual` | `:sporadic` (default: :gradual)

- `affected_percentage`: Percentage of devices affected (default: 1.0)

## Examples

    # 5-minute complete outage
    TestScenarios.network_outage_scenario(devices, duration_seconds: 300)

    # Gradual recovery affecting 80% of devices
    TestScenarios.network_outage_scenario(devices,
      duration_seconds: 600,
      recovery_type: :gradual,
      affected_percentage: 0.8
    )

# signal_degradation_scenario(devices, opts \\ [])

    @spec signal_degradation_scenario(
      device_list(),
      keyword()
    ) :: scenario_result()

Simulate signal degradation for wireless/cable devices.

Models weather-related signal issues, interference, or equipment problems.

## Options

- `snr_degradation`: SNR reduction in dB (default: 5)
- `power_variation`: Power level variation in dBmV (default: 3)
- `duration_minutes`: Degradation duration (default: 30)

- `pattern`: `:steady` | `:fluctuating` | `:progressive` (default: :fluctuating)

## Examples

    # Weather-related signal degradation
    TestScenarios.signal_degradation_scenario(cable_modems,
      snr_degradation: 10,
      power_variation: 5,
      duration_minutes: 45,
      pattern: :progressive
    )