smolpy 1.9.1.dev6__tar.gz → 1.9.1.dev10__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 (146) hide show
  1. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/PKG-INFO +2 -2
  2. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/README.md +1 -1
  3. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/adr/0004-execution-backends.md +67 -6
  4. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/adr/0009-batch-execution-and-cross-backend-validation.md +1 -1
  5. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/dsl-reference.md +1 -1
  6. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/roadmap.md +9 -2
  7. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/backends.py +10 -17
  8. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/model/frames.py +21 -8
  9. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/ns3/__init__.py +76 -11
  10. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/ns3/cpp/smol-ns3.cc +576 -15
  11. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/equivalence/harness.py +27 -0
  12. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/equivalence/test_equivalence.py +29 -2
  13. smolpy-1.9.1.dev10/tests/test_ns3.py +353 -0
  14. smolpy-1.9.1.dev6/tests/test_ns3.py +0 -173
  15. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/.github/workflows/ci.yml +0 -0
  16. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/.github/workflows/dev-build.yml +0 -0
  17. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/.github/workflows/docker-image.yml +0 -0
  18. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/.github/workflows/docs.yml +0 -0
  19. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/.github/workflows/github-release.yml +0 -0
  20. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/.github/workflows/ns3-base.yml +0 -0
  21. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/.github/workflows/publish.yml +0 -0
  22. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/.github/workflows/release.yml +0 -0
  23. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/.github/workflows/rust-wheels.yml +0 -0
  24. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/.gitignore +0 -0
  25. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/LICENSE +0 -0
  26. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/__init__.py +0 -0
  27. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/__main__.py +0 -0
  28. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-13-0921-simpy-jaws-zbook-baseline.json +0 -0
  29. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-13-1527-simpy-jaws-zbook-optimised.json +0 -0
  30. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-13-2116-simpy-jaws-zbook-research-batch.json +0 -0
  31. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-13-2119-simpy-jaws-zbook-research-b4.json +0 -0
  32. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-15-1255-rust-jaws-zbook-stop-criterion.json +0 -0
  33. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-15-1333-rust-jaws-zbook-research-b4.json +0 -0
  34. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-15-1346-rust-jaws-zbook-research-batch.json +0 -0
  35. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/runner.py +0 -0
  36. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/scenarios.py +0 -0
  37. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/benchmarks/worker.py +0 -0
  38. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docker/Dockerfile +0 -0
  39. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docker/Dockerfile.dockerignore +0 -0
  40. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docker/ns3-base/Dockerfile +0 -0
  41. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docker/ns3-base/smoke.cc +0 -0
  42. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docker/smoke.smol +0 -0
  43. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/adr/0001-protocol-package-structure.md +0 -0
  44. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/adr/0002-modbus-tcp-implementation.md +0 -0
  45. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/adr/0003-smol-external-dsl.md +0 -0
  46. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/adr/0005-profinet-rt.md +0 -0
  47. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/adr/0006-profiling-and-baseline-benchmark.md +0 -0
  48. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/adr/0007-execution-independent-scenario-model.md +0 -0
  49. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/adr/0008-rust-des-engine-mvp.md +0 -0
  50. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/adr/0010-ethernet-frames-on-the-wire.md +0 -0
  51. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/benchmarks.md +0 -0
  52. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/dashboard.md +0 -0
  53. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/examples.md +0 -0
  54. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/index.md +0 -0
  55. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/language-reference.md +0 -0
  56. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/modbus.md +0 -0
  57. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/model-semantics.md +0 -0
  58. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/mqtt.md +0 -0
  59. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/profinet.md +0 -0
  60. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/scenario-model.md +0 -0
  61. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/docs/simulation-engine.md +0 -0
  62. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/README.md +0 -0
  63. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example.py +0 -0
  64. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example.smol +0 -0
  65. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example_10_clients.py +0 -0
  66. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example_12_clients.py +0 -0
  67. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example_20_clients.py +0 -0
  68. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example_file_transfer.py +0 -0
  69. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example_modbus.py +0 -0
  70. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example_mqtt.py +0 -0
  71. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example_profinet.py +0 -0
  72. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example_profinet.smol +0 -0
  73. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example_staggered_transfer.py +0 -0
  74. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/examples/example_two_tier.py +0 -0
  75. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/mkdocs.yml +0 -0
  76. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/pyproject.toml +0 -0
  77. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/Cargo.lock +0 -0
  78. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/Cargo.toml +0 -0
  79. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smol-engine/Cargo.toml +0 -0
  80. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smol-engine/src/frames.rs +0 -0
  81. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smol-engine/src/lib.rs +0 -0
  82. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smol-engine/src/rng.rs +0 -0
  83. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smol-engine/src/scenario.rs +0 -0
  84. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smol-engine/src/sim.rs +0 -0
  85. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smol-engine/src/timebase.rs +0 -0
  86. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smolpy-engine-rs/Cargo.toml +0 -0
  87. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smolpy-engine-rs/README.md +0 -0
  88. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smolpy-engine-rs/pyproject.toml +0 -0
  89. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smolpy-engine-rs/smoke_test.py +0 -0
  90. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/rust/smolpy-engine-rs/src/lib.rs +0 -0
  91. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/__init__.py +0 -0
  92. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/_worker.py +0 -0
  93. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/batch.py +0 -0
  94. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/cli.py +0 -0
  95. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/core/__init__.py +0 -0
  96. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/core/adapter.py +0 -0
  97. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/core/batch.py +0 -0
  98. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/core/link.py +0 -0
  99. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/core/network.py +0 -0
  100. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/core/node.py +0 -0
  101. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/core/observation.py +0 -0
  102. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/ethernet/__init__.py +0 -0
  103. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/ethernet/switch.py +0 -0
  104. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/lang/__init__.py +0 -0
  105. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/lang/ast.py +0 -0
  106. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/lang/errors.py +0 -0
  107. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/lang/grammar.lark +0 -0
  108. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/lang/interpreter.py +0 -0
  109. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/lang/transformer.py +0 -0
  110. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/modbus/__init__.py +0 -0
  111. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/modbus/slave.py +0 -0
  112. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/model/__init__.py +0 -0
  113. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/model/scenario.py +0 -0
  114. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/model/streams.py +0 -0
  115. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/model/timebase.py +0 -0
  116. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/model/validate.py +0 -0
  117. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/mqtt/__init__.py +0 -0
  118. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/mqtt/broker.py +0 -0
  119. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/profinet/__init__.py +0 -0
  120. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/profinet/device.py +0 -0
  121. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/sim/__init__.py +0 -0
  122. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/sim/engine.py +0 -0
  123. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/stats.py +0 -0
  124. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/viz/__init__.py +0 -0
  125. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/viz/dashboard.py +0 -0
  126. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/src/smolpy/viz/text_dashboard.py +0 -0
  127. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/__init__.py +0 -0
  128. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/equivalence/__init__.py +0 -0
  129. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/equivalence/scenarios.py +0 -0
  130. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/equivalence/test_rust_timebase.py +0 -0
  131. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_backends.py +0 -0
  132. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_batch.py +0 -0
  133. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_benchmarks.py +0 -0
  134. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_cli.py +0 -0
  135. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_dsl.py +0 -0
  136. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_engine_ir.py +0 -0
  137. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_lang.py +0 -0
  138. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_model.py +0 -0
  139. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_profinet.py +0 -0
  140. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_semantics.py +0 -0
  141. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_simulation.py +0 -0
  142. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_stats.py +0 -0
  143. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_sweep.py +0 -0
  144. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_timebase.py +0 -0
  145. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/tests/test_validate.py +0 -0
  146. {smolpy-1.9.1.dev6 → smolpy-1.9.1.dev10}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: smolpy
3
- Version: 1.9.1.dev6
3
+ Version: 1.9.1.dev10
4
4
  Summary: Network simulation DSL and discrete-event simulator
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -482,7 +482,7 @@ Every simulation goes through the same path. The Python API and `.smol` files bu
482
482
  |---|---|---|---|---|
483
483
  | `simpy` (default) | Python, SimPy | the whole model, the live and text dashboards | reference | included |
484
484
  | `rust` | Rust, through PyO3 | the whole model, headless: Ethernet, Modbus TCP, MQTT and PROFINET RT, every metric | about **40× faster**: B1 at 10 M frames in 4.9 s, not 200.8 s | `pip install smolpy[rust]` (since v1.8.0) |
485
- | `ns3` (in progress) | ns-3's IPv4/UDP stack, from C++ | Ethernet so far: adapters, switches, every traffic pattern, IMIX, priorities; bit-exact with SimPy there | slower: each run is an ns-3 process | an ns-3 3.49 build in `NS3_HOME`, e.g. the image `ghcr.io/jwszolek/smolpy-ns3-base:3.49` |
485
+ | `ns3` | ns-3's IPv4 stack, from C++ | the whole model, headless. Ethernet over UDP and PROFINET RT on layer 2, bit-exact with SimPy. Modbus TCP and MQTT over ns-3's TCP, which adds connection setup and acknowledgements | slower: each run is an ns-3 process | an ns-3 3.49 build in `NS3_HOME`, e.g. the image `ghcr.io/jwszolek/smolpy-ns3-base:3.49` |
486
486
 
487
487
  ```python
488
488
  result = net.simulate(duration=60_000, backend="rust") # one run
@@ -454,7 +454,7 @@ Every simulation goes through the same path. The Python API and `.smol` files bu
454
454
  |---|---|---|---|---|
455
455
  | `simpy` (default) | Python, SimPy | the whole model, the live and text dashboards | reference | included |
456
456
  | `rust` | Rust, through PyO3 | the whole model, headless: Ethernet, Modbus TCP, MQTT and PROFINET RT, every metric | about **40× faster**: B1 at 10 M frames in 4.9 s, not 200.8 s | `pip install smolpy[rust]` (since v1.8.0) |
457
- | `ns3` (in progress) | ns-3's IPv4/UDP stack, from C++ | Ethernet so far: adapters, switches, every traffic pattern, IMIX, priorities; bit-exact with SimPy there | slower: each run is an ns-3 process | an ns-3 3.49 build in `NS3_HOME`, e.g. the image `ghcr.io/jwszolek/smolpy-ns3-base:3.49` |
457
+ | `ns3` | ns-3's IPv4 stack, from C++ | the whole model, headless. Ethernet over UDP and PROFINET RT on layer 2, bit-exact with SimPy. Modbus TCP and MQTT over ns-3's TCP, which adds connection setup and acknowledgements | slower: each run is an ns-3 process | an ns-3 3.49 build in `NS3_HOME`, e.g. the image `ghcr.io/jwszolek/smolpy-ns3-base:3.49` |
458
458
 
459
459
  ```python
460
460
  result = net.simulate(duration=60_000, backend="rust") # one run
@@ -117,13 +117,14 @@ smolpy backends # list backends and their capabiliti
117
117
  | SMOL | ns-3 |
118
118
  |---|---|
119
119
  | `adapter`, `mqtt_broker`, `modbus_slave` | Node with Internet stack (IPv4 address from `ip`) |
120
+ | `profinet_device`, `controls` | *Added 2026-11-16:* a node whose device sends and receives PROFINET RT frames on layer 2; see "PROFINET RT on ns-3" below |
120
121
  | `switch` (store-and-forward) | ~~Node with a learning bridge over one device per port~~ *As built:* a node with one SMOL Ethernet device per port and SMOL's switch, which learns, floods unknown destinations and drops hairpins. ns-3's `BridgeNetDevice` floods a hairpin instead of dropping it. |
121
122
  | `switch mode=cut-through` | **unsupported** — capability error |
