Aller au contenu principal

Time-Sensitive Networking (TSN)

IEEE 802.1 TSN support for deterministic Ethernet communication with priority tagging, scheduled transmission, and capability detection.

Linux Only

Full TSN support requires Linux (kernel >= 4.19 for SO_TXTIME). Other platforms use a stub backend that returns unsupported errors.

Overview

TSN extends standard Ethernet with deterministic delivery guarantees. HDDS integrates with Linux TSN infrastructure to provide:

  • Priority tagging -- SO_PRIORITY mapped to traffic classes (mqprio) and VLAN PCP
  • Scheduled TX -- SO_TXTIME + SCM_TXTIME for "send-at-time" (LaunchTime)
  • Capability detection -- Runtime probe of TSN features (ETF, TAPRIO, HW timestamping)

Architecture

+---------------------------------------------------------+
| Application |
| write() / write_at(txtime) / write_with(WriteOptions) |
+---------------------+-----------------------------------+
|
+---------------------v-----------------------------------+
| DataWriter |
| TsnConfig (from TopicQos or WriterQos override) |
+---------------------+-----------------------------------+
|
+---------------------v-----------------------------------+
| UdpTransport |
| TX Socket Pool (keyed by SocketProfile) |
| TsnBackend (LinuxTsnBackend / NullTsnBackend) |
+---------------------------------------------------------+

Configuration

TsnConfig

use hdds::transport::tsn::{TsnConfig, TsnEnforcement, TxTimePolicy};
use std::time::Duration;

// Enable TSN with priority tagging
let config = TsnConfig::new()
.with_priority(6) // PCP 6 (high priority)
.strict(); // Fail if TSN not available

// With scheduled TX
let config = TsnConfig::new()
.with_priority(6)
.with_txtime(TxTimePolicy::Mandatory)
.with_lead_time(Duration::from_micros(500));

Priority Presets

HDDS provides preset configurations mapping to standard priority levels.

PresetPCPPriority LevelUse Case
high_priority()6P0Commands, safety-critical
normal_priority()4P1Normal data
low_priority()2P2Telemetry, best-effort
use hdds::transport::tsn::TsnConfig;

let high = TsnConfig::high_priority(); // PCP 6
let normal = TsnConfig::normal_priority(); // PCP 4
let low = TsnConfig::low_priority(); // PCP 2

Configuration Options

OptionDefaultDescription
enabledfalseMaster switch for TSN features
enforcementBestEffortBehavior when capabilities are missing
pcpNoneVLAN Priority Code Point (0-7)
dscpNoneIP DSCP value (0-63) for L3 QoS
traffic_classNonemqprio traffic class index
tx_timeDisabledTimed send policy
clock_idTaiReference clock for txtime
lead_time_ns500,000 (500 us)Delta added to now() for auto txtime
strict_deadlinefalseDrop if txtime is exceeded
srp_stream_idNone802.1Qat stream reservation ID
frerNone802.1CB Frame Replication config (future)

Enforcement Modes

ModeDescription
BestEffortDegrade silently if TSN unavailable (counter + debug log)
StrictError if prerequisites are missing
use hdds::transport::tsn::{TsnConfig, TsnEnforcement};

// Best-effort: works everywhere, degrades gracefully
let config = TsnConfig::new().with_priority(6);

// Strict: fail fast if TSN is not properly configured
let config = TsnConfig::new().with_priority(6).strict();

TX Time Policies

Control how HDDS uses SO_TXTIME for scheduled transmission.

PolicyDescription
DisabledStandard sendto(), no txtime (default)
OpportunisticUse SO_TXTIME if available, fall back to sendto()
MandatoryRequire SO_TXTIME, error if unavailable
use hdds::transport::tsn::{TsnConfig, TxTimePolicy};
use std::time::Duration;

let config = TsnConfig::new()
.with_priority(6)
.with_txtime(TxTimePolicy::Mandatory)
.with_lead_time(Duration::from_micros(500));

Clock Sources

The reference clock determines how txtime values are computed.

use hdds::transport::tsn::TsnClockId;

TsnClockId::Tai // CLOCK_TAI (PTP-synced, recommended for production)
TsnClockId::Monotonic // CLOCK_MONOTONIC (dev/test, not synced across hosts)
TsnClockId::Realtime // CLOCK_REALTIME (avoid -- leap second issues)
TsnClockId::Phc(path) // Direct PHC device (e.g., "/dev/ptp0")
Clock Selection

For production TSN deployments, use TsnClockId::Tai with PTP synchronization. CLOCK_MONOTONIC is acceptable for development and testing but is not synchronized across hosts. Avoid CLOCK_REALTIME due to leap second discontinuities.

Capability Detection

Probe the system for TSN support at runtime.

use hdds::transport::tsn::TsnProbe;

let caps = TsnProbe::probe("eth0")?;
println!("SO_TXTIME: {:?}", caps.so_txtime);
println!("ETF qdisc: {:?}", caps.etf_configured);
println!("TAPRIO qdisc: {:?}", caps.taprio_configured);
println!("mqprio: {:?}", caps.mqprio_configured);
println!("HW timestamping: {:?}", caps.hw_timestamping);
println!("PHC device: {:?}", caps.phc_device);

Support Levels

Each capability reports one of:

LevelDescription
UnsupportedFeature not available
SupportedFeature available (software)
SupportedWithOffloadFeature available with hardware offload

System Requirements

  • Linux kernel >= 4.19 for SO_TXTIME support
  • ETF qdisc configured for scheduled transmission
  • TAPRIO qdisc for time-aware scheduling
  • mqprio qdisc for traffic class mapping
  • PTP synchronization for cross-host time coordination

Traffic Policy

HDDS maps DDS priority levels to TSN traffic policies.

use hdds::transport::tsn::{Priority, TrafficPolicy, DropPolicy};

// P0: critical traffic (PCP 6) -- immediate, retransmit
// P1: normal traffic (PCP 4) -- batched, no retransmit
// P2: telemetry (PCP 2) -- batched, drop on congestion
PriorityPCPDrop PolicyDescription
P06BestEffortCritical/reliable, immediate flush
P14BestEffortImportant, batched
P22DropIfLateTelemetry, dropped on congestion

TSN Metrics

HDDS tracks TSN-related metrics via atomic counters.

// Metrics snapshot includes:
// - priority_set: number of sockets with SO_PRIORITY set
// - txtime_enabled: number of sockets with SO_TXTIME
// - txtime_sends: successful timed sends
// - regular_sends: standard sends (no txtime)
// - dropped_late: packets dropped due to late txtime
// - dropped_other: packets dropped for other reasons
// - txtime_fallbacks: txtime-to-regular fallbacks
// - txtime_failures: txtime send failures
// - probes: capability probes performed
// - error_queue_drains: error queue drain operations

The TsnMetricsSnapshot provides derived metrics:

  • txtime_ratio() -- ratio of timed sends to total sends
  • drop_rate() -- ratio of drops to total sends

Linux Network Setup

TSN requires proper network configuration. Here is a minimal setup example:

mqprio (Traffic Class Mapping)

# Map 3 traffic classes to hardware queues
sudo tc qdisc add dev eth0 root handle 1: mqprio \
num_tc 3 \
map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \
queues 1@0 1@1 1@2 \
hw 0

ETF (Earliest TxTime First)

# Configure ETF on queue 0 with CLOCK_TAI
sudo tc qdisc add dev eth0 parent 1:1 etf \
clockid CLOCK_TAI \
delta 500000 \
offload

TAPRIO (Time-Aware Priority)

# Configure TAPRIO with a 1ms cycle
sudo tc qdisc replace dev eth0 parent root handle 100 taprio \
num_tc 3 \
map 2 2 1 0 2 2 2 2 2 2 2 2 2 2 2 2 \
queues 1@0 1@1 1@2 \
base-time 0 \
sched-entry S 01 300000 \
sched-entry S 02 300000 \
sched-entry S 04 400000 \
clockid CLOCK_TAI

Platform Support

PlatformStatusDetails
LinuxFull supportSO_PRIORITY, SO_TXTIME, ETF/TAPRIO detection
OthersStub backendNullTsnBackend returns unsupported errors

Limitations

LimitationDescription
Linux onlyFull TSN requires Linux kernel >= 4.19
Network configRequires proper qdisc setup (mqprio, ETF, TAPRIO)
PTP syncCross-host txtime requires PTP synchronization
PHC clockPhc clock requires fd-to-clockid conversion (not yet automated)
802.1CB FRERFrame Replication config is reserved for future use
No C FFITSN configuration is not yet exposed in the C API

Next Steps