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)

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.2.0.tar.gz (10.7 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.2.0-py3-none-any.whl (8.9 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for scapy_gptp-0.2.0.tar.gz
Algorithm Hash digest
SHA256 dfb710a1422054bf8a166c7dd0b0c6347d9b51aa17f55593170c89ba913d0099
MD5 01a75d374bcf10efaf3a3fc9b0d16730
BLAKE2b-256 6675a561f26e831daed1c34de2376180b3df7ddef6380a75ed9cfa1a1a930580

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for scapy_gptp-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1cf8e89d3a8d82317aab6865f565aa58276c444782aa29e91e86faac4829d4cf
MD5 4752291660a90686adc82d8f72d07c95
BLAKE2b-256 a0c2a4dc8b02bc62deeb126faa63f46c252ad76dc558ae431d1885c751fa02fe

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