zerodds_transport_tsn/lib.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 ZeroDDS Contributors
3//! DDS Extensions for Time Sensitive Networking (DDS-TSN) 1.0.
4//!
5//! Crate `zerodds-transport-tsn`. Safety classification: **STANDARD**.
6//! Spec `formal/2024-05-16` (`docs/standards/cache/omg/dds-tsn-1.0-beta2.pdf`).
7//!
8//! # Scope
9//!
10//! We implement the **configuration model PIM** (Spec §7.2)
11//! and the **DDSI-RTPS Ethernet PSM** (Spec Annex A) as a pure-Rust
12//! no_std+alloc library:
13//!
14//! * `IEEE802VlanTag` (Spec Tab 7.21) — TPID + PCP + DEI + VID per
15//! IEEE 802.1Q.
16//! * `IEEE802MacAddresses` (Spec Tab 7.20) — 6-byte MAC with
17//! multicast/broadcast detection.
18//! * `TrafficSpecification` (Spec Tab 7.16) — Interval/Max-Frame-Size/
19//! Max-Frames-per-Interval/Transmission-Selection per IEEE 802.1Qcc.
20//! * `TimeAware` (Spec Tab 7.17) — earliest/latest_transmit_offset +
21//! jitter per IEEE 802.1Qbv.
22//! * `TsnTalker` + `TsnListener` + `TsnConfiguration` (Spec Tab 7.15 +
23//! 7.24 + Figure 7.3) — stream configuration model incl.
24//! `network_requirements` + `datawriter_ref`.
25//! * `NetworkRequirements` (Spec Tab 7.18/7.25) — `num_seamless_trees`
26//! + `max_latency` (IEEE 802.1CB FRER redundancy + latency bound).
27//! * `DataFrameSpecification` (Spec Tab 7.19) — frame header filter
28//! with MAC + VLAN + IPv4/v6 tuple (incl. `dscp` from Tab 7.22/7.23).
29//! * `Dscp` (RFC 2474) — Differentiated Services Code Point.
30//! * **YANG PSM** (Spec §7.3.3, [`pim::yang`]) — transformation of the
31//! configuration model into `group-talker`/`group-listener` (UNI
32//! CUC→CNC), incl. `stream-id-type`, `interface-capabilities` and
33//! an RFC-7951 YANG-JSON renderer. The XML/JSON PSM (§7.3.1/§7.3.2) is in
34//! [`pim::xml`]/[`pim::json`].
35//! * **Live AF_PACKET transport** (Spec Annex A, feature `live`,
36//! Linux) — `socket::TsnTransport` sends/receives RTPS directly in the
37//! Ethernet frame (EtherType 0x88B5); frame logic in `live_frame`.
38//!
39//! # What is not covered
40//!
41//! * **TSN UNI wire protocol** — proprietary (caller layer, dependent
42//! on the bridge vendor such as Cisco IE/Hirschmann/etc.). We provide the
43//! YANG group representation (§7.3.3); its transport over the
44//! concrete UNI protocol is the caller layer.
45//! * **Hardware acceleration** (TX timestamping via
46//! `SO_TIMESTAMPING`/PHC) — caller layer with an OS-specific API.
47//! * **gPTP / 802.1AS time-sync daemon** — caller layer (typically
48//! `linuxptp/ptp4l` external).
49//!
50//! # Hardware validation (as of 2026-06)
51//!
52//! The configuration model, the PSM renderers (YANG/XML/JSON) and the
53//! frame/wire logic ([`ethernet_psm`] + `live_frame`) are
54//! hardware-independent and fully unit-tested. **Not** verified against
55//! real TSN hardware are the *time-critical guarantees*
56//! themselves — time-aware shaping (IEEE 802.1Qbv), frame preemption (802.1Qbu),
57//! FRER redundancy (802.1CB) and gPTP sync (802.1AS) — as well as the throughput/
58//! latency of the `live` AF_PACKET path (`socket`, feature `live`). This
59//! is **not a code blocker**, but a pure validation gap: TSN-capable
60//! NIC/switch hardware (with a configured
61//! Qbv gate schedule + PTP grandmaster) is currently missing. On such hardware the
62//! `live` path is the integration point; the TSN guarantees are then provided by the
63//! network (bridges) + an external `ptp4l`/`tc-taprio`, which this
64//! library configures rather than enforces itself.
65
66// The spec model is unsafe-free; only the optional `live` AF_PACKET
67// transport (socket.rs) needs libc unsafe.
68#![cfg_attr(not(feature = "live"), forbid(unsafe_code))]
69#![warn(missing_docs)]
70
71extern crate alloc;
72
73pub mod data_frame;
74pub mod dscp;
75pub mod ethernet_psm;
76pub mod mac;
77pub mod network_requirements;
78pub mod pim;
79pub mod stream;
80pub mod time_aware;
81pub mod traffic;
82pub mod vlan_tag;
83
84#[cfg(feature = "std")]
85pub mod config;
86
87/// Platform-independent frame helpers for the live transport
88/// (feature `live`). Testable on every platform.
89#[cfg(feature = "live")]
90pub mod live_frame;
91
92/// Live AF_PACKET transport (Linux-only, feature `live`). Empty on
93/// other platforms.
94#[cfg(feature = "live")]
95pub mod socket;
96
97pub use data_frame::{DataFrameSpecification, IPv4Tuple, IPv6Tuple};
98pub use dscp::Dscp;
99pub use ethernet_psm::{ETHERTYPE_RTPS, EthernetFrameHeader};
100pub use mac::MacAddress;
101pub use network_requirements::NetworkRequirements;
102pub use stream::{StreamIdentifier, TsnConfiguration, TsnListener, TsnTalker};
103pub use time_aware::TimeAware;
104pub use traffic::{TrafficSpecification, TransmissionSelection};
105pub use vlan_tag::{Ieee802VlanTag, TPID_8021AD, TPID_8021Q};
106
107#[cfg(all(feature = "live", target_os = "linux"))]
108pub use socket::TsnTransport;
109
110// Note: the legacy `config::TsnConfiguration` (old simplified
111// top-level config) is deliberately NOT re-exported at the crate root, to
112// avoid colliding with the spec `stream::TsnConfiguration` (Figure 7.3 talker/
113// listener aggregate). It remains reachable as `config::TsnConfiguration`.
114#[cfg(feature = "std")]
115pub use config::{
116 ConfigError, DeploymentLibrary, DomainLibrary, QosProfileEntry, TsnQosLibrary,
117 parse_xml_config, render_json_config,
118};