smolpy 1.12.0__tar.gz → 1.12.1.dev2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (165) hide show
  1. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/PKG-INFO +17 -12
  2. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/README.md +15 -10
  3. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/__main__.py +24 -1
  4. smolpy-1.12.1.dev2/benchmarks/ingress.py +239 -0
  5. smolpy-1.12.1.dev2/benchmarks/results/2026-11-24-0836-simpy-rust-ns3-jaws-zbook-ingress-buffers.json +3337 -0
  6. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0004-execution-backends.md +2 -2
  7. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0011-bounded-switch-buffers.md +3 -1
  8. smolpy-1.12.1.dev2/docs/adr/0013-ingress-buffer-accounting.md +372 -0
  9. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/backends.md +37 -0
  10. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/benchmarks.md +4 -0
  11. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/dsl-reference.md +30 -9
  12. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/examples.md +19 -0
  13. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/language-reference.md +24 -10
  14. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/modbus.md +3 -1
  15. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/model-semantics.md +41 -18
  16. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/roadmap.md +19 -0
  17. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/scenario-model.md +3 -3
  18. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/README.md +24 -8
  19. smolpy-1.12.1.dev2/examples/example_ingress_buffer.smol +50 -0
  20. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/mkdocs.yml +1 -0
  21. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/pyproject.toml +6 -5
  22. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smol-engine/src/scenario.rs +72 -14
  23. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smol-engine/src/sim.rs +369 -103
  24. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smolpy-engine-rs/README.md +4 -3
  25. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/__init__.py +2 -0
  26. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/backends.py +49 -6
  27. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/core/adapter.py +42 -14
  28. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/core/network.py +17 -17
  29. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/ethernet/switch.py +41 -5
  30. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/lang/ast.py +4 -1
  31. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/lang/interpreter.py +7 -5
  32. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/lang/transformer.py +22 -1
  33. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/modbus/slave.py +5 -5
  34. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/model/scenario.py +45 -6
  35. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/model/validate.py +59 -19
  36. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/mqtt/broker.py +2 -3
  37. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/ns3/__init__.py +29 -6
  38. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/ns3/cpp/smol-ns3.cc +205 -41
  39. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/profinet/device.py +2 -3
  40. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/sim/engine.py +255 -62
  41. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/equivalence/harness.py +1 -1
  42. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/equivalence/scenarios.py +104 -1
  43. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/equivalence/test_equivalence.py +1 -1
  44. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_benchmarks.py +39 -0
  45. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_buffers.py +10 -8
  46. smolpy-1.12.1.dev2/tests/test_ingress.py +690 -0
  47. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_ns3.py +2 -2
  48. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_outstanding.py +2 -2
  49. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_validate.py +6 -2
  50. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/uv.lock +8 -8
  51. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/.github/workflows/ci.yml +0 -0
  52. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/.github/workflows/dev-build.yml +0 -0
  53. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/.github/workflows/docker-image.yml +0 -0
  54. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/.github/workflows/docs.yml +0 -0
  55. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/.github/workflows/github-release.yml +0 -0
  56. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/.github/workflows/ns3-base.yml +0 -0
  57. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/.github/workflows/publish.yml +0 -0
  58. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/.github/workflows/release.yml +0 -0
  59. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/.github/workflows/rust-wheels.yml +0 -0
  60. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/.gitignore +0 -0
  61. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/LICENSE +0 -0
  62. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/__init__.py +0 -0
  63. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/closed_loop.py +0 -0
  64. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/load.py +0 -0
  65. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/loss.py +0 -0
  66. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/results/2026-11-13-0921-simpy-jaws-zbook-baseline.json +0 -0
  67. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/results/2026-11-13-1527-simpy-jaws-zbook-optimised.json +0 -0
  68. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/results/2026-11-13-2116-simpy-jaws-zbook-research-batch.json +0 -0
  69. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/results/2026-11-13-2119-simpy-jaws-zbook-research-b4.json +0 -0
  70. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/results/2026-11-15-1255-rust-jaws-zbook-stop-criterion.json +0 -0
  71. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/results/2026-11-15-1333-rust-jaws-zbook-research-b4.json +0 -0
  72. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/results/2026-11-15-1346-rust-jaws-zbook-research-batch.json +0 -0
  73. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/results/2026-11-16-1839-simpy-ns3-jaws-zbook-tcp-under-load.json +0 -0
  74. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/results/2026-11-23-1228-simpy-rust-ns3-jaws-zbook-bounded-buffers.json +0 -0
  75. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/results/2026-11-23-2106-simpy-rust-ns3-jaws-zbook-one-request-in-flight.json +0 -0
  76. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/runner.py +0 -0
  77. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/scenarios.py +0 -0
  78. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/benchmarks/worker.py +0 -0
  79. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docker/Dockerfile +0 -0
  80. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docker/Dockerfile.dockerignore +0 -0
  81. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docker/Dockerfile.ns3 +0 -0
  82. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docker/Dockerfile.ns3.dockerignore +0 -0
  83. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docker/ns3-base/Dockerfile +0 -0
  84. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docker/ns3-base/smoke.cc +0 -0
  85. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docker/smoke.smol +0 -0
  86. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0001-protocol-package-structure.md +0 -0
  87. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0002-modbus-tcp-implementation.md +0 -0
  88. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0003-smol-external-dsl.md +0 -0
  89. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0005-profinet-rt.md +0 -0
  90. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0006-profiling-and-baseline-benchmark.md +0 -0
  91. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0007-execution-independent-scenario-model.md +0 -0
  92. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0008-rust-des-engine-mvp.md +0 -0
  93. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0009-batch-execution-and-cross-backend-validation.md +0 -0
  94. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0010-ethernet-frames-on-the-wire.md +0 -0
  95. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/adr/0012-modbus-one-request-in-flight.md +0 -0
  96. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/dashboard.md +0 -0
  97. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/index.md +0 -0
  98. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/mqtt.md +0 -0
  99. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/profinet.md +0 -0
  100. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/docs/simulation-engine.md +0 -0
  101. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example.py +0 -0
  102. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example.smol +0 -0
  103. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_10_clients.py +0 -0
  104. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_12_clients.py +0 -0
  105. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_20_clients.py +0 -0
  106. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_bounded_buffer.smol +0 -0
  107. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_file_transfer.py +0 -0
  108. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_modbus.py +0 -0
  109. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_modbus_timeout.smol +0 -0
  110. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_mqtt.py +0 -0
  111. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_profinet.py +0 -0
  112. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_profinet.smol +0 -0
  113. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_staggered_transfer.py +0 -0
  114. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/examples/example_two_tier.py +0 -0
  115. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/Cargo.lock +0 -0
  116. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/Cargo.toml +0 -0
  117. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smol-engine/Cargo.toml +0 -0
  118. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smol-engine/src/frames.rs +0 -0
  119. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smol-engine/src/lib.rs +0 -0
  120. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smol-engine/src/rng.rs +0 -0
  121. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smol-engine/src/timebase.rs +0 -0
  122. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smolpy-engine-rs/Cargo.toml +0 -0
  123. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smolpy-engine-rs/pyproject.toml +0 -0
  124. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smolpy-engine-rs/smoke_test.py +0 -0
  125. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/rust/smolpy-engine-rs/src/lib.rs +0 -0
  126. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/_worker.py +0 -0
  127. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/batch.py +0 -0
  128. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/cli.py +0 -0
  129. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/core/__init__.py +0 -0
  130. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/core/batch.py +0 -0
  131. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/core/link.py +0 -0
  132. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/core/node.py +0 -0
  133. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/core/observation.py +0 -0
  134. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/ethernet/__init__.py +0 -0
  135. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/lang/__init__.py +0 -0
  136. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/lang/errors.py +0 -0
  137. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/lang/grammar.lark +0 -0
  138. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/modbus/__init__.py +0 -0
  139. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/model/__init__.py +0 -0
  140. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/model/frames.py +0 -0
  141. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/model/streams.py +0 -0
  142. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/model/timebase.py +0 -0
  143. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/mqtt/__init__.py +0 -0
  144. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/profinet/__init__.py +0 -0
  145. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/sim/__init__.py +0 -0
  146. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/stats.py +0 -0
  147. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/viz/__init__.py +0 -0
  148. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/viz/dashboard.py +0 -0
  149. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/src/smolpy/viz/text_dashboard.py +0 -0
  150. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/__init__.py +0 -0
  151. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/equivalence/__init__.py +0 -0
  152. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/equivalence/test_rust_timebase.py +0 -0
  153. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_backends.py +0 -0
  154. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_batch.py +0 -0
  155. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_cli.py +0 -0
  156. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_dsl.py +0 -0
  157. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_engine_ir.py +0 -0
  158. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_lang.py +0 -0
  159. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_model.py +0 -0
  160. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_profinet.py +0 -0
  161. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_semantics.py +0 -0
  162. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_simulation.py +0 -0
  163. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_stats.py +0 -0
  164. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_sweep.py +0 -0
  165. {smolpy-1.12.0 → smolpy-1.12.1.dev2}/tests/test_timebase.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: smolpy
3
- Version: 1.12.0
3
+ Version: 1.12.1.dev2
4
4
  Summary: Network simulation DSL and discrete-event simulator
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -23,7 +23,7 @@ Requires-Dist: ruff; extra == 'dev'
23
23
  Provides-Extra: docs
24
24
  Requires-Dist: mkdocs-material>=9; extra == 'docs'
25
25
  Provides-Extra: rust
26
- Requires-Dist: smolpy-engine-rs>=1.11.1.dev0; extra == 'rust'
26
+ Requires-Dist: smolpy-engine-rs>=1.12.0; extra == 'rust'
27
27
  Description-Content-Type: text/markdown
28
28
 
29
29
  # SMOLPy
@@ -64,7 +64,7 @@ SMOLPy lets you describe a network topology in pure Python, define traffic flows
64
64
  | **Modbus TCP** | TCP/IP | Request / response polling (Read Holding Registers, FC 03) | `ModbusSlave`, `Adapter.polls()` | `modbus_slave`, `poll` | `modbus_latency`, `modbus_unanswered`, `modbus_timeouts`, `modbus_skipped` |
65
65
  | **PROFINET RT** | Layer 2 (EtherType 0x8892), 802.1Q priority 6 | Cyclic producer / consumer exchange with watchdog | `ProfinetDevice`, `Adapter.controls()` | `profinet_device`, `control` | `pn_latency`, `pn_jitter`, `pn_watchdog_expiries` |
66
66
 
67
- Infrastructure: MAC-learning **switches** with 802.1Q strict-priority egress queues (`qos="strict"`, or `qos="fifo"` to disable prioritisation), unbounded or bounded with tail drop (`buffer=` in bytes). One `Adapter` can act in several roles at once — e.g. a PLC that is a Modbus master, an MQTT publisher and a PROFINET controller.
67
+ Infrastructure: MAC-learning **switches** with 802.1Q strict-priority egress queues (`qos="strict"`, or `qos="fifo"` to disable prioritisation), unbounded or bounded with tail drop per egress or ingress port (`buffer=`, `ingress_buffer=`, in bytes or `Frames(n)`). Every end station can send flows, so a Modbus server can also stream data on its one port. One `Adapter` can act in several roles at once — e.g. a PLC that is a Modbus master, an MQTT publisher and a PROFINET controller.
68
68
 
69
69
  **Not supported (yet):** PROFINET IRT, PROFIBUS, EtherNet/IP, EtherCAT, OPC UA, Modbus RTU (serial), and Modbus write function codes. See the [Architecture Decision Records](https://jwszolek.github.io/SMOLPy/adr/0001-protocol-package-structure/) for what is planned.
70
70
 
@@ -233,6 +233,9 @@ sensor.publishes(to=broker, topic="plant/temp", rate=1.0, payload=20, qos=0, del
233
233
  # Broker topic routing — must be called before simulate()
234
234
  broker.routes("plant/temp", to=[server])
235
235
 
236
+ # Any end station sends flows: a Modbus server that also streams data
237
+ pi.sends(to=laptop, rate=8_100, size=1_518, pattern="poisson")
238
+
236
239
  # Modbus TCP poll (master → slave, Read Holding Registers)
237
240
  plc.polls(slave, register=40001, count=10, rate=1.0)
238
241
  plc.polls(slave, register=30001, count=5, rate=2.0, delay_ms=500)
@@ -313,22 +316,24 @@ net.observe(metric, on=node, every=interval_ms)
313
316
  |---|---|---|
314
317
  | `throughput` | Mb/s | Adapter |
315
318
  | `latency` | µs | Adapter |
316
- | `bytes_sent` | MB | Adapter (sender) |
319
+ | `bytes_sent` | MB | any end station (sender) |
317
320
  | `bytes_received` | MB | Adapter (receiver) |
318
321
  | `queue_depth` | frames | Switch |
319
322
  | `utilization` | % | Any node |
320
323
  | `broker_queue` | msgs | MQTTBroker |
321
- | `modbus_latency` | µs | Adapter (master) |
324
+ | `modbus_latency` | µs | Adapter (master), ModbusSlave (its polls) |
322
325
  | `pn_latency` | µs | Adapter (controller), ProfinetDevice |
323
326
  | `pn_jitter` | µs | Adapter (controller), ProfinetDevice |
324
327
  | `pn_watchdog_expiries` | count | Adapter (controller), ProfinetDevice |
325
- | `drops` | frames | Switch: dropped by its buffers in the window |
328
+ | `drops` | frames | Switch: dropped by its buffers in the window, ingress and egress |
326
329
  | `drops_total` | frames | Switch: dropped by its buffers so far |
327
- | `frames_sent` | frames | Adapter (sender) |
330
+ | `frames_sent` | frames | any end station (sender) |
328
331
  | `frames_received` | frames | Adapter (receiver) |
329
- | `modbus_unanswered` | polls | Adapter (master): polls without a response so far, lost or in flight |
330
- | `modbus_timeouts` | polls | Adapter (master): requests that timed out so far, with `outstanding=1` |
331
- | `modbus_skipped` | polls | Adapter (master): poll instants skipped so far, because a request was outstanding |
332
+ | `modbus_unanswered` | polls | Adapter (master), ModbusSlave (its polls): polls without a response so far, lost or in flight |
333
+ | `modbus_timeouts` | polls | Adapter (master), ModbusSlave (its polls): requests that timed out so far, with `outstanding=1` |
334
+ | `modbus_skipped` | polls | Adapter (master), ModbusSlave (its polls): poll instants skipped so far, because a request was outstanding |
335
+ | `ingress_drops_total` | frames | Switch: dropped by its ingress accounts so far |
336
+ | `egress_drops_total` | frames | Switch: dropped by its egress accounts so far |
332
337
 
333
338
  ### Simulation
334
339
 
@@ -523,7 +528,7 @@ The model every engine implements:
523
528
  - **MAC-learning switch** — each switch pre-seeds its forwarding table from the topology wiring, eliminating spurious flooding toward silent endpoints (e.g. a server that only receives). Dynamic learning still operates for traffic through intermediate switches.
524
529
  - **Store-and-forward model** — transmission delay + propagation delay per hop.
525
530
  - **Queuing** — each link direction has its own egress queue with 8 strict 802.1Q priority classes (FIFO within a class, non-preemptive); `qos="fifo"` on a switch ignores priorities. `queue_depth` reports buffered frames at the switch's outbound ports.
526
- - **Bounded buffers** — a switch with `buffer` (bytes per port) drops a frame that does not fit, with tail drop: delay is capped and loss appears, as on real switches near saturation ([ADR-0011](https://jwszolek.github.io/SMOLPy/adr/0011-bounded-switch-buffers/)). Without it queues are unbounded.
531
+ - **Bounded buffers** — a switch with `buffer` (per egress port) or `ingress_buffer` (per ingress port), in bytes or in frames, drops a frame that does not fit, with tail drop: delay is capped and loss appears, as on real switches near saturation ([ADR-0011](https://jwszolek.github.io/SMOLPy/adr/0011-bounded-switch-buffers/), [ADR-0013](https://jwszolek.github.io/SMOLPy/adr/0013-ingress-buffer-accounting/)). Without them queues are unbounded.
527
532
  - **Traffic shaping** — constant, Poisson, Pareto-burst and batch patterns; IMIX frame-size distribution.
528
533
  - **Live mode** (SimPy only) — simulation runs in 200 chunks (~8 s total wall time); the dashboard reads shared metric arrays between chunks via Python's GIL.
529
534
 
@@ -560,7 +565,7 @@ Below saturation the engines agree. At saturation, TCP's own acknowledgements ti
560
565
 
561
566
  ## Examples
562
567
 
563
- See [`examples/README.md`](examples/README.md) for twelve ready-to-run scenarios covering single-switch saturation, oversubscription, two-tier access bottlenecks, MQTT publish-subscribe, Modbus TCP polling, PROFINET RT cyclic I/O, a bounded switch buffer, and a Modbus master that waits for each response.
568
+ See [`examples/README.md`](examples/README.md) for thirteen ready-to-run scenarios covering single-switch saturation, oversubscription, two-tier access bottlenecks, MQTT publish-subscribe, Modbus TCP polling, PROFINET RT cyclic I/O, a bounded switch buffer, a Modbus master that waits for each response, and ingress buffer accounting.
564
569
 
565
570
  ```bash
566
571
  uv run smolpy run examples/example.py
@@ -36,7 +36,7 @@ SMOLPy lets you describe a network topology in pure Python, define traffic flows
36
36
  | **Modbus TCP** | TCP/IP | Request / response polling (Read Holding Registers, FC 03) | `ModbusSlave`, `Adapter.polls()` | `modbus_slave`, `poll` | `modbus_latency`, `modbus_unanswered`, `modbus_timeouts`, `modbus_skipped` |
37
37
  | **PROFINET RT** | Layer 2 (EtherType 0x8892), 802.1Q priority 6 | Cyclic producer / consumer exchange with watchdog | `ProfinetDevice`, `Adapter.controls()` | `profinet_device`, `control` | `pn_latency`, `pn_jitter`, `pn_watchdog_expiries` |
38
38
 
39
- Infrastructure: MAC-learning **switches** with 802.1Q strict-priority egress queues (`qos="strict"`, or `qos="fifo"` to disable prioritisation), unbounded or bounded with tail drop (`buffer=` in bytes). One `Adapter` can act in several roles at once — e.g. a PLC that is a Modbus master, an MQTT publisher and a PROFINET controller.
39
+ Infrastructure: MAC-learning **switches** with 802.1Q strict-priority egress queues (`qos="strict"`, or `qos="fifo"` to disable prioritisation), unbounded or bounded with tail drop per egress or ingress port (`buffer=`, `ingress_buffer=`, in bytes or `Frames(n)`). Every end station can send flows, so a Modbus server can also stream data on its one port. One `Adapter` can act in several roles at once — e.g. a PLC that is a Modbus master, an MQTT publisher and a PROFINET controller.
40
40
 
41
41
  **Not supported (yet):** PROFINET IRT, PROFIBUS, EtherNet/IP, EtherCAT, OPC UA, Modbus RTU (serial), and Modbus write function codes. See the [Architecture Decision Records](https://jwszolek.github.io/SMOLPy/adr/0001-protocol-package-structure/) for what is planned.
42
42
 
@@ -205,6 +205,9 @@ sensor.publishes(to=broker, topic="plant/temp", rate=1.0, payload=20, qos=0, del
205
205
  # Broker topic routing — must be called before simulate()
206
206
  broker.routes("plant/temp", to=[server])
207
207
 
208
+ # Any end station sends flows: a Modbus server that also streams data
209
+ pi.sends(to=laptop, rate=8_100, size=1_518, pattern="poisson")
210
+
208
211
  # Modbus TCP poll (master → slave, Read Holding Registers)
209
212
  plc.polls(slave, register=40001, count=10, rate=1.0)
210
213
  plc.polls(slave, register=30001, count=5, rate=2.0, delay_ms=500)
@@ -285,22 +288,24 @@ net.observe(metric, on=node, every=interval_ms)
285
288
  |---|---|---|
286
289
  | `throughput` | Mb/s | Adapter |
287
290
  | `latency` | µs | Adapter |
288
- | `bytes_sent` | MB | Adapter (sender) |
291
+ | `bytes_sent` | MB | any end station (sender) |
289
292
  | `bytes_received` | MB | Adapter (receiver) |
290
293
  | `queue_depth` | frames | Switch |
291
294
  | `utilization` | % | Any node |
292
295
  | `broker_queue` | msgs | MQTTBroker |
293
- | `modbus_latency` | µs | Adapter (master) |
296
+ | `modbus_latency` | µs | Adapter (master), ModbusSlave (its polls) |
294
297
  | `pn_latency` | µs | Adapter (controller), ProfinetDevice |
295
298
  | `pn_jitter` | µs | Adapter (controller), ProfinetDevice |
296
299
  | `pn_watchdog_expiries` | count | Adapter (controller), ProfinetDevice |
297
- | `drops` | frames | Switch: dropped by its buffers in the window |
300
+ | `drops` | frames | Switch: dropped by its buffers in the window, ingress and egress |
298
301
  | `drops_total` | frames | Switch: dropped by its buffers so far |
299
- | `frames_sent` | frames | Adapter (sender) |
302
+ | `frames_sent` | frames | any end station (sender) |
300
303
  | `frames_received` | frames | Adapter (receiver) |
301
- | `modbus_unanswered` | polls | Adapter (master): polls without a response so far, lost or in flight |
302
- | `modbus_timeouts` | polls | Adapter (master): requests that timed out so far, with `outstanding=1` |
303
- | `modbus_skipped` | polls | Adapter (master): poll instants skipped so far, because a request was outstanding |
304
+ | `modbus_unanswered` | polls | Adapter (master), ModbusSlave (its polls): polls without a response so far, lost or in flight |
305
+ | `modbus_timeouts` | polls | Adapter (master), ModbusSlave (its polls): requests that timed out so far, with `outstanding=1` |
306
+ | `modbus_skipped` | polls | Adapter (master), ModbusSlave (its polls): poll instants skipped so far, because a request was outstanding |
307
+ | `ingress_drops_total` | frames | Switch: dropped by its ingress accounts so far |
308
+ | `egress_drops_total` | frames | Switch: dropped by its egress accounts so far |
304
309
 
305
310
  ### Simulation
306
311
 
@@ -495,7 +500,7 @@ The model every engine implements:
495
500
  - **MAC-learning switch** — each switch pre-seeds its forwarding table from the topology wiring, eliminating spurious flooding toward silent endpoints (e.g. a server that only receives). Dynamic learning still operates for traffic through intermediate switches.
496
501
  - **Store-and-forward model** — transmission delay + propagation delay per hop.
497
502
  - **Queuing** — each link direction has its own egress queue with 8 strict 802.1Q priority classes (FIFO within a class, non-preemptive); `qos="fifo"` on a switch ignores priorities. `queue_depth` reports buffered frames at the switch's outbound ports.
498
- - **Bounded buffers** — a switch with `buffer` (bytes per port) drops a frame that does not fit, with tail drop: delay is capped and loss appears, as on real switches near saturation ([ADR-0011](https://jwszolek.github.io/SMOLPy/adr/0011-bounded-switch-buffers/)). Without it queues are unbounded.
503
+ - **Bounded buffers** — a switch with `buffer` (per egress port) or `ingress_buffer` (per ingress port), in bytes or in frames, drops a frame that does not fit, with tail drop: delay is capped and loss appears, as on real switches near saturation ([ADR-0011](https://jwszolek.github.io/SMOLPy/adr/0011-bounded-switch-buffers/), [ADR-0013](https://jwszolek.github.io/SMOLPy/adr/0013-ingress-buffer-accounting/)). Without them queues are unbounded.
499
504
  - **Traffic shaping** — constant, Poisson, Pareto-burst and batch patterns; IMIX frame-size distribution.
500
505
  - **Live mode** (SimPy only) — simulation runs in 200 chunks (~8 s total wall time); the dashboard reads shared metric arrays between chunks via Python's GIL.
501
506
 
@@ -532,7 +537,7 @@ Below saturation the engines agree. At saturation, TCP's own acknowledgements ti
532
537
 
533
538
  ## Examples
534
539
 
535
- See [`examples/README.md`](examples/README.md) for twelve ready-to-run scenarios covering single-switch saturation, oversubscription, two-tier access bottlenecks, MQTT publish-subscribe, Modbus TCP polling, PROFINET RT cyclic I/O, a bounded switch buffer, and a Modbus master that waits for each response.
540
+ See [`examples/README.md`](examples/README.md) for thirteen ready-to-run scenarios covering single-switch saturation, oversubscription, two-tier access bottlenecks, MQTT publish-subscribe, Modbus TCP polling, PROFINET RT cyclic I/O, a bounded switch buffer, a Modbus master that waits for each response, and ingress buffer accounting.
536
541
 
537
542
  ```bash
538
543
  uv run smolpy run examples/example.py
@@ -11,6 +11,8 @@ python -m benchmarks loss [--loads 0.93 0.996] [--duration 30000] [--backend sim
11
11
  python -m benchmarks loss-summary benchmarks/results/<file>.json
12
12
  python -m benchmarks closed-loop [--loads 0.99] [--duration 30000] [--backend simpy rust ns3]
13
13
  python -m benchmarks closed-loop-summary benchmarks/results/<file>.json
14
+ python -m benchmarks ingress [--loads 0.997] [--duration 30000] [--backend simpy rust ns3]
15
+ python -m benchmarks ingress-summary benchmarks/results/<file>.json
14
16
  """
15
17
 
16
18
  from __future__ import annotations
@@ -22,7 +24,7 @@ import subprocess
22
24
  import sys
23
25
  from pathlib import Path
24
26
 
25
- from benchmarks import closed_loop, loss
27
+ from benchmarks import closed_loop, ingress, loss
26
28
  from benchmarks.load import DURATION_MS, LOADS, run_load, summarize_load
27
29
  from benchmarks.runner import parse_size, run_batch, run_suite, size_label, summarize
28
30
 
@@ -121,6 +123,19 @@ def main() -> None:
121
123
  )
122
124
  closed_summ.add_argument("file", type=Path)
123
125
 
126
+ ing = sub.add_parser(
127
+ "ingress", help="the testbed of ADR-0013, ingress accounts in frames, every engine"
128
+ )
129
+ ing.add_argument("--loads", nargs="+", type=float, default=list(ingress.LOADS))
130
+ ing.add_argument("--duration", type=float, default=ingress.DURATION_MS, help="simulated ms")
131
+ ing.add_argument("--backend", nargs="+", default=list(ingress.ENGINES))
132
+ ing.add_argument("--model", nargs="+", default=list(ingress.MODELS), choices=ingress.MODELS)
133
+ ing.add_argument("--label", default="ingress-buffers")
134
+ ing.add_argument("--out", type=Path, default=None)
135
+
136
+ ing_summ = sub.add_parser("ingress-summary", help="markdown table of an ingress results file")
137
+ ing_summ.add_argument("file", type=Path)
138
+
124
139
  a = p.parse_args()
125
140
  if a.cmd == "run":
126
141
  sizes = [parse_size(s) for s in a.frames]
@@ -149,6 +164,14 @@ def main() -> None:
149
164
  print(closed_loop.summarize_closed_loop(out))
150
165
  elif a.cmd == "closed-loop-summary":
151
166
  print(closed_loop.summarize_closed_loop(a.file))
167
+ elif a.cmd == "ingress":
168
+ out = ingress.run_ingress(
169
+ a.loads, a.duration, a.backend, a.label, a.out, models=tuple(a.model)
170
+ )
171
+ print(f"results written to {out}")
172
+ print(ingress.summarize_ingress(out))
173
+ elif a.cmd == "ingress-summary":
174
+ print(ingress.summarize_ingress(a.file))
152
175
  elif a.cmd == "batch":
153
176
  frames = parse_size(a.frames)
154
177
  r = run_batch(a.scenario, frames, a.metrics, a.runs, a.jobs, a.timeout, a.seed, a.backend)
@@ -0,0 +1,239 @@
1
+ """Ingress accounts and limits in frames on the three engines: the testbed of
2
+ ADR-0013.
3
+
4
+ Scenario T3 is the testbed as it was measured more widely: a TP-Link
5
+ LS108GP, with
6
+ - a Raspberry Pi on a 1 Gb/s port, one station that sends Poisson UDP of
7
+ 1 518 B frames to the laptop and serves the laptop's Modbus polls every
8
+ 10 ms, on its one port (a Modbus slave with a flow, ADR-0013);
9
+ - a Waveshare Modbus TCP relay module on another 1 Gb/s port, polled every
10
+ 20 ms; its responses are small, as the Pi's;
11
+ - the laptop on a 100 Mb/s port, polling both with one request in flight
12
+ and a timeout of 1 s (ADR-0012).
13
+
14
+ rho is the UDP stream's wire bits as a share of the laptop's 100 Mb/s. Two
15
+ models of the switch:
16
+ - ``ingress``: 60 frames per ingress port, whatever their size, and no
17
+ egress limit: what the testbed's losses point to;
18
+ - ``egress``: 91 080 B per egress port (60 frames of 1 518 B), the model of
19
+ ADR-0011 and ADR-0012, for comparison.
20
+
21
+ At 8 100 frames/s (rho = 0.997) the testbed retransmitted 0.44 % of the Pi's
22
+ polls and none of the Waveshare's, and lost 0.66 % of the UDP frames.
23
+
24
+ The record keeps, per run and per server:
25
+ - the polls sent, and the instants skipped while a request was outstanding;
26
+ - every long round trip, over ``LONG_MS``: a response TCP retransmitted, on
27
+ ns-3; timeouts and polls unanswered at the end, on SimPy and Rust;
28
+ - the polls affected, as a share of the polls sent;
29
+ - the round trip's median and p99 of its means over 1 ms windows;
30
+
31
+ and the share of the Pi's frames the switch dropped, ``drops_total /
32
+ frames_sent:pi``. The Pi's responses are 1.2 % of its frames, and the
33
+ Waveshare's 0.6 % of the frames through the switch, so that is its UDP
34
+ loss to within about 1 % of its value.
35
+
36
+ python -m benchmarks ingress [--loads 0.997] [--duration 30000]
37
+ """
38
+
39
+ from __future__ import annotations
40
+
41
+ import datetime as dt
42
+ import json
43
+ import math
44
+ import statistics
45
+ from pathlib import Path
46
+
47
+ from benchmarks.runner import RESULTS_DIR, environment
48
+ from smolpy import Frames, Network, backends
49
+ from smolpy.model import Scenario
50
+ from smolpy.model import timebase as tb
51
+ from smolpy.model.frames import WIRE_OVERHEAD_BYTES
52
+
53
+ LAPTOP_MBPS = 100
54
+ FRAME = 1_518
55
+ INGRESS = Frames(60)
56
+ EGRESS = 60 * FRAME # 91 080 B: the model of ADR-0011 and ADR-0012
57
+ MODELS = ("ingress", "egress")
58
+ SERVERS = {"pi": (100, 10), "waveshare": (50, 1)} # polls/s, registers
59
+ TIMEOUT_MS = 1_000.0
60
+ LOADS = (0.96, 0.984, 0.997)
61
+ DURATION_MS = 30_000
62
+ ENGINES = ("simpy", "rust", "ns3")
63
+ SEEDS = (1, 2, 3, 4, 5)
64
+ LONG_MS = 100.0 # a round trip far over any queueing delay
65
+ # the testbed, at 8 100 frames/s (rho = 0.997) for 310 s
66
+ MEASURED = {
67
+ "pi": "133 of 30 000 polls retransmitted (0.44 %)",
68
+ "waveshare": "0 of 15 000 polls",
69
+ "udp_loss": "0.66 %",
70
+ }
71
+
72
+
73
+ def udp_rate(rho: float) -> float:
74
+ """The Pi's UDP frames per second at *rho* of the laptop's port."""
75
+ return rho * LAPTOP_MBPS * 1e6 / ((FRAME + WIRE_OVERHEAD_BYTES) * 8)
76
+
77
+
78
+ def scenario(
79
+ rho: float, switch: str = "ingress", duration_ms: float = DURATION_MS, seed: int = SEEDS[0]
80
+ ) -> Scenario:
81
+ """T3 with the UDP stream at *rho* and the *switch* model."""
82
+ net = Network("T3")
83
+ limits = {"ingress_buffer": INGRESS} if switch == "ingress" else {"buffer": EGRESS}
84
+ sw = net.switch("sw", ports=3, **limits)
85
+ pi = net.modbus_slave("pi", ip="10.0.0.1", unit_id=1)
86
+ waveshare = net.modbus_slave("waveshare", ip="10.0.0.3", unit_id=1)
87
+ laptop = net.adapter("laptop", ip="10.0.0.2")
88
+ net.link(pi, sw, speed=1_000, length=2)
89
+ net.link(waveshare, sw, speed=1_000, length=2)
90
+ net.link(laptop, sw, speed=LAPTOP_MBPS, length=2)
91
+ pi.sends(laptop, rate=udp_rate(rho), size=FRAME, pattern="poisson")
92
+ for server, (rate, count) in SERVERS.items():
93
+ node = pi if server == "pi" else waveshare
94
+ laptop.polls(node, register=0, count=count, rate=rate, outstanding=1, timeout_ms=TIMEOUT_MS)
95
+ end = duration_ms - 1 # the last sample, at the end of the run
96
+ for node in (pi, waveshare):
97
+ net.observe("modbus_latency", on=node, every=1)
98
+ for metric in ("modbus_timeouts", "modbus_unanswered", "modbus_skipped"):
99
+ net.observe(metric, on=node, every=end)
100
+ net.observe("frames_sent", on=pi, every=end)
101
+ for metric in ("drops_total", "ingress_drops_total", "egress_drops_total"):
102
+ net.observe(metric, on=sw, every=end)
103
+ return net.to_scenario(duration=duration_ms, seed=seed)
104
+
105
+
106
+ def _instants(until_ms: float, rate: float) -> int:
107
+ """The poll instants up to *until_ms*, which falls on none."""
108
+ end = tb.ms_to_ns(until_ms)
109
+ n = 0
110
+ for t in tb.instants(0, tb.interval_ns(rate)):
111
+ if t > end:
112
+ return n
113
+ n += 1
114
+ raise AssertionError("unreachable")
115
+
116
+
117
+ def _summary(metrics: dict[str, list[tuple[float, float]]]) -> dict[str, object]:
118
+ last = {k: (s[-1][1] if s else math.nan) for k, s in metrics.items()}
119
+ out: dict[str, object] = {}
120
+ for server, (rate, _) in SERVERS.items():
121
+ rtt = [v / 1_000 for _, v in metrics[f"modbus_latency:{server}"]] # ms
122
+ long = sorted(r for r in rtt if r > LONG_MS)
123
+ at, skipped = metrics[f"modbus_skipped:{server}"][-1]
124
+ sent = _instants(at, rate) - skipped
125
+ unanswered = last[f"modbus_unanswered:{server}"]
126
+ affected = len(long) + unanswered # retransmitted, timed out or unanswered
127
+ q = statistics.quantiles(rtt, n=100) if len(rtt) > 1 else [math.nan] * 99
128
+ out[server] = {
129
+ "sent": sent,
130
+ "skipped": skipped,
131
+ "long_rtts_ms": long,
132
+ "timeouts": last[f"modbus_timeouts:{server}"],
133
+ "unanswered": unanswered,
134
+ "affected": affected / sent if sent else math.nan,
135
+ "rtt_median_ms": q[49],
136
+ "rtt_p99_ms": q[98],
137
+ }
138
+ out["dropped"] = last["drops_total:sw"] / last["frames_sent:pi"]
139
+ out["ingress_drops"] = last["ingress_drops_total:sw"]
140
+ out["egress_drops"] = last["egress_drops_total:sw"]
141
+ return out
142
+
143
+
144
+ def run_ingress(
145
+ loads: list[float],
146
+ duration_ms: float,
147
+ engines: list[str],
148
+ label: str = "ingress-buffers",
149
+ out: Path | None = None,
150
+ seeds: tuple[int, ...] = SEEDS,
151
+ models: tuple[str, ...] = MODELS,
152
+ ) -> Path:
153
+ env = environment()
154
+ stamp = dt.datetime.now().strftime("%Y-%m-%d-%H%M")
155
+ out = out or RESULTS_DIR / f"{stamp}-{'-'.join(engines)}-{env['host']}-{label}.json"
156
+ out.parent.mkdir(parents=True, exist_ok=True)
157
+ doc: dict[str, object] = {
158
+ "format": "smolpy-ingress",
159
+ "version": 1,
160
+ "label": label,
161
+ "created": dt.datetime.now().isoformat(timespec="seconds"),
162
+ "environment": env,
163
+ "scenario": "T3",
164
+ "models": {"ingress": str(INGRESS), "egress": f"{EGRESS} B"},
165
+ "duration_ms": duration_ms,
166
+ "seeds": list(seeds),
167
+ "measured": MEASURED,
168
+ "runs": [],
169
+ }
170
+ runs: list[dict[str, object]] = []
171
+ doc["runs"] = runs
172
+ for model in models:
173
+ for rho in loads:
174
+ for seed in seeds:
175
+ sc = scenario(rho, model, duration_ms, seed)
176
+ for engine in engines:
177
+ result = backends.get(engine).run(sc)
178
+ s = _summary(result.metrics)
179
+ runs.append(
180
+ {
181
+ "model": model,
182
+ "rho": rho,
183
+ "seed": seed,
184
+ "backend": engine,
185
+ "events": result.stats.events,
186
+ "wall_s": result.stats.wall_s,
187
+ "summary": s,
188
+ }
189
+ )
190
+ out.write_text(json.dumps(doc, indent=1)) # keep partial progress
191
+ pi, ws = s["pi"], s["waveshare"]
192
+ assert isinstance(pi, dict) and isinstance(ws, dict)
193
+ print(
194
+ f"{model:7s} rho {rho:5.3f} seed {seed} {engine:6s}"
195
+ f" pi {pi['affected']:.2%} waveshare {ws['affected']:.2%}"
196
+ f" dropped {s['dropped']:.3%} ({runs[-1]['wall_s']:.1f} s)",
197
+ flush=True,
198
+ )
199
+ return out
200
+
201
+
202
+ def summarize_ingress(path: Path) -> str:
203
+ """A markdown table: each model, load and engine over the seeds."""
204
+ doc = json.loads(path.read_text())
205
+ groups: dict[tuple[str, float, str], list[dict]] = {}
206
+ for r in doc["runs"]:
207
+ groups.setdefault((r["model"], r["rho"], r["backend"]), []).append(r["summary"])
208
+ m = doc["measured"]
209
+ lines = [
210
+ f"T3, {doc['duration_ms'] / 1000:g} s per run, seeds {doc['seeds']}: sums or means over"
211
+ f" the seeds. Models: ingress {doc['models']['ingress']}, egress"
212
+ f" {doc['models']['egress']}. The testbed at rho = 0.997: Pi {m['pi']}, Waveshare"
213
+ f" {m['waveshare']}, UDP loss {m['udp_loss']}.",
214
+ "",
215
+ "| model | rho | engine | Pi: polls affected | Pi: long RTTs (ms): n, min, median, max"
216
+ " | Waveshare: polls affected | RTT median, p99 (ms), Pi | Pi's frames dropped |",
217
+ "|---|---|---|---|---|---|---|---|",
218
+ ]
219
+
220
+ def affected(runs: list[dict], server: str) -> str:
221
+ sent = sum(s[server]["sent"] for s in runs)
222
+ n = sum(s[server]["affected"] * s[server]["sent"] for s in runs)
223
+ return f"{n / sent:.2%} ({n:.0f} of {sent:.0f})"
224
+
225
+ for (model, rho, engine), runs in groups.items():
226
+ long = sorted(r for s in runs for r in s["pi"]["long_rtts_ms"])
227
+ spread = (
228
+ f"{len(long)}, {long[0]:.1f}, {statistics.median(long):.1f}, {long[-1]:.1f}"
229
+ if long
230
+ else "0"
231
+ )
232
+ lines.append(
233
+ f"| {model} | {rho:.3f} | {engine} | {affected(runs, 'pi')} | {spread}"
234
+ f" | {affected(runs, 'waveshare')}"
235
+ f" | {statistics.fmean(s['pi']['rtt_median_ms'] for s in runs):.2f},"
236
+ f" {statistics.fmean(s['pi']['rtt_p99_ms'] for s in runs):.2f}"
237
+ f" | {statistics.fmean(s['dropped'] for s in runs):.3%} |"
238
+ )
239
+ return "\n".join(lines)