Skip to content

holoplot/ptp-trace

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ•ฐ๏ธ PTP Trace

A powerful cross-platform terminal-based application for monitoring and analyzing PTPv2 (Precision Time Protocol) networks in real-time with full keyboard and mouse support.

License Rust Platform

โœจ Features

๐Ÿ–ฅ๏ธ Interactive Terminal UI

  • ๐Ÿ“Š Real-time dashboard with multiple panels
  • ๐ŸŽจ Multiple themes: Default, Monokai, Matrix
  • โŒจ๏ธ Intuitive keyboard navigation
  • ๐Ÿ–ฑ๏ธ Mouse support - Click to switch views, select rows, and navigate content
  • ๐Ÿ“ฑ Responsive layout that adapts to terminal size
  • ๐Ÿ”„ Live updates without screen flicker
  • โธ๏ธ Pause mode to temporarily stop network parsing for UI inspection

๐ŸŒ Network Monitoring

  • ๐Ÿ” Automatic PTP and gPTP host discovery (UDP ports 319/320 and Ethernet 0x88f7)
  • ๐Ÿ“ก Cross-platform packet capture - Uses pnet for live capturing on Linux, macOS, and Windows
  • ๐ŸŒ Dual protocol support - Handles both PTP over UDP (Layer 3) and gPTP over Ethernet (Layer 2, IEEE 802.1AS)
  • ๐Ÿ“„ PCAP file support - Read and analyze PTP packets from captured pcap files (offline analysis mode)
  • ๐ŸŒ Multicast group membership - Ensures network interfaces receive multicast PTP traffic
  • ๐Ÿ” Full packet analysis - Records both raw packet data and parsed PTP content
  • ๐ŸŽฏ Smart interface selection - Automatically filters virtual interfaces while supporting manual override
  • ๐Ÿท๏ธ Host classification by PTP state
  • ๐Ÿ† BMCA (Best Master Clock Algorithm) - Automatic primary time transmitter detection
  • ๐Ÿ“Š Primary Time Transmitter marked with "PTT" indicator
  • ๐Ÿ“ˆ Network statistics and quality metrics
  • ๐Ÿ• Timing relationship tracking
  • โธ๏ธ Time reference modes - Live network uses current system time; pcap mode uses last packet timestamp as reference
  • ๐ŸŒณ Tree view mode - Hierarchical display showing transmitter-receiver relationships with proper indentation and PTT (Primary Time Transmitter) indicators
  • ๐ŸŒณ Visual hierarchy mapping of transmitter-receiver relationships
  • ๐Ÿท๏ธ VLAN support - Detects and displays VLAN tags in PTP packets

๐Ÿ“‹ Host Management

  • ๐Ÿ“ Comprehensive host table with sortable columns
  • ๐Ÿ”ข Multiple sort options (State, IP, Clock Identity, Domain, etc.)
  • ๐ŸŽฏ Selection tracking across operations
  • ๐Ÿ“Š Quality indicators and confidence levels
  • ๐Ÿ” OUI database integration to show vendor information
  • โญ Local machine identification: Your own machine is marked with asterisks (*) in the host list and details
  • ๐Ÿ–ฑ๏ธ Mouse-enabled selection - Click on any host row to select it instantly

๐Ÿ“ฆ Packet Analysis

  • ๐Ÿ“‹ Real-time packet history with version identification
  • ๐ŸŽจ Color-coded message types (ANNOUNCE, SYNC, DELAY_REQ, PDELAY_REQ, etc.)
  • ๐ŸŒ Interface-aware capture - Tracks which interface each packet was received on
  • ๐Ÿ–ฑ๏ธ Interactive packet selection - Click to select packets, double-click for detailed view
  • ๐Ÿ“œ Scroll wheel support - Navigate through packet history with mouse wheel

๐Ÿ“„ PCAP File Analysis

PTP Trace supports offline analysis of PTP traffic from pcap files in offline mode.

Creating PCAP Files:

# Capture PTP traffic with tcpdump (Linux/macOS)
sudo tcpdump -i eth0 -w ptp_capture.pcap 'udp port 319 or udp port 320 or ether proto 0x88f7'

# Capture with Wireshark (all platforms)
# Filter: udp.port == 319 or udp.port == 320 or eth.type == 0x88f7
# Save as: ptp_capture.pcap

# Analyze the captured file
./target/release/ptp-trace --pcap-file ptp_capture.pcap

Demo

Demo

๐Ÿš€ Quick Start

๐Ÿ“‹ Prerequisites

  • ๐Ÿฆ€ Rust 1.70.0 or later
  • ๐Ÿ”ง Administrator privileges required - Needed for promiscuous mode packet capture (in live capture mode)
  • ๐ŸŒ Network interfaces with PTP traffic (ports 319/320)
  • ๐Ÿ“ฆ Platform-specific requirements:
    • macOS: Xcode command line tools (xcode-select --install)
    • Windows: WinPcap or Npcap installed

