timestamp

package
v0.0.0-...-3e45774 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2024 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ControlSizeBytes is a socket control message containing TX/RX timestamp
	// If the read fails we may endup with multiple timestamps in the buffer
	// which is best to read right away
	ControlSizeBytes = 128
	// PayloadSizeBytes is a size of maximum ptp packet which is usually up to 66 bytes
	PayloadSizeBytes = 128
)
View Source
const Unsupported = "Unsupported"

Unsupported is a string for unsupported timestamp

Variables

View Source
var AttemptsTXTS = defaultTXTS

AttemptsTXTS is configured amount of attempts to read TX timestamp

View Source
var TimeoutTXTS = time.Millisecond

TimeoutTXTS is configured timeout to read TX timestamp

Functions

func AddrToSockaddr

func AddrToSockaddr(ip netip.Addr, port int) unix.Sockaddr

AddrToSockaddr converts netip.Addr + port into a socket address

func ConnFd

func ConnFd(conn *net.UDPConn) (int, error)

ConnFd returns file descriptor of a connection

func EnableHWTimestamps

func EnableHWTimestamps(connFd int, iface string) error

EnableHWTimestamps enables HW timestamps (TX and RX) on the socket

func EnableHWTimestampsRx

func EnableHWTimestampsRx(connFd int, iface string) error

EnableHWTimestampsRx enables HW RX timestamps on the socket

func EnableSWTimestamps

func EnableSWTimestamps(connFd int) error

EnableSWTimestamps enables SW timestamps (TX and RX) on the socket

func EnableSWTimestampsRx

func EnableSWTimestampsRx(connFd int) error

EnableSWTimestampsRx enables SW RX timestamps on the socket

func EnableTimestamps

func EnableTimestamps(ts Timestamp, connFd int, iface string) error

EnableTimestamps enables timestamps on the socket based on requested type

func IPToSockaddr

func IPToSockaddr(ip net.IP, port int) unix.Sockaddr

IPToSockaddr converts IP + port into a socket address Somewhat copy from https://github.com/golang/go/blob/16cd770e0668a410a511680b2ac1412e554bd27b/src/net/ipsock_posix.go#L145

func NewSockaddrWithPort

func NewSockaddrWithPort(sa unix.Sockaddr, port int) unix.Sockaddr

NewSockaddrWithPort creates a new socket address with the same IP and new port

func ReadPacketWithRXTimestamp

func ReadPacketWithRXTimestamp(connFd int) ([]byte, unix.Sockaddr, time.Time, error)

ReadPacketWithRXTimestamp returns byte packet and HW RX timestamp

func ReadPacketWithRXTimestampBuf

func ReadPacketWithRXTimestampBuf(connFd int, buf, oob []byte) (int, unix.Sockaddr, time.Time, error)

ReadPacketWithRXTimestampBuf writes byte packet into provide buffer buf, and returns number of bytes copied to the buffer, client ip and HW RX timestamp. oob buffer can be reaused after ReadPacketWithRXTimestampBuf call.

func ReadTXtimestamp

func ReadTXtimestamp(connFd int) (time.Time, int, error)

ReadTXtimestamp returns HW TX timestamp

func ReadTXtimestampBuf

func ReadTXtimestampBuf(connFd int, oob, toob []byte) (time.Time, int, error)

ReadTXtimestampBuf returns HW TX timestamp, needs to be provided 2 buffers which all can be re-used after ReadTXtimestampBuf finishes.

func SockaddrToAddr

func SockaddrToAddr(sa unix.Sockaddr) netip.Addr

SockaddrToAddr converts socket address to a netip.Addr Somewhat copy from https://github.com/golang/go/blob/658b5e66ecbc41a49e6fb5aa63c5d9c804cf305f/src/net/udpsock_posix.go#L15

func SockaddrToIP

func SockaddrToIP(sa unix.Sockaddr) net.IP

SockaddrToIP converts socket address to an IP Somewhat copy from https://github.com/golang/go/blob/658b5e66ecbc41a49e6fb5aa63c5d9c804cf305f/src/net/udpsock_posix.go#L15

func SockaddrToPort

func SockaddrToPort(sa unix.Sockaddr) int

SockaddrToPort converts socket address to an IP Somewhat copy from https://github.com/golang/go/blob/658b5e66ecbc41a49e6fb5aa63c5d9c804cf305f/src/net/udpsock_posix.go#L15

Types

type Timestamp

type Timestamp int

Timestamp is a type of timestamp

const (
	// SW is a software timestamp
	SW Timestamp = iota
	// SWRX is a software RX timestamp
	SWRX
	// HW is a hardware timestamp
	HW
	// HWRX is a hardware RX timestamp
	HWRX
)

func (Timestamp) MarshalText

func (t Timestamp) MarshalText() ([]byte, error)

MarshalText timestamp to byte slice

func (*Timestamp) Set

func (t *Timestamp) Set(value string) error

Set timestamp from string

func (Timestamp) String

func (t Timestamp) String() string

String timestamp to string

func (*Timestamp) Type

func (t *Timestamp) Type() string

Type is required by the cobra.Value interface

func (*Timestamp) UnmarshalText

func (t *Timestamp) UnmarshalText(value []byte) error

UnmarshalText timestamp from byte slice

Jump to

Keyboard shortcuts

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