122
123
  | `hub` | Shared CSMA channel *(hubs and `collision_rate` were later removed; see [Model Semantics](../model-semantics.md#open-issues), open issue 3)* |
123
124
  | `link speed= length=` | *Amended 2026-11-16: SMOL's own full-duplex Ethernet device and channel, not CSMA; see "Link model on ns-3" below.* Device data rate = `speed`; channel delay = `length / 2·10⁸ m/s` (same propagation constant as `core/link.py`). *Since ADR-0010:* inter-frame gap = the time of 20 B at `speed` (preamble, SFD and gap, which CSMA does not model otherwise); CSMA adds the Ethernet header and FCS itself. *In ns-3.49 the gap is not an attribute: `Attach()` sets 12 B, so the generator calls `CsmaNetDevice::SetInterframeGap()` on each device after installing it.* |
124
125
  | `flow` | UDP application; payload sized so the on-wire frame matches `size` (constant, Poisson, bursty patterns; `imix` sizes). *As built:* the payload is `size` minus 46 B (Ethernet 18, IPv4 20, UDP 8), sent to port 9 of the destination, where a socket discards it. |
125
- | `publish` / `route` | MQTT publisher / broker Applications over one persistent TCP connection per client; QoS 1 sends PUBACK |
126
- | `poll` | Modbus TCP master / slave Applications over one persistent TCP connection per master–slave pair (port 502), MBAP transaction IDs, Read Holding Registers (FC 03) |
126
+ | `publish` / `route` | MQTT publisher / broker Applications over one persistent TCP connection per client; QoS 1 sends PUBACK. *As built:* port 1883; subscribers connect to the broker as clients, and one connection carries all of a client's PUBLISH messages and copies (see "Modbus and MQTT over TCP" below). |
127
+ | `poll` | Modbus TCP master / slave Applications over one persistent TCP connection per master–slave pair (port 502), MBAP transaction IDs, Read Holding Registers (FC 03). *As built:* without transaction IDs. Responses come back in order on the connection, so the master pairs them with its requests in that order. |
127
128
  | `observe` | Periodic sampler writing CSV rows |
128
129
  | `simulate mode=` | `headless` only; `text`/`live` are capability errors (results are post-processed after the run) |
129
130
 
@@ -150,11 +151,11 @@ smolpy backends # list backends and their capabiliti
150
151
  | `throughput`, `bytes_received` | frames addressed to the node, received by its device: frame bytes, header to FCS (`MacRx`) |
151
152
  | `bytes_sent` | frames whose transmission on the node's device has completed (`PhyTxEnd`), frame bytes |
152
153
  | `latency` | from the origin time, carried in a packet tag set when the data is created, to reception by the device. Queueing at the sender is included, as in SimPy. |
153
- | `modbus_latency` | the same, with the request's origin tag copied into the response |
154
- | `pn_latency`, `pn_jitter`, `pn_watchdog_expiries` | the SMOL PROFINET consumer application, with the definitions of Model Semantics §7 |
154
+ | `modbus_latency` | the same, with the request's origin tag copied into the response. *As built:* measured when the master has the whole response. |
155
+ | `pn_latency`, `pn_jitter`, `pn_watchdog_expiries` | the SMOL PROFINET consumer application, with the definitions of Model Semantics §7. *As built:* the node's consumer, called by its device for each PROFINET frame; see "PROFINET RT on ns-3" below. |
155
156
  | `queue_depth` | frames waiting in the egress queues of the switch's devices, not counting the frame in transmission |
156
157
  | `utilization` | frame + 20 B per frame completed on the links into the node, as a share of their capacity (ADR-0010) |
157
- | `broker_queue` | the queue of the broker application |
158
+ | `broker_queue` | the queue of the broker application. *As built:* messages waiting for a subscriber's connection, which the subscriber has not yet opened. The broker handles a message at once, as on SimPy, so the queue is otherwise empty. |
158
159
 
159
160
  - **How FlowMonitor differs.** This is for comparisons with ns-3 literature, and is to be checked against the pinned release. FlowMonitor's statistics:
160
161
  - are per flow (IP 5-tuple), not per node and window;
@@ -218,7 +219,7 @@ ns-3.49's CSMA is a shared bus: the two ends of a link wait for each other, and
218
219
  - It occupies the wire for preamble, SFD and frame, and the next frame waits for the 12 B gap (ADR-0010).
219
220
  - Times are rounded as in Model Semantics §1.
220
221
  - **IP on top.** IPv4 runs on the device with a /32 address and every destination on the link. IPv6 is not installed, so there are no router solicitations or other IPv6 traffic. The neighbour caches start full, because SMOL models no ARP.
221
- - **What ns-3 contributes** is its IPv4/UDP stack now, and its TCP stack for Modbus and MQTT later. The differences that remain between engines are the protocol stack's, which is what the comparison is for.
222
+ - **What ns-3 contributes** is its IPv4/UDP stack, and its TCP stack for Modbus and MQTT ("Modbus and MQTT over TCP" below). The differences that remain between engines are the protocol stack's, which is what the comparison is for.
222
223
  - **Options rejected.**
223
224
  - **CSMA as planned.** Its differences from the other engines would come from half duplex.
224
225
  - **`SimpleNetDevice`.** It is full duplex, but it counts neither the Ethernet header and FCS nor the preamble and gap: about 38 B per frame too few.
@@ -230,6 +231,66 @@ ns-3.49's CSMA is a shared bus: the two ends of a link wait for each other, and
230
231
 
231
232
  ns-3 adds a priority to a frame as a packet tag. Its device then adds the 802.1Q tag's 4 B and serves its egress queue strictly by priority, or FIFO on a switch with `qos="fifo"`.
232
233
 
234
+ **Modbus and MQTT over TCP** *(decided and built 2026-11-16)*
235
+
236
+ What ns-3 is there for is its TCP. The backend therefore keeps everything else as on the other engines, so that the differences that remain are TCP's.
237
+ - **Connections.**
238
+ - One persistent connection per Modbus master and slave (port 502), and one per MQTT client and broker (port 1883).
239
+ - A client that publishes to a broker and subscribes to it uses one connection.
240
+ - Every connection is opened at the start of the run. The first messages come later.
241
+ - **Messages, not bytes.**
242
+ - The applications send whole protocol messages, sized in TCP payload bytes with SMOL's formulas (`frames.py`: `mqtt_publish_message_bytes`, `modbus_response_message_bytes`, ...).
243
+ - The bytes carry nothing. Each connection keeps, per direction, the messages whose bytes are on the way. TCP delivers bytes in order, so a message has arrived when all of its bytes have.
244
+ - Each message's bytes carry its origin time as a byte tag. So `latency` is measured per frame for TCP data as for UDP. Segments without data, such as acknowledgements and the handshake, have no origin and do not count in `latency`.
245
+ - **SMOL's frame sizes.**
246
+ - Every segment has a 20 B TCP header, as SMOL sizes Modbus and MQTT frames: the timestamp option is off. Window scaling and SACK stay on. They add 8 B to the SYN and SYN-ACK, and SACK blocks only to the acknowledgements of a loss, which SMOL's unbounded queues do not cause.
247
+ - The segment size is Ethernet's 1460 B, not ns-3's default of 536 B.
248
+ - **ns-3's defaults otherwise.** Congestion control is CUBIC. Delayed acknowledgements are every second segment or after 200 ms. Nagle is off (`TcpNoDelay`). The minimum RTO is 1 s.
249
+ - **Applications.**
250
+ - They act at the instant a message arrives, as on SimPy.
251
+ - They never block: the send buffer (1 GiB) holds what TCP cannot send yet.
252
+ - A broker sends its copies to subscribers first and then the PUBACK, as on SimPy.
253
+ - **Options rejected.**
254
+ - **Parsing real MQTT and MBAP bytes in the stream.** SMOL's sizes are not real encodings: for example, MQTT's remaining length takes 2 B above 127 B. Real encodings would change the frame sizes.
255
+ - **ns-3's timestamp option.** It is on in Linux, but it would make every frame 12 B larger than SMOL's. That difference would come from sizing, not from TCP's behaviour.
256
+
257
+ **What TCP changes, to the nanosecond** (tests in `tests/test_ns3.py`):
258
+ - **1 ns per send.** ns-3 sends an application's data one time step after the call, which is 1 ns here. So a Modbus round trip and a PUBLISH from publisher to subscriber both take SimPy's time plus 2 ns. A broker's or slave's reply would otherwise leave at once, ahead of other data: `Send()` on the connection that has just received data is flushed in the same event. Replies are therefore scheduled as events of their own, in the order the application makes them.
259
+ - **The handshake.** Each client receives a SYN-ACK of 66 B at the start, and switches learn the stations from it.
260
+ - **The first data segment** of a connection is acknowledged at once. ns-3 counts the handshake as a full delayed-ACK count. The reply waits behind that frame, 6.72 µs at 100 Mb/s.
261
+ - **Acknowledgements.**
262
+ - **Request and response (Modbus, MQTT QoS 1).** Each reply carries the acknowledgement of the request, and the next request carries the acknowledgement of the reply. No extra frames.
263
+ - **One-way PUBLISH (QoS 0, and copies to subscribers).** The receiver sends a 64 B acknowledgement for every second segment. At a broker, that frame leaves just before the copies and delays them by its transmission time.
264
+
265
+ **First results over TCP** *(2026-11-16)*. The suite's TCP scenarios sample the same metrics at the same instants as SimPy (`test_over_tcp`). The table gives the means of their values over the run:
266
+
267
+ | Scenario | Metric | SimPy | ns-3 | Why |
268
+ |---|---|---|---|---|
269
+ | `protocols` | `modbus_latency:scada` | 43.76 µs | 44.37 µs | +2 ns per round trip; +6.72 µs on the first one |
270
+ | | `latency:hmi` | 47.12 µs | 49.26 µs | copies behind the broker's acknowledgements of the QoS 0 topic |
271
+ | | `bytes_received:scada` | 3.19 kB | 3.38 kB | SYN-ACKs and the first acknowledgements |
272
+ | `polling` | `modbus_latency:scada` | 123.21 µs | 131.05 µs | the first window: the handshakes on the 10 Mb/s link; then +2 ns |
273
+ | | `bytes_received:plc` | 1.06 kB | 1.30 kB | SYN-ACKs and the first acknowledgements |
274
+ | | `utilization:edge` | 0.40 % | 0.48 % | the handshakes, in the first windows |
275
+ | `messaging` (loaded uplink) | `bytes_received:hall`, `:cell` | 0.48 kB, 0.31 kB | 0.86 kB, 0.61 kB | a 64 B acknowledgement for every second QoS 0 PUBLISH |
276
+ | | `utilization:plant` | 1.07 % | 1.67 % | the acknowledgements sent to the broker |
277
+ | | `latency:hmi`, `:scada`, `:historian` | 291, 266, 119 µs | 289, 259, 115 µs | acknowledgements change the order of frames in the FIFO queues, both ways |
278
+ | | `queue_depth:edge` | 0.0175 | 0.0063 | the same |
279
+
280
+ - **Low load.** After the first messages, ns-3 is SimPy plus 2 ns per message. The remaining differences are the handshake, the first acknowledgement, and the acknowledgements of one-way traffic.
281
+ - **Loaded.** The acknowledgements reorder frames in shared queues, so differences remain throughout the run. They are reported, not asserted (ADR-0009). Quantifying them under heavier load, where TCP's flow and congestion control act, is the next part of this research.
282
+
283
+ **PROFINET RT on ns-3** *(built 2026-11-16)*
284
+
285
+ PROFINET RT is a layer 2 protocol (EtherType 0x8892), without IP, so ns-3's stack has nothing to add to it. The backend runs it on SMOL's Ethernet device, so that scenarios that mix PROFINET with flows, Modbus and MQTT run whole on ns-3.
286
+ - **Providers.** Each AR has a provider on the controller (outputs) and on the device (inputs). Each one hands a frame to its device every cycle, from the AR's start delay on.
287
+ - Frames are sized by the model's formula (`pn_frame_size`), 802.1Q tag and padding included.
288
+ - Their priority is 6, served strictly by the egress queues, or FIFO on a switch with `qos="fifo"`.
289
+ - The providers start by controller in node order, as on the reference engine.
290
+ - **Consumers.** Each node's consumer measures latency and jitter, and supervises each AR with a watchdog, as defined in Model Semantics §7. The watchdog is one ns-3 event at `hold × cycle` after the last frame. Each frame cancels it and sets it again.
291
+ - **The deadline comes first.** A frame that arrives exactly at the deadline was scheduled after the watchdog, at the end of its transmission. ns-3 runs events of one instant in the order they were scheduled, so the expiry counts, and the frame then restarts supervision. That is SimPy's outcome, where the watchdog's timeout fires before the frame is delivered.
292
+ - **Results.** `priorities`, `cyclic` and `batches` (with the same seed) give SimPy's results bit for bit. That includes watchdog expiries under load, and a hold of one cycle with no jitter, where every frame arrives at its deadline (`test_a_frame_at_the_watchdogs_deadline_is_too_late`).
293
+
233
294
  **The ns-3 base image, as built** *(2026-11-16)*:
234
295
  - `ghcr.io/jwszolek/smolpy-ns3-base:3.49`, built by `.github/workflows/ns3-base.yml` from `docker/ns3-base/Dockerfile`, for `linux/amd64` only for now. It is rebuilt when that Dockerfile changes, and pushed after the merge to `main`.
235
296
  - **Pinned release:** ns-3.49 (released 2026-10-07), as the git tag `ns-3.49` with its commit checked. Debian 12's g++ 12 and CMake 3.25 meet its minimums: g++ 11.1, C++23 and CMake 3.25.
@@ -87,7 +87,7 @@ The suite lives in `tests/equivalence/`. It runs a fixed set of reference scenar
87
87
  |---|---|
88
88
  | **Deterministic** (constant patterns, fixed sizes, no randomness) | ~~Per metric window: \|a − b\| ≤ abs_tol + rel_tol·\|b\|. The tolerance only covers time representation (SimPy float µs vs Rust integer ns); default `rel_tol = 1e-6`, `abs_tol` = 1 ns-equivalent in the metric's unit.~~ *Amended by the ADR-0007 revision of 2026-11-14 ([integer nanoseconds](0007-execution-independent-scenario-model.md#simulated-time-integer-nanoseconds)):* every metric window must match exactly, sample times and values bit for bit (in place since ADR-0007 step 8). |
89
89
  | **Stochastic** | 30 replications per backend. For each metric's per-run scalar, the ~~95 %~~ confidence interval of the difference of means must contain 0, and the relative difference of means must be under 2 %. *Amended 2026-11-15:* with *k* metrics in a scenario, each interval is at the Bonferroni level `1 − 0.05/k`, e.g. 98.75 % for 4 metrics. Two equivalent backends then fail a scenario by chance at most 5 % of the time. With 95 % per metric they failed about one seed block in ten, and now one in forty (measured over 20 blocks per scenario). |
90
- | **High-fidelity backends** (ns-3) | Low-load scenarios: same rules as stochastic. Loaded scenarios: differences are **reported, not asserted** (ADR-0004). Quantifying them is a research result. *Amended 2026-11-16:* on SMOL's own Ethernet with UDP, ns-3 gives SimPy's results bit for bit, so the deterministic scenarios in its scope are compared exactly, as for Rust. ns-3 draws random traffic from the reference engine's streams, so a stochastic scenario with the same seed must also match bit for bit (`test_same_streams_give_the_same_run`), besides the statistical comparison. These rules remain for TCP, where ns-3's stack is meant to differ. |
90
+ | **High-fidelity backends** (ns-3) | Low-load scenarios: same rules as stochastic. Loaded scenarios: differences are **reported, not asserted** (ADR-0004). Quantifying them is a research result. *Amended 2026-11-16:* on SMOL's own Ethernet with UDP, ns-3 gives SimPy's results bit for bit, so the deterministic scenarios in its scope are compared exactly, as for Rust. ns-3 draws random traffic from the reference engine's streams, so a stochastic scenario with the same seed must also match bit for bit (`test_same_streams_give_the_same_run`), besides the statistical comparison. These rules remain for TCP, where ns-3's stack is meant to differ. *Amended 2026-11-16:* ns-3 runs Modbus and MQTT over TCP. For a scenario with that traffic, the suite checks that ns-3 samples the same metrics at the same instants, and reports the differences in their means (`test_over_tcp`). Tests of small scenarios check what TCP adds to the nanosecond (ADR-0004). PROFINET RT on ns-3 is layer 2 and is compared exactly, like Ethernet. |
91
91
 
92
92
  - Backends that are not installed are skipped.
93
93
  - **CI:** SimPy against itself (a sanity check of the harness) and Rust against SimPy when the Rust package is available.
@@ -165,7 +165,7 @@ result.export("out.csv", format="csv") # explicit format override
165
165
  |---|---|
166
166
  | `"simpy"` | The reference implementation. It is the default, always installed, and runs the whole model, including the live and text dashboards. |
167
167
  | `"rust"` | The native engine of [ADR-0008](adr/0008-rust-des-engine-mvp.md), from the optional package `smolpy-engine-rs` (`pip install smolpy[rust]`). It runs headless. |
168
- | `"ns3"` | ns-3 ([ADR-0004](adr/0004-execution-backends.md)), in progress: so far Ethernet (adapters, switches, flows with every pattern, IMIX and 802.1Q priorities, the Ethernet metrics) on ns-3's IPv4/UDP stack, with random traffic drawn from SimPy's streams. It needs `NS3_HOME`, naming a built ns-3 3.49 tree, and a C++ compiler; the image `ghcr.io/jwszolek/smolpy-ns3-base:3.49` has both. It runs headless. |
168
+ | `"ns3"` | ns-3 ([ADR-0004](adr/0004-execution-backends.md)), the whole model. Ethernet (flows with every pattern, IMIX and 802.1Q priorities) runs on ns-3's IPv4/UDP stack, with random traffic drawn from SimPy's streams. PROFINET RT runs on layer 2. Both give SimPy's results bit for bit. Modbus TCP and MQTT run on ns-3's TCP, whose connection setup and acknowledgements make those results differ from SimPy's. It needs `NS3_HOME`, naming a built ns-3 3.49 tree, and a C++ compiler; the image `ghcr.io/jwszolek/smolpy-ns3-base:3.49` has both. It runs headless. |
169
169
 
170
170
  - **What a backend can run is checked before the run.** Every backend declares what it supports: node kinds, traffic kinds, patterns and metrics. A scenario that uses anything else is rejected with a `ScenarioError` naming the element. A dashboard (`live=True` or `text=True`) on a headless backend is a `ValueError`.
171
171
  - **A missing backend is an error.** When a backend is not installed, selecting it raises `BackendUnavailable` with the install command.
@@ -172,7 +172,7 @@ A code-generated ns-3 scenario from the Scenario IR. Gives a realistic TCP/IP st
172
172
 
173
173
  ns-3 cannot be installed with `pip`, so the backend ships as a container image, `ghcr.io/jwszolek/smolpy:<version>-ns3`. It holds the pinned ns-3 release built once, and CI runs the ns-3 equivalence suite in it ([ADR-0004 — Container images](adr/0004-execution-backends.md#container-images)). A lighter image with SMOLPy and the Rust engine, without ns-3, can be published from the first release of `smolpy-engine-rs`.
174
174
 
175
- **Status:** steps 1 and 2 of 3 done, and step 3 has begun.
175
+ **Status:** steps 1 and 2 of 3 done. In step 3 the backend runs the whole model, and the `-ns3` image remains.
176
176
  1. **The image without ns-3: done.** `ghcr.io/jwszolek/smolpy:<version>` holds SMOLPy and the Rust engine, for `linux/amd64` and `linux/arm64`. It is built, tested and pushed at each release.
177
177
  2. **The ns-3 base image: done.** `ghcr.io/jwszolek/smolpy-ns3-base:3.49` holds ns-3.49, built once, for `linux/amd64`. `arm64` follows on a native runner.
178
178
  3. **The ns-3 backend.**
@@ -181,7 +181,14 @@ ns-3 cannot be installed with `pip`, so the backend ships as a container image,
181
181
  - Random traffic is drawn from the reference engine's streams.
182
182
  - Every Ethernet scenario of the suite is bit-exact with SimPy. For the stochastic ones that holds with the same seed.
183
183
  - CI runs the backend in the base image.
184
- - **Next:** Modbus and MQTT over ns-3's TCP, then PROFINET.
184
+ - **Modbus and MQTT: done.** They run over ns-3's TCP, with one persistent connection per master and slave, or per client and broker (ADR-0004).
185
+ - Their frames have SMOL's sizes. What TCP adds is the handshake, acknowledgements and, under load, its flow and congestion control.
186
+ - At low load, after the first messages, every Modbus round trip and MQTT delivery is SimPy's plus 2 ns. Tests check this to the nanosecond.
187
+ - The suite checks that the TCP scenarios sample the same metrics at the same instants as SimPy, and reports how their values differ.
188
+ - **PROFINET: done.** PROFINET RT runs on layer 2, on SMOL's Ethernet device, with the three PROFINET metrics.
189
+ - Every PROFINET scenario of the suite is bit-exact with SimPy, watchdog expiries included.
190
+ - A frame that arrives exactly at the watchdog's deadline is too late on both engines.
191
+ - **Next:** the `<version>-ns3` image, with CI running the ns-3 suite in it.
185
192
 
186
193
  **Exit criteria:**
187
194
 
@@ -160,8 +160,9 @@ class RustBackend:
160
160
  class Ns3Backend:
161
161
  """ns-3 (ADR-0004, ``smolpy.ns3``), where ``NS3_HOME`` names an ns-3 build.
162
162
 
163
- So far it runs Ethernet: adapters, switches and flows with every pattern,
164
- IMIX and 802.1Q priorities. The protocols follow in Phase 6.
163
+ It runs the whole model, headless: Ethernet (adapters, switches and flows
164
+ with every pattern, IMIX and 802.1Q priorities) over UDP, Modbus TCP and
165
+ MQTT over ns-3's TCP, and PROFINET RT on layer 2.
165
166
  """
166
167
 
167
168
  name = "ns3"
@@ -189,10 +190,9 @@ class Ns3Backend:
189
190
 
190
191
  def capabilities(self) -> Capabilities:
191
192
  self._locate()
192
- later = "planned for Phase 6"
193
193
  return Capabilities(
194
- nodes=frozenset({"adapter", "switch"}),
195
- traffic=frozenset({"flow"}),
194
+ nodes=_NODE_KINDS,
195
+ traffic=_TRAFFIC_KINDS,
196
196
  patterns=_PATTERNS,
197
197
  metrics=frozenset(
198
198
  {
@@ -202,21 +202,14 @@ class Ns3Backend:
202
202
  "bytes_received",
203
203
  "queue_depth",
204
204
  "utilization",
205
+ "modbus_latency",
206
+ "broker_queue",
207
+ "pn_latency",
208
+ "pn_jitter",
209
+ "pn_watchdog_expiries",
205
210
  }
206
211
  ),
207
212
  features=frozenset({"imix"}),
208
- notes={
209
- kind: later
210
- for kind in (
211
- "mqtt_broker",
212
- "modbus_slave",
213
- "profinet_device",
214
- "publish",
215
- "route",
216
- "poll",
217
- "profinet_ar",
218
- )
219
- },
220
213
  )
221
214
 
222
215
  def run(self, scenario: Scenario) -> SimulationResult:
@@ -28,9 +28,15 @@ PN_RT_PRIORITY = 6 # 802.1Q PCP carried by PROFINET RT cyclic frames
28
28
  PN_CYCLES_MS = tuple(2**n for n in range(10)) # 1, 2, 4, ... 512 ms
29
29
  PN_MAX_IO_BYTES = 1440
30
30
 
31
- MQTT_PUBACK_BYTES = max(MIN_FRAME_BYTES, ETHERNET_IP_TCP_BYTES + 4) # 62 B, padded to 64
31
+ # The protocol messages below are the TCP payload of one frame each; their
32
+ # frames add ETHERNET_IP_TCP_BYTES. The ns-3 backend sends the messages
33
+ # themselves over TCP.
32
34
 
33
- MODBUS_REQUEST_BYTES = ETHERNET_IP_TCP_BYTES + 6 + 1 + 2 + 2 # 69: MBAP, FC, addr, quantity
35
+ MQTT_PUBACK_MESSAGE_BYTES = 4
36
+ MQTT_PUBACK_BYTES = max(MIN_FRAME_BYTES, ETHERNET_IP_TCP_BYTES + MQTT_PUBACK_MESSAGE_BYTES) # 64
37
+
38
+ MODBUS_REQUEST_MESSAGE_BYTES = 6 + 1 + 2 + 2 # MBAP, FC, address, quantity
39
+ MODBUS_REQUEST_BYTES = ETHERNET_IP_TCP_BYTES + MODBUS_REQUEST_MESSAGE_BYTES # 69
34
40
 
35
41
 
36
42
  def padded(frame_bytes: int) -> int:
@@ -44,16 +50,23 @@ def flow_frame_size(size: int, priority: int) -> int:
44
50
  return size + (VLAN_TAG_BYTES if priority > 0 else 0)
45
51
 
46
52
 
53
+ def mqtt_publish_message_bytes(topic: str, payload_bytes: int, qos: int) -> int:
54
+ """MQTT PUBLISH: fixed header (2) + topic length (2) + topic + packet id (QoS > 0)
55
+ + payload. The topic's length counts characters."""
56
+ return 2 + 2 + len(topic) + (2 if qos > 0 else 0) + payload_bytes
57
+
58
+
47
59
  def mqtt_publish_frame_size(topic: str, payload_bytes: int, qos: int) -> int:
48
- """MQTT PUBLISH: fixed header (2) + topic length (2) + topic + packet id (QoS > 0)."""
49
- return padded(
50
- ETHERNET_IP_TCP_BYTES + 2 + 2 + len(topic) + (2 if qos > 0 else 0) + payload_bytes
51
- )
60
+ return padded(ETHERNET_IP_TCP_BYTES + mqtt_publish_message_bytes(topic, payload_bytes, qos))
52
61
 
53
62
 
54
- def modbus_response_frame_size(count: int) -> int:
63
+ def modbus_response_message_bytes(count: int) -> int:
55
64
  """Read Holding Registers response: MBAP (6) + FC (1) + byte count (1) + 2 B per register."""
56
- return padded(ETHERNET_IP_TCP_BYTES + 6 + 1 + 1 + 2 * count)
65
+ return 6 + 1 + 1 + 2 * count
66
+
67
+
68
+ def modbus_response_frame_size(count: int) -> int:
69
+ return padded(ETHERNET_IP_TCP_BYTES + modbus_response_message_bytes(count))
57
70
 
58
71
 
59
72
  def pn_frame_size(io_bytes: int) -> int:
@@ -1,4 +1,5 @@
1
- """The ns-3 backend (ADR-0004): SMOLPy scenarios on ns-3's IPv4/UDP stack.
1
+ """The ns-3 backend (ADR-0004): SMOLPy scenarios on ns-3's IPv4 stack, with
2
+ UDP for flows and TCP for Modbus and MQTT, and PROFINET RT on layer 2.
2
3
 
3
4
  A scenario is lowered to plain lines of integers (every time in integer
4
5
  nanoseconds, every speed and period an exact rational) and run by
@@ -34,7 +35,13 @@ from typing import TYPE_CHECKING
34
35
 
35
36
  from smolpy import model
36
37
  from smolpy.model import timebase as tb
37
- from smolpy.model.frames import IFG_BYTES
38
+ from smolpy.model.frames import (
39
+ IFG_BYTES,
40
+ MODBUS_REQUEST_MESSAGE_BYTES,
41
+ modbus_response_message_bytes,
42
+ mqtt_publish_message_bytes,
43
+ pn_frame_size,
44
+ )
38
45
  from smolpy.model.streams import source_ids, stream_seed
39
46
 
40
47
  if TYPE_CHECKING:
@@ -44,6 +51,8 @@ FORMAT_VERSION = 1
44
51
  UDP_IP_BYTES = 8 + 20
45
52
  ETHERNET_BYTES = 14 + 4 # header and FCS
46
53
  PROGRAM = "smol-ns3"
54
+ MODBUS_PORT = 502
55
+ MQTT_PORT = 1883
47
56
 
48
57
 
49
58
  class Ns3Unavailable(RuntimeError):
@@ -207,12 +216,10 @@ def lower(scenario: model.Scenario) -> tuple[str, list[_Sampler]]:
207
216
  index = {n.name: i for i, n in enumerate(scenario.nodes)}
208
217
  lines = [f"smol-ns3 {FORMAT_VERSION}", f"duration {tb.ms_to_ns(scenario.run.duration_ms)}"]
209
218
  for n in scenario.nodes:
210
- if isinstance(n, model.AdapterNode):
211
- lines.append(f"adapter {n.mac} {n.ip}")
212
- elif isinstance(n, model.SwitchNode):
219
+ if isinstance(n, model.SwitchNode):
213
220
  lines.append("switch")
214
- else: # the capabilities exclude it
215
- raise ValueError(f"the ns3 backend does not support {n.kind} nodes")
221
+ else:
222
+ lines.append(f"adapter {n.mac} {n.ip}") # a station, with IPv4
216
223
 
217
224
  next_port: dict[str, int] = {n.name: 0 for n in scenario.nodes}
218
225
  neighbours: dict[str, list[tuple[int, str]]] = {n.name: [] for n in scenario.nodes}
@@ -238,7 +245,7 @@ def lower(scenario: model.Scenario) -> tuple[str, list[_Sampler]]:
238
245
  into.setdefault(b.name, []).append((2 * i, speed))
239
246
  # a switch knows the stations wired to it from the start
240
247
  for end, other, port in ((a, b, port_b), (b, a, port_a)):
241
- if isinstance(end, model.AdapterNode) and isinstance(other, model.SwitchNode):
248
+ if not isinstance(end, model.SwitchNode) and isinstance(other, model.SwitchNode):
242
249
  static.setdefault(other.name, {})[end.mac] = port
243
250
  for n in scenario.nodes:
244
251
  if isinstance(n, model.SwitchNode) and n.mac_table == "topology":
@@ -250,7 +257,58 @@ def lower(scenario: model.Scenario) -> tuple[str, list[_Sampler]]:
250
257
 
251
258
  sinks: list[str] = []
252
259
  duration_ns = tb.ms_to_ns(scenario.run.duration_ms)
260
+ connections: dict[tuple[str, str], int] = {} # one per client and server
261
+ topics: dict[str, int] = {}
262
+
263
+ def connection(client: str, server: str, port: int) -> int:
264
+ if (client, server) not in connections:
265
+ connections[client, server] = len(connections)
266
+ lines.append(f"connect {index[client]} {index[server]} {port}")
267
+ return connections[client, server]
268
+
269
+ def periodic(rate: float, delay_ms: float) -> str:
270
+ num, den = _ratio(tb.interval_ns(rate))
271
+ return f"{tb.ms_to_ns(delay_ms)} {num} {den}"
272
+
273
+ # PROFINET ARs first, by controller in node order, as the reference engine
274
+ # starts them: their first frames are sent at the start of the run
275
+ ars = [t for t in scenario.traffic if isinstance(t, model.ProfinetAR)]
276
+ for ar_id, pn in enumerate(sorted(ars, key=lambda ar: index[ar.controller])):
277
+ if pn.controller in has_link and pn.device in has_link:
278
+ lines.append(
279
+ f"ar {index[pn.controller]} {index[pn.device]} {ar_id}"
280
+ f" {tb.ms_to_ns(pn.cycle_ms)} {pn.hold} {tb.ms_to_ns(pn.delay_ms)}"
281
+ f" {pn_frame_size(pn.outputs)} {pn_frame_size(pn.inputs)}"
282
+ )
253
283
  for t, source_id in zip(scenario.traffic, source_ids(scenario), strict=True):
284
+ if isinstance(t, model.ProfinetAR):
285
+ continue
286
+ if isinstance(t, model.Poll):
287
+ if t.source in has_link:
288
+ c = connection(t.source, t.slave, MODBUS_PORT)
289
+ response = modbus_response_message_bytes(t.count)
290
+ lines.append(
291
+ f"poll {c} {MODBUS_REQUEST_MESSAGE_BYTES} {response}"
292
+ f" {periodic(t.rate, t.delay_ms)}"
293
+ )
294
+ continue
295
+ if isinstance(t, model.Publish):
296
+ if t.source in has_link:
297
+ c = connection(t.source, t.broker, MQTT_PORT)
298
+ topic = topics.setdefault(t.topic, len(topics))
299
+ message = mqtt_publish_message_bytes(t.topic, t.payload, t.qos)
300
+ lines.append(
301
+ f"publish {c} {message} {t.qos} {topic} {periodic(t.rate, t.delay_ms)}"
302
+ )
303
+ continue
304
+ if isinstance(t, model.Route):
305
+ topic = topics.setdefault(t.topic, len(topics))
306
+ subscribers = [
307
+ connection(sub, t.broker, MQTT_PORT) for sub in t.subscribers if sub in has_link
308
+ ]
309
+ listed = " ".join(str(c) for c in subscribers)
310
+ lines.append(f"route {index[t.broker]} {topic} {listed}".rstrip())
311
+ continue
254
312
  if not isinstance(t, model.Flow):
255
313
  raise ValueError(f"the ns3 backend does not support {t.kind} traffic")
256
314
  if t.source not in has_link:
@@ -280,8 +338,12 @@ def lower(scenario: model.Scenario) -> tuple[str, list[_Sampler]]:
280
338
  devices = ""
281
339
  speed = Fraction(0)
282
340
  metric = obs.metric
283
- if metric in ("throughput", "latency", "bytes_received"):
341
+ if metric in ("throughput", "latency", "bytes_received", "modbus_latency"):
284
342
  ok = adapter and target.name in has_link
343
+ elif metric == "broker_queue":
344
+ ok = isinstance(target, model.MqttBrokerNode)
345
+ elif metric in ("pn_latency", "pn_jitter", "pn_watchdog_expiries"):
346
+ ok = isinstance(target, model.AdapterNode | model.ProfinetDeviceNode)
285
347
  elif metric == "bytes_sent":
286
348
  ok = adapter and target.name in has_link
287
349
  elif metric == "queue_depth":
@@ -325,14 +387,17 @@ def _metrics(
325
387
  t_ms = tb.ns_to_ms(t)
326
388
  if s.metric == "throughput":
327
389
  out.append((t_ms, (a - last) * 8 * tb.NS_PER_US / (t - last_t)))
328
- elif s.metric == "latency":
390
+ elif s.metric in ("latency", "modbus_latency", "pn_latency"):
329
391
  if b:
330
392
  out.append((t_ms, a / (b * tb.NS_PER_US)))
393
+ elif s.metric == "pn_jitter":
394
+ if b:
395
+ out.append((t_ms, a / tb.NS_PER_US))
331
396
  elif s.metric == "bytes_received":
332
397
  out.append((t_ms, a / 1_000_000))
333
398
  elif s.metric == "bytes_sent":
334
399
  out.append((t_ms, a // 8 / 1_000_000))
335
- elif s.metric == "queue_depth":
400
+ elif s.metric in ("queue_depth", "broker_queue", "pn_watchdog_expiries"):
336
401
  out.append((t_ms, float(a)))
337
402
  elif s.metric == "utilization":
338
403
  out.append((t_ms, tb.quotient((a - last) * 100_000, s.speed * (t - last_t))))