Files
fips/testing/chaos/sim/__main__.py
T
Johnathan Corgan b3a1fb464f testing: add bloom-storm chaos scenario
Six-node depth-4 mesh with an induced upstream parent flap. Asserts a
trailing-window ceiling on per-node `stats.bloom.sent` and a sanity
floor on parent-switch count over a ~3-4 min observation window.

Guards against the regression class where a spanning-tree update that
changes only an internal path edge (no root or depth delta) fails to
be properly contained and instead propagates to leaves as a sustained
bloom-traffic oscillation, visible only at fleet scale and only after
several minutes of uptime.

Adds a new chaos primitive (`link_swap`) for deterministic asymmetric
link-cost flapping and a post-run assertion framework with two
checks:

  - `bloom_send_rate.max_per_node`: trailing-window ceiling on the
    `show_bloom` stats counter delta. Calibrated against the
    post-mortem reproduction harness data (per-variant counter table
    against pre-fix vs post-fix binaries).

  - `min_parent_switches.min_total`: sanity guard against a
    misconfigured harness where the flap inducer fires but the
    topology never produces a real parent-switch event (e.g., wrong
    root election from a different seed). Without this, the
    bloom-rate assertion would trivially pass on any binary
    including a regressed one.

The runner exits 3 on assertion failure (alongside 0 success and 2
panic-detected). Threshold derivation is documented in the scenario
README; the seed pin is also documented there since smallest-NodeAddr
root election is sensitive to the pubkey hash ordering.

Wired into ci-local.sh's chaos pool and the GitHub CI chaos matrix.
2026-05-08 18:24:58 +00:00

64 lines
1.6 KiB
Python

"""CLI entry point: python -m sim <scenario.yaml>"""
import argparse
import logging
import sys
from .runner import SimRunner
from .scenario import load_scenario
def main():
parser = argparse.ArgumentParser(
prog="sim",
description="FIPS stochastic network simulation",
)
parser.add_argument("scenario", help="Path to scenario YAML file")
parser.add_argument(
"-v", "--verbose", action="store_true", help="Enable debug logging"
)
parser.add_argument(
"--seed", type=int, default=None,
help="Override scenario seed",
)
parser.add_argument(
"--duration", type=int, default=None,
help="Override scenario duration in seconds",
)
args = parser.parse_args()
level = logging.DEBUG if args.verbose else logging.INFO
logging.basicConfig(
level=level,
format="%(asctime)s %(levelname)-5s %(name)s: %(message)s",
datefmt="%H:%M:%S",
)
try:
scenario = load_scenario(args.scenario)
except (FileNotFoundError, ValueError) as e:
print(f"Error loading scenario: {e}", file=sys.stderr)
sys.exit(1)
# Apply CLI overrides
if args.seed is not None:
scenario.seed = args.seed
if args.duration is not None:
if args.duration < 1:
print("Error: --duration must be >= 1", file=sys.stderr)
sys.exit(1)
scenario.duration_secs = args.duration
runner = SimRunner(scenario)
result = runner.run()
if result and result.panics:
sys.exit(2)
if runner.assertions_failed:
sys.exit(3)
sys.exit(0)
if __name__ == "__main__":
main()