smolpy 1.10.3.dev8__tar.gz → 1.11.1.dev2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/PKG-INFO +1 -1
- smolpy-1.11.1.dev2/docs/adr/0012-modbus-one-request-in-flight.md +258 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/scenario-model.md +2 -2
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/mkdocs.yml +1 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smol-engine/src/scenario.rs +16 -1
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/backends.py +5 -1
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/core/adapter.py +13 -2
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/core/network.py +10 -1
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/lang/ast.py +2 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/lang/interpreter.py +7 -1
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/lang/transformer.py +13 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/model/scenario.py +10 -3
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/model/validate.py +23 -0
- smolpy-1.11.1.dev2/tests/test_outstanding.py +210 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/.github/workflows/ci.yml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/.github/workflows/dev-build.yml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/.github/workflows/docker-image.yml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/.github/workflows/docs.yml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/.github/workflows/github-release.yml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/.github/workflows/ns3-base.yml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/.github/workflows/publish.yml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/.github/workflows/release.yml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/.github/workflows/rust-wheels.yml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/.gitignore +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/LICENSE +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/README.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/__main__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/load.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/loss.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/results/2026-11-13-0921-simpy-jaws-zbook-baseline.json +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/results/2026-11-13-1527-simpy-jaws-zbook-optimised.json +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/results/2026-11-13-2116-simpy-jaws-zbook-research-batch.json +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/results/2026-11-13-2119-simpy-jaws-zbook-research-b4.json +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/results/2026-11-15-1255-rust-jaws-zbook-stop-criterion.json +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/results/2026-11-15-1333-rust-jaws-zbook-research-b4.json +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/results/2026-11-15-1346-rust-jaws-zbook-research-batch.json +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/results/2026-11-16-1839-simpy-ns3-jaws-zbook-tcp-under-load.json +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/results/2026-11-23-1228-simpy-rust-ns3-jaws-zbook-bounded-buffers.json +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/runner.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/scenarios.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/benchmarks/worker.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docker/Dockerfile +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docker/Dockerfile.dockerignore +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docker/Dockerfile.ns3 +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docker/Dockerfile.ns3.dockerignore +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docker/ns3-base/Dockerfile +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docker/ns3-base/smoke.cc +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docker/smoke.smol +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0001-protocol-package-structure.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0002-modbus-tcp-implementation.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0003-smol-external-dsl.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0004-execution-backends.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0005-profinet-rt.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0006-profiling-and-baseline-benchmark.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0007-execution-independent-scenario-model.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0008-rust-des-engine-mvp.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0009-batch-execution-and-cross-backend-validation.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0010-ethernet-frames-on-the-wire.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/adr/0011-bounded-switch-buffers.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/backends.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/benchmarks.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/dashboard.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/dsl-reference.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/examples.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/index.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/language-reference.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/modbus.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/model-semantics.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/mqtt.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/profinet.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/roadmap.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/docs/simulation-engine.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/README.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example.smol +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_10_clients.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_12_clients.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_20_clients.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_bounded_buffer.smol +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_file_transfer.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_modbus.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_mqtt.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_profinet.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_profinet.smol +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_staggered_transfer.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/examples/example_two_tier.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/pyproject.toml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/Cargo.lock +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/Cargo.toml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smol-engine/Cargo.toml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smol-engine/src/frames.rs +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smol-engine/src/lib.rs +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smol-engine/src/rng.rs +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smol-engine/src/sim.rs +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smol-engine/src/timebase.rs +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smolpy-engine-rs/Cargo.toml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smolpy-engine-rs/README.md +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smolpy-engine-rs/pyproject.toml +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smolpy-engine-rs/smoke_test.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/rust/smolpy-engine-rs/src/lib.rs +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/_worker.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/batch.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/cli.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/core/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/core/batch.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/core/link.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/core/node.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/core/observation.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/ethernet/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/ethernet/switch.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/lang/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/lang/errors.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/lang/grammar.lark +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/modbus/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/modbus/slave.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/model/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/model/frames.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/model/streams.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/model/timebase.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/mqtt/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/mqtt/broker.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/ns3/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/ns3/cpp/smol-ns3.cc +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/profinet/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/profinet/device.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/sim/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/sim/engine.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/stats.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/viz/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/viz/dashboard.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/src/smolpy/viz/text_dashboard.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/equivalence/__init__.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/equivalence/harness.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/equivalence/scenarios.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/equivalence/test_equivalence.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/equivalence/test_rust_timebase.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_backends.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_batch.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_benchmarks.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_buffers.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_cli.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_dsl.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_engine_ir.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_lang.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_model.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_ns3.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_profinet.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_semantics.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_simulation.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_stats.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_sweep.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_timebase.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/tests/test_validate.py +0 -0
- {smolpy-1.10.3.dev8 → smolpy-1.11.1.dev2}/uv.lock +0 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
# ADR-0012: Modbus Polling with One Request in Flight
|
|
2
|
+
|
|
3
|
+
**Status:** Accepted
|
|
4
|
+
**Date:** 2026-11-23
|
|
5
|
+
**Amends:**
|
|
6
|
+
- ADR-0002: `poll` gains `outstanding` and `timeout`.
|
|
7
|
+
- ADR-0007: two new optional fields of the IR, which stays version 2.
|
|
8
|
+
- ADR-0004: the `smol-ns3` line format becomes version 3, and ns-3's TCP settings are set to Linux's.
|
|
9
|
+
- ADR-0011: "Protocols when a frame is lost", for Modbus.
|
|
10
|
+
- [Model Semantics](../model-semantics.md) §5, §6, §8 and §9.
|
|
11
|
+
|
|
12
|
+
**Roadmap:** none. It came out of the ADR-0011 testbed.
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Context
|
|
17
|
+
|
|
18
|
+
**Today's `poll` is open loop.** It sends a request every `1/rate` seconds whether or not the previous response has arrived. That holds in all three engines:
|
|
19
|
+
- SimPy: `_modbus_poll_gen`;
|
|
20
|
+
- Rust: `Periodic` in `rust/smol-engine`;
|
|
21
|
+
- ns-3: `Periodic` in `smol-ns3.cc`.
|
|
22
|
+
|
|
23
|
+
Most real Modbus TCP masters work differently. They have one transaction in flight per connection: they wait for the response, or for their response timeout, before sending the next request.
|
|
24
|
+
|
|
25
|
+
**The ADR-0011 testbed shows where this matters.** The setup:
|
|
26
|
+
- **Switch:** a TP-Link LS108GP. The egress port to the master runs at 100 Mb/s, holds about 60 frames, and has 802.3x PAUSE disabled.
|
|
27
|
+
- **Background traffic:** a Raspberry Pi sends Poisson UDP traffic of 1 518 B frames to the master's port, at ρ = 0.985 and 0.996.
|
|
28
|
+
- **Polling:** the master polls a Modbus TCP server on the Pi every 10 ms, and waits for each response.
|
|
29
|
+
|
|
30
|
+
Results with `buffer=91080` (60 frames):
|
|
31
|
+
|
|
32
|
+
| | Lost Modbus responses | RTT of the affected polls |
|
|
33
|
+
|---|---|---|
|
|
34
|
+
| hardware | 3 of 1 680 (0.18 %) | about 215 ms |
|
|
35
|
+
| ns-3 backend | — | 24–40 ms |
|
|
36
|
+
| SimPy / Rust | about 0.75 % of polls never answered | — |
|
|
37
|
+
|
|
38
|
+
Everything else matches on all three engines, from ρ = 0.25 to 0.996: queueing delay, the RTT's median, p90 and p99, and UDP loss. The difference is in what happens after a lost response:
|
|
39
|
+
- **Hardware.** TCP retransmits the lost response after a retransmission timeout. With one request in flight, no later segments follow it, so there are no duplicate ACKs to trigger a fast retransmit.
|
|
40
|
+
- **ns-3.** The open-loop polls keep requests and responses flowing. Three duplicate ACKs follow the loss, and the fast retransmit comes after tens of ms.
|
|
41
|
+
- **SimPy and Rust.** There is no TCP, so a lost response is simply never answered, and the master keeps polling.
|
|
42
|
+
|
|
43
|
+
**ns-3's retransmission timeout is not Linux's.** Linux runs on most masters and slaves, and on both ends of the testbed. The ns-3 program sets none of `TcpSocketBase`'s RTO attributes, so it uses ns-3's defaults. The two compute the RTO as follows:
|
|
44
|
+
- **ns-3:** `RTO = max(SRTT + max(G, 4·RTTVAR), MinRto)`, with `MinRto` = 1 s (RFC 6298) and the clock granularity `G` = 1 ms (`tcp-socket-base.cc`). After a lost response the slave would retransmit only after 1 s.
|
|
45
|
+
- **Linux:** `RTO = SRTT + RTTVAR`, where `tcp_rtt_estimator()` keeps `RTTVAR`, in units of 4 × the deviation, at or above `rto_min` (`TCP_RTO_MIN = HZ/5`, 200 ms; `net/ipv4/tcp_input.c`, `include/net/tcp.h`). So `RTO ≥ SRTT + 200 ms`, which is the hardware's 215 ms: 200 ms plus a few ms of RTT.
|
|
46
|
+
|
|
47
|
+
### Options considered
|
|
48
|
+
|
|
49
|
+
**When a poll instant comes while the request is still outstanding:**
|
|
50
|
+
- **A: skip it, as a counted cycle overrun.** **Chosen.** The request goes out at the next poll instant after the response or the timeout. A master on a fixed cycle works this way: the PLC task that issues the request runs every cycle and does nothing while its transaction is busy. The schedule stays `start + round(k·T)` (§1, "No drift"), and every request is sent at its own scheduled instant. So when `modbus_latency` starts is not open to question, and how many instants were skipped is simply a count.
|
|
51
|
+
- **B: defer it, sending as soon as the response or timeout arrives.** Masters written as `request; wait; sleep(until next)` work this way. Requests then go out at instants set by the network, not the schedule, and the send has to be defined apart from the scheduled instant. With a long outage, B makes a burst after recovery: one request at once, then the schedule again. B can be added later as `overrun=defer`, alongside A.
|
|
52
|
+
- **C: catch up, sending every missed request one after another.** With one request in flight, that is a burst of round trips until the master is back on schedule. Few masters do this, and it would add load after an overload. Rejected.
|
|
53
|
+
|
|
54
|
+
**What the limit applies to:**
|
|
55
|
+
- **Per master–slave pair.** **Chosen.** It is one TCP connection, and Modbus TCP's MBAP transaction id matches responses per connection. The ns-3 backend already opens exactly one connection per pair.
|
|
56
|
+
- **Per master.** One transaction in flight across all of a master's slaves. That is what serial Modbus RTU does, not Modbus TCP. Rejected.
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Decision
|
|
61
|
+
|
|
62
|
+
### The parameters
|
|
63
|
+
|
|
64
|
+
```
|
|
65
|
+
poll laptop -> server register=0 count=10 rate=100 outstanding=1 timeout=500
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```python
|
|
69
|
+
laptop.polls(server, register=0, count=10, rate=100, outstanding=1, timeout_ms=500)
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
- **`outstanding`:** `1` or `unlimited`. In Python it is `1` or `None`.
|
|
73
|
+
- **The default is unlimited:** today's open loop. A scenario without the parameter means exactly what it meant before: the same results and event counts, the same benchmark hashes (B1–B4) and the same equivalence suite.
|
|
74
|
+
- **`timeout`:** the master's response timeout, in ms, the same unit as `delay`.
|
|
75
|
+
- It needs `outstanding=1`. With an unlimited number of requests in flight it would need its own semantics (per request, with late responses discarded); that is left for later.
|
|
76
|
+
- **Without `timeout`, the master waits forever.** On SimPy and Rust a single lost request or response then stops that pair's polling for the rest of the run. That is what a master without a timeout would do without TCP retransmission, and `modbus_skipped` shows it. Documentation recommends a timeout on those backends.
|
|
77
|
+
- **Validation:**
|
|
78
|
+
- `outstanding` is `1` or unset. The IR holds an integer, so that a window of `N` can be added later.
|
|
79
|
+
- `timeout` is a positive number, at least 1 ns after rounding (§1), and set only with `outstanding=1`.
|
|
80
|
+
- **A pair with `outstanding=1` has one poll statement.** Two statements to the same slave would have to share one transaction slot, and their instants would compete. The rule needed for that, a transaction queue per connection, is left for later. Several register blocks of one slave are one poll with a larger `count`.
|
|
81
|
+
- **IR.** `Poll.outstanding: int | None = None` and `Poll.timeout_ms: float | None = None`.
|
|
82
|
+
|
|
83
|
+
### One request in flight
|
|
84
|
+
|
|
85
|
+
A pair with `outstanding=1` holds at most one **outstanding** request. That is a request sent and neither answered nor timed out.
|
|
86
|
+
|
|
87
|
+
- **At a poll instant `t`:**
|
|
88
|
+
- the request is **sent** if no request is outstanding and the previous request did not complete at `t` itself;
|
|
89
|
+
- otherwise the instant is **skipped**: nothing is sent, and the instant is counted in `modbus_skipped`;
|
|
90
|
+
- either way, the next instant is the next one of the schedule.
|
|
91
|
+
- **Completed** means its response was accepted or its timeout fired.
|
|
92
|
+
- **Same-instant rule.** A response or timeout at exactly a poll instant does not free that instant: the next request goes out at the following instant. The rule depends on no event order, so it holds the same way on every engine, TCP's included. It matters only for exact ties, such as an RTT equal to the period.
|
|
93
|
+
- **Transaction ids.** Each request of the pair carries the next MBAP transaction id, and its response carries the same id back. Ids are counted from 0 without wrapping. A real MBAP id has 16 bits, but with one request in flight two live ids are never 65 536 apart.
|
|
94
|
+
|
|
95
|
+
### The timeout
|
|
96
|
+
|
|
97
|
+
A request sent at `s`, with timeout `τ` rounded to ns:
|
|
98
|
+
- **A response with its id arriving at `a < s + τ`** is **accepted**:
|
|
99
|
+
- it ends the transaction;
|
|
100
|
+
- it counts towards `modbus_latency` (`a − s`);
|
|
101
|
+
- it counts as a response.
|
|
102
|
+
- **At `s + τ`, if the request is still outstanding,** it **times out**:
|
|
103
|
+
- it is counted in `modbus_timeouts`;
|
|
104
|
+
- it ends the transaction, so the next poll instant after `s + τ` sends the next request.
|
|
105
|
+
- **A response arriving at `a ≥ s + τ`, or with an id that is not outstanding, is discarded.**
|
|
106
|
+
- It is a late response: the master already counted its request as timed out.
|
|
107
|
+
- It still counts as a frame the master's NIC accepted (`frames_received`, `bytes_received`, `throughput`, `latency`).
|
|
108
|
+
- It does not count towards `modbus_latency` or as a response.
|
|
109
|
+
- **A response at exactly `s + τ` is late,** whichever event an engine processes first.
|
|
110
|
+
|
|
111
|
+
### Where `modbus_latency` starts
|
|
112
|
+
|
|
113
|
+
It starts at **the instant the master sends the request**, which is what a master measures: it timestamps the request when it hands it to its TCP socket. Under rule A, a request is only ever sent at its scheduled instant, so the two instants are the same. As today, the request's origin time is that instant, and the response carries it back.
|
|
114
|
+
|
|
115
|
+
### On each engine
|
|
116
|
+
|
|
117
|
+
- **SimPy and Rust have no transport layer.** A lost request or response is not retransmitted. The transaction ends at its timeout, or never if the poll has no timeout.
|
|
118
|
+
- **ns-3 runs Modbus over real TCP.**
|
|
119
|
+
- A lost segment is retransmitted: after the RTO, or after a fast retransmit if enough duplicate ACKs arrive. With one request in flight, they usually do not.
|
|
120
|
+
- The timeout matters only when recovery takes longer than `τ`.
|
|
121
|
+
- **After a timeout the connection stays open.** The next request is sent on the same byte stream, behind the old request if that is still being retransmitted. Its response then also waits for the old response's bytes to arrive, so in-order delivery can make it time out too. A real master that keeps its connection behaves the same; many masters reconnect after a timeout, which is not modelled.
|
|
122
|
+
- **The engines therefore differ by design under loss.** On SimPy and Rust a loss becomes a timeout. On ns-3 it becomes an RTT of about RTO + RTT, or a timeout if `τ` is shorter. The testbed is the reference for the second.
|
|
123
|
+
|
|
124
|
+
### Metrics
|
|
125
|
+
|
|
126
|
+
| Metric | On | Value at a sample | Unit |
|
|
127
|
+
|---|---|---|---|
|
|
128
|
+
| `modbus_timeouts` | adapter | requests of its polls that timed out so far | polls |
|
|
129
|
+
| `modbus_skipped` | adapter | poll instants skipped so far because a request was outstanding | polls |
|
|
130
|
+
|
|
131
|
+
Both are cumulative counts, like `modbus_unanswered`. On a poll with an unlimited number of requests in flight they stay 0.
|
|
132
|
+
|
|
133
|
+
**Changed definitions:**
|
|
134
|
+
- **`modbus_unanswered`** stays *requests sent less responses accepted*.
|
|
135
|
+
- Skipped instants are not requests.
|
|
136
|
+
- A discarded late response is not a response.
|
|
137
|
+
- So, for a master's polls with `outstanding=1`: `modbus_unanswered = modbus_timeouts + outstanding`, where `outstanding` is the number of its pairs with a request outstanding at the sample.
|
|
138
|
+
- **Poll instants.** Over a master's polls with `outstanding=1`, the instants so far are the requests sent plus `modbus_skipped`.
|
|
139
|
+
|
|
140
|
+
### The IR stays version 2
|
|
141
|
+
|
|
142
|
+
- `outstanding` and `timeout_ms` are optional fields, as `buffer_bytes` is in ADR-0011. They are written only when set, so a scenario without them is the same JSON byte for byte.
|
|
143
|
+
- **Capability feature `"modbus_outstanding"`.** `smolpy.backends.check` rejects a poll with `outstanding=1` on a backend without it, naming the poll. A backend never ignores it silently.
|
|
144
|
+
- **The Rust package.** `smolpy[rust]` requires the `smolpy-engine-rs` release that runs it.
|
|
145
|
+
|
|
146
|
+
### ns-3
|
|
147
|
+
|
|
148
|
+
**Format 3.** The poll line gains two fields:
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
poll <connection> <request B> <response B> <delay ns> <period num> <period den> <outstanding> <timeout ns>
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
- `outstanding` is 0 for unlimited or 1.
|
|
155
|
+
- `timeout` is 0 for none.
|
|
156
|
+
|
|
157
|
+
**On the client side:**
|
|
158
|
+
- **The poll owns the transaction slot.** `Periodic` hands a request to `Connection::Send` only when no request of its pair is outstanding.
|
|
159
|
+
- **`Sent` carries the transaction id.** On arrival of a whole response, `Connection::Arrived` accepts it only if its id is the outstanding one and it arrived before `s + τ`.
|
|
160
|
+
- **What the application guarantees.** It never has more than one request awaiting a response. Below the application, TCP's own queue (`m_inFlight`) can still hold a timed-out request's bytes; see above.
|
|
161
|
+
- **A test checks that `outstanding=1` really keeps one request in flight on the connection,** without loss and with it.
|
|
162
|
+
|
|
163
|
+
**TCP settings, set to Linux's.** These are `Config::SetDefault` values in `smol-ns3.cc`. Sources: ns-3 3.49 `src/internet/model/tcp-socket.cc`, `tcp-socket-base.cc`, `rtt-estimator.cc`; Linux `include/net/tcp.h`, `net/ipv4/tcp_input.c`, `net/ipv4/tcp_output.c`.
|
|
164
|
+
|
|
165
|
+
| Setting | ns-3 default | Linux | Set to |
|
|
166
|
+
|---|---|---|---|
|
|
167
|
+
| `TcpSocketBase::MinRto` | 1 s | 200 ms (`TCP_RTO_MIN`) | **200 ms** |
|
|
168
|
+
| `TcpSocketBase::ClockGranularity` | 1 ms | `rto_min` is a floor on `RTTVAR` | **200 ms** |
|
|
169
|
+
| `RttEstimator::InitialEstimation`, the first RTO | 1 s | 1 s (`TCP_TIMEOUT_INIT`) | 1 s, unchanged |
|
|
170
|
+
| `TcpSocket::ConnTimeout`, the SYN RTO | 3 s | 1 s | **1 s** |
|
|
171
|
+
| `TcpSocket::DelAckTimeout` | 200 ms | 40 ms at first (`TCP_ATO_MIN`); adapts up to 200 ms (`TCP_DELACK_MAX`) | **40 ms** |
|
|
172
|
+
| `TcpSocket::DelAckCount` | 2 | an ACK at once for more than one full segment | 2, unchanged |
|
|
173
|
+
| `TcpSocketBase::Timestamp` | on | on | off, unchanged |
|
|
174
|
+
| `TcpSocketBase::Sack` | on | on | on, unchanged |
|
|
175
|
+
| `TcpSocket::TcpNoDelay` | on | Nagle by default; Modbus stacks set `TCP_NODELAY` | on, unchanged |
|
|
176
|
+
| congestion control, recovery | CUBIC, PRR | CUBIC, PRR | unchanged |
|
|
177
|
+
|
|
178
|
+
- **Clock granularity.** With `G = 200 ms`, ns-3's RTO becomes `SRTT + max(200 ms, 4·RTTVAR)`. That is Linux's formula, including its addition of the floor to SRTT. `MinRto` alone would give `max(200 ms, SRTT + 4·RTTVAR)`, about 10 ms short of the testbed. Both are set, so the RTO is never under 200 ms.
|
|
179
|
+
- **Delayed ACK.** Linux starts its delayed-ACK timeout at 40 ms and adapts it. 40 ms is its value for request–response traffic that does not piggyback the ACK. Linux's quick-ACK mode at the start of a connection is not modelled.
|
|
180
|
+
- **Timestamps stay off.** Linux sends them, but SMOL sizes every TCP frame without the 12 B option (Model Semantics §2). Frame sizes then agree across engines, and the RTO's RTT samples come from ACKs alone, by Karn's rule.
|
|
181
|
+
- **Tail loss probe.** Linux's TLP is not in ns-3. With one segment in flight, its probe comes at `2·SRTT + rto_min`, capped at the RTO, so it is not earlier than the RTO. A lone lost response is therefore recovered at the RTO on both.
|
|
182
|
+
- **The settings change how ns-3's TCP recovers, and so how ns-3 results look under loss.** Without loss, only the delayed ACK can change a result: a pure ACK now leaves after 40 ms instead of 200 ms when nothing piggybacks it. That moves frames on the wire at poll and publish periods above 40 ms. Step 4 records every ns-3 result that changes.
|
|
183
|
+
|
|
184
|
+
**A backend option, not part of the scenario.** `smolpy.ns3.TcpSettings` holds the values above, with these defaults: minimum RTO, clock granularity, delayed-ACK timeout and SYN RTO. The program reads them from a `tcp` line of the format. `Ns3Backend(tcp=TcpSettings(min_rto_ms=1000))` runs with other values. They are not in the IR, for two reasons:
|
|
185
|
+
- SimPy and Rust have no TCP to apply them to;
|
|
186
|
+
- they describe the hosts' operating system, not the network.
|
|
187
|
+
|
|
188
|
+
### Validation and tests
|
|
189
|
+
|
|
190
|
+
**Unit tests, on SimPy and Rust:**
|
|
191
|
+
- with `outstanding=1`, no loss and an RTT shorter than the period, every result equals the open loop's, event counts aside;
|
|
192
|
+
- with an RTT longer than the period, the instants are skipped exactly as rule A says;
|
|
193
|
+
- a poll instant at exactly the same instant as a response arrival is skipped;
|
|
194
|
+
- a timeout fires exactly `τ` after the request;
|
|
195
|
+
- a response at or after `s + τ` is discarded and not counted;
|
|
196
|
+
- `modbus_unanswered = modbus_timeouts + outstanding`, and instants = requests sent + `modbus_skipped`;
|
|
197
|
+
- validation of `outstanding` and `timeout`, the `.smol` syntax, and the capability.
|
|
198
|
+
|
|
199
|
+
**Cross-engine.** Two deterministic scenarios join the bit-exact set of SimPy and Rust, event counts included:
|
|
200
|
+
- **`poll-timeouts`:** a slow path through a bounded buffer, where constant background flows overflow it, responses are lost and timeouts fire;
|
|
201
|
+
- **`poll-tie`:** an RTT exactly equal to the poll period, so that each response arrives at the instant of the next poll.
|
|
202
|
+
|
|
203
|
+
**ns-3, the testbed case:**
|
|
204
|
+
- **Setup:**
|
|
205
|
+
- Poisson UDP at ρ ≈ 0.99 through a 100 Mb/s port with `buffer=91080`;
|
|
206
|
+
- Modbus with `outstanding=1`, `rate=100` and no timeout;
|
|
207
|
+
- 30 s per run, several seeds.
|
|
208
|
+
- **Expected:**
|
|
209
|
+
- lost responses come back with an RTT of about `MinRto + RTT` (≈ 200–220 ms), not tens of ms;
|
|
210
|
+
- no poll stays unanswered at the end, beyond the one in flight.
|
|
211
|
+
- **Reported:**
|
|
212
|
+
- the distribution of the long RTTs across the seeds;
|
|
213
|
+
- the share of polls affected, against the hardware's 0.18 %.
|
|
214
|
+
|
|
215
|
+
The model loses more frames than the testbed (ADR-0011: 0.5 % against 0.09 % of UDP frames). So the share of affected polls is expected to be higher than the hardware's, and that gap stays open.
|
|
216
|
+
|
|
217
|
+
### Steps
|
|
218
|
+
|
|
219
|
+
1. **The model:**
|
|
220
|
+
- the two optional IR fields, written only when set;
|
|
221
|
+
- `outstanding` and `timeout` in the Python API and in `.smol`;
|
|
222
|
+
- validation;
|
|
223
|
+
- the capability feature, which no backend has yet, so every backend rejects `outstanding=1`, and the Rust reader rejects the fields.
|
|
224
|
+
2. **SimPy:**
|
|
225
|
+
- rule A, the timeout, transaction ids and the two metrics;
|
|
226
|
+
- unit tests;
|
|
227
|
+
- Model Semantics updated.
|
|
228
|
+
3. **Rust:**
|
|
229
|
+
- the same;
|
|
230
|
+
- the two bit-exact scenarios;
|
|
231
|
+
- the `smolpy-engine-rs` floor raised.
|
|
232
|
+
4. **ns-3:**
|
|
233
|
+
- format 3 and the poll state on the client side;
|
|
234
|
+
- `TcpSettings` and the `tcp` line;
|
|
235
|
+
- the testbed case on ns-3, with its results recorded, and on SimPy and Rust for comparison.
|
|
236
|
+
5. **Documentation:**
|
|
237
|
+
- `modbus.md`, the language and DSL references, `backends.md`;
|
|
238
|
+
- an example scenario;
|
|
239
|
+
- the roadmap, with `response_delay` (slave processing time) named as the natural next step of the Modbus candidate.
|
|
240
|
+
|
|
241
|
+
---
|
|
242
|
+
|
|
243
|
+
## Consequences
|
|
244
|
+
|
|
245
|
+
**Positive**
|
|
246
|
+
- **The usual Modbus TCP master can be modelled:** one transaction per connection, a response timeout, and cycle overruns counted.
|
|
247
|
+
- **ns-3 reproduces the testbed's recovery:** an RTO-sized RTT for a lost response, with Linux's minimum RTO, where it now shows a fast retransmit that the hardware cannot have.
|
|
248
|
+
- **On SimPy and Rust a loss becomes a timeout,** a bounded and countable event, instead of a poll unanswered for good.
|
|
249
|
+
- **ns-3's TCP matches Linux in the settings that shape recovery,** and they are documented and can be changed.
|
|
250
|
+
|
|
251
|
+
**Negative / trade-offs**
|
|
252
|
+
- **A new `smolpy-engine-rs` release and ns-3 format version.**
|
|
253
|
+
- **ns-3 results with loss change.** Results without loss can change too, through the delayed-ACK timeout, at poll and publish periods above 40 ms.
|
|
254
|
+
- **One poll statement per pair with `outstanding=1`.** Masters that serialize several transactions on one connection are not modelled yet.
|
|
255
|
+
- **Not modelled:**
|
|
256
|
+
- masters that defer instead of skipping (option B);
|
|
257
|
+
- reconnecting after a timeout;
|
|
258
|
+
- a window of more than one request.
|
|
@@ -77,7 +77,7 @@ link c -- sw: 'sw' has only 2 ports, all in use
|
|
|
77
77
|
| `Flow` | source and destination are adapters; `rate` > 0; `size` ≥ 1 or `imix`; known `pattern`; `priority` 0–7; a batch size exactly when `pattern="batch"` |
|
|
78
78
|
| `Publish` | adapter → MQTT broker; non-empty topic; `rate` > 0; `qos` 0 or 1 (QoS 2 is not modelled) |
|
|
79
79
|
| `Route` | broker → adapters, each subscriber once |
|
|
80
|
-
| `Poll` | adapter → Modbus slave; `register` 0–65535; `count` 1–125; `rate` > 0 |
|
|
80
|
+
| `Poll` | adapter → Modbus slave; `register` 0–65535; `count` 1–125; `rate` > 0; `outstanding` 1 or unset; `timeout_ms` ≥ 1 ns, only with `outstanding`; with `outstanding`, one poll per master–slave pair |
|
|
81
81
|
| `ProfinetAR` | adapter → PROFINET device; `cycle` 1, 2, 4 … 512 ms; `inputs`/`outputs` 1–1440 B; `hold` 1–255 |
|
|
82
82
|
| observations | an implemented metric (`frame_loss` is not); a node type the metric applies to; `every` > 0 |
|
|
83
83
|
| run | `duration` > 0; integer `seed` |
|
|
@@ -152,4 +152,4 @@ Each node and traffic entry carries a `kind`: `adapter`, `switch`, `mqtt_broker`
|
|
|
152
152
|
- an unknown `kind` or field;
|
|
153
153
|
- a missing required field.
|
|
154
154
|
|
|
155
|
-
Optional fields that are left out take their defaults. Under ADR-0007, a new optional field does not change the version, and any change in meaning does. A switch's `buffer_bytes` ([ADR-0011](adr/0011-bounded-switch-buffers.md)) is written only when it is set, so documents without bounded switches are as before.
|
|
155
|
+
Optional fields that are left out take their defaults. Under ADR-0007, a new optional field does not change the version, and any change in meaning does. A switch's `buffer_bytes` ([ADR-0011](adr/0011-bounded-switch-buffers.md)) is written only when it is set, so documents without bounded switches are as before. So are a poll's `outstanding` and `timeout_ms` ([ADR-0012](adr/0012-modbus-one-request-in-flight.md)).
|
|
@@ -54,6 +54,7 @@ nav:
|
|
|
54
54
|
- ADR-0009 Batch Execution and Cross-Backend Validation: adr/0009-batch-execution-and-cross-backend-validation.md
|
|
55
55
|
- ADR-0010 Ethernet Frames on the Wire: adr/0010-ethernet-frames-on-the-wire.md
|
|
56
56
|
- ADR-0011 Bounded Switch Buffers: adr/0011-bounded-switch-buffers.md
|
|
57
|
+
- ADR-0012 One Modbus Request in Flight: adr/0012-modbus-one-request-in-flight.md
|
|
57
58
|
|
|
58
59
|
markdown_extensions:
|
|
59
60
|
- admonition
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
//! Reads Scenario IR JSON, format "smol-ir" version 2 (ADR-0007, ADR-0010),
|
|
2
|
-
//! with the optional switch buffers of ADR-0011.
|
|
2
|
+
//! with the optional switch buffers of ADR-0011. Polls with one request in
|
|
3
|
+
//! flight (ADR-0012) are rejected.
|
|
3
4
|
//!
|
|
4
5
|
//! The scenario has already been validated by `smolpy.model.validate`; this
|
|
5
6
|
//! reader is strict about structure (unknown fields, kinds and versions are
|
|
@@ -526,6 +527,12 @@ fn parse_traffic(value: Value, i: usize) -> Res<Traffic> {
|
|
|
526
527
|
None => Q::int(0),
|
|
527
528
|
Some(v) => number(&v, "poll: delay_ms")?,
|
|
528
529
|
};
|
|
530
|
+
for field in ["outstanding", "timeout_ms"] {
|
|
531
|
+
match f.take_or(field) {
|
|
532
|
+
None | Some(Value::Null) => {}
|
|
533
|
+
Some(_) => return Err(unsupported("polls with one request in flight")),
|
|
534
|
+
}
|
|
535
|
+
}
|
|
529
536
|
f.done()?;
|
|
530
537
|
Ok(Traffic::Poll(Poll {
|
|
531
538
|
source,
|
|
@@ -713,6 +720,14 @@ mod tests {
|
|
|
713
720
|
.unwrap_err()
|
|
714
721
|
.contains("unknown field \"x\"")
|
|
715
722
|
);
|
|
723
|
+
for field in ["\"outstanding\": 1", "\"timeout_ms\": 50.0"] {
|
|
724
|
+
let poll = format!(
|
|
725
|
+
"\"traffic\": [{{\"kind\": \"poll\", \"source\": \"tx\", \"slave\": \"rx\", \"register\": 0, \"count\": 10, \"rate\": 100, \"delay_ms\": 0.0, {field}}}, "
|
|
726
|
+
);
|
|
727
|
+
assert!(parse(&B1.replace("\"traffic\": [", &poll))
|
|
728
|
+
.unwrap_err()
|
|
729
|
+
.contains("polls with one request in flight"));
|
|
730
|
+
}
|
|
716
731
|
let poisson = parse(&B1.replace("\"constant\"", "\"poisson\"")).unwrap();
|
|
717
732
|
assert_eq!(poisson.flows[0].pattern, Pattern::Poisson);
|
|
718
733
|
let imix = parse(&B1.replace("\"size\": 512", "\"size\": \"imix\"")).unwrap();
|
|
@@ -52,7 +52,8 @@ class Capabilities:
|
|
|
52
52
|
traffic: frozenset[str]
|
|
53
53
|
patterns: frozenset[str] # of flows
|
|
54
54
|
metrics: frozenset[str]
|
|
55
|
-
# "imix": IMIX frame sizes; "bounded_buffer": switch buffers (ADR-0011)
|
|
55
|
+
# "imix": IMIX frame sizes; "bounded_buffer": switch buffers (ADR-0011);
|
|
56
|
+
# "modbus_outstanding": polls with one request in flight (ADR-0012)
|
|
56
57
|
features: frozenset[str] = frozenset()
|
|
57
58
|
priorities: bool = True # 802.1Q priorities above 0 on flows
|
|
58
59
|
half_duplex: bool = False
|
|
@@ -298,6 +299,9 @@ def check(scenario: Scenario, backend: str = DEFAULT, *, dashboard: bool = False
|
|
|
298
299
|
raise unsupported(t, f"pattern {pattern!r}", ("traffic", i))
|
|
299
300
|
if getattr(t, "size", None) == "imix" and "imix" not in caps.features:
|
|
300
301
|
raise unsupported(t, "IMIX frame sizes", ("traffic", i))
|
|
302
|
+
closed = getattr(t, "outstanding", None) is not None
|
|
303
|
+
if closed and "modbus_outstanding" not in caps.features:
|
|
304
|
+
raise unsupported(t, "polls with one request in flight", ("traffic", i))
|
|
301
305
|
if getattr(t, "priority", 0) > 0 and not caps.priorities:
|
|
302
306
|
raise unsupported(t, "802.1Q priorities", ("traffic", i))
|
|
303
307
|
for i, o in enumerate(scenario.observations):
|
|
@@ -68,12 +68,16 @@ class ModbusSpec:
|
|
|
68
68
|
count: int,
|
|
69
69
|
rate_hz: float,
|
|
70
70
|
delay_ms: float = 0.0,
|
|
71
|
+
outstanding: int | None = None,
|
|
72
|
+
timeout_ms: float | None = None,
|
|
71
73
|
) -> None:
|
|
72
74
|
self.slave = slave
|
|
73
75
|
self.register = register
|
|
74
76
|
self.count = count
|
|
75
77
|
self.rate_hz = rate_hz
|
|
76
78
|
self.delay_ms = delay_ms
|
|
79
|
+
self.outstanding = outstanding # None: any number of requests in flight
|
|
80
|
+
self.timeout_ms = timeout_ms # None: no response timeout
|
|
77
81
|
# Frame sizes are part of the model: smolpy.model.frames.
|
|
78
82
|
self.request_frame_size: int = MODBUS_REQUEST_BYTES
|
|
79
83
|
self.response_frame_size: int = modbus_response_frame_size(count)
|
|
@@ -163,9 +167,16 @@ class Adapter(Node):
|
|
|
163
167
|
count: int,
|
|
164
168
|
rate: float = 1.0, # polls / second
|
|
165
169
|
delay_ms: float = 0.0,
|
|
170
|
+
outstanding: int | None = None, # 1: one request in flight (ADR-0012)
|
|
171
|
+
timeout_ms: float | None = None, # response timeout, with outstanding=1
|
|
166
172
|
) -> None:
|
|
167
|
-
|
|
168
|
-
|
|
173
|
+
poll = model.Poll(
|
|
174
|
+
self.name, slave.name, register, count, rate, delay_ms, outstanding, timeout_ms
|
|
175
|
+
)
|
|
176
|
+
self._check(poll, slave)
|
|
177
|
+
self.modbus_specs.append(
|
|
178
|
+
ModbusSpec(slave, register, count, rate, delay_ms, outstanding, timeout_ms)
|
|
179
|
+
)
|
|
169
180
|
|
|
170
181
|
def controls(
|
|
171
182
|
self,
|
|
@@ -274,7 +274,16 @@ class Network:
|
|
|
274
274
|
for m in node.mqtt_specs
|
|
275
275
|
)
|
|
276
276
|
traffic.extend(
|
|
277
|
-
model.Poll(
|
|
277
|
+
model.Poll(
|
|
278
|
+
node.name,
|
|
279
|
+
p.slave.name,
|
|
280
|
+
p.register,
|
|
281
|
+
p.count,
|
|
282
|
+
p.rate_hz,
|
|
283
|
+
p.delay_ms,
|
|
284
|
+
p.outstanding,
|
|
285
|
+
p.timeout_ms,
|
|
286
|
+
)
|
|
278
287
|
for p in node.modbus_specs
|
|
279
288
|
)
|
|
280
289
|
elif isinstance(node, MQTTBroker):
|
|
@@ -171,7 +171,13 @@ class _Interpreter:
|
|
|
171
171
|
slave = self._resolve(net, d.slave, d.line)
|
|
172
172
|
assert isinstance(master, Adapter)
|
|
173
173
|
master.polls(
|
|
174
|
-
slave,
|
|
174
|
+
slave,
|
|
175
|
+
register=d.register,
|
|
176
|
+
count=d.count,
|
|
177
|
+
rate=d.rate,
|
|
178
|
+
delay_ms=d.delay_ms,
|
|
179
|
+
outstanding=d.outstanding, # type: ignore[arg-type]
|
|
180
|
+
timeout_ms=d.timeout_ms, # type: ignore[arg-type]
|
|
175
181
|
)
|
|
176
182
|
lines.statement("poll", master.name, d.line)
|
|
177
183
|
elif isinstance(d, smol_ast.ControlDecl):
|
|
@@ -62,6 +62,17 @@ def _bytes(raw: Any) -> Any:
|
|
|
62
62
|
return raw
|
|
63
63
|
|
|
64
64
|
|
|
65
|
+
def _outstanding(raw: Any) -> Any:
|
|
66
|
+
"""``outstanding=unlimited`` is ``None``; anything else is left for
|
|
67
|
+
validation, which accepts only 1 (ADR-0012)."""
|
|
68
|
+
return None if raw == "unlimited" else raw
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _ms(raw: Any) -> Any:
|
|
72
|
+
"""A time in ms as a float; anything else is left for validation."""
|
|
73
|
+
return float(raw) if isinstance(raw, int) and not isinstance(raw, bool) else raw
|
|
74
|
+
|
|
75
|
+
|
|
65
76
|
def _require(kwargs: dict[str, Any], key: str, *, file: str, line: int, stmt: str) -> Any:
|
|
66
77
|
if key not in kwargs:
|
|
67
78
|
raise SMOLSyntaxError(file, line, f"'{stmt}' is missing required argument '{key}'")
|
|
@@ -213,6 +224,8 @@ class _SmolTransformer(Transformer):
|
|
|
213
224
|
count=int(_require(kw, "count", file=self.file, line=meta.line, stmt="poll")),
|
|
214
225
|
rate=float(kw.get("rate", 1.0)),
|
|
215
226
|
delay_ms=float(kw.get("delay", 0.0)),
|
|
227
|
+
outstanding=_outstanding(kw["outstanding"]) if "outstanding" in kw else None,
|
|
228
|
+
timeout_ms=_ms(kw["timeout"]) if "timeout" in kw else None,
|
|
216
229
|
line=meta.line,
|
|
217
230
|
)
|
|
218
231
|
|
|
@@ -28,8 +28,8 @@ VERSION = 2 # 2: Ethernet frames on the wire (ADR-0010)
|
|
|
28
28
|
|
|
29
29
|
# Optional fields that are left out of the JSON while they hold their default,
|
|
30
30
|
# so that documents not using them read as before, in older readers too
|
|
31
|
-
# (ADR-0011: switch buffers).
|
|
32
|
-
_OMITTED_WHEN_UNSET = {"buffer_bytes"}
|
|
31
|
+
# (ADR-0011: switch buffers; ADR-0012: one Modbus request in flight).
|
|
32
|
+
_OMITTED_WHEN_UNSET = {"buffer_bytes", "outstanding", "timeout_ms"}
|
|
33
33
|
|
|
34
34
|
SwitchMode = Literal["store-and-forward", "cut-through"]
|
|
35
35
|
SwitchQoS = Literal["strict", "fifo"]
|
|
@@ -158,7 +158,12 @@ class Route:
|
|
|
158
158
|
|
|
159
159
|
@dataclass(frozen=True)
|
|
160
160
|
class Poll:
|
|
161
|
-
"""Modbus TCP register reads of *slave* (``Adapter.polls``); *rate* in polls/s.
|
|
161
|
+
"""Modbus TCP register reads of *slave* (``Adapter.polls``); *rate* in polls/s.
|
|
162
|
+
|
|
163
|
+
*outstanding* is the number of requests the master keeps in flight: ``None``
|
|
164
|
+
for any number (open loop) or 1, which skips a poll instant while a request
|
|
165
|
+
is outstanding; *timeout_ms* is its response timeout, ``None`` for none
|
|
166
|
+
(ADR-0012)."""
|
|
162
167
|
|
|
163
168
|
kind: ClassVar[str] = "poll"
|
|
164
169
|
source: str
|
|
@@ -167,6 +172,8 @@ class Poll:
|
|
|
167
172
|
count: int
|
|
168
173
|
rate: float = 1.0
|
|
169
174
|
delay_ms: float = 0.0
|
|
175
|
+
outstanding: int | None = None
|
|
176
|
+
timeout_ms: float | None = None
|
|
170
177
|
|
|
171
178
|
|
|
172
179
|
@dataclass(frozen=True)
|
|
@@ -243,6 +243,7 @@ def check_traffic(t: TrafficSpec, nodes: Mapping[str, NodeSpec] | None = None) -
|
|
|
243
243
|
_in_range(t, "register", t.register, 0, 65_535)
|
|
244
244
|
_in_range(t, "count", t.count, 1, MODBUS_MAX_REGISTERS)
|
|
245
245
|
_positive(t, "rate", t.rate)
|
|
246
|
+
_check_outstanding(t)
|
|
246
247
|
elif isinstance(t, ProfinetAR):
|
|
247
248
|
if t.cycle_ms not in PN_CYCLES_MS or not _integer(t.cycle_ms):
|
|
248
249
|
raise _fail(t, f"cycle {t.cycle_ms!r} ms must be one of {list(PN_CYCLES_MS)} ms")
|
|
@@ -252,6 +253,21 @@ def check_traffic(t: TrafficSpec, nodes: Mapping[str, NodeSpec] | None = None) -
|
|
|
252
253
|
_non_negative(t, "delay", getattr(t, "delay_ms", 0.0))
|
|
253
254
|
|
|
254
255
|
|
|
256
|
+
def _check_outstanding(t: Poll) -> None:
|
|
257
|
+
"""ADR-0012: *outstanding* is 1 or unset; a timeout needs it."""
|
|
258
|
+
if t.outstanding is not None and (not _integer(t.outstanding) or t.outstanding != 1):
|
|
259
|
+
raise _fail(t, f"outstanding must be 1 or unlimited, got {t.outstanding!r}")
|
|
260
|
+
if t.timeout_ms is None:
|
|
261
|
+
return
|
|
262
|
+
if t.outstanding is None:
|
|
263
|
+
raise _fail(t, "timeout needs outstanding=1")
|
|
264
|
+
_positive(t, "timeout", t.timeout_ms)
|
|
265
|
+
if not math.isfinite(t.timeout_ms) or timebase.ms_to_ns(t.timeout_ms) < 1:
|
|
266
|
+
raise _fail(
|
|
267
|
+
t, f"timeout must be at least 1 ns (0.000001 ms) and finite, got {t.timeout_ms!r}"
|
|
268
|
+
)
|
|
269
|
+
|
|
270
|
+
|
|
255
271
|
def _largest_frame(t: TrafficSpec) -> int:
|
|
256
272
|
"""The largest frame *t* sends, in bytes (Model Semantics §2)."""
|
|
257
273
|
if isinstance(t, Flow):
|
|
@@ -340,6 +356,7 @@ def validate(scenario: Scenario) -> None:
|
|
|
340
356
|
|
|
341
357
|
ars: set[tuple[str, str]] = set()
|
|
342
358
|
routes: set[tuple[str, str]] = set()
|
|
359
|
+
polled = Counter((t.source, t.slave) for t in scenario.traffic if isinstance(t, Poll))
|
|
343
360
|
for i, t in enumerate(scenario.traffic):
|
|
344
361
|
with _at("traffic", i):
|
|
345
362
|
check_traffic(t, nodes)
|
|
@@ -356,6 +373,12 @@ def validate(scenario: Scenario) -> None:
|
|
|
356
373
|
if (t.controller, t.device) in ars:
|
|
357
374
|
raise _fail(t, f"{t.controller!r} already controls {t.device!r}")
|
|
358
375
|
ars.add((t.controller, t.device))
|
|
376
|
+
if isinstance(t, Poll) and t.outstanding is not None and polled[t.source, t.slave] > 1:
|
|
377
|
+
raise _fail(
|
|
378
|
+
t,
|
|
379
|
+
f"{t.source!r} polls {t.slave!r} more than once; with outstanding=1"
|
|
380
|
+
" a master-slave pair has one poll",
|
|
381
|
+
)
|
|
359
382
|
if isinstance(t, Route):
|
|
360
383
|
if (t.broker, t.topic) in routes:
|
|
361
384
|
raise _fail(t, "topic is routed twice")
|