protocol

package
v0.0.0-...-b56da86 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 1, 2024 License: Apache-2.0 Imports: 11 Imported by: 2

Documentation

Overview

Package protocol implements a subset of the PTPv2.1 protocol (IEEE 1588-2019).

Implementation is focused on unicast communications over IPv6 and is sufficient to build unicast PTP server or client.

This package also contains basic management client that can be used to exchange Management Packets with ptp server.

All references throughout the code relate to the IEEE 1588-2019 Standard.

Implemented protocol parts include:

Marshalling and unmarshalling of defined PTP messages

Sync
Delay_Req
Pdelay_Req
Pdelay_Resp
Follow_Up
Delay_Resp
Pdelay_Resp_Follow_Up
Announce
Signaling
Management

TLVs

MANAGEMENT
MANAGEMENT_ERROR_STATUS
REQUEST_UNICAST_TRANSMISSION
GRANT_UNICAST_TRANSMISSION
CANCEL_UNICAST_TRANSMISSION
ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION
PATH_TRACE
ALTERNATE_TIME_OFFSET_INDICATOR

Management TLVs

DEFAULT_DATA_SET
CURRENT_DATA_SET
PARENT_DATA_SET

Non-portable ptp4l-specific Management TLVs

TIME_STATUS_NP
PORT_PROPERTIES_NP
PORT_STATS_NP
PORT_SERVICE_STATS_NP
UNICAST_MASTER_TABLE_NP

Index

Constants

View Source
const (
	MajorVersion     uint8 = 2
	MinorVersion     uint8 = 1
	Version          uint8 = MinorVersion<<4 | MajorVersion
	MajorVersionMask uint8 = 0x0f
)

what version of PTP protocol we implement

View Source
const (
	// first octet
	FlagAlternateMaster  uint16 = 1 << (8 + 0)
	FlagTwoStep          uint16 = 1 << (8 + 1)
	FlagUnicast          uint16 = 1 << (8 + 2)
	FlagProfileSpecific1 uint16 = 1 << (8 + 5)
	FlagProfileSpecific2 uint16 = 1 << (8 + 6)
	// second octet
	FlagLeap61                   uint16 = 1 << 0
	FlagLeap59                   uint16 = 1 << 1
	FlagCurrentUtcOffsetValid    uint16 = 1 << 2
	FlagPTPTimescale             uint16 = 1 << 3
	FlagTimeTraceable            uint16 = 1 << 4
	FlagFrequencyTraceable       uint16 = 1 << 5
	FlagSynchronizationUncertain uint16 = 1 << 6
)

flags used in FlagField as per Table 37 Values of flagField

View Source
const PTP4lSock = "/var/run/ptp4l"

PTP4lSock is the default path to PTP4L socket

Variables

View Source
var (
	PortEvent   = 319
	PortGeneral = 320
)

UDP port numbers: The UDP destination port of a PTP event message shall be 319. The UDP destination port of a multicast PTP general message shall be 320. The UDP destination port of a unicast PTP general message that is addressed to a PTP Instance shall be 320. The UDP destination port of a unicast PTP general message that is addressed to a manager shall be the UDP source port value of the PTP message to which this is a response.

View Source
var DefaultTargetPortIdentity = PortIdentity{
	ClockIdentity: 0xffffffffffffffff,
	PortNumber:    0xffff,
}

DefaultTargetPortIdentity is a port identity that means any port

View Source
var ErrManagementMsgErrorStatus = errors.New("received MANAGEMENT_ERROR_STATUS_TLV")

ErrManagementMsgErrorStatus is what happens if we expected to get Management TLV in response, but received special ManagementErrorStatusTLV

View Source
var ManagementErrorIDToString = map[ManagementErrorID]string{
	ErrorResponseTooBig: "RESPONSE_TOO_BIG",
	ErrorNoSuchID:       "NO_SUCH_ID",
	ErrorWrongLength:    "WRONG_LENGTH",
	ErrorWrongValue:     "WRONG_VALUE",
	ErrorNotSetable:     "NOT_SETABLE",
	ErrorNotSupported:   "NOT_SUPPORTED",
	ErrorUnpopulated:    "UNPOPULATED",
	ErrorGeneralError:   "GENERAL_ERROR",
}

ManagementErrorIDToString is a map from ManagementErrorID to string

View Source
var MessageTypeToString = map[MessageType]string{
	MessageSync:               "SYNC",
	MessageDelayReq:           "DELAY_REQ",
	MessagePDelayReq:          "PDELAY_REQ",
	MessagePDelayResp:         "PDELAY_RES",
	MessageFollowUp:           "FOLLOW_UP",
	MessageDelayResp:          "DELAY_RESP",
	MessagePDelayRespFollowUp: "PDELAY_RESP_FOLLOW_UP",
	MessageAnnounce:           "ANNOUNCE",
	MessageSignaling:          "SIGNALING",
	MessageManagement:         "MANAGEMENT",
}

MessageTypeToString is a map from MessageType to string

View Source
var PortStateToString = map[PortState]string{
	PortStateInitializing: "INITIALIZING",
	PortStateFaulty:       "FAULTY",
	PortStateDisabled:     "DISABLED",
	PortStateListening:    "LISTENING",
	PortStatePreMaster:    "PRE_MASTER",
	PortStateMaster:       "MASTER",
	PortStatePassive:      "PASSIVE",
	PortStateUncalibrated: "UNCALIBRATED",
	PortStateSlave:        "SLAVE",
	PortStateGrandMaster:  "GRAND_MASTER",
}

PortStateToString is a map from PortState to string

View Source
var TLVTypeToString = map[TLVType]string{
	TLVManagement:                           "MANAGEMENT",
	TLVManagementErrorStatus:                "MANAGEMENT_ERROR_STATUS",
	TLVOrganizationExtension:                "ORGANIZATION_EXTENSION",
	TLVRequestUnicastTransmission:           "REQUEST_UNICAST_TRANSMISSION",
	TLVGrantUnicastTransmission:             "GRANT_UNICAST_TRANSMISSION",
	TLVCancelUnicastTransmission:            "CANCEL_UNICAST_TRANSMISSION",
	TLVAcknowledgeCancelUnicastTransmission: "ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION",
	TLVPathTrace:                            "PATH_TRACE",
	TLVAlternateTimeOffsetIndicator:         "ALTERNATE_TIME_OFFSET_INDICATOR",
}

TLVTypeToString is a map from TLVType to string

View Source
var TimeSourceToString = map[TimeSource]string{
	TimeSourceAtomicClock:        "ATOMIC_CLOCK",
	TimeSourceGNSS:               "GNSS",
	TimeSourceTerrestrialRadio:   "TERRESTRIAL_RADIO",
	TimeSourceSerialTimeCode:     "SERIAL_TIME_CODE",
	TimeSourcePTP:                "PTP",
	TimeSourceNTP:                "NTP",
	TimeSourceHandSet:            "HAND_SET",
	TimeSourceOther:              "OTHER",
	TimeSourceInternalOscillator: "INTERNAL_OSCILLATOR",
}

TimeSourceToString is a map from TimeSource to string

View Source
var TransportTypeToString = map[TransportType]string{
	TransportTypeUDS:        "UDS",
	TransportTypeUDPIPV4:    "UDP_IPV4",
	TransportTypeUDPIPV6:    "UDP_IPV6",
	TransportTypeIEEE8023:   "IEEE_802_3",
	TransportTypeDeviceNet:  "DEVICENET",
	TransportTypeControlNet: "CONTROLNET",
	TransportTypePROFINET:   "PROFINET",
}

TransportTypeToString is a map from TransportType to string

View Source
var UnicastMasterStateToString = map[UnicastMasterState]string{
	UnicastMasterStateWait:         "WAIT",
	UnicastMasterStateHaveAnnounce: "HAVE_ANN",
	UnicastMasterStateNeedSYDY:     "NEED_SYDY",
	UnicastMasterStateHaveSYDY:     "HAVE_SYDY",
}

UnicastMasterStateToString is a map from UnicastMasterState to string

Functions

func Bytes

func Bytes(p Packet) ([]byte, error)

Bytes converts any packet to []bytes PTP over UDPv6 requires adding extra two bytes that may be modified by the initiator or an intermediate PTP Instance to ensure that the UDP checksum remains uncompromised after any modification of PTP fields. We simply always add them - in worst case they add extra 2 unused bytes when used over UDPv4.

func BytesTo

func BytesTo(p BinaryMarshalerTo, buf []byte) (int, error)

BytesTo marshalls packets that support this optimized marshalling into []byte

func FromBytes

func FromBytes(rawBytes []byte, p Packet) error

FromBytes parses []byte into any packet

func RegisterMgmtTLVDecoder

func RegisterMgmtTLVDecoder(id ManagementID, decoder MgmtTLVDecoderFunc)

RegisterMgmtTLVDecoder registers function we'll use to decode particular custom management TLV. IEEE1588-2019 specifies that range C000 – DFFF should be used for implementation-specific identifiers, and E000 – FFFE is to be assigned by alternate PTP Profile.

Types

type AcknowledgeCancelUnicastTransmissionTLV

type AcknowledgeCancelUnicastTransmissionTLV struct {
	TLVHead
	MsgTypeAndFlags UnicastMsgTypeAndFlags // first 4 bits is msg type, then flags R and/or G
	Reserved        uint8
}

AcknowledgeCancelUnicastTransmissionTLV Table 113 ACKNOWLEDGE_CANCEL_UNICAST_TRANSMISSION TLV format

func (*AcknowledgeCancelUnicastTransmissionTLV) MarshalBinaryTo

func (t *AcknowledgeCancelUnicastTransmissionTLV) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to AcknowledgeCancelUnicastTransmissionTLV

func (*AcknowledgeCancelUnicastTransmissionTLV) UnmarshalBinary

func (t *AcknowledgeCancelUnicastTransmissionTLV) UnmarshalBinary(b []byte) error

UnmarshalBinary parses []byte and populates struct fields

type Action

type Action uint8

Action indicate the action to be taken on receipt of the PTP message as defined in Table 57

const (
	GET Action = iota
	SET
	RESPONSE
	COMMAND
	ACKNOWLEDGE
)

actions as in Table 57 Values of the actionField

type AlternateTimeOffsetIndicatorTLV

type AlternateTimeOffsetIndicatorTLV struct {
	TLVHead
	KeyField       uint8
	CurrentOffset  int32
	JumpSeconds    int32
	TimeOfNextJump PTPSeconds // uint48
	DisplayName    PTPText
}

AlternateTimeOffsetIndicatorTLV is a Table 116 ALTERNATE_TIME_OFFSET_INDICATOR TLV format

func (*AlternateTimeOffsetIndicatorTLV) MarshalBinaryTo

func (t *AlternateTimeOffsetIndicatorTLV) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to AlternateTimeOffsetIndicatorTLV

func (*AlternateTimeOffsetIndicatorTLV) UnmarshalBinary

func (t *AlternateTimeOffsetIndicatorTLV) UnmarshalBinary(b []byte) error

UnmarshalBinary parses []byte and populates struct fields

type Announce

type Announce struct {
	Header
	AnnounceBody
	TLVs []TLV
}

Announce is a full Announce packet

func (*Announce) MarshalBinary

func (p *Announce) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

func (*Announce) MarshalBinaryTo

func (p *Announce) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to Announce

func (*Announce) UnmarshalBinary

func (p *Announce) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals bytes to Announce

type AnnounceBody

type AnnounceBody struct {
	OriginTimestamp         Timestamp
	CurrentUTCOffset        int16
	Reserved                uint8
	GrandmasterPriority1    uint8
	GrandmasterClockQuality ClockQuality
	GrandmasterPriority2    uint8
	GrandmasterIdentity     ClockIdentity
	StepsRemoved            uint16
	TimeSource              TimeSource
}

AnnounceBody Table 43 Announce message fields

type BinaryMarshalerTo

type BinaryMarshalerTo interface {
	MarshalBinaryTo([]byte) (int, error)
}

BinaryMarshalerTo is an interface implemented by an object that can marshal itself into a binary form into provided []byte

type CancelUnicastTransmissionTLV

type CancelUnicastTransmissionTLV struct {
	TLVHead
	MsgTypeAndFlags UnicastMsgTypeAndFlags // first 4 bits is msg type, then flags R and/or G
	Reserved        uint8
}

CancelUnicastTransmissionTLV Table 112 CANCEL_UNICAST_TRANSMISSION TLV format

func (*CancelUnicastTransmissionTLV) MarshalBinaryTo

func (t *CancelUnicastTransmissionTLV) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to CancelUnicastTransmissionTLV

func (*CancelUnicastTransmissionTLV) UnmarshalBinary

func (t *CancelUnicastTransmissionTLV) UnmarshalBinary(b []byte) error

UnmarshalBinary parses []byte and populates struct fields

type ClockAccuracy

type ClockAccuracy uint8

ClockAccuracy represents a PTP clock accuracy

const (
	ClockAccuracyNanosecond25       ClockAccuracy = 0x20
	ClockAccuracyNanosecond100      ClockAccuracy = 0x21
	ClockAccuracyNanosecond250      ClockAccuracy = 0x22
	ClockAccuracyMicrosecond1       ClockAccuracy = 0x23
	ClockAccuracyMicrosecond2point5 ClockAccuracy = 0x24
	ClockAccuracyMicrosecond10      ClockAccuracy = 0x25
	ClockAccuracyMicrosecond25      ClockAccuracy = 0x26
	ClockAccuracyMicrosecond100     ClockAccuracy = 0x27
	ClockAccuracyMicrosecond250     ClockAccuracy = 0x28
	ClockAccuracyMillisecond1       ClockAccuracy = 0x29
	ClockAccuracyMillisecond2point5 ClockAccuracy = 0x2A
	ClockAccuracyMillisecond10      ClockAccuracy = 0x2B
	ClockAccuracyMillisecond25      ClockAccuracy = 0x2C
	ClockAccuracyMillisecond100     ClockAccuracy = 0x2D
	ClockAccuracyMillisecond250     ClockAccuracy = 0x2E
	ClockAccuracySecond1            ClockAccuracy = 0x2F
	ClockAccuracySecond10           ClockAccuracy = 0x30
	ClockAccuracySecondGreater10    ClockAccuracy = 0x31
	ClockAccuracyUnknown            ClockAccuracy = 0xFE
)

Available Clock Accuracy https://datatracker.ietf.org/doc/html/rfc8173#section-7.6.2.5

func ClockAccuracyFromOffset

func ClockAccuracyFromOffset(offset time.Duration) ClockAccuracy

ClockAccuracyFromOffset returns PTP Clock Accuracy covering the time.Duration

func (ClockAccuracy) Duration

func (c ClockAccuracy) Duration() time.Duration

Duration returns matching time.Duration of PTP Clock Accuracy

type ClockAccuracyTLV

type ClockAccuracyTLV struct {
	ManagementTLVHead

	ClockAccuracy ClockAccuracy
	Reserved      uint8
}

ClockAccuracyTLV is a TLV containing Clock Accuracy

type ClockClass

type ClockClass uint8

ClockClass represents a PTP clock class

const (
	ClockClass6         ClockClass = 6
	ClockClass7         ClockClass = 7
	ClockClass13        ClockClass = 13
	ClockClass14        ClockClass = 14
	ClockClass52        ClockClass = 52
	ClockClass58        ClockClass = 58
	ClockClassSlaveOnly ClockClass = 255
)

Available Clock Classes https://datatracker.ietf.org/doc/html/rfc8173#section-7.6.2.4

type ClockIdentity

type ClockIdentity uint64

The ClockIdentity type identifies unique entities within a PTP Network, e.g. a PTP Instance or an entity of a common service.

func NewClockIdentity

func NewClockIdentity(mac net.HardwareAddr) (ClockIdentity, error)

NewClockIdentity creates new ClockIdentity from MAC address

func (ClockIdentity) MAC

func (c ClockIdentity) MAC() net.HardwareAddr

MAC turns ClockIdentity into the MAC address it was based upon. EUI-48 is assumed.

func (ClockIdentity) String

func (c ClockIdentity) String() string

String formats ClockIdentity same way ptp4l pmc client does

type ClockQuality

type ClockQuality struct {
	ClockClass              ClockClass    `json:"clock_class"`
	ClockAccuracy           ClockAccuracy `json:"clock_accuracy"`
	OffsetScaledLogVariance uint16        `json:"offset_scaled_log_variance"`
}

ClockQuality represents the quality of a clock.

type Correction

type Correction IntFloat

Correction is the value of the correction measured in nanoseconds and multiplied by 2**16. For example, 2.5 ns is represented as 0000 0000 0002 8000 base 16 A value of one in all bits, except the most significant, of the field shall indicate that the correction is too big to be represented.

func NewCorrection

func NewCorrection(ns float64) Correction

NewCorrection returns Correction built from Nanoseconds

func (Correction) Nanoseconds

func (t Correction) Nanoseconds() float64

Nanoseconds decodes Correction to human-understandable nanoseconds

func (Correction) String

func (t Correction) String() string

func (Correction) TooBig

func (t Correction) TooBig() bool

TooBig means correction is too big to be represented.

type CurrentDataSetTLV

type CurrentDataSetTLV struct {
	ManagementTLVHead

	StepsRemoved     uint16
	OffsetFromMaster TimeInterval
	MeanPathDelay    TimeInterval
}

CurrentDataSetTLV Spec Table 84 - CURRENT_DATA_SET management TLV data field

type DefaultDataSetTLV

type DefaultDataSetTLV struct {
	ManagementTLVHead

	SoTSC         uint8
	Reserved0     uint8
	NumberPorts   uint16
	Priority1     uint8
	ClockQuality  ClockQuality
	Priority2     uint8
	ClockIdentity ClockIdentity
	DomainNumber  uint8
	Reserved1     uint8
}

DefaultDataSetTLV Spec Table 69 - DEFAULT_DATA_SET management TLV data field

type DelayResp

type DelayResp struct {
	Header
	DelayRespBody
}

DelayResp is a full Delay_Resp packet

func (*DelayResp) MarshalBinary

func (p *DelayResp) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

func (*DelayResp) MarshalBinaryTo

func (p *DelayResp) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to DelayResp

func (*DelayResp) UnmarshalBinary

func (p *DelayResp) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals bytes to DelayResp

type DelayRespBody

type DelayRespBody struct {
	ReceiveTimestamp       Timestamp
	RequestingPortIdentity PortIdentity
}

DelayRespBody Table 46 Delay_Resp message fields

type FollowUp

type FollowUp struct {
	Header
	FollowUpBody
}

FollowUp is a full Follow_Up packet

func (*FollowUp) MarshalBinary

func (p *FollowUp) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

func (*FollowUp) MarshalBinaryTo

func (p *FollowUp) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to FollowUp

func (*FollowUp) UnmarshalBinary

func (p *FollowUp) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals bytes to FollowUp

type FollowUpBody

type FollowUpBody struct {
	PreciseOriginTimestamp Timestamp
}

FollowUpBody Table 45 Follow_Up message fields

type GrantUnicastTransmissionTLV

type GrantUnicastTransmissionTLV struct {
	TLVHead
	MsgTypeAndReserved    UnicastMsgTypeAndFlags // first 4 bits only, same enums as with normal message type
	LogInterMessagePeriod LogInterval
	DurationField         uint32
	Reserved              uint8
	Renewal               uint8
}

GrantUnicastTransmissionTLV Table 111 GRANT_UNICAST_TRANSMISSION TLV format

func (*GrantUnicastTransmissionTLV) MarshalBinaryTo

func (t *GrantUnicastTransmissionTLV) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to GrantUnicastTransmissionTLV

func (*GrantUnicastTransmissionTLV) UnmarshalBinary

func (t *GrantUnicastTransmissionTLV) UnmarshalBinary(b []byte) error

UnmarshalBinary parses []byte and populates struct fields

type Header struct {
	SdoIDAndMsgType     SdoIDAndMsgType // first 4 bits is SdoId, next 4 bytes are msgtype
	Version             uint8
	MessageLength       uint16
	DomainNumber        uint8
	MinorSdoID          uint8
	FlagField           uint16
	CorrectionField     Correction
	MessageTypeSpecific uint32
	SourcePortIdentity  PortIdentity
	SequenceID          uint16
	ControlField        uint8       // the use of this field is obsolete according to IEEE, unless it's ipv4
	LogMessageInterval  LogInterval // see Table 42 Values of logMessageInterval field
}

Header Table 35 Common PTP message header

func (*Header) MessageType

func (p *Header) MessageType() MessageType

MessageType returns MessageType

func (*Header) SetSequence

func (p *Header) SetSequence(sequence uint16)

SetSequence populates sequence field

type IntFloat

type IntFloat int64

IntFloat is a float64 stored in int64

func (IntFloat) Value

func (t IntFloat) Value() float64

Value decodes IntFloat to float64

type LogInterval

type LogInterval int8

LogInterval shall be the logarithm, to base 2, of the requested period in seconds. In layman's terms, it's specified as a power of two in seconds.

const MgmtLogMessageInterval LogInterval = 0x7f // as per Table 42 Values of logMessageInterval field

MgmtLogMessageInterval is the default LogInterval value used in Management packets

func NewLogInterval

func NewLogInterval(d time.Duration) (LogInterval, error)

NewLogInterval returns new LogInterval from time.Duration. The values of these logarithmic attributes shall be selected from integers in the range -128 to 127 subject to further limits established in the applicable PTP Profile.

func (LogInterval) Duration

func (i LogInterval) Duration() time.Duration

Duration returns LogInterval as time.Duration

type Management

type Management struct {
	ManagementMsgHead
	TLV ManagementTLV
}

Management packet, see '15. PTP management messages'

func ClockAccuracyRequest

func ClockAccuracyRequest() *Management

ClockAccuracyRequest prepares request packet for CLOCK_ACCURACY request

func CurrentDataSetRequest

func CurrentDataSetRequest() *Management

CurrentDataSetRequest prepares request packet for CURRENT_DATA_SET request

func DefaultDataSetRequest

func DefaultDataSetRequest() *Management

DefaultDataSetRequest prepares request packet for DEFAULT_DATA_SET request

func ParentDataSetRequest

func ParentDataSetRequest() *Management

ParentDataSetRequest prepares request packet for PARENT_DATA_SET request

func PortPropertiesNPRequest

func PortPropertiesNPRequest() *Management

PortPropertiesNPRequest prepares request packet for PORT_STATS_NP request

func PortServiceStatsNPRequest

func PortServiceStatsNPRequest() *Management

PortServiceStatsNPRequest prepares request packet for PORT_SERVICE_STATS_NP request

func PortStatsNPRequest

func PortStatsNPRequest() *Management

PortStatsNPRequest prepares request packet for PORT_STATS_NP request

func TimeStatusNPRequest

func TimeStatusNPRequest() *Management

TimeStatusNPRequest prepares request packet for TIME_STATUS_NP request

func UnicastMasterTableNPRequest

func UnicastMasterTableNPRequest() *Management

UnicastMasterTableNPRequest creates new packet with UNICAST_MASTER_TABLE_NP request

func (*Management) MarshalBinary

func (p *Management) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

func (*Management) MarshalBinaryToBuf

func (p *Management) MarshalBinaryToBuf(bytes io.Writer) error

MarshalBinaryToBuf converts packet to bytes and writes those into provided buffer

func (*Management) UnmarshalBinary

func (p *Management) UnmarshalBinary(rawBytes []byte) error

UnmarshalBinary parses []byte and populates struct fields

type ManagementErrorID

type ManagementErrorID uint16

ManagementErrorID is an enum for possible management errors

const (
	ErrorResponseTooBig ManagementErrorID = 0x0001 // The requested operation could not fit in a single response message
	ErrorNoSuchID       ManagementErrorID = 0x0002 // The managementId is not recognized
	ErrorWrongLength    ManagementErrorID = 0x0003 // The managementId was identified but the length of the data was wrong
	ErrorWrongValue     ManagementErrorID = 0x0004 // The managementId and length were correct but one or more values were wrong
	ErrorNotSetable     ManagementErrorID = 0x0005 // Some of the variables in the set command were not updated because they are not configurable
	ErrorNotSupported   ManagementErrorID = 0x0006 // The requested operation is not supported in this PTP Instance
	ErrorUnpopulated    ManagementErrorID = 0x0007 // The targetPortIdentity of the PTP management message refers to an entity that is not present in the PTP Instance at the time of the request
	// some reserved and provile-specific ranges
	ErrorGeneralError ManagementErrorID = 0xFFFE //An error occurred that is not covered by other ManagementErrorID values
)

Table 109 ManagementErrorID enumeration

func (ManagementErrorID) Error

func (t ManagementErrorID) Error() string

func (ManagementErrorID) String

func (t ManagementErrorID) String() string

type ManagementErrorStatusTLV

type ManagementErrorStatusTLV struct {
	TLVHead

	ManagementErrorID ManagementErrorID
	ManagementID      ManagementID
	Reserved          int32
	DisplayData       PTPText
}

ManagementErrorStatusTLV spec Table 108 MANAGEMENT_ERROR_STATUS TLV format

type ManagementID

type ManagementID uint16

ManagementID is type for Management IDs

const (
	IDNullPTPManagement        ManagementID = 0x0000
	IDClockDescription         ManagementID = 0x0001
	IDUserDescription          ManagementID = 0x0002
	IDSaveInNonVolatileStorage ManagementID = 0x0003
	IDResetNonVolatileStorage  ManagementID = 0x0004
	IDInitialize               ManagementID = 0x0005
	IDFaultLog                 ManagementID = 0x0006
	IDFaultLogReset            ManagementID = 0x0007

	IDDefaultDataSet        ManagementID = 0x2000
	IDCurrentDataSet        ManagementID = 0x2001
	IDParentDataSet         ManagementID = 0x2002
	IDTimePropertiesDataSet ManagementID = 0x2003
	IDPortDataSet           ManagementID = 0x2004
	IDClockAccuracy         ManagementID = 0x2010
)

Management IDs we support, from Table 59 managementId values

const (
	IDTimeStatusNP         ManagementID = 0xC000
	IDPortPropertiesNP     ManagementID = 0xC004
	IDPortStatsNP          ManagementID = 0xC005
	IDPortServiceStatsNP   ManagementID = 0xC007
	IDUnicastMasterTableNP ManagementID = 0xC008
)

ptp4l-specific management TLV ids

type ManagementMsgErrorStatus

type ManagementMsgErrorStatus struct {
	ManagementMsgHead
	ManagementErrorStatusTLV
}

ManagementMsgErrorStatus is header + ManagementErrorStatusTLV

func (*ManagementMsgErrorStatus) MarshalBinary

func (p *ManagementMsgErrorStatus) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

func (*ManagementMsgErrorStatus) MarshalBinaryToBuf

func (p *ManagementMsgErrorStatus) MarshalBinaryToBuf(bytes io.Writer) error

MarshalBinaryToBuf converts packet to bytes and writes those into provided buffer

func (*ManagementMsgErrorStatus) UnmarshalBinary

func (p *ManagementMsgErrorStatus) UnmarshalBinary(rawBytes []byte) error

UnmarshalBinary parses []byte and populates struct fields

type ManagementMsgHead

type ManagementMsgHead struct {
	Header

	TargetPortIdentity   PortIdentity
	StartingBoundaryHops uint8
	BoundaryHops         uint8
	ActionField          Action
	Reserved             uint8
}

ManagementMsgHead Spec Table 56 - Management message fields

func (*ManagementMsgHead) Action

func (p *ManagementMsgHead) Action() Action

Action returns ActionField

type ManagementTLV

type ManagementTLV interface {
	TLV
	MgmtID() ManagementID
}

ManagementTLV abstracts away any ManagementTLV

type ManagementTLVHead

type ManagementTLVHead struct {
	TLVHead

	ManagementID ManagementID
}

ManagementTLVHead Spec Table 58 - Management TLV fields

func (*ManagementTLVHead) MgmtID

func (p *ManagementTLVHead) MgmtID() ManagementID

MgmtID returns ManagementID

type MessageType

type MessageType uint8

MessageType is type for Message Types

const (
	MessageSync               MessageType = 0x0
	MessageDelayReq           MessageType = 0x1
	MessagePDelayReq          MessageType = 0x2
	MessagePDelayResp         MessageType = 0x3
	MessageFollowUp           MessageType = 0x8
	MessageDelayResp          MessageType = 0x9
	MessagePDelayRespFollowUp MessageType = 0xA
	MessageAnnounce           MessageType = 0xB
	MessageSignaling          MessageType = 0xC
	MessageManagement         MessageType = 0xD
)

As per Table 36 Values of messageType field

func ProbeMsgType

func ProbeMsgType(data []byte) (msg MessageType, err error)

ProbeMsgType reads first 8 bits of data and tries to decode it to SdoIDAndMsgType, then return MessageType

func (MessageType) String

func (m MessageType) String() string

type MgmtClient

type MgmtClient struct {
	Connection io.ReadWriter
	Sequence   uint16
}

MgmtClient talks to ptp server over unix socket

func (*MgmtClient) ClockAccuracy

func (c *MgmtClient) ClockAccuracy() (*ClockAccuracyTLV, error)

ClockAccuracy sends CLOCK_ACCURACY request and returns response

func (*MgmtClient) Communicate

func (c *MgmtClient) Communicate(packet *Management) (*Management, error)

Communicate sends the management the packet, parses response into something usable

func (*MgmtClient) CurrentDataSet

func (c *MgmtClient) CurrentDataSet() (*CurrentDataSetTLV, error)

CurrentDataSet sends CURRENT_DATA_SET request and returns response

func (*MgmtClient) DefaultDataSet

func (c *MgmtClient) DefaultDataSet() (*DefaultDataSetTLV, error)

DefaultDataSet sends DEFAULT_DATA_SET request and returns response

func (*MgmtClient) ParentDataSet

func (c *MgmtClient) ParentDataSet() (*ParentDataSetTLV, error)

ParentDataSet sends PARENT_DATA_SET request and returns response

func (*MgmtClient) PortPropertiesNP

func (c *MgmtClient) PortPropertiesNP() (*PortPropertiesNPTLV, error)

PortPropertiesNP sends PORT_PROPERTIES_NP request and returns response

func (*MgmtClient) PortServiceStatsNP

func (c *MgmtClient) PortServiceStatsNP() (*PortServiceStatsNPTLV, error)

PortServiceStatsNP sends PORT_SERVICE_STATS_NP request and returns response

func (*MgmtClient) PortStatsNP

func (c *MgmtClient) PortStatsNP() (*PortStatsNPTLV, error)

PortStatsNP sends PORT_STATS_NP request and returns response

func (*MgmtClient) SendPacket

func (c *MgmtClient) SendPacket(packet *Management) error

SendPacket sends packet, incrementing sequence counter

func (*MgmtClient) TimeStatusNP

func (c *MgmtClient) TimeStatusNP() (*TimeStatusNPTLV, error)

TimeStatusNP sends TIME_STATUS_NP request and returns response

func (*MgmtClient) UnicastMasterTableNP

func (c *MgmtClient) UnicastMasterTableNP() (*UnicastMasterTableNPTLV, error)

UnicastMasterTableNP request UNICAST_MASTER_TABLE_NP from ptp4l, and returns the result

type MgmtTLVDecoderFunc

type MgmtTLVDecoderFunc func(data []byte) (ManagementTLV, error)

MgmtTLVDecoderFunc is the function we use to decode management TLV from bytes

type PDelayReq

type PDelayReq struct {
	Header
	PDelayReqBody
}

PDelayReq is a full Pdelay_Req packet

type PDelayReqBody

type PDelayReqBody struct {
	OriginTimestamp Timestamp
	Reserved        [10]uint8
}

PDelayReqBody Table 47 Pdelay_Req message fields

type PDelayResp

type PDelayResp struct {
	Header
	PDelayRespBody
}

PDelayResp is a full Pdelay_Resp packet

type PDelayRespBody

type PDelayRespBody struct {
	RequestReceiptTimestamp Timestamp
	RequestingPortIdentity  PortIdentity
}

PDelayRespBody Table 48 Pdelay_Resp message fields

type PDelayRespFollowUp

type PDelayRespFollowUp struct {
	Header
	PDelayRespFollowUpBody
}

PDelayRespFollowUp is a full Pdelay_Resp_Follow_Up packet

type PDelayRespFollowUpBody

type PDelayRespFollowUpBody struct {
	ResponseOriginTimestamp Timestamp
	RequestingPortIdentity  PortIdentity
}

PDelayRespFollowUpBody Table 49 Pdelay_Resp_Follow_Up message fields

type PTPSeconds

type PTPSeconds [6]uint8 // uint48

PTPSeconds type representing seconds

func NewPTPSeconds

func NewPTPSeconds(t time.Time) PTPSeconds

NewPTPSeconds creates a new instance of PTPSeconds

func (PTPSeconds) Empty

func (s PTPSeconds) Empty() bool

Empty returns 0 seconds

func (PTPSeconds) Seconds

func (s PTPSeconds) Seconds() uint64

Seconds returns number of seconds as uint64

func (PTPSeconds) String

func (s PTPSeconds) String() string

String returns number of seconds in as String

func (PTPSeconds) Time

func (s PTPSeconds) Time() time.Time

Time returns number of seconds in as Time

type PTPText

type PTPText string

PTPText data type is used to represent textual material in PTP messages. TextField is encoded as UTF-8. The most significant byte of the leading text symbol shall be the element of the array with index 0. UTF-8 encoding has variable length, thus LengthField can be larger than number of characters.

type PTPText struct {
	LengthField uint8
	TextField   []byte
}

func (*PTPText) MarshalBinary

func (p *PTPText) MarshalBinary() ([]byte, error)

MarshalBinary converts ptptext to []bytes

func (*PTPText) UnmarshalBinary

func (p *PTPText) UnmarshalBinary(rawBytes []byte) error

UnmarshalBinary populates ptptext from bytes

type Packet

type Packet interface {
	MessageType() MessageType
	SetSequence(uint16)
}

Packet is an interface to abstract all different packets

func DecodePacket

func DecodePacket(b []byte) (Packet, error)

DecodePacket provides single entry point to try and decode any []bytes to PTPv2 packet. It can be used for easy integration with anything that provides UDP packet payload as bytes. Resulting Packet user can then either switch based on MessageType(), or just with type switch.

type ParentDataSetTLV

type ParentDataSetTLV struct {
	ManagementTLVHead

	ParentPortIdentity                    PortIdentity
	PS                                    uint8
	Reserved                              uint8
	ObservedParentOffsetScaledLogVariance uint16
	ObservedParentClockPhaseChangeRate    uint32
	GrandmasterPriority1                  uint8
	GrandmasterClockQuality               ClockQuality
	GrandmasterPriority2                  uint8
	GrandmasterIdentity                   ClockIdentity
}

ParentDataSetTLV Spec Table 85 - PARENT_DATA_SET management TLV data field

type PathTraceTLV

type PathTraceTLV struct {
	TLVHead
	// The value of the lengthField is 8N.
	PathSequence []ClockIdentity // N
}

PathTraceTLV Table 115 PATH_TRACE TLV format

func (*PathTraceTLV) MarshalBinaryTo

func (t *PathTraceTLV) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to PathTraceTLV

func (*PathTraceTLV) UnmarshalBinary

func (t *PathTraceTLV) UnmarshalBinary(b []byte) error

UnmarshalBinary parses []byte and populates struct fields

type PortAddress

type PortAddress struct {
	NetworkProtocol TransportType
	AddressLength   uint16
	AddressField    []byte
}

PortAddress see 5.3.6 PortAddress

func (*PortAddress) IP

func (p *PortAddress) IP() (net.IP, error)

IP converts PortAddress to IP

func (*PortAddress) MarshalBinary

func (p *PortAddress) MarshalBinary() ([]byte, error)

MarshalBinary converts PortAddress to []bytes

func (*PortAddress) UnmarshalBinary

func (p *PortAddress) UnmarshalBinary(b []byte) error

UnmarshalBinary converts bytes to PortAddress

type PortIdentity

type PortIdentity struct {
	ClockIdentity ClockIdentity
	PortNumber    uint16
}

The PortIdentity type identifies a PTP Port or a Link Port

func (PortIdentity) Compare

func (p PortIdentity) Compare(q PortIdentity) int

Compare returns an integer comparing two port identities. The result will be 0 if p == q, -1 if p < q, and +1 if p > q. The definition of "less than" is the same as the Less method.

func (PortIdentity) Less

func (p PortIdentity) Less(q PortIdentity) bool

Less reports whether p sorts before q. Port identities sort first by clock identity, then their port numbers.

func (PortIdentity) String

func (p PortIdentity) String() string

String formats PortIdentity same way ptp4l pmc client does

type PortPropertiesNPTLV

type PortPropertiesNPTLV struct {
	ManagementTLVHead

	PortIdentity PortIdentity
	PortState    PortState
	Timestamping Timestamping
	Interface    PTPText
}

PortPropertiesNPTLV is a ptp4l struct containing port properties

func (*PortPropertiesNPTLV) MarshalBinary

func (p *PortPropertiesNPTLV) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

type PortServiceStats

type PortServiceStats struct {
	AnnounceTimeout       uint64 `json:"ptp.servicestats.announce_timeout"`
	SyncTimeout           uint64 `json:"ptp.servicestats.sync_timeout"`
	DelayTimeout          uint64 `json:"ptp.servicestats.delay_timeout"`
	UnicastServiceTimeout uint64 `json:"ptp.servicestats.unicast_service_timeout"`
	UnicastRequestTimeout uint64 `json:"ptp.servicestats.unicast_request_timeout"`
	MasterAnnounceTimeout uint64 `json:"ptp.servicestats.master_announce_timeout"`
	MasterSyncTimeout     uint64 `json:"ptp.servicestats.master_sync_timeout"`
	QualificationTimeout  uint64 `json:"ptp.servicestats.qualification_timeout"`
	SyncMismatch          uint64 `json:"ptp.servicestats.sync_mismatch"`
	FollowupMismatch      uint64 `json:"ptp.servicestats.followup_mismatch"`
}

PortServiceStats is a ptp4l struct containing counters for different port events, which we added in linuxptp cfbb8bdb50f5a38687fcddccbe6a264c6a078bbd

type PortServiceStatsNPTLV

type PortServiceStatsNPTLV struct {
	ManagementTLVHead

	PortIdentity     PortIdentity
	PortServiceStats PortServiceStats
}

PortServiceStatsNPTLV is a management TLV added in linuxptp cfbb8bdb50f5a38687fcddccbe6a264c6a078bbd

func (*PortServiceStatsNPTLV) MarshalBinary

func (p *PortServiceStatsNPTLV) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

type PortState

type PortState uint8

PortState is a enum describing one of possible states of port state machines

const (
	PortStateInitializing PortState = iota + 1
	PortStateFaulty
	PortStateDisabled
	PortStateListening
	PortStatePreMaster
	PortStateMaster
	PortStatePassive
	PortStateUncalibrated
	PortStateSlave
	PortStateGrandMaster /*non-standard extension*/
)

Table 20 PTP state enumeration

func (PortState) String

func (ps PortState) String() string

type PortStats

type PortStats struct {
	RXMsgType [16]uint64
	TXMsgType [16]uint64
}

PortStats is a ptp4l struct containing port statistics

type PortStatsNPTLV

type PortStatsNPTLV struct {
	ManagementTLVHead

	PortIdentity PortIdentity
	PortStats    PortStats
}

PortStatsNPTLV is a ptp4l struct containing port identinity and statistics

func (*PortStatsNPTLV) MarshalBinary

func (p *PortStatsNPTLV) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

type RequestUnicastTransmissionTLV

type RequestUnicastTransmissionTLV struct {
	TLVHead
	MsgTypeAndReserved    UnicastMsgTypeAndFlags // first 4 bits only, same enums as with normal message type
	LogInterMessagePeriod LogInterval
	DurationField         uint32
}

RequestUnicastTransmissionTLV Table 110 REQUEST_UNICAST_TRANSMISSION TLV format

func (*RequestUnicastTransmissionTLV) MarshalBinaryTo

func (t *RequestUnicastTransmissionTLV) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to RequestUnicastTransmissionTLV

func (*RequestUnicastTransmissionTLV) UnmarshalBinary

func (t *RequestUnicastTransmissionTLV) UnmarshalBinary(b []byte) error

UnmarshalBinary parses []byte and populates struct fields

type ScaledNS

type ScaledNS struct {
	NanosecondsMSB        uint16
	NanosecondsLSB        uint64
	FractionalNanoseconds uint16
}

ScaledNS is some struct used by ptp4l to report phase change

type SdoIDAndMsgType

type SdoIDAndMsgType uint8

SdoIDAndMsgType is a uint8 where first 4 bites contain SdoID and last 4 bits MessageType

func NewSdoIDAndMsgType

func NewSdoIDAndMsgType(msgType MessageType, sdoID uint8) SdoIDAndMsgType

NewSdoIDAndMsgType builds new SdoIDAndMsgType from MessageType and flags

func (SdoIDAndMsgType) MsgType

func (m SdoIDAndMsgType) MsgType() MessageType

MsgType extracts MessageType from SdoIDAndMsgType

type Signaling

type Signaling struct {
	Header
	TargetPortIdentity PortIdentity
	TLVs               []TLV
}

Signaling packet. As it's of variable size, we cannot just binary.Read/Write it.

func (*Signaling) MarshalBinary

func (p *Signaling) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

func (*Signaling) MarshalBinaryTo

func (p *Signaling) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to Signaling

func (*Signaling) UnmarshalBinary

func (p *Signaling) UnmarshalBinary(b []byte) error

UnmarshalBinary parses []byte and populates struct fields

type SyncDelayReq

type SyncDelayReq struct {
	Header
	SyncDelayReqBody
}

SyncDelayReq is a full Sync/Delay_Req packet

func (*SyncDelayReq) MarshalBinary

func (p *SyncDelayReq) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

func (*SyncDelayReq) MarshalBinaryTo

func (p *SyncDelayReq) MarshalBinaryTo(b []byte) (int, error)

MarshalBinaryTo marshals bytes to SyncDelayReq

func (*SyncDelayReq) UnmarshalBinary

func (p *SyncDelayReq) UnmarshalBinary(b []byte) error

UnmarshalBinary unmarshals bytes to SyncDelayReq

type SyncDelayReqBody

type SyncDelayReqBody struct {
	OriginTimestamp Timestamp
}

SyncDelayReqBody Table 44 Sync and Delay_Req message fields

type TLV

type TLV interface {
	Type() TLVType
}

TLV abstracts away any TLV

type TLVHead

type TLVHead struct {
	TLVType     TLVType
	LengthField uint16 // The length of all TLVs shall be an even number of octets
}

TLVHead is a common part of all TLVs

func (TLVHead) Type

func (t TLVHead) Type() TLVType

Type implements TLV interface

type TLVType

type TLVType uint16

TLVType is type for TLV types

const (
	TLVManagement                           TLVType = 0x0001
	TLVManagementErrorStatus                TLVType = 0x0002
	TLVOrganizationExtension                TLVType = 0x0003
	TLVRequestUnicastTransmission           TLVType = 0x0004
	TLVGrantUnicastTransmission             TLVType = 0x0005
	TLVCancelUnicastTransmission            TLVType = 0x0006
	TLVAcknowledgeCancelUnicastTransmission TLVType = 0x0007
	TLVPathTrace                            TLVType = 0x0008
	TLVAlternateTimeOffsetIndicator         TLVType = 0x0009
)

As per Table 52 tlvType values

func (TLVType) String

func (t TLVType) String() string

type TimeInterval

type TimeInterval IntFloat

TimeInterval is the time interval expressed in nanoseconds, multiplied by 2**16. Positive or negative time intervals outside the maximum range of this data type shall be encoded as the largest positive and negative values of the data type, respectively. For example, 2.5 ns is expressed as 0000 0000 0002 8000 base 16

func NewTimeInterval

func NewTimeInterval(ns float64) TimeInterval

NewTimeInterval returns TimeInterval built from Nanoseconds

func (TimeInterval) Nanoseconds

func (t TimeInterval) Nanoseconds() float64

Nanoseconds decodes TimeInterval to human-understandable nanoseconds

func (TimeInterval) String

func (t TimeInterval) String() string

type TimeSource

type TimeSource uint8

TimeSource indicates the immediate source of time used by the Grandmaster PTP Instance

const (
	TimeSourceAtomicClock        TimeSource = 0x10
	TimeSourceGNSS               TimeSource = 0x20
	TimeSourceTerrestrialRadio   TimeSource = 0x30
	TimeSourceSerialTimeCode     TimeSource = 0x39
	TimeSourcePTP                TimeSource = 0x40
	TimeSourceNTP                TimeSource = 0x50
	TimeSourceHandSet            TimeSource = 0x60
	TimeSourceOther              TimeSource = 0x90
	TimeSourceInternalOscillator TimeSource = 0xa0
)

TimeSource values, Table 6 timeSource enumeration

func (TimeSource) String

func (t TimeSource) String() string

type TimeStatusNPTLV

type TimeStatusNPTLV struct {
	ManagementTLVHead

	MasterOffsetNS             int64
	IngressTimeNS              int64 // this is PHC time
	CumulativeScaledRateOffset int32
	ScaledLastGmPhaseChange    int32
	GMTimeBaseIndicator        uint16
	LastGmPhaseChange          ScaledNS
	GMPresent                  int32
	GMIdentity                 ClockIdentity
}

TimeStatusNPTLV is a ptp4l struct containing actually useful instance metrics

type Timestamp

type Timestamp struct {
	Seconds     PTPSeconds
	Nanoseconds uint32
}

Timestamp type represents a positive time with respect to the epoch. The secondsField member is the integer portion of the timestamp in units of seconds. The nanosecondsField member is the fractional portion of the timestamp in units of nanoseconds. The nanosecondsField member is always less than 10**9 . For example: +2.000000001 seconds is represented by secondsField = 0000 0000 0002 base 16 and nanosecondsField= 0000 0001 base 16.

func NewTimestamp

func NewTimestamp(t time.Time) Timestamp

NewTimestamp allows to create Timestamp from time.Time

func (Timestamp) Empty

func (t Timestamp) Empty() bool

Empty timestamp

func (Timestamp) String

func (t Timestamp) String() string

String representation of the timestamp

func (Timestamp) Time

func (t Timestamp) Time() time.Time

Time turns Timestamp into normal Go time.Time

type Timestamping

type Timestamping uint8

Timestamping is a ptp4l-specific enum describing timestamping type

const (
	// TimestampingSoftware is a software timestamp const
	TimestampingSoftware Timestamping = iota
	// TimestampingHardware is a hardware timestamp const
	TimestampingHardware
	// TimestampingLegacyHW is a legacy hardware timestamp const
	TimestampingLegacyHW
	// TimestampingOneStep is a one step timestamp const
	TimestampingOneStep
	// TimestampingP2P1Step is a P2P one step timestamp const
	TimestampingP2P1Step
)

type TransportType

type TransportType uint16

TransportType is a enum describing network transport protocol types

const (
	/* 0 is Reserved in spec. Use it for UDS */
	TransportTypeUDS TransportType = iota
	TransportTypeUDPIPV4
	TransportTypeUDPIPV6
	TransportTypeIEEE8023
	TransportTypeDeviceNet
	TransportTypeControlNet
	TransportTypePROFINET
)

Table 3 networkProtocol enumeration

func (TransportType) String

func (t TransportType) String() string

type UnicastMasterEntry

type UnicastMasterEntry struct {
	PortIdentity PortIdentity
	ClockQuality ClockQuality
	Selected     bool
	PortState    UnicastMasterState
	Priority1    uint8
	Priority2    uint8
	Address      net.IP
}

UnicastMasterEntry is an entry in UnicastMasterTable that ptp4l exports via management TLV

func (*UnicastMasterEntry) MarshalBinary

func (e *UnicastMasterEntry) MarshalBinary() ([]byte, error)

MarshalBinary converts UnicastMasterEntry to []bytes

func (*UnicastMasterEntry) UnmarshalBinary

func (e *UnicastMasterEntry) UnmarshalBinary(b []byte) error

UnmarshalBinary implements Unmarshaller interface

type UnicastMasterState

type UnicastMasterState uint8

UnicastMasterState is a enum describing the unicast master state in ptp4l unicast master table

const (
	UnicastMasterStateWait UnicastMasterState = iota
	UnicastMasterStateHaveAnnounce
	UnicastMasterStateNeedSYDY
	UnicastMasterStateHaveSYDY
)

possible states of unicast master in ptp4l unicast master table

func (UnicastMasterState) String

func (t UnicastMasterState) String() string

type UnicastMasterTable

type UnicastMasterTable struct {
	ActualTableSize uint16
	UnicastMasters  []UnicastMasterEntry
}

UnicastMasterTable is a table of UnicastMasterEntries

type UnicastMasterTableNPTLV

type UnicastMasterTableNPTLV struct {
	ManagementTLVHead

	UnicastMasterTable UnicastMasterTable
}

UnicastMasterTableNPTLV is a custom management packet that exports unicast master table state

func (*UnicastMasterTableNPTLV) MarshalBinary

func (p *UnicastMasterTableNPTLV) MarshalBinary() ([]byte, error)

MarshalBinary converts packet to []bytes

type UnicastMsgTypeAndFlags

type UnicastMsgTypeAndFlags uint8

UnicastMsgTypeAndFlags is a uint8 where first 4 bites contain MessageType and last 4 bits contain some flags

func NewUnicastMsgTypeAndFlags

func NewUnicastMsgTypeAndFlags(msgType MessageType, flags uint8) UnicastMsgTypeAndFlags

NewUnicastMsgTypeAndFlags builds new UnicastMsgTypeAndFlags from MessageType and flags

func (UnicastMsgTypeAndFlags) MsgType

func (m UnicastMsgTypeAndFlags) MsgType() MessageType

MsgType extracts MessageType from UnicastMsgTypeAndFlags

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL