Skip to main content

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

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scapy_gptp-0.3.0.tar.gz (10.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

scapy_gptp-0.3.0-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file scapy_gptp-0.3.0.tar.gz.

File metadata

  • Download URL: scapy_gptp-0.3.0.tar.gz
  • Upload date:
  • Size: 10.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for scapy_gptp-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9af450e46cadb8c60fb38cd23f339ad68a47260d45188a8e84103a77909d194a
MD5 a7d7aea3bf2a8ffa45de753a2a81fa5d
BLAKE2b-256 9ed7899cc8b050d29211032d3f420d3cd22d661c902596e5623ff5ff9180b0aa

See more details on using hashes here.

File details

Details for the file scapy_gptp-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: scapy_gptp-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 11.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.19

File hashes

Hashes for scapy_gptp-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ad32ea95ae84dd442f00af26d26f370e0ed680219c63acb583accda806ccd1d
MD5 693fa7694f2a9964ca5af216dcc38702
BLAKE2b-256 40d11902e618146b9be8a3791b1860f83544495d70c6285b8e532925d5cc8f17

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page