Skip to main content

scapy-gptp - scapy layer definition and tools for GPTP (IEEE 802.1as)

PyPI - Version PyPI - License PyPI - Python Version

This python module contains the layer definition for PTPv2 (GPTP) which includes custom definitions for Timestamp and ClockIdentity fields. It further provide some handy utils when analyzing PTPv2 traces.

Usage

The PTPv2 layer is automatically bound to the Ethernet layer based on its type field (0x88F7). Just import the PTPv2 layer definition to make scapy aware of this bond and for example read a pcap file to dissect

from gptp.layers import PTPv2
from scapy.utils import rdpcap

pcap = rdpcap("traces.pcap")

for p in pcap:
    if p.haslayer('PTPv2'):
        p.show()

which yields something like

###[ Ethernet ]###
  dst       = 01:83:b0:02:21:fe
  src       = 7a:1b:31:80:11:06
  type      = 0x88f7
###[ PTPv2 ]###
     transportSpecific= 1
     messageType= Sync
     reserved0 = 0x0
     versionPTP= 2
     messageLength= 44
     domainNumber= 0
     reserved1 = 0x0
     flags     = TIMESCALE+TWO_STEP
     correctionField= 0
     reserved2 = 0x0
     sourcePortIdentity= 7a:1b:31:80:11:06/1
     sequenceId= 2081
     control   = 0x0
     logMessageInterval= -3
     reserved3 = None
###[ Padding ]###
        load      = '\x00\x00\x00\x00\x00\x00'

A handy addition when analyzing PTP traces is the MatchedList from utils module. You can add PTP packets to it and it will automatically find matching (Sync, FollowUp) message pairs as well as (PdelayReq, PdelayResp, PdelayRespFollowUp) message triplets, providing them as lists for easy processing and analysis.

from gptp.utils import MatchedList

pcap = rdpcap("traces.pcap")
matched_list = MatchedList([p for p in pcap if p.haslayer('PTPv2')])

(sync, fup) = matched_list.sync[0]
assert sync.sequenceId == fup.sequenceId
print(fup.preciseOriginTimestamp)  # prints 1602135835.0758622

Metadata

Release files for scapy-gptp 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for scapy-gptp 0.3.0
File Size Uploaded
scapy_gptp-0.3.0.tar.gz 10.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for scapy-gptp 0.3.0
File Interpreter ABI Platform
scapy_gptp-0.3.0-py3-none-any.whl Python 3 none any Details

Total release size: 22.7 kB

Release files / scapy_gptp-0.3.0.tar.gz

Download URL scapy_gptp-0.3.0.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
9af450e46cadb8c60fb38cd23f339ad68a47260d45188a8e84103a77909d194a
BLAKE2b-256 checksum
How to use checksums
9ed7899cc8b050d29211032d3f420d3cd22d661c902596e5623ff5ff9180b0aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release files / scapy_gptp-0.3.0-py3-none-any.whl

Download URL scapy_gptp-0.3.0-py3-none-any.whl
Size 11.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4ad32ea95ae84dd442f00af26d26f370e0ed680219c63acb583accda806ccd1d
BLAKE2b-256 checksum
How to use checksums
40d11902e618146b9be8a3791b1860f83544495d70c6285b8e532925d5cc8f17
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.19

Release history Release notifications | RSS feed

This release

0.3.0 This release

2 release files

0.2.1

2 release files

0.2.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page