smolpy 1.8.2.dev2__tar.gz → 1.8.2.dev6__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 (135) hide show
  1. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/PKG-INFO +15 -4
  2. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/README.md +14 -3
  3. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/dsl-reference.md +2 -2
  4. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/roadmap.md +6 -0
  5. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smol-engine/src/frames.rs +20 -0
  6. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smol-engine/src/scenario.rs +69 -16
  7. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smol-engine/src/sim.rs +186 -16
  8. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smolpy-engine-rs/README.md +2 -1
  9. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/equivalence/scenarios.py +34 -0
  10. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/.github/workflows/ci.yml +0 -0
  11. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/.github/workflows/dev-build.yml +0 -0
  12. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/.github/workflows/docs.yml +0 -0
  13. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/.github/workflows/github-release.yml +0 -0
  14. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/.github/workflows/publish.yml +0 -0
  15. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/.github/workflows/release.yml +0 -0
  16. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/.github/workflows/rust-wheels.yml +0 -0
  17. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/.gitignore +0 -0
  18. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/LICENSE +0 -0
  19. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/__init__.py +0 -0
  20. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/__main__.py +0 -0
  21. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/results/2026-11-13-0921-simpy-jaws-zbook-baseline.json +0 -0
  22. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/results/2026-11-13-1527-simpy-jaws-zbook-optimised.json +0 -0
  23. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/results/2026-11-13-2116-simpy-jaws-zbook-research-batch.json +0 -0
  24. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/results/2026-11-13-2119-simpy-jaws-zbook-research-b4.json +0 -0
  25. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/results/2026-11-15-1255-rust-jaws-zbook-stop-criterion.json +0 -0
  26. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/results/2026-11-15-1333-rust-jaws-zbook-research-b4.json +0 -0
  27. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/results/2026-11-15-1346-rust-jaws-zbook-research-batch.json +0 -0
  28. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/runner.py +0 -0
  29. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/scenarios.py +0 -0
  30. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/benchmarks/worker.py +0 -0
  31. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/adr/0001-protocol-package-structure.md +0 -0
  32. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/adr/0002-modbus-tcp-implementation.md +0 -0
  33. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/adr/0003-smol-external-dsl.md +0 -0
  34. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/adr/0004-execution-backends.md +0 -0
  35. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/adr/0005-profinet-rt.md +0 -0
  36. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/adr/0006-profiling-and-baseline-benchmark.md +0 -0
  37. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/adr/0007-execution-independent-scenario-model.md +0 -0
  38. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/adr/0008-rust-des-engine-mvp.md +0 -0
  39. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/adr/0009-batch-execution-and-cross-backend-validation.md +0 -0
  40. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/adr/0010-ethernet-frames-on-the-wire.md +0 -0
  41. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/benchmarks.md +0 -0
  42. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/dashboard.md +0 -0
  43. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/examples.md +0 -0
  44. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/index.md +0 -0
  45. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/language-reference.md +0 -0
  46. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/modbus.md +0 -0
  47. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/model-semantics.md +0 -0
  48. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/mqtt.md +0 -0
  49. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/profinet.md +0 -0
  50. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/scenario-model.md +0 -0
  51. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/docs/simulation-engine.md +0 -0
  52. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/README.md +0 -0
  53. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example.py +0 -0
  54. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example.smol +0 -0
  55. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example_10_clients.py +0 -0
  56. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example_12_clients.py +0 -0
  57. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example_20_clients.py +0 -0
  58. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example_file_transfer.py +0 -0
  59. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example_modbus.py +0 -0
  60. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example_mqtt.py +0 -0
  61. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example_profinet.py +0 -0
  62. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example_profinet.smol +0 -0
  63. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example_staggered_transfer.py +0 -0
  64. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/examples/example_two_tier.py +0 -0
  65. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/mkdocs.yml +0 -0
  66. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/pyproject.toml +0 -0
  67. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/Cargo.lock +0 -0
  68. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/Cargo.toml +0 -0
  69. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smol-engine/Cargo.toml +0 -0
  70. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smol-engine/src/lib.rs +0 -0
  71. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smol-engine/src/rng.rs +0 -0
  72. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smol-engine/src/timebase.rs +0 -0
  73. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smolpy-engine-rs/Cargo.toml +0 -0
  74. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smolpy-engine-rs/pyproject.toml +0 -0
  75. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smolpy-engine-rs/smoke_test.py +0 -0
  76. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/rust/smolpy-engine-rs/src/lib.rs +0 -0
  77. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/__init__.py +0 -0
  78. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/_worker.py +0 -0
  79. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/backends.py +0 -0
  80. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/batch.py +0 -0
  81. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/cli.py +0 -0
  82. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/core/__init__.py +0 -0
  83. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/core/adapter.py +0 -0
  84. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/core/batch.py +0 -0
  85. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/core/link.py +0 -0
  86. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/core/network.py +0 -0
  87. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/core/node.py +0 -0
  88. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/core/observation.py +0 -0
  89. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/ethernet/__init__.py +0 -0
  90. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/ethernet/switch.py +0 -0
  91. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/lang/__init__.py +0 -0
  92. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/lang/ast.py +0 -0
  93. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/lang/errors.py +0 -0
  94. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/lang/grammar.lark +0 -0
  95. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/lang/interpreter.py +0 -0
  96. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/lang/transformer.py +0 -0
  97. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/modbus/__init__.py +0 -0
  98. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/modbus/slave.py +0 -0
  99. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/model/__init__.py +0 -0
  100. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/model/frames.py +0 -0
  101. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/model/scenario.py +0 -0
  102. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/model/streams.py +0 -0
  103. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/model/timebase.py +0 -0
  104. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/model/validate.py +0 -0
  105. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/mqtt/__init__.py +0 -0
  106. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/mqtt/broker.py +0 -0
  107. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/profinet/__init__.py +0 -0
  108. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/profinet/device.py +0 -0
  109. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/sim/__init__.py +0 -0
  110. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/sim/engine.py +0 -0
  111. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/stats.py +0 -0
  112. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/viz/__init__.py +0 -0
  113. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/viz/dashboard.py +0 -0
  114. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/src/smolpy/viz/text_dashboard.py +0 -0
  115. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/__init__.py +0 -0
  116. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/equivalence/__init__.py +0 -0
  117. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/equivalence/harness.py +0 -0
  118. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/equivalence/test_equivalence.py +0 -0
  119. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/equivalence/test_rust_timebase.py +0 -0
  120. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_backends.py +0 -0
  121. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_batch.py +0 -0
  122. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_benchmarks.py +0 -0
  123. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_cli.py +0 -0
  124. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_dsl.py +0 -0
  125. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_engine_ir.py +0 -0
  126. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_lang.py +0 -0
  127. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_model.py +0 -0
  128. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_profinet.py +0 -0
  129. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_semantics.py +0 -0
  130. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_simulation.py +0 -0
  131. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_stats.py +0 -0
  132. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_sweep.py +0 -0
  133. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_timebase.py +0 -0
  134. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/tests/test_validate.py +0 -0
  135. {smolpy-1.8.2.dev2 → smolpy-1.8.2.dev6}/uv.lock +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: smolpy
3
- Version: 1.8.2.dev2
3
+ Version: 1.8.2.dev6
4
4
  Summary: Network simulation DSL and discrete-event simulator
5
5
  License: MIT
6
6
  License-File: LICENSE
@@ -30,6 +30,7 @@ Description-Content-Type: text/markdown
30
30
 
31
31
  [![CI](https://github.com/jwszolek/SMOLPy/actions/workflows/ci.yml/badge.svg)](https://github.com/jwszolek/SMOLPy/actions/workflows/ci.yml)
32
32
  [![PyPI version](https://img.shields.io/pypi/v/smolpy)](https://pypi.org/project/smolpy/)
33
+ [![Dev build](https://img.shields.io/github/v/release/jwszolek/SMOLPy?include_prereleases&filter=Development%2A&display_name=release&label=main)](https://github.com/jwszolek/SMOLPy/releases/tag/dev)
33
34
  [![Python](https://img.shields.io/pypi/pyversions/smolpy)](https://pypi.org/project/smolpy/)
34
35
  [![License](https://img.shields.io/github/license/jwszolek/SMOLPy)](LICENSE)
35
36
  [![Docs](https://img.shields.io/badge/docs-mkdocs--material-blue)](https://jwszolek.github.io/SMOLPy/)
@@ -47,7 +48,7 @@ SMOLPy lets you describe a network topology in pure Python, define traffic flows
47
48
  > result = net.simulate(duration=60_000, backend="rust")
48
49
  > ```
49
50
  >
50
- > The Rust engine covers Ethernet for now: adapters, switches, links and flows. MQTT, Modbus TCP and PROFINET follow. See [Simulation engine](#simulation-engine) and [ADR-0008](https://jwszolek.github.io/SMOLPy/adr/0008-rust-des-engine-mvp/).
51
+ > The Rust engine covers Ethernet and Modbus TCP for now: adapters, switches, links, flows and Modbus polling. MQTT and PROFINET follow. See [Simulation engine](#simulation-engine) and [ADR-0008](https://jwszolek.github.io/SMOLPy/adr/0008-rust-des-engine-mvp/).
51
52
 
52
53
  📖 **Full documentation:** [jwszolek.github.io/SMOLPy](https://jwszolek.github.io/SMOLPy/)
53
54
 
@@ -76,7 +77,17 @@ pip install "smolpy[rust]" # plus the native Rust engine, about 40x faster
76
77
  pip install --pre "smolpy[rust]" # the latest development build of main
77
78
  ```
78
79
 
79
- Every merge to `main` that changes the package publishes a **development build**, `X.Y.(Z+1).devN` (N commits after the latest release). It is a pre-release on PyPI, so `pip` installs it only with `--pre`, and the GitHub pre-release [Development build](https://github.com/jwszolek/SMOLPy/releases/tag/dev) points to its commit. Releases proper are made by hand.
80
+ **Release channels.** The versions below are read live from PyPI and GitHub, so this table is always current:
81
+
82
+ | Channel | smolpy | smolpy-engine-rs | Install |
83
+ |---|---|---|---|
84
+ | **Stable**, released by hand | [![smolpy](https://img.shields.io/pypi/v/smolpy?label=)](https://pypi.org/project/smolpy/) | [![smolpy-engine-rs](https://img.shields.io/pypi/v/smolpy-engine-rs?label=)](https://pypi.org/project/smolpy-engine-rs/) | `pip install "smolpy[rust]"` |
85
+ | **Development**, every merge to `main` | [![dev](https://img.shields.io/github/v/release/jwszolek/SMOLPy?include_prereleases&filter=Development%2A&display_name=release&label=)](https://github.com/jwszolek/SMOLPy/releases/tag/dev) | same version | `pip install --pre "smolpy[rust]"` |
86
+
87
+ - **What a development build is.** Every merge to `main` that changes the package publishes one, as `X.Y.(Z+1).devN`, N commits after the latest release.
88
+ - **How to get it.** It is a pre-release on PyPI, so `pip` installs it only with `--pre`.
89
+ - **Where it is on GitHub.** The [Development build](https://github.com/jwszolek/SMOLPy/releases/tag/dev) pre-release points to its commit.
90
+ - **Releases proper** are made by hand.
80
91
 
81
92
  From a clone, for development:
82
93
 
@@ -460,7 +471,7 @@ Every simulation goes through the same path. The Python API and `.smol` files bu
460
471
  | Backend | Language | What it runs | Speed | Install |
461
472
  |---|---|---|---|---|
462
473
  | `simpy` (default) | Python, SimPy | the whole model, the live and text dashboards | reference | included |
463
- | `rust` | Rust, through PyO3 | Ethernet: adapters, switches, links, flows (constant, Poisson, bursty, batch, IMIX), six metrics | about **40× faster**: B1 at 10 M frames in 4.9 s, not 200.8 s | `pip install smolpy[rust]` (since v1.8.0) |
474
+ | `rust` | Rust, through PyO3 | Ethernet: adapters, switches, links, flows (constant, Poisson, bursty, batch, IMIX); Modbus TCP polling; seven metrics | about **40× faster**: B1 at 10 M frames in 4.9 s, not 200.8 s | `pip install smolpy[rust]` (since v1.8.0) |
464
475
 
465
476
  ```python
466
477
  result = net.simulate(duration=60_000, backend="rust") # one run
@@ -2,6 +2,7 @@
2
2
 
3
3
  [![CI](https://github.com/jwszolek/SMOLPy/actions/workflows/ci.yml/badge.svg)](https://github.com/jwszolek/SMOLPy/actions/workflows/ci.yml)
4
4
  [![PyPI version](https://img.shields.io/pypi/v/smolpy)](https://pypi.org/project/smolpy/)
5
+ [![Dev build](https://img.shields.io/github/v/release/jwszolek/SMOLPy?include_prereleases&filter=Development%2A&display_name=release&label=main)](https://github.com/jwszolek/SMOLPy/releases/tag/dev)
5
6
  [![Python](https://img.shields.io/pypi/pyversions/smolpy)](https://pypi.org/project/smolpy/)
6
7
  [![License](https://img.shields.io/github/license/jwszolek/SMOLPy)](LICENSE)
7
8
  [![Docs](https://img.shields.io/badge/docs-mkdocs--material-blue)](https://jwszolek.github.io/SMOLPy/)
@@ -19,7 +20,7 @@ SMOLPy lets you describe a network topology in pure Python, define traffic flows
19
20
  > result = net.simulate(duration=60_000, backend="rust")
20
21
  > ```
21
22
  >
22
- > The Rust engine covers Ethernet for now: adapters, switches, links and flows. MQTT, Modbus TCP and PROFINET follow. See [Simulation engine](#simulation-engine) and [ADR-0008](https://jwszolek.github.io/SMOLPy/adr/0008-rust-des-engine-mvp/).
23
+ > The Rust engine covers Ethernet and Modbus TCP for now: adapters, switches, links, flows and Modbus polling. MQTT and PROFINET follow. See [Simulation engine](#simulation-engine) and [ADR-0008](https://jwszolek.github.io/SMOLPy/adr/0008-rust-des-engine-mvp/).
23
24
 
24
25
  📖 **Full documentation:** [jwszolek.github.io/SMOLPy](https://jwszolek.github.io/SMOLPy/)
25
26
 
@@ -48,7 +49,17 @@ pip install "smolpy[rust]" # plus the native Rust engine, about 40x faster
48
49
  pip install --pre "smolpy[rust]" # the latest development build of main
49
50
  ```
50
51
 
51
- Every merge to `main` that changes the package publishes a **development build**, `X.Y.(Z+1).devN` (N commits after the latest release). It is a pre-release on PyPI, so `pip` installs it only with `--pre`, and the GitHub pre-release [Development build](https://github.com/jwszolek/SMOLPy/releases/tag/dev) points to its commit. Releases proper are made by hand.
52
+ **Release channels.** The versions below are read live from PyPI and GitHub, so this table is always current:
53
+
54
+ | Channel | smolpy | smolpy-engine-rs | Install |
55
+ |---|---|---|---|
56
+ | **Stable**, released by hand | [![smolpy](https://img.shields.io/pypi/v/smolpy?label=)](https://pypi.org/project/smolpy/) | [![smolpy-engine-rs](https://img.shields.io/pypi/v/smolpy-engine-rs?label=)](https://pypi.org/project/smolpy-engine-rs/) | `pip install "smolpy[rust]"` |
57
+ | **Development**, every merge to `main` | [![dev](https://img.shields.io/github/v/release/jwszolek/SMOLPy?include_prereleases&filter=Development%2A&display_name=release&label=)](https://github.com/jwszolek/SMOLPy/releases/tag/dev) | same version | `pip install --pre "smolpy[rust]"` |
58
+
59
+ - **What a development build is.** Every merge to `main` that changes the package publishes one, as `X.Y.(Z+1).devN`, N commits after the latest release.
60
+ - **How to get it.** It is a pre-release on PyPI, so `pip` installs it only with `--pre`.
61
+ - **Where it is on GitHub.** The [Development build](https://github.com/jwszolek/SMOLPy/releases/tag/dev) pre-release points to its commit.
62
+ - **Releases proper** are made by hand.
52
63
 
53
64
  From a clone, for development:
54
65
 
@@ -432,7 +443,7 @@ Every simulation goes through the same path. The Python API and `.smol` files bu
432
443
  | Backend | Language | What it runs | Speed | Install |
433
444
  |---|---|---|---|---|
434
445
  | `simpy` (default) | Python, SimPy | the whole model, the live and text dashboards | reference | included |
435
- | `rust` | Rust, through PyO3 | Ethernet: adapters, switches, links, flows (constant, Poisson, bursty, batch, IMIX), six metrics | about **40× faster**: B1 at 10 M frames in 4.9 s, not 200.8 s | `pip install smolpy[rust]` (since v1.8.0) |
446
+ | `rust` | Rust, through PyO3 | Ethernet: adapters, switches, links, flows (constant, Poisson, bursty, batch, IMIX); Modbus TCP polling; seven metrics | about **40× faster**: B1 at 10 M frames in 4.9 s, not 200.8 s | `pip install smolpy[rust]` (since v1.8.0) |
436
447
 
437
448
  ```python
438
449
  result = net.simulate(duration=60_000, backend="rust") # one run
@@ -170,9 +170,9 @@ result.export("out.csv", format="csv") # explicit format override
170
170
  - **A missing backend is an error.** When a backend is not installed, selecting it raises `BackendUnavailable` with the install command.
171
171
  - **`smolpy.backends.installed()`** lists the backends that can run here.
172
172
 
173
- **The Rust backend so far** runs adapters, switches (`strict` and `fifo` QoS, `learning` and `topology` MAC tables), links and flows with every pattern (`constant`, `poisson`, `bursty`, `batch`) and with fixed or IMIX sizes. It covers the metrics `throughput`, `latency`, `bytes_sent`, `bytes_received`, `queue_depth` and `utilization`.
173
+ **The Rust backend so far** runs adapters, switches (`strict` and `fifo` QoS, `learning` and `topology` MAC tables), links and flows with every pattern (`constant`, `poisson`, `bursty`, `batch`) and with fixed or IMIX sizes. It also runs Modbus TCP: slaves, `polls()` and `modbus_latency`. It covers the metrics `throughput`, `latency`, `bytes_sent`, `bytes_received`, `queue_depth`, `utilization` and `modbus_latency`.
174
174
  - **Same results as SimPy.** Deterministic scenarios give SimPy's results bit for bit. Random traffic uses the same streams and distributions with the engine's own generator, so there the results agree statistically.
175
- - **Not in it yet.** MQTT, Modbus and PROFINET come in Phase 5 of the [roadmap](roadmap.md).
175
+ - **Not in it yet.** MQTT and PROFINET come in Phase 5 of the [roadmap](roadmap.md).
176
176
  - **Install** it with `pip install smolpy[rust]`, or `pip install smolpy-engine-rs` next to an installed `smolpy`. It is released together with `smolpy`, with the same version, since v1.8.0. Wheels exist for Linux x86_64 and aarch64, macOS arm64 and x86_64, and Windows x86_64. To build it from the repository instead, with a Rust toolchain:
177
177
 
178
178
  ```bash
@@ -153,6 +153,12 @@ Modbus TCP, MQTT and PROFINET RT in the Rust engine. These need no new architect
153
153
 
154
154
  **Exit criteria:** the Rust backend's capabilities equal SimPy's, apart from the live dashboard.
155
155
 
156
+ **Status:** one of three protocols done.
157
+ - **Modbus TCP: done.**
158
+ - The Rust engine runs slaves, `polls()` and `modbus_latency`. It reproduces SimPy's poll generator and slave process, including requests flooded to other slaves and dropped there.
159
+ - The new `polling` scenario is bit-exact with SimPy, down to the event count.
160
+ - **MQTT and PROFINET RT** are next. PROFINET's watchdog waits on "a frame or a timeout", a SimPy condition whose event ordering the engine has to reproduce.
161
+
156
162
  ## Phase 6: ns-3 high-fidelity backend ([ADR-0004](adr/0004-execution-backends.md), revised)
157
163
 
158
164
  A code-generated ns-3 scenario from the Scenario IR. Gives a realistic TCP/IP stack for Modbus and MQTT.
@@ -10,6 +10,22 @@ pub const PREAMBLE_SFD_BYTES: u64 = 8;
10
10
  pub const IFG_BYTES: u64 = 12;
11
11
  pub const WIRE_OVERHEAD_BYTES: u64 = PREAMBLE_SFD_BYTES + IFG_BYTES;
12
12
 
13
+ pub const MIN_FRAME_BYTES: u64 = 64;
14
+ /// Ethernet header (14), IPv4 (20), TCP (20) and FCS (4).
15
+ pub const ETHERNET_IP_TCP_BYTES: u64 = 14 + 20 + 20 + 4;
16
+ /// Modbus TCP Read Holding Registers request: MBAP (6), FC, address, quantity.
17
+ pub const MODBUS_REQUEST_BYTES: u64 = ETHERNET_IP_TCP_BYTES + 6 + 1 + 2 + 2;
18
+
19
+ /// A frame padded to the 64 B Ethernet minimum.
20
+ pub fn padded(bytes: u64) -> u64 {
21
+ bytes.max(MIN_FRAME_BYTES)
22
+ }
23
+
24
+ /// Read Holding Registers response: MBAP (6), FC (1), byte count (1), 2 B per register.
25
+ pub fn modbus_response_frame_size(count: u16) -> u64 {
26
+ padded(ETHERNET_IP_TCP_BYTES + 6 + 1 + 1 + 2 * count as u64)
27
+ }
28
+
13
29
  /// A flow frame of `size` bytes (untagged, FCS included), with the tag a
14
30
  /// priority above 0 needs.
15
31
  pub fn flow_frame_size(size: u64, priority: u8) -> u64 {
@@ -25,5 +41,9 @@ mod tests {
25
41
  assert_eq!(flow_frame_size(100, 0), 100);
26
42
  assert_eq!(flow_frame_size(100, 3), 104);
27
43
  assert_eq!(WIRE_OVERHEAD_BYTES, 20);
44
+ // the values of tests/test_semantics.py::test_frame_sizes
45
+ assert_eq!(MODBUS_REQUEST_BYTES, 69);
46
+ assert_eq!(modbus_response_frame_size(10), 86);
47
+ assert_eq!(modbus_response_frame_size(1), 68);
28
48
  }
29
49
  }
@@ -15,6 +15,7 @@ pub const VERSION: u64 = 2;
15
15
  #[derive(Debug, Clone)]
16
16
  pub enum NodeKind {
17
17
  Adapter { mac: String },
18
+ ModbusSlave { mac: String, unit: u8 },
18
19
  Switch { fifo: bool, topology: bool },
19
20
  }
20
21
 
@@ -58,6 +59,16 @@ pub struct Flow {
58
59
  pub priority: u8,
59
60
  }
60
61
 
62
+ /// Modbus TCP polling (FC 03): `count` registers at `rate` polls per second.
63
+ #[derive(Debug, Clone)]
64
+ pub struct Poll {
65
+ pub source: String,
66
+ pub slave: String,
67
+ pub count: u16,
68
+ pub rate: Q,
69
+ pub delay_ms: Q,
70
+ }
71
+
61
72
  #[derive(Debug, Clone, Copy, PartialEq, Eq)]
62
73
  pub enum Metric {
63
74
  Throughput,
@@ -66,16 +77,18 @@ pub enum Metric {
66
77
  BytesReceived,
67
78
  QueueDepth,
68
79
  Utilization,
80
+ ModbusLatency,
69
81
  }
70
82
 
71
83
  impl Metric {
72
- pub const ALL: [(&'static str, Metric); 6] = [
84
+ pub const ALL: [(&'static str, Metric); 7] = [
73
85
  ("throughput", Metric::Throughput),
74
86
  ("latency", Metric::Latency),
75
87
  ("bytes_sent", Metric::BytesSent),
76
88
  ("bytes_received", Metric::BytesReceived),
77
89
  ("queue_depth", Metric::QueueDepth),
78
90
  ("utilization", Metric::Utilization),
91
+ ("modbus_latency", Metric::ModbusLatency),
79
92
  ];
80
93
 
81
94
  pub fn name(self) -> &'static str {
@@ -96,6 +109,7 @@ pub struct Scenario {
96
109
  pub nodes: Vec<Node>,
97
110
  pub links: Vec<Link>,
98
111
  pub flows: Vec<Flow>,
112
+ pub polls: Vec<Poll>,
99
113
  pub observations: Vec<Observation>,
100
114
  pub duration_ms: Q,
101
115
  pub seed: u64,
@@ -112,8 +126,8 @@ pub struct Capabilities {
112
126
  }
113
127
 
114
128
  pub const CAPABILITIES: Capabilities = Capabilities {
115
- nodes: &["adapter", "switch"],
116
- traffic: &["flow"],
129
+ nodes: &["adapter", "switch", "modbus_slave"],
130
+ traffic: &["flow", "poll"],
117
131
  patterns: &["constant", "poisson", "bursty", "batch"],
118
132
  metrics: &[
119
133
  "throughput",
@@ -122,15 +136,14 @@ pub const CAPABILITIES: Capabilities = Capabilities {
122
136
  "bytes_received",
123
137
  "queue_depth",
124
138
  "utilization",
139
+ "modbus_latency",
125
140
  ],
126
141
  features: &["imix"],
127
142
  notes: &[
128
143
  ("mqtt_broker", "planned for Phase 5"),
129
- ("modbus_slave", "planned for Phase 5"),
130
144
  ("profinet_device", "planned for Phase 5"),
131
145
  ("publish", "planned for Phase 5"),
132
146
  ("route", "planned for Phase 5"),
133
- ("poll", "planned for Phase 5"),
134
147
  ("profinet_ar", "planned for Phase 5"),
135
148
  ],
136
149
  };
@@ -256,12 +269,15 @@ pub fn parse(text: &str) -> Res<Scenario> {
256
269
  f.done()?;
257
270
  links.push(link);
258
271
  }
259
- let mut flows = Vec::new();
272
+ let (mut flows, mut polls) = (Vec::new(), Vec::new());
260
273
  for (i, v) in array(top.take_or("traffic"), "traffic")?
261
274
  .into_iter()
262
275
  .enumerate()
263
276
  {
264
- flows.push(parse_traffic(v, i)?);
277
+ match parse_traffic(v, i)? {
278
+ Traffic::Flow(flow) => flows.push(flow),
279
+ Traffic::Poll(poll) => polls.push(poll),
280
+ }
265
281
  }
266
282
  let mut observations = Vec::new();
267
283
  for (i, v) in array(top.take_or("observations"), "observations")?
@@ -305,6 +321,7 @@ pub fn parse(text: &str) -> Res<Scenario> {
305
321
  nodes,
306
322
  links,
307
323
  flows,
324
+ polls,
308
325
  observations,
309
326
  duration_ms,
310
327
  seed,
@@ -358,7 +375,15 @@ fn parse_node(value: Value, i: usize) -> Res<Node> {
358
375
  };
359
376
  NodeKind::Switch { fifo, topology }
360
377
  }
361
- "mqtt_broker" | "modbus_slave" | "profinet_device" => {
378
+ "modbus_slave" => {
379
+ f.string("ip")?;
380
+ let mac = f.string("mac")?;
381
+ let unit = f.integer("unit_id")?;
382
+ let unit =
383
+ u8::try_from(unit).map_err(|_| format!("modbus_slave {name}: unit_id {unit}"))?;
384
+ NodeKind::ModbusSlave { mac, unit }
385
+ }
386
+ "mqtt_broker" | "profinet_device" => {
362
387
  return Err(unsupported(&format!("{kind} nodes (Phase 5)")))
363
388
  }
364
389
  other => return Err(format!("unknown node kind {other:?}")),
@@ -367,17 +392,45 @@ fn parse_node(value: Value, i: usize) -> Res<Node> {
367
392
  Ok(Node { name, kind })
368
393
  }
369
394
 
370
- fn parse_traffic(value: Value, i: usize) -> Res<Flow> {
395
+ enum Traffic {
396
+ Flow(Flow),
397
+ Poll(Poll),
398
+ }
399
+
400
+ fn parse_traffic(value: Value, i: usize) -> Res<Traffic> {
371
401
  let mut f = Fields::new(value, format!("traffic {i}"))?;
372
402
  let kind = f.string("kind")?;
373
- if kind != "flow" {
374
- return match kind.as_str() {
375
- "publish" | "route" | "poll" | "profinet_ar" => {
376
- Err(unsupported(&format!("{kind} traffic (Phase 5)")))
377
- }
378
- other => Err(format!("unknown traffic kind {other:?}")),
379
- };
403
+ match kind.as_str() {
404
+ "flow" => parse_flow(f).map(Traffic::Flow),
405
+ "poll" => {
406
+ let source = f.string("source")?;
407
+ let slave = f.string("slave")?;
408
+ f.what = format!("poll {source} -> {slave}");
409
+ f.integer("register")?; // the register address does not change the frames
410
+ let count = f.integer("count")?;
411
+ let count = u16::try_from(count).map_err(|_| format!("poll: count {count}"))?;
412
+ let rate = f.number("rate")?;
413
+ let delay_ms = match f.take_or("delay_ms") {
414
+ None => Q::int(0),
415
+ Some(v) => number(&v, "poll: delay_ms")?,
416
+ };
417
+ f.done()?;
418
+ Ok(Traffic::Poll(Poll {
419
+ source,
420
+ slave,
421
+ count,
422
+ rate,
423
+ delay_ms,
424
+ }))
425
+ }
426
+ "publish" | "route" | "profinet_ar" => {
427
+ Err(unsupported(&format!("{kind} traffic (Phase 5)")))
428
+ }
429
+ other => Err(format!("unknown traffic kind {other:?}")),
380
430
  }
431
+ }
432
+
433
+ fn parse_flow(mut f: Fields<'_>) -> Res<Flow> {
381
434
  let source = f.string("source")?;
382
435
  let destination = f.string("destination")?;
383
436
  f.what = format!("flow {source} -> {destination}");
@@ -16,7 +16,10 @@
16
16
  //! processes in node order, then metric samplers in observation order;
17
17
  //! - the run stops before the first event at `t = duration`.
18
18
 
19
- use crate::frames::{flow_frame_size, IFG_BYTES, PREAMBLE_SFD_BYTES, WIRE_OVERHEAD_BYTES};
19
+ use crate::frames::{
20
+ flow_frame_size, modbus_response_frame_size, IFG_BYTES, MODBUS_REQUEST_BYTES,
21
+ PREAMBLE_SFD_BYTES, WIRE_OVERHEAD_BYTES,
22
+ };
20
23
  use crate::rng::{stream_seed, Rng};
21
24
  use crate::scenario::{Metric, NodeKind, Pattern, Scenario, Size};
22
25
  use crate::timebase::{self as tb, Instants, Q};
@@ -45,8 +48,23 @@ struct Frame {
45
48
  created: u64,
46
49
  priority: u8,
47
50
  in_port: i32,
51
+ modbus: Modbus,
48
52
  }
49
53
 
54
+ /// The Modbus TCP fields of a frame; `unit < 0` on any other frame.
55
+ #[derive(Clone, Copy)]
56
+ struct Modbus {
57
+ unit: i16,
58
+ count: u16,
59
+ response: bool,
60
+ }
61
+
62
+ const NOT_MODBUS: Modbus = Modbus {
63
+ unit: -1,
64
+ count: 0,
65
+ response: false,
66
+ };
67
+
50
68
  enum Items {
51
69
  Fifo(VecDeque<u32>),
52
70
  /// SimPy's PriorityStore of PriorityItem((class, sequence), frame)
@@ -96,6 +114,27 @@ struct Adapter {
96
114
  out: Option<u32>,
97
115
  bytes_received: u128,
98
116
  latency_windows: Vec<u32>,
117
+ modbus_windows: Vec<u32>, // round-trip times of Modbus responses
118
+ }
119
+
120
+ /// A Modbus TCP slave: answers Read Holding Registers for its unit id.
121
+ struct Slave {
122
+ mac: u32,
123
+ unit: u8,
124
+ inbound: u32,
125
+ out: Option<u32>,
126
+ }
127
+
128
+ /// A Modbus TCP master's polls of one slave, at constant instants.
129
+ struct PollGen {
130
+ src: u32,
131
+ dst: u32,
132
+ unit: u8,
133
+ count: u16,
134
+ chan: u32,
135
+ delay_ns: u64,
136
+ delayed: bool,
137
+ instants: Instants,
99
138
  }
100
139
 
101
140
  struct Switch {
@@ -158,6 +197,8 @@ enum Proc {
158
197
  Switch(u32),
159
198
  Flow(u32),
160
199
  Sampler(u32),
200
+ Slave(u32),
201
+ Poll(u32),
161
202
  }
162
203
 
163
204
  pub struct Outcome {
@@ -179,6 +220,8 @@ struct Engine {
179
220
  adapters: Vec<Adapter>,
180
221
  switches: Vec<Switch>,
181
222
  flows: Vec<FlowGen>,
223
+ slaves: Vec<Slave>,
224
+ polls: Vec<PollGen>,
182
225
  samplers: Vec<Sampler>,
183
226
  windows: Vec<Vec<u64>>,
184
227
  procs: Vec<Proc>,
@@ -293,6 +336,20 @@ impl Engine {
293
336
  let t = self.samplers[i as usize].ticks.next().unwrap();
294
337
  self.schedule(Ev::Timeout(proc), NORMAL, t - self.now);
295
338
  }
339
+ Proc::Slave(i) => {
340
+ let s = self.slaves[i as usize].inbound;
341
+ self.get(s, proc);
342
+ }
343
+ Proc::Poll(i) => {
344
+ let pg = &mut self.polls[i as usize];
345
+ let delay = if pg.delay_ns > 0 {
346
+ pg.delayed = true;
347
+ pg.delay_ns
348
+ } else {
349
+ pg.instants.next().unwrap() - self.now
350
+ };
351
+ self.schedule(Ev::Timeout(proc), NORMAL, delay);
352
+ }
296
353
  }
297
354
  }
298
355
 
@@ -324,6 +381,11 @@ impl Engine {
324
381
  for w in &ad.latency_windows {
325
382
  self.windows[*w as usize].push(self.now - fr.created);
326
383
  }
384
+ if fr.modbus.response {
385
+ for w in &ad.modbus_windows {
386
+ self.windows[*w as usize].push(self.now - fr.created);
387
+ }
388
+ }
327
389
  }
328
390
  self.release(f);
329
391
  self.get(store, proc);
@@ -353,7 +415,34 @@ impl Engine {
353
415
  }
354
416
  self.get(store, proc);
355
417
  }
356
- Proc::Flow(_) | Proc::Sampler(_) => unreachable!("these processes do not get"),
418
+ Proc::Slave(i) => {
419
+ let fr = self.frames[f as usize];
420
+ let sl = &self.slaves[i as usize];
421
+ // a flooded frame for another station, or not for this unit: dropped
422
+ if fr.dst == sl.mac && fr.modbus.unit == sl.unit as i16 {
423
+ let response = Frame {
424
+ src: sl.mac,
425
+ dst: fr.src,
426
+ size: modbus_response_frame_size(fr.modbus.count),
427
+ created: fr.created, // the request's: modbus_latency is a round trip
428
+ priority: 0,
429
+ in_port: -1,
430
+ modbus: Modbus {
431
+ unit: fr.modbus.unit,
432
+ count: fr.modbus.count,
433
+ response: true,
434
+ },
435
+ };
436
+ let chan = sl.out.expect("a slave process has a link");
437
+ let r = self.alloc(response);
438
+ self.enqueue(chan, r);
439
+ }
440
+ self.release(f);
441
+ self.get(store, proc);
442
+ }
443
+ Proc::Flow(_) | Proc::Sampler(_) | Proc::Poll(_) => {
444
+ unreachable!("these processes do not get")
445
+ }
357
446
  }
358
447
  }
359
448
 
@@ -376,7 +465,34 @@ impl Engine {
376
465
  let t = self.samplers[i as usize].ticks.next().unwrap();
377
466
  self.schedule(Ev::Timeout(proc), NORMAL, t - self.now);
378
467
  }
379
- Proc::AdapterRx(_) | Proc::Switch(_) => unreachable!("these processes do not time out"),
468
+ Proc::Poll(i) => {
469
+ let pg = &mut self.polls[i as usize];
470
+ if pg.delayed {
471
+ pg.delayed = false;
472
+ } else {
473
+ let request = Frame {
474
+ src: pg.src,
475
+ dst: pg.dst,
476
+ size: MODBUS_REQUEST_BYTES,
477
+ created: self.now,
478
+ priority: 0,
479
+ in_port: -1,
480
+ modbus: Modbus {
481
+ unit: pg.unit as i16,
482
+ count: pg.count,
483
+ response: false,
484
+ },
485
+ };
486
+ let chan = pg.chan;
487
+ let r = self.alloc(request);
488
+ self.enqueue(chan, r);
489
+ }
490
+ let t = self.polls[i as usize].instants.next().unwrap();
491
+ self.schedule(Ev::Timeout(proc), NORMAL, t - self.now);
492
+ }
493
+ Proc::AdapterRx(_) | Proc::Switch(_) | Proc::Slave(_) => {
494
+ unreachable!("these processes do not time out")
495
+ }
380
496
  }
381
497
  }
382
498
 
@@ -482,6 +598,7 @@ impl Engine {
482
598
  created: self.now,
483
599
  priority: fl.priority,
484
600
  in_port: -1,
601
+ modbus: NOT_MODBUS,
485
602
  };
486
603
  let chan = fl.chan;
487
604
  let f = self.alloc(frame);
@@ -574,6 +691,8 @@ pub fn run(sc: &Scenario) -> Result<Outcome, String> {
574
691
  adapters: Vec::new(),
575
692
  switches: Vec::new(),
576
693
  flows: Vec::new(),
694
+ slaves: Vec::new(),
695
+ polls: Vec::new(),
577
696
  samplers: Vec::new(),
578
697
  windows: Vec::new(),
579
698
  procs: Vec::new(),
@@ -613,9 +732,20 @@ pub fn run(sc: &Scenario) -> Result<Outcome, String> {
613
732
  out: None,
614
733
  bytes_received: 0,
615
734
  latency_windows: Vec::new(),
735
+ modbus_windows: Vec::new(),
616
736
  });
617
737
  role.push(e.adapters.len() - 1);
618
738
  }
739
+ NodeKind::ModbusSlave { mac, unit } => {
740
+ let mac = intern(mac);
741
+ e.slaves.push(Slave {
742
+ mac,
743
+ unit: *unit,
744
+ inbound: s,
745
+ out: None,
746
+ });
747
+ role.push(e.slaves.len() - 1);
748
+ }
619
749
  NodeKind::Switch { .. } => {
620
750
  e.switches.push(Switch {
621
751
  inbound: s,
@@ -628,10 +758,12 @@ pub fn run(sc: &Scenario) -> Result<Outcome, String> {
628
758
  }
629
759
  let is_switch = |i: usize| matches!(sc.nodes[i].kind, NodeKind::Switch { .. });
630
760
  let strict = |i: usize| !matches!(sc.nodes[i].kind, NodeKind::Switch { fifo: true, .. });
761
+ // every node but a switch is an end station with a MAC address
631
762
  let mac_of = |i: usize| match &sc.nodes[i].kind {
632
- NodeKind::Adapter { mac } => Some(mac.clone()),
763
+ NodeKind::Adapter { mac } | NodeKind::ModbusSlave { mac, .. } => Some(mac.clone()),
633
764
  NodeKind::Switch { .. } => None,
634
765
  };
766
+ let is_adapter = |i: usize| matches!(sc.nodes[i].kind, NodeKind::Adapter { .. });
635
767
 
636
768
  let mut next_port = vec![0i32; sc.nodes.len()];
637
769
  let mut in_channels: Vec<Vec<u32>> = vec![Vec::new(); sc.nodes.len()];
@@ -683,16 +815,17 @@ pub fn run(sc: &Scenario) -> Result<Outcome, String> {
683
815
  in_channels[a].push(ch_ba);
684
816
  neighbours[a].push((port_a, b));
685
817
  neighbours[b].push((port_b, a));
686
- if let Some(mac) = mac_of(a) {
687
- e.adapters[role[a]].out = Some(ch_ab);
688
- if is_switch(b) {
689
- static_macs[b].insert(intern(&mac), port_b);
690
- }
691
- }
692
- if let Some(mac) = mac_of(b) {
693
- e.adapters[role[b]].out = Some(ch_ba);
694
- if is_switch(a) {
695
- static_macs[a].insert(intern(&mac), port_a);
818
+ // an end station's single link is its way out (the model allows one)
819
+ for (node, other, ch, port) in [(a, b, ch_ab, port_b), (b, a, ch_ba, port_a)] {
820
+ if let Some(mac) = mac_of(node) {
821
+ match &sc.nodes[node].kind {
822
+ NodeKind::Adapter { .. } => e.adapters[role[node]].out = Some(ch),
823
+ NodeKind::ModbusSlave { .. } => e.slaves[role[node]].out = Some(ch),
824
+ NodeKind::Switch { .. } => unreachable!(),
825
+ }
826
+ if is_switch(other) {
827
+ static_macs[other].insert(intern(&mac), port);
828
+ }
696
829
  }
697
830
  }
698
831
  }
@@ -774,6 +907,34 @@ pub fn run(sc: &Scenario) -> Result<Outcome, String> {
774
907
  });
775
908
  e.process(Proc::Flow((e.flows.len() - 1) as u32));
776
909
  }
910
+ // then its Modbus polls, as the reference engine starts them
911
+ for poll in sc.polls.iter().filter(|p| p.source == node.name) {
912
+ let slave = lookup(&poll.slave)?;
913
+ let NodeKind::ModbusSlave { mac, unit } = &sc.nodes[slave].kind else {
914
+ return Err(format!(
915
+ "poll {} -> {}: not a Modbus slave",
916
+ poll.source, poll.slave
917
+ ));
918
+ };
919
+ let delay_ns = tb::ms_to_ns(poll.delay_ms)?;
920
+ e.polls.push(PollGen {
921
+ src: e.adapters[a as usize].mac,
922
+ dst: intern(mac),
923
+ unit: *unit,
924
+ count: poll.count,
925
+ chan,
926
+ delay_ns,
927
+ delayed: false,
928
+ instants: Instants::new(delay_ns, tb::interval_ns(poll.rate)?),
929
+ });
930
+ e.process(Proc::Poll((e.polls.len() - 1) as u32));
931
+ }
932
+ }
933
+ }
934
+ NodeKind::ModbusSlave { .. } => {
935
+ let w = role[i];
936
+ if e.slaves[w].out.is_some() {
937
+ e.process(Proc::Slave(w as u32));
777
938
  }
778
939
  }
779
940
  NodeKind::Switch { .. } => {
@@ -795,7 +956,7 @@ pub fn run(sc: &Scenario) -> Result<Outcome, String> {
795
956
  e.out.len() - 1
796
957
  }
797
958
  };
798
- let adapter = mac_of(target).is_some();
959
+ let adapter = is_adapter(target);
799
960
  let what = match obs.metric {
800
961
  Metric::Throughput if adapter => Some(Sampled::Throughput(role[target] as u32)),
801
962
  Metric::Latency if adapter => {
@@ -804,7 +965,16 @@ pub fn run(sc: &Scenario) -> Result<Outcome, String> {
804
965
  e.adapters[role[target]].latency_windows.push(w);
805
966
  Some(Sampled::Latency(w))
806
967
  }
807
- Metric::QueueDepth if !adapter => Some(Sampled::QueueDepth(role[target] as u32)),
968
+ Metric::QueueDepth if is_switch(target) => {
969
+ Some(Sampled::QueueDepth(role[target] as u32))
970
+ }
971
+ Metric::ModbusLatency if adapter => {
972
+ // the window mean of round-trip times, as latency
973
+ e.windows.push(Vec::new());
974
+ let w = (e.windows.len() - 1) as u32;
975
+ e.adapters[role[target]].modbus_windows.push(w);
976
+ Some(Sampled::Latency(w))
977
+ }
808
978
  Metric::Utilization if !in_channels[target].is_empty() => {
809
979
  let chans = in_channels[target].clone();
810
980
  let mut speed = Q::int(0);
@@ -17,7 +17,8 @@ result = net.simulate(duration=60_000, backend="rust")
17
17
  - **Scope so far.**
18
18
  - Adapters, switches (both QoS modes, learning and converged MAC tables), links, and flows with every pattern and IMIX sizes.
19
19
  - The metrics `throughput`, `latency`, `bytes_sent`, `bytes_received`, `queue_depth` and `utilization`.
20
- - MQTT, Modbus TCP and PROFINET follow. A scenario that uses them is rejected before the run, with a message naming the element.
20
+ - Modbus TCP polling: slaves, polls and `modbus_latency`.
21
+ - MQTT and PROFINET follow. A scenario that uses them is rejected before the run, with a message naming the element.
21
22
  - **Versions.** The package is released together with `smolpy`, with the same version. It checks that it reads the Scenario IR version that `smolpy` writes.
22
23
 
23
24
  One abi3 wheel per platform serves every Python from 3.10: Linux x86_64 and aarch64, macOS arm64 and x86_64, and Windows x86_64.
@@ -100,6 +100,39 @@ def switching() -> Scenario:
100
100
  return net.to_scenario(duration=40)
101
101
 
102
102
 
103
+ def polling() -> Scenario:
104
+ """Modbus TCP only, within the Rust engine's scope: two masters poll three
105
+ slaves, one behind a second switch. The learning core floods requests
106
+ until it learns a slave, so slaves also receive requests for others,
107
+ and drop them. Bulk traffic shares the uplink."""
108
+ net = Network("polling")
109
+ core = net.switch("core", ports=5) # learning
110
+ edge = net.switch("edge", ports=3)
111
+ scada = net.adapter("scada", ip="10.0.0.1")
112
+ plc = net.adapter("plc", ip="10.0.0.2")
113
+ meter = net.modbus_slave("meter", ip="10.0.0.10", unit_id=1)
114
+ drive = net.modbus_slave("drive", ip="10.0.0.11", unit_id=7)
115
+ valve = net.modbus_slave("valve", ip="10.0.0.12", unit_id=3)
116
+ net.link(scada, core, speed=100, length=10)
117
+ net.link(plc, core, speed=100, length=10)
118
+ net.link(meter, core, speed=10, length=5)
119
+ net.link(core, edge, speed=100, length=80)
120
+ net.link(drive, edge, speed=100, length=5)
121
+ net.link(valve, edge, speed=100, length=5)
122
+ scada.polls(meter, register=0, count=2, rate=250)
123
+ scada.polls(drive, register=100, count=60, rate=125, delay_ms=0.3)
124
+ plc.polls(valve, register=10, count=1, rate=500, delay_ms=1)
125
+ plc.polls(drive, register=0, count=125, rate=100)
126
+ plc.sends(scada, rate=3_000, size=1_200, delay_ms=0.5) # shares the core with responses
127
+ for master in (scada, plc):
128
+ net.observe("modbus_latency", on=master, every=2)
129
+ net.observe("bytes_received", on=master, every=2)
130
+ net.observe("latency", on=scada, every=4)
131
+ net.observe("queue_depth", on=core, every=1)
132
+ net.observe("utilization", on=edge, every=4)
133
+ return net.to_scenario(duration=40)
134
+
135
+
103
136
  def protocols() -> Scenario:
104
137
  """Modbus polling and MQTT publish/subscribe across a switch, with a
105
138
  FIFO switch."""
@@ -187,6 +220,7 @@ DETERMINISTIC: dict[str, Callable[[], Scenario]] = {
187
220
  "line": line,
188
221
  "priorities": priorities,
189
222
  "switching": switching,
223
+ "polling": polling,
190
224
  "protocols": protocols,
191
225
  }
192
226
  STOCHASTIC: dict[str, Callable[[], Scenario]] = {
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes