smolpy 1.9.1.dev8__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 (145) hide show
  1. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/PKG-INFO +2 -2
  2. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/README.md +1 -1
  3. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/adr/0004-execution-backends.md +13 -1
  4. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/adr/0009-batch-execution-and-cross-backend-validation.md +1 -1
  5. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/dsl-reference.md +1 -1
  6. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/roadmap.md +5 -2
  7. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/backends.py +8 -7
  8. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/ns3/__init__.py +24 -8
  9. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/ns3/cpp/smol-ns3.cc +197 -5
  10. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_ns3.py +55 -21
  11. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/.github/workflows/ci.yml +0 -0
  12. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/.github/workflows/dev-build.yml +0 -0
  13. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/.github/workflows/docker-image.yml +0 -0
  14. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/.github/workflows/docs.yml +0 -0
  15. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/.github/workflows/github-release.yml +0 -0
  16. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/.github/workflows/ns3-base.yml +0 -0
  17. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/.github/workflows/publish.yml +0 -0
  18. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/.github/workflows/release.yml +0 -0
  19. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/.github/workflows/rust-wheels.yml +0 -0
  20. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/.gitignore +0 -0
  21. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/LICENSE +0 -0
  22. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/__init__.py +0 -0
  23. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/__main__.py +0 -0
  24. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-13-0921-simpy-jaws-zbook-baseline.json +0 -0
  25. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-13-1527-simpy-jaws-zbook-optimised.json +0 -0
  26. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-13-2116-simpy-jaws-zbook-research-batch.json +0 -0
  27. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-13-2119-simpy-jaws-zbook-research-b4.json +0 -0
  28. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-15-1255-rust-jaws-zbook-stop-criterion.json +0 -0
  29. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-15-1333-rust-jaws-zbook-research-b4.json +0 -0
  30. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/results/2026-11-15-1346-rust-jaws-zbook-research-batch.json +0 -0
  31. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/runner.py +0 -0
  32. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/scenarios.py +0 -0
  33. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/benchmarks/worker.py +0 -0
  34. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docker/Dockerfile +0 -0
  35. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docker/Dockerfile.dockerignore +0 -0
  36. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docker/ns3-base/Dockerfile +0 -0
  37. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docker/ns3-base/smoke.cc +0 -0
  38. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docker/smoke.smol +0 -0
  39. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/adr/0001-protocol-package-structure.md +0 -0
  40. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/adr/0002-modbus-tcp-implementation.md +0 -0
  41. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/adr/0003-smol-external-dsl.md +0 -0
  42. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/adr/0005-profinet-rt.md +0 -0
  43. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/adr/0006-profiling-and-baseline-benchmark.md +0 -0
  44. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/adr/0007-execution-independent-scenario-model.md +0 -0
  45. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/adr/0008-rust-des-engine-mvp.md +0 -0
  46. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/adr/0010-ethernet-frames-on-the-wire.md +0 -0
  47. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/benchmarks.md +0 -0
  48. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/dashboard.md +0 -0
  49. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/examples.md +0 -0
  50. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/index.md +0 -0
  51. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/language-reference.md +0 -0
  52. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/modbus.md +0 -0
  53. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/model-semantics.md +0 -0
  54. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/mqtt.md +0 -0
  55. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/profinet.md +0 -0
  56. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/scenario-model.md +0 -0
  57. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/docs/simulation-engine.md +0 -0
  58. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/README.md +0 -0
  59. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example.py +0 -0
  60. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example.smol +0 -0
  61. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example_10_clients.py +0 -0
  62. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example_12_clients.py +0 -0
  63. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example_20_clients.py +0 -0
  64. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example_file_transfer.py +0 -0
  65. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example_modbus.py +0 -0
  66. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example_mqtt.py +0 -0
  67. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example_profinet.py +0 -0
  68. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example_profinet.smol +0 -0
  69. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example_staggered_transfer.py +0 -0
  70. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/examples/example_two_tier.py +0 -0
  71. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/mkdocs.yml +0 -0
  72. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/pyproject.toml +0 -0
  73. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/Cargo.lock +0 -0
  74. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/Cargo.toml +0 -0
  75. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smol-engine/Cargo.toml +0 -0
  76. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smol-engine/src/frames.rs +0 -0
  77. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smol-engine/src/lib.rs +0 -0
  78. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smol-engine/src/rng.rs +0 -0
  79. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smol-engine/src/scenario.rs +0 -0
  80. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smol-engine/src/sim.rs +0 -0
  81. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smol-engine/src/timebase.rs +0 -0
  82. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smolpy-engine-rs/Cargo.toml +0 -0
  83. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smolpy-engine-rs/README.md +0 -0
  84. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smolpy-engine-rs/pyproject.toml +0 -0
  85. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smolpy-engine-rs/smoke_test.py +0 -0
  86. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/rust/smolpy-engine-rs/src/lib.rs +0 -0
  87. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/__init__.py +0 -0
  88. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/_worker.py +0 -0
  89. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/batch.py +0 -0
  90. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/cli.py +0 -0
  91. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/core/__init__.py +0 -0
  92. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/core/adapter.py +0 -0
  93. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/core/batch.py +0 -0
  94. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/core/link.py +0 -0
  95. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/core/network.py +0 -0
  96. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/core/node.py +0 -0
  97. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/core/observation.py +0 -0
  98. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/ethernet/__init__.py +0 -0
  99. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/ethernet/switch.py +0 -0
  100. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/lang/__init__.py +0 -0
  101. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/lang/ast.py +0 -0
  102. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/lang/errors.py +0 -0
  103. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/lang/grammar.lark +0 -0
  104. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/lang/interpreter.py +0 -0
  105. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/lang/transformer.py +0 -0
  106. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/modbus/__init__.py +0 -0
  107. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/modbus/slave.py +0 -0
  108. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/model/__init__.py +0 -0
  109. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/model/frames.py +0 -0
  110. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/model/scenario.py +0 -0
  111. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/model/streams.py +0 -0
  112. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/model/timebase.py +0 -0
  113. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/model/validate.py +0 -0
  114. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/mqtt/__init__.py +0 -0
  115. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/mqtt/broker.py +0 -0
  116. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/profinet/__init__.py +0 -0
  117. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/profinet/device.py +0 -0
  118. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/sim/__init__.py +0 -0
  119. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/sim/engine.py +0 -0
  120. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/stats.py +0 -0
  121. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/viz/__init__.py +0 -0
  122. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/viz/dashboard.py +0 -0
  123. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/src/smolpy/viz/text_dashboard.py +0 -0
  124. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/__init__.py +0 -0
  125. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/equivalence/__init__.py +0 -0
  126. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/equivalence/harness.py +0 -0
  127. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/equivalence/scenarios.py +0 -0
  128. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/equivalence/test_equivalence.py +0 -0
  129. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/equivalence/test_rust_timebase.py +0 -0
  130. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_backends.py +0 -0
  131. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_batch.py +0 -0
  132. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_benchmarks.py +0 -0
  133. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_cli.py +0 -0
  134. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_dsl.py +0 -0
  135. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_engine_ir.py +0 -0
  136. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_lang.py +0 -0
  137. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_model.py +0 -0
  138. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_profinet.py +0 -0
  139. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_semantics.py +0 -0
  140. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_simulation.py +0 -0
  141. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_stats.py +0 -0
  142. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_sweep.py +0 -0
  143. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_timebase.py +0 -0
  144. {smolpy-1.9.1.dev8 → smolpy-1.9.1.dev10}/tests/test_validate.py +0 -0
  145. {smolpy-1.9.1.dev8 → 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.dev8
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 stack, from C++ | Ethernet over UDP, bit-exact with SimPy: adapters, switches, every traffic pattern, IMIX, priorities. Modbus TCP and MQTT over ns-3's TCP, which adds connection setup and acknowledgements. PROFINET not yet | 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 stack, from C++ | Ethernet over UDP, bit-exact with SimPy: adapters, switches, every traffic pattern, IMIX, priorities. Modbus TCP and MQTT over ns-3's TCP, which adds connection setup and acknowledgements. PROFINET not yet | 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,6 +117,7 @@ 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)* |
@@ -151,7 +152,7 @@ smolpy backends # list backends and their capabiliti
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
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. |
154
- | `pn_latency`, `pn_jitter`, `pn_watchdog_expiries` | the SMOL PROFINET consumer application, with the definitions of Model Semantics §7 |
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
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. |
@@ -279,6 +280,17 @@ What ns-3 is there for is its TCP. The backend therefore keeps everything else a
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.
280
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.
281
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
+
282
294
  **The ns-3 base image, as built** *(2026-11-16)*:
283
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`.
284
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. *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). |
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; and Modbus TCP and MQTT on ns-3's TCP, with `modbus_latency` and `broker_queue`. TCP's connection setup and acknowledgements make those results differ from SimPy's. PROFINET is not supported yet. 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 is under way.
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.**
@@ -185,7 +185,10 @@ ns-3 cannot be installed with `pip`, so the backend ships as a container image,
185
185
  - Their frames have SMOL's sizes. What TCP adds is the handshake, acknowledgements and, under load, its flow and congestion control.
186
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
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
- - **Next:** PROFINET.
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.
189
192
 
190
193
  **Exit criteria:**
191
194
 
@@ -160,9 +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) over UDP, and Modbus TCP and MQTT over ns-3's
165
- TCP. PROFINET follows 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.
166
166
  """
167
167
 
168
168
  name = "ns3"
@@ -190,10 +190,9 @@ class Ns3Backend:
190
190
 
191
191
  def capabilities(self) -> Capabilities:
192
192
  self._locate()
193
- later = "planned for Phase 6"
194
193
  return Capabilities(
195
- nodes=frozenset({"adapter", "switch", "mqtt_broker", "modbus_slave"}),
196
- traffic=frozenset({"flow", "publish", "route", "poll"}),
194
+ nodes=_NODE_KINDS,
195
+ traffic=_TRAFFIC_KINDS,
197
196
  patterns=_PATTERNS,
198
197
  metrics=frozenset(
199
198
  {
@@ -205,10 +204,12 @@ class Ns3Backend:
205
204
  "utilization",
206
205
  "modbus_latency",
207
206
  "broker_queue",
207
+ "pn_latency",
208
+ "pn_jitter",
209
+ "pn_watchdog_expiries",
208
210
  }
209
211
  ),
210
212
  features=frozenset({"imix"}),
211
- notes={kind: later for kind in ("profinet_device", "profinet_ar")},
212
213
  )
213
214
 
214
215
  def run(self, scenario: Scenario) -> SimulationResult:
@@ -1,5 +1,5 @@
1
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.
2
+ UDP for flows and TCP for Modbus and MQTT, and PROFINET RT on layer 2.
3
3
 
4
4
  A scenario is lowered to plain lines of integers (every time in integer
5
5
  nanoseconds, every speed and period an exact rational) and run by
@@ -40,6 +40,7 @@ from smolpy.model.frames import (
40
40
  MODBUS_REQUEST_MESSAGE_BYTES,
41
41
  modbus_response_message_bytes,
42
42
  mqtt_publish_message_bytes,
43
+ pn_frame_size,
43
44
  )
44
45
  from smolpy.model.streams import source_ids, stream_seed
45
46
 
@@ -215,12 +216,10 @@ def lower(scenario: model.Scenario) -> tuple[str, list[_Sampler]]:
215
216
  index = {n.name: i for i, n in enumerate(scenario.nodes)}
216
217
  lines = [f"smol-ns3 {FORMAT_VERSION}", f"duration {tb.ms_to_ns(scenario.run.duration_ms)}"]
217
218
  for n in scenario.nodes:
218
- if isinstance(n, model.AdapterNode | model.MqttBrokerNode | model.ModbusSlaveNode):
219
- lines.append(f"adapter {n.mac} {n.ip}") # an IPv4 host
220
- elif isinstance(n, model.SwitchNode):
219
+ if isinstance(n, model.SwitchNode):
221
220
  lines.append("switch")
222
- else: # the capabilities exclude it
223
- 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
224
223
 
225
224
  next_port: dict[str, int] = {n.name: 0 for n in scenario.nodes}
226
225
  neighbours: dict[str, list[tuple[int, str]]] = {n.name: [] for n in scenario.nodes}
@@ -271,7 +270,19 @@ def lower(scenario: model.Scenario) -> tuple[str, list[_Sampler]]:
271
270
  num, den = _ratio(tb.interval_ns(rate))
272
271
  return f"{tb.ms_to_ns(delay_ms)} {num} {den}"
273
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
+ )
274
283
  for t, source_id in zip(scenario.traffic, source_ids(scenario), strict=True):
284
+ if isinstance(t, model.ProfinetAR):
285
+ continue
275
286
  if isinstance(t, model.Poll):
276
287
  if t.source in has_link:
277
288
  c = connection(t.source, t.slave, MODBUS_PORT)
@@ -331,6 +342,8 @@ def lower(scenario: model.Scenario) -> tuple[str, list[_Sampler]]:
331
342
  ok = adapter and target.name in has_link
332
343
  elif metric == "broker_queue":
333
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)
334
347
  elif metric == "bytes_sent":
335
348
  ok = adapter and target.name in has_link
336
349
  elif metric == "queue_depth":
@@ -374,14 +387,17 @@ def _metrics(
374
387
  t_ms = tb.ns_to_ms(t)
375
388
  if s.metric == "throughput":
376
389
  out.append((t_ms, (a - last) * 8 * tb.NS_PER_US / (t - last_t)))
377
- elif s.metric in ("latency", "modbus_latency"):
390
+ elif s.metric in ("latency", "modbus_latency", "pn_latency"):
378
391
  if b:
379
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))
380
396
  elif s.metric == "bytes_received":
381
397
  out.append((t_ms, a / 1_000_000))
382
398
  elif s.metric == "bytes_sent":
383
399
  out.append((t_ms, a // 8 / 1_000_000))
384
- elif s.metric in ("queue_depth", "broker_queue"):
400
+ elif s.metric in ("queue_depth", "broker_queue", "pn_watchdog_expiries"):
385
401
  out.append((t_ms, float(a)))
386
402
  elif s.metric == "utilization":
387
403
  out.append((t_ms, tb.quotient((a - last) * 100_000, s.speed * (t - last_t))))
@@ -17,12 +17,15 @@
17
17
  // poll <connection> <request B> <response B> <delay ns> <period num> <period den>
18
18
  // publish <connection> <message B> <qos> <topic> <delay ns> <period num> <period den>
19
19
  // route <broker> <topic> <connection>... the subscribers' connections
20
+ // ar <controller> <device> <ar> <cycle ns> <hold> <delay ns> <output frame B> <input frame B>
20
21
  // observe <kind> <target> <period num> <period den> <device>...
21
22
  //
22
23
  // A flow is a constant one of fixed-size frames; "sends" lists every frame of
23
24
  // any other flow, its instant and size drawn by smolpy.ns3 from the flow's
24
25
  // random stream exactly as the reference engine draws them. Modbus and MQTT
25
26
  // messages are sized in bytes of TCP payload, and topics are numbered.
27
+ // PROFINET RT frames are layer 2 and sized as whole frames, 802.1Q tag and
28
+ // padding included.
26
29
  //
27
30
  // Link i has the devices 2i (on a) and 2i + 1 (on b); a node's ports are
28
31
  // numbered in the order of its links. Speeds are exact rationals in Mb/s and
@@ -231,6 +234,9 @@ class PriorityTag : public Tag
231
234
  uint8_t m_priority;
232
235
  };
233
236
 
237
+ constexpr uint16_t PN_ETHERTYPE = 0x8892;
238
+ constexpr uint8_t PN_RT_PRIORITY = 6;
239
+
234
240
  struct Frame
235
241
  {
236
242
  Ptr<Packet> packet;
@@ -239,12 +245,84 @@ struct Frame
239
245
  uint16_t protocol = 0;
240
246
  uint64_t bytes = 0;
241
247
  uint8_t priority = 0;
248
+ int32_t ar = -1; // a PROFINET RT frame's AR
242
249
  };
243
250
 
244
251
  struct Window
245
252
  {
246
253
  uint64_t sum = 0;
247
254
  uint64_t count = 0;
255
+ uint64_t max = 0; // pn_jitter
256
+ };
257
+
258
+ // The consumer of PROFINET RT cyclic data on one node, across its ARs, as
259
+ // smolpy.sim.engine._PnConsumer (Model Semantics §7).
260
+ class PnConsumer
261
+ {
262
+ public:
263
+ std::vector<Window*> latencyWindows;
264
+ std::vector<Window*> jitterWindows;
265
+ uint64_t expiries = 0;
266
+
267
+ void Expect(int32_t ar, uint64_t cycleNs, uint64_t hold)
268
+ {
269
+ Ar& a = m_ars[ar];
270
+ a.cycleNs = cycleNs;
271
+ a.timeoutNs = hold * cycleNs;
272
+ }
273
+
274
+ void Record(int32_t id, uint64_t origin)
275
+ {
276
+ auto it = m_ars.find(id);
277
+ if (it == m_ars.end())
278
+ {
279
+ return;
280
+ }
281
+ Ar& ar = it->second;
282
+ uint64_t now = Simulator::Now().GetNanoSeconds();
283
+ for (Window* w : latencyWindows)
284
+ {
285
+ w->sum += now - origin;
286
+ ++w->count;
287
+ }
288
+ if (ar.started)
289
+ {
290
+ int64_t delta = static_cast<int64_t>(now - ar.last) - static_cast<int64_t>(ar.cycleNs);
291
+ uint64_t jitter = static_cast<uint64_t>(delta < 0 ? -delta : delta);
292
+ for (Window* w : jitterWindows)
293
+ {
294
+ w->max = std::max(w->max, jitter);
295
+ ++w->count;
296
+ }
297
+ }
298
+ // Supervision starts with the first frame and restarts with each
299
+ // one. A frame that arrives exactly at the deadline is too late: its
300
+ // arrival was scheduled after the deadline, so the deadline comes
301
+ // first, as on SimPy, where the watchdog's timeout fires before the
302
+ // frame is delivered.
303
+ ar.started = true;
304
+ ar.last = now;
305
+ ar.watchdog.Cancel();
306
+ ar.watchdog = Simulator::Schedule(NanoSeconds(ar.timeoutNs), &PnConsumer::Expire, this);
307
+ }
308
+
309
+ private:
310
+ struct Ar
311
+ {
312
+ uint64_t cycleNs = 0;
313
+ uint64_t timeoutNs = 0; // hold x cycle
314
+ bool started = false;
315
+ uint64_t last = 0;
316
+ EventId watchdog;
317
+ };
318
+
319
+ // Counted once per gap; the exchange goes on (ADR-0005).
320
+ void Expire()
321
+ {
322
+ ++expiries;
323
+ }
324
+
325
+ std::unordered_map<int32_t, Ar> m_ars;
248
326
  };
249
327
 
250
328
  class SmolChannel;
@@ -304,6 +382,7 @@ class SmolDevice : public NetDevice
304
382
  uint64_t framesSent = 0; // those frames
305
383
  uint64_t bytesReceived = 0; // frames addressed to this port
306
384
  std::vector<Window*> latencyWindows;
385
+ PnConsumer* pn = nullptr; // the node's PROFINET consumer
307
386
 
308
387
  // NetDevice
309
388
  void SetIfIndex(const uint32_t index) override
@@ -637,11 +716,11 @@ SmolDevice::Receive(Frame frame)
637
716
  return;
638
717
  }
639
718
  bytesReceived += frame.bytes;
640
- // a UDP datagram's origin is a packet tag; TCP data carries it as a byte
641
- // tag, the first one in a segment; segments without data have none
719
+ // a UDP datagram's or PROFINET frame's origin is a packet tag; TCP data
720
+ // carries it as a byte tag, the first one in a segment; segments without
721
+ // data have none
642
722
  OriginTag tag;
643
- if (!latencyWindows.empty() &&
644
- (frame.packet->PeekPacketTag(tag) || frame.packet->FindFirstMatchingByteTag(tag)))
723
+ if (frame.packet->PeekPacketTag(tag) || frame.packet->FindFirstMatchingByteTag(tag))
645
724
  {
646
725
  uint64_t latency = Simulator::Now().GetNanoSeconds() - tag.Created();
647
726
  for (Window* w : latencyWindows)
@@ -650,6 +729,14 @@ SmolDevice::Receive(Frame frame)
650
729
  ++w->count;
651
730
  }
652
731
  }
732
+ if (frame.protocol == PN_ETHERTYPE)
733
+ {
734
+ if (pn) // PROFINET RT is layer 2: not for IP
735
+ {
736
+ pn->Record(frame.ar, tag.Created());
737
+ }
738
+ return;
739
+ }
653
740
  m_rx(this, frame.packet, frame.protocol, frame.src);
654
741
  }
655
742
 
@@ -804,6 +891,7 @@ class Connection;
804
891
  // The protocol state of a node (an adapter, slave or broker).
805
892
  struct Host
806
893
  {
894
+ PnConsumer pn;
807
895
  std::vector<Window*> rttWindows; // modbus_latency
808
896
  std::unordered_map<uint32_t, std::vector<Connection*>> routes; // broker: topic -> subscribers
809
897
  uint64_t waiting = 0; // broker: messages waiting for a subscriber's connection
@@ -990,6 +1078,37 @@ class Listener
990
1078
  std::unordered_map<uint32_t, Connection*> m_connections;
991
1079
  };
992
1080
 
1081
+ // A PROFINET RT provider: one cyclic frame each cycle from its start, as
1082
+ // smolpy.sim.engine._pn_provider. It is layer 2, handed to the device.
1083
+ struct PnProvider
1084
+ {
1085
+ Ptr<SmolDevice> device;
1086
+ Mac48Address dst;
1087
+ int32_t ar;
1088
+ uint64_t bytes;
1089
+ uint64_t cycleNs;
1090
+ uint64_t stopNs;
1091
+
1092
+ void Fire()
1093
+ {
1094
+ uint64_t now = Simulator::Now().GetNanoSeconds();
1095
+ Frame frame;
1096
+ frame.packet = Create<Packet>();
1097
+ frame.packet->AddPacketTag(OriginTag(now));
1098
+ frame.src = Mac48Address::ConvertFrom(device->GetAddress());
1099
+ frame.dst = dst;
1100
+ frame.protocol = PN_ETHERTYPE;
1101
+ frame.bytes = bytes; // tagged and padded by the model's formula
1102
+ frame.priority = PN_RT_PRIORITY;
1103
+ frame.ar = ar;
1104
+ device->Enqueue(std::move(frame));
1105
+ if (now + cycleNs < stopNs)
1106
+ {
1107
+ Simulator::Schedule(NanoSeconds(cycleNs), &PnProvider::Fire, this);
1108
+ }
1109
+ }
1110
+ };
1111
+
993
1112
  // Modbus polls or MQTT PUBLISH messages at constant instants, as
994
1113
  // smolpy.sim.engine._modbus_poll_gen and _mqtt_traffic_gen.
995
1114
  struct Periodic
@@ -1029,6 +1148,9 @@ enum class Kind
1029
1148
  Utilization,
1030
1149
  ModbusLatency,
1031
1150
  BrokerQueue,
1151
+ PnLatency,
1152
+ PnJitter,
1153
+ PnWatchdogExpiries,
1032
1154
  };
1033
1155
 
1034
1156
  struct Observation
@@ -1059,6 +1181,7 @@ Sample(Observation* o)
1059
1181
  break;
1060
1182
  case Kind::Latency:
1061
1183
  case Kind::ModbusLatency:
1184
+ case Kind::PnLatency:
1062
1185
  a = o->window.sum;
1063
1186
  b = o->window.count;
1064
1187
  o->window = Window();
@@ -1078,6 +1201,14 @@ Sample(Observation* o)
1078
1201
  case Kind::BrokerQueue:
1079
1202
  a = o->host->waiting;
1080
1203
  break;
1204
+ case Kind::PnJitter:
1205
+ a = o->window.max;
1206
+ b = o->window.count;
1207
+ o->window = Window();
1208
+ break;
1209
+ case Kind::PnWatchdogExpiries:
1210
+ a = o->host->pn.expiries;
1211
+ break;
1081
1212
  }
1082
1213
  *o->out << o->index << ' ' << now << ' ' << a << ' ' << b << '\n';
1083
1214
  uint64_t next = o->ticks.Next();
@@ -1213,7 +1344,8 @@ Run(std::istream& in, std::ostream& out)
1213
1344
  switches[switchOf[sw]].table[MacKey(Mac48Address(mac.c_str()))] = port;
1214
1345
  }
1215
1346
  else if (word == "flow" || word == "sends" || word == "sink" || word == "connect" ||
1216
- word == "poll" || word == "publish" || word == "route" || word == "observe")
1347
+ word == "poll" || word == "publish" || word == "route" || word == "ar" ||
1348
+ word == "observe")
1217
1349
  {
1218
1350
  break; // the network is complete: IPv4 and neighbour caches come first
1219
1351
  }
@@ -1262,6 +1394,14 @@ Run(std::istream& in, std::ostream& out)
1262
1394
  }
1263
1395
 
1264
1396
  std::vector<Host> hosts(nodes.GetN());
1397
+ for (uint32_t i = 0; i < nodes.GetN(); ++i)
1398
+ {
1399
+ if (portOf[i])
1400
+ {
1401
+ portOf[i]->pn = &hosts[i].pn;
1402
+ }
1403
+ }
1404
+ std::vector<std::unique_ptr<PnProvider>> providers;
1265
1405
  std::vector<std::unique_ptr<Connection>> connections;
1266
1406
  std::map<std::pair<uint32_t, uint16_t>, std::unique_ptr<Listener>> listeners;
1267
1407
  std::vector<std::unique_ptr<Periodic>> periodics;
@@ -1335,6 +1475,43 @@ Run(std::istream& in, std::ostream& out)
1335
1475
  Periodic{connection(c), message, Instants(delayNs, num, den), durationNs}));
1336
1476
  periodics.back()->Next();
1337
1477
  }
1478
+ else if (word == "ar")
1479
+ {
1480
+ uint32_t controller;
1481
+ uint32_t device;
1482
+ int32_t ar;
1483
+ uint64_t cycleNs;
1484
+ uint64_t hold;
1485
+ uint64_t delayNs;
1486
+ uint64_t outputs;
1487
+ uint64_t inputs;
1488
+ s >> controller >> device >> ar >> cycleNs >> hold >> delayNs >> outputs >> inputs;
1489
+ if (!s || controller >= nodes.GetN() || device >= nodes.GetN() || !portOf[controller] ||
1490
+ !portOf[device] || cycleNs == 0)
1491
+ {
1492
+ Fail("bad ar: " + line);
1493
+ }
1494
+ hosts[controller].pn.Expect(ar, cycleNs, hold); // inputs
1495
+ hosts[device].pn.Expect(ar, cycleNs, hold); // outputs
1496
+ // the controller's provider first, as on the reference engine
1497
+ uint32_t from[2] = {controller, device};
1498
+ uint64_t bytes[2] = {outputs, inputs};
1499
+ for (int i = 0; i < 2; ++i)
1500
+ {
1501
+ providers.push_back(std::make_unique<PnProvider>(PnProvider{portOf[from[i]],
1502
+ macs[from[1 - i]],
1503
+ ar,
1504
+ bytes[i],
1505
+ cycleNs,
1506
+ durationNs}));
1507
+ if (delayNs < durationNs)
1508
+ {
1509
+ Simulator::Schedule(NanoSeconds(delayNs),
1510
+ &PnProvider::Fire,
1511
+ providers.back().get());
1512
+ }
1513
+ }
1514
+ }
1338
1515
  else if (word == "route")
1339
1516
  {
1340
1517
  uint32_t broker;
@@ -1454,6 +1631,21 @@ Run(std::istream& in, std::ostream& out)
1454
1631
  o->kind = Kind::BrokerQueue;
1455
1632
  o->host = &hosts.at(target);
1456
1633
  }
1634
+ else if (kind == "pn_latency")
1635
+ {
1636
+ o->kind = Kind::PnLatency;
1637
+ hosts.at(target).pn.latencyWindows.push_back(&o->window);
1638
+ }
1639
+ else if (kind == "pn_jitter")
1640
+ {
1641
+ o->kind = Kind::PnJitter;
1642
+ hosts.at(target).pn.jitterWindows.push_back(&o->window);
1643
+ }
1644
+ else if (kind == "pn_watchdog_expiries")
1645
+ {
1646
+ o->kind = Kind::PnWatchdogExpiries;
1647
+ o->host = &hosts.at(target);
1648
+ }
1457
1649
  else
1458
1650
  {
1459
1651
  Fail("unknown observation: " + line);
@@ -181,27 +181,41 @@ def fake_ns3(monkeypatch):
181
181
  monkeypatch.setattr(ns3, "locate", lambda: None)
182
182
 
183
183
 
184
- def test_profinet_is_outside_its_capabilities(fake_ns3) -> None:
185
- net = Network("prio")
184
+ def test_it_runs_the_whole_model(fake_ns3) -> None:
185
+ """Every node, traffic kind, pattern and metric of the reference engine;
186
+ headless only."""
187
+ ns3_caps = backends.REGISTRY["ns3"].capabilities()
188
+ simpy_caps = backends.REGISTRY["simpy"].capabilities()
189
+ for field in ("nodes", "traffic", "patterns", "metrics", "features"):
190
+ assert getattr(ns3_caps, field) == getattr(simpy_caps, field), field
191
+ assert ns3_caps.priorities and not ns3_caps.dashboards and not ns3_caps.notes
192
+
193
+
194
+ def test_lowering_profinet() -> None:
195
+ """ARs by controller in node order, as the reference engine starts them;
196
+ frames sized by the model, 802.1Q tag and padding included. An AR with
197
+ an unwired side exchanges nothing."""
198
+ net = Network("pn")
186
199
  sw = net.switch("sw", ports=4)
187
- a = net.adapter("a", ip="10.0.0.1")
188
- b = net.adapter("b", ip="10.0.0.2")
189
- net.link(a, sw, speed=100, length=1)
190
- net.link(b, sw, speed=100, length=1)
191
- a.sends(b, rate=100, size="imix", pattern="bursty", priority=3)
192
- slave = net.modbus_slave("m", ip="10.0.0.3", unit_id=1)
193
- broker = net.mqtt_broker("mq", ip="10.0.0.4")
194
- net.link(slave, sw, speed=100, length=1)
195
- net.link(broker, sw, speed=100, length=1)
196
- a.polls(slave, register=0, count=2)
197
- a.publishes(broker, topic="t", qos=1)
198
- broker.routes("t", to=[b])
199
- for metric in ("modbus_latency", "broker_queue"):
200
- net.observe(metric, on=broker if metric == "broker_queue" else a, every=1)
201
- backends.check(net.to_scenario(duration=10), "ns3") # Ethernet, Modbus and MQTT
202
- net.profinet_device("io", ip="10.0.0.5")
203
- with pytest.raises(ScenarioError, match="PROFINET device \\(planned for Phase 6\\)"):
204
- backends.check(net.to_scenario(duration=10), "ns3")
200
+ drive = net.profinet_device("drive", ip="10.0.1.1")
201
+ robot = net.adapter("robot", ip="10.0.0.2")
202
+ plc = net.adapter("plc", ip="10.0.0.1")
203
+ spare = net.profinet_device("spare", ip="10.0.1.9") # no link
204
+ for node in (drive, robot, plc):
205
+ net.link(node, sw, speed=100, length=0)
206
+ plc.controls(drive, cycle=4, inputs=100, outputs=8, hold=2, delay_ms=0.25)
207
+ robot.controls(drive, cycle=1, inputs=200, outputs=40)
208
+ plc.controls(spare, cycle=2, inputs=8, outputs=8)
209
+ net.observe("pn_jitter", on=drive, every=4)
210
+ net.observe("pn_watchdog_expiries", on=spare, every=4) # samples 0, as on SimPy
211
+ text, samplers = ns3.lower(net.to_scenario(duration=10))
212
+ assert [line for line in text.splitlines() if line.startswith(("ar", "observe"))] == [
213
+ "ar 2 1 0 1000000 3 0 68 228", # robot's first: robot comes first in node order
214
+ "ar 3 1 1 4000000 2 250000 64 128", # 8 B of outputs: padded to 64 B
215
+ "observe pn_jitter 1 4000000 1",
216
+ "observe pn_watchdog_expiries 4 4000000 1",
217
+ ]
218
+ assert [s.metric for s in samplers] == ["pn_jitter", "pn_watchdog_expiries"]
205
219
 
206
220
 
207
221
  def test_priorities_can_be_outside_a_backends_capabilities(monkeypatch) -> None:
@@ -224,7 +238,7 @@ def test_priorities_can_be_outside_a_backends_capabilities(monkeypatch) -> None:
224
238
  backends.check(net.to_scenario(duration=10), "ns3")
225
239
 
226
240
 
227
- # --- Modbus and MQTT over ns-3's TCP ---
241
+ # --- on ns-3 ---
228
242
 
229
243
  needs_ns3 = pytest.mark.skipif(
230
244
  not backends.REGISTRY["ns3"].available(), reason="NS3_HOME names no ns-3 build"
@@ -317,3 +331,23 @@ def test_mqtt_over_tcp(qos: int) -> None:
317
331
  message = _bytes(simpy["bytes_received:hmi"])[1]
318
332
  assert _bytes(ns3["bytes_received:hmi"]) == [SYN_ACK + message * k for k in range(5)]
319
333
  assert _values(ns3["broker_queue:broker"]) == [0.0] * 5
334
+
335
+
336
+ @needs_ns3
337
+ @pytest.mark.parametrize("length", [0, 100])
338
+ def test_a_frame_at_the_watchdogs_deadline_is_too_late(length: float) -> None:
339
+ """With a hold of one cycle and no jitter, every frame arrives exactly at
340
+ the deadline, which comes first, as on SimPy: one expiry per cycle."""
341
+ net = Network("deadline")
342
+ sw = net.switch("sw", ports=2)
343
+ plc = net.adapter("plc", ip="10.0.0.1")
344
+ io = net.profinet_device("io", ip="10.0.0.2")
345
+ net.link(plc, sw, speed=100, length=length)
346
+ net.link(io, sw, speed=100, length=length)
347
+ plc.controls(io, cycle=1, inputs=10, outputs=10, hold=1)
348
+ net.observe("pn_watchdog_expiries", on=io, every=5)
349
+ net.observe("pn_jitter", on=io, every=5)
350
+ simpy, ns3 = _run(net, 20)
351
+ assert ns3 == simpy
352
+ assert _values(ns3["pn_watchdog_expiries:io"]) == [4.0, 9.0, 14.0] # from the 2nd frame
353
+ assert set(_values(ns3["pn_jitter:io"])) == {0.0}
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes