# `MaeBPF.Sim`
[🔗](https://github.com/cocoa-xu/MaeBPF/blob/v0.1.0/maebpf/lib/maebpf/sim.ex#L1)

Pure-Elixir macOS and Linux simulator for `MaeBPF.IR` pipelines.

Executes the exact fused IR operations generated by `use MaeBPF` or
`MaeBPF.compile_pipeline/2` without requiring Linux or root privileges,
returning the packet verdict, per-plug execution trace, updated map states,
RingBuf event streams, and hidden `ringbuf_drops` counts.

# `run`

Simulates a single packet (or tracepoint event) through hook `hook_name` of
`module_or_ir`.

`state` options:
  * `:maps` - initial map contents (`%{map_id => ...}`):
    - counters: `%{0 => count, 1 => bytes}`
    - exact IPv4 blocklists (`:hash` / `:lru_hash`): `MapSet`, list, or map of
      IPv4 strings, 4-tuples, or 4-byte binaries
    - CIDR LPM blocklists (`:lpm_trie`): `MapSet`, list, or map of CIDR strings
      (`"10.0.0.0/8"`), `{ip, prefix}` tuples, or 8-byte LPM keys
  * `:ringbuf` - initial emitted 16-byte binary events per stream (`%{stream => [...]}`)
  * `:ringbuf_capacity` - simulated max queued events per stream
    (`%{stream => non_neg_integer()}` or integer default for all streams).
    When full, emitting increments both `drops[stream]` and the hidden
    `"__maebpf_rb_drops_<stream>"` map slot `0`.
  * `:drops` - initial drop counts per stream (`%{stream => count}`)
  * `:sample_seq` - sampling counter state persisted across multi-packet runs
  * `:debug_trace` - when `true`, runs with per-plug debug RingBuf emission
    into `:__maebpf_debug_rb` (honoring optional `:debug_sample` / `:sample`)

Returns:
    %{
      action: :drop | :pass | :tx | :redirect | :aborted | :next | :ok,
      trace: [{plug_module, :cont | {:halt, action}}],
      maps: %{map_id => term()},
      ringbuf: %{stream_id => [binary()]},
      events: %{stream_id => [map()]},
      drops: %{stream_id => non_neg_integer()},
      sample_seq: map()
    }

---

*Consult [api-reference.md](api-reference.md) for complete listing*
