smolpy 1.10.2__tar.gz → 1.10.3.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.2 → smolpy-1.10.3.dev2}/PKG-INFO +1 -1
- smolpy-1.10.3.dev2/docs/adr/0011-bounded-switch-buffers.md +198 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/scenario-model.md +2 -2
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/mkdocs.yml +1 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smol-engine/src/scenario.rs +11 -1
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/backends.py +5 -1
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/core/network.py +2 -1
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/ethernet/switch.py +9 -1
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/lang/ast.py +1 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/lang/interpreter.py +1 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/lang/transformer.py +20 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/model/frames.py +1 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/model/scenario.py +13 -1
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/model/validate.py +42 -1
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/ns3/__init__.py +4 -0
- smolpy-1.10.3.dev2/tests/test_buffers.py +196 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/.github/workflows/ci.yml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/.github/workflows/dev-build.yml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/.github/workflows/docker-image.yml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/.github/workflows/docs.yml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/.github/workflows/github-release.yml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/.github/workflows/ns3-base.yml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/.github/workflows/publish.yml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/.github/workflows/release.yml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/.github/workflows/rust-wheels.yml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/.gitignore +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/LICENSE +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/README.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/__main__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/load.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/results/2026-11-13-0921-simpy-jaws-zbook-baseline.json +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/results/2026-11-13-1527-simpy-jaws-zbook-optimised.json +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/results/2026-11-13-2116-simpy-jaws-zbook-research-batch.json +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/results/2026-11-13-2119-simpy-jaws-zbook-research-b4.json +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/results/2026-11-15-1255-rust-jaws-zbook-stop-criterion.json +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/results/2026-11-15-1333-rust-jaws-zbook-research-b4.json +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/results/2026-11-15-1346-rust-jaws-zbook-research-batch.json +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/results/2026-11-16-1839-simpy-ns3-jaws-zbook-tcp-under-load.json +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/runner.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/scenarios.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/benchmarks/worker.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docker/Dockerfile +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docker/Dockerfile.dockerignore +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docker/Dockerfile.ns3 +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docker/Dockerfile.ns3.dockerignore +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docker/ns3-base/Dockerfile +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docker/ns3-base/smoke.cc +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docker/smoke.smol +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/adr/0001-protocol-package-structure.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/adr/0002-modbus-tcp-implementation.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/adr/0003-smol-external-dsl.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/adr/0004-execution-backends.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/adr/0005-profinet-rt.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/adr/0006-profiling-and-baseline-benchmark.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/adr/0007-execution-independent-scenario-model.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/adr/0008-rust-des-engine-mvp.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/adr/0009-batch-execution-and-cross-backend-validation.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/adr/0010-ethernet-frames-on-the-wire.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/backends.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/benchmarks.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/dashboard.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/dsl-reference.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/examples.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/index.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/language-reference.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/modbus.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/model-semantics.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/mqtt.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/profinet.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/roadmap.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/docs/simulation-engine.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/README.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example.smol +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example_10_clients.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example_12_clients.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example_20_clients.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example_file_transfer.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example_modbus.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example_mqtt.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example_profinet.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example_profinet.smol +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example_staggered_transfer.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/examples/example_two_tier.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/pyproject.toml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/Cargo.lock +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/Cargo.toml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smol-engine/Cargo.toml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smol-engine/src/frames.rs +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smol-engine/src/lib.rs +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smol-engine/src/rng.rs +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smol-engine/src/sim.rs +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smol-engine/src/timebase.rs +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smolpy-engine-rs/Cargo.toml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smolpy-engine-rs/README.md +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smolpy-engine-rs/pyproject.toml +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smolpy-engine-rs/smoke_test.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/rust/smolpy-engine-rs/src/lib.rs +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/_worker.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/batch.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/cli.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/core/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/core/adapter.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/core/batch.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/core/link.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/core/node.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/core/observation.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/ethernet/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/lang/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/lang/errors.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/lang/grammar.lark +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/modbus/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/modbus/slave.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/model/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/model/streams.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/model/timebase.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/mqtt/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/mqtt/broker.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/ns3/cpp/smol-ns3.cc +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/profinet/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/profinet/device.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/sim/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/sim/engine.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/stats.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/viz/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/viz/dashboard.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/src/smolpy/viz/text_dashboard.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/equivalence/__init__.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/equivalence/harness.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/equivalence/scenarios.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/equivalence/test_equivalence.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/equivalence/test_rust_timebase.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_backends.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_batch.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_benchmarks.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_cli.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_dsl.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_engine_ir.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_lang.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_model.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_ns3.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_profinet.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_semantics.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_simulation.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_stats.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_sweep.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_timebase.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/tests/test_validate.py +0 -0
- {smolpy-1.10.2 → smolpy-1.10.3.dev2}/uv.lock +0 -0
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
# ADR-0011: Bounded Switch Buffers with Frame Loss
|
|
2
|
+
|
|
3
|
+
**Status:** Proposed
|
|
4
|
+
**Date:** 2026-11-23
|
|
5
|
+
**Amends:** ADR-0007 (a new optional field of the IR, which stays version 2), ADR-0004 (the `smol-ns3` line format becomes version 2), [Model Semantics](../model-semantics.md) §3, §5, §8 and §9
|
|
6
|
+
**Roadmap:** the candidate "Bounded switch buffers with frame loss"
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## Context
|
|
11
|
+
|
|
12
|
+
Model Semantics §3 says: *"Queues are unbounded, so no frame is ever dropped for lack of buffer."* Below saturation that costs nothing. Near saturation and above it, it is where the model and a real network part ways.
|
|
13
|
+
|
|
14
|
+
**A hardware testbed shows where.** The setup:
|
|
15
|
+
- **Switch:** a TP-Link LS108GP, an unmanaged 8 × 1 Gb/s store-and-forward switch.
|
|
16
|
+
- **Traffic:** a Raspberry Pi on a 1 Gb/s port sends Poisson UDP traffic, 1 518 B frames, to a laptop whose port runs at 100 Mb/s.
|
|
17
|
+
- **Polling:** the laptop polls a Modbus TCP server on the Pi every 10 ms. The responses share the laptop's egress port with the UDP stream.
|
|
18
|
+
|
|
19
|
+
| Offered load ρ of the 100 Mb/s port | Measured | SMOLPy (unbounded queues) |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| up to 0.93 | Modbus RTT: mean wait, median, p90, p99 | the same, within a few percent |
|
|
22
|
+
| 0.996 | RTT capped at about 9.8 ms; 0.09 % of UDP frames lost | median 11 ms, p99 79 ms, nothing lost |
|
|
23
|
+
|
|
24
|
+
The cap and the loss point to a bounded egress buffer of about 115 kB, or about 75 frames of 1 538 B on the wire: 75 × 1 538 × 8 / 100 Mb/s = 9.2 ms. An unbounded queue at ρ ≈ 1 grows without limit, and so does the delay it predicts.
|
|
25
|
+
|
|
26
|
+
The same limitation appears in the ns-3 load study ([Execution backends](../backends.md#modbus-and-mqtt-over-tcp)). There nothing is dropped, so ns-3's TCP never retransmits, and its overload behaviour comes only from its windows.
|
|
27
|
+
|
|
28
|
+
### Options considered
|
|
29
|
+
|
|
30
|
+
- **A — keep unbounded queues** and document the limit of validity. Cheap, but the model then cannot be used at and above saturation, which is where industrial networks are dimensioned.
|
|
31
|
+
- **B — a bounded egress buffer per switch port, with tail drop.** **Chosen.** It is what the unmanaged switches of the testbed do. It needs one new scenario parameter, and every engine can reproduce it exactly.
|
|
32
|
+
- **C — a shared buffer pool per switch with dynamic thresholds**, as managed switches have. Closer to some hardware, but the sharing policy is vendor-specific and has no single correct model. It stays a possible later extension of B (below).
|
|
33
|
+
- **D — active queue management (RED, CoDel).** Not what industrial unmanaged switches do. Out of scope.
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
## Decision
|
|
38
|
+
|
|
39
|
+
### The parameter
|
|
40
|
+
|
|
41
|
+
A switch takes an optional **egress buffer limit in bytes**, the same for each of its ports:
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
switch sw ports=8 buffer=115000
|
|
45
|
+
switch sw ports=8 buffer=115kB # 115 000 B
|
|
46
|
+
switch sw ports=8 buffer=112KiB # 114 688 B
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
sw = net.switch("sw", ports=8, buffer=115_000)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- **Unit: bytes.** Real switches allocate buffer memory by size, not by frame count. A limit in frames would let 64 B and 1 518 B frames take the same space.
|
|
54
|
+
- **Suffixes** in `.smol`: `kB` (10³), `MB` (10⁶), `KiB` (2¹⁰), `MiB` (2²⁰). The value must come out as a whole number of bytes. The Python API takes an `int`.
|
|
55
|
+
- **Default: unbounded,** as now. A scenario without `buffer` means exactly what it meant before: same results, same event counts, same benchmark hashes (B1–B4) and the same equivalence suite.
|
|
56
|
+
- **Validation.** `buffer` must be a positive integer, not a bool. It must be at least one maximum frame: 1 522 B, the largest standard frame with an 802.1Q tag, and at least the largest frame that any traffic statement of the scenario sends. A jumbo flow would otherwise be dropped in full at every bounded switch it crosses.
|
|
57
|
+
- **IR.** `SwitchNode.buffer_bytes: int | None = None`, `None` meaning unbounded.
|
|
58
|
+
|
|
59
|
+
### What occupies the buffer
|
|
60
|
+
|
|
61
|
+
- **Frame bytes.** A frame occupies its size as defined in Model Semantics §2: header to FCS, its 802.1Q tag included, without the preamble, SFD or gap. That is how switches account buffer memory, and how `bytes_sent` and `bytes_received` already count.
|
|
62
|
+
- **Only waiting frames.** The buffer holds exactly the frames that `queue_depth` counts: those queued on the port and not yet taken by its transmitter. **The frame in transmission does not occupy the buffer.**
|
|
63
|
+
- It has left the queue: one notion of "queued" serves both `queue_depth` and the limit.
|
|
64
|
+
- The delay a frame can see is then bounded simply: what is queued ahead of it, plus at most one frame in transmission (below).
|
|
65
|
+
- A real switch also holds the frame it is sending, so its memory is `buffer` plus one frame per port. For the testbed that is one frame in 76, or 1.3 %: `buffer` is the switch's memory less one maximum frame.
|
|
66
|
+
- **When the transmitter takes a frame.** This is today's behaviour, now stated, because the limit makes it observable:
|
|
67
|
+
- when the transmitter has sent a frame's FCS, it takes the next frame at once, if there is one. That frame then waits out the inter-frame gap as part of its own transmission (§3);
|
|
68
|
+
- when the transmitter is idle, it takes a frame queued at instant `t` at the same instant, **after the events already scheduled for `t`** (§9). Frames queued in between at `t` are in the buffer together, and the transmitter takes the highest-priority one of them.
|
|
69
|
+
|
|
70
|
+
### Admission: tail drop
|
|
71
|
+
|
|
72
|
+
A frame of size `s` that arrives at a port with `q` bytes queued:
|
|
73
|
+
- is **queued** if `q + s ≤ buffer`;
|
|
74
|
+
- is **dropped** otherwise. It is never queued, and nothing else changes: no queued frame is displaced, and the transmitter does not notice.
|
|
75
|
+
|
|
76
|
+
Further rules:
|
|
77
|
+
- **Priorities.** One limit per port is shared by all 8 priority classes. The arriving frame is dropped whatever its priority. A PROFINET frame (PCP 6) that arrives at a port full of best-effort frames is lost. That is what a single-buffer unmanaged switch does. With `qos="fifo"` there is one class, and nothing else changes.
|
|
78
|
+
- **Flooding.** Each copy of a flooded frame is admitted or dropped on its own port.
|
|
79
|
+
- **Simultaneous arrivals.** Admissions at the same instant are decided in the order the frames are queued (§9). That is the order in which the switch forwards them, and within one forward, port order for flooded copies. Together with the rule on when the transmitter takes a frame, every engine decides every drop the same way.
|
|
80
|
+
- **Bound on delay.** A frame admitted with `n` frames of `q ≤ buffer − s` bytes ahead of it waits at most `tx(q + 20·n) + tx(8 + m) + tx(12)` before its own preamble starts. Here `m` is the largest frame in the scenario, for the frame in transmission and its gap. Its queueing delay is therefore at most about `buffer / speed` plus one frame time.
|
|
81
|
+
|
|
82
|
+
### Scope
|
|
83
|
+
|
|
84
|
+
- **Per egress port of a switch.** Ingress buffering is not modelled. A switch forwards in zero time (§4).
|
|
85
|
+
- **End stations stay unbounded.** The egress queues of adapters, MQTT brokers, Modbus slaves and PROFINET devices have no limit. A station never drops a frame it generates, as a host's socket buffer and qdisc would push back on the application instead. The scenario offers its traffic, and only the network loses it.
|
|
86
|
+
- **Possible later extensions, not part of this decision:**
|
|
87
|
+
- a buffer pool shared by the ports of a switch, with per-port thresholds;
|
|
88
|
+
- limits per priority class;
|
|
89
|
+
- a limit in frames, for switches that count descriptors.
|
|
90
|
+
|
|
91
|
+
### Protocols when a frame is lost
|
|
92
|
+
|
|
93
|
+
**On SimPy and Rust there is no transport layer.** SMOL sizes Modbus TCP and MQTT frames as TCP segments but models no TCP behaviour, so nothing is retransmitted:
|
|
94
|
+
- **Modbus TCP:** a lost request or response leaves its poll without a response. The master does not retry, and its next polls go out on schedule.
|
|
95
|
+
- **MQTT:**
|
|
96
|
+
- a lost PUBLISH is lost: the broker forwards nothing and sends no PUBACK;
|
|
97
|
+
- a lost forwarded copy is lost to that subscriber;
|
|
98
|
+
- a lost PUBACK changes nothing, since publishers do not wait for it.
|
|
99
|
+
- **PROFINET RT:** there is no retransmission in PROFINET RT either. A lost cyclic frame leaves a gap. If no frame arrives within `hold × cycle`, the watchdog expires (§7), as on a real device.
|
|
100
|
+
- **Flows (UDP-like):** lost.
|
|
101
|
+
|
|
102
|
+
**This is a limitation, and it is stated as one.** A real Modbus TCP or MQTT stack retransmits a lost segment, after a retransmission timeout or three duplicate acknowledgements. So the message arrives late rather than not at all, and the connection's window shrinks. **The ns-3 backend shows that behaviour.** There Modbus and MQTT run over ns-3's TCP (CUBIC, minimum RTO 1 s, fast retransmit), and a dropped segment is retransmitted. The engines therefore disagree by design on these protocols under loss: SimPy and Rust count a lost poll, while ns-3 delivers it late and shows the delay in `modbus_latency`. That difference is measured (below), not hidden.
|
|
103
|
+
|
|
104
|
+
### Metrics
|
|
105
|
+
|
|
106
|
+
| Metric | On | Value at a sample | Unit |
|
|
107
|
+
|---|---|---|---|
|
|
108
|
+
| `drops` | switch | frames its egress buffers dropped in the window. Sampled every time, 0 included. | frames |
|
|
109
|
+
| `drops_total` | switch | frames its egress buffers dropped so far | frames |
|
|
110
|
+
| `frames_sent` | adapter | frames whose transmission on the adapter's link has completed so far, as `bytes_sent` | frames |
|
|
111
|
+
| `frames_received` | adapter | frames the adapter has accepted so far, as `bytes_received` | frames |
|
|
112
|
+
| `modbus_unanswered` | adapter | Modbus requests the adapter has generated so far, less the responses it has accepted so far: lost polls plus polls in flight | polls |
|
|
113
|
+
|
|
114
|
+
- **Loss of a flow.** For a flow `a → b`, when `a` sends nothing else: lost = `frames_sent:a` − `frames_received:b`, less the frames in flight at the sample. That is at most the frames buffered on the path. Over a long run the loss ratio is `1 − frames_received:b / frames_sent:a`.
|
|
115
|
+
- **Lost polls.** `modbus_unanswered` includes polls still in flight. That is at most `⌈max RTT / poll period⌉` per poll statement, and with bounded buffers the RTT is bounded. It is a count, not a ratio: the requests generated are `rate × t`.
|
|
116
|
+
- **All counts are integers** and are reported as they are, like `pn_watchdog_expiries`.
|
|
117
|
+
- **Why not count losses per destination at the switch?** A flooded frame's copy that is dropped on a port leading away from its destination is not a loss to anyone, and the switch cannot tell which copy that is. Counts at the end stations are exact.
|
|
118
|
+
|
|
119
|
+
### The IR stays version 2
|
|
120
|
+
|
|
121
|
+
- **New field:** `SwitchNode.buffer_bytes`, optional.
|
|
122
|
+
- **No new version.** By ADR-0007's rule, a new optional field does not change the version, and only a change in meaning does. A switch without the field means what it always meant.
|
|
123
|
+
- **Nothing is run without it.** Every reader rejects fields it does not know. An engine that predates this ADR therefore rejects a document with a bounded switch instead of running it as lossless. Before that, `check()` rejects the scenario for the missing capability (below).
|
|
124
|
+
- **Written only when set.** `buffer_bytes` is left out of the JSON while it is `None`, so a document without bounded switches is byte for byte what it was before, and older readers still read it.
|
|
125
|
+
- **The Rust package.** `smolpy[rust]` requires the `smolpy-engine-rs` release that runs bounded switches.
|
|
126
|
+
|
|
127
|
+
### Capabilities
|
|
128
|
+
|
|
129
|
+
A new capability feature, `"bounded_buffer"`. `smolpy.backends.check` rejects a scenario with a bounded switch on a backend without it, naming the switch, before the run. A backend never ignores `buffer` silently. The new metrics are capabilities as usual. All three backends get the feature in this change.
|
|
130
|
+
|
|
131
|
+
### ns-3
|
|
132
|
+
|
|
133
|
+
The ns-3 backend does not use ns-3 queues for switches. Links and switches are SMOL's own (`SmolDevice`, `SmolSwitch` in `smol-ns3.cc`). So:
|
|
134
|
+
- **The limit** is implemented in `SmolDevice::Enqueue`, with a byte count of the queued frames and a drop counter. The `switch` line carries the limit: `switch <buffer bytes>`, 0 for unbounded.
|
|
135
|
+
- **The idle-port rule above.** `SmolDevice` today starts the first frame queued on an idle port at once, while SimPy and Rust take it after the events already scheduled for that instant. That difference was not observable so far, apart from a same-instant priority order no test covered. It is now, so `SmolDevice` defers the start with `Simulator::ScheduleNow`, which ns-3 orders FIFO among same-instant events, as SimPy does.
|
|
136
|
+
- **Format.** The line format becomes `smol-ns3 2`, and the observe kinds `drops`, `frames_sent`, `frames_received` and `modbus_unanswered` are added.
|
|
137
|
+
- **Expected agreement:**
|
|
138
|
+
- Ethernet over UDP and PROFINET RT stay bit-exact with SimPy, drops included, stochastic scenarios with the same seed included;
|
|
139
|
+
- Modbus and MQTT differ by TCP, as now, and now also by its retransmissions.
|
|
140
|
+
|
|
141
|
+
### Validation and tests
|
|
142
|
+
|
|
143
|
+
- **Unit tests:**
|
|
144
|
+
- validation of `buffer`;
|
|
145
|
+
- no drops while the limit is never reached;
|
|
146
|
+
- a drop exactly when `q + s > buffer`, for each class and for flooded copies;
|
|
147
|
+
- same-instant arrivals at a full queue;
|
|
148
|
+
- delay within the bound above;
|
|
149
|
+
- `drops_total` = `frames_sent` − `frames_received` − in flight, for one flow.
|
|
150
|
+
- **Analytical test.** One egress port with Poisson arrivals of fixed-size frames is an M/D/1/K queue:
|
|
151
|
+
- service time `D = tx(8 + s) + tx(12)`;
|
|
152
|
+
- `K = 1 + ⌊buffer / s⌋`: the frame in transmission and the waiting room.
|
|
153
|
+
|
|
154
|
+
Its blocking probability and mean waiting time come from the embedded Markov chain at departures. They are compared with `drops_total` / `frames_sent` and with the mean latency, over several seeds, with a tolerance from the spread across seeds. The model differs from M/D/1/K only for the first frame of a busy period, whose remaining gap is shorter than `tx(12)`. The test uses 9 000 B frames, where that is under 0.14 % of `D`.
|
|
155
|
+
- **Cross-engine:**
|
|
156
|
+
- deterministic scenarios with drops, same-instant arrivals at a full queue among them, go into the bit-exact set of SimPy and Rust, event counts included;
|
|
157
|
+
- the same Ethernet and PROFINET scenarios are compared exactly on ns-3.
|
|
158
|
+
- **The testbed scenario.** Poisson UDP of 1 518 B frames and Modbus polls every 10 ms share a 100 Mb/s port with `buffer=115000`, at ρ from 0.9 to 1.05. It runs on all three engines. The report covers the Modbus RTT (mean, median, p99, maximum), lost polls on SimPy and Rust against late polls on ns-3, and the UDP loss ratio, set against the testbed: 9.8 ms and 0.09 % at ρ = 0.996.
|
|
159
|
+
|
|
160
|
+
### Steps
|
|
161
|
+
|
|
162
|
+
1. **The model.**
|
|
163
|
+
- the optional IR field, written only when set;
|
|
164
|
+
- `buffer` in the Python API and in `.smol`, with its suffixes;
|
|
165
|
+
- validation;
|
|
166
|
+
- the capability feature, which no backend has yet, so every backend rejects a bounded switch.
|
|
167
|
+
2. **SimPy:**
|
|
168
|
+
- the limit, the drops and the five metrics;
|
|
169
|
+
- unit, semantics and M/D/1/K tests;
|
|
170
|
+
- Model Semantics updated.
|
|
171
|
+
3. **Rust:**
|
|
172
|
+
- the same;
|
|
173
|
+
- the bit-exact scenarios with drops;
|
|
174
|
+
- the `smolpy-engine-rs` floor raised.
|
|
175
|
+
4. **ns-3:**
|
|
176
|
+
- format 2, the limit and the counters, the deferred start on an idle port;
|
|
177
|
+
- the exact comparisons;
|
|
178
|
+
- the testbed scenario on all three engines, with its results recorded.
|
|
179
|
+
5. **Documentation:**
|
|
180
|
+
- language reference, DSL reference, backends;
|
|
181
|
+
- an example scenario: a 100 Mb/s bottleneck with `buffer=115000` near ρ = 1;
|
|
182
|
+
- the roadmap item moved to done.
|
|
183
|
+
|
|
184
|
+
---
|
|
185
|
+
|
|
186
|
+
## Consequences
|
|
187
|
+
|
|
188
|
+
**Positive**
|
|
189
|
+
- **The model can be used at and above saturation.** Delay is capped by the buffer, and loss appears where it does on real switches.
|
|
190
|
+
- **The testbed's knee is reproducible:** capped RTT and the onset of loss at ρ ≈ 1.
|
|
191
|
+
- **All three engines implement the same rule exactly,** so SimPy and Rust stay bit-exact and ns-3 stays bit-exact on Ethernet and PROFINET.
|
|
192
|
+
- **ns-3's TCP can now be studied under loss,** with retransmissions, which the previous load study could not show.
|
|
193
|
+
|
|
194
|
+
**Negative / trade-offs**
|
|
195
|
+
- **A new `smolpy-engine-rs` release.** `smolpy[rust]` needs the engine that runs bounded switches.
|
|
196
|
+
- **On SimPy and Rust, Modbus and MQTT simply lose messages,** where a real stack retransmits them. Results for these protocols under loss are a lower bound on delivery and say nothing about retransmission delay. ns-3 is the backend for that.
|
|
197
|
+
- **One limit per port, shared by all priorities.** Switches that reserve buffer for high priorities, or share a pool across ports, are not modelled yet.
|
|
198
|
+
- **The idle-port rule is now normative.** It was an implementation detail of SimPy, and ns-3 is changed to follow it.
|
|
@@ -72,7 +72,7 @@ link c -- sw: 'sw' has only 2 ports, all in use
|
|
|
72
72
|
|
|
73
73
|
| Element | Rules |
|
|
74
74
|
|---|---|
|
|
75
|
-
| nodes | IPv4 address; MAC address of six hex bytes; `ports` ≥ 1; switch `mode`, `qos`, `mac_table
|
|
75
|
+
| nodes | IPv4 address; MAC address of six hex bytes; `ports` ≥ 1; switch `mode`, `qos`, `mac_table`, and `buffer_bytes`, a whole number of bytes of at least 1 522 and of the largest frame in the scenario; Modbus `unit_id` 0–255 |
|
|
76
76
|
| links | not to itself; `speed` > 0; `length` ≥ 0 |
|
|
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) |
|
|
@@ -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.
|
|
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.
|
|
@@ -53,6 +53,7 @@ nav:
|
|
|
53
53
|
- ADR-0008 Rust DES Engine (MVP): adr/0008-rust-des-engine-mvp.md
|
|
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
|
+
- ADR-0011 Bounded Switch Buffers: adr/0011-bounded-switch-buffers.md
|
|
56
57
|
|
|
57
58
|
markdown_extensions:
|
|
58
59
|
- admonition
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
//! Reads Scenario IR JSON, format "smol-ir" version 2 (ADR-0007, ADR-0010)
|
|
1
|
+
//! Reads Scenario IR JSON, format "smol-ir" version 2 (ADR-0007, ADR-0010),
|
|
2
|
+
//! with the optional switch buffers of ADR-0011.
|
|
2
3
|
//!
|
|
3
4
|
//! The scenario has already been validated by `smolpy.model.validate`; this
|
|
4
5
|
//! reader is strict about structure (unknown fields, kinds and versions are
|
|
@@ -431,6 +432,10 @@ fn parse_node(value: Value, i: usize) -> Res<Node> {
|
|
|
431
432
|
Some("topology") => true,
|
|
432
433
|
Some(other) => return Err(format!("switch {name}: unknown mac_table {other:?}")),
|
|
433
434
|
};
|
|
435
|
+
match f.take_or("buffer_bytes") {
|
|
436
|
+
None | Some(Value::Null) => {}
|
|
437
|
+
Some(_) => return Err(unsupported("bounded switch buffers")),
|
|
438
|
+
}
|
|
434
439
|
NodeKind::Switch { fifo, topology }
|
|
435
440
|
}
|
|
436
441
|
"modbus_slave" => {
|
|
@@ -652,6 +657,11 @@ mod tests {
|
|
|
652
657
|
assert!(parse(&B1.replace("\"version\": 2", "\"version\": 1"))
|
|
653
658
|
.unwrap_err()
|
|
654
659
|
.contains("version 1"));
|
|
660
|
+
assert!(
|
|
661
|
+
parse(&B1.replace("\"learning\"", "\"learning\", \"buffer_bytes\": 4000"))
|
|
662
|
+
.unwrap_err()
|
|
663
|
+
.contains("bounded switch buffers")
|
|
664
|
+
);
|
|
655
665
|
assert!(
|
|
656
666
|
parse(&B1.replace("\"priority\": 0", "\"priority\": 0, \"x\": 1"))
|
|
657
667
|
.unwrap_err()
|
|
@@ -52,7 +52,8 @@ class Capabilities:
|
|
|
52
52
|
traffic: frozenset[str]
|
|
53
53
|
patterns: frozenset[str] # of flows
|
|
54
54
|
metrics: frozenset[str]
|
|
55
|
-
|
|
55
|
+
# "imix": IMIX frame sizes; "bounded_buffer": switch buffers (ADR-0011)
|
|
56
|
+
features: frozenset[str] = frozenset()
|
|
56
57
|
priorities: bool = True # 802.1Q priorities above 0 on flows
|
|
57
58
|
half_duplex: bool = False
|
|
58
59
|
dashboards: bool = False # the live and text modes of simulate()
|
|
@@ -278,6 +279,9 @@ def check(scenario: Scenario, backend: str = DEFAULT, *, dashboard: bool = False
|
|
|
278
279
|
for i, node in enumerate(scenario.nodes):
|
|
279
280
|
if node.kind not in caps.nodes:
|
|
280
281
|
raise unsupported(node, label(node.kind), ("nodes", i))
|
|
282
|
+
bounded = getattr(node, "buffer_bytes", None) is not None
|
|
283
|
+
if bounded and "bounded_buffer" not in caps.features:
|
|
284
|
+
raise unsupported(node, "bounded switch buffers", ("nodes", i))
|
|
281
285
|
for i, link in enumerate(scenario.links):
|
|
282
286
|
if not link.duplex and not caps.half_duplex:
|
|
283
287
|
raise unsupported(link, "half-duplex links", ("links", i))
|
|
@@ -142,8 +142,9 @@ class Network:
|
|
|
142
142
|
mode: SwitchMode = "store-and-forward",
|
|
143
143
|
qos: SwitchQoS = "strict",
|
|
144
144
|
mac_table: MacTableMode = "learning",
|
|
145
|
+
buffer: int | None = None,
|
|
145
146
|
) -> Switch:
|
|
146
|
-
node = Switch(name, ports=ports, mode=mode, qos=qos, mac_table=mac_table)
|
|
147
|
+
node = Switch(name, ports=ports, mode=mode, qos=qos, mac_table=mac_table, buffer=buffer)
|
|
147
148
|
self._register(node)
|
|
148
149
|
return node
|
|
149
150
|
|
|
@@ -22,6 +22,10 @@ class Switch(Node):
|
|
|
22
22
|
meanwhile. mac_table="topology" starts with the port towards every end
|
|
23
23
|
station already known (shortest path), i.e. the converged state, and
|
|
24
24
|
keeps learning on top of it.
|
|
25
|
+
|
|
26
|
+
buffer bounds every egress queue, in bytes: a frame that would take the
|
|
27
|
+
bytes waiting on its port beyond it is dropped (ADR-0011). None, the
|
|
28
|
+
default, is unbounded.
|
|
25
29
|
"""
|
|
26
30
|
|
|
27
31
|
def __init__(
|
|
@@ -31,13 +35,17 @@ class Switch(Node):
|
|
|
31
35
|
mode: SwitchMode = "store-and-forward",
|
|
32
36
|
qos: SwitchQoS = "strict",
|
|
33
37
|
mac_table: MacTableMode = "learning",
|
|
38
|
+
buffer: int | None = None,
|
|
34
39
|
) -> None:
|
|
35
40
|
super().__init__(name)
|
|
36
41
|
self.ports = ports
|
|
37
42
|
self.mode = mode
|
|
38
43
|
self.qos = qos
|
|
39
44
|
self.mac_table_mode = mac_table
|
|
45
|
+
self.buffer = buffer
|
|
40
46
|
check_node(self.to_spec())
|
|
41
47
|
|
|
42
48
|
def to_spec(self) -> SwitchNode:
|
|
43
|
-
return SwitchNode(
|
|
49
|
+
return SwitchNode(
|
|
50
|
+
self.name, self.ports, self.mode, self.qos, self.mac_table_mode, self.buffer
|
|
51
|
+
)
|
|
@@ -120,6 +120,7 @@ class _Interpreter:
|
|
|
120
120
|
mode=d.mode, # type: ignore[arg-type]
|
|
121
121
|
qos=d.qos, # type: ignore[arg-type]
|
|
122
122
|
mac_table=d.mac_table, # type: ignore[arg-type]
|
|
123
|
+
buffer=d.buffer, # type: ignore[arg-type]
|
|
123
124
|
)
|
|
124
125
|
elif isinstance(d, smol_ast.MqttBrokerDecl):
|
|
125
126
|
net.mqtt_broker(d.name, ip=d.ip)
|
|
@@ -43,6 +43,25 @@ def _coerce(raw: str) -> int | float | str:
|
|
|
43
43
|
return raw
|
|
44
44
|
|
|
45
45
|
|
|
46
|
+
_BYTE_SUFFIXES = {"kB": 10**3, "MB": 10**6, "KiB": 2**10, "MiB": 2**20}
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def _bytes(raw: Any) -> Any:
|
|
50
|
+
"""A byte count with an optional suffix (``115kB``, ``112KiB``), as an int
|
|
51
|
+
when it is a whole number of bytes. Anything else is returned as it is,
|
|
52
|
+
for validation to reject with the scenario's own message."""
|
|
53
|
+
if isinstance(raw, str):
|
|
54
|
+
for suffix, factor in _BYTE_SUFFIXES.items():
|
|
55
|
+
if raw.endswith(suffix):
|
|
56
|
+
number = _coerce(raw[: -len(suffix)])
|
|
57
|
+
if isinstance(number, (int, float)) and not isinstance(number, bool):
|
|
58
|
+
value = number * factor
|
|
59
|
+
return int(value) if value == int(value) else value
|
|
60
|
+
if isinstance(raw, float) and raw == int(raw):
|
|
61
|
+
return int(raw)
|
|
62
|
+
return raw
|
|
63
|
+
|
|
64
|
+
|
|
46
65
|
def _require(kwargs: dict[str, Any], key: str, *, file: str, line: int, stmt: str) -> Any:
|
|
47
66
|
if key not in kwargs:
|
|
48
67
|
raise SMOLSyntaxError(file, line, f"'{stmt}' is missing required argument '{key}'")
|
|
@@ -98,6 +117,7 @@ class _SmolTransformer(Transformer):
|
|
|
98
117
|
line=meta.line,
|
|
99
118
|
qos=str(kw.get("qos", "strict")),
|
|
100
119
|
mac_table=str(kw.get("mac_table", "learning")),
|
|
120
|
+
buffer=_bytes(kw["buffer"]) if "buffer" in kw else None,
|
|
101
121
|
)
|
|
102
122
|
|
|
103
123
|
def mqtt_broker_decl(self, meta: Any, children: list) -> MqttBrokerDecl:
|
|
@@ -16,6 +16,7 @@ ETHERNET_HEADER_BYTES = 14
|
|
|
16
16
|
FCS_BYTES = 4
|
|
17
17
|
VLAN_TAG_BYTES = 4 # 802.1Q, on frames with a priority above 0
|
|
18
18
|
MIN_FRAME_BYTES = 64
|
|
19
|
+
MAX_STANDARD_FRAME_BYTES = 1522 # 1 518 B and an 802.1Q tag: the least a bounded buffer holds
|
|
19
20
|
PREAMBLE_SFD_BYTES = 8
|
|
20
21
|
IFG_BYTES = 12 # inter-frame gap
|
|
21
22
|
WIRE_OVERHEAD_BYTES = PREAMBLE_SFD_BYTES + IFG_BYTES # 20 B per frame on the wire
|
|
@@ -26,6 +26,11 @@ from smolpy.core.batch import BatchSpec
|
|
|
26
26
|
FORMAT = "smol-ir"
|
|
27
27
|
VERSION = 2 # 2: Ethernet frames on the wire (ADR-0010)
|
|
28
28
|
|
|
29
|
+
# Optional fields that are left out of the JSON while they hold their default,
|
|
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"}
|
|
33
|
+
|
|
29
34
|
SwitchMode = Literal["store-and-forward", "cut-through"]
|
|
30
35
|
SwitchQoS = Literal["strict", "fifo"]
|
|
31
36
|
MacTableMode = Literal["learning", "topology"]
|
|
@@ -48,7 +53,11 @@ class AdapterNode:
|
|
|
48
53
|
|
|
49
54
|
@dataclass(frozen=True)
|
|
50
55
|
class SwitchNode:
|
|
51
|
-
"""Layer-2 switch: per-port egress queues and a MAC table.
|
|
56
|
+
"""Layer-2 switch: per-port egress queues and a MAC table.
|
|
57
|
+
|
|
58
|
+
*buffer_bytes* bounds each egress queue: the frame bytes waiting on a
|
|
59
|
+
port, the frame in transmission not counted. A frame that would exceed it
|
|
60
|
+
is dropped (ADR-0011). ``None`` is unbounded."""
|
|
52
61
|
|
|
53
62
|
kind: ClassVar[str] = "switch"
|
|
54
63
|
name: str
|
|
@@ -56,6 +65,7 @@ class SwitchNode:
|
|
|
56
65
|
mode: SwitchMode = "store-and-forward"
|
|
57
66
|
qos: SwitchQoS = "strict"
|
|
58
67
|
mac_table: MacTableMode = "learning"
|
|
68
|
+
buffer_bytes: int | None = None
|
|
59
69
|
|
|
60
70
|
|
|
61
71
|
@dataclass(frozen=True)
|
|
@@ -422,6 +432,8 @@ def _encode(obj: Any) -> dict[str, Any]:
|
|
|
422
432
|
out["kind"] = kind
|
|
423
433
|
for f in dataclasses.fields(obj):
|
|
424
434
|
value = getattr(obj, f.name)
|
|
435
|
+
if f.name in _OMITTED_WHEN_UNSET and value is None:
|
|
436
|
+
continue
|
|
425
437
|
if isinstance(value, BatchSpec):
|
|
426
438
|
value = {"kind": value.kind, "param": value.param}
|
|
427
439
|
elif isinstance(value, tuple):
|
|
@@ -20,7 +20,17 @@ from collections.abc import Mapping
|
|
|
20
20
|
from typing import Literal
|
|
21
21
|
|
|
22
22
|
from smolpy.model import timebase
|
|
23
|
-
from smolpy.model.frames import
|
|
23
|
+
from smolpy.model.frames import (
|
|
24
|
+
IMIX_SIZES,
|
|
25
|
+
MAX_STANDARD_FRAME_BYTES,
|
|
26
|
+
MIN_FRAME_BYTES,
|
|
27
|
+
PN_CYCLES_MS,
|
|
28
|
+
PN_MAX_IO_BYTES,
|
|
29
|
+
flow_frame_size,
|
|
30
|
+
modbus_response_frame_size,
|
|
31
|
+
mqtt_publish_frame_size,
|
|
32
|
+
pn_frame_size,
|
|
33
|
+
)
|
|
24
34
|
from smolpy.model.scenario import (
|
|
25
35
|
AdapterNode,
|
|
26
36
|
Flow,
|
|
@@ -168,6 +178,13 @@ def check_node(node: NodeSpec) -> None:
|
|
|
168
178
|
_one_of(node, "mode", node.mode, SWITCH_MODES)
|
|
169
179
|
_one_of(node, "qos", node.qos, SWITCH_QOS)
|
|
170
180
|
_one_of(node, "mac_table", node.mac_table, MAC_TABLES)
|
|
181
|
+
b = node.buffer_bytes
|
|
182
|
+
if b is not None and (not _integer(b) or b < MAX_STANDARD_FRAME_BYTES):
|
|
183
|
+
raise _fail(
|
|
184
|
+
node,
|
|
185
|
+
f"buffer must be a whole number of bytes, at least one maximum frame"
|
|
186
|
+
f" ({MAX_STANDARD_FRAME_BYTES} B), got {b!r}",
|
|
187
|
+
)
|
|
171
188
|
if isinstance(node, ModbusSlaveNode):
|
|
172
189
|
_in_range(node, "unit_id", node.unit_id, 0, 255)
|
|
173
190
|
|
|
@@ -229,6 +246,20 @@ def check_traffic(t: TrafficSpec, nodes: Mapping[str, NodeSpec] | None = None) -
|
|
|
229
246
|
_non_negative(t, "delay", getattr(t, "delay_ms", 0.0))
|
|
230
247
|
|
|
231
248
|
|
|
249
|
+
def _largest_frame(t: TrafficSpec) -> int:
|
|
250
|
+
"""The largest frame *t* sends, in bytes (Model Semantics §2)."""
|
|
251
|
+
if isinstance(t, Flow):
|
|
252
|
+
size = max(s for s, _ in IMIX_SIZES) if t.size == "imix" else t.size
|
|
253
|
+
return flow_frame_size(size, t.priority)
|
|
254
|
+
if isinstance(t, Publish):
|
|
255
|
+
return mqtt_publish_frame_size(t.topic, t.payload, t.qos)
|
|
256
|
+
if isinstance(t, Poll):
|
|
257
|
+
return modbus_response_frame_size(t.count)
|
|
258
|
+
if isinstance(t, ProfinetAR):
|
|
259
|
+
return pn_frame_size(max(t.inputs, t.outputs))
|
|
260
|
+
return 0 # a route forwards PUBLISH frames, sized by their publish
|
|
261
|
+
|
|
262
|
+
|
|
232
263
|
def _check_batch(t: Flow) -> None:
|
|
233
264
|
b = t.batch
|
|
234
265
|
assert b is not None
|
|
@@ -324,6 +355,16 @@ def validate(scenario: Scenario) -> None:
|
|
|
324
355
|
raise _fail(t, "topic is routed twice")
|
|
325
356
|
routes.add((t.broker, t.topic))
|
|
326
357
|
|
|
358
|
+
largest = max((_largest_frame(t) for t in scenario.traffic), default=0)
|
|
359
|
+
for i, node in enumerate(scenario.nodes):
|
|
360
|
+
if isinstance(node, SwitchNode) and node.buffer_bytes is not None:
|
|
361
|
+
if node.buffer_bytes < largest:
|
|
362
|
+
raise ScenarioError(
|
|
363
|
+
f"{describe(node)}: buffer {node.buffer_bytes} B is smaller than the"
|
|
364
|
+
f" largest frame of the scenario, {largest} B, which it would always drop",
|
|
365
|
+
("nodes", i),
|
|
366
|
+
)
|
|
367
|
+
|
|
327
368
|
observed: set[tuple[str, str]] = set()
|
|
328
369
|
for i, o in enumerate(scenario.observations):
|
|
329
370
|
with _at("observations", i):
|
|
@@ -224,6 +224,10 @@ def lower(scenario: model.Scenario) -> tuple[str, list[_Sampler]]:
|
|
|
224
224
|
lines = [f"smol-ns3 {FORMAT_VERSION}", f"duration {tb.ms_to_ns(scenario.run.duration_ms)}"]
|
|
225
225
|
for n in scenario.nodes:
|
|
226
226
|
if isinstance(n, model.SwitchNode):
|
|
227
|
+
if n.buffer_bytes is not None: # never run as unbounded (ADR-0011)
|
|
228
|
+
raise ValueError(
|
|
229
|
+
f"switch {n.name!r}: the ns3 backend does not support bounded switch buffers"
|
|
230
|
+
)
|
|
227
231
|
lines.append("switch")
|
|
228
232
|
else:
|
|
229
233
|
lines.append(f"adapter {n.mac} {n.ip}") # a station, with IPv4
|