๐Ÿ”จ Installation

# Clone the repository
git clone https://github.com/holoplot/ptp-trace.git
cd ptp-trace

# Build from source
cargo build --release

# Run with default settings (requires root)
sudo ./target/release/ptp-trace

โš™๏ธ Command Line Options

# ๐Ÿ“„ Analyze packets from pcap file (offline mode, no admin privileges needed)
./target/release/ptp-trace --pcap-file capture.pcap

# ๐ŸŒ Monitor specific interface (requires root)
sudo ./target/release/ptp-trace --interface eth0

# ๐ŸŒ Monitor multiple interfaces (requires admin privileges)
sudo ./target/release/ptp-trace --interface eth0 --interface eth1        # Linux/macOS

# ๐ŸŒ Monitor all suitable interfaces (default behavior, requires admin privileges)
# Automatically excludes virtual interfaces (Docker, VPN, etc.)
sudo ./target/release/ptp-trace                                          # Linux/macOS
./target/release/ptp-trace.exe                                          # Windows (as Administrator)

# ๐ŸŒ Force monitoring of virtual interfaces (requires explicit specification)
sudo ./target/release/ptp-trace --interface docker0 --interface br-123456

# โšก Faster updates (500ms)
sudo ./target/release/ptp-trace --update-interval 500

# ๐ŸŽจ Use Matrix theme
sudo ./target/release/ptp-trace --theme matrix

# ๐Ÿ–ฑ๏ธ Disable mouse support (enabled by default)
sudo ./target/release/ptp-trace --no-mouse

# ๐Ÿ“„ Analyze pcap file with custom theme and faster updates
./target/release/ptp-trace --pcap-file capture.pcap --theme matrix --update-interval 250

# ๐Ÿ› Enable debug mode
sudo ./target/release/ptp-trace --debug

# ๐Ÿ”ง Combine options for live monitoring
sudo ./target/release/ptp-trace --interface eth0 --interface eth1 --theme matrix --update-interval 500 --no-mouse

# Note: --interface and --pcap-file options are mutually exclusive

๐ŸŽฎ Controls

๐ŸŽฎ Navigation

  • Tab - ๐Ÿ”„ Cycle between views: Host Table โ†’ Host Details โ†’ Packet History
  • โ†‘ / k - ๐Ÿ“ˆ Move selection up (host table) or scroll up (details/packets)
  • โ†“ / j - ๐Ÿ“‰ Move selection down (host table) or scroll down (details/packets)
  • PgUp / PgDn - ๐Ÿ“„ Page navigation (10 items) or scroll by page
  • Home / End - ๐Ÿ  Jump to top/bottom
  • Enter - ๐Ÿ“‹ Show packet details modal (when packet history is active)
  • q - ๐Ÿšช Close packet details modal (when modal is open) or quit application
  • Esc - ๐Ÿšช Close help screen

๐Ÿ–ฑ๏ธ Mouse Support (enabled by default, disable with --no-mouse)

  • Click - ๐ŸŽฏ Switch to view and select row (host table/packet history)
  • Double-click - ๐Ÿ“‹ Open packet details modal (packet history rows)
  • Click outside modal - ๐Ÿšช Close packet details modal (or use 'q' key)
  • Scroll wheel - ๐Ÿ”„ Navigate selections/scroll content (3 lines per scroll)

๐Ÿ“Š Table Operations

  • s - ๐Ÿ”„ Cycle sort columns
  • S - โ†•๏ธ Toggle sort direction
  • a - โฌ…๏ธ Previous sort column
  • t - ๐ŸŒณ Toggle tree view mode
  • Green headers indicate active sort column

๐ŸŽฌ Actions

  • r - ๐Ÿ”„ Refresh/rescan network
  • Ctrl+L - ๐Ÿ”„ Refresh/redraw screen
  • c - ๐Ÿ—‘๏ธ Clear hosts and packet history
  • x - ๐Ÿ—‘๏ธ Clear packet history for selected host
  • p - โธ๏ธ Toggle pause mode (stops network parsing, shows "PAUSED" in header)
  • w - ๐Ÿ”„ Toggle packet auto-scroll
  • e - ๐Ÿ“Š Toggle expanded packet history
  • d - ๐Ÿ› Toggle debug mode

โ„น๏ธ Help & Exit

  • h / F1 - โ“ Show/hide help
  • Esc / q - ๐Ÿšช Close help screen
  • q - ๐Ÿšซ Close modal/help or quit application

๐Ÿ“‹ Interface Behavior

  • Three-way navigation: Use Tab to cycle between Host Table, Host Details, and Packet History
  • Scrollable views: Host Details and Packet History are fully scrollable with arrow keys, Page Up/Down, Home/End
  • Preserved selections: Packet selection is maintained when switching views until you select a different host
  • Auto-scroll control: Packet auto-scroll is disabled when manually navigating, re-enable with w
  • Smart resets: Scroll positions reset to top when selecting a different host
  • Mouse integration: Mouse and keyboard controls work seamlessly together
  • Accessibility: Use --no-mouse flag to disable mouse support if needed

โœŠ Terminology & Inclusive Language

In accordance with IEEE 1588g-2022, this project uses inclusive terminology to describe the roles of network components.

๐Ÿ”„ Term Mapping

Inclusive term Industry Standard Description
Time Transmitter Master Clock Device that provides timing reference
Time Receiver Slave Clock Device that synchronizes to timing reference
Primary Time Transmitter (PTT) Grandmaster Clock Best master clock selected by BMCA algorithm

The underlying PTP protocol and packet structures remain unchanged - only the user-facing terminology has been modernized for clarity and inclusivity.

A blog post from Meinberg has more information about the topic.

๐ŸŽจ Themes

Choose from multiple built-in themes. See the output of ptp-trace --help to get a list of available themes.

๐Ÿšง Current Status

โœ… Implemented Features

  • ๐Ÿ–ผ๏ธ Complete terminal UI framework
  • ๐ŸŽฎ Application structure and navigation
  • ๐Ÿ“Š Host table with sorting and scrolling
  • ๐Ÿ“ฆ Packet history with detailed view
  • ๐ŸŽจ Multiple theme support
  • โŒจ๏ธ Comprehensive keyboard controls
  • ๐Ÿ” Debug mode with scroll information

๐Ÿ—บ๏ธ Future Roadmap

  • ๐Ÿ“ค Data export - JSON, PCAP output formats for raw packet data
  • ๐Ÿ” Advanced filtering - Search and filter capabilities for both live and pcap modes
  • ๐Ÿ“Š Enhanced analytics - Statistical analysis of timing data
  • ๐Ÿ”ง Configuration management - Save/load application settings
  • โšก Hardware-accelerated filtering - Use BPF filters for efficient packet capture

๐Ÿ› ๏ธ Development

๐Ÿ”ง Building

# Development build
cargo build

# Optimized release build
cargo build --release

# Run tests
cargo test

# Format code
cargo fmt

# Lint code
cargo clippy

Update built-in OUI database

This project features an integrated OUI database for MAC address lookup. The information is compiled into the binary at build time so that it can be used without an internet connection from a single binary. To update the database, follow these steps:

# Update OUI database
python3 -r oui/requirements.txt
python3 oui/gen_oui_rust_phf.py >src/oui_map.rs

# Make sure to lint the code after updating the database
cargo clippy

Feel free to contribute to this project by submitting pull requests with the updated OUI database.

๐Ÿ“š Dependencies

  • ๐Ÿ–ฅ๏ธ ratatui - Terminal UI framework
  • โšก tokio - Async runtime
  • โŒจ๏ธ crossterm - Cross-platform terminal handling
  • ๐Ÿ“ clap - Command line argument parsing
  • โ— anyhow - Error handling
  • ๐Ÿ”Œ pnet - Cross-platform packet capture
  • ๐Ÿ”ง socket2 - Advanced socket operations and multicast group joining
  • ๐Ÿงฎ libc - Low-level system calls

๐Ÿค Contributing

We welcome contributions! Please:

  1. ๐Ÿด Fork the repository
  2. ๐ŸŒฟ Create a feature branch
  3. ๐Ÿ”ง Make your changes
  4. โœ… Add tests if applicable
  5. ๐Ÿ“ Update documentation
  6. ๐Ÿš€ Submit a pull request

๐Ÿ“ Code Standards

  • ๐Ÿฆ€ Follow Rust best practices
  • ๐Ÿ“ Document public APIs
  • โœ… Include tests for new features
  • ๐ŸŽจ Use cargo fmt for formatting
  • ๐Ÿ” Pass cargo clippy lints

๐Ÿ“œ License

This project is licensed under the GPLv2 License - see the LICENSE file for details.

๐Ÿ”— Related Projects

  • ๐Ÿ•ฐ๏ธ statime - Rust PTP implementation
  • ๐Ÿง ptp4l - Linux PTP daemon
  • ๐Ÿ–ผ๏ธ ratatui - Terminal UI library
  • โšก tokio - Async runtime for Rust

๐Ÿ†˜ Support

  • ๐Ÿ“– Use h or F1 in the application for interactive help
  • ๐Ÿ› Enable debug mode with d for troubleshooting
  • ๐Ÿ“ง Report issues on the project's issue tracker
  • ๐Ÿ’ฌ Join discussions for feature requests and support

๐Ÿ•ฐ๏ธ Built for precision timing networks โ€ข ๐Ÿฆ€ Written in Rust โ€ข ๐Ÿ–ฅ๏ธ Runs in your terminal