Skip to content

Protocol Library Simulation

finthetechguy edited this page Nov 23, 2026 · 1 revision

Simulated Console

The library contains a simulated console that speaks the protocol in either role without a radio. It drives a real link::Link through a whole pass in simulated time, with optional frame loss. It exercises the same frame building, key derivation, CCMP, YY and object code as a real exchange.

The simulator is internal to the crate. It is not part of the public API.

Implemented in: sim.

What it models

flowchart LR
    link["link::Link, the ctrpass side"] -->|"frames"| air["Air: drops about 1 in N frames"]
    air -->|"frames"| console["sim::Console"]
    console -->|"frames"| air2["Air"]
    air2 -->|"frames"| link
    host["Host"] --- link
Loading

The simulated console has a fixed MAC (96:58:cb:11:22:33) and token, and uses a built-in key file with placeholder slot 0x2E and HMAC keys. It takes one of two behaviours:

Behaviour Pairs with ctrpass role What it does
Hosts Lead Answers probes with offers on channel 1, waits a set delay after the first directed probe, then answers with link-up and answers each object.
Leads Wait Sends a broadcast probe every 250 ms, accepts an offer with two accept frames, sends bursts of 3 directed probes every 300 ms, and opens each object once the link is up.

It prepares the same object list a console does: session open, capabilities, services, then the outbox objects from its messages.

Settings

Setting Effect
Messages and services What the console offers
refuse Titles the console refuses in its verdict
link_delay How long after the first directed probe the console announces the link (default 500 ms)
sends_messages Whether the console answers the message list at all; turning it off produces an exchange where the console stores nothing

Answers it gives

As host, the console answers the way ctrpass answers in the Wait role:

Request Answer
0x41, 0x11, 0x21 Its own object, type + 1
0x31 offer Its own offer as 0x32; it also prepares its verdict on the offer
0x43 Its own 0x43
0x23 0x24 with value 2
0x33 verdict Applies the verdict to its own envelopes; answers with its prepared 0x34
0x81 Its own message list and envelopes, once

As lead, it replaces its verdict when the offer reply arrives and applies the peer's verdict reply to its outbox.

Running

sim::run(link, console, host, loss, seed):

  1. Starts a simulated clock.
  2. Every 5 ms of simulated time: polls the link and the console, passes each output frame to the other side unless the air drops it.
  3. Collects the link's events.
  4. Stops when the link is done or 30 s of simulated time have passed.

Frame loss uses a small xorshift generator seeded from seed. With loss set to N, about one frame in N is dropped in each direction. With loss 0 nothing is dropped. The same seed gives the same run.

Because Link and Session take the time as an argument (see Library Modules), the whole pass runs as fast as the code allows and gives the same result every time.

Clone this wiki